diff --git a/Projects/Android/jni/Android.mk b/Projects/Android/jni/Android.mk index 1782f4e..6de6c66 100644 --- a/Projects/Android/jni/Android.mk +++ b/Projects/Android/jni/Android.mk @@ -1,10 +1,2 @@ include $(GL4ES_PATH)/Android.mk -include $(SUPPORT_LIBS)/SDL2/SDL2/Android.mk -include $(SUPPORT_LIBS)/SDL2/SDL2_mixer/Android.mk -include $(SUPPORT_LIBS)/jpeg8d/Android.mk -include $(SUPPORT_LIBS)/libzip/Android.mk -include $(SUPPORT_LIBS)/libpng/Android.mk -include $(SUPPORT_LIBS)/sigc++/Android.mk -include $(TOP_DIR)/quake2/Android.mk -include $(TOP_DIR)/quake2/Android_game.mk -include $(TOP_DIR)/quake2/Android_gl1.mk +include $(TOP_DIR)/rtcw/Android.mk diff --git a/Projects/Android/jni/Application.mk b/Projects/Android/jni/Application.mk index b129e88..bbbbc35 100644 --- a/Projects/Android/jni/Application.mk +++ b/Projects/Android/jni/Application.mk @@ -16,7 +16,7 @@ GL4ES_PATH := $(SUPPORT_LIBS)/gl4es APP_ALLOW_MISSING_DEPS=true -APP_MODULES := yquake2 yquake2_game gl4es yquake2_gl1 +APP_MODULES := gl4es qagamearm rtcw_client uiarm cgamearm APP_STL := c++_shared diff --git a/Projects/Android/jni/SupportLibs/gl4es/.gitignore b/Projects/Android/jni/SupportLibs/gl4es/.gitignore new file mode 100644 index 0000000..b033c64 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/.gitignore @@ -0,0 +1,10 @@ +.gdb_history +.vscode/ +CMakeFiles/ +lib/ +Makefile +CMakeCache.txt +cmake_install.cmake +spec/yml/gles-1.1-full.yml +/build/ +/tests/*.png diff --git a/Projects/Android/jni/SupportLibs/gl4es/.travis.yml b/Projects/Android/jni/SupportLibs/gl4es/.travis.yml new file mode 100644 index 0000000..3dcc36f --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/.travis.yml @@ -0,0 +1,24 @@ +language: c +sudo: false +dist: xenial +addons: + apt: + packages: + - cmake + +compiler: + - gcc + +#Build steps +before_script: + - mkdir build + - cd build + - cmake .. -DODROID=1 + +script: + - make + +#after_script: +# - sudo apt-get install apitrace-gl-frontend=5\* imagemagick xvfb -y +# - cd ../tests +# - xvfb-run ./tests.sh ../lib diff --git a/Projects/Android/jni/SupportLibs/gl4es/Android.mk b/Projects/Android/jni/SupportLibs/gl4es/Android.mk new file mode 100644 index 0000000..5433bae --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/Android.mk @@ -0,0 +1,86 @@ +LOCAL_PATH := $(call my-dir) + +########################### +# +# GL static library +# +########################### + +include $(CLEAR_VARS) + +LOCAL_MODULE := gl4es + +LOCAL_C_INCLUDES := $(LOCAL_PATH)/include + +LOCAL_EXPORT_C_INCLUDES := $(LOCAL_C_INCLUDES) -DBCMHOST + +LOCAL_SRC_FILES := \ + src/gl/array.c \ + src/gl/blend.c \ + src/gl/blit.c \ + src/gl/buffers.c \ + src/gl/build_info.c \ + src/gl/debug.c \ + src/gl/decompress.c \ + src/gl/depth.c \ + src/gl/directstate.c \ + src/gl/drawing.c \ + src/gl/enable.c \ + src/gl/eval.c \ + src/gl/face.c \ + src/gl/fog.c \ + src/gl/fpe.c \ + src/gl/fpe_shader.c \ + src/gl/framebuffers.c \ + src/gl/getter.c \ + src/gl/gl4es.c \ + src/gl/glstate.c \ + src/gl/hint.c \ + src/gl/init.c \ + src/gl/light.c \ + src/gl/line.c \ + src/gl/list.c \ + src/gl/listdraw.c \ + src/gl/listrl.c \ + src/gl/loader.c \ + src/gl/matrix.c \ + src/gl/matvec.c \ + src/gl/pixel.c \ + src/gl/planes.c \ + src/gl/pointsprite.c \ + src/gl/preproc.c \ + src/gl/program.c \ + src/gl/queries.c \ + src/gl/raster.c \ + src/gl/render.c \ + src/gl/shader.c \ + src/gl/shaderconv.c \ + src/gl/stack.c \ + src/gl/stencil.c \ + src/gl/string_utils.c \ + src/gl/stubs.c \ + src/gl/texenv.c \ + src/gl/texgen.c \ + src/gl/texture.c \ + src/gl/uniform.c \ + src/gl/vertexattrib.c \ + src/gl/wrap/gl4es.c \ + src/gl/wrap/gles.c \ + src/gl/wrap/glstub.c \ + src/gl/math/eval.c \ + src/glx/hardext.c \ + src/glx/glx.c \ + src/glx/lookup.c \ + src/glx/gbm.c \ + src/glx/streaming.c \ + +LOCAL_CFLAGS += -g -std=c99 -funwind-tables -O3 -DBCMHOST -fvisibility=hidden -include include/android_debug.h +LOCAL_CFLAGS += -DNOX11 +LOCAL_CFLAGS += -DNO_GBM +LOCAL_CFLAGS += -DDEFAULT_ES=2 +LOCAL_CFLAGS += -DNO_INIT_CONSTRUCTOR + + +LOCAL_LDLIBS := -ldl -llog -lEGL -lGLESv3 + +include $(BUILD_SHARED_LIBRARY) diff --git a/Projects/Android/jni/SupportLibs/gl4es/CHANGELOG.md b/Projects/Android/jni/SupportLibs/gl4es/CHANGELOG.md new file mode 100644 index 0000000..acf72ec --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/CHANGELOG.md @@ -0,0 +1,135 @@ +Version history +---- +##### current version +* Improved a bit the merger (wich merge subsequent `glBegin(...)`/`glEnd()`) efficiency +* Removed LIBGL_BEGINEND=2 (that was not working correctly, and it complexify the code too much) +* Added some Direct Acces function (from EXT_direct_access) +* Fixes and Improvements on depth (and depth_Stencil) Texture handling +* Handling of GL_BGRA color size in VA (for HumandRessourceMachine) +* Some fixes to fpe_shader (for Neverwinter Night) +* Rework of Header structure (from @rajdakin) +* Better test, using "make test" (from @rajdakin, still using apitrace for replay) + +##### v1.1.0 +* Default backend is now GLES2 (but not on Pandora, still GLES1.1 for compatibility reasons) +* Added LIBGL_SHADERNOGLES to remove the GLES part of shaders (if any). +* Various RPi improvments, mainly in the context creation. +* Various AmigaOS4 improvement and workaround (but still in a beta state) +* Various improvement in GLX function, with a more accurate way to emulate GLXFBConfig +* Improved the way eglSurface are created in glx.c, to avoid try to create 2 on the same window (EGL doesn't allow that) +* Added LIBGL_GLXRECYCLE to not delete eglSurface and recycle them +* Added tracking of Framebuffers Object and Renderbuffers Objects +* Added (real) support for Float and Half-float Texture (including has attachement to FBO, emulating it if not supported in Hardware) +* Added support for Depth Stencil texture when attached to an FBO +* Added LIBGL_FBO=WxH for all plateform +* Fixed some issue when resized textures attached to an FBO +* Added LIBGL_NODEPTHTEX to avoid using Depth Texture when available (using renderbuffer can be faster) +* Added support for Depth Texture when attached to an FBO (if supported by Hardware) +* Fixes some isue with blitting of FBO when size of Main Framebuffer changed +* Added option LIBGL_LOGSHADERERROR to get Shader compiler log and error +* Added support for (emulated) Hardware Instancing +* Added support for GL_ARB_draw_elements_base_vertex + +##### v1.0.8 +* Fixes and improvments to avoid unnecessary GLES state changes +* Fixes some memory issues with glBitmap +* Fixes to FPE (when using multitexture and GL_COMBINE) +* Added some TexEnv extension for GLES2 backend +* Fixes to Batch / Merger on GL_POLYGON primitives +* Fixes to LineStipple +* Pandora only: Fixed use of Texture Streaming on GLES2 backend + +##### v1.0.6 +* Factorised "Blit" function, and implemented `glBlitFramebuffer` +* Optimized `glBitmap` +* Added (limited) direct support to `GL_UNSIGNED_INT` for `glDrawElements` for hardware that support it +* Improved (a lot) `glBegin`/`glEnd` merger +* Added Anisotropic filterring support, for hardware that support it. +* Changed `LIBGL_BATCH`. It will now try to merge small (parametrable) subsequent `glDrawXXXX` +* Changed (simplified) the way texture "0" is handled +* Improvement to `glDrawArrays` and `glDrawElement`, with less copy of datas +* WIP AmigaOS4 support (and BigEndian architecture) +* Improved NPOT support for "Limited NPOT" hardware +* Lots of FPE fixes +* Improve the way multi glX Context are handled +* Added basic pre-proc (only handle comments for now) +* Small optimisation on when using `glDrawArrays` with GL_QUADS +* Improvement to GL_RENDER +* Improvement to line stipple +* Improvement to glPolygonMode(GL_LINE) + +##### v1.0.4 + * FPE is now usable. Most function are implemented + * ShaderConv in now usable. Basic GL 2 shader are supported + * Refactored Texture cache and handling, for better Tex1D/Tex3D/TexRectangle handling + +##### v1.0.2 + * Added GLES2 backend infrastructure + * Begin GLES2 backend + * Infrastructure for FPE (Fixed Pipeline Emulator) + * Basic and Crude Shader convertor + * Added blit function for GLES2 backend + * Added some OpenGL Builtin VAs and Uniforms + +##### 1.0.0 + * Removed old ES2 defines (ES2 will be dynamic later) + +##### 0.9.8 + * Added TravisCI build on github + * Added some optimisation when to discard call to glBindTexture if useless (same texture) between 2 glBegin/glEnd blocks + * Stubbed glGet with GL_DRAW_BUFFER + * Improvement to Raster operations + * Factorised Blit function (only 1 function for that now) + * Tracking ShadeModel + * Tracking TexEnv + +##### 0.9.7 + * Tracking Clip Planes + * Refactor Blitting function, and use glDrawTex extension if present + * Restructured README and split in several files + * Some improvments and fixes to LIBGL_BEGINEND=2 mode + * Some improvments to some LIBGL_SHRINK mode + * Proper support for DOT3 extension + * Some fixes to Read/Draw Buffer handling + * Some fix with the PixMap glX context creation + +##### 0.9.6 + * Some fixes in GL_TEXTURE_RECTANGLE_ARB handling + * Some other fixes in texture handling (unpack and glList related) + * Some fix with the PBuffer glX context creation + * Tracking of glFog + * Exposed glBlendEquation if supported + * New LIBGL_AVOID16BITS parameter to prefer 32bits texture (usefull on ODroid) + * Some optimisations in texture conversion + +##### 0.9.5 + * Added some optimisations for sequencial glBegin/glEnd blocks, with a switch to control them + * Fixed many issue with Lights introduced with 0.9.4 + * Fixed Android build introduced with 0.9.4 + +##### 0.9.4 + * Fixed some extended functions (like glBlendFuncSeparate) not working inside list (fixing some issues with Batch mode) + * Added back GL_TEXTURE_RECTANGLE_ARB handling (and using npot texture, even limited, if available) + * Added tracking of Lights and Materials + * Fixed (Added in fact) support for Multisampling on the GLX Context creation (a bit hacky, but seems to works) + * Added LIBGL_NODOWNSAMPLING and associated Hint + * Try to implement some caching on VAO to avoid some memcpy in renderlist (with a way to disable it just in case) + +##### 0.9.3 + * Added support for Cube Mapping (with hardware support) + * Improved Texture state tracking + * Added LIBGL_NOTEXMAT env. var. switch for Texture Matrix handling + * Added GL_EXT_vertex_array_bgra (and NEONinzed some loop) + * Finished GL_EXT_direct_state_access extension + * Mangled glX function (to be abble to use apitrace to capture GL frames) + * Return some values in glXQueryServerString, coherent with glXGetClientString + +##### 0.9.2 + * All matrix are tracked now + * Texture Matrix are 100% handled by gl4es. GLES Hardware keep an Identity matrix (TexCoord are transformed if needed). This allows a better handling of NPOT texture on hadware that doesn't support Full NPOT (fixed movies beiing horizontaly shifted in openmw with LIBGL_NPOT=1 for example) + +##### 0.9.1 + * Added gl4es specifics glHint capabilities. If the extension GL_GL4ES_hint is present, than a few Hint are accessible. Look in include/gl4eshint.h for the list. + +##### 0.9.0 + * New name: gl4es diff --git a/Projects/Android/jni/SupportLibs/gl4es/CMakeLists.txt b/Projects/Android/jni/SupportLibs/gl4es/CMakeLists.txt new file mode 100644 index 0000000..f39eee8 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/CMakeLists.txt @@ -0,0 +1,200 @@ +cmake_minimum_required(VERSION 2.8) + +project(gl4es LANGUAGES C) + +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) + +link_directories(${CMAKE_LIBRARY_OUTPUT_DIRECTORY}) + +option(PANDORA "Set to ON if targeting an OpenPandora device" ${PANDORA}) +option(BCMHOST "Set to ON if targeting an RPi(2) device" ${BCMHOST}) +option(ODROID "Set to ON if targeting an ODroid device" ${ODROID}) +option(CHIP "Set to ON if targeting an C.H.I.P. device" ${CHIP}) +option(AMIGAOS4 "Set to ON if targeting an AmigaOS4/Warp3D platform (activate NOEGL and NOX11)" ${AMIGAOS4}) +option(NOX11 "Set to ON to not use X11 (creation of context has to be done outside gl4es)" ${NOX11}) +option(NOEGL "Set to ON to not use EGL (all functions are taken in GLES library)" ${NOEGL}) +option(STATICLIB "Set to ON to build a static version of gl4es" ${STATICLIB}) +option(GBM "Set to ON to not build GBM interface" ${GBM}) +option(USE_CCACHE "Set to ON to use ccache if present in the system" ${USE_CCACHE}) + +# Pandora +if(PANDORA) + add_definitions(-DPANDORA) + add_definitions(-DTEXSTREAM) + add_definitions(-mcpu=cortex-a8 -mfpu=neon -mfloat-abi=softfp -ftree-vectorize -fsingle-precision-constant -ffast-math) + set(NO_GBM ON) +endif() + +if((NOT GBM) OR PANDORA) + set(NO_GBM ON) +else() + set(NO_GBM OFF) +endif() + + +if(NOT DEFAULT_ES) + if(PANDORA) + set(DEFAULT_ES 1) + else() + set(DEFAULT_ES 2) + endif() +endif() + +# Raspberry PI +if(BCMHOST) + include_directories(/opt/vc/include /opt/vc/include/interface/vcos/pthreads /opt/vc/include/interface/vmcs_host/linux) + link_directories(/opt/vc/lib) + add_definitions(-DBCMHOST) +endif() + +# ODROID +if(ODROID) + add_definitions(-DODROID) +endif() + +#PocketCHIP +if(CHIP) + add_definitions(-DCHIP) + add_definitions(-mcpu=cortex-a8 -mfpu=neon -mfloat-abi=hard -ftree-vectorize -fsingle-precision-constant -ffast-math) +endif() + +# AmigaOS4 +if(AMIGAOS4) + set(CMAKE_C_COMPILER "ppc-amigaos-gcc") + set(CMAKE_CXX_COMPILER "ppc-amigaos-g++") + set(CMAKE_LINKER "ppc-amigaos-ld") + set(CMAKE_AR "ppc-amigaos-ar") + set(CMAKE_RANLIB "ppc-amigaos-ranlib") + add_definitions(-DAMIGAOS4) + set(NOX11 ON) + set(NOEGL ON) + set(NO_GBM ON) +endif() + +#NOX11 +if(NOX11) + add_definitions(-DNOX11) +endif() + +#NOEGL +if(NOEGL) + add_definitions(-DNOEGL) + add_definitions(-DNOX11) +endif() + +if(NOT NO_GBM) + find_package(PkgConfig REQUIRED) + pkg_check_modules(KMSDRM REQUIRED libdrm gbm egl) + link_directories(${KMSDRM_LIBRARY_DIRS}) + include_directories(${KMSDRM_INCLUDE_DIRS}) +endif() + +if(NO_GBM) + add_definitions(-DNO_GBM) +endif() + +#DEFAULT_ES=2 +if(DEFAULT_ES EQUAL 2) + add_definitions(-DDEFAULT_ES=2) +endif() +if(DEFAULT_ES EQUAL 1) + add_definitions(-DDEFAULT_ES=1) +endif() + +if(USE_CCACHE) + find_program(CCACHE_FOUND ccache) + if(CCACHE_FOUND) + set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache) + set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache) + endif() +endif() + +link_directories(${CMAKE_BINARY_DIR}/lib) +add_definitions(-std=gnu99 -funwind-tables -fvisibility=hidden) + +include_directories(include) +add_subdirectory(src) + +enable_testing() + +macro(create_test test_name test_filename calls_count tolerance) + if (${ARGC} EQUAL 5) + add_test(${test_name} + ${CMAKE_COMMAND} + -D LIBRARY_FOLDER=${CMAKE_LIBRARY_OUTPUT_DIRECTORY} + -D TESTS_DIRECTORY=${CMAKE_SOURCE_DIR}/tests + -D TEST_FILENAME=${test_filename} + -D CALLS=${calls_count} + -D TOLERANCE=${tolerance} + -D EXTRACT_RANGE=${ARGV4} + -P ${CMAKE_SOURCE_DIR}/test.cmake) + elseif (${ARGC} EQUAL 6) + if (${ARGV4} STREQUAL "NOEXTRACT_RANGE") + add_test(${test_name} + ${CMAKE_COMMAND} + -D LIBRARY_FOLDER=${CMAKE_LIBRARY_OUTPUT_DIRECTORY} + -D TESTS_DIRECTORY=${CMAKE_SOURCE_DIR}/tests + -D TEST_FILENAME=${test_filename} + -D CALLS=${calls_count} + -D TOLERANCE_GLES1=${tolerance} + -D TOLERANCE_GLES2=${ARGV5} + -P ${CMAKE_SOURCE_DIR}/test.cmake) + else (${ARGV4} STREQUAL "NOEXTRACT_RANGE") + add_test(${test_name} + ${CMAKE_COMMAND} + -D LIBRARY_FOLDER=${CMAKE_LIBRARY_OUTPUT_DIRECTORY} + -D TESTS_DIRECTORY=${CMAKE_SOURCE_DIR}/tests + -D TEST_FILENAME=${test_filename} + -D CALLS=${calls_count} + -D TOLERANCE_GLES1=${tolerance} + -D TOLERANCE_GLES2=${ARGV5} + -D EXTRACT_RANGE=${ARGV4} + -P ${CMAKE_SOURCE_DIR}/test.cmake) + endif (${ARGV4} STREQUAL "NOEXTRACT_RANGE") + else (${ARGC} EQUAL 5) + add_test(${test_name} + ${CMAKE_COMMAND} + -D LIBRARY_FOLDER=${CMAKE_LIBRARY_OUTPUT_DIRECTORY} + -D TESTS_DIRECTORY=${CMAKE_SOURCE_DIR}/tests + -D TEST_FILENAME=${test_filename} + -D CALLS=${calls_count} + -D TOLERANCE=${tolerance} + -P ${CMAKE_SOURCE_DIR}/test.cmake) + endif (${ARGC} EQUAL 5) +endmacro(create_test) + +macro(create_test_GLES test_name GLES test_filename calls_count tolerance) + if (${ARGC} EQUAL 5) + add_test(${test_name}_GLES${GLES} + ${CMAKE_COMMAND} + -D LIBRARY_FOLDER=${CMAKE_LIBRARY_OUTPUT_DIRECTORY} + -D TESTS_DIRECTORY=${CMAKE_SOURCE_DIR}/tests + -D TEST_FILENAME=${test_filename} + -D CALLS=${calls_count} + -D TOLERANCE=${tolerance} + -D EXTRACT_RANGE=${ARGV4} + -D GLES_FORCED=${GLES} + -P ${CMAKE_SOURCE_DIR}/test.cmake) + else (${ARGC} EQUAL 5) + add_test(${test_name}_GLES${GLES} + ${CMAKE_COMMAND} + -D LIBRARY_FOLDER=${CMAKE_LIBRARY_OUTPUT_DIRECTORY} + -D TESTS_DIRECTORY=${CMAKE_SOURCE_DIR}/tests + -D TEST_FILENAME=${test_filename} + -D CALLS=${calls_count} + -D TOLERANCE=${tolerance} + -D GLES_FORCED=${GLES} + -P ${CMAKE_SOURCE_DIR}/test.cmake) + endif (${ARGC} EQUAL 5) +endmacro(create_test_GLES) + +create_test(GLXgears glxgears "0000008203" 25 "NOEXTRACT_RANGE" 700) +create_test(StuntCarRacer stuntcarracer "0000118817" 20 "638x478+1+1") +create_test(Neverball neverball "0000078750" 20 "798x478+1+1" 200) +create_test(FoobillardPlus foobillardplus "0000014748" 20 "798x478+1+1" 60) +create_test(PointSprite pointsprite "0000248810" 20) + +create_test_GLES(OpenRA 2 openra "0000031249" 20 "638x478+1+1") +create_test_GLES(GLSL_lighting 2 glsl_lighting "0000505393" 20) diff --git a/Projects/Android/jni/SupportLibs/gl4es/COMPILE.md b/Projects/Android/jni/SupportLibs/gl4es/COMPILE.md new file mode 100644 index 0000000..2f55c01 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/COMPILE.md @@ -0,0 +1,87 @@ +Compiling +---- +*for Pandora* + + `mkdir build; cd build; cmake .. -DPANDORA=1; make` + +*or for the Raspberry Pi* + + `mkdir build; cd build; cmake .. -DBCMHOST=1; make` + +*or for the ODroid* + + `mkdir build; cd build; cmake .. -DODROID=1; make` + +*or for the OrangePI* + + use ODROID profile. + +*or for CHIP machines* + + `mkdir build; cd build; cmake .. -DCHIP=1; make` + +*or for Android* + + An Android.mk is provided that should compile with an NDK + +*or use ccmake* + +Alternatively, you can use the curses-bases ccmake (or any other gui frontend for cmake) to select wich platform to use interactively. + +*for other board* + +You can avoid the use of X11 with `NOX11=1` and EGL with `NOEGL=1`, but then, you will need to create the EGL Context yourself (or using SDL for example). Be sure to synchronize the context you create with the Backend you use. By default GLES 1.1 backend is used. To used GLES2 by default, use `DEFAULT_ES=2` +You can use cmake and mix command line argument to custom build your version of GL4ES. For example, for a generic ARM with NEON platform, not using X11 or EGL, defaulting to GLES2 backend, and enabling RPi, you would do: + + `mkdir build; cd build; cmake .. -DBCMHOST=1 -DNOEGL=1 -DNOX11=1 -DDEFAULT_ES=2 -DCMAKE_C_FLAGS="-marm -mcpu=cortex-a9 -mfpu=neon -mfloat-abi=hard" ; make` + +---- + +Testing +---- +A few tests are included. +They can be launched with `tests/tests.sh` +You will need apitrace and imagemagick for them to run. (on debian and friend, it's `sudo apt install apitrace-gl-frontend imagemagick`) +The tests use a pre-recorded GL trace that is replayed, then a specific frame is captured and compared to a reference picture. +Because each renderer may render slightly differently, there are some fuzz in the comparison, so only significant changes will be detected. +For now, 2 tests are done, one with glxgears (basic testing, using mostly glBegin / glEnd) and stuntcarracer (with more GL stuff, textures and lighting). + +---- + +Per-platform +---- + +##### OpenPandora + +This is the main developpement platform for now. GL4ES works on all 3 models (CC, Rebirth and Gigahertz), and with all driver version. +For the SGX Driver version that doesn't support X11 Windowed mode (i.e. there is no `/usr/lib/libpvrPVR2D_X11WSEGL.so` library in the firmware), you need to use one of the framebuffer output: `LIBGL_FB=1` is the fastest, but you may need `LIBGL_FB=2` if you need 32bits framebuffer, or `LIBGL_FB=3` if you need GL in a Window (but it will be slow, as each frame has to be blitted back in the X11 windows). +On the Pandora, the special `LIBGL_GAMMA` can be used also, to boost gamma at load, using firmware command to change LCD gamma. + +##### ODroid + +GL4ES works well on ODroid. I can test on XU4 model, but it has been reported to work on all model, including 64bits version. +On ODroid, the EGL context can be created with SRGB attribute, by using `LIBGL_SRGB=1`, for a nice boost in the gamma (supported on most ODroid). + +##### OrangePI +GL4ES works on OrangePI using ODROID profile. GLES Hardware is MALI and is similar to ODroid in many way. I don't own any OrangePI but I have seen many success in compiling and using the lib. + +##### C.H.I.P. + +GL4ES should work on CHIP and PocketCHIP. Framebuffers mode will probably not work, with only `LIBGL_FB=3` mode that seems to work fine, and with adequate performances (there is probably no slow blit, as the driver handle directly the GL->X11 blit). +Also, on the CHIP, you will probably need to do `sudo apt-get install chip-mali-userspace` to be sure the GLES driver of the CHIP is present. + +##### RaspberryPI + +GL4ES works on RaspberryPI. I don't own any RPi model, so I cannot fine tune it for this plateform. +Framebuffer mode should work on this plateform. It seems `LIBGL_FB=3` gives good result and should be used in most cases. `LIBGL_FB=1` try to use `DispManX` for more speed. Be aware that if you use X-less config, many SDL version dedicated to DispManX do not handle GL context creation. So trying to create a GL context with this version of SDL will fail, but GL4ES is never called, so I cannot "fix" that (the fix would be inside SDL/DispManX driver). Also, GLES 1.1 seems to be deprecated in latest version of the OS, so you may need to use ES2.0 backend. + +##### Android +On Android build of GL4ES, no X11 function are called. So most `glX` function are not defined. That means that the GL context (in fact a GLES1.1 context) has to be created by other apps (mainly SDL or SDL2). + +On Android version 4.0 and earlier, there is a bug that prevent dlopen to be called inside dlopen (see [here](http://grokbase.com/t/gg/android-ndk/124bdvscqx/block-with-calling-dlopen-and-dlclose)). +GL4ES use a "library constructor" to initialize itself a load, and that constructor do some dlopen (to load EGL and GLES libraries), so it will trigger that bug. +If you are targeting a wide range of device, you should probably activate the workaround: +1. Modify [Android.mk](Android.mk) to uncomment `#LOCAL_CFLAGS += -DNO_INIT_CONSTRUCTOR` near the end of the file, to prevent the use of the library constructor. +2. In your code, call `void initialize_gl4es()` as soon as possible after loading GL4ES, and before using any GL function. + +To try the GLES2 backend, you can compile gl4es with ES2 by default (so you don't have to mess with env. variable). Simply uncomment `#LOCAL_CFLAGS += -DDEFAULT_ES=2`, and create the GL Context as GLES2. diff --git a/Projects/Android/jni/SupportLibs/gl4es/LICENSE b/Projects/Android/jni/SupportLibs/gl4es/LICENSE new file mode 100644 index 0000000..f34587f --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/LICENSE @@ -0,0 +1,20 @@ +Copyright (c) 2016-2018 Sebastien Chevalier +Copyright (c) 2013-2016 Ryan Hileman + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/Projects/Android/jni/SupportLibs/gl4es/MEDIA.md b/Projects/Android/jni/SupportLibs/gl4es/MEDIA.md new file mode 100644 index 0000000..b02effc --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/MEDIA.md @@ -0,0 +1,41 @@ +GL4ES - OpenGL for GLES Hardware +==== + +Many OpenGL software already works with GL4ES. + +![foobillards++](refs/foobillardplus.0000014748.png) + +Complex OpenGL 1.5 games, like Foobillard++, that uses cascaded display list, line stipple, TexGen, works fine. Here running on the OpenPandora. It will work with both GLES1.1 and GLES2.0 backend. Most OpenGL 1.x games will runs. + + +[![Play on Youtube](https://img.youtube.com/vi/75FYb60L7zw/0.jpg)](https://www.youtube.com/watch?v=75FYb60L7zw) + +The limit is an hardware one: GLES1.1 and GLES2.0 hardware do not allow reading Depth buffer, so some games that use it (like AssultCube) for game play wont run. Some FPS are using it just for cosmetics (Lens flare), the they still run fine without, Like Serious Sam (both First and Second Encouter), here on the OpenPandora again. + + +[![Play on Youtube](https://img.youtube.com/vi/kJPb2jYiBoM/0.jpg)](https://www.youtube.com/watch?v=kJPb2jYiBoM) + +More complex program, like Blender, can also run. + + +![MineCraft](media/minecraft.png) + +But also Minecraft, here on an ODroid in this old video. + + +![OpenRA](refs/openra.0000031249.png) + +On the OpenGL 2.0, side using GLES2.0 backend, OpenRA can run on the Pandora. + + +And OpenGL 2.x opens a lot of dors. Many commercial games run just fine on gl4es. + +[![Play on Youtube](https://img.youtube.com/vi/VUoeHWuwlMU/0.jpg)](https://www.youtube.com/watch?v=VUoeHWuwlMU) + +Here some FNA games, running on an ODroid XU4 (using method described [there](https://magazine.odroid.com/article/playing-modern-fna-games-on-the-odroid-platform/)). That video show just a few, and even more can be make to run. + + + +[![Play on Youtube](https://img.youtube.com/vi/B4YN37z3-ws/0.jpg)](https://www.youtube.com/watch?v=B4YN37z3-ws) + +And with [Box86](https://github.com/ptitSeb/box86), even more commercial games can run, like here NeverWinter Night on an ODroid XU4 diff --git a/Projects/Android/jni/SupportLibs/gl4es/README.md b/Projects/Android/jni/SupportLibs/gl4es/README.md new file mode 100644 index 0000000..64211f0 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/README.md @@ -0,0 +1,90 @@ +GL4ES - OpenGL for GLES Hardware +==== + +![gl4es build status](https://api.travis-ci.org/ptitSeb/gl4es.png "gl4es build status") + +This is a library provide OpenGL 2.x functionality for GLES2.0 accelerated Hardware (and of course also support OpenGL 1.5 function, sometimes better then when using GLES 1.1 backend) +There is also support for GLES 1.1 Hardware, emulating OpenGL 1.5, and some OpenGL 2.x+ extensions, but without shaders. + +GL4ES is known to work on many platform: OpenPandora, ODroid, RaspberryPI (2 and 3 at least), PocketCHIP, "otherfruit"PI (like the OrangePI), Android, x86 and x86_64 Linux (tested using mesa-egl). There is also some WIP support for AmigaOS4, using experimental GLES2 driver for Warp3D. + +This library is based on glshim (https://github.com/lunixbochs/glshim) but as now evolved far from it, with different feature set and objectives. Go check this lib if you need things like RemoteGL or TinyGLES (for 100% software rendering). + +The focus is on compatibility and speed with a wide selection of game and software. + +It has been tested successfully of a large selection of games and software, including: Minecraft, OpenMW, SeriousSam (both First and Second Encounters), RVGL (ReVolt GL), TSMC (The Secret Maryo Chronicles), TORCS, SpeedDreams, GL-117, Foobillard(plus), Blender 2.68 to name just a few. I have also some success with Linux port of XNA games, using either MonoGame or FNA. + +Most function of OpenGL up to 1.5 are supported, with some notable exceptions: + * Reading of Depth or Stencil buffer will not work + * GL_FEEDBACK mode is not implemented + * No Accum emulation + +Some known general limitations: + * GL_SELECT as some limitation in its implementation (for exemple, current Depth buffer or binded texture are not taken into account, also custom vertex shader will not work here) + * NPOT texture are supported, but not with GL_REPEAT / GL_MIRRORED, only GL_CLAMP will work properly (unless the GLES Hardware support NPOT) + * Multiple Color attachment on Framebuffer are not supported + * OcclusionQuery is implemented, but with a 0 bits precision + * Probably many other things + +Status of the GLES2 backend + * The FPE (Fixed Pipeline Emulator) has most OpenGL 1.5 drawing call implemented + * The Shader Conversion is really crude, so only simple shaders will work (especialy, the implicit conversion float <-> int is not handled) + * Lighting support double-side and color separation + * FogCoord are supported, along with secondary color + * An ES2 context should be usable (usefull for SDL2) + * OpenGL 2.x games that have been tested include: OpenRA, GZDoom, Danger from the Deep, SuperTuxKart 0.8.1, Hammerwatch, OpenMW, many FNA & MonoGames games (FEZ, Towerfall Ascension, Stardew Valley, Dust, Owlboy, and many other)... + * glxgears works, but FlatShade is not implemented (and will probably never be), so it's slightly different then using GLES1.1 or actuel GL hardware + * GL_TEXTURE_1D, GL_TEXTURE_3D and GL_TEXTURE_RECTANGLE_ARB are not yet supported in shaders (they are supported in fixed pipeline functions), and texture 3D are just a single 2D layer for now. + * Program that link only a GL_FRAGMENT or GL_VERTEX shader are not supported yet. + +Status of the GLES1.1 backend + * Framebuffer use FRAMEBUFFER_OES extension (that must be present in the GLES 1.1 stack) + * Lighting doesn't support double-side or color separation + * FogCoord or Secondary colors are not supported + * GL_TEXTURE_3D are just a single 2D layer (the 1st layer). + +If you use gl4es in your project (as a static or dynamic link), please mention gl4es in you readme / about / whatever. + +---- + +Compiling +---- +How to compile and per-platform specific comment can be found [here](COMPILE.md) + +---- + +GLU +---- + +Standard GLU do works without any issues. You can find a version [here](https://github.com/ptitSeb/GLU) if you need one. + +---- + +Installation +---- + +Put lib/libGL.so.1 in your `LD_LIBRARY_PATH`. +Beware that GL4ES is meant to replace any libGL you can have on your system (like Mesa for example) + +---- + +Usage +---- + +There are many environnement variable to control gl4es behavour, also usable at runtime using `glHint(...)`. + +See [here](USAGE.md) for all variables and what they do. + +---- + +Media (what is working already) +---- + +Some screenshot and youtube links of stuffs that works [here](MEDIA.md) + +---- + +Version history +---- + +The change log is [here](CHANGELOG.md) diff --git a/Projects/Android/jni/SupportLibs/gl4es/USAGE.md b/Projects/Android/jni/SupportLibs/gl4es/USAGE.md new file mode 100644 index 0000000..9e19402 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/USAGE.md @@ -0,0 +1,320 @@ +Usage +---- + +There are many environnement variable to control gl4es behavour. All are numeric, except LIBGL_VERSION that take a string, LIBGL_FBO that takes a 2d size (WxH), and both LIBGL_EGL and LIBGL_GLES that take path/filename. +You can also change many of this variable at runtime using the `glHint(...)` function. See [gl4eshint.h](include/gl4eshint.h) for the list of #define to use in this function. + +##### LIBGL_FB +Controls the Framebuffer output + * 0 : Default, using standard x11 rendering + * 1 : Use Framebuffer output (x11 bypassed, only fullscreen) + * 2 : Use Framebuffer, but also an intermediary FBO + * 3 : Use PBuffer, allowing x11 (and windowed) rendering even if driver doesn't support it + +##### LIBGL_ES +Controls the version of GLES to use + * 0 : Default, using GLES 2.0 backend (unless built with DEFAULT_ES 1) (not on Pandora, still GLES 1.1 backend by default) + * 1 : Use GLES 1.1 backend + * 2 : Use GLES 2.0 backend + +##### LIBGL_GL +Controls the version of OpenGL exposed + * 0 : Default, expose OpenGL 1.5 when using GLES1.1 or OpenGL 2.0 when using GLES2.0 + * 15: Expose OpenGL 1.5 + * 20: Expose OpenGL 2.0 + * 21: Expose OpenGL 2.1 + +##### LIBGL_XREFRESH +Debug helper in specific cases + * 0 : Default, nothing special + * 1 : xrefresh will be called on cleanup + +##### LIBGL_STACKTRACE +Automatic Backtrace log + * 0 : Default, nothing special + * 1 : stacktrace will be printed on crash + +##### LIBGL_FPS +Print current FPS to the console + * 0 : Defaut, don't mesure or printf FPS + * 1 : Print FPS (on stdout) every second + +##### LIBGL_VSYNC +VSync control + * 0 : Default, nothing special + * 1 : vsync enabled + +##### LIBGL_RECYCLEFBO +Recycling FBO special case (don't delete a created FBO, but recycle it if needed) + * 0 : Default, nothing special + * 1 : Recycling of FBO enabled + +##### LIBGL_MIPMAP +Handling of Manual and Automatic MIPMAP + * 0 : Default, nothing special + * 1 : AutoMipMap forced + * 2 : guess AutoMipMap (based on manual mipmaping on textures) + * 3 : ignore MipMap (mipmap creation / use entirely disabled) + * 4 : ignore AutoMipMap on non-squared textures + * 5 : calculate all sub-mipmap one time when uploading level 1 + +##### LIBGL_FORCENPOT +Forcing NPOT (Non-Power of Two) Texture size. + * 0 : Default, nothing special + * 1 : If hardware only support Limited NPOT, then disabling MIPMAP (i.e. LIBGL_MIPMAP=3), so all texture can be NPOT. + If Hardware support full NPOT, do nothing special. Usefull for GLES2 backend where limited NPOT is always supported. + +##### LIBGL_TEXCOPY +Make a local copy of every texture for easy glGetTexImage2D + * 0 : Default, nothing special + * 1 : Texture copy enabled + +##### LIBGL_SHRINK +Texture shrinking control + * 0 : Default, nothing special + * 1 : everything / 2 (using original algorithm for size reduction, all other shink mode use a refined algorithm) + * 2 : only textures wich one size > 512 are / 2 + * 3 : only textures wich one size > 256 are / 2 + * 4 : only textures wich one size > 256 are / 2, and the one > 1024 are / 4 + * 5 : only textures wich one size > 256 are resized to 256 (if possible, because only /2 and /4 exists), but empty texture are not shrinked + * 6 : only textures wich one size > 128 are / 2, thoses >= 512 are resized to 256 (if possible, because only /2 and /4 exists), but empty texture are not shrinked + * 7 : only textures wich one size > 512 are / 2, but empty texture are not shrinked + * 8 : advertise a max texture size *4, but every texture wich one size > 2048 are shrinked to 2048 + * 9 : advertise a max texture size *4, but every texture wich one size > 4096 are / 4 and the one > 512 are / 2, but empty texture are not shrinked + * 10: advertise a max texture size *4, but every texture wich one size > 2048 are / 4 and the one > 512 are / 2, but empty texture are not shrinked + * 11: advertise a max texture size *2, but every texture with one dimension > max texture size will get shrinked to max texture size + +##### LIBGL_TEXDUMP +Texture dump + * 0 : Default, nothing special + * 1 : Texture dump enabled + +##### LIBGL_ALPHAHACK +Experimental: enable Alpha test only when using texture that contains an alpha channel + * 0 : Default, nothing special + * 1 : Alpha Hack enabled + +##### LIBGL_NODOWNSAMPLING +Texture downsampling control (deprecated, use LIBGL_AVOID16BITS instead) + * 0 : Default, DXTc texture are downsampled to 16bits + * 1 : DXTc texture are left as 32bits RGBA + +##### LIBGL_STREAM +PANDORA only: enable Texture Streaming (works only on RGB textures) + * 0 : Default, nothing special + * 1 : Enabled on empty RGB textures + * 2 : Enabled on all RGB textures + +##### LIBGL_COPY +Removed (Controled the glCopyTex(Sub)Image2D hack, it's now automatic, depending on how compatible is the readed framebuffer) + +##### LIBGL_NOLUMALPHA +Control the availability of the LUMUNANCE_ALPHA format (can be buggy on Pandora model CC) + * 0 : Default,GL_LUMINANCE_ALPHA is available and used if needed + * 1 : GL_LUMINANCE_ALPHA hardware support disabled (a GL_RGBA texture will be used instead) + +##### LIBGL_BLENDHACK +Experimental: Change Blend GL_SRC_ALPHA, GL_ONE to GL_ONE, GL_ONE + * 0 : Default, nothing special + * 1 : Change Blend GL_SRC_ALPHA, GL_ONE to GL_ONE, GL_ONE (can be usefull for Xash3D engine) + +##### LIBGL_BLENDCOLOR +Hack: Export a (faked) glBlendColor + * 0 : Default, don't expose gBlendColor + * 1 : Exposed the function (if no hadware support, faked function willbe used) + +##### LIBGL_VERSION +Hack: Control the glGetString version. Overide version string (should be in the form of "1.x") + +##### LIBGL_BATCH +This has been changed with v1.0.5. +Now BATCH simply try to merge subsequents glDrawXXXXX (glDrawArrays, glDrawElements...). It only try to merge if arrays is less the 10*N vertices +The Batching stop when there is a change of GL State, but also if an Array of more then 100*N is encountered. + * 0 : Default: don't try to merge glDrawXXXXX + * N : Any number: try to merger arrays, 1st must be less than 10*N, max is 100*N vertices + +##### LIBGL_NOERROR +Hack: glGetError() always return GL_NOERROR + * 0 : Default, glGetError behave as it should + * 1 : glGetError never fail. + +##### LIBGL_GAMMA +Pandora Hack: Set a Gamma value (in decimal formal, 1.0 means no gamma boost) + * X.Y : Use X.Y as gamma when creating context (typical value can be 1.6 or 2.0) + +##### LIBGL_SRGB +ODROID Hack: Enable sRGB Surface (so Gamma corrected), if Hardware support it + * 0 : Default, don't try to use sRGB surface + * 1 : Enable sRGB Surface (but support will be tested first, must have EGL_KHR_gl_colorspace extension) + +##### LIBGL_FASTMATH +Hack: Activate some Fast Math in processor/coprocessor + * 0 : Default, nothing special + * 1 : On OpenPandora and CHIP, activate "RunFast" on Cortex-A8 (mode default NaN, flush-to-zero) + : Not implemented on other platforms (will do nothing) + +##### LIBGL_SILENTSTUB +Debug: Hide or Show the Sub / Not found message + * 0 : The messages for Stub or absend function are printed + * 1 : Default, don't print the STUB or glXGetProcAddress glXXXXX not found message + +##### LIBGL_NOBANNER +Show/Hide initial text + * 0 : Default, print starting message + * 1 : Silent: no LIBGL message at start (combine with LIBGL_SILENTSTUB for more silence) + +##### LIBGL_NPOT +Expose NPOT (Non Power of Two) Support + * 0 : Default, expose the extension that are availble by the GLES backend + * 1 : Expose limited NPOT extension + * 2 : Expose GL_ARB_texture_non_power_of_two extension + +##### LIBGL_GLQUERIES +Expose glQueries functions + * 0 : Don't expose the function (fake one will be used if called) + * 1 : Default, expose fake functions (always answer 0) + +##### LIBGL_NOTEXMAT +Handling of Texture Matrix + * 0 : Default, perform handling internaly (better handling of NPOT texture on all hardware) + * 1 : Let the driver handle texmat (can be faster in some cases, but NPOT texture may be broken) + +##### LIBGL_NOTEST +Initial Hardware test + * 0 : Default, perform intial hardware testing (using a PBuffer) + * 1 : Do not perform test (no extensions tested or used) + +##### LIBGL_NOVAOCACHE +VAO Caching + * 0 : Default, try to cache vao to avoid memcpy in render list + * 1 : Don't cache VAO + +##### LIBGL_VABGRA +Vertex Array BGRA extension + * 0 : Default, GL_ARB_vertex_array_bgra not exposed (still emulated) + * 1 : Extension exposed may be faster in some cases (Arx Libertatis mainly) + +##### LIBGL_BEGINEND +Merge of subsequent glBegin/glEnd blocks (will be non-effective if BATCH mode is used) + * 0 : Don't try to merge + * 1 : Try to merge, even if there is a glColor / glNormal in between (default) + +##### LIBGL_AVOID16BITS +Try to avoid 16bits textures + * 0 : Default, use 16bits texture if it can avoid a convertion or for DXTc textures + * 1 : Use 32bits texture unless specifically requested (using internalformat) + +##### LIBGL_AVOID24BITS +Try to avoid 24bits textures (i.e. GL_RGB) + * 0 : Default, use 24bits texture when it's possible + * 1 : Force 32bits textures when GL_RGB is asked (as internal or not). Not recommanded, as it may break some blend functions (especialy on GLES 1.1 backend). Does not impact 16bits formats. + +##### LIBGL_FORCE16BITS +Try to use 16bits textures + * 0 : Default, don't force 16bits texture + * 1 : Use 16bits texture instead of 32bits (i.e. use RGBA4 instead of RGBA8 and RGB5 instead of RGB8) + +##### LIBGL_POTFRAMEBUFFER +Use only Power Of Two dimension for Framebuffer + * 0 : Default, use NPOT dimension if supported + * 1 : Force Framebuffer to be created with POT dimension (not advised on GLES2 backend) + +##### LIBGL_NOBGRA +Ignore BGRA Texture hardware extension + * 0 : Default, use BGRA extension if possible + * 1 : Ignore BGRA extension, even if supported by GLES hardware + +##### LIBGL_NOHIGHP +Usage of highp precision in fragment shader (ES2 backend only) + * 0 : Default, use highp if available + * 1 : Disable usage of highp in Fragment shaders + +##### LIBGL_COMMENTS +Comments in shaders are kept (also for generated shaders by fpe_shaders) + * 0 : Default, no comments in shaders sent to GLES Hardware + * 1 : Comments are left in Shaders sent to GLES Hardware + +##### LIBGL_DEFAULTWRAP +Hack to define default WRAP mode for texture +* 0 : Default wrap mode is GL_REPEAT (normal OpenGL behavour): default on NPOT hardware +* 1 : Default wrap mode is GL_CLAMP_TO_EDGE: default on limited NPOT or non-NPOT hardware +* 2 : Default wrap mode is GL_CLAMP_TO_EDGE, enforced (not advised) + +##### LIBGL_FBOMAKECURRENT +Workaround for FBO and glXMakeCurrent (force unbind/bind FBO when changing context) +* 0 : Disabled (Default on most configuration) +* 1 : Enabled (Default if Vendor is ARM or if using LIBGL_FB 1 and 2) + +##### LIBL_FBOUNBIND +Workaround on FBO where a binded texture is used for drawing +* 0 : Disabled (Default for all other configuration) +* 1 : Enabled (Default on ARM and PowerVR hardware) + +##### LIBGL_FBOFORCETEX +For the Color Attachment 0 to be a Texture2D (even if program attachs a Renderbuffer) => may speedup glBlitFramebuffer if used +* 0 : Default, don't force +* 1 : For Color Attachment 0 of FBO to be a texture + +##### LIBGL_FBO +Hack: define custom dimension for FBO (only used with LIBGL_FBO=2) +* WxH : Define FBO of WxH size (ex: LIBGL_FBO=1280x720) + +##### LIBGL_NOTEXARRAY +Hack to force using discrete Texture instead of Array in all shader +* 0 : Default: Array of texture is used in shaders (not in FPE generated ones) +* 1 : Individual texture are forced in shaders (shaders may fail to compile if array are accessed by indice) + +##### LIBGL_LOGSHADERERROR +Log to the console Shader Compile error, with initial and ShaderConv'd source of the shader +* 0 : Default, don't log +* 1 : Log Shader Compilation Errors + +##### LIBGL_SHADERNOGLES +Don't use GL_ES part in shaders +* 0 : Default, let GL_ES part in shader +* 1 : Remove the GL_ES part in shader (usefull for Löve for example) + +##### LIBGL_NODEPTHTEX +Disable the use of Depth texture +* 0 : Default, Use Depth Texture if supported by Hardware +* 1 : Disable the use of Depth Texture (renderbuffer will be used in FBO) + +##### LIBGL_FLOAT +Expose support for FLOAT and HALF_FLOAT Texture support (and has attachement to FBO) +* 0 : Don't exposed, even if supported in hardware +* 1 : Default, exposed what is supported by hardware +* 2 : Force exposed, even if no supported (will be emulated has GL_UNSIGNED_BYTE if not supported) + +##### LIBGL_GLXRECYCLE +Recycle EGLSurface per Drawable, instead of destroying them +* 0 : Default, don't recycle +* 1 : Don't destroy EGLSurface, per reused them per drawable (can fix EGL_BAD_ALLOC error). EGLSurface are never destroyed in this mode for now. + +##### LIBGL_NOCLEAN +Debug: don't clean GLContext when they are destroy +* 0 : Default, clean GLContext +* 1 : Don't clean GLContext + +##### LIBGL_EGL +Define EGL lib to use. Default folder are the standard one for dynamic librarie loading (LD_LIBRARY_PATH and friend) plus "/opt/vc/lib/", /usr/local/lib/" and "/usr/lib/". +* by default try to use libbrcmEGL and libEGL +* filename: try to load from the defaults folder (don't forget to use complete filename, with ".so" extension). If not found/loaded, default one will be tried. +* /path/to/filename: try to use exact path/filename. If not found/loaded, default one will be tried. + +##### LIBGL_GLES +Define GLES(2) lib to use. Default folder are the standard one for dynamic librarie loading (LD_LIBRARY_PATH and friend) plus "/opt/vc/lib/", /usr/local/lib/" and "/usr/lib/". Be sure to point to correct GLES library depanding on wich GLES backend you are using. +* by default try to use libGLESv1_CM, libGLES_CM or libbrcmGLESv1_CM for GLES1.1 and libGLESv2_CM, libGLESv2 or libbrcmGLESv2 for GLES2 backend +* filename: try to load from the defaults folder (don't forget to use complete filename, with ".so" extension). If not found/loaded, default one will be tried. +* /path/to/filename: try to use exact path/filename. If not found/loaded, default one will be tried. + +##### LIBGL_DBGSHADERCONV +Log to the console all shaders before and after conversion +* 0 : Default: don't log anything +* 1 : Log Vertex Shader +* 2 : Log Framegent Shader +* 4 : Log Shaders before going to Shaderconv +* 8 : Log Shaders after going to Shaderconv +Note that you can combine (logical or state. So 14 will be only Fragment shader before and after shaderconv) +Note also that if neither Fragment and Vertex are defined, both will be selected. Same for Before and After. +At last, the value "1" will be changed to "15", to log everything. + diff --git a/Projects/Android/jni/SupportLibs/gl4es/_config.yml b/Projects/Android/jni/SupportLibs/gl4es/_config.yml new file mode 100644 index 0000000..2326bdd --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/_config.yml @@ -0,0 +1,2 @@ +theme: jekyll-theme-hacker +title: GL4ES - The OpenGL driver for GLES Hardware diff --git a/Projects/Android/jni/SupportLibs/gl4es/bc_cat.h b/Projects/Android/jni/SupportLibs/gl4es/bc_cat.h new file mode 100644 index 0000000..3ca0b69 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/bc_cat.h @@ -0,0 +1,84 @@ +/********************************************************************** + * + * Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/ + * Copyright(c) 2008 Imagination Technologies Ltd. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful but, except + * as otherwise stated in writing, without any warranty; without even the + * implied warranty of merchantability or fitness for a particular purpose. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. + * + * The full GNU General Public License is included in this distribution in + * the file called "COPYING". + * + * Contact Information: + * Imagination Technologies Ltd. + * Home Park Estate, Kings Langley, Herts, WD4 8LZ, UK + * + ******************************************************************************/ + +#ifndef __BC_CAT_H__ +#define __BC_CAT_H__ + +#include + +#define BC_FOURCC(a,b,c,d) \ + ((unsigned long) ((a) | (b)<<8 | (c)<<16 | (d)<<24)) + +#define BC_PIX_FMT_NV12 BC_FOURCC('N', 'V', '1', '2') /*YUV 4:2:0*/ +#define BC_PIX_FMT_UYVY BC_FOURCC('U', 'Y', 'V', 'Y') /*YUV 4:2:2*/ +#define BC_PIX_FMT_YUYV BC_FOURCC('Y', 'U', 'Y', 'V') /*YUV 4:2:2*/ +#define BC_PIX_FMT_RGB565 BC_FOURCC('R', 'G', 'B', 'P') /*RGB 5:6:5*/ + +enum BC_memory { + BC_MEMORY_MMAP = 1, + BC_MEMORY_USERPTR = 2, +}; + +typedef struct BCIO_package_TAG { + int input; + int output; +}BCIO_package; + +/* + * the following types are tested for fourcc in struct bc_buf_params_t + * NV12 + * UYVY + * RGB565 - not tested yet + * YUYV + */ +typedef struct bc_buf_params { + int count; /*number of buffers, [in/out]*/ + int width; /*buffer width in pixel, multiple of 8 or 32*/ + int height; /*buffer height in pixel*/ + unsigned int fourcc; /*buffer pixel format*/ + enum BC_memory type; +} bc_buf_params_t; + +typedef struct bc_buf_ptr { + unsigned int index; + int size; + unsigned long pa; +} bc_buf_ptr_t; + +#define BCIO_GID 'g' +#define BC_IOWR(INDEX) _IOWR(BCIO_GID, INDEX, BCIO_package) + +#define BCIOGET_BUFFERCOUNT BC_IOWR(0) /*obsolete, since BCIOREQ_BUFFERS + return the number of buffers*/ +#define BCIOGET_BUFFERPHYADDR BC_IOWR(1) /*get physical address by index*/ +#define BCIOGET_BUFFERIDX BC_IOWR(2) /*get index by physical address*/ + +#define BCIOREQ_BUFFERS BC_IOWR(3) +#define BCIOSET_BUFFERPHYADDR BC_IOWR(4) + +#endif + diff --git a/Projects/Android/jni/SupportLibs/gl4es/include/EGL/egl.h b/Projects/Android/jni/SupportLibs/gl4es/include/EGL/egl.h new file mode 100644 index 0000000..99ea342 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/include/EGL/egl.h @@ -0,0 +1,329 @@ +/* -*- mode: c; tab-width: 8; -*- */ +/* vi: set sw=4 ts=8: */ +/* Reference version of egl.h for EGL 1.4. + * $Revision: 9356 $ on $Date: 2009-10-21 02:52:25 -0700 (Wed, 21 Oct 2009) $ + */ + +/* +** Copyright (c) 2007-2009 The Khronos Group Inc. +** +** Permission is hereby granted, free of charge, to any person obtaining a +** copy of this software and/or associated documentation files (the +** "Materials"), to deal in the Materials without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Materials, and to +** permit persons to whom the Materials are furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be included +** in all copies or substantial portions of the Materials. +** +** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. +*/ + +#ifndef __egl_h_ +#define __egl_h_ + +/* All platform-dependent types and macro boilerplate (such as EGLAPI + * and EGLAPIENTRY) should go in eglplatform.h. + */ +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* EGL Types */ +/* EGLint is defined in eglplatform.h */ +typedef unsigned int EGLBoolean; +typedef unsigned int EGLenum; +typedef void *EGLConfig; +typedef void *EGLContext; +typedef void *EGLDisplay; +typedef void *EGLSurface; +typedef void *EGLClientBuffer; + +/* EGL Versioning */ +#define EGL_VERSION_1_0 1 +#define EGL_VERSION_1_1 1 +#define EGL_VERSION_1_2 1 +#define EGL_VERSION_1_3 1 +#define EGL_VERSION_1_4 1 + +/* EGL Enumerants. Bitmasks and other exceptional cases aside, most + * enums are assigned unique values starting at 0x3000. + */ + +/* EGL aliases */ +#define EGL_FALSE 0 +#define EGL_TRUE 1 + +/* Out-of-band handle values */ +#define EGL_DEFAULT_DISPLAY ((EGLNativeDisplayType)0) +#define EGL_NO_CONTEXT ((EGLContext)0) +#define EGL_NO_DISPLAY ((EGLDisplay)0) +#define EGL_NO_SURFACE ((EGLSurface)0) + +/* Out-of-band attribute value */ +#define EGL_DONT_CARE ((EGLint)-1) + +/* Errors / GetError return values */ +#define EGL_SUCCESS 0x3000 +#define EGL_NOT_INITIALIZED 0x3001 +#define EGL_BAD_ACCESS 0x3002 +#define EGL_BAD_ALLOC 0x3003 +#define EGL_BAD_ATTRIBUTE 0x3004 +#define EGL_BAD_CONFIG 0x3005 +#define EGL_BAD_CONTEXT 0x3006 +#define EGL_BAD_CURRENT_SURFACE 0x3007 +#define EGL_BAD_DISPLAY 0x3008 +#define EGL_BAD_MATCH 0x3009 +#define EGL_BAD_NATIVE_PIXMAP 0x300A +#define EGL_BAD_NATIVE_WINDOW 0x300B +#define EGL_BAD_PARAMETER 0x300C +#define EGL_BAD_SURFACE 0x300D +#define EGL_CONTEXT_LOST 0x300E /* EGL 1.1 - IMG_power_management */ + +/* Reserved 0x300F-0x301F for additional errors */ + +/* Config attributes */ +#define EGL_BUFFER_SIZE 0x3020 +#define EGL_ALPHA_SIZE 0x3021 +#define EGL_BLUE_SIZE 0x3022 +#define EGL_GREEN_SIZE 0x3023 +#define EGL_RED_SIZE 0x3024 +#define EGL_DEPTH_SIZE 0x3025 +#define EGL_STENCIL_SIZE 0x3026 +#define EGL_CONFIG_CAVEAT 0x3027 +#define EGL_CONFIG_ID 0x3028 +#define EGL_LEVEL 0x3029 +#define EGL_MAX_PBUFFER_HEIGHT 0x302A +#define EGL_MAX_PBUFFER_PIXELS 0x302B +#define EGL_MAX_PBUFFER_WIDTH 0x302C +#define EGL_NATIVE_RENDERABLE 0x302D +#define EGL_NATIVE_VISUAL_ID 0x302E +#define EGL_NATIVE_VISUAL_TYPE 0x302F +#define EGL_SAMPLES 0x3031 +#define EGL_SAMPLE_BUFFERS 0x3032 +#define EGL_SURFACE_TYPE 0x3033 +#define EGL_TRANSPARENT_TYPE 0x3034 +#define EGL_TRANSPARENT_BLUE_VALUE 0x3035 +#define EGL_TRANSPARENT_GREEN_VALUE 0x3036 +#define EGL_TRANSPARENT_RED_VALUE 0x3037 +#define EGL_NONE 0x3038 /* Attrib list terminator */ +#define EGL_BIND_TO_TEXTURE_RGB 0x3039 +#define EGL_BIND_TO_TEXTURE_RGBA 0x303A +#define EGL_MIN_SWAP_INTERVAL 0x303B +#define EGL_MAX_SWAP_INTERVAL 0x303C +#define EGL_LUMINANCE_SIZE 0x303D +#define EGL_ALPHA_MASK_SIZE 0x303E +#define EGL_COLOR_BUFFER_TYPE 0x303F +#define EGL_RENDERABLE_TYPE 0x3040 +#define EGL_MATCH_NATIVE_PIXMAP 0x3041 /* Pseudo-attribute (not queryable) */ +#define EGL_CONFORMANT 0x3042 + +/* Reserved 0x3041-0x304F for additional config attributes */ + +/* Config attribute values */ +#define EGL_SLOW_CONFIG 0x3050 /* EGL_CONFIG_CAVEAT value */ +#define EGL_NON_CONFORMANT_CONFIG 0x3051 /* EGL_CONFIG_CAVEAT value */ +#define EGL_TRANSPARENT_RGB 0x3052 /* EGL_TRANSPARENT_TYPE value */ +#define EGL_RGB_BUFFER 0x308E /* EGL_COLOR_BUFFER_TYPE value */ +#define EGL_LUMINANCE_BUFFER 0x308F /* EGL_COLOR_BUFFER_TYPE value */ + +/* More config attribute values, for EGL_TEXTURE_FORMAT */ +#define EGL_NO_TEXTURE 0x305C +#define EGL_TEXTURE_RGB 0x305D +#define EGL_TEXTURE_RGBA 0x305E +#define EGL_TEXTURE_2D 0x305F + +/* Config attribute mask bits */ +#define EGL_PBUFFER_BIT 0x0001 /* EGL_SURFACE_TYPE mask bits */ +#define EGL_PIXMAP_BIT 0x0002 /* EGL_SURFACE_TYPE mask bits */ +#define EGL_WINDOW_BIT 0x0004 /* EGL_SURFACE_TYPE mask bits */ +#define EGL_VG_COLORSPACE_LINEAR_BIT 0x0020 /* EGL_SURFACE_TYPE mask bits */ +#define EGL_VG_ALPHA_FORMAT_PRE_BIT 0x0040 /* EGL_SURFACE_TYPE mask bits */ +#define EGL_MULTISAMPLE_RESOLVE_BOX_BIT 0x0200 /* EGL_SURFACE_TYPE mask bits */ +#define EGL_SWAP_BEHAVIOR_PRESERVED_BIT 0x0400 /* EGL_SURFACE_TYPE mask bits */ + +#define EGL_OPENGL_ES_BIT 0x0001 /* EGL_RENDERABLE_TYPE mask bits */ +#define EGL_OPENVG_BIT 0x0002 /* EGL_RENDERABLE_TYPE mask bits */ +#define EGL_OPENGL_ES2_BIT 0x0004 /* EGL_RENDERABLE_TYPE mask bits */ +#define EGL_OPENGL_BIT 0x0008 /* EGL_RENDERABLE_TYPE mask bits */ + +/* QueryString targets */ +#define EGL_VENDOR 0x3053 +#define EGL_VERSION 0x3054 +#define EGL_EXTENSIONS 0x3055 +#define EGL_CLIENT_APIS 0x308D + +/* QuerySurface / SurfaceAttrib / CreatePbufferSurface targets */ +#define EGL_HEIGHT 0x3056 +#define EGL_WIDTH 0x3057 +#define EGL_LARGEST_PBUFFER 0x3058 +#define EGL_TEXTURE_FORMAT 0x3080 +#define EGL_TEXTURE_TARGET 0x3081 +#define EGL_MIPMAP_TEXTURE 0x3082 +#define EGL_MIPMAP_LEVEL 0x3083 +#define EGL_RENDER_BUFFER 0x3086 +#define EGL_VG_COLORSPACE 0x3087 +#define EGL_VG_ALPHA_FORMAT 0x3088 +#define EGL_HORIZONTAL_RESOLUTION 0x3090 +#define EGL_VERTICAL_RESOLUTION 0x3091 +#define EGL_PIXEL_ASPECT_RATIO 0x3092 +#define EGL_SWAP_BEHAVIOR 0x3093 +#define EGL_MULTISAMPLE_RESOLVE 0x3099 + +/* EGL_RENDER_BUFFER values / BindTexImage / ReleaseTexImage buffer targets */ +#define EGL_BACK_BUFFER 0x3084 +#define EGL_SINGLE_BUFFER 0x3085 + +/* OpenVG color spaces */ +#define EGL_VG_COLORSPACE_sRGB 0x3089 /* EGL_VG_COLORSPACE value */ +#define EGL_VG_COLORSPACE_LINEAR 0x308A /* EGL_VG_COLORSPACE value */ + +/* OpenVG alpha formats */ +#define EGL_VG_ALPHA_FORMAT_NONPRE 0x308B /* EGL_ALPHA_FORMAT value */ +#define EGL_VG_ALPHA_FORMAT_PRE 0x308C /* EGL_ALPHA_FORMAT value */ + +/* Constant scale factor by which fractional display resolutions & + * aspect ratio are scaled when queried as integer values. + */ +#define EGL_DISPLAY_SCALING 10000 + +/* Unknown display resolution/aspect ratio */ +#define EGL_UNKNOWN ((EGLint)-1) + +/* Back buffer swap behaviors */ +#define EGL_BUFFER_PRESERVED 0x3094 /* EGL_SWAP_BEHAVIOR value */ +#define EGL_BUFFER_DESTROYED 0x3095 /* EGL_SWAP_BEHAVIOR value */ + +/* CreatePbufferFromClientBuffer buffer types */ +#define EGL_OPENVG_IMAGE 0x3096 + +/* QueryContext targets */ +#define EGL_CONTEXT_CLIENT_TYPE 0x3097 + +/* CreateContext attributes */ +#define EGL_CONTEXT_CLIENT_VERSION 0x3098 + +/* Multisample resolution behaviors */ +#define EGL_MULTISAMPLE_RESOLVE_DEFAULT 0x309A /* EGL_MULTISAMPLE_RESOLVE value */ +#define EGL_MULTISAMPLE_RESOLVE_BOX 0x309B /* EGL_MULTISAMPLE_RESOLVE value */ + +/* BindAPI/QueryAPI targets */ +#define EGL_OPENGL_ES_API 0x30A0 +#define EGL_OPENVG_API 0x30A1 +#define EGL_OPENGL_API 0x30A2 + +/* GetCurrentSurface targets */ +#define EGL_DRAW 0x3059 +#define EGL_READ 0x305A + +/* WaitNative engines */ +#define EGL_CORE_NATIVE_ENGINE 0x305B + +/* EGL 1.2 tokens renamed for consistency in EGL 1.3 */ +#define EGL_COLORSPACE EGL_VG_COLORSPACE +#define EGL_ALPHA_FORMAT EGL_VG_ALPHA_FORMAT +#define EGL_COLORSPACE_sRGB EGL_VG_COLORSPACE_sRGB +#define EGL_COLORSPACE_LINEAR EGL_VG_COLORSPACE_LINEAR +#define EGL_ALPHA_FORMAT_NONPRE EGL_VG_ALPHA_FORMAT_NONPRE +#define EGL_ALPHA_FORMAT_PRE EGL_VG_ALPHA_FORMAT_PRE + +/* EGL extensions must request enum blocks from the Khronos + * API Registrar, who maintains the enumerant registry. Submit + * a bug in Khronos Bugzilla against task "Registry". + */ + + + +/* EGL Functions */ + +EGLAPI EGLint EGLAPIENTRY eglGetError(void); + +EGLAPI EGLDisplay EGLAPIENTRY eglGetDisplay(EGLNativeDisplayType display_id); +EGLAPI EGLBoolean EGLAPIENTRY eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor); +EGLAPI EGLBoolean EGLAPIENTRY eglTerminate(EGLDisplay dpy); + +EGLAPI const char * EGLAPIENTRY eglQueryString(EGLDisplay dpy, EGLint name); + +EGLAPI EGLBoolean EGLAPIENTRY eglGetConfigs(EGLDisplay dpy, EGLConfig *configs, + EGLint config_size, EGLint *num_config); +EGLAPI EGLBoolean EGLAPIENTRY eglChooseConfig(EGLDisplay dpy, const EGLint *attrib_list, + EGLConfig *configs, EGLint config_size, + EGLint *num_config); +EGLAPI EGLBoolean EGLAPIENTRY eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config, + EGLint attribute, EGLint *value); + +EGLAPI EGLSurface EGLAPIENTRY eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config, + EGLNativeWindowType win, + const EGLint *attrib_list); +EGLAPI EGLSurface EGLAPIENTRY eglCreatePbufferSurface(EGLDisplay dpy, EGLConfig config, + const EGLint *attrib_list); +EGLAPI EGLSurface EGLAPIENTRY eglCreatePixmapSurface(EGLDisplay dpy, EGLConfig config, + EGLNativePixmapType pixmap, + const EGLint *attrib_list); +EGLAPI EGLBoolean EGLAPIENTRY eglDestroySurface(EGLDisplay dpy, EGLSurface surface); +EGLAPI EGLBoolean EGLAPIENTRY eglQuerySurface(EGLDisplay dpy, EGLSurface surface, + EGLint attribute, EGLint *value); + +EGLAPI EGLBoolean EGLAPIENTRY eglBindAPI(EGLenum api); +EGLAPI EGLenum EGLAPIENTRY eglQueryAPI(void); + +EGLAPI EGLBoolean EGLAPIENTRY eglWaitClient(void); + +EGLAPI EGLBoolean EGLAPIENTRY eglReleaseThread(void); + +EGLAPI EGLSurface EGLAPIENTRY eglCreatePbufferFromClientBuffer( + EGLDisplay dpy, EGLenum buftype, EGLClientBuffer buffer, + EGLConfig config, const EGLint *attrib_list); + +EGLAPI EGLBoolean EGLAPIENTRY eglSurfaceAttrib(EGLDisplay dpy, EGLSurface surface, + EGLint attribute, EGLint value); +EGLAPI EGLBoolean EGLAPIENTRY eglBindTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer); +EGLAPI EGLBoolean EGLAPIENTRY eglReleaseTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer); + + +EGLAPI EGLBoolean EGLAPIENTRY eglSwapInterval(EGLDisplay dpy, EGLint interval); + + +EGLAPI EGLContext EGLAPIENTRY eglCreateContext(EGLDisplay dpy, EGLConfig config, + EGLContext share_context, + const EGLint *attrib_list); +EGLAPI EGLBoolean EGLAPIENTRY eglDestroyContext(EGLDisplay dpy, EGLContext ctx); +EGLAPI EGLBoolean EGLAPIENTRY eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, + EGLSurface read, EGLContext ctx); + +EGLAPI EGLContext EGLAPIENTRY eglGetCurrentContext(void); +EGLAPI EGLSurface EGLAPIENTRY eglGetCurrentSurface(EGLint readdraw); +EGLAPI EGLDisplay EGLAPIENTRY eglGetCurrentDisplay(void); +EGLAPI EGLBoolean EGLAPIENTRY eglQueryContext(EGLDisplay dpy, EGLContext ctx, + EGLint attribute, EGLint *value); + +EGLAPI EGLBoolean EGLAPIENTRY eglWaitGL(void); +EGLAPI EGLBoolean EGLAPIENTRY eglWaitNative(EGLint engine); +EGLAPI EGLBoolean EGLAPIENTRY eglSwapBuffers(EGLDisplay dpy, EGLSurface surface); +EGLAPI EGLBoolean EGLAPIENTRY eglCopyBuffers(EGLDisplay dpy, EGLSurface surface, + EGLNativePixmapType target); + +/* This is a generic function pointer type, whose name indicates it must + * be cast to the proper type *and calling convention* before use. + */ +typedef void (*__eglMustCastToProperFunctionPointerType)(void); + +/* Now, define eglGetProcAddress using the generic function ptr. type */ +EGLAPI __eglMustCastToProperFunctionPointerType EGLAPIENTRY + eglGetProcAddress(const char *procname); + +#ifdef __cplusplus +} +#endif + +#endif /* __egl_h_ */ diff --git a/Projects/Android/jni/SupportLibs/gl4es/include/EGL/eglext.h b/Projects/Android/jni/SupportLibs/gl4es/include/EGL/eglext.h new file mode 100644 index 0000000..93a7365 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/include/EGL/eglext.h @@ -0,0 +1,477 @@ +#ifndef __eglext_h_ +#define __eglext_h_ + +#ifdef __cplusplus +extern "C" { +#endif + +/* +** Copyright (c) 2007-2012 The Khronos Group Inc. +** +** Permission is hereby granted, free of charge, to any person obtaining a +** copy of this software and/or associated documentation files (the +** "Materials"), to deal in the Materials without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Materials, and to +** permit persons to whom the Materials are furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be included +** in all copies or substantial portions of the Materials. +** +** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. +*/ + +#include + +/*************************************************************/ + +/* Header file version number */ +/* Current version at http://www.khronos.org/registry/egl/ */ +/* $Revision: 19571 $ on $Date: 2012-10-31 10:10:33 -0700 (Wed, 31 Oct 2012) $ */ +#define EGL_EGLEXT_VERSION 14 + +#ifndef EGL_KHR_config_attribs +#define EGL_KHR_config_attribs 1 +#define EGL_CONFORMANT_KHR 0x3042 /* EGLConfig attribute */ +#define EGL_VG_COLORSPACE_LINEAR_BIT_KHR 0x0020 /* EGL_SURFACE_TYPE bitfield */ +#define EGL_VG_ALPHA_FORMAT_PRE_BIT_KHR 0x0040 /* EGL_SURFACE_TYPE bitfield */ +#endif + +#ifndef EGL_KHR_lock_surface +#define EGL_KHR_lock_surface 1 +#define EGL_READ_SURFACE_BIT_KHR 0x0001 /* EGL_LOCK_USAGE_HINT_KHR bitfield */ +#define EGL_WRITE_SURFACE_BIT_KHR 0x0002 /* EGL_LOCK_USAGE_HINT_KHR bitfield */ +#define EGL_LOCK_SURFACE_BIT_KHR 0x0080 /* EGL_SURFACE_TYPE bitfield */ +#define EGL_OPTIMAL_FORMAT_BIT_KHR 0x0100 /* EGL_SURFACE_TYPE bitfield */ +#define EGL_MATCH_FORMAT_KHR 0x3043 /* EGLConfig attribute */ +#define EGL_FORMAT_RGB_565_EXACT_KHR 0x30C0 /* EGL_MATCH_FORMAT_KHR value */ +#define EGL_FORMAT_RGB_565_KHR 0x30C1 /* EGL_MATCH_FORMAT_KHR value */ +#define EGL_FORMAT_RGBA_8888_EXACT_KHR 0x30C2 /* EGL_MATCH_FORMAT_KHR value */ +#define EGL_FORMAT_RGBA_8888_KHR 0x30C3 /* EGL_MATCH_FORMAT_KHR value */ +#define EGL_MAP_PRESERVE_PIXELS_KHR 0x30C4 /* eglLockSurfaceKHR attribute */ +#define EGL_LOCK_USAGE_HINT_KHR 0x30C5 /* eglLockSurfaceKHR attribute */ +#define EGL_BITMAP_POINTER_KHR 0x30C6 /* eglQuerySurface attribute */ +#define EGL_BITMAP_PITCH_KHR 0x30C7 /* eglQuerySurface attribute */ +#define EGL_BITMAP_ORIGIN_KHR 0x30C8 /* eglQuerySurface attribute */ +#define EGL_BITMAP_PIXEL_RED_OFFSET_KHR 0x30C9 /* eglQuerySurface attribute */ +#define EGL_BITMAP_PIXEL_GREEN_OFFSET_KHR 0x30CA /* eglQuerySurface attribute */ +#define EGL_BITMAP_PIXEL_BLUE_OFFSET_KHR 0x30CB /* eglQuerySurface attribute */ +#define EGL_BITMAP_PIXEL_ALPHA_OFFSET_KHR 0x30CC /* eglQuerySurface attribute */ +#define EGL_BITMAP_PIXEL_LUMINANCE_OFFSET_KHR 0x30CD /* eglQuerySurface attribute */ +#define EGL_LOWER_LEFT_KHR 0x30CE /* EGL_BITMAP_ORIGIN_KHR value */ +#define EGL_UPPER_LEFT_KHR 0x30CF /* EGL_BITMAP_ORIGIN_KHR value */ +#ifdef EGL_EGLEXT_PROTOTYPES +EGLAPI EGLBoolean EGLAPIENTRY eglLockSurfaceKHR (EGLDisplay display, EGLSurface surface, const EGLint *attrib_list); +EGLAPI EGLBoolean EGLAPIENTRY eglUnlockSurfaceKHR (EGLDisplay display, EGLSurface surface); +#endif /* EGL_EGLEXT_PROTOTYPES */ +typedef EGLBoolean (EGLAPIENTRYP PFNEGLLOCKSURFACEKHRPROC) (EGLDisplay display, EGLSurface surface, const EGLint *attrib_list); +typedef EGLBoolean (EGLAPIENTRYP PFNEGLUNLOCKSURFACEKHRPROC) (EGLDisplay display, EGLSurface surface); +#endif + +#ifndef EGL_KHR_image +#define EGL_KHR_image 1 +#define EGL_NATIVE_PIXMAP_KHR 0x30B0 /* eglCreateImageKHR target */ +typedef void *EGLImageKHR; +#define EGL_NO_IMAGE_KHR ((EGLImageKHR)0) +#ifdef EGL_EGLEXT_PROTOTYPES +EGLAPI EGLImageKHR EGLAPIENTRY eglCreateImageKHR (EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *attrib_list); +EGLAPI EGLBoolean EGLAPIENTRY eglDestroyImageKHR (EGLDisplay dpy, EGLImageKHR image); +#endif /* EGL_EGLEXT_PROTOTYPES */ +typedef EGLImageKHR (EGLAPIENTRYP PFNEGLCREATEIMAGEKHRPROC) (EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *attrib_list); +typedef EGLBoolean (EGLAPIENTRYP PFNEGLDESTROYIMAGEKHRPROC) (EGLDisplay dpy, EGLImageKHR image); +#endif + +#ifndef EGL_KHR_vg_parent_image +#define EGL_KHR_vg_parent_image 1 +#define EGL_VG_PARENT_IMAGE_KHR 0x30BA /* eglCreateImageKHR target */ +#endif + +#ifndef EGL_KHR_gl_texture_2D_image +#define EGL_KHR_gl_texture_2D_image 1 +#define EGL_GL_TEXTURE_2D_KHR 0x30B1 /* eglCreateImageKHR target */ +#define EGL_GL_TEXTURE_LEVEL_KHR 0x30BC /* eglCreateImageKHR attribute */ +#endif + +#ifndef EGL_KHR_gl_texture_cubemap_image +#define EGL_KHR_gl_texture_cubemap_image 1 +#define EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_X_KHR 0x30B3 /* eglCreateImageKHR target */ +#define EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_X_KHR 0x30B4 /* eglCreateImageKHR target */ +#define EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Y_KHR 0x30B5 /* eglCreateImageKHR target */ +#define EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_KHR 0x30B6 /* eglCreateImageKHR target */ +#define EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Z_KHR 0x30B7 /* eglCreateImageKHR target */ +#define EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_KHR 0x30B8 /* eglCreateImageKHR target */ +#endif + +#ifndef EGL_KHR_gl_texture_3D_image +#define EGL_KHR_gl_texture_3D_image 1 +#define EGL_GL_TEXTURE_3D_KHR 0x30B2 /* eglCreateImageKHR target */ +#define EGL_GL_TEXTURE_ZOFFSET_KHR 0x30BD /* eglCreateImageKHR attribute */ +#endif + +#ifndef EGL_KHR_gl_renderbuffer_image +#define EGL_KHR_gl_renderbuffer_image 1 +#define EGL_GL_RENDERBUFFER_KHR 0x30B9 /* eglCreateImageKHR target */ +#endif + +#if KHRONOS_SUPPORT_INT64 /* EGLTimeKHR requires 64-bit uint support */ +#ifndef EGL_KHR_reusable_sync +#define EGL_KHR_reusable_sync 1 + +typedef void* EGLSyncKHR; +typedef khronos_utime_nanoseconds_t EGLTimeKHR; + +#define EGL_SYNC_STATUS_KHR 0x30F1 +#define EGL_SIGNALED_KHR 0x30F2 +#define EGL_UNSIGNALED_KHR 0x30F3 +#define EGL_TIMEOUT_EXPIRED_KHR 0x30F5 +#define EGL_CONDITION_SATISFIED_KHR 0x30F6 +#define EGL_SYNC_TYPE_KHR 0x30F7 +#define EGL_SYNC_REUSABLE_KHR 0x30FA +#define EGL_SYNC_FLUSH_COMMANDS_BIT_KHR 0x0001 /* eglClientWaitSyncKHR bitfield */ +#define EGL_FOREVER_KHR 0xFFFFFFFFFFFFFFFFull +#define EGL_NO_SYNC_KHR ((EGLSyncKHR)0) +#ifdef EGL_EGLEXT_PROTOTYPES +EGLAPI EGLSyncKHR EGLAPIENTRY eglCreateSyncKHR(EGLDisplay dpy, EGLenum type, const EGLint *attrib_list); +EGLAPI EGLBoolean EGLAPIENTRY eglDestroySyncKHR(EGLDisplay dpy, EGLSyncKHR sync); +EGLAPI EGLint EGLAPIENTRY eglClientWaitSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLint flags, EGLTimeKHR timeout); +EGLAPI EGLBoolean EGLAPIENTRY eglSignalSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLenum mode); +EGLAPI EGLBoolean EGLAPIENTRY eglGetSyncAttribKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLint attribute, EGLint *value); +#endif /* EGL_EGLEXT_PROTOTYPES */ +typedef EGLSyncKHR (EGLAPIENTRYP PFNEGLCREATESYNCKHRPROC) (EGLDisplay dpy, EGLenum type, const EGLint *attrib_list); +typedef EGLBoolean (EGLAPIENTRYP PFNEGLDESTROYSYNCKHRPROC) (EGLDisplay dpy, EGLSyncKHR sync); +typedef EGLint (EGLAPIENTRYP PFNEGLCLIENTWAITSYNCKHRPROC) (EGLDisplay dpy, EGLSyncKHR sync, EGLint flags, EGLTimeKHR timeout); +typedef EGLBoolean (EGLAPIENTRYP PFNEGLSIGNALSYNCKHRPROC) (EGLDisplay dpy, EGLSyncKHR sync, EGLenum mode); +typedef EGLBoolean (EGLAPIENTRYP PFNEGLGETSYNCATTRIBKHRPROC) (EGLDisplay dpy, EGLSyncKHR sync, EGLint attribute, EGLint *value); +#endif +#endif + +#ifndef EGL_KHR_image_base +#define EGL_KHR_image_base 1 +/* Most interfaces defined by EGL_KHR_image_pixmap above */ +#define EGL_IMAGE_PRESERVED_KHR 0x30D2 /* eglCreateImageKHR attribute */ +#endif + +#ifndef EGL_KHR_image_pixmap +#define EGL_KHR_image_pixmap 1 +/* Interfaces defined by EGL_KHR_image above */ +#endif + +#ifndef EGL_IMG_context_priority +#define EGL_IMG_context_priority 1 +#define EGL_CONTEXT_PRIORITY_LEVEL_IMG 0x3100 +#define EGL_CONTEXT_PRIORITY_HIGH_IMG 0x3101 +#define EGL_CONTEXT_PRIORITY_MEDIUM_IMG 0x3102 +#define EGL_CONTEXT_PRIORITY_LOW_IMG 0x3103 +#endif + +#ifndef EGL_KHR_lock_surface2 +#define EGL_KHR_lock_surface2 1 +#define EGL_BITMAP_PIXEL_SIZE_KHR 0x3110 +#endif + +#ifndef EGL_NV_coverage_sample +#define EGL_NV_coverage_sample 1 +#define EGL_COVERAGE_BUFFERS_NV 0x30E0 +#define EGL_COVERAGE_SAMPLES_NV 0x30E1 +#endif + +#ifndef EGL_NV_depth_nonlinear +#define EGL_NV_depth_nonlinear 1 +#define EGL_DEPTH_ENCODING_NV 0x30E2 +#define EGL_DEPTH_ENCODING_NONE_NV 0 +#define EGL_DEPTH_ENCODING_NONLINEAR_NV 0x30E3 +#endif + +#if KHRONOS_SUPPORT_INT64 /* EGLTimeNV requires 64-bit uint support */ +#ifndef EGL_NV_sync +#define EGL_NV_sync 1 +#define EGL_SYNC_PRIOR_COMMANDS_COMPLETE_NV 0x30E6 +#define EGL_SYNC_STATUS_NV 0x30E7 +#define EGL_SIGNALED_NV 0x30E8 +#define EGL_UNSIGNALED_NV 0x30E9 +#define EGL_SYNC_FLUSH_COMMANDS_BIT_NV 0x0001 +#define EGL_FOREVER_NV 0xFFFFFFFFFFFFFFFFull +#define EGL_ALREADY_SIGNALED_NV 0x30EA +#define EGL_TIMEOUT_EXPIRED_NV 0x30EB +#define EGL_CONDITION_SATISFIED_NV 0x30EC +#define EGL_SYNC_TYPE_NV 0x30ED +#define EGL_SYNC_CONDITION_NV 0x30EE +#define EGL_SYNC_FENCE_NV 0x30EF +#define EGL_NO_SYNC_NV ((EGLSyncNV)0) +typedef void* EGLSyncNV; +typedef khronos_utime_nanoseconds_t EGLTimeNV; +#ifdef EGL_EGLEXT_PROTOTYPES +EGLAPI EGLSyncNV EGLAPIENTRY eglCreateFenceSyncNV (EGLDisplay dpy, EGLenum condition, const EGLint *attrib_list); +EGLAPI EGLBoolean EGLAPIENTRY eglDestroySyncNV (EGLSyncNV sync); +EGLAPI EGLBoolean EGLAPIENTRY eglFenceNV (EGLSyncNV sync); +EGLAPI EGLint EGLAPIENTRY eglClientWaitSyncNV (EGLSyncNV sync, EGLint flags, EGLTimeNV timeout); +EGLAPI EGLBoolean EGLAPIENTRY eglSignalSyncNV (EGLSyncNV sync, EGLenum mode); +EGLAPI EGLBoolean EGLAPIENTRY eglGetSyncAttribNV (EGLSyncNV sync, EGLint attribute, EGLint *value); +#endif /* EGL_EGLEXT_PROTOTYPES */ +typedef EGLSyncNV (EGLAPIENTRYP PFNEGLCREATEFENCESYNCNVPROC) (EGLDisplay dpy, EGLenum condition, const EGLint *attrib_list); +typedef EGLBoolean (EGLAPIENTRYP PFNEGLDESTROYSYNCNVPROC) (EGLSyncNV sync); +typedef EGLBoolean (EGLAPIENTRYP PFNEGLFENCENVPROC) (EGLSyncNV sync); +typedef EGLint (EGLAPIENTRYP PFNEGLCLIENTWAITSYNCNVPROC) (EGLSyncNV sync, EGLint flags, EGLTimeNV timeout); +typedef EGLBoolean (EGLAPIENTRYP PFNEGLSIGNALSYNCNVPROC) (EGLSyncNV sync, EGLenum mode); +typedef EGLBoolean (EGLAPIENTRYP PFNEGLGETSYNCATTRIBNVPROC) (EGLSyncNV sync, EGLint attribute, EGLint *value); +#endif +#endif + +#if KHRONOS_SUPPORT_INT64 /* Dependent on EGL_KHR_reusable_sync which requires 64-bit uint support */ +#ifndef EGL_KHR_fence_sync +#define EGL_KHR_fence_sync 1 +/* Reuses most tokens and entry points from EGL_KHR_reusable_sync */ +#define EGL_SYNC_PRIOR_COMMANDS_COMPLETE_KHR 0x30F0 +#define EGL_SYNC_CONDITION_KHR 0x30F8 +#define EGL_SYNC_FENCE_KHR 0x30F9 +#endif +#endif + +#ifndef EGL_HI_clientpixmap +#define EGL_HI_clientpixmap 1 + +/* Surface Attribute */ +#define EGL_CLIENT_PIXMAP_POINTER_HI 0x8F74 +/* + * Structure representing a client pixmap + * (pixmap's data is in client-space memory). + */ +struct EGLClientPixmapHI +{ + void* pData; + EGLint iWidth; + EGLint iHeight; + EGLint iStride; +}; + +#ifdef EGL_EGLEXT_PROTOTYPES +EGLAPI EGLSurface EGLAPIENTRY eglCreatePixmapSurfaceHI(EGLDisplay dpy, EGLConfig config, struct EGLClientPixmapHI* pixmap); +#endif /* EGL_EGLEXT_PROTOTYPES */ +typedef EGLSurface (EGLAPIENTRYP PFNEGLCREATEPIXMAPSURFACEHIPROC) (EGLDisplay dpy, EGLConfig config, struct EGLClientPixmapHI* pixmap); +#endif /* EGL_HI_clientpixmap */ + +#ifndef EGL_HI_colorformats +#define EGL_HI_colorformats 1 +/* Config Attribute */ +#define EGL_COLOR_FORMAT_HI 0x8F70 +/* Color Formats */ +#define EGL_COLOR_RGB_HI 0x8F71 +#define EGL_COLOR_RGBA_HI 0x8F72 +#define EGL_COLOR_ARGB_HI 0x8F73 +#endif /* EGL_HI_colorformats */ + +#ifndef EGL_MESA_drm_image +#define EGL_MESA_drm_image 1 +#define EGL_DRM_BUFFER_FORMAT_MESA 0x31D0 /* CreateDRMImageMESA attribute */ +#define EGL_DRM_BUFFER_USE_MESA 0x31D1 /* CreateDRMImageMESA attribute */ +#define EGL_DRM_BUFFER_FORMAT_ARGB32_MESA 0x31D2 /* EGL_IMAGE_FORMAT_MESA attribute value */ +#define EGL_DRM_BUFFER_MESA 0x31D3 /* eglCreateImageKHR target */ +#define EGL_DRM_BUFFER_STRIDE_MESA 0x31D4 +#define EGL_DRM_BUFFER_USE_SCANOUT_MESA 0x00000001 /* EGL_DRM_BUFFER_USE_MESA bits */ +#define EGL_DRM_BUFFER_USE_SHARE_MESA 0x00000002 /* EGL_DRM_BUFFER_USE_MESA bits */ +#ifdef EGL_EGLEXT_PROTOTYPES +EGLAPI EGLImageKHR EGLAPIENTRY eglCreateDRMImageMESA (EGLDisplay dpy, const EGLint *attrib_list); +EGLAPI EGLBoolean EGLAPIENTRY eglExportDRMImageMESA (EGLDisplay dpy, EGLImageKHR image, EGLint *name, EGLint *handle, EGLint *stride); +#endif /* EGL_EGLEXT_PROTOTYPES */ +typedef EGLImageKHR (EGLAPIENTRYP PFNEGLCREATEDRMIMAGEMESAPROC) (EGLDisplay dpy, const EGLint *attrib_list); +typedef EGLBoolean (EGLAPIENTRYP PFNEGLEXPORTDRMIMAGEMESAPROC) (EGLDisplay dpy, EGLImageKHR image, EGLint *name, EGLint *handle, EGLint *stride); +#endif + +#ifndef EGL_NV_post_sub_buffer +#define EGL_NV_post_sub_buffer 1 +#define EGL_POST_SUB_BUFFER_SUPPORTED_NV 0x30BE +#ifdef EGL_EGLEXT_PROTOTYPES +EGLAPI EGLBoolean EGLAPIENTRY eglPostSubBufferNV (EGLDisplay dpy, EGLSurface surface, EGLint x, EGLint y, EGLint width, EGLint height); +#endif /* EGL_EGLEXT_PROTOTYPES */ +typedef EGLBoolean (EGLAPIENTRYP PFNEGLPOSTSUBBUFFERNVPROC) (EGLDisplay dpy, EGLSurface surface, EGLint x, EGLint y, EGLint width, EGLint height); +#endif + +#ifndef EGL_ANGLE_query_surface_pointer +#define EGL_ANGLE_query_surface_pointer 1 +#ifdef EGL_EGLEXT_PROTOTYPES +EGLAPI EGLBoolean eglQuerySurfacePointerANGLE(EGLDisplay dpy, EGLSurface surface, EGLint attribute, void **value); +#endif +typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYSURFACEPOINTERANGLEPROC) (EGLDisplay dpy, EGLSurface surface, EGLint attribute, void **value); +#endif + +#ifndef EGL_ANGLE_surface_d3d_texture_2d_share_handle +#define EGL_ANGLE_surface_d3d_texture_2d_share_handle 1 +#define EGL_D3D_TEXTURE_2D_SHARE_HANDLE_ANGLE 0x3200 +#endif + +#ifndef EGL_NV_coverage_sample_resolve +#define EGL_NV_coverage_sample_resolve 1 +#define EGL_COVERAGE_SAMPLE_RESOLVE_NV 0x3131 +#define EGL_COVERAGE_SAMPLE_RESOLVE_DEFAULT_NV 0x3132 +#define EGL_COVERAGE_SAMPLE_RESOLVE_NONE_NV 0x3133 +#endif + +#if KHRONOS_SUPPORT_INT64 /* EGLuint64NV requires 64-bit uint support */ +#ifndef EGL_NV_system_time +#define EGL_NV_system_time 1 + +typedef khronos_utime_nanoseconds_t EGLuint64NV; + +#ifdef EGL_EGLEXT_PROTOTYPES +EGLAPI EGLuint64NV EGLAPIENTRY eglGetSystemTimeFrequencyNV(void); +EGLAPI EGLuint64NV EGLAPIENTRY eglGetSystemTimeNV(void); +#endif /* EGL_EGLEXT_PROTOTYPES */ +typedef EGLuint64NV (EGLAPIENTRYP PFNEGLGETSYSTEMTIMEFREQUENCYNVPROC) (void); +typedef EGLuint64NV (EGLAPIENTRYP PFNEGLGETSYSTEMTIMENVPROC) (void); +#endif +#endif + +#if KHRONOS_SUPPORT_INT64 /* EGLuint64KHR requires 64-bit uint support */ +#ifndef EGL_KHR_stream +#define EGL_KHR_stream 1 +typedef void* EGLStreamKHR; +typedef khronos_uint64_t EGLuint64KHR; +#define EGL_NO_STREAM_KHR ((EGLStreamKHR)0) +#define EGL_CONSUMER_LATENCY_USEC_KHR 0x3210 +#define EGL_PRODUCER_FRAME_KHR 0x3212 +#define EGL_CONSUMER_FRAME_KHR 0x3213 +#define EGL_STREAM_STATE_KHR 0x3214 +#define EGL_STREAM_STATE_CREATED_KHR 0x3215 +#define EGL_STREAM_STATE_CONNECTING_KHR 0x3216 +#define EGL_STREAM_STATE_EMPTY_KHR 0x3217 +#define EGL_STREAM_STATE_NEW_FRAME_AVAILABLE_KHR 0x3218 +#define EGL_STREAM_STATE_OLD_FRAME_AVAILABLE_KHR 0x3219 +#define EGL_STREAM_STATE_DISCONNECTED_KHR 0x321A +#define EGL_BAD_STREAM_KHR 0x321B +#define EGL_BAD_STATE_KHR 0x321C +#ifdef EGL_EGLEXT_PROTOTYPES +EGLAPI EGLStreamKHR EGLAPIENTRY eglCreateStreamKHR(EGLDisplay dpy, const EGLint *attrib_list); +EGLAPI EGLBoolean EGLAPIENTRY eglDestroyStreamKHR(EGLDisplay dpy, EGLStreamKHR stream); +EGLAPI EGLBoolean EGLAPIENTRY eglStreamAttribKHR(EGLDisplay dpy, EGLStreamKHR stream, EGLenum attribute, EGLint value); +EGLAPI EGLBoolean EGLAPIENTRY eglQueryStreamKHR(EGLDisplay dpy, EGLStreamKHR stream, EGLenum attribute, EGLint *value); +EGLAPI EGLBoolean EGLAPIENTRY eglQueryStreamu64KHR(EGLDisplay dpy, EGLStreamKHR stream, EGLenum attribute, EGLuint64KHR *value); +#endif /* EGL_EGLEXT_PROTOTYPES */ +typedef EGLStreamKHR (EGLAPIENTRYP PFNEGLCREATESTREAMKHRPROC)(EGLDisplay dpy, const EGLint *attrib_list); +typedef EGLBoolean (EGLAPIENTRYP PFNEGLDESTROYSTREAMKHRPROC)(EGLDisplay dpy, EGLStreamKHR stream); +typedef EGLBoolean (EGLAPIENTRYP PFNEGLSTREAMATTRIBKHRPROC)(EGLDisplay dpy, EGLStreamKHR stream, EGLenum attribute, EGLint value); +typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYSTREAMKHRPROC)(EGLDisplay dpy, EGLStreamKHR stream, EGLenum attribute, EGLint *value); +typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYSTREAMU64KHRPROC)(EGLDisplay dpy, EGLStreamKHR stream, EGLenum attribute, EGLuint64KHR *value); +#endif +#endif + +#ifdef EGL_KHR_stream /* Requires KHR_stream extension */ +#ifndef EGL_KHR_stream_consumer_gltexture +#define EGL_KHR_stream_consumer_gltexture 1 +#define EGL_CONSUMER_ACQUIRE_TIMEOUT_USEC_KHR 0x321E +#ifdef EGL_EGLEXT_PROTOTYPES +EGLAPI EGLBoolean EGLAPIENTRY eglStreamConsumerGLTextureExternalKHR(EGLDisplay dpy, EGLStreamKHR stream); +EGLAPI EGLBoolean EGLAPIENTRY eglStreamConsumerAcquireKHR(EGLDisplay dpy, EGLStreamKHR stream); +EGLAPI EGLBoolean EGLAPIENTRY eglStreamConsumerReleaseKHR(EGLDisplay dpy, EGLStreamKHR stream); +#endif /* EGL_EGLEXT_PROTOTYPES */ +typedef EGLBoolean (EGLAPIENTRYP PFNEGLSTREAMCONSUMERGLTEXTUREEXTERNALKHRPROC)(EGLDisplay dpy, EGLStreamKHR stream); +typedef EGLBoolean (EGLAPIENTRYP PFNEGLSTREAMCONSUMERACQUIREKHRPROC)(EGLDisplay dpy, EGLStreamKHR stream); +typedef EGLBoolean (EGLAPIENTRYP PFNEGLSTREAMCONSUMERRELEASEKHRPROC)(EGLDisplay dpy, EGLStreamKHR stream); +#endif +#endif + +#ifdef EGL_KHR_stream /* Requires KHR_stream extension */ +#ifndef EGL_KHR_stream_producer_eglsurface +#define EGL_KHR_stream_producer_eglsurface 1 +#define EGL_STREAM_BIT_KHR 0x0800 +#ifdef EGL_EGLEXT_PROTOTYPES +EGLAPI EGLSurface EGLAPIENTRY eglCreateStreamProducerSurfaceKHR(EGLDisplay dpy, EGLConfig config, EGLStreamKHR stream, const EGLint *attrib_list); +#endif /* EGL_EGLEXT_PROTOTYPES */ +typedef EGLSurface (EGLAPIENTRYP PFNEGLCREATESTREAMPRODUCERSURFACEKHRPROC)(EGLDisplay dpy, EGLConfig config, EGLStreamKHR stream, const EGLint *attrib_list); +#endif +#endif + +#ifdef EGL_KHR_stream /* Requires KHR_stream extension */ +#ifndef EGL_KHR_stream_producer_aldatalocator +#define EGL_KHR_stream_producer_aldatalocator 1 +#endif +#endif + +#ifdef EGL_KHR_stream /* Requires KHR_stream extension */ +#ifndef EGL_KHR_stream_fifo +#define EGL_KHR_stream_fifo 1 +/* reuse EGLTimeKHR */ +#define EGL_STREAM_FIFO_LENGTH_KHR 0x31FC +#define EGL_STREAM_TIME_NOW_KHR 0x31FD +#define EGL_STREAM_TIME_CONSUMER_KHR 0x31FE +#define EGL_STREAM_TIME_PRODUCER_KHR 0x31FF +#ifdef EGL_EGLEXT_PROTOTYPES +EGLAPI EGLBoolean EGLAPIENTRY eglQueryStreamTimeKHR(EGLDisplay dpy, EGLStreamKHR stream, EGLenum attribute, EGLTimeKHR *value); +#endif /* EGL_EGLEXT_PROTOTYPES */ +typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYSTREAMTIMEKHRPROC)(EGLDisplay dpy, EGLStreamKHR stream, EGLenum attribute, EGLTimeKHR *value); +#endif +#endif + +#ifndef EGL_EXT_create_context_robustness +#define EGL_EXT_create_context_robustness 1 +#define EGL_CONTEXT_OPENGL_ROBUST_ACCESS_EXT 0x30BF +#define EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT 0x3138 +#define EGL_NO_RESET_NOTIFICATION_EXT 0x31BE +#define EGL_LOSE_CONTEXT_ON_RESET_EXT 0x31BF +#endif + +#ifndef EGL_ANGLE_d3d_share_handle_client_buffer +#define EGL_ANGLE_d3d_share_handle_client_buffer 1 +/* reuse EGL_D3D_TEXTURE_2D_SHARE_HANDLE_ANGLE */ +#endif + +#ifndef EGL_KHR_create_context +#define EGL_KHR_create_context 1 +#define EGL_CONTEXT_MAJOR_VERSION_KHR EGL_CONTEXT_CLIENT_VERSION +#define EGL_CONTEXT_MINOR_VERSION_KHR 0x30FB +#define EGL_CONTEXT_FLAGS_KHR 0x30FC +#define EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR 0x30FD +#define EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_KHR 0x31BD +#define EGL_NO_RESET_NOTIFICATION_KHR 0x31BE +#define EGL_LOSE_CONTEXT_ON_RESET_KHR 0x31BF +#define EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR 0x00000001 +#define EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR 0x00000002 +#define EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR 0x00000004 +#define EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR 0x00000001 +#define EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT_KHR 0x00000002 +#define EGL_OPENGL_ES3_BIT_KHR 0x00000040 +#endif + +#ifndef EGL_KHR_surfaceless_context +#define EGL_KHR_surfaceless_context 1 +/* No tokens/entry points, just relaxes an error condition */ +#endif + +#ifdef EGL_KHR_stream /* Requires KHR_stream extension */ +#ifndef EGL_KHR_stream_cross_process_fd +#define EGL_KHR_stream_cross_process_fd 1 +typedef int EGLNativeFileDescriptorKHR; +#define EGL_NO_FILE_DESCRIPTOR_KHR ((EGLNativeFileDescriptorKHR)(-1)) +#ifdef EGL_EGLEXT_PROTOTYPES +EGLAPI EGLNativeFileDescriptorKHR EGLAPIENTRY eglGetStreamFileDescriptorKHR(EGLDisplay dpy, EGLStreamKHR stream); +EGLAPI EGLStreamKHR EGLAPIENTRY eglCreateStreamFromFileDescriptorKHR(EGLDisplay dpy, EGLNativeFileDescriptorKHR file_descriptor); +#endif /* EGL_EGLEXT_PROTOTYPES */ +typedef EGLNativeFileDescriptorKHR (EGLAPIENTRYP PFNEGLGETSTREAMFILEDESCRIPTORKHRPROC)(EGLDisplay dpy, EGLStreamKHR stream); +typedef EGLStreamKHR (EGLAPIENTRYP PFNEGLCREATESTREAMFROMFILEDESCRIPTORKHRPROC)(EGLDisplay dpy, EGLNativeFileDescriptorKHR file_descriptor); +#endif +#endif + +#ifndef EGL_EXT_multiview_window +#define EGL_EXT_multiview_window 1 +#define EGL_MULTIVIEW_VIEW_COUNT_EXT 0x3134 +#endif + +#ifndef EGL_KHR_wait_sync +#define EGL_KHR_wait_sync 1 +#ifdef EGL_EGLEXT_PROTOTYPES +EGLAPI EGLint EGLAPIENTRY eglWaitSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLint flags); +#endif /* EGL_EGLEXT_PROTOTYPES */ +typedef EGLint (EGLAPIENTRYP PFNEGLWAITSYNCKHRPROC)(EGLDisplay dpy, EGLSyncKHR sync, EGLint flags); +#endif + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/Projects/Android/jni/SupportLibs/gl4es/include/EGL/eglplatform.h b/Projects/Android/jni/SupportLibs/gl4es/include/EGL/eglplatform.h new file mode 100644 index 0000000..d5e9424 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/include/EGL/eglplatform.h @@ -0,0 +1,121 @@ +#ifndef __eglplatform_h_ +#define __eglplatform_h_ + +/* +** Copyright (c) 2007-2009 The Khronos Group Inc. +** +** Permission is hereby granted, free of charge, to any person obtaining a +** copy of this software and/or associated documentation files (the +** "Materials"), to deal in the Materials without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Materials, and to +** permit persons to whom the Materials are furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be included +** in all copies or substantial portions of the Materials. +** +** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. +*/ + +/* Platform-specific types and definitions for egl.h + * $Revision: 12306 $ on $Date: 2010-08-25 09:51:28 -0700 (Wed, 25 Aug 2010) $ + * + * Adopters may modify khrplatform.h and this file to suit their platform. + * You are encouraged to submit all modifications to the Khronos group so that + * they can be included in future versions of this file. Please submit changes + * by sending them to the public Khronos Bugzilla (http://khronos.org/bugzilla) + * by filing a bug against product "EGL" component "Registry". + */ + +#include + +/* Macros used in EGL function prototype declarations. + * + * EGL functions should be prototyped as: + * + * EGLAPI return-type EGLAPIENTRY eglFunction(arguments); + * typedef return-type (EXPAPIENTRYP PFNEGLFUNCTIONPROC) (arguments); + * + * KHRONOS_APICALL and KHRONOS_APIENTRY are defined in KHR/khrplatform.h + */ + +#ifndef EGLAPI +#define EGLAPI KHRONOS_APICALL +#endif + +#ifndef EGLAPIENTRY +#define EGLAPIENTRY KHRONOS_APIENTRY +#endif +#define EGLAPIENTRYP EGLAPIENTRY* + +/* The types NativeDisplayType, NativeWindowType, and NativePixmapType + * are aliases of window-system-dependent types, such as X Display * or + * Windows Device Context. They must be defined in platform-specific + * code below. The EGL-prefixed versions of Native*Type are the same + * types, renamed in EGL 1.3 so all types in the API start with "EGL". + * + * Khronos STRONGLY RECOMMENDS that you use the default definitions + * provided below, since these changes affect both binary and source + * portability of applications using EGL running on different EGL + * implementations. + */ + +#if defined(_WIN32) || defined(__VC32__) && !defined(__CYGWIN__) && !defined(__SCITECH_SNAP__) /* Win32 and WinCE */ +#ifndef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN 1 +#endif +#include + +typedef HDC EGLNativeDisplayType; +typedef HBITMAP EGLNativePixmapType; +typedef HWND EGLNativeWindowType; + +#elif defined(__WINSCW__) || defined(__SYMBIAN32__) /* Symbian */ + +typedef int EGLNativeDisplayType; +typedef void *EGLNativeWindowType; +typedef void *EGLNativePixmapType; + +#elif defined(__unix__) && !defined(ANDROID) + +/* X11 (tentative) */ +#include +#include + +typedef Display *EGLNativeDisplayType; +typedef Pixmap EGLNativePixmapType; +typedef Window EGLNativeWindowType; + +#elif defined(ANDROID) + +typedef int EGLNativeDisplayType; +typedef void *EGLNativeWindowType; +typedef void *EGLNativePixmapType; + +#else +#error "Platform not recognized" +#endif + +/* EGL 1.2 types, renamed for consistency in EGL 1.3 */ +typedef EGLNativeDisplayType NativeDisplayType; +typedef EGLNativePixmapType NativePixmapType; +typedef EGLNativeWindowType NativeWindowType; + + +/* Define EGLint. This must be a signed integral type large enough to contain + * all legal attribute names and values passed into and out of EGL, whether + * their type is boolean, bitmask, enumerant (symbolic constant), integer, + * handle, or other. While in general a 32-bit integer will suffice, if + * handles are 64 bit types, then EGLint should be defined as a signed 64-bit + * integer type. + */ +typedef khronos_int32_t EGLint; + +#endif /* __eglplatform_h */ diff --git a/Projects/Android/jni/SupportLibs/gl4es/include/GL/gl.h b/Projects/Android/jni/SupportLibs/gl4es/include/GL/gl.h new file mode 100644 index 0000000..857dbd6 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/include/GL/gl.h @@ -0,0 +1,2247 @@ +/* + * Mesa 3-D graphics library + * Version: 7.6 + * + * Copyright (C) 1999-2006 Brian Paul All Rights Reserved. + * Copyright (C) 2009 VMware, Inc. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + + +#ifndef __gl_h_ +#define __gl_h_ + +#ifdef __EMSCRIPTEN__ +#define USE_MGL_NAMESPACE 1 +#define GL_GLEXT_PROTOTYPES 1 +#define MANGLE(x) gl4es_gl##x +#endif + +#if defined(USE_MGL_NAMESPACE) +#include "gl_mangle.h" +#endif + + +/********************************************************************** + * Begin system-specific stuff. Do not do any of this when building + * for SciTech SNAP, as this is all done before this header file is + * included. + */ +#if !defined(__SCITECH_SNAP__) + +#if defined(__BEOS__) +#include /* to get some BeOS-isms */ +#endif + +#if !defined(OPENSTEP) && (defined(NeXT) || defined(NeXT_PDO)) +#define OPENSTEP +#endif + +#if defined(_WIN32) && !defined(__WIN32__) && !defined(__CYGWIN__) +#define __WIN32__ +#endif + +#if !defined(OPENSTEP) && (defined(__WIN32__) && !defined(__CYGWIN__)) +# if (defined(_MSC_VER) || defined(__MINGW32__)) && defined(BUILD_GL32) /* tag specify we're building mesa as a DLL */ +# define GLAPI __declspec(dllexport) +# elif (defined(_MSC_VER) || defined(__MINGW32__)) && defined(_DLL) /* tag specifying we're building for DLL runtime support */ +# define GLAPI __declspec(dllimport) +# else /* for use with static link lib build of Win32 edition only */ +# define GLAPI extern +# endif /* _STATIC_MESA support */ +# if defined(__MINGW32__) && defined(GL_NO_STDCALL) || defined(UNDER_CE) /* The generated DLLs by MingW with STDCALL are not compatible with the ones done by Microsoft's compilers */ +# define GLAPIENTRY +# else +# define GLAPIENTRY __stdcall +# endif +#elif defined(__CYGWIN__) && defined(USE_OPENGL32) /* use native windows opengl32 */ +# define GLAPI extern +# define GLAPIENTRY __stdcall +#elif defined(__GNUC__) || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)) +# define GLAPI __attribute__((visibility("default"))) +# define GLAPIENTRY +#endif /* WIN32 && !CYGWIN */ + +#if (defined(__BEOS__) && defined(__POWERPC__)) || defined(__QUICKDRAW__) +# define PRAGMA_EXPORT_SUPPORTED 1 +#endif + +/* + * WINDOWS: Include windows.h here to define APIENTRY. + * It is also useful when applications include this file by + * including only glut.h, since glut.h depends on windows.h. + * Applications needing to include windows.h with parms other + * than "WIN32_LEAN_AND_MEAN" may include windows.h before + * glut.h or gl.h. + */ +#if defined(_WIN32) && !defined(APIENTRY) && !defined(__CYGWIN__) +#ifndef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN 1 +#endif +#include +#endif + +#if defined(_WIN32) && !defined(_WINGDI_) && !defined(_WIN32_WCE) \ + && !defined(_GNU_H_WINDOWS32_DEFINES) && !defined(OPENSTEP) \ + && !defined(__CYGWIN__) || defined(__MINGW32__) +#include +#endif + +#if defined(macintosh) && PRAGMA_IMPORT_SUPPORTED +#pragma import on +#endif + +#ifndef GLAPI +#define GLAPI extern +#endif + +#ifndef GLAPIENTRY +#define GLAPIENTRY +#endif + +#ifndef APIENTRY +#define APIENTRY GLAPIENTRY +#endif + +/* "P" suffix to be used for a pointer to a function */ +#ifndef APIENTRYP +#define APIENTRYP APIENTRY * +#endif + +#ifndef GLAPIENTRYP +#define GLAPIENTRYP GLAPIENTRY * +#endif + +#ifdef CENTERLINE_CLPP +#define signed +#endif + +#if defined(PRAGMA_EXPORT_SUPPORTED) +#pragma export on +#endif + +#endif /* !__SCITECH_SNAP__ */ +/* + * End system-specific stuff. + **********************************************************************/ + + + +#ifdef __cplusplus +extern "C" { +#endif + + + +#define GL_VERSION_1_1 1 +#define GL_VERSION_1_2 1 +#define GL_VERSION_1_3 1 +#define GL_ARB_imaging 1 + + +/* + * Datatypes + */ +typedef unsigned int GLenum; +typedef unsigned char GLboolean; +typedef unsigned int GLbitfield; +typedef void GLvoid; +typedef signed char GLbyte; /* 1-byte signed */ +typedef short GLshort; /* 2-byte signed */ +typedef int GLint; /* 4-byte signed */ +typedef unsigned char GLubyte; /* 1-byte unsigned */ +typedef unsigned short GLushort; /* 2-byte unsigned */ +typedef unsigned int GLuint; /* 4-byte unsigned */ +typedef int GLsizei; /* 4-byte signed */ +typedef float GLfloat; /* single precision float */ +typedef float GLclampf; /* single precision float in [0,1] */ +typedef double GLdouble; /* double precision float */ +typedef double GLclampd; /* double precision float in [0,1] */ + + + +/* + * Constants + */ + +/* Boolean values */ +#define GL_FALSE 0x0 +#define GL_TRUE 0x1 + +/* Data types */ +#define GL_BYTE 0x1400 +#define GL_UNSIGNED_BYTE 0x1401 +#define GL_SHORT 0x1402 +#define GL_UNSIGNED_SHORT 0x1403 +#define GL_INT 0x1404 +#define GL_UNSIGNED_INT 0x1405 +#define GL_FLOAT 0x1406 +#define GL_2_BYTES 0x1407 +#define GL_3_BYTES 0x1408 +#define GL_4_BYTES 0x1409 +#define GL_DOUBLE 0x140A + +/* Primitives */ +#define GL_POINTS 0x0000 +#define GL_LINES 0x0001 +#define GL_LINE_LOOP 0x0002 +#define GL_LINE_STRIP 0x0003 +#define GL_TRIANGLES 0x0004 +#define GL_TRIANGLE_STRIP 0x0005 +#define GL_TRIANGLE_FAN 0x0006 +#define GL_QUADS 0x0007 +#define GL_QUAD_STRIP 0x0008 +#define GL_POLYGON 0x0009 + +/* Vertex Arrays */ +#define GL_VERTEX_ARRAY 0x8074 +#define GL_NORMAL_ARRAY 0x8075 +#define GL_COLOR_ARRAY 0x8076 +#define GL_INDEX_ARRAY 0x8077 +#define GL_TEXTURE_COORD_ARRAY 0x8078 +#define GL_EDGE_FLAG_ARRAY 0x8079 +#define GL_VERTEX_ARRAY_SIZE 0x807A +#define GL_VERTEX_ARRAY_TYPE 0x807B +#define GL_VERTEX_ARRAY_STRIDE 0x807C +#define GL_NORMAL_ARRAY_TYPE 0x807E +#define GL_NORMAL_ARRAY_STRIDE 0x807F +#define GL_COLOR_ARRAY_SIZE 0x8081 +#define GL_COLOR_ARRAY_TYPE 0x8082 +#define GL_COLOR_ARRAY_STRIDE 0x8083 +#define GL_INDEX_ARRAY_TYPE 0x8085 +#define GL_INDEX_ARRAY_STRIDE 0x8086 +#define GL_TEXTURE_COORD_ARRAY_SIZE 0x8088 +#define GL_TEXTURE_COORD_ARRAY_TYPE 0x8089 +#define GL_TEXTURE_COORD_ARRAY_STRIDE 0x808A +#define GL_EDGE_FLAG_ARRAY_STRIDE 0x808C +#define GL_VERTEX_ARRAY_POINTER 0x808E +#define GL_NORMAL_ARRAY_POINTER 0x808F +#define GL_COLOR_ARRAY_POINTER 0x8090 +#define GL_INDEX_ARRAY_POINTER 0x8091 +#define GL_TEXTURE_COORD_ARRAY_POINTER 0x8092 +#define GL_EDGE_FLAG_ARRAY_POINTER 0x8093 +#define GL_V2F 0x2A20 +#define GL_V3F 0x2A21 +#define GL_C4UB_V2F 0x2A22 +#define GL_C4UB_V3F 0x2A23 +#define GL_C3F_V3F 0x2A24 +#define GL_N3F_V3F 0x2A25 +#define GL_C4F_N3F_V3F 0x2A26 +#define GL_T2F_V3F 0x2A27 +#define GL_T4F_V4F 0x2A28 +#define GL_T2F_C4UB_V3F 0x2A29 +#define GL_T2F_C3F_V3F 0x2A2A +#define GL_T2F_N3F_V3F 0x2A2B +#define GL_T2F_C4F_N3F_V3F 0x2A2C +#define GL_T4F_C4F_N3F_V4F 0x2A2D + +/* Matrix Mode */ +#define GL_MATRIX_MODE 0x0BA0 +#define GL_MODELVIEW 0x1700 +#define GL_PROJECTION 0x1701 +#define GL_TEXTURE 0x1702 + +/* Points */ +#define GL_POINT_SMOOTH 0x0B10 +#define GL_POINT_SIZE 0x0B11 +#define GL_POINT_SIZE_GRANULARITY 0x0B13 +#define GL_POINT_SIZE_RANGE 0x0B12 + +/* Lines */ +#define GL_LINE_SMOOTH 0x0B20 +#define GL_LINE_STIPPLE 0x0B24 +#define GL_LINE_STIPPLE_PATTERN 0x0B25 +#define GL_LINE_STIPPLE_REPEAT 0x0B26 +#define GL_LINE_WIDTH 0x0B21 +#define GL_LINE_WIDTH_GRANULARITY 0x0B23 +#define GL_LINE_WIDTH_RANGE 0x0B22 + +/* Polygons */ +#define GL_POINT 0x1B00 +#define GL_LINE 0x1B01 +#define GL_FILL 0x1B02 +#define GL_CW 0x0900 +#define GL_CCW 0x0901 +#define GL_FRONT 0x0404 +#define GL_BACK 0x0405 +#define GL_POLYGON_MODE 0x0B40 +#define GL_POLYGON_SMOOTH 0x0B41 +#define GL_POLYGON_STIPPLE 0x0B42 +#define GL_EDGE_FLAG 0x0B43 +#define GL_CULL_FACE 0x0B44 +#define GL_CULL_FACE_MODE 0x0B45 +#define GL_FRONT_FACE 0x0B46 +#define GL_POLYGON_OFFSET_FACTOR 0x8038 +#define GL_POLYGON_OFFSET_UNITS 0x2A00 +#define GL_POLYGON_OFFSET_POINT 0x2A01 +#define GL_POLYGON_OFFSET_LINE 0x2A02 +#define GL_POLYGON_OFFSET_FILL 0x8037 + +/* Display Lists */ +#define GL_COMPILE 0x1300 +#define GL_COMPILE_AND_EXECUTE 0x1301 +#define GL_LIST_BASE 0x0B32 +#define GL_LIST_INDEX 0x0B33 +#define GL_LIST_MODE 0x0B30 + +/* Depth buffer */ +#define GL_NEVER 0x0200 +#define GL_LESS 0x0201 +#define GL_EQUAL 0x0202 +#define GL_LEQUAL 0x0203 +#define GL_GREATER 0x0204 +#define GL_NOTEQUAL 0x0205 +#define GL_GEQUAL 0x0206 +#define GL_ALWAYS 0x0207 +#define GL_DEPTH_TEST 0x0B71 +#define GL_DEPTH_BITS 0x0D56 +#define GL_DEPTH_CLEAR_VALUE 0x0B73 +#define GL_DEPTH_FUNC 0x0B74 +#define GL_DEPTH_RANGE 0x0B70 +#define GL_DEPTH_WRITEMASK 0x0B72 +#define GL_DEPTH_COMPONENT 0x1902 + +/* Lighting */ +#define GL_LIGHTING 0x0B50 +#define GL_LIGHT0 0x4000 +#define GL_LIGHT1 0x4001 +#define GL_LIGHT2 0x4002 +#define GL_LIGHT3 0x4003 +#define GL_LIGHT4 0x4004 +#define GL_LIGHT5 0x4005 +#define GL_LIGHT6 0x4006 +#define GL_LIGHT7 0x4007 +#define GL_SPOT_EXPONENT 0x1205 +#define GL_SPOT_CUTOFF 0x1206 +#define GL_CONSTANT_ATTENUATION 0x1207 +#define GL_LINEAR_ATTENUATION 0x1208 +#define GL_QUADRATIC_ATTENUATION 0x1209 +#define GL_AMBIENT 0x1200 +#define GL_DIFFUSE 0x1201 +#define GL_SPECULAR 0x1202 +#define GL_SHININESS 0x1601 +#define GL_EMISSION 0x1600 +#define GL_POSITION 0x1203 +#define GL_SPOT_DIRECTION 0x1204 +#define GL_AMBIENT_AND_DIFFUSE 0x1602 +#define GL_COLOR_INDEXES 0x1603 +#define GL_LIGHT_MODEL_TWO_SIDE 0x0B52 +#define GL_LIGHT_MODEL_LOCAL_VIEWER 0x0B51 +#define GL_LIGHT_MODEL_AMBIENT 0x0B53 +#define GL_FRONT_AND_BACK 0x0408 +#define GL_SHADE_MODEL 0x0B54 +#define GL_FLAT 0x1D00 +#define GL_SMOOTH 0x1D01 +#define GL_COLOR_MATERIAL 0x0B57 +#define GL_COLOR_MATERIAL_FACE 0x0B55 +#define GL_COLOR_MATERIAL_PARAMETER 0x0B56 +#define GL_NORMALIZE 0x0BA1 + +/* User clipping planes */ +#define GL_CLIP_PLANE0 0x3000 +#define GL_CLIP_PLANE1 0x3001 +#define GL_CLIP_PLANE2 0x3002 +#define GL_CLIP_PLANE3 0x3003 +#define GL_CLIP_PLANE4 0x3004 +#define GL_CLIP_PLANE5 0x3005 + +/* Accumulation buffer */ +#define GL_ACCUM_RED_BITS 0x0D58 +#define GL_ACCUM_GREEN_BITS 0x0D59 +#define GL_ACCUM_BLUE_BITS 0x0D5A +#define GL_ACCUM_ALPHA_BITS 0x0D5B +#define GL_ACCUM_CLEAR_VALUE 0x0B80 +#define GL_ACCUM 0x0100 +#define GL_ADD 0x0104 +#define GL_LOAD 0x0101 +#define GL_MULT 0x0103 +#define GL_RETURN 0x0102 + +/* Alpha testing */ +#define GL_ALPHA_TEST 0x0BC0 +#define GL_ALPHA_TEST_REF 0x0BC2 +#define GL_ALPHA_TEST_FUNC 0x0BC1 + +/* Blending */ +#define GL_BLEND 0x0BE2 +#define GL_BLEND_SRC 0x0BE1 +#define GL_BLEND_DST 0x0BE0 +#define GL_ZERO 0x0 +#define GL_ONE 0x1 +#define GL_SRC_COLOR 0x0300 +#define GL_ONE_MINUS_SRC_COLOR 0x0301 +#define GL_SRC_ALPHA 0x0302 +#define GL_ONE_MINUS_SRC_ALPHA 0x0303 +#define GL_DST_ALPHA 0x0304 +#define GL_ONE_MINUS_DST_ALPHA 0x0305 +#define GL_DST_COLOR 0x0306 +#define GL_ONE_MINUS_DST_COLOR 0x0307 +#define GL_SRC_ALPHA_SATURATE 0x0308 + +/* Render Mode */ +#define GL_FEEDBACK 0x1C01 +#define GL_RENDER 0x1C00 +#define GL_SELECT 0x1C02 + +/* Feedback */ +#define GL_2D 0x0600 +#define GL_3D 0x0601 +#define GL_3D_COLOR 0x0602 +#define GL_3D_COLOR_TEXTURE 0x0603 +#define GL_4D_COLOR_TEXTURE 0x0604 +#define GL_POINT_TOKEN 0x0701 +#define GL_LINE_TOKEN 0x0702 +#define GL_LINE_RESET_TOKEN 0x0707 +#define GL_POLYGON_TOKEN 0x0703 +#define GL_BITMAP_TOKEN 0x0704 +#define GL_DRAW_PIXEL_TOKEN 0x0705 +#define GL_COPY_PIXEL_TOKEN 0x0706 +#define GL_PASS_THROUGH_TOKEN 0x0700 +#define GL_FEEDBACK_BUFFER_POINTER 0x0DF0 +#define GL_FEEDBACK_BUFFER_SIZE 0x0DF1 +#define GL_FEEDBACK_BUFFER_TYPE 0x0DF2 + +/* Selection */ +#define GL_SELECTION_BUFFER_POINTER 0x0DF3 +#define GL_SELECTION_BUFFER_SIZE 0x0DF4 + +/* Fog */ +#define GL_FOG 0x0B60 +#define GL_FOG_MODE 0x0B65 +#define GL_FOG_DENSITY 0x0B62 +#define GL_FOG_COLOR 0x0B66 +#define GL_FOG_INDEX 0x0B61 +#define GL_FOG_START 0x0B63 +#define GL_FOG_END 0x0B64 +#define GL_LINEAR 0x2601 +#define GL_EXP 0x0800 +#define GL_EXP2 0x0801 + +/* Logic Ops */ +#define GL_LOGIC_OP 0x0BF1 +#define GL_INDEX_LOGIC_OP 0x0BF1 +#define GL_COLOR_LOGIC_OP 0x0BF2 +#define GL_LOGIC_OP_MODE 0x0BF0 +#define GL_CLEAR 0x1500 +#define GL_SET 0x150F +#define GL_COPY 0x1503 +#define GL_COPY_INVERTED 0x150C +#define GL_NOOP 0x1505 +#define GL_INVERT 0x150A +#define GL_AND 0x1501 +#define GL_NAND 0x150E +#define GL_OR 0x1507 +#define GL_NOR 0x1508 +#define GL_XOR 0x1506 +#define GL_EQUIV 0x1509 +#define GL_AND_REVERSE 0x1502 +#define GL_AND_INVERTED 0x1504 +#define GL_OR_REVERSE 0x150B +#define GL_OR_INVERTED 0x150D + +/* Stencil */ +#define GL_STENCIL_BITS 0x0D57 +#define GL_STENCIL_TEST 0x0B90 +#define GL_STENCIL_CLEAR_VALUE 0x0B91 +#define GL_STENCIL_FUNC 0x0B92 +#define GL_STENCIL_VALUE_MASK 0x0B93 +#define GL_STENCIL_FAIL 0x0B94 +#define GL_STENCIL_PASS_DEPTH_FAIL 0x0B95 +#define GL_STENCIL_PASS_DEPTH_PASS 0x0B96 +#define GL_STENCIL_REF 0x0B97 +#define GL_STENCIL_WRITEMASK 0x0B98 +#define GL_STENCIL_INDEX 0x1901 +#define GL_KEEP 0x1E00 +#define GL_REPLACE 0x1E01 +#define GL_INCR 0x1E02 +#define GL_DECR 0x1E03 + +/* Buffers, Pixel Drawing/Reading */ +#define GL_NONE 0x0 +#define GL_LEFT 0x0406 +#define GL_RIGHT 0x0407 +/*GL_FRONT 0x0404 */ +/*GL_BACK 0x0405 */ +/*GL_FRONT_AND_BACK 0x0408 */ +#define GL_FRONT_LEFT 0x0400 +#define GL_FRONT_RIGHT 0x0401 +#define GL_BACK_LEFT 0x0402 +#define GL_BACK_RIGHT 0x0403 +#define GL_AUX0 0x0409 +#define GL_AUX1 0x040A +#define GL_AUX2 0x040B +#define GL_AUX3 0x040C +#define GL_COLOR_INDEX 0x1900 +#define GL_RED 0x1903 +#define GL_GREEN 0x1904 +#define GL_BLUE 0x1905 +#define GL_ALPHA 0x1906 +#define GL_LUMINANCE 0x1909 +#define GL_LUMINANCE_ALPHA 0x190A +#define GL_ALPHA_BITS 0x0D55 +#define GL_RED_BITS 0x0D52 +#define GL_GREEN_BITS 0x0D53 +#define GL_BLUE_BITS 0x0D54 +#define GL_INDEX_BITS 0x0D51 +#define GL_SUBPIXEL_BITS 0x0D50 +#define GL_AUX_BUFFERS 0x0C00 +#define GL_READ_BUFFER 0x0C02 +#define GL_DRAW_BUFFER 0x0C01 +#define GL_DOUBLEBUFFER 0x0C32 +#define GL_STEREO 0x0C33 +#define GL_BITMAP 0x1A00 +#define GL_COLOR 0x1800 +#define GL_DEPTH 0x1801 +#define GL_STENCIL 0x1802 +#define GL_DITHER 0x0BD0 +#define GL_RGB 0x1907 +#define GL_RGBA 0x1908 + +/* Implementation limits */ +#define GL_MAX_LIST_NESTING 0x0B31 +#define GL_MAX_EVAL_ORDER 0x0D30 +#define GL_MAX_LIGHTS 0x0D31 +#define GL_MAX_CLIP_PLANES 0x0D32 +#define GL_MAX_TEXTURE_SIZE 0x0D33 +#define GL_MAX_PIXEL_MAP_TABLE 0x0D34 +#define GL_MAX_ATTRIB_STACK_DEPTH 0x0D35 +#define GL_MAX_MODELVIEW_STACK_DEPTH 0x0D36 +#define GL_MAX_NAME_STACK_DEPTH 0x0D37 +#define GL_MAX_PROJECTION_STACK_DEPTH 0x0D38 +#define GL_MAX_TEXTURE_STACK_DEPTH 0x0D39 +#define GL_MAX_VIEWPORT_DIMS 0x0D3A +#define GL_MAX_CLIENT_ATTRIB_STACK_DEPTH 0x0D3B + +/* Gets */ +#define GL_ATTRIB_STACK_DEPTH 0x0BB0 +#define GL_CLIENT_ATTRIB_STACK_DEPTH 0x0BB1 +#define GL_COLOR_CLEAR_VALUE 0x0C22 +#define GL_COLOR_WRITEMASK 0x0C23 +#define GL_CURRENT_INDEX 0x0B01 +#define GL_CURRENT_COLOR 0x0B00 +#define GL_CURRENT_NORMAL 0x0B02 +#define GL_CURRENT_RASTER_COLOR 0x0B04 +#define GL_CURRENT_RASTER_DISTANCE 0x0B09 +#define GL_CURRENT_RASTER_INDEX 0x0B05 +#define GL_CURRENT_RASTER_POSITION 0x0B07 +#define GL_CURRENT_RASTER_TEXTURE_COORDS 0x0B06 +#define GL_CURRENT_RASTER_POSITION_VALID 0x0B08 +#define GL_CURRENT_TEXTURE_COORDS 0x0B03 +#define GL_INDEX_CLEAR_VALUE 0x0C20 +#define GL_INDEX_MODE 0x0C30 +#define GL_INDEX_WRITEMASK 0x0C21 +#define GL_MODELVIEW_MATRIX 0x0BA6 +#define GL_MODELVIEW_STACK_DEPTH 0x0BA3 +#define GL_NAME_STACK_DEPTH 0x0D70 +#define GL_PROJECTION_MATRIX 0x0BA7 +#define GL_PROJECTION_STACK_DEPTH 0x0BA4 +#define GL_RENDER_MODE 0x0C40 +#define GL_RGBA_MODE 0x0C31 +#define GL_TEXTURE_MATRIX 0x0BA8 +#define GL_TEXTURE_STACK_DEPTH 0x0BA5 +#define GL_VIEWPORT 0x0BA2 + +/* Evaluators */ +#define GL_AUTO_NORMAL 0x0D80 +#define GL_MAP1_COLOR_4 0x0D90 +#define GL_MAP1_INDEX 0x0D91 +#define GL_MAP1_NORMAL 0x0D92 +#define GL_MAP1_TEXTURE_COORD_1 0x0D93 +#define GL_MAP1_TEXTURE_COORD_2 0x0D94 +#define GL_MAP1_TEXTURE_COORD_3 0x0D95 +#define GL_MAP1_TEXTURE_COORD_4 0x0D96 +#define GL_MAP1_VERTEX_3 0x0D97 +#define GL_MAP1_VERTEX_4 0x0D98 +#define GL_MAP2_COLOR_4 0x0DB0 +#define GL_MAP2_INDEX 0x0DB1 +#define GL_MAP2_NORMAL 0x0DB2 +#define GL_MAP2_TEXTURE_COORD_1 0x0DB3 +#define GL_MAP2_TEXTURE_COORD_2 0x0DB4 +#define GL_MAP2_TEXTURE_COORD_3 0x0DB5 +#define GL_MAP2_TEXTURE_COORD_4 0x0DB6 +#define GL_MAP2_VERTEX_3 0x0DB7 +#define GL_MAP2_VERTEX_4 0x0DB8 +#define GL_MAP1_GRID_DOMAIN 0x0DD0 +#define GL_MAP1_GRID_SEGMENTS 0x0DD1 +#define GL_MAP2_GRID_DOMAIN 0x0DD2 +#define GL_MAP2_GRID_SEGMENTS 0x0DD3 +#define GL_COEFF 0x0A00 +#define GL_ORDER 0x0A01 +#define GL_DOMAIN 0x0A02 + +/* Hints */ +#define GL_PERSPECTIVE_CORRECTION_HINT 0x0C50 +#define GL_POINT_SMOOTH_HINT 0x0C51 +#define GL_LINE_SMOOTH_HINT 0x0C52 +#define GL_POLYGON_SMOOTH_HINT 0x0C53 +#define GL_FOG_HINT 0x0C54 +#define GL_DONT_CARE 0x1100 +#define GL_FASTEST 0x1101 +#define GL_NICEST 0x1102 + +/* Scissor box */ +#define GL_SCISSOR_BOX 0x0C10 +#define GL_SCISSOR_TEST 0x0C11 + +/* Pixel Mode / Transfer */ +#define GL_MAP_COLOR 0x0D10 +#define GL_MAP_STENCIL 0x0D11 +#define GL_INDEX_SHIFT 0x0D12 +#define GL_INDEX_OFFSET 0x0D13 +#define GL_RED_SCALE 0x0D14 +#define GL_RED_BIAS 0x0D15 +#define GL_GREEN_SCALE 0x0D18 +#define GL_GREEN_BIAS 0x0D19 +#define GL_BLUE_SCALE 0x0D1A +#define GL_BLUE_BIAS 0x0D1B +#define GL_ALPHA_SCALE 0x0D1C +#define GL_ALPHA_BIAS 0x0D1D +#define GL_DEPTH_SCALE 0x0D1E +#define GL_DEPTH_BIAS 0x0D1F +#define GL_PIXEL_MAP_S_TO_S_SIZE 0x0CB1 +#define GL_PIXEL_MAP_I_TO_I_SIZE 0x0CB0 +#define GL_PIXEL_MAP_I_TO_R_SIZE 0x0CB2 +#define GL_PIXEL_MAP_I_TO_G_SIZE 0x0CB3 +#define GL_PIXEL_MAP_I_TO_B_SIZE 0x0CB4 +#define GL_PIXEL_MAP_I_TO_A_SIZE 0x0CB5 +#define GL_PIXEL_MAP_R_TO_R_SIZE 0x0CB6 +#define GL_PIXEL_MAP_G_TO_G_SIZE 0x0CB7 +#define GL_PIXEL_MAP_B_TO_B_SIZE 0x0CB8 +#define GL_PIXEL_MAP_A_TO_A_SIZE 0x0CB9 +#define GL_PIXEL_MAP_S_TO_S 0x0C71 +#define GL_PIXEL_MAP_I_TO_I 0x0C70 +#define GL_PIXEL_MAP_I_TO_R 0x0C72 +#define GL_PIXEL_MAP_I_TO_G 0x0C73 +#define GL_PIXEL_MAP_I_TO_B 0x0C74 +#define GL_PIXEL_MAP_I_TO_A 0x0C75 +#define GL_PIXEL_MAP_R_TO_R 0x0C76 +#define GL_PIXEL_MAP_G_TO_G 0x0C77 +#define GL_PIXEL_MAP_B_TO_B 0x0C78 +#define GL_PIXEL_MAP_A_TO_A 0x0C79 +#define GL_PACK_ALIGNMENT 0x0D05 +#define GL_PACK_LSB_FIRST 0x0D01 +#define GL_PACK_ROW_LENGTH 0x0D02 +#define GL_PACK_SKIP_PIXELS 0x0D04 +#define GL_PACK_SKIP_ROWS 0x0D03 +#define GL_PACK_SWAP_BYTES 0x0D00 +#define GL_UNPACK_ALIGNMENT 0x0CF5 +#define GL_UNPACK_LSB_FIRST 0x0CF1 +#define GL_UNPACK_ROW_LENGTH 0x0CF2 +#define GL_UNPACK_SKIP_PIXELS 0x0CF4 +#define GL_UNPACK_SKIP_ROWS 0x0CF3 +#define GL_UNPACK_SWAP_BYTES 0x0CF0 +#define GL_ZOOM_X 0x0D16 +#define GL_ZOOM_Y 0x0D17 + +/* Texture mapping */ +#define GL_TEXTURE_ENV 0x2300 +#define GL_TEXTURE_ENV_MODE 0x2200 +#define GL_TEXTURE_1D 0x0DE0 +#define GL_TEXTURE_2D 0x0DE1 +#define GL_TEXTURE_WRAP_S 0x2802 +#define GL_TEXTURE_WRAP_T 0x2803 +#define GL_TEXTURE_MAG_FILTER 0x2800 +#define GL_TEXTURE_MIN_FILTER 0x2801 +#define GL_TEXTURE_ENV_COLOR 0x2201 +#define GL_TEXTURE_GEN_S 0x0C60 +#define GL_TEXTURE_GEN_T 0x0C61 +#define GL_TEXTURE_GEN_MODE 0x2500 +#define GL_TEXTURE_BORDER_COLOR 0x1004 +#define GL_TEXTURE_WIDTH 0x1000 +#define GL_TEXTURE_HEIGHT 0x1001 +#define GL_TEXTURE_BORDER 0x1005 +#define GL_TEXTURE_COMPONENTS 0x1003 +#define GL_TEXTURE_RED_SIZE 0x805C +#define GL_TEXTURE_GREEN_SIZE 0x805D +#define GL_TEXTURE_BLUE_SIZE 0x805E +#define GL_TEXTURE_ALPHA_SIZE 0x805F +#define GL_TEXTURE_LUMINANCE_SIZE 0x8060 +#define GL_TEXTURE_INTENSITY_SIZE 0x8061 +#define GL_NEAREST_MIPMAP_NEAREST 0x2700 +#define GL_NEAREST_MIPMAP_LINEAR 0x2702 +#define GL_LINEAR_MIPMAP_NEAREST 0x2701 +#define GL_LINEAR_MIPMAP_LINEAR 0x2703 +#define GL_OBJECT_LINEAR 0x2401 +#define GL_OBJECT_PLANE 0x2501 +#define GL_EYE_LINEAR 0x2400 +#define GL_EYE_PLANE 0x2502 +#define GL_SPHERE_MAP 0x2402 +#define GL_DECAL 0x2101 +#define GL_MODULATE 0x2100 +#define GL_NEAREST 0x2600 +#define GL_REPEAT 0x2901 +#define GL_CLAMP 0x2900 +#define GL_S 0x2000 +#define GL_T 0x2001 +#define GL_R 0x2002 +#define GL_Q 0x2003 +#define GL_TEXTURE_GEN_R 0x0C62 +#define GL_TEXTURE_GEN_Q 0x0C63 + +/* Utility */ +#define GL_VENDOR 0x1F00 +#define GL_RENDERER 0x1F01 +#define GL_VERSION 0x1F02 +#define GL_EXTENSIONS 0x1F03 + +/* Errors */ +#define GL_NO_ERROR 0x0 +#define GL_INVALID_ENUM 0x0500 +#define GL_INVALID_VALUE 0x0501 +#define GL_INVALID_OPERATION 0x0502 +#define GL_STACK_OVERFLOW 0x0503 +#define GL_STACK_UNDERFLOW 0x0504 +#define GL_OUT_OF_MEMORY 0x0505 + +/* glPush/PopAttrib bits */ +#define GL_CURRENT_BIT 0x00000001 +#define GL_POINT_BIT 0x00000002 +#define GL_LINE_BIT 0x00000004 +#define GL_POLYGON_BIT 0x00000008 +#define GL_POLYGON_STIPPLE_BIT 0x00000010 +#define GL_PIXEL_MODE_BIT 0x00000020 +#define GL_LIGHTING_BIT 0x00000040 +#define GL_FOG_BIT 0x00000080 +#define GL_DEPTH_BUFFER_BIT 0x00000100 +#define GL_ACCUM_BUFFER_BIT 0x00000200 +#define GL_STENCIL_BUFFER_BIT 0x00000400 +#define GL_VIEWPORT_BIT 0x00000800 +#define GL_TRANSFORM_BIT 0x00001000 +#define GL_ENABLE_BIT 0x00002000 +#define GL_COLOR_BUFFER_BIT 0x00004000 +#define GL_HINT_BIT 0x00008000 +#define GL_EVAL_BIT 0x00010000 +#define GL_LIST_BIT 0x00020000 +#define GL_TEXTURE_BIT 0x00040000 +#define GL_SCISSOR_BIT 0x00080000 +#define GL_ALL_ATTRIB_BITS 0x000FFFFF + + +/* OpenGL 1.1 */ +#define GL_PROXY_TEXTURE_1D 0x8063 +#define GL_PROXY_TEXTURE_2D 0x8064 +#define GL_TEXTURE_PRIORITY 0x8066 +#define GL_TEXTURE_RESIDENT 0x8067 +#define GL_TEXTURE_BINDING_1D 0x8068 +#define GL_TEXTURE_BINDING_2D 0x8069 +#define GL_TEXTURE_INTERNAL_FORMAT 0x1003 +#define GL_ALPHA4 0x803B +#define GL_ALPHA8 0x803C +#define GL_ALPHA12 0x803D +#define GL_ALPHA16 0x803E +#define GL_LUMINANCE4 0x803F +#define GL_LUMINANCE8 0x8040 +#define GL_LUMINANCE12 0x8041 +#define GL_LUMINANCE16 0x8042 +#define GL_LUMINANCE4_ALPHA4 0x8043 +#define GL_LUMINANCE6_ALPHA2 0x8044 +#define GL_LUMINANCE8_ALPHA8 0x8045 +#define GL_LUMINANCE12_ALPHA4 0x8046 +#define GL_LUMINANCE12_ALPHA12 0x8047 +#define GL_LUMINANCE16_ALPHA16 0x8048 +#define GL_INTENSITY 0x8049 +#define GL_INTENSITY4 0x804A +#define GL_INTENSITY8 0x804B +#define GL_INTENSITY12 0x804C +#define GL_INTENSITY16 0x804D +#define GL_R3_G3_B2 0x2A10 +#define GL_RGB4 0x804F +#define GL_RGB5 0x8050 +#define GL_RGB8 0x8051 +#define GL_RGB10 0x8052 +#define GL_RGB12 0x8053 +#define GL_RGB16 0x8054 +#define GL_RGBA2 0x8055 +#define GL_RGBA4 0x8056 +#define GL_RGB5_A1 0x8057 +#define GL_RGBA8 0x8058 +#define GL_RGB10_A2 0x8059 +#define GL_RGBA12 0x805A +#define GL_RGBA16 0x805B +#define GL_CLIENT_PIXEL_STORE_BIT 0x00000001 +#define GL_CLIENT_VERTEX_ARRAY_BIT 0x00000002 +#define GL_ALL_CLIENT_ATTRIB_BITS 0xFFFFFFFF +#define GL_CLIENT_ALL_ATTRIB_BITS 0xFFFFFFFF + + + +/* + * Miscellaneous + */ + +GLAPI void GLAPIENTRY glClearIndex( GLfloat c ); + +GLAPI void GLAPIENTRY glClearColor( GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha ); + +GLAPI void GLAPIENTRY glClear( GLbitfield mask ); + +GLAPI void GLAPIENTRY glIndexMask( GLuint mask ); + +GLAPI void GLAPIENTRY glColorMask( GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha ); + +GLAPI void GLAPIENTRY glAlphaFunc( GLenum func, GLclampf ref ); + +GLAPI void GLAPIENTRY glBlendFunc( GLenum sfactor, GLenum dfactor ); + +GLAPI void GLAPIENTRY glLogicOp( GLenum opcode ); + +GLAPI void GLAPIENTRY glCullFace( GLenum mode ); + +GLAPI void GLAPIENTRY glFrontFace( GLenum mode ); + +GLAPI void GLAPIENTRY glPointSize( GLfloat size ); + +GLAPI void GLAPIENTRY glLineWidth( GLfloat width ); + +GLAPI void GLAPIENTRY glLineStipple( GLint factor, GLushort pattern ); + +GLAPI void GLAPIENTRY glPolygonMode( GLenum face, GLenum mode ); + +GLAPI void GLAPIENTRY glPolygonOffset( GLfloat factor, GLfloat units ); + +GLAPI void GLAPIENTRY glPolygonStipple( const GLubyte *mask ); + +GLAPI void GLAPIENTRY glGetPolygonStipple( GLubyte *mask ); + +GLAPI void GLAPIENTRY glEdgeFlag( GLboolean flag ); + +GLAPI void GLAPIENTRY glEdgeFlagv( const GLboolean *flag ); + +GLAPI void GLAPIENTRY glScissor( GLint x, GLint y, GLsizei width, GLsizei height); + +GLAPI void GLAPIENTRY glClipPlane( GLenum plane, const GLdouble *equation ); + +GLAPI void GLAPIENTRY glGetClipPlane( GLenum plane, GLdouble *equation ); + +GLAPI void GLAPIENTRY glDrawBuffer( GLenum mode ); + +GLAPI void GLAPIENTRY glReadBuffer( GLenum mode ); + +GLAPI void GLAPIENTRY glEnable( GLenum cap ); + +GLAPI void GLAPIENTRY glDisable( GLenum cap ); + +GLAPI GLboolean GLAPIENTRY glIsEnabled( GLenum cap ); + + +GLAPI void GLAPIENTRY glEnableClientState( GLenum cap ); /* 1.1 */ + +GLAPI void GLAPIENTRY glDisableClientState( GLenum cap ); /* 1.1 */ + + +GLAPI void GLAPIENTRY glGetBooleanv( GLenum pname, GLboolean *params ); + +GLAPI void GLAPIENTRY glGetDoublev( GLenum pname, GLdouble *params ); + +GLAPI void GLAPIENTRY glGetFloatv( GLenum pname, GLfloat *params ); + +GLAPI void GLAPIENTRY glGetIntegerv( GLenum pname, GLint *params ); + + +GLAPI void GLAPIENTRY glPushAttrib( GLbitfield mask ); + +GLAPI void GLAPIENTRY glPopAttrib( void ); + + +GLAPI void GLAPIENTRY glPushClientAttrib( GLbitfield mask ); /* 1.1 */ + +GLAPI void GLAPIENTRY glPopClientAttrib( void ); /* 1.1 */ + + +GLAPI GLint GLAPIENTRY glRenderMode( GLenum mode ); + +GLAPI GLenum GLAPIENTRY glGetError( void ); + +GLAPI const GLubyte * GLAPIENTRY glGetString( GLenum name ); + +GLAPI void GLAPIENTRY glFinish( void ); + +GLAPI void GLAPIENTRY glFlush( void ); + +GLAPI void GLAPIENTRY glHint( GLenum target, GLenum mode ); + + +/* + * Depth Buffer + */ + +GLAPI void GLAPIENTRY glClearDepth( GLclampd depth ); + +GLAPI void GLAPIENTRY glDepthFunc( GLenum func ); + +GLAPI void GLAPIENTRY glDepthMask( GLboolean flag ); + +GLAPI void GLAPIENTRY glDepthRange( GLclampd near_val, GLclampd far_val ); + + +/* + * Accumulation Buffer + */ + +GLAPI void GLAPIENTRY glClearAccum( GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha ); + +GLAPI void GLAPIENTRY glAccum( GLenum op, GLfloat value ); + + +/* + * Transformation + */ + +GLAPI void GLAPIENTRY glMatrixMode( GLenum mode ); + +GLAPI void GLAPIENTRY glOrtho( GLdouble left, GLdouble right, + GLdouble bottom, GLdouble top, + GLdouble near_val, GLdouble far_val ); + +GLAPI void GLAPIENTRY glFrustum( GLdouble left, GLdouble right, + GLdouble bottom, GLdouble top, + GLdouble near_val, GLdouble far_val ); + +GLAPI void GLAPIENTRY glViewport( GLint x, GLint y, + GLsizei width, GLsizei height ); + +GLAPI void GLAPIENTRY glPushMatrix( void ); + +GLAPI void GLAPIENTRY glPopMatrix( void ); + +GLAPI void GLAPIENTRY glLoadIdentity( void ); + +GLAPI void GLAPIENTRY glLoadMatrixd( const GLdouble *m ); +GLAPI void GLAPIENTRY glLoadMatrixf( const GLfloat *m ); + +GLAPI void GLAPIENTRY glMultMatrixd( const GLdouble *m ); +GLAPI void GLAPIENTRY glMultMatrixf( const GLfloat *m ); + +GLAPI void GLAPIENTRY glRotated( GLdouble angle, + GLdouble x, GLdouble y, GLdouble z ); +GLAPI void GLAPIENTRY glRotatef( GLfloat angle, + GLfloat x, GLfloat y, GLfloat z ); + +GLAPI void GLAPIENTRY glScaled( GLdouble x, GLdouble y, GLdouble z ); +GLAPI void GLAPIENTRY glScalef( GLfloat x, GLfloat y, GLfloat z ); + +GLAPI void GLAPIENTRY glTranslated( GLdouble x, GLdouble y, GLdouble z ); +GLAPI void GLAPIENTRY glTranslatef( GLfloat x, GLfloat y, GLfloat z ); + + +/* + * Display Lists + */ + +GLAPI GLboolean GLAPIENTRY glIsList( GLuint list ); + +GLAPI void GLAPIENTRY glDeleteLists( GLuint list, GLsizei range ); + +GLAPI GLuint GLAPIENTRY glGenLists( GLsizei range ); + +GLAPI void GLAPIENTRY glNewList( GLuint list, GLenum mode ); + +GLAPI void GLAPIENTRY glEndList( void ); + +GLAPI void GLAPIENTRY glCallList( GLuint list ); + +GLAPI void GLAPIENTRY glCallLists( GLsizei n, GLenum type, + const GLvoid *lists ); + +GLAPI void GLAPIENTRY glListBase( GLuint base ); + + +/* + * Drawing Functions + */ + +GLAPI void GLAPIENTRY glBegin( GLenum mode ); + +GLAPI void GLAPIENTRY glEnd( void ); + + +GLAPI void GLAPIENTRY glVertex2d( GLdouble x, GLdouble y ); +GLAPI void GLAPIENTRY glVertex2f( GLfloat x, GLfloat y ); +GLAPI void GLAPIENTRY glVertex2i( GLint x, GLint y ); +GLAPI void GLAPIENTRY glVertex2s( GLshort x, GLshort y ); + +GLAPI void GLAPIENTRY glVertex3d( GLdouble x, GLdouble y, GLdouble z ); +GLAPI void GLAPIENTRY glVertex3f( GLfloat x, GLfloat y, GLfloat z ); +GLAPI void GLAPIENTRY glVertex3i( GLint x, GLint y, GLint z ); +GLAPI void GLAPIENTRY glVertex3s( GLshort x, GLshort y, GLshort z ); + +GLAPI void GLAPIENTRY glVertex4d( GLdouble x, GLdouble y, GLdouble z, GLdouble w ); +GLAPI void GLAPIENTRY glVertex4f( GLfloat x, GLfloat y, GLfloat z, GLfloat w ); +GLAPI void GLAPIENTRY glVertex4i( GLint x, GLint y, GLint z, GLint w ); +GLAPI void GLAPIENTRY glVertex4s( GLshort x, GLshort y, GLshort z, GLshort w ); + +GLAPI void GLAPIENTRY glVertex2dv( const GLdouble *v ); +GLAPI void GLAPIENTRY glVertex2fv( const GLfloat *v ); +GLAPI void GLAPIENTRY glVertex2iv( const GLint *v ); +GLAPI void GLAPIENTRY glVertex2sv( const GLshort *v ); + +GLAPI void GLAPIENTRY glVertex3dv( const GLdouble *v ); +GLAPI void GLAPIENTRY glVertex3fv( const GLfloat *v ); +GLAPI void GLAPIENTRY glVertex3iv( const GLint *v ); +GLAPI void GLAPIENTRY glVertex3sv( const GLshort *v ); + +GLAPI void GLAPIENTRY glVertex4dv( const GLdouble *v ); +GLAPI void GLAPIENTRY glVertex4fv( const GLfloat *v ); +GLAPI void GLAPIENTRY glVertex4iv( const GLint *v ); +GLAPI void GLAPIENTRY glVertex4sv( const GLshort *v ); + + +GLAPI void GLAPIENTRY glNormal3b( GLbyte nx, GLbyte ny, GLbyte nz ); +GLAPI void GLAPIENTRY glNormal3d( GLdouble nx, GLdouble ny, GLdouble nz ); +GLAPI void GLAPIENTRY glNormal3f( GLfloat nx, GLfloat ny, GLfloat nz ); +GLAPI void GLAPIENTRY glNormal3i( GLint nx, GLint ny, GLint nz ); +GLAPI void GLAPIENTRY glNormal3s( GLshort nx, GLshort ny, GLshort nz ); + +GLAPI void GLAPIENTRY glNormal3bv( const GLbyte *v ); +GLAPI void GLAPIENTRY glNormal3dv( const GLdouble *v ); +GLAPI void GLAPIENTRY glNormal3fv( const GLfloat *v ); +GLAPI void GLAPIENTRY glNormal3iv( const GLint *v ); +GLAPI void GLAPIENTRY glNormal3sv( const GLshort *v ); + + +GLAPI void GLAPIENTRY glIndexd( GLdouble c ); +GLAPI void GLAPIENTRY glIndexf( GLfloat c ); +GLAPI void GLAPIENTRY glIndexi( GLint c ); +GLAPI void GLAPIENTRY glIndexs( GLshort c ); +GLAPI void GLAPIENTRY glIndexub( GLubyte c ); /* 1.1 */ + +GLAPI void GLAPIENTRY glIndexdv( const GLdouble *c ); +GLAPI void GLAPIENTRY glIndexfv( const GLfloat *c ); +GLAPI void GLAPIENTRY glIndexiv( const GLint *c ); +GLAPI void GLAPIENTRY glIndexsv( const GLshort *c ); +GLAPI void GLAPIENTRY glIndexubv( const GLubyte *c ); /* 1.1 */ + +GLAPI void GLAPIENTRY glColor3b( GLbyte red, GLbyte green, GLbyte blue ); +GLAPI void GLAPIENTRY glColor3d( GLdouble red, GLdouble green, GLdouble blue ); +GLAPI void GLAPIENTRY glColor3f( GLfloat red, GLfloat green, GLfloat blue ); +GLAPI void GLAPIENTRY glColor3i( GLint red, GLint green, GLint blue ); +GLAPI void GLAPIENTRY glColor3s( GLshort red, GLshort green, GLshort blue ); +GLAPI void GLAPIENTRY glColor3ub( GLubyte red, GLubyte green, GLubyte blue ); +GLAPI void GLAPIENTRY glColor3ui( GLuint red, GLuint green, GLuint blue ); +GLAPI void GLAPIENTRY glColor3us( GLushort red, GLushort green, GLushort blue ); + +GLAPI void GLAPIENTRY glColor4b( GLbyte red, GLbyte green, + GLbyte blue, GLbyte alpha ); +GLAPI void GLAPIENTRY glColor4d( GLdouble red, GLdouble green, + GLdouble blue, GLdouble alpha ); +GLAPI void GLAPIENTRY glColor4f( GLfloat red, GLfloat green, + GLfloat blue, GLfloat alpha ); +GLAPI void GLAPIENTRY glColor4i( GLint red, GLint green, + GLint blue, GLint alpha ); +GLAPI void GLAPIENTRY glColor4s( GLshort red, GLshort green, + GLshort blue, GLshort alpha ); +GLAPI void GLAPIENTRY glColor4ub( GLubyte red, GLubyte green, + GLubyte blue, GLubyte alpha ); +GLAPI void GLAPIENTRY glColor4ui( GLuint red, GLuint green, + GLuint blue, GLuint alpha ); +GLAPI void GLAPIENTRY glColor4us( GLushort red, GLushort green, + GLushort blue, GLushort alpha ); + + +GLAPI void GLAPIENTRY glColor3bv( const GLbyte *v ); +GLAPI void GLAPIENTRY glColor3dv( const GLdouble *v ); +GLAPI void GLAPIENTRY glColor3fv( const GLfloat *v ); +GLAPI void GLAPIENTRY glColor3iv( const GLint *v ); +GLAPI void GLAPIENTRY glColor3sv( const GLshort *v ); +GLAPI void GLAPIENTRY glColor3ubv( const GLubyte *v ); +GLAPI void GLAPIENTRY glColor3uiv( const GLuint *v ); +GLAPI void GLAPIENTRY glColor3usv( const GLushort *v ); + +GLAPI void GLAPIENTRY glColor4bv( const GLbyte *v ); +GLAPI void GLAPIENTRY glColor4dv( const GLdouble *v ); +GLAPI void GLAPIENTRY glColor4fv( const GLfloat *v ); +GLAPI void GLAPIENTRY glColor4iv( const GLint *v ); +GLAPI void GLAPIENTRY glColor4sv( const GLshort *v ); +GLAPI void GLAPIENTRY glColor4ubv( const GLubyte *v ); +GLAPI void GLAPIENTRY glColor4uiv( const GLuint *v ); +GLAPI void GLAPIENTRY glColor4usv( const GLushort *v ); + + +GLAPI void GLAPIENTRY glTexCoord1d( GLdouble s ); +GLAPI void GLAPIENTRY glTexCoord1f( GLfloat s ); +GLAPI void GLAPIENTRY glTexCoord1i( GLint s ); +GLAPI void GLAPIENTRY glTexCoord1s( GLshort s ); + +GLAPI void GLAPIENTRY glTexCoord2d( GLdouble s, GLdouble t ); +GLAPI void GLAPIENTRY glTexCoord2f( GLfloat s, GLfloat t ); +GLAPI void GLAPIENTRY glTexCoord2i( GLint s, GLint t ); +GLAPI void GLAPIENTRY glTexCoord2s( GLshort s, GLshort t ); + +GLAPI void GLAPIENTRY glTexCoord3d( GLdouble s, GLdouble t, GLdouble r ); +GLAPI void GLAPIENTRY glTexCoord3f( GLfloat s, GLfloat t, GLfloat r ); +GLAPI void GLAPIENTRY glTexCoord3i( GLint s, GLint t, GLint r ); +GLAPI void GLAPIENTRY glTexCoord3s( GLshort s, GLshort t, GLshort r ); + +GLAPI void GLAPIENTRY glTexCoord4d( GLdouble s, GLdouble t, GLdouble r, GLdouble q ); +GLAPI void GLAPIENTRY glTexCoord4f( GLfloat s, GLfloat t, GLfloat r, GLfloat q ); +GLAPI void GLAPIENTRY glTexCoord4i( GLint s, GLint t, GLint r, GLint q ); +GLAPI void GLAPIENTRY glTexCoord4s( GLshort s, GLshort t, GLshort r, GLshort q ); + +GLAPI void GLAPIENTRY glTexCoord1dv( const GLdouble *v ); +GLAPI void GLAPIENTRY glTexCoord1fv( const GLfloat *v ); +GLAPI void GLAPIENTRY glTexCoord1iv( const GLint *v ); +GLAPI void GLAPIENTRY glTexCoord1sv( const GLshort *v ); + +GLAPI void GLAPIENTRY glTexCoord2dv( const GLdouble *v ); +GLAPI void GLAPIENTRY glTexCoord2fv( const GLfloat *v ); +GLAPI void GLAPIENTRY glTexCoord2iv( const GLint *v ); +GLAPI void GLAPIENTRY glTexCoord2sv( const GLshort *v ); + +GLAPI void GLAPIENTRY glTexCoord3dv( const GLdouble *v ); +GLAPI void GLAPIENTRY glTexCoord3fv( const GLfloat *v ); +GLAPI void GLAPIENTRY glTexCoord3iv( const GLint *v ); +GLAPI void GLAPIENTRY glTexCoord3sv( const GLshort *v ); + +GLAPI void GLAPIENTRY glTexCoord4dv( const GLdouble *v ); +GLAPI void GLAPIENTRY glTexCoord4fv( const GLfloat *v ); +GLAPI void GLAPIENTRY glTexCoord4iv( const GLint *v ); +GLAPI void GLAPIENTRY glTexCoord4sv( const GLshort *v ); + + +GLAPI void GLAPIENTRY glRasterPos2d( GLdouble x, GLdouble y ); +GLAPI void GLAPIENTRY glRasterPos2f( GLfloat x, GLfloat y ); +GLAPI void GLAPIENTRY glRasterPos2i( GLint x, GLint y ); +GLAPI void GLAPIENTRY glRasterPos2s( GLshort x, GLshort y ); + +GLAPI void GLAPIENTRY glRasterPos3d( GLdouble x, GLdouble y, GLdouble z ); +GLAPI void GLAPIENTRY glRasterPos3f( GLfloat x, GLfloat y, GLfloat z ); +GLAPI void GLAPIENTRY glRasterPos3i( GLint x, GLint y, GLint z ); +GLAPI void GLAPIENTRY glRasterPos3s( GLshort x, GLshort y, GLshort z ); + +GLAPI void GLAPIENTRY glRasterPos4d( GLdouble x, GLdouble y, GLdouble z, GLdouble w ); +GLAPI void GLAPIENTRY glRasterPos4f( GLfloat x, GLfloat y, GLfloat z, GLfloat w ); +GLAPI void GLAPIENTRY glRasterPos4i( GLint x, GLint y, GLint z, GLint w ); +GLAPI void GLAPIENTRY glRasterPos4s( GLshort x, GLshort y, GLshort z, GLshort w ); + +GLAPI void GLAPIENTRY glRasterPos2dv( const GLdouble *v ); +GLAPI void GLAPIENTRY glRasterPos2fv( const GLfloat *v ); +GLAPI void GLAPIENTRY glRasterPos2iv( const GLint *v ); +GLAPI void GLAPIENTRY glRasterPos2sv( const GLshort *v ); + +GLAPI void GLAPIENTRY glRasterPos3dv( const GLdouble *v ); +GLAPI void GLAPIENTRY glRasterPos3fv( const GLfloat *v ); +GLAPI void GLAPIENTRY glRasterPos3iv( const GLint *v ); +GLAPI void GLAPIENTRY glRasterPos3sv( const GLshort *v ); + +GLAPI void GLAPIENTRY glRasterPos4dv( const GLdouble *v ); +GLAPI void GLAPIENTRY glRasterPos4fv( const GLfloat *v ); +GLAPI void GLAPIENTRY glRasterPos4iv( const GLint *v ); +GLAPI void GLAPIENTRY glRasterPos4sv( const GLshort *v ); + + +GLAPI void GLAPIENTRY glRectd( GLdouble x1, GLdouble y1, GLdouble x2, GLdouble y2 ); +GLAPI void GLAPIENTRY glRectf( GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2 ); +GLAPI void GLAPIENTRY glRecti( GLint x1, GLint y1, GLint x2, GLint y2 ); +GLAPI void GLAPIENTRY glRects( GLshort x1, GLshort y1, GLshort x2, GLshort y2 ); + + +GLAPI void GLAPIENTRY glRectdv( const GLdouble *v1, const GLdouble *v2 ); +GLAPI void GLAPIENTRY glRectfv( const GLfloat *v1, const GLfloat *v2 ); +GLAPI void GLAPIENTRY glRectiv( const GLint *v1, const GLint *v2 ); +GLAPI void GLAPIENTRY glRectsv( const GLshort *v1, const GLshort *v2 ); + + +/* + * Vertex Arrays (1.1) + */ + +GLAPI void GLAPIENTRY glVertexPointer( GLint size, GLenum type, + GLsizei stride, const GLvoid *ptr ); + +GLAPI void GLAPIENTRY glNormalPointer( GLenum type, GLsizei stride, + const GLvoid *ptr ); + +GLAPI void GLAPIENTRY glColorPointer( GLint size, GLenum type, + GLsizei stride, const GLvoid *ptr ); + +GLAPI void GLAPIENTRY glIndexPointer( GLenum type, GLsizei stride, + const GLvoid *ptr ); + +GLAPI void GLAPIENTRY glTexCoordPointer( GLint size, GLenum type, + GLsizei stride, const GLvoid *ptr ); + +GLAPI void GLAPIENTRY glEdgeFlagPointer( GLsizei stride, const GLvoid *ptr ); + +GLAPI void GLAPIENTRY glGetPointerv( GLenum pname, GLvoid **params ); + +GLAPI void GLAPIENTRY glArrayElement( GLint i ); + +GLAPI void GLAPIENTRY glDrawArrays( GLenum mode, GLint first, GLsizei count ); + +GLAPI void GLAPIENTRY glDrawElements( GLenum mode, GLsizei count, + GLenum type, const GLvoid *indices ); + +GLAPI void GLAPIENTRY glInterleavedArrays( GLenum format, GLsizei stride, + const GLvoid *pointer ); + +/* + * Lighting + */ + +GLAPI void GLAPIENTRY glShadeModel( GLenum mode ); + +GLAPI void GLAPIENTRY glLightf( GLenum light, GLenum pname, GLfloat param ); +GLAPI void GLAPIENTRY glLighti( GLenum light, GLenum pname, GLint param ); +GLAPI void GLAPIENTRY glLightfv( GLenum light, GLenum pname, + const GLfloat *params ); +GLAPI void GLAPIENTRY glLightiv( GLenum light, GLenum pname, + const GLint *params ); + +GLAPI void GLAPIENTRY glGetLightfv( GLenum light, GLenum pname, + GLfloat *params ); +GLAPI void GLAPIENTRY glGetLightiv( GLenum light, GLenum pname, + GLint *params ); + +GLAPI void GLAPIENTRY glLightModelf( GLenum pname, GLfloat param ); +GLAPI void GLAPIENTRY glLightModeli( GLenum pname, GLint param ); +GLAPI void GLAPIENTRY glLightModelfv( GLenum pname, const GLfloat *params ); +GLAPI void GLAPIENTRY glLightModeliv( GLenum pname, const GLint *params ); + +GLAPI void GLAPIENTRY glMaterialf( GLenum face, GLenum pname, GLfloat param ); +GLAPI void GLAPIENTRY glMateriali( GLenum face, GLenum pname, GLint param ); +GLAPI void GLAPIENTRY glMaterialfv( GLenum face, GLenum pname, const GLfloat *params ); +GLAPI void GLAPIENTRY glMaterialiv( GLenum face, GLenum pname, const GLint *params ); + +GLAPI void GLAPIENTRY glGetMaterialfv( GLenum face, GLenum pname, GLfloat *params ); +GLAPI void GLAPIENTRY glGetMaterialiv( GLenum face, GLenum pname, GLint *params ); + +GLAPI void GLAPIENTRY glColorMaterial( GLenum face, GLenum mode ); + + +/* + * Raster functions + */ + +GLAPI void GLAPIENTRY glPixelZoom( GLfloat xfactor, GLfloat yfactor ); + +GLAPI void GLAPIENTRY glPixelStoref( GLenum pname, GLfloat param ); +GLAPI void GLAPIENTRY glPixelStorei( GLenum pname, GLint param ); + +GLAPI void GLAPIENTRY glPixelTransferf( GLenum pname, GLfloat param ); +GLAPI void GLAPIENTRY glPixelTransferi( GLenum pname, GLint param ); + +GLAPI void GLAPIENTRY glPixelMapfv( GLenum map, GLsizei mapsize, + const GLfloat *values ); +GLAPI void GLAPIENTRY glPixelMapuiv( GLenum map, GLsizei mapsize, + const GLuint *values ); +GLAPI void GLAPIENTRY glPixelMapusv( GLenum map, GLsizei mapsize, + const GLushort *values ); + +GLAPI void GLAPIENTRY glGetPixelMapfv( GLenum map, GLfloat *values ); +GLAPI void GLAPIENTRY glGetPixelMapuiv( GLenum map, GLuint *values ); +GLAPI void GLAPIENTRY glGetPixelMapusv( GLenum map, GLushort *values ); + +GLAPI void GLAPIENTRY glBitmap( GLsizei width, GLsizei height, + GLfloat xorig, GLfloat yorig, + GLfloat xmove, GLfloat ymove, + const GLubyte *bitmap ); + +GLAPI void GLAPIENTRY glReadPixels( GLint x, GLint y, + GLsizei width, GLsizei height, + GLenum format, GLenum type, + GLvoid *pixels ); + +GLAPI void GLAPIENTRY glDrawPixels( GLsizei width, GLsizei height, + GLenum format, GLenum type, + const GLvoid *pixels ); + +GLAPI void GLAPIENTRY glCopyPixels( GLint x, GLint y, + GLsizei width, GLsizei height, + GLenum type ); + +/* + * Stenciling + */ + +GLAPI void GLAPIENTRY glStencilFunc( GLenum func, GLint ref, GLuint mask ); + +GLAPI void GLAPIENTRY glStencilMask( GLuint mask ); + +GLAPI void GLAPIENTRY glStencilOp( GLenum fail, GLenum zfail, GLenum zpass ); + +GLAPI void GLAPIENTRY glClearStencil( GLint s ); + + + +/* + * Texture mapping + */ + +GLAPI void GLAPIENTRY glTexGend( GLenum coord, GLenum pname, GLdouble param ); +GLAPI void GLAPIENTRY glTexGenf( GLenum coord, GLenum pname, GLfloat param ); +GLAPI void GLAPIENTRY glTexGeni( GLenum coord, GLenum pname, GLint param ); + +GLAPI void GLAPIENTRY glTexGendv( GLenum coord, GLenum pname, const GLdouble *params ); +GLAPI void GLAPIENTRY glTexGenfv( GLenum coord, GLenum pname, const GLfloat *params ); +GLAPI void GLAPIENTRY glTexGeniv( GLenum coord, GLenum pname, const GLint *params ); + +GLAPI void GLAPIENTRY glGetTexGendv( GLenum coord, GLenum pname, GLdouble *params ); +GLAPI void GLAPIENTRY glGetTexGenfv( GLenum coord, GLenum pname, GLfloat *params ); +GLAPI void GLAPIENTRY glGetTexGeniv( GLenum coord, GLenum pname, GLint *params ); + + +GLAPI void GLAPIENTRY glTexEnvf( GLenum target, GLenum pname, GLfloat param ); +GLAPI void GLAPIENTRY glTexEnvi( GLenum target, GLenum pname, GLint param ); + +GLAPI void GLAPIENTRY glTexEnvfv( GLenum target, GLenum pname, const GLfloat *params ); +GLAPI void GLAPIENTRY glTexEnviv( GLenum target, GLenum pname, const GLint *params ); + +GLAPI void GLAPIENTRY glGetTexEnvfv( GLenum target, GLenum pname, GLfloat *params ); +GLAPI void GLAPIENTRY glGetTexEnviv( GLenum target, GLenum pname, GLint *params ); + + +GLAPI void GLAPIENTRY glTexParameterf( GLenum target, GLenum pname, GLfloat param ); +GLAPI void GLAPIENTRY glTexParameteri( GLenum target, GLenum pname, GLint param ); + +GLAPI void GLAPIENTRY glTexParameterfv( GLenum target, GLenum pname, + const GLfloat *params ); +GLAPI void GLAPIENTRY glTexParameteriv( GLenum target, GLenum pname, + const GLint *params ); + +GLAPI void GLAPIENTRY glGetTexParameterfv( GLenum target, + GLenum pname, GLfloat *params); +GLAPI void GLAPIENTRY glGetTexParameteriv( GLenum target, + GLenum pname, GLint *params ); + +GLAPI void GLAPIENTRY glGetTexLevelParameterfv( GLenum target, GLint level, + GLenum pname, GLfloat *params ); +GLAPI void GLAPIENTRY glGetTexLevelParameteriv( GLenum target, GLint level, + GLenum pname, GLint *params ); + + +GLAPI void GLAPIENTRY glTexImage1D( GLenum target, GLint level, + GLint internalFormat, + GLsizei width, GLint border, + GLenum format, GLenum type, + const GLvoid *pixels ); + +GLAPI void GLAPIENTRY glTexImage2D( GLenum target, GLint level, + GLint internalFormat, + GLsizei width, GLsizei height, + GLint border, GLenum format, GLenum type, + const GLvoid *pixels ); + +GLAPI void GLAPIENTRY glGetTexImage( GLenum target, GLint level, + GLenum format, GLenum type, + GLvoid *pixels ); + + +/* 1.1 functions */ + +GLAPI void GLAPIENTRY glGenTextures( GLsizei n, GLuint *textures ); + +GLAPI void GLAPIENTRY glDeleteTextures( GLsizei n, const GLuint *textures); + +GLAPI void GLAPIENTRY glBindTexture( GLenum target, GLuint texture ); + +GLAPI void GLAPIENTRY glPrioritizeTextures( GLsizei n, + const GLuint *textures, + const GLclampf *priorities ); + +GLAPI GLboolean GLAPIENTRY glAreTexturesResident( GLsizei n, + const GLuint *textures, + GLboolean *residences ); + +GLAPI GLboolean GLAPIENTRY glIsTexture( GLuint texture ); + + +GLAPI void GLAPIENTRY glTexSubImage1D( GLenum target, GLint level, + GLint xoffset, + GLsizei width, GLenum format, + GLenum type, const GLvoid *pixels ); + + +GLAPI void GLAPIENTRY glTexSubImage2D( GLenum target, GLint level, + GLint xoffset, GLint yoffset, + GLsizei width, GLsizei height, + GLenum format, GLenum type, + const GLvoid *pixels ); + + +GLAPI void GLAPIENTRY glCopyTexImage1D( GLenum target, GLint level, + GLenum internalformat, + GLint x, GLint y, + GLsizei width, GLint border ); + + +GLAPI void GLAPIENTRY glCopyTexImage2D( GLenum target, GLint level, + GLenum internalformat, + GLint x, GLint y, + GLsizei width, GLsizei height, + GLint border ); + + +GLAPI void GLAPIENTRY glCopyTexSubImage1D( GLenum target, GLint level, + GLint xoffset, GLint x, GLint y, + GLsizei width ); + + +GLAPI void GLAPIENTRY glCopyTexSubImage2D( GLenum target, GLint level, + GLint xoffset, GLint yoffset, + GLint x, GLint y, + GLsizei width, GLsizei height ); + + +/* + * Evaluators + */ + +GLAPI void GLAPIENTRY glMap1d( GLenum target, GLdouble u1, GLdouble u2, + GLint stride, + GLint order, const GLdouble *points ); +GLAPI void GLAPIENTRY glMap1f( GLenum target, GLfloat u1, GLfloat u2, + GLint stride, + GLint order, const GLfloat *points ); + +GLAPI void GLAPIENTRY glMap2d( GLenum target, + GLdouble u1, GLdouble u2, GLint ustride, GLint uorder, + GLdouble v1, GLdouble v2, GLint vstride, GLint vorder, + const GLdouble *points ); +GLAPI void GLAPIENTRY glMap2f( GLenum target, + GLfloat u1, GLfloat u2, GLint ustride, GLint uorder, + GLfloat v1, GLfloat v2, GLint vstride, GLint vorder, + const GLfloat *points ); + +GLAPI void GLAPIENTRY glGetMapdv( GLenum target, GLenum query, GLdouble *v ); +GLAPI void GLAPIENTRY glGetMapfv( GLenum target, GLenum query, GLfloat *v ); +GLAPI void GLAPIENTRY glGetMapiv( GLenum target, GLenum query, GLint *v ); + +GLAPI void GLAPIENTRY glEvalCoord1d( GLdouble u ); +GLAPI void GLAPIENTRY glEvalCoord1f( GLfloat u ); + +GLAPI void GLAPIENTRY glEvalCoord1dv( const GLdouble *u ); +GLAPI void GLAPIENTRY glEvalCoord1fv( const GLfloat *u ); + +GLAPI void GLAPIENTRY glEvalCoord2d( GLdouble u, GLdouble v ); +GLAPI void GLAPIENTRY glEvalCoord2f( GLfloat u, GLfloat v ); + +GLAPI void GLAPIENTRY glEvalCoord2dv( const GLdouble *u ); +GLAPI void GLAPIENTRY glEvalCoord2fv( const GLfloat *u ); + +GLAPI void GLAPIENTRY glMapGrid1d( GLint un, GLdouble u1, GLdouble u2 ); +GLAPI void GLAPIENTRY glMapGrid1f( GLint un, GLfloat u1, GLfloat u2 ); + +GLAPI void GLAPIENTRY glMapGrid2d( GLint un, GLdouble u1, GLdouble u2, + GLint vn, GLdouble v1, GLdouble v2 ); +GLAPI void GLAPIENTRY glMapGrid2f( GLint un, GLfloat u1, GLfloat u2, + GLint vn, GLfloat v1, GLfloat v2 ); + +GLAPI void GLAPIENTRY glEvalPoint1( GLint i ); + +GLAPI void GLAPIENTRY glEvalPoint2( GLint i, GLint j ); + +GLAPI void GLAPIENTRY glEvalMesh1( GLenum mode, GLint i1, GLint i2 ); + +GLAPI void GLAPIENTRY glEvalMesh2( GLenum mode, GLint i1, GLint i2, GLint j1, GLint j2 ); + + +/* + * Fog + */ + +GLAPI void GLAPIENTRY glFogf( GLenum pname, GLfloat param ); + +GLAPI void GLAPIENTRY glFogi( GLenum pname, GLint param ); + +GLAPI void GLAPIENTRY glFogfv( GLenum pname, const GLfloat *params ); + +GLAPI void GLAPIENTRY glFogiv( GLenum pname, const GLint *params ); + + +/* + * Selection and Feedback + */ + +GLAPI void GLAPIENTRY glFeedbackBuffer( GLsizei size, GLenum type, GLfloat *buffer ); + +GLAPI void GLAPIENTRY glPassThrough( GLfloat token ); + +GLAPI void GLAPIENTRY glSelectBuffer( GLsizei size, GLuint *buffer ); + +GLAPI void GLAPIENTRY glInitNames( void ); + +GLAPI void GLAPIENTRY glLoadName( GLuint name ); + +GLAPI void GLAPIENTRY glPushName( GLuint name ); + +GLAPI void GLAPIENTRY glPopName( void ); + + + +/* + * OpenGL 1.2 + */ + +#define GL_RESCALE_NORMAL 0x803A +#define GL_CLAMP_TO_EDGE 0x812F +#define GL_MAX_ELEMENTS_VERTICES 0x80E8 +#define GL_MAX_ELEMENTS_INDICES 0x80E9 +#define GL_BGR 0x80E0 +#define GL_BGRA 0x80E1 +#define GL_UNSIGNED_BYTE_3_3_2 0x8032 +#define GL_UNSIGNED_BYTE_2_3_3_REV 0x8362 +#define GL_UNSIGNED_SHORT_5_6_5 0x8363 +#define GL_UNSIGNED_SHORT_5_6_5_REV 0x8364 +#define GL_UNSIGNED_SHORT_4_4_4_4 0x8033 +#define GL_UNSIGNED_SHORT_4_4_4_4_REV 0x8365 +#define GL_UNSIGNED_SHORT_5_5_5_1 0x8034 +#define GL_UNSIGNED_SHORT_1_5_5_5_REV 0x8366 +#define GL_UNSIGNED_INT_8_8_8_8 0x8035 +#define GL_UNSIGNED_INT_8_8_8_8_REV 0x8367 +#define GL_UNSIGNED_INT_10_10_10_2 0x8036 +#define GL_UNSIGNED_INT_2_10_10_10_REV 0x8368 +#define GL_LIGHT_MODEL_COLOR_CONTROL 0x81F8 +#define GL_SINGLE_COLOR 0x81F9 +#define GL_SEPARATE_SPECULAR_COLOR 0x81FA +#define GL_TEXTURE_MIN_LOD 0x813A +#define GL_TEXTURE_MAX_LOD 0x813B +#define GL_TEXTURE_BASE_LEVEL 0x813C +#define GL_TEXTURE_MAX_LEVEL 0x813D +#define GL_SMOOTH_POINT_SIZE_RANGE 0x0B12 +#define GL_SMOOTH_POINT_SIZE_GRANULARITY 0x0B13 +#define GL_SMOOTH_LINE_WIDTH_RANGE 0x0B22 +#define GL_SMOOTH_LINE_WIDTH_GRANULARITY 0x0B23 +#define GL_ALIASED_POINT_SIZE_RANGE 0x846D +#define GL_ALIASED_LINE_WIDTH_RANGE 0x846E +#define GL_PACK_SKIP_IMAGES 0x806B +#define GL_PACK_IMAGE_HEIGHT 0x806C +#define GL_UNPACK_SKIP_IMAGES 0x806D +#define GL_UNPACK_IMAGE_HEIGHT 0x806E +#define GL_TEXTURE_3D 0x806F +#define GL_PROXY_TEXTURE_3D 0x8070 +#define GL_TEXTURE_DEPTH 0x8071 +#define GL_TEXTURE_WRAP_R 0x8072 +#define GL_MAX_3D_TEXTURE_SIZE 0x8073 +#define GL_TEXTURE_BINDING_3D 0x806A + +GLAPI void GLAPIENTRY glDrawRangeElements( GLenum mode, GLuint start, + GLuint end, GLsizei count, GLenum type, const GLvoid *indices ); + +GLAPI void GLAPIENTRY glTexImage3D( GLenum target, GLint level, + GLint internalFormat, + GLsizei width, GLsizei height, + GLsizei depth, GLint border, + GLenum format, GLenum type, + const GLvoid *pixels ); + +GLAPI void GLAPIENTRY glTexSubImage3D( GLenum target, GLint level, + GLint xoffset, GLint yoffset, + GLint zoffset, GLsizei width, + GLsizei height, GLsizei depth, + GLenum format, + GLenum type, const GLvoid *pixels); + +GLAPI void GLAPIENTRY glCopyTexSubImage3D( GLenum target, GLint level, + GLint xoffset, GLint yoffset, + GLint zoffset, GLint x, + GLint y, GLsizei width, + GLsizei height ); + +typedef void (APIENTRYP PFNGLDRAWRANGEELEMENTSPROC) (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices); +typedef void (APIENTRYP PFNGLTEXIMAGE3DPROC) (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels); +typedef void (APIENTRYP PFNGLTEXSUBIMAGE3DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *pixels); +typedef void (APIENTRYP PFNGLCOPYTEXSUBIMAGE3DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height); + + +/* + * GL_ARB_imaging + */ + +#define GL_CONSTANT_COLOR 0x8001 +#define GL_ONE_MINUS_CONSTANT_COLOR 0x8002 +#define GL_CONSTANT_ALPHA 0x8003 +#define GL_ONE_MINUS_CONSTANT_ALPHA 0x8004 +#define GL_COLOR_TABLE 0x80D0 +#define GL_POST_CONVOLUTION_COLOR_TABLE 0x80D1 +#define GL_POST_COLOR_MATRIX_COLOR_TABLE 0x80D2 +#define GL_PROXY_COLOR_TABLE 0x80D3 +#define GL_PROXY_POST_CONVOLUTION_COLOR_TABLE 0x80D4 +#define GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE 0x80D5 +#define GL_COLOR_TABLE_SCALE 0x80D6 +#define GL_COLOR_TABLE_BIAS 0x80D7 +#define GL_COLOR_TABLE_FORMAT 0x80D8 +#define GL_COLOR_TABLE_WIDTH 0x80D9 +#define GL_COLOR_TABLE_RED_SIZE 0x80DA +#define GL_COLOR_TABLE_GREEN_SIZE 0x80DB +#define GL_COLOR_TABLE_BLUE_SIZE 0x80DC +#define GL_COLOR_TABLE_ALPHA_SIZE 0x80DD +#define GL_COLOR_TABLE_LUMINANCE_SIZE 0x80DE +#define GL_COLOR_TABLE_INTENSITY_SIZE 0x80DF +#define GL_CONVOLUTION_1D 0x8010 +#define GL_CONVOLUTION_2D 0x8011 +#define GL_SEPARABLE_2D 0x8012 +#define GL_CONVOLUTION_BORDER_MODE 0x8013 +#define GL_CONVOLUTION_FILTER_SCALE 0x8014 +#define GL_CONVOLUTION_FILTER_BIAS 0x8015 +#define GL_REDUCE 0x8016 +#define GL_CONVOLUTION_FORMAT 0x8017 +#define GL_CONVOLUTION_WIDTH 0x8018 +#define GL_CONVOLUTION_HEIGHT 0x8019 +#define GL_MAX_CONVOLUTION_WIDTH 0x801A +#define GL_MAX_CONVOLUTION_HEIGHT 0x801B +#define GL_POST_CONVOLUTION_RED_SCALE 0x801C +#define GL_POST_CONVOLUTION_GREEN_SCALE 0x801D +#define GL_POST_CONVOLUTION_BLUE_SCALE 0x801E +#define GL_POST_CONVOLUTION_ALPHA_SCALE 0x801F +#define GL_POST_CONVOLUTION_RED_BIAS 0x8020 +#define GL_POST_CONVOLUTION_GREEN_BIAS 0x8021 +#define GL_POST_CONVOLUTION_BLUE_BIAS 0x8022 +#define GL_POST_CONVOLUTION_ALPHA_BIAS 0x8023 +#define GL_CONSTANT_BORDER 0x8151 +#define GL_REPLICATE_BORDER 0x8153 +#define GL_CONVOLUTION_BORDER_COLOR 0x8154 +#define GL_COLOR_MATRIX 0x80B1 +#define GL_COLOR_MATRIX_STACK_DEPTH 0x80B2 +#define GL_MAX_COLOR_MATRIX_STACK_DEPTH 0x80B3 +#define GL_POST_COLOR_MATRIX_RED_SCALE 0x80B4 +#define GL_POST_COLOR_MATRIX_GREEN_SCALE 0x80B5 +#define GL_POST_COLOR_MATRIX_BLUE_SCALE 0x80B6 +#define GL_POST_COLOR_MATRIX_ALPHA_SCALE 0x80B7 +#define GL_POST_COLOR_MATRIX_RED_BIAS 0x80B8 +#define GL_POST_COLOR_MATRIX_GREEN_BIAS 0x80B9 +#define GL_POST_COLOR_MATRIX_BLUE_BIAS 0x80BA +#define GL_POST_COLOR_MATRIX_ALPHA_BIAS 0x80BB +#define GL_HISTOGRAM 0x8024 +#define GL_PROXY_HISTOGRAM 0x8025 +#define GL_HISTOGRAM_WIDTH 0x8026 +#define GL_HISTOGRAM_FORMAT 0x8027 +#define GL_HISTOGRAM_RED_SIZE 0x8028 +#define GL_HISTOGRAM_GREEN_SIZE 0x8029 +#define GL_HISTOGRAM_BLUE_SIZE 0x802A +#define GL_HISTOGRAM_ALPHA_SIZE 0x802B +#define GL_HISTOGRAM_LUMINANCE_SIZE 0x802C +#define GL_HISTOGRAM_SINK 0x802D +#define GL_MINMAX 0x802E +#define GL_MINMAX_FORMAT 0x802F +#define GL_MINMAX_SINK 0x8030 +#define GL_TABLE_TOO_LARGE 0x8031 +#define GL_BLEND_EQUATION 0x8009 +#define GL_MIN 0x8007 +#define GL_MAX 0x8008 +#define GL_FUNC_ADD 0x8006 +#define GL_FUNC_SUBTRACT 0x800A +#define GL_FUNC_REVERSE_SUBTRACT 0x800B +#define GL_BLEND_COLOR 0x8005 + + +GLAPI void GLAPIENTRY glColorTable( GLenum target, GLenum internalformat, + GLsizei width, GLenum format, + GLenum type, const GLvoid *table ); + +GLAPI void GLAPIENTRY glColorSubTable( GLenum target, + GLsizei start, GLsizei count, + GLenum format, GLenum type, + const GLvoid *data ); + +GLAPI void GLAPIENTRY glColorTableParameteriv(GLenum target, GLenum pname, + const GLint *params); + +GLAPI void GLAPIENTRY glColorTableParameterfv(GLenum target, GLenum pname, + const GLfloat *params); + +GLAPI void GLAPIENTRY glCopyColorSubTable( GLenum target, GLsizei start, + GLint x, GLint y, GLsizei width ); + +GLAPI void GLAPIENTRY glCopyColorTable( GLenum target, GLenum internalformat, + GLint x, GLint y, GLsizei width ); + +GLAPI void GLAPIENTRY glGetColorTable( GLenum target, GLenum format, + GLenum type, GLvoid *table ); + +GLAPI void GLAPIENTRY glGetColorTableParameterfv( GLenum target, GLenum pname, + GLfloat *params ); + +GLAPI void GLAPIENTRY glGetColorTableParameteriv( GLenum target, GLenum pname, + GLint *params ); + +GLAPI void GLAPIENTRY glBlendEquation( GLenum mode ); + +GLAPI void GLAPIENTRY glBlendColor( GLclampf red, GLclampf green, + GLclampf blue, GLclampf alpha ); + +GLAPI void GLAPIENTRY glHistogram( GLenum target, GLsizei width, + GLenum internalformat, GLboolean sink ); + +GLAPI void GLAPIENTRY glResetHistogram( GLenum target ); + +GLAPI void GLAPIENTRY glGetHistogram( GLenum target, GLboolean reset, + GLenum format, GLenum type, + GLvoid *values ); + +GLAPI void GLAPIENTRY glGetHistogramParameterfv( GLenum target, GLenum pname, + GLfloat *params ); + +GLAPI void GLAPIENTRY glGetHistogramParameteriv( GLenum target, GLenum pname, + GLint *params ); + +GLAPI void GLAPIENTRY glMinmax( GLenum target, GLenum internalformat, + GLboolean sink ); + +GLAPI void GLAPIENTRY glResetMinmax( GLenum target ); + +GLAPI void GLAPIENTRY glGetMinmax( GLenum target, GLboolean reset, + GLenum format, GLenum types, + GLvoid *values ); + +GLAPI void GLAPIENTRY glGetMinmaxParameterfv( GLenum target, GLenum pname, + GLfloat *params ); + +GLAPI void GLAPIENTRY glGetMinmaxParameteriv( GLenum target, GLenum pname, + GLint *params ); + +GLAPI void GLAPIENTRY glConvolutionFilter1D( GLenum target, + GLenum internalformat, GLsizei width, GLenum format, GLenum type, + const GLvoid *image ); + +GLAPI void GLAPIENTRY glConvolutionFilter2D( GLenum target, + GLenum internalformat, GLsizei width, GLsizei height, GLenum format, + GLenum type, const GLvoid *image ); + +GLAPI void GLAPIENTRY glConvolutionParameterf( GLenum target, GLenum pname, + GLfloat params ); + +GLAPI void GLAPIENTRY glConvolutionParameterfv( GLenum target, GLenum pname, + const GLfloat *params ); + +GLAPI void GLAPIENTRY glConvolutionParameteri( GLenum target, GLenum pname, + GLint params ); + +GLAPI void GLAPIENTRY glConvolutionParameteriv( GLenum target, GLenum pname, + const GLint *params ); + +GLAPI void GLAPIENTRY glCopyConvolutionFilter1D( GLenum target, + GLenum internalformat, GLint x, GLint y, GLsizei width ); + +GLAPI void GLAPIENTRY glCopyConvolutionFilter2D( GLenum target, + GLenum internalformat, GLint x, GLint y, GLsizei width, + GLsizei height); + +GLAPI void GLAPIENTRY glGetConvolutionFilter( GLenum target, GLenum format, + GLenum type, GLvoid *image ); + +GLAPI void GLAPIENTRY glGetConvolutionParameterfv( GLenum target, GLenum pname, + GLfloat *params ); + +GLAPI void GLAPIENTRY glGetConvolutionParameteriv( GLenum target, GLenum pname, + GLint *params ); + +GLAPI void GLAPIENTRY glSeparableFilter2D( GLenum target, + GLenum internalformat, GLsizei width, GLsizei height, GLenum format, + GLenum type, const GLvoid *row, const GLvoid *column ); + +GLAPI void GLAPIENTRY glGetSeparableFilter( GLenum target, GLenum format, + GLenum type, GLvoid *row, GLvoid *column, GLvoid *span ); + +typedef void (APIENTRYP PFNGLBLENDCOLORPROC) (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha); +typedef void (APIENTRYP PFNGLBLENDEQUATIONPROC) (GLenum mode); + + + +/* + * OpenGL 1.3 + */ + +/* multitexture */ +#define GL_TEXTURE0 0x84C0 +#define GL_TEXTURE1 0x84C1 +#define GL_TEXTURE2 0x84C2 +#define GL_TEXTURE3 0x84C3 +#define GL_TEXTURE4 0x84C4 +#define GL_TEXTURE5 0x84C5 +#define GL_TEXTURE6 0x84C6 +#define GL_TEXTURE7 0x84C7 +#define GL_TEXTURE8 0x84C8 +#define GL_TEXTURE9 0x84C9 +#define GL_TEXTURE10 0x84CA +#define GL_TEXTURE11 0x84CB +#define GL_TEXTURE12 0x84CC +#define GL_TEXTURE13 0x84CD +#define GL_TEXTURE14 0x84CE +#define GL_TEXTURE15 0x84CF +#define GL_TEXTURE16 0x84D0 +#define GL_TEXTURE17 0x84D1 +#define GL_TEXTURE18 0x84D2 +#define GL_TEXTURE19 0x84D3 +#define GL_TEXTURE20 0x84D4 +#define GL_TEXTURE21 0x84D5 +#define GL_TEXTURE22 0x84D6 +#define GL_TEXTURE23 0x84D7 +#define GL_TEXTURE24 0x84D8 +#define GL_TEXTURE25 0x84D9 +#define GL_TEXTURE26 0x84DA +#define GL_TEXTURE27 0x84DB +#define GL_TEXTURE28 0x84DC +#define GL_TEXTURE29 0x84DD +#define GL_TEXTURE30 0x84DE +#define GL_TEXTURE31 0x84DF +#define GL_ACTIVE_TEXTURE 0x84E0 +#define GL_CLIENT_ACTIVE_TEXTURE 0x84E1 +#define GL_MAX_TEXTURE_UNITS 0x84E2 +/* texture_cube_map */ +#define GL_NORMAL_MAP 0x8511 +#define GL_REFLECTION_MAP 0x8512 +#define GL_TEXTURE_CUBE_MAP 0x8513 +#define GL_TEXTURE_BINDING_CUBE_MAP 0x8514 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_X 0x8515 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_X 0x8516 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_Y 0x8517 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Y 0x8518 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_Z 0x8519 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Z 0x851A +#define GL_PROXY_TEXTURE_CUBE_MAP 0x851B +#define GL_MAX_CUBE_MAP_TEXTURE_SIZE 0x851C +/* texture_compression */ +#define GL_COMPRESSED_ALPHA 0x84E9 +#define GL_COMPRESSED_LUMINANCE 0x84EA +#define GL_COMPRESSED_LUMINANCE_ALPHA 0x84EB +#define GL_COMPRESSED_INTENSITY 0x84EC +#define GL_COMPRESSED_RGB 0x84ED +#define GL_COMPRESSED_RGBA 0x84EE +#define GL_TEXTURE_COMPRESSION_HINT 0x84EF +#define GL_TEXTURE_COMPRESSED_IMAGE_SIZE 0x86A0 +#define GL_TEXTURE_COMPRESSED 0x86A1 +#define GL_NUM_COMPRESSED_TEXTURE_FORMATS 0x86A2 +#define GL_COMPRESSED_TEXTURE_FORMATS 0x86A3 +/* multisample */ +#define GL_MULTISAMPLE 0x809D +#define GL_SAMPLE_ALPHA_TO_COVERAGE 0x809E +#define GL_SAMPLE_ALPHA_TO_ONE 0x809F +#define GL_SAMPLE_COVERAGE 0x80A0 +#define GL_SAMPLE_BUFFERS 0x80A8 +#define GL_SAMPLES 0x80A9 +#define GL_SAMPLE_COVERAGE_VALUE 0x80AA +#define GL_SAMPLE_COVERAGE_INVERT 0x80AB +#define GL_MULTISAMPLE_BIT 0x20000000 +/* transpose_matrix */ +#define GL_TRANSPOSE_MODELVIEW_MATRIX 0x84E3 +#define GL_TRANSPOSE_PROJECTION_MATRIX 0x84E4 +#define GL_TRANSPOSE_TEXTURE_MATRIX 0x84E5 +#define GL_TRANSPOSE_COLOR_MATRIX 0x84E6 +/* texture_env_combine */ +#define GL_COMBINE 0x8570 +#define GL_COMBINE_RGB 0x8571 +#define GL_COMBINE_ALPHA 0x8572 +#define GL_SOURCE0_RGB 0x8580 +#define GL_SOURCE1_RGB 0x8581 +#define GL_SOURCE2_RGB 0x8582 +#define GL_SOURCE0_ALPHA 0x8588 +#define GL_SOURCE1_ALPHA 0x8589 +#define GL_SOURCE2_ALPHA 0x858A +#define GL_OPERAND0_RGB 0x8590 +#define GL_OPERAND1_RGB 0x8591 +#define GL_OPERAND2_RGB 0x8592 +#define GL_OPERAND0_ALPHA 0x8598 +#define GL_OPERAND1_ALPHA 0x8599 +#define GL_OPERAND2_ALPHA 0x859A +#define GL_RGB_SCALE 0x8573 +#define GL_ADD_SIGNED 0x8574 +#define GL_INTERPOLATE 0x8575 +#define GL_SUBTRACT 0x84E7 +#define GL_CONSTANT 0x8576 +#define GL_PRIMARY_COLOR 0x8577 +#define GL_PREVIOUS 0x8578 +/* texture_env_dot3 */ +#define GL_DOT3_RGB 0x86AE +#define GL_DOT3_RGBA 0x86AF +/* texture_border_clamp */ +#define GL_CLAMP_TO_BORDER 0x812D + +GLAPI void GLAPIENTRY glActiveTexture( GLenum texture ); + +GLAPI void GLAPIENTRY glClientActiveTexture( GLenum texture ); + +GLAPI void GLAPIENTRY glCompressedTexImage1D( GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const GLvoid *data ); + +GLAPI void GLAPIENTRY glCompressedTexImage2D( GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data ); + +GLAPI void GLAPIENTRY glCompressedTexImage3D( GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid *data ); + +GLAPI void GLAPIENTRY glCompressedTexSubImage1D( GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const GLvoid *data ); + +GLAPI void GLAPIENTRY glCompressedTexSubImage2D( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *data ); + +GLAPI void GLAPIENTRY glCompressedTexSubImage3D( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid *data ); + +GLAPI void GLAPIENTRY glGetCompressedTexImage( GLenum target, GLint lod, GLvoid *img ); + +GLAPI void GLAPIENTRY glMultiTexCoord1d( GLenum target, GLdouble s ); + +GLAPI void GLAPIENTRY glMultiTexCoord1dv( GLenum target, const GLdouble *v ); + +GLAPI void GLAPIENTRY glMultiTexCoord1f( GLenum target, GLfloat s ); + +GLAPI void GLAPIENTRY glMultiTexCoord1fv( GLenum target, const GLfloat *v ); + +GLAPI void GLAPIENTRY glMultiTexCoord1i( GLenum target, GLint s ); + +GLAPI void GLAPIENTRY glMultiTexCoord1iv( GLenum target, const GLint *v ); + +GLAPI void GLAPIENTRY glMultiTexCoord1s( GLenum target, GLshort s ); + +GLAPI void GLAPIENTRY glMultiTexCoord1sv( GLenum target, const GLshort *v ); + +GLAPI void GLAPIENTRY glMultiTexCoord2d( GLenum target, GLdouble s, GLdouble t ); + +GLAPI void GLAPIENTRY glMultiTexCoord2dv( GLenum target, const GLdouble *v ); + +GLAPI void GLAPIENTRY glMultiTexCoord2f( GLenum target, GLfloat s, GLfloat t ); + +GLAPI void GLAPIENTRY glMultiTexCoord2fv( GLenum target, const GLfloat *v ); + +GLAPI void GLAPIENTRY glMultiTexCoord2i( GLenum target, GLint s, GLint t ); + +GLAPI void GLAPIENTRY glMultiTexCoord2iv( GLenum target, const GLint *v ); + +GLAPI void GLAPIENTRY glMultiTexCoord2s( GLenum target, GLshort s, GLshort t ); + +GLAPI void GLAPIENTRY glMultiTexCoord2sv( GLenum target, const GLshort *v ); + +GLAPI void GLAPIENTRY glMultiTexCoord3d( GLenum target, GLdouble s, GLdouble t, GLdouble r ); + +GLAPI void GLAPIENTRY glMultiTexCoord3dv( GLenum target, const GLdouble *v ); + +GLAPI void GLAPIENTRY glMultiTexCoord3f( GLenum target, GLfloat s, GLfloat t, GLfloat r ); + +GLAPI void GLAPIENTRY glMultiTexCoord3fv( GLenum target, const GLfloat *v ); + +GLAPI void GLAPIENTRY glMultiTexCoord3i( GLenum target, GLint s, GLint t, GLint r ); + +GLAPI void GLAPIENTRY glMultiTexCoord3iv( GLenum target, const GLint *v ); + +GLAPI void GLAPIENTRY glMultiTexCoord3s( GLenum target, GLshort s, GLshort t, GLshort r ); + +GLAPI void GLAPIENTRY glMultiTexCoord3sv( GLenum target, const GLshort *v ); + +GLAPI void GLAPIENTRY glMultiTexCoord4d( GLenum target, GLdouble s, GLdouble t, GLdouble r, GLdouble q ); + +GLAPI void GLAPIENTRY glMultiTexCoord4dv( GLenum target, const GLdouble *v ); + +GLAPI void GLAPIENTRY glMultiTexCoord4f( GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q ); + +GLAPI void GLAPIENTRY glMultiTexCoord4fv( GLenum target, const GLfloat *v ); + +GLAPI void GLAPIENTRY glMultiTexCoord4i( GLenum target, GLint s, GLint t, GLint r, GLint q ); + +GLAPI void GLAPIENTRY glMultiTexCoord4iv( GLenum target, const GLint *v ); + +GLAPI void GLAPIENTRY glMultiTexCoord4s( GLenum target, GLshort s, GLshort t, GLshort r, GLshort q ); + +GLAPI void GLAPIENTRY glMultiTexCoord4sv( GLenum target, const GLshort *v ); + + +GLAPI void GLAPIENTRY glLoadTransposeMatrixd( const GLdouble m[16] ); + +GLAPI void GLAPIENTRY glLoadTransposeMatrixf( const GLfloat m[16] ); + +GLAPI void GLAPIENTRY glMultTransposeMatrixd( const GLdouble m[16] ); + +GLAPI void GLAPIENTRY glMultTransposeMatrixf( const GLfloat m[16] ); + +GLAPI void GLAPIENTRY glSampleCoverage( GLclampf value, GLboolean invert ); + + +typedef void (APIENTRYP PFNGLACTIVETEXTUREPROC) (GLenum texture); +typedef void (APIENTRYP PFNGLSAMPLECOVERAGEPROC) (GLclampf value, GLboolean invert); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE3DPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE2DPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE1DPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE3DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE2DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE1DPROC) (GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLGETCOMPRESSEDTEXIMAGEPROC) (GLenum target, GLint level, GLvoid *img); + + + +/* + * GL_ARB_multitexture (ARB extension 1 and OpenGL 1.2.1) + */ +#ifndef GL_ARB_multitexture +#define GL_ARB_multitexture 1 + +#define GL_TEXTURE0_ARB 0x84C0 +#define GL_TEXTURE1_ARB 0x84C1 +#define GL_TEXTURE2_ARB 0x84C2 +#define GL_TEXTURE3_ARB 0x84C3 +#define GL_TEXTURE4_ARB 0x84C4 +#define GL_TEXTURE5_ARB 0x84C5 +#define GL_TEXTURE6_ARB 0x84C6 +#define GL_TEXTURE7_ARB 0x84C7 +#define GL_TEXTURE8_ARB 0x84C8 +#define GL_TEXTURE9_ARB 0x84C9 +#define GL_TEXTURE10_ARB 0x84CA +#define GL_TEXTURE11_ARB 0x84CB +#define GL_TEXTURE12_ARB 0x84CC +#define GL_TEXTURE13_ARB 0x84CD +#define GL_TEXTURE14_ARB 0x84CE +#define GL_TEXTURE15_ARB 0x84CF +#define GL_TEXTURE16_ARB 0x84D0 +#define GL_TEXTURE17_ARB 0x84D1 +#define GL_TEXTURE18_ARB 0x84D2 +#define GL_TEXTURE19_ARB 0x84D3 +#define GL_TEXTURE20_ARB 0x84D4 +#define GL_TEXTURE21_ARB 0x84D5 +#define GL_TEXTURE22_ARB 0x84D6 +#define GL_TEXTURE23_ARB 0x84D7 +#define GL_TEXTURE24_ARB 0x84D8 +#define GL_TEXTURE25_ARB 0x84D9 +#define GL_TEXTURE26_ARB 0x84DA +#define GL_TEXTURE27_ARB 0x84DB +#define GL_TEXTURE28_ARB 0x84DC +#define GL_TEXTURE29_ARB 0x84DD +#define GL_TEXTURE30_ARB 0x84DE +#define GL_TEXTURE31_ARB 0x84DF +#define GL_ACTIVE_TEXTURE_ARB 0x84E0 +#define GL_CLIENT_ACTIVE_TEXTURE_ARB 0x84E1 +#define GL_MAX_TEXTURE_UNITS_ARB 0x84E2 + +GLAPI void GLAPIENTRY glActiveTextureARB(GLenum texture); +GLAPI void GLAPIENTRY glClientActiveTextureARB(GLenum texture); +GLAPI void GLAPIENTRY glMultiTexCoord1dARB(GLenum target, GLdouble s); +GLAPI void GLAPIENTRY glMultiTexCoord1dvARB(GLenum target, const GLdouble *v); +GLAPI void GLAPIENTRY glMultiTexCoord1fARB(GLenum target, GLfloat s); +GLAPI void GLAPIENTRY glMultiTexCoord1fvARB(GLenum target, const GLfloat *v); +GLAPI void GLAPIENTRY glMultiTexCoord1iARB(GLenum target, GLint s); +GLAPI void GLAPIENTRY glMultiTexCoord1ivARB(GLenum target, const GLint *v); +GLAPI void GLAPIENTRY glMultiTexCoord1sARB(GLenum target, GLshort s); +GLAPI void GLAPIENTRY glMultiTexCoord1svARB(GLenum target, const GLshort *v); +GLAPI void GLAPIENTRY glMultiTexCoord2dARB(GLenum target, GLdouble s, GLdouble t); +GLAPI void GLAPIENTRY glMultiTexCoord2dvARB(GLenum target, const GLdouble *v); +GLAPI void GLAPIENTRY glMultiTexCoord2fARB(GLenum target, GLfloat s, GLfloat t); +GLAPI void GLAPIENTRY glMultiTexCoord2fvARB(GLenum target, const GLfloat *v); +GLAPI void GLAPIENTRY glMultiTexCoord2iARB(GLenum target, GLint s, GLint t); +GLAPI void GLAPIENTRY glMultiTexCoord2ivARB(GLenum target, const GLint *v); +GLAPI void GLAPIENTRY glMultiTexCoord2sARB(GLenum target, GLshort s, GLshort t); +GLAPI void GLAPIENTRY glMultiTexCoord2svARB(GLenum target, const GLshort *v); +GLAPI void GLAPIENTRY glMultiTexCoord3dARB(GLenum target, GLdouble s, GLdouble t, GLdouble r); +GLAPI void GLAPIENTRY glMultiTexCoord3dvARB(GLenum target, const GLdouble *v); +GLAPI void GLAPIENTRY glMultiTexCoord3fARB(GLenum target, GLfloat s, GLfloat t, GLfloat r); +GLAPI void GLAPIENTRY glMultiTexCoord3fvARB(GLenum target, const GLfloat *v); +GLAPI void GLAPIENTRY glMultiTexCoord3iARB(GLenum target, GLint s, GLint t, GLint r); +GLAPI void GLAPIENTRY glMultiTexCoord3ivARB(GLenum target, const GLint *v); +GLAPI void GLAPIENTRY glMultiTexCoord3sARB(GLenum target, GLshort s, GLshort t, GLshort r); +GLAPI void GLAPIENTRY glMultiTexCoord3svARB(GLenum target, const GLshort *v); +GLAPI void GLAPIENTRY glMultiTexCoord4dARB(GLenum target, GLdouble s, GLdouble t, GLdouble r, GLdouble q); +GLAPI void GLAPIENTRY glMultiTexCoord4dvARB(GLenum target, const GLdouble *v); +GLAPI void GLAPIENTRY glMultiTexCoord4fARB(GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q); +GLAPI void GLAPIENTRY glMultiTexCoord4fvARB(GLenum target, const GLfloat *v); +GLAPI void GLAPIENTRY glMultiTexCoord4iARB(GLenum target, GLint s, GLint t, GLint r, GLint q); +GLAPI void GLAPIENTRY glMultiTexCoord4ivARB(GLenum target, const GLint *v); +GLAPI void GLAPIENTRY glMultiTexCoord4sARB(GLenum target, GLshort s, GLshort t, GLshort r, GLshort q); +GLAPI void GLAPIENTRY glMultiTexCoord4svARB(GLenum target, const GLshort *v); + +typedef void (APIENTRYP PFNGLACTIVETEXTUREARBPROC) (GLenum texture); +typedef void (APIENTRYP PFNGLCLIENTACTIVETEXTUREARBPROC) (GLenum texture); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1DARBPROC) (GLenum target, GLdouble s); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1DVARBPROC) (GLenum target, const GLdouble *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1FARBPROC) (GLenum target, GLfloat s); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1FVARBPROC) (GLenum target, const GLfloat *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1IARBPROC) (GLenum target, GLint s); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1IVARBPROC) (GLenum target, const GLint *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1SARBPROC) (GLenum target, GLshort s); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1SVARBPROC) (GLenum target, const GLshort *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2DARBPROC) (GLenum target, GLdouble s, GLdouble t); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2DVARBPROC) (GLenum target, const GLdouble *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2FARBPROC) (GLenum target, GLfloat s, GLfloat t); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2FVARBPROC) (GLenum target, const GLfloat *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2IARBPROC) (GLenum target, GLint s, GLint t); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2IVARBPROC) (GLenum target, const GLint *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2SARBPROC) (GLenum target, GLshort s, GLshort t); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2SVARBPROC) (GLenum target, const GLshort *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3DARBPROC) (GLenum target, GLdouble s, GLdouble t, GLdouble r); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3DVARBPROC) (GLenum target, const GLdouble *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3FARBPROC) (GLenum target, GLfloat s, GLfloat t, GLfloat r); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3FVARBPROC) (GLenum target, const GLfloat *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3IARBPROC) (GLenum target, GLint s, GLint t, GLint r); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3IVARBPROC) (GLenum target, const GLint *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3SARBPROC) (GLenum target, GLshort s, GLshort t, GLshort r); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3SVARBPROC) (GLenum target, const GLshort *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4DARBPROC) (GLenum target, GLdouble s, GLdouble t, GLdouble r, GLdouble q); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4DVARBPROC) (GLenum target, const GLdouble *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4FARBPROC) (GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4FVARBPROC) (GLenum target, const GLfloat *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4IARBPROC) (GLenum target, GLint s, GLint t, GLint r, GLint q); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4IVARBPROC) (GLenum target, const GLint *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4SARBPROC) (GLenum target, GLshort s, GLshort t, GLshort r, GLshort q); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4SVARBPROC) (GLenum target, const GLshort *v); + +#endif /* GL_ARB_multitexture */ + + + +/* + * Define this token if you want "old-style" header file behaviour (extensions + * defined in gl.h). Otherwise, extensions will be included from glext.h. + */ +#if defined(GL_GLEXT_LEGACY) + +/* All extensions that used to be here are now found in glext.h */ + +#else /* GL_GLEXT_LEGACY */ + +#include + +#endif /* GL_GLEXT_LEGACY */ + + + +#if GL_ARB_shader_objects + +#ifndef GL_MESA_shader_debug +#define GL_MESA_shader_debug 1 + +#define GL_DEBUG_OBJECT_MESA 0x8759 +#define GL_DEBUG_PRINT_MESA 0x875A +#define GL_DEBUG_ASSERT_MESA 0x875B + +GLAPI GLhandleARB GLAPIENTRY glCreateDebugObjectMESA (void); +GLAPI void GLAPIENTRY glClearDebugLogMESA (GLhandleARB obj, GLenum logType, GLenum shaderType); +GLAPI void GLAPIENTRY glGetDebugLogMESA (GLhandleARB obj, GLenum logType, GLenum shaderType, GLsizei maxLength, + GLsizei *length, GLcharARB *debugLog); +GLAPI GLsizei GLAPIENTRY glGetDebugLogLengthMESA (GLhandleARB obj, GLenum logType, GLenum shaderType); + +#endif /* GL_MESA_shader_debug */ + +#endif /* GL_ARB_shader_objects */ + + +/* + * ???. GL_MESA_packed_depth_stencil + * XXX obsolete + */ +#ifndef GL_MESA_packed_depth_stencil +#define GL_MESA_packed_depth_stencil 1 + +#define GL_DEPTH_STENCIL_MESA 0x8750 +#define GL_UNSIGNED_INT_24_8_MESA 0x8751 +#define GL_UNSIGNED_INT_8_24_REV_MESA 0x8752 +#define GL_UNSIGNED_SHORT_15_1_MESA 0x8753 +#define GL_UNSIGNED_SHORT_1_15_REV_MESA 0x8754 + +#endif /* GL_MESA_packed_depth_stencil */ + + +#ifndef GL_MESA_program_debug +#define GL_MESA_program_debug 1 + +#define GL_FRAGMENT_PROGRAM_POSITION_MESA 0x8bb0 +#define GL_FRAGMENT_PROGRAM_CALLBACK_MESA 0x8bb1 +#define GL_FRAGMENT_PROGRAM_CALLBACK_FUNC_MESA 0x8bb2 +#define GL_FRAGMENT_PROGRAM_CALLBACK_DATA_MESA 0x8bb3 +#define GL_VERTEX_PROGRAM_POSITION_MESA 0x8bb4 +#define GL_VERTEX_PROGRAM_CALLBACK_MESA 0x8bb5 +#define GL_VERTEX_PROGRAM_CALLBACK_FUNC_MESA 0x8bb6 +#define GL_VERTEX_PROGRAM_CALLBACK_DATA_MESA 0x8bb7 + +typedef void (*GLprogramcallbackMESA)(GLenum target, GLvoid *data); + +GLAPI void GLAPIENTRY glProgramCallbackMESA(GLenum target, GLprogramcallbackMESA callback, GLvoid *data); + +GLAPI void GLAPIENTRY glGetProgramRegisterfvMESA(GLenum target, GLsizei len, const GLubyte *name, GLfloat *v); + +#endif /* GL_MESA_program_debug */ + + +#ifndef GL_MESA_texture_array +#define GL_MESA_texture_array 1 + +/* GL_MESA_texture_array uses the same enum values as GL_EXT_texture_array. + */ +#ifndef GL_EXT_texture_array + +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glFramebufferTextureLayerEXT(GLenum target, + GLenum attachment, GLuint texture, GLint level, GLint layer); +#endif /* GL_GLEXT_PROTOTYPES */ + +#if 0 +/* (temporarily) disabled because of collision with typedef in glext.h + * that happens if apps include both gl.h and glext.h + */ +typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURELAYEREXTPROC) (GLenum target, + GLenum attachment, GLuint texture, GLint level, GLint layer); +#endif + +#define GL_TEXTURE_1D_ARRAY_EXT 0x8C18 +#define GL_PROXY_TEXTURE_1D_ARRAY_EXT 0x8C19 +#define GL_TEXTURE_2D_ARRAY_EXT 0x8C1A +#define GL_PROXY_TEXTURE_2D_ARRAY_EXT 0x8C1B +#define GL_TEXTURE_BINDING_1D_ARRAY_EXT 0x8C1C +#define GL_TEXTURE_BINDING_2D_ARRAY_EXT 0x8C1D +#define GL_MAX_ARRAY_TEXTURE_LAYERS_EXT 0x88FF +#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER_EXT 0x8CD4 +#endif + +#endif + + +#ifndef GL_ATI_blend_equation_separate +#define GL_ATI_blend_equation_separate 1 + +#define GL_ALPHA_BLEND_EQUATION_ATI 0x883D + +GLAPI void GLAPIENTRY glBlendEquationSeparateATI( GLenum modeRGB, GLenum modeA ); +typedef void (APIENTRYP PFNGLBLENDEQUATIONSEPARATEATIPROC) (GLenum modeRGB, GLenum modeA); + +#endif /* GL_ATI_blend_equation_separate */ + + +/* GL_OES_EGL_image */ +#ifndef GL_OES_EGL_image +typedef void* GLeglImageOES; +#endif + +#ifndef GL_OES_EGL_image +#define GL_OES_EGL_image 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glEGLImageTargetTexture2DOES (GLenum target, GLeglImageOES image); +GLAPI void APIENTRY glEGLImageTargetRenderbufferStorageOES (GLenum target, GLeglImageOES image); +#endif +typedef void (APIENTRYP PFNGLEGLIMAGETARGETTEXTURE2DOESPROC) (GLenum target, GLeglImageOES image); +typedef void (APIENTRYP PFNGLEGLIMAGETARGETRENDERBUFFERSTORAGEOESPROC) (GLenum target, GLeglImageOES image); +#endif + + +/** + ** NOTE!!!!! If you add new functions to this file, or update + ** glext.h be sure to regenerate the gl_mangle.h file. See comments + ** in that file for details. + **/ + + + +/********************************************************************** + * Begin system-specific stuff + */ +#if defined(PRAGMA_EXPORT_SUPPORTED) +#pragma export off +#endif + +#if defined(macintosh) && PRAGMA_IMPORT_SUPPORTED +#pragma import off +#endif +/* + * End system-specific stuff + **********************************************************************/ + + +#ifdef __cplusplus +} +#endif + +#endif /* __gl_h_ */ diff --git a/Projects/Android/jni/SupportLibs/gl4es/include/GL/gl_mangle.h b/Projects/Android/jni/SupportLibs/gl4es/include/GL/gl_mangle.h new file mode 100644 index 0000000..43d2e89 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/include/GL/gl_mangle.h @@ -0,0 +1,1985 @@ +#if 0 +#define GL_MANGLE_C1 "DO NOT EDIT!!! - TO REGENERATE from gl.h, EXECUTE THIS FILE IN SHELL (/bin/sh) and save the output" +#define GL_MANGLE_C2 "This file is used to create GL function protypes and aliases for the function names" + files="gl.h glext.h" +#define GL_MANGLE_C3 "get regeneration header - copy everything in this file above the 'REGENERATE_TO_END' line" + awk '!done; /^\/\*REGENERATE_TO_END/ {done=1}' $0 + echo "" +#define GL_MANGLE_C4 get aliases + grep '^GLAPI' $files | sed -e 's/.*ENTRY gl\([^( ]*\).*$/#define gl\1 MANGLE(\1)/' | sort | uniq + echo "" + echo "#endif /* GL_MANGLE_H */" + exit +#endif /* REGENERATION */ + +/* + * If you compile Mesa with USE_MGL_NAMESPACE defined then you can link + * your application both with OpenGL and Mesa. The Mesa functions will + * be redefined so they are prefixed with "mgl" instead of "gl". + * Mgl contributed by Randy Frank (rfrank@rsinc.com) + * Regneration code contributed by Ray Tice (rayt@ma.ultra.net) + */ + +#ifndef GL_MANGLE_H +#define GL_MANGLE_H + +#ifndef MANGLE +#define MANGLE(x) mgl##x +#endif /*MANGLE*/ + +/*REGENERATE_TO_END-----------ALL LINES BELOW HERE GET REPLACED ON REGENERATION */ + +#define glAccum MANGLE(Accum) +#define glActiveProgramEXT MANGLE(ActiveProgramEXT) +#define glActiveStencilFaceEXT MANGLE(ActiveStencilFaceEXT) +#define glActiveTextureARB MANGLE(ActiveTextureARB) +#define glActiveTexture MANGLE(ActiveTexture) +#define glActiveVaryingNV MANGLE(ActiveVaryingNV) +#define glAlphaFragmentOp1ATI MANGLE(AlphaFragmentOp1ATI) +#define glAlphaFragmentOp2ATI MANGLE(AlphaFragmentOp2ATI) +#define glAlphaFragmentOp3ATI MANGLE(AlphaFragmentOp3ATI) +#define glAlphaFunc MANGLE(AlphaFunc) +#define glApplyTextureEXT MANGLE(ApplyTextureEXT) +#define glAreProgramsResidentNV MANGLE(AreProgramsResidentNV) +#define glAreTexturesResidentEXT MANGLE(AreTexturesResidentEXT) +#define glAreTexturesResident MANGLE(AreTexturesResident) +#define glArrayElementEXT MANGLE(ArrayElementEXT) +#define glArrayElement MANGLE(ArrayElement) +#define glArrayObjectATI MANGLE(ArrayObjectATI) +#define glAsyncMarkerSGIX MANGLE(AsyncMarkerSGIX) +#define glAttachObjectARB MANGLE(AttachObjectARB) +#define glAttachShader MANGLE(AttachShader) +#define glBeginConditionalRender MANGLE(BeginConditionalRender) +#define glBeginConditionalRenderNV MANGLE(BeginConditionalRenderNV) +#define glBeginFragmentShaderATI MANGLE(BeginFragmentShaderATI) +#define glBegin MANGLE(Begin) +#define glBeginOcclusionQueryNV MANGLE(BeginOcclusionQueryNV) +#define glBeginPerfMonitorAMD MANGLE(BeginPerfMonitorAMD) +#define glBeginQueryARB MANGLE(BeginQueryARB) +#define glBeginQuery MANGLE(BeginQuery) +#define glBeginTransformFeedbackEXT MANGLE(BeginTransformFeedbackEXT) +#define glBeginTransformFeedback MANGLE(BeginTransformFeedback) +#define glBeginTransformFeedbackNV MANGLE(BeginTransformFeedbackNV) +#define glBeginVertexShaderEXT MANGLE(BeginVertexShaderEXT) +#define glBeginVideoCaptureNV MANGLE(BeginVideoCaptureNV) +#define glBindAttribLocationARB MANGLE(BindAttribLocationARB) +#define glBindAttribLocation MANGLE(BindAttribLocation) +#define glBindBufferARB MANGLE(BindBufferARB) +#define glBindBufferBaseEXT MANGLE(BindBufferBaseEXT) +#define glBindBufferBase MANGLE(BindBufferBase) +#define glBindBufferBaseNV MANGLE(BindBufferBaseNV) +#define glBindBuffer MANGLE(BindBuffer) +#define glBindBufferOffsetEXT MANGLE(BindBufferOffsetEXT) +#define glBindBufferOffsetNV MANGLE(BindBufferOffsetNV) +#define glBindBufferRangeEXT MANGLE(BindBufferRangeEXT) +#define glBindBufferRange MANGLE(BindBufferRange) +#define glBindBufferRangeNV MANGLE(BindBufferRangeNV) +#define glBindFragDataLocationEXT MANGLE(BindFragDataLocationEXT) +#define glBindFragDataLocation MANGLE(BindFragDataLocation) +#define glBindFragmentShaderATI MANGLE(BindFragmentShaderATI) +#define glBindFramebufferEXT MANGLE(BindFramebufferEXT) +#define glBindFramebuffer MANGLE(BindFramebuffer) +#define glBindLightParameterEXT MANGLE(BindLightParameterEXT) +#define glBindMaterialParameterEXT MANGLE(BindMaterialParameterEXT) +#define glBindMultiTextureEXT MANGLE(BindMultiTextureEXT) +#define glBindParameterEXT MANGLE(BindParameterEXT) +#define glBindProgramARB MANGLE(BindProgramARB) +#define glBindProgramNV MANGLE(BindProgramNV) +#define glBindRenderbufferEXT MANGLE(BindRenderbufferEXT) +#define glBindRenderbuffer MANGLE(BindRenderbuffer) +#define glBindTexGenParameterEXT MANGLE(BindTexGenParameterEXT) +#define glBindTextureEXT MANGLE(BindTextureEXT) +#define glBindTexture MANGLE(BindTexture) +#define glBindTextureUnitParameterEXT MANGLE(BindTextureUnitParameterEXT) +#define glBindTransformFeedbackNV MANGLE(BindTransformFeedbackNV) +#define glBindVertexArrayAPPLE MANGLE(BindVertexArrayAPPLE) +#define glBindVertexArray MANGLE(BindVertexArray) +#define glBindVertexShaderEXT MANGLE(BindVertexShaderEXT) +#define glBindVideoCaptureStreamBufferNV MANGLE(BindVideoCaptureStreamBufferNV) +#define glBindVideoCaptureStreamTextureNV MANGLE(BindVideoCaptureStreamTextureNV) +#define glBinormal3bEXT MANGLE(Binormal3bEXT) +#define glBinormal3bvEXT MANGLE(Binormal3bvEXT) +#define glBinormal3dEXT MANGLE(Binormal3dEXT) +#define glBinormal3dvEXT MANGLE(Binormal3dvEXT) +#define glBinormal3fEXT MANGLE(Binormal3fEXT) +#define glBinormal3fvEXT MANGLE(Binormal3fvEXT) +#define glBinormal3iEXT MANGLE(Binormal3iEXT) +#define glBinormal3ivEXT MANGLE(Binormal3ivEXT) +#define glBinormal3sEXT MANGLE(Binormal3sEXT) +#define glBinormal3svEXT MANGLE(Binormal3svEXT) +#define glBinormalPointerEXT MANGLE(BinormalPointerEXT) +#define glBitmap MANGLE(Bitmap) +#define glBlendColorEXT MANGLE(BlendColorEXT) +#define glBlendColor MANGLE(BlendColor) +#define glBlendEquationEXT MANGLE(BlendEquationEXT) +#define glBlendEquationi MANGLE(BlendEquationi) +#define glBlendEquationIndexedAMD MANGLE(BlendEquationIndexedAMD) +#define glBlendEquation MANGLE(BlendEquation) +#define glBlendEquationSeparateATI MANGLE(BlendEquationSeparateATI) +#define glBlendEquationSeparateEXT MANGLE(BlendEquationSeparateEXT) +#define glBlendEquationSeparatei MANGLE(BlendEquationSeparatei) +#define glBlendEquationSeparateIndexedAMD MANGLE(BlendEquationSeparateIndexedAMD) +#define glBlendEquationSeparate MANGLE(BlendEquationSeparate) +#define glBlendFunci MANGLE(BlendFunci) +#define glBlendFuncIndexedAMD MANGLE(BlendFuncIndexedAMD) +#define glBlendFunc MANGLE(BlendFunc) +#define glBlendFuncSeparateEXT MANGLE(BlendFuncSeparateEXT) +#define glBlendFuncSeparatei MANGLE(BlendFuncSeparatei) +#define glBlendFuncSeparateIndexedAMD MANGLE(BlendFuncSeparateIndexedAMD) +#define glBlendFuncSeparateINGR MANGLE(BlendFuncSeparateINGR) +#define glBlendFuncSeparate MANGLE(BlendFuncSeparate) +#define glBlitFramebufferEXT MANGLE(BlitFramebufferEXT) +#define glBlitFramebuffer MANGLE(BlitFramebuffer) +#define glBufferAddressRangeNV MANGLE(BufferAddressRangeNV) +#define glBufferDataARB MANGLE(BufferDataARB) +#define glBufferData MANGLE(BufferData) +#define glBufferParameteriAPPLE MANGLE(BufferParameteriAPPLE) +#define glBufferSubDataARB MANGLE(BufferSubDataARB) +#define glBufferSubData MANGLE(BufferSubData) +#define glCallList MANGLE(CallList) +#define glCallLists MANGLE(CallLists) +#define glCheckFramebufferStatusEXT MANGLE(CheckFramebufferStatusEXT) +#define glCheckFramebufferStatus MANGLE(CheckFramebufferStatus) +#define glCheckNamedFramebufferStatusEXT MANGLE(CheckNamedFramebufferStatusEXT) +#define glClampColorARB MANGLE(ClampColorARB) +#define glClampColor MANGLE(ClampColor) +#define glClearAccum MANGLE(ClearAccum) +#define glClearBufferfi MANGLE(ClearBufferfi) +#define glClearBufferfv MANGLE(ClearBufferfv) +#define glClearBufferiv MANGLE(ClearBufferiv) +#define glClearBufferuiv MANGLE(ClearBufferuiv) +#define glClearColorIiEXT MANGLE(ClearColorIiEXT) +#define glClearColorIuiEXT MANGLE(ClearColorIuiEXT) +#define glClearColor MANGLE(ClearColor) +#define glClearDebugLogMESA MANGLE(ClearDebugLogMESA) +#define glClearDepthdNV MANGLE(ClearDepthdNV) +#define glClearDepth MANGLE(ClearDepth) +#define glClearIndex MANGLE(ClearIndex) +#define glClear MANGLE(Clear) +#define glClearStencil MANGLE(ClearStencil) +#define glClientActiveTextureARB MANGLE(ClientActiveTextureARB) +#define glClientActiveTexture MANGLE(ClientActiveTexture) +#define glClientActiveVertexStreamATI MANGLE(ClientActiveVertexStreamATI) +#define glClientAttribDefaultEXT MANGLE(ClientAttribDefaultEXT) +#define glClientWaitSync MANGLE(ClientWaitSync) +#define glClipPlane MANGLE(ClipPlane) +#define glColor3b MANGLE(Color3b) +#define glColor3bv MANGLE(Color3bv) +#define glColor3d MANGLE(Color3d) +#define glColor3dv MANGLE(Color3dv) +#define glColor3f MANGLE(Color3f) +#define glColor3fVertex3fSUN MANGLE(Color3fVertex3fSUN) +#define glColor3fVertex3fvSUN MANGLE(Color3fVertex3fvSUN) +#define glColor3fv MANGLE(Color3fv) +#define glColor3hNV MANGLE(Color3hNV) +#define glColor3hvNV MANGLE(Color3hvNV) +#define glColor3i MANGLE(Color3i) +#define glColor3iv MANGLE(Color3iv) +#define glColor3s MANGLE(Color3s) +#define glColor3sv MANGLE(Color3sv) +#define glColor3ub MANGLE(Color3ub) +#define glColor3ubv MANGLE(Color3ubv) +#define glColor3ui MANGLE(Color3ui) +#define glColor3uiv MANGLE(Color3uiv) +#define glColor3us MANGLE(Color3us) +#define glColor3usv MANGLE(Color3usv) +#define glColor4b MANGLE(Color4b) +#define glColor4bv MANGLE(Color4bv) +#define glColor4d MANGLE(Color4d) +#define glColor4dv MANGLE(Color4dv) +#define glColor4f MANGLE(Color4f) +#define glColor4fNormal3fVertex3fSUN MANGLE(Color4fNormal3fVertex3fSUN) +#define glColor4fNormal3fVertex3fvSUN MANGLE(Color4fNormal3fVertex3fvSUN) +#define glColor4fv MANGLE(Color4fv) +#define glColor4hNV MANGLE(Color4hNV) +#define glColor4hvNV MANGLE(Color4hvNV) +#define glColor4i MANGLE(Color4i) +#define glColor4iv MANGLE(Color4iv) +#define glColor4s MANGLE(Color4s) +#define glColor4sv MANGLE(Color4sv) +#define glColor4ub MANGLE(Color4ub) +#define glColor4ubVertex2fSUN MANGLE(Color4ubVertex2fSUN) +#define glColor4ubVertex2fvSUN MANGLE(Color4ubVertex2fvSUN) +#define glColor4ubVertex3fSUN MANGLE(Color4ubVertex3fSUN) +#define glColor4ubVertex3fvSUN MANGLE(Color4ubVertex3fvSUN) +#define glColor4ubv MANGLE(Color4ubv) +#define glColor4ui MANGLE(Color4ui) +#define glColor4uiv MANGLE(Color4uiv) +#define glColor4us MANGLE(Color4us) +#define glColor4usv MANGLE(Color4usv) +#define glColorFormatNV MANGLE(ColorFormatNV) +#define glColorFragmentOp1ATI MANGLE(ColorFragmentOp1ATI) +#define glColorFragmentOp2ATI MANGLE(ColorFragmentOp2ATI) +#define glColorFragmentOp3ATI MANGLE(ColorFragmentOp3ATI) +#define glColorMaski MANGLE(ColorMaski) +#define glColorMaskIndexedEXT MANGLE(ColorMaskIndexedEXT) +#define glColorMask MANGLE(ColorMask) +#define glColorMaterial MANGLE(ColorMaterial) +#define glColorPointerEXT MANGLE(ColorPointerEXT) +#define glColorPointerListIBM MANGLE(ColorPointerListIBM) +#define glColorPointer MANGLE(ColorPointer) +#define glColorPointervINTEL MANGLE(ColorPointervINTEL) +#define glColorSubTableEXT MANGLE(ColorSubTableEXT) +#define glColorSubTable MANGLE(ColorSubTable) +#define glColorTableEXT MANGLE(ColorTableEXT) +#define glColorTable MANGLE(ColorTable) +#define glColorTableParameterfv MANGLE(ColorTableParameterfv) +#define glColorTableParameterfvSGI MANGLE(ColorTableParameterfvSGI) +#define glColorTableParameteriv MANGLE(ColorTableParameteriv) +#define glColorTableParameterivSGI MANGLE(ColorTableParameterivSGI) +#define glColorTableSGI MANGLE(ColorTableSGI) +#define glCombinerInputNV MANGLE(CombinerInputNV) +#define glCombinerOutputNV MANGLE(CombinerOutputNV) +#define glCombinerParameterfNV MANGLE(CombinerParameterfNV) +#define glCombinerParameterfvNV MANGLE(CombinerParameterfvNV) +#define glCombinerParameteriNV MANGLE(CombinerParameteriNV) +#define glCombinerParameterivNV MANGLE(CombinerParameterivNV) +#define glCombinerStageParameterfvNV MANGLE(CombinerStageParameterfvNV) +#define glCompileShaderARB MANGLE(CompileShaderARB) +#define glCompileShader MANGLE(CompileShader) +#define glCompressedMultiTexImage1DEXT MANGLE(CompressedMultiTexImage1DEXT) +#define glCompressedMultiTexImage2DEXT MANGLE(CompressedMultiTexImage2DEXT) +#define glCompressedMultiTexImage3DEXT MANGLE(CompressedMultiTexImage3DEXT) +#define glCompressedMultiTexSubImage1DEXT MANGLE(CompressedMultiTexSubImage1DEXT) +#define glCompressedMultiTexSubImage2DEXT MANGLE(CompressedMultiTexSubImage2DEXT) +#define glCompressedMultiTexSubImage3DEXT MANGLE(CompressedMultiTexSubImage3DEXT) +#define glCompressedTexImage1DARB MANGLE(CompressedTexImage1DARB) +#define glCompressedTexImage1D MANGLE(CompressedTexImage1D) +#define glCompressedTexImage2DARB MANGLE(CompressedTexImage2DARB) +#define glCompressedTexImage2D MANGLE(CompressedTexImage2D) +#define glCompressedTexImage3DARB MANGLE(CompressedTexImage3DARB) +#define glCompressedTexImage3D MANGLE(CompressedTexImage3D) +#define glCompressedTexSubImage1DARB MANGLE(CompressedTexSubImage1DARB) +#define glCompressedTexSubImage1D MANGLE(CompressedTexSubImage1D) +#define glCompressedTexSubImage2DARB MANGLE(CompressedTexSubImage2DARB) +#define glCompressedTexSubImage2D MANGLE(CompressedTexSubImage2D) +#define glCompressedTexSubImage3DARB MANGLE(CompressedTexSubImage3DARB) +#define glCompressedTexSubImage3D MANGLE(CompressedTexSubImage3D) +#define glCompressedTextureImage1DEXT MANGLE(CompressedTextureImage1DEXT) +#define glCompressedTextureImage2DEXT MANGLE(CompressedTextureImage2DEXT) +#define glCompressedTextureImage3DEXT MANGLE(CompressedTextureImage3DEXT) +#define glCompressedTextureSubImage1DEXT MANGLE(CompressedTextureSubImage1DEXT) +#define glCompressedTextureSubImage2DEXT MANGLE(CompressedTextureSubImage2DEXT) +#define glCompressedTextureSubImage3DEXT MANGLE(CompressedTextureSubImage3DEXT) +#define glConvolutionFilter1DEXT MANGLE(ConvolutionFilter1DEXT) +#define glConvolutionFilter1D MANGLE(ConvolutionFilter1D) +#define glConvolutionFilter2DEXT MANGLE(ConvolutionFilter2DEXT) +#define glConvolutionFilter2D MANGLE(ConvolutionFilter2D) +#define glConvolutionParameterfEXT MANGLE(ConvolutionParameterfEXT) +#define glConvolutionParameterf MANGLE(ConvolutionParameterf) +#define glConvolutionParameterfvEXT MANGLE(ConvolutionParameterfvEXT) +#define glConvolutionParameterfv MANGLE(ConvolutionParameterfv) +#define glConvolutionParameteriEXT MANGLE(ConvolutionParameteriEXT) +#define glConvolutionParameteri MANGLE(ConvolutionParameteri) +#define glConvolutionParameterivEXT MANGLE(ConvolutionParameterivEXT) +#define glConvolutionParameteriv MANGLE(ConvolutionParameteriv) +#define glCopyBufferSubData MANGLE(CopyBufferSubData) +#define glCopyColorSubTableEXT MANGLE(CopyColorSubTableEXT) +#define glCopyColorSubTable MANGLE(CopyColorSubTable) +#define glCopyColorTable MANGLE(CopyColorTable) +#define glCopyColorTableSGI MANGLE(CopyColorTableSGI) +#define glCopyConvolutionFilter1DEXT MANGLE(CopyConvolutionFilter1DEXT) +#define glCopyConvolutionFilter1D MANGLE(CopyConvolutionFilter1D) +#define glCopyConvolutionFilter2DEXT MANGLE(CopyConvolutionFilter2DEXT) +#define glCopyConvolutionFilter2D MANGLE(CopyConvolutionFilter2D) +#define glCopyImageSubDataNV MANGLE(CopyImageSubDataNV) +#define glCopyMultiTexImage1DEXT MANGLE(CopyMultiTexImage1DEXT) +#define glCopyMultiTexImage2DEXT MANGLE(CopyMultiTexImage2DEXT) +#define glCopyMultiTexSubImage1DEXT MANGLE(CopyMultiTexSubImage1DEXT) +#define glCopyMultiTexSubImage2DEXT MANGLE(CopyMultiTexSubImage2DEXT) +#define glCopyMultiTexSubImage3DEXT MANGLE(CopyMultiTexSubImage3DEXT) +#define glCopyPixels MANGLE(CopyPixels) +#define glCopyTexImage1DEXT MANGLE(CopyTexImage1DEXT) +#define glCopyTexImage1D MANGLE(CopyTexImage1D) +#define glCopyTexImage2DEXT MANGLE(CopyTexImage2DEXT) +#define glCopyTexImage2D MANGLE(CopyTexImage2D) +#define glCopyTexSubImage1DEXT MANGLE(CopyTexSubImage1DEXT) +#define glCopyTexSubImage1D MANGLE(CopyTexSubImage1D) +#define glCopyTexSubImage2DEXT MANGLE(CopyTexSubImage2DEXT) +#define glCopyTexSubImage2D MANGLE(CopyTexSubImage2D) +#define glCopyTexSubImage3DEXT MANGLE(CopyTexSubImage3DEXT) +#define glCopyTexSubImage3D MANGLE(CopyTexSubImage3D) +#define glCopyTextureImage1DEXT MANGLE(CopyTextureImage1DEXT) +#define glCopyTextureImage2DEXT MANGLE(CopyTextureImage2DEXT) +#define glCopyTextureSubImage1DEXT MANGLE(CopyTextureSubImage1DEXT) +#define glCopyTextureSubImage2DEXT MANGLE(CopyTextureSubImage2DEXT) +#define glCopyTextureSubImage3DEXT MANGLE(CopyTextureSubImage3DEXT) +#define glCreateDebugObjectMESA MANGLE(CreateDebugObjectMESA) +#define glCreateProgram MANGLE(CreateProgram) +#define glCreateProgramObjectARB MANGLE(CreateProgramObjectARB) +#define glCreateShader MANGLE(CreateShader) +#define glCreateShaderObjectARB MANGLE(CreateShaderObjectARB) +#define glCreateShaderProgramEXT MANGLE(CreateShaderProgramEXT) +#define glCullFace MANGLE(CullFace) +#define glCullParameterdvEXT MANGLE(CullParameterdvEXT) +#define glCullParameterfvEXT MANGLE(CullParameterfvEXT) +#define glCurrentPaletteMatrixARB MANGLE(CurrentPaletteMatrixARB) +#define glDeformationMap3dSGIX MANGLE(DeformationMap3dSGIX) +#define glDeformationMap3fSGIX MANGLE(DeformationMap3fSGIX) +#define glDeformSGIX MANGLE(DeformSGIX) +#define glDeleteAsyncMarkersSGIX MANGLE(DeleteAsyncMarkersSGIX) +#define glDeleteBuffersARB MANGLE(DeleteBuffersARB) +#define glDeleteBuffers MANGLE(DeleteBuffers) +#define glDeleteFencesAPPLE MANGLE(DeleteFencesAPPLE) +#define glDeleteFencesNV MANGLE(DeleteFencesNV) +#define glDeleteFragmentShaderATI MANGLE(DeleteFragmentShaderATI) +#define glDeleteFramebuffersEXT MANGLE(DeleteFramebuffersEXT) +#define glDeleteFramebuffers MANGLE(DeleteFramebuffers) +#define glDeleteLists MANGLE(DeleteLists) +#define glDeleteObjectARB MANGLE(DeleteObjectARB) +#define glDeleteOcclusionQueriesNV MANGLE(DeleteOcclusionQueriesNV) +#define glDeletePerfMonitorsAMD MANGLE(DeletePerfMonitorsAMD) +#define glDeleteProgram MANGLE(DeleteProgram) +#define glDeleteProgramsARB MANGLE(DeleteProgramsARB) +#define glDeleteProgramsNV MANGLE(DeleteProgramsNV) +#define glDeleteQueriesARB MANGLE(DeleteQueriesARB) +#define glDeleteQueries MANGLE(DeleteQueries) +#define glDeleteRenderbuffersEXT MANGLE(DeleteRenderbuffersEXT) +#define glDeleteRenderbuffers MANGLE(DeleteRenderbuffers) +#define glDeleteShader MANGLE(DeleteShader) +#define glDeleteSync MANGLE(DeleteSync) +#define glDeleteTexturesEXT MANGLE(DeleteTexturesEXT) +#define glDeleteTextures MANGLE(DeleteTextures) +#define glDeleteTransformFeedbacksNV MANGLE(DeleteTransformFeedbacksNV) +#define glDeleteVertexArraysAPPLE MANGLE(DeleteVertexArraysAPPLE) +#define glDeleteVertexArrays MANGLE(DeleteVertexArrays) +#define glDeleteVertexShaderEXT MANGLE(DeleteVertexShaderEXT) +#define glDepthBoundsdNV MANGLE(DepthBoundsdNV) +#define glDepthBoundsEXT MANGLE(DepthBoundsEXT) +#define glDepthFunc MANGLE(DepthFunc) +#define glDepthMask MANGLE(DepthMask) +#define glDepthRangedNV MANGLE(DepthRangedNV) +#define glDepthRange MANGLE(DepthRange) +#define glDetachObjectARB MANGLE(DetachObjectARB) +#define glDetachShader MANGLE(DetachShader) +#define glDetailTexFuncSGIS MANGLE(DetailTexFuncSGIS) +#define glDisableClientStateIndexedEXT MANGLE(DisableClientStateIndexedEXT) +#define glDisableClientState MANGLE(DisableClientState) +#define glDisablei MANGLE(Disablei) +#define glDisableIndexedEXT MANGLE(DisableIndexedEXT) +#define glDisable MANGLE(Disable) +#define glDisableVariantClientStateEXT MANGLE(DisableVariantClientStateEXT) +#define glDisableVertexAttribAPPLE MANGLE(DisableVertexAttribAPPLE) +#define glDisableVertexAttribArrayARB MANGLE(DisableVertexAttribArrayARB) +#define glDisableVertexAttribArray MANGLE(DisableVertexAttribArray) +#define glDrawArraysEXT MANGLE(DrawArraysEXT) +#define glDrawArraysInstancedARB MANGLE(DrawArraysInstancedARB) +#define glDrawArraysInstancedEXT MANGLE(DrawArraysInstancedEXT) +#define glDrawArraysInstanced MANGLE(DrawArraysInstanced) +#define glDrawArrays MANGLE(DrawArrays) +#define glDrawBuffer MANGLE(DrawBuffer) +#define glDrawBuffersARB MANGLE(DrawBuffersARB) +#define glDrawBuffersATI MANGLE(DrawBuffersATI) +#define glDrawBuffers MANGLE(DrawBuffers) +#define glDrawElementArrayAPPLE MANGLE(DrawElementArrayAPPLE) +#define glDrawElementArrayATI MANGLE(DrawElementArrayATI) +#define glDrawElementsBaseVertex MANGLE(DrawElementsBaseVertex) +#define glDrawElementsInstancedARB MANGLE(DrawElementsInstancedARB) +#define glDrawElementsInstancedBaseVertex MANGLE(DrawElementsInstancedBaseVertex) +#define glDrawElementsInstancedEXT MANGLE(DrawElementsInstancedEXT) +#define glDrawElementsInstanced MANGLE(DrawElementsInstanced) +#define glDrawElements MANGLE(DrawElements) +#define glDrawMeshArraysSUN MANGLE(DrawMeshArraysSUN) +#define glDrawPixels MANGLE(DrawPixels) +#define glDrawRangeElementArrayAPPLE MANGLE(DrawRangeElementArrayAPPLE) +#define glDrawRangeElementArrayATI MANGLE(DrawRangeElementArrayATI) +#define glDrawRangeElementsBaseVertex MANGLE(DrawRangeElementsBaseVertex) +#define glDrawRangeElementsEXT MANGLE(DrawRangeElementsEXT) +#define glDrawRangeElements MANGLE(DrawRangeElements) +#define glDrawTransformFeedbackNV MANGLE(DrawTransformFeedbackNV) +#define glEdgeFlagFormatNV MANGLE(EdgeFlagFormatNV) +#define glEdgeFlag MANGLE(EdgeFlag) +#define glEdgeFlagPointerEXT MANGLE(EdgeFlagPointerEXT) +#define glEdgeFlagPointerListIBM MANGLE(EdgeFlagPointerListIBM) +#define glEdgeFlagPointer MANGLE(EdgeFlagPointer) +#define glEdgeFlagv MANGLE(EdgeFlagv) +#define glEGLImageTargetRenderbufferStorageOES MANGLE(EGLImageTargetRenderbufferStorageOES) +#define glEGLImageTargetTexture2DOES MANGLE(EGLImageTargetTexture2DOES) +#define glElementPointerAPPLE MANGLE(ElementPointerAPPLE) +#define glElementPointerATI MANGLE(ElementPointerATI) +#define glEnableClientStateIndexedEXT MANGLE(EnableClientStateIndexedEXT) +#define glEnableClientState MANGLE(EnableClientState) +#define glEnablei MANGLE(Enablei) +#define glEnableIndexedEXT MANGLE(EnableIndexedEXT) +#define glEnable MANGLE(Enable) +#define glEnableVariantClientStateEXT MANGLE(EnableVariantClientStateEXT) +#define glEnableVertexAttribAPPLE MANGLE(EnableVertexAttribAPPLE) +#define glEnableVertexAttribArrayARB MANGLE(EnableVertexAttribArrayARB) +#define glEnableVertexAttribArray MANGLE(EnableVertexAttribArray) +#define glEndConditionalRender MANGLE(EndConditionalRender) +#define glEndConditionalRenderNV MANGLE(EndConditionalRenderNV) +#define glEndFragmentShaderATI MANGLE(EndFragmentShaderATI) +#define glEndList MANGLE(EndList) +#define glEnd MANGLE(End) +#define glEndOcclusionQueryNV MANGLE(EndOcclusionQueryNV) +#define glEndPerfMonitorAMD MANGLE(EndPerfMonitorAMD) +#define glEndQueryARB MANGLE(EndQueryARB) +#define glEndQuery MANGLE(EndQuery) +#define glEndTransformFeedbackEXT MANGLE(EndTransformFeedbackEXT) +#define glEndTransformFeedback MANGLE(EndTransformFeedback) +#define glEndTransformFeedbackNV MANGLE(EndTransformFeedbackNV) +#define glEndVertexShaderEXT MANGLE(EndVertexShaderEXT) +#define glEndVideoCaptureNV MANGLE(EndVideoCaptureNV) +#define glEvalCoord1d MANGLE(EvalCoord1d) +#define glEvalCoord1dv MANGLE(EvalCoord1dv) +#define glEvalCoord1f MANGLE(EvalCoord1f) +#define glEvalCoord1fv MANGLE(EvalCoord1fv) +#define glEvalCoord2d MANGLE(EvalCoord2d) +#define glEvalCoord2dv MANGLE(EvalCoord2dv) +#define glEvalCoord2f MANGLE(EvalCoord2f) +#define glEvalCoord2fv MANGLE(EvalCoord2fv) +#define glEvalMapsNV MANGLE(EvalMapsNV) +#define glEvalMesh1 MANGLE(EvalMesh1) +#define glEvalMesh2 MANGLE(EvalMesh2) +#define glEvalPoint1 MANGLE(EvalPoint1) +#define glEvalPoint2 MANGLE(EvalPoint2) +#define glExecuteProgramNV MANGLE(ExecuteProgramNV) +#define glExtractComponentEXT MANGLE(ExtractComponentEXT) +#define glFeedbackBuffer MANGLE(FeedbackBuffer) +#define glFenceSync MANGLE(FenceSync) +#define glFinalCombinerInputNV MANGLE(FinalCombinerInputNV) +#define glFinishAsyncSGIX MANGLE(FinishAsyncSGIX) +#define glFinishFenceAPPLE MANGLE(FinishFenceAPPLE) +#define glFinishFenceNV MANGLE(FinishFenceNV) +#define glFinish MANGLE(Finish) +#define glFinishObjectAPPLE MANGLE(FinishObjectAPPLE) +#define glFinishTextureSUNX MANGLE(FinishTextureSUNX) +#define glFlush MANGLE(Flush) +#define glFlushMappedBufferRangeAPPLE MANGLE(FlushMappedBufferRangeAPPLE) +#define glFlushMappedBufferRange MANGLE(FlushMappedBufferRange) +#define glFlushPixelDataRangeNV MANGLE(FlushPixelDataRangeNV) +#define glFlushRasterSGIX MANGLE(FlushRasterSGIX) +#define glFlushVertexArrayRangeAPPLE MANGLE(FlushVertexArrayRangeAPPLE) +#define glFlushVertexArrayRangeNV MANGLE(FlushVertexArrayRangeNV) +#define glFogCoorddEXT MANGLE(FogCoorddEXT) +#define glFogCoordd MANGLE(FogCoordd) +#define glFogCoorddvEXT MANGLE(FogCoorddvEXT) +#define glFogCoorddv MANGLE(FogCoorddv) +#define glFogCoordfEXT MANGLE(FogCoordfEXT) +#define glFogCoordf MANGLE(FogCoordf) +#define glFogCoordFormatNV MANGLE(FogCoordFormatNV) +#define glFogCoordfvEXT MANGLE(FogCoordfvEXT) +#define glFogCoordfv MANGLE(FogCoordfv) +#define glFogCoordhNV MANGLE(FogCoordhNV) +#define glFogCoordhvNV MANGLE(FogCoordhvNV) +#define glFogCoordPointerEXT MANGLE(FogCoordPointerEXT) +#define glFogCoordPointerListIBM MANGLE(FogCoordPointerListIBM) +#define glFogCoordPointer MANGLE(FogCoordPointer) +#define glFogf MANGLE(Fogf) +#define glFogFuncSGIS MANGLE(FogFuncSGIS) +#define glFogfv MANGLE(Fogfv) +#define glFogi MANGLE(Fogi) +#define glFogiv MANGLE(Fogiv) +#define glFragmentColorMaterialSGIX MANGLE(FragmentColorMaterialSGIX) +#define glFragmentLightfSGIX MANGLE(FragmentLightfSGIX) +#define glFragmentLightfvSGIX MANGLE(FragmentLightfvSGIX) +#define glFragmentLightiSGIX MANGLE(FragmentLightiSGIX) +#define glFragmentLightivSGIX MANGLE(FragmentLightivSGIX) +#define glFragmentLightModelfSGIX MANGLE(FragmentLightModelfSGIX) +#define glFragmentLightModelfvSGIX MANGLE(FragmentLightModelfvSGIX) +#define glFragmentLightModeliSGIX MANGLE(FragmentLightModeliSGIX) +#define glFragmentLightModelivSGIX MANGLE(FragmentLightModelivSGIX) +#define glFragmentMaterialfSGIX MANGLE(FragmentMaterialfSGIX) +#define glFragmentMaterialfvSGIX MANGLE(FragmentMaterialfvSGIX) +#define glFragmentMaterialiSGIX MANGLE(FragmentMaterialiSGIX) +#define glFragmentMaterialivSGIX MANGLE(FragmentMaterialivSGIX) +#define glFramebufferDrawBufferEXT MANGLE(FramebufferDrawBufferEXT) +#define glFramebufferDrawBuffersEXT MANGLE(FramebufferDrawBuffersEXT) +#define glFramebufferReadBufferEXT MANGLE(FramebufferReadBufferEXT) +#define glFramebufferRenderbufferEXT MANGLE(FramebufferRenderbufferEXT) +#define glFramebufferRenderbuffer MANGLE(FramebufferRenderbuffer) +#define glFramebufferTexture1DEXT MANGLE(FramebufferTexture1DEXT) +#define glFramebufferTexture1D MANGLE(FramebufferTexture1D) +#define glFramebufferTexture2DEXT MANGLE(FramebufferTexture2DEXT) +#define glFramebufferTexture2D MANGLE(FramebufferTexture2D) +#define glFramebufferTexture3DEXT MANGLE(FramebufferTexture3DEXT) +#define glFramebufferTexture3D MANGLE(FramebufferTexture3D) +#define glFramebufferTextureARB MANGLE(FramebufferTextureARB) +#define glFramebufferTextureEXT MANGLE(FramebufferTextureEXT) +#define glFramebufferTextureFaceARB MANGLE(FramebufferTextureFaceARB) +#define glFramebufferTextureFaceEXT MANGLE(FramebufferTextureFaceEXT) +#define glFramebufferTextureFace MANGLE(FramebufferTextureFace) +#define glFramebufferTextureLayerARB MANGLE(FramebufferTextureLayerARB) +#define glFramebufferTextureLayerEXT MANGLE(FramebufferTextureLayerEXT) +#define glFramebufferTextureLayer MANGLE(FramebufferTextureLayer) +#define glFramebufferTexture MANGLE(FramebufferTexture) +#define glFrameTerminatorGREMEDY MANGLE(FrameTerminatorGREMEDY) +#define glFrameZoomSGIX MANGLE(FrameZoomSGIX) +#define glFreeObjectBufferATI MANGLE(FreeObjectBufferATI) +#define glFrontFace MANGLE(FrontFace) +#define glFrustum MANGLE(Frustum) +#define glGenAsyncMarkersSGIX MANGLE(GenAsyncMarkersSGIX) +#define glGenBuffersARB MANGLE(GenBuffersARB) +#define glGenBuffers MANGLE(GenBuffers) +#define glGenerateMipmapEXT MANGLE(GenerateMipmapEXT) +#define glGenerateMipmap MANGLE(GenerateMipmap) +#define glGenerateMultiTexMipmapEXT MANGLE(GenerateMultiTexMipmapEXT) +#define glGenerateTextureMipmapEXT MANGLE(GenerateTextureMipmapEXT) +#define glGenFencesAPPLE MANGLE(GenFencesAPPLE) +#define glGenFencesNV MANGLE(GenFencesNV) +#define glGenFragmentShadersATI MANGLE(GenFragmentShadersATI) +#define glGenFramebuffersEXT MANGLE(GenFramebuffersEXT) +#define glGenFramebuffers MANGLE(GenFramebuffers) +#define glGenLists MANGLE(GenLists) +#define glGenOcclusionQueriesNV MANGLE(GenOcclusionQueriesNV) +#define glGenPerfMonitorsAMD MANGLE(GenPerfMonitorsAMD) +#define glGenProgramsARB MANGLE(GenProgramsARB) +#define glGenProgramsNV MANGLE(GenProgramsNV) +#define glGenQueriesARB MANGLE(GenQueriesARB) +#define glGenQueries MANGLE(GenQueries) +#define glGenRenderbuffersEXT MANGLE(GenRenderbuffersEXT) +#define glGenRenderbuffers MANGLE(GenRenderbuffers) +#define glGenSymbolsEXT MANGLE(GenSymbolsEXT) +#define glGenTexturesEXT MANGLE(GenTexturesEXT) +#define glGenTextures MANGLE(GenTextures) +#define glGenTransformFeedbacksNV MANGLE(GenTransformFeedbacksNV) +#define glGenVertexArraysAPPLE MANGLE(GenVertexArraysAPPLE) +#define glGenVertexArrays MANGLE(GenVertexArrays) +#define glGenVertexShadersEXT MANGLE(GenVertexShadersEXT) +#define glGetActiveAttribARB MANGLE(GetActiveAttribARB) +#define glGetActiveAttrib MANGLE(GetActiveAttrib) +#define glGetActiveUniformARB MANGLE(GetActiveUniformARB) +#define glGetActiveUniformBlockiv MANGLE(GetActiveUniformBlockiv) +#define glGetActiveUniformBlockName MANGLE(GetActiveUniformBlockName) +#define glGetActiveUniform MANGLE(GetActiveUniform) +#define glGetActiveUniformName MANGLE(GetActiveUniformName) +#define glGetActiveUniformsiv MANGLE(GetActiveUniformsiv) +#define glGetActiveVaryingNV MANGLE(GetActiveVaryingNV) +#define glGetArrayObjectfvATI MANGLE(GetArrayObjectfvATI) +#define glGetArrayObjectivATI MANGLE(GetArrayObjectivATI) +#define glGetAttachedObjectsARB MANGLE(GetAttachedObjectsARB) +#define glGetAttachedShaders MANGLE(GetAttachedShaders) +#define glGetAttribLocationARB MANGLE(GetAttribLocationARB) +#define glGetAttribLocation MANGLE(GetAttribLocation) +#define glGetBooleanIndexedvEXT MANGLE(GetBooleanIndexedvEXT) +#define glGetBooleani_v MANGLE(GetBooleani_v) +#define glGetBooleanv MANGLE(GetBooleanv) +#define glGetBufferParameteri64v MANGLE(GetBufferParameteri64v) +#define glGetBufferParameterivARB MANGLE(GetBufferParameterivARB) +#define glGetBufferParameteriv MANGLE(GetBufferParameteriv) +#define glGetBufferParameterui64vNV MANGLE(GetBufferParameterui64vNV) +#define glGetBufferPointervARB MANGLE(GetBufferPointervARB) +#define glGetBufferPointerv MANGLE(GetBufferPointerv) +#define glGetBufferSubDataARB MANGLE(GetBufferSubDataARB) +#define glGetBufferSubData MANGLE(GetBufferSubData) +#define glGetClipPlane MANGLE(GetClipPlane) +#define glGetColorTableEXT MANGLE(GetColorTableEXT) +#define glGetColorTable MANGLE(GetColorTable) +#define glGetColorTableParameterfvEXT MANGLE(GetColorTableParameterfvEXT) +#define glGetColorTableParameterfv MANGLE(GetColorTableParameterfv) +#define glGetColorTableParameterfvSGI MANGLE(GetColorTableParameterfvSGI) +#define glGetColorTableParameterivEXT MANGLE(GetColorTableParameterivEXT) +#define glGetColorTableParameteriv MANGLE(GetColorTableParameteriv) +#define glGetColorTableParameterivSGI MANGLE(GetColorTableParameterivSGI) +#define glGetColorTableSGI MANGLE(GetColorTableSGI) +#define glGetCombinerInputParameterfvNV MANGLE(GetCombinerInputParameterfvNV) +#define glGetCombinerInputParameterivNV MANGLE(GetCombinerInputParameterivNV) +#define glGetCombinerOutputParameterfvNV MANGLE(GetCombinerOutputParameterfvNV) +#define glGetCombinerOutputParameterivNV MANGLE(GetCombinerOutputParameterivNV) +#define glGetCombinerStageParameterfvNV MANGLE(GetCombinerStageParameterfvNV) +#define glGetCompressedMultiTexImageEXT MANGLE(GetCompressedMultiTexImageEXT) +#define glGetCompressedTexImageARB MANGLE(GetCompressedTexImageARB) +#define glGetCompressedTexImage MANGLE(GetCompressedTexImage) +#define glGetCompressedTextureImageEXT MANGLE(GetCompressedTextureImageEXT) +#define glGetConvolutionFilterEXT MANGLE(GetConvolutionFilterEXT) +#define glGetConvolutionFilter MANGLE(GetConvolutionFilter) +#define glGetConvolutionParameterfvEXT MANGLE(GetConvolutionParameterfvEXT) +#define glGetConvolutionParameterfv MANGLE(GetConvolutionParameterfv) +#define glGetConvolutionParameterivEXT MANGLE(GetConvolutionParameterivEXT) +#define glGetConvolutionParameteriv MANGLE(GetConvolutionParameteriv) +#define glGetDebugLogLengthMESA MANGLE(GetDebugLogLengthMESA) +#define glGetDebugLogMESA MANGLE(GetDebugLogMESA) +#define glGetDetailTexFuncSGIS MANGLE(GetDetailTexFuncSGIS) +#define glGetDoubleIndexedvEXT MANGLE(GetDoubleIndexedvEXT) +#define glGetDoublev MANGLE(GetDoublev) +#define glGetError MANGLE(GetError) +#define glGetFenceivNV MANGLE(GetFenceivNV) +#define glGetFinalCombinerInputParameterfvNV MANGLE(GetFinalCombinerInputParameterfvNV) +#define glGetFinalCombinerInputParameterivNV MANGLE(GetFinalCombinerInputParameterivNV) +#define glGetFloatIndexedvEXT MANGLE(GetFloatIndexedvEXT) +#define glGetFloatv MANGLE(GetFloatv) +#define glGetFogFuncSGIS MANGLE(GetFogFuncSGIS) +#define glGetFragDataLocationEXT MANGLE(GetFragDataLocationEXT) +#define glGetFragDataLocation MANGLE(GetFragDataLocation) +#define glGetFragmentLightfvSGIX MANGLE(GetFragmentLightfvSGIX) +#define glGetFragmentLightivSGIX MANGLE(GetFragmentLightivSGIX) +#define glGetFragmentMaterialfvSGIX MANGLE(GetFragmentMaterialfvSGIX) +#define glGetFragmentMaterialivSGIX MANGLE(GetFragmentMaterialivSGIX) +#define glGetFramebufferAttachmentParameterivEXT MANGLE(GetFramebufferAttachmentParameterivEXT) +#define glGetFramebufferAttachmentParameteriv MANGLE(GetFramebufferAttachmentParameteriv) +#define glGetFramebufferParameterivEXT MANGLE(GetFramebufferParameterivEXT) +#define glGetHandleARB MANGLE(GetHandleARB) +#define glGetHistogramEXT MANGLE(GetHistogramEXT) +#define glGetHistogram MANGLE(GetHistogram) +#define glGetHistogramParameterfvEXT MANGLE(GetHistogramParameterfvEXT) +#define glGetHistogramParameterfv MANGLE(GetHistogramParameterfv) +#define glGetHistogramParameterivEXT MANGLE(GetHistogramParameterivEXT) +#define glGetHistogramParameteriv MANGLE(GetHistogramParameteriv) +#define glGetImageTransformParameterfvHP MANGLE(GetImageTransformParameterfvHP) +#define glGetImageTransformParameterivHP MANGLE(GetImageTransformParameterivHP) +#define glGetInfoLogARB MANGLE(GetInfoLogARB) +#define glGetInstrumentsSGIX MANGLE(GetInstrumentsSGIX) +#define glGetInteger64i_v MANGLE(GetInteger64i_v) +#define glGetInteger64v MANGLE(GetInteger64v) +#define glGetIntegerIndexedvEXT MANGLE(GetIntegerIndexedvEXT) +#define glGetIntegeri_v MANGLE(GetIntegeri_v) +#define glGetIntegerui64i_vNV MANGLE(GetIntegerui64i_vNV) +#define glGetIntegerui64vNV MANGLE(GetIntegerui64vNV) +#define glGetIntegerv MANGLE(GetIntegerv) +#define glGetInvariantBooleanvEXT MANGLE(GetInvariantBooleanvEXT) +#define glGetInvariantFloatvEXT MANGLE(GetInvariantFloatvEXT) +#define glGetInvariantIntegervEXT MANGLE(GetInvariantIntegervEXT) +#define glGetLightfv MANGLE(GetLightfv) +#define glGetLightiv MANGLE(GetLightiv) +#define glGetListParameterfvSGIX MANGLE(GetListParameterfvSGIX) +#define glGetListParameterivSGIX MANGLE(GetListParameterivSGIX) +#define glGetLocalConstantBooleanvEXT MANGLE(GetLocalConstantBooleanvEXT) +#define glGetLocalConstantFloatvEXT MANGLE(GetLocalConstantFloatvEXT) +#define glGetLocalConstantIntegervEXT MANGLE(GetLocalConstantIntegervEXT) +#define glGetMapAttribParameterfvNV MANGLE(GetMapAttribParameterfvNV) +#define glGetMapAttribParameterivNV MANGLE(GetMapAttribParameterivNV) +#define glGetMapControlPointsNV MANGLE(GetMapControlPointsNV) +#define glGetMapdv MANGLE(GetMapdv) +#define glGetMapfv MANGLE(GetMapfv) +#define glGetMapiv MANGLE(GetMapiv) +#define glGetMapParameterfvNV MANGLE(GetMapParameterfvNV) +#define glGetMapParameterivNV MANGLE(GetMapParameterivNV) +#define glGetMaterialfv MANGLE(GetMaterialfv) +#define glGetMaterialiv MANGLE(GetMaterialiv) +#define glGetMinmaxEXT MANGLE(GetMinmaxEXT) +#define glGetMinmax MANGLE(GetMinmax) +#define glGetMinmaxParameterfvEXT MANGLE(GetMinmaxParameterfvEXT) +#define glGetMinmaxParameterfv MANGLE(GetMinmaxParameterfv) +#define glGetMinmaxParameterivEXT MANGLE(GetMinmaxParameterivEXT) +#define glGetMinmaxParameteriv MANGLE(GetMinmaxParameteriv) +#define glGetMultisamplefv MANGLE(GetMultisamplefv) +#define glGetMultisamplefvNV MANGLE(GetMultisamplefvNV) +#define glGetMultiTexEnvfvEXT MANGLE(GetMultiTexEnvfvEXT) +#define glGetMultiTexEnvivEXT MANGLE(GetMultiTexEnvivEXT) +#define glGetMultiTexGendvEXT MANGLE(GetMultiTexGendvEXT) +#define glGetMultiTexGenfvEXT MANGLE(GetMultiTexGenfvEXT) +#define glGetMultiTexGenivEXT MANGLE(GetMultiTexGenivEXT) +#define glGetMultiTexImageEXT MANGLE(GetMultiTexImageEXT) +#define glGetMultiTexLevelParameterfvEXT MANGLE(GetMultiTexLevelParameterfvEXT) +#define glGetMultiTexLevelParameterivEXT MANGLE(GetMultiTexLevelParameterivEXT) +#define glGetMultiTexParameterfvEXT MANGLE(GetMultiTexParameterfvEXT) +#define glGetMultiTexParameterIivEXT MANGLE(GetMultiTexParameterIivEXT) +#define glGetMultiTexParameterIuivEXT MANGLE(GetMultiTexParameterIuivEXT) +#define glGetMultiTexParameterivEXT MANGLE(GetMultiTexParameterivEXT) +#define glGetNamedBufferParameterivEXT MANGLE(GetNamedBufferParameterivEXT) +#define glGetNamedBufferParameterui64vNV MANGLE(GetNamedBufferParameterui64vNV) +#define glGetNamedBufferPointervEXT MANGLE(GetNamedBufferPointervEXT) +#define glGetNamedBufferSubDataEXT MANGLE(GetNamedBufferSubDataEXT) +#define glGetNamedFramebufferAttachmentParameterivEXT MANGLE(GetNamedFramebufferAttachmentParameterivEXT) +#define glGetNamedProgramivEXT MANGLE(GetNamedProgramivEXT) +#define glGetNamedProgramLocalParameterdvEXT MANGLE(GetNamedProgramLocalParameterdvEXT) +#define glGetNamedProgramLocalParameterfvEXT MANGLE(GetNamedProgramLocalParameterfvEXT) +#define glGetNamedProgramLocalParameterIivEXT MANGLE(GetNamedProgramLocalParameterIivEXT) +#define glGetNamedProgramLocalParameterIuivEXT MANGLE(GetNamedProgramLocalParameterIuivEXT) +#define glGetNamedProgramStringEXT MANGLE(GetNamedProgramStringEXT) +#define glGetNamedRenderbufferParameterivEXT MANGLE(GetNamedRenderbufferParameterivEXT) +#define glGetObjectBufferfvATI MANGLE(GetObjectBufferfvATI) +#define glGetObjectBufferivATI MANGLE(GetObjectBufferivATI) +#define glGetObjectParameterfvARB MANGLE(GetObjectParameterfvARB) +#define glGetObjectParameterivAPPLE MANGLE(GetObjectParameterivAPPLE) +#define glGetObjectParameterivARB MANGLE(GetObjectParameterivARB) +#define glGetOcclusionQueryivNV MANGLE(GetOcclusionQueryivNV) +#define glGetOcclusionQueryuivNV MANGLE(GetOcclusionQueryuivNV) +#define glGetPerfMonitorCounterDataAMD MANGLE(GetPerfMonitorCounterDataAMD) +#define glGetPerfMonitorCounterInfoAMD MANGLE(GetPerfMonitorCounterInfoAMD) +#define glGetPerfMonitorCountersAMD MANGLE(GetPerfMonitorCountersAMD) +#define glGetPerfMonitorCounterStringAMD MANGLE(GetPerfMonitorCounterStringAMD) +#define glGetPerfMonitorGroupsAMD MANGLE(GetPerfMonitorGroupsAMD) +#define glGetPerfMonitorGroupStringAMD MANGLE(GetPerfMonitorGroupStringAMD) +#define glGetPixelMapfv MANGLE(GetPixelMapfv) +#define glGetPixelMapuiv MANGLE(GetPixelMapuiv) +#define glGetPixelMapusv MANGLE(GetPixelMapusv) +#define glGetPixelTexGenParameterfvSGIS MANGLE(GetPixelTexGenParameterfvSGIS) +#define glGetPixelTexGenParameterivSGIS MANGLE(GetPixelTexGenParameterivSGIS) +#define glGetPointerIndexedvEXT MANGLE(GetPointerIndexedvEXT) +#define glGetPointervEXT MANGLE(GetPointervEXT) +#define glGetPointerv MANGLE(GetPointerv) +#define glGetPolygonStipple MANGLE(GetPolygonStipple) +#define glGetProgramEnvParameterdvARB MANGLE(GetProgramEnvParameterdvARB) +#define glGetProgramEnvParameterfvARB MANGLE(GetProgramEnvParameterfvARB) +#define glGetProgramEnvParameterIivNV MANGLE(GetProgramEnvParameterIivNV) +#define glGetProgramEnvParameterIuivNV MANGLE(GetProgramEnvParameterIuivNV) +#define glGetProgramInfoLog MANGLE(GetProgramInfoLog) +#define glGetProgramivARB MANGLE(GetProgramivARB) +#define glGetProgramiv MANGLE(GetProgramiv) +#define glGetProgramivNV MANGLE(GetProgramivNV) +#define glGetProgramLocalParameterdvARB MANGLE(GetProgramLocalParameterdvARB) +#define glGetProgramLocalParameterfvARB MANGLE(GetProgramLocalParameterfvARB) +#define glGetProgramLocalParameterIivNV MANGLE(GetProgramLocalParameterIivNV) +#define glGetProgramLocalParameterIuivNV MANGLE(GetProgramLocalParameterIuivNV) +#define glGetProgramNamedParameterdvNV MANGLE(GetProgramNamedParameterdvNV) +#define glGetProgramNamedParameterfvNV MANGLE(GetProgramNamedParameterfvNV) +#define glGetProgramParameterdvNV MANGLE(GetProgramParameterdvNV) +#define glGetProgramParameterfvNV MANGLE(GetProgramParameterfvNV) +#define glGetProgramRegisterfvMESA MANGLE(GetProgramRegisterfvMESA) +#define glGetProgramStringARB MANGLE(GetProgramStringARB) +#define glGetProgramStringNV MANGLE(GetProgramStringNV) +#define glGetQueryivARB MANGLE(GetQueryivARB) +#define glGetQueryiv MANGLE(GetQueryiv) +#define glGetQueryObjecti64vEXT MANGLE(GetQueryObjecti64vEXT) +#define glGetQueryObjectivARB MANGLE(GetQueryObjectivARB) +#define glGetQueryObjectiv MANGLE(GetQueryObjectiv) +#define glGetQueryObjectui64vEXT MANGLE(GetQueryObjectui64vEXT) +#define glGetQueryObjectuivARB MANGLE(GetQueryObjectuivARB) +#define glGetQueryObjectuiv MANGLE(GetQueryObjectuiv) +#define glGetRenderbufferParameterivEXT MANGLE(GetRenderbufferParameterivEXT) +#define glGetRenderbufferParameteriv MANGLE(GetRenderbufferParameteriv) +#define glGetSeparableFilterEXT MANGLE(GetSeparableFilterEXT) +#define glGetSeparableFilter MANGLE(GetSeparableFilter) +#define glGetShaderInfoLog MANGLE(GetShaderInfoLog) +#define glGetShaderiv MANGLE(GetShaderiv) +#define glGetShaderSourceARB MANGLE(GetShaderSourceARB) +#define glGetShaderSource MANGLE(GetShaderSource) +#define glGetSharpenTexFuncSGIS MANGLE(GetSharpenTexFuncSGIS) +#define glGetStringi MANGLE(GetStringi) +#define glGetString MANGLE(GetString) +#define glGetSynciv MANGLE(GetSynciv) +#define glGetTexBumpParameterfvATI MANGLE(GetTexBumpParameterfvATI) +#define glGetTexBumpParameterivATI MANGLE(GetTexBumpParameterivATI) +#define glGetTexEnvfv MANGLE(GetTexEnvfv) +#define glGetTexEnviv MANGLE(GetTexEnviv) +#define glGetTexFilterFuncSGIS MANGLE(GetTexFilterFuncSGIS) +#define glGetTexGendv MANGLE(GetTexGendv) +#define glGetTexGenfv MANGLE(GetTexGenfv) +#define glGetTexGeniv MANGLE(GetTexGeniv) +#define glGetTexImage MANGLE(GetTexImage) +#define glGetTexLevelParameterfv MANGLE(GetTexLevelParameterfv) +#define glGetTexLevelParameteriv MANGLE(GetTexLevelParameteriv) +#define glGetTexParameterfv MANGLE(GetTexParameterfv) +#define glGetTexParameterIivEXT MANGLE(GetTexParameterIivEXT) +#define glGetTexParameterIiv MANGLE(GetTexParameterIiv) +#define glGetTexParameterIuivEXT MANGLE(GetTexParameterIuivEXT) +#define glGetTexParameterIuiv MANGLE(GetTexParameterIuiv) +#define glGetTexParameteriv MANGLE(GetTexParameteriv) +#define glGetTexParameterPointervAPPLE MANGLE(GetTexParameterPointervAPPLE) +#define glGetTextureImageEXT MANGLE(GetTextureImageEXT) +#define glGetTextureLevelParameterfvEXT MANGLE(GetTextureLevelParameterfvEXT) +#define glGetTextureLevelParameterivEXT MANGLE(GetTextureLevelParameterivEXT) +#define glGetTextureParameterfvEXT MANGLE(GetTextureParameterfvEXT) +#define glGetTextureParameterIivEXT MANGLE(GetTextureParameterIivEXT) +#define glGetTextureParameterIuivEXT MANGLE(GetTextureParameterIuivEXT) +#define glGetTextureParameterivEXT MANGLE(GetTextureParameterivEXT) +#define glGetTrackMatrixivNV MANGLE(GetTrackMatrixivNV) +#define glGetTransformFeedbackVaryingEXT MANGLE(GetTransformFeedbackVaryingEXT) +#define glGetTransformFeedbackVarying MANGLE(GetTransformFeedbackVarying) +#define glGetTransformFeedbackVaryingNV MANGLE(GetTransformFeedbackVaryingNV) +#define glGetUniformBlockIndex MANGLE(GetUniformBlockIndex) +#define glGetUniformBufferSizeEXT MANGLE(GetUniformBufferSizeEXT) +#define glGetUniformfvARB MANGLE(GetUniformfvARB) +#define glGetUniformfv MANGLE(GetUniformfv) +#define glGetUniformIndices MANGLE(GetUniformIndices) +#define glGetUniformivARB MANGLE(GetUniformivARB) +#define glGetUniformiv MANGLE(GetUniformiv) +#define glGetUniformLocationARB MANGLE(GetUniformLocationARB) +#define glGetUniformLocation MANGLE(GetUniformLocation) +#define glGetUniformOffsetEXT MANGLE(GetUniformOffsetEXT) +#define glGetUniformui64vNV MANGLE(GetUniformui64vNV) +#define glGetUniformuivEXT MANGLE(GetUniformuivEXT) +#define glGetUniformuiv MANGLE(GetUniformuiv) +#define glGetVariantArrayObjectfvATI MANGLE(GetVariantArrayObjectfvATI) +#define glGetVariantArrayObjectivATI MANGLE(GetVariantArrayObjectivATI) +#define glGetVariantBooleanvEXT MANGLE(GetVariantBooleanvEXT) +#define glGetVariantFloatvEXT MANGLE(GetVariantFloatvEXT) +#define glGetVariantIntegervEXT MANGLE(GetVariantIntegervEXT) +#define glGetVariantPointervEXT MANGLE(GetVariantPointervEXT) +#define glGetVaryingLocationNV MANGLE(GetVaryingLocationNV) +#define glGetVertexAttribArrayObjectfvATI MANGLE(GetVertexAttribArrayObjectfvATI) +#define glGetVertexAttribArrayObjectivATI MANGLE(GetVertexAttribArrayObjectivATI) +#define glGetVertexAttribdvARB MANGLE(GetVertexAttribdvARB) +#define glGetVertexAttribdv MANGLE(GetVertexAttribdv) +#define glGetVertexAttribdvNV MANGLE(GetVertexAttribdvNV) +#define glGetVertexAttribfvARB MANGLE(GetVertexAttribfvARB) +#define glGetVertexAttribfv MANGLE(GetVertexAttribfv) +#define glGetVertexAttribfvNV MANGLE(GetVertexAttribfvNV) +#define glGetVertexAttribIivEXT MANGLE(GetVertexAttribIivEXT) +#define glGetVertexAttribIiv MANGLE(GetVertexAttribIiv) +#define glGetVertexAttribIuivEXT MANGLE(GetVertexAttribIuivEXT) +#define glGetVertexAttribIuiv MANGLE(GetVertexAttribIuiv) +#define glGetVertexAttribivARB MANGLE(GetVertexAttribivARB) +#define glGetVertexAttribiv MANGLE(GetVertexAttribiv) +#define glGetVertexAttribivNV MANGLE(GetVertexAttribivNV) +#define glGetVertexAttribPointervARB MANGLE(GetVertexAttribPointervARB) +#define glGetVertexAttribPointerv MANGLE(GetVertexAttribPointerv) +#define glGetVertexAttribPointervNV MANGLE(GetVertexAttribPointervNV) +#define glGetVideoCaptureivNV MANGLE(GetVideoCaptureivNV) +#define glGetVideoCaptureStreamdvNV MANGLE(GetVideoCaptureStreamdvNV) +#define glGetVideoCaptureStreamfvNV MANGLE(GetVideoCaptureStreamfvNV) +#define glGetVideoCaptureStreamivNV MANGLE(GetVideoCaptureStreamivNV) +#define glGetVideoi64vNV MANGLE(GetVideoi64vNV) +#define glGetVideoivNV MANGLE(GetVideoivNV) +#define glGetVideoui64vNV MANGLE(GetVideoui64vNV) +#define glGetVideouivNV MANGLE(GetVideouivNV) +#define glGlobalAlphaFactorbSUN MANGLE(GlobalAlphaFactorbSUN) +#define glGlobalAlphaFactordSUN MANGLE(GlobalAlphaFactordSUN) +#define glGlobalAlphaFactorfSUN MANGLE(GlobalAlphaFactorfSUN) +#define glGlobalAlphaFactoriSUN MANGLE(GlobalAlphaFactoriSUN) +#define glGlobalAlphaFactorsSUN MANGLE(GlobalAlphaFactorsSUN) +#define glGlobalAlphaFactorubSUN MANGLE(GlobalAlphaFactorubSUN) +#define glGlobalAlphaFactoruiSUN MANGLE(GlobalAlphaFactoruiSUN) +#define glGlobalAlphaFactorusSUN MANGLE(GlobalAlphaFactorusSUN) +#define glHint MANGLE(Hint) +#define glHintPGI MANGLE(HintPGI) +#define glHistogramEXT MANGLE(HistogramEXT) +#define glHistogram MANGLE(Histogram) +#define glIglooInterfaceSGIX MANGLE(IglooInterfaceSGIX) +#define glImageTransformParameterfHP MANGLE(ImageTransformParameterfHP) +#define glImageTransformParameterfvHP MANGLE(ImageTransformParameterfvHP) +#define glImageTransformParameteriHP MANGLE(ImageTransformParameteriHP) +#define glImageTransformParameterivHP MANGLE(ImageTransformParameterivHP) +#define glIndexd MANGLE(Indexd) +#define glIndexdv MANGLE(Indexdv) +#define glIndexf MANGLE(Indexf) +#define glIndexFormatNV MANGLE(IndexFormatNV) +#define glIndexFuncEXT MANGLE(IndexFuncEXT) +#define glIndexfv MANGLE(Indexfv) +#define glIndexi MANGLE(Indexi) +#define glIndexiv MANGLE(Indexiv) +#define glIndexMask MANGLE(IndexMask) +#define glIndexMaterialEXT MANGLE(IndexMaterialEXT) +#define glIndexPointerEXT MANGLE(IndexPointerEXT) +#define glIndexPointerListIBM MANGLE(IndexPointerListIBM) +#define glIndexPointer MANGLE(IndexPointer) +#define glIndexs MANGLE(Indexs) +#define glIndexsv MANGLE(Indexsv) +#define glIndexub MANGLE(Indexub) +#define glIndexubv MANGLE(Indexubv) +#define glInitNames MANGLE(InitNames) +#define glInsertComponentEXT MANGLE(InsertComponentEXT) +#define glInstrumentsBufferSGIX MANGLE(InstrumentsBufferSGIX) +#define glInterleavedArrays MANGLE(InterleavedArrays) +#define glIsAsyncMarkerSGIX MANGLE(IsAsyncMarkerSGIX) +#define glIsBufferARB MANGLE(IsBufferARB) +#define glIsBuffer MANGLE(IsBuffer) +#define glIsBufferResidentNV MANGLE(IsBufferResidentNV) +#define glIsEnabledi MANGLE(IsEnabledi) +#define glIsEnabledIndexedEXT MANGLE(IsEnabledIndexedEXT) +#define glIsEnabled MANGLE(IsEnabled) +#define glIsFenceAPPLE MANGLE(IsFenceAPPLE) +#define glIsFenceNV MANGLE(IsFenceNV) +#define glIsFramebufferEXT MANGLE(IsFramebufferEXT) +#define glIsFramebuffer MANGLE(IsFramebuffer) +#define glIsList MANGLE(IsList) +#define glIsNamedBufferResidentNV MANGLE(IsNamedBufferResidentNV) +#define glIsObjectBufferATI MANGLE(IsObjectBufferATI) +#define glIsOcclusionQueryNV MANGLE(IsOcclusionQueryNV) +#define glIsProgramARB MANGLE(IsProgramARB) +#define glIsProgram MANGLE(IsProgram) +#define glIsProgramNV MANGLE(IsProgramNV) +#define glIsQueryARB MANGLE(IsQueryARB) +#define glIsQuery MANGLE(IsQuery) +#define glIsRenderbufferEXT MANGLE(IsRenderbufferEXT) +#define glIsRenderbuffer MANGLE(IsRenderbuffer) +#define glIsShader MANGLE(IsShader) +#define glIsSync MANGLE(IsSync) +#define glIsTextureEXT MANGLE(IsTextureEXT) +#define glIsTexture MANGLE(IsTexture) +#define glIsTransformFeedbackNV MANGLE(IsTransformFeedbackNV) +#define glIsVariantEnabledEXT MANGLE(IsVariantEnabledEXT) +#define glIsVertexArrayAPPLE MANGLE(IsVertexArrayAPPLE) +#define glIsVertexArray MANGLE(IsVertexArray) +#define glIsVertexAttribEnabledAPPLE MANGLE(IsVertexAttribEnabledAPPLE) +#define glLightEnviSGIX MANGLE(LightEnviSGIX) +#define glLightf MANGLE(Lightf) +#define glLightfv MANGLE(Lightfv) +#define glLighti MANGLE(Lighti) +#define glLightiv MANGLE(Lightiv) +#define glLightModelf MANGLE(LightModelf) +#define glLightModelfv MANGLE(LightModelfv) +#define glLightModeli MANGLE(LightModeli) +#define glLightModeliv MANGLE(LightModeliv) +#define glLineStipple MANGLE(LineStipple) +#define glLineWidth MANGLE(LineWidth) +#define glLinkProgramARB MANGLE(LinkProgramARB) +#define glLinkProgram MANGLE(LinkProgram) +#define glListBase MANGLE(ListBase) +#define glListParameterfSGIX MANGLE(ListParameterfSGIX) +#define glListParameterfvSGIX MANGLE(ListParameterfvSGIX) +#define glListParameteriSGIX MANGLE(ListParameteriSGIX) +#define glListParameterivSGIX MANGLE(ListParameterivSGIX) +#define glLoadIdentityDeformationMapSGIX MANGLE(LoadIdentityDeformationMapSGIX) +#define glLoadIdentity MANGLE(LoadIdentity) +#define glLoadMatrixd MANGLE(LoadMatrixd) +#define glLoadMatrixf MANGLE(LoadMatrixf) +#define glLoadName MANGLE(LoadName) +#define glLoadProgramNV MANGLE(LoadProgramNV) +#define glLoadTransposeMatrixdARB MANGLE(LoadTransposeMatrixdARB) +#define glLoadTransposeMatrixd MANGLE(LoadTransposeMatrixd) +#define glLoadTransposeMatrixfARB MANGLE(LoadTransposeMatrixfARB) +#define glLoadTransposeMatrixf MANGLE(LoadTransposeMatrixf) +#define glLockArraysEXT MANGLE(LockArraysEXT) +#define glLogicOp MANGLE(LogicOp) +#define glMakeBufferNonResidentNV MANGLE(MakeBufferNonResidentNV) +#define glMakeBufferResidentNV MANGLE(MakeBufferResidentNV) +#define glMap1d MANGLE(Map1d) +#define glMap1f MANGLE(Map1f) +#define glMap2d MANGLE(Map2d) +#define glMap2f MANGLE(Map2f) +#define glMapBufferARB MANGLE(MapBufferARB) +#define glMapBuffer MANGLE(MapBuffer) +#define glMapBufferRange MANGLE(MapBufferRange) +#define glMapControlPointsNV MANGLE(MapControlPointsNV) +#define glMapGrid1d MANGLE(MapGrid1d) +#define glMapGrid1f MANGLE(MapGrid1f) +#define glMapGrid2d MANGLE(MapGrid2d) +#define glMapGrid2f MANGLE(MapGrid2f) +#define glMapNamedBufferEXT MANGLE(MapNamedBufferEXT) +#define glMapObjectBufferATI MANGLE(MapObjectBufferATI) +#define glMapParameterfvNV MANGLE(MapParameterfvNV) +#define glMapParameterivNV MANGLE(MapParameterivNV) +#define glMapVertexAttrib1dAPPLE MANGLE(MapVertexAttrib1dAPPLE) +#define glMapVertexAttrib1fAPPLE MANGLE(MapVertexAttrib1fAPPLE) +#define glMapVertexAttrib2dAPPLE MANGLE(MapVertexAttrib2dAPPLE) +#define glMapVertexAttrib2fAPPLE MANGLE(MapVertexAttrib2fAPPLE) +#define glMaterialf MANGLE(Materialf) +#define glMaterialfv MANGLE(Materialfv) +#define glMateriali MANGLE(Materiali) +#define glMaterialiv MANGLE(Materialiv) +#define glMatrixFrustumEXT MANGLE(MatrixFrustumEXT) +#define glMatrixIndexPointerARB MANGLE(MatrixIndexPointerARB) +#define glMatrixIndexubvARB MANGLE(MatrixIndexubvARB) +#define glMatrixIndexuivARB MANGLE(MatrixIndexuivARB) +#define glMatrixIndexusvARB MANGLE(MatrixIndexusvARB) +#define glMatrixLoaddEXT MANGLE(MatrixLoaddEXT) +#define glMatrixLoadfEXT MANGLE(MatrixLoadfEXT) +#define glMatrixLoadIdentityEXT MANGLE(MatrixLoadIdentityEXT) +#define glMatrixLoadTransposedEXT MANGLE(MatrixLoadTransposedEXT) +#define glMatrixLoadTransposefEXT MANGLE(MatrixLoadTransposefEXT) +#define glMatrixMode MANGLE(MatrixMode) +#define glMatrixMultdEXT MANGLE(MatrixMultdEXT) +#define glMatrixMultfEXT MANGLE(MatrixMultfEXT) +#define glMatrixMultTransposedEXT MANGLE(MatrixMultTransposedEXT) +#define glMatrixMultTransposefEXT MANGLE(MatrixMultTransposefEXT) +#define glMatrixOrthoEXT MANGLE(MatrixOrthoEXT) +#define glMatrixPopEXT MANGLE(MatrixPopEXT) +#define glMatrixPushEXT MANGLE(MatrixPushEXT) +#define glMatrixRotatedEXT MANGLE(MatrixRotatedEXT) +#define glMatrixRotatefEXT MANGLE(MatrixRotatefEXT) +#define glMatrixScaledEXT MANGLE(MatrixScaledEXT) +#define glMatrixScalefEXT MANGLE(MatrixScalefEXT) +#define glMatrixTranslatedEXT MANGLE(MatrixTranslatedEXT) +#define glMatrixTranslatefEXT MANGLE(MatrixTranslatefEXT) +#define glMinmaxEXT MANGLE(MinmaxEXT) +#define glMinmax MANGLE(Minmax) +#define glMinSampleShading MANGLE(MinSampleShading) +#define glMultiDrawArraysEXT MANGLE(MultiDrawArraysEXT) +#define glMultiDrawArrays MANGLE(MultiDrawArrays) +#define glMultiDrawElementArrayAPPLE MANGLE(MultiDrawElementArrayAPPLE) +#define glMultiDrawElementsBaseVertex MANGLE(MultiDrawElementsBaseVertex) +#define glMultiDrawElementsEXT MANGLE(MultiDrawElementsEXT) +#define glMultiDrawElements MANGLE(MultiDrawElements) +#define glMultiDrawRangeElementArrayAPPLE MANGLE(MultiDrawRangeElementArrayAPPLE) +#define glMultiModeDrawArraysIBM MANGLE(MultiModeDrawArraysIBM) +#define glMultiModeDrawElementsIBM MANGLE(MultiModeDrawElementsIBM) +#define glMultiTexBufferEXT MANGLE(MultiTexBufferEXT) +#define glMultiTexCoord1dARB MANGLE(MultiTexCoord1dARB) +#define glMultiTexCoord1d MANGLE(MultiTexCoord1d) +#define glMultiTexCoord1dvARB MANGLE(MultiTexCoord1dvARB) +#define glMultiTexCoord1dv MANGLE(MultiTexCoord1dv) +#define glMultiTexCoord1fARB MANGLE(MultiTexCoord1fARB) +#define glMultiTexCoord1f MANGLE(MultiTexCoord1f) +#define glMultiTexCoord1fvARB MANGLE(MultiTexCoord1fvARB) +#define glMultiTexCoord1fv MANGLE(MultiTexCoord1fv) +#define glMultiTexCoord1hNV MANGLE(MultiTexCoord1hNV) +#define glMultiTexCoord1hvNV MANGLE(MultiTexCoord1hvNV) +#define glMultiTexCoord1iARB MANGLE(MultiTexCoord1iARB) +#define glMultiTexCoord1i MANGLE(MultiTexCoord1i) +#define glMultiTexCoord1ivARB MANGLE(MultiTexCoord1ivARB) +#define glMultiTexCoord1iv MANGLE(MultiTexCoord1iv) +#define glMultiTexCoord1sARB MANGLE(MultiTexCoord1sARB) +#define glMultiTexCoord1s MANGLE(MultiTexCoord1s) +#define glMultiTexCoord1svARB MANGLE(MultiTexCoord1svARB) +#define glMultiTexCoord1sv MANGLE(MultiTexCoord1sv) +#define glMultiTexCoord2dARB MANGLE(MultiTexCoord2dARB) +#define glMultiTexCoord2d MANGLE(MultiTexCoord2d) +#define glMultiTexCoord2dvARB MANGLE(MultiTexCoord2dvARB) +#define glMultiTexCoord2dv MANGLE(MultiTexCoord2dv) +#define glMultiTexCoord2fARB MANGLE(MultiTexCoord2fARB) +#define glMultiTexCoord2f MANGLE(MultiTexCoord2f) +#define glMultiTexCoord2fvARB MANGLE(MultiTexCoord2fvARB) +#define glMultiTexCoord2fv MANGLE(MultiTexCoord2fv) +#define glMultiTexCoord2hNV MANGLE(MultiTexCoord2hNV) +#define glMultiTexCoord2hvNV MANGLE(MultiTexCoord2hvNV) +#define glMultiTexCoord2iARB MANGLE(MultiTexCoord2iARB) +#define glMultiTexCoord2i MANGLE(MultiTexCoord2i) +#define glMultiTexCoord2ivARB MANGLE(MultiTexCoord2ivARB) +#define glMultiTexCoord2iv MANGLE(MultiTexCoord2iv) +#define glMultiTexCoord2sARB MANGLE(MultiTexCoord2sARB) +#define glMultiTexCoord2s MANGLE(MultiTexCoord2s) +#define glMultiTexCoord2svARB MANGLE(MultiTexCoord2svARB) +#define glMultiTexCoord2sv MANGLE(MultiTexCoord2sv) +#define glMultiTexCoord3dARB MANGLE(MultiTexCoord3dARB) +#define glMultiTexCoord3d MANGLE(MultiTexCoord3d) +#define glMultiTexCoord3dvARB MANGLE(MultiTexCoord3dvARB) +#define glMultiTexCoord3dv MANGLE(MultiTexCoord3dv) +#define glMultiTexCoord3fARB MANGLE(MultiTexCoord3fARB) +#define glMultiTexCoord3f MANGLE(MultiTexCoord3f) +#define glMultiTexCoord3fvARB MANGLE(MultiTexCoord3fvARB) +#define glMultiTexCoord3fv MANGLE(MultiTexCoord3fv) +#define glMultiTexCoord3hNV MANGLE(MultiTexCoord3hNV) +#define glMultiTexCoord3hvNV MANGLE(MultiTexCoord3hvNV) +#define glMultiTexCoord3iARB MANGLE(MultiTexCoord3iARB) +#define glMultiTexCoord3i MANGLE(MultiTexCoord3i) +#define glMultiTexCoord3ivARB MANGLE(MultiTexCoord3ivARB) +#define glMultiTexCoord3iv MANGLE(MultiTexCoord3iv) +#define glMultiTexCoord3sARB MANGLE(MultiTexCoord3sARB) +#define glMultiTexCoord3s MANGLE(MultiTexCoord3s) +#define glMultiTexCoord3svARB MANGLE(MultiTexCoord3svARB) +#define glMultiTexCoord3sv MANGLE(MultiTexCoord3sv) +#define glMultiTexCoord4dARB MANGLE(MultiTexCoord4dARB) +#define glMultiTexCoord4d MANGLE(MultiTexCoord4d) +#define glMultiTexCoord4dvARB MANGLE(MultiTexCoord4dvARB) +#define glMultiTexCoord4dv MANGLE(MultiTexCoord4dv) +#define glMultiTexCoord4fARB MANGLE(MultiTexCoord4fARB) +#define glMultiTexCoord4f MANGLE(MultiTexCoord4f) +#define glMultiTexCoord4fvARB MANGLE(MultiTexCoord4fvARB) +#define glMultiTexCoord4fv MANGLE(MultiTexCoord4fv) +#define glMultiTexCoord4hNV MANGLE(MultiTexCoord4hNV) +#define glMultiTexCoord4hvNV MANGLE(MultiTexCoord4hvNV) +#define glMultiTexCoord4iARB MANGLE(MultiTexCoord4iARB) +#define glMultiTexCoord4i MANGLE(MultiTexCoord4i) +#define glMultiTexCoord4ivARB MANGLE(MultiTexCoord4ivARB) +#define glMultiTexCoord4iv MANGLE(MultiTexCoord4iv) +#define glMultiTexCoord4sARB MANGLE(MultiTexCoord4sARB) +#define glMultiTexCoord4s MANGLE(MultiTexCoord4s) +#define glMultiTexCoord4svARB MANGLE(MultiTexCoord4svARB) +#define glMultiTexCoord4sv MANGLE(MultiTexCoord4sv) +#define glMultiTexCoordPointerEXT MANGLE(MultiTexCoordPointerEXT) +#define glMultiTexEnvfEXT MANGLE(MultiTexEnvfEXT) +#define glMultiTexEnvfvEXT MANGLE(MultiTexEnvfvEXT) +#define glMultiTexEnviEXT MANGLE(MultiTexEnviEXT) +#define glMultiTexEnvivEXT MANGLE(MultiTexEnvivEXT) +#define glMultiTexGendEXT MANGLE(MultiTexGendEXT) +#define glMultiTexGendvEXT MANGLE(MultiTexGendvEXT) +#define glMultiTexGenfEXT MANGLE(MultiTexGenfEXT) +#define glMultiTexGenfvEXT MANGLE(MultiTexGenfvEXT) +#define glMultiTexGeniEXT MANGLE(MultiTexGeniEXT) +#define glMultiTexGenivEXT MANGLE(MultiTexGenivEXT) +#define glMultiTexImage1DEXT MANGLE(MultiTexImage1DEXT) +#define glMultiTexImage2DEXT MANGLE(MultiTexImage2DEXT) +#define glMultiTexImage3DEXT MANGLE(MultiTexImage3DEXT) +#define glMultiTexParameterfEXT MANGLE(MultiTexParameterfEXT) +#define glMultiTexParameterfvEXT MANGLE(MultiTexParameterfvEXT) +#define glMultiTexParameteriEXT MANGLE(MultiTexParameteriEXT) +#define glMultiTexParameterIivEXT MANGLE(MultiTexParameterIivEXT) +#define glMultiTexParameterIuivEXT MANGLE(MultiTexParameterIuivEXT) +#define glMultiTexParameterivEXT MANGLE(MultiTexParameterivEXT) +#define glMultiTexRenderbufferEXT MANGLE(MultiTexRenderbufferEXT) +#define glMultiTexSubImage1DEXT MANGLE(MultiTexSubImage1DEXT) +#define glMultiTexSubImage2DEXT MANGLE(MultiTexSubImage2DEXT) +#define glMultiTexSubImage3DEXT MANGLE(MultiTexSubImage3DEXT) +#define glMultMatrixd MANGLE(MultMatrixd) +#define glMultMatrixf MANGLE(MultMatrixf) +#define glMultTransposeMatrixdARB MANGLE(MultTransposeMatrixdARB) +#define glMultTransposeMatrixd MANGLE(MultTransposeMatrixd) +#define glMultTransposeMatrixfARB MANGLE(MultTransposeMatrixfARB) +#define glMultTransposeMatrixf MANGLE(MultTransposeMatrixf) +#define glNamedBufferDataEXT MANGLE(NamedBufferDataEXT) +#define glNamedBufferSubDataEXT MANGLE(NamedBufferSubDataEXT) +#define glNamedFramebufferRenderbufferEXT MANGLE(NamedFramebufferRenderbufferEXT) +#define glNamedFramebufferTexture1DEXT MANGLE(NamedFramebufferTexture1DEXT) +#define glNamedFramebufferTexture2DEXT MANGLE(NamedFramebufferTexture2DEXT) +#define glNamedFramebufferTexture3DEXT MANGLE(NamedFramebufferTexture3DEXT) +#define glNamedFramebufferTextureEXT MANGLE(NamedFramebufferTextureEXT) +#define glNamedFramebufferTextureFaceEXT MANGLE(NamedFramebufferTextureFaceEXT) +#define glNamedFramebufferTextureLayerEXT MANGLE(NamedFramebufferTextureLayerEXT) +#define glNamedMakeBufferNonResidentNV MANGLE(NamedMakeBufferNonResidentNV) +#define glNamedMakeBufferResidentNV MANGLE(NamedMakeBufferResidentNV) +#define glNamedProgramLocalParameter4dEXT MANGLE(NamedProgramLocalParameter4dEXT) +#define glNamedProgramLocalParameter4dvEXT MANGLE(NamedProgramLocalParameter4dvEXT) +#define glNamedProgramLocalParameter4fEXT MANGLE(NamedProgramLocalParameter4fEXT) +#define glNamedProgramLocalParameter4fvEXT MANGLE(NamedProgramLocalParameter4fvEXT) +#define glNamedProgramLocalParameterI4iEXT MANGLE(NamedProgramLocalParameterI4iEXT) +#define glNamedProgramLocalParameterI4ivEXT MANGLE(NamedProgramLocalParameterI4ivEXT) +#define glNamedProgramLocalParameterI4uiEXT MANGLE(NamedProgramLocalParameterI4uiEXT) +#define glNamedProgramLocalParameterI4uivEXT MANGLE(NamedProgramLocalParameterI4uivEXT) +#define glNamedProgramLocalParameters4fvEXT MANGLE(NamedProgramLocalParameters4fvEXT) +#define glNamedProgramLocalParametersI4ivEXT MANGLE(NamedProgramLocalParametersI4ivEXT) +#define glNamedProgramLocalParametersI4uivEXT MANGLE(NamedProgramLocalParametersI4uivEXT) +#define glNamedProgramStringEXT MANGLE(NamedProgramStringEXT) +#define glNamedRenderbufferStorageEXT MANGLE(NamedRenderbufferStorageEXT) +#define glNamedRenderbufferStorageMultisampleCoverageEXT MANGLE(NamedRenderbufferStorageMultisampleCoverageEXT) +#define glNamedRenderbufferStorageMultisampleEXT MANGLE(NamedRenderbufferStorageMultisampleEXT) +#define glNewList MANGLE(NewList) +#define glNewObjectBufferATI MANGLE(NewObjectBufferATI) +#define glNormal3b MANGLE(Normal3b) +#define glNormal3bv MANGLE(Normal3bv) +#define glNormal3d MANGLE(Normal3d) +#define glNormal3dv MANGLE(Normal3dv) +#define glNormal3f MANGLE(Normal3f) +#define glNormal3fVertex3fSUN MANGLE(Normal3fVertex3fSUN) +#define glNormal3fVertex3fvSUN MANGLE(Normal3fVertex3fvSUN) +#define glNormal3fv MANGLE(Normal3fv) +#define glNormal3hNV MANGLE(Normal3hNV) +#define glNormal3hvNV MANGLE(Normal3hvNV) +#define glNormal3i MANGLE(Normal3i) +#define glNormal3iv MANGLE(Normal3iv) +#define glNormal3s MANGLE(Normal3s) +#define glNormal3sv MANGLE(Normal3sv) +#define glNormalFormatNV MANGLE(NormalFormatNV) +#define glNormalPointerEXT MANGLE(NormalPointerEXT) +#define glNormalPointerListIBM MANGLE(NormalPointerListIBM) +#define glNormalPointer MANGLE(NormalPointer) +#define glNormalPointervINTEL MANGLE(NormalPointervINTEL) +#define glNormalStream3bATI MANGLE(NormalStream3bATI) +#define glNormalStream3bvATI MANGLE(NormalStream3bvATI) +#define glNormalStream3dATI MANGLE(NormalStream3dATI) +#define glNormalStream3dvATI MANGLE(NormalStream3dvATI) +#define glNormalStream3fATI MANGLE(NormalStream3fATI) +#define glNormalStream3fvATI MANGLE(NormalStream3fvATI) +#define glNormalStream3iATI MANGLE(NormalStream3iATI) +#define glNormalStream3ivATI MANGLE(NormalStream3ivATI) +#define glNormalStream3sATI MANGLE(NormalStream3sATI) +#define glNormalStream3svATI MANGLE(NormalStream3svATI) +#define glObjectPurgeableAPPLE MANGLE(ObjectPurgeableAPPLE) +#define glObjectUnpurgeableAPPLE MANGLE(ObjectUnpurgeableAPPLE) +#define glOrtho MANGLE(Ortho) +#define glPassTexCoordATI MANGLE(PassTexCoordATI) +#define glPassThrough MANGLE(PassThrough) +#define glPauseTransformFeedbackNV MANGLE(PauseTransformFeedbackNV) +#define glPixelDataRangeNV MANGLE(PixelDataRangeNV) +#define glPixelMapfv MANGLE(PixelMapfv) +#define glPixelMapuiv MANGLE(PixelMapuiv) +#define glPixelMapusv MANGLE(PixelMapusv) +#define glPixelStoref MANGLE(PixelStoref) +#define glPixelStorei MANGLE(PixelStorei) +#define glPixelTexGenParameterfSGIS MANGLE(PixelTexGenParameterfSGIS) +#define glPixelTexGenParameterfvSGIS MANGLE(PixelTexGenParameterfvSGIS) +#define glPixelTexGenParameteriSGIS MANGLE(PixelTexGenParameteriSGIS) +#define glPixelTexGenParameterivSGIS MANGLE(PixelTexGenParameterivSGIS) +#define glPixelTexGenSGIX MANGLE(PixelTexGenSGIX) +#define glPixelTransferf MANGLE(PixelTransferf) +#define glPixelTransferi MANGLE(PixelTransferi) +#define glPixelTransformParameterfEXT MANGLE(PixelTransformParameterfEXT) +#define glPixelTransformParameterfvEXT MANGLE(PixelTransformParameterfvEXT) +#define glPixelTransformParameteriEXT MANGLE(PixelTransformParameteriEXT) +#define glPixelTransformParameterivEXT MANGLE(PixelTransformParameterivEXT) +#define glPixelZoom MANGLE(PixelZoom) +#define glPNTrianglesfATI MANGLE(PNTrianglesfATI) +#define glPNTrianglesiATI MANGLE(PNTrianglesiATI) +#define glPointParameterfARB MANGLE(PointParameterfARB) +#define glPointParameterfEXT MANGLE(PointParameterfEXT) +#define glPointParameterf MANGLE(PointParameterf) +#define glPointParameterfSGIS MANGLE(PointParameterfSGIS) +#define glPointParameterfvARB MANGLE(PointParameterfvARB) +#define glPointParameterfvEXT MANGLE(PointParameterfvEXT) +#define glPointParameterfv MANGLE(PointParameterfv) +#define glPointParameterfvSGIS MANGLE(PointParameterfvSGIS) +#define glPointParameteri MANGLE(PointParameteri) +#define glPointParameteriNV MANGLE(PointParameteriNV) +#define glPointParameteriv MANGLE(PointParameteriv) +#define glPointParameterivNV MANGLE(PointParameterivNV) +#define glPointSize MANGLE(PointSize) +#define glPollAsyncSGIX MANGLE(PollAsyncSGIX) +#define glPollInstrumentsSGIX MANGLE(PollInstrumentsSGIX) +#define glPolygonMode MANGLE(PolygonMode) +#define glPolygonOffsetEXT MANGLE(PolygonOffsetEXT) +#define glPolygonOffset MANGLE(PolygonOffset) +#define glPolygonStipple MANGLE(PolygonStipple) +#define glPopAttrib MANGLE(PopAttrib) +#define glPopClientAttrib MANGLE(PopClientAttrib) +#define glPopMatrix MANGLE(PopMatrix) +#define glPopName MANGLE(PopName) +#define glPresentFrameDualFillNV MANGLE(PresentFrameDualFillNV) +#define glPresentFrameKeyedNV MANGLE(PresentFrameKeyedNV) +#define glPrimitiveRestartIndex MANGLE(PrimitiveRestartIndex) +#define glPrimitiveRestartIndexNV MANGLE(PrimitiveRestartIndexNV) +#define glPrimitiveRestartNV MANGLE(PrimitiveRestartNV) +#define glPrioritizeTexturesEXT MANGLE(PrioritizeTexturesEXT) +#define glPrioritizeTextures MANGLE(PrioritizeTextures) +#define glProgramBufferParametersfvNV MANGLE(ProgramBufferParametersfvNV) +#define glProgramBufferParametersIivNV MANGLE(ProgramBufferParametersIivNV) +#define glProgramBufferParametersIuivNV MANGLE(ProgramBufferParametersIuivNV) +#define glProgramCallbackMESA MANGLE(ProgramCallbackMESA) +#define glProgramEnvParameter4dARB MANGLE(ProgramEnvParameter4dARB) +#define glProgramEnvParameter4dvARB MANGLE(ProgramEnvParameter4dvARB) +#define glProgramEnvParameter4fARB MANGLE(ProgramEnvParameter4fARB) +#define glProgramEnvParameter4fvARB MANGLE(ProgramEnvParameter4fvARB) +#define glProgramEnvParameterI4iNV MANGLE(ProgramEnvParameterI4iNV) +#define glProgramEnvParameterI4ivNV MANGLE(ProgramEnvParameterI4ivNV) +#define glProgramEnvParameterI4uiNV MANGLE(ProgramEnvParameterI4uiNV) +#define glProgramEnvParameterI4uivNV MANGLE(ProgramEnvParameterI4uivNV) +#define glProgramEnvParameters4fvEXT MANGLE(ProgramEnvParameters4fvEXT) +#define glProgramEnvParametersI4ivNV MANGLE(ProgramEnvParametersI4ivNV) +#define glProgramEnvParametersI4uivNV MANGLE(ProgramEnvParametersI4uivNV) +#define glProgramLocalParameter4dARB MANGLE(ProgramLocalParameter4dARB) +#define glProgramLocalParameter4dvARB MANGLE(ProgramLocalParameter4dvARB) +#define glProgramLocalParameter4fARB MANGLE(ProgramLocalParameter4fARB) +#define glProgramLocalParameter4fvARB MANGLE(ProgramLocalParameter4fvARB) +#define glProgramLocalParameterI4iNV MANGLE(ProgramLocalParameterI4iNV) +#define glProgramLocalParameterI4ivNV MANGLE(ProgramLocalParameterI4ivNV) +#define glProgramLocalParameterI4uiNV MANGLE(ProgramLocalParameterI4uiNV) +#define glProgramLocalParameterI4uivNV MANGLE(ProgramLocalParameterI4uivNV) +#define glProgramLocalParameters4fvEXT MANGLE(ProgramLocalParameters4fvEXT) +#define glProgramLocalParametersI4ivNV MANGLE(ProgramLocalParametersI4ivNV) +#define glProgramLocalParametersI4uivNV MANGLE(ProgramLocalParametersI4uivNV) +#define glProgramNamedParameter4dNV MANGLE(ProgramNamedParameter4dNV) +#define glProgramNamedParameter4dvNV MANGLE(ProgramNamedParameter4dvNV) +#define glProgramNamedParameter4fNV MANGLE(ProgramNamedParameter4fNV) +#define glProgramNamedParameter4fvNV MANGLE(ProgramNamedParameter4fvNV) +#define glProgramParameter4dNV MANGLE(ProgramParameter4dNV) +#define glProgramParameter4dvNV MANGLE(ProgramParameter4dvNV) +#define glProgramParameter4fNV MANGLE(ProgramParameter4fNV) +#define glProgramParameter4fvNV MANGLE(ProgramParameter4fvNV) +#define glProgramParameteriARB MANGLE(ProgramParameteriARB) +#define glProgramParameteriEXT MANGLE(ProgramParameteriEXT) +#define glProgramParameteri MANGLE(ProgramParameteri) +#define glProgramParameters4dvNV MANGLE(ProgramParameters4dvNV) +#define glProgramParameters4fvNV MANGLE(ProgramParameters4fvNV) +#define glProgramStringARB MANGLE(ProgramStringARB) +#define glProgramUniform1fEXT MANGLE(ProgramUniform1fEXT) +#define glProgramUniform1fvEXT MANGLE(ProgramUniform1fvEXT) +#define glProgramUniform1iEXT MANGLE(ProgramUniform1iEXT) +#define glProgramUniform1ivEXT MANGLE(ProgramUniform1ivEXT) +#define glProgramUniform1uiEXT MANGLE(ProgramUniform1uiEXT) +#define glProgramUniform1uivEXT MANGLE(ProgramUniform1uivEXT) +#define glProgramUniform2fEXT MANGLE(ProgramUniform2fEXT) +#define glProgramUniform2fvEXT MANGLE(ProgramUniform2fvEXT) +#define glProgramUniform2iEXT MANGLE(ProgramUniform2iEXT) +#define glProgramUniform2ivEXT MANGLE(ProgramUniform2ivEXT) +#define glProgramUniform2uiEXT MANGLE(ProgramUniform2uiEXT) +#define glProgramUniform2uivEXT MANGLE(ProgramUniform2uivEXT) +#define glProgramUniform3fEXT MANGLE(ProgramUniform3fEXT) +#define glProgramUniform3fvEXT MANGLE(ProgramUniform3fvEXT) +#define glProgramUniform3iEXT MANGLE(ProgramUniform3iEXT) +#define glProgramUniform3ivEXT MANGLE(ProgramUniform3ivEXT) +#define glProgramUniform3uiEXT MANGLE(ProgramUniform3uiEXT) +#define glProgramUniform3uivEXT MANGLE(ProgramUniform3uivEXT) +#define glProgramUniform4fEXT MANGLE(ProgramUniform4fEXT) +#define glProgramUniform4fvEXT MANGLE(ProgramUniform4fvEXT) +#define glProgramUniform4iEXT MANGLE(ProgramUniform4iEXT) +#define glProgramUniform4ivEXT MANGLE(ProgramUniform4ivEXT) +#define glProgramUniform4uiEXT MANGLE(ProgramUniform4uiEXT) +#define glProgramUniform4uivEXT MANGLE(ProgramUniform4uivEXT) +#define glProgramUniformMatrix2fvEXT MANGLE(ProgramUniformMatrix2fvEXT) +#define glProgramUniformMatrix2x3fvEXT MANGLE(ProgramUniformMatrix2x3fvEXT) +#define glProgramUniformMatrix2x4fvEXT MANGLE(ProgramUniformMatrix2x4fvEXT) +#define glProgramUniformMatrix3fvEXT MANGLE(ProgramUniformMatrix3fvEXT) +#define glProgramUniformMatrix3x2fvEXT MANGLE(ProgramUniformMatrix3x2fvEXT) +#define glProgramUniformMatrix3x4fvEXT MANGLE(ProgramUniformMatrix3x4fvEXT) +#define glProgramUniformMatrix4fvEXT MANGLE(ProgramUniformMatrix4fvEXT) +#define glProgramUniformMatrix4x2fvEXT MANGLE(ProgramUniformMatrix4x2fvEXT) +#define glProgramUniformMatrix4x3fvEXT MANGLE(ProgramUniformMatrix4x3fvEXT) +#define glProgramUniformui64NV MANGLE(ProgramUniformui64NV) +#define glProgramUniformui64vNV MANGLE(ProgramUniformui64vNV) +#define glProgramVertexLimitNV MANGLE(ProgramVertexLimitNV) +#define glProvokingVertexEXT MANGLE(ProvokingVertexEXT) +#define glProvokingVertex MANGLE(ProvokingVertex) +#define glPushAttrib MANGLE(PushAttrib) +#define glPushClientAttribDefaultEXT MANGLE(PushClientAttribDefaultEXT) +#define glPushClientAttrib MANGLE(PushClientAttrib) +#define glPushMatrix MANGLE(PushMatrix) +#define glPushName MANGLE(PushName) +#define glRasterPos2d MANGLE(RasterPos2d) +#define glRasterPos2dv MANGLE(RasterPos2dv) +#define glRasterPos2f MANGLE(RasterPos2f) +#define glRasterPos2fv MANGLE(RasterPos2fv) +#define glRasterPos2i MANGLE(RasterPos2i) +#define glRasterPos2iv MANGLE(RasterPos2iv) +#define glRasterPos2s MANGLE(RasterPos2s) +#define glRasterPos2sv MANGLE(RasterPos2sv) +#define glRasterPos3d MANGLE(RasterPos3d) +#define glRasterPos3dv MANGLE(RasterPos3dv) +#define glRasterPos3f MANGLE(RasterPos3f) +#define glRasterPos3fv MANGLE(RasterPos3fv) +#define glRasterPos3i MANGLE(RasterPos3i) +#define glRasterPos3iv MANGLE(RasterPos3iv) +#define glRasterPos3s MANGLE(RasterPos3s) +#define glRasterPos3sv MANGLE(RasterPos3sv) +#define glRasterPos4d MANGLE(RasterPos4d) +#define glRasterPos4dv MANGLE(RasterPos4dv) +#define glRasterPos4f MANGLE(RasterPos4f) +#define glRasterPos4fv MANGLE(RasterPos4fv) +#define glRasterPos4i MANGLE(RasterPos4i) +#define glRasterPos4iv MANGLE(RasterPos4iv) +#define glRasterPos4s MANGLE(RasterPos4s) +#define glRasterPos4sv MANGLE(RasterPos4sv) +#define glReadBuffer MANGLE(ReadBuffer) +#define glReadInstrumentsSGIX MANGLE(ReadInstrumentsSGIX) +#define glReadPixels MANGLE(ReadPixels) +#define glRectd MANGLE(Rectd) +#define glRectdv MANGLE(Rectdv) +#define glRectf MANGLE(Rectf) +#define glRectfv MANGLE(Rectfv) +#define glRecti MANGLE(Recti) +#define glRectiv MANGLE(Rectiv) +#define glRects MANGLE(Rects) +#define glRectsv MANGLE(Rectsv) +#define glReferencePlaneSGIX MANGLE(ReferencePlaneSGIX) +#define glRenderbufferStorageEXT MANGLE(RenderbufferStorageEXT) +#define glRenderbufferStorage MANGLE(RenderbufferStorage) +#define glRenderbufferStorageMultisampleCoverageNV MANGLE(RenderbufferStorageMultisampleCoverageNV) +#define glRenderbufferStorageMultisampleEXT MANGLE(RenderbufferStorageMultisampleEXT) +#define glRenderbufferStorageMultisample MANGLE(RenderbufferStorageMultisample) +#define glRenderMode MANGLE(RenderMode) +#define glReplacementCodePointerSUN MANGLE(ReplacementCodePointerSUN) +#define glReplacementCodeubSUN MANGLE(ReplacementCodeubSUN) +#define glReplacementCodeubvSUN MANGLE(ReplacementCodeubvSUN) +#define glReplacementCodeuiColor3fVertex3fSUN MANGLE(ReplacementCodeuiColor3fVertex3fSUN) +#define glReplacementCodeuiColor3fVertex3fvSUN MANGLE(ReplacementCodeuiColor3fVertex3fvSUN) +#define glReplacementCodeuiColor4fNormal3fVertex3fSUN MANGLE(ReplacementCodeuiColor4fNormal3fVertex3fSUN) +#define glReplacementCodeuiColor4fNormal3fVertex3fvSUN MANGLE(ReplacementCodeuiColor4fNormal3fVertex3fvSUN) +#define glReplacementCodeuiColor4ubVertex3fSUN MANGLE(ReplacementCodeuiColor4ubVertex3fSUN) +#define glReplacementCodeuiColor4ubVertex3fvSUN MANGLE(ReplacementCodeuiColor4ubVertex3fvSUN) +#define glReplacementCodeuiNormal3fVertex3fSUN MANGLE(ReplacementCodeuiNormal3fVertex3fSUN) +#define glReplacementCodeuiNormal3fVertex3fvSUN MANGLE(ReplacementCodeuiNormal3fVertex3fvSUN) +#define glReplacementCodeuiSUN MANGLE(ReplacementCodeuiSUN) +#define glReplacementCodeuiTexCoord2fColor4fNormal3fVertex3fSUN MANGLE(ReplacementCodeuiTexCoord2fColor4fNormal3fVertex3fSUN) +#define glReplacementCodeuiTexCoord2fColor4fNormal3fVertex3fvSUN MANGLE(ReplacementCodeuiTexCoord2fColor4fNormal3fVertex3fvSUN) +#define glReplacementCodeuiTexCoord2fNormal3fVertex3fSUN MANGLE(ReplacementCodeuiTexCoord2fNormal3fVertex3fSUN) +#define glReplacementCodeuiTexCoord2fNormal3fVertex3fvSUN MANGLE(ReplacementCodeuiTexCoord2fNormal3fVertex3fvSUN) +#define glReplacementCodeuiTexCoord2fVertex3fSUN MANGLE(ReplacementCodeuiTexCoord2fVertex3fSUN) +#define glReplacementCodeuiTexCoord2fVertex3fvSUN MANGLE(ReplacementCodeuiTexCoord2fVertex3fvSUN) +#define glReplacementCodeuiVertex3fSUN MANGLE(ReplacementCodeuiVertex3fSUN) +#define glReplacementCodeuiVertex3fvSUN MANGLE(ReplacementCodeuiVertex3fvSUN) +#define glReplacementCodeuivSUN MANGLE(ReplacementCodeuivSUN) +#define glReplacementCodeusSUN MANGLE(ReplacementCodeusSUN) +#define glReplacementCodeusvSUN MANGLE(ReplacementCodeusvSUN) +#define glRequestResidentProgramsNV MANGLE(RequestResidentProgramsNV) +#define glResetHistogramEXT MANGLE(ResetHistogramEXT) +#define glResetHistogram MANGLE(ResetHistogram) +#define glResetMinmaxEXT MANGLE(ResetMinmaxEXT) +#define glResetMinmax MANGLE(ResetMinmax) +#define glResizeBuffersMESA MANGLE(ResizeBuffersMESA) +#define glResumeTransformFeedbackNV MANGLE(ResumeTransformFeedbackNV) +#define glRotated MANGLE(Rotated) +#define glRotatef MANGLE(Rotatef) +#define glSampleCoverageARB MANGLE(SampleCoverageARB) +#define glSampleCoverage MANGLE(SampleCoverage) +#define glSampleMapATI MANGLE(SampleMapATI) +#define glSampleMaskEXT MANGLE(SampleMaskEXT) +#define glSampleMaski MANGLE(SampleMaski) +#define glSampleMaskIndexedNV MANGLE(SampleMaskIndexedNV) +#define glSampleMaskSGIS MANGLE(SampleMaskSGIS) +#define glSamplePatternEXT MANGLE(SamplePatternEXT) +#define glSamplePatternSGIS MANGLE(SamplePatternSGIS) +#define glScaled MANGLE(Scaled) +#define glScalef MANGLE(Scalef) +#define glScissor MANGLE(Scissor) +#define glSecondaryColor3bEXT MANGLE(SecondaryColor3bEXT) +#define glSecondaryColor3b MANGLE(SecondaryColor3b) +#define glSecondaryColor3bvEXT MANGLE(SecondaryColor3bvEXT) +#define glSecondaryColor3bv MANGLE(SecondaryColor3bv) +#define glSecondaryColor3dEXT MANGLE(SecondaryColor3dEXT) +#define glSecondaryColor3d MANGLE(SecondaryColor3d) +#define glSecondaryColor3dvEXT MANGLE(SecondaryColor3dvEXT) +#define glSecondaryColor3dv MANGLE(SecondaryColor3dv) +#define glSecondaryColor3fEXT MANGLE(SecondaryColor3fEXT) +#define glSecondaryColor3f MANGLE(SecondaryColor3f) +#define glSecondaryColor3fvEXT MANGLE(SecondaryColor3fvEXT) +#define glSecondaryColor3fv MANGLE(SecondaryColor3fv) +#define glSecondaryColor3hNV MANGLE(SecondaryColor3hNV) +#define glSecondaryColor3hvNV MANGLE(SecondaryColor3hvNV) +#define glSecondaryColor3iEXT MANGLE(SecondaryColor3iEXT) +#define glSecondaryColor3i MANGLE(SecondaryColor3i) +#define glSecondaryColor3ivEXT MANGLE(SecondaryColor3ivEXT) +#define glSecondaryColor3iv MANGLE(SecondaryColor3iv) +#define glSecondaryColor3sEXT MANGLE(SecondaryColor3sEXT) +#define glSecondaryColor3s MANGLE(SecondaryColor3s) +#define glSecondaryColor3svEXT MANGLE(SecondaryColor3svEXT) +#define glSecondaryColor3sv MANGLE(SecondaryColor3sv) +#define glSecondaryColor3ubEXT MANGLE(SecondaryColor3ubEXT) +#define glSecondaryColor3ub MANGLE(SecondaryColor3ub) +#define glSecondaryColor3ubvEXT MANGLE(SecondaryColor3ubvEXT) +#define glSecondaryColor3ubv MANGLE(SecondaryColor3ubv) +#define glSecondaryColor3uiEXT MANGLE(SecondaryColor3uiEXT) +#define glSecondaryColor3ui MANGLE(SecondaryColor3ui) +#define glSecondaryColor3uivEXT MANGLE(SecondaryColor3uivEXT) +#define glSecondaryColor3uiv MANGLE(SecondaryColor3uiv) +#define glSecondaryColor3usEXT MANGLE(SecondaryColor3usEXT) +#define glSecondaryColor3us MANGLE(SecondaryColor3us) +#define glSecondaryColor3usvEXT MANGLE(SecondaryColor3usvEXT) +#define glSecondaryColor3usv MANGLE(SecondaryColor3usv) +#define glSecondaryColorFormatNV MANGLE(SecondaryColorFormatNV) +#define glSecondaryColorPointerEXT MANGLE(SecondaryColorPointerEXT) +#define glSecondaryColorPointerListIBM MANGLE(SecondaryColorPointerListIBM) +#define glSecondaryColorPointer MANGLE(SecondaryColorPointer) +#define glSelectBuffer MANGLE(SelectBuffer) +#define glSelectPerfMonitorCountersAMD MANGLE(SelectPerfMonitorCountersAMD) +#define glSeparableFilter2DEXT MANGLE(SeparableFilter2DEXT) +#define glSeparableFilter2D MANGLE(SeparableFilter2D) +#define glSetFenceAPPLE MANGLE(SetFenceAPPLE) +#define glSetFenceNV MANGLE(SetFenceNV) +#define glSetFragmentShaderConstantATI MANGLE(SetFragmentShaderConstantATI) +#define glSetInvariantEXT MANGLE(SetInvariantEXT) +#define glSetLocalConstantEXT MANGLE(SetLocalConstantEXT) +#define glShadeModel MANGLE(ShadeModel) +#define glShaderOp1EXT MANGLE(ShaderOp1EXT) +#define glShaderOp2EXT MANGLE(ShaderOp2EXT) +#define glShaderOp3EXT MANGLE(ShaderOp3EXT) +#define glShaderSourceARB MANGLE(ShaderSourceARB) +#define glShaderSource MANGLE(ShaderSource) +#define glSharpenTexFuncSGIS MANGLE(SharpenTexFuncSGIS) +#define glSpriteParameterfSGIX MANGLE(SpriteParameterfSGIX) +#define glSpriteParameterfvSGIX MANGLE(SpriteParameterfvSGIX) +#define glSpriteParameteriSGIX MANGLE(SpriteParameteriSGIX) +#define glSpriteParameterivSGIX MANGLE(SpriteParameterivSGIX) +#define glStartInstrumentsSGIX MANGLE(StartInstrumentsSGIX) +#define glStencilClearTagEXT MANGLE(StencilClearTagEXT) +#define glStencilFunc MANGLE(StencilFunc) +#define glStencilFuncSeparateATI MANGLE(StencilFuncSeparateATI) +#define glStencilFuncSeparate MANGLE(StencilFuncSeparate) +#define glStencilMask MANGLE(StencilMask) +#define glStencilMaskSeparate MANGLE(StencilMaskSeparate) +#define glStencilOp MANGLE(StencilOp) +#define glStencilOpSeparateATI MANGLE(StencilOpSeparateATI) +#define glStencilOpSeparate MANGLE(StencilOpSeparate) +#define glStopInstrumentsSGIX MANGLE(StopInstrumentsSGIX) +#define glStringMarkerGREMEDY MANGLE(StringMarkerGREMEDY) +#define glSwizzleEXT MANGLE(SwizzleEXT) +#define glTagSampleBufferSGIX MANGLE(TagSampleBufferSGIX) +#define glTangent3bEXT MANGLE(Tangent3bEXT) +#define glTangent3bvEXT MANGLE(Tangent3bvEXT) +#define glTangent3dEXT MANGLE(Tangent3dEXT) +#define glTangent3dvEXT MANGLE(Tangent3dvEXT) +#define glTangent3fEXT MANGLE(Tangent3fEXT) +#define glTangent3fvEXT MANGLE(Tangent3fvEXT) +#define glTangent3iEXT MANGLE(Tangent3iEXT) +#define glTangent3ivEXT MANGLE(Tangent3ivEXT) +#define glTangent3sEXT MANGLE(Tangent3sEXT) +#define glTangent3svEXT MANGLE(Tangent3svEXT) +#define glTangentPointerEXT MANGLE(TangentPointerEXT) +#define glTbufferMask3DFX MANGLE(TbufferMask3DFX) +#define glTessellationFactorAMD MANGLE(TessellationFactorAMD) +#define glTessellationModeAMD MANGLE(TessellationModeAMD) +#define glTestFenceAPPLE MANGLE(TestFenceAPPLE) +#define glTestFenceNV MANGLE(TestFenceNV) +#define glTestObjectAPPLE MANGLE(TestObjectAPPLE) +#define glTexBufferARB MANGLE(TexBufferARB) +#define glTexBufferEXT MANGLE(TexBufferEXT) +#define glTexBuffer MANGLE(TexBuffer) +#define glTexBumpParameterfvATI MANGLE(TexBumpParameterfvATI) +#define glTexBumpParameterivATI MANGLE(TexBumpParameterivATI) +#define glTexCoord1d MANGLE(TexCoord1d) +#define glTexCoord1dv MANGLE(TexCoord1dv) +#define glTexCoord1f MANGLE(TexCoord1f) +#define glTexCoord1fv MANGLE(TexCoord1fv) +#define glTexCoord1hNV MANGLE(TexCoord1hNV) +#define glTexCoord1hvNV MANGLE(TexCoord1hvNV) +#define glTexCoord1i MANGLE(TexCoord1i) +#define glTexCoord1iv MANGLE(TexCoord1iv) +#define glTexCoord1s MANGLE(TexCoord1s) +#define glTexCoord1sv MANGLE(TexCoord1sv) +#define glTexCoord2d MANGLE(TexCoord2d) +#define glTexCoord2dv MANGLE(TexCoord2dv) +#define glTexCoord2fColor3fVertex3fSUN MANGLE(TexCoord2fColor3fVertex3fSUN) +#define glTexCoord2fColor3fVertex3fvSUN MANGLE(TexCoord2fColor3fVertex3fvSUN) +#define glTexCoord2fColor4fNormal3fVertex3fSUN MANGLE(TexCoord2fColor4fNormal3fVertex3fSUN) +#define glTexCoord2fColor4fNormal3fVertex3fvSUN MANGLE(TexCoord2fColor4fNormal3fVertex3fvSUN) +#define glTexCoord2fColor4ubVertex3fSUN MANGLE(TexCoord2fColor4ubVertex3fSUN) +#define glTexCoord2fColor4ubVertex3fvSUN MANGLE(TexCoord2fColor4ubVertex3fvSUN) +#define glTexCoord2f MANGLE(TexCoord2f) +#define glTexCoord2fNormal3fVertex3fSUN MANGLE(TexCoord2fNormal3fVertex3fSUN) +#define glTexCoord2fNormal3fVertex3fvSUN MANGLE(TexCoord2fNormal3fVertex3fvSUN) +#define glTexCoord2fVertex3fSUN MANGLE(TexCoord2fVertex3fSUN) +#define glTexCoord2fVertex3fvSUN MANGLE(TexCoord2fVertex3fvSUN) +#define glTexCoord2fv MANGLE(TexCoord2fv) +#define glTexCoord2hNV MANGLE(TexCoord2hNV) +#define glTexCoord2hvNV MANGLE(TexCoord2hvNV) +#define glTexCoord2i MANGLE(TexCoord2i) +#define glTexCoord2iv MANGLE(TexCoord2iv) +#define glTexCoord2s MANGLE(TexCoord2s) +#define glTexCoord2sv MANGLE(TexCoord2sv) +#define glTexCoord3d MANGLE(TexCoord3d) +#define glTexCoord3dv MANGLE(TexCoord3dv) +#define glTexCoord3f MANGLE(TexCoord3f) +#define glTexCoord3fv MANGLE(TexCoord3fv) +#define glTexCoord3hNV MANGLE(TexCoord3hNV) +#define glTexCoord3hvNV MANGLE(TexCoord3hvNV) +#define glTexCoord3i MANGLE(TexCoord3i) +#define glTexCoord3iv MANGLE(TexCoord3iv) +#define glTexCoord3s MANGLE(TexCoord3s) +#define glTexCoord3sv MANGLE(TexCoord3sv) +#define glTexCoord4d MANGLE(TexCoord4d) +#define glTexCoord4dv MANGLE(TexCoord4dv) +#define glTexCoord4fColor4fNormal3fVertex4fSUN MANGLE(TexCoord4fColor4fNormal3fVertex4fSUN) +#define glTexCoord4fColor4fNormal3fVertex4fvSUN MANGLE(TexCoord4fColor4fNormal3fVertex4fvSUN) +#define glTexCoord4f MANGLE(TexCoord4f) +#define glTexCoord4fVertex4fSUN MANGLE(TexCoord4fVertex4fSUN) +#define glTexCoord4fVertex4fvSUN MANGLE(TexCoord4fVertex4fvSUN) +#define glTexCoord4fv MANGLE(TexCoord4fv) +#define glTexCoord4hNV MANGLE(TexCoord4hNV) +#define glTexCoord4hvNV MANGLE(TexCoord4hvNV) +#define glTexCoord4i MANGLE(TexCoord4i) +#define glTexCoord4iv MANGLE(TexCoord4iv) +#define glTexCoord4s MANGLE(TexCoord4s) +#define glTexCoord4sv MANGLE(TexCoord4sv) +#define glTexCoordFormatNV MANGLE(TexCoordFormatNV) +#define glTexCoordPointerEXT MANGLE(TexCoordPointerEXT) +#define glTexCoordPointerListIBM MANGLE(TexCoordPointerListIBM) +#define glTexCoordPointer MANGLE(TexCoordPointer) +#define glTexCoordPointervINTEL MANGLE(TexCoordPointervINTEL) +#define glTexEnvf MANGLE(TexEnvf) +#define glTexEnvfv MANGLE(TexEnvfv) +#define glTexEnvi MANGLE(TexEnvi) +#define glTexEnviv MANGLE(TexEnviv) +#define glTexFilterFuncSGIS MANGLE(TexFilterFuncSGIS) +#define glTexGend MANGLE(TexGend) +#define glTexGendv MANGLE(TexGendv) +#define glTexGenf MANGLE(TexGenf) +#define glTexGenfv MANGLE(TexGenfv) +#define glTexGeni MANGLE(TexGeni) +#define glTexGeniv MANGLE(TexGeniv) +#define glTexImage1D MANGLE(TexImage1D) +#define glTexImage2D MANGLE(TexImage2D) +#define glTexImage2DMultisample MANGLE(TexImage2DMultisample) +#define glTexImage3DEXT MANGLE(TexImage3DEXT) +#define glTexImage3D MANGLE(TexImage3D) +#define glTexImage3DMultisample MANGLE(TexImage3DMultisample) +#define glTexImage4DSGIS MANGLE(TexImage4DSGIS) +#define glTexParameterf MANGLE(TexParameterf) +#define glTexParameterfv MANGLE(TexParameterfv) +#define glTexParameterIivEXT MANGLE(TexParameterIivEXT) +#define glTexParameterIiv MANGLE(TexParameterIiv) +#define glTexParameteri MANGLE(TexParameteri) +#define glTexParameterIuivEXT MANGLE(TexParameterIuivEXT) +#define glTexParameterIuiv MANGLE(TexParameterIuiv) +#define glTexParameteriv MANGLE(TexParameteriv) +#define glTexRenderbufferNV MANGLE(TexRenderbufferNV) +#define glTexSubImage1DEXT MANGLE(TexSubImage1DEXT) +#define glTexSubImage1D MANGLE(TexSubImage1D) +#define glTexSubImage2DEXT MANGLE(TexSubImage2DEXT) +#define glTexSubImage2D MANGLE(TexSubImage2D) +#define glTexSubImage3DEXT MANGLE(TexSubImage3DEXT) +#define glTexSubImage3D MANGLE(TexSubImage3D) +#define glTexSubImage4DSGIS MANGLE(TexSubImage4DSGIS) +#define glTextureBarrierNV MANGLE(TextureBarrierNV) +#define glTextureBufferEXT MANGLE(TextureBufferEXT) +#define glTextureColorMaskSGIS MANGLE(TextureColorMaskSGIS) +#define glTextureImage1DEXT MANGLE(TextureImage1DEXT) +#define glTextureImage2DEXT MANGLE(TextureImage2DEXT) +#define glTextureImage3DEXT MANGLE(TextureImage3DEXT) +#define glTextureLightEXT MANGLE(TextureLightEXT) +#define glTextureMaterialEXT MANGLE(TextureMaterialEXT) +#define glTextureNormalEXT MANGLE(TextureNormalEXT) +#define glTextureParameterfEXT MANGLE(TextureParameterfEXT) +#define glTextureParameterfvEXT MANGLE(TextureParameterfvEXT) +#define glTextureParameteriEXT MANGLE(TextureParameteriEXT) +#define glTextureParameterIivEXT MANGLE(TextureParameterIivEXT) +#define glTextureParameterIuivEXT MANGLE(TextureParameterIuivEXT) +#define glTextureParameterivEXT MANGLE(TextureParameterivEXT) +#define glTextureRangeAPPLE MANGLE(TextureRangeAPPLE) +#define glTextureRenderbufferEXT MANGLE(TextureRenderbufferEXT) +#define glTextureSubImage1DEXT MANGLE(TextureSubImage1DEXT) +#define glTextureSubImage2DEXT MANGLE(TextureSubImage2DEXT) +#define glTextureSubImage3DEXT MANGLE(TextureSubImage3DEXT) +#define glTrackMatrixNV MANGLE(TrackMatrixNV) +#define glTransformFeedbackAttribsNV MANGLE(TransformFeedbackAttribsNV) +#define glTransformFeedbackVaryingsEXT MANGLE(TransformFeedbackVaryingsEXT) +#define glTransformFeedbackVaryings MANGLE(TransformFeedbackVaryings) +#define glTransformFeedbackVaryingsNV MANGLE(TransformFeedbackVaryingsNV) +#define glTranslated MANGLE(Translated) +#define glTranslatef MANGLE(Translatef) +#define glUniform1fARB MANGLE(Uniform1fARB) +#define glUniform1f MANGLE(Uniform1f) +#define glUniform1fvARB MANGLE(Uniform1fvARB) +#define glUniform1fv MANGLE(Uniform1fv) +#define glUniform1iARB MANGLE(Uniform1iARB) +#define glUniform1i MANGLE(Uniform1i) +#define glUniform1ivARB MANGLE(Uniform1ivARB) +#define glUniform1iv MANGLE(Uniform1iv) +#define glUniform1uiEXT MANGLE(Uniform1uiEXT) +#define glUniform1ui MANGLE(Uniform1ui) +#define glUniform1uivEXT MANGLE(Uniform1uivEXT) +#define glUniform1uiv MANGLE(Uniform1uiv) +#define glUniform2fARB MANGLE(Uniform2fARB) +#define glUniform2f MANGLE(Uniform2f) +#define glUniform2fvARB MANGLE(Uniform2fvARB) +#define glUniform2fv MANGLE(Uniform2fv) +#define glUniform2iARB MANGLE(Uniform2iARB) +#define glUniform2i MANGLE(Uniform2i) +#define glUniform2ivARB MANGLE(Uniform2ivARB) +#define glUniform2iv MANGLE(Uniform2iv) +#define glUniform2uiEXT MANGLE(Uniform2uiEXT) +#define glUniform2ui MANGLE(Uniform2ui) +#define glUniform2uivEXT MANGLE(Uniform2uivEXT) +#define glUniform2uiv MANGLE(Uniform2uiv) +#define glUniform3fARB MANGLE(Uniform3fARB) +#define glUniform3f MANGLE(Uniform3f) +#define glUniform3fvARB MANGLE(Uniform3fvARB) +#define glUniform3fv MANGLE(Uniform3fv) +#define glUniform3iARB MANGLE(Uniform3iARB) +#define glUniform3i MANGLE(Uniform3i) +#define glUniform3ivARB MANGLE(Uniform3ivARB) +#define glUniform3iv MANGLE(Uniform3iv) +#define glUniform3uiEXT MANGLE(Uniform3uiEXT) +#define glUniform3ui MANGLE(Uniform3ui) +#define glUniform3uivEXT MANGLE(Uniform3uivEXT) +#define glUniform3uiv MANGLE(Uniform3uiv) +#define glUniform4fARB MANGLE(Uniform4fARB) +#define glUniform4f MANGLE(Uniform4f) +#define glUniform4fvARB MANGLE(Uniform4fvARB) +#define glUniform4fv MANGLE(Uniform4fv) +#define glUniform4iARB MANGLE(Uniform4iARB) +#define glUniform4i MANGLE(Uniform4i) +#define glUniform4ivARB MANGLE(Uniform4ivARB) +#define glUniform4iv MANGLE(Uniform4iv) +#define glUniform4uiEXT MANGLE(Uniform4uiEXT) +#define glUniform4ui MANGLE(Uniform4ui) +#define glUniform4uivEXT MANGLE(Uniform4uivEXT) +#define glUniform4uiv MANGLE(Uniform4uiv) +#define glUniformBlockBinding MANGLE(UniformBlockBinding) +#define glUniformBufferEXT MANGLE(UniformBufferEXT) +#define glUniformMatrix2fvARB MANGLE(UniformMatrix2fvARB) +#define glUniformMatrix2fv MANGLE(UniformMatrix2fv) +#define glUniformMatrix2x3fv MANGLE(UniformMatrix2x3fv) +#define glUniformMatrix2x4fv MANGLE(UniformMatrix2x4fv) +#define glUniformMatrix3fvARB MANGLE(UniformMatrix3fvARB) +#define glUniformMatrix3fv MANGLE(UniformMatrix3fv) +#define glUniformMatrix3x2fv MANGLE(UniformMatrix3x2fv) +#define glUniformMatrix3x4fv MANGLE(UniformMatrix3x4fv) +#define glUniformMatrix4fvARB MANGLE(UniformMatrix4fvARB) +#define glUniformMatrix4fv MANGLE(UniformMatrix4fv) +#define glUniformMatrix4x2fv MANGLE(UniformMatrix4x2fv) +#define glUniformMatrix4x3fv MANGLE(UniformMatrix4x3fv) +#define glUniformui64NV MANGLE(Uniformui64NV) +#define glUniformui64vNV MANGLE(Uniformui64vNV) +#define glUnlockArraysEXT MANGLE(UnlockArraysEXT) +#define glUnmapBufferARB MANGLE(UnmapBufferARB) +#define glUnmapBuffer MANGLE(UnmapBuffer) +#define glUnmapNamedBufferEXT MANGLE(UnmapNamedBufferEXT) +#define glUnmapObjectBufferATI MANGLE(UnmapObjectBufferATI) +#define glUpdateObjectBufferATI MANGLE(UpdateObjectBufferATI) +#define glUseProgram MANGLE(UseProgram) +#define glUseProgramObjectARB MANGLE(UseProgramObjectARB) +#define glUseShaderProgramEXT MANGLE(UseShaderProgramEXT) +#define glValidateProgramARB MANGLE(ValidateProgramARB) +#define glValidateProgram MANGLE(ValidateProgram) +#define glVariantArrayObjectATI MANGLE(VariantArrayObjectATI) +#define glVariantbvEXT MANGLE(VariantbvEXT) +#define glVariantdvEXT MANGLE(VariantdvEXT) +#define glVariantfvEXT MANGLE(VariantfvEXT) +#define glVariantivEXT MANGLE(VariantivEXT) +#define glVariantPointerEXT MANGLE(VariantPointerEXT) +#define glVariantsvEXT MANGLE(VariantsvEXT) +#define glVariantubvEXT MANGLE(VariantubvEXT) +#define glVariantuivEXT MANGLE(VariantuivEXT) +#define glVariantusvEXT MANGLE(VariantusvEXT) +#define glVertex2d MANGLE(Vertex2d) +#define glVertex2dv MANGLE(Vertex2dv) +#define glVertex2f MANGLE(Vertex2f) +#define glVertex2fv MANGLE(Vertex2fv) +#define glVertex2hNV MANGLE(Vertex2hNV) +#define glVertex2hvNV MANGLE(Vertex2hvNV) +#define glVertex2i MANGLE(Vertex2i) +#define glVertex2iv MANGLE(Vertex2iv) +#define glVertex2s MANGLE(Vertex2s) +#define glVertex2sv MANGLE(Vertex2sv) +#define glVertex3d MANGLE(Vertex3d) +#define glVertex3dv MANGLE(Vertex3dv) +#define glVertex3f MANGLE(Vertex3f) +#define glVertex3fv MANGLE(Vertex3fv) +#define glVertex3hNV MANGLE(Vertex3hNV) +#define glVertex3hvNV MANGLE(Vertex3hvNV) +#define glVertex3i MANGLE(Vertex3i) +#define glVertex3iv MANGLE(Vertex3iv) +#define glVertex3s MANGLE(Vertex3s) +#define glVertex3sv MANGLE(Vertex3sv) +#define glVertex4d MANGLE(Vertex4d) +#define glVertex4dv MANGLE(Vertex4dv) +#define glVertex4f MANGLE(Vertex4f) +#define glVertex4fv MANGLE(Vertex4fv) +#define glVertex4hNV MANGLE(Vertex4hNV) +#define glVertex4hvNV MANGLE(Vertex4hvNV) +#define glVertex4i MANGLE(Vertex4i) +#define glVertex4iv MANGLE(Vertex4iv) +#define glVertex4s MANGLE(Vertex4s) +#define glVertex4sv MANGLE(Vertex4sv) +#define glVertexArrayParameteriAPPLE MANGLE(VertexArrayParameteriAPPLE) +#define glVertexArrayRangeAPPLE MANGLE(VertexArrayRangeAPPLE) +#define glVertexArrayRangeNV MANGLE(VertexArrayRangeNV) +#define glVertexAttrib1dARB MANGLE(VertexAttrib1dARB) +#define glVertexAttrib1d MANGLE(VertexAttrib1d) +#define glVertexAttrib1dNV MANGLE(VertexAttrib1dNV) +#define glVertexAttrib1dvARB MANGLE(VertexAttrib1dvARB) +#define glVertexAttrib1dv MANGLE(VertexAttrib1dv) +#define glVertexAttrib1dvNV MANGLE(VertexAttrib1dvNV) +#define glVertexAttrib1fARB MANGLE(VertexAttrib1fARB) +#define glVertexAttrib1f MANGLE(VertexAttrib1f) +#define glVertexAttrib1fNV MANGLE(VertexAttrib1fNV) +#define glVertexAttrib1fvARB MANGLE(VertexAttrib1fvARB) +#define glVertexAttrib1fv MANGLE(VertexAttrib1fv) +#define glVertexAttrib1fvNV MANGLE(VertexAttrib1fvNV) +#define glVertexAttrib1hNV MANGLE(VertexAttrib1hNV) +#define glVertexAttrib1hvNV MANGLE(VertexAttrib1hvNV) +#define glVertexAttrib1sARB MANGLE(VertexAttrib1sARB) +#define glVertexAttrib1s MANGLE(VertexAttrib1s) +#define glVertexAttrib1sNV MANGLE(VertexAttrib1sNV) +#define glVertexAttrib1svARB MANGLE(VertexAttrib1svARB) +#define glVertexAttrib1sv MANGLE(VertexAttrib1sv) +#define glVertexAttrib1svNV MANGLE(VertexAttrib1svNV) +#define glVertexAttrib2dARB MANGLE(VertexAttrib2dARB) +#define glVertexAttrib2d MANGLE(VertexAttrib2d) +#define glVertexAttrib2dNV MANGLE(VertexAttrib2dNV) +#define glVertexAttrib2dvARB MANGLE(VertexAttrib2dvARB) +#define glVertexAttrib2dv MANGLE(VertexAttrib2dv) +#define glVertexAttrib2dvNV MANGLE(VertexAttrib2dvNV) +#define glVertexAttrib2fARB MANGLE(VertexAttrib2fARB) +#define glVertexAttrib2f MANGLE(VertexAttrib2f) +#define glVertexAttrib2fNV MANGLE(VertexAttrib2fNV) +#define glVertexAttrib2fvARB MANGLE(VertexAttrib2fvARB) +#define glVertexAttrib2fv MANGLE(VertexAttrib2fv) +#define glVertexAttrib2fvNV MANGLE(VertexAttrib2fvNV) +#define glVertexAttrib2hNV MANGLE(VertexAttrib2hNV) +#define glVertexAttrib2hvNV MANGLE(VertexAttrib2hvNV) +#define glVertexAttrib2sARB MANGLE(VertexAttrib2sARB) +#define glVertexAttrib2s MANGLE(VertexAttrib2s) +#define glVertexAttrib2sNV MANGLE(VertexAttrib2sNV) +#define glVertexAttrib2svARB MANGLE(VertexAttrib2svARB) +#define glVertexAttrib2sv MANGLE(VertexAttrib2sv) +#define glVertexAttrib2svNV MANGLE(VertexAttrib2svNV) +#define glVertexAttrib3dARB MANGLE(VertexAttrib3dARB) +#define glVertexAttrib3d MANGLE(VertexAttrib3d) +#define glVertexAttrib3dNV MANGLE(VertexAttrib3dNV) +#define glVertexAttrib3dvARB MANGLE(VertexAttrib3dvARB) +#define glVertexAttrib3dv MANGLE(VertexAttrib3dv) +#define glVertexAttrib3dvNV MANGLE(VertexAttrib3dvNV) +#define glVertexAttrib3fARB MANGLE(VertexAttrib3fARB) +#define glVertexAttrib3f MANGLE(VertexAttrib3f) +#define glVertexAttrib3fNV MANGLE(VertexAttrib3fNV) +#define glVertexAttrib3fvARB MANGLE(VertexAttrib3fvARB) +#define glVertexAttrib3fv MANGLE(VertexAttrib3fv) +#define glVertexAttrib3fvNV MANGLE(VertexAttrib3fvNV) +#define glVertexAttrib3hNV MANGLE(VertexAttrib3hNV) +#define glVertexAttrib3hvNV MANGLE(VertexAttrib3hvNV) +#define glVertexAttrib3sARB MANGLE(VertexAttrib3sARB) +#define glVertexAttrib3s MANGLE(VertexAttrib3s) +#define glVertexAttrib3sNV MANGLE(VertexAttrib3sNV) +#define glVertexAttrib3svARB MANGLE(VertexAttrib3svARB) +#define glVertexAttrib3sv MANGLE(VertexAttrib3sv) +#define glVertexAttrib3svNV MANGLE(VertexAttrib3svNV) +#define glVertexAttrib4bvARB MANGLE(VertexAttrib4bvARB) +#define glVertexAttrib4bv MANGLE(VertexAttrib4bv) +#define glVertexAttrib4dARB MANGLE(VertexAttrib4dARB) +#define glVertexAttrib4d MANGLE(VertexAttrib4d) +#define glVertexAttrib4dNV MANGLE(VertexAttrib4dNV) +#define glVertexAttrib4dvARB MANGLE(VertexAttrib4dvARB) +#define glVertexAttrib4dv MANGLE(VertexAttrib4dv) +#define glVertexAttrib4dvNV MANGLE(VertexAttrib4dvNV) +#define glVertexAttrib4fARB MANGLE(VertexAttrib4fARB) +#define glVertexAttrib4f MANGLE(VertexAttrib4f) +#define glVertexAttrib4fNV MANGLE(VertexAttrib4fNV) +#define glVertexAttrib4fvARB MANGLE(VertexAttrib4fvARB) +#define glVertexAttrib4fv MANGLE(VertexAttrib4fv) +#define glVertexAttrib4fvNV MANGLE(VertexAttrib4fvNV) +#define glVertexAttrib4hNV MANGLE(VertexAttrib4hNV) +#define glVertexAttrib4hvNV MANGLE(VertexAttrib4hvNV) +#define glVertexAttrib4ivARB MANGLE(VertexAttrib4ivARB) +#define glVertexAttrib4iv MANGLE(VertexAttrib4iv) +#define glVertexAttrib4NbvARB MANGLE(VertexAttrib4NbvARB) +#define glVertexAttrib4Nbv MANGLE(VertexAttrib4Nbv) +#define glVertexAttrib4NivARB MANGLE(VertexAttrib4NivARB) +#define glVertexAttrib4Niv MANGLE(VertexAttrib4Niv) +#define glVertexAttrib4NsvARB MANGLE(VertexAttrib4NsvARB) +#define glVertexAttrib4Nsv MANGLE(VertexAttrib4Nsv) +#define glVertexAttrib4NubARB MANGLE(VertexAttrib4NubARB) +#define glVertexAttrib4Nub MANGLE(VertexAttrib4Nub) +#define glVertexAttrib4NubvARB MANGLE(VertexAttrib4NubvARB) +#define glVertexAttrib4Nubv MANGLE(VertexAttrib4Nubv) +#define glVertexAttrib4NuivARB MANGLE(VertexAttrib4NuivARB) +#define glVertexAttrib4Nuiv MANGLE(VertexAttrib4Nuiv) +#define glVertexAttrib4NusvARB MANGLE(VertexAttrib4NusvARB) +#define glVertexAttrib4Nusv MANGLE(VertexAttrib4Nusv) +#define glVertexAttrib4sARB MANGLE(VertexAttrib4sARB) +#define glVertexAttrib4s MANGLE(VertexAttrib4s) +#define glVertexAttrib4sNV MANGLE(VertexAttrib4sNV) +#define glVertexAttrib4svARB MANGLE(VertexAttrib4svARB) +#define glVertexAttrib4sv MANGLE(VertexAttrib4sv) +#define glVertexAttrib4svNV MANGLE(VertexAttrib4svNV) +#define glVertexAttrib4ubNV MANGLE(VertexAttrib4ubNV) +#define glVertexAttrib4ubvARB MANGLE(VertexAttrib4ubvARB) +#define glVertexAttrib4ubv MANGLE(VertexAttrib4ubv) +#define glVertexAttrib4ubvNV MANGLE(VertexAttrib4ubvNV) +#define glVertexAttrib4uivARB MANGLE(VertexAttrib4uivARB) +#define glVertexAttrib4uiv MANGLE(VertexAttrib4uiv) +#define glVertexAttrib4usvARB MANGLE(VertexAttrib4usvARB) +#define glVertexAttrib4usv MANGLE(VertexAttrib4usv) +#define glVertexAttribArrayObjectATI MANGLE(VertexAttribArrayObjectATI) +#define glVertexAttribDivisorARB MANGLE(VertexAttribDivisorARB) +#define glVertexAttribFormatNV MANGLE(VertexAttribFormatNV) +#define glVertexAttribI1iEXT MANGLE(VertexAttribI1iEXT) +#define glVertexAttribI1i MANGLE(VertexAttribI1i) +#define glVertexAttribI1ivEXT MANGLE(VertexAttribI1ivEXT) +#define glVertexAttribI1iv MANGLE(VertexAttribI1iv) +#define glVertexAttribI1uiEXT MANGLE(VertexAttribI1uiEXT) +#define glVertexAttribI1ui MANGLE(VertexAttribI1ui) +#define glVertexAttribI1uivEXT MANGLE(VertexAttribI1uivEXT) +#define glVertexAttribI1uiv MANGLE(VertexAttribI1uiv) +#define glVertexAttribI2iEXT MANGLE(VertexAttribI2iEXT) +#define glVertexAttribI2i MANGLE(VertexAttribI2i) +#define glVertexAttribI2ivEXT MANGLE(VertexAttribI2ivEXT) +#define glVertexAttribI2iv MANGLE(VertexAttribI2iv) +#define glVertexAttribI2uiEXT MANGLE(VertexAttribI2uiEXT) +#define glVertexAttribI2ui MANGLE(VertexAttribI2ui) +#define glVertexAttribI2uivEXT MANGLE(VertexAttribI2uivEXT) +#define glVertexAttribI2uiv MANGLE(VertexAttribI2uiv) +#define glVertexAttribI3iEXT MANGLE(VertexAttribI3iEXT) +#define glVertexAttribI3i MANGLE(VertexAttribI3i) +#define glVertexAttribI3ivEXT MANGLE(VertexAttribI3ivEXT) +#define glVertexAttribI3iv MANGLE(VertexAttribI3iv) +#define glVertexAttribI3uiEXT MANGLE(VertexAttribI3uiEXT) +#define glVertexAttribI3ui MANGLE(VertexAttribI3ui) +#define glVertexAttribI3uivEXT MANGLE(VertexAttribI3uivEXT) +#define glVertexAttribI3uiv MANGLE(VertexAttribI3uiv) +#define glVertexAttribI4bvEXT MANGLE(VertexAttribI4bvEXT) +#define glVertexAttribI4bv MANGLE(VertexAttribI4bv) +#define glVertexAttribI4iEXT MANGLE(VertexAttribI4iEXT) +#define glVertexAttribI4i MANGLE(VertexAttribI4i) +#define glVertexAttribI4ivEXT MANGLE(VertexAttribI4ivEXT) +#define glVertexAttribI4iv MANGLE(VertexAttribI4iv) +#define glVertexAttribI4svEXT MANGLE(VertexAttribI4svEXT) +#define glVertexAttribI4sv MANGLE(VertexAttribI4sv) +#define glVertexAttribI4ubvEXT MANGLE(VertexAttribI4ubvEXT) +#define glVertexAttribI4ubv MANGLE(VertexAttribI4ubv) +#define glVertexAttribI4uiEXT MANGLE(VertexAttribI4uiEXT) +#define glVertexAttribI4ui MANGLE(VertexAttribI4ui) +#define glVertexAttribI4uivEXT MANGLE(VertexAttribI4uivEXT) +#define glVertexAttribI4uiv MANGLE(VertexAttribI4uiv) +#define glVertexAttribI4usvEXT MANGLE(VertexAttribI4usvEXT) +#define glVertexAttribI4usv MANGLE(VertexAttribI4usv) +#define glVertexAttribIFormatNV MANGLE(VertexAttribIFormatNV) +#define glVertexAttribIPointerEXT MANGLE(VertexAttribIPointerEXT) +#define glVertexAttribIPointer MANGLE(VertexAttribIPointer) +#define glVertexAttribPointerARB MANGLE(VertexAttribPointerARB) +#define glVertexAttribPointer MANGLE(VertexAttribPointer) +#define glVertexAttribPointerNV MANGLE(VertexAttribPointerNV) +#define glVertexAttribs1dvNV MANGLE(VertexAttribs1dvNV) +#define glVertexAttribs1fvNV MANGLE(VertexAttribs1fvNV) +#define glVertexAttribs1hvNV MANGLE(VertexAttribs1hvNV) +#define glVertexAttribs1svNV MANGLE(VertexAttribs1svNV) +#define glVertexAttribs2dvNV MANGLE(VertexAttribs2dvNV) +#define glVertexAttribs2fvNV MANGLE(VertexAttribs2fvNV) +#define glVertexAttribs2hvNV MANGLE(VertexAttribs2hvNV) +#define glVertexAttribs2svNV MANGLE(VertexAttribs2svNV) +#define glVertexAttribs3dvNV MANGLE(VertexAttribs3dvNV) +#define glVertexAttribs3fvNV MANGLE(VertexAttribs3fvNV) +#define glVertexAttribs3hvNV MANGLE(VertexAttribs3hvNV) +#define glVertexAttribs3svNV MANGLE(VertexAttribs3svNV) +#define glVertexAttribs4dvNV MANGLE(VertexAttribs4dvNV) +#define glVertexAttribs4fvNV MANGLE(VertexAttribs4fvNV) +#define glVertexAttribs4hvNV MANGLE(VertexAttribs4hvNV) +#define glVertexAttribs4svNV MANGLE(VertexAttribs4svNV) +#define glVertexAttribs4ubvNV MANGLE(VertexAttribs4ubvNV) +#define glVertexBlendARB MANGLE(VertexBlendARB) +#define glVertexBlendEnvfATI MANGLE(VertexBlendEnvfATI) +#define glVertexBlendEnviATI MANGLE(VertexBlendEnviATI) +#define glVertexFormatNV MANGLE(VertexFormatNV) +#define glVertexPointerEXT MANGLE(VertexPointerEXT) +#define glVertexPointerListIBM MANGLE(VertexPointerListIBM) +#define glVertexPointer MANGLE(VertexPointer) +#define glVertexPointervINTEL MANGLE(VertexPointervINTEL) +#define glVertexStream1dATI MANGLE(VertexStream1dATI) +#define glVertexStream1dvATI MANGLE(VertexStream1dvATI) +#define glVertexStream1fATI MANGLE(VertexStream1fATI) +#define glVertexStream1fvATI MANGLE(VertexStream1fvATI) +#define glVertexStream1iATI MANGLE(VertexStream1iATI) +#define glVertexStream1ivATI MANGLE(VertexStream1ivATI) +#define glVertexStream1sATI MANGLE(VertexStream1sATI) +#define glVertexStream1svATI MANGLE(VertexStream1svATI) +#define glVertexStream2dATI MANGLE(VertexStream2dATI) +#define glVertexStream2dvATI MANGLE(VertexStream2dvATI) +#define glVertexStream2fATI MANGLE(VertexStream2fATI) +#define glVertexStream2fvATI MANGLE(VertexStream2fvATI) +#define glVertexStream2iATI MANGLE(VertexStream2iATI) +#define glVertexStream2ivATI MANGLE(VertexStream2ivATI) +#define glVertexStream2sATI MANGLE(VertexStream2sATI) +#define glVertexStream2svATI MANGLE(VertexStream2svATI) +#define glVertexStream3dATI MANGLE(VertexStream3dATI) +#define glVertexStream3dvATI MANGLE(VertexStream3dvATI) +#define glVertexStream3fATI MANGLE(VertexStream3fATI) +#define glVertexStream3fvATI MANGLE(VertexStream3fvATI) +#define glVertexStream3iATI MANGLE(VertexStream3iATI) +#define glVertexStream3ivATI MANGLE(VertexStream3ivATI) +#define glVertexStream3sATI MANGLE(VertexStream3sATI) +#define glVertexStream3svATI MANGLE(VertexStream3svATI) +#define glVertexStream4dATI MANGLE(VertexStream4dATI) +#define glVertexStream4dvATI MANGLE(VertexStream4dvATI) +#define glVertexStream4fATI MANGLE(VertexStream4fATI) +#define glVertexStream4fvATI MANGLE(VertexStream4fvATI) +#define glVertexStream4iATI MANGLE(VertexStream4iATI) +#define glVertexStream4ivATI MANGLE(VertexStream4ivATI) +#define glVertexStream4sATI MANGLE(VertexStream4sATI) +#define glVertexStream4svATI MANGLE(VertexStream4svATI) +#define glVertexWeightfEXT MANGLE(VertexWeightfEXT) +#define glVertexWeightfvEXT MANGLE(VertexWeightfvEXT) +#define glVertexWeighthNV MANGLE(VertexWeighthNV) +#define glVertexWeighthvNV MANGLE(VertexWeighthvNV) +#define glVertexWeightPointerEXT MANGLE(VertexWeightPointerEXT) +#define glVideoCaptureNV MANGLE(VideoCaptureNV) +#define glVideoCaptureStreamParameterdvNV MANGLE(VideoCaptureStreamParameterdvNV) +#define glVideoCaptureStreamParameterfvNV MANGLE(VideoCaptureStreamParameterfvNV) +#define glVideoCaptureStreamParameterivNV MANGLE(VideoCaptureStreamParameterivNV) +#define glViewport MANGLE(Viewport) +#define glWaitSync MANGLE(WaitSync) +#define glWeightbvARB MANGLE(WeightbvARB) +#define glWeightdvARB MANGLE(WeightdvARB) +#define glWeightfvARB MANGLE(WeightfvARB) +#define glWeightivARB MANGLE(WeightivARB) +#define glWeightPointerARB MANGLE(WeightPointerARB) +#define glWeightsvARB MANGLE(WeightsvARB) +#define glWeightubvARB MANGLE(WeightubvARB) +#define glWeightuivARB MANGLE(WeightuivARB) +#define glWeightusvARB MANGLE(WeightusvARB) +#define glWindowPos2dARB MANGLE(WindowPos2dARB) +#define glWindowPos2d MANGLE(WindowPos2d) +#define glWindowPos2dMESA MANGLE(WindowPos2dMESA) +#define glWindowPos2dvARB MANGLE(WindowPos2dvARB) +#define glWindowPos2dv MANGLE(WindowPos2dv) +#define glWindowPos2dvMESA MANGLE(WindowPos2dvMESA) +#define glWindowPos2fARB MANGLE(WindowPos2fARB) +#define glWindowPos2f MANGLE(WindowPos2f) +#define glWindowPos2fMESA MANGLE(WindowPos2fMESA) +#define glWindowPos2fvARB MANGLE(WindowPos2fvARB) +#define glWindowPos2fv MANGLE(WindowPos2fv) +#define glWindowPos2fvMESA MANGLE(WindowPos2fvMESA) +#define glWindowPos2iARB MANGLE(WindowPos2iARB) +#define glWindowPos2i MANGLE(WindowPos2i) +#define glWindowPos2iMESA MANGLE(WindowPos2iMESA) +#define glWindowPos2ivARB MANGLE(WindowPos2ivARB) +#define glWindowPos2iv MANGLE(WindowPos2iv) +#define glWindowPos2ivMESA MANGLE(WindowPos2ivMESA) +#define glWindowPos2sARB MANGLE(WindowPos2sARB) +#define glWindowPos2s MANGLE(WindowPos2s) +#define glWindowPos2sMESA MANGLE(WindowPos2sMESA) +#define glWindowPos2svARB MANGLE(WindowPos2svARB) +#define glWindowPos2sv MANGLE(WindowPos2sv) +#define glWindowPos2svMESA MANGLE(WindowPos2svMESA) +#define glWindowPos3dARB MANGLE(WindowPos3dARB) +#define glWindowPos3d MANGLE(WindowPos3d) +#define glWindowPos3dMESA MANGLE(WindowPos3dMESA) +#define glWindowPos3dvARB MANGLE(WindowPos3dvARB) +#define glWindowPos3dv MANGLE(WindowPos3dv) +#define glWindowPos3dvMESA MANGLE(WindowPos3dvMESA) +#define glWindowPos3fARB MANGLE(WindowPos3fARB) +#define glWindowPos3f MANGLE(WindowPos3f) +#define glWindowPos3fMESA MANGLE(WindowPos3fMESA) +#define glWindowPos3fvARB MANGLE(WindowPos3fvARB) +#define glWindowPos3fv MANGLE(WindowPos3fv) +#define glWindowPos3fvMESA MANGLE(WindowPos3fvMESA) +#define glWindowPos3iARB MANGLE(WindowPos3iARB) +#define glWindowPos3i MANGLE(WindowPos3i) +#define glWindowPos3iMESA MANGLE(WindowPos3iMESA) +#define glWindowPos3ivARB MANGLE(WindowPos3ivARB) +#define glWindowPos3iv MANGLE(WindowPos3iv) +#define glWindowPos3ivMESA MANGLE(WindowPos3ivMESA) +#define glWindowPos3sARB MANGLE(WindowPos3sARB) +#define glWindowPos3s MANGLE(WindowPos3s) +#define glWindowPos3sMESA MANGLE(WindowPos3sMESA) +#define glWindowPos3svARB MANGLE(WindowPos3svARB) +#define glWindowPos3sv MANGLE(WindowPos3sv) +#define glWindowPos3svMESA MANGLE(WindowPos3svMESA) +#define glWindowPos4dMESA MANGLE(WindowPos4dMESA) +#define glWindowPos4dvMESA MANGLE(WindowPos4dvMESA) +#define glWindowPos4fMESA MANGLE(WindowPos4fMESA) +#define glWindowPos4fvMESA MANGLE(WindowPos4fvMESA) +#define glWindowPos4iMESA MANGLE(WindowPos4iMESA) +#define glWindowPos4ivMESA MANGLE(WindowPos4ivMESA) +#define glWindowPos4sMESA MANGLE(WindowPos4sMESA) +#define glWindowPos4svMESA MANGLE(WindowPos4svMESA) +#define glWriteMaskEXT MANGLE(WriteMaskEXT) + +#endif /* GL_MANGLE_H */ diff --git a/Projects/Android/jni/SupportLibs/gl4es/include/GL/glext.h b/Projects/Android/jni/SupportLibs/gl4es/include/GL/glext.h new file mode 100644 index 0000000..22348a1 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/include/GL/glext.h @@ -0,0 +1,11028 @@ +#ifndef __glext_h_ +#define __glext_h_ + +#ifdef __cplusplus +extern "C" { +#endif + +/* +** Copyright (c) 2007-2010 The Khronos Group Inc. +** +** Permission is hereby granted, free of charge, to any person obtaining a +** copy of this software and/or associated documentation files (the +** "Materials"), to deal in the Materials without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Materials, and to +** permit persons to whom the Materials are furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be included +** in all copies or substantial portions of the Materials. +** +** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. +*/ + +/* Header file version number, required by OpenGL ABI for Linux */ +/* glext.h last updated $Date: 2010-08-03 01:30:25 -0700 (Tue, 03 Aug 2010) $ */ +/* Current version at http://www.opengl.org/registry/ */ +#define GL_GLEXT_VERSION 64 +/* Function declaration macros - to move into glplatform.h */ + +#if defined(_WIN32) && !defined(APIENTRY) && !defined(__CYGWIN__) && !defined(__SCITECH_SNAP__) +#define WIN32_LEAN_AND_MEAN 1 +#include +#endif + +#ifndef APIENTRY +#define APIENTRY +#endif +#ifndef APIENTRYP +#define APIENTRYP APIENTRY * +#endif +#ifndef GLAPI +#define GLAPI extern +#endif + +/*************************************************************/ + +#ifndef GL_VERSION_1_2 +#define GL_UNSIGNED_BYTE_3_3_2 0x8032 +#define GL_UNSIGNED_SHORT_4_4_4_4 0x8033 +#define GL_UNSIGNED_SHORT_5_5_5_1 0x8034 +#define GL_UNSIGNED_INT_8_8_8_8 0x8035 +#define GL_UNSIGNED_INT_10_10_10_2 0x8036 +#define GL_TEXTURE_BINDING_3D 0x806A +#define GL_PACK_SKIP_IMAGES 0x806B +#define GL_PACK_IMAGE_HEIGHT 0x806C +#define GL_UNPACK_SKIP_IMAGES 0x806D +#define GL_UNPACK_IMAGE_HEIGHT 0x806E +#define GL_TEXTURE_3D 0x806F +#define GL_PROXY_TEXTURE_3D 0x8070 +#define GL_TEXTURE_DEPTH 0x8071 +#define GL_TEXTURE_WRAP_R 0x8072 +#define GL_MAX_3D_TEXTURE_SIZE 0x8073 +#define GL_UNSIGNED_BYTE_2_3_3_REV 0x8362 +#define GL_UNSIGNED_SHORT_5_6_5 0x8363 +#define GL_UNSIGNED_SHORT_5_6_5_REV 0x8364 +#define GL_UNSIGNED_SHORT_4_4_4_4_REV 0x8365 +#define GL_UNSIGNED_SHORT_1_5_5_5_REV 0x8366 +#define GL_UNSIGNED_INT_8_8_8_8_REV 0x8367 +#define GL_UNSIGNED_INT_2_10_10_10_REV 0x8368 +#define GL_BGR 0x80E0 +#define GL_BGRA 0x80E1 +#define GL_MAX_ELEMENTS_VERTICES 0x80E8 +#define GL_MAX_ELEMENTS_INDICES 0x80E9 +#define GL_CLAMP_TO_EDGE 0x812F +#define GL_TEXTURE_MIN_LOD 0x813A +#define GL_TEXTURE_MAX_LOD 0x813B +#define GL_TEXTURE_BASE_LEVEL 0x813C +#define GL_TEXTURE_MAX_LEVEL 0x813D +#define GL_SMOOTH_POINT_SIZE_RANGE 0x0B12 +#define GL_SMOOTH_POINT_SIZE_GRANULARITY 0x0B13 +#define GL_SMOOTH_LINE_WIDTH_RANGE 0x0B22 +#define GL_SMOOTH_LINE_WIDTH_GRANULARITY 0x0B23 +#define GL_ALIASED_LINE_WIDTH_RANGE 0x846E +#endif + +#ifndef GL_VERSION_1_2_DEPRECATED +#define GL_RESCALE_NORMAL 0x803A +#define GL_LIGHT_MODEL_COLOR_CONTROL 0x81F8 +#define GL_SINGLE_COLOR 0x81F9 +#define GL_SEPARATE_SPECULAR_COLOR 0x81FA +#define GL_ALIASED_POINT_SIZE_RANGE 0x846D +#endif + +#ifndef GL_ARB_imaging +#define GL_CONSTANT_COLOR 0x8001 +#define GL_ONE_MINUS_CONSTANT_COLOR 0x8002 +#define GL_CONSTANT_ALPHA 0x8003 +#define GL_ONE_MINUS_CONSTANT_ALPHA 0x8004 +#define GL_BLEND_COLOR 0x8005 +#define GL_FUNC_ADD 0x8006 +#define GL_MIN 0x8007 +#define GL_MAX 0x8008 +#define GL_BLEND_EQUATION 0x8009 +#define GL_FUNC_SUBTRACT 0x800A +#define GL_FUNC_REVERSE_SUBTRACT 0x800B +#endif + +#ifndef GL_ARB_imaging_DEPRECATED +#define GL_CONVOLUTION_1D 0x8010 +#define GL_CONVOLUTION_2D 0x8011 +#define GL_SEPARABLE_2D 0x8012 +#define GL_CONVOLUTION_BORDER_MODE 0x8013 +#define GL_CONVOLUTION_FILTER_SCALE 0x8014 +#define GL_CONVOLUTION_FILTER_BIAS 0x8015 +#define GL_REDUCE 0x8016 +#define GL_CONVOLUTION_FORMAT 0x8017 +#define GL_CONVOLUTION_WIDTH 0x8018 +#define GL_CONVOLUTION_HEIGHT 0x8019 +#define GL_MAX_CONVOLUTION_WIDTH 0x801A +#define GL_MAX_CONVOLUTION_HEIGHT 0x801B +#define GL_POST_CONVOLUTION_RED_SCALE 0x801C +#define GL_POST_CONVOLUTION_GREEN_SCALE 0x801D +#define GL_POST_CONVOLUTION_BLUE_SCALE 0x801E +#define GL_POST_CONVOLUTION_ALPHA_SCALE 0x801F +#define GL_POST_CONVOLUTION_RED_BIAS 0x8020 +#define GL_POST_CONVOLUTION_GREEN_BIAS 0x8021 +#define GL_POST_CONVOLUTION_BLUE_BIAS 0x8022 +#define GL_POST_CONVOLUTION_ALPHA_BIAS 0x8023 +#define GL_HISTOGRAM 0x8024 +#define GL_PROXY_HISTOGRAM 0x8025 +#define GL_HISTOGRAM_WIDTH 0x8026 +#define GL_HISTOGRAM_FORMAT 0x8027 +#define GL_HISTOGRAM_RED_SIZE 0x8028 +#define GL_HISTOGRAM_GREEN_SIZE 0x8029 +#define GL_HISTOGRAM_BLUE_SIZE 0x802A +#define GL_HISTOGRAM_ALPHA_SIZE 0x802B +#define GL_HISTOGRAM_LUMINANCE_SIZE 0x802C +#define GL_HISTOGRAM_SINK 0x802D +#define GL_MINMAX 0x802E +#define GL_MINMAX_FORMAT 0x802F +#define GL_MINMAX_SINK 0x8030 +#define GL_TABLE_TOO_LARGE 0x8031 +#define GL_COLOR_MATRIX 0x80B1 +#define GL_COLOR_MATRIX_STACK_DEPTH 0x80B2 +#define GL_MAX_COLOR_MATRIX_STACK_DEPTH 0x80B3 +#define GL_POST_COLOR_MATRIX_RED_SCALE 0x80B4 +#define GL_POST_COLOR_MATRIX_GREEN_SCALE 0x80B5 +#define GL_POST_COLOR_MATRIX_BLUE_SCALE 0x80B6 +#define GL_POST_COLOR_MATRIX_ALPHA_SCALE 0x80B7 +#define GL_POST_COLOR_MATRIX_RED_BIAS 0x80B8 +#define GL_POST_COLOR_MATRIX_GREEN_BIAS 0x80B9 +#define GL_POST_COLOR_MATRIX_BLUE_BIAS 0x80BA +#define GL_POST_COLOR_MATRIX_ALPHA_BIAS 0x80BB +#define GL_COLOR_TABLE 0x80D0 +#define GL_POST_CONVOLUTION_COLOR_TABLE 0x80D1 +#define GL_POST_COLOR_MATRIX_COLOR_TABLE 0x80D2 +#define GL_PROXY_COLOR_TABLE 0x80D3 +#define GL_PROXY_POST_CONVOLUTION_COLOR_TABLE 0x80D4 +#define GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE 0x80D5 +#define GL_COLOR_TABLE_SCALE 0x80D6 +#define GL_COLOR_TABLE_BIAS 0x80D7 +#define GL_COLOR_TABLE_FORMAT 0x80D8 +#define GL_COLOR_TABLE_WIDTH 0x80D9 +#define GL_COLOR_TABLE_RED_SIZE 0x80DA +#define GL_COLOR_TABLE_GREEN_SIZE 0x80DB +#define GL_COLOR_TABLE_BLUE_SIZE 0x80DC +#define GL_COLOR_TABLE_ALPHA_SIZE 0x80DD +#define GL_COLOR_TABLE_LUMINANCE_SIZE 0x80DE +#define GL_COLOR_TABLE_INTENSITY_SIZE 0x80DF +#define GL_CONSTANT_BORDER 0x8151 +#define GL_REPLICATE_BORDER 0x8153 +#define GL_CONVOLUTION_BORDER_COLOR 0x8154 +#endif + +#ifndef GL_VERSION_1_3 +#define GL_TEXTURE0 0x84C0 +#define GL_TEXTURE1 0x84C1 +#define GL_TEXTURE2 0x84C2 +#define GL_TEXTURE3 0x84C3 +#define GL_TEXTURE4 0x84C4 +#define GL_TEXTURE5 0x84C5 +#define GL_TEXTURE6 0x84C6 +#define GL_TEXTURE7 0x84C7 +#define GL_TEXTURE8 0x84C8 +#define GL_TEXTURE9 0x84C9 +#define GL_TEXTURE10 0x84CA +#define GL_TEXTURE11 0x84CB +#define GL_TEXTURE12 0x84CC +#define GL_TEXTURE13 0x84CD +#define GL_TEXTURE14 0x84CE +#define GL_TEXTURE15 0x84CF +#define GL_TEXTURE16 0x84D0 +#define GL_TEXTURE17 0x84D1 +#define GL_TEXTURE18 0x84D2 +#define GL_TEXTURE19 0x84D3 +#define GL_TEXTURE20 0x84D4 +#define GL_TEXTURE21 0x84D5 +#define GL_TEXTURE22 0x84D6 +#define GL_TEXTURE23 0x84D7 +#define GL_TEXTURE24 0x84D8 +#define GL_TEXTURE25 0x84D9 +#define GL_TEXTURE26 0x84DA +#define GL_TEXTURE27 0x84DB +#define GL_TEXTURE28 0x84DC +#define GL_TEXTURE29 0x84DD +#define GL_TEXTURE30 0x84DE +#define GL_TEXTURE31 0x84DF +#define GL_ACTIVE_TEXTURE 0x84E0 +#define GL_MULTISAMPLE 0x809D +#define GL_SAMPLE_ALPHA_TO_COVERAGE 0x809E +#define GL_SAMPLE_ALPHA_TO_ONE 0x809F +#define GL_SAMPLE_COVERAGE 0x80A0 +#define GL_SAMPLE_BUFFERS 0x80A8 +#define GL_SAMPLES 0x80A9 +#define GL_SAMPLE_COVERAGE_VALUE 0x80AA +#define GL_SAMPLE_COVERAGE_INVERT 0x80AB +#define GL_TEXTURE_CUBE_MAP 0x8513 +#define GL_TEXTURE_BINDING_CUBE_MAP 0x8514 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_X 0x8515 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_X 0x8516 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_Y 0x8517 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Y 0x8518 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_Z 0x8519 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Z 0x851A +#define GL_PROXY_TEXTURE_CUBE_MAP 0x851B +#define GL_MAX_CUBE_MAP_TEXTURE_SIZE 0x851C +#define GL_COMPRESSED_RGB 0x84ED +#define GL_COMPRESSED_RGBA 0x84EE +#define GL_TEXTURE_COMPRESSION_HINT 0x84EF +#define GL_TEXTURE_COMPRESSED_IMAGE_SIZE 0x86A0 +#define GL_TEXTURE_COMPRESSED 0x86A1 +#define GL_NUM_COMPRESSED_TEXTURE_FORMATS 0x86A2 +#define GL_COMPRESSED_TEXTURE_FORMATS 0x86A3 +#define GL_CLAMP_TO_BORDER 0x812D +#endif + +#ifndef GL_VERSION_1_3_DEPRECATED +#define GL_CLIENT_ACTIVE_TEXTURE 0x84E1 +#define GL_MAX_TEXTURE_UNITS 0x84E2 +#define GL_TRANSPOSE_MODELVIEW_MATRIX 0x84E3 +#define GL_TRANSPOSE_PROJECTION_MATRIX 0x84E4 +#define GL_TRANSPOSE_TEXTURE_MATRIX 0x84E5 +#define GL_TRANSPOSE_COLOR_MATRIX 0x84E6 +#define GL_MULTISAMPLE_BIT 0x20000000 +#define GL_NORMAL_MAP 0x8511 +#define GL_REFLECTION_MAP 0x8512 +#define GL_COMPRESSED_ALPHA 0x84E9 +#define GL_COMPRESSED_LUMINANCE 0x84EA +#define GL_COMPRESSED_LUMINANCE_ALPHA 0x84EB +#define GL_COMPRESSED_INTENSITY 0x84EC +#define GL_COMBINE 0x8570 +#define GL_COMBINE_RGB 0x8571 +#define GL_COMBINE_ALPHA 0x8572 +#define GL_SOURCE0_RGB 0x8580 +#define GL_SOURCE1_RGB 0x8581 +#define GL_SOURCE2_RGB 0x8582 +#define GL_SOURCE0_ALPHA 0x8588 +#define GL_SOURCE1_ALPHA 0x8589 +#define GL_SOURCE2_ALPHA 0x858A +#define GL_OPERAND0_RGB 0x8590 +#define GL_OPERAND1_RGB 0x8591 +#define GL_OPERAND2_RGB 0x8592 +#define GL_OPERAND0_ALPHA 0x8598 +#define GL_OPERAND1_ALPHA 0x8599 +#define GL_OPERAND2_ALPHA 0x859A +#define GL_RGB_SCALE 0x8573 +#define GL_ADD_SIGNED 0x8574 +#define GL_INTERPOLATE 0x8575 +#define GL_SUBTRACT 0x84E7 +#define GL_CONSTANT 0x8576 +#define GL_PRIMARY_COLOR 0x8577 +#define GL_PREVIOUS 0x8578 +#define GL_DOT3_RGB 0x86AE +#define GL_DOT3_RGBA 0x86AF +#endif + +#ifndef GL_VERSION_1_4 +#define GL_BLEND_DST_RGB 0x80C8 +#define GL_BLEND_SRC_RGB 0x80C9 +#define GL_BLEND_DST_ALPHA 0x80CA +#define GL_BLEND_SRC_ALPHA 0x80CB +#define GL_POINT_FADE_THRESHOLD_SIZE 0x8128 +#define GL_DEPTH_COMPONENT16 0x81A5 +#define GL_DEPTH_COMPONENT24 0x81A6 +#define GL_DEPTH_COMPONENT32 0x81A7 +#define GL_MIRRORED_REPEAT 0x8370 +#define GL_MAX_TEXTURE_LOD_BIAS 0x84FD +#define GL_TEXTURE_LOD_BIAS 0x8501 +#define GL_INCR_WRAP 0x8507 +#define GL_DECR_WRAP 0x8508 +#define GL_TEXTURE_DEPTH_SIZE 0x884A +#define GL_TEXTURE_COMPARE_MODE 0x884C +#define GL_TEXTURE_COMPARE_FUNC 0x884D +#endif + +#ifndef GL_VERSION_1_4_DEPRECATED +#define GL_POINT_SIZE_MIN 0x8126 +#define GL_POINT_SIZE_MAX 0x8127 +#define GL_POINT_DISTANCE_ATTENUATION 0x8129 +#define GL_GENERATE_MIPMAP 0x8191 +#define GL_GENERATE_MIPMAP_HINT 0x8192 +#define GL_FOG_COORDINATE_SOURCE 0x8450 +#define GL_FOG_COORDINATE 0x8451 +#define GL_FRAGMENT_DEPTH 0x8452 +#define GL_CURRENT_FOG_COORDINATE 0x8453 +#define GL_FOG_COORDINATE_ARRAY_TYPE 0x8454 +#define GL_FOG_COORDINATE_ARRAY_STRIDE 0x8455 +#define GL_FOG_COORDINATE_ARRAY_POINTER 0x8456 +#define GL_FOG_COORDINATE_ARRAY 0x8457 +#define GL_COLOR_SUM 0x8458 +#define GL_CURRENT_SECONDARY_COLOR 0x8459 +#define GL_SECONDARY_COLOR_ARRAY_SIZE 0x845A +#define GL_SECONDARY_COLOR_ARRAY_TYPE 0x845B +#define GL_SECONDARY_COLOR_ARRAY_STRIDE 0x845C +#define GL_SECONDARY_COLOR_ARRAY_POINTER 0x845D +#define GL_SECONDARY_COLOR_ARRAY 0x845E +#define GL_TEXTURE_FILTER_CONTROL 0x8500 +#define GL_DEPTH_TEXTURE_MODE 0x884B +#define GL_COMPARE_R_TO_TEXTURE 0x884E +#endif + +#ifndef GL_VERSION_1_5 +#define GL_BUFFER_SIZE 0x8764 +#define GL_BUFFER_USAGE 0x8765 +#define GL_QUERY_COUNTER_BITS 0x8864 +#define GL_CURRENT_QUERY 0x8865 +#define GL_QUERY_RESULT 0x8866 +#define GL_QUERY_RESULT_AVAILABLE 0x8867 +#define GL_ARRAY_BUFFER 0x8892 +#define GL_ELEMENT_ARRAY_BUFFER 0x8893 +#define GL_ARRAY_BUFFER_BINDING 0x8894 +#define GL_ELEMENT_ARRAY_BUFFER_BINDING 0x8895 +#define GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING 0x889F +#define GL_READ_ONLY 0x88B8 +#define GL_WRITE_ONLY 0x88B9 +#define GL_READ_WRITE 0x88BA +#define GL_BUFFER_ACCESS 0x88BB +#define GL_BUFFER_MAPPED 0x88BC +#define GL_BUFFER_MAP_POINTER 0x88BD +#define GL_STREAM_DRAW 0x88E0 +#define GL_STREAM_READ 0x88E1 +#define GL_STREAM_COPY 0x88E2 +#define GL_STATIC_DRAW 0x88E4 +#define GL_STATIC_READ 0x88E5 +#define GL_STATIC_COPY 0x88E6 +#define GL_DYNAMIC_DRAW 0x88E8 +#define GL_DYNAMIC_READ 0x88E9 +#define GL_DYNAMIC_COPY 0x88EA +#define GL_SAMPLES_PASSED 0x8914 +#endif + +#ifndef GL_VERSION_1_5_DEPRECATED +#define GL_VERTEX_ARRAY_BUFFER_BINDING 0x8896 +#define GL_NORMAL_ARRAY_BUFFER_BINDING 0x8897 +#define GL_COLOR_ARRAY_BUFFER_BINDING 0x8898 +#define GL_INDEX_ARRAY_BUFFER_BINDING 0x8899 +#define GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING 0x889A +#define GL_EDGE_FLAG_ARRAY_BUFFER_BINDING 0x889B +#define GL_SECONDARY_COLOR_ARRAY_BUFFER_BINDING 0x889C +#define GL_FOG_COORDINATE_ARRAY_BUFFER_BINDING 0x889D +#define GL_WEIGHT_ARRAY_BUFFER_BINDING 0x889E +#define GL_FOG_COORD_SRC 0x8450 +#define GL_FOG_COORD 0x8451 +#define GL_CURRENT_FOG_COORD 0x8453 +#define GL_FOG_COORD_ARRAY_TYPE 0x8454 +#define GL_FOG_COORD_ARRAY_STRIDE 0x8455 +#define GL_FOG_COORD_ARRAY_POINTER 0x8456 +#define GL_FOG_COORD_ARRAY 0x8457 +#define GL_FOG_COORD_ARRAY_BUFFER_BINDING 0x889D +#define GL_SRC0_RGB 0x8580 +#define GL_SRC1_RGB 0x8581 +#define GL_SRC2_RGB 0x8582 +#define GL_SRC0_ALPHA 0x8588 +#define GL_SRC1_ALPHA 0x8589 +#define GL_SRC2_ALPHA 0x858A +#endif + +#ifndef GL_VERSION_2_0 +#define GL_BLEND_EQUATION_RGB 0x8009 +#define GL_VERTEX_ATTRIB_ARRAY_ENABLED 0x8622 +#define GL_VERTEX_ATTRIB_ARRAY_SIZE 0x8623 +#define GL_VERTEX_ATTRIB_ARRAY_STRIDE 0x8624 +#define GL_VERTEX_ATTRIB_ARRAY_TYPE 0x8625 +#define GL_CURRENT_VERTEX_ATTRIB 0x8626 +#define GL_VERTEX_PROGRAM_POINT_SIZE 0x8642 +#define GL_VERTEX_ATTRIB_ARRAY_POINTER 0x8645 +#define GL_STENCIL_BACK_FUNC 0x8800 +#define GL_STENCIL_BACK_FAIL 0x8801 +#define GL_STENCIL_BACK_PASS_DEPTH_FAIL 0x8802 +#define GL_STENCIL_BACK_PASS_DEPTH_PASS 0x8803 +#define GL_MAX_DRAW_BUFFERS 0x8824 +#define GL_DRAW_BUFFER0 0x8825 +#define GL_DRAW_BUFFER1 0x8826 +#define GL_DRAW_BUFFER2 0x8827 +#define GL_DRAW_BUFFER3 0x8828 +#define GL_DRAW_BUFFER4 0x8829 +#define GL_DRAW_BUFFER5 0x882A +#define GL_DRAW_BUFFER6 0x882B +#define GL_DRAW_BUFFER7 0x882C +#define GL_DRAW_BUFFER8 0x882D +#define GL_DRAW_BUFFER9 0x882E +#define GL_DRAW_BUFFER10 0x882F +#define GL_DRAW_BUFFER11 0x8830 +#define GL_DRAW_BUFFER12 0x8831 +#define GL_DRAW_BUFFER13 0x8832 +#define GL_DRAW_BUFFER14 0x8833 +#define GL_DRAW_BUFFER15 0x8834 +#define GL_BLEND_EQUATION_ALPHA 0x883D +#define GL_MAX_VERTEX_ATTRIBS 0x8869 +#define GL_VERTEX_ATTRIB_ARRAY_NORMALIZED 0x886A +#define GL_MAX_TEXTURE_IMAGE_UNITS 0x8872 +#define GL_FRAGMENT_SHADER 0x8B30 +#define GL_VERTEX_SHADER 0x8B31 +#define GL_MAX_FRAGMENT_UNIFORM_COMPONENTS 0x8B49 +#define GL_MAX_VERTEX_UNIFORM_COMPONENTS 0x8B4A +#define GL_MAX_VARYING_FLOATS 0x8B4B +#define GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS 0x8B4C +#define GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS 0x8B4D +#define GL_SHADER_TYPE 0x8B4F +#define GL_FLOAT_VEC2 0x8B50 +#define GL_FLOAT_VEC3 0x8B51 +#define GL_FLOAT_VEC4 0x8B52 +#define GL_INT_VEC2 0x8B53 +#define GL_INT_VEC3 0x8B54 +#define GL_INT_VEC4 0x8B55 +#define GL_BOOL 0x8B56 +#define GL_BOOL_VEC2 0x8B57 +#define GL_BOOL_VEC3 0x8B58 +#define GL_BOOL_VEC4 0x8B59 +#define GL_FLOAT_MAT2 0x8B5A +#define GL_FLOAT_MAT3 0x8B5B +#define GL_FLOAT_MAT4 0x8B5C +#define GL_SAMPLER_1D 0x8B5D +#define GL_SAMPLER_2D 0x8B5E +#define GL_SAMPLER_3D 0x8B5F +#define GL_SAMPLER_CUBE 0x8B60 +#define GL_SAMPLER_1D_SHADOW 0x8B61 +#define GL_SAMPLER_2D_SHADOW 0x8B62 +#define GL_DELETE_STATUS 0x8B80 +#define GL_COMPILE_STATUS 0x8B81 +#define GL_LINK_STATUS 0x8B82 +#define GL_VALIDATE_STATUS 0x8B83 +#define GL_INFO_LOG_LENGTH 0x8B84 +#define GL_ATTACHED_SHADERS 0x8B85 +#define GL_ACTIVE_UNIFORMS 0x8B86 +#define GL_ACTIVE_UNIFORM_MAX_LENGTH 0x8B87 +#define GL_SHADER_SOURCE_LENGTH 0x8B88 +#define GL_ACTIVE_ATTRIBUTES 0x8B89 +#define GL_ACTIVE_ATTRIBUTE_MAX_LENGTH 0x8B8A +#define GL_FRAGMENT_SHADER_DERIVATIVE_HINT 0x8B8B +#define GL_SHADING_LANGUAGE_VERSION 0x8B8C +#define GL_CURRENT_PROGRAM 0x8B8D +#define GL_POINT_SPRITE_COORD_ORIGIN 0x8CA0 +#define GL_LOWER_LEFT 0x8CA1 +#define GL_UPPER_LEFT 0x8CA2 +#define GL_STENCIL_BACK_REF 0x8CA3 +#define GL_STENCIL_BACK_VALUE_MASK 0x8CA4 +#define GL_STENCIL_BACK_WRITEMASK 0x8CA5 +#endif + +#ifndef GL_VERSION_2_0_DEPRECATED +#define GL_VERTEX_PROGRAM_TWO_SIDE 0x8643 +#define GL_POINT_SPRITE 0x8861 +#define GL_COORD_REPLACE 0x8862 +#define GL_MAX_TEXTURE_COORDS 0x8871 +#endif + +#ifndef GL_VERSION_2_1 +#define GL_PIXEL_PACK_BUFFER 0x88EB +#define GL_PIXEL_UNPACK_BUFFER 0x88EC +#define GL_PIXEL_PACK_BUFFER_BINDING 0x88ED +#define GL_PIXEL_UNPACK_BUFFER_BINDING 0x88EF +#define GL_FLOAT_MAT2x3 0x8B65 +#define GL_FLOAT_MAT2x4 0x8B66 +#define GL_FLOAT_MAT3x2 0x8B67 +#define GL_FLOAT_MAT3x4 0x8B68 +#define GL_FLOAT_MAT4x2 0x8B69 +#define GL_FLOAT_MAT4x3 0x8B6A +#define GL_SRGB 0x8C40 +#define GL_SRGB8 0x8C41 +#define GL_SRGB_ALPHA 0x8C42 +#define GL_SRGB8_ALPHA8 0x8C43 +#define GL_COMPRESSED_SRGB 0x8C48 +#define GL_COMPRESSED_SRGB_ALPHA 0x8C49 +#endif + +#ifndef GL_VERSION_2_1_DEPRECATED +#define GL_CURRENT_RASTER_SECONDARY_COLOR 0x845F +#define GL_SLUMINANCE_ALPHA 0x8C44 +#define GL_SLUMINANCE8_ALPHA8 0x8C45 +#define GL_SLUMINANCE 0x8C46 +#define GL_SLUMINANCE8 0x8C47 +#define GL_COMPRESSED_SLUMINANCE 0x8C4A +#define GL_COMPRESSED_SLUMINANCE_ALPHA 0x8C4B +#endif + +#ifndef GL_VERSION_3_0 +#define GL_COMPARE_REF_TO_TEXTURE 0x884E +#define GL_CLIP_DISTANCE0 0x3000 +#define GL_CLIP_DISTANCE1 0x3001 +#define GL_CLIP_DISTANCE2 0x3002 +#define GL_CLIP_DISTANCE3 0x3003 +#define GL_CLIP_DISTANCE4 0x3004 +#define GL_CLIP_DISTANCE5 0x3005 +#define GL_CLIP_DISTANCE6 0x3006 +#define GL_CLIP_DISTANCE7 0x3007 +#define GL_MAX_CLIP_DISTANCES 0x0D32 +#define GL_MAJOR_VERSION 0x821B +#define GL_MINOR_VERSION 0x821C +#define GL_NUM_EXTENSIONS 0x821D +#define GL_CONTEXT_FLAGS 0x821E +#define GL_DEPTH_BUFFER 0x8223 +#define GL_STENCIL_BUFFER 0x8224 +#define GL_COMPRESSED_RED 0x8225 +#define GL_COMPRESSED_RG 0x8226 +#define GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT 0x0001 +#define GL_RGBA32F 0x8814 +#define GL_RGB32F 0x8815 +#define GL_RGBA16F 0x881A +#define GL_RGB16F 0x881B +#define GL_VERTEX_ATTRIB_ARRAY_INTEGER 0x88FD +#define GL_MAX_ARRAY_TEXTURE_LAYERS 0x88FF +#define GL_MIN_PROGRAM_TEXEL_OFFSET 0x8904 +#define GL_MAX_PROGRAM_TEXEL_OFFSET 0x8905 +#define GL_CLAMP_READ_COLOR 0x891C +#define GL_FIXED_ONLY 0x891D +#define GL_MAX_VARYING_COMPONENTS 0x8B4B +#define GL_TEXTURE_1D_ARRAY 0x8C18 +#define GL_PROXY_TEXTURE_1D_ARRAY 0x8C19 +#define GL_TEXTURE_2D_ARRAY 0x8C1A +#define GL_PROXY_TEXTURE_2D_ARRAY 0x8C1B +#define GL_TEXTURE_BINDING_1D_ARRAY 0x8C1C +#define GL_TEXTURE_BINDING_2D_ARRAY 0x8C1D +#define GL_R11F_G11F_B10F 0x8C3A +#define GL_UNSIGNED_INT_10F_11F_11F_REV 0x8C3B +#define GL_RGB9_E5 0x8C3D +#define GL_UNSIGNED_INT_5_9_9_9_REV 0x8C3E +#define GL_TEXTURE_SHARED_SIZE 0x8C3F +#define GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH 0x8C76 +#define GL_TRANSFORM_FEEDBACK_BUFFER_MODE 0x8C7F +#define GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS 0x8C80 +#define GL_TRANSFORM_FEEDBACK_VARYINGS 0x8C83 +#define GL_TRANSFORM_FEEDBACK_BUFFER_START 0x8C84 +#define GL_TRANSFORM_FEEDBACK_BUFFER_SIZE 0x8C85 +#define GL_PRIMITIVES_GENERATED 0x8C87 +#define GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN 0x8C88 +#define GL_RASTERIZER_DISCARD 0x8C89 +#define GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS 0x8C8A +#define GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS 0x8C8B +#define GL_INTERLEAVED_ATTRIBS 0x8C8C +#define GL_SEPARATE_ATTRIBS 0x8C8D +#define GL_TRANSFORM_FEEDBACK_BUFFER 0x8C8E +#define GL_TRANSFORM_FEEDBACK_BUFFER_BINDING 0x8C8F +#define GL_RGBA32UI 0x8D70 +#define GL_RGB32UI 0x8D71 +#define GL_RGBA16UI 0x8D76 +#define GL_RGB16UI 0x8D77 +#define GL_RGBA8UI 0x8D7C +#define GL_RGB8UI 0x8D7D +#define GL_RGBA32I 0x8D82 +#define GL_RGB32I 0x8D83 +#define GL_RGBA16I 0x8D88 +#define GL_RGB16I 0x8D89 +#define GL_RGBA8I 0x8D8E +#define GL_RGB8I 0x8D8F +#define GL_RED_INTEGER 0x8D94 +#define GL_GREEN_INTEGER 0x8D95 +#define GL_BLUE_INTEGER 0x8D96 +#define GL_RGB_INTEGER 0x8D98 +#define GL_RGBA_INTEGER 0x8D99 +#define GL_BGR_INTEGER 0x8D9A +#define GL_BGRA_INTEGER 0x8D9B +#define GL_SAMPLER_1D_ARRAY 0x8DC0 +#define GL_SAMPLER_2D_ARRAY 0x8DC1 +#define GL_SAMPLER_1D_ARRAY_SHADOW 0x8DC3 +#define GL_SAMPLER_2D_ARRAY_SHADOW 0x8DC4 +#define GL_SAMPLER_CUBE_SHADOW 0x8DC5 +#define GL_UNSIGNED_INT_VEC2 0x8DC6 +#define GL_UNSIGNED_INT_VEC3 0x8DC7 +#define GL_UNSIGNED_INT_VEC4 0x8DC8 +#define GL_INT_SAMPLER_1D 0x8DC9 +#define GL_INT_SAMPLER_2D 0x8DCA +#define GL_INT_SAMPLER_3D 0x8DCB +#define GL_INT_SAMPLER_CUBE 0x8DCC +#define GL_INT_SAMPLER_1D_ARRAY 0x8DCE +#define GL_INT_SAMPLER_2D_ARRAY 0x8DCF +#define GL_UNSIGNED_INT_SAMPLER_1D 0x8DD1 +#define GL_UNSIGNED_INT_SAMPLER_2D 0x8DD2 +#define GL_UNSIGNED_INT_SAMPLER_3D 0x8DD3 +#define GL_UNSIGNED_INT_SAMPLER_CUBE 0x8DD4 +#define GL_UNSIGNED_INT_SAMPLER_1D_ARRAY 0x8DD6 +#define GL_UNSIGNED_INT_SAMPLER_2D_ARRAY 0x8DD7 +#define GL_QUERY_WAIT 0x8E13 +#define GL_QUERY_NO_WAIT 0x8E14 +#define GL_QUERY_BY_REGION_WAIT 0x8E15 +#define GL_QUERY_BY_REGION_NO_WAIT 0x8E16 +#define GL_BUFFER_ACCESS_FLAGS 0x911F +#define GL_BUFFER_MAP_LENGTH 0x9120 +#define GL_BUFFER_MAP_OFFSET 0x9121 +/* Reuse tokens from ARB_depth_buffer_float */ +/* reuse GL_DEPTH_COMPONENT32F */ +/* reuse GL_DEPTH32F_STENCIL8 */ +/* reuse GL_FLOAT_32_UNSIGNED_INT_24_8_REV */ +/* Reuse tokens from ARB_framebuffer_object */ +/* reuse GL_INVALID_FRAMEBUFFER_OPERATION */ +/* reuse GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING */ +/* reuse GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE */ +/* reuse GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE */ +/* reuse GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE */ +/* reuse GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE */ +/* reuse GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE */ +/* reuse GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE */ +/* reuse GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE */ +/* reuse GL_FRAMEBUFFER_DEFAULT */ +/* reuse GL_FRAMEBUFFER_UNDEFINED */ +/* reuse GL_DEPTH_STENCIL_ATTACHMENT */ +/* reuse GL_INDEX */ +/* reuse GL_MAX_RENDERBUFFER_SIZE */ +/* reuse GL_DEPTH_STENCIL */ +/* reuse GL_UNSIGNED_INT_24_8 */ +/* reuse GL_DEPTH24_STENCIL8 */ +/* reuse GL_TEXTURE_STENCIL_SIZE */ +/* reuse GL_TEXTURE_RED_TYPE */ +/* reuse GL_TEXTURE_GREEN_TYPE */ +/* reuse GL_TEXTURE_BLUE_TYPE */ +/* reuse GL_TEXTURE_ALPHA_TYPE */ +/* reuse GL_TEXTURE_DEPTH_TYPE */ +/* reuse GL_UNSIGNED_NORMALIZED */ +/* reuse GL_FRAMEBUFFER_BINDING */ +/* reuse GL_DRAW_FRAMEBUFFER_BINDING */ +/* reuse GL_RENDERBUFFER_BINDING */ +/* reuse GL_READ_FRAMEBUFFER */ +/* reuse GL_DRAW_FRAMEBUFFER */ +/* reuse GL_READ_FRAMEBUFFER_BINDING */ +/* reuse GL_RENDERBUFFER_SAMPLES */ +/* reuse GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE */ +/* reuse GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME */ +/* reuse GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL */ +/* reuse GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE */ +/* reuse GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER */ +/* reuse GL_FRAMEBUFFER_COMPLETE */ +/* reuse GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT */ +/* reuse GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT */ +/* reuse GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER */ +/* reuse GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER */ +/* reuse GL_FRAMEBUFFER_UNSUPPORTED */ +/* reuse GL_MAX_COLOR_ATTACHMENTS */ +/* reuse GL_COLOR_ATTACHMENT0 */ +/* reuse GL_COLOR_ATTACHMENT1 */ +/* reuse GL_COLOR_ATTACHMENT2 */ +/* reuse GL_COLOR_ATTACHMENT3 */ +/* reuse GL_COLOR_ATTACHMENT4 */ +/* reuse GL_COLOR_ATTACHMENT5 */ +/* reuse GL_COLOR_ATTACHMENT6 */ +/* reuse GL_COLOR_ATTACHMENT7 */ +/* reuse GL_COLOR_ATTACHMENT8 */ +/* reuse GL_COLOR_ATTACHMENT9 */ +/* reuse GL_COLOR_ATTACHMENT10 */ +/* reuse GL_COLOR_ATTACHMENT11 */ +/* reuse GL_COLOR_ATTACHMENT12 */ +/* reuse GL_COLOR_ATTACHMENT13 */ +/* reuse GL_COLOR_ATTACHMENT14 */ +/* reuse GL_COLOR_ATTACHMENT15 */ +/* reuse GL_DEPTH_ATTACHMENT */ +/* reuse GL_STENCIL_ATTACHMENT */ +/* reuse GL_FRAMEBUFFER */ +/* reuse GL_RENDERBUFFER */ +/* reuse GL_RENDERBUFFER_WIDTH */ +/* reuse GL_RENDERBUFFER_HEIGHT */ +/* reuse GL_RENDERBUFFER_INTERNAL_FORMAT */ +/* reuse GL_STENCIL_INDEX1 */ +/* reuse GL_STENCIL_INDEX4 */ +/* reuse GL_STENCIL_INDEX8 */ +/* reuse GL_STENCIL_INDEX16 */ +/* reuse GL_RENDERBUFFER_RED_SIZE */ +/* reuse GL_RENDERBUFFER_GREEN_SIZE */ +/* reuse GL_RENDERBUFFER_BLUE_SIZE */ +/* reuse GL_RENDERBUFFER_ALPHA_SIZE */ +/* reuse GL_RENDERBUFFER_DEPTH_SIZE */ +/* reuse GL_RENDERBUFFER_STENCIL_SIZE */ +/* reuse GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE */ +/* reuse GL_MAX_SAMPLES */ +/* Reuse tokens from ARB_framebuffer_sRGB */ +/* reuse GL_FRAMEBUFFER_SRGB */ +/* Reuse tokens from ARB_half_float_vertex */ +/* reuse GL_HALF_FLOAT */ +/* Reuse tokens from ARB_map_buffer_range */ +/* reuse GL_MAP_READ_BIT */ +/* reuse GL_MAP_WRITE_BIT */ +/* reuse GL_MAP_INVALIDATE_RANGE_BIT */ +/* reuse GL_MAP_INVALIDATE_BUFFER_BIT */ +/* reuse GL_MAP_FLUSH_EXPLICIT_BIT */ +/* reuse GL_MAP_UNSYNCHRONIZED_BIT */ +/* Reuse tokens from ARB_texture_compression_rgtc */ +/* reuse GL_COMPRESSED_RED_RGTC1 */ +/* reuse GL_COMPRESSED_SIGNED_RED_RGTC1 */ +/* reuse GL_COMPRESSED_RG_RGTC2 */ +/* reuse GL_COMPRESSED_SIGNED_RG_RGTC2 */ +/* Reuse tokens from ARB_texture_rg */ +/* reuse GL_RG */ +/* reuse GL_RG_INTEGER */ +/* reuse GL_R8 */ +/* reuse GL_R16 */ +/* reuse GL_RG8 */ +/* reuse GL_RG16 */ +/* reuse GL_R16F */ +/* reuse GL_R32F */ +/* reuse GL_RG16F */ +/* reuse GL_RG32F */ +/* reuse GL_R8I */ +/* reuse GL_R8UI */ +/* reuse GL_R16I */ +/* reuse GL_R16UI */ +/* reuse GL_R32I */ +/* reuse GL_R32UI */ +/* reuse GL_RG8I */ +/* reuse GL_RG8UI */ +/* reuse GL_RG16I */ +/* reuse GL_RG16UI */ +/* reuse GL_RG32I */ +/* reuse GL_RG32UI */ +/* Reuse tokens from ARB_vertex_array_object */ +/* reuse GL_VERTEX_ARRAY_BINDING */ +#endif + +#ifndef GL_VERSION_3_0_DEPRECATED +#define GL_CLAMP_VERTEX_COLOR 0x891A +#define GL_CLAMP_FRAGMENT_COLOR 0x891B +#define GL_ALPHA_INTEGER 0x8D97 +/* Reuse tokens from ARB_framebuffer_object */ +/* reuse GL_TEXTURE_LUMINANCE_TYPE */ +/* reuse GL_TEXTURE_INTENSITY_TYPE */ +#endif + +#ifndef GL_VERSION_3_1 +#define GL_SAMPLER_2D_RECT 0x8B63 +#define GL_SAMPLER_2D_RECT_SHADOW 0x8B64 +#define GL_SAMPLER_BUFFER 0x8DC2 +#define GL_INT_SAMPLER_2D_RECT 0x8DCD +#define GL_INT_SAMPLER_BUFFER 0x8DD0 +#define GL_UNSIGNED_INT_SAMPLER_2D_RECT 0x8DD5 +#define GL_UNSIGNED_INT_SAMPLER_BUFFER 0x8DD8 +#define GL_TEXTURE_BUFFER 0x8C2A +#define GL_MAX_TEXTURE_BUFFER_SIZE 0x8C2B +#define GL_TEXTURE_BINDING_BUFFER 0x8C2C +#define GL_TEXTURE_BUFFER_DATA_STORE_BINDING 0x8C2D +#define GL_TEXTURE_BUFFER_FORMAT 0x8C2E +#define GL_TEXTURE_RECTANGLE 0x84F5 +#define GL_TEXTURE_BINDING_RECTANGLE 0x84F6 +#define GL_PROXY_TEXTURE_RECTANGLE 0x84F7 +#define GL_MAX_RECTANGLE_TEXTURE_SIZE 0x84F8 +#define GL_RED_SNORM 0x8F90 +#define GL_RG_SNORM 0x8F91 +#define GL_RGB_SNORM 0x8F92 +#define GL_RGBA_SNORM 0x8F93 +#define GL_R8_SNORM 0x8F94 +#define GL_RG8_SNORM 0x8F95 +#define GL_RGB8_SNORM 0x8F96 +#define GL_RGBA8_SNORM 0x8F97 +#define GL_R16_SNORM 0x8F98 +#define GL_RG16_SNORM 0x8F99 +#define GL_RGB16_SNORM 0x8F9A +#define GL_RGBA16_SNORM 0x8F9B +#define GL_SIGNED_NORMALIZED 0x8F9C +#define GL_PRIMITIVE_RESTART 0x8F9D +#define GL_PRIMITIVE_RESTART_INDEX 0x8F9E +/* Reuse tokens from ARB_copy_buffer */ +/* reuse GL_COPY_READ_BUFFER */ +/* reuse GL_COPY_WRITE_BUFFER */ +/* Reuse tokens from ARB_draw_instanced (none) */ +/* Reuse tokens from ARB_uniform_buffer_object */ +/* reuse GL_UNIFORM_BUFFER */ +/* reuse GL_UNIFORM_BUFFER_BINDING */ +/* reuse GL_UNIFORM_BUFFER_START */ +/* reuse GL_UNIFORM_BUFFER_SIZE */ +/* reuse GL_MAX_VERTEX_UNIFORM_BLOCKS */ +/* reuse GL_MAX_FRAGMENT_UNIFORM_BLOCKS */ +/* reuse GL_MAX_COMBINED_UNIFORM_BLOCKS */ +/* reuse GL_MAX_UNIFORM_BUFFER_BINDINGS */ +/* reuse GL_MAX_UNIFORM_BLOCK_SIZE */ +/* reuse GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS */ +/* reuse GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS */ +/* reuse GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT */ +/* reuse GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH */ +/* reuse GL_ACTIVE_UNIFORM_BLOCKS */ +/* reuse GL_UNIFORM_TYPE */ +/* reuse GL_UNIFORM_SIZE */ +/* reuse GL_UNIFORM_NAME_LENGTH */ +/* reuse GL_UNIFORM_BLOCK_INDEX */ +/* reuse GL_UNIFORM_OFFSET */ +/* reuse GL_UNIFORM_ARRAY_STRIDE */ +/* reuse GL_UNIFORM_MATRIX_STRIDE */ +/* reuse GL_UNIFORM_IS_ROW_MAJOR */ +/* reuse GL_UNIFORM_BLOCK_BINDING */ +/* reuse GL_UNIFORM_BLOCK_DATA_SIZE */ +/* reuse GL_UNIFORM_BLOCK_NAME_LENGTH */ +/* reuse GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS */ +/* reuse GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES */ +/* reuse GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER */ +/* reuse GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER */ +/* reuse GL_INVALID_INDEX */ +#endif + +#ifndef GL_VERSION_3_2 +#define GL_CONTEXT_CORE_PROFILE_BIT 0x00000001 +#define GL_CONTEXT_COMPATIBILITY_PROFILE_BIT 0x00000002 +#define GL_LINES_ADJACENCY 0x000A +#define GL_LINE_STRIP_ADJACENCY 0x000B +#define GL_TRIANGLES_ADJACENCY 0x000C +#define GL_TRIANGLE_STRIP_ADJACENCY 0x000D +#define GL_PROGRAM_POINT_SIZE 0x8642 +#define GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS 0x8C29 +#define GL_FRAMEBUFFER_ATTACHMENT_LAYERED 0x8DA7 +#define GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS 0x8DA8 +#define GL_GEOMETRY_SHADER 0x8DD9 +#define GL_GEOMETRY_VERTICES_OUT 0x8916 +#define GL_GEOMETRY_INPUT_TYPE 0x8917 +#define GL_GEOMETRY_OUTPUT_TYPE 0x8918 +#define GL_MAX_GEOMETRY_UNIFORM_COMPONENTS 0x8DDF +#define GL_MAX_GEOMETRY_OUTPUT_VERTICES 0x8DE0 +#define GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS 0x8DE1 +#define GL_MAX_VERTEX_OUTPUT_COMPONENTS 0x9122 +#define GL_MAX_GEOMETRY_INPUT_COMPONENTS 0x9123 +#define GL_MAX_GEOMETRY_OUTPUT_COMPONENTS 0x9124 +#define GL_MAX_FRAGMENT_INPUT_COMPONENTS 0x9125 +#define GL_CONTEXT_PROFILE_MASK 0x9126 +/* reuse GL_MAX_VARYING_COMPONENTS */ +/* reuse GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER */ +/* Reuse tokens from ARB_depth_clamp */ +/* reuse GL_DEPTH_CLAMP */ +/* Reuse tokens from ARB_draw_elements_base_vertex (none) */ +/* Reuse tokens from ARB_fragment_coord_conventions (none) */ +/* Reuse tokens from ARB_provoking_vertex */ +/* reuse GL_QUADS_FOLLOW_PROVOKING_VERTEX_CONVENTION */ +/* reuse GL_FIRST_VERTEX_CONVENTION */ +/* reuse GL_LAST_VERTEX_CONVENTION */ +/* reuse GL_PROVOKING_VERTEX */ +/* Reuse tokens from ARB_seamless_cube_map */ +/* reuse GL_TEXTURE_CUBE_MAP_SEAMLESS */ +/* Reuse tokens from ARB_sync */ +/* reuse GL_MAX_SERVER_WAIT_TIMEOUT */ +/* reuse GL_OBJECT_TYPE */ +/* reuse GL_SYNC_CONDITION */ +/* reuse GL_SYNC_STATUS */ +/* reuse GL_SYNC_FLAGS */ +/* reuse GL_SYNC_FENCE */ +/* reuse GL_SYNC_GPU_COMMANDS_COMPLETE */ +/* reuse GL_UNSIGNALED */ +/* reuse GL_SIGNALED */ +/* reuse GL_ALREADY_SIGNALED */ +/* reuse GL_TIMEOUT_EXPIRED */ +/* reuse GL_CONDITION_SATISFIED */ +/* reuse GL_WAIT_FAILED */ +/* reuse GL_TIMEOUT_IGNORED */ +/* reuse GL_SYNC_FLUSH_COMMANDS_BIT */ +/* reuse GL_TIMEOUT_IGNORED */ +/* Reuse tokens from ARB_texture_multisample */ +/* reuse GL_SAMPLE_POSITION */ +/* reuse GL_SAMPLE_MASK */ +/* reuse GL_SAMPLE_MASK_VALUE */ +/* reuse GL_MAX_SAMPLE_MASK_WORDS */ +/* reuse GL_TEXTURE_2D_MULTISAMPLE */ +/* reuse GL_PROXY_TEXTURE_2D_MULTISAMPLE */ +/* reuse GL_TEXTURE_2D_MULTISAMPLE_ARRAY */ +/* reuse GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY */ +/* reuse GL_TEXTURE_BINDING_2D_MULTISAMPLE */ +/* reuse GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY */ +/* reuse GL_TEXTURE_SAMPLES */ +/* reuse GL_TEXTURE_FIXED_SAMPLE_LOCATIONS */ +/* reuse GL_SAMPLER_2D_MULTISAMPLE */ +/* reuse GL_INT_SAMPLER_2D_MULTISAMPLE */ +/* reuse GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE */ +/* reuse GL_SAMPLER_2D_MULTISAMPLE_ARRAY */ +/* reuse GL_INT_SAMPLER_2D_MULTISAMPLE_ARRAY */ +/* reuse GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY */ +/* reuse GL_MAX_COLOR_TEXTURE_SAMPLES */ +/* reuse GL_MAX_DEPTH_TEXTURE_SAMPLES */ +/* reuse GL_MAX_INTEGER_SAMPLES */ +/* Don't need to reuse tokens from ARB_vertex_array_bgra since they're already in 1.2 core */ +#endif + +#ifndef GL_VERSION_3_3 +#define GL_VERTEX_ATTRIB_ARRAY_DIVISOR 0x88FE +/* Reuse tokens from ARB_blend_func_extended */ +/* reuse GL_SRC1_COLOR */ +/* reuse GL_ONE_MINUS_SRC1_COLOR */ +/* reuse GL_ONE_MINUS_SRC1_ALPHA */ +/* reuse GL_MAX_DUAL_SOURCE_DRAW_BUFFERS */ +/* Reuse tokens from ARB_explicit_attrib_location (none) */ +/* Reuse tokens from ARB_occlusion_query2 */ +/* reuse GL_ANY_SAMPLES_PASSED */ +/* Reuse tokens from ARB_sampler_objects */ +/* reuse GL_SAMPLER_BINDING */ +/* Reuse tokens from ARB_shader_bit_encoding (none) */ +/* Reuse tokens from ARB_texture_rgb10_a2ui */ +/* reuse GL_RGB10_A2UI */ +/* Reuse tokens from ARB_texture_swizzle */ +/* reuse GL_TEXTURE_SWIZZLE_R */ +/* reuse GL_TEXTURE_SWIZZLE_G */ +/* reuse GL_TEXTURE_SWIZZLE_B */ +/* reuse GL_TEXTURE_SWIZZLE_A */ +/* reuse GL_TEXTURE_SWIZZLE_RGBA */ +/* Reuse tokens from ARB_timer_query */ +/* reuse GL_TIME_ELAPSED */ +/* reuse GL_TIMESTAMP */ +/* Reuse tokens from ARB_vertex_type_2_10_10_10_rev */ +/* reuse GL_INT_2_10_10_10_REV */ +#endif + +#ifndef GL_VERSION_4_0 +#define GL_SAMPLE_SHADING 0x8C36 +#define GL_MIN_SAMPLE_SHADING_VALUE 0x8C37 +#define GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET 0x8E5E +#define GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET 0x8E5F +#define GL_TEXTURE_CUBE_MAP_ARRAY 0x9009 +#define GL_TEXTURE_BINDING_CUBE_MAP_ARRAY 0x900A +#define GL_PROXY_TEXTURE_CUBE_MAP_ARRAY 0x900B +#define GL_SAMPLER_CUBE_MAP_ARRAY 0x900C +#define GL_SAMPLER_CUBE_MAP_ARRAY_SHADOW 0x900D +#define GL_INT_SAMPLER_CUBE_MAP_ARRAY 0x900E +#define GL_UNSIGNED_INT_SAMPLER_CUBE_MAP_ARRAY 0x900F +/* Reuse tokens from ARB_texture_query_lod (none) */ +/* Reuse tokens from ARB_draw_buffers_blend (none) */ +/* Reuse tokens from ARB_draw_indirect */ +/* reuse GL_DRAW_INDIRECT_BUFFER */ +/* reuse GL_DRAW_INDIRECT_BUFFER_BINDING */ +/* Reuse tokens from ARB_gpu_shader5 */ +/* reuse GL_GEOMETRY_SHADER_INVOCATIONS */ +/* reuse GL_MAX_GEOMETRY_SHADER_INVOCATIONS */ +/* reuse GL_MIN_FRAGMENT_INTERPOLATION_OFFSET */ +/* reuse GL_MAX_FRAGMENT_INTERPOLATION_OFFSET */ +/* reuse GL_FRAGMENT_INTERPOLATION_OFFSET_BITS */ +/* reuse GL_MAX_VERTEX_STREAMS */ +/* Reuse tokens from ARB_gpu_shader_fp64 */ +/* reuse GL_DOUBLE_VEC2 */ +/* reuse GL_DOUBLE_VEC3 */ +/* reuse GL_DOUBLE_VEC4 */ +/* reuse GL_DOUBLE_MAT2 */ +/* reuse GL_DOUBLE_MAT3 */ +/* reuse GL_DOUBLE_MAT4 */ +/* reuse GL_DOUBLE_MAT2x3 */ +/* reuse GL_DOUBLE_MAT2x4 */ +/* reuse GL_DOUBLE_MAT3x2 */ +/* reuse GL_DOUBLE_MAT3x4 */ +/* reuse GL_DOUBLE_MAT4x2 */ +/* reuse GL_DOUBLE_MAT4x3 */ +/* Reuse tokens from ARB_shader_subroutine */ +/* reuse GL_ACTIVE_SUBROUTINES */ +/* reuse GL_ACTIVE_SUBROUTINE_UNIFORMS */ +/* reuse GL_ACTIVE_SUBROUTINE_UNIFORM_LOCATIONS */ +/* reuse GL_ACTIVE_SUBROUTINE_MAX_LENGTH */ +/* reuse GL_ACTIVE_SUBROUTINE_UNIFORM_MAX_LENGTH */ +/* reuse GL_MAX_SUBROUTINES */ +/* reuse GL_MAX_SUBROUTINE_UNIFORM_LOCATIONS */ +/* reuse GL_NUM_COMPATIBLE_SUBROUTINES */ +/* reuse GL_COMPATIBLE_SUBROUTINES */ +/* Reuse tokens from ARB_tessellation_shader */ +/* reuse GL_PATCHES */ +/* reuse GL_PATCH_VERTICES */ +/* reuse GL_PATCH_DEFAULT_INNER_LEVEL */ +/* reuse GL_PATCH_DEFAULT_OUTER_LEVEL */ +/* reuse GL_TESS_CONTROL_OUTPUT_VERTICES */ +/* reuse GL_TESS_GEN_MODE */ +/* reuse GL_TESS_GEN_SPACING */ +/* reuse GL_TESS_GEN_VERTEX_ORDER */ +/* reuse GL_TESS_GEN_POINT_MODE */ +/* reuse GL_ISOLINES */ +/* reuse GL_FRACTIONAL_ODD */ +/* reuse GL_FRACTIONAL_EVEN */ +/* reuse GL_MAX_PATCH_VERTICES */ +/* reuse GL_MAX_TESS_GEN_LEVEL */ +/* reuse GL_MAX_TESS_CONTROL_UNIFORM_COMPONENTS */ +/* reuse GL_MAX_TESS_EVALUATION_UNIFORM_COMPONENTS */ +/* reuse GL_MAX_TESS_CONTROL_TEXTURE_IMAGE_UNITS */ +/* reuse GL_MAX_TESS_EVALUATION_TEXTURE_IMAGE_UNITS */ +/* reuse GL_MAX_TESS_CONTROL_OUTPUT_COMPONENTS */ +/* reuse GL_MAX_TESS_PATCH_COMPONENTS */ +/* reuse GL_MAX_TESS_CONTROL_TOTAL_OUTPUT_COMPONENTS */ +/* reuse GL_MAX_TESS_EVALUATION_OUTPUT_COMPONENTS */ +/* reuse GL_MAX_TESS_CONTROL_UNIFORM_BLOCKS */ +/* reuse GL_MAX_TESS_EVALUATION_UNIFORM_BLOCKS */ +/* reuse GL_MAX_TESS_CONTROL_INPUT_COMPONENTS */ +/* reuse GL_MAX_TESS_EVALUATION_INPUT_COMPONENTS */ +/* reuse GL_MAX_COMBINED_TESS_CONTROL_UNIFORM_COMPONENTS */ +/* reuse GL_MAX_COMBINED_TESS_EVALUATION_UNIFORM_COMPONENTS */ +/* reuse GL_UNIFORM_BLOCK_REFERENCED_BY_TESS_CONTROL_SHADER */ +/* reuse GL_UNIFORM_BLOCK_REFERENCED_BY_TESS_EVALUATION_SHADER */ +/* reuse GL_TESS_EVALUATION_SHADER */ +/* reuse GL_TESS_CONTROL_SHADER */ +/* Reuse tokens from ARB_texture_buffer_object_rgb32 (none) */ +/* Reuse tokens from ARB_transform_feedback2 */ +/* reuse GL_TRANSFORM_FEEDBACK */ +/* reuse GL_TRANSFORM_FEEDBACK_BUFFER_PAUSED */ +/* reuse GL_TRANSFORM_FEEDBACK_BUFFER_ACTIVE */ +/* reuse GL_TRANSFORM_FEEDBACK_BINDING */ +/* Reuse tokens from ARB_transform_feedback3 */ +/* reuse GL_MAX_TRANSFORM_FEEDBACK_BUFFERS */ +/* reuse GL_MAX_VERTEX_STREAMS */ +#endif + +#ifndef GL_VERSION_4_1 +/* Reuse tokens from ARB_ES2_compatibility */ +/* reuse GL_FIXED */ +/* reuse GL_IMPLEMENTATION_COLOR_READ_TYPE */ +/* reuse GL_IMPLEMENTATION_COLOR_READ_FORMAT */ +/* reuse GL_LOW_FLOAT */ +/* reuse GL_MEDIUM_FLOAT */ +/* reuse GL_HIGH_FLOAT */ +/* reuse GL_LOW_INT */ +/* reuse GL_MEDIUM_INT */ +/* reuse GL_HIGH_INT */ +/* reuse GL_SHADER_COMPILER */ +/* reuse GL_NUM_SHADER_BINARY_FORMATS */ +/* reuse GL_MAX_VERTEX_UNIFORM_VECTORS */ +/* reuse GL_MAX_VARYING_VECTORS */ +/* reuse GL_MAX_FRAGMENT_UNIFORM_VECTORS */ +/* Reuse tokens from ARB_get_program_binary */ +/* reuse GL_PROGRAM_BINARY_RETRIEVABLE_HINT */ +/* reuse GL_PROGRAM_BINARY_LENGTH */ +/* reuse GL_NUM_PROGRAM_BINARY_FORMATS */ +/* reuse GL_PROGRAM_BINARY_FORMATS */ +/* Reuse tokens from ARB_separate_shader_objects */ +/* reuse GL_VERTEX_SHADER_BIT */ +/* reuse GL_FRAGMENT_SHADER_BIT */ +/* reuse GL_GEOMETRY_SHADER_BIT */ +/* reuse GL_TESS_CONTROL_SHADER_BIT */ +/* reuse GL_TESS_EVALUATION_SHADER_BIT */ +/* reuse GL_ALL_SHADER_BITS */ +/* reuse GL_PROGRAM_SEPARABLE */ +/* reuse GL_ACTIVE_PROGRAM */ +/* reuse GL_PROGRAM_PIPELINE_BINDING */ +/* Reuse tokens from ARB_shader_precision (none) */ +/* Reuse tokens from ARB_vertex_attrib_64bit - all are in GL 3.0 and 4.0 already */ +/* Reuse tokens from ARB_viewport_array - some are in GL 1.1 and ARB_provoking_vertex already */ +/* reuse GL_MAX_VIEWPORTS */ +/* reuse GL_VIEWPORT_SUBPIXEL_BITS */ +/* reuse GL_VIEWPORT_BOUNDS_RANGE */ +/* reuse GL_LAYER_PROVOKING_VERTEX */ +/* reuse GL_VIEWPORT_INDEX_PROVOKING_VERTEX */ +/* reuse GL_UNDEFINED_VERTEX */ +#endif + +#ifndef GL_ARB_multitexture +#define GL_TEXTURE0_ARB 0x84C0 +#define GL_TEXTURE1_ARB 0x84C1 +#define GL_TEXTURE2_ARB 0x84C2 +#define GL_TEXTURE3_ARB 0x84C3 +#define GL_TEXTURE4_ARB 0x84C4 +#define GL_TEXTURE5_ARB 0x84C5 +#define GL_TEXTURE6_ARB 0x84C6 +#define GL_TEXTURE7_ARB 0x84C7 +#define GL_TEXTURE8_ARB 0x84C8 +#define GL_TEXTURE9_ARB 0x84C9 +#define GL_TEXTURE10_ARB 0x84CA +#define GL_TEXTURE11_ARB 0x84CB +#define GL_TEXTURE12_ARB 0x84CC +#define GL_TEXTURE13_ARB 0x84CD +#define GL_TEXTURE14_ARB 0x84CE +#define GL_TEXTURE15_ARB 0x84CF +#define GL_TEXTURE16_ARB 0x84D0 +#define GL_TEXTURE17_ARB 0x84D1 +#define GL_TEXTURE18_ARB 0x84D2 +#define GL_TEXTURE19_ARB 0x84D3 +#define GL_TEXTURE20_ARB 0x84D4 +#define GL_TEXTURE21_ARB 0x84D5 +#define GL_TEXTURE22_ARB 0x84D6 +#define GL_TEXTURE23_ARB 0x84D7 +#define GL_TEXTURE24_ARB 0x84D8 +#define GL_TEXTURE25_ARB 0x84D9 +#define GL_TEXTURE26_ARB 0x84DA +#define GL_TEXTURE27_ARB 0x84DB +#define GL_TEXTURE28_ARB 0x84DC +#define GL_TEXTURE29_ARB 0x84DD +#define GL_TEXTURE30_ARB 0x84DE +#define GL_TEXTURE31_ARB 0x84DF +#define GL_ACTIVE_TEXTURE_ARB 0x84E0 +#define GL_CLIENT_ACTIVE_TEXTURE_ARB 0x84E1 +#define GL_MAX_TEXTURE_UNITS_ARB 0x84E2 +#endif + +#ifndef GL_ARB_transpose_matrix +#define GL_TRANSPOSE_MODELVIEW_MATRIX_ARB 0x84E3 +#define GL_TRANSPOSE_PROJECTION_MATRIX_ARB 0x84E4 +#define GL_TRANSPOSE_TEXTURE_MATRIX_ARB 0x84E5 +#define GL_TRANSPOSE_COLOR_MATRIX_ARB 0x84E6 +#endif + +#ifndef GL_ARB_multisample +#define GL_MULTISAMPLE_ARB 0x809D +#define GL_SAMPLE_ALPHA_TO_COVERAGE_ARB 0x809E +#define GL_SAMPLE_ALPHA_TO_ONE_ARB 0x809F +#define GL_SAMPLE_COVERAGE_ARB 0x80A0 +#define GL_SAMPLE_BUFFERS_ARB 0x80A8 +#define GL_SAMPLES_ARB 0x80A9 +#define GL_SAMPLE_COVERAGE_VALUE_ARB 0x80AA +#define GL_SAMPLE_COVERAGE_INVERT_ARB 0x80AB +#define GL_MULTISAMPLE_BIT_ARB 0x20000000 +#endif + +#ifndef GL_ARB_texture_env_add +#endif + +#ifndef GL_ARB_texture_cube_map +#define GL_NORMAL_MAP_ARB 0x8511 +#define GL_REFLECTION_MAP_ARB 0x8512 +#define GL_TEXTURE_CUBE_MAP_ARB 0x8513 +#define GL_TEXTURE_BINDING_CUBE_MAP_ARB 0x8514 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB 0x8515 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB 0x8516 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB 0x8517 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB 0x8518 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB 0x8519 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB 0x851A +#define GL_PROXY_TEXTURE_CUBE_MAP_ARB 0x851B +#define GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB 0x851C +#endif + +#ifndef GL_ARB_texture_compression +#define GL_COMPRESSED_ALPHA_ARB 0x84E9 +#define GL_COMPRESSED_LUMINANCE_ARB 0x84EA +#define GL_COMPRESSED_LUMINANCE_ALPHA_ARB 0x84EB +#define GL_COMPRESSED_INTENSITY_ARB 0x84EC +#define GL_COMPRESSED_RGB_ARB 0x84ED +#define GL_COMPRESSED_RGBA_ARB 0x84EE +#define GL_TEXTURE_COMPRESSION_HINT_ARB 0x84EF +#define GL_TEXTURE_COMPRESSED_IMAGE_SIZE_ARB 0x86A0 +#define GL_TEXTURE_COMPRESSED_ARB 0x86A1 +#define GL_NUM_COMPRESSED_TEXTURE_FORMATS_ARB 0x86A2 +#define GL_COMPRESSED_TEXTURE_FORMATS_ARB 0x86A3 +#endif + +#ifndef GL_ARB_texture_border_clamp +#define GL_CLAMP_TO_BORDER_ARB 0x812D +#endif + +#ifndef GL_ARB_point_parameters +#define GL_POINT_SIZE_MIN_ARB 0x8126 +#define GL_POINT_SIZE_MAX_ARB 0x8127 +#define GL_POINT_FADE_THRESHOLD_SIZE_ARB 0x8128 +#define GL_POINT_DISTANCE_ATTENUATION_ARB 0x8129 +#endif + +#ifndef GL_ARB_vertex_blend +#define GL_MAX_VERTEX_UNITS_ARB 0x86A4 +#define GL_ACTIVE_VERTEX_UNITS_ARB 0x86A5 +#define GL_WEIGHT_SUM_UNITY_ARB 0x86A6 +#define GL_VERTEX_BLEND_ARB 0x86A7 +#define GL_CURRENT_WEIGHT_ARB 0x86A8 +#define GL_WEIGHT_ARRAY_TYPE_ARB 0x86A9 +#define GL_WEIGHT_ARRAY_STRIDE_ARB 0x86AA +#define GL_WEIGHT_ARRAY_SIZE_ARB 0x86AB +#define GL_WEIGHT_ARRAY_POINTER_ARB 0x86AC +#define GL_WEIGHT_ARRAY_ARB 0x86AD +#define GL_MODELVIEW0_ARB 0x1700 +#define GL_MODELVIEW1_ARB 0x850A +#define GL_MODELVIEW2_ARB 0x8722 +#define GL_MODELVIEW3_ARB 0x8723 +#define GL_MODELVIEW4_ARB 0x8724 +#define GL_MODELVIEW5_ARB 0x8725 +#define GL_MODELVIEW6_ARB 0x8726 +#define GL_MODELVIEW7_ARB 0x8727 +#define GL_MODELVIEW8_ARB 0x8728 +#define GL_MODELVIEW9_ARB 0x8729 +#define GL_MODELVIEW10_ARB 0x872A +#define GL_MODELVIEW11_ARB 0x872B +#define GL_MODELVIEW12_ARB 0x872C +#define GL_MODELVIEW13_ARB 0x872D +#define GL_MODELVIEW14_ARB 0x872E +#define GL_MODELVIEW15_ARB 0x872F +#define GL_MODELVIEW16_ARB 0x8730 +#define GL_MODELVIEW17_ARB 0x8731 +#define GL_MODELVIEW18_ARB 0x8732 +#define GL_MODELVIEW19_ARB 0x8733 +#define GL_MODELVIEW20_ARB 0x8734 +#define GL_MODELVIEW21_ARB 0x8735 +#define GL_MODELVIEW22_ARB 0x8736 +#define GL_MODELVIEW23_ARB 0x8737 +#define GL_MODELVIEW24_ARB 0x8738 +#define GL_MODELVIEW25_ARB 0x8739 +#define GL_MODELVIEW26_ARB 0x873A +#define GL_MODELVIEW27_ARB 0x873B +#define GL_MODELVIEW28_ARB 0x873C +#define GL_MODELVIEW29_ARB 0x873D +#define GL_MODELVIEW30_ARB 0x873E +#define GL_MODELVIEW31_ARB 0x873F +#endif + +#ifndef GL_ARB_matrix_palette +#define GL_MATRIX_PALETTE_ARB 0x8840 +#define GL_MAX_MATRIX_PALETTE_STACK_DEPTH_ARB 0x8841 +#define GL_MAX_PALETTE_MATRICES_ARB 0x8842 +#define GL_CURRENT_PALETTE_MATRIX_ARB 0x8843 +#define GL_MATRIX_INDEX_ARRAY_ARB 0x8844 +#define GL_CURRENT_MATRIX_INDEX_ARB 0x8845 +#define GL_MATRIX_INDEX_ARRAY_SIZE_ARB 0x8846 +#define GL_MATRIX_INDEX_ARRAY_TYPE_ARB 0x8847 +#define GL_MATRIX_INDEX_ARRAY_STRIDE_ARB 0x8848 +#define GL_MATRIX_INDEX_ARRAY_POINTER_ARB 0x8849 +#endif + +#ifndef GL_ARB_texture_env_combine +#define GL_COMBINE_ARB 0x8570 +#define GL_COMBINE_RGB_ARB 0x8571 +#define GL_COMBINE_ALPHA_ARB 0x8572 +#define GL_SOURCE0_RGB_ARB 0x8580 +#define GL_SOURCE1_RGB_ARB 0x8581 +#define GL_SOURCE2_RGB_ARB 0x8582 +#define GL_SOURCE0_ALPHA_ARB 0x8588 +#define GL_SOURCE1_ALPHA_ARB 0x8589 +#define GL_SOURCE2_ALPHA_ARB 0x858A +#define GL_OPERAND0_RGB_ARB 0x8590 +#define GL_OPERAND1_RGB_ARB 0x8591 +#define GL_OPERAND2_RGB_ARB 0x8592 +#define GL_OPERAND0_ALPHA_ARB 0x8598 +#define GL_OPERAND1_ALPHA_ARB 0x8599 +#define GL_OPERAND2_ALPHA_ARB 0x859A +#define GL_RGB_SCALE_ARB 0x8573 +#define GL_ADD_SIGNED_ARB 0x8574 +#define GL_INTERPOLATE_ARB 0x8575 +#define GL_SUBTRACT_ARB 0x84E7 +#define GL_CONSTANT_ARB 0x8576 +#define GL_PRIMARY_COLOR_ARB 0x8577 +#define GL_PREVIOUS_ARB 0x8578 +#endif + +#ifndef GL_ARB_texture_env_crossbar +#endif + +#ifndef GL_ARB_texture_env_dot3 +#define GL_DOT3_RGB_ARB 0x86AE +#define GL_DOT3_RGBA_ARB 0x86AF +#endif + +#ifndef GL_ARB_texture_mirrored_repeat +#define GL_MIRRORED_REPEAT_ARB 0x8370 +#endif + +#ifndef GL_ARB_depth_texture +#define GL_DEPTH_COMPONENT16_ARB 0x81A5 +#define GL_DEPTH_COMPONENT24_ARB 0x81A6 +#define GL_DEPTH_COMPONENT32_ARB 0x81A7 +#define GL_TEXTURE_DEPTH_SIZE_ARB 0x884A +#define GL_DEPTH_TEXTURE_MODE_ARB 0x884B +#endif + +#ifndef GL_ARB_shadow +#define GL_TEXTURE_COMPARE_MODE_ARB 0x884C +#define GL_TEXTURE_COMPARE_FUNC_ARB 0x884D +#define GL_COMPARE_R_TO_TEXTURE_ARB 0x884E +#endif + +#ifndef GL_ARB_shadow_ambient +#define GL_TEXTURE_COMPARE_FAIL_VALUE_ARB 0x80BF +#endif + +#ifndef GL_ARB_window_pos +#endif + +#ifndef GL_ARB_vertex_program +#define GL_COLOR_SUM_ARB 0x8458 +#define GL_VERTEX_PROGRAM_ARB 0x8620 +#define GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB 0x8622 +#define GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB 0x8623 +#define GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB 0x8624 +#define GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB 0x8625 +#define GL_CURRENT_VERTEX_ATTRIB_ARB 0x8626 +#define GL_PROGRAM_LENGTH_ARB 0x8627 +#define GL_PROGRAM_STRING_ARB 0x8628 +#define GL_MAX_PROGRAM_MATRIX_STACK_DEPTH_ARB 0x862E +#define GL_MAX_PROGRAM_MATRICES_ARB 0x862F +#define GL_CURRENT_MATRIX_STACK_DEPTH_ARB 0x8640 +#define GL_CURRENT_MATRIX_ARB 0x8641 +#define GL_VERTEX_PROGRAM_POINT_SIZE_ARB 0x8642 +#define GL_VERTEX_PROGRAM_TWO_SIDE_ARB 0x8643 +#define GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB 0x8645 +#define GL_PROGRAM_ERROR_POSITION_ARB 0x864B +#define GL_PROGRAM_BINDING_ARB 0x8677 +#define GL_MAX_VERTEX_ATTRIBS_ARB 0x8869 +#define GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB 0x886A +#define GL_PROGRAM_ERROR_STRING_ARB 0x8874 +#define GL_PROGRAM_FORMAT_ASCII_ARB 0x8875 +#define GL_PROGRAM_FORMAT_ARB 0x8876 +#define GL_PROGRAM_INSTRUCTIONS_ARB 0x88A0 +#define GL_MAX_PROGRAM_INSTRUCTIONS_ARB 0x88A1 +#define GL_PROGRAM_NATIVE_INSTRUCTIONS_ARB 0x88A2 +#define GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB 0x88A3 +#define GL_PROGRAM_TEMPORARIES_ARB 0x88A4 +#define GL_MAX_PROGRAM_TEMPORARIES_ARB 0x88A5 +#define GL_PROGRAM_NATIVE_TEMPORARIES_ARB 0x88A6 +#define GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB 0x88A7 +#define GL_PROGRAM_PARAMETERS_ARB 0x88A8 +#define GL_MAX_PROGRAM_PARAMETERS_ARB 0x88A9 +#define GL_PROGRAM_NATIVE_PARAMETERS_ARB 0x88AA +#define GL_MAX_PROGRAM_NATIVE_PARAMETERS_ARB 0x88AB +#define GL_PROGRAM_ATTRIBS_ARB 0x88AC +#define GL_MAX_PROGRAM_ATTRIBS_ARB 0x88AD +#define GL_PROGRAM_NATIVE_ATTRIBS_ARB 0x88AE +#define GL_MAX_PROGRAM_NATIVE_ATTRIBS_ARB 0x88AF +#define GL_PROGRAM_ADDRESS_REGISTERS_ARB 0x88B0 +#define GL_MAX_PROGRAM_ADDRESS_REGISTERS_ARB 0x88B1 +#define GL_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB 0x88B2 +#define GL_MAX_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB 0x88B3 +#define GL_MAX_PROGRAM_LOCAL_PARAMETERS_ARB 0x88B4 +#define GL_MAX_PROGRAM_ENV_PARAMETERS_ARB 0x88B5 +#define GL_PROGRAM_UNDER_NATIVE_LIMITS_ARB 0x88B6 +#define GL_TRANSPOSE_CURRENT_MATRIX_ARB 0x88B7 +#define GL_MATRIX0_ARB 0x88C0 +#define GL_MATRIX1_ARB 0x88C1 +#define GL_MATRIX2_ARB 0x88C2 +#define GL_MATRIX3_ARB 0x88C3 +#define GL_MATRIX4_ARB 0x88C4 +#define GL_MATRIX5_ARB 0x88C5 +#define GL_MATRIX6_ARB 0x88C6 +#define GL_MATRIX7_ARB 0x88C7 +#define GL_MATRIX8_ARB 0x88C8 +#define GL_MATRIX9_ARB 0x88C9 +#define GL_MATRIX10_ARB 0x88CA +#define GL_MATRIX11_ARB 0x88CB +#define GL_MATRIX12_ARB 0x88CC +#define GL_MATRIX13_ARB 0x88CD +#define GL_MATRIX14_ARB 0x88CE +#define GL_MATRIX15_ARB 0x88CF +#define GL_MATRIX16_ARB 0x88D0 +#define GL_MATRIX17_ARB 0x88D1 +#define GL_MATRIX18_ARB 0x88D2 +#define GL_MATRIX19_ARB 0x88D3 +#define GL_MATRIX20_ARB 0x88D4 +#define GL_MATRIX21_ARB 0x88D5 +#define GL_MATRIX22_ARB 0x88D6 +#define GL_MATRIX23_ARB 0x88D7 +#define GL_MATRIX24_ARB 0x88D8 +#define GL_MATRIX25_ARB 0x88D9 +#define GL_MATRIX26_ARB 0x88DA +#define GL_MATRIX27_ARB 0x88DB +#define GL_MATRIX28_ARB 0x88DC +#define GL_MATRIX29_ARB 0x88DD +#define GL_MATRIX30_ARB 0x88DE +#define GL_MATRIX31_ARB 0x88DF +#endif + +#ifndef GL_ARB_fragment_program +#define GL_FRAGMENT_PROGRAM_ARB 0x8804 +#define GL_PROGRAM_ALU_INSTRUCTIONS_ARB 0x8805 +#define GL_PROGRAM_TEX_INSTRUCTIONS_ARB 0x8806 +#define GL_PROGRAM_TEX_INDIRECTIONS_ARB 0x8807 +#define GL_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB 0x8808 +#define GL_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB 0x8809 +#define GL_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB 0x880A +#define GL_MAX_PROGRAM_ALU_INSTRUCTIONS_ARB 0x880B +#define GL_MAX_PROGRAM_TEX_INSTRUCTIONS_ARB 0x880C +#define GL_MAX_PROGRAM_TEX_INDIRECTIONS_ARB 0x880D +#define GL_MAX_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB 0x880E +#define GL_MAX_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB 0x880F +#define GL_MAX_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB 0x8810 +#define GL_MAX_TEXTURE_COORDS_ARB 0x8871 +#define GL_MAX_TEXTURE_IMAGE_UNITS_ARB 0x8872 +#endif + +#ifndef GL_ARB_vertex_buffer_object +#define GL_BUFFER_SIZE_ARB 0x8764 +#define GL_BUFFER_USAGE_ARB 0x8765 +#define GL_ARRAY_BUFFER_ARB 0x8892 +#define GL_ELEMENT_ARRAY_BUFFER_ARB 0x8893 +#define GL_ARRAY_BUFFER_BINDING_ARB 0x8894 +#define GL_ELEMENT_ARRAY_BUFFER_BINDING_ARB 0x8895 +#define GL_VERTEX_ARRAY_BUFFER_BINDING_ARB 0x8896 +#define GL_NORMAL_ARRAY_BUFFER_BINDING_ARB 0x8897 +#define GL_COLOR_ARRAY_BUFFER_BINDING_ARB 0x8898 +#define GL_INDEX_ARRAY_BUFFER_BINDING_ARB 0x8899 +#define GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING_ARB 0x889A +#define GL_EDGE_FLAG_ARRAY_BUFFER_BINDING_ARB 0x889B +#define GL_SECONDARY_COLOR_ARRAY_BUFFER_BINDING_ARB 0x889C +#define GL_FOG_COORDINATE_ARRAY_BUFFER_BINDING_ARB 0x889D +#define GL_WEIGHT_ARRAY_BUFFER_BINDING_ARB 0x889E +#define GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB 0x889F +#define GL_READ_ONLY_ARB 0x88B8 +#define GL_WRITE_ONLY_ARB 0x88B9 +#define GL_READ_WRITE_ARB 0x88BA +#define GL_BUFFER_ACCESS_ARB 0x88BB +#define GL_BUFFER_MAPPED_ARB 0x88BC +#define GL_BUFFER_MAP_POINTER_ARB 0x88BD +#define GL_STREAM_DRAW_ARB 0x88E0 +#define GL_STREAM_READ_ARB 0x88E1 +#define GL_STREAM_COPY_ARB 0x88E2 +#define GL_STATIC_DRAW_ARB 0x88E4 +#define GL_STATIC_READ_ARB 0x88E5 +#define GL_STATIC_COPY_ARB 0x88E6 +#define GL_DYNAMIC_DRAW_ARB 0x88E8 +#define GL_DYNAMIC_READ_ARB 0x88E9 +#define GL_DYNAMIC_COPY_ARB 0x88EA +#endif + +#ifndef GL_ARB_occlusion_query +#define GL_QUERY_COUNTER_BITS_ARB 0x8864 +#define GL_CURRENT_QUERY_ARB 0x8865 +#define GL_QUERY_RESULT_ARB 0x8866 +#define GL_QUERY_RESULT_AVAILABLE_ARB 0x8867 +#define GL_SAMPLES_PASSED_ARB 0x8914 +#endif + +#ifndef GL_ARB_shader_objects +#define GL_PROGRAM_OBJECT_ARB 0x8B40 +#define GL_SHADER_OBJECT_ARB 0x8B48 +#define GL_OBJECT_TYPE_ARB 0x8B4E +#define GL_OBJECT_SUBTYPE_ARB 0x8B4F +#define GL_FLOAT_VEC2_ARB 0x8B50 +#define GL_FLOAT_VEC3_ARB 0x8B51 +#define GL_FLOAT_VEC4_ARB 0x8B52 +#define GL_INT_VEC2_ARB 0x8B53 +#define GL_INT_VEC3_ARB 0x8B54 +#define GL_INT_VEC4_ARB 0x8B55 +#define GL_BOOL_ARB 0x8B56 +#define GL_BOOL_VEC2_ARB 0x8B57 +#define GL_BOOL_VEC3_ARB 0x8B58 +#define GL_BOOL_VEC4_ARB 0x8B59 +#define GL_FLOAT_MAT2_ARB 0x8B5A +#define GL_FLOAT_MAT3_ARB 0x8B5B +#define GL_FLOAT_MAT4_ARB 0x8B5C +#define GL_SAMPLER_1D_ARB 0x8B5D +#define GL_SAMPLER_2D_ARB 0x8B5E +#define GL_SAMPLER_3D_ARB 0x8B5F +#define GL_SAMPLER_CUBE_ARB 0x8B60 +#define GL_SAMPLER_1D_SHADOW_ARB 0x8B61 +#define GL_SAMPLER_2D_SHADOW_ARB 0x8B62 +#define GL_SAMPLER_2D_RECT_ARB 0x8B63 +#define GL_SAMPLER_2D_RECT_SHADOW_ARB 0x8B64 +#define GL_OBJECT_DELETE_STATUS_ARB 0x8B80 +#define GL_OBJECT_COMPILE_STATUS_ARB 0x8B81 +#define GL_OBJECT_LINK_STATUS_ARB 0x8B82 +#define GL_OBJECT_VALIDATE_STATUS_ARB 0x8B83 +#define GL_OBJECT_INFO_LOG_LENGTH_ARB 0x8B84 +#define GL_OBJECT_ATTACHED_OBJECTS_ARB 0x8B85 +#define GL_OBJECT_ACTIVE_UNIFORMS_ARB 0x8B86 +#define GL_OBJECT_ACTIVE_UNIFORM_MAX_LENGTH_ARB 0x8B87 +#define GL_OBJECT_SHADER_SOURCE_LENGTH_ARB 0x8B88 +#endif + +#ifndef GL_ARB_vertex_shader +#define GL_VERTEX_SHADER_ARB 0x8B31 +#define GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB 0x8B4A +#define GL_MAX_VARYING_FLOATS_ARB 0x8B4B +#define GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB 0x8B4C +#define GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS_ARB 0x8B4D +#define GL_OBJECT_ACTIVE_ATTRIBUTES_ARB 0x8B89 +#define GL_OBJECT_ACTIVE_ATTRIBUTE_MAX_LENGTH_ARB 0x8B8A +#endif + +#ifndef GL_ARB_fragment_shader +#define GL_FRAGMENT_SHADER_ARB 0x8B30 +#define GL_MAX_FRAGMENT_UNIFORM_COMPONENTS_ARB 0x8B49 +#define GL_FRAGMENT_SHADER_DERIVATIVE_HINT_ARB 0x8B8B +#endif + +#ifndef GL_ARB_shading_language_100 +#define GL_SHADING_LANGUAGE_VERSION_ARB 0x8B8C +#endif + +#ifndef GL_ARB_texture_non_power_of_two +#endif + +#ifndef GL_ARB_point_sprite +#define GL_POINT_SPRITE_ARB 0x8861 +#define GL_COORD_REPLACE_ARB 0x8862 +#endif + +#ifndef GL_ARB_fragment_program_shadow +#endif + +#ifndef GL_ARB_draw_buffers +#define GL_MAX_DRAW_BUFFERS_ARB 0x8824 +#define GL_DRAW_BUFFER0_ARB 0x8825 +#define GL_DRAW_BUFFER1_ARB 0x8826 +#define GL_DRAW_BUFFER2_ARB 0x8827 +#define GL_DRAW_BUFFER3_ARB 0x8828 +#define GL_DRAW_BUFFER4_ARB 0x8829 +#define GL_DRAW_BUFFER5_ARB 0x882A +#define GL_DRAW_BUFFER6_ARB 0x882B +#define GL_DRAW_BUFFER7_ARB 0x882C +#define GL_DRAW_BUFFER8_ARB 0x882D +#define GL_DRAW_BUFFER9_ARB 0x882E +#define GL_DRAW_BUFFER10_ARB 0x882F +#define GL_DRAW_BUFFER11_ARB 0x8830 +#define GL_DRAW_BUFFER12_ARB 0x8831 +#define GL_DRAW_BUFFER13_ARB 0x8832 +#define GL_DRAW_BUFFER14_ARB 0x8833 +#define GL_DRAW_BUFFER15_ARB 0x8834 +#endif + +#ifndef GL_ARB_texture_rectangle +#define GL_TEXTURE_RECTANGLE_ARB 0x84F5 +#define GL_TEXTURE_BINDING_RECTANGLE_ARB 0x84F6 +#define GL_PROXY_TEXTURE_RECTANGLE_ARB 0x84F7 +#define GL_MAX_RECTANGLE_TEXTURE_SIZE_ARB 0x84F8 +#endif + +#ifndef GL_ARB_color_buffer_float +#define GL_RGBA_FLOAT_MODE_ARB 0x8820 +#define GL_CLAMP_VERTEX_COLOR_ARB 0x891A +#define GL_CLAMP_FRAGMENT_COLOR_ARB 0x891B +#define GL_CLAMP_READ_COLOR_ARB 0x891C +#define GL_FIXED_ONLY_ARB 0x891D +#endif + +#ifndef GL_ARB_half_float_pixel +#define GL_HALF_FLOAT_ARB 0x140B +#endif + +#ifndef GL_ARB_texture_float +#define GL_TEXTURE_RED_TYPE_ARB 0x8C10 +#define GL_TEXTURE_GREEN_TYPE_ARB 0x8C11 +#define GL_TEXTURE_BLUE_TYPE_ARB 0x8C12 +#define GL_TEXTURE_ALPHA_TYPE_ARB 0x8C13 +#define GL_TEXTURE_LUMINANCE_TYPE_ARB 0x8C14 +#define GL_TEXTURE_INTENSITY_TYPE_ARB 0x8C15 +#define GL_TEXTURE_DEPTH_TYPE_ARB 0x8C16 +#define GL_UNSIGNED_NORMALIZED_ARB 0x8C17 +#define GL_RGBA32F_ARB 0x8814 +#define GL_RGB32F_ARB 0x8815 +#define GL_ALPHA32F_ARB 0x8816 +#define GL_INTENSITY32F_ARB 0x8817 +#define GL_LUMINANCE32F_ARB 0x8818 +#define GL_LUMINANCE_ALPHA32F_ARB 0x8819 +#define GL_RGBA16F_ARB 0x881A +#define GL_RGB16F_ARB 0x881B +#define GL_ALPHA16F_ARB 0x881C +#define GL_INTENSITY16F_ARB 0x881D +#define GL_LUMINANCE16F_ARB 0x881E +#define GL_LUMINANCE_ALPHA16F_ARB 0x881F +#endif + +#ifndef GL_ARB_pixel_buffer_object +#define GL_PIXEL_PACK_BUFFER_ARB 0x88EB +#define GL_PIXEL_UNPACK_BUFFER_ARB 0x88EC +#define GL_PIXEL_PACK_BUFFER_BINDING_ARB 0x88ED +#define GL_PIXEL_UNPACK_BUFFER_BINDING_ARB 0x88EF +#endif + +#ifndef GL_ARB_depth_buffer_float +#define GL_DEPTH_COMPONENT32F 0x8CAC +#define GL_DEPTH32F_STENCIL8 0x8CAD +#define GL_FLOAT_32_UNSIGNED_INT_24_8_REV 0x8DAD +#endif + +#ifndef GL_ARB_draw_instanced +#endif + +#ifndef GL_ARB_framebuffer_object +#define GL_INVALID_FRAMEBUFFER_OPERATION 0x0506 +#define GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING 0x8210 +#define GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE 0x8211 +#define GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE 0x8212 +#define GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE 0x8213 +#define GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE 0x8214 +#define GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE 0x8215 +#define GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE 0x8216 +#define GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE 0x8217 +#define GL_FRAMEBUFFER_DEFAULT 0x8218 +#define GL_FRAMEBUFFER_UNDEFINED 0x8219 +#define GL_DEPTH_STENCIL_ATTACHMENT 0x821A +#define GL_MAX_RENDERBUFFER_SIZE 0x84E8 +#define GL_DEPTH_STENCIL 0x84F9 +#define GL_UNSIGNED_INT_24_8 0x84FA +#define GL_DEPTH24_STENCIL8 0x88F0 +#define GL_TEXTURE_STENCIL_SIZE 0x88F1 +#define GL_TEXTURE_RED_TYPE 0x8C10 +#define GL_TEXTURE_GREEN_TYPE 0x8C11 +#define GL_TEXTURE_BLUE_TYPE 0x8C12 +#define GL_TEXTURE_ALPHA_TYPE 0x8C13 +#define GL_TEXTURE_DEPTH_TYPE 0x8C16 +#define GL_UNSIGNED_NORMALIZED 0x8C17 +#define GL_FRAMEBUFFER_BINDING 0x8CA6 +#define GL_DRAW_FRAMEBUFFER_BINDING GL_FRAMEBUFFER_BINDING +#define GL_RENDERBUFFER_BINDING 0x8CA7 +#define GL_READ_FRAMEBUFFER 0x8CA8 +#define GL_DRAW_FRAMEBUFFER 0x8CA9 +#define GL_READ_FRAMEBUFFER_BINDING 0x8CAA +#define GL_RENDERBUFFER_SAMPLES 0x8CAB +#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE 0x8CD0 +#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME 0x8CD1 +#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL 0x8CD2 +#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE 0x8CD3 +#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER 0x8CD4 +#define GL_FRAMEBUFFER_COMPLETE 0x8CD5 +#define GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT 0x8CD6 +#define GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT 0x8CD7 +#define GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER 0x8CDB +#define GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER 0x8CDC +#define GL_FRAMEBUFFER_UNSUPPORTED 0x8CDD +#define GL_MAX_COLOR_ATTACHMENTS 0x8CDF +#define GL_COLOR_ATTACHMENT0 0x8CE0 +#define GL_COLOR_ATTACHMENT1 0x8CE1 +#define GL_COLOR_ATTACHMENT2 0x8CE2 +#define GL_COLOR_ATTACHMENT3 0x8CE3 +#define GL_COLOR_ATTACHMENT4 0x8CE4 +#define GL_COLOR_ATTACHMENT5 0x8CE5 +#define GL_COLOR_ATTACHMENT6 0x8CE6 +#define GL_COLOR_ATTACHMENT7 0x8CE7 +#define GL_COLOR_ATTACHMENT8 0x8CE8 +#define GL_COLOR_ATTACHMENT9 0x8CE9 +#define GL_COLOR_ATTACHMENT10 0x8CEA +#define GL_COLOR_ATTACHMENT11 0x8CEB +#define GL_COLOR_ATTACHMENT12 0x8CEC +#define GL_COLOR_ATTACHMENT13 0x8CED +#define GL_COLOR_ATTACHMENT14 0x8CEE +#define GL_COLOR_ATTACHMENT15 0x8CEF +#define GL_DEPTH_ATTACHMENT 0x8D00 +#define GL_STENCIL_ATTACHMENT 0x8D20 +#define GL_FRAMEBUFFER 0x8D40 +#define GL_RENDERBUFFER 0x8D41 +#define GL_RENDERBUFFER_WIDTH 0x8D42 +#define GL_RENDERBUFFER_HEIGHT 0x8D43 +#define GL_RENDERBUFFER_INTERNAL_FORMAT 0x8D44 +#define GL_STENCIL_INDEX1 0x8D46 +#define GL_STENCIL_INDEX4 0x8D47 +#define GL_STENCIL_INDEX8 0x8D48 +#define GL_STENCIL_INDEX16 0x8D49 +#define GL_RENDERBUFFER_RED_SIZE 0x8D50 +#define GL_RENDERBUFFER_GREEN_SIZE 0x8D51 +#define GL_RENDERBUFFER_BLUE_SIZE 0x8D52 +#define GL_RENDERBUFFER_ALPHA_SIZE 0x8D53 +#define GL_RENDERBUFFER_DEPTH_SIZE 0x8D54 +#define GL_RENDERBUFFER_STENCIL_SIZE 0x8D55 +#define GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE 0x8D56 +#define GL_MAX_SAMPLES 0x8D57 +#endif + +#ifndef GL_ARB_framebuffer_object_DEPRECATED +#define GL_INDEX 0x8222 +#define GL_TEXTURE_LUMINANCE_TYPE 0x8C14 +#define GL_TEXTURE_INTENSITY_TYPE 0x8C15 +#endif + +#ifndef GL_ARB_framebuffer_sRGB +#define GL_FRAMEBUFFER_SRGB 0x8DB9 +#endif + +#ifndef GL_ARB_geometry_shader4 +#define GL_LINES_ADJACENCY_ARB 0x000A +#define GL_LINE_STRIP_ADJACENCY_ARB 0x000B +#define GL_TRIANGLES_ADJACENCY_ARB 0x000C +#define GL_TRIANGLE_STRIP_ADJACENCY_ARB 0x000D +#define GL_PROGRAM_POINT_SIZE_ARB 0x8642 +#define GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_ARB 0x8C29 +#define GL_FRAMEBUFFER_ATTACHMENT_LAYERED_ARB 0x8DA7 +#define GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS_ARB 0x8DA8 +#define GL_FRAMEBUFFER_INCOMPLETE_LAYER_COUNT_ARB 0x8DA9 +#define GL_GEOMETRY_SHADER_ARB 0x8DD9 +#define GL_GEOMETRY_VERTICES_OUT_ARB 0x8DDA +#define GL_GEOMETRY_INPUT_TYPE_ARB 0x8DDB +#define GL_GEOMETRY_OUTPUT_TYPE_ARB 0x8DDC +#define GL_MAX_GEOMETRY_VARYING_COMPONENTS_ARB 0x8DDD +#define GL_MAX_VERTEX_VARYING_COMPONENTS_ARB 0x8DDE +#define GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_ARB 0x8DDF +#define GL_MAX_GEOMETRY_OUTPUT_VERTICES_ARB 0x8DE0 +#define GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_ARB 0x8DE1 +/* reuse GL_MAX_VARYING_COMPONENTS */ +/* reuse GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER */ +#endif + +#ifndef GL_ARB_half_float_vertex +#define GL_HALF_FLOAT 0x140B +#endif + +#ifndef GL_ARB_instanced_arrays +#define GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ARB 0x88FE +#endif + +#ifndef GL_ARB_map_buffer_range +#define GL_MAP_READ_BIT 0x0001 +#define GL_MAP_WRITE_BIT 0x0002 +#define GL_MAP_INVALIDATE_RANGE_BIT 0x0004 +#define GL_MAP_INVALIDATE_BUFFER_BIT 0x0008 +#define GL_MAP_FLUSH_EXPLICIT_BIT 0x0010 +#define GL_MAP_UNSYNCHRONIZED_BIT 0x0020 +#endif + +#ifndef GL_ARB_texture_buffer_object +#define GL_TEXTURE_BUFFER_ARB 0x8C2A +#define GL_MAX_TEXTURE_BUFFER_SIZE_ARB 0x8C2B +#define GL_TEXTURE_BINDING_BUFFER_ARB 0x8C2C +#define GL_TEXTURE_BUFFER_DATA_STORE_BINDING_ARB 0x8C2D +#define GL_TEXTURE_BUFFER_FORMAT_ARB 0x8C2E +#endif + +#ifndef GL_ARB_texture_compression_rgtc +#define GL_COMPRESSED_RED_RGTC1 0x8DBB +#define GL_COMPRESSED_SIGNED_RED_RGTC1 0x8DBC +#define GL_COMPRESSED_RG_RGTC2 0x8DBD +#define GL_COMPRESSED_SIGNED_RG_RGTC2 0x8DBE +#endif + +#ifndef GL_ARB_texture_rg +#define GL_RG 0x8227 +#define GL_RG_INTEGER 0x8228 +#define GL_R8 0x8229 +#define GL_R16 0x822A +#define GL_RG8 0x822B +#define GL_RG16 0x822C +#define GL_R16F 0x822D +#define GL_R32F 0x822E +#define GL_RG16F 0x822F +#define GL_RG32F 0x8230 +#define GL_R8I 0x8231 +#define GL_R8UI 0x8232 +#define GL_R16I 0x8233 +#define GL_R16UI 0x8234 +#define GL_R32I 0x8235 +#define GL_R32UI 0x8236 +#define GL_RG8I 0x8237 +#define GL_RG8UI 0x8238 +#define GL_RG16I 0x8239 +#define GL_RG16UI 0x823A +#define GL_RG32I 0x823B +#define GL_RG32UI 0x823C +#endif + +#ifndef GL_ARB_vertex_array_object +#define GL_VERTEX_ARRAY_BINDING 0x85B5 +#endif + +#ifndef GL_ARB_uniform_buffer_object +#define GL_UNIFORM_BUFFER 0x8A11 +#define GL_UNIFORM_BUFFER_BINDING 0x8A28 +#define GL_UNIFORM_BUFFER_START 0x8A29 +#define GL_UNIFORM_BUFFER_SIZE 0x8A2A +#define GL_MAX_VERTEX_UNIFORM_BLOCKS 0x8A2B +#define GL_MAX_GEOMETRY_UNIFORM_BLOCKS 0x8A2C +#define GL_MAX_FRAGMENT_UNIFORM_BLOCKS 0x8A2D +#define GL_MAX_COMBINED_UNIFORM_BLOCKS 0x8A2E +#define GL_MAX_UNIFORM_BUFFER_BINDINGS 0x8A2F +#define GL_MAX_UNIFORM_BLOCK_SIZE 0x8A30 +#define GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS 0x8A31 +#define GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS 0x8A32 +#define GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS 0x8A33 +#define GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT 0x8A34 +#define GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH 0x8A35 +#define GL_ACTIVE_UNIFORM_BLOCKS 0x8A36 +#define GL_UNIFORM_TYPE 0x8A37 +#define GL_UNIFORM_SIZE 0x8A38 +#define GL_UNIFORM_NAME_LENGTH 0x8A39 +#define GL_UNIFORM_BLOCK_INDEX 0x8A3A +#define GL_UNIFORM_OFFSET 0x8A3B +#define GL_UNIFORM_ARRAY_STRIDE 0x8A3C +#define GL_UNIFORM_MATRIX_STRIDE 0x8A3D +#define GL_UNIFORM_IS_ROW_MAJOR 0x8A3E +#define GL_UNIFORM_BLOCK_BINDING 0x8A3F +#define GL_UNIFORM_BLOCK_DATA_SIZE 0x8A40 +#define GL_UNIFORM_BLOCK_NAME_LENGTH 0x8A41 +#define GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS 0x8A42 +#define GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES 0x8A43 +#define GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER 0x8A44 +#define GL_UNIFORM_BLOCK_REFERENCED_BY_GEOMETRY_SHADER 0x8A45 +#define GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER 0x8A46 +#define GL_INVALID_INDEX 0xFFFFFFFFu +#endif + +#ifndef GL_ARB_compatibility +/* ARB_compatibility just defines tokens from core 3.0 */ +#endif + +#ifndef GL_ARB_copy_buffer +#define GL_COPY_READ_BUFFER 0x8F36 +#define GL_COPY_WRITE_BUFFER 0x8F37 +#endif + +#ifndef GL_ARB_shader_texture_lod +#endif + +#ifndef GL_ARB_depth_clamp +#define GL_DEPTH_CLAMP 0x864F +#endif + +#ifndef GL_ARB_draw_elements_base_vertex +#endif + +#ifndef GL_ARB_fragment_coord_conventions +#endif + +#ifndef GL_ARB_provoking_vertex +#define GL_QUADS_FOLLOW_PROVOKING_VERTEX_CONVENTION 0x8E4C +#define GL_FIRST_VERTEX_CONVENTION 0x8E4D +#define GL_LAST_VERTEX_CONVENTION 0x8E4E +#define GL_PROVOKING_VERTEX 0x8E4F +#endif + +#ifndef GL_ARB_seamless_cube_map +#define GL_TEXTURE_CUBE_MAP_SEAMLESS 0x884F +#endif + +#ifndef GL_ARB_sync +#define GL_MAX_SERVER_WAIT_TIMEOUT 0x9111 +#define GL_OBJECT_TYPE 0x9112 +#define GL_SYNC_CONDITION 0x9113 +#define GL_SYNC_STATUS 0x9114 +#define GL_SYNC_FLAGS 0x9115 +#define GL_SYNC_FENCE 0x9116 +#define GL_SYNC_GPU_COMMANDS_COMPLETE 0x9117 +#define GL_UNSIGNALED 0x9118 +#define GL_SIGNALED 0x9119 +#define GL_ALREADY_SIGNALED 0x911A +#define GL_TIMEOUT_EXPIRED 0x911B +#define GL_CONDITION_SATISFIED 0x911C +#define GL_WAIT_FAILED 0x911D +#define GL_SYNC_FLUSH_COMMANDS_BIT 0x00000001 +#define GL_TIMEOUT_IGNORED 0xFFFFFFFFFFFFFFFFull +#endif + +#ifndef GL_ARB_texture_multisample +#define GL_SAMPLE_POSITION 0x8E50 +#define GL_SAMPLE_MASK 0x8E51 +#define GL_SAMPLE_MASK_VALUE 0x8E52 +#define GL_MAX_SAMPLE_MASK_WORDS 0x8E59 +#define GL_TEXTURE_2D_MULTISAMPLE 0x9100 +#define GL_PROXY_TEXTURE_2D_MULTISAMPLE 0x9101 +#define GL_TEXTURE_2D_MULTISAMPLE_ARRAY 0x9102 +#define GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY 0x9103 +#define GL_TEXTURE_BINDING_2D_MULTISAMPLE 0x9104 +#define GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY 0x9105 +#define GL_TEXTURE_SAMPLES 0x9106 +#define GL_TEXTURE_FIXED_SAMPLE_LOCATIONS 0x9107 +#define GL_SAMPLER_2D_MULTISAMPLE 0x9108 +#define GL_INT_SAMPLER_2D_MULTISAMPLE 0x9109 +#define GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE 0x910A +#define GL_SAMPLER_2D_MULTISAMPLE_ARRAY 0x910B +#define GL_INT_SAMPLER_2D_MULTISAMPLE_ARRAY 0x910C +#define GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY 0x910D +#define GL_MAX_COLOR_TEXTURE_SAMPLES 0x910E +#define GL_MAX_DEPTH_TEXTURE_SAMPLES 0x910F +#define GL_MAX_INTEGER_SAMPLES 0x9110 +#endif + +#ifndef GL_ARB_vertex_array_bgra +/* reuse GL_BGRA */ +#endif + +#ifndef GL_ARB_draw_buffers_blend +#endif + +#ifndef GL_ARB_sample_shading +#define GL_SAMPLE_SHADING_ARB 0x8C36 +#define GL_MIN_SAMPLE_SHADING_VALUE_ARB 0x8C37 +#endif + +#ifndef GL_ARB_texture_cube_map_array +#define GL_TEXTURE_CUBE_MAP_ARRAY_ARB 0x9009 +#define GL_TEXTURE_BINDING_CUBE_MAP_ARRAY_ARB 0x900A +#define GL_PROXY_TEXTURE_CUBE_MAP_ARRAY_ARB 0x900B +#define GL_SAMPLER_CUBE_MAP_ARRAY_ARB 0x900C +#define GL_SAMPLER_CUBE_MAP_ARRAY_SHADOW_ARB 0x900D +#define GL_INT_SAMPLER_CUBE_MAP_ARRAY_ARB 0x900E +#define GL_UNSIGNED_INT_SAMPLER_CUBE_MAP_ARRAY_ARB 0x900F +#endif + +#ifndef GL_ARB_texture_gather +#define GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET_ARB 0x8E5E +#define GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET_ARB 0x8E5F +#endif + +#ifndef GL_ARB_texture_query_lod +#endif + +#ifndef GL_ARB_shading_language_include +#define GL_SHADER_INCLUDE_ARB 0x8DAE +#define GL_NAMED_STRING_LENGTH_ARB 0x8DE9 +#define GL_NAMED_STRING_TYPE_ARB 0x8DEA +#endif + +#ifndef GL_ARB_texture_compression_bptc +#define GL_COMPRESSED_RGBA_BPTC_UNORM_ARB 0x8E8C +#define GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_ARB 0x8E8D +#define GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB 0x8E8E +#define GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_ARB 0x8E8F +#endif + +#ifndef GL_ARB_blend_func_extended +#define GL_SRC1_COLOR 0x88F9 +/* reuse GL_SRC1_ALPHA */ +#define GL_ONE_MINUS_SRC1_COLOR 0x88FA +#define GL_ONE_MINUS_SRC1_ALPHA 0x88FB +#define GL_MAX_DUAL_SOURCE_DRAW_BUFFERS 0x88FC +#endif + +#ifndef GL_ARB_explicit_attrib_location +#endif + +#ifndef GL_ARB_occlusion_query2 +#define GL_ANY_SAMPLES_PASSED 0x8C2F +#endif + +#ifndef GL_ARB_sampler_objects +#define GL_SAMPLER_BINDING 0x8919 +#endif + +#ifndef GL_ARB_shader_bit_encoding +#endif + +#ifndef GL_ARB_texture_rgb10_a2ui +#define GL_RGB10_A2UI 0x906F +#endif + +#ifndef GL_ARB_texture_swizzle +#define GL_TEXTURE_SWIZZLE_R 0x8E42 +#define GL_TEXTURE_SWIZZLE_G 0x8E43 +#define GL_TEXTURE_SWIZZLE_B 0x8E44 +#define GL_TEXTURE_SWIZZLE_A 0x8E45 +#define GL_TEXTURE_SWIZZLE_RGBA 0x8E46 +#endif + +#ifndef GL_ARB_timer_query +#define GL_TIME_ELAPSED 0x88BF +#define GL_TIMESTAMP 0x8E28 +#endif + +#ifndef GL_ARB_vertex_type_2_10_10_10_rev +/* reuse GL_UNSIGNED_INT_2_10_10_10_REV */ +#define GL_INT_2_10_10_10_REV 0x8D9F +#endif + +#ifndef GL_ARB_draw_indirect +#define GL_DRAW_INDIRECT_BUFFER 0x8F3F +#define GL_DRAW_INDIRECT_BUFFER_BINDING 0x8F43 +#endif + +#ifndef GL_ARB_gpu_shader5 +#define GL_GEOMETRY_SHADER_INVOCATIONS 0x887F +#define GL_MAX_GEOMETRY_SHADER_INVOCATIONS 0x8E5A +#define GL_MIN_FRAGMENT_INTERPOLATION_OFFSET 0x8E5B +#define GL_MAX_FRAGMENT_INTERPOLATION_OFFSET 0x8E5C +#define GL_FRAGMENT_INTERPOLATION_OFFSET_BITS 0x8E5D +/* reuse GL_MAX_VERTEX_STREAMS */ +#endif + +#ifndef GL_ARB_gpu_shader_fp64 +/* reuse GL_DOUBLE */ +#define GL_DOUBLE_VEC2 0x8FFC +#define GL_DOUBLE_VEC3 0x8FFD +#define GL_DOUBLE_VEC4 0x8FFE +#define GL_DOUBLE_MAT2 0x8F46 +#define GL_DOUBLE_MAT3 0x8F47 +#define GL_DOUBLE_MAT4 0x8F48 +#define GL_DOUBLE_MAT2x3 0x8F49 +#define GL_DOUBLE_MAT2x4 0x8F4A +#define GL_DOUBLE_MAT3x2 0x8F4B +#define GL_DOUBLE_MAT3x4 0x8F4C +#define GL_DOUBLE_MAT4x2 0x8F4D +#define GL_DOUBLE_MAT4x3 0x8F4E +#endif + +#ifndef GL_ARB_shader_subroutine +#define GL_ACTIVE_SUBROUTINES 0x8DE5 +#define GL_ACTIVE_SUBROUTINE_UNIFORMS 0x8DE6 +#define GL_ACTIVE_SUBROUTINE_UNIFORM_LOCATIONS 0x8E47 +#define GL_ACTIVE_SUBROUTINE_MAX_LENGTH 0x8E48 +#define GL_ACTIVE_SUBROUTINE_UNIFORM_MAX_LENGTH 0x8E49 +#define GL_MAX_SUBROUTINES 0x8DE7 +#define GL_MAX_SUBROUTINE_UNIFORM_LOCATIONS 0x8DE8 +#define GL_NUM_COMPATIBLE_SUBROUTINES 0x8E4A +#define GL_COMPATIBLE_SUBROUTINES 0x8E4B +/* reuse GL_UNIFORM_SIZE */ +/* reuse GL_UNIFORM_NAME_LENGTH */ +#endif + +#ifndef GL_ARB_tessellation_shader +#define GL_PATCHES 0x000E +#define GL_PATCH_VERTICES 0x8E72 +#define GL_PATCH_DEFAULT_INNER_LEVEL 0x8E73 +#define GL_PATCH_DEFAULT_OUTER_LEVEL 0x8E74 +#define GL_TESS_CONTROL_OUTPUT_VERTICES 0x8E75 +#define GL_TESS_GEN_MODE 0x8E76 +#define GL_TESS_GEN_SPACING 0x8E77 +#define GL_TESS_GEN_VERTEX_ORDER 0x8E78 +#define GL_TESS_GEN_POINT_MODE 0x8E79 +/* reuse GL_TRIANGLES */ +/* reuse GL_QUADS */ +#define GL_ISOLINES 0x8E7A +/* reuse GL_EQUAL */ +#define GL_FRACTIONAL_ODD 0x8E7B +#define GL_FRACTIONAL_EVEN 0x8E7C +/* reuse GL_CCW */ +/* reuse GL_CW */ +#define GL_MAX_PATCH_VERTICES 0x8E7D +#define GL_MAX_TESS_GEN_LEVEL 0x8E7E +#define GL_MAX_TESS_CONTROL_UNIFORM_COMPONENTS 0x8E7F +#define GL_MAX_TESS_EVALUATION_UNIFORM_COMPONENTS 0x8E80 +#define GL_MAX_TESS_CONTROL_TEXTURE_IMAGE_UNITS 0x8E81 +#define GL_MAX_TESS_EVALUATION_TEXTURE_IMAGE_UNITS 0x8E82 +#define GL_MAX_TESS_CONTROL_OUTPUT_COMPONENTS 0x8E83 +#define GL_MAX_TESS_PATCH_COMPONENTS 0x8E84 +#define GL_MAX_TESS_CONTROL_TOTAL_OUTPUT_COMPONENTS 0x8E85 +#define GL_MAX_TESS_EVALUATION_OUTPUT_COMPONENTS 0x8E86 +#define GL_MAX_TESS_CONTROL_UNIFORM_BLOCKS 0x8E89 +#define GL_MAX_TESS_EVALUATION_UNIFORM_BLOCKS 0x8E8A +#define GL_MAX_TESS_CONTROL_INPUT_COMPONENTS 0x886C +#define GL_MAX_TESS_EVALUATION_INPUT_COMPONENTS 0x886D +#define GL_MAX_COMBINED_TESS_CONTROL_UNIFORM_COMPONENTS 0x8E1E +#define GL_MAX_COMBINED_TESS_EVALUATION_UNIFORM_COMPONENTS 0x8E1F +#define GL_UNIFORM_BLOCK_REFERENCED_BY_TESS_CONTROL_SHADER 0x84F0 +#define GL_UNIFORM_BLOCK_REFERENCED_BY_TESS_EVALUATION_SHADER 0x84F1 +#define GL_TESS_EVALUATION_SHADER 0x8E87 +#define GL_TESS_CONTROL_SHADER 0x8E88 +#endif + +#ifndef GL_ARB_texture_buffer_object_rgb32 +/* reuse GL_RGB32F */ +/* reuse GL_RGB32UI */ +/* reuse GL_RGB32I */ +#endif + +#ifndef GL_ARB_transform_feedback2 +#define GL_TRANSFORM_FEEDBACK 0x8E22 +#define GL_TRANSFORM_FEEDBACK_BUFFER_PAUSED 0x8E23 +#define GL_TRANSFORM_FEEDBACK_BUFFER_ACTIVE 0x8E24 +#define GL_TRANSFORM_FEEDBACK_BINDING 0x8E25 +#endif + +#ifndef GL_ARB_transform_feedback3 +#define GL_MAX_TRANSFORM_FEEDBACK_BUFFERS 0x8E70 +#define GL_MAX_VERTEX_STREAMS 0x8E71 +#endif + +#ifndef GL_ARB_ES2_compatibility +#define GL_FIXED 0x140C +#define GL_IMPLEMENTATION_COLOR_READ_TYPE 0x8B9A +#define GL_IMPLEMENTATION_COLOR_READ_FORMAT 0x8B9B +#define GL_LOW_FLOAT 0x8DF0 +#define GL_MEDIUM_FLOAT 0x8DF1 +#define GL_HIGH_FLOAT 0x8DF2 +#define GL_LOW_INT 0x8DF3 +#define GL_MEDIUM_INT 0x8DF4 +#define GL_HIGH_INT 0x8DF5 +#define GL_SHADER_COMPILER 0x8DFA +#define GL_NUM_SHADER_BINARY_FORMATS 0x8DF9 +#define GL_MAX_VERTEX_UNIFORM_VECTORS 0x8DFB +#define GL_MAX_VARYING_VECTORS 0x8DFC +#define GL_MAX_FRAGMENT_UNIFORM_VECTORS 0x8DFD +#endif + +#ifndef GL_ARB_get_program_binary +#define GL_PROGRAM_BINARY_RETRIEVABLE_HINT 0x8257 +#define GL_PROGRAM_BINARY_LENGTH 0x8741 +#define GL_NUM_PROGRAM_BINARY_FORMATS 0x87FE +#define GL_PROGRAM_BINARY_FORMATS 0x87FF +#endif + +#ifndef GL_ARB_separate_shader_objects +#define GL_VERTEX_SHADER_BIT 0x00000001 +#define GL_FRAGMENT_SHADER_BIT 0x00000002 +#define GL_GEOMETRY_SHADER_BIT 0x00000004 +#define GL_TESS_CONTROL_SHADER_BIT 0x00000008 +#define GL_TESS_EVALUATION_SHADER_BIT 0x00000010 +#define GL_ALL_SHADER_BITS 0xFFFFFFFF +#define GL_PROGRAM_SEPARABLE 0x8258 +#define GL_ACTIVE_PROGRAM 0x8259 +#define GL_PROGRAM_PIPELINE_BINDING 0x825A +#endif + +#ifndef GL_ARB_shader_precision +#endif + +#ifndef GL_ARB_vertex_attrib_64bit +/* reuse GL_RGB32I */ +/* reuse GL_DOUBLE_VEC2 */ +/* reuse GL_DOUBLE_VEC3 */ +/* reuse GL_DOUBLE_VEC4 */ +/* reuse GL_DOUBLE_MAT2 */ +/* reuse GL_DOUBLE_MAT3 */ +/* reuse GL_DOUBLE_MAT4 */ +/* reuse GL_DOUBLE_MAT2x3 */ +/* reuse GL_DOUBLE_MAT2x4 */ +/* reuse GL_DOUBLE_MAT3x2 */ +/* reuse GL_DOUBLE_MAT3x4 */ +/* reuse GL_DOUBLE_MAT4x2 */ +/* reuse GL_DOUBLE_MAT4x3 */ +#endif + +#ifndef GL_ARB_viewport_array +/* reuse GL_SCISSOR_BOX */ +/* reuse GL_VIEWPORT */ +/* reuse GL_DEPTH_RANGE */ +/* reuse GL_SCISSOR_TEST */ +#define GL_MAX_VIEWPORTS 0x825B +#define GL_VIEWPORT_SUBPIXEL_BITS 0x825C +#define GL_VIEWPORT_BOUNDS_RANGE 0x825D +#define GL_LAYER_PROVOKING_VERTEX 0x825E +#define GL_VIEWPORT_INDEX_PROVOKING_VERTEX 0x825F +#define GL_UNDEFINED_VERTEX 0x8260 +/* reuse GL_FIRST_VERTEX_CONVENTION */ +/* reuse GL_LAST_VERTEX_CONVENTION */ +/* reuse GL_PROVOKING_VERTEX */ +#endif + +#ifndef GL_ARB_cl_event +#define GL_SYNC_CL_EVENT_ARB 0x8240 +#define GL_SYNC_CL_EVENT_COMPLETE_ARB 0x8241 +#endif + +#ifndef GL_ARB_debug_output +#define GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB 0x8242 +#define GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH_ARB 0x8243 +#define GL_DEBUG_CALLBACK_FUNCTION_ARB 0x8244 +#define GL_DEBUG_CALLBACK_USER_PARAM_ARB 0x8245 +#define GL_DEBUG_SOURCE_API_ARB 0x8246 +#define GL_DEBUG_SOURCE_WINDOW_SYSTEM_ARB 0x8247 +#define GL_DEBUG_SOURCE_SHADER_COMPILER_ARB 0x8248 +#define GL_DEBUG_SOURCE_THIRD_PARTY_ARB 0x8249 +#define GL_DEBUG_SOURCE_APPLICATION_ARB 0x824A +#define GL_DEBUG_SOURCE_OTHER_ARB 0x824B +#define GL_DEBUG_TYPE_ERROR_ARB 0x824C +#define GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_ARB 0x824D +#define GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_ARB 0x824E +#define GL_DEBUG_TYPE_PORTABILITY_ARB 0x824F +#define GL_DEBUG_TYPE_PERFORMANCE_ARB 0x8250 +#define GL_DEBUG_TYPE_OTHER_ARB 0x8251 +#define GL_MAX_DEBUG_MESSAGE_LENGTH_ARB 0x9143 +#define GL_MAX_DEBUG_LOGGED_MESSAGES_ARB 0x9144 +#define GL_DEBUG_LOGGED_MESSAGES_ARB 0x9145 +#define GL_DEBUG_SEVERITY_HIGH_ARB 0x9146 +#define GL_DEBUG_SEVERITY_MEDIUM_ARB 0x9147 +#define GL_DEBUG_SEVERITY_LOW_ARB 0x9148 +#endif + +#ifndef GL_ARB_robustness +/* reuse GL_NO_ERROR */ +#define GL_CONTEXT_FLAG_ROBUST_ACCESS_BIT_ARB 0x00000004 +#define GL_LOSE_CONTEXT_ON_RESET_ARB 0x8252 +#define GL_GUILTY_CONTEXT_RESET_ARB 0x8253 +#define GL_INNOCENT_CONTEXT_RESET_ARB 0x8254 +#define GL_UNKNOWN_CONTEXT_RESET_ARB 0x8255 +#define GL_RESET_NOTIFICATION_STRATEGY_ARB 0x8256 +#define GL_NO_RESET_NOTIFICATION_ARB 0x8261 +#endif + +#ifndef GL_ARB_shader_stencil_export +#endif + +#ifndef GL_EXT_abgr +#define GL_ABGR_EXT 0x8000 +#endif + +#ifndef GL_EXT_blend_color +#define GL_CONSTANT_COLOR_EXT 0x8001 +#define GL_ONE_MINUS_CONSTANT_COLOR_EXT 0x8002 +#define GL_CONSTANT_ALPHA_EXT 0x8003 +#define GL_ONE_MINUS_CONSTANT_ALPHA_EXT 0x8004 +#define GL_BLEND_COLOR_EXT 0x8005 +#endif + +#ifndef GL_EXT_polygon_offset +#define GL_POLYGON_OFFSET_EXT 0x8037 +#define GL_POLYGON_OFFSET_FACTOR_EXT 0x8038 +#define GL_POLYGON_OFFSET_BIAS_EXT 0x8039 +#endif + +#ifndef GL_EXT_texture +#define GL_ALPHA4_EXT 0x803B +#define GL_ALPHA8_EXT 0x803C +#define GL_ALPHA12_EXT 0x803D +#define GL_ALPHA16_EXT 0x803E +#define GL_LUMINANCE4_EXT 0x803F +#define GL_LUMINANCE8_EXT 0x8040 +#define GL_LUMINANCE12_EXT 0x8041 +#define GL_LUMINANCE16_EXT 0x8042 +#define GL_LUMINANCE4_ALPHA4_EXT 0x8043 +#define GL_LUMINANCE6_ALPHA2_EXT 0x8044 +#define GL_LUMINANCE8_ALPHA8_EXT 0x8045 +#define GL_LUMINANCE12_ALPHA4_EXT 0x8046 +#define GL_LUMINANCE12_ALPHA12_EXT 0x8047 +#define GL_LUMINANCE16_ALPHA16_EXT 0x8048 +#define GL_INTENSITY_EXT 0x8049 +#define GL_INTENSITY4_EXT 0x804A +#define GL_INTENSITY8_EXT 0x804B +#define GL_INTENSITY12_EXT 0x804C +#define GL_INTENSITY16_EXT 0x804D +#define GL_RGB2_EXT 0x804E +#define GL_RGB4_EXT 0x804F +#define GL_RGB5_EXT 0x8050 +#define GL_RGB8_EXT 0x8051 +#define GL_RGB10_EXT 0x8052 +#define GL_RGB12_EXT 0x8053 +#define GL_RGB16_EXT 0x8054 +#define GL_RGBA2_EXT 0x8055 +#define GL_RGBA4_EXT 0x8056 +#define GL_RGB5_A1_EXT 0x8057 +#define GL_RGBA8_EXT 0x8058 +#define GL_RGB10_A2_EXT 0x8059 +#define GL_RGBA12_EXT 0x805A +#define GL_RGBA16_EXT 0x805B +#define GL_TEXTURE_RED_SIZE_EXT 0x805C +#define GL_TEXTURE_GREEN_SIZE_EXT 0x805D +#define GL_TEXTURE_BLUE_SIZE_EXT 0x805E +#define GL_TEXTURE_ALPHA_SIZE_EXT 0x805F +#define GL_TEXTURE_LUMINANCE_SIZE_EXT 0x8060 +#define GL_TEXTURE_INTENSITY_SIZE_EXT 0x8061 +#define GL_REPLACE_EXT 0x8062 +#define GL_PROXY_TEXTURE_1D_EXT 0x8063 +#define GL_PROXY_TEXTURE_2D_EXT 0x8064 +#define GL_TEXTURE_TOO_LARGE_EXT 0x8065 +#endif + +#ifndef GL_EXT_texture3D +#define GL_PACK_SKIP_IMAGES_EXT 0x806B +#define GL_PACK_IMAGE_HEIGHT_EXT 0x806C +#define GL_UNPACK_SKIP_IMAGES_EXT 0x806D +#define GL_UNPACK_IMAGE_HEIGHT_EXT 0x806E +#define GL_TEXTURE_3D_EXT 0x806F +#define GL_PROXY_TEXTURE_3D_EXT 0x8070 +#define GL_TEXTURE_DEPTH_EXT 0x8071 +#define GL_TEXTURE_WRAP_R_EXT 0x8072 +#define GL_MAX_3D_TEXTURE_SIZE_EXT 0x8073 +#endif + +#ifndef GL_SGIS_texture_filter4 +#define GL_FILTER4_SGIS 0x8146 +#define GL_TEXTURE_FILTER4_SIZE_SGIS 0x8147 +#endif + +#ifndef GL_EXT_subtexture +#endif + +#ifndef GL_EXT_copy_texture +#endif + +#ifndef GL_EXT_histogram +#define GL_HISTOGRAM_EXT 0x8024 +#define GL_PROXY_HISTOGRAM_EXT 0x8025 +#define GL_HISTOGRAM_WIDTH_EXT 0x8026 +#define GL_HISTOGRAM_FORMAT_EXT 0x8027 +#define GL_HISTOGRAM_RED_SIZE_EXT 0x8028 +#define GL_HISTOGRAM_GREEN_SIZE_EXT 0x8029 +#define GL_HISTOGRAM_BLUE_SIZE_EXT 0x802A +#define GL_HISTOGRAM_ALPHA_SIZE_EXT 0x802B +#define GL_HISTOGRAM_LUMINANCE_SIZE_EXT 0x802C +#define GL_HISTOGRAM_SINK_EXT 0x802D +#define GL_MINMAX_EXT 0x802E +#define GL_MINMAX_FORMAT_EXT 0x802F +#define GL_MINMAX_SINK_EXT 0x8030 +#define GL_TABLE_TOO_LARGE_EXT 0x8031 +#endif + +#ifndef GL_EXT_convolution +#define GL_CONVOLUTION_1D_EXT 0x8010 +#define GL_CONVOLUTION_2D_EXT 0x8011 +#define GL_SEPARABLE_2D_EXT 0x8012 +#define GL_CONVOLUTION_BORDER_MODE_EXT 0x8013 +#define GL_CONVOLUTION_FILTER_SCALE_EXT 0x8014 +#define GL_CONVOLUTION_FILTER_BIAS_EXT 0x8015 +#define GL_REDUCE_EXT 0x8016 +#define GL_CONVOLUTION_FORMAT_EXT 0x8017 +#define GL_CONVOLUTION_WIDTH_EXT 0x8018 +#define GL_CONVOLUTION_HEIGHT_EXT 0x8019 +#define GL_MAX_CONVOLUTION_WIDTH_EXT 0x801A +#define GL_MAX_CONVOLUTION_HEIGHT_EXT 0x801B +#define GL_POST_CONVOLUTION_RED_SCALE_EXT 0x801C +#define GL_POST_CONVOLUTION_GREEN_SCALE_EXT 0x801D +#define GL_POST_CONVOLUTION_BLUE_SCALE_EXT 0x801E +#define GL_POST_CONVOLUTION_ALPHA_SCALE_EXT 0x801F +#define GL_POST_CONVOLUTION_RED_BIAS_EXT 0x8020 +#define GL_POST_CONVOLUTION_GREEN_BIAS_EXT 0x8021 +#define GL_POST_CONVOLUTION_BLUE_BIAS_EXT 0x8022 +#define GL_POST_CONVOLUTION_ALPHA_BIAS_EXT 0x8023 +#endif + +#ifndef GL_SGI_color_matrix +#define GL_COLOR_MATRIX_SGI 0x80B1 +#define GL_COLOR_MATRIX_STACK_DEPTH_SGI 0x80B2 +#define GL_MAX_COLOR_MATRIX_STACK_DEPTH_SGI 0x80B3 +#define GL_POST_COLOR_MATRIX_RED_SCALE_SGI 0x80B4 +#define GL_POST_COLOR_MATRIX_GREEN_SCALE_SGI 0x80B5 +#define GL_POST_COLOR_MATRIX_BLUE_SCALE_SGI 0x80B6 +#define GL_POST_COLOR_MATRIX_ALPHA_SCALE_SGI 0x80B7 +#define GL_POST_COLOR_MATRIX_RED_BIAS_SGI 0x80B8 +#define GL_POST_COLOR_MATRIX_GREEN_BIAS_SGI 0x80B9 +#define GL_POST_COLOR_MATRIX_BLUE_BIAS_SGI 0x80BA +#define GL_POST_COLOR_MATRIX_ALPHA_BIAS_SGI 0x80BB +#endif + +#ifndef GL_SGI_color_table +#define GL_COLOR_TABLE_SGI 0x80D0 +#define GL_POST_CONVOLUTION_COLOR_TABLE_SGI 0x80D1 +#define GL_POST_COLOR_MATRIX_COLOR_TABLE_SGI 0x80D2 +#define GL_PROXY_COLOR_TABLE_SGI 0x80D3 +#define GL_PROXY_POST_CONVOLUTION_COLOR_TABLE_SGI 0x80D4 +#define GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE_SGI 0x80D5 +#define GL_COLOR_TABLE_SCALE_SGI 0x80D6 +#define GL_COLOR_TABLE_BIAS_SGI 0x80D7 +#define GL_COLOR_TABLE_FORMAT_SGI 0x80D8 +#define GL_COLOR_TABLE_WIDTH_SGI 0x80D9 +#define GL_COLOR_TABLE_RED_SIZE_SGI 0x80DA +#define GL_COLOR_TABLE_GREEN_SIZE_SGI 0x80DB +#define GL_COLOR_TABLE_BLUE_SIZE_SGI 0x80DC +#define GL_COLOR_TABLE_ALPHA_SIZE_SGI 0x80DD +#define GL_COLOR_TABLE_LUMINANCE_SIZE_SGI 0x80DE +#define GL_COLOR_TABLE_INTENSITY_SIZE_SGI 0x80DF +#endif + +#ifndef GL_SGIS_pixel_texture +#define GL_PIXEL_TEXTURE_SGIS 0x8353 +#define GL_PIXEL_FRAGMENT_RGB_SOURCE_SGIS 0x8354 +#define GL_PIXEL_FRAGMENT_ALPHA_SOURCE_SGIS 0x8355 +#define GL_PIXEL_GROUP_COLOR_SGIS 0x8356 +#endif + +#ifndef GL_SGIX_pixel_texture +#define GL_PIXEL_TEX_GEN_SGIX 0x8139 +#define GL_PIXEL_TEX_GEN_MODE_SGIX 0x832B +#endif + +#ifndef GL_SGIS_texture4D +#define GL_PACK_SKIP_VOLUMES_SGIS 0x8130 +#define GL_PACK_IMAGE_DEPTH_SGIS 0x8131 +#define GL_UNPACK_SKIP_VOLUMES_SGIS 0x8132 +#define GL_UNPACK_IMAGE_DEPTH_SGIS 0x8133 +#define GL_TEXTURE_4D_SGIS 0x8134 +#define GL_PROXY_TEXTURE_4D_SGIS 0x8135 +#define GL_TEXTURE_4DSIZE_SGIS 0x8136 +#define GL_TEXTURE_WRAP_Q_SGIS 0x8137 +#define GL_MAX_4D_TEXTURE_SIZE_SGIS 0x8138 +#define GL_TEXTURE_4D_BINDING_SGIS 0x814F +#endif + +#ifndef GL_SGI_texture_color_table +#define GL_TEXTURE_COLOR_TABLE_SGI 0x80BC +#define GL_PROXY_TEXTURE_COLOR_TABLE_SGI 0x80BD +#endif + +#ifndef GL_EXT_cmyka +#define GL_CMYK_EXT 0x800C +#define GL_CMYKA_EXT 0x800D +#define GL_PACK_CMYK_HINT_EXT 0x800E +#define GL_UNPACK_CMYK_HINT_EXT 0x800F +#endif + +#ifndef GL_EXT_texture_object +#define GL_TEXTURE_PRIORITY_EXT 0x8066 +#define GL_TEXTURE_RESIDENT_EXT 0x8067 +#define GL_TEXTURE_1D_BINDING_EXT 0x8068 +#define GL_TEXTURE_2D_BINDING_EXT 0x8069 +#define GL_TEXTURE_3D_BINDING_EXT 0x806A +#endif + +#ifndef GL_SGIS_detail_texture +#define GL_DETAIL_TEXTURE_2D_SGIS 0x8095 +#define GL_DETAIL_TEXTURE_2D_BINDING_SGIS 0x8096 +#define GL_LINEAR_DETAIL_SGIS 0x8097 +#define GL_LINEAR_DETAIL_ALPHA_SGIS 0x8098 +#define GL_LINEAR_DETAIL_COLOR_SGIS 0x8099 +#define GL_DETAIL_TEXTURE_LEVEL_SGIS 0x809A +#define GL_DETAIL_TEXTURE_MODE_SGIS 0x809B +#define GL_DETAIL_TEXTURE_FUNC_POINTS_SGIS 0x809C +#endif + +#ifndef GL_SGIS_sharpen_texture +#define GL_LINEAR_SHARPEN_SGIS 0x80AD +#define GL_LINEAR_SHARPEN_ALPHA_SGIS 0x80AE +#define GL_LINEAR_SHARPEN_COLOR_SGIS 0x80AF +#define GL_SHARPEN_TEXTURE_FUNC_POINTS_SGIS 0x80B0 +#endif + +#ifndef GL_EXT_packed_pixels +#define GL_UNSIGNED_BYTE_3_3_2_EXT 0x8032 +#define GL_UNSIGNED_SHORT_4_4_4_4_EXT 0x8033 +#define GL_UNSIGNED_SHORT_5_5_5_1_EXT 0x8034 +#define GL_UNSIGNED_INT_8_8_8_8_EXT 0x8035 +#define GL_UNSIGNED_INT_10_10_10_2_EXT 0x8036 +#endif + +#ifndef GL_SGIS_texture_lod +#define GL_TEXTURE_MIN_LOD_SGIS 0x813A +#define GL_TEXTURE_MAX_LOD_SGIS 0x813B +#define GL_TEXTURE_BASE_LEVEL_SGIS 0x813C +#define GL_TEXTURE_MAX_LEVEL_SGIS 0x813D +#endif + +#ifndef GL_SGIS_multisample +#define GL_MULTISAMPLE_SGIS 0x809D +#define GL_SAMPLE_ALPHA_TO_MASK_SGIS 0x809E +#define GL_SAMPLE_ALPHA_TO_ONE_SGIS 0x809F +#define GL_SAMPLE_MASK_SGIS 0x80A0 +#define GL_1PASS_SGIS 0x80A1 +#define GL_2PASS_0_SGIS 0x80A2 +#define GL_2PASS_1_SGIS 0x80A3 +#define GL_4PASS_0_SGIS 0x80A4 +#define GL_4PASS_1_SGIS 0x80A5 +#define GL_4PASS_2_SGIS 0x80A6 +#define GL_4PASS_3_SGIS 0x80A7 +#define GL_SAMPLE_BUFFERS_SGIS 0x80A8 +#define GL_SAMPLES_SGIS 0x80A9 +#define GL_SAMPLE_MASK_VALUE_SGIS 0x80AA +#define GL_SAMPLE_MASK_INVERT_SGIS 0x80AB +#define GL_SAMPLE_PATTERN_SGIS 0x80AC +#endif + +#ifndef GL_EXT_rescale_normal +#define GL_RESCALE_NORMAL_EXT 0x803A +#endif + +#ifndef GL_EXT_vertex_array +#define GL_VERTEX_ARRAY_EXT 0x8074 +#define GL_NORMAL_ARRAY_EXT 0x8075 +#define GL_COLOR_ARRAY_EXT 0x8076 +#define GL_INDEX_ARRAY_EXT 0x8077 +#define GL_TEXTURE_COORD_ARRAY_EXT 0x8078 +#define GL_EDGE_FLAG_ARRAY_EXT 0x8079 +#define GL_VERTEX_ARRAY_SIZE_EXT 0x807A +#define GL_VERTEX_ARRAY_TYPE_EXT 0x807B +#define GL_VERTEX_ARRAY_STRIDE_EXT 0x807C +#define GL_VERTEX_ARRAY_COUNT_EXT 0x807D +#define GL_NORMAL_ARRAY_TYPE_EXT 0x807E +#define GL_NORMAL_ARRAY_STRIDE_EXT 0x807F +#define GL_NORMAL_ARRAY_COUNT_EXT 0x8080 +#define GL_COLOR_ARRAY_SIZE_EXT 0x8081 +#define GL_COLOR_ARRAY_TYPE_EXT 0x8082 +#define GL_COLOR_ARRAY_STRIDE_EXT 0x8083 +#define GL_COLOR_ARRAY_COUNT_EXT 0x8084 +#define GL_INDEX_ARRAY_TYPE_EXT 0x8085 +#define GL_INDEX_ARRAY_STRIDE_EXT 0x8086 +#define GL_INDEX_ARRAY_COUNT_EXT 0x8087 +#define GL_TEXTURE_COORD_ARRAY_SIZE_EXT 0x8088 +#define GL_TEXTURE_COORD_ARRAY_TYPE_EXT 0x8089 +#define GL_TEXTURE_COORD_ARRAY_STRIDE_EXT 0x808A +#define GL_TEXTURE_COORD_ARRAY_COUNT_EXT 0x808B +#define GL_EDGE_FLAG_ARRAY_STRIDE_EXT 0x808C +#define GL_EDGE_FLAG_ARRAY_COUNT_EXT 0x808D +#define GL_VERTEX_ARRAY_POINTER_EXT 0x808E +#define GL_NORMAL_ARRAY_POINTER_EXT 0x808F +#define GL_COLOR_ARRAY_POINTER_EXT 0x8090 +#define GL_INDEX_ARRAY_POINTER_EXT 0x8091 +#define GL_TEXTURE_COORD_ARRAY_POINTER_EXT 0x8092 +#define GL_EDGE_FLAG_ARRAY_POINTER_EXT 0x8093 +#endif + +#ifndef GL_EXT_misc_attribute +#endif + +#ifndef GL_SGIS_generate_mipmap +#define GL_GENERATE_MIPMAP_SGIS 0x8191 +#define GL_GENERATE_MIPMAP_HINT_SGIS 0x8192 +#endif + +#ifndef GL_SGIX_clipmap +#define GL_LINEAR_CLIPMAP_LINEAR_SGIX 0x8170 +#define GL_TEXTURE_CLIPMAP_CENTER_SGIX 0x8171 +#define GL_TEXTURE_CLIPMAP_FRAME_SGIX 0x8172 +#define GL_TEXTURE_CLIPMAP_OFFSET_SGIX 0x8173 +#define GL_TEXTURE_CLIPMAP_VIRTUAL_DEPTH_SGIX 0x8174 +#define GL_TEXTURE_CLIPMAP_LOD_OFFSET_SGIX 0x8175 +#define GL_TEXTURE_CLIPMAP_DEPTH_SGIX 0x8176 +#define GL_MAX_CLIPMAP_DEPTH_SGIX 0x8177 +#define GL_MAX_CLIPMAP_VIRTUAL_DEPTH_SGIX 0x8178 +#define GL_NEAREST_CLIPMAP_NEAREST_SGIX 0x844D +#define GL_NEAREST_CLIPMAP_LINEAR_SGIX 0x844E +#define GL_LINEAR_CLIPMAP_NEAREST_SGIX 0x844F +#endif + +#ifndef GL_SGIX_shadow +#define GL_TEXTURE_COMPARE_SGIX 0x819A +#define GL_TEXTURE_COMPARE_OPERATOR_SGIX 0x819B +#define GL_TEXTURE_LEQUAL_R_SGIX 0x819C +#define GL_TEXTURE_GEQUAL_R_SGIX 0x819D +#endif + +#ifndef GL_SGIS_texture_edge_clamp +#define GL_CLAMP_TO_EDGE_SGIS 0x812F +#endif + +#ifndef GL_SGIS_texture_border_clamp +#define GL_CLAMP_TO_BORDER_SGIS 0x812D +#endif + +#ifndef GL_EXT_blend_minmax +#define GL_FUNC_ADD_EXT 0x8006 +#define GL_MIN_EXT 0x8007 +#define GL_MAX_EXT 0x8008 +#define GL_BLEND_EQUATION_EXT 0x8009 +#endif + +#ifndef GL_EXT_blend_subtract +#define GL_FUNC_SUBTRACT_EXT 0x800A +#define GL_FUNC_REVERSE_SUBTRACT_EXT 0x800B +#endif + +#ifndef GL_EXT_blend_logic_op +#endif + +#ifndef GL_SGIX_interlace +#define GL_INTERLACE_SGIX 0x8094 +#endif + +#ifndef GL_SGIX_pixel_tiles +#define GL_PIXEL_TILE_BEST_ALIGNMENT_SGIX 0x813E +#define GL_PIXEL_TILE_CACHE_INCREMENT_SGIX 0x813F +#define GL_PIXEL_TILE_WIDTH_SGIX 0x8140 +#define GL_PIXEL_TILE_HEIGHT_SGIX 0x8141 +#define GL_PIXEL_TILE_GRID_WIDTH_SGIX 0x8142 +#define GL_PIXEL_TILE_GRID_HEIGHT_SGIX 0x8143 +#define GL_PIXEL_TILE_GRID_DEPTH_SGIX 0x8144 +#define GL_PIXEL_TILE_CACHE_SIZE_SGIX 0x8145 +#endif + +#ifndef GL_SGIS_texture_select +#define GL_DUAL_ALPHA4_SGIS 0x8110 +#define GL_DUAL_ALPHA8_SGIS 0x8111 +#define GL_DUAL_ALPHA12_SGIS 0x8112 +#define GL_DUAL_ALPHA16_SGIS 0x8113 +#define GL_DUAL_LUMINANCE4_SGIS 0x8114 +#define GL_DUAL_LUMINANCE8_SGIS 0x8115 +#define GL_DUAL_LUMINANCE12_SGIS 0x8116 +#define GL_DUAL_LUMINANCE16_SGIS 0x8117 +#define GL_DUAL_INTENSITY4_SGIS 0x8118 +#define GL_DUAL_INTENSITY8_SGIS 0x8119 +#define GL_DUAL_INTENSITY12_SGIS 0x811A +#define GL_DUAL_INTENSITY16_SGIS 0x811B +#define GL_DUAL_LUMINANCE_ALPHA4_SGIS 0x811C +#define GL_DUAL_LUMINANCE_ALPHA8_SGIS 0x811D +#define GL_QUAD_ALPHA4_SGIS 0x811E +#define GL_QUAD_ALPHA8_SGIS 0x811F +#define GL_QUAD_LUMINANCE4_SGIS 0x8120 +#define GL_QUAD_LUMINANCE8_SGIS 0x8121 +#define GL_QUAD_INTENSITY4_SGIS 0x8122 +#define GL_QUAD_INTENSITY8_SGIS 0x8123 +#define GL_DUAL_TEXTURE_SELECT_SGIS 0x8124 +#define GL_QUAD_TEXTURE_SELECT_SGIS 0x8125 +#endif + +#ifndef GL_SGIX_sprite +#define GL_SPRITE_SGIX 0x8148 +#define GL_SPRITE_MODE_SGIX 0x8149 +#define GL_SPRITE_AXIS_SGIX 0x814A +#define GL_SPRITE_TRANSLATION_SGIX 0x814B +#define GL_SPRITE_AXIAL_SGIX 0x814C +#define GL_SPRITE_OBJECT_ALIGNED_SGIX 0x814D +#define GL_SPRITE_EYE_ALIGNED_SGIX 0x814E +#endif + +#ifndef GL_SGIX_texture_multi_buffer +#define GL_TEXTURE_MULTI_BUFFER_HINT_SGIX 0x812E +#endif + +#ifndef GL_EXT_point_parameters +#define GL_POINT_SIZE_MIN_EXT 0x8126 +#define GL_POINT_SIZE_MAX_EXT 0x8127 +#define GL_POINT_FADE_THRESHOLD_SIZE_EXT 0x8128 +#define GL_DISTANCE_ATTENUATION_EXT 0x8129 +#endif + +#ifndef GL_SGIS_point_parameters +#define GL_POINT_SIZE_MIN_SGIS 0x8126 +#define GL_POINT_SIZE_MAX_SGIS 0x8127 +#define GL_POINT_FADE_THRESHOLD_SIZE_SGIS 0x8128 +#define GL_DISTANCE_ATTENUATION_SGIS 0x8129 +#endif + +#ifndef GL_SGIX_instruments +#define GL_INSTRUMENT_BUFFER_POINTER_SGIX 0x8180 +#define GL_INSTRUMENT_MEASUREMENTS_SGIX 0x8181 +#endif + +#ifndef GL_SGIX_texture_scale_bias +#define GL_POST_TEXTURE_FILTER_BIAS_SGIX 0x8179 +#define GL_POST_TEXTURE_FILTER_SCALE_SGIX 0x817A +#define GL_POST_TEXTURE_FILTER_BIAS_RANGE_SGIX 0x817B +#define GL_POST_TEXTURE_FILTER_SCALE_RANGE_SGIX 0x817C +#endif + +#ifndef GL_SGIX_framezoom +#define GL_FRAMEZOOM_SGIX 0x818B +#define GL_FRAMEZOOM_FACTOR_SGIX 0x818C +#define GL_MAX_FRAMEZOOM_FACTOR_SGIX 0x818D +#endif + +#ifndef GL_SGIX_tag_sample_buffer +#endif + +#ifndef GL_FfdMaskSGIX +#define GL_TEXTURE_DEFORMATION_BIT_SGIX 0x00000001 +#define GL_GEOMETRY_DEFORMATION_BIT_SGIX 0x00000002 +#endif + +#ifndef GL_SGIX_polynomial_ffd +#define GL_GEOMETRY_DEFORMATION_SGIX 0x8194 +#define GL_TEXTURE_DEFORMATION_SGIX 0x8195 +#define GL_DEFORMATIONS_MASK_SGIX 0x8196 +#define GL_MAX_DEFORMATION_ORDER_SGIX 0x8197 +#endif + +#ifndef GL_SGIX_reference_plane +#define GL_REFERENCE_PLANE_SGIX 0x817D +#define GL_REFERENCE_PLANE_EQUATION_SGIX 0x817E +#endif + +#ifndef GL_SGIX_flush_raster +#endif + +#ifndef GL_SGIX_depth_texture +#define GL_DEPTH_COMPONENT16_SGIX 0x81A5 +#define GL_DEPTH_COMPONENT24_SGIX 0x81A6 +#define GL_DEPTH_COMPONENT32_SGIX 0x81A7 +#endif + +#ifndef GL_SGIS_fog_function +#define GL_FOG_FUNC_SGIS 0x812A +#define GL_FOG_FUNC_POINTS_SGIS 0x812B +#define GL_MAX_FOG_FUNC_POINTS_SGIS 0x812C +#endif + +#ifndef GL_SGIX_fog_offset +#define GL_FOG_OFFSET_SGIX 0x8198 +#define GL_FOG_OFFSET_VALUE_SGIX 0x8199 +#endif + +#ifndef GL_HP_image_transform +#define GL_IMAGE_SCALE_X_HP 0x8155 +#define GL_IMAGE_SCALE_Y_HP 0x8156 +#define GL_IMAGE_TRANSLATE_X_HP 0x8157 +#define GL_IMAGE_TRANSLATE_Y_HP 0x8158 +#define GL_IMAGE_ROTATE_ANGLE_HP 0x8159 +#define GL_IMAGE_ROTATE_ORIGIN_X_HP 0x815A +#define GL_IMAGE_ROTATE_ORIGIN_Y_HP 0x815B +#define GL_IMAGE_MAG_FILTER_HP 0x815C +#define GL_IMAGE_MIN_FILTER_HP 0x815D +#define GL_IMAGE_CUBIC_WEIGHT_HP 0x815E +#define GL_CUBIC_HP 0x815F +#define GL_AVERAGE_HP 0x8160 +#define GL_IMAGE_TRANSFORM_2D_HP 0x8161 +#define GL_POST_IMAGE_TRANSFORM_COLOR_TABLE_HP 0x8162 +#define GL_PROXY_POST_IMAGE_TRANSFORM_COLOR_TABLE_HP 0x8163 +#endif + +#ifndef GL_HP_convolution_border_modes +#define GL_IGNORE_BORDER_HP 0x8150 +#define GL_CONSTANT_BORDER_HP 0x8151 +#define GL_REPLICATE_BORDER_HP 0x8153 +#define GL_CONVOLUTION_BORDER_COLOR_HP 0x8154 +#endif + +#ifndef GL_INGR_palette_buffer +#endif + +#ifndef GL_SGIX_texture_add_env +#define GL_TEXTURE_ENV_BIAS_SGIX 0x80BE +#endif + +#ifndef GL_EXT_color_subtable +#endif + +#ifndef GL_PGI_vertex_hints +#define GL_VERTEX_DATA_HINT_PGI 0x1A22A +#define GL_VERTEX_CONSISTENT_HINT_PGI 0x1A22B +#define GL_MATERIAL_SIDE_HINT_PGI 0x1A22C +#define GL_MAX_VERTEX_HINT_PGI 0x1A22D +#define GL_COLOR3_BIT_PGI 0x00010000 +#define GL_COLOR4_BIT_PGI 0x00020000 +#define GL_EDGEFLAG_BIT_PGI 0x00040000 +#define GL_INDEX_BIT_PGI 0x00080000 +#define GL_MAT_AMBIENT_BIT_PGI 0x00100000 +#define GL_MAT_AMBIENT_AND_DIFFUSE_BIT_PGI 0x00200000 +#define GL_MAT_DIFFUSE_BIT_PGI 0x00400000 +#define GL_MAT_EMISSION_BIT_PGI 0x00800000 +#define GL_MAT_COLOR_INDEXES_BIT_PGI 0x01000000 +#define GL_MAT_SHININESS_BIT_PGI 0x02000000 +#define GL_MAT_SPECULAR_BIT_PGI 0x04000000 +#define GL_NORMAL_BIT_PGI 0x08000000 +#define GL_TEXCOORD1_BIT_PGI 0x10000000 +#define GL_TEXCOORD2_BIT_PGI 0x20000000 +#define GL_TEXCOORD3_BIT_PGI 0x40000000 +#define GL_TEXCOORD4_BIT_PGI 0x80000000 +#define GL_VERTEX23_BIT_PGI 0x00000004 +#define GL_VERTEX4_BIT_PGI 0x00000008 +#endif + +#ifndef GL_PGI_misc_hints +#define GL_PREFER_DOUBLEBUFFER_HINT_PGI 0x1A1F8 +#define GL_CONSERVE_MEMORY_HINT_PGI 0x1A1FD +#define GL_RECLAIM_MEMORY_HINT_PGI 0x1A1FE +#define GL_NATIVE_GRAPHICS_HANDLE_PGI 0x1A202 +#define GL_NATIVE_GRAPHICS_BEGIN_HINT_PGI 0x1A203 +#define GL_NATIVE_GRAPHICS_END_HINT_PGI 0x1A204 +#define GL_ALWAYS_FAST_HINT_PGI 0x1A20C +#define GL_ALWAYS_SOFT_HINT_PGI 0x1A20D +#define GL_ALLOW_DRAW_OBJ_HINT_PGI 0x1A20E +#define GL_ALLOW_DRAW_WIN_HINT_PGI 0x1A20F +#define GL_ALLOW_DRAW_FRG_HINT_PGI 0x1A210 +#define GL_ALLOW_DRAW_MEM_HINT_PGI 0x1A211 +#define GL_STRICT_DEPTHFUNC_HINT_PGI 0x1A216 +#define GL_STRICT_LIGHTING_HINT_PGI 0x1A217 +#define GL_STRICT_SCISSOR_HINT_PGI 0x1A218 +#define GL_FULL_STIPPLE_HINT_PGI 0x1A219 +#define GL_CLIP_NEAR_HINT_PGI 0x1A220 +#define GL_CLIP_FAR_HINT_PGI 0x1A221 +#define GL_WIDE_LINE_HINT_PGI 0x1A222 +#define GL_BACK_NORMALS_HINT_PGI 0x1A223 +#endif + +#ifndef GL_EXT_paletted_texture +#define GL_COLOR_INDEX1_EXT 0x80E2 +#define GL_COLOR_INDEX2_EXT 0x80E3 +#define GL_COLOR_INDEX4_EXT 0x80E4 +#define GL_COLOR_INDEX8_EXT 0x80E5 +#define GL_COLOR_INDEX12_EXT 0x80E6 +#define GL_COLOR_INDEX16_EXT 0x80E7 +#define GL_TEXTURE_INDEX_SIZE_EXT 0x80ED +#endif + +#ifndef GL_EXT_clip_volume_hint +#define GL_CLIP_VOLUME_CLIPPING_HINT_EXT 0x80F0 +#endif + +#ifndef GL_SGIX_list_priority +#define GL_LIST_PRIORITY_SGIX 0x8182 +#endif + +#ifndef GL_SGIX_ir_instrument1 +#define GL_IR_INSTRUMENT1_SGIX 0x817F +#endif + +#ifndef GL_SGIX_calligraphic_fragment +#define GL_CALLIGRAPHIC_FRAGMENT_SGIX 0x8183 +#endif + +#ifndef GL_SGIX_texture_lod_bias +#define GL_TEXTURE_LOD_BIAS_S_SGIX 0x818E +#define GL_TEXTURE_LOD_BIAS_T_SGIX 0x818F +#define GL_TEXTURE_LOD_BIAS_R_SGIX 0x8190 +#endif + +#ifndef GL_SGIX_shadow_ambient +#define GL_SHADOW_AMBIENT_SGIX 0x80BF +#endif + +#ifndef GL_EXT_index_texture +#endif + +#ifndef GL_EXT_index_material +#define GL_INDEX_MATERIAL_EXT 0x81B8 +#define GL_INDEX_MATERIAL_PARAMETER_EXT 0x81B9 +#define GL_INDEX_MATERIAL_FACE_EXT 0x81BA +#endif + +#ifndef GL_EXT_index_func +#define GL_INDEX_TEST_EXT 0x81B5 +#define GL_INDEX_TEST_FUNC_EXT 0x81B6 +#define GL_INDEX_TEST_REF_EXT 0x81B7 +#endif + +#ifndef GL_EXT_index_array_formats +#define GL_IUI_V2F_EXT 0x81AD +#define GL_IUI_V3F_EXT 0x81AE +#define GL_IUI_N3F_V2F_EXT 0x81AF +#define GL_IUI_N3F_V3F_EXT 0x81B0 +#define GL_T2F_IUI_V2F_EXT 0x81B1 +#define GL_T2F_IUI_V3F_EXT 0x81B2 +#define GL_T2F_IUI_N3F_V2F_EXT 0x81B3 +#define GL_T2F_IUI_N3F_V3F_EXT 0x81B4 +#endif + +#ifndef GL_EXT_compiled_vertex_array +#define GL_ARRAY_ELEMENT_LOCK_FIRST_EXT 0x81A8 +#define GL_ARRAY_ELEMENT_LOCK_COUNT_EXT 0x81A9 +#endif + +#ifndef GL_EXT_cull_vertex +#define GL_CULL_VERTEX_EXT 0x81AA +#define GL_CULL_VERTEX_EYE_POSITION_EXT 0x81AB +#define GL_CULL_VERTEX_OBJECT_POSITION_EXT 0x81AC +#endif + +#ifndef GL_SGIX_ycrcb +#define GL_YCRCB_422_SGIX 0x81BB +#define GL_YCRCB_444_SGIX 0x81BC +#endif + +#ifndef GL_SGIX_fragment_lighting +#define GL_FRAGMENT_LIGHTING_SGIX 0x8400 +#define GL_FRAGMENT_COLOR_MATERIAL_SGIX 0x8401 +#define GL_FRAGMENT_COLOR_MATERIAL_FACE_SGIX 0x8402 +#define GL_FRAGMENT_COLOR_MATERIAL_PARAMETER_SGIX 0x8403 +#define GL_MAX_FRAGMENT_LIGHTS_SGIX 0x8404 +#define GL_MAX_ACTIVE_LIGHTS_SGIX 0x8405 +#define GL_CURRENT_RASTER_NORMAL_SGIX 0x8406 +#define GL_LIGHT_ENV_MODE_SGIX 0x8407 +#define GL_FRAGMENT_LIGHT_MODEL_LOCAL_VIEWER_SGIX 0x8408 +#define GL_FRAGMENT_LIGHT_MODEL_TWO_SIDE_SGIX 0x8409 +#define GL_FRAGMENT_LIGHT_MODEL_AMBIENT_SGIX 0x840A +#define GL_FRAGMENT_LIGHT_MODEL_NORMAL_INTERPOLATION_SGIX 0x840B +#define GL_FRAGMENT_LIGHT0_SGIX 0x840C +#define GL_FRAGMENT_LIGHT1_SGIX 0x840D +#define GL_FRAGMENT_LIGHT2_SGIX 0x840E +#define GL_FRAGMENT_LIGHT3_SGIX 0x840F +#define GL_FRAGMENT_LIGHT4_SGIX 0x8410 +#define GL_FRAGMENT_LIGHT5_SGIX 0x8411 +#define GL_FRAGMENT_LIGHT6_SGIX 0x8412 +#define GL_FRAGMENT_LIGHT7_SGIX 0x8413 +#endif + +#ifndef GL_IBM_rasterpos_clip +#define GL_RASTER_POSITION_UNCLIPPED_IBM 0x19262 +#endif + +#ifndef GL_HP_texture_lighting +#define GL_TEXTURE_LIGHTING_MODE_HP 0x8167 +#define GL_TEXTURE_POST_SPECULAR_HP 0x8168 +#define GL_TEXTURE_PRE_SPECULAR_HP 0x8169 +#endif + +#ifndef GL_EXT_draw_range_elements +#define GL_MAX_ELEMENTS_VERTICES_EXT 0x80E8 +#define GL_MAX_ELEMENTS_INDICES_EXT 0x80E9 +#endif + +#ifndef GL_WIN_phong_shading +#define GL_PHONG_WIN 0x80EA +#define GL_PHONG_HINT_WIN 0x80EB +#endif + +#ifndef GL_WIN_specular_fog +#define GL_FOG_SPECULAR_TEXTURE_WIN 0x80EC +#endif + +#ifndef GL_EXT_light_texture +#define GL_FRAGMENT_MATERIAL_EXT 0x8349 +#define GL_FRAGMENT_NORMAL_EXT 0x834A +#define GL_FRAGMENT_COLOR_EXT 0x834C +#define GL_ATTENUATION_EXT 0x834D +#define GL_SHADOW_ATTENUATION_EXT 0x834E +#define GL_TEXTURE_APPLICATION_MODE_EXT 0x834F +#define GL_TEXTURE_LIGHT_EXT 0x8350 +#define GL_TEXTURE_MATERIAL_FACE_EXT 0x8351 +#define GL_TEXTURE_MATERIAL_PARAMETER_EXT 0x8352 +/* reuse GL_FRAGMENT_DEPTH_EXT */ +#endif + +#ifndef GL_SGIX_blend_alpha_minmax +#define GL_ALPHA_MIN_SGIX 0x8320 +#define GL_ALPHA_MAX_SGIX 0x8321 +#endif + +#ifndef GL_SGIX_impact_pixel_texture +#define GL_PIXEL_TEX_GEN_Q_CEILING_SGIX 0x8184 +#define GL_PIXEL_TEX_GEN_Q_ROUND_SGIX 0x8185 +#define GL_PIXEL_TEX_GEN_Q_FLOOR_SGIX 0x8186 +#define GL_PIXEL_TEX_GEN_ALPHA_REPLACE_SGIX 0x8187 +#define GL_PIXEL_TEX_GEN_ALPHA_NO_REPLACE_SGIX 0x8188 +#define GL_PIXEL_TEX_GEN_ALPHA_LS_SGIX 0x8189 +#define GL_PIXEL_TEX_GEN_ALPHA_MS_SGIX 0x818A +#endif + +#ifndef GL_EXT_bgra +#define GL_BGR_EXT 0x80E0 +#define GL_BGRA_EXT 0x80E1 +#endif + +#ifndef GL_SGIX_async +#define GL_ASYNC_MARKER_SGIX 0x8329 +#endif + +#ifndef GL_SGIX_async_pixel +#define GL_ASYNC_TEX_IMAGE_SGIX 0x835C +#define GL_ASYNC_DRAW_PIXELS_SGIX 0x835D +#define GL_ASYNC_READ_PIXELS_SGIX 0x835E +#define GL_MAX_ASYNC_TEX_IMAGE_SGIX 0x835F +#define GL_MAX_ASYNC_DRAW_PIXELS_SGIX 0x8360 +#define GL_MAX_ASYNC_READ_PIXELS_SGIX 0x8361 +#endif + +#ifndef GL_SGIX_async_histogram +#define GL_ASYNC_HISTOGRAM_SGIX 0x832C +#define GL_MAX_ASYNC_HISTOGRAM_SGIX 0x832D +#endif + +#ifndef GL_INTEL_texture_scissor +#endif + +#ifndef GL_INTEL_parallel_arrays +#define GL_PARALLEL_ARRAYS_INTEL 0x83F4 +#define GL_VERTEX_ARRAY_PARALLEL_POINTERS_INTEL 0x83F5 +#define GL_NORMAL_ARRAY_PARALLEL_POINTERS_INTEL 0x83F6 +#define GL_COLOR_ARRAY_PARALLEL_POINTERS_INTEL 0x83F7 +#define GL_TEXTURE_COORD_ARRAY_PARALLEL_POINTERS_INTEL 0x83F8 +#endif + +#ifndef GL_HP_occlusion_test +#define GL_OCCLUSION_TEST_HP 0x8165 +#define GL_OCCLUSION_TEST_RESULT_HP 0x8166 +#endif + +#ifndef GL_EXT_pixel_transform +#define GL_PIXEL_TRANSFORM_2D_EXT 0x8330 +#define GL_PIXEL_MAG_FILTER_EXT 0x8331 +#define GL_PIXEL_MIN_FILTER_EXT 0x8332 +#define GL_PIXEL_CUBIC_WEIGHT_EXT 0x8333 +#define GL_CUBIC_EXT 0x8334 +#define GL_AVERAGE_EXT 0x8335 +#define GL_PIXEL_TRANSFORM_2D_STACK_DEPTH_EXT 0x8336 +#define GL_MAX_PIXEL_TRANSFORM_2D_STACK_DEPTH_EXT 0x8337 +#define GL_PIXEL_TRANSFORM_2D_MATRIX_EXT 0x8338 +#endif + +#ifndef GL_EXT_pixel_transform_color_table +#endif + +#ifndef GL_EXT_shared_texture_palette +#define GL_SHARED_TEXTURE_PALETTE_EXT 0x81FB +#endif + +#ifndef GL_EXT_separate_specular_color +#define GL_LIGHT_MODEL_COLOR_CONTROL_EXT 0x81F8 +#define GL_SINGLE_COLOR_EXT 0x81F9 +#define GL_SEPARATE_SPECULAR_COLOR_EXT 0x81FA +#endif + +#ifndef GL_EXT_secondary_color +#define GL_COLOR_SUM_EXT 0x8458 +#define GL_CURRENT_SECONDARY_COLOR_EXT 0x8459 +#define GL_SECONDARY_COLOR_ARRAY_SIZE_EXT 0x845A +#define GL_SECONDARY_COLOR_ARRAY_TYPE_EXT 0x845B +#define GL_SECONDARY_COLOR_ARRAY_STRIDE_EXT 0x845C +#define GL_SECONDARY_COLOR_ARRAY_POINTER_EXT 0x845D +#define GL_SECONDARY_COLOR_ARRAY_EXT 0x845E +#endif + +#ifndef GL_EXT_texture_perturb_normal +#define GL_PERTURB_EXT 0x85AE +#define GL_TEXTURE_NORMAL_EXT 0x85AF +#endif + +#ifndef GL_EXT_multi_draw_arrays +#endif + +#ifndef GL_EXT_fog_coord +#define GL_FOG_COORDINATE_SOURCE_EXT 0x8450 +#define GL_FOG_COORDINATE_EXT 0x8451 +#define GL_FRAGMENT_DEPTH_EXT 0x8452 +#define GL_CURRENT_FOG_COORDINATE_EXT 0x8453 +#define GL_FOG_COORDINATE_ARRAY_TYPE_EXT 0x8454 +#define GL_FOG_COORDINATE_ARRAY_STRIDE_EXT 0x8455 +#define GL_FOG_COORDINATE_ARRAY_POINTER_EXT 0x8456 +#define GL_FOG_COORDINATE_ARRAY_EXT 0x8457 +#endif + +#ifndef GL_REND_screen_coordinates +#define GL_SCREEN_COORDINATES_REND 0x8490 +#define GL_INVERTED_SCREEN_W_REND 0x8491 +#endif + +#ifndef GL_EXT_coordinate_frame +#define GL_TANGENT_ARRAY_EXT 0x8439 +#define GL_BINORMAL_ARRAY_EXT 0x843A +#define GL_CURRENT_TANGENT_EXT 0x843B +#define GL_CURRENT_BINORMAL_EXT 0x843C +#define GL_TANGENT_ARRAY_TYPE_EXT 0x843E +#define GL_TANGENT_ARRAY_STRIDE_EXT 0x843F +#define GL_BINORMAL_ARRAY_TYPE_EXT 0x8440 +#define GL_BINORMAL_ARRAY_STRIDE_EXT 0x8441 +#define GL_TANGENT_ARRAY_POINTER_EXT 0x8442 +#define GL_BINORMAL_ARRAY_POINTER_EXT 0x8443 +#define GL_MAP1_TANGENT_EXT 0x8444 +#define GL_MAP2_TANGENT_EXT 0x8445 +#define GL_MAP1_BINORMAL_EXT 0x8446 +#define GL_MAP2_BINORMAL_EXT 0x8447 +#endif + +#ifndef GL_EXT_texture_env_combine +#define GL_COMBINE_EXT 0x8570 +#define GL_COMBINE_RGB_EXT 0x8571 +#define GL_COMBINE_ALPHA_EXT 0x8572 +#define GL_RGB_SCALE_EXT 0x8573 +#define GL_ADD_SIGNED_EXT 0x8574 +#define GL_INTERPOLATE_EXT 0x8575 +#define GL_CONSTANT_EXT 0x8576 +#define GL_PRIMARY_COLOR_EXT 0x8577 +#define GL_PREVIOUS_EXT 0x8578 +#define GL_SOURCE0_RGB_EXT 0x8580 +#define GL_SOURCE1_RGB_EXT 0x8581 +#define GL_SOURCE2_RGB_EXT 0x8582 +#define GL_SOURCE0_ALPHA_EXT 0x8588 +#define GL_SOURCE1_ALPHA_EXT 0x8589 +#define GL_SOURCE2_ALPHA_EXT 0x858A +#define GL_OPERAND0_RGB_EXT 0x8590 +#define GL_OPERAND1_RGB_EXT 0x8591 +#define GL_OPERAND2_RGB_EXT 0x8592 +#define GL_OPERAND0_ALPHA_EXT 0x8598 +#define GL_OPERAND1_ALPHA_EXT 0x8599 +#define GL_OPERAND2_ALPHA_EXT 0x859A +#endif + +#ifndef GL_APPLE_specular_vector +#define GL_LIGHT_MODEL_SPECULAR_VECTOR_APPLE 0x85B0 +#endif + +#ifndef GL_APPLE_transform_hint +#define GL_TRANSFORM_HINT_APPLE 0x85B1 +#endif + +#ifndef GL_SGIX_fog_scale +#define GL_FOG_SCALE_SGIX 0x81FC +#define GL_FOG_SCALE_VALUE_SGIX 0x81FD +#endif + +#ifndef GL_SUNX_constant_data +#define GL_UNPACK_CONSTANT_DATA_SUNX 0x81D5 +#define GL_TEXTURE_CONSTANT_DATA_SUNX 0x81D6 +#endif + +#ifndef GL_SUN_global_alpha +#define GL_GLOBAL_ALPHA_SUN 0x81D9 +#define GL_GLOBAL_ALPHA_FACTOR_SUN 0x81DA +#endif + +#ifndef GL_SUN_triangle_list +#define GL_RESTART_SUN 0x0001 +#define GL_REPLACE_MIDDLE_SUN 0x0002 +#define GL_REPLACE_OLDEST_SUN 0x0003 +#define GL_TRIANGLE_LIST_SUN 0x81D7 +#define GL_REPLACEMENT_CODE_SUN 0x81D8 +#define GL_REPLACEMENT_CODE_ARRAY_SUN 0x85C0 +#define GL_REPLACEMENT_CODE_ARRAY_TYPE_SUN 0x85C1 +#define GL_REPLACEMENT_CODE_ARRAY_STRIDE_SUN 0x85C2 +#define GL_REPLACEMENT_CODE_ARRAY_POINTER_SUN 0x85C3 +#define GL_R1UI_V3F_SUN 0x85C4 +#define GL_R1UI_C4UB_V3F_SUN 0x85C5 +#define GL_R1UI_C3F_V3F_SUN 0x85C6 +#define GL_R1UI_N3F_V3F_SUN 0x85C7 +#define GL_R1UI_C4F_N3F_V3F_SUN 0x85C8 +#define GL_R1UI_T2F_V3F_SUN 0x85C9 +#define GL_R1UI_T2F_N3F_V3F_SUN 0x85CA +#define GL_R1UI_T2F_C4F_N3F_V3F_SUN 0x85CB +#endif + +#ifndef GL_SUN_vertex +#endif + +#ifndef GL_EXT_blend_func_separate +#define GL_BLEND_DST_RGB_EXT 0x80C8 +#define GL_BLEND_SRC_RGB_EXT 0x80C9 +#define GL_BLEND_DST_ALPHA_EXT 0x80CA +#define GL_BLEND_SRC_ALPHA_EXT 0x80CB +#endif + +#ifndef GL_INGR_color_clamp +#define GL_RED_MIN_CLAMP_INGR 0x8560 +#define GL_GREEN_MIN_CLAMP_INGR 0x8561 +#define GL_BLUE_MIN_CLAMP_INGR 0x8562 +#define GL_ALPHA_MIN_CLAMP_INGR 0x8563 +#define GL_RED_MAX_CLAMP_INGR 0x8564 +#define GL_GREEN_MAX_CLAMP_INGR 0x8565 +#define GL_BLUE_MAX_CLAMP_INGR 0x8566 +#define GL_ALPHA_MAX_CLAMP_INGR 0x8567 +#endif + +#ifndef GL_INGR_interlace_read +#define GL_INTERLACE_READ_INGR 0x8568 +#endif + +#ifndef GL_EXT_stencil_wrap +#define GL_INCR_WRAP_EXT 0x8507 +#define GL_DECR_WRAP_EXT 0x8508 +#endif + +#ifndef GL_EXT_422_pixels +#define GL_422_EXT 0x80CC +#define GL_422_REV_EXT 0x80CD +#define GL_422_AVERAGE_EXT 0x80CE +#define GL_422_REV_AVERAGE_EXT 0x80CF +#endif + +#ifndef GL_NV_texgen_reflection +#define GL_NORMAL_MAP_NV 0x8511 +#define GL_REFLECTION_MAP_NV 0x8512 +#endif + +#ifndef GL_EXT_texture_cube_map +#define GL_NORMAL_MAP_EXT 0x8511 +#define GL_REFLECTION_MAP_EXT 0x8512 +#define GL_TEXTURE_CUBE_MAP_EXT 0x8513 +#define GL_TEXTURE_BINDING_CUBE_MAP_EXT 0x8514 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_X_EXT 0x8515 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_X_EXT 0x8516 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_Y_EXT 0x8517 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_EXT 0x8518 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_Z_EXT 0x8519 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_EXT 0x851A +#define GL_PROXY_TEXTURE_CUBE_MAP_EXT 0x851B +#define GL_MAX_CUBE_MAP_TEXTURE_SIZE_EXT 0x851C +#endif + +#ifndef GL_SUN_convolution_border_modes +#define GL_WRAP_BORDER_SUN 0x81D4 +#endif + +#ifndef GL_EXT_texture_env_add +#endif + +#ifndef GL_EXT_texture_lod_bias +#define GL_MAX_TEXTURE_LOD_BIAS_EXT 0x84FD +#define GL_TEXTURE_FILTER_CONTROL_EXT 0x8500 +#define GL_TEXTURE_LOD_BIAS_EXT 0x8501 +#endif + +#ifndef GL_EXT_texture_filter_anisotropic +#define GL_TEXTURE_MAX_ANISOTROPY_EXT 0x84FE +#define GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT 0x84FF +#endif + +#ifndef GL_EXT_vertex_weighting +#define GL_MODELVIEW0_STACK_DEPTH_EXT GL_MODELVIEW_STACK_DEPTH +#define GL_MODELVIEW1_STACK_DEPTH_EXT 0x8502 +#define GL_MODELVIEW0_MATRIX_EXT GL_MODELVIEW_MATRIX +#define GL_MODELVIEW1_MATRIX_EXT 0x8506 +#define GL_VERTEX_WEIGHTING_EXT 0x8509 +#define GL_MODELVIEW0_EXT GL_MODELVIEW +#define GL_MODELVIEW1_EXT 0x850A +#define GL_CURRENT_VERTEX_WEIGHT_EXT 0x850B +#define GL_VERTEX_WEIGHT_ARRAY_EXT 0x850C +#define GL_VERTEX_WEIGHT_ARRAY_SIZE_EXT 0x850D +#define GL_VERTEX_WEIGHT_ARRAY_TYPE_EXT 0x850E +#define GL_VERTEX_WEIGHT_ARRAY_STRIDE_EXT 0x850F +#define GL_VERTEX_WEIGHT_ARRAY_POINTER_EXT 0x8510 +#endif + +#ifndef GL_NV_light_max_exponent +#define GL_MAX_SHININESS_NV 0x8504 +#define GL_MAX_SPOT_EXPONENT_NV 0x8505 +#endif + +#ifndef GL_NV_vertex_array_range +#define GL_VERTEX_ARRAY_RANGE_NV 0x851D +#define GL_VERTEX_ARRAY_RANGE_LENGTH_NV 0x851E +#define GL_VERTEX_ARRAY_RANGE_VALID_NV 0x851F +#define GL_MAX_VERTEX_ARRAY_RANGE_ELEMENT_NV 0x8520 +#define GL_VERTEX_ARRAY_RANGE_POINTER_NV 0x8521 +#endif + +#ifndef GL_NV_register_combiners +#define GL_REGISTER_COMBINERS_NV 0x8522 +#define GL_VARIABLE_A_NV 0x8523 +#define GL_VARIABLE_B_NV 0x8524 +#define GL_VARIABLE_C_NV 0x8525 +#define GL_VARIABLE_D_NV 0x8526 +#define GL_VARIABLE_E_NV 0x8527 +#define GL_VARIABLE_F_NV 0x8528 +#define GL_VARIABLE_G_NV 0x8529 +#define GL_CONSTANT_COLOR0_NV 0x852A +#define GL_CONSTANT_COLOR1_NV 0x852B +#define GL_PRIMARY_COLOR_NV 0x852C +#define GL_SECONDARY_COLOR_NV 0x852D +#define GL_SPARE0_NV 0x852E +#define GL_SPARE1_NV 0x852F +#define GL_DISCARD_NV 0x8530 +#define GL_E_TIMES_F_NV 0x8531 +#define GL_SPARE0_PLUS_SECONDARY_COLOR_NV 0x8532 +#define GL_UNSIGNED_IDENTITY_NV 0x8536 +#define GL_UNSIGNED_INVERT_NV 0x8537 +#define GL_EXPAND_NORMAL_NV 0x8538 +#define GL_EXPAND_NEGATE_NV 0x8539 +#define GL_HALF_BIAS_NORMAL_NV 0x853A +#define GL_HALF_BIAS_NEGATE_NV 0x853B +#define GL_SIGNED_IDENTITY_NV 0x853C +#define GL_SIGNED_NEGATE_NV 0x853D +#define GL_SCALE_BY_TWO_NV 0x853E +#define GL_SCALE_BY_FOUR_NV 0x853F +#define GL_SCALE_BY_ONE_HALF_NV 0x8540 +#define GL_BIAS_BY_NEGATIVE_ONE_HALF_NV 0x8541 +#define GL_COMBINER_INPUT_NV 0x8542 +#define GL_COMBINER_MAPPING_NV 0x8543 +#define GL_COMBINER_COMPONENT_USAGE_NV 0x8544 +#define GL_COMBINER_AB_DOT_PRODUCT_NV 0x8545 +#define GL_COMBINER_CD_DOT_PRODUCT_NV 0x8546 +#define GL_COMBINER_MUX_SUM_NV 0x8547 +#define GL_COMBINER_SCALE_NV 0x8548 +#define GL_COMBINER_BIAS_NV 0x8549 +#define GL_COMBINER_AB_OUTPUT_NV 0x854A +#define GL_COMBINER_CD_OUTPUT_NV 0x854B +#define GL_COMBINER_SUM_OUTPUT_NV 0x854C +#define GL_MAX_GENERAL_COMBINERS_NV 0x854D +#define GL_NUM_GENERAL_COMBINERS_NV 0x854E +#define GL_COLOR_SUM_CLAMP_NV 0x854F +#define GL_COMBINER0_NV 0x8550 +#define GL_COMBINER1_NV 0x8551 +#define GL_COMBINER2_NV 0x8552 +#define GL_COMBINER3_NV 0x8553 +#define GL_COMBINER4_NV 0x8554 +#define GL_COMBINER5_NV 0x8555 +#define GL_COMBINER6_NV 0x8556 +#define GL_COMBINER7_NV 0x8557 +/* reuse GL_TEXTURE0_ARB */ +/* reuse GL_TEXTURE1_ARB */ +/* reuse GL_ZERO */ +/* reuse GL_NONE */ +/* reuse GL_FOG */ +#endif + +#ifndef GL_NV_fog_distance +#define GL_FOG_DISTANCE_MODE_NV 0x855A +#define GL_EYE_RADIAL_NV 0x855B +#define GL_EYE_PLANE_ABSOLUTE_NV 0x855C +/* reuse GL_EYE_PLANE */ +#endif + +#ifndef GL_NV_texgen_emboss +#define GL_EMBOSS_LIGHT_NV 0x855D +#define GL_EMBOSS_CONSTANT_NV 0x855E +#define GL_EMBOSS_MAP_NV 0x855F +#endif + +#ifndef GL_NV_blend_square +#endif + +#ifndef GL_NV_texture_env_combine4 +#define GL_COMBINE4_NV 0x8503 +#define GL_SOURCE3_RGB_NV 0x8583 +#define GL_SOURCE3_ALPHA_NV 0x858B +#define GL_OPERAND3_RGB_NV 0x8593 +#define GL_OPERAND3_ALPHA_NV 0x859B +#endif + +#ifndef GL_MESA_resize_buffers +#endif + +#ifndef GL_MESA_window_pos +#endif + +#ifndef GL_EXT_texture_compression_s3tc +#define GL_COMPRESSED_RGB_S3TC_DXT1_EXT 0x83F0 +#define GL_COMPRESSED_RGBA_S3TC_DXT1_EXT 0x83F1 +#define GL_COMPRESSED_RGBA_S3TC_DXT3_EXT 0x83F2 +#define GL_COMPRESSED_RGBA_S3TC_DXT5_EXT 0x83F3 +#endif + +#ifndef GL_IBM_cull_vertex +#define GL_CULL_VERTEX_IBM 103050 +#endif + +#ifndef GL_IBM_multimode_draw_arrays +#endif + +#ifndef GL_IBM_vertex_array_lists +#define GL_VERTEX_ARRAY_LIST_IBM 103070 +#define GL_NORMAL_ARRAY_LIST_IBM 103071 +#define GL_COLOR_ARRAY_LIST_IBM 103072 +#define GL_INDEX_ARRAY_LIST_IBM 103073 +#define GL_TEXTURE_COORD_ARRAY_LIST_IBM 103074 +#define GL_EDGE_FLAG_ARRAY_LIST_IBM 103075 +#define GL_FOG_COORDINATE_ARRAY_LIST_IBM 103076 +#define GL_SECONDARY_COLOR_ARRAY_LIST_IBM 103077 +#define GL_VERTEX_ARRAY_LIST_STRIDE_IBM 103080 +#define GL_NORMAL_ARRAY_LIST_STRIDE_IBM 103081 +#define GL_COLOR_ARRAY_LIST_STRIDE_IBM 103082 +#define GL_INDEX_ARRAY_LIST_STRIDE_IBM 103083 +#define GL_TEXTURE_COORD_ARRAY_LIST_STRIDE_IBM 103084 +#define GL_EDGE_FLAG_ARRAY_LIST_STRIDE_IBM 103085 +#define GL_FOG_COORDINATE_ARRAY_LIST_STRIDE_IBM 103086 +#define GL_SECONDARY_COLOR_ARRAY_LIST_STRIDE_IBM 103087 +#endif + +#ifndef GL_SGIX_subsample +#define GL_PACK_SUBSAMPLE_RATE_SGIX 0x85A0 +#define GL_UNPACK_SUBSAMPLE_RATE_SGIX 0x85A1 +#define GL_PIXEL_SUBSAMPLE_4444_SGIX 0x85A2 +#define GL_PIXEL_SUBSAMPLE_2424_SGIX 0x85A3 +#define GL_PIXEL_SUBSAMPLE_4242_SGIX 0x85A4 +#endif + +#ifndef GL_SGIX_ycrcb_subsample +#endif + +#ifndef GL_SGIX_ycrcba +#define GL_YCRCB_SGIX 0x8318 +#define GL_YCRCBA_SGIX 0x8319 +#endif + +#ifndef GL_SGI_depth_pass_instrument +#define GL_DEPTH_PASS_INSTRUMENT_SGIX 0x8310 +#define GL_DEPTH_PASS_INSTRUMENT_COUNTERS_SGIX 0x8311 +#define GL_DEPTH_PASS_INSTRUMENT_MAX_SGIX 0x8312 +#endif + +#ifndef GL_3DFX_texture_compression_FXT1 +#define GL_COMPRESSED_RGB_FXT1_3DFX 0x86B0 +#define GL_COMPRESSED_RGBA_FXT1_3DFX 0x86B1 +#endif + +#ifndef GL_3DFX_multisample +#define GL_MULTISAMPLE_3DFX 0x86B2 +#define GL_SAMPLE_BUFFERS_3DFX 0x86B3 +#define GL_SAMPLES_3DFX 0x86B4 +#define GL_MULTISAMPLE_BIT_3DFX 0x20000000 +#endif + +#ifndef GL_3DFX_tbuffer +#endif + +#ifndef GL_EXT_multisample +#define GL_MULTISAMPLE_EXT 0x809D +#define GL_SAMPLE_ALPHA_TO_MASK_EXT 0x809E +#define GL_SAMPLE_ALPHA_TO_ONE_EXT 0x809F +#define GL_SAMPLE_MASK_EXT 0x80A0 +#define GL_1PASS_EXT 0x80A1 +#define GL_2PASS_0_EXT 0x80A2 +#define GL_2PASS_1_EXT 0x80A3 +#define GL_4PASS_0_EXT 0x80A4 +#define GL_4PASS_1_EXT 0x80A5 +#define GL_4PASS_2_EXT 0x80A6 +#define GL_4PASS_3_EXT 0x80A7 +#define GL_SAMPLE_BUFFERS_EXT 0x80A8 +#define GL_SAMPLES_EXT 0x80A9 +#define GL_SAMPLE_MASK_VALUE_EXT 0x80AA +#define GL_SAMPLE_MASK_INVERT_EXT 0x80AB +#define GL_SAMPLE_PATTERN_EXT 0x80AC +#define GL_MULTISAMPLE_BIT_EXT 0x20000000 +#endif + +#ifndef GL_SGIX_vertex_preclip +#define GL_VERTEX_PRECLIP_SGIX 0x83EE +#define GL_VERTEX_PRECLIP_HINT_SGIX 0x83EF +#endif + +#ifndef GL_SGIX_convolution_accuracy +#define GL_CONVOLUTION_HINT_SGIX 0x8316 +#endif + +#ifndef GL_SGIX_resample +#define GL_PACK_RESAMPLE_SGIX 0x842C +#define GL_UNPACK_RESAMPLE_SGIX 0x842D +#define GL_RESAMPLE_REPLICATE_SGIX 0x842E +#define GL_RESAMPLE_ZERO_FILL_SGIX 0x842F +#define GL_RESAMPLE_DECIMATE_SGIX 0x8430 +#endif + +#ifndef GL_SGIS_point_line_texgen +#define GL_EYE_DISTANCE_TO_POINT_SGIS 0x81F0 +#define GL_OBJECT_DISTANCE_TO_POINT_SGIS 0x81F1 +#define GL_EYE_DISTANCE_TO_LINE_SGIS 0x81F2 +#define GL_OBJECT_DISTANCE_TO_LINE_SGIS 0x81F3 +#define GL_EYE_POINT_SGIS 0x81F4 +#define GL_OBJECT_POINT_SGIS 0x81F5 +#define GL_EYE_LINE_SGIS 0x81F6 +#define GL_OBJECT_LINE_SGIS 0x81F7 +#endif + +#ifndef GL_SGIS_texture_color_mask +#define GL_TEXTURE_COLOR_WRITEMASK_SGIS 0x81EF +#endif + +#ifndef GL_EXT_texture_env_dot3 +#define GL_DOT3_RGB_EXT 0x8740 +#define GL_DOT3_RGBA_EXT 0x8741 +#endif + +#ifndef GL_ATI_texture_mirror_once +#define GL_MIRROR_CLAMP_ATI 0x8742 +#define GL_MIRROR_CLAMP_TO_EDGE_ATI 0x8743 +#endif + +#ifndef GL_NV_fence +#define GL_ALL_COMPLETED_NV 0x84F2 +#define GL_FENCE_STATUS_NV 0x84F3 +#define GL_FENCE_CONDITION_NV 0x84F4 +#endif + +#ifndef GL_IBM_texture_mirrored_repeat +#define GL_MIRRORED_REPEAT_IBM 0x8370 +#endif + +#ifndef GL_NV_evaluators +#define GL_EVAL_2D_NV 0x86C0 +#define GL_EVAL_TRIANGULAR_2D_NV 0x86C1 +#define GL_MAP_TESSELLATION_NV 0x86C2 +#define GL_MAP_ATTRIB_U_ORDER_NV 0x86C3 +#define GL_MAP_ATTRIB_V_ORDER_NV 0x86C4 +#define GL_EVAL_FRACTIONAL_TESSELLATION_NV 0x86C5 +#define GL_EVAL_VERTEX_ATTRIB0_NV 0x86C6 +#define GL_EVAL_VERTEX_ATTRIB1_NV 0x86C7 +#define GL_EVAL_VERTEX_ATTRIB2_NV 0x86C8 +#define GL_EVAL_VERTEX_ATTRIB3_NV 0x86C9 +#define GL_EVAL_VERTEX_ATTRIB4_NV 0x86CA +#define GL_EVAL_VERTEX_ATTRIB5_NV 0x86CB +#define GL_EVAL_VERTEX_ATTRIB6_NV 0x86CC +#define GL_EVAL_VERTEX_ATTRIB7_NV 0x86CD +#define GL_EVAL_VERTEX_ATTRIB8_NV 0x86CE +#define GL_EVAL_VERTEX_ATTRIB9_NV 0x86CF +#define GL_EVAL_VERTEX_ATTRIB10_NV 0x86D0 +#define GL_EVAL_VERTEX_ATTRIB11_NV 0x86D1 +#define GL_EVAL_VERTEX_ATTRIB12_NV 0x86D2 +#define GL_EVAL_VERTEX_ATTRIB13_NV 0x86D3 +#define GL_EVAL_VERTEX_ATTRIB14_NV 0x86D4 +#define GL_EVAL_VERTEX_ATTRIB15_NV 0x86D5 +#define GL_MAX_MAP_TESSELLATION_NV 0x86D6 +#define GL_MAX_RATIONAL_EVAL_ORDER_NV 0x86D7 +#endif + +#ifndef GL_NV_packed_depth_stencil +#define GL_DEPTH_STENCIL_NV 0x84F9 +#define GL_UNSIGNED_INT_24_8_NV 0x84FA +#endif + +#ifndef GL_NV_register_combiners2 +#define GL_PER_STAGE_CONSTANTS_NV 0x8535 +#endif + +#ifndef GL_NV_texture_compression_vtc +#endif + +#ifndef GL_NV_texture_rectangle +#define GL_TEXTURE_RECTANGLE_NV 0x84F5 +#define GL_TEXTURE_BINDING_RECTANGLE_NV 0x84F6 +#define GL_PROXY_TEXTURE_RECTANGLE_NV 0x84F7 +#define GL_MAX_RECTANGLE_TEXTURE_SIZE_NV 0x84F8 +#endif + +#ifndef GL_NV_texture_shader +#define GL_OFFSET_TEXTURE_RECTANGLE_NV 0x864C +#define GL_OFFSET_TEXTURE_RECTANGLE_SCALE_NV 0x864D +#define GL_DOT_PRODUCT_TEXTURE_RECTANGLE_NV 0x864E +#define GL_RGBA_UNSIGNED_DOT_PRODUCT_MAPPING_NV 0x86D9 +#define GL_UNSIGNED_INT_S8_S8_8_8_NV 0x86DA +#define GL_UNSIGNED_INT_8_8_S8_S8_REV_NV 0x86DB +#define GL_DSDT_MAG_INTENSITY_NV 0x86DC +#define GL_SHADER_CONSISTENT_NV 0x86DD +#define GL_TEXTURE_SHADER_NV 0x86DE +#define GL_SHADER_OPERATION_NV 0x86DF +#define GL_CULL_MODES_NV 0x86E0 +#define GL_OFFSET_TEXTURE_MATRIX_NV 0x86E1 +#define GL_OFFSET_TEXTURE_SCALE_NV 0x86E2 +#define GL_OFFSET_TEXTURE_BIAS_NV 0x86E3 +#define GL_OFFSET_TEXTURE_2D_MATRIX_NV GL_OFFSET_TEXTURE_MATRIX_NV +#define GL_OFFSET_TEXTURE_2D_SCALE_NV GL_OFFSET_TEXTURE_SCALE_NV +#define GL_OFFSET_TEXTURE_2D_BIAS_NV GL_OFFSET_TEXTURE_BIAS_NV +#define GL_PREVIOUS_TEXTURE_INPUT_NV 0x86E4 +#define GL_CONST_EYE_NV 0x86E5 +#define GL_PASS_THROUGH_NV 0x86E6 +#define GL_CULL_FRAGMENT_NV 0x86E7 +#define GL_OFFSET_TEXTURE_2D_NV 0x86E8 +#define GL_DEPENDENT_AR_TEXTURE_2D_NV 0x86E9 +#define GL_DEPENDENT_GB_TEXTURE_2D_NV 0x86EA +#define GL_DOT_PRODUCT_NV 0x86EC +#define GL_DOT_PRODUCT_DEPTH_REPLACE_NV 0x86ED +#define GL_DOT_PRODUCT_TEXTURE_2D_NV 0x86EE +#define GL_DOT_PRODUCT_TEXTURE_CUBE_MAP_NV 0x86F0 +#define GL_DOT_PRODUCT_DIFFUSE_CUBE_MAP_NV 0x86F1 +#define GL_DOT_PRODUCT_REFLECT_CUBE_MAP_NV 0x86F2 +#define GL_DOT_PRODUCT_CONST_EYE_REFLECT_CUBE_MAP_NV 0x86F3 +#define GL_HILO_NV 0x86F4 +#define GL_DSDT_NV 0x86F5 +#define GL_DSDT_MAG_NV 0x86F6 +#define GL_DSDT_MAG_VIB_NV 0x86F7 +#define GL_HILO16_NV 0x86F8 +#define GL_SIGNED_HILO_NV 0x86F9 +#define GL_SIGNED_HILO16_NV 0x86FA +#define GL_SIGNED_RGBA_NV 0x86FB +#define GL_SIGNED_RGBA8_NV 0x86FC +#define GL_SIGNED_RGB_NV 0x86FE +#define GL_SIGNED_RGB8_NV 0x86FF +#define GL_SIGNED_LUMINANCE_NV 0x8701 +#define GL_SIGNED_LUMINANCE8_NV 0x8702 +#define GL_SIGNED_LUMINANCE_ALPHA_NV 0x8703 +#define GL_SIGNED_LUMINANCE8_ALPHA8_NV 0x8704 +#define GL_SIGNED_ALPHA_NV 0x8705 +#define GL_SIGNED_ALPHA8_NV 0x8706 +#define GL_SIGNED_INTENSITY_NV 0x8707 +#define GL_SIGNED_INTENSITY8_NV 0x8708 +#define GL_DSDT8_NV 0x8709 +#define GL_DSDT8_MAG8_NV 0x870A +#define GL_DSDT8_MAG8_INTENSITY8_NV 0x870B +#define GL_SIGNED_RGB_UNSIGNED_ALPHA_NV 0x870C +#define GL_SIGNED_RGB8_UNSIGNED_ALPHA8_NV 0x870D +#define GL_HI_SCALE_NV 0x870E +#define GL_LO_SCALE_NV 0x870F +#define GL_DS_SCALE_NV 0x8710 +#define GL_DT_SCALE_NV 0x8711 +#define GL_MAGNITUDE_SCALE_NV 0x8712 +#define GL_VIBRANCE_SCALE_NV 0x8713 +#define GL_HI_BIAS_NV 0x8714 +#define GL_LO_BIAS_NV 0x8715 +#define GL_DS_BIAS_NV 0x8716 +#define GL_DT_BIAS_NV 0x8717 +#define GL_MAGNITUDE_BIAS_NV 0x8718 +#define GL_VIBRANCE_BIAS_NV 0x8719 +#define GL_TEXTURE_BORDER_VALUES_NV 0x871A +#define GL_TEXTURE_HI_SIZE_NV 0x871B +#define GL_TEXTURE_LO_SIZE_NV 0x871C +#define GL_TEXTURE_DS_SIZE_NV 0x871D +#define GL_TEXTURE_DT_SIZE_NV 0x871E +#define GL_TEXTURE_MAG_SIZE_NV 0x871F +#endif + +#ifndef GL_NV_texture_shader2 +#define GL_DOT_PRODUCT_TEXTURE_3D_NV 0x86EF +#endif + +#ifndef GL_NV_vertex_array_range2 +#define GL_VERTEX_ARRAY_RANGE_WITHOUT_FLUSH_NV 0x8533 +#endif + +#ifndef GL_NV_vertex_program +#define GL_VERTEX_PROGRAM_NV 0x8620 +#define GL_VERTEX_STATE_PROGRAM_NV 0x8621 +#define GL_ATTRIB_ARRAY_SIZE_NV 0x8623 +#define GL_ATTRIB_ARRAY_STRIDE_NV 0x8624 +#define GL_ATTRIB_ARRAY_TYPE_NV 0x8625 +#define GL_CURRENT_ATTRIB_NV 0x8626 +#define GL_PROGRAM_LENGTH_NV 0x8627 +#define GL_PROGRAM_STRING_NV 0x8628 +#define GL_MODELVIEW_PROJECTION_NV 0x8629 +#define GL_IDENTITY_NV 0x862A +#define GL_INVERSE_NV 0x862B +#define GL_TRANSPOSE_NV 0x862C +#define GL_INVERSE_TRANSPOSE_NV 0x862D +#define GL_MAX_TRACK_MATRIX_STACK_DEPTH_NV 0x862E +#define GL_MAX_TRACK_MATRICES_NV 0x862F +#define GL_MATRIX0_NV 0x8630 +#define GL_MATRIX1_NV 0x8631 +#define GL_MATRIX2_NV 0x8632 +#define GL_MATRIX3_NV 0x8633 +#define GL_MATRIX4_NV 0x8634 +#define GL_MATRIX5_NV 0x8635 +#define GL_MATRIX6_NV 0x8636 +#define GL_MATRIX7_NV 0x8637 +#define GL_CURRENT_MATRIX_STACK_DEPTH_NV 0x8640 +#define GL_CURRENT_MATRIX_NV 0x8641 +#define GL_VERTEX_PROGRAM_POINT_SIZE_NV 0x8642 +#define GL_VERTEX_PROGRAM_TWO_SIDE_NV 0x8643 +#define GL_PROGRAM_PARAMETER_NV 0x8644 +#define GL_ATTRIB_ARRAY_POINTER_NV 0x8645 +#define GL_PROGRAM_TARGET_NV 0x8646 +#define GL_PROGRAM_RESIDENT_NV 0x8647 +#define GL_TRACK_MATRIX_NV 0x8648 +#define GL_TRACK_MATRIX_TRANSFORM_NV 0x8649 +#define GL_VERTEX_PROGRAM_BINDING_NV 0x864A +#define GL_PROGRAM_ERROR_POSITION_NV 0x864B +#define GL_VERTEX_ATTRIB_ARRAY0_NV 0x8650 +#define GL_VERTEX_ATTRIB_ARRAY1_NV 0x8651 +#define GL_VERTEX_ATTRIB_ARRAY2_NV 0x8652 +#define GL_VERTEX_ATTRIB_ARRAY3_NV 0x8653 +#define GL_VERTEX_ATTRIB_ARRAY4_NV 0x8654 +#define GL_VERTEX_ATTRIB_ARRAY5_NV 0x8655 +#define GL_VERTEX_ATTRIB_ARRAY6_NV 0x8656 +#define GL_VERTEX_ATTRIB_ARRAY7_NV 0x8657 +#define GL_VERTEX_ATTRIB_ARRAY8_NV 0x8658 +#define GL_VERTEX_ATTRIB_ARRAY9_NV 0x8659 +#define GL_VERTEX_ATTRIB_ARRAY10_NV 0x865A +#define GL_VERTEX_ATTRIB_ARRAY11_NV 0x865B +#define GL_VERTEX_ATTRIB_ARRAY12_NV 0x865C +#define GL_VERTEX_ATTRIB_ARRAY13_NV 0x865D +#define GL_VERTEX_ATTRIB_ARRAY14_NV 0x865E +#define GL_VERTEX_ATTRIB_ARRAY15_NV 0x865F +#define GL_MAP1_VERTEX_ATTRIB0_4_NV 0x8660 +#define GL_MAP1_VERTEX_ATTRIB1_4_NV 0x8661 +#define GL_MAP1_VERTEX_ATTRIB2_4_NV 0x8662 +#define GL_MAP1_VERTEX_ATTRIB3_4_NV 0x8663 +#define GL_MAP1_VERTEX_ATTRIB4_4_NV 0x8664 +#define GL_MAP1_VERTEX_ATTRIB5_4_NV 0x8665 +#define GL_MAP1_VERTEX_ATTRIB6_4_NV 0x8666 +#define GL_MAP1_VERTEX_ATTRIB7_4_NV 0x8667 +#define GL_MAP1_VERTEX_ATTRIB8_4_NV 0x8668 +#define GL_MAP1_VERTEX_ATTRIB9_4_NV 0x8669 +#define GL_MAP1_VERTEX_ATTRIB10_4_NV 0x866A +#define GL_MAP1_VERTEX_ATTRIB11_4_NV 0x866B +#define GL_MAP1_VERTEX_ATTRIB12_4_NV 0x866C +#define GL_MAP1_VERTEX_ATTRIB13_4_NV 0x866D +#define GL_MAP1_VERTEX_ATTRIB14_4_NV 0x866E +#define GL_MAP1_VERTEX_ATTRIB15_4_NV 0x866F +#define GL_MAP2_VERTEX_ATTRIB0_4_NV 0x8670 +#define GL_MAP2_VERTEX_ATTRIB1_4_NV 0x8671 +#define GL_MAP2_VERTEX_ATTRIB2_4_NV 0x8672 +#define GL_MAP2_VERTEX_ATTRIB3_4_NV 0x8673 +#define GL_MAP2_VERTEX_ATTRIB4_4_NV 0x8674 +#define GL_MAP2_VERTEX_ATTRIB5_4_NV 0x8675 +#define GL_MAP2_VERTEX_ATTRIB6_4_NV 0x8676 +#define GL_MAP2_VERTEX_ATTRIB7_4_NV 0x8677 +#define GL_MAP2_VERTEX_ATTRIB8_4_NV 0x8678 +#define GL_MAP2_VERTEX_ATTRIB9_4_NV 0x8679 +#define GL_MAP2_VERTEX_ATTRIB10_4_NV 0x867A +#define GL_MAP2_VERTEX_ATTRIB11_4_NV 0x867B +#define GL_MAP2_VERTEX_ATTRIB12_4_NV 0x867C +#define GL_MAP2_VERTEX_ATTRIB13_4_NV 0x867D +#define GL_MAP2_VERTEX_ATTRIB14_4_NV 0x867E +#define GL_MAP2_VERTEX_ATTRIB15_4_NV 0x867F +#endif + +#ifndef GL_SGIX_texture_coordinate_clamp +#define GL_TEXTURE_MAX_CLAMP_S_SGIX 0x8369 +#define GL_TEXTURE_MAX_CLAMP_T_SGIX 0x836A +#define GL_TEXTURE_MAX_CLAMP_R_SGIX 0x836B +#endif + +#ifndef GL_SGIX_scalebias_hint +#define GL_SCALEBIAS_HINT_SGIX 0x8322 +#endif + +#ifndef GL_OML_interlace +#define GL_INTERLACE_OML 0x8980 +#define GL_INTERLACE_READ_OML 0x8981 +#endif + +#ifndef GL_OML_subsample +#define GL_FORMAT_SUBSAMPLE_24_24_OML 0x8982 +#define GL_FORMAT_SUBSAMPLE_244_244_OML 0x8983 +#endif + +#ifndef GL_OML_resample +#define GL_PACK_RESAMPLE_OML 0x8984 +#define GL_UNPACK_RESAMPLE_OML 0x8985 +#define GL_RESAMPLE_REPLICATE_OML 0x8986 +#define GL_RESAMPLE_ZERO_FILL_OML 0x8987 +#define GL_RESAMPLE_AVERAGE_OML 0x8988 +#define GL_RESAMPLE_DECIMATE_OML 0x8989 +#endif + +#ifndef GL_NV_copy_depth_to_color +#define GL_DEPTH_STENCIL_TO_RGBA_NV 0x886E +#define GL_DEPTH_STENCIL_TO_BGRA_NV 0x886F +#endif + +#ifndef GL_ATI_envmap_bumpmap +#define GL_BUMP_ROT_MATRIX_ATI 0x8775 +#define GL_BUMP_ROT_MATRIX_SIZE_ATI 0x8776 +#define GL_BUMP_NUM_TEX_UNITS_ATI 0x8777 +#define GL_BUMP_TEX_UNITS_ATI 0x8778 +#define GL_DUDV_ATI 0x8779 +#define GL_DU8DV8_ATI 0x877A +#define GL_BUMP_ENVMAP_ATI 0x877B +#define GL_BUMP_TARGET_ATI 0x877C +#endif + +#ifndef GL_ATI_fragment_shader +#define GL_FRAGMENT_SHADER_ATI 0x8920 +#define GL_REG_0_ATI 0x8921 +#define GL_REG_1_ATI 0x8922 +#define GL_REG_2_ATI 0x8923 +#define GL_REG_3_ATI 0x8924 +#define GL_REG_4_ATI 0x8925 +#define GL_REG_5_ATI 0x8926 +#define GL_REG_6_ATI 0x8927 +#define GL_REG_7_ATI 0x8928 +#define GL_REG_8_ATI 0x8929 +#define GL_REG_9_ATI 0x892A +#define GL_REG_10_ATI 0x892B +#define GL_REG_11_ATI 0x892C +#define GL_REG_12_ATI 0x892D +#define GL_REG_13_ATI 0x892E +#define GL_REG_14_ATI 0x892F +#define GL_REG_15_ATI 0x8930 +#define GL_REG_16_ATI 0x8931 +#define GL_REG_17_ATI 0x8932 +#define GL_REG_18_ATI 0x8933 +#define GL_REG_19_ATI 0x8934 +#define GL_REG_20_ATI 0x8935 +#define GL_REG_21_ATI 0x8936 +#define GL_REG_22_ATI 0x8937 +#define GL_REG_23_ATI 0x8938 +#define GL_REG_24_ATI 0x8939 +#define GL_REG_25_ATI 0x893A +#define GL_REG_26_ATI 0x893B +#define GL_REG_27_ATI 0x893C +#define GL_REG_28_ATI 0x893D +#define GL_REG_29_ATI 0x893E +#define GL_REG_30_ATI 0x893F +#define GL_REG_31_ATI 0x8940 +#define GL_CON_0_ATI 0x8941 +#define GL_CON_1_ATI 0x8942 +#define GL_CON_2_ATI 0x8943 +#define GL_CON_3_ATI 0x8944 +#define GL_CON_4_ATI 0x8945 +#define GL_CON_5_ATI 0x8946 +#define GL_CON_6_ATI 0x8947 +#define GL_CON_7_ATI 0x8948 +#define GL_CON_8_ATI 0x8949 +#define GL_CON_9_ATI 0x894A +#define GL_CON_10_ATI 0x894B +#define GL_CON_11_ATI 0x894C +#define GL_CON_12_ATI 0x894D +#define GL_CON_13_ATI 0x894E +#define GL_CON_14_ATI 0x894F +#define GL_CON_15_ATI 0x8950 +#define GL_CON_16_ATI 0x8951 +#define GL_CON_17_ATI 0x8952 +#define GL_CON_18_ATI 0x8953 +#define GL_CON_19_ATI 0x8954 +#define GL_CON_20_ATI 0x8955 +#define GL_CON_21_ATI 0x8956 +#define GL_CON_22_ATI 0x8957 +#define GL_CON_23_ATI 0x8958 +#define GL_CON_24_ATI 0x8959 +#define GL_CON_25_ATI 0x895A +#define GL_CON_26_ATI 0x895B +#define GL_CON_27_ATI 0x895C +#define GL_CON_28_ATI 0x895D +#define GL_CON_29_ATI 0x895E +#define GL_CON_30_ATI 0x895F +#define GL_CON_31_ATI 0x8960 +#define GL_MOV_ATI 0x8961 +#define GL_ADD_ATI 0x8963 +#define GL_MUL_ATI 0x8964 +#define GL_SUB_ATI 0x8965 +#define GL_DOT3_ATI 0x8966 +#define GL_DOT4_ATI 0x8967 +#define GL_MAD_ATI 0x8968 +#define GL_LERP_ATI 0x8969 +#define GL_CND_ATI 0x896A +#define GL_CND0_ATI 0x896B +#define GL_DOT2_ADD_ATI 0x896C +#define GL_SECONDARY_INTERPOLATOR_ATI 0x896D +#define GL_NUM_FRAGMENT_REGISTERS_ATI 0x896E +#define GL_NUM_FRAGMENT_CONSTANTS_ATI 0x896F +#define GL_NUM_PASSES_ATI 0x8970 +#define GL_NUM_INSTRUCTIONS_PER_PASS_ATI 0x8971 +#define GL_NUM_INSTRUCTIONS_TOTAL_ATI 0x8972 +#define GL_NUM_INPUT_INTERPOLATOR_COMPONENTS_ATI 0x8973 +#define GL_NUM_LOOPBACK_COMPONENTS_ATI 0x8974 +#define GL_COLOR_ALPHA_PAIRING_ATI 0x8975 +#define GL_SWIZZLE_STR_ATI 0x8976 +#define GL_SWIZZLE_STQ_ATI 0x8977 +#define GL_SWIZZLE_STR_DR_ATI 0x8978 +#define GL_SWIZZLE_STQ_DQ_ATI 0x8979 +#define GL_SWIZZLE_STRQ_ATI 0x897A +#define GL_SWIZZLE_STRQ_DQ_ATI 0x897B +#define GL_RED_BIT_ATI 0x00000001 +#define GL_GREEN_BIT_ATI 0x00000002 +#define GL_BLUE_BIT_ATI 0x00000004 +#define GL_2X_BIT_ATI 0x00000001 +#define GL_4X_BIT_ATI 0x00000002 +#define GL_8X_BIT_ATI 0x00000004 +#define GL_HALF_BIT_ATI 0x00000008 +#define GL_QUARTER_BIT_ATI 0x00000010 +#define GL_EIGHTH_BIT_ATI 0x00000020 +#define GL_SATURATE_BIT_ATI 0x00000040 +#define GL_COMP_BIT_ATI 0x00000002 +#define GL_NEGATE_BIT_ATI 0x00000004 +#define GL_BIAS_BIT_ATI 0x00000008 +#endif + +#ifndef GL_ATI_pn_triangles +#define GL_PN_TRIANGLES_ATI 0x87F0 +#define GL_MAX_PN_TRIANGLES_TESSELATION_LEVEL_ATI 0x87F1 +#define GL_PN_TRIANGLES_POINT_MODE_ATI 0x87F2 +#define GL_PN_TRIANGLES_NORMAL_MODE_ATI 0x87F3 +#define GL_PN_TRIANGLES_TESSELATION_LEVEL_ATI 0x87F4 +#define GL_PN_TRIANGLES_POINT_MODE_LINEAR_ATI 0x87F5 +#define GL_PN_TRIANGLES_POINT_MODE_CUBIC_ATI 0x87F6 +#define GL_PN_TRIANGLES_NORMAL_MODE_LINEAR_ATI 0x87F7 +#define GL_PN_TRIANGLES_NORMAL_MODE_QUADRATIC_ATI 0x87F8 +#endif + +#ifndef GL_ATI_vertex_array_object +#define GL_STATIC_ATI 0x8760 +#define GL_DYNAMIC_ATI 0x8761 +#define GL_PRESERVE_ATI 0x8762 +#define GL_DISCARD_ATI 0x8763 +#define GL_OBJECT_BUFFER_SIZE_ATI 0x8764 +#define GL_OBJECT_BUFFER_USAGE_ATI 0x8765 +#define GL_ARRAY_OBJECT_BUFFER_ATI 0x8766 +#define GL_ARRAY_OBJECT_OFFSET_ATI 0x8767 +#endif + +#ifndef GL_EXT_vertex_shader +#define GL_VERTEX_SHADER_EXT 0x8780 +#define GL_VERTEX_SHADER_BINDING_EXT 0x8781 +#define GL_OP_INDEX_EXT 0x8782 +#define GL_OP_NEGATE_EXT 0x8783 +#define GL_OP_DOT3_EXT 0x8784 +#define GL_OP_DOT4_EXT 0x8785 +#define GL_OP_MUL_EXT 0x8786 +#define GL_OP_ADD_EXT 0x8787 +#define GL_OP_MADD_EXT 0x8788 +#define GL_OP_FRAC_EXT 0x8789 +#define GL_OP_MAX_EXT 0x878A +#define GL_OP_MIN_EXT 0x878B +#define GL_OP_SET_GE_EXT 0x878C +#define GL_OP_SET_LT_EXT 0x878D +#define GL_OP_CLAMP_EXT 0x878E +#define GL_OP_FLOOR_EXT 0x878F +#define GL_OP_ROUND_EXT 0x8790 +#define GL_OP_EXP_BASE_2_EXT 0x8791 +#define GL_OP_LOG_BASE_2_EXT 0x8792 +#define GL_OP_POWER_EXT 0x8793 +#define GL_OP_RECIP_EXT 0x8794 +#define GL_OP_RECIP_SQRT_EXT 0x8795 +#define GL_OP_SUB_EXT 0x8796 +#define GL_OP_CROSS_PRODUCT_EXT 0x8797 +#define GL_OP_MULTIPLY_MATRIX_EXT 0x8798 +#define GL_OP_MOV_EXT 0x8799 +#define GL_OUTPUT_VERTEX_EXT 0x879A +#define GL_OUTPUT_COLOR0_EXT 0x879B +#define GL_OUTPUT_COLOR1_EXT 0x879C +#define GL_OUTPUT_TEXTURE_COORD0_EXT 0x879D +#define GL_OUTPUT_TEXTURE_COORD1_EXT 0x879E +#define GL_OUTPUT_TEXTURE_COORD2_EXT 0x879F +#define GL_OUTPUT_TEXTURE_COORD3_EXT 0x87A0 +#define GL_OUTPUT_TEXTURE_COORD4_EXT 0x87A1 +#define GL_OUTPUT_TEXTURE_COORD5_EXT 0x87A2 +#define GL_OUTPUT_TEXTURE_COORD6_EXT 0x87A3 +#define GL_OUTPUT_TEXTURE_COORD7_EXT 0x87A4 +#define GL_OUTPUT_TEXTURE_COORD8_EXT 0x87A5 +#define GL_OUTPUT_TEXTURE_COORD9_EXT 0x87A6 +#define GL_OUTPUT_TEXTURE_COORD10_EXT 0x87A7 +#define GL_OUTPUT_TEXTURE_COORD11_EXT 0x87A8 +#define GL_OUTPUT_TEXTURE_COORD12_EXT 0x87A9 +#define GL_OUTPUT_TEXTURE_COORD13_EXT 0x87AA +#define GL_OUTPUT_TEXTURE_COORD14_EXT 0x87AB +#define GL_OUTPUT_TEXTURE_COORD15_EXT 0x87AC +#define GL_OUTPUT_TEXTURE_COORD16_EXT 0x87AD +#define GL_OUTPUT_TEXTURE_COORD17_EXT 0x87AE +#define GL_OUTPUT_TEXTURE_COORD18_EXT 0x87AF +#define GL_OUTPUT_TEXTURE_COORD19_EXT 0x87B0 +#define GL_OUTPUT_TEXTURE_COORD20_EXT 0x87B1 +#define GL_OUTPUT_TEXTURE_COORD21_EXT 0x87B2 +#define GL_OUTPUT_TEXTURE_COORD22_EXT 0x87B3 +#define GL_OUTPUT_TEXTURE_COORD23_EXT 0x87B4 +#define GL_OUTPUT_TEXTURE_COORD24_EXT 0x87B5 +#define GL_OUTPUT_TEXTURE_COORD25_EXT 0x87B6 +#define GL_OUTPUT_TEXTURE_COORD26_EXT 0x87B7 +#define GL_OUTPUT_TEXTURE_COORD27_EXT 0x87B8 +#define GL_OUTPUT_TEXTURE_COORD28_EXT 0x87B9 +#define GL_OUTPUT_TEXTURE_COORD29_EXT 0x87BA +#define GL_OUTPUT_TEXTURE_COORD30_EXT 0x87BB +#define GL_OUTPUT_TEXTURE_COORD31_EXT 0x87BC +#define GL_OUTPUT_FOG_EXT 0x87BD +#define GL_SCALAR_EXT 0x87BE +#define GL_VECTOR_EXT 0x87BF +#define GL_MATRIX_EXT 0x87C0 +#define GL_VARIANT_EXT 0x87C1 +#define GL_INVARIANT_EXT 0x87C2 +#define GL_LOCAL_CONSTANT_EXT 0x87C3 +#define GL_LOCAL_EXT 0x87C4 +#define GL_MAX_VERTEX_SHADER_INSTRUCTIONS_EXT 0x87C5 +#define GL_MAX_VERTEX_SHADER_VARIANTS_EXT 0x87C6 +#define GL_MAX_VERTEX_SHADER_INVARIANTS_EXT 0x87C7 +#define GL_MAX_VERTEX_SHADER_LOCAL_CONSTANTS_EXT 0x87C8 +#define GL_MAX_VERTEX_SHADER_LOCALS_EXT 0x87C9 +#define GL_MAX_OPTIMIZED_VERTEX_SHADER_INSTRUCTIONS_EXT 0x87CA +#define GL_MAX_OPTIMIZED_VERTEX_SHADER_VARIANTS_EXT 0x87CB +#define GL_MAX_OPTIMIZED_VERTEX_SHADER_LOCAL_CONSTANTS_EXT 0x87CC +#define GL_MAX_OPTIMIZED_VERTEX_SHADER_INVARIANTS_EXT 0x87CD +#define GL_MAX_OPTIMIZED_VERTEX_SHADER_LOCALS_EXT 0x87CE +#define GL_VERTEX_SHADER_INSTRUCTIONS_EXT 0x87CF +#define GL_VERTEX_SHADER_VARIANTS_EXT 0x87D0 +#define GL_VERTEX_SHADER_INVARIANTS_EXT 0x87D1 +#define GL_VERTEX_SHADER_LOCAL_CONSTANTS_EXT 0x87D2 +#define GL_VERTEX_SHADER_LOCALS_EXT 0x87D3 +#define GL_VERTEX_SHADER_OPTIMIZED_EXT 0x87D4 +#define GL_X_EXT 0x87D5 +#define GL_Y_EXT 0x87D6 +#define GL_Z_EXT 0x87D7 +#define GL_W_EXT 0x87D8 +#define GL_NEGATIVE_X_EXT 0x87D9 +#define GL_NEGATIVE_Y_EXT 0x87DA +#define GL_NEGATIVE_Z_EXT 0x87DB +#define GL_NEGATIVE_W_EXT 0x87DC +#define GL_ZERO_EXT 0x87DD +#define GL_ONE_EXT 0x87DE +#define GL_NEGATIVE_ONE_EXT 0x87DF +#define GL_NORMALIZED_RANGE_EXT 0x87E0 +#define GL_FULL_RANGE_EXT 0x87E1 +#define GL_CURRENT_VERTEX_EXT 0x87E2 +#define GL_MVP_MATRIX_EXT 0x87E3 +#define GL_VARIANT_VALUE_EXT 0x87E4 +#define GL_VARIANT_DATATYPE_EXT 0x87E5 +#define GL_VARIANT_ARRAY_STRIDE_EXT 0x87E6 +#define GL_VARIANT_ARRAY_TYPE_EXT 0x87E7 +#define GL_VARIANT_ARRAY_EXT 0x87E8 +#define GL_VARIANT_ARRAY_POINTER_EXT 0x87E9 +#define GL_INVARIANT_VALUE_EXT 0x87EA +#define GL_INVARIANT_DATATYPE_EXT 0x87EB +#define GL_LOCAL_CONSTANT_VALUE_EXT 0x87EC +#define GL_LOCAL_CONSTANT_DATATYPE_EXT 0x87ED +#endif + +#ifndef GL_ATI_vertex_streams +#define GL_MAX_VERTEX_STREAMS_ATI 0x876B +#define GL_VERTEX_STREAM0_ATI 0x876C +#define GL_VERTEX_STREAM1_ATI 0x876D +#define GL_VERTEX_STREAM2_ATI 0x876E +#define GL_VERTEX_STREAM3_ATI 0x876F +#define GL_VERTEX_STREAM4_ATI 0x8770 +#define GL_VERTEX_STREAM5_ATI 0x8771 +#define GL_VERTEX_STREAM6_ATI 0x8772 +#define GL_VERTEX_STREAM7_ATI 0x8773 +#define GL_VERTEX_SOURCE_ATI 0x8774 +#endif + +#ifndef GL_ATI_element_array +#define GL_ELEMENT_ARRAY_ATI 0x8768 +#define GL_ELEMENT_ARRAY_TYPE_ATI 0x8769 +#define GL_ELEMENT_ARRAY_POINTER_ATI 0x876A +#endif + +#ifndef GL_SUN_mesh_array +#define GL_QUAD_MESH_SUN 0x8614 +#define GL_TRIANGLE_MESH_SUN 0x8615 +#endif + +#ifndef GL_SUN_slice_accum +#define GL_SLICE_ACCUM_SUN 0x85CC +#endif + +#ifndef GL_NV_multisample_filter_hint +#define GL_MULTISAMPLE_FILTER_HINT_NV 0x8534 +#endif + +#ifndef GL_NV_depth_clamp +#define GL_DEPTH_CLAMP_NV 0x864F +#endif + +#ifndef GL_NV_occlusion_query +#define GL_PIXEL_COUNTER_BITS_NV 0x8864 +#define GL_CURRENT_OCCLUSION_QUERY_ID_NV 0x8865 +#define GL_PIXEL_COUNT_NV 0x8866 +#define GL_PIXEL_COUNT_AVAILABLE_NV 0x8867 +#endif + +#ifndef GL_NV_point_sprite +#define GL_POINT_SPRITE_NV 0x8861 +#define GL_COORD_REPLACE_NV 0x8862 +#define GL_POINT_SPRITE_R_MODE_NV 0x8863 +#endif + +#ifndef GL_NV_texture_shader3 +#define GL_OFFSET_PROJECTIVE_TEXTURE_2D_NV 0x8850 +#define GL_OFFSET_PROJECTIVE_TEXTURE_2D_SCALE_NV 0x8851 +#define GL_OFFSET_PROJECTIVE_TEXTURE_RECTANGLE_NV 0x8852 +#define GL_OFFSET_PROJECTIVE_TEXTURE_RECTANGLE_SCALE_NV 0x8853 +#define GL_OFFSET_HILO_TEXTURE_2D_NV 0x8854 +#define GL_OFFSET_HILO_TEXTURE_RECTANGLE_NV 0x8855 +#define GL_OFFSET_HILO_PROJECTIVE_TEXTURE_2D_NV 0x8856 +#define GL_OFFSET_HILO_PROJECTIVE_TEXTURE_RECTANGLE_NV 0x8857 +#define GL_DEPENDENT_HILO_TEXTURE_2D_NV 0x8858 +#define GL_DEPENDENT_RGB_TEXTURE_3D_NV 0x8859 +#define GL_DEPENDENT_RGB_TEXTURE_CUBE_MAP_NV 0x885A +#define GL_DOT_PRODUCT_PASS_THROUGH_NV 0x885B +#define GL_DOT_PRODUCT_TEXTURE_1D_NV 0x885C +#define GL_DOT_PRODUCT_AFFINE_DEPTH_REPLACE_NV 0x885D +#define GL_HILO8_NV 0x885E +#define GL_SIGNED_HILO8_NV 0x885F +#define GL_FORCE_BLUE_TO_ONE_NV 0x8860 +#endif + +#ifndef GL_NV_vertex_program1_1 +#endif + +#ifndef GL_EXT_shadow_funcs +#endif + +#ifndef GL_EXT_stencil_two_side +#define GL_STENCIL_TEST_TWO_SIDE_EXT 0x8910 +#define GL_ACTIVE_STENCIL_FACE_EXT 0x8911 +#endif + +#ifndef GL_ATI_text_fragment_shader +#define GL_TEXT_FRAGMENT_SHADER_ATI 0x8200 +#endif + +#ifndef GL_APPLE_client_storage +#define GL_UNPACK_CLIENT_STORAGE_APPLE 0x85B2 +#endif + +#ifndef GL_APPLE_element_array +#define GL_ELEMENT_ARRAY_APPLE 0x8A0C +#define GL_ELEMENT_ARRAY_TYPE_APPLE 0x8A0D +#define GL_ELEMENT_ARRAY_POINTER_APPLE 0x8A0E +#endif + +#ifndef GL_APPLE_fence +#define GL_DRAW_PIXELS_APPLE 0x8A0A +#define GL_FENCE_APPLE 0x8A0B +#endif + +#ifndef GL_APPLE_vertex_array_object +#define GL_VERTEX_ARRAY_BINDING_APPLE 0x85B5 +#endif + +#ifndef GL_APPLE_vertex_array_range +#define GL_VERTEX_ARRAY_RANGE_APPLE 0x851D +#define GL_VERTEX_ARRAY_RANGE_LENGTH_APPLE 0x851E +#define GL_VERTEX_ARRAY_STORAGE_HINT_APPLE 0x851F +#define GL_VERTEX_ARRAY_RANGE_POINTER_APPLE 0x8521 +#define GL_STORAGE_CLIENT_APPLE 0x85B4 +#define GL_STORAGE_CACHED_APPLE 0x85BE +#define GL_STORAGE_SHARED_APPLE 0x85BF +#endif + +#ifndef GL_APPLE_ycbcr_422 +#define GL_YCBCR_422_APPLE 0x85B9 +#define GL_UNSIGNED_SHORT_8_8_APPLE 0x85BA +#define GL_UNSIGNED_SHORT_8_8_REV_APPLE 0x85BB +#endif + +#ifndef GL_S3_s3tc +#define GL_RGB_S3TC 0x83A0 +#define GL_RGB4_S3TC 0x83A1 +#define GL_RGBA_S3TC 0x83A2 +#define GL_RGBA4_S3TC 0x83A3 +#endif + +#ifndef GL_ATI_draw_buffers +#define GL_MAX_DRAW_BUFFERS_ATI 0x8824 +#define GL_DRAW_BUFFER0_ATI 0x8825 +#define GL_DRAW_BUFFER1_ATI 0x8826 +#define GL_DRAW_BUFFER2_ATI 0x8827 +#define GL_DRAW_BUFFER3_ATI 0x8828 +#define GL_DRAW_BUFFER4_ATI 0x8829 +#define GL_DRAW_BUFFER5_ATI 0x882A +#define GL_DRAW_BUFFER6_ATI 0x882B +#define GL_DRAW_BUFFER7_ATI 0x882C +#define GL_DRAW_BUFFER8_ATI 0x882D +#define GL_DRAW_BUFFER9_ATI 0x882E +#define GL_DRAW_BUFFER10_ATI 0x882F +#define GL_DRAW_BUFFER11_ATI 0x8830 +#define GL_DRAW_BUFFER12_ATI 0x8831 +#define GL_DRAW_BUFFER13_ATI 0x8832 +#define GL_DRAW_BUFFER14_ATI 0x8833 +#define GL_DRAW_BUFFER15_ATI 0x8834 +#endif + +#ifndef GL_ATI_pixel_format_float +#define GL_TYPE_RGBA_FLOAT_ATI 0x8820 +#define GL_COLOR_CLEAR_UNCLAMPED_VALUE_ATI 0x8835 +#endif + +#ifndef GL_ATI_texture_env_combine3 +#define GL_MODULATE_ADD_ATI 0x8744 +#define GL_MODULATE_SIGNED_ADD_ATI 0x8745 +#define GL_MODULATE_SUBTRACT_ATI 0x8746 +#endif + +#ifndef GL_ATI_texture_float +#define GL_RGBA_FLOAT32_ATI 0x8814 +#define GL_RGB_FLOAT32_ATI 0x8815 +#define GL_ALPHA_FLOAT32_ATI 0x8816 +#define GL_INTENSITY_FLOAT32_ATI 0x8817 +#define GL_LUMINANCE_FLOAT32_ATI 0x8818 +#define GL_LUMINANCE_ALPHA_FLOAT32_ATI 0x8819 +#define GL_RGBA_FLOAT16_ATI 0x881A +#define GL_RGB_FLOAT16_ATI 0x881B +#define GL_ALPHA_FLOAT16_ATI 0x881C +#define GL_INTENSITY_FLOAT16_ATI 0x881D +#define GL_LUMINANCE_FLOAT16_ATI 0x881E +#define GL_LUMINANCE_ALPHA_FLOAT16_ATI 0x881F +#endif + +#ifndef GL_NV_float_buffer +#define GL_FLOAT_R_NV 0x8880 +#define GL_FLOAT_RG_NV 0x8881 +#define GL_FLOAT_RGB_NV 0x8882 +#define GL_FLOAT_RGBA_NV 0x8883 +#define GL_FLOAT_R16_NV 0x8884 +#define GL_FLOAT_R32_NV 0x8885 +#define GL_FLOAT_RG16_NV 0x8886 +#define GL_FLOAT_RG32_NV 0x8887 +#define GL_FLOAT_RGB16_NV 0x8888 +#define GL_FLOAT_RGB32_NV 0x8889 +#define GL_FLOAT_RGBA16_NV 0x888A +#define GL_FLOAT_RGBA32_NV 0x888B +#define GL_TEXTURE_FLOAT_COMPONENTS_NV 0x888C +#define GL_FLOAT_CLEAR_COLOR_VALUE_NV 0x888D +#define GL_FLOAT_RGBA_MODE_NV 0x888E +#endif + +#ifndef GL_NV_fragment_program +#define GL_MAX_FRAGMENT_PROGRAM_LOCAL_PARAMETERS_NV 0x8868 +#define GL_FRAGMENT_PROGRAM_NV 0x8870 +#define GL_MAX_TEXTURE_COORDS_NV 0x8871 +#define GL_MAX_TEXTURE_IMAGE_UNITS_NV 0x8872 +#define GL_FRAGMENT_PROGRAM_BINDING_NV 0x8873 +#define GL_PROGRAM_ERROR_STRING_NV 0x8874 +#endif + +#ifndef GL_NV_half_float +#define GL_HALF_FLOAT_NV 0x140B +#endif + +#ifndef GL_NV_pixel_data_range +#define GL_WRITE_PIXEL_DATA_RANGE_NV 0x8878 +#define GL_READ_PIXEL_DATA_RANGE_NV 0x8879 +#define GL_WRITE_PIXEL_DATA_RANGE_LENGTH_NV 0x887A +#define GL_READ_PIXEL_DATA_RANGE_LENGTH_NV 0x887B +#define GL_WRITE_PIXEL_DATA_RANGE_POINTER_NV 0x887C +#define GL_READ_PIXEL_DATA_RANGE_POINTER_NV 0x887D +#endif + +#ifndef GL_NV_primitive_restart +#define GL_PRIMITIVE_RESTART_NV 0x8558 +#define GL_PRIMITIVE_RESTART_INDEX_NV 0x8559 +#endif + +#ifndef GL_NV_texture_expand_normal +#define GL_TEXTURE_UNSIGNED_REMAP_MODE_NV 0x888F +#endif + +#ifndef GL_NV_vertex_program2 +#endif + +#ifndef GL_ATI_map_object_buffer +#endif + +#ifndef GL_ATI_separate_stencil +#define GL_STENCIL_BACK_FUNC_ATI 0x8800 +#define GL_STENCIL_BACK_FAIL_ATI 0x8801 +#define GL_STENCIL_BACK_PASS_DEPTH_FAIL_ATI 0x8802 +#define GL_STENCIL_BACK_PASS_DEPTH_PASS_ATI 0x8803 +#endif + +#ifndef GL_ATI_vertex_attrib_array_object +#endif + +#ifndef GL_OES_read_format +#define GL_IMPLEMENTATION_COLOR_READ_TYPE_OES 0x8B9A +#define GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES 0x8B9B +#endif + +#ifndef GL_EXT_depth_bounds_test +#define GL_DEPTH_BOUNDS_TEST_EXT 0x8890 +#define GL_DEPTH_BOUNDS_EXT 0x8891 +#endif + +#ifndef GL_EXT_texture_mirror_clamp +#define GL_MIRROR_CLAMP_EXT 0x8742 +#define GL_MIRROR_CLAMP_TO_EDGE_EXT 0x8743 +#define GL_MIRROR_CLAMP_TO_BORDER_EXT 0x8912 +#endif + +#ifndef GL_EXT_blend_equation_separate +#define GL_BLEND_EQUATION_RGB_EXT 0x8009 +#define GL_BLEND_EQUATION_ALPHA_EXT 0x883D +#endif + +#ifndef GL_MESA_pack_invert +#define GL_PACK_INVERT_MESA 0x8758 +#endif + +#ifndef GL_MESA_ycbcr_texture +#define GL_UNSIGNED_SHORT_8_8_MESA 0x85BA +#define GL_UNSIGNED_SHORT_8_8_REV_MESA 0x85BB +#define GL_YCBCR_MESA 0x8757 +#endif + +#ifndef GL_EXT_pixel_buffer_object +#define GL_PIXEL_PACK_BUFFER_EXT 0x88EB +#define GL_PIXEL_UNPACK_BUFFER_EXT 0x88EC +#define GL_PIXEL_PACK_BUFFER_BINDING_EXT 0x88ED +#define GL_PIXEL_UNPACK_BUFFER_BINDING_EXT 0x88EF +#endif + +#ifndef GL_NV_fragment_program_option +#endif + +#ifndef GL_NV_fragment_program2 +#define GL_MAX_PROGRAM_EXEC_INSTRUCTIONS_NV 0x88F4 +#define GL_MAX_PROGRAM_CALL_DEPTH_NV 0x88F5 +#define GL_MAX_PROGRAM_IF_DEPTH_NV 0x88F6 +#define GL_MAX_PROGRAM_LOOP_DEPTH_NV 0x88F7 +#define GL_MAX_PROGRAM_LOOP_COUNT_NV 0x88F8 +#endif + +#ifndef GL_NV_vertex_program2_option +/* reuse GL_MAX_PROGRAM_EXEC_INSTRUCTIONS_NV */ +/* reuse GL_MAX_PROGRAM_CALL_DEPTH_NV */ +#endif + +#ifndef GL_NV_vertex_program3 +/* reuse GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB */ +#endif + +#ifndef GL_EXT_framebuffer_object +#define GL_INVALID_FRAMEBUFFER_OPERATION_EXT 0x0506 +#define GL_MAX_RENDERBUFFER_SIZE_EXT 0x84E8 +#define GL_FRAMEBUFFER_BINDING_EXT 0x8CA6 +#define GL_RENDERBUFFER_BINDING_EXT 0x8CA7 +#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_EXT 0x8CD0 +#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT 0x8CD1 +#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_EXT 0x8CD2 +#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE_EXT 0x8CD3 +#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_EXT 0x8CD4 +#define GL_FRAMEBUFFER_COMPLETE_EXT 0x8CD5 +#define GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT 0x8CD6 +#define GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT 0x8CD7 +#define GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT 0x8CD9 +#define GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT 0x8CDA +#define GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT 0x8CDB +#define GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT 0x8CDC +#define GL_FRAMEBUFFER_UNSUPPORTED_EXT 0x8CDD +#define GL_MAX_COLOR_ATTACHMENTS_EXT 0x8CDF +#define GL_COLOR_ATTACHMENT0_EXT 0x8CE0 +#define GL_COLOR_ATTACHMENT1_EXT 0x8CE1 +#define GL_COLOR_ATTACHMENT2_EXT 0x8CE2 +#define GL_COLOR_ATTACHMENT3_EXT 0x8CE3 +#define GL_COLOR_ATTACHMENT4_EXT 0x8CE4 +#define GL_COLOR_ATTACHMENT5_EXT 0x8CE5 +#define GL_COLOR_ATTACHMENT6_EXT 0x8CE6 +#define GL_COLOR_ATTACHMENT7_EXT 0x8CE7 +#define GL_COLOR_ATTACHMENT8_EXT 0x8CE8 +#define GL_COLOR_ATTACHMENT9_EXT 0x8CE9 +#define GL_COLOR_ATTACHMENT10_EXT 0x8CEA +#define GL_COLOR_ATTACHMENT11_EXT 0x8CEB +#define GL_COLOR_ATTACHMENT12_EXT 0x8CEC +#define GL_COLOR_ATTACHMENT13_EXT 0x8CED +#define GL_COLOR_ATTACHMENT14_EXT 0x8CEE +#define GL_COLOR_ATTACHMENT15_EXT 0x8CEF +#define GL_DEPTH_ATTACHMENT_EXT 0x8D00 +#define GL_STENCIL_ATTACHMENT_EXT 0x8D20 +#define GL_FRAMEBUFFER_EXT 0x8D40 +#define GL_RENDERBUFFER_EXT 0x8D41 +#define GL_RENDERBUFFER_WIDTH_EXT 0x8D42 +#define GL_RENDERBUFFER_HEIGHT_EXT 0x8D43 +#define GL_RENDERBUFFER_INTERNAL_FORMAT_EXT 0x8D44 +#define GL_STENCIL_INDEX1_EXT 0x8D46 +#define GL_STENCIL_INDEX4_EXT 0x8D47 +#define GL_STENCIL_INDEX8_EXT 0x8D48 +#define GL_STENCIL_INDEX16_EXT 0x8D49 +#define GL_RENDERBUFFER_RED_SIZE_EXT 0x8D50 +#define GL_RENDERBUFFER_GREEN_SIZE_EXT 0x8D51 +#define GL_RENDERBUFFER_BLUE_SIZE_EXT 0x8D52 +#define GL_RENDERBUFFER_ALPHA_SIZE_EXT 0x8D53 +#define GL_RENDERBUFFER_DEPTH_SIZE_EXT 0x8D54 +#define GL_RENDERBUFFER_STENCIL_SIZE_EXT 0x8D55 +#endif + +#ifndef GL_GREMEDY_string_marker +#endif + +#ifndef GL_EXT_packed_depth_stencil +#define GL_DEPTH_STENCIL_EXT 0x84F9 +#define GL_UNSIGNED_INT_24_8_EXT 0x84FA +#define GL_DEPTH24_STENCIL8_EXT 0x88F0 +#define GL_TEXTURE_STENCIL_SIZE_EXT 0x88F1 +#endif + +#ifndef GL_EXT_stencil_clear_tag +#define GL_STENCIL_TAG_BITS_EXT 0x88F2 +#define GL_STENCIL_CLEAR_TAG_VALUE_EXT 0x88F3 +#endif + +#ifndef GL_EXT_texture_sRGB +#define GL_SRGB_EXT 0x8C40 +#define GL_SRGB8_EXT 0x8C41 +#define GL_SRGB_ALPHA_EXT 0x8C42 +#define GL_SRGB8_ALPHA8_EXT 0x8C43 +#define GL_SLUMINANCE_ALPHA_EXT 0x8C44 +#define GL_SLUMINANCE8_ALPHA8_EXT 0x8C45 +#define GL_SLUMINANCE_EXT 0x8C46 +#define GL_SLUMINANCE8_EXT 0x8C47 +#define GL_COMPRESSED_SRGB_EXT 0x8C48 +#define GL_COMPRESSED_SRGB_ALPHA_EXT 0x8C49 +#define GL_COMPRESSED_SLUMINANCE_EXT 0x8C4A +#define GL_COMPRESSED_SLUMINANCE_ALPHA_EXT 0x8C4B +#define GL_COMPRESSED_SRGB_S3TC_DXT1_EXT 0x8C4C +#define GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT 0x8C4D +#define GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT 0x8C4E +#define GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT 0x8C4F +#endif + +#ifndef GL_EXT_framebuffer_blit +#define GL_READ_FRAMEBUFFER_EXT 0x8CA8 +#define GL_DRAW_FRAMEBUFFER_EXT 0x8CA9 +#define GL_DRAW_FRAMEBUFFER_BINDING_EXT GL_FRAMEBUFFER_BINDING_EXT +#define GL_READ_FRAMEBUFFER_BINDING_EXT 0x8CAA +#endif + +#ifndef GL_EXT_framebuffer_multisample +#define GL_RENDERBUFFER_SAMPLES_EXT 0x8CAB +#define GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_EXT 0x8D56 +#define GL_MAX_SAMPLES_EXT 0x8D57 +#endif + +#ifndef GL_MESAX_texture_stack +#define GL_TEXTURE_1D_STACK_MESAX 0x8759 +#define GL_TEXTURE_2D_STACK_MESAX 0x875A +#define GL_PROXY_TEXTURE_1D_STACK_MESAX 0x875B +#define GL_PROXY_TEXTURE_2D_STACK_MESAX 0x875C +#define GL_TEXTURE_1D_STACK_BINDING_MESAX 0x875D +#define GL_TEXTURE_2D_STACK_BINDING_MESAX 0x875E +#endif + +#ifndef GL_EXT_timer_query +#define GL_TIME_ELAPSED_EXT 0x88BF +#endif + +#ifndef GL_EXT_gpu_program_parameters +#endif + +#ifndef GL_APPLE_flush_buffer_range +#define GL_BUFFER_SERIALIZED_MODIFY_APPLE 0x8A12 +#define GL_BUFFER_FLUSHING_UNMAP_APPLE 0x8A13 +#endif + +#ifndef GL_NV_gpu_program4 +#define GL_MIN_PROGRAM_TEXEL_OFFSET_NV 0x8904 +#define GL_MAX_PROGRAM_TEXEL_OFFSET_NV 0x8905 +#define GL_PROGRAM_ATTRIB_COMPONENTS_NV 0x8906 +#define GL_PROGRAM_RESULT_COMPONENTS_NV 0x8907 +#define GL_MAX_PROGRAM_ATTRIB_COMPONENTS_NV 0x8908 +#define GL_MAX_PROGRAM_RESULT_COMPONENTS_NV 0x8909 +#define GL_MAX_PROGRAM_GENERIC_ATTRIBS_NV 0x8DA5 +#define GL_MAX_PROGRAM_GENERIC_RESULTS_NV 0x8DA6 +#endif + +#ifndef GL_NV_geometry_program4 +#define GL_LINES_ADJACENCY_EXT 0x000A +#define GL_LINE_STRIP_ADJACENCY_EXT 0x000B +#define GL_TRIANGLES_ADJACENCY_EXT 0x000C +#define GL_TRIANGLE_STRIP_ADJACENCY_EXT 0x000D +#define GL_GEOMETRY_PROGRAM_NV 0x8C26 +#define GL_MAX_PROGRAM_OUTPUT_VERTICES_NV 0x8C27 +#define GL_MAX_PROGRAM_TOTAL_OUTPUT_COMPONENTS_NV 0x8C28 +#define GL_GEOMETRY_VERTICES_OUT_EXT 0x8DDA +#define GL_GEOMETRY_INPUT_TYPE_EXT 0x8DDB +#define GL_GEOMETRY_OUTPUT_TYPE_EXT 0x8DDC +#define GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT 0x8C29 +#define GL_FRAMEBUFFER_ATTACHMENT_LAYERED_EXT 0x8DA7 +#define GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS_EXT 0x8DA8 +#define GL_FRAMEBUFFER_INCOMPLETE_LAYER_COUNT_EXT 0x8DA9 +#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER_EXT 0x8CD4 +#define GL_PROGRAM_POINT_SIZE_EXT 0x8642 +#endif + +#ifndef GL_EXT_geometry_shader4 +#define GL_GEOMETRY_SHADER_EXT 0x8DD9 +/* reuse GL_GEOMETRY_VERTICES_OUT_EXT */ +/* reuse GL_GEOMETRY_INPUT_TYPE_EXT */ +/* reuse GL_GEOMETRY_OUTPUT_TYPE_EXT */ +/* reuse GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT */ +#define GL_MAX_GEOMETRY_VARYING_COMPONENTS_EXT 0x8DDD +#define GL_MAX_VERTEX_VARYING_COMPONENTS_EXT 0x8DDE +#define GL_MAX_VARYING_COMPONENTS_EXT 0x8B4B +#define GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT 0x8DDF +#define GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT 0x8DE0 +#define GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT 0x8DE1 +/* reuse GL_LINES_ADJACENCY_EXT */ +/* reuse GL_LINE_STRIP_ADJACENCY_EXT */ +/* reuse GL_TRIANGLES_ADJACENCY_EXT */ +/* reuse GL_TRIANGLE_STRIP_ADJACENCY_EXT */ +/* reuse GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS_EXT */ +/* reuse GL_FRAMEBUFFER_INCOMPLETE_LAYER_COUNT_EXT */ +/* reuse GL_FRAMEBUFFER_ATTACHMENT_LAYERED_EXT */ +/* reuse GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER_EXT */ +/* reuse GL_PROGRAM_POINT_SIZE_EXT */ +#endif + +#ifndef GL_NV_vertex_program4 +#define GL_VERTEX_ATTRIB_ARRAY_INTEGER_NV 0x88FD +#endif + +#ifndef GL_EXT_gpu_shader4 +#define GL_SAMPLER_1D_ARRAY_EXT 0x8DC0 +#define GL_SAMPLER_2D_ARRAY_EXT 0x8DC1 +#define GL_SAMPLER_BUFFER_EXT 0x8DC2 +#define GL_SAMPLER_1D_ARRAY_SHADOW_EXT 0x8DC3 +#define GL_SAMPLER_2D_ARRAY_SHADOW_EXT 0x8DC4 +#define GL_SAMPLER_CUBE_SHADOW_EXT 0x8DC5 +#define GL_UNSIGNED_INT_VEC2_EXT 0x8DC6 +#define GL_UNSIGNED_INT_VEC3_EXT 0x8DC7 +#define GL_UNSIGNED_INT_VEC4_EXT 0x8DC8 +#define GL_INT_SAMPLER_1D_EXT 0x8DC9 +#define GL_INT_SAMPLER_2D_EXT 0x8DCA +#define GL_INT_SAMPLER_3D_EXT 0x8DCB +#define GL_INT_SAMPLER_CUBE_EXT 0x8DCC +#define GL_INT_SAMPLER_2D_RECT_EXT 0x8DCD +#define GL_INT_SAMPLER_1D_ARRAY_EXT 0x8DCE +#define GL_INT_SAMPLER_2D_ARRAY_EXT 0x8DCF +#define GL_INT_SAMPLER_BUFFER_EXT 0x8DD0 +#define GL_UNSIGNED_INT_SAMPLER_1D_EXT 0x8DD1 +#define GL_UNSIGNED_INT_SAMPLER_2D_EXT 0x8DD2 +#define GL_UNSIGNED_INT_SAMPLER_3D_EXT 0x8DD3 +#define GL_UNSIGNED_INT_SAMPLER_CUBE_EXT 0x8DD4 +#define GL_UNSIGNED_INT_SAMPLER_2D_RECT_EXT 0x8DD5 +#define GL_UNSIGNED_INT_SAMPLER_1D_ARRAY_EXT 0x8DD6 +#define GL_UNSIGNED_INT_SAMPLER_2D_ARRAY_EXT 0x8DD7 +#define GL_UNSIGNED_INT_SAMPLER_BUFFER_EXT 0x8DD8 +#endif + +#ifndef GL_EXT_draw_instanced +#endif + +#ifndef GL_EXT_packed_float +#define GL_R11F_G11F_B10F_EXT 0x8C3A +#define GL_UNSIGNED_INT_10F_11F_11F_REV_EXT 0x8C3B +#define GL_RGBA_SIGNED_COMPONENTS_EXT 0x8C3C +#endif + +#ifndef GL_EXT_texture_array +#define GL_TEXTURE_1D_ARRAY_EXT 0x8C18 +#define GL_PROXY_TEXTURE_1D_ARRAY_EXT 0x8C19 +#define GL_TEXTURE_2D_ARRAY_EXT 0x8C1A +#define GL_PROXY_TEXTURE_2D_ARRAY_EXT 0x8C1B +#define GL_TEXTURE_BINDING_1D_ARRAY_EXT 0x8C1C +#define GL_TEXTURE_BINDING_2D_ARRAY_EXT 0x8C1D +#define GL_MAX_ARRAY_TEXTURE_LAYERS_EXT 0x88FF +#define GL_COMPARE_REF_DEPTH_TO_TEXTURE_EXT 0x884E +/* reuse GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER_EXT */ +#endif + +#ifndef GL_EXT_texture_buffer_object +#define GL_TEXTURE_BUFFER_EXT 0x8C2A +#define GL_MAX_TEXTURE_BUFFER_SIZE_EXT 0x8C2B +#define GL_TEXTURE_BINDING_BUFFER_EXT 0x8C2C +#define GL_TEXTURE_BUFFER_DATA_STORE_BINDING_EXT 0x8C2D +#define GL_TEXTURE_BUFFER_FORMAT_EXT 0x8C2E +#endif + +#ifndef GL_EXT_texture_compression_latc +#define GL_COMPRESSED_LUMINANCE_LATC1_EXT 0x8C70 +#define GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT 0x8C71 +#define GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT 0x8C72 +#define GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT 0x8C73 +#endif + +#ifndef GL_EXT_texture_compression_rgtc +#define GL_COMPRESSED_RED_RGTC1_EXT 0x8DBB +#define GL_COMPRESSED_SIGNED_RED_RGTC1_EXT 0x8DBC +#define GL_COMPRESSED_RED_GREEN_RGTC2_EXT 0x8DBD +#define GL_COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT 0x8DBE +#endif + +#ifndef GL_EXT_texture_shared_exponent +#define GL_RGB9_E5_EXT 0x8C3D +#define GL_UNSIGNED_INT_5_9_9_9_REV_EXT 0x8C3E +#define GL_TEXTURE_SHARED_SIZE_EXT 0x8C3F +#endif + +#ifndef GL_NV_depth_buffer_float +#define GL_DEPTH_COMPONENT32F_NV 0x8DAB +#define GL_DEPTH32F_STENCIL8_NV 0x8DAC +#define GL_FLOAT_32_UNSIGNED_INT_24_8_REV_NV 0x8DAD +#define GL_DEPTH_BUFFER_FLOAT_MODE_NV 0x8DAF +#endif + +#ifndef GL_NV_fragment_program4 +#endif + +#ifndef GL_NV_framebuffer_multisample_coverage +#define GL_RENDERBUFFER_COVERAGE_SAMPLES_NV 0x8CAB +#define GL_RENDERBUFFER_COLOR_SAMPLES_NV 0x8E10 +#define GL_MAX_MULTISAMPLE_COVERAGE_MODES_NV 0x8E11 +#define GL_MULTISAMPLE_COVERAGE_MODES_NV 0x8E12 +#endif + +#ifndef GL_EXT_framebuffer_sRGB +#define GL_FRAMEBUFFER_SRGB_EXT 0x8DB9 +#define GL_FRAMEBUFFER_SRGB_CAPABLE_EXT 0x8DBA +#endif + +#ifndef GL_NV_geometry_shader4 +#endif + +#ifndef GL_NV_parameter_buffer_object +#define GL_MAX_PROGRAM_PARAMETER_BUFFER_BINDINGS_NV 0x8DA0 +#define GL_MAX_PROGRAM_PARAMETER_BUFFER_SIZE_NV 0x8DA1 +#define GL_VERTEX_PROGRAM_PARAMETER_BUFFER_NV 0x8DA2 +#define GL_GEOMETRY_PROGRAM_PARAMETER_BUFFER_NV 0x8DA3 +#define GL_FRAGMENT_PROGRAM_PARAMETER_BUFFER_NV 0x8DA4 +#endif + +#ifndef GL_EXT_draw_buffers2 +#endif + +#ifndef GL_NV_transform_feedback +#define GL_BACK_PRIMARY_COLOR_NV 0x8C77 +#define GL_BACK_SECONDARY_COLOR_NV 0x8C78 +#define GL_TEXTURE_COORD_NV 0x8C79 +#define GL_CLIP_DISTANCE_NV 0x8C7A +#define GL_VERTEX_ID_NV 0x8C7B +#define GL_PRIMITIVE_ID_NV 0x8C7C +#define GL_GENERIC_ATTRIB_NV 0x8C7D +#define GL_TRANSFORM_FEEDBACK_ATTRIBS_NV 0x8C7E +#define GL_TRANSFORM_FEEDBACK_BUFFER_MODE_NV 0x8C7F +#define GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS_NV 0x8C80 +#define GL_ACTIVE_VARYINGS_NV 0x8C81 +#define GL_ACTIVE_VARYING_MAX_LENGTH_NV 0x8C82 +#define GL_TRANSFORM_FEEDBACK_VARYINGS_NV 0x8C83 +#define GL_TRANSFORM_FEEDBACK_BUFFER_START_NV 0x8C84 +#define GL_TRANSFORM_FEEDBACK_BUFFER_SIZE_NV 0x8C85 +#define GL_TRANSFORM_FEEDBACK_RECORD_NV 0x8C86 +#define GL_PRIMITIVES_GENERATED_NV 0x8C87 +#define GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN_NV 0x8C88 +#define GL_RASTERIZER_DISCARD_NV 0x8C89 +#define GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_ATTRIBS_NV 0x8C8A +#define GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS_NV 0x8C8B +#define GL_INTERLEAVED_ATTRIBS_NV 0x8C8C +#define GL_SEPARATE_ATTRIBS_NV 0x8C8D +#define GL_TRANSFORM_FEEDBACK_BUFFER_NV 0x8C8E +#define GL_TRANSFORM_FEEDBACK_BUFFER_BINDING_NV 0x8C8F +#define GL_LAYER_NV 0x8DAA +#define GL_NEXT_BUFFER_NV -2 +#define GL_SKIP_COMPONENTS4_NV -3 +#define GL_SKIP_COMPONENTS3_NV -4 +#define GL_SKIP_COMPONENTS2_NV -5 +#define GL_SKIP_COMPONENTS1_NV -6 +#endif + +#ifndef GL_EXT_bindable_uniform +#define GL_MAX_VERTEX_BINDABLE_UNIFORMS_EXT 0x8DE2 +#define GL_MAX_FRAGMENT_BINDABLE_UNIFORMS_EXT 0x8DE3 +#define GL_MAX_GEOMETRY_BINDABLE_UNIFORMS_EXT 0x8DE4 +#define GL_MAX_BINDABLE_UNIFORM_SIZE_EXT 0x8DED +#define GL_UNIFORM_BUFFER_EXT 0x8DEE +#define GL_UNIFORM_BUFFER_BINDING_EXT 0x8DEF +#endif + +#ifndef GL_EXT_texture_integer +#define GL_RGBA32UI_EXT 0x8D70 +#define GL_RGB32UI_EXT 0x8D71 +#define GL_ALPHA32UI_EXT 0x8D72 +#define GL_INTENSITY32UI_EXT 0x8D73 +#define GL_LUMINANCE32UI_EXT 0x8D74 +#define GL_LUMINANCE_ALPHA32UI_EXT 0x8D75 +#define GL_RGBA16UI_EXT 0x8D76 +#define GL_RGB16UI_EXT 0x8D77 +#define GL_ALPHA16UI_EXT 0x8D78 +#define GL_INTENSITY16UI_EXT 0x8D79 +#define GL_LUMINANCE16UI_EXT 0x8D7A +#define GL_LUMINANCE_ALPHA16UI_EXT 0x8D7B +#define GL_RGBA8UI_EXT 0x8D7C +#define GL_RGB8UI_EXT 0x8D7D +#define GL_ALPHA8UI_EXT 0x8D7E +#define GL_INTENSITY8UI_EXT 0x8D7F +#define GL_LUMINANCE8UI_EXT 0x8D80 +#define GL_LUMINANCE_ALPHA8UI_EXT 0x8D81 +#define GL_RGBA32I_EXT 0x8D82 +#define GL_RGB32I_EXT 0x8D83 +#define GL_ALPHA32I_EXT 0x8D84 +#define GL_INTENSITY32I_EXT 0x8D85 +#define GL_LUMINANCE32I_EXT 0x8D86 +#define GL_LUMINANCE_ALPHA32I_EXT 0x8D87 +#define GL_RGBA16I_EXT 0x8D88 +#define GL_RGB16I_EXT 0x8D89 +#define GL_ALPHA16I_EXT 0x8D8A +#define GL_INTENSITY16I_EXT 0x8D8B +#define GL_LUMINANCE16I_EXT 0x8D8C +#define GL_LUMINANCE_ALPHA16I_EXT 0x8D8D +#define GL_RGBA8I_EXT 0x8D8E +#define GL_RGB8I_EXT 0x8D8F +#define GL_ALPHA8I_EXT 0x8D90 +#define GL_INTENSITY8I_EXT 0x8D91 +#define GL_LUMINANCE8I_EXT 0x8D92 +#define GL_LUMINANCE_ALPHA8I_EXT 0x8D93 +#define GL_RED_INTEGER_EXT 0x8D94 +#define GL_GREEN_INTEGER_EXT 0x8D95 +#define GL_BLUE_INTEGER_EXT 0x8D96 +#define GL_ALPHA_INTEGER_EXT 0x8D97 +#define GL_RGB_INTEGER_EXT 0x8D98 +#define GL_RGBA_INTEGER_EXT 0x8D99 +#define GL_BGR_INTEGER_EXT 0x8D9A +#define GL_BGRA_INTEGER_EXT 0x8D9B +#define GL_LUMINANCE_INTEGER_EXT 0x8D9C +#define GL_LUMINANCE_ALPHA_INTEGER_EXT 0x8D9D +#define GL_RGBA_INTEGER_MODE_EXT 0x8D9E +#endif + +#ifndef GL_GREMEDY_frame_terminator +#endif + +#ifndef GL_NV_conditional_render +#define GL_QUERY_WAIT_NV 0x8E13 +#define GL_QUERY_NO_WAIT_NV 0x8E14 +#define GL_QUERY_BY_REGION_WAIT_NV 0x8E15 +#define GL_QUERY_BY_REGION_NO_WAIT_NV 0x8E16 +#endif + +#ifndef GL_NV_present_video +#define GL_FRAME_NV 0x8E26 +#define GL_FIELDS_NV 0x8E27 +#define GL_CURRENT_TIME_NV 0x8E28 +#define GL_NUM_FILL_STREAMS_NV 0x8E29 +#define GL_PRESENT_TIME_NV 0x8E2A +#define GL_PRESENT_DURATION_NV 0x8E2B +#endif + +#ifndef GL_EXT_transform_feedback +#define GL_TRANSFORM_FEEDBACK_BUFFER_EXT 0x8C8E +#define GL_TRANSFORM_FEEDBACK_BUFFER_START_EXT 0x8C84 +#define GL_TRANSFORM_FEEDBACK_BUFFER_SIZE_EXT 0x8C85 +#define GL_TRANSFORM_FEEDBACK_BUFFER_BINDING_EXT 0x8C8F +#define GL_INTERLEAVED_ATTRIBS_EXT 0x8C8C +#define GL_SEPARATE_ATTRIBS_EXT 0x8C8D +#define GL_PRIMITIVES_GENERATED_EXT 0x8C87 +#define GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN_EXT 0x8C88 +#define GL_RASTERIZER_DISCARD_EXT 0x8C89 +#define GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS_EXT 0x8C8A +#define GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS_EXT 0x8C8B +#define GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS_EXT 0x8C80 +#define GL_TRANSFORM_FEEDBACK_VARYINGS_EXT 0x8C83 +#define GL_TRANSFORM_FEEDBACK_BUFFER_MODE_EXT 0x8C7F +#define GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH_EXT 0x8C76 +#endif + +#ifndef GL_EXT_direct_state_access +#define GL_PROGRAM_MATRIX_EXT 0x8E2D +#define GL_TRANSPOSE_PROGRAM_MATRIX_EXT 0x8E2E +#define GL_PROGRAM_MATRIX_STACK_DEPTH_EXT 0x8E2F +#endif + +#ifndef GL_EXT_vertex_array_bgra +/* reuse GL_BGRA */ +#endif + +#ifndef GL_EXT_texture_swizzle +#define GL_TEXTURE_SWIZZLE_R_EXT 0x8E42 +#define GL_TEXTURE_SWIZZLE_G_EXT 0x8E43 +#define GL_TEXTURE_SWIZZLE_B_EXT 0x8E44 +#define GL_TEXTURE_SWIZZLE_A_EXT 0x8E45 +#define GL_TEXTURE_SWIZZLE_RGBA_EXT 0x8E46 +#endif + +#ifndef GL_NV_explicit_multisample +#define GL_SAMPLE_POSITION_NV 0x8E50 +#define GL_SAMPLE_MASK_NV 0x8E51 +#define GL_SAMPLE_MASK_VALUE_NV 0x8E52 +#define GL_TEXTURE_BINDING_RENDERBUFFER_NV 0x8E53 +#define GL_TEXTURE_RENDERBUFFER_DATA_STORE_BINDING_NV 0x8E54 +#define GL_TEXTURE_RENDERBUFFER_NV 0x8E55 +#define GL_SAMPLER_RENDERBUFFER_NV 0x8E56 +#define GL_INT_SAMPLER_RENDERBUFFER_NV 0x8E57 +#define GL_UNSIGNED_INT_SAMPLER_RENDERBUFFER_NV 0x8E58 +#define GL_MAX_SAMPLE_MASK_WORDS_NV 0x8E59 +#endif + +#ifndef GL_NV_transform_feedback2 +#define GL_TRANSFORM_FEEDBACK_NV 0x8E22 +#define GL_TRANSFORM_FEEDBACK_BUFFER_PAUSED_NV 0x8E23 +#define GL_TRANSFORM_FEEDBACK_BUFFER_ACTIVE_NV 0x8E24 +#define GL_TRANSFORM_FEEDBACK_BINDING_NV 0x8E25 +#endif + +#ifndef GL_ATI_meminfo +#define GL_VBO_FREE_MEMORY_ATI 0x87FB +#define GL_TEXTURE_FREE_MEMORY_ATI 0x87FC +#define GL_RENDERBUFFER_FREE_MEMORY_ATI 0x87FD +#endif + +#ifndef GL_AMD_performance_monitor +#define GL_COUNTER_TYPE_AMD 0x8BC0 +#define GL_COUNTER_RANGE_AMD 0x8BC1 +#define GL_UNSIGNED_INT64_AMD 0x8BC2 +#define GL_PERCENTAGE_AMD 0x8BC3 +#define GL_PERFMON_RESULT_AVAILABLE_AMD 0x8BC4 +#define GL_PERFMON_RESULT_SIZE_AMD 0x8BC5 +#define GL_PERFMON_RESULT_AMD 0x8BC6 +#endif + +#ifndef GL_AMD_texture_texture4 +#endif + +#ifndef GL_AMD_vertex_shader_tesselator +#define GL_SAMPLER_BUFFER_AMD 0x9001 +#define GL_INT_SAMPLER_BUFFER_AMD 0x9002 +#define GL_UNSIGNED_INT_SAMPLER_BUFFER_AMD 0x9003 +#define GL_TESSELLATION_MODE_AMD 0x9004 +#define GL_TESSELLATION_FACTOR_AMD 0x9005 +#define GL_DISCRETE_AMD 0x9006 +#define GL_CONTINUOUS_AMD 0x9007 +#endif + +#ifndef GL_EXT_provoking_vertex +#define GL_QUADS_FOLLOW_PROVOKING_VERTEX_CONVENTION_EXT 0x8E4C +#define GL_FIRST_VERTEX_CONVENTION_EXT 0x8E4D +#define GL_LAST_VERTEX_CONVENTION_EXT 0x8E4E +#define GL_PROVOKING_VERTEX_EXT 0x8E4F +#endif + +#ifndef GL_EXT_texture_snorm +#define GL_ALPHA_SNORM 0x9010 +#define GL_LUMINANCE_SNORM 0x9011 +#define GL_LUMINANCE_ALPHA_SNORM 0x9012 +#define GL_INTENSITY_SNORM 0x9013 +#define GL_ALPHA8_SNORM 0x9014 +#define GL_LUMINANCE8_SNORM 0x9015 +#define GL_LUMINANCE8_ALPHA8_SNORM 0x9016 +#define GL_INTENSITY8_SNORM 0x9017 +#define GL_ALPHA16_SNORM 0x9018 +#define GL_LUMINANCE16_SNORM 0x9019 +#define GL_LUMINANCE16_ALPHA16_SNORM 0x901A +#define GL_INTENSITY16_SNORM 0x901B +/* reuse GL_RED_SNORM */ +/* reuse GL_RG_SNORM */ +/* reuse GL_RGB_SNORM */ +/* reuse GL_RGBA_SNORM */ +/* reuse GL_R8_SNORM */ +/* reuse GL_RG8_SNORM */ +/* reuse GL_RGB8_SNORM */ +/* reuse GL_RGBA8_SNORM */ +/* reuse GL_R16_SNORM */ +/* reuse GL_RG16_SNORM */ +/* reuse GL_RGB16_SNORM */ +/* reuse GL_RGBA16_SNORM */ +/* reuse GL_SIGNED_NORMALIZED */ +#endif + +#ifndef GL_AMD_draw_buffers_blend +#endif + +#ifndef GL_APPLE_texture_range +#define GL_TEXTURE_RANGE_LENGTH_APPLE 0x85B7 +#define GL_TEXTURE_RANGE_POINTER_APPLE 0x85B8 +#define GL_TEXTURE_STORAGE_HINT_APPLE 0x85BC +#define GL_STORAGE_PRIVATE_APPLE 0x85BD +/* reuse GL_STORAGE_CACHED_APPLE */ +/* reuse GL_STORAGE_SHARED_APPLE */ +#endif + +#ifndef GL_APPLE_float_pixels +#define GL_HALF_APPLE 0x140B +#define GL_RGBA_FLOAT32_APPLE 0x8814 +#define GL_RGB_FLOAT32_APPLE 0x8815 +#define GL_ALPHA_FLOAT32_APPLE 0x8816 +#define GL_INTENSITY_FLOAT32_APPLE 0x8817 +#define GL_LUMINANCE_FLOAT32_APPLE 0x8818 +#define GL_LUMINANCE_ALPHA_FLOAT32_APPLE 0x8819 +#define GL_RGBA_FLOAT16_APPLE 0x881A +#define GL_RGB_FLOAT16_APPLE 0x881B +#define GL_ALPHA_FLOAT16_APPLE 0x881C +#define GL_INTENSITY_FLOAT16_APPLE 0x881D +#define GL_LUMINANCE_FLOAT16_APPLE 0x881E +#define GL_LUMINANCE_ALPHA_FLOAT16_APPLE 0x881F +#define GL_COLOR_FLOAT_APPLE 0x8A0F +#endif + +#ifndef GL_APPLE_vertex_program_evaluators +#define GL_VERTEX_ATTRIB_MAP1_APPLE 0x8A00 +#define GL_VERTEX_ATTRIB_MAP2_APPLE 0x8A01 +#define GL_VERTEX_ATTRIB_MAP1_SIZE_APPLE 0x8A02 +#define GL_VERTEX_ATTRIB_MAP1_COEFF_APPLE 0x8A03 +#define GL_VERTEX_ATTRIB_MAP1_ORDER_APPLE 0x8A04 +#define GL_VERTEX_ATTRIB_MAP1_DOMAIN_APPLE 0x8A05 +#define GL_VERTEX_ATTRIB_MAP2_SIZE_APPLE 0x8A06 +#define GL_VERTEX_ATTRIB_MAP2_COEFF_APPLE 0x8A07 +#define GL_VERTEX_ATTRIB_MAP2_ORDER_APPLE 0x8A08 +#define GL_VERTEX_ATTRIB_MAP2_DOMAIN_APPLE 0x8A09 +#endif + +#ifndef GL_APPLE_aux_depth_stencil +#define GL_AUX_DEPTH_STENCIL_APPLE 0x8A14 +#endif + +#ifndef GL_APPLE_object_purgeable +#define GL_BUFFER_OBJECT_APPLE 0x85B3 +#define GL_RELEASED_APPLE 0x8A19 +#define GL_VOLATILE_APPLE 0x8A1A +#define GL_RETAINED_APPLE 0x8A1B +#define GL_UNDEFINED_APPLE 0x8A1C +#define GL_PURGEABLE_APPLE 0x8A1D +#endif + +#ifndef GL_APPLE_row_bytes +#define GL_PACK_ROW_BYTES_APPLE 0x8A15 +#define GL_UNPACK_ROW_BYTES_APPLE 0x8A16 +#endif + +#ifndef GL_APPLE_rgb_422 +#define GL_RGB_422_APPLE 0x8A1F +/* reuse GL_UNSIGNED_SHORT_8_8_APPLE */ +/* reuse GL_UNSIGNED_SHORT_8_8_REV_APPLE */ +#endif + +#ifndef GL_NV_video_capture +#define GL_VIDEO_BUFFER_NV 0x9020 +#define GL_VIDEO_BUFFER_BINDING_NV 0x9021 +#define GL_FIELD_UPPER_NV 0x9022 +#define GL_FIELD_LOWER_NV 0x9023 +#define GL_NUM_VIDEO_CAPTURE_STREAMS_NV 0x9024 +#define GL_NEXT_VIDEO_CAPTURE_BUFFER_STATUS_NV 0x9025 +#define GL_VIDEO_CAPTURE_TO_422_SUPPORTED_NV 0x9026 +#define GL_LAST_VIDEO_CAPTURE_STATUS_NV 0x9027 +#define GL_VIDEO_BUFFER_PITCH_NV 0x9028 +#define GL_VIDEO_COLOR_CONVERSION_MATRIX_NV 0x9029 +#define GL_VIDEO_COLOR_CONVERSION_MAX_NV 0x902A +#define GL_VIDEO_COLOR_CONVERSION_MIN_NV 0x902B +#define GL_VIDEO_COLOR_CONVERSION_OFFSET_NV 0x902C +#define GL_VIDEO_BUFFER_INTERNAL_FORMAT_NV 0x902D +#define GL_PARTIAL_SUCCESS_NV 0x902E +#define GL_SUCCESS_NV 0x902F +#define GL_FAILURE_NV 0x9030 +#define GL_YCBYCR8_422_NV 0x9031 +#define GL_YCBAYCR8A_4224_NV 0x9032 +#define GL_Z6Y10Z6CB10Z6Y10Z6CR10_422_NV 0x9033 +#define GL_Z6Y10Z6CB10Z6A10Z6Y10Z6CR10Z6A10_4224_NV 0x9034 +#define GL_Z4Y12Z4CB12Z4Y12Z4CR12_422_NV 0x9035 +#define GL_Z4Y12Z4CB12Z4A12Z4Y12Z4CR12Z4A12_4224_NV 0x9036 +#define GL_Z4Y12Z4CB12Z4CR12_444_NV 0x9037 +#define GL_VIDEO_CAPTURE_FRAME_WIDTH_NV 0x9038 +#define GL_VIDEO_CAPTURE_FRAME_HEIGHT_NV 0x9039 +#define GL_VIDEO_CAPTURE_FIELD_UPPER_HEIGHT_NV 0x903A +#define GL_VIDEO_CAPTURE_FIELD_LOWER_HEIGHT_NV 0x903B +#define GL_VIDEO_CAPTURE_SURFACE_ORIGIN_NV 0x903C +#endif + +#ifndef GL_NV_copy_image +#endif + +#ifndef GL_EXT_separate_shader_objects +#define GL_ACTIVE_PROGRAM_EXT 0x8B8D +#endif + +#ifndef GL_NV_parameter_buffer_object2 +#endif + +#ifndef GL_NV_shader_buffer_load +#define GL_BUFFER_GPU_ADDRESS_NV 0x8F1D +#define GL_GPU_ADDRESS_NV 0x8F34 +#define GL_MAX_SHADER_BUFFER_ADDRESS_NV 0x8F35 +#endif + +#ifndef GL_NV_vertex_buffer_unified_memory +#define GL_VERTEX_ATTRIB_ARRAY_UNIFIED_NV 0x8F1E +#define GL_ELEMENT_ARRAY_UNIFIED_NV 0x8F1F +#define GL_VERTEX_ATTRIB_ARRAY_ADDRESS_NV 0x8F20 +#define GL_VERTEX_ARRAY_ADDRESS_NV 0x8F21 +#define GL_NORMAL_ARRAY_ADDRESS_NV 0x8F22 +#define GL_COLOR_ARRAY_ADDRESS_NV 0x8F23 +#define GL_INDEX_ARRAY_ADDRESS_NV 0x8F24 +#define GL_TEXTURE_COORD_ARRAY_ADDRESS_NV 0x8F25 +#define GL_EDGE_FLAG_ARRAY_ADDRESS_NV 0x8F26 +#define GL_SECONDARY_COLOR_ARRAY_ADDRESS_NV 0x8F27 +#define GL_FOG_COORD_ARRAY_ADDRESS_NV 0x8F28 +#define GL_ELEMENT_ARRAY_ADDRESS_NV 0x8F29 +#define GL_VERTEX_ATTRIB_ARRAY_LENGTH_NV 0x8F2A +#define GL_VERTEX_ARRAY_LENGTH_NV 0x8F2B +#define GL_NORMAL_ARRAY_LENGTH_NV 0x8F2C +#define GL_COLOR_ARRAY_LENGTH_NV 0x8F2D +#define GL_INDEX_ARRAY_LENGTH_NV 0x8F2E +#define GL_TEXTURE_COORD_ARRAY_LENGTH_NV 0x8F2F +#define GL_EDGE_FLAG_ARRAY_LENGTH_NV 0x8F30 +#define GL_SECONDARY_COLOR_ARRAY_LENGTH_NV 0x8F31 +#define GL_FOG_COORD_ARRAY_LENGTH_NV 0x8F32 +#define GL_ELEMENT_ARRAY_LENGTH_NV 0x8F33 +#define GL_DRAW_INDIRECT_UNIFIED_NV 0x8F40 +#define GL_DRAW_INDIRECT_ADDRESS_NV 0x8F41 +#define GL_DRAW_INDIRECT_LENGTH_NV 0x8F42 +#endif + +#ifndef GL_NV_texture_barrier +#endif + +#ifndef GL_AMD_shader_stencil_export +#endif + +#ifndef GL_AMD_seamless_cubemap_per_texture +/* reuse GL_TEXTURE_CUBE_MAP_SEAMLESS_ARB */ +#endif + +#ifndef GL_AMD_conservative_depth +#endif + +#ifndef GL_EXT_shader_image_load_store +#define GL_MAX_IMAGE_UNITS_EXT 0x8F38 +#define GL_MAX_COMBINED_IMAGE_UNITS_AND_FRAGMENT_OUTPUTS_EXT 0x8F39 +#define GL_IMAGE_BINDING_NAME_EXT 0x8F3A +#define GL_IMAGE_BINDING_LEVEL_EXT 0x8F3B +#define GL_IMAGE_BINDING_LAYERED_EXT 0x8F3C +#define GL_IMAGE_BINDING_LAYER_EXT 0x8F3D +#define GL_IMAGE_BINDING_ACCESS_EXT 0x8F3E +#define GL_IMAGE_1D_EXT 0x904C +#define GL_IMAGE_2D_EXT 0x904D +#define GL_IMAGE_3D_EXT 0x904E +#define GL_IMAGE_2D_RECT_EXT 0x904F +#define GL_IMAGE_CUBE_EXT 0x9050 +#define GL_IMAGE_BUFFER_EXT 0x9051 +#define GL_IMAGE_1D_ARRAY_EXT 0x9052 +#define GL_IMAGE_2D_ARRAY_EXT 0x9053 +#define GL_IMAGE_CUBE_MAP_ARRAY_EXT 0x9054 +#define GL_IMAGE_2D_MULTISAMPLE_EXT 0x9055 +#define GL_IMAGE_2D_MULTISAMPLE_ARRAY_EXT 0x9056 +#define GL_INT_IMAGE_1D_EXT 0x9057 +#define GL_INT_IMAGE_2D_EXT 0x9058 +#define GL_INT_IMAGE_3D_EXT 0x9059 +#define GL_INT_IMAGE_2D_RECT_EXT 0x905A +#define GL_INT_IMAGE_CUBE_EXT 0x905B +#define GL_INT_IMAGE_BUFFER_EXT 0x905C +#define GL_INT_IMAGE_1D_ARRAY_EXT 0x905D +#define GL_INT_IMAGE_2D_ARRAY_EXT 0x905E +#define GL_INT_IMAGE_CUBE_MAP_ARRAY_EXT 0x905F +#define GL_INT_IMAGE_2D_MULTISAMPLE_EXT 0x9060 +#define GL_INT_IMAGE_2D_MULTISAMPLE_ARRAY_EXT 0x9061 +#define GL_UNSIGNED_INT_IMAGE_1D_EXT 0x9062 +#define GL_UNSIGNED_INT_IMAGE_2D_EXT 0x9063 +#define GL_UNSIGNED_INT_IMAGE_3D_EXT 0x9064 +#define GL_UNSIGNED_INT_IMAGE_2D_RECT_EXT 0x9065 +#define GL_UNSIGNED_INT_IMAGE_CUBE_EXT 0x9066 +#define GL_UNSIGNED_INT_IMAGE_BUFFER_EXT 0x9067 +#define GL_UNSIGNED_INT_IMAGE_1D_ARRAY_EXT 0x9068 +#define GL_UNSIGNED_INT_IMAGE_2D_ARRAY_EXT 0x9069 +#define GL_UNSIGNED_INT_IMAGE_CUBE_MAP_ARRAY_EXT 0x906A +#define GL_UNSIGNED_INT_IMAGE_2D_MULTISAMPLE_EXT 0x906B +#define GL_UNSIGNED_INT_IMAGE_2D_MULTISAMPLE_ARRAY_EXT 0x906C +#define GL_MAX_IMAGE_SAMPLES_EXT 0x906D +#define GL_IMAGE_BINDING_FORMAT_EXT 0x906E +#define GL_VERTEX_ATTRIB_ARRAY_BARRIER_BIT_EXT 0x00000001 +#define GL_ELEMENT_ARRAY_BARRIER_BIT_EXT 0x00000002 +#define GL_UNIFORM_BARRIER_BIT_EXT 0x00000004 +#define GL_TEXTURE_FETCH_BARRIER_BIT_EXT 0x00000008 +#define GL_SHADER_IMAGE_ACCESS_BARRIER_BIT_EXT 0x00000020 +#define GL_COMMAND_BARRIER_BIT_EXT 0x00000040 +#define GL_PIXEL_BUFFER_BARRIER_BIT_EXT 0x00000080 +#define GL_TEXTURE_UPDATE_BARRIER_BIT_EXT 0x00000100 +#define GL_BUFFER_UPDATE_BARRIER_BIT_EXT 0x00000200 +#define GL_FRAMEBUFFER_BARRIER_BIT_EXT 0x00000400 +#define GL_TRANSFORM_FEEDBACK_BARRIER_BIT_EXT 0x00000800 +#define GL_ATOMIC_COUNTER_BARRIER_BIT_EXT 0x00001000 +#define GL_ALL_BARRIER_BITS_EXT 0xFFFFFFFF +#endif + +#ifndef GL_EXT_vertex_attrib_64bit +/* reuse GL_DOUBLE */ +#define GL_DOUBLE_VEC2_EXT 0x8FFC +#define GL_DOUBLE_VEC3_EXT 0x8FFD +#define GL_DOUBLE_VEC4_EXT 0x8FFE +#define GL_DOUBLE_MAT2_EXT 0x8F46 +#define GL_DOUBLE_MAT3_EXT 0x8F47 +#define GL_DOUBLE_MAT4_EXT 0x8F48 +#define GL_DOUBLE_MAT2x3_EXT 0x8F49 +#define GL_DOUBLE_MAT2x4_EXT 0x8F4A +#define GL_DOUBLE_MAT3x2_EXT 0x8F4B +#define GL_DOUBLE_MAT3x4_EXT 0x8F4C +#define GL_DOUBLE_MAT4x2_EXT 0x8F4D +#define GL_DOUBLE_MAT4x3_EXT 0x8F4E +#endif + +#ifndef GL_NV_gpu_program5 +#define GL_MAX_GEOMETRY_PROGRAM_INVOCATIONS_NV 0x8E5A +#define GL_MIN_FRAGMENT_INTERPOLATION_OFFSET_NV 0x8E5B +#define GL_MAX_FRAGMENT_INTERPOLATION_OFFSET_NV 0x8E5C +#define GL_FRAGMENT_PROGRAM_INTERPOLATION_OFFSET_BITS_NV 0x8E5D +#define GL_MAX_PROGRAM_SUBROUTINE_PARAMETERS_NV 0x8F44 +#define GL_MAX_PROGRAM_SUBROUTINE_NUM_NV 0x8F45 +#endif + +#ifndef GL_NV_gpu_shader5 +#define GL_INT64_NV 0x140E +#define GL_UNSIGNED_INT64_NV 0x140F +#define GL_INT8_NV 0x8FE0 +#define GL_INT8_VEC2_NV 0x8FE1 +#define GL_INT8_VEC3_NV 0x8FE2 +#define GL_INT8_VEC4_NV 0x8FE3 +#define GL_INT16_NV 0x8FE4 +#define GL_INT16_VEC2_NV 0x8FE5 +#define GL_INT16_VEC3_NV 0x8FE6 +#define GL_INT16_VEC4_NV 0x8FE7 +#define GL_INT64_VEC2_NV 0x8FE9 +#define GL_INT64_VEC3_NV 0x8FEA +#define GL_INT64_VEC4_NV 0x8FEB +#define GL_UNSIGNED_INT8_NV 0x8FEC +#define GL_UNSIGNED_INT8_VEC2_NV 0x8FED +#define GL_UNSIGNED_INT8_VEC3_NV 0x8FEE +#define GL_UNSIGNED_INT8_VEC4_NV 0x8FEF +#define GL_UNSIGNED_INT16_NV 0x8FF0 +#define GL_UNSIGNED_INT16_VEC2_NV 0x8FF1 +#define GL_UNSIGNED_INT16_VEC3_NV 0x8FF2 +#define GL_UNSIGNED_INT16_VEC4_NV 0x8FF3 +#define GL_UNSIGNED_INT64_VEC2_NV 0x8FF5 +#define GL_UNSIGNED_INT64_VEC3_NV 0x8FF6 +#define GL_UNSIGNED_INT64_VEC4_NV 0x8FF7 +#define GL_FLOAT16_NV 0x8FF8 +#define GL_FLOAT16_VEC2_NV 0x8FF9 +#define GL_FLOAT16_VEC3_NV 0x8FFA +#define GL_FLOAT16_VEC4_NV 0x8FFB +/* reuse GL_PATCHES */ +#endif + +#ifndef GL_NV_shader_buffer_store +#define GL_SHADER_GLOBAL_ACCESS_BARRIER_BIT_NV 0x00000010 +/* reuse GL_READ_WRITE */ +/* reuse GL_WRITE_ONLY */ +#endif + +#ifndef GL_NV_tessellation_program5 +#define GL_MAX_PROGRAM_PATCH_ATTRIBS_NV 0x86D8 +#define GL_TESS_CONTROL_PROGRAM_NV 0x891E +#define GL_TESS_EVALUATION_PROGRAM_NV 0x891F +#define GL_TESS_CONTROL_PROGRAM_PARAMETER_BUFFER_NV 0x8C74 +#define GL_TESS_EVALUATION_PROGRAM_PARAMETER_BUFFER_NV 0x8C75 +#endif + +#ifndef GL_NV_vertex_attrib_integer_64bit +/* reuse GL_INT64_NV */ +/* reuse GL_UNSIGNED_INT64_NV */ +#endif + +#ifndef GL_NV_multisample_coverage +#define GL_COVERAGE_SAMPLES_NV 0x80A9 +#define GL_COLOR_SAMPLES_NV 0x8E20 +#endif + +#ifndef GL_AMD_name_gen_delete +#define GL_DATA_BUFFER_AMD 0x9151 +#define GL_PERFORMANCE_MONITOR_AMD 0x9152 +#define GL_QUERY_OBJECT_AMD 0x9153 +#define GL_VERTEX_ARRAY_OBJECT_AMD 0x9154 +#define GL_SAMPLER_OBJECT_AMD 0x9155 +#endif + +#ifndef GL_AMD_debug_output +#define GL_MAX_DEBUG_LOGGED_MESSAGES_AMD 0x9144 +#define GL_DEBUG_LOGGED_MESSAGES_AMD 0x9145 +#define GL_DEBUG_SEVERITY_HIGH_AMD 0x9146 +#define GL_DEBUG_SEVERITY_MEDIUM_AMD 0x9147 +#define GL_DEBUG_SEVERITY_LOW_AMD 0x9148 +#define GL_DEBUG_CATEGORY_API_ERROR_AMD 0x9149 +#define GL_DEBUG_CATEGORY_WINDOW_SYSTEM_AMD 0x914A +#define GL_DEBUG_CATEGORY_DEPRECATION_AMD 0x914B +#define GL_DEBUG_CATEGORY_UNDEFINED_BEHAVIOR_AMD 0x914C +#define GL_DEBUG_CATEGORY_PERFORMANCE_AMD 0x914D +#define GL_DEBUG_CATEGORY_SHADER_COMPILER_AMD 0x914E +#define GL_DEBUG_CATEGORY_APPLICATION_AMD 0x914F +#define GL_DEBUG_CATEGORY_OTHER_AMD 0x9150 +#endif + +#ifndef GL_NV_vdpau_interop +#define GL_SURFACE_STATE_NV 0x86EB +#define GL_SURFACE_REGISTERED_NV 0x86FD +#define GL_SURFACE_MAPPED_NV 0x8700 +#define GL_WRITE_DISCARD_NV 0x88BE +#endif + +#ifndef GL_AMD_transform_feedback3_lines_triangles +#endif + + +/*************************************************************/ + +#include +#ifndef GL_VERSION_2_0 +/* GL type for program/shader text */ +typedef char GLchar; +#endif + +#ifndef GL_VERSION_1_5 +/* GL types for handling large vertex buffer objects */ +typedef ptrdiff_t GLintptr; +typedef ptrdiff_t GLsizeiptr; +#endif + +#ifndef GL_ARB_vertex_buffer_object +/* GL types for handling large vertex buffer objects */ +typedef ptrdiff_t GLintptrARB; +typedef ptrdiff_t GLsizeiptrARB; +#endif + +#ifndef GL_ARB_shader_objects +/* GL types for program/shader text and shader object handles */ +typedef char GLcharARB; +typedef unsigned int GLhandleARB; +#endif + +/* GL type for "half" precision (s10e5) float data in host memory */ +#ifndef GL_ARB_half_float_pixel +typedef unsigned short GLhalfARB; +#endif + +#ifndef GL_NV_half_float +typedef unsigned short GLhalfNV; +#endif + +#ifndef GLEXT_64_TYPES_DEFINED +/* This code block is duplicated in glxext.h, so must be protected */ +#define GLEXT_64_TYPES_DEFINED +/* Define int32_t, int64_t, and uint64_t types for UST/MSC */ +/* (as used in the GL_EXT_timer_query extension). */ +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L +#include +#elif defined(__sun__) || defined(__digital__) +#include +#if defined(__STDC__) +#if defined(__arch64__) || defined(_LP64) +typedef long int int64_t; +typedef unsigned long int uint64_t; +#else +typedef long long int int64_t; +typedef unsigned long long int uint64_t; +#endif /* __arch64__ */ +#endif /* __STDC__ */ +#elif defined( __VMS ) || defined(__sgi) +#include +#elif defined(__SCO__) || defined(__USLC__) +#include +#elif defined(__UNIXOS2__) || defined(__SOL64__) +typedef long int int32_t; +typedef long long int int64_t; +typedef unsigned long long int uint64_t; +#elif defined(_WIN32) && defined(__GNUC__) +#include +#elif defined(_WIN32) +typedef __int32 int32_t; +typedef __int64 int64_t; +typedef unsigned __int64 uint64_t; +#else +/* Fallback if nothing above works */ +#include +#endif +#endif + +#ifndef GL_EXT_timer_query +typedef int64_t GLint64EXT; +typedef uint64_t GLuint64EXT; +#endif + +#ifndef GL_ARB_sync +typedef int64_t GLint64; +typedef uint64_t GLuint64; +typedef struct __GLsync *GLsync; +#endif + +#ifndef GL_ARB_cl_event +/* These incomplete types let us declare types compatible with OpenCL's cl_context and cl_event */ +struct _cl_context; +struct _cl_event; +#endif + +#ifndef GL_ARB_debug_output +typedef void (APIENTRY *GLDEBUGPROCARB)(GLenum source,GLenum type,GLuint id,GLenum severity,GLsizei length,const GLchar *message,GLvoid *userParam); +#endif + +#ifndef GL_AMD_debug_output +typedef void (APIENTRY *GLDEBUGPROCAMD)(GLuint id,GLenum category,GLenum severity,GLsizei length,const GLchar *message,GLvoid *userParam); +#endif + +#ifndef GL_NV_vdpau_interop +typedef GLintptr GLvdpauSurfaceNV; +#endif + +#ifndef GL_VERSION_1_2 +#define GL_VERSION_1_2 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBlendColor (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha); +GLAPI void APIENTRY glBlendEquation (GLenum mode); +GLAPI void APIENTRY glDrawRangeElements (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices); +GLAPI void APIENTRY glTexImage3D (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels); +GLAPI void APIENTRY glTexSubImage3D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *pixels); +GLAPI void APIENTRY glCopyTexSubImage3D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBLENDCOLORPROC) (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha); +typedef void (APIENTRYP PFNGLBLENDEQUATIONPROC) (GLenum mode); +typedef void (APIENTRYP PFNGLDRAWRANGEELEMENTSPROC) (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices); +typedef void (APIENTRYP PFNGLTEXIMAGE3DPROC) (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels); +typedef void (APIENTRYP PFNGLTEXSUBIMAGE3DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *pixels); +typedef void (APIENTRYP PFNGLCOPYTEXSUBIMAGE3DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height); +#endif + +#ifndef GL_VERSION_1_2_DEPRECATED +#define GL_VERSION_1_2_DEPRECATED 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glColorTable (GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const GLvoid *table); +GLAPI void APIENTRY glColorTableParameterfv (GLenum target, GLenum pname, const GLfloat *params); +GLAPI void APIENTRY glColorTableParameteriv (GLenum target, GLenum pname, const GLint *params); +GLAPI void APIENTRY glCopyColorTable (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width); +GLAPI void APIENTRY glGetColorTable (GLenum target, GLenum format, GLenum type, GLvoid *table); +GLAPI void APIENTRY glGetColorTableParameterfv (GLenum target, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetColorTableParameteriv (GLenum target, GLenum pname, GLint *params); +GLAPI void APIENTRY glColorSubTable (GLenum target, GLsizei start, GLsizei count, GLenum format, GLenum type, const GLvoid *data); +GLAPI void APIENTRY glCopyColorSubTable (GLenum target, GLsizei start, GLint x, GLint y, GLsizei width); +GLAPI void APIENTRY glConvolutionFilter1D (GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const GLvoid *image); +GLAPI void APIENTRY glConvolutionFilter2D (GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *image); +GLAPI void APIENTRY glConvolutionParameterf (GLenum target, GLenum pname, GLfloat params); +GLAPI void APIENTRY glConvolutionParameterfv (GLenum target, GLenum pname, const GLfloat *params); +GLAPI void APIENTRY glConvolutionParameteri (GLenum target, GLenum pname, GLint params); +GLAPI void APIENTRY glConvolutionParameteriv (GLenum target, GLenum pname, const GLint *params); +GLAPI void APIENTRY glCopyConvolutionFilter1D (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width); +GLAPI void APIENTRY glCopyConvolutionFilter2D (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height); +GLAPI void APIENTRY glGetConvolutionFilter (GLenum target, GLenum format, GLenum type, GLvoid *image); +GLAPI void APIENTRY glGetConvolutionParameterfv (GLenum target, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetConvolutionParameteriv (GLenum target, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetSeparableFilter (GLenum target, GLenum format, GLenum type, GLvoid *row, GLvoid *column, GLvoid *span); +GLAPI void APIENTRY glSeparableFilter2D (GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *row, const GLvoid *column); +GLAPI void APIENTRY glGetHistogram (GLenum target, GLboolean reset, GLenum format, GLenum type, GLvoid *values); +GLAPI void APIENTRY glGetHistogramParameterfv (GLenum target, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetHistogramParameteriv (GLenum target, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetMinmax (GLenum target, GLboolean reset, GLenum format, GLenum type, GLvoid *values); +GLAPI void APIENTRY glGetMinmaxParameterfv (GLenum target, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetMinmaxParameteriv (GLenum target, GLenum pname, GLint *params); +GLAPI void APIENTRY glHistogram (GLenum target, GLsizei width, GLenum internalformat, GLboolean sink); +GLAPI void APIENTRY glMinmax (GLenum target, GLenum internalformat, GLboolean sink); +GLAPI void APIENTRY glResetHistogram (GLenum target); +GLAPI void APIENTRY glResetMinmax (GLenum target); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCOLORTABLEPROC) (GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const GLvoid *table); +typedef void (APIENTRYP PFNGLCOLORTABLEPARAMETERFVPROC) (GLenum target, GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLCOLORTABLEPARAMETERIVPROC) (GLenum target, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLCOPYCOLORTABLEPROC) (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width); +typedef void (APIENTRYP PFNGLGETCOLORTABLEPROC) (GLenum target, GLenum format, GLenum type, GLvoid *table); +typedef void (APIENTRYP PFNGLGETCOLORTABLEPARAMETERFVPROC) (GLenum target, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETCOLORTABLEPARAMETERIVPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLCOLORSUBTABLEPROC) (GLenum target, GLsizei start, GLsizei count, GLenum format, GLenum type, const GLvoid *data); +typedef void (APIENTRYP PFNGLCOPYCOLORSUBTABLEPROC) (GLenum target, GLsizei start, GLint x, GLint y, GLsizei width); +typedef void (APIENTRYP PFNGLCONVOLUTIONFILTER1DPROC) (GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const GLvoid *image); +typedef void (APIENTRYP PFNGLCONVOLUTIONFILTER2DPROC) (GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *image); +typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERFPROC) (GLenum target, GLenum pname, GLfloat params); +typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERFVPROC) (GLenum target, GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERIPROC) (GLenum target, GLenum pname, GLint params); +typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERIVPROC) (GLenum target, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLCOPYCONVOLUTIONFILTER1DPROC) (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width); +typedef void (APIENTRYP PFNGLCOPYCONVOLUTIONFILTER2DPROC) (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLGETCONVOLUTIONFILTERPROC) (GLenum target, GLenum format, GLenum type, GLvoid *image); +typedef void (APIENTRYP PFNGLGETCONVOLUTIONPARAMETERFVPROC) (GLenum target, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETCONVOLUTIONPARAMETERIVPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETSEPARABLEFILTERPROC) (GLenum target, GLenum format, GLenum type, GLvoid *row, GLvoid *column, GLvoid *span); +typedef void (APIENTRYP PFNGLSEPARABLEFILTER2DPROC) (GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *row, const GLvoid *column); +typedef void (APIENTRYP PFNGLGETHISTOGRAMPROC) (GLenum target, GLboolean reset, GLenum format, GLenum type, GLvoid *values); +typedef void (APIENTRYP PFNGLGETHISTOGRAMPARAMETERFVPROC) (GLenum target, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETHISTOGRAMPARAMETERIVPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETMINMAXPROC) (GLenum target, GLboolean reset, GLenum format, GLenum type, GLvoid *values); +typedef void (APIENTRYP PFNGLGETMINMAXPARAMETERFVPROC) (GLenum target, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETMINMAXPARAMETERIVPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLHISTOGRAMPROC) (GLenum target, GLsizei width, GLenum internalformat, GLboolean sink); +typedef void (APIENTRYP PFNGLMINMAXPROC) (GLenum target, GLenum internalformat, GLboolean sink); +typedef void (APIENTRYP PFNGLRESETHISTOGRAMPROC) (GLenum target); +typedef void (APIENTRYP PFNGLRESETMINMAXPROC) (GLenum target); +#endif + +#ifndef GL_VERSION_1_3 +#define GL_VERSION_1_3 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glActiveTexture (GLenum texture); +GLAPI void APIENTRY glSampleCoverage (GLclampf value, GLboolean invert); +GLAPI void APIENTRY glCompressedTexImage3D (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid *data); +GLAPI void APIENTRY glCompressedTexImage2D (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data); +GLAPI void APIENTRY glCompressedTexImage1D (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const GLvoid *data); +GLAPI void APIENTRY glCompressedTexSubImage3D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid *data); +GLAPI void APIENTRY glCompressedTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *data); +GLAPI void APIENTRY glCompressedTexSubImage1D (GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const GLvoid *data); +GLAPI void APIENTRY glGetCompressedTexImage (GLenum target, GLint level, GLvoid *img); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLACTIVETEXTUREPROC) (GLenum texture); +typedef void (APIENTRYP PFNGLSAMPLECOVERAGEPROC) (GLclampf value, GLboolean invert); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE3DPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE2DPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE1DPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE3DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE2DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE1DPROC) (GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLGETCOMPRESSEDTEXIMAGEPROC) (GLenum target, GLint level, GLvoid *img); +#endif + +#ifndef GL_VERSION_1_3_DEPRECATED +#define GL_VERSION_1_3_DEPRECATED 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glClientActiveTexture (GLenum texture); +GLAPI void APIENTRY glMultiTexCoord1d (GLenum target, GLdouble s); +GLAPI void APIENTRY glMultiTexCoord1dv (GLenum target, const GLdouble *v); +GLAPI void APIENTRY glMultiTexCoord1f (GLenum target, GLfloat s); +GLAPI void APIENTRY glMultiTexCoord1fv (GLenum target, const GLfloat *v); +GLAPI void APIENTRY glMultiTexCoord1i (GLenum target, GLint s); +GLAPI void APIENTRY glMultiTexCoord1iv (GLenum target, const GLint *v); +GLAPI void APIENTRY glMultiTexCoord1s (GLenum target, GLshort s); +GLAPI void APIENTRY glMultiTexCoord1sv (GLenum target, const GLshort *v); +GLAPI void APIENTRY glMultiTexCoord2d (GLenum target, GLdouble s, GLdouble t); +GLAPI void APIENTRY glMultiTexCoord2dv (GLenum target, const GLdouble *v); +GLAPI void APIENTRY glMultiTexCoord2f (GLenum target, GLfloat s, GLfloat t); +GLAPI void APIENTRY glMultiTexCoord2fv (GLenum target, const GLfloat *v); +GLAPI void APIENTRY glMultiTexCoord2i (GLenum target, GLint s, GLint t); +GLAPI void APIENTRY glMultiTexCoord2iv (GLenum target, const GLint *v); +GLAPI void APIENTRY glMultiTexCoord2s (GLenum target, GLshort s, GLshort t); +GLAPI void APIENTRY glMultiTexCoord2sv (GLenum target, const GLshort *v); +GLAPI void APIENTRY glMultiTexCoord3d (GLenum target, GLdouble s, GLdouble t, GLdouble r); +GLAPI void APIENTRY glMultiTexCoord3dv (GLenum target, const GLdouble *v); +GLAPI void APIENTRY glMultiTexCoord3f (GLenum target, GLfloat s, GLfloat t, GLfloat r); +GLAPI void APIENTRY glMultiTexCoord3fv (GLenum target, const GLfloat *v); +GLAPI void APIENTRY glMultiTexCoord3i (GLenum target, GLint s, GLint t, GLint r); +GLAPI void APIENTRY glMultiTexCoord3iv (GLenum target, const GLint *v); +GLAPI void APIENTRY glMultiTexCoord3s (GLenum target, GLshort s, GLshort t, GLshort r); +GLAPI void APIENTRY glMultiTexCoord3sv (GLenum target, const GLshort *v); +GLAPI void APIENTRY glMultiTexCoord4d (GLenum target, GLdouble s, GLdouble t, GLdouble r, GLdouble q); +GLAPI void APIENTRY glMultiTexCoord4dv (GLenum target, const GLdouble *v); +GLAPI void APIENTRY glMultiTexCoord4f (GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q); +GLAPI void APIENTRY glMultiTexCoord4fv (GLenum target, const GLfloat *v); +GLAPI void APIENTRY glMultiTexCoord4i (GLenum target, GLint s, GLint t, GLint r, GLint q); +GLAPI void APIENTRY glMultiTexCoord4iv (GLenum target, const GLint *v); +GLAPI void APIENTRY glMultiTexCoord4s (GLenum target, GLshort s, GLshort t, GLshort r, GLshort q); +GLAPI void APIENTRY glMultiTexCoord4sv (GLenum target, const GLshort *v); +GLAPI void APIENTRY glLoadTransposeMatrixf (const GLfloat *m); +GLAPI void APIENTRY glLoadTransposeMatrixd (const GLdouble *m); +GLAPI void APIENTRY glMultTransposeMatrixf (const GLfloat *m); +GLAPI void APIENTRY glMultTransposeMatrixd (const GLdouble *m); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCLIENTACTIVETEXTUREPROC) (GLenum texture); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1DPROC) (GLenum target, GLdouble s); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1DVPROC) (GLenum target, const GLdouble *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1FPROC) (GLenum target, GLfloat s); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1FVPROC) (GLenum target, const GLfloat *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1IPROC) (GLenum target, GLint s); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1IVPROC) (GLenum target, const GLint *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1SPROC) (GLenum target, GLshort s); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1SVPROC) (GLenum target, const GLshort *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2DPROC) (GLenum target, GLdouble s, GLdouble t); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2DVPROC) (GLenum target, const GLdouble *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2FPROC) (GLenum target, GLfloat s, GLfloat t); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2FVPROC) (GLenum target, const GLfloat *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2IPROC) (GLenum target, GLint s, GLint t); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2IVPROC) (GLenum target, const GLint *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2SPROC) (GLenum target, GLshort s, GLshort t); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2SVPROC) (GLenum target, const GLshort *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3DPROC) (GLenum target, GLdouble s, GLdouble t, GLdouble r); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3DVPROC) (GLenum target, const GLdouble *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3FPROC) (GLenum target, GLfloat s, GLfloat t, GLfloat r); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3FVPROC) (GLenum target, const GLfloat *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3IPROC) (GLenum target, GLint s, GLint t, GLint r); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3IVPROC) (GLenum target, const GLint *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3SPROC) (GLenum target, GLshort s, GLshort t, GLshort r); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3SVPROC) (GLenum target, const GLshort *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4DPROC) (GLenum target, GLdouble s, GLdouble t, GLdouble r, GLdouble q); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4DVPROC) (GLenum target, const GLdouble *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4FPROC) (GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4FVPROC) (GLenum target, const GLfloat *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4IPROC) (GLenum target, GLint s, GLint t, GLint r, GLint q); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4IVPROC) (GLenum target, const GLint *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4SPROC) (GLenum target, GLshort s, GLshort t, GLshort r, GLshort q); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4SVPROC) (GLenum target, const GLshort *v); +typedef void (APIENTRYP PFNGLLOADTRANSPOSEMATRIXFPROC) (const GLfloat *m); +typedef void (APIENTRYP PFNGLLOADTRANSPOSEMATRIXDPROC) (const GLdouble *m); +typedef void (APIENTRYP PFNGLMULTTRANSPOSEMATRIXFPROC) (const GLfloat *m); +typedef void (APIENTRYP PFNGLMULTTRANSPOSEMATRIXDPROC) (const GLdouble *m); +#endif + +#ifndef GL_VERSION_1_4 +#define GL_VERSION_1_4 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBlendFuncSeparate (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha); +GLAPI void APIENTRY glMultiDrawArrays (GLenum mode, const GLint *first, const GLsizei *count, GLsizei primcount); +GLAPI void APIENTRY glMultiDrawElements (GLenum mode, const GLsizei *count, GLenum type, const GLvoid* *indices, GLsizei primcount); +GLAPI void APIENTRY glPointParameterf (GLenum pname, GLfloat param); +GLAPI void APIENTRY glPointParameterfv (GLenum pname, const GLfloat *params); +GLAPI void APIENTRY glPointParameteri (GLenum pname, GLint param); +GLAPI void APIENTRY glPointParameteriv (GLenum pname, const GLint *params); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEPROC) (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha); +typedef void (APIENTRYP PFNGLMULTIDRAWARRAYSPROC) (GLenum mode, const GLint *first, const GLsizei *count, GLsizei primcount); +typedef void (APIENTRYP PFNGLMULTIDRAWELEMENTSPROC) (GLenum mode, const GLsizei *count, GLenum type, const GLvoid* *indices, GLsizei primcount); +typedef void (APIENTRYP PFNGLPOINTPARAMETERFPROC) (GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLPOINTPARAMETERFVPROC) (GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLPOINTPARAMETERIPROC) (GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLPOINTPARAMETERIVPROC) (GLenum pname, const GLint *params); +#endif + +#ifndef GL_VERSION_1_4_DEPRECATED +#define GL_VERSION_1_4_DEPRECATED 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glFogCoordf (GLfloat coord); +GLAPI void APIENTRY glFogCoordfv (const GLfloat *coord); +GLAPI void APIENTRY glFogCoordd (GLdouble coord); +GLAPI void APIENTRY glFogCoorddv (const GLdouble *coord); +GLAPI void APIENTRY glFogCoordPointer (GLenum type, GLsizei stride, const GLvoid *pointer); +GLAPI void APIENTRY glSecondaryColor3b (GLbyte red, GLbyte green, GLbyte blue); +GLAPI void APIENTRY glSecondaryColor3bv (const GLbyte *v); +GLAPI void APIENTRY glSecondaryColor3d (GLdouble red, GLdouble green, GLdouble blue); +GLAPI void APIENTRY glSecondaryColor3dv (const GLdouble *v); +GLAPI void APIENTRY glSecondaryColor3f (GLfloat red, GLfloat green, GLfloat blue); +GLAPI void APIENTRY glSecondaryColor3fv (const GLfloat *v); +GLAPI void APIENTRY glSecondaryColor3i (GLint red, GLint green, GLint blue); +GLAPI void APIENTRY glSecondaryColor3iv (const GLint *v); +GLAPI void APIENTRY glSecondaryColor3s (GLshort red, GLshort green, GLshort blue); +GLAPI void APIENTRY glSecondaryColor3sv (const GLshort *v); +GLAPI void APIENTRY glSecondaryColor3ub (GLubyte red, GLubyte green, GLubyte blue); +GLAPI void APIENTRY glSecondaryColor3ubv (const GLubyte *v); +GLAPI void APIENTRY glSecondaryColor3ui (GLuint red, GLuint green, GLuint blue); +GLAPI void APIENTRY glSecondaryColor3uiv (const GLuint *v); +GLAPI void APIENTRY glSecondaryColor3us (GLushort red, GLushort green, GLushort blue); +GLAPI void APIENTRY glSecondaryColor3usv (const GLushort *v); +GLAPI void APIENTRY glSecondaryColorPointer (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +GLAPI void APIENTRY glWindowPos2d (GLdouble x, GLdouble y); +GLAPI void APIENTRY glWindowPos2dv (const GLdouble *v); +GLAPI void APIENTRY glWindowPos2f (GLfloat x, GLfloat y); +GLAPI void APIENTRY glWindowPos2fv (const GLfloat *v); +GLAPI void APIENTRY glWindowPos2i (GLint x, GLint y); +GLAPI void APIENTRY glWindowPos2iv (const GLint *v); +GLAPI void APIENTRY glWindowPos2s (GLshort x, GLshort y); +GLAPI void APIENTRY glWindowPos2sv (const GLshort *v); +GLAPI void APIENTRY glWindowPos3d (GLdouble x, GLdouble y, GLdouble z); +GLAPI void APIENTRY glWindowPos3dv (const GLdouble *v); +GLAPI void APIENTRY glWindowPos3f (GLfloat x, GLfloat y, GLfloat z); +GLAPI void APIENTRY glWindowPos3fv (const GLfloat *v); +GLAPI void APIENTRY glWindowPos3i (GLint x, GLint y, GLint z); +GLAPI void APIENTRY glWindowPos3iv (const GLint *v); +GLAPI void APIENTRY glWindowPos3s (GLshort x, GLshort y, GLshort z); +GLAPI void APIENTRY glWindowPos3sv (const GLshort *v); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLFOGCOORDFPROC) (GLfloat coord); +typedef void (APIENTRYP PFNGLFOGCOORDFVPROC) (const GLfloat *coord); +typedef void (APIENTRYP PFNGLFOGCOORDDPROC) (GLdouble coord); +typedef void (APIENTRYP PFNGLFOGCOORDDVPROC) (const GLdouble *coord); +typedef void (APIENTRYP PFNGLFOGCOORDPOINTERPROC) (GLenum type, GLsizei stride, const GLvoid *pointer); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3BPROC) (GLbyte red, GLbyte green, GLbyte blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3BVPROC) (const GLbyte *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3DPROC) (GLdouble red, GLdouble green, GLdouble blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3DVPROC) (const GLdouble *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3FPROC) (GLfloat red, GLfloat green, GLfloat blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3FVPROC) (const GLfloat *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3IPROC) (GLint red, GLint green, GLint blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3IVPROC) (const GLint *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3SPROC) (GLshort red, GLshort green, GLshort blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3SVPROC) (const GLshort *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UBPROC) (GLubyte red, GLubyte green, GLubyte blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UBVPROC) (const GLubyte *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UIPROC) (GLuint red, GLuint green, GLuint blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UIVPROC) (const GLuint *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3USPROC) (GLushort red, GLushort green, GLushort blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3USVPROC) (const GLushort *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLORPOINTERPROC) (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +typedef void (APIENTRYP PFNGLWINDOWPOS2DPROC) (GLdouble x, GLdouble y); +typedef void (APIENTRYP PFNGLWINDOWPOS2DVPROC) (const GLdouble *v); +typedef void (APIENTRYP PFNGLWINDOWPOS2FPROC) (GLfloat x, GLfloat y); +typedef void (APIENTRYP PFNGLWINDOWPOS2FVPROC) (const GLfloat *v); +typedef void (APIENTRYP PFNGLWINDOWPOS2IPROC) (GLint x, GLint y); +typedef void (APIENTRYP PFNGLWINDOWPOS2IVPROC) (const GLint *v); +typedef void (APIENTRYP PFNGLWINDOWPOS2SPROC) (GLshort x, GLshort y); +typedef void (APIENTRYP PFNGLWINDOWPOS2SVPROC) (const GLshort *v); +typedef void (APIENTRYP PFNGLWINDOWPOS3DPROC) (GLdouble x, GLdouble y, GLdouble z); +typedef void (APIENTRYP PFNGLWINDOWPOS3DVPROC) (const GLdouble *v); +typedef void (APIENTRYP PFNGLWINDOWPOS3FPROC) (GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLWINDOWPOS3FVPROC) (const GLfloat *v); +typedef void (APIENTRYP PFNGLWINDOWPOS3IPROC) (GLint x, GLint y, GLint z); +typedef void (APIENTRYP PFNGLWINDOWPOS3IVPROC) (const GLint *v); +typedef void (APIENTRYP PFNGLWINDOWPOS3SPROC) (GLshort x, GLshort y, GLshort z); +typedef void (APIENTRYP PFNGLWINDOWPOS3SVPROC) (const GLshort *v); +#endif + +#ifndef GL_VERSION_1_5 +#define GL_VERSION_1_5 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glGenQueries (GLsizei n, GLuint *ids); +GLAPI void APIENTRY glDeleteQueries (GLsizei n, const GLuint *ids); +GLAPI GLboolean APIENTRY glIsQuery (GLuint id); +GLAPI void APIENTRY glBeginQuery (GLenum target, GLuint id); +GLAPI void APIENTRY glEndQuery (GLenum target); +GLAPI void APIENTRY glGetQueryiv (GLenum target, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetQueryObjectiv (GLuint id, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetQueryObjectuiv (GLuint id, GLenum pname, GLuint *params); +GLAPI void APIENTRY glBindBuffer (GLenum target, GLuint buffer); +GLAPI void APIENTRY glDeleteBuffers (GLsizei n, const GLuint *buffers); +GLAPI void APIENTRY glGenBuffers (GLsizei n, GLuint *buffers); +GLAPI GLboolean APIENTRY glIsBuffer (GLuint buffer); +GLAPI void APIENTRY glBufferData (GLenum target, GLsizeiptr size, const GLvoid *data, GLenum usage); +GLAPI void APIENTRY glBufferSubData (GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid *data); +GLAPI void APIENTRY glGetBufferSubData (GLenum target, GLintptr offset, GLsizeiptr size, GLvoid *data); +GLAPI GLvoid* APIENTRY glMapBuffer (GLenum target, GLenum access); +GLAPI GLboolean APIENTRY glUnmapBuffer (GLenum target); +GLAPI void APIENTRY glGetBufferParameteriv (GLenum target, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetBufferPointerv (GLenum target, GLenum pname, GLvoid* *params); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGENQUERIESPROC) (GLsizei n, GLuint *ids); +typedef void (APIENTRYP PFNGLDELETEQUERIESPROC) (GLsizei n, const GLuint *ids); +typedef GLboolean (APIENTRYP PFNGLISQUERYPROC) (GLuint id); +typedef void (APIENTRYP PFNGLBEGINQUERYPROC) (GLenum target, GLuint id); +typedef void (APIENTRYP PFNGLENDQUERYPROC) (GLenum target); +typedef void (APIENTRYP PFNGLGETQUERYIVPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETQUERYOBJECTIVPROC) (GLuint id, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETQUERYOBJECTUIVPROC) (GLuint id, GLenum pname, GLuint *params); +typedef void (APIENTRYP PFNGLBINDBUFFERPROC) (GLenum target, GLuint buffer); +typedef void (APIENTRYP PFNGLDELETEBUFFERSPROC) (GLsizei n, const GLuint *buffers); +typedef void (APIENTRYP PFNGLGENBUFFERSPROC) (GLsizei n, GLuint *buffers); +typedef GLboolean (APIENTRYP PFNGLISBUFFERPROC) (GLuint buffer); +typedef void (APIENTRYP PFNGLBUFFERDATAPROC) (GLenum target, GLsizeiptr size, const GLvoid *data, GLenum usage); +typedef void (APIENTRYP PFNGLBUFFERSUBDATAPROC) (GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid *data); +typedef void (APIENTRYP PFNGLGETBUFFERSUBDATAPROC) (GLenum target, GLintptr offset, GLsizeiptr size, GLvoid *data); +typedef GLvoid* (APIENTRYP PFNGLMAPBUFFERPROC) (GLenum target, GLenum access); +typedef GLboolean (APIENTRYP PFNGLUNMAPBUFFERPROC) (GLenum target); +typedef void (APIENTRYP PFNGLGETBUFFERPARAMETERIVPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETBUFFERPOINTERVPROC) (GLenum target, GLenum pname, GLvoid* *params); +#endif + +#ifndef GL_VERSION_2_0 +#define GL_VERSION_2_0 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBlendEquationSeparate (GLenum modeRGB, GLenum modeAlpha); +GLAPI void APIENTRY glDrawBuffers (GLsizei n, const GLenum *bufs); +GLAPI void APIENTRY glStencilOpSeparate (GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass); +GLAPI void APIENTRY glStencilFuncSeparate (GLenum face, GLenum func, GLint ref, GLuint mask); +GLAPI void APIENTRY glStencilMaskSeparate (GLenum face, GLuint mask); +GLAPI void APIENTRY glAttachShader (GLuint program, GLuint shader); +GLAPI void APIENTRY glBindAttribLocation (GLuint program, GLuint index, const GLchar *name); +GLAPI void APIENTRY glCompileShader (GLuint shader); +GLAPI GLuint APIENTRY glCreateProgram (void); +GLAPI GLuint APIENTRY glCreateShader (GLenum type); +GLAPI void APIENTRY glDeleteProgram (GLuint program); +GLAPI void APIENTRY glDeleteShader (GLuint shader); +GLAPI void APIENTRY glDetachShader (GLuint program, GLuint shader); +GLAPI void APIENTRY glDisableVertexAttribArray (GLuint index); +GLAPI void APIENTRY glEnableVertexAttribArray (GLuint index); +GLAPI void APIENTRY glGetActiveAttrib (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name); +GLAPI void APIENTRY glGetActiveUniform (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name); +GLAPI void APIENTRY glGetAttachedShaders (GLuint program, GLsizei maxCount, GLsizei *count, GLuint *obj); +GLAPI GLint APIENTRY glGetAttribLocation (GLuint program, const GLchar *name); +GLAPI void APIENTRY glGetProgramiv (GLuint program, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetProgramInfoLog (GLuint program, GLsizei bufSize, GLsizei *length, GLchar *infoLog); +GLAPI void APIENTRY glGetShaderiv (GLuint shader, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetShaderInfoLog (GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *infoLog); +GLAPI void APIENTRY glGetShaderSource (GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *source); +GLAPI GLint APIENTRY glGetUniformLocation (GLuint program, const GLchar *name); +GLAPI void APIENTRY glGetUniformfv (GLuint program, GLint location, GLfloat *params); +GLAPI void APIENTRY glGetUniformiv (GLuint program, GLint location, GLint *params); +GLAPI void APIENTRY glGetVertexAttribdv (GLuint index, GLenum pname, GLdouble *params); +GLAPI void APIENTRY glGetVertexAttribfv (GLuint index, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetVertexAttribiv (GLuint index, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetVertexAttribPointerv (GLuint index, GLenum pname, GLvoid* *pointer); +GLAPI GLboolean APIENTRY glIsProgram (GLuint program); +GLAPI GLboolean APIENTRY glIsShader (GLuint shader); +GLAPI void APIENTRY glLinkProgram (GLuint program); +GLAPI void APIENTRY glShaderSource (GLuint shader, GLsizei count, const GLchar* *string, const GLint *length); +GLAPI void APIENTRY glUseProgram (GLuint program); +GLAPI void APIENTRY glUniform1f (GLint location, GLfloat v0); +GLAPI void APIENTRY glUniform2f (GLint location, GLfloat v0, GLfloat v1); +GLAPI void APIENTRY glUniform3f (GLint location, GLfloat v0, GLfloat v1, GLfloat v2); +GLAPI void APIENTRY glUniform4f (GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3); +GLAPI void APIENTRY glUniform1i (GLint location, GLint v0); +GLAPI void APIENTRY glUniform2i (GLint location, GLint v0, GLint v1); +GLAPI void APIENTRY glUniform3i (GLint location, GLint v0, GLint v1, GLint v2); +GLAPI void APIENTRY glUniform4i (GLint location, GLint v0, GLint v1, GLint v2, GLint v3); +GLAPI void APIENTRY glUniform1fv (GLint location, GLsizei count, const GLfloat *value); +GLAPI void APIENTRY glUniform2fv (GLint location, GLsizei count, const GLfloat *value); +GLAPI void APIENTRY glUniform3fv (GLint location, GLsizei count, const GLfloat *value); +GLAPI void APIENTRY glUniform4fv (GLint location, GLsizei count, const GLfloat *value); +GLAPI void APIENTRY glUniform1iv (GLint location, GLsizei count, const GLint *value); +GLAPI void APIENTRY glUniform2iv (GLint location, GLsizei count, const GLint *value); +GLAPI void APIENTRY glUniform3iv (GLint location, GLsizei count, const GLint *value); +GLAPI void APIENTRY glUniform4iv (GLint location, GLsizei count, const GLint *value); +GLAPI void APIENTRY glUniformMatrix2fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glUniformMatrix3fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glUniformMatrix4fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glValidateProgram (GLuint program); +GLAPI void APIENTRY glVertexAttrib1d (GLuint index, GLdouble x); +GLAPI void APIENTRY glVertexAttrib1dv (GLuint index, const GLdouble *v); +GLAPI void APIENTRY glVertexAttrib1f (GLuint index, GLfloat x); +GLAPI void APIENTRY glVertexAttrib1fv (GLuint index, const GLfloat *v); +GLAPI void APIENTRY glVertexAttrib1s (GLuint index, GLshort x); +GLAPI void APIENTRY glVertexAttrib1sv (GLuint index, const GLshort *v); +GLAPI void APIENTRY glVertexAttrib2d (GLuint index, GLdouble x, GLdouble y); +GLAPI void APIENTRY glVertexAttrib2dv (GLuint index, const GLdouble *v); +GLAPI void APIENTRY glVertexAttrib2f (GLuint index, GLfloat x, GLfloat y); +GLAPI void APIENTRY glVertexAttrib2fv (GLuint index, const GLfloat *v); +GLAPI void APIENTRY glVertexAttrib2s (GLuint index, GLshort x, GLshort y); +GLAPI void APIENTRY glVertexAttrib2sv (GLuint index, const GLshort *v); +GLAPI void APIENTRY glVertexAttrib3d (GLuint index, GLdouble x, GLdouble y, GLdouble z); +GLAPI void APIENTRY glVertexAttrib3dv (GLuint index, const GLdouble *v); +GLAPI void APIENTRY glVertexAttrib3f (GLuint index, GLfloat x, GLfloat y, GLfloat z); +GLAPI void APIENTRY glVertexAttrib3fv (GLuint index, const GLfloat *v); +GLAPI void APIENTRY glVertexAttrib3s (GLuint index, GLshort x, GLshort y, GLshort z); +GLAPI void APIENTRY glVertexAttrib3sv (GLuint index, const GLshort *v); +GLAPI void APIENTRY glVertexAttrib4Nbv (GLuint index, const GLbyte *v); +GLAPI void APIENTRY glVertexAttrib4Niv (GLuint index, const GLint *v); +GLAPI void APIENTRY glVertexAttrib4Nsv (GLuint index, const GLshort *v); +GLAPI void APIENTRY glVertexAttrib4Nub (GLuint index, GLubyte x, GLubyte y, GLubyte z, GLubyte w); +GLAPI void APIENTRY glVertexAttrib4Nubv (GLuint index, const GLubyte *v); +GLAPI void APIENTRY glVertexAttrib4Nuiv (GLuint index, const GLuint *v); +GLAPI void APIENTRY glVertexAttrib4Nusv (GLuint index, const GLushort *v); +GLAPI void APIENTRY glVertexAttrib4bv (GLuint index, const GLbyte *v); +GLAPI void APIENTRY glVertexAttrib4d (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +GLAPI void APIENTRY glVertexAttrib4dv (GLuint index, const GLdouble *v); +GLAPI void APIENTRY glVertexAttrib4f (GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +GLAPI void APIENTRY glVertexAttrib4fv (GLuint index, const GLfloat *v); +GLAPI void APIENTRY glVertexAttrib4iv (GLuint index, const GLint *v); +GLAPI void APIENTRY glVertexAttrib4s (GLuint index, GLshort x, GLshort y, GLshort z, GLshort w); +GLAPI void APIENTRY glVertexAttrib4sv (GLuint index, const GLshort *v); +GLAPI void APIENTRY glVertexAttrib4ubv (GLuint index, const GLubyte *v); +GLAPI void APIENTRY glVertexAttrib4uiv (GLuint index, const GLuint *v); +GLAPI void APIENTRY glVertexAttrib4usv (GLuint index, const GLushort *v); +GLAPI void APIENTRY glVertexAttribPointer (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid *pointer); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBLENDEQUATIONSEPARATEPROC) (GLenum modeRGB, GLenum modeAlpha); +typedef void (APIENTRYP PFNGLDRAWBUFFERSPROC) (GLsizei n, const GLenum *bufs); +typedef void (APIENTRYP PFNGLSTENCILOPSEPARATEPROC) (GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass); +typedef void (APIENTRYP PFNGLSTENCILFUNCSEPARATEPROC) (GLenum face, GLenum func, GLint ref, GLuint mask); +typedef void (APIENTRYP PFNGLSTENCILMASKSEPARATEPROC) (GLenum face, GLuint mask); +typedef void (APIENTRYP PFNGLATTACHSHADERPROC) (GLuint program, GLuint shader); +typedef void (APIENTRYP PFNGLBINDATTRIBLOCATIONPROC) (GLuint program, GLuint index, const GLchar *name); +typedef void (APIENTRYP PFNGLCOMPILESHADERPROC) (GLuint shader); +typedef GLuint (APIENTRYP PFNGLCREATEPROGRAMPROC) (void); +typedef GLuint (APIENTRYP PFNGLCREATESHADERPROC) (GLenum type); +typedef void (APIENTRYP PFNGLDELETEPROGRAMPROC) (GLuint program); +typedef void (APIENTRYP PFNGLDELETESHADERPROC) (GLuint shader); +typedef void (APIENTRYP PFNGLDETACHSHADERPROC) (GLuint program, GLuint shader); +typedef void (APIENTRYP PFNGLDISABLEVERTEXATTRIBARRAYPROC) (GLuint index); +typedef void (APIENTRYP PFNGLENABLEVERTEXATTRIBARRAYPROC) (GLuint index); +typedef void (APIENTRYP PFNGLGETACTIVEATTRIBPROC) (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name); +typedef void (APIENTRYP PFNGLGETACTIVEUNIFORMPROC) (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name); +typedef void (APIENTRYP PFNGLGETATTACHEDSHADERSPROC) (GLuint program, GLsizei maxCount, GLsizei *count, GLuint *obj); +typedef GLint (APIENTRYP PFNGLGETATTRIBLOCATIONPROC) (GLuint program, const GLchar *name); +typedef void (APIENTRYP PFNGLGETPROGRAMIVPROC) (GLuint program, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETPROGRAMINFOLOGPROC) (GLuint program, GLsizei bufSize, GLsizei *length, GLchar *infoLog); +typedef void (APIENTRYP PFNGLGETSHADERIVPROC) (GLuint shader, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETSHADERINFOLOGPROC) (GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *infoLog); +typedef void (APIENTRYP PFNGLGETSHADERSOURCEPROC) (GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *source); +typedef GLint (APIENTRYP PFNGLGETUNIFORMLOCATIONPROC) (GLuint program, const GLchar *name); +typedef void (APIENTRYP PFNGLGETUNIFORMFVPROC) (GLuint program, GLint location, GLfloat *params); +typedef void (APIENTRYP PFNGLGETUNIFORMIVPROC) (GLuint program, GLint location, GLint *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBDVPROC) (GLuint index, GLenum pname, GLdouble *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBFVPROC) (GLuint index, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIVPROC) (GLuint index, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBPOINTERVPROC) (GLuint index, GLenum pname, GLvoid* *pointer); +typedef GLboolean (APIENTRYP PFNGLISPROGRAMPROC) (GLuint program); +typedef GLboolean (APIENTRYP PFNGLISSHADERPROC) (GLuint shader); +typedef void (APIENTRYP PFNGLLINKPROGRAMPROC) (GLuint program); +typedef void (APIENTRYP PFNGLSHADERSOURCEPROC) (GLuint shader, GLsizei count, const GLchar* *string, const GLint *length); +typedef void (APIENTRYP PFNGLUSEPROGRAMPROC) (GLuint program); +typedef void (APIENTRYP PFNGLUNIFORM1FPROC) (GLint location, GLfloat v0); +typedef void (APIENTRYP PFNGLUNIFORM2FPROC) (GLint location, GLfloat v0, GLfloat v1); +typedef void (APIENTRYP PFNGLUNIFORM3FPROC) (GLint location, GLfloat v0, GLfloat v1, GLfloat v2); +typedef void (APIENTRYP PFNGLUNIFORM4FPROC) (GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3); +typedef void (APIENTRYP PFNGLUNIFORM1IPROC) (GLint location, GLint v0); +typedef void (APIENTRYP PFNGLUNIFORM2IPROC) (GLint location, GLint v0, GLint v1); +typedef void (APIENTRYP PFNGLUNIFORM3IPROC) (GLint location, GLint v0, GLint v1, GLint v2); +typedef void (APIENTRYP PFNGLUNIFORM4IPROC) (GLint location, GLint v0, GLint v1, GLint v2, GLint v3); +typedef void (APIENTRYP PFNGLUNIFORM1FVPROC) (GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORM2FVPROC) (GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORM3FVPROC) (GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORM4FVPROC) (GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORM1IVPROC) (GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLUNIFORM2IVPROC) (GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLUNIFORM3IVPROC) (GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLUNIFORM4IVPROC) (GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX2FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX3FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX4FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLVALIDATEPROGRAMPROC) (GLuint program); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1DPROC) (GLuint index, GLdouble x); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1DVPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1FPROC) (GLuint index, GLfloat x); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1FVPROC) (GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1SPROC) (GLuint index, GLshort x); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1SVPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2DPROC) (GLuint index, GLdouble x, GLdouble y); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2DVPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2FPROC) (GLuint index, GLfloat x, GLfloat y); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2FVPROC) (GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2SPROC) (GLuint index, GLshort x, GLshort y); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2SVPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3DPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3DVPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3FPROC) (GLuint index, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3FVPROC) (GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3SPROC) (GLuint index, GLshort x, GLshort y, GLshort z); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3SVPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NBVPROC) (GLuint index, const GLbyte *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NIVPROC) (GLuint index, const GLint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NSVPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUBPROC) (GLuint index, GLubyte x, GLubyte y, GLubyte z, GLubyte w); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUBVPROC) (GLuint index, const GLubyte *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUIVPROC) (GLuint index, const GLuint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUSVPROC) (GLuint index, const GLushort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4BVPROC) (GLuint index, const GLbyte *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4DPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4DVPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4FPROC) (GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4FVPROC) (GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4IVPROC) (GLuint index, const GLint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4SPROC) (GLuint index, GLshort x, GLshort y, GLshort z, GLshort w); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4SVPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4UBVPROC) (GLuint index, const GLubyte *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4UIVPROC) (GLuint index, const GLuint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4USVPROC) (GLuint index, const GLushort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBPOINTERPROC) (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid *pointer); +#endif + +#ifndef GL_VERSION_2_1 +#define GL_VERSION_2_1 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glUniformMatrix2x3fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glUniformMatrix3x2fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glUniformMatrix2x4fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glUniformMatrix4x2fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glUniformMatrix3x4fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glUniformMatrix4x3fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLUNIFORMMATRIX2X3FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX3X2FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX2X4FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX4X2FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX3X4FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX4X3FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +#endif + +#ifndef GL_VERSION_3_0 +#define GL_VERSION_3_0 1 +/* OpenGL 3.0 also reuses entry points from these extensions: */ +/* ARB_framebuffer_object */ +/* ARB_map_buffer_range */ +/* ARB_vertex_array_object */ +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glColorMaski (GLuint index, GLboolean r, GLboolean g, GLboolean b, GLboolean a); +GLAPI void APIENTRY glGetBooleani_v (GLenum target, GLuint index, GLboolean *data); +GLAPI void APIENTRY glGetIntegeri_v (GLenum target, GLuint index, GLint *data); +GLAPI void APIENTRY glEnablei (GLenum target, GLuint index); +GLAPI void APIENTRY glDisablei (GLenum target, GLuint index); +GLAPI GLboolean APIENTRY glIsEnabledi (GLenum target, GLuint index); +GLAPI void APIENTRY glBeginTransformFeedback (GLenum primitiveMode); +GLAPI void APIENTRY glEndTransformFeedback (void); +GLAPI void APIENTRY glBindBufferRange (GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size); +GLAPI void APIENTRY glBindBufferBase (GLenum target, GLuint index, GLuint buffer); +GLAPI void APIENTRY glTransformFeedbackVaryings (GLuint program, GLsizei count, const GLchar* *varyings, GLenum bufferMode); +GLAPI void APIENTRY glGetTransformFeedbackVarying (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLsizei *size, GLenum *type, GLchar *name); +GLAPI void APIENTRY glClampColor (GLenum target, GLenum clamp); +GLAPI void APIENTRY glBeginConditionalRender (GLuint id, GLenum mode); +GLAPI void APIENTRY glEndConditionalRender (void); +GLAPI void APIENTRY glVertexAttribIPointer (GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +GLAPI void APIENTRY glGetVertexAttribIiv (GLuint index, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetVertexAttribIuiv (GLuint index, GLenum pname, GLuint *params); +GLAPI void APIENTRY glVertexAttribI1i (GLuint index, GLint x); +GLAPI void APIENTRY glVertexAttribI2i (GLuint index, GLint x, GLint y); +GLAPI void APIENTRY glVertexAttribI3i (GLuint index, GLint x, GLint y, GLint z); +GLAPI void APIENTRY glVertexAttribI4i (GLuint index, GLint x, GLint y, GLint z, GLint w); +GLAPI void APIENTRY glVertexAttribI1ui (GLuint index, GLuint x); +GLAPI void APIENTRY glVertexAttribI2ui (GLuint index, GLuint x, GLuint y); +GLAPI void APIENTRY glVertexAttribI3ui (GLuint index, GLuint x, GLuint y, GLuint z); +GLAPI void APIENTRY glVertexAttribI4ui (GLuint index, GLuint x, GLuint y, GLuint z, GLuint w); +GLAPI void APIENTRY glVertexAttribI1iv (GLuint index, const GLint *v); +GLAPI void APIENTRY glVertexAttribI2iv (GLuint index, const GLint *v); +GLAPI void APIENTRY glVertexAttribI3iv (GLuint index, const GLint *v); +GLAPI void APIENTRY glVertexAttribI4iv (GLuint index, const GLint *v); +GLAPI void APIENTRY glVertexAttribI1uiv (GLuint index, const GLuint *v); +GLAPI void APIENTRY glVertexAttribI2uiv (GLuint index, const GLuint *v); +GLAPI void APIENTRY glVertexAttribI3uiv (GLuint index, const GLuint *v); +GLAPI void APIENTRY glVertexAttribI4uiv (GLuint index, const GLuint *v); +GLAPI void APIENTRY glVertexAttribI4bv (GLuint index, const GLbyte *v); +GLAPI void APIENTRY glVertexAttribI4sv (GLuint index, const GLshort *v); +GLAPI void APIENTRY glVertexAttribI4ubv (GLuint index, const GLubyte *v); +GLAPI void APIENTRY glVertexAttribI4usv (GLuint index, const GLushort *v); +GLAPI void APIENTRY glGetUniformuiv (GLuint program, GLint location, GLuint *params); +GLAPI void APIENTRY glBindFragDataLocation (GLuint program, GLuint color, const GLchar *name); +GLAPI GLint APIENTRY glGetFragDataLocation (GLuint program, const GLchar *name); +GLAPI void APIENTRY glUniform1ui (GLint location, GLuint v0); +GLAPI void APIENTRY glUniform2ui (GLint location, GLuint v0, GLuint v1); +GLAPI void APIENTRY glUniform3ui (GLint location, GLuint v0, GLuint v1, GLuint v2); +GLAPI void APIENTRY glUniform4ui (GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3); +GLAPI void APIENTRY glUniform1uiv (GLint location, GLsizei count, const GLuint *value); +GLAPI void APIENTRY glUniform2uiv (GLint location, GLsizei count, const GLuint *value); +GLAPI void APIENTRY glUniform3uiv (GLint location, GLsizei count, const GLuint *value); +GLAPI void APIENTRY glUniform4uiv (GLint location, GLsizei count, const GLuint *value); +GLAPI void APIENTRY glTexParameterIiv (GLenum target, GLenum pname, const GLint *params); +GLAPI void APIENTRY glTexParameterIuiv (GLenum target, GLenum pname, const GLuint *params); +GLAPI void APIENTRY glGetTexParameterIiv (GLenum target, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetTexParameterIuiv (GLenum target, GLenum pname, GLuint *params); +GLAPI void APIENTRY glClearBufferiv (GLenum buffer, GLint drawbuffer, const GLint *value); +GLAPI void APIENTRY glClearBufferuiv (GLenum buffer, GLint drawbuffer, const GLuint *value); +GLAPI void APIENTRY glClearBufferfv (GLenum buffer, GLint drawbuffer, const GLfloat *value); +GLAPI void APIENTRY glClearBufferfi (GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil); +GLAPI const GLubyte * APIENTRY glGetStringi (GLenum name, GLuint index); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCOLORMASKIPROC) (GLuint index, GLboolean r, GLboolean g, GLboolean b, GLboolean a); +typedef void (APIENTRYP PFNGLGETBOOLEANI_VPROC) (GLenum target, GLuint index, GLboolean *data); +typedef void (APIENTRYP PFNGLGETINTEGERI_VPROC) (GLenum target, GLuint index, GLint *data); +typedef void (APIENTRYP PFNGLENABLEIPROC) (GLenum target, GLuint index); +typedef void (APIENTRYP PFNGLDISABLEIPROC) (GLenum target, GLuint index); +typedef GLboolean (APIENTRYP PFNGLISENABLEDIPROC) (GLenum target, GLuint index); +typedef void (APIENTRYP PFNGLBEGINTRANSFORMFEEDBACKPROC) (GLenum primitiveMode); +typedef void (APIENTRYP PFNGLENDTRANSFORMFEEDBACKPROC) (void); +typedef void (APIENTRYP PFNGLBINDBUFFERRANGEPROC) (GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size); +typedef void (APIENTRYP PFNGLBINDBUFFERBASEPROC) (GLenum target, GLuint index, GLuint buffer); +typedef void (APIENTRYP PFNGLTRANSFORMFEEDBACKVARYINGSPROC) (GLuint program, GLsizei count, const GLchar* *varyings, GLenum bufferMode); +typedef void (APIENTRYP PFNGLGETTRANSFORMFEEDBACKVARYINGPROC) (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLsizei *size, GLenum *type, GLchar *name); +typedef void (APIENTRYP PFNGLCLAMPCOLORPROC) (GLenum target, GLenum clamp); +typedef void (APIENTRYP PFNGLBEGINCONDITIONALRENDERPROC) (GLuint id, GLenum mode); +typedef void (APIENTRYP PFNGLENDCONDITIONALRENDERPROC) (void); +typedef void (APIENTRYP PFNGLVERTEXATTRIBIPOINTERPROC) (GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIIVPROC) (GLuint index, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIUIVPROC) (GLuint index, GLenum pname, GLuint *params); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI1IPROC) (GLuint index, GLint x); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI2IPROC) (GLuint index, GLint x, GLint y); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI3IPROC) (GLuint index, GLint x, GLint y, GLint z); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI4IPROC) (GLuint index, GLint x, GLint y, GLint z, GLint w); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI1UIPROC) (GLuint index, GLuint x); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI2UIPROC) (GLuint index, GLuint x, GLuint y); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI3UIPROC) (GLuint index, GLuint x, GLuint y, GLuint z); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI4UIPROC) (GLuint index, GLuint x, GLuint y, GLuint z, GLuint w); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI1IVPROC) (GLuint index, const GLint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI2IVPROC) (GLuint index, const GLint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI3IVPROC) (GLuint index, const GLint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI4IVPROC) (GLuint index, const GLint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI1UIVPROC) (GLuint index, const GLuint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI2UIVPROC) (GLuint index, const GLuint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI3UIVPROC) (GLuint index, const GLuint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI4UIVPROC) (GLuint index, const GLuint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI4BVPROC) (GLuint index, const GLbyte *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI4SVPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI4UBVPROC) (GLuint index, const GLubyte *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI4USVPROC) (GLuint index, const GLushort *v); +typedef void (APIENTRYP PFNGLGETUNIFORMUIVPROC) (GLuint program, GLint location, GLuint *params); +typedef void (APIENTRYP PFNGLBINDFRAGDATALOCATIONPROC) (GLuint program, GLuint color, const GLchar *name); +typedef GLint (APIENTRYP PFNGLGETFRAGDATALOCATIONPROC) (GLuint program, const GLchar *name); +typedef void (APIENTRYP PFNGLUNIFORM1UIPROC) (GLint location, GLuint v0); +typedef void (APIENTRYP PFNGLUNIFORM2UIPROC) (GLint location, GLuint v0, GLuint v1); +typedef void (APIENTRYP PFNGLUNIFORM3UIPROC) (GLint location, GLuint v0, GLuint v1, GLuint v2); +typedef void (APIENTRYP PFNGLUNIFORM4UIPROC) (GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3); +typedef void (APIENTRYP PFNGLUNIFORM1UIVPROC) (GLint location, GLsizei count, const GLuint *value); +typedef void (APIENTRYP PFNGLUNIFORM2UIVPROC) (GLint location, GLsizei count, const GLuint *value); +typedef void (APIENTRYP PFNGLUNIFORM3UIVPROC) (GLint location, GLsizei count, const GLuint *value); +typedef void (APIENTRYP PFNGLUNIFORM4UIVPROC) (GLint location, GLsizei count, const GLuint *value); +typedef void (APIENTRYP PFNGLTEXPARAMETERIIVPROC) (GLenum target, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLTEXPARAMETERIUIVPROC) (GLenum target, GLenum pname, const GLuint *params); +typedef void (APIENTRYP PFNGLGETTEXPARAMETERIIVPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETTEXPARAMETERIUIVPROC) (GLenum target, GLenum pname, GLuint *params); +typedef void (APIENTRYP PFNGLCLEARBUFFERIVPROC) (GLenum buffer, GLint drawbuffer, const GLint *value); +typedef void (APIENTRYP PFNGLCLEARBUFFERUIVPROC) (GLenum buffer, GLint drawbuffer, const GLuint *value); +typedef void (APIENTRYP PFNGLCLEARBUFFERFVPROC) (GLenum buffer, GLint drawbuffer, const GLfloat *value); +typedef void (APIENTRYP PFNGLCLEARBUFFERFIPROC) (GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil); +typedef const GLubyte * (APIENTRYP PFNGLGETSTRINGIPROC) (GLenum name, GLuint index); +#endif + +#ifndef GL_VERSION_3_1 +#define GL_VERSION_3_1 1 +/* OpenGL 3.1 also reuses entry points from these extensions: */ +/* ARB_copy_buffer */ +/* ARB_uniform_buffer_object */ +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDrawArraysInstanced (GLenum mode, GLint first, GLsizei count, GLsizei primcount); +GLAPI void APIENTRY glDrawElementsInstanced (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei primcount); +GLAPI void APIENTRY glTexBuffer (GLenum target, GLenum internalformat, GLuint buffer); +GLAPI void APIENTRY glPrimitiveRestartIndex (GLuint index); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDRAWARRAYSINSTANCEDPROC) (GLenum mode, GLint first, GLsizei count, GLsizei primcount); +typedef void (APIENTRYP PFNGLDRAWELEMENTSINSTANCEDPROC) (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei primcount); +typedef void (APIENTRYP PFNGLTEXBUFFERPROC) (GLenum target, GLenum internalformat, GLuint buffer); +typedef void (APIENTRYP PFNGLPRIMITIVERESTARTINDEXPROC) (GLuint index); +#endif + +#ifndef GL_VERSION_3_2 +#define GL_VERSION_3_2 1 +/* OpenGL 3.2 also reuses entry points from these extensions: */ +/* ARB_draw_elements_base_vertex */ +/* ARB_provoking_vertex */ +/* ARB_sync */ +/* ARB_texture_multisample */ +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glGetInteger64i_v (GLenum target, GLuint index, GLint64 *data); +GLAPI void APIENTRY glGetBufferParameteri64v (GLenum target, GLenum pname, GLint64 *params); +GLAPI void APIENTRY glFramebufferTexture (GLenum target, GLenum attachment, GLuint texture, GLint level); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGETINTEGER64I_VPROC) (GLenum target, GLuint index, GLint64 *data); +typedef void (APIENTRYP PFNGLGETBUFFERPARAMETERI64VPROC) (GLenum target, GLenum pname, GLint64 *params); +typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTUREPROC) (GLenum target, GLenum attachment, GLuint texture, GLint level); +#endif + +#ifndef GL_VERSION_3_3 +#define GL_VERSION_3_3 1 +/* OpenGL 3.3 also reuses entry points from these extensions: */ +/* ARB_blend_func_extended */ +/* ARB_sampler_objects */ +/* ARB_explicit_attrib_location, but it has none */ +/* ARB_occlusion_query2 (no entry points) */ +/* ARB_shader_bit_encoding (no entry points) */ +/* ARB_texture_rgb10_a2ui (no entry points) */ +/* ARB_texture_swizzle (no entry points) */ +/* ARB_timer_query */ +/* ARB_vertex_type_2_10_10_10_rev */ +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glVertexAttribDivisor (GLuint index, GLuint divisor); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLVERTEXATTRIBDIVISORPROC) (GLuint index, GLuint divisor); +#endif + +#ifndef GL_VERSION_4_0 +#define GL_VERSION_4_0 1 +/* OpenGL 4.0 also reuses entry points from these extensions: */ +/* ARB_texture_query_lod (no entry points) */ +/* ARB_draw_indirect */ +/* ARB_gpu_shader5 (no entry points) */ +/* ARB_gpu_shader_fp64 */ +/* ARB_shader_subroutine */ +/* ARB_tessellation_shader */ +/* ARB_texture_buffer_object_rgb32 (no entry points) */ +/* ARB_texture_cube_map_array (no entry points) */ +/* ARB_texture_gather (no entry points) */ +/* ARB_transform_feedback2 */ +/* ARB_transform_feedback3 */ +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glMinSampleShading (GLclampf value); +GLAPI void APIENTRY glBlendEquationi (GLuint buf, GLenum mode); +GLAPI void APIENTRY glBlendEquationSeparatei (GLuint buf, GLenum modeRGB, GLenum modeAlpha); +GLAPI void APIENTRY glBlendFunci (GLuint buf, GLenum src, GLenum dst); +GLAPI void APIENTRY glBlendFuncSeparatei (GLuint buf, GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLMINSAMPLESHADINGPROC) (GLclampf value); +typedef void (APIENTRYP PFNGLBLENDEQUATIONIPROC) (GLuint buf, GLenum mode); +typedef void (APIENTRYP PFNGLBLENDEQUATIONSEPARATEIPROC) (GLuint buf, GLenum modeRGB, GLenum modeAlpha); +typedef void (APIENTRYP PFNGLBLENDFUNCIPROC) (GLuint buf, GLenum src, GLenum dst); +typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEIPROC) (GLuint buf, GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha); +#endif + +#ifndef GL_VERSION_4_1 +#define GL_VERSION_4_1 1 +/* OpenGL 4.1 also reuses entry points from these extensions: */ +/* ARB_ES2_compatibility */ +/* ARB_get_program_binary */ +/* ARB_separate_shader_objects */ +/* ARB_shader_precision (no entry points) */ +/* ARB_vertex_attrib_64bit */ +/* ARB_viewport_array */ +#endif + +#ifndef GL_ARB_multitexture +#define GL_ARB_multitexture 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glActiveTextureARB (GLenum texture); +GLAPI void APIENTRY glClientActiveTextureARB (GLenum texture); +GLAPI void APIENTRY glMultiTexCoord1dARB (GLenum target, GLdouble s); +GLAPI void APIENTRY glMultiTexCoord1dvARB (GLenum target, const GLdouble *v); +GLAPI void APIENTRY glMultiTexCoord1fARB (GLenum target, GLfloat s); +GLAPI void APIENTRY glMultiTexCoord1fvARB (GLenum target, const GLfloat *v); +GLAPI void APIENTRY glMultiTexCoord1iARB (GLenum target, GLint s); +GLAPI void APIENTRY glMultiTexCoord1ivARB (GLenum target, const GLint *v); +GLAPI void APIENTRY glMultiTexCoord1sARB (GLenum target, GLshort s); +GLAPI void APIENTRY glMultiTexCoord1svARB (GLenum target, const GLshort *v); +GLAPI void APIENTRY glMultiTexCoord2dARB (GLenum target, GLdouble s, GLdouble t); +GLAPI void APIENTRY glMultiTexCoord2dvARB (GLenum target, const GLdouble *v); +GLAPI void APIENTRY glMultiTexCoord2fARB (GLenum target, GLfloat s, GLfloat t); +GLAPI void APIENTRY glMultiTexCoord2fvARB (GLenum target, const GLfloat *v); +GLAPI void APIENTRY glMultiTexCoord2iARB (GLenum target, GLint s, GLint t); +GLAPI void APIENTRY glMultiTexCoord2ivARB (GLenum target, const GLint *v); +GLAPI void APIENTRY glMultiTexCoord2sARB (GLenum target, GLshort s, GLshort t); +GLAPI void APIENTRY glMultiTexCoord2svARB (GLenum target, const GLshort *v); +GLAPI void APIENTRY glMultiTexCoord3dARB (GLenum target, GLdouble s, GLdouble t, GLdouble r); +GLAPI void APIENTRY glMultiTexCoord3dvARB (GLenum target, const GLdouble *v); +GLAPI void APIENTRY glMultiTexCoord3fARB (GLenum target, GLfloat s, GLfloat t, GLfloat r); +GLAPI void APIENTRY glMultiTexCoord3fvARB (GLenum target, const GLfloat *v); +GLAPI void APIENTRY glMultiTexCoord3iARB (GLenum target, GLint s, GLint t, GLint r); +GLAPI void APIENTRY glMultiTexCoord3ivARB (GLenum target, const GLint *v); +GLAPI void APIENTRY glMultiTexCoord3sARB (GLenum target, GLshort s, GLshort t, GLshort r); +GLAPI void APIENTRY glMultiTexCoord3svARB (GLenum target, const GLshort *v); +GLAPI void APIENTRY glMultiTexCoord4dARB (GLenum target, GLdouble s, GLdouble t, GLdouble r, GLdouble q); +GLAPI void APIENTRY glMultiTexCoord4dvARB (GLenum target, const GLdouble *v); +GLAPI void APIENTRY glMultiTexCoord4fARB (GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q); +GLAPI void APIENTRY glMultiTexCoord4fvARB (GLenum target, const GLfloat *v); +GLAPI void APIENTRY glMultiTexCoord4iARB (GLenum target, GLint s, GLint t, GLint r, GLint q); +GLAPI void APIENTRY glMultiTexCoord4ivARB (GLenum target, const GLint *v); +GLAPI void APIENTRY glMultiTexCoord4sARB (GLenum target, GLshort s, GLshort t, GLshort r, GLshort q); +GLAPI void APIENTRY glMultiTexCoord4svARB (GLenum target, const GLshort *v); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLACTIVETEXTUREARBPROC) (GLenum texture); +typedef void (APIENTRYP PFNGLCLIENTACTIVETEXTUREARBPROC) (GLenum texture); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1DARBPROC) (GLenum target, GLdouble s); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1DVARBPROC) (GLenum target, const GLdouble *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1FARBPROC) (GLenum target, GLfloat s); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1FVARBPROC) (GLenum target, const GLfloat *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1IARBPROC) (GLenum target, GLint s); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1IVARBPROC) (GLenum target, const GLint *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1SARBPROC) (GLenum target, GLshort s); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1SVARBPROC) (GLenum target, const GLshort *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2DARBPROC) (GLenum target, GLdouble s, GLdouble t); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2DVARBPROC) (GLenum target, const GLdouble *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2FARBPROC) (GLenum target, GLfloat s, GLfloat t); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2FVARBPROC) (GLenum target, const GLfloat *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2IARBPROC) (GLenum target, GLint s, GLint t); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2IVARBPROC) (GLenum target, const GLint *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2SARBPROC) (GLenum target, GLshort s, GLshort t); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2SVARBPROC) (GLenum target, const GLshort *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3DARBPROC) (GLenum target, GLdouble s, GLdouble t, GLdouble r); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3DVARBPROC) (GLenum target, const GLdouble *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3FARBPROC) (GLenum target, GLfloat s, GLfloat t, GLfloat r); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3FVARBPROC) (GLenum target, const GLfloat *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3IARBPROC) (GLenum target, GLint s, GLint t, GLint r); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3IVARBPROC) (GLenum target, const GLint *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3SARBPROC) (GLenum target, GLshort s, GLshort t, GLshort r); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3SVARBPROC) (GLenum target, const GLshort *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4DARBPROC) (GLenum target, GLdouble s, GLdouble t, GLdouble r, GLdouble q); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4DVARBPROC) (GLenum target, const GLdouble *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4FARBPROC) (GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4FVARBPROC) (GLenum target, const GLfloat *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4IARBPROC) (GLenum target, GLint s, GLint t, GLint r, GLint q); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4IVARBPROC) (GLenum target, const GLint *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4SARBPROC) (GLenum target, GLshort s, GLshort t, GLshort r, GLshort q); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4SVARBPROC) (GLenum target, const GLshort *v); +#endif + +#ifndef GL_ARB_transpose_matrix +#define GL_ARB_transpose_matrix 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glLoadTransposeMatrixfARB (const GLfloat *m); +GLAPI void APIENTRY glLoadTransposeMatrixdARB (const GLdouble *m); +GLAPI void APIENTRY glMultTransposeMatrixfARB (const GLfloat *m); +GLAPI void APIENTRY glMultTransposeMatrixdARB (const GLdouble *m); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLLOADTRANSPOSEMATRIXFARBPROC) (const GLfloat *m); +typedef void (APIENTRYP PFNGLLOADTRANSPOSEMATRIXDARBPROC) (const GLdouble *m); +typedef void (APIENTRYP PFNGLMULTTRANSPOSEMATRIXFARBPROC) (const GLfloat *m); +typedef void (APIENTRYP PFNGLMULTTRANSPOSEMATRIXDARBPROC) (const GLdouble *m); +#endif + +#ifndef GL_ARB_multisample +#define GL_ARB_multisample 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glSampleCoverageARB (GLclampf value, GLboolean invert); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLSAMPLECOVERAGEARBPROC) (GLclampf value, GLboolean invert); +#endif + +#ifndef GL_ARB_texture_env_add +#define GL_ARB_texture_env_add 1 +#endif + +#ifndef GL_ARB_texture_cube_map +#define GL_ARB_texture_cube_map 1 +#endif + +#ifndef GL_ARB_texture_compression +#define GL_ARB_texture_compression 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glCompressedTexImage3DARB (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid *data); +GLAPI void APIENTRY glCompressedTexImage2DARB (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data); +GLAPI void APIENTRY glCompressedTexImage1DARB (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const GLvoid *data); +GLAPI void APIENTRY glCompressedTexSubImage3DARB (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid *data); +GLAPI void APIENTRY glCompressedTexSubImage2DARB (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *data); +GLAPI void APIENTRY glCompressedTexSubImage1DARB (GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const GLvoid *data); +GLAPI void APIENTRY glGetCompressedTexImageARB (GLenum target, GLint level, GLvoid *img); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE3DARBPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE2DARBPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE1DARBPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE3DARBPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE2DARBPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE1DARBPROC) (GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLGETCOMPRESSEDTEXIMAGEARBPROC) (GLenum target, GLint level, GLvoid *img); +#endif + +#ifndef GL_ARB_texture_border_clamp +#define GL_ARB_texture_border_clamp 1 +#endif + +#ifndef GL_ARB_point_parameters +#define GL_ARB_point_parameters 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glPointParameterfARB (GLenum pname, GLfloat param); +GLAPI void APIENTRY glPointParameterfvARB (GLenum pname, const GLfloat *params); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPOINTPARAMETERFARBPROC) (GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLPOINTPARAMETERFVARBPROC) (GLenum pname, const GLfloat *params); +#endif + +#ifndef GL_ARB_vertex_blend +#define GL_ARB_vertex_blend 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glWeightbvARB (GLint size, const GLbyte *weights); +GLAPI void APIENTRY glWeightsvARB (GLint size, const GLshort *weights); +GLAPI void APIENTRY glWeightivARB (GLint size, const GLint *weights); +GLAPI void APIENTRY glWeightfvARB (GLint size, const GLfloat *weights); +GLAPI void APIENTRY glWeightdvARB (GLint size, const GLdouble *weights); +GLAPI void APIENTRY glWeightubvARB (GLint size, const GLubyte *weights); +GLAPI void APIENTRY glWeightusvARB (GLint size, const GLushort *weights); +GLAPI void APIENTRY glWeightuivARB (GLint size, const GLuint *weights); +GLAPI void APIENTRY glWeightPointerARB (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +GLAPI void APIENTRY glVertexBlendARB (GLint count); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLWEIGHTBVARBPROC) (GLint size, const GLbyte *weights); +typedef void (APIENTRYP PFNGLWEIGHTSVARBPROC) (GLint size, const GLshort *weights); +typedef void (APIENTRYP PFNGLWEIGHTIVARBPROC) (GLint size, const GLint *weights); +typedef void (APIENTRYP PFNGLWEIGHTFVARBPROC) (GLint size, const GLfloat *weights); +typedef void (APIENTRYP PFNGLWEIGHTDVARBPROC) (GLint size, const GLdouble *weights); +typedef void (APIENTRYP PFNGLWEIGHTUBVARBPROC) (GLint size, const GLubyte *weights); +typedef void (APIENTRYP PFNGLWEIGHTUSVARBPROC) (GLint size, const GLushort *weights); +typedef void (APIENTRYP PFNGLWEIGHTUIVARBPROC) (GLint size, const GLuint *weights); +typedef void (APIENTRYP PFNGLWEIGHTPOINTERARBPROC) (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +typedef void (APIENTRYP PFNGLVERTEXBLENDARBPROC) (GLint count); +#endif + +#ifndef GL_ARB_matrix_palette +#define GL_ARB_matrix_palette 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glCurrentPaletteMatrixARB (GLint index); +GLAPI void APIENTRY glMatrixIndexubvARB (GLint size, const GLubyte *indices); +GLAPI void APIENTRY glMatrixIndexusvARB (GLint size, const GLushort *indices); +GLAPI void APIENTRY glMatrixIndexuivARB (GLint size, const GLuint *indices); +GLAPI void APIENTRY glMatrixIndexPointerARB (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCURRENTPALETTEMATRIXARBPROC) (GLint index); +typedef void (APIENTRYP PFNGLMATRIXINDEXUBVARBPROC) (GLint size, const GLubyte *indices); +typedef void (APIENTRYP PFNGLMATRIXINDEXUSVARBPROC) (GLint size, const GLushort *indices); +typedef void (APIENTRYP PFNGLMATRIXINDEXUIVARBPROC) (GLint size, const GLuint *indices); +typedef void (APIENTRYP PFNGLMATRIXINDEXPOINTERARBPROC) (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +#endif + +#ifndef GL_ARB_texture_env_combine +#define GL_ARB_texture_env_combine 1 +#endif + +#ifndef GL_ARB_texture_env_crossbar +#define GL_ARB_texture_env_crossbar 1 +#endif + +#ifndef GL_ARB_texture_env_dot3 +#define GL_ARB_texture_env_dot3 1 +#endif + +#ifndef GL_ARB_texture_mirrored_repeat +#define GL_ARB_texture_mirrored_repeat 1 +#endif + +#ifndef GL_ARB_depth_texture +#define GL_ARB_depth_texture 1 +#endif + +#ifndef GL_ARB_shadow +#define GL_ARB_shadow 1 +#endif + +#ifndef GL_ARB_shadow_ambient +#define GL_ARB_shadow_ambient 1 +#endif + +#ifndef GL_ARB_window_pos +#define GL_ARB_window_pos 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glWindowPos2dARB (GLdouble x, GLdouble y); +GLAPI void APIENTRY glWindowPos2dvARB (const GLdouble *v); +GLAPI void APIENTRY glWindowPos2fARB (GLfloat x, GLfloat y); +GLAPI void APIENTRY glWindowPos2fvARB (const GLfloat *v); +GLAPI void APIENTRY glWindowPos2iARB (GLint x, GLint y); +GLAPI void APIENTRY glWindowPos2ivARB (const GLint *v); +GLAPI void APIENTRY glWindowPos2sARB (GLshort x, GLshort y); +GLAPI void APIENTRY glWindowPos2svARB (const GLshort *v); +GLAPI void APIENTRY glWindowPos3dARB (GLdouble x, GLdouble y, GLdouble z); +GLAPI void APIENTRY glWindowPos3dvARB (const GLdouble *v); +GLAPI void APIENTRY glWindowPos3fARB (GLfloat x, GLfloat y, GLfloat z); +GLAPI void APIENTRY glWindowPos3fvARB (const GLfloat *v); +GLAPI void APIENTRY glWindowPos3iARB (GLint x, GLint y, GLint z); +GLAPI void APIENTRY glWindowPos3ivARB (const GLint *v); +GLAPI void APIENTRY glWindowPos3sARB (GLshort x, GLshort y, GLshort z); +GLAPI void APIENTRY glWindowPos3svARB (const GLshort *v); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLWINDOWPOS2DARBPROC) (GLdouble x, GLdouble y); +typedef void (APIENTRYP PFNGLWINDOWPOS2DVARBPROC) (const GLdouble *v); +typedef void (APIENTRYP PFNGLWINDOWPOS2FARBPROC) (GLfloat x, GLfloat y); +typedef void (APIENTRYP PFNGLWINDOWPOS2FVARBPROC) (const GLfloat *v); +typedef void (APIENTRYP PFNGLWINDOWPOS2IARBPROC) (GLint x, GLint y); +typedef void (APIENTRYP PFNGLWINDOWPOS2IVARBPROC) (const GLint *v); +typedef void (APIENTRYP PFNGLWINDOWPOS2SARBPROC) (GLshort x, GLshort y); +typedef void (APIENTRYP PFNGLWINDOWPOS2SVARBPROC) (const GLshort *v); +typedef void (APIENTRYP PFNGLWINDOWPOS3DARBPROC) (GLdouble x, GLdouble y, GLdouble z); +typedef void (APIENTRYP PFNGLWINDOWPOS3DVARBPROC) (const GLdouble *v); +typedef void (APIENTRYP PFNGLWINDOWPOS3FARBPROC) (GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLWINDOWPOS3FVARBPROC) (const GLfloat *v); +typedef void (APIENTRYP PFNGLWINDOWPOS3IARBPROC) (GLint x, GLint y, GLint z); +typedef void (APIENTRYP PFNGLWINDOWPOS3IVARBPROC) (const GLint *v); +typedef void (APIENTRYP PFNGLWINDOWPOS3SARBPROC) (GLshort x, GLshort y, GLshort z); +typedef void (APIENTRYP PFNGLWINDOWPOS3SVARBPROC) (const GLshort *v); +#endif + +#ifndef GL_ARB_vertex_program +#define GL_ARB_vertex_program 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glVertexAttrib1dARB (GLuint index, GLdouble x); +GLAPI void APIENTRY glVertexAttrib1dvARB (GLuint index, const GLdouble *v); +GLAPI void APIENTRY glVertexAttrib1fARB (GLuint index, GLfloat x); +GLAPI void APIENTRY glVertexAttrib1fvARB (GLuint index, const GLfloat *v); +GLAPI void APIENTRY glVertexAttrib1sARB (GLuint index, GLshort x); +GLAPI void APIENTRY glVertexAttrib1svARB (GLuint index, const GLshort *v); +GLAPI void APIENTRY glVertexAttrib2dARB (GLuint index, GLdouble x, GLdouble y); +GLAPI void APIENTRY glVertexAttrib2dvARB (GLuint index, const GLdouble *v); +GLAPI void APIENTRY glVertexAttrib2fARB (GLuint index, GLfloat x, GLfloat y); +GLAPI void APIENTRY glVertexAttrib2fvARB (GLuint index, const GLfloat *v); +GLAPI void APIENTRY glVertexAttrib2sARB (GLuint index, GLshort x, GLshort y); +GLAPI void APIENTRY glVertexAttrib2svARB (GLuint index, const GLshort *v); +GLAPI void APIENTRY glVertexAttrib3dARB (GLuint index, GLdouble x, GLdouble y, GLdouble z); +GLAPI void APIENTRY glVertexAttrib3dvARB (GLuint index, const GLdouble *v); +GLAPI void APIENTRY glVertexAttrib3fARB (GLuint index, GLfloat x, GLfloat y, GLfloat z); +GLAPI void APIENTRY glVertexAttrib3fvARB (GLuint index, const GLfloat *v); +GLAPI void APIENTRY glVertexAttrib3sARB (GLuint index, GLshort x, GLshort y, GLshort z); +GLAPI void APIENTRY glVertexAttrib3svARB (GLuint index, const GLshort *v); +GLAPI void APIENTRY glVertexAttrib4NbvARB (GLuint index, const GLbyte *v); +GLAPI void APIENTRY glVertexAttrib4NivARB (GLuint index, const GLint *v); +GLAPI void APIENTRY glVertexAttrib4NsvARB (GLuint index, const GLshort *v); +GLAPI void APIENTRY glVertexAttrib4NubARB (GLuint index, GLubyte x, GLubyte y, GLubyte z, GLubyte w); +GLAPI void APIENTRY glVertexAttrib4NubvARB (GLuint index, const GLubyte *v); +GLAPI void APIENTRY glVertexAttrib4NuivARB (GLuint index, const GLuint *v); +GLAPI void APIENTRY glVertexAttrib4NusvARB (GLuint index, const GLushort *v); +GLAPI void APIENTRY glVertexAttrib4bvARB (GLuint index, const GLbyte *v); +GLAPI void APIENTRY glVertexAttrib4dARB (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +GLAPI void APIENTRY glVertexAttrib4dvARB (GLuint index, const GLdouble *v); +GLAPI void APIENTRY glVertexAttrib4fARB (GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +GLAPI void APIENTRY glVertexAttrib4fvARB (GLuint index, const GLfloat *v); +GLAPI void APIENTRY glVertexAttrib4ivARB (GLuint index, const GLint *v); +GLAPI void APIENTRY glVertexAttrib4sARB (GLuint index, GLshort x, GLshort y, GLshort z, GLshort w); +GLAPI void APIENTRY glVertexAttrib4svARB (GLuint index, const GLshort *v); +GLAPI void APIENTRY glVertexAttrib4ubvARB (GLuint index, const GLubyte *v); +GLAPI void APIENTRY glVertexAttrib4uivARB (GLuint index, const GLuint *v); +GLAPI void APIENTRY glVertexAttrib4usvARB (GLuint index, const GLushort *v); +GLAPI void APIENTRY glVertexAttribPointerARB (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid *pointer); +GLAPI void APIENTRY glEnableVertexAttribArrayARB (GLuint index); +GLAPI void APIENTRY glDisableVertexAttribArrayARB (GLuint index); +GLAPI void APIENTRY glProgramStringARB (GLenum target, GLenum format, GLsizei len, const GLvoid *string); +GLAPI void APIENTRY glBindProgramARB (GLenum target, GLuint program); +GLAPI void APIENTRY glDeleteProgramsARB (GLsizei n, const GLuint *programs); +GLAPI void APIENTRY glGenProgramsARB (GLsizei n, GLuint *programs); +GLAPI void APIENTRY glProgramEnvParameter4dARB (GLenum target, GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +GLAPI void APIENTRY glProgramEnvParameter4dvARB (GLenum target, GLuint index, const GLdouble *params); +GLAPI void APIENTRY glProgramEnvParameter4fARB (GLenum target, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +GLAPI void APIENTRY glProgramEnvParameter4fvARB (GLenum target, GLuint index, const GLfloat *params); +GLAPI void APIENTRY glProgramLocalParameter4dARB (GLenum target, GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +GLAPI void APIENTRY glProgramLocalParameter4dvARB (GLenum target, GLuint index, const GLdouble *params); +GLAPI void APIENTRY glProgramLocalParameter4fARB (GLenum target, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +GLAPI void APIENTRY glProgramLocalParameter4fvARB (GLenum target, GLuint index, const GLfloat *params); +GLAPI void APIENTRY glGetProgramEnvParameterdvARB (GLenum target, GLuint index, GLdouble *params); +GLAPI void APIENTRY glGetProgramEnvParameterfvARB (GLenum target, GLuint index, GLfloat *params); +GLAPI void APIENTRY glGetProgramLocalParameterdvARB (GLenum target, GLuint index, GLdouble *params); +GLAPI void APIENTRY glGetProgramLocalParameterfvARB (GLenum target, GLuint index, GLfloat *params); +GLAPI void APIENTRY glGetProgramivARB (GLenum target, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetProgramStringARB (GLenum target, GLenum pname, GLvoid *string); +GLAPI void APIENTRY glGetVertexAttribdvARB (GLuint index, GLenum pname, GLdouble *params); +GLAPI void APIENTRY glGetVertexAttribfvARB (GLuint index, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetVertexAttribivARB (GLuint index, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetVertexAttribPointervARB (GLuint index, GLenum pname, GLvoid* *pointer); +GLAPI GLboolean APIENTRY glIsProgramARB (GLuint program); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLVERTEXATTRIB1DARBPROC) (GLuint index, GLdouble x); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1DVARBPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1FARBPROC) (GLuint index, GLfloat x); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1FVARBPROC) (GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1SARBPROC) (GLuint index, GLshort x); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1SVARBPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2DARBPROC) (GLuint index, GLdouble x, GLdouble y); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2DVARBPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2FARBPROC) (GLuint index, GLfloat x, GLfloat y); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2FVARBPROC) (GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2SARBPROC) (GLuint index, GLshort x, GLshort y); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2SVARBPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3DARBPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3DVARBPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3FARBPROC) (GLuint index, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3FVARBPROC) (GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3SARBPROC) (GLuint index, GLshort x, GLshort y, GLshort z); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3SVARBPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NBVARBPROC) (GLuint index, const GLbyte *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NIVARBPROC) (GLuint index, const GLint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NSVARBPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUBARBPROC) (GLuint index, GLubyte x, GLubyte y, GLubyte z, GLubyte w); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUBVARBPROC) (GLuint index, const GLubyte *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUIVARBPROC) (GLuint index, const GLuint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUSVARBPROC) (GLuint index, const GLushort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4BVARBPROC) (GLuint index, const GLbyte *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4DARBPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4DVARBPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4FARBPROC) (GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4FVARBPROC) (GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4IVARBPROC) (GLuint index, const GLint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4SARBPROC) (GLuint index, GLshort x, GLshort y, GLshort z, GLshort w); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4SVARBPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4UBVARBPROC) (GLuint index, const GLubyte *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4UIVARBPROC) (GLuint index, const GLuint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4USVARBPROC) (GLuint index, const GLushort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBPOINTERARBPROC) (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid *pointer); +typedef void (APIENTRYP PFNGLENABLEVERTEXATTRIBARRAYARBPROC) (GLuint index); +typedef void (APIENTRYP PFNGLDISABLEVERTEXATTRIBARRAYARBPROC) (GLuint index); +typedef void (APIENTRYP PFNGLPROGRAMSTRINGARBPROC) (GLenum target, GLenum format, GLsizei len, const GLvoid *string); +typedef void (APIENTRYP PFNGLBINDPROGRAMARBPROC) (GLenum target, GLuint program); +typedef void (APIENTRYP PFNGLDELETEPROGRAMSARBPROC) (GLsizei n, const GLuint *programs); +typedef void (APIENTRYP PFNGLGENPROGRAMSARBPROC) (GLsizei n, GLuint *programs); +typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETER4DARBPROC) (GLenum target, GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETER4DVARBPROC) (GLenum target, GLuint index, const GLdouble *params); +typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETER4FARBPROC) (GLenum target, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETER4FVARBPROC) (GLenum target, GLuint index, const GLfloat *params); +typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETER4DARBPROC) (GLenum target, GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETER4DVARBPROC) (GLenum target, GLuint index, const GLdouble *params); +typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETER4FARBPROC) (GLenum target, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETER4FVARBPROC) (GLenum target, GLuint index, const GLfloat *params); +typedef void (APIENTRYP PFNGLGETPROGRAMENVPARAMETERDVARBPROC) (GLenum target, GLuint index, GLdouble *params); +typedef void (APIENTRYP PFNGLGETPROGRAMENVPARAMETERFVARBPROC) (GLenum target, GLuint index, GLfloat *params); +typedef void (APIENTRYP PFNGLGETPROGRAMLOCALPARAMETERDVARBPROC) (GLenum target, GLuint index, GLdouble *params); +typedef void (APIENTRYP PFNGLGETPROGRAMLOCALPARAMETERFVARBPROC) (GLenum target, GLuint index, GLfloat *params); +typedef void (APIENTRYP PFNGLGETPROGRAMIVARBPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETPROGRAMSTRINGARBPROC) (GLenum target, GLenum pname, GLvoid *string); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBDVARBPROC) (GLuint index, GLenum pname, GLdouble *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBFVARBPROC) (GLuint index, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIVARBPROC) (GLuint index, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBPOINTERVARBPROC) (GLuint index, GLenum pname, GLvoid* *pointer); +typedef GLboolean (APIENTRYP PFNGLISPROGRAMARBPROC) (GLuint program); +#endif + +#ifndef GL_ARB_fragment_program +#define GL_ARB_fragment_program 1 +/* All ARB_fragment_program entry points are shared with ARB_vertex_program. */ +#endif + +#ifndef GL_ARB_vertex_buffer_object +#define GL_ARB_vertex_buffer_object 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBindBufferARB (GLenum target, GLuint buffer); +GLAPI void APIENTRY glDeleteBuffersARB (GLsizei n, const GLuint *buffers); +GLAPI void APIENTRY glGenBuffersARB (GLsizei n, GLuint *buffers); +GLAPI GLboolean APIENTRY glIsBufferARB (GLuint buffer); +GLAPI void APIENTRY glBufferDataARB (GLenum target, GLsizeiptrARB size, const GLvoid *data, GLenum usage); +GLAPI void APIENTRY glBufferSubDataARB (GLenum target, GLintptrARB offset, GLsizeiptrARB size, const GLvoid *data); +GLAPI void APIENTRY glGetBufferSubDataARB (GLenum target, GLintptrARB offset, GLsizeiptrARB size, GLvoid *data); +GLAPI GLvoid* APIENTRY glMapBufferARB (GLenum target, GLenum access); +GLAPI GLboolean APIENTRY glUnmapBufferARB (GLenum target); +GLAPI void APIENTRY glGetBufferParameterivARB (GLenum target, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetBufferPointervARB (GLenum target, GLenum pname, GLvoid* *params); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBINDBUFFERARBPROC) (GLenum target, GLuint buffer); +typedef void (APIENTRYP PFNGLDELETEBUFFERSARBPROC) (GLsizei n, const GLuint *buffers); +typedef void (APIENTRYP PFNGLGENBUFFERSARBPROC) (GLsizei n, GLuint *buffers); +typedef GLboolean (APIENTRYP PFNGLISBUFFERARBPROC) (GLuint buffer); +typedef void (APIENTRYP PFNGLBUFFERDATAARBPROC) (GLenum target, GLsizeiptrARB size, const GLvoid *data, GLenum usage); +typedef void (APIENTRYP PFNGLBUFFERSUBDATAARBPROC) (GLenum target, GLintptrARB offset, GLsizeiptrARB size, const GLvoid *data); +typedef void (APIENTRYP PFNGLGETBUFFERSUBDATAARBPROC) (GLenum target, GLintptrARB offset, GLsizeiptrARB size, GLvoid *data); +typedef GLvoid* (APIENTRYP PFNGLMAPBUFFERARBPROC) (GLenum target, GLenum access); +typedef GLboolean (APIENTRYP PFNGLUNMAPBUFFERARBPROC) (GLenum target); +typedef void (APIENTRYP PFNGLGETBUFFERPARAMETERIVARBPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETBUFFERPOINTERVARBPROC) (GLenum target, GLenum pname, GLvoid* *params); +#endif + +#ifndef GL_ARB_occlusion_query +#define GL_ARB_occlusion_query 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glGenQueriesARB (GLsizei n, GLuint *ids); +GLAPI void APIENTRY glDeleteQueriesARB (GLsizei n, const GLuint *ids); +GLAPI GLboolean APIENTRY glIsQueryARB (GLuint id); +GLAPI void APIENTRY glBeginQueryARB (GLenum target, GLuint id); +GLAPI void APIENTRY glEndQueryARB (GLenum target); +GLAPI void APIENTRY glGetQueryivARB (GLenum target, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetQueryObjectivARB (GLuint id, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetQueryObjectuivARB (GLuint id, GLenum pname, GLuint *params); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGENQUERIESARBPROC) (GLsizei n, GLuint *ids); +typedef void (APIENTRYP PFNGLDELETEQUERIESARBPROC) (GLsizei n, const GLuint *ids); +typedef GLboolean (APIENTRYP PFNGLISQUERYARBPROC) (GLuint id); +typedef void (APIENTRYP PFNGLBEGINQUERYARBPROC) (GLenum target, GLuint id); +typedef void (APIENTRYP PFNGLENDQUERYARBPROC) (GLenum target); +typedef void (APIENTRYP PFNGLGETQUERYIVARBPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETQUERYOBJECTIVARBPROC) (GLuint id, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETQUERYOBJECTUIVARBPROC) (GLuint id, GLenum pname, GLuint *params); +#endif + +#ifndef GL_ARB_shader_objects +#define GL_ARB_shader_objects 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDeleteObjectARB (GLhandleARB obj); +GLAPI GLhandleARB APIENTRY glGetHandleARB (GLenum pname); +GLAPI void APIENTRY glDetachObjectARB (GLhandleARB containerObj, GLhandleARB attachedObj); +GLAPI GLhandleARB APIENTRY glCreateShaderObjectARB (GLenum shaderType); +GLAPI void APIENTRY glShaderSourceARB (GLhandleARB shaderObj, GLsizei count, const GLcharARB* *string, const GLint *length); +GLAPI void APIENTRY glCompileShaderARB (GLhandleARB shaderObj); +GLAPI GLhandleARB APIENTRY glCreateProgramObjectARB (void); +GLAPI void APIENTRY glAttachObjectARB (GLhandleARB containerObj, GLhandleARB obj); +GLAPI void APIENTRY glLinkProgramARB (GLhandleARB programObj); +GLAPI void APIENTRY glUseProgramObjectARB (GLhandleARB programObj); +GLAPI void APIENTRY glValidateProgramARB (GLhandleARB programObj); +GLAPI void APIENTRY glUniform1fARB (GLint location, GLfloat v0); +GLAPI void APIENTRY glUniform2fARB (GLint location, GLfloat v0, GLfloat v1); +GLAPI void APIENTRY glUniform3fARB (GLint location, GLfloat v0, GLfloat v1, GLfloat v2); +GLAPI void APIENTRY glUniform4fARB (GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3); +GLAPI void APIENTRY glUniform1iARB (GLint location, GLint v0); +GLAPI void APIENTRY glUniform2iARB (GLint location, GLint v0, GLint v1); +GLAPI void APIENTRY glUniform3iARB (GLint location, GLint v0, GLint v1, GLint v2); +GLAPI void APIENTRY glUniform4iARB (GLint location, GLint v0, GLint v1, GLint v2, GLint v3); +GLAPI void APIENTRY glUniform1fvARB (GLint location, GLsizei count, const GLfloat *value); +GLAPI void APIENTRY glUniform2fvARB (GLint location, GLsizei count, const GLfloat *value); +GLAPI void APIENTRY glUniform3fvARB (GLint location, GLsizei count, const GLfloat *value); +GLAPI void APIENTRY glUniform4fvARB (GLint location, GLsizei count, const GLfloat *value); +GLAPI void APIENTRY glUniform1ivARB (GLint location, GLsizei count, const GLint *value); +GLAPI void APIENTRY glUniform2ivARB (GLint location, GLsizei count, const GLint *value); +GLAPI void APIENTRY glUniform3ivARB (GLint location, GLsizei count, const GLint *value); +GLAPI void APIENTRY glUniform4ivARB (GLint location, GLsizei count, const GLint *value); +GLAPI void APIENTRY glUniformMatrix2fvARB (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glUniformMatrix3fvARB (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glUniformMatrix4fvARB (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glGetObjectParameterfvARB (GLhandleARB obj, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetObjectParameterivARB (GLhandleARB obj, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetInfoLogARB (GLhandleARB obj, GLsizei maxLength, GLsizei *length, GLcharARB *infoLog); +GLAPI void APIENTRY glGetAttachedObjectsARB (GLhandleARB containerObj, GLsizei maxCount, GLsizei *count, GLhandleARB *obj); +GLAPI GLint APIENTRY glGetUniformLocationARB (GLhandleARB programObj, const GLcharARB *name); +GLAPI void APIENTRY glGetActiveUniformARB (GLhandleARB programObj, GLuint index, GLsizei maxLength, GLsizei *length, GLint *size, GLenum *type, GLcharARB *name); +GLAPI void APIENTRY glGetUniformfvARB (GLhandleARB programObj, GLint location, GLfloat *params); +GLAPI void APIENTRY glGetUniformivARB (GLhandleARB programObj, GLint location, GLint *params); +GLAPI void APIENTRY glGetShaderSourceARB (GLhandleARB obj, GLsizei maxLength, GLsizei *length, GLcharARB *source); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDELETEOBJECTARBPROC) (GLhandleARB obj); +typedef GLhandleARB (APIENTRYP PFNGLGETHANDLEARBPROC) (GLenum pname); +typedef void (APIENTRYP PFNGLDETACHOBJECTARBPROC) (GLhandleARB containerObj, GLhandleARB attachedObj); +typedef GLhandleARB (APIENTRYP PFNGLCREATESHADEROBJECTARBPROC) (GLenum shaderType); +typedef void (APIENTRYP PFNGLSHADERSOURCEARBPROC) (GLhandleARB shaderObj, GLsizei count, const GLcharARB* *string, const GLint *length); +typedef void (APIENTRYP PFNGLCOMPILESHADERARBPROC) (GLhandleARB shaderObj); +typedef GLhandleARB (APIENTRYP PFNGLCREATEPROGRAMOBJECTARBPROC) (void); +typedef void (APIENTRYP PFNGLATTACHOBJECTARBPROC) (GLhandleARB containerObj, GLhandleARB obj); +typedef void (APIENTRYP PFNGLLINKPROGRAMARBPROC) (GLhandleARB programObj); +typedef void (APIENTRYP PFNGLUSEPROGRAMOBJECTARBPROC) (GLhandleARB programObj); +typedef void (APIENTRYP PFNGLVALIDATEPROGRAMARBPROC) (GLhandleARB programObj); +typedef void (APIENTRYP PFNGLUNIFORM1FARBPROC) (GLint location, GLfloat v0); +typedef void (APIENTRYP PFNGLUNIFORM2FARBPROC) (GLint location, GLfloat v0, GLfloat v1); +typedef void (APIENTRYP PFNGLUNIFORM3FARBPROC) (GLint location, GLfloat v0, GLfloat v1, GLfloat v2); +typedef void (APIENTRYP PFNGLUNIFORM4FARBPROC) (GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3); +typedef void (APIENTRYP PFNGLUNIFORM1IARBPROC) (GLint location, GLint v0); +typedef void (APIENTRYP PFNGLUNIFORM2IARBPROC) (GLint location, GLint v0, GLint v1); +typedef void (APIENTRYP PFNGLUNIFORM3IARBPROC) (GLint location, GLint v0, GLint v1, GLint v2); +typedef void (APIENTRYP PFNGLUNIFORM4IARBPROC) (GLint location, GLint v0, GLint v1, GLint v2, GLint v3); +typedef void (APIENTRYP PFNGLUNIFORM1FVARBPROC) (GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORM2FVARBPROC) (GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORM3FVARBPROC) (GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORM4FVARBPROC) (GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORM1IVARBPROC) (GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLUNIFORM2IVARBPROC) (GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLUNIFORM3IVARBPROC) (GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLUNIFORM4IVARBPROC) (GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX2FVARBPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX3FVARBPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX4FVARBPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLGETOBJECTPARAMETERFVARBPROC) (GLhandleARB obj, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETOBJECTPARAMETERIVARBPROC) (GLhandleARB obj, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETINFOLOGARBPROC) (GLhandleARB obj, GLsizei maxLength, GLsizei *length, GLcharARB *infoLog); +typedef void (APIENTRYP PFNGLGETATTACHEDOBJECTSARBPROC) (GLhandleARB containerObj, GLsizei maxCount, GLsizei *count, GLhandleARB *obj); +typedef GLint (APIENTRYP PFNGLGETUNIFORMLOCATIONARBPROC) (GLhandleARB programObj, const GLcharARB *name); +typedef void (APIENTRYP PFNGLGETACTIVEUNIFORMARBPROC) (GLhandleARB programObj, GLuint index, GLsizei maxLength, GLsizei *length, GLint *size, GLenum *type, GLcharARB *name); +typedef void (APIENTRYP PFNGLGETUNIFORMFVARBPROC) (GLhandleARB programObj, GLint location, GLfloat *params); +typedef void (APIENTRYP PFNGLGETUNIFORMIVARBPROC) (GLhandleARB programObj, GLint location, GLint *params); +typedef void (APIENTRYP PFNGLGETSHADERSOURCEARBPROC) (GLhandleARB obj, GLsizei maxLength, GLsizei *length, GLcharARB *source); +#endif + +#ifndef GL_ARB_vertex_shader +#define GL_ARB_vertex_shader 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBindAttribLocationARB (GLhandleARB programObj, GLuint index, const GLcharARB *name); +GLAPI void APIENTRY glGetActiveAttribARB (GLhandleARB programObj, GLuint index, GLsizei maxLength, GLsizei *length, GLint *size, GLenum *type, GLcharARB *name); +GLAPI GLint APIENTRY glGetAttribLocationARB (GLhandleARB programObj, const GLcharARB *name); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBINDATTRIBLOCATIONARBPROC) (GLhandleARB programObj, GLuint index, const GLcharARB *name); +typedef void (APIENTRYP PFNGLGETACTIVEATTRIBARBPROC) (GLhandleARB programObj, GLuint index, GLsizei maxLength, GLsizei *length, GLint *size, GLenum *type, GLcharARB *name); +typedef GLint (APIENTRYP PFNGLGETATTRIBLOCATIONARBPROC) (GLhandleARB programObj, const GLcharARB *name); +#endif + +#ifndef GL_ARB_fragment_shader +#define GL_ARB_fragment_shader 1 +#endif + +#ifndef GL_ARB_shading_language_100 +#define GL_ARB_shading_language_100 1 +#endif + +#ifndef GL_ARB_texture_non_power_of_two +#define GL_ARB_texture_non_power_of_two 1 +#endif + +#ifndef GL_ARB_point_sprite +#define GL_ARB_point_sprite 1 +#endif + +#ifndef GL_ARB_fragment_program_shadow +#define GL_ARB_fragment_program_shadow 1 +#endif + +#ifndef GL_ARB_draw_buffers +#define GL_ARB_draw_buffers 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDrawBuffersARB (GLsizei n, const GLenum *bufs); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDRAWBUFFERSARBPROC) (GLsizei n, const GLenum *bufs); +#endif + +#ifndef GL_ARB_texture_rectangle +#define GL_ARB_texture_rectangle 1 +#endif + +#ifndef GL_ARB_color_buffer_float +#define GL_ARB_color_buffer_float 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glClampColorARB (GLenum target, GLenum clamp); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCLAMPCOLORARBPROC) (GLenum target, GLenum clamp); +#endif + +#ifndef GL_ARB_half_float_pixel +#define GL_ARB_half_float_pixel 1 +#endif + +#ifndef GL_ARB_texture_float +#define GL_ARB_texture_float 1 +#endif + +#ifndef GL_ARB_pixel_buffer_object +#define GL_ARB_pixel_buffer_object 1 +#endif + +#ifndef GL_ARB_depth_buffer_float +#define GL_ARB_depth_buffer_float 1 +#endif + +#ifndef GL_ARB_draw_instanced +#define GL_ARB_draw_instanced 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDrawArraysInstancedARB (GLenum mode, GLint first, GLsizei count, GLsizei primcount); +GLAPI void APIENTRY glDrawElementsInstancedARB (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei primcount); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDRAWARRAYSINSTANCEDARBPROC) (GLenum mode, GLint first, GLsizei count, GLsizei primcount); +typedef void (APIENTRYP PFNGLDRAWELEMENTSINSTANCEDARBPROC) (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei primcount); +#endif + +#ifndef GL_ARB_framebuffer_object +#define GL_ARB_framebuffer_object 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI GLboolean APIENTRY glIsRenderbuffer (GLuint renderbuffer); +GLAPI void APIENTRY glBindRenderbuffer (GLenum target, GLuint renderbuffer); +GLAPI void APIENTRY glDeleteRenderbuffers (GLsizei n, const GLuint *renderbuffers); +GLAPI void APIENTRY glGenRenderbuffers (GLsizei n, GLuint *renderbuffers); +GLAPI void APIENTRY glRenderbufferStorage (GLenum target, GLenum internalformat, GLsizei width, GLsizei height); +GLAPI void APIENTRY glGetRenderbufferParameteriv (GLenum target, GLenum pname, GLint *params); +GLAPI GLboolean APIENTRY glIsFramebuffer (GLuint framebuffer); +GLAPI void APIENTRY glBindFramebuffer (GLenum target, GLuint framebuffer); +GLAPI void APIENTRY glDeleteFramebuffers (GLsizei n, const GLuint *framebuffers); +GLAPI void APIENTRY glGenFramebuffers (GLsizei n, GLuint *framebuffers); +GLAPI GLenum APIENTRY glCheckFramebufferStatus (GLenum target); +GLAPI void APIENTRY glFramebufferTexture1D (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); +GLAPI void APIENTRY glFramebufferTexture2D (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); +GLAPI void APIENTRY glFramebufferTexture3D (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset); +GLAPI void APIENTRY glFramebufferRenderbuffer (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer); +GLAPI void APIENTRY glGetFramebufferAttachmentParameteriv (GLenum target, GLenum attachment, GLenum pname, GLint *params); +GLAPI void APIENTRY glGenerateMipmap (GLenum target); +GLAPI void APIENTRY glBlitFramebuffer (GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter); +GLAPI void APIENTRY glRenderbufferStorageMultisample (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height); +GLAPI void APIENTRY glFramebufferTextureLayer (GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef GLboolean (APIENTRYP PFNGLISRENDERBUFFERPROC) (GLuint renderbuffer); +typedef void (APIENTRYP PFNGLBINDRENDERBUFFERPROC) (GLenum target, GLuint renderbuffer); +typedef void (APIENTRYP PFNGLDELETERENDERBUFFERSPROC) (GLsizei n, const GLuint *renderbuffers); +typedef void (APIENTRYP PFNGLGENRENDERBUFFERSPROC) (GLsizei n, GLuint *renderbuffers); +typedef void (APIENTRYP PFNGLRENDERBUFFERSTORAGEPROC) (GLenum target, GLenum internalformat, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLGETRENDERBUFFERPARAMETERIVPROC) (GLenum target, GLenum pname, GLint *params); +typedef GLboolean (APIENTRYP PFNGLISFRAMEBUFFERPROC) (GLuint framebuffer); +typedef void (APIENTRYP PFNGLBINDFRAMEBUFFERPROC) (GLenum target, GLuint framebuffer); +typedef void (APIENTRYP PFNGLDELETEFRAMEBUFFERSPROC) (GLsizei n, const GLuint *framebuffers); +typedef void (APIENTRYP PFNGLGENFRAMEBUFFERSPROC) (GLsizei n, GLuint *framebuffers); +typedef GLenum (APIENTRYP PFNGLCHECKFRAMEBUFFERSTATUSPROC) (GLenum target); +typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURE1DPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); +typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURE2DPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); +typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURE3DPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset); +typedef void (APIENTRYP PFNGLFRAMEBUFFERRENDERBUFFERPROC) (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer); +typedef void (APIENTRYP PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVPROC) (GLenum target, GLenum attachment, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGENERATEMIPMAPPROC) (GLenum target); +typedef void (APIENTRYP PFNGLBLITFRAMEBUFFERPROC) (GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter); +typedef void (APIENTRYP PFNGLRENDERBUFFERSTORAGEMULTISAMPLEPROC) (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURELAYERPROC) (GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer); +#endif + +#ifndef GL_ARB_framebuffer_sRGB +#define GL_ARB_framebuffer_sRGB 1 +#endif + +#ifndef GL_ARB_geometry_shader4 +#define GL_ARB_geometry_shader4 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glProgramParameteriARB (GLuint program, GLenum pname, GLint value); +GLAPI void APIENTRY glFramebufferTextureARB (GLenum target, GLenum attachment, GLuint texture, GLint level); +GLAPI void APIENTRY glFramebufferTextureLayerARB (GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer); +GLAPI void APIENTRY glFramebufferTextureFaceARB (GLenum target, GLenum attachment, GLuint texture, GLint level, GLenum face); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPROGRAMPARAMETERIARBPROC) (GLuint program, GLenum pname, GLint value); +typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTUREARBPROC) (GLenum target, GLenum attachment, GLuint texture, GLint level); +typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURELAYERARBPROC) (GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer); +typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTUREFACEARBPROC) (GLenum target, GLenum attachment, GLuint texture, GLint level, GLenum face); +#endif + +#ifndef GL_ARB_half_float_vertex +#define GL_ARB_half_float_vertex 1 +#endif + +#ifndef GL_ARB_instanced_arrays +#define GL_ARB_instanced_arrays 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glVertexAttribDivisorARB (GLuint index, GLuint divisor); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLVERTEXATTRIBDIVISORARBPROC) (GLuint index, GLuint divisor); +#endif + +#ifndef GL_ARB_map_buffer_range +#define GL_ARB_map_buffer_range 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI GLvoid* APIENTRY glMapBufferRange (GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access); +GLAPI void APIENTRY glFlushMappedBufferRange (GLenum target, GLintptr offset, GLsizeiptr length); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef GLvoid* (APIENTRYP PFNGLMAPBUFFERRANGEPROC) (GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access); +typedef void (APIENTRYP PFNGLFLUSHMAPPEDBUFFERRANGEPROC) (GLenum target, GLintptr offset, GLsizeiptr length); +#endif + +#ifndef GL_ARB_texture_buffer_object +#define GL_ARB_texture_buffer_object 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTexBufferARB (GLenum target, GLenum internalformat, GLuint buffer); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLTEXBUFFERARBPROC) (GLenum target, GLenum internalformat, GLuint buffer); +#endif + +#ifndef GL_ARB_texture_compression_rgtc +#define GL_ARB_texture_compression_rgtc 1 +#endif + +#ifndef GL_ARB_texture_rg +#define GL_ARB_texture_rg 1 +#endif + +#ifndef GL_ARB_vertex_array_object +#define GL_ARB_vertex_array_object 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBindVertexArray (GLuint array); +GLAPI void APIENTRY glDeleteVertexArrays (GLsizei n, const GLuint *arrays); +GLAPI void APIENTRY glGenVertexArrays (GLsizei n, GLuint *arrays); +GLAPI GLboolean APIENTRY glIsVertexArray (GLuint array); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBINDVERTEXARRAYPROC) (GLuint array); +typedef void (APIENTRYP PFNGLDELETEVERTEXARRAYSPROC) (GLsizei n, const GLuint *arrays); +typedef void (APIENTRYP PFNGLGENVERTEXARRAYSPROC) (GLsizei n, GLuint *arrays); +typedef GLboolean (APIENTRYP PFNGLISVERTEXARRAYPROC) (GLuint array); +#endif + +#ifndef GL_ARB_uniform_buffer_object +#define GL_ARB_uniform_buffer_object 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glGetUniformIndices (GLuint program, GLsizei uniformCount, const GLchar* *uniformNames, GLuint *uniformIndices); +GLAPI void APIENTRY glGetActiveUniformsiv (GLuint program, GLsizei uniformCount, const GLuint *uniformIndices, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetActiveUniformName (GLuint program, GLuint uniformIndex, GLsizei bufSize, GLsizei *length, GLchar *uniformName); +GLAPI GLuint APIENTRY glGetUniformBlockIndex (GLuint program, const GLchar *uniformBlockName); +GLAPI void APIENTRY glGetActiveUniformBlockiv (GLuint program, GLuint uniformBlockIndex, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetActiveUniformBlockName (GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei *length, GLchar *uniformBlockName); +GLAPI void APIENTRY glUniformBlockBinding (GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGETUNIFORMINDICESPROC) (GLuint program, GLsizei uniformCount, const GLchar* *uniformNames, GLuint *uniformIndices); +typedef void (APIENTRYP PFNGLGETACTIVEUNIFORMSIVPROC) (GLuint program, GLsizei uniformCount, const GLuint *uniformIndices, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETACTIVEUNIFORMNAMEPROC) (GLuint program, GLuint uniformIndex, GLsizei bufSize, GLsizei *length, GLchar *uniformName); +typedef GLuint (APIENTRYP PFNGLGETUNIFORMBLOCKINDEXPROC) (GLuint program, const GLchar *uniformBlockName); +typedef void (APIENTRYP PFNGLGETACTIVEUNIFORMBLOCKIVPROC) (GLuint program, GLuint uniformBlockIndex, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETACTIVEUNIFORMBLOCKNAMEPROC) (GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei *length, GLchar *uniformBlockName); +typedef void (APIENTRYP PFNGLUNIFORMBLOCKBINDINGPROC) (GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding); +#endif + +#ifndef GL_ARB_compatibility +#define GL_ARB_compatibility 1 +#endif + +#ifndef GL_ARB_copy_buffer +#define GL_ARB_copy_buffer 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glCopyBufferSubData (GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCOPYBUFFERSUBDATAPROC) (GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size); +#endif + +#ifndef GL_ARB_shader_texture_lod +#define GL_ARB_shader_texture_lod 1 +#endif + +#ifndef GL_ARB_depth_clamp +#define GL_ARB_depth_clamp 1 +#endif + +#ifndef GL_ARB_draw_elements_base_vertex +#define GL_ARB_draw_elements_base_vertex 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDrawElementsBaseVertex (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLint basevertex); +GLAPI void APIENTRY glDrawRangeElementsBaseVertex (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices, GLint basevertex); +GLAPI void APIENTRY glDrawElementsInstancedBaseVertex (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei primcount, GLint basevertex); +GLAPI void APIENTRY glMultiDrawElementsBaseVertex (GLenum mode, const GLsizei *count, GLenum type, const GLvoid* *indices, GLsizei primcount, const GLint *basevertex); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDRAWELEMENTSBASEVERTEXPROC) (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLint basevertex); +typedef void (APIENTRYP PFNGLDRAWRANGEELEMENTSBASEVERTEXPROC) (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices, GLint basevertex); +typedef void (APIENTRYP PFNGLDRAWELEMENTSINSTANCEDBASEVERTEXPROC) (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei primcount, GLint basevertex); +typedef void (APIENTRYP PFNGLMULTIDRAWELEMENTSBASEVERTEXPROC) (GLenum mode, const GLsizei *count, GLenum type, const GLvoid* *indices, GLsizei primcount, const GLint *basevertex); +#endif + +#ifndef GL_ARB_fragment_coord_conventions +#define GL_ARB_fragment_coord_conventions 1 +#endif + +#ifndef GL_ARB_provoking_vertex +#define GL_ARB_provoking_vertex 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glProvokingVertex (GLenum mode); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPROVOKINGVERTEXPROC) (GLenum mode); +#endif + +#ifndef GL_ARB_seamless_cube_map +#define GL_ARB_seamless_cube_map 1 +#endif + +#ifndef GL_ARB_sync +#define GL_ARB_sync 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI GLsync APIENTRY glFenceSync (GLenum condition, GLbitfield flags); +GLAPI GLboolean APIENTRY glIsSync (GLsync sync); +GLAPI void APIENTRY glDeleteSync (GLsync sync); +GLAPI GLenum APIENTRY glClientWaitSync (GLsync sync, GLbitfield flags, GLuint64 timeout); +GLAPI void APIENTRY glWaitSync (GLsync sync, GLbitfield flags, GLuint64 timeout); +GLAPI void APIENTRY glGetInteger64v (GLenum pname, GLint64 *params); +GLAPI void APIENTRY glGetSynciv (GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef GLsync (APIENTRYP PFNGLFENCESYNCPROC) (GLenum condition, GLbitfield flags); +typedef GLboolean (APIENTRYP PFNGLISSYNCPROC) (GLsync sync); +typedef void (APIENTRYP PFNGLDELETESYNCPROC) (GLsync sync); +typedef GLenum (APIENTRYP PFNGLCLIENTWAITSYNCPROC) (GLsync sync, GLbitfield flags, GLuint64 timeout); +typedef void (APIENTRYP PFNGLWAITSYNCPROC) (GLsync sync, GLbitfield flags, GLuint64 timeout); +typedef void (APIENTRYP PFNGLGETINTEGER64VPROC) (GLenum pname, GLint64 *params); +typedef void (APIENTRYP PFNGLGETSYNCIVPROC) (GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values); +#endif + +#ifndef GL_ARB_texture_multisample +#define GL_ARB_texture_multisample 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTexImage2DMultisample (GLenum target, GLsizei samples, GLint internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations); +GLAPI void APIENTRY glTexImage3DMultisample (GLenum target, GLsizei samples, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedsamplelocations); +GLAPI void APIENTRY glGetMultisamplefv (GLenum pname, GLuint index, GLfloat *val); +GLAPI void APIENTRY glSampleMaski (GLuint index, GLbitfield mask); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLTEXIMAGE2DMULTISAMPLEPROC) (GLenum target, GLsizei samples, GLint internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations); +typedef void (APIENTRYP PFNGLTEXIMAGE3DMULTISAMPLEPROC) (GLenum target, GLsizei samples, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedsamplelocations); +typedef void (APIENTRYP PFNGLGETMULTISAMPLEFVPROC) (GLenum pname, GLuint index, GLfloat *val); +typedef void (APIENTRYP PFNGLSAMPLEMASKIPROC) (GLuint index, GLbitfield mask); +#endif + +#ifndef GL_ARB_vertex_array_bgra +#define GL_ARB_vertex_array_bgra 1 +#endif + +#ifndef GL_ARB_draw_buffers_blend +#define GL_ARB_draw_buffers_blend 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBlendEquationiARB (GLuint buf, GLenum mode); +GLAPI void APIENTRY glBlendEquationSeparateiARB (GLuint buf, GLenum modeRGB, GLenum modeAlpha); +GLAPI void APIENTRY glBlendFunciARB (GLuint buf, GLenum src, GLenum dst); +GLAPI void APIENTRY glBlendFuncSeparateiARB (GLuint buf, GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBLENDEQUATIONIARBPROC) (GLuint buf, GLenum mode); +typedef void (APIENTRYP PFNGLBLENDEQUATIONSEPARATEIARBPROC) (GLuint buf, GLenum modeRGB, GLenum modeAlpha); +typedef void (APIENTRYP PFNGLBLENDFUNCIARBPROC) (GLuint buf, GLenum src, GLenum dst); +typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEIARBPROC) (GLuint buf, GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha); +#endif + +#ifndef GL_ARB_sample_shading +#define GL_ARB_sample_shading 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glMinSampleShadingARB (GLclampf value); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLMINSAMPLESHADINGARBPROC) (GLclampf value); +#endif + +#ifndef GL_ARB_texture_cube_map_array +#define GL_ARB_texture_cube_map_array 1 +#endif + +#ifndef GL_ARB_texture_gather +#define GL_ARB_texture_gather 1 +#endif + +#ifndef GL_ARB_texture_query_lod +#define GL_ARB_texture_query_lod 1 +#endif + +#ifndef GL_ARB_shading_language_include +#define GL_ARB_shading_language_include 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glNamedStringARB (GLenum type, GLint namelen, const GLchar *name, GLint stringlen, const GLchar *string); +GLAPI void APIENTRY glDeleteNamedStringARB (GLint namelen, const GLchar *name); +GLAPI void APIENTRY glCompileShaderIncludeARB (GLuint shader, GLsizei count, const GLchar* *path, const GLint *length); +GLAPI GLboolean APIENTRY glIsNamedStringARB (GLint namelen, const GLchar *name); +GLAPI void APIENTRY glGetNamedStringARB (GLint namelen, const GLchar *name, GLsizei bufSize, GLint *stringlen, GLchar *string); +GLAPI void APIENTRY glGetNamedStringivARB (GLint namelen, const GLchar *name, GLenum pname, GLint *params); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLNAMEDSTRINGARBPROC) (GLenum type, GLint namelen, const GLchar *name, GLint stringlen, const GLchar *string); +typedef void (APIENTRYP PFNGLDELETENAMEDSTRINGARBPROC) (GLint namelen, const GLchar *name); +typedef void (APIENTRYP PFNGLCOMPILESHADERINCLUDEARBPROC) (GLuint shader, GLsizei count, const GLchar* *path, const GLint *length); +typedef GLboolean (APIENTRYP PFNGLISNAMEDSTRINGARBPROC) (GLint namelen, const GLchar *name); +typedef void (APIENTRYP PFNGLGETNAMEDSTRINGARBPROC) (GLint namelen, const GLchar *name, GLsizei bufSize, GLint *stringlen, GLchar *string); +typedef void (APIENTRYP PFNGLGETNAMEDSTRINGIVARBPROC) (GLint namelen, const GLchar *name, GLenum pname, GLint *params); +#endif + +#ifndef GL_ARB_texture_compression_bptc +#define GL_ARB_texture_compression_bptc 1 +#endif + +#ifndef GL_ARB_blend_func_extended +#define GL_ARB_blend_func_extended 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBindFragDataLocationIndexed (GLuint program, GLuint colorNumber, GLuint index, const GLchar *name); +GLAPI GLint APIENTRY glGetFragDataIndex (GLuint program, const GLchar *name); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBINDFRAGDATALOCATIONINDEXEDPROC) (GLuint program, GLuint colorNumber, GLuint index, const GLchar *name); +typedef GLint (APIENTRYP PFNGLGETFRAGDATAINDEXPROC) (GLuint program, const GLchar *name); +#endif + +#ifndef GL_ARB_explicit_attrib_location +#define GL_ARB_explicit_attrib_location 1 +#endif + +#ifndef GL_ARB_occlusion_query2 +#define GL_ARB_occlusion_query2 1 +#endif + +#ifndef GL_ARB_sampler_objects +#define GL_ARB_sampler_objects 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glGenSamplers (GLsizei count, GLuint *samplers); +GLAPI void APIENTRY glDeleteSamplers (GLsizei count, const GLuint *samplers); +GLAPI GLboolean APIENTRY glIsSampler (GLuint sampler); +GLAPI void APIENTRY glBindSampler (GLuint unit, GLuint sampler); +GLAPI void APIENTRY glSamplerParameteri (GLuint sampler, GLenum pname, GLint param); +GLAPI void APIENTRY glSamplerParameteriv (GLuint sampler, GLenum pname, const GLint *param); +GLAPI void APIENTRY glSamplerParameterf (GLuint sampler, GLenum pname, GLfloat param); +GLAPI void APIENTRY glSamplerParameterfv (GLuint sampler, GLenum pname, const GLfloat *param); +GLAPI void APIENTRY glSamplerParameterIiv (GLuint sampler, GLenum pname, const GLint *param); +GLAPI void APIENTRY glSamplerParameterIuiv (GLuint sampler, GLenum pname, const GLuint *param); +GLAPI void APIENTRY glGetSamplerParameteriv (GLuint sampler, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetSamplerParameterIiv (GLuint sampler, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetSamplerParameterfv (GLuint sampler, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetSamplerParameterIuiv (GLuint sampler, GLenum pname, GLuint *params); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGENSAMPLERSPROC) (GLsizei count, GLuint *samplers); +typedef void (APIENTRYP PFNGLDELETESAMPLERSPROC) (GLsizei count, const GLuint *samplers); +typedef GLboolean (APIENTRYP PFNGLISSAMPLERPROC) (GLuint sampler); +typedef void (APIENTRYP PFNGLBINDSAMPLERPROC) (GLuint unit, GLuint sampler); +typedef void (APIENTRYP PFNGLSAMPLERPARAMETERIPROC) (GLuint sampler, GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLSAMPLERPARAMETERIVPROC) (GLuint sampler, GLenum pname, const GLint *param); +typedef void (APIENTRYP PFNGLSAMPLERPARAMETERFPROC) (GLuint sampler, GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLSAMPLERPARAMETERFVPROC) (GLuint sampler, GLenum pname, const GLfloat *param); +typedef void (APIENTRYP PFNGLSAMPLERPARAMETERIIVPROC) (GLuint sampler, GLenum pname, const GLint *param); +typedef void (APIENTRYP PFNGLSAMPLERPARAMETERIUIVPROC) (GLuint sampler, GLenum pname, const GLuint *param); +typedef void (APIENTRYP PFNGLGETSAMPLERPARAMETERIVPROC) (GLuint sampler, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETSAMPLERPARAMETERIIVPROC) (GLuint sampler, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETSAMPLERPARAMETERFVPROC) (GLuint sampler, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETSAMPLERPARAMETERIUIVPROC) (GLuint sampler, GLenum pname, GLuint *params); +#endif + +#ifndef GL_ARB_texture_rgb10_a2ui +#define GL_ARB_texture_rgb10_a2ui 1 +#endif + +#ifndef GL_ARB_texture_swizzle +#define GL_ARB_texture_swizzle 1 +#endif + +#ifndef GL_ARB_timer_query +#define GL_ARB_timer_query 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glQueryCounter (GLuint id, GLenum target); +GLAPI void APIENTRY glGetQueryObjecti64v (GLuint id, GLenum pname, GLint64 *params); +GLAPI void APIENTRY glGetQueryObjectui64v (GLuint id, GLenum pname, GLuint64 *params); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLQUERYCOUNTERPROC) (GLuint id, GLenum target); +typedef void (APIENTRYP PFNGLGETQUERYOBJECTI64VPROC) (GLuint id, GLenum pname, GLint64 *params); +typedef void (APIENTRYP PFNGLGETQUERYOBJECTUI64VPROC) (GLuint id, GLenum pname, GLuint64 *params); +#endif + +#ifndef GL_ARB_vertex_type_2_10_10_10_rev +#define GL_ARB_vertex_type_2_10_10_10_rev 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glVertexP2ui (GLenum type, GLuint value); +GLAPI void APIENTRY glVertexP2uiv (GLenum type, const GLuint *value); +GLAPI void APIENTRY glVertexP3ui (GLenum type, GLuint value); +GLAPI void APIENTRY glVertexP3uiv (GLenum type, const GLuint *value); +GLAPI void APIENTRY glVertexP4ui (GLenum type, GLuint value); +GLAPI void APIENTRY glVertexP4uiv (GLenum type, const GLuint *value); +GLAPI void APIENTRY glTexCoordP1ui (GLenum type, GLuint coords); +GLAPI void APIENTRY glTexCoordP1uiv (GLenum type, const GLuint *coords); +GLAPI void APIENTRY glTexCoordP2ui (GLenum type, GLuint coords); +GLAPI void APIENTRY glTexCoordP2uiv (GLenum type, const GLuint *coords); +GLAPI void APIENTRY glTexCoordP3ui (GLenum type, GLuint coords); +GLAPI void APIENTRY glTexCoordP3uiv (GLenum type, const GLuint *coords); +GLAPI void APIENTRY glTexCoordP4ui (GLenum type, GLuint coords); +GLAPI void APIENTRY glTexCoordP4uiv (GLenum type, const GLuint *coords); +GLAPI void APIENTRY glMultiTexCoordP1ui (GLenum texture, GLenum type, GLuint coords); +GLAPI void APIENTRY glMultiTexCoordP1uiv (GLenum texture, GLenum type, const GLuint *coords); +GLAPI void APIENTRY glMultiTexCoordP2ui (GLenum texture, GLenum type, GLuint coords); +GLAPI void APIENTRY glMultiTexCoordP2uiv (GLenum texture, GLenum type, const GLuint *coords); +GLAPI void APIENTRY glMultiTexCoordP3ui (GLenum texture, GLenum type, GLuint coords); +GLAPI void APIENTRY glMultiTexCoordP3uiv (GLenum texture, GLenum type, const GLuint *coords); +GLAPI void APIENTRY glMultiTexCoordP4ui (GLenum texture, GLenum type, GLuint coords); +GLAPI void APIENTRY glMultiTexCoordP4uiv (GLenum texture, GLenum type, const GLuint *coords); +GLAPI void APIENTRY glNormalP3ui (GLenum type, GLuint coords); +GLAPI void APIENTRY glNormalP3uiv (GLenum type, const GLuint *coords); +GLAPI void APIENTRY glColorP3ui (GLenum type, GLuint color); +GLAPI void APIENTRY glColorP3uiv (GLenum type, const GLuint *color); +GLAPI void APIENTRY glColorP4ui (GLenum type, GLuint color); +GLAPI void APIENTRY glColorP4uiv (GLenum type, const GLuint *color); +GLAPI void APIENTRY glSecondaryColorP3ui (GLenum type, GLuint color); +GLAPI void APIENTRY glSecondaryColorP3uiv (GLenum type, const GLuint *color); +GLAPI void APIENTRY glVertexAttribP1ui (GLuint index, GLenum type, GLboolean normalized, GLuint value); +GLAPI void APIENTRY glVertexAttribP1uiv (GLuint index, GLenum type, GLboolean normalized, const GLuint *value); +GLAPI void APIENTRY glVertexAttribP2ui (GLuint index, GLenum type, GLboolean normalized, GLuint value); +GLAPI void APIENTRY glVertexAttribP2uiv (GLuint index, GLenum type, GLboolean normalized, const GLuint *value); +GLAPI void APIENTRY glVertexAttribP3ui (GLuint index, GLenum type, GLboolean normalized, GLuint value); +GLAPI void APIENTRY glVertexAttribP3uiv (GLuint index, GLenum type, GLboolean normalized, const GLuint *value); +GLAPI void APIENTRY glVertexAttribP4ui (GLuint index, GLenum type, GLboolean normalized, GLuint value); +GLAPI void APIENTRY glVertexAttribP4uiv (GLuint index, GLenum type, GLboolean normalized, const GLuint *value); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLVERTEXP2UIPROC) (GLenum type, GLuint value); +typedef void (APIENTRYP PFNGLVERTEXP2UIVPROC) (GLenum type, const GLuint *value); +typedef void (APIENTRYP PFNGLVERTEXP3UIPROC) (GLenum type, GLuint value); +typedef void (APIENTRYP PFNGLVERTEXP3UIVPROC) (GLenum type, const GLuint *value); +typedef void (APIENTRYP PFNGLVERTEXP4UIPROC) (GLenum type, GLuint value); +typedef void (APIENTRYP PFNGLVERTEXP4UIVPROC) (GLenum type, const GLuint *value); +typedef void (APIENTRYP PFNGLTEXCOORDP1UIPROC) (GLenum type, GLuint coords); +typedef void (APIENTRYP PFNGLTEXCOORDP1UIVPROC) (GLenum type, const GLuint *coords); +typedef void (APIENTRYP PFNGLTEXCOORDP2UIPROC) (GLenum type, GLuint coords); +typedef void (APIENTRYP PFNGLTEXCOORDP2UIVPROC) (GLenum type, const GLuint *coords); +typedef void (APIENTRYP PFNGLTEXCOORDP3UIPROC) (GLenum type, GLuint coords); +typedef void (APIENTRYP PFNGLTEXCOORDP3UIVPROC) (GLenum type, const GLuint *coords); +typedef void (APIENTRYP PFNGLTEXCOORDP4UIPROC) (GLenum type, GLuint coords); +typedef void (APIENTRYP PFNGLTEXCOORDP4UIVPROC) (GLenum type, const GLuint *coords); +typedef void (APIENTRYP PFNGLMULTITEXCOORDP1UIPROC) (GLenum texture, GLenum type, GLuint coords); +typedef void (APIENTRYP PFNGLMULTITEXCOORDP1UIVPROC) (GLenum texture, GLenum type, const GLuint *coords); +typedef void (APIENTRYP PFNGLMULTITEXCOORDP2UIPROC) (GLenum texture, GLenum type, GLuint coords); +typedef void (APIENTRYP PFNGLMULTITEXCOORDP2UIVPROC) (GLenum texture, GLenum type, const GLuint *coords); +typedef void (APIENTRYP PFNGLMULTITEXCOORDP3UIPROC) (GLenum texture, GLenum type, GLuint coords); +typedef void (APIENTRYP PFNGLMULTITEXCOORDP3UIVPROC) (GLenum texture, GLenum type, const GLuint *coords); +typedef void (APIENTRYP PFNGLMULTITEXCOORDP4UIPROC) (GLenum texture, GLenum type, GLuint coords); +typedef void (APIENTRYP PFNGLMULTITEXCOORDP4UIVPROC) (GLenum texture, GLenum type, const GLuint *coords); +typedef void (APIENTRYP PFNGLNORMALP3UIPROC) (GLenum type, GLuint coords); +typedef void (APIENTRYP PFNGLNORMALP3UIVPROC) (GLenum type, const GLuint *coords); +typedef void (APIENTRYP PFNGLCOLORP3UIPROC) (GLenum type, GLuint color); +typedef void (APIENTRYP PFNGLCOLORP3UIVPROC) (GLenum type, const GLuint *color); +typedef void (APIENTRYP PFNGLCOLORP4UIPROC) (GLenum type, GLuint color); +typedef void (APIENTRYP PFNGLCOLORP4UIVPROC) (GLenum type, const GLuint *color); +typedef void (APIENTRYP PFNGLSECONDARYCOLORP3UIPROC) (GLenum type, GLuint color); +typedef void (APIENTRYP PFNGLSECONDARYCOLORP3UIVPROC) (GLenum type, const GLuint *color); +typedef void (APIENTRYP PFNGLVERTEXATTRIBP1UIPROC) (GLuint index, GLenum type, GLboolean normalized, GLuint value); +typedef void (APIENTRYP PFNGLVERTEXATTRIBP1UIVPROC) (GLuint index, GLenum type, GLboolean normalized, const GLuint *value); +typedef void (APIENTRYP PFNGLVERTEXATTRIBP2UIPROC) (GLuint index, GLenum type, GLboolean normalized, GLuint value); +typedef void (APIENTRYP PFNGLVERTEXATTRIBP2UIVPROC) (GLuint index, GLenum type, GLboolean normalized, const GLuint *value); +typedef void (APIENTRYP PFNGLVERTEXATTRIBP3UIPROC) (GLuint index, GLenum type, GLboolean normalized, GLuint value); +typedef void (APIENTRYP PFNGLVERTEXATTRIBP3UIVPROC) (GLuint index, GLenum type, GLboolean normalized, const GLuint *value); +typedef void (APIENTRYP PFNGLVERTEXATTRIBP4UIPROC) (GLuint index, GLenum type, GLboolean normalized, GLuint value); +typedef void (APIENTRYP PFNGLVERTEXATTRIBP4UIVPROC) (GLuint index, GLenum type, GLboolean normalized, const GLuint *value); +#endif + +#ifndef GL_ARB_draw_indirect +#define GL_ARB_draw_indirect 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDrawArraysIndirect (GLenum mode, const GLvoid *indirect); +GLAPI void APIENTRY glDrawElementsIndirect (GLenum mode, GLenum type, const GLvoid *indirect); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDRAWARRAYSINDIRECTPROC) (GLenum mode, const GLvoid *indirect); +typedef void (APIENTRYP PFNGLDRAWELEMENTSINDIRECTPROC) (GLenum mode, GLenum type, const GLvoid *indirect); +#endif + +#ifndef GL_ARB_gpu_shader5 +#define GL_ARB_gpu_shader5 1 +#endif + +#ifndef GL_ARB_gpu_shader_fp64 +#define GL_ARB_gpu_shader_fp64 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glUniform1d (GLint location, GLdouble x); +GLAPI void APIENTRY glUniform2d (GLint location, GLdouble x, GLdouble y); +GLAPI void APIENTRY glUniform3d (GLint location, GLdouble x, GLdouble y, GLdouble z); +GLAPI void APIENTRY glUniform4d (GLint location, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +GLAPI void APIENTRY glUniform1dv (GLint location, GLsizei count, const GLdouble *value); +GLAPI void APIENTRY glUniform2dv (GLint location, GLsizei count, const GLdouble *value); +GLAPI void APIENTRY glUniform3dv (GLint location, GLsizei count, const GLdouble *value); +GLAPI void APIENTRY glUniform4dv (GLint location, GLsizei count, const GLdouble *value); +GLAPI void APIENTRY glUniformMatrix2dv (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glUniformMatrix3dv (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glUniformMatrix4dv (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glUniformMatrix2x3dv (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glUniformMatrix2x4dv (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glUniformMatrix3x2dv (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glUniformMatrix3x4dv (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glUniformMatrix4x2dv (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glUniformMatrix4x3dv (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glGetUniformdv (GLuint program, GLint location, GLdouble *params); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLUNIFORM1DPROC) (GLint location, GLdouble x); +typedef void (APIENTRYP PFNGLUNIFORM2DPROC) (GLint location, GLdouble x, GLdouble y); +typedef void (APIENTRYP PFNGLUNIFORM3DPROC) (GLint location, GLdouble x, GLdouble y, GLdouble z); +typedef void (APIENTRYP PFNGLUNIFORM4DPROC) (GLint location, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +typedef void (APIENTRYP PFNGLUNIFORM1DVPROC) (GLint location, GLsizei count, const GLdouble *value); +typedef void (APIENTRYP PFNGLUNIFORM2DVPROC) (GLint location, GLsizei count, const GLdouble *value); +typedef void (APIENTRYP PFNGLUNIFORM3DVPROC) (GLint location, GLsizei count, const GLdouble *value); +typedef void (APIENTRYP PFNGLUNIFORM4DVPROC) (GLint location, GLsizei count, const GLdouble *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX2DVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX3DVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX4DVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX2X3DVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX2X4DVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX3X2DVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX3X4DVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX4X2DVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX4X3DVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLGETUNIFORMDVPROC) (GLuint program, GLint location, GLdouble *params); +#endif + +#ifndef GL_ARB_shader_subroutine +#define GL_ARB_shader_subroutine 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI GLint APIENTRY glGetSubroutineUniformLocation (GLuint program, GLenum shadertype, const GLchar *name); +GLAPI GLuint APIENTRY glGetSubroutineIndex (GLuint program, GLenum shadertype, const GLchar *name); +GLAPI void APIENTRY glGetActiveSubroutineUniformiv (GLuint program, GLenum shadertype, GLuint index, GLenum pname, GLint *values); +GLAPI void APIENTRY glGetActiveSubroutineUniformName (GLuint program, GLenum shadertype, GLuint index, GLsizei bufsize, GLsizei *length, GLchar *name); +GLAPI void APIENTRY glGetActiveSubroutineName (GLuint program, GLenum shadertype, GLuint index, GLsizei bufsize, GLsizei *length, GLchar *name); +GLAPI void APIENTRY glUniformSubroutinesuiv (GLenum shadertype, GLsizei count, const GLuint *indices); +GLAPI void APIENTRY glGetUniformSubroutineuiv (GLenum shadertype, GLint location, GLuint *params); +GLAPI void APIENTRY glGetProgramStageiv (GLuint program, GLenum shadertype, GLenum pname, GLint *values); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef GLint (APIENTRYP PFNGLGETSUBROUTINEUNIFORMLOCATIONPROC) (GLuint program, GLenum shadertype, const GLchar *name); +typedef GLuint (APIENTRYP PFNGLGETSUBROUTINEINDEXPROC) (GLuint program, GLenum shadertype, const GLchar *name); +typedef void (APIENTRYP PFNGLGETACTIVESUBROUTINEUNIFORMIVPROC) (GLuint program, GLenum shadertype, GLuint index, GLenum pname, GLint *values); +typedef void (APIENTRYP PFNGLGETACTIVESUBROUTINEUNIFORMNAMEPROC) (GLuint program, GLenum shadertype, GLuint index, GLsizei bufsize, GLsizei *length, GLchar *name); +typedef void (APIENTRYP PFNGLGETACTIVESUBROUTINENAMEPROC) (GLuint program, GLenum shadertype, GLuint index, GLsizei bufsize, GLsizei *length, GLchar *name); +typedef void (APIENTRYP PFNGLUNIFORMSUBROUTINESUIVPROC) (GLenum shadertype, GLsizei count, const GLuint *indices); +typedef void (APIENTRYP PFNGLGETUNIFORMSUBROUTINEUIVPROC) (GLenum shadertype, GLint location, GLuint *params); +typedef void (APIENTRYP PFNGLGETPROGRAMSTAGEIVPROC) (GLuint program, GLenum shadertype, GLenum pname, GLint *values); +#endif + +#ifndef GL_ARB_tessellation_shader +#define GL_ARB_tessellation_shader 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glPatchParameteri (GLenum pname, GLint value); +GLAPI void APIENTRY glPatchParameterfv (GLenum pname, const GLfloat *values); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPATCHPARAMETERIPROC) (GLenum pname, GLint value); +typedef void (APIENTRYP PFNGLPATCHPARAMETERFVPROC) (GLenum pname, const GLfloat *values); +#endif + +#ifndef GL_ARB_texture_buffer_object_rgb32 +#define GL_ARB_texture_buffer_object_rgb32 1 +#endif + +#ifndef GL_ARB_transform_feedback2 +#define GL_ARB_transform_feedback2 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBindTransformFeedback (GLenum target, GLuint id); +GLAPI void APIENTRY glDeleteTransformFeedbacks (GLsizei n, const GLuint *ids); +GLAPI void APIENTRY glGenTransformFeedbacks (GLsizei n, GLuint *ids); +GLAPI GLboolean APIENTRY glIsTransformFeedback (GLuint id); +GLAPI void APIENTRY glPauseTransformFeedback (void); +GLAPI void APIENTRY glResumeTransformFeedback (void); +GLAPI void APIENTRY glDrawTransformFeedback (GLenum mode, GLuint id); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBINDTRANSFORMFEEDBACKPROC) (GLenum target, GLuint id); +typedef void (APIENTRYP PFNGLDELETETRANSFORMFEEDBACKSPROC) (GLsizei n, const GLuint *ids); +typedef void (APIENTRYP PFNGLGENTRANSFORMFEEDBACKSPROC) (GLsizei n, GLuint *ids); +typedef GLboolean (APIENTRYP PFNGLISTRANSFORMFEEDBACKPROC) (GLuint id); +typedef void (APIENTRYP PFNGLPAUSETRANSFORMFEEDBACKPROC) (void); +typedef void (APIENTRYP PFNGLRESUMETRANSFORMFEEDBACKPROC) (void); +typedef void (APIENTRYP PFNGLDRAWTRANSFORMFEEDBACKPROC) (GLenum mode, GLuint id); +#endif + +#ifndef GL_ARB_transform_feedback3 +#define GL_ARB_transform_feedback3 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDrawTransformFeedbackStream (GLenum mode, GLuint id, GLuint stream); +GLAPI void APIENTRY glBeginQueryIndexed (GLenum target, GLuint index, GLuint id); +GLAPI void APIENTRY glEndQueryIndexed (GLenum target, GLuint index); +GLAPI void APIENTRY glGetQueryIndexediv (GLenum target, GLuint index, GLenum pname, GLint *params); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDRAWTRANSFORMFEEDBACKSTREAMPROC) (GLenum mode, GLuint id, GLuint stream); +typedef void (APIENTRYP PFNGLBEGINQUERYINDEXEDPROC) (GLenum target, GLuint index, GLuint id); +typedef void (APIENTRYP PFNGLENDQUERYINDEXEDPROC) (GLenum target, GLuint index); +typedef void (APIENTRYP PFNGLGETQUERYINDEXEDIVPROC) (GLenum target, GLuint index, GLenum pname, GLint *params); +#endif + +#ifndef GL_ARB_ES2_compatibility +#define GL_ARB_ES2_compatibility 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glReleaseShaderCompiler (void); +GLAPI void APIENTRY glShaderBinary (GLsizei count, const GLuint *shaders, GLenum binaryformat, const GLvoid *binary, GLsizei length); +GLAPI void APIENTRY glGetShaderPrecisionFormat (GLenum shadertype, GLenum precisiontype, GLint *range, GLint *precision); +GLAPI void APIENTRY glDepthRangef (GLclampf n, GLclampf f); +GLAPI void APIENTRY glClearDepthf (GLclampf d); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLRELEASESHADERCOMPILERPROC) (void); +typedef void (APIENTRYP PFNGLSHADERBINARYPROC) (GLsizei count, const GLuint *shaders, GLenum binaryformat, const GLvoid *binary, GLsizei length); +typedef void (APIENTRYP PFNGLGETSHADERPRECISIONFORMATPROC) (GLenum shadertype, GLenum precisiontype, GLint *range, GLint *precision); +typedef void (APIENTRYP PFNGLDEPTHRANGEFPROC) (GLclampf n, GLclampf f); +typedef void (APIENTRYP PFNGLCLEARDEPTHFPROC) (GLclampf d); +#endif + +#ifndef GL_ARB_get_program_binary +#define GL_ARB_get_program_binary 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glGetProgramBinary (GLuint program, GLsizei bufSize, GLsizei *length, GLenum *binaryFormat, GLvoid *binary); +GLAPI void APIENTRY glProgramBinary (GLuint program, GLenum binaryFormat, const GLvoid *binary, GLsizei length); +GLAPI void APIENTRY glProgramParameteri (GLuint program, GLenum pname, GLint value); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGETPROGRAMBINARYPROC) (GLuint program, GLsizei bufSize, GLsizei *length, GLenum *binaryFormat, GLvoid *binary); +typedef void (APIENTRYP PFNGLPROGRAMBINARYPROC) (GLuint program, GLenum binaryFormat, const GLvoid *binary, GLsizei length); +typedef void (APIENTRYP PFNGLPROGRAMPARAMETERIPROC) (GLuint program, GLenum pname, GLint value); +#endif + +#ifndef GL_ARB_separate_shader_objects +#define GL_ARB_separate_shader_objects 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glUseProgramStages (GLuint pipeline, GLbitfield stages, GLuint program); +GLAPI void APIENTRY glActiveShaderProgram (GLuint pipeline, GLuint program); +GLAPI GLuint APIENTRY glCreateShaderProgramv (GLenum type, GLsizei count, const GLchar* *strings); +GLAPI void APIENTRY glBindProgramPipeline (GLuint pipeline); +GLAPI void APIENTRY glDeleteProgramPipelines (GLsizei n, const GLuint *pipelines); +GLAPI void APIENTRY glGenProgramPipelines (GLsizei n, GLuint *pipelines); +GLAPI GLboolean APIENTRY glIsProgramPipeline (GLuint pipeline); +GLAPI void APIENTRY glGetProgramPipelineiv (GLuint pipeline, GLenum pname, GLint *params); +GLAPI void APIENTRY glProgramUniform1i (GLuint program, GLint location, GLint v0); +GLAPI void APIENTRY glProgramUniform1iv (GLuint program, GLint location, GLsizei count, const GLint *value); +GLAPI void APIENTRY glProgramUniform1f (GLuint program, GLint location, GLfloat v0); +GLAPI void APIENTRY glProgramUniform1fv (GLuint program, GLint location, GLsizei count, const GLfloat *value); +GLAPI void APIENTRY glProgramUniform1d (GLuint program, GLint location, GLdouble v0); +GLAPI void APIENTRY glProgramUniform1dv (GLuint program, GLint location, GLsizei count, const GLdouble *value); +GLAPI void APIENTRY glProgramUniform1ui (GLuint program, GLint location, GLuint v0); +GLAPI void APIENTRY glProgramUniform1uiv (GLuint program, GLint location, GLsizei count, const GLuint *value); +GLAPI void APIENTRY glProgramUniform2i (GLuint program, GLint location, GLint v0, GLint v1); +GLAPI void APIENTRY glProgramUniform2iv (GLuint program, GLint location, GLsizei count, const GLint *value); +GLAPI void APIENTRY glProgramUniform2f (GLuint program, GLint location, GLfloat v0, GLfloat v1); +GLAPI void APIENTRY glProgramUniform2fv (GLuint program, GLint location, GLsizei count, const GLfloat *value); +GLAPI void APIENTRY glProgramUniform2d (GLuint program, GLint location, GLdouble v0, GLdouble v1); +GLAPI void APIENTRY glProgramUniform2dv (GLuint program, GLint location, GLsizei count, const GLdouble *value); +GLAPI void APIENTRY glProgramUniform2ui (GLuint program, GLint location, GLuint v0, GLuint v1); +GLAPI void APIENTRY glProgramUniform2uiv (GLuint program, GLint location, GLsizei count, const GLuint *value); +GLAPI void APIENTRY glProgramUniform3i (GLuint program, GLint location, GLint v0, GLint v1, GLint v2); +GLAPI void APIENTRY glProgramUniform3iv (GLuint program, GLint location, GLsizei count, const GLint *value); +GLAPI void APIENTRY glProgramUniform3f (GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2); +GLAPI void APIENTRY glProgramUniform3fv (GLuint program, GLint location, GLsizei count, const GLfloat *value); +GLAPI void APIENTRY glProgramUniform3d (GLuint program, GLint location, GLdouble v0, GLdouble v1, GLdouble v2); +GLAPI void APIENTRY glProgramUniform3dv (GLuint program, GLint location, GLsizei count, const GLdouble *value); +GLAPI void APIENTRY glProgramUniform3ui (GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2); +GLAPI void APIENTRY glProgramUniform3uiv (GLuint program, GLint location, GLsizei count, const GLuint *value); +GLAPI void APIENTRY glProgramUniform4i (GLuint program, GLint location, GLint v0, GLint v1, GLint v2, GLint v3); +GLAPI void APIENTRY glProgramUniform4iv (GLuint program, GLint location, GLsizei count, const GLint *value); +GLAPI void APIENTRY glProgramUniform4f (GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3); +GLAPI void APIENTRY glProgramUniform4fv (GLuint program, GLint location, GLsizei count, const GLfloat *value); +GLAPI void APIENTRY glProgramUniform4d (GLuint program, GLint location, GLdouble v0, GLdouble v1, GLdouble v2, GLdouble v3); +GLAPI void APIENTRY glProgramUniform4dv (GLuint program, GLint location, GLsizei count, const GLdouble *value); +GLAPI void APIENTRY glProgramUniform4ui (GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3); +GLAPI void APIENTRY glProgramUniform4uiv (GLuint program, GLint location, GLsizei count, const GLuint *value); +GLAPI void APIENTRY glProgramUniformMatrix2fv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glProgramUniformMatrix3fv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glProgramUniformMatrix4fv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glProgramUniformMatrix2dv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glProgramUniformMatrix3dv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glProgramUniformMatrix4dv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glProgramUniformMatrix2x3fv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glProgramUniformMatrix3x2fv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glProgramUniformMatrix2x4fv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glProgramUniformMatrix4x2fv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glProgramUniformMatrix3x4fv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glProgramUniformMatrix4x3fv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glProgramUniformMatrix2x3dv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glProgramUniformMatrix3x2dv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glProgramUniformMatrix2x4dv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glProgramUniformMatrix4x2dv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glProgramUniformMatrix3x4dv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glProgramUniformMatrix4x3dv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glValidateProgramPipeline (GLuint pipeline); +GLAPI void APIENTRY glGetProgramPipelineInfoLog (GLuint pipeline, GLsizei bufSize, GLsizei *length, GLchar *infoLog); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLUSEPROGRAMSTAGESPROC) (GLuint pipeline, GLbitfield stages, GLuint program); +typedef void (APIENTRYP PFNGLACTIVESHADERPROGRAMPROC) (GLuint pipeline, GLuint program); +typedef GLuint (APIENTRYP PFNGLCREATESHADERPROGRAMVPROC) (GLenum type, GLsizei count, const GLchar* *strings); +typedef void (APIENTRYP PFNGLBINDPROGRAMPIPELINEPROC) (GLuint pipeline); +typedef void (APIENTRYP PFNGLDELETEPROGRAMPIPELINESPROC) (GLsizei n, const GLuint *pipelines); +typedef void (APIENTRYP PFNGLGENPROGRAMPIPELINESPROC) (GLsizei n, GLuint *pipelines); +typedef GLboolean (APIENTRYP PFNGLISPROGRAMPIPELINEPROC) (GLuint pipeline); +typedef void (APIENTRYP PFNGLGETPROGRAMPIPELINEIVPROC) (GLuint pipeline, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1IPROC) (GLuint program, GLint location, GLint v0); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1IVPROC) (GLuint program, GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1FPROC) (GLuint program, GLint location, GLfloat v0); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1FVPROC) (GLuint program, GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1DPROC) (GLuint program, GLint location, GLdouble v0); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1DVPROC) (GLuint program, GLint location, GLsizei count, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1UIPROC) (GLuint program, GLint location, GLuint v0); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1UIVPROC) (GLuint program, GLint location, GLsizei count, const GLuint *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2IPROC) (GLuint program, GLint location, GLint v0, GLint v1); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2IVPROC) (GLuint program, GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2FPROC) (GLuint program, GLint location, GLfloat v0, GLfloat v1); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2FVPROC) (GLuint program, GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2DPROC) (GLuint program, GLint location, GLdouble v0, GLdouble v1); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2DVPROC) (GLuint program, GLint location, GLsizei count, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2UIPROC) (GLuint program, GLint location, GLuint v0, GLuint v1); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2UIVPROC) (GLuint program, GLint location, GLsizei count, const GLuint *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3IPROC) (GLuint program, GLint location, GLint v0, GLint v1, GLint v2); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3IVPROC) (GLuint program, GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3FPROC) (GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3FVPROC) (GLuint program, GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3DPROC) (GLuint program, GLint location, GLdouble v0, GLdouble v1, GLdouble v2); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3DVPROC) (GLuint program, GLint location, GLsizei count, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3UIPROC) (GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3UIVPROC) (GLuint program, GLint location, GLsizei count, const GLuint *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4IPROC) (GLuint program, GLint location, GLint v0, GLint v1, GLint v2, GLint v3); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4IVPROC) (GLuint program, GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4FPROC) (GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4FVPROC) (GLuint program, GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4DPROC) (GLuint program, GLint location, GLdouble v0, GLdouble v1, GLdouble v2, GLdouble v3); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4DVPROC) (GLuint program, GLint location, GLsizei count, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4UIPROC) (GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4UIVPROC) (GLuint program, GLint location, GLsizei count, const GLuint *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2FVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3FVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4FVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2DVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3DVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4DVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2X3FVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3X2FVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2X4FVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4X2FVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3X4FVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4X3FVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2X3DVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3X2DVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2X4DVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4X2DVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3X4DVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4X3DVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLVALIDATEPROGRAMPIPELINEPROC) (GLuint pipeline); +typedef void (APIENTRYP PFNGLGETPROGRAMPIPELINEINFOLOGPROC) (GLuint pipeline, GLsizei bufSize, GLsizei *length, GLchar *infoLog); +#endif + +#ifndef GL_ARB_vertex_attrib_64bit +#define GL_ARB_vertex_attrib_64bit 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glVertexAttribL1d (GLuint index, GLdouble x); +GLAPI void APIENTRY glVertexAttribL2d (GLuint index, GLdouble x, GLdouble y); +GLAPI void APIENTRY glVertexAttribL3d (GLuint index, GLdouble x, GLdouble y, GLdouble z); +GLAPI void APIENTRY glVertexAttribL4d (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +GLAPI void APIENTRY glVertexAttribL1dv (GLuint index, const GLdouble *v); +GLAPI void APIENTRY glVertexAttribL2dv (GLuint index, const GLdouble *v); +GLAPI void APIENTRY glVertexAttribL3dv (GLuint index, const GLdouble *v); +GLAPI void APIENTRY glVertexAttribL4dv (GLuint index, const GLdouble *v); +GLAPI void APIENTRY glVertexAttribLPointer (GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +GLAPI void APIENTRY glGetVertexAttribLdv (GLuint index, GLenum pname, GLdouble *params); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLVERTEXATTRIBL1DPROC) (GLuint index, GLdouble x); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL2DPROC) (GLuint index, GLdouble x, GLdouble y); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL3DPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL4DPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL1DVPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL2DVPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL3DVPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL4DVPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBLPOINTERPROC) (GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBLDVPROC) (GLuint index, GLenum pname, GLdouble *params); +#endif + +#ifndef GL_ARB_viewport_array +#define GL_ARB_viewport_array 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glViewportArrayv (GLuint first, GLsizei count, const GLfloat *v); +GLAPI void APIENTRY glViewportIndexedf (GLuint index, GLfloat x, GLfloat y, GLfloat w, GLfloat h); +GLAPI void APIENTRY glViewportIndexedfv (GLuint index, const GLfloat *v); +GLAPI void APIENTRY glScissorArrayv (GLuint first, GLsizei count, const GLint *v); +GLAPI void APIENTRY glScissorIndexed (GLuint index, GLint left, GLint bottom, GLsizei width, GLsizei height); +GLAPI void APIENTRY glScissorIndexedv (GLuint index, const GLint *v); +GLAPI void APIENTRY glDepthRangeArrayv (GLuint first, GLsizei count, const GLclampd *v); +GLAPI void APIENTRY glDepthRangeIndexed (GLuint index, GLclampd n, GLclampd f); +GLAPI void APIENTRY glGetFloati_v (GLenum target, GLuint index, GLfloat *data); +GLAPI void APIENTRY glGetDoublei_v (GLenum target, GLuint index, GLdouble *data); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLVIEWPORTARRAYVPROC) (GLuint first, GLsizei count, const GLfloat *v); +typedef void (APIENTRYP PFNGLVIEWPORTINDEXEDFPROC) (GLuint index, GLfloat x, GLfloat y, GLfloat w, GLfloat h); +typedef void (APIENTRYP PFNGLVIEWPORTINDEXEDFVPROC) (GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLSCISSORARRAYVPROC) (GLuint first, GLsizei count, const GLint *v); +typedef void (APIENTRYP PFNGLSCISSORINDEXEDPROC) (GLuint index, GLint left, GLint bottom, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLSCISSORINDEXEDVPROC) (GLuint index, const GLint *v); +typedef void (APIENTRYP PFNGLDEPTHRANGEARRAYVPROC) (GLuint first, GLsizei count, const GLclampd *v); +typedef void (APIENTRYP PFNGLDEPTHRANGEINDEXEDPROC) (GLuint index, GLclampd n, GLclampd f); +typedef void (APIENTRYP PFNGLGETFLOATI_VPROC) (GLenum target, GLuint index, GLfloat *data); +typedef void (APIENTRYP PFNGLGETDOUBLEI_VPROC) (GLenum target, GLuint index, GLdouble *data); +#endif + +#ifndef GL_ARB_cl_event +#define GL_ARB_cl_event 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI GLsync APIENTRY glCreateSyncFromCLeventARB (struct _cl_context * context, struct _cl_event * event, GLbitfield flags); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef GLsync (APIENTRYP PFNGLCREATESYNCFROMCLEVENTARBPROC) (struct _cl_context * context, struct _cl_event * event, GLbitfield flags); +#endif + +#ifndef GL_ARB_debug_output +#define GL_ARB_debug_output 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDebugMessageControlARB (GLenum source, GLenum type, GLenum severity, GLsizei count, const GLuint *ids, GLboolean enabled); +GLAPI void APIENTRY glDebugMessageInsertARB (GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *buf); +GLAPI void APIENTRY glDebugMessageCallbackARB (GLDEBUGPROCARB callback, const GLvoid *userParam); +GLAPI GLuint APIENTRY glGetDebugMessageLogARB (GLuint count, GLsizei bufsize, GLenum *sources, GLenum *types, GLuint *ids, GLenum *severities, GLsizei *lengths, GLchar *messageLog); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDEBUGMESSAGECONTROLARBPROC) (GLenum source, GLenum type, GLenum severity, GLsizei count, const GLuint *ids, GLboolean enabled); +typedef void (APIENTRYP PFNGLDEBUGMESSAGEINSERTARBPROC) (GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *buf); +typedef void (APIENTRYP PFNGLDEBUGMESSAGECALLBACKARBPROC) (GLDEBUGPROCARB callback, const GLvoid *userParam); +typedef GLuint (APIENTRYP PFNGLGETDEBUGMESSAGELOGARBPROC) (GLuint count, GLsizei bufsize, GLenum *sources, GLenum *types, GLuint *ids, GLenum *severities, GLsizei *lengths, GLchar *messageLog); +#endif + +#ifndef GL_ARB_robustness +#define GL_ARB_robustness 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI GLenum APIENTRY glGetGraphicsResetStatusARB (void); +GLAPI void APIENTRY glGetnMapdvARB (GLenum target, GLenum query, GLsizei bufSize, GLdouble *v); +GLAPI void APIENTRY glGetnMapfvARB (GLenum target, GLenum query, GLsizei bufSize, GLfloat *v); +GLAPI void APIENTRY glGetnMapivARB (GLenum target, GLenum query, GLsizei bufSize, GLint *v); +GLAPI void APIENTRY glGetnPixelMapfvARB (GLenum map, GLsizei bufSize, GLfloat *values); +GLAPI void APIENTRY glGetnPixelMapuivARB (GLenum map, GLsizei bufSize, GLuint *values); +GLAPI void APIENTRY glGetnPixelMapusvARB (GLenum map, GLsizei bufSize, GLushort *values); +GLAPI void APIENTRY glGetnPolygonStippleARB (GLsizei bufSize, GLubyte *pattern); +GLAPI void APIENTRY glGetnColorTableARB (GLenum target, GLenum format, GLenum type, GLsizei bufSize, GLvoid *table); +GLAPI void APIENTRY glGetnConvolutionFilterARB (GLenum target, GLenum format, GLenum type, GLsizei bufSize, GLvoid *image); +GLAPI void APIENTRY glGetnSeparableFilterARB (GLenum target, GLenum format, GLenum type, GLsizei rowBufSize, GLvoid *row, GLsizei columnBufSize, GLvoid *column, GLvoid *span); +GLAPI void APIENTRY glGetnHistogramARB (GLenum target, GLboolean reset, GLenum format, GLenum type, GLsizei bufSize, GLvoid *values); +GLAPI void APIENTRY glGetnMinmaxARB (GLenum target, GLboolean reset, GLenum format, GLenum type, GLsizei bufSize, GLvoid *values); +GLAPI void APIENTRY glGetnTexImageARB (GLenum target, GLint level, GLenum format, GLenum type, GLsizei bufSize, GLvoid *img); +GLAPI void APIENTRY glReadnPixelsARB (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLsizei bufSize, GLvoid *data); +GLAPI void APIENTRY glGetnCompressedTexImageARB (GLenum target, GLint lod, GLsizei bufSize, GLvoid *img); +GLAPI void APIENTRY glGetnUniformfvARB (GLuint program, GLint location, GLsizei bufSize, GLfloat *params); +GLAPI void APIENTRY glGetnUniformivARB (GLuint program, GLint location, GLsizei bufSize, GLint *params); +GLAPI void APIENTRY glGetnUniformuivARB (GLuint program, GLint location, GLsizei bufSize, GLuint *params); +GLAPI void APIENTRY glGetnUniformdvARB (GLuint program, GLint location, GLsizei bufSize, GLdouble *params); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef GLenum (APIENTRYP PFNGLGETGRAPHICSRESETSTATUSARBPROC) (void); +typedef void (APIENTRYP PFNGLGETNMAPDVARBPROC) (GLenum target, GLenum query, GLsizei bufSize, GLdouble *v); +typedef void (APIENTRYP PFNGLGETNMAPFVARBPROC) (GLenum target, GLenum query, GLsizei bufSize, GLfloat *v); +typedef void (APIENTRYP PFNGLGETNMAPIVARBPROC) (GLenum target, GLenum query, GLsizei bufSize, GLint *v); +typedef void (APIENTRYP PFNGLGETNPIXELMAPFVARBPROC) (GLenum map, GLsizei bufSize, GLfloat *values); +typedef void (APIENTRYP PFNGLGETNPIXELMAPUIVARBPROC) (GLenum map, GLsizei bufSize, GLuint *values); +typedef void (APIENTRYP PFNGLGETNPIXELMAPUSVARBPROC) (GLenum map, GLsizei bufSize, GLushort *values); +typedef void (APIENTRYP PFNGLGETNPOLYGONSTIPPLEARBPROC) (GLsizei bufSize, GLubyte *pattern); +typedef void (APIENTRYP PFNGLGETNCOLORTABLEARBPROC) (GLenum target, GLenum format, GLenum type, GLsizei bufSize, GLvoid *table); +typedef void (APIENTRYP PFNGLGETNCONVOLUTIONFILTERARBPROC) (GLenum target, GLenum format, GLenum type, GLsizei bufSize, GLvoid *image); +typedef void (APIENTRYP PFNGLGETNSEPARABLEFILTERARBPROC) (GLenum target, GLenum format, GLenum type, GLsizei rowBufSize, GLvoid *row, GLsizei columnBufSize, GLvoid *column, GLvoid *span); +typedef void (APIENTRYP PFNGLGETNHISTOGRAMARBPROC) (GLenum target, GLboolean reset, GLenum format, GLenum type, GLsizei bufSize, GLvoid *values); +typedef void (APIENTRYP PFNGLGETNMINMAXARBPROC) (GLenum target, GLboolean reset, GLenum format, GLenum type, GLsizei bufSize, GLvoid *values); +typedef void (APIENTRYP PFNGLGETNTEXIMAGEARBPROC) (GLenum target, GLint level, GLenum format, GLenum type, GLsizei bufSize, GLvoid *img); +typedef void (APIENTRYP PFNGLREADNPIXELSARBPROC) (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLsizei bufSize, GLvoid *data); +typedef void (APIENTRYP PFNGLGETNCOMPRESSEDTEXIMAGEARBPROC) (GLenum target, GLint lod, GLsizei bufSize, GLvoid *img); +typedef void (APIENTRYP PFNGLGETNUNIFORMFVARBPROC) (GLuint program, GLint location, GLsizei bufSize, GLfloat *params); +typedef void (APIENTRYP PFNGLGETNUNIFORMIVARBPROC) (GLuint program, GLint location, GLsizei bufSize, GLint *params); +typedef void (APIENTRYP PFNGLGETNUNIFORMUIVARBPROC) (GLuint program, GLint location, GLsizei bufSize, GLuint *params); +typedef void (APIENTRYP PFNGLGETNUNIFORMDVARBPROC) (GLuint program, GLint location, GLsizei bufSize, GLdouble *params); +#endif + +#ifndef GL_ARB_shader_stencil_export +#define GL_ARB_shader_stencil_export 1 +#endif + +#ifndef GL_EXT_abgr +#define GL_EXT_abgr 1 +#endif + +#ifndef GL_EXT_blend_color +#define GL_EXT_blend_color 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBlendColorEXT (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBLENDCOLOREXTPROC) (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha); +#endif + +#ifndef GL_EXT_polygon_offset +#define GL_EXT_polygon_offset 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glPolygonOffsetEXT (GLfloat factor, GLfloat bias); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPOLYGONOFFSETEXTPROC) (GLfloat factor, GLfloat bias); +#endif + +#ifndef GL_EXT_texture +#define GL_EXT_texture 1 +#endif + +#ifndef GL_EXT_texture3D +#define GL_EXT_texture3D 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTexImage3DEXT (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels); +GLAPI void APIENTRY glTexSubImage3DEXT (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *pixels); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLTEXIMAGE3DEXTPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels); +typedef void (APIENTRYP PFNGLTEXSUBIMAGE3DEXTPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *pixels); +#endif + +#ifndef GL_SGIS_texture_filter4 +#define GL_SGIS_texture_filter4 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glGetTexFilterFuncSGIS (GLenum target, GLenum filter, GLfloat *weights); +GLAPI void APIENTRY glTexFilterFuncSGIS (GLenum target, GLenum filter, GLsizei n, const GLfloat *weights); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGETTEXFILTERFUNCSGISPROC) (GLenum target, GLenum filter, GLfloat *weights); +typedef void (APIENTRYP PFNGLTEXFILTERFUNCSGISPROC) (GLenum target, GLenum filter, GLsizei n, const GLfloat *weights); +#endif + +#ifndef GL_EXT_subtexture +#define GL_EXT_subtexture 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTexSubImage1DEXT (GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid *pixels); +GLAPI void APIENTRY glTexSubImage2DEXT (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLTEXSUBIMAGE1DEXTPROC) (GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid *pixels); +typedef void (APIENTRYP PFNGLTEXSUBIMAGE2DEXTPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels); +#endif + +#ifndef GL_EXT_copy_texture +#define GL_EXT_copy_texture 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glCopyTexImage1DEXT (GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLint border); +GLAPI void APIENTRY glCopyTexImage2DEXT (GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border); +GLAPI void APIENTRY glCopyTexSubImage1DEXT (GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width); +GLAPI void APIENTRY glCopyTexSubImage2DEXT (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height); +GLAPI void APIENTRY glCopyTexSubImage3DEXT (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCOPYTEXIMAGE1DEXTPROC) (GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLint border); +typedef void (APIENTRYP PFNGLCOPYTEXIMAGE2DEXTPROC) (GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border); +typedef void (APIENTRYP PFNGLCOPYTEXSUBIMAGE1DEXTPROC) (GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width); +typedef void (APIENTRYP PFNGLCOPYTEXSUBIMAGE2DEXTPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLCOPYTEXSUBIMAGE3DEXTPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height); +#endif + +#ifndef GL_EXT_histogram +#define GL_EXT_histogram 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glGetHistogramEXT (GLenum target, GLboolean reset, GLenum format, GLenum type, GLvoid *values); +GLAPI void APIENTRY glGetHistogramParameterfvEXT (GLenum target, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetHistogramParameterivEXT (GLenum target, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetMinmaxEXT (GLenum target, GLboolean reset, GLenum format, GLenum type, GLvoid *values); +GLAPI void APIENTRY glGetMinmaxParameterfvEXT (GLenum target, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetMinmaxParameterivEXT (GLenum target, GLenum pname, GLint *params); +GLAPI void APIENTRY glHistogramEXT (GLenum target, GLsizei width, GLenum internalformat, GLboolean sink); +GLAPI void APIENTRY glMinmaxEXT (GLenum target, GLenum internalformat, GLboolean sink); +GLAPI void APIENTRY glResetHistogramEXT (GLenum target); +GLAPI void APIENTRY glResetMinmaxEXT (GLenum target); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGETHISTOGRAMEXTPROC) (GLenum target, GLboolean reset, GLenum format, GLenum type, GLvoid *values); +typedef void (APIENTRYP PFNGLGETHISTOGRAMPARAMETERFVEXTPROC) (GLenum target, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETHISTOGRAMPARAMETERIVEXTPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETMINMAXEXTPROC) (GLenum target, GLboolean reset, GLenum format, GLenum type, GLvoid *values); +typedef void (APIENTRYP PFNGLGETMINMAXPARAMETERFVEXTPROC) (GLenum target, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETMINMAXPARAMETERIVEXTPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLHISTOGRAMEXTPROC) (GLenum target, GLsizei width, GLenum internalformat, GLboolean sink); +typedef void (APIENTRYP PFNGLMINMAXEXTPROC) (GLenum target, GLenum internalformat, GLboolean sink); +typedef void (APIENTRYP PFNGLRESETHISTOGRAMEXTPROC) (GLenum target); +typedef void (APIENTRYP PFNGLRESETMINMAXEXTPROC) (GLenum target); +#endif + +#ifndef GL_EXT_convolution +#define GL_EXT_convolution 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glConvolutionFilter1DEXT (GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const GLvoid *image); +GLAPI void APIENTRY glConvolutionFilter2DEXT (GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *image); +GLAPI void APIENTRY glConvolutionParameterfEXT (GLenum target, GLenum pname, GLfloat params); +GLAPI void APIENTRY glConvolutionParameterfvEXT (GLenum target, GLenum pname, const GLfloat *params); +GLAPI void APIENTRY glConvolutionParameteriEXT (GLenum target, GLenum pname, GLint params); +GLAPI void APIENTRY glConvolutionParameterivEXT (GLenum target, GLenum pname, const GLint *params); +GLAPI void APIENTRY glCopyConvolutionFilter1DEXT (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width); +GLAPI void APIENTRY glCopyConvolutionFilter2DEXT (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height); +GLAPI void APIENTRY glGetConvolutionFilterEXT (GLenum target, GLenum format, GLenum type, GLvoid *image); +GLAPI void APIENTRY glGetConvolutionParameterfvEXT (GLenum target, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetConvolutionParameterivEXT (GLenum target, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetSeparableFilterEXT (GLenum target, GLenum format, GLenum type, GLvoid *row, GLvoid *column, GLvoid *span); +GLAPI void APIENTRY glSeparableFilter2DEXT (GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *row, const GLvoid *column); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCONVOLUTIONFILTER1DEXTPROC) (GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const GLvoid *image); +typedef void (APIENTRYP PFNGLCONVOLUTIONFILTER2DEXTPROC) (GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *image); +typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERFEXTPROC) (GLenum target, GLenum pname, GLfloat params); +typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERFVEXTPROC) (GLenum target, GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERIEXTPROC) (GLenum target, GLenum pname, GLint params); +typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERIVEXTPROC) (GLenum target, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLCOPYCONVOLUTIONFILTER1DEXTPROC) (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width); +typedef void (APIENTRYP PFNGLCOPYCONVOLUTIONFILTER2DEXTPROC) (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLGETCONVOLUTIONFILTEREXTPROC) (GLenum target, GLenum format, GLenum type, GLvoid *image); +typedef void (APIENTRYP PFNGLGETCONVOLUTIONPARAMETERFVEXTPROC) (GLenum target, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETCONVOLUTIONPARAMETERIVEXTPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETSEPARABLEFILTEREXTPROC) (GLenum target, GLenum format, GLenum type, GLvoid *row, GLvoid *column, GLvoid *span); +typedef void (APIENTRYP PFNGLSEPARABLEFILTER2DEXTPROC) (GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *row, const GLvoid *column); +#endif + +#ifndef GL_SGI_color_matrix +#define GL_SGI_color_matrix 1 +#endif + +#ifndef GL_SGI_color_table +#define GL_SGI_color_table 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glColorTableSGI (GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const GLvoid *table); +GLAPI void APIENTRY glColorTableParameterfvSGI (GLenum target, GLenum pname, const GLfloat *params); +GLAPI void APIENTRY glColorTableParameterivSGI (GLenum target, GLenum pname, const GLint *params); +GLAPI void APIENTRY glCopyColorTableSGI (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width); +GLAPI void APIENTRY glGetColorTableSGI (GLenum target, GLenum format, GLenum type, GLvoid *table); +GLAPI void APIENTRY glGetColorTableParameterfvSGI (GLenum target, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetColorTableParameterivSGI (GLenum target, GLenum pname, GLint *params); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCOLORTABLESGIPROC) (GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const GLvoid *table); +typedef void (APIENTRYP PFNGLCOLORTABLEPARAMETERFVSGIPROC) (GLenum target, GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLCOLORTABLEPARAMETERIVSGIPROC) (GLenum target, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLCOPYCOLORTABLESGIPROC) (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width); +typedef void (APIENTRYP PFNGLGETCOLORTABLESGIPROC) (GLenum target, GLenum format, GLenum type, GLvoid *table); +typedef void (APIENTRYP PFNGLGETCOLORTABLEPARAMETERFVSGIPROC) (GLenum target, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETCOLORTABLEPARAMETERIVSGIPROC) (GLenum target, GLenum pname, GLint *params); +#endif + +#ifndef GL_SGIX_pixel_texture +#define GL_SGIX_pixel_texture 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glPixelTexGenSGIX (GLenum mode); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPIXELTEXGENSGIXPROC) (GLenum mode); +#endif + +#ifndef GL_SGIS_pixel_texture +#define GL_SGIS_pixel_texture 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glPixelTexGenParameteriSGIS (GLenum pname, GLint param); +GLAPI void APIENTRY glPixelTexGenParameterivSGIS (GLenum pname, const GLint *params); +GLAPI void APIENTRY glPixelTexGenParameterfSGIS (GLenum pname, GLfloat param); +GLAPI void APIENTRY glPixelTexGenParameterfvSGIS (GLenum pname, const GLfloat *params); +GLAPI void APIENTRY glGetPixelTexGenParameterivSGIS (GLenum pname, GLint *params); +GLAPI void APIENTRY glGetPixelTexGenParameterfvSGIS (GLenum pname, GLfloat *params); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPIXELTEXGENPARAMETERISGISPROC) (GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLPIXELTEXGENPARAMETERIVSGISPROC) (GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLPIXELTEXGENPARAMETERFSGISPROC) (GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLPIXELTEXGENPARAMETERFVSGISPROC) (GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLGETPIXELTEXGENPARAMETERIVSGISPROC) (GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETPIXELTEXGENPARAMETERFVSGISPROC) (GLenum pname, GLfloat *params); +#endif + +#ifndef GL_SGIS_texture4D +#define GL_SGIS_texture4D 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTexImage4DSGIS (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLsizei size4d, GLint border, GLenum format, GLenum type, const GLvoid *pixels); +GLAPI void APIENTRY glTexSubImage4DSGIS (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint woffset, GLsizei width, GLsizei height, GLsizei depth, GLsizei size4d, GLenum format, GLenum type, const GLvoid *pixels); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLTEXIMAGE4DSGISPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLsizei size4d, GLint border, GLenum format, GLenum type, const GLvoid *pixels); +typedef void (APIENTRYP PFNGLTEXSUBIMAGE4DSGISPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint woffset, GLsizei width, GLsizei height, GLsizei depth, GLsizei size4d, GLenum format, GLenum type, const GLvoid *pixels); +#endif + +#ifndef GL_SGI_texture_color_table +#define GL_SGI_texture_color_table 1 +#endif + +#ifndef GL_EXT_cmyka +#define GL_EXT_cmyka 1 +#endif + +#ifndef GL_EXT_texture_object +#define GL_EXT_texture_object 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI GLboolean APIENTRY glAreTexturesResidentEXT (GLsizei n, const GLuint *textures, GLboolean *residences); +GLAPI void APIENTRY glBindTextureEXT (GLenum target, GLuint texture); +GLAPI void APIENTRY glDeleteTexturesEXT (GLsizei n, const GLuint *textures); +GLAPI void APIENTRY glGenTexturesEXT (GLsizei n, GLuint *textures); +GLAPI GLboolean APIENTRY glIsTextureEXT (GLuint texture); +GLAPI void APIENTRY glPrioritizeTexturesEXT (GLsizei n, const GLuint *textures, const GLclampf *priorities); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef GLboolean (APIENTRYP PFNGLARETEXTURESRESIDENTEXTPROC) (GLsizei n, const GLuint *textures, GLboolean *residences); +typedef void (APIENTRYP PFNGLBINDTEXTUREEXTPROC) (GLenum target, GLuint texture); +typedef void (APIENTRYP PFNGLDELETETEXTURESEXTPROC) (GLsizei n, const GLuint *textures); +typedef void (APIENTRYP PFNGLGENTEXTURESEXTPROC) (GLsizei n, GLuint *textures); +typedef GLboolean (APIENTRYP PFNGLISTEXTUREEXTPROC) (GLuint texture); +typedef void (APIENTRYP PFNGLPRIORITIZETEXTURESEXTPROC) (GLsizei n, const GLuint *textures, const GLclampf *priorities); +#endif + +#ifndef GL_SGIS_detail_texture +#define GL_SGIS_detail_texture 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDetailTexFuncSGIS (GLenum target, GLsizei n, const GLfloat *points); +GLAPI void APIENTRY glGetDetailTexFuncSGIS (GLenum target, GLfloat *points); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDETAILTEXFUNCSGISPROC) (GLenum target, GLsizei n, const GLfloat *points); +typedef void (APIENTRYP PFNGLGETDETAILTEXFUNCSGISPROC) (GLenum target, GLfloat *points); +#endif + +#ifndef GL_SGIS_sharpen_texture +#define GL_SGIS_sharpen_texture 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glSharpenTexFuncSGIS (GLenum target, GLsizei n, const GLfloat *points); +GLAPI void APIENTRY glGetSharpenTexFuncSGIS (GLenum target, GLfloat *points); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLSHARPENTEXFUNCSGISPROC) (GLenum target, GLsizei n, const GLfloat *points); +typedef void (APIENTRYP PFNGLGETSHARPENTEXFUNCSGISPROC) (GLenum target, GLfloat *points); +#endif + +#ifndef GL_EXT_packed_pixels +#define GL_EXT_packed_pixels 1 +#endif + +#ifndef GL_SGIS_texture_lod +#define GL_SGIS_texture_lod 1 +#endif + +#ifndef GL_SGIS_multisample +#define GL_SGIS_multisample 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glSampleMaskSGIS (GLclampf value, GLboolean invert); +GLAPI void APIENTRY glSamplePatternSGIS (GLenum pattern); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLSAMPLEMASKSGISPROC) (GLclampf value, GLboolean invert); +typedef void (APIENTRYP PFNGLSAMPLEPATTERNSGISPROC) (GLenum pattern); +#endif + +#ifndef GL_EXT_rescale_normal +#define GL_EXT_rescale_normal 1 +#endif + +#ifndef GL_EXT_vertex_array +#define GL_EXT_vertex_array 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glArrayElementEXT (GLint i); +GLAPI void APIENTRY glColorPointerEXT (GLint size, GLenum type, GLsizei stride, GLsizei count, const GLvoid *pointer); +GLAPI void APIENTRY glDrawArraysEXT (GLenum mode, GLint first, GLsizei count); +GLAPI void APIENTRY glEdgeFlagPointerEXT (GLsizei stride, GLsizei count, const GLboolean *pointer); +GLAPI void APIENTRY glGetPointervEXT (GLenum pname, GLvoid* *params); +GLAPI void APIENTRY glIndexPointerEXT (GLenum type, GLsizei stride, GLsizei count, const GLvoid *pointer); +GLAPI void APIENTRY glNormalPointerEXT (GLenum type, GLsizei stride, GLsizei count, const GLvoid *pointer); +GLAPI void APIENTRY glTexCoordPointerEXT (GLint size, GLenum type, GLsizei stride, GLsizei count, const GLvoid *pointer); +GLAPI void APIENTRY glVertexPointerEXT (GLint size, GLenum type, GLsizei stride, GLsizei count, const GLvoid *pointer); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLARRAYELEMENTEXTPROC) (GLint i); +typedef void (APIENTRYP PFNGLCOLORPOINTEREXTPROC) (GLint size, GLenum type, GLsizei stride, GLsizei count, const GLvoid *pointer); +typedef void (APIENTRYP PFNGLDRAWARRAYSEXTPROC) (GLenum mode, GLint first, GLsizei count); +typedef void (APIENTRYP PFNGLEDGEFLAGPOINTEREXTPROC) (GLsizei stride, GLsizei count, const GLboolean *pointer); +typedef void (APIENTRYP PFNGLGETPOINTERVEXTPROC) (GLenum pname, GLvoid* *params); +typedef void (APIENTRYP PFNGLINDEXPOINTEREXTPROC) (GLenum type, GLsizei stride, GLsizei count, const GLvoid *pointer); +typedef void (APIENTRYP PFNGLNORMALPOINTEREXTPROC) (GLenum type, GLsizei stride, GLsizei count, const GLvoid *pointer); +typedef void (APIENTRYP PFNGLTEXCOORDPOINTEREXTPROC) (GLint size, GLenum type, GLsizei stride, GLsizei count, const GLvoid *pointer); +typedef void (APIENTRYP PFNGLVERTEXPOINTEREXTPROC) (GLint size, GLenum type, GLsizei stride, GLsizei count, const GLvoid *pointer); +#endif + +#ifndef GL_EXT_misc_attribute +#define GL_EXT_misc_attribute 1 +#endif + +#ifndef GL_SGIS_generate_mipmap +#define GL_SGIS_generate_mipmap 1 +#endif + +#ifndef GL_SGIX_clipmap +#define GL_SGIX_clipmap 1 +#endif + +#ifndef GL_SGIX_shadow +#define GL_SGIX_shadow 1 +#endif + +#ifndef GL_SGIS_texture_edge_clamp +#define GL_SGIS_texture_edge_clamp 1 +#endif + +#ifndef GL_SGIS_texture_border_clamp +#define GL_SGIS_texture_border_clamp 1 +#endif + +#ifndef GL_EXT_blend_minmax +#define GL_EXT_blend_minmax 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBlendEquationEXT (GLenum mode); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBLENDEQUATIONEXTPROC) (GLenum mode); +#endif + +#ifndef GL_EXT_blend_subtract +#define GL_EXT_blend_subtract 1 +#endif + +#ifndef GL_EXT_blend_logic_op +#define GL_EXT_blend_logic_op 1 +#endif + +#ifndef GL_SGIX_interlace +#define GL_SGIX_interlace 1 +#endif + +#ifndef GL_SGIX_pixel_tiles +#define GL_SGIX_pixel_tiles 1 +#endif + +#ifndef GL_SGIX_texture_select +#define GL_SGIX_texture_select 1 +#endif + +#ifndef GL_SGIX_sprite +#define GL_SGIX_sprite 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glSpriteParameterfSGIX (GLenum pname, GLfloat param); +GLAPI void APIENTRY glSpriteParameterfvSGIX (GLenum pname, const GLfloat *params); +GLAPI void APIENTRY glSpriteParameteriSGIX (GLenum pname, GLint param); +GLAPI void APIENTRY glSpriteParameterivSGIX (GLenum pname, const GLint *params); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLSPRITEPARAMETERFSGIXPROC) (GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLSPRITEPARAMETERFVSGIXPROC) (GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLSPRITEPARAMETERISGIXPROC) (GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLSPRITEPARAMETERIVSGIXPROC) (GLenum pname, const GLint *params); +#endif + +#ifndef GL_SGIX_texture_multi_buffer +#define GL_SGIX_texture_multi_buffer 1 +#endif + +#ifndef GL_EXT_point_parameters +#define GL_EXT_point_parameters 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glPointParameterfEXT (GLenum pname, GLfloat param); +GLAPI void APIENTRY glPointParameterfvEXT (GLenum pname, const GLfloat *params); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPOINTPARAMETERFEXTPROC) (GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLPOINTPARAMETERFVEXTPROC) (GLenum pname, const GLfloat *params); +#endif + +#ifndef GL_SGIS_point_parameters +#define GL_SGIS_point_parameters 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glPointParameterfSGIS (GLenum pname, GLfloat param); +GLAPI void APIENTRY glPointParameterfvSGIS (GLenum pname, const GLfloat *params); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPOINTPARAMETERFSGISPROC) (GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLPOINTPARAMETERFVSGISPROC) (GLenum pname, const GLfloat *params); +#endif + +#ifndef GL_SGIX_instruments +#define GL_SGIX_instruments 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI GLint APIENTRY glGetInstrumentsSGIX (void); +GLAPI void APIENTRY glInstrumentsBufferSGIX (GLsizei size, GLint *buffer); +GLAPI GLint APIENTRY glPollInstrumentsSGIX (GLint *marker_p); +GLAPI void APIENTRY glReadInstrumentsSGIX (GLint marker); +GLAPI void APIENTRY glStartInstrumentsSGIX (void); +GLAPI void APIENTRY glStopInstrumentsSGIX (GLint marker); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef GLint (APIENTRYP PFNGLGETINSTRUMENTSSGIXPROC) (void); +typedef void (APIENTRYP PFNGLINSTRUMENTSBUFFERSGIXPROC) (GLsizei size, GLint *buffer); +typedef GLint (APIENTRYP PFNGLPOLLINSTRUMENTSSGIXPROC) (GLint *marker_p); +typedef void (APIENTRYP PFNGLREADINSTRUMENTSSGIXPROC) (GLint marker); +typedef void (APIENTRYP PFNGLSTARTINSTRUMENTSSGIXPROC) (void); +typedef void (APIENTRYP PFNGLSTOPINSTRUMENTSSGIXPROC) (GLint marker); +#endif + +#ifndef GL_SGIX_texture_scale_bias +#define GL_SGIX_texture_scale_bias 1 +#endif + +#ifndef GL_SGIX_framezoom +#define GL_SGIX_framezoom 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glFrameZoomSGIX (GLint factor); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLFRAMEZOOMSGIXPROC) (GLint factor); +#endif + +#ifndef GL_SGIX_tag_sample_buffer +#define GL_SGIX_tag_sample_buffer 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTagSampleBufferSGIX (void); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLTAGSAMPLEBUFFERSGIXPROC) (void); +#endif + +#ifndef GL_SGIX_polynomial_ffd +#define GL_SGIX_polynomial_ffd 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDeformationMap3dSGIX (GLenum target, GLdouble u1, GLdouble u2, GLint ustride, GLint uorder, GLdouble v1, GLdouble v2, GLint vstride, GLint vorder, GLdouble w1, GLdouble w2, GLint wstride, GLint worder, const GLdouble *points); +GLAPI void APIENTRY glDeformationMap3fSGIX (GLenum target, GLfloat u1, GLfloat u2, GLint ustride, GLint uorder, GLfloat v1, GLfloat v2, GLint vstride, GLint vorder, GLfloat w1, GLfloat w2, GLint wstride, GLint worder, const GLfloat *points); +GLAPI void APIENTRY glDeformSGIX (GLbitfield mask); +GLAPI void APIENTRY glLoadIdentityDeformationMapSGIX (GLbitfield mask); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDEFORMATIONMAP3DSGIXPROC) (GLenum target, GLdouble u1, GLdouble u2, GLint ustride, GLint uorder, GLdouble v1, GLdouble v2, GLint vstride, GLint vorder, GLdouble w1, GLdouble w2, GLint wstride, GLint worder, const GLdouble *points); +typedef void (APIENTRYP PFNGLDEFORMATIONMAP3FSGIXPROC) (GLenum target, GLfloat u1, GLfloat u2, GLint ustride, GLint uorder, GLfloat v1, GLfloat v2, GLint vstride, GLint vorder, GLfloat w1, GLfloat w2, GLint wstride, GLint worder, const GLfloat *points); +typedef void (APIENTRYP PFNGLDEFORMSGIXPROC) (GLbitfield mask); +typedef void (APIENTRYP PFNGLLOADIDENTITYDEFORMATIONMAPSGIXPROC) (GLbitfield mask); +#endif + +#ifndef GL_SGIX_reference_plane +#define GL_SGIX_reference_plane 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glReferencePlaneSGIX (const GLdouble *equation); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLREFERENCEPLANESGIXPROC) (const GLdouble *equation); +#endif + +#ifndef GL_SGIX_flush_raster +#define GL_SGIX_flush_raster 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glFlushRasterSGIX (void); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLFLUSHRASTERSGIXPROC) (void); +#endif + +#ifndef GL_SGIX_depth_texture +#define GL_SGIX_depth_texture 1 +#endif + +#ifndef GL_SGIS_fog_function +#define GL_SGIS_fog_function 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glFogFuncSGIS (GLsizei n, const GLfloat *points); +GLAPI void APIENTRY glGetFogFuncSGIS (GLfloat *points); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLFOGFUNCSGISPROC) (GLsizei n, const GLfloat *points); +typedef void (APIENTRYP PFNGLGETFOGFUNCSGISPROC) (GLfloat *points); +#endif + +#ifndef GL_SGIX_fog_offset +#define GL_SGIX_fog_offset 1 +#endif + +#ifndef GL_HP_image_transform +#define GL_HP_image_transform 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glImageTransformParameteriHP (GLenum target, GLenum pname, GLint param); +GLAPI void APIENTRY glImageTransformParameterfHP (GLenum target, GLenum pname, GLfloat param); +GLAPI void APIENTRY glImageTransformParameterivHP (GLenum target, GLenum pname, const GLint *params); +GLAPI void APIENTRY glImageTransformParameterfvHP (GLenum target, GLenum pname, const GLfloat *params); +GLAPI void APIENTRY glGetImageTransformParameterivHP (GLenum target, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetImageTransformParameterfvHP (GLenum target, GLenum pname, GLfloat *params); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLIMAGETRANSFORMPARAMETERIHPPROC) (GLenum target, GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLIMAGETRANSFORMPARAMETERFHPPROC) (GLenum target, GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLIMAGETRANSFORMPARAMETERIVHPPROC) (GLenum target, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLIMAGETRANSFORMPARAMETERFVHPPROC) (GLenum target, GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLGETIMAGETRANSFORMPARAMETERIVHPPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETIMAGETRANSFORMPARAMETERFVHPPROC) (GLenum target, GLenum pname, GLfloat *params); +#endif + +#ifndef GL_HP_convolution_border_modes +#define GL_HP_convolution_border_modes 1 +#endif + +#ifndef GL_SGIX_texture_add_env +#define GL_SGIX_texture_add_env 1 +#endif + +#ifndef GL_EXT_color_subtable +#define GL_EXT_color_subtable 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glColorSubTableEXT (GLenum target, GLsizei start, GLsizei count, GLenum format, GLenum type, const GLvoid *data); +GLAPI void APIENTRY glCopyColorSubTableEXT (GLenum target, GLsizei start, GLint x, GLint y, GLsizei width); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCOLORSUBTABLEEXTPROC) (GLenum target, GLsizei start, GLsizei count, GLenum format, GLenum type, const GLvoid *data); +typedef void (APIENTRYP PFNGLCOPYCOLORSUBTABLEEXTPROC) (GLenum target, GLsizei start, GLint x, GLint y, GLsizei width); +#endif + +#ifndef GL_PGI_vertex_hints +#define GL_PGI_vertex_hints 1 +#endif + +#ifndef GL_PGI_misc_hints +#define GL_PGI_misc_hints 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glHintPGI (GLenum target, GLint mode); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLHINTPGIPROC) (GLenum target, GLint mode); +#endif + +#ifndef GL_EXT_paletted_texture +#define GL_EXT_paletted_texture 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glColorTableEXT (GLenum target, GLenum internalFormat, GLsizei width, GLenum format, GLenum type, const GLvoid *table); +GLAPI void APIENTRY glGetColorTableEXT (GLenum target, GLenum format, GLenum type, GLvoid *data); +GLAPI void APIENTRY glGetColorTableParameterivEXT (GLenum target, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetColorTableParameterfvEXT (GLenum target, GLenum pname, GLfloat *params); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCOLORTABLEEXTPROC) (GLenum target, GLenum internalFormat, GLsizei width, GLenum format, GLenum type, const GLvoid *table); +typedef void (APIENTRYP PFNGLGETCOLORTABLEEXTPROC) (GLenum target, GLenum format, GLenum type, GLvoid *data); +typedef void (APIENTRYP PFNGLGETCOLORTABLEPARAMETERIVEXTPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETCOLORTABLEPARAMETERFVEXTPROC) (GLenum target, GLenum pname, GLfloat *params); +#endif + +#ifndef GL_EXT_clip_volume_hint +#define GL_EXT_clip_volume_hint 1 +#endif + +#ifndef GL_SGIX_list_priority +#define GL_SGIX_list_priority 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glGetListParameterfvSGIX (GLuint list, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetListParameterivSGIX (GLuint list, GLenum pname, GLint *params); +GLAPI void APIENTRY glListParameterfSGIX (GLuint list, GLenum pname, GLfloat param); +GLAPI void APIENTRY glListParameterfvSGIX (GLuint list, GLenum pname, const GLfloat *params); +GLAPI void APIENTRY glListParameteriSGIX (GLuint list, GLenum pname, GLint param); +GLAPI void APIENTRY glListParameterivSGIX (GLuint list, GLenum pname, const GLint *params); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGETLISTPARAMETERFVSGIXPROC) (GLuint list, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETLISTPARAMETERIVSGIXPROC) (GLuint list, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLLISTPARAMETERFSGIXPROC) (GLuint list, GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLLISTPARAMETERFVSGIXPROC) (GLuint list, GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLLISTPARAMETERISGIXPROC) (GLuint list, GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLLISTPARAMETERIVSGIXPROC) (GLuint list, GLenum pname, const GLint *params); +#endif + +#ifndef GL_SGIX_ir_instrument1 +#define GL_SGIX_ir_instrument1 1 +#endif + +#ifndef GL_SGIX_calligraphic_fragment +#define GL_SGIX_calligraphic_fragment 1 +#endif + +#ifndef GL_SGIX_texture_lod_bias +#define GL_SGIX_texture_lod_bias 1 +#endif + +#ifndef GL_SGIX_shadow_ambient +#define GL_SGIX_shadow_ambient 1 +#endif + +#ifndef GL_EXT_index_texture +#define GL_EXT_index_texture 1 +#endif + +#ifndef GL_EXT_index_material +#define GL_EXT_index_material 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glIndexMaterialEXT (GLenum face, GLenum mode); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLINDEXMATERIALEXTPROC) (GLenum face, GLenum mode); +#endif + +#ifndef GL_EXT_index_func +#define GL_EXT_index_func 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glIndexFuncEXT (GLenum func, GLclampf ref); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLINDEXFUNCEXTPROC) (GLenum func, GLclampf ref); +#endif + +#ifndef GL_EXT_index_array_formats +#define GL_EXT_index_array_formats 1 +#endif + +#ifndef GL_EXT_compiled_vertex_array +#define GL_EXT_compiled_vertex_array 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glLockArraysEXT (GLint first, GLsizei count); +GLAPI void APIENTRY glUnlockArraysEXT (void); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLLOCKARRAYSEXTPROC) (GLint first, GLsizei count); +typedef void (APIENTRYP PFNGLUNLOCKARRAYSEXTPROC) (void); +#endif + +#ifndef GL_EXT_cull_vertex +#define GL_EXT_cull_vertex 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glCullParameterdvEXT (GLenum pname, GLdouble *params); +GLAPI void APIENTRY glCullParameterfvEXT (GLenum pname, GLfloat *params); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCULLPARAMETERDVEXTPROC) (GLenum pname, GLdouble *params); +typedef void (APIENTRYP PFNGLCULLPARAMETERFVEXTPROC) (GLenum pname, GLfloat *params); +#endif + +#ifndef GL_SGIX_ycrcb +#define GL_SGIX_ycrcb 1 +#endif + +#ifndef GL_SGIX_fragment_lighting +#define GL_SGIX_fragment_lighting 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glFragmentColorMaterialSGIX (GLenum face, GLenum mode); +GLAPI void APIENTRY glFragmentLightfSGIX (GLenum light, GLenum pname, GLfloat param); +GLAPI void APIENTRY glFragmentLightfvSGIX (GLenum light, GLenum pname, const GLfloat *params); +GLAPI void APIENTRY glFragmentLightiSGIX (GLenum light, GLenum pname, GLint param); +GLAPI void APIENTRY glFragmentLightivSGIX (GLenum light, GLenum pname, const GLint *params); +GLAPI void APIENTRY glFragmentLightModelfSGIX (GLenum pname, GLfloat param); +GLAPI void APIENTRY glFragmentLightModelfvSGIX (GLenum pname, const GLfloat *params); +GLAPI void APIENTRY glFragmentLightModeliSGIX (GLenum pname, GLint param); +GLAPI void APIENTRY glFragmentLightModelivSGIX (GLenum pname, const GLint *params); +GLAPI void APIENTRY glFragmentMaterialfSGIX (GLenum face, GLenum pname, GLfloat param); +GLAPI void APIENTRY glFragmentMaterialfvSGIX (GLenum face, GLenum pname, const GLfloat *params); +GLAPI void APIENTRY glFragmentMaterialiSGIX (GLenum face, GLenum pname, GLint param); +GLAPI void APIENTRY glFragmentMaterialivSGIX (GLenum face, GLenum pname, const GLint *params); +GLAPI void APIENTRY glGetFragmentLightfvSGIX (GLenum light, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetFragmentLightivSGIX (GLenum light, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetFragmentMaterialfvSGIX (GLenum face, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetFragmentMaterialivSGIX (GLenum face, GLenum pname, GLint *params); +GLAPI void APIENTRY glLightEnviSGIX (GLenum pname, GLint param); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLFRAGMENTCOLORMATERIALSGIXPROC) (GLenum face, GLenum mode); +typedef void (APIENTRYP PFNGLFRAGMENTLIGHTFSGIXPROC) (GLenum light, GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLFRAGMENTLIGHTFVSGIXPROC) (GLenum light, GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLFRAGMENTLIGHTISGIXPROC) (GLenum light, GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLFRAGMENTLIGHTIVSGIXPROC) (GLenum light, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLFRAGMENTLIGHTMODELFSGIXPROC) (GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLFRAGMENTLIGHTMODELFVSGIXPROC) (GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLFRAGMENTLIGHTMODELISGIXPROC) (GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLFRAGMENTLIGHTMODELIVSGIXPROC) (GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLFRAGMENTMATERIALFSGIXPROC) (GLenum face, GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLFRAGMENTMATERIALFVSGIXPROC) (GLenum face, GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLFRAGMENTMATERIALISGIXPROC) (GLenum face, GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLFRAGMENTMATERIALIVSGIXPROC) (GLenum face, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLGETFRAGMENTLIGHTFVSGIXPROC) (GLenum light, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETFRAGMENTLIGHTIVSGIXPROC) (GLenum light, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETFRAGMENTMATERIALFVSGIXPROC) (GLenum face, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETFRAGMENTMATERIALIVSGIXPROC) (GLenum face, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLLIGHTENVISGIXPROC) (GLenum pname, GLint param); +#endif + +#ifndef GL_IBM_rasterpos_clip +#define GL_IBM_rasterpos_clip 1 +#endif + +#ifndef GL_HP_texture_lighting +#define GL_HP_texture_lighting 1 +#endif + +#ifndef GL_EXT_draw_range_elements +#define GL_EXT_draw_range_elements 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDrawRangeElementsEXT (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDRAWRANGEELEMENTSEXTPROC) (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices); +#endif + +#ifndef GL_WIN_phong_shading +#define GL_WIN_phong_shading 1 +#endif + +#ifndef GL_WIN_specular_fog +#define GL_WIN_specular_fog 1 +#endif + +#ifndef GL_EXT_light_texture +#define GL_EXT_light_texture 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glApplyTextureEXT (GLenum mode); +GLAPI void APIENTRY glTextureLightEXT (GLenum pname); +GLAPI void APIENTRY glTextureMaterialEXT (GLenum face, GLenum mode); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLAPPLYTEXTUREEXTPROC) (GLenum mode); +typedef void (APIENTRYP PFNGLTEXTURELIGHTEXTPROC) (GLenum pname); +typedef void (APIENTRYP PFNGLTEXTUREMATERIALEXTPROC) (GLenum face, GLenum mode); +#endif + +#ifndef GL_SGIX_blend_alpha_minmax +#define GL_SGIX_blend_alpha_minmax 1 +#endif + +#ifndef GL_EXT_bgra +#define GL_EXT_bgra 1 +#endif + +#ifndef GL_SGIX_async +#define GL_SGIX_async 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glAsyncMarkerSGIX (GLuint marker); +GLAPI GLint APIENTRY glFinishAsyncSGIX (GLuint *markerp); +GLAPI GLint APIENTRY glPollAsyncSGIX (GLuint *markerp); +GLAPI GLuint APIENTRY glGenAsyncMarkersSGIX (GLsizei range); +GLAPI void APIENTRY glDeleteAsyncMarkersSGIX (GLuint marker, GLsizei range); +GLAPI GLboolean APIENTRY glIsAsyncMarkerSGIX (GLuint marker); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLASYNCMARKERSGIXPROC) (GLuint marker); +typedef GLint (APIENTRYP PFNGLFINISHASYNCSGIXPROC) (GLuint *markerp); +typedef GLint (APIENTRYP PFNGLPOLLASYNCSGIXPROC) (GLuint *markerp); +typedef GLuint (APIENTRYP PFNGLGENASYNCMARKERSSGIXPROC) (GLsizei range); +typedef void (APIENTRYP PFNGLDELETEASYNCMARKERSSGIXPROC) (GLuint marker, GLsizei range); +typedef GLboolean (APIENTRYP PFNGLISASYNCMARKERSGIXPROC) (GLuint marker); +#endif + +#ifndef GL_SGIX_async_pixel +#define GL_SGIX_async_pixel 1 +#endif + +#ifndef GL_SGIX_async_histogram +#define GL_SGIX_async_histogram 1 +#endif + +#ifndef GL_INTEL_parallel_arrays +#define GL_INTEL_parallel_arrays 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glVertexPointervINTEL (GLint size, GLenum type, const GLvoid* *pointer); +GLAPI void APIENTRY glNormalPointervINTEL (GLenum type, const GLvoid* *pointer); +GLAPI void APIENTRY glColorPointervINTEL (GLint size, GLenum type, const GLvoid* *pointer); +GLAPI void APIENTRY glTexCoordPointervINTEL (GLint size, GLenum type, const GLvoid* *pointer); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLVERTEXPOINTERVINTELPROC) (GLint size, GLenum type, const GLvoid* *pointer); +typedef void (APIENTRYP PFNGLNORMALPOINTERVINTELPROC) (GLenum type, const GLvoid* *pointer); +typedef void (APIENTRYP PFNGLCOLORPOINTERVINTELPROC) (GLint size, GLenum type, const GLvoid* *pointer); +typedef void (APIENTRYP PFNGLTEXCOORDPOINTERVINTELPROC) (GLint size, GLenum type, const GLvoid* *pointer); +#endif + +#ifndef GL_HP_occlusion_test +#define GL_HP_occlusion_test 1 +#endif + +#ifndef GL_EXT_pixel_transform +#define GL_EXT_pixel_transform 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glPixelTransformParameteriEXT (GLenum target, GLenum pname, GLint param); +GLAPI void APIENTRY glPixelTransformParameterfEXT (GLenum target, GLenum pname, GLfloat param); +GLAPI void APIENTRY glPixelTransformParameterivEXT (GLenum target, GLenum pname, const GLint *params); +GLAPI void APIENTRY glPixelTransformParameterfvEXT (GLenum target, GLenum pname, const GLfloat *params); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPIXELTRANSFORMPARAMETERIEXTPROC) (GLenum target, GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLPIXELTRANSFORMPARAMETERFEXTPROC) (GLenum target, GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLPIXELTRANSFORMPARAMETERIVEXTPROC) (GLenum target, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLPIXELTRANSFORMPARAMETERFVEXTPROC) (GLenum target, GLenum pname, const GLfloat *params); +#endif + +#ifndef GL_EXT_pixel_transform_color_table +#define GL_EXT_pixel_transform_color_table 1 +#endif + +#ifndef GL_EXT_shared_texture_palette +#define GL_EXT_shared_texture_palette 1 +#endif + +#ifndef GL_EXT_separate_specular_color +#define GL_EXT_separate_specular_color 1 +#endif + +#ifndef GL_EXT_secondary_color +#define GL_EXT_secondary_color 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glSecondaryColor3bEXT (GLbyte red, GLbyte green, GLbyte blue); +GLAPI void APIENTRY glSecondaryColor3bvEXT (const GLbyte *v); +GLAPI void APIENTRY glSecondaryColor3dEXT (GLdouble red, GLdouble green, GLdouble blue); +GLAPI void APIENTRY glSecondaryColor3dvEXT (const GLdouble *v); +GLAPI void APIENTRY glSecondaryColor3fEXT (GLfloat red, GLfloat green, GLfloat blue); +GLAPI void APIENTRY glSecondaryColor3fvEXT (const GLfloat *v); +GLAPI void APIENTRY glSecondaryColor3iEXT (GLint red, GLint green, GLint blue); +GLAPI void APIENTRY glSecondaryColor3ivEXT (const GLint *v); +GLAPI void APIENTRY glSecondaryColor3sEXT (GLshort red, GLshort green, GLshort blue); +GLAPI void APIENTRY glSecondaryColor3svEXT (const GLshort *v); +GLAPI void APIENTRY glSecondaryColor3ubEXT (GLubyte red, GLubyte green, GLubyte blue); +GLAPI void APIENTRY glSecondaryColor3ubvEXT (const GLubyte *v); +GLAPI void APIENTRY glSecondaryColor3uiEXT (GLuint red, GLuint green, GLuint blue); +GLAPI void APIENTRY glSecondaryColor3uivEXT (const GLuint *v); +GLAPI void APIENTRY glSecondaryColor3usEXT (GLushort red, GLushort green, GLushort blue); +GLAPI void APIENTRY glSecondaryColor3usvEXT (const GLushort *v); +GLAPI void APIENTRY glSecondaryColorPointerEXT (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3BEXTPROC) (GLbyte red, GLbyte green, GLbyte blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3BVEXTPROC) (const GLbyte *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3DEXTPROC) (GLdouble red, GLdouble green, GLdouble blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3DVEXTPROC) (const GLdouble *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3FEXTPROC) (GLfloat red, GLfloat green, GLfloat blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3FVEXTPROC) (const GLfloat *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3IEXTPROC) (GLint red, GLint green, GLint blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3IVEXTPROC) (const GLint *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3SEXTPROC) (GLshort red, GLshort green, GLshort blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3SVEXTPROC) (const GLshort *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UBEXTPROC) (GLubyte red, GLubyte green, GLubyte blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UBVEXTPROC) (const GLubyte *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UIEXTPROC) (GLuint red, GLuint green, GLuint blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UIVEXTPROC) (const GLuint *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3USEXTPROC) (GLushort red, GLushort green, GLushort blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3USVEXTPROC) (const GLushort *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLORPOINTEREXTPROC) (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +#endif + +#ifndef GL_EXT_texture_perturb_normal +#define GL_EXT_texture_perturb_normal 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTextureNormalEXT (GLenum mode); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLTEXTURENORMALEXTPROC) (GLenum mode); +#endif + +#ifndef GL_EXT_multi_draw_arrays +#define GL_EXT_multi_draw_arrays 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glMultiDrawArraysEXT (GLenum mode, const GLint *first, const GLsizei *count, GLsizei primcount); +GLAPI void APIENTRY glMultiDrawElementsEXT (GLenum mode, const GLsizei *count, GLenum type, const GLvoid* *indices, GLsizei primcount); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLMULTIDRAWARRAYSEXTPROC) (GLenum mode, const GLint *first, const GLsizei *count, GLsizei primcount); +typedef void (APIENTRYP PFNGLMULTIDRAWELEMENTSEXTPROC) (GLenum mode, const GLsizei *count, GLenum type, const GLvoid* *indices, GLsizei primcount); +#endif + +#ifndef GL_EXT_fog_coord +#define GL_EXT_fog_coord 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glFogCoordfEXT (GLfloat coord); +GLAPI void APIENTRY glFogCoordfvEXT (const GLfloat *coord); +GLAPI void APIENTRY glFogCoorddEXT (GLdouble coord); +GLAPI void APIENTRY glFogCoorddvEXT (const GLdouble *coord); +GLAPI void APIENTRY glFogCoordPointerEXT (GLenum type, GLsizei stride, const GLvoid *pointer); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLFOGCOORDFEXTPROC) (GLfloat coord); +typedef void (APIENTRYP PFNGLFOGCOORDFVEXTPROC) (const GLfloat *coord); +typedef void (APIENTRYP PFNGLFOGCOORDDEXTPROC) (GLdouble coord); +typedef void (APIENTRYP PFNGLFOGCOORDDVEXTPROC) (const GLdouble *coord); +typedef void (APIENTRYP PFNGLFOGCOORDPOINTEREXTPROC) (GLenum type, GLsizei stride, const GLvoid *pointer); +#endif + +#ifndef GL_REND_screen_coordinates +#define GL_REND_screen_coordinates 1 +#endif + +#ifndef GL_EXT_coordinate_frame +#define GL_EXT_coordinate_frame 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTangent3bEXT (GLbyte tx, GLbyte ty, GLbyte tz); +GLAPI void APIENTRY glTangent3bvEXT (const GLbyte *v); +GLAPI void APIENTRY glTangent3dEXT (GLdouble tx, GLdouble ty, GLdouble tz); +GLAPI void APIENTRY glTangent3dvEXT (const GLdouble *v); +GLAPI void APIENTRY glTangent3fEXT (GLfloat tx, GLfloat ty, GLfloat tz); +GLAPI void APIENTRY glTangent3fvEXT (const GLfloat *v); +GLAPI void APIENTRY glTangent3iEXT (GLint tx, GLint ty, GLint tz); +GLAPI void APIENTRY glTangent3ivEXT (const GLint *v); +GLAPI void APIENTRY glTangent3sEXT (GLshort tx, GLshort ty, GLshort tz); +GLAPI void APIENTRY glTangent3svEXT (const GLshort *v); +GLAPI void APIENTRY glBinormal3bEXT (GLbyte bx, GLbyte by, GLbyte bz); +GLAPI void APIENTRY glBinormal3bvEXT (const GLbyte *v); +GLAPI void APIENTRY glBinormal3dEXT (GLdouble bx, GLdouble by, GLdouble bz); +GLAPI void APIENTRY glBinormal3dvEXT (const GLdouble *v); +GLAPI void APIENTRY glBinormal3fEXT (GLfloat bx, GLfloat by, GLfloat bz); +GLAPI void APIENTRY glBinormal3fvEXT (const GLfloat *v); +GLAPI void APIENTRY glBinormal3iEXT (GLint bx, GLint by, GLint bz); +GLAPI void APIENTRY glBinormal3ivEXT (const GLint *v); +GLAPI void APIENTRY glBinormal3sEXT (GLshort bx, GLshort by, GLshort bz); +GLAPI void APIENTRY glBinormal3svEXT (const GLshort *v); +GLAPI void APIENTRY glTangentPointerEXT (GLenum type, GLsizei stride, const GLvoid *pointer); +GLAPI void APIENTRY glBinormalPointerEXT (GLenum type, GLsizei stride, const GLvoid *pointer); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLTANGENT3BEXTPROC) (GLbyte tx, GLbyte ty, GLbyte tz); +typedef void (APIENTRYP PFNGLTANGENT3BVEXTPROC) (const GLbyte *v); +typedef void (APIENTRYP PFNGLTANGENT3DEXTPROC) (GLdouble tx, GLdouble ty, GLdouble tz); +typedef void (APIENTRYP PFNGLTANGENT3DVEXTPROC) (const GLdouble *v); +typedef void (APIENTRYP PFNGLTANGENT3FEXTPROC) (GLfloat tx, GLfloat ty, GLfloat tz); +typedef void (APIENTRYP PFNGLTANGENT3FVEXTPROC) (const GLfloat *v); +typedef void (APIENTRYP PFNGLTANGENT3IEXTPROC) (GLint tx, GLint ty, GLint tz); +typedef void (APIENTRYP PFNGLTANGENT3IVEXTPROC) (const GLint *v); +typedef void (APIENTRYP PFNGLTANGENT3SEXTPROC) (GLshort tx, GLshort ty, GLshort tz); +typedef void (APIENTRYP PFNGLTANGENT3SVEXTPROC) (const GLshort *v); +typedef void (APIENTRYP PFNGLBINORMAL3BEXTPROC) (GLbyte bx, GLbyte by, GLbyte bz); +typedef void (APIENTRYP PFNGLBINORMAL3BVEXTPROC) (const GLbyte *v); +typedef void (APIENTRYP PFNGLBINORMAL3DEXTPROC) (GLdouble bx, GLdouble by, GLdouble bz); +typedef void (APIENTRYP PFNGLBINORMAL3DVEXTPROC) (const GLdouble *v); +typedef void (APIENTRYP PFNGLBINORMAL3FEXTPROC) (GLfloat bx, GLfloat by, GLfloat bz); +typedef void (APIENTRYP PFNGLBINORMAL3FVEXTPROC) (const GLfloat *v); +typedef void (APIENTRYP PFNGLBINORMAL3IEXTPROC) (GLint bx, GLint by, GLint bz); +typedef void (APIENTRYP PFNGLBINORMAL3IVEXTPROC) (const GLint *v); +typedef void (APIENTRYP PFNGLBINORMAL3SEXTPROC) (GLshort bx, GLshort by, GLshort bz); +typedef void (APIENTRYP PFNGLBINORMAL3SVEXTPROC) (const GLshort *v); +typedef void (APIENTRYP PFNGLTANGENTPOINTEREXTPROC) (GLenum type, GLsizei stride, const GLvoid *pointer); +typedef void (APIENTRYP PFNGLBINORMALPOINTEREXTPROC) (GLenum type, GLsizei stride, const GLvoid *pointer); +#endif + +#ifndef GL_EXT_texture_env_combine +#define GL_EXT_texture_env_combine 1 +#endif + +#ifndef GL_APPLE_specular_vector +#define GL_APPLE_specular_vector 1 +#endif + +#ifndef GL_APPLE_transform_hint +#define GL_APPLE_transform_hint 1 +#endif + +#ifndef GL_SGIX_fog_scale +#define GL_SGIX_fog_scale 1 +#endif + +#ifndef GL_SUNX_constant_data +#define GL_SUNX_constant_data 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glFinishTextureSUNX (void); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLFINISHTEXTURESUNXPROC) (void); +#endif + +#ifndef GL_SUN_global_alpha +#define GL_SUN_global_alpha 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glGlobalAlphaFactorbSUN (GLbyte factor); +GLAPI void APIENTRY glGlobalAlphaFactorsSUN (GLshort factor); +GLAPI void APIENTRY glGlobalAlphaFactoriSUN (GLint factor); +GLAPI void APIENTRY glGlobalAlphaFactorfSUN (GLfloat factor); +GLAPI void APIENTRY glGlobalAlphaFactordSUN (GLdouble factor); +GLAPI void APIENTRY glGlobalAlphaFactorubSUN (GLubyte factor); +GLAPI void APIENTRY glGlobalAlphaFactorusSUN (GLushort factor); +GLAPI void APIENTRY glGlobalAlphaFactoruiSUN (GLuint factor); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORBSUNPROC) (GLbyte factor); +typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORSSUNPROC) (GLshort factor); +typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORISUNPROC) (GLint factor); +typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORFSUNPROC) (GLfloat factor); +typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORDSUNPROC) (GLdouble factor); +typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORUBSUNPROC) (GLubyte factor); +typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORUSSUNPROC) (GLushort factor); +typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORUISUNPROC) (GLuint factor); +#endif + +#ifndef GL_SUN_triangle_list +#define GL_SUN_triangle_list 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glReplacementCodeuiSUN (GLuint code); +GLAPI void APIENTRY glReplacementCodeusSUN (GLushort code); +GLAPI void APIENTRY glReplacementCodeubSUN (GLubyte code); +GLAPI void APIENTRY glReplacementCodeuivSUN (const GLuint *code); +GLAPI void APIENTRY glReplacementCodeusvSUN (const GLushort *code); +GLAPI void APIENTRY glReplacementCodeubvSUN (const GLubyte *code); +GLAPI void APIENTRY glReplacementCodePointerSUN (GLenum type, GLsizei stride, const GLvoid* *pointer); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUISUNPROC) (GLuint code); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUSSUNPROC) (GLushort code); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUBSUNPROC) (GLubyte code); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUIVSUNPROC) (const GLuint *code); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUSVSUNPROC) (const GLushort *code); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUBVSUNPROC) (const GLubyte *code); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEPOINTERSUNPROC) (GLenum type, GLsizei stride, const GLvoid* *pointer); +#endif + +#ifndef GL_SUN_vertex +#define GL_SUN_vertex 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glColor4ubVertex2fSUN (GLubyte r, GLubyte g, GLubyte b, GLubyte a, GLfloat x, GLfloat y); +GLAPI void APIENTRY glColor4ubVertex2fvSUN (const GLubyte *c, const GLfloat *v); +GLAPI void APIENTRY glColor4ubVertex3fSUN (GLubyte r, GLubyte g, GLubyte b, GLubyte a, GLfloat x, GLfloat y, GLfloat z); +GLAPI void APIENTRY glColor4ubVertex3fvSUN (const GLubyte *c, const GLfloat *v); +GLAPI void APIENTRY glColor3fVertex3fSUN (GLfloat r, GLfloat g, GLfloat b, GLfloat x, GLfloat y, GLfloat z); +GLAPI void APIENTRY glColor3fVertex3fvSUN (const GLfloat *c, const GLfloat *v); +GLAPI void APIENTRY glNormal3fVertex3fSUN (GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); +GLAPI void APIENTRY glNormal3fVertex3fvSUN (const GLfloat *n, const GLfloat *v); +GLAPI void APIENTRY glColor4fNormal3fVertex3fSUN (GLfloat r, GLfloat g, GLfloat b, GLfloat a, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); +GLAPI void APIENTRY glColor4fNormal3fVertex3fvSUN (const GLfloat *c, const GLfloat *n, const GLfloat *v); +GLAPI void APIENTRY glTexCoord2fVertex3fSUN (GLfloat s, GLfloat t, GLfloat x, GLfloat y, GLfloat z); +GLAPI void APIENTRY glTexCoord2fVertex3fvSUN (const GLfloat *tc, const GLfloat *v); +GLAPI void APIENTRY glTexCoord4fVertex4fSUN (GLfloat s, GLfloat t, GLfloat p, GLfloat q, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +GLAPI void APIENTRY glTexCoord4fVertex4fvSUN (const GLfloat *tc, const GLfloat *v); +GLAPI void APIENTRY glTexCoord2fColor4ubVertex3fSUN (GLfloat s, GLfloat t, GLubyte r, GLubyte g, GLubyte b, GLubyte a, GLfloat x, GLfloat y, GLfloat z); +GLAPI void APIENTRY glTexCoord2fColor4ubVertex3fvSUN (const GLfloat *tc, const GLubyte *c, const GLfloat *v); +GLAPI void APIENTRY glTexCoord2fColor3fVertex3fSUN (GLfloat s, GLfloat t, GLfloat r, GLfloat g, GLfloat b, GLfloat x, GLfloat y, GLfloat z); +GLAPI void APIENTRY glTexCoord2fColor3fVertex3fvSUN (const GLfloat *tc, const GLfloat *c, const GLfloat *v); +GLAPI void APIENTRY glTexCoord2fNormal3fVertex3fSUN (GLfloat s, GLfloat t, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); +GLAPI void APIENTRY glTexCoord2fNormal3fVertex3fvSUN (const GLfloat *tc, const GLfloat *n, const GLfloat *v); +GLAPI void APIENTRY glTexCoord2fColor4fNormal3fVertex3fSUN (GLfloat s, GLfloat t, GLfloat r, GLfloat g, GLfloat b, GLfloat a, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); +GLAPI void APIENTRY glTexCoord2fColor4fNormal3fVertex3fvSUN (const GLfloat *tc, const GLfloat *c, const GLfloat *n, const GLfloat *v); +GLAPI void APIENTRY glTexCoord4fColor4fNormal3fVertex4fSUN (GLfloat s, GLfloat t, GLfloat p, GLfloat q, GLfloat r, GLfloat g, GLfloat b, GLfloat a, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +GLAPI void APIENTRY glTexCoord4fColor4fNormal3fVertex4fvSUN (const GLfloat *tc, const GLfloat *c, const GLfloat *n, const GLfloat *v); +GLAPI void APIENTRY glReplacementCodeuiVertex3fSUN (GLuint rc, GLfloat x, GLfloat y, GLfloat z); +GLAPI void APIENTRY glReplacementCodeuiVertex3fvSUN (const GLuint *rc, const GLfloat *v); +GLAPI void APIENTRY glReplacementCodeuiColor4ubVertex3fSUN (GLuint rc, GLubyte r, GLubyte g, GLubyte b, GLubyte a, GLfloat x, GLfloat y, GLfloat z); +GLAPI void APIENTRY glReplacementCodeuiColor4ubVertex3fvSUN (const GLuint *rc, const GLubyte *c, const GLfloat *v); +GLAPI void APIENTRY glReplacementCodeuiColor3fVertex3fSUN (GLuint rc, GLfloat r, GLfloat g, GLfloat b, GLfloat x, GLfloat y, GLfloat z); +GLAPI void APIENTRY glReplacementCodeuiColor3fVertex3fvSUN (const GLuint *rc, const GLfloat *c, const GLfloat *v); +GLAPI void APIENTRY glReplacementCodeuiNormal3fVertex3fSUN (GLuint rc, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); +GLAPI void APIENTRY glReplacementCodeuiNormal3fVertex3fvSUN (const GLuint *rc, const GLfloat *n, const GLfloat *v); +GLAPI void APIENTRY glReplacementCodeuiColor4fNormal3fVertex3fSUN (GLuint rc, GLfloat r, GLfloat g, GLfloat b, GLfloat a, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); +GLAPI void APIENTRY glReplacementCodeuiColor4fNormal3fVertex3fvSUN (const GLuint *rc, const GLfloat *c, const GLfloat *n, const GLfloat *v); +GLAPI void APIENTRY glReplacementCodeuiTexCoord2fVertex3fSUN (GLuint rc, GLfloat s, GLfloat t, GLfloat x, GLfloat y, GLfloat z); +GLAPI void APIENTRY glReplacementCodeuiTexCoord2fVertex3fvSUN (const GLuint *rc, const GLfloat *tc, const GLfloat *v); +GLAPI void APIENTRY glReplacementCodeuiTexCoord2fNormal3fVertex3fSUN (GLuint rc, GLfloat s, GLfloat t, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); +GLAPI void APIENTRY glReplacementCodeuiTexCoord2fNormal3fVertex3fvSUN (const GLuint *rc, const GLfloat *tc, const GLfloat *n, const GLfloat *v); +GLAPI void APIENTRY glReplacementCodeuiTexCoord2fColor4fNormal3fVertex3fSUN (GLuint rc, GLfloat s, GLfloat t, GLfloat r, GLfloat g, GLfloat b, GLfloat a, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); +GLAPI void APIENTRY glReplacementCodeuiTexCoord2fColor4fNormal3fVertex3fvSUN (const GLuint *rc, const GLfloat *tc, const GLfloat *c, const GLfloat *n, const GLfloat *v); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCOLOR4UBVERTEX2FSUNPROC) (GLubyte r, GLubyte g, GLubyte b, GLubyte a, GLfloat x, GLfloat y); +typedef void (APIENTRYP PFNGLCOLOR4UBVERTEX2FVSUNPROC) (const GLubyte *c, const GLfloat *v); +typedef void (APIENTRYP PFNGLCOLOR4UBVERTEX3FSUNPROC) (GLubyte r, GLubyte g, GLubyte b, GLubyte a, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLCOLOR4UBVERTEX3FVSUNPROC) (const GLubyte *c, const GLfloat *v); +typedef void (APIENTRYP PFNGLCOLOR3FVERTEX3FSUNPROC) (GLfloat r, GLfloat g, GLfloat b, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLCOLOR3FVERTEX3FVSUNPROC) (const GLfloat *c, const GLfloat *v); +typedef void (APIENTRYP PFNGLNORMAL3FVERTEX3FSUNPROC) (GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLNORMAL3FVERTEX3FVSUNPROC) (const GLfloat *n, const GLfloat *v); +typedef void (APIENTRYP PFNGLCOLOR4FNORMAL3FVERTEX3FSUNPROC) (GLfloat r, GLfloat g, GLfloat b, GLfloat a, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLCOLOR4FNORMAL3FVERTEX3FVSUNPROC) (const GLfloat *c, const GLfloat *n, const GLfloat *v); +typedef void (APIENTRYP PFNGLTEXCOORD2FVERTEX3FSUNPROC) (GLfloat s, GLfloat t, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLTEXCOORD2FVERTEX3FVSUNPROC) (const GLfloat *tc, const GLfloat *v); +typedef void (APIENTRYP PFNGLTEXCOORD4FVERTEX4FSUNPROC) (GLfloat s, GLfloat t, GLfloat p, GLfloat q, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +typedef void (APIENTRYP PFNGLTEXCOORD4FVERTEX4FVSUNPROC) (const GLfloat *tc, const GLfloat *v); +typedef void (APIENTRYP PFNGLTEXCOORD2FCOLOR4UBVERTEX3FSUNPROC) (GLfloat s, GLfloat t, GLubyte r, GLubyte g, GLubyte b, GLubyte a, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLTEXCOORD2FCOLOR4UBVERTEX3FVSUNPROC) (const GLfloat *tc, const GLubyte *c, const GLfloat *v); +typedef void (APIENTRYP PFNGLTEXCOORD2FCOLOR3FVERTEX3FSUNPROC) (GLfloat s, GLfloat t, GLfloat r, GLfloat g, GLfloat b, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLTEXCOORD2FCOLOR3FVERTEX3FVSUNPROC) (const GLfloat *tc, const GLfloat *c, const GLfloat *v); +typedef void (APIENTRYP PFNGLTEXCOORD2FNORMAL3FVERTEX3FSUNPROC) (GLfloat s, GLfloat t, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLTEXCOORD2FNORMAL3FVERTEX3FVSUNPROC) (const GLfloat *tc, const GLfloat *n, const GLfloat *v); +typedef void (APIENTRYP PFNGLTEXCOORD2FCOLOR4FNORMAL3FVERTEX3FSUNPROC) (GLfloat s, GLfloat t, GLfloat r, GLfloat g, GLfloat b, GLfloat a, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLTEXCOORD2FCOLOR4FNORMAL3FVERTEX3FVSUNPROC) (const GLfloat *tc, const GLfloat *c, const GLfloat *n, const GLfloat *v); +typedef void (APIENTRYP PFNGLTEXCOORD4FCOLOR4FNORMAL3FVERTEX4FSUNPROC) (GLfloat s, GLfloat t, GLfloat p, GLfloat q, GLfloat r, GLfloat g, GLfloat b, GLfloat a, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +typedef void (APIENTRYP PFNGLTEXCOORD4FCOLOR4FNORMAL3FVERTEX4FVSUNPROC) (const GLfloat *tc, const GLfloat *c, const GLfloat *n, const GLfloat *v); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUIVERTEX3FSUNPROC) (GLuint rc, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUIVERTEX3FVSUNPROC) (const GLuint *rc, const GLfloat *v); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUICOLOR4UBVERTEX3FSUNPROC) (GLuint rc, GLubyte r, GLubyte g, GLubyte b, GLubyte a, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUICOLOR4UBVERTEX3FVSUNPROC) (const GLuint *rc, const GLubyte *c, const GLfloat *v); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUICOLOR3FVERTEX3FSUNPROC) (GLuint rc, GLfloat r, GLfloat g, GLfloat b, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUICOLOR3FVERTEX3FVSUNPROC) (const GLuint *rc, const GLfloat *c, const GLfloat *v); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUINORMAL3FVERTEX3FSUNPROC) (GLuint rc, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUINORMAL3FVERTEX3FVSUNPROC) (const GLuint *rc, const GLfloat *n, const GLfloat *v); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUICOLOR4FNORMAL3FVERTEX3FSUNPROC) (GLuint rc, GLfloat r, GLfloat g, GLfloat b, GLfloat a, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUICOLOR4FNORMAL3FVERTEX3FVSUNPROC) (const GLuint *rc, const GLfloat *c, const GLfloat *n, const GLfloat *v); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUITEXCOORD2FVERTEX3FSUNPROC) (GLuint rc, GLfloat s, GLfloat t, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUITEXCOORD2FVERTEX3FVSUNPROC) (const GLuint *rc, const GLfloat *tc, const GLfloat *v); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUITEXCOORD2FNORMAL3FVERTEX3FSUNPROC) (GLuint rc, GLfloat s, GLfloat t, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUITEXCOORD2FNORMAL3FVERTEX3FVSUNPROC) (const GLuint *rc, const GLfloat *tc, const GLfloat *n, const GLfloat *v); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUITEXCOORD2FCOLOR4FNORMAL3FVERTEX3FSUNPROC) (GLuint rc, GLfloat s, GLfloat t, GLfloat r, GLfloat g, GLfloat b, GLfloat a, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUITEXCOORD2FCOLOR4FNORMAL3FVERTEX3FVSUNPROC) (const GLuint *rc, const GLfloat *tc, const GLfloat *c, const GLfloat *n, const GLfloat *v); +#endif + +#ifndef GL_EXT_blend_func_separate +#define GL_EXT_blend_func_separate 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBlendFuncSeparateEXT (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEEXTPROC) (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha); +#endif + +#ifndef GL_INGR_blend_func_separate +#define GL_INGR_blend_func_separate 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBlendFuncSeparateINGR (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEINGRPROC) (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha); +#endif + +#ifndef GL_INGR_color_clamp +#define GL_INGR_color_clamp 1 +#endif + +#ifndef GL_INGR_interlace_read +#define GL_INGR_interlace_read 1 +#endif + +#ifndef GL_EXT_stencil_wrap +#define GL_EXT_stencil_wrap 1 +#endif + +#ifndef GL_EXT_422_pixels +#define GL_EXT_422_pixels 1 +#endif + +#ifndef GL_NV_texgen_reflection +#define GL_NV_texgen_reflection 1 +#endif + +#ifndef GL_SUN_convolution_border_modes +#define GL_SUN_convolution_border_modes 1 +#endif + +#ifndef GL_EXT_texture_env_add +#define GL_EXT_texture_env_add 1 +#endif + +#ifndef GL_EXT_texture_lod_bias +#define GL_EXT_texture_lod_bias 1 +#endif + +#ifndef GL_EXT_texture_filter_anisotropic +#define GL_EXT_texture_filter_anisotropic 1 +#endif + +#ifndef GL_EXT_vertex_weighting +#define GL_EXT_vertex_weighting 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glVertexWeightfEXT (GLfloat weight); +GLAPI void APIENTRY glVertexWeightfvEXT (const GLfloat *weight); +GLAPI void APIENTRY glVertexWeightPointerEXT (GLsizei size, GLenum type, GLsizei stride, const GLvoid *pointer); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLVERTEXWEIGHTFEXTPROC) (GLfloat weight); +typedef void (APIENTRYP PFNGLVERTEXWEIGHTFVEXTPROC) (const GLfloat *weight); +typedef void (APIENTRYP PFNGLVERTEXWEIGHTPOINTEREXTPROC) (GLsizei size, GLenum type, GLsizei stride, const GLvoid *pointer); +#endif + +#ifndef GL_NV_light_max_exponent +#define GL_NV_light_max_exponent 1 +#endif + +#ifndef GL_NV_vertex_array_range +#define GL_NV_vertex_array_range 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glFlushVertexArrayRangeNV (void); +GLAPI void APIENTRY glVertexArrayRangeNV (GLsizei length, const GLvoid *pointer); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLFLUSHVERTEXARRAYRANGENVPROC) (void); +typedef void (APIENTRYP PFNGLVERTEXARRAYRANGENVPROC) (GLsizei length, const GLvoid *pointer); +#endif + +#ifndef GL_NV_register_combiners +#define GL_NV_register_combiners 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glCombinerParameterfvNV (GLenum pname, const GLfloat *params); +GLAPI void APIENTRY glCombinerParameterfNV (GLenum pname, GLfloat param); +GLAPI void APIENTRY glCombinerParameterivNV (GLenum pname, const GLint *params); +GLAPI void APIENTRY glCombinerParameteriNV (GLenum pname, GLint param); +GLAPI void APIENTRY glCombinerInputNV (GLenum stage, GLenum portion, GLenum variable, GLenum input, GLenum mapping, GLenum componentUsage); +GLAPI void APIENTRY glCombinerOutputNV (GLenum stage, GLenum portion, GLenum abOutput, GLenum cdOutput, GLenum sumOutput, GLenum scale, GLenum bias, GLboolean abDotProduct, GLboolean cdDotProduct, GLboolean muxSum); +GLAPI void APIENTRY glFinalCombinerInputNV (GLenum variable, GLenum input, GLenum mapping, GLenum componentUsage); +GLAPI void APIENTRY glGetCombinerInputParameterfvNV (GLenum stage, GLenum portion, GLenum variable, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetCombinerInputParameterivNV (GLenum stage, GLenum portion, GLenum variable, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetCombinerOutputParameterfvNV (GLenum stage, GLenum portion, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetCombinerOutputParameterivNV (GLenum stage, GLenum portion, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetFinalCombinerInputParameterfvNV (GLenum variable, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetFinalCombinerInputParameterivNV (GLenum variable, GLenum pname, GLint *params); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCOMBINERPARAMETERFVNVPROC) (GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLCOMBINERPARAMETERFNVPROC) (GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLCOMBINERPARAMETERIVNVPROC) (GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLCOMBINERPARAMETERINVPROC) (GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLCOMBINERINPUTNVPROC) (GLenum stage, GLenum portion, GLenum variable, GLenum input, GLenum mapping, GLenum componentUsage); +typedef void (APIENTRYP PFNGLCOMBINEROUTPUTNVPROC) (GLenum stage, GLenum portion, GLenum abOutput, GLenum cdOutput, GLenum sumOutput, GLenum scale, GLenum bias, GLboolean abDotProduct, GLboolean cdDotProduct, GLboolean muxSum); +typedef void (APIENTRYP PFNGLFINALCOMBINERINPUTNVPROC) (GLenum variable, GLenum input, GLenum mapping, GLenum componentUsage); +typedef void (APIENTRYP PFNGLGETCOMBINERINPUTPARAMETERFVNVPROC) (GLenum stage, GLenum portion, GLenum variable, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETCOMBINERINPUTPARAMETERIVNVPROC) (GLenum stage, GLenum portion, GLenum variable, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETCOMBINEROUTPUTPARAMETERFVNVPROC) (GLenum stage, GLenum portion, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETCOMBINEROUTPUTPARAMETERIVNVPROC) (GLenum stage, GLenum portion, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETFINALCOMBINERINPUTPARAMETERFVNVPROC) (GLenum variable, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETFINALCOMBINERINPUTPARAMETERIVNVPROC) (GLenum variable, GLenum pname, GLint *params); +#endif + +#ifndef GL_NV_fog_distance +#define GL_NV_fog_distance 1 +#endif + +#ifndef GL_NV_texgen_emboss +#define GL_NV_texgen_emboss 1 +#endif + +#ifndef GL_NV_blend_square +#define GL_NV_blend_square 1 +#endif + +#ifndef GL_NV_texture_env_combine4 +#define GL_NV_texture_env_combine4 1 +#endif + +#ifndef GL_MESA_resize_buffers +#define GL_MESA_resize_buffers 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glResizeBuffersMESA (void); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLRESIZEBUFFERSMESAPROC) (void); +#endif + +#ifndef GL_MESA_window_pos +#define GL_MESA_window_pos 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glWindowPos2dMESA (GLdouble x, GLdouble y); +GLAPI void APIENTRY glWindowPos2dvMESA (const GLdouble *v); +GLAPI void APIENTRY glWindowPos2fMESA (GLfloat x, GLfloat y); +GLAPI void APIENTRY glWindowPos2fvMESA (const GLfloat *v); +GLAPI void APIENTRY glWindowPos2iMESA (GLint x, GLint y); +GLAPI void APIENTRY glWindowPos2ivMESA (const GLint *v); +GLAPI void APIENTRY glWindowPos2sMESA (GLshort x, GLshort y); +GLAPI void APIENTRY glWindowPos2svMESA (const GLshort *v); +GLAPI void APIENTRY glWindowPos3dMESA (GLdouble x, GLdouble y, GLdouble z); +GLAPI void APIENTRY glWindowPos3dvMESA (const GLdouble *v); +GLAPI void APIENTRY glWindowPos3fMESA (GLfloat x, GLfloat y, GLfloat z); +GLAPI void APIENTRY glWindowPos3fvMESA (const GLfloat *v); +GLAPI void APIENTRY glWindowPos3iMESA (GLint x, GLint y, GLint z); +GLAPI void APIENTRY glWindowPos3ivMESA (const GLint *v); +GLAPI void APIENTRY glWindowPos3sMESA (GLshort x, GLshort y, GLshort z); +GLAPI void APIENTRY glWindowPos3svMESA (const GLshort *v); +GLAPI void APIENTRY glWindowPos4dMESA (GLdouble x, GLdouble y, GLdouble z, GLdouble w); +GLAPI void APIENTRY glWindowPos4dvMESA (const GLdouble *v); +GLAPI void APIENTRY glWindowPos4fMESA (GLfloat x, GLfloat y, GLfloat z, GLfloat w); +GLAPI void APIENTRY glWindowPos4fvMESA (const GLfloat *v); +GLAPI void APIENTRY glWindowPos4iMESA (GLint x, GLint y, GLint z, GLint w); +GLAPI void APIENTRY glWindowPos4ivMESA (const GLint *v); +GLAPI void APIENTRY glWindowPos4sMESA (GLshort x, GLshort y, GLshort z, GLshort w); +GLAPI void APIENTRY glWindowPos4svMESA (const GLshort *v); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLWINDOWPOS2DMESAPROC) (GLdouble x, GLdouble y); +typedef void (APIENTRYP PFNGLWINDOWPOS2DVMESAPROC) (const GLdouble *v); +typedef void (APIENTRYP PFNGLWINDOWPOS2FMESAPROC) (GLfloat x, GLfloat y); +typedef void (APIENTRYP PFNGLWINDOWPOS2FVMESAPROC) (const GLfloat *v); +typedef void (APIENTRYP PFNGLWINDOWPOS2IMESAPROC) (GLint x, GLint y); +typedef void (APIENTRYP PFNGLWINDOWPOS2IVMESAPROC) (const GLint *v); +typedef void (APIENTRYP PFNGLWINDOWPOS2SMESAPROC) (GLshort x, GLshort y); +typedef void (APIENTRYP PFNGLWINDOWPOS2SVMESAPROC) (const GLshort *v); +typedef void (APIENTRYP PFNGLWINDOWPOS3DMESAPROC) (GLdouble x, GLdouble y, GLdouble z); +typedef void (APIENTRYP PFNGLWINDOWPOS3DVMESAPROC) (const GLdouble *v); +typedef void (APIENTRYP PFNGLWINDOWPOS3FMESAPROC) (GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLWINDOWPOS3FVMESAPROC) (const GLfloat *v); +typedef void (APIENTRYP PFNGLWINDOWPOS3IMESAPROC) (GLint x, GLint y, GLint z); +typedef void (APIENTRYP PFNGLWINDOWPOS3IVMESAPROC) (const GLint *v); +typedef void (APIENTRYP PFNGLWINDOWPOS3SMESAPROC) (GLshort x, GLshort y, GLshort z); +typedef void (APIENTRYP PFNGLWINDOWPOS3SVMESAPROC) (const GLshort *v); +typedef void (APIENTRYP PFNGLWINDOWPOS4DMESAPROC) (GLdouble x, GLdouble y, GLdouble z, GLdouble w); +typedef void (APIENTRYP PFNGLWINDOWPOS4DVMESAPROC) (const GLdouble *v); +typedef void (APIENTRYP PFNGLWINDOWPOS4FMESAPROC) (GLfloat x, GLfloat y, GLfloat z, GLfloat w); +typedef void (APIENTRYP PFNGLWINDOWPOS4FVMESAPROC) (const GLfloat *v); +typedef void (APIENTRYP PFNGLWINDOWPOS4IMESAPROC) (GLint x, GLint y, GLint z, GLint w); +typedef void (APIENTRYP PFNGLWINDOWPOS4IVMESAPROC) (const GLint *v); +typedef void (APIENTRYP PFNGLWINDOWPOS4SMESAPROC) (GLshort x, GLshort y, GLshort z, GLshort w); +typedef void (APIENTRYP PFNGLWINDOWPOS4SVMESAPROC) (const GLshort *v); +#endif + +#ifndef GL_IBM_cull_vertex +#define GL_IBM_cull_vertex 1 +#endif + +#ifndef GL_IBM_multimode_draw_arrays +#define GL_IBM_multimode_draw_arrays 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glMultiModeDrawArraysIBM (const GLenum *mode, const GLint *first, const GLsizei *count, GLsizei primcount, GLint modestride); +GLAPI void APIENTRY glMultiModeDrawElementsIBM (const GLenum *mode, const GLsizei *count, GLenum type, const GLvoid* const *indices, GLsizei primcount, GLint modestride); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLMULTIMODEDRAWARRAYSIBMPROC) (const GLenum *mode, const GLint *first, const GLsizei *count, GLsizei primcount, GLint modestride); +typedef void (APIENTRYP PFNGLMULTIMODEDRAWELEMENTSIBMPROC) (const GLenum *mode, const GLsizei *count, GLenum type, const GLvoid* const *indices, GLsizei primcount, GLint modestride); +#endif + +#ifndef GL_IBM_vertex_array_lists +#define GL_IBM_vertex_array_lists 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glColorPointerListIBM (GLint size, GLenum type, GLint stride, const GLvoid* *pointer, GLint ptrstride); +GLAPI void APIENTRY glSecondaryColorPointerListIBM (GLint size, GLenum type, GLint stride, const GLvoid* *pointer, GLint ptrstride); +GLAPI void APIENTRY glEdgeFlagPointerListIBM (GLint stride, const GLboolean* *pointer, GLint ptrstride); +GLAPI void APIENTRY glFogCoordPointerListIBM (GLenum type, GLint stride, const GLvoid* *pointer, GLint ptrstride); +GLAPI void APIENTRY glIndexPointerListIBM (GLenum type, GLint stride, const GLvoid* *pointer, GLint ptrstride); +GLAPI void APIENTRY glNormalPointerListIBM (GLenum type, GLint stride, const GLvoid* *pointer, GLint ptrstride); +GLAPI void APIENTRY glTexCoordPointerListIBM (GLint size, GLenum type, GLint stride, const GLvoid* *pointer, GLint ptrstride); +GLAPI void APIENTRY glVertexPointerListIBM (GLint size, GLenum type, GLint stride, const GLvoid* *pointer, GLint ptrstride); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCOLORPOINTERLISTIBMPROC) (GLint size, GLenum type, GLint stride, const GLvoid* *pointer, GLint ptrstride); +typedef void (APIENTRYP PFNGLSECONDARYCOLORPOINTERLISTIBMPROC) (GLint size, GLenum type, GLint stride, const GLvoid* *pointer, GLint ptrstride); +typedef void (APIENTRYP PFNGLEDGEFLAGPOINTERLISTIBMPROC) (GLint stride, const GLboolean* *pointer, GLint ptrstride); +typedef void (APIENTRYP PFNGLFOGCOORDPOINTERLISTIBMPROC) (GLenum type, GLint stride, const GLvoid* *pointer, GLint ptrstride); +typedef void (APIENTRYP PFNGLINDEXPOINTERLISTIBMPROC) (GLenum type, GLint stride, const GLvoid* *pointer, GLint ptrstride); +typedef void (APIENTRYP PFNGLNORMALPOINTERLISTIBMPROC) (GLenum type, GLint stride, const GLvoid* *pointer, GLint ptrstride); +typedef void (APIENTRYP PFNGLTEXCOORDPOINTERLISTIBMPROC) (GLint size, GLenum type, GLint stride, const GLvoid* *pointer, GLint ptrstride); +typedef void (APIENTRYP PFNGLVERTEXPOINTERLISTIBMPROC) (GLint size, GLenum type, GLint stride, const GLvoid* *pointer, GLint ptrstride); +#endif + +#ifndef GL_SGIX_subsample +#define GL_SGIX_subsample 1 +#endif + +#ifndef GL_SGIX_ycrcba +#define GL_SGIX_ycrcba 1 +#endif + +#ifndef GL_SGIX_ycrcb_subsample +#define GL_SGIX_ycrcb_subsample 1 +#endif + +#ifndef GL_SGIX_depth_pass_instrument +#define GL_SGIX_depth_pass_instrument 1 +#endif + +#ifndef GL_3DFX_texture_compression_FXT1 +#define GL_3DFX_texture_compression_FXT1 1 +#endif + +#ifndef GL_3DFX_multisample +#define GL_3DFX_multisample 1 +#endif + +#ifndef GL_3DFX_tbuffer +#define GL_3DFX_tbuffer 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTbufferMask3DFX (GLuint mask); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLTBUFFERMASK3DFXPROC) (GLuint mask); +#endif + +#ifndef GL_EXT_multisample +#define GL_EXT_multisample 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glSampleMaskEXT (GLclampf value, GLboolean invert); +GLAPI void APIENTRY glSamplePatternEXT (GLenum pattern); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLSAMPLEMASKEXTPROC) (GLclampf value, GLboolean invert); +typedef void (APIENTRYP PFNGLSAMPLEPATTERNEXTPROC) (GLenum pattern); +#endif + +#ifndef GL_SGIX_vertex_preclip +#define GL_SGIX_vertex_preclip 1 +#endif + +#ifndef GL_SGIX_convolution_accuracy +#define GL_SGIX_convolution_accuracy 1 +#endif + +#ifndef GL_SGIX_resample +#define GL_SGIX_resample 1 +#endif + +#ifndef GL_SGIS_point_line_texgen +#define GL_SGIS_point_line_texgen 1 +#endif + +#ifndef GL_SGIS_texture_color_mask +#define GL_SGIS_texture_color_mask 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTextureColorMaskSGIS (GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLTEXTURECOLORMASKSGISPROC) (GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha); +#endif + +#ifndef GL_SGIX_igloo_interface +#define GL_SGIX_igloo_interface 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glIglooInterfaceSGIX (GLenum pname, const GLvoid *params); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLIGLOOINTERFACESGIXPROC) (GLenum pname, const GLvoid *params); +#endif + +#ifndef GL_EXT_texture_env_dot3 +#define GL_EXT_texture_env_dot3 1 +#endif + +#ifndef GL_ATI_texture_mirror_once +#define GL_ATI_texture_mirror_once 1 +#endif + +#ifndef GL_NV_fence +#define GL_NV_fence 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDeleteFencesNV (GLsizei n, const GLuint *fences); +GLAPI void APIENTRY glGenFencesNV (GLsizei n, GLuint *fences); +GLAPI GLboolean APIENTRY glIsFenceNV (GLuint fence); +GLAPI GLboolean APIENTRY glTestFenceNV (GLuint fence); +GLAPI void APIENTRY glGetFenceivNV (GLuint fence, GLenum pname, GLint *params); +GLAPI void APIENTRY glFinishFenceNV (GLuint fence); +GLAPI void APIENTRY glSetFenceNV (GLuint fence, GLenum condition); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDELETEFENCESNVPROC) (GLsizei n, const GLuint *fences); +typedef void (APIENTRYP PFNGLGENFENCESNVPROC) (GLsizei n, GLuint *fences); +typedef GLboolean (APIENTRYP PFNGLISFENCENVPROC) (GLuint fence); +typedef GLboolean (APIENTRYP PFNGLTESTFENCENVPROC) (GLuint fence); +typedef void (APIENTRYP PFNGLGETFENCEIVNVPROC) (GLuint fence, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLFINISHFENCENVPROC) (GLuint fence); +typedef void (APIENTRYP PFNGLSETFENCENVPROC) (GLuint fence, GLenum condition); +#endif + +#ifndef GL_NV_evaluators +#define GL_NV_evaluators 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glMapControlPointsNV (GLenum target, GLuint index, GLenum type, GLsizei ustride, GLsizei vstride, GLint uorder, GLint vorder, GLboolean packed, const GLvoid *points); +GLAPI void APIENTRY glMapParameterivNV (GLenum target, GLenum pname, const GLint *params); +GLAPI void APIENTRY glMapParameterfvNV (GLenum target, GLenum pname, const GLfloat *params); +GLAPI void APIENTRY glGetMapControlPointsNV (GLenum target, GLuint index, GLenum type, GLsizei ustride, GLsizei vstride, GLboolean packed, GLvoid *points); +GLAPI void APIENTRY glGetMapParameterivNV (GLenum target, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetMapParameterfvNV (GLenum target, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetMapAttribParameterivNV (GLenum target, GLuint index, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetMapAttribParameterfvNV (GLenum target, GLuint index, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glEvalMapsNV (GLenum target, GLenum mode); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLMAPCONTROLPOINTSNVPROC) (GLenum target, GLuint index, GLenum type, GLsizei ustride, GLsizei vstride, GLint uorder, GLint vorder, GLboolean packed, const GLvoid *points); +typedef void (APIENTRYP PFNGLMAPPARAMETERIVNVPROC) (GLenum target, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLMAPPARAMETERFVNVPROC) (GLenum target, GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLGETMAPCONTROLPOINTSNVPROC) (GLenum target, GLuint index, GLenum type, GLsizei ustride, GLsizei vstride, GLboolean packed, GLvoid *points); +typedef void (APIENTRYP PFNGLGETMAPPARAMETERIVNVPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETMAPPARAMETERFVNVPROC) (GLenum target, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETMAPATTRIBPARAMETERIVNVPROC) (GLenum target, GLuint index, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETMAPATTRIBPARAMETERFVNVPROC) (GLenum target, GLuint index, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLEVALMAPSNVPROC) (GLenum target, GLenum mode); +#endif + +#ifndef GL_NV_packed_depth_stencil +#define GL_NV_packed_depth_stencil 1 +#endif + +#ifndef GL_NV_register_combiners2 +#define GL_NV_register_combiners2 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glCombinerStageParameterfvNV (GLenum stage, GLenum pname, const GLfloat *params); +GLAPI void APIENTRY glGetCombinerStageParameterfvNV (GLenum stage, GLenum pname, GLfloat *params); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCOMBINERSTAGEPARAMETERFVNVPROC) (GLenum stage, GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLGETCOMBINERSTAGEPARAMETERFVNVPROC) (GLenum stage, GLenum pname, GLfloat *params); +#endif + +#ifndef GL_NV_texture_compression_vtc +#define GL_NV_texture_compression_vtc 1 +#endif + +#ifndef GL_NV_texture_rectangle +#define GL_NV_texture_rectangle 1 +#endif + +#ifndef GL_NV_texture_shader +#define GL_NV_texture_shader 1 +#endif + +#ifndef GL_NV_texture_shader2 +#define GL_NV_texture_shader2 1 +#endif + +#ifndef GL_NV_vertex_array_range2 +#define GL_NV_vertex_array_range2 1 +#endif + +#ifndef GL_NV_vertex_program +#define GL_NV_vertex_program 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI GLboolean APIENTRY glAreProgramsResidentNV (GLsizei n, const GLuint *programs, GLboolean *residences); +GLAPI void APIENTRY glBindProgramNV (GLenum target, GLuint id); +GLAPI void APIENTRY glDeleteProgramsNV (GLsizei n, const GLuint *programs); +GLAPI void APIENTRY glExecuteProgramNV (GLenum target, GLuint id, const GLfloat *params); +GLAPI void APIENTRY glGenProgramsNV (GLsizei n, GLuint *programs); +GLAPI void APIENTRY glGetProgramParameterdvNV (GLenum target, GLuint index, GLenum pname, GLdouble *params); +GLAPI void APIENTRY glGetProgramParameterfvNV (GLenum target, GLuint index, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetProgramivNV (GLuint id, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetProgramStringNV (GLuint id, GLenum pname, GLubyte *program); +GLAPI void APIENTRY glGetTrackMatrixivNV (GLenum target, GLuint address, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetVertexAttribdvNV (GLuint index, GLenum pname, GLdouble *params); +GLAPI void APIENTRY glGetVertexAttribfvNV (GLuint index, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetVertexAttribivNV (GLuint index, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetVertexAttribPointervNV (GLuint index, GLenum pname, GLvoid* *pointer); +GLAPI GLboolean APIENTRY glIsProgramNV (GLuint id); +GLAPI void APIENTRY glLoadProgramNV (GLenum target, GLuint id, GLsizei len, const GLubyte *program); +GLAPI void APIENTRY glProgramParameter4dNV (GLenum target, GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +GLAPI void APIENTRY glProgramParameter4dvNV (GLenum target, GLuint index, const GLdouble *v); +GLAPI void APIENTRY glProgramParameter4fNV (GLenum target, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +GLAPI void APIENTRY glProgramParameter4fvNV (GLenum target, GLuint index, const GLfloat *v); +GLAPI void APIENTRY glProgramParameters4dvNV (GLenum target, GLuint index, GLuint count, const GLdouble *v); +GLAPI void APIENTRY glProgramParameters4fvNV (GLenum target, GLuint index, GLuint count, const GLfloat *v); +GLAPI void APIENTRY glRequestResidentProgramsNV (GLsizei n, const GLuint *programs); +GLAPI void APIENTRY glTrackMatrixNV (GLenum target, GLuint address, GLenum matrix, GLenum transform); +GLAPI void APIENTRY glVertexAttribPointerNV (GLuint index, GLint fsize, GLenum type, GLsizei stride, const GLvoid *pointer); +GLAPI void APIENTRY glVertexAttrib1dNV (GLuint index, GLdouble x); +GLAPI void APIENTRY glVertexAttrib1dvNV (GLuint index, const GLdouble *v); +GLAPI void APIENTRY glVertexAttrib1fNV (GLuint index, GLfloat x); +GLAPI void APIENTRY glVertexAttrib1fvNV (GLuint index, const GLfloat *v); +GLAPI void APIENTRY glVertexAttrib1sNV (GLuint index, GLshort x); +GLAPI void APIENTRY glVertexAttrib1svNV (GLuint index, const GLshort *v); +GLAPI void APIENTRY glVertexAttrib2dNV (GLuint index, GLdouble x, GLdouble y); +GLAPI void APIENTRY glVertexAttrib2dvNV (GLuint index, const GLdouble *v); +GLAPI void APIENTRY glVertexAttrib2fNV (GLuint index, GLfloat x, GLfloat y); +GLAPI void APIENTRY glVertexAttrib2fvNV (GLuint index, const GLfloat *v); +GLAPI void APIENTRY glVertexAttrib2sNV (GLuint index, GLshort x, GLshort y); +GLAPI void APIENTRY glVertexAttrib2svNV (GLuint index, const GLshort *v); +GLAPI void APIENTRY glVertexAttrib3dNV (GLuint index, GLdouble x, GLdouble y, GLdouble z); +GLAPI void APIENTRY glVertexAttrib3dvNV (GLuint index, const GLdouble *v); +GLAPI void APIENTRY glVertexAttrib3fNV (GLuint index, GLfloat x, GLfloat y, GLfloat z); +GLAPI void APIENTRY glVertexAttrib3fvNV (GLuint index, const GLfloat *v); +GLAPI void APIENTRY glVertexAttrib3sNV (GLuint index, GLshort x, GLshort y, GLshort z); +GLAPI void APIENTRY glVertexAttrib3svNV (GLuint index, const GLshort *v); +GLAPI void APIENTRY glVertexAttrib4dNV (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +GLAPI void APIENTRY glVertexAttrib4dvNV (GLuint index, const GLdouble *v); +GLAPI void APIENTRY glVertexAttrib4fNV (GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +GLAPI void APIENTRY glVertexAttrib4fvNV (GLuint index, const GLfloat *v); +GLAPI void APIENTRY glVertexAttrib4sNV (GLuint index, GLshort x, GLshort y, GLshort z, GLshort w); +GLAPI void APIENTRY glVertexAttrib4svNV (GLuint index, const GLshort *v); +GLAPI void APIENTRY glVertexAttrib4ubNV (GLuint index, GLubyte x, GLubyte y, GLubyte z, GLubyte w); +GLAPI void APIENTRY glVertexAttrib4ubvNV (GLuint index, const GLubyte *v); +GLAPI void APIENTRY glVertexAttribs1dvNV (GLuint index, GLsizei count, const GLdouble *v); +GLAPI void APIENTRY glVertexAttribs1fvNV (GLuint index, GLsizei count, const GLfloat *v); +GLAPI void APIENTRY glVertexAttribs1svNV (GLuint index, GLsizei count, const GLshort *v); +GLAPI void APIENTRY glVertexAttribs2dvNV (GLuint index, GLsizei count, const GLdouble *v); +GLAPI void APIENTRY glVertexAttribs2fvNV (GLuint index, GLsizei count, const GLfloat *v); +GLAPI void APIENTRY glVertexAttribs2svNV (GLuint index, GLsizei count, const GLshort *v); +GLAPI void APIENTRY glVertexAttribs3dvNV (GLuint index, GLsizei count, const GLdouble *v); +GLAPI void APIENTRY glVertexAttribs3fvNV (GLuint index, GLsizei count, const GLfloat *v); +GLAPI void APIENTRY glVertexAttribs3svNV (GLuint index, GLsizei count, const GLshort *v); +GLAPI void APIENTRY glVertexAttribs4dvNV (GLuint index, GLsizei count, const GLdouble *v); +GLAPI void APIENTRY glVertexAttribs4fvNV (GLuint index, GLsizei count, const GLfloat *v); +GLAPI void APIENTRY glVertexAttribs4svNV (GLuint index, GLsizei count, const GLshort *v); +GLAPI void APIENTRY glVertexAttribs4ubvNV (GLuint index, GLsizei count, const GLubyte *v); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef GLboolean (APIENTRYP PFNGLAREPROGRAMSRESIDENTNVPROC) (GLsizei n, const GLuint *programs, GLboolean *residences); +typedef void (APIENTRYP PFNGLBINDPROGRAMNVPROC) (GLenum target, GLuint id); +typedef void (APIENTRYP PFNGLDELETEPROGRAMSNVPROC) (GLsizei n, const GLuint *programs); +typedef void (APIENTRYP PFNGLEXECUTEPROGRAMNVPROC) (GLenum target, GLuint id, const GLfloat *params); +typedef void (APIENTRYP PFNGLGENPROGRAMSNVPROC) (GLsizei n, GLuint *programs); +typedef void (APIENTRYP PFNGLGETPROGRAMPARAMETERDVNVPROC) (GLenum target, GLuint index, GLenum pname, GLdouble *params); +typedef void (APIENTRYP PFNGLGETPROGRAMPARAMETERFVNVPROC) (GLenum target, GLuint index, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETPROGRAMIVNVPROC) (GLuint id, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETPROGRAMSTRINGNVPROC) (GLuint id, GLenum pname, GLubyte *program); +typedef void (APIENTRYP PFNGLGETTRACKMATRIXIVNVPROC) (GLenum target, GLuint address, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBDVNVPROC) (GLuint index, GLenum pname, GLdouble *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBFVNVPROC) (GLuint index, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIVNVPROC) (GLuint index, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBPOINTERVNVPROC) (GLuint index, GLenum pname, GLvoid* *pointer); +typedef GLboolean (APIENTRYP PFNGLISPROGRAMNVPROC) (GLuint id); +typedef void (APIENTRYP PFNGLLOADPROGRAMNVPROC) (GLenum target, GLuint id, GLsizei len, const GLubyte *program); +typedef void (APIENTRYP PFNGLPROGRAMPARAMETER4DNVPROC) (GLenum target, GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +typedef void (APIENTRYP PFNGLPROGRAMPARAMETER4DVNVPROC) (GLenum target, GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLPROGRAMPARAMETER4FNVPROC) (GLenum target, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +typedef void (APIENTRYP PFNGLPROGRAMPARAMETER4FVNVPROC) (GLenum target, GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLPROGRAMPARAMETERS4DVNVPROC) (GLenum target, GLuint index, GLuint count, const GLdouble *v); +typedef void (APIENTRYP PFNGLPROGRAMPARAMETERS4FVNVPROC) (GLenum target, GLuint index, GLuint count, const GLfloat *v); +typedef void (APIENTRYP PFNGLREQUESTRESIDENTPROGRAMSNVPROC) (GLsizei n, const GLuint *programs); +typedef void (APIENTRYP PFNGLTRACKMATRIXNVPROC) (GLenum target, GLuint address, GLenum matrix, GLenum transform); +typedef void (APIENTRYP PFNGLVERTEXATTRIBPOINTERNVPROC) (GLuint index, GLint fsize, GLenum type, GLsizei stride, const GLvoid *pointer); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1DNVPROC) (GLuint index, GLdouble x); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1DVNVPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1FNVPROC) (GLuint index, GLfloat x); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1FVNVPROC) (GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1SNVPROC) (GLuint index, GLshort x); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1SVNVPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2DNVPROC) (GLuint index, GLdouble x, GLdouble y); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2DVNVPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2FNVPROC) (GLuint index, GLfloat x, GLfloat y); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2FVNVPROC) (GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2SNVPROC) (GLuint index, GLshort x, GLshort y); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2SVNVPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3DNVPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3DVNVPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3FNVPROC) (GLuint index, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3FVNVPROC) (GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3SNVPROC) (GLuint index, GLshort x, GLshort y, GLshort z); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3SVNVPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4DNVPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4DVNVPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4FNVPROC) (GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4FVNVPROC) (GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4SNVPROC) (GLuint index, GLshort x, GLshort y, GLshort z, GLshort w); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4SVNVPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4UBNVPROC) (GLuint index, GLubyte x, GLubyte y, GLubyte z, GLubyte w); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4UBVNVPROC) (GLuint index, const GLubyte *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS1DVNVPROC) (GLuint index, GLsizei count, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS1FVNVPROC) (GLuint index, GLsizei count, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS1SVNVPROC) (GLuint index, GLsizei count, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS2DVNVPROC) (GLuint index, GLsizei count, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS2FVNVPROC) (GLuint index, GLsizei count, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS2SVNVPROC) (GLuint index, GLsizei count, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS3DVNVPROC) (GLuint index, GLsizei count, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS3FVNVPROC) (GLuint index, GLsizei count, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS3SVNVPROC) (GLuint index, GLsizei count, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS4DVNVPROC) (GLuint index, GLsizei count, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS4FVNVPROC) (GLuint index, GLsizei count, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS4SVNVPROC) (GLuint index, GLsizei count, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS4UBVNVPROC) (GLuint index, GLsizei count, const GLubyte *v); +#endif + +#ifndef GL_SGIX_texture_coordinate_clamp +#define GL_SGIX_texture_coordinate_clamp 1 +#endif + +#ifndef GL_SGIX_scalebias_hint +#define GL_SGIX_scalebias_hint 1 +#endif + +#ifndef GL_OML_interlace +#define GL_OML_interlace 1 +#endif + +#ifndef GL_OML_subsample +#define GL_OML_subsample 1 +#endif + +#ifndef GL_OML_resample +#define GL_OML_resample 1 +#endif + +#ifndef GL_NV_copy_depth_to_color +#define GL_NV_copy_depth_to_color 1 +#endif + +#ifndef GL_ATI_envmap_bumpmap +#define GL_ATI_envmap_bumpmap 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTexBumpParameterivATI (GLenum pname, const GLint *param); +GLAPI void APIENTRY glTexBumpParameterfvATI (GLenum pname, const GLfloat *param); +GLAPI void APIENTRY glGetTexBumpParameterivATI (GLenum pname, GLint *param); +GLAPI void APIENTRY glGetTexBumpParameterfvATI (GLenum pname, GLfloat *param); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLTEXBUMPPARAMETERIVATIPROC) (GLenum pname, const GLint *param); +typedef void (APIENTRYP PFNGLTEXBUMPPARAMETERFVATIPROC) (GLenum pname, const GLfloat *param); +typedef void (APIENTRYP PFNGLGETTEXBUMPPARAMETERIVATIPROC) (GLenum pname, GLint *param); +typedef void (APIENTRYP PFNGLGETTEXBUMPPARAMETERFVATIPROC) (GLenum pname, GLfloat *param); +#endif + +#ifndef GL_ATI_fragment_shader +#define GL_ATI_fragment_shader 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI GLuint APIENTRY glGenFragmentShadersATI (GLuint range); +GLAPI void APIENTRY glBindFragmentShaderATI (GLuint id); +GLAPI void APIENTRY glDeleteFragmentShaderATI (GLuint id); +GLAPI void APIENTRY glBeginFragmentShaderATI (void); +GLAPI void APIENTRY glEndFragmentShaderATI (void); +GLAPI void APIENTRY glPassTexCoordATI (GLuint dst, GLuint coord, GLenum swizzle); +GLAPI void APIENTRY glSampleMapATI (GLuint dst, GLuint interp, GLenum swizzle); +GLAPI void APIENTRY glColorFragmentOp1ATI (GLenum op, GLuint dst, GLuint dstMask, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod); +GLAPI void APIENTRY glColorFragmentOp2ATI (GLenum op, GLuint dst, GLuint dstMask, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod, GLuint arg2, GLuint arg2Rep, GLuint arg2Mod); +GLAPI void APIENTRY glColorFragmentOp3ATI (GLenum op, GLuint dst, GLuint dstMask, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod, GLuint arg2, GLuint arg2Rep, GLuint arg2Mod, GLuint arg3, GLuint arg3Rep, GLuint arg3Mod); +GLAPI void APIENTRY glAlphaFragmentOp1ATI (GLenum op, GLuint dst, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod); +GLAPI void APIENTRY glAlphaFragmentOp2ATI (GLenum op, GLuint dst, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod, GLuint arg2, GLuint arg2Rep, GLuint arg2Mod); +GLAPI void APIENTRY glAlphaFragmentOp3ATI (GLenum op, GLuint dst, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod, GLuint arg2, GLuint arg2Rep, GLuint arg2Mod, GLuint arg3, GLuint arg3Rep, GLuint arg3Mod); +GLAPI void APIENTRY glSetFragmentShaderConstantATI (GLuint dst, const GLfloat *value); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef GLuint (APIENTRYP PFNGLGENFRAGMENTSHADERSATIPROC) (GLuint range); +typedef void (APIENTRYP PFNGLBINDFRAGMENTSHADERATIPROC) (GLuint id); +typedef void (APIENTRYP PFNGLDELETEFRAGMENTSHADERATIPROC) (GLuint id); +typedef void (APIENTRYP PFNGLBEGINFRAGMENTSHADERATIPROC) (void); +typedef void (APIENTRYP PFNGLENDFRAGMENTSHADERATIPROC) (void); +typedef void (APIENTRYP PFNGLPASSTEXCOORDATIPROC) (GLuint dst, GLuint coord, GLenum swizzle); +typedef void (APIENTRYP PFNGLSAMPLEMAPATIPROC) (GLuint dst, GLuint interp, GLenum swizzle); +typedef void (APIENTRYP PFNGLCOLORFRAGMENTOP1ATIPROC) (GLenum op, GLuint dst, GLuint dstMask, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod); +typedef void (APIENTRYP PFNGLCOLORFRAGMENTOP2ATIPROC) (GLenum op, GLuint dst, GLuint dstMask, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod, GLuint arg2, GLuint arg2Rep, GLuint arg2Mod); +typedef void (APIENTRYP PFNGLCOLORFRAGMENTOP3ATIPROC) (GLenum op, GLuint dst, GLuint dstMask, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod, GLuint arg2, GLuint arg2Rep, GLuint arg2Mod, GLuint arg3, GLuint arg3Rep, GLuint arg3Mod); +typedef void (APIENTRYP PFNGLALPHAFRAGMENTOP1ATIPROC) (GLenum op, GLuint dst, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod); +typedef void (APIENTRYP PFNGLALPHAFRAGMENTOP2ATIPROC) (GLenum op, GLuint dst, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod, GLuint arg2, GLuint arg2Rep, GLuint arg2Mod); +typedef void (APIENTRYP PFNGLALPHAFRAGMENTOP3ATIPROC) (GLenum op, GLuint dst, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod, GLuint arg2, GLuint arg2Rep, GLuint arg2Mod, GLuint arg3, GLuint arg3Rep, GLuint arg3Mod); +typedef void (APIENTRYP PFNGLSETFRAGMENTSHADERCONSTANTATIPROC) (GLuint dst, const GLfloat *value); +#endif + +#ifndef GL_ATI_pn_triangles +#define GL_ATI_pn_triangles 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glPNTrianglesiATI (GLenum pname, GLint param); +GLAPI void APIENTRY glPNTrianglesfATI (GLenum pname, GLfloat param); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPNTRIANGLESIATIPROC) (GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLPNTRIANGLESFATIPROC) (GLenum pname, GLfloat param); +#endif + +#ifndef GL_ATI_vertex_array_object +#define GL_ATI_vertex_array_object 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI GLuint APIENTRY glNewObjectBufferATI (GLsizei size, const GLvoid *pointer, GLenum usage); +GLAPI GLboolean APIENTRY glIsObjectBufferATI (GLuint buffer); +GLAPI void APIENTRY glUpdateObjectBufferATI (GLuint buffer, GLuint offset, GLsizei size, const GLvoid *pointer, GLenum preserve); +GLAPI void APIENTRY glGetObjectBufferfvATI (GLuint buffer, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetObjectBufferivATI (GLuint buffer, GLenum pname, GLint *params); +GLAPI void APIENTRY glFreeObjectBufferATI (GLuint buffer); +GLAPI void APIENTRY glArrayObjectATI (GLenum array, GLint size, GLenum type, GLsizei stride, GLuint buffer, GLuint offset); +GLAPI void APIENTRY glGetArrayObjectfvATI (GLenum array, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetArrayObjectivATI (GLenum array, GLenum pname, GLint *params); +GLAPI void APIENTRY glVariantArrayObjectATI (GLuint id, GLenum type, GLsizei stride, GLuint buffer, GLuint offset); +GLAPI void APIENTRY glGetVariantArrayObjectfvATI (GLuint id, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetVariantArrayObjectivATI (GLuint id, GLenum pname, GLint *params); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef GLuint (APIENTRYP PFNGLNEWOBJECTBUFFERATIPROC) (GLsizei size, const GLvoid *pointer, GLenum usage); +typedef GLboolean (APIENTRYP PFNGLISOBJECTBUFFERATIPROC) (GLuint buffer); +typedef void (APIENTRYP PFNGLUPDATEOBJECTBUFFERATIPROC) (GLuint buffer, GLuint offset, GLsizei size, const GLvoid *pointer, GLenum preserve); +typedef void (APIENTRYP PFNGLGETOBJECTBUFFERFVATIPROC) (GLuint buffer, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETOBJECTBUFFERIVATIPROC) (GLuint buffer, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLFREEOBJECTBUFFERATIPROC) (GLuint buffer); +typedef void (APIENTRYP PFNGLARRAYOBJECTATIPROC) (GLenum array, GLint size, GLenum type, GLsizei stride, GLuint buffer, GLuint offset); +typedef void (APIENTRYP PFNGLGETARRAYOBJECTFVATIPROC) (GLenum array, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETARRAYOBJECTIVATIPROC) (GLenum array, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLVARIANTARRAYOBJECTATIPROC) (GLuint id, GLenum type, GLsizei stride, GLuint buffer, GLuint offset); +typedef void (APIENTRYP PFNGLGETVARIANTARRAYOBJECTFVATIPROC) (GLuint id, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETVARIANTARRAYOBJECTIVATIPROC) (GLuint id, GLenum pname, GLint *params); +#endif + +#ifndef GL_EXT_vertex_shader +#define GL_EXT_vertex_shader 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBeginVertexShaderEXT (void); +GLAPI void APIENTRY glEndVertexShaderEXT (void); +GLAPI void APIENTRY glBindVertexShaderEXT (GLuint id); +GLAPI GLuint APIENTRY glGenVertexShadersEXT (GLuint range); +GLAPI void APIENTRY glDeleteVertexShaderEXT (GLuint id); +GLAPI void APIENTRY glShaderOp1EXT (GLenum op, GLuint res, GLuint arg1); +GLAPI void APIENTRY glShaderOp2EXT (GLenum op, GLuint res, GLuint arg1, GLuint arg2); +GLAPI void APIENTRY glShaderOp3EXT (GLenum op, GLuint res, GLuint arg1, GLuint arg2, GLuint arg3); +GLAPI void APIENTRY glSwizzleEXT (GLuint res, GLuint in, GLenum outX, GLenum outY, GLenum outZ, GLenum outW); +GLAPI void APIENTRY glWriteMaskEXT (GLuint res, GLuint in, GLenum outX, GLenum outY, GLenum outZ, GLenum outW); +GLAPI void APIENTRY glInsertComponentEXT (GLuint res, GLuint src, GLuint num); +GLAPI void APIENTRY glExtractComponentEXT (GLuint res, GLuint src, GLuint num); +GLAPI GLuint APIENTRY glGenSymbolsEXT (GLenum datatype, GLenum storagetype, GLenum range, GLuint components); +GLAPI void APIENTRY glSetInvariantEXT (GLuint id, GLenum type, const GLvoid *addr); +GLAPI void APIENTRY glSetLocalConstantEXT (GLuint id, GLenum type, const GLvoid *addr); +GLAPI void APIENTRY glVariantbvEXT (GLuint id, const GLbyte *addr); +GLAPI void APIENTRY glVariantsvEXT (GLuint id, const GLshort *addr); +GLAPI void APIENTRY glVariantivEXT (GLuint id, const GLint *addr); +GLAPI void APIENTRY glVariantfvEXT (GLuint id, const GLfloat *addr); +GLAPI void APIENTRY glVariantdvEXT (GLuint id, const GLdouble *addr); +GLAPI void APIENTRY glVariantubvEXT (GLuint id, const GLubyte *addr); +GLAPI void APIENTRY glVariantusvEXT (GLuint id, const GLushort *addr); +GLAPI void APIENTRY glVariantuivEXT (GLuint id, const GLuint *addr); +GLAPI void APIENTRY glVariantPointerEXT (GLuint id, GLenum type, GLuint stride, const GLvoid *addr); +GLAPI void APIENTRY glEnableVariantClientStateEXT (GLuint id); +GLAPI void APIENTRY glDisableVariantClientStateEXT (GLuint id); +GLAPI GLuint APIENTRY glBindLightParameterEXT (GLenum light, GLenum value); +GLAPI GLuint APIENTRY glBindMaterialParameterEXT (GLenum face, GLenum value); +GLAPI GLuint APIENTRY glBindTexGenParameterEXT (GLenum unit, GLenum coord, GLenum value); +GLAPI GLuint APIENTRY glBindTextureUnitParameterEXT (GLenum unit, GLenum value); +GLAPI GLuint APIENTRY glBindParameterEXT (GLenum value); +GLAPI GLboolean APIENTRY glIsVariantEnabledEXT (GLuint id, GLenum cap); +GLAPI void APIENTRY glGetVariantBooleanvEXT (GLuint id, GLenum value, GLboolean *data); +GLAPI void APIENTRY glGetVariantIntegervEXT (GLuint id, GLenum value, GLint *data); +GLAPI void APIENTRY glGetVariantFloatvEXT (GLuint id, GLenum value, GLfloat *data); +GLAPI void APIENTRY glGetVariantPointervEXT (GLuint id, GLenum value, GLvoid* *data); +GLAPI void APIENTRY glGetInvariantBooleanvEXT (GLuint id, GLenum value, GLboolean *data); +GLAPI void APIENTRY glGetInvariantIntegervEXT (GLuint id, GLenum value, GLint *data); +GLAPI void APIENTRY glGetInvariantFloatvEXT (GLuint id, GLenum value, GLfloat *data); +GLAPI void APIENTRY glGetLocalConstantBooleanvEXT (GLuint id, GLenum value, GLboolean *data); +GLAPI void APIENTRY glGetLocalConstantIntegervEXT (GLuint id, GLenum value, GLint *data); +GLAPI void APIENTRY glGetLocalConstantFloatvEXT (GLuint id, GLenum value, GLfloat *data); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBEGINVERTEXSHADEREXTPROC) (void); +typedef void (APIENTRYP PFNGLENDVERTEXSHADEREXTPROC) (void); +typedef void (APIENTRYP PFNGLBINDVERTEXSHADEREXTPROC) (GLuint id); +typedef GLuint (APIENTRYP PFNGLGENVERTEXSHADERSEXTPROC) (GLuint range); +typedef void (APIENTRYP PFNGLDELETEVERTEXSHADEREXTPROC) (GLuint id); +typedef void (APIENTRYP PFNGLSHADEROP1EXTPROC) (GLenum op, GLuint res, GLuint arg1); +typedef void (APIENTRYP PFNGLSHADEROP2EXTPROC) (GLenum op, GLuint res, GLuint arg1, GLuint arg2); +typedef void (APIENTRYP PFNGLSHADEROP3EXTPROC) (GLenum op, GLuint res, GLuint arg1, GLuint arg2, GLuint arg3); +typedef void (APIENTRYP PFNGLSWIZZLEEXTPROC) (GLuint res, GLuint in, GLenum outX, GLenum outY, GLenum outZ, GLenum outW); +typedef void (APIENTRYP PFNGLWRITEMASKEXTPROC) (GLuint res, GLuint in, GLenum outX, GLenum outY, GLenum outZ, GLenum outW); +typedef void (APIENTRYP PFNGLINSERTCOMPONENTEXTPROC) (GLuint res, GLuint src, GLuint num); +typedef void (APIENTRYP PFNGLEXTRACTCOMPONENTEXTPROC) (GLuint res, GLuint src, GLuint num); +typedef GLuint (APIENTRYP PFNGLGENSYMBOLSEXTPROC) (GLenum datatype, GLenum storagetype, GLenum range, GLuint components); +typedef void (APIENTRYP PFNGLSETINVARIANTEXTPROC) (GLuint id, GLenum type, const GLvoid *addr); +typedef void (APIENTRYP PFNGLSETLOCALCONSTANTEXTPROC) (GLuint id, GLenum type, const GLvoid *addr); +typedef void (APIENTRYP PFNGLVARIANTBVEXTPROC) (GLuint id, const GLbyte *addr); +typedef void (APIENTRYP PFNGLVARIANTSVEXTPROC) (GLuint id, const GLshort *addr); +typedef void (APIENTRYP PFNGLVARIANTIVEXTPROC) (GLuint id, const GLint *addr); +typedef void (APIENTRYP PFNGLVARIANTFVEXTPROC) (GLuint id, const GLfloat *addr); +typedef void (APIENTRYP PFNGLVARIANTDVEXTPROC) (GLuint id, const GLdouble *addr); +typedef void (APIENTRYP PFNGLVARIANTUBVEXTPROC) (GLuint id, const GLubyte *addr); +typedef void (APIENTRYP PFNGLVARIANTUSVEXTPROC) (GLuint id, const GLushort *addr); +typedef void (APIENTRYP PFNGLVARIANTUIVEXTPROC) (GLuint id, const GLuint *addr); +typedef void (APIENTRYP PFNGLVARIANTPOINTEREXTPROC) (GLuint id, GLenum type, GLuint stride, const GLvoid *addr); +typedef void (APIENTRYP PFNGLENABLEVARIANTCLIENTSTATEEXTPROC) (GLuint id); +typedef void (APIENTRYP PFNGLDISABLEVARIANTCLIENTSTATEEXTPROC) (GLuint id); +typedef GLuint (APIENTRYP PFNGLBINDLIGHTPARAMETEREXTPROC) (GLenum light, GLenum value); +typedef GLuint (APIENTRYP PFNGLBINDMATERIALPARAMETEREXTPROC) (GLenum face, GLenum value); +typedef GLuint (APIENTRYP PFNGLBINDTEXGENPARAMETEREXTPROC) (GLenum unit, GLenum coord, GLenum value); +typedef GLuint (APIENTRYP PFNGLBINDTEXTUREUNITPARAMETEREXTPROC) (GLenum unit, GLenum value); +typedef GLuint (APIENTRYP PFNGLBINDPARAMETEREXTPROC) (GLenum value); +typedef GLboolean (APIENTRYP PFNGLISVARIANTENABLEDEXTPROC) (GLuint id, GLenum cap); +typedef void (APIENTRYP PFNGLGETVARIANTBOOLEANVEXTPROC) (GLuint id, GLenum value, GLboolean *data); +typedef void (APIENTRYP PFNGLGETVARIANTINTEGERVEXTPROC) (GLuint id, GLenum value, GLint *data); +typedef void (APIENTRYP PFNGLGETVARIANTFLOATVEXTPROC) (GLuint id, GLenum value, GLfloat *data); +typedef void (APIENTRYP PFNGLGETVARIANTPOINTERVEXTPROC) (GLuint id, GLenum value, GLvoid* *data); +typedef void (APIENTRYP PFNGLGETINVARIANTBOOLEANVEXTPROC) (GLuint id, GLenum value, GLboolean *data); +typedef void (APIENTRYP PFNGLGETINVARIANTINTEGERVEXTPROC) (GLuint id, GLenum value, GLint *data); +typedef void (APIENTRYP PFNGLGETINVARIANTFLOATVEXTPROC) (GLuint id, GLenum value, GLfloat *data); +typedef void (APIENTRYP PFNGLGETLOCALCONSTANTBOOLEANVEXTPROC) (GLuint id, GLenum value, GLboolean *data); +typedef void (APIENTRYP PFNGLGETLOCALCONSTANTINTEGERVEXTPROC) (GLuint id, GLenum value, GLint *data); +typedef void (APIENTRYP PFNGLGETLOCALCONSTANTFLOATVEXTPROC) (GLuint id, GLenum value, GLfloat *data); +#endif + +#ifndef GL_ATI_vertex_streams +#define GL_ATI_vertex_streams 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glVertexStream1sATI (GLenum stream, GLshort x); +GLAPI void APIENTRY glVertexStream1svATI (GLenum stream, const GLshort *coords); +GLAPI void APIENTRY glVertexStream1iATI (GLenum stream, GLint x); +GLAPI void APIENTRY glVertexStream1ivATI (GLenum stream, const GLint *coords); +GLAPI void APIENTRY glVertexStream1fATI (GLenum stream, GLfloat x); +GLAPI void APIENTRY glVertexStream1fvATI (GLenum stream, const GLfloat *coords); +GLAPI void APIENTRY glVertexStream1dATI (GLenum stream, GLdouble x); +GLAPI void APIENTRY glVertexStream1dvATI (GLenum stream, const GLdouble *coords); +GLAPI void APIENTRY glVertexStream2sATI (GLenum stream, GLshort x, GLshort y); +GLAPI void APIENTRY glVertexStream2svATI (GLenum stream, const GLshort *coords); +GLAPI void APIENTRY glVertexStream2iATI (GLenum stream, GLint x, GLint y); +GLAPI void APIENTRY glVertexStream2ivATI (GLenum stream, const GLint *coords); +GLAPI void APIENTRY glVertexStream2fATI (GLenum stream, GLfloat x, GLfloat y); +GLAPI void APIENTRY glVertexStream2fvATI (GLenum stream, const GLfloat *coords); +GLAPI void APIENTRY glVertexStream2dATI (GLenum stream, GLdouble x, GLdouble y); +GLAPI void APIENTRY glVertexStream2dvATI (GLenum stream, const GLdouble *coords); +GLAPI void APIENTRY glVertexStream3sATI (GLenum stream, GLshort x, GLshort y, GLshort z); +GLAPI void APIENTRY glVertexStream3svATI (GLenum stream, const GLshort *coords); +GLAPI void APIENTRY glVertexStream3iATI (GLenum stream, GLint x, GLint y, GLint z); +GLAPI void APIENTRY glVertexStream3ivATI (GLenum stream, const GLint *coords); +GLAPI void APIENTRY glVertexStream3fATI (GLenum stream, GLfloat x, GLfloat y, GLfloat z); +GLAPI void APIENTRY glVertexStream3fvATI (GLenum stream, const GLfloat *coords); +GLAPI void APIENTRY glVertexStream3dATI (GLenum stream, GLdouble x, GLdouble y, GLdouble z); +GLAPI void APIENTRY glVertexStream3dvATI (GLenum stream, const GLdouble *coords); +GLAPI void APIENTRY glVertexStream4sATI (GLenum stream, GLshort x, GLshort y, GLshort z, GLshort w); +GLAPI void APIENTRY glVertexStream4svATI (GLenum stream, const GLshort *coords); +GLAPI void APIENTRY glVertexStream4iATI (GLenum stream, GLint x, GLint y, GLint z, GLint w); +GLAPI void APIENTRY glVertexStream4ivATI (GLenum stream, const GLint *coords); +GLAPI void APIENTRY glVertexStream4fATI (GLenum stream, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +GLAPI void APIENTRY glVertexStream4fvATI (GLenum stream, const GLfloat *coords); +GLAPI void APIENTRY glVertexStream4dATI (GLenum stream, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +GLAPI void APIENTRY glVertexStream4dvATI (GLenum stream, const GLdouble *coords); +GLAPI void APIENTRY glNormalStream3bATI (GLenum stream, GLbyte nx, GLbyte ny, GLbyte nz); +GLAPI void APIENTRY glNormalStream3bvATI (GLenum stream, const GLbyte *coords); +GLAPI void APIENTRY glNormalStream3sATI (GLenum stream, GLshort nx, GLshort ny, GLshort nz); +GLAPI void APIENTRY glNormalStream3svATI (GLenum stream, const GLshort *coords); +GLAPI void APIENTRY glNormalStream3iATI (GLenum stream, GLint nx, GLint ny, GLint nz); +GLAPI void APIENTRY glNormalStream3ivATI (GLenum stream, const GLint *coords); +GLAPI void APIENTRY glNormalStream3fATI (GLenum stream, GLfloat nx, GLfloat ny, GLfloat nz); +GLAPI void APIENTRY glNormalStream3fvATI (GLenum stream, const GLfloat *coords); +GLAPI void APIENTRY glNormalStream3dATI (GLenum stream, GLdouble nx, GLdouble ny, GLdouble nz); +GLAPI void APIENTRY glNormalStream3dvATI (GLenum stream, const GLdouble *coords); +GLAPI void APIENTRY glClientActiveVertexStreamATI (GLenum stream); +GLAPI void APIENTRY glVertexBlendEnviATI (GLenum pname, GLint param); +GLAPI void APIENTRY glVertexBlendEnvfATI (GLenum pname, GLfloat param); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLVERTEXSTREAM1SATIPROC) (GLenum stream, GLshort x); +typedef void (APIENTRYP PFNGLVERTEXSTREAM1SVATIPROC) (GLenum stream, const GLshort *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM1IATIPROC) (GLenum stream, GLint x); +typedef void (APIENTRYP PFNGLVERTEXSTREAM1IVATIPROC) (GLenum stream, const GLint *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM1FATIPROC) (GLenum stream, GLfloat x); +typedef void (APIENTRYP PFNGLVERTEXSTREAM1FVATIPROC) (GLenum stream, const GLfloat *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM1DATIPROC) (GLenum stream, GLdouble x); +typedef void (APIENTRYP PFNGLVERTEXSTREAM1DVATIPROC) (GLenum stream, const GLdouble *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM2SATIPROC) (GLenum stream, GLshort x, GLshort y); +typedef void (APIENTRYP PFNGLVERTEXSTREAM2SVATIPROC) (GLenum stream, const GLshort *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM2IATIPROC) (GLenum stream, GLint x, GLint y); +typedef void (APIENTRYP PFNGLVERTEXSTREAM2IVATIPROC) (GLenum stream, const GLint *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM2FATIPROC) (GLenum stream, GLfloat x, GLfloat y); +typedef void (APIENTRYP PFNGLVERTEXSTREAM2FVATIPROC) (GLenum stream, const GLfloat *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM2DATIPROC) (GLenum stream, GLdouble x, GLdouble y); +typedef void (APIENTRYP PFNGLVERTEXSTREAM2DVATIPROC) (GLenum stream, const GLdouble *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM3SATIPROC) (GLenum stream, GLshort x, GLshort y, GLshort z); +typedef void (APIENTRYP PFNGLVERTEXSTREAM3SVATIPROC) (GLenum stream, const GLshort *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM3IATIPROC) (GLenum stream, GLint x, GLint y, GLint z); +typedef void (APIENTRYP PFNGLVERTEXSTREAM3IVATIPROC) (GLenum stream, const GLint *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM3FATIPROC) (GLenum stream, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLVERTEXSTREAM3FVATIPROC) (GLenum stream, const GLfloat *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM3DATIPROC) (GLenum stream, GLdouble x, GLdouble y, GLdouble z); +typedef void (APIENTRYP PFNGLVERTEXSTREAM3DVATIPROC) (GLenum stream, const GLdouble *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM4SATIPROC) (GLenum stream, GLshort x, GLshort y, GLshort z, GLshort w); +typedef void (APIENTRYP PFNGLVERTEXSTREAM4SVATIPROC) (GLenum stream, const GLshort *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM4IATIPROC) (GLenum stream, GLint x, GLint y, GLint z, GLint w); +typedef void (APIENTRYP PFNGLVERTEXSTREAM4IVATIPROC) (GLenum stream, const GLint *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM4FATIPROC) (GLenum stream, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +typedef void (APIENTRYP PFNGLVERTEXSTREAM4FVATIPROC) (GLenum stream, const GLfloat *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM4DATIPROC) (GLenum stream, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +typedef void (APIENTRYP PFNGLVERTEXSTREAM4DVATIPROC) (GLenum stream, const GLdouble *coords); +typedef void (APIENTRYP PFNGLNORMALSTREAM3BATIPROC) (GLenum stream, GLbyte nx, GLbyte ny, GLbyte nz); +typedef void (APIENTRYP PFNGLNORMALSTREAM3BVATIPROC) (GLenum stream, const GLbyte *coords); +typedef void (APIENTRYP PFNGLNORMALSTREAM3SATIPROC) (GLenum stream, GLshort nx, GLshort ny, GLshort nz); +typedef void (APIENTRYP PFNGLNORMALSTREAM3SVATIPROC) (GLenum stream, const GLshort *coords); +typedef void (APIENTRYP PFNGLNORMALSTREAM3IATIPROC) (GLenum stream, GLint nx, GLint ny, GLint nz); +typedef void (APIENTRYP PFNGLNORMALSTREAM3IVATIPROC) (GLenum stream, const GLint *coords); +typedef void (APIENTRYP PFNGLNORMALSTREAM3FATIPROC) (GLenum stream, GLfloat nx, GLfloat ny, GLfloat nz); +typedef void (APIENTRYP PFNGLNORMALSTREAM3FVATIPROC) (GLenum stream, const GLfloat *coords); +typedef void (APIENTRYP PFNGLNORMALSTREAM3DATIPROC) (GLenum stream, GLdouble nx, GLdouble ny, GLdouble nz); +typedef void (APIENTRYP PFNGLNORMALSTREAM3DVATIPROC) (GLenum stream, const GLdouble *coords); +typedef void (APIENTRYP PFNGLCLIENTACTIVEVERTEXSTREAMATIPROC) (GLenum stream); +typedef void (APIENTRYP PFNGLVERTEXBLENDENVIATIPROC) (GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLVERTEXBLENDENVFATIPROC) (GLenum pname, GLfloat param); +#endif + +#ifndef GL_ATI_element_array +#define GL_ATI_element_array 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glElementPointerATI (GLenum type, const GLvoid *pointer); +GLAPI void APIENTRY glDrawElementArrayATI (GLenum mode, GLsizei count); +GLAPI void APIENTRY glDrawRangeElementArrayATI (GLenum mode, GLuint start, GLuint end, GLsizei count); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLELEMENTPOINTERATIPROC) (GLenum type, const GLvoid *pointer); +typedef void (APIENTRYP PFNGLDRAWELEMENTARRAYATIPROC) (GLenum mode, GLsizei count); +typedef void (APIENTRYP PFNGLDRAWRANGEELEMENTARRAYATIPROC) (GLenum mode, GLuint start, GLuint end, GLsizei count); +#endif + +#ifndef GL_SUN_mesh_array +#define GL_SUN_mesh_array 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDrawMeshArraysSUN (GLenum mode, GLint first, GLsizei count, GLsizei width); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDRAWMESHARRAYSSUNPROC) (GLenum mode, GLint first, GLsizei count, GLsizei width); +#endif + +#ifndef GL_SUN_slice_accum +#define GL_SUN_slice_accum 1 +#endif + +#ifndef GL_NV_multisample_filter_hint +#define GL_NV_multisample_filter_hint 1 +#endif + +#ifndef GL_NV_depth_clamp +#define GL_NV_depth_clamp 1 +#endif + +#ifndef GL_NV_occlusion_query +#define GL_NV_occlusion_query 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glGenOcclusionQueriesNV (GLsizei n, GLuint *ids); +GLAPI void APIENTRY glDeleteOcclusionQueriesNV (GLsizei n, const GLuint *ids); +GLAPI GLboolean APIENTRY glIsOcclusionQueryNV (GLuint id); +GLAPI void APIENTRY glBeginOcclusionQueryNV (GLuint id); +GLAPI void APIENTRY glEndOcclusionQueryNV (void); +GLAPI void APIENTRY glGetOcclusionQueryivNV (GLuint id, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetOcclusionQueryuivNV (GLuint id, GLenum pname, GLuint *params); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGENOCCLUSIONQUERIESNVPROC) (GLsizei n, GLuint *ids); +typedef void (APIENTRYP PFNGLDELETEOCCLUSIONQUERIESNVPROC) (GLsizei n, const GLuint *ids); +typedef GLboolean (APIENTRYP PFNGLISOCCLUSIONQUERYNVPROC) (GLuint id); +typedef void (APIENTRYP PFNGLBEGINOCCLUSIONQUERYNVPROC) (GLuint id); +typedef void (APIENTRYP PFNGLENDOCCLUSIONQUERYNVPROC) (void); +typedef void (APIENTRYP PFNGLGETOCCLUSIONQUERYIVNVPROC) (GLuint id, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETOCCLUSIONQUERYUIVNVPROC) (GLuint id, GLenum pname, GLuint *params); +#endif + +#ifndef GL_NV_point_sprite +#define GL_NV_point_sprite 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glPointParameteriNV (GLenum pname, GLint param); +GLAPI void APIENTRY glPointParameterivNV (GLenum pname, const GLint *params); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPOINTPARAMETERINVPROC) (GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLPOINTPARAMETERIVNVPROC) (GLenum pname, const GLint *params); +#endif + +#ifndef GL_NV_texture_shader3 +#define GL_NV_texture_shader3 1 +#endif + +#ifndef GL_NV_vertex_program1_1 +#define GL_NV_vertex_program1_1 1 +#endif + +#ifndef GL_EXT_shadow_funcs +#define GL_EXT_shadow_funcs 1 +#endif + +#ifndef GL_EXT_stencil_two_side +#define GL_EXT_stencil_two_side 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glActiveStencilFaceEXT (GLenum face); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLACTIVESTENCILFACEEXTPROC) (GLenum face); +#endif + +#ifndef GL_ATI_text_fragment_shader +#define GL_ATI_text_fragment_shader 1 +#endif + +#ifndef GL_APPLE_client_storage +#define GL_APPLE_client_storage 1 +#endif + +#ifndef GL_APPLE_element_array +#define GL_APPLE_element_array 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glElementPointerAPPLE (GLenum type, const GLvoid *pointer); +GLAPI void APIENTRY glDrawElementArrayAPPLE (GLenum mode, GLint first, GLsizei count); +GLAPI void APIENTRY glDrawRangeElementArrayAPPLE (GLenum mode, GLuint start, GLuint end, GLint first, GLsizei count); +GLAPI void APIENTRY glMultiDrawElementArrayAPPLE (GLenum mode, const GLint *first, const GLsizei *count, GLsizei primcount); +GLAPI void APIENTRY glMultiDrawRangeElementArrayAPPLE (GLenum mode, GLuint start, GLuint end, const GLint *first, const GLsizei *count, GLsizei primcount); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLELEMENTPOINTERAPPLEPROC) (GLenum type, const GLvoid *pointer); +typedef void (APIENTRYP PFNGLDRAWELEMENTARRAYAPPLEPROC) (GLenum mode, GLint first, GLsizei count); +typedef void (APIENTRYP PFNGLDRAWRANGEELEMENTARRAYAPPLEPROC) (GLenum mode, GLuint start, GLuint end, GLint first, GLsizei count); +typedef void (APIENTRYP PFNGLMULTIDRAWELEMENTARRAYAPPLEPROC) (GLenum mode, const GLint *first, const GLsizei *count, GLsizei primcount); +typedef void (APIENTRYP PFNGLMULTIDRAWRANGEELEMENTARRAYAPPLEPROC) (GLenum mode, GLuint start, GLuint end, const GLint *first, const GLsizei *count, GLsizei primcount); +#endif + +#ifndef GL_APPLE_fence +#define GL_APPLE_fence 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glGenFencesAPPLE (GLsizei n, GLuint *fences); +GLAPI void APIENTRY glDeleteFencesAPPLE (GLsizei n, const GLuint *fences); +GLAPI void APIENTRY glSetFenceAPPLE (GLuint fence); +GLAPI GLboolean APIENTRY glIsFenceAPPLE (GLuint fence); +GLAPI GLboolean APIENTRY glTestFenceAPPLE (GLuint fence); +GLAPI void APIENTRY glFinishFenceAPPLE (GLuint fence); +GLAPI GLboolean APIENTRY glTestObjectAPPLE (GLenum object, GLuint name); +GLAPI void APIENTRY glFinishObjectAPPLE (GLenum object, GLint name); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGENFENCESAPPLEPROC) (GLsizei n, GLuint *fences); +typedef void (APIENTRYP PFNGLDELETEFENCESAPPLEPROC) (GLsizei n, const GLuint *fences); +typedef void (APIENTRYP PFNGLSETFENCEAPPLEPROC) (GLuint fence); +typedef GLboolean (APIENTRYP PFNGLISFENCEAPPLEPROC) (GLuint fence); +typedef GLboolean (APIENTRYP PFNGLTESTFENCEAPPLEPROC) (GLuint fence); +typedef void (APIENTRYP PFNGLFINISHFENCEAPPLEPROC) (GLuint fence); +typedef GLboolean (APIENTRYP PFNGLTESTOBJECTAPPLEPROC) (GLenum object, GLuint name); +typedef void (APIENTRYP PFNGLFINISHOBJECTAPPLEPROC) (GLenum object, GLint name); +#endif + +#ifndef GL_APPLE_vertex_array_object +#define GL_APPLE_vertex_array_object 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBindVertexArrayAPPLE (GLuint array); +GLAPI void APIENTRY glDeleteVertexArraysAPPLE (GLsizei n, const GLuint *arrays); +GLAPI void APIENTRY glGenVertexArraysAPPLE (GLsizei n, GLuint *arrays); +GLAPI GLboolean APIENTRY glIsVertexArrayAPPLE (GLuint array); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBINDVERTEXARRAYAPPLEPROC) (GLuint array); +typedef void (APIENTRYP PFNGLDELETEVERTEXARRAYSAPPLEPROC) (GLsizei n, const GLuint *arrays); +typedef void (APIENTRYP PFNGLGENVERTEXARRAYSAPPLEPROC) (GLsizei n, GLuint *arrays); +typedef GLboolean (APIENTRYP PFNGLISVERTEXARRAYAPPLEPROC) (GLuint array); +#endif + +#ifndef GL_APPLE_vertex_array_range +#define GL_APPLE_vertex_array_range 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glVertexArrayRangeAPPLE (GLsizei length, GLvoid *pointer); +GLAPI void APIENTRY glFlushVertexArrayRangeAPPLE (GLsizei length, GLvoid *pointer); +GLAPI void APIENTRY glVertexArrayParameteriAPPLE (GLenum pname, GLint param); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLVERTEXARRAYRANGEAPPLEPROC) (GLsizei length, GLvoid *pointer); +typedef void (APIENTRYP PFNGLFLUSHVERTEXARRAYRANGEAPPLEPROC) (GLsizei length, GLvoid *pointer); +typedef void (APIENTRYP PFNGLVERTEXARRAYPARAMETERIAPPLEPROC) (GLenum pname, GLint param); +#endif + +#ifndef GL_APPLE_ycbcr_422 +#define GL_APPLE_ycbcr_422 1 +#endif + +#ifndef GL_S3_s3tc +#define GL_S3_s3tc 1 +#endif + +#ifndef GL_ATI_draw_buffers +#define GL_ATI_draw_buffers 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDrawBuffersATI (GLsizei n, const GLenum *bufs); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDRAWBUFFERSATIPROC) (GLsizei n, const GLenum *bufs); +#endif + +#ifndef GL_ATI_pixel_format_float +#define GL_ATI_pixel_format_float 1 +/* This is really a WGL extension, but defines some associated GL enums. + * ATI does not export "GL_ATI_pixel_format_float" in the GL_EXTENSIONS string. + */ +#endif + +#ifndef GL_ATI_texture_env_combine3 +#define GL_ATI_texture_env_combine3 1 +#endif + +#ifndef GL_ATI_texture_float +#define GL_ATI_texture_float 1 +#endif + +#ifndef GL_NV_float_buffer +#define GL_NV_float_buffer 1 +#endif + +#ifndef GL_NV_fragment_program +#define GL_NV_fragment_program 1 +/* Some NV_fragment_program entry points are shared with ARB_vertex_program. */ +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glProgramNamedParameter4fNV (GLuint id, GLsizei len, const GLubyte *name, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +GLAPI void APIENTRY glProgramNamedParameter4dNV (GLuint id, GLsizei len, const GLubyte *name, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +GLAPI void APIENTRY glProgramNamedParameter4fvNV (GLuint id, GLsizei len, const GLubyte *name, const GLfloat *v); +GLAPI void APIENTRY glProgramNamedParameter4dvNV (GLuint id, GLsizei len, const GLubyte *name, const GLdouble *v); +GLAPI void APIENTRY glGetProgramNamedParameterfvNV (GLuint id, GLsizei len, const GLubyte *name, GLfloat *params); +GLAPI void APIENTRY glGetProgramNamedParameterdvNV (GLuint id, GLsizei len, const GLubyte *name, GLdouble *params); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPROGRAMNAMEDPARAMETER4FNVPROC) (GLuint id, GLsizei len, const GLubyte *name, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +typedef void (APIENTRYP PFNGLPROGRAMNAMEDPARAMETER4DNVPROC) (GLuint id, GLsizei len, const GLubyte *name, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +typedef void (APIENTRYP PFNGLPROGRAMNAMEDPARAMETER4FVNVPROC) (GLuint id, GLsizei len, const GLubyte *name, const GLfloat *v); +typedef void (APIENTRYP PFNGLPROGRAMNAMEDPARAMETER4DVNVPROC) (GLuint id, GLsizei len, const GLubyte *name, const GLdouble *v); +typedef void (APIENTRYP PFNGLGETPROGRAMNAMEDPARAMETERFVNVPROC) (GLuint id, GLsizei len, const GLubyte *name, GLfloat *params); +typedef void (APIENTRYP PFNGLGETPROGRAMNAMEDPARAMETERDVNVPROC) (GLuint id, GLsizei len, const GLubyte *name, GLdouble *params); +#endif + +#ifndef GL_NV_half_float +#define GL_NV_half_float 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glVertex2hNV (GLhalfNV x, GLhalfNV y); +GLAPI void APIENTRY glVertex2hvNV (const GLhalfNV *v); +GLAPI void APIENTRY glVertex3hNV (GLhalfNV x, GLhalfNV y, GLhalfNV z); +GLAPI void APIENTRY glVertex3hvNV (const GLhalfNV *v); +GLAPI void APIENTRY glVertex4hNV (GLhalfNV x, GLhalfNV y, GLhalfNV z, GLhalfNV w); +GLAPI void APIENTRY glVertex4hvNV (const GLhalfNV *v); +GLAPI void APIENTRY glNormal3hNV (GLhalfNV nx, GLhalfNV ny, GLhalfNV nz); +GLAPI void APIENTRY glNormal3hvNV (const GLhalfNV *v); +GLAPI void APIENTRY glColor3hNV (GLhalfNV red, GLhalfNV green, GLhalfNV blue); +GLAPI void APIENTRY glColor3hvNV (const GLhalfNV *v); +GLAPI void APIENTRY glColor4hNV (GLhalfNV red, GLhalfNV green, GLhalfNV blue, GLhalfNV alpha); +GLAPI void APIENTRY glColor4hvNV (const GLhalfNV *v); +GLAPI void APIENTRY glTexCoord1hNV (GLhalfNV s); +GLAPI void APIENTRY glTexCoord1hvNV (const GLhalfNV *v); +GLAPI void APIENTRY glTexCoord2hNV (GLhalfNV s, GLhalfNV t); +GLAPI void APIENTRY glTexCoord2hvNV (const GLhalfNV *v); +GLAPI void APIENTRY glTexCoord3hNV (GLhalfNV s, GLhalfNV t, GLhalfNV r); +GLAPI void APIENTRY glTexCoord3hvNV (const GLhalfNV *v); +GLAPI void APIENTRY glTexCoord4hNV (GLhalfNV s, GLhalfNV t, GLhalfNV r, GLhalfNV q); +GLAPI void APIENTRY glTexCoord4hvNV (const GLhalfNV *v); +GLAPI void APIENTRY glMultiTexCoord1hNV (GLenum target, GLhalfNV s); +GLAPI void APIENTRY glMultiTexCoord1hvNV (GLenum target, const GLhalfNV *v); +GLAPI void APIENTRY glMultiTexCoord2hNV (GLenum target, GLhalfNV s, GLhalfNV t); +GLAPI void APIENTRY glMultiTexCoord2hvNV (GLenum target, const GLhalfNV *v); +GLAPI void APIENTRY glMultiTexCoord3hNV (GLenum target, GLhalfNV s, GLhalfNV t, GLhalfNV r); +GLAPI void APIENTRY glMultiTexCoord3hvNV (GLenum target, const GLhalfNV *v); +GLAPI void APIENTRY glMultiTexCoord4hNV (GLenum target, GLhalfNV s, GLhalfNV t, GLhalfNV r, GLhalfNV q); +GLAPI void APIENTRY glMultiTexCoord4hvNV (GLenum target, const GLhalfNV *v); +GLAPI void APIENTRY glFogCoordhNV (GLhalfNV fog); +GLAPI void APIENTRY glFogCoordhvNV (const GLhalfNV *fog); +GLAPI void APIENTRY glSecondaryColor3hNV (GLhalfNV red, GLhalfNV green, GLhalfNV blue); +GLAPI void APIENTRY glSecondaryColor3hvNV (const GLhalfNV *v); +GLAPI void APIENTRY glVertexWeighthNV (GLhalfNV weight); +GLAPI void APIENTRY glVertexWeighthvNV (const GLhalfNV *weight); +GLAPI void APIENTRY glVertexAttrib1hNV (GLuint index, GLhalfNV x); +GLAPI void APIENTRY glVertexAttrib1hvNV (GLuint index, const GLhalfNV *v); +GLAPI void APIENTRY glVertexAttrib2hNV (GLuint index, GLhalfNV x, GLhalfNV y); +GLAPI void APIENTRY glVertexAttrib2hvNV (GLuint index, const GLhalfNV *v); +GLAPI void APIENTRY glVertexAttrib3hNV (GLuint index, GLhalfNV x, GLhalfNV y, GLhalfNV z); +GLAPI void APIENTRY glVertexAttrib3hvNV (GLuint index, const GLhalfNV *v); +GLAPI void APIENTRY glVertexAttrib4hNV (GLuint index, GLhalfNV x, GLhalfNV y, GLhalfNV z, GLhalfNV w); +GLAPI void APIENTRY glVertexAttrib4hvNV (GLuint index, const GLhalfNV *v); +GLAPI void APIENTRY glVertexAttribs1hvNV (GLuint index, GLsizei n, const GLhalfNV *v); +GLAPI void APIENTRY glVertexAttribs2hvNV (GLuint index, GLsizei n, const GLhalfNV *v); +GLAPI void APIENTRY glVertexAttribs3hvNV (GLuint index, GLsizei n, const GLhalfNV *v); +GLAPI void APIENTRY glVertexAttribs4hvNV (GLuint index, GLsizei n, const GLhalfNV *v); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLVERTEX2HNVPROC) (GLhalfNV x, GLhalfNV y); +typedef void (APIENTRYP PFNGLVERTEX2HVNVPROC) (const GLhalfNV *v); +typedef void (APIENTRYP PFNGLVERTEX3HNVPROC) (GLhalfNV x, GLhalfNV y, GLhalfNV z); +typedef void (APIENTRYP PFNGLVERTEX3HVNVPROC) (const GLhalfNV *v); +typedef void (APIENTRYP PFNGLVERTEX4HNVPROC) (GLhalfNV x, GLhalfNV y, GLhalfNV z, GLhalfNV w); +typedef void (APIENTRYP PFNGLVERTEX4HVNVPROC) (const GLhalfNV *v); +typedef void (APIENTRYP PFNGLNORMAL3HNVPROC) (GLhalfNV nx, GLhalfNV ny, GLhalfNV nz); +typedef void (APIENTRYP PFNGLNORMAL3HVNVPROC) (const GLhalfNV *v); +typedef void (APIENTRYP PFNGLCOLOR3HNVPROC) (GLhalfNV red, GLhalfNV green, GLhalfNV blue); +typedef void (APIENTRYP PFNGLCOLOR3HVNVPROC) (const GLhalfNV *v); +typedef void (APIENTRYP PFNGLCOLOR4HNVPROC) (GLhalfNV red, GLhalfNV green, GLhalfNV blue, GLhalfNV alpha); +typedef void (APIENTRYP PFNGLCOLOR4HVNVPROC) (const GLhalfNV *v); +typedef void (APIENTRYP PFNGLTEXCOORD1HNVPROC) (GLhalfNV s); +typedef void (APIENTRYP PFNGLTEXCOORD1HVNVPROC) (const GLhalfNV *v); +typedef void (APIENTRYP PFNGLTEXCOORD2HNVPROC) (GLhalfNV s, GLhalfNV t); +typedef void (APIENTRYP PFNGLTEXCOORD2HVNVPROC) (const GLhalfNV *v); +typedef void (APIENTRYP PFNGLTEXCOORD3HNVPROC) (GLhalfNV s, GLhalfNV t, GLhalfNV r); +typedef void (APIENTRYP PFNGLTEXCOORD3HVNVPROC) (const GLhalfNV *v); +typedef void (APIENTRYP PFNGLTEXCOORD4HNVPROC) (GLhalfNV s, GLhalfNV t, GLhalfNV r, GLhalfNV q); +typedef void (APIENTRYP PFNGLTEXCOORD4HVNVPROC) (const GLhalfNV *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1HNVPROC) (GLenum target, GLhalfNV s); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1HVNVPROC) (GLenum target, const GLhalfNV *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2HNVPROC) (GLenum target, GLhalfNV s, GLhalfNV t); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2HVNVPROC) (GLenum target, const GLhalfNV *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3HNVPROC) (GLenum target, GLhalfNV s, GLhalfNV t, GLhalfNV r); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3HVNVPROC) (GLenum target, const GLhalfNV *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4HNVPROC) (GLenum target, GLhalfNV s, GLhalfNV t, GLhalfNV r, GLhalfNV q); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4HVNVPROC) (GLenum target, const GLhalfNV *v); +typedef void (APIENTRYP PFNGLFOGCOORDHNVPROC) (GLhalfNV fog); +typedef void (APIENTRYP PFNGLFOGCOORDHVNVPROC) (const GLhalfNV *fog); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3HNVPROC) (GLhalfNV red, GLhalfNV green, GLhalfNV blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3HVNVPROC) (const GLhalfNV *v); +typedef void (APIENTRYP PFNGLVERTEXWEIGHTHNVPROC) (GLhalfNV weight); +typedef void (APIENTRYP PFNGLVERTEXWEIGHTHVNVPROC) (const GLhalfNV *weight); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1HNVPROC) (GLuint index, GLhalfNV x); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1HVNVPROC) (GLuint index, const GLhalfNV *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2HNVPROC) (GLuint index, GLhalfNV x, GLhalfNV y); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2HVNVPROC) (GLuint index, const GLhalfNV *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3HNVPROC) (GLuint index, GLhalfNV x, GLhalfNV y, GLhalfNV z); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3HVNVPROC) (GLuint index, const GLhalfNV *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4HNVPROC) (GLuint index, GLhalfNV x, GLhalfNV y, GLhalfNV z, GLhalfNV w); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4HVNVPROC) (GLuint index, const GLhalfNV *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS1HVNVPROC) (GLuint index, GLsizei n, const GLhalfNV *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS2HVNVPROC) (GLuint index, GLsizei n, const GLhalfNV *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS3HVNVPROC) (GLuint index, GLsizei n, const GLhalfNV *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS4HVNVPROC) (GLuint index, GLsizei n, const GLhalfNV *v); +#endif + +#ifndef GL_NV_pixel_data_range +#define GL_NV_pixel_data_range 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glPixelDataRangeNV (GLenum target, GLsizei length, GLvoid *pointer); +GLAPI void APIENTRY glFlushPixelDataRangeNV (GLenum target); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPIXELDATARANGENVPROC) (GLenum target, GLsizei length, GLvoid *pointer); +typedef void (APIENTRYP PFNGLFLUSHPIXELDATARANGENVPROC) (GLenum target); +#endif + +#ifndef GL_NV_primitive_restart +#define GL_NV_primitive_restart 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glPrimitiveRestartNV (void); +GLAPI void APIENTRY glPrimitiveRestartIndexNV (GLuint index); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPRIMITIVERESTARTNVPROC) (void); +typedef void (APIENTRYP PFNGLPRIMITIVERESTARTINDEXNVPROC) (GLuint index); +#endif + +#ifndef GL_NV_texture_expand_normal +#define GL_NV_texture_expand_normal 1 +#endif + +#ifndef GL_NV_vertex_program2 +#define GL_NV_vertex_program2 1 +#endif + +#ifndef GL_ATI_map_object_buffer +#define GL_ATI_map_object_buffer 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI GLvoid* APIENTRY glMapObjectBufferATI (GLuint buffer); +GLAPI void APIENTRY glUnmapObjectBufferATI (GLuint buffer); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef GLvoid* (APIENTRYP PFNGLMAPOBJECTBUFFERATIPROC) (GLuint buffer); +typedef void (APIENTRYP PFNGLUNMAPOBJECTBUFFERATIPROC) (GLuint buffer); +#endif + +#ifndef GL_ATI_separate_stencil +#define GL_ATI_separate_stencil 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glStencilOpSeparateATI (GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass); +GLAPI void APIENTRY glStencilFuncSeparateATI (GLenum frontfunc, GLenum backfunc, GLint ref, GLuint mask); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLSTENCILOPSEPARATEATIPROC) (GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass); +typedef void (APIENTRYP PFNGLSTENCILFUNCSEPARATEATIPROC) (GLenum frontfunc, GLenum backfunc, GLint ref, GLuint mask); +#endif + +#ifndef GL_ATI_vertex_attrib_array_object +#define GL_ATI_vertex_attrib_array_object 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glVertexAttribArrayObjectATI (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, GLuint buffer, GLuint offset); +GLAPI void APIENTRY glGetVertexAttribArrayObjectfvATI (GLuint index, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetVertexAttribArrayObjectivATI (GLuint index, GLenum pname, GLint *params); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLVERTEXATTRIBARRAYOBJECTATIPROC) (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, GLuint buffer, GLuint offset); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBARRAYOBJECTFVATIPROC) (GLuint index, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBARRAYOBJECTIVATIPROC) (GLuint index, GLenum pname, GLint *params); +#endif + +#ifndef GL_OES_read_format +#define GL_OES_read_format 1 +#endif + +#ifndef GL_EXT_depth_bounds_test +#define GL_EXT_depth_bounds_test 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDepthBoundsEXT (GLclampd zmin, GLclampd zmax); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDEPTHBOUNDSEXTPROC) (GLclampd zmin, GLclampd zmax); +#endif + +#ifndef GL_EXT_texture_mirror_clamp +#define GL_EXT_texture_mirror_clamp 1 +#endif + +#ifndef GL_EXT_blend_equation_separate +#define GL_EXT_blend_equation_separate 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBlendEquationSeparateEXT (GLenum modeRGB, GLenum modeAlpha); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBLENDEQUATIONSEPARATEEXTPROC) (GLenum modeRGB, GLenum modeAlpha); +#endif + +#ifndef GL_MESA_pack_invert +#define GL_MESA_pack_invert 1 +#endif + +#ifndef GL_MESA_ycbcr_texture +#define GL_MESA_ycbcr_texture 1 +#endif + +#ifndef GL_EXT_pixel_buffer_object +#define GL_EXT_pixel_buffer_object 1 +#endif + +#ifndef GL_NV_fragment_program_option +#define GL_NV_fragment_program_option 1 +#endif + +#ifndef GL_NV_fragment_program2 +#define GL_NV_fragment_program2 1 +#endif + +#ifndef GL_NV_vertex_program2_option +#define GL_NV_vertex_program2_option 1 +#endif + +#ifndef GL_NV_vertex_program3 +#define GL_NV_vertex_program3 1 +#endif + +#ifndef GL_EXT_framebuffer_object +#define GL_EXT_framebuffer_object 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI GLboolean APIENTRY glIsRenderbufferEXT (GLuint renderbuffer); +GLAPI void APIENTRY glBindRenderbufferEXT (GLenum target, GLuint renderbuffer); +GLAPI void APIENTRY glDeleteRenderbuffersEXT (GLsizei n, const GLuint *renderbuffers); +GLAPI void APIENTRY glGenRenderbuffersEXT (GLsizei n, GLuint *renderbuffers); +GLAPI void APIENTRY glRenderbufferStorageEXT (GLenum target, GLenum internalformat, GLsizei width, GLsizei height); +GLAPI void APIENTRY glGetRenderbufferParameterivEXT (GLenum target, GLenum pname, GLint *params); +GLAPI GLboolean APIENTRY glIsFramebufferEXT (GLuint framebuffer); +GLAPI void APIENTRY glBindFramebufferEXT (GLenum target, GLuint framebuffer); +GLAPI void APIENTRY glDeleteFramebuffersEXT (GLsizei n, const GLuint *framebuffers); +GLAPI void APIENTRY glGenFramebuffersEXT (GLsizei n, GLuint *framebuffers); +GLAPI GLenum APIENTRY glCheckFramebufferStatusEXT (GLenum target); +GLAPI void APIENTRY glFramebufferTexture1DEXT (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); +GLAPI void APIENTRY glFramebufferTexture2DEXT (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); +GLAPI void APIENTRY glFramebufferTexture3DEXT (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset); +GLAPI void APIENTRY glFramebufferRenderbufferEXT (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer); +GLAPI void APIENTRY glGetFramebufferAttachmentParameterivEXT (GLenum target, GLenum attachment, GLenum pname, GLint *params); +GLAPI void APIENTRY glGenerateMipmapEXT (GLenum target); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef GLboolean (APIENTRYP PFNGLISRENDERBUFFEREXTPROC) (GLuint renderbuffer); +typedef void (APIENTRYP PFNGLBINDRENDERBUFFEREXTPROC) (GLenum target, GLuint renderbuffer); +typedef void (APIENTRYP PFNGLDELETERENDERBUFFERSEXTPROC) (GLsizei n, const GLuint *renderbuffers); +typedef void (APIENTRYP PFNGLGENRENDERBUFFERSEXTPROC) (GLsizei n, GLuint *renderbuffers); +typedef void (APIENTRYP PFNGLRENDERBUFFERSTORAGEEXTPROC) (GLenum target, GLenum internalformat, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLGETRENDERBUFFERPARAMETERIVEXTPROC) (GLenum target, GLenum pname, GLint *params); +typedef GLboolean (APIENTRYP PFNGLISFRAMEBUFFEREXTPROC) (GLuint framebuffer); +typedef void (APIENTRYP PFNGLBINDFRAMEBUFFEREXTPROC) (GLenum target, GLuint framebuffer); +typedef void (APIENTRYP PFNGLDELETEFRAMEBUFFERSEXTPROC) (GLsizei n, const GLuint *framebuffers); +typedef void (APIENTRYP PFNGLGENFRAMEBUFFERSEXTPROC) (GLsizei n, GLuint *framebuffers); +typedef GLenum (APIENTRYP PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC) (GLenum target); +typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURE1DEXTPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); +typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURE2DEXTPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); +typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURE3DEXTPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset); +typedef void (APIENTRYP PFNGLFRAMEBUFFERRENDERBUFFEREXTPROC) (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer); +typedef void (APIENTRYP PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVEXTPROC) (GLenum target, GLenum attachment, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGENERATEMIPMAPEXTPROC) (GLenum target); +#endif + +#ifndef GL_GREMEDY_string_marker +#define GL_GREMEDY_string_marker 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glStringMarkerGREMEDY (GLsizei len, const GLvoid *string); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLSTRINGMARKERGREMEDYPROC) (GLsizei len, const GLvoid *string); +#endif + +#ifndef GL_EXT_packed_depth_stencil +#define GL_EXT_packed_depth_stencil 1 +#endif + +#ifndef GL_EXT_stencil_clear_tag +#define GL_EXT_stencil_clear_tag 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glStencilClearTagEXT (GLsizei stencilTagBits, GLuint stencilClearTag); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLSTENCILCLEARTAGEXTPROC) (GLsizei stencilTagBits, GLuint stencilClearTag); +#endif + +#ifndef GL_EXT_texture_sRGB +#define GL_EXT_texture_sRGB 1 +#endif + +#ifndef GL_EXT_framebuffer_blit +#define GL_EXT_framebuffer_blit 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBlitFramebufferEXT (GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBLITFRAMEBUFFEREXTPROC) (GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter); +#endif + +#ifndef GL_EXT_framebuffer_multisample +#define GL_EXT_framebuffer_multisample 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glRenderbufferStorageMultisampleEXT (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLRENDERBUFFERSTORAGEMULTISAMPLEEXTPROC) (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height); +#endif + +#ifndef GL_MESAX_texture_stack +#define GL_MESAX_texture_stack 1 +#endif + +#ifndef GL_EXT_timer_query +#define GL_EXT_timer_query 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glGetQueryObjecti64vEXT (GLuint id, GLenum pname, GLint64EXT *params); +GLAPI void APIENTRY glGetQueryObjectui64vEXT (GLuint id, GLenum pname, GLuint64EXT *params); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGETQUERYOBJECTI64VEXTPROC) (GLuint id, GLenum pname, GLint64EXT *params); +typedef void (APIENTRYP PFNGLGETQUERYOBJECTUI64VEXTPROC) (GLuint id, GLenum pname, GLuint64EXT *params); +#endif + +#ifndef GL_EXT_gpu_program_parameters +#define GL_EXT_gpu_program_parameters 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glProgramEnvParameters4fvEXT (GLenum target, GLuint index, GLsizei count, const GLfloat *params); +GLAPI void APIENTRY glProgramLocalParameters4fvEXT (GLenum target, GLuint index, GLsizei count, const GLfloat *params); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETERS4FVEXTPROC) (GLenum target, GLuint index, GLsizei count, const GLfloat *params); +typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETERS4FVEXTPROC) (GLenum target, GLuint index, GLsizei count, const GLfloat *params); +#endif + +#ifndef GL_APPLE_flush_buffer_range +#define GL_APPLE_flush_buffer_range 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBufferParameteriAPPLE (GLenum target, GLenum pname, GLint param); +GLAPI void APIENTRY glFlushMappedBufferRangeAPPLE (GLenum target, GLintptr offset, GLsizeiptr size); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBUFFERPARAMETERIAPPLEPROC) (GLenum target, GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLFLUSHMAPPEDBUFFERRANGEAPPLEPROC) (GLenum target, GLintptr offset, GLsizeiptr size); +#endif + +#ifndef GL_NV_gpu_program4 +#define GL_NV_gpu_program4 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glProgramLocalParameterI4iNV (GLenum target, GLuint index, GLint x, GLint y, GLint z, GLint w); +GLAPI void APIENTRY glProgramLocalParameterI4ivNV (GLenum target, GLuint index, const GLint *params); +GLAPI void APIENTRY glProgramLocalParametersI4ivNV (GLenum target, GLuint index, GLsizei count, const GLint *params); +GLAPI void APIENTRY glProgramLocalParameterI4uiNV (GLenum target, GLuint index, GLuint x, GLuint y, GLuint z, GLuint w); +GLAPI void APIENTRY glProgramLocalParameterI4uivNV (GLenum target, GLuint index, const GLuint *params); +GLAPI void APIENTRY glProgramLocalParametersI4uivNV (GLenum target, GLuint index, GLsizei count, const GLuint *params); +GLAPI void APIENTRY glProgramEnvParameterI4iNV (GLenum target, GLuint index, GLint x, GLint y, GLint z, GLint w); +GLAPI void APIENTRY glProgramEnvParameterI4ivNV (GLenum target, GLuint index, const GLint *params); +GLAPI void APIENTRY glProgramEnvParametersI4ivNV (GLenum target, GLuint index, GLsizei count, const GLint *params); +GLAPI void APIENTRY glProgramEnvParameterI4uiNV (GLenum target, GLuint index, GLuint x, GLuint y, GLuint z, GLuint w); +GLAPI void APIENTRY glProgramEnvParameterI4uivNV (GLenum target, GLuint index, const GLuint *params); +GLAPI void APIENTRY glProgramEnvParametersI4uivNV (GLenum target, GLuint index, GLsizei count, const GLuint *params); +GLAPI void APIENTRY glGetProgramLocalParameterIivNV (GLenum target, GLuint index, GLint *params); +GLAPI void APIENTRY glGetProgramLocalParameterIuivNV (GLenum target, GLuint index, GLuint *params); +GLAPI void APIENTRY glGetProgramEnvParameterIivNV (GLenum target, GLuint index, GLint *params); +GLAPI void APIENTRY glGetProgramEnvParameterIuivNV (GLenum target, GLuint index, GLuint *params); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETERI4INVPROC) (GLenum target, GLuint index, GLint x, GLint y, GLint z, GLint w); +typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETERI4IVNVPROC) (GLenum target, GLuint index, const GLint *params); +typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETERSI4IVNVPROC) (GLenum target, GLuint index, GLsizei count, const GLint *params); +typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETERI4UINVPROC) (GLenum target, GLuint index, GLuint x, GLuint y, GLuint z, GLuint w); +typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETERI4UIVNVPROC) (GLenum target, GLuint index, const GLuint *params); +typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETERSI4UIVNVPROC) (GLenum target, GLuint index, GLsizei count, const GLuint *params); +typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETERI4INVPROC) (GLenum target, GLuint index, GLint x, GLint y, GLint z, GLint w); +typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETERI4IVNVPROC) (GLenum target, GLuint index, const GLint *params); +typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETERSI4IVNVPROC) (GLenum target, GLuint index, GLsizei count, const GLint *params); +typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETERI4UINVPROC) (GLenum target, GLuint index, GLuint x, GLuint y, GLuint z, GLuint w); +typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETERI4UIVNVPROC) (GLenum target, GLuint index, const GLuint *params); +typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETERSI4UIVNVPROC) (GLenum target, GLuint index, GLsizei count, const GLuint *params); +typedef void (APIENTRYP PFNGLGETPROGRAMLOCALPARAMETERIIVNVPROC) (GLenum target, GLuint index, GLint *params); +typedef void (APIENTRYP PFNGLGETPROGRAMLOCALPARAMETERIUIVNVPROC) (GLenum target, GLuint index, GLuint *params); +typedef void (APIENTRYP PFNGLGETPROGRAMENVPARAMETERIIVNVPROC) (GLenum target, GLuint index, GLint *params); +typedef void (APIENTRYP PFNGLGETPROGRAMENVPARAMETERIUIVNVPROC) (GLenum target, GLuint index, GLuint *params); +#endif + +#ifndef GL_NV_geometry_program4 +#define GL_NV_geometry_program4 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glProgramVertexLimitNV (GLenum target, GLint limit); +GLAPI void APIENTRY glFramebufferTextureEXT (GLenum target, GLenum attachment, GLuint texture, GLint level); +GLAPI void APIENTRY glFramebufferTextureLayerEXT (GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer); +GLAPI void APIENTRY glFramebufferTextureFaceEXT (GLenum target, GLenum attachment, GLuint texture, GLint level, GLenum face); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPROGRAMVERTEXLIMITNVPROC) (GLenum target, GLint limit); +typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTUREEXTPROC) (GLenum target, GLenum attachment, GLuint texture, GLint level); +typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURELAYEREXTPROC) (GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer); +typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTUREFACEEXTPROC) (GLenum target, GLenum attachment, GLuint texture, GLint level, GLenum face); +#endif + +#ifndef GL_EXT_geometry_shader4 +#define GL_EXT_geometry_shader4 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glProgramParameteriEXT (GLuint program, GLenum pname, GLint value); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPROGRAMPARAMETERIEXTPROC) (GLuint program, GLenum pname, GLint value); +#endif + +#ifndef GL_NV_vertex_program4 +#define GL_NV_vertex_program4 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glVertexAttribI1iEXT (GLuint index, GLint x); +GLAPI void APIENTRY glVertexAttribI2iEXT (GLuint index, GLint x, GLint y); +GLAPI void APIENTRY glVertexAttribI3iEXT (GLuint index, GLint x, GLint y, GLint z); +GLAPI void APIENTRY glVertexAttribI4iEXT (GLuint index, GLint x, GLint y, GLint z, GLint w); +GLAPI void APIENTRY glVertexAttribI1uiEXT (GLuint index, GLuint x); +GLAPI void APIENTRY glVertexAttribI2uiEXT (GLuint index, GLuint x, GLuint y); +GLAPI void APIENTRY glVertexAttribI3uiEXT (GLuint index, GLuint x, GLuint y, GLuint z); +GLAPI void APIENTRY glVertexAttribI4uiEXT (GLuint index, GLuint x, GLuint y, GLuint z, GLuint w); +GLAPI void APIENTRY glVertexAttribI1ivEXT (GLuint index, const GLint *v); +GLAPI void APIENTRY glVertexAttribI2ivEXT (GLuint index, const GLint *v); +GLAPI void APIENTRY glVertexAttribI3ivEXT (GLuint index, const GLint *v); +GLAPI void APIENTRY glVertexAttribI4ivEXT (GLuint index, const GLint *v); +GLAPI void APIENTRY glVertexAttribI1uivEXT (GLuint index, const GLuint *v); +GLAPI void APIENTRY glVertexAttribI2uivEXT (GLuint index, const GLuint *v); +GLAPI void APIENTRY glVertexAttribI3uivEXT (GLuint index, const GLuint *v); +GLAPI void APIENTRY glVertexAttribI4uivEXT (GLuint index, const GLuint *v); +GLAPI void APIENTRY glVertexAttribI4bvEXT (GLuint index, const GLbyte *v); +GLAPI void APIENTRY glVertexAttribI4svEXT (GLuint index, const GLshort *v); +GLAPI void APIENTRY glVertexAttribI4ubvEXT (GLuint index, const GLubyte *v); +GLAPI void APIENTRY glVertexAttribI4usvEXT (GLuint index, const GLushort *v); +GLAPI void APIENTRY glVertexAttribIPointerEXT (GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +GLAPI void APIENTRY glGetVertexAttribIivEXT (GLuint index, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetVertexAttribIuivEXT (GLuint index, GLenum pname, GLuint *params); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLVERTEXATTRIBI1IEXTPROC) (GLuint index, GLint x); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI2IEXTPROC) (GLuint index, GLint x, GLint y); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI3IEXTPROC) (GLuint index, GLint x, GLint y, GLint z); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI4IEXTPROC) (GLuint index, GLint x, GLint y, GLint z, GLint w); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI1UIEXTPROC) (GLuint index, GLuint x); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI2UIEXTPROC) (GLuint index, GLuint x, GLuint y); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI3UIEXTPROC) (GLuint index, GLuint x, GLuint y, GLuint z); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI4UIEXTPROC) (GLuint index, GLuint x, GLuint y, GLuint z, GLuint w); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI1IVEXTPROC) (GLuint index, const GLint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI2IVEXTPROC) (GLuint index, const GLint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI3IVEXTPROC) (GLuint index, const GLint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI4IVEXTPROC) (GLuint index, const GLint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI1UIVEXTPROC) (GLuint index, const GLuint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI2UIVEXTPROC) (GLuint index, const GLuint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI3UIVEXTPROC) (GLuint index, const GLuint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI4UIVEXTPROC) (GLuint index, const GLuint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI4BVEXTPROC) (GLuint index, const GLbyte *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI4SVEXTPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI4UBVEXTPROC) (GLuint index, const GLubyte *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI4USVEXTPROC) (GLuint index, const GLushort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBIPOINTEREXTPROC) (GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIIVEXTPROC) (GLuint index, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIUIVEXTPROC) (GLuint index, GLenum pname, GLuint *params); +#endif + +#ifndef GL_EXT_gpu_shader4 +#define GL_EXT_gpu_shader4 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glGetUniformuivEXT (GLuint program, GLint location, GLuint *params); +GLAPI void APIENTRY glBindFragDataLocationEXT (GLuint program, GLuint color, const GLchar *name); +GLAPI GLint APIENTRY glGetFragDataLocationEXT (GLuint program, const GLchar *name); +GLAPI void APIENTRY glUniform1uiEXT (GLint location, GLuint v0); +GLAPI void APIENTRY glUniform2uiEXT (GLint location, GLuint v0, GLuint v1); +GLAPI void APIENTRY glUniform3uiEXT (GLint location, GLuint v0, GLuint v1, GLuint v2); +GLAPI void APIENTRY glUniform4uiEXT (GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3); +GLAPI void APIENTRY glUniform1uivEXT (GLint location, GLsizei count, const GLuint *value); +GLAPI void APIENTRY glUniform2uivEXT (GLint location, GLsizei count, const GLuint *value); +GLAPI void APIENTRY glUniform3uivEXT (GLint location, GLsizei count, const GLuint *value); +GLAPI void APIENTRY glUniform4uivEXT (GLint location, GLsizei count, const GLuint *value); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGETUNIFORMUIVEXTPROC) (GLuint program, GLint location, GLuint *params); +typedef void (APIENTRYP PFNGLBINDFRAGDATALOCATIONEXTPROC) (GLuint program, GLuint color, const GLchar *name); +typedef GLint (APIENTRYP PFNGLGETFRAGDATALOCATIONEXTPROC) (GLuint program, const GLchar *name); +typedef void (APIENTRYP PFNGLUNIFORM1UIEXTPROC) (GLint location, GLuint v0); +typedef void (APIENTRYP PFNGLUNIFORM2UIEXTPROC) (GLint location, GLuint v0, GLuint v1); +typedef void (APIENTRYP PFNGLUNIFORM3UIEXTPROC) (GLint location, GLuint v0, GLuint v1, GLuint v2); +typedef void (APIENTRYP PFNGLUNIFORM4UIEXTPROC) (GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3); +typedef void (APIENTRYP PFNGLUNIFORM1UIVEXTPROC) (GLint location, GLsizei count, const GLuint *value); +typedef void (APIENTRYP PFNGLUNIFORM2UIVEXTPROC) (GLint location, GLsizei count, const GLuint *value); +typedef void (APIENTRYP PFNGLUNIFORM3UIVEXTPROC) (GLint location, GLsizei count, const GLuint *value); +typedef void (APIENTRYP PFNGLUNIFORM4UIVEXTPROC) (GLint location, GLsizei count, const GLuint *value); +#endif + +#ifndef GL_EXT_draw_instanced +#define GL_EXT_draw_instanced 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDrawArraysInstancedEXT (GLenum mode, GLint start, GLsizei count, GLsizei primcount); +GLAPI void APIENTRY glDrawElementsInstancedEXT (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei primcount); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDRAWARRAYSINSTANCEDEXTPROC) (GLenum mode, GLint start, GLsizei count, GLsizei primcount); +typedef void (APIENTRYP PFNGLDRAWELEMENTSINSTANCEDEXTPROC) (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei primcount); +#endif + +#ifndef GL_EXT_packed_float +#define GL_EXT_packed_float 1 +#endif + +#ifndef GL_EXT_texture_array +#define GL_EXT_texture_array 1 +#endif + +#ifndef GL_EXT_texture_buffer_object +#define GL_EXT_texture_buffer_object 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTexBufferEXT (GLenum target, GLenum internalformat, GLuint buffer); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLTEXBUFFEREXTPROC) (GLenum target, GLenum internalformat, GLuint buffer); +#endif + +#ifndef GL_EXT_texture_compression_latc +#define GL_EXT_texture_compression_latc 1 +#endif + +#ifndef GL_EXT_texture_compression_rgtc +#define GL_EXT_texture_compression_rgtc 1 +#endif + +#ifndef GL_EXT_texture_shared_exponent +#define GL_EXT_texture_shared_exponent 1 +#endif + +#ifndef GL_NV_depth_buffer_float +#define GL_NV_depth_buffer_float 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDepthRangedNV (GLdouble zNear, GLdouble zFar); +GLAPI void APIENTRY glClearDepthdNV (GLdouble depth); +GLAPI void APIENTRY glDepthBoundsdNV (GLdouble zmin, GLdouble zmax); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDEPTHRANGEDNVPROC) (GLdouble zNear, GLdouble zFar); +typedef void (APIENTRYP PFNGLCLEARDEPTHDNVPROC) (GLdouble depth); +typedef void (APIENTRYP PFNGLDEPTHBOUNDSDNVPROC) (GLdouble zmin, GLdouble zmax); +#endif + +#ifndef GL_NV_fragment_program4 +#define GL_NV_fragment_program4 1 +#endif + +#ifndef GL_NV_framebuffer_multisample_coverage +#define GL_NV_framebuffer_multisample_coverage 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glRenderbufferStorageMultisampleCoverageNV (GLenum target, GLsizei coverageSamples, GLsizei colorSamples, GLenum internalformat, GLsizei width, GLsizei height); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLRENDERBUFFERSTORAGEMULTISAMPLECOVERAGENVPROC) (GLenum target, GLsizei coverageSamples, GLsizei colorSamples, GLenum internalformat, GLsizei width, GLsizei height); +#endif + +#ifndef GL_EXT_framebuffer_sRGB +#define GL_EXT_framebuffer_sRGB 1 +#endif + +#ifndef GL_NV_geometry_shader4 +#define GL_NV_geometry_shader4 1 +#endif + +#ifndef GL_NV_parameter_buffer_object +#define GL_NV_parameter_buffer_object 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glProgramBufferParametersfvNV (GLenum target, GLuint buffer, GLuint index, GLsizei count, const GLfloat *params); +GLAPI void APIENTRY glProgramBufferParametersIivNV (GLenum target, GLuint buffer, GLuint index, GLsizei count, const GLint *params); +GLAPI void APIENTRY glProgramBufferParametersIuivNV (GLenum target, GLuint buffer, GLuint index, GLsizei count, const GLuint *params); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPROGRAMBUFFERPARAMETERSFVNVPROC) (GLenum target, GLuint buffer, GLuint index, GLsizei count, const GLfloat *params); +typedef void (APIENTRYP PFNGLPROGRAMBUFFERPARAMETERSIIVNVPROC) (GLenum target, GLuint buffer, GLuint index, GLsizei count, const GLint *params); +typedef void (APIENTRYP PFNGLPROGRAMBUFFERPARAMETERSIUIVNVPROC) (GLenum target, GLuint buffer, GLuint index, GLsizei count, const GLuint *params); +#endif + +#ifndef GL_EXT_draw_buffers2 +#define GL_EXT_draw_buffers2 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glColorMaskIndexedEXT (GLuint index, GLboolean r, GLboolean g, GLboolean b, GLboolean a); +GLAPI void APIENTRY glGetBooleanIndexedvEXT (GLenum target, GLuint index, GLboolean *data); +GLAPI void APIENTRY glGetIntegerIndexedvEXT (GLenum target, GLuint index, GLint *data); +GLAPI void APIENTRY glEnableIndexedEXT (GLenum target, GLuint index); +GLAPI void APIENTRY glDisableIndexedEXT (GLenum target, GLuint index); +GLAPI GLboolean APIENTRY glIsEnabledIndexedEXT (GLenum target, GLuint index); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCOLORMASKINDEXEDEXTPROC) (GLuint index, GLboolean r, GLboolean g, GLboolean b, GLboolean a); +typedef void (APIENTRYP PFNGLGETBOOLEANINDEXEDVEXTPROC) (GLenum target, GLuint index, GLboolean *data); +typedef void (APIENTRYP PFNGLGETINTEGERINDEXEDVEXTPROC) (GLenum target, GLuint index, GLint *data); +typedef void (APIENTRYP PFNGLENABLEINDEXEDEXTPROC) (GLenum target, GLuint index); +typedef void (APIENTRYP PFNGLDISABLEINDEXEDEXTPROC) (GLenum target, GLuint index); +typedef GLboolean (APIENTRYP PFNGLISENABLEDINDEXEDEXTPROC) (GLenum target, GLuint index); +#endif + +#ifndef GL_NV_transform_feedback +#define GL_NV_transform_feedback 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBeginTransformFeedbackNV (GLenum primitiveMode); +GLAPI void APIENTRY glEndTransformFeedbackNV (void); +GLAPI void APIENTRY glTransformFeedbackAttribsNV (GLuint count, const GLint *attribs, GLenum bufferMode); +GLAPI void APIENTRY glBindBufferRangeNV (GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size); +GLAPI void APIENTRY glBindBufferOffsetNV (GLenum target, GLuint index, GLuint buffer, GLintptr offset); +GLAPI void APIENTRY glBindBufferBaseNV (GLenum target, GLuint index, GLuint buffer); +GLAPI void APIENTRY glTransformFeedbackVaryingsNV (GLuint program, GLsizei count, const GLint *locations, GLenum bufferMode); +GLAPI void APIENTRY glActiveVaryingNV (GLuint program, const GLchar *name); +GLAPI GLint APIENTRY glGetVaryingLocationNV (GLuint program, const GLchar *name); +GLAPI void APIENTRY glGetActiveVaryingNV (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLsizei *size, GLenum *type, GLchar *name); +GLAPI void APIENTRY glGetTransformFeedbackVaryingNV (GLuint program, GLuint index, GLint *location); +GLAPI void APIENTRY glTransformFeedbackStreamAttribsNV (GLsizei count, const GLint *attribs, GLsizei nbuffers, const GLint *bufstreams, GLenum bufferMode); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBEGINTRANSFORMFEEDBACKNVPROC) (GLenum primitiveMode); +typedef void (APIENTRYP PFNGLENDTRANSFORMFEEDBACKNVPROC) (void); +typedef void (APIENTRYP PFNGLTRANSFORMFEEDBACKATTRIBSNVPROC) (GLuint count, const GLint *attribs, GLenum bufferMode); +typedef void (APIENTRYP PFNGLBINDBUFFERRANGENVPROC) (GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size); +typedef void (APIENTRYP PFNGLBINDBUFFEROFFSETNVPROC) (GLenum target, GLuint index, GLuint buffer, GLintptr offset); +typedef void (APIENTRYP PFNGLBINDBUFFERBASENVPROC) (GLenum target, GLuint index, GLuint buffer); +typedef void (APIENTRYP PFNGLTRANSFORMFEEDBACKVARYINGSNVPROC) (GLuint program, GLsizei count, const GLint *locations, GLenum bufferMode); +typedef void (APIENTRYP PFNGLACTIVEVARYINGNVPROC) (GLuint program, const GLchar *name); +typedef GLint (APIENTRYP PFNGLGETVARYINGLOCATIONNVPROC) (GLuint program, const GLchar *name); +typedef void (APIENTRYP PFNGLGETACTIVEVARYINGNVPROC) (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLsizei *size, GLenum *type, GLchar *name); +typedef void (APIENTRYP PFNGLGETTRANSFORMFEEDBACKVARYINGNVPROC) (GLuint program, GLuint index, GLint *location); +typedef void (APIENTRYP PFNGLTRANSFORMFEEDBACKSTREAMATTRIBSNVPROC) (GLsizei count, const GLint *attribs, GLsizei nbuffers, const GLint *bufstreams, GLenum bufferMode); +#endif + +#ifndef GL_EXT_bindable_uniform +#define GL_EXT_bindable_uniform 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glUniformBufferEXT (GLuint program, GLint location, GLuint buffer); +GLAPI GLint APIENTRY glGetUniformBufferSizeEXT (GLuint program, GLint location); +GLAPI GLintptr APIENTRY glGetUniformOffsetEXT (GLuint program, GLint location); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLUNIFORMBUFFEREXTPROC) (GLuint program, GLint location, GLuint buffer); +typedef GLint (APIENTRYP PFNGLGETUNIFORMBUFFERSIZEEXTPROC) (GLuint program, GLint location); +typedef GLintptr (APIENTRYP PFNGLGETUNIFORMOFFSETEXTPROC) (GLuint program, GLint location); +#endif + +#ifndef GL_EXT_texture_integer +#define GL_EXT_texture_integer 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTexParameterIivEXT (GLenum target, GLenum pname, const GLint *params); +GLAPI void APIENTRY glTexParameterIuivEXT (GLenum target, GLenum pname, const GLuint *params); +GLAPI void APIENTRY glGetTexParameterIivEXT (GLenum target, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetTexParameterIuivEXT (GLenum target, GLenum pname, GLuint *params); +GLAPI void APIENTRY glClearColorIiEXT (GLint red, GLint green, GLint blue, GLint alpha); +GLAPI void APIENTRY glClearColorIuiEXT (GLuint red, GLuint green, GLuint blue, GLuint alpha); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLTEXPARAMETERIIVEXTPROC) (GLenum target, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLTEXPARAMETERIUIVEXTPROC) (GLenum target, GLenum pname, const GLuint *params); +typedef void (APIENTRYP PFNGLGETTEXPARAMETERIIVEXTPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETTEXPARAMETERIUIVEXTPROC) (GLenum target, GLenum pname, GLuint *params); +typedef void (APIENTRYP PFNGLCLEARCOLORIIEXTPROC) (GLint red, GLint green, GLint blue, GLint alpha); +typedef void (APIENTRYP PFNGLCLEARCOLORIUIEXTPROC) (GLuint red, GLuint green, GLuint blue, GLuint alpha); +#endif + +#ifndef GL_GREMEDY_frame_terminator +#define GL_GREMEDY_frame_terminator 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glFrameTerminatorGREMEDY (void); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLFRAMETERMINATORGREMEDYPROC) (void); +#endif + +#ifndef GL_NV_conditional_render +#define GL_NV_conditional_render 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBeginConditionalRenderNV (GLuint id, GLenum mode); +GLAPI void APIENTRY glEndConditionalRenderNV (void); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBEGINCONDITIONALRENDERNVPROC) (GLuint id, GLenum mode); +typedef void (APIENTRYP PFNGLENDCONDITIONALRENDERNVPROC) (void); +#endif + +#ifndef GL_NV_present_video +#define GL_NV_present_video 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glPresentFrameKeyedNV (GLuint video_slot, GLuint64EXT minPresentTime, GLuint beginPresentTimeId, GLuint presentDurationId, GLenum type, GLenum target0, GLuint fill0, GLuint key0, GLenum target1, GLuint fill1, GLuint key1); +GLAPI void APIENTRY glPresentFrameDualFillNV (GLuint video_slot, GLuint64EXT minPresentTime, GLuint beginPresentTimeId, GLuint presentDurationId, GLenum type, GLenum target0, GLuint fill0, GLenum target1, GLuint fill1, GLenum target2, GLuint fill2, GLenum target3, GLuint fill3); +GLAPI void APIENTRY glGetVideoivNV (GLuint video_slot, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetVideouivNV (GLuint video_slot, GLenum pname, GLuint *params); +GLAPI void APIENTRY glGetVideoi64vNV (GLuint video_slot, GLenum pname, GLint64EXT *params); +GLAPI void APIENTRY glGetVideoui64vNV (GLuint video_slot, GLenum pname, GLuint64EXT *params); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPRESENTFRAMEKEYEDNVPROC) (GLuint video_slot, GLuint64EXT minPresentTime, GLuint beginPresentTimeId, GLuint presentDurationId, GLenum type, GLenum target0, GLuint fill0, GLuint key0, GLenum target1, GLuint fill1, GLuint key1); +typedef void (APIENTRYP PFNGLPRESENTFRAMEDUALFILLNVPROC) (GLuint video_slot, GLuint64EXT minPresentTime, GLuint beginPresentTimeId, GLuint presentDurationId, GLenum type, GLenum target0, GLuint fill0, GLenum target1, GLuint fill1, GLenum target2, GLuint fill2, GLenum target3, GLuint fill3); +typedef void (APIENTRYP PFNGLGETVIDEOIVNVPROC) (GLuint video_slot, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETVIDEOUIVNVPROC) (GLuint video_slot, GLenum pname, GLuint *params); +typedef void (APIENTRYP PFNGLGETVIDEOI64VNVPROC) (GLuint video_slot, GLenum pname, GLint64EXT *params); +typedef void (APIENTRYP PFNGLGETVIDEOUI64VNVPROC) (GLuint video_slot, GLenum pname, GLuint64EXT *params); +#endif + +#ifndef GL_EXT_transform_feedback +#define GL_EXT_transform_feedback 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBeginTransformFeedbackEXT (GLenum primitiveMode); +GLAPI void APIENTRY glEndTransformFeedbackEXT (void); +GLAPI void APIENTRY glBindBufferRangeEXT (GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size); +GLAPI void APIENTRY glBindBufferOffsetEXT (GLenum target, GLuint index, GLuint buffer, GLintptr offset); +GLAPI void APIENTRY glBindBufferBaseEXT (GLenum target, GLuint index, GLuint buffer); +GLAPI void APIENTRY glTransformFeedbackVaryingsEXT (GLuint program, GLsizei count, const GLchar* *varyings, GLenum bufferMode); +GLAPI void APIENTRY glGetTransformFeedbackVaryingEXT (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLsizei *size, GLenum *type, GLchar *name); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBEGINTRANSFORMFEEDBACKEXTPROC) (GLenum primitiveMode); +typedef void (APIENTRYP PFNGLENDTRANSFORMFEEDBACKEXTPROC) (void); +typedef void (APIENTRYP PFNGLBINDBUFFERRANGEEXTPROC) (GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size); +typedef void (APIENTRYP PFNGLBINDBUFFEROFFSETEXTPROC) (GLenum target, GLuint index, GLuint buffer, GLintptr offset); +typedef void (APIENTRYP PFNGLBINDBUFFERBASEEXTPROC) (GLenum target, GLuint index, GLuint buffer); +typedef void (APIENTRYP PFNGLTRANSFORMFEEDBACKVARYINGSEXTPROC) (GLuint program, GLsizei count, const GLchar* *varyings, GLenum bufferMode); +typedef void (APIENTRYP PFNGLGETTRANSFORMFEEDBACKVARYINGEXTPROC) (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLsizei *size, GLenum *type, GLchar *name); +#endif + +#ifndef GL_EXT_direct_state_access +#define GL_EXT_direct_state_access 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glClientAttribDefaultEXT (GLbitfield mask); +GLAPI void APIENTRY glPushClientAttribDefaultEXT (GLbitfield mask); +GLAPI void APIENTRY glMatrixLoadfEXT (GLenum mode, const GLfloat *m); +GLAPI void APIENTRY glMatrixLoaddEXT (GLenum mode, const GLdouble *m); +GLAPI void APIENTRY glMatrixMultfEXT (GLenum mode, const GLfloat *m); +GLAPI void APIENTRY glMatrixMultdEXT (GLenum mode, const GLdouble *m); +GLAPI void APIENTRY glMatrixLoadIdentityEXT (GLenum mode); +GLAPI void APIENTRY glMatrixRotatefEXT (GLenum mode, GLfloat angle, GLfloat x, GLfloat y, GLfloat z); +GLAPI void APIENTRY glMatrixRotatedEXT (GLenum mode, GLdouble angle, GLdouble x, GLdouble y, GLdouble z); +GLAPI void APIENTRY glMatrixScalefEXT (GLenum mode, GLfloat x, GLfloat y, GLfloat z); +GLAPI void APIENTRY glMatrixScaledEXT (GLenum mode, GLdouble x, GLdouble y, GLdouble z); +GLAPI void APIENTRY glMatrixTranslatefEXT (GLenum mode, GLfloat x, GLfloat y, GLfloat z); +GLAPI void APIENTRY glMatrixTranslatedEXT (GLenum mode, GLdouble x, GLdouble y, GLdouble z); +GLAPI void APIENTRY glMatrixFrustumEXT (GLenum mode, GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar); +GLAPI void APIENTRY glMatrixOrthoEXT (GLenum mode, GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar); +GLAPI void APIENTRY glMatrixPopEXT (GLenum mode); +GLAPI void APIENTRY glMatrixPushEXT (GLenum mode); +GLAPI void APIENTRY glMatrixLoadTransposefEXT (GLenum mode, const GLfloat *m); +GLAPI void APIENTRY glMatrixLoadTransposedEXT (GLenum mode, const GLdouble *m); +GLAPI void APIENTRY glMatrixMultTransposefEXT (GLenum mode, const GLfloat *m); +GLAPI void APIENTRY glMatrixMultTransposedEXT (GLenum mode, const GLdouble *m); +GLAPI void APIENTRY glTextureParameterfEXT (GLuint texture, GLenum target, GLenum pname, GLfloat param); +GLAPI void APIENTRY glTextureParameterfvEXT (GLuint texture, GLenum target, GLenum pname, const GLfloat *params); +GLAPI void APIENTRY glTextureParameteriEXT (GLuint texture, GLenum target, GLenum pname, GLint param); +GLAPI void APIENTRY glTextureParameterivEXT (GLuint texture, GLenum target, GLenum pname, const GLint *params); +GLAPI void APIENTRY glTextureImage1DEXT (GLuint texture, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLenum format, GLenum type, const GLvoid *pixels); +GLAPI void APIENTRY glTextureImage2DEXT (GLuint texture, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels); +GLAPI void APIENTRY glTextureSubImage1DEXT (GLuint texture, GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid *pixels); +GLAPI void APIENTRY glTextureSubImage2DEXT (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels); +GLAPI void APIENTRY glCopyTextureImage1DEXT (GLuint texture, GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLint border); +GLAPI void APIENTRY glCopyTextureImage2DEXT (GLuint texture, GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border); +GLAPI void APIENTRY glCopyTextureSubImage1DEXT (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width); +GLAPI void APIENTRY glCopyTextureSubImage2DEXT (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height); +GLAPI void APIENTRY glGetTextureImageEXT (GLuint texture, GLenum target, GLint level, GLenum format, GLenum type, GLvoid *pixels); +GLAPI void APIENTRY glGetTextureParameterfvEXT (GLuint texture, GLenum target, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetTextureParameterivEXT (GLuint texture, GLenum target, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetTextureLevelParameterfvEXT (GLuint texture, GLenum target, GLint level, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetTextureLevelParameterivEXT (GLuint texture, GLenum target, GLint level, GLenum pname, GLint *params); +GLAPI void APIENTRY glTextureImage3DEXT (GLuint texture, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels); +GLAPI void APIENTRY glTextureSubImage3DEXT (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *pixels); +GLAPI void APIENTRY glCopyTextureSubImage3DEXT (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height); +GLAPI void APIENTRY glMultiTexParameterfEXT (GLenum texunit, GLenum target, GLenum pname, GLfloat param); +GLAPI void APIENTRY glMultiTexParameterfvEXT (GLenum texunit, GLenum target, GLenum pname, const GLfloat *params); +GLAPI void APIENTRY glMultiTexParameteriEXT (GLenum texunit, GLenum target, GLenum pname, GLint param); +GLAPI void APIENTRY glMultiTexParameterivEXT (GLenum texunit, GLenum target, GLenum pname, const GLint *params); +GLAPI void APIENTRY glMultiTexImage1DEXT (GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLenum format, GLenum type, const GLvoid *pixels); +GLAPI void APIENTRY glMultiTexImage2DEXT (GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels); +GLAPI void APIENTRY glMultiTexSubImage1DEXT (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid *pixels); +GLAPI void APIENTRY glMultiTexSubImage2DEXT (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels); +GLAPI void APIENTRY glCopyMultiTexImage1DEXT (GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLint border); +GLAPI void APIENTRY glCopyMultiTexImage2DEXT (GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border); +GLAPI void APIENTRY glCopyMultiTexSubImage1DEXT (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width); +GLAPI void APIENTRY glCopyMultiTexSubImage2DEXT (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height); +GLAPI void APIENTRY glGetMultiTexImageEXT (GLenum texunit, GLenum target, GLint level, GLenum format, GLenum type, GLvoid *pixels); +GLAPI void APIENTRY glGetMultiTexParameterfvEXT (GLenum texunit, GLenum target, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetMultiTexParameterivEXT (GLenum texunit, GLenum target, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetMultiTexLevelParameterfvEXT (GLenum texunit, GLenum target, GLint level, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetMultiTexLevelParameterivEXT (GLenum texunit, GLenum target, GLint level, GLenum pname, GLint *params); +GLAPI void APIENTRY glMultiTexImage3DEXT (GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels); +GLAPI void APIENTRY glMultiTexSubImage3DEXT (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *pixels); +GLAPI void APIENTRY glCopyMultiTexSubImage3DEXT (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height); +GLAPI void APIENTRY glBindMultiTextureEXT (GLenum texunit, GLenum target, GLuint texture); +GLAPI void APIENTRY glEnableClientStateIndexedEXT (GLenum array, GLuint index); +GLAPI void APIENTRY glDisableClientStateIndexedEXT (GLenum array, GLuint index); +GLAPI void APIENTRY glMultiTexCoordPointerEXT (GLenum texunit, GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +GLAPI void APIENTRY glMultiTexEnvfEXT (GLenum texunit, GLenum target, GLenum pname, GLfloat param); +GLAPI void APIENTRY glMultiTexEnvfvEXT (GLenum texunit, GLenum target, GLenum pname, const GLfloat *params); +GLAPI void APIENTRY glMultiTexEnviEXT (GLenum texunit, GLenum target, GLenum pname, GLint param); +GLAPI void APIENTRY glMultiTexEnvivEXT (GLenum texunit, GLenum target, GLenum pname, const GLint *params); +GLAPI void APIENTRY glMultiTexGendEXT (GLenum texunit, GLenum coord, GLenum pname, GLdouble param); +GLAPI void APIENTRY glMultiTexGendvEXT (GLenum texunit, GLenum coord, GLenum pname, const GLdouble *params); +GLAPI void APIENTRY glMultiTexGenfEXT (GLenum texunit, GLenum coord, GLenum pname, GLfloat param); +GLAPI void APIENTRY glMultiTexGenfvEXT (GLenum texunit, GLenum coord, GLenum pname, const GLfloat *params); +GLAPI void APIENTRY glMultiTexGeniEXT (GLenum texunit, GLenum coord, GLenum pname, GLint param); +GLAPI void APIENTRY glMultiTexGenivEXT (GLenum texunit, GLenum coord, GLenum pname, const GLint *params); +GLAPI void APIENTRY glGetMultiTexEnvfvEXT (GLenum texunit, GLenum target, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetMultiTexEnvivEXT (GLenum texunit, GLenum target, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetMultiTexGendvEXT (GLenum texunit, GLenum coord, GLenum pname, GLdouble *params); +GLAPI void APIENTRY glGetMultiTexGenfvEXT (GLenum texunit, GLenum coord, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetMultiTexGenivEXT (GLenum texunit, GLenum coord, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetFloatIndexedvEXT (GLenum target, GLuint index, GLfloat *data); +GLAPI void APIENTRY glGetDoubleIndexedvEXT (GLenum target, GLuint index, GLdouble *data); +GLAPI void APIENTRY glGetPointerIndexedvEXT (GLenum target, GLuint index, GLvoid* *data); +GLAPI void APIENTRY glCompressedTextureImage3DEXT (GLuint texture, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid *bits); +GLAPI void APIENTRY glCompressedTextureImage2DEXT (GLuint texture, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *bits); +GLAPI void APIENTRY glCompressedTextureImage1DEXT (GLuint texture, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const GLvoid *bits); +GLAPI void APIENTRY glCompressedTextureSubImage3DEXT (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid *bits); +GLAPI void APIENTRY glCompressedTextureSubImage2DEXT (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *bits); +GLAPI void APIENTRY glCompressedTextureSubImage1DEXT (GLuint texture, GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const GLvoid *bits); +GLAPI void APIENTRY glGetCompressedTextureImageEXT (GLuint texture, GLenum target, GLint lod, GLvoid *img); +GLAPI void APIENTRY glCompressedMultiTexImage3DEXT (GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid *bits); +GLAPI void APIENTRY glCompressedMultiTexImage2DEXT (GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *bits); +GLAPI void APIENTRY glCompressedMultiTexImage1DEXT (GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const GLvoid *bits); +GLAPI void APIENTRY glCompressedMultiTexSubImage3DEXT (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid *bits); +GLAPI void APIENTRY glCompressedMultiTexSubImage2DEXT (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *bits); +GLAPI void APIENTRY glCompressedMultiTexSubImage1DEXT (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const GLvoid *bits); +GLAPI void APIENTRY glGetCompressedMultiTexImageEXT (GLenum texunit, GLenum target, GLint lod, GLvoid *img); +GLAPI void APIENTRY glNamedProgramStringEXT (GLuint program, GLenum target, GLenum format, GLsizei len, const GLvoid *string); +GLAPI void APIENTRY glNamedProgramLocalParameter4dEXT (GLuint program, GLenum target, GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +GLAPI void APIENTRY glNamedProgramLocalParameter4dvEXT (GLuint program, GLenum target, GLuint index, const GLdouble *params); +GLAPI void APIENTRY glNamedProgramLocalParameter4fEXT (GLuint program, GLenum target, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +GLAPI void APIENTRY glNamedProgramLocalParameter4fvEXT (GLuint program, GLenum target, GLuint index, const GLfloat *params); +GLAPI void APIENTRY glGetNamedProgramLocalParameterdvEXT (GLuint program, GLenum target, GLuint index, GLdouble *params); +GLAPI void APIENTRY glGetNamedProgramLocalParameterfvEXT (GLuint program, GLenum target, GLuint index, GLfloat *params); +GLAPI void APIENTRY glGetNamedProgramivEXT (GLuint program, GLenum target, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetNamedProgramStringEXT (GLuint program, GLenum target, GLenum pname, GLvoid *string); +GLAPI void APIENTRY glNamedProgramLocalParameters4fvEXT (GLuint program, GLenum target, GLuint index, GLsizei count, const GLfloat *params); +GLAPI void APIENTRY glNamedProgramLocalParameterI4iEXT (GLuint program, GLenum target, GLuint index, GLint x, GLint y, GLint z, GLint w); +GLAPI void APIENTRY glNamedProgramLocalParameterI4ivEXT (GLuint program, GLenum target, GLuint index, const GLint *params); +GLAPI void APIENTRY glNamedProgramLocalParametersI4ivEXT (GLuint program, GLenum target, GLuint index, GLsizei count, const GLint *params); +GLAPI void APIENTRY glNamedProgramLocalParameterI4uiEXT (GLuint program, GLenum target, GLuint index, GLuint x, GLuint y, GLuint z, GLuint w); +GLAPI void APIENTRY glNamedProgramLocalParameterI4uivEXT (GLuint program, GLenum target, GLuint index, const GLuint *params); +GLAPI void APIENTRY glNamedProgramLocalParametersI4uivEXT (GLuint program, GLenum target, GLuint index, GLsizei count, const GLuint *params); +GLAPI void APIENTRY glGetNamedProgramLocalParameterIivEXT (GLuint program, GLenum target, GLuint index, GLint *params); +GLAPI void APIENTRY glGetNamedProgramLocalParameterIuivEXT (GLuint program, GLenum target, GLuint index, GLuint *params); +GLAPI void APIENTRY glTextureParameterIivEXT (GLuint texture, GLenum target, GLenum pname, const GLint *params); +GLAPI void APIENTRY glTextureParameterIuivEXT (GLuint texture, GLenum target, GLenum pname, const GLuint *params); +GLAPI void APIENTRY glGetTextureParameterIivEXT (GLuint texture, GLenum target, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetTextureParameterIuivEXT (GLuint texture, GLenum target, GLenum pname, GLuint *params); +GLAPI void APIENTRY glMultiTexParameterIivEXT (GLenum texunit, GLenum target, GLenum pname, const GLint *params); +GLAPI void APIENTRY glMultiTexParameterIuivEXT (GLenum texunit, GLenum target, GLenum pname, const GLuint *params); +GLAPI void APIENTRY glGetMultiTexParameterIivEXT (GLenum texunit, GLenum target, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetMultiTexParameterIuivEXT (GLenum texunit, GLenum target, GLenum pname, GLuint *params); +GLAPI void APIENTRY glProgramUniform1fEXT (GLuint program, GLint location, GLfloat v0); +GLAPI void APIENTRY glProgramUniform2fEXT (GLuint program, GLint location, GLfloat v0, GLfloat v1); +GLAPI void APIENTRY glProgramUniform3fEXT (GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2); +GLAPI void APIENTRY glProgramUniform4fEXT (GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3); +GLAPI void APIENTRY glProgramUniform1iEXT (GLuint program, GLint location, GLint v0); +GLAPI void APIENTRY glProgramUniform2iEXT (GLuint program, GLint location, GLint v0, GLint v1); +GLAPI void APIENTRY glProgramUniform3iEXT (GLuint program, GLint location, GLint v0, GLint v1, GLint v2); +GLAPI void APIENTRY glProgramUniform4iEXT (GLuint program, GLint location, GLint v0, GLint v1, GLint v2, GLint v3); +GLAPI void APIENTRY glProgramUniform1fvEXT (GLuint program, GLint location, GLsizei count, const GLfloat *value); +GLAPI void APIENTRY glProgramUniform2fvEXT (GLuint program, GLint location, GLsizei count, const GLfloat *value); +GLAPI void APIENTRY glProgramUniform3fvEXT (GLuint program, GLint location, GLsizei count, const GLfloat *value); +GLAPI void APIENTRY glProgramUniform4fvEXT (GLuint program, GLint location, GLsizei count, const GLfloat *value); +GLAPI void APIENTRY glProgramUniform1ivEXT (GLuint program, GLint location, GLsizei count, const GLint *value); +GLAPI void APIENTRY glProgramUniform2ivEXT (GLuint program, GLint location, GLsizei count, const GLint *value); +GLAPI void APIENTRY glProgramUniform3ivEXT (GLuint program, GLint location, GLsizei count, const GLint *value); +GLAPI void APIENTRY glProgramUniform4ivEXT (GLuint program, GLint location, GLsizei count, const GLint *value); +GLAPI void APIENTRY glProgramUniformMatrix2fvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glProgramUniformMatrix3fvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glProgramUniformMatrix4fvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glProgramUniformMatrix2x3fvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glProgramUniformMatrix3x2fvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glProgramUniformMatrix2x4fvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glProgramUniformMatrix4x2fvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glProgramUniformMatrix3x4fvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glProgramUniformMatrix4x3fvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glProgramUniform1uiEXT (GLuint program, GLint location, GLuint v0); +GLAPI void APIENTRY glProgramUniform2uiEXT (GLuint program, GLint location, GLuint v0, GLuint v1); +GLAPI void APIENTRY glProgramUniform3uiEXT (GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2); +GLAPI void APIENTRY glProgramUniform4uiEXT (GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3); +GLAPI void APIENTRY glProgramUniform1uivEXT (GLuint program, GLint location, GLsizei count, const GLuint *value); +GLAPI void APIENTRY glProgramUniform2uivEXT (GLuint program, GLint location, GLsizei count, const GLuint *value); +GLAPI void APIENTRY glProgramUniform3uivEXT (GLuint program, GLint location, GLsizei count, const GLuint *value); +GLAPI void APIENTRY glProgramUniform4uivEXT (GLuint program, GLint location, GLsizei count, const GLuint *value); +GLAPI void APIENTRY glNamedBufferDataEXT (GLuint buffer, GLsizeiptr size, const GLvoid *data, GLenum usage); +GLAPI void APIENTRY glNamedBufferSubDataEXT (GLuint buffer, GLintptr offset, GLsizeiptr size, const GLvoid *data); +GLAPI GLvoid* APIENTRY glMapNamedBufferEXT (GLuint buffer, GLenum access); +GLAPI GLboolean APIENTRY glUnmapNamedBufferEXT (GLuint buffer); +GLAPI GLvoid* APIENTRY glMapNamedBufferRangeEXT (GLuint buffer, GLintptr offset, GLsizeiptr length, GLbitfield access); +GLAPI void APIENTRY glFlushMappedNamedBufferRangeEXT (GLuint buffer, GLintptr offset, GLsizeiptr length); +GLAPI void APIENTRY glNamedCopyBufferSubDataEXT (GLuint readBuffer, GLuint writeBuffer, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size); +GLAPI void APIENTRY glGetNamedBufferParameterivEXT (GLuint buffer, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetNamedBufferPointervEXT (GLuint buffer, GLenum pname, GLvoid* *params); +GLAPI void APIENTRY glGetNamedBufferSubDataEXT (GLuint buffer, GLintptr offset, GLsizeiptr size, GLvoid *data); +GLAPI void APIENTRY glTextureBufferEXT (GLuint texture, GLenum target, GLenum internalformat, GLuint buffer); +GLAPI void APIENTRY glMultiTexBufferEXT (GLenum texunit, GLenum target, GLenum internalformat, GLuint buffer); +GLAPI void APIENTRY glNamedRenderbufferStorageEXT (GLuint renderbuffer, GLenum internalformat, GLsizei width, GLsizei height); +GLAPI void APIENTRY glGetNamedRenderbufferParameterivEXT (GLuint renderbuffer, GLenum pname, GLint *params); +GLAPI GLenum APIENTRY glCheckNamedFramebufferStatusEXT (GLuint framebuffer, GLenum target); +GLAPI void APIENTRY glNamedFramebufferTexture1DEXT (GLuint framebuffer, GLenum attachment, GLenum textarget, GLuint texture, GLint level); +GLAPI void APIENTRY glNamedFramebufferTexture2DEXT (GLuint framebuffer, GLenum attachment, GLenum textarget, GLuint texture, GLint level); +GLAPI void APIENTRY glNamedFramebufferTexture3DEXT (GLuint framebuffer, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset); +GLAPI void APIENTRY glNamedFramebufferRenderbufferEXT (GLuint framebuffer, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer); +GLAPI void APIENTRY glGetNamedFramebufferAttachmentParameterivEXT (GLuint framebuffer, GLenum attachment, GLenum pname, GLint *params); +GLAPI void APIENTRY glGenerateTextureMipmapEXT (GLuint texture, GLenum target); +GLAPI void APIENTRY glGenerateMultiTexMipmapEXT (GLenum texunit, GLenum target); +GLAPI void APIENTRY glFramebufferDrawBufferEXT (GLuint framebuffer, GLenum mode); +GLAPI void APIENTRY glFramebufferDrawBuffersEXT (GLuint framebuffer, GLsizei n, const GLenum *bufs); +GLAPI void APIENTRY glFramebufferReadBufferEXT (GLuint framebuffer, GLenum mode); +GLAPI void APIENTRY glGetFramebufferParameterivEXT (GLuint framebuffer, GLenum pname, GLint *params); +GLAPI void APIENTRY glNamedRenderbufferStorageMultisampleEXT (GLuint renderbuffer, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height); +GLAPI void APIENTRY glNamedRenderbufferStorageMultisampleCoverageEXT (GLuint renderbuffer, GLsizei coverageSamples, GLsizei colorSamples, GLenum internalformat, GLsizei width, GLsizei height); +GLAPI void APIENTRY glNamedFramebufferTextureEXT (GLuint framebuffer, GLenum attachment, GLuint texture, GLint level); +GLAPI void APIENTRY glNamedFramebufferTextureLayerEXT (GLuint framebuffer, GLenum attachment, GLuint texture, GLint level, GLint layer); +GLAPI void APIENTRY glNamedFramebufferTextureFaceEXT (GLuint framebuffer, GLenum attachment, GLuint texture, GLint level, GLenum face); +GLAPI void APIENTRY glTextureRenderbufferEXT (GLuint texture, GLenum target, GLuint renderbuffer); +GLAPI void APIENTRY glMultiTexRenderbufferEXT (GLenum texunit, GLenum target, GLuint renderbuffer); +GLAPI void APIENTRY glProgramUniform1dEXT (GLuint program, GLint location, GLdouble x); +GLAPI void APIENTRY glProgramUniform2dEXT (GLuint program, GLint location, GLdouble x, GLdouble y); +GLAPI void APIENTRY glProgramUniform3dEXT (GLuint program, GLint location, GLdouble x, GLdouble y, GLdouble z); +GLAPI void APIENTRY glProgramUniform4dEXT (GLuint program, GLint location, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +GLAPI void APIENTRY glProgramUniform1dvEXT (GLuint program, GLint location, GLsizei count, const GLdouble *value); +GLAPI void APIENTRY glProgramUniform2dvEXT (GLuint program, GLint location, GLsizei count, const GLdouble *value); +GLAPI void APIENTRY glProgramUniform3dvEXT (GLuint program, GLint location, GLsizei count, const GLdouble *value); +GLAPI void APIENTRY glProgramUniform4dvEXT (GLuint program, GLint location, GLsizei count, const GLdouble *value); +GLAPI void APIENTRY glProgramUniformMatrix2dvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glProgramUniformMatrix3dvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glProgramUniformMatrix4dvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glProgramUniformMatrix2x3dvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glProgramUniformMatrix2x4dvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glProgramUniformMatrix3x2dvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glProgramUniformMatrix3x4dvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glProgramUniformMatrix4x2dvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glProgramUniformMatrix4x3dvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCLIENTATTRIBDEFAULTEXTPROC) (GLbitfield mask); +typedef void (APIENTRYP PFNGLPUSHCLIENTATTRIBDEFAULTEXTPROC) (GLbitfield mask); +typedef void (APIENTRYP PFNGLMATRIXLOADFEXTPROC) (GLenum mode, const GLfloat *m); +typedef void (APIENTRYP PFNGLMATRIXLOADDEXTPROC) (GLenum mode, const GLdouble *m); +typedef void (APIENTRYP PFNGLMATRIXMULTFEXTPROC) (GLenum mode, const GLfloat *m); +typedef void (APIENTRYP PFNGLMATRIXMULTDEXTPROC) (GLenum mode, const GLdouble *m); +typedef void (APIENTRYP PFNGLMATRIXLOADIDENTITYEXTPROC) (GLenum mode); +typedef void (APIENTRYP PFNGLMATRIXROTATEFEXTPROC) (GLenum mode, GLfloat angle, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLMATRIXROTATEDEXTPROC) (GLenum mode, GLdouble angle, GLdouble x, GLdouble y, GLdouble z); +typedef void (APIENTRYP PFNGLMATRIXSCALEFEXTPROC) (GLenum mode, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLMATRIXSCALEDEXTPROC) (GLenum mode, GLdouble x, GLdouble y, GLdouble z); +typedef void (APIENTRYP PFNGLMATRIXTRANSLATEFEXTPROC) (GLenum mode, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLMATRIXTRANSLATEDEXTPROC) (GLenum mode, GLdouble x, GLdouble y, GLdouble z); +typedef void (APIENTRYP PFNGLMATRIXFRUSTUMEXTPROC) (GLenum mode, GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar); +typedef void (APIENTRYP PFNGLMATRIXORTHOEXTPROC) (GLenum mode, GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar); +typedef void (APIENTRYP PFNGLMATRIXPOPEXTPROC) (GLenum mode); +typedef void (APIENTRYP PFNGLMATRIXPUSHEXTPROC) (GLenum mode); +typedef void (APIENTRYP PFNGLMATRIXLOADTRANSPOSEFEXTPROC) (GLenum mode, const GLfloat *m); +typedef void (APIENTRYP PFNGLMATRIXLOADTRANSPOSEDEXTPROC) (GLenum mode, const GLdouble *m); +typedef void (APIENTRYP PFNGLMATRIXMULTTRANSPOSEFEXTPROC) (GLenum mode, const GLfloat *m); +typedef void (APIENTRYP PFNGLMATRIXMULTTRANSPOSEDEXTPROC) (GLenum mode, const GLdouble *m); +typedef void (APIENTRYP PFNGLTEXTUREPARAMETERFEXTPROC) (GLuint texture, GLenum target, GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLTEXTUREPARAMETERFVEXTPROC) (GLuint texture, GLenum target, GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLTEXTUREPARAMETERIEXTPROC) (GLuint texture, GLenum target, GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLTEXTUREPARAMETERIVEXTPROC) (GLuint texture, GLenum target, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLTEXTUREIMAGE1DEXTPROC) (GLuint texture, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLenum format, GLenum type, const GLvoid *pixels); +typedef void (APIENTRYP PFNGLTEXTUREIMAGE2DEXTPROC) (GLuint texture, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels); +typedef void (APIENTRYP PFNGLTEXTURESUBIMAGE1DEXTPROC) (GLuint texture, GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid *pixels); +typedef void (APIENTRYP PFNGLTEXTURESUBIMAGE2DEXTPROC) (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels); +typedef void (APIENTRYP PFNGLCOPYTEXTUREIMAGE1DEXTPROC) (GLuint texture, GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLint border); +typedef void (APIENTRYP PFNGLCOPYTEXTUREIMAGE2DEXTPROC) (GLuint texture, GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border); +typedef void (APIENTRYP PFNGLCOPYTEXTURESUBIMAGE1DEXTPROC) (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width); +typedef void (APIENTRYP PFNGLCOPYTEXTURESUBIMAGE2DEXTPROC) (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLGETTEXTUREIMAGEEXTPROC) (GLuint texture, GLenum target, GLint level, GLenum format, GLenum type, GLvoid *pixels); +typedef void (APIENTRYP PFNGLGETTEXTUREPARAMETERFVEXTPROC) (GLuint texture, GLenum target, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETTEXTUREPARAMETERIVEXTPROC) (GLuint texture, GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETTEXTURELEVELPARAMETERFVEXTPROC) (GLuint texture, GLenum target, GLint level, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETTEXTURELEVELPARAMETERIVEXTPROC) (GLuint texture, GLenum target, GLint level, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLTEXTUREIMAGE3DEXTPROC) (GLuint texture, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels); +typedef void (APIENTRYP PFNGLTEXTURESUBIMAGE3DEXTPROC) (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *pixels); +typedef void (APIENTRYP PFNGLCOPYTEXTURESUBIMAGE3DEXTPROC) (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLMULTITEXPARAMETERFEXTPROC) (GLenum texunit, GLenum target, GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLMULTITEXPARAMETERFVEXTPROC) (GLenum texunit, GLenum target, GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLMULTITEXPARAMETERIEXTPROC) (GLenum texunit, GLenum target, GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLMULTITEXPARAMETERIVEXTPROC) (GLenum texunit, GLenum target, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLMULTITEXIMAGE1DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLenum format, GLenum type, const GLvoid *pixels); +typedef void (APIENTRYP PFNGLMULTITEXIMAGE2DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels); +typedef void (APIENTRYP PFNGLMULTITEXSUBIMAGE1DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid *pixels); +typedef void (APIENTRYP PFNGLMULTITEXSUBIMAGE2DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels); +typedef void (APIENTRYP PFNGLCOPYMULTITEXIMAGE1DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLint border); +typedef void (APIENTRYP PFNGLCOPYMULTITEXIMAGE2DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border); +typedef void (APIENTRYP PFNGLCOPYMULTITEXSUBIMAGE1DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width); +typedef void (APIENTRYP PFNGLCOPYMULTITEXSUBIMAGE2DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLGETMULTITEXIMAGEEXTPROC) (GLenum texunit, GLenum target, GLint level, GLenum format, GLenum type, GLvoid *pixels); +typedef void (APIENTRYP PFNGLGETMULTITEXPARAMETERFVEXTPROC) (GLenum texunit, GLenum target, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETMULTITEXPARAMETERIVEXTPROC) (GLenum texunit, GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETMULTITEXLEVELPARAMETERFVEXTPROC) (GLenum texunit, GLenum target, GLint level, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETMULTITEXLEVELPARAMETERIVEXTPROC) (GLenum texunit, GLenum target, GLint level, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLMULTITEXIMAGE3DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels); +typedef void (APIENTRYP PFNGLMULTITEXSUBIMAGE3DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *pixels); +typedef void (APIENTRYP PFNGLCOPYMULTITEXSUBIMAGE3DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLBINDMULTITEXTUREEXTPROC) (GLenum texunit, GLenum target, GLuint texture); +typedef void (APIENTRYP PFNGLENABLECLIENTSTATEINDEXEDEXTPROC) (GLenum array, GLuint index); +typedef void (APIENTRYP PFNGLDISABLECLIENTSTATEINDEXEDEXTPROC) (GLenum array, GLuint index); +typedef void (APIENTRYP PFNGLMULTITEXCOORDPOINTEREXTPROC) (GLenum texunit, GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +typedef void (APIENTRYP PFNGLMULTITEXENVFEXTPROC) (GLenum texunit, GLenum target, GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLMULTITEXENVFVEXTPROC) (GLenum texunit, GLenum target, GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLMULTITEXENVIEXTPROC) (GLenum texunit, GLenum target, GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLMULTITEXENVIVEXTPROC) (GLenum texunit, GLenum target, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLMULTITEXGENDEXTPROC) (GLenum texunit, GLenum coord, GLenum pname, GLdouble param); +typedef void (APIENTRYP PFNGLMULTITEXGENDVEXTPROC) (GLenum texunit, GLenum coord, GLenum pname, const GLdouble *params); +typedef void (APIENTRYP PFNGLMULTITEXGENFEXTPROC) (GLenum texunit, GLenum coord, GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLMULTITEXGENFVEXTPROC) (GLenum texunit, GLenum coord, GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLMULTITEXGENIEXTPROC) (GLenum texunit, GLenum coord, GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLMULTITEXGENIVEXTPROC) (GLenum texunit, GLenum coord, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLGETMULTITEXENVFVEXTPROC) (GLenum texunit, GLenum target, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETMULTITEXENVIVEXTPROC) (GLenum texunit, GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETMULTITEXGENDVEXTPROC) (GLenum texunit, GLenum coord, GLenum pname, GLdouble *params); +typedef void (APIENTRYP PFNGLGETMULTITEXGENFVEXTPROC) (GLenum texunit, GLenum coord, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETMULTITEXGENIVEXTPROC) (GLenum texunit, GLenum coord, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETFLOATINDEXEDVEXTPROC) (GLenum target, GLuint index, GLfloat *data); +typedef void (APIENTRYP PFNGLGETDOUBLEINDEXEDVEXTPROC) (GLenum target, GLuint index, GLdouble *data); +typedef void (APIENTRYP PFNGLGETPOINTERINDEXEDVEXTPROC) (GLenum target, GLuint index, GLvoid* *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXTUREIMAGE3DEXTPROC) (GLuint texture, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid *bits); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXTUREIMAGE2DEXTPROC) (GLuint texture, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *bits); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXTUREIMAGE1DEXTPROC) (GLuint texture, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const GLvoid *bits); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXTURESUBIMAGE3DEXTPROC) (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid *bits); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXTURESUBIMAGE2DEXTPROC) (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *bits); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXTURESUBIMAGE1DEXTPROC) (GLuint texture, GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const GLvoid *bits); +typedef void (APIENTRYP PFNGLGETCOMPRESSEDTEXTUREIMAGEEXTPROC) (GLuint texture, GLenum target, GLint lod, GLvoid *img); +typedef void (APIENTRYP PFNGLCOMPRESSEDMULTITEXIMAGE3DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid *bits); +typedef void (APIENTRYP PFNGLCOMPRESSEDMULTITEXIMAGE2DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *bits); +typedef void (APIENTRYP PFNGLCOMPRESSEDMULTITEXIMAGE1DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const GLvoid *bits); +typedef void (APIENTRYP PFNGLCOMPRESSEDMULTITEXSUBIMAGE3DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid *bits); +typedef void (APIENTRYP PFNGLCOMPRESSEDMULTITEXSUBIMAGE2DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *bits); +typedef void (APIENTRYP PFNGLCOMPRESSEDMULTITEXSUBIMAGE1DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const GLvoid *bits); +typedef void (APIENTRYP PFNGLGETCOMPRESSEDMULTITEXIMAGEEXTPROC) (GLenum texunit, GLenum target, GLint lod, GLvoid *img); +typedef void (APIENTRYP PFNGLNAMEDPROGRAMSTRINGEXTPROC) (GLuint program, GLenum target, GLenum format, GLsizei len, const GLvoid *string); +typedef void (APIENTRYP PFNGLNAMEDPROGRAMLOCALPARAMETER4DEXTPROC) (GLuint program, GLenum target, GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +typedef void (APIENTRYP PFNGLNAMEDPROGRAMLOCALPARAMETER4DVEXTPROC) (GLuint program, GLenum target, GLuint index, const GLdouble *params); +typedef void (APIENTRYP PFNGLNAMEDPROGRAMLOCALPARAMETER4FEXTPROC) (GLuint program, GLenum target, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +typedef void (APIENTRYP PFNGLNAMEDPROGRAMLOCALPARAMETER4FVEXTPROC) (GLuint program, GLenum target, GLuint index, const GLfloat *params); +typedef void (APIENTRYP PFNGLGETNAMEDPROGRAMLOCALPARAMETERDVEXTPROC) (GLuint program, GLenum target, GLuint index, GLdouble *params); +typedef void (APIENTRYP PFNGLGETNAMEDPROGRAMLOCALPARAMETERFVEXTPROC) (GLuint program, GLenum target, GLuint index, GLfloat *params); +typedef void (APIENTRYP PFNGLGETNAMEDPROGRAMIVEXTPROC) (GLuint program, GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETNAMEDPROGRAMSTRINGEXTPROC) (GLuint program, GLenum target, GLenum pname, GLvoid *string); +typedef void (APIENTRYP PFNGLNAMEDPROGRAMLOCALPARAMETERS4FVEXTPROC) (GLuint program, GLenum target, GLuint index, GLsizei count, const GLfloat *params); +typedef void (APIENTRYP PFNGLNAMEDPROGRAMLOCALPARAMETERI4IEXTPROC) (GLuint program, GLenum target, GLuint index, GLint x, GLint y, GLint z, GLint w); +typedef void (APIENTRYP PFNGLNAMEDPROGRAMLOCALPARAMETERI4IVEXTPROC) (GLuint program, GLenum target, GLuint index, const GLint *params); +typedef void (APIENTRYP PFNGLNAMEDPROGRAMLOCALPARAMETERSI4IVEXTPROC) (GLuint program, GLenum target, GLuint index, GLsizei count, const GLint *params); +typedef void (APIENTRYP PFNGLNAMEDPROGRAMLOCALPARAMETERI4UIEXTPROC) (GLuint program, GLenum target, GLuint index, GLuint x, GLuint y, GLuint z, GLuint w); +typedef void (APIENTRYP PFNGLNAMEDPROGRAMLOCALPARAMETERI4UIVEXTPROC) (GLuint program, GLenum target, GLuint index, const GLuint *params); +typedef void (APIENTRYP PFNGLNAMEDPROGRAMLOCALPARAMETERSI4UIVEXTPROC) (GLuint program, GLenum target, GLuint index, GLsizei count, const GLuint *params); +typedef void (APIENTRYP PFNGLGETNAMEDPROGRAMLOCALPARAMETERIIVEXTPROC) (GLuint program, GLenum target, GLuint index, GLint *params); +typedef void (APIENTRYP PFNGLGETNAMEDPROGRAMLOCALPARAMETERIUIVEXTPROC) (GLuint program, GLenum target, GLuint index, GLuint *params); +typedef void (APIENTRYP PFNGLTEXTUREPARAMETERIIVEXTPROC) (GLuint texture, GLenum target, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLTEXTUREPARAMETERIUIVEXTPROC) (GLuint texture, GLenum target, GLenum pname, const GLuint *params); +typedef void (APIENTRYP PFNGLGETTEXTUREPARAMETERIIVEXTPROC) (GLuint texture, GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETTEXTUREPARAMETERIUIVEXTPROC) (GLuint texture, GLenum target, GLenum pname, GLuint *params); +typedef void (APIENTRYP PFNGLMULTITEXPARAMETERIIVEXTPROC) (GLenum texunit, GLenum target, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLMULTITEXPARAMETERIUIVEXTPROC) (GLenum texunit, GLenum target, GLenum pname, const GLuint *params); +typedef void (APIENTRYP PFNGLGETMULTITEXPARAMETERIIVEXTPROC) (GLenum texunit, GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETMULTITEXPARAMETERIUIVEXTPROC) (GLenum texunit, GLenum target, GLenum pname, GLuint *params); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1FEXTPROC) (GLuint program, GLint location, GLfloat v0); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2FEXTPROC) (GLuint program, GLint location, GLfloat v0, GLfloat v1); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3FEXTPROC) (GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4FEXTPROC) (GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1IEXTPROC) (GLuint program, GLint location, GLint v0); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2IEXTPROC) (GLuint program, GLint location, GLint v0, GLint v1); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3IEXTPROC) (GLuint program, GLint location, GLint v0, GLint v1, GLint v2); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4IEXTPROC) (GLuint program, GLint location, GLint v0, GLint v1, GLint v2, GLint v3); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1FVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2FVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3FVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4FVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1IVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2IVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3IVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4IVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2FVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3FVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4FVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2X3FVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3X2FVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2X4FVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4X2FVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3X4FVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4X3FVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1UIEXTPROC) (GLuint program, GLint location, GLuint v0); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2UIEXTPROC) (GLuint program, GLint location, GLuint v0, GLuint v1); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3UIEXTPROC) (GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4UIEXTPROC) (GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1UIVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLuint *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2UIVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLuint *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3UIVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLuint *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4UIVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLuint *value); +typedef void (APIENTRYP PFNGLNAMEDBUFFERDATAEXTPROC) (GLuint buffer, GLsizeiptr size, const GLvoid *data, GLenum usage); +typedef void (APIENTRYP PFNGLNAMEDBUFFERSUBDATAEXTPROC) (GLuint buffer, GLintptr offset, GLsizeiptr size, const GLvoid *data); +typedef GLvoid* (APIENTRYP PFNGLMAPNAMEDBUFFEREXTPROC) (GLuint buffer, GLenum access); +typedef GLboolean (APIENTRYP PFNGLUNMAPNAMEDBUFFEREXTPROC) (GLuint buffer); +typedef GLvoid* (APIENTRYP PFNGLMAPNAMEDBUFFERRANGEEXTPROC) (GLuint buffer, GLintptr offset, GLsizeiptr length, GLbitfield access); +typedef void (APIENTRYP PFNGLFLUSHMAPPEDNAMEDBUFFERRANGEEXTPROC) (GLuint buffer, GLintptr offset, GLsizeiptr length); +typedef void (APIENTRYP PFNGLNAMEDCOPYBUFFERSUBDATAEXTPROC) (GLuint readBuffer, GLuint writeBuffer, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size); +typedef void (APIENTRYP PFNGLGETNAMEDBUFFERPARAMETERIVEXTPROC) (GLuint buffer, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETNAMEDBUFFERPOINTERVEXTPROC) (GLuint buffer, GLenum pname, GLvoid* *params); +typedef void (APIENTRYP PFNGLGETNAMEDBUFFERSUBDATAEXTPROC) (GLuint buffer, GLintptr offset, GLsizeiptr size, GLvoid *data); +typedef void (APIENTRYP PFNGLTEXTUREBUFFEREXTPROC) (GLuint texture, GLenum target, GLenum internalformat, GLuint buffer); +typedef void (APIENTRYP PFNGLMULTITEXBUFFEREXTPROC) (GLenum texunit, GLenum target, GLenum internalformat, GLuint buffer); +typedef void (APIENTRYP PFNGLNAMEDRENDERBUFFERSTORAGEEXTPROC) (GLuint renderbuffer, GLenum internalformat, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLGETNAMEDRENDERBUFFERPARAMETERIVEXTPROC) (GLuint renderbuffer, GLenum pname, GLint *params); +typedef GLenum (APIENTRYP PFNGLCHECKNAMEDFRAMEBUFFERSTATUSEXTPROC) (GLuint framebuffer, GLenum target); +typedef void (APIENTRYP PFNGLNAMEDFRAMEBUFFERTEXTURE1DEXTPROC) (GLuint framebuffer, GLenum attachment, GLenum textarget, GLuint texture, GLint level); +typedef void (APIENTRYP PFNGLNAMEDFRAMEBUFFERTEXTURE2DEXTPROC) (GLuint framebuffer, GLenum attachment, GLenum textarget, GLuint texture, GLint level); +typedef void (APIENTRYP PFNGLNAMEDFRAMEBUFFERTEXTURE3DEXTPROC) (GLuint framebuffer, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset); +typedef void (APIENTRYP PFNGLNAMEDFRAMEBUFFERRENDERBUFFEREXTPROC) (GLuint framebuffer, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer); +typedef void (APIENTRYP PFNGLGETNAMEDFRAMEBUFFERATTACHMENTPARAMETERIVEXTPROC) (GLuint framebuffer, GLenum attachment, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGENERATETEXTUREMIPMAPEXTPROC) (GLuint texture, GLenum target); +typedef void (APIENTRYP PFNGLGENERATEMULTITEXMIPMAPEXTPROC) (GLenum texunit, GLenum target); +typedef void (APIENTRYP PFNGLFRAMEBUFFERDRAWBUFFEREXTPROC) (GLuint framebuffer, GLenum mode); +typedef void (APIENTRYP PFNGLFRAMEBUFFERDRAWBUFFERSEXTPROC) (GLuint framebuffer, GLsizei n, const GLenum *bufs); +typedef void (APIENTRYP PFNGLFRAMEBUFFERREADBUFFEREXTPROC) (GLuint framebuffer, GLenum mode); +typedef void (APIENTRYP PFNGLGETFRAMEBUFFERPARAMETERIVEXTPROC) (GLuint framebuffer, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLNAMEDRENDERBUFFERSTORAGEMULTISAMPLEEXTPROC) (GLuint renderbuffer, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLNAMEDRENDERBUFFERSTORAGEMULTISAMPLECOVERAGEEXTPROC) (GLuint renderbuffer, GLsizei coverageSamples, GLsizei colorSamples, GLenum internalformat, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLNAMEDFRAMEBUFFERTEXTUREEXTPROC) (GLuint framebuffer, GLenum attachment, GLuint texture, GLint level); +typedef void (APIENTRYP PFNGLNAMEDFRAMEBUFFERTEXTURELAYEREXTPROC) (GLuint framebuffer, GLenum attachment, GLuint texture, GLint level, GLint layer); +typedef void (APIENTRYP PFNGLNAMEDFRAMEBUFFERTEXTUREFACEEXTPROC) (GLuint framebuffer, GLenum attachment, GLuint texture, GLint level, GLenum face); +typedef void (APIENTRYP PFNGLTEXTURERENDERBUFFEREXTPROC) (GLuint texture, GLenum target, GLuint renderbuffer); +typedef void (APIENTRYP PFNGLMULTITEXRENDERBUFFEREXTPROC) (GLenum texunit, GLenum target, GLuint renderbuffer); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1DEXTPROC) (GLuint program, GLint location, GLdouble x); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2DEXTPROC) (GLuint program, GLint location, GLdouble x, GLdouble y); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3DEXTPROC) (GLuint program, GLint location, GLdouble x, GLdouble y, GLdouble z); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4DEXTPROC) (GLuint program, GLint location, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1DVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2DVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3DVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4DVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2DVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3DVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4DVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2X3DVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2X4DVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3X2DVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3X4DVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4X2DVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4X3DVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +#endif + +#ifndef GL_EXT_vertex_array_bgra +#define GL_EXT_vertex_array_bgra 1 +#endif + +#ifndef GL_EXT_texture_swizzle +#define GL_EXT_texture_swizzle 1 +#endif + +#ifndef GL_NV_explicit_multisample +#define GL_NV_explicit_multisample 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glGetMultisamplefvNV (GLenum pname, GLuint index, GLfloat *val); +GLAPI void APIENTRY glSampleMaskIndexedNV (GLuint index, GLbitfield mask); +GLAPI void APIENTRY glTexRenderbufferNV (GLenum target, GLuint renderbuffer); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGETMULTISAMPLEFVNVPROC) (GLenum pname, GLuint index, GLfloat *val); +typedef void (APIENTRYP PFNGLSAMPLEMASKINDEXEDNVPROC) (GLuint index, GLbitfield mask); +typedef void (APIENTRYP PFNGLTEXRENDERBUFFERNVPROC) (GLenum target, GLuint renderbuffer); +#endif + +#ifndef GL_NV_transform_feedback2 +#define GL_NV_transform_feedback2 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBindTransformFeedbackNV (GLenum target, GLuint id); +GLAPI void APIENTRY glDeleteTransformFeedbacksNV (GLsizei n, const GLuint *ids); +GLAPI void APIENTRY glGenTransformFeedbacksNV (GLsizei n, GLuint *ids); +GLAPI GLboolean APIENTRY glIsTransformFeedbackNV (GLuint id); +GLAPI void APIENTRY glPauseTransformFeedbackNV (void); +GLAPI void APIENTRY glResumeTransformFeedbackNV (void); +GLAPI void APIENTRY glDrawTransformFeedbackNV (GLenum mode, GLuint id); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBINDTRANSFORMFEEDBACKNVPROC) (GLenum target, GLuint id); +typedef void (APIENTRYP PFNGLDELETETRANSFORMFEEDBACKSNVPROC) (GLsizei n, const GLuint *ids); +typedef void (APIENTRYP PFNGLGENTRANSFORMFEEDBACKSNVPROC) (GLsizei n, GLuint *ids); +typedef GLboolean (APIENTRYP PFNGLISTRANSFORMFEEDBACKNVPROC) (GLuint id); +typedef void (APIENTRYP PFNGLPAUSETRANSFORMFEEDBACKNVPROC) (void); +typedef void (APIENTRYP PFNGLRESUMETRANSFORMFEEDBACKNVPROC) (void); +typedef void (APIENTRYP PFNGLDRAWTRANSFORMFEEDBACKNVPROC) (GLenum mode, GLuint id); +#endif + +#ifndef GL_ATI_meminfo +#define GL_ATI_meminfo 1 +#endif + +#ifndef GL_AMD_performance_monitor +#define GL_AMD_performance_monitor 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glGetPerfMonitorGroupsAMD (GLint *numGroups, GLsizei groupsSize, GLuint *groups); +GLAPI void APIENTRY glGetPerfMonitorCountersAMD (GLuint group, GLint *numCounters, GLint *maxActiveCounters, GLsizei counterSize, GLuint *counters); +GLAPI void APIENTRY glGetPerfMonitorGroupStringAMD (GLuint group, GLsizei bufSize, GLsizei *length, GLchar *groupString); +GLAPI void APIENTRY glGetPerfMonitorCounterStringAMD (GLuint group, GLuint counter, GLsizei bufSize, GLsizei *length, GLchar *counterString); +GLAPI void APIENTRY glGetPerfMonitorCounterInfoAMD (GLuint group, GLuint counter, GLenum pname, GLvoid *data); +GLAPI void APIENTRY glGenPerfMonitorsAMD (GLsizei n, GLuint *monitors); +GLAPI void APIENTRY glDeletePerfMonitorsAMD (GLsizei n, GLuint *monitors); +GLAPI void APIENTRY glSelectPerfMonitorCountersAMD (GLuint monitor, GLboolean enable, GLuint group, GLint numCounters, GLuint *counterList); +GLAPI void APIENTRY glBeginPerfMonitorAMD (GLuint monitor); +GLAPI void APIENTRY glEndPerfMonitorAMD (GLuint monitor); +GLAPI void APIENTRY glGetPerfMonitorCounterDataAMD (GLuint monitor, GLenum pname, GLsizei dataSize, GLuint *data, GLint *bytesWritten); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGETPERFMONITORGROUPSAMDPROC) (GLint *numGroups, GLsizei groupsSize, GLuint *groups); +typedef void (APIENTRYP PFNGLGETPERFMONITORCOUNTERSAMDPROC) (GLuint group, GLint *numCounters, GLint *maxActiveCounters, GLsizei counterSize, GLuint *counters); +typedef void (APIENTRYP PFNGLGETPERFMONITORGROUPSTRINGAMDPROC) (GLuint group, GLsizei bufSize, GLsizei *length, GLchar *groupString); +typedef void (APIENTRYP PFNGLGETPERFMONITORCOUNTERSTRINGAMDPROC) (GLuint group, GLuint counter, GLsizei bufSize, GLsizei *length, GLchar *counterString); +typedef void (APIENTRYP PFNGLGETPERFMONITORCOUNTERINFOAMDPROC) (GLuint group, GLuint counter, GLenum pname, GLvoid *data); +typedef void (APIENTRYP PFNGLGENPERFMONITORSAMDPROC) (GLsizei n, GLuint *monitors); +typedef void (APIENTRYP PFNGLDELETEPERFMONITORSAMDPROC) (GLsizei n, GLuint *monitors); +typedef void (APIENTRYP PFNGLSELECTPERFMONITORCOUNTERSAMDPROC) (GLuint monitor, GLboolean enable, GLuint group, GLint numCounters, GLuint *counterList); +typedef void (APIENTRYP PFNGLBEGINPERFMONITORAMDPROC) (GLuint monitor); +typedef void (APIENTRYP PFNGLENDPERFMONITORAMDPROC) (GLuint monitor); +typedef void (APIENTRYP PFNGLGETPERFMONITORCOUNTERDATAAMDPROC) (GLuint monitor, GLenum pname, GLsizei dataSize, GLuint *data, GLint *bytesWritten); +#endif + +#ifndef GL_AMD_texture_texture4 +#define GL_AMD_texture_texture4 1 +#endif + +#ifndef GL_AMD_vertex_shader_tesselator +#define GL_AMD_vertex_shader_tesselator 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTessellationFactorAMD (GLfloat factor); +GLAPI void APIENTRY glTessellationModeAMD (GLenum mode); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLTESSELLATIONFACTORAMDPROC) (GLfloat factor); +typedef void (APIENTRYP PFNGLTESSELLATIONMODEAMDPROC) (GLenum mode); +#endif + +#ifndef GL_EXT_provoking_vertex +#define GL_EXT_provoking_vertex 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glProvokingVertexEXT (GLenum mode); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPROVOKINGVERTEXEXTPROC) (GLenum mode); +#endif + +#ifndef GL_EXT_texture_snorm +#define GL_EXT_texture_snorm 1 +#endif + +#ifndef GL_AMD_draw_buffers_blend +#define GL_AMD_draw_buffers_blend 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBlendFuncIndexedAMD (GLuint buf, GLenum src, GLenum dst); +GLAPI void APIENTRY glBlendFuncSeparateIndexedAMD (GLuint buf, GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha); +GLAPI void APIENTRY glBlendEquationIndexedAMD (GLuint buf, GLenum mode); +GLAPI void APIENTRY glBlendEquationSeparateIndexedAMD (GLuint buf, GLenum modeRGB, GLenum modeAlpha); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBLENDFUNCINDEXEDAMDPROC) (GLuint buf, GLenum src, GLenum dst); +typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEINDEXEDAMDPROC) (GLuint buf, GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha); +typedef void (APIENTRYP PFNGLBLENDEQUATIONINDEXEDAMDPROC) (GLuint buf, GLenum mode); +typedef void (APIENTRYP PFNGLBLENDEQUATIONSEPARATEINDEXEDAMDPROC) (GLuint buf, GLenum modeRGB, GLenum modeAlpha); +#endif + +#ifndef GL_APPLE_texture_range +#define GL_APPLE_texture_range 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTextureRangeAPPLE (GLenum target, GLsizei length, const GLvoid *pointer); +GLAPI void APIENTRY glGetTexParameterPointervAPPLE (GLenum target, GLenum pname, GLvoid* *params); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLTEXTURERANGEAPPLEPROC) (GLenum target, GLsizei length, const GLvoid *pointer); +typedef void (APIENTRYP PFNGLGETTEXPARAMETERPOINTERVAPPLEPROC) (GLenum target, GLenum pname, GLvoid* *params); +#endif + +#ifndef GL_APPLE_float_pixels +#define GL_APPLE_float_pixels 1 +#endif + +#ifndef GL_APPLE_vertex_program_evaluators +#define GL_APPLE_vertex_program_evaluators 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glEnableVertexAttribAPPLE (GLuint index, GLenum pname); +GLAPI void APIENTRY glDisableVertexAttribAPPLE (GLuint index, GLenum pname); +GLAPI GLboolean APIENTRY glIsVertexAttribEnabledAPPLE (GLuint index, GLenum pname); +GLAPI void APIENTRY glMapVertexAttrib1dAPPLE (GLuint index, GLuint size, GLdouble u1, GLdouble u2, GLint stride, GLint order, const GLdouble *points); +GLAPI void APIENTRY glMapVertexAttrib1fAPPLE (GLuint index, GLuint size, GLfloat u1, GLfloat u2, GLint stride, GLint order, const GLfloat *points); +GLAPI void APIENTRY glMapVertexAttrib2dAPPLE (GLuint index, GLuint size, GLdouble u1, GLdouble u2, GLint ustride, GLint uorder, GLdouble v1, GLdouble v2, GLint vstride, GLint vorder, const GLdouble *points); +GLAPI void APIENTRY glMapVertexAttrib2fAPPLE (GLuint index, GLuint size, GLfloat u1, GLfloat u2, GLint ustride, GLint uorder, GLfloat v1, GLfloat v2, GLint vstride, GLint vorder, const GLfloat *points); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLENABLEVERTEXATTRIBAPPLEPROC) (GLuint index, GLenum pname); +typedef void (APIENTRYP PFNGLDISABLEVERTEXATTRIBAPPLEPROC) (GLuint index, GLenum pname); +typedef GLboolean (APIENTRYP PFNGLISVERTEXATTRIBENABLEDAPPLEPROC) (GLuint index, GLenum pname); +typedef void (APIENTRYP PFNGLMAPVERTEXATTRIB1DAPPLEPROC) (GLuint index, GLuint size, GLdouble u1, GLdouble u2, GLint stride, GLint order, const GLdouble *points); +typedef void (APIENTRYP PFNGLMAPVERTEXATTRIB1FAPPLEPROC) (GLuint index, GLuint size, GLfloat u1, GLfloat u2, GLint stride, GLint order, const GLfloat *points); +typedef void (APIENTRYP PFNGLMAPVERTEXATTRIB2DAPPLEPROC) (GLuint index, GLuint size, GLdouble u1, GLdouble u2, GLint ustride, GLint uorder, GLdouble v1, GLdouble v2, GLint vstride, GLint vorder, const GLdouble *points); +typedef void (APIENTRYP PFNGLMAPVERTEXATTRIB2FAPPLEPROC) (GLuint index, GLuint size, GLfloat u1, GLfloat u2, GLint ustride, GLint uorder, GLfloat v1, GLfloat v2, GLint vstride, GLint vorder, const GLfloat *points); +#endif + +#ifndef GL_APPLE_aux_depth_stencil +#define GL_APPLE_aux_depth_stencil 1 +#endif + +#ifndef GL_APPLE_object_purgeable +#define GL_APPLE_object_purgeable 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI GLenum APIENTRY glObjectPurgeableAPPLE (GLenum objectType, GLuint name, GLenum option); +GLAPI GLenum APIENTRY glObjectUnpurgeableAPPLE (GLenum objectType, GLuint name, GLenum option); +GLAPI void APIENTRY glGetObjectParameterivAPPLE (GLenum objectType, GLuint name, GLenum pname, GLint *params); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef GLenum (APIENTRYP PFNGLOBJECTPURGEABLEAPPLEPROC) (GLenum objectType, GLuint name, GLenum option); +typedef GLenum (APIENTRYP PFNGLOBJECTUNPURGEABLEAPPLEPROC) (GLenum objectType, GLuint name, GLenum option); +typedef void (APIENTRYP PFNGLGETOBJECTPARAMETERIVAPPLEPROC) (GLenum objectType, GLuint name, GLenum pname, GLint *params); +#endif + +#ifndef GL_APPLE_row_bytes +#define GL_APPLE_row_bytes 1 +#endif + +#ifndef GL_APPLE_rgb_422 +#define GL_APPLE_rgb_422 1 +#endif + +#ifndef GL_NV_video_capture +#define GL_NV_video_capture 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBeginVideoCaptureNV (GLuint video_capture_slot); +GLAPI void APIENTRY glBindVideoCaptureStreamBufferNV (GLuint video_capture_slot, GLuint stream, GLenum frame_region, GLintptrARB offset); +GLAPI void APIENTRY glBindVideoCaptureStreamTextureNV (GLuint video_capture_slot, GLuint stream, GLenum frame_region, GLenum target, GLuint texture); +GLAPI void APIENTRY glEndVideoCaptureNV (GLuint video_capture_slot); +GLAPI void APIENTRY glGetVideoCaptureivNV (GLuint video_capture_slot, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetVideoCaptureStreamivNV (GLuint video_capture_slot, GLuint stream, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetVideoCaptureStreamfvNV (GLuint video_capture_slot, GLuint stream, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetVideoCaptureStreamdvNV (GLuint video_capture_slot, GLuint stream, GLenum pname, GLdouble *params); +GLAPI GLenum APIENTRY glVideoCaptureNV (GLuint video_capture_slot, GLuint *sequence_num, GLuint64EXT *capture_time); +GLAPI void APIENTRY glVideoCaptureStreamParameterivNV (GLuint video_capture_slot, GLuint stream, GLenum pname, const GLint *params); +GLAPI void APIENTRY glVideoCaptureStreamParameterfvNV (GLuint video_capture_slot, GLuint stream, GLenum pname, const GLfloat *params); +GLAPI void APIENTRY glVideoCaptureStreamParameterdvNV (GLuint video_capture_slot, GLuint stream, GLenum pname, const GLdouble *params); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBEGINVIDEOCAPTURENVPROC) (GLuint video_capture_slot); +typedef void (APIENTRYP PFNGLBINDVIDEOCAPTURESTREAMBUFFERNVPROC) (GLuint video_capture_slot, GLuint stream, GLenum frame_region, GLintptrARB offset); +typedef void (APIENTRYP PFNGLBINDVIDEOCAPTURESTREAMTEXTURENVPROC) (GLuint video_capture_slot, GLuint stream, GLenum frame_region, GLenum target, GLuint texture); +typedef void (APIENTRYP PFNGLENDVIDEOCAPTURENVPROC) (GLuint video_capture_slot); +typedef void (APIENTRYP PFNGLGETVIDEOCAPTUREIVNVPROC) (GLuint video_capture_slot, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETVIDEOCAPTURESTREAMIVNVPROC) (GLuint video_capture_slot, GLuint stream, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETVIDEOCAPTURESTREAMFVNVPROC) (GLuint video_capture_slot, GLuint stream, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETVIDEOCAPTURESTREAMDVNVPROC) (GLuint video_capture_slot, GLuint stream, GLenum pname, GLdouble *params); +typedef GLenum (APIENTRYP PFNGLVIDEOCAPTURENVPROC) (GLuint video_capture_slot, GLuint *sequence_num, GLuint64EXT *capture_time); +typedef void (APIENTRYP PFNGLVIDEOCAPTURESTREAMPARAMETERIVNVPROC) (GLuint video_capture_slot, GLuint stream, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLVIDEOCAPTURESTREAMPARAMETERFVNVPROC) (GLuint video_capture_slot, GLuint stream, GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLVIDEOCAPTURESTREAMPARAMETERDVNVPROC) (GLuint video_capture_slot, GLuint stream, GLenum pname, const GLdouble *params); +#endif + +#ifndef GL_NV_copy_image +#define GL_NV_copy_image 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glCopyImageSubDataNV (GLuint srcName, GLenum srcTarget, GLint srcLevel, GLint srcX, GLint srcY, GLint srcZ, GLuint dstName, GLenum dstTarget, GLint dstLevel, GLint dstX, GLint dstY, GLint dstZ, GLsizei width, GLsizei height, GLsizei depth); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCOPYIMAGESUBDATANVPROC) (GLuint srcName, GLenum srcTarget, GLint srcLevel, GLint srcX, GLint srcY, GLint srcZ, GLuint dstName, GLenum dstTarget, GLint dstLevel, GLint dstX, GLint dstY, GLint dstZ, GLsizei width, GLsizei height, GLsizei depth); +#endif + +#ifndef GL_EXT_separate_shader_objects +#define GL_EXT_separate_shader_objects 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glUseShaderProgramEXT (GLenum type, GLuint program); +GLAPI void APIENTRY glActiveProgramEXT (GLuint program); +GLAPI GLuint APIENTRY glCreateShaderProgramEXT (GLenum type, const GLchar *string); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLUSESHADERPROGRAMEXTPROC) (GLenum type, GLuint program); +typedef void (APIENTRYP PFNGLACTIVEPROGRAMEXTPROC) (GLuint program); +typedef GLuint (APIENTRYP PFNGLCREATESHADERPROGRAMEXTPROC) (GLenum type, const GLchar *string); +#endif + +#ifndef GL_NV_parameter_buffer_object2 +#define GL_NV_parameter_buffer_object2 1 +#endif + +#ifndef GL_NV_shader_buffer_load +#define GL_NV_shader_buffer_load 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glMakeBufferResidentNV (GLenum target, GLenum access); +GLAPI void APIENTRY glMakeBufferNonResidentNV (GLenum target); +GLAPI GLboolean APIENTRY glIsBufferResidentNV (GLenum target); +GLAPI void APIENTRY glMakeNamedBufferResidentNV (GLuint buffer, GLenum access); +GLAPI void APIENTRY glMakeNamedBufferNonResidentNV (GLuint buffer); +GLAPI GLboolean APIENTRY glIsNamedBufferResidentNV (GLuint buffer); +GLAPI void APIENTRY glGetBufferParameterui64vNV (GLenum target, GLenum pname, GLuint64EXT *params); +GLAPI void APIENTRY glGetNamedBufferParameterui64vNV (GLuint buffer, GLenum pname, GLuint64EXT *params); +GLAPI void APIENTRY glGetIntegerui64vNV (GLenum value, GLuint64EXT *result); +GLAPI void APIENTRY glUniformui64NV (GLint location, GLuint64EXT value); +GLAPI void APIENTRY glUniformui64vNV (GLint location, GLsizei count, const GLuint64EXT *value); +GLAPI void APIENTRY glGetUniformui64vNV (GLuint program, GLint location, GLuint64EXT *params); +GLAPI void APIENTRY glProgramUniformui64NV (GLuint program, GLint location, GLuint64EXT value); +GLAPI void APIENTRY glProgramUniformui64vNV (GLuint program, GLint location, GLsizei count, const GLuint64EXT *value); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLMAKEBUFFERRESIDENTNVPROC) (GLenum target, GLenum access); +typedef void (APIENTRYP PFNGLMAKEBUFFERNONRESIDENTNVPROC) (GLenum target); +typedef GLboolean (APIENTRYP PFNGLISBUFFERRESIDENTNVPROC) (GLenum target); +typedef void (APIENTRYP PFNGLMAKENAMEDBUFFERRESIDENTNVPROC) (GLuint buffer, GLenum access); +typedef void (APIENTRYP PFNGLMAKENAMEDBUFFERNONRESIDENTNVPROC) (GLuint buffer); +typedef GLboolean (APIENTRYP PFNGLISNAMEDBUFFERRESIDENTNVPROC) (GLuint buffer); +typedef void (APIENTRYP PFNGLGETBUFFERPARAMETERUI64VNVPROC) (GLenum target, GLenum pname, GLuint64EXT *params); +typedef void (APIENTRYP PFNGLGETNAMEDBUFFERPARAMETERUI64VNVPROC) (GLuint buffer, GLenum pname, GLuint64EXT *params); +typedef void (APIENTRYP PFNGLGETINTEGERUI64VNVPROC) (GLenum value, GLuint64EXT *result); +typedef void (APIENTRYP PFNGLUNIFORMUI64NVPROC) (GLint location, GLuint64EXT value); +typedef void (APIENTRYP PFNGLUNIFORMUI64VNVPROC) (GLint location, GLsizei count, const GLuint64EXT *value); +typedef void (APIENTRYP PFNGLGETUNIFORMUI64VNVPROC) (GLuint program, GLint location, GLuint64EXT *params); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMUI64NVPROC) (GLuint program, GLint location, GLuint64EXT value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMUI64VNVPROC) (GLuint program, GLint location, GLsizei count, const GLuint64EXT *value); +#endif + +#ifndef GL_NV_vertex_buffer_unified_memory +#define GL_NV_vertex_buffer_unified_memory 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBufferAddressRangeNV (GLenum pname, GLuint index, GLuint64EXT address, GLsizeiptr length); +GLAPI void APIENTRY glVertexFormatNV (GLint size, GLenum type, GLsizei stride); +GLAPI void APIENTRY glNormalFormatNV (GLenum type, GLsizei stride); +GLAPI void APIENTRY glColorFormatNV (GLint size, GLenum type, GLsizei stride); +GLAPI void APIENTRY glIndexFormatNV (GLenum type, GLsizei stride); +GLAPI void APIENTRY glTexCoordFormatNV (GLint size, GLenum type, GLsizei stride); +GLAPI void APIENTRY glEdgeFlagFormatNV (GLsizei stride); +GLAPI void APIENTRY glSecondaryColorFormatNV (GLint size, GLenum type, GLsizei stride); +GLAPI void APIENTRY glFogCoordFormatNV (GLenum type, GLsizei stride); +GLAPI void APIENTRY glVertexAttribFormatNV (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride); +GLAPI void APIENTRY glVertexAttribIFormatNV (GLuint index, GLint size, GLenum type, GLsizei stride); +GLAPI void APIENTRY glGetIntegerui64i_vNV (GLenum value, GLuint index, GLuint64EXT *result); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBUFFERADDRESSRANGENVPROC) (GLenum pname, GLuint index, GLuint64EXT address, GLsizeiptr length); +typedef void (APIENTRYP PFNGLVERTEXFORMATNVPROC) (GLint size, GLenum type, GLsizei stride); +typedef void (APIENTRYP PFNGLNORMALFORMATNVPROC) (GLenum type, GLsizei stride); +typedef void (APIENTRYP PFNGLCOLORFORMATNVPROC) (GLint size, GLenum type, GLsizei stride); +typedef void (APIENTRYP PFNGLINDEXFORMATNVPROC) (GLenum type, GLsizei stride); +typedef void (APIENTRYP PFNGLTEXCOORDFORMATNVPROC) (GLint size, GLenum type, GLsizei stride); +typedef void (APIENTRYP PFNGLEDGEFLAGFORMATNVPROC) (GLsizei stride); +typedef void (APIENTRYP PFNGLSECONDARYCOLORFORMATNVPROC) (GLint size, GLenum type, GLsizei stride); +typedef void (APIENTRYP PFNGLFOGCOORDFORMATNVPROC) (GLenum type, GLsizei stride); +typedef void (APIENTRYP PFNGLVERTEXATTRIBFORMATNVPROC) (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride); +typedef void (APIENTRYP PFNGLVERTEXATTRIBIFORMATNVPROC) (GLuint index, GLint size, GLenum type, GLsizei stride); +typedef void (APIENTRYP PFNGLGETINTEGERUI64I_VNVPROC) (GLenum value, GLuint index, GLuint64EXT *result); +#endif + +#ifndef GL_NV_texture_barrier +#define GL_NV_texture_barrier 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTextureBarrierNV (void); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLTEXTUREBARRIERNVPROC) (void); +#endif + +#ifndef GL_AMD_shader_stencil_export +#define GL_AMD_shader_stencil_export 1 +#endif + +#ifndef GL_AMD_seamless_cubemap_per_texture +#define GL_AMD_seamless_cubemap_per_texture 1 +#endif + +#ifndef GL_AMD_conservative_depth +#define GL_AMD_conservative_depth 1 +#endif + +#ifndef GL_EXT_shader_image_load_store +#define GL_EXT_shader_image_load_store 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBindImageTextureEXT (GLuint index, GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum access, GLint format); +GLAPI void APIENTRY glMemoryBarrierEXT (GLbitfield barriers); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBINDIMAGETEXTUREEXTPROC) (GLuint index, GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum access, GLint format); +typedef void (APIENTRYP PFNGLMEMORYBARRIEREXTPROC) (GLbitfield barriers); +#endif + +#ifndef GL_EXT_vertex_attrib_64bit +#define GL_EXT_vertex_attrib_64bit 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glVertexAttribL1dEXT (GLuint index, GLdouble x); +GLAPI void APIENTRY glVertexAttribL2dEXT (GLuint index, GLdouble x, GLdouble y); +GLAPI void APIENTRY glVertexAttribL3dEXT (GLuint index, GLdouble x, GLdouble y, GLdouble z); +GLAPI void APIENTRY glVertexAttribL4dEXT (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +GLAPI void APIENTRY glVertexAttribL1dvEXT (GLuint index, const GLdouble *v); +GLAPI void APIENTRY glVertexAttribL2dvEXT (GLuint index, const GLdouble *v); +GLAPI void APIENTRY glVertexAttribL3dvEXT (GLuint index, const GLdouble *v); +GLAPI void APIENTRY glVertexAttribL4dvEXT (GLuint index, const GLdouble *v); +GLAPI void APIENTRY glVertexAttribLPointerEXT (GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +GLAPI void APIENTRY glGetVertexAttribLdvEXT (GLuint index, GLenum pname, GLdouble *params); +GLAPI void APIENTRY glVertexArrayVertexAttribLOffsetEXT (GLuint vaobj, GLuint buffer, GLuint index, GLint size, GLenum type, GLsizei stride, GLintptr offset); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLVERTEXATTRIBL1DEXTPROC) (GLuint index, GLdouble x); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL2DEXTPROC) (GLuint index, GLdouble x, GLdouble y); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL3DEXTPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL4DEXTPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL1DVEXTPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL2DVEXTPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL3DVEXTPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL4DVEXTPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBLPOINTEREXTPROC) (GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBLDVEXTPROC) (GLuint index, GLenum pname, GLdouble *params); +typedef void (APIENTRYP PFNGLVERTEXARRAYVERTEXATTRIBLOFFSETEXTPROC) (GLuint vaobj, GLuint buffer, GLuint index, GLint size, GLenum type, GLsizei stride, GLintptr offset); +#endif + +#ifndef GL_NV_gpu_program5 +#define GL_NV_gpu_program5 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glProgramSubroutineParametersuivNV (GLenum target, GLsizei count, const GLuint *params); +GLAPI void APIENTRY glGetProgramSubroutineParameteruivNV (GLenum target, GLuint index, GLuint *param); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPROGRAMSUBROUTINEPARAMETERSUIVNVPROC) (GLenum target, GLsizei count, const GLuint *params); +typedef void (APIENTRYP PFNGLGETPROGRAMSUBROUTINEPARAMETERUIVNVPROC) (GLenum target, GLuint index, GLuint *param); +#endif + +#ifndef GL_NV_gpu_shader5 +#define GL_NV_gpu_shader5 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glUniform1i64NV (GLint location, GLint64EXT x); +GLAPI void APIENTRY glUniform2i64NV (GLint location, GLint64EXT x, GLint64EXT y); +GLAPI void APIENTRY glUniform3i64NV (GLint location, GLint64EXT x, GLint64EXT y, GLint64EXT z); +GLAPI void APIENTRY glUniform4i64NV (GLint location, GLint64EXT x, GLint64EXT y, GLint64EXT z, GLint64EXT w); +GLAPI void APIENTRY glUniform1i64vNV (GLint location, GLsizei count, const GLint64EXT *value); +GLAPI void APIENTRY glUniform2i64vNV (GLint location, GLsizei count, const GLint64EXT *value); +GLAPI void APIENTRY glUniform3i64vNV (GLint location, GLsizei count, const GLint64EXT *value); +GLAPI void APIENTRY glUniform4i64vNV (GLint location, GLsizei count, const GLint64EXT *value); +GLAPI void APIENTRY glUniform1ui64NV (GLint location, GLuint64EXT x); +GLAPI void APIENTRY glUniform2ui64NV (GLint location, GLuint64EXT x, GLuint64EXT y); +GLAPI void APIENTRY glUniform3ui64NV (GLint location, GLuint64EXT x, GLuint64EXT y, GLuint64EXT z); +GLAPI void APIENTRY glUniform4ui64NV (GLint location, GLuint64EXT x, GLuint64EXT y, GLuint64EXT z, GLuint64EXT w); +GLAPI void APIENTRY glUniform1ui64vNV (GLint location, GLsizei count, const GLuint64EXT *value); +GLAPI void APIENTRY glUniform2ui64vNV (GLint location, GLsizei count, const GLuint64EXT *value); +GLAPI void APIENTRY glUniform3ui64vNV (GLint location, GLsizei count, const GLuint64EXT *value); +GLAPI void APIENTRY glUniform4ui64vNV (GLint location, GLsizei count, const GLuint64EXT *value); +GLAPI void APIENTRY glGetUniformi64vNV (GLuint program, GLint location, GLint64EXT *params); +GLAPI void APIENTRY glProgramUniform1i64NV (GLuint program, GLint location, GLint64EXT x); +GLAPI void APIENTRY glProgramUniform2i64NV (GLuint program, GLint location, GLint64EXT x, GLint64EXT y); +GLAPI void APIENTRY glProgramUniform3i64NV (GLuint program, GLint location, GLint64EXT x, GLint64EXT y, GLint64EXT z); +GLAPI void APIENTRY glProgramUniform4i64NV (GLuint program, GLint location, GLint64EXT x, GLint64EXT y, GLint64EXT z, GLint64EXT w); +GLAPI void APIENTRY glProgramUniform1i64vNV (GLuint program, GLint location, GLsizei count, const GLint64EXT *value); +GLAPI void APIENTRY glProgramUniform2i64vNV (GLuint program, GLint location, GLsizei count, const GLint64EXT *value); +GLAPI void APIENTRY glProgramUniform3i64vNV (GLuint program, GLint location, GLsizei count, const GLint64EXT *value); +GLAPI void APIENTRY glProgramUniform4i64vNV (GLuint program, GLint location, GLsizei count, const GLint64EXT *value); +GLAPI void APIENTRY glProgramUniform1ui64NV (GLuint program, GLint location, GLuint64EXT x); +GLAPI void APIENTRY glProgramUniform2ui64NV (GLuint program, GLint location, GLuint64EXT x, GLuint64EXT y); +GLAPI void APIENTRY glProgramUniform3ui64NV (GLuint program, GLint location, GLuint64EXT x, GLuint64EXT y, GLuint64EXT z); +GLAPI void APIENTRY glProgramUniform4ui64NV (GLuint program, GLint location, GLuint64EXT x, GLuint64EXT y, GLuint64EXT z, GLuint64EXT w); +GLAPI void APIENTRY glProgramUniform1ui64vNV (GLuint program, GLint location, GLsizei count, const GLuint64EXT *value); +GLAPI void APIENTRY glProgramUniform2ui64vNV (GLuint program, GLint location, GLsizei count, const GLuint64EXT *value); +GLAPI void APIENTRY glProgramUniform3ui64vNV (GLuint program, GLint location, GLsizei count, const GLuint64EXT *value); +GLAPI void APIENTRY glProgramUniform4ui64vNV (GLuint program, GLint location, GLsizei count, const GLuint64EXT *value); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLUNIFORM1I64NVPROC) (GLint location, GLint64EXT x); +typedef void (APIENTRYP PFNGLUNIFORM2I64NVPROC) (GLint location, GLint64EXT x, GLint64EXT y); +typedef void (APIENTRYP PFNGLUNIFORM3I64NVPROC) (GLint location, GLint64EXT x, GLint64EXT y, GLint64EXT z); +typedef void (APIENTRYP PFNGLUNIFORM4I64NVPROC) (GLint location, GLint64EXT x, GLint64EXT y, GLint64EXT z, GLint64EXT w); +typedef void (APIENTRYP PFNGLUNIFORM1I64VNVPROC) (GLint location, GLsizei count, const GLint64EXT *value); +typedef void (APIENTRYP PFNGLUNIFORM2I64VNVPROC) (GLint location, GLsizei count, const GLint64EXT *value); +typedef void (APIENTRYP PFNGLUNIFORM3I64VNVPROC) (GLint location, GLsizei count, const GLint64EXT *value); +typedef void (APIENTRYP PFNGLUNIFORM4I64VNVPROC) (GLint location, GLsizei count, const GLint64EXT *value); +typedef void (APIENTRYP PFNGLUNIFORM1UI64NVPROC) (GLint location, GLuint64EXT x); +typedef void (APIENTRYP PFNGLUNIFORM2UI64NVPROC) (GLint location, GLuint64EXT x, GLuint64EXT y); +typedef void (APIENTRYP PFNGLUNIFORM3UI64NVPROC) (GLint location, GLuint64EXT x, GLuint64EXT y, GLuint64EXT z); +typedef void (APIENTRYP PFNGLUNIFORM4UI64NVPROC) (GLint location, GLuint64EXT x, GLuint64EXT y, GLuint64EXT z, GLuint64EXT w); +typedef void (APIENTRYP PFNGLUNIFORM1UI64VNVPROC) (GLint location, GLsizei count, const GLuint64EXT *value); +typedef void (APIENTRYP PFNGLUNIFORM2UI64VNVPROC) (GLint location, GLsizei count, const GLuint64EXT *value); +typedef void (APIENTRYP PFNGLUNIFORM3UI64VNVPROC) (GLint location, GLsizei count, const GLuint64EXT *value); +typedef void (APIENTRYP PFNGLUNIFORM4UI64VNVPROC) (GLint location, GLsizei count, const GLuint64EXT *value); +typedef void (APIENTRYP PFNGLGETUNIFORMI64VNVPROC) (GLuint program, GLint location, GLint64EXT *params); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1I64NVPROC) (GLuint program, GLint location, GLint64EXT x); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2I64NVPROC) (GLuint program, GLint location, GLint64EXT x, GLint64EXT y); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3I64NVPROC) (GLuint program, GLint location, GLint64EXT x, GLint64EXT y, GLint64EXT z); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4I64NVPROC) (GLuint program, GLint location, GLint64EXT x, GLint64EXT y, GLint64EXT z, GLint64EXT w); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1I64VNVPROC) (GLuint program, GLint location, GLsizei count, const GLint64EXT *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2I64VNVPROC) (GLuint program, GLint location, GLsizei count, const GLint64EXT *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3I64VNVPROC) (GLuint program, GLint location, GLsizei count, const GLint64EXT *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4I64VNVPROC) (GLuint program, GLint location, GLsizei count, const GLint64EXT *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1UI64NVPROC) (GLuint program, GLint location, GLuint64EXT x); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2UI64NVPROC) (GLuint program, GLint location, GLuint64EXT x, GLuint64EXT y); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3UI64NVPROC) (GLuint program, GLint location, GLuint64EXT x, GLuint64EXT y, GLuint64EXT z); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4UI64NVPROC) (GLuint program, GLint location, GLuint64EXT x, GLuint64EXT y, GLuint64EXT z, GLuint64EXT w); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1UI64VNVPROC) (GLuint program, GLint location, GLsizei count, const GLuint64EXT *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2UI64VNVPROC) (GLuint program, GLint location, GLsizei count, const GLuint64EXT *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3UI64VNVPROC) (GLuint program, GLint location, GLsizei count, const GLuint64EXT *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4UI64VNVPROC) (GLuint program, GLint location, GLsizei count, const GLuint64EXT *value); +#endif + +#ifndef GL_NV_shader_buffer_store +#define GL_NV_shader_buffer_store 1 +#endif + +#ifndef GL_NV_tessellation_program5 +#define GL_NV_tessellation_program5 1 +#endif + +#ifndef GL_NV_vertex_attrib_integer_64bit +#define GL_NV_vertex_attrib_integer_64bit 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glVertexAttribL1i64NV (GLuint index, GLint64EXT x); +GLAPI void APIENTRY glVertexAttribL2i64NV (GLuint index, GLint64EXT x, GLint64EXT y); +GLAPI void APIENTRY glVertexAttribL3i64NV (GLuint index, GLint64EXT x, GLint64EXT y, GLint64EXT z); +GLAPI void APIENTRY glVertexAttribL4i64NV (GLuint index, GLint64EXT x, GLint64EXT y, GLint64EXT z, GLint64EXT w); +GLAPI void APIENTRY glVertexAttribL1i64vNV (GLuint index, const GLint64EXT *v); +GLAPI void APIENTRY glVertexAttribL2i64vNV (GLuint index, const GLint64EXT *v); +GLAPI void APIENTRY glVertexAttribL3i64vNV (GLuint index, const GLint64EXT *v); +GLAPI void APIENTRY glVertexAttribL4i64vNV (GLuint index, const GLint64EXT *v); +GLAPI void APIENTRY glVertexAttribL1ui64NV (GLuint index, GLuint64EXT x); +GLAPI void APIENTRY glVertexAttribL2ui64NV (GLuint index, GLuint64EXT x, GLuint64EXT y); +GLAPI void APIENTRY glVertexAttribL3ui64NV (GLuint index, GLuint64EXT x, GLuint64EXT y, GLuint64EXT z); +GLAPI void APIENTRY glVertexAttribL4ui64NV (GLuint index, GLuint64EXT x, GLuint64EXT y, GLuint64EXT z, GLuint64EXT w); +GLAPI void APIENTRY glVertexAttribL1ui64vNV (GLuint index, const GLuint64EXT *v); +GLAPI void APIENTRY glVertexAttribL2ui64vNV (GLuint index, const GLuint64EXT *v); +GLAPI void APIENTRY glVertexAttribL3ui64vNV (GLuint index, const GLuint64EXT *v); +GLAPI void APIENTRY glVertexAttribL4ui64vNV (GLuint index, const GLuint64EXT *v); +GLAPI void APIENTRY glGetVertexAttribLi64vNV (GLuint index, GLenum pname, GLint64EXT *params); +GLAPI void APIENTRY glGetVertexAttribLui64vNV (GLuint index, GLenum pname, GLuint64EXT *params); +GLAPI void APIENTRY glVertexAttribLFormatNV (GLuint index, GLint size, GLenum type, GLsizei stride); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLVERTEXATTRIBL1I64NVPROC) (GLuint index, GLint64EXT x); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL2I64NVPROC) (GLuint index, GLint64EXT x, GLint64EXT y); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL3I64NVPROC) (GLuint index, GLint64EXT x, GLint64EXT y, GLint64EXT z); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL4I64NVPROC) (GLuint index, GLint64EXT x, GLint64EXT y, GLint64EXT z, GLint64EXT w); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL1I64VNVPROC) (GLuint index, const GLint64EXT *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL2I64VNVPROC) (GLuint index, const GLint64EXT *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL3I64VNVPROC) (GLuint index, const GLint64EXT *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL4I64VNVPROC) (GLuint index, const GLint64EXT *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL1UI64NVPROC) (GLuint index, GLuint64EXT x); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL2UI64NVPROC) (GLuint index, GLuint64EXT x, GLuint64EXT y); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL3UI64NVPROC) (GLuint index, GLuint64EXT x, GLuint64EXT y, GLuint64EXT z); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL4UI64NVPROC) (GLuint index, GLuint64EXT x, GLuint64EXT y, GLuint64EXT z, GLuint64EXT w); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL1UI64VNVPROC) (GLuint index, const GLuint64EXT *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL2UI64VNVPROC) (GLuint index, const GLuint64EXT *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL3UI64VNVPROC) (GLuint index, const GLuint64EXT *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL4UI64VNVPROC) (GLuint index, const GLuint64EXT *v); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBLI64VNVPROC) (GLuint index, GLenum pname, GLint64EXT *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBLUI64VNVPROC) (GLuint index, GLenum pname, GLuint64EXT *params); +typedef void (APIENTRYP PFNGLVERTEXATTRIBLFORMATNVPROC) (GLuint index, GLint size, GLenum type, GLsizei stride); +#endif + +#ifndef GL_NV_multisample_coverage +#define GL_NV_multisample_coverage 1 +#endif + +#ifndef GL_AMD_name_gen_delete +#define GL_AMD_name_gen_delete 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glGenNamesAMD (GLenum identifier, GLuint num, GLuint *names); +GLAPI void APIENTRY glDeleteNamesAMD (GLenum identifier, GLuint num, const GLuint *names); +GLAPI GLboolean APIENTRY glIsNameAMD (GLenum identifier, GLuint name); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGENNAMESAMDPROC) (GLenum identifier, GLuint num, GLuint *names); +typedef void (APIENTRYP PFNGLDELETENAMESAMDPROC) (GLenum identifier, GLuint num, const GLuint *names); +typedef GLboolean (APIENTRYP PFNGLISNAMEAMDPROC) (GLenum identifier, GLuint name); +#endif + +#ifndef GL_AMD_debug_output +#define GL_AMD_debug_output 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDebugMessageEnableAMD (GLenum category, GLenum severity, GLsizei count, const GLuint *ids, GLboolean enabled); +GLAPI void APIENTRY glDebugMessageInsertAMD (GLenum category, GLenum severity, GLuint id, GLsizei length, const GLchar *buf); +GLAPI void APIENTRY glDebugMessageCallbackAMD (GLDEBUGPROCAMD callback, GLvoid *userParam); +GLAPI GLuint APIENTRY glGetDebugMessageLogAMD (GLuint count, GLsizei bufsize, GLenum *categories, GLuint *severities, GLuint *ids, GLsizei *lengths, GLchar *message); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDEBUGMESSAGEENABLEAMDPROC) (GLenum category, GLenum severity, GLsizei count, const GLuint *ids, GLboolean enabled); +typedef void (APIENTRYP PFNGLDEBUGMESSAGEINSERTAMDPROC) (GLenum category, GLenum severity, GLuint id, GLsizei length, const GLchar *buf); +typedef void (APIENTRYP PFNGLDEBUGMESSAGECALLBACKAMDPROC) (GLDEBUGPROCAMD callback, GLvoid *userParam); +typedef GLuint (APIENTRYP PFNGLGETDEBUGMESSAGELOGAMDPROC) (GLuint count, GLsizei bufsize, GLenum *categories, GLuint *severities, GLuint *ids, GLsizei *lengths, GLchar *message); +#endif + +#ifndef GL_NV_vdpau_interop +#define GL_NV_vdpau_interop 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glVDPAUInitNV (const GLvoid *vdpDevice, const GLvoid *getProcAddress); +GLAPI void APIENTRY glVDPAUFiniNV (void); +GLAPI GLvdpauSurfaceNV APIENTRY glVDPAURegisterVideoSurfaceNV (GLvoid *vdpSurface, GLenum target, GLsizei numTextureNames, const GLuint *textureNames); +GLAPI GLvdpauSurfaceNV APIENTRY glVDPAURegisterOutputSurfaceNV (GLvoid *vdpSurface, GLenum target, GLsizei numTextureNames, const GLuint *textureNames); +GLAPI void APIENTRY glVDPAUIsSurfaceNV (GLvdpauSurfaceNV surface); +GLAPI void APIENTRY glVDPAUUnregisterSurfaceNV (GLvdpauSurfaceNV surface); +GLAPI void APIENTRY glVDPAUGetSurfaceivNV (GLvdpauSurfaceNV surface, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values); +GLAPI void APIENTRY glVDPAUSurfaceAccessNV (GLvdpauSurfaceNV surface, GLenum access); +GLAPI void APIENTRY glVDPAUMapSurfacesNV (GLsizei numSurfaces, const GLvdpauSurfaceNV *surfaces); +GLAPI void APIENTRY glVDPAUUnmapSurfacesNV (GLsizei numSurface, const GLvdpauSurfaceNV *surfaces); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLVDPAUINITNVPROC) (const GLvoid *vdpDevice, const GLvoid *getProcAddress); +typedef void (APIENTRYP PFNGLVDPAUFININVPROC) (void); +typedef GLvdpauSurfaceNV (APIENTRYP PFNGLVDPAUREGISTERVIDEOSURFACENVPROC) (GLvoid *vdpSurface, GLenum target, GLsizei numTextureNames, const GLuint *textureNames); +typedef GLvdpauSurfaceNV (APIENTRYP PFNGLVDPAUREGISTEROUTPUTSURFACENVPROC) (GLvoid *vdpSurface, GLenum target, GLsizei numTextureNames, const GLuint *textureNames); +typedef void (APIENTRYP PFNGLVDPAUISSURFACENVPROC) (GLvdpauSurfaceNV surface); +typedef void (APIENTRYP PFNGLVDPAUUNREGISTERSURFACENVPROC) (GLvdpauSurfaceNV surface); +typedef void (APIENTRYP PFNGLVDPAUGETSURFACEIVNVPROC) (GLvdpauSurfaceNV surface, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values); +typedef void (APIENTRYP PFNGLVDPAUSURFACEACCESSNVPROC) (GLvdpauSurfaceNV surface, GLenum access); +typedef void (APIENTRYP PFNGLVDPAUMAPSURFACESNVPROC) (GLsizei numSurfaces, const GLvdpauSurfaceNV *surfaces); +typedef void (APIENTRYP PFNGLVDPAUUNMAPSURFACESNVPROC) (GLsizei numSurface, const GLvdpauSurfaceNV *surfaces); +#endif + +#ifndef GL_AMD_transform_feedback3_lines_triangles +#define GL_AMD_transform_feedback3_lines_triangles 1 +#endif + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/Projects/Android/jni/SupportLibs/gl4es/include/GL/glu.h b/Projects/Android/jni/SupportLibs/gl4es/include/GL/glu.h new file mode 100644 index 0000000..ba2228d --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/include/GL/glu.h @@ -0,0 +1,353 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF + * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * Except as contained in this notice, the name of Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ + +#ifndef __glu_h__ +#define __glu_h__ + +#if defined(USE_MGL_NAMESPACE) +#include "glu_mangle.h" +#endif + +#include + +#ifndef GLAPIENTRY +#if defined(_MSC_VER) || defined(__MINGW32__) +#define GLAPIENTRY __stdcall +#else +#define GLAPIENTRY +#endif +#endif + +#ifndef GLAPIENTRYP +#define GLAPIENTRYP GLAPIENTRY * +#endif + +#if (defined(_MSC_VER) || defined(__MINGW32__)) && defined(BUILD_GLU32) +# undef GLAPI +# define GLAPI __declspec(dllexport) +#elif (defined(_MSC_VER) || defined(__MINGW32__)) && defined(_DLL) +/* tag specifying we're building for DLL runtime support */ +# undef GLAPI +# define GLAPI __declspec(dllimport) +#elif !defined(GLAPI) +/* for use with static link lib build of Win32 edition only */ +# define GLAPI extern +#endif /* _STATIC_MESA support */ + +#ifdef __cplusplus +extern "C" { +#endif + +/*************************************************************/ + +/* Extensions */ +#define GLU_EXT_object_space_tess 1 +#define GLU_EXT_nurbs_tessellator 1 + +/* Boolean */ +#define GLU_FALSE 0 +#define GLU_TRUE 1 + +/* Version */ +#define GLU_VERSION_1_1 1 +#define GLU_VERSION_1_2 1 +#define GLU_VERSION_1_3 1 + +/* StringName */ +#define GLU_VERSION 100800 +#define GLU_EXTENSIONS 100801 + +/* ErrorCode */ +#define GLU_INVALID_ENUM 100900 +#define GLU_INVALID_VALUE 100901 +#define GLU_OUT_OF_MEMORY 100902 +#define GLU_INCOMPATIBLE_GL_VERSION 100903 +#define GLU_INVALID_OPERATION 100904 + +/* NurbsDisplay */ +/* GLU_FILL */ +#define GLU_OUTLINE_POLYGON 100240 +#define GLU_OUTLINE_PATCH 100241 + +/* NurbsCallback */ +#define GLU_NURBS_ERROR 100103 +#define GLU_ERROR 100103 +#define GLU_NURBS_BEGIN 100164 +#define GLU_NURBS_BEGIN_EXT 100164 +#define GLU_NURBS_VERTEX 100165 +#define GLU_NURBS_VERTEX_EXT 100165 +#define GLU_NURBS_NORMAL 100166 +#define GLU_NURBS_NORMAL_EXT 100166 +#define GLU_NURBS_COLOR 100167 +#define GLU_NURBS_COLOR_EXT 100167 +#define GLU_NURBS_TEXTURE_COORD 100168 +#define GLU_NURBS_TEX_COORD_EXT 100168 +#define GLU_NURBS_END 100169 +#define GLU_NURBS_END_EXT 100169 +#define GLU_NURBS_BEGIN_DATA 100170 +#define GLU_NURBS_BEGIN_DATA_EXT 100170 +#define GLU_NURBS_VERTEX_DATA 100171 +#define GLU_NURBS_VERTEX_DATA_EXT 100171 +#define GLU_NURBS_NORMAL_DATA 100172 +#define GLU_NURBS_NORMAL_DATA_EXT 100172 +#define GLU_NURBS_COLOR_DATA 100173 +#define GLU_NURBS_COLOR_DATA_EXT 100173 +#define GLU_NURBS_TEXTURE_COORD_DATA 100174 +#define GLU_NURBS_TEX_COORD_DATA_EXT 100174 +#define GLU_NURBS_END_DATA 100175 +#define GLU_NURBS_END_DATA_EXT 100175 + +/* NurbsError */ +#define GLU_NURBS_ERROR1 100251 +#define GLU_NURBS_ERROR2 100252 +#define GLU_NURBS_ERROR3 100253 +#define GLU_NURBS_ERROR4 100254 +#define GLU_NURBS_ERROR5 100255 +#define GLU_NURBS_ERROR6 100256 +#define GLU_NURBS_ERROR7 100257 +#define GLU_NURBS_ERROR8 100258 +#define GLU_NURBS_ERROR9 100259 +#define GLU_NURBS_ERROR10 100260 +#define GLU_NURBS_ERROR11 100261 +#define GLU_NURBS_ERROR12 100262 +#define GLU_NURBS_ERROR13 100263 +#define GLU_NURBS_ERROR14 100264 +#define GLU_NURBS_ERROR15 100265 +#define GLU_NURBS_ERROR16 100266 +#define GLU_NURBS_ERROR17 100267 +#define GLU_NURBS_ERROR18 100268 +#define GLU_NURBS_ERROR19 100269 +#define GLU_NURBS_ERROR20 100270 +#define GLU_NURBS_ERROR21 100271 +#define GLU_NURBS_ERROR22 100272 +#define GLU_NURBS_ERROR23 100273 +#define GLU_NURBS_ERROR24 100274 +#define GLU_NURBS_ERROR25 100275 +#define GLU_NURBS_ERROR26 100276 +#define GLU_NURBS_ERROR27 100277 +#define GLU_NURBS_ERROR28 100278 +#define GLU_NURBS_ERROR29 100279 +#define GLU_NURBS_ERROR30 100280 +#define GLU_NURBS_ERROR31 100281 +#define GLU_NURBS_ERROR32 100282 +#define GLU_NURBS_ERROR33 100283 +#define GLU_NURBS_ERROR34 100284 +#define GLU_NURBS_ERROR35 100285 +#define GLU_NURBS_ERROR36 100286 +#define GLU_NURBS_ERROR37 100287 + +/* NurbsProperty */ +#define GLU_AUTO_LOAD_MATRIX 100200 +#define GLU_CULLING 100201 +#define GLU_SAMPLING_TOLERANCE 100203 +#define GLU_DISPLAY_MODE 100204 +#define GLU_PARAMETRIC_TOLERANCE 100202 +#define GLU_SAMPLING_METHOD 100205 +#define GLU_U_STEP 100206 +#define GLU_V_STEP 100207 +#define GLU_NURBS_MODE 100160 +#define GLU_NURBS_MODE_EXT 100160 +#define GLU_NURBS_TESSELLATOR 100161 +#define GLU_NURBS_TESSELLATOR_EXT 100161 +#define GLU_NURBS_RENDERER 100162 +#define GLU_NURBS_RENDERER_EXT 100162 + +/* NurbsSampling */ +#define GLU_OBJECT_PARAMETRIC_ERROR 100208 +#define GLU_OBJECT_PARAMETRIC_ERROR_EXT 100208 +#define GLU_OBJECT_PATH_LENGTH 100209 +#define GLU_OBJECT_PATH_LENGTH_EXT 100209 +#define GLU_PATH_LENGTH 100215 +#define GLU_PARAMETRIC_ERROR 100216 +#define GLU_DOMAIN_DISTANCE 100217 + +/* NurbsTrim */ +#define GLU_MAP1_TRIM_2 100210 +#define GLU_MAP1_TRIM_3 100211 + +/* QuadricDrawStyle */ +#define GLU_POINT 100010 +#define GLU_LINE 100011 +#define GLU_FILL 100012 +#define GLU_SILHOUETTE 100013 + +/* QuadricCallback */ +/* GLU_ERROR */ + +/* QuadricNormal */ +#define GLU_SMOOTH 100000 +#define GLU_FLAT 100001 +#define GLU_NONE 100002 + +/* QuadricOrientation */ +#define GLU_OUTSIDE 100020 +#define GLU_INSIDE 100021 + +/* TessCallback */ +#define GLU_TESS_BEGIN 100100 +#define GLU_BEGIN 100100 +#define GLU_TESS_VERTEX 100101 +#define GLU_VERTEX 100101 +#define GLU_TESS_END 100102 +#define GLU_END 100102 +#define GLU_TESS_ERROR 100103 +#define GLU_TESS_EDGE_FLAG 100104 +#define GLU_EDGE_FLAG 100104 +#define GLU_TESS_COMBINE 100105 +#define GLU_TESS_BEGIN_DATA 100106 +#define GLU_TESS_VERTEX_DATA 100107 +#define GLU_TESS_END_DATA 100108 +#define GLU_TESS_ERROR_DATA 100109 +#define GLU_TESS_EDGE_FLAG_DATA 100110 +#define GLU_TESS_COMBINE_DATA 100111 + +/* TessContour */ +#define GLU_CW 100120 +#define GLU_CCW 100121 +#define GLU_INTERIOR 100122 +#define GLU_EXTERIOR 100123 +#define GLU_UNKNOWN 100124 + +/* TessProperty */ +#define GLU_TESS_WINDING_RULE 100140 +#define GLU_TESS_BOUNDARY_ONLY 100141 +#define GLU_TESS_TOLERANCE 100142 + +/* TessError */ +#define GLU_TESS_ERROR1 100151 +#define GLU_TESS_ERROR2 100152 +#define GLU_TESS_ERROR3 100153 +#define GLU_TESS_ERROR4 100154 +#define GLU_TESS_ERROR5 100155 +#define GLU_TESS_ERROR6 100156 +#define GLU_TESS_ERROR7 100157 +#define GLU_TESS_ERROR8 100158 +#define GLU_TESS_MISSING_BEGIN_POLYGON 100151 +#define GLU_TESS_MISSING_BEGIN_CONTOUR 100152 +#define GLU_TESS_MISSING_END_POLYGON 100153 +#define GLU_TESS_MISSING_END_CONTOUR 100154 +#define GLU_TESS_COORD_TOO_LARGE 100155 +#define GLU_TESS_NEED_COMBINE_CALLBACK 100156 + +/* TessWinding */ +#define GLU_TESS_WINDING_ODD 100130 +#define GLU_TESS_WINDING_NONZERO 100131 +#define GLU_TESS_WINDING_POSITIVE 100132 +#define GLU_TESS_WINDING_NEGATIVE 100133 +#define GLU_TESS_WINDING_ABS_GEQ_TWO 100134 + +/*************************************************************/ + + +#ifdef __cplusplus +class GLUnurbs; +class GLUquadric; +class GLUtesselator; +#else +typedef struct GLUnurbs GLUnurbs; +typedef struct GLUquadric GLUquadric; +typedef struct GLUtesselator GLUtesselator; +#endif + +typedef GLUnurbs GLUnurbsObj; +typedef GLUquadric GLUquadricObj; +typedef GLUtesselator GLUtesselatorObj; +typedef GLUtesselator GLUtriangulatorObj; + +#define GLU_TESS_MAX_COORD 1.0e150 + +/* Internal convenience typedefs */ +typedef void (GLAPIENTRYP _GLUfuncptr)(void); + +GLAPI void GLAPIENTRY gluBeginCurve (GLUnurbs* nurb); +GLAPI void GLAPIENTRY gluBeginPolygon (GLUtesselator* tess); +GLAPI void GLAPIENTRY gluBeginSurface (GLUnurbs* nurb); +GLAPI void GLAPIENTRY gluBeginTrim (GLUnurbs* nurb); +GLAPI GLint GLAPIENTRY gluBuild1DMipmapLevels (GLenum target, GLint internalFormat, GLsizei width, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void *data); +GLAPI GLint GLAPIENTRY gluBuild1DMipmaps (GLenum target, GLint internalFormat, GLsizei width, GLenum format, GLenum type, const void *data); +GLAPI GLint GLAPIENTRY gluBuild2DMipmapLevels (GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void *data); +GLAPI GLint GLAPIENTRY gluBuild2DMipmaps (GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *data); +GLAPI GLint GLAPIENTRY gluBuild3DMipmapLevels (GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void *data); +GLAPI GLint GLAPIENTRY gluBuild3DMipmaps (GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void *data); +GLAPI GLboolean GLAPIENTRY gluCheckExtension (const GLubyte *extName, const GLubyte *extString); +GLAPI void GLAPIENTRY gluCylinder (GLUquadric* quad, GLdouble base, GLdouble top, GLdouble height, GLint slices, GLint stacks); +GLAPI void GLAPIENTRY gluDeleteNurbsRenderer (GLUnurbs* nurb); +GLAPI void GLAPIENTRY gluDeleteQuadric (GLUquadric* quad); +GLAPI void GLAPIENTRY gluDeleteTess (GLUtesselator* tess); +GLAPI void GLAPIENTRY gluDisk (GLUquadric* quad, GLdouble inner, GLdouble outer, GLint slices, GLint loops); +GLAPI void GLAPIENTRY gluEndCurve (GLUnurbs* nurb); +GLAPI void GLAPIENTRY gluEndPolygon (GLUtesselator* tess); +GLAPI void GLAPIENTRY gluEndSurface (GLUnurbs* nurb); +GLAPI void GLAPIENTRY gluEndTrim (GLUnurbs* nurb); +GLAPI const GLubyte * GLAPIENTRY gluErrorString (GLenum error); +GLAPI void GLAPIENTRY gluGetNurbsProperty (GLUnurbs* nurb, GLenum property, GLfloat* data); +GLAPI const GLubyte * GLAPIENTRY gluGetString (GLenum name); +GLAPI void GLAPIENTRY gluGetTessProperty (GLUtesselator* tess, GLenum which, GLdouble* data); +GLAPI void GLAPIENTRY gluLoadSamplingMatrices (GLUnurbs* nurb, const GLfloat *model, const GLfloat *perspective, const GLint *view); +GLAPI void GLAPIENTRY gluLookAt (GLdouble eyeX, GLdouble eyeY, GLdouble eyeZ, GLdouble centerX, GLdouble centerY, GLdouble centerZ, GLdouble upX, GLdouble upY, GLdouble upZ); +GLAPI GLUnurbs* GLAPIENTRY gluNewNurbsRenderer (void); +GLAPI GLUquadric* GLAPIENTRY gluNewQuadric (void); +GLAPI GLUtesselator* GLAPIENTRY gluNewTess (void); +GLAPI void GLAPIENTRY gluNextContour (GLUtesselator* tess, GLenum type); +GLAPI void GLAPIENTRY gluNurbsCallback (GLUnurbs* nurb, GLenum which, _GLUfuncptr CallBackFunc); +GLAPI void GLAPIENTRY gluNurbsCallbackData (GLUnurbs* nurb, GLvoid* userData); +GLAPI void GLAPIENTRY gluNurbsCallbackDataEXT (GLUnurbs* nurb, GLvoid* userData); +GLAPI void GLAPIENTRY gluNurbsCurve (GLUnurbs* nurb, GLint knotCount, GLfloat *knots, GLint stride, GLfloat *control, GLint order, GLenum type); +GLAPI void GLAPIENTRY gluNurbsProperty (GLUnurbs* nurb, GLenum property, GLfloat value); +GLAPI void GLAPIENTRY gluNurbsSurface (GLUnurbs* nurb, GLint sKnotCount, GLfloat* sKnots, GLint tKnotCount, GLfloat* tKnots, GLint sStride, GLint tStride, GLfloat* control, GLint sOrder, GLint tOrder, GLenum type); +GLAPI void GLAPIENTRY gluOrtho2D (GLdouble left, GLdouble right, GLdouble bottom, GLdouble top); +GLAPI void GLAPIENTRY gluPartialDisk (GLUquadric* quad, GLdouble inner, GLdouble outer, GLint slices, GLint loops, GLdouble start, GLdouble sweep); +GLAPI void GLAPIENTRY gluPerspective (GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar); +GLAPI void GLAPIENTRY gluPickMatrix (GLdouble x, GLdouble y, GLdouble delX, GLdouble delY, GLint *viewport); +GLAPI GLint GLAPIENTRY gluProject (GLdouble objX, GLdouble objY, GLdouble objZ, const GLdouble *model, const GLdouble *proj, const GLint *view, GLdouble* winX, GLdouble* winY, GLdouble* winZ); +GLAPI void GLAPIENTRY gluPwlCurve (GLUnurbs* nurb, GLint count, GLfloat* data, GLint stride, GLenum type); +GLAPI void GLAPIENTRY gluQuadricCallback (GLUquadric* quad, GLenum which, _GLUfuncptr CallBackFunc); +GLAPI void GLAPIENTRY gluQuadricDrawStyle (GLUquadric* quad, GLenum draw); +GLAPI void GLAPIENTRY gluQuadricNormals (GLUquadric* quad, GLenum normal); +GLAPI void GLAPIENTRY gluQuadricOrientation (GLUquadric* quad, GLenum orientation); +GLAPI void GLAPIENTRY gluQuadricTexture (GLUquadric* quad, GLboolean texture); +GLAPI GLint GLAPIENTRY gluScaleImage (GLenum format, GLsizei wIn, GLsizei hIn, GLenum typeIn, const void *dataIn, GLsizei wOut, GLsizei hOut, GLenum typeOut, GLvoid* dataOut); +GLAPI void GLAPIENTRY gluSphere (GLUquadric* quad, GLdouble radius, GLint slices, GLint stacks); +GLAPI void GLAPIENTRY gluTessBeginContour (GLUtesselator* tess); +GLAPI void GLAPIENTRY gluTessBeginPolygon (GLUtesselator* tess, GLvoid* data); +GLAPI void GLAPIENTRY gluTessCallback (GLUtesselator* tess, GLenum which, _GLUfuncptr CallBackFunc); +GLAPI void GLAPIENTRY gluTessEndContour (GLUtesselator* tess); +GLAPI void GLAPIENTRY gluTessEndPolygon (GLUtesselator* tess); +GLAPI void GLAPIENTRY gluTessNormal (GLUtesselator* tess, GLdouble valueX, GLdouble valueY, GLdouble valueZ); +GLAPI void GLAPIENTRY gluTessProperty (GLUtesselator* tess, GLenum which, GLdouble data); +GLAPI void GLAPIENTRY gluTessVertex (GLUtesselator* tess, GLdouble *location, GLvoid* data); +GLAPI GLint GLAPIENTRY gluUnProject (GLdouble winX, GLdouble winY, GLdouble winZ, const GLdouble *model, const GLdouble *proj, const GLint *view, GLdouble* objX, GLdouble* objY, GLdouble* objZ); +GLAPI GLint GLAPIENTRY gluUnProject4 (GLdouble winX, GLdouble winY, GLdouble winZ, GLdouble clipW, const GLdouble *model, const GLdouble *proj, const GLint *view, GLdouble nearVal, GLdouble farVal, GLdouble* objX, GLdouble* objY, GLdouble* objZ, GLdouble* objW); + +#ifdef __cplusplus +} +#endif + +#endif /* __glu_h__ */ diff --git a/Projects/Android/jni/SupportLibs/gl4es/include/GL/glu_mangle.h b/Projects/Android/jni/SupportLibs/gl4es/include/GL/glu_mangle.h new file mode 100644 index 0000000..9c25aa8 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/include/GL/glu_mangle.h @@ -0,0 +1,86 @@ +/* + * Mesa 3-D graphics library + * Version: 3.0 + * Copyright (C) 1995-1998 Brian Paul + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + + +#ifndef GLU_MANGLE_H +#define GLU_MANGLE_H + + +#define gluLookAt mgluLookAt +#define gluOrtho2D mgluOrtho2D +#define gluPerspective mgluPerspective +#define gluPickMatrix mgluPickMatrix +#define gluProject mgluProject +#define gluUnProject mgluUnProject +#define gluErrorString mgluErrorString +#define gluScaleImage mgluScaleImage +#define gluBuild1DMipmaps mgluBuild1DMipmaps +#define gluBuild2DMipmaps mgluBuild2DMipmaps +#define gluNewQuadric mgluNewQuadric +#define gluDeleteQuadric mgluDeleteQuadric +#define gluQuadricDrawStyle mgluQuadricDrawStyle +#define gluQuadricOrientation mgluQuadricOrientation +#define gluQuadricNormals mgluQuadricNormals +#define gluQuadricTexture mgluQuadricTexture +#define gluQuadricCallback mgluQuadricCallback +#define gluCylinder mgluCylinder +#define gluSphere mgluSphere +#define gluDisk mgluDisk +#define gluPartialDisk mgluPartialDisk +#define gluNewNurbsRenderer mgluNewNurbsRenderer +#define gluDeleteNurbsRenderer mgluDeleteNurbsRenderer +#define gluLoadSamplingMatrices mgluLoadSamplingMatrices +#define gluNurbsProperty mgluNurbsProperty +#define gluGetNurbsProperty mgluGetNurbsProperty +#define gluBeginCurve mgluBeginCurve +#define gluEndCurve mgluEndCurve +#define gluNurbsCurve mgluNurbsCurve +#define gluBeginSurface mgluBeginSurface +#define gluEndSurface mgluEndSurface +#define gluNurbsSurface mgluNurbsSurface +#define gluBeginTrim mgluBeginTrim +#define gluEndTrim mgluEndTrim +#define gluPwlCurve mgluPwlCurve +#define gluNurbsCallback mgluNurbsCallback +#define gluNewTess mgluNewTess +#define gluDeleteTess mgluDeleteTess +#define gluTessBeginPolygon mgluTessBeginPolygon +#define gluTessBeginContour mgluTessBeginContour +#define gluTessVertex mgluTessVertex +#define gluTessEndPolygon mgluTessEndPolygon +#define gluTessEndContour mgluTessEndContour +#define gluTessProperty mgluTessProperty +#define gluTessNormal mgluTessNormal +#define gluTessCallback mgluTessCallback +#define gluGetTessProperty mgluGetTessProperty +#define gluBeginPolygon mgluBeginPolygon +#define gluNextContour mgluNextContour +#define gluEndPolygon mgluEndPolygon +#define gluGetString mgluGetString +#define gluBuild1DMipmapLevels mgluBuild1DMipmapLevels +#define gluBuild2DMipmapLevels mgluBuild2DMipmapLevels +#define gluBuild3DMipmapLevels mgluBuild3DMipmapLevels +#define gluBuild3DMipmaps mgluBuild3DMipmaps +#define gluCheckExtension mgluCheckExtension +#define gluUnProject4 mgluUnProject4 +#define gluNurbsCallbackData mgluNurbsCallbackData +#define gluNurbsCallbackDataEXT mgluNurbsCallbackDataEXT + +#endif diff --git a/Projects/Android/jni/SupportLibs/gl4es/include/GL/glx.h b/Projects/Android/jni/SupportLibs/gl4es/include/GL/glx.h new file mode 100644 index 0000000..18b784d --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/include/GL/glx.h @@ -0,0 +1,528 @@ +/* + * Mesa 3-D graphics library + * Version: 6.5 + * + * Copyright (C) 1999-2006 Brian Paul All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + + +#ifndef GLX_H +#define GLX_H + + +#ifdef __VMS +#include +# ifdef __cplusplus +/* VMS Xlib.h gives problems with C++. + * this avoids a bunch of trivial warnings */ +#pragma message disable nosimpint +#endif +#endif +#ifndef ANDROID +#include +#include +#endif //ANDROID +#ifdef __VMS +# ifdef __cplusplus +#pragma message enable nosimpint +#endif +#endif +#include + + +#if defined(USE_MGL_NAMESPACE) +#include "glx_mangle.h" +#endif + + +#ifdef __cplusplus +extern "C" { +#endif + + +#define GLX_VERSION_1_1 1 +#define GLX_VERSION_1_2 1 +#define GLX_VERSION_1_3 1 +#define GLX_VERSION_1_4 1 + +#define GLX_EXTENSION_NAME "GLX" + + + +/* + * Tokens for glXChooseVisual and glXGetConfig: + */ +#define GLX_USE_GL 1 +#define GLX_BUFFER_SIZE 2 +#define GLX_LEVEL 3 +#define GLX_RGBA 4 +#define GLX_DOUBLEBUFFER 5 +#define GLX_STEREO 6 +#define GLX_AUX_BUFFERS 7 +#define GLX_RED_SIZE 8 +#define GLX_GREEN_SIZE 9 +#define GLX_BLUE_SIZE 10 +#define GLX_ALPHA_SIZE 11 +#define GLX_DEPTH_SIZE 12 +#define GLX_STENCIL_SIZE 13 +#define GLX_ACCUM_RED_SIZE 14 +#define GLX_ACCUM_GREEN_SIZE 15 +#define GLX_ACCUM_BLUE_SIZE 16 +#define GLX_ACCUM_ALPHA_SIZE 17 + + +/* + * Error codes returned by glXGetConfig: + */ +#define GLX_BAD_SCREEN 1 +#define GLX_BAD_ATTRIBUTE 2 +#define GLX_NO_EXTENSION 3 +#define GLX_BAD_VISUAL 4 +#define GLX_BAD_CONTEXT 5 +#define GLX_BAD_VALUE 6 +#define GLX_BAD_ENUM 7 + + +/* + * GLX 1.1 and later: + */ +#define GLX_VENDOR 1 +#define GLX_VERSION 2 +#define GLX_EXTENSIONS 3 + + +/* + * GLX 1.3 and later: + */ +#define GLX_CONFIG_CAVEAT 0x20 +#define GLX_DONT_CARE 0xFFFFFFFF +#define GLX_X_VISUAL_TYPE 0x22 +#define GLX_TRANSPARENT_TYPE 0x23 +#define GLX_TRANSPARENT_INDEX_VALUE 0x24 +#define GLX_TRANSPARENT_RED_VALUE 0x25 +#define GLX_TRANSPARENT_GREEN_VALUE 0x26 +#define GLX_TRANSPARENT_BLUE_VALUE 0x27 +#define GLX_TRANSPARENT_ALPHA_VALUE 0x28 +#define GLX_WINDOW_BIT 0x00000001 +#define GLX_PIXMAP_BIT 0x00000002 +#define GLX_PBUFFER_BIT 0x00000004 +#define GLX_AUX_BUFFERS_BIT 0x00000010 +#define GLX_FRONT_LEFT_BUFFER_BIT 0x00000001 +#define GLX_FRONT_RIGHT_BUFFER_BIT 0x00000002 +#define GLX_BACK_LEFT_BUFFER_BIT 0x00000004 +#define GLX_BACK_RIGHT_BUFFER_BIT 0x00000008 +#define GLX_DEPTH_BUFFER_BIT 0x00000020 +#define GLX_STENCIL_BUFFER_BIT 0x00000040 +#define GLX_ACCUM_BUFFER_BIT 0x00000080 +#define GLX_NONE 0x8000 +#define GLX_SLOW_CONFIG 0x8001 +#define GLX_TRUE_COLOR 0x8002 +#define GLX_DIRECT_COLOR 0x8003 +#define GLX_PSEUDO_COLOR 0x8004 +#define GLX_STATIC_COLOR 0x8005 +#define GLX_GRAY_SCALE 0x8006 +#define GLX_STATIC_GRAY 0x8007 +#define GLX_TRANSPARENT_RGB 0x8008 +#define GLX_TRANSPARENT_INDEX 0x8009 +#define GLX_VISUAL_ID 0x800B +#define GLX_SCREEN 0x800C +#define GLX_NON_CONFORMANT_CONFIG 0x800D +#define GLX_DRAWABLE_TYPE 0x8010 +#define GLX_RENDER_TYPE 0x8011 +#define GLX_X_RENDERABLE 0x8012 +#define GLX_FBCONFIG_ID 0x8013 +#define GLX_RGBA_TYPE 0x8014 +#define GLX_COLOR_INDEX_TYPE 0x8015 +#define GLX_MAX_PBUFFER_WIDTH 0x8016 +#define GLX_MAX_PBUFFER_HEIGHT 0x8017 +#define GLX_MAX_PBUFFER_PIXELS 0x8018 +#define GLX_PRESERVED_CONTENTS 0x801B +#define GLX_LARGEST_PBUFFER 0x801C +#define GLX_WIDTH 0x801D +#define GLX_HEIGHT 0x801E +#define GLX_EVENT_MASK 0x801F +#define GLX_DAMAGED 0x8020 +#define GLX_SAVED 0x8021 +#define GLX_WINDOW 0x8022 +#define GLX_PBUFFER 0x8023 +#define GLX_PBUFFER_HEIGHT 0x8040 +#define GLX_PBUFFER_WIDTH 0x8041 +#define GLX_RGBA_BIT 0x00000001 +#define GLX_COLOR_INDEX_BIT 0x00000002 +#define GLX_PBUFFER_CLOBBER_MASK 0x08000000 + + +/* + * GLX 1.4 and later: + */ +#define GLX_SAMPLE_BUFFERS 0x186a0 /*100000*/ +#define GLX_SAMPLES 0x186a1 /*100001*/ + + + +typedef struct __GLXcontextRec *GLXContext; +typedef XID GLXPixmap; +typedef XID GLXDrawable; +/* GLX 1.3 and later */ +typedef struct __GLXFBConfigRec *GLXFBConfig; +typedef XID GLXFBConfigID; +typedef XID GLXContextID; +typedef XID GLXWindow; +typedef XID GLXPbuffer; + + +/* +** Events. +** __GLX_NUMBER_EVENTS is set to 17 to account for the BufferClobberSGIX +** event - this helps initialization if the server supports the pbuffer +** extension and the client doesn't. +*/ +#define GLX_PbufferClobber 0 +#define GLX_BufferSwapComplete 1 + +#define __GLX_NUMBER_EVENTS 17 + +extern XVisualInfo* glXChooseVisual( Display *dpy, int screen, + int *attribList ); + +extern GLXContext glXCreateContext( Display *dpy, XVisualInfo *vis, + GLXContext shareList, Bool direct ); + +extern void glXDestroyContext( Display *dpy, GLXContext ctx ); + +extern Bool glXMakeCurrent( Display *dpy, GLXDrawable drawable, + GLXContext ctx); + +extern void glXCopyContext( Display *dpy, GLXContext src, GLXContext dst, + unsigned long mask ); + +extern void glXSwapBuffers( Display *dpy, GLXDrawable drawable ); + +extern GLXPixmap glXCreateGLXPixmap( Display *dpy, XVisualInfo *visual, + Pixmap pixmap ); + +extern void glXDestroyGLXPixmap( Display *dpy, GLXPixmap pixmap ); + +extern Bool glXQueryExtension( Display *dpy, int *errorb, int *event ); + +extern Bool glXQueryVersion( Display *dpy, int *maj, int *min ); + +extern Bool glXIsDirect( Display *dpy, GLXContext ctx ); + +extern int glXGetConfig( Display *dpy, XVisualInfo *visual, + int attrib, int *value ); + +extern GLXContext glXGetCurrentContext( void ); + +extern GLXDrawable glXGetCurrentDrawable( void ); + +extern void glXWaitGL( void ); + +extern void glXWaitX( void ); + +extern void glXUseXFont( Font font, int first, int count, int list ); + + + +/* GLX 1.1 and later */ +extern const char *glXQueryExtensionsString( Display *dpy, int screen ); + +extern const char *glXQueryServerString( Display *dpy, int screen, int name ); + +extern const char *glXGetClientString( Display *dpy, int name ); + + +/* GLX 1.2 and later */ +extern Display *glXGetCurrentDisplay( void ); + + +/* GLX 1.3 and later */ +extern GLXFBConfig *glXChooseFBConfig( Display *dpy, int screen, + const int *attribList, int *nitems ); + +extern int glXGetFBConfigAttrib( Display *dpy, GLXFBConfig config, + int attribute, int *value ); + +extern GLXFBConfig *glXGetFBConfigs( Display *dpy, int screen, + int *nelements ); + +extern XVisualInfo *glXGetVisualFromFBConfig( Display *dpy, + GLXFBConfig config ); + +extern GLXWindow glXCreateWindow( Display *dpy, GLXFBConfig config, + Window win, const int *attribList ); + +extern void glXDestroyWindow( Display *dpy, GLXWindow window ); + +extern GLXPixmap glXCreatePixmap( Display *dpy, GLXFBConfig config, + Pixmap pixmap, const int *attribList ); + +extern void glXDestroyPixmap( Display *dpy, GLXPixmap pixmap ); + +extern GLXPbuffer glXCreatePbuffer( Display *dpy, GLXFBConfig config, + const int *attribList ); + +extern void glXDestroyPbuffer( Display *dpy, GLXPbuffer pbuf ); + +extern void glXQueryDrawable( Display *dpy, GLXDrawable draw, int attribute, + unsigned int *value ); + +extern GLXContext glXCreateNewContext( Display *dpy, GLXFBConfig config, + int renderType, GLXContext shareList, + Bool direct ); + +extern Bool glXMakeContextCurrent( Display *dpy, GLXDrawable draw, + GLXDrawable read, GLXContext ctx ); + +extern GLXDrawable glXGetCurrentReadDrawable( void ); + +extern int glXQueryContext( Display *dpy, GLXContext ctx, int attribute, + int *value ); + +extern void glXSelectEvent( Display *dpy, GLXDrawable drawable, + unsigned long mask ); + +extern void glXGetSelectedEvent( Display *dpy, GLXDrawable drawable, + unsigned long *mask ); + +/* GLX 1.3 function pointer typedefs */ +typedef GLXFBConfig * (* PFNGLXGETFBCONFIGSPROC) (Display *dpy, int screen, int *nelements); +typedef GLXFBConfig * (* PFNGLXCHOOSEFBCONFIGPROC) (Display *dpy, int screen, const int *attrib_list, int *nelements); +typedef int (* PFNGLXGETFBCONFIGATTRIBPROC) (Display *dpy, GLXFBConfig config, int attribute, int *value); +typedef XVisualInfo * (* PFNGLXGETVISUALFROMFBCONFIGPROC) (Display *dpy, GLXFBConfig config); +typedef GLXWindow (* PFNGLXCREATEWINDOWPROC) (Display *dpy, GLXFBConfig config, Window win, const int *attrib_list); +typedef void (* PFNGLXDESTROYWINDOWPROC) (Display *dpy, GLXWindow win); +typedef GLXPixmap (* PFNGLXCREATEPIXMAPPROC) (Display *dpy, GLXFBConfig config, Pixmap pixmap, const int *attrib_list); +typedef void (* PFNGLXDESTROYPIXMAPPROC) (Display *dpy, GLXPixmap pixmap); +typedef GLXPbuffer (* PFNGLXCREATEPBUFFERPROC) (Display *dpy, GLXFBConfig config, const int *attrib_list); +typedef void (* PFNGLXDESTROYPBUFFERPROC) (Display *dpy, GLXPbuffer pbuf); +typedef void (* PFNGLXQUERYDRAWABLEPROC) (Display *dpy, GLXDrawable draw, int attribute, unsigned int *value); +typedef GLXContext (* PFNGLXCREATENEWCONTEXTPROC) (Display *dpy, GLXFBConfig config, int render_type, GLXContext share_list, Bool direct); +typedef Bool (* PFNGLXMAKECONTEXTCURRENTPROC) (Display *dpy, GLXDrawable draw, GLXDrawable read, GLXContext ctx); +typedef GLXDrawable (* PFNGLXGETCURRENTREADDRAWABLEPROC) (void); +typedef Display * (* PFNGLXGETCURRENTDISPLAYPROC) (void); +typedef int (* PFNGLXQUERYCONTEXTPROC) (Display *dpy, GLXContext ctx, int attribute, int *value); +typedef void (* PFNGLXSELECTEVENTPROC) (Display *dpy, GLXDrawable draw, unsigned long event_mask); +typedef void (* PFNGLXGETSELECTEDEVENTPROC) (Display *dpy, GLXDrawable draw, unsigned long *event_mask); + + +/* + * ARB 2. GLX_ARB_get_proc_address + */ +#ifndef GLX_ARB_get_proc_address +#define GLX_ARB_get_proc_address 1 + +typedef void (*__GLXextFuncPtr)(void); +extern __GLXextFuncPtr glXGetProcAddressARB (const GLubyte *); + +#endif /* GLX_ARB_get_proc_address */ + + + +/* GLX 1.4 and later */ +extern void (*glXGetProcAddress(const GLubyte *procname))( void ); + +/* GLX 1.4 function pointer typedefs */ +typedef __GLXextFuncPtr (* PFNGLXGETPROCADDRESSPROC) (const GLubyte *procName); + + +#ifndef GLX_GLXEXT_LEGACY + +#include + +#endif /* GLX_GLXEXT_LEGACY */ + + +/** + ** The following aren't in glxext.h yet. + **/ + + +/* + * ???. GLX_NV_vertex_array_range + */ +#ifndef GLX_NV_vertex_array_range +#define GLX_NV_vertex_array_range + +extern void *glXAllocateMemoryNV(GLsizei size, GLfloat readfreq, GLfloat writefreq, GLfloat priority); +extern void glXFreeMemoryNV(GLvoid *pointer); +typedef void * ( * PFNGLXALLOCATEMEMORYNVPROC) (GLsizei size, GLfloat readfreq, GLfloat writefreq, GLfloat priority); +typedef void ( * PFNGLXFREEMEMORYNVPROC) (GLvoid *pointer); + +#endif /* GLX_NV_vertex_array_range */ + + +/* + * ARB ?. GLX_ARB_render_texture + * XXX This was never finalized! + */ +#ifndef GLX_ARB_render_texture +#define GLX_ARB_render_texture 1 + +extern Bool glXBindTexImageARB(Display *dpy, GLXPbuffer pbuffer, int buffer); +extern Bool glXReleaseTexImageARB(Display *dpy, GLXPbuffer pbuffer, int buffer); +extern Bool glXDrawableAttribARB(Display *dpy, GLXDrawable draw, const int *attribList); + +#endif /* GLX_ARB_render_texture */ + + +/* + * Remove this when glxext.h is updated. + */ +#ifndef GLX_NV_float_buffer +#define GLX_NV_float_buffer 1 + +#define GLX_FLOAT_COMPONENTS_NV 0x20B0 + +#endif /* GLX_NV_float_buffer */ + + + +/* + * #?. GLX_MESA_swap_frame_usage + */ +#ifndef GLX_MESA_swap_frame_usage +#define GLX_MESA_swap_frame_usage 1 + +extern int glXGetFrameUsageMESA(Display *dpy, GLXDrawable drawable, float *usage); +extern int glXBeginFrameTrackingMESA(Display *dpy, GLXDrawable drawable); +extern int glXEndFrameTrackingMESA(Display *dpy, GLXDrawable drawable); +extern int glXQueryFrameTrackingMESA(Display *dpy, GLXDrawable drawable, int64_t *swapCount, int64_t *missedFrames, float *lastMissedUsage); + +typedef int (*PFNGLXGETFRAMEUSAGEMESAPROC) (Display *dpy, GLXDrawable drawable, float *usage); +typedef int (*PFNGLXBEGINFRAMETRACKINGMESAPROC)(Display *dpy, GLXDrawable drawable); +typedef int (*PFNGLXENDFRAMETRACKINGMESAPROC)(Display *dpy, GLXDrawable drawable); +typedef int (*PFNGLXQUERYFRAMETRACKINGMESAPROC)(Display *dpy, GLXDrawable drawable, int64_t *swapCount, int64_t *missedFrames, float *lastMissedUsage); + +#endif /* GLX_MESA_swap_frame_usage */ + + + +/* + * #?. GLX_MESA_swap_control + */ +#ifndef GLX_MESA_swap_control +#define GLX_MESA_swap_control 1 + +extern int glXSwapIntervalMESA(unsigned int interval); +extern int glXGetSwapIntervalMESA(void); + +typedef int (*PFNGLXSWAPINTERVALMESAPROC)(unsigned int interval); +typedef int (*PFNGLXGETSWAPINTERVALMESAPROC)(void); + +#endif /* GLX_MESA_swap_control */ + + + +/* + * #?. GLX_EXT_texture_from_pixmap + * XXX not finished? + */ +#ifndef GLX_EXT_texture_from_pixmap +#define GLX_EXT_texture_from_pixmap 1 + +#define GLX_BIND_TO_TEXTURE_RGB_EXT 0x20D0 +#define GLX_BIND_TO_TEXTURE_RGBA_EXT 0x20D1 +#define GLX_BIND_TO_MIPMAP_TEXTURE_EXT 0x20D2 +#define GLX_BIND_TO_TEXTURE_TARGETS_EXT 0x20D3 +#define GLX_Y_INVERTED_EXT 0x20D4 + +#define GLX_TEXTURE_FORMAT_EXT 0x20D5 +#define GLX_TEXTURE_TARGET_EXT 0x20D6 +#define GLX_MIPMAP_TEXTURE_EXT 0x20D7 + +#define GLX_TEXTURE_FORMAT_NONE_EXT 0x20D8 +#define GLX_TEXTURE_FORMAT_RGB_EXT 0x20D9 +#define GLX_TEXTURE_FORMAT_RGBA_EXT 0x20DA + +#define GLX_TEXTURE_1D_BIT_EXT 0x00000001 +#define GLX_TEXTURE_2D_BIT_EXT 0x00000002 +#define GLX_TEXTURE_RECTANGLE_BIT_EXT 0x00000004 + +#define GLX_TEXTURE_1D_EXT 0x20DB +#define GLX_TEXTURE_2D_EXT 0x20DC +#define GLX_TEXTURE_RECTANGLE_EXT 0x20DD + +#define GLX_FRONT_LEFT_EXT 0x20DE +#define GLX_FRONT_RIGHT_EXT 0x20DF +#define GLX_BACK_LEFT_EXT 0x20E0 +#define GLX_BACK_RIGHT_EXT 0x20E1 +#define GLX_FRONT_EXT GLX_FRONT_LEFT_EXT +#define GLX_BACK_EXT GLX_BACK_LEFT_EXT +#define GLX_AUX0_EXT 0x20E2 +#define GLX_AUX1_EXT 0x20E3 +#define GLX_AUX2_EXT 0x20E4 +#define GLX_AUX3_EXT 0x20E5 +#define GLX_AUX4_EXT 0x20E6 +#define GLX_AUX5_EXT 0x20E7 +#define GLX_AUX6_EXT 0x20E8 +#define GLX_AUX7_EXT 0x20E9 +#define GLX_AUX8_EXT 0x20EA +#define GLX_AUX9_EXT 0x20EB + +extern void glXBindTexImageEXT(Display *dpy, GLXDrawable drawable, int buffer, const int *attrib_list); +extern void glXReleaseTexImageEXT(Display *dpy, GLXDrawable drawable, int buffer); + +#endif /* GLX_EXT_texture_from_pixmap */ + + + + +/*** Should these go here, or in another header? */ +/* +** GLX Events +*/ +typedef struct { + int event_type; /* GLX_DAMAGED or GLX_SAVED */ + int draw_type; /* GLX_WINDOW or GLX_PBUFFER */ + unsigned long serial; /* # of last request processed by server */ + Bool send_event; /* true if this came for SendEvent request */ + Display *display; /* display the event was read from */ + GLXDrawable drawable; /* XID of Drawable */ + unsigned int buffer_mask; /* mask indicating which buffers are affected */ + unsigned int aux_buffer; /* which aux buffer was affected */ + int x, y; + int width, height; + int count; /* if nonzero, at least this many more */ +} GLXPbufferClobberEvent; + +typedef struct { + int type; + unsigned long serial; /* # of last request processed by server */ + Bool send_event; /* true if this came from a SendEvent request */ + Display *display; /* Display the event was read from */ + GLXDrawable drawable; /* drawable on which event was requested in event mask */ + int event_type; + int64_t ust; + int64_t msc; + int64_t sbc; +} GLXBufferSwapComplete; + +typedef union __GLXEvent { + GLXPbufferClobberEvent glxpbufferclobber; + GLXBufferSwapComplete glxbufferswapcomplete; + long pad[24]; +} GLXEvent; + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/Projects/Android/jni/SupportLibs/gl4es/include/GL/glx_mangle.h b/Projects/Android/jni/SupportLibs/gl4es/include/GL/glx_mangle.h new file mode 100644 index 0000000..fa664a7 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/include/GL/glx_mangle.h @@ -0,0 +1,82 @@ +/* + * Mesa 3-D graphics library + * Version: 6.5 + * + * Copyright (C) 1999-2006 Brian Paul All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + + +#ifndef GLX_MANGLE_H +#define GLX_MANGLE_H + +#define glXChooseVisual mglXChooseVisual +#define glXCreateContext mglXCreateContext +#define glXDestroyContext mglXDestroyContext +#define glXMakeCurrent mglXMakeCurrent +#define glXCopyContext mglXCopyContext +#define glXSwapBuffers mglXSwapBuffers +#define glXCreateGLXPixmap mglXCreateGLXPixmap +#define glXDestroyGLXPixmap mglXDestroyGLXPixmap +#define glXQueryExtension mglXQueryExtension +#define glXQueryVersion mglXQueryVersion +#define glXIsDirect mglXIsDirect +#define glXGetConfig mglXGetConfig +#define glXGetCurrentContext mglXGetCurrentContext +#define glXGetCurrentDrawable mglXGetCurrentDrawable +#define glXWaitGL mglXWaitGL +#define glXWaitX mglXWaitX +#define glXUseXFont mglXUseXFont +#define glXQueryExtensionsString mglXQueryExtensionsString +#define glXQueryServerString mglXQueryServerString +#define glXGetClientString mglXGetClientString +#define glXCreateGLXPixmapMESA mglXCreateGLXPixmapMESA +#define glXReleaseBuffersMESA mglXReleaseBuffersMESA +#define glXCopySubBufferMESA mglXCopySubBufferMESA +#define glXGetVideoSyncSGI mglXGetVideoSyncSGI +#define glXWaitVideoSyncSGI mglXWaitVideoSyncSGI + +/* GLX 1.2 */ +#define glXGetCurrentDisplay mglXGetCurrentDisplay + +/* GLX 1.3 */ +#define glXChooseFBConfig mglXChooseFBConfig +#define glXGetFBConfigAttrib mglXGetFBConfigAttrib +#define glXGetFBConfigs mglXGetFBConfigs +#define glXGetVisualFromFBConfig mglXGetVisualFromFBConfig +#define glXCreateWindow mglXCreateWindow +#define glXDestroyWindow mglXDestroyWindow +#define glXCreatePixmap mglXCreatePixmap +#define glXDestroyPixmap mglXDestroyPixmap +#define glXCreatePbuffer mglXCreatePbuffer +#define glXDestroyPbuffer mglXDestroyPbuffer +#define glXQueryDrawable mglXQueryDrawable +#define glXCreateNewContext mglXCreateNewContext +#define glXMakeContextCurrent mglXMakeContextCurrent +#define glXGetCurrentReadDrawable mglXGetCurrentReadDrawable +#define glXQueryContext mglXQueryContext +#define glXSelectEvent mglXSelectEvent +#define glXGetSelectedEvent mglXGetSelectedEvent + +/* GLX 1.4 */ +#define glXGetProcAddress mglXGetProcAddress +#define glXGetProcAddressARB mglXGetProcAddressARB + + +#endif diff --git a/Projects/Android/jni/SupportLibs/gl4es/include/GL/glxext.h b/Projects/Android/jni/SupportLibs/gl4es/include/GL/glxext.h new file mode 100644 index 0000000..3c47dc3 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/include/GL/glxext.h @@ -0,0 +1,993 @@ +#ifndef __glxext_h_ +#define __glxext_h_ + +#ifdef __cplusplus +extern "C" { +#endif + +/* +** Copyright (c) 2007-2010 The Khronos Group Inc. +** +** Permission is hereby granted, free of charge, to any person obtaining a +** copy of this software and/or associated documentation files (the +** "Materials"), to deal in the Materials without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Materials, and to +** permit persons to whom the Materials are furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be included +** in all copies or substantial portions of the Materials. +** +** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. +*/ + +/* Function declaration macros - to move into glplatform.h */ + +#if defined(_WIN32) && !defined(APIENTRY) && !defined(__CYGWIN__) && !defined(__SCITECH_SNAP__) +#define WIN32_LEAN_AND_MEAN 1 +#include +#endif + +#ifndef APIENTRY +#define APIENTRY +#endif +#ifndef APIENTRYP +#define APIENTRYP APIENTRY * +#endif +#ifndef GLAPI +#define GLAPI extern +#endif + +/*************************************************************/ + +/* Header file version number, required by OpenGL ABI for Linux */ +/* glxext.h last updated 2010/08/06 */ +/* Current version at http://www.opengl.org/registry/ */ +#define GLX_GLXEXT_VERSION 32 + +#ifndef GLX_VERSION_1_3 +#define GLX_WINDOW_BIT 0x00000001 +#define GLX_PIXMAP_BIT 0x00000002 +#define GLX_PBUFFER_BIT 0x00000004 +#define GLX_RGBA_BIT 0x00000001 +#define GLX_COLOR_INDEX_BIT 0x00000002 +#define GLX_PBUFFER_CLOBBER_MASK 0x08000000 +#define GLX_FRONT_LEFT_BUFFER_BIT 0x00000001 +#define GLX_FRONT_RIGHT_BUFFER_BIT 0x00000002 +#define GLX_BACK_LEFT_BUFFER_BIT 0x00000004 +#define GLX_BACK_RIGHT_BUFFER_BIT 0x00000008 +#define GLX_AUX_BUFFERS_BIT 0x00000010 +#define GLX_DEPTH_BUFFER_BIT 0x00000020 +#define GLX_STENCIL_BUFFER_BIT 0x00000040 +#define GLX_ACCUM_BUFFER_BIT 0x00000080 +#define GLX_CONFIG_CAVEAT 0x20 +#define GLX_X_VISUAL_TYPE 0x22 +#define GLX_TRANSPARENT_TYPE 0x23 +#define GLX_TRANSPARENT_INDEX_VALUE 0x24 +#define GLX_TRANSPARENT_RED_VALUE 0x25 +#define GLX_TRANSPARENT_GREEN_VALUE 0x26 +#define GLX_TRANSPARENT_BLUE_VALUE 0x27 +#define GLX_TRANSPARENT_ALPHA_VALUE 0x28 +#define GLX_DONT_CARE 0xFFFFFFFF +#define GLX_NONE 0x8000 +#define GLX_SLOW_CONFIG 0x8001 +#define GLX_TRUE_COLOR 0x8002 +#define GLX_DIRECT_COLOR 0x8003 +#define GLX_PSEUDO_COLOR 0x8004 +#define GLX_STATIC_COLOR 0x8005 +#define GLX_GRAY_SCALE 0x8006 +#define GLX_STATIC_GRAY 0x8007 +#define GLX_TRANSPARENT_RGB 0x8008 +#define GLX_TRANSPARENT_INDEX 0x8009 +#define GLX_VISUAL_ID 0x800B +#define GLX_SCREEN 0x800C +#define GLX_NON_CONFORMANT_CONFIG 0x800D +#define GLX_DRAWABLE_TYPE 0x8010 +#define GLX_RENDER_TYPE 0x8011 +#define GLX_X_RENDERABLE 0x8012 +#define GLX_FBCONFIG_ID 0x8013 +#define GLX_RGBA_TYPE 0x8014 +#define GLX_COLOR_INDEX_TYPE 0x8015 +#define GLX_MAX_PBUFFER_WIDTH 0x8016 +#define GLX_MAX_PBUFFER_HEIGHT 0x8017 +#define GLX_MAX_PBUFFER_PIXELS 0x8018 +#define GLX_PRESERVED_CONTENTS 0x801B +#define GLX_LARGEST_PBUFFER 0x801C +#define GLX_WIDTH 0x801D +#define GLX_HEIGHT 0x801E +#define GLX_EVENT_MASK 0x801F +#define GLX_DAMAGED 0x8020 +#define GLX_SAVED 0x8021 +#define GLX_WINDOW 0x8022 +#define GLX_PBUFFER 0x8023 +#define GLX_PBUFFER_HEIGHT 0x8040 +#define GLX_PBUFFER_WIDTH 0x8041 +#endif + +#ifndef GLX_VERSION_1_4 +#define GLX_SAMPLE_BUFFERS 100000 +#define GLX_SAMPLES 100001 +#endif + +#ifndef GLX_ARB_get_proc_address +#endif + +#ifndef GLX_ARB_multisample +#define GLX_SAMPLE_BUFFERS_ARB 100000 +#define GLX_SAMPLES_ARB 100001 +#endif + +#ifndef GLX_ARB_vertex_buffer_object +#define GLX_CONTEXT_ALLOW_BUFFER_BYTE_ORDER_MISMATCH_ARB 0x2095 +#endif + +#ifndef GLX_ARB_fbconfig_float +#define GLX_RGBA_FLOAT_TYPE_ARB 0x20B9 +#define GLX_RGBA_FLOAT_BIT_ARB 0x00000004 +#endif + +#ifndef GLX_ARB_framebuffer_sRGB +#define GLX_FRAMEBUFFER_SRGB_CAPABLE_ARB 0x20B2 +#endif + +#ifndef GLX_ARB_create_context +#define GLX_CONTEXT_DEBUG_BIT_ARB 0x00000001 +#define GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB 0x00000002 +#define GLX_CONTEXT_MAJOR_VERSION_ARB 0x2091 +#define GLX_CONTEXT_MINOR_VERSION_ARB 0x2092 +#define GLX_CONTEXT_FLAGS_ARB 0x2094 +#endif + +#ifndef GLX_ARB_create_context_profile +#define GLX_CONTEXT_CORE_PROFILE_BIT_ARB 0x00000001 +#define GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB 0x00000002 +#define GLX_CONTEXT_PROFILE_MASK_ARB 0x9126 +#endif + +#ifndef GLX_ARB_create_context_robustness +#define GLX_CONTEXT_ROBUST_ACCESS_BIT_ARB 0x00000004 +#define GLX_LOSE_CONTEXT_ON_RESET_ARB 0x8252 +#define GLX_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB 0x8256 +#define GLX_NO_RESET_NOTIFICATION_ARB 0x8261 +#endif + +#ifndef GLX_SGIS_multisample +#define GLX_SAMPLE_BUFFERS_SGIS 100000 +#define GLX_SAMPLES_SGIS 100001 +#endif + +#ifndef GLX_EXT_visual_info +#define GLX_X_VISUAL_TYPE_EXT 0x22 +#define GLX_TRANSPARENT_TYPE_EXT 0x23 +#define GLX_TRANSPARENT_INDEX_VALUE_EXT 0x24 +#define GLX_TRANSPARENT_RED_VALUE_EXT 0x25 +#define GLX_TRANSPARENT_GREEN_VALUE_EXT 0x26 +#define GLX_TRANSPARENT_BLUE_VALUE_EXT 0x27 +#define GLX_TRANSPARENT_ALPHA_VALUE_EXT 0x28 +#define GLX_NONE_EXT 0x8000 +#define GLX_TRUE_COLOR_EXT 0x8002 +#define GLX_DIRECT_COLOR_EXT 0x8003 +#define GLX_PSEUDO_COLOR_EXT 0x8004 +#define GLX_STATIC_COLOR_EXT 0x8005 +#define GLX_GRAY_SCALE_EXT 0x8006 +#define GLX_STATIC_GRAY_EXT 0x8007 +#define GLX_TRANSPARENT_RGB_EXT 0x8008 +#define GLX_TRANSPARENT_INDEX_EXT 0x8009 +#endif + +#ifndef GLX_SGI_swap_control +#endif + +#ifndef GLX_SGI_video_sync +#endif + +#ifndef GLX_SGI_make_current_read +#endif + +#ifndef GLX_SGIX_video_source +#endif + +#ifndef GLX_EXT_visual_rating +#define GLX_VISUAL_CAVEAT_EXT 0x20 +#define GLX_SLOW_VISUAL_EXT 0x8001 +#define GLX_NON_CONFORMANT_VISUAL_EXT 0x800D +/* reuse GLX_NONE_EXT */ +#endif + +#ifndef GLX_EXT_import_context +#define GLX_SHARE_CONTEXT_EXT 0x800A +#define GLX_VISUAL_ID_EXT 0x800B +#define GLX_SCREEN_EXT 0x800C +#endif + +#ifndef GLX_SGIX_fbconfig +#define GLX_WINDOW_BIT_SGIX 0x00000001 +#define GLX_PIXMAP_BIT_SGIX 0x00000002 +#define GLX_RGBA_BIT_SGIX 0x00000001 +#define GLX_COLOR_INDEX_BIT_SGIX 0x00000002 +#define GLX_DRAWABLE_TYPE_SGIX 0x8010 +#define GLX_RENDER_TYPE_SGIX 0x8011 +#define GLX_X_RENDERABLE_SGIX 0x8012 +#define GLX_FBCONFIG_ID_SGIX 0x8013 +#define GLX_RGBA_TYPE_SGIX 0x8014 +#define GLX_COLOR_INDEX_TYPE_SGIX 0x8015 +/* reuse GLX_SCREEN_EXT */ +#endif + +#ifndef GLX_SGIX_pbuffer +#define GLX_PBUFFER_BIT_SGIX 0x00000004 +#define GLX_BUFFER_CLOBBER_MASK_SGIX 0x08000000 +#define GLX_FRONT_LEFT_BUFFER_BIT_SGIX 0x00000001 +#define GLX_FRONT_RIGHT_BUFFER_BIT_SGIX 0x00000002 +#define GLX_BACK_LEFT_BUFFER_BIT_SGIX 0x00000004 +#define GLX_BACK_RIGHT_BUFFER_BIT_SGIX 0x00000008 +#define GLX_AUX_BUFFERS_BIT_SGIX 0x00000010 +#define GLX_DEPTH_BUFFER_BIT_SGIX 0x00000020 +#define GLX_STENCIL_BUFFER_BIT_SGIX 0x00000040 +#define GLX_ACCUM_BUFFER_BIT_SGIX 0x00000080 +#define GLX_SAMPLE_BUFFERS_BIT_SGIX 0x00000100 +#define GLX_MAX_PBUFFER_WIDTH_SGIX 0x8016 +#define GLX_MAX_PBUFFER_HEIGHT_SGIX 0x8017 +#define GLX_MAX_PBUFFER_PIXELS_SGIX 0x8018 +#define GLX_OPTIMAL_PBUFFER_WIDTH_SGIX 0x8019 +#define GLX_OPTIMAL_PBUFFER_HEIGHT_SGIX 0x801A +#define GLX_PRESERVED_CONTENTS_SGIX 0x801B +#define GLX_LARGEST_PBUFFER_SGIX 0x801C +#define GLX_WIDTH_SGIX 0x801D +#define GLX_HEIGHT_SGIX 0x801E +#define GLX_EVENT_MASK_SGIX 0x801F +#define GLX_DAMAGED_SGIX 0x8020 +#define GLX_SAVED_SGIX 0x8021 +#define GLX_WINDOW_SGIX 0x8022 +#define GLX_PBUFFER_SGIX 0x8023 +#endif + +#ifndef GLX_SGI_cushion +#endif + +#ifndef GLX_SGIX_video_resize +#define GLX_SYNC_FRAME_SGIX 0x00000000 +#define GLX_SYNC_SWAP_SGIX 0x00000001 +#endif + +#ifndef GLX_SGIX_dmbuffer +#define GLX_DIGITAL_MEDIA_PBUFFER_SGIX 0x8024 +#endif + +#ifndef GLX_SGIX_swap_group +#endif + +#ifndef GLX_SGIX_swap_barrier +#endif + +#ifndef GLX_SGIS_blended_overlay +#define GLX_BLENDED_RGBA_SGIS 0x8025 +#endif + +#ifndef GLX_SGIS_shared_multisample +#define GLX_MULTISAMPLE_SUB_RECT_WIDTH_SGIS 0x8026 +#define GLX_MULTISAMPLE_SUB_RECT_HEIGHT_SGIS 0x8027 +#endif + +#ifndef GLX_SUN_get_transparent_index +#endif + +#ifndef GLX_3DFX_multisample +#define GLX_SAMPLE_BUFFERS_3DFX 0x8050 +#define GLX_SAMPLES_3DFX 0x8051 +#endif + +#ifndef GLX_MESA_copy_sub_buffer +#endif + +#ifndef GLX_MESA_pixmap_colormap +#endif + +#ifndef GLX_MESA_release_buffers +#endif + +#ifndef GLX_MESA_set_3dfx_mode +#define GLX_3DFX_WINDOW_MODE_MESA 0x1 +#define GLX_3DFX_FULLSCREEN_MODE_MESA 0x2 +#endif + +#ifndef GLX_SGIX_visual_select_group +#define GLX_VISUAL_SELECT_GROUP_SGIX 0x8028 +#endif + +#ifndef GLX_OML_swap_method +#define GLX_SWAP_METHOD_OML 0x8060 +#define GLX_SWAP_EXCHANGE_OML 0x8061 +#define GLX_SWAP_COPY_OML 0x8062 +#define GLX_SWAP_UNDEFINED_OML 0x8063 +#endif + +#ifndef GLX_OML_sync_control +#endif + +#ifndef GLX_NV_float_buffer +#define GLX_FLOAT_COMPONENTS_NV 0x20B0 +#endif + +#ifndef GLX_SGIX_hyperpipe +#define GLX_HYPERPIPE_PIPE_NAME_LENGTH_SGIX 80 +#define GLX_BAD_HYPERPIPE_CONFIG_SGIX 91 +#define GLX_BAD_HYPERPIPE_SGIX 92 +#define GLX_HYPERPIPE_DISPLAY_PIPE_SGIX 0x00000001 +#define GLX_HYPERPIPE_RENDER_PIPE_SGIX 0x00000002 +#define GLX_PIPE_RECT_SGIX 0x00000001 +#define GLX_PIPE_RECT_LIMITS_SGIX 0x00000002 +#define GLX_HYPERPIPE_STEREO_SGIX 0x00000003 +#define GLX_HYPERPIPE_PIXEL_AVERAGE_SGIX 0x00000004 +#define GLX_HYPERPIPE_ID_SGIX 0x8030 +#endif + +#ifndef GLX_MESA_agp_offset +#endif + +#ifndef GLX_EXT_fbconfig_packed_float +#define GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT 0x20B1 +#define GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT 0x00000008 +#endif + +#ifndef GLX_EXT_framebuffer_sRGB +#define GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT 0x20B2 +#endif + +#ifndef GLX_EXT_texture_from_pixmap +#define GLX_TEXTURE_1D_BIT_EXT 0x00000001 +#define GLX_TEXTURE_2D_BIT_EXT 0x00000002 +#define GLX_TEXTURE_RECTANGLE_BIT_EXT 0x00000004 +#define GLX_BIND_TO_TEXTURE_RGB_EXT 0x20D0 +#define GLX_BIND_TO_TEXTURE_RGBA_EXT 0x20D1 +#define GLX_BIND_TO_MIPMAP_TEXTURE_EXT 0x20D2 +#define GLX_BIND_TO_TEXTURE_TARGETS_EXT 0x20D3 +#define GLX_Y_INVERTED_EXT 0x20D4 +#define GLX_TEXTURE_FORMAT_EXT 0x20D5 +#define GLX_TEXTURE_TARGET_EXT 0x20D6 +#define GLX_MIPMAP_TEXTURE_EXT 0x20D7 +#define GLX_TEXTURE_FORMAT_NONE_EXT 0x20D8 +#define GLX_TEXTURE_FORMAT_RGB_EXT 0x20D9 +#define GLX_TEXTURE_FORMAT_RGBA_EXT 0x20DA +#define GLX_TEXTURE_1D_EXT 0x20DB +#define GLX_TEXTURE_2D_EXT 0x20DC +#define GLX_TEXTURE_RECTANGLE_EXT 0x20DD +#define GLX_FRONT_LEFT_EXT 0x20DE +#define GLX_FRONT_RIGHT_EXT 0x20DF +#define GLX_BACK_LEFT_EXT 0x20E0 +#define GLX_BACK_RIGHT_EXT 0x20E1 +#define GLX_FRONT_EXT GLX_FRONT_LEFT_EXT +#define GLX_BACK_EXT GLX_BACK_LEFT_EXT +#define GLX_AUX0_EXT 0x20E2 +#define GLX_AUX1_EXT 0x20E3 +#define GLX_AUX2_EXT 0x20E4 +#define GLX_AUX3_EXT 0x20E5 +#define GLX_AUX4_EXT 0x20E6 +#define GLX_AUX5_EXT 0x20E7 +#define GLX_AUX6_EXT 0x20E8 +#define GLX_AUX7_EXT 0x20E9 +#define GLX_AUX8_EXT 0x20EA +#define GLX_AUX9_EXT 0x20EB +#endif + +#ifndef GLX_NV_present_video +#define GLX_NUM_VIDEO_SLOTS_NV 0x20F0 +#endif + +#ifndef GLX_NV_video_out +#define GLX_VIDEO_OUT_COLOR_NV 0x20C3 +#define GLX_VIDEO_OUT_ALPHA_NV 0x20C4 +#define GLX_VIDEO_OUT_DEPTH_NV 0x20C5 +#define GLX_VIDEO_OUT_COLOR_AND_ALPHA_NV 0x20C6 +#define GLX_VIDEO_OUT_COLOR_AND_DEPTH_NV 0x20C7 +#define GLX_VIDEO_OUT_FRAME_NV 0x20C8 +#define GLX_VIDEO_OUT_FIELD_1_NV 0x20C9 +#define GLX_VIDEO_OUT_FIELD_2_NV 0x20CA +#define GLX_VIDEO_OUT_STACKED_FIELDS_1_2_NV 0x20CB +#define GLX_VIDEO_OUT_STACKED_FIELDS_2_1_NV 0x20CC +#endif + +#ifndef GLX_NV_swap_group +#endif + +#ifndef GLX_NV_video_capture +#define GLX_DEVICE_ID_NV 0x20CD +#define GLX_UNIQUE_ID_NV 0x20CE +#define GLX_NUM_VIDEO_CAPTURE_SLOTS_NV 0x20CF +#endif + +#ifndef GLX_EXT_swap_control +#define GLX_SWAP_INTERVAL_EXT 0x20F1 +#define GLX_MAX_SWAP_INTERVAL_EXT 0x20F2 +#endif + +#ifndef GLX_NV_copy_image +#endif + +#ifndef GLX_INTEL_swap_event +#define GLX_BUFFER_SWAP_COMPLETE_INTEL_MASK 0x04000000 +#define GLX_EXCHANGE_COMPLETE_INTEL 0x8180 +#define GLX_COPY_COMPLETE_INTEL 0x8181 +#define GLX_FLIP_COMPLETE_INTEL 0x8182 +#endif + +#ifndef GLX_NV_multisample_coverage +#define GLX_COVERAGE_SAMPLES_NV 100001 +#define GLX_COLOR_SAMPLES_NV 0x20B3 +#endif + +#ifndef GLX_AMD_gpu_association +#define GLX_GPU_VENDOR_AMD 0x1F00 +#define GLX_GPU_RENDERER_STRING_AMD 0x1F01 +#define GLX_GPU_OPENGL_VERSION_STRING_AMD 0x1F02 +#define GLX_GPU_FASTEST_TARGET_GPUS_AMD 0x21A2 +#define GLX_GPU_RAM_AMD 0x21A3 +#define GLX_GPU_CLOCK_AMD 0x21A4 +#define GLX_GPU_NUM_PIPES_AMD 0x21A5 +#define GLX_GPU_NUM_SIMD_AMD 0x21A6 +#define GLX_GPU_NUM_RB_AMD 0x21A7 +#define GLX_GPU_NUM_SPI_AMD 0x21A8 +#endif + +#ifndef GLX_EXT_create_context_es2_profile +#define GLX_CONTEXT_ES2_PROFILE_BIT_EXT 0x00000004 +#endif + + +/*************************************************************/ + +#ifndef GLX_ARB_get_proc_address +typedef void (*__GLXextFuncPtr)(void); +#endif + +#ifndef GLX_SGIX_video_source +typedef XID GLXVideoSourceSGIX; +#endif + +#ifndef GLX_SGIX_fbconfig +typedef XID GLXFBConfigIDSGIX; +typedef struct __GLXFBConfigRec *GLXFBConfigSGIX; +#endif + +#ifndef GLX_SGIX_pbuffer +typedef XID GLXPbufferSGIX; +typedef struct { + int type; + unsigned long serial; /* # of last request processed by server */ + Bool send_event; /* true if this came for SendEvent request */ + Display *display; /* display the event was read from */ + GLXDrawable drawable; /* i.d. of Drawable */ + int event_type; /* GLX_DAMAGED_SGIX or GLX_SAVED_SGIX */ + int draw_type; /* GLX_WINDOW_SGIX or GLX_PBUFFER_SGIX */ + unsigned int mask; /* mask indicating which buffers are affected*/ + int x, y; + int width, height; + int count; /* if nonzero, at least this many more */ +} GLXBufferClobberEventSGIX; +#endif + +#ifndef GLX_NV_video_output +typedef unsigned int GLXVideoDeviceNV; +#endif + +#ifndef GLX_NV_video_capture +typedef XID GLXVideoCaptureDeviceNV; +#endif + +#ifndef GLEXT_64_TYPES_DEFINED +/* This code block is duplicated in glext.h, so must be protected */ +#define GLEXT_64_TYPES_DEFINED +/* Define int32_t, int64_t, and uint64_t types for UST/MSC */ +/* (as used in the GLX_OML_sync_control extension). */ +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L +#include +#elif defined(__sun__) || defined(__digital__) +#include +#if defined(__STDC__) +#if defined(__arch64__) || defined(_LP64) +typedef long int int64_t; +typedef unsigned long int uint64_t; +#else +typedef long long int int64_t; +typedef unsigned long long int uint64_t; +#endif /* __arch64__ */ +#endif /* __STDC__ */ +#elif defined( __VMS ) || defined(__sgi) +#include +#elif defined(__SCO__) || defined(__USLC__) +#include +#elif defined(__UNIXOS2__) || defined(__SOL64__) +typedef long int int32_t; +typedef long long int int64_t; +typedef unsigned long long int uint64_t; +#elif defined(_WIN32) && defined(__GNUC__) +#include +#elif defined(_WIN32) +typedef __int32 int32_t; +typedef __int64 int64_t; +typedef unsigned __int64 uint64_t; +#else +#include /* Fallback option */ +#endif +#endif + +#ifndef GLX_VERSION_1_3 +#define GLX_VERSION_1_3 1 +#ifdef GLX_GLXEXT_PROTOTYPES +extern GLXFBConfig * glXGetFBConfigs (Display *dpy, int screen, int *nelements); +extern GLXFBConfig * glXChooseFBConfig (Display *dpy, int screen, const int *attrib_list, int *nelements); +extern int glXGetFBConfigAttrib (Display *dpy, GLXFBConfig config, int attribute, int *value); +extern XVisualInfo * glXGetVisualFromFBConfig (Display *dpy, GLXFBConfig config); +extern GLXWindow glXCreateWindow (Display *dpy, GLXFBConfig config, Window win, const int *attrib_list); +extern void glXDestroyWindow (Display *dpy, GLXWindow win); +extern GLXPixmap glXCreatePixmap (Display *dpy, GLXFBConfig config, Pixmap pixmap, const int *attrib_list); +extern void glXDestroyPixmap (Display *dpy, GLXPixmap pixmap); +extern GLXPbuffer glXCreatePbuffer (Display *dpy, GLXFBConfig config, const int *attrib_list); +extern void glXDestroyPbuffer (Display *dpy, GLXPbuffer pbuf); +extern void glXQueryDrawable (Display *dpy, GLXDrawable draw, int attribute, unsigned int *value); +extern GLXContext glXCreateNewContext (Display *dpy, GLXFBConfig config, int render_type, GLXContext share_list, Bool direct); +extern Bool glXMakeContextCurrent (Display *dpy, GLXDrawable draw, GLXDrawable read, GLXContext ctx); +extern GLXDrawable glXGetCurrentReadDrawable (void); +extern Display * glXGetCurrentDisplay (void); +extern int glXQueryContext (Display *dpy, GLXContext ctx, int attribute, int *value); +extern void glXSelectEvent (Display *dpy, GLXDrawable draw, unsigned long event_mask); +extern void glXGetSelectedEvent (Display *dpy, GLXDrawable draw, unsigned long *event_mask); +#endif /* GLX_GLXEXT_PROTOTYPES */ +typedef GLXFBConfig * ( * PFNGLXGETFBCONFIGSPROC) (Display *dpy, int screen, int *nelements); +typedef GLXFBConfig * ( * PFNGLXCHOOSEFBCONFIGPROC) (Display *dpy, int screen, const int *attrib_list, int *nelements); +typedef int ( * PFNGLXGETFBCONFIGATTRIBPROC) (Display *dpy, GLXFBConfig config, int attribute, int *value); +typedef XVisualInfo * ( * PFNGLXGETVISUALFROMFBCONFIGPROC) (Display *dpy, GLXFBConfig config); +typedef GLXWindow ( * PFNGLXCREATEWINDOWPROC) (Display *dpy, GLXFBConfig config, Window win, const int *attrib_list); +typedef void ( * PFNGLXDESTROYWINDOWPROC) (Display *dpy, GLXWindow win); +typedef GLXPixmap ( * PFNGLXCREATEPIXMAPPROC) (Display *dpy, GLXFBConfig config, Pixmap pixmap, const int *attrib_list); +typedef void ( * PFNGLXDESTROYPIXMAPPROC) (Display *dpy, GLXPixmap pixmap); +typedef GLXPbuffer ( * PFNGLXCREATEPBUFFERPROC) (Display *dpy, GLXFBConfig config, const int *attrib_list); +typedef void ( * PFNGLXDESTROYPBUFFERPROC) (Display *dpy, GLXPbuffer pbuf); +typedef void ( * PFNGLXQUERYDRAWABLEPROC) (Display *dpy, GLXDrawable draw, int attribute, unsigned int *value); +typedef GLXContext ( * PFNGLXCREATENEWCONTEXTPROC) (Display *dpy, GLXFBConfig config, int render_type, GLXContext share_list, Bool direct); +typedef Bool ( * PFNGLXMAKECONTEXTCURRENTPROC) (Display *dpy, GLXDrawable draw, GLXDrawable read, GLXContext ctx); +typedef GLXDrawable ( * PFNGLXGETCURRENTREADDRAWABLEPROC) (void); +typedef Display * ( * PFNGLXGETCURRENTDISPLAYPROC) (void); +typedef int ( * PFNGLXQUERYCONTEXTPROC) (Display *dpy, GLXContext ctx, int attribute, int *value); +typedef void ( * PFNGLXSELECTEVENTPROC) (Display *dpy, GLXDrawable draw, unsigned long event_mask); +typedef void ( * PFNGLXGETSELECTEDEVENTPROC) (Display *dpy, GLXDrawable draw, unsigned long *event_mask); +#endif + +#ifndef GLX_VERSION_1_4 +#define GLX_VERSION_1_4 1 +#ifdef GLX_GLXEXT_PROTOTYPES +extern __GLXextFuncPtr glXGetProcAddress (const GLubyte *procName); +#endif /* GLX_GLXEXT_PROTOTYPES */ +typedef __GLXextFuncPtr ( * PFNGLXGETPROCADDRESSPROC) (const GLubyte *procName); +#endif + +#ifndef GLX_ARB_get_proc_address +#define GLX_ARB_get_proc_address 1 +#ifdef GLX_GLXEXT_PROTOTYPES +extern __GLXextFuncPtr glXGetProcAddressARB (const GLubyte *procName); +#endif /* GLX_GLXEXT_PROTOTYPES */ +typedef __GLXextFuncPtr ( * PFNGLXGETPROCADDRESSARBPROC) (const GLubyte *procName); +#endif + +#ifndef GLX_ARB_multisample +#define GLX_ARB_multisample 1 +#endif + +#ifndef GLX_ARB_fbconfig_float +#define GLX_ARB_fbconfig_float 1 +#endif + +#ifndef GLX_ARB_framebuffer_sRGB +#define GLX_ARB_framebuffer_sRGB 1 +#endif + +#ifndef GLX_ARB_create_context +#define GLX_ARB_create_context 1 +#ifdef GLX_GLXEXT_PROTOTYPES +extern GLXContext glXCreateContextAttribsARB (Display *dpy, GLXFBConfig config, GLXContext share_context, Bool direct, const int *attrib_list); +#endif /* GLX_GLXEXT_PROTOTYPES */ +typedef GLXContext ( * PFNGLXCREATECONTEXTATTRIBSARBPROC) (Display *dpy, GLXFBConfig config, GLXContext share_context, Bool direct, const int *attrib_list); +#endif + +#ifndef GLX_ARB_create_context_profile +#define GLX_ARB_create_context_profile 1 +#endif + +#ifndef GLX_ARB_create_context_robustness +#define GLX_ARB_create_context_robustness 1 +#endif + +#ifndef GLX_SGIS_multisample +#define GLX_SGIS_multisample 1 +#endif + +#ifndef GLX_EXT_visual_info +#define GLX_EXT_visual_info 1 +#endif + +#ifndef GLX_SGI_swap_control +#define GLX_SGI_swap_control 1 +#ifdef GLX_GLXEXT_PROTOTYPES +extern int glXSwapIntervalSGI (int interval); +#endif /* GLX_GLXEXT_PROTOTYPES */ +typedef int ( * PFNGLXSWAPINTERVALSGIPROC) (int interval); +#endif + +#ifndef GLX_SGI_video_sync +#define GLX_SGI_video_sync 1 +#ifdef GLX_GLXEXT_PROTOTYPES +extern int glXGetVideoSyncSGI (unsigned int *count); +extern int glXWaitVideoSyncSGI (int divisor, int remainder, unsigned int *count); +#endif /* GLX_GLXEXT_PROTOTYPES */ +typedef int ( * PFNGLXGETVIDEOSYNCSGIPROC) (unsigned int *count); +typedef int ( * PFNGLXWAITVIDEOSYNCSGIPROC) (int divisor, int remainder, unsigned int *count); +#endif + +#ifndef GLX_SGI_make_current_read +#define GLX_SGI_make_current_read 1 +#ifdef GLX_GLXEXT_PROTOTYPES +extern Bool glXMakeCurrentReadSGI (Display *dpy, GLXDrawable draw, GLXDrawable read, GLXContext ctx); +extern GLXDrawable glXGetCurrentReadDrawableSGI (void); +#endif /* GLX_GLXEXT_PROTOTYPES */ +typedef Bool ( * PFNGLXMAKECURRENTREADSGIPROC) (Display *dpy, GLXDrawable draw, GLXDrawable read, GLXContext ctx); +typedef GLXDrawable ( * PFNGLXGETCURRENTREADDRAWABLESGIPROC) (void); +#endif + +#ifndef GLX_SGIX_video_source +#define GLX_SGIX_video_source 1 +#ifdef _VL_H +#ifdef GLX_GLXEXT_PROTOTYPES +extern GLXVideoSourceSGIX glXCreateGLXVideoSourceSGIX (Display *display, int screen, VLServer server, VLPath path, int nodeClass, VLNode drainNode); +extern void glXDestroyGLXVideoSourceSGIX (Display *dpy, GLXVideoSourceSGIX glxvideosource); +#endif /* GLX_GLXEXT_PROTOTYPES */ +typedef GLXVideoSourceSGIX ( * PFNGLXCREATEGLXVIDEOSOURCESGIXPROC) (Display *display, int screen, VLServer server, VLPath path, int nodeClass, VLNode drainNode); +typedef void ( * PFNGLXDESTROYGLXVIDEOSOURCESGIXPROC) (Display *dpy, GLXVideoSourceSGIX glxvideosource); +#endif /* _VL_H */ +#endif + +#ifndef GLX_EXT_visual_rating +#define GLX_EXT_visual_rating 1 +#endif + +#ifndef GLX_EXT_import_context +#define GLX_EXT_import_context 1 +#ifdef GLX_GLXEXT_PROTOTYPES +extern Display * glXGetCurrentDisplayEXT (void); +extern int glXQueryContextInfoEXT (Display *dpy, GLXContext context, int attribute, int *value); +extern GLXContextID glXGetContextIDEXT (const GLXContext context); +extern GLXContext glXImportContextEXT (Display *dpy, GLXContextID contextID); +extern void glXFreeContextEXT (Display *dpy, GLXContext context); +#endif /* GLX_GLXEXT_PROTOTYPES */ +typedef Display * ( * PFNGLXGETCURRENTDISPLAYEXTPROC) (void); +typedef int ( * PFNGLXQUERYCONTEXTINFOEXTPROC) (Display *dpy, GLXContext context, int attribute, int *value); +typedef GLXContextID ( * PFNGLXGETCONTEXTIDEXTPROC) (const GLXContext context); +typedef GLXContext ( * PFNGLXIMPORTCONTEXTEXTPROC) (Display *dpy, GLXContextID contextID); +typedef void ( * PFNGLXFREECONTEXTEXTPROC) (Display *dpy, GLXContext context); +#endif + +#ifndef GLX_SGIX_fbconfig +#define GLX_SGIX_fbconfig 1 +#ifdef GLX_GLXEXT_PROTOTYPES +extern int glXGetFBConfigAttribSGIX (Display *dpy, GLXFBConfigSGIX config, int attribute, int *value); +extern GLXFBConfigSGIX * glXChooseFBConfigSGIX (Display *dpy, int screen, int *attrib_list, int *nelements); +extern GLXPixmap glXCreateGLXPixmapWithConfigSGIX (Display *dpy, GLXFBConfigSGIX config, Pixmap pixmap); +extern GLXContext glXCreateContextWithConfigSGIX (Display *dpy, GLXFBConfigSGIX config, int render_type, GLXContext share_list, Bool direct); +extern XVisualInfo * glXGetVisualFromFBConfigSGIX (Display *dpy, GLXFBConfigSGIX config); +extern GLXFBConfigSGIX glXGetFBConfigFromVisualSGIX (Display *dpy, XVisualInfo *vis); +#endif /* GLX_GLXEXT_PROTOTYPES */ +typedef int ( * PFNGLXGETFBCONFIGATTRIBSGIXPROC) (Display *dpy, GLXFBConfigSGIX config, int attribute, int *value); +typedef GLXFBConfigSGIX * ( * PFNGLXCHOOSEFBCONFIGSGIXPROC) (Display *dpy, int screen, int *attrib_list, int *nelements); +typedef GLXPixmap ( * PFNGLXCREATEGLXPIXMAPWITHCONFIGSGIXPROC) (Display *dpy, GLXFBConfigSGIX config, Pixmap pixmap); +typedef GLXContext ( * PFNGLXCREATECONTEXTWITHCONFIGSGIXPROC) (Display *dpy, GLXFBConfigSGIX config, int render_type, GLXContext share_list, Bool direct); +typedef XVisualInfo * ( * PFNGLXGETVISUALFROMFBCONFIGSGIXPROC) (Display *dpy, GLXFBConfigSGIX config); +typedef GLXFBConfigSGIX ( * PFNGLXGETFBCONFIGFROMVISUALSGIXPROC) (Display *dpy, XVisualInfo *vis); +#endif + +#ifndef GLX_SGIX_pbuffer +#define GLX_SGIX_pbuffer 1 +#ifdef GLX_GLXEXT_PROTOTYPES +extern GLXPbufferSGIX glXCreateGLXPbufferSGIX (Display *dpy, GLXFBConfigSGIX config, unsigned int width, unsigned int height, int *attrib_list); +extern void glXDestroyGLXPbufferSGIX (Display *dpy, GLXPbufferSGIX pbuf); +extern int glXQueryGLXPbufferSGIX (Display *dpy, GLXPbufferSGIX pbuf, int attribute, unsigned int *value); +extern void glXSelectEventSGIX (Display *dpy, GLXDrawable drawable, unsigned long mask); +extern void glXGetSelectedEventSGIX (Display *dpy, GLXDrawable drawable, unsigned long *mask); +#endif /* GLX_GLXEXT_PROTOTYPES */ +typedef GLXPbufferSGIX ( * PFNGLXCREATEGLXPBUFFERSGIXPROC) (Display *dpy, GLXFBConfigSGIX config, unsigned int width, unsigned int height, int *attrib_list); +typedef void ( * PFNGLXDESTROYGLXPBUFFERSGIXPROC) (Display *dpy, GLXPbufferSGIX pbuf); +typedef int ( * PFNGLXQUERYGLXPBUFFERSGIXPROC) (Display *dpy, GLXPbufferSGIX pbuf, int attribute, unsigned int *value); +typedef void ( * PFNGLXSELECTEVENTSGIXPROC) (Display *dpy, GLXDrawable drawable, unsigned long mask); +typedef void ( * PFNGLXGETSELECTEDEVENTSGIXPROC) (Display *dpy, GLXDrawable drawable, unsigned long *mask); +#endif + +#ifndef GLX_SGI_cushion +#define GLX_SGI_cushion 1 +#ifdef GLX_GLXEXT_PROTOTYPES +extern void glXCushionSGI (Display *dpy, Window window, float cushion); +#endif /* GLX_GLXEXT_PROTOTYPES */ +typedef void ( * PFNGLXCUSHIONSGIPROC) (Display *dpy, Window window, float cushion); +#endif + +#ifndef GLX_SGIX_video_resize +#define GLX_SGIX_video_resize 1 +#ifdef GLX_GLXEXT_PROTOTYPES +extern int glXBindChannelToWindowSGIX (Display *display, int screen, int channel, Window window); +extern int glXChannelRectSGIX (Display *display, int screen, int channel, int x, int y, int w, int h); +extern int glXQueryChannelRectSGIX (Display *display, int screen, int channel, int *dx, int *dy, int *dw, int *dh); +extern int glXQueryChannelDeltasSGIX (Display *display, int screen, int channel, int *x, int *y, int *w, int *h); +extern int glXChannelRectSyncSGIX (Display *display, int screen, int channel, GLenum synctype); +#endif /* GLX_GLXEXT_PROTOTYPES */ +typedef int ( * PFNGLXBINDCHANNELTOWINDOWSGIXPROC) (Display *display, int screen, int channel, Window window); +typedef int ( * PFNGLXCHANNELRECTSGIXPROC) (Display *display, int screen, int channel, int x, int y, int w, int h); +typedef int ( * PFNGLXQUERYCHANNELRECTSGIXPROC) (Display *display, int screen, int channel, int *dx, int *dy, int *dw, int *dh); +typedef int ( * PFNGLXQUERYCHANNELDELTASSGIXPROC) (Display *display, int screen, int channel, int *x, int *y, int *w, int *h); +typedef int ( * PFNGLXCHANNELRECTSYNCSGIXPROC) (Display *display, int screen, int channel, GLenum synctype); +#endif + +#ifndef GLX_SGIX_dmbuffer +#define GLX_SGIX_dmbuffer 1 +#ifdef _DM_BUFFER_H_ +#ifdef GLX_GLXEXT_PROTOTYPES +extern Bool glXAssociateDMPbufferSGIX (Display *dpy, GLXPbufferSGIX pbuffer, DMparams *params, DMbuffer dmbuffer); +#endif /* GLX_GLXEXT_PROTOTYPES */ +typedef Bool ( * PFNGLXASSOCIATEDMPBUFFERSGIXPROC) (Display *dpy, GLXPbufferSGIX pbuffer, DMparams *params, DMbuffer dmbuffer); +#endif /* _DM_BUFFER_H_ */ +#endif + +#ifndef GLX_SGIX_swap_group +#define GLX_SGIX_swap_group 1 +#ifdef GLX_GLXEXT_PROTOTYPES +extern void glXJoinSwapGroupSGIX (Display *dpy, GLXDrawable drawable, GLXDrawable member); +#endif /* GLX_GLXEXT_PROTOTYPES */ +typedef void ( * PFNGLXJOINSWAPGROUPSGIXPROC) (Display *dpy, GLXDrawable drawable, GLXDrawable member); +#endif + +#ifndef GLX_SGIX_swap_barrier +#define GLX_SGIX_swap_barrier 1 +#ifdef GLX_GLXEXT_PROTOTYPES +extern void glXBindSwapBarrierSGIX (Display *dpy, GLXDrawable drawable, int barrier); +extern Bool glXQueryMaxSwapBarriersSGIX (Display *dpy, int screen, int *max); +#endif /* GLX_GLXEXT_PROTOTYPES */ +typedef void ( * PFNGLXBINDSWAPBARRIERSGIXPROC) (Display *dpy, GLXDrawable drawable, int barrier); +typedef Bool ( * PFNGLXQUERYMAXSWAPBARRIERSSGIXPROC) (Display *dpy, int screen, int *max); +#endif + +#ifndef GLX_SUN_get_transparent_index +#define GLX_SUN_get_transparent_index 1 +#ifdef GLX_GLXEXT_PROTOTYPES +extern Status glXGetTransparentIndexSUN (Display *dpy, Window overlay, Window underlay, long *pTransparentIndex); +#endif /* GLX_GLXEXT_PROTOTYPES */ +typedef Status ( * PFNGLXGETTRANSPARENTINDEXSUNPROC) (Display *dpy, Window overlay, Window underlay, long *pTransparentIndex); +#endif + +#ifndef GLX_MESA_copy_sub_buffer +#define GLX_MESA_copy_sub_buffer 1 +#ifdef GLX_GLXEXT_PROTOTYPES +extern void glXCopySubBufferMESA (Display *dpy, GLXDrawable drawable, int x, int y, int width, int height); +#endif /* GLX_GLXEXT_PROTOTYPES */ +typedef void ( * PFNGLXCOPYSUBBUFFERMESAPROC) (Display *dpy, GLXDrawable drawable, int x, int y, int width, int height); +#endif + +#ifndef GLX_MESA_pixmap_colormap +#define GLX_MESA_pixmap_colormap 1 +#ifdef GLX_GLXEXT_PROTOTYPES +extern GLXPixmap glXCreateGLXPixmapMESA (Display *dpy, XVisualInfo *visual, Pixmap pixmap, Colormap cmap); +#endif /* GLX_GLXEXT_PROTOTYPES */ +typedef GLXPixmap ( * PFNGLXCREATEGLXPIXMAPMESAPROC) (Display *dpy, XVisualInfo *visual, Pixmap pixmap, Colormap cmap); +#endif + +#ifndef GLX_MESA_release_buffers +#define GLX_MESA_release_buffers 1 +#ifdef GLX_GLXEXT_PROTOTYPES +extern Bool glXReleaseBuffersMESA (Display *dpy, GLXDrawable drawable); +#endif /* GLX_GLXEXT_PROTOTYPES */ +typedef Bool ( * PFNGLXRELEASEBUFFERSMESAPROC) (Display *dpy, GLXDrawable drawable); +#endif + +#ifndef GLX_MESA_set_3dfx_mode +#define GLX_MESA_set_3dfx_mode 1 +#ifdef GLX_GLXEXT_PROTOTYPES +extern Bool glXSet3DfxModeMESA (int mode); +#endif /* GLX_GLXEXT_PROTOTYPES */ +typedef Bool ( * PFNGLXSET3DFXMODEMESAPROC) (int mode); +#endif + +#ifndef GLX_SGIX_visual_select_group +#define GLX_SGIX_visual_select_group 1 +#endif + +#ifndef GLX_OML_swap_method +#define GLX_OML_swap_method 1 +#endif + +#ifndef GLX_OML_sync_control +#define GLX_OML_sync_control 1 +#ifdef GLX_GLXEXT_PROTOTYPES +extern Bool glXGetSyncValuesOML (Display *dpy, GLXDrawable drawable, int64_t *ust, int64_t *msc, int64_t *sbc); +extern Bool glXGetMscRateOML (Display *dpy, GLXDrawable drawable, int32_t *numerator, int32_t *denominator); +extern int64_t glXSwapBuffersMscOML (Display *dpy, GLXDrawable drawable, int64_t target_msc, int64_t divisor, int64_t remainder); +extern Bool glXWaitForMscOML (Display *dpy, GLXDrawable drawable, int64_t target_msc, int64_t divisor, int64_t remainder, int64_t *ust, int64_t *msc, int64_t *sbc); +extern Bool glXWaitForSbcOML (Display *dpy, GLXDrawable drawable, int64_t target_sbc, int64_t *ust, int64_t *msc, int64_t *sbc); +#endif /* GLX_GLXEXT_PROTOTYPES */ +typedef Bool ( * PFNGLXGETSYNCVALUESOMLPROC) (Display *dpy, GLXDrawable drawable, int64_t *ust, int64_t *msc, int64_t *sbc); +typedef Bool ( * PFNGLXGETMSCRATEOMLPROC) (Display *dpy, GLXDrawable drawable, int32_t *numerator, int32_t *denominator); +typedef int64_t ( * PFNGLXSWAPBUFFERSMSCOMLPROC) (Display *dpy, GLXDrawable drawable, int64_t target_msc, int64_t divisor, int64_t remainder); +typedef Bool ( * PFNGLXWAITFORMSCOMLPROC) (Display *dpy, GLXDrawable drawable, int64_t target_msc, int64_t divisor, int64_t remainder, int64_t *ust, int64_t *msc, int64_t *sbc); +typedef Bool ( * PFNGLXWAITFORSBCOMLPROC) (Display *dpy, GLXDrawable drawable, int64_t target_sbc, int64_t *ust, int64_t *msc, int64_t *sbc); +#endif + +#ifndef GLX_NV_float_buffer +#define GLX_NV_float_buffer 1 +#endif + +#ifndef GLX_SGIX_hyperpipe +#define GLX_SGIX_hyperpipe 1 + +typedef struct { + char pipeName[GLX_HYPERPIPE_PIPE_NAME_LENGTH_SGIX]; + int networkId; +} GLXHyperpipeNetworkSGIX; + +typedef struct { + char pipeName[GLX_HYPERPIPE_PIPE_NAME_LENGTH_SGIX]; + int channel; + unsigned int + participationType; + int timeSlice; +} GLXHyperpipeConfigSGIX; + +typedef struct { + char pipeName[GLX_HYPERPIPE_PIPE_NAME_LENGTH_SGIX]; + int srcXOrigin, srcYOrigin, srcWidth, srcHeight; + int destXOrigin, destYOrigin, destWidth, destHeight; +} GLXPipeRect; + +typedef struct { + char pipeName[GLX_HYPERPIPE_PIPE_NAME_LENGTH_SGIX]; + int XOrigin, YOrigin, maxHeight, maxWidth; +} GLXPipeRectLimits; + +#ifdef GLX_GLXEXT_PROTOTYPES +extern GLXHyperpipeNetworkSGIX * glXQueryHyperpipeNetworkSGIX (Display *dpy, int *npipes); +extern int glXHyperpipeConfigSGIX (Display *dpy, int networkId, int npipes, GLXHyperpipeConfigSGIX *cfg, int *hpId); +extern GLXHyperpipeConfigSGIX * glXQueryHyperpipeConfigSGIX (Display *dpy, int hpId, int *npipes); +extern int glXDestroyHyperpipeConfigSGIX (Display *dpy, int hpId); +extern int glXBindHyperpipeSGIX (Display *dpy, int hpId); +extern int glXQueryHyperpipeBestAttribSGIX (Display *dpy, int timeSlice, int attrib, int size, void *attribList, void *returnAttribList); +extern int glXHyperpipeAttribSGIX (Display *dpy, int timeSlice, int attrib, int size, void *attribList); +extern int glXQueryHyperpipeAttribSGIX (Display *dpy, int timeSlice, int attrib, int size, void *returnAttribList); +#endif /* GLX_GLXEXT_PROTOTYPES */ +typedef GLXHyperpipeNetworkSGIX * ( * PFNGLXQUERYHYPERPIPENETWORKSGIXPROC) (Display *dpy, int *npipes); +typedef int ( * PFNGLXHYPERPIPECONFIGSGIXPROC) (Display *dpy, int networkId, int npipes, GLXHyperpipeConfigSGIX *cfg, int *hpId); +typedef GLXHyperpipeConfigSGIX * ( * PFNGLXQUERYHYPERPIPECONFIGSGIXPROC) (Display *dpy, int hpId, int *npipes); +typedef int ( * PFNGLXDESTROYHYPERPIPECONFIGSGIXPROC) (Display *dpy, int hpId); +typedef int ( * PFNGLXBINDHYPERPIPESGIXPROC) (Display *dpy, int hpId); +typedef int ( * PFNGLXQUERYHYPERPIPEBESTATTRIBSGIXPROC) (Display *dpy, int timeSlice, int attrib, int size, void *attribList, void *returnAttribList); +typedef int ( * PFNGLXHYPERPIPEATTRIBSGIXPROC) (Display *dpy, int timeSlice, int attrib, int size, void *attribList); +typedef int ( * PFNGLXQUERYHYPERPIPEATTRIBSGIXPROC) (Display *dpy, int timeSlice, int attrib, int size, void *returnAttribList); +#endif + +#ifndef GLX_MESA_agp_offset +#define GLX_MESA_agp_offset 1 +#ifdef GLX_GLXEXT_PROTOTYPES +extern unsigned int glXGetAGPOffsetMESA (const void *pointer); +#endif /* GLX_GLXEXT_PROTOTYPES */ +typedef unsigned int ( * PFNGLXGETAGPOFFSETMESAPROC) (const void *pointer); +#endif + +#ifndef GLX_EXT_fbconfig_packed_float +#define GLX_EXT_fbconfig_packed_float 1 +#endif + +#ifndef GLX_EXT_framebuffer_sRGB +#define GLX_EXT_framebuffer_sRGB 1 +#endif + +#ifndef GLX_EXT_texture_from_pixmap +#define GLX_EXT_texture_from_pixmap 1 +#ifdef GLX_GLXEXT_PROTOTYPES +extern void glXBindTexImageEXT (Display *dpy, GLXDrawable drawable, int buffer, const int *attrib_list); +extern void glXReleaseTexImageEXT (Display *dpy, GLXDrawable drawable, int buffer); +#endif /* GLX_GLXEXT_PROTOTYPES */ +typedef void ( * PFNGLXBINDTEXIMAGEEXTPROC) (Display *dpy, GLXDrawable drawable, int buffer, const int *attrib_list); +typedef void ( * PFNGLXRELEASETEXIMAGEEXTPROC) (Display *dpy, GLXDrawable drawable, int buffer); +#endif + +#ifndef GLX_NV_present_video +#define GLX_NV_present_video 1 +#ifdef GLX_GLXEXT_PROTOTYPES +extern unsigned int * glXEnumerateVideoDevicesNV (Display *dpy, int screen, int *nelements); +extern int glXBindVideoDeviceNV (Display *dpy, unsigned int video_slot, unsigned int video_device, const int *attrib_list); +#endif /* GLX_GLXEXT_PROTOTYPES */ +typedef unsigned int * ( * PFNGLXENUMERATEVIDEODEVICESNVPROC) (Display *dpy, int screen, int *nelements); +typedef int ( * PFNGLXBINDVIDEODEVICENVPROC) (Display *dpy, unsigned int video_slot, unsigned int video_device, const int *attrib_list); +#endif + +#ifndef GLX_NV_video_output +#define GLX_NV_video_output 1 +#ifdef GLX_GLXEXT_PROTOTYPES +extern int glXGetVideoDeviceNV (Display *dpy, int screen, int numVideoDevices, GLXVideoDeviceNV *pVideoDevice); +extern int glXReleaseVideoDeviceNV (Display *dpy, int screen, GLXVideoDeviceNV VideoDevice); +extern int glXBindVideoImageNV (Display *dpy, GLXVideoDeviceNV VideoDevice, GLXPbuffer pbuf, int iVideoBuffer); +extern int glXReleaseVideoImageNV (Display *dpy, GLXPbuffer pbuf); +extern int glXSendPbufferToVideoNV (Display *dpy, GLXPbuffer pbuf, int iBufferType, unsigned long *pulCounterPbuffer, GLboolean bBlock); +extern int glXGetVideoInfoNV (Display *dpy, int screen, GLXVideoDeviceNV VideoDevice, unsigned long *pulCounterOutputPbuffer, unsigned long *pulCounterOutputVideo); +#endif /* GLX_GLXEXT_PROTOTYPES */ +typedef int ( * PFNGLXGETVIDEODEVICENVPROC) (Display *dpy, int screen, int numVideoDevices, GLXVideoDeviceNV *pVideoDevice); +typedef int ( * PFNGLXRELEASEVIDEODEVICENVPROC) (Display *dpy, int screen, GLXVideoDeviceNV VideoDevice); +typedef int ( * PFNGLXBINDVIDEOIMAGENVPROC) (Display *dpy, GLXVideoDeviceNV VideoDevice, GLXPbuffer pbuf, int iVideoBuffer); +typedef int ( * PFNGLXRELEASEVIDEOIMAGENVPROC) (Display *dpy, GLXPbuffer pbuf); +typedef int ( * PFNGLXSENDPBUFFERTOVIDEONVPROC) (Display *dpy, GLXPbuffer pbuf, int iBufferType, unsigned long *pulCounterPbuffer, GLboolean bBlock); +typedef int ( * PFNGLXGETVIDEOINFONVPROC) (Display *dpy, int screen, GLXVideoDeviceNV VideoDevice, unsigned long *pulCounterOutputPbuffer, unsigned long *pulCounterOutputVideo); +#endif + +#ifndef GLX_NV_swap_group +#define GLX_NV_swap_group 1 +#ifdef GLX_GLXEXT_PROTOTYPES +extern Bool glXJoinSwapGroupNV (Display *dpy, GLXDrawable drawable, GLuint group); +extern Bool glXBindSwapBarrierNV (Display *dpy, GLuint group, GLuint barrier); +extern Bool glXQuerySwapGroupNV (Display *dpy, GLXDrawable drawable, GLuint *group, GLuint *barrier); +extern Bool glXQueryMaxSwapGroupsNV (Display *dpy, int screen, GLuint *maxGroups, GLuint *maxBarriers); +extern Bool glXQueryFrameCountNV (Display *dpy, int screen, GLuint *count); +extern Bool glXResetFrameCountNV (Display *dpy, int screen); +#endif /* GLX_GLXEXT_PROTOTYPES */ +typedef Bool ( * PFNGLXJOINSWAPGROUPNVPROC) (Display *dpy, GLXDrawable drawable, GLuint group); +typedef Bool ( * PFNGLXBINDSWAPBARRIERNVPROC) (Display *dpy, GLuint group, GLuint barrier); +typedef Bool ( * PFNGLXQUERYSWAPGROUPNVPROC) (Display *dpy, GLXDrawable drawable, GLuint *group, GLuint *barrier); +typedef Bool ( * PFNGLXQUERYMAXSWAPGROUPSNVPROC) (Display *dpy, int screen, GLuint *maxGroups, GLuint *maxBarriers); +typedef Bool ( * PFNGLXQUERYFRAMECOUNTNVPROC) (Display *dpy, int screen, GLuint *count); +typedef Bool ( * PFNGLXRESETFRAMECOUNTNVPROC) (Display *dpy, int screen); +#endif + +#ifndef GLX_NV_video_capture +#define GLX_NV_video_capture 1 +#ifdef GLX_GLXEXT_PROTOTYPES +extern int glXBindVideoCaptureDeviceNV (Display *dpy, unsigned int video_capture_slot, GLXVideoCaptureDeviceNV device); +extern GLXVideoCaptureDeviceNV * glXEnumerateVideoCaptureDevicesNV (Display *dpy, int screen, int *nelements); +extern void glXLockVideoCaptureDeviceNV (Display *dpy, GLXVideoCaptureDeviceNV device); +extern int glXQueryVideoCaptureDeviceNV (Display *dpy, GLXVideoCaptureDeviceNV device, int attribute, int *value); +extern void glXReleaseVideoCaptureDeviceNV (Display *dpy, GLXVideoCaptureDeviceNV device); +#endif /* GLX_GLXEXT_PROTOTYPES */ +typedef int ( * PFNGLXBINDVIDEOCAPTUREDEVICENVPROC) (Display *dpy, unsigned int video_capture_slot, GLXVideoCaptureDeviceNV device); +typedef GLXVideoCaptureDeviceNV * ( * PFNGLXENUMERATEVIDEOCAPTUREDEVICESNVPROC) (Display *dpy, int screen, int *nelements); +typedef void ( * PFNGLXLOCKVIDEOCAPTUREDEVICENVPROC) (Display *dpy, GLXVideoCaptureDeviceNV device); +typedef int ( * PFNGLXQUERYVIDEOCAPTUREDEVICENVPROC) (Display *dpy, GLXVideoCaptureDeviceNV device, int attribute, int *value); +typedef void ( * PFNGLXRELEASEVIDEOCAPTUREDEVICENVPROC) (Display *dpy, GLXVideoCaptureDeviceNV device); +#endif + +#ifndef GLX_EXT_swap_control +#define GLX_EXT_swap_control 1 +#ifdef GLX_GLXEXT_PROTOTYPES +extern int glXSwapIntervalEXT (Display *dpy, GLXDrawable drawable, int interval); +#endif /* GLX_GLXEXT_PROTOTYPES */ +typedef int ( * PFNGLXSWAPINTERVALEXTPROC) (Display *dpy, GLXDrawable drawable, int interval); +#endif + +#ifndef GLX_NV_copy_image +#define GLX_NV_copy_image 1 +#ifdef GLX_GLXEXT_PROTOTYPES +extern void glXCopyImageSubDataNV (Display *dpy, GLXContext srcCtx, GLuint srcName, GLenum srcTarget, GLint srcLevel, GLint srcX, GLint srcY, GLint srcZ, GLXContext dstCtx, GLuint dstName, GLenum dstTarget, GLint dstLevel, GLint dstX, GLint dstY, GLint dstZ, GLsizei width, GLsizei height, GLsizei depth); +#endif /* GLX_GLXEXT_PROTOTYPES */ +typedef void ( * PFNGLXCOPYIMAGESUBDATANVPROC) (Display *dpy, GLXContext srcCtx, GLuint srcName, GLenum srcTarget, GLint srcLevel, GLint srcX, GLint srcY, GLint srcZ, GLXContext dstCtx, GLuint dstName, GLenum dstTarget, GLint dstLevel, GLint dstX, GLint dstY, GLint dstZ, GLsizei width, GLsizei height, GLsizei depth); +#endif + +#ifndef GLX_INTEL_swap_event +#define GLX_INTEL_swap_event 1 +#endif + +#ifndef GLX_NV_multisample_coverage +#define GLX_NV_multisample_coverage 1 +#endif + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/Projects/Android/jni/SupportLibs/gl4es/include/GL/internal/dri_interface.h b/Projects/Android/jni/SupportLibs/gl4es/include/GL/internal/dri_interface.h new file mode 100644 index 0000000..9ee039b --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/include/GL/internal/dri_interface.h @@ -0,0 +1,862 @@ +/* + * Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas. + * Copyright 2007-2008 Red Hat, Inc. + * (C) Copyright IBM Corporation 2004 + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * on the rights to use, copy, modify, merge, publish, distribute, sub + * license, and/or sell copies of the Software, and to permit persons to whom + * the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL + * THE COPYRIGHT HOLDERS AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + * USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/** + * \file dri_interface.h + * + * This file contains all the types and functions that define the interface + * between a DRI driver and driver loader. Currently, the most common driver + * loader is the XFree86 libGL.so. However, other loaders do exist, and in + * the future the server-side libglx.a will also be a loader. + * + * \author Kevin E. Martin + * \author Ian Romanick + * \author Kristian Høgsberg + */ + +#ifndef DRI_INTERFACE_H +#define DRI_INTERFACE_H + +/* For archs with no drm.h */ +#if defined(__APPLE__) || defined(__CYGWIN__) || defined(__GNU__) +#ifndef __NOT_HAVE_DRM_H +#define __NOT_HAVE_DRM_H +#endif +#endif + +#ifndef __NOT_HAVE_DRM_H +#include +#else +typedef unsigned int drm_context_t; +typedef unsigned int drm_drawable_t; +typedef struct drm_clip_rect drm_clip_rect_t; +#endif + +/** + * \name DRI interface structures + * + * The following structures define the interface between the GLX client + * side library and the DRI (direct rendering infrastructure). + */ +/*@{*/ +typedef struct __DRIdisplayRec __DRIdisplay; +typedef struct __DRIscreenRec __DRIscreen; +typedef struct __DRIcontextRec __DRIcontext; +typedef struct __DRIdrawableRec __DRIdrawable; +typedef struct __DRIconfigRec __DRIconfig; +typedef struct __DRIframebufferRec __DRIframebuffer; +typedef struct __DRIversionRec __DRIversion; + +typedef struct __DRIcoreExtensionRec __DRIcoreExtension; +typedef struct __DRIextensionRec __DRIextension; +typedef struct __DRIcopySubBufferExtensionRec __DRIcopySubBufferExtension; +typedef struct __DRIswapControlExtensionRec __DRIswapControlExtension; +typedef struct __DRIframeTrackingExtensionRec __DRIframeTrackingExtension; +typedef struct __DRImediaStreamCounterExtensionRec __DRImediaStreamCounterExtension; +typedef struct __DRItexOffsetExtensionRec __DRItexOffsetExtension; +typedef struct __DRItexBufferExtensionRec __DRItexBufferExtension; +typedef struct __DRIlegacyExtensionRec __DRIlegacyExtension; +typedef struct __DRIswrastExtensionRec __DRIswrastExtension; +typedef struct __DRIbufferRec __DRIbuffer; +typedef struct __DRIdri2ExtensionRec __DRIdri2Extension; +typedef struct __DRIdri2LoaderExtensionRec __DRIdri2LoaderExtension; +typedef struct __DRI2flushExtensionRec __DRI2flushExtension; + +/*@}*/ + + +/** + * Extension struct. Drivers 'inherit' from this struct by embedding + * it as the first element in the extension struct. + * + * We never break API in for a DRI extension. If we need to change + * the way things work in a non-backwards compatible manner, we + * introduce a new extension. During a transition period, we can + * leave both the old and the new extension in the driver, which + * allows us to move to the new interface without having to update the + * loader(s) in lock step. + * + * However, we can add entry points to an extension over time as long + * as we don't break the old ones. As we add entry points to an + * extension, we increase the version number. The corresponding + * #define can be used to guard code that accesses the new entry + * points at compile time and the version field in the extension + * struct can be used at run-time to determine how to use the + * extension. + */ +struct __DRIextensionRec { + const char *name; + int version; +}; + +/** + * The first set of extension are the screen extensions, returned by + * __DRIcore::getExtensions(). This entry point will return a list of + * extensions and the loader can use the ones it knows about by + * casting them to more specific extensions and advertising any GLX + * extensions the DRI extensions enables. + */ + +/** + * Used by drivers to indicate support for setting the read drawable. + */ +#define __DRI_READ_DRAWABLE "DRI_ReadDrawable" +#define __DRI_READ_DRAWABLE_VERSION 1 + +/** + * Used by drivers that implement the GLX_MESA_copy_sub_buffer extension. + */ +#define __DRI_COPY_SUB_BUFFER "DRI_CopySubBuffer" +#define __DRI_COPY_SUB_BUFFER_VERSION 1 +struct __DRIcopySubBufferExtensionRec { + __DRIextension base; + void (*copySubBuffer)(__DRIdrawable *drawable, int x, int y, int w, int h); +}; + +/** + * Used by drivers that implement the GLX_SGI_swap_control or + * GLX_MESA_swap_control extension. + */ +#define __DRI_SWAP_CONTROL "DRI_SwapControl" +#define __DRI_SWAP_CONTROL_VERSION 1 +struct __DRIswapControlExtensionRec { + __DRIextension base; + void (*setSwapInterval)(__DRIdrawable *drawable, unsigned int inteval); + unsigned int (*getSwapInterval)(__DRIdrawable *drawable); +}; + +/** + * Used by drivers that implement the GLX_MESA_swap_frame_usage extension. + */ +#define __DRI_FRAME_TRACKING "DRI_FrameTracking" +#define __DRI_FRAME_TRACKING_VERSION 1 +struct __DRIframeTrackingExtensionRec { + __DRIextension base; + + /** + * Enable or disable frame usage tracking. + * + * \since Internal API version 20030317. + */ + int (*frameTracking)(__DRIdrawable *drawable, GLboolean enable); + + /** + * Retrieve frame usage information. + * + * \since Internal API version 20030317. + */ + int (*queryFrameTracking)(__DRIdrawable *drawable, + int64_t * sbc, int64_t * missedFrames, + float * lastMissedUsage, float * usage); +}; + + +/** + * Used by drivers that implement the GLX_SGI_video_sync extension. + */ +#define __DRI_MEDIA_STREAM_COUNTER "DRI_MediaStreamCounter" +#define __DRI_MEDIA_STREAM_COUNTER_VERSION 1 +struct __DRImediaStreamCounterExtensionRec { + __DRIextension base; + + /** + * Wait for the MSC to equal target_msc, or, if that has already passed, + * the next time (MSC % divisor) is equal to remainder. If divisor is + * zero, the function will return as soon as MSC is greater than or equal + * to target_msc. + */ + int (*waitForMSC)(__DRIdrawable *drawable, + int64_t target_msc, int64_t divisor, int64_t remainder, + int64_t * msc, int64_t * sbc); + + /** + * Get the number of vertical refreshes since some point in time before + * this function was first called (i.e., system start up). + */ + int (*getDrawableMSC)(__DRIscreen *screen, __DRIdrawable *drawable, + int64_t *msc); +}; + + +#define __DRI_TEX_OFFSET "DRI_TexOffset" +#define __DRI_TEX_OFFSET_VERSION 1 +struct __DRItexOffsetExtensionRec { + __DRIextension base; + + /** + * Method to override base texture image with a driver specific 'offset'. + * The depth passed in allows e.g. to ignore the alpha channel of texture + * images where the non-alpha components don't occupy a whole texel. + * + * For GLX_EXT_texture_from_pixmap with AIGLX. + */ + void (*setTexOffset)(__DRIcontext *pDRICtx, GLint texname, + unsigned long long offset, GLint depth, GLuint pitch); +}; + + +/* Valid values for format in the setTexBuffer2 function below. These + * values match the GLX tokens for compatibility reasons, but we + * define them here since the DRI interface can't depend on GLX. */ +#define __DRI_TEXTURE_FORMAT_NONE 0x20D8 +#define __DRI_TEXTURE_FORMAT_RGB 0x20D9 +#define __DRI_TEXTURE_FORMAT_RGBA 0x20DA + +#define __DRI_TEX_BUFFER "DRI_TexBuffer" +#define __DRI_TEX_BUFFER_VERSION 2 +struct __DRItexBufferExtensionRec { + __DRIextension base; + + /** + * Method to override base texture image with the contents of a + * __DRIdrawable. + * + * For GLX_EXT_texture_from_pixmap with AIGLX. Deprecated in favor of + * setTexBuffer2 in version 2 of this interface + */ + void (*setTexBuffer)(__DRIcontext *pDRICtx, + GLint target, + __DRIdrawable *pDraw); + + /** + * Method to override base texture image with the contents of a + * __DRIdrawable, including the required texture format attribute. + * + * For GLX_EXT_texture_from_pixmap with AIGLX. + */ + void (*setTexBuffer2)(__DRIcontext *pDRICtx, + GLint target, + GLint format, + __DRIdrawable *pDraw); +}; + +/** + * Used by drivers that implement DRI2 + */ +#define __DRI2_FLUSH "DRI2_Flush" +#define __DRI2_FLUSH_VERSION 3 +struct __DRI2flushExtensionRec { + __DRIextension base; + void (*flush)(__DRIdrawable *drawable); + + /** + * Ask the driver to call getBuffers/getBuffersWithFormat before + * it starts rendering again. + * + * \param drawable the drawable to invalidate + * + * \since 3 + */ + void (*invalidate)(__DRIdrawable *drawable); +}; + + +/** + * XML document describing the configuration options supported by the + * driver. + */ +extern const char __driConfigOptions[]; + +/*@}*/ + +/** + * The following extensions describe loader features that the DRI + * driver can make use of. Some of these are mandatory, such as the + * getDrawableInfo extension for DRI and the DRI Loader extensions for + * DRI2, while others are optional, and if present allow the driver to + * expose certain features. The loader pass in a NULL terminated + * array of these extensions to the driver in the createNewScreen + * constructor. + */ + +typedef struct __DRIgetDrawableInfoExtensionRec __DRIgetDrawableInfoExtension; +typedef struct __DRIsystemTimeExtensionRec __DRIsystemTimeExtension; +typedef struct __DRIdamageExtensionRec __DRIdamageExtension; +typedef struct __DRIloaderExtensionRec __DRIloaderExtension; +typedef struct __DRIswrastLoaderExtensionRec __DRIswrastLoaderExtension; + + +/** + * Callback to getDrawableInfo protocol + */ +#define __DRI_GET_DRAWABLE_INFO "DRI_GetDrawableInfo" +#define __DRI_GET_DRAWABLE_INFO_VERSION 1 +struct __DRIgetDrawableInfoExtensionRec { + __DRIextension base; + + /** + * This function is used to get information about the position, size, and + * clip rects of a drawable. + */ + GLboolean (* getDrawableInfo) ( __DRIdrawable *drawable, + unsigned int * index, unsigned int * stamp, + int * x, int * y, int * width, int * height, + int * numClipRects, drm_clip_rect_t ** pClipRects, + int * backX, int * backY, + int * numBackClipRects, drm_clip_rect_t ** pBackClipRects, + void *loaderPrivate); +}; + +/** + * Callback to get system time for media stream counter extensions. + */ +#define __DRI_SYSTEM_TIME "DRI_SystemTime" +#define __DRI_SYSTEM_TIME_VERSION 1 +struct __DRIsystemTimeExtensionRec { + __DRIextension base; + + /** + * Get the 64-bit unadjusted system time (UST). + */ + int (*getUST)(int64_t * ust); + + /** + * Get the media stream counter (MSC) rate. + * + * Matching the definition in GLX_OML_sync_control, this function returns + * the rate of the "media stream counter". In practical terms, this is + * the frame refresh rate of the display. + */ + GLboolean (*getMSCRate)(__DRIdrawable *draw, + int32_t * numerator, int32_t * denominator, + void *loaderPrivate); +}; + +/** + * Damage reporting + */ +#define __DRI_DAMAGE "DRI_Damage" +#define __DRI_DAMAGE_VERSION 1 +struct __DRIdamageExtensionRec { + __DRIextension base; + + /** + * Reports areas of the given drawable which have been modified by the + * driver. + * + * \param drawable which the drawing was done to. + * \param rects rectangles affected, with the drawable origin as the + * origin. + * \param x X offset of the drawable within the screen (used in the + * front_buffer case) + * \param y Y offset of the drawable within the screen. + * \param front_buffer boolean flag for whether the drawing to the + * drawable was actually done directly to the front buffer (instead + * of backing storage, for example) + * \param loaderPrivate the data passed in at createNewDrawable time + */ + void (*reportDamage)(__DRIdrawable *draw, + int x, int y, + drm_clip_rect_t *rects, int num_rects, + GLboolean front_buffer, + void *loaderPrivate); +}; + +#define __DRI_SWRAST_IMAGE_OP_DRAW 1 +#define __DRI_SWRAST_IMAGE_OP_CLEAR 2 +#define __DRI_SWRAST_IMAGE_OP_SWAP 3 + +/** + * SWRast Loader extension. + */ +#define __DRI_SWRAST_LOADER "DRI_SWRastLoader" +#define __DRI_SWRAST_LOADER_VERSION 1 +struct __DRIswrastLoaderExtensionRec { + __DRIextension base; + + /* + * Drawable position and size + */ + void (*getDrawableInfo)(__DRIdrawable *drawable, + int *x, int *y, int *width, int *height, + void *loaderPrivate); + + /** + * Put image to drawable + */ + void (*putImage)(__DRIdrawable *drawable, int op, + int x, int y, int width, int height, + char *data, void *loaderPrivate); + + /** + * Get image from readable + */ + void (*getImage)(__DRIdrawable *readable, + int x, int y, int width, int height, + char *data, void *loaderPrivate); +}; + +/** + * Invalidate loader extension. The presence of this extension + * indicates to the DRI driver that the loader will call invalidate in + * the __DRI2_FLUSH extension, whenever the needs to query for new + * buffers. This means that the DRI driver can drop the polling in + * glViewport(). + * + * The extension doesn't provide any functionality, it's only use to + * indicate to the driver that it can use the new semantics. A DRI + * driver can use this to switch between the different semantics or + * just refuse to initialize if this extension isn't present. + */ +#define __DRI_USE_INVALIDATE "DRI_UseInvalidate" +#define __DRI_USE_INVALIDATE_VERSION 1 + +typedef struct __DRIuseInvalidateExtensionRec __DRIuseInvalidateExtension; +struct __DRIuseInvalidateExtensionRec { + __DRIextension base; +}; + +/** + * The remaining extensions describe driver extensions, immediately + * available interfaces provided by the driver. To start using the + * driver, dlsym() for the __DRI_DRIVER_EXTENSIONS symbol and look for + * the extension you need in the array. + */ +#define __DRI_DRIVER_EXTENSIONS "__driDriverExtensions" + +/** + * Tokens for __DRIconfig attribs. A number of attributes defined by + * GLX or EGL standards are not in the table, as they must be provided + * by the loader. For example, FBConfig ID or visual ID, drawable type. + */ + +#define __DRI_ATTRIB_BUFFER_SIZE 1 +#define __DRI_ATTRIB_LEVEL 2 +#define __DRI_ATTRIB_RED_SIZE 3 +#define __DRI_ATTRIB_GREEN_SIZE 4 +#define __DRI_ATTRIB_BLUE_SIZE 5 +#define __DRI_ATTRIB_LUMINANCE_SIZE 6 +#define __DRI_ATTRIB_ALPHA_SIZE 7 +#define __DRI_ATTRIB_ALPHA_MASK_SIZE 8 +#define __DRI_ATTRIB_DEPTH_SIZE 9 +#define __DRI_ATTRIB_STENCIL_SIZE 10 +#define __DRI_ATTRIB_ACCUM_RED_SIZE 11 +#define __DRI_ATTRIB_ACCUM_GREEN_SIZE 12 +#define __DRI_ATTRIB_ACCUM_BLUE_SIZE 13 +#define __DRI_ATTRIB_ACCUM_ALPHA_SIZE 14 +#define __DRI_ATTRIB_SAMPLE_BUFFERS 15 +#define __DRI_ATTRIB_SAMPLES 16 +#define __DRI_ATTRIB_RENDER_TYPE 17 +#define __DRI_ATTRIB_CONFIG_CAVEAT 18 +#define __DRI_ATTRIB_CONFORMANT 19 +#define __DRI_ATTRIB_DOUBLE_BUFFER 20 +#define __DRI_ATTRIB_STEREO 21 +#define __DRI_ATTRIB_AUX_BUFFERS 22 +#define __DRI_ATTRIB_TRANSPARENT_TYPE 23 +#define __DRI_ATTRIB_TRANSPARENT_INDEX_VALUE 24 +#define __DRI_ATTRIB_TRANSPARENT_RED_VALUE 25 +#define __DRI_ATTRIB_TRANSPARENT_GREEN_VALUE 26 +#define __DRI_ATTRIB_TRANSPARENT_BLUE_VALUE 27 +#define __DRI_ATTRIB_TRANSPARENT_ALPHA_VALUE 28 +#define __DRI_ATTRIB_FLOAT_MODE 29 +#define __DRI_ATTRIB_RED_MASK 30 +#define __DRI_ATTRIB_GREEN_MASK 31 +#define __DRI_ATTRIB_BLUE_MASK 32 +#define __DRI_ATTRIB_ALPHA_MASK 33 +#define __DRI_ATTRIB_MAX_PBUFFER_WIDTH 34 +#define __DRI_ATTRIB_MAX_PBUFFER_HEIGHT 35 +#define __DRI_ATTRIB_MAX_PBUFFER_PIXELS 36 +#define __DRI_ATTRIB_OPTIMAL_PBUFFER_WIDTH 37 +#define __DRI_ATTRIB_OPTIMAL_PBUFFER_HEIGHT 38 +#define __DRI_ATTRIB_VISUAL_SELECT_GROUP 39 +#define __DRI_ATTRIB_SWAP_METHOD 40 +#define __DRI_ATTRIB_MAX_SWAP_INTERVAL 41 +#define __DRI_ATTRIB_MIN_SWAP_INTERVAL 42 +#define __DRI_ATTRIB_BIND_TO_TEXTURE_RGB 43 +#define __DRI_ATTRIB_BIND_TO_TEXTURE_RGBA 44 +#define __DRI_ATTRIB_BIND_TO_MIPMAP_TEXTURE 45 +#define __DRI_ATTRIB_BIND_TO_TEXTURE_TARGETS 46 +#define __DRI_ATTRIB_YINVERTED 47 + +/* __DRI_ATTRIB_RENDER_TYPE */ +#define __DRI_ATTRIB_RGBA_BIT 0x01 +#define __DRI_ATTRIB_COLOR_INDEX_BIT 0x02 +#define __DRI_ATTRIB_LUMINANCE_BIT 0x04 + +/* __DRI_ATTRIB_CONFIG_CAVEAT */ +#define __DRI_ATTRIB_SLOW_BIT 0x01 +#define __DRI_ATTRIB_NON_CONFORMANT_CONFIG 0x02 + +/* __DRI_ATTRIB_TRANSPARENT_TYPE */ +#define __DRI_ATTRIB_TRANSPARENT_RGB 0x00 +#define __DRI_ATTRIB_TRANSPARENT_INDEX 0x01 + +/* __DRI_ATTRIB_BIND_TO_TEXTURE_TARGETS */ +#define __DRI_ATTRIB_TEXTURE_1D_BIT 0x01 +#define __DRI_ATTRIB_TEXTURE_2D_BIT 0x02 +#define __DRI_ATTRIB_TEXTURE_RECTANGLE_BIT 0x04 + +/** + * This extension defines the core DRI functionality. + */ +#define __DRI_CORE "DRI_Core" +#define __DRI_CORE_VERSION 1 + +struct __DRIcoreExtensionRec { + __DRIextension base; + + __DRIscreen *(*createNewScreen)(int screen, int fd, + unsigned int sarea_handle, + const __DRIextension **extensions, + const __DRIconfig ***driverConfigs, + void *loaderPrivate); + + void (*destroyScreen)(__DRIscreen *screen); + + const __DRIextension **(*getExtensions)(__DRIscreen *screen); + + int (*getConfigAttrib)(const __DRIconfig *config, + unsigned int attrib, + unsigned int *value); + + int (*indexConfigAttrib)(const __DRIconfig *config, int index, + unsigned int *attrib, unsigned int *value); + + __DRIdrawable *(*createNewDrawable)(__DRIscreen *screen, + const __DRIconfig *config, + unsigned int drawable_id, + unsigned int head, + void *loaderPrivate); + + void (*destroyDrawable)(__DRIdrawable *drawable); + + void (*swapBuffers)(__DRIdrawable *drawable); + + __DRIcontext *(*createNewContext)(__DRIscreen *screen, + const __DRIconfig *config, + __DRIcontext *shared, + void *loaderPrivate); + + int (*copyContext)(__DRIcontext *dest, + __DRIcontext *src, + unsigned long mask); + + void (*destroyContext)(__DRIcontext *context); + + int (*bindContext)(__DRIcontext *ctx, + __DRIdrawable *pdraw, + __DRIdrawable *pread); + + int (*unbindContext)(__DRIcontext *ctx); +}; + +/** + * Stored version of some component (i.e., server-side DRI module, kernel-side + * DRM, etc.). + * + * \todo + * There are several data structures that explicitly store a major version, + * minor version, and patch level. These structures should be modified to + * have a \c __DRIversionRec instead. + */ +struct __DRIversionRec { + int major; /**< Major version number. */ + int minor; /**< Minor version number. */ + int patch; /**< Patch-level. */ +}; + +/** + * Framebuffer information record. Used by libGL to communicate information + * about the framebuffer to the driver's \c __driCreateNewScreen function. + * + * In XFree86, most of this information is derrived from data returned by + * calling \c XF86DRIGetDeviceInfo. + * + * \sa XF86DRIGetDeviceInfo __DRIdisplayRec::createNewScreen + * __driUtilCreateNewScreen CallCreateNewScreen + * + * \bug This structure could be better named. + */ +struct __DRIframebufferRec { + unsigned char *base; /**< Framebuffer base address in the CPU's + * address space. This value is calculated by + * calling \c drmMap on the framebuffer handle + * returned by \c XF86DRIGetDeviceInfo (or a + * similar function). + */ + int size; /**< Framebuffer size, in bytes. */ + int stride; /**< Number of bytes from one line to the next. */ + int width; /**< Pixel width of the framebuffer. */ + int height; /**< Pixel height of the framebuffer. */ + int dev_priv_size; /**< Size of the driver's dev-priv structure. */ + void *dev_priv; /**< Pointer to the driver's dev-priv structure. */ +}; + + +/** + * This extension provides alternative screen, drawable and context + * constructors for legacy DRI functionality. This is used in + * conjunction with the core extension. + */ +#define __DRI_LEGACY "DRI_Legacy" +#define __DRI_LEGACY_VERSION 1 + +struct __DRIlegacyExtensionRec { + __DRIextension base; + + __DRIscreen *(*createNewScreen)(int screen, + const __DRIversion *ddx_version, + const __DRIversion *dri_version, + const __DRIversion *drm_version, + const __DRIframebuffer *frame_buffer, + void *pSAREA, int fd, + const __DRIextension **extensions, + const __DRIconfig ***driver_configs, + void *loaderPrivate); + + __DRIdrawable *(*createNewDrawable)(__DRIscreen *screen, + const __DRIconfig *config, + drm_drawable_t hwDrawable, + int renderType, const int *attrs, + void *loaderPrivate); + + __DRIcontext *(*createNewContext)(__DRIscreen *screen, + const __DRIconfig *config, + int render_type, + __DRIcontext *shared, + drm_context_t hwContext, + void *loaderPrivate); +}; + +/** + * This extension provides alternative screen, drawable and context + * constructors for swrast DRI functionality. This is used in + * conjunction with the core extension. + */ +#define __DRI_SWRAST "DRI_SWRast" +#define __DRI_SWRAST_VERSION 1 + +struct __DRIswrastExtensionRec { + __DRIextension base; + + __DRIscreen *(*createNewScreen)(int screen, + const __DRIextension **extensions, + const __DRIconfig ***driver_configs, + void *loaderPrivate); + + __DRIdrawable *(*createNewDrawable)(__DRIscreen *screen, + const __DRIconfig *config, + void *loaderPrivate); +}; + +/** + * DRI2 Loader extension. + */ +#define __DRI_BUFFER_FRONT_LEFT 0 +#define __DRI_BUFFER_BACK_LEFT 1 +#define __DRI_BUFFER_FRONT_RIGHT 2 +#define __DRI_BUFFER_BACK_RIGHT 3 +#define __DRI_BUFFER_DEPTH 4 +#define __DRI_BUFFER_STENCIL 5 +#define __DRI_BUFFER_ACCUM 6 +#define __DRI_BUFFER_FAKE_FRONT_LEFT 7 +#define __DRI_BUFFER_FAKE_FRONT_RIGHT 8 +#define __DRI_BUFFER_DEPTH_STENCIL 9 /**< Only available with DRI2 1.1 */ + +struct __DRIbufferRec { + unsigned int attachment; + unsigned int name; + unsigned int pitch; + unsigned int cpp; + unsigned int flags; +}; + +#define __DRI_DRI2_LOADER "DRI_DRI2Loader" +#define __DRI_DRI2_LOADER_VERSION 3 +struct __DRIdri2LoaderExtensionRec { + __DRIextension base; + + __DRIbuffer *(*getBuffers)(__DRIdrawable *driDrawable, + int *width, int *height, + unsigned int *attachments, int count, + int *out_count, void *loaderPrivate); + + /** + * Flush pending front-buffer rendering + * + * Any rendering that has been performed to the + * \c __DRI_BUFFER_FAKE_FRONT_LEFT will be flushed to the + * \c __DRI_BUFFER_FRONT_LEFT. + * + * \param driDrawable Drawable whose front-buffer is to be flushed + * \param loaderPrivate Loader's private data that was previously passed + * into __DRIdri2ExtensionRec::createNewDrawable + */ + void (*flushFrontBuffer)(__DRIdrawable *driDrawable, void *loaderPrivate); + + + /** + * Get list of buffers from the server + * + * Gets a list of buffer for the specified set of attachments. Unlike + * \c ::getBuffers, this function takes a list of attachments paired with + * opaque \c unsigned \c int value describing the format of the buffer. + * It is the responsibility of the caller to know what the service that + * allocates the buffers will expect to receive for the format. + * + * \param driDrawable Drawable whose buffers are being queried. + * \param width Output where the width of the buffers is stored. + * \param height Output where the height of the buffers is stored. + * \param attachments List of pairs of attachment ID and opaque format + * requested for the drawable. + * \param count Number of attachment / format pairs stored in + * \c attachments. + * \param loaderPrivate Loader's private data that was previously passed + * into __DRIdri2ExtensionRec::createNewDrawable. + */ + __DRIbuffer *(*getBuffersWithFormat)(__DRIdrawable *driDrawable, + int *width, int *height, + unsigned int *attachments, int count, + int *out_count, void *loaderPrivate); +}; + +/** + * This extension provides alternative screen, drawable and context + * constructors for DRI2. + */ +#define __DRI_DRI2 "DRI_DRI2" +#define __DRI_DRI2_VERSION 2 + +#define __DRI_API_OPENGL 0 +#define __DRI_API_GLES 1 +#define __DRI_API_GLES2 2 + +struct __DRIdri2ExtensionRec { + __DRIextension base; + + __DRIscreen *(*createNewScreen)(int screen, int fd, + const __DRIextension **extensions, + const __DRIconfig ***driver_configs, + void *loaderPrivate); + + __DRIdrawable *(*createNewDrawable)(__DRIscreen *screen, + const __DRIconfig *config, + void *loaderPrivate); + + __DRIcontext *(*createNewContext)(__DRIscreen *screen, + const __DRIconfig *config, + __DRIcontext *shared, + void *loaderPrivate); + + /* Since version 2 */ + unsigned int (*getAPIMask)(__DRIscreen *screen); + + __DRIcontext *(*createNewContextForAPI)(__DRIscreen *screen, + int api, + const __DRIconfig *config, + __DRIcontext *shared, + void *data); +}; + + +/** + * This extension provides functionality to enable various EGLImage + * extensions. + */ +#define __DRI_IMAGE "DRI_IMAGE" +#define __DRI_IMAGE_VERSION 1 + +/** + * These formats correspond to the similarly named MESA_FORMAT_* + * tokens, except in the native endian of the CPU. For example, on + * little endian __DRI_IMAGE_FORMAT_XRGB8888 corresponds to + * MESA_FORMAT_XRGB8888, but MESA_FORMAT_XRGB8888_REV on big endian. + */ +#define __DRI_IMAGE_FORMAT_RGB565 0x1001 +#define __DRI_IMAGE_FORMAT_XRGB8888 0x1002 +#define __DRI_IMAGE_FORMAT_ARGB8888 0x1003 + +#define __DRI_IMAGE_USE_SHARE 0x0001 +#define __DRI_IMAGE_USE_SCANOUT 0x0002 + +/** + * queryImage attributes + */ + +#define __DRI_IMAGE_ATTRIB_STRIDE 0x2000 +#define __DRI_IMAGE_ATTRIB_HANDLE 0x2001 +#define __DRI_IMAGE_ATTRIB_NAME 0x2002 + +typedef struct __DRIimageRec __DRIimage; +typedef struct __DRIimageExtensionRec __DRIimageExtension; +struct __DRIimageExtensionRec { + __DRIextension base; + + __DRIimage *(*createImageFromName)(__DRIscreen *screen, + int width, int height, int format, + int name, int pitch, + void *loaderPrivate); + + __DRIimage *(*createImageFromRenderbuffer)(__DRIcontext *context, + int renderbuffer, + void *loaderPrivate); + + void (*destroyImage)(__DRIimage *image); + + __DRIimage *(*createImage)(__DRIscreen *screen, + int width, int height, int format, + unsigned int use, + void *loaderPrivate); + + GLboolean (*queryImage)(__DRIimage *image, int attrib, int *value); +}; + + +/** + * This extension must be implemented by the loader and passed to the + * driver at screen creation time. The EGLImage entry points in the + * various client APIs take opaque EGLImage handles and use this + * extension to map them to a __DRIimage. At version 1, this + * extensions allows mapping EGLImage pointers to __DRIimage pointers, + * but future versions could support other EGLImage-like, opaque types + * with new lookup functions. + */ +#define __DRI_IMAGE_LOOKUP "DRI_IMAGE_LOOKUP" +#define __DRI_IMAGE_LOOKUP_VERSION 1 + +typedef struct __DRIimageLookupExtensionRec __DRIimageLookupExtension; +struct __DRIimageLookupExtensionRec { + __DRIextension base; + + __DRIimage *(*lookupEGLImage)(__DRIscreen *screen, void *image, + void *loaderPrivate); +}; + +/** + * This extension allows for common DRI2 options + */ +#define __DRI2_CONFIG_QUERY "DRI_CONFIG_QUERY" +#define __DRI2_CONFIG_QUERY_VERSION 1 + +typedef struct __DRI2configQueryExtensionRec __DRI2configQueryExtension; +struct __DRI2configQueryExtensionRec { + __DRIextension base; + + int (*configQueryb)(__DRIscreen *screen, const char *var, GLboolean *val); + int (*configQueryi)(__DRIscreen *screen, const char *var, GLint *val); + int (*configQueryf)(__DRIscreen *screen, const char *var, GLfloat *val); +}; +#endif diff --git a/Projects/Android/jni/SupportLibs/gl4es/include/GLES/egl.h b/Projects/Android/jni/SupportLibs/gl4es/include/GLES/egl.h new file mode 100644 index 0000000..5778e00 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/include/GLES/egl.h @@ -0,0 +1,15 @@ +/* + * Skeleton egl.h to provide compatibility for early GLES 1.0 + * applications. Several early implementations included gl.h + * in egl.h leading applications to include only egl.h + * + * $Revision: 6252 $ on $Date:: 2008-08-06 16:35:08 -0700 #$ + */ + +#ifndef __legacy_egl_h_ +#define __legacy_egl_h_ + +#include +#include + +#endif /* __legacy_egl_h_ */ diff --git a/Projects/Android/jni/SupportLibs/gl4es/include/GLES/gl.h b/Projects/Android/jni/SupportLibs/gl4es/include/GLES/gl.h new file mode 100644 index 0000000..5b8d85a --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/include/GLES/gl.h @@ -0,0 +1,770 @@ +#ifndef __gl_h_ +#define __gl_h_ + +/* $Revision: 10601 $ on $Date:: 2010-03-04 22:15:27 -0800 #$ */ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * This document is licensed under the SGI Free Software B License Version + * 2.0. For details, see http://oss.sgi.com/projects/FreeB/ . + */ + +typedef void GLvoid; +typedef char GLchar; +typedef unsigned int GLenum; +typedef unsigned char GLboolean; +typedef unsigned int GLbitfield; +typedef khronos_int8_t GLbyte; +typedef short GLshort; +typedef int GLint; +typedef int GLsizei; +typedef khronos_uint8_t GLubyte; +typedef unsigned short GLushort; +typedef unsigned int GLuint; +typedef khronos_float_t GLfloat; +typedef khronos_float_t GLclampf; +typedef khronos_int32_t GLfixed; +typedef khronos_int32_t GLclampx; + +typedef khronos_intptr_t GLintptr; +typedef khronos_ssize_t GLsizeiptr; + + +/*************************************************************/ + +/* OpenGL ES core versions */ +#define GL_VERSION_ES_CM_1_0 1 +#define GL_VERSION_ES_CL_1_0 1 +#define GL_VERSION_ES_CM_1_1 1 +#define GL_VERSION_ES_CL_1_1 1 + +/* ClearBufferMask */ +#define GL_DEPTH_BUFFER_BIT 0x00000100 +#define GL_STENCIL_BUFFER_BIT 0x00000400 +#define GL_COLOR_BUFFER_BIT 0x00004000 + +/* Boolean */ +#define GL_FALSE 0 +#define GL_TRUE 1 + +/* BeginMode */ +#define GL_POINTS 0x0000 +#define GL_LINES 0x0001 +#define GL_LINE_LOOP 0x0002 +#define GL_LINE_STRIP 0x0003 +#define GL_TRIANGLES 0x0004 +#define GL_TRIANGLE_STRIP 0x0005 +#define GL_TRIANGLE_FAN 0x0006 + +/* AlphaFunction */ +#define GL_NEVER 0x0200 +#define GL_LESS 0x0201 +#define GL_EQUAL 0x0202 +#define GL_LEQUAL 0x0203 +#define GL_GREATER 0x0204 +#define GL_NOTEQUAL 0x0205 +#define GL_GEQUAL 0x0206 +#define GL_ALWAYS 0x0207 + +/* BlendingFactorDest */ +#define GL_ZERO 0 +#define GL_ONE 1 +#define GL_SRC_COLOR 0x0300 +#define GL_ONE_MINUS_SRC_COLOR 0x0301 +#define GL_SRC_ALPHA 0x0302 +#define GL_ONE_MINUS_SRC_ALPHA 0x0303 +#define GL_DST_ALPHA 0x0304 +#define GL_ONE_MINUS_DST_ALPHA 0x0305 + +/* BlendingFactorSrc */ +/* GL_ZERO */ +/* GL_ONE */ +#define GL_DST_COLOR 0x0306 +#define GL_ONE_MINUS_DST_COLOR 0x0307 +#define GL_SRC_ALPHA_SATURATE 0x0308 +/* GL_SRC_ALPHA */ +/* GL_ONE_MINUS_SRC_ALPHA */ +/* GL_DST_ALPHA */ +/* GL_ONE_MINUS_DST_ALPHA */ + +/* ClipPlaneName */ +#define GL_CLIP_PLANE0 0x3000 +#define GL_CLIP_PLANE1 0x3001 +#define GL_CLIP_PLANE2 0x3002 +#define GL_CLIP_PLANE3 0x3003 +#define GL_CLIP_PLANE4 0x3004 +#define GL_CLIP_PLANE5 0x3005 + +/* ColorMaterialFace */ +/* GL_FRONT_AND_BACK */ + +/* ColorMaterialParameter */ +/* GL_AMBIENT_AND_DIFFUSE */ + +/* ColorPointerType */ +/* GL_UNSIGNED_BYTE */ +/* GL_FLOAT */ +/* GL_FIXED */ + +/* CullFaceMode */ +#define GL_FRONT 0x0404 +#define GL_BACK 0x0405 +#define GL_FRONT_AND_BACK 0x0408 + +/* DepthFunction */ +/* GL_NEVER */ +/* GL_LESS */ +/* GL_EQUAL */ +/* GL_LEQUAL */ +/* GL_GREATER */ +/* GL_NOTEQUAL */ +/* GL_GEQUAL */ +/* GL_ALWAYS */ + +/* EnableCap */ +#define GL_FOG 0x0B60 +#define GL_LIGHTING 0x0B50 +#define GL_TEXTURE_2D 0x0DE1 +#define GL_CULL_FACE 0x0B44 +#define GL_ALPHA_TEST 0x0BC0 +#define GL_BLEND 0x0BE2 +#define GL_COLOR_LOGIC_OP 0x0BF2 +#define GL_DITHER 0x0BD0 +#define GL_STENCIL_TEST 0x0B90 +#define GL_DEPTH_TEST 0x0B71 +/* GL_LIGHT0 */ +/* GL_LIGHT1 */ +/* GL_LIGHT2 */ +/* GL_LIGHT3 */ +/* GL_LIGHT4 */ +/* GL_LIGHT5 */ +/* GL_LIGHT6 */ +/* GL_LIGHT7 */ +#define GL_POINT_SMOOTH 0x0B10 +#define GL_LINE_SMOOTH 0x0B20 +#define GL_SCISSOR_TEST 0x0C11 +#define GL_COLOR_MATERIAL 0x0B57 +#define GL_NORMALIZE 0x0BA1 +#define GL_RESCALE_NORMAL 0x803A +#define GL_POLYGON_OFFSET_FILL 0x8037 +#define GL_VERTEX_ARRAY 0x8074 +#define GL_NORMAL_ARRAY 0x8075 +#define GL_COLOR_ARRAY 0x8076 +#define GL_TEXTURE_COORD_ARRAY 0x8078 +#define GL_MULTISAMPLE 0x809D +#define GL_SAMPLE_ALPHA_TO_COVERAGE 0x809E +#define GL_SAMPLE_ALPHA_TO_ONE 0x809F +#define GL_SAMPLE_COVERAGE 0x80A0 + +/* ErrorCode */ +#define GL_NO_ERROR 0 +#define GL_INVALID_ENUM 0x0500 +#define GL_INVALID_VALUE 0x0501 +#define GL_INVALID_OPERATION 0x0502 +#define GL_STACK_OVERFLOW 0x0503 +#define GL_STACK_UNDERFLOW 0x0504 +#define GL_OUT_OF_MEMORY 0x0505 + +/* FogMode */ +/* GL_LINEAR */ +#define GL_EXP 0x0800 +#define GL_EXP2 0x0801 + +/* FogParameter */ +#define GL_FOG_DENSITY 0x0B62 +#define GL_FOG_START 0x0B63 +#define GL_FOG_END 0x0B64 +#define GL_FOG_MODE 0x0B65 +#define GL_FOG_COLOR 0x0B66 + +/* FrontFaceDirection */ +#define GL_CW 0x0900 +#define GL_CCW 0x0901 + +/* GetPName */ +#define GL_CURRENT_COLOR 0x0B00 +#define GL_CURRENT_NORMAL 0x0B02 +#define GL_CURRENT_TEXTURE_COORDS 0x0B03 +#define GL_POINT_SIZE 0x0B11 +#define GL_POINT_SIZE_MIN 0x8126 +#define GL_POINT_SIZE_MAX 0x8127 +#define GL_POINT_FADE_THRESHOLD_SIZE 0x8128 +#define GL_POINT_DISTANCE_ATTENUATION 0x8129 +#define GL_SMOOTH_POINT_SIZE_RANGE 0x0B12 +#define GL_LINE_WIDTH 0x0B21 +#define GL_SMOOTH_LINE_WIDTH_RANGE 0x0B22 +#define GL_ALIASED_POINT_SIZE_RANGE 0x846D +#define GL_ALIASED_LINE_WIDTH_RANGE 0x846E +#define GL_CULL_FACE_MODE 0x0B45 +#define GL_FRONT_FACE 0x0B46 +#define GL_SHADE_MODEL 0x0B54 +#define GL_DEPTH_RANGE 0x0B70 +#define GL_DEPTH_WRITEMASK 0x0B72 +#define GL_DEPTH_CLEAR_VALUE 0x0B73 +#define GL_DEPTH_FUNC 0x0B74 +#define GL_STENCIL_CLEAR_VALUE 0x0B91 +#define GL_STENCIL_FUNC 0x0B92 +#define GL_STENCIL_VALUE_MASK 0x0B93 +#define GL_STENCIL_FAIL 0x0B94 +#define GL_STENCIL_PASS_DEPTH_FAIL 0x0B95 +#define GL_STENCIL_PASS_DEPTH_PASS 0x0B96 +#define GL_STENCIL_REF 0x0B97 +#define GL_STENCIL_WRITEMASK 0x0B98 +#define GL_MATRIX_MODE 0x0BA0 +#define GL_VIEWPORT 0x0BA2 +#define GL_MODELVIEW_STACK_DEPTH 0x0BA3 +#define GL_PROJECTION_STACK_DEPTH 0x0BA4 +#define GL_TEXTURE_STACK_DEPTH 0x0BA5 +#define GL_MODELVIEW_MATRIX 0x0BA6 +#define GL_PROJECTION_MATRIX 0x0BA7 +#define GL_TEXTURE_MATRIX 0x0BA8 +#define GL_ALPHA_TEST_FUNC 0x0BC1 +#define GL_ALPHA_TEST_REF 0x0BC2 +#define GL_BLEND_DST 0x0BE0 +#define GL_BLEND_SRC 0x0BE1 +#define GL_LOGIC_OP_MODE 0x0BF0 +#define GL_SCISSOR_BOX 0x0C10 +#define GL_SCISSOR_TEST 0x0C11 +#define GL_COLOR_CLEAR_VALUE 0x0C22 +#define GL_COLOR_WRITEMASK 0x0C23 +#define GL_UNPACK_ALIGNMENT 0x0CF5 +#define GL_PACK_ALIGNMENT 0x0D05 +#define GL_MAX_LIGHTS 0x0D31 +#define GL_MAX_CLIP_PLANES 0x0D32 +#define GL_MAX_TEXTURE_SIZE 0x0D33 +#define GL_MAX_MODELVIEW_STACK_DEPTH 0x0D36 +#define GL_MAX_PROJECTION_STACK_DEPTH 0x0D38 +#define GL_MAX_TEXTURE_STACK_DEPTH 0x0D39 +#define GL_MAX_VIEWPORT_DIMS 0x0D3A +#define GL_MAX_TEXTURE_UNITS 0x84E2 +#define GL_SUBPIXEL_BITS 0x0D50 +#define GL_RED_BITS 0x0D52 +#define GL_GREEN_BITS 0x0D53 +#define GL_BLUE_BITS 0x0D54 +#define GL_ALPHA_BITS 0x0D55 +#define GL_DEPTH_BITS 0x0D56 +#define GL_STENCIL_BITS 0x0D57 +#define GL_POLYGON_OFFSET_UNITS 0x2A00 +#define GL_POLYGON_OFFSET_FILL 0x8037 +#define GL_POLYGON_OFFSET_FACTOR 0x8038 +#define GL_TEXTURE_BINDING_2D 0x8069 +#define GL_VERTEX_ARRAY_SIZE 0x807A +#define GL_VERTEX_ARRAY_TYPE 0x807B +#define GL_VERTEX_ARRAY_STRIDE 0x807C +#define GL_NORMAL_ARRAY_TYPE 0x807E +#define GL_NORMAL_ARRAY_STRIDE 0x807F +#define GL_COLOR_ARRAY_SIZE 0x8081 +#define GL_COLOR_ARRAY_TYPE 0x8082 +#define GL_COLOR_ARRAY_STRIDE 0x8083 +#define GL_TEXTURE_COORD_ARRAY_SIZE 0x8088 +#define GL_TEXTURE_COORD_ARRAY_TYPE 0x8089 +#define GL_TEXTURE_COORD_ARRAY_STRIDE 0x808A +#define GL_VERTEX_ARRAY_POINTER 0x808E +#define GL_NORMAL_ARRAY_POINTER 0x808F +#define GL_COLOR_ARRAY_POINTER 0x8090 +#define GL_TEXTURE_COORD_ARRAY_POINTER 0x8092 +#define GL_SAMPLE_BUFFERS 0x80A8 +#define GL_SAMPLES 0x80A9 +#define GL_SAMPLE_COVERAGE_VALUE 0x80AA +#define GL_SAMPLE_COVERAGE_INVERT 0x80AB + +/* GetTextureParameter */ +/* GL_TEXTURE_MAG_FILTER */ +/* GL_TEXTURE_MIN_FILTER */ +/* GL_TEXTURE_WRAP_S */ +/* GL_TEXTURE_WRAP_T */ + +#define GL_NUM_COMPRESSED_TEXTURE_FORMATS 0x86A2 +#define GL_COMPRESSED_TEXTURE_FORMATS 0x86A3 + +/* HintMode */ +#define GL_DONT_CARE 0x1100 +#define GL_FASTEST 0x1101 +#define GL_NICEST 0x1102 + +/* HintTarget */ +#define GL_PERSPECTIVE_CORRECTION_HINT 0x0C50 +#define GL_POINT_SMOOTH_HINT 0x0C51 +#define GL_LINE_SMOOTH_HINT 0x0C52 +#define GL_FOG_HINT 0x0C54 +#define GL_GENERATE_MIPMAP_HINT 0x8192 + +/* LightModelParameter */ +#define GL_LIGHT_MODEL_AMBIENT 0x0B53 +#define GL_LIGHT_MODEL_TWO_SIDE 0x0B52 + +/* LightParameter */ +#define GL_AMBIENT 0x1200 +#define GL_DIFFUSE 0x1201 +#define GL_SPECULAR 0x1202 +#define GL_POSITION 0x1203 +#define GL_SPOT_DIRECTION 0x1204 +#define GL_SPOT_EXPONENT 0x1205 +#define GL_SPOT_CUTOFF 0x1206 +#define GL_CONSTANT_ATTENUATION 0x1207 +#define GL_LINEAR_ATTENUATION 0x1208 +#define GL_QUADRATIC_ATTENUATION 0x1209 + +/* DataType */ +#define GL_BYTE 0x1400 +#define GL_UNSIGNED_BYTE 0x1401 +#define GL_SHORT 0x1402 +#define GL_UNSIGNED_SHORT 0x1403 +#define GL_FLOAT 0x1406 +#define GL_FIXED 0x140C + +/* LogicOp */ +#define GL_CLEAR 0x1500 +#define GL_AND 0x1501 +#define GL_AND_REVERSE 0x1502 +#define GL_COPY 0x1503 +#define GL_AND_INVERTED 0x1504 +#define GL_NOOP 0x1505 +#define GL_XOR 0x1506 +#define GL_OR 0x1507 +#define GL_NOR 0x1508 +#define GL_EQUIV 0x1509 +#define GL_INVERT 0x150A +#define GL_OR_REVERSE 0x150B +#define GL_COPY_INVERTED 0x150C +#define GL_OR_INVERTED 0x150D +#define GL_NAND 0x150E +#define GL_SET 0x150F + +/* MaterialFace */ +/* GL_FRONT_AND_BACK */ + +/* MaterialParameter */ +#define GL_EMISSION 0x1600 +#define GL_SHININESS 0x1601 +#define GL_AMBIENT_AND_DIFFUSE 0x1602 +/* GL_AMBIENT */ +/* GL_DIFFUSE */ +/* GL_SPECULAR */ + +/* MatrixMode */ +#define GL_MODELVIEW 0x1700 +#define GL_PROJECTION 0x1701 +#define GL_TEXTURE 0x1702 + +/* NormalPointerType */ +/* GL_BYTE */ +/* GL_SHORT */ +/* GL_FLOAT */ +/* GL_FIXED */ + +/* PixelFormat */ +#define GL_ALPHA 0x1906 +#define GL_RGB 0x1907 +#define GL_RGBA 0x1908 +#define GL_LUMINANCE 0x1909 +#define GL_LUMINANCE_ALPHA 0x190A + +/* PixelStoreParameter */ +#define GL_UNPACK_ALIGNMENT 0x0CF5 +#define GL_PACK_ALIGNMENT 0x0D05 + +/* PixelType */ +/* GL_UNSIGNED_BYTE */ +#define GL_UNSIGNED_SHORT_4_4_4_4 0x8033 +#define GL_UNSIGNED_SHORT_5_5_5_1 0x8034 +#define GL_UNSIGNED_SHORT_5_6_5 0x8363 + +/* ShadingModel */ +#define GL_FLAT 0x1D00 +#define GL_SMOOTH 0x1D01 + +/* StencilFunction */ +/* GL_NEVER */ +/* GL_LESS */ +/* GL_EQUAL */ +/* GL_LEQUAL */ +/* GL_GREATER */ +/* GL_NOTEQUAL */ +/* GL_GEQUAL */ +/* GL_ALWAYS */ + +/* StencilOp */ +/* GL_ZERO */ +#define GL_KEEP 0x1E00 +#define GL_REPLACE 0x1E01 +#define GL_INCR 0x1E02 +#define GL_DECR 0x1E03 +/* GL_INVERT */ + +/* StringName */ +#define GL_VENDOR 0x1F00 +#define GL_RENDERER 0x1F01 +#define GL_VERSION 0x1F02 +#define GL_EXTENSIONS 0x1F03 + +/* TexCoordPointerType */ +/* GL_SHORT */ +/* GL_FLOAT */ +/* GL_FIXED */ +/* GL_BYTE */ + +/* TextureEnvMode */ +#define GL_MODULATE 0x2100 +#define GL_DECAL 0x2101 +/* GL_BLEND */ +#define GL_ADD 0x0104 +/* GL_REPLACE */ + +/* TextureEnvParameter */ +#define GL_TEXTURE_ENV_MODE 0x2200 +#define GL_TEXTURE_ENV_COLOR 0x2201 + +/* TextureEnvTarget */ +#define GL_TEXTURE_ENV 0x2300 + +/* TextureMagFilter */ +#define GL_NEAREST 0x2600 +#define GL_LINEAR 0x2601 + +/* TextureMinFilter */ +/* GL_NEAREST */ +/* GL_LINEAR */ +#define GL_NEAREST_MIPMAP_NEAREST 0x2700 +#define GL_LINEAR_MIPMAP_NEAREST 0x2701 +#define GL_NEAREST_MIPMAP_LINEAR 0x2702 +#define GL_LINEAR_MIPMAP_LINEAR 0x2703 + +/* TextureParameterName */ +#define GL_TEXTURE_MAG_FILTER 0x2800 +#define GL_TEXTURE_MIN_FILTER 0x2801 +#define GL_TEXTURE_WRAP_S 0x2802 +#define GL_TEXTURE_WRAP_T 0x2803 +#define GL_GENERATE_MIPMAP 0x8191 + +/* TextureTarget */ +/* GL_TEXTURE_2D */ + +/* TextureUnit */ +#define GL_TEXTURE0 0x84C0 +#define GL_TEXTURE1 0x84C1 +#define GL_TEXTURE2 0x84C2 +#define GL_TEXTURE3 0x84C3 +#define GL_TEXTURE4 0x84C4 +#define GL_TEXTURE5 0x84C5 +#define GL_TEXTURE6 0x84C6 +#define GL_TEXTURE7 0x84C7 +#define GL_TEXTURE8 0x84C8 +#define GL_TEXTURE9 0x84C9 +#define GL_TEXTURE10 0x84CA +#define GL_TEXTURE11 0x84CB +#define GL_TEXTURE12 0x84CC +#define GL_TEXTURE13 0x84CD +#define GL_TEXTURE14 0x84CE +#define GL_TEXTURE15 0x84CF +#define GL_TEXTURE16 0x84D0 +#define GL_TEXTURE17 0x84D1 +#define GL_TEXTURE18 0x84D2 +#define GL_TEXTURE19 0x84D3 +#define GL_TEXTURE20 0x84D4 +#define GL_TEXTURE21 0x84D5 +#define GL_TEXTURE22 0x84D6 +#define GL_TEXTURE23 0x84D7 +#define GL_TEXTURE24 0x84D8 +#define GL_TEXTURE25 0x84D9 +#define GL_TEXTURE26 0x84DA +#define GL_TEXTURE27 0x84DB +#define GL_TEXTURE28 0x84DC +#define GL_TEXTURE29 0x84DD +#define GL_TEXTURE30 0x84DE +#define GL_TEXTURE31 0x84DF +#define GL_ACTIVE_TEXTURE 0x84E0 +#define GL_CLIENT_ACTIVE_TEXTURE 0x84E1 + +/* TextureWrapMode */ +#define GL_REPEAT 0x2901 +#define GL_CLAMP_TO_EDGE 0x812F + +/* VertexPointerType */ +/* GL_SHORT */ +/* GL_FLOAT */ +/* GL_FIXED */ +/* GL_BYTE */ + +/* LightName */ +#define GL_LIGHT0 0x4000 +#define GL_LIGHT1 0x4001 +#define GL_LIGHT2 0x4002 +#define GL_LIGHT3 0x4003 +#define GL_LIGHT4 0x4004 +#define GL_LIGHT5 0x4005 +#define GL_LIGHT6 0x4006 +#define GL_LIGHT7 0x4007 + +/* Buffer Objects */ +#define GL_ARRAY_BUFFER 0x8892 +#define GL_ELEMENT_ARRAY_BUFFER 0x8893 + +#define GL_ARRAY_BUFFER_BINDING 0x8894 +#define GL_ELEMENT_ARRAY_BUFFER_BINDING 0x8895 +#define GL_VERTEX_ARRAY_BUFFER_BINDING 0x8896 +#define GL_NORMAL_ARRAY_BUFFER_BINDING 0x8897 +#define GL_COLOR_ARRAY_BUFFER_BINDING 0x8898 +#define GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING 0x889A + +#define GL_STATIC_DRAW 0x88E4 +#define GL_DYNAMIC_DRAW 0x88E8 + +#define GL_BUFFER_SIZE 0x8764 +#define GL_BUFFER_USAGE 0x8765 + +/* Texture combine + dot3 */ +#define GL_SUBTRACT 0x84E7 +#define GL_COMBINE 0x8570 +#define GL_COMBINE_RGB 0x8571 +#define GL_COMBINE_ALPHA 0x8572 +#define GL_RGB_SCALE 0x8573 +#define GL_ADD_SIGNED 0x8574 +#define GL_INTERPOLATE 0x8575 +#define GL_CONSTANT 0x8576 +#define GL_PRIMARY_COLOR 0x8577 +#define GL_PREVIOUS 0x8578 +#define GL_OPERAND0_RGB 0x8590 +#define GL_OPERAND1_RGB 0x8591 +#define GL_OPERAND2_RGB 0x8592 +#define GL_OPERAND0_ALPHA 0x8598 +#define GL_OPERAND1_ALPHA 0x8599 +#define GL_OPERAND2_ALPHA 0x859A + +#define GL_ALPHA_SCALE 0x0D1C + +#define GL_SRC0_RGB 0x8580 +#define GL_SRC1_RGB 0x8581 +#define GL_SRC2_RGB 0x8582 +#define GL_SRC0_ALPHA 0x8588 +#define GL_SRC1_ALPHA 0x8589 +#define GL_SRC2_ALPHA 0x858A + +#define GL_DOT3_RGB 0x86AE +#define GL_DOT3_RGBA 0x86AF + +/*------------------------------------------------------------------------* + * required OES extension tokens + *------------------------------------------------------------------------*/ + +/* OES_read_format */ +#ifndef GL_OES_read_format +#define GL_IMPLEMENTATION_COLOR_READ_TYPE_OES 0x8B9A +#define GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES 0x8B9B +#endif + +/* GL_OES_compressed_paletted_texture */ +#ifndef GL_OES_compressed_paletted_texture +#define GL_PALETTE4_RGB8_OES 0x8B90 +#define GL_PALETTE4_RGBA8_OES 0x8B91 +#define GL_PALETTE4_R5_G6_B5_OES 0x8B92 +#define GL_PALETTE4_RGBA4_OES 0x8B93 +#define GL_PALETTE4_RGB5_A1_OES 0x8B94 +#define GL_PALETTE8_RGB8_OES 0x8B95 +#define GL_PALETTE8_RGBA8_OES 0x8B96 +#define GL_PALETTE8_R5_G6_B5_OES 0x8B97 +#define GL_PALETTE8_RGBA4_OES 0x8B98 +#define GL_PALETTE8_RGB5_A1_OES 0x8B99 +#endif + +/* OES_point_size_array */ +#ifndef GL_OES_point_size_array +#define GL_POINT_SIZE_ARRAY_OES 0x8B9C +#define GL_POINT_SIZE_ARRAY_TYPE_OES 0x898A +#define GL_POINT_SIZE_ARRAY_STRIDE_OES 0x898B +#define GL_POINT_SIZE_ARRAY_POINTER_OES 0x898C +#define GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES 0x8B9F +#endif + +/* GL_OES_point_sprite */ +#ifndef GL_OES_point_sprite +#define GL_POINT_SPRITE_OES 0x8861 +#define GL_COORD_REPLACE_OES 0x8862 +#endif + +/*************************************************************/ + +/* Available only in Common profile */ +GL_API void GL_APIENTRY glAlphaFunc (GLenum func, GLclampf ref); +GL_API void GL_APIENTRY glClearColor (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha); +GL_API void GL_APIENTRY glClearDepthf (GLclampf depth); +GL_API void GL_APIENTRY glClipPlanef (GLenum plane, const GLfloat *equation); +GL_API void GL_APIENTRY glColor4f (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); +GL_API void GL_APIENTRY glDepthRangef (GLclampf zNear, GLclampf zFar); +GL_API void GL_APIENTRY glFogf (GLenum pname, GLfloat param); +GL_API void GL_APIENTRY glFogfv (GLenum pname, const GLfloat *params); +GL_API void GL_APIENTRY glFrustumf (GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar); +GL_API void GL_APIENTRY glGetClipPlanef (GLenum pname, GLfloat eqn[4]); +GL_API void GL_APIENTRY glGetFloatv (GLenum pname, GLfloat *params); +GL_API void GL_APIENTRY glGetLightfv (GLenum light, GLenum pname, GLfloat *params); +GL_API void GL_APIENTRY glGetMaterialfv (GLenum face, GLenum pname, GLfloat *params); +GL_API void GL_APIENTRY glGetTexEnvfv (GLenum env, GLenum pname, GLfloat *params); +GL_API void GL_APIENTRY glGetTexParameterfv (GLenum target, GLenum pname, GLfloat *params); +GL_API void GL_APIENTRY glLightModelf (GLenum pname, GLfloat param); +GL_API void GL_APIENTRY glLightModelfv (GLenum pname, const GLfloat *params); +GL_API void GL_APIENTRY glLightf (GLenum light, GLenum pname, GLfloat param); +GL_API void GL_APIENTRY glLightfv (GLenum light, GLenum pname, const GLfloat *params); +GL_API void GL_APIENTRY glLineWidth (GLfloat width); +GL_API void GL_APIENTRY glLoadMatrixf (const GLfloat *m); +GL_API void GL_APIENTRY glMaterialf (GLenum face, GLenum pname, GLfloat param); +GL_API void GL_APIENTRY glMaterialfv (GLenum face, GLenum pname, const GLfloat *params); +GL_API void GL_APIENTRY glMultMatrixf (const GLfloat *m); +GL_API void GL_APIENTRY glMultiTexCoord4f (GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q); +GL_API void GL_APIENTRY glNormal3f (GLfloat nx, GLfloat ny, GLfloat nz); +GL_API void GL_APIENTRY glOrthof (GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar); +GL_API void GL_APIENTRY glPointParameterf (GLenum pname, GLfloat param); +GL_API void GL_APIENTRY glPointParameterfv (GLenum pname, const GLfloat *params); +GL_API void GL_APIENTRY glPointSize (GLfloat size); +GL_API void GL_APIENTRY glPolygonOffset (GLfloat factor, GLfloat units); +GL_API void GL_APIENTRY glRotatef (GLfloat angle, GLfloat x, GLfloat y, GLfloat z); +GL_API void GL_APIENTRY glScalef (GLfloat x, GLfloat y, GLfloat z); +GL_API void GL_APIENTRY glTexEnvf (GLenum target, GLenum pname, GLfloat param); +GL_API void GL_APIENTRY glTexEnvfv (GLenum target, GLenum pname, const GLfloat *params); +GL_API void GL_APIENTRY glTexParameterf (GLenum target, GLenum pname, GLfloat param); +GL_API void GL_APIENTRY glTexParameterfv (GLenum target, GLenum pname, const GLfloat *params); +GL_API void GL_APIENTRY glTranslatef (GLfloat x, GLfloat y, GLfloat z); + +/* Available in both Common and Common-Lite profiles */ +GL_API void GL_APIENTRY glActiveTexture (GLenum texture); +GL_API void GL_APIENTRY glAlphaFuncx (GLenum func, GLclampx ref); +GL_API void GL_APIENTRY glBindBuffer (GLenum target, GLuint buffer); +GL_API void GL_APIENTRY glBindTexture (GLenum target, GLuint texture); +GL_API void GL_APIENTRY glBlendFunc (GLenum sfactor, GLenum dfactor); +GL_API void GL_APIENTRY glBufferData (GLenum target, GLsizeiptr size, const GLvoid *data, GLenum usage); +GL_API void GL_APIENTRY glBufferSubData (GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid *data); +GL_API void GL_APIENTRY glClear (GLbitfield mask); +GL_API void GL_APIENTRY glClearColorx (GLclampx red, GLclampx green, GLclampx blue, GLclampx alpha); +GL_API void GL_APIENTRY glClearDepthx (GLclampx depth); +GL_API void GL_APIENTRY glClearStencil (GLint s); +GL_API void GL_APIENTRY glClientActiveTexture (GLenum texture); +GL_API void GL_APIENTRY glClipPlanex (GLenum plane, const GLfixed *equation); +GL_API void GL_APIENTRY glColor4ub (GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha); +GL_API void GL_APIENTRY glColor4x (GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha); +GL_API void GL_APIENTRY glColorMask (GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha); +GL_API void GL_APIENTRY glColorPointer (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +GL_API void GL_APIENTRY glCompressedTexImage2D (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data); +GL_API void GL_APIENTRY glCompressedTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *data); +GL_API void GL_APIENTRY glCopyTexImage2D (GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border); +GL_API void GL_APIENTRY glCopyTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height); +GL_API void GL_APIENTRY glCullFace (GLenum mode); +GL_API void GL_APIENTRY glDeleteBuffers (GLsizei n, const GLuint *buffers); +GL_API void GL_APIENTRY glDeleteTextures (GLsizei n, const GLuint *textures); +GL_API void GL_APIENTRY glDepthFunc (GLenum func); +GL_API void GL_APIENTRY glDepthMask (GLboolean flag); +GL_API void GL_APIENTRY glDepthRangex (GLclampx zNear, GLclampx zFar); +GL_API void GL_APIENTRY glDisable (GLenum cap); +GL_API void GL_APIENTRY glDisableClientState (GLenum array); +GL_API void GL_APIENTRY glDrawArrays (GLenum mode, GLint first, GLsizei count); +GL_API void GL_APIENTRY glDrawElements (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices); +GL_API void GL_APIENTRY glEnable (GLenum cap); +GL_API void GL_APIENTRY glEnableClientState (GLenum array); +GL_API void GL_APIENTRY glFinish (void); +GL_API void GL_APIENTRY glFlush (void); +GL_API void GL_APIENTRY glFogx (GLenum pname, GLfixed param); +GL_API void GL_APIENTRY glFogxv (GLenum pname, const GLfixed *params); +GL_API void GL_APIENTRY glFrontFace (GLenum mode); +GL_API void GL_APIENTRY glFrustumx (GLfixed left, GLfixed right, GLfixed bottom, GLfixed top, GLfixed zNear, GLfixed zFar); +GL_API void GL_APIENTRY glGetBooleanv (GLenum pname, GLboolean *params); +GL_API void GL_APIENTRY glGetBufferParameteriv (GLenum target, GLenum pname, GLint *params); +GL_API void GL_APIENTRY glGetClipPlanex (GLenum pname, GLfixed eqn[4]); +GL_API void GL_APIENTRY glGenBuffers (GLsizei n, GLuint *buffers); +GL_API void GL_APIENTRY glGenTextures (GLsizei n, GLuint *textures); +GL_API GLenum GL_APIENTRY glGetError (void); +GL_API void GL_APIENTRY glGetFixedv (GLenum pname, GLfixed *params); +GL_API void GL_APIENTRY glGetIntegerv (GLenum pname, GLint *params); +GL_API void GL_APIENTRY glGetLightxv (GLenum light, GLenum pname, GLfixed *params); +GL_API void GL_APIENTRY glGetMaterialxv (GLenum face, GLenum pname, GLfixed *params); +GL_API void GL_APIENTRY glGetPointerv (GLenum pname, GLvoid **params); +GL_API const GLubyte * GL_APIENTRY glGetString (GLenum name); +GL_API void GL_APIENTRY glGetTexEnviv (GLenum env, GLenum pname, GLint *params); +GL_API void GL_APIENTRY glGetTexEnvxv (GLenum env, GLenum pname, GLfixed *params); +GL_API void GL_APIENTRY glGetTexParameteriv (GLenum target, GLenum pname, GLint *params); +GL_API void GL_APIENTRY glGetTexParameterxv (GLenum target, GLenum pname, GLfixed *params); +GL_API void GL_APIENTRY glHint (GLenum target, GLenum mode); +GL_API GLboolean GL_APIENTRY glIsBuffer (GLuint buffer); +GL_API GLboolean GL_APIENTRY glIsEnabled (GLenum cap); +GL_API GLboolean GL_APIENTRY glIsTexture (GLuint texture); +GL_API void GL_APIENTRY glLightModelx (GLenum pname, GLfixed param); +GL_API void GL_APIENTRY glLightModelxv (GLenum pname, const GLfixed *params); +GL_API void GL_APIENTRY glLightx (GLenum light, GLenum pname, GLfixed param); +GL_API void GL_APIENTRY glLightxv (GLenum light, GLenum pname, const GLfixed *params); +GL_API void GL_APIENTRY glLineWidthx (GLfixed width); +GL_API void GL_APIENTRY glLoadIdentity (void); +GL_API void GL_APIENTRY glLoadMatrixx (const GLfixed *m); +GL_API void GL_APIENTRY glLogicOp (GLenum opcode); +GL_API void GL_APIENTRY glMaterialx (GLenum face, GLenum pname, GLfixed param); +GL_API void GL_APIENTRY glMaterialxv (GLenum face, GLenum pname, const GLfixed *params); +GL_API void GL_APIENTRY glMatrixMode (GLenum mode); +GL_API void GL_APIENTRY glMultMatrixx (const GLfixed *m); +GL_API void GL_APIENTRY glMultiTexCoord4x (GLenum target, GLfixed s, GLfixed t, GLfixed r, GLfixed q); +GL_API void GL_APIENTRY glNormal3x (GLfixed nx, GLfixed ny, GLfixed nz); +GL_API void GL_APIENTRY glNormalPointer (GLenum type, GLsizei stride, const GLvoid *pointer); +GL_API void GL_APIENTRY glOrthox (GLfixed left, GLfixed right, GLfixed bottom, GLfixed top, GLfixed zNear, GLfixed zFar); +GL_API void GL_APIENTRY glPixelStorei (GLenum pname, GLint param); +GL_API void GL_APIENTRY glPointParameterx (GLenum pname, GLfixed param); +GL_API void GL_APIENTRY glPointParameterxv (GLenum pname, const GLfixed *params); +GL_API void GL_APIENTRY glPointSizex (GLfixed size); +GL_API void GL_APIENTRY glPolygonOffsetx (GLfixed factor, GLfixed units); +GL_API void GL_APIENTRY glPopMatrix (void); +GL_API void GL_APIENTRY glPushMatrix (void); +GL_API void GL_APIENTRY glReadPixels (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels); +GL_API void GL_APIENTRY glRotatex (GLfixed angle, GLfixed x, GLfixed y, GLfixed z); +GL_API void GL_APIENTRY glSampleCoverage (GLclampf value, GLboolean invert); +GL_API void GL_APIENTRY glSampleCoveragex (GLclampx value, GLboolean invert); +GL_API void GL_APIENTRY glScalex (GLfixed x, GLfixed y, GLfixed z); +GL_API void GL_APIENTRY glScissor (GLint x, GLint y, GLsizei width, GLsizei height); +GL_API void GL_APIENTRY glShadeModel (GLenum mode); +GL_API void GL_APIENTRY glStencilFunc (GLenum func, GLint ref, GLuint mask); +GL_API void GL_APIENTRY glStencilMask (GLuint mask); +GL_API void GL_APIENTRY glStencilOp (GLenum fail, GLenum zfail, GLenum zpass); +GL_API void GL_APIENTRY glTexCoordPointer (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +GL_API void GL_APIENTRY glTexEnvi (GLenum target, GLenum pname, GLint param); +GL_API void GL_APIENTRY glTexEnvx (GLenum target, GLenum pname, GLfixed param); +GL_API void GL_APIENTRY glTexEnviv (GLenum target, GLenum pname, const GLint *params); +GL_API void GL_APIENTRY glTexEnvxv (GLenum target, GLenum pname, const GLfixed *params); +GL_API void GL_APIENTRY glTexImage2D (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels); +GL_API void GL_APIENTRY glTexParameteri (GLenum target, GLenum pname, GLint param); +GL_API void GL_APIENTRY glTexParameterx (GLenum target, GLenum pname, GLfixed param); +GL_API void GL_APIENTRY glTexParameteriv (GLenum target, GLenum pname, const GLint *params); +GL_API void GL_APIENTRY glTexParameterxv (GLenum target, GLenum pname, const GLfixed *params); +GL_API void GL_APIENTRY glTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels); +GL_API void GL_APIENTRY glTranslatex (GLfixed x, GLfixed y, GLfixed z); +GL_API void GL_APIENTRY glVertexPointer (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +GL_API void GL_APIENTRY glViewport (GLint x, GLint y, GLsizei width, GLsizei height); + +/*------------------------------------------------------------------------* + * Required OES extension functions + *------------------------------------------------------------------------*/ + +/* GL_OES_read_format */ +#ifndef GL_OES_read_format +#define GL_OES_read_format 1 +#endif + +/* GL_OES_compressed_paletted_texture */ +#ifndef GL_OES_compressed_paletted_texture +#define GL_OES_compressed_paletted_texture 1 +#endif + +/* GL_OES_point_size_array */ +#ifndef GL_OES_point_size_array +#define GL_OES_point_size_array 1 +GL_API void GL_APIENTRY glPointSizePointerOES (GLenum type, GLsizei stride, const GLvoid *pointer); +#endif + +/* GL_OES_point_sprite */ +#ifndef GL_OES_point_sprite +#define GL_OES_point_sprite 1 +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* __gl_h_ */ + diff --git a/Projects/Android/jni/SupportLibs/gl4es/include/GLES/gl2.h b/Projects/Android/jni/SupportLibs/gl4es/include/GLES/gl2.h new file mode 100644 index 0000000..b7fe76e --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/include/GLES/gl2.h @@ -0,0 +1,620 @@ +#ifndef __gl2_h_ +#define __gl2_h_ + +/* $Revision: 16803 $ on $Date:: 2012-02-02 09:49:18 -0800 #$ */ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * This document is licensed under the SGI Free Software B License Version + * 2.0. For details, see http://oss.sgi.com/projects/FreeB/ . + */ + +/*------------------------------------------------------------------------- + * Data type definitions + *-----------------------------------------------------------------------*/ + +typedef void GLvoid; +typedef char GLchar; +typedef unsigned int GLenum; +typedef unsigned char GLboolean; +typedef unsigned int GLbitfield; +typedef khronos_int8_t GLbyte; +typedef short GLshort; +typedef int GLint; +typedef int GLsizei; +typedef khronos_uint8_t GLubyte; +typedef unsigned short GLushort; +typedef unsigned int GLuint; +typedef khronos_float_t GLfloat; +typedef khronos_float_t GLclampf; +typedef khronos_int32_t GLfixed; + +/* GL types for handling large vertex buffer objects */ +typedef khronos_intptr_t GLintptr; +typedef khronos_ssize_t GLsizeiptr; + +/* OpenGL ES core versions */ +#define GL_ES_VERSION_2_0 1 + +/* ClearBufferMask */ +#define GL_DEPTH_BUFFER_BIT 0x00000100 +#define GL_STENCIL_BUFFER_BIT 0x00000400 +#define GL_COLOR_BUFFER_BIT 0x00004000 + +/* Boolean */ +#define GL_FALSE 0 +#define GL_TRUE 1 + +/* BeginMode */ +#define GL_POINTS 0x0000 +#define GL_LINES 0x0001 +#define GL_LINE_LOOP 0x0002 +#define GL_LINE_STRIP 0x0003 +#define GL_TRIANGLES 0x0004 +#define GL_TRIANGLE_STRIP 0x0005 +#define GL_TRIANGLE_FAN 0x0006 + +/* AlphaFunction (not supported in ES20) */ +/* GL_NEVER */ +/* GL_LESS */ +/* GL_EQUAL */ +/* GL_LEQUAL */ +/* GL_GREATER */ +/* GL_NOTEQUAL */ +/* GL_GEQUAL */ +/* GL_ALWAYS */ + +/* BlendingFactorDest */ +#define GL_ZERO 0 +#define GL_ONE 1 +#define GL_SRC_COLOR 0x0300 +#define GL_ONE_MINUS_SRC_COLOR 0x0301 +#define GL_SRC_ALPHA 0x0302 +#define GL_ONE_MINUS_SRC_ALPHA 0x0303 +#define GL_DST_ALPHA 0x0304 +#define GL_ONE_MINUS_DST_ALPHA 0x0305 + +/* BlendingFactorSrc */ +/* GL_ZERO */ +/* GL_ONE */ +#define GL_DST_COLOR 0x0306 +#define GL_ONE_MINUS_DST_COLOR 0x0307 +#define GL_SRC_ALPHA_SATURATE 0x0308 +/* GL_SRC_ALPHA */ +/* GL_ONE_MINUS_SRC_ALPHA */ +/* GL_DST_ALPHA */ +/* GL_ONE_MINUS_DST_ALPHA */ + +/* BlendEquationSeparate */ +#define GL_FUNC_ADD 0x8006 +#define GL_BLEND_EQUATION 0x8009 +#define GL_BLEND_EQUATION_RGB 0x8009 /* same as BLEND_EQUATION */ +#define GL_BLEND_EQUATION_ALPHA 0x883D + +/* BlendSubtract */ +#define GL_FUNC_SUBTRACT 0x800A +#define GL_FUNC_REVERSE_SUBTRACT 0x800B + +/* Separate Blend Functions */ +#define GL_BLEND_DST_RGB 0x80C8 +#define GL_BLEND_SRC_RGB 0x80C9 +#define GL_BLEND_DST_ALPHA 0x80CA +#define GL_BLEND_SRC_ALPHA 0x80CB +#define GL_CONSTANT_COLOR 0x8001 +#define GL_ONE_MINUS_CONSTANT_COLOR 0x8002 +#define GL_CONSTANT_ALPHA 0x8003 +#define GL_ONE_MINUS_CONSTANT_ALPHA 0x8004 +#define GL_BLEND_COLOR 0x8005 + +/* Buffer Objects */ +#define GL_ARRAY_BUFFER 0x8892 +#define GL_ELEMENT_ARRAY_BUFFER 0x8893 +#define GL_ARRAY_BUFFER_BINDING 0x8894 +#define GL_ELEMENT_ARRAY_BUFFER_BINDING 0x8895 + +#define GL_STREAM_DRAW 0x88E0 +#define GL_STATIC_DRAW 0x88E4 +#define GL_DYNAMIC_DRAW 0x88E8 + +#define GL_BUFFER_SIZE 0x8764 +#define GL_BUFFER_USAGE 0x8765 + +#define GL_CURRENT_VERTEX_ATTRIB 0x8626 + +/* CullFaceMode */ +#define GL_FRONT 0x0404 +#define GL_BACK 0x0405 +#define GL_FRONT_AND_BACK 0x0408 + +/* DepthFunction */ +/* GL_NEVER */ +/* GL_LESS */ +/* GL_EQUAL */ +/* GL_LEQUAL */ +/* GL_GREATER */ +/* GL_NOTEQUAL */ +/* GL_GEQUAL */ +/* GL_ALWAYS */ + +/* EnableCap */ +#define GL_TEXTURE_2D 0x0DE1 +#define GL_CULL_FACE 0x0B44 +#define GL_BLEND 0x0BE2 +#define GL_DITHER 0x0BD0 +#define GL_STENCIL_TEST 0x0B90 +#define GL_DEPTH_TEST 0x0B71 +#define GL_SCISSOR_TEST 0x0C11 +#define GL_POLYGON_OFFSET_FILL 0x8037 +#define GL_SAMPLE_ALPHA_TO_COVERAGE 0x809E +#define GL_SAMPLE_COVERAGE 0x80A0 + +/* ErrorCode */ +#define GL_NO_ERROR 0 +#define GL_INVALID_ENUM 0x0500 +#define GL_INVALID_VALUE 0x0501 +#define GL_INVALID_OPERATION 0x0502 +#define GL_OUT_OF_MEMORY 0x0505 + +/* FrontFaceDirection */ +#define GL_CW 0x0900 +#define GL_CCW 0x0901 + +/* GetPName */ +#define GL_LINE_WIDTH 0x0B21 +#define GL_ALIASED_POINT_SIZE_RANGE 0x846D +#define GL_ALIASED_LINE_WIDTH_RANGE 0x846E +#define GL_CULL_FACE_MODE 0x0B45 +#define GL_FRONT_FACE 0x0B46 +#define GL_DEPTH_RANGE 0x0B70 +#define GL_DEPTH_WRITEMASK 0x0B72 +#define GL_DEPTH_CLEAR_VALUE 0x0B73 +#define GL_DEPTH_FUNC 0x0B74 +#define GL_STENCIL_CLEAR_VALUE 0x0B91 +#define GL_STENCIL_FUNC 0x0B92 +#define GL_STENCIL_FAIL 0x0B94 +#define GL_STENCIL_PASS_DEPTH_FAIL 0x0B95 +#define GL_STENCIL_PASS_DEPTH_PASS 0x0B96 +#define GL_STENCIL_REF 0x0B97 +#define GL_STENCIL_VALUE_MASK 0x0B93 +#define GL_STENCIL_WRITEMASK 0x0B98 +#define GL_STENCIL_BACK_FUNC 0x8800 +#define GL_STENCIL_BACK_FAIL 0x8801 +#define GL_STENCIL_BACK_PASS_DEPTH_FAIL 0x8802 +#define GL_STENCIL_BACK_PASS_DEPTH_PASS 0x8803 +#define GL_STENCIL_BACK_REF 0x8CA3 +#define GL_STENCIL_BACK_VALUE_MASK 0x8CA4 +#define GL_STENCIL_BACK_WRITEMASK 0x8CA5 +#define GL_VIEWPORT 0x0BA2 +#define GL_SCISSOR_BOX 0x0C10 +/* GL_SCISSOR_TEST */ +#define GL_COLOR_CLEAR_VALUE 0x0C22 +#define GL_COLOR_WRITEMASK 0x0C23 +#define GL_UNPACK_ALIGNMENT 0x0CF5 +#define GL_PACK_ALIGNMENT 0x0D05 +#define GL_MAX_TEXTURE_SIZE 0x0D33 +#define GL_MAX_VIEWPORT_DIMS 0x0D3A +#define GL_SUBPIXEL_BITS 0x0D50 +#define GL_RED_BITS 0x0D52 +#define GL_GREEN_BITS 0x0D53 +#define GL_BLUE_BITS 0x0D54 +#define GL_ALPHA_BITS 0x0D55 +#define GL_DEPTH_BITS 0x0D56 +#define GL_STENCIL_BITS 0x0D57 +#define GL_POLYGON_OFFSET_UNITS 0x2A00 +/* GL_POLYGON_OFFSET_FILL */ +#define GL_POLYGON_OFFSET_FACTOR 0x8038 +#define GL_TEXTURE_BINDING_2D 0x8069 +#define GL_SAMPLE_BUFFERS 0x80A8 +#define GL_SAMPLES 0x80A9 +#define GL_SAMPLE_COVERAGE_VALUE 0x80AA +#define GL_SAMPLE_COVERAGE_INVERT 0x80AB + +/* GetTextureParameter */ +/* GL_TEXTURE_MAG_FILTER */ +/* GL_TEXTURE_MIN_FILTER */ +/* GL_TEXTURE_WRAP_S */ +/* GL_TEXTURE_WRAP_T */ + +#define GL_NUM_COMPRESSED_TEXTURE_FORMATS 0x86A2 +#define GL_COMPRESSED_TEXTURE_FORMATS 0x86A3 + +/* HintMode */ +#define GL_DONT_CARE 0x1100 +#define GL_FASTEST 0x1101 +#define GL_NICEST 0x1102 + +/* HintTarget */ +#define GL_GENERATE_MIPMAP_HINT 0x8192 + +/* DataType */ +#define GL_BYTE 0x1400 +#define GL_UNSIGNED_BYTE 0x1401 +#define GL_SHORT 0x1402 +#define GL_UNSIGNED_SHORT 0x1403 +#define GL_INT 0x1404 +#define GL_UNSIGNED_INT 0x1405 +#define GL_FLOAT 0x1406 +#define GL_FIXED 0x140C + +/* PixelFormat */ +#define GL_DEPTH_COMPONENT 0x1902 +#define GL_ALPHA 0x1906 +#define GL_RGB 0x1907 +#define GL_RGBA 0x1908 +#define GL_LUMINANCE 0x1909 +#define GL_LUMINANCE_ALPHA 0x190A + +/* PixelType */ +/* GL_UNSIGNED_BYTE */ +#define GL_UNSIGNED_SHORT_4_4_4_4 0x8033 +#define GL_UNSIGNED_SHORT_5_5_5_1 0x8034 +#define GL_UNSIGNED_SHORT_5_6_5 0x8363 + +/* Shaders */ +#define GL_FRAGMENT_SHADER 0x8B30 +#define GL_VERTEX_SHADER 0x8B31 +#define GL_MAX_VERTEX_ATTRIBS 0x8869 +#define GL_MAX_VERTEX_UNIFORM_VECTORS 0x8DFB +#define GL_MAX_VARYING_VECTORS 0x8DFC +#define GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS 0x8B4D +#define GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS 0x8B4C +#define GL_MAX_TEXTURE_IMAGE_UNITS 0x8872 +#define GL_MAX_FRAGMENT_UNIFORM_VECTORS 0x8DFD +#define GL_SHADER_TYPE 0x8B4F +#define GL_DELETE_STATUS 0x8B80 +#define GL_LINK_STATUS 0x8B82 +#define GL_VALIDATE_STATUS 0x8B83 +#define GL_ATTACHED_SHADERS 0x8B85 +#define GL_ACTIVE_UNIFORMS 0x8B86 +#define GL_ACTIVE_UNIFORM_MAX_LENGTH 0x8B87 +#define GL_ACTIVE_ATTRIBUTES 0x8B89 +#define GL_ACTIVE_ATTRIBUTE_MAX_LENGTH 0x8B8A +#define GL_SHADING_LANGUAGE_VERSION 0x8B8C +#define GL_CURRENT_PROGRAM 0x8B8D + +/* StencilFunction */ +#define GL_NEVER 0x0200 +#define GL_LESS 0x0201 +#define GL_EQUAL 0x0202 +#define GL_LEQUAL 0x0203 +#define GL_GREATER 0x0204 +#define GL_NOTEQUAL 0x0205 +#define GL_GEQUAL 0x0206 +#define GL_ALWAYS 0x0207 + +/* StencilOp */ +/* GL_ZERO */ +#define GL_KEEP 0x1E00 +#define GL_REPLACE 0x1E01 +#define GL_INCR 0x1E02 +#define GL_DECR 0x1E03 +#define GL_INVERT 0x150A +#define GL_INCR_WRAP 0x8507 +#define GL_DECR_WRAP 0x8508 + +/* StringName */ +#define GL_VENDOR 0x1F00 +#define GL_RENDERER 0x1F01 +#define GL_VERSION 0x1F02 +#define GL_EXTENSIONS 0x1F03 + +/* TextureMagFilter */ +#define GL_NEAREST 0x2600 +#define GL_LINEAR 0x2601 + +/* TextureMinFilter */ +/* GL_NEAREST */ +/* GL_LINEAR */ +#define GL_NEAREST_MIPMAP_NEAREST 0x2700 +#define GL_LINEAR_MIPMAP_NEAREST 0x2701 +#define GL_NEAREST_MIPMAP_LINEAR 0x2702 +#define GL_LINEAR_MIPMAP_LINEAR 0x2703 + +/* TextureParameterName */ +#define GL_TEXTURE_MAG_FILTER 0x2800 +#define GL_TEXTURE_MIN_FILTER 0x2801 +#define GL_TEXTURE_WRAP_S 0x2802 +#define GL_TEXTURE_WRAP_T 0x2803 + +/* TextureTarget */ +/* GL_TEXTURE_2D */ +#define GL_TEXTURE 0x1702 + +#define GL_TEXTURE_CUBE_MAP 0x8513 +#define GL_TEXTURE_BINDING_CUBE_MAP 0x8514 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_X 0x8515 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_X 0x8516 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_Y 0x8517 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Y 0x8518 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_Z 0x8519 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Z 0x851A +#define GL_MAX_CUBE_MAP_TEXTURE_SIZE 0x851C + +/* TextureUnit */ +#define GL_TEXTURE0 0x84C0 +#define GL_TEXTURE1 0x84C1 +#define GL_TEXTURE2 0x84C2 +#define GL_TEXTURE3 0x84C3 +#define GL_TEXTURE4 0x84C4 +#define GL_TEXTURE5 0x84C5 +#define GL_TEXTURE6 0x84C6 +#define GL_TEXTURE7 0x84C7 +#define GL_TEXTURE8 0x84C8 +#define GL_TEXTURE9 0x84C9 +#define GL_TEXTURE10 0x84CA +#define GL_TEXTURE11 0x84CB +#define GL_TEXTURE12 0x84CC +#define GL_TEXTURE13 0x84CD +#define GL_TEXTURE14 0x84CE +#define GL_TEXTURE15 0x84CF +#define GL_TEXTURE16 0x84D0 +#define GL_TEXTURE17 0x84D1 +#define GL_TEXTURE18 0x84D2 +#define GL_TEXTURE19 0x84D3 +#define GL_TEXTURE20 0x84D4 +#define GL_TEXTURE21 0x84D5 +#define GL_TEXTURE22 0x84D6 +#define GL_TEXTURE23 0x84D7 +#define GL_TEXTURE24 0x84D8 +#define GL_TEXTURE25 0x84D9 +#define GL_TEXTURE26 0x84DA +#define GL_TEXTURE27 0x84DB +#define GL_TEXTURE28 0x84DC +#define GL_TEXTURE29 0x84DD +#define GL_TEXTURE30 0x84DE +#define GL_TEXTURE31 0x84DF +#define GL_ACTIVE_TEXTURE 0x84E0 + +/* TextureWrapMode */ +#define GL_REPEAT 0x2901 +#define GL_CLAMP_TO_EDGE 0x812F +#define GL_MIRRORED_REPEAT 0x8370 + +/* Uniform Types */ +#define GL_FLOAT_VEC2 0x8B50 +#define GL_FLOAT_VEC3 0x8B51 +#define GL_FLOAT_VEC4 0x8B52 +#define GL_INT_VEC2 0x8B53 +#define GL_INT_VEC3 0x8B54 +#define GL_INT_VEC4 0x8B55 +#define GL_BOOL 0x8B56 +#define GL_BOOL_VEC2 0x8B57 +#define GL_BOOL_VEC3 0x8B58 +#define GL_BOOL_VEC4 0x8B59 +#define GL_FLOAT_MAT2 0x8B5A +#define GL_FLOAT_MAT3 0x8B5B +#define GL_FLOAT_MAT4 0x8B5C +#define GL_SAMPLER_2D 0x8B5E +#define GL_SAMPLER_CUBE 0x8B60 + +/* Vertex Arrays */ +#define GL_VERTEX_ATTRIB_ARRAY_ENABLED 0x8622 +#define GL_VERTEX_ATTRIB_ARRAY_SIZE 0x8623 +#define GL_VERTEX_ATTRIB_ARRAY_STRIDE 0x8624 +#define GL_VERTEX_ATTRIB_ARRAY_TYPE 0x8625 +#define GL_VERTEX_ATTRIB_ARRAY_NORMALIZED 0x886A +#define GL_VERTEX_ATTRIB_ARRAY_POINTER 0x8645 +#define GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING 0x889F + +/* Read Format */ +#define GL_IMPLEMENTATION_COLOR_READ_TYPE 0x8B9A +#define GL_IMPLEMENTATION_COLOR_READ_FORMAT 0x8B9B + +/* Shader Source */ +#define GL_COMPILE_STATUS 0x8B81 +#define GL_INFO_LOG_LENGTH 0x8B84 +#define GL_SHADER_SOURCE_LENGTH 0x8B88 +#define GL_SHADER_COMPILER 0x8DFA + +/* Shader Binary */ +#define GL_SHADER_BINARY_FORMATS 0x8DF8 +#define GL_NUM_SHADER_BINARY_FORMATS 0x8DF9 + +/* Shader Precision-Specified Types */ +#define GL_LOW_FLOAT 0x8DF0 +#define GL_MEDIUM_FLOAT 0x8DF1 +#define GL_HIGH_FLOAT 0x8DF2 +#define GL_LOW_INT 0x8DF3 +#define GL_MEDIUM_INT 0x8DF4 +#define GL_HIGH_INT 0x8DF5 + +/* Framebuffer Object. */ +#define GL_FRAMEBUFFER 0x8D40 +#define GL_RENDERBUFFER 0x8D41 + +#define GL_RGBA4 0x8056 +#define GL_RGB5_A1 0x8057 +#define GL_RGB565 0x8D62 +#define GL_DEPTH_COMPONENT16 0x81A5 +#define GL_STENCIL_INDEX8 0x8D48 + +#define GL_RENDERBUFFER_WIDTH 0x8D42 +#define GL_RENDERBUFFER_HEIGHT 0x8D43 +#define GL_RENDERBUFFER_INTERNAL_FORMAT 0x8D44 +#define GL_RENDERBUFFER_RED_SIZE 0x8D50 +#define GL_RENDERBUFFER_GREEN_SIZE 0x8D51 +#define GL_RENDERBUFFER_BLUE_SIZE 0x8D52 +#define GL_RENDERBUFFER_ALPHA_SIZE 0x8D53 +#define GL_RENDERBUFFER_DEPTH_SIZE 0x8D54 +#define GL_RENDERBUFFER_STENCIL_SIZE 0x8D55 + +#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE 0x8CD0 +#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME 0x8CD1 +#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL 0x8CD2 +#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE 0x8CD3 + +#define GL_COLOR_ATTACHMENT0 0x8CE0 +#define GL_DEPTH_ATTACHMENT 0x8D00 +#define GL_STENCIL_ATTACHMENT 0x8D20 + +#define GL_NONE 0 + +#define GL_FRAMEBUFFER_COMPLETE 0x8CD5 +#define GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT 0x8CD6 +#define GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT 0x8CD7 +#define GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS 0x8CD9 +#define GL_FRAMEBUFFER_UNSUPPORTED 0x8CDD + +#define GL_FRAMEBUFFER_BINDING 0x8CA6 +#define GL_RENDERBUFFER_BINDING 0x8CA7 +#define GL_MAX_RENDERBUFFER_SIZE 0x84E8 + +#define GL_INVALID_FRAMEBUFFER_OPERATION 0x0506 + +/*------------------------------------------------------------------------- + * GL core functions. + *-----------------------------------------------------------------------*/ + +GL_APICALL void GL_APIENTRY glActiveTexture (GLenum texture); +GL_APICALL void GL_APIENTRY glAttachShader (GLuint program, GLuint shader); +GL_APICALL void GL_APIENTRY glBindAttribLocation (GLuint program, GLuint index, const GLchar* name); +GL_APICALL void GL_APIENTRY glBindBuffer (GLenum target, GLuint buffer); +GL_APICALL void GL_APIENTRY glBindFramebuffer (GLenum target, GLuint framebuffer); +GL_APICALL void GL_APIENTRY glBindRenderbuffer (GLenum target, GLuint renderbuffer); +GL_APICALL void GL_APIENTRY glBindTexture (GLenum target, GLuint texture); +GL_APICALL void GL_APIENTRY glBlendColor (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha); +GL_APICALL void GL_APIENTRY glBlendEquation ( GLenum mode ); +GL_APICALL void GL_APIENTRY glBlendEquationSeparate (GLenum modeRGB, GLenum modeAlpha); +GL_APICALL void GL_APIENTRY glBlendFunc (GLenum sfactor, GLenum dfactor); +GL_APICALL void GL_APIENTRY glBlendFuncSeparate (GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha); +GL_APICALL void GL_APIENTRY glBufferData (GLenum target, GLsizeiptr size, const GLvoid* data, GLenum usage); +GL_APICALL void GL_APIENTRY glBufferSubData (GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid* data); +GL_APICALL GLenum GL_APIENTRY glCheckFramebufferStatus (GLenum target); +GL_APICALL void GL_APIENTRY glClear (GLbitfield mask); +GL_APICALL void GL_APIENTRY glClearColor (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha); +GL_APICALL void GL_APIENTRY glClearDepthf (GLclampf depth); +GL_APICALL void GL_APIENTRY glClearStencil (GLint s); +GL_APICALL void GL_APIENTRY glColorMask (GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha); +GL_APICALL void GL_APIENTRY glCompileShader (GLuint shader); +GL_APICALL void GL_APIENTRY glCompressedTexImage2D (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid* data); +GL_APICALL void GL_APIENTRY glCompressedTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid* data); +GL_APICALL void GL_APIENTRY glCopyTexImage2D (GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border); +GL_APICALL void GL_APIENTRY glCopyTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height); +GL_APICALL GLuint GL_APIENTRY glCreateProgram (void); +GL_APICALL GLuint GL_APIENTRY glCreateShader (GLenum type); +GL_APICALL void GL_APIENTRY glCullFace (GLenum mode); +GL_APICALL void GL_APIENTRY glDeleteBuffers (GLsizei n, const GLuint* buffers); +GL_APICALL void GL_APIENTRY glDeleteFramebuffers (GLsizei n, const GLuint* framebuffers); +GL_APICALL void GL_APIENTRY glDeleteProgram (GLuint program); +GL_APICALL void GL_APIENTRY glDeleteRenderbuffers (GLsizei n, const GLuint* renderbuffers); +GL_APICALL void GL_APIENTRY glDeleteShader (GLuint shader); +GL_APICALL void GL_APIENTRY glDeleteTextures (GLsizei n, const GLuint* textures); +GL_APICALL void GL_APIENTRY glDepthFunc (GLenum func); +GL_APICALL void GL_APIENTRY glDepthMask (GLboolean flag); +GL_APICALL void GL_APIENTRY glDepthRangef (GLclampf zNear, GLclampf zFar); +GL_APICALL void GL_APIENTRY glDetachShader (GLuint program, GLuint shader); +GL_APICALL void GL_APIENTRY glDisable (GLenum cap); +GL_APICALL void GL_APIENTRY glDisableVertexAttribArray (GLuint index); +GL_APICALL void GL_APIENTRY glDrawArrays (GLenum mode, GLint first, GLsizei count); +GL_APICALL void GL_APIENTRY glDrawElements (GLenum mode, GLsizei count, GLenum type, const GLvoid* indices); +GL_APICALL void GL_APIENTRY glEnable (GLenum cap); +GL_APICALL void GL_APIENTRY glEnableVertexAttribArray (GLuint index); +GL_APICALL void GL_APIENTRY glFinish (void); +GL_APICALL void GL_APIENTRY glFlush (void); +GL_APICALL void GL_APIENTRY glFramebufferRenderbuffer (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer); +GL_APICALL void GL_APIENTRY glFramebufferTexture2D (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); +GL_APICALL void GL_APIENTRY glFrontFace (GLenum mode); +GL_APICALL void GL_APIENTRY glGenBuffers (GLsizei n, GLuint* buffers); +GL_APICALL void GL_APIENTRY glGenerateMipmap (GLenum target); +GL_APICALL void GL_APIENTRY glGenFramebuffers (GLsizei n, GLuint* framebuffers); +GL_APICALL void GL_APIENTRY glGenRenderbuffers (GLsizei n, GLuint* renderbuffers); +GL_APICALL void GL_APIENTRY glGenTextures (GLsizei n, GLuint* textures); +GL_APICALL void GL_APIENTRY glGetActiveAttrib (GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name); +GL_APICALL void GL_APIENTRY glGetActiveUniform (GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name); +GL_APICALL void GL_APIENTRY glGetAttachedShaders (GLuint program, GLsizei maxcount, GLsizei* count, GLuint* shaders); +GL_APICALL int GL_APIENTRY glGetAttribLocation (GLuint program, const GLchar* name); +GL_APICALL void GL_APIENTRY glGetBooleanv (GLenum pname, GLboolean* params); +GL_APICALL void GL_APIENTRY glGetBufferParameteriv (GLenum target, GLenum pname, GLint* params); +GL_APICALL GLenum GL_APIENTRY glGetError (void); +GL_APICALL void GL_APIENTRY glGetFloatv (GLenum pname, GLfloat* params); +GL_APICALL void GL_APIENTRY glGetFramebufferAttachmentParameteriv (GLenum target, GLenum attachment, GLenum pname, GLint* params); +GL_APICALL void GL_APIENTRY glGetIntegerv (GLenum pname, GLint* params); +GL_APICALL void GL_APIENTRY glGetProgramiv (GLuint program, GLenum pname, GLint* params); +GL_APICALL void GL_APIENTRY glGetProgramInfoLog (GLuint program, GLsizei bufsize, GLsizei* length, GLchar* infolog); +GL_APICALL void GL_APIENTRY glGetRenderbufferParameteriv (GLenum target, GLenum pname, GLint* params); +GL_APICALL void GL_APIENTRY glGetShaderiv (GLuint shader, GLenum pname, GLint* params); +GL_APICALL void GL_APIENTRY glGetShaderInfoLog (GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* infolog); +GL_APICALL void GL_APIENTRY glGetShaderPrecisionFormat (GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision); +GL_APICALL void GL_APIENTRY glGetShaderSource (GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source); +GL_APICALL const GLubyte* GL_APIENTRY glGetString (GLenum name); +GL_APICALL void GL_APIENTRY glGetTexParameterfv (GLenum target, GLenum pname, GLfloat* params); +GL_APICALL void GL_APIENTRY glGetTexParameteriv (GLenum target, GLenum pname, GLint* params); +GL_APICALL void GL_APIENTRY glGetUniformfv (GLuint program, GLint location, GLfloat* params); +GL_APICALL void GL_APIENTRY glGetUniformiv (GLuint program, GLint location, GLint* params); +GL_APICALL int GL_APIENTRY glGetUniformLocation (GLuint program, const GLchar* name); +GL_APICALL void GL_APIENTRY glGetVertexAttribfv (GLuint index, GLenum pname, GLfloat* params); +GL_APICALL void GL_APIENTRY glGetVertexAttribiv (GLuint index, GLenum pname, GLint* params); +GL_APICALL void GL_APIENTRY glGetVertexAttribPointerv (GLuint index, GLenum pname, GLvoid** pointer); +GL_APICALL void GL_APIENTRY glHint (GLenum target, GLenum mode); +GL_APICALL GLboolean GL_APIENTRY glIsBuffer (GLuint buffer); +GL_APICALL GLboolean GL_APIENTRY glIsEnabled (GLenum cap); +GL_APICALL GLboolean GL_APIENTRY glIsFramebuffer (GLuint framebuffer); +GL_APICALL GLboolean GL_APIENTRY glIsProgram (GLuint program); +GL_APICALL GLboolean GL_APIENTRY glIsRenderbuffer (GLuint renderbuffer); +GL_APICALL GLboolean GL_APIENTRY glIsShader (GLuint shader); +GL_APICALL GLboolean GL_APIENTRY glIsTexture (GLuint texture); +GL_APICALL void GL_APIENTRY glLineWidth (GLfloat width); +GL_APICALL void GL_APIENTRY glLinkProgram (GLuint program); +GL_APICALL void GL_APIENTRY glPixelStorei (GLenum pname, GLint param); +GL_APICALL void GL_APIENTRY glPolygonOffset (GLfloat factor, GLfloat units); +GL_APICALL void GL_APIENTRY glReadPixels (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid* pixels); +GL_APICALL void GL_APIENTRY glReleaseShaderCompiler (void); +GL_APICALL void GL_APIENTRY glRenderbufferStorage (GLenum target, GLenum internalformat, GLsizei width, GLsizei height); +GL_APICALL void GL_APIENTRY glSampleCoverage (GLclampf value, GLboolean invert); +GL_APICALL void GL_APIENTRY glScissor (GLint x, GLint y, GLsizei width, GLsizei height); +GL_APICALL void GL_APIENTRY glShaderBinary (GLsizei n, const GLuint* shaders, GLenum binaryformat, const GLvoid* binary, GLsizei length); +GL_APICALL void GL_APIENTRY glShaderSource (GLuint shader, GLsizei count, const GLchar* const* string, const GLint* length); +GL_APICALL void GL_APIENTRY glStencilFunc (GLenum func, GLint ref, GLuint mask); +GL_APICALL void GL_APIENTRY glStencilFuncSeparate (GLenum face, GLenum func, GLint ref, GLuint mask); +GL_APICALL void GL_APIENTRY glStencilMask (GLuint mask); +GL_APICALL void GL_APIENTRY glStencilMaskSeparate (GLenum face, GLuint mask); +GL_APICALL void GL_APIENTRY glStencilOp (GLenum fail, GLenum zfail, GLenum zpass); +GL_APICALL void GL_APIENTRY glStencilOpSeparate (GLenum face, GLenum fail, GLenum zfail, GLenum zpass); +GL_APICALL void GL_APIENTRY glTexImage2D (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid* pixels); +GL_APICALL void GL_APIENTRY glTexParameterf (GLenum target, GLenum pname, GLfloat param); +GL_APICALL void GL_APIENTRY glTexParameterfv (GLenum target, GLenum pname, const GLfloat* params); +GL_APICALL void GL_APIENTRY glTexParameteri (GLenum target, GLenum pname, GLint param); +GL_APICALL void GL_APIENTRY glTexParameteriv (GLenum target, GLenum pname, const GLint* params); +GL_APICALL void GL_APIENTRY glTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid* pixels); +GL_APICALL void GL_APIENTRY glUniform1f (GLint location, GLfloat x); +GL_APICALL void GL_APIENTRY glUniform1fv (GLint location, GLsizei count, const GLfloat* v); +GL_APICALL void GL_APIENTRY glUniform1i (GLint location, GLint x); +GL_APICALL void GL_APIENTRY glUniform1iv (GLint location, GLsizei count, const GLint* v); +GL_APICALL void GL_APIENTRY glUniform2f (GLint location, GLfloat x, GLfloat y); +GL_APICALL void GL_APIENTRY glUniform2fv (GLint location, GLsizei count, const GLfloat* v); +GL_APICALL void GL_APIENTRY glUniform2i (GLint location, GLint x, GLint y); +GL_APICALL void GL_APIENTRY glUniform2iv (GLint location, GLsizei count, const GLint* v); +GL_APICALL void GL_APIENTRY glUniform3f (GLint location, GLfloat x, GLfloat y, GLfloat z); +GL_APICALL void GL_APIENTRY glUniform3fv (GLint location, GLsizei count, const GLfloat* v); +GL_APICALL void GL_APIENTRY glUniform3i (GLint location, GLint x, GLint y, GLint z); +GL_APICALL void GL_APIENTRY glUniform3iv (GLint location, GLsizei count, const GLint* v); +GL_APICALL void GL_APIENTRY glUniform4f (GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +GL_APICALL void GL_APIENTRY glUniform4fv (GLint location, GLsizei count, const GLfloat* v); +GL_APICALL void GL_APIENTRY glUniform4i (GLint location, GLint x, GLint y, GLint z, GLint w); +GL_APICALL void GL_APIENTRY glUniform4iv (GLint location, GLsizei count, const GLint* v); +GL_APICALL void GL_APIENTRY glUniformMatrix2fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat* value); +GL_APICALL void GL_APIENTRY glUniformMatrix3fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat* value); +GL_APICALL void GL_APIENTRY glUniformMatrix4fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat* value); +GL_APICALL void GL_APIENTRY glUseProgram (GLuint program); +GL_APICALL void GL_APIENTRY glValidateProgram (GLuint program); +GL_APICALL void GL_APIENTRY glVertexAttrib1f (GLuint indx, GLfloat x); +GL_APICALL void GL_APIENTRY glVertexAttrib1fv (GLuint indx, const GLfloat* values); +GL_APICALL void GL_APIENTRY glVertexAttrib2f (GLuint indx, GLfloat x, GLfloat y); +GL_APICALL void GL_APIENTRY glVertexAttrib2fv (GLuint indx, const GLfloat* values); +GL_APICALL void GL_APIENTRY glVertexAttrib3f (GLuint indx, GLfloat x, GLfloat y, GLfloat z); +GL_APICALL void GL_APIENTRY glVertexAttrib3fv (GLuint indx, const GLfloat* values); +GL_APICALL void GL_APIENTRY glVertexAttrib4f (GLuint indx, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +GL_APICALL void GL_APIENTRY glVertexAttrib4fv (GLuint indx, const GLfloat* values); +GL_APICALL void GL_APIENTRY glVertexAttribPointer (GLuint indx, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* ptr); +GL_APICALL void GL_APIENTRY glViewport (GLint x, GLint y, GLsizei width, GLsizei height); + +#ifdef __cplusplus +} +#endif + +#endif /* __gl2_h_ */ diff --git a/Projects/Android/jni/SupportLibs/gl4es/include/GLES/gl2ext.h b/Projects/Android/jni/SupportLibs/gl4es/include/GLES/gl2ext.h new file mode 100644 index 0000000..65b8e80 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/include/GLES/gl2ext.h @@ -0,0 +1,1808 @@ +#ifndef __gl2ext_h_ +#define __gl2ext_h_ + +/* $Revision: 19436 $ on $Date:: 2012-10-10 10:37:04 -0700 #$ */ + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * This document is licensed under the SGI Free Software B License Version + * 2.0. For details, see http://oss.sgi.com/projects/FreeB/ . + */ + +#ifndef GL_APIENTRYP +# define GL_APIENTRYP GL_APIENTRY* +#endif + +/*------------------------------------------------------------------------* + * OES extension tokens + *------------------------------------------------------------------------*/ + +/* GL_OES_compressed_ETC1_RGB8_texture */ +#ifndef GL_OES_compressed_ETC1_RGB8_texture +#define GL_ETC1_RGB8_OES 0x8D64 +#endif + +/* GL_OES_compressed_paletted_texture */ +#ifndef GL_OES_compressed_paletted_texture +#define GL_PALETTE4_RGB8_OES 0x8B90 +#define GL_PALETTE4_RGBA8_OES 0x8B91 +#define GL_PALETTE4_R5_G6_B5_OES 0x8B92 +#define GL_PALETTE4_RGBA4_OES 0x8B93 +#define GL_PALETTE4_RGB5_A1_OES 0x8B94 +#define GL_PALETTE8_RGB8_OES 0x8B95 +#define GL_PALETTE8_RGBA8_OES 0x8B96 +#define GL_PALETTE8_R5_G6_B5_OES 0x8B97 +#define GL_PALETTE8_RGBA4_OES 0x8B98 +#define GL_PALETTE8_RGB5_A1_OES 0x8B99 +#endif + +/* GL_OES_depth24 */ +#ifndef GL_OES_depth24 +#define GL_DEPTH_COMPONENT24_OES 0x81A6 +#endif + +/* GL_OES_depth32 */ +#ifndef GL_OES_depth32 +#define GL_DEPTH_COMPONENT32_OES 0x81A7 +#endif + +/* GL_OES_depth_texture */ +/* No new tokens introduced by this extension. */ + +/* GL_OES_EGL_image */ +#ifndef GL_OES_EGL_image +typedef void* GLeglImageOES; +#endif + +/* GL_OES_EGL_image_external */ +#ifndef GL_OES_EGL_image_external +/* GLeglImageOES defined in GL_OES_EGL_image already. */ +#define GL_TEXTURE_EXTERNAL_OES 0x8D65 +#define GL_SAMPLER_EXTERNAL_OES 0x8D66 +#define GL_TEXTURE_BINDING_EXTERNAL_OES 0x8D67 +#define GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES 0x8D68 +#endif + +/* GL_OES_element_index_uint */ +#ifndef GL_OES_element_index_uint +#define GL_UNSIGNED_INT 0x1405 +#endif + +/* GL_OES_get_program_binary */ +#ifndef GL_OES_get_program_binary +#define GL_PROGRAM_BINARY_LENGTH_OES 0x8741 +#define GL_NUM_PROGRAM_BINARY_FORMATS_OES 0x87FE +#define GL_PROGRAM_BINARY_FORMATS_OES 0x87FF +#endif + +/* GL_OES_mapbuffer */ +#ifndef GL_OES_mapbuffer +#define GL_WRITE_ONLY_OES 0x88B9 +#define GL_BUFFER_ACCESS_OES 0x88BB +#define GL_BUFFER_MAPPED_OES 0x88BC +#define GL_BUFFER_MAP_POINTER_OES 0x88BD +#endif + +/* GL_OES_packed_depth_stencil */ +#ifndef GL_OES_packed_depth_stencil +#define GL_DEPTH_STENCIL_OES 0x84F9 +#define GL_UNSIGNED_INT_24_8_OES 0x84FA +#define GL_DEPTH24_STENCIL8_OES 0x88F0 +#endif + +/* GL_OES_required_internalformat */ +#ifndef GL_OES_required_internalformat +#define GL_ALPHA8_OES 0x803C +#define GL_DEPTH_COMPONENT16_OES 0x81A5 +/* reuse GL_DEPTH_COMPONENT24_OES */ +/* reuse GL_DEPTH24_STENCIL8_OES */ +/* reuse GL_DEPTH_COMPONENT32_OES */ +#define GL_LUMINANCE4_ALPHA4_OES 0x8043 +#define GL_LUMINANCE8_ALPHA8_OES 0x8045 +#define GL_LUMINANCE8_OES 0x8040 +#define GL_RGBA4_OES 0x8056 +#define GL_RGB5_A1_OES 0x8057 +#define GL_RGB565_OES 0x8D62 +/* reuse GL_RGB8_OES */ +/* reuse GL_RGBA8_OES */ +/* reuse GL_RGB10_EXT */ +/* reuse GL_RGB10_A2_EXT */ +#endif + +/* GL_OES_rgb8_rgba8 */ +#ifndef GL_OES_rgb8_rgba8 +#define GL_RGB8_OES 0x8051 +#define GL_RGBA8_OES 0x8058 +#endif + +/* GL_OES_standard_derivatives */ +#ifndef GL_OES_standard_derivatives +#define GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES 0x8B8B +#endif + +/* GL_OES_stencil1 */ +#ifndef GL_OES_stencil1 +#define GL_STENCIL_INDEX1_OES 0x8D46 +#endif + +/* GL_OES_stencil4 */ +#ifndef GL_OES_stencil4 +#define GL_STENCIL_INDEX4_OES 0x8D47 +#endif + +#ifndef GL_OES_surfaceless_context +#define GL_FRAMEBUFFER_UNDEFINED_OES 0x8219 +#endif + +/* GL_OES_texture_3D */ +#ifndef GL_OES_texture_3D +#define GL_TEXTURE_WRAP_R_OES 0x8072 +#define GL_TEXTURE_3D_OES 0x806F +#define GL_TEXTURE_BINDING_3D_OES 0x806A +#define GL_MAX_3D_TEXTURE_SIZE_OES 0x8073 +#define GL_SAMPLER_3D_OES 0x8B5F +#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_OES 0x8CD4 +#endif + +/* GL_OES_texture_float */ +/* No new tokens introduced by this extension. */ + +/* GL_OES_texture_float_linear */ +/* No new tokens introduced by this extension. */ + +/* GL_OES_texture_half_float */ +#ifndef GL_OES_texture_half_float +#define GL_HALF_FLOAT_OES 0x8D61 +#endif + +/* GL_OES_texture_half_float_linear */ +/* No new tokens introduced by this extension. */ + +/* GL_OES_texture_npot */ +/* No new tokens introduced by this extension. */ + +/* GL_OES_vertex_array_object */ +#ifndef GL_OES_vertex_array_object +#define GL_VERTEX_ARRAY_BINDING_OES 0x85B5 +#endif + +/* GL_OES_vertex_half_float */ +/* GL_HALF_FLOAT_OES defined in GL_OES_texture_half_float already. */ + +/* GL_OES_vertex_type_10_10_10_2 */ +#ifndef GL_OES_vertex_type_10_10_10_2 +#define GL_UNSIGNED_INT_10_10_10_2_OES 0x8DF6 +#define GL_INT_10_10_10_2_OES 0x8DF7 +#endif + +/*------------------------------------------------------------------------* + * KHR extension tokens + *------------------------------------------------------------------------*/ + +#ifndef GL_KHR_debug +typedef void (GL_APIENTRYP GLDEBUGPROC)(GLenum source,GLenum type,GLuint id,GLenum severity,GLsizei length,const GLchar *message,GLvoid *userParam); +#define GL_DEBUG_OUTPUT_SYNCHRONOUS 0x8242 +#define GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH 0x8243 +#define GL_DEBUG_CALLBACK_FUNCTION 0x8244 +#define GL_DEBUG_CALLBACK_USER_PARAM 0x8245 +#define GL_DEBUG_SOURCE_API 0x8246 +#define GL_DEBUG_SOURCE_WINDOW_SYSTEM 0x8247 +#define GL_DEBUG_SOURCE_SHADER_COMPILER 0x8248 +#define GL_DEBUG_SOURCE_THIRD_PARTY 0x8249 +#define GL_DEBUG_SOURCE_APPLICATION 0x824A +#define GL_DEBUG_SOURCE_OTHER 0x824B +#define GL_DEBUG_TYPE_ERROR 0x824C +#define GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR 0x824D +#define GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR 0x824E +#define GL_DEBUG_TYPE_PORTABILITY 0x824F +#define GL_DEBUG_TYPE_PERFORMANCE 0x8250 +#define GL_DEBUG_TYPE_OTHER 0x8251 +#define GL_DEBUG_TYPE_MARKER 0x8268 +#define GL_DEBUG_TYPE_PUSH_GROUP 0x8269 +#define GL_DEBUG_TYPE_POP_GROUP 0x826A +#define GL_DEBUG_SEVERITY_NOTIFICATION 0x826B +#define GL_MAX_DEBUG_GROUP_STACK_DEPTH 0x826C +#define GL_DEBUG_GROUP_STACK_DEPTH 0x826D +#define GL_BUFFER 0x82E0 +#define GL_SHADER 0x82E1 +#define GL_PROGRAM 0x82E2 +#define GL_QUERY 0x82E3 +/* PROGRAM_PIPELINE only in GL */ +#define GL_SAMPLER 0x82E6 +/* DISPLAY_LIST only in GL */ +#define GL_MAX_LABEL_LENGTH 0x82E8 +#define GL_MAX_DEBUG_MESSAGE_LENGTH 0x9143 +#define GL_MAX_DEBUG_LOGGED_MESSAGES 0x9144 +#define GL_DEBUG_LOGGED_MESSAGES 0x9145 +#define GL_DEBUG_SEVERITY_HIGH 0x9146 +#define GL_DEBUG_SEVERITY_MEDIUM 0x9147 +#define GL_DEBUG_SEVERITY_LOW 0x9148 +#define GL_DEBUG_OUTPUT 0x92E0 +#define GL_CONTEXT_FLAG_DEBUG_BIT 0x00000002 +#define GL_STACK_OVERFLOW 0x0503 +#define GL_STACK_UNDERFLOW 0x0504 +#endif + +#ifndef GL_KHR_texture_compression_astc_ldr +#define GL_COMPRESSED_RGBA_ASTC_4x4_KHR 0x93B0 +#define GL_COMPRESSED_RGBA_ASTC_5x4_KHR 0x93B1 +#define GL_COMPRESSED_RGBA_ASTC_5x5_KHR 0x93B2 +#define GL_COMPRESSED_RGBA_ASTC_6x5_KHR 0x93B3 +#define GL_COMPRESSED_RGBA_ASTC_6x6_KHR 0x93B4 +#define GL_COMPRESSED_RGBA_ASTC_8x5_KHR 0x93B5 +#define GL_COMPRESSED_RGBA_ASTC_8x6_KHR 0x93B6 +#define GL_COMPRESSED_RGBA_ASTC_8x8_KHR 0x93B7 +#define GL_COMPRESSED_RGBA_ASTC_10x5_KHR 0x93B8 +#define GL_COMPRESSED_RGBA_ASTC_10x6_KHR 0x93B9 +#define GL_COMPRESSED_RGBA_ASTC_10x8_KHR 0x93BA +#define GL_COMPRESSED_RGBA_ASTC_10x10_KHR 0x93BB +#define GL_COMPRESSED_RGBA_ASTC_12x10_KHR 0x93BC +#define GL_COMPRESSED_RGBA_ASTC_12x12_KHR 0x93BD +#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR 0x93D0 +#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR 0x93D1 +#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR 0x93D2 +#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR 0x93D3 +#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR 0x93D4 +#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR 0x93D5 +#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR 0x93D6 +#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR 0x93D7 +#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR 0x93D8 +#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR 0x93D9 +#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR 0x93DA +#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR 0x93DB +#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR 0x93DC +#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR 0x93DD +#endif + +/*------------------------------------------------------------------------* + * AMD extension tokens + *------------------------------------------------------------------------*/ + +/* GL_AMD_compressed_3DC_texture */ +#ifndef GL_AMD_compressed_3DC_texture +#define GL_3DC_X_AMD 0x87F9 +#define GL_3DC_XY_AMD 0x87FA +#endif + +/* GL_AMD_compressed_ATC_texture */ +#ifndef GL_AMD_compressed_ATC_texture +#define GL_ATC_RGB_AMD 0x8C92 +#define GL_ATC_RGBA_EXPLICIT_ALPHA_AMD 0x8C93 +#define GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD 0x87EE +#endif + +/* GL_AMD_performance_monitor */ +#ifndef GL_AMD_performance_monitor +#define GL_COUNTER_TYPE_AMD 0x8BC0 +#define GL_COUNTER_RANGE_AMD 0x8BC1 +#define GL_UNSIGNED_INT64_AMD 0x8BC2 +#define GL_PERCENTAGE_AMD 0x8BC3 +#define GL_PERFMON_RESULT_AVAILABLE_AMD 0x8BC4 +#define GL_PERFMON_RESULT_SIZE_AMD 0x8BC5 +#define GL_PERFMON_RESULT_AMD 0x8BC6 +#endif + +/* GL_AMD_program_binary_Z400 */ +#ifndef GL_AMD_program_binary_Z400 +#define GL_Z400_BINARY_AMD 0x8740 +#endif + +/*------------------------------------------------------------------------* + * ANGLE extension tokens + *------------------------------------------------------------------------*/ + +/* GL_ANGLE_framebuffer_blit */ +#ifndef GL_ANGLE_framebuffer_blit +#define GL_READ_FRAMEBUFFER_ANGLE 0x8CA8 +#define GL_DRAW_FRAMEBUFFER_ANGLE 0x8CA9 +#define GL_DRAW_FRAMEBUFFER_BINDING_ANGLE 0x8CA6 +#define GL_READ_FRAMEBUFFER_BINDING_ANGLE 0x8CAA +#endif + +/* GL_ANGLE_framebuffer_multisample */ +#ifndef GL_ANGLE_framebuffer_multisample +#define GL_RENDERBUFFER_SAMPLES_ANGLE 0x8CAB +#define GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_ANGLE 0x8D56 +#define GL_MAX_SAMPLES_ANGLE 0x8D57 +#endif + +/* GL_ANGLE_instanced_arrays */ +#ifndef GL_ANGLE_instanced_arrays +#define GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE 0x88FE +#endif + +/* GL_ANGLE_pack_reverse_row_order */ +#ifndef GL_ANGLE_pack_reverse_row_order +#define GL_PACK_REVERSE_ROW_ORDER_ANGLE 0x93A4 +#endif + +/* GL_ANGLE_texture_compression_dxt3 */ +#ifndef GL_ANGLE_texture_compression_dxt3 +#define GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE 0x83F2 +#endif + +/* GL_ANGLE_texture_compression_dxt5 */ +#ifndef GL_ANGLE_texture_compression_dxt5 +#define GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE 0x83F3 +#endif + +/* GL_ANGLE_texture_usage */ +#ifndef GL_ANGLE_texture_usage +#define GL_TEXTURE_USAGE_ANGLE 0x93A2 +#define GL_FRAMEBUFFER_ATTACHMENT_ANGLE 0x93A3 +#endif + +/* GL_ANGLE_translated_shader_source */ +#ifndef GL_ANGLE_translated_shader_source +#define GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE 0x93A0 +#endif + +/*------------------------------------------------------------------------* + * APPLE extension tokens + *------------------------------------------------------------------------*/ + +/* GL_APPLE_copy_texture_levels */ +/* No new tokens introduced by this extension. */ + +/* GL_APPLE_framebuffer_multisample */ +#ifndef GL_APPLE_framebuffer_multisample +#define GL_RENDERBUFFER_SAMPLES_APPLE 0x8CAB +#define GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_APPLE 0x8D56 +#define GL_MAX_SAMPLES_APPLE 0x8D57 +#define GL_READ_FRAMEBUFFER_APPLE 0x8CA8 +#define GL_DRAW_FRAMEBUFFER_APPLE 0x8CA9 +#define GL_DRAW_FRAMEBUFFER_BINDING_APPLE 0x8CA6 +#define GL_READ_FRAMEBUFFER_BINDING_APPLE 0x8CAA +#endif + +/* GL_APPLE_rgb_422 */ +#ifndef GL_APPLE_rgb_422 +#define GL_RGB_422_APPLE 0x8A1F +#define GL_UNSIGNED_SHORT_8_8_APPLE 0x85BA +#define GL_UNSIGNED_SHORT_8_8_REV_APPLE 0x85BB +#endif + +/* GL_APPLE_sync */ +#ifndef GL_APPLE_sync + +#ifndef __gl3_h_ +/* These types are defined with reference to + * in the Apple extension spec, but here we use the Khronos + * portable types in khrplatform.h, and assume those types + * are always defined. + * If any other extensions using these types are defined, + * the typedefs must move out of this block and be shared. + */ +typedef khronos_int64_t GLint64; +typedef khronos_uint64_t GLuint64; +typedef struct __GLsync *GLsync; +#endif + +#define GL_SYNC_OBJECT_APPLE 0x8A53 +#define GL_MAX_SERVER_WAIT_TIMEOUT_APPLE 0x9111 +#define GL_OBJECT_TYPE_APPLE 0x9112 +#define GL_SYNC_CONDITION_APPLE 0x9113 +#define GL_SYNC_STATUS_APPLE 0x9114 +#define GL_SYNC_FLAGS_APPLE 0x9115 +#define GL_SYNC_FENCE_APPLE 0x9116 +#define GL_SYNC_GPU_COMMANDS_COMPLETE_APPLE 0x9117 +#define GL_UNSIGNALED_APPLE 0x9118 +#define GL_SIGNALED_APPLE 0x9119 +#define GL_ALREADY_SIGNALED_APPLE 0x911A +#define GL_TIMEOUT_EXPIRED_APPLE 0x911B +#define GL_CONDITION_SATISFIED_APPLE 0x911C +#define GL_WAIT_FAILED_APPLE 0x911D +#define GL_SYNC_FLUSH_COMMANDS_BIT_APPLE 0x00000001 +#define GL_TIMEOUT_IGNORED_APPLE 0xFFFFFFFFFFFFFFFFull +#endif + +/* GL_APPLE_texture_format_BGRA8888 */ +#ifndef GL_APPLE_texture_format_BGRA8888 +#define GL_BGRA_EXT 0x80E1 +#endif + +/* GL_APPLE_texture_max_level */ +#ifndef GL_APPLE_texture_max_level +#define GL_TEXTURE_MAX_LEVEL_APPLE 0x813D +#endif + +/*------------------------------------------------------------------------* + * ARM extension tokens + *------------------------------------------------------------------------*/ + +/* GL_ARM_mali_program_binary */ +#ifndef GL_ARM_mali_program_binary +#define GL_MALI_PROGRAM_BINARY_ARM 0x8F61 +#endif + +/* GL_ARM_mali_shader_binary */ +#ifndef GL_ARM_mali_shader_binary +#define GL_MALI_SHADER_BINARY_ARM 0x8F60 +#endif + +/* GL_ARM_rgba8 */ +/* No new tokens introduced by this extension. */ + +/*------------------------------------------------------------------------* + * EXT extension tokens + *------------------------------------------------------------------------*/ + +/* GL_EXT_blend_minmax */ +#ifndef GL_EXT_blend_minmax +#define GL_MIN_EXT 0x8007 +#define GL_MAX_EXT 0x8008 +#endif + +/* GL_EXT_color_buffer_half_float */ +#ifndef GL_EXT_color_buffer_half_float +#define GL_RGBA16F_EXT 0x881A +#define GL_RGB16F_EXT 0x881B +#define GL_RG16F_EXT 0x822F +#define GL_R16F_EXT 0x822D +#define GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE_EXT 0x8211 +#define GL_UNSIGNED_NORMALIZED_EXT 0x8C17 +#endif + +/* GL_EXT_debug_label */ +#ifndef GL_EXT_debug_label +#define GL_PROGRAM_PIPELINE_OBJECT_EXT 0x8A4F +#define GL_PROGRAM_OBJECT_EXT 0x8B40 +#define GL_SHADER_OBJECT_EXT 0x8B48 +#define GL_BUFFER_OBJECT_EXT 0x9151 +#define GL_QUERY_OBJECT_EXT 0x9153 +#define GL_VERTEX_ARRAY_OBJECT_EXT 0x9154 +#endif + +/* GL_EXT_debug_marker */ +/* No new tokens introduced by this extension. */ + +/* GL_EXT_discard_framebuffer */ +#ifndef GL_EXT_discard_framebuffer +#define GL_COLOR_EXT 0x1800 +#define GL_DEPTH_EXT 0x1801 +#define GL_STENCIL_EXT 0x1802 +#endif + +/* GL_EXT_map_buffer_range */ +#ifndef GL_EXT_map_buffer_range +#define GL_MAP_READ_BIT_EXT 0x0001 +#define GL_MAP_WRITE_BIT_EXT 0x0002 +#define GL_MAP_INVALIDATE_RANGE_BIT_EXT 0x0004 +#define GL_MAP_INVALIDATE_BUFFER_BIT_EXT 0x0008 +#define GL_MAP_FLUSH_EXPLICIT_BIT_EXT 0x0010 +#define GL_MAP_UNSYNCHRONIZED_BIT_EXT 0x0020 +#endif + +/* GL_EXT_multisampled_render_to_texture */ +#ifndef GL_EXT_multisampled_render_to_texture +#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_SAMPLES_EXT 0x8D6C +/* reuse values from GL_EXT_framebuffer_multisample (desktop extension) */ +#define GL_RENDERBUFFER_SAMPLES_EXT 0x8CAB +#define GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_EXT 0x8D56 +#define GL_MAX_SAMPLES_EXT 0x8D57 +#endif + +/* GL_EXT_multiview_draw_buffers */ +#ifndef GL_EXT_multiview_draw_buffers +#define GL_COLOR_ATTACHMENT_EXT 0x90F0 +#define GL_MULTIVIEW_EXT 0x90F1 +#define GL_DRAW_BUFFER_EXT 0x0C01 +#define GL_READ_BUFFER_EXT 0x0C02 +#define GL_MAX_MULTIVIEW_BUFFERS_EXT 0x90F2 +#endif + +/* GL_EXT_multi_draw_arrays */ +/* No new tokens introduced by this extension. */ + +/* GL_EXT_occlusion_query_boolean */ +#ifndef GL_EXT_occlusion_query_boolean +#define GL_ANY_SAMPLES_PASSED_EXT 0x8C2F +#define GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT 0x8D6A +#define GL_CURRENT_QUERY_EXT 0x8865 +#define GL_QUERY_RESULT_EXT 0x8866 +#define GL_QUERY_RESULT_AVAILABLE_EXT 0x8867 +#endif + +/* GL_EXT_read_format_bgra */ +#ifndef GL_EXT_read_format_bgra +#define GL_BGRA_EXT 0x80E1 +#define GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT 0x8365 +#define GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT 0x8366 +#endif + +/* GL_EXT_robustness */ +#ifndef GL_EXT_robustness +/* reuse GL_NO_ERROR */ +#define GL_GUILTY_CONTEXT_RESET_EXT 0x8253 +#define GL_INNOCENT_CONTEXT_RESET_EXT 0x8254 +#define GL_UNKNOWN_CONTEXT_RESET_EXT 0x8255 +#define GL_CONTEXT_ROBUST_ACCESS_EXT 0x90F3 +#define GL_RESET_NOTIFICATION_STRATEGY_EXT 0x8256 +#define GL_LOSE_CONTEXT_ON_RESET_EXT 0x8252 +#define GL_NO_RESET_NOTIFICATION_EXT 0x8261 +#endif + +/* GL_EXT_separate_shader_objects */ +#ifndef GL_EXT_separate_shader_objects +#define GL_VERTEX_SHADER_BIT_EXT 0x00000001 +#define GL_FRAGMENT_SHADER_BIT_EXT 0x00000002 +#define GL_ALL_SHADER_BITS_EXT 0xFFFFFFFF +#define GL_PROGRAM_SEPARABLE_EXT 0x8258 +#define GL_ACTIVE_PROGRAM_EXT 0x8259 +#define GL_PROGRAM_PIPELINE_BINDING_EXT 0x825A +#endif + +/* GL_EXT_shader_framebuffer_fetch */ +#ifndef GL_EXT_shader_framebuffer_fetch +#define GL_FRAGMENT_SHADER_DISCARDS_SAMPLES_EXT 0x8A52 +#endif + +/* GL_EXT_shader_texture_lod */ +/* No new tokens introduced by this extension. */ + +/* GL_EXT_shadow_samplers */ +#ifndef GL_EXT_shadow_samplers +#define GL_TEXTURE_COMPARE_MODE_EXT 0x884C +#define GL_TEXTURE_COMPARE_FUNC_EXT 0x884D +#define GL_COMPARE_REF_TO_TEXTURE_EXT 0x884E +#define GL_SAMPLER_2D_SHADOW_EXT 0x8B62 +#endif + +/* GL_EXT_sRGB */ +#ifndef GL_EXT_sRGB +#define GL_SRGB_EXT 0x8C40 +#define GL_SRGB_ALPHA_EXT 0x8C42 +#define GL_SRGB8_ALPHA8_EXT 0x8C43 +#define GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING_EXT 0x8210 +#endif + +/* GL_EXT_texture_compression_dxt1 */ +#ifndef GL_EXT_texture_compression_dxt1 +#define GL_COMPRESSED_RGB_S3TC_DXT1_EXT 0x83F0 +#define GL_COMPRESSED_RGBA_S3TC_DXT1_EXT 0x83F1 +#endif + +/* GL_EXT_texture_filter_anisotropic */ +#ifndef GL_EXT_texture_filter_anisotropic +#define GL_TEXTURE_MAX_ANISOTROPY_EXT 0x84FE +#define GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT 0x84FF +#endif + +/* GL_EXT_texture_format_BGRA8888 */ +#ifndef GL_EXT_texture_format_BGRA8888 +#define GL_BGRA_EXT 0x80E1 +#endif + +/* GL_EXT_texture_rg */ +#ifndef GL_EXT_texture_rg +#define GL_RED_EXT 0x1903 +#define GL_RG_EXT 0x8227 +#define GL_R8_EXT 0x8229 +#define GL_RG8_EXT 0x822B +#endif + +/* GL_EXT_texture_storage */ +#ifndef GL_EXT_texture_storage +#define GL_TEXTURE_IMMUTABLE_FORMAT_EXT 0x912F +#define GL_ALPHA8_EXT 0x803C +#define GL_LUMINANCE8_EXT 0x8040 +#define GL_LUMINANCE8_ALPHA8_EXT 0x8045 +#define GL_RGBA32F_EXT 0x8814 +#define GL_RGB32F_EXT 0x8815 +#define GL_ALPHA32F_EXT 0x8816 +#define GL_LUMINANCE32F_EXT 0x8818 +#define GL_LUMINANCE_ALPHA32F_EXT 0x8819 +/* reuse GL_RGBA16F_EXT */ +/* reuse GL_RGB16F_EXT */ +#define GL_ALPHA16F_EXT 0x881C +#define GL_LUMINANCE16F_EXT 0x881E +#define GL_LUMINANCE_ALPHA16F_EXT 0x881F +#define GL_RGB10_A2_EXT 0x8059 +#define GL_RGB10_EXT 0x8052 +#define GL_BGRA8_EXT 0x93A1 +#define GL_R8_EXT 0x8229 +#define GL_RG8_EXT 0x822B +#define GL_R32F_EXT 0x822E +#define GL_RG32F_EXT 0x8230 +#define GL_R16F_EXT 0x822D +#define GL_RG16F_EXT 0x822F +#endif + +/* GL_EXT_texture_type_2_10_10_10_REV */ +#ifndef GL_EXT_texture_type_2_10_10_10_REV +#define GL_UNSIGNED_INT_2_10_10_10_REV_EXT 0x8368 +#endif + +/* GL_EXT_unpack_subimage */ +#ifndef GL_EXT_unpack_subimage +#define GL_UNPACK_ROW_LENGTH 0x0CF2 +#define GL_UNPACK_SKIP_ROWS 0x0CF3 +#define GL_UNPACK_SKIP_PIXELS 0x0CF4 +#endif + +/*------------------------------------------------------------------------* + * DMP extension tokens + *------------------------------------------------------------------------*/ + +/* GL_DMP_shader_binary */ +#ifndef GL_DMP_shader_binary +#define GL_SHADER_BINARY_DMP 0x9250 +#endif + +/*------------------------------------------------------------------------* + * FJ extension tokens + *------------------------------------------------------------------------*/ + +/* GL_FJ_shader_binary_GCCSO */ +#ifndef GL_FJ_shader_binary_GCCSO +#define GCCSO_SHADER_BINARY_FJ 0x9260 +#endif + +/*------------------------------------------------------------------------* + * IMG extension tokens + *------------------------------------------------------------------------*/ + +/* GL_IMG_program_binary */ +#ifndef GL_IMG_program_binary +#define GL_SGX_PROGRAM_BINARY_IMG 0x9130 +#endif + +/* GL_IMG_read_format */ +#ifndef GL_IMG_read_format +#define GL_BGRA_IMG 0x80E1 +#define GL_UNSIGNED_SHORT_4_4_4_4_REV_IMG 0x8365 +#endif + +/* GL_IMG_shader_binary */ +#ifndef GL_IMG_shader_binary +#define GL_SGX_BINARY_IMG 0x8C0A +#endif + +/* GL_IMG_texture_compression_pvrtc */ +#ifndef GL_IMG_texture_compression_pvrtc +#define GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG 0x8C00 +#define GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG 0x8C01 +#define GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG 0x8C02 +#define GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG 0x8C03 +#endif + +/* GL_IMG_multisampled_render_to_texture */ +#ifndef GL_IMG_multisampled_render_to_texture +#define GL_RENDERBUFFER_SAMPLES_IMG 0x9133 +#define GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_IMG 0x9134 +#define GL_MAX_SAMPLES_IMG 0x9135 +#define GL_TEXTURE_SAMPLES_IMG 0x9136 +#endif + +/*------------------------------------------------------------------------* + * NV extension tokens + *------------------------------------------------------------------------*/ + +/* GL_NV_coverage_sample */ +#ifndef GL_NV_coverage_sample +#define GL_COVERAGE_COMPONENT_NV 0x8ED0 +#define GL_COVERAGE_COMPONENT4_NV 0x8ED1 +#define GL_COVERAGE_ATTACHMENT_NV 0x8ED2 +#define GL_COVERAGE_BUFFERS_NV 0x8ED3 +#define GL_COVERAGE_SAMPLES_NV 0x8ED4 +#define GL_COVERAGE_ALL_FRAGMENTS_NV 0x8ED5 +#define GL_COVERAGE_EDGE_FRAGMENTS_NV 0x8ED6 +#define GL_COVERAGE_AUTOMATIC_NV 0x8ED7 +#define GL_COVERAGE_BUFFER_BIT_NV 0x8000 +#endif + +/* GL_NV_depth_nonlinear */ +#ifndef GL_NV_depth_nonlinear +#define GL_DEPTH_COMPONENT16_NONLINEAR_NV 0x8E2C +#endif + +/* GL_NV_draw_buffers */ +#ifndef GL_NV_draw_buffers +#define GL_MAX_DRAW_BUFFERS_NV 0x8824 +#define GL_DRAW_BUFFER0_NV 0x8825 +#define GL_DRAW_BUFFER1_NV 0x8826 +#define GL_DRAW_BUFFER2_NV 0x8827 +#define GL_DRAW_BUFFER3_NV 0x8828 +#define GL_DRAW_BUFFER4_NV 0x8829 +#define GL_DRAW_BUFFER5_NV 0x882A +#define GL_DRAW_BUFFER6_NV 0x882B +#define GL_DRAW_BUFFER7_NV 0x882C +#define GL_DRAW_BUFFER8_NV 0x882D +#define GL_DRAW_BUFFER9_NV 0x882E +#define GL_DRAW_BUFFER10_NV 0x882F +#define GL_DRAW_BUFFER11_NV 0x8830 +#define GL_DRAW_BUFFER12_NV 0x8831 +#define GL_DRAW_BUFFER13_NV 0x8832 +#define GL_DRAW_BUFFER14_NV 0x8833 +#define GL_DRAW_BUFFER15_NV 0x8834 +#define GL_COLOR_ATTACHMENT0_NV 0x8CE0 +#define GL_COLOR_ATTACHMENT1_NV 0x8CE1 +#define GL_COLOR_ATTACHMENT2_NV 0x8CE2 +#define GL_COLOR_ATTACHMENT3_NV 0x8CE3 +#define GL_COLOR_ATTACHMENT4_NV 0x8CE4 +#define GL_COLOR_ATTACHMENT5_NV 0x8CE5 +#define GL_COLOR_ATTACHMENT6_NV 0x8CE6 +#define GL_COLOR_ATTACHMENT7_NV 0x8CE7 +#define GL_COLOR_ATTACHMENT8_NV 0x8CE8 +#define GL_COLOR_ATTACHMENT9_NV 0x8CE9 +#define GL_COLOR_ATTACHMENT10_NV 0x8CEA +#define GL_COLOR_ATTACHMENT11_NV 0x8CEB +#define GL_COLOR_ATTACHMENT12_NV 0x8CEC +#define GL_COLOR_ATTACHMENT13_NV 0x8CED +#define GL_COLOR_ATTACHMENT14_NV 0x8CEE +#define GL_COLOR_ATTACHMENT15_NV 0x8CEF +#endif + +/* GL_NV_fbo_color_attachments */ +#ifndef GL_NV_fbo_color_attachments +#define GL_MAX_COLOR_ATTACHMENTS_NV 0x8CDF +/* GL_COLOR_ATTACHMENT{0-15}_NV defined in GL_NV_draw_buffers already. */ +#endif + +/* GL_NV_fence */ +#ifndef GL_NV_fence +#define GL_ALL_COMPLETED_NV 0x84F2 +#define GL_FENCE_STATUS_NV 0x84F3 +#define GL_FENCE_CONDITION_NV 0x84F4 +#endif + +/* GL_NV_read_buffer */ +#ifndef GL_NV_read_buffer +#define GL_READ_BUFFER_NV 0x0C02 +#endif + +/* GL_NV_read_buffer_front */ +/* No new tokens introduced by this extension. */ + +/* GL_NV_read_depth */ +/* No new tokens introduced by this extension. */ + +/* GL_NV_read_depth_stencil */ +/* No new tokens introduced by this extension. */ + +/* GL_NV_read_stencil */ +/* No new tokens introduced by this extension. */ + +/* GL_NV_texture_compression_s3tc_update */ +/* No new tokens introduced by this extension. */ + +/* GL_NV_texture_npot_2D_mipmap */ +/* No new tokens introduced by this extension. */ + +/*------------------------------------------------------------------------* + * QCOM extension tokens + *------------------------------------------------------------------------*/ + +/* GL_QCOM_alpha_test */ +#ifndef GL_QCOM_alpha_test +#define GL_ALPHA_TEST_QCOM 0x0BC0 +#define GL_ALPHA_TEST_FUNC_QCOM 0x0BC1 +#define GL_ALPHA_TEST_REF_QCOM 0x0BC2 +#endif + +/* GL_QCOM_binning_control */ +#ifndef GL_QCOM_binning_control +#define GL_BINNING_CONTROL_HINT_QCOM 0x8FB0 +#define GL_CPU_OPTIMIZED_QCOM 0x8FB1 +#define GL_GPU_OPTIMIZED_QCOM 0x8FB2 +#define GL_RENDER_DIRECT_TO_FRAMEBUFFER_QCOM 0x8FB3 +#endif + +/* GL_QCOM_driver_control */ +/* No new tokens introduced by this extension. */ + +/* GL_QCOM_extended_get */ +#ifndef GL_QCOM_extended_get +#define GL_TEXTURE_WIDTH_QCOM 0x8BD2 +#define GL_TEXTURE_HEIGHT_QCOM 0x8BD3 +#define GL_TEXTURE_DEPTH_QCOM 0x8BD4 +#define GL_TEXTURE_INTERNAL_FORMAT_QCOM 0x8BD5 +#define GL_TEXTURE_FORMAT_QCOM 0x8BD6 +#define GL_TEXTURE_TYPE_QCOM 0x8BD7 +#define GL_TEXTURE_IMAGE_VALID_QCOM 0x8BD8 +#define GL_TEXTURE_NUM_LEVELS_QCOM 0x8BD9 +#define GL_TEXTURE_TARGET_QCOM 0x8BDA +#define GL_TEXTURE_OBJECT_VALID_QCOM 0x8BDB +#define GL_STATE_RESTORE 0x8BDC +#endif + +/* GL_QCOM_extended_get2 */ +/* No new tokens introduced by this extension. */ + +/* GL_QCOM_perfmon_global_mode */ +#ifndef GL_QCOM_perfmon_global_mode +#define GL_PERFMON_GLOBAL_MODE_QCOM 0x8FA0 +#endif + +/* GL_QCOM_writeonly_rendering */ +#ifndef GL_QCOM_writeonly_rendering +#define GL_WRITEONLY_RENDERING_QCOM 0x8823 +#endif + +/* GL_QCOM_tiled_rendering */ +#ifndef GL_QCOM_tiled_rendering +#define GL_COLOR_BUFFER_BIT0_QCOM 0x00000001 +#define GL_COLOR_BUFFER_BIT1_QCOM 0x00000002 +#define GL_COLOR_BUFFER_BIT2_QCOM 0x00000004 +#define GL_COLOR_BUFFER_BIT3_QCOM 0x00000008 +#define GL_COLOR_BUFFER_BIT4_QCOM 0x00000010 +#define GL_COLOR_BUFFER_BIT5_QCOM 0x00000020 +#define GL_COLOR_BUFFER_BIT6_QCOM 0x00000040 +#define GL_COLOR_BUFFER_BIT7_QCOM 0x00000080 +#define GL_DEPTH_BUFFER_BIT0_QCOM 0x00000100 +#define GL_DEPTH_BUFFER_BIT1_QCOM 0x00000200 +#define GL_DEPTH_BUFFER_BIT2_QCOM 0x00000400 +#define GL_DEPTH_BUFFER_BIT3_QCOM 0x00000800 +#define GL_DEPTH_BUFFER_BIT4_QCOM 0x00001000 +#define GL_DEPTH_BUFFER_BIT5_QCOM 0x00002000 +#define GL_DEPTH_BUFFER_BIT6_QCOM 0x00004000 +#define GL_DEPTH_BUFFER_BIT7_QCOM 0x00008000 +#define GL_STENCIL_BUFFER_BIT0_QCOM 0x00010000 +#define GL_STENCIL_BUFFER_BIT1_QCOM 0x00020000 +#define GL_STENCIL_BUFFER_BIT2_QCOM 0x00040000 +#define GL_STENCIL_BUFFER_BIT3_QCOM 0x00080000 +#define GL_STENCIL_BUFFER_BIT4_QCOM 0x00100000 +#define GL_STENCIL_BUFFER_BIT5_QCOM 0x00200000 +#define GL_STENCIL_BUFFER_BIT6_QCOM 0x00400000 +#define GL_STENCIL_BUFFER_BIT7_QCOM 0x00800000 +#define GL_MULTISAMPLE_BUFFER_BIT0_QCOM 0x01000000 +#define GL_MULTISAMPLE_BUFFER_BIT1_QCOM 0x02000000 +#define GL_MULTISAMPLE_BUFFER_BIT2_QCOM 0x04000000 +#define GL_MULTISAMPLE_BUFFER_BIT3_QCOM 0x08000000 +#define GL_MULTISAMPLE_BUFFER_BIT4_QCOM 0x10000000 +#define GL_MULTISAMPLE_BUFFER_BIT5_QCOM 0x20000000 +#define GL_MULTISAMPLE_BUFFER_BIT6_QCOM 0x40000000 +#define GL_MULTISAMPLE_BUFFER_BIT7_QCOM 0x80000000 +#endif + +/*------------------------------------------------------------------------* + * VIV extension tokens + *------------------------------------------------------------------------*/ + +/* GL_VIV_shader_binary */ +#ifndef GL_VIV_shader_binary +#define GL_SHADER_BINARY_VIV 0x8FC4 +#endif + +/*------------------------------------------------------------------------* + * End of extension tokens, start of corresponding extension functions + *------------------------------------------------------------------------*/ + +/*------------------------------------------------------------------------* + * OES extension functions + *------------------------------------------------------------------------*/ + +/* GL_OES_compressed_ETC1_RGB8_texture */ +#ifndef GL_OES_compressed_ETC1_RGB8_texture +#define GL_OES_compressed_ETC1_RGB8_texture 1 +#endif + +/* GL_OES_compressed_paletted_texture */ +#ifndef GL_OES_compressed_paletted_texture +#define GL_OES_compressed_paletted_texture 1 +#endif + +/* GL_OES_depth24 */ +#ifndef GL_OES_depth24 +#define GL_OES_depth24 1 +#endif + +/* GL_OES_depth32 */ +#ifndef GL_OES_depth32 +#define GL_OES_depth32 1 +#endif + +/* GL_OES_depth_texture */ +#ifndef GL_OES_depth_texture +#define GL_OES_depth_texture 1 +#endif + +/* GL_OES_EGL_image */ +#ifndef GL_OES_EGL_image +#define GL_OES_EGL_image 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_APICALL void GL_APIENTRY glEGLImageTargetTexture2DOES (GLenum target, GLeglImageOES image); +GL_APICALL void GL_APIENTRY glEGLImageTargetRenderbufferStorageOES (GLenum target, GLeglImageOES image); +#endif +typedef void (GL_APIENTRYP PFNGLEGLIMAGETARGETTEXTURE2DOESPROC) (GLenum target, GLeglImageOES image); +typedef void (GL_APIENTRYP PFNGLEGLIMAGETARGETRENDERBUFFERSTORAGEOESPROC) (GLenum target, GLeglImageOES image); +#endif + +/* GL_OES_EGL_image_external */ +#ifndef GL_OES_EGL_image_external +#define GL_OES_EGL_image_external 1 +/* glEGLImageTargetTexture2DOES defined in GL_OES_EGL_image already. */ +#endif + +/* GL_OES_element_index_uint */ +#ifndef GL_OES_element_index_uint +#define GL_OES_element_index_uint 1 +#endif + +/* GL_OES_fbo_render_mipmap */ +#ifndef GL_OES_fbo_render_mipmap +#define GL_OES_fbo_render_mipmap 1 +#endif + +/* GL_OES_fragment_precision_high */ +#ifndef GL_OES_fragment_precision_high +#define GL_OES_fragment_precision_high 1 +#endif + +/* GL_OES_get_program_binary */ +#ifndef GL_OES_get_program_binary +#define GL_OES_get_program_binary 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_APICALL void GL_APIENTRY glGetProgramBinaryOES (GLuint program, GLsizei bufSize, GLsizei *length, GLenum *binaryFormat, GLvoid *binary); +GL_APICALL void GL_APIENTRY glProgramBinaryOES (GLuint program, GLenum binaryFormat, const GLvoid *binary, GLint length); +#endif +typedef void (GL_APIENTRYP PFNGLGETPROGRAMBINARYOESPROC) (GLuint program, GLsizei bufSize, GLsizei *length, GLenum *binaryFormat, GLvoid *binary); +typedef void (GL_APIENTRYP PFNGLPROGRAMBINARYOESPROC) (GLuint program, GLenum binaryFormat, const GLvoid *binary, GLint length); +#endif + +/* GL_OES_mapbuffer */ +#ifndef GL_OES_mapbuffer +#define GL_OES_mapbuffer 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_APICALL void* GL_APIENTRY glMapBufferOES (GLenum target, GLenum access); +GL_APICALL GLboolean GL_APIENTRY glUnmapBufferOES (GLenum target); +GL_APICALL void GL_APIENTRY glGetBufferPointervOES (GLenum target, GLenum pname, GLvoid** params); +#endif +typedef void* (GL_APIENTRYP PFNGLMAPBUFFEROESPROC) (GLenum target, GLenum access); +typedef GLboolean (GL_APIENTRYP PFNGLUNMAPBUFFEROESPROC) (GLenum target); +typedef void (GL_APIENTRYP PFNGLGETBUFFERPOINTERVOESPROC) (GLenum target, GLenum pname, GLvoid** params); +#endif + +/* GL_OES_packed_depth_stencil */ +#ifndef GL_OES_packed_depth_stencil +#define GL_OES_packed_depth_stencil 1 +#endif + +/* GL_OES_required_internalformat */ +#ifndef GL_OES_required_internalformat +#define GL_OES_required_internalformat 1 +#endif + +/* GL_OES_rgb8_rgba8 */ +#ifndef GL_OES_rgb8_rgba8 +#define GL_OES_rgb8_rgba8 1 +#endif + +/* GL_OES_standard_derivatives */ +#ifndef GL_OES_standard_derivatives +#define GL_OES_standard_derivatives 1 +#endif + +/* GL_OES_stencil1 */ +#ifndef GL_OES_stencil1 +#define GL_OES_stencil1 1 +#endif + +/* GL_OES_stencil4 */ +#ifndef GL_OES_stencil4 +#define GL_OES_stencil4 1 +#endif + +#ifndef GL_OES_surfaceless_context +#define GL_OES_surfaceless_context 1 +#endif + +/* GL_OES_texture_3D */ +#ifndef GL_OES_texture_3D +#define GL_OES_texture_3D 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_APICALL void GL_APIENTRY glTexImage3DOES (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid* pixels); +GL_APICALL void GL_APIENTRY glTexSubImage3DOES (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid* pixels); +GL_APICALL void GL_APIENTRY glCopyTexSubImage3DOES (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height); +GL_APICALL void GL_APIENTRY glCompressedTexImage3DOES (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid* data); +GL_APICALL void GL_APIENTRY glCompressedTexSubImage3DOES (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid* data); +GL_APICALL void GL_APIENTRY glFramebufferTexture3DOES (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset); +#endif +typedef void (GL_APIENTRYP PFNGLTEXIMAGE3DOESPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid* pixels); +typedef void (GL_APIENTRYP PFNGLTEXSUBIMAGE3DOESPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid* pixels); +typedef void (GL_APIENTRYP PFNGLCOPYTEXSUBIMAGE3DOESPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height); +typedef void (GL_APIENTRYP PFNGLCOMPRESSEDTEXIMAGE3DOESPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid* data); +typedef void (GL_APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE3DOESPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid* data); +typedef void (GL_APIENTRYP PFNGLFRAMEBUFFERTEXTURE3DOES) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset); +#endif + +/* GL_OES_texture_float */ +#ifndef GL_OES_texture_float +#define GL_OES_texture_float 1 +#endif + +/* GL_OES_texture_float_linear */ +#ifndef GL_OES_texture_float_linear +#define GL_OES_texture_float_linear 1 +#endif + +/* GL_OES_texture_half_float */ +#ifndef GL_OES_texture_half_float +#define GL_OES_texture_half_float 1 +#endif + +/* GL_OES_texture_half_float_linear */ +#ifndef GL_OES_texture_half_float_linear +#define GL_OES_texture_half_float_linear 1 +#endif + +/* GL_OES_texture_npot */ +#ifndef GL_OES_texture_npot +#define GL_OES_texture_npot 1 +#endif + +/* GL_OES_vertex_array_object */ +#ifndef GL_OES_vertex_array_object +#define GL_OES_vertex_array_object 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_APICALL void GL_APIENTRY glBindVertexArrayOES (GLuint array); +GL_APICALL void GL_APIENTRY glDeleteVertexArraysOES (GLsizei n, const GLuint *arrays); +GL_APICALL void GL_APIENTRY glGenVertexArraysOES (GLsizei n, GLuint *arrays); +GL_APICALL GLboolean GL_APIENTRY glIsVertexArrayOES (GLuint array); +#endif +typedef void (GL_APIENTRYP PFNGLBINDVERTEXARRAYOESPROC) (GLuint array); +typedef void (GL_APIENTRYP PFNGLDELETEVERTEXARRAYSOESPROC) (GLsizei n, const GLuint *arrays); +typedef void (GL_APIENTRYP PFNGLGENVERTEXARRAYSOESPROC) (GLsizei n, GLuint *arrays); +typedef GLboolean (GL_APIENTRYP PFNGLISVERTEXARRAYOESPROC) (GLuint array); +#endif + +/* GL_OES_vertex_half_float */ +#ifndef GL_OES_vertex_half_float +#define GL_OES_vertex_half_float 1 +#endif + +/* GL_OES_vertex_type_10_10_10_2 */ +#ifndef GL_OES_vertex_type_10_10_10_2 +#define GL_OES_vertex_type_10_10_10_2 1 +#endif + +/*------------------------------------------------------------------------* + * KHR extension functions + *------------------------------------------------------------------------*/ + +#ifndef GL_KHR_debug +#define GL_KHR_debug 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_APICALL void GL_APIENTRY glDebugMessageControl (GLenum source, GLenum type, GLenum severity, GLsizei count, const GLuint *ids, GLboolean enabled); +GL_APICALL void GL_APIENTRY glDebugMessageInsert (GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *buf); +GL_APICALL void GL_APIENTRY glDebugMessageCallback (GLDEBUGPROC callback, const void *userParam); +GL_APICALL GLuint GL_APIENTRY glGetDebugMessageLog (GLuint count, GLsizei bufsize, GLenum *sources, GLenum *types, GLuint *ids, GLenum *severities, GLsizei *lengths, GLchar *messageLog); +GL_APICALL void GL_APIENTRY glPushDebugGroup (GLenum source, GLuint id, GLsizei length, const GLchar *message); +GL_APICALL void GL_APIENTRY glPopDebugGroup (void); +GL_APICALL void GL_APIENTRY glObjectLabel (GLenum identifier, GLuint name, GLsizei length, const GLchar *label); +GL_APICALL void GL_APIENTRY glGetObjectLabel (GLenum identifier, GLuint name, GLsizei bufSize, GLsizei *length, GLchar *label); +GL_APICALL void GL_APIENTRY glObjectPtrLabel (const void *ptr, GLsizei length, const GLchar *label); +GL_APICALL void GL_APIENTRY glGetObjectPtrLabel (const void *ptr, GLsizei bufSize, GLsizei *length, GLchar *label); +GL_APICALL void GL_APIENTRY glGetPointerv (GLenum pname, void **params); +#endif +typedef void (GL_APIENTRYP PFNGLDEBUGMESSAGECONTROLPROC) (GLenum source, GLenum type, GLenum severity, GLsizei count, const GLuint *ids, GLboolean enabled); +typedef void (GL_APIENTRYP PFNGLDEBUGMESSAGEINSERTPROC) (GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *buf); +typedef void (GL_APIENTRYP PFNGLDEBUGMESSAGECALLBACKPROC) (GLDEBUGPROC callback, const void *userParam); +typedef GLuint (GL_APIENTRYP PFNGLGETDEBUGMESSAGELOGPROC) (GLuint count, GLsizei bufsize, GLenum *sources, GLenum *types, GLuint *ids, GLenum *severities, GLsizei *lengths, GLchar *messageLog); +typedef void (GL_APIENTRYP PFNGLPUSHDEBUGGROUPPROC) (GLenum source, GLuint id, GLsizei length, const GLchar *message); +typedef void (GL_APIENTRYP PFNGLPOPDEBUGGROUPPROC) (void); +typedef void (GL_APIENTRYP PFNGLOBJECTLABELPROC) (GLenum identifier, GLuint name, GLsizei length, const GLchar *label); +typedef void (GL_APIENTRYP PFNGLGETOBJECTLABELPROC) (GLenum identifier, GLuint name, GLsizei bufSize, GLsizei *length, GLchar *label); +typedef void (GL_APIENTRYP PFNGLOBJECTPTRLABELPROC) (const void *ptr, GLsizei length, const GLchar *label); +typedef void (GL_APIENTRYP PFNGLGETOBJECTPTRLABELPROC) (const void *ptr, GLsizei bufSize, GLsizei *length, GLchar *label); +typedef void (GL_APIENTRYP PFNGLGETPOINTERVPROC) (GLenum pname, void **params); +#endif + +#ifndef GL_KHR_texture_compression_astc_ldr +#define GL_KHR_texture_compression_astc_ldr 1 +#endif + + +/*------------------------------------------------------------------------* + * AMD extension functions + *------------------------------------------------------------------------*/ + +/* GL_AMD_compressed_3DC_texture */ +#ifndef GL_AMD_compressed_3DC_texture +#define GL_AMD_compressed_3DC_texture 1 +#endif + +/* GL_AMD_compressed_ATC_texture */ +#ifndef GL_AMD_compressed_ATC_texture +#define GL_AMD_compressed_ATC_texture 1 +#endif + +/* AMD_performance_monitor */ +#ifndef GL_AMD_performance_monitor +#define GL_AMD_performance_monitor 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_APICALL void GL_APIENTRY glGetPerfMonitorGroupsAMD (GLint *numGroups, GLsizei groupsSize, GLuint *groups); +GL_APICALL void GL_APIENTRY glGetPerfMonitorCountersAMD (GLuint group, GLint *numCounters, GLint *maxActiveCounters, GLsizei counterSize, GLuint *counters); +GL_APICALL void GL_APIENTRY glGetPerfMonitorGroupStringAMD (GLuint group, GLsizei bufSize, GLsizei *length, GLchar *groupString); +GL_APICALL void GL_APIENTRY glGetPerfMonitorCounterStringAMD (GLuint group, GLuint counter, GLsizei bufSize, GLsizei *length, GLchar *counterString); +GL_APICALL void GL_APIENTRY glGetPerfMonitorCounterInfoAMD (GLuint group, GLuint counter, GLenum pname, GLvoid *data); +GL_APICALL void GL_APIENTRY glGenPerfMonitorsAMD (GLsizei n, GLuint *monitors); +GL_APICALL void GL_APIENTRY glDeletePerfMonitorsAMD (GLsizei n, GLuint *monitors); +GL_APICALL void GL_APIENTRY glSelectPerfMonitorCountersAMD (GLuint monitor, GLboolean enable, GLuint group, GLint numCounters, GLuint *countersList); +GL_APICALL void GL_APIENTRY glBeginPerfMonitorAMD (GLuint monitor); +GL_APICALL void GL_APIENTRY glEndPerfMonitorAMD (GLuint monitor); +GL_APICALL void GL_APIENTRY glGetPerfMonitorCounterDataAMD (GLuint monitor, GLenum pname, GLsizei dataSize, GLuint *data, GLint *bytesWritten); +#endif +typedef void (GL_APIENTRYP PFNGLGETPERFMONITORGROUPSAMDPROC) (GLint *numGroups, GLsizei groupsSize, GLuint *groups); +typedef void (GL_APIENTRYP PFNGLGETPERFMONITORCOUNTERSAMDPROC) (GLuint group, GLint *numCounters, GLint *maxActiveCounters, GLsizei counterSize, GLuint *counters); +typedef void (GL_APIENTRYP PFNGLGETPERFMONITORGROUPSTRINGAMDPROC) (GLuint group, GLsizei bufSize, GLsizei *length, GLchar *groupString); +typedef void (GL_APIENTRYP PFNGLGETPERFMONITORCOUNTERSTRINGAMDPROC) (GLuint group, GLuint counter, GLsizei bufSize, GLsizei *length, GLchar *counterString); +typedef void (GL_APIENTRYP PFNGLGETPERFMONITORCOUNTERINFOAMDPROC) (GLuint group, GLuint counter, GLenum pname, GLvoid *data); +typedef void (GL_APIENTRYP PFNGLGENPERFMONITORSAMDPROC) (GLsizei n, GLuint *monitors); +typedef void (GL_APIENTRYP PFNGLDELETEPERFMONITORSAMDPROC) (GLsizei n, GLuint *monitors); +typedef void (GL_APIENTRYP PFNGLSELECTPERFMONITORCOUNTERSAMDPROC) (GLuint monitor, GLboolean enable, GLuint group, GLint numCounters, GLuint *countersList); +typedef void (GL_APIENTRYP PFNGLBEGINPERFMONITORAMDPROC) (GLuint monitor); +typedef void (GL_APIENTRYP PFNGLENDPERFMONITORAMDPROC) (GLuint monitor); +typedef void (GL_APIENTRYP PFNGLGETPERFMONITORCOUNTERDATAAMDPROC) (GLuint monitor, GLenum pname, GLsizei dataSize, GLuint *data, GLint *bytesWritten); +#endif + +/* GL_AMD_program_binary_Z400 */ +#ifndef GL_AMD_program_binary_Z400 +#define GL_AMD_program_binary_Z400 1 +#endif + +/*------------------------------------------------------------------------* + * ANGLE extension functions + *------------------------------------------------------------------------*/ + +/* GL_ANGLE_framebuffer_blit */ +#ifndef GL_ANGLE_framebuffer_blit +#define GL_ANGLE_framebuffer_blit 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_APICALL void GL_APIENTRY glBlitFramebufferANGLE (GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter); +#endif +typedef void (GL_APIENTRYP PFNGLBLITFRAMEBUFFERANGLEPROC) (GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter); +#endif + +/* GL_ANGLE_framebuffer_multisample */ +#ifndef GL_ANGLE_framebuffer_multisample +#define GL_ANGLE_framebuffer_multisample 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_APICALL void GL_APIENTRY glRenderbufferStorageMultisampleANGLE (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height); +#endif +typedef void (GL_APIENTRYP PFNGLRENDERBUFFERSTORAGEMULTISAMPLEANGLEPROC) (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height); +#endif + +#ifndef GL_ANGLE_instanced_arrays +#ifdef GL_GLEXT_PROTOTYPES +GL_APICALL void GL_APIENTRY glDrawArraysInstancedANGLE (GLenum mode, GLint first, GLsizei count, GLsizei primcount); +GL_APICALL void GL_APIENTRY glDrawElementsInstancedANGLE (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei primcount); +GL_APICALL void GL_APIENTRY glVertexAttribDivisorANGLE (GLuint index, GLuint divisor); +#endif +typedef void (GL_APIENTRYP PFLGLDRAWARRAYSINSTANCEDANGLEPROC) (GLenum mode, GLint first, GLsizei count, GLsizei primcount); +typedef void (GL_APIENTRYP PFLGLDRAWELEMENTSINSTANCEDANGLEPROC) (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei primcount); +typedef void (GL_APIENTRYP PFLGLVERTEXATTRIBDIVISORANGLEPROC) (GLuint index, GLuint divisor); +#endif + +/* GL_ANGLE_pack_reverse_row_order */ +#ifndef GL_ANGLE_pack_reverse_row_order +#define GL_ANGLE_pack_reverse_row_order 1 +#endif + +/* GL_ANGLE_texture_compression_dxt3 */ +#ifndef GL_ANGLE_texture_compression_dxt3 +#define GL_ANGLE_texture_compression_dxt3 1 +#endif + +/* GL_ANGLE_texture_compression_dxt5 */ +#ifndef GL_ANGLE_texture_compression_dxt5 +#define GL_ANGLE_texture_compression_dxt5 1 +#endif + +/* GL_ANGLE_texture_usage */ +#ifndef GL_ANGLE_texture_usage +#define GL_ANGLE_texture_usage 1 +#endif + +#ifndef GL_ANGLE_translated_shader_source +#define GL_ANGLE_translated_shader_source 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_APICALL void GL_APIENTRY glGetTranslatedShaderSourceANGLE (GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source); +#endif +typedef void (GL_APIENTRYP PFLGLGETTRANSLATEDSHADERSOURCEANGLEPROC) (GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source); +#endif + +/*------------------------------------------------------------------------* + * APPLE extension functions + *------------------------------------------------------------------------*/ + +/* GL_APPLE_copy_texture_levels */ +#ifndef GL_APPLE_copy_texture_levels +#define GL_APPLE_copy_texture_levels 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_APICALL void GL_APIENTRY glCopyTextureLevelsAPPLE (GLuint destinationTexture, GLuint sourceTexture, GLint sourceBaseLevel, GLsizei sourceLevelCount); +#endif +typedef void (GL_APIENTRYP PFNGLCOPYTEXTURELEVELSAPPLEPROC) (GLuint destinationTexture, GLuint sourceTexture, GLint sourceBaseLevel, GLsizei sourceLevelCount); +#endif + +/* GL_APPLE_framebuffer_multisample */ +#ifndef GL_APPLE_framebuffer_multisample +#define GL_APPLE_framebuffer_multisample 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_APICALL void GL_APIENTRY glRenderbufferStorageMultisampleAPPLE (GLenum, GLsizei, GLenum, GLsizei, GLsizei); +GL_APICALL void GL_APIENTRY glResolveMultisampleFramebufferAPPLE (void); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (GL_APIENTRYP PFNGLRENDERBUFFERSTORAGEMULTISAMPLEAPPLEPROC) (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height); +typedef void (GL_APIENTRYP PFNGLRESOLVEMULTISAMPLEFRAMEBUFFERAPPLEPROC) (void); +#endif + +/* GL_APPLE_rgb_422 */ +#ifndef GL_APPLE_rgb_422 +#define GL_APPLE_rgb_422 1 +#endif + +/* GL_APPLE_sync */ +#ifndef GL_APPLE_sync +#define GL_APPLE_sync 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_APICALL GLsync GL_APIENTRY glFenceSyncAPPLE (GLenum condition, GLbitfield flags); +GL_APICALL GLboolean GL_APIENTRY glIsSyncAPPLE (GLsync sync); +GL_APICALL void GL_APIENTRY glDeleteSyncAPPLE (GLsync sync); +GL_APICALL GLenum GL_APIENTRY glClientWaitSyncAPPLE (GLsync sync, GLbitfield flags, GLuint64 timeout); +GL_APICALL void GL_APIENTRY glWaitSyncAPPLE (GLsync sync, GLbitfield flags, GLuint64 timeout); +GL_APICALL void GL_APIENTRY glGetInteger64vAPPLE (GLenum pname, GLint64 *params); +GL_APICALL void GL_APIENTRY glGetSyncivAPPLE (GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values); +#endif +typedef GLsync (GL_APIENTRYP PFNGLFENCESYNCAPPLEPROC) (GLenum condition, GLbitfield flags); +typedef GLboolean (GL_APIENTRYP PFNGLISSYNCAPPLEPROC) (GLsync sync); +typedef void (GL_APIENTRYP PFNGLDELETESYNCAPPLEPROC) (GLsync sync); +typedef GLenum (GL_APIENTRYP PFNGLCLIENTWAITSYNCAPPLEPROC) (GLsync sync, GLbitfield flags, GLuint64 timeout); +typedef void (GL_APIENTRYP PFNGLWAITSYNCAPPLEPROC) (GLsync sync, GLbitfield flags, GLuint64 timeout); +typedef void (GL_APIENTRYP PFNGLGETINTEGER64VAPPLEPROC) (GLenum pname, GLint64 *params); +typedef void (GL_APIENTRYP PFNGLGETSYNCIVAPPLEPROC) (GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values); +#endif + +/* GL_APPLE_texture_format_BGRA8888 */ +#ifndef GL_APPLE_texture_format_BGRA8888 +#define GL_APPLE_texture_format_BGRA8888 1 +#endif + +/* GL_APPLE_texture_max_level */ +#ifndef GL_APPLE_texture_max_level +#define GL_APPLE_texture_max_level 1 +#endif + +/*------------------------------------------------------------------------* + * ARM extension functions + *------------------------------------------------------------------------*/ + +/* GL_ARM_mali_program_binary */ +#ifndef GL_ARM_mali_program_binary +#define GL_ARM_mali_program_binary 1 +#endif + +/* GL_ARM_mali_shader_binary */ +#ifndef GL_ARM_mali_shader_binary +#define GL_ARM_mali_shader_binary 1 +#endif + +/* GL_ARM_rgba8 */ +#ifndef GL_ARM_rgba8 +#define GL_ARM_rgba8 1 +#endif + +/*------------------------------------------------------------------------* + * EXT extension functions + *------------------------------------------------------------------------*/ + +/* GL_EXT_blend_minmax */ +#ifndef GL_EXT_blend_minmax +#define GL_EXT_blend_minmax 1 +#endif + +/* GL_EXT_color_buffer_half_float */ +#ifndef GL_EXT_color_buffer_half_float +#define GL_EXT_color_buffer_half_float 1 +#endif + +/* GL_EXT_debug_label */ +#ifndef GL_EXT_debug_label +#define GL_EXT_debug_label 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_APICALL void GL_APIENTRY glLabelObjectEXT (GLenum type, GLuint object, GLsizei length, const GLchar *label); +GL_APICALL void GL_APIENTRY glGetObjectLabelEXT (GLenum type, GLuint object, GLsizei bufSize, GLsizei *length, GLchar *label); +#endif +typedef void (GL_APIENTRYP PFNGLLABELOBJECTEXTPROC) (GLenum type, GLuint object, GLsizei length, const GLchar *label); +typedef void (GL_APIENTRYP PFNGLGETOBJECTLABELEXTPROC) (GLenum type, GLuint object, GLsizei bufSize, GLsizei *length, GLchar *label); +#endif + +/* GL_EXT_debug_marker */ +#ifndef GL_EXT_debug_marker +#define GL_EXT_debug_marker 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_APICALL void GL_APIENTRY glInsertEventMarkerEXT (GLsizei length, const GLchar *marker); +GL_APICALL void GL_APIENTRY glPushGroupMarkerEXT (GLsizei length, const GLchar *marker); +GL_APICALL void GL_APIENTRY glPopGroupMarkerEXT (void); +#endif +typedef void (GL_APIENTRYP PFNGLINSERTEVENTMARKEREXTPROC) (GLsizei length, const GLchar *marker); +typedef void (GL_APIENTRYP PFNGLPUSHGROUPMARKEREXTPROC) (GLsizei length, const GLchar *marker); +typedef void (GL_APIENTRYP PFNGLPOPGROUPMARKEREXTPROC) (void); +#endif + +/* GL_EXT_discard_framebuffer */ +#ifndef GL_EXT_discard_framebuffer +#define GL_EXT_discard_framebuffer 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_APICALL void GL_APIENTRY glDiscardFramebufferEXT (GLenum target, GLsizei numAttachments, const GLenum *attachments); +#endif +typedef void (GL_APIENTRYP PFNGLDISCARDFRAMEBUFFEREXTPROC) (GLenum target, GLsizei numAttachments, const GLenum *attachments); +#endif + +/* GL_EXT_map_buffer_range */ +#ifndef GL_EXT_map_buffer_range +#define GL_EXT_map_buffer_range 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_APICALL void* GL_APIENTRY glMapBufferRangeEXT (GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access); +GL_APICALL void GL_APIENTRY glFlushMappedBufferRangeEXT (GLenum target, GLintptr offset, GLsizeiptr length); +#endif +typedef void* (GL_APIENTRYP PFNGLMAPBUFFERRANGEEXTPROC) (GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access); +typedef void (GL_APIENTRYP PFNGLFLUSHMAPPEDBUFFERRANGEEXTPROC) (GLenum target, GLintptr offset, GLsizeiptr length); +#endif + +/* GL_EXT_multisampled_render_to_texture */ +#ifndef GL_EXT_multisampled_render_to_texture +#define GL_EXT_multisampled_render_to_texture 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_APICALL void GL_APIENTRY glRenderbufferStorageMultisampleEXT (GLenum, GLsizei, GLenum, GLsizei, GLsizei); +GL_APICALL void GL_APIENTRY glFramebufferTexture2DMultisampleEXT (GLenum, GLenum, GLenum, GLuint, GLint, GLsizei); +#endif +typedef void (GL_APIENTRYP PFNGLRENDERBUFFERSTORAGEMULTISAMPLEEXTPROC) (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height); +typedef void (GL_APIENTRYP PFNGLFRAMEBUFFERTEXTURE2DMULTISAMPLEEXTPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLsizei samples); +#endif + +/* GL_EXT_multiview_draw_buffers */ +#ifndef GL_EXT_multiview_draw_buffers +#define GL_EXT_multiview_draw_buffers 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_APICALL void GL_APIENTRY glReadBufferIndexedEXT (GLenum src, GLint index); +GL_APICALL void GL_APIENTRY glDrawBuffersIndexedEXT (GLint n, const GLenum *location, const GLint *indices); +GL_APICALL void GL_APIENTRY glGetIntegeri_vEXT (GLenum target, GLuint index, GLint *data); +#endif +typedef void (GL_APIENTRYP PFNGLREADBUFFERINDEXEDEXTPROC) (GLenum src, GLint index); +typedef void (GL_APIENTRYP PFNGLDRAWBUFFERSINDEXEDEXTPROC) (GLint n, const GLenum *location, const GLint *indices); +typedef void (GL_APIENTRYP PFNGLGETINTEGERI_VEXTPROC) (GLenum target, GLuint index, GLint *data); +#endif + +#ifndef GL_EXT_multi_draw_arrays +#define GL_EXT_multi_draw_arrays 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_APICALL void GL_APIENTRY glMultiDrawArraysEXT (GLenum, GLint *, GLsizei *, GLsizei); +GL_APICALL void GL_APIENTRY glMultiDrawElementsEXT (GLenum, const GLsizei *, GLenum, const GLvoid* *, GLsizei); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (GL_APIENTRYP PFNGLMULTIDRAWARRAYSEXTPROC) (GLenum mode, GLint *first, GLsizei *count, GLsizei primcount); +typedef void (GL_APIENTRYP PFNGLMULTIDRAWELEMENTSEXTPROC) (GLenum mode, const GLsizei *count, GLenum type, const GLvoid* *indices, GLsizei primcount); +#endif + +/* GL_EXT_occlusion_query_boolean */ +#ifndef GL_EXT_occlusion_query_boolean +#define GL_EXT_occlusion_query_boolean 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_APICALL void GL_APIENTRY glGenQueriesEXT (GLsizei n, GLuint *ids); +GL_APICALL void GL_APIENTRY glDeleteQueriesEXT (GLsizei n, const GLuint *ids); +GL_APICALL GLboolean GL_APIENTRY glIsQueryEXT (GLuint id); +GL_APICALL void GL_APIENTRY glBeginQueryEXT (GLenum target, GLuint id); +GL_APICALL void GL_APIENTRY glEndQueryEXT (GLenum target); +GL_APICALL void GL_APIENTRY glGetQueryivEXT (GLenum target, GLenum pname, GLint *params); +GL_APICALL void GL_APIENTRY glGetQueryObjectuivEXT (GLuint id, GLenum pname, GLuint *params); +#endif +typedef void (GL_APIENTRYP PFNGLGENQUERIESEXTPROC) (GLsizei n, GLuint *ids); +typedef void (GL_APIENTRYP PFNGLDELETEQUERIESEXTPROC) (GLsizei n, const GLuint *ids); +typedef GLboolean (GL_APIENTRYP PFNGLISQUERYEXTPROC) (GLuint id); +typedef void (GL_APIENTRYP PFNGLBEGINQUERYEXTPROC) (GLenum target, GLuint id); +typedef void (GL_APIENTRYP PFNGLENDQUERYEXTPROC) (GLenum target); +typedef void (GL_APIENTRYP PFNGLGETQUERYIVEXTPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (GL_APIENTRYP PFNGLGETQUERYOBJECTUIVEXTPROC) (GLuint id, GLenum pname, GLuint *params); +#endif + +/* GL_EXT_read_format_bgra */ +#ifndef GL_EXT_read_format_bgra +#define GL_EXT_read_format_bgra 1 +#endif + +/* GL_EXT_robustness */ +#ifndef GL_EXT_robustness +#define GL_EXT_robustness 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_APICALL GLenum GL_APIENTRY glGetGraphicsResetStatusEXT (void); +GL_APICALL void GL_APIENTRY glReadnPixelsEXT (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLsizei bufSize, void *data); +GL_APICALL void GL_APIENTRY glGetnUniformfvEXT (GLuint program, GLint location, GLsizei bufSize, float *params); +GL_APICALL void GL_APIENTRY glGetnUniformivEXT (GLuint program, GLint location, GLsizei bufSize, GLint *params); +#endif +typedef GLenum (GL_APIENTRYP PFNGLGETGRAPHICSRESETSTATUSEXTPROC) (void); +typedef void (GL_APIENTRYP PFNGLREADNPIXELSEXTPROC) (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLsizei bufSize, void *data); +typedef void (GL_APIENTRYP PFNGLGETNUNIFORMFVEXTPROC) (GLuint program, GLint location, GLsizei bufSize, float *params); +typedef void (GL_APIENTRYP PFNGLGETNUNIFORMIVEXTPROC) (GLuint program, GLint location, GLsizei bufSize, GLint *params); +#endif + +/* GL_EXT_separate_shader_objects */ +#ifndef GL_EXT_separate_shader_objects +#define GL_EXT_separate_shader_objects 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_APICALL void GL_APIENTRY glUseProgramStagesEXT (GLuint pipeline, GLbitfield stages, GLuint program); +GL_APICALL void GL_APIENTRY glActiveShaderProgramEXT (GLuint pipeline, GLuint program); +GL_APICALL GLuint GL_APIENTRY glCreateShaderProgramvEXT (GLenum type, GLsizei count, const GLchar **strings); +GL_APICALL void GL_APIENTRY glBindProgramPipelineEXT (GLuint pipeline); +GL_APICALL void GL_APIENTRY glDeleteProgramPipelinesEXT (GLsizei n, const GLuint *pipelines); +GL_APICALL void GL_APIENTRY glGenProgramPipelinesEXT (GLsizei n, GLuint *pipelines); +GL_APICALL GLboolean GL_APIENTRY glIsProgramPipelineEXT (GLuint pipeline); +GL_APICALL void GL_APIENTRY glProgramParameteriEXT (GLuint program, GLenum pname, GLint value); +GL_APICALL void GL_APIENTRY glGetProgramPipelineivEXT (GLuint pipeline, GLenum pname, GLint *params); +GL_APICALL void GL_APIENTRY glProgramUniform1iEXT (GLuint program, GLint location, GLint x); +GL_APICALL void GL_APIENTRY glProgramUniform2iEXT (GLuint program, GLint location, GLint x, GLint y); +GL_APICALL void GL_APIENTRY glProgramUniform3iEXT (GLuint program, GLint location, GLint x, GLint y, GLint z); +GL_APICALL void GL_APIENTRY glProgramUniform4iEXT (GLuint program, GLint location, GLint x, GLint y, GLint z, GLint w); +GL_APICALL void GL_APIENTRY glProgramUniform1fEXT (GLuint program, GLint location, GLfloat x); +GL_APICALL void GL_APIENTRY glProgramUniform2fEXT (GLuint program, GLint location, GLfloat x, GLfloat y); +GL_APICALL void GL_APIENTRY glProgramUniform3fEXT (GLuint program, GLint location, GLfloat x, GLfloat y, GLfloat z); +GL_APICALL void GL_APIENTRY glProgramUniform4fEXT (GLuint program, GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +GL_APICALL void GL_APIENTRY glProgramUniform1ivEXT (GLuint program, GLint location, GLsizei count, const GLint *value); +GL_APICALL void GL_APIENTRY glProgramUniform2ivEXT (GLuint program, GLint location, GLsizei count, const GLint *value); +GL_APICALL void GL_APIENTRY glProgramUniform3ivEXT (GLuint program, GLint location, GLsizei count, const GLint *value); +GL_APICALL void GL_APIENTRY glProgramUniform4ivEXT (GLuint program, GLint location, GLsizei count, const GLint *value); +GL_APICALL void GL_APIENTRY glProgramUniform1fvEXT (GLuint program, GLint location, GLsizei count, const GLfloat *value); +GL_APICALL void GL_APIENTRY glProgramUniform2fvEXT (GLuint program, GLint location, GLsizei count, const GLfloat *value); +GL_APICALL void GL_APIENTRY glProgramUniform3fvEXT (GLuint program, GLint location, GLsizei count, const GLfloat *value); +GL_APICALL void GL_APIENTRY glProgramUniform4fvEXT (GLuint program, GLint location, GLsizei count, const GLfloat *value); +GL_APICALL void GL_APIENTRY glProgramUniformMatrix2fvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GL_APICALL void GL_APIENTRY glProgramUniformMatrix3fvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GL_APICALL void GL_APIENTRY glProgramUniformMatrix4fvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GL_APICALL void GL_APIENTRY glValidateProgramPipelineEXT (GLuint pipeline); +GL_APICALL void GL_APIENTRY glGetProgramPipelineInfoLogEXT (GLuint pipeline, GLsizei bufSize, GLsizei *length, GLchar *infoLog); +#endif +typedef void (GL_APIENTRYP PFNGLUSEPROGRAMSTAGESEXTPROC) (GLuint pipeline, GLbitfield stages, GLuint program); +typedef void (GL_APIENTRYP PFNGLACTIVESHADERPROGRAMEXTPROC) (GLuint pipeline, GLuint program); +typedef GLuint (GL_APIENTRYP PFNGLCREATESHADERPROGRAMVEXTPROC) (GLenum type, GLsizei count, const GLchar **strings); +typedef void (GL_APIENTRYP PFNGLBINDPROGRAMPIPELINEEXTPROC) (GLuint pipeline); +typedef void (GL_APIENTRYP PFNGLDELETEPROGRAMPIPELINESEXTPROC) (GLsizei n, const GLuint *pipelines); +typedef void (GL_APIENTRYP PFNGLGENPROGRAMPIPELINESEXTPROC) (GLsizei n, GLuint *pipelines); +typedef GLboolean (GL_APIENTRYP PFNGLISPROGRAMPIPELINEEXTPROC) (GLuint pipeline); +typedef void (GL_APIENTRYP PFNGLPROGRAMPARAMETERIEXTPROC) (GLuint program, GLenum pname, GLint value); +typedef void (GL_APIENTRYP PFNGLGETPROGRAMPIPELINEIVEXTPROC) (GLuint pipeline, GLenum pname, GLint *params); +typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM1IEXTPROC) (GLuint program, GLint location, GLint x); +typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM2IEXTPROC) (GLuint program, GLint location, GLint x, GLint y); +typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM3IEXTPROC) (GLuint program, GLint location, GLint x, GLint y, GLint z); +typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM4IEXTPROC) (GLuint program, GLint location, GLint x, GLint y, GLint z, GLint w); +typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM1FEXTPROC) (GLuint program, GLint location, GLfloat x); +typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM2FEXTPROC) (GLuint program, GLint location, GLfloat x, GLfloat y); +typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM3FEXTPROC) (GLuint program, GLint location, GLfloat x, GLfloat y, GLfloat z); +typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM4FEXTPROC) (GLuint program, GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM1IVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLint *value); +typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM2IVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLint *value); +typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM3IVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLint *value); +typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM4IVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLint *value); +typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM1FVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLfloat *value); +typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM2FVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLfloat *value); +typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM3FVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLfloat *value); +typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM4FVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLfloat *value); +typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2FVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3FVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4FVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (GL_APIENTRYP PFNGLVALIDATEPROGRAMPIPELINEEXTPROC) (GLuint pipeline); +typedef void (GL_APIENTRYP PFNGLGETPROGRAMPIPELINEINFOLOGEXTPROC) (GLuint pipeline, GLsizei bufSize, GLsizei *length, GLchar *infoLog); +#endif + +/* GL_EXT_shader_framebuffer_fetch */ +#ifndef GL_EXT_shader_framebuffer_fetch +#define GL_EXT_shader_framebuffer_fetch 1 +#endif + +/* GL_EXT_shader_texture_lod */ +#ifndef GL_EXT_shader_texture_lod +#define GL_EXT_shader_texture_lod 1 +#endif + +/* GL_EXT_shadow_samplers */ +#ifndef GL_EXT_shadow_samplers +#define GL_EXT_shadow_samplers 1 +#endif + +/* GL_EXT_sRGB */ +#ifndef GL_EXT_sRGB +#define GL_EXT_sRGB 1 +#endif + +/* GL_EXT_texture_compression_dxt1 */ +#ifndef GL_EXT_texture_compression_dxt1 +#define GL_EXT_texture_compression_dxt1 1 +#endif + +/* GL_EXT_texture_filter_anisotropic */ +#ifndef GL_EXT_texture_filter_anisotropic +#define GL_EXT_texture_filter_anisotropic 1 +#endif + +/* GL_EXT_texture_format_BGRA8888 */ +#ifndef GL_EXT_texture_format_BGRA8888 +#define GL_EXT_texture_format_BGRA8888 1 +#endif + +/* GL_EXT_texture_rg */ +#ifndef GL_EXT_texture_rg +#define GL_EXT_texture_rg 1 +#endif + +/* GL_EXT_texture_storage */ +#ifndef GL_EXT_texture_storage +#define GL_EXT_texture_storage 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_APICALL void GL_APIENTRY glTexStorage1DEXT (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width); +GL_APICALL void GL_APIENTRY glTexStorage2DEXT (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height); +GL_APICALL void GL_APIENTRY glTexStorage3DEXT (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth); +GL_APICALL void GL_APIENTRY glTextureStorage1DEXT (GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width); +GL_APICALL void GL_APIENTRY glTextureStorage2DEXT (GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height); +GL_APICALL void GL_APIENTRY glTextureStorage3DEXT (GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth); +#endif +typedef void (GL_APIENTRYP PFNGLTEXSTORAGE1DEXTPROC) (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width); +typedef void (GL_APIENTRYP PFNGLTEXSTORAGE2DEXTPROC) (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height); +typedef void (GL_APIENTRYP PFNGLTEXSTORAGE3DEXTPROC) (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth); +typedef void (GL_APIENTRYP PFNGLTEXTURESTORAGE1DEXTPROC) (GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width); +typedef void (GL_APIENTRYP PFNGLTEXTURESTORAGE2DEXTPROC) (GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height); +typedef void (GL_APIENTRYP PFNGLTEXTURESTORAGE3DEXTPROC) (GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth); +#endif + +/* GL_EXT_texture_type_2_10_10_10_REV */ +#ifndef GL_EXT_texture_type_2_10_10_10_REV +#define GL_EXT_texture_type_2_10_10_10_REV 1 +#endif + +/* GL_EXT_unpack_subimage */ +#ifndef GL_EXT_unpack_subimage +#define GL_EXT_unpack_subimage 1 +#endif + +/*------------------------------------------------------------------------* + * DMP extension functions + *------------------------------------------------------------------------*/ + +/* GL_DMP_shader_binary */ +#ifndef GL_DMP_shader_binary +#define GL_DMP_shader_binary 1 +#endif + +/*------------------------------------------------------------------------* + * FJ extension functions + *------------------------------------------------------------------------*/ + +/* GL_FJ_shader_binary_GCCSO */ +#ifndef GL_FJ_shader_binary_GCCSO +#define GL_FJ_shader_binary_GCCSO 1 +#endif + +/*------------------------------------------------------------------------* + * IMG extension functions + *------------------------------------------------------------------------*/ + +/* GL_IMG_program_binary */ +#ifndef GL_IMG_program_binary +#define GL_IMG_program_binary 1 +#endif + +/* GL_IMG_read_format */ +#ifndef GL_IMG_read_format +#define GL_IMG_read_format 1 +#endif + +/* GL_IMG_shader_binary */ +#ifndef GL_IMG_shader_binary +#define GL_IMG_shader_binary 1 +#endif + +/* GL_IMG_texture_compression_pvrtc */ +#ifndef GL_IMG_texture_compression_pvrtc +#define GL_IMG_texture_compression_pvrtc 1 +#endif + +/* GL_IMG_multisampled_render_to_texture */ +#ifndef GL_IMG_multisampled_render_to_texture +#define GL_IMG_multisampled_render_to_texture 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_APICALL void GL_APIENTRY glRenderbufferStorageMultisampleIMG (GLenum, GLsizei, GLenum, GLsizei, GLsizei); +GL_APICALL void GL_APIENTRY glFramebufferTexture2DMultisampleIMG (GLenum, GLenum, GLenum, GLuint, GLint, GLsizei); +#endif +typedef void (GL_APIENTRYP PFNGLRENDERBUFFERSTORAGEMULTISAMPLEIMGPROC) (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height); +typedef void (GL_APIENTRYP PFNGLFRAMEBUFFERTEXTURE2DMULTISAMPLEIMGPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLsizei samples); +#endif + +/*------------------------------------------------------------------------* + * NV extension functions + *------------------------------------------------------------------------*/ + +/* GL_NV_coverage_sample */ +#ifndef GL_NV_coverage_sample +#define GL_NV_coverage_sample 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_APICALL void GL_APIENTRY glCoverageMaskNV (GLboolean mask); +GL_APICALL void GL_APIENTRY glCoverageOperationNV (GLenum operation); +#endif +typedef void (GL_APIENTRYP PFNGLCOVERAGEMASKNVPROC) (GLboolean mask); +typedef void (GL_APIENTRYP PFNGLCOVERAGEOPERATIONNVPROC) (GLenum operation); +#endif + +/* GL_NV_depth_nonlinear */ +#ifndef GL_NV_depth_nonlinear +#define GL_NV_depth_nonlinear 1 +#endif + +/* GL_NV_draw_buffers */ +#ifndef GL_NV_draw_buffers +#define GL_NV_draw_buffers 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_APICALL void GL_APIENTRY glDrawBuffersNV (GLsizei n, const GLenum *bufs); +#endif +typedef void (GL_APIENTRYP PFNGLDRAWBUFFERSNVPROC) (GLsizei n, const GLenum *bufs); +#endif + +/* GL_NV_fbo_color_attachments */ +#ifndef GL_NV_fbo_color_attachments +#define GL_NV_fbo_color_attachments 1 +#endif + +/* GL_NV_fence */ +#ifndef GL_NV_fence +#define GL_NV_fence 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_APICALL void GL_APIENTRY glDeleteFencesNV (GLsizei, const GLuint *); +GL_APICALL void GL_APIENTRY glGenFencesNV (GLsizei, GLuint *); +GL_APICALL GLboolean GL_APIENTRY glIsFenceNV (GLuint); +GL_APICALL GLboolean GL_APIENTRY glTestFenceNV (GLuint); +GL_APICALL void GL_APIENTRY glGetFenceivNV (GLuint, GLenum, GLint *); +GL_APICALL void GL_APIENTRY glFinishFenceNV (GLuint); +GL_APICALL void GL_APIENTRY glSetFenceNV (GLuint, GLenum); +#endif +typedef void (GL_APIENTRYP PFNGLDELETEFENCESNVPROC) (GLsizei n, const GLuint *fences); +typedef void (GL_APIENTRYP PFNGLGENFENCESNVPROC) (GLsizei n, GLuint *fences); +typedef GLboolean (GL_APIENTRYP PFNGLISFENCENVPROC) (GLuint fence); +typedef GLboolean (GL_APIENTRYP PFNGLTESTFENCENVPROC) (GLuint fence); +typedef void (GL_APIENTRYP PFNGLGETFENCEIVNVPROC) (GLuint fence, GLenum pname, GLint *params); +typedef void (GL_APIENTRYP PFNGLFINISHFENCENVPROC) (GLuint fence); +typedef void (GL_APIENTRYP PFNGLSETFENCENVPROC) (GLuint fence, GLenum condition); +#endif + +/* GL_NV_read_buffer */ +#ifndef GL_NV_read_buffer +#define GL_NV_read_buffer 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_APICALL void GL_APIENTRY glReadBufferNV (GLenum mode); +#endif +typedef void (GL_APIENTRYP PFNGLREADBUFFERNVPROC) (GLenum mode); +#endif + +/* GL_NV_read_buffer_front */ +#ifndef GL_NV_read_buffer_front +#define GL_NV_read_buffer_front 1 +#endif + +/* GL_NV_read_depth */ +#ifndef GL_NV_read_depth +#define GL_NV_read_depth 1 +#endif + +/* GL_NV_read_depth_stencil */ +#ifndef GL_NV_read_depth_stencil +#define GL_NV_read_depth_stencil 1 +#endif + +/* GL_NV_read_stencil */ +#ifndef GL_NV_read_stencil +#define GL_NV_read_stencil 1 +#endif + +/* GL_NV_texture_compression_s3tc_update */ +#ifndef GL_NV_texture_compression_s3tc_update +#define GL_NV_texture_compression_s3tc_update 1 +#endif + +/* GL_NV_texture_npot_2D_mipmap */ +#ifndef GL_NV_texture_npot_2D_mipmap +#define GL_NV_texture_npot_2D_mipmap 1 +#endif + +/*------------------------------------------------------------------------* + * QCOM extension functions + *------------------------------------------------------------------------*/ + +/* GL_QCOM_alpha_test */ +#ifndef GL_QCOM_alpha_test +#define GL_QCOM_alpha_test 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_APICALL void GL_APIENTRY glAlphaFuncQCOM (GLenum func, GLclampf ref); +#endif +typedef void (GL_APIENTRYP PFNGLALPHAFUNCQCOMPROC) (GLenum func, GLclampf ref); +#endif + +/* GL_QCOM_binning_control */ +#ifndef GL_QCOM_binning_control +#define GL_QCOM_binning_control 1 +#endif + +/* GL_QCOM_driver_control */ +#ifndef GL_QCOM_driver_control +#define GL_QCOM_driver_control 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_APICALL void GL_APIENTRY glGetDriverControlsQCOM (GLint *num, GLsizei size, GLuint *driverControls); +GL_APICALL void GL_APIENTRY glGetDriverControlStringQCOM (GLuint driverControl, GLsizei bufSize, GLsizei *length, GLchar *driverControlString); +GL_APICALL void GL_APIENTRY glEnableDriverControlQCOM (GLuint driverControl); +GL_APICALL void GL_APIENTRY glDisableDriverControlQCOM (GLuint driverControl); +#endif +typedef void (GL_APIENTRYP PFNGLGETDRIVERCONTROLSQCOMPROC) (GLint *num, GLsizei size, GLuint *driverControls); +typedef void (GL_APIENTRYP PFNGLGETDRIVERCONTROLSTRINGQCOMPROC) (GLuint driverControl, GLsizei bufSize, GLsizei *length, GLchar *driverControlString); +typedef void (GL_APIENTRYP PFNGLENABLEDRIVERCONTROLQCOMPROC) (GLuint driverControl); +typedef void (GL_APIENTRYP PFNGLDISABLEDRIVERCONTROLQCOMPROC) (GLuint driverControl); +#endif + +/* GL_QCOM_extended_get */ +#ifndef GL_QCOM_extended_get +#define GL_QCOM_extended_get 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_APICALL void GL_APIENTRY glExtGetTexturesQCOM (GLuint *textures, GLint maxTextures, GLint *numTextures); +GL_APICALL void GL_APIENTRY glExtGetBuffersQCOM (GLuint *buffers, GLint maxBuffers, GLint *numBuffers); +GL_APICALL void GL_APIENTRY glExtGetRenderbuffersQCOM (GLuint *renderbuffers, GLint maxRenderbuffers, GLint *numRenderbuffers); +GL_APICALL void GL_APIENTRY glExtGetFramebuffersQCOM (GLuint *framebuffers, GLint maxFramebuffers, GLint *numFramebuffers); +GL_APICALL void GL_APIENTRY glExtGetTexLevelParameterivQCOM (GLuint texture, GLenum face, GLint level, GLenum pname, GLint *params); +GL_APICALL void GL_APIENTRY glExtTexObjectStateOverrideiQCOM (GLenum target, GLenum pname, GLint param); +GL_APICALL void GL_APIENTRY glExtGetTexSubImageQCOM (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, GLvoid *texels); +GL_APICALL void GL_APIENTRY glExtGetBufferPointervQCOM (GLenum target, GLvoid **params); +#endif +typedef void (GL_APIENTRYP PFNGLEXTGETTEXTURESQCOMPROC) (GLuint *textures, GLint maxTextures, GLint *numTextures); +typedef void (GL_APIENTRYP PFNGLEXTGETBUFFERSQCOMPROC) (GLuint *buffers, GLint maxBuffers, GLint *numBuffers); +typedef void (GL_APIENTRYP PFNGLEXTGETRENDERBUFFERSQCOMPROC) (GLuint *renderbuffers, GLint maxRenderbuffers, GLint *numRenderbuffers); +typedef void (GL_APIENTRYP PFNGLEXTGETFRAMEBUFFERSQCOMPROC) (GLuint *framebuffers, GLint maxFramebuffers, GLint *numFramebuffers); +typedef void (GL_APIENTRYP PFNGLEXTGETTEXLEVELPARAMETERIVQCOMPROC) (GLuint texture, GLenum face, GLint level, GLenum pname, GLint *params); +typedef void (GL_APIENTRYP PFNGLEXTTEXOBJECTSTATEOVERRIDEIQCOMPROC) (GLenum target, GLenum pname, GLint param); +typedef void (GL_APIENTRYP PFNGLEXTGETTEXSUBIMAGEQCOMPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, GLvoid *texels); +typedef void (GL_APIENTRYP PFNGLEXTGETBUFFERPOINTERVQCOMPROC) (GLenum target, GLvoid **params); +#endif + +/* GL_QCOM_extended_get2 */ +#ifndef GL_QCOM_extended_get2 +#define GL_QCOM_extended_get2 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_APICALL void GL_APIENTRY glExtGetShadersQCOM (GLuint *shaders, GLint maxShaders, GLint *numShaders); +GL_APICALL void GL_APIENTRY glExtGetProgramsQCOM (GLuint *programs, GLint maxPrograms, GLint *numPrograms); +GL_APICALL GLboolean GL_APIENTRY glExtIsProgramBinaryQCOM (GLuint program); +GL_APICALL void GL_APIENTRY glExtGetProgramBinarySourceQCOM (GLuint program, GLenum shadertype, GLchar *source, GLint *length); +#endif +typedef void (GL_APIENTRYP PFNGLEXTGETSHADERSQCOMPROC) (GLuint *shaders, GLint maxShaders, GLint *numShaders); +typedef void (GL_APIENTRYP PFNGLEXTGETPROGRAMSQCOMPROC) (GLuint *programs, GLint maxPrograms, GLint *numPrograms); +typedef GLboolean (GL_APIENTRYP PFNGLEXTISPROGRAMBINARYQCOMPROC) (GLuint program); +typedef void (GL_APIENTRYP PFNGLEXTGETPROGRAMBINARYSOURCEQCOMPROC) (GLuint program, GLenum shadertype, GLchar *source, GLint *length); +#endif + +/* GL_QCOM_perfmon_global_mode */ +#ifndef GL_QCOM_perfmon_global_mode +#define GL_QCOM_perfmon_global_mode 1 +#endif + +/* GL_QCOM_writeonly_rendering */ +#ifndef GL_QCOM_writeonly_rendering +#define GL_QCOM_writeonly_rendering 1 +#endif + +/* GL_QCOM_tiled_rendering */ +#ifndef GL_QCOM_tiled_rendering +#define GL_QCOM_tiled_rendering 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_APICALL void GL_APIENTRY glStartTilingQCOM (GLuint x, GLuint y, GLuint width, GLuint height, GLbitfield preserveMask); +GL_APICALL void GL_APIENTRY glEndTilingQCOM (GLbitfield preserveMask); +#endif +typedef void (GL_APIENTRYP PFNGLSTARTTILINGQCOMPROC) (GLuint x, GLuint y, GLuint width, GLuint height, GLbitfield preserveMask); +typedef void (GL_APIENTRYP PFNGLENDTILINGQCOMPROC) (GLbitfield preserveMask); +#endif + +/*------------------------------------------------------------------------* + * VIV extension tokens + *------------------------------------------------------------------------*/ + +/* GL_VIV_shader_binary */ +#ifndef GL_VIV_shader_binary +#define GL_VIV_shader_binary 1 +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* __gl2ext_h_ */ diff --git a/Projects/Android/jni/SupportLibs/gl4es/include/GLES/gl2platform.h b/Projects/Android/jni/SupportLibs/gl4es/include/GLES/gl2platform.h new file mode 100644 index 0000000..c9fa3c4 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/include/GLES/gl2platform.h @@ -0,0 +1,30 @@ +#ifndef __gl2platform_h_ +#define __gl2platform_h_ + +/* $Revision: 10602 $ on $Date:: 2010-03-04 22:35:34 -0800 #$ */ + +/* + * This document is licensed under the SGI Free Software B License Version + * 2.0. For details, see http://oss.sgi.com/projects/FreeB/ . + */ + +/* Platform-specific types and definitions for OpenGL ES 2.X gl2.h + * + * Adopters may modify khrplatform.h and this file to suit their platform. + * You are encouraged to submit all modifications to the Khronos group so that + * they can be included in future versions of this file. Please submit changes + * by sending them to the public Khronos Bugzilla (http://khronos.org/bugzilla) + * by filing a bug against product "OpenGL-ES" component "Registry". + */ + +#include + +#ifndef GL_APICALL +#define GL_APICALL KHRONOS_APICALL +#endif + +#ifndef GL_APIENTRY +#define GL_APIENTRY KHRONOS_APIENTRY +#endif + +#endif /* __gl2platform_h_ */ diff --git a/Projects/Android/jni/SupportLibs/gl4es/include/GLES/gl3.h b/Projects/Android/jni/SupportLibs/gl4es/include/GLES/gl3.h new file mode 100644 index 0000000..b9399e9 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/include/GLES/gl3.h @@ -0,0 +1,1061 @@ +#ifndef __gl3_h_ +#define __gl3_h_ + +/* + * gl3.h last updated on $Date: 2012-09-12 10:13:02 -0700 (Wed, 12 Sep 2012) $ + */ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* +** Copyright (c) 2007-2012 The Khronos Group Inc. +** +** Permission is hereby granted, free of charge, to any person obtaining a +** copy of this software and/or associated documentation files (the +** "Materials"), to deal in the Materials without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Materials, and to +** permit persons to whom the Materials are furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be included +** in all copies or substantial portions of the Materials. +** +** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. +*/ + +/*------------------------------------------------------------------------- + * Data type definitions + *-----------------------------------------------------------------------*/ + +/* OpenGL ES 2.0 */ + +typedef void GLvoid; +typedef char GLchar; +typedef unsigned int GLenum; +typedef unsigned char GLboolean; +typedef unsigned int GLbitfield; +typedef khronos_int8_t GLbyte; +typedef short GLshort; +typedef int GLint; +typedef int GLsizei; +typedef khronos_uint8_t GLubyte; +typedef unsigned short GLushort; +typedef unsigned int GLuint; +typedef khronos_float_t GLfloat; +typedef khronos_float_t GLclampf; +typedef khronos_int32_t GLfixed; +typedef khronos_intptr_t GLintptr; +typedef khronos_ssize_t GLsizeiptr; + +/* OpenGL ES 3.0 */ + +typedef unsigned short GLhalf; +typedef khronos_int64_t GLint64; +typedef khronos_uint64_t GLuint64; +typedef struct __GLsync *GLsync; + +/*------------------------------------------------------------------------- + * Token definitions + *-----------------------------------------------------------------------*/ + +/* OpenGL ES core versions */ +#define GL_ES_VERSION_3_0 1 +#define GL_ES_VERSION_2_0 1 + +/* OpenGL ES 2.0 */ + +/* ClearBufferMask */ +#define GL_DEPTH_BUFFER_BIT 0x00000100 +#define GL_STENCIL_BUFFER_BIT 0x00000400 +#define GL_COLOR_BUFFER_BIT 0x00004000 + +/* Boolean */ +#define GL_FALSE 0 +#define GL_TRUE 1 + +/* BeginMode */ +#define GL_POINTS 0x0000 +#define GL_LINES 0x0001 +#define GL_LINE_LOOP 0x0002 +#define GL_LINE_STRIP 0x0003 +#define GL_TRIANGLES 0x0004 +#define GL_TRIANGLE_STRIP 0x0005 +#define GL_TRIANGLE_FAN 0x0006 + +/* BlendingFactorDest */ +#define GL_ZERO 0 +#define GL_ONE 1 +#define GL_SRC_COLOR 0x0300 +#define GL_ONE_MINUS_SRC_COLOR 0x0301 +#define GL_SRC_ALPHA 0x0302 +#define GL_ONE_MINUS_SRC_ALPHA 0x0303 +#define GL_DST_ALPHA 0x0304 +#define GL_ONE_MINUS_DST_ALPHA 0x0305 + +/* BlendingFactorSrc */ +/* GL_ZERO */ +/* GL_ONE */ +#define GL_DST_COLOR 0x0306 +#define GL_ONE_MINUS_DST_COLOR 0x0307 +#define GL_SRC_ALPHA_SATURATE 0x0308 +/* GL_SRC_ALPHA */ +/* GL_ONE_MINUS_SRC_ALPHA */ +/* GL_DST_ALPHA */ +/* GL_ONE_MINUS_DST_ALPHA */ + +/* BlendEquationSeparate */ +#define GL_FUNC_ADD 0x8006 +#define GL_BLEND_EQUATION 0x8009 +#define GL_BLEND_EQUATION_RGB 0x8009 /* same as BLEND_EQUATION */ +#define GL_BLEND_EQUATION_ALPHA 0x883D + +/* BlendSubtract */ +#define GL_FUNC_SUBTRACT 0x800A +#define GL_FUNC_REVERSE_SUBTRACT 0x800B + +/* Separate Blend Functions */ +#define GL_BLEND_DST_RGB 0x80C8 +#define GL_BLEND_SRC_RGB 0x80C9 +#define GL_BLEND_DST_ALPHA 0x80CA +#define GL_BLEND_SRC_ALPHA 0x80CB +#define GL_CONSTANT_COLOR 0x8001 +#define GL_ONE_MINUS_CONSTANT_COLOR 0x8002 +#define GL_CONSTANT_ALPHA 0x8003 +#define GL_ONE_MINUS_CONSTANT_ALPHA 0x8004 +#define GL_BLEND_COLOR 0x8005 + +/* Buffer Objects */ +#define GL_ARRAY_BUFFER 0x8892 +#define GL_ELEMENT_ARRAY_BUFFER 0x8893 +#define GL_ARRAY_BUFFER_BINDING 0x8894 +#define GL_ELEMENT_ARRAY_BUFFER_BINDING 0x8895 + +#define GL_STREAM_DRAW 0x88E0 +#define GL_STATIC_DRAW 0x88E4 +#define GL_DYNAMIC_DRAW 0x88E8 + +#define GL_BUFFER_SIZE 0x8764 +#define GL_BUFFER_USAGE 0x8765 + +#define GL_CURRENT_VERTEX_ATTRIB 0x8626 + +/* CullFaceMode */ +#define GL_FRONT 0x0404 +#define GL_BACK 0x0405 +#define GL_FRONT_AND_BACK 0x0408 + +/* DepthFunction */ +/* GL_NEVER */ +/* GL_LESS */ +/* GL_EQUAL */ +/* GL_LEQUAL */ +/* GL_GREATER */ +/* GL_NOTEQUAL */ +/* GL_GEQUAL */ +/* GL_ALWAYS */ + +/* EnableCap */ +#define GL_TEXTURE_2D 0x0DE1 +#define GL_CULL_FACE 0x0B44 +#define GL_BLEND 0x0BE2 +#define GL_DITHER 0x0BD0 +#define GL_STENCIL_TEST 0x0B90 +#define GL_DEPTH_TEST 0x0B71 +#define GL_SCISSOR_TEST 0x0C11 +#define GL_POLYGON_OFFSET_FILL 0x8037 +#define GL_SAMPLE_ALPHA_TO_COVERAGE 0x809E +#define GL_SAMPLE_COVERAGE 0x80A0 + +/* ErrorCode */ +#define GL_NO_ERROR 0 +#define GL_INVALID_ENUM 0x0500 +#define GL_INVALID_VALUE 0x0501 +#define GL_INVALID_OPERATION 0x0502 +#define GL_OUT_OF_MEMORY 0x0505 + +/* FrontFaceDirection */ +#define GL_CW 0x0900 +#define GL_CCW 0x0901 + +/* GetPName */ +#define GL_LINE_WIDTH 0x0B21 +#define GL_ALIASED_POINT_SIZE_RANGE 0x846D +#define GL_ALIASED_LINE_WIDTH_RANGE 0x846E +#define GL_CULL_FACE_MODE 0x0B45 +#define GL_FRONT_FACE 0x0B46 +#define GL_DEPTH_RANGE 0x0B70 +#define GL_DEPTH_WRITEMASK 0x0B72 +#define GL_DEPTH_CLEAR_VALUE 0x0B73 +#define GL_DEPTH_FUNC 0x0B74 +#define GL_STENCIL_CLEAR_VALUE 0x0B91 +#define GL_STENCIL_FUNC 0x0B92 +#define GL_STENCIL_FAIL 0x0B94 +#define GL_STENCIL_PASS_DEPTH_FAIL 0x0B95 +#define GL_STENCIL_PASS_DEPTH_PASS 0x0B96 +#define GL_STENCIL_REF 0x0B97 +#define GL_STENCIL_VALUE_MASK 0x0B93 +#define GL_STENCIL_WRITEMASK 0x0B98 +#define GL_STENCIL_BACK_FUNC 0x8800 +#define GL_STENCIL_BACK_FAIL 0x8801 +#define GL_STENCIL_BACK_PASS_DEPTH_FAIL 0x8802 +#define GL_STENCIL_BACK_PASS_DEPTH_PASS 0x8803 +#define GL_STENCIL_BACK_REF 0x8CA3 +#define GL_STENCIL_BACK_VALUE_MASK 0x8CA4 +#define GL_STENCIL_BACK_WRITEMASK 0x8CA5 +#define GL_VIEWPORT 0x0BA2 +#define GL_SCISSOR_BOX 0x0C10 +/* GL_SCISSOR_TEST */ +#define GL_COLOR_CLEAR_VALUE 0x0C22 +#define GL_COLOR_WRITEMASK 0x0C23 +#define GL_UNPACK_ALIGNMENT 0x0CF5 +#define GL_PACK_ALIGNMENT 0x0D05 +#define GL_MAX_TEXTURE_SIZE 0x0D33 +#define GL_MAX_VIEWPORT_DIMS 0x0D3A +#define GL_SUBPIXEL_BITS 0x0D50 +#define GL_RED_BITS 0x0D52 +#define GL_GREEN_BITS 0x0D53 +#define GL_BLUE_BITS 0x0D54 +#define GL_ALPHA_BITS 0x0D55 +#define GL_DEPTH_BITS 0x0D56 +#define GL_STENCIL_BITS 0x0D57 +#define GL_POLYGON_OFFSET_UNITS 0x2A00 +/* GL_POLYGON_OFFSET_FILL */ +#define GL_POLYGON_OFFSET_FACTOR 0x8038 +#define GL_TEXTURE_BINDING_2D 0x8069 +#define GL_SAMPLE_BUFFERS 0x80A8 +#define GL_SAMPLES 0x80A9 +#define GL_SAMPLE_COVERAGE_VALUE 0x80AA +#define GL_SAMPLE_COVERAGE_INVERT 0x80AB + +/* GetTextureParameter */ +/* GL_TEXTURE_MAG_FILTER */ +/* GL_TEXTURE_MIN_FILTER */ +/* GL_TEXTURE_WRAP_S */ +/* GL_TEXTURE_WRAP_T */ + +#define GL_NUM_COMPRESSED_TEXTURE_FORMATS 0x86A2 +#define GL_COMPRESSED_TEXTURE_FORMATS 0x86A3 + +/* HintMode */ +#define GL_DONT_CARE 0x1100 +#define GL_FASTEST 0x1101 +#define GL_NICEST 0x1102 + +/* HintTarget */ +#define GL_GENERATE_MIPMAP_HINT 0x8192 + +/* DataType */ +#define GL_BYTE 0x1400 +#define GL_UNSIGNED_BYTE 0x1401 +#define GL_SHORT 0x1402 +#define GL_UNSIGNED_SHORT 0x1403 +#define GL_INT 0x1404 +#define GL_UNSIGNED_INT 0x1405 +#define GL_FLOAT 0x1406 +#define GL_FIXED 0x140C + +/* PixelFormat */ +#define GL_DEPTH_COMPONENT 0x1902 +#define GL_ALPHA 0x1906 +#define GL_RGB 0x1907 +#define GL_RGBA 0x1908 +#define GL_LUMINANCE 0x1909 +#define GL_LUMINANCE_ALPHA 0x190A + +/* PixelType */ +/* GL_UNSIGNED_BYTE */ +#define GL_UNSIGNED_SHORT_4_4_4_4 0x8033 +#define GL_UNSIGNED_SHORT_5_5_5_1 0x8034 +#define GL_UNSIGNED_SHORT_5_6_5 0x8363 + +/* Shaders */ +#define GL_FRAGMENT_SHADER 0x8B30 +#define GL_VERTEX_SHADER 0x8B31 +#define GL_MAX_VERTEX_ATTRIBS 0x8869 +#define GL_MAX_VERTEX_UNIFORM_VECTORS 0x8DFB +#define GL_MAX_VARYING_VECTORS 0x8DFC +#define GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS 0x8B4D +#define GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS 0x8B4C +#define GL_MAX_TEXTURE_IMAGE_UNITS 0x8872 +#define GL_MAX_FRAGMENT_UNIFORM_VECTORS 0x8DFD +#define GL_SHADER_TYPE 0x8B4F +#define GL_DELETE_STATUS 0x8B80 +#define GL_LINK_STATUS 0x8B82 +#define GL_VALIDATE_STATUS 0x8B83 +#define GL_ATTACHED_SHADERS 0x8B85 +#define GL_ACTIVE_UNIFORMS 0x8B86 +#define GL_ACTIVE_UNIFORM_MAX_LENGTH 0x8B87 +#define GL_ACTIVE_ATTRIBUTES 0x8B89 +#define GL_ACTIVE_ATTRIBUTE_MAX_LENGTH 0x8B8A +#define GL_SHADING_LANGUAGE_VERSION 0x8B8C +#define GL_CURRENT_PROGRAM 0x8B8D + +/* StencilFunction */ +#define GL_NEVER 0x0200 +#define GL_LESS 0x0201 +#define GL_EQUAL 0x0202 +#define GL_LEQUAL 0x0203 +#define GL_GREATER 0x0204 +#define GL_NOTEQUAL 0x0205 +#define GL_GEQUAL 0x0206 +#define GL_ALWAYS 0x0207 + +/* StencilOp */ +/* GL_ZERO */ +#define GL_KEEP 0x1E00 +#define GL_REPLACE 0x1E01 +#define GL_INCR 0x1E02 +#define GL_DECR 0x1E03 +#define GL_INVERT 0x150A +#define GL_INCR_WRAP 0x8507 +#define GL_DECR_WRAP 0x8508 + +/* StringName */ +#define GL_VENDOR 0x1F00 +#define GL_RENDERER 0x1F01 +#define GL_VERSION 0x1F02 +#define GL_EXTENSIONS 0x1F03 + +/* TextureMagFilter */ +#define GL_NEAREST 0x2600 +#define GL_LINEAR 0x2601 + +/* TextureMinFilter */ +/* GL_NEAREST */ +/* GL_LINEAR */ +#define GL_NEAREST_MIPMAP_NEAREST 0x2700 +#define GL_LINEAR_MIPMAP_NEAREST 0x2701 +#define GL_NEAREST_MIPMAP_LINEAR 0x2702 +#define GL_LINEAR_MIPMAP_LINEAR 0x2703 + +/* TextureParameterName */ +#define GL_TEXTURE_MAG_FILTER 0x2800 +#define GL_TEXTURE_MIN_FILTER 0x2801 +#define GL_TEXTURE_WRAP_S 0x2802 +#define GL_TEXTURE_WRAP_T 0x2803 + +/* TextureTarget */ +/* GL_TEXTURE_2D */ +#define GL_TEXTURE 0x1702 + +#define GL_TEXTURE_CUBE_MAP 0x8513 +#define GL_TEXTURE_BINDING_CUBE_MAP 0x8514 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_X 0x8515 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_X 0x8516 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_Y 0x8517 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Y 0x8518 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_Z 0x8519 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Z 0x851A +#define GL_MAX_CUBE_MAP_TEXTURE_SIZE 0x851C + +/* TextureUnit */ +#define GL_TEXTURE0 0x84C0 +#define GL_TEXTURE1 0x84C1 +#define GL_TEXTURE2 0x84C2 +#define GL_TEXTURE3 0x84C3 +#define GL_TEXTURE4 0x84C4 +#define GL_TEXTURE5 0x84C5 +#define GL_TEXTURE6 0x84C6 +#define GL_TEXTURE7 0x84C7 +#define GL_TEXTURE8 0x84C8 +#define GL_TEXTURE9 0x84C9 +#define GL_TEXTURE10 0x84CA +#define GL_TEXTURE11 0x84CB +#define GL_TEXTURE12 0x84CC +#define GL_TEXTURE13 0x84CD +#define GL_TEXTURE14 0x84CE +#define GL_TEXTURE15 0x84CF +#define GL_TEXTURE16 0x84D0 +#define GL_TEXTURE17 0x84D1 +#define GL_TEXTURE18 0x84D2 +#define GL_TEXTURE19 0x84D3 +#define GL_TEXTURE20 0x84D4 +#define GL_TEXTURE21 0x84D5 +#define GL_TEXTURE22 0x84D6 +#define GL_TEXTURE23 0x84D7 +#define GL_TEXTURE24 0x84D8 +#define GL_TEXTURE25 0x84D9 +#define GL_TEXTURE26 0x84DA +#define GL_TEXTURE27 0x84DB +#define GL_TEXTURE28 0x84DC +#define GL_TEXTURE29 0x84DD +#define GL_TEXTURE30 0x84DE +#define GL_TEXTURE31 0x84DF +#define GL_ACTIVE_TEXTURE 0x84E0 + +/* TextureWrapMode */ +#define GL_REPEAT 0x2901 +#define GL_CLAMP_TO_EDGE 0x812F +#define GL_MIRRORED_REPEAT 0x8370 + +/* Uniform Types */ +#define GL_FLOAT_VEC2 0x8B50 +#define GL_FLOAT_VEC3 0x8B51 +#define GL_FLOAT_VEC4 0x8B52 +#define GL_INT_VEC2 0x8B53 +#define GL_INT_VEC3 0x8B54 +#define GL_INT_VEC4 0x8B55 +#define GL_BOOL 0x8B56 +#define GL_BOOL_VEC2 0x8B57 +#define GL_BOOL_VEC3 0x8B58 +#define GL_BOOL_VEC4 0x8B59 +#define GL_FLOAT_MAT2 0x8B5A +#define GL_FLOAT_MAT3 0x8B5B +#define GL_FLOAT_MAT4 0x8B5C +#define GL_SAMPLER_2D 0x8B5E +#define GL_SAMPLER_CUBE 0x8B60 + +/* Vertex Arrays */ +#define GL_VERTEX_ATTRIB_ARRAY_ENABLED 0x8622 +#define GL_VERTEX_ATTRIB_ARRAY_SIZE 0x8623 +#define GL_VERTEX_ATTRIB_ARRAY_STRIDE 0x8624 +#define GL_VERTEX_ATTRIB_ARRAY_TYPE 0x8625 +#define GL_VERTEX_ATTRIB_ARRAY_NORMALIZED 0x886A +#define GL_VERTEX_ATTRIB_ARRAY_POINTER 0x8645 +#define GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING 0x889F + +/* Read Format */ +#define GL_IMPLEMENTATION_COLOR_READ_TYPE 0x8B9A +#define GL_IMPLEMENTATION_COLOR_READ_FORMAT 0x8B9B + +/* Shader Source */ +#define GL_COMPILE_STATUS 0x8B81 +#define GL_INFO_LOG_LENGTH 0x8B84 +#define GL_SHADER_SOURCE_LENGTH 0x8B88 +#define GL_SHADER_COMPILER 0x8DFA + +/* Shader Binary */ +#define GL_SHADER_BINARY_FORMATS 0x8DF8 +#define GL_NUM_SHADER_BINARY_FORMATS 0x8DF9 + +/* Shader Precision-Specified Types */ +#define GL_LOW_FLOAT 0x8DF0 +#define GL_MEDIUM_FLOAT 0x8DF1 +#define GL_HIGH_FLOAT 0x8DF2 +#define GL_LOW_INT 0x8DF3 +#define GL_MEDIUM_INT 0x8DF4 +#define GL_HIGH_INT 0x8DF5 + +/* Framebuffer Object. */ +#define GL_FRAMEBUFFER 0x8D40 +#define GL_RENDERBUFFER 0x8D41 + +#define GL_RGBA4 0x8056 +#define GL_RGB5_A1 0x8057 +#define GL_RGB565 0x8D62 +#define GL_DEPTH_COMPONENT16 0x81A5 +#define GL_STENCIL_INDEX8 0x8D48 + +#define GL_RENDERBUFFER_WIDTH 0x8D42 +#define GL_RENDERBUFFER_HEIGHT 0x8D43 +#define GL_RENDERBUFFER_INTERNAL_FORMAT 0x8D44 +#define GL_RENDERBUFFER_RED_SIZE 0x8D50 +#define GL_RENDERBUFFER_GREEN_SIZE 0x8D51 +#define GL_RENDERBUFFER_BLUE_SIZE 0x8D52 +#define GL_RENDERBUFFER_ALPHA_SIZE 0x8D53 +#define GL_RENDERBUFFER_DEPTH_SIZE 0x8D54 +#define GL_RENDERBUFFER_STENCIL_SIZE 0x8D55 + +#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE 0x8CD0 +#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME 0x8CD1 +#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL 0x8CD2 +#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE 0x8CD3 + +#define GL_COLOR_ATTACHMENT0 0x8CE0 +#define GL_DEPTH_ATTACHMENT 0x8D00 +#define GL_STENCIL_ATTACHMENT 0x8D20 + +#define GL_NONE 0 + +#define GL_FRAMEBUFFER_COMPLETE 0x8CD5 +#define GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT 0x8CD6 +#define GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT 0x8CD7 +#define GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS 0x8CD9 +#define GL_FRAMEBUFFER_UNSUPPORTED 0x8CDD + +#define GL_FRAMEBUFFER_BINDING 0x8CA6 +#define GL_RENDERBUFFER_BINDING 0x8CA7 +#define GL_MAX_RENDERBUFFER_SIZE 0x84E8 + +#define GL_INVALID_FRAMEBUFFER_OPERATION 0x0506 + +/* OpenGL ES 3.0 */ + +#define GL_READ_BUFFER 0x0C02 +#define GL_UNPACK_ROW_LENGTH 0x0CF2 +#define GL_UNPACK_SKIP_ROWS 0x0CF3 +#define GL_UNPACK_SKIP_PIXELS 0x0CF4 +#define GL_PACK_ROW_LENGTH 0x0D02 +#define GL_PACK_SKIP_ROWS 0x0D03 +#define GL_PACK_SKIP_PIXELS 0x0D04 +#define GL_COLOR 0x1800 +#define GL_DEPTH 0x1801 +#define GL_STENCIL 0x1802 +#define GL_RED 0x1903 +#define GL_RGB8 0x8051 +#define GL_RGBA8 0x8058 +#define GL_RGB10_A2 0x8059 +#define GL_TEXTURE_BINDING_3D 0x806A +#define GL_UNPACK_SKIP_IMAGES 0x806D +#define GL_UNPACK_IMAGE_HEIGHT 0x806E +#define GL_TEXTURE_3D 0x806F +#define GL_TEXTURE_WRAP_R 0x8072 +#define GL_MAX_3D_TEXTURE_SIZE 0x8073 +#define GL_UNSIGNED_INT_2_10_10_10_REV 0x8368 +#define GL_MAX_ELEMENTS_VERTICES 0x80E8 +#define GL_MAX_ELEMENTS_INDICES 0x80E9 +#define GL_TEXTURE_MIN_LOD 0x813A +#define GL_TEXTURE_MAX_LOD 0x813B +#define GL_TEXTURE_BASE_LEVEL 0x813C +#define GL_TEXTURE_MAX_LEVEL 0x813D +#define GL_MIN 0x8007 +#define GL_MAX 0x8008 +#define GL_DEPTH_COMPONENT24 0x81A6 +#define GL_MAX_TEXTURE_LOD_BIAS 0x84FD +#define GL_TEXTURE_COMPARE_MODE 0x884C +#define GL_TEXTURE_COMPARE_FUNC 0x884D +#define GL_CURRENT_QUERY 0x8865 +#define GL_QUERY_RESULT 0x8866 +#define GL_QUERY_RESULT_AVAILABLE 0x8867 +#define GL_BUFFER_MAPPED 0x88BC +#define GL_BUFFER_MAP_POINTER 0x88BD +#define GL_STREAM_READ 0x88E1 +#define GL_STREAM_COPY 0x88E2 +#define GL_STATIC_READ 0x88E5 +#define GL_STATIC_COPY 0x88E6 +#define GL_DYNAMIC_READ 0x88E9 +#define GL_DYNAMIC_COPY 0x88EA +#define GL_MAX_DRAW_BUFFERS 0x8824 +#define GL_DRAW_BUFFER0 0x8825 +#define GL_DRAW_BUFFER1 0x8826 +#define GL_DRAW_BUFFER2 0x8827 +#define GL_DRAW_BUFFER3 0x8828 +#define GL_DRAW_BUFFER4 0x8829 +#define GL_DRAW_BUFFER5 0x882A +#define GL_DRAW_BUFFER6 0x882B +#define GL_DRAW_BUFFER7 0x882C +#define GL_DRAW_BUFFER8 0x882D +#define GL_DRAW_BUFFER9 0x882E +#define GL_DRAW_BUFFER10 0x882F +#define GL_DRAW_BUFFER11 0x8830 +#define GL_DRAW_BUFFER12 0x8831 +#define GL_DRAW_BUFFER13 0x8832 +#define GL_DRAW_BUFFER14 0x8833 +#define GL_DRAW_BUFFER15 0x8834 +#define GL_MAX_FRAGMENT_UNIFORM_COMPONENTS 0x8B49 +#define GL_MAX_VERTEX_UNIFORM_COMPONENTS 0x8B4A +#define GL_SAMPLER_3D 0x8B5F +#define GL_SAMPLER_2D_SHADOW 0x8B62 +#define GL_FRAGMENT_SHADER_DERIVATIVE_HINT 0x8B8B +#define GL_PIXEL_PACK_BUFFER 0x88EB +#define GL_PIXEL_UNPACK_BUFFER 0x88EC +#define GL_PIXEL_PACK_BUFFER_BINDING 0x88ED +#define GL_PIXEL_UNPACK_BUFFER_BINDING 0x88EF +#define GL_FLOAT_MAT2x3 0x8B65 +#define GL_FLOAT_MAT2x4 0x8B66 +#define GL_FLOAT_MAT3x2 0x8B67 +#define GL_FLOAT_MAT3x4 0x8B68 +#define GL_FLOAT_MAT4x2 0x8B69 +#define GL_FLOAT_MAT4x3 0x8B6A +#define GL_SRGB 0x8C40 +#define GL_SRGB8 0x8C41 +#define GL_SRGB8_ALPHA8 0x8C43 +#define GL_COMPARE_REF_TO_TEXTURE 0x884E +#define GL_MAJOR_VERSION 0x821B +#define GL_MINOR_VERSION 0x821C +#define GL_NUM_EXTENSIONS 0x821D +#define GL_RGBA32F 0x8814 +#define GL_RGB32F 0x8815 +#define GL_RGBA16F 0x881A +#define GL_RGB16F 0x881B +#define GL_VERTEX_ATTRIB_ARRAY_INTEGER 0x88FD +#define GL_MAX_ARRAY_TEXTURE_LAYERS 0x88FF +#define GL_MIN_PROGRAM_TEXEL_OFFSET 0x8904 +#define GL_MAX_PROGRAM_TEXEL_OFFSET 0x8905 +#define GL_MAX_VARYING_COMPONENTS 0x8B4B +#define GL_TEXTURE_2D_ARRAY 0x8C1A +#define GL_TEXTURE_BINDING_2D_ARRAY 0x8C1D +#define GL_R11F_G11F_B10F 0x8C3A +#define GL_UNSIGNED_INT_10F_11F_11F_REV 0x8C3B +#define GL_RGB9_E5 0x8C3D +#define GL_UNSIGNED_INT_5_9_9_9_REV 0x8C3E +#define GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH 0x8C76 +#define GL_TRANSFORM_FEEDBACK_BUFFER_MODE 0x8C7F +#define GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS 0x8C80 +#define GL_TRANSFORM_FEEDBACK_VARYINGS 0x8C83 +#define GL_TRANSFORM_FEEDBACK_BUFFER_START 0x8C84 +#define GL_TRANSFORM_FEEDBACK_BUFFER_SIZE 0x8C85 +#define GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN 0x8C88 +#define GL_RASTERIZER_DISCARD 0x8C89 +#define GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS 0x8C8A +#define GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS 0x8C8B +#define GL_INTERLEAVED_ATTRIBS 0x8C8C +#define GL_SEPARATE_ATTRIBS 0x8C8D +#define GL_TRANSFORM_FEEDBACK_BUFFER 0x8C8E +#define GL_TRANSFORM_FEEDBACK_BUFFER_BINDING 0x8C8F +#define GL_RGBA32UI 0x8D70 +#define GL_RGB32UI 0x8D71 +#define GL_RGBA16UI 0x8D76 +#define GL_RGB16UI 0x8D77 +#define GL_RGBA8UI 0x8D7C +#define GL_RGB8UI 0x8D7D +#define GL_RGBA32I 0x8D82 +#define GL_RGB32I 0x8D83 +#define GL_RGBA16I 0x8D88 +#define GL_RGB16I 0x8D89 +#define GL_RGBA8I 0x8D8E +#define GL_RGB8I 0x8D8F +#define GL_RED_INTEGER 0x8D94 +#define GL_RGB_INTEGER 0x8D98 +#define GL_RGBA_INTEGER 0x8D99 +#define GL_SAMPLER_2D_ARRAY 0x8DC1 +#define GL_SAMPLER_2D_ARRAY_SHADOW 0x8DC4 +#define GL_SAMPLER_CUBE_SHADOW 0x8DC5 +#define GL_UNSIGNED_INT_VEC2 0x8DC6 +#define GL_UNSIGNED_INT_VEC3 0x8DC7 +#define GL_UNSIGNED_INT_VEC4 0x8DC8 +#define GL_INT_SAMPLER_2D 0x8DCA +#define GL_INT_SAMPLER_3D 0x8DCB +#define GL_INT_SAMPLER_CUBE 0x8DCC +#define GL_INT_SAMPLER_2D_ARRAY 0x8DCF +#define GL_UNSIGNED_INT_SAMPLER_2D 0x8DD2 +#define GL_UNSIGNED_INT_SAMPLER_3D 0x8DD3 +#define GL_UNSIGNED_INT_SAMPLER_CUBE 0x8DD4 +#define GL_UNSIGNED_INT_SAMPLER_2D_ARRAY 0x8DD7 +#define GL_BUFFER_ACCESS_FLAGS 0x911F +#define GL_BUFFER_MAP_LENGTH 0x9120 +#define GL_BUFFER_MAP_OFFSET 0x9121 +#define GL_DEPTH_COMPONENT32F 0x8CAC +#define GL_DEPTH32F_STENCIL8 0x8CAD +#define GL_FLOAT_32_UNSIGNED_INT_24_8_REV 0x8DAD +#define GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING 0x8210 +#define GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE 0x8211 +#define GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE 0x8212 +#define GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE 0x8213 +#define GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE 0x8214 +#define GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE 0x8215 +#define GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE 0x8216 +#define GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE 0x8217 +#define GL_FRAMEBUFFER_DEFAULT 0x8218 +#define GL_FRAMEBUFFER_UNDEFINED 0x8219 +#define GL_DEPTH_STENCIL_ATTACHMENT 0x821A +#define GL_DEPTH_STENCIL 0x84F9 +#define GL_UNSIGNED_INT_24_8 0x84FA +#define GL_DEPTH24_STENCIL8 0x88F0 +#define GL_UNSIGNED_NORMALIZED 0x8C17 +#define GL_DRAW_FRAMEBUFFER_BINDING GL_FRAMEBUFFER_BINDING +#define GL_READ_FRAMEBUFFER 0x8CA8 +#define GL_DRAW_FRAMEBUFFER 0x8CA9 +#define GL_READ_FRAMEBUFFER_BINDING 0x8CAA +#define GL_RENDERBUFFER_SAMPLES 0x8CAB +#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER 0x8CD4 +#define GL_MAX_COLOR_ATTACHMENTS 0x8CDF +#define GL_COLOR_ATTACHMENT1 0x8CE1 +#define GL_COLOR_ATTACHMENT2 0x8CE2 +#define GL_COLOR_ATTACHMENT3 0x8CE3 +#define GL_COLOR_ATTACHMENT4 0x8CE4 +#define GL_COLOR_ATTACHMENT5 0x8CE5 +#define GL_COLOR_ATTACHMENT6 0x8CE6 +#define GL_COLOR_ATTACHMENT7 0x8CE7 +#define GL_COLOR_ATTACHMENT8 0x8CE8 +#define GL_COLOR_ATTACHMENT9 0x8CE9 +#define GL_COLOR_ATTACHMENT10 0x8CEA +#define GL_COLOR_ATTACHMENT11 0x8CEB +#define GL_COLOR_ATTACHMENT12 0x8CEC +#define GL_COLOR_ATTACHMENT13 0x8CED +#define GL_COLOR_ATTACHMENT14 0x8CEE +#define GL_COLOR_ATTACHMENT15 0x8CEF +#define GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE 0x8D56 +#define GL_MAX_SAMPLES 0x8D57 +#define GL_HALF_FLOAT 0x140B +#define GL_MAP_READ_BIT 0x0001 +#define GL_MAP_WRITE_BIT 0x0002 +#define GL_MAP_INVALIDATE_RANGE_BIT 0x0004 +#define GL_MAP_INVALIDATE_BUFFER_BIT 0x0008 +#define GL_MAP_FLUSH_EXPLICIT_BIT 0x0010 +#define GL_MAP_UNSYNCHRONIZED_BIT 0x0020 +#define GL_RG 0x8227 +#define GL_RG_INTEGER 0x8228 +#define GL_R8 0x8229 +#define GL_RG8 0x822B +#define GL_R16F 0x822D +#define GL_R32F 0x822E +#define GL_RG16F 0x822F +#define GL_RG32F 0x8230 +#define GL_R8I 0x8231 +#define GL_R8UI 0x8232 +#define GL_R16I 0x8233 +#define GL_R16UI 0x8234 +#define GL_R32I 0x8235 +#define GL_R32UI 0x8236 +#define GL_RG8I 0x8237 +#define GL_RG8UI 0x8238 +#define GL_RG16I 0x8239 +#define GL_RG16UI 0x823A +#define GL_RG32I 0x823B +#define GL_RG32UI 0x823C +#define GL_VERTEX_ARRAY_BINDING 0x85B5 +#define GL_R8_SNORM 0x8F94 +#define GL_RG8_SNORM 0x8F95 +#define GL_RGB8_SNORM 0x8F96 +#define GL_RGBA8_SNORM 0x8F97 +#define GL_SIGNED_NORMALIZED 0x8F9C +#define GL_PRIMITIVE_RESTART_FIXED_INDEX 0x8D69 +#define GL_COPY_READ_BUFFER 0x8F36 +#define GL_COPY_WRITE_BUFFER 0x8F37 +#define GL_COPY_READ_BUFFER_BINDING GL_COPY_READ_BUFFER +#define GL_COPY_WRITE_BUFFER_BINDING GL_COPY_WRITE_BUFFER +#define GL_UNIFORM_BUFFER 0x8A11 +#define GL_UNIFORM_BUFFER_BINDING 0x8A28 +#define GL_UNIFORM_BUFFER_START 0x8A29 +#define GL_UNIFORM_BUFFER_SIZE 0x8A2A +#define GL_MAX_VERTEX_UNIFORM_BLOCKS 0x8A2B +#define GL_MAX_FRAGMENT_UNIFORM_BLOCKS 0x8A2D +#define GL_MAX_COMBINED_UNIFORM_BLOCKS 0x8A2E +#define GL_MAX_UNIFORM_BUFFER_BINDINGS 0x8A2F +#define GL_MAX_UNIFORM_BLOCK_SIZE 0x8A30 +#define GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS 0x8A31 +#define GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS 0x8A33 +#define GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT 0x8A34 +#define GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH 0x8A35 +#define GL_ACTIVE_UNIFORM_BLOCKS 0x8A36 +#define GL_UNIFORM_TYPE 0x8A37 +#define GL_UNIFORM_SIZE 0x8A38 +#define GL_UNIFORM_NAME_LENGTH 0x8A39 +#define GL_UNIFORM_BLOCK_INDEX 0x8A3A +#define GL_UNIFORM_OFFSET 0x8A3B +#define GL_UNIFORM_ARRAY_STRIDE 0x8A3C +#define GL_UNIFORM_MATRIX_STRIDE 0x8A3D +#define GL_UNIFORM_IS_ROW_MAJOR 0x8A3E +#define GL_UNIFORM_BLOCK_BINDING 0x8A3F +#define GL_UNIFORM_BLOCK_DATA_SIZE 0x8A40 +#define GL_UNIFORM_BLOCK_NAME_LENGTH 0x8A41 +#define GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS 0x8A42 +#define GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES 0x8A43 +#define GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER 0x8A44 +#define GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER 0x8A46 +#define GL_INVALID_INDEX 0xFFFFFFFFu +#define GL_MAX_VERTEX_OUTPUT_COMPONENTS 0x9122 +#define GL_MAX_FRAGMENT_INPUT_COMPONENTS 0x9125 +#define GL_MAX_SERVER_WAIT_TIMEOUT 0x9111 +#define GL_OBJECT_TYPE 0x9112 +#define GL_SYNC_CONDITION 0x9113 +#define GL_SYNC_STATUS 0x9114 +#define GL_SYNC_FLAGS 0x9115 +#define GL_SYNC_FENCE 0x9116 +#define GL_SYNC_GPU_COMMANDS_COMPLETE 0x9117 +#define GL_UNSIGNALED 0x9118 +#define GL_SIGNALED 0x9119 +#define GL_ALREADY_SIGNALED 0x911A +#define GL_TIMEOUT_EXPIRED 0x911B +#define GL_CONDITION_SATISFIED 0x911C +#define GL_WAIT_FAILED 0x911D +#define GL_SYNC_FLUSH_COMMANDS_BIT 0x00000001 +#define GL_TIMEOUT_IGNORED 0xFFFFFFFFFFFFFFFFull +#define GL_VERTEX_ATTRIB_ARRAY_DIVISOR 0x88FE +#define GL_ANY_SAMPLES_PASSED 0x8C2F +#define GL_ANY_SAMPLES_PASSED_CONSERVATIVE 0x8D6A +#define GL_SAMPLER_BINDING 0x8919 +#define GL_RGB10_A2UI 0x906F +#define GL_TEXTURE_SWIZZLE_R 0x8E42 +#define GL_TEXTURE_SWIZZLE_G 0x8E43 +#define GL_TEXTURE_SWIZZLE_B 0x8E44 +#define GL_TEXTURE_SWIZZLE_A 0x8E45 +#define GL_GREEN 0x1904 +#define GL_BLUE 0x1905 +#define GL_INT_2_10_10_10_REV 0x8D9F +#define GL_TRANSFORM_FEEDBACK 0x8E22 +#define GL_TRANSFORM_FEEDBACK_PAUSED 0x8E23 +#define GL_TRANSFORM_FEEDBACK_ACTIVE 0x8E24 +#define GL_TRANSFORM_FEEDBACK_BINDING 0x8E25 +#define GL_PROGRAM_BINARY_RETRIEVABLE_HINT 0x8257 +#define GL_PROGRAM_BINARY_LENGTH 0x8741 +#define GL_NUM_PROGRAM_BINARY_FORMATS 0x87FE +#define GL_PROGRAM_BINARY_FORMATS 0x87FF +#define GL_COMPRESSED_R11_EAC 0x9270 +#define GL_COMPRESSED_SIGNED_R11_EAC 0x9271 +#define GL_COMPRESSED_RG11_EAC 0x9272 +#define GL_COMPRESSED_SIGNED_RG11_EAC 0x9273 +#define GL_COMPRESSED_RGB8_ETC2 0x9274 +#define GL_COMPRESSED_SRGB8_ETC2 0x9275 +#define GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2 0x9276 +#define GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2 0x9277 +#define GL_COMPRESSED_RGBA8_ETC2_EAC 0x9278 +#define GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC 0x9279 +#define GL_TEXTURE_IMMUTABLE_FORMAT 0x912F +#define GL_MAX_ELEMENT_INDEX 0x8D6B +#define GL_NUM_SAMPLE_COUNTS 0x9380 +#define GL_TEXTURE_IMMUTABLE_LEVELS 0x8D63 + +/*------------------------------------------------------------------------- + * Entrypoint definitions + *-----------------------------------------------------------------------*/ + +/* OpenGL ES 2.0 */ + +GL_APICALL void GL_APIENTRY glActiveTexture (GLenum texture); +GL_APICALL void GL_APIENTRY glAttachShader (GLuint program, GLuint shader); +GL_APICALL void GL_APIENTRY glBindAttribLocation (GLuint program, GLuint index, const GLchar* name); +GL_APICALL void GL_APIENTRY glBindBuffer (GLenum target, GLuint buffer); +GL_APICALL void GL_APIENTRY glBindFramebuffer (GLenum target, GLuint framebuffer); +GL_APICALL void GL_APIENTRY glBindRenderbuffer (GLenum target, GLuint renderbuffer); +GL_APICALL void GL_APIENTRY glBindTexture (GLenum target, GLuint texture); +GL_APICALL void GL_APIENTRY glBlendColor (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); +GL_APICALL void GL_APIENTRY glBlendEquation (GLenum mode); +GL_APICALL void GL_APIENTRY glBlendEquationSeparate (GLenum modeRGB, GLenum modeAlpha); +GL_APICALL void GL_APIENTRY glBlendFunc (GLenum sfactor, GLenum dfactor); +GL_APICALL void GL_APIENTRY glBlendFuncSeparate (GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha); +GL_APICALL void GL_APIENTRY glBufferData (GLenum target, GLsizeiptr size, const GLvoid* data, GLenum usage); +GL_APICALL void GL_APIENTRY glBufferSubData (GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid* data); +GL_APICALL GLenum GL_APIENTRY glCheckFramebufferStatus (GLenum target); +GL_APICALL void GL_APIENTRY glClear (GLbitfield mask); +GL_APICALL void GL_APIENTRY glClearColor (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); +GL_APICALL void GL_APIENTRY glClearDepthf (GLfloat depth); +GL_APICALL void GL_APIENTRY glClearStencil (GLint s); +GL_APICALL void GL_APIENTRY glColorMask (GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha); +GL_APICALL void GL_APIENTRY glCompileShader (GLuint shader); +GL_APICALL void GL_APIENTRY glCompressedTexImage2D (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid* data); +GL_APICALL void GL_APIENTRY glCompressedTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid* data); +GL_APICALL void GL_APIENTRY glCopyTexImage2D (GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border); +GL_APICALL void GL_APIENTRY glCopyTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height); +GL_APICALL GLuint GL_APIENTRY glCreateProgram (void); +GL_APICALL GLuint GL_APIENTRY glCreateShader (GLenum type); +GL_APICALL void GL_APIENTRY glCullFace (GLenum mode); +GL_APICALL void GL_APIENTRY glDeleteBuffers (GLsizei n, const GLuint* buffers); +GL_APICALL void GL_APIENTRY glDeleteFramebuffers (GLsizei n, const GLuint* framebuffers); +GL_APICALL void GL_APIENTRY glDeleteProgram (GLuint program); +GL_APICALL void GL_APIENTRY glDeleteRenderbuffers (GLsizei n, const GLuint* renderbuffers); +GL_APICALL void GL_APIENTRY glDeleteShader (GLuint shader); +GL_APICALL void GL_APIENTRY glDeleteTextures (GLsizei n, const GLuint* textures); +GL_APICALL void GL_APIENTRY glDepthFunc (GLenum func); +GL_APICALL void GL_APIENTRY glDepthMask (GLboolean flag); +GL_APICALL void GL_APIENTRY glDepthRangef (GLfloat n, GLfloat f); +GL_APICALL void GL_APIENTRY glDetachShader (GLuint program, GLuint shader); +GL_APICALL void GL_APIENTRY glDisable (GLenum cap); +GL_APICALL void GL_APIENTRY glDisableVertexAttribArray (GLuint index); +GL_APICALL void GL_APIENTRY glDrawArrays (GLenum mode, GLint first, GLsizei count); +GL_APICALL void GL_APIENTRY glDrawElements (GLenum mode, GLsizei count, GLenum type, const GLvoid* indices); +GL_APICALL void GL_APIENTRY glEnable (GLenum cap); +GL_APICALL void GL_APIENTRY glEnableVertexAttribArray (GLuint index); +GL_APICALL void GL_APIENTRY glFinish (void); +GL_APICALL void GL_APIENTRY glFlush (void); +GL_APICALL void GL_APIENTRY glFramebufferRenderbuffer (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer); +GL_APICALL void GL_APIENTRY glFramebufferTexture2D (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); +GL_APICALL void GL_APIENTRY glFrontFace (GLenum mode); +GL_APICALL void GL_APIENTRY glGenBuffers (GLsizei n, GLuint* buffers); +GL_APICALL void GL_APIENTRY glGenerateMipmap (GLenum target); +GL_APICALL void GL_APIENTRY glGenFramebuffers (GLsizei n, GLuint* framebuffers); +GL_APICALL void GL_APIENTRY glGenRenderbuffers (GLsizei n, GLuint* renderbuffers); +GL_APICALL void GL_APIENTRY glGenTextures (GLsizei n, GLuint* textures); +GL_APICALL void GL_APIENTRY glGetActiveAttrib (GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name); +GL_APICALL void GL_APIENTRY glGetActiveUniform (GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name); +GL_APICALL void GL_APIENTRY glGetAttachedShaders (GLuint program, GLsizei maxcount, GLsizei* count, GLuint* shaders); +GL_APICALL int GL_APIENTRY glGetAttribLocation (GLuint program, const GLchar* name); +GL_APICALL void GL_APIENTRY glGetBooleanv (GLenum pname, GLboolean* params); +GL_APICALL void GL_APIENTRY glGetBufferParameteriv (GLenum target, GLenum pname, GLint* params); +GL_APICALL GLenum GL_APIENTRY glGetError (void); +GL_APICALL void GL_APIENTRY glGetFloatv (GLenum pname, GLfloat* params); +GL_APICALL void GL_APIENTRY glGetFramebufferAttachmentParameteriv (GLenum target, GLenum attachment, GLenum pname, GLint* params); +GL_APICALL void GL_APIENTRY glGetIntegerv (GLenum pname, GLint* params); +GL_APICALL void GL_APIENTRY glGetProgramiv (GLuint program, GLenum pname, GLint* params); +GL_APICALL void GL_APIENTRY glGetProgramInfoLog (GLuint program, GLsizei bufsize, GLsizei* length, GLchar* infolog); +GL_APICALL void GL_APIENTRY glGetRenderbufferParameteriv (GLenum target, GLenum pname, GLint* params); +GL_APICALL void GL_APIENTRY glGetShaderiv (GLuint shader, GLenum pname, GLint* params); +GL_APICALL void GL_APIENTRY glGetShaderInfoLog (GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* infolog); +GL_APICALL void GL_APIENTRY glGetShaderPrecisionFormat (GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision); +GL_APICALL void GL_APIENTRY glGetShaderSource (GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source); +GL_APICALL const GLubyte* GL_APIENTRY glGetString (GLenum name); +GL_APICALL void GL_APIENTRY glGetTexParameterfv (GLenum target, GLenum pname, GLfloat* params); +GL_APICALL void GL_APIENTRY glGetTexParameteriv (GLenum target, GLenum pname, GLint* params); +GL_APICALL void GL_APIENTRY glGetUniformfv (GLuint program, GLint location, GLfloat* params); +GL_APICALL void GL_APIENTRY glGetUniformiv (GLuint program, GLint location, GLint* params); +GL_APICALL int GL_APIENTRY glGetUniformLocation (GLuint program, const GLchar* name); +GL_APICALL void GL_APIENTRY glGetVertexAttribfv (GLuint index, GLenum pname, GLfloat* params); +GL_APICALL void GL_APIENTRY glGetVertexAttribiv (GLuint index, GLenum pname, GLint* params); +GL_APICALL void GL_APIENTRY glGetVertexAttribPointerv (GLuint index, GLenum pname, GLvoid** pointer); +GL_APICALL void GL_APIENTRY glHint (GLenum target, GLenum mode); +GL_APICALL GLboolean GL_APIENTRY glIsBuffer (GLuint buffer); +GL_APICALL GLboolean GL_APIENTRY glIsEnabled (GLenum cap); +GL_APICALL GLboolean GL_APIENTRY glIsFramebuffer (GLuint framebuffer); +GL_APICALL GLboolean GL_APIENTRY glIsProgram (GLuint program); +GL_APICALL GLboolean GL_APIENTRY glIsRenderbuffer (GLuint renderbuffer); +GL_APICALL GLboolean GL_APIENTRY glIsShader (GLuint shader); +GL_APICALL GLboolean GL_APIENTRY glIsTexture (GLuint texture); +GL_APICALL void GL_APIENTRY glLineWidth (GLfloat width); +GL_APICALL void GL_APIENTRY glLinkProgram (GLuint program); +GL_APICALL void GL_APIENTRY glPixelStorei (GLenum pname, GLint param); +GL_APICALL void GL_APIENTRY glPolygonOffset (GLfloat factor, GLfloat units); +GL_APICALL void GL_APIENTRY glReadPixels (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid* pixels); +GL_APICALL void GL_APIENTRY glReleaseShaderCompiler (void); +GL_APICALL void GL_APIENTRY glRenderbufferStorage (GLenum target, GLenum internalformat, GLsizei width, GLsizei height); +GL_APICALL void GL_APIENTRY glSampleCoverage (GLfloat value, GLboolean invert); +GL_APICALL void GL_APIENTRY glScissor (GLint x, GLint y, GLsizei width, GLsizei height); +GL_APICALL void GL_APIENTRY glShaderBinary (GLsizei n, const GLuint* shaders, GLenum binaryformat, const GLvoid* binary, GLsizei length); +GL_APICALL void GL_APIENTRY glShaderSource (GLuint shader, GLsizei count, const GLchar* const* string, const GLint* length); +GL_APICALL void GL_APIENTRY glStencilFunc (GLenum func, GLint ref, GLuint mask); +GL_APICALL void GL_APIENTRY glStencilFuncSeparate (GLenum face, GLenum func, GLint ref, GLuint mask); +GL_APICALL void GL_APIENTRY glStencilMask (GLuint mask); +GL_APICALL void GL_APIENTRY glStencilMaskSeparate (GLenum face, GLuint mask); +GL_APICALL void GL_APIENTRY glStencilOp (GLenum fail, GLenum zfail, GLenum zpass); +GL_APICALL void GL_APIENTRY glStencilOpSeparate (GLenum face, GLenum fail, GLenum zfail, GLenum zpass); +GL_APICALL void GL_APIENTRY glTexImage2D (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid* pixels); +GL_APICALL void GL_APIENTRY glTexParameterf (GLenum target, GLenum pname, GLfloat param); +GL_APICALL void GL_APIENTRY glTexParameterfv (GLenum target, GLenum pname, const GLfloat* params); +GL_APICALL void GL_APIENTRY glTexParameteri (GLenum target, GLenum pname, GLint param); +GL_APICALL void GL_APIENTRY glTexParameteriv (GLenum target, GLenum pname, const GLint* params); +GL_APICALL void GL_APIENTRY glTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid* pixels); +GL_APICALL void GL_APIENTRY glUniform1f (GLint location, GLfloat x); +GL_APICALL void GL_APIENTRY glUniform1fv (GLint location, GLsizei count, const GLfloat* v); +GL_APICALL void GL_APIENTRY glUniform1i (GLint location, GLint x); +GL_APICALL void GL_APIENTRY glUniform1iv (GLint location, GLsizei count, const GLint* v); +GL_APICALL void GL_APIENTRY glUniform2f (GLint location, GLfloat x, GLfloat y); +GL_APICALL void GL_APIENTRY glUniform2fv (GLint location, GLsizei count, const GLfloat* v); +GL_APICALL void GL_APIENTRY glUniform2i (GLint location, GLint x, GLint y); +GL_APICALL void GL_APIENTRY glUniform2iv (GLint location, GLsizei count, const GLint* v); +GL_APICALL void GL_APIENTRY glUniform3f (GLint location, GLfloat x, GLfloat y, GLfloat z); +GL_APICALL void GL_APIENTRY glUniform3fv (GLint location, GLsizei count, const GLfloat* v); +GL_APICALL void GL_APIENTRY glUniform3i (GLint location, GLint x, GLint y, GLint z); +GL_APICALL void GL_APIENTRY glUniform3iv (GLint location, GLsizei count, const GLint* v); +GL_APICALL void GL_APIENTRY glUniform4f (GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +GL_APICALL void GL_APIENTRY glUniform4fv (GLint location, GLsizei count, const GLfloat* v); +GL_APICALL void GL_APIENTRY glUniform4i (GLint location, GLint x, GLint y, GLint z, GLint w); +GL_APICALL void GL_APIENTRY glUniform4iv (GLint location, GLsizei count, const GLint* v); +GL_APICALL void GL_APIENTRY glUniformMatrix2fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat* value); +GL_APICALL void GL_APIENTRY glUniformMatrix3fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat* value); +GL_APICALL void GL_APIENTRY glUniformMatrix4fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat* value); +GL_APICALL void GL_APIENTRY glUseProgram (GLuint program); +GL_APICALL void GL_APIENTRY glValidateProgram (GLuint program); +GL_APICALL void GL_APIENTRY glVertexAttrib1f (GLuint indx, GLfloat x); +GL_APICALL void GL_APIENTRY glVertexAttrib1fv (GLuint indx, const GLfloat* values); +GL_APICALL void GL_APIENTRY glVertexAttrib2f (GLuint indx, GLfloat x, GLfloat y); +GL_APICALL void GL_APIENTRY glVertexAttrib2fv (GLuint indx, const GLfloat* values); +GL_APICALL void GL_APIENTRY glVertexAttrib3f (GLuint indx, GLfloat x, GLfloat y, GLfloat z); +GL_APICALL void GL_APIENTRY glVertexAttrib3fv (GLuint indx, const GLfloat* values); +GL_APICALL void GL_APIENTRY glVertexAttrib4f (GLuint indx, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +GL_APICALL void GL_APIENTRY glVertexAttrib4fv (GLuint indx, const GLfloat* values); +GL_APICALL void GL_APIENTRY glVertexAttribPointer (GLuint indx, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* ptr); +GL_APICALL void GL_APIENTRY glViewport (GLint x, GLint y, GLsizei width, GLsizei height); + +/* OpenGL ES 3.0 */ + +GL_APICALL void GL_APIENTRY glReadBuffer (GLenum mode); +GL_APICALL void GL_APIENTRY glDrawRangeElements (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid* indices); +GL_APICALL void GL_APIENTRY glTexImage3D (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid* pixels); +GL_APICALL void GL_APIENTRY glTexSubImage3D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid* pixels); +GL_APICALL void GL_APIENTRY glCopyTexSubImage3D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height); +GL_APICALL void GL_APIENTRY glCompressedTexImage3D (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid* data); +GL_APICALL void GL_APIENTRY glCompressedTexSubImage3D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid* data); +GL_APICALL void GL_APIENTRY glGenQueries (GLsizei n, GLuint* ids); +GL_APICALL void GL_APIENTRY glDeleteQueries (GLsizei n, const GLuint* ids); +GL_APICALL GLboolean GL_APIENTRY glIsQuery (GLuint id); +GL_APICALL void GL_APIENTRY glBeginQuery (GLenum target, GLuint id); +GL_APICALL void GL_APIENTRY glEndQuery (GLenum target); +GL_APICALL void GL_APIENTRY glGetQueryiv (GLenum target, GLenum pname, GLint* params); +GL_APICALL void GL_APIENTRY glGetQueryObjectuiv (GLuint id, GLenum pname, GLuint* params); +GL_APICALL GLboolean GL_APIENTRY glUnmapBuffer (GLenum target); +GL_APICALL void GL_APIENTRY glGetBufferPointerv (GLenum target, GLenum pname, GLvoid** params); +GL_APICALL void GL_APIENTRY glDrawBuffers (GLsizei n, const GLenum* bufs); +GL_APICALL void GL_APIENTRY glUniformMatrix2x3fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat* value); +GL_APICALL void GL_APIENTRY glUniformMatrix3x2fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat* value); +GL_APICALL void GL_APIENTRY glUniformMatrix2x4fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat* value); +GL_APICALL void GL_APIENTRY glUniformMatrix4x2fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat* value); +GL_APICALL void GL_APIENTRY glUniformMatrix3x4fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat* value); +GL_APICALL void GL_APIENTRY glUniformMatrix4x3fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat* value); +GL_APICALL void GL_APIENTRY glBlitFramebuffer (GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter); +GL_APICALL void GL_APIENTRY glRenderbufferStorageMultisample (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height); +GL_APICALL void GL_APIENTRY glFramebufferTextureLayer (GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer); +GL_APICALL GLvoid* GL_APIENTRY glMapBufferRange (GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access); +GL_APICALL void GL_APIENTRY glFlushMappedBufferRange (GLenum target, GLintptr offset, GLsizeiptr length); +GL_APICALL void GL_APIENTRY glBindVertexArray (GLuint array); +GL_APICALL void GL_APIENTRY glDeleteVertexArrays (GLsizei n, const GLuint* arrays); +GL_APICALL void GL_APIENTRY glGenVertexArrays (GLsizei n, GLuint* arrays); +GL_APICALL GLboolean GL_APIENTRY glIsVertexArray (GLuint array); +GL_APICALL void GL_APIENTRY glGetIntegeri_v (GLenum target, GLuint index, GLint* data); +GL_APICALL void GL_APIENTRY glBeginTransformFeedback (GLenum primitiveMode); +GL_APICALL void GL_APIENTRY glEndTransformFeedback (void); +GL_APICALL void GL_APIENTRY glBindBufferRange (GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size); +GL_APICALL void GL_APIENTRY glBindBufferBase (GLenum target, GLuint index, GLuint buffer); +GL_APICALL void GL_APIENTRY glTransformFeedbackVaryings (GLuint program, GLsizei count, const GLchar* const* varyings, GLenum bufferMode); +GL_APICALL void GL_APIENTRY glGetTransformFeedbackVarying (GLuint program, GLuint index, GLsizei bufSize, GLsizei* length, GLsizei* size, GLenum* type, GLchar* name); +GL_APICALL void GL_APIENTRY glVertexAttribIPointer (GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid* pointer); +GL_APICALL void GL_APIENTRY glGetVertexAttribIiv (GLuint index, GLenum pname, GLint* params); +GL_APICALL void GL_APIENTRY glGetVertexAttribIuiv (GLuint index, GLenum pname, GLuint* params); +GL_APICALL void GL_APIENTRY glVertexAttribI4i (GLuint index, GLint x, GLint y, GLint z, GLint w); +GL_APICALL void GL_APIENTRY glVertexAttribI4ui (GLuint index, GLuint x, GLuint y, GLuint z, GLuint w); +GL_APICALL void GL_APIENTRY glVertexAttribI4iv (GLuint index, const GLint* v); +GL_APICALL void GL_APIENTRY glVertexAttribI4uiv (GLuint index, const GLuint* v); +GL_APICALL void GL_APIENTRY glGetUniformuiv (GLuint program, GLint location, GLuint* params); +GL_APICALL GLint GL_APIENTRY glGetFragDataLocation (GLuint program, const GLchar *name); +GL_APICALL void GL_APIENTRY glUniform1ui (GLint location, GLuint v0); +GL_APICALL void GL_APIENTRY glUniform2ui (GLint location, GLuint v0, GLuint v1); +GL_APICALL void GL_APIENTRY glUniform3ui (GLint location, GLuint v0, GLuint v1, GLuint v2); +GL_APICALL void GL_APIENTRY glUniform4ui (GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3); +GL_APICALL void GL_APIENTRY glUniform1uiv (GLint location, GLsizei count, const GLuint* value); +GL_APICALL void GL_APIENTRY glUniform2uiv (GLint location, GLsizei count, const GLuint* value); +GL_APICALL void GL_APIENTRY glUniform3uiv (GLint location, GLsizei count, const GLuint* value); +GL_APICALL void GL_APIENTRY glUniform4uiv (GLint location, GLsizei count, const GLuint* value); +GL_APICALL void GL_APIENTRY glClearBufferiv (GLenum buffer, GLint drawbuffer, const GLint* value); +GL_APICALL void GL_APIENTRY glClearBufferuiv (GLenum buffer, GLint drawbuffer, const GLuint* value); +GL_APICALL void GL_APIENTRY glClearBufferfv (GLenum buffer, GLint drawbuffer, const GLfloat* value); +GL_APICALL void GL_APIENTRY glClearBufferfi (GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil); +GL_APICALL const GLubyte* GL_APIENTRY glGetStringi (GLenum name, GLuint index); +GL_APICALL void GL_APIENTRY glCopyBufferSubData (GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size); +GL_APICALL void GL_APIENTRY glGetUniformIndices (GLuint program, GLsizei uniformCount, const GLchar* const* uniformNames, GLuint* uniformIndices); +GL_APICALL void GL_APIENTRY glGetActiveUniformsiv (GLuint program, GLsizei uniformCount, const GLuint* uniformIndices, GLenum pname, GLint* params); +GL_APICALL GLuint GL_APIENTRY glGetUniformBlockIndex (GLuint program, const GLchar* uniformBlockName); +GL_APICALL void GL_APIENTRY glGetActiveUniformBlockiv (GLuint program, GLuint uniformBlockIndex, GLenum pname, GLint* params); +GL_APICALL void GL_APIENTRY glGetActiveUniformBlockName (GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei* length, GLchar* uniformBlockName); +GL_APICALL void GL_APIENTRY glUniformBlockBinding (GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding); +GL_APICALL void GL_APIENTRY glDrawArraysInstanced (GLenum mode, GLint first, GLsizei count, GLsizei instanceCount); +GL_APICALL void GL_APIENTRY glDrawElementsInstanced (GLenum mode, GLsizei count, GLenum type, const GLvoid* indices, GLsizei instanceCount); +GL_APICALL GLsync GL_APIENTRY glFenceSync (GLenum condition, GLbitfield flags); +GL_APICALL GLboolean GL_APIENTRY glIsSync (GLsync sync); +GL_APICALL void GL_APIENTRY glDeleteSync (GLsync sync); +GL_APICALL GLenum GL_APIENTRY glClientWaitSync (GLsync sync, GLbitfield flags, GLuint64 timeout); +GL_APICALL void GL_APIENTRY glWaitSync (GLsync sync, GLbitfield flags, GLuint64 timeout); +GL_APICALL void GL_APIENTRY glGetInteger64v (GLenum pname, GLint64* params); +GL_APICALL void GL_APIENTRY glGetSynciv (GLsync sync, GLenum pname, GLsizei bufSize, GLsizei* length, GLint* values); +GL_APICALL void GL_APIENTRY glGetInteger64i_v (GLenum target, GLuint index, GLint64* data); +GL_APICALL void GL_APIENTRY glGetBufferParameteri64v (GLenum target, GLenum pname, GLint64* params); +GL_APICALL void GL_APIENTRY glGenSamplers (GLsizei count, GLuint* samplers); +GL_APICALL void GL_APIENTRY glDeleteSamplers (GLsizei count, const GLuint* samplers); +GL_APICALL GLboolean GL_APIENTRY glIsSampler (GLuint sampler); +GL_APICALL void GL_APIENTRY glBindSampler (GLuint unit, GLuint sampler); +GL_APICALL void GL_APIENTRY glSamplerParameteri (GLuint sampler, GLenum pname, GLint param); +GL_APICALL void GL_APIENTRY glSamplerParameteriv (GLuint sampler, GLenum pname, const GLint* param); +GL_APICALL void GL_APIENTRY glSamplerParameterf (GLuint sampler, GLenum pname, GLfloat param); +GL_APICALL void GL_APIENTRY glSamplerParameterfv (GLuint sampler, GLenum pname, const GLfloat* param); +GL_APICALL void GL_APIENTRY glGetSamplerParameteriv (GLuint sampler, GLenum pname, GLint* params); +GL_APICALL void GL_APIENTRY glGetSamplerParameterfv (GLuint sampler, GLenum pname, GLfloat* params); +GL_APICALL void GL_APIENTRY glVertexAttribDivisor (GLuint index, GLuint divisor); +GL_APICALL void GL_APIENTRY glBindTransformFeedback (GLenum target, GLuint id); +GL_APICALL void GL_APIENTRY glDeleteTransformFeedbacks (GLsizei n, const GLuint* ids); +GL_APICALL void GL_APIENTRY glGenTransformFeedbacks (GLsizei n, GLuint* ids); +GL_APICALL GLboolean GL_APIENTRY glIsTransformFeedback (GLuint id); +GL_APICALL void GL_APIENTRY glPauseTransformFeedback (void); +GL_APICALL void GL_APIENTRY glResumeTransformFeedback (void); +GL_APICALL void GL_APIENTRY glGetProgramBinary (GLuint program, GLsizei bufSize, GLsizei* length, GLenum* binaryFormat, GLvoid* binary); +GL_APICALL void GL_APIENTRY glProgramBinary (GLuint program, GLenum binaryFormat, const GLvoid* binary, GLsizei length); +GL_APICALL void GL_APIENTRY glProgramParameteri (GLuint program, GLenum pname, GLint value); +GL_APICALL void GL_APIENTRY glInvalidateFramebuffer (GLenum target, GLsizei numAttachments, const GLenum* attachments); +GL_APICALL void GL_APIENTRY glInvalidateSubFramebuffer (GLenum target, GLsizei numAttachments, const GLenum* attachments, GLint x, GLint y, GLsizei width, GLsizei height); +GL_APICALL void GL_APIENTRY glTexStorage2D (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height); +GL_APICALL void GL_APIENTRY glTexStorage3D (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth); +GL_APICALL void GL_APIENTRY glGetInternalformativ (GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint* params); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/Projects/Android/jni/SupportLibs/gl4es/include/GLES/gl3ext.h b/Projects/Android/jni/SupportLibs/gl4es/include/GLES/gl3ext.h new file mode 100644 index 0000000..4d4ea96 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/include/GLES/gl3ext.h @@ -0,0 +1,24 @@ +#ifndef __gl3ext_h_ +#define __gl3ext_h_ + +/* $Revision: 17809 $ on $Date:: 2012-05-14 08:03:36 -0700 #$ */ + +/* + * This document is licensed under the SGI Free Software B License Version + * 2.0. For details, see http://oss.sgi.com/projects/FreeB/ . + */ + +/* OpenGL ES 3 Extensions + * + * After an OES extension's interactions with OpenGl ES 3.0 have been documented, + * its tokens and function definitions should be added to this file in a manner + * that does not conflict with gl2ext.h or gl3.h. + * + * Tokens and function definitions for extensions that have become standard + * features in OpenGL ES 3.0 will not be added to this file. + * + * Applications using OpenGL-ES-2-only extensions should include gl2ext.h + */ + +#endif /* __gl3ext_h_ */ + diff --git a/Projects/Android/jni/SupportLibs/gl4es/include/GLES/gl3platform.h b/Projects/Android/jni/SupportLibs/gl4es/include/GLES/gl3platform.h new file mode 100644 index 0000000..1bd1a85 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/include/GLES/gl3platform.h @@ -0,0 +1,30 @@ +#ifndef __gl3platform_h_ +#define __gl3platform_h_ + +/* $Revision: 18437 $ on $Date:: 2012-07-08 23:31:39 -0700 #$ */ + +/* + * This document is licensed under the SGI Free Software B License Version + * 2.0. For details, see http://oss.sgi.com/projects/FreeB/ . + */ + +/* Platform-specific types and definitions for OpenGL ES 3.X gl3.h + * + * Adopters may modify khrplatform.h and this file to suit their platform. + * You are encouraged to submit all modifications to the Khronos group so that + * they can be included in future versions of this file. Please submit changes + * by sending them to the public Khronos Bugzilla (http://khronos.org/bugzilla) + * by filing a bug against product "OpenGL-ES" component "Registry". + */ + +#include + +#ifndef GL_APICALL +#define GL_APICALL KHRONOS_APICALL +#endif + +#ifndef GL_APIENTRY +#define GL_APIENTRY KHRONOS_APIENTRY +#endif + +#endif /* __gl3platform_h_ */ diff --git a/Projects/Android/jni/SupportLibs/gl4es/include/GLES/glext.h b/Projects/Android/jni/SupportLibs/gl4es/include/GLES/glext.h new file mode 100644 index 0000000..5b46ae6 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/include/GLES/glext.h @@ -0,0 +1,1278 @@ +#ifndef __glext_h_ +#define __glext_h_ + +/* $Revision: 19260 $ on $Date:: 2012-09-20 11:30:36 -0700 #$ */ + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * This document is licensed under the SGI Free Software B License Version + * 2.0. For details, see http://oss.sgi.com/projects/FreeB/ . + */ + +#ifndef GL_APIENTRYP +# define GL_APIENTRYP GL_APIENTRY* +#endif + +/*------------------------------------------------------------------------* + * OES extension tokens + *------------------------------------------------------------------------*/ + +/* GL_OES_blend_equation_separate */ +#ifndef GL_OES_blend_equation_separate +/* BLEND_EQUATION_RGB_OES same as BLEND_EQUATION_OES */ +#define GL_BLEND_EQUATION_RGB_OES 0x8009 +#define GL_BLEND_EQUATION_ALPHA_OES 0x883D +#endif + +/* GL_OES_blend_func_separate */ +#ifndef GL_OES_blend_func_separate +#define GL_BLEND_DST_RGB_OES 0x80C8 +#define GL_BLEND_SRC_RGB_OES 0x80C9 +#define GL_BLEND_DST_ALPHA_OES 0x80CA +#define GL_BLEND_SRC_ALPHA_OES 0x80CB +#endif + +/* GL_OES_blend_subtract */ +#ifndef GL_OES_blend_subtract +#define GL_BLEND_EQUATION_OES 0x8009 +#define GL_FUNC_ADD_OES 0x8006 +#define GL_FUNC_SUBTRACT_OES 0x800A +#define GL_FUNC_REVERSE_SUBTRACT_OES 0x800B +#endif + +/* GL_OES_compressed_ETC1_RGB8_texture */ +#ifndef GL_OES_compressed_ETC1_RGB8_texture +#define GL_ETC1_RGB8_OES 0x8D64 +#endif + +/* GL_OES_depth24 */ +#ifndef GL_OES_depth24 +#define GL_DEPTH_COMPONENT24_OES 0x81A6 +#endif + +/* GL_OES_depth32 */ +#ifndef GL_OES_depth32 +#define GL_DEPTH_COMPONENT32_OES 0x81A7 +#endif + +/* GL_OES_draw_texture */ +#ifndef GL_OES_draw_texture +#define GL_TEXTURE_CROP_RECT_OES 0x8B9D +#endif + +/* GL_OES_EGL_image */ +#ifndef GL_OES_EGL_image +typedef void* GLeglImageOES; +#endif + +/* GL_OES_EGL_image_external */ +#ifndef GL_OES_EGL_image_external +/* GLeglImageOES defined in GL_OES_EGL_image already. */ +#define GL_TEXTURE_EXTERNAL_OES 0x8D65 +#define GL_TEXTURE_BINDING_EXTERNAL_OES 0x8D67 +#define GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES 0x8D68 +#endif + +/* GL_OES_element_index_uint */ +#ifndef GL_OES_element_index_uint +#define GL_UNSIGNED_INT 0x1405 +#endif + +/* GL_OES_fixed_point */ +#ifndef GL_OES_fixed_point +#define GL_FIXED_OES 0x140C +#endif + +/* GL_OES_framebuffer_object */ +#ifndef GL_OES_framebuffer_object +#define GL_NONE_OES 0 +#define GL_FRAMEBUFFER_OES 0x8D40 +#define GL_RENDERBUFFER_OES 0x8D41 +#define GL_RGBA4_OES 0x8056 +#define GL_RGB5_A1_OES 0x8057 +#define GL_RGB565_OES 0x8D62 +#define GL_DEPTH_COMPONENT16_OES 0x81A5 +#define GL_RENDERBUFFER_WIDTH_OES 0x8D42 +#define GL_RENDERBUFFER_HEIGHT_OES 0x8D43 +#define GL_RENDERBUFFER_INTERNAL_FORMAT_OES 0x8D44 +#define GL_RENDERBUFFER_RED_SIZE_OES 0x8D50 +#define GL_RENDERBUFFER_GREEN_SIZE_OES 0x8D51 +#define GL_RENDERBUFFER_BLUE_SIZE_OES 0x8D52 +#define GL_RENDERBUFFER_ALPHA_SIZE_OES 0x8D53 +#define GL_RENDERBUFFER_DEPTH_SIZE_OES 0x8D54 +#define GL_RENDERBUFFER_STENCIL_SIZE_OES 0x8D55 +#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_OES 0x8CD0 +#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_OES 0x8CD1 +#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_OES 0x8CD2 +#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE_OES 0x8CD3 +#define GL_COLOR_ATTACHMENT0_OES 0x8CE0 +#define GL_DEPTH_ATTACHMENT_OES 0x8D00 +#define GL_STENCIL_ATTACHMENT_OES 0x8D20 +#define GL_FRAMEBUFFER_COMPLETE_OES 0x8CD5 +#define GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_OES 0x8CD6 +#define GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_OES 0x8CD7 +#define GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_OES 0x8CD9 +#define GL_FRAMEBUFFER_INCOMPLETE_FORMATS_OES 0x8CDA +#define GL_FRAMEBUFFER_UNSUPPORTED_OES 0x8CDD +#define GL_FRAMEBUFFER_BINDING_OES 0x8CA6 +#define GL_RENDERBUFFER_BINDING_OES 0x8CA7 +#define GL_MAX_RENDERBUFFER_SIZE_OES 0x84E8 +#define GL_INVALID_FRAMEBUFFER_OPERATION_OES 0x0506 +#endif + +/* GL_OES_mapbuffer */ +#ifndef GL_OES_mapbuffer +#define GL_WRITE_ONLY_OES 0x88B9 +#define GL_BUFFER_ACCESS_OES 0x88BB +#define GL_BUFFER_MAPPED_OES 0x88BC +#define GL_BUFFER_MAP_POINTER_OES 0x88BD +#endif + +/* GL_OES_matrix_get */ +#ifndef GL_OES_matrix_get +#define GL_MODELVIEW_MATRIX_FLOAT_AS_INT_BITS_OES 0x898D +#define GL_PROJECTION_MATRIX_FLOAT_AS_INT_BITS_OES 0x898E +#define GL_TEXTURE_MATRIX_FLOAT_AS_INT_BITS_OES 0x898F +#endif + +/* GL_OES_matrix_palette */ +#ifndef GL_OES_matrix_palette +#define GL_MAX_VERTEX_UNITS_OES 0x86A4 +#define GL_MAX_PALETTE_MATRICES_OES 0x8842 +#define GL_MATRIX_PALETTE_OES 0x8840 +#define GL_MATRIX_INDEX_ARRAY_OES 0x8844 +#define GL_WEIGHT_ARRAY_OES 0x86AD +#define GL_CURRENT_PALETTE_MATRIX_OES 0x8843 +#define GL_MATRIX_INDEX_ARRAY_SIZE_OES 0x8846 +#define GL_MATRIX_INDEX_ARRAY_TYPE_OES 0x8847 +#define GL_MATRIX_INDEX_ARRAY_STRIDE_OES 0x8848 +#define GL_MATRIX_INDEX_ARRAY_POINTER_OES 0x8849 +#define GL_MATRIX_INDEX_ARRAY_BUFFER_BINDING_OES 0x8B9E +#define GL_WEIGHT_ARRAY_SIZE_OES 0x86AB +#define GL_WEIGHT_ARRAY_TYPE_OES 0x86A9 +#define GL_WEIGHT_ARRAY_STRIDE_OES 0x86AA +#define GL_WEIGHT_ARRAY_POINTER_OES 0x86AC +#define GL_WEIGHT_ARRAY_BUFFER_BINDING_OES 0x889E +#endif + +/* GL_OES_packed_depth_stencil */ +#ifndef GL_OES_packed_depth_stencil +#define GL_DEPTH_STENCIL_OES 0x84F9 +#define GL_UNSIGNED_INT_24_8_OES 0x84FA +#define GL_DEPTH24_STENCIL8_OES 0x88F0 +#endif + +/* GL_OES_required_internalformat */ +/* No new tokens introduced by this extension. */ + +/* GL_OES_rgb8_rgba8 */ +#ifndef GL_OES_rgb8_rgba8 +#define GL_RGB8_OES 0x8051 +#define GL_RGBA8_OES 0x8058 +#endif + +/* GL_OES_stencil1 */ +#ifndef GL_OES_stencil1 +#define GL_STENCIL_INDEX1_OES 0x8D46 +#endif + +/* GL_OES_stencil4 */ +#ifndef GL_OES_stencil4 +#define GL_STENCIL_INDEX4_OES 0x8D47 +#endif + +/* GL_OES_stencil8 */ +#ifndef GL_OES_stencil8 +#define GL_STENCIL_INDEX8_OES 0x8D48 +#endif + +/* GL_OES_stencil_wrap */ +#ifndef GL_OES_stencil_wrap +#define GL_INCR_WRAP_OES 0x8507 +#define GL_DECR_WRAP_OES 0x8508 +#endif + +/* GL_OES_texture_cube_map */ +#ifndef GL_OES_texture_cube_map +#define GL_NORMAL_MAP_OES 0x8511 +#define GL_REFLECTION_MAP_OES 0x8512 +#define GL_TEXTURE_CUBE_MAP_OES 0x8513 +#define GL_TEXTURE_BINDING_CUBE_MAP_OES 0x8514 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_X_OES 0x8515 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_X_OES 0x8516 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_Y_OES 0x8517 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_OES 0x8518 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_Z_OES 0x8519 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_OES 0x851A +#define GL_MAX_CUBE_MAP_TEXTURE_SIZE_OES 0x851C +#define GL_TEXTURE_GEN_MODE_OES 0x2500 +#define GL_TEXTURE_GEN_STR_OES 0x8D60 +#endif + +/* GL_OES_texture_mirrored_repeat */ +#ifndef GL_OES_texture_mirrored_repeat +#define GL_MIRRORED_REPEAT_OES 0x8370 +#endif + +/* GL_OES_vertex_array_object */ +#ifndef GL_OES_vertex_array_object +#define GL_VERTEX_ARRAY_BINDING_OES 0x85B5 +#endif + +/*------------------------------------------------------------------------* + * AMD extension tokens + *------------------------------------------------------------------------*/ + +/* GL_AMD_compressed_3DC_texture */ +#ifndef GL_AMD_compressed_3DC_texture +#define GL_3DC_X_AMD 0x87F9 +#define GL_3DC_XY_AMD 0x87FA +#endif + +/* GL_AMD_compressed_ATC_texture */ +#ifndef GL_AMD_compressed_ATC_texture +#define GL_ATC_RGB_AMD 0x8C92 +#define GL_ATC_RGBA_EXPLICIT_ALPHA_AMD 0x8C93 +#define GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD 0x87EE +#endif + +/*------------------------------------------------------------------------* + * APPLE extension tokens + *------------------------------------------------------------------------*/ + +/* GL_APPLE_copy_texture_levels */ +/* No new tokens introduced by this extension. */ + +/* GL_APPLE_framebuffer_multisample */ +#ifndef GL_APPLE_framebuffer_multisample +#define GL_RENDERBUFFER_SAMPLES_APPLE 0x8CAB +#define GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_APPLE 0x8D56 +#define GL_MAX_SAMPLES_APPLE 0x8D57 +#define GL_READ_FRAMEBUFFER_APPLE 0x8CA8 +#define GL_DRAW_FRAMEBUFFER_APPLE 0x8CA9 +#define GL_DRAW_FRAMEBUFFER_BINDING_APPLE 0x8CA6 +#define GL_READ_FRAMEBUFFER_BINDING_APPLE 0x8CAA +#endif + +/* GL_APPLE_sync */ +#ifndef GL_APPLE_sync + +/* These types are defined with reference to + * in the Apple extension spec, but here we use the Khronos + * portable types in khrplatform.h, and assume those types + * are always defined. + * If any other extensions using these types are defined, + * the typedefs must move out of this block and be shared. + */ +typedef khronos_int64_t GLint64; +typedef khronos_uint64_t GLuint64; +typedef struct __GLsync *GLsync; + +#define GL_SYNC_OBJECT_APPLE 0x8A53 +#define GL_MAX_SERVER_WAIT_TIMEOUT_APPLE 0x9111 +#define GL_OBJECT_TYPE_APPLE 0x9112 +#define GL_SYNC_CONDITION_APPLE 0x9113 +#define GL_SYNC_STATUS_APPLE 0x9114 +#define GL_SYNC_FLAGS_APPLE 0x9115 +#define GL_SYNC_FENCE_APPLE 0x9116 +#define GL_SYNC_GPU_COMMANDS_COMPLETE_APPLE 0x9117 +#define GL_UNSIGNALED_APPLE 0x9118 +#define GL_SIGNALED_APPLE 0x9119 +#define GL_ALREADY_SIGNALED_APPLE 0x911A +#define GL_TIMEOUT_EXPIRED_APPLE 0x911B +#define GL_CONDITION_SATISFIED_APPLE 0x911C +#define GL_WAIT_FAILED_APPLE 0x911D +#define GL_SYNC_FLUSH_COMMANDS_BIT_APPLE 0x00000001 +#define GL_TIMEOUT_IGNORED_APPLE 0xFFFFFFFFFFFFFFFFull +#endif + +/* GL_APPLE_texture_2D_limited_npot */ +/* No new tokens introduced by this extension. */ + +/* GL_APPLE_texture_format_BGRA8888 */ +#ifndef GL_APPLE_texture_format_BGRA8888 +#define GL_BGRA_EXT 0x80E1 +#endif + +/* GL_APPLE_texture_max_level */ +#ifndef GL_APPLE_texture_max_level +#define GL_TEXTURE_MAX_LEVEL_APPLE 0x813D +#endif + +/*------------------------------------------------------------------------* + * ARM extension tokens + *------------------------------------------------------------------------*/ + +/* GL_ARM_rgba8 */ +/* No new tokens introduced by this extension. */ + +/*------------------------------------------------------------------------* + * EXT extension tokens + *------------------------------------------------------------------------*/ + +/* GL_EXT_blend_minmax */ +#ifndef GL_EXT_blend_minmax +#define GL_MIN_EXT 0x8007 +#define GL_MAX_EXT 0x8008 +#endif + +/* GL_EXT_discard_framebuffer */ +#ifndef GL_EXT_discard_framebuffer +#define GL_COLOR_EXT 0x1800 +#define GL_DEPTH_EXT 0x1801 +#define GL_STENCIL_EXT 0x1802 +#endif + +/* GL_EXT_map_buffer_range */ +#ifndef GL_EXT_map_buffer_range +#define GL_MAP_READ_BIT_EXT 0x0001 +#define GL_MAP_WRITE_BIT_EXT 0x0002 +#define GL_MAP_INVALIDATE_RANGE_BIT_EXT 0x0004 +#define GL_MAP_INVALIDATE_BUFFER_BIT_EXT 0x0008 +#define GL_MAP_FLUSH_EXPLICIT_BIT_EXT 0x0010 +#define GL_MAP_UNSYNCHRONIZED_BIT_EXT 0x0020 +#endif + +/* GL_EXT_multisampled_render_to_texture */ +#ifndef GL_EXT_multisampled_render_to_texture +#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_SAMPLES_EXT 0x8D6C +/* reuse values from GL_EXT_framebuffer_multisample (desktop extension) */ +#define GL_RENDERBUFFER_SAMPLES_EXT 0x8CAB +#define GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_EXT 0x8D56 +#define GL_MAX_SAMPLES_EXT 0x8D57 +#endif + +/* GL_EXT_multi_draw_arrays */ +/* No new tokens introduced by this extension. */ + +/* GL_EXT_read_format_bgra */ +#ifndef GL_EXT_read_format_bgra +#define GL_BGRA_EXT 0x80E1 +#define GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT 0x8365 +#define GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT 0x8366 +#endif + +/* GL_EXT_robustness */ +#ifndef GL_EXT_robustness +/* reuse GL_NO_ERROR */ +#define GL_GUILTY_CONTEXT_RESET_EXT 0x8253 +#define GL_INNOCENT_CONTEXT_RESET_EXT 0x8254 +#define GL_UNKNOWN_CONTEXT_RESET_EXT 0x8255 +#define GL_CONTEXT_ROBUST_ACCESS_EXT 0x90F3 +#define GL_RESET_NOTIFICATION_STRATEGY_EXT 0x8256 +#define GL_LOSE_CONTEXT_ON_RESET_EXT 0x8252 +#define GL_NO_RESET_NOTIFICATION_EXT 0x8261 +#endif + +/* GL_EXT_sRGB */ +#ifndef GL_EXT_sRGB +#define GL_SRGB_EXT 0x8C40 +#define GL_SRGB_ALPHA_EXT 0x8C42 +#define GL_SRGB8_ALPHA8_EXT 0x8C43 +#define GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING_EXT 0x8210 +#endif + +/* GL_EXT_texture_compression_dxt1 */ +#ifndef GL_EXT_texture_compression_dxt1 +#define GL_COMPRESSED_RGB_S3TC_DXT1_EXT 0x83F0 +#define GL_COMPRESSED_RGBA_S3TC_DXT1_EXT 0x83F1 +#endif + +/* GL_EXT_texture_filter_anisotropic */ +#ifndef GL_EXT_texture_filter_anisotropic +#define GL_TEXTURE_MAX_ANISOTROPY_EXT 0x84FE +#define GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT 0x84FF +#endif + +/* GL_EXT_texture_format_BGRA8888 */ +#ifndef GL_EXT_texture_format_BGRA8888 +#define GL_BGRA_EXT 0x80E1 +#endif + +/* GL_EXT_texture_lod_bias */ +#ifndef GL_EXT_texture_lod_bias +#define GL_MAX_TEXTURE_LOD_BIAS_EXT 0x84FD +#define GL_TEXTURE_FILTER_CONTROL_EXT 0x8500 +#define GL_TEXTURE_LOD_BIAS_EXT 0x8501 +#endif + +/* GL_EXT_texture_storage */ +#ifndef GL_EXT_texture_storage +#define GL_TEXTURE_IMMUTABLE_FORMAT_EXT 0x912F +#define GL_ALPHA8_EXT 0x803C +#define GL_LUMINANCE8_EXT 0x8040 +#define GL_LUMINANCE8_ALPHA8_EXT 0x8045 +#define GL_RGBA32F_EXT 0x8814 +#define GL_RGB32F_EXT 0x8815 +#define GL_ALPHA32F_EXT 0x8816 +#define GL_LUMINANCE32F_EXT 0x8818 +#define GL_LUMINANCE_ALPHA32F_EXT 0x8819 +/* reuse GL_RGBA16F_EXT */ +#define GL_RGB16F_EXT 0x881B +#define GL_ALPHA16F_EXT 0x881C +#define GL_LUMINANCE16F_EXT 0x881E +#define GL_LUMINANCE_ALPHA16F_EXT 0x881F +#define GL_RGB10_A2_EXT 0x8059 +#define GL_RGB10_EXT 0x8052 +#define GL_BGRA8_EXT 0x93A1 +#endif + +/*------------------------------------------------------------------------* + * IMG extension tokens + *------------------------------------------------------------------------*/ + +/* GL_IMG_read_format */ +#ifndef GL_IMG_read_format +#define GL_BGRA_IMG 0x80E1 +#define GL_UNSIGNED_SHORT_4_4_4_4_REV_IMG 0x8365 +#endif + +/* GL_IMG_texture_compression_pvrtc */ +#ifndef GL_IMG_texture_compression_pvrtc +#define GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG 0x8C00 +#define GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG 0x8C01 +#define GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG 0x8C02 +#define GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG 0x8C03 +#endif + +/* GL_IMG_texture_env_enhanced_fixed_function */ +#ifndef GL_IMG_texture_env_enhanced_fixed_function +#define GL_MODULATE_COLOR_IMG 0x8C04 +#define GL_RECIP_ADD_SIGNED_ALPHA_IMG 0x8C05 +#define GL_TEXTURE_ALPHA_MODULATE_IMG 0x8C06 +#define GL_FACTOR_ALPHA_MODULATE_IMG 0x8C07 +#define GL_FRAGMENT_ALPHA_MODULATE_IMG 0x8C08 +#define GL_ADD_BLEND_IMG 0x8C09 +#define GL_DOT3_RGBA_IMG 0x86AF +#endif + +/* GL_IMG_user_clip_plane */ +#ifndef GL_IMG_user_clip_plane +#define GL_CLIP_PLANE0_IMG 0x3000 +#define GL_CLIP_PLANE1_IMG 0x3001 +#define GL_CLIP_PLANE2_IMG 0x3002 +#define GL_CLIP_PLANE3_IMG 0x3003 +#define GL_CLIP_PLANE4_IMG 0x3004 +#define GL_CLIP_PLANE5_IMG 0x3005 +#define GL_MAX_CLIP_PLANES_IMG 0x0D32 +#endif + +/* GL_IMG_multisampled_render_to_texture */ +#ifndef GL_IMG_multisampled_render_to_texture +#define GL_RENDERBUFFER_SAMPLES_IMG 0x9133 +#define GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_IMG 0x9134 +#define GL_MAX_SAMPLES_IMG 0x9135 +#define GL_TEXTURE_SAMPLES_IMG 0x9136 +#endif + +/*------------------------------------------------------------------------* + * NV extension tokens + *------------------------------------------------------------------------*/ + +/* GL_NV_fence */ +#ifndef GL_NV_fence +#define GL_ALL_COMPLETED_NV 0x84F2 +#define GL_FENCE_STATUS_NV 0x84F3 +#define GL_FENCE_CONDITION_NV 0x84F4 +#endif + +/*------------------------------------------------------------------------* + * QCOM extension tokens + *------------------------------------------------------------------------*/ + +/* GL_QCOM_driver_control */ +/* No new tokens introduced by this extension. */ + +/* GL_QCOM_extended_get */ +#ifndef GL_QCOM_extended_get +#define GL_TEXTURE_WIDTH_QCOM 0x8BD2 +#define GL_TEXTURE_HEIGHT_QCOM 0x8BD3 +#define GL_TEXTURE_DEPTH_QCOM 0x8BD4 +#define GL_TEXTURE_INTERNAL_FORMAT_QCOM 0x8BD5 +#define GL_TEXTURE_FORMAT_QCOM 0x8BD6 +#define GL_TEXTURE_TYPE_QCOM 0x8BD7 +#define GL_TEXTURE_IMAGE_VALID_QCOM 0x8BD8 +#define GL_TEXTURE_NUM_LEVELS_QCOM 0x8BD9 +#define GL_TEXTURE_TARGET_QCOM 0x8BDA +#define GL_TEXTURE_OBJECT_VALID_QCOM 0x8BDB +#define GL_STATE_RESTORE 0x8BDC +#endif + +/* GL_QCOM_extended_get2 */ +/* No new tokens introduced by this extension. */ + +/* GL_QCOM_perfmon_global_mode */ +#ifndef GL_QCOM_perfmon_global_mode +#define GL_PERFMON_GLOBAL_MODE_QCOM 0x8FA0 +#endif + +/* GL_QCOM_writeonly_rendering */ +#ifndef GL_QCOM_writeonly_rendering +#define GL_WRITEONLY_RENDERING_QCOM 0x8823 +#endif + +/* GL_QCOM_tiled_rendering */ +#ifndef GL_QCOM_tiled_rendering +#define GL_COLOR_BUFFER_BIT0_QCOM 0x00000001 +#define GL_COLOR_BUFFER_BIT1_QCOM 0x00000002 +#define GL_COLOR_BUFFER_BIT2_QCOM 0x00000004 +#define GL_COLOR_BUFFER_BIT3_QCOM 0x00000008 +#define GL_COLOR_BUFFER_BIT4_QCOM 0x00000010 +#define GL_COLOR_BUFFER_BIT5_QCOM 0x00000020 +#define GL_COLOR_BUFFER_BIT6_QCOM 0x00000040 +#define GL_COLOR_BUFFER_BIT7_QCOM 0x00000080 +#define GL_DEPTH_BUFFER_BIT0_QCOM 0x00000100 +#define GL_DEPTH_BUFFER_BIT1_QCOM 0x00000200 +#define GL_DEPTH_BUFFER_BIT2_QCOM 0x00000400 +#define GL_DEPTH_BUFFER_BIT3_QCOM 0x00000800 +#define GL_DEPTH_BUFFER_BIT4_QCOM 0x00001000 +#define GL_DEPTH_BUFFER_BIT5_QCOM 0x00002000 +#define GL_DEPTH_BUFFER_BIT6_QCOM 0x00004000 +#define GL_DEPTH_BUFFER_BIT7_QCOM 0x00008000 +#define GL_STENCIL_BUFFER_BIT0_QCOM 0x00010000 +#define GL_STENCIL_BUFFER_BIT1_QCOM 0x00020000 +#define GL_STENCIL_BUFFER_BIT2_QCOM 0x00040000 +#define GL_STENCIL_BUFFER_BIT3_QCOM 0x00080000 +#define GL_STENCIL_BUFFER_BIT4_QCOM 0x00100000 +#define GL_STENCIL_BUFFER_BIT5_QCOM 0x00200000 +#define GL_STENCIL_BUFFER_BIT6_QCOM 0x00400000 +#define GL_STENCIL_BUFFER_BIT7_QCOM 0x00800000 +#define GL_MULTISAMPLE_BUFFER_BIT0_QCOM 0x01000000 +#define GL_MULTISAMPLE_BUFFER_BIT1_QCOM 0x02000000 +#define GL_MULTISAMPLE_BUFFER_BIT2_QCOM 0x04000000 +#define GL_MULTISAMPLE_BUFFER_BIT3_QCOM 0x08000000 +#define GL_MULTISAMPLE_BUFFER_BIT4_QCOM 0x10000000 +#define GL_MULTISAMPLE_BUFFER_BIT5_QCOM 0x20000000 +#define GL_MULTISAMPLE_BUFFER_BIT6_QCOM 0x40000000 +#define GL_MULTISAMPLE_BUFFER_BIT7_QCOM 0x80000000 +#endif + +/*------------------------------------------------------------------------* + * End of extension tokens, start of corresponding extension functions + *------------------------------------------------------------------------*/ + +/*------------------------------------------------------------------------* + * OES extension functions + *------------------------------------------------------------------------*/ + +/* GL_OES_blend_equation_separate */ +#ifndef GL_OES_blend_equation_separate +#define GL_OES_blend_equation_separate 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_API void GL_APIENTRY glBlendEquationSeparateOES (GLenum modeRGB, GLenum modeAlpha); +#endif +typedef void (GL_APIENTRYP PFNGLBLENDEQUATIONSEPARATEOESPROC) (GLenum modeRGB, GLenum modeAlpha); +#endif + +/* GL_OES_blend_func_separate */ +#ifndef GL_OES_blend_func_separate +#define GL_OES_blend_func_separate 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_API void GL_APIENTRY glBlendFuncSeparateOES (GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha); +#endif +typedef void (GL_APIENTRYP PFNGLBLENDFUNCSEPARATEOESPROC) (GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha); +#endif + +/* GL_OES_blend_subtract */ +#ifndef GL_OES_blend_subtract +#define GL_OES_blend_subtract 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_API void GL_APIENTRY glBlendEquationOES (GLenum mode); +#endif +typedef void (GL_APIENTRYP PFNGLBLENDEQUATIONOESPROC) (GLenum mode); +#endif + +/* GL_OES_byte_coordinates */ +#ifndef GL_OES_byte_coordinates +#define GL_OES_byte_coordinates 1 +#endif + +/* GL_OES_compressed_ETC1_RGB8_texture */ +#ifndef GL_OES_compressed_ETC1_RGB8_texture +#define GL_OES_compressed_ETC1_RGB8_texture 1 +#endif + +/* GL_OES_depth24 */ +#ifndef GL_OES_depth24 +#define GL_OES_depth24 1 +#endif + +/* GL_OES_depth32 */ +#ifndef GL_OES_depth32 +#define GL_OES_depth32 1 +#endif + +/* GL_OES_draw_texture */ +#ifndef GL_OES_draw_texture +#define GL_OES_draw_texture 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_API void GL_APIENTRY glDrawTexsOES (GLshort x, GLshort y, GLshort z, GLshort width, GLshort height); +GL_API void GL_APIENTRY glDrawTexiOES (GLint x, GLint y, GLint z, GLint width, GLint height); +GL_API void GL_APIENTRY glDrawTexxOES (GLfixed x, GLfixed y, GLfixed z, GLfixed width, GLfixed height); +GL_API void GL_APIENTRY glDrawTexsvOES (const GLshort *coords); +GL_API void GL_APIENTRY glDrawTexivOES (const GLint *coords); +GL_API void GL_APIENTRY glDrawTexxvOES (const GLfixed *coords); +GL_API void GL_APIENTRY glDrawTexfOES (GLfloat x, GLfloat y, GLfloat z, GLfloat width, GLfloat height); +GL_API void GL_APIENTRY glDrawTexfvOES (const GLfloat *coords); +#endif +typedef void (GL_APIENTRYP PFNGLDRAWTEXSOESPROC) (GLshort x, GLshort y, GLshort z, GLshort width, GLshort height); +typedef void (GL_APIENTRYP PFNGLDRAWTEXIOESPROC) (GLint x, GLint y, GLint z, GLint width, GLint height); +typedef void (GL_APIENTRYP PFNGLDRAWTEXXOESPROC) (GLfixed x, GLfixed y, GLfixed z, GLfixed width, GLfixed height); +typedef void (GL_APIENTRYP PFNGLDRAWTEXSVOESPROC) (const GLshort *coords); +typedef void (GL_APIENTRYP PFNGLDRAWTEXIVOESPROC) (const GLint *coords); +typedef void (GL_APIENTRYP PFNGLDRAWTEXXVOESPROC) (const GLfixed *coords); +typedef void (GL_APIENTRYP PFNGLDRAWTEXFOESPROC) (GLfloat x, GLfloat y, GLfloat z, GLfloat width, GLfloat height); +typedef void (GL_APIENTRYP PFNGLDRAWTEXFVOESPROC) (const GLfloat *coords); +#endif + +/* GL_OES_EGL_image */ +#ifndef GL_OES_EGL_image +#define GL_OES_EGL_image 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_API void GL_APIENTRY glEGLImageTargetTexture2DOES (GLenum target, GLeglImageOES image); +GL_API void GL_APIENTRY glEGLImageTargetRenderbufferStorageOES (GLenum target, GLeglImageOES image); +#endif +typedef void (GL_APIENTRYP PFNGLEGLIMAGETARGETTEXTURE2DOESPROC) (GLenum target, GLeglImageOES image); +typedef void (GL_APIENTRYP PFNGLEGLIMAGETARGETRENDERBUFFERSTORAGEOESPROC) (GLenum target, GLeglImageOES image); +#endif + +/* GL_OES_EGL_image_external */ +#ifndef GL_OES_EGL_image_external +#define GL_OES_EGL_image_external 1 +/* glEGLImageTargetTexture2DOES defined in GL_OES_EGL_image already. */ +#endif + +/* GL_OES_element_index_uint */ +#ifndef GL_OES_element_index_uint +#define GL_OES_element_index_uint 1 +#endif + +/* GL_OES_extended_matrix_palette */ +#ifndef GL_OES_extended_matrix_palette +#define GL_OES_extended_matrix_palette 1 +#endif + +/* GL_OES_fbo_render_mipmap */ +#ifndef GL_OES_fbo_render_mipmap +#define GL_OES_fbo_render_mipmap 1 +#endif + +/* GL_OES_fixed_point */ +#ifndef GL_OES_fixed_point +#define GL_OES_fixed_point 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_API void GL_APIENTRY glAlphaFuncxOES (GLenum func, GLclampx ref); +GL_API void GL_APIENTRY glClearColorxOES (GLclampx red, GLclampx green, GLclampx blue, GLclampx alpha); +GL_API void GL_APIENTRY glClearDepthxOES (GLclampx depth); +GL_API void GL_APIENTRY glClipPlanexOES (GLenum plane, const GLfixed *equation); +GL_API void GL_APIENTRY glColor4xOES (GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha); +GL_API void GL_APIENTRY glDepthRangexOES (GLclampx zNear, GLclampx zFar); +GL_API void GL_APIENTRY glFogxOES (GLenum pname, GLfixed param); +GL_API void GL_APIENTRY glFogxvOES (GLenum pname, const GLfixed *params); +GL_API void GL_APIENTRY glFrustumxOES (GLfixed left, GLfixed right, GLfixed bottom, GLfixed top, GLfixed zNear, GLfixed zFar); +GL_API void GL_APIENTRY glGetClipPlanexOES (GLenum pname, GLfixed eqn[4]); +GL_API void GL_APIENTRY glGetFixedvOES (GLenum pname, GLfixed *params); +GL_API void GL_APIENTRY glGetLightxvOES (GLenum light, GLenum pname, GLfixed *params); +GL_API void GL_APIENTRY glGetMaterialxvOES (GLenum face, GLenum pname, GLfixed *params); +GL_API void GL_APIENTRY glGetTexEnvxvOES (GLenum env, GLenum pname, GLfixed *params); +GL_API void GL_APIENTRY glGetTexParameterxvOES (GLenum target, GLenum pname, GLfixed *params); +GL_API void GL_APIENTRY glLightModelxOES (GLenum pname, GLfixed param); +GL_API void GL_APIENTRY glLightModelxvOES (GLenum pname, const GLfixed *params); +GL_API void GL_APIENTRY glLightxOES (GLenum light, GLenum pname, GLfixed param); +GL_API void GL_APIENTRY glLightxvOES (GLenum light, GLenum pname, const GLfixed *params); +GL_API void GL_APIENTRY glLineWidthxOES (GLfixed width); +GL_API void GL_APIENTRY glLoadMatrixxOES (const GLfixed *m); +GL_API void GL_APIENTRY glMaterialxOES (GLenum face, GLenum pname, GLfixed param); +GL_API void GL_APIENTRY glMaterialxvOES (GLenum face, GLenum pname, const GLfixed *params); +GL_API void GL_APIENTRY glMultMatrixxOES (const GLfixed *m); +GL_API void GL_APIENTRY glMultiTexCoord4xOES (GLenum target, GLfixed s, GLfixed t, GLfixed r, GLfixed q); +GL_API void GL_APIENTRY glNormal3xOES (GLfixed nx, GLfixed ny, GLfixed nz); +GL_API void GL_APIENTRY glOrthoxOES (GLfixed left, GLfixed right, GLfixed bottom, GLfixed top, GLfixed zNear, GLfixed zFar); +GL_API void GL_APIENTRY glPointParameterxOES (GLenum pname, GLfixed param); +GL_API void GL_APIENTRY glPointParameterxvOES (GLenum pname, const GLfixed *params); +GL_API void GL_APIENTRY glPointSizexOES (GLfixed size); +GL_API void GL_APIENTRY glPolygonOffsetxOES (GLfixed factor, GLfixed units); +GL_API void GL_APIENTRY glRotatexOES (GLfixed angle, GLfixed x, GLfixed y, GLfixed z); +GL_API void GL_APIENTRY glSampleCoveragexOES (GLclampx value, GLboolean invert); +GL_API void GL_APIENTRY glScalexOES (GLfixed x, GLfixed y, GLfixed z); +GL_API void GL_APIENTRY glTexEnvxOES (GLenum target, GLenum pname, GLfixed param); +GL_API void GL_APIENTRY glTexEnvxvOES (GLenum target, GLenum pname, const GLfixed *params); +GL_API void GL_APIENTRY glTexParameterxOES (GLenum target, GLenum pname, GLfixed param); +GL_API void GL_APIENTRY glTexParameterxvOES (GLenum target, GLenum pname, const GLfixed *params); +GL_API void GL_APIENTRY glTranslatexOES (GLfixed x, GLfixed y, GLfixed z); +#endif +typedef void (GL_APIENTRYP PFNGLALPHAFUNCXOESPROC) (GLenum func, GLclampx ref); +typedef void (GL_APIENTRYP PFNGLCLEARCOLORXOESPROC) (GLclampx red, GLclampx green, GLclampx blue, GLclampx alpha); +typedef void (GL_APIENTRYP PFNGLCLEARDEPTHXOESPROC) (GLclampx depth); +typedef void (GL_APIENTRYP PFNGLCLIPPLANEXOESPROC) (GLenum plane, const GLfixed *equation); +typedef void (GL_APIENTRYP PFNGLCOLOR4XOESPROC) (GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha); +typedef void (GL_APIENTRYP PFNGLDEPTHRANGEXOESPROC) (GLclampx zNear, GLclampx zFar); +typedef void (GL_APIENTRYP PFNGLFOGXOESPROC) (GLenum pname, GLfixed param); +typedef void (GL_APIENTRYP PFNGLFOGXVOESPROC) (GLenum pname, const GLfixed *params); +typedef void (GL_APIENTRYP PFNGLFRUSTUMXOESPROC) (GLfixed left, GLfixed right, GLfixed bottom, GLfixed top, GLfixed zNear, GLfixed zFar); +typedef void (GL_APIENTRYP PFNGLGETCLIPPLANEXOESPROC) (GLenum pname, GLfixed eqn[4]); +typedef void (GL_APIENTRYP PFNGLGETFIXEDVOESPROC) (GLenum pname, GLfixed *params); +typedef void (GL_APIENTRYP PFNGLGETLIGHTXVOESPROC) (GLenum light, GLenum pname, GLfixed *params); +typedef void (GL_APIENTRYP PFNGLGETMATERIALXVOESPROC) (GLenum face, GLenum pname, GLfixed *params); +typedef void (GL_APIENTRYP PFNGLGETTEXENVXVOESPROC) (GLenum env, GLenum pname, GLfixed *params); +typedef void (GL_APIENTRYP PFNGLGETTEXPARAMETERXVOESPROC) (GLenum target, GLenum pname, GLfixed *params); +typedef void (GL_APIENTRYP PFNGLLIGHTMODELXOESPROC) (GLenum pname, GLfixed param); +typedef void (GL_APIENTRYP PFNGLLIGHTMODELXVOESPROC) (GLenum pname, const GLfixed *params); +typedef void (GL_APIENTRYP PFNGLLIGHTXOESPROC) (GLenum light, GLenum pname, GLfixed param); +typedef void (GL_APIENTRYP PFNGLLIGHTXVOESPROC) (GLenum light, GLenum pname, const GLfixed *params); +typedef void (GL_APIENTRYP PFNGLLINEWIDTHXOESPROC) (GLfixed width); +typedef void (GL_APIENTRYP PFNGLLOADMATRIXXOESPROC) (const GLfixed *m); +typedef void (GL_APIENTRYP PFNGLMATERIALXOESPROC) (GLenum face, GLenum pname, GLfixed param); +typedef void (GL_APIENTRYP PFNGLMATERIALXVOESPROC) (GLenum face, GLenum pname, const GLfixed *params); +typedef void (GL_APIENTRYP PFNGLMULTMATRIXXOESPROC) (const GLfixed *m); +typedef void (GL_APIENTRYP PFNGLMULTITEXCOORD4XOESPROC) (GLenum target, GLfixed s, GLfixed t, GLfixed r, GLfixed q); +typedef void (GL_APIENTRYP PFNGLNORMAL3XOESPROC) (GLfixed nx, GLfixed ny, GLfixed nz); +typedef void (GL_APIENTRYP PFNGLORTHOXOESPROC) (GLfixed left, GLfixed right, GLfixed bottom, GLfixed top, GLfixed zNear, GLfixed zFar); +typedef void (GL_APIENTRYP PFNGLPOINTPARAMETERXOESPROC) (GLenum pname, GLfixed param); +typedef void (GL_APIENTRYP PFNGLPOINTPARAMETERXVOESPROC) (GLenum pname, const GLfixed *params); +typedef void (GL_APIENTRYP PFNGLPOINTSIZEXOESPROC) (GLfixed size); +typedef void (GL_APIENTRYP PFNGLPOLYGONOFFSETXOESPROC) (GLfixed factor, GLfixed units); +typedef void (GL_APIENTRYP PFNGLROTATEXOESPROC) (GLfixed angle, GLfixed x, GLfixed y, GLfixed z); +typedef void (GL_APIENTRYP PFNGLSAMPLECOVERAGEXOESPROC) (GLclampx value, GLboolean invert); +typedef void (GL_APIENTRYP PFNGLSCALEXOESPROC) (GLfixed x, GLfixed y, GLfixed z); +typedef void (GL_APIENTRYP PFNGLTEXENVXOESPROC) (GLenum target, GLenum pname, GLfixed param); +typedef void (GL_APIENTRYP PFNGLTEXENVXVOESPROC) (GLenum target, GLenum pname, const GLfixed *params); +typedef void (GL_APIENTRYP PFNGLTEXPARAMETERXOESPROC) (GLenum target, GLenum pname, GLfixed param); +typedef void (GL_APIENTRYP PFNGLTEXPARAMETERXVOESPROC) (GLenum target, GLenum pname, const GLfixed *params); +typedef void (GL_APIENTRYP PFNGLTRANSLATEXOESPROC) (GLfixed x, GLfixed y, GLfixed z); +#endif + +/* GL_OES_framebuffer_object */ +#ifndef GL_OES_framebuffer_object +#define GL_OES_framebuffer_object 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_API GLboolean GL_APIENTRY glIsRenderbufferOES (GLuint renderbuffer); +GL_API void GL_APIENTRY glBindRenderbufferOES (GLenum target, GLuint renderbuffer); +GL_API void GL_APIENTRY glDeleteRenderbuffersOES (GLsizei n, const GLuint* renderbuffers); +GL_API void GL_APIENTRY glGenRenderbuffersOES (GLsizei n, GLuint* renderbuffers); +GL_API void GL_APIENTRY glRenderbufferStorageOES (GLenum target, GLenum internalformat, GLsizei width, GLsizei height); +GL_API void GL_APIENTRY glGetRenderbufferParameterivOES (GLenum target, GLenum pname, GLint* params); +GL_API GLboolean GL_APIENTRY glIsFramebufferOES (GLuint framebuffer); +GL_API void GL_APIENTRY glBindFramebufferOES (GLenum target, GLuint framebuffer); +GL_API void GL_APIENTRY glDeleteFramebuffersOES (GLsizei n, const GLuint* framebuffers); +GL_API void GL_APIENTRY glGenFramebuffersOES (GLsizei n, GLuint* framebuffers); +GL_API GLenum GL_APIENTRY glCheckFramebufferStatusOES (GLenum target); +GL_API void GL_APIENTRY glFramebufferRenderbufferOES (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer); +GL_API void GL_APIENTRY glFramebufferTexture2DOES (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); +GL_API void GL_APIENTRY glGetFramebufferAttachmentParameterivOES (GLenum target, GLenum attachment, GLenum pname, GLint* params); +GL_API void GL_APIENTRY glGenerateMipmapOES (GLenum target); +#endif +typedef GLboolean (GL_APIENTRYP PFNGLISRENDERBUFFEROESPROC) (GLuint renderbuffer); +typedef void (GL_APIENTRYP PFNGLBINDRENDERBUFFEROESPROC) (GLenum target, GLuint renderbuffer); +typedef void (GL_APIENTRYP PFNGLDELETERENDERBUFFERSOESPROC) (GLsizei n, const GLuint* renderbuffers); +typedef void (GL_APIENTRYP PFNGLGENRENDERBUFFERSOESPROC) (GLsizei n, GLuint* renderbuffers); +typedef void (GL_APIENTRYP PFNGLRENDERBUFFERSTORAGEOESPROC) (GLenum target, GLenum internalformat, GLsizei width, GLsizei height); +typedef void (GL_APIENTRYP PFNGLGETRENDERBUFFERPARAMETERIVOESPROC) (GLenum target, GLenum pname, GLint* params); +typedef GLboolean (GL_APIENTRYP PFNGLISFRAMEBUFFEROESPROC) (GLuint framebuffer); +typedef void (GL_APIENTRYP PFNGLBINDFRAMEBUFFEROESPROC) (GLenum target, GLuint framebuffer); +typedef void (GL_APIENTRYP PFNGLDELETEFRAMEBUFFERSOESPROC) (GLsizei n, const GLuint* framebuffers); +typedef void (GL_APIENTRYP PFNGLGENFRAMEBUFFERSOESPROC) (GLsizei n, GLuint* framebuffers); +typedef GLenum (GL_APIENTRYP PFNGLCHECKFRAMEBUFFERSTATUSOESPROC) (GLenum target); +typedef void (GL_APIENTRYP PFNGLFRAMEBUFFERRENDERBUFFEROESPROC) (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer); +typedef void (GL_APIENTRYP PFNGLFRAMEBUFFERTEXTURE2DOESPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); +typedef void (GL_APIENTRYP PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVOESPROC) (GLenum target, GLenum attachment, GLenum pname, GLint* params); +typedef void (GL_APIENTRYP PFNGLGENERATEMIPMAPOESPROC) (GLenum target); +#endif + +/* GL_OES_mapbuffer */ +#ifndef GL_OES_mapbuffer +#define GL_OES_mapbuffer 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_API void* GL_APIENTRY glMapBufferOES (GLenum target, GLenum access); +GL_API GLboolean GL_APIENTRY glUnmapBufferOES (GLenum target); +GL_API void GL_APIENTRY glGetBufferPointervOES (GLenum target, GLenum pname, GLvoid ** params); +#endif +typedef void* (GL_APIENTRYP PFNGLMAPBUFFEROESPROC) (GLenum target, GLenum access); +typedef GLboolean (GL_APIENTRYP PFNGLUNMAPBUFFEROESPROC) (GLenum target); +typedef void (GL_APIENTRYP PFNGLGETBUFFERPOINTERVOESPROC) (GLenum target, GLenum pname, GLvoid ** params); +#endif + +/* GL_OES_matrix_get */ +#ifndef GL_OES_matrix_get +#define GL_OES_matrix_get 1 +#endif + +/* GL_OES_matrix_palette */ +#ifndef GL_OES_matrix_palette +#define GL_OES_matrix_palette 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_API void GL_APIENTRY glCurrentPaletteMatrixOES (GLuint matrixpaletteindex); +GL_API void GL_APIENTRY glLoadPaletteFromModelViewMatrixOES (void); +GL_API void GL_APIENTRY glMatrixIndexPointerOES (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +GL_API void GL_APIENTRY glWeightPointerOES (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +#endif +typedef void (GL_APIENTRYP PFNGLCURRENTPALETTEMATRIXOESPROC) (GLuint matrixpaletteindex); +typedef void (GL_APIENTRYP PFNGLLOADPALETTEFROMMODELVIEWMATRIXOESPROC) (void); +typedef void (GL_APIENTRYP PFNGLMATRIXINDEXPOINTEROESPROC) (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +typedef void (GL_APIENTRYP PFNGLWEIGHTPOINTEROESPROC) (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +#endif + +/* GL_OES_packed_depth_stencil */ +#ifndef GL_OES_packed_depth_stencil +#define GL_OES_packed_depth_stencil 1 +#endif + +/* GL_OES_required_internalformat */ +#ifndef GL_OES_required_internalformat +#define GL_OES_required_internalformat 1 +#endif + +/* GL_OES_query_matrix */ +#ifndef GL_OES_query_matrix +#define GL_OES_query_matrix 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_API GLbitfield GL_APIENTRY glQueryMatrixxOES (GLfixed mantissa[16], GLint exponent[16]); +#endif +typedef GLbitfield (GL_APIENTRYP PFNGLQUERYMATRIXXOESPROC) (GLfixed mantissa[16], GLint exponent[16]); +#endif + +/* GL_OES_rgb8_rgba8 */ +#ifndef GL_OES_rgb8_rgba8 +#define GL_OES_rgb8_rgba8 1 +#endif + +/* GL_OES_single_precision */ +#ifndef GL_OES_single_precision +#define GL_OES_single_precision 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_API void GL_APIENTRY glDepthRangefOES (GLclampf zNear, GLclampf zFar); +GL_API void GL_APIENTRY glFrustumfOES (GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar); +GL_API void GL_APIENTRY glOrthofOES (GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar); +GL_API void GL_APIENTRY glClipPlanefOES (GLenum plane, const GLfloat *equation); +GL_API void GL_APIENTRY glGetClipPlanefOES (GLenum pname, GLfloat eqn[4]); +GL_API void GL_APIENTRY glClearDepthfOES (GLclampf depth); +#endif +typedef void (GL_APIENTRYP PFNGLDEPTHRANGEFOESPROC) (GLclampf zNear, GLclampf zFar); +typedef void (GL_APIENTRYP PFNGLFRUSTUMFOESPROC) (GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar); +typedef void (GL_APIENTRYP PFNGLORTHOFOESPROC) (GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar); +typedef void (GL_APIENTRYP PFNGLCLIPPLANEFOESPROC) (GLenum plane, const GLfloat *equation); +typedef void (GL_APIENTRYP PFNGLGETCLIPPLANEFOESPROC) (GLenum pname, GLfloat eqn[4]); +typedef void (GL_APIENTRYP PFNGLCLEARDEPTHFOESPROC) (GLclampf depth); +#endif + +/* GL_OES_stencil1 */ +#ifndef GL_OES_stencil1 +#define GL_OES_stencil1 1 +#endif + +/* GL_OES_stencil4 */ +#ifndef GL_OES_stencil4 +#define GL_OES_stencil4 1 +#endif + +/* GL_OES_stencil8 */ +#ifndef GL_OES_stencil8 +#define GL_OES_stencil8 1 +#endif + +/* GL_OES_stencil_wrap */ +#ifndef GL_OES_stencil_wrap +#define GL_OES_stencil_wrap 1 +#endif + +/* GL_OES_texture_cube_map */ +#ifndef GL_OES_texture_cube_map +#define GL_OES_texture_cube_map 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_API void GL_APIENTRY glTexGenfOES (GLenum coord, GLenum pname, GLfloat param); +GL_API void GL_APIENTRY glTexGenfvOES (GLenum coord, GLenum pname, const GLfloat *params); +GL_API void GL_APIENTRY glTexGeniOES (GLenum coord, GLenum pname, GLint param); +GL_API void GL_APIENTRY glTexGenivOES (GLenum coord, GLenum pname, const GLint *params); +GL_API void GL_APIENTRY glTexGenxOES (GLenum coord, GLenum pname, GLfixed param); +GL_API void GL_APIENTRY glTexGenxvOES (GLenum coord, GLenum pname, const GLfixed *params); +GL_API void GL_APIENTRY glGetTexGenfvOES (GLenum coord, GLenum pname, GLfloat *params); +GL_API void GL_APIENTRY glGetTexGenivOES (GLenum coord, GLenum pname, GLint *params); +GL_API void GL_APIENTRY glGetTexGenxvOES (GLenum coord, GLenum pname, GLfixed *params); +#endif +typedef void (GL_APIENTRYP PFNGLTEXGENFOESPROC) (GLenum coord, GLenum pname, GLfloat param); +typedef void (GL_APIENTRYP PFNGLTEXGENFVOESPROC) (GLenum coord, GLenum pname, const GLfloat *params); +typedef void (GL_APIENTRYP PFNGLTEXGENIOESPROC) (GLenum coord, GLenum pname, GLint param); +typedef void (GL_APIENTRYP PFNGLTEXGENIVOESPROC) (GLenum coord, GLenum pname, const GLint *params); +typedef void (GL_APIENTRYP PFNGLTEXGENXOESPROC) (GLenum coord, GLenum pname, GLfixed param); +typedef void (GL_APIENTRYP PFNGLTEXGENXVOESPROC) (GLenum coord, GLenum pname, const GLfixed *params); +typedef void (GL_APIENTRYP PFNGLGETTEXGENFVOESPROC) (GLenum coord, GLenum pname, GLfloat *params); +typedef void (GL_APIENTRYP PFNGLGETTEXGENIVOESPROC) (GLenum coord, GLenum pname, GLint *params); +typedef void (GL_APIENTRYP PFNGLGETTEXGENXVOESPROC) (GLenum coord, GLenum pname, GLfixed *params); +#endif + +/* GL_OES_texture_env_crossbar */ +#ifndef GL_OES_texture_env_crossbar +#define GL_OES_texture_env_crossbar 1 +#endif + +/* GL_OES_texture_mirrored_repeat */ +#ifndef GL_OES_texture_mirrored_repeat +#define GL_OES_texture_mirrored_repeat 1 +#endif + +/* GL_OES_vertex_array_object */ +#ifndef GL_OES_vertex_array_object +#define GL_OES_vertex_array_object 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_API void GL_APIENTRY glBindVertexArrayOES (GLuint array); +GL_API void GL_APIENTRY glDeleteVertexArraysOES (GLsizei n, const GLuint *arrays); +GL_API void GL_APIENTRY glGenVertexArraysOES (GLsizei n, GLuint *arrays); +GL_API GLboolean GL_APIENTRY glIsVertexArrayOES (GLuint array); +#endif +typedef void (GL_APIENTRYP PFNGLBINDVERTEXARRAYOESPROC) (GLuint array); +typedef void (GL_APIENTRYP PFNGLDELETEVERTEXARRAYSOESPROC) (GLsizei n, const GLuint *arrays); +typedef void (GL_APIENTRYP PFNGLGENVERTEXARRAYSOESPROC) (GLsizei n, GLuint *arrays); +typedef GLboolean (GL_APIENTRYP PFNGLISVERTEXARRAYOESPROC) (GLuint array); +#endif + +/*------------------------------------------------------------------------* + * AMD extension functions + *------------------------------------------------------------------------*/ + +/* GL_AMD_compressed_3DC_texture */ +#ifndef GL_AMD_compressed_3DC_texture +#define GL_AMD_compressed_3DC_texture 1 +#endif + +/* GL_AMD_compressed_ATC_texture */ +#ifndef GL_AMD_compressed_ATC_texture +#define GL_AMD_compressed_ATC_texture 1 +#endif + +/*------------------------------------------------------------------------* + * APPLE extension functions + *------------------------------------------------------------------------*/ + +/* GL_APPLE_copy_texture_levels */ +#ifndef GL_APPLE_copy_texture_levels +#define GL_APPLE_copy_texture_levels 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_API void GL_APIENTRY glCopyTextureLevelsAPPLE (GLuint destinationTexture, GLuint sourceTexture, GLint sourceBaseLevel, GLsizei sourceLevelCount); +#endif +typedef void (GL_APIENTRYP PFNGLCOPYTEXTURELEVELSAPPLEPROC) (GLuint destinationTexture, GLuint sourceTexture, GLint sourceBaseLevel, GLsizei sourceLevelCount); +#endif + +/* GL_APPLE_framebuffer_multisample */ +#ifndef GL_APPLE_framebuffer_multisample +#define GL_APPLE_framebuffer_multisample 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_API void GL_APIENTRY glRenderbufferStorageMultisampleAPPLE (GLenum, GLsizei, GLenum, GLsizei, GLsizei); +GL_API void GL_APIENTRY glResolveMultisampleFramebufferAPPLE (void); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (GL_APIENTRYP PFNGLRENDERBUFFERSTORAGEMULTISAMPLEAPPLEPROC) (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height); +typedef void (GL_APIENTRYP PFNGLRESOLVEMULTISAMPLEFRAMEBUFFERAPPLEPROC) (void); +#endif + +/* GL_APPLE_sync */ +#ifndef GL_APPLE_sync +#define GL_APPLE_sync 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_API GLsync GL_APIENTRY glFenceSyncAPPLE (GLenum condition, GLbitfield flags); +GL_API GLboolean GL_APIENTRY glIsSyncAPPLE (GLsync sync); +GL_API void GL_APIENTRY glDeleteSyncAPPLE (GLsync sync); +GL_API GLenum GL_APIENTRY glClientWaitSyncAPPLE (GLsync sync, GLbitfield flags, GLuint64 timeout); +GL_API void GL_APIENTRY glWaitSyncAPPLE (GLsync sync, GLbitfield flags, GLuint64 timeout); +GL_API void GL_APIENTRY glGetInteger64vAPPLE (GLenum pname, GLint64 *params); +GL_API void GL_APIENTRY glGetSyncivAPPLE (GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values); +#endif +typedef GLsync (GL_APIENTRYP PFNGLFENCESYNCAPPLEPROC) (GLenum condition, GLbitfield flags); +typedef GLboolean (GL_APIENTRYP PFNGLISSYNCAPPLEPROC) (GLsync sync); +typedef void (GL_APIENTRYP PFNGLDELETESYNCAPPLEPROC) (GLsync sync); +typedef GLenum (GL_APIENTRYP PFNGLCLIENTWAITSYNCAPPLEPROC) (GLsync sync, GLbitfield flags, GLuint64 timeout); +typedef void (GL_APIENTRYP PFNGLWAITSYNCAPPLEPROC) (GLsync sync, GLbitfield flags, GLuint64 timeout); +typedef void (GL_APIENTRYP PFNGLGETINTEGER64VAPPLEPROC) (GLenum pname, GLint64 *params); +typedef void (GL_APIENTRYP PFNGLGETSYNCIVAPPLEPROC) (GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values); +#endif + +/* GL_APPLE_texture_2D_limited_npot */ +#ifndef GL_APPLE_texture_2D_limited_npot +#define GL_APPLE_texture_2D_limited_npot 1 +#endif + +/* GL_APPLE_texture_format_BGRA8888 */ +#ifndef GL_APPLE_texture_format_BGRA8888 +#define GL_APPLE_texture_format_BGRA8888 1 +#endif + +/* GL_APPLE_texture_max_level */ +#ifndef GL_APPLE_texture_max_level +#define GL_APPLE_texture_max_level 1 +#endif + +/*------------------------------------------------------------------------* + * ARM extension functions + *------------------------------------------------------------------------*/ + +/* GL_ARM_rgba8 */ +#ifndef GL_ARM_rgba8 +#define GL_ARM_rgba8 1 +#endif + +/*------------------------------------------------------------------------* + * EXT extension functions + *------------------------------------------------------------------------*/ + +/* GL_EXT_blend_minmax */ +#ifndef GL_EXT_blend_minmax +#define GL_EXT_blend_minmax 1 +#endif + +/* GL_EXT_discard_framebuffer */ +#ifndef GL_EXT_discard_framebuffer +#define GL_EXT_discard_framebuffer 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_API void GL_APIENTRY glDiscardFramebufferEXT (GLenum target, GLsizei numAttachments, const GLenum *attachments); +#endif +typedef void (GL_APIENTRYP PFNGLDISCARDFRAMEBUFFEREXTPROC) (GLenum target, GLsizei numAttachments, const GLenum *attachments); +#endif + +/* GL_EXT_map_buffer_range */ +#ifndef GL_EXT_map_buffer_range +#define GL_EXT_map_buffer_range 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_API void GL_APIENTRY *glMapBufferRangeEXT (GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access); +GL_API void GL_APIENTRY glFlushMappedBufferRangeEXT (GLenum target, GLintptr offset, GLsizeiptr length); +#endif +typedef void* (GL_APIENTRYP PFNGLMAPBUFFERRANGEEXTPROC) (GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access); +typedef void (GL_APIENTRYP PFNGLFLUSHMAPPEDBUFFERRANGEEXTPROC) (GLenum target, GLintptr offset, GLsizeiptr length); +#endif + +/* GL_EXT_multisampled_render_to_texture */ +#ifndef GL_EXT_multisampled_render_to_texture +#define GL_EXT_multisampled_render_to_texture 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_API void GL_APIENTRY glRenderbufferStorageMultisampleEXT (GLenum, GLsizei, GLenum, GLsizei, GLsizei); +GL_API void GL_APIENTRY glFramebufferTexture2DMultisampleEXT (GLenum, GLenum, GLenum, GLuint, GLint, GLsizei); +#endif +typedef void (GL_APIENTRYP PFNGLRENDERBUFFERSTORAGEMULTISAMPLEEXTPROC) (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height); +typedef void (GL_APIENTRYP PFNGLFRAMEBUFFERTEXTURE2DMULTISAMPLEEXTPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLsizei samples); +#endif + +/* GL_EXT_multi_draw_arrays */ +#ifndef GL_EXT_multi_draw_arrays +#define GL_EXT_multi_draw_arrays 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_API void GL_APIENTRY glMultiDrawArraysEXT (GLenum, GLint *, GLsizei *, GLsizei); +GL_API void GL_APIENTRY glMultiDrawElementsEXT (GLenum, const GLsizei *, GLenum, const GLvoid* *, GLsizei); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (GL_APIENTRYP PFNGLMULTIDRAWARRAYSEXTPROC) (GLenum mode, GLint *first, GLsizei *count, GLsizei primcount); +typedef void (GL_APIENTRYP PFNGLMULTIDRAWELEMENTSEXTPROC) (GLenum mode, const GLsizei *count, GLenum type, const GLvoid* *indices, GLsizei primcount); +#endif + +/* GL_EXT_read_format_bgra */ +#ifndef GL_EXT_read_format_bgra +#define GL_EXT_read_format_bgra 1 +#endif + +/* GL_EXT_robustness */ +#ifndef GL_EXT_robustness +#define GL_EXT_robustness 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_API GLenum GL_APIENTRY glGetGraphicsResetStatusEXT (void); +GL_API void GL_APIENTRY glReadnPixelsEXT (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLsizei bufSize, void *data); +GL_API void GL_APIENTRY glGetnUniformfvEXT (GLuint program, GLint location, GLsizei bufSize, float *params); +GL_API void GL_APIENTRY glGetnUniformivEXT (GLuint program, GLint location, GLsizei bufSize, GLint *params); +#endif +typedef GLenum (GL_APIENTRYP PFNGLGETGRAPHICSRESETSTATUSEXTPROC) (void); +typedef void (GL_APIENTRYP PFNGLREADNPIXELSEXTPROC) (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLsizei bufSize, void *data); +typedef void (GL_APIENTRYP PFNGLGETNUNIFORMFVEXTPROC) (GLuint program, GLint location, GLsizei bufSize, float *params); +typedef void (GL_APIENTRYP PFNGLGETNUNIFORMIVEXTPROC) (GLuint program, GLint location, GLsizei bufSize, GLint *params); +#endif + +/* GL_EXT_sRGB */ +#ifndef GL_EXT_sRGB +#define GL_EXT_sRGB 1 +#endif + +/* GL_EXT_texture_compression_dxt1 */ +#ifndef GL_EXT_texture_compression_dxt1 +#define GL_EXT_texture_compression_dxt1 1 +#endif + +/* GL_EXT_texture_filter_anisotropic */ +#ifndef GL_EXT_texture_filter_anisotropic +#define GL_EXT_texture_filter_anisotropic 1 +#endif + +/* GL_EXT_texture_format_BGRA8888 */ +#ifndef GL_EXT_texture_format_BGRA8888 +#define GL_EXT_texture_format_BGRA8888 1 +#endif + +/* GL_EXT_texture_lod_bias */ +#ifndef GL_EXT_texture_lod_bias +#define GL_EXT_texture_lod_bias 1 +#endif + +/* GL_EXT_texture_storage */ +#ifndef GL_EXT_texture_storage +#define GL_EXT_texture_storage 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_API void GL_APIENTRY glTexStorage1DEXT (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width); +GL_API void GL_APIENTRY glTexStorage2DEXT (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height); +GL_API void GL_APIENTRY glTexStorage3DEXT (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth); +GL_API void GL_APIENTRY glTextureStorage1DEXT (GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width); +GL_API void GL_APIENTRY glTextureStorage2DEXT (GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height); +GL_API void GL_APIENTRY glTextureStorage3DEXT (GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth); +#endif +typedef void (GL_APIENTRYP PFNGLTEXSTORAGE1DEXTPROC) (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width); +typedef void (GL_APIENTRYP PFNGLTEXSTORAGE2DEXTPROC) (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height); +typedef void (GL_APIENTRYP PFNGLTEXSTORAGE3DEXTPROC) (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth); +typedef void (GL_APIENTRYP PFNGLTEXTURESTORAGE1DEXTPROC) (GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width); +typedef void (GL_APIENTRYP PFNGLTEXTURESTORAGE2DEXTPROC) (GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height); +typedef void (GL_APIENTRYP PFNGLTEXTURESTORAGE3DEXTPROC) (GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth); +#endif + +/*------------------------------------------------------------------------* + * IMG extension functions + *------------------------------------------------------------------------*/ + +/* GL_IMG_read_format */ +#ifndef GL_IMG_read_format +#define GL_IMG_read_format 1 +#endif + +/* GL_IMG_texture_compression_pvrtc */ +#ifndef GL_IMG_texture_compression_pvrtc +#define GL_IMG_texture_compression_pvrtc 1 +#endif + +/* GL_IMG_texture_env_enhanced_fixed_function */ +#ifndef GL_IMG_texture_env_enhanced_fixed_function +#define GL_IMG_texture_env_enhanced_fixed_function 1 +#endif + +/* GL_IMG_user_clip_plane */ +#ifndef GL_IMG_user_clip_plane +#define GL_IMG_user_clip_plane 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_API void GL_APIENTRY glClipPlanefIMG (GLenum, const GLfloat *); +GL_API void GL_APIENTRY glClipPlanexIMG (GLenum, const GLfixed *); +#endif +typedef void (GL_APIENTRYP PFNGLCLIPPLANEFIMGPROC) (GLenum p, const GLfloat *eqn); +typedef void (GL_APIENTRYP PFNGLCLIPPLANEXIMGPROC) (GLenum p, const GLfixed *eqn); +#endif + +/* GL_IMG_multisampled_render_to_texture */ +#ifndef GL_IMG_multisampled_render_to_texture +#define GL_IMG_multisampled_render_to_texture 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_API void GL_APIENTRY glRenderbufferStorageMultisampleIMG (GLenum, GLsizei, GLenum, GLsizei, GLsizei); +GL_API void GL_APIENTRY glFramebufferTexture2DMultisampleIMG (GLenum, GLenum, GLenum, GLuint, GLint, GLsizei); +#endif +typedef void (GL_APIENTRYP PFNGLRENDERBUFFERSTORAGEMULTISAMPLEIMGPROC) (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height); +typedef void (GL_APIENTRYP PFNGLFRAMEBUFFERTEXTURE2DMULTISAMPLEIMGPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLsizei samples); +#endif + +/*------------------------------------------------------------------------* + * NV extension functions + *------------------------------------------------------------------------*/ + +/* NV_fence */ +#ifndef GL_NV_fence +#define GL_NV_fence 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_API void GL_APIENTRY glDeleteFencesNV (GLsizei, const GLuint *); +GL_API void GL_APIENTRY glGenFencesNV (GLsizei, GLuint *); +GL_API GLboolean GL_APIENTRY glIsFenceNV (GLuint); +GL_API GLboolean GL_APIENTRY glTestFenceNV (GLuint); +GL_API void GL_APIENTRY glGetFenceivNV (GLuint, GLenum, GLint *); +GL_API void GL_APIENTRY glFinishFenceNV (GLuint); +GL_API void GL_APIENTRY glSetFenceNV (GLuint, GLenum); +#endif +typedef void (GL_APIENTRYP PFNGLDELETEFENCESNVPROC) (GLsizei n, const GLuint *fences); +typedef void (GL_APIENTRYP PFNGLGENFENCESNVPROC) (GLsizei n, GLuint *fences); +typedef GLboolean (GL_APIENTRYP PFNGLISFENCENVPROC) (GLuint fence); +typedef GLboolean (GL_APIENTRYP PFNGLTESTFENCENVPROC) (GLuint fence); +typedef void (GL_APIENTRYP PFNGLGETFENCEIVNVPROC) (GLuint fence, GLenum pname, GLint *params); +typedef void (GL_APIENTRYP PFNGLFINISHFENCENVPROC) (GLuint fence); +typedef void (GL_APIENTRYP PFNGLSETFENCENVPROC) (GLuint fence, GLenum condition); +#endif + +/*------------------------------------------------------------------------* + * QCOM extension functions + *------------------------------------------------------------------------*/ + +/* GL_QCOM_driver_control */ +#ifndef GL_QCOM_driver_control +#define GL_QCOM_driver_control 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_API void GL_APIENTRY glGetDriverControlsQCOM (GLint *num, GLsizei size, GLuint *driverControls); +GL_API void GL_APIENTRY glGetDriverControlStringQCOM (GLuint driverControl, GLsizei bufSize, GLsizei *length, GLchar *driverControlString); +GL_API void GL_APIENTRY glEnableDriverControlQCOM (GLuint driverControl); +GL_API void GL_APIENTRY glDisableDriverControlQCOM (GLuint driverControl); +#endif +typedef void (GL_APIENTRYP PFNGLGETDRIVERCONTROLSQCOMPROC) (GLint *num, GLsizei size, GLuint *driverControls); +typedef void (GL_APIENTRYP PFNGLGETDRIVERCONTROLSTRINGQCOMPROC) (GLuint driverControl, GLsizei bufSize, GLsizei *length, GLchar *driverControlString); +typedef void (GL_APIENTRYP PFNGLENABLEDRIVERCONTROLQCOMPROC) (GLuint driverControl); +typedef void (GL_APIENTRYP PFNGLDISABLEDRIVERCONTROLQCOMPROC) (GLuint driverControl); +#endif + +/* GL_QCOM_extended_get */ +#ifndef GL_QCOM_extended_get +#define GL_QCOM_extended_get 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_API void GL_APIENTRY glExtGetTexturesQCOM (GLuint *textures, GLint maxTextures, GLint *numTextures); +GL_API void GL_APIENTRY glExtGetBuffersQCOM (GLuint *buffers, GLint maxBuffers, GLint *numBuffers); +GL_API void GL_APIENTRY glExtGetRenderbuffersQCOM (GLuint *renderbuffers, GLint maxRenderbuffers, GLint *numRenderbuffers); +GL_API void GL_APIENTRY glExtGetFramebuffersQCOM (GLuint *framebuffers, GLint maxFramebuffers, GLint *numFramebuffers); +GL_API void GL_APIENTRY glExtGetTexLevelParameterivQCOM (GLuint texture, GLenum face, GLint level, GLenum pname, GLint *params); +GL_API void GL_APIENTRY glExtTexObjectStateOverrideiQCOM (GLenum target, GLenum pname, GLint param); +GL_API void GL_APIENTRY glExtGetTexSubImageQCOM (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, GLvoid *texels); +GL_API void GL_APIENTRY glExtGetBufferPointervQCOM (GLenum target, GLvoid **params); +#endif +typedef void (GL_APIENTRYP PFNGLEXTGETTEXTURESQCOMPROC) (GLuint *textures, GLint maxTextures, GLint *numTextures); +typedef void (GL_APIENTRYP PFNGLEXTGETBUFFERSQCOMPROC) (GLuint *buffers, GLint maxBuffers, GLint *numBuffers); +typedef void (GL_APIENTRYP PFNGLEXTGETRENDERBUFFERSQCOMPROC) (GLuint *renderbuffers, GLint maxRenderbuffers, GLint *numRenderbuffers); +typedef void (GL_APIENTRYP PFNGLEXTGETFRAMEBUFFERSQCOMPROC) (GLuint *framebuffers, GLint maxFramebuffers, GLint *numFramebuffers); +typedef void (GL_APIENTRYP PFNGLEXTGETTEXLEVELPARAMETERIVQCOMPROC) (GLuint texture, GLenum face, GLint level, GLenum pname, GLint *params); +typedef void (GL_APIENTRYP PFNGLEXTTEXOBJECTSTATEOVERRIDEIQCOMPROC) (GLenum target, GLenum pname, GLint param); +typedef void (GL_APIENTRYP PFNGLEXTGETTEXSUBIMAGEQCOMPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, GLvoid *texels); +typedef void (GL_APIENTRYP PFNGLEXTGETBUFFERPOINTERVQCOMPROC) (GLenum target, GLvoid **params); +#endif + +/* GL_QCOM_extended_get2 */ +#ifndef GL_QCOM_extended_get2 +#define GL_QCOM_extended_get2 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_API void GL_APIENTRY glExtGetShadersQCOM (GLuint *shaders, GLint maxShaders, GLint *numShaders); +GL_API void GL_APIENTRY glExtGetProgramsQCOM (GLuint *programs, GLint maxPrograms, GLint *numPrograms); +GL_API GLboolean GL_APIENTRY glExtIsProgramBinaryQCOM (GLuint program); +GL_API void GL_APIENTRY glExtGetProgramBinarySourceQCOM (GLuint program, GLenum shadertype, GLchar *source, GLint *length); +#endif +typedef void (GL_APIENTRYP PFNGLEXTGETSHADERSQCOMPROC) (GLuint *shaders, GLint maxShaders, GLint *numShaders); +typedef void (GL_APIENTRYP PFNGLEXTGETPROGRAMSQCOMPROC) (GLuint *programs, GLint maxPrograms, GLint *numPrograms); +typedef GLboolean (GL_APIENTRYP PFNGLEXTISPROGRAMBINARYQCOMPROC) (GLuint program); +typedef void (GL_APIENTRYP PFNGLEXTGETPROGRAMBINARYSOURCEQCOMPROC) (GLuint program, GLenum shadertype, GLchar *source, GLint *length); +#endif + +/* GL_QCOM_perfmon_global_mode */ +#ifndef GL_QCOM_perfmon_global_mode +#define GL_QCOM_perfmon_global_mode 1 +#endif + +/* GL_QCOM_writeonly_rendering */ +#ifndef GL_QCOM_writeonly_rendering +#define GL_QCOM_writeonly_rendering 1 +#endif + +/* GL_QCOM_tiled_rendering */ +#ifndef GL_QCOM_tiled_rendering +#define GL_QCOM_tiled_rendering 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_API void GL_APIENTRY glStartTilingQCOM (GLuint x, GLuint y, GLuint width, GLuint height, GLbitfield preserveMask); +GL_API void GL_APIENTRY glEndTilingQCOM (GLbitfield preserveMask); +#endif +typedef void (GL_APIENTRYP PFNGLSTARTTILINGQCOMPROC) (GLuint x, GLuint y, GLuint width, GLuint height, GLbitfield preserveMask); +typedef void (GL_APIENTRYP PFNGLENDTILINGQCOMPROC) (GLbitfield preserveMask); +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* __glext_h_ */ + diff --git a/Projects/Android/jni/SupportLibs/gl4es/include/GLES/glplatform.h b/Projects/Android/jni/SupportLibs/gl4es/include/GLES/glplatform.h new file mode 100644 index 0000000..2db6ee2 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/include/GLES/glplatform.h @@ -0,0 +1,30 @@ +#ifndef __glplatform_h_ +#define __glplatform_h_ + +/* $Revision: 10601 $ on $Date:: 2010-03-04 22:15:27 -0800 #$ */ + +/* + * This document is licensed under the SGI Free Software B License Version + * 2.0. For details, see http://oss.sgi.com/projects/FreeB/ . + */ + +/* Platform-specific types and definitions for OpenGL ES 1.X gl.h + * + * Adopters may modify khrplatform.h and this file to suit their platform. + * You are encouraged to submit all modifications to the Khronos group so that + * they can be included in future versions of this file. Please submit changes + * by sending them to the public Khronos Bugzilla (http://khronos.org/bugzilla) + * by filing a bug against product "OpenGL-ES" component "Registry". + */ + +#include + +#ifndef GL_API +#define GL_API KHRONOS_APICALL +#endif + +#ifndef GL_APIENTRY +#define GL_APIENTRY KHRONOS_APIENTRY +#endif + +#endif /* __glplatform_h_ */ diff --git a/Projects/Android/jni/SupportLibs/gl4es/include/KHR/khrplatform.h b/Projects/Android/jni/SupportLibs/gl4es/include/KHR/khrplatform.h new file mode 100644 index 0000000..8ec0d19 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/include/KHR/khrplatform.h @@ -0,0 +1,269 @@ +#ifndef __khrplatform_h_ +#define __khrplatform_h_ + +/* +** Copyright (c) 2008-2009 The Khronos Group Inc. +** +** Permission is hereby granted, free of charge, to any person obtaining a +** copy of this software and/or associated documentation files (the +** "Materials"), to deal in the Materials without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Materials, and to +** permit persons to whom the Materials are furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be included +** in all copies or substantial portions of the Materials. +** +** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. +*/ + +/* Khronos platform-specific types and definitions. + * + * $Revision: 9356 $ on $Date: 2009-10-21 02:52:25 -0700 (Wed, 21 Oct 2009) $ + * + * Adopters may modify this file to suit their platform. Adopters are + * encouraged to submit platform specific modifications to the Khronos + * group so that they can be included in future versions of this file. + * Please submit changes by sending them to the public Khronos Bugzilla + * (http://khronos.org/bugzilla) by filing a bug against product + * "Khronos (general)" component "Registry". + * + * A predefined template which fills in some of the bug fields can be + * reached using http://tinyurl.com/khrplatform-h-bugreport, but you + * must create a Bugzilla login first. + * + * + * See the Implementer's Guidelines for information about where this file + * should be located on your system and for more details of its use: + * http://www.khronos.org/registry/implementers_guide.pdf + * + * This file should be included as + * #include + * by Khronos client API header files that use its types and defines. + * + * The types in khrplatform.h should only be used to define API-specific types. + * + * Types defined in khrplatform.h: + * khronos_int8_t signed 8 bit + * khronos_uint8_t unsigned 8 bit + * khronos_int16_t signed 16 bit + * khronos_uint16_t unsigned 16 bit + * khronos_int32_t signed 32 bit + * khronos_uint32_t unsigned 32 bit + * khronos_int64_t signed 64 bit + * khronos_uint64_t unsigned 64 bit + * khronos_intptr_t signed same number of bits as a pointer + * khronos_uintptr_t unsigned same number of bits as a pointer + * khronos_ssize_t signed size + * khronos_usize_t unsigned size + * khronos_float_t signed 32 bit floating point + * khronos_time_ns_t unsigned 64 bit time in nanoseconds + * khronos_utime_nanoseconds_t unsigned time interval or absolute time in + * nanoseconds + * khronos_stime_nanoseconds_t signed time interval in nanoseconds + * khronos_boolean_enum_t enumerated boolean type. This should + * only be used as a base type when a client API's boolean type is + * an enum. Client APIs which use an integer or other type for + * booleans cannot use this as the base type for their boolean. + * + * Tokens defined in khrplatform.h: + * + * KHRONOS_FALSE, KHRONOS_TRUE Enumerated boolean false/true values. + * + * KHRONOS_SUPPORT_INT64 is 1 if 64 bit integers are supported; otherwise 0. + * KHRONOS_SUPPORT_FLOAT is 1 if floats are supported; otherwise 0. + * + * Calling convention macros defined in this file: + * KHRONOS_APICALL + * KHRONOS_APIENTRY + * KHRONOS_APIATTRIBUTES + * + * These may be used in function prototypes as: + * + * KHRONOS_APICALL void KHRONOS_APIENTRY funcname( + * int arg1, + * int arg2) KHRONOS_APIATTRIBUTES; + */ + +/*------------------------------------------------------------------------- + * Definition of KHRONOS_APICALL + *------------------------------------------------------------------------- + * This precedes the return type of the function in the function prototype. + */ +#if defined(_WIN32) && !defined(__SCITECH_SNAP__) +# define KHRONOS_APICALL __declspec(dllimport) +#elif defined (__SYMBIAN32__) +# define KHRONOS_APICALL IMPORT_C +#else +# define KHRONOS_APICALL +#endif + +/*------------------------------------------------------------------------- + * Definition of KHRONOS_APIENTRY + *------------------------------------------------------------------------- + * This follows the return type of the function and precedes the function + * name in the function prototype. + */ +#if defined(_WIN32) && !defined(_WIN32_WCE) && !defined(__SCITECH_SNAP__) + /* Win32 but not WinCE */ +# define KHRONOS_APIENTRY __stdcall +#else +# define KHRONOS_APIENTRY +#endif + +/*------------------------------------------------------------------------- + * Definition of KHRONOS_APIATTRIBUTES + *------------------------------------------------------------------------- + * This follows the closing parenthesis of the function prototype arguments. + */ +#if defined (__ARMCC_2__) +#define KHRONOS_APIATTRIBUTES __softfp +#else +#define KHRONOS_APIATTRIBUTES +#endif + +/*------------------------------------------------------------------------- + * basic type definitions + *-----------------------------------------------------------------------*/ +#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || defined(__GNUC__) || defined(__SCO__) || defined(__USLC__) + + +/* + * Using + */ +#include +typedef int32_t khronos_int32_t; +typedef uint32_t khronos_uint32_t; +typedef int64_t khronos_int64_t; +typedef uint64_t khronos_uint64_t; +#define KHRONOS_SUPPORT_INT64 1 +#define KHRONOS_SUPPORT_FLOAT 1 + +#elif defined(__VMS ) || defined(__sgi) + +/* + * Using + */ +#include +typedef int32_t khronos_int32_t; +typedef uint32_t khronos_uint32_t; +typedef int64_t khronos_int64_t; +typedef uint64_t khronos_uint64_t; +#define KHRONOS_SUPPORT_INT64 1 +#define KHRONOS_SUPPORT_FLOAT 1 + +#elif defined(_WIN32) && !defined(__SCITECH_SNAP__) + +/* + * Win32 + */ +typedef __int32 khronos_int32_t; +typedef unsigned __int32 khronos_uint32_t; +typedef __int64 khronos_int64_t; +typedef unsigned __int64 khronos_uint64_t; +#define KHRONOS_SUPPORT_INT64 1 +#define KHRONOS_SUPPORT_FLOAT 1 + +#elif defined(__sun__) || defined(__digital__) + +/* + * Sun or Digital + */ +typedef int khronos_int32_t; +typedef unsigned int khronos_uint32_t; +#if defined(__arch64__) || defined(_LP64) +typedef long int khronos_int64_t; +typedef unsigned long int khronos_uint64_t; +#else +typedef long long int khronos_int64_t; +typedef unsigned long long int khronos_uint64_t; +#endif /* __arch64__ */ +#define KHRONOS_SUPPORT_INT64 1 +#define KHRONOS_SUPPORT_FLOAT 1 + +#elif 0 + +/* + * Hypothetical platform with no float or int64 support + */ +typedef int khronos_int32_t; +typedef unsigned int khronos_uint32_t; +#define KHRONOS_SUPPORT_INT64 0 +#define KHRONOS_SUPPORT_FLOAT 0 + +#else + +/* + * Generic fallback + */ +#include +typedef int32_t khronos_int32_t; +typedef uint32_t khronos_uint32_t; +typedef int64_t khronos_int64_t; +typedef uint64_t khronos_uint64_t; +#define KHRONOS_SUPPORT_INT64 1 +#define KHRONOS_SUPPORT_FLOAT 1 + +#endif + + +/* + * Types that are (so far) the same on all platforms + */ +typedef signed char khronos_int8_t; +typedef unsigned char khronos_uint8_t; +typedef signed short int khronos_int16_t; +typedef unsigned short int khronos_uint16_t; +typedef signed long int khronos_intptr_t; +typedef unsigned long int khronos_uintptr_t; +typedef signed long int khronos_ssize_t; +typedef unsigned long int khronos_usize_t; + +#if KHRONOS_SUPPORT_FLOAT +/* + * Float type + */ +typedef float khronos_float_t; +#endif + +#if KHRONOS_SUPPORT_INT64 +/* Time types + * + * These types can be used to represent a time interval in nanoseconds or + * an absolute Unadjusted System Time. Unadjusted System Time is the number + * of nanoseconds since some arbitrary system event (e.g. since the last + * time the system booted). The Unadjusted System Time is an unsigned + * 64 bit value that wraps back to 0 every 584 years. Time intervals + * may be either signed or unsigned. + */ +typedef khronos_uint64_t khronos_utime_nanoseconds_t; +typedef khronos_int64_t khronos_stime_nanoseconds_t; +#endif + +/* + * Dummy value used to pad enum types to 32 bits. + */ +#ifndef KHRONOS_MAX_ENUM +#define KHRONOS_MAX_ENUM 0x7FFFFFFF +#endif + +/* + * Enumerated boolean type + * + * Values other than zero should be considered to be true. Therefore + * comparisons should not be made against KHRONOS_TRUE. + */ +typedef enum { + KHRONOS_FALSE = 0, + KHRONOS_TRUE = 1, + KHRONOS_BOOLEAN_ENUM_FORCE_SIZE = KHRONOS_MAX_ENUM +} khronos_boolean_enum_t; + +#endif /* __khrplatform_h_ */ diff --git a/Projects/Android/jni/SupportLibs/gl4es/include/android_debug.h b/Projects/Android/jni/SupportLibs/gl4es/include/android_debug.h new file mode 100644 index 0000000..075e1f4 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/include/android_debug.h @@ -0,0 +1,70 @@ +#ifndef __ANDROID_DEBUG_H__ +#define __ANDROID_DEBUG_H__ + +// Redirect printf() to Android log +// Put this file into CFLAGS: "-include ../android_debug.h" + +#include +#include +#include + +#ifdef __cplusplus +// Include everything beforehand, so we wont' get compiler errors because of our #define +#include +#include +#include +#include +#include +#include + +namespace std +{ + class android_cout: public ostringstream + { + public: + android_cout() {} + template + android_cout &operator<<(const T &v) + { + *((ostringstream*)this) << v; + if( this->str().find('\n') != ::std::string::npos ) + { + __android_log_print(ANDROID_LOG_INFO, "LIBGL", "%s", this->str().c_str()); + this->str().clear(); + } + return *this; + } + ~android_cout() + { + __android_log_print(ANDROID_LOG_INFO, "LIBGL", "%s", this->str().c_str()); + this->str().clear(); + } + }; + static const char * android_endl = "\n"; +} +#define cout android_cout() +#define cerr android_cout() +#define endl android_endl + +#endif + +#define printf(...) __android_log_print(ANDROID_LOG_INFO, "LIBGL", __VA_ARGS__) +/* +// Override fprintf(stderr, ...) constructs +static inline int __sdl_logged_fprintf(FILE *stream, const char *format, ...) +{ + int ret = 0; + va_list args; + va_start(args, format); + if( stream == stderr || stream == stdout ) + ret = __android_log_vprint(ANDROID_LOG_INFO, "LIBGL", format, args); + else + ret = vfprintf(stream, format, args); + va_end(args); + return ret; +} + +#define fprintf(...) __sdl_logged_fprintf(__VA_ARGS__) +*/ +#endif + diff --git a/Projects/Android/jni/SupportLibs/gl4es/include/gl4eshint.h b/Projects/Android/jni/SupportLibs/gl4es/include/gl4eshint.h new file mode 100644 index 0000000..6a1bd7f --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/include/gl4eshint.h @@ -0,0 +1,36 @@ +#ifndef _GL4ESINCLUDE_HINT_H_ +#define _GL4ESINCLUDE_HINT_H_ + +// Custom hints to handles some specifics gl4es options + +// same as using LIBGL_SHRINK=x +#define GL_SHRINK_HINT_GL4ES 0xA101 +// same as using LIBGL_ALPHAHACK=x +#define GL_ALPHAHACK_HINT_GL4ES 0xA102 +// same as using LIBGL_RECYCLEFBO=x +#define GL_RECYCLEFBO_HINT_GL4ES 0xA103 +// same as using LIBGL_MIPMAP=x +#define GL_MIPMAP_HINT_GL4ES 0xA104 +// same as using LIBGL_TEXDUMP=x +#define GL_TEXDUMP_HINT_GL4ES 0xA105 +// same as using LIBGL_COPY=x +#define GL_COPY_HINT_GL4ES 0xA106 +// same as using LIBGL_NOLUMALPHA=x +#define GL_NOLUMAPHA_HINT_GL4ES 0xA107 +// same as using LIBGL_BLENDHACK=x +#define GL_BLENDHACK_HINT_GL4ES 0xA108 +// REMOVED same as using LIBGL_BATCH=x +#define GL_BATCH_HINT_GL4ES 0xA109 +// same as using LIBGL_NOERROR=x +#define GL_NOERROR_HINT_GL4ES 0xA10A +// same as using LIBGL_NODOWNSAMPLING=x +#define GL_NODOWNSAMPLING_HINT_GL4ES 0xA10B +// same as using LIBGL_NOVAOCACHE=x +#define GL_NOVAOCACHE_HINT_GL4ES 0xA10C +// same as using LIBGL_BEGINEND=x +#define GL_BEGINEND_HINT_GL4ES 0xA10D +// same as using LIBGL_AVOID16BITS=x +#define GL_AVOID16BITS_HINT_GL4ES 0xA10E +// same as using LIBGL_GAMMA=xx (PANDORA only) +#define GL_GAMMA_HINT_GL4ES 0xA10F +#endif // _GL4ESINCLUDE_HINT_H_ diff --git a/Projects/Android/jni/SupportLibs/gl4es/include/khash.h b/Projects/Android/jni/SupportLibs/gl4es/include/khash.h new file mode 100644 index 0000000..bedc8d2 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/include/khash.h @@ -0,0 +1,652 @@ +/* The MIT License + + Copyright (c) 2008, 2009, 2011 by Attractive Chaos + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +/* + An example: + +#include "khash.h" +KHASH_MAP_INIT_INT(32, char) +int main() { + int ret, is_missing; + khiter_t k; + khash_t(32) *h = kh_init(32); + k = kh_put(32, h, 5, &ret); + kh_value(h, k) = 10; + k = kh_get(32, h, 10); + is_missing = (k == kh_end(h)); + k = kh_get(32, h, 5); + kh_del(32, h, k); + for (k = kh_begin(h); k != kh_end(h); ++k) + if (kh_exist(h, k)) kh_value(h, k) = 1; + kh_destroy(32, h); + return 0; +} +*/ + +/* + 2013-05-02 (0.2.8): + + * Use quadratic probing. When the capacity is power of 2, stepping function + i*(i+1)/2 guarantees to traverse each bucket. It is better than double + hashing on cache performance and is more robust than linear probing. + + In theory, double hashing should be more robust than quadratic probing. + However, my implementation is probably not for large hash tables, because + the second hash function is closely tied to the first hash function, + which reduce the effectiveness of double hashing. + + Reference: http://research.cs.vt.edu/AVresearch/hashing/quadratic.php + + 2011-12-29 (0.2.7): + + * Minor code clean up; no actual effect. + + 2011-09-16 (0.2.6): + + * The capacity is a power of 2. This seems to dramatically improve the + speed for simple keys. Thank Zilong Tan for the suggestion. Reference: + + - http://code.google.com/p/ulib/ + - http://nothings.org/computer/judy/ + + * Allow to optionally use linear probing which usually has better + performance for random input. Double hashing is still the default as it + is more robust to certain non-random input. + + * Added Wang's integer hash function (not used by default). This hash + function is more robust to certain non-random input. + + 2011-02-14 (0.2.5): + + * Allow to declare global functions. + + 2009-09-26 (0.2.4): + + * Improve portability + + 2008-09-19 (0.2.3): + + * Corrected the example + * Improved interfaces + + 2008-09-11 (0.2.2): + + * Improved speed a little in kh_put() + + 2008-09-10 (0.2.1): + + * Added kh_clear() + * Fixed a compiling error + + 2008-09-02 (0.2.0): + + * Changed to token concatenation which increases flexibility. + + 2008-08-31 (0.1.2): + + * Fixed a bug in kh_get(), which has not been tested previously. + + 2008-08-31 (0.1.1): + + * Added destructor +*/ + + +#ifndef __AC_KHASH_H +#define __AC_KHASH_H + +/*! + @header + + Generic hash table library. + */ + +#define AC_VERSION_KHASH_H "0.2.8" + +#include +#include +#include + +/* compiler specific configuration */ + +#if UINT_MAX == 0xffffffffu +typedef unsigned int khint32_t; +#elif ULONG_MAX == 0xffffffffu +typedef unsigned long khint32_t; +#endif + +#if ULONG_MAX == ULLONG_MAX +typedef unsigned long khint64_t; +#else +typedef unsigned long long khint64_t; +#endif + +#ifdef _MSC_VER +#define kh_inline __inline +#else +#define kh_inline inline +#endif + +typedef khint32_t khint_t; +typedef khint_t khiter_t; + +#define __ac_isempty(flag, i) ((flag[i>>4]>>((i&0xfU)<<1))&2) +#define __ac_isdel(flag, i) ((flag[i>>4]>>((i&0xfU)<<1))&1) +#define __ac_iseither(flag, i) ((flag[i>>4]>>((i&0xfU)<<1))&3) +#define __ac_set_isdel_false(flag, i) (flag[i>>4]&=~(1ul<<((i&0xfU)<<1))) +#define __ac_set_isempty_false(flag, i) (flag[i>>4]&=~(2ul<<((i&0xfU)<<1))) +#define __ac_set_isboth_false(flag, i) (flag[i>>4]&=~(3ul<<((i&0xfU)<<1))) +#define __ac_set_isdel_true(flag, i) (flag[i>>4]|=1ul<<((i&0xfU)<<1)) + +#define __ac_fsize(m) ((m) < 16? 1 : (m)>>4) + +#ifndef kroundup32 +#define kroundup32(x) (--(x), (x)|=(x)>>1, (x)|=(x)>>2, (x)|=(x)>>4, (x)|=(x)>>8, (x)|=(x)>>16, ++(x)) +#endif + +#ifndef kcalloc +#define kcalloc(N,Z) calloc(N,Z) +#endif +#ifndef kmalloc +#define kmalloc(Z) malloc(Z) +#endif +#ifndef krealloc +#define krealloc(P,Z) realloc(P,Z) +#endif +#ifndef kfree +#define kfree(P) free(P) +#endif + +static const double __ac_HASH_UPPER = 0.77; + +#define __KHASH_TYPE(name, khkey_t, khval_t) \ + typedef struct { \ + khint_t n_buckets, size, n_occupied, upper_bound; \ + khint32_t *flags; \ + khkey_t *keys; \ + khval_t *vals; \ + } kh_##name##_t; + +#define __KHASH_PROTOTYPES(name, khkey_t, khval_t) \ + extern kh_##name##_t *kh_init_##name(void); \ + extern void kh_destroy_##name(kh_##name##_t *h); \ + extern void kh_clear_##name(kh_##name##_t *h); \ + extern khint_t kh_get_##name(const kh_##name##_t *h, khkey_t key); \ + extern int kh_resize_##name(kh_##name##_t *h, khint_t new_n_buckets); \ + extern khint_t kh_put_##name(kh_##name##_t *h, khkey_t key, int *ret); \ + extern void kh_del_##name(kh_##name##_t *h, khint_t x); + +#define __KHASH_IMPL(name, SCOPE, khkey_t, khval_t, kh_is_map, __hash_func, __hash_equal) \ + SCOPE kh_##name##_t *kh_init_##name(void) { \ + return (kh_##name##_t*)kcalloc(1, sizeof(kh_##name##_t)); \ + } \ + SCOPE void kh_destroy_##name(kh_##name##_t *h) \ + { \ + if (h) { \ + kfree((void *)h->keys); kfree(h->flags); \ + kfree((void *)h->vals); \ + kfree(h); \ + } \ + } \ + SCOPE void kh_clear_##name(kh_##name##_t *h) \ + { \ + if (h && h->flags) { \ + memset(h->flags, 0xaa, __ac_fsize(h->n_buckets) * sizeof(khint32_t)); \ + h->size = h->n_occupied = 0; \ + } \ + } \ + SCOPE khint_t kh_get_##name(const kh_##name##_t *h, khkey_t key) \ + { \ + if (h->n_buckets) { \ + khint_t k, i, last, mask, step = 0; \ + mask = h->n_buckets - 1; \ + k = __hash_func(key); i = k & mask; \ + last = i; \ + while (!__ac_isempty(h->flags, i) && (__ac_isdel(h->flags, i) || !__hash_equal(h->keys[i], key))) { \ + i = (i + (++step)) & mask; \ + if (i == last) return h->n_buckets; \ + } \ + return __ac_iseither(h->flags, i)? h->n_buckets : i; \ + } else return 0; \ + } \ + SCOPE int kh_resize_##name(kh_##name##_t *h, khint_t new_n_buckets) \ + { /* This function uses 0.25*n_buckets bytes of working space instead of [sizeof(key_t+val_t)+.25]*n_buckets. */ \ + khint32_t *new_flags = 0; \ + khint_t j = 1; \ + { \ + kroundup32(new_n_buckets); \ + if (new_n_buckets < 4) new_n_buckets = 4; \ + if (h->size >= (khint_t)(new_n_buckets * __ac_HASH_UPPER + 0.5)) j = 0; /* requested size is too small */ \ + else { /* hash table size to be changed (shrink or expand); rehash */ \ + new_flags = (khint32_t*)kmalloc(__ac_fsize(new_n_buckets) * sizeof(khint32_t)); \ + if (!new_flags) return -1; \ + memset(new_flags, 0xaa, __ac_fsize(new_n_buckets) * sizeof(khint32_t)); \ + if (h->n_buckets < new_n_buckets) { /* expand */ \ + khkey_t *new_keys = (khkey_t*)krealloc((void *)h->keys, new_n_buckets * sizeof(khkey_t)); \ + if (!new_keys) return -1; \ + h->keys = new_keys; \ + if (kh_is_map) { \ + khval_t *new_vals = (khval_t*)krealloc((void *)h->vals, new_n_buckets * sizeof(khval_t)); \ + if (!new_vals) return -1; \ + h->vals = new_vals; \ + } \ + } /* otherwise shrink */ \ + } \ + } \ + if (j) { /* rehashing is needed */ \ + for (j = 0; j != h->n_buckets; ++j) { \ + if (__ac_iseither(h->flags, j) == 0) { \ + khkey_t key = h->keys[j]; \ + khval_t val; \ + khint_t new_mask; \ + new_mask = new_n_buckets - 1; \ + if (kh_is_map) val = h->vals[j]; \ + __ac_set_isdel_true(h->flags, j); \ + while (1) { /* kick-out process; sort of like in Cuckoo hashing */ \ + khint_t k, i, step = 0; \ + k = __hash_func(key); \ + i = k & new_mask; \ + while (!__ac_isempty(new_flags, i)) i = (i + (++step)) & new_mask; \ + __ac_set_isempty_false(new_flags, i); \ + if (i < h->n_buckets && __ac_iseither(h->flags, i) == 0) { /* kick out the existing element */ \ + { khkey_t tmp = h->keys[i]; h->keys[i] = key; key = tmp; } \ + if (kh_is_map) { khval_t tmp = h->vals[i]; h->vals[i] = val; val = tmp; } \ + __ac_set_isdel_true(h->flags, i); /* mark it as deleted in the old hash table */ \ + } else { /* write the element and jump out of the loop */ \ + h->keys[i] = key; \ + if (kh_is_map) h->vals[i] = val; \ + break; \ + } \ + } \ + } \ + } \ + if (h->n_buckets > new_n_buckets) { /* shrink the hash table */ \ + h->keys = (khkey_t*)krealloc((void *)h->keys, new_n_buckets * sizeof(khkey_t)); \ + if (kh_is_map) h->vals = (khval_t*)krealloc((void *)h->vals, new_n_buckets * sizeof(khval_t)); \ + } \ + kfree(h->flags); /* free the working space */ \ + h->flags = new_flags; \ + h->n_buckets = new_n_buckets; \ + h->n_occupied = h->size; \ + h->upper_bound = (khint_t)(h->n_buckets * __ac_HASH_UPPER + 0.5); \ + } \ + return 0; \ + } \ + SCOPE khint_t kh_put_##name(kh_##name##_t *h, khkey_t key, int *ret) \ + { \ + khint_t x; \ + if (h->n_occupied >= h->upper_bound) { /* update the hash table */ \ + if (h->n_buckets > (h->size<<1)) { \ + if (kh_resize_##name(h, h->n_buckets - 1) < 0) { /* clear "deleted" elements */ \ + *ret = -1; return h->n_buckets; \ + } \ + } else if (kh_resize_##name(h, h->n_buckets + 1) < 0) { /* expand the hash table */ \ + *ret = -1; return h->n_buckets; \ + } \ + } /* TODO: to implement automatically shrinking; resize() already support shrinking */ \ + { \ + khint_t k, i, site, last, mask = h->n_buckets - 1, step = 0; \ + x = site = h->n_buckets; k = __hash_func(key); i = k & mask; \ + if (__ac_isempty(h->flags, i)) x = i; /* for speed up */ \ + else { \ + last = i; \ + while (!__ac_isempty(h->flags, i) && (__ac_isdel(h->flags, i) || !__hash_equal(h->keys[i], key))) { \ + if (__ac_isdel(h->flags, i)) site = i; \ + i = (i + (++step)) & mask; \ + if (i == last) { x = site; break; } \ + } \ + if (x == h->n_buckets) { \ + if (__ac_isempty(h->flags, i) && site != h->n_buckets) x = site; \ + else x = i; \ + } \ + } \ + } \ + if (__ac_isempty(h->flags, x)) { /* not present at all */ \ + h->keys[x] = key; \ + __ac_set_isboth_false(h->flags, x); \ + ++h->size; ++h->n_occupied; \ + *ret = 1; \ + } else if (__ac_isdel(h->flags, x)) { /* deleted */ \ + h->keys[x] = key; \ + __ac_set_isboth_false(h->flags, x); \ + ++h->size; \ + *ret = 2; \ + } else *ret = 0; /* Don't touch h->keys[x] if present and not deleted */ \ + return x; \ + } \ + SCOPE void kh_del_##name(kh_##name##_t *h, khint_t x) \ + { \ + if (x != h->n_buckets && !__ac_iseither(h->flags, x)) { \ + __ac_set_isdel_true(h->flags, x); \ + --h->size; \ + } \ + } + +#define KHASH_DECLARE(name, khkey_t, khval_t) \ + __KHASH_TYPE(name, khkey_t, khval_t) \ + __KHASH_PROTOTYPES(name, khkey_t, khval_t) + +#define KHASH_INIT2(name, SCOPE, khkey_t, khval_t, kh_is_map, __hash_func, __hash_equal) \ + __KHASH_TYPE(name, khkey_t, khval_t) \ + __KHASH_IMPL(name, SCOPE, khkey_t, khval_t, kh_is_map, __hash_func, __hash_equal) + +#define KHASH_INIT(name, khkey_t, khval_t, kh_is_map, __hash_func, __hash_equal) \ + KHASH_INIT2(name, static kh_inline, khkey_t, khval_t, kh_is_map, __hash_func, __hash_equal) + +/* --- BEGIN OF HASH FUNCTIONS --- */ + +/*! @function + @abstract Integer hash function + @param key The integer [khint32_t] + @return The hash value [khint_t] + */ +#define kh_int_hash_func(key) (khint32_t)(key) +/*! @function + @abstract Integer comparison function + */ +#define kh_int_hash_equal(a, b) ((a) == (b)) +/*! @function + @abstract 64-bit integer hash function + @param key The integer [khint64_t] + @return The hash value [khint_t] + */ +#define kh_int64_hash_func(key) (khint32_t)((key)>>33^(key)^(key)<<11) +/*! @function + @abstract 64-bit integer comparison function + */ +#define kh_int64_hash_equal(a, b) ((a) == (b)) +/*! @function + @abstract const char* hash function + @param s Pointer to a null terminated string + @return The hash value + */ +static kh_inline khint_t __ac_X31_hash_string(const char *s) +{ + khint_t h = (khint_t)*s; + if (h) for (++s ; *s; ++s) h = (h << 5) - h + (khint_t)*s; + return h; +} +/*! @function + @abstract Another interface to const char* hash function + @param key Pointer to a null terminated string [const char*] + @return The hash value [khint_t] + */ +#define kh_str_hash_func(key) __ac_X31_hash_string(key) +/*! @function + @abstract Const char* comparison function + */ +#define kh_str_hash_equal(a, b) (strcmp(a, b) == 0) + +static kh_inline khint_t __ac_Wang_hash(khint_t key) +{ + key += ~(key << 15); + key ^= (key >> 10); + key += (key << 3); + key ^= (key >> 6); + key += ~(key << 11); + key ^= (key >> 16); + return key; +} +#define kh_int_hash_func2(k) __ac_Wang_hash((khint_t)key) + +/* --- END OF HASH FUNCTIONS --- */ + +/* Other convenient macros... */ + +/*! + @abstract Type of the hash table. + @param name Name of the hash table [symbol] + */ +#define khash_t(name) kh_##name##_t + +/*! @function + @abstract Initiate a hash table. + @param name Name of the hash table [symbol] + @return Pointer to the hash table [khash_t(name)*] + */ +#define kh_init(name) kh_init_##name() + +/*! @function + @abstract Destroy a hash table. + @param name Name of the hash table [symbol] + @param h Pointer to the hash table [khash_t(name)*] + */ +#define kh_destroy(name, h) kh_destroy_##name(h) + +/*! @function + @abstract Reset a hash table without deallocating memory. + @param name Name of the hash table [symbol] + @param h Pointer to the hash table [khash_t(name)*] + */ +#define kh_clear(name, h) kh_clear_##name(h) + +/*! @function + @abstract Resize a hash table. + @param name Name of the hash table [symbol] + @param h Pointer to the hash table [khash_t(name)*] + @param s New size [khint_t] + */ +#define kh_resize(name, h, s) kh_resize_##name(h, s) + +/*! @function + @abstract Insert a key to the hash table. + @param name Name of the hash table [symbol] + @param h Pointer to the hash table [khash_t(name)*] + @param k Key [type of keys] + @param r Extra return code: 0 if the key is present in the hash table; + 1 if the bucket is empty (never used); 2 if the element in + the bucket has been deleted [int*] + @return Iterator to the inserted element [khint_t] + */ +#define kh_put(name, h, k, r) kh_put_##name(h, k, r) + +/*! @function + @abstract Retrieve a key from the hash table. + @param name Name of the hash table [symbol] + @param h Pointer to the hash table [khash_t(name)*] + @param k Key [type of keys] + @return Iterator to the found element, or kh_end(h) if the element is absent [khint_t] + */ +#define kh_get(name, h, k) kh_get_##name(h, k) + +/*! @function + @abstract Remove a key from the hash table. + @param name Name of the hash table [symbol] + @param h Pointer to the hash table [khash_t(name)*] + @param k Iterator to the element to be deleted [khint_t] + */ +#define kh_del(name, h, k) kh_del_##name(h, k) + +/*! @function + @abstract Test whether a bucket contains data. + @param h Pointer to the hash table [khash_t(name)*] + @param x Iterator to the bucket [khint_t] + @return 1 if containing data; 0 otherwise [int] + */ +#define kh_exist(h, x) (!__ac_iseither((h)->flags, (x))) + +/*! @function + @abstract Get key given an iterator + @param h Pointer to the hash table [khash_t(name)*] + @param x Iterator to the bucket [khint_t] + @return Key [type of keys] + */ +#define kh_key(h, x) ((h)->keys[x]) + +/*! @function + @abstract Get value given an iterator + @param h Pointer to the hash table [khash_t(name)*] + @param x Iterator to the bucket [khint_t] + @return Value [type of values] + @discussion For hash sets, calling this results in segfault. + */ +#define kh_val(h, x) ((h)->vals[x]) + +/*! @function + @abstract Alias of kh_val() + */ +#define kh_value(h, x) ((h)->vals[x]) + +/*! @function + @abstract Get the start iterator + @param h Pointer to the hash table [khash_t(name)*] + @return The start iterator [khint_t] + */ +#define kh_begin(h) (khint_t)(0) + +/*! @function + @abstract Get the end iterator + @param h Pointer to the hash table [khash_t(name)*] + @return The end iterator [khint_t] + */ +#define kh_end(h) ((h)->n_buckets) + +/*! @function + @abstract Get the number of elements in the hash table + @param h Pointer to the hash table [khash_t(name)*] + @return Number of elements in the hash table [khint_t] + */ +#define kh_size(h) ((h)->size) + +/*! @function + @abstract Get the number of buckets in the hash table + @param h Pointer to the hash table [khash_t(name)*] + @return Number of buckets in the hash table [khint_t] + */ +#define kh_n_buckets(h) ((h)->n_buckets) + +/*! @function + @abstract Iterate over the entries in the hash table + @param h Pointer to the hash table [khash_t(name)*] + @param kvar Variable to which key will be assigned + @param vvar Variable to which value will be assigned + @param code Block of code to execute + */ +#define kh_foreach(h, kvar, vvar, code) { khint_t __i; \ + for (__i = kh_begin(h); __i != kh_end(h); ++__i) { \ + if (!kh_exist(h,__i)) continue; \ + (kvar) = kh_key(h,__i); \ + (vvar) = kh_val(h,__i); \ + code; \ + } } + +/*! @function + @abstract Iterate over the values in the hash table + @param h Pointer to the hash table [khash_t(name)*] + @param vvar Variable to which value will be assigned + @param code Block of code to execute + */ +#define kh_foreach_value(h, vvar, code) { khint_t __i; \ + for (__i = kh_begin(h); __i != kh_end(h); ++__i) { \ + if (!kh_exist(h,__i)) continue; \ + (vvar) = kh_val(h,__i); \ + code; \ + } } + +/* More conenient interfaces */ + +/*! @function + @abstract Instantiate a hash set containing integer keys + @param name Name of the hash table [symbol] + */ +#define KHASH_SET_INIT_INT(name) \ + KHASH_INIT(name, khint32_t, char, 0, kh_int_hash_func, kh_int_hash_equal) + +#define KHASH_SET_DECLARE_INT(name) \ + KHASH_DECLARE(name, khint32_t, char) + +#define KHASH_SET_IMPL_INT(name) \ + __KHASH_IMPL(name, , khkey_t, khval_t, kh_is_map, __hash_func, __hash_equal) + +/*! @function + @abstract Instantiate a hash map containing integer keys + @param name Name of the hash table [symbol] + @param khval_t Type of values [type] + */ +#define KHASH_MAP_INIT_INT(name, khval_t) \ + KHASH_INIT(name, khint32_t, khval_t, 1, kh_int_hash_func, kh_int_hash_equal) + +#define KHASH_MAP_DECLARE_INT(name, khval_t) \ + KHASH_DECLARE(name, khint32_t, khval_t) + +#define KHASH_MAP_IMPL_INT(name, khval_t) \ + __KHASH_IMPL(name, , khint32_t, khval_t, 1, kh_int_hash_func, kh_int_hash_equal) + +/*! @function + @abstract Instantiate a hash map containing 64-bit integer keys + @param name Name of the hash table [symbol] + */ +#define KHASH_SET_INIT_INT64(name) \ + KHASH_INIT(name, khint64_t, char, 0, kh_int64_hash_func, kh_int64_hash_equal) + +#define KHASH_SET_DECLARE_INT64(name) \ + KHASH_DECLARE(name, khint64_t, char) + +#define KHASH_SET_IMPL_INT64(name) \ + __KHASH_IMPL(name, , khint64_t, char, 0, kh_int64_hash_func, kh_int64_hash_equal) + +/*! @function + @abstract Instantiate a hash map containing 64-bit integer keys + @param name Name of the hash table [symbol] + @param khval_t Type of values [type] + */ +#define KHASH_MAP_INIT_INT64(name, khval_t) \ + KHASH_INIT(name, khint64_t, khval_t, 1, kh_int64_hash_func, kh_int64_hash_equal) + +#define KHASH_MAP_DECLARE_INT64(name, khval_t) \ + KHASH_DECLARE(name, khint64_t, khval_t) + +#define KHASH_MAP_IMPL_INT64(name, khval_t) \ + __KHASH_IMPL(name, , khint64_t, khval_t, 1, kh_int64_hash_func, kh_int64_hash_equal) + +typedef const char *kh_cstr_t; +/*! @function + @abstract Instantiate a hash map containing const char* keys + @param name Name of the hash table [symbol] + */ +#define KHASH_SET_INIT_STR(name) \ + KHASH_INIT(name, kh_cstr_t, char, 0, kh_str_hash_func, kh_str_hash_equal) + +#define KHASH_SET_DECLARE_STR(name) \ + KHASH_DECLARE(name, kh_cstr_t, char) + +#define KHASH_SET_IMPL_STR(name) \ + __KHASH_IMPL(name, , kh_cstr_t, char, 0, kh_str_hash_func, kh_str_hash_equal) + +/*! @function + @abstract Instantiate a hash map containing const char* keys + @param name Name of the hash table [symbol] + @param khval_t Type of values [type] + */ +#define KHASH_MAP_INIT_STR(name, khval_t) \ + KHASH_INIT(name, kh_cstr_t, khval_t, 1, kh_str_hash_func, kh_str_hash_equal) + +#define KHASH_MAP_DECLARE_STR(name, khval_t) \ + KHASH_DECLARE(name, kh_cstr_t, khval_t) + +#define KHASH_MAP_IMPL_STR(name, khval_t) \ + __KHASH_IMPL(name, , kh_cstr_t, khval_t, 1, kh_str_hash_func, kh_str_hash_equal) + +#endif /* __AC_KHASH_H */ diff --git a/Projects/Android/jni/SupportLibs/gl4es/media/minecraft.png b/Projects/Android/jni/SupportLibs/gl4es/media/minecraft.png new file mode 100644 index 0000000..1ba79e0 Binary files /dev/null and b/Projects/Android/jni/SupportLibs/gl4es/media/minecraft.png differ diff --git a/Projects/Android/jni/SupportLibs/gl4es/refs/foobillardplus.0000014748.png b/Projects/Android/jni/SupportLibs/gl4es/refs/foobillardplus.0000014748.png new file mode 100644 index 0000000..8e7dce1 Binary files /dev/null and b/Projects/Android/jni/SupportLibs/gl4es/refs/foobillardplus.0000014748.png differ diff --git a/Projects/Android/jni/SupportLibs/gl4es/refs/glsl_lighting.0000505393.png b/Projects/Android/jni/SupportLibs/gl4es/refs/glsl_lighting.0000505393.png new file mode 100644 index 0000000..b00e8a9 Binary files /dev/null and b/Projects/Android/jni/SupportLibs/gl4es/refs/glsl_lighting.0000505393.png differ diff --git a/Projects/Android/jni/SupportLibs/gl4es/refs/glxgears.0000008203.png b/Projects/Android/jni/SupportLibs/gl4es/refs/glxgears.0000008203.png new file mode 100644 index 0000000..1f2c9e9 Binary files /dev/null and b/Projects/Android/jni/SupportLibs/gl4es/refs/glxgears.0000008203.png differ diff --git a/Projects/Android/jni/SupportLibs/gl4es/refs/neverball.0000078750.png b/Projects/Android/jni/SupportLibs/gl4es/refs/neverball.0000078750.png new file mode 100644 index 0000000..8c93cbc Binary files /dev/null and b/Projects/Android/jni/SupportLibs/gl4es/refs/neverball.0000078750.png differ diff --git a/Projects/Android/jni/SupportLibs/gl4es/refs/openra.0000031249.png b/Projects/Android/jni/SupportLibs/gl4es/refs/openra.0000031249.png new file mode 100644 index 0000000..a4099d8 Binary files /dev/null and b/Projects/Android/jni/SupportLibs/gl4es/refs/openra.0000031249.png differ diff --git a/Projects/Android/jni/SupportLibs/gl4es/refs/pointsprite.0000248810.png b/Projects/Android/jni/SupportLibs/gl4es/refs/pointsprite.0000248810.png new file mode 100644 index 0000000..d27df06 Binary files /dev/null and b/Projects/Android/jni/SupportLibs/gl4es/refs/pointsprite.0000248810.png differ diff --git a/Projects/Android/jni/SupportLibs/gl4es/refs/stuntcarracer.0000118817.png b/Projects/Android/jni/SupportLibs/gl4es/refs/stuntcarracer.0000118817.png new file mode 100644 index 0000000..8295ea0 Binary files /dev/null and b/Projects/Android/jni/SupportLibs/gl4es/refs/stuntcarracer.0000118817.png differ diff --git a/Projects/Android/jni/SupportLibs/gl4es/spec/build b/Projects/Android/jni/SupportLibs/gl4es/spec/build new file mode 100644 index 0000000..766a6b6 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/spec/build @@ -0,0 +1,17 @@ +#!/bin/bash -ux +cd "$(dirname "$0")" + +base=../src/ +if [ -e yml/gles-1.1-full.yml ]; then rm yml/gles-1.1-full.yml ;fi +touch yml/gles-1.1-full.yml +cat yml/*-1.1.yml >> yml/gles-1.1-full.yml +gles1=$(ls -1 yml/*-1.1-full.yml | tr '\n' ',' | sed -e 's/,$//') +gles=$(ls -1 yml/*es-1.1.yml | tr '\n' ',' | sed -e 's/,$//') +glext=$(ls -1 yml/*ext-1.1.yml | tr '\n' ',' | sed -e 's/,$//') + +#./gen.py "$gles" gleswrap.c.j2 gleswrap.c gles.h > "$base/gl/wrap/gles.c" +#./gen.py "$glext" glextwrap.c.j2 glextwrap.c gles.h > "$base/gl/wrap/glesext.c" +./gen.py "$gles1" gleswrap.c.j2 gleswrap.c gles.h ../gl4es.h ../loader.h skips.h > "$base/gl/wrap/gles.c" +./gen.py "$gles1" glwrap.h.j2 gleswrap.h ../gles.h > "$base/gl/wrap/gles.h" +./gen.py "$gles1" glxfuncs.j2 glxfuncs.inc ../gl/gl4es.h > "$base/glx/glesfuncs.inc" + diff --git a/Projects/Android/jni/SupportLibs/gl4es/spec/gen.py b/Projects/Android/jni/SupportLibs/gl4es/spec/gen.py new file mode 100644 index 0000000..5766206 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/spec/gen.py @@ -0,0 +1,166 @@ +#!/usr/bin/env python + +import argparse +import jinja2 +import re +from yaml import load + +split_re = re.compile(r'^(?P.*?)\s*(?P\w+)$') +env = jinja2.Environment( + trim_blocks=True, + lstrip_blocks=True, + loader=jinja2.FileSystemLoader('template'), +) + +def args(args, add_type=True): + return ', '.join( + '{} {}'.format(arg['type'], arg['name']) if add_type else arg['name'] + for arg in args + ) + +f = '0.2f' +printf_lookup = { + 'GLbitfield': 'd', + 'GLboolean': 'd', + 'GLbyte': 'c', + 'GLubyte': 'c', + 'GLchar': 'c', + 'GLdouble': '0.2f', + 'GLenum': 'u', + 'GLfloat': '0.2f', + 'GLint': 'd', + 'GLintptr': 'd', + 'GLintptrARB': 'd', + 'GLshort': 'd', + 'GLsizei': 'd', + 'GLsizeiptr': 'd', + 'GLsizeiptrARB': 'd', + 'GLuint': 'u', + 'GLushort': 'u', + 'GLvoid': 'p', +} + +def printf(args): + types = [] + for arg in args: + typ = arg['type'] + if '*' in typ: + t = 'p' + else: + t = printf_lookup.get(typ, 'p') + + types.append(t) + + return ', '.join('%' + t for t in types) + +def unconst(s): + split = s.split(' ') + while 'const' in split: + split.remove('const') + return ' '.join(split) + +env.filters['args'] = args +env.filters['printf'] = printf +env.filters['unconst'] = unconst + +def split_arg(arg): + match = split_re.match(arg) + if match: + return match.groupdict() + else: + return {'type': 'unknown', 'name': arg} + +def gen(files, template, guard_name, headers, + deep=False, cats=(), ifdef=None, ifndef=None): + funcs = {} + formats = [] + unique_formats = set() + for data in files: + if deep and not isinstance(data.values()[0], list): + functions = [] + for cat, f in data.items(): + if not cats or cat in cats: + functions.extend(f.items()) + else: + functions = data.items() + + for name, args in sorted(functions): + props = {} + if args: + ret = args.pop(0) + else: + ret = 'void' + + loadlib = 'LOAD_GLES' + if name.endswith('_OES_'): + loadlib = 'LOAD_GLES_OES' + name = name[:-5] + + args = [split_arg(arg) for arg in args if not arg == 'void'] + if any(arg.get('type') == 'unknown' for arg in args): + continue + + if args: + args[0]['first'] = True + args[-1]['last'] = True + + for i, arg in enumerate(args): + arg['index'] = i + + types = '_'.join( + arg['type'].replace(' ', '_').replace('*', '__GENPT__') + for arg in [{'type': ret}] + args) + + props.update({ + 'return': ret, + 'name': name, + 'args': args, + 'types': types, + 'void': ret == 'void', + 'loadlib': loadlib, + }) + if not types in unique_formats: + unique_formats.add(types) + formats.append(props) + + funcs[name] = props + + context = { + 'functions': [i[1] for i in sorted(funcs.items())], + 'formats': formats, + 'headers': headers, + 'name': guard_name, + 'ifdef': ifdef, + 'ifndef': ifndef, + } + + t = env.get_template(template) + return t.render(**context).rstrip('\n') + +if __name__ == '__main__': + parser = argparse.ArgumentParser(description='Generate code with yml/jinja.') + parser.add_argument('yaml', help='spec files') + parser.add_argument('template', help='jinja template to load') + parser.add_argument('name', help='header guard name') + parser.add_argument('headers', nargs='*', help='headers to include') + parser.add_argument('--deep', help='nested definitions', action='store_true') + parser.add_argument('--cats', help='deep category filter') + parser.add_argument('--ifdef', help='wrap with ifdef') + parser.add_argument('--ifndef', help='wrap with ifndef') + + args = parser.parse_args() + + files = [] + for name in args.yaml.split(','): + with open(name) as f: + data = load(f) + if data: + files.append(data) + + if args.cats: + cats = args.cats.split(',') + else: + cats = None + print gen(files, args.template, args.name, + args.headers, args.deep, cats, + args.ifdef, args.ifndef) diff --git a/Projects/Android/jni/SupportLibs/gl4es/spec/requirements.txt b/Projects/Android/jni/SupportLibs/gl4es/spec/requirements.txt new file mode 100644 index 0000000..4e859bb --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/spec/requirements.txt @@ -0,0 +1,2 @@ +jinja2 +pyyaml diff --git a/Projects/Android/jni/SupportLibs/gl4es/spec/template/base/base.j2 b/Projects/Android/jni/SupportLibs/gl4es/spec/template/base/base.j2 new file mode 100644 index 0000000..6d47950 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/spec/template/base/base.j2 @@ -0,0 +1,8 @@ +{% if ifdef %}#ifdef {{ ifdef }} +{% endif %} +{% if ifndef %}#ifndef {{ ifndef }} +{% endif %} +{% block main %}{% endblock %} +{% block content %}{% endblock %} +{% if ifdef %}#endif{% endif %} +{% if ifndef %}#endif{% endif %} diff --git a/Projects/Android/jni/SupportLibs/gl4es/spec/template/base/copy_packed_call.j2 b/Projects/Android/jni/SupportLibs/gl4es/spec/template/base/copy_packed_call.j2 new file mode 100644 index 0000000..f48d4ca --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/spec/template/base/copy_packed_call.j2 @@ -0,0 +1,13 @@ +packed_call_t* glCopyPackedCall(const packed_call_t *packed) { + switch (packed->format) { + {% for f in formats %} + case FORMAT_{{ f.types }}: { + int sizeofpacked = sizeof(PACKED_{{ f.types }}); + PACKED_{{ f.types }} *newpacked = (PACKED_{{ f.types }}*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + {% endfor %} + } +} diff --git a/Projects/Android/jni/SupportLibs/gl4es/spec/template/base/fprint.j2 b/Projects/Android/jni/SupportLibs/gl4es/spec/template/base/fprint.j2 new file mode 100644 index 0000000..31c0ae0 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/spec/template/base/fprint.j2 @@ -0,0 +1,5 @@ +{% if func.args %} + printf("{{ func.name }}({{ func.args|printf }});\n", {{ func.args|args(0) }}); +{% else %} + printf("{{ func.name }}();\n"); +{% endif %} diff --git a/Projects/Android/jni/SupportLibs/gl4es/spec/template/base/header.j2 b/Projects/Android/jni/SupportLibs/gl4es/spec/template/base/header.j2 new file mode 100644 index 0000000..ad752e9 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/spec/template/base/header.j2 @@ -0,0 +1,10 @@ +{% extends "base/base.j2" %} +{% block main %} +{% include "base/headers.j2" %} + +{% set guard = name.upper().replace('.', '_') -%} +#ifndef {{ guard }} +#define {{ guard }} +{% block content %}{% endblock %} +#endif +{% endblock %} diff --git a/Projects/Android/jni/SupportLibs/gl4es/spec/template/base/headers.j2 b/Projects/Android/jni/SupportLibs/gl4es/spec/template/base/headers.j2 new file mode 100644 index 0000000..ffb85a5 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/spec/template/base/headers.j2 @@ -0,0 +1,9 @@ +{% block headers %} +{% for header in headers %} +{% if "<" in header %} +#include {{ header }} +{% else %} +#include "{{ header }}" +{% endif %} +{% endfor %} +{% endblock %} diff --git a/Projects/Android/jni/SupportLibs/gl4es/spec/template/base/indexed_call.j2 b/Projects/Android/jni/SupportLibs/gl4es/spec/template/base/indexed_call.j2 new file mode 100644 index 0000000..0a6c6f2 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/spec/template/base/indexed_call.j2 @@ -0,0 +1,22 @@ +void glIndexedCall(const indexed_call_t *packed, void *ret_v) { + switch (packed->func) { + {% for f in functions %} + #ifndef skip_index_{{ f.name }} + case {{ f.name }}_INDEX: { + INDEXED_{{ f.types }} *unpacked = (INDEXED_{{ f.types }} *)packed; + {% if f.args %} + ARGS_{{ f.types }} args = unpacked->args; + {% endif %} + {% if not f.void %} + {{ f.return }} *ret = ({{ f.return }} *)ret_v; + *ret = + {% endif %} + {{ f.name }}({% for arg in f.args -%} + args.a{{ loop.index }}{% if not arg.last %}, {% endif %} + {% endfor %}); + break; + } + #endif + {% endfor %} + } +} diff --git a/Projects/Android/jni/SupportLibs/gl4es/spec/template/base/packed_call.j2 b/Projects/Android/jni/SupportLibs/gl4es/spec/template/base/packed_call.j2 new file mode 100644 index 0000000..eadbfb1 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/spec/template/base/packed_call.j2 @@ -0,0 +1,16 @@ +void glPackedCall(const packed_call_t *packed) { + switch (packed->format) { + {% for f in formats %} + case FORMAT_{{ f.types }}: { + PACKED_{{ f.types }} *unpacked = (PACKED_{{ f.types }} *)packed; + {% if f.args %} + ARGS_{{ f.types }} args = unpacked->args; + {% endif %} + unpacked->func({% for arg in f.args -%} + args.a{{ loop.index }}{% if not arg.last %}, {% endif %} + {% endfor %}); + break; + } + {% endfor %} + } +} diff --git a/Projects/Android/jni/SupportLibs/gl4es/spec/template/base/wrap.c.j2 b/Projects/Android/jni/SupportLibs/gl4es/spec/template/base/wrap.c.j2 new file mode 100644 index 0000000..a87b888 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/spec/template/base/wrap.c.j2 @@ -0,0 +1,15 @@ +{% extends "base/base.j2" %} +{% block main %} +{% include "base/headers.j2" %} +{% for func in functions %} +{% block definition scoped %} +{{ func.return }} gl4es_{{ func.name }}({{ func.args|args }}) { + {% block load scoped %}{% endblock %} + {% block call scoped %} + {% if not func.void %}return {% endif %}{% block prefix %}wrap{% endblock %}_{{ func.name }}({{ func.args|args(0) }}); + {%- endblock %} +} +{{ func.return }} {{ func.name }}({{ func.args|args }}) __attribute__((alias("gl4es_{{ func.name }}"))) __attribute__((visibility("default"))); +{% endblock %} +{% endfor %} +{% endblock %} diff --git a/Projects/Android/jni/SupportLibs/gl4es/spec/template/base/wrap.h.j2 b/Projects/Android/jni/SupportLibs/gl4es/spec/template/base/wrap.h.j2 new file mode 100644 index 0000000..9f5887f --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/spec/template/base/wrap.h.j2 @@ -0,0 +1,65 @@ +{% extends "base/header.j2" %} +{% block content %} + +typedef struct { + int format; + void *func; + void *args; +} packed_call_t; + +typedef struct { + int func; + void *args; +} indexed_call_t; + +enum FORMAT { +{% for f in formats %} + FORMAT_{{ f.types }}, +{% endfor %} +}; + +{% for f in formats %} +typedef {{ f.return }} (*FUNC_{{ f.types }})({{ f.args|args }}); +{% if f.args %} +typedef struct { + {% for arg in f.args %} + {{ arg.type|unconst }} a{{ loop.index }}{% if arg.type == 'GLdouble' %} __attribute__ ((aligned(8))){% endif %}; + {% endfor %} +} ARGS_{{ f.types }}; +{% endif %} +typedef struct { + int format; + FUNC_{{ f.types }} func; + {% if f.args %} + ARGS_{{ f.types }} args; + {% endif %} +} PACKED_{{ f.types }}; +typedef struct { + int func; + {% if f.args %} + ARGS_{{ f.types }} args; + {% endif %} +} INDEXED_{{ f.types }}; +{% endfor %} + +extern void glPushCall(void *data); +void glPackedCall(const packed_call_t *packed); +void glIndexedCall(const indexed_call_t *packed, void *ret_v); +packed_call_t* glCopyPackedCall(const packed_call_t *packed); + +{% for func in functions %} +#define {{ func.name }}_INDEX {{ loop.index }} +#define {{ func.name }}_RETURN {{ func.return }} +#define {{ func.name }}_ARG_NAMES {{ func.args|args(0) }} +#define {{ func.name }}_ARG_EXPAND {{ func.args|args }} +#define {{ func.name }}_PACKED PACKED_{{ func.types }} +#define {{ func.name }}_INDEXED INDEXED_{{ func.types }} +#define {{ func.name }}_FORMAT FORMAT_{{ func.types }} +{% endfor %} + +{% for func in functions %} +{{ func.return }} gl4es_{{ func.name }}({{ func.name }}_ARG_EXPAND); +typedef {{ func.return }} (*{{ func.name }}_PTR)({{ func.name }}_ARG_EXPAND); +{% endfor %} + +{% endblock %} diff --git a/Projects/Android/jni/SupportLibs/gl4es/spec/template/client.c.j2 b/Projects/Android/jni/SupportLibs/gl4es/spec/template/client.c.j2 new file mode 100644 index 0000000..9ed9111 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/spec/template/client.c.j2 @@ -0,0 +1,52 @@ +{% extends "base/wrap.c.j2" %} +{% block headers %} +#include +#include +#include +#include +{{ super() }} + +{% endblock %} + +{% block main %} +{{ super() }} + +snd_config_t *snd_config = NULL; + +__GLXextFuncPtr glXGetProcAddressARB(const GLubyte *name) { + {% for func in functions %} + {% if not func.name.startswith('snd_') %} + if (strcmp(name, "{{ func.name }}") == 0) { + return (void *){{ func.name }}; + } + {% endif %} + {% endfor %} + printf("glXGetProcAddress(%s) not found\n", name); + return NULL; +} + +__GLXextFuncPtr glXGetProcAddress(const GLubyte *name) { + return glXGetProcAddressARB(name); +} +{% endblock %} + +{% block definition %} +#if !defined(skip_client_{{ func.name }}) && !defined(skip_index_{{ func.name }}) +{{ super() -}} +#endif +{% endblock %} + +{% block call %} + {{ func.name }}_INDEXED packed_data; + packed_data.func = {{ func.name }}_INDEX; + {% for arg in func.args %} + packed_data.args.a{{ loop.index }} = ({{ arg.type|unconst }}){{ arg.name }}; + {% endfor %} + {% if not func.void %} + {{ func.return }} ret; + syscall(SYS_proxy, (void *)&packed_data, &ret); + return ret; + {% else %} + syscall(SYS_proxy, (void *)&packed_data, NULL); + {% endif %} +{% endblock %} diff --git a/Projects/Android/jni/SupportLibs/gl4es/spec/template/eglwrap.c.j2 b/Projects/Android/jni/SupportLibs/gl4es/spec/template/eglwrap.c.j2 new file mode 100644 index 0000000..1bacb85 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/spec/template/eglwrap.c.j2 @@ -0,0 +1,23 @@ +{% extends "base/wrap.c.j2" %} +{% block headers %} +{{ super() }} +void *egl_lib; +#define WARN_NULL(name) if (name == NULL) printf("LIBGL: warning, " #name " is NULL\n"); +#define LOAD_EGL(type, name, args...) \ + typedef type (*eglptr_##name)(args); \ + static eglptr_##name egl_##name; \ + if (egl##name == NULL) { \ + if (egl_lib == NULL) { \ + egl_lib = dlopen("libEGL.so", RTLD_LOCAL | RTLD_LAZY); \ + WARN_NULL(egl_lib); \ + } \ + egl_##name = (eglptr_##name)dlsym(egl_lib, #name); \ + WARN_NULL(egl_lib_##name); \ + } \ +{% endblock %} + +{% block load %} + LOAD_EGL({{ func.return }}, {{ func.name }} + {%- if func.args %}, {{ func.args|args }}{% endif %}); +{% endblock %} +{% block prefix %}egl{% endblock %} diff --git a/Projects/Android/jni/SupportLibs/gl4es/spec/template/gleswrap.c.j2 b/Projects/Android/jni/SupportLibs/gl4es/spec/template/gleswrap.c.j2 new file mode 100644 index 0000000..b9a1d52 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/spec/template/gleswrap.c.j2 @@ -0,0 +1,29 @@ +{% extends "base/wrap.c.j2" %} +{% block headers %} +{{ super() }} + +{% endblock %} +{% block content %} +{% include "base/packed_call.j2" %} + +/* +{% include "base/copy_packed_call.j2" %} +*/ + +{% endblock %} + +{% block definition %} +#ifndef skip_{{ func.name }} +{{ super() -}} +#endif +{% endblock %} +{% block load %} + {{ func.loadlib }}({{ func.name }}); +{% endblock %} +{% block call %} +#ifndef direct_{{ func.name }} + PUSH_IF_COMPILING({{ func.name }}) +#endif + {{ super() }} +{% endblock %} +{% block prefix %}gles{% endblock %} diff --git a/Projects/Android/jni/SupportLibs/gl4es/spec/template/glextwrap.c.j2 b/Projects/Android/jni/SupportLibs/gl4es/spec/template/glextwrap.c.j2 new file mode 100644 index 0000000..6f01c3e --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/spec/template/glextwrap.c.j2 @@ -0,0 +1,20 @@ +{% extends "base/wrap.c.j2" %} +{% block headers %} +{{ super() }} + +{% endblock %} +{% block definition %} +#ifndef skip_{{ func.name }} +{{ super() -}} +#endif +{% endblock %} +{% block load %} + {{ func.loadlib }}({{ func.name }}); +{% endblock %} +{% block call %} +#ifndef direct_{{ func.name }} + PUSH_IF_COMPILING({{ func.name }}) +#endif + {{ super() }} +{% endblock %} +{% block prefix %}gles{% endblock %} diff --git a/Projects/Android/jni/SupportLibs/gl4es/spec/template/glwrap.h.j2 b/Projects/Android/jni/SupportLibs/gl4es/spec/template/glwrap.h.j2 new file mode 100644 index 0000000..a892e0c --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/spec/template/glwrap.h.j2 @@ -0,0 +1,20 @@ +{% extends "base/wrap.h.j2" %} +{% block content %} +{{ super() }} + +{% for func in functions %} +#ifndef direct_{{ func.name }} +#define push_{{ func.name }}({{ func.args|args(0) }}) { \ + {{ func.name }}_PACKED *packed_data = malloc(sizeof({{ func.name }}_PACKED)); \ + packed_data->format = {{ func.name }}_FORMAT; \ + packed_data->func = gl4es_{{ func.name }}; \ + {% if func.args %} + {% for arg in func.args %} + packed_data->args.a{{ loop.index }} = ({{ arg.type|unconst }}){{ arg.name }}; \ + {% endfor %} + {% endif %} + glPushCall((void *)packed_data); \ +} +#endif +{% endfor %} +{% endblock %} \ No newline at end of file diff --git a/Projects/Android/jni/SupportLibs/gl4es/spec/template/glxfuncs.j2 b/Projects/Android/jni/SupportLibs/gl4es/spec/template/glxfuncs.j2 new file mode 100644 index 0000000..7fc6072 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/spec/template/glxfuncs.j2 @@ -0,0 +1,3 @@ +{% for func in functions %} +_EX({{ func.name }}); +{% endfor %} diff --git a/Projects/Android/jni/SupportLibs/gl4es/spec/template/host.c.j2 b/Projects/Android/jni/SupportLibs/gl4es/spec/template/host.c.j2 new file mode 100644 index 0000000..38c1133 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/spec/template/host.c.j2 @@ -0,0 +1,6 @@ +{% extends "base/header.j2" %} + +{% block content %} +{% include "base/indexed_call.j2" %} + +{% endblock %} diff --git a/Projects/Android/jni/SupportLibs/gl4es/spec/template/proxy.h.j2 b/Projects/Android/jni/SupportLibs/gl4es/spec/template/proxy.h.j2 new file mode 100644 index 0000000..ff9f7e8 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/spec/template/proxy.h.j2 @@ -0,0 +1 @@ +{% extends "base/wrap.h.j2" %} diff --git a/Projects/Android/jni/SupportLibs/gl4es/spec/xml/toyml.py b/Projects/Android/jni/SupportLibs/gl4es/spec/xml/toyml.py new file mode 100644 index 0000000..179b816 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/spec/xml/toyml.py @@ -0,0 +1,112 @@ +#!/usr/bin/env python +from collections import defaultdict +import re +import xml.etree.ElementTree as ET +import yaml + + +def etna_to_yml(xml): + defs = xml.find('functions') + functions = defaultdict(dict) + for f in defs.findall('function'): + name = f.get('name') + ret = f.find('return') + if ret is not None: + ret = ret.get('type') + if ret is None: + ret = 'void' + + params = [] + for p in f.findall('param'): + params.append('{} {}'.format(p.get('type'), p.get('name'))) + + functions[name] = [ret] + params + + return functions + + +def lua_to_yml(xml): + typemap = xml.find('typemap') + types = {} + for t in typemap: + name = t.get('typename') + types[name] = t.get('C-lang', name) + + defs = xml.find('functions').find('function-defs') + functions = defaultdict(dict) + for f in defs.findall('function'): + cat = f.get('category') + ret = f.get('return') + ret = types.get(ret, ret) + func = f.get('name') + + params = [] + for param in f.findall('param'): + typ = param.get('type') + typ = types.get(typ, typ) + name = param.get('name') + kind = param.get('kind') + if kind in ('array', 'reference', 'array[size]'): + typ = typ.rstrip() + if not typ.endswith('*') or kind == 'reference': + typ += ' *' + if not 'const' in typ and param.get('input', 'false') == 'true': + typ = 'const ' + typ + p = '{} {}'.format(typ, name) + p = p.replace('* ', '*') + params.append(p) + + args = [ret] + args.extend(params) + functions[cat][func] = args + return functions + + +def khronos_to_yml(xml): + def extract(node): + return node.findtext('ptype') or node.text, node.findtext('name') + + def clean(s): + return re.sub('\s+', ' ', s).strip() + + defs = xml.find('commands') + functions = defaultdict(dict) + for f in defs.findall('command'): + proto = f.find('proto') + ret, name = extract(proto) + params = [] + for param in f.findall('param'): + params.append(clean(' '.join((param.itertext())))) + + functions[name] = [ret] + params + return functions + + +def to_yml(filename): + with open(filename, 'r') as f: + data = f.read() + + data = re.sub(' xmlns="[^"]+"', '', data, count=1) + xml = ET.fromstring(data) + + if xml.tag == 'root': + functions = etna_to_yml(xml) + elif xml.tag == 'specification': + functions = lua_to_yml(xml) + elif xml.tag == 'registry': + functions = khronos_to_yml(xml) + else: + print 'unrecognized root tag:', xml.tag + + yml = yaml.dump(dict(functions)) + with open(filename.replace('xml', 'yml'), 'w') as o: + o.write(yml) + +if __name__ == '__main__': + import sys + if len(sys.argv) < 2: + print 'Usage: {} [file.xml...]'.format(sys.argv[0]) + sys.exit(1) + + for name in sys.argv[1:]: + to_yml(name) diff --git a/Projects/Android/jni/SupportLibs/gl4es/spec/yml/alsa.yml b/Projects/Android/jni/SupportLibs/gl4es/spec/yml/alsa.yml new file mode 100644 index 0000000..d94b6f1 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/spec/yml/alsa.yml @@ -0,0 +1,1229 @@ +snd_asoundlib_version: [const char *] +# note: dlsym/dlopen need to be implemented in the client proxy lib +snd_dlopen: [void *, const char *file, int mode] +snd_dlsym: [void *, void *handle, const char *name, const char *version] +snd_dlclose: [int, void *handle] + +# global.h +# callback functions won't work :( +snd_async_add_handler: [int, snd_async_handler_t **handler, int fd, snd_async_callback_t callback, void *private_data] +snd_async_del_handler: [int, snd_async_handler_t *handler] +snd_async_handler_get_fd: [int, snd_async_handler_t *handler] +snd_async_handler_get_signo: [int, snd_async_handler_t *handler] +snd_async_handler_get_callback_private: [void *, snd_async_handler_t *handler] +snd_shm_area_create: [struct snd_shm_area *, int shmid, void *ptr] +snd_shm_area_share: [struct snd_shm_area *, struct snd_shm_area *area] +snd_shm_area_destroy: [int, struct snd_shm_area *area] +snd_user_file: [int, const char *file, char **result] + +# input.h +snd_input_stdio_open: [int, snd_input_t **inputp, const char *file, const char *mode] +snd_input_stdio_attach: [int, snd_input_t **inputp, FILE *fp, int _close] +snd_input_buffer_open: [int, snd_input_t **inputp, const char *buffer, ssize_t size] +snd_input_close: [int, snd_input_t *input] +snd_input_scanf: [int, snd_input_t *input, const char *format, ...] +snd_input_gets: [char *, snd_input_t *input, char *str, size_t size] +snd_input_getc: [int, snd_input_t *input] +snd_input_ungetc: [int, snd_input_t *input, int c] + +# output.h +snd_output_stdio_open: [int, snd_output_t **outputp, const char *file, const char *mode] +snd_output_stdio_attach: [int, snd_output_t **outputp, FILE *fp, int _close] +snd_output_buffer_open: [int, snd_output_t **outputp] +snd_output_buffer_string: [size_t, snd_output_t *output, char **buf] +snd_output_close: [int, snd_output_t *output] +snd_output_printf: [int, snd_output_t *output, const char *format, ...] +snd_output_vprintf: [int, snd_output_t *output, const char *format, va_list args] +snd_output_puts: [int, snd_output_t *output, const char *str] +snd_output_putc: [int, snd_output_t *output, int c] +snd_output_flush: [int, snd_output_t *output] + +# error.h +snd_strerror: [const char *, int errnum] +# callback-based functions won't work +snd_lib_error_set_handler: [int, snd_lib_error_handler_t handler] + +# conf.h +snd_config_top: [int, snd_config_t **config] +snd_config_load: [int, snd_config_t *config, snd_input_t *in] +snd_config_load_override: [int, snd_config_t *config, snd_input_t *in] +snd_config_save: [int, snd_config_t *config, snd_output_t *out] +snd_config_update: [int] +snd_config_update_r: [int, snd_config_t **top, snd_config_update_t **update, const char *path] +snd_config_update_free: [int, snd_config_update_t *update] +snd_config_update_free_global: [int] +snd_config_search: [int, snd_config_t *config, const char *key, snd_config_t **result] +snd_config_searchv: [int, snd_config_t *config, snd_config_t **result, ...] +snd_config_search_definition: [int, snd_config_t *config, const char *base, const char *key, snd_config_t **result] +snd_config_expand: [int, snd_config_t *config, snd_config_t *root, const char *args, snd_config_t *private_data, snd_config_t **result] +snd_config_evaluate: [int, snd_config_t *config, snd_config_t *root, snd_config_t *private_data, snd_config_t **result] +snd_config_add: [int, snd_config_t *config, snd_config_t *leaf] +snd_config_delete: [int, snd_config_t *config] +snd_config_delete_compound_members: [int, const snd_config_t *config] +snd_config_copy: [int, snd_config_t **dst, snd_config_t *src] +snd_config_make: [int, snd_config_t **config, const char *key, snd_config_type_t type] +snd_config_make_integer: [int, snd_config_t **config, const char *key] +snd_config_make_integer64: [int, snd_config_t **config, const char *key] +snd_config_make_real: [int, snd_config_t **config, const char *key] +snd_config_make_string: [int, snd_config_t **config, const char *key] +snd_config_make_pointer: [int, snd_config_t **config, const char *key] +snd_config_make_compound: [int, snd_config_t **config, const char *key, int join] +snd_config_imake_integer: [int, snd_config_t **config, const char *key, const long value] +snd_config_imake_integer64: [int, snd_config_t **config, const char *key, const long long value] +snd_config_imake_real: [int, snd_config_t **config, const char *key, const double value] +snd_config_imake_string: [int, snd_config_t **config, const char *key, const char *ascii] +snd_config_imake_pointer: [int, snd_config_t **config, const char *key, const void *ptr] +snd_config_get_type: [snd_config_type_t, const snd_config_t *config] +snd_config_set_id: [int, snd_config_t *config, const char *id] +snd_config_set_integer: [int, snd_config_t *config, long value] +snd_config_set_integer64: [int, snd_config_t *config, long long value] +snd_config_set_real: [int, snd_config_t *config, double value] +snd_config_set_string: [int, snd_config_t *config, const char *value] +snd_config_set_ascii: [int, snd_config_t *config, const char *ascii] +snd_config_set_pointer: [int, snd_config_t *config, const void *ptr] +snd_config_get_id: [int, const snd_config_t *config, const char **value] +snd_config_get_integer: [int, const snd_config_t *config, long *value] +snd_config_get_integer64: [int, const snd_config_t *config, long long *value] +snd_config_get_real: [int, const snd_config_t *config, double *value] +snd_config_get_ireal: [int, const snd_config_t *config, double *value] +snd_config_get_string: [int, const snd_config_t *config, const char **value] +snd_config_get_ascii: [int, const snd_config_t *config, char **value] +snd_config_get_pointer: [int, const snd_config_t *config, const void **value] +snd_config_test_id: [int, const snd_config_t *config, const char *id] +snd_config_iterator_first: [snd_config_iterator_t, const snd_config_t *node] +snd_config_iterator_next: [snd_config_iterator_t, const snd_config_iterator_t iterator] +snd_config_iterator_end: [snd_config_iterator_t, const snd_config_t *node] +snd_config_iterator_entry: [snd_config_t *, const snd_config_iterator_t iterator] +snd_config_get_bool_ascii: [int, const char *ascii] +snd_config_get_bool: [int, const snd_config_t *conf] +snd_config_get_ctl_iface_ascii: [int, const char *ascii] +snd_config_get_ctl_iface: [int, const snd_config_t *conf] +snd_names_list: [int, const char *iface, snd_devname_t **list] +snd_names_list_free: [void, snd_devname_t *list] + +# pcm.h +snd_pcm_format_mask_sizeof: [size_t] +snd_pcm_subformat_mask_sizeof: [size_t] +snd_pcm_status_sizeof: [size_t] +snd_async_add_pcm_handler: [int, snd_async_handler_t **handler, snd_pcm_t *pcm, snd_async_callback_t callback, void *private_data] +snd_async_handler_get_pcm: [snd_pcm_t *, snd_async_handler_t *handler] +snd_pcm_access_mask_any: [void, snd_pcm_access_mask_t *mask] +snd_pcm_access_mask_copy: [void, snd_pcm_access_mask_t *dst, const snd_pcm_access_mask_t *src] +snd_pcm_access_mask_empty: [int, const snd_pcm_access_mask_t *mask] +snd_pcm_access_mask_free: [void, snd_pcm_access_mask_t *obj] +snd_pcm_access_mask_malloc: [int, snd_pcm_access_mask_t **ptr] +snd_pcm_access_mask_none: [void, snd_pcm_access_mask_t *mask] +snd_pcm_access_mask_reset: [void, snd_pcm_access_mask_t *mask, snd_pcm_access_t val] +snd_pcm_access_mask_set: [void, snd_pcm_access_mask_t *mask, snd_pcm_access_t val] +snd_pcm_access_mask_test: [int, const snd_pcm_access_mask_t *mask, snd_pcm_access_t val] +snd_pcm_access_name: [const char *, const snd_pcm_access_t _access] +snd_pcm_area_copy: [int, const snd_pcm_channel_area_t *dst_channel, snd_pcm_uframes_t dst_offset, const snd_pcm_channel_area_t *src_channel, snd_pcm_uframes_t src_offset, unsigned int samples, snd_pcm_format_t format] +snd_pcm_area_silence: [int, const snd_pcm_channel_area_t *dst_channel, snd_pcm_uframes_t dst_offset, unsigned int samples, snd_pcm_format_t format] +snd_pcm_areas_copy: [int, const snd_pcm_channel_area_t *dst_channels, snd_pcm_uframes_t dst_offset, const snd_pcm_channel_area_t *src_channels, snd_pcm_uframes_t src_offset, unsigned int channels, snd_pcm_uframes_t frames, snd_pcm_format_t format] +snd_pcm_areas_silence: [int, const snd_pcm_channel_area_t *dst_channels, snd_pcm_uframes_t dst_offset, unsigned int channels, snd_pcm_uframes_t frames, snd_pcm_format_t format] +snd_pcm_avail_update: [snd_pcm_sframes_t, snd_pcm_t *pcm] +snd_pcm_build_linear_format: [snd_pcm_format_t, int width, int pwidth, int unsignd, int big_endian] +snd_pcm_bytes_to_frames: [snd_pcm_sframes_t, snd_pcm_t *pcm, ssize_t bytes] +snd_pcm_bytes_to_samples: [long, snd_pcm_t *pcm, ssize_t bytes] +snd_pcm_close: [int, snd_pcm_t *pcm] +snd_pcm_delay: [int, snd_pcm_t *pcm, snd_pcm_sframes_t *delayp] +snd_pcm_drain: [int, snd_pcm_t *pcm] +snd_pcm_drop: [int, snd_pcm_t *pcm] +snd_pcm_dump: [int, snd_pcm_t *pcm, snd_output_t *out] +snd_pcm_dump_hw_setup: [int, snd_pcm_t *pcm, snd_output_t *out] +snd_pcm_dump_setup: [int, snd_pcm_t *pcm, snd_output_t *out] +snd_pcm_dump_sw_setup: [int, snd_pcm_t *pcm, snd_output_t *out] +snd_pcm_format_big_endian: [int, snd_pcm_format_t format] +snd_pcm_format_cpu_endian: [int, snd_pcm_format_t format] +snd_pcm_format_description: [const char *, const snd_pcm_format_t format] +snd_pcm_format_float: [int, snd_pcm_format_t format] +snd_pcm_format_linear: [int, snd_pcm_format_t format] +snd_pcm_format_little_endian: [int, snd_pcm_format_t format] +snd_pcm_format_mask_any: [void, snd_pcm_format_mask_t *mask] +snd_pcm_format_mask_copy: [void, snd_pcm_format_mask_t *dst, const snd_pcm_format_mask_t *src] +snd_pcm_format_mask_empty: [int, const snd_pcm_format_mask_t *mask] +snd_pcm_format_mask_free: [void, snd_pcm_format_mask_t *obj] +snd_pcm_format_mask_malloc: [int, snd_pcm_format_mask_t **ptr] +snd_pcm_format_mask_none: [void, snd_pcm_format_mask_t *mask] +snd_pcm_format_mask_reset: [void, snd_pcm_format_mask_t *mask, snd_pcm_format_t val] +snd_pcm_format_mask_set: [void, snd_pcm_format_mask_t *mask, snd_pcm_format_t val] +snd_pcm_format_mask_test: [int, const snd_pcm_format_mask_t *mask, snd_pcm_format_t val] +snd_pcm_format_name: [const char *, const snd_pcm_format_t format] +snd_pcm_format_physical_width: [int, snd_pcm_format_t format] +snd_pcm_format_set_silence: [int, snd_pcm_format_t format, void *buf, unsigned int samples] +snd_pcm_format_signed: [int, snd_pcm_format_t format] +snd_pcm_format_silence: [u_int8_t, snd_pcm_format_t format] +snd_pcm_format_silence_16: [u_int16_t, snd_pcm_format_t format] +snd_pcm_format_silence_32: [u_int32_t, snd_pcm_format_t format] +snd_pcm_format_silence_64: [u_int64_t, snd_pcm_format_t format] +snd_pcm_format_size: [ssize_t, snd_pcm_format_t format, size_t samples] +snd_pcm_format_unsigned: [int, snd_pcm_format_t format] +snd_pcm_format_value: [snd_pcm_format_t, const char* name] +snd_pcm_format_width: [int, snd_pcm_format_t format] +snd_pcm_forward: [snd_pcm_sframes_t, snd_pcm_t *pcm, snd_pcm_uframes_t frames] +snd_pcm_frames_to_bytes: [ssize_t, snd_pcm_t *pcm, snd_pcm_sframes_t frames] +snd_pcm_get_params: [int, snd_pcm_t *pcm, snd_pcm_uframes_t *buffer_size, snd_pcm_uframes_t *period_size] +snd_pcm_hook_add: [int, snd_pcm_hook_t **hookp, snd_pcm_t *pcm, snd_pcm_hook_type_t type, snd_pcm_hook_func_t func, void *private_data] +snd_pcm_hook_get_pcm: [snd_pcm_t *, snd_pcm_hook_t *hook] +snd_pcm_hook_get_private: [void *, snd_pcm_hook_t *hook] +snd_pcm_hook_remove: [int, snd_pcm_hook_t *hook] +snd_pcm_hook_set_private: [void, snd_pcm_hook_t *hook, void *private_data] +snd_pcm_hw_free: [int, snd_pcm_t *pcm] +snd_pcm_hw_params: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params] +snd_pcm_hw_params_any: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params] +snd_pcm_hw_params_can_mmap_sample_resolution: [int, const snd_pcm_hw_params_t *params] +snd_pcm_hw_params_can_overrange: [int, const snd_pcm_hw_params_t *params] +snd_pcm_hw_params_can_pause: [int, const snd_pcm_hw_params_t *params] +snd_pcm_hw_params_can_resume: [int, const snd_pcm_hw_params_t *params] +snd_pcm_hw_params_can_sync_start: [int, const snd_pcm_hw_params_t *params] +snd_pcm_hw_params_copy: [void, snd_pcm_hw_params_t *dst, const snd_pcm_hw_params_t *src] +snd_pcm_hw_params_current: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params] +snd_pcm_hw_params_dump: [int, snd_pcm_hw_params_t *params, snd_output_t *out] +snd_pcm_hw_params_free: [void, snd_pcm_hw_params_t *obj] +snd_pcm_hw_params_get_access: [int, const snd_pcm_hw_params_t *params, snd_pcm_access_t *_access] +snd_pcm_hw_params_get_access_mask: [int, snd_pcm_hw_params_t *params, snd_pcm_access_mask_t *mask] +snd_pcm_hw_params_get_buffer_size: [int, const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val] +snd_pcm_hw_params_get_buffer_size_max: [int, const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val] +snd_pcm_hw_params_get_buffer_size_min: [int, const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val] +snd_pcm_hw_params_get_buffer_time: [int, const snd_pcm_hw_params_t *params, unsigned int *val, int *dir] +snd_pcm_hw_params_get_buffer_time_max: [int, const snd_pcm_hw_params_t *params, unsigned int *val, int *dir] +snd_pcm_hw_params_get_buffer_time_min: [int, const snd_pcm_hw_params_t *params, unsigned int *val, int *dir] +snd_pcm_hw_params_get_channels: [int, const snd_pcm_hw_params_t *params, unsigned int *val] +snd_pcm_hw_params_get_channels_max: [int, const snd_pcm_hw_params_t *params, unsigned int *val] +snd_pcm_hw_params_get_channels_min: [int, const snd_pcm_hw_params_t *params, unsigned int *val] +snd_pcm_hw_params_get_export_buffer: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val] +snd_pcm_hw_params_get_fifo_size: [int, const snd_pcm_hw_params_t *params] +snd_pcm_hw_params_get_format: [int, const snd_pcm_hw_params_t *params, snd_pcm_format_t *val] +snd_pcm_hw_params_get_format_mask: [void, snd_pcm_hw_params_t *params, snd_pcm_format_mask_t *mask] +snd_pcm_hw_params_get_min_align: [int, const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val] +snd_pcm_hw_params_get_period_size: [int, const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *frames, int *dir] +snd_pcm_hw_params_get_period_size_max: [int, const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *frames, int *dir] +snd_pcm_hw_params_get_period_size_min: [int, const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *frames, int *dir] +snd_pcm_hw_params_get_period_time: [int, const snd_pcm_hw_params_t *params, unsigned int *val, int *dir] +snd_pcm_hw_params_get_period_time_max: [int, const snd_pcm_hw_params_t *params, unsigned int *val, int *dir] +snd_pcm_hw_params_get_period_time_min: [int, const snd_pcm_hw_params_t *params, unsigned int *val, int *dir] +snd_pcm_hw_params_get_periods: [int, const snd_pcm_hw_params_t *params, unsigned int *val, int *dir] +snd_pcm_hw_params_get_periods_max: [int, const snd_pcm_hw_params_t *params, unsigned int *val, int *dir] +snd_pcm_hw_params_get_periods_min: [int, const snd_pcm_hw_params_t *params, unsigned int *val, int *dir] +snd_pcm_hw_params_get_rate: [int, const snd_pcm_hw_params_t *params, unsigned int *val, int *dir] +snd_pcm_hw_params_get_rate_max: [int, const snd_pcm_hw_params_t *params, unsigned int *val, int *dir] +snd_pcm_hw_params_get_rate_min: [int, const snd_pcm_hw_params_t *params, unsigned int *val, int *dir] +snd_pcm_hw_params_get_rate_numden: [int, const snd_pcm_hw_params_t *params, unsigned int *rate_num, unsigned int *rate_den] +snd_pcm_hw_params_get_rate_resample: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val] +snd_pcm_hw_params_get_sbits: [int, const snd_pcm_hw_params_t *params] +snd_pcm_hw_params_get_subformat: [int, const snd_pcm_hw_params_t *params, snd_pcm_subformat_t *subformat] +snd_pcm_hw_params_get_subformat_mask: [void, snd_pcm_hw_params_t *params, snd_pcm_subformat_mask_t *mask] +snd_pcm_hw_params_get_tick_time: [int, const snd_pcm_hw_params_t *params, unsigned int *val, int *dir] +snd_pcm_hw_params_get_tick_time_max: [int, const snd_pcm_hw_params_t *params, unsigned int *val, int *dir] +snd_pcm_hw_params_get_tick_time_min: [int, const snd_pcm_hw_params_t *params, unsigned int *val, int *dir] +snd_pcm_hw_params_is_batch: [int, const snd_pcm_hw_params_t *params] +snd_pcm_hw_params_is_block_transfer: [int, const snd_pcm_hw_params_t *params] +snd_pcm_hw_params_is_double: [int, const snd_pcm_hw_params_t *params] +snd_pcm_hw_params_is_half_duplex: [int, const snd_pcm_hw_params_t *params] +snd_pcm_hw_params_is_joint_duplex: [int, const snd_pcm_hw_params_t *params] +snd_pcm_hw_params_malloc: [int, snd_pcm_hw_params_t **ptr] +snd_pcm_hw_params_set_access: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_access_t _access] +snd_pcm_hw_params_set_access_first: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_access_t *_access] +snd_pcm_hw_params_set_access_last: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_access_t *_access] +snd_pcm_hw_params_set_access_mask: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_access_mask_t *mask] +snd_pcm_hw_params_set_buffer_size: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t val] +snd_pcm_hw_params_set_buffer_size_first: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val] +snd_pcm_hw_params_set_buffer_size_last: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val] +snd_pcm_hw_params_set_buffer_size_max: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val] +snd_pcm_hw_params_set_buffer_size_min: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val] +snd_pcm_hw_params_set_buffer_size_minmax: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *min, snd_pcm_uframes_t *max] +snd_pcm_hw_params_set_buffer_size_near: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val] +snd_pcm_hw_params_set_buffer_time: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val, int dir] +snd_pcm_hw_params_set_buffer_time_first: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir] +snd_pcm_hw_params_set_buffer_time_last: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir] +snd_pcm_hw_params_set_buffer_time_max: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir] +snd_pcm_hw_params_set_buffer_time_min: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir] +snd_pcm_hw_params_set_buffer_time_minmax: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *min, int *mindir, unsigned int *max, int *maxdir] +snd_pcm_hw_params_set_buffer_time_near: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir] +snd_pcm_hw_params_set_channels: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val] +snd_pcm_hw_params_set_channels_first: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val] +snd_pcm_hw_params_set_channels_last: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val] +snd_pcm_hw_params_set_channels_max: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val] +snd_pcm_hw_params_set_channels_min: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val] +snd_pcm_hw_params_set_channels_minmax: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *min, unsigned int *max] +snd_pcm_hw_params_set_channels_near: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val] +snd_pcm_hw_params_set_export_buffer: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val] +snd_pcm_hw_params_set_format: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_format_t val] +snd_pcm_hw_params_set_format_first: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_format_t *format] +snd_pcm_hw_params_set_format_last: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_format_t *format] +snd_pcm_hw_params_set_format_mask: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_format_mask_t *mask] +snd_pcm_hw_params_set_period_size: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t val, int dir] +snd_pcm_hw_params_set_period_size_first: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val, int *dir] +snd_pcm_hw_params_set_period_size_integer: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params] +snd_pcm_hw_params_set_period_size_last: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val, int *dir] +snd_pcm_hw_params_set_period_size_max: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val, int *dir] +snd_pcm_hw_params_set_period_size_min: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val, int *dir] +snd_pcm_hw_params_set_period_size_minmax: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *min, int *mindir, snd_pcm_uframes_t *max, int *maxdir] +snd_pcm_hw_params_set_period_size_near: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val, int *dir] +snd_pcm_hw_params_set_period_time: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val, int dir] +snd_pcm_hw_params_set_period_time_first: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir] +snd_pcm_hw_params_set_period_time_last: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir] +snd_pcm_hw_params_set_period_time_max: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir] +snd_pcm_hw_params_set_period_time_min: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir] +snd_pcm_hw_params_set_period_time_minmax: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *min, int *mindir, unsigned int *max, int *maxdir] +snd_pcm_hw_params_set_period_time_near: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir] +snd_pcm_hw_params_set_periods: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val, int dir] +snd_pcm_hw_params_set_periods_first: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir] +snd_pcm_hw_params_set_periods_integer: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params] +snd_pcm_hw_params_set_periods_last: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir] +snd_pcm_hw_params_set_periods_max: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir] +snd_pcm_hw_params_set_periods_min: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir] +snd_pcm_hw_params_set_periods_minmax: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *min, int *mindir, unsigned int *max, int *maxdir] +snd_pcm_hw_params_set_periods_near: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir] +snd_pcm_hw_params_set_rate: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val, int dir] +snd_pcm_hw_params_set_rate_first: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir] +snd_pcm_hw_params_set_rate_last: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir] +snd_pcm_hw_params_set_rate_max: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir] +snd_pcm_hw_params_set_rate_min: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir] +snd_pcm_hw_params_set_rate_minmax: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *min, int *mindir, unsigned int *max, int *maxdir] +snd_pcm_hw_params_set_rate_near: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir] +snd_pcm_hw_params_set_rate_resample: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val] +snd_pcm_hw_params_set_subformat: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_subformat_t subformat] +snd_pcm_hw_params_set_subformat_first: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_subformat_t *subformat] +snd_pcm_hw_params_set_subformat_last: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_subformat_t *subformat] +snd_pcm_hw_params_set_subformat_mask: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_subformat_mask_t *mask] +snd_pcm_hw_params_set_tick_time: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val, int dir] +snd_pcm_hw_params_set_tick_time_first: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir] +snd_pcm_hw_params_set_tick_time_last: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir] +snd_pcm_hw_params_set_tick_time_max: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir] +snd_pcm_hw_params_set_tick_time_min: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir] +snd_pcm_hw_params_set_tick_time_minmax: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *min, int *mindir, unsigned int *max, int *maxdir] +snd_pcm_hw_params_set_tick_time_near: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir] +snd_pcm_hw_params_test_access: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_access_t _access] +snd_pcm_hw_params_test_buffer_size: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t val] +snd_pcm_hw_params_test_buffer_time: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val, int dir] +snd_pcm_hw_params_test_channels: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val] +snd_pcm_hw_params_test_format: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_format_t val] +snd_pcm_hw_params_test_period_size: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t val, int dir] +snd_pcm_hw_params_test_period_time: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val, int dir] +snd_pcm_hw_params_test_periods: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val, int dir] +snd_pcm_hw_params_test_rate: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val, int dir] +snd_pcm_hw_params_test_subformat: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_subformat_t subformat] +snd_pcm_hw_params_test_tick_time: [int, snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val, int dir] +snd_pcm_hwsync: [int, snd_pcm_t *pcm] +snd_pcm_info: [int, snd_pcm_t *pcm, snd_pcm_info_t *info] +snd_pcm_info_copy: [void, snd_pcm_info_t *dst, const snd_pcm_info_t *src] +snd_pcm_info_free: [void, snd_pcm_info_t *obj] +snd_pcm_info_get_card: [int, const snd_pcm_info_t *obj] +snd_pcm_info_get_class: [snd_pcm_class_t, const snd_pcm_info_t *obj] +snd_pcm_info_get_device: [unsigned int, const snd_pcm_info_t *obj] +snd_pcm_info_get_id: [const char *, const snd_pcm_info_t *obj] +snd_pcm_info_get_name: [const char *, const snd_pcm_info_t *obj] +snd_pcm_info_get_stream: [snd_pcm_stream_t, const snd_pcm_info_t *obj] +snd_pcm_info_get_subclass: [snd_pcm_subclass_t, const snd_pcm_info_t *obj] +snd_pcm_info_get_subdevice: [unsigned int, const snd_pcm_info_t *obj] +snd_pcm_info_get_subdevice_name: [const char *, const snd_pcm_info_t *obj] +snd_pcm_info_get_subdevices_avail: [unsigned int, const snd_pcm_info_t *obj] +snd_pcm_info_get_subdevices_count: [unsigned int, const snd_pcm_info_t *obj] +snd_pcm_info_get_sync: [snd_pcm_sync_id_t, const snd_pcm_info_t *obj] +snd_pcm_info_malloc: [int, snd_pcm_info_t **ptr] +snd_pcm_info_sizeof: [size_t] +snd_pcm_access_mask_sizeof: [size_t] +snd_pcm_info_set_device: [void, snd_pcm_info_t *obj, unsigned int val] +snd_pcm_info_set_stream: [void, snd_pcm_info_t *obj, snd_pcm_stream_t val] +snd_pcm_info_set_subdevice: [void, snd_pcm_info_t *obj, unsigned int val] +snd_pcm_link: [int, snd_pcm_t *pcm1, snd_pcm_t *pcm2] +snd_pcm_meter_add_scope: [int, snd_pcm_t *pcm, snd_pcm_scope_t *scope] +snd_pcm_meter_get_boundary: [snd_pcm_uframes_t, snd_pcm_t *pcm] +snd_pcm_meter_get_bufsize: [snd_pcm_uframes_t, snd_pcm_t *pcm] +snd_pcm_meter_get_channels: [unsigned int, snd_pcm_t *pcm] +snd_pcm_meter_get_now: [snd_pcm_uframes_t, snd_pcm_t *pcm] +snd_pcm_meter_get_rate: [unsigned int, snd_pcm_t *pcm] +snd_pcm_meter_search_scope: [snd_pcm_scope_t *, snd_pcm_t *pcm, const char *name] +snd_pcm_mmap_begin: [int, snd_pcm_t *pcm, const snd_pcm_channel_area_t **areas, snd_pcm_uframes_t *offset, snd_pcm_uframes_t *frames] +snd_pcm_mmap_commit: [snd_pcm_sframes_t, snd_pcm_t *pcm, snd_pcm_uframes_t offset, snd_pcm_uframes_t frames] +snd_pcm_mmap_readi: [snd_pcm_sframes_t, snd_pcm_t *pcm, void *buffer, snd_pcm_uframes_t size] +snd_pcm_mmap_readn: [snd_pcm_sframes_t, snd_pcm_t *pcm, void **bufs, snd_pcm_uframes_t size] +snd_pcm_mmap_writei: [snd_pcm_sframes_t, snd_pcm_t *pcm, const void *buffer, snd_pcm_uframes_t size] +snd_pcm_mmap_writen: [snd_pcm_sframes_t, snd_pcm_t *pcm, void **bufs, snd_pcm_uframes_t size] +snd_pcm_name: [const char *, snd_pcm_t *pcm] +snd_pcm_nonblock: [int, snd_pcm_t *pcm, int nonblock] +snd_pcm_open: [int, snd_pcm_t **pcm, const char *name, snd_pcm_stream_t stream, int mode] +snd_pcm_open_lconf: [int, snd_pcm_t **pcm, const char *name, snd_pcm_stream_t stream, int mode, snd_config_t *lconf] +snd_pcm_pause: [int, snd_pcm_t *pcm, int enable] +snd_pcm_poll_descriptors: [int, snd_pcm_t *pcm, struct pollfd *pfds, unsigned int space] +snd_pcm_poll_descriptors_count: [int, snd_pcm_t *pcm] +snd_pcm_poll_descriptors_revents: [int, snd_pcm_t *pcm, struct pollfd *pfds, unsigned int nfds, unsigned short *revents] +snd_pcm_prepare: [int, snd_pcm_t *pcm] +snd_pcm_readi: [snd_pcm_sframes_t, snd_pcm_t *pcm, void *buffer, snd_pcm_uframes_t size] +snd_pcm_readn: [snd_pcm_sframes_t, snd_pcm_t *pcm, void **bufs, snd_pcm_uframes_t size] +snd_pcm_recover: [int, snd_pcm_t *pcm, int err, int silent] +snd_pcm_reset: [int, snd_pcm_t *pcm] +snd_pcm_resume: [int, snd_pcm_t *pcm] +snd_pcm_rewind: [snd_pcm_sframes_t, snd_pcm_t *pcm, snd_pcm_uframes_t frames] +snd_pcm_samples_to_bytes: [ssize_t, snd_pcm_t *pcm, long samples] +snd_pcm_scope_get_callback_private: [void *, snd_pcm_scope_t *scope] +snd_pcm_scope_get_name: [const char *, snd_pcm_scope_t *scope] +snd_pcm_scope_malloc: [int, snd_pcm_scope_t **ptr] +snd_pcm_scope_s16_get_channel_buffer: [int16_t *, snd_pcm_scope_t *scope, unsigned int channel] +snd_pcm_scope_s16_open: [int, snd_pcm_t *pcm, const char *name, snd_pcm_scope_t **scopep] +snd_pcm_scope_set_callback_private: [void, snd_pcm_scope_t *scope, void *val] +snd_pcm_hw_params_sizeof: [size_t] +snd_pcm_sw_params_sizeof: [size_t] +snd_pcm_hw_params_is_monotonic: [int, const snd_pcm_hw_params_t *params] +snd_pcm_scope_set_name: [void, snd_pcm_scope_t *scope, const char *val] +snd_pcm_scope_set_ops: [void, snd_pcm_scope_t *scope, const snd_pcm_scope_ops_t *val] +snd_pcm_set_params: [int, snd_pcm_t *pcm, snd_pcm_format_t format, snd_pcm_access_t access, unsigned int channels, unsigned int rate, int soft_resample, unsigned int latency] +snd_pcm_start: [int, snd_pcm_t *pcm] +snd_pcm_start_mode_name: [const char *, snd_pcm_start_t mode] +snd_pcm_state: [snd_pcm_state_t, snd_pcm_t *pcm] +snd_pcm_state_name: [const char *, const snd_pcm_state_t state] +snd_pcm_status: [int, snd_pcm_t *pcm, snd_pcm_status_t *status] +snd_pcm_status_copy: [void, snd_pcm_status_t *dst, const snd_pcm_status_t *src] +snd_pcm_status_dump: [int, snd_pcm_status_t *status, snd_output_t *out] +snd_pcm_status_free: [void, snd_pcm_status_t *obj] +snd_pcm_status_get_avail: [snd_pcm_uframes_t, const snd_pcm_status_t *obj] +snd_pcm_status_get_avail_max: [snd_pcm_uframes_t, const snd_pcm_status_t *obj] +snd_pcm_status_get_delay: [snd_pcm_sframes_t, const snd_pcm_status_t *obj] +snd_pcm_status_get_htstamp: [void, const snd_pcm_status_t *obj, snd_htimestamp_t *ptr] +snd_pcm_status_get_overrange: [snd_pcm_uframes_t, const snd_pcm_status_t *obj] +snd_pcm_status_get_state: [snd_pcm_state_t, const snd_pcm_status_t *obj] +snd_pcm_status_get_trigger_htstamp: [void, const snd_pcm_status_t *obj, snd_htimestamp_t *ptr] +snd_pcm_status_get_trigger_tstamp: [void, const snd_pcm_status_t *obj, snd_timestamp_t *ptr] +snd_pcm_status_get_tstamp: [void, const snd_pcm_status_t *obj, snd_timestamp_t *ptr] +snd_pcm_status_malloc: [int, snd_pcm_status_t **ptr] +snd_pcm_stream: [snd_pcm_stream_t, snd_pcm_t *pcm] +snd_pcm_stream_name: [const char *, const snd_pcm_stream_t stream] +snd_pcm_subformat_description: [const char *, const snd_pcm_subformat_t subformat] +snd_pcm_subformat_mask_any: [void, snd_pcm_subformat_mask_t *mask] +snd_pcm_subformat_mask_copy: [void, snd_pcm_subformat_mask_t *dst, const snd_pcm_subformat_mask_t *src] +snd_pcm_subformat_mask_empty: [int, const snd_pcm_subformat_mask_t *mask] +snd_pcm_subformat_mask_free: [void, snd_pcm_subformat_mask_t *obj] +snd_pcm_subformat_mask_malloc: [int, snd_pcm_subformat_mask_t **ptr] +snd_pcm_subformat_mask_none: [void, snd_pcm_subformat_mask_t *mask] +snd_pcm_subformat_mask_reset: [void, snd_pcm_subformat_mask_t *mask, snd_pcm_subformat_t val] +snd_pcm_subformat_mask_set: [void, snd_pcm_subformat_mask_t *mask, snd_pcm_subformat_t val] +snd_pcm_subformat_mask_test: [int, const snd_pcm_subformat_mask_t *mask, snd_pcm_subformat_t val] +snd_pcm_subformat_name: [const char *, const snd_pcm_subformat_t subformat] +snd_pcm_sw_params: [int, snd_pcm_t *pcm, snd_pcm_sw_params_t *params] +snd_pcm_sw_params_copy: [void, snd_pcm_sw_params_t *dst, const snd_pcm_sw_params_t *src] +snd_pcm_sw_params_current: [int, snd_pcm_t *pcm, snd_pcm_sw_params_t *params] +snd_pcm_sw_params_dump: [int, snd_pcm_sw_params_t *params, snd_output_t *out] +snd_pcm_sw_params_free: [void, snd_pcm_sw_params_t *obj] +snd_pcm_sw_params_get_avail_min: [int, const snd_pcm_sw_params_t *params, snd_pcm_uframes_t *val] +snd_pcm_sw_params_get_boundary: [int, const snd_pcm_sw_params_t *params, snd_pcm_uframes_t *val] +snd_pcm_sw_params_get_silence_size: [int, const snd_pcm_sw_params_t *params, snd_pcm_uframes_t *val] +snd_pcm_sw_params_get_silence_threshold: [int, const snd_pcm_sw_params_t *params, snd_pcm_uframes_t *val] +snd_pcm_sw_params_get_sleep_min: [int, const snd_pcm_sw_params_t *params, unsigned int *val] +snd_pcm_sw_params_get_start_mode: [snd_pcm_start_t, const snd_pcm_sw_params_t *params] +snd_pcm_sw_params_get_start_threshold: [int, const snd_pcm_sw_params_t *paramsm, snd_pcm_uframes_t *val] +snd_pcm_sw_params_get_stop_threshold: [int, const snd_pcm_sw_params_t *params, snd_pcm_uframes_t *val] +snd_pcm_sw_params_get_tstamp_mode: [int, const snd_pcm_sw_params_t *params, snd_pcm_tstamp_t *val] +snd_pcm_sw_params_get_xfer_align: [int, const snd_pcm_sw_params_t *params, snd_pcm_uframes_t *val] +snd_pcm_sw_params_get_xrun_mode: [snd_pcm_xrun_t, const snd_pcm_sw_params_t *params] +snd_pcm_sw_params_malloc: [int, snd_pcm_sw_params_t **ptr] +snd_pcm_sw_params_set_avail_min: [int, snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_uframes_t val] +snd_pcm_sw_params_set_silence_size: [int, snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_uframes_t val] +snd_pcm_sw_params_set_silence_threshold: [int, snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_uframes_t val] +snd_pcm_sw_params_set_sleep_min: [int, snd_pcm_t *pcm, snd_pcm_sw_params_t *params, unsigned int val] +snd_pcm_sw_params_set_start_mode: [int, snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_start_t val] +snd_pcm_sw_params_set_start_threshold: [int, snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_uframes_t val] +snd_pcm_sw_params_set_stop_threshold: [int, snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_uframes_t val] +snd_pcm_sw_params_set_tstamp_mode: [int, snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_tstamp_t val] +snd_pcm_sw_params_set_xfer_align: [int, snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_uframes_t val] +snd_pcm_sw_params_set_xrun_mode: [int, snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_xrun_t val] +snd_pcm_tstamp_mode_name: [const char *, const snd_pcm_tstamp_t mode] +snd_pcm_type: [snd_pcm_type_t, snd_pcm_t *pcm] +snd_pcm_type_name: [const char *, snd_pcm_type_t type] +snd_pcm_unlink: [int, snd_pcm_t *pcm] +snd_pcm_wait: [int, snd_pcm_t *pcm, int timeout] +snd_pcm_writei: [snd_pcm_sframes_t, snd_pcm_t *pcm, const void *buffer, snd_pcm_uframes_t size] +snd_pcm_writen: [snd_pcm_sframes_t, snd_pcm_t *pcm, void **bufs, snd_pcm_uframes_t size] +snd_pcm_xrun_mode_name: [const char *, snd_pcm_xrun_t mode] +snd_spcm_init: [int, snd_pcm_t *pcm, unsigned int rate, unsigned int channels, snd_pcm_format_t format, snd_pcm_subformat_t subformat, snd_spcm_latency_t latency, snd_pcm_access_t _access, snd_spcm_xrun_type_t xrun_type] +snd_spcm_init_duplex: [int, snd_pcm_t *playback_pcm, snd_pcm_t *capture_pcm, unsigned int rate, unsigned int channels, snd_pcm_format_t format, snd_pcm_subformat_t subformat, snd_spcm_latency_t latency, snd_pcm_access_t _access, snd_spcm_xrun_type_t xrun_type, snd_spcm_duplex_type_t duplex_type] +snd_spcm_init_get_params: [int, snd_pcm_t *pcm, unsigned int *rate, snd_pcm_uframes_t *buffer_size, snd_pcm_uframes_t *period_size] + +# rawmidi.h +snd_rawmidi_open: [int, snd_rawmidi_t **in_rmidi, snd_rawmidi_t **out_rmidi, const char *name, int mode] +snd_rawmidi_open_lconf: [int, snd_rawmidi_t **in_rmidi, snd_rawmidi_t **out_rmidi, const char *name, int mode, snd_config_t *lconf] +snd_rawmidi_close: [int, snd_rawmidi_t *rmidi] +snd_rawmidi_poll_descriptors_count: [int, snd_rawmidi_t *rmidi] +snd_rawmidi_poll_descriptors: [int, snd_rawmidi_t *rmidi, struct pollfd *pfds, unsigned int space] +snd_rawmidi_poll_descriptors_revents: [int, snd_rawmidi_t *rawmidi, struct pollfd *pfds, unsigned int nfds, unsigned short *revent] +snd_rawmidi_nonblock: [int, snd_rawmidi_t *rmidi, int nonblock] +snd_rawmidi_info_sizeof: [size_t] +snd_rawmidi_info_malloc: [int, snd_rawmidi_info_t **ptr] +snd_rawmidi_info_free: [void, snd_rawmidi_info_t *obj] +snd_rawmidi_info_copy: [void, snd_rawmidi_info_t *dst, const snd_rawmidi_info_t *src] +snd_rawmidi_info_get_device: [unsigned int, const snd_rawmidi_info_t *obj] +snd_rawmidi_info_get_subdevice: [unsigned int, const snd_rawmidi_info_t *obj] +snd_rawmidi_info_get_stream: [snd_rawmidi_stream_t, const snd_rawmidi_info_t *obj] +snd_rawmidi_info_get_card: [int, const snd_rawmidi_info_t *obj] +snd_rawmidi_info_get_flags: [unsigned int, const snd_rawmidi_info_t *obj] +snd_rawmidi_info_get_id: [const char *, const snd_rawmidi_info_t *obj] +snd_rawmidi_info_get_name: [const char *, const snd_rawmidi_info_t *obj] +snd_rawmidi_info_get_subdevice_name: [const char *, const snd_rawmidi_info_t *obj] +snd_rawmidi_info_get_subdevices_count: [unsigned int, const snd_rawmidi_info_t *obj] +snd_rawmidi_info_get_subdevices_avail: [unsigned int, const snd_rawmidi_info_t *obj] +snd_rawmidi_info_set_device: [void, snd_rawmidi_info_t *obj, unsigned int val] +snd_rawmidi_info_set_subdevice: [void, snd_rawmidi_info_t *obj, unsigned int val] +snd_rawmidi_info_set_stream: [void, snd_rawmidi_info_t *obj, snd_rawmidi_stream_t val] +snd_rawmidi_info: [int, snd_rawmidi_t *rmidi, snd_rawmidi_info_t * info] +snd_rawmidi_params_sizeof: [size_t] +snd_rawmidi_params_malloc: [int, snd_rawmidi_params_t **ptr] +snd_rawmidi_params_free: [void, snd_rawmidi_params_t *obj] +snd_rawmidi_params_copy: [void, snd_rawmidi_params_t *dst, const snd_rawmidi_params_t *src] +snd_rawmidi_params_set_buffer_size: [int, snd_rawmidi_t *rmidi, snd_rawmidi_params_t *params, size_t val] +snd_rawmidi_params_get_buffer_size: [size_t, const snd_rawmidi_params_t *params] +snd_rawmidi_params_set_avail_min: [int, snd_rawmidi_t *rmidi, snd_rawmidi_params_t *params, size_t val] +snd_rawmidi_params_get_avail_min: [size_t, const snd_rawmidi_params_t *params] +snd_rawmidi_params_set_no_active_sensing: [int, snd_rawmidi_t *rmidi, snd_rawmidi_params_t *params, int val] +snd_rawmidi_params_get_no_active_sensing: [int, const snd_rawmidi_params_t *params] +snd_rawmidi_params: [int, snd_rawmidi_t *rmidi, snd_rawmidi_params_t * params] +snd_rawmidi_params_current: [int, snd_rawmidi_t *rmidi, snd_rawmidi_params_t *params] +snd_rawmidi_status_sizeof: [size_t] +snd_rawmidi_status_malloc: [int, snd_rawmidi_status_t **ptr] +snd_rawmidi_status_free: [void, snd_rawmidi_status_t *obj] +snd_rawmidi_status_copy: [void, snd_rawmidi_status_t *dst, const snd_rawmidi_status_t *src] +snd_rawmidi_status_get_tstamp: [void, const snd_rawmidi_status_t *obj, snd_htimestamp_t *ptr] +snd_rawmidi_status_get_avail: [size_t, const snd_rawmidi_status_t *obj] +snd_rawmidi_status_get_xruns: [size_t, const snd_rawmidi_status_t *obj] +snd_rawmidi_status: [int, snd_rawmidi_t *rmidi, snd_rawmidi_status_t * status] +snd_rawmidi_drain: [int, snd_rawmidi_t *rmidi] +snd_rawmidi_drop: [int, snd_rawmidi_t *rmidi] +snd_rawmidi_write: [ssize_t, snd_rawmidi_t *rmidi, const void *buffer, size_t size] +snd_rawmidi_read: [ssize_t, snd_rawmidi_t *rmidi, void *buffer, size_t size] +snd_rawmidi_name: [const char *, snd_rawmidi_t *rmidi] +snd_rawmidi_type: [snd_rawmidi_type_t, snd_rawmidi_t *rmidi] +snd_rawmidi_stream: [snd_rawmidi_stream_t, snd_rawmidi_t *rawmidi] + +# timer.h +snd_timer_query_open: [int, snd_timer_query_t **handle, const char *name, int mode] +snd_timer_query_open_lconf: [int, snd_timer_query_t **handle, const char *name, int mode, snd_config_t *lconf] +snd_timer_query_close: [int, snd_timer_query_t *handle] +snd_timer_query_next_device: [int, snd_timer_query_t *handle, snd_timer_id_t *tid] +snd_timer_query_info: [int, snd_timer_query_t *handle, snd_timer_ginfo_t *info] +snd_timer_query_params: [int, snd_timer_query_t *handle, snd_timer_gparams_t *params] +snd_timer_query_status: [int, snd_timer_query_t *handle, snd_timer_gstatus_t *status] +snd_timer_open: [int, snd_timer_t **handle, const char *name, int mode] +snd_timer_open_lconf: [int, snd_timer_t **handle, const char *name, int mode, snd_config_t *lconf] +snd_timer_close: [int, snd_timer_t *handle] +snd_async_add_timer_handler: [int, snd_async_handler_t **handler, snd_timer_t *timer, snd_async_callback_t callback, void *private_data] +snd_async_handler_get_timer: [snd_timer_t *, snd_async_handler_t *handler] +snd_timer_poll_descriptors_count: [int, snd_timer_t *handle] +snd_timer_poll_descriptors: [int, snd_timer_t *handle, struct pollfd *pfds, unsigned int space] +snd_timer_poll_descriptors_revents: [int, snd_timer_t *timer, struct pollfd *pfds, unsigned int nfds, unsigned short *revents] +snd_timer_info: [int, snd_timer_t *handle, snd_timer_info_t *timer] +snd_timer_params: [int, snd_timer_t *handle, snd_timer_params_t *params] +snd_timer_status: [int, snd_timer_t *handle, snd_timer_status_t *status] +snd_timer_start: [int, snd_timer_t *handle] +snd_timer_stop: [int, snd_timer_t *handle] +snd_timer_continue: [int, snd_timer_t *handle] +snd_timer_read: [ssize_t, snd_timer_t *handle, void *buffer, size_t size] +snd_timer_id_sizeof: [size_t] +snd_timer_id_malloc: [int, snd_timer_id_t **ptr] +snd_timer_id_free: [void, snd_timer_id_t *obj] +snd_timer_id_copy: [void, snd_timer_id_t *dst, const snd_timer_id_t *src] +snd_timer_id_set_class: [void, snd_timer_id_t *id, int dev_class] +snd_timer_id_get_class: [int, snd_timer_id_t *id] +snd_timer_id_set_sclass: [void, snd_timer_id_t *id, int dev_sclass] +snd_timer_id_get_sclass: [int, snd_timer_id_t *id] +snd_timer_id_set_card: [void, snd_timer_id_t *id, int card] +snd_timer_id_get_card: [int, snd_timer_id_t *id] +snd_timer_id_set_device: [void, snd_timer_id_t *id, int device] +snd_timer_id_get_device: [int, snd_timer_id_t *id] +snd_timer_id_set_subdevice: [void, snd_timer_id_t *id, int subdevice] +snd_timer_id_get_subdevice: [int, snd_timer_id_t *id] +snd_timer_ginfo_sizeof: [size_t] +snd_timer_ginfo_malloc: [int, snd_timer_ginfo_t **ptr] +snd_timer_ginfo_free: [void, snd_timer_ginfo_t *obj] +snd_timer_ginfo_copy: [void, snd_timer_ginfo_t *dst, const snd_timer_ginfo_t *src] +snd_timer_ginfo_set_tid: [int, snd_timer_ginfo_t *obj, snd_timer_id_t *tid] +snd_timer_ginfo_get_tid: [snd_timer_id_t *, snd_timer_ginfo_t *obj] +snd_timer_ginfo_get_flags: [unsigned int, snd_timer_ginfo_t *obj] +snd_timer_ginfo_get_card: [int, snd_timer_ginfo_t *obj] +snd_timer_ginfo_get_id: [char *, snd_timer_ginfo_t *obj] +snd_timer_ginfo_get_name: [char *, snd_timer_ginfo_t *obj] +snd_timer_ginfo_get_resolution: [unsigned long, snd_timer_ginfo_t *obj] +snd_timer_ginfo_get_resolution_min: [unsigned long, snd_timer_ginfo_t *obj] +snd_timer_ginfo_get_resolution_max: [unsigned long, snd_timer_ginfo_t *obj] +snd_timer_ginfo_get_clients: [unsigned int, snd_timer_ginfo_t *obj] +snd_timer_info_sizeof: [size_t] +snd_timer_info_malloc: [int, snd_timer_info_t **ptr] +snd_timer_info_free: [void, snd_timer_info_t *obj] +snd_timer_info_copy: [void, snd_timer_info_t *dst, const snd_timer_info_t *src] +snd_timer_info_is_slave: [int, snd_timer_info_t * info] +snd_timer_info_get_card: [int, snd_timer_info_t * info] +snd_timer_info_get_id: [const char *, snd_timer_info_t * info] +snd_timer_info_get_name: [const char *, snd_timer_info_t * info] +snd_timer_info_get_resolution: [long, snd_timer_info_t * info] +snd_timer_params_sizeof: [size_t] +snd_timer_params_malloc: [int, snd_timer_params_t **ptr] +snd_timer_params_free: [void, snd_timer_params_t *obj] +snd_timer_params_copy: [void, snd_timer_params_t *dst, const snd_timer_params_t *src] +snd_timer_params_set_auto_start: [int, snd_timer_params_t * params, int auto_start] +snd_timer_params_get_auto_start: [int, snd_timer_params_t * params] +snd_timer_params_set_exclusive: [int, snd_timer_params_t * params, int exclusive] +snd_timer_params_get_exclusive: [int, snd_timer_params_t * params] +snd_timer_params_set_early_event: [int, snd_timer_params_t * params, int early_event] +snd_timer_params_get_early_event: [int, snd_timer_params_t * params] +snd_timer_params_set_ticks: [void, snd_timer_params_t * params, long ticks] +snd_timer_params_get_ticks: [long, snd_timer_params_t * params] +snd_timer_params_set_queue_size: [void, snd_timer_params_t * params, long queue_size] +snd_timer_params_get_queue_size: [long, snd_timer_params_t * params] +snd_timer_params_set_filter: [void, snd_timer_params_t * params, unsigned int filter] +snd_timer_params_get_filter: [unsigned int, snd_timer_params_t * params] +snd_timer_status_sizeof: [size_t] +snd_timer_status_malloc: [int, snd_timer_status_t **ptr] +snd_timer_status_free: [void, snd_timer_status_t *obj] +snd_timer_status_copy: [void, snd_timer_status_t *dst, const snd_timer_status_t *src] +snd_timer_status_get_timestamp: [snd_htimestamp_t, snd_timer_status_t * status] +snd_timer_status_get_resolution: [long, snd_timer_status_t * status] +snd_timer_status_get_lost: [long, snd_timer_status_t * status] +snd_timer_status_get_overrun: [long, snd_timer_status_t * status] +snd_timer_status_get_queue: [long, snd_timer_status_t * status] +snd_timer_info_get_ticks: [long, snd_timer_info_t * info] + +# hwdep.h +snd_hwdep_open: [int, snd_hwdep_t **hwdep, const char *name, int mode] +snd_hwdep_close: [int, snd_hwdep_t *hwdep] +snd_hwdep_poll_descriptors: [int, snd_hwdep_t *hwdep, struct pollfd *pfds, unsigned int space] +snd_hwdep_poll_descriptors_revents: [int, snd_hwdep_t *hwdep, struct pollfd *pfds, unsigned int nfds, unsigned short *revents] +snd_hwdep_nonblock: [int, snd_hwdep_t *hwdep, int nonblock] +snd_hwdep_info: [int, snd_hwdep_t *hwdep, snd_hwdep_info_t * info] +snd_hwdep_dsp_status: [int, snd_hwdep_t *hwdep, snd_hwdep_dsp_status_t *status] +snd_hwdep_dsp_load: [int, snd_hwdep_t *hwdep, snd_hwdep_dsp_image_t *block] +snd_hwdep_ioctl: [int, snd_hwdep_t *hwdep, unsigned int request, void * arg] +snd_hwdep_write: [ssize_t, snd_hwdep_t *hwdep, const void *buffer, size_t size] +snd_hwdep_read: [ssize_t, snd_hwdep_t *hwdep, void *buffer, size_t size] +snd_hwdep_info_sizeof: [size_t] +snd_hwdep_dsp_status_sizeof: [size_t] +snd_hwdep_dsp_status_malloc: [int, snd_hwdep_dsp_status_t **ptr] +snd_hwdep_dsp_status_free: [void, snd_hwdep_dsp_status_t *obj] +snd_hwdep_dsp_status_copy: [void, snd_hwdep_dsp_status_t *dst, const snd_hwdep_dsp_status_t *src] +snd_hwdep_dsp_status_get_version: [unsigned int, const snd_hwdep_dsp_status_t *obj] +snd_hwdep_dsp_status_get_id: [const char *, const snd_hwdep_dsp_status_t *obj] +snd_hwdep_dsp_status_get_num_dsps: [unsigned int, const snd_hwdep_dsp_status_t *obj] +snd_hwdep_dsp_status_get_dsp_loaded: [unsigned int, const snd_hwdep_dsp_status_t *obj] +snd_hwdep_dsp_status_get_chip_ready: [unsigned int, const snd_hwdep_dsp_status_t *obj] +snd_hwdep_dsp_image_sizeof: [size_t] +snd_hwdep_dsp_image_malloc: [int, snd_hwdep_dsp_image_t **ptr] +snd_hwdep_dsp_image_free: [void, snd_hwdep_dsp_image_t *obj] +snd_hwdep_dsp_image_copy: [void, snd_hwdep_dsp_image_t *dst, const snd_hwdep_dsp_image_t *src] +snd_hwdep_dsp_image_get_index: [unsigned int, const snd_hwdep_dsp_image_t *obj] +snd_hwdep_dsp_image_get_name: [const char *, const snd_hwdep_dsp_image_t *obj] +snd_hwdep_dsp_image_get_image: [const void *, const snd_hwdep_dsp_image_t *obj] +snd_hwdep_dsp_image_get_length: [size_t, const snd_hwdep_dsp_image_t *obj] +snd_hwdep_dsp_image_set_index: [void, snd_hwdep_dsp_image_t *obj, unsigned int _index] +snd_hwdep_dsp_image_set_name: [void, snd_hwdep_dsp_image_t *obj, const char *name] +snd_hwdep_dsp_image_set_image: [void, snd_hwdep_dsp_image_t *obj, void *buffer] +snd_hwdep_dsp_image_set_length: [void, snd_hwdep_dsp_image_t *obj, size_t length] + +# control.h +snd_card_load: [int, int card] +snd_card_next: [int, int *card] +snd_card_get_index: [int, const char *name] +snd_card_get_name: [int, int card, char **name] +snd_card_get_longname: [int, int card, char **name] +snd_ctl_open: [int, snd_ctl_t **ctl, const char *name, int mode] +snd_ctl_open_lconf: [int, snd_ctl_t **ctl, const char *name, int mode, snd_config_t *lconf] +snd_ctl_close: [int, snd_ctl_t *ctl] +snd_ctl_nonblock: [int, snd_ctl_t *ctl, int nonblock] +snd_async_add_ctl_handler: [int, snd_async_handler_t **handler, snd_ctl_t *ctl, snd_async_callback_t callback, void *private_data] +snd_async_handler_get_ctl: [snd_ctl_t *, snd_async_handler_t *handler] +snd_ctl_poll_descriptors_count: [int, snd_ctl_t *ctl] +snd_ctl_poll_descriptors: [int, snd_ctl_t *ctl, struct pollfd *pfds, unsigned int space] +snd_ctl_poll_descriptors_revents: [int, snd_ctl_t *ctl, struct pollfd *pfds, unsigned int nfds, unsigned short *revents] +snd_ctl_subscribe_events: [int, snd_ctl_t *ctl, int subscribe] +snd_ctl_card_info: [int, snd_ctl_t *ctl, snd_ctl_card_info_t *info] +snd_ctl_elem_list: [int, snd_ctl_t *ctl, snd_ctl_elem_list_t *list] +snd_ctl_elem_info: [int, snd_ctl_t *ctl, snd_ctl_elem_info_t *info] +snd_ctl_elem_read: [int, snd_ctl_t *ctl, snd_ctl_elem_value_t *value] +snd_ctl_elem_write: [int, snd_ctl_t *ctl, snd_ctl_elem_value_t *value] +snd_ctl_elem_lock: [int, snd_ctl_t *ctl, snd_ctl_elem_id_t *id] +snd_ctl_elem_unlock: [int, snd_ctl_t *ctl, snd_ctl_elem_id_t *id] +snd_ctl_elem_tlv_read: [int, snd_ctl_t *ctl, const snd_ctl_elem_id_t *id, unsigned int *tlv, unsigned int tlv_size] +snd_ctl_elem_tlv_write: [int, snd_ctl_t *ctl, const snd_ctl_elem_id_t *id, const unsigned int *tlv] +snd_ctl_elem_tlv_command: [int, snd_ctl_t *ctl, const snd_ctl_elem_id_t *id, const unsigned int *tlv] +snd_ctl_hwdep_next_device: [int, snd_ctl_t *ctl, int * device] +snd_ctl_hwdep_info: [int, snd_ctl_t *ctl, snd_hwdep_info_t * info] +snd_ctl_pcm_next_device: [int, snd_ctl_t *ctl, int *device] +snd_ctl_pcm_info: [int, snd_ctl_t *ctl, snd_pcm_info_t * info] +snd_ctl_pcm_prefer_subdevice: [int, snd_ctl_t *ctl, int subdev] +snd_ctl_rawmidi_next_device: [int, snd_ctl_t *ctl, int * device] +snd_ctl_rawmidi_info: [int, snd_ctl_t *ctl, snd_rawmidi_info_t * info] +snd_ctl_rawmidi_prefer_subdevice: [int, snd_ctl_t *ctl, int subdev] +snd_ctl_set_power_state: [int, snd_ctl_t *ctl, unsigned int state] +snd_ctl_get_power_state: [int, snd_ctl_t *ctl, unsigned int *state] +snd_ctl_read: [int, snd_ctl_t *ctl, snd_ctl_event_t *event] +snd_ctl_wait: [int, snd_ctl_t *ctl, int timeout] +snd_ctl_name: [const char *, snd_ctl_t *ctl] +snd_ctl_type: [snd_ctl_type_t, snd_ctl_t *ctl] +snd_ctl_elem_type_name: [const char *, snd_ctl_elem_type_t type] +snd_ctl_elem_iface_name: [const char *, snd_ctl_elem_iface_t iface] +snd_ctl_event_type_name: [const char *, snd_ctl_event_type_t type] +snd_ctl_event_elem_get_mask: [unsigned int, const snd_ctl_event_t *obj] +snd_ctl_event_elem_get_numid: [unsigned int, const snd_ctl_event_t *obj] +snd_ctl_event_elem_get_id: [void, const snd_ctl_event_t *obj, snd_ctl_elem_id_t *ptr] +snd_ctl_event_elem_get_interface: [snd_ctl_elem_iface_t, const snd_ctl_event_t *obj] +snd_ctl_event_elem_get_device: [unsigned int, const snd_ctl_event_t *obj] +snd_ctl_event_elem_get_subdevice: [unsigned int, const snd_ctl_event_t *obj] +snd_ctl_event_elem_get_name: [const char *, const snd_ctl_event_t *obj] +snd_ctl_event_elem_get_index: [unsigned int, const snd_ctl_event_t *obj] +snd_ctl_elem_list_alloc_space: [int, snd_ctl_elem_list_t *obj, unsigned int entries] +snd_ctl_elem_list_free_space: [void, snd_ctl_elem_list_t *obj] +snd_ctl_elem_id_sizeof: [size_t] +snd_ctl_elem_id_malloc: [int, snd_ctl_elem_id_t **ptr] +snd_ctl_elem_id_free: [void, snd_ctl_elem_id_t *obj] +snd_ctl_elem_id_clear: [void, snd_ctl_elem_id_t *obj] +snd_ctl_elem_id_copy: [void, snd_ctl_elem_id_t *dst, const snd_ctl_elem_id_t *src] +snd_ctl_elem_id_get_numid: [unsigned int, const snd_ctl_elem_id_t *obj] +snd_ctl_elem_id_get_interface: [snd_ctl_elem_iface_t, const snd_ctl_elem_id_t *obj] +snd_ctl_elem_id_get_device: [unsigned int, const snd_ctl_elem_id_t *obj] +snd_ctl_elem_id_get_subdevice: [unsigned int, const snd_ctl_elem_id_t *obj] +snd_ctl_elem_id_get_name: [const char *, const snd_ctl_elem_id_t *obj] +snd_ctl_elem_id_get_index: [unsigned int, const snd_ctl_elem_id_t *obj] +snd_ctl_elem_id_set_numid: [void, snd_ctl_elem_id_t *obj, unsigned int val] +snd_ctl_elem_id_set_interface: [void, snd_ctl_elem_id_t *obj, snd_ctl_elem_iface_t val] +snd_ctl_elem_id_set_device: [void, snd_ctl_elem_id_t *obj, unsigned int val] +snd_ctl_elem_id_set_subdevice: [void, snd_ctl_elem_id_t *obj, unsigned int val] +snd_ctl_elem_id_set_name: [void, snd_ctl_elem_id_t *obj, const char *val] +snd_ctl_elem_id_set_index: [void, snd_ctl_elem_id_t *obj, unsigned int val] +snd_ctl_card_info_sizeof: [size_t] +snd_ctl_card_info_malloc: [int, snd_ctl_card_info_t **ptr] +snd_ctl_card_info_free: [void, snd_ctl_card_info_t *obj] +snd_ctl_card_info_clear: [void, snd_ctl_card_info_t *obj] +snd_ctl_card_info_copy: [void, snd_ctl_card_info_t *dst, const snd_ctl_card_info_t *src] +snd_ctl_card_info_get_card: [int, const snd_ctl_card_info_t *obj] +snd_ctl_card_info_get_id: [const char *, const snd_ctl_card_info_t *obj] +snd_ctl_card_info_get_driver: [const char *, const snd_ctl_card_info_t *obj] +snd_ctl_card_info_get_name: [const char *, const snd_ctl_card_info_t *obj] +snd_ctl_card_info_get_longname: [const char *, const snd_ctl_card_info_t *obj] +snd_ctl_card_info_get_mixername: [const char *, const snd_ctl_card_info_t *obj] +snd_ctl_card_info_get_components: [const char *, const snd_ctl_card_info_t *obj] +snd_ctl_event_sizeof: [size_t] +snd_ctl_event_malloc: [int, snd_ctl_event_t **ptr] +snd_ctl_event_free: [void, snd_ctl_event_t *obj] +snd_ctl_event_clear: [void, snd_ctl_event_t *obj] +snd_ctl_event_copy: [void, snd_ctl_event_t *dst, const snd_ctl_event_t *src] +snd_ctl_event_get_type: [snd_ctl_event_type_t, const snd_ctl_event_t *obj] +snd_ctl_elem_list_sizeof: [size_t] +snd_ctl_elem_list_malloc: [int, snd_ctl_elem_list_t **ptr] +snd_ctl_elem_list_free: [void, snd_ctl_elem_list_t *obj] +snd_ctl_elem_list_clear: [void, snd_ctl_elem_list_t *obj] +snd_ctl_elem_list_copy: [void, snd_ctl_elem_list_t *dst, const snd_ctl_elem_list_t *src] +snd_ctl_elem_list_set_offset: [void, snd_ctl_elem_list_t *obj, unsigned int val] +snd_ctl_elem_list_get_used: [unsigned int, const snd_ctl_elem_list_t *obj] +snd_ctl_elem_list_get_count: [unsigned int, const snd_ctl_elem_list_t *obj] +snd_ctl_elem_list_get_id: [void, const snd_ctl_elem_list_t *obj, unsigned int idx, snd_ctl_elem_id_t *ptr] +snd_ctl_elem_list_get_numid: [unsigned int, const snd_ctl_elem_list_t *obj, unsigned int idx] +snd_ctl_elem_list_get_interface: [snd_ctl_elem_iface_t, const snd_ctl_elem_list_t *obj, unsigned int idx] +snd_ctl_elem_list_get_device: [unsigned int, const snd_ctl_elem_list_t *obj, unsigned int idx] +snd_ctl_elem_list_get_subdevice: [unsigned int, const snd_ctl_elem_list_t *obj, unsigned int idx] +snd_ctl_elem_list_get_name: [const char *, const snd_ctl_elem_list_t *obj, unsigned int idx] +snd_ctl_elem_list_get_index: [unsigned int, const snd_ctl_elem_list_t *obj, unsigned int idx] +snd_ctl_elem_info_sizeof: [size_t] +snd_ctl_elem_info_malloc: [int, snd_ctl_elem_info_t **ptr] +snd_ctl_elem_info_free: [void, snd_ctl_elem_info_t *obj] +snd_ctl_elem_info_clear: [void, snd_ctl_elem_info_t *obj] +snd_ctl_elem_info_copy: [void, snd_ctl_elem_info_t *dst, const snd_ctl_elem_info_t *src] +snd_ctl_elem_info_get_type: [snd_ctl_elem_type_t, const snd_ctl_elem_info_t *obj] +snd_ctl_elem_info_is_readable: [int, const snd_ctl_elem_info_t *obj] +snd_ctl_elem_info_is_writable: [int, const snd_ctl_elem_info_t *obj] +snd_ctl_elem_info_is_volatile: [int, const snd_ctl_elem_info_t *obj] +snd_ctl_elem_info_is_inactive: [int, const snd_ctl_elem_info_t *obj] +snd_ctl_elem_info_is_locked: [int, const snd_ctl_elem_info_t *obj] +snd_ctl_elem_info_is_tlv_readable: [int, const snd_ctl_elem_info_t *obj] +snd_ctl_elem_info_is_tlv_writable: [int, const snd_ctl_elem_info_t *obj] +snd_ctl_elem_info_is_tlv_commandable: [int, const snd_ctl_elem_info_t *obj] +snd_ctl_elem_info_is_owner: [int, const snd_ctl_elem_info_t *obj] +snd_ctl_elem_info_is_user: [int, const snd_ctl_elem_info_t *obj] +snd_ctl_elem_info_get_owner: [pid_t, const snd_ctl_elem_info_t *obj] +snd_ctl_elem_info_get_count: [unsigned int, const snd_ctl_elem_info_t *obj] +snd_ctl_elem_info_get_min: [long, const snd_ctl_elem_info_t *obj] +snd_ctl_elem_info_get_max: [long, const snd_ctl_elem_info_t *obj] +snd_ctl_elem_info_get_step: [long, const snd_ctl_elem_info_t *obj] +snd_ctl_elem_info_get_min64: [long long, const snd_ctl_elem_info_t *obj] +snd_ctl_elem_info_get_max64: [long long, const snd_ctl_elem_info_t *obj] +snd_ctl_elem_info_get_step64: [long long, const snd_ctl_elem_info_t *obj] +snd_ctl_elem_info_get_items: [unsigned int, const snd_ctl_elem_info_t *obj] +snd_ctl_elem_info_set_item: [void, snd_ctl_elem_info_t *obj, unsigned int val] +snd_ctl_elem_info_get_item_name: [const char *, const snd_ctl_elem_info_t *obj] +snd_ctl_elem_info_get_dimensions: [int, const snd_ctl_elem_info_t *obj] +snd_ctl_elem_info_get_dimension: [int, const snd_ctl_elem_info_t *obj, unsigned int idx] +snd_ctl_elem_info_get_id: [void, const snd_ctl_elem_info_t *obj, snd_ctl_elem_id_t *ptr] +snd_ctl_elem_info_get_numid: [unsigned int, const snd_ctl_elem_info_t *obj] +snd_ctl_elem_info_get_interface: [snd_ctl_elem_iface_t, const snd_ctl_elem_info_t *obj] +snd_ctl_elem_info_get_device: [unsigned int, const snd_ctl_elem_info_t *obj] +snd_ctl_elem_info_get_subdevice: [unsigned int, const snd_ctl_elem_info_t *obj] +snd_ctl_elem_info_get_name: [const char *, const snd_ctl_elem_info_t *obj] +snd_ctl_elem_info_get_index: [unsigned int, const snd_ctl_elem_info_t *obj] +snd_ctl_elem_info_set_id: [void, snd_ctl_elem_info_t *obj, const snd_ctl_elem_id_t *ptr] +snd_ctl_elem_info_set_numid: [void, snd_ctl_elem_info_t *obj, unsigned int val] +snd_ctl_elem_info_set_interface: [void, snd_ctl_elem_info_t *obj, snd_ctl_elem_iface_t val] +snd_ctl_elem_info_set_device: [void, snd_ctl_elem_info_t *obj, unsigned int val] +snd_ctl_elem_info_set_subdevice: [void, snd_ctl_elem_info_t *obj, unsigned int val] +snd_ctl_elem_info_set_name: [void, snd_ctl_elem_info_t *obj, const char *val] +snd_ctl_elem_info_set_index: [void, snd_ctl_elem_info_t *obj, unsigned int val] +snd_ctl_elem_add_integer: [int, snd_ctl_t *ctl, const snd_ctl_elem_id_t *id, unsigned int count, long imin, long imax, long istep] +snd_ctl_elem_add_integer64: [int, snd_ctl_t *ctl, const snd_ctl_elem_id_t *id, unsigned int count, long long imin, long long imax, long long istep] +snd_ctl_elem_add_boolean: [int, snd_ctl_t *ctl, const snd_ctl_elem_id_t *id, unsigned int count] +snd_ctl_elem_add_iec958: [int, snd_ctl_t *ctl, const snd_ctl_elem_id_t *id] +snd_ctl_elem_remove: [int, snd_ctl_t *ctl, snd_ctl_elem_id_t *id] +snd_ctl_elem_value_sizeof: [size_t] +snd_ctl_elem_value_malloc: [int, snd_ctl_elem_value_t **ptr] +snd_ctl_elem_value_free: [void, snd_ctl_elem_value_t *obj] +snd_ctl_elem_value_clear: [void, snd_ctl_elem_value_t *obj] +snd_ctl_elem_value_copy: [void, snd_ctl_elem_value_t *dst, const snd_ctl_elem_value_t *src] +snd_ctl_elem_value_get_id: [void, const snd_ctl_elem_value_t *obj, snd_ctl_elem_id_t *ptr] +snd_ctl_elem_value_get_numid: [unsigned int, const snd_ctl_elem_value_t *obj] +snd_ctl_elem_value_get_interface: [snd_ctl_elem_iface_t, const snd_ctl_elem_value_t *obj] +snd_ctl_elem_value_get_device: [unsigned int, const snd_ctl_elem_value_t *obj] +snd_ctl_elem_value_get_subdevice: [unsigned int, const snd_ctl_elem_value_t *obj] +snd_ctl_elem_value_get_name: [const char *, const snd_ctl_elem_value_t *obj] +snd_ctl_elem_value_get_index: [unsigned int, const snd_ctl_elem_value_t *obj] +snd_ctl_elem_value_set_id: [void, snd_ctl_elem_value_t *obj, const snd_ctl_elem_id_t *ptr] +snd_ctl_elem_value_set_numid: [void, snd_ctl_elem_value_t *obj, unsigned int val] +snd_ctl_elem_value_set_interface: [void, snd_ctl_elem_value_t *obj, snd_ctl_elem_iface_t val] +snd_ctl_elem_value_set_device: [void, snd_ctl_elem_value_t *obj, unsigned int val] +snd_ctl_elem_value_set_subdevice: [void, snd_ctl_elem_value_t *obj, unsigned int val] +snd_ctl_elem_value_set_name: [void, snd_ctl_elem_value_t *obj, const char *val] +snd_ctl_elem_value_set_index: [void, snd_ctl_elem_value_t *obj, unsigned int val] +snd_ctl_elem_value_get_boolean: [int, const snd_ctl_elem_value_t *obj, unsigned int idx] +snd_ctl_elem_value_get_integer: [long, const snd_ctl_elem_value_t *obj, unsigned int idx] +snd_ctl_elem_value_get_integer64: [long long, const snd_ctl_elem_value_t *obj, unsigned int idx] +snd_ctl_elem_value_get_enumerated: [unsigned int, const snd_ctl_elem_value_t *obj, unsigned int idx] +snd_ctl_elem_value_get_byte: [unsigned char, const snd_ctl_elem_value_t *obj, unsigned int idx] +snd_ctl_elem_value_set_boolean: [void, snd_ctl_elem_value_t *obj, unsigned int idx, long val] +snd_ctl_elem_value_set_integer: [void, snd_ctl_elem_value_t *obj, unsigned int idx, long val] +snd_ctl_elem_value_set_integer64: [void, snd_ctl_elem_value_t *obj, unsigned int idx, long long val] +snd_ctl_elem_value_set_enumerated: [void, snd_ctl_elem_value_t *obj, unsigned int idx, unsigned int val] +snd_ctl_elem_value_set_byte: [void, snd_ctl_elem_value_t *obj, unsigned int idx, unsigned char val] +snd_ctl_elem_set_bytes: [void, snd_ctl_elem_value_t *obj, void *data, size_t size] +snd_ctl_elem_value_get_bytes: [const void *, const snd_ctl_elem_value_t *obj] +snd_ctl_elem_value_get_iec958: [void, const snd_ctl_elem_value_t *obj, snd_aes_iec958_t *ptr] +snd_ctl_elem_value_set_iec958: [void, snd_ctl_elem_value_t *obj, const snd_aes_iec958_t *ptr] +snd_hctl_compare_fast: [int, const snd_hctl_elem_t *c1, const snd_hctl_elem_t *c2] +snd_hctl_open: [int, snd_hctl_t **hctl, const char *name, int mode] +snd_hctl_open_ctl: [int, snd_hctl_t **hctlp, snd_ctl_t *ctl] +snd_hctl_close: [int, snd_hctl_t *hctl] +snd_hctl_nonblock: [int, snd_hctl_t *hctl, int nonblock] +snd_hctl_poll_descriptors_count: [int, snd_hctl_t *hctl] +snd_hctl_poll_descriptors: [int, snd_hctl_t *hctl, struct pollfd *pfds, unsigned int space] +snd_hctl_poll_descriptors_revents: [int, snd_hctl_t *ctl, struct pollfd *pfds, unsigned int nfds, unsigned short *revents] +snd_hctl_get_count: [unsigned int, snd_hctl_t *hctl] +snd_hctl_set_compare: [int, snd_hctl_t *hctl, snd_hctl_compare_t hsort] +snd_hctl_first_elem: [snd_hctl_elem_t *, snd_hctl_t *hctl] +snd_hctl_last_elem: [snd_hctl_elem_t *, snd_hctl_t *hctl] +snd_hctl_find_elem: [snd_hctl_elem_t *, snd_hctl_t *hctl, const snd_ctl_elem_id_t *id] +snd_hctl_set_callback: [void, snd_hctl_t *hctl, snd_hctl_callback_t callback] +snd_hctl_set_callback_private: [void, snd_hctl_t *hctl, void *data] +snd_hctl_get_callback_private: [void *, snd_hctl_t *hctl] +snd_hctl_load: [int, snd_hctl_t *hctl] +snd_hctl_free: [int, snd_hctl_t *hctl] +snd_hctl_handle_events: [int, snd_hctl_t *hctl] +snd_hctl_name: [const char *, snd_hctl_t *hctl] +snd_hctl_wait: [int, snd_hctl_t *hctl, int timeout] +snd_hctl_ctl: [snd_ctl_t *, snd_hctl_t *hctl] +snd_hctl_elem_next: [snd_hctl_elem_t *, snd_hctl_elem_t *elem] +snd_hctl_elem_prev: [snd_hctl_elem_t *, snd_hctl_elem_t *elem] +snd_hctl_elem_info: [int, snd_hctl_elem_t *elem, snd_ctl_elem_info_t * info] +snd_hctl_elem_read: [int, snd_hctl_elem_t *elem, snd_ctl_elem_value_t * value] +snd_hctl_elem_write: [int, snd_hctl_elem_t *elem, snd_ctl_elem_value_t * value] +snd_hctl_elem_tlv_read: [int, snd_hctl_elem_t *elem, unsigned int *tlv, unsigned int tlv_size] +snd_hctl_elem_tlv_write: [int, snd_hctl_elem_t *elem, const unsigned int *tlv] +snd_hctl_elem_tlv_command: [int, snd_hctl_elem_t *elem, const unsigned int *tlv] +snd_hctl_elem_get_hctl: [snd_hctl_t *, snd_hctl_elem_t *elem] +snd_hctl_elem_get_id: [void, const snd_hctl_elem_t *obj, snd_ctl_elem_id_t *ptr] +snd_hctl_elem_get_numid: [unsigned int, const snd_hctl_elem_t *obj] +snd_hctl_elem_get_interface: [snd_ctl_elem_iface_t, const snd_hctl_elem_t *obj] +snd_hctl_elem_get_device: [unsigned int, const snd_hctl_elem_t *obj] +snd_hctl_elem_get_subdevice: [unsigned int, const snd_hctl_elem_t *obj] +snd_hctl_elem_get_name: [const char *, const snd_hctl_elem_t *obj] +snd_hctl_elem_get_index: [unsigned int, const snd_hctl_elem_t *obj] +snd_hctl_elem_set_callback: [void, snd_hctl_elem_t *obj, snd_hctl_elem_callback_t val] +snd_hctl_elem_get_callback_private: [void *, const snd_hctl_elem_t *obj] +snd_hctl_elem_set_callback_private: [void, snd_hctl_elem_t *obj, void * val] +snd_sctl_build: [int, snd_sctl_t **ctl, snd_ctl_t *handle, snd_config_t *config, snd_config_t *private_data, int mode] +snd_sctl_free: [int, snd_sctl_t *handle] +snd_sctl_install: [int, snd_sctl_t *handle] +snd_sctl_remove: [int, snd_sctl_t *handle] + +# mixer.h +snd_mixer_open: [int, snd_mixer_t **mixer, int mode] +snd_mixer_close: [int, snd_mixer_t *mixer] +snd_mixer_first_elem: [snd_mixer_elem_t *, snd_mixer_t *mixer] +snd_mixer_last_elem: [snd_mixer_elem_t *, snd_mixer_t *mixer] +snd_mixer_handle_events: [int, snd_mixer_t *mixer] +snd_mixer_attach: [int, snd_mixer_t *mixer, const char *name] +snd_mixer_attach_hctl: [int, snd_mixer_t *mixer, snd_hctl_t *hctl] +snd_mixer_detach: [int, snd_mixer_t *mixer, const char *name] +snd_mixer_detach_hctl: [int, snd_mixer_t *mixer, snd_hctl_t *hctl] +snd_mixer_get_hctl: [int, snd_mixer_t *mixer, const char *name, snd_hctl_t **hctl] +snd_mixer_poll_descriptors_count: [int, snd_mixer_t *mixer] +snd_mixer_poll_descriptors: [int, snd_mixer_t *mixer, struct pollfd *pfds, unsigned int space] +snd_mixer_poll_descriptors_revents: [int, snd_mixer_t *mixer, struct pollfd *pfds, unsigned int nfds, unsigned short *revents] +snd_mixer_load: [int, snd_mixer_t *mixer] +snd_mixer_free: [void, snd_mixer_t *mixer] +snd_mixer_wait: [int, snd_mixer_t *mixer, int timeout] +snd_mixer_set_compare: [int, snd_mixer_t *mixer, snd_mixer_compare_t msort] +snd_mixer_set_callback: [void, snd_mixer_t *obj, snd_mixer_callback_t val] +snd_mixer_get_callback_private: [void *, const snd_mixer_t *obj] +snd_mixer_set_callback_private: [void, snd_mixer_t *obj, void * val] +snd_mixer_get_count: [unsigned int, const snd_mixer_t *obj] +snd_mixer_class_unregister: [int, snd_mixer_class_t *clss] +snd_mixer_elem_next: [snd_mixer_elem_t *, snd_mixer_elem_t *elem] +snd_mixer_elem_prev: [snd_mixer_elem_t *, snd_mixer_elem_t *elem] +snd_mixer_elem_set_callback: [void, snd_mixer_elem_t *obj, snd_mixer_elem_callback_t val] +snd_mixer_elem_get_callback_private: [void *, const snd_mixer_elem_t *obj] +snd_mixer_elem_set_callback_private: [void, snd_mixer_elem_t *obj, void * val] +snd_mixer_elem_get_type: [snd_mixer_elem_type_t, const snd_mixer_elem_t *obj] +snd_mixer_class_register: [int, snd_mixer_class_t *class_, snd_mixer_t *mixer] +# snd_mixer_add_elem: [int, snd_mixer_t *mixer, snd_mixer_elem_t *elem] +# snd_mixer_remove_elem: [int, snd_mixer_t *mixer, snd_mixer_elem_t *elem] +snd_mixer_elem_new: [int, snd_mixer_elem_t **elem, snd_mixer_elem_type_t type, int compare_weight, void *private_data, void *] +snd_mixer_elem_add: [int, snd_mixer_elem_t *elem, snd_mixer_class_t *class_] +snd_mixer_elem_remove: [int, snd_mixer_elem_t *elem] +snd_mixer_elem_free: [void, snd_mixer_elem_t *elem] +snd_mixer_elem_info: [int, snd_mixer_elem_t *elem] +snd_mixer_elem_value: [int, snd_mixer_elem_t *elem] +snd_mixer_elem_attach: [int, snd_mixer_elem_t *melem, snd_hctl_elem_t *helem] +snd_mixer_elem_detach: [int, snd_mixer_elem_t *melem, snd_hctl_elem_t *helem] +snd_mixer_elem_empty: [int, snd_mixer_elem_t *melem] +snd_mixer_elem_get_private: [void *, const snd_mixer_elem_t *melem] +snd_mixer_class_sizeof: [size_t] +snd_mixer_class_malloc: [int, snd_mixer_class_t **ptr] +snd_mixer_class_free: [void, snd_mixer_class_t *obj] +snd_mixer_class_copy: [void, snd_mixer_class_t *dst, const snd_mixer_class_t *src] +snd_mixer_class_get_mixer: [snd_mixer_t *, const snd_mixer_class_t *class_] +snd_mixer_class_get_event: [snd_mixer_event_t, const snd_mixer_class_t *class_] +snd_mixer_class_get_private: [void *, const snd_mixer_class_t *class_] +snd_mixer_class_get_compare: [snd_mixer_compare_t, const snd_mixer_class_t *class_] +snd_mixer_class_set_event: [int, snd_mixer_class_t *class_, snd_mixer_event_t event] +snd_mixer_class_set_private: [int, snd_mixer_class_t *class_, void *private_data] +snd_mixer_class_set_private_free: [int, snd_mixer_class_t *class_, void *] +snd_mixer_class_set_compare: [int, snd_mixer_class_t *class_, snd_mixer_compare_t compare] +snd_mixer_selem_channel_name: [const char *, snd_mixer_selem_channel_id_t channel] +snd_mixer_selem_register: [int, snd_mixer_t *mixer, struct snd_mixer_selem_regopt *options, snd_mixer_class_t **classp] +snd_mixer_selem_get_id: [void, snd_mixer_elem_t *element, snd_mixer_selem_id_t *id] +snd_mixer_selem_get_name: [const char *, snd_mixer_elem_t *elem] +snd_mixer_selem_get_index: [unsigned int, snd_mixer_elem_t *elem] +snd_mixer_find_selem: [snd_mixer_elem_t *, snd_mixer_t *mixer, const snd_mixer_selem_id_t *id] +snd_mixer_selem_is_active: [int, snd_mixer_elem_t *elem] +snd_mixer_selem_is_playback_mono: [int, snd_mixer_elem_t *elem] +snd_mixer_selem_has_playback_channel: [int, snd_mixer_elem_t *obj, snd_mixer_selem_channel_id_t channel] +snd_mixer_selem_is_capture_mono: [int, snd_mixer_elem_t *elem] +snd_mixer_selem_has_capture_channel: [int, snd_mixer_elem_t *obj, snd_mixer_selem_channel_id_t channel] +snd_mixer_selem_get_capture_group: [int, snd_mixer_elem_t *elem] +snd_mixer_selem_has_common_volume: [int, snd_mixer_elem_t *elem] +snd_mixer_selem_has_playback_volume: [int, snd_mixer_elem_t *elem] +snd_mixer_selem_has_playback_volume_joined: [int, snd_mixer_elem_t *elem] +snd_mixer_selem_has_capture_volume: [int, snd_mixer_elem_t *elem] +snd_mixer_selem_has_capture_volume_joined: [int, snd_mixer_elem_t *elem] +snd_mixer_selem_has_common_switch: [int, snd_mixer_elem_t *elem] +snd_mixer_selem_has_playback_switch: [int, snd_mixer_elem_t *elem] +snd_mixer_selem_has_playback_switch_joined: [int, snd_mixer_elem_t *elem] +snd_mixer_selem_has_capture_switch: [int, snd_mixer_elem_t *elem] +snd_mixer_selem_has_capture_switch_joined: [int, snd_mixer_elem_t *elem] +snd_mixer_selem_has_capture_switch_exclusive: [int, snd_mixer_elem_t *elem] +snd_mixer_selem_get_playback_volume: [int, snd_mixer_elem_t *elem, snd_mixer_selem_channel_id_t channel, long *value] +snd_mixer_selem_get_capture_volume: [int, snd_mixer_elem_t *elem, snd_mixer_selem_channel_id_t channel, long *value] +snd_mixer_selem_get_playback_dB: [int, snd_mixer_elem_t *elem, snd_mixer_selem_channel_id_t channel, long *value] +snd_mixer_selem_get_capture_dB: [int, snd_mixer_elem_t *elem, snd_mixer_selem_channel_id_t channel, long *value] +snd_mixer_selem_get_playback_switch: [int, snd_mixer_elem_t *elem, snd_mixer_selem_channel_id_t channel, int *value] +snd_mixer_selem_get_capture_switch: [int, snd_mixer_elem_t *elem, snd_mixer_selem_channel_id_t channel, int *value] +snd_mixer_selem_set_playback_volume: [int, snd_mixer_elem_t *elem, snd_mixer_selem_channel_id_t channel, long value] +snd_mixer_selem_set_capture_volume: [int, snd_mixer_elem_t *elem, snd_mixer_selem_channel_id_t channel, long value] +snd_mixer_selem_set_playback_dB: [int, snd_mixer_elem_t *elem, snd_mixer_selem_channel_id_t channel, long value, int dir] +snd_mixer_selem_set_capture_dB: [int, snd_mixer_elem_t *elem, snd_mixer_selem_channel_id_t channel, long value, int dir] +snd_mixer_selem_set_playback_volume_all: [int, snd_mixer_elem_t *elem, long value] +snd_mixer_selem_set_capture_volume_all: [int, snd_mixer_elem_t *elem, long value] +snd_mixer_selem_set_playback_dB_all: [int, snd_mixer_elem_t *elem, long value, int dir] +snd_mixer_selem_set_capture_dB_all: [int, snd_mixer_elem_t *elem, long value, int dir] +snd_mixer_selem_set_playback_switch: [int, snd_mixer_elem_t *elem, snd_mixer_selem_channel_id_t channel, int value] +snd_mixer_selem_set_capture_switch: [int, snd_mixer_elem_t *elem, snd_mixer_selem_channel_id_t channel, int value] +snd_mixer_selem_set_playback_switch_all: [int, snd_mixer_elem_t *elem, int value] +snd_mixer_selem_set_capture_switch_all: [int, snd_mixer_elem_t *elem, int value] +snd_mixer_selem_get_playback_volume_range: [int, snd_mixer_elem_t *elem, long *min, long *max] +snd_mixer_selem_get_playback_dB_range: [int, snd_mixer_elem_t *elem, long *min, long *max] +snd_mixer_selem_set_playback_volume_range: [int, snd_mixer_elem_t *elem, long min, long max] +snd_mixer_selem_get_capture_volume_range: [int, snd_mixer_elem_t *elem, long *min, long *max] +snd_mixer_selem_get_capture_dB_range: [int, snd_mixer_elem_t *elem, long *min, long *max] +snd_mixer_selem_set_capture_volume_range: [int, snd_mixer_elem_t *elem, long min, long max] +snd_mixer_selem_is_enumerated: [int, snd_mixer_elem_t *elem] +snd_mixer_selem_is_enum_playback: [int, snd_mixer_elem_t *elem] +snd_mixer_selem_is_enum_capture: [int, snd_mixer_elem_t *elem] +snd_mixer_selem_get_enum_items: [int, snd_mixer_elem_t *elem] +snd_mixer_selem_get_enum_item_name: [int, snd_mixer_elem_t *elem, unsigned int idx, size_t maxlen, char *str] +snd_mixer_selem_get_enum_item: [int, snd_mixer_elem_t *elem, snd_mixer_selem_channel_id_t channel, unsigned int *idxp] +snd_mixer_selem_set_enum_item: [int, snd_mixer_elem_t *elem, snd_mixer_selem_channel_id_t channel, unsigned int idx] +snd_mixer_selem_id_sizeof: [size_t] +snd_mixer_selem_id_malloc: [int, snd_mixer_selem_id_t **ptr] +snd_mixer_selem_id_free: [void, snd_mixer_selem_id_t *obj] +snd_mixer_selem_id_copy: [void, snd_mixer_selem_id_t *dst, const snd_mixer_selem_id_t *src] +snd_mixer_selem_id_get_name: [const char *, const snd_mixer_selem_id_t *obj] +snd_mixer_selem_id_get_index: [unsigned int, const snd_mixer_selem_id_t *obj] +snd_mixer_selem_id_set_name: [void, snd_mixer_selem_id_t *obj, const char *val] +snd_mixer_selem_id_set_index: [void, snd_mixer_selem_id_t *obj, unsigned int val] + +# seq.h +snd_seq_open: [int, snd_seq_t **handle, const char *name, int streams, int mode] +snd_seq_open_lconf: [int, snd_seq_t **handle, const char *name, int streams, int mode, snd_config_t *lconf] +snd_seq_name: [const char *, snd_seq_t *seq] +snd_seq_type: [snd_seq_type_t, snd_seq_t *seq] +snd_seq_close: [int, snd_seq_t *handle] +snd_seq_poll_descriptors_count: [int, snd_seq_t *handle, short events] +snd_seq_poll_descriptors: [int, snd_seq_t *handle, struct pollfd *pfds, unsigned int space, short events] +snd_seq_poll_descriptors_revents: [int, snd_seq_t *seq, struct pollfd *pfds, unsigned int nfds, unsigned short *revents] +snd_seq_nonblock: [int, snd_seq_t *handle, int nonblock] +snd_seq_client_id: [int, snd_seq_t *handle] +snd_seq_get_output_buffer_size: [size_t, snd_seq_t *handle] +snd_seq_get_input_buffer_size: [size_t, snd_seq_t *handle] +snd_seq_set_output_buffer_size: [int, snd_seq_t *handle, size_t size] +snd_seq_set_input_buffer_size: [int, snd_seq_t *handle, size_t size] +snd_seq_system_info_sizeof: [size_t] +snd_seq_system_info_malloc: [int, snd_seq_system_info_t **ptr] +snd_seq_system_info_free: [void, snd_seq_system_info_t *ptr] +snd_seq_system_info_copy: [void, snd_seq_system_info_t *dst, const snd_seq_system_info_t *src] +snd_seq_system_info_get_queues: [int, const snd_seq_system_info_t *info] +snd_seq_system_info_get_clients: [int, const snd_seq_system_info_t *info] +snd_seq_system_info_get_ports: [int, const snd_seq_system_info_t *info] +snd_seq_system_info_get_channels: [int, const snd_seq_system_info_t *info] +snd_seq_system_info_get_cur_clients: [int, const snd_seq_system_info_t *info] +snd_seq_system_info_get_cur_queues: [int, const snd_seq_system_info_t *info] +snd_seq_system_info: [int, snd_seq_t *handle, snd_seq_system_info_t *info] +snd_seq_client_info_sizeof: [size_t] +snd_seq_client_info_malloc: [int, snd_seq_client_info_t **ptr] +snd_seq_client_info_free: [void, snd_seq_client_info_t *ptr] +snd_seq_client_info_copy: [void, snd_seq_client_info_t *dst, const snd_seq_client_info_t *src] +snd_seq_client_info_get_client: [int, const snd_seq_client_info_t *info] +snd_seq_client_info_get_type: [snd_seq_client_type_t, const snd_seq_client_info_t *info] +snd_seq_client_info_get_name: [const char *, snd_seq_client_info_t *info] +snd_seq_client_info_get_broadcast_filter: [int, const snd_seq_client_info_t *info] +snd_seq_client_info_get_error_bounce: [int, const snd_seq_client_info_t *info] +snd_seq_client_info_get_event_filter: [const unsigned char *, const snd_seq_client_info_t *info] +snd_seq_client_info_get_num_ports: [int, const snd_seq_client_info_t *info] +snd_seq_client_info_get_event_lost: [int, const snd_seq_client_info_t *info] +snd_seq_client_info_set_client: [void, snd_seq_client_info_t *info, int client] +snd_seq_client_info_set_name: [void, snd_seq_client_info_t *info, const char *name] +snd_seq_client_info_set_broadcast_filter: [void, snd_seq_client_info_t *info, int val] +snd_seq_client_info_set_error_bounce: [void, snd_seq_client_info_t *info, int val] +snd_seq_client_info_set_event_filter: [void, snd_seq_client_info_t *info, unsigned char *filter] +snd_seq_get_client_info: [int, snd_seq_t *handle, snd_seq_client_info_t *info] +snd_seq_get_any_client_info: [int, snd_seq_t *handle, int client, snd_seq_client_info_t *info] +snd_seq_set_client_info: [int, snd_seq_t *handle, snd_seq_client_info_t *info] +snd_seq_query_next_client: [int, snd_seq_t *handle, snd_seq_client_info_t *info] +snd_seq_client_pool_sizeof: [size_t] +snd_seq_client_pool_malloc: [int, snd_seq_client_pool_t **ptr] +snd_seq_client_pool_free: [void, snd_seq_client_pool_t *ptr] +snd_seq_client_pool_copy: [void, snd_seq_client_pool_t *dst, const snd_seq_client_pool_t *src] +snd_seq_client_pool_get_client: [int, const snd_seq_client_pool_t *info] +snd_seq_client_pool_get_output_pool: [size_t, const snd_seq_client_pool_t *info] +snd_seq_client_pool_get_input_pool: [size_t, const snd_seq_client_pool_t *info] +snd_seq_client_pool_get_output_room: [size_t, const snd_seq_client_pool_t *info] +snd_seq_client_pool_get_output_free: [size_t, const snd_seq_client_pool_t *info] +snd_seq_client_pool_get_input_free: [size_t, const snd_seq_client_pool_t *info] +snd_seq_client_pool_set_output_pool: [void, snd_seq_client_pool_t *info, size_t size] +snd_seq_client_pool_set_input_pool: [void, snd_seq_client_pool_t *info, size_t size] +snd_seq_client_pool_set_output_room: [void, snd_seq_client_pool_t *info, size_t size] +snd_seq_get_client_pool: [int, snd_seq_t *handle, snd_seq_client_pool_t *info] +snd_seq_set_client_pool: [int, snd_seq_t *handle, snd_seq_client_pool_t *info] +snd_seq_port_info_sizeof: [size_t] +snd_seq_port_info_malloc: [int, snd_seq_port_info_t **ptr] +snd_seq_port_info_free: [void, snd_seq_port_info_t *ptr] +snd_seq_port_info_copy: [void, snd_seq_port_info_t *dst, const snd_seq_port_info_t *src] +snd_seq_port_info_get_client: [int, const snd_seq_port_info_t *info] +snd_seq_port_info_get_port: [int, const snd_seq_port_info_t *info] +snd_seq_port_info_get_addr: [const snd_seq_addr_t *, const snd_seq_port_info_t *info] +snd_seq_port_info_get_name: [const char *, const snd_seq_port_info_t *info] +snd_seq_port_info_get_capability: [unsigned int, const snd_seq_port_info_t *info] +snd_seq_port_info_get_type: [unsigned int, const snd_seq_port_info_t *info] +snd_seq_port_info_get_midi_channels: [int, const snd_seq_port_info_t *info] +snd_seq_port_info_get_midi_voices: [int, const snd_seq_port_info_t *info] +snd_seq_port_info_get_synth_voices: [int, const snd_seq_port_info_t *info] +snd_seq_port_info_get_read_use: [int, const snd_seq_port_info_t *info] +snd_seq_port_info_get_write_use: [int, const snd_seq_port_info_t *info] +snd_seq_port_info_get_port_specified: [int, const snd_seq_port_info_t *info] +snd_seq_port_info_get_timestamping: [int, const snd_seq_port_info_t *info] +snd_seq_port_info_get_timestamp_real: [int, const snd_seq_port_info_t *info] +snd_seq_port_info_get_timestamp_queue: [int, const snd_seq_port_info_t *info] +snd_seq_port_info_set_client: [void, snd_seq_port_info_t *info, int client] +snd_seq_port_info_set_port: [void, snd_seq_port_info_t *info, int port] +snd_seq_port_info_set_addr: [void, snd_seq_port_info_t *info, const snd_seq_addr_t *addr] +snd_seq_port_info_set_name: [void, snd_seq_port_info_t *info, const char *name] +snd_seq_port_info_set_capability: [void, snd_seq_port_info_t *info, unsigned int capability] +snd_seq_port_info_set_type: [void, snd_seq_port_info_t *info, unsigned int type] +snd_seq_port_info_set_midi_channels: [void, snd_seq_port_info_t *info, int channels] +snd_seq_port_info_set_midi_voices: [void, snd_seq_port_info_t *info, int voices] +snd_seq_port_info_set_synth_voices: [void, snd_seq_port_info_t *info, int voices] +snd_seq_port_info_set_port_specified: [void, snd_seq_port_info_t *info, int val] +snd_seq_port_info_set_timestamping: [void, snd_seq_port_info_t *info, int enable] +snd_seq_port_info_set_timestamp_real: [void, snd_seq_port_info_t *info, int realtime] +snd_seq_port_info_set_timestamp_queue: [void, snd_seq_port_info_t *info, int queue] +snd_seq_create_port: [int, snd_seq_t *handle, snd_seq_port_info_t *info] +snd_seq_delete_port: [int, snd_seq_t *handle, int port] +snd_seq_get_port_info: [int, snd_seq_t *handle, int port, snd_seq_port_info_t *info] +snd_seq_get_any_port_info: [int, snd_seq_t *handle, int client, int port, snd_seq_port_info_t *info] +snd_seq_set_port_info: [int, snd_seq_t *handle, int port, snd_seq_port_info_t *info] +snd_seq_query_next_port: [int, snd_seq_t *handle, snd_seq_port_info_t *info] +snd_seq_port_subscribe_sizeof: [size_t] +snd_seq_port_subscribe_malloc: [int, snd_seq_port_subscribe_t **ptr] +snd_seq_port_subscribe_free: [void, snd_seq_port_subscribe_t *ptr] +snd_seq_port_subscribe_copy: [void, snd_seq_port_subscribe_t *dst, const snd_seq_port_subscribe_t *src] +snd_seq_port_subscribe_get_sender: [const snd_seq_addr_t *, const snd_seq_port_subscribe_t *info] +snd_seq_port_subscribe_get_dest: [const snd_seq_addr_t *, const snd_seq_port_subscribe_t *info] +snd_seq_port_subscribe_get_queue: [int, const snd_seq_port_subscribe_t *info] +snd_seq_port_subscribe_get_exclusive: [int, const snd_seq_port_subscribe_t *info] +snd_seq_port_subscribe_get_time_update: [int, const snd_seq_port_subscribe_t *info] +snd_seq_port_subscribe_get_time_real: [int, const snd_seq_port_subscribe_t *info] +snd_seq_port_subscribe_set_sender: [void, snd_seq_port_subscribe_t *info, const snd_seq_addr_t *addr] +snd_seq_port_subscribe_set_dest: [void, snd_seq_port_subscribe_t *info, const snd_seq_addr_t *addr] +snd_seq_port_subscribe_set_queue: [void, snd_seq_port_subscribe_t *info, int q] +snd_seq_port_subscribe_set_exclusive: [void, snd_seq_port_subscribe_t *info, int val] +snd_seq_port_subscribe_set_time_update: [void, snd_seq_port_subscribe_t *info, int val] +snd_seq_port_subscribe_set_time_real: [void, snd_seq_port_subscribe_t *info, int val] +snd_seq_get_port_subscription: [int, snd_seq_t *handle, snd_seq_port_subscribe_t *sub] +snd_seq_subscribe_port: [int, snd_seq_t *handle, snd_seq_port_subscribe_t *sub] +snd_seq_unsubscribe_port: [int, snd_seq_t *handle, snd_seq_port_subscribe_t *sub] +snd_seq_query_subscribe_sizeof: [size_t] +snd_seq_query_subscribe_malloc: [int, snd_seq_query_subscribe_t **ptr] +snd_seq_query_subscribe_free: [void, snd_seq_query_subscribe_t *ptr] +snd_seq_query_subscribe_copy: [void, snd_seq_query_subscribe_t *dst, const snd_seq_query_subscribe_t *src] +snd_seq_query_subscribe_get_client: [int, const snd_seq_query_subscribe_t *info] +snd_seq_query_subscribe_get_port: [int, const snd_seq_query_subscribe_t *info] +snd_seq_query_subscribe_get_root: [const snd_seq_addr_t *, const snd_seq_query_subscribe_t *info] +snd_seq_query_subscribe_get_type: [snd_seq_query_subs_type_t, const snd_seq_query_subscribe_t *info] +snd_seq_query_subscribe_get_index: [int, const snd_seq_query_subscribe_t *info] +snd_seq_query_subscribe_get_num_subs: [int, const snd_seq_query_subscribe_t *info] +snd_seq_query_subscribe_get_addr: [const snd_seq_addr_t *, const snd_seq_query_subscribe_t *info] +snd_seq_query_subscribe_get_queue: [int, const snd_seq_query_subscribe_t *info] +snd_seq_query_subscribe_get_exclusive: [int, const snd_seq_query_subscribe_t *info] +snd_seq_query_subscribe_get_time_update: [int, const snd_seq_query_subscribe_t *info] +snd_seq_query_subscribe_get_time_real: [int, const snd_seq_query_subscribe_t *info] +snd_seq_query_subscribe_set_client: [void, snd_seq_query_subscribe_t *info, int client] +snd_seq_query_subscribe_set_port: [void, snd_seq_query_subscribe_t *info, int port] +snd_seq_query_subscribe_set_root: [void, snd_seq_query_subscribe_t *info, const snd_seq_addr_t *addr] +snd_seq_query_subscribe_set_type: [void, snd_seq_query_subscribe_t *info, snd_seq_query_subs_type_t type] +snd_seq_query_subscribe_set_index: [void, snd_seq_query_subscribe_t *info, int _index] +snd_seq_query_port_subscribers: [int, snd_seq_t *seq, snd_seq_query_subscribe_t * subs] +snd_seq_queue_info_sizeof: [size_t] +snd_seq_queue_info_malloc: [int, snd_seq_queue_info_t **ptr] +snd_seq_queue_info_free: [void, snd_seq_queue_info_t *ptr] +snd_seq_queue_info_copy: [void, snd_seq_queue_info_t *dst, const snd_seq_queue_info_t *src] +snd_seq_queue_info_get_queue: [int, const snd_seq_queue_info_t *info] +snd_seq_queue_info_get_name: [const char *, const snd_seq_queue_info_t *info] +snd_seq_queue_info_get_owner: [int, const snd_seq_queue_info_t *info] +snd_seq_queue_info_get_locked: [int, const snd_seq_queue_info_t *info] +snd_seq_queue_info_get_flags: [unsigned int, const snd_seq_queue_info_t *info] +snd_seq_queue_info_set_name: [void, snd_seq_queue_info_t *info, const char *name] +snd_seq_queue_info_set_owner: [void, snd_seq_queue_info_t *info, int owner] +snd_seq_queue_info_set_locked: [void, snd_seq_queue_info_t *info, int locked] +snd_seq_queue_info_set_flags: [void, snd_seq_queue_info_t *info, unsigned int flags] +snd_seq_create_queue: [int, snd_seq_t *seq, snd_seq_queue_info_t *info] +snd_seq_alloc_named_queue: [int, snd_seq_t *seq, const char *name] +snd_seq_alloc_queue: [int, snd_seq_t *handle] +snd_seq_free_queue: [int, snd_seq_t *handle, int q] +snd_seq_get_queue_info: [int, snd_seq_t *seq, int q, snd_seq_queue_info_t *info] +snd_seq_set_queue_info: [int, snd_seq_t *seq, int q, snd_seq_queue_info_t *info] +snd_seq_query_named_queue: [int, snd_seq_t *seq, const char *name] +snd_seq_get_queue_usage: [int, snd_seq_t *handle, int q] +snd_seq_set_queue_usage: [int, snd_seq_t *handle, int q, int used] +snd_seq_queue_status_sizeof: [size_t] +snd_seq_queue_status_malloc: [int, snd_seq_queue_status_t **ptr] +snd_seq_queue_status_free: [void, snd_seq_queue_status_t *ptr] +snd_seq_queue_status_copy: [void, snd_seq_queue_status_t *dst, const snd_seq_queue_status_t *src] +snd_seq_queue_status_get_queue: [int, const snd_seq_queue_status_t *info] +snd_seq_queue_status_get_events: [int, const snd_seq_queue_status_t *info] +snd_seq_queue_status_get_tick_time: [snd_seq_tick_time_t, const snd_seq_queue_status_t *info] +snd_seq_queue_status_get_real_time: [const snd_seq_real_time_t *, const snd_seq_queue_status_t *info] +snd_seq_queue_status_get_status: [unsigned int, const snd_seq_queue_status_t *info] +snd_seq_get_queue_status: [int, snd_seq_t *handle, int q, snd_seq_queue_status_t *status] +snd_seq_queue_tempo_sizeof: [size_t] +snd_seq_queue_tempo_malloc: [int, snd_seq_queue_tempo_t **ptr] +snd_seq_queue_tempo_free: [void, snd_seq_queue_tempo_t *ptr] +snd_seq_queue_tempo_copy: [void, snd_seq_queue_tempo_t *dst, const snd_seq_queue_tempo_t *src] +snd_seq_queue_tempo_get_queue: [int, const snd_seq_queue_tempo_t *info] +snd_seq_queue_tempo_get_tempo: [unsigned int, const snd_seq_queue_tempo_t *info] +snd_seq_queue_tempo_get_ppq: [int, const snd_seq_queue_tempo_t *info] +snd_seq_queue_tempo_get_skew: [unsigned int, const snd_seq_queue_tempo_t *info] +snd_seq_queue_tempo_get_skew_base: [unsigned int, const snd_seq_queue_tempo_t *info] +snd_seq_queue_tempo_set_tempo: [void, snd_seq_queue_tempo_t *info, unsigned int tempo] +snd_seq_queue_tempo_set_ppq: [void, snd_seq_queue_tempo_t *info, int ppq] +snd_seq_queue_tempo_set_skew: [void, snd_seq_queue_tempo_t *info, unsigned int skew] +snd_seq_queue_tempo_set_skew_base: [void, snd_seq_queue_tempo_t *info, unsigned int base] +snd_seq_get_queue_tempo: [int, snd_seq_t *handle, int q, snd_seq_queue_tempo_t *tempo] +snd_seq_set_queue_tempo: [int, snd_seq_t *handle, int q, snd_seq_queue_tempo_t *tempo] +snd_seq_queue_timer_sizeof: [size_t] +snd_seq_queue_timer_malloc: [int, snd_seq_queue_timer_t **ptr] +snd_seq_queue_timer_free: [void, snd_seq_queue_timer_t *ptr] +snd_seq_queue_timer_copy: [void, snd_seq_queue_timer_t *dst, const snd_seq_queue_timer_t *src] +snd_seq_queue_timer_get_queue: [int, const snd_seq_queue_timer_t *info] +snd_seq_queue_timer_get_type: [snd_seq_queue_timer_type_t, const snd_seq_queue_timer_t *info] +snd_seq_queue_timer_get_id: [const snd_timer_id_t *, const snd_seq_queue_timer_t *info] +snd_seq_queue_timer_get_resolution: [unsigned int, const snd_seq_queue_timer_t *info] +snd_seq_queue_timer_set_type: [void, snd_seq_queue_timer_t *info, snd_seq_queue_timer_type_t type] +snd_seq_queue_timer_set_id: [void, snd_seq_queue_timer_t *info, const snd_timer_id_t *id] +snd_seq_queue_timer_set_resolution: [void, snd_seq_queue_timer_t *info, unsigned int resolution] +snd_seq_get_queue_timer: [int, snd_seq_t *handle, int q, snd_seq_queue_timer_t *timer] +snd_seq_set_queue_timer: [int, snd_seq_t *handle, int q, snd_seq_queue_timer_t *timer] +snd_seq_free_event: [int, snd_seq_event_t *ev] +snd_seq_event_length: [ssize_t, snd_seq_event_t *ev] +snd_seq_event_output: [int, snd_seq_t *handle, snd_seq_event_t *ev] +snd_seq_event_output_buffer: [int, snd_seq_t *handle, snd_seq_event_t *ev] +snd_seq_event_output_direct: [int, snd_seq_t *handle, snd_seq_event_t *ev] +snd_seq_event_input: [int, snd_seq_t *handle, snd_seq_event_t **ev] +snd_seq_event_input_pending: [int, snd_seq_t *seq, int fetch_sequencer] +snd_seq_drain_output: [int, snd_seq_t *handle] +snd_seq_event_output_pending: [int, snd_seq_t *seq] +snd_seq_extract_output: [int, snd_seq_t *handle, snd_seq_event_t **ev] +snd_seq_drop_output: [int, snd_seq_t *handle] +snd_seq_drop_output_buffer: [int, snd_seq_t *handle] +snd_seq_drop_input: [int, snd_seq_t *handle] +snd_seq_drop_input_buffer: [int, snd_seq_t *handle] +snd_seq_remove_events_sizeof: [size_t] +snd_seq_remove_events_malloc: [int, snd_seq_remove_events_t **ptr] +snd_seq_remove_events_free: [void, snd_seq_remove_events_t *ptr] +snd_seq_remove_events_copy: [void, snd_seq_remove_events_t *dst, const snd_seq_remove_events_t *src] +snd_seq_remove_events_get_condition: [unsigned int, const snd_seq_remove_events_t *info] +snd_seq_remove_events_get_queue: [int, const snd_seq_remove_events_t *info] +snd_seq_remove_events_get_time: [const snd_seq_timestamp_t *, const snd_seq_remove_events_t *info] +snd_seq_remove_events_get_dest: [const snd_seq_addr_t *, const snd_seq_remove_events_t *info] +snd_seq_remove_events_get_channel: [int, const snd_seq_remove_events_t *info] +snd_seq_remove_events_get_event_type: [int, const snd_seq_remove_events_t *info] +snd_seq_remove_events_get_tag: [int, const snd_seq_remove_events_t *info] +snd_seq_remove_events_set_condition: [void, snd_seq_remove_events_t *info, unsigned int flags] +snd_seq_remove_events_set_queue: [void, snd_seq_remove_events_t *info, int queue] +snd_seq_remove_events_set_time: [void, snd_seq_remove_events_t *info, const snd_seq_timestamp_t *time] +snd_seq_remove_events_set_dest: [void, snd_seq_remove_events_t *info, const snd_seq_addr_t *addr] +snd_seq_remove_events_set_channel: [void, snd_seq_remove_events_t *info, int channel] +snd_seq_remove_events_set_event_type: [void, snd_seq_remove_events_t *info, int type] +snd_seq_remove_events_set_tag: [void, snd_seq_remove_events_t *info, int tag] +snd_seq_remove_events: [int, snd_seq_t *handle, snd_seq_remove_events_t *info] +snd_seq_set_bit: [void, int nr, void *array] +snd_seq_change_bit: [int, int nr, void *array] +snd_seq_get_bit: [int, int nr, void *array] + +# seq_midi_event.h +snd_midi_event_new: [int, size_t bufsize, snd_midi_event_t **rdev] +snd_midi_event_resize_buffer: [int, snd_midi_event_t *dev, size_t bufsize] +snd_midi_event_free: [void, snd_midi_event_t *dev] +snd_midi_event_init: [void, snd_midi_event_t *dev] +snd_midi_event_reset_encode: [void, snd_midi_event_t *dev] +snd_midi_event_reset_decode: [void, snd_midi_event_t *dev] +snd_midi_event_no_status: [void, snd_midi_event_t *dev, int on] +snd_midi_event_encode: [long, snd_midi_event_t *dev, const unsigned char *buf, long count, snd_seq_event_t *ev] +snd_midi_event_encode_byte: [int, snd_midi_event_t *dev, int c, snd_seq_event_t *ev] +snd_midi_event_decode: [long, snd_midi_event_t *dev, unsigned char *buf, long count, const snd_seq_event_t *ev] + +# seqmid.c +snd_seq_control_queue: [int, snd_seq_t *seq, int q, int type, int value, snd_seq_event_t *ev] +snd_seq_create_simple_port: [int, snd_seq_t *seq, const char *name, unsigned int caps, unsigned int type] +snd_seq_delete_simple_port: [int, snd_seq_t *seq, int port] +snd_seq_connect_from: [int, snd_seq_t *seq, int myport, int src_client, int src_port] +snd_seq_connect_to: [int, snd_seq_t *seq, int myport, int dest_client, int dest_port] +snd_seq_disconnect_from: [int, snd_seq_t *seq, int myport, int src_client, int src_port] +snd_seq_disconnect_to: [int, snd_seq_t *seq, int myport, int dest_client, int dest_port] +snd_seq_set_client_name: [int, snd_seq_t *seq, const char *name] +snd_seq_set_client_event_filter: [int, snd_seq_t *seq, int event_type] +snd_seq_set_client_pool_output_room: [int, snd_seq_t *seq, size_t size] +snd_seq_set_client_pool_input: [int, snd_seq_t *seq, size_t size] +snd_seq_reset_pool_output: [int, snd_seq_t *seq] +snd_seq_reset_pool_input: [int, snd_seq_t *seq] +snd_seq_sync_output_queue: [int, snd_seq_t *seq] +snd_seq_parse_address: [int, snd_seq_t *seq, snd_seq_addr_t *addr, const char *arg] diff --git a/Projects/Android/jni/SupportLibs/gl4es/spec/yml/egl.yml b/Projects/Android/jni/SupportLibs/gl4es/spec/yml/egl.yml new file mode 100644 index 0000000..94b0f44 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/spec/yml/egl.yml @@ -0,0 +1,108 @@ +eglBindAPI: [EGLBoolean, EGLenum api] +eglBindTexImage: [EGLBoolean, EGLDisplay dpy, EGLSurface surface, EGLint buffer] +eglChooseConfig: [EGLBoolean, EGLDisplay dpy, const EGLint * attrib_list, EGLConfig + * configs, EGLint config_size, EGLint * num_config] +eglClientWaitSyncKHR: [EGLint, EGLDisplay dpy, EGLSyncKHR sync, EGLint flags, EGLTimeKHR + timeout] +eglClientWaitSyncNV: [EGLint, EGLSyncNV sync, EGLint flags, EGLTimeNV timeout] +eglCopyBuffers: [EGLBoolean, EGLDisplay dpy, EGLSurface surface, EGLNativePixmapType + target] +eglCreateContext: [EGLContext, EGLDisplay dpy, EGLConfig config, EGLContext share_context, + const EGLint * attrib_list] +eglCreateDRMImageMESA: [EGLImageKHR, EGLDisplay dpy, const EGLint * attrib_list] +eglCreateFenceSyncNV: [EGLSyncNV, EGLDisplay dpy, EGLenum condition, const EGLint + * attrib_list] +eglCreateImageKHR: [EGLImageKHR, EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer + buffer, const EGLint * attrib_list] +eglCreatePbufferFromClientBuffer: [EGLSurface, EGLDisplay dpy, EGLenum buftype, EGLClientBuffer + buffer, EGLConfig config, const EGLint * attrib_list] +eglCreatePbufferSurface: [EGLSurface, EGLDisplay dpy, EGLConfig config, const EGLint + * attrib_list] +eglCreatePixmapSurface: [EGLSurface, EGLDisplay dpy, EGLConfig config, EGLNativePixmapType + pixmap, const EGLint * attrib_list] +eglCreatePixmapSurfaceHI: [EGLSurface, EGLDisplay dpy, EGLConfig config, struct EGLClientPixmapHI + * pixmap] +eglCreateStreamFromFileDescriptorKHR: [EGLStreamKHR, EGLDisplay dpy, EGLNativeFileDescriptorKHR + file_descriptor] +eglCreateStreamKHR: [EGLStreamKHR, EGLDisplay dpy, const EGLint * attrib_list] +eglCreateStreamProducerSurfaceKHR: [EGLSurface, EGLDisplay dpy, EGLConfig config, + EGLStreamKHR stream, const EGLint * attrib_list] +eglCreateSyncKHR: [EGLSyncKHR, EGLDisplay dpy, EGLenum type, const EGLint * attrib_list] +eglCreateWindowSurface: [EGLSurface, EGLDisplay dpy, EGLConfig config, EGLNativeWindowType + win, const EGLint * attrib_list] +eglDestroyContext: [EGLBoolean, EGLDisplay dpy, EGLContext ctx] +eglDestroyImageKHR: [EGLBoolean, EGLDisplay dpy, EGLImageKHR image] +eglDestroyStreamKHR: [EGLBoolean, EGLDisplay dpy, EGLStreamKHR stream] +eglDestroySurface: [EGLBoolean, EGLDisplay dpy, EGLSurface surface] +eglDestroySyncKHR: [EGLBoolean, EGLDisplay dpy, EGLSyncKHR sync] +eglDestroySyncNV: [EGLBoolean, EGLSyncNV sync] +eglDupNativeFenceFDANDROID: [EGLint, EGLDisplay dpy, EGLSyncKHR sync] +eglExportDRMImageMESA: [EGLBoolean, EGLDisplay dpy, EGLImageKHR image, EGLint * name, + EGLint * handle, EGLint * stride] +eglFenceNV: [EGLBoolean, EGLSyncNV sync] +eglGetConfigAttrib: [EGLBoolean, EGLDisplay dpy, EGLConfig config, EGLint attribute, + EGLint * value] +eglGetConfigs: [EGLBoolean, EGLDisplay dpy, EGLConfig * configs, EGLint config_size, + EGLint * num_config] +eglGetCurrentContext: [EGLContext] +eglGetCurrentDisplay: [EGLDisplay] +eglGetCurrentSurface: [EGLSurface, EGLint readdraw] +eglGetDisplay: [EGLDisplay, EGLNativeDisplayType display_id] +eglGetError: [EGLint] +eglGetProcAddress: [__eglMustCastToProperFunctionPointerType, const char * procname] +eglGetStreamFileDescriptorKHR: [EGLNativeFileDescriptorKHR, EGLDisplay dpy, EGLStreamKHR + stream] +eglGetSyncAttribKHR: [EGLBoolean, EGLDisplay dpy, EGLSyncKHR sync, EGLint attribute, + EGLint * value] +eglGetSyncAttribNV: [EGLBoolean, EGLSyncNV sync, EGLint attribute, EGLint * value] +eglGetSystemTimeFrequencyNV: [EGLuint64NV] +eglGetSystemTimeNV: [EGLuint64NV] +eglInitialize: [EGLBoolean, EGLDisplay dpy, EGLint * major, EGLint * minor] +eglLockSurfaceKHR: [EGLBoolean, EGLDisplay display, EGLSurface surface, const EGLint + * attrib_list] +eglMakeCurrent: [EGLBoolean, EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext + ctx] +eglPostSubBufferNV: [EGLBoolean, EGLDisplay dpy, EGLSurface surface, EGLint x, EGLint + y, EGLint width, EGLint height] +eglQueryAPI: [EGLenum] +eglQueryContext: [EGLBoolean, EGLDisplay dpy, EGLContext ctx, EGLint attribute, EGLint + * value] +eglQueryNativeDisplayNV: [EGLBoolean, EGLDisplay dpy, EGLNativeDisplayType * display_id] +eglQueryNativePixmapNV: [EGLBoolean, EGLDisplay dpy, EGLSurface surf, EGLNativePixmapType + * pixmap] +eglQueryNativeWindowNV: [EGLBoolean, EGLDisplay dpy, EGLSurface surf, EGLNativeWindowType + * window] +eglQueryStreamKHR: [EGLBoolean, EGLDisplay dpy, EGLStreamKHR stream, EGLenum attribute, + EGLint * value] +eglQueryStreamTimeKHR: [EGLBoolean, EGLDisplay dpy, EGLStreamKHR stream, EGLenum attribute, + EGLTimeKHR * value] +eglQueryStreamu64KHR: [EGLBoolean, EGLDisplay dpy, EGLStreamKHR stream, EGLenum attribute, + EGLuint64KHR * value] +eglQueryString: [const char *, EGLDisplay dpy, EGLint name] +eglQuerySurface: [EGLBoolean, EGLDisplay dpy, EGLSurface surface, EGLint attribute, + EGLint * value] +eglQuerySurfacePointerANGLE: [EGLBoolean, EGLDisplay dpy, EGLSurface surface, EGLint + attribute, void ** value] +eglReleaseTexImage: [EGLBoolean, EGLDisplay dpy, EGLSurface surface, EGLint buffer] +eglReleaseThread: [EGLBoolean] +eglSetBlobCacheFuncsANDROID: ['void ', EGLDisplay dpy, EGLSetBlobFuncANDROID set, + EGLGetBlobFuncANDROID get] +eglSignalSyncKHR: [EGLBoolean, EGLDisplay dpy, EGLSyncKHR sync, EGLenum mode] +eglSignalSyncNV: [EGLBoolean, EGLSyncNV sync, EGLenum mode] +eglStreamAttribKHR: [EGLBoolean, EGLDisplay dpy, EGLStreamKHR stream, EGLenum attribute, + EGLint value] +eglStreamConsumerAcquireKHR: [EGLBoolean, EGLDisplay dpy, EGLStreamKHR stream] +eglStreamConsumerGLTextureExternalKHR: [EGLBoolean, EGLDisplay dpy, EGLStreamKHR stream] +eglStreamConsumerReleaseKHR: [EGLBoolean, EGLDisplay dpy, EGLStreamKHR stream] +eglSurfaceAttrib: [EGLBoolean, EGLDisplay dpy, EGLSurface surface, EGLint attribute, + EGLint value] +eglSwapBuffers: [EGLBoolean, EGLDisplay dpy, EGLSurface surface] +eglSwapBuffersWithDamageEXT: [EGLBoolean, EGLDisplay dpy, EGLSurface surface, EGLint + * rects, EGLint n_rects] +eglSwapInterval: [EGLBoolean, EGLDisplay dpy, EGLint interval] +eglTerminate: [EGLBoolean, EGLDisplay dpy] +eglUnlockSurfaceKHR: [EGLBoolean, EGLDisplay display, EGLSurface surface] +eglWaitClient: [EGLBoolean] +eglWaitGL: [EGLBoolean] +eglWaitNative: [EGLBoolean, EGLint engine] +eglWaitSyncKHR: [EGLint, EGLDisplay dpy, EGLSyncKHR sync, EGLint flags] diff --git a/Projects/Android/jni/SupportLibs/gl4es/spec/yml/gles-1.1.yml b/Projects/Android/jni/SupportLibs/gl4es/spec/yml/gles-1.1.yml new file mode 100644 index 0000000..4dcc9b2 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/spec/yml/gles-1.1.yml @@ -0,0 +1,148 @@ +#GLES 1.1 Core +glActiveTexture: [void, GLenum texture] +glAlphaFunc: [void, GLenum func, GLclampf ref] +glAlphaFuncx: [void, GLenum func, GLclampx ref] +glBindBuffer: [void, GLenum target, GLuint buffer] +glBindTexture: [void, GLenum target, GLuint texture] +glBlendFunc: [void, GLenum sfactor, GLenum dfactor] +glBufferData: [void, GLenum target, GLsizeiptr size, "const GLvoid *data", GLenum usage] +glBufferSubData: [void, GLenum target, GLintptr offset, GLsizeiptr size, "const GLvoid *data"] +glClear: [void, GLbitfield mask] +glClearColor: [void, GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha] +glClearColorx: [void, GLclampx red, GLclampx green, GLclampx blue, GLclampx alpha] +glClearDepthf: [void, GLclampf depth] +glClearDepthx: [void, GLclampx depth] +glClearStencil: [void, GLint s] +glClientActiveTexture: [void, GLenum texture] +glClipPlanef: [void, GLenum plane, "const GLfloat *equation"] +glClipPlanex: [void, GLenum plane, "const GLfixed *equation"] +glColor4f: [void, GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha] +glColor4ub: [void, GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha] +glColor4x: [void, GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha] +glColorMask: [void, GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha] +glColorPointer: [void, GLint size, GLenum type, GLsizei stride, "const GLvoid *pointer"] +glCompressedTexImage2D: [void, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, "const GLvoid *data"] +glCompressedTexSubImage2D: [void, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, "const GLvoid *data"] +glCopyTexImage2D: [void, GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border] +glCopyTexSubImage2D: [void, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height] +glCullFace: [void, GLenum mode] +glDeleteBuffers: [void, GLsizei n, "const GLuint *buffers"] +glDeleteTextures: [void, GLsizei n, "const GLuint *textures"] +glDepthFunc: [void, GLenum func] +glDepthMask: [void, GLboolean flag] +glDepthRangef: [void, GLclampf near, GLclampf far] +glDepthRangex: [void, GLclampx near, GLclampx far] +glDisable: [void, GLenum cap] +glDisableClientState: [void, GLenum array] +glDisableClientState: [void, GLenum array] +glDrawArrays: [void, GLenum mode, GLint first, GLsizei count] +glDrawElements: [void, GLenum mode, GLsizei count, GLenum type, "const GLvoid *indices"] +glEnable: [void, GLenum cap] +glEnableClientState: [void, GLenum array] +glEnableClientState: [void, GLenum array] +glFinish: [void, void] +glFlush: [void, void] +glFogf: [void, GLenum pname, GLfloat param] +glFogfv: [void, GLenum pname, "const GLfloat *params"] +glFogx: [void, GLenum pname, GLfixed param] +glFogxv: [void, GLenum pname, "const GLfixed *params"] +glFrontFace: [void, GLenum mode] +glFrustumf: [void, GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat near, GLfloat far] +glFrustumx: [void, GLfixed left, GLfixed right, GLfixed bottom, GLfixed top, GLfixed near, GLfixed far] +glGenBuffers: [void, GLsizei n, "GLuint *buffers"] +glGenTextures: [void, GLsizei n, "GLuint *textures"] +glGetBooleanv: [void, GLenum pname, "GLboolean *params"] +glGetBufferParameteriv: [void, GLenum target, GLenum pname, "GLint *params"] +glGetClipPlanef: [void, GLenum plane, "GLfloat *equation"] +glGetClipPlanex: [void, GLenum plane, "GLfixed *equation"] +glGetError: [GLenum, void] +glGetFixedv: [void, GLenum pname, "GLfixed *params"] +glGetFloatv: [void, GLenum pname, "GLfloat *params"] +glGetIntegerv: [void, GLenum pname, "GLint *params"] +glGetLightfv: [void, GLenum light, GLenum pname, "GLfloat *params"] +glGetLightxv: [void, GLenum light, GLenum pname, "GLfixed *params"] +glGetMaterialfv: [void, GLenum face, GLenum pname, "GLfloat *params"] +glGetMaterialxv: [void, GLenum face, GLenum pname, "GLfixed *params"] +glGetPointerv: [void, GLenum pname, "GLvoid **params"] +glGetString: [const GLubyte *, GLenum name] +glGetTexEnvfv: [void, GLenum target, GLenum pname, "GLfloat *params"] +glGetTexEnviv: [void, GLenum target, GLenum pname, "GLint *params"] +glGetTexEnvxv: [void, GLenum target, GLenum pname, "GLfixed *params"] +glGetTexParameterfv: [void, GLenum target, GLenum pname, "GLfloat *params"] +glGetTexParameteriv: [void, GLenum target, GLenum pname, "GLint *params"] +glGetTexParameterxv: [void, GLenum target, GLenum pname, "GLfixed *params"] +glHint: [void, GLenum target, GLenum mode] +glIsBuffer: [GLboolean, GLuint buffer] +glIsEnabled: [GLboolean, GLenum cap] +glIsTexture: [GLboolean, GLuint texture] +glLightf: [void, GLenum light, GLenum pname, GLfloat param] +glLightfv: [void, GLenum light, GLenum pname, "const GLfloat *params"] +glLightModelf: [void, GLenum pname, GLfloat param] +glLightModelfv: [void, GLenum pname, "const GLfloat *params"] +glLightModelx: [void, GLenum pname, GLfixed param] +glLightModelxv: [void, GLenum pname, "const GLfixed *params"] +glLightx: [void, GLenum light, GLenum pname, GLfixed param] +glLightxv: [void, GLenum light, GLenum pname, "const GLfixed *params"] +glLineWidth: [void, GLfloat width] +glLineWidthx: [void, GLfixed width] +glLoadIdentity: [void, void] +glLoadMatrixf: [void, "const GLfloat *m"] +glLoadMatrixx: [void, "const GLfixed *m"] +glLogicOp: [void, GLenum opcode] +glMaterialf: [void, GLenum face, GLenum pname, GLfloat param] +glMaterialfv: [void, GLenum face, GLenum pname, "const GLfloat *params"] +glMaterialx: [void, GLenum face, GLenum pname, GLfixed param] +glMaterialxv: [void, GLenum face, GLenum pname, "const GLfixed *params"] +glMatrixMode: [void, GLenum mode] +glMultiTexCoord4f: [void, GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q] +glMultiTexCoord4x: [void, GLenum target, GLfixed s, GLfixed t, GLfixed r, GLfixed q] +glMultMatrixf: [void, "const GLfloat *m"] +glMultMatrixx: [void, "const GLfixed *m"] +glNormal3f: [void, GLfloat nx, GLfloat ny, GLfloat nz] +glNormal3x: [void, GLfixed nx, GLfixed ny, GLfixed nz] +glNormalPointer: [void, GLenum type, GLsizei stride, "const GLvoid *pointer"] +glOrthof: [void, GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat near, GLfloat far] +glOrthox: [void, GLfixed left, GLfixed right, GLfixed bottom, GLfixed top, GLfixed near, GLfixed far] +glPixelStorei: [void, GLenum pname, GLint param] +glPointParameterf: [void, GLenum pname, GLfloat param] +glPointParameterfv: [void, GLenum pname, "const GLfloat *params"] +glPointParameterx: [void, GLenum pname, GLfixed param] +glPointParameterxv: [void, GLenum pname, "const GLfixed *params"] +glPointSize: [void, GLfloat size] +glPointSizePointerOES: [void, GLenum type, GLsizei stride, "const GLvoid *pointer"] +glPointSizex: [void, GLfixed size] +glPolygonOffset: [void, GLfloat factor, GLfloat units] +glPolygonOffsetx: [void, GLfixed factor, GLfixed units] +glPopMatrix: [void, void] +glPushMatrix: [void, void] +glReadPixels: [void, GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, "GLvoid *pixels"] +glRotatef: [void, GLfloat angle, GLfloat x, GLfloat y, GLfloat z] +glRotatex: [void, GLfixed angle, GLfixed x, GLfixed y, GLfixed z] +glSampleCoverage: [void, GLclampf value, GLboolean invert] +glSampleCoveragex: [void, GLclampx value, GLboolean invert] +glScalef: [void, GLfloat x, GLfloat y, GLfloat z] +glScalex: [void, GLfixed x, GLfixed y, GLfixed z] +glScissor: [void, GLint x, GLint y, GLsizei width, GLsizei height] +glShadeModel: [void, GLenum mode] +glStencilFunc: [void, GLenum func, GLint ref, GLuint mask] +glStencilMask: [void, GLuint mask] +glStencilOp: [void, GLenum fail, GLenum zfail, GLenum zpass] +glTexCoordPointer: [void, GLint size, GLenum type, GLsizei stride, "const GLvoid *pointer"] +glTexEnvf: [void, GLenum target, GLenum pname, GLfloat param] +glTexEnvfv: [void, GLenum target, GLenum pname, "const GLfloat *params"] +glTexEnvi: [void, GLenum target, GLenum pname, GLint param] +glTexEnviv: [void, GLenum target, GLenum pname, "const GLint *params"] +glTexEnvx: [void, GLenum target, GLenum pname, GLfixed param] +glTexEnvxv: [void, GLenum target, GLenum pname, "const GLfixed *params"] +glTexImage2D: [void, GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, "const GLvoid *data"] +glTexParameterf: [void, GLenum target, GLenum pname, GLfloat param] +glTexParameterfv: [void, GLenum target, GLenum pname, "const GLfloat *params"] +glTexParameteri: [void, GLenum target, GLenum pname, GLint param] +glTexParameteriv: [void, GLenum target, GLenum pname, "const GLint *params"] +glTexParameterx: [void, GLenum target, GLenum pname, GLfixed param] +glTexParameterxv: [void, GLenum target, GLenum pname, "const GLfixed *params"] +glTexSubImage2D: [void, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, "const GLvoid *data"] +glTranslatef: [void, GLfloat x, GLfloat y, GLfloat z] +glTranslatex: [void, GLfixed x, GLfixed y, GLfixed z] +glVertexPointer: [void, GLint size, GLenum type, GLsizei stride, "const GLvoid *pointer"] +glViewport: [void, GLint x, GLint y, GLsizei width, GLsizei height] diff --git a/Projects/Android/jni/SupportLibs/gl4es/spec/yml/gles-2.0.yml b/Projects/Android/jni/SupportLibs/gl4es/spec/yml/gles-2.0.yml new file mode 100644 index 0000000..dac8860 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/spec/yml/gles-2.0.yml @@ -0,0 +1,169 @@ +glActiveTexture: [void, GLenum texture] +glAttachShader: [void, GLuint program, GLuint shader] +glBindAttribLocation: [void, GLuint program, GLuint index, const GLchar * name] +glBindBuffer: [void, GLenum target, GLuint buffer] +glBindFramebuffer: [void, GLenum target, GLuint framebuffer] +glBindRenderbuffer: [void, GLenum target, GLuint renderbuffer] +glBindTexture: [void, GLenum target, GLuint texture] +glBlendColor: [void, GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha] +glBlendEquation: [void, GLenum mode] +glBlendEquationSeparate: [void, GLenum modeRGB, GLenum modeA] +glBlendFunc: [void, GLenum sfactor, GLenum dfactor] +glBlendFuncSeparate: [void, GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, + GLenum dfactorAlpha] +glBufferData: [void, GLenum target, GLsizeiptr size, const GLvoid * data, GLenum usage] +glBufferSubData: [void, GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid + * data] +glCheckFramebufferStatus: [GLenum, GLenum target] +glClear: [void, GLbitfield mask] +glClearColor: [void, GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha] +glClearDepthf: [void, GLclampf depth] +glClearStencil: [void, GLint s] +glColorMask: [void, GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha] +glCompileShader: [void, GLuint shader] +glCompressedTexImage2D: [void, GLenum target, GLint level, GLenum internalformat, + GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid * data] +glCompressedTexSubImage2D: [void, GLenum target, GLint level, GLint xoffset, GLint + yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const + GLvoid * data] +glCopyTexImage2D: [void, GLenum target, GLint level, GLenum internalformat, GLint + x, GLint y, GLsizei width, GLsizei height, GLint border] +glCopyTexSubImage2D: [void, GLenum target, GLint level, GLint xoffset, GLint yoffset, + GLint x, GLint y, GLsizei width, GLsizei height] +glCreateProgram: [GLuint] +glCreateShader: [GLuint, GLenum type] +glCullFace: [void, GLenum mode] +glDeleteBuffers: [void, GLsizei n, const GLuint * buffer] +glDeleteFramebuffers: [void, GLsizei n, const GLuint * framebuffers] +glDeleteProgram: [void, GLuint program] +glDeleteRenderbuffers: [void, GLsizei n, const GLuint * renderbuffers] +glDeleteShader: [void, GLuint program] +glDeleteTextures: [void, GLsizei n, const GLuint * textures] +glDepthFunc: [void, GLenum func] +glDepthMask: [void, GLboolean flag] +glDepthRangef: [void, GLclampf zNear, GLclampf zFar] +glDetachShader: [void, GLuint program, GLuint shader] +glDisable: [void, GLenum cap] +glDisableVertexAttribArray: [void, GLuint index] +glDrawArrays: [void, GLenum mode, GLint first, GLsizei count] +glDrawElements: [void, GLenum mode, GLsizei count, GLenum type, const GLvoid * indices] +glEnable: [void, GLenum cap] +glEnableVertexAttribArray: [void, GLuint index] +glFinish: [void] +glFlush: [void] +glFramebufferRenderbuffer: [void, GLenum target, GLenum attachment, GLenum renderbuffertarget, + GLuint renderbuffer] +glFramebufferTexture2D: [void, GLenum target, GLenum attachment, GLenum textarget, + GLuint texture, GLint level] +glFrontFace: [void, GLenum mode] +glGenBuffers: [void, GLsizei n, GLuint * buffer] +glGenFramebuffers: [void, GLsizei n, GLuint * framebuffers] +glGenRenderbuffers: [void, GLsizei n, GLuint * renderbuffers] +glGenTextures: [void, GLsizei n, GLuint * textures] +glGenerateMipmap: [void, GLenum target] +glGetActiveAttrib: [void, GLuint program, GLuint index, GLsizei bufSize, GLsizei * + length, GLint * size, GLenum * type, GLchar * name] +glGetActiveUniform: [void, GLuint program, GLuint index, GLsizei bufSize, GLsizei + * length, GLint * size, GLenum * type, GLchar * name] +glGetAttachedShaders: [void, GLuint program, GLsizei maxCount, GLsizei * count, GLuint + * obj] +glGetAttribLocation: [GLint, GLuint program, const GLchar * name] +glGetBooleanv: [void, GLenum pname, GLboolean * params] +glGetBufferParameteriv: [void, GLenum target, GLenum pname, GLint * params] +glGetError: [GLenum] +glGetFloatv: [void, GLenum pname, GLfloat * params] +glGetFramebufferAttachmentParameteriv: [void, GLenum target, GLenum attachment, GLenum + pname, GLint * params] +glGetIntegerv: [void, GLenum pname, GLint * params] +glGetProgramInfoLog: [void, GLuint program, GLsizei bufSize, GLsizei * length, GLchar + * infoLog] +glGetProgramiv: [void, GLuint program, GLenum pname, GLint * params] +glGetRenderbufferParameteriv: [void, GLenum target, GLenum pname, GLint * params] +glGetShaderInfoLog: [void, GLuint shader, GLsizei bufSize, GLsizei * length, GLchar + * infoLog] +glGetShaderPrecisionFormat: [void, GLenum shadertype, GLenum precisiontype, GLint + * range, GLint * precision] +glGetShaderSource: [void, GLuint shader, GLsizei bufSize, GLsizei * length, GLchar + * source] +glGetShaderiv: [void, GLuint shader, GLenum pname, GLint * params] +glGetString: [const GLubyte *, GLenum name] +glGetTexParameterfv: [void, GLenum target, GLenum pname, GLfloat * params] +glGetTexParameteriv: [void, GLenum target, GLenum pname, GLint * params] +glGetUniformLocation: [GLint, GLuint program, const GLchar * name] +glGetUniformfv: [void, GLuint program, GLint location, GLfloat * params] +glGetUniformiv: [void, GLuint program, GLint location, GLint * params] +glGetVertexAttribPointerv: [void, GLuint index, GLenum pname, GLvoid ** pointer] +glGetVertexAttribfv: [void, GLuint index, GLenum pname, GLfloat * params] +glGetVertexAttribiv: [void, GLuint index, GLenum pname, GLint * params] +glHint: [void, GLenum target, GLenum mode] +glIsBuffer: [GLboolean, GLuint buffer] +glIsEnabled: [GLboolean, GLenum cap] +glIsFramebuffer: [GLboolean, GLuint framebuffer] +glIsProgram: [GLboolean, GLuint program] +glIsRenderbuffer: [GLboolean, GLuint renderbuffer] +glIsShader: [GLboolean, GLuint shader] +glIsTexture: [GLboolean, GLuint texture] +glLineWidth: [void, GLfloat width] +glLinkProgram: [void, GLuint program] +glPixelStorei: [void, GLenum pname, GLint param] +glPolygonOffset: [void, GLfloat factor, GLfloat units] +glReadPixels: [void, GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, + GLenum type, GLvoid * pixels] +glReleaseShaderCompiler: [void] +glRenderbufferStorage: [void, GLenum target, GLenum internalformat, GLsizei width, + GLsizei height] +glSampleCoverage: [void, GLclampf value, GLboolean invert] +glScissor: [void, GLint x, GLint y, GLsizei width, GLsizei height] +glShaderBinary: [void, GLsizei n, const GLuint * shaders, GLenum binaryformat, const + GLvoid * binary, GLsizei length] +glShaderSource: [void, GLuint shader, GLsizei count, const GLchar * const * string, + const GLint * length] +glStencilFunc: [void, GLenum func, GLint ref, GLuint mask] +glStencilFuncSeparate: [void, GLenum face, GLenum func, GLint ref, GLuint mask] +glStencilMask: [void, GLuint mask] +glStencilMaskSeparate: [void, GLenum face, GLuint mask] +glStencilOp: [void, GLenum fail, GLenum zfail, GLenum zpass] +glStencilOpSeparate: [void, GLenum face, GLenum sfail, GLenum zfail, GLenum zpass] +glTexImage2D: [void, GLenum target, GLint level, GLint internalformat, GLsizei width, + GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid * pixels] +glTexParameterf: [void, GLenum target, GLenum pname, GLfloat param] +glTexParameterfv: [void, GLenum target, GLenum pname, const GLfloat * params] +glTexParameteri: [void, GLenum target, GLenum pname, GLint param] +glTexParameteriv: [void, GLenum target, GLenum pname, const GLint * params] +glTexSubImage2D: [void, GLenum target, GLint level, GLint xoffset, GLint yoffset, + GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid * pixels] +glUniform1f: [void, GLint location, GLfloat v0] +glUniform1fv: [void, GLint location, GLsizei count, const GLfloat * value] +glUniform1i: [void, GLint location, GLint v0] +glUniform1iv: [void, GLint location, GLsizei count, const GLint * value] +glUniform2f: [void, GLint location, GLfloat v0, GLfloat v1] +glUniform2fv: [void, GLint location, GLsizei count, const GLfloat * value] +glUniform2i: [void, GLint location, GLint v0, GLint v1] +glUniform2iv: [void, GLint location, GLsizei count, const GLint * value] +glUniform3f: [void, GLint location, GLfloat v0, GLfloat v1, GLfloat v2] +glUniform3fv: [void, GLint location, GLsizei count, const GLfloat * value] +glUniform3i: [void, GLint location, GLint v0, GLint v1, GLint v2] +glUniform3iv: [void, GLint location, GLsizei count, const GLint * value] +glUniform4f: [void, GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3] +glUniform4fv: [void, GLint location, GLsizei count, const GLfloat * value] +glUniform4i: [void, GLint location, GLint v0, GLint v1, GLint v2, GLint v3] +glUniform4iv: [void, GLint location, GLsizei count, const GLint * value] +glUniformMatrix2fv: [void, GLint location, GLsizei count, GLboolean transpose, const + GLfloat * value] +glUniformMatrix3fv: [void, GLint location, GLsizei count, GLboolean transpose, const + GLfloat * value] +glUniformMatrix4fv: [void, GLint location, GLsizei count, GLboolean transpose, const + GLfloat * value] +glUseProgram: [void, GLuint program] +glValidateProgram: [void, GLuint program] +glVertexAttrib1f: [void, GLuint index, GLfloat x] +glVertexAttrib1fv: [void, GLuint index, const GLfloat * v] +glVertexAttrib2f: [void, GLuint index, GLfloat x, GLfloat y] +glVertexAttrib2fv: [void, GLuint index, const GLfloat * v] +glVertexAttrib3f: [void, GLuint index, GLfloat x, GLfloat y, GLfloat z] +glVertexAttrib3fv: [void, GLuint index, const GLfloat * v] +glVertexAttrib4f: [void, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w] +glVertexAttrib4fv: [void, GLuint index, const GLfloat * v] +glVertexAttribPointer: [void, GLuint index, GLint size, GLenum type, GLboolean normalized, + GLsizei stride, const GLvoid * pointer] +glViewport: [void, GLint x, GLint y, GLsizei width, GLsizei height] diff --git a/Projects/Android/jni/SupportLibs/gl4es/spec/yml/glext-1.1.yml b/Projects/Android/jni/SupportLibs/gl4es/spec/yml/glext-1.1.yml new file mode 100644 index 0000000..9122a7f --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/spec/yml/glext-1.1.yml @@ -0,0 +1,31 @@ +#GLES 1.1 Extensions (might be GLES 2.0 Core) +glBlendColor_OES_: [void, GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha] +glBlendEquation_OES_: [void, GLenum mode] +glBlendEquationSeparate_OES_: [void, GLenum modeRGB, GLenum modeA] +glBlendFuncSeparate_OES_: [void, GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha] +# glTexGenfOES_OES_: [void, GLenum coord, GLenum pname, GLfloat param] +glTexGenfv_OES_: [void, GLenum coord, GLenum pname, "const GLfloat *params"] +glTexGeni_OES_: [void, GLenum coord, GLenum pname, GLint param] +# glTexGenivOES_OES_: [void, GLenum coord, GLenum pname, "const GLint *params"] + +glGenFramebuffers_OES_: [void, GLsizei n, "GLuint *ids"] +glDeleteFramebuffers_OES_: [void, GLsizei n, "GLuint *framebuffers"] +glIsFramebuffer_OES_: [GLboolean, GLuint framebuffer] +glCheckFramebufferStatus_OES_: [GLenum, GLenum target] +glBindFramebuffer_OES_: [void, GLenum target, GLuint framebuffer] +glFramebufferTexture2D_OES_: [void, GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level] +glGenRenderbuffers_OES_: [void, GLsizei n, "GLuint *renderbuffers"] +glFramebufferRenderbuffer_OES_: [void, GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer] +glDeleteRenderbuffers_OES_: [void, GLsizei n, "GLuint *renderbuffers"] +glRenderbufferStorage_OES_: [void, GLenum target, GLenum internalformat, GLsizei width, GLsizei height] +glBindRenderbuffer_OES_: [void, GLenum target, GLuint renderbuffer] +glIsRenderbuffer_OES_: [GLboolean, GLuint renderbuffer] +glGenerateMipmap_OES_: [void, GLenum target] +glGetFramebufferAttachmentParameteriv_OES_: [void, GLenum target, GLenum attachment, GLenum pname, "GLint *params"] +glGetRenderbufferParameteriv_OES_: [void, GLenum target, GLenum pname, "GLint * params"] + +glDrawTexi_OES_: [void, GLint x, GLint y, GLint z, GLint width, GLint height] +glDrawTexf_OES_: [void, GLfloat x, GLfloat y, GLfloat z, GLfloat width, GLfloat height] + +glMultiDrawArrays_OES_: [void, GLenum mode, "const GLint *first", "const GLsizei *count", GLsizei primcount] +glMultiDrawElements_OES_: [void, GLenum mode, "GLsizei *count", GLenum type, "const void * const *indices", GLsizei primcount] diff --git a/Projects/Android/jni/SupportLibs/gl4es/spec/yml/glext-es2-1.1.yml b/Projects/Android/jni/SupportLibs/gl4es/spec/yml/glext-es2-1.1.yml new file mode 100644 index 0000000..a3ab59c --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/spec/yml/glext-es2-1.1.yml @@ -0,0 +1,93 @@ +#GLES 2.0 Core (minus GLES 1.1 core+ext functions) +glAttachShader: [void, GLuint program, GLuint shader] +glBindAttribLocation: [void, GLuint program, GLuint index, const GLchar * name] +glBindBuffer: [void, GLenum target, GLuint buffer] +glBufferData: [void, GLenum target, GLsizeiptr size, const GLvoid * data, GLenum usage] +glBufferSubData: [void, GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid + * data] +glCompileShader: [void, GLuint shader] +glCreateProgram: [GLuint] +glCreateShader: [GLuint, GLenum type] +glDeleteBuffers: [void, GLsizei n, const GLuint * buffer] +glDeleteProgram: [void, GLuint program] +glDeleteShader: [void, GLuint shader] +glDetachShader: [void, GLuint program, GLuint shader] +glDisableVertexAttribArray: [void, GLuint index] +glEnableVertexAttribArray: [void, GLuint index] +glGenBuffers: [void, GLsizei n, GLuint * buffer] +glGetActiveAttrib: [void, GLuint program, GLuint index, GLsizei bufSize, GLsizei * + length, GLint * size, GLenum * type, GLchar * name] +glGetActiveUniform: [void, GLuint program, GLuint index, GLsizei bufSize, GLsizei + * length, GLint * size, GLenum * type, GLchar * name] +glGetAttachedShaders: [void, GLuint program, GLsizei maxCount, GLsizei * count, GLuint + * obj] +glGetAttribLocation: [GLint, GLuint program, const GLchar * name] +glGetBufferParameteriv: [void, GLenum target, GLenum pname, GLint * params] +glGetProgramInfoLog: [void, GLuint program, GLsizei bufSize, GLsizei * length, GLchar + * infoLog] +glGetProgramiv: [void, GLuint program, GLenum pname, GLint * params] +glGetShaderInfoLog: [void, GLuint shader, GLsizei bufSize, GLsizei * length, GLchar + * infoLog] +glGetShaderPrecisionFormat: [void, GLenum shadertype, GLenum precisiontype, GLint + * range, GLint * precision] +glGetShaderSource: [void, GLuint shader, GLsizei bufSize, GLsizei * length, GLchar + * source] +glGetShaderiv: [void, GLuint shader, GLenum pname, GLint * params] +glGetUniformLocation: [GLint, GLuint program, const GLchar * name] +glGetUniformfv: [void, GLuint program, GLint location, GLfloat * params] +glGetUniformiv: [void, GLuint program, GLint location, GLint * params] +glGetVertexAttribPointerv: [void, GLuint index, GLenum pname, GLvoid ** pointer] +glGetVertexAttribfv: [void, GLuint index, GLenum pname, GLfloat * params] +glGetVertexAttribiv: [void, GLuint index, GLenum pname, GLint * params] +glIsBuffer: [GLboolean, GLuint buffer] +glIsProgram: [GLboolean, GLuint program] +glIsShader: [GLboolean, GLuint shader] +glLinkProgram: [void, GLuint program] +glReleaseShaderCompiler: [void] +glShaderBinary: [void, GLsizei n, const GLuint * shaders, GLenum binaryformat, const + GLvoid * binary, GLsizei length] +glShaderSource: [void, GLuint shader, GLsizei count, const GLchar * const * string, + const GLint * length] +glStencilFuncSeparate: [void, GLenum face, GLenum func, GLint ref, GLuint mask] +glStencilMaskSeparate: [void, GLenum face, GLuint mask] +glStencilOpSeparate: [void, GLenum face, GLenum sfail, GLenum zfail, GLenum zpass] +glUniform1f: [void, GLint location, GLfloat v0] +glUniform1fv: [void, GLint location, GLsizei count, const GLfloat * value] +glUniform1i: [void, GLint location, GLint v0] +glUniform1iv: [void, GLint location, GLsizei count, const GLint * value] +glUniform2f: [void, GLint location, GLfloat v0, GLfloat v1] +glUniform2fv: [void, GLint location, GLsizei count, const GLfloat * value] +glUniform2i: [void, GLint location, GLint v0, GLint v1] +glUniform2iv: [void, GLint location, GLsizei count, const GLint * value] +glUniform3f: [void, GLint location, GLfloat v0, GLfloat v1, GLfloat v2] +glUniform3fv: [void, GLint location, GLsizei count, const GLfloat * value] +glUniform3i: [void, GLint location, GLint v0, GLint v1, GLint v2] +glUniform3iv: [void, GLint location, GLsizei count, const GLint * value] +glUniform4f: [void, GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3] +glUniform4fv: [void, GLint location, GLsizei count, const GLfloat * value] +glUniform4i: [void, GLint location, GLint v0, GLint v1, GLint v2, GLint v3] +glUniform4iv: [void, GLint location, GLsizei count, const GLint * value] +glUniformMatrix2fv: [void, GLint location, GLsizei count, GLboolean transpose, const + GLfloat * value] +glUniformMatrix3fv: [void, GLint location, GLsizei count, GLboolean transpose, const + GLfloat * value] +glUniformMatrix4fv: [void, GLint location, GLsizei count, GLboolean transpose, const + GLfloat * value] +glUseProgram: [void, GLuint program] +glValidateProgram: [void, GLuint program] +glVertexAttrib1f: [void, GLuint index, GLfloat x] +glVertexAttrib1fv: [void, GLuint index, const GLfloat * v] +glVertexAttrib2f: [void, GLuint index, GLfloat x, GLfloat y] +glVertexAttrib2fv: [void, GLuint index, const GLfloat * v] +glVertexAttrib3f: [void, GLuint index, GLfloat x, GLfloat y, GLfloat z] +glVertexAttrib3fv: [void, GLuint index, const GLfloat * v] +glVertexAttrib4f: [void, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w] +glVertexAttrib4fv: [void, GLuint index, const GLfloat * v] +glVertexAttribPointer: [void, GLuint index, GLint size, GLenum type, GLboolean normalized, + GLsizei stride, const GLvoid * pointer] + + +#Other function, probably in no GLES version +glFogCoordf: [void, GLfloat coord] +glFogCoordfv: [void, const GLfloat * coord] +glFogCoordPointer: [void, GLenum type, GLsizei stride, const GLvoid * pointer] diff --git a/Projects/Android/jni/SupportLibs/gl4es/spec/yml/glx.yml b/Projects/Android/jni/SupportLibs/gl4es/spec/yml/glx.yml new file mode 100644 index 0000000..2acd025 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/spec/yml/glx.yml @@ -0,0 +1,68 @@ +glx: + glXBindHyperpipeSGIX: [int, Display *dpy, int hpId] + glXBindSwapBarrierSGIX: [void, uint32_t window, uint32_t barrier] + glXChangeDrawableAttributes: [void, uint32_t drawable] + glXChangeDrawableAttributesSGIX: [void, uint32_t drawable] + glXClientInfo: [void] + glXCopyContext: [void, uint32_t source, uint32_t dest, uint32_t mask] + glXCreateContext: [void, uint32_t gc_id, uint32_t screen, uint32_t visual, uint32_t + share_list] + glXCreateContextWithConfigSGIX: [void, uint32_t gc_id, uint32_t screen, uint32_t + config, uint32_t share_list] + glXCreateGLXPbufferSGIX: [void, uint32_t config, uint32_t pbuffer] + glXCreateGLXPixmap: [void, uint32_t visual, uint32_t pixmap, uint32_t glxpixmap] + glXCreateGLXPixmapWithConfigSGIX: [void, uint32_t config, uint32_t pixmap, uint32_t + glxpixmap] + glXCreateGLXVideoSourceSGIX: [void, uint32_t dpy, uint32_t screen, uint32_t server, + uint32_t path, uint32_t class, uint32_t node] + glXCreateNewContext: [void, uint32_t config, uint32_t render_type, uint32_t share_list, + uint32_t direct] + glXCreatePbuffer: [void, uint32_t config, uint32_t pbuffer] + glXCreatePixmap: [void, uint32_t config, uint32_t pixmap, uint32_t glxpixmap] + glXCreateWindow: [void, uint32_t config, uint32_t window, uint32_t glxwindow] + glXDestroyContext: [void, uint32_t context] + glXDestroyGLXPbufferSGIX: [void, uint32_t pbuffer] + glXDestroyGLXPixmap: [void, uint32_t pixmap] + glXDestroyGLXVideoSourceSGIX: [void, uint32_t dpy, uint32_t glxvideosource] + glXDestroyHyperpipeConfigSGIX: [int, Display *dpy, int hpId] + glXDestroyPbuffer: [void, uint32_t pbuffer] + glXDestroyPixmap: [void, uint32_t glxpixmap] + glXDestroyWindow: [void, uint32_t glxwindow] + glXGetDrawableAttributes: [void, uint32_t drawable] + glXGetDrawableAttributesSGIX: [void, uint32_t drawable] + glXGetFBConfigs: [void] + glXGetFBConfigsSGIX: [void] + glXGetVisualConfigs: [void] + glXHyperpipeAttribSGIX: [int, Display *dpy, int timeSlice, int attrib, int size, + const void *attribList] + glXHyperpipeConfigSGIX: [int, Display *dpy, int networkId, int npipes, GLXHyperpipeConfigSGIX + cfg, int *hpId] + glXIsDirect: [void, uint32_t dpy, uint32_t context] + glXJoinSwapGroupSGIX: [void, uint32_t window, uint32_t group] + glXMakeContextCurrent: [void, uint32_t drawable, uint32_t readdrawable, uint32_t + context] + glXMakeCurrent: [void, uint32_t drawable, uint32_t context] + glXMakeCurrentReadSGI: [void, uint32_t drawable, uint32_t readdrawable, uint32_t + context] + glXQueryContext: [void] + glXQueryContextInfoEXT: [void] + glXQueryExtensionsString: [void, uint32_t screen] + glXQueryHyperpipeAttribSGIX: [int, Display *dpy, int timeSlice, int attrib, int + size, const void *returnAttribList] + glXQueryHyperpipeBestAttribSGIX: [int, Display *dpy, int timeSlice, int attrib, + int size, const void *attribList, void *returnAttribList] + glXQueryHyperpipeConfigSGIX: [GLXHyperpipeConfigSGIX *, Display *dpy, int hpId, + int *npipes] + glXQueryHyperpipeNetworkSGIX: [GLXHyperpipeNetworkSGIX *, Display *dpy, int *npipes] + glXQueryMaxSwapBarriersSGIX: [void] + glXQueryServerString: [void, uint32_t screen, uint32_t name] + glXQueryVersion: [void, uint32_t *major, uint32_t *minor] + glXRender: [void] + glXRenderLarge: [void] + glXSwapBuffers: [void, uint32_t drawable] + glXSwapIntervalSGI: [void] + glXUseXFont: [void, uint32_t font, uint32_t first, uint32_t count, uint32_t list_base] + glXVendorPrivate: [void] + glXVendorPrivateWithReply: [void] + glXWaitGL: [void, uint32_t context] + glXWaitX: [void] diff --git a/Projects/Android/jni/SupportLibs/gl4es/spec/yml/glxext.yml b/Projects/Android/jni/SupportLibs/gl4es/spec/yml/glxext.yml new file mode 100644 index 0000000..07b139d --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/spec/yml/glxext.yml @@ -0,0 +1,178 @@ +ARB_create_context: + glXCreateContextAttribsARB: [GLXContext, Display *dpy, GLXFBConfig config, GLXContext + share_context, Bool direct, const int *attrib_list] +ARB_get_proc_address: + glXGetProcAddressARB: [__GLXextFuncPtr, const GLubyte *procName] +EXT_import_context: + glXFreeContextEXT: [void, Display *dpy, GLXContext context] + glXGetContextIDEXT: [GLXContextID, const GLXContext context] + glXGetCurrentDisplayEXT: [Display *] + glXImportContextEXT: [GLXContext, Display *dpy, GLXContextID contextID] + glXQueryContextInfoEXT: [int, Display *dpy, GLXContext context, int attribute, int + *value] +EXT_swap_control: + glXSwapIntervalEXT: [void, Display *dpy, GLXDrawable drawable, int interval] +EXT_texture_from_pixmap: + glXBindTexImageEXT: [void, Display *dpy, GLXDrawable drawable, int buffer, const + int *attrib_list] + glXReleaseTexImageEXT: [void, Display *dpy, GLXDrawable drawable, int buffer] +MESA_agp_offset: + glXGetAGPOffsetMESA: [unsigned int, const void *pointer] +MESA_copy_sub_buffer: + glXCopySubBufferMESA: [void, Display *dpy, GLXDrawable drawable, int x, int y, int + width, int height] +MESA_pixmap_colormap: + glXCreateGLXPixmapMESA: [GLXPixmap, Display *dpy, XVisualInfo *visual, Pixmap pixmap, + Colormap cmap] +MESA_release_buffers: + glXReleaseBuffersMESA: [Bool, Display *dpy, GLXDrawable drawable] +MESA_set_3dfx_mode: + glXSet3DfxModeMESA: [Bool, int mode] +NV_copy_image: + glXCopyImageSubDataNV: [void, Display *dpy, GLXContext srcCtx, GLuint srcName, GLenum + srcTarget, GLint srcLevel, GLint srcX, GLint srcY, GLint srcZ, GLXContext dstCtx, + GLuint dstName, GLenum dstTarget, GLint dstLevel, GLint dstX, GLint dstY, GLint + dstZ, GLsizei width, GLsizei height, GLsizei depth] +NV_present_video: + glXBindVideoDeviceNV: [int, Display *dpy, unsigned int video_slot, unsigned int + video_device, const int *attrib_list] + glXEnumerateVideoDevicesNV: [unsigned int *, Display *dpy, int screen, int *nelements] +NV_swap_group: + glXBindSwapBarrierNV: [Bool, Display *dpy, GLuint group, GLuint barrier] + glXJoinSwapGroupNV: [Bool, Display *dpy, GLXDrawable drawable, GLuint group] + glXQueryFrameCountNV: [Bool, Display *dpy, int screen, GLuint *count] + glXQueryMaxSwapGroupsNV: [Bool, Display *dpy, int screen, GLuint *maxGroups, GLuint + *maxBarriers] + glXQuerySwapGroupNV: [Bool, Display *dpy, GLXDrawable drawable, GLuint *group, GLuint + *barrier] + glXResetFrameCountNV: [Bool, Display *dpy, int screen] +NV_video_capture: + glXBindVideoCaptureDeviceNV: [int, Display *dpy, unsigned int video_capture_slot, + GLXVideoCaptureDeviceNV device] + glXEnumerateVideoCaptureDevicesNV: [GLXVideoCaptureDeviceNV *, Display *dpy, int + screen, int *nelements] + glXLockVideoCaptureDeviceNV: [void, Display *dpy, GLXVideoCaptureDeviceNV device] + glXQueryVideoCaptureDeviceNV: [int, Display *dpy, GLXVideoCaptureDeviceNV device, + int attribute, int *value] + glXReleaseVideoCaptureDeviceNV: [void, Display *dpy, GLXVideoCaptureDeviceNV device] +NV_video_output: + glXBindVideoImageNV: [int, Display *dpy, GLXVideoDeviceNV VideoDevice, GLXPbuffer + pbuf, int iVideoBuffer] + glXGetVideoDeviceNV: [int, Display *dpy, int screen, int numVideoDevices, GLXVideoDeviceNV + *pVideoDevice] + glXGetVideoInfoNV: [int, Display *dpy, int screen, GLXVideoDeviceNV VideoDevice, + unsigned long *pulCounterOutputPbuffer, unsigned long *pulCounterOutputVideo] + glXReleaseVideoDeviceNV: [int, Display *dpy, int screen, GLXVideoDeviceNV VideoDevice] + glXReleaseVideoImageNV: [int, Display *dpy, GLXPbuffer pbuf] + glXSendPbufferToVideoNV: [int, Display *dpy, GLXPbuffer pbuf, int iBufferType, unsigned + long *pulCounterPbuffer, GLboolean bBlock] +OML_sync_control: + glXGetMscRateOML: [Bool, Display *dpy, GLXDrawable drawable, int32_t *numerator, + int32_t *denominator] + glXGetSyncValuesOML: [Bool, Display *dpy, GLXDrawable drawable, int64_t *ust, int64_t + *msc, int64_t *sbc] + glXSwapBuffersMscOML: [int64_t, Display *dpy, GLXDrawable drawable, int64_t target_msc, + int64_t divisor, int64_t remainder] + glXWaitForMscOML: [Bool, Display *dpy, GLXDrawable drawable, int64_t target_msc, + int64_t divisor, int64_t remainder, int64_t *ust, int64_t *msc, int64_t *sbc] + glXWaitForSbcOML: [Bool, Display *dpy, GLXDrawable drawable, int64_t target_sbc, + int64_t *ust, int64_t *msc, int64_t *sbc] +SGIX_dmbuffer: + glXAssociateDMPbufferSGIX: [Bool, Display *dpy, GLXPbufferSGIX pbuffer, DMparams + *params, DMbuffer dmbuffer] +SGIX_fbconfig: + glXChooseFBConfigSGIX: [GLXFBConfigSGIX *, Display *dpy, int screen, int *attrib_list, + int *nelements] + glXCreateContextWithConfigSGIX: [GLXContext, Display *dpy, GLXFBConfigSGIX config, + int render_type, GLXContext share_list, Bool direct] + glXCreateGLXPixmapWithConfigSGIX: [GLXPixmap, Display *dpy, GLXFBConfigSGIX config, + Pixmap pixmap] + glXGetFBConfigAttribSGIX: [int, Display *dpy, GLXFBConfigSGIX config, int attribute, + int *value] + glXGetFBConfigFromVisualSGIX: [GLXFBConfigSGIX, Display *dpy, XVisualInfo *vis] + glXGetVisualFromFBConfigSGIX: [XVisualInfo *, Display *dpy, GLXFBConfigSGIX config] +SGIX_hyperpipe: + glXBindHyperpipeSGIX: [int, Display *dpy, int hpId] + glXDestroyHyperpipeConfigSGIX: [int, Display *dpy, int hpId] + glXHyperpipeAttribSGIX: [int, Display *dpy, int timeSlice, int attrib, int size, + void *attribList] + glXHyperpipeConfigSGIX: [int, Display *dpy, int networkId, int npipes, GLXHyperpipeConfigSGIX + *cfg, int *hpId] + glXQueryHyperpipeAttribSGIX: [int, Display *dpy, int timeSlice, int attrib, int + size, void *returnAttribList] + glXQueryHyperpipeBestAttribSGIX: [int, Display *dpy, int timeSlice, int attrib, + int size, void *attribList, void *returnAttribList] + glXQueryHyperpipeConfigSGIX: [GLXHyperpipeConfigSGIX *, Display *dpy, int hpId, + int *npipes] + glXQueryHyperpipeNetworkSGIX: [GLXHyperpipeNetworkSGIX *, Display *dpy, int *npipes] +SGIX_pbuffer: + glXCreateGLXPbufferSGIX: [GLXPbufferSGIX, Display *dpy, GLXFBConfigSGIX config, + unsigned int width, unsigned int height, int *attrib_list] + glXDestroyGLXPbufferSGIX: [void, Display *dpy, GLXPbufferSGIX pbuf] + glXGetSelectedEventSGIX: [void, Display *dpy, GLXDrawable drawable, unsigned long + *mask] + glXQueryGLXPbufferSGIX: [int, Display *dpy, GLXPbufferSGIX pbuf, int attribute, + unsigned int *value] + glXSelectEventSGIX: [void, Display *dpy, GLXDrawable drawable, unsigned long mask] +SGIX_swap_barrier: + glXBindSwapBarrierSGIX: [void, Display *dpy, GLXDrawable drawable, int barrier] + glXQueryMaxSwapBarriersSGIX: [Bool, Display *dpy, int screen, int *max] +SGIX_swap_group: + glXJoinSwapGroupSGIX: [void, Display *dpy, GLXDrawable drawable, GLXDrawable member] +SGIX_video_resize: + glXBindChannelToWindowSGIX: [int, Display *display, int screen, int channel, Window + window] + glXChannelRectSGIX: [int, Display *display, int screen, int channel, int x, int + y, int w, int h] + glXChannelRectSyncSGIX: [int, Display *display, int screen, int channel, GLenum + synctype] + glXQueryChannelDeltasSGIX: [int, Display *display, int screen, int channel, int + *x, int *y, int *w, int *h] + glXQueryChannelRectSGIX: [int, Display *display, int screen, int channel, int *dx, + int *dy, int *dw, int *dh] +SGIX_video_source: + glXCreateGLXVideoSourceSGIX: [GLXVideoSourceSGIX, Display *display, int screen, + VLServer server, VLPath path, int nodeClass, VLNode drainNode] + glXDestroyGLXVideoSourceSGIX: [void, Display *dpy, GLXVideoSourceSGIX glxvideosource] +SGI_cushion: + glXCushionSGI: [void, Display *dpy, Window window, float cushion] +SGI_make_current_read: + glXGetCurrentReadDrawableSGI: [GLXDrawable] + glXMakeCurrentReadSGI: [Bool, Display *dpy, GLXDrawable draw, GLXDrawable read, + GLXContext ctx] +SGI_swap_control: + glXSwapIntervalSGI: [int, int interval] +SGI_video_sync: + glXGetVideoSyncSGI: [int, unsigned int *count] + glXWaitVideoSyncSGI: [int, int divisor, int remainder, unsigned int *count] +SUN_get_transparent_index: + glXGetTransparentIndexSUN: [Status, Display *dpy, Window overlay, Window underlay, + long *pTransparentIndex] +VERSION_1_3: + glXChooseFBConfig: [GLXFBConfig *, Display *dpy, int screen, const int *attrib_list, + int *nelements] + glXCreateNewContext: [GLXContext, Display *dpy, GLXFBConfig config, int render_type, + GLXContext share_list, Bool direct] + glXCreatePbuffer: [GLXPbuffer, Display *dpy, GLXFBConfig config, const int *attrib_list] + glXCreatePixmap: [GLXPixmap, Display *dpy, GLXFBConfig config, Pixmap pixmap, const + int *attrib_list] + glXCreateWindow: [GLXWindow, Display *dpy, GLXFBConfig config, Window win, const + int *attrib_list] + glXDestroyPbuffer: [void, Display *dpy, GLXPbuffer pbuf] + glXDestroyPixmap: [void, Display *dpy, GLXPixmap pixmap] + glXDestroyWindow: [void, Display *dpy, GLXWindow win] + glXGetCurrentDisplay: [Display *] + glXGetCurrentReadDrawable: [GLXDrawable] + glXGetFBConfigAttrib: [int, Display *dpy, GLXFBConfig config, int attribute, int + *value] + glXGetFBConfigs: [GLXFBConfig *, Display *dpy, int screen, int *nelements] + glXGetSelectedEvent: [void, Display *dpy, GLXDrawable draw, unsigned long *event_mask] + glXGetVisualFromFBConfig: [XVisualInfo *, Display *dpy, GLXFBConfig config] + glXMakeContextCurrent: [Bool, Display *dpy, GLXDrawable draw, GLXDrawable read, + GLXContext ctx] + glXQueryContext: [int, Display *dpy, GLXContext ctx, int attribute, int *value] + glXQueryDrawable: [void, Display *dpy, GLXDrawable draw, int attribute, unsigned + int *value] + glXSelectEvent: [void, Display *dpy, GLXDrawable draw, unsigned long event_mask] +VERSION_1_4: + glXGetProcAddress: [__GLXextFuncPtr, const GLubyte *procName] diff --git a/Projects/Android/jni/SupportLibs/gl4es/spec/yml/my_glx.yml b/Projects/Android/jni/SupportLibs/gl4es/spec/yml/my_glx.yml new file mode 100644 index 0000000..f2674e2 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/spec/yml/my_glx.yml @@ -0,0 +1,76 @@ +glx: + glXChooseVisual: [XVisualInfo *, Display *dpy, int screen, int *attribList] + glXBindHyperpipeSGIX: [int, Display *dpy, int hpId] + glXBindSwapBarrierSGIX: [void, uint32_t window, uint32_t barrier] + glXChangeDrawableAttributes: [void, uint32_t drawable] + glXChangeDrawableAttributesSGIX: [void, uint32_t drawable] + glXClientInfo: [void] + glXCopyContext: [void, Display *dpy, GLXContext src, GLXContext dst, unsigned long mask] + glXCreateContext: [GLXContext, Display *dpy, XVisualInfo *vis, GLXContext shareList, Bool direct] + glXCreateContextAttribsARB: [GLXContext, Display *display, void *config, GLXContext share_context, Bool direct, const int *attrib_list] + glXCreateContextWithConfigSGIX: [void, uint32_t gc_id, uint32_t screen, uint32_t + config, uint32_t share_list] + glXCreateGLXPbufferSGIX: [void, uint32_t config, uint32_t pbuffer] + glXCreateGLXPixmap: [GLXPixmap, Display *dpy, XVisualInfo *visual, Pixmap pixmap] + glXCreateGLXPixmapWithConfigSGIX: [void, uint32_t config, uint32_t pixmap, uint32_t + glxpixmap] + glXCreateGLXVideoSourceSGIX: [void, Display *dpy, uint32_t screen, uint32_t server, + uint32_t path, uint32_t class, uint32_t node] + glXCreateNewContext: [void, uint32_t config, uint32_t render_type, uint32_t share_list, + uint32_t direct] + glXCreatePbuffer: [void, uint32_t config, uint32_t pbuffer] + glXCreatePixmap: [void, uint32_t config, uint32_t pixmap, uint32_t glxpixmap] + glXCreateWindow: [void, uint32_t config, uint32_t window, uint32_t glxwindow] + glXDestroyContext: [void, Display *dpy, GLXContext ctx] + glXDestroyGLXPbufferSGIX: [void, uint32_t pbuffer] + glXDestroyGLXPixmap: [void, Display *dpy, GLXPixmap pixmap] + glXDestroyGLXVideoSourceSGIX: [void, Display *dpy, uint32_t glxvideosource] + glXDestroyHyperpipeConfigSGIX: [int, Display *dpy, int hpId] + glXDestroyPbuffer: [void, uint32_t pbuffer] + glXDestroyPixmap: [void, uint32_t glxpixmap] + glXDestroyWindow: [void, uint32_t glxwindow] + glXGetDrawableAttributes: [void, uint32_t drawable] + glXGetDrawableAttributesSGIX: [void, uint32_t drawable] + glXGetClientString: [const char *, Display *display, int name] + glXGetCurrentContext: [GLXContext] + glXGetCurrentDrawable: [GLXDrawable] + glXGetConfig: [int, Display *display, XVisualInfo *visual, int attribute, int *value] + glXGetFBConfigs: [void] + glXGetFBConfigsSGIX: [void] + glXGetVisualConfigs: [void] + glXHyperpipeAttribSGIX: [int, Display *dpy, int timeSlice, int attrib, int size, + const void *attribList] + glXHyperpipeConfigSGIX: [int, Display *dpy, int networkId, int npipes, GLXHyperpipeConfigSGIX + cfg, int *hpId] + glXIsDirect: [Bool, Display *dpy, GLXContext ctx] + glXJoinSwapGroupSGIX: [void, uint32_t window, uint32_t group] + glXMakeContextCurrent: [void, uint32_t drawable, uint32_t readdrawable, uint32_t + context] + glXMakeCurrent: [Bool, Display *dpy, GLXDrawable drawable, GLXContext ctx] + glXMakeCurrentReadSGI: [void, uint32_t drawable, uint32_t readdrawable, uint32_t + context] + glXQueryContext: [void] + glXQueryContextInfoEXT: [void] + glXQueryExtension: [Bool, Display *display, int *errorBase, int *eventBase] + glXQueryExtensionsString: [const char *, Display *dpy, int screen] + glXQueryHyperpipeAttribSGIX: [int, Display *dpy, int timeSlice, int attrib, int + size, const void *returnAttribList] + glXQueryHyperpipeBestAttribSGIX: [int, Display *dpy, int timeSlice, int attrib, + int size, const void *attribList, void *returnAttribList] + glXQueryHyperpipeConfigSGIX: [GLXHyperpipeConfigSGIX *, Display *dpy, int hpId, + int *npipes] + glXQueryHyperpipeNetworkSGIX: [GLXHyperpipeNetworkSGIX *, Display *dpy, int *npipes] + glXQueryMaxSwapBarriersSGIX: [void] + glXQueryServerString: [const char *, Display *dpy, int screen, int name] + glXQueryVersion: [Bool, Display *dpy, int *maj, int *min] + glXReleaseBuffersMESA: [Bool, Display *dpy, GLXDrawable drawable] + glXRender: [void] + glXRenderLarge: [void] + glXSwapBuffers: [void, Display *dpy, GLXDrawable drawable] + glXSwapIntervalSGI: [void, unsigned int interval] + glXSwapIntervalMESA: [int, unsigned int interval] + glXUseXFont: [void, Font font, int first, int count, int list] + glXVendorPrivate: [void] + glXVendorPrivateWithReply: [void] + glXWaitGL: [void] + glXWaitX: [void] diff --git a/Projects/Android/jni/SupportLibs/gl4es/spec/yml/opengl.yml b/Projects/Android/jni/SupportLibs/gl4es/spec/yml/opengl.yml new file mode 100644 index 0000000..7430bc5 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/spec/yml/opengl.yml @@ -0,0 +1,3672 @@ +3DFX_tbuffer: + glTbufferMask3DFX: [void, GLuint mask] +AMD_debug_output: + glDebugMessageCallbackAMD: [void, GLDEBUGPROCAMD callback, GLvoid *userParam] + glDebugMessageEnableAMD: [void, GLenum category, GLenum severity, GLsizei count, + const GLuint *ids, GLboolean enabled] + glDebugMessageInsertAMD: [void, GLenum category, GLenum severity, GLuint id, GLsizei + length, const GLchar *buf] + glGetDebugMessageLogAMD: [GLuint, GLuint count, GLsizei bufsize, GLenum *categories, + GLuint *severities, GLuint *ids, GLsizei *lengths, GLchar *message] +AMD_draw_buffers_blend: + glBlendEquationIndexedAMD: [void, GLuint buf, GLenum mode] + glBlendEquationSeparateIndexedAMD: [void, GLuint buf, GLenum modeRGB, GLenum modeAlpha] + glBlendFuncIndexedAMD: [void, GLuint buf, GLenum src, GLenum dst] + glBlendFuncSeparateIndexedAMD: [void, GLuint buf, GLenum srcRGB, GLenum dstRGB, + GLenum srcAlpha, GLenum dstAlpha] +AMD_multi_draw_indirect: + glMultiDrawArraysIndirectAMD: [void, GLenum mode, const GLvoid *indirect, GLsizei + primcount, GLsizei stride] + glMultiDrawElementsIndirectAMD: [void, GLenum mode, GLenum type, const GLvoid *indirect, + GLsizei primcount, GLsizei stride] +AMD_name_gen_delete: + glDeleteNamesAMD: [void, GLenum identifier, GLuint num, const GLuint *names] + glGenNamesAMD: [void, GLenum identifier, GLuint num, GLuint *names] + glIsNameAMD: [GLboolean, GLenum identifier, GLuint name] +AMD_performance_monitor: + glBeginPerfMonitorAMD: [void, GLuint monitor] + glDeletePerfMonitorsAMD: [void, GLsizei n, GLuint *monitors] + glEndPerfMonitorAMD: [void, GLuint monitor] + glGenPerfMonitorsAMD: [void, GLsizei n, GLuint *monitors] + glGetPerfMonitorCounterDataAMD: [void, GLuint monitor, GLenum pname, GLsizei dataSize, + GLuint *data, GLint *bytesWritten] + glGetPerfMonitorCounterInfoAMD: [void, GLuint group, GLuint counter, GLenum pname, + GLvoid *data] + glGetPerfMonitorCounterStringAMD: [void, GLuint group, GLuint counter, GLsizei bufSize, + GLsizei *length, GLchar *counterString] + glGetPerfMonitorCountersAMD: [void, GLuint group, GLint *numCounters, GLint *maxActiveCounters, + GLsizei counterSize, GLuint *counters] + glGetPerfMonitorGroupStringAMD: [void, GLuint group, GLsizei bufSize, GLsizei *length, + GLchar *groupString] + glGetPerfMonitorGroupsAMD: [void, GLint *numGroups, GLsizei groupsSize, GLuint *groups] + glSelectPerfMonitorCountersAMD: [void, GLuint monitor, GLboolean enable, GLuint + group, GLint numCounters, GLuint *counterList] +AMD_sample_positions: + glSetMultisamplefvAMD: [void, GLenum pname, GLuint index, const GLfloat *val] +AMD_sparse_texture: + glTexStorageSparseAMD: [void, GLenum target, GLenum internalFormat, GLsizei width, + GLsizei height, GLsizei depth, GLsizei layers, GLbitfield flags] + glTextureStorageSparseAMD: [void, GLuint texture, GLenum target, GLenum internalFormat, + GLsizei width, GLsizei height, GLsizei depth, GLsizei layers, GLbitfield flags] +AMD_stencil_operation_extended: + glStencilOpValueAMD: [void, GLenum face, GLuint value] +AMD_vertex_shader_tessellator: + glTessellationFactorAMD: [void, GLfloat factor] + glTessellationModeAMD: [void, GLenum mode] +APPLE_element_array: + glDrawElementArrayAPPLE: [void, GLenum mode, GLint first, GLsizei count] + glDrawRangeElementArrayAPPLE: [void, GLenum mode, GLuint start, GLuint end, GLint + first, GLsizei count] + glElementPointerAPPLE: [void, GLenum type, const GLvoid *pointer] + glMultiDrawElementArrayAPPLE: [void, GLenum mode, const GLint *first, const GLsizei + *count, GLsizei primcount] + glMultiDrawRangeElementArrayAPPLE: [void, GLenum mode, GLuint start, GLuint end, + const GLint *first, const GLsizei *count, GLsizei primcount] +APPLE_fence: + glDeleteFencesAPPLE: [void, GLsizei n, const GLuint *fences] + glFinishFenceAPPLE: [void, GLuint fence] + glFinishObjectAPPLE: [void, GLenum object, GLint name] + glGenFencesAPPLE: [void, GLsizei n, GLuint *fences] + glIsFenceAPPLE: [GLboolean, GLuint fence] + glSetFenceAPPLE: [void, GLuint fence] + glTestFenceAPPLE: [GLboolean, GLuint fence] + glTestObjectAPPLE: [GLboolean, GLenum object, GLuint name] +APPLE_flush_buffer_range: + glBufferParameteriAPPLE: [void, GLenum target, GLenum pname, GLint param] + glFlushMappedBufferRangeAPPLE: [void, GLenum target, GLintptr offset, GLsizeiptr + size] +APPLE_object_purgeable: + glGetObjectParameterivAPPLE: [void, GLenum objectType, GLuint name, GLenum pname, + GLint *params] + glObjectPurgeableAPPLE: [GLenum, GLenum objectType, GLuint name, GLenum option] + glObjectUnpurgeableAPPLE: [GLenum, GLenum objectType, GLuint name, GLenum option] +APPLE_texture_range: + glGetTexParameterPointervAPPLE: [void, GLenum target, GLenum pname, GLvoid *params] + glTextureRangeAPPLE: [void, GLenum target, GLsizei length, const GLvoid *pointer] +APPLE_vertex_array_object: + glBindVertexArrayAPPLE: [void, GLuint array] + glDeleteVertexArraysAPPLE: [void, GLsizei n, const GLuint *arrays] + glGenVertexArraysAPPLE: [void, GLsizei n, GLuint *arrays] + glIsVertexArrayAPPLE: [GLboolean, GLuint array] +APPLE_vertex_array_range: + glFlushVertexArrayRangeAPPLE: [void, GLsizei length, GLvoid *pointer] + glVertexArrayParameteriAPPLE: [void, GLenum pname, GLint param] + glVertexArrayRangeAPPLE: [void, GLsizei length, GLvoid *pointer] +APPLE_vertex_program_evaluators: + glDisableVertexAttribAPPLE: [void, GLuint index, GLenum pname] + glEnableVertexAttribAPPLE: [void, GLuint index, GLenum pname] + glIsVertexAttribEnabledAPPLE: [GLboolean, GLuint index, GLenum pname] + glMapVertexAttrib1dAPPLE: [void, GLuint index, GLuint size, GLdouble u1, GLdouble + u2, GLint stride, GLint order, const GLdouble *points] + glMapVertexAttrib1fAPPLE: [void, GLuint index, GLuint size, GLfloat u1, GLfloat + u2, GLint stride, GLint order, const GLfloat *points] + glMapVertexAttrib2dAPPLE: [void, GLuint index, GLuint size, GLdouble u1, GLdouble + u2, GLint ustride, GLint uorder, GLdouble v1, GLdouble v2, GLint vstride, GLint + vorder, const GLdouble *points] + glMapVertexAttrib2fAPPLE: [void, GLuint index, GLuint size, GLfloat u1, GLfloat + u2, GLint ustride, GLint uorder, GLfloat v1, GLfloat v2, GLint vstride, GLint + vorder, const GLfloat *points] +ARB_ES2_compatibility: + glClearDepthf: [void, GLfloat d] + glDepthRangef: [void, GLfloat n, GLfloat f] + glGetShaderPrecisionFormat: [void, GLenum shadertype, GLenum precisiontype, GLint + *range, GLint *precision] + glReleaseShaderCompiler: [void] + glShaderBinary: [void, GLsizei count, const GLuint *shaders, GLenum binaryformat, + const GLvoid *binary, GLsizei length] +ARB_base_instance: + glDrawArraysInstancedBaseInstance: [void, GLenum mode, GLint first, GLsizei count, + GLsizei instancecount, GLuint baseinstance] + glDrawElementsInstancedBaseInstance: [void, GLenum mode, GLsizei count, GLenum type, + const void *indices, GLsizei instancecount, GLuint baseinstance] + glDrawElementsInstancedBaseVertexBaseInstance: [void, GLenum mode, GLsizei count, + GLenum type, const void *indices, GLsizei instancecount, GLint basevertex, GLuint + baseinstance] +ARB_blend_func_extended: + glBindFragDataLocationIndexed: [void, GLuint program, GLuint colorNumber, GLuint + index, const GLchar *name] + glGetFragDataIndex: [GLint, GLuint program, const GLchar *name] +ARB_cl_event: + glCreateSyncFromCLeventARB: [GLsync, struct _cl_context *context, struct _cl_event + *event, GLbitfield flags] +ARB_clear_buffer_object: + glClearBufferData: [void, GLenum target, GLenum internalformat, GLenum format, GLenum + type, const void *data] + glClearBufferSubData: [void, GLenum target, GLenum internalformat, GLintptr offset, + GLsizeiptr size, GLenum format, GLenum type, const void *data] + glClearNamedBufferDataEXT: [void, GLuint buffer, GLenum internalformat, GLenum format, + GLenum type, const void *data] + glClearNamedBufferSubDataEXT: [void, GLuint buffer, GLenum internalformat, GLenum + format, GLenum type, GLsizeiptr offset, GLsizeiptr size, const void *data] +ARB_color_buffer_float: + glClampColorARB: [void, GLenum target, GLenum clamp] +ARB_compute_shader: + glDispatchCompute: [void, GLuint num_groups_x, GLuint num_groups_y, GLuint num_groups_z] + glDispatchComputeIndirect: [void, GLintptr indirect] +ARB_copy_buffer: + glCopyBufferSubData: [void, GLenum readTarget, GLenum writeTarget, GLintptr readOffset, + GLintptr writeOffset, GLsizeiptr size] +ARB_copy_image: + glCopyImageSubData: [void, GLuint srcName, GLenum srcTarget, GLint srcLevel, GLint + srcX, GLint srcY, GLint srcZ, GLuint dstName, GLenum dstTarget, GLint dstLevel, + GLint dstX, GLint dstY, GLint dstZ, GLsizei srcWidth, GLsizei srcHeight, GLsizei + srcDepth] +ARB_debug_output: + glDebugMessageCallbackARB: [void, GLDEBUGPROCARB callback, const GLvoid *userParam] + glDebugMessageControlARB: [void, GLenum source, GLenum type, GLenum severity, GLsizei + count, const GLuint *ids, GLboolean enabled] + glDebugMessageInsertARB: [void, GLenum source, GLenum type, GLuint id, GLenum severity, + GLsizei length, const GLchar *buf] + glGetDebugMessageLogARB: [GLuint, GLuint count, GLsizei bufsize, GLenum *sources, + GLenum *types, GLuint *ids, GLenum *severities, GLsizei *lengths, GLchar *messageLog] +ARB_draw_buffers: + glDrawBuffersARB: [void, GLsizei n, const GLenum *bufs] +ARB_draw_buffers_blend: + glBlendEquationSeparateiARB: [void, GLuint buf, GLenum modeRGB, GLenum modeAlpha] + glBlendEquationiARB: [void, GLuint buf, GLenum mode] + glBlendFuncSeparateiARB: [void, GLuint buf, GLenum srcRGB, GLenum dstRGB, GLenum + srcAlpha, GLenum dstAlpha] + glBlendFunciARB: [void, GLuint buf, GLenum src, GLenum dst] +ARB_draw_elements_base_vertex: + glDrawElementsBaseVertex: [void, GLenum mode, GLsizei count, GLenum type, const + GLvoid *indices, GLint basevertex] + glDrawElementsInstancedBaseVertex: [void, GLenum mode, GLsizei count, GLenum type, + const GLvoid *indices, GLsizei instancecount, GLint basevertex] + glDrawRangeElementsBaseVertex: [void, GLenum mode, GLuint start, GLuint end, GLsizei + count, GLenum type, const GLvoid *indices, GLint basevertex] + glMultiDrawElementsBaseVertex: [void, GLenum mode, const GLsizei *count, GLenum + type, GLvoid*const *indices, GLsizei drawcount, const GLint *basevertex] +ARB_draw_indirect: + glDrawArraysIndirect: [void, GLenum mode, const GLvoid *indirect] + glDrawElementsIndirect: [void, GLenum mode, GLenum type, const GLvoid *indirect] +ARB_draw_instanced: + glDrawArraysInstancedARB: [void, GLenum mode, GLint first, GLsizei count, GLsizei + primcount] + glDrawElementsInstancedARB: [void, GLenum mode, GLsizei count, GLenum type, const + GLvoid *indices, GLsizei primcount] +ARB_framebuffer_no_attachments: + glFramebufferParameteri: [void, GLenum target, GLenum pname, GLint param] + glGetFramebufferParameteriv: [void, GLenum target, GLenum pname, GLint *params] + glGetNamedFramebufferParameterivEXT: [void, GLuint framebuffer, GLenum pname, GLint + *params] + glNamedFramebufferParameteriEXT: [void, GLuint framebuffer, GLenum pname, GLint + param] +ARB_framebuffer_object: + glBindFramebuffer: [void, GLenum target, GLuint framebuffer] + glBindRenderbuffer: [void, GLenum target, GLuint renderbuffer] + glBlitFramebuffer: [void, GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint + dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter] + glCheckFramebufferStatus: [GLenum, GLenum target] + glDeleteFramebuffers: [void, GLsizei n, const GLuint *framebuffers] + glDeleteRenderbuffers: [void, GLsizei n, const GLuint *renderbuffers] + glFramebufferRenderbuffer: [void, GLenum target, GLenum attachment, GLenum renderbuffertarget, + GLuint renderbuffer] + glFramebufferTexture1D: [void, GLenum target, GLenum attachment, GLenum textarget, + GLuint texture, GLint level] + glFramebufferTexture2D: [void, GLenum target, GLenum attachment, GLenum textarget, + GLuint texture, GLint level] + glFramebufferTexture3D: [void, GLenum target, GLenum attachment, GLenum textarget, + GLuint texture, GLint level, GLint zoffset] + glFramebufferTextureLayer: [void, GLenum target, GLenum attachment, GLuint texture, + GLint level, GLint layer] + glGenFramebuffers: [void, GLsizei n, GLuint *framebuffers] + glGenRenderbuffers: [void, GLsizei n, GLuint *renderbuffers] + glGenerateMipmap: [void, GLenum target] + glGetFramebufferAttachmentParameteriv: [void, GLenum target, GLenum attachment, + GLenum pname, GLint *params] + glGetRenderbufferParameteriv: [void, GLenum target, GLenum pname, GLint *params] + glIsFramebuffer: [GLboolean, GLuint framebuffer] + glIsRenderbuffer: [GLboolean, GLuint renderbuffer] + glRenderbufferStorage: [void, GLenum target, GLenum internalformat, GLsizei width, + GLsizei height] + glRenderbufferStorageMultisample: [void, GLenum target, GLsizei samples, GLenum + internalformat, GLsizei width, GLsizei height] +ARB_geometry_shader4: + glFramebufferTextureARB: [void, GLenum target, GLenum attachment, GLuint texture, + GLint level] + glFramebufferTextureFaceARB: [void, GLenum target, GLenum attachment, GLuint texture, + GLint level, GLenum face] + glFramebufferTextureLayerARB: [void, GLenum target, GLenum attachment, GLuint texture, + GLint level, GLint layer] + glProgramParameteriARB: [void, GLuint program, GLenum pname, GLint value] +ARB_get_program_binary: + glGetProgramBinary: [void, GLuint program, GLsizei bufSize, GLsizei *length, GLenum + *binaryFormat, GLvoid *binary] + glProgramBinary: [void, GLuint program, GLenum binaryFormat, const GLvoid *binary, + GLsizei length] + glProgramParameteri: [void, GLuint program, GLenum pname, GLint value] +ARB_gpu_shader_fp64: + glGetUniformdv: [void, GLuint program, GLint location, GLdouble *params] + glUniform1d: [void, GLint location, GLdouble x] + glUniform1dv: [void, GLint location, GLsizei count, const GLdouble *value] + glUniform2d: [void, GLint location, GLdouble x, GLdouble y] + glUniform2dv: [void, GLint location, GLsizei count, const GLdouble *value] + glUniform3d: [void, GLint location, GLdouble x, GLdouble y, GLdouble z] + glUniform3dv: [void, GLint location, GLsizei count, const GLdouble *value] + glUniform4d: [void, GLint location, GLdouble x, GLdouble y, GLdouble z, GLdouble + w] + glUniform4dv: [void, GLint location, GLsizei count, const GLdouble *value] + glUniformMatrix2dv: [void, GLint location, GLsizei count, GLboolean transpose, const + GLdouble *value] + glUniformMatrix2x3dv: [void, GLint location, GLsizei count, GLboolean transpose, + const GLdouble *value] + glUniformMatrix2x4dv: [void, GLint location, GLsizei count, GLboolean transpose, + const GLdouble *value] + glUniformMatrix3dv: [void, GLint location, GLsizei count, GLboolean transpose, const + GLdouble *value] + glUniformMatrix3x2dv: [void, GLint location, GLsizei count, GLboolean transpose, + const GLdouble *value] + glUniformMatrix3x4dv: [void, GLint location, GLsizei count, GLboolean transpose, + const GLdouble *value] + glUniformMatrix4dv: [void, GLint location, GLsizei count, GLboolean transpose, const + GLdouble *value] + glUniformMatrix4x2dv: [void, GLint location, GLsizei count, GLboolean transpose, + const GLdouble *value] + glUniformMatrix4x3dv: [void, GLint location, GLsizei count, GLboolean transpose, + const GLdouble *value] +ARB_instanced_arrays: + glVertexAttribDivisorARB: [void, GLuint index, GLuint divisor] +ARB_internalformat_query: + glGetInternalformativ: [void, GLenum target, GLenum internalformat, GLenum pname, + GLsizei bufSize, GLint *params] +ARB_internalformat_query2: + glGetInternalformati64v: [void, GLenum target, GLenum internalformat, GLenum pname, + GLsizei bufSize, GLint64 *params] +ARB_invalidate_subdata: + glInvalidateBufferData: [void, GLuint buffer] + glInvalidateBufferSubData: [void, GLuint buffer, GLintptr offset, GLsizeiptr length] + glInvalidateFramebuffer: [void, GLenum target, GLsizei numAttachments, const GLenum + *attachments] + glInvalidateSubFramebuffer: [void, GLenum target, GLsizei numAttachments, const + GLenum *attachments, GLint x, GLint y, GLsizei width, GLsizei height] + glInvalidateTexImage: [void, GLuint texture, GLint level] + glInvalidateTexSubImage: [void, GLuint texture, GLint level, GLint xoffset, GLint + yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth] +ARB_map_buffer_range: + glFlushMappedBufferRange: [void, GLenum target, GLintptr offset, GLsizeiptr length] + glMapBufferRange: [GLvoid *, GLenum target, GLintptr offset, GLsizeiptr length, + GLbitfield access] +ARB_matrix_palette: + glCurrentPaletteMatrixARB: [void, GLint index] + glMatrixIndexPointerARB: [void, GLint size, GLenum type, GLsizei stride, const GLvoid + *pointer] + glMatrixIndexubvARB: [void, GLint size, const GLubyte *indices] + glMatrixIndexuivARB: [void, GLint size, const GLuint *indices] + glMatrixIndexusvARB: [void, GLint size, const GLushort *indices] +ARB_multi_draw_indirect: + glMultiDrawArraysIndirect: [void, GLenum mode, const void *indirect, GLsizei drawcount, + GLsizei stride] + glMultiDrawElementsIndirect: [void, GLenum mode, GLenum type, const void *indirect, + GLsizei drawcount, GLsizei stride] +ARB_multisample: + glSampleCoverageARB: [void, GLfloat value, GLboolean invert] +ARB_multitexture: + glActiveTextureARB: [void, GLenum texture] + glClientActiveTextureARB: [void, GLenum texture] + glMultiTexCoord1dARB: [void, GLenum target, GLdouble s] + glMultiTexCoord1dvARB: [void, GLenum target, const GLdouble *v] + glMultiTexCoord1fARB: [void, GLenum target, GLfloat s] + glMultiTexCoord1fvARB: [void, GLenum target, const GLfloat *v] + glMultiTexCoord1iARB: [void, GLenum target, GLint s] + glMultiTexCoord1ivARB: [void, GLenum target, const GLint *v] + glMultiTexCoord1sARB: [void, GLenum target, GLshort s] + glMultiTexCoord1svARB: [void, GLenum target, const GLshort *v] + glMultiTexCoord2dARB: [void, GLenum target, GLdouble s, GLdouble t] + glMultiTexCoord2dvARB: [void, GLenum target, const GLdouble *v] + glMultiTexCoord2fARB: [void, GLenum target, GLfloat s, GLfloat t] + glMultiTexCoord2fvARB: [void, GLenum target, const GLfloat *v] + glMultiTexCoord2iARB: [void, GLenum target, GLint s, GLint t] + glMultiTexCoord2ivARB: [void, GLenum target, const GLint *v] + glMultiTexCoord2sARB: [void, GLenum target, GLshort s, GLshort t] + glMultiTexCoord2svARB: [void, GLenum target, const GLshort *v] + glMultiTexCoord3dARB: [void, GLenum target, GLdouble s, GLdouble t, GLdouble r] + glMultiTexCoord3dvARB: [void, GLenum target, const GLdouble *v] + glMultiTexCoord3fARB: [void, GLenum target, GLfloat s, GLfloat t, GLfloat r] + glMultiTexCoord3fvARB: [void, GLenum target, const GLfloat *v] + glMultiTexCoord3iARB: [void, GLenum target, GLint s, GLint t, GLint r] + glMultiTexCoord3ivARB: [void, GLenum target, const GLint *v] + glMultiTexCoord3sARB: [void, GLenum target, GLshort s, GLshort t, GLshort r] + glMultiTexCoord3svARB: [void, GLenum target, const GLshort *v] + glMultiTexCoord4dARB: [void, GLenum target, GLdouble s, GLdouble t, GLdouble r, + GLdouble q] + glMultiTexCoord4dvARB: [void, GLenum target, const GLdouble *v] + glMultiTexCoord4fARB: [void, GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat + q] + glMultiTexCoord4fvARB: [void, GLenum target, const GLfloat *v] + glMultiTexCoord4iARB: [void, GLenum target, GLint s, GLint t, GLint r, GLint q] + glMultiTexCoord4ivARB: [void, GLenum target, const GLint *v] + glMultiTexCoord4sARB: [void, GLenum target, GLshort s, GLshort t, GLshort r, GLshort + q] + glMultiTexCoord4svARB: [void, GLenum target, const GLshort *v] +ARB_occlusion_query: + glBeginQueryARB: [void, GLenum target, GLuint id] + glDeleteQueriesARB: [void, GLsizei n, const GLuint *ids] + glEndQueryARB: [void, GLenum target] + glGenQueriesARB: [void, GLsizei n, GLuint *ids] + glGetQueryObjectivARB: [void, GLuint id, GLenum pname, GLint *params] + glGetQueryObjectuivARB: [void, GLuint id, GLenum pname, GLuint *params] + glGetQueryivARB: [void, GLenum target, GLenum pname, GLint *params] + glIsQueryARB: [GLboolean, GLuint id] +ARB_point_parameters: + glPointParameterfARB: [void, GLenum pname, GLfloat param] + glPointParameterfvARB: [void, GLenum pname, const GLfloat *params] +ARB_program_interface_query: + glGetProgramInterfaceiv: [void, GLuint program, GLenum programInterface, GLenum + pname, GLint *params] + glGetProgramResourceIndex: [GLuint, GLuint program, GLenum programInterface, const + GLchar *name] + glGetProgramResourceLocation: [GLint, GLuint program, GLenum programInterface, const + GLchar *name] + glGetProgramResourceLocationIndex: [GLint, GLuint program, GLenum programInterface, + const GLchar *name] + glGetProgramResourceName: [void, GLuint program, GLenum programInterface, GLuint + index, GLsizei bufSize, GLsizei *length, GLchar *name] + glGetProgramResourceiv: [void, GLuint program, GLenum programInterface, GLuint index, + GLsizei propCount, const GLenum *props, GLsizei bufSize, GLsizei *length, GLint + *params] +ARB_provoking_vertex: + glProvokingVertex: [void, GLenum mode] +ARB_robustness: + glGetGraphicsResetStatusARB: [GLenum] + glGetnColorTableARB: [void, GLenum target, GLenum format, GLenum type, GLsizei bufSize, + GLvoid *table] + glGetnCompressedTexImageARB: [void, GLenum target, GLint lod, GLsizei bufSize, GLvoid + *img] + glGetnConvolutionFilterARB: [void, GLenum target, GLenum format, GLenum type, GLsizei + bufSize, GLvoid *image] + glGetnHistogramARB: [void, GLenum target, GLboolean reset, GLenum format, GLenum + type, GLsizei bufSize, GLvoid *values] + glGetnMapdvARB: [void, GLenum target, GLenum query, GLsizei bufSize, GLdouble *v] + glGetnMapfvARB: [void, GLenum target, GLenum query, GLsizei bufSize, GLfloat *v] + glGetnMapivARB: [void, GLenum target, GLenum query, GLsizei bufSize, GLint *v] + glGetnMinmaxARB: [void, GLenum target, GLboolean reset, GLenum format, GLenum type, + GLsizei bufSize, GLvoid *values] + glGetnPixelMapfvARB: [void, GLenum map, GLsizei bufSize, GLfloat *values] + glGetnPixelMapuivARB: [void, GLenum map, GLsizei bufSize, GLuint *values] + glGetnPixelMapusvARB: [void, GLenum map, GLsizei bufSize, GLushort *values] + glGetnPolygonStippleARB: [void, GLsizei bufSize, GLubyte *pattern] + glGetnSeparableFilterARB: [void, GLenum target, GLenum format, GLenum type, GLsizei + rowBufSize, GLvoid *row, GLsizei columnBufSize, GLvoid *column, GLvoid *span] + glGetnTexImageARB: [void, GLenum target, GLint level, GLenum format, GLenum type, + GLsizei bufSize, GLvoid *img] + glGetnUniformdvARB: [void, GLuint program, GLint location, GLsizei bufSize, GLdouble + *params] + glGetnUniformfvARB: [void, GLuint program, GLint location, GLsizei bufSize, GLfloat + *params] + glGetnUniformivARB: [void, GLuint program, GLint location, GLsizei bufSize, GLint + *params] + glGetnUniformuivARB: [void, GLuint program, GLint location, GLsizei bufSize, GLuint + *params] + glReadnPixelsARB: [void, GLint x, GLint y, GLsizei width, GLsizei height, GLenum + format, GLenum type, GLsizei bufSize, GLvoid *data] +ARB_sample_shading: + glMinSampleShadingARB: [void, GLfloat value] +ARB_sampler_objects: + glBindSampler: [void, GLuint unit, GLuint sampler] + glDeleteSamplers: [void, GLsizei count, const GLuint *samplers] + glGenSamplers: [void, GLsizei count, GLuint *samplers] + glGetSamplerParameterIiv: [void, GLuint sampler, GLenum pname, GLint *params] + glGetSamplerParameterIuiv: [void, GLuint sampler, GLenum pname, GLuint *params] + glGetSamplerParameterfv: [void, GLuint sampler, GLenum pname, GLfloat *params] + glGetSamplerParameteriv: [void, GLuint sampler, GLenum pname, GLint *params] + glIsSampler: [GLboolean, GLuint sampler] + glSamplerParameterIiv: [void, GLuint sampler, GLenum pname, const GLint *param] + glSamplerParameterIuiv: [void, GLuint sampler, GLenum pname, const GLuint *param] + glSamplerParameterf: [void, GLuint sampler, GLenum pname, GLfloat param] + glSamplerParameterfv: [void, GLuint sampler, GLenum pname, const GLfloat *param] + glSamplerParameteri: [void, GLuint sampler, GLenum pname, GLint param] + glSamplerParameteriv: [void, GLuint sampler, GLenum pname, const GLint *param] +ARB_separate_shader_objects: + glActiveShaderProgram: [void, GLuint pipeline, GLuint program] + glBindProgramPipeline: [void, GLuint pipeline] + glCreateShaderProgramv: [GLuint, GLenum type, GLsizei count, GLchar*const *strings] + glDeleteProgramPipelines: [void, GLsizei n, const GLuint *pipelines] + glGenProgramPipelines: [void, GLsizei n, GLuint *pipelines] + glGetProgramPipelineInfoLog: [void, GLuint pipeline, GLsizei bufSize, GLsizei *length, + GLchar *infoLog] + glGetProgramPipelineiv: [void, GLuint pipeline, GLenum pname, GLint *params] + glIsProgramPipeline: [GLboolean, GLuint pipeline] + glProgramUniform1d: [void, GLuint program, GLint location, GLdouble v0] + glProgramUniform1dv: [void, GLuint program, GLint location, GLsizei count, const + GLdouble *value] + glProgramUniform1f: [void, GLuint program, GLint location, GLfloat v0] + glProgramUniform1fv: [void, GLuint program, GLint location, GLsizei count, const + GLfloat *value] + glProgramUniform1i: [void, GLuint program, GLint location, GLint v0] + glProgramUniform1iv: [void, GLuint program, GLint location, GLsizei count, const + GLint *value] + glProgramUniform1ui: [void, GLuint program, GLint location, GLuint v0] + glProgramUniform1uiv: [void, GLuint program, GLint location, GLsizei count, const + GLuint *value] + glProgramUniform2d: [void, GLuint program, GLint location, GLdouble v0, GLdouble + v1] + glProgramUniform2dv: [void, GLuint program, GLint location, GLsizei count, const + GLdouble *value] + glProgramUniform2f: [void, GLuint program, GLint location, GLfloat v0, GLfloat v1] + glProgramUniform2fv: [void, GLuint program, GLint location, GLsizei count, const + GLfloat *value] + glProgramUniform2i: [void, GLuint program, GLint location, GLint v0, GLint v1] + glProgramUniform2iv: [void, GLuint program, GLint location, GLsizei count, const + GLint *value] + glProgramUniform2ui: [void, GLuint program, GLint location, GLuint v0, GLuint v1] + glProgramUniform2uiv: [void, GLuint program, GLint location, GLsizei count, const + GLuint *value] + glProgramUniform3d: [void, GLuint program, GLint location, GLdouble v0, GLdouble + v1, GLdouble v2] + glProgramUniform3dv: [void, GLuint program, GLint location, GLsizei count, const + GLdouble *value] + glProgramUniform3f: [void, GLuint program, GLint location, GLfloat v0, GLfloat v1, + GLfloat v2] + glProgramUniform3fv: [void, GLuint program, GLint location, GLsizei count, const + GLfloat *value] + glProgramUniform3i: [void, GLuint program, GLint location, GLint v0, GLint v1, GLint + v2] + glProgramUniform3iv: [void, GLuint program, GLint location, GLsizei count, const + GLint *value] + glProgramUniform3ui: [void, GLuint program, GLint location, GLuint v0, GLuint v1, + GLuint v2] + glProgramUniform3uiv: [void, GLuint program, GLint location, GLsizei count, const + GLuint *value] + glProgramUniform4d: [void, GLuint program, GLint location, GLdouble v0, GLdouble + v1, GLdouble v2, GLdouble v3] + glProgramUniform4dv: [void, GLuint program, GLint location, GLsizei count, const + GLdouble *value] + glProgramUniform4f: [void, GLuint program, GLint location, GLfloat v0, GLfloat v1, + GLfloat v2, GLfloat v3] + glProgramUniform4fv: [void, GLuint program, GLint location, GLsizei count, const + GLfloat *value] + glProgramUniform4i: [void, GLuint program, GLint location, GLint v0, GLint v1, GLint + v2, GLint v3] + glProgramUniform4iv: [void, GLuint program, GLint location, GLsizei count, const + GLint *value] + glProgramUniform4ui: [void, GLuint program, GLint location, GLuint v0, GLuint v1, + GLuint v2, GLuint v3] + glProgramUniform4uiv: [void, GLuint program, GLint location, GLsizei count, const + GLuint *value] + glProgramUniformMatrix2dv: [void, GLuint program, GLint location, GLsizei count, + GLboolean transpose, const GLdouble *value] + glProgramUniformMatrix2fv: [void, GLuint program, GLint location, GLsizei count, + GLboolean transpose, const GLfloat *value] + glProgramUniformMatrix2x3dv: [void, GLuint program, GLint location, GLsizei count, + GLboolean transpose, const GLdouble *value] + glProgramUniformMatrix2x3fv: [void, GLuint program, GLint location, GLsizei count, + GLboolean transpose, const GLfloat *value] + glProgramUniformMatrix2x4dv: [void, GLuint program, GLint location, GLsizei count, + GLboolean transpose, const GLdouble *value] + glProgramUniformMatrix2x4fv: [void, GLuint program, GLint location, GLsizei count, + GLboolean transpose, const GLfloat *value] + glProgramUniformMatrix3dv: [void, GLuint program, GLint location, GLsizei count, + GLboolean transpose, const GLdouble *value] + glProgramUniformMatrix3fv: [void, GLuint program, GLint location, GLsizei count, + GLboolean transpose, const GLfloat *value] + glProgramUniformMatrix3x2dv: [void, GLuint program, GLint location, GLsizei count, + GLboolean transpose, const GLdouble *value] + glProgramUniformMatrix3x2fv: [void, GLuint program, GLint location, GLsizei count, + GLboolean transpose, const GLfloat *value] + glProgramUniformMatrix3x4dv: [void, GLuint program, GLint location, GLsizei count, + GLboolean transpose, const GLdouble *value] + glProgramUniformMatrix3x4fv: [void, GLuint program, GLint location, GLsizei count, + GLboolean transpose, const GLfloat *value] + glProgramUniformMatrix4dv: [void, GLuint program, GLint location, GLsizei count, + GLboolean transpose, const GLdouble *value] + glProgramUniformMatrix4fv: [void, GLuint program, GLint location, GLsizei count, + GLboolean transpose, const GLfloat *value] + glProgramUniformMatrix4x2dv: [void, GLuint program, GLint location, GLsizei count, + GLboolean transpose, const GLdouble *value] + glProgramUniformMatrix4x2fv: [void, GLuint program, GLint location, GLsizei count, + GLboolean transpose, const GLfloat *value] + glProgramUniformMatrix4x3dv: [void, GLuint program, GLint location, GLsizei count, + GLboolean transpose, const GLdouble *value] + glProgramUniformMatrix4x3fv: [void, GLuint program, GLint location, GLsizei count, + GLboolean transpose, const GLfloat *value] + glUseProgramStages: [void, GLuint pipeline, GLbitfield stages, GLuint program] + glValidateProgramPipeline: [void, GLuint pipeline] +ARB_shader_atomic_counters: + glGetActiveAtomicCounterBufferiv: [void, GLuint program, GLuint bufferIndex, GLenum + pname, GLint *params] +ARB_shader_image_load_store: + glBindImageTexture: [void, GLuint unit, GLuint texture, GLint level, GLboolean layered, + GLint layer, GLenum access, GLenum format] + glMemoryBarrier: [void, GLbitfield barriers] +ARB_shader_objects: + glAttachObjectARB: [void, GLhandleARB containerObj, GLhandleARB obj] + glCompileShaderARB: [void, GLhandleARB shaderObj] + glCreateProgramObjectARB: [GLhandleARB] + glCreateShaderObjectARB: [GLhandleARB, GLenum shaderType] + glDeleteObjectARB: [void, GLhandleARB obj] + glDetachObjectARB: [void, GLhandleARB containerObj, GLhandleARB attachedObj] + glGetActiveUniformARB: [void, GLhandleARB programObj, GLuint index, GLsizei maxLength, + GLsizei *length, GLint *size, GLenum *type, GLcharARB *name] + glGetAttachedObjectsARB: [void, GLhandleARB containerObj, GLsizei maxCount, GLsizei + *count, GLhandleARB *obj] + glGetHandleARB: [GLhandleARB, GLenum pname] + glGetInfoLogARB: [void, GLhandleARB obj, GLsizei maxLength, GLsizei *length, GLcharARB + *infoLog] + glGetObjectParameterfvARB: [void, GLhandleARB obj, GLenum pname, GLfloat *params] + glGetObjectParameterivARB: [void, GLhandleARB obj, GLenum pname, GLint *params] + glGetShaderSourceARB: [void, GLhandleARB obj, GLsizei maxLength, GLsizei *length, + GLcharARB *source] + glGetUniformLocationARB: [GLint, GLhandleARB programObj, const GLcharARB *name] + glGetUniformfvARB: [void, GLhandleARB programObj, GLint location, GLfloat *params] + glGetUniformivARB: [void, GLhandleARB programObj, GLint location, GLint *params] + glLinkProgramARB: [void, GLhandleARB programObj] + glShaderSourceARB: [void, GLhandleARB shaderObj, GLsizei count, const GLcharARB + *string, const GLint *length] + glUniform1fARB: [void, GLint location, GLfloat v0] + glUniform1fvARB: [void, GLint location, GLsizei count, const GLfloat *value] + glUniform1iARB: [void, GLint location, GLint v0] + glUniform1ivARB: [void, GLint location, GLsizei count, const GLint *value] + glUniform2fARB: [void, GLint location, GLfloat v0, GLfloat v1] + glUniform2fvARB: [void, GLint location, GLsizei count, const GLfloat *value] + glUniform2iARB: [void, GLint location, GLint v0, GLint v1] + glUniform2ivARB: [void, GLint location, GLsizei count, const GLint *value] + glUniform3fARB: [void, GLint location, GLfloat v0, GLfloat v1, GLfloat v2] + glUniform3fvARB: [void, GLint location, GLsizei count, const GLfloat *value] + glUniform3iARB: [void, GLint location, GLint v0, GLint v1, GLint v2] + glUniform3ivARB: [void, GLint location, GLsizei count, const GLint *value] + glUniform4fARB: [void, GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat + v3] + glUniform4fvARB: [void, GLint location, GLsizei count, const GLfloat *value] + glUniform4iARB: [void, GLint location, GLint v0, GLint v1, GLint v2, GLint v3] + glUniform4ivARB: [void, GLint location, GLsizei count, const GLint *value] + glUniformMatrix2fvARB: [void, GLint location, GLsizei count, GLboolean transpose, + const GLfloat *value] + glUniformMatrix3fvARB: [void, GLint location, GLsizei count, GLboolean transpose, + const GLfloat *value] + glUniformMatrix4fvARB: [void, GLint location, GLsizei count, GLboolean transpose, + const GLfloat *value] + glUseProgramObjectARB: [void, GLhandleARB programObj] + glValidateProgramARB: [void, GLhandleARB programObj] +ARB_shader_storage_buffer_object: + glShaderStorageBlockBinding: [void, GLuint program, GLuint storageBlockIndex, GLuint + storageBlockBinding] +ARB_shader_subroutine: + glGetActiveSubroutineName: [void, GLuint program, GLenum shadertype, GLuint index, + GLsizei bufsize, GLsizei *length, GLchar *name] + glGetActiveSubroutineUniformName: [void, GLuint program, GLenum shadertype, GLuint + index, GLsizei bufsize, GLsizei *length, GLchar *name] + glGetActiveSubroutineUniformiv: [void, GLuint program, GLenum shadertype, GLuint + index, GLenum pname, GLint *values] + glGetProgramStageiv: [void, GLuint program, GLenum shadertype, GLenum pname, GLint + *values] + glGetSubroutineIndex: [GLuint, GLuint program, GLenum shadertype, const GLchar *name] + glGetSubroutineUniformLocation: [GLint, GLuint program, GLenum shadertype, const + GLchar *name] + glGetUniformSubroutineuiv: [void, GLenum shadertype, GLint location, GLuint *params] + glUniformSubroutinesuiv: [void, GLenum shadertype, GLsizei count, const GLuint *indices] +ARB_shading_language_include: + glCompileShaderIncludeARB: [void, GLuint shader, GLsizei count, const GLchar *path, + const GLint *length] + glDeleteNamedStringARB: [void, GLint namelen, const GLchar *name] + glGetNamedStringARB: [void, GLint namelen, const GLchar *name, GLsizei bufSize, + GLint *stringlen, GLchar *string] + glGetNamedStringivARB: [void, GLint namelen, const GLchar *name, GLenum pname, GLint + *params] + glIsNamedStringARB: [GLboolean, GLint namelen, const GLchar *name] + glNamedStringARB: [void, GLenum type, GLint namelen, const GLchar *name, GLint stringlen, + const GLchar *string] +ARB_sync: + glClientWaitSync: [GLenum, GLsync sync, GLbitfield flags, GLuint64 timeout] + glDeleteSync: [void, GLsync sync] + glFenceSync: [GLsync, GLenum condition, GLbitfield flags] + glGetInteger64v: [void, GLenum pname, GLint64 *params] + glGetSynciv: [void, GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, + GLint *values] + glIsSync: [GLboolean, GLsync sync] + glWaitSync: [void, GLsync sync, GLbitfield flags, GLuint64 timeout] +ARB_tessellation_shader: + glPatchParameterfv: [void, GLenum pname, const GLfloat *values] + glPatchParameteri: [void, GLenum pname, GLint value] +ARB_texture_buffer_object: + glTexBufferARB: [void, GLenum target, GLenum internalformat, GLuint buffer] +ARB_texture_buffer_range: + glTexBufferRange: [void, GLenum target, GLenum internalformat, GLuint buffer, GLintptr + offset, GLsizeiptr size] + glTextureBufferRangeEXT: [void, GLuint texture, GLenum target, GLenum internalformat, + GLuint buffer, GLintptr offset, GLsizeiptr size] +ARB_texture_compression: + glCompressedTexImage1DARB: [void, GLenum target, GLint level, GLenum internalformat, + GLsizei width, GLint border, GLsizei imageSize, const GLvoid *data] + glCompressedTexImage2DARB: [void, GLenum target, GLint level, GLenum internalformat, + GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data] + glCompressedTexImage3DARB: [void, GLenum target, GLint level, GLenum internalformat, + GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, + const GLvoid *data] + glCompressedTexSubImage1DARB: [void, GLenum target, GLint level, GLint xoffset, + GLsizei width, GLenum format, GLsizei imageSize, const GLvoid *data] + glCompressedTexSubImage2DARB: [void, GLenum target, GLint level, GLint xoffset, + GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, + const GLvoid *data] + glCompressedTexSubImage3DARB: [void, GLenum target, GLint level, GLint xoffset, + GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum + format, GLsizei imageSize, const GLvoid *data] + glGetCompressedTexImageARB: [void, GLenum target, GLint level, GLvoid *img] +ARB_texture_multisample: + glGetMultisamplefv: [void, GLenum pname, GLuint index, GLfloat *val] + glSampleMaski: [void, GLuint index, GLbitfield mask] + glTexImage2DMultisample: [void, GLenum target, GLsizei samples, GLint internalformat, + GLsizei width, GLsizei height, GLboolean fixedsamplelocations] + glTexImage3DMultisample: [void, GLenum target, GLsizei samples, GLint internalformat, + GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedsamplelocations] +ARB_texture_storage: + glTexStorage1D: [void, GLenum target, GLsizei levels, GLenum internalformat, GLsizei + width] + glTexStorage2D: [void, GLenum target, GLsizei levels, GLenum internalformat, GLsizei + width, GLsizei height] + glTexStorage3D: [void, GLenum target, GLsizei levels, GLenum internalformat, GLsizei + width, GLsizei height, GLsizei depth] + glTextureStorage1DEXT: [void, GLuint texture, GLenum target, GLsizei levels, GLenum + internalformat, GLsizei width] + glTextureStorage2DEXT: [void, GLuint texture, GLenum target, GLsizei levels, GLenum + internalformat, GLsizei width, GLsizei height] + glTextureStorage3DEXT: [void, GLuint texture, GLenum target, GLsizei levels, GLenum + internalformat, GLsizei width, GLsizei height, GLsizei depth] +ARB_texture_storage_multisample: + glTexStorage2DMultisample: [void, GLenum target, GLsizei samples, GLenum internalformat, + GLsizei width, GLsizei height, GLboolean fixedsamplelocations] + glTexStorage3DMultisample: [void, GLenum target, GLsizei samples, GLenum internalformat, + GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedsamplelocations] + glTextureStorage2DMultisampleEXT: [void, GLuint texture, GLenum target, GLsizei + samples, GLenum internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations] + glTextureStorage3DMultisampleEXT: [void, GLuint texture, GLenum target, GLsizei + samples, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, + GLboolean fixedsamplelocations] +ARB_texture_view: + glTextureView: [void, GLuint texture, GLenum target, GLuint origtexture, GLenum + internalformat, GLuint minlevel, GLuint numlevels, GLuint minlayer, GLuint numlayers] +ARB_timer_query: + glGetQueryObjecti64v: [void, GLuint id, GLenum pname, GLint64 *params] + glGetQueryObjectui64v: [void, GLuint id, GLenum pname, GLuint64 *params] + glQueryCounter: [void, GLuint id, GLenum target] +ARB_transform_feedback2: + glBindTransformFeedback: [void, GLenum target, GLuint id] + glDeleteTransformFeedbacks: [void, GLsizei n, const GLuint *ids] + glDrawTransformFeedback: [void, GLenum mode, GLuint id] + glGenTransformFeedbacks: [void, GLsizei n, GLuint *ids] + glIsTransformFeedback: [GLboolean, GLuint id] + glPauseTransformFeedback: [void] + glResumeTransformFeedback: [void] +ARB_transform_feedback3: + glBeginQueryIndexed: [void, GLenum target, GLuint index, GLuint id] + glDrawTransformFeedbackStream: [void, GLenum mode, GLuint id, GLuint stream] + glEndQueryIndexed: [void, GLenum target, GLuint index] + glGetQueryIndexediv: [void, GLenum target, GLuint index, GLenum pname, GLint *params] +ARB_transform_feedback_instanced: + glDrawTransformFeedbackInstanced: [void, GLenum mode, GLuint id, GLsizei instancecount] + glDrawTransformFeedbackStreamInstanced: [void, GLenum mode, GLuint id, GLuint stream, + GLsizei instancecount] +ARB_transpose_matrix: + glLoadTransposeMatrixdARB: [void, const GLdouble *m] + glLoadTransposeMatrixfARB: [void, const GLfloat *m] + glMultTransposeMatrixdARB: [void, const GLdouble *m] + glMultTransposeMatrixfARB: [void, const GLfloat *m] +ARB_uniform_buffer_object: + glGetActiveUniformBlockName: [void, GLuint program, GLuint uniformBlockIndex, GLsizei + bufSize, GLsizei *length, GLchar *uniformBlockName] + glGetActiveUniformBlockiv: [void, GLuint program, GLuint uniformBlockIndex, GLenum + pname, GLint *params] + glGetActiveUniformName: [void, GLuint program, GLuint uniformIndex, GLsizei bufSize, + GLsizei *length, GLchar *uniformName] + glGetActiveUniformsiv: [void, GLuint program, GLsizei uniformCount, const GLuint + *uniformIndices, GLenum pname, GLint *params] + glGetUniformBlockIndex: [GLuint, GLuint program, const GLchar *uniformBlockName] + glGetUniformIndices: [void, GLuint program, GLsizei uniformCount, GLchar*const *uniformNames, + GLuint *uniformIndices] + glUniformBlockBinding: [void, GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding] +ARB_vertex_array_object: + glBindVertexArray: [void, GLuint array] + glDeleteVertexArrays: [void, GLsizei n, const GLuint *arrays] + glGenVertexArrays: [void, GLsizei n, GLuint *arrays] + glIsVertexArray: [GLboolean, GLuint array] +ARB_vertex_attrib_64bit: + glGetVertexAttribLdv: [void, GLuint index, GLenum pname, GLdouble *params] + glVertexAttribL1d: [void, GLuint index, GLdouble x] + glVertexAttribL1dv: [void, GLuint index, const GLdouble *v] + glVertexAttribL2d: [void, GLuint index, GLdouble x, GLdouble y] + glVertexAttribL2dv: [void, GLuint index, const GLdouble *v] + glVertexAttribL3d: [void, GLuint index, GLdouble x, GLdouble y, GLdouble z] + glVertexAttribL3dv: [void, GLuint index, const GLdouble *v] + glVertexAttribL4d: [void, GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble + w] + glVertexAttribL4dv: [void, GLuint index, const GLdouble *v] + glVertexAttribLPointer: [void, GLuint index, GLint size, GLenum type, GLsizei stride, + const GLvoid *pointer] +ARB_vertex_attrib_binding: + glBindVertexBuffer: [void, GLuint bindingindex, GLuint buffer, GLintptr offset, + GLsizei stride] + glVertexArrayBindVertexBufferEXT: [void, GLuint vaobj, GLuint bindingindex, GLuint + buffer, GLintptr offset, GLsizei stride] + glVertexArrayVertexAttribBindingEXT: [void, GLuint vaobj, GLuint attribindex, GLuint + bindingindex] + glVertexArrayVertexAttribFormatEXT: [void, GLuint vaobj, GLuint attribindex, GLint + size, GLenum type, GLboolean normalized, GLuint relativeoffset] + glVertexArrayVertexAttribIFormatEXT: [void, GLuint vaobj, GLuint attribindex, GLint + size, GLenum type, GLuint relativeoffset] + glVertexArrayVertexAttribLFormatEXT: [void, GLuint vaobj, GLuint attribindex, GLint + size, GLenum type, GLuint relativeoffset] + glVertexArrayVertexBindingDivisorEXT: [void, GLuint vaobj, GLuint bindingindex, + GLuint divisor] + glVertexAttribBinding: [void, GLuint attribindex, GLuint bindingindex] + glVertexAttribFormat: [void, GLuint attribindex, GLint size, GLenum type, GLboolean + normalized, GLuint relativeoffset] + glVertexAttribIFormat: [void, GLuint attribindex, GLint size, GLenum type, GLuint + relativeoffset] + glVertexAttribLFormat: [void, GLuint attribindex, GLint size, GLenum type, GLuint + relativeoffset] + glVertexBindingDivisor: [void, GLuint bindingindex, GLuint divisor] +ARB_vertex_blend: + glVertexBlendARB: [void, GLint count] + glWeightPointerARB: [void, GLint size, GLenum type, GLsizei stride, const GLvoid + *pointer] + glWeightbvARB: [void, GLint size, const GLbyte *weights] + glWeightdvARB: [void, GLint size, const GLdouble *weights] + glWeightfvARB: [void, GLint size, const GLfloat *weights] + glWeightivARB: [void, GLint size, const GLint *weights] + glWeightsvARB: [void, GLint size, const GLshort *weights] + glWeightubvARB: [void, GLint size, const GLubyte *weights] + glWeightuivARB: [void, GLint size, const GLuint *weights] + glWeightusvARB: [void, GLint size, const GLushort *weights] +ARB_vertex_buffer_object: + glBindBufferARB: [void, GLenum target, GLuint buffer] + glBufferDataARB: [void, GLenum target, GLsizeiptrARB size, const GLvoid *data, GLenum + usage] + glBufferSubDataARB: [void, GLenum target, GLintptrARB offset, GLsizeiptrARB size, + const GLvoid *data] + glDeleteBuffersARB: [void, GLsizei n, const GLuint *buffers] + glGenBuffersARB: [void, GLsizei n, GLuint *buffers] + glGetBufferParameterivARB: [void, GLenum target, GLenum pname, GLint *params] + glGetBufferPointervARB: [void, GLenum target, GLenum pname, GLvoid *params] + glGetBufferSubDataARB: [void, GLenum target, GLintptrARB offset, GLsizeiptrARB size, + GLvoid *data] + glIsBufferARB: [GLboolean, GLuint buffer] + glMapBufferARB: [GLvoid *, GLenum target, GLenum access] + glUnmapBufferARB: [GLboolean, GLenum target] +ARB_vertex_program: + glBindProgramARB: [void, GLenum target, GLuint program] + glDeleteProgramsARB: [void, GLsizei n, const GLuint *programs] + glDisableVertexAttribArrayARB: [void, GLuint index] + glEnableVertexAttribArrayARB: [void, GLuint index] + glGenProgramsARB: [void, GLsizei n, GLuint *programs] + glGetProgramEnvParameterdvARB: [void, GLenum target, GLuint index, GLdouble *params] + glGetProgramEnvParameterfvARB: [void, GLenum target, GLuint index, GLfloat *params] + glGetProgramLocalParameterdvARB: [void, GLenum target, GLuint index, GLdouble *params] + glGetProgramLocalParameterfvARB: [void, GLenum target, GLuint index, GLfloat *params] + glGetProgramStringARB: [void, GLenum target, GLenum pname, GLvoid *string] + glGetProgramivARB: [void, GLenum target, GLenum pname, GLint *params] + glGetVertexAttribPointervARB: [void, GLuint index, GLenum pname, GLvoid *pointer] + glGetVertexAttribdvARB: [void, GLuint index, GLenum pname, GLdouble *params] + glGetVertexAttribfvARB: [void, GLuint index, GLenum pname, GLfloat *params] + glGetVertexAttribivARB: [void, GLuint index, GLenum pname, GLint *params] + glIsProgramARB: [GLboolean, GLuint program] + glProgramEnvParameter4dARB: [void, GLenum target, GLuint index, GLdouble x, GLdouble + y, GLdouble z, GLdouble w] + glProgramEnvParameter4dvARB: [void, GLenum target, GLuint index, const GLdouble + *params] + glProgramEnvParameter4fARB: [void, GLenum target, GLuint index, GLfloat x, GLfloat + y, GLfloat z, GLfloat w] + glProgramEnvParameter4fvARB: [void, GLenum target, GLuint index, const GLfloat *params] + glProgramLocalParameter4dARB: [void, GLenum target, GLuint index, GLdouble x, GLdouble + y, GLdouble z, GLdouble w] + glProgramLocalParameter4dvARB: [void, GLenum target, GLuint index, const GLdouble + *params] + glProgramLocalParameter4fARB: [void, GLenum target, GLuint index, GLfloat x, GLfloat + y, GLfloat z, GLfloat w] + glProgramLocalParameter4fvARB: [void, GLenum target, GLuint index, const GLfloat + *params] + glProgramStringARB: [void, GLenum target, GLenum format, GLsizei len, const GLvoid + *string] + glVertexAttrib1dARB: [void, GLuint index, GLdouble x] + glVertexAttrib1dvARB: [void, GLuint index, const GLdouble *v] + glVertexAttrib1fARB: [void, GLuint index, GLfloat x] + glVertexAttrib1fvARB: [void, GLuint index, const GLfloat *v] + glVertexAttrib1sARB: [void, GLuint index, GLshort x] + glVertexAttrib1svARB: [void, GLuint index, const GLshort *v] + glVertexAttrib2dARB: [void, GLuint index, GLdouble x, GLdouble y] + glVertexAttrib2dvARB: [void, GLuint index, const GLdouble *v] + glVertexAttrib2fARB: [void, GLuint index, GLfloat x, GLfloat y] + glVertexAttrib2fvARB: [void, GLuint index, const GLfloat *v] + glVertexAttrib2sARB: [void, GLuint index, GLshort x, GLshort y] + glVertexAttrib2svARB: [void, GLuint index, const GLshort *v] + glVertexAttrib3dARB: [void, GLuint index, GLdouble x, GLdouble y, GLdouble z] + glVertexAttrib3dvARB: [void, GLuint index, const GLdouble *v] + glVertexAttrib3fARB: [void, GLuint index, GLfloat x, GLfloat y, GLfloat z] + glVertexAttrib3fvARB: [void, GLuint index, const GLfloat *v] + glVertexAttrib3sARB: [void, GLuint index, GLshort x, GLshort y, GLshort z] + glVertexAttrib3svARB: [void, GLuint index, const GLshort *v] + glVertexAttrib4NbvARB: [void, GLuint index, const GLbyte *v] + glVertexAttrib4NivARB: [void, GLuint index, const GLint *v] + glVertexAttrib4NsvARB: [void, GLuint index, const GLshort *v] + glVertexAttrib4NubARB: [void, GLuint index, GLubyte x, GLubyte y, GLubyte z, GLubyte + w] + glVertexAttrib4NubvARB: [void, GLuint index, const GLubyte *v] + glVertexAttrib4NuivARB: [void, GLuint index, const GLuint *v] + glVertexAttrib4NusvARB: [void, GLuint index, const GLushort *v] + glVertexAttrib4bvARB: [void, GLuint index, const GLbyte *v] + glVertexAttrib4dARB: [void, GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble + w] + glVertexAttrib4dvARB: [void, GLuint index, const GLdouble *v] + glVertexAttrib4fARB: [void, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat + w] + glVertexAttrib4fvARB: [void, GLuint index, const GLfloat *v] + glVertexAttrib4ivARB: [void, GLuint index, const GLint *v] + glVertexAttrib4sARB: [void, GLuint index, GLshort x, GLshort y, GLshort z, GLshort + w] + glVertexAttrib4svARB: [void, GLuint index, const GLshort *v] + glVertexAttrib4ubvARB: [void, GLuint index, const GLubyte *v] + glVertexAttrib4uivARB: [void, GLuint index, const GLuint *v] + glVertexAttrib4usvARB: [void, GLuint index, const GLushort *v] + glVertexAttribPointerARB: [void, GLuint index, GLint size, GLenum type, GLboolean + normalized, GLsizei stride, const GLvoid *pointer] +ARB_vertex_shader: + glBindAttribLocationARB: [void, GLhandleARB programObj, GLuint index, const GLcharARB + *name] + glGetActiveAttribARB: [void, GLhandleARB programObj, GLuint index, GLsizei maxLength, + GLsizei *length, GLint *size, GLenum *type, GLcharARB *name] + glGetAttribLocationARB: [GLint, GLhandleARB programObj, const GLcharARB *name] +ARB_vertex_type_2_10_10_10_rev: + glColorP3ui: [void, GLenum type, GLuint color] + glColorP3uiv: [void, GLenum type, const GLuint *color] + glColorP4ui: [void, GLenum type, GLuint color] + glColorP4uiv: [void, GLenum type, const GLuint *color] + glMultiTexCoordP1ui: [void, GLenum texture, GLenum type, GLuint coords] + glMultiTexCoordP1uiv: [void, GLenum texture, GLenum type, const GLuint *coords] + glMultiTexCoordP2ui: [void, GLenum texture, GLenum type, GLuint coords] + glMultiTexCoordP2uiv: [void, GLenum texture, GLenum type, const GLuint *coords] + glMultiTexCoordP3ui: [void, GLenum texture, GLenum type, GLuint coords] + glMultiTexCoordP3uiv: [void, GLenum texture, GLenum type, const GLuint *coords] + glMultiTexCoordP4ui: [void, GLenum texture, GLenum type, GLuint coords] + glMultiTexCoordP4uiv: [void, GLenum texture, GLenum type, const GLuint *coords] + glNormalP3ui: [void, GLenum type, GLuint coords] + glNormalP3uiv: [void, GLenum type, const GLuint *coords] + glSecondaryColorP3ui: [void, GLenum type, GLuint color] + glSecondaryColorP3uiv: [void, GLenum type, const GLuint *color] + glTexCoordP1ui: [void, GLenum type, GLuint coords] + glTexCoordP1uiv: [void, GLenum type, const GLuint *coords] + glTexCoordP2ui: [void, GLenum type, GLuint coords] + glTexCoordP2uiv: [void, GLenum type, const GLuint *coords] + glTexCoordP3ui: [void, GLenum type, GLuint coords] + glTexCoordP3uiv: [void, GLenum type, const GLuint *coords] + glTexCoordP4ui: [void, GLenum type, GLuint coords] + glTexCoordP4uiv: [void, GLenum type, const GLuint *coords] + glVertexAttribP1ui: [void, GLuint index, GLenum type, GLboolean normalized, GLuint + value] + glVertexAttribP1uiv: [void, GLuint index, GLenum type, GLboolean normalized, const + GLuint *value] + glVertexAttribP2ui: [void, GLuint index, GLenum type, GLboolean normalized, GLuint + value] + glVertexAttribP2uiv: [void, GLuint index, GLenum type, GLboolean normalized, const + GLuint *value] + glVertexAttribP3ui: [void, GLuint index, GLenum type, GLboolean normalized, GLuint + value] + glVertexAttribP3uiv: [void, GLuint index, GLenum type, GLboolean normalized, const + GLuint *value] + glVertexAttribP4ui: [void, GLuint index, GLenum type, GLboolean normalized, GLuint + value] + glVertexAttribP4uiv: [void, GLuint index, GLenum type, GLboolean normalized, const + GLuint *value] + glVertexP2ui: [void, GLenum type, GLuint value] + glVertexP2uiv: [void, GLenum type, const GLuint *value] + glVertexP3ui: [void, GLenum type, GLuint value] + glVertexP3uiv: [void, GLenum type, const GLuint *value] + glVertexP4ui: [void, GLenum type, GLuint value] + glVertexP4uiv: [void, GLenum type, const GLuint *value] +ARB_viewport_array: + glDepthRangeArrayv: [void, GLuint first, GLsizei count, const GLdouble *v] + glDepthRangeIndexed: [void, GLuint index, GLdouble n, GLdouble f] + glGetDoublei_v: [void, GLenum target, GLuint index, GLdouble *data] + glGetFloati_v: [void, GLenum target, GLuint index, GLfloat *data] + glScissorArrayv: [void, GLuint first, GLsizei count, const GLint *v] + glScissorIndexed: [void, GLuint index, GLint left, GLint bottom, GLsizei width, + GLsizei height] + glScissorIndexedv: [void, GLuint index, const GLint *v] + glViewportArrayv: [void, GLuint first, GLsizei count, const GLfloat *v] + glViewportIndexedf: [void, GLuint index, GLfloat x, GLfloat y, GLfloat w, GLfloat + h] + glViewportIndexedfv: [void, GLuint index, const GLfloat *v] +ARB_window_pos: + glWindowPos2dARB: [void, GLdouble x, GLdouble y] + glWindowPos2dvARB: [void, const GLdouble *v] + glWindowPos2fARB: [void, GLfloat x, GLfloat y] + glWindowPos2fvARB: [void, const GLfloat *v] + glWindowPos2iARB: [void, GLint x, GLint y] + glWindowPos2ivARB: [void, const GLint *v] + glWindowPos2sARB: [void, GLshort x, GLshort y] + glWindowPos2svARB: [void, const GLshort *v] + glWindowPos3dARB: [void, GLdouble x, GLdouble y, GLdouble z] + glWindowPos3dvARB: [void, const GLdouble *v] + glWindowPos3fARB: [void, GLfloat x, GLfloat y, GLfloat z] + glWindowPos3fvARB: [void, const GLfloat *v] + glWindowPos3iARB: [void, GLint x, GLint y, GLint z] + glWindowPos3ivARB: [void, const GLint *v] + glWindowPos3sARB: [void, GLshort x, GLshort y, GLshort z] + glWindowPos3svARB: [void, const GLshort *v] +ATI_draw_buffers: + glDrawBuffersATI: [void, GLsizei n, const GLenum *bufs] +ATI_element_array: + glDrawElementArrayATI: [void, GLenum mode, GLsizei count] + glDrawRangeElementArrayATI: [void, GLenum mode, GLuint start, GLuint end, GLsizei + count] + glElementPointerATI: [void, GLenum type, const GLvoid *pointer] +ATI_envmap_bumpmap: + glGetTexBumpParameterfvATI: [void, GLenum pname, GLfloat *param] + glGetTexBumpParameterivATI: [void, GLenum pname, GLint *param] + glTexBumpParameterfvATI: [void, GLenum pname, const GLfloat *param] + glTexBumpParameterivATI: [void, GLenum pname, const GLint *param] +ATI_fragment_shader: + glAlphaFragmentOp1ATI: [void, GLenum op, GLuint dst, GLuint dstMod, GLuint arg1, + GLuint arg1Rep, GLuint arg1Mod] + glAlphaFragmentOp2ATI: [void, GLenum op, GLuint dst, GLuint dstMod, GLuint arg1, + GLuint arg1Rep, GLuint arg1Mod, GLuint arg2, GLuint arg2Rep, GLuint arg2Mod] + glAlphaFragmentOp3ATI: [void, GLenum op, GLuint dst, GLuint dstMod, GLuint arg1, + GLuint arg1Rep, GLuint arg1Mod, GLuint arg2, GLuint arg2Rep, GLuint arg2Mod, GLuint + arg3, GLuint arg3Rep, GLuint arg3Mod] + glBeginFragmentShaderATI: [void] + glBindFragmentShaderATI: [void, GLuint id] + glColorFragmentOp1ATI: [void, GLenum op, GLuint dst, GLuint dstMask, GLuint dstMod, + GLuint arg1, GLuint arg1Rep, GLuint arg1Mod] + glColorFragmentOp2ATI: [void, GLenum op, GLuint dst, GLuint dstMask, GLuint dstMod, + GLuint arg1, GLuint arg1Rep, GLuint arg1Mod, GLuint arg2, GLuint arg2Rep, GLuint + arg2Mod] + glColorFragmentOp3ATI: [void, GLenum op, GLuint dst, GLuint dstMask, GLuint dstMod, + GLuint arg1, GLuint arg1Rep, GLuint arg1Mod, GLuint arg2, GLuint arg2Rep, GLuint + arg2Mod, GLuint arg3, GLuint arg3Rep, GLuint arg3Mod] + glDeleteFragmentShaderATI: [void, GLuint id] + glEndFragmentShaderATI: [void] + glGenFragmentShadersATI: [GLuint, GLuint range] + glPassTexCoordATI: [void, GLuint dst, GLuint coord, GLenum swizzle] + glSampleMapATI: [void, GLuint dst, GLuint interp, GLenum swizzle] + glSetFragmentShaderConstantATI: [void, GLuint dst, const GLfloat *value] +ATI_map_object_buffer: + glMapObjectBufferATI: [GLvoid *, GLuint buffer] + glUnmapObjectBufferATI: [void, GLuint buffer] +ATI_pn_triangles: + glPNTrianglesfATI: [void, GLenum pname, GLfloat param] + glPNTrianglesiATI: [void, GLenum pname, GLint param] +ATI_separate_stencil: + glStencilFuncSeparateATI: [void, GLenum frontfunc, GLenum backfunc, GLint ref, GLuint + mask] + glStencilOpSeparateATI: [void, GLenum face, GLenum sfail, GLenum dpfail, GLenum + dppass] +ATI_vertex_array_object: + glArrayObjectATI: [void, GLenum array, GLint size, GLenum type, GLsizei stride, + GLuint buffer, GLuint offset] + glFreeObjectBufferATI: [void, GLuint buffer] + glGetArrayObjectfvATI: [void, GLenum array, GLenum pname, GLfloat *params] + glGetArrayObjectivATI: [void, GLenum array, GLenum pname, GLint *params] + glGetObjectBufferfvATI: [void, GLuint buffer, GLenum pname, GLfloat *params] + glGetObjectBufferivATI: [void, GLuint buffer, GLenum pname, GLint *params] + glGetVariantArrayObjectfvATI: [void, GLuint id, GLenum pname, GLfloat *params] + glGetVariantArrayObjectivATI: [void, GLuint id, GLenum pname, GLint *params] + glIsObjectBufferATI: [GLboolean, GLuint buffer] + glNewObjectBufferATI: [GLuint, GLsizei size, const GLvoid *pointer, GLenum usage] + glUpdateObjectBufferATI: [void, GLuint buffer, GLuint offset, GLsizei size, const + GLvoid *pointer, GLenum preserve] + glVariantArrayObjectATI: [void, GLuint id, GLenum type, GLsizei stride, GLuint buffer, + GLuint offset] +ATI_vertex_attrib_array_object: + glGetVertexAttribArrayObjectfvATI: [void, GLuint index, GLenum pname, GLfloat *params] + glGetVertexAttribArrayObjectivATI: [void, GLuint index, GLenum pname, GLint *params] + glVertexAttribArrayObjectATI: [void, GLuint index, GLint size, GLenum type, GLboolean + normalized, GLsizei stride, GLuint buffer, GLuint offset] +ATI_vertex_streams: + glClientActiveVertexStreamATI: [void, GLenum stream] + glNormalStream3bATI: [void, GLenum stream, GLbyte nx, GLbyte ny, GLbyte nz] + glNormalStream3bvATI: [void, GLenum stream, const GLbyte *coords] + glNormalStream3dATI: [void, GLenum stream, GLdouble nx, GLdouble ny, GLdouble nz] + glNormalStream3dvATI: [void, GLenum stream, const GLdouble *coords] + glNormalStream3fATI: [void, GLenum stream, GLfloat nx, GLfloat ny, GLfloat nz] + glNormalStream3fvATI: [void, GLenum stream, const GLfloat *coords] + glNormalStream3iATI: [void, GLenum stream, GLint nx, GLint ny, GLint nz] + glNormalStream3ivATI: [void, GLenum stream, const GLint *coords] + glNormalStream3sATI: [void, GLenum stream, GLshort nx, GLshort ny, GLshort nz] + glNormalStream3svATI: [void, GLenum stream, const GLshort *coords] + glVertexBlendEnvfATI: [void, GLenum pname, GLfloat param] + glVertexBlendEnviATI: [void, GLenum pname, GLint param] + glVertexStream1dATI: [void, GLenum stream, GLdouble x] + glVertexStream1dvATI: [void, GLenum stream, const GLdouble *coords] + glVertexStream1fATI: [void, GLenum stream, GLfloat x] + glVertexStream1fvATI: [void, GLenum stream, const GLfloat *coords] + glVertexStream1iATI: [void, GLenum stream, GLint x] + glVertexStream1ivATI: [void, GLenum stream, const GLint *coords] + glVertexStream1sATI: [void, GLenum stream, GLshort x] + glVertexStream1svATI: [void, GLenum stream, const GLshort *coords] + glVertexStream2dATI: [void, GLenum stream, GLdouble x, GLdouble y] + glVertexStream2dvATI: [void, GLenum stream, const GLdouble *coords] + glVertexStream2fATI: [void, GLenum stream, GLfloat x, GLfloat y] + glVertexStream2fvATI: [void, GLenum stream, const GLfloat *coords] + glVertexStream2iATI: [void, GLenum stream, GLint x, GLint y] + glVertexStream2ivATI: [void, GLenum stream, const GLint *coords] + glVertexStream2sATI: [void, GLenum stream, GLshort x, GLshort y] + glVertexStream2svATI: [void, GLenum stream, const GLshort *coords] + glVertexStream3dATI: [void, GLenum stream, GLdouble x, GLdouble y, GLdouble z] + glVertexStream3dvATI: [void, GLenum stream, const GLdouble *coords] + glVertexStream3fATI: [void, GLenum stream, GLfloat x, GLfloat y, GLfloat z] + glVertexStream3fvATI: [void, GLenum stream, const GLfloat *coords] + glVertexStream3iATI: [void, GLenum stream, GLint x, GLint y, GLint z] + glVertexStream3ivATI: [void, GLenum stream, const GLint *coords] + glVertexStream3sATI: [void, GLenum stream, GLshort x, GLshort y, GLshort z] + glVertexStream3svATI: [void, GLenum stream, const GLshort *coords] + glVertexStream4dATI: [void, GLenum stream, GLdouble x, GLdouble y, GLdouble z, GLdouble + w] + glVertexStream4dvATI: [void, GLenum stream, const GLdouble *coords] + glVertexStream4fATI: [void, GLenum stream, GLfloat x, GLfloat y, GLfloat z, GLfloat + w] + glVertexStream4fvATI: [void, GLenum stream, const GLfloat *coords] + glVertexStream4iATI: [void, GLenum stream, GLint x, GLint y, GLint z, GLint w] + glVertexStream4ivATI: [void, GLenum stream, const GLint *coords] + glVertexStream4sATI: [void, GLenum stream, GLshort x, GLshort y, GLshort z, GLshort + w] + glVertexStream4svATI: [void, GLenum stream, const GLshort *coords] +EXT_bindable_uniform: + glGetUniformBufferSizeEXT: [GLint, GLuint program, GLint location] + glGetUniformOffsetEXT: [GLintptr, GLuint program, GLint location] + glUniformBufferEXT: [void, GLuint program, GLint location, GLuint buffer] +EXT_blend_color: + glBlendColorEXT: [void, GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha] +EXT_blend_equation_separate: + glBlendEquationSeparateEXT: [void, GLenum modeRGB, GLenum modeAlpha] +EXT_blend_func_separate: + glBlendFuncSeparateEXT: [void, GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, + GLenum dfactorAlpha] +EXT_blend_minmax: + glBlendEquationEXT: [void, GLenum mode] +EXT_color_subtable: + glColorSubTableEXT: [void, GLenum target, GLsizei start, GLsizei count, GLenum format, + GLenum type, const GLvoid *data] + glCopyColorSubTableEXT: [void, GLenum target, GLsizei start, GLint x, GLint y, GLsizei + width] +EXT_compiled_vertex_array: + glLockArraysEXT: [void, GLint first, GLsizei count] + glUnlockArraysEXT: [void] +EXT_convolution: + glConvolutionFilter1DEXT: [void, GLenum target, GLenum internalformat, GLsizei width, + GLenum format, GLenum type, const GLvoid *image] + glConvolutionFilter2DEXT: [void, GLenum target, GLenum internalformat, GLsizei width, + GLsizei height, GLenum format, GLenum type, const GLvoid *image] + glConvolutionParameterfEXT: [void, GLenum target, GLenum pname, GLfloat params] + glConvolutionParameterfvEXT: [void, GLenum target, GLenum pname, const GLfloat *params] + glConvolutionParameteriEXT: [void, GLenum target, GLenum pname, GLint params] + glConvolutionParameterivEXT: [void, GLenum target, GLenum pname, const GLint *params] + glCopyConvolutionFilter1DEXT: [void, GLenum target, GLenum internalformat, GLint + x, GLint y, GLsizei width] + glCopyConvolutionFilter2DEXT: [void, GLenum target, GLenum internalformat, GLint + x, GLint y, GLsizei width, GLsizei height] + glGetConvolutionFilterEXT: [void, GLenum target, GLenum format, GLenum type, GLvoid + *image] + glGetConvolutionParameterfvEXT: [void, GLenum target, GLenum pname, GLfloat *params] + glGetConvolutionParameterivEXT: [void, GLenum target, GLenum pname, GLint *params] + glGetSeparableFilterEXT: [void, GLenum target, GLenum format, GLenum type, GLvoid + *row, GLvoid *column, GLvoid *span] + glSeparableFilter2DEXT: [void, GLenum target, GLenum internalformat, GLsizei width, + GLsizei height, GLenum format, GLenum type, const GLvoid *row, const GLvoid *column] +EXT_coordinate_frame: + glBinormal3bEXT: [void, GLbyte bx, GLbyte by, GLbyte bz] + glBinormal3bvEXT: [void, const GLbyte *v] + glBinormal3dEXT: [void, GLdouble bx, GLdouble by, GLdouble bz] + glBinormal3dvEXT: [void, const GLdouble *v] + glBinormal3fEXT: [void, GLfloat bx, GLfloat by, GLfloat bz] + glBinormal3fvEXT: [void, const GLfloat *v] + glBinormal3iEXT: [void, GLint bx, GLint by, GLint bz] + glBinormal3ivEXT: [void, const GLint *v] + glBinormal3sEXT: [void, GLshort bx, GLshort by, GLshort bz] + glBinormal3svEXT: [void, const GLshort *v] + glBinormalPointerEXT: [void, GLenum type, GLsizei stride, const GLvoid *pointer] + glTangent3bEXT: [void, GLbyte tx, GLbyte ty, GLbyte tz] + glTangent3bvEXT: [void, const GLbyte *v] + glTangent3dEXT: [void, GLdouble tx, GLdouble ty, GLdouble tz] + glTangent3dvEXT: [void, const GLdouble *v] + glTangent3fEXT: [void, GLfloat tx, GLfloat ty, GLfloat tz] + glTangent3fvEXT: [void, const GLfloat *v] + glTangent3iEXT: [void, GLint tx, GLint ty, GLint tz] + glTangent3ivEXT: [void, const GLint *v] + glTangent3sEXT: [void, GLshort tx, GLshort ty, GLshort tz] + glTangent3svEXT: [void, const GLshort *v] + glTangentPointerEXT: [void, GLenum type, GLsizei stride, const GLvoid *pointer] +EXT_copy_texture: + glCopyTexImage1DEXT: [void, GLenum target, GLint level, GLenum internalformat, GLint + x, GLint y, GLsizei width, GLint border] + glCopyTexImage2DEXT: [void, GLenum target, GLint level, GLenum internalformat, GLint + x, GLint y, GLsizei width, GLsizei height, GLint border] + glCopyTexSubImage1DEXT: [void, GLenum target, GLint level, GLint xoffset, GLint + x, GLint y, GLsizei width] + glCopyTexSubImage2DEXT: [void, GLenum target, GLint level, GLint xoffset, GLint + yoffset, GLint x, GLint y, GLsizei width, GLsizei height] + glCopyTexSubImage3DEXT: [void, GLenum target, GLint level, GLint xoffset, GLint + yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height] +EXT_cull_vertex: + glCullParameterdvEXT: [void, GLenum pname, GLdouble *params] + glCullParameterfvEXT: [void, GLenum pname, GLfloat *params] +EXT_depth_bounds_test: + glDepthBoundsEXT: [void, GLclampd zmin, GLclampd zmax] +EXT_direct_state_access: + glBindMultiTextureEXT: [void, GLenum texunit, GLenum target, GLuint texture] + glCheckNamedFramebufferStatusEXT: [GLenum, GLuint framebuffer, GLenum target] + glClientAttribDefaultEXT: [void, GLbitfield mask] + glCompressedMultiTexImage1DEXT: [void, GLenum texunit, GLenum target, GLint level, + GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const GLvoid + *bits] + glCompressedMultiTexImage2DEXT: [void, GLenum texunit, GLenum target, GLint level, + GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, + const GLvoid *bits] + glCompressedMultiTexImage3DEXT: [void, GLenum texunit, GLenum target, GLint level, + GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, + GLsizei imageSize, const GLvoid *bits] + glCompressedMultiTexSubImage1DEXT: [void, GLenum texunit, GLenum target, GLint level, + GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const GLvoid *bits] + glCompressedMultiTexSubImage2DEXT: [void, GLenum texunit, GLenum target, GLint level, + GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei + imageSize, const GLvoid *bits] + glCompressedMultiTexSubImage3DEXT: [void, GLenum texunit, GLenum target, GLint level, + GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei + depth, GLenum format, GLsizei imageSize, const GLvoid *bits] + glCompressedTextureImage1DEXT: [void, GLuint texture, GLenum target, GLint level, + GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const GLvoid + *bits] + glCompressedTextureImage2DEXT: [void, GLuint texture, GLenum target, GLint level, + GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, + const GLvoid *bits] + glCompressedTextureImage3DEXT: [void, GLuint texture, GLenum target, GLint level, + GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, + GLsizei imageSize, const GLvoid *bits] + glCompressedTextureSubImage1DEXT: [void, GLuint texture, GLenum target, GLint level, + GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const GLvoid *bits] + glCompressedTextureSubImage2DEXT: [void, GLuint texture, GLenum target, GLint level, + GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei + imageSize, const GLvoid *bits] + glCompressedTextureSubImage3DEXT: [void, GLuint texture, GLenum target, GLint level, + GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei + depth, GLenum format, GLsizei imageSize, const GLvoid *bits] + glCopyMultiTexImage1DEXT: [void, GLenum texunit, GLenum target, GLint level, GLenum + internalformat, GLint x, GLint y, GLsizei width, GLint border] + glCopyMultiTexImage2DEXT: [void, GLenum texunit, GLenum target, GLint level, GLenum + internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border] + glCopyMultiTexSubImage1DEXT: [void, GLenum texunit, GLenum target, GLint level, + GLint xoffset, GLint x, GLint y, GLsizei width] + glCopyMultiTexSubImage2DEXT: [void, GLenum texunit, GLenum target, GLint level, + GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height] + glCopyMultiTexSubImage3DEXT: [void, GLenum texunit, GLenum target, GLint level, + GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, + GLsizei height] + glCopyTextureImage1DEXT: [void, GLuint texture, GLenum target, GLint level, GLenum + internalformat, GLint x, GLint y, GLsizei width, GLint border] + glCopyTextureImage2DEXT: [void, GLuint texture, GLenum target, GLint level, GLenum + internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border] + glCopyTextureSubImage1DEXT: [void, GLuint texture, GLenum target, GLint level, GLint + xoffset, GLint x, GLint y, GLsizei width] + glCopyTextureSubImage2DEXT: [void, GLuint texture, GLenum target, GLint level, GLint + xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height] + glCopyTextureSubImage3DEXT: [void, GLuint texture, GLenum target, GLint level, GLint + xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei + height] + glDisableClientStateIndexedEXT: [void, GLenum array, GLuint index] + glDisableClientStateiEXT: [void, GLenum array, GLuint index] + glDisableVertexArrayAttribEXT: [void, GLuint vaobj, GLuint index] + glDisableVertexArrayEXT: [void, GLuint vaobj, GLenum array] + glEnableClientStateIndexedEXT: [void, GLenum array, GLuint index] + glEnableClientStateiEXT: [void, GLenum array, GLuint index] + glEnableVertexArrayAttribEXT: [void, GLuint vaobj, GLuint index] + glEnableVertexArrayEXT: [void, GLuint vaobj, GLenum array] + glFlushMappedNamedBufferRangeEXT: [void, GLuint buffer, GLintptr offset, GLsizeiptr + length] + glFramebufferDrawBufferEXT: [void, GLuint framebuffer, GLenum mode] + glFramebufferDrawBuffersEXT: [void, GLuint framebuffer, GLsizei n, const GLenum + *bufs] + glFramebufferReadBufferEXT: [void, GLuint framebuffer, GLenum mode] + glGenerateMultiTexMipmapEXT: [void, GLenum texunit, GLenum target] + glGenerateTextureMipmapEXT: [void, GLuint texture, GLenum target] + glGetCompressedMultiTexImageEXT: [void, GLenum texunit, GLenum target, GLint lod, + GLvoid *img] + glGetCompressedTextureImageEXT: [void, GLuint texture, GLenum target, GLint lod, + GLvoid *img] + glGetDoubleIndexedvEXT: [void, GLenum target, GLuint index, GLdouble *data] + glGetDoublei_vEXT: [void, GLenum target, GLuint index, GLdouble *data] + glGetFloatIndexedvEXT: [void, GLenum target, GLuint index, GLfloat *data] + glGetFloati_vEXT: [void, GLenum target, GLuint index, GLfloat *data] + glGetFramebufferParameterivEXT: [void, GLuint framebuffer, GLenum pname, GLint *params] + glGetMultiTexEnvfvEXT: [void, GLenum texunit, GLenum target, GLenum pname, GLfloat + *params] + glGetMultiTexEnvivEXT: [void, GLenum texunit, GLenum target, GLenum pname, GLint + *params] + glGetMultiTexGendvEXT: [void, GLenum texunit, GLenum coord, GLenum pname, GLdouble + *params] + glGetMultiTexGenfvEXT: [void, GLenum texunit, GLenum coord, GLenum pname, GLfloat + *params] + glGetMultiTexGenivEXT: [void, GLenum texunit, GLenum coord, GLenum pname, GLint + *params] + glGetMultiTexImageEXT: [void, GLenum texunit, GLenum target, GLint level, GLenum + format, GLenum type, GLvoid *pixels] + glGetMultiTexLevelParameterfvEXT: [void, GLenum texunit, GLenum target, GLint level, + GLenum pname, GLfloat *params] + glGetMultiTexLevelParameterivEXT: [void, GLenum texunit, GLenum target, GLint level, + GLenum pname, GLint *params] + glGetMultiTexParameterIivEXT: [void, GLenum texunit, GLenum target, GLenum pname, + GLint *params] + glGetMultiTexParameterIuivEXT: [void, GLenum texunit, GLenum target, GLenum pname, + GLuint *params] + glGetMultiTexParameterfvEXT: [void, GLenum texunit, GLenum target, GLenum pname, + GLfloat *params] + glGetMultiTexParameterivEXT: [void, GLenum texunit, GLenum target, GLenum pname, + GLint *params] + glGetNamedBufferParameterivEXT: [void, GLuint buffer, GLenum pname, GLint *params] + glGetNamedBufferPointervEXT: [void, GLuint buffer, GLenum pname, GLvoid *params] + glGetNamedBufferSubDataEXT: [void, GLuint buffer, GLintptr offset, GLsizeiptr size, + GLvoid *data] + glGetNamedFramebufferAttachmentParameterivEXT: [void, GLuint framebuffer, GLenum + attachment, GLenum pname, GLint *params] + glGetNamedProgramLocalParameterIivEXT: [void, GLuint program, GLenum target, GLuint + index, GLint *params] + glGetNamedProgramLocalParameterIuivEXT: [void, GLuint program, GLenum target, GLuint + index, GLuint *params] + glGetNamedProgramLocalParameterdvEXT: [void, GLuint program, GLenum target, GLuint + index, GLdouble *params] + glGetNamedProgramLocalParameterfvEXT: [void, GLuint program, GLenum target, GLuint + index, GLfloat *params] + glGetNamedProgramStringEXT: [void, GLuint program, GLenum target, GLenum pname, + GLvoid *string] + glGetNamedProgramivEXT: [void, GLuint program, GLenum target, GLenum pname, GLint + *params] + glGetNamedRenderbufferParameterivEXT: [void, GLuint renderbuffer, GLenum pname, + GLint *params] + glGetPointerIndexedvEXT: [void, GLenum target, GLuint index, GLvoid *data] + glGetPointeri_vEXT: [void, GLenum target, GLuint index, GLvoid *data] + glGetTextureImageEXT: [void, GLuint texture, GLenum target, GLint level, GLenum + format, GLenum type, GLvoid *pixels] + glGetTextureLevelParameterfvEXT: [void, GLuint texture, GLenum target, GLint level, + GLenum pname, GLfloat *params] + glGetTextureLevelParameterivEXT: [void, GLuint texture, GLenum target, GLint level, + GLenum pname, GLint *params] + glGetTextureParameterIivEXT: [void, GLuint texture, GLenum target, GLenum pname, + GLint *params] + glGetTextureParameterIuivEXT: [void, GLuint texture, GLenum target, GLenum pname, + GLuint *params] + glGetTextureParameterfvEXT: [void, GLuint texture, GLenum target, GLenum pname, + GLfloat *params] + glGetTextureParameterivEXT: [void, GLuint texture, GLenum target, GLenum pname, + GLint *params] + glGetVertexArrayIntegeri_vEXT: [void, GLuint vaobj, GLuint index, GLenum pname, + GLint *param] + glGetVertexArrayIntegervEXT: [void, GLuint vaobj, GLenum pname, GLint *param] + glGetVertexArrayPointeri_vEXT: [void, GLuint vaobj, GLuint index, GLenum pname, + GLvoid *param] + glGetVertexArrayPointervEXT: [void, GLuint vaobj, GLenum pname, GLvoid *param] + glMapNamedBufferEXT: [GLvoid *, GLuint buffer, GLenum access] + glMapNamedBufferRangeEXT: [GLvoid *, GLuint buffer, GLintptr offset, GLsizeiptr + length, GLbitfield access] + glMatrixFrustumEXT: [void, GLenum mode, GLdouble left, GLdouble right, GLdouble + bottom, GLdouble top, GLdouble zNear, GLdouble zFar] + glMatrixLoadIdentityEXT: [void, GLenum mode] + glMatrixLoadTransposedEXT: [void, GLenum mode, const GLdouble *m] + glMatrixLoadTransposefEXT: [void, GLenum mode, const GLfloat *m] + glMatrixLoaddEXT: [void, GLenum mode, const GLdouble *m] + glMatrixLoadfEXT: [void, GLenum mode, const GLfloat *m] + glMatrixMultTransposedEXT: [void, GLenum mode, const GLdouble *m] + glMatrixMultTransposefEXT: [void, GLenum mode, const GLfloat *m] + glMatrixMultdEXT: [void, GLenum mode, const GLdouble *m] + glMatrixMultfEXT: [void, GLenum mode, const GLfloat *m] + glMatrixOrthoEXT: [void, GLenum mode, GLdouble left, GLdouble right, GLdouble bottom, + GLdouble top, GLdouble zNear, GLdouble zFar] + glMatrixPopEXT: [void, GLenum mode] + glMatrixPushEXT: [void, GLenum mode] + glMatrixRotatedEXT: [void, GLenum mode, GLdouble angle, GLdouble x, GLdouble y, + GLdouble z] + glMatrixRotatefEXT: [void, GLenum mode, GLfloat angle, GLfloat x, GLfloat y, GLfloat + z] + glMatrixScaledEXT: [void, GLenum mode, GLdouble x, GLdouble y, GLdouble z] + glMatrixScalefEXT: [void, GLenum mode, GLfloat x, GLfloat y, GLfloat z] + glMatrixTranslatedEXT: [void, GLenum mode, GLdouble x, GLdouble y, GLdouble z] + glMatrixTranslatefEXT: [void, GLenum mode, GLfloat x, GLfloat y, GLfloat z] + glMultiTexBufferEXT: [void, GLenum texunit, GLenum target, GLenum internalformat, + GLuint buffer] + glMultiTexCoordPointerEXT: [void, GLenum texunit, GLint size, GLenum type, GLsizei + stride, const GLvoid *pointer] + glMultiTexEnvfEXT: [void, GLenum texunit, GLenum target, GLenum pname, GLfloat param] + glMultiTexEnvfvEXT: [void, GLenum texunit, GLenum target, GLenum pname, const GLfloat + *params] + glMultiTexEnviEXT: [void, GLenum texunit, GLenum target, GLenum pname, GLint param] + glMultiTexEnvivEXT: [void, GLenum texunit, GLenum target, GLenum pname, const GLint + *params] + glMultiTexGendEXT: [void, GLenum texunit, GLenum coord, GLenum pname, GLdouble param] + glMultiTexGendvEXT: [void, GLenum texunit, GLenum coord, GLenum pname, const GLdouble + *params] + glMultiTexGenfEXT: [void, GLenum texunit, GLenum coord, GLenum pname, GLfloat param] + glMultiTexGenfvEXT: [void, GLenum texunit, GLenum coord, GLenum pname, const GLfloat + *params] + glMultiTexGeniEXT: [void, GLenum texunit, GLenum coord, GLenum pname, GLint param] + glMultiTexGenivEXT: [void, GLenum texunit, GLenum coord, GLenum pname, const GLint + *params] + glMultiTexImage1DEXT: [void, GLenum texunit, GLenum target, GLint level, GLenum + internalformat, GLsizei width, GLint border, GLenum format, GLenum type, const + GLvoid *pixels] + glMultiTexImage2DEXT: [void, GLenum texunit, GLenum target, GLint level, GLenum + internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, + GLenum type, const GLvoid *pixels] + glMultiTexImage3DEXT: [void, GLenum texunit, GLenum target, GLint level, GLenum + internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, + GLenum format, GLenum type, const GLvoid *pixels] + glMultiTexParameterIivEXT: [void, GLenum texunit, GLenum target, GLenum pname, const + GLint *params] + glMultiTexParameterIuivEXT: [void, GLenum texunit, GLenum target, GLenum pname, + const GLuint *params] + glMultiTexParameterfEXT: [void, GLenum texunit, GLenum target, GLenum pname, GLfloat + param] + glMultiTexParameterfvEXT: [void, GLenum texunit, GLenum target, GLenum pname, const + GLfloat *params] + glMultiTexParameteriEXT: [void, GLenum texunit, GLenum target, GLenum pname, GLint + param] + glMultiTexParameterivEXT: [void, GLenum texunit, GLenum target, GLenum pname, const + GLint *params] + glMultiTexRenderbufferEXT: [void, GLenum texunit, GLenum target, GLuint renderbuffer] + glMultiTexSubImage1DEXT: [void, GLenum texunit, GLenum target, GLint level, GLint + xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid *pixels] + glMultiTexSubImage2DEXT: [void, GLenum texunit, GLenum target, GLint level, GLint + xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum + type, const GLvoid *pixels] + glMultiTexSubImage3DEXT: [void, GLenum texunit, GLenum target, GLint level, GLint + xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei + depth, GLenum format, GLenum type, const GLvoid *pixels] + glNamedBufferDataEXT: [void, GLuint buffer, GLsizeiptr size, const GLvoid *data, + GLenum usage] + glNamedBufferSubDataEXT: [void, GLuint buffer, GLintptr offset, GLsizeiptr size, + const GLvoid *data] + glNamedCopyBufferSubDataEXT: [void, GLuint readBuffer, GLuint writeBuffer, GLintptr + readOffset, GLintptr writeOffset, GLsizeiptr size] + glNamedFramebufferRenderbufferEXT: [void, GLuint framebuffer, GLenum attachment, + GLenum renderbuffertarget, GLuint renderbuffer] + glNamedFramebufferTexture1DEXT: [void, GLuint framebuffer, GLenum attachment, GLenum + textarget, GLuint texture, GLint level] + glNamedFramebufferTexture2DEXT: [void, GLuint framebuffer, GLenum attachment, GLenum + textarget, GLuint texture, GLint level] + glNamedFramebufferTexture3DEXT: [void, GLuint framebuffer, GLenum attachment, GLenum + textarget, GLuint texture, GLint level, GLint zoffset] + glNamedFramebufferTextureEXT: [void, GLuint framebuffer, GLenum attachment, GLuint + texture, GLint level] + glNamedFramebufferTextureFaceEXT: [void, GLuint framebuffer, GLenum attachment, + GLuint texture, GLint level, GLenum face] + glNamedFramebufferTextureLayerEXT: [void, GLuint framebuffer, GLenum attachment, + GLuint texture, GLint level, GLint layer] + glNamedProgramLocalParameter4dEXT: [void, GLuint program, GLenum target, GLuint + index, GLdouble x, GLdouble y, GLdouble z, GLdouble w] + glNamedProgramLocalParameter4dvEXT: [void, GLuint program, GLenum target, GLuint + index, const GLdouble *params] + glNamedProgramLocalParameter4fEXT: [void, GLuint program, GLenum target, GLuint + index, GLfloat x, GLfloat y, GLfloat z, GLfloat w] + glNamedProgramLocalParameter4fvEXT: [void, GLuint program, GLenum target, GLuint + index, const GLfloat *params] + glNamedProgramLocalParameterI4iEXT: [void, GLuint program, GLenum target, GLuint + index, GLint x, GLint y, GLint z, GLint w] + glNamedProgramLocalParameterI4ivEXT: [void, GLuint program, GLenum target, GLuint + index, const GLint *params] + glNamedProgramLocalParameterI4uiEXT: [void, GLuint program, GLenum target, GLuint + index, GLuint x, GLuint y, GLuint z, GLuint w] + glNamedProgramLocalParameterI4uivEXT: [void, GLuint program, GLenum target, GLuint + index, const GLuint *params] + glNamedProgramLocalParameters4fvEXT: [void, GLuint program, GLenum target, GLuint + index, GLsizei count, const GLfloat *params] + glNamedProgramLocalParametersI4ivEXT: [void, GLuint program, GLenum target, GLuint + index, GLsizei count, const GLint *params] + glNamedProgramLocalParametersI4uivEXT: [void, GLuint program, GLenum target, GLuint + index, GLsizei count, const GLuint *params] + glNamedProgramStringEXT: [void, GLuint program, GLenum target, GLenum format, GLsizei + len, const GLvoid *string] + glNamedRenderbufferStorageEXT: [void, GLuint renderbuffer, GLenum internalformat, + GLsizei width, GLsizei height] + glNamedRenderbufferStorageMultisampleCoverageEXT: [void, GLuint renderbuffer, GLsizei + coverageSamples, GLsizei colorSamples, GLenum internalformat, GLsizei width, + GLsizei height] + glNamedRenderbufferStorageMultisampleEXT: [void, GLuint renderbuffer, GLsizei samples, + GLenum internalformat, GLsizei width, GLsizei height] + glProgramUniform1dEXT: [void, GLuint program, GLint location, GLdouble x] + glProgramUniform1dvEXT: [void, GLuint program, GLint location, GLsizei count, const + GLdouble *value] + glProgramUniform1fEXT: [void, GLuint program, GLint location, GLfloat v0] + glProgramUniform1fvEXT: [void, GLuint program, GLint location, GLsizei count, const + GLfloat *value] + glProgramUniform1iEXT: [void, GLuint program, GLint location, GLint v0] + glProgramUniform1ivEXT: [void, GLuint program, GLint location, GLsizei count, const + GLint *value] + glProgramUniform1uiEXT: [void, GLuint program, GLint location, GLuint v0] + glProgramUniform1uivEXT: [void, GLuint program, GLint location, GLsizei count, const + GLuint *value] + glProgramUniform2dEXT: [void, GLuint program, GLint location, GLdouble x, GLdouble + y] + glProgramUniform2dvEXT: [void, GLuint program, GLint location, GLsizei count, const + GLdouble *value] + glProgramUniform2fEXT: [void, GLuint program, GLint location, GLfloat v0, GLfloat + v1] + glProgramUniform2fvEXT: [void, GLuint program, GLint location, GLsizei count, const + GLfloat *value] + glProgramUniform2iEXT: [void, GLuint program, GLint location, GLint v0, GLint v1] + glProgramUniform2ivEXT: [void, GLuint program, GLint location, GLsizei count, const + GLint *value] + glProgramUniform2uiEXT: [void, GLuint program, GLint location, GLuint v0, GLuint + v1] + glProgramUniform2uivEXT: [void, GLuint program, GLint location, GLsizei count, const + GLuint *value] + glProgramUniform3dEXT: [void, GLuint program, GLint location, GLdouble x, GLdouble + y, GLdouble z] + glProgramUniform3dvEXT: [void, GLuint program, GLint location, GLsizei count, const + GLdouble *value] + glProgramUniform3fEXT: [void, GLuint program, GLint location, GLfloat v0, GLfloat + v1, GLfloat v2] + glProgramUniform3fvEXT: [void, GLuint program, GLint location, GLsizei count, const + GLfloat *value] + glProgramUniform3iEXT: [void, GLuint program, GLint location, GLint v0, GLint v1, + GLint v2] + glProgramUniform3ivEXT: [void, GLuint program, GLint location, GLsizei count, const + GLint *value] + glProgramUniform3uiEXT: [void, GLuint program, GLint location, GLuint v0, GLuint + v1, GLuint v2] + glProgramUniform3uivEXT: [void, GLuint program, GLint location, GLsizei count, const + GLuint *value] + glProgramUniform4dEXT: [void, GLuint program, GLint location, GLdouble x, GLdouble + y, GLdouble z, GLdouble w] + glProgramUniform4dvEXT: [void, GLuint program, GLint location, GLsizei count, const + GLdouble *value] + glProgramUniform4fEXT: [void, GLuint program, GLint location, GLfloat v0, GLfloat + v1, GLfloat v2, GLfloat v3] + glProgramUniform4fvEXT: [void, GLuint program, GLint location, GLsizei count, const + GLfloat *value] + glProgramUniform4iEXT: [void, GLuint program, GLint location, GLint v0, GLint v1, + GLint v2, GLint v3] + glProgramUniform4ivEXT: [void, GLuint program, GLint location, GLsizei count, const + GLint *value] + glProgramUniform4uiEXT: [void, GLuint program, GLint location, GLuint v0, GLuint + v1, GLuint v2, GLuint v3] + glProgramUniform4uivEXT: [void, GLuint program, GLint location, GLsizei count, const + GLuint *value] + glProgramUniformMatrix2dvEXT: [void, GLuint program, GLint location, GLsizei count, + GLboolean transpose, const GLdouble *value] + glProgramUniformMatrix2fvEXT: [void, GLuint program, GLint location, GLsizei count, + GLboolean transpose, const GLfloat *value] + glProgramUniformMatrix2x3dvEXT: [void, GLuint program, GLint location, GLsizei count, + GLboolean transpose, const GLdouble *value] + glProgramUniformMatrix2x3fvEXT: [void, GLuint program, GLint location, GLsizei count, + GLboolean transpose, const GLfloat *value] + glProgramUniformMatrix2x4dvEXT: [void, GLuint program, GLint location, GLsizei count, + GLboolean transpose, const GLdouble *value] + glProgramUniformMatrix2x4fvEXT: [void, GLuint program, GLint location, GLsizei count, + GLboolean transpose, const GLfloat *value] + glProgramUniformMatrix3dvEXT: [void, GLuint program, GLint location, GLsizei count, + GLboolean transpose, const GLdouble *value] + glProgramUniformMatrix3fvEXT: [void, GLuint program, GLint location, GLsizei count, + GLboolean transpose, const GLfloat *value] + glProgramUniformMatrix3x2dvEXT: [void, GLuint program, GLint location, GLsizei count, + GLboolean transpose, const GLdouble *value] + glProgramUniformMatrix3x2fvEXT: [void, GLuint program, GLint location, GLsizei count, + GLboolean transpose, const GLfloat *value] + glProgramUniformMatrix3x4dvEXT: [void, GLuint program, GLint location, GLsizei count, + GLboolean transpose, const GLdouble *value] + glProgramUniformMatrix3x4fvEXT: [void, GLuint program, GLint location, GLsizei count, + GLboolean transpose, const GLfloat *value] + glProgramUniformMatrix4dvEXT: [void, GLuint program, GLint location, GLsizei count, + GLboolean transpose, const GLdouble *value] + glProgramUniformMatrix4fvEXT: [void, GLuint program, GLint location, GLsizei count, + GLboolean transpose, const GLfloat *value] + glProgramUniformMatrix4x2dvEXT: [void, GLuint program, GLint location, GLsizei count, + GLboolean transpose, const GLdouble *value] + glProgramUniformMatrix4x2fvEXT: [void, GLuint program, GLint location, GLsizei count, + GLboolean transpose, const GLfloat *value] + glProgramUniformMatrix4x3dvEXT: [void, GLuint program, GLint location, GLsizei count, + GLboolean transpose, const GLdouble *value] + glProgramUniformMatrix4x3fvEXT: [void, GLuint program, GLint location, GLsizei count, + GLboolean transpose, const GLfloat *value] + glPushClientAttribDefaultEXT: [void, GLbitfield mask] + glTextureBufferEXT: [void, GLuint texture, GLenum target, GLenum internalformat, + GLuint buffer] + glTextureImage1DEXT: [void, GLuint texture, GLenum target, GLint level, GLenum internalformat, + GLsizei width, GLint border, GLenum format, GLenum type, const GLvoid *pixels] + glTextureImage2DEXT: [void, GLuint texture, GLenum target, GLint level, GLenum internalformat, + GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const + GLvoid *pixels] + glTextureImage3DEXT: [void, GLuint texture, GLenum target, GLint level, GLenum internalformat, + GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum + type, const GLvoid *pixels] + glTextureParameterIivEXT: [void, GLuint texture, GLenum target, GLenum pname, const + GLint *params] + glTextureParameterIuivEXT: [void, GLuint texture, GLenum target, GLenum pname, const + GLuint *params] + glTextureParameterfEXT: [void, GLuint texture, GLenum target, GLenum pname, GLfloat + param] + glTextureParameterfvEXT: [void, GLuint texture, GLenum target, GLenum pname, const + GLfloat *params] + glTextureParameteriEXT: [void, GLuint texture, GLenum target, GLenum pname, GLint + param] + glTextureParameterivEXT: [void, GLuint texture, GLenum target, GLenum pname, const + GLint *params] + glTextureRenderbufferEXT: [void, GLuint texture, GLenum target, GLuint renderbuffer] + glTextureSubImage1DEXT: [void, GLuint texture, GLenum target, GLint level, GLint + xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid *pixels] + glTextureSubImage2DEXT: [void, GLuint texture, GLenum target, GLint level, GLint + xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum + type, const GLvoid *pixels] + glTextureSubImage3DEXT: [void, GLuint texture, GLenum target, GLint level, GLint + xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei + depth, GLenum format, GLenum type, const GLvoid *pixels] + glUnmapNamedBufferEXT: [GLboolean, GLuint buffer] + glVertexArrayColorOffsetEXT: [void, GLuint vaobj, GLuint buffer, GLint size, GLenum + type, GLsizei stride, GLintptr offset] + glVertexArrayEdgeFlagOffsetEXT: [void, GLuint vaobj, GLuint buffer, GLsizei stride, + GLintptr offset] + glVertexArrayFogCoordOffsetEXT: [void, GLuint vaobj, GLuint buffer, GLenum type, + GLsizei stride, GLintptr offset] + glVertexArrayIndexOffsetEXT: [void, GLuint vaobj, GLuint buffer, GLenum type, GLsizei + stride, GLintptr offset] + glVertexArrayMultiTexCoordOffsetEXT: [void, GLuint vaobj, GLuint buffer, GLenum + texunit, GLint size, GLenum type, GLsizei stride, GLintptr offset] + glVertexArrayNormalOffsetEXT: [void, GLuint vaobj, GLuint buffer, GLenum type, GLsizei + stride, GLintptr offset] + glVertexArraySecondaryColorOffsetEXT: [void, GLuint vaobj, GLuint buffer, GLint + size, GLenum type, GLsizei stride, GLintptr offset] + glVertexArrayTexCoordOffsetEXT: [void, GLuint vaobj, GLuint buffer, GLint size, + GLenum type, GLsizei stride, GLintptr offset] + glVertexArrayVertexAttribIOffsetEXT: [void, GLuint vaobj, GLuint buffer, GLuint + index, GLint size, GLenum type, GLsizei stride, GLintptr offset] + glVertexArrayVertexAttribOffsetEXT: [void, GLuint vaobj, GLuint buffer, GLuint index, + GLint size, GLenum type, GLboolean normalized, GLsizei stride, GLintptr offset] + glVertexArrayVertexOffsetEXT: [void, GLuint vaobj, GLuint buffer, GLint size, GLenum + type, GLsizei stride, GLintptr offset] +EXT_draw_buffers2: + glColorMaskIndexedEXT: [void, GLuint index, GLboolean r, GLboolean g, GLboolean + b, GLboolean a] + glDisableIndexedEXT: [void, GLenum target, GLuint index] + glEnableIndexedEXT: [void, GLenum target, GLuint index] + glGetBooleanIndexedvEXT: [void, GLenum target, GLuint index, GLboolean *data] + glGetIntegerIndexedvEXT: [void, GLenum target, GLuint index, GLint *data] + glIsEnabledIndexedEXT: [GLboolean, GLenum target, GLuint index] +EXT_draw_instanced: + glDrawArraysInstancedEXT: [void, GLenum mode, GLint start, GLsizei count, GLsizei + primcount] + glDrawElementsInstancedEXT: [void, GLenum mode, GLsizei count, GLenum type, const + GLvoid *indices, GLsizei primcount] +EXT_draw_range_elements: + glDrawRangeElementsEXT: [void, GLenum mode, GLuint start, GLuint end, GLsizei count, + GLenum type, const GLvoid *indices] +EXT_fog_coord: + glFogCoordPointerEXT: [void, GLenum type, GLsizei stride, const GLvoid *pointer] + glFogCoorddEXT: [void, GLdouble coord] + glFogCoorddvEXT: [void, const GLdouble *coord] + glFogCoordfEXT: [void, GLfloat coord] + glFogCoordfvEXT: [void, const GLfloat *coord] +EXT_framebuffer_blit: + glBlitFramebufferEXT: [void, GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, + GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter] +EXT_framebuffer_multisample: + glRenderbufferStorageMultisampleEXT: [void, GLenum target, GLsizei samples, GLenum + internalformat, GLsizei width, GLsizei height] +EXT_framebuffer_object: + glBindFramebufferEXT: [void, GLenum target, GLuint framebuffer] + glBindRenderbufferEXT: [void, GLenum target, GLuint renderbuffer] + glCheckFramebufferStatusEXT: [GLenum, GLenum target] + glDeleteFramebuffersEXT: [void, GLsizei n, const GLuint *framebuffers] + glDeleteRenderbuffersEXT: [void, GLsizei n, const GLuint *renderbuffers] + glFramebufferRenderbufferEXT: [void, GLenum target, GLenum attachment, GLenum renderbuffertarget, + GLuint renderbuffer] + glFramebufferTexture1DEXT: [void, GLenum target, GLenum attachment, GLenum textarget, + GLuint texture, GLint level] + glFramebufferTexture2DEXT: [void, GLenum target, GLenum attachment, GLenum textarget, + GLuint texture, GLint level] + glFramebufferTexture3DEXT: [void, GLenum target, GLenum attachment, GLenum textarget, + GLuint texture, GLint level, GLint zoffset] + glGenFramebuffersEXT: [void, GLsizei n, GLuint *framebuffers] + glGenRenderbuffersEXT: [void, GLsizei n, GLuint *renderbuffers] + glGenerateMipmapEXT: [void, GLenum target] + glGetFramebufferAttachmentParameterivEXT: [void, GLenum target, GLenum attachment, + GLenum pname, GLint *params] + glGetRenderbufferParameterivEXT: [void, GLenum target, GLenum pname, GLint *params] + glIsFramebufferEXT: [GLboolean, GLuint framebuffer] + glIsRenderbufferEXT: [GLboolean, GLuint renderbuffer] + glRenderbufferStorageEXT: [void, GLenum target, GLenum internalformat, GLsizei width, + GLsizei height] +EXT_geometry_shader4: + glProgramParameteriEXT: [void, GLuint program, GLenum pname, GLint value] +EXT_gpu_program_parameters: + glProgramEnvParameters4fvEXT: [void, GLenum target, GLuint index, GLsizei count, + const GLfloat *params] + glProgramLocalParameters4fvEXT: [void, GLenum target, GLuint index, GLsizei count, + const GLfloat *params] +EXT_gpu_shader4: + glBindFragDataLocationEXT: [void, GLuint program, GLuint color, const GLchar *name] + glGetFragDataLocationEXT: [GLint, GLuint program, const GLchar *name] + glGetUniformuivEXT: [void, GLuint program, GLint location, GLuint *params] + glUniform1uiEXT: [void, GLint location, GLuint v0] + glUniform1uivEXT: [void, GLint location, GLsizei count, const GLuint *value] + glUniform2uiEXT: [void, GLint location, GLuint v0, GLuint v1] + glUniform2uivEXT: [void, GLint location, GLsizei count, const GLuint *value] + glUniform3uiEXT: [void, GLint location, GLuint v0, GLuint v1, GLuint v2] + glUniform3uivEXT: [void, GLint location, GLsizei count, const GLuint *value] + glUniform4uiEXT: [void, GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint + v3] + glUniform4uivEXT: [void, GLint location, GLsizei count, const GLuint *value] +EXT_histogram: + glGetHistogramEXT: [void, GLenum target, GLboolean reset, GLenum format, GLenum + type, GLvoid *values] + glGetHistogramParameterfvEXT: [void, GLenum target, GLenum pname, GLfloat *params] + glGetHistogramParameterivEXT: [void, GLenum target, GLenum pname, GLint *params] + glGetMinmaxEXT: [void, GLenum target, GLboolean reset, GLenum format, GLenum type, + GLvoid *values] + glGetMinmaxParameterfvEXT: [void, GLenum target, GLenum pname, GLfloat *params] + glGetMinmaxParameterivEXT: [void, GLenum target, GLenum pname, GLint *params] + glHistogramEXT: [void, GLenum target, GLsizei width, GLenum internalformat, GLboolean + sink] + glMinmaxEXT: [void, GLenum target, GLenum internalformat, GLboolean sink] + glResetHistogramEXT: [void, GLenum target] + glResetMinmaxEXT: [void, GLenum target] +EXT_index_func: + glIndexFuncEXT: [void, GLenum func, GLclampf ref] +EXT_index_material: + glIndexMaterialEXT: [void, GLenum face, GLenum mode] +EXT_light_texture: + glApplyTextureEXT: [void, GLenum mode] + glTextureLightEXT: [void, GLenum pname] + glTextureMaterialEXT: [void, GLenum face, GLenum mode] +EXT_multi_draw_arrays: + glMultiDrawArraysEXT: [void, GLenum mode, const GLint *first, const GLsizei *count, + GLsizei primcount] + glMultiDrawElementsEXT: [void, GLenum mode, const GLsizei *count, GLenum type, const + GLvoid *indices, GLsizei primcount] +EXT_multisample: + glSampleMaskEXT: [void, GLclampf value, GLboolean invert] + glSamplePatternEXT: [void, GLenum pattern] +EXT_paletted_texture: + glColorTableEXT: [void, GLenum target, GLenum internalFormat, GLsizei width, GLenum + format, GLenum type, const GLvoid *table] + glGetColorTableEXT: [void, GLenum target, GLenum format, GLenum type, GLvoid *data] + glGetColorTableParameterfvEXT: [void, GLenum target, GLenum pname, GLfloat *params] + glGetColorTableParameterivEXT: [void, GLenum target, GLenum pname, GLint *params] +EXT_pixel_transform: + glGetPixelTransformParameterfvEXT: [void, GLenum target, GLenum pname, GLfloat *params] + glGetPixelTransformParameterivEXT: [void, GLenum target, GLenum pname, GLint *params] + glPixelTransformParameterfEXT: [void, GLenum target, GLenum pname, GLfloat param] + glPixelTransformParameterfvEXT: [void, GLenum target, GLenum pname, const GLfloat + *params] + glPixelTransformParameteriEXT: [void, GLenum target, GLenum pname, GLint param] + glPixelTransformParameterivEXT: [void, GLenum target, GLenum pname, const GLint + *params] +EXT_point_parameters: + glPointParameterfEXT: [void, GLenum pname, GLfloat param] + glPointParameterfvEXT: [void, GLenum pname, const GLfloat *params] +EXT_polygon_offset: + glPolygonOffsetEXT: [void, GLfloat factor, GLfloat bias] +EXT_provoking_vertex: + glProvokingVertexEXT: [void, GLenum mode] +EXT_secondary_color: + glSecondaryColor3bEXT: [void, GLbyte red, GLbyte green, GLbyte blue] + glSecondaryColor3bvEXT: [void, const GLbyte *v] + glSecondaryColor3dEXT: [void, GLdouble red, GLdouble green, GLdouble blue] + glSecondaryColor3dvEXT: [void, const GLdouble *v] + glSecondaryColor3fEXT: [void, GLfloat red, GLfloat green, GLfloat blue] + glSecondaryColor3fvEXT: [void, const GLfloat *v] + glSecondaryColor3iEXT: [void, GLint red, GLint green, GLint blue] + glSecondaryColor3ivEXT: [void, const GLint *v] + glSecondaryColor3sEXT: [void, GLshort red, GLshort green, GLshort blue] + glSecondaryColor3svEXT: [void, const GLshort *v] + glSecondaryColor3ubEXT: [void, GLubyte red, GLubyte green, GLubyte blue] + glSecondaryColor3ubvEXT: [void, const GLubyte *v] + glSecondaryColor3uiEXT: [void, GLuint red, GLuint green, GLuint blue] + glSecondaryColor3uivEXT: [void, const GLuint *v] + glSecondaryColor3usEXT: [void, GLushort red, GLushort green, GLushort blue] + glSecondaryColor3usvEXT: [void, const GLushort *v] + glSecondaryColorPointerEXT: [void, GLint size, GLenum type, GLsizei stride, const + GLvoid *pointer] +EXT_separate_shader_objects: + glActiveProgramEXT: [void, GLuint program] + glCreateShaderProgramEXT: [GLuint, GLenum type, const GLchar *string] + glUseShaderProgramEXT: [void, GLenum type, GLuint program] +EXT_shader_image_load_store: + glBindImageTextureEXT: [void, GLuint index, GLuint texture, GLint level, GLboolean + layered, GLint layer, GLenum access, GLint format] + glMemoryBarrierEXT: [void, GLbitfield barriers] +EXT_stencil_clear_tag: + glStencilClearTagEXT: [void, GLsizei stencilTagBits, GLuint stencilClearTag] +EXT_stencil_two_side: + glActiveStencilFaceEXT: [void, GLenum face] +EXT_subtexture: + glTexSubImage1DEXT: [void, GLenum target, GLint level, GLint xoffset, GLsizei width, + GLenum format, GLenum type, const GLvoid *pixels] + glTexSubImage2DEXT: [void, GLenum target, GLint level, GLint xoffset, GLint yoffset, + GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels] +EXT_texture3D: + glTexImage3DEXT: [void, GLenum target, GLint level, GLenum internalformat, GLsizei + width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, + const GLvoid *pixels] + glTexSubImage3DEXT: [void, GLenum target, GLint level, GLint xoffset, GLint yoffset, + GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum + type, const GLvoid *pixels] +EXT_texture_buffer_object: + glTexBufferEXT: [void, GLenum target, GLenum internalformat, GLuint buffer] +EXT_texture_integer: + glClearColorIiEXT: [void, GLint red, GLint green, GLint blue, GLint alpha] + glClearColorIuiEXT: [void, GLuint red, GLuint green, GLuint blue, GLuint alpha] + glGetTexParameterIivEXT: [void, GLenum target, GLenum pname, GLint *params] + glGetTexParameterIuivEXT: [void, GLenum target, GLenum pname, GLuint *params] + glTexParameterIivEXT: [void, GLenum target, GLenum pname, const GLint *params] + glTexParameterIuivEXT: [void, GLenum target, GLenum pname, const GLuint *params] +EXT_texture_object: + glAreTexturesResidentEXT: [GLboolean, GLsizei n, const GLuint *textures, GLboolean + *residences] + glBindTextureEXT: [void, GLenum target, GLuint texture] + glDeleteTexturesEXT: [void, GLsizei n, const GLuint *textures] + glGenTexturesEXT: [void, GLsizei n, GLuint *textures] + glIsTextureEXT: [GLboolean, GLuint texture] + glPrioritizeTexturesEXT: [void, GLsizei n, const GLuint *textures, const GLclampf + *priorities] +EXT_texture_perturb_normal: + glTextureNormalEXT: [void, GLenum mode] +EXT_timer_query: + glGetQueryObjecti64vEXT: [void, GLuint id, GLenum pname, GLint64EXT *params] + glGetQueryObjectui64vEXT: [void, GLuint id, GLenum pname, GLuint64EXT *params] +EXT_transform_feedback: + glBeginTransformFeedbackEXT: [void, GLenum primitiveMode] + glBindBufferBaseEXT: [void, GLenum target, GLuint index, GLuint buffer] + glBindBufferOffsetEXT: [void, GLenum target, GLuint index, GLuint buffer, GLintptr + offset] + glBindBufferRangeEXT: [void, GLenum target, GLuint index, GLuint buffer, GLintptr + offset, GLsizeiptr size] + glEndTransformFeedbackEXT: [void] + glGetTransformFeedbackVaryingEXT: [void, GLuint program, GLuint index, GLsizei bufSize, + GLsizei *length, GLsizei *size, GLenum *type, GLchar *name] + glTransformFeedbackVaryingsEXT: [void, GLuint program, GLsizei count, const GLchar + *varyings, GLenum bufferMode] +EXT_vertex_array: + glArrayElementEXT: [void, GLint i] + glColorPointerEXT: [void, GLint size, GLenum type, GLsizei stride, GLsizei count, + const GLvoid *pointer] + glDrawArraysEXT: [void, GLenum mode, GLint first, GLsizei count] + glEdgeFlagPointerEXT: [void, GLsizei stride, GLsizei count, const GLboolean *pointer] + glGetPointervEXT: [void, GLenum pname, GLvoid *params] + glIndexPointerEXT: [void, GLenum type, GLsizei stride, GLsizei count, const GLvoid + *pointer] + glNormalPointerEXT: [void, GLenum type, GLsizei stride, GLsizei count, const GLvoid + *pointer] + glTexCoordPointerEXT: [void, GLint size, GLenum type, GLsizei stride, GLsizei count, + const GLvoid *pointer] + glVertexPointerEXT: [void, GLint size, GLenum type, GLsizei stride, GLsizei count, + const GLvoid *pointer] +EXT_vertex_attrib_64bit: + glGetVertexAttribLdvEXT: [void, GLuint index, GLenum pname, GLdouble *params] + glVertexArrayVertexAttribLOffsetEXT: [void, GLuint vaobj, GLuint buffer, GLuint + index, GLint size, GLenum type, GLsizei stride, GLintptr offset] + glVertexAttribL1dEXT: [void, GLuint index, GLdouble x] + glVertexAttribL1dvEXT: [void, GLuint index, const GLdouble *v] + glVertexAttribL2dEXT: [void, GLuint index, GLdouble x, GLdouble y] + glVertexAttribL2dvEXT: [void, GLuint index, const GLdouble *v] + glVertexAttribL3dEXT: [void, GLuint index, GLdouble x, GLdouble y, GLdouble z] + glVertexAttribL3dvEXT: [void, GLuint index, const GLdouble *v] + glVertexAttribL4dEXT: [void, GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble + w] + glVertexAttribL4dvEXT: [void, GLuint index, const GLdouble *v] + glVertexAttribLPointerEXT: [void, GLuint index, GLint size, GLenum type, GLsizei + stride, const GLvoid *pointer] +EXT_vertex_shader: + glBeginVertexShaderEXT: [void] + glBindLightParameterEXT: [GLuint, GLenum light, GLenum value] + glBindMaterialParameterEXT: [GLuint, GLenum face, GLenum value] + glBindParameterEXT: [GLuint, GLenum value] + glBindTexGenParameterEXT: [GLuint, GLenum unit, GLenum coord, GLenum value] + glBindTextureUnitParameterEXT: [GLuint, GLenum unit, GLenum value] + glBindVertexShaderEXT: [void, GLuint id] + glDeleteVertexShaderEXT: [void, GLuint id] + glDisableVariantClientStateEXT: [void, GLuint id] + glEnableVariantClientStateEXT: [void, GLuint id] + glEndVertexShaderEXT: [void] + glExtractComponentEXT: [void, GLuint res, GLuint src, GLuint num] + glGenSymbolsEXT: [GLuint, GLenum datatype, GLenum storagetype, GLenum range, GLuint + components] + glGenVertexShadersEXT: [GLuint, GLuint range] + glGetInvariantBooleanvEXT: [void, GLuint id, GLenum value, GLboolean *data] + glGetInvariantFloatvEXT: [void, GLuint id, GLenum value, GLfloat *data] + glGetInvariantIntegervEXT: [void, GLuint id, GLenum value, GLint *data] + glGetLocalConstantBooleanvEXT: [void, GLuint id, GLenum value, GLboolean *data] + glGetLocalConstantFloatvEXT: [void, GLuint id, GLenum value, GLfloat *data] + glGetLocalConstantIntegervEXT: [void, GLuint id, GLenum value, GLint *data] + glGetVariantBooleanvEXT: [void, GLuint id, GLenum value, GLboolean *data] + glGetVariantFloatvEXT: [void, GLuint id, GLenum value, GLfloat *data] + glGetVariantIntegervEXT: [void, GLuint id, GLenum value, GLint *data] + glGetVariantPointervEXT: [void, GLuint id, GLenum value, GLvoid *data] + glInsertComponentEXT: [void, GLuint res, GLuint src, GLuint num] + glIsVariantEnabledEXT: [GLboolean, GLuint id, GLenum cap] + glSetInvariantEXT: [void, GLuint id, GLenum type, const GLvoid *addr] + glSetLocalConstantEXT: [void, GLuint id, GLenum type, const GLvoid *addr] + glShaderOp1EXT: [void, GLenum op, GLuint res, GLuint arg1] + glShaderOp2EXT: [void, GLenum op, GLuint res, GLuint arg1, GLuint arg2] + glShaderOp3EXT: [void, GLenum op, GLuint res, GLuint arg1, GLuint arg2, GLuint arg3] + glSwizzleEXT: [void, GLuint res, GLuint in, GLenum outX, GLenum outY, GLenum outZ, + GLenum outW] + glVariantPointerEXT: [void, GLuint id, GLenum type, GLuint stride, const GLvoid + *addr] + glVariantbvEXT: [void, GLuint id, const GLbyte *addr] + glVariantdvEXT: [void, GLuint id, const GLdouble *addr] + glVariantfvEXT: [void, GLuint id, const GLfloat *addr] + glVariantivEXT: [void, GLuint id, const GLint *addr] + glVariantsvEXT: [void, GLuint id, const GLshort *addr] + glVariantubvEXT: [void, GLuint id, const GLubyte *addr] + glVariantuivEXT: [void, GLuint id, const GLuint *addr] + glVariantusvEXT: [void, GLuint id, const GLushort *addr] + glWriteMaskEXT: [void, GLuint res, GLuint in, GLenum outX, GLenum outY, GLenum outZ, + GLenum outW] +EXT_vertex_weighting: + glVertexWeightPointerEXT: [void, GLint size, GLenum type, GLsizei stride, const + GLvoid *pointer] + glVertexWeightfEXT: [void, GLfloat weight] + glVertexWeightfvEXT: [void, const GLfloat *weight] +EXT_x11_sync_object: + glImportSyncEXT: [GLsync, GLenum external_sync_type, GLintptr external_sync, GLbitfield + flags] +GREMEDY_frame_terminator: + glFrameTerminatorGREMEDY: [void] +GREMEDY_string_marker: + glStringMarkerGREMEDY: [void, GLsizei len, const GLvoid *string] +HP_image_transform: + glGetImageTransformParameterfvHP: [void, GLenum target, GLenum pname, GLfloat *params] + glGetImageTransformParameterivHP: [void, GLenum target, GLenum pname, GLint *params] + glImageTransformParameterfHP: [void, GLenum target, GLenum pname, GLfloat param] + glImageTransformParameterfvHP: [void, GLenum target, GLenum pname, const GLfloat + *params] + glImageTransformParameteriHP: [void, GLenum target, GLenum pname, GLint param] + glImageTransformParameterivHP: [void, GLenum target, GLenum pname, const GLint *params] +IBM_multimode_draw_arrays: + glMultiModeDrawArraysIBM: [void, const GLenum *mode, const GLint *first, const GLsizei + *count, GLsizei primcount, GLint modestride] + glMultiModeDrawElementsIBM: [void, const GLenum *mode, const GLsizei *count, GLenum + type, GLvoid*const *indices, GLsizei primcount, GLint modestride] +IBM_static_data: + glFlushStaticDataIBM: [void, GLenum target] +IBM_vertex_array_lists: + glColorPointerListIBM: [void, GLint size, GLenum type, GLint stride, const GLvoid + *pointer, GLint ptrstride] + glEdgeFlagPointerListIBM: [void, GLint stride, const GLboolean *pointer, GLint ptrstride] + glFogCoordPointerListIBM: [void, GLenum type, GLint stride, const GLvoid *pointer, + GLint ptrstride] + glIndexPointerListIBM: [void, GLenum type, GLint stride, const GLvoid *pointer, + GLint ptrstride] + glNormalPointerListIBM: [void, GLenum type, GLint stride, const GLvoid *pointer, + GLint ptrstride] + glSecondaryColorPointerListIBM: [void, GLint size, GLenum type, GLint stride, const + GLvoid *pointer, GLint ptrstride] + glTexCoordPointerListIBM: [void, GLint size, GLenum type, GLint stride, const GLvoid + *pointer, GLint ptrstride] + glVertexPointerListIBM: [void, GLint size, GLenum type, GLint stride, const GLvoid + *pointer, GLint ptrstride] +INGR_blend_func_separate: + glBlendFuncSeparateINGR: [void, GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, + GLenum dfactorAlpha] +INTEL_map_texture: + glMapTexture2DINTEL: [GLvoid *, GLuint texture, GLint level, GLbitfield access, + const GLint *stride, const GLenum *layout] + glSyncTextureINTEL: [void, GLuint texture] + glUnmapTexture2DINTEL: [void, GLuint texture, GLint level] +INTEL_parallel_arrays: + glColorPointervINTEL: [void, GLint size, GLenum type, const GLvoid *pointer] + glNormalPointervINTEL: [void, GLenum type, const GLvoid *pointer] + glTexCoordPointervINTEL: [void, GLint size, GLenum type, const GLvoid *pointer] + glVertexPointervINTEL: [void, GLint size, GLenum type, const GLvoid *pointer] +KHR_debug: + glDebugMessageCallback: [void, GLDEBUGPROC callback, const void *userParam] + glDebugMessageControl: [void, GLenum source, GLenum type, GLenum severity, GLsizei + count, const GLuint *ids, GLboolean enabled] + glDebugMessageInsert: [void, GLenum source, GLenum type, GLuint id, GLenum severity, + GLsizei length, const GLchar *buf] + glGetDebugMessageLog: [GLuint, GLuint count, GLsizei bufsize, GLenum *sources, GLenum + *types, GLuint *ids, GLenum *severities, GLsizei *lengths, GLchar *messageLog] + glGetObjectLabel: [void, GLenum identifier, GLuint name, GLsizei bufSize, GLsizei + *length, GLchar *label] + glGetObjectPtrLabel: [void, const void *ptr, GLsizei bufSize, GLsizei *length, GLchar + *label] + glObjectLabel: [void, GLenum identifier, GLuint name, GLsizei length, const GLchar + *label] + glObjectPtrLabel: [void, const void *ptr, GLsizei length, const GLchar *label] + glPopDebugGroup: [void] + glPushDebugGroup: [void, GLenum source, GLuint id, GLsizei length, const GLchar + *message] +MESA_resize_buffers: + glResizeBuffersMESA: [void] +MESA_window_pos: + glWindowPos2dMESA: [void, GLdouble x, GLdouble y] + glWindowPos2dvMESA: [void, const GLdouble *v] + glWindowPos2fMESA: [void, GLfloat x, GLfloat y] + glWindowPos2fvMESA: [void, const GLfloat *v] + glWindowPos2iMESA: [void, GLint x, GLint y] + glWindowPos2ivMESA: [void, const GLint *v] + glWindowPos2sMESA: [void, GLshort x, GLshort y] + glWindowPos2svMESA: [void, const GLshort *v] + glWindowPos3dMESA: [void, GLdouble x, GLdouble y, GLdouble z] + glWindowPos3dvMESA: [void, const GLdouble *v] + glWindowPos3fMESA: [void, GLfloat x, GLfloat y, GLfloat z] + glWindowPos3fvMESA: [void, const GLfloat *v] + glWindowPos3iMESA: [void, GLint x, GLint y, GLint z] + glWindowPos3ivMESA: [void, const GLint *v] + glWindowPos3sMESA: [void, GLshort x, GLshort y, GLshort z] + glWindowPos3svMESA: [void, const GLshort *v] + glWindowPos4dMESA: [void, GLdouble x, GLdouble y, GLdouble z, GLdouble w] + glWindowPos4dvMESA: [void, const GLdouble *v] + glWindowPos4fMESA: [void, GLfloat x, GLfloat y, GLfloat z, GLfloat w] + glWindowPos4fvMESA: [void, const GLfloat *v] + glWindowPos4iMESA: [void, GLint x, GLint y, GLint z, GLint w] + glWindowPos4ivMESA: [void, const GLint *v] + glWindowPos4sMESA: [void, GLshort x, GLshort y, GLshort z, GLshort w] + glWindowPos4svMESA: [void, const GLshort *v] +NVX_conditional_render: + glBeginConditionalRenderNVX: [void, GLuint id] + glEndConditionalRenderNVX: [void] +NV_bindless_texture: + glGetImageHandleNV: [GLuint64, GLuint texture, GLint level, GLboolean layered, GLint + layer, GLenum format] + glGetTextureHandleNV: [GLuint64, GLuint texture] + glGetTextureSamplerHandleNV: [GLuint64, GLuint texture, GLuint sampler] + glIsImageHandleResidentNV: [GLboolean, GLuint64 handle] + glIsTextureHandleResidentNV: [GLboolean, GLuint64 handle] + glMakeImageHandleNonResidentNV: [void, GLuint64 handle] + glMakeImageHandleResidentNV: [void, GLuint64 handle, GLenum access] + glMakeTextureHandleNonResidentNV: [void, GLuint64 handle] + glMakeTextureHandleResidentNV: [void, GLuint64 handle] + glProgramUniformHandleui64NV: [void, GLuint program, GLint location, GLuint64 value] + glProgramUniformHandleui64vNV: [void, GLuint program, GLint location, GLsizei count, + const GLuint64 *values] + glUniformHandleui64NV: [void, GLint location, GLuint64 value] + glUniformHandleui64vNV: [void, GLint location, GLsizei count, const GLuint64 *value] +NV_conditional_render: + glBeginConditionalRenderNV: [void, GLuint id, GLenum mode] + glEndConditionalRenderNV: [void] +NV_copy_image: + glCopyImageSubDataNV: [void, GLuint srcName, GLenum srcTarget, GLint srcLevel, GLint + srcX, GLint srcY, GLint srcZ, GLuint dstName, GLenum dstTarget, GLint dstLevel, + GLint dstX, GLint dstY, GLint dstZ, GLsizei width, GLsizei height, GLsizei depth] +NV_depth_buffer_float: + glClearDepthdNV: [void, GLdouble depth] + glDepthBoundsdNV: [void, GLdouble zmin, GLdouble zmax] + glDepthRangedNV: [void, GLdouble zNear, GLdouble zFar] +NV_draw_texture: + glDrawTextureNV: [void, GLuint texture, GLuint sampler, GLfloat x0, GLfloat y0, + GLfloat x1, GLfloat y1, GLfloat z, GLfloat s0, GLfloat t0, GLfloat s1, GLfloat + t1] +NV_evaluators: + glEvalMapsNV: [void, GLenum target, GLenum mode] + glGetMapAttribParameterfvNV: [void, GLenum target, GLuint index, GLenum pname, GLfloat + *params] + glGetMapAttribParameterivNV: [void, GLenum target, GLuint index, GLenum pname, GLint + *params] + glGetMapControlPointsNV: [void, GLenum target, GLuint index, GLenum type, GLsizei + ustride, GLsizei vstride, GLboolean packed, GLvoid *points] + glGetMapParameterfvNV: [void, GLenum target, GLenum pname, GLfloat *params] + glGetMapParameterivNV: [void, GLenum target, GLenum pname, GLint *params] + glMapControlPointsNV: [void, GLenum target, GLuint index, GLenum type, GLsizei ustride, + GLsizei vstride, GLint uorder, GLint vorder, GLboolean packed, const GLvoid *points] + glMapParameterfvNV: [void, GLenum target, GLenum pname, const GLfloat *params] + glMapParameterivNV: [void, GLenum target, GLenum pname, const GLint *params] +NV_explicit_multisample: + glGetMultisamplefvNV: [void, GLenum pname, GLuint index, GLfloat *val] + glSampleMaskIndexedNV: [void, GLuint index, GLbitfield mask] + glTexRenderbufferNV: [void, GLenum target, GLuint renderbuffer] +NV_fence: + glDeleteFencesNV: [void, GLsizei n, const GLuint *fences] + glFinishFenceNV: [void, GLuint fence] + glGenFencesNV: [void, GLsizei n, GLuint *fences] + glGetFenceivNV: [void, GLuint fence, GLenum pname, GLint *params] + glIsFenceNV: [GLboolean, GLuint fence] + glSetFenceNV: [void, GLuint fence, GLenum condition] + glTestFenceNV: [GLboolean, GLuint fence] +NV_fragment_program: + glGetProgramNamedParameterdvNV: [void, GLuint id, GLsizei len, const GLubyte *name, + GLdouble *params] + glGetProgramNamedParameterfvNV: [void, GLuint id, GLsizei len, const GLubyte *name, + GLfloat *params] + glProgramNamedParameter4dNV: [void, GLuint id, GLsizei len, const GLubyte *name, + GLdouble x, GLdouble y, GLdouble z, GLdouble w] + glProgramNamedParameter4dvNV: [void, GLuint id, GLsizei len, const GLubyte *name, + const GLdouble *v] + glProgramNamedParameter4fNV: [void, GLuint id, GLsizei len, const GLubyte *name, + GLfloat x, GLfloat y, GLfloat z, GLfloat w] + glProgramNamedParameter4fvNV: [void, GLuint id, GLsizei len, const GLubyte *name, + const GLfloat *v] +NV_framebuffer_multisample_coverage: + glRenderbufferStorageMultisampleCoverageNV: [void, GLenum target, GLsizei coverageSamples, + GLsizei colorSamples, GLenum internalformat, GLsizei width, GLsizei height] +NV_geometry_program4: + glFramebufferTextureEXT: [void, GLenum target, GLenum attachment, GLuint texture, + GLint level] + glFramebufferTextureFaceEXT: [void, GLenum target, GLenum attachment, GLuint texture, + GLint level, GLenum face] + glFramebufferTextureLayerEXT: [void, GLenum target, GLenum attachment, GLuint texture, + GLint level, GLint layer] + glProgramVertexLimitNV: [void, GLenum target, GLint limit] +NV_gpu_program4: + glGetProgramEnvParameterIivNV: [void, GLenum target, GLuint index, GLint *params] + glGetProgramEnvParameterIuivNV: [void, GLenum target, GLuint index, GLuint *params] + glGetProgramLocalParameterIivNV: [void, GLenum target, GLuint index, GLint *params] + glGetProgramLocalParameterIuivNV: [void, GLenum target, GLuint index, GLuint *params] + glProgramEnvParameterI4iNV: [void, GLenum target, GLuint index, GLint x, GLint y, + GLint z, GLint w] + glProgramEnvParameterI4ivNV: [void, GLenum target, GLuint index, const GLint *params] + glProgramEnvParameterI4uiNV: [void, GLenum target, GLuint index, GLuint x, GLuint + y, GLuint z, GLuint w] + glProgramEnvParameterI4uivNV: [void, GLenum target, GLuint index, const GLuint *params] + glProgramEnvParametersI4ivNV: [void, GLenum target, GLuint index, GLsizei count, + const GLint *params] + glProgramEnvParametersI4uivNV: [void, GLenum target, GLuint index, GLsizei count, + const GLuint *params] + glProgramLocalParameterI4iNV: [void, GLenum target, GLuint index, GLint x, GLint + y, GLint z, GLint w] + glProgramLocalParameterI4ivNV: [void, GLenum target, GLuint index, const GLint *params] + glProgramLocalParameterI4uiNV: [void, GLenum target, GLuint index, GLuint x, GLuint + y, GLuint z, GLuint w] + glProgramLocalParameterI4uivNV: [void, GLenum target, GLuint index, const GLuint + *params] + glProgramLocalParametersI4ivNV: [void, GLenum target, GLuint index, GLsizei count, + const GLint *params] + glProgramLocalParametersI4uivNV: [void, GLenum target, GLuint index, GLsizei count, + const GLuint *params] +NV_gpu_program5: + glGetProgramSubroutineParameteruivNV: [void, GLenum target, GLuint index, GLuint + *param] + glProgramSubroutineParametersuivNV: [void, GLenum target, GLsizei count, const GLuint + *params] +NV_gpu_shader5: + glGetUniformi64vNV: [void, GLuint program, GLint location, GLint64EXT *params] + glProgramUniform1i64NV: [void, GLuint program, GLint location, GLint64EXT x] + glProgramUniform1i64vNV: [void, GLuint program, GLint location, GLsizei count, const + GLint64EXT *value] + glProgramUniform1ui64NV: [void, GLuint program, GLint location, GLuint64EXT x] + glProgramUniform1ui64vNV: [void, GLuint program, GLint location, GLsizei count, + const GLuint64EXT *value] + glProgramUniform2i64NV: [void, GLuint program, GLint location, GLint64EXT x, GLint64EXT + y] + glProgramUniform2i64vNV: [void, GLuint program, GLint location, GLsizei count, const + GLint64EXT *value] + glProgramUniform2ui64NV: [void, GLuint program, GLint location, GLuint64EXT x, GLuint64EXT + y] + glProgramUniform2ui64vNV: [void, GLuint program, GLint location, GLsizei count, + const GLuint64EXT *value] + glProgramUniform3i64NV: [void, GLuint program, GLint location, GLint64EXT x, GLint64EXT + y, GLint64EXT z] + glProgramUniform3i64vNV: [void, GLuint program, GLint location, GLsizei count, const + GLint64EXT *value] + glProgramUniform3ui64NV: [void, GLuint program, GLint location, GLuint64EXT x, GLuint64EXT + y, GLuint64EXT z] + glProgramUniform3ui64vNV: [void, GLuint program, GLint location, GLsizei count, + const GLuint64EXT *value] + glProgramUniform4i64NV: [void, GLuint program, GLint location, GLint64EXT x, GLint64EXT + y, GLint64EXT z, GLint64EXT w] + glProgramUniform4i64vNV: [void, GLuint program, GLint location, GLsizei count, const + GLint64EXT *value] + glProgramUniform4ui64NV: [void, GLuint program, GLint location, GLuint64EXT x, GLuint64EXT + y, GLuint64EXT z, GLuint64EXT w] + glProgramUniform4ui64vNV: [void, GLuint program, GLint location, GLsizei count, + const GLuint64EXT *value] + glUniform1i64NV: [void, GLint location, GLint64EXT x] + glUniform1i64vNV: [void, GLint location, GLsizei count, const GLint64EXT *value] + glUniform1ui64NV: [void, GLint location, GLuint64EXT x] + glUniform1ui64vNV: [void, GLint location, GLsizei count, const GLuint64EXT *value] + glUniform2i64NV: [void, GLint location, GLint64EXT x, GLint64EXT y] + glUniform2i64vNV: [void, GLint location, GLsizei count, const GLint64EXT *value] + glUniform2ui64NV: [void, GLint location, GLuint64EXT x, GLuint64EXT y] + glUniform2ui64vNV: [void, GLint location, GLsizei count, const GLuint64EXT *value] + glUniform3i64NV: [void, GLint location, GLint64EXT x, GLint64EXT y, GLint64EXT z] + glUniform3i64vNV: [void, GLint location, GLsizei count, const GLint64EXT *value] + glUniform3ui64NV: [void, GLint location, GLuint64EXT x, GLuint64EXT y, GLuint64EXT + z] + glUniform3ui64vNV: [void, GLint location, GLsizei count, const GLuint64EXT *value] + glUniform4i64NV: [void, GLint location, GLint64EXT x, GLint64EXT y, GLint64EXT z, + GLint64EXT w] + glUniform4i64vNV: [void, GLint location, GLsizei count, const GLint64EXT *value] + glUniform4ui64NV: [void, GLint location, GLuint64EXT x, GLuint64EXT y, GLuint64EXT + z, GLuint64EXT w] + glUniform4ui64vNV: [void, GLint location, GLsizei count, const GLuint64EXT *value] +NV_half_float: + glColor3hNV: [void, GLhalfNV red, GLhalfNV green, GLhalfNV blue] + glColor3hvNV: [void, const GLhalfNV *v] + glColor4hNV: [void, GLhalfNV red, GLhalfNV green, GLhalfNV blue, GLhalfNV alpha] + glColor4hvNV: [void, const GLhalfNV *v] + glFogCoordhNV: [void, GLhalfNV fog] + glFogCoordhvNV: [void, const GLhalfNV *fog] + glMultiTexCoord1hNV: [void, GLenum target, GLhalfNV s] + glMultiTexCoord1hvNV: [void, GLenum target, const GLhalfNV *v] + glMultiTexCoord2hNV: [void, GLenum target, GLhalfNV s, GLhalfNV t] + glMultiTexCoord2hvNV: [void, GLenum target, const GLhalfNV *v] + glMultiTexCoord3hNV: [void, GLenum target, GLhalfNV s, GLhalfNV t, GLhalfNV r] + glMultiTexCoord3hvNV: [void, GLenum target, const GLhalfNV *v] + glMultiTexCoord4hNV: [void, GLenum target, GLhalfNV s, GLhalfNV t, GLhalfNV r, GLhalfNV + q] + glMultiTexCoord4hvNV: [void, GLenum target, const GLhalfNV *v] + glNormal3hNV: [void, GLhalfNV nx, GLhalfNV ny, GLhalfNV nz] + glNormal3hvNV: [void, const GLhalfNV *v] + glSecondaryColor3hNV: [void, GLhalfNV red, GLhalfNV green, GLhalfNV blue] + glSecondaryColor3hvNV: [void, const GLhalfNV *v] + glTexCoord1hNV: [void, GLhalfNV s] + glTexCoord1hvNV: [void, const GLhalfNV *v] + glTexCoord2hNV: [void, GLhalfNV s, GLhalfNV t] + glTexCoord2hvNV: [void, const GLhalfNV *v] + glTexCoord3hNV: [void, GLhalfNV s, GLhalfNV t, GLhalfNV r] + glTexCoord3hvNV: [void, const GLhalfNV *v] + glTexCoord4hNV: [void, GLhalfNV s, GLhalfNV t, GLhalfNV r, GLhalfNV q] + glTexCoord4hvNV: [void, const GLhalfNV *v] + glVertex2hNV: [void, GLhalfNV x, GLhalfNV y] + glVertex2hvNV: [void, const GLhalfNV *v] + glVertex3hNV: [void, GLhalfNV x, GLhalfNV y, GLhalfNV z] + glVertex3hvNV: [void, const GLhalfNV *v] + glVertex4hNV: [void, GLhalfNV x, GLhalfNV y, GLhalfNV z, GLhalfNV w] + glVertex4hvNV: [void, const GLhalfNV *v] + glVertexAttrib1hNV: [void, GLuint index, GLhalfNV x] + glVertexAttrib1hvNV: [void, GLuint index, const GLhalfNV *v] + glVertexAttrib2hNV: [void, GLuint index, GLhalfNV x, GLhalfNV y] + glVertexAttrib2hvNV: [void, GLuint index, const GLhalfNV *v] + glVertexAttrib3hNV: [void, GLuint index, GLhalfNV x, GLhalfNV y, GLhalfNV z] + glVertexAttrib3hvNV: [void, GLuint index, const GLhalfNV *v] + glVertexAttrib4hNV: [void, GLuint index, GLhalfNV x, GLhalfNV y, GLhalfNV z, GLhalfNV + w] + glVertexAttrib4hvNV: [void, GLuint index, const GLhalfNV *v] + glVertexAttribs1hvNV: [void, GLuint index, GLsizei n, const GLhalfNV *v] + glVertexAttribs2hvNV: [void, GLuint index, GLsizei n, const GLhalfNV *v] + glVertexAttribs3hvNV: [void, GLuint index, GLsizei n, const GLhalfNV *v] + glVertexAttribs4hvNV: [void, GLuint index, GLsizei n, const GLhalfNV *v] + glVertexWeighthNV: [void, GLhalfNV weight] + glVertexWeighthvNV: [void, const GLhalfNV *weight] +NV_occlusion_query: + glBeginOcclusionQueryNV: [void, GLuint id] + glDeleteOcclusionQueriesNV: [void, GLsizei n, const GLuint *ids] + glEndOcclusionQueryNV: [void] + glGenOcclusionQueriesNV: [void, GLsizei n, GLuint *ids] + glGetOcclusionQueryivNV: [void, GLuint id, GLenum pname, GLint *params] + glGetOcclusionQueryuivNV: [void, GLuint id, GLenum pname, GLuint *params] + glIsOcclusionQueryNV: [GLboolean, GLuint id] +NV_parameter_buffer_object: + glProgramBufferParametersIivNV: [void, GLenum target, GLuint bindingIndex, GLuint + wordIndex, GLsizei count, const GLint *params] + glProgramBufferParametersIuivNV: [void, GLenum target, GLuint bindingIndex, GLuint + wordIndex, GLsizei count, const GLuint *params] + glProgramBufferParametersfvNV: [void, GLenum target, GLuint bindingIndex, GLuint + wordIndex, GLsizei count, const GLfloat *params] +NV_path_rendering: + glCopyPathNV: [void, GLuint resultPath, GLuint srcPath] + glCoverFillPathInstancedNV: [void, GLsizei numPaths, GLenum pathNameType, const + GLvoid *paths, GLuint pathBase, GLenum coverMode, GLenum transformType, const + GLfloat *transformValues] + glCoverFillPathNV: [void, GLuint path, GLenum coverMode] + glCoverStrokePathInstancedNV: [void, GLsizei numPaths, GLenum pathNameType, const + GLvoid *paths, GLuint pathBase, GLenum coverMode, GLenum transformType, const + GLfloat *transformValues] + glCoverStrokePathNV: [void, GLuint path, GLenum coverMode] + glDeletePathsNV: [void, GLuint path, GLsizei range] + glGenPathsNV: [GLuint, GLsizei range] + glGetPathColorGenfvNV: [void, GLenum color, GLenum pname, GLfloat *value] + glGetPathColorGenivNV: [void, GLenum color, GLenum pname, GLint *value] + glGetPathCommandsNV: [void, GLuint path, GLubyte *commands] + glGetPathCoordsNV: [void, GLuint path, GLfloat *coords] + glGetPathDashArrayNV: [void, GLuint path, GLfloat *dashArray] + glGetPathLengthNV: [GLfloat, GLuint path, GLsizei startSegment, GLsizei numSegments] + glGetPathMetricRangeNV: [void, GLbitfield metricQueryMask, GLuint firstPathName, + GLsizei numPaths, GLsizei stride, GLfloat *metrics] + glGetPathMetricsNV: [void, GLbitfield metricQueryMask, GLsizei numPaths, GLenum + pathNameType, const GLvoid *paths, GLuint pathBase, GLsizei stride, GLfloat + *metrics] + glGetPathParameterfvNV: [void, GLuint path, GLenum pname, GLfloat *value] + glGetPathParameterivNV: [void, GLuint path, GLenum pname, GLint *value] + glGetPathSpacingNV: [void, GLenum pathListMode, GLsizei numPaths, GLenum pathNameType, + const GLvoid *paths, GLuint pathBase, GLfloat advanceScale, GLfloat kerningScale, + GLenum transformType, GLfloat *returnedSpacing] + glGetPathTexGenfvNV: [void, GLenum texCoordSet, GLenum pname, GLfloat *value] + glGetPathTexGenivNV: [void, GLenum texCoordSet, GLenum pname, GLint *value] + glInterpolatePathsNV: [void, GLuint resultPath, GLuint pathA, GLuint pathB, GLfloat + weight] + glIsPathNV: [GLboolean, GLuint path] + glIsPointInFillPathNV: [GLboolean, GLuint path, GLuint mask, GLfloat x, GLfloat + y] + glIsPointInStrokePathNV: [GLboolean, GLuint path, GLfloat x, GLfloat y] + glPathColorGenNV: [void, GLenum color, GLenum genMode, GLenum colorFormat, const + GLfloat *coeffs] + glPathCommandsNV: [void, GLuint path, GLsizei numCommands, const GLubyte *commands, + GLsizei numCoords, GLenum coordType, const GLvoid *coords] + glPathCoordsNV: [void, GLuint path, GLsizei numCoords, GLenum coordType, const GLvoid + *coords] + glPathCoverDepthFuncNV: [void, GLenum func] + glPathDashArrayNV: [void, GLuint path, GLsizei dashCount, const GLfloat *dashArray] + glPathFogGenNV: [void, GLenum genMode] + glPathGlyphRangeNV: [void, GLuint firstPathName, GLenum fontTarget, const GLvoid + *fontName, GLbitfield fontStyle, GLuint firstGlyph, GLsizei numGlyphs, GLenum + handleMissingGlyphs, GLuint pathParameterTemplate, GLfloat emScale] + glPathGlyphsNV: [void, GLuint firstPathName, GLenum fontTarget, const GLvoid *fontName, + GLbitfield fontStyle, GLsizei numGlyphs, GLenum type, const GLvoid *charcodes, + GLenum handleMissingGlyphs, GLuint pathParameterTemplate, GLfloat emScale] + glPathParameterfNV: [void, GLuint path, GLenum pname, GLfloat value] + glPathParameterfvNV: [void, GLuint path, GLenum pname, const GLfloat *value] + glPathParameteriNV: [void, GLuint path, GLenum pname, GLint value] + glPathParameterivNV: [void, GLuint path, GLenum pname, const GLint *value] + glPathStencilDepthOffsetNV: [void, GLfloat factor, GLfloat units] + glPathStencilFuncNV: [void, GLenum func, GLint ref, GLuint mask] + glPathStringNV: [void, GLuint path, GLenum format, GLsizei length, const GLvoid + *pathString] + glPathSubCommandsNV: [void, GLuint path, GLsizei commandStart, GLsizei commandsToDelete, + GLsizei numCommands, const GLubyte *commands, GLsizei numCoords, GLenum coordType, + const GLvoid *coords] + glPathSubCoordsNV: [void, GLuint path, GLsizei coordStart, GLsizei numCoords, GLenum + coordType, const GLvoid *coords] + glPathTexGenNV: [void, GLenum texCoordSet, GLenum genMode, GLint components, const + GLfloat *coeffs] + glPointAlongPathNV: [GLboolean, GLuint path, GLsizei startSegment, GLsizei numSegments, + GLfloat distance, GLfloat *x, GLfloat *y, GLfloat *tangentX, GLfloat *tangentY] + glStencilFillPathInstancedNV: [void, GLsizei numPaths, GLenum pathNameType, const + GLvoid *paths, GLuint pathBase, GLenum fillMode, GLuint mask, GLenum transformType, + const GLfloat *transformValues] + glStencilFillPathNV: [void, GLuint path, GLenum fillMode, GLuint mask] + glStencilStrokePathInstancedNV: [void, GLsizei numPaths, GLenum pathNameType, const + GLvoid *paths, GLuint pathBase, GLint reference, GLuint mask, GLenum transformType, + const GLfloat *transformValues] + glStencilStrokePathNV: [void, GLuint path, GLint reference, GLuint mask] + glTransformPathNV: [void, GLuint resultPath, GLuint srcPath, GLenum transformType, + const GLfloat *transformValues] + glWeightPathsNV: [void, GLuint resultPath, GLsizei numPaths, const GLuint *paths, + const GLfloat *weights] +NV_pixel_data_range: + glFlushPixelDataRangeNV: [void, GLenum target] + glPixelDataRangeNV: [void, GLenum target, GLsizei length, const GLvoid *pointer] +NV_point_sprite: + glPointParameteriNV: [void, GLenum pname, GLint param] + glPointParameterivNV: [void, GLenum pname, const GLint *params] +NV_present_video: + glGetVideoi64vNV: [void, GLuint video_slot, GLenum pname, GLint64EXT *params] + glGetVideoivNV: [void, GLuint video_slot, GLenum pname, GLint *params] + glGetVideoui64vNV: [void, GLuint video_slot, GLenum pname, GLuint64EXT *params] + glGetVideouivNV: [void, GLuint video_slot, GLenum pname, GLuint *params] + glPresentFrameDualFillNV: [void, GLuint video_slot, GLuint64EXT minPresentTime, + GLuint beginPresentTimeId, GLuint presentDurationId, GLenum type, GLenum target0, + GLuint fill0, GLenum target1, GLuint fill1, GLenum target2, GLuint fill2, GLenum + target3, GLuint fill3] + glPresentFrameKeyedNV: [void, GLuint video_slot, GLuint64EXT minPresentTime, GLuint + beginPresentTimeId, GLuint presentDurationId, GLenum type, GLenum target0, GLuint + fill0, GLuint key0, GLenum target1, GLuint fill1, GLuint key1] +NV_primitive_restart: + glPrimitiveRestartIndexNV: [void, GLuint index] + glPrimitiveRestartNV: [void] +NV_register_combiners: + glCombinerInputNV: [void, GLenum stage, GLenum portion, GLenum variable, GLenum + input, GLenum mapping, GLenum componentUsage] + glCombinerOutputNV: [void, GLenum stage, GLenum portion, GLenum abOutput, GLenum + cdOutput, GLenum sumOutput, GLenum scale, GLenum bias, GLboolean abDotProduct, + GLboolean cdDotProduct, GLboolean muxSum] + glCombinerParameterfNV: [void, GLenum pname, GLfloat param] + glCombinerParameterfvNV: [void, GLenum pname, const GLfloat *params] + glCombinerParameteriNV: [void, GLenum pname, GLint param] + glCombinerParameterivNV: [void, GLenum pname, const GLint *params] + glFinalCombinerInputNV: [void, GLenum variable, GLenum input, GLenum mapping, GLenum + componentUsage] + glGetCombinerInputParameterfvNV: [void, GLenum stage, GLenum portion, GLenum variable, + GLenum pname, GLfloat *params] + glGetCombinerInputParameterivNV: [void, GLenum stage, GLenum portion, GLenum variable, + GLenum pname, GLint *params] + glGetCombinerOutputParameterfvNV: [void, GLenum stage, GLenum portion, GLenum pname, + GLfloat *params] + glGetCombinerOutputParameterivNV: [void, GLenum stage, GLenum portion, GLenum pname, + GLint *params] + glGetFinalCombinerInputParameterfvNV: [void, GLenum variable, GLenum pname, GLfloat + *params] + glGetFinalCombinerInputParameterivNV: [void, GLenum variable, GLenum pname, GLint + *params] +NV_register_combiners2: + glCombinerStageParameterfvNV: [void, GLenum stage, GLenum pname, const GLfloat *params] + glGetCombinerStageParameterfvNV: [void, GLenum stage, GLenum pname, GLfloat *params] +NV_shader_buffer_load: + glGetBufferParameterui64vNV: [void, GLenum target, GLenum pname, GLuint64EXT *params] + glGetIntegerui64vNV: [void, GLenum value, GLuint64EXT *result] + glGetNamedBufferParameterui64vNV: [void, GLuint buffer, GLenum pname, GLuint64EXT + *params] + glGetUniformui64vNV: [void, GLuint program, GLint location, GLuint64EXT *params] + glIsBufferResidentNV: [GLboolean, GLenum target] + glIsNamedBufferResidentNV: [GLboolean, GLuint buffer] + glMakeBufferNonResidentNV: [void, GLenum target] + glMakeBufferResidentNV: [void, GLenum target, GLenum access] + glMakeNamedBufferNonResidentNV: [void, GLuint buffer] + glMakeNamedBufferResidentNV: [void, GLuint buffer, GLenum access] + glProgramUniformui64NV: [void, GLuint program, GLint location, GLuint64EXT value] + glProgramUniformui64vNV: [void, GLuint program, GLint location, GLsizei count, const + GLuint64EXT *value] + glUniformui64NV: [void, GLint location, GLuint64EXT value] + glUniformui64vNV: [void, GLint location, GLsizei count, const GLuint64EXT *value] +NV_texture_barrier: + glTextureBarrierNV: [void] +NV_texture_multisample: + glTexImage2DMultisampleCoverageNV: [void, GLenum target, GLsizei coverageSamples, + GLsizei colorSamples, GLint internalFormat, GLsizei width, GLsizei height, GLboolean + fixedSampleLocations] + glTexImage3DMultisampleCoverageNV: [void, GLenum target, GLsizei coverageSamples, + GLsizei colorSamples, GLint internalFormat, GLsizei width, GLsizei height, GLsizei + depth, GLboolean fixedSampleLocations] + glTextureImage2DMultisampleCoverageNV: [void, GLuint texture, GLenum target, GLsizei + coverageSamples, GLsizei colorSamples, GLint internalFormat, GLsizei width, + GLsizei height, GLboolean fixedSampleLocations] + glTextureImage2DMultisampleNV: [void, GLuint texture, GLenum target, GLsizei samples, + GLint internalFormat, GLsizei width, GLsizei height, GLboolean fixedSampleLocations] + glTextureImage3DMultisampleCoverageNV: [void, GLuint texture, GLenum target, GLsizei + coverageSamples, GLsizei colorSamples, GLint internalFormat, GLsizei width, + GLsizei height, GLsizei depth, GLboolean fixedSampleLocations] + glTextureImage3DMultisampleNV: [void, GLuint texture, GLenum target, GLsizei samples, + GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLboolean + fixedSampleLocations] +NV_transform_feedback: + glActiveVaryingNV: [void, GLuint program, const GLchar *name] + glBeginTransformFeedbackNV: [void, GLenum primitiveMode] + glBindBufferBaseNV: [void, GLenum target, GLuint index, GLuint buffer] + glBindBufferOffsetNV: [void, GLenum target, GLuint index, GLuint buffer, GLintptr + offset] + glBindBufferRangeNV: [void, GLenum target, GLuint index, GLuint buffer, GLintptr + offset, GLsizeiptr size] + glEndTransformFeedbackNV: [void] + glGetActiveVaryingNV: [void, GLuint program, GLuint index, GLsizei bufSize, GLsizei + *length, GLsizei *size, GLenum *type, GLchar *name] + glGetTransformFeedbackVaryingNV: [void, GLuint program, GLuint index, GLint *location] + glGetVaryingLocationNV: [GLint, GLuint program, const GLchar *name] + glTransformFeedbackAttribsNV: [void, GLsizei count, const GLint *attribs, GLenum + bufferMode] + glTransformFeedbackStreamAttribsNV: [void, GLsizei count, const GLint *attribs, + GLsizei nbuffers, const GLint *bufstreams, GLenum bufferMode] + glTransformFeedbackVaryingsNV: [void, GLuint program, GLsizei count, const GLint + *locations, GLenum bufferMode] +NV_transform_feedback2: + glBindTransformFeedbackNV: [void, GLenum target, GLuint id] + glDeleteTransformFeedbacksNV: [void, GLsizei n, const GLuint *ids] + glDrawTransformFeedbackNV: [void, GLenum mode, GLuint id] + glGenTransformFeedbacksNV: [void, GLsizei n, GLuint *ids] + glIsTransformFeedbackNV: [GLboolean, GLuint id] + glPauseTransformFeedbackNV: [void] + glResumeTransformFeedbackNV: [void] +NV_vdpau_interop: + glVDPAUFiniNV: [void] + glVDPAUGetSurfaceivNV: [void, GLvdpauSurfaceNV surface, GLenum pname, GLsizei bufSize, + GLsizei *length, GLint *values] + glVDPAUInitNV: [void, const GLvoid *vdpDevice, const GLvoid *getProcAddress] + glVDPAUIsSurfaceNV: [void, GLvdpauSurfaceNV surface] + glVDPAUMapSurfacesNV: [void, GLsizei numSurfaces, const GLvdpauSurfaceNV *surfaces] + glVDPAURegisterOutputSurfaceNV: [GLvdpauSurfaceNV, GLvoid *vdpSurface, GLenum target, + GLsizei numTextureNames, const GLuint *textureNames] + glVDPAURegisterVideoSurfaceNV: [GLvdpauSurfaceNV, const GLvoid *vdpSurface, GLenum + target, GLsizei numTextureNames, const GLuint *textureNames] + glVDPAUSurfaceAccessNV: [void, GLvdpauSurfaceNV surface, GLenum access] + glVDPAUUnmapSurfacesNV: [void, GLsizei numSurface, const GLvdpauSurfaceNV *surfaces] + glVDPAUUnregisterSurfaceNV: [void, GLvdpauSurfaceNV surface] +NV_vertex_array_range: + glFlushVertexArrayRangeNV: [void] + glVertexArrayRangeNV: [void, GLsizei length, const GLvoid *pointer] +NV_vertex_attrib_integer_64bit: + glGetVertexAttribLi64vNV: [void, GLuint index, GLenum pname, GLint64EXT *params] + glGetVertexAttribLui64vNV: [void, GLuint index, GLenum pname, GLuint64EXT *params] + glVertexAttribL1i64NV: [void, GLuint index, GLint64EXT x] + glVertexAttribL1i64vNV: [void, GLuint index, const GLint64EXT *v] + glVertexAttribL1ui64NV: [void, GLuint index, GLuint64EXT x] + glVertexAttribL1ui64vNV: [void, GLuint index, const GLuint64EXT *v] + glVertexAttribL2i64NV: [void, GLuint index, GLint64EXT x, GLint64EXT y] + glVertexAttribL2i64vNV: [void, GLuint index, const GLint64EXT *v] + glVertexAttribL2ui64NV: [void, GLuint index, GLuint64EXT x, GLuint64EXT y] + glVertexAttribL2ui64vNV: [void, GLuint index, const GLuint64EXT *v] + glVertexAttribL3i64NV: [void, GLuint index, GLint64EXT x, GLint64EXT y, GLint64EXT + z] + glVertexAttribL3i64vNV: [void, GLuint index, const GLint64EXT *v] + glVertexAttribL3ui64NV: [void, GLuint index, GLuint64EXT x, GLuint64EXT y, GLuint64EXT + z] + glVertexAttribL3ui64vNV: [void, GLuint index, const GLuint64EXT *v] + glVertexAttribL4i64NV: [void, GLuint index, GLint64EXT x, GLint64EXT y, GLint64EXT + z, GLint64EXT w] + glVertexAttribL4i64vNV: [void, GLuint index, const GLint64EXT *v] + glVertexAttribL4ui64NV: [void, GLuint index, GLuint64EXT x, GLuint64EXT y, GLuint64EXT + z, GLuint64EXT w] + glVertexAttribL4ui64vNV: [void, GLuint index, const GLuint64EXT *v] + glVertexAttribLFormatNV: [void, GLuint index, GLint size, GLenum type, GLsizei stride] +NV_vertex_buffer_unified_memory: + glBufferAddressRangeNV: [void, GLenum pname, GLuint index, GLuint64EXT address, + GLsizeiptr length] + glColorFormatNV: [void, GLint size, GLenum type, GLsizei stride] + glEdgeFlagFormatNV: [void, GLsizei stride] + glFogCoordFormatNV: [void, GLenum type, GLsizei stride] + glGetIntegerui64i_vNV: [void, GLenum value, GLuint index, GLuint64EXT *result] + glIndexFormatNV: [void, GLenum type, GLsizei stride] + glNormalFormatNV: [void, GLenum type, GLsizei stride] + glSecondaryColorFormatNV: [void, GLint size, GLenum type, GLsizei stride] + glTexCoordFormatNV: [void, GLint size, GLenum type, GLsizei stride] + glVertexAttribFormatNV: [void, GLuint index, GLint size, GLenum type, GLboolean + normalized, GLsizei stride] + glVertexAttribIFormatNV: [void, GLuint index, GLint size, GLenum type, GLsizei stride] + glVertexFormatNV: [void, GLint size, GLenum type, GLsizei stride] +NV_vertex_program: + glAreProgramsResidentNV: [GLboolean, GLsizei n, const GLuint *programs, GLboolean + *residences] + glBindProgramNV: [void, GLenum target, GLuint id] + glDeleteProgramsNV: [void, GLsizei n, const GLuint *programs] + glExecuteProgramNV: [void, GLenum target, GLuint id, const GLfloat *params] + glGenProgramsNV: [void, GLsizei n, GLuint *programs] + glGetProgramParameterdvNV: [void, GLenum target, GLuint index, GLenum pname, GLdouble + *params] + glGetProgramParameterfvNV: [void, GLenum target, GLuint index, GLenum pname, GLfloat + *params] + glGetProgramStringNV: [void, GLuint id, GLenum pname, GLubyte *program] + glGetProgramivNV: [void, GLuint id, GLenum pname, GLint *params] + glGetTrackMatrixivNV: [void, GLenum target, GLuint address, GLenum pname, GLint + *params] + glGetVertexAttribPointervNV: [void, GLuint index, GLenum pname, GLvoid *pointer] + glGetVertexAttribdvNV: [void, GLuint index, GLenum pname, GLdouble *params] + glGetVertexAttribfvNV: [void, GLuint index, GLenum pname, GLfloat *params] + glGetVertexAttribivNV: [void, GLuint index, GLenum pname, GLint *params] + glIsProgramNV: [GLboolean, GLuint id] + glLoadProgramNV: [void, GLenum target, GLuint id, GLsizei len, const GLubyte *program] + glProgramParameter4dNV: [void, GLenum target, GLuint index, GLdouble x, GLdouble + y, GLdouble z, GLdouble w] + glProgramParameter4dvNV: [void, GLenum target, GLuint index, const GLdouble *v] + glProgramParameter4fNV: [void, GLenum target, GLuint index, GLfloat x, GLfloat y, + GLfloat z, GLfloat w] + glProgramParameter4fvNV: [void, GLenum target, GLuint index, const GLfloat *v] + glProgramParameters4dvNV: [void, GLenum target, GLuint index, GLsizei count, const + GLdouble *v] + glProgramParameters4fvNV: [void, GLenum target, GLuint index, GLsizei count, const + GLfloat *v] + glRequestResidentProgramsNV: [void, GLsizei n, const GLuint *programs] + glTrackMatrixNV: [void, GLenum target, GLuint address, GLenum matrix, GLenum transform] + glVertexAttrib1dNV: [void, GLuint index, GLdouble x] + glVertexAttrib1dvNV: [void, GLuint index, const GLdouble *v] + glVertexAttrib1fNV: [void, GLuint index, GLfloat x] + glVertexAttrib1fvNV: [void, GLuint index, const GLfloat *v] + glVertexAttrib1sNV: [void, GLuint index, GLshort x] + glVertexAttrib1svNV: [void, GLuint index, const GLshort *v] + glVertexAttrib2dNV: [void, GLuint index, GLdouble x, GLdouble y] + glVertexAttrib2dvNV: [void, GLuint index, const GLdouble *v] + glVertexAttrib2fNV: [void, GLuint index, GLfloat x, GLfloat y] + glVertexAttrib2fvNV: [void, GLuint index, const GLfloat *v] + glVertexAttrib2sNV: [void, GLuint index, GLshort x, GLshort y] + glVertexAttrib2svNV: [void, GLuint index, const GLshort *v] + glVertexAttrib3dNV: [void, GLuint index, GLdouble x, GLdouble y, GLdouble z] + glVertexAttrib3dvNV: [void, GLuint index, const GLdouble *v] + glVertexAttrib3fNV: [void, GLuint index, GLfloat x, GLfloat y, GLfloat z] + glVertexAttrib3fvNV: [void, GLuint index, const GLfloat *v] + glVertexAttrib3sNV: [void, GLuint index, GLshort x, GLshort y, GLshort z] + glVertexAttrib3svNV: [void, GLuint index, const GLshort *v] + glVertexAttrib4dNV: [void, GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble + w] + glVertexAttrib4dvNV: [void, GLuint index, const GLdouble *v] + glVertexAttrib4fNV: [void, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat + w] + glVertexAttrib4fvNV: [void, GLuint index, const GLfloat *v] + glVertexAttrib4sNV: [void, GLuint index, GLshort x, GLshort y, GLshort z, GLshort + w] + glVertexAttrib4svNV: [void, GLuint index, const GLshort *v] + glVertexAttrib4ubNV: [void, GLuint index, GLubyte x, GLubyte y, GLubyte z, GLubyte + w] + glVertexAttrib4ubvNV: [void, GLuint index, const GLubyte *v] + glVertexAttribPointerNV: [void, GLuint index, GLint fsize, GLenum type, GLsizei + stride, const GLvoid *pointer] + glVertexAttribs1dvNV: [void, GLuint index, GLsizei count, const GLdouble *v] + glVertexAttribs1fvNV: [void, GLuint index, GLsizei count, const GLfloat *v] + glVertexAttribs1svNV: [void, GLuint index, GLsizei count, const GLshort *v] + glVertexAttribs2dvNV: [void, GLuint index, GLsizei count, const GLdouble *v] + glVertexAttribs2fvNV: [void, GLuint index, GLsizei count, const GLfloat *v] + glVertexAttribs2svNV: [void, GLuint index, GLsizei count, const GLshort *v] + glVertexAttribs3dvNV: [void, GLuint index, GLsizei count, const GLdouble *v] + glVertexAttribs3fvNV: [void, GLuint index, GLsizei count, const GLfloat *v] + glVertexAttribs3svNV: [void, GLuint index, GLsizei count, const GLshort *v] + glVertexAttribs4dvNV: [void, GLuint index, GLsizei count, const GLdouble *v] + glVertexAttribs4fvNV: [void, GLuint index, GLsizei count, const GLfloat *v] + glVertexAttribs4svNV: [void, GLuint index, GLsizei count, const GLshort *v] + glVertexAttribs4ubvNV: [void, GLuint index, GLsizei count, const GLubyte *v] +NV_vertex_program4: + glGetVertexAttribIivEXT: [void, GLuint index, GLenum pname, GLint *params] + glGetVertexAttribIuivEXT: [void, GLuint index, GLenum pname, GLuint *params] + glVertexAttribI1iEXT: [void, GLuint index, GLint x] + glVertexAttribI1ivEXT: [void, GLuint index, const GLint *v] + glVertexAttribI1uiEXT: [void, GLuint index, GLuint x] + glVertexAttribI1uivEXT: [void, GLuint index, const GLuint *v] + glVertexAttribI2iEXT: [void, GLuint index, GLint x, GLint y] + glVertexAttribI2ivEXT: [void, GLuint index, const GLint *v] + glVertexAttribI2uiEXT: [void, GLuint index, GLuint x, GLuint y] + glVertexAttribI2uivEXT: [void, GLuint index, const GLuint *v] + glVertexAttribI3iEXT: [void, GLuint index, GLint x, GLint y, GLint z] + glVertexAttribI3ivEXT: [void, GLuint index, const GLint *v] + glVertexAttribI3uiEXT: [void, GLuint index, GLuint x, GLuint y, GLuint z] + glVertexAttribI3uivEXT: [void, GLuint index, const GLuint *v] + glVertexAttribI4bvEXT: [void, GLuint index, const GLbyte *v] + glVertexAttribI4iEXT: [void, GLuint index, GLint x, GLint y, GLint z, GLint w] + glVertexAttribI4ivEXT: [void, GLuint index, const GLint *v] + glVertexAttribI4svEXT: [void, GLuint index, const GLshort *v] + glVertexAttribI4ubvEXT: [void, GLuint index, const GLubyte *v] + glVertexAttribI4uiEXT: [void, GLuint index, GLuint x, GLuint y, GLuint z, GLuint + w] + glVertexAttribI4uivEXT: [void, GLuint index, const GLuint *v] + glVertexAttribI4usvEXT: [void, GLuint index, const GLushort *v] + glVertexAttribIPointerEXT: [void, GLuint index, GLint size, GLenum type, GLsizei + stride, const GLvoid *pointer] +NV_video_capture: + glBeginVideoCaptureNV: [void, GLuint video_capture_slot] + glBindVideoCaptureStreamBufferNV: [void, GLuint video_capture_slot, GLuint stream, + GLenum frame_region, GLintptrARB offset] + glBindVideoCaptureStreamTextureNV: [void, GLuint video_capture_slot, GLuint stream, + GLenum frame_region, GLenum target, GLuint texture] + glEndVideoCaptureNV: [void, GLuint video_capture_slot] + glGetVideoCaptureStreamdvNV: [void, GLuint video_capture_slot, GLuint stream, GLenum + pname, GLdouble *params] + glGetVideoCaptureStreamfvNV: [void, GLuint video_capture_slot, GLuint stream, GLenum + pname, GLfloat *params] + glGetVideoCaptureStreamivNV: [void, GLuint video_capture_slot, GLuint stream, GLenum + pname, GLint *params] + glGetVideoCaptureivNV: [void, GLuint video_capture_slot, GLenum pname, GLint *params] + glVideoCaptureNV: [GLenum, GLuint video_capture_slot, GLuint *sequence_num, GLuint64EXT + *capture_time] + glVideoCaptureStreamParameterdvNV: [void, GLuint video_capture_slot, GLuint stream, + GLenum pname, const GLdouble *params] + glVideoCaptureStreamParameterfvNV: [void, GLuint video_capture_slot, GLuint stream, + GLenum pname, const GLfloat *params] + glVideoCaptureStreamParameterivNV: [void, GLuint video_capture_slot, GLuint stream, + GLenum pname, const GLint *params] +OES_byte_coordinates: + glMultiTexCoord1bOES: [void, GLenum texture, GLbyte s] + glMultiTexCoord1bvOES: [void, GLenum texture, const GLbyte *coords] + glMultiTexCoord2bOES: [void, GLenum texture, GLbyte s, GLbyte t] + glMultiTexCoord2bvOES: [void, GLenum texture, const GLbyte *coords] + glMultiTexCoord3bOES: [void, GLenum texture, GLbyte s, GLbyte t, GLbyte r] + glMultiTexCoord3bvOES: [void, GLenum texture, const GLbyte *coords] + glMultiTexCoord4bOES: [void, GLenum texture, GLbyte s, GLbyte t, GLbyte r, GLbyte + q] + glMultiTexCoord4bvOES: [void, GLenum texture, const GLbyte *coords] + glTexCoord1bOES: [void, GLbyte s] + glTexCoord1bvOES: [void, const GLbyte *coords] + glTexCoord2bOES: [void, GLbyte s, GLbyte t] + glTexCoord2bvOES: [void, const GLbyte *coords] + glTexCoord3bOES: [void, GLbyte s, GLbyte t, GLbyte r] + glTexCoord3bvOES: [void, const GLbyte *coords] + glTexCoord4bOES: [void, GLbyte s, GLbyte t, GLbyte r, GLbyte q] + glTexCoord4bvOES: [void, const GLbyte *coords] + glVertex2bOES: [void, GLbyte x] + glVertex2bvOES: [void, const GLbyte *coords] + glVertex3bOES: [void, GLbyte x, GLbyte y] + glVertex3bvOES: [void, const GLbyte *coords] + glVertex4bOES: [void, GLbyte x, GLbyte y, GLbyte z] + glVertex4bvOES: [void, const GLbyte *coords] +OES_fixed_point: + glAccumxOES: [void, GLenum op, GLfixed value] + glAlphaFuncxOES: [void, GLenum func, GLfixed ref] + glBitmapxOES: [void, GLsizei width, GLsizei height, GLfixed xorig, GLfixed yorig, + GLfixed xmove, GLfixed ymove, const GLubyte *bitmap] + glBlendColorxOES: [void, GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha] + glClearAccumxOES: [void, GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha] + glClearColorxOES: [void, GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha] + glClearDepthxOES: [void, GLfixed depth] + glClipPlanexOES: [void, GLenum plane, const GLfixed *equation] + glColor3xOES: [void, GLfixed red, GLfixed green, GLfixed blue] + glColor3xvOES: [void, const GLfixed *components] + glColor4xOES: [void, GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha] + glColor4xvOES: [void, const GLfixed *components] + glConvolutionParameterxOES: [void, GLenum target, GLenum pname, GLfixed param] + glConvolutionParameterxvOES: [void, GLenum target, GLenum pname, const GLfixed *params] + glDepthRangexOES: [void, GLfixed n, GLfixed f] + glEvalCoord1xOES: [void, GLfixed u] + glEvalCoord1xvOES: [void, const GLfixed *coords] + glEvalCoord2xOES: [void, GLfixed u, GLfixed v] + glEvalCoord2xvOES: [void, const GLfixed *coords] + glFeedbackBufferxOES: [void, GLsizei n, GLenum type, const GLfixed *buffer] + glFogxOES: [void, GLenum pname, GLfixed param] + glFogxvOES: [void, GLenum pname, const GLfixed *param] + glFrustumxOES: [void, GLfixed l, GLfixed r, GLfixed b, GLfixed t, GLfixed n, GLfixed + f] + glGetClipPlanexOES: [void, GLenum plane, GLfixed *equation] + glGetConvolutionParameterxvOES: [void, GLenum target, GLenum pname, GLfixed *params] + glGetFixedvOES: [void, GLenum pname, GLfixed *params] + glGetHistogramParameterxvOES: [void, GLenum target, GLenum pname, GLfixed *params] + glGetLightxOES: [void, GLenum light, GLenum pname, GLfixed *params] + glGetMapxvOES: [void, GLenum target, GLenum query, GLfixed *v] + glGetMaterialxOES: [void, GLenum face, GLenum pname, GLfixed param] + glGetPixelMapxv: [void, GLenum map, GLint size, GLfixed *values] + glGetTexEnvxvOES: [void, GLenum target, GLenum pname, GLfixed *params] + glGetTexGenxvOES: [void, GLenum coord, GLenum pname, GLfixed *params] + glGetTexLevelParameterxvOES: [void, GLenum target, GLint level, GLenum pname, GLfixed + *params] + glGetTexParameterxvOES: [void, GLenum target, GLenum pname, GLfixed *params] + glIndexxOES: [void, GLfixed component] + glIndexxvOES: [void, const GLfixed *component] + glLightModelxOES: [void, GLenum pname, GLfixed param] + glLightModelxvOES: [void, GLenum pname, const GLfixed *param] + glLightxOES: [void, GLenum light, GLenum pname, GLfixed param] + glLightxvOES: [void, GLenum light, GLenum pname, const GLfixed *params] + glLineWidthxOES: [void, GLfixed width] + glLoadMatrixxOES: [void, const GLfixed *m] + glLoadTransposeMatrixxOES: [void, const GLfixed *m] + glMap1xOES: [void, GLenum target, GLfixed u1, GLfixed u2, GLint stride, GLint order, + GLfixed points] + glMap2xOES: [void, GLenum target, GLfixed u1, GLfixed u2, GLint ustride, GLint uorder, + GLfixed v1, GLfixed v2, GLint vstride, GLint vorder, GLfixed points] + glMapGrid1xOES: [void, GLint n, GLfixed u1, GLfixed u2] + glMapGrid2xOES: [void, GLint n, GLfixed u1, GLfixed u2, GLfixed v1, GLfixed v2] + glMaterialxOES: [void, GLenum face, GLenum pname, GLfixed param] + glMaterialxvOES: [void, GLenum face, GLenum pname, const GLfixed *param] + glMultMatrixxOES: [void, const GLfixed *m] + glMultTransposeMatrixxOES: [void, const GLfixed *m] + glMultiTexCoord1xOES: [void, GLenum texture, GLfixed s] + glMultiTexCoord1xvOES: [void, GLenum texture, const GLfixed *coords] + glMultiTexCoord2xOES: [void, GLenum texture, GLfixed s, GLfixed t] + glMultiTexCoord2xvOES: [void, GLenum texture, const GLfixed *coords] + glMultiTexCoord3xOES: [void, GLenum texture, GLfixed s, GLfixed t, GLfixed r] + glMultiTexCoord3xvOES: [void, GLenum texture, const GLfixed *coords] + glMultiTexCoord4xOES: [void, GLenum texture, GLfixed s, GLfixed t, GLfixed r, GLfixed + q] + glMultiTexCoord4xvOES: [void, GLenum texture, const GLfixed *coords] + glNormal3xOES: [void, GLfixed nx, GLfixed ny, GLfixed nz] + glNormal3xvOES: [void, const GLfixed *coords] + glOrthoxOES: [void, GLfixed l, GLfixed r, GLfixed b, GLfixed t, GLfixed n, GLfixed + f] + glPassThroughxOES: [void, GLfixed token] + glPixelMapx: [void, GLenum map, GLint size, const GLfixed *values] + glPixelStorex: [void, GLenum pname, GLfixed param] + glPixelTransferxOES: [void, GLenum pname, GLfixed param] + glPixelZoomxOES: [void, GLfixed xfactor, GLfixed yfactor] + glPointParameterxvOES: [void, GLenum pname, const GLfixed *params] + glPointSizexOES: [void, GLfixed size] + glPolygonOffsetxOES: [void, GLfixed factor, GLfixed units] + glPrioritizeTexturesxOES: [void, GLsizei n, const GLuint *textures, const GLfixed + *priorities] + glRasterPos2xOES: [void, GLfixed x, GLfixed y] + glRasterPos2xvOES: [void, const GLfixed *coords] + glRasterPos3xOES: [void, GLfixed x, GLfixed y, GLfixed z] + glRasterPos3xvOES: [void, const GLfixed *coords] + glRasterPos4xOES: [void, GLfixed x, GLfixed y, GLfixed z, GLfixed w] + glRasterPos4xvOES: [void, const GLfixed *coords] + glRectxOES: [void, GLfixed x1, GLfixed y1, GLfixed x2, GLfixed y2] + glRectxvOES: [void, const GLfixed *v1, const GLfixed *v2] + glRotatexOES: [void, GLfixed angle, GLfixed x, GLfixed y, GLfixed z] + glSampleCoverageOES: [void, GLfixed value, GLboolean invert] + glScalexOES: [void, GLfixed x, GLfixed y, GLfixed z] + glTexCoord1xOES: [void, GLfixed s] + glTexCoord1xvOES: [void, const GLfixed *coords] + glTexCoord2xOES: [void, GLfixed s, GLfixed t] + glTexCoord2xvOES: [void, const GLfixed *coords] + glTexCoord3xOES: [void, GLfixed s, GLfixed t, GLfixed r] + glTexCoord3xvOES: [void, const GLfixed *coords] + glTexCoord4xOES: [void, GLfixed s, GLfixed t, GLfixed r, GLfixed q] + glTexCoord4xvOES: [void, const GLfixed *coords] + glTexEnvxOES: [void, GLenum target, GLenum pname, GLfixed param] + glTexEnvxvOES: [void, GLenum target, GLenum pname, const GLfixed *params] + glTexGenxOES: [void, GLenum coord, GLenum pname, GLfixed param] + glTexGenxvOES: [void, GLenum coord, GLenum pname, const GLfixed *params] + glTexParameterxOES: [void, GLenum target, GLenum pname, GLfixed param] + glTexParameterxvOES: [void, GLenum target, GLenum pname, const GLfixed *params] + glTranslatexOES: [void, GLfixed x, GLfixed y, GLfixed z] + glVertex2xOES: [void, GLfixed x] + glVertex2xvOES: [void, const GLfixed *coords] + glVertex3xOES: [void, GLfixed x, GLfixed y] + glVertex3xvOES: [void, const GLfixed *coords] + glVertex4xOES: [void, GLfixed x, GLfixed y, GLfixed z] + glVertex4xvOES: [void, const GLfixed *coords] +OES_query_matrix: + glQueryMatrixxOES: [GLbitfield, GLfixed *mantissa, GLint *exponent] +OES_single_precision: + glClearDepthfOES: [void, GLclampf depth] + glClipPlanefOES: [void, GLenum plane, const GLfloat *equation] + glDepthRangefOES: [void, GLclampf n, GLclampf f] + glFrustumfOES: [void, GLfloat l, GLfloat r, GLfloat b, GLfloat t, GLfloat n, GLfloat + f] + glGetClipPlanefOES: [void, GLenum plane, GLfloat *equation] + glOrthofOES: [void, GLfloat l, GLfloat r, GLfloat b, GLfloat t, GLfloat n, GLfloat + f] +PGI_misc_hints: + glHintPGI: [void, GLenum target, GLint mode] +SGIS_detail_texture: + glDetailTexFuncSGIS: [void, GLenum target, GLsizei n, const GLfloat *points] + glGetDetailTexFuncSGIS: [void, GLenum target, GLfloat *points] +SGIS_fog_function: + glFogFuncSGIS: [void, GLsizei n, const GLfloat *points] + glGetFogFuncSGIS: [void, GLfloat *points] +SGIS_multisample: + glSampleMaskSGIS: [void, GLclampf value, GLboolean invert] + glSamplePatternSGIS: [void, GLenum pattern] +SGIS_pixel_texture: + glGetPixelTexGenParameterfvSGIS: [void, GLenum pname, GLfloat *params] + glGetPixelTexGenParameterivSGIS: [void, GLenum pname, GLint *params] + glPixelTexGenParameterfSGIS: [void, GLenum pname, GLfloat param] + glPixelTexGenParameterfvSGIS: [void, GLenum pname, const GLfloat *params] + glPixelTexGenParameteriSGIS: [void, GLenum pname, GLint param] + glPixelTexGenParameterivSGIS: [void, GLenum pname, const GLint *params] +SGIS_point_parameters: + glPointParameterfSGIS: [void, GLenum pname, GLfloat param] + glPointParameterfvSGIS: [void, GLenum pname, const GLfloat *params] +SGIS_sharpen_texture: + glGetSharpenTexFuncSGIS: [void, GLenum target, GLfloat *points] + glSharpenTexFuncSGIS: [void, GLenum target, GLsizei n, const GLfloat *points] +SGIS_texture4D: + glTexImage4DSGIS: [void, GLenum target, GLint level, GLenum internalformat, GLsizei + width, GLsizei height, GLsizei depth, GLsizei size4d, GLint border, GLenum format, + GLenum type, const GLvoid *pixels] + glTexSubImage4DSGIS: [void, GLenum target, GLint level, GLint xoffset, GLint yoffset, + GLint zoffset, GLint woffset, GLsizei width, GLsizei height, GLsizei depth, GLsizei + size4d, GLenum format, GLenum type, const GLvoid *pixels] +SGIS_texture_color_mask: + glTextureColorMaskSGIS: [void, GLboolean red, GLboolean green, GLboolean blue, GLboolean + alpha] +SGIS_texture_filter4: + glGetTexFilterFuncSGIS: [void, GLenum target, GLenum filter, GLfloat *weights] + glTexFilterFuncSGIS: [void, GLenum target, GLenum filter, GLsizei n, const GLfloat + *weights] +SGIX_async: + glAsyncMarkerSGIX: [void, GLuint marker] + glDeleteAsyncMarkersSGIX: [void, GLuint marker, GLsizei range] + glFinishAsyncSGIX: [GLint, GLuint *markerp] + glGenAsyncMarkersSGIX: [GLuint, GLsizei range] + glIsAsyncMarkerSGIX: [GLboolean, GLuint marker] + glPollAsyncSGIX: [GLint, GLuint *markerp] +SGIX_flush_raster: + glFlushRasterSGIX: [void] +SGIX_fragment_lighting: + glFragmentColorMaterialSGIX: [void, GLenum face, GLenum mode] + glFragmentLightModelfSGIX: [void, GLenum pname, GLfloat param] + glFragmentLightModelfvSGIX: [void, GLenum pname, const GLfloat *params] + glFragmentLightModeliSGIX: [void, GLenum pname, GLint param] + glFragmentLightModelivSGIX: [void, GLenum pname, const GLint *params] + glFragmentLightfSGIX: [void, GLenum light, GLenum pname, GLfloat param] + glFragmentLightfvSGIX: [void, GLenum light, GLenum pname, const GLfloat *params] + glFragmentLightiSGIX: [void, GLenum light, GLenum pname, GLint param] + glFragmentLightivSGIX: [void, GLenum light, GLenum pname, const GLint *params] + glFragmentMaterialfSGIX: [void, GLenum face, GLenum pname, GLfloat param] + glFragmentMaterialfvSGIX: [void, GLenum face, GLenum pname, const GLfloat *params] + glFragmentMaterialiSGIX: [void, GLenum face, GLenum pname, GLint param] + glFragmentMaterialivSGIX: [void, GLenum face, GLenum pname, const GLint *params] + glGetFragmentLightfvSGIX: [void, GLenum light, GLenum pname, GLfloat *params] + glGetFragmentLightivSGIX: [void, GLenum light, GLenum pname, GLint *params] + glGetFragmentMaterialfvSGIX: [void, GLenum face, GLenum pname, GLfloat *params] + glGetFragmentMaterialivSGIX: [void, GLenum face, GLenum pname, GLint *params] + glLightEnviSGIX: [void, GLenum pname, GLint param] +SGIX_framezoom: + glFrameZoomSGIX: [void, GLint factor] +SGIX_igloo_interface: + glIglooInterfaceSGIX: [void, GLenum pname, const GLvoid *params] +SGIX_instruments: + glGetInstrumentsSGIX: [GLint] + glInstrumentsBufferSGIX: [void, GLsizei size, GLint *buffer] + glPollInstrumentsSGIX: [GLint, GLint *marker_p] + glReadInstrumentsSGIX: [void, GLint marker] + glStartInstrumentsSGIX: [void] + glStopInstrumentsSGIX: [void, GLint marker] +SGIX_list_priority: + glGetListParameterfvSGIX: [void, GLuint list, GLenum pname, GLfloat *params] + glGetListParameterivSGIX: [void, GLuint list, GLenum pname, GLint *params] + glListParameterfSGIX: [void, GLuint list, GLenum pname, GLfloat param] + glListParameterfvSGIX: [void, GLuint list, GLenum pname, const GLfloat *params] + glListParameteriSGIX: [void, GLuint list, GLenum pname, GLint param] + glListParameterivSGIX: [void, GLuint list, GLenum pname, const GLint *params] +SGIX_pixel_texture: + glPixelTexGenSGIX: [void, GLenum mode] +SGIX_polynomial_ffd: + glDeformSGIX: [void, GLbitfield mask] + glDeformationMap3dSGIX: [void, GLenum target, GLdouble u1, GLdouble u2, GLint ustride, + GLint uorder, GLdouble v1, GLdouble v2, GLint vstride, GLint vorder, GLdouble + w1, GLdouble w2, GLint wstride, GLint worder, const GLdouble *points] + glDeformationMap3fSGIX: [void, GLenum target, GLfloat u1, GLfloat u2, GLint ustride, + GLint uorder, GLfloat v1, GLfloat v2, GLint vstride, GLint vorder, GLfloat w1, + GLfloat w2, GLint wstride, GLint worder, const GLfloat *points] + glLoadIdentityDeformationMapSGIX: [void, GLbitfield mask] +SGIX_reference_plane: + glReferencePlaneSGIX: [void, const GLdouble *equation] +SGIX_sprite: + glSpriteParameterfSGIX: [void, GLenum pname, GLfloat param] + glSpriteParameterfvSGIX: [void, GLenum pname, const GLfloat *params] + glSpriteParameteriSGIX: [void, GLenum pname, GLint param] + glSpriteParameterivSGIX: [void, GLenum pname, const GLint *params] +SGIX_tag_sample_buffer: + glTagSampleBufferSGIX: [void] +SGI_color_table: + glColorTableParameterfvSGI: [void, GLenum target, GLenum pname, const GLfloat *params] + glColorTableParameterivSGI: [void, GLenum target, GLenum pname, const GLint *params] + glColorTableSGI: [void, GLenum target, GLenum internalformat, GLsizei width, GLenum + format, GLenum type, const GLvoid *table] + glCopyColorTableSGI: [void, GLenum target, GLenum internalformat, GLint x, GLint + y, GLsizei width] + glGetColorTableParameterfvSGI: [void, GLenum target, GLenum pname, GLfloat *params] + glGetColorTableParameterivSGI: [void, GLenum target, GLenum pname, GLint *params] + glGetColorTableSGI: [void, GLenum target, GLenum format, GLenum type, GLvoid *table] +SUNX_constant_data: + glFinishTextureSUNX: [void] +SUN_global_alpha: + glGlobalAlphaFactorbSUN: [void, GLbyte factor] + glGlobalAlphaFactordSUN: [void, GLdouble factor] + glGlobalAlphaFactorfSUN: [void, GLfloat factor] + glGlobalAlphaFactoriSUN: [void, GLint factor] + glGlobalAlphaFactorsSUN: [void, GLshort factor] + glGlobalAlphaFactorubSUN: [void, GLubyte factor] + glGlobalAlphaFactoruiSUN: [void, GLuint factor] + glGlobalAlphaFactorusSUN: [void, GLushort factor] +SUN_mesh_array: + glDrawMeshArraysSUN: [void, GLenum mode, GLint first, GLsizei count, GLsizei width] +SUN_triangle_list: + glReplacementCodePointerSUN: [void, GLenum type, GLsizei stride, const GLvoid *pointer] + glReplacementCodeubSUN: [void, GLubyte code] + glReplacementCodeubvSUN: [void, const GLubyte *code] + glReplacementCodeuiSUN: [void, GLuint code] + glReplacementCodeuivSUN: [void, const GLuint *code] + glReplacementCodeusSUN: [void, GLushort code] + glReplacementCodeusvSUN: [void, const GLushort *code] +SUN_vertex: + glColor3fVertex3fSUN: [void, GLfloat r, GLfloat g, GLfloat b, GLfloat x, GLfloat + y, GLfloat z] + glColor3fVertex3fvSUN: [void, const GLfloat *c, const GLfloat *v] + glColor4fNormal3fVertex3fSUN: [void, GLfloat r, GLfloat g, GLfloat b, GLfloat a, + GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z] + glColor4fNormal3fVertex3fvSUN: [void, const GLfloat *c, const GLfloat *n, const + GLfloat *v] + glColor4ubVertex2fSUN: [void, GLubyte r, GLubyte g, GLubyte b, GLubyte a, GLfloat + x, GLfloat y] + glColor4ubVertex2fvSUN: [void, const GLubyte *c, const GLfloat *v] + glColor4ubVertex3fSUN: [void, GLubyte r, GLubyte g, GLubyte b, GLubyte a, GLfloat + x, GLfloat y, GLfloat z] + glColor4ubVertex3fvSUN: [void, const GLubyte *c, const GLfloat *v] + glNormal3fVertex3fSUN: [void, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat + y, GLfloat z] + glNormal3fVertex3fvSUN: [void, const GLfloat *n, const GLfloat *v] + glReplacementCodeuiColor3fVertex3fSUN: [void, GLuint rc, GLfloat r, GLfloat g, GLfloat + b, GLfloat x, GLfloat y, GLfloat z] + glReplacementCodeuiColor3fVertex3fvSUN: [void, const GLuint *rc, const GLfloat *c, + const GLfloat *v] + glReplacementCodeuiColor4fNormal3fVertex3fSUN: [void, GLuint rc, GLfloat r, GLfloat + g, GLfloat b, GLfloat a, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat + y, GLfloat z] + glReplacementCodeuiColor4fNormal3fVertex3fvSUN: [void, const GLuint *rc, const GLfloat + *c, const GLfloat *n, const GLfloat *v] + glReplacementCodeuiColor4ubVertex3fSUN: [void, GLuint rc, GLubyte r, GLubyte g, + GLubyte b, GLubyte a, GLfloat x, GLfloat y, GLfloat z] + glReplacementCodeuiColor4ubVertex3fvSUN: [void, const GLuint *rc, const GLubyte + *c, const GLfloat *v] + glReplacementCodeuiNormal3fVertex3fSUN: [void, GLuint rc, GLfloat nx, GLfloat ny, + GLfloat nz, GLfloat x, GLfloat y, GLfloat z] + glReplacementCodeuiNormal3fVertex3fvSUN: [void, const GLuint *rc, const GLfloat + *n, const GLfloat *v] + glReplacementCodeuiTexCoord2fColor4fNormal3fVertex3fSUN: [void, GLuint rc, GLfloat + s, GLfloat t, GLfloat r, GLfloat g, GLfloat b, GLfloat a, GLfloat nx, GLfloat + ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z] + glReplacementCodeuiTexCoord2fColor4fNormal3fVertex3fvSUN: [void, const GLuint *rc, + const GLfloat *tc, const GLfloat *c, const GLfloat *n, const GLfloat *v] + glReplacementCodeuiTexCoord2fNormal3fVertex3fSUN: [void, GLuint rc, GLfloat s, GLfloat + t, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z] + glReplacementCodeuiTexCoord2fNormal3fVertex3fvSUN: [void, const GLuint *rc, const + GLfloat *tc, const GLfloat *n, const GLfloat *v] + glReplacementCodeuiTexCoord2fVertex3fSUN: [void, GLuint rc, GLfloat s, GLfloat t, + GLfloat x, GLfloat y, GLfloat z] + glReplacementCodeuiTexCoord2fVertex3fvSUN: [void, const GLuint *rc, const GLfloat + *tc, const GLfloat *v] + glReplacementCodeuiVertex3fSUN: [void, GLuint rc, GLfloat x, GLfloat y, GLfloat + z] + glReplacementCodeuiVertex3fvSUN: [void, const GLuint *rc, const GLfloat *v] + glTexCoord2fColor3fVertex3fSUN: [void, GLfloat s, GLfloat t, GLfloat r, GLfloat + g, GLfloat b, GLfloat x, GLfloat y, GLfloat z] + glTexCoord2fColor3fVertex3fvSUN: [void, const GLfloat *tc, const GLfloat *c, const + GLfloat *v] + glTexCoord2fColor4fNormal3fVertex3fSUN: [void, GLfloat s, GLfloat t, GLfloat r, + GLfloat g, GLfloat b, GLfloat a, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, + GLfloat y, GLfloat z] + glTexCoord2fColor4fNormal3fVertex3fvSUN: [void, const GLfloat *tc, const GLfloat + *c, const GLfloat *n, const GLfloat *v] + glTexCoord2fColor4ubVertex3fSUN: [void, GLfloat s, GLfloat t, GLubyte r, GLubyte + g, GLubyte b, GLubyte a, GLfloat x, GLfloat y, GLfloat z] + glTexCoord2fColor4ubVertex3fvSUN: [void, const GLfloat *tc, const GLubyte *c, const + GLfloat *v] + glTexCoord2fNormal3fVertex3fSUN: [void, GLfloat s, GLfloat t, GLfloat nx, GLfloat + ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z] + glTexCoord2fNormal3fVertex3fvSUN: [void, const GLfloat *tc, const GLfloat *n, const + GLfloat *v] + glTexCoord2fVertex3fSUN: [void, GLfloat s, GLfloat t, GLfloat x, GLfloat y, GLfloat + z] + glTexCoord2fVertex3fvSUN: [void, const GLfloat *tc, const GLfloat *v] + glTexCoord4fColor4fNormal3fVertex4fSUN: [void, GLfloat s, GLfloat t, GLfloat p, + GLfloat q, GLfloat r, GLfloat g, GLfloat b, GLfloat a, GLfloat nx, GLfloat ny, + GLfloat nz, GLfloat x, GLfloat y, GLfloat z, GLfloat w] + glTexCoord4fColor4fNormal3fVertex4fvSUN: [void, const GLfloat *tc, const GLfloat + *c, const GLfloat *n, const GLfloat *v] + glTexCoord4fVertex4fSUN: [void, GLfloat s, GLfloat t, GLfloat p, GLfloat q, GLfloat + x, GLfloat y, GLfloat z, GLfloat w] + glTexCoord4fVertex4fvSUN: [void, const GLfloat *tc, const GLfloat *v] +VERSION_1_0: + glAccum: [void, GLenum op, GLfloat value] + glAlphaFunc: [void, GLenum func, GLfloat ref] + glBegin: [void, GLenum mode] + glBitmap: [void, GLsizei width, GLsizei height, GLfloat xorig, GLfloat yorig, GLfloat + xmove, GLfloat ymove, const GLubyte *bitmap] + glBlendFunc: [void, GLenum sfactor, GLenum dfactor] + glCallList: [void, GLuint list] + glCallLists: [void, GLsizei n, GLenum type, const GLvoid *lists] + glClear: [void, GLbitfield mask] + glClearAccum: [void, GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha] + glClearColor: [void, GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha] + glClearDepth: [void, GLdouble depth] + glClearIndex: [void, GLfloat c] + glClearStencil: [void, GLint s] + glClipPlane: [void, GLenum plane, const GLdouble *equation] + glColor3b: [void, GLbyte red, GLbyte green, GLbyte blue] + glColor3bv: [void, const GLbyte *v] + glColor3d: [void, GLdouble red, GLdouble green, GLdouble blue] + glColor3dv: [void, const GLdouble *v] + glColor3f: [void, GLfloat red, GLfloat green, GLfloat blue] + glColor3fv: [void, const GLfloat *v] + glColor3i: [void, GLint red, GLint green, GLint blue] + glColor3iv: [void, const GLint *v] + glColor3s: [void, GLshort red, GLshort green, GLshort blue] + glColor3sv: [void, const GLshort *v] + glColor3ub: [void, GLubyte red, GLubyte green, GLubyte blue] + glColor3ubv: [void, const GLubyte *v] + glColor3ui: [void, GLuint red, GLuint green, GLuint blue] + glColor3uiv: [void, const GLuint *v] + glColor3us: [void, GLushort red, GLushort green, GLushort blue] + glColor3usv: [void, const GLushort *v] + glColor4b: [void, GLbyte red, GLbyte green, GLbyte blue, GLbyte alpha] + glColor4bv: [void, const GLbyte *v] + glColor4d: [void, GLdouble red, GLdouble green, GLdouble blue, GLdouble alpha] + glColor4dv: [void, const GLdouble *v] + glColor4f: [void, GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha] + glColor4fv: [void, const GLfloat *v] + glColor4i: [void, GLint red, GLint green, GLint blue, GLint alpha] + glColor4iv: [void, const GLint *v] + glColor4s: [void, GLshort red, GLshort green, GLshort blue, GLshort alpha] + glColor4sv: [void, const GLshort *v] + glColor4ub: [void, GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha] + glColor4ubv: [void, const GLubyte *v] + glColor4ui: [void, GLuint red, GLuint green, GLuint blue, GLuint alpha] + glColor4uiv: [void, const GLuint *v] + glColor4us: [void, GLushort red, GLushort green, GLushort blue, GLushort alpha] + glColor4usv: [void, const GLushort *v] + glColorMask: [void, GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha] + glColorMaterial: [void, GLenum face, GLenum mode] + glCopyPixels: [void, GLint x, GLint y, GLsizei width, GLsizei height, GLenum type] + glCullFace: [void, GLenum mode] + glDeleteLists: [void, GLuint list, GLsizei range] + glDepthFunc: [void, GLenum func] + glDepthMask: [void, GLboolean flag] + glDepthRange: [void, GLdouble near, GLdouble far] + glDisable: [void, GLenum cap] + glDrawBuffer: [void, GLenum mode] + glDrawPixels: [void, GLsizei width, GLsizei height, GLenum format, GLenum type, + const GLvoid *pixels] + glEdgeFlag: [void, GLboolean flag] + glEdgeFlagv: [void, const GLboolean *flag] + glEnable: [void, GLenum cap] + glEnd: [void] + glEndList: [void] + glEvalCoord1d: [void, GLdouble u] + glEvalCoord1dv: [void, const GLdouble *u] + glEvalCoord1f: [void, GLfloat u] + glEvalCoord1fv: [void, const GLfloat *u] + glEvalCoord2d: [void, GLdouble u, GLdouble v] + glEvalCoord2dv: [void, const GLdouble *u] + glEvalCoord2f: [void, GLfloat u, GLfloat v] + glEvalCoord2fv: [void, const GLfloat *u] + glEvalMesh1: [void, GLenum mode, GLint i1, GLint i2] + glEvalMesh2: [void, GLenum mode, GLint i1, GLint i2, GLint j1, GLint j2] + glEvalPoint1: [void, GLint i] + glEvalPoint2: [void, GLint i, GLint j] + glFeedbackBuffer: [void, GLsizei size, GLenum type, GLfloat *buffer] + glFinish: [void] + glFlush: [void] + glFogf: [void, GLenum pname, GLfloat param] + glFogfv: [void, GLenum pname, const GLfloat *params] + glFogi: [void, GLenum pname, GLint param] + glFogiv: [void, GLenum pname, const GLint *params] + glFrontFace: [void, GLenum mode] + glFrustum: [void, GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, + GLdouble zNear, GLdouble zFar] + glGenLists: [GLuint, GLsizei range] + glGetBooleanv: [void, GLenum pname, GLboolean *params] + glGetClipPlane: [void, GLenum plane, GLdouble *equation] + glGetDoublev: [void, GLenum pname, GLdouble *params] + glGetError: [GLenum] + glGetFloatv: [void, GLenum pname, GLfloat *params] + glGetIntegerv: [void, GLenum pname, GLint *params] + glGetLightfv: [void, GLenum light, GLenum pname, GLfloat *params] + glGetLightiv: [void, GLenum light, GLenum pname, GLint *params] + glGetMapdv: [void, GLenum target, GLenum query, GLdouble *v] + glGetMapfv: [void, GLenum target, GLenum query, GLfloat *v] + glGetMapiv: [void, GLenum target, GLenum query, GLint *v] + glGetMaterialfv: [void, GLenum face, GLenum pname, GLfloat *params] + glGetMaterialiv: [void, GLenum face, GLenum pname, GLint *params] + glGetPixelMapfv: [void, GLenum map, GLfloat *values] + glGetPixelMapuiv: [void, GLenum map, GLuint *values] + glGetPixelMapusv: [void, GLenum map, GLushort *values] + glGetPolygonStipple: [void, GLubyte *mask] + glGetString: [const GLubyte *, GLenum name] + glGetTexEnvfv: [void, GLenum target, GLenum pname, GLfloat *params] + glGetTexEnviv: [void, GLenum target, GLenum pname, GLint *params] + glGetTexGendv: [void, GLenum coord, GLenum pname, GLdouble *params] + glGetTexGenfv: [void, GLenum coord, GLenum pname, GLfloat *params] + glGetTexGeniv: [void, GLenum coord, GLenum pname, GLint *params] + glGetTexImage: [void, GLenum target, GLint level, GLenum format, GLenum type, GLvoid + *pixels] + glGetTexLevelParameterfv: [void, GLenum target, GLint level, GLenum pname, GLfloat + *params] + glGetTexLevelParameteriv: [void, GLenum target, GLint level, GLenum pname, GLint + *params] + glGetTexParameterfv: [void, GLenum target, GLenum pname, GLfloat *params] + glGetTexParameteriv: [void, GLenum target, GLenum pname, GLint *params] + glHint: [void, GLenum target, GLenum mode] + glIndexMask: [void, GLuint mask] + glIndexd: [void, GLdouble c] + glIndexdv: [void, const GLdouble *c] + glIndexf: [void, GLfloat c] + glIndexfv: [void, const GLfloat *c] + glIndexi: [void, GLint c] + glIndexiv: [void, const GLint *c] + glIndexs: [void, GLshort c] + glIndexsv: [void, const GLshort *c] + glInitNames: [void] + glIsEnabled: [GLboolean, GLenum cap] + glIsList: [GLboolean, GLuint list] + glLightModelf: [void, GLenum pname, GLfloat param] + glLightModelfv: [void, GLenum pname, const GLfloat *params] + glLightModeli: [void, GLenum pname, GLint param] + glLightModeliv: [void, GLenum pname, const GLint *params] + glLightf: [void, GLenum light, GLenum pname, GLfloat param] + glLightfv: [void, GLenum light, GLenum pname, const GLfloat *params] + glLighti: [void, GLenum light, GLenum pname, GLint param] + glLightiv: [void, GLenum light, GLenum pname, const GLint *params] + glLineStipple: [void, GLint factor, GLushort pattern] + glLineWidth: [void, GLfloat width] + glListBase: [void, GLuint base] + glLoadIdentity: [void] + glLoadMatrixd: [void, const GLdouble *m] + glLoadMatrixf: [void, const GLfloat *m] + glLoadName: [void, GLuint name] + glLogicOp: [void, GLenum opcode] + glMap1d: [void, GLenum target, GLdouble u1, GLdouble u2, GLint stride, GLint order, + const GLdouble *points] + glMap1f: [void, GLenum target, GLfloat u1, GLfloat u2, GLint stride, GLint order, + const GLfloat *points] + glMap2d: [void, GLenum target, GLdouble u1, GLdouble u2, GLint ustride, GLint uorder, + GLdouble v1, GLdouble v2, GLint vstride, GLint vorder, const GLdouble *points] + glMap2f: [void, GLenum target, GLfloat u1, GLfloat u2, GLint ustride, GLint uorder, + GLfloat v1, GLfloat v2, GLint vstride, GLint vorder, const GLfloat *points] + glMapGrid1d: [void, GLint un, GLdouble u1, GLdouble u2] + glMapGrid1f: [void, GLint un, GLfloat u1, GLfloat u2] + glMapGrid2d: [void, GLint un, GLdouble u1, GLdouble u2, GLint vn, GLdouble v1, GLdouble + v2] + glMapGrid2f: [void, GLint un, GLfloat u1, GLfloat u2, GLint vn, GLfloat v1, GLfloat + v2] + glMaterialf: [void, GLenum face, GLenum pname, GLfloat param] + glMaterialfv: [void, GLenum face, GLenum pname, const GLfloat *params] + glMateriali: [void, GLenum face, GLenum pname, GLint param] + glMaterialiv: [void, GLenum face, GLenum pname, const GLint *params] + glMatrixMode: [void, GLenum mode] + glMultMatrixd: [void, const GLdouble *m] + glMultMatrixf: [void, const GLfloat *m] + glNewList: [void, GLuint list, GLenum mode] + glNormal3b: [void, GLbyte nx, GLbyte ny, GLbyte nz] + glNormal3bv: [void, const GLbyte *v] + glNormal3d: [void, GLdouble nx, GLdouble ny, GLdouble nz] + glNormal3dv: [void, const GLdouble *v] + glNormal3f: [void, GLfloat nx, GLfloat ny, GLfloat nz] + glNormal3fv: [void, const GLfloat *v] + glNormal3i: [void, GLint nx, GLint ny, GLint nz] + glNormal3iv: [void, const GLint *v] + glNormal3s: [void, GLshort nx, GLshort ny, GLshort nz] + glNormal3sv: [void, const GLshort *v] + glOrtho: [void, GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble + zNear, GLdouble zFar] + glPassThrough: [void, GLfloat token] + glPixelMapfv: [void, GLenum map, GLsizei mapsize, const GLfloat *values] + glPixelMapuiv: [void, GLenum map, GLsizei mapsize, const GLuint *values] + glPixelMapusv: [void, GLenum map, GLsizei mapsize, const GLushort *values] + glPixelStoref: [void, GLenum pname, GLfloat param] + glPixelStorei: [void, GLenum pname, GLint param] + glPixelTransferf: [void, GLenum pname, GLfloat param] + glPixelTransferi: [void, GLenum pname, GLint param] + glPixelZoom: [void, GLfloat xfactor, GLfloat yfactor] + glPointSize: [void, GLfloat size] + glPolygonMode: [void, GLenum face, GLenum mode] + glPolygonStipple: [void, const GLubyte *mask] + glPopAttrib: [void] + glPopMatrix: [void] + glPopName: [void] + glPushAttrib: [void, GLbitfield mask] + glPushMatrix: [void] + glPushName: [void, GLuint name] + glRasterPos2d: [void, GLdouble x, GLdouble y] + glRasterPos2dv: [void, const GLdouble *v] + glRasterPos2f: [void, GLfloat x, GLfloat y] + glRasterPos2fv: [void, const GLfloat *v] + glRasterPos2i: [void, GLint x, GLint y] + glRasterPos2iv: [void, const GLint *v] + glRasterPos2s: [void, GLshort x, GLshort y] + glRasterPos2sv: [void, const GLshort *v] + glRasterPos3d: [void, GLdouble x, GLdouble y, GLdouble z] + glRasterPos3dv: [void, const GLdouble *v] + glRasterPos3f: [void, GLfloat x, GLfloat y, GLfloat z] + glRasterPos3fv: [void, const GLfloat *v] + glRasterPos3i: [void, GLint x, GLint y, GLint z] + glRasterPos3iv: [void, const GLint *v] + glRasterPos3s: [void, GLshort x, GLshort y, GLshort z] + glRasterPos3sv: [void, const GLshort *v] + glRasterPos4d: [void, GLdouble x, GLdouble y, GLdouble z, GLdouble w] + glRasterPos4dv: [void, const GLdouble *v] + glRasterPos4f: [void, GLfloat x, GLfloat y, GLfloat z, GLfloat w] + glRasterPos4fv: [void, const GLfloat *v] + glRasterPos4i: [void, GLint x, GLint y, GLint z, GLint w] + glRasterPos4iv: [void, const GLint *v] + glRasterPos4s: [void, GLshort x, GLshort y, GLshort z, GLshort w] + glRasterPos4sv: [void, const GLshort *v] + glReadBuffer: [void, GLenum mode] + glReadPixels: [void, GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, + GLenum type, GLvoid *pixels] + glRectd: [void, GLdouble x1, GLdouble y1, GLdouble x2, GLdouble y2] + glRectdv: [void, const GLdouble *v1, const GLdouble *v2] + glRectf: [void, GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2] + glRectfv: [void, const GLfloat *v1, const GLfloat *v2] + glRecti: [void, GLint x1, GLint y1, GLint x2, GLint y2] + glRectiv: [void, const GLint *v1, const GLint *v2] + glRects: [void, GLshort x1, GLshort y1, GLshort x2, GLshort y2] + glRectsv: [void, const GLshort *v1, const GLshort *v2] + glRenderMode: [GLint, GLenum mode] + glRotated: [void, GLdouble angle, GLdouble x, GLdouble y, GLdouble z] + glRotatef: [void, GLfloat angle, GLfloat x, GLfloat y, GLfloat z] + glScaled: [void, GLdouble x, GLdouble y, GLdouble z] + glScalef: [void, GLfloat x, GLfloat y, GLfloat z] + glScissor: [void, GLint x, GLint y, GLsizei width, GLsizei height] + glSelectBuffer: [void, GLsizei size, GLuint *buffer] + glShadeModel: [void, GLenum mode] + glStencilFunc: [void, GLenum func, GLint ref, GLuint mask] + glStencilMask: [void, GLuint mask] + glStencilOp: [void, GLenum fail, GLenum zfail, GLenum zpass] + glTexCoord1d: [void, GLdouble s] + glTexCoord1dv: [void, const GLdouble *v] + glTexCoord1f: [void, GLfloat s] + glTexCoord1fv: [void, const GLfloat *v] + glTexCoord1i: [void, GLint s] + glTexCoord1iv: [void, const GLint *v] + glTexCoord1s: [void, GLshort s] + glTexCoord1sv: [void, const GLshort *v] + glTexCoord2d: [void, GLdouble s, GLdouble t] + glTexCoord2dv: [void, const GLdouble *v] + glTexCoord2f: [void, GLfloat s, GLfloat t] + glTexCoord2fv: [void, const GLfloat *v] + glTexCoord2i: [void, GLint s, GLint t] + glTexCoord2iv: [void, const GLint *v] + glTexCoord2s: [void, GLshort s, GLshort t] + glTexCoord2sv: [void, const GLshort *v] + glTexCoord3d: [void, GLdouble s, GLdouble t, GLdouble r] + glTexCoord3dv: [void, const GLdouble *v] + glTexCoord3f: [void, GLfloat s, GLfloat t, GLfloat r] + glTexCoord3fv: [void, const GLfloat *v] + glTexCoord3i: [void, GLint s, GLint t, GLint r] + glTexCoord3iv: [void, const GLint *v] + glTexCoord3s: [void, GLshort s, GLshort t, GLshort r] + glTexCoord3sv: [void, const GLshort *v] + glTexCoord4d: [void, GLdouble s, GLdouble t, GLdouble r, GLdouble q] + glTexCoord4dv: [void, const GLdouble *v] + glTexCoord4f: [void, GLfloat s, GLfloat t, GLfloat r, GLfloat q] + glTexCoord4fv: [void, const GLfloat *v] + glTexCoord4i: [void, GLint s, GLint t, GLint r, GLint q] + glTexCoord4iv: [void, const GLint *v] + glTexCoord4s: [void, GLshort s, GLshort t, GLshort r, GLshort q] + glTexCoord4sv: [void, const GLshort *v] + glTexEnvf: [void, GLenum target, GLenum pname, GLfloat param] + glTexEnvfv: [void, GLenum target, GLenum pname, const GLfloat *params] + glTexEnvi: [void, GLenum target, GLenum pname, GLint param] + glTexEnviv: [void, GLenum target, GLenum pname, const GLint *params] + glTexGend: [void, GLenum coord, GLenum pname, GLdouble param] + glTexGendv: [void, GLenum coord, GLenum pname, const GLdouble *params] + glTexGenf: [void, GLenum coord, GLenum pname, GLfloat param] + glTexGenfv: [void, GLenum coord, GLenum pname, const GLfloat *params] + glTexGeni: [void, GLenum coord, GLenum pname, GLint param] + glTexGeniv: [void, GLenum coord, GLenum pname, const GLint *params] + glTexImage1D: [void, GLenum target, GLint level, GLint internalformat, GLsizei width, + GLint border, GLenum format, GLenum type, const GLvoid *pixels] + glTexImage2D: [void, GLenum target, GLint level, GLint internalformat, GLsizei width, + GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels] + glTexParameterf: [void, GLenum target, GLenum pname, GLfloat param] + glTexParameterfv: [void, GLenum target, GLenum pname, const GLfloat *params] + glTexParameteri: [void, GLenum target, GLenum pname, GLint param] + glTexParameteriv: [void, GLenum target, GLenum pname, const GLint *params] + glTranslated: [void, GLdouble x, GLdouble y, GLdouble z] + glTranslatef: [void, GLfloat x, GLfloat y, GLfloat z] + glVertex2d: [void, GLdouble x, GLdouble y] + glVertex2dv: [void, const GLdouble *v] + glVertex2f: [void, GLfloat x, GLfloat y] + glVertex2fv: [void, const GLfloat *v] + glVertex2i: [void, GLint x, GLint y] + glVertex2iv: [void, const GLint *v] + glVertex2s: [void, GLshort x, GLshort y] + glVertex2sv: [void, const GLshort *v] + glVertex3d: [void, GLdouble x, GLdouble y, GLdouble z] + glVertex3dv: [void, const GLdouble *v] + glVertex3f: [void, GLfloat x, GLfloat y, GLfloat z] + glVertex3fv: [void, const GLfloat *v] + glVertex3i: [void, GLint x, GLint y, GLint z] + glVertex3iv: [void, const GLint *v] + glVertex3s: [void, GLshort x, GLshort y, GLshort z] + glVertex3sv: [void, const GLshort *v] + glVertex4d: [void, GLdouble x, GLdouble y, GLdouble z, GLdouble w] + glVertex4dv: [void, const GLdouble *v] + glVertex4f: [void, GLfloat x, GLfloat y, GLfloat z, GLfloat w] + glVertex4fv: [void, const GLfloat *v] + glVertex4i: [void, GLint x, GLint y, GLint z, GLint w] + glVertex4iv: [void, const GLint *v] + glVertex4s: [void, GLshort x, GLshort y, GLshort z, GLshort w] + glVertex4sv: [void, const GLshort *v] + glViewport: [void, GLint x, GLint y, GLsizei width, GLsizei height] +VERSION_1_1: + glAreTexturesResident: [GLboolean, GLsizei n, const GLuint *textures, GLboolean + *residences] + glArrayElement: [void, GLint i] + glBindTexture: [void, GLenum target, GLuint texture] + glColorPointer: [void, GLint size, GLenum type, GLsizei stride, const GLvoid *pointer] + glCopyTexImage1D: [void, GLenum target, GLint level, GLenum internalformat, GLint + x, GLint y, GLsizei width, GLint border] + glCopyTexImage2D: [void, GLenum target, GLint level, GLenum internalformat, GLint + x, GLint y, GLsizei width, GLsizei height, GLint border] + glCopyTexSubImage1D: [void, GLenum target, GLint level, GLint xoffset, GLint x, + GLint y, GLsizei width] + glCopyTexSubImage2D: [void, GLenum target, GLint level, GLint xoffset, GLint yoffset, + GLint x, GLint y, GLsizei width, GLsizei height] + glDeleteTextures: [void, GLsizei n, const GLuint *textures] + glDisableClientState: [void, GLenum array] + glDrawArrays: [void, GLenum mode, GLint first, GLsizei count] + glDrawElements: [void, GLenum mode, GLsizei count, GLenum type, const GLvoid *indices] + glEdgeFlagPointer: [void, GLsizei stride, const GLvoid *pointer] + glEnableClientState: [void, GLenum array] + glGenTextures: [void, GLsizei n, GLuint *textures] + glGetPointerv: [void, GLenum pname, GLvoid **params] + glIndexPointer: [void, GLenum type, GLsizei stride, const GLvoid *pointer] + glIndexub: [void, GLubyte c] + glIndexubv: [void, const GLubyte *c] + glInterleavedArrays: [void, GLenum format, GLsizei stride, const GLvoid *pointer] + glIsTexture: [GLboolean, GLuint texture] + glNormalPointer: [void, GLenum type, GLsizei stride, const GLvoid *pointer] + glPolygonOffset: [void, GLfloat factor, GLfloat units] + glPopClientAttrib: [void] + glPrioritizeTextures: [void, GLsizei n, const GLuint *textures, const GLfloat *priorities] + glPushClientAttrib: [void, GLbitfield mask] + glTexCoordPointer: [void, GLint size, GLenum type, GLsizei stride, const GLvoid + *pointer] + glTexSubImage1D: [void, GLenum target, GLint level, GLint xoffset, GLsizei width, + GLenum format, GLenum type, const GLvoid *pixels] + glTexSubImage2D: [void, GLenum target, GLint level, GLint xoffset, GLint yoffset, + GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels] + glVertexPointer: [void, GLint size, GLenum type, GLsizei stride, const GLvoid *pointer] +VERSION_1_2: + glBlendColor: [void, GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha] + glBlendEquation: [void, GLenum mode] + glColorSubTable: [void, GLenum target, GLsizei start, GLsizei count, GLenum format, + GLenum type, const GLvoid *data] + glColorTable: [void, GLenum target, GLenum internalformat, GLsizei width, GLenum + format, GLenum type, const GLvoid *table] + glColorTableParameterfv: [void, GLenum target, GLenum pname, const GLfloat *params] + glColorTableParameteriv: [void, GLenum target, GLenum pname, const GLint *params] + glConvolutionFilter1D: [void, GLenum target, GLenum internalformat, GLsizei width, + GLenum format, GLenum type, const GLvoid *image] + glConvolutionFilter2D: [void, GLenum target, GLenum internalformat, GLsizei width, + GLsizei height, GLenum format, GLenum type, const GLvoid *image] + glConvolutionParameterf: [void, GLenum target, GLenum pname, GLfloat params] + glConvolutionParameterfv: [void, GLenum target, GLenum pname, const GLfloat *params] + glConvolutionParameteri: [void, GLenum target, GLenum pname, GLint params] + glConvolutionParameteriv: [void, GLenum target, GLenum pname, const GLint *params] + glCopyColorSubTable: [void, GLenum target, GLsizei start, GLint x, GLint y, GLsizei + width] + glCopyColorTable: [void, GLenum target, GLenum internalformat, GLint x, GLint y, + GLsizei width] + glCopyConvolutionFilter1D: [void, GLenum target, GLenum internalformat, GLint x, + GLint y, GLsizei width] + glCopyConvolutionFilter2D: [void, GLenum target, GLenum internalformat, GLint x, + GLint y, GLsizei width, GLsizei height] + glCopyTexSubImage3D: [void, GLenum target, GLint level, GLint xoffset, GLint yoffset, + GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height] + glDrawRangeElements: [void, GLenum mode, GLuint start, GLuint end, GLsizei count, + GLenum type, const GLvoid *indices] + glGetColorTable: [void, GLenum target, GLenum format, GLenum type, GLvoid *table] + glGetColorTableParameterfv: [void, GLenum target, GLenum pname, GLfloat *params] + glGetColorTableParameteriv: [void, GLenum target, GLenum pname, GLint *params] + glGetConvolutionFilter: [void, GLenum target, GLenum format, GLenum type, GLvoid + *image] + glGetConvolutionParameterfv: [void, GLenum target, GLenum pname, GLfloat *params] + glGetConvolutionParameteriv: [void, GLenum target, GLenum pname, GLint *params] + glGetHistogram: [void, GLenum target, GLboolean reset, GLenum format, GLenum type, + GLvoid *values] + glGetHistogramParameterfv: [void, GLenum target, GLenum pname, GLfloat *params] + glGetHistogramParameteriv: [void, GLenum target, GLenum pname, GLint *params] + glGetMinmax: [void, GLenum target, GLboolean reset, GLenum format, GLenum type, + GLvoid *values] + glGetMinmaxParameterfv: [void, GLenum target, GLenum pname, GLfloat *params] + glGetMinmaxParameteriv: [void, GLenum target, GLenum pname, GLint *params] + glGetSeparableFilter: [void, GLenum target, GLenum format, GLenum type, GLvoid *row, + GLvoid *column, GLvoid *span] + glHistogram: [void, GLenum target, GLsizei width, GLenum internalformat, GLboolean + sink] + glMinmax: [void, GLenum target, GLenum internalformat, GLboolean sink] + glResetHistogram: [void, GLenum target] + glResetMinmax: [void, GLenum target] + glSeparableFilter2D: [void, GLenum target, GLenum internalformat, GLsizei width, + GLsizei height, GLenum format, GLenum type, const GLvoid *row, const GLvoid *column] + glTexImage3D: [void, GLenum target, GLint level, GLint internalformat, GLsizei width, + GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const + GLvoid *pixels] + glTexSubImage3D: [void, GLenum target, GLint level, GLint xoffset, GLint yoffset, + GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum + type, const GLvoid *pixels] +VERSION_1_3: + glActiveTexture: [void, GLenum texture] + glClientActiveTexture: [void, GLenum texture] + glCompressedTexImage1D: [void, GLenum target, GLint level, GLenum internalformat, + GLsizei width, GLint border, GLsizei imageSize, const GLvoid *data] + glCompressedTexImage2D: [void, GLenum target, GLint level, GLenum internalformat, + GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data] + glCompressedTexImage3D: [void, GLenum target, GLint level, GLenum internalformat, + GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, + const GLvoid *data] + glCompressedTexSubImage1D: [void, GLenum target, GLint level, GLint xoffset, GLsizei + width, GLenum format, GLsizei imageSize, const GLvoid *data] + glCompressedTexSubImage2D: [void, GLenum target, GLint level, GLint xoffset, GLint + yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const + GLvoid *data] + glCompressedTexSubImage3D: [void, GLenum target, GLint level, GLint xoffset, GLint + yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum + format, GLsizei imageSize, const GLvoid *data] + glGetCompressedTexImage: [void, GLenum target, GLint level, GLvoid *img] + glLoadTransposeMatrixd: [void, const GLdouble *m] + glLoadTransposeMatrixf: [void, const GLfloat *m] + glMultTransposeMatrixd: [void, const GLdouble *m] + glMultTransposeMatrixf: [void, const GLfloat *m] + glMultiTexCoord1d: [void, GLenum target, GLdouble s] + glMultiTexCoord1dv: [void, GLenum target, const GLdouble *v] + glMultiTexCoord1f: [void, GLenum target, GLfloat s] + glMultiTexCoord1fv: [void, GLenum target, const GLfloat *v] + glMultiTexCoord1i: [void, GLenum target, GLint s] + glMultiTexCoord1iv: [void, GLenum target, const GLint *v] + glMultiTexCoord1s: [void, GLenum target, GLshort s] + glMultiTexCoord1sv: [void, GLenum target, const GLshort *v] + glMultiTexCoord2d: [void, GLenum target, GLdouble s, GLdouble t] + glMultiTexCoord2dv: [void, GLenum target, const GLdouble *v] + glMultiTexCoord2f: [void, GLenum target, GLfloat s, GLfloat t] + glMultiTexCoord2fv: [void, GLenum target, const GLfloat *v] + glMultiTexCoord2i: [void, GLenum target, GLint s, GLint t] + glMultiTexCoord2iv: [void, GLenum target, const GLint *v] + glMultiTexCoord2s: [void, GLenum target, GLshort s, GLshort t] + glMultiTexCoord2sv: [void, GLenum target, const GLshort *v] + glMultiTexCoord3d: [void, GLenum target, GLdouble s, GLdouble t, GLdouble r] + glMultiTexCoord3dv: [void, GLenum target, const GLdouble *v] + glMultiTexCoord3f: [void, GLenum target, GLfloat s, GLfloat t, GLfloat r] + glMultiTexCoord3fv: [void, GLenum target, const GLfloat *v] + glMultiTexCoord3i: [void, GLenum target, GLint s, GLint t, GLint r] + glMultiTexCoord3iv: [void, GLenum target, const GLint *v] + glMultiTexCoord3s: [void, GLenum target, GLshort s, GLshort t, GLshort r] + glMultiTexCoord3sv: [void, GLenum target, const GLshort *v] + glMultiTexCoord4d: [void, GLenum target, GLdouble s, GLdouble t, GLdouble r, GLdouble + q] + glMultiTexCoord4dv: [void, GLenum target, const GLdouble *v] + glMultiTexCoord4f: [void, GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat + q] + glMultiTexCoord4fv: [void, GLenum target, const GLfloat *v] + glMultiTexCoord4i: [void, GLenum target, GLint s, GLint t, GLint r, GLint q] + glMultiTexCoord4iv: [void, GLenum target, const GLint *v] + glMultiTexCoord4s: [void, GLenum target, GLshort s, GLshort t, GLshort r, GLshort + q] + glMultiTexCoord4sv: [void, GLenum target, const GLshort *v] + glSampleCoverage: [void, GLfloat value, GLboolean invert] +VERSION_1_4: + glBlendFuncSeparate: [void, GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, + GLenum dfactorAlpha] + glFogCoordPointer: [void, GLenum type, GLsizei stride, const GLvoid *pointer] + glFogCoordd: [void, GLdouble coord] + glFogCoorddv: [void, const GLdouble *coord] + glFogCoordf: [void, GLfloat coord] + glFogCoordfv: [void, const GLfloat *coord] + glMultiDrawArrays: [void, GLenum mode, const GLint *first, const GLsizei *count, + GLsizei drawcount] + glMultiDrawElements: [void, GLenum mode, const GLsizei *count, GLenum type, GLvoid*const + *indices, GLsizei drawcount] + glPointParameterf: [void, GLenum pname, GLfloat param] + glPointParameterfv: [void, GLenum pname, const GLfloat *params] + glPointParameteri: [void, GLenum pname, GLint param] + glPointParameteriv: [void, GLenum pname, const GLint *params] + glSecondaryColor3b: [void, GLbyte red, GLbyte green, GLbyte blue] + glSecondaryColor3bv: [void, const GLbyte *v] + glSecondaryColor3d: [void, GLdouble red, GLdouble green, GLdouble blue] + glSecondaryColor3dv: [void, const GLdouble *v] + glSecondaryColor3f: [void, GLfloat red, GLfloat green, GLfloat blue] + glSecondaryColor3fv: [void, const GLfloat *v] + glSecondaryColor3i: [void, GLint red, GLint green, GLint blue] + glSecondaryColor3iv: [void, const GLint *v] + glSecondaryColor3s: [void, GLshort red, GLshort green, GLshort blue] + glSecondaryColor3sv: [void, const GLshort *v] + glSecondaryColor3ub: [void, GLubyte red, GLubyte green, GLubyte blue] + glSecondaryColor3ubv: [void, const GLubyte *v] + glSecondaryColor3ui: [void, GLuint red, GLuint green, GLuint blue] + glSecondaryColor3uiv: [void, const GLuint *v] + glSecondaryColor3us: [void, GLushort red, GLushort green, GLushort blue] + glSecondaryColor3usv: [void, const GLushort *v] + glSecondaryColorPointer: [void, GLint size, GLenum type, GLsizei stride, const GLvoid + *pointer] + glWindowPos2d: [void, GLdouble x, GLdouble y] + glWindowPos2dv: [void, const GLdouble *v] + glWindowPos2f: [void, GLfloat x, GLfloat y] + glWindowPos2fv: [void, const GLfloat *v] + glWindowPos2i: [void, GLint x, GLint y] + glWindowPos2iv: [void, const GLint *v] + glWindowPos2s: [void, GLshort x, GLshort y] + glWindowPos2sv: [void, const GLshort *v] + glWindowPos3d: [void, GLdouble x, GLdouble y, GLdouble z] + glWindowPos3dv: [void, const GLdouble *v] + glWindowPos3f: [void, GLfloat x, GLfloat y, GLfloat z] + glWindowPos3fv: [void, const GLfloat *v] + glWindowPos3i: [void, GLint x, GLint y, GLint z] + glWindowPos3iv: [void, const GLint *v] + glWindowPos3s: [void, GLshort x, GLshort y, GLshort z] + glWindowPos3sv: [void, const GLshort *v] +VERSION_1_5: + glBeginQuery: [void, GLenum target, GLuint id] + glBindBuffer: [void, GLenum target, GLuint buffer] + glBufferData: [void, GLenum target, GLsizeiptr size, const GLvoid *data, GLenum + usage] + glBufferSubData: [void, GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid + *data] + glDeleteBuffers: [void, GLsizei n, const GLuint *buffers] + glDeleteQueries: [void, GLsizei n, const GLuint *ids] + glEndQuery: [void, GLenum target] + glGenBuffers: [void, GLsizei n, GLuint *buffers] + glGenQueries: [void, GLsizei n, GLuint *ids] + glGetBufferParameteriv: [void, GLenum target, GLenum pname, GLint *params] + glGetBufferPointerv: [void, GLenum target, GLenum pname, GLvoid *params] + glGetBufferSubData: [void, GLenum target, GLintptr offset, GLsizeiptr size, GLvoid + *data] + glGetQueryObjectiv: [void, GLuint id, GLenum pname, GLint *params] + glGetQueryObjectuiv: [void, GLuint id, GLenum pname, GLuint *params] + glGetQueryiv: [void, GLenum target, GLenum pname, GLint *params] + glIsBuffer: [GLboolean, GLuint buffer] + glIsQuery: [GLboolean, GLuint id] + glMapBuffer: [GLvoid *, GLenum target, GLenum access] + glUnmapBuffer: [GLboolean, GLenum target] +VERSION_2_0: + glAttachShader: [void, GLuint program, GLuint shader] + glBindAttribLocation: [void, GLuint program, GLuint index, const GLchar *name] + glBlendEquationSeparate: [void, GLenum modeRGB, GLenum modeAlpha] + glCompileShader: [void, GLuint shader] + glCreateProgram: [GLuint] + glCreateShader: [GLuint, GLenum type] + glDeleteProgram: [void, GLuint program] + glDeleteShader: [void, GLuint shader] + glDetachShader: [void, GLuint program, GLuint shader] + glDisableVertexAttribArray: [void, GLuint index] + glDrawBuffers: [void, GLsizei n, const GLenum *bufs] + glEnableVertexAttribArray: [void, GLuint index] + glGetActiveAttrib: [void, GLuint program, GLuint index, GLsizei bufSize, GLsizei + *length, GLint *size, GLenum *type, GLchar *name] + glGetActiveUniform: [void, GLuint program, GLuint index, GLsizei bufSize, GLsizei + *length, GLint *size, GLenum *type, GLchar *name] + glGetAttachedShaders: [void, GLuint program, GLsizei maxCount, GLsizei *count, GLuint + *obj] + glGetAttribLocation: [GLint, GLuint program, const GLchar *name] + glGetProgramInfoLog: [void, GLuint program, GLsizei bufSize, GLsizei *length, GLchar + *infoLog] + glGetProgramiv: [void, GLuint program, GLenum pname, GLint *params] + glGetShaderInfoLog: [void, GLuint shader, GLsizei bufSize, GLsizei *length, GLchar + *infoLog] + glGetShaderSource: [void, GLuint shader, GLsizei bufSize, GLsizei *length, GLchar + *source] + glGetShaderiv: [void, GLuint shader, GLenum pname, GLint *params] + glGetUniformLocation: [GLint, GLuint program, const GLchar *name] + glGetUniformfv: [void, GLuint program, GLint location, GLfloat *params] + glGetUniformiv: [void, GLuint program, GLint location, GLint *params] + glGetVertexAttribPointerv: [void, GLuint index, GLenum pname, GLvoid *pointer] + glGetVertexAttribdv: [void, GLuint index, GLenum pname, GLdouble *params] + glGetVertexAttribfv: [void, GLuint index, GLenum pname, GLfloat *params] + glGetVertexAttribiv: [void, GLuint index, GLenum pname, GLint *params] + glIsProgram: [GLboolean, GLuint program] + glIsShader: [GLboolean, GLuint shader] + glLinkProgram: [void, GLuint program] + glShaderSource: [void, GLuint shader, GLsizei count, GLchar*const *string, const + GLint *length] + glStencilFuncSeparate: [void, GLenum face, GLenum func, GLint ref, GLuint mask] + glStencilMaskSeparate: [void, GLenum face, GLuint mask] + glStencilOpSeparate: [void, GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass] + glUniform1f: [void, GLint location, GLfloat v0] + glUniform1fv: [void, GLint location, GLsizei count, const GLfloat *value] + glUniform1i: [void, GLint location, GLint v0] + glUniform1iv: [void, GLint location, GLsizei count, const GLint *value] + glUniform2f: [void, GLint location, GLfloat v0, GLfloat v1] + glUniform2fv: [void, GLint location, GLsizei count, const GLfloat *value] + glUniform2i: [void, GLint location, GLint v0, GLint v1] + glUniform2iv: [void, GLint location, GLsizei count, const GLint *value] + glUniform3f: [void, GLint location, GLfloat v0, GLfloat v1, GLfloat v2] + glUniform3fv: [void, GLint location, GLsizei count, const GLfloat *value] + glUniform3i: [void, GLint location, GLint v0, GLint v1, GLint v2] + glUniform3iv: [void, GLint location, GLsizei count, const GLint *value] + glUniform4f: [void, GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat + v3] + glUniform4fv: [void, GLint location, GLsizei count, const GLfloat *value] + glUniform4i: [void, GLint location, GLint v0, GLint v1, GLint v2, GLint v3] + glUniform4iv: [void, GLint location, GLsizei count, const GLint *value] + glUniformMatrix2fv: [void, GLint location, GLsizei count, GLboolean transpose, const + GLfloat *value] + glUniformMatrix3fv: [void, GLint location, GLsizei count, GLboolean transpose, const + GLfloat *value] + glUniformMatrix4fv: [void, GLint location, GLsizei count, GLboolean transpose, const + GLfloat *value] + glUseProgram: [void, GLuint program] + glValidateProgram: [void, GLuint program] + glVertexAttrib1d: [void, GLuint index, GLdouble x] + glVertexAttrib1dv: [void, GLuint index, const GLdouble *v] + glVertexAttrib1f: [void, GLuint index, GLfloat x] + glVertexAttrib1fv: [void, GLuint index, const GLfloat *v] + glVertexAttrib1s: [void, GLuint index, GLshort x] + glVertexAttrib1sv: [void, GLuint index, const GLshort *v] + glVertexAttrib2d: [void, GLuint index, GLdouble x, GLdouble y] + glVertexAttrib2dv: [void, GLuint index, const GLdouble *v] + glVertexAttrib2f: [void, GLuint index, GLfloat x, GLfloat y] + glVertexAttrib2fv: [void, GLuint index, const GLfloat *v] + glVertexAttrib2s: [void, GLuint index, GLshort x, GLshort y] + glVertexAttrib2sv: [void, GLuint index, const GLshort *v] + glVertexAttrib3d: [void, GLuint index, GLdouble x, GLdouble y, GLdouble z] + glVertexAttrib3dv: [void, GLuint index, const GLdouble *v] + glVertexAttrib3f: [void, GLuint index, GLfloat x, GLfloat y, GLfloat z] + glVertexAttrib3fv: [void, GLuint index, const GLfloat *v] + glVertexAttrib3s: [void, GLuint index, GLshort x, GLshort y, GLshort z] + glVertexAttrib3sv: [void, GLuint index, const GLshort *v] + glVertexAttrib4Nbv: [void, GLuint index, const GLbyte *v] + glVertexAttrib4Niv: [void, GLuint index, const GLint *v] + glVertexAttrib4Nsv: [void, GLuint index, const GLshort *v] + glVertexAttrib4Nub: [void, GLuint index, GLubyte x, GLubyte y, GLubyte z, GLubyte + w] + glVertexAttrib4Nubv: [void, GLuint index, const GLubyte *v] + glVertexAttrib4Nuiv: [void, GLuint index, const GLuint *v] + glVertexAttrib4Nusv: [void, GLuint index, const GLushort *v] + glVertexAttrib4bv: [void, GLuint index, const GLbyte *v] + glVertexAttrib4d: [void, GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble + w] + glVertexAttrib4dv: [void, GLuint index, const GLdouble *v] + glVertexAttrib4f: [void, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat + w] + glVertexAttrib4fv: [void, GLuint index, const GLfloat *v] + glVertexAttrib4iv: [void, GLuint index, const GLint *v] + glVertexAttrib4s: [void, GLuint index, GLshort x, GLshort y, GLshort z, GLshort + w] + glVertexAttrib4sv: [void, GLuint index, const GLshort *v] + glVertexAttrib4ubv: [void, GLuint index, const GLubyte *v] + glVertexAttrib4uiv: [void, GLuint index, const GLuint *v] + glVertexAttrib4usv: [void, GLuint index, const GLushort *v] + glVertexAttribPointer: [void, GLuint index, GLint size, GLenum type, GLboolean normalized, + GLsizei stride, const GLvoid *pointer] +VERSION_2_1: + glUniformMatrix2x3fv: [void, GLint location, GLsizei count, GLboolean transpose, + const GLfloat *value] + glUniformMatrix2x4fv: [void, GLint location, GLsizei count, GLboolean transpose, + const GLfloat *value] + glUniformMatrix3x2fv: [void, GLint location, GLsizei count, GLboolean transpose, + const GLfloat *value] + glUniformMatrix3x4fv: [void, GLint location, GLsizei count, GLboolean transpose, + const GLfloat *value] + glUniformMatrix4x2fv: [void, GLint location, GLsizei count, GLboolean transpose, + const GLfloat *value] + glUniformMatrix4x3fv: [void, GLint location, GLsizei count, GLboolean transpose, + const GLfloat *value] +VERSION_3_0: + glBeginConditionalRender: [void, GLuint id, GLenum mode] + glBeginTransformFeedback: [void, GLenum primitiveMode] + glBindBufferBase: [void, GLenum target, GLuint index, GLuint buffer] + glBindBufferRange: [void, GLenum target, GLuint index, GLuint buffer, GLintptr offset, + GLsizeiptr size] + glBindFragDataLocation: [void, GLuint program, GLuint color, const GLchar *name] + glClampColor: [void, GLenum target, GLenum clamp] + glClearBufferfi: [void, GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil] + glClearBufferfv: [void, GLenum buffer, GLint drawbuffer, const GLfloat *value] + glClearBufferiv: [void, GLenum buffer, GLint drawbuffer, const GLint *value] + glClearBufferuiv: [void, GLenum buffer, GLint drawbuffer, const GLuint *value] + glColorMaski: [void, GLuint index, GLboolean r, GLboolean g, GLboolean b, GLboolean + a] + glDisablei: [void, GLenum target, GLuint index] + glEnablei: [void, GLenum target, GLuint index] + glEndConditionalRender: [void] + glEndTransformFeedback: [void] + glGetBooleani_v: [void, GLenum target, GLuint index, GLboolean *data] + glGetFragDataLocation: [GLint, GLuint program, const GLchar *name] + glGetIntegeri_v: [void, GLenum target, GLuint index, GLint *data] + glGetStringi: [const GLubyte *, GLenum name, GLuint index] + glGetTexParameterIiv: [void, GLenum target, GLenum pname, GLint *params] + glGetTexParameterIuiv: [void, GLenum target, GLenum pname, GLuint *params] + glGetTransformFeedbackVarying: [void, GLuint program, GLuint index, GLsizei bufSize, + GLsizei *length, GLsizei *size, GLenum *type, GLchar *name] + glGetUniformuiv: [void, GLuint program, GLint location, GLuint *params] + glGetVertexAttribIiv: [void, GLuint index, GLenum pname, GLint *params] + glGetVertexAttribIuiv: [void, GLuint index, GLenum pname, GLuint *params] + glIsEnabledi: [GLboolean, GLenum target, GLuint index] + glTexParameterIiv: [void, GLenum target, GLenum pname, const GLint *params] + glTexParameterIuiv: [void, GLenum target, GLenum pname, const GLuint *params] + glTransformFeedbackVaryings: [void, GLuint program, GLsizei count, GLchar*const + *varyings, GLenum bufferMode] + glUniform1ui: [void, GLint location, GLuint v0] + glUniform1uiv: [void, GLint location, GLsizei count, const GLuint *value] + glUniform2ui: [void, GLint location, GLuint v0, GLuint v1] + glUniform2uiv: [void, GLint location, GLsizei count, const GLuint *value] + glUniform3ui: [void, GLint location, GLuint v0, GLuint v1, GLuint v2] + glUniform3uiv: [void, GLint location, GLsizei count, const GLuint *value] + glUniform4ui: [void, GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3] + glUniform4uiv: [void, GLint location, GLsizei count, const GLuint *value] + glVertexAttribI1i: [void, GLuint index, GLint x] + glVertexAttribI1iv: [void, GLuint index, const GLint *v] + glVertexAttribI1ui: [void, GLuint index, GLuint x] + glVertexAttribI1uiv: [void, GLuint index, const GLuint *v] + glVertexAttribI2i: [void, GLuint index, GLint x, GLint y] + glVertexAttribI2iv: [void, GLuint index, const GLint *v] + glVertexAttribI2ui: [void, GLuint index, GLuint x, GLuint y] + glVertexAttribI2uiv: [void, GLuint index, const GLuint *v] + glVertexAttribI3i: [void, GLuint index, GLint x, GLint y, GLint z] + glVertexAttribI3iv: [void, GLuint index, const GLint *v] + glVertexAttribI3ui: [void, GLuint index, GLuint x, GLuint y, GLuint z] + glVertexAttribI3uiv: [void, GLuint index, const GLuint *v] + glVertexAttribI4bv: [void, GLuint index, const GLbyte *v] + glVertexAttribI4i: [void, GLuint index, GLint x, GLint y, GLint z, GLint w] + glVertexAttribI4iv: [void, GLuint index, const GLint *v] + glVertexAttribI4sv: [void, GLuint index, const GLshort *v] + glVertexAttribI4ubv: [void, GLuint index, const GLubyte *v] + glVertexAttribI4ui: [void, GLuint index, GLuint x, GLuint y, GLuint z, GLuint w] + glVertexAttribI4uiv: [void, GLuint index, const GLuint *v] + glVertexAttribI4usv: [void, GLuint index, const GLushort *v] + glVertexAttribIPointer: [void, GLuint index, GLint size, GLenum type, GLsizei stride, + const GLvoid *pointer] +VERSION_3_1: + glDrawArraysInstanced: [void, GLenum mode, GLint first, GLsizei count, GLsizei instancecount] + glDrawElementsInstanced: [void, GLenum mode, GLsizei count, GLenum type, const GLvoid + *indices, GLsizei instancecount] + glPrimitiveRestartIndex: [void, GLuint index] + glTexBuffer: [void, GLenum target, GLenum internalformat, GLuint buffer] +VERSION_3_2: + glFramebufferTexture: [void, GLenum target, GLenum attachment, GLuint texture, GLint + level] + glGetBufferParameteri64v: [void, GLenum target, GLenum pname, GLint64 *params] + glGetInteger64i_v: [void, GLenum target, GLuint index, GLint64 *data] +VERSION_3_3: + glVertexAttribDivisor: [void, GLuint index, GLuint divisor] +VERSION_4_0: + glBlendEquationSeparatei: [void, GLuint buf, GLenum modeRGB, GLenum modeAlpha] + glBlendEquationi: [void, GLuint buf, GLenum mode] + glBlendFuncSeparatei: [void, GLuint buf, GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, + GLenum dstAlpha] + glBlendFunci: [void, GLuint buf, GLenum src, GLenum dst] + glMinSampleShading: [void, GLfloat value] diff --git a/Projects/Android/jni/SupportLibs/gl4es/spec/yml/wgl.yml b/Projects/Android/jni/SupportLibs/gl4es/spec/yml/wgl.yml new file mode 100644 index 0000000..70b6d2b --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/spec/yml/wgl.yml @@ -0,0 +1,177 @@ +3DL_stereo_control: + wglSetStereoEmitterState3DL: [BOOL, HDC hDC, UINT uState] +AMD_gpu_association: + wglBlitContextFramebufferAMD: [VOID, HGLRC dstCtx, GLint srcX0, GLint srcY0, GLint + srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield + mask, GLenum filter] + wglCreateAssociatedContextAMD: [HGLRC, UINT id] + wglCreateAssociatedContextAttribsAMD: [HGLRC, UINT id, HGLRC hShareContext, const + int *attribList] + wglDeleteAssociatedContextAMD: [BOOL, HGLRC hglrc] + wglGetContextGPUIDAMD: [UINT, HGLRC hglrc] + wglGetCurrentAssociatedContextAMD: [HGLRC] + wglGetGPUIDsAMD: [UINT, UINT maxCount, UINT *ids] + wglGetGPUInfoAMD: [INT, UINT id, int property, GLenum dataType, UINT size, void + *data] + wglMakeAssociatedContextCurrentAMD: [BOOL, HGLRC hglrc] +ARB_buffer_region: + wglCreateBufferRegionARB: [HANDLE, HDC hDC, int iLayerPlane, UINT uType] + wglDeleteBufferRegionARB: [VOID, HANDLE hRegion] + wglRestoreBufferRegionARB: [BOOL, HANDLE hRegion, int x, int y, int width, int height, + int xSrc, int ySrc] + wglSaveBufferRegionARB: [BOOL, HANDLE hRegion, int x, int y, int width, int height] +ARB_create_context: + wglCreateContextAttribsARB: [HGLRC, HDC hDC, HGLRC hShareContext, const int *attribList] +ARB_extensions_string: + wglGetExtensionsStringARB: [const char *, HDC hdc] +ARB_make_current_read: + wglGetCurrentReadDCARB: [HDC] + wglMakeContextCurrentARB: [BOOL, HDC hDrawDC, HDC hReadDC, HGLRC hglrc] +ARB_pbuffer: + wglCreatePbufferARB: [HPBUFFERARB, HDC hDC, int iPixelFormat, int iWidth, int iHeight, + const int *piAttribList] + wglDestroyPbufferARB: [BOOL, HPBUFFERARB hPbuffer] + wglGetPbufferDCARB: [HDC, HPBUFFERARB hPbuffer] + wglQueryPbufferARB: [BOOL, HPBUFFERARB hPbuffer, int iAttribute, int *piValue] + wglReleasePbufferDCARB: [int, HPBUFFERARB hPbuffer, HDC hDC] +ARB_pixel_format: + wglChoosePixelFormatARB: [BOOL, HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList, + UINT nMaxFormats, int *piFormats, UINT *nNumFormats] + wglGetPixelFormatAttribfvARB: [BOOL, HDC hdc, int iPixelFormat, int iLayerPlane, + UINT nAttributes, const int *piAttributes, FLOAT *pfValues] + wglGetPixelFormatAttribivARB: [BOOL, HDC hdc, int iPixelFormat, int iLayerPlane, + UINT nAttributes, const int *piAttributes, int *piValues] +ARB_render_texture: + wglBindTexImageARB: [BOOL, HPBUFFERARB hPbuffer, int iBuffer] + wglReleaseTexImageARB: [BOOL, HPBUFFERARB hPbuffer, int iBuffer] + wglSetPbufferAttribARB: [BOOL, HPBUFFERARB hPbuffer, const int *piAttribList] +EXT_display_color_table: + wglBindDisplayColorTableEXT: [GLboolean, GLushort id] + wglCreateDisplayColorTableEXT: [GLboolean, GLushort id] + wglDestroyDisplayColorTableEXT: [VOID, GLushort id] + wglLoadDisplayColorTableEXT: [GLboolean, const GLushort *table, GLuint length] +EXT_extensions_string: + wglGetExtensionsStringEXT: [const char *] +EXT_make_current_read: + wglGetCurrentReadDCEXT: [HDC] + wglMakeContextCurrentEXT: [BOOL, HDC hDrawDC, HDC hReadDC, HGLRC hglrc] +EXT_pbuffer: + wglCreatePbufferEXT: [HPBUFFEREXT, HDC hDC, int iPixelFormat, int iWidth, int iHeight, + const int *piAttribList] + wglDestroyPbufferEXT: [BOOL, HPBUFFEREXT hPbuffer] + wglGetPbufferDCEXT: [HDC, HPBUFFEREXT hPbuffer] + wglQueryPbufferEXT: [BOOL, HPBUFFEREXT hPbuffer, int iAttribute, int *piValue] + wglReleasePbufferDCEXT: [int, HPBUFFEREXT hPbuffer, HDC hDC] +EXT_pixel_format: + wglChoosePixelFormatEXT: [BOOL, HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList, + UINT nMaxFormats, int *piFormats, UINT *nNumFormats] + wglGetPixelFormatAttribfvEXT: [BOOL, HDC hdc, int iPixelFormat, int iLayerPlane, + UINT nAttributes, int *piAttributes, FLOAT *pfValues] + wglGetPixelFormatAttribivEXT: [BOOL, HDC hdc, int iPixelFormat, int iLayerPlane, + UINT nAttributes, int *piAttributes, int *piValues] +EXT_swap_control: + wglGetSwapIntervalEXT: [int] + wglSwapIntervalEXT: [BOOL, int interval] +I3D_digital_video_control: + wglGetDigitalVideoParametersI3D: [BOOL, HDC hDC, int iAttribute, int *piValue] + wglSetDigitalVideoParametersI3D: [BOOL, HDC hDC, int iAttribute, const int *piValue] +I3D_gamma: + wglGetGammaTableI3D: [BOOL, HDC hDC, int iEntries, USHORT *puRed, USHORT *puGreen, + USHORT *puBlue] + wglGetGammaTableParametersI3D: [BOOL, HDC hDC, int iAttribute, int *piValue] + wglSetGammaTableI3D: [BOOL, HDC hDC, int iEntries, const USHORT *puRed, const USHORT + *puGreen, const USHORT *puBlue] + wglSetGammaTableParametersI3D: [BOOL, HDC hDC, int iAttribute, const int *piValue] +I3D_genlock: + wglDisableGenlockI3D: [BOOL, HDC hDC] + wglEnableGenlockI3D: [BOOL, HDC hDC] + wglGenlockSampleRateI3D: [BOOL, HDC hDC, UINT uRate] + wglGenlockSourceDelayI3D: [BOOL, HDC hDC, UINT uDelay] + wglGenlockSourceEdgeI3D: [BOOL, HDC hDC, UINT uEdge] + wglGenlockSourceI3D: [BOOL, HDC hDC, UINT uSource] + wglGetGenlockSampleRateI3D: [BOOL, HDC hDC, UINT *uRate] + wglGetGenlockSourceDelayI3D: [BOOL, HDC hDC, UINT *uDelay] + wglGetGenlockSourceEdgeI3D: [BOOL, HDC hDC, UINT *uEdge] + wglGetGenlockSourceI3D: [BOOL, HDC hDC, UINT *uSource] + wglIsEnabledGenlockI3D: [BOOL, HDC hDC, BOOL *pFlag] + wglQueryGenlockMaxSourceDelayI3D: [BOOL, HDC hDC, UINT *uMaxLineDelay, UINT *uMaxPixelDelay] +I3D_image_buffer: + wglAssociateImageBufferEventsI3D: [BOOL, HDC hDC, const HANDLE *pEvent, const LPVOID + *pAddress, const DWORD *pSize, UINT count] + wglCreateImageBufferI3D: [LPVOID, HDC hDC, DWORD dwSize, UINT uFlags] + wglDestroyImageBufferI3D: [BOOL, HDC hDC, LPVOID pAddress] + wglReleaseImageBufferEventsI3D: [BOOL, HDC hDC, const LPVOID *pAddress, UINT count] +I3D_swap_frame_lock: + wglDisableFrameLockI3D: [BOOL] + wglEnableFrameLockI3D: [BOOL] + wglIsEnabledFrameLockI3D: [BOOL, BOOL *pFlag] + wglQueryFrameLockMasterI3D: [BOOL, BOOL *pFlag] +I3D_swap_frame_usage: + wglBeginFrameTrackingI3D: [BOOL] + wglEndFrameTrackingI3D: [BOOL] + wglGetFrameUsageI3D: [BOOL, float *pUsage] + wglQueryFrameTrackingI3D: [BOOL, DWORD *pFrameCount, DWORD *pMissedFrames, float + *pLastMissedUsage] +NV_DX_interop: + wglDXCloseDeviceNV: [BOOL, HANDLE hDevice] + wglDXLockObjectsNV: [BOOL, HANDLE hDevice, GLint count, HANDLE *hObjects] + wglDXObjectAccessNV: [BOOL, HANDLE hObject, GLenum access] + wglDXOpenDeviceNV: [HANDLE, void *dxDevice] + wglDXRegisterObjectNV: [HANDLE, HANDLE hDevice, void *dxObject, GLuint name, GLenum + type, GLenum access] + wglDXSetResourceShareHandleNV: [BOOL, void *dxObject, HANDLE shareHandle] + wglDXUnlockObjectsNV: [BOOL, HANDLE hDevice, GLint count, HANDLE *hObjects] + wglDXUnregisterObjectNV: [BOOL, HANDLE hDevice, HANDLE hObject] +NV_copy_image: + wglCopyImageSubDataNV: [BOOL, HGLRC hSrcRC, GLuint srcName, GLenum srcTarget, GLint + srcLevel, GLint srcX, GLint srcY, GLint srcZ, HGLRC hDstRC, GLuint dstName, + GLenum dstTarget, GLint dstLevel, GLint dstX, GLint dstY, GLint dstZ, GLsizei + width, GLsizei height, GLsizei depth] +NV_gpu_affinity: + wglCreateAffinityDCNV: [HDC, const HGPUNV *phGpuList] + wglDeleteDCNV: [BOOL, HDC hdc] + wglEnumGpuDevicesNV: [BOOL, HGPUNV hGpu, UINT iDeviceIndex, PGPU_DEVICE lpGpuDevice] + wglEnumGpusFromAffinityDCNV: [BOOL, HDC hAffinityDC, UINT iGpuIndex, HGPUNV *hGpu] + wglEnumGpusNV: [BOOL, UINT iGpuIndex, HGPUNV *phGpu] +NV_present_video: + wglBindVideoDeviceNV: [BOOL, HDC hDC, unsigned int uVideoSlot, HVIDEOOUTPUTDEVICENV + hVideoDevice, const int *piAttribList] + wglEnumerateVideoDevicesNV: [int, HDC hDC, HVIDEOOUTPUTDEVICENV *phDeviceList] + wglQueryCurrentContextNV: [BOOL, int iAttribute, int *piValue] +NV_swap_group: + wglBindSwapBarrierNV: [BOOL, GLuint group, GLuint barrier] + wglJoinSwapGroupNV: [BOOL, HDC hDC, GLuint group] + wglQueryFrameCountNV: [BOOL, HDC hDC, GLuint *count] + wglQueryMaxSwapGroupsNV: [BOOL, HDC hDC, GLuint *maxGroups, GLuint *maxBarriers] + wglQuerySwapGroupNV: [BOOL, HDC hDC, GLuint *group, GLuint *barrier] + wglResetFrameCountNV: [BOOL, HDC hDC] +NV_vertex_array_range: + wglAllocateMemoryNV: [void *, GLsizei size, GLfloat readfreq, GLfloat writefreq, + GLfloat priority] + wglFreeMemoryNV: [void *, void *pointer] +NV_video_capture: + wglBindVideoCaptureDeviceNV: [BOOL, UINT uVideoSlot, HVIDEOINPUTDEVICENV hDevice] + wglEnumerateVideoCaptureDevicesNV: [UINT, HDC hDc, HVIDEOINPUTDEVICENV *phDeviceList] + wglLockVideoCaptureDeviceNV: [BOOL, HDC hDc, HVIDEOINPUTDEVICENV hDevice] + wglQueryVideoCaptureDeviceNV: [BOOL, HDC hDc, HVIDEOINPUTDEVICENV hDevice, int iAttribute, + int *piValue] + wglReleaseVideoCaptureDeviceNV: [BOOL, HDC hDc, HVIDEOINPUTDEVICENV hDevice] +NV_video_output: + wglBindVideoImageNV: [BOOL, HPVIDEODEV hVideoDevice, HPBUFFERARB hPbuffer, int iVideoBuffer] + wglGetVideoDeviceNV: [BOOL, HDC hDC, int numDevices, HPVIDEODEV *hVideoDevice] + wglGetVideoInfoNV: [BOOL, HPVIDEODEV hpVideoDevice, unsigned long *pulCounterOutputPbuffer, + unsigned long *pulCounterOutputVideo] + wglReleaseVideoDeviceNV: [BOOL, HPVIDEODEV hVideoDevice] + wglReleaseVideoImageNV: [BOOL, HPBUFFERARB hPbuffer, int iVideoBuffer] + wglSendPbufferToVideoNV: [BOOL, HPBUFFERARB hPbuffer, int iBufferType, unsigned + long *pulCounterPbuffer, BOOL bBlock] +OML_sync_control: + wglGetMscRateOML: [BOOL, HDC hdc, INT32 *numerator, INT32 *denominator] + wglGetSyncValuesOML: [BOOL, HDC hdc, INT64 *ust, INT64 *msc, INT64 *sbc] + wglSwapBuffersMscOML: [INT64, HDC hdc, INT64 target_msc, INT64 divisor, INT64 remainder] + wglSwapLayerBuffersMscOML: [INT64, HDC hdc, int fuPlanes, INT64 target_msc, INT64 + divisor, INT64 remainder] + wglWaitForMscOML: [BOOL, HDC hdc, INT64 target_msc, INT64 divisor, INT64 remainder, + INT64 *ust, INT64 *msc, INT64 *sbc] + wglWaitForSbcOML: [BOOL, HDC hdc, INT64 target_sbc, INT64 *ust, INT64 *msc, INT64 + *sbc] diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/CMakeLists.txt b/Projects/Android/jni/SupportLibs/gl4es/src/CMakeLists.txt new file mode 100644 index 0000000..dd102af --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/CMakeLists.txt @@ -0,0 +1,191 @@ +include_directories(util) + +#file(GLOB_RECURSE GL_SOURCES gl/*.c) +SET(GL_SRC + gl/array.c + gl/blit.c + gl/blend.c + gl/buffers.c + gl/build_info.c + gl/debug.c + gl/decompress.c + gl/depth.c + gl/directstate.c + gl/drawing.c + gl/enable.c + gl/eval.c + gl/face.c + gl/fog.c + gl/fpe.c + gl/fpe_shader.c + gl/framebuffers.c + gl/getter.c + gl/gl4es.c + gl/glstate.c + gl/hint.c + gl/init.c + gl/light.c + gl/line.c + gl/list.c + gl/listdraw.c + gl/listrl.c + gl/loader.c + gl/matrix.c + gl/matvec.c + gl/pixel.c + gl/planes.c + gl/pointsprite.c + gl/preproc.c + gl/program.c + gl/queries.c + gl/raster.c + gl/render.c + gl/shader.c + gl/shaderconv.c + gl/stack.c + gl/stencil.c + gl/string_utils.c + gl/stubs.c + gl/texenv.c + gl/texgen.c + gl/texture.c + gl/uniform.c + gl/vertexattrib.c + gl/wrap/gl4es.c + gl/wrap/gles.c + gl/wrap/glstub.c + gl/math/eval.c +) + +SET(GL_H + ../version.h + gl/array.h + gl/blend.h + gl/blit.h + gl/buffers.h + gl/build_info.h + gl/const.h + gl/debug.h + gl/decompress.h + gl/defines.h + gl/depth.h + gl/directstate.h + gl/eval.h + gl/face.h + gl/fog.h + gl/fpe.h + gl/fpe_shader.h + gl/framebuffers.h + gl/gles.h + gl/gl4es.h + gl/glstate.h + gl/hint.h + gl/init.h + gl/light.h + gl/line.h + gl/list.h + gl/loader.h + gl/logs.h + gl/matrix.h + gl/matvec.h + gl/pixel.h + gl/planes.h + gl/pointsprite.h + gl/preproc.h + gl/program.h + gl/queries.h + gl/raster.h + gl/render.h + gl/shader.h + gl/shaderconv.h + gl/stack.h + gl/state.h + gl/stencil.h + gl/stb_dxt_104.h + gl/string_utils.h + gl/texenv.h + gl/texgen.h + gl/uniform.h + gl/texture.h + gl/vertexattrib.h + gl/math/eval.h + gl/wrap/gl4es.h + gl/wrap/gles.h + gl/wrap/stub.h +) + +set_source_files_properties(gl/build_info.c PROPERTIES OBJECT_OUTPUTS "dummy.c") + +if(${CMAKE_SYSTEM_NAME} MATCHES "Linux") + include_directories(glx) +# aux_source_directory(glx GLX_SOURCES) +# list(APPEND GL_SOURCES ${GLX_SOURCES}) + list(APPEND GL_SRC + glx/hardext.c + glx/gbm.c + glx/glx.c + glx/lookup.c + glx/rpi.c + glx/streaming.c + glx/utils.c + ) + list(APPEND GL_H + glx/glx_gbm.h + glx/gbmfunc.h + glx/drmfunc.h + glx/glx.h + glx/hardext.h + glx/rpi.h + glx/streaming.h + glx/utils.h + ) +else() + message(STATUS "Not on Linux: building without GLX support.") +endif() + +if(${CMAKE_SYSTEM_NAME} MATCHES "Emscripten") + include_directories(glx) + list(APPEND GL_SRC + glx/hardext.c + ) +endif() + +if(AMIGAOS4) + include_directories(agl) + list(APPEND GL_SRC + glx/hardext.c + glx/gbm.c + glx/glx.c + glx/lookup.c + agl/amigaos.c + agl/agl.c + ) + list(APPEND GL_H + glx/hardext.h + glx/glx.h + agl/amigaos.h + agl/agl.h + ) +endif() + +if(STATICLIB) +add_library(GL STATIC ${GL_SRC}) +else() + add_library(GL SHARED ${GL_SRC}) + + if(${CMAKE_SYSTEM_NAME} MATCHES "Linux") + if(NOX11) + if(AMIGAOS4) + target_link_libraries(GL m) + else() + target_link_libraries(GL m dl) + endif() + else() + target_link_libraries(GL X11 m dl) + endif() + endif() + + if(CMAKE_SHARED_LIBRARY_SUFFIX MATCHES ".so") + set_target_properties(GL PROPERTIES SUFFIX ".so.1") + endif() +endif() diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/agl/agl.c b/Projects/Android/jni/SupportLibs/gl4es/src/agl/agl.c new file mode 100644 index 0000000..e1c5fd3 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/agl/agl.c @@ -0,0 +1,157 @@ +#include "agl.h" + +#include +#include +#include +//#include +#undef __USE_INLINE__ +#include +#include + +extern struct OGLES2IFace *IOGLES2; + +void* NewGLState(void* shared_glstate, int es2only); +void DeleteGLState(void* oldstate); +void ActivateGLState(void* new_glstate); +void GetHardwareExtensions(int notest); + +typedef struct _agl_ctx_glstate { + void* context; + void* glstate; +} agl_ctx_glstate; + +static agl_ctx_glstate *agl_context = NULL; +static int agl_context_len = 0; +static int agl_context_cap = 0; +static void* agl_current_ctx = NULL; + +// find (or add if not found) a context in the list, and activate glstate... +void agl_context_find(void* ctx) { + if(!ctx) + return; + if(!agl_context) { + agl_context_cap = 10; + agl_context = (agl_ctx_glstate*)malloc(sizeof(agl_ctx_glstate)*agl_context_cap); + memset(agl_context, 0, sizeof(agl_ctx_glstate)*agl_context_cap); + } + int idx = 0; + while (idxaglCreateContext2(errcode, tags); + return NULL; +} +void* aglCreateContext2(ULONG * errcode, struct TagItem * tags) { + return aglCreateContext(errcode, tags); +} +/* +void* VARARGS68K aglCreateContextTags(ULONG * errcode, ...) { + void* ret = NULL; + if(IOGLES2) { + struct TagItem tags[100]; + VA_LIST args; + VA_START(args, errcode); + int i = 0; + do { + struct Tagitem tag = VA_ARG(args, struct TagItem); + tags[i++] = tag; + } while (tag!=TAG_DONE); + VA_END(args); + ret = IOGLES2->aglCreateContext2(errcode, tags); + } + return ret; +} +*/ +void aglDestroyContext(void* context) { + if(IOGLES2) { + //bind the context before deleting stuffs. + if(context!=agl_current_ctx) + IOGLES2->aglMakeCurrent(context); + + agl_context_remove(context); // remove the associated glstate + + if(context!=agl_current_ctx) // rebind old context if needed + IOGLES2->aglMakeCurrent(agl_current_ctx); + IOGLES2->aglDestroyContext(context); + + } +} + +void aglMakeCurrent(void* context) { + agl_current_ctx = context; + if(IOGLES2) { + IOGLES2->aglMakeCurrent(context); + + if (context) + agl_context_find(context); // activate (and create if needed) the correct glstate + } +} + +void aglSetParams2(struct TagItem * tags) { + if(IOGLES2) { + return IOGLES2->aglSetParams2(tags); + } +} + +void amiga_pre_swap(); +void amiga_post_swap(); +void aglSwapBuffers() { + amiga_pre_swap(); + // Swap the Buffers! + if(IOGLES2) { + IOGLES2->aglSwapBuffers(); + } + amiga_post_swap(); +} + +// what is the use of this function? +void aglSetBitmap(struct BitMap *bitmap) { + if(IOGLES2) { + IOGLES2->aglSetBitmap(bitmap); + } +} + +//void* aglGetProcAddress(const char* name); //-> declared in glx/lookup.c diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/agl/agl.h b/Projects/Android/jni/SupportLibs/gl4es/src/agl/agl.h new file mode 100644 index 0000000..3917271 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/agl/agl.h @@ -0,0 +1,34 @@ +#ifndef _AGL_H_ +#define _AGL_H_ + +#ifndef EXEC_TYPES_H +#include +#endif +#ifndef EXEC_EXEC_H +#include +#endif +#ifndef EXEC_INTERFACES_H +#include +#endif + +#ifndef GRAPHICS_GFX_H +#include +#endif + +#ifndef OGLES2_OGLES2_DEFS_H +// it would be better to have an include with only the CreateContextTags enum difed, to avoid conflict +// of other typedef with full OpenGL header file... +#include +#endif + +void* aglCreateContext(ULONG * errcode, struct TagItem * tags); +void* aglCreateContext2(ULONG * errcode, struct TagItem * tags); +//void* aglCreateContextTags(ULONG * errcode, ...); +void aglDestroyContext(void* context); +void aglMakeCurrent(void* context); +void aglSwapBuffers(); +void aglSetParams2(struct TagItem * tags); +void aglSetBitmap(struct BitMap *bitmap); +void* aglGetProcAddress(const char* name); + +#endif //_AGL_H_ \ No newline at end of file diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/agl/amigaos.c b/Projects/Android/jni/SupportLibs/gl4es/src/agl/amigaos.c new file mode 100644 index 0000000..71708c2 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/agl/amigaos.c @@ -0,0 +1,798 @@ +#include "amigaos.h" + +#include +#include +#include +#include +// make sure we don't use inline version here +#undef __USE_INLINE__ +#include +#include + +#define MIN_W3DNOVA_LIB_VERSION 1 +#define MIN_W3DNOVA_LIB_REVISION 62 +#define MIN_OGLES2_LIB_VERSION 1 +#define MIN_OGLES2_LIB_REVISION 22 + +struct Library *LOGLES2 = NULL; +struct OGLES2IFace *IOGLES2 = NULL; + +// Open OGLES2 library and interface +void os4OpenLib(void** lib) +{ + // first check version for Warp3DNova lib + struct Library *Warp3DNovaBase = NULL; + Warp3DNovaBase = IExec->OpenLibrary("Warp3DNova.library", MIN_W3DNOVA_LIB_VERSION); + if(!Warp3DNovaBase) { + printf("LIBGL: Error, cannot open Warp3DNova.library!\n"); + return; + } + printf("LIBGL: Using Warp3DNova.library v%d revision %d\n", Warp3DNovaBase->lib_Version, Warp3DNovaBase->lib_Revision); + if (!(Warp3DNovaBase->lib_Version > MIN_W3DNOVA_LIB_VERSION || (Warp3DNovaBase->lib_Version == MIN_W3DNOVA_LIB_VERSION && Warp3DNovaBase->lib_Revision >= MIN_W3DNOVA_LIB_REVISION))) { + printf("LIBGL: Warning, your Warp3DNovaBase.library is too old, minimum is v%d.%d, please update!\n", MIN_W3DNOVA_LIB_VERSION,MIN_W3DNOVA_LIB_REVISION); + } + //close warp3dnova.library, we open it just for version check + IExec->CloseLibrary(Warp3DNovaBase); + Warp3DNovaBase = NULL; + + LOGLES2 = IExec->OpenLibrary("ogles2.library", MIN_OGLES2_LIB_VERSION); + if(!LOGLES2) { + printf("LIBGL: Error, cannot open ogles2 Library!\n"); + return; + } + printf("LIBGL: Using OGLES2.library v%d revision %d\n", LOGLES2->lib_Version, LOGLES2->lib_Revision); + if (!(LOGLES2->lib_Version > MIN_OGLES2_LIB_VERSION || (LOGLES2->lib_Version == MIN_OGLES2_LIB_VERSION && LOGLES2->lib_Revision >= MIN_OGLES2_LIB_REVISION))) { + printf("LIBGL: Warning, your OGLES2.library is too old, minimum is v%d.%d, please update!\n", MIN_OGLES2_LIB_VERSION,MIN_OGLES2_LIB_REVISION); + } + IOGLES2 = (struct OGLES2IFace *)IExec->GetInterface(LOGLES2, "main", 1, NULL); + if(!IOGLES2) { + printf("LIBGL: Warning, cannot open ogles2 Interface!\n"); + IExec->CloseLibrary(LOGLES2); + LOGLES2 = NULL; + return; + } + *lib = LOGLES2; + // small debug message, always helpfull at beggining + printf("LIBGL: OGLES2 Library and Interface open successfuly\n"); +} + +// Close OGLES2 lib and interface +void os4CloseLib() +{ + if(IOGLES2) { + IExec->DropInterface((struct Interface*)IOGLES2); + IOGLES2 = NULL; + } + if(LOGLES2) { + IExec->CloseLibrary(LOGLES2); + LOGLES2 = NULL; + } + printf("LIBGL: OGLES2 Library and Interface closed\n"); +} + + +static void AmiglActiveTexture (GLenum texture) { + return IOGLES2->glActiveTexture(texture); +} + +static void AmiglAttachShader (GLuint program, GLuint shader) { + return IOGLES2->glAttachShader(program, shader); +} + +static void AmiglBindAttribLocation (GLuint program, GLuint index, const GLchar *name) { + return IOGLES2->glBindAttribLocation(program, index, name); +} + +static void AmiglBindBuffer (GLenum target, GLuint buffer) { + return IOGLES2->glBindBuffer(target, buffer); +} + +static void AmiglBindFramebuffer (GLenum target, GLuint framebuffer) { + return IOGLES2->glBindFramebuffer(target, framebuffer); +} + +static void AmiglBindRenderbuffer (GLenum target, GLuint renderbuffer) { + return IOGLES2->glBindRenderbuffer(target, renderbuffer); +} + +static void AmiglBindTexture (GLenum target, GLuint texture) { + return IOGLES2->glBindTexture(target, texture); +} + +static void AmiglBlendColor (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) { + return IOGLES2->glBlendColor(red, green, blue, alpha); +} + +static void AmiglBlendEquation (GLenum mode) { + return IOGLES2->glBlendEquation(mode); +} + +static void AmiglBlendEquationSeparate (GLenum modeRGB, GLenum modeAlpha) { + return IOGLES2->glBlendEquationSeparate(modeRGB, modeAlpha); +} + +static void AmiglBlendFunc (GLenum sfactor, GLenum dfactor) { + return IOGLES2->glBlendFunc(sfactor, dfactor); +} + +static void AmiglBlendFuncSeparate (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha) { + return IOGLES2->glBlendFuncSeparate(sfactorRGB, dfactorRGB, sfactorAlpha, dfactorAlpha); +} + +static void AmiglBufferData (GLenum target, GLsizeiptr size, const void *data, GLenum usage) { + return IOGLES2->glBufferData(target, size, data, usage); +} + +static void AmiglBufferSubData (GLenum target, GLintptr offset, GLsizeiptr size, const void *data) { + return IOGLES2->glBufferSubData(target, offset, size, data); +} + +static GLenum AmiglCheckFramebufferStatus (GLenum target) { + return IOGLES2->glCheckFramebufferStatus(target); +} + +static void AmiglClear (GLbitfield mask) { + return IOGLES2->glClear(mask); +} + +static void AmiglClearColor (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) { + return IOGLES2->glClearColor(red, green, blue, alpha); +} + +static void AmiglClearDepthf (GLfloat d) { + return IOGLES2->glClearDepthf(d); +} + +static void AmiglClearStencil (GLint s) { + return IOGLES2->glClearStencil(s); +} + +static void AmiglColorMask (GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha) { + return IOGLES2->glColorMask(red, green, blue, alpha); +} + +static void AmiglCompileShader (GLuint shader) { + return IOGLES2->glCompileShader(shader); +} + +static void AmiglCompressedTexImage2D (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const void *data) { + return IOGLES2->glCompressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data); +} + +static void AmiglCompressedTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *data) { + return IOGLES2->glCompressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize, data); +} + +static void AmiglCopyTexImage2D (GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border) { + return IOGLES2->glCopyTexImage2D(target, level, internalformat, x, y, width, height, border); +} + +static void AmiglCopyTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height) { + return IOGLES2->glCopyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height); +} + +static GLuint AmiglCreateProgram (void) { + return IOGLES2->glCreateProgram(); +} + +static GLuint AmiglCreateShader (GLenum type) { + return IOGLES2->glCreateShader(type); +} + +static void AmiglCullFace (GLenum mode) { + return IOGLES2->glCullFace(mode); +} + +static void AmiglDeleteBuffers (GLsizei n, const GLuint *buffers) { + return IOGLES2->glDeleteBuffers(n, buffers); +} + +static void AmiglDeleteFramebuffers (GLsizei n, const GLuint *framebuffers) { + return IOGLES2->glDeleteFramebuffers(n, framebuffers); +} + +static void AmiglDeleteProgram (GLuint program) { + return IOGLES2->glDeleteProgram(program); +} + +static void AmiglDeleteRenderbuffers (GLsizei n, const GLuint *renderbuffers) { + return IOGLES2->glDeleteRenderbuffers(n, renderbuffers); +} + +static void AmiglDeleteShader (GLuint shader) { + return IOGLES2->glDeleteShader(shader); +} + +static void AmiglDeleteTextures (GLsizei n, const GLuint *textures) { + return IOGLES2->glDeleteTextures(n, textures); +} + +static void AmiglDepthFunc (GLenum func) { + return IOGLES2->glDepthFunc(func); +} + +static void AmiglDepthMask (GLboolean flag) { + return IOGLES2->glDepthMask(flag); +} + +static void AmiglDepthRangef (GLfloat n, GLfloat f) { + return IOGLES2->glDepthRangef(n, f); +} + +static void AmiglDetachShader (GLuint program, GLuint shader) { + return IOGLES2->glDetachShader(program, shader); +} + +static void AmiglDisable (GLenum cap) { + return IOGLES2->glDisable(cap); +} + +static void AmiglDisableVertexAttribArray (GLuint index) { + return IOGLES2->glDisableVertexAttribArray(index); +} + +static void AmiglDrawArrays (GLenum mode, GLint first, GLsizei count) { + return IOGLES2->glDrawArrays(mode, first, count); +} + +static void AmiglDrawElements (GLenum mode, GLsizei count, GLenum type, const void *indices) { + return IOGLES2->glDrawElements(mode, count, type, indices); +} + +static void AmiglEnable (GLenum cap) { + return IOGLES2->glEnable(cap); +} + +static void AmiglEnableVertexAttribArray (GLuint index) { + return IOGLES2->glEnableVertexAttribArray(index); +} + +static void AmiglFinish (void) { + return IOGLES2->glFinish(); +} + +static void AmiglFlush (void) { + return IOGLES2->glFlush(); +} + +static void AmiglFramebufferRenderbuffer (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer) { + return IOGLES2->glFramebufferRenderbuffer(target, attachment, renderbuffertarget, renderbuffer); +} + +static void AmiglFramebufferTexture2D (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level) { + return IOGLES2->glFramebufferTexture2D(target, attachment, textarget, texture, level); +} + +static void AmiglFrontFace (GLenum mode) { + return IOGLES2->glFrontFace(mode); +} + +static void AmiglGenBuffers (GLsizei n, GLuint *buffers) { + return IOGLES2->glGenBuffers(n, buffers); +} + +static void AmiglGenerateMipmap (GLenum target) { + return IOGLES2->glGenerateMipmap(target); +} + +static void AmiglGenFramebuffers (GLsizei n, GLuint *framebuffers) { + return IOGLES2->glGenFramebuffers(n, framebuffers); +} + +static void AmiglGenRenderbuffers (GLsizei n, GLuint *renderbuffers) { + return IOGLES2->glGenRenderbuffers(n, renderbuffers); +} + +static void AmiglGenTextures (GLsizei n, GLuint *textures) { + return IOGLES2->glGenTextures(n, textures); +} + +static void AmiglGetActiveAttrib (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name) { + return IOGLES2->glGetActiveAttrib(program, index, bufSize, length, size, type, name); +} + +static void AmiglGetActiveUniform (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name) { + return IOGLES2->glGetActiveUniform(program, index, bufSize, length, size, type, name); +} + +static void AmiglGetAttachedShaders (GLuint program, GLsizei maxCount, GLsizei *count, GLuint *shaders) { + return IOGLES2->glGetAttachedShaders(program, maxCount, count, shaders); +} + +static GLint AmiglGetAttribLocation (GLuint program, const GLchar *name) { + return IOGLES2->glGetAttribLocation(program, name); +} + +static void AmiglGetBooleanv (GLenum pname, GLboolean *data) { + return IOGLES2->glGetBooleanv(pname, data); +} + +static void AmiglGetBufferParameteriv (GLenum target, GLenum pname, GLint *params) { + return IOGLES2->glGetBufferParameteriv(target, pname, params); +} + +static GLenum AmiglGetError (void) { + return IOGLES2->glGetError(); +} + +static void AmiglGetFloatv (GLenum pname, GLfloat *data) { + return IOGLES2->glGetFloatv(pname, data); +} + +static void AmiglGetFramebufferAttachmentParameteriv (GLenum target, GLenum attachment, GLenum pname, GLint *params) { + return IOGLES2->glGetFramebufferAttachmentParameteriv(target, attachment, pname, params); +} + +static void AmiglGetIntegerv (GLenum pname, GLint *data) { + return IOGLES2->glGetIntegerv(pname, data); +} + +static void AmiglGetProgramiv (GLuint program, GLenum pname, GLint *params) { + return IOGLES2->glGetProgramiv(program, pname, params); +} + +static void AmiglGetProgramInfoLog (GLuint program, GLsizei bufSize, GLsizei *length, GLchar *infoLog) { + return IOGLES2->glGetProgramInfoLog(program, bufSize, length, infoLog); +} + +static void AmiglGetRenderbufferParameteriv (GLenum target, GLenum pname, GLint *params) { + return IOGLES2->glGetRenderbufferParameteriv(target, pname, params); +} + +static void AmiglGetShaderiv (GLuint shader, GLenum pname, GLint *params) { + return IOGLES2->glGetShaderiv(shader, pname, params); +} + +static void AmiglGetShaderInfoLog (GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *infoLog) { + return IOGLES2->glGetShaderInfoLog(shader, bufSize, length, infoLog); +} + +static void AmiglGetShaderPrecisionFormat (GLenum shadertype, GLenum precisiontype, GLint *range, GLint *precision) { + return IOGLES2->glGetShaderPrecisionFormat(shadertype, precisiontype, range, precision); +} + +static void AmiglGetShaderSource (GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *source) { + return IOGLES2->glGetShaderSource(shader, bufSize, length, source); +} + +static const GLubyte *AmiglGetString (GLenum name) { + return IOGLES2->glGetString(name); +} + +static void AmiglGetTexParameterfv (GLenum target, GLenum pname, GLfloat *params) { + return IOGLES2->glGetTexParameterfv(target, pname, params); +} + +static void AmiglGetTexParameteriv (GLenum target, GLenum pname, GLint *params) { + return IOGLES2->glGetTexParameteriv(target, pname, params); +} + +static void AmiglGetUniformfv (GLuint program, GLint location, GLfloat *params) { + return IOGLES2->glGetUniformfv(program, location, params); +} + +static void AmiglGetUniformiv (GLuint program, GLint location, GLint *params) { + return IOGLES2->glGetUniformiv(program, location, params); +} + +static GLint AmiglGetUniformLocation (GLuint program, const GLchar *name) { + return IOGLES2->glGetUniformLocation(program, name); +} + +static void AmiglGetVertexAttribfv (GLuint index, GLenum pname, GLfloat *params) { + return IOGLES2->glGetVertexAttribfv(index, pname, params); +} + +static void AmiglGetVertexAttribiv (GLuint index, GLenum pname, GLint *params) { + return IOGLES2->glGetVertexAttribiv(index, pname, params); +} + +static void AmiglGetVertexAttribPointerv (GLuint index, GLenum pname, void **pointer) { + return IOGLES2->glGetVertexAttribPointerv(index, pname, pointer); +} + +static void AmiglHint (GLenum target, GLenum mode) { + return IOGLES2->glHint(target, mode); +} + +static GLboolean AmiglIsBuffer (GLuint buffer) { + return IOGLES2->glIsBuffer(buffer); +} + +static GLboolean AmiglIsEnabled (GLenum cap) { + return IOGLES2->glIsEnabled(cap); +} + +static GLboolean AmiglIsFramebuffer (GLuint framebuffer) { + return IOGLES2->glIsFramebuffer(framebuffer); +} + +static GLboolean AmiglIsProgram (GLuint program) { + return IOGLES2->glIsProgram(program); +} + +static GLboolean AmiglIsRenderbuffer (GLuint renderbuffer) { + return IOGLES2->glIsRenderbuffer(renderbuffer); +} + +static GLboolean AmiglIsShader (GLuint shader) { + return IOGLES2->glIsShader(shader); +} + +static GLboolean AmiglIsTexture (GLuint texture) { + return IOGLES2->glIsTexture(texture); +} + +static void AmiglLineWidth (GLfloat width) { + return IOGLES2->glLineWidth(width); +} + +static void AmiglLinkProgram (GLuint program) { + return IOGLES2->glLinkProgram(program); +} + +static void AmiglPixelStorei (GLenum pname, GLint param) { + return IOGLES2->glPixelStorei(pname, param); +} + +static void AmiglPolygonOffset (GLfloat factor, GLfloat units) { + return IOGLES2->glPolygonOffset(factor, units); +} + +static void AmiglReadPixels (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void *pixels) { + return IOGLES2->glReadPixels(x, y, width, height, format, type, pixels); +} + +static void AmiglReleaseShaderCompiler (void) { + return IOGLES2->glReleaseShaderCompiler(); +} + +static void AmiglRenderbufferStorage (GLenum target, GLenum internalformat, GLsizei width, GLsizei height) { + return IOGLES2->glRenderbufferStorage(target, internalformat, width, height); +} + +static void AmiglSampleCoverage (GLfloat value, GLboolean invert) { + return IOGLES2->glSampleCoverage(value, invert); +} + +static void AmiglScissor (GLint x, GLint y, GLsizei width, GLsizei height) { + return IOGLES2->glScissor(x, y, width, height); +} + +static void AmiglShaderBinary (GLsizei count, const GLuint *shaders, GLenum binaryformat, const void *binary, GLsizei length) { + return IOGLES2->glShaderBinary(count, shaders, binaryformat, binary, length); +} + +static void AmiglShaderSource (GLuint shader, GLsizei count, const GLchar *const*string, const GLint *length) { + return IOGLES2->glShaderSource(shader, count, string, length); +} + +static void AmiglStencilFunc (GLenum func, GLint ref, GLuint mask) { + return IOGLES2->glStencilFunc(func, ref, mask); +} + +static void AmiglStencilFuncSeparate (GLenum face, GLenum func, GLint ref, GLuint mask) { + return IOGLES2->glStencilFuncSeparate(face, func, ref, mask); +} + +static void AmiglStencilMask (GLuint mask) { + return IOGLES2->glStencilMask(mask); +} + +static void AmiglStencilMaskSeparate (GLenum face, GLuint mask) { + return IOGLES2->glStencilMaskSeparate(face, mask); +} + +static void AmiglStencilOp (GLenum fail, GLenum zfail, GLenum zpass) { + return IOGLES2->glStencilOp(fail, zfail, zpass); +} + +static void AmiglStencilOpSeparate (GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass) { + return IOGLES2->glStencilOpSeparate(face, sfail, dpfail, dppass); +} + +static void AmiglTexImage2D (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void *pixels) { + return IOGLES2->glTexImage2D(target, level, internalformat, width, height, border, format, type, pixels); +} + +static void AmiglTexParameterf (GLenum target, GLenum pname, GLfloat param) { + return IOGLES2->glTexParameterf(target, pname, param); +} + +static void AmiglTexParameterfv (GLenum target, GLenum pname, const GLfloat *params) { + return IOGLES2->glTexParameterfv(target, pname, params); +} + +static void AmiglTexParameteri (GLenum target, GLenum pname, GLint param) { + return IOGLES2->glTexParameteri(target, pname, param); +} + +static void AmiglTexParameteriv (GLenum target, GLenum pname, const GLint *params) { + return IOGLES2->glTexParameteriv(target, pname, params); +} + +static void AmiglTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *pixels) { + return IOGLES2->glTexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels); +} + +static void AmiglUniform1f (GLint location, GLfloat v0) { + return IOGLES2->glUniform1f(location, v0); +} + +static void AmiglUniform1fv (GLint location, GLsizei count, const GLfloat *value) { + return IOGLES2->glUniform1fv(location, count, value); +} + +static void AmiglUniform1i (GLint location, GLint v0) { + return IOGLES2->glUniform1i(location, v0); +} + +static void AmiglUniform1iv (GLint location, GLsizei count, const GLint *value) { + return IOGLES2->glUniform1iv(location, count, value); +} + +static void AmiglUniform2f (GLint location, GLfloat v0, GLfloat v1) { + return IOGLES2->glUniform2f(location, v0, v1); +} + +static void AmiglUniform2fv (GLint location, GLsizei count, const GLfloat *value) { + return IOGLES2->glUniform2fv(location, count, value); +} + +static void AmiglUniform2i (GLint location, GLint v0, GLint v1) { + return IOGLES2->glUniform2i(location, v0, v1); +} + +static void AmiglUniform2iv (GLint location, GLsizei count, const GLint *value) { + return IOGLES2->glUniform2iv(location, count, value); +} + +static void AmiglUniform3f (GLint location, GLfloat v0, GLfloat v1, GLfloat v2) { + return IOGLES2->glUniform3f(location, v0, v1, v2); +} + +static void AmiglUniform3fv (GLint location, GLsizei count, const GLfloat *value) { + return IOGLES2->glUniform3fv(location, count, value); +} + +static void AmiglUniform3i (GLint location, GLint v0, GLint v1, GLint v2) { + return IOGLES2->glUniform3i(location, v0, v1, v2); +} + +static void AmiglUniform3iv (GLint location, GLsizei count, const GLint *value) { + return IOGLES2->glUniform3iv(location, count, value); +} + +static void AmiglUniform4f (GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3) { + return IOGLES2->glUniform4f(location, v0, v1, v2, v3); +} + +static void AmiglUniform4fv (GLint location, GLsizei count, const GLfloat *value) { + return IOGLES2->glUniform4fv(location, count, value); +} + +static void AmiglUniform4i (GLint location, GLint v0, GLint v1, GLint v2, GLint v3) { + return IOGLES2->glUniform4i(location, v0, v1, v2, v3); +} + +static void AmiglUniform4iv (GLint location, GLsizei count, const GLint *value) { + return IOGLES2->glUniform4iv(location, count, value); +} + +static void AmiglUniformMatrix2fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) { + return IOGLES2->glUniformMatrix2fv(location, count, transpose, value); +} + +static void AmiglUniformMatrix3fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) { + return IOGLES2->glUniformMatrix3fv(location, count, transpose, value); +} + +static void AmiglUniformMatrix4fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) { + return IOGLES2->glUniformMatrix4fv(location, count, transpose, value); +} + +static void AmiglUseProgram (GLuint program) { + return IOGLES2->glUseProgram(program); +} + +static void AmiglValidateProgram (GLuint program) { + return IOGLES2->glValidateProgram(program); +} + +static void AmiglVertexAttrib1f (GLuint index, GLfloat x) { + return IOGLES2->glVertexAttrib1f(index, x); +} + +static void AmiglVertexAttrib1fv (GLuint index, const GLfloat *v) { + return IOGLES2->glVertexAttrib1fv(index, v); +} + +static void AmiglVertexAttrib2f (GLuint index, GLfloat x, GLfloat y) { + return IOGLES2->glVertexAttrib2f(index, x, y); +} + +static void AmiglVertexAttrib2fv (GLuint index, const GLfloat *v) { + return IOGLES2->glVertexAttrib2fv(index, v); +} + +static void AmiglVertexAttrib3f (GLuint index, GLfloat x, GLfloat y, GLfloat z) { + return IOGLES2->glVertexAttrib3f(index, x, y, z); +} + +static void AmiglVertexAttrib3fv (GLuint index, const GLfloat *v) { + return IOGLES2->glVertexAttrib3fv(index, v); +} + +static void AmiglVertexAttrib4f (GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w) { + return IOGLES2->glVertexAttrib4f(index, x, y, z, w); +} + +static void AmiglVertexAttrib4fv (GLuint index, const GLfloat *v) { + return IOGLES2->glVertexAttrib4fv(index, v); +} + +static void AmiglVertexAttribPointer (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void *pointer) { + return IOGLES2->glVertexAttribPointer(index, size, type, normalized, stride, pointer); +} + +static void AmiglViewport (GLint x, GLint y, GLsizei width, GLsizei height) { + return IOGLES2->glViewport(x, y, width, height); +} + +// Using glXXX name, return the function pointer of that function in ogles2 library +#define MAP(func_name, func) \ + if (strcmp(name, func_name) == 0) return (void *)Ami##func; + +#define EX(func_name) MAP(#func_name, func_name) + +void* os4GetProcAddress(const char* name) +{ + if(!IOGLES2) + return NULL; + // All GL functions from OGLES2 drivers + EX(glActiveTexture) + EX(glAttachShader) + EX(glBindAttribLocation) + EX(glBindBuffer) + EX(glBindFramebuffer) + EX(glBindRenderbuffer) + EX(glBindTexture) + EX(glBlendColor) + EX(glBlendEquation) + EX(glBlendEquationSeparate) + EX(glBlendFunc) + EX(glBlendFuncSeparate) + EX(glBufferData) + EX(glBufferSubData) + EX(glCheckFramebufferStatus) + EX(glClear) + EX(glClearColor) + EX(glClearDepthf) + EX(glClearStencil) + EX(glColorMask) + EX(glCompileShader) + EX(glCompressedTexImage2D) + EX(glCompressedTexSubImage2D) + EX(glCopyTexImage2D) + EX(glCopyTexSubImage2D) + EX(glCreateProgram) + EX(glCreateShader) + EX(glCullFace) + EX(glDeleteBuffers) + EX(glDeleteFramebuffers) + EX(glDeleteProgram) + EX(glDeleteRenderbuffers) + EX(glDeleteShader) + EX(glDeleteTextures) + EX(glDepthFunc) + EX(glDepthMask) + EX(glDepthRangef) + EX(glDetachShader) + EX(glDisable) + EX(glDisableVertexAttribArray) + EX(glDrawArrays) + EX(glDrawElements) + EX(glEnable) + EX(glEnableVertexAttribArray) + EX(glFinish) + EX(glFlush) + EX(glFramebufferRenderbuffer) + EX(glFramebufferTexture2D) + EX(glFrontFace) + EX(glGenBuffers) + EX(glGenerateMipmap) + EX(glGenFramebuffers) + EX(glGenRenderbuffers) + EX(glGenTextures) + EX(glGetActiveAttrib) + EX(glGetActiveUniform) + EX(glGetAttachedShaders) + EX(glGetAttribLocation) + EX(glGetBooleanv) + EX(glGetBufferParameteriv) + EX(glGetError) + EX(glGetFloatv) + EX(glGetFramebufferAttachmentParameteriv) + EX(glGetIntegerv) + EX(glGetProgramiv) + EX(glGetProgramInfoLog) + EX(glGetRenderbufferParameteriv) + EX(glGetShaderiv) + EX(glGetShaderInfoLog) + EX(glGetShaderPrecisionFormat) + EX(glGetShaderSource) + EX(glGetString) + EX(glGetTexParameterfv) + EX(glGetTexParameteriv) + EX(glGetUniformfv) + EX(glGetUniformiv) + EX(glGetUniformLocation) + EX(glGetVertexAttribfv) + EX(glGetVertexAttribiv) + EX(glGetVertexAttribPointerv) + EX(glHint) + EX(glIsBuffer) + EX(glIsEnabled) + EX(glIsFramebuffer) + EX(glIsProgram) + EX(glIsRenderbuffer) + EX(glIsShader) + EX(glIsTexture) + EX(glLineWidth) + EX(glLinkProgram) + EX(glPixelStorei) + EX(glPolygonOffset) + EX(glReadPixels) + EX(glReleaseShaderCompiler) + EX(glRenderbufferStorage) + EX(glSampleCoverage) + EX(glScissor) + EX(glShaderBinary) + EX(glShaderSource) + EX(glStencilFunc) + EX(glStencilFuncSeparate) + EX(glStencilMask) + EX(glStencilMaskSeparate) + EX(glStencilOp) + EX(glStencilOpSeparate) + EX(glTexImage2D) + EX(glTexParameterf) + EX(glTexParameterfv) + EX(glTexParameteri) + EX(glTexParameteriv) + EX(glTexSubImage2D) + EX(glUniform1f) + EX(glUniform1fv) + EX(glUniform1i) + EX(glUniform1iv) + EX(glUniform2f) + EX(glUniform2fv) + EX(glUniform2i) + EX(glUniform2iv) + EX(glUniform3f) + EX(glUniform3fv) + EX(glUniform3i) + EX(glUniform3iv) + EX(glUniform4f) + EX(glUniform4fv) + EX(glUniform4i) + EX(glUniform4iv) + EX(glUniformMatrix2fv) + EX(glUniformMatrix3fv) + EX(glUniformMatrix4fv) + EX(glUseProgram) + EX(glValidateProgram) + EX(glVertexAttrib1f) + EX(glVertexAttrib1fv) + EX(glVertexAttrib2f) + EX(glVertexAttrib2fv) + EX(glVertexAttrib3f) + EX(glVertexAttrib3fv) + EX(glVertexAttrib4f) + EX(glVertexAttrib4fv) + EX(glVertexAttribPointer) + EX(glViewport) + //EX(glPolygonMode) //This is a non-standard function, and gl4es will ignore it (and emulate it), even if Amiga OGLES2 driver implement it + + return NULL; +} \ No newline at end of file diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/agl/amigaos.h b/Projects/Android/jni/SupportLibs/gl4es/src/agl/amigaos.h new file mode 100644 index 0000000..bb1ccde --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/agl/amigaos.h @@ -0,0 +1,9 @@ +#ifndef _AMIGAOS_H_ +#define _AMIGAOS_H_ + +void* os4GetProcAddress(const char* name); + +void os4OpenLib(void** lib); +void os4CloseLib(); + +#endif //_AMIGAOS_H_ \ No newline at end of file diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/config.h b/Projects/Android/jni/SupportLibs/gl4es/src/config.h new file mode 100644 index 0000000..fee0c5e --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/config.h @@ -0,0 +1,16 @@ +#ifndef _GL4ES_MAIN_CONFIG_H +#define _GL4ES_MAIN_CONFIG_H + +#define SYS_proxy 9999 +#define MAX_EVAL_ORDER 30 +#define MAX_TEX 8 +#define MAX_LIGHT 8 +#define MAX_STACK_PROJECTION 16 +#define MAX_STACK_TEXTURE 16 +#define MAX_STACK_MODELVIEW 64 +#define MAX_STACK_COLOR 16 +#define MAX_CLIP_PLANES 6 +#define MAX_VATTRIB 32 +#define MAX_MAP_SIZE 256 + +#endif // _GL4ES_MAIN_CONFIG_H diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/array.c b/Projects/Android/jni/SupportLibs/gl4es/src/gl/array.c new file mode 100644 index 0000000..a9cf42a --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/array.c @@ -0,0 +1,469 @@ +#include "array.h" + +#include "debug.h" +#include "enum_info.h" +#include "glcase.h" +#include "light.h" +#include "state.h" + +GLvoid *copy_gl_array(const GLvoid *src, + GLenum from, GLsizei width, GLsizei stride, + GLenum to, GLsizei to_width, GLsizei skip, GLsizei count) { + if (! src || !count) + return NULL; + + if (! stride) + stride = width * gl_sizeof(from); + + const char *unknown_str = "LIBGL: copy_gl_array -> unknown type: %x\n"; + GLvoid *dst = malloc((count-skip) * to_width * gl_sizeof(to)); + GLsizei from_size = gl_sizeof(from) * width; + if (to_width < width) { +/* printf("Warning: copy_gl_array: %i < %i\n", to_width, width); + return NULL;*/ + width = to_width; + } + // quick path if just copying same to same and no specific stride involved + if(stride == (to_width*gl_sizeof(to)) && width==to_width && from==to) { + memcpy(dst, (char*)src + stride*skip, (count-skip) * to_width * gl_sizeof(to)); + return dst; + } + + // if stride is weird, we need to be able to arbitrarily shift src + // so we leave it in a uintptr_t and cast after incrementing + uintptr_t in = (uintptr_t)src; + in += stride*skip; + if (from == to && to_width >= width) { + GL_TYPE_SWITCH(out, dst, to, + for (int i = skip; i < count; i++) { + memcpy(out, (GLvoid *)in, from_size); + for (int j = width; j < to_width; j++) { + out[j] = 0; + } + out += to_width; + in += stride; + }, + default: + printf(unknown_str, from); + return NULL; + ) + } else { + GL_TYPE_SWITCH(out, dst, to, + for (int i = skip; i < count; i++) { + GL_TYPE_SWITCH(input, in, from, + for (int j = 0; j < width; j++) { + out[j] = input[j]; + } + for (int j = width; j < to_width; j++) { + out[j] = 0; + } + out += to_width; + in += stride; + , + default: + printf(unknown_str, from); + return NULL; + ) + }, + default: + printf(unknown_str, to); + return NULL; + ) + } + + return dst; +} + +GLvoid *copy_gl_array_texcoord(const GLvoid *src, + GLenum from, GLsizei width, GLsizei stride, + GLenum to, GLsizei to_width, GLsizei skip, GLsizei count, GLvoid* filler, void* dest) { + if (! src || !count) + return NULL; + + if (! stride) + stride = width * gl_sizeof(from); + + const char *unknown_str = "LIBGL: copy_gl_array -> unknown type: %x\n"; + GLvoid *dst = (dest)?dest:malloc((count-skip) * to_width * gl_sizeof(to)); + GLsizei from_size = gl_sizeof(from) * width; + GLsizei to_elem = gl_sizeof(to); + uintptr_t in = (uintptr_t)src; + in += stride*skip; + if (from == to && to_width >= width) { + GL_TYPE_SWITCH(out, dst, to, + for (int i = skip; i < count; i++) { + memcpy(out, (GLvoid *)in, from_size); + for (int j = width; j < to_width; j++) { + if(j==to_width-1) + memcpy(out+j, filler, to_elem); + else + out[j] = 0; + } + out += to_width; + in += stride; + }, + default: + printf(unknown_str, from); + return NULL; + ) + } else { + GL_TYPE_SWITCH(out, dst, to, + for (int i = skip; i < count; i++) { + GL_TYPE_SWITCH(input, in, from, + for (int j = 0; j < width; j++) { + out[j] = input[j]; + } + for (int j = width; j < to_width; j++) { + if(j==3) + memcpy(out+j, filler, to_elem); + else + out[j] = 0; + } + out += to_width; + in += stride; + , + default: + printf(unknown_str, from); + return NULL; + ) + }, + default: + printf(unknown_str, to); + return NULL; + ) + } + + return dst; +} + +GLvoid *copy_gl_array_quickconvert(const GLvoid *src, + GLenum from, GLsizei stride, + GLsizei skip, GLsizei count) { + + if (! stride) + stride = 4 * gl_sizeof(from); + const char *unknown_str = "LIBGL: copy_gl_array_quickconvert -> unknown type: %x\n"; + GLvoid *dst = malloc((count-skip) * 4 * gl_sizeof(GL_FLOAT)); + + uintptr_t in = (uintptr_t)src; + in += stride*skip; + int j; + + GLfloat *out = (GLfloat*)dst; + GL_TYPE_SWITCH2(input, in, from, + const GLfloat maxf = 1.0f/gl_max_value(from); + for (int i = skip; i < count; i++) + , + for (j = 0; j < 4; j++) { + out[j] = ((GLfloat)input[j])*maxf; + } + out += 4; + in += stride; + , + default: + printf(unknown_str, from); + return NULL; + ) + return dst; +} + +GLvoid *copy_gl_array_convert(const GLvoid *src, + GLenum from, GLsizei width, GLsizei stride, + GLenum to, GLsizei to_width, GLsizei skip, GLsizei count, GLvoid* filler) { + if (! src || !count) + return NULL; + + if(to==GL_FLOAT && width==to_width && width==4) + return copy_gl_array_quickconvert(src, from, stride, skip, count); + + if (! stride) + stride = width * gl_sizeof(from); + const char *unknown_str = "LIBGL: copy_gl_array_convert -> unknown type: %x\n"; + GLvoid *dst = malloc((count-skip) * to_width * gl_sizeof(to)); + GLsizei from_size = gl_sizeof(from) * width; + if (to_width < width) { + /*printf("Warning: copy_gl_array: %i < %i\n", to_width, width); + return NULL;*/ + width = to_width; + } + + // if stride is weird, we need to be able to arbitrarily shift src + // so we leave it in a uintptr_t and cast after incrementing + uintptr_t in = (uintptr_t)src; + in += stride*skip; + int j; + if (from == to && to_width >= width) { + GL_TYPE_SWITCH(out, dst, to, + for (int i = skip; i < count; i++) { + memcpy(out, (GLvoid *)in, from_size); + for (j = width; j < to_width-1; j++) { + out[j]=0; + } + for (; j < to_width; j++) { + memcpy(&out[j], filler, gl_sizeof(to)); + } + out += to_width; + in += stride; + }, + default: + printf(unknown_str, from); + return NULL; + ) + } else { + GL_TYPE_SWITCH_MAX(out, dst, to, + GL_TYPE_SWITCH2(input, in, from, + const GLuint maxf = gl_max_value(from); + for (int i = skip; i < count; i++) + , + for (j = 0; j < width; j++) { + out[j] = input[j]*maxv/maxf; + } + for (; j < to_width-1; j++) { + out[j]=0; + } + for (; j < to_width; j++) { + memcpy(&out[j], filler, gl_sizeof(to)); + } + out += to_width; + in += stride; + , + default: + printf(unknown_str, from); + return NULL; + ), + default: + printf(unknown_str, to); + return NULL; + ) + } + + return dst; +} + +GLvoid *copy_gl_pointer(pointer_state_t *ptr, GLsizei width, GLsizei skip, GLsizei count) { + float filler = 0.0f; + return copy_gl_array_convert(ptr->pointer, ptr->type, ptr->size, ptr->stride, + GL_FLOAT, width, skip, count, &filler); +} +GLvoid *copy_gl_pointer_color(pointer_state_t *ptr, GLsizei width, GLsizei skip, GLsizei count) { + float filler = 1.0f; + return copy_gl_array_convert(ptr->pointer, ptr->type, ptr->size, ptr->stride, + GL_FLOAT, width, skip, count, &filler); +} +GLvoid *copy_gl_pointer_bytecolor(pointer_state_t *ptr, GLsizei width, GLsizei skip, GLsizei count) { + GLubyte filler = 255; + return copy_gl_array_convert(ptr->pointer, ptr->type, ptr->size, ptr->stride, + GL_UNSIGNED_BYTE, width, skip, count, &filler); +} + +GLvoid *copy_gl_pointer_raw(pointer_state_t *ptr, GLsizei width, GLsizei skip, GLsizei count) { + return copy_gl_array(ptr->pointer, ptr->type, ptr->size, ptr->stride, + GL_FLOAT, width, skip, count); +} + +GLvoid *copy_gl_pointer_tex(pointer_state_t *ptr, GLsizei width, GLsizei skip, GLsizei count) { + float filler = 1.0f; + return copy_gl_array_texcoord(ptr->pointer, ptr->type, ptr->size, ptr->stride, + GL_FLOAT, width, skip, count, &filler, 0); +} + +void copy_gl_pointer_tex_noalloc(void* dest, pointer_state_t *ptr, GLsizei width, GLsizei skip, GLsizei count) { + float filler = 1.0f; + copy_gl_array_texcoord(ptr->pointer, ptr->type, ptr->size, ptr->stride, + GL_FLOAT, width, skip, count, &filler, dest); +} + +GLfloat *gl_pointer_index(pointer_state_t *p, GLint index) { + static GLfloat buf[4]; + GLsizei size = gl_sizeof(p->type); + GLsizei stride = p->stride ? p->stride : (size * p->size); + uintptr_t ptr = (uintptr_t)(p->pointer) + (stride * index); + + GL_TYPE_SWITCH(src, ptr, p->type, + for (int i = 0; i < p->size; i++) { + buf[i] = src[i]; + } + // zero anything not set by the pointer + for (int i = p->size; i < 4; i++) { + buf[i] = 0; + }, + default: + printf("LIBGL: unknown pointer type: 0x%x\n", p->type); + ) + return buf; +} + + +GLfloat *copy_eval_double1(GLenum target, GLint ustride, GLint uorder, + const GLdouble *src) { + + GLsizei width = get_map_width(target); + GLfloat* out; + + if(!src || !width) + return NULL; + + out = malloc(uorder*width*sizeof(GLfloat)); + + GLfloat *p = out; + + for (int i=0; i vorder ? uorder : vorder)*width; + + if(hsize>dsize) + out = malloc((uorder*vorder*width+hsize)*sizeof(GLfloat)); + else + out = malloc((uorder*vorder*width+dsize)*sizeof(GLfloat)); + + int uinc = ustride - vorder*vstride; + GLfloat* p = out; + + for (int i=0; i vorder ? uorder : vorder)*width; + + if(hsize>dsize) + out = malloc((uorder*vorder*width+hsize)*sizeof(GLfloat)); + else + out = malloc((uorder*vorder*width+dsize)*sizeof(GLfloat)); + + int uinc = ustride - vorder*vstride; + GLfloat* p = out; + + for (int i=0; i *max) *max = n; + } +} +void normalize_indices_us(GLushort *indices, GLsizei *max, GLsizei *min, GLsizei count) { + getminmax_indices_us(indices, max, min, count); + for (int i = 0; i < count; i++) { + indices[i] -= *min; + } +} + +void getminmax_indices_ui(const GLuint *indices, GLsizei *max, GLsizei *min, GLsizei count) { + if (!count) return; + *max = indices[0]; + *min = indices[0]; + for (int i = 1; i < count; i++) { + GLsizei n = indices[i]; + if( n < *min) *min = n; + if (n > *max) *max = n; + } +} +void normalize_indices_ui(GLuint *indices, GLsizei *max, GLsizei *min, GLsizei count) { + getminmax_indices_ui(indices, max, min, count); + for (int i = 0; i < count; i++) { + indices[i] -= *min; + } +} + +GLvoid *copy_gl_pointer_color_bgra(const void *ptr, GLint stride, GLsizei width, GLsizei skip, GLsizei count) { + // this one only convert from BGRA (unsigned byte) to RGBA FLOAT + GLubyte* src = (GLubyte*)ptr; + + if (! src || !(count-skip)) + return NULL; + + if (! stride) + stride = 4; + + void* out = malloc(4*sizeof(GLfloat)*(count-skip)); + GLfloat* dst = out; + src += skip*(stride); + + static const float d = 1.0f/255.0f; + for (int i=skip; i>16) | ((lsrc&0x000000ff)<<16); + asm volatile ( + "vmov s12, %1 \n\t" // because you cannot vmovl.u8 d6, s11 + "vmovl.u8 q3, d6 \n\t" // Expand to 16-bit (so unsetuped s13 is expanded in d7) + "vmovl.u16 q3, d6 \n\t" // Expand to 32-bit, ignoring expanded d7 + "vcvt.f32.u32 q3, q3 \n\t" // Convert to float + "vmul.f32 q3, q3, %y2 \n\t" // Normalize + "vst1.f32 {q3}, [%0]! \n\t" // Store, next + :"+r"(dst) :"r"(lsrc), "w"(d) + : "q3", "memory" + ); + #else + const GLubyte b = src[0], g = src[1], r = src[2], a = src[3]; + *dst++ = r*d; + *dst++ = g*d; + *dst++ = b*d; + *dst++ = a*d; + #endif + src+=stride; + } + return out; +} diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/array.h b/Projects/Android/jni/SupportLibs/gl4es/src/gl/array.h new file mode 100644 index 0000000..ae05c2c --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/array.h @@ -0,0 +1,33 @@ +#ifndef _GL4ES_ARRAY_H_ +#define _GL4ES_ARRAY_H_ + +#include "buffers.h" +#include "gles.h" + +GLvoid *copy_gl_array(const GLvoid *src, + GLenum from, GLsizei width, GLsizei stride, + GLenum to, GLsizei to_width, GLsizei skip, GLsizei count); + +GLvoid *copy_gl_array_convert(const GLvoid *src, + GLenum from, GLsizei width, GLsizei stride, + GLenum to, GLsizei to_width, GLsizei skip, GLsizei count, GLvoid* filler); + +GLvoid *copy_gl_pointer(pointer_state_t *ptr, GLsizei width, GLsizei skip, GLsizei count); +GLvoid *copy_gl_pointer_color(pointer_state_t *ptr, GLsizei width, GLsizei skip, GLsizei count); +GLvoid *copy_gl_pointer_color_bgra(const void *ptr, GLint stride, GLsizei width, GLsizei skip, GLsizei count); +GLvoid *copy_gl_pointer_bytecolor(pointer_state_t *ptr, GLsizei width, GLsizei skip, GLsizei count); +GLvoid *copy_gl_pointer_raw(pointer_state_t *ptr, GLsizei width, GLsizei skip, GLsizei count); +GLvoid *copy_gl_pointer_tex(pointer_state_t *ptr, GLsizei width, GLsizei skip, GLsizei count); +void copy_gl_pointer_tex_noalloc(void* dest, pointer_state_t *ptr, GLsizei width, GLsizei skip, GLsizei count); +GLfloat *gl_pointer_index(pointer_state_t *ptr, GLint index); +void normalize_indices_us(GLushort *indices, GLsizei *max, GLsizei *min, GLsizei count); +void getminmax_indices_us(const GLushort *indices, GLsizei *max, GLsizei *min, GLsizei count); +void normalize_indices_ui(GLuint *indices, GLsizei *max, GLsizei *min, GLsizei count); +void getminmax_indices_ui(const GLuint *indices, GLsizei *max, GLsizei *min, GLsizei count); + +GLfloat *copy_eval_double1(GLenum target, GLint ustride, GLint uorder, const GLdouble *points); +GLfloat *copy_eval_float1(GLenum target, GLint ustride, GLint uorder, const GLfloat *points); +GLfloat *copy_eval_double2(GLenum target, GLint ustride, GLint uorder, GLint vstride, GLint vorder, const GLdouble *points); +GLfloat *copy_eval_float2(GLenum target, GLint ustride, GLint uorder, GLint vstride, GLint vorder, const GLfloat *points); + +#endif // _GL4ES_ARRAY_H_ diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/attributes.h b/Projects/Android/jni/SupportLibs/gl4es/src/gl/attributes.h new file mode 100644 index 0000000..6454710 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/attributes.h @@ -0,0 +1,35 @@ +#ifndef _GL4ES_ATTRIBUTES_H_ +#define _GL4ES_ATTRIBUTES_H_ + +#ifndef AliasExport + #ifdef __EMSCRIPTEN__ + #define AliasExport(name) + #else + #define AliasExport(name) __attribute__((alias(name))) __attribute__((visibility("default"))) + #endif +#endif // AliasExport + +#ifndef FASTMATH +#ifdef __GNUC__ + #ifdef __arm__ + #ifdef __ARM_PCS_VFP + //#warning Arm Hardfloat detected + #define FASTMATH + #else // __ARM_PCS_VFP + #if defined(__ARM_FP) && defined(PANDORA) + //#warning Arm SoftFP detected + #define FASTMATH __attribute__((pcs("aapcs-vfp"))) + #else // defined(__ARM_FP) && defined(PANDORA) + //#warning Arm no FP detected + #define FASTMATH + #endif // defined(__ARM_FP) && defined(PANDORA) + #endif // __ARM_PCS_VFP + #else // __arm__ + #define FASTMATH + #endif // __arm__ +#else // __GNUC__ + #define FASTMATH +#endif // __GNUC__ +#endif // FASTMATH + +#endif // _GL4ES_ATTRIBUTES_H_ diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/blend.c b/Projects/Android/jni/SupportLibs/gl4es/src/gl/blend.c new file mode 100644 index 0000000..b6af6de --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/blend.c @@ -0,0 +1,172 @@ +#include "blend.h" + +#include "../glx/hardext.h" +#include "debug.h" +#include "gl4es.h" +#include "glstate.h" +#include "init.h" +#include "loader.h" +#include "logs.h" + +void gl4es_glBlendColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha) { + PUSH_IF_COMPILING(glBlendColor); + LOAD_GLES2_OR_OES(glBlendColor); + if (gles_glBlendColor) + gles_glBlendColor(red, green, blue, alpha); + else { + static int test = 1; + if (test) { + LOGD("stub glBlendColor(%f, %f, %f, %f)\n", red, green, blue, alpha); + test = 0; + } + } +} +void glBlendColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha) AliasExport("gl4es_glBlendColor"); +void glBlendColorEXT(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha) AliasExport("gl4es_glBlendColor"); +void glBlendColorARB(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha) AliasExport("gl4es_glBlendColor"); + +void gl4es_glBlendFuncSeparate(GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha) +{ + if(!glstate->list.pending) + PUSH_IF_COMPILING(glBlendFuncSeparate) + + LOAD_GLES2_OR_OES(glBlendFuncSeparate); + if(sfactorRGB==glstate->blendsfactorrgb && dfactorRGB==glstate->blenddfactorrgb + && sfactorAlpha==glstate->blendsfactoralpha && dfactorAlpha==glstate->blenddfactoralpha) + return; // no change... + + if(glstate->list.pending) + flush(); + +#ifndef PANDORA + if(gles_glBlendFuncSeparate==NULL) { + // some fallback function to have better rendering with SDL2, better then nothing... + if(sfactorRGB==GL_SRC_ALPHA && dfactorRGB==GL_ONE_MINUS_SRC_ALPHA && sfactorAlpha==GL_ONE && dfactorAlpha==GL_ONE_MINUS_SRC_ALPHA) + gl4es_glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + else if (sfactorRGB==GL_SRC_ALPHA && dfactorRGB==GL_ONE && sfactorAlpha==GL_ZERO && dfactorAlpha==GL_ONE) + gl4es_glBlendFunc(GL_SRC_ALPHA, GL_ONE); + else if (sfactorRGB==GL_ZERO && dfactorRGB==GL_SRC_COLOR && sfactorAlpha==GL_ZERO && dfactorAlpha==GL_ONE) + gl4es_glBlendFunc(GL_ZERO, GL_SRC_COLOR); + else if (sfactorRGB==sfactorAlpha && dfactorRGB==dfactorAlpha) + gl4es_glBlendFunc(sfactorRGB, dfactorRGB); + } else +#endif + gles_glBlendFuncSeparate(sfactorRGB, dfactorRGB, sfactorAlpha, dfactorAlpha); + + glstate->blendsfactorrgb = sfactorRGB; + glstate->blenddfactorrgb = dfactorRGB; + glstate->blendsfactoralpha = sfactorAlpha; + glstate->blenddfactoralpha = dfactorAlpha; +} +void glBlendFuncSeparate(GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha) AliasExport("gl4es_glBlendFuncSeparate"); +void glBlendFuncSeparateEXT (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha) AliasExport("gl4es_glBlendFuncSeparate"); + +void gl4es_glBlendEquationSeparate(GLenum modeRGB, GLenum modeA) { + PUSH_IF_COMPILING(glBlendEquationSeparate); + LOAD_GLES2_OR_OES(glBlendEquationSeparate); +#ifndef PANDORA + if(gles_glBlendEquationSeparate) +#endif + gles_glBlendEquationSeparate(modeRGB, modeA); +} +void glBlendEquationSeparate(GLenum modeRGB, GLenum modeA) AliasExport("gl4es_glBlendEquationSeparate"); +void glBlendEquationSeparateEXT(GLenum modeRGB, GLenum modeA) AliasExport("gl4es_glBlendEquationSeparate"); + +void gl4es_glBlendFunc(GLenum sfactor, GLenum dfactor) { + if(!glstate->list.pending) + PUSH_IF_COMPILING(glBlendFunc) + + if(sfactor==glstate->blendsfactorrgb && dfactor==glstate->blenddfactorrgb + && sfactor==glstate->blendsfactoralpha && dfactor==glstate->blenddfactoralpha) + return; // already set + + if(glstate->list.pending) + flush(); + + LOAD_GLES(glBlendFunc); + LOAD_GLES2_OR_OES(glBlendFuncSeparate); + errorGL(); + + glstate->blendsfactorrgb = sfactor; + glstate->blenddfactorrgb = dfactor; + glstate->blendsfactoralpha = sfactor; + glstate->blenddfactoralpha = dfactor; + // There are some limitations in GLES1.1 Blend functions + switch(sfactor) { + #if 0 + case GL_SRC_COLOR: + if (gles_glBlendFuncSeparate) { + gles_glBlendFuncSeparate(sfactor, dfactor, sfactor, dfactor); + return; + } + sfactor = GL_ONE; // approx... + break; + case GL_ONE_MINUS_SRC_COLOR: + if (gles_glBlendFuncSeparate) { + gles_glBlendFuncSeparate(sfactor, dfactor, sfactor, dfactor); + return; + } + sfactor = GL_ONE; // not sure it make sense... + break; + #endif + // here, we need support for glBlendColor... + case GL_CONSTANT_COLOR: + case GL_CONSTANT_ALPHA: + if(hardext.blendcolor==0) + sfactor = GL_ONE; + break; + case GL_ONE_MINUS_CONSTANT_COLOR: + case GL_ONE_MINUS_CONSTANT_ALPHA: + if(hardext.blendcolor==0) + sfactor = GL_ZERO; + break; + default: + break; + } + + switch(dfactor) { + #if 0 + case GL_DST_COLOR: + sfactor = GL_ONE; // approx... + break; + case GL_ONE_MINUS_DST_COLOR: + sfactor = GL_ZERO; // not sure it make sense... + break; + #endif + // here, we need support for glBlendColor... + case GL_CONSTANT_COLOR: + case GL_CONSTANT_ALPHA: + if(hardext.blendcolor==0) + sfactor = GL_ONE; + break; + case GL_ONE_MINUS_CONSTANT_COLOR: + case GL_ONE_MINUS_CONSTANT_ALPHA: + if(hardext.blendcolor==0) + sfactor = GL_ZERO; + break; + default: + break; + } + + if ((globals4es.blendhack) && (sfactor==GL_SRC_ALPHA) && (dfactor==GL_ONE)) { + // special case, as seen in Xash3D, but it breaks torus_trooper, so behind a parameter + sfactor = GL_ONE; + } +#ifdef ODROID + if(gles_glBlendFunc) +#endif + gles_glBlendFunc(sfactor, dfactor); +} +void glBlendFunc(GLenum sfactor, GLenum dfactor) AliasExport("gl4es_glBlendFunc"); + +void gl4es_glBlendEquation(GLenum mode) { + PUSH_IF_COMPILING(glBlendEquation) + LOAD_GLES2_OR_OES(glBlendEquation); + errorGL(); +#ifdef ODROID + if(gles_glBlendEquation) +#endif + gles_glBlendEquation(mode); +} +void glBlendEquation(GLenum mode) AliasExport("gl4es_glBlendEquation"); +void glBlendEquationEXT(GLenum mode) AliasExport("gl4es_glBlendEquation"); \ No newline at end of file diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/blend.h b/Projects/Android/jni/SupportLibs/gl4es/src/gl/blend.h new file mode 100644 index 0000000..e5aa553 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/blend.h @@ -0,0 +1,12 @@ +#ifndef _GL4ES_BLEND_H_ +#define _GL4ES_BLEND_H_ + +#include "gles.h" + +void gl4es_glBlendColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha); +void gl4es_glBlendFuncSeparate(GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha); +void gl4es_glBlendEquationSeparate(GLenum modeRGB, GLenum modeA); +void gl4es_glBlendFunc(GLenum sfactor, GLenum dfactor); +void gl4es_glBlendEquation(GLenum mode); + +#endif //_GL4ES_BLEND_H_ diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/blit.c b/Projects/Android/jni/SupportLibs/gl4es/src/gl/blit.c new file mode 100644 index 0000000..f041397 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/blit.c @@ -0,0 +1,435 @@ +/* Blit utility function */ +#include "blit.h" + +#include + +#include "fpe.h" +#include "gl4es.h" +#include "glstate.h" +#include "init.h" +#include "loader.h" +#ifdef TEXSTREAM +# ifndef GL_TEXTURE_STREAM_IMG +# define GL_TEXTURE_STREAM_IMG 0x8C0D +# endif +#include "../glx/streaming.h" +#endif + +#define SHUT(a) if(!globals4es.nobanner) a + +// hacky viewport temporary changes +void pushViewport(GLint x, GLint y, GLsizei width, GLsizei height); +void popViewport(); + +void gl4es_blitTexture_gles1(GLuint texture, + GLfloat sx, GLfloat sy, + GLfloat width, GLfloat height, + GLfloat nwidth, GLfloat nheight, + GLfloat zoomx, GLfloat zoomy, + GLfloat vpwidth, GLfloat vpheight, + GLfloat x, GLfloat y, GLint mode) { + + LOAD_GLES(glClientActiveTexture); + + GLfloat old_projection[16], old_modelview[16], old_texture[16]; + + int customvp = (vpwidth>0.0); + int drawtexok = (hardext.drawtex) && (zoomx==1.0f) && (zoomy==1.0f); + + GLuint old_cli = glstate->texture.client; + if (old_cli!=0) gles_glClientActiveTexture(GL_TEXTURE0); + + gl4es_glDisable(GL_LIGHTING); + gl4es_glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + gl4es_glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + switch (mode) { + case BLIT_OPAQUE: + gl4es_glDisable(GL_ALPHA_TEST); + gl4es_glDisable(GL_BLEND); + break; + case BLIT_ALPHA: + gl4es_glEnable(GL_ALPHA_TEST); + gl4es_glAlphaFunc(GL_GREATER, 0.0f); + break; + case BLIT_COLOR: + break; + } + + if(drawtexok) { + LOAD_GLES_OES(glDrawTexf); + LOAD_GLES(glTexParameteriv); + // setup texture first + int sourceRect[4] = {sx, sy, width, height}; + gles_glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, sourceRect); + // take x/y of ViewPort into account + GLfloat dx = (customvp)?0.0f:glstate->raster.viewport.x; + GLfloat dy = (customvp)?0.0f:glstate->raster.viewport.y; + //TODO: do something with width / height of ViewPort? + // then draw it + gles_glDrawTexf(x+dx, y+dy, 0.0f, width, height); + } else { + LOAD_GLES(glEnableClientState); + LOAD_GLES(glDisableClientState); + LOAD_GLES(glVertexPointer); + LOAD_GLES(glTexCoordPointer); + LOAD_GLES(glDrawArrays); + + GLfloat w2 = 2.0f / (customvp?vpwidth:glstate->raster.viewport.width); + GLfloat h2 = 2.0f / (customvp?vpheight:glstate->raster.viewport.height); + GLfloat blit_x1=roundf(x); + GLfloat blit_x2=roundf(x+width*zoomx); + GLfloat blit_y1=roundf(y); + GLfloat blit_y2=roundf(y+height*zoomy); + GLfloat blit_vert[] = { + blit_x1*w2-1.0f, blit_y1*h2-1.0f, + blit_x2*w2-1.0f, blit_y1*h2-1.0f, + blit_x2*w2-1.0f, blit_y2*h2-1.0f, + blit_x1*w2-1.0f, blit_y2*h2-1.0f + }; + GLfloat sw = sx/nwidth; + GLfloat sh = sy/nheight; + GLfloat rw = (sx+width)/nwidth; + GLfloat rh = (sy+height)/nheight; + GLfloat blit_tex[] = { + sw, sh, + rw, sh, + rw, rh, + sw, rh + }; + + gl4es_glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT | GL_CLIENT_PIXEL_STORE_BIT); + gl4es_glGetFloatv(GL_TEXTURE_MATRIX, old_texture); + gl4es_glGetFloatv(GL_PROJECTION_MATRIX, old_projection); + gl4es_glGetFloatv(GL_MODELVIEW_MATRIX, old_modelview); + gl4es_glMatrixMode(GL_TEXTURE); + gl4es_glLoadIdentity(); + gl4es_glMatrixMode(GL_PROJECTION); + gl4es_glLoadIdentity(); + gl4es_glMatrixMode(GL_MODELVIEW); + gl4es_glLoadIdentity(); + + if(customvp) + pushViewport(0,0,vpwidth, vpheight); + + if(!glstate->clientstate[ATT_VERTEX]) + { + gles_glEnableClientState(GL_VERTEX_ARRAY); + glstate->clientstate[ATT_VERTEX] = 1; + } + gles_glVertexPointer(2, GL_FLOAT, 0, blit_vert); + if(!glstate->clientstate[ATT_MULTITEXCOORD0]) + { + gles_glEnableClientState(GL_TEXTURE_COORD_ARRAY); + glstate->clientstate[ATT_MULTITEXCOORD0] = 1; + } + gles_glTexCoordPointer(2, GL_FLOAT, 0, blit_tex); + for (int a=1; a clientstate[ATT_MULTITEXCOORD0+a]) { + gles_glClientActiveTexture(GL_TEXTURE0 + a); + gles_glDisableClientState(GL_TEXTURE_COORD_ARRAY); + glstate->clientstate[ATT_MULTITEXCOORD0+a] = 0; + gles_glClientActiveTexture(GL_TEXTURE0); + } + if(glstate->clientstate[ATT_COLOR]) { + gles_glDisableClientState(GL_COLOR_ARRAY); + glstate->clientstate[ATT_COLOR] = 0; + } + if(glstate->clientstate[ATT_NORMAL]) { + gles_glDisableClientState(GL_NORMAL_ARRAY); + glstate->clientstate[ATT_NORMAL] = 0; + } + gles_glDrawArrays(GL_TRIANGLE_FAN, 0, 4); + + if(customvp) + popViewport(); + + gl4es_glPopClientAttrib(); + gl4es_glMatrixMode(GL_TEXTURE); + gl4es_glLoadMatrixf(old_texture); + gl4es_glMatrixMode(GL_MODELVIEW); + gl4es_glLoadMatrixf(old_modelview); + gl4es_glMatrixMode(GL_PROJECTION); + gl4es_glLoadMatrixf(old_projection); + } + + if (old_cli!=0) gles_glClientActiveTexture(GL_TEXTURE0+old_cli); + +} + +const char _blit_vsh[] = "#version 100 \n" \ +"attribute highp vec2 aPosition; \n" \ +"attribute highp vec2 aTexCoord; \n" \ +"varying mediump vec2 vTexCoord; \n" \ +"void main(){ \n" \ +"gl_Position = vec4(aPosition.x, aPosition.y, 0.0, 1.0);\n" \ +"vTexCoord = aTexCoord; \n" \ +"} \n"; + +const char _blit_fsh[] = "#version 100 \n" \ +"uniform sampler2D uTex; \n" \ +"varying mediump vec2 vTexCoord; \n" \ +"void main(){ \n" \ +"gl_FragColor = texture2D(uTex, vTexCoord); \n" \ +"} \n"; + +const char _blit_vsh_alpha[] = "#version 100 \n" \ +"attribute highp vec2 aPosition; \n" \ +"attribute highp vec2 aTexCoord; \n" \ +"varying mediump vec2 vTexCoord; \n" \ +"void main(){ \n" \ +"gl_Position = vec4(aPosition.x, aPosition.y, 0.0, 1.0);\n" \ +"vTexCoord = aTexCoord; \n" \ +"} \n"; + +const char _blit_fsh_alpha[] = "#version 100 \n" \ +"uniform sampler2D uTex; \n" \ +"varying mediump vec2 vTexCoord; \n" \ +"void main(){ \n" \ +"lowp vec4 p = texture2D(uTex, vTexCoord); \n" \ +"if (p.a==0.0) discard; \n" \ +"gl_FragColor = p; \n" \ +"} \n"; + +void gl4es_blitTexture_gles2(GLuint texture, + GLfloat sx, GLfloat sy, + GLfloat width, GLfloat height, + GLfloat nwidth, GLfloat nheight, + GLfloat zoomx, GLfloat zoomy, + GLfloat vpwidth, GLfloat vpheight, + GLfloat x, GLfloat y, GLint mode) { + + LOAD_GLES(glDrawArrays); + + if(!glstate->blit) { + LOAD_GLES2(glCreateShader); + LOAD_GLES2(glShaderSource); + LOAD_GLES2(glCompileShader); + LOAD_GLES2(glGetShaderiv); + LOAD_GLES2(glBindAttribLocation); + LOAD_GLES2(glAttachShader); + LOAD_GLES2(glCreateProgram); + LOAD_GLES2(glLinkProgram); + LOAD_GLES2(glGetProgramiv); + LOAD_GLES(glGetUniformLocation); + LOAD_GLES2(glUniform1i); + LOAD_GLES2(glUseProgram); + + glstate->blit = (glesblit_t*)malloc(sizeof(glesblit_t)); + memset(glstate->blit, 0, sizeof(glesblit_t)); + + GLint success; + const char *src[1]; + src[0] = _blit_fsh; + glstate->blit->pixelshader = gles_glCreateShader( GL_FRAGMENT_SHADER ); + gles_glShaderSource( glstate->blit->pixelshader, 1, (const char**) src, NULL ); + gles_glCompileShader( glstate->blit->pixelshader ); + gles_glGetShaderiv( glstate->blit->pixelshader, GL_COMPILE_STATUS, &success ); + if (!success) + { + LOAD_GLES(glGetShaderInfoLog); + char log[400]; + gles_glGetShaderInfoLog(glstate->blit->pixelshader_alpha, 399, NULL, log); + SHUT(printf("LIBGL: Failed to produce blit fragment shader.\n%s", log);) + free(glstate->blit); + glstate->blit = NULL; + } + + src[0] = _blit_fsh_alpha; + glstate->blit->pixelshader_alpha = gles_glCreateShader( GL_FRAGMENT_SHADER ); + gles_glShaderSource( glstate->blit->pixelshader_alpha, 1, (const char**) src, NULL ); + gles_glCompileShader( glstate->blit->pixelshader_alpha ); + gles_glGetShaderiv( glstate->blit->pixelshader_alpha, GL_COMPILE_STATUS, &success ); + if (!success) + { + LOAD_GLES(glGetShaderInfoLog); + char log[400]; + gles_glGetShaderInfoLog(glstate->blit->pixelshader_alpha, 399, NULL, log); + SHUT(printf("LIBGL: Failed to produce blit with alpha fragment shader.\n%s", log);) + free(glstate->blit); + glstate->blit = NULL; + } + + src[0] = _blit_vsh; + glstate->blit->vertexshader = gles_glCreateShader( GL_VERTEX_SHADER ); + gles_glShaderSource( glstate->blit->vertexshader, 1, (const char**) src, NULL ); + gles_glCompileShader( glstate->blit->vertexshader ); + gles_glGetShaderiv( glstate->blit->vertexshader, GL_COMPILE_STATUS, &success ); + if( !success ) + { + LOAD_GLES(glGetShaderInfoLog); + char log[400]; + gles_glGetShaderInfoLog(glstate->blit->pixelshader_alpha, 399, NULL, log); + SHUT(printf("LIBGL: Failed to produce blit vertex shader.\n%s", log);) + free(glstate->blit); + glstate->blit = NULL; + } + + src[0] = _blit_vsh_alpha; + glstate->blit->vertexshader_alpha = gles_glCreateShader( GL_VERTEX_SHADER ); + gles_glShaderSource( glstate->blit->vertexshader_alpha, 1, (const char**) src, NULL ); + gles_glCompileShader( glstate->blit->vertexshader_alpha ); + gles_glGetShaderiv( glstate->blit->vertexshader_alpha, GL_COMPILE_STATUS, &success ); + if( !success ) + { + LOAD_GLES(glGetShaderInfoLog); + char log[400]; + gles_glGetShaderInfoLog(glstate->blit->pixelshader_alpha, 399, NULL, log); + SHUT(printf("LIBGL: Failed to produce blit with alpha vertex shader.\n%s", log);) + free(glstate->blit); + glstate->blit = NULL; + } + + glstate->blit->program = gles_glCreateProgram(); + gles_glBindAttribLocation( glstate->blit->program, 0, "aPosition" ); + gles_glBindAttribLocation( glstate->blit->program, 1, "aTexCoord" ); + gles_glAttachShader( glstate->blit->program, glstate->blit->pixelshader ); + gles_glAttachShader( glstate->blit->program, glstate->blit->vertexshader ); + gles_glLinkProgram( glstate->blit->program ); + gles_glGetProgramiv( glstate->blit->program, GL_LINK_STATUS, &success ); + if( !success ) + { + SHUT(printf("LIBGL: Failed to link blit program.\n");) + free(glstate->blit); + glstate->blit = NULL; + } + GLuint oldprog = glstate->gleshard->program; + gles_glUseProgram(glstate->blit->program); + gles_glUniform1i( gles_glGetUniformLocation( glstate->blit->program, "uTex" ), 0 ); + + glstate->blit->program_alpha = gles_glCreateProgram(); + gles_glBindAttribLocation( glstate->blit->program_alpha, 0, "aPosition" ); + gles_glBindAttribLocation( glstate->blit->program_alpha, 1, "aTexCoord" ); + gles_glAttachShader( glstate->blit->program_alpha, glstate->blit->pixelshader_alpha ); + gles_glAttachShader( glstate->blit->program_alpha, glstate->blit->vertexshader_alpha ); + gles_glLinkProgram( glstate->blit->program_alpha ); + gles_glGetProgramiv( glstate->blit->program_alpha, GL_LINK_STATUS, &success ); + if( !success ) + { + SHUT(printf("LIBGL: Failed to link blit program.\n");) + free(glstate->blit); + glstate->blit = NULL; + } + gles_glUseProgram(glstate->blit->program_alpha); + gles_glUniform1i( gles_glGetUniformLocation( glstate->blit->program_alpha, "uTex" ), 0 ); + gles_glUseProgram(oldprog); + } + + int customvp = (vpwidth>0.0); + GLfloat w2 = 2.0f / (customvp?vpwidth:glstate->raster.viewport.width); + GLfloat h2 = 2.0f / (customvp?vpheight:glstate->raster.viewport.height); + GLfloat blit_x1=roundf(x); + GLfloat blit_x2=roundf(x+width*zoomx); + GLfloat blit_y1=roundf(y); + GLfloat blit_y2=roundf(y+height*zoomy); + GLfloat *vert = glstate->blit->vert; + GLfloat *tex = glstate->blit->tex; + vert[0] = blit_x1*w2-1.0f; vert[1] = blit_y1*h2-1.0f; + vert[2] = blit_x2*w2-1.0f; vert[3] = vert[1]; + vert[4] = vert[2]; vert[5] = blit_y2*h2-1.0f; + vert[6] = vert[0]; vert[7] = vert[5]; + GLfloat sw = sx/nwidth; + GLfloat sh = sy/nheight; + GLfloat rw = (sx+width)/nwidth; + GLfloat rh = (sy+height)/nheight; + tex[0] = sw; tex[1] = sh; + tex[2] = rw; tex[3] = sh; + tex[4] = rw; tex[5] = rh; + tex[6] = sw; tex[7] = rh; + gl4es_glDisable(GL_BLEND); + int alpha = 0; + switch (mode) { + case BLIT_OPAQUE: + //gl4es_glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + break; + case BLIT_ALPHA: + alpha = 1; + break; + case BLIT_COLOR: + //gl4es_glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + break; + } + + realize_blitenv(alpha); + + gles_glDrawArrays(GL_TRIANGLE_FAN, 0, 4); +} + +void gl4es_blitTexture(GLuint texture, + GLfloat sx, GLfloat sy, + GLfloat width, GLfloat height, + GLfloat nwidth, GLfloat nheight, + GLfloat zoomx, GLfloat zoomy, + GLfloat vpwidth, GLfloat vpheight, + GLfloat x, GLfloat y, GLint mode) { +//printf("blitTexture(%d, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %d) customvp=%d, vp=%d/%d/%d/%d\n", texture, sx, sy, width, height, nwidth, nheight, zoomx, zoomy, vpwidth, vpheight, x, y, mode, (vpwidth>0.0), glstate->raster.viewport.x, glstate->raster.viewport.y, glstate->raster.viewport.width, glstate->raster.viewport.height); + LOAD_GLES(glBindTexture); + LOAD_GLES(glActiveTexture); + LOAD_GLES(glEnable); + LOAD_GLES(glDisable); + + realize_textures(); + + gl4es_glPushAttrib(GL_TEXTURE_BIT | GL_ENABLE_BIT | GL_TRANSFORM_BIT | GL_COLOR_BUFFER_BIT | GL_CURRENT_BIT); + + if(glstate->gleshard->active) { + glstate->gleshard->active = 0; + gles_glActiveTexture(GL_TEXTURE0); + } + + GLint depthwrite = glstate->depth.mask; + + gl4es_glDisable(GL_DEPTH_TEST); + gl4es_glDisable(GL_CULL_FACE); + gl4es_glDisable(GL_STENCIL_TEST); + + if(depthwrite) + gl4es_glDepthMask(GL_FALSE); + +#ifdef TEXSTREAM + if(glstate->bound_stream[0] && hardext.esversion==1) { +//printf("TMU%d, turning off Streaming (blit)\n", 0); + gles_glDisable(GL_TEXTURE_STREAM_IMG); + DeactivateStreaming(); + } +#endif + int tmp = glstate->enable.texture[0]; + + if(glstate->actual_tex2d[0] != texture); + gles_glBindTexture(GL_TEXTURE_2D, texture); + + if(hardext.esversion==1) { + if(!IS_TEX2D(tmp)) + gles_glEnable(GL_TEXTURE_2D); + if(IS_CUBE_MAP(tmp)) + gles_glDisable(GL_TEXTURE_CUBE_MAP); + + gl4es_blitTexture_gles1(texture, sx, sy, width, height, + nwidth, nheight, zoomx, zoomy, + vpwidth, vpheight, x, y, mode); + if(!IS_TEX2D(tmp)) + gles_glDisable(GL_TEXTURE_2D); + if(IS_CUBE_MAP(tmp)) + gles_glEnable(GL_TEXTURE_CUBE_MAP); + } else { + gl4es_blitTexture_gles2(texture, sx, sy, width, height, + nwidth, nheight, zoomx, zoomy, + vpwidth, vpheight, x, y, mode); + } + + // All the previous states are Pushed / Poped anyway... +#ifdef TEXSTREAM + if(glstate->bound_stream[0] && hardext.esversion==1) { +//printf("TMU%d, turning ON Streaming (blit)\n", 0); + gltexture_t *tex = glstate->texture.bound[0][ENABLED_TEX2D]; + ActivateStreaming(tex->streamingID); + gles_glEnable(GL_TEXTURE_STREAM_IMG); + } else +#endif + if (glstate->actual_tex2d[0] != texture) + gles_glBindTexture(GL_TEXTURE_2D, glstate->actual_tex2d[0]); + + if(depthwrite) + gl4es_glDepthMask(GL_TRUE); + + gl4es_glPopAttrib(); +} \ No newline at end of file diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/blit.h b/Projects/Android/jni/SupportLibs/gl4es/src/gl/blit.h new file mode 100644 index 0000000..ac1e35f --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/blit.h @@ -0,0 +1,18 @@ +#ifndef _GL4ES_BLIT_H_ +#define _GL4ES_BLIT_H_ + +#include "gles.h" + +#define BLIT_ALPHA 0 +#define BLIT_OPAQUE 1 +#define BLIT_COLOR 2 + +void gl4es_blitTexture(GLuint texture, + GLfloat sx, GLfloat sy, + GLfloat width, GLfloat height, + GLfloat nwidth, GLfloat nheight, + GLfloat zoomx, GLfloat zoomy, + GLfloat vpwidth, GLfloat vpheight, + GLfloat x, GLfloat y, GLint mode); + +#endif // _GL4ES_BLIT_H_ diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/buffers.c b/Projects/Android/jni/SupportLibs/gl4es/src/gl/buffers.c new file mode 100644 index 0000000..5026070 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/buffers.c @@ -0,0 +1,663 @@ +#include "buffers.h" + +#include "khash.h" +#include "../glx/hardext.h" +#include "attributes.h" +#include "debug.h" +#include "gl4es.h" +#include "glstate.h" +#include "logs.h" + +//#define DEBUG +#ifdef DEBUG +#define DBG(a) a +#else +#define DBG(a) +#endif + + +KHASH_MAP_IMPL_INT(buff, glbuffer_t *); +KHASH_MAP_IMPL_INT(glvao, glvao_t*); + +static GLuint lastbuffer = 1; + +// Utility function to bind / unbind a particular buffer + +glbuffer_t** BUFF(GLenum target) { + switch(target) { + case GL_ARRAY_BUFFER: + return &glstate->vao->vertex; + break; + case GL_ELEMENT_ARRAY_BUFFER: + return &glstate->vao->elements; + break; + case GL_PIXEL_PACK_BUFFER: + return &glstate->vao->pack; + break; + case GL_PIXEL_UNPACK_BUFFER: + return &glstate->vao->unpack; + break; + default: + LOGD("LIBGL: Warning, unknown buffer target 0x%04X\n", target); + } + return (glbuffer_t**)NULL; +} + +void unbind_buffer(GLenum target) { + glbuffer_t **t = BUFF(target); + if (t) + *t=(glbuffer_t*)NULL; +} +void bind_buffer(GLenum target, glbuffer_t* buff) { + glbuffer_t ** t = BUFF(target); + if (t) + *t = buff; +} +glbuffer_t* getbuffer_buffer(GLenum target) { + glbuffer_t ** t = BUFF(target); + if (t) + return *t; + return NULL; +} +glbuffer_t* getbuffer_id(GLuint buffer) { + if(!buffer) + return NULL; + khint_t k; + int ret; + khash_t(buff) *list = glstate->buffers; + k = kh_get(buff, list, buffer); + if (k == kh_end(list)) + return NULL; + return kh_value(list, k); +} + +int buffer_target(GLenum target) { + if (target==GL_ARRAY_BUFFER) + return 1; + if (target==GL_ELEMENT_ARRAY_BUFFER) + return 1; + if (target==GL_PIXEL_PACK_BUFFER) + return 1; + if (target==GL_PIXEL_UNPACK_BUFFER) + return 1; + return 0; +} + +void gl4es_glGenBuffers(GLsizei n, GLuint * buffers) { + DBG(printf("glGenBuffers(%i, %p)\n", n, buffers);) + noerrorShim(); + if (n<1) { + errorShim(GL_INVALID_VALUE); + return; + } + for (int i=0; ilist.pending) // this is probably not needed as long as real VBO are not used + flush(); + + khint_t k; + int ret; + khash_t(buff) *list = glstate->buffers; + if (!buffer_target(target)) { + errorShim(GL_INVALID_ENUM); + return; + } + // if buffer = 0 => unbind buffer! + if (buffer == 0) { + // unbind buffer + unbind_buffer(target); + } else { + // search for an existing buffer + k = kh_get(buff, list, buffer); + glbuffer_t *buff = NULL; + if (k == kh_end(list)){ + k = kh_put(buff, list, buffer, &ret); + buff = kh_value(list, k) = malloc(sizeof(glbuffer_t)); + buff->buffer = buffer; + buff->type = target; + buff->data = NULL; + buff->usage = GL_STATIC_DRAW; + buff->size = 0; + buff->access = GL_READ_WRITE; + buff->mapped = 0; + } else { + buff = kh_value(list, k); + } + bind_buffer(target, buff); + } + noerrorShim(); +} + +void gl4es_glBufferData(GLenum target, GLsizeiptr size, const GLvoid * data, GLenum usage) { + DBG(printf("glBufferData(%s, %i, %p, %s)\n", PrintEnum(target), size, data, PrintEnum(usage));) + if (!buffer_target(target)) { + errorShim(GL_INVALID_ENUM); + return; + } + glbuffer_t *buff = getbuffer_buffer(target); + if (buff==NULL) { + errorShim(GL_INVALID_OPERATION); + LOGE("LIBGL: Warning, null buffer for target=0x%04X for glBufferData\n", target); + return; + } + if (buff->data) { + free(buff->data); + + } + if(target==GL_ARRAY_BUFFER) + VaoSharedClear(glstate->vao); + + buff->size = size; + buff->usage = usage; + buff->data = malloc(size); + buff->access = GL_READ_WRITE; + if (data) + memcpy(buff->data, data, size); + noerrorShim(); +} + +void gl4es_glNamedBufferData(GLuint buffer, GLsizeiptr size, const GLvoid * data, GLenum usage) { + DBG(printf("glNamedBufferData(%u, %i, %p, %s)\n", buffer, size, data, PrintEnum(usage));) + glbuffer_t *buff = getbuffer_id(buffer); + if (buff==NULL) { + errorShim(GL_INVALID_OPERATION); + return; + } + if (buff->data) { + free(buff->data); + + } + + buff->size = size; + buff->usage = usage; + buff->data = malloc(size); + buff->access = GL_READ_WRITE; + if (data) + memcpy(buff->data, data, size); + noerrorShim(); +} + +void gl4es_glBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid * data) { + DBG(printf("glBufferSubData(%s, %p, %i, %p)\n", PrintEnum(target), offset, size, data);) + if (!buffer_target(target)) { + errorShim(GL_INVALID_ENUM); + return; + } + glbuffer_t *buff = getbuffer_buffer(target); + if (buff==NULL) { + errorShim(GL_INVALID_OPERATION); + DBG(printf("LIBGL: Warning, null buffer for target=0x%04X for glBufferSubData\n", target);) + return; + } + + if(target==GL_ARRAY_BUFFER) + VaoSharedClear(glstate->vao); + + if (offset<0 || size<0 || offset+size>buff->size) { + errorShim(GL_INVALID_VALUE); + return; + } + + memcpy(buff->data + offset, data, size); + noerrorShim(); +} +void gl4es_glNamedBufferSubData(GLuint buffer, GLintptr offset, GLsizeiptr size, const GLvoid * data) { + DBG(printf("glNamedBufferSubData(%u, %p, %i, %p)\n", buffer, offset, size, data);) + glbuffer_t *buff = getbuffer_id(buffer); + if (buff==NULL) { + errorShim(GL_INVALID_OPERATION); + return; + } + + if (offset<0 || size<0 || offset+size>buff->size) { + errorShim(GL_INVALID_VALUE); + return; + } + + memcpy(buff->data + offset, data, size); + noerrorShim(); +} + +void gl4es_glDeleteBuffers(GLsizei n, const GLuint * buffers) { + DBG(printf("glDeleteBuffers(%i, %p)\n", n, buffers);) + if(!glstate) return; + FLUSH_BEGINEND; + + VaoSharedClear(glstate->vao); + khash_t(buff) *list = glstate->buffers; + if (list) { + khint_t k; + glbuffer_t *buff; + for (int i = 0; i < n; i++) { + GLuint t = buffers[i]; + if (t) { // don't allow to remove default one + k = kh_get(buff, list, t); + if (k != kh_end(list)) { + buff = kh_value(list, k); + if (glstate->vao->vertex == buff) + glstate->vao->vertex = NULL; + if (glstate->vao->elements == buff) + glstate->vao->elements = NULL; + if (glstate->vao->pack == buff) + glstate->vao->pack = NULL; + if (glstate->vao->unpack == buff) + glstate->vao->unpack = NULL; + for (int j = 0; j < hardext.maxvattrib; j++) + if (glstate->vao->vertexattrib[j].buffer == buff) + glstate->vao->vertexattrib[j].buffer = NULL; + if (buff->data) free(buff->data); + kh_del(buff, list, k); + free(buff); + } + } + } + } + noerrorShim(); +} + +GLboolean gl4es_glIsBuffer(GLuint buffer) { + DBG(printf("glIsBuffer(%u)\n", buffer);) + khash_t(buff) *list = glstate->buffers; + khint_t k; + noerrorShim(); + if (list) { + k = kh_get(buff, list, buffer); + if (k != kh_end(list)) { + return GL_TRUE; + } + } + return GL_FALSE; +} + + +static void* bufferGetParameteriv(glbuffer_t* buff, GLenum value, GLint * data) { + noerrorShim(); + switch (value) { + case GL_BUFFER_ACCESS: + data[0] = buff->access; + break; + case GL_BUFFER_ACCESS_FLAGS: + data[0] = GL_MAP_READ_BIT | GL_MAP_WRITE_BIT; + break; + case GL_BUFFER_MAPPED: + data[0]=(buff->mapped)?GL_TRUE:GL_FALSE; + break; + case GL_BUFFER_MAP_LENGTH: + data[0]=(buff->mapped)?buff->size:0; + break; + case GL_BUFFER_MAP_OFFSET: + data[0]=0; + break; + case GL_BUFFER_SIZE: + data[0] = buff->size; + break; + case GL_BUFFER_USAGE: + data[0] = buff->usage; + break; + default: + errorShim(GL_INVALID_ENUM); + /* TODO Error if something else */ + } +} + +void gl4es_glGetBufferParameteriv(GLenum target, GLenum value, GLint * data) { + DBG(printf("glGetBufferParameteriv(%s, %s, %p)\n", PrintEnum(target), PrintEnum(value), data);) + if (!buffer_target(target)) { + errorShim(GL_INVALID_ENUM); + return; + } + glbuffer_t* buff = getbuffer_buffer(target); + if (buff==NULL) { + errorShim(GL_INVALID_OPERATION); + return; // Should generate an error! + } + bufferGetParameteriv(buff, value, data); +} +void gl4es_glGetNamedBufferParameteriv(GLuint buffer, GLenum value, GLint * data) { + DBG(printf("glGetNamedBufferParameteriv(%u, %s, %p)\n", buffer, PrintEnum(value), data);) + glbuffer_t* buff = getbuffer_id(buffer); + if (buff==NULL) { + errorShim(GL_INVALID_OPERATION); + return; // Should generate an error! + } + bufferGetParameteriv(buff, value, data); +} + +void *gl4es_glMapBuffer(GLenum target, GLenum access) { + DBG(printf("glMapBuffer(%s, %s)\n", PrintEnum(target), PrintEnum(access));) + if (!buffer_target(target)) { + errorShim(GL_INVALID_ENUM); + return (void*)NULL; + } + + if(target==GL_ARRAY_BUFFER) + VaoSharedClear(glstate->vao); + + glbuffer_t *buff = getbuffer_buffer(target); + if (buff==NULL) + return (void*)NULL; // Should generate an error! + buff->access = access; // not used + buff->mapped = 1; + noerrorShim(); + return buff->data; // Not nice, should do some copy or something probably +} +void *gl4es_glMapNamedBuffer(GLuint buffer, GLenum access) { + DBG(printf("glMapNamedBuffer(%u, %s)\n", buffer, PrintEnum(access));) + + glbuffer_t *buff = getbuffer_id(buffer); + if (buff==NULL) + return (void*)NULL; // Should generate an error! + buff->access = access; // not used + buff->mapped = 1; + noerrorShim(); + return buff->data; // Not nice, should do some copy or something probably +} + +GLboolean gl4es_glUnmapBuffer(GLenum target) { + DBG(printf("glUnmapBuffer(%s)\n", PrintEnum(target));) + if(glstate->list.compiling) {errorShim(GL_INVALID_OPERATION); return GL_FALSE;} + if(glstate->list.active) + flush(); + + if (!buffer_target(target)) { + errorShim(GL_INVALID_ENUM); + return GL_FALSE; + } + + if(target==GL_ARRAY_BUFFER) + VaoSharedClear(glstate->vao); + + glbuffer_t *buff = getbuffer_buffer(target); + if (buff==NULL) + return GL_FALSE; // Should generate an error! + noerrorShim(); + if (buff->mapped) { + buff->mapped = 0; + return GL_TRUE; + } + return GL_FALSE; +} +GLboolean gl4es_glUnmapNamedBuffer(GLuint buffer) { + DBG(printf("glUnmapNamedBuffer(%u)\n", buffer);) + if(glstate->list.compiling) {errorShim(GL_INVALID_OPERATION); return GL_FALSE;} + if(glstate->list.active) + flush(); + + glbuffer_t *buff = getbuffer_id(buffer); + if (buff==NULL) + return GL_FALSE; // Should generate an error! + noerrorShim(); + if (buff->mapped) { + buff->mapped = 0; + return GL_TRUE; + } + return GL_FALSE; +} + +void gl4es_glGetBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, GLvoid * data) { + DBG(printf("glGetBufferSubData(%s, %p, %i, %p)\n", PrintEnum(target), offset, size, data);) + if (!buffer_target(target)) { + errorShim(GL_INVALID_ENUM); + return; + } + glbuffer_t *buff = getbuffer_buffer(target); + + if (buff==NULL) + return; // Should generate an error! + // TODO, check parameter consistancie + memcpy(data, buff->data+offset, size); + noerrorShim(); +} +void gl4es_glGetNamedBufferSubData(GLuint buffer, GLintptr offset, GLsizeiptr size, GLvoid * data) { + DBG(printf("glGetNamedBufferSubData(%u, %p, %i, %p)\n", buffer, offset, size, data);) + glbuffer_t *buff = getbuffer_id(buffer); + + if (buff==NULL) + return; // Should generate an error! + // TODO, check parameter consistancie + memcpy(data, buff->data+offset, size); + noerrorShim(); +} + +void gl4es_glGetBufferPointerv(GLenum target, GLenum pname, GLvoid ** params) { + DBG(printf("glGetBufferPointerv(%s, %s, %p)\n", PrintEnum(target), PrintEnum(pname), params);) + if (!buffer_target(target)) { + errorShim(GL_INVALID_ENUM); + return; + } + glbuffer_t *buff = getbuffer_buffer(target); + if (buff==NULL) + return; // Should generate an error! + if (pname != GL_BUFFER_MAP_POINTER) { + errorShim(GL_INVALID_ENUM); + return; + } + if (!buff->mapped) { + params[0] = NULL; + } else { + params[0] = buff->data; + } +} +void gl4es_glGetNamedBufferPointerv(GLuint buffer, GLenum pname, GLvoid ** params) { + DBG(printf("glGetNamedBufferPointerv(%u, %s, %p)\n", buffer, PrintEnum(pname), params);) + glbuffer_t *buff = getbuffer_id(buffer); + if (buff==NULL) + return; // Should generate an error! + if (pname != GL_BUFFER_MAP_POINTER) { + errorShim(GL_INVALID_ENUM); + return; + } + if (!buff->mapped) { + params[0] = NULL; + } else { + params[0] = buff->data; + } +} + +void* gl4es_glMapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access) +{ + DBG(printf("glMapBuffer(%s, %s)\n", PrintEnum(target), PrintEnum(access));) + if (!buffer_target(target)) { + errorShim(GL_INVALID_ENUM); + return (void*)NULL; + } + + if(target==GL_ARRAY_BUFFER) + VaoSharedClear(glstate->vao); + + glbuffer_t *buff = getbuffer_buffer(target); + if (buff==NULL) + return (void*)NULL; // Should generate an error! + buff->access = access; // not used + buff->mapped = 1; + noerrorShim(); + uintptr_t ret = (uintptr_t)buff->data; + ret += offset; + return (void*)ret; // Not nice, should do some copy or something probably +} +void gl4es_glFlushMappedBufferRange(GLenum target, GLintptr offset, GLsizeiptr length) +{ + // ignored for now. A proprer handling is probably necessary + // but that would mean also proprer handling of MapBuffer in the first place + // with shadow copy for example when in read mode only +} + + +//Direct wrapper +void glGenBuffers(GLsizei n, GLuint * buffers) AliasExport("gl4es_glGenBuffers"); +void glBindBuffer(GLenum target, GLuint buffer) AliasExport("gl4es_glBindBuffer"); +void glBufferData(GLenum target, GLsizeiptr size, const GLvoid * data, GLenum usage) AliasExport("gl4es_glBufferData"); +void glBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid * data) AliasExport("gl4es_glBufferSubData"); +void glDeleteBuffers(GLsizei n, const GLuint * buffers) AliasExport("gl4es_glDeleteBuffers"); +GLboolean glIsBuffer(GLuint buffer) AliasExport("gl4es_glIsBuffer"); +void glGetBufferParameteriv(GLenum target, GLenum value, GLint * data) AliasExport("gl4es_glGetBufferParameteriv"); +void *glMapBuffer(GLenum target, GLenum access) AliasExport("gl4es_glMapBuffer"); +GLboolean glUnmapBuffer(GLenum target) AliasExport("gl4es_glUnmapBuffer"); +void glGetBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, GLvoid * data) AliasExport("gl4es_glGetBufferSubData"); +void glGetBufferPointerv(GLenum target, GLenum pname, GLvoid ** params) AliasExport("gl4es_glGetBufferPointerv"); + +void *glMapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access) AliasExport("gl4es_glMapBufferRange"); +void glFlushMappedBufferRange(GLenum target, GLintptr offset, GLsizeiptr length) AliasExport("gl4es_glFlushMappedBufferRange"); + +//ARB wrapper +void glGenBuffersARB(GLsizei n, GLuint * buffers) AliasExport("gl4es_glGenBuffers"); +void glBindBufferARB(GLenum target, GLuint buffer) AliasExport("gl4es_glBindBuffer"); +void glBufferDataARB(GLenum target, GLsizeiptr size, const GLvoid * data, GLenum usage) AliasExport("gl4es_glBufferData"); +void glBufferSubDataARB(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid * data) AliasExport("gl4es_glBufferSubData"); +void glDeleteBuffersARB(GLsizei n, const GLuint * buffers) AliasExport("gl4es_glDeleteBuffers"); +GLboolean glIsBufferARB(GLuint buffer) AliasExport("gl4es_glIsBuffer"); +void glGetBufferParameterivARB(GLenum target, GLenum value, GLint * data) AliasExport("gl4es_glGetBufferParameteriv"); +void *glMapBufferARB(GLenum target, GLenum access) AliasExport("gl4es_glMapBuffer"); +GLboolean glUnmapBufferARB(GLenum target) AliasExport("gl4es_glUnmapBuffer"); +void glGetBufferSubDataARB(GLenum target, GLintptr offset, GLsizeiptr size, GLvoid * data) AliasExport("gl4es_glGetBufferSubData"); +void glGetBufferPointervARB(GLenum target, GLenum pname, GLvoid ** params) AliasExport("gl4es_glGetBufferPointerv"); + +//Direct Access +void glNamedBufferData(GLuint buffer, GLsizeiptr size, const GLvoid * data, GLenum usage) AliasExport("gl4es_glNamedBufferData"); +void glNamedBufferSubData(GLuint buffer, GLintptr offset, GLsizeiptr size, const GLvoid * data) AliasExport("gl4es_glNamedBufferSubData"); +void glGetNamedBufferParameteriv(GLuint buffer, GLenum value, GLint * data) AliasExport("gl4es_glGetNamedBufferParameteriv"); +void *glMapNamedBuffer(GLuint buffer, GLenum access) AliasExport("gl4es_glMapNamedBuffer"); +GLboolean glUnmapNamedBuffer(GLuint buffer) AliasExport("gl4es_glUnmapNamedBuffer"); +void glGetNamedBufferSubData(GLuint buffer, GLintptr offset, GLsizeiptr size, GLvoid * data) AliasExport("gl4es_glGetNamedBufferSubData"); +void glGetNamedBufferPointerv(GLuint buffer, GLenum pname, GLvoid ** params) AliasExport("gl4es_glGetNamedBufferPointerv"); + +void glNamedBufferDataEXT(GLuint buffer, GLsizeiptr size, const GLvoid * data, GLenum usage) AliasExport("gl4es_glNamedBufferData"); +void glNamedBufferSubDataEXT(GLuint buffer, GLintptr offset, GLsizeiptr size, const GLvoid * data) AliasExport("gl4es_glNamedBufferSubData"); +void glGetNamedBufferParameterivEXT(GLuint buffer, GLenum value, GLint * data) AliasExport("gl4es_glGetNamedBufferParameteriv"); +void *glMapNamedBufferEXT(GLuint buffer, GLenum access) AliasExport("gl4es_glMapNamedBuffer"); +GLboolean glUnmapNamedBufferEXT(GLuint buffer) AliasExport("gl4es_glUnmapNamedBuffer"); +void glGetNamedBufferSubDataEXT(GLuint buffer, GLintptr offset, GLsizeiptr size, GLvoid * data) AliasExport("gl4es_glGetNamedBufferSubData"); +void glGetNamedBufferPointervEXT(GLuint buffer, GLenum pname, GLvoid ** params) AliasExport("gl4es_glGetNamedBufferPointerv"); + + +// VAO **************** +static GLuint lastvao = 1; + +void gl4es_glGenVertexArrays(GLsizei n, GLuint *arrays) { + DBG(printf("glGenVertexArrays(%i, %p)\n", n, arrays);) + noerrorShim(); + if (n<1) { + errorShim(GL_INVALID_VALUE); + return; + } + for (int i=0; ilist.pending) + flush(); + + khint_t k; + int ret; + khash_t(glvao) *list = glstate->vaos; + // if array = 0 => unbind buffer! + if (array == 0) { + // unbind buffer + glstate->vao = glstate->defaultvao; + } else { + // search for an existing buffer + k = kh_get(glvao, list, array); + glvao_t *glvao = NULL; + if (k == kh_end(list)){ + k = kh_put(glvao, list, array, &ret); + glvao = kh_value(list, k) = malloc(sizeof(glvao_t)); + // new vao is binded to nothing + VaoInit(glvao); + // TODO: check if should copy status of current VAO instead of cleanning everything + + // just put is number + glvao->array = array; + } else { + glvao = kh_value(list, k); + } + glstate->vao = glvao; + } + // TODO: find a better way to do that, to many useless copying stuff + if(glstate->fpe_state) + memcpy(glstate->glesva.wanted, glstate->vao->vertexattrib, MAX_VATTRIB * sizeof(vertexattrib_t)); + + noerrorShim(); +} +void gl4es_glDeleteVertexArrays(GLsizei n, const GLuint *arrays) { + DBG(printf("glDeleteVertexArrays(%i, %p)\n", n, arrays);) + if(!glstate) return; + FLUSH_BEGINEND; + + khash_t(glvao) *list = glstate->vaos; + if (list) { + khint_t k; + glvao_t *glvao; + for (int i = 0; i < n; i++) { + GLuint t = arrays[i]; + if (t) { // don't allow to remove the default one + k = kh_get(glvao, list, t); + if (k != kh_end(list)) { + glvao = kh_value(list, k); + VaoSharedClear(glvao); + kh_del(glvao, list, k); + //free(glvao); //let the use delete those + } + } + } + } + noerrorShim(); +} +GLboolean gl4es_glIsVertexArray(GLuint array) { + DBG(printf("glIsVertexArray(%u)\n", array);) + if(!glstate) + return GL_FALSE; + khash_t(glvao) *list = glstate->vaos; + khint_t k; + noerrorShim(); + if (list) { + k = kh_get(glvao, list, array); + if (k != kh_end(list)) { + return GL_TRUE; + } + } + return GL_FALSE; +} + +void VaoSharedClear(glvao_t *vao) { + if(vao==NULL || vao->shared_arrays==NULL) + return; + if(!(--(*vao->shared_arrays))) { + free(vao->vert.ptr); + free(vao->color.ptr); + free(vao->secondary.ptr); + free(vao->normal.ptr); + for (int i=0; itex[i].ptr); + free(vao->shared_arrays); + } + vao->vert.ptr = NULL; + vao->color.ptr = NULL; + vao->secondary.ptr = NULL; + vao->normal.ptr = NULL; + for (int i=0; itex[i].ptr = NULL; + vao->shared_arrays = NULL; +} + +void VaoInit(glvao_t *vao) { + memset(vao, 0, sizeof(glvao_t)); + for (int i=0; ivertexattrib[i].size = 4; + vao->vertexattrib[i].type = GL_FLOAT; + vao->vertexattrib[i].current[3] = 1.0f; + } +} + +//Direct wrapper +void glGenVertexArrays(GLsizei n, GLuint *arrays) AliasExport("gl4es_glGenVertexArrays"); +void glBindVertexArray(GLuint array) AliasExport("gl4es_glBindVertexArray"); +void glDeleteVertexArrays(GLsizei n, const GLuint *arrays) AliasExport("gl4es_glDeleteVertexArrays"); +GLboolean glIsVertexArray(GLuint array) AliasExport("gl4es_glIsVertexArray"); + diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/buffers.h b/Projects/Android/jni/SupportLibs/gl4es/src/gl/buffers.h new file mode 100644 index 0000000..ab1f196 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/buffers.h @@ -0,0 +1,167 @@ +#ifndef _GL4ES_BUFFERS_H_ +#define _GL4ES_BUFFERS_H_ + +#include "khash.h" +#include "../config.h" +#include "gles.h" + +// VBO ***************** +typedef struct { + GLuint buffer; + GLenum type; + GLsizeiptr size; + GLenum usage; + GLint access; + int mapped; + GLvoid *data; +} glbuffer_t; + +KHASH_MAP_DECLARE_INT(buff, glbuffer_t *); + +void gl4es_glGenBuffers(GLsizei n, GLuint * buffers); +void gl4es_glBindBuffer(GLenum target, GLuint buffer); +void gl4es_glBufferData(GLenum target, GLsizeiptr size, const GLvoid * data, GLenum usage); +void gl4es_glBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid * data); +void gl4es_glDeleteBuffers(GLsizei n, const GLuint * buffers); +GLboolean gl4es_glIsBuffer(GLuint buffer); +void gl4es_glGetBufferParameteriv(GLenum target, GLenum value, GLint * data); + +void *gl4es_glMapBuffer(GLenum target, GLenum access); +GLboolean gl4es_glUnmapBuffer(GLenum target); +void gl4es_glGetBufferPointerv(GLenum target, GLenum pname, GLvoid ** params); +void gl4es_glGetBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, GLvoid * data); + +void *gl4es_glMapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access); +void gl4es_glFlushMappedBufferRange(GLenum target, GLintptr offset, GLsizeiptr length); + +void glGenBuffers(GLsizei n, GLuint * buffers); +void glBindBuffer(GLenum target, GLuint buffer); +void glBufferData(GLenum target, GLsizeiptr size, const GLvoid * data, GLenum usage); +void glBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid * data); +void glDeleteBuffers(GLsizei n, const GLuint * buffers); +GLboolean glIsBuffer(GLuint buffer); +void glGetBufferParameteriv(GLenum target, GLenum value, GLint * data); +void *glMapBuffer(GLenum target, GLenum access); +GLboolean glUnmapBuffer(GLenum target); +void glGetBufferPointerv(GLenum target, GLenum pname, GLvoid ** params); +void glGetBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, GLvoid * data); + +void *glMapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access); +void glFlushMappedBufferRange(GLenum target, GLintptr offset, GLsizeiptr length); + +void glGenBuffersARB(GLsizei n, GLuint * buffers); +void glBindBufferARB(GLenum target, GLuint buffer); +void glBufferDataARB(GLenum target, GLsizeiptr size, const GLvoid * data, GLenum usage); +void glBufferSubDataARB(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid * data); +void glDeleteBuffersARB(GLsizei n, const GLuint * buffers); +GLboolean glIsBufferARB(GLuint buffer); +void glGetBufferParameterivARB(GLenum target, GLenum value, GLint * data); +void *glMapBufferARB(GLenum target, GLenum access); +GLboolean glUnmapBufferARB(GLenum target); +void glGetBufferSubDataARB(GLenum target, GLintptr offset, GLsizeiptr size, GLvoid * data); +void glGetBufferPointervARB(GLenum target, GLenum pname, GLvoid ** params); + +// Pointer..... ****** +typedef struct { + GLint size; + GLenum type; + GLsizei stride; + const GLvoid *pointer; + GLboolean enabled; +} pointer_state_t; + +typedef enum { + ATT_VERTEX = 0, + ATT_COLOR, + ATT_MULTITEXCOORD0, + ATT_MULTITEXCOORD1, + ATT_MULTITEXCOORD2, + ATT_MULTITEXCOORD3, + ATT_MULTITEXCOORD4, + ATT_MULTITEXCOORD5, + ATT_MULTITEXCOORD6, + ATT_MULTITEXCOORD7, + ATT_NORMAL, + ATT_SECONDARY, + ATT_FOGCOORD, + //ATT_POINTSIZE, //this one is supported by GLES hardware + ATT_MAX +} reserved_attrib_t; + +#define NB_VA (ATT_MAX) + +typedef struct { + GLfloat *ptr; + pointer_state_t state; + GLboolean enabled; +} pointer_cache_t; + +// Vertex Attrib.. *** +typedef struct { + GLint size; + GLenum type; + GLsizei stride; + const GLvoid* pointer; + GLboolean vaarray; + GLboolean normalized; + glbuffer_t *buffer; // reference buffer + GLfloat current[4]; + GLint divisor; +} vertexattrib_t; + +// VAO **************** +typedef struct { + GLuint array; + // pointer state + pointer_state_t pointers[NB_VA]; + // buffer state + glbuffer_t *vertex; + glbuffer_t *elements; + glbuffer_t *pack; + glbuffer_t *unpack; + // locked arrays + GLboolean locked; + GLsizei count; + GLint first; + GLboolean locked_mapped; + pointer_state_t locked_pointers[NB_VA]; + + int maxtex; // upper limit enabled tex_coord + // VAO optimisation: keep a shared copy of the digested datas (unless the vao is the default one) + int *shared_arrays; + pointer_cache_t vert; + pointer_cache_t normal; + pointer_cache_t color; + pointer_cache_t secondary; + pointer_cache_t fog; + pointer_cache_t tex[MAX_TEX]; + int cache_count; + // Vertex Attrib + vertexattrib_t vertexattrib[MAX_VATTRIB]; + // TODO: Cache VA also? +} glvao_t; + +void VaoSharedClear(glvao_t *vao); +void VaoInit(glvao_t *vao); + +KHASH_MAP_DECLARE_INT(glvao, glvao_t*); + +void gl4es_glGenVertexArrays(GLsizei n, GLuint *arrays); +void gl4es_glBindVertexArray(GLuint array); +void gl4es_glDeleteVertexArrays(GLsizei n, const GLuint *arrays); +GLboolean gl4es_glIsVertexArray(GLuint array); + +void glGenVertexArrays(GLsizei n, GLuint *arrays); +void glBindVertexArray(GLuint array); +void glDeleteVertexArrays(GLsizei n, const GLuint *arrays); +GLboolean glIsVertexArray(GLuint array); + +void gl4es_glNamedBufferData(GLuint buffer, GLsizeiptr size, const GLvoid * data, GLenum usage); +void gl4es_glNamedBufferSubData(GLuint buffer, GLintptr offset, GLsizeiptr size, const GLvoid * data); +void gl4es_glGetNamedBufferParameteriv(GLuint buffer, GLenum value, GLint * data); +void* gl4es_glMapNamedBuffer(GLuint buffer, GLenum access); +GLboolean gl4es_glUnmapNamedBuffer(GLuint buffer); +void gl4es_glGetNamedBufferSubData(GLuint buffer, GLintptr offset, GLsizeiptr size, GLvoid * data); +void gl4es_glGetNamedBufferPointerv(GLuint buffer, GLenum pname, GLvoid ** params); + +#endif // _GL4ES_BUFFERS_H_ diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/build_info.c b/Projects/Android/jni/SupportLibs/gl4es/src/gl/build_info.c new file mode 100644 index 0000000..81825ab --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/build_info.c @@ -0,0 +1,9 @@ +#include +#include "build_info.h" +#include "logs.h" +#include "../../version.h" + +void print_build_infos() +{ + LOGD("LIBGL: v%d.%d.%d built on %s %s\n", MAJOR, MINOR, REVISION, __DATE__, __TIME__); +} diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/build_info.h b/Projects/Android/jni/SupportLibs/gl4es/src/gl/build_info.h new file mode 100644 index 0000000..b1bdda8 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/build_info.h @@ -0,0 +1,6 @@ +#ifndef _GL4ES_BUILD_INFO_H_ +#define _GL4ES_BUILD_INFO_H_ + +void print_build_infos(); + +#endif // _GL4ES_BUILD_INFO_H_ diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/const.h b/Projects/Android/jni/SupportLibs/gl4es/src/gl/const.h new file mode 100644 index 0000000..c096f2d --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/const.h @@ -0,0 +1,771 @@ +#ifndef _GL4ES_CONST_H_ +#define _GL4ES_CONST_H_ + +#define GL_QUADS 7 +#define GL_QUAD_STRIP 8 +#define GL_POLYGON 9 + +#define GL_MAJOR_VERSION 0x821B +#define GL_MINOR_VERSION 0x821C +#define GL_DOUBLEBUFFER 0x0C32 +/* texture mapping */ +#define GL_TEXTURE_ENV 0x2300 +#define GL_TEXTURE_ENV_MODE 0x2200 +#define GL_TEXTURE_1D 0x0DE0 +#define GL_TEXTURE_2D 0x0DE1 +#define GL_TEXTURE_3D 0x806F +#define GL_TEXTURE_WRAP_S 0x2802 +#define GL_TEXTURE_WRAP_T 0x2803 +#define GL_TEXTURE_WRAP_R 0x8072 +#define GL_TEXTURE_MAG_FILTER 0x2800 +#define GL_TEXTURE_MIN_FILTER 0x2801 +#define GL_TEXTURE_ENV_COLOR 0x2201 +#define GL_TEXTURE_GEN_S 0x0C60 +#define GL_TEXTURE_GEN_T 0x0C61 +#define GL_TEXTURE_GEN_MODE 0x2500 +#define GL_TEXTURE_BORDER_COLOR 0x1004 +#define GL_TEXTURE_BORDER 0x1005 +#define GL_TEXTURE_WIDTH 0x1000 +#define GL_TEXTURE_HEIGHT 0x1001 +#define GL_TEXTURE_BORDER 0x1005 +#define GL_TEXTURE_COMPONENTS 0x1003 +#define GL_TEXTURE_RED_SIZE 0x805C +#define GL_TEXTURE_GREEN_SIZE 0x805D +#define GL_TEXTURE_BLUE_SIZE 0x805E +#define GL_TEXTURE_ALPHA_SIZE 0x805F +#define GL_TEXTURE_LUMINANCE_SIZE 0x8060 +#define GL_TEXTURE_INTENSITY_SIZE 0x8061 +#define GL_NEAREST_MIPMAP_NEAREST 0x2700 +#define GL_NEAREST_MIPMAP_LINEAR 0x2702 +#define GL_LINEAR_MIPMAP_NEAREST 0x2701 +#define GL_LINEAR_MIPMAP_LINEAR 0x2703 +#define GL_OBJECT_LINEAR 0x2401 +#define GL_OBJECT_PLANE 0x2501 +#define GL_EYE_LINEAR 0x2400 +#define GL_EYE_PLANE 0x2502 +#define GL_SPHERE_MAP 0x2402 +#define GL_NORMAL_MAP 0x8511 +#define GL_REFLECTION_MAP 0x8512 +#define GL_DECAL 0x2101 +#define GL_MODULATE 0x2100 +#define GL_NEAREST 0x2600 +#define GL_REPEAT 0x2901 +#define GL_CLAMP 0x2900 +#define GL_S 0x2000 +#define GL_T 0x2001 +#define GL_R 0x2002 +#define GL_Q 0x2003 +#define GL_TEXTURE_GEN_R 0x0C62 +#define GL_TEXTURE_GEN_Q 0x0C63 +#define GL_PROXY_TEXTURE_1D 0x8063 +#define GL_PROXY_TEXTURE_2D 0x8064 +#define GL_PROXY_TEXTURE_3D 0x8070 +#define GL_TEXTURE_MIN_LOD 0x813A +#define GL_TEXTURE_MAX_LOD 0x813B +#define GL_TEXTURE_FILTER_CONTROL 0x8500 +#define GL_TEXTURE_LOD_BIAS 0x8501 +#define GL_TEXTURE_CUBE_MAP 0x8513 +#define GL_TEXTURE_GEN_STR 0x8D60 +#define GL_CLAMP_TO_BORDER 0x812D +#define GL_MAX_TEXTURE_COORDS 0x8871 + +#define GL_TEXTURE_COMPARE_MODE 0x884C + +// GL_ARB_point_sprite +#define GL_POINT_SPRITE 0x8861 +#define GL_COORD_REPLACE 0x8862 + +// GL_ARB_texture_rectangle +#define GL_TEXTURE_RECTANGLE_ARB 0x84F5 +#define GL_TEXTURE_BINDING_RECTANGLE_ARB 0x84F6 +#define GL_PROXY_TEXTURE_RECTANGLE_ARB 0x84F7 +#define GL_MAX_RECTANGLE_TEXTURE_SIZE_ARB 0x84F8 + +#define GL_LINE_SMOOTH 0x0B20 +#define GL_LINE_STIPPLE 0x0B24 +#define GL_LINE_STIPPLE_PATTERN 0x0B25 +#define GL_LINE_STIPPLE_REPEAT 0x0B26 +#define GL_LINE_WIDTH 0x0B21 +#define GL_LINE_WIDTH_GRANULARITY 0x0B23 +#define GL_LINE_WIDTH_RANGE 0x0B22 + +#define GL_OBJECT_LINEAR 0x2401 +#define GL_OBJECT_PLANE 0x2501 +#define GL_EYE_LINEAR 0x2400 +#define GL_EYE_PLANE 0x2502 +#define GL_SPHERE_MAP 0x2402 + +#define GL_CURRENT_BIT 0x00001 +#define GL_POINT_BIT 0x00002 +#define GL_LINE_BIT 0x00004 +#define GL_POLYGON_BIT 0x00008 +#define GL_POLYGON_STIPPLE_BIT 0x00010 +#define GL_PIXEL_MODE_BIT 0x00020 +#define GL_LIGHTING_BIT 0x00040 +#define GL_FOG_BIT 0x00080 +// some of these are already defined in GLES +// #define GL_DEPTH_BUFFER_BIT 0x00100 +#define GL_ACCUM_BUFFER_BIT 0x00200 +// #define GL_STENCIL_BUFFER_BIT 0x00400 +#define GL_VIEWPORT_BIT 0x00800 +#define GL_TRANSFORM_BIT 0x01000 +#define GL_ENABLE_BIT 0x02000 +// #define GL_COLOR_BUFFER_BIT 0x04000 +#define GL_HINT_BIT 0x08000 +#define GL_EVAL_BIT 0x10000 +#define GL_LIST_BIT 0x20000 +#define GL_TEXTURE_BIT 0x40000 +#define GL_SCISSOR_BIT 0x80000 +#define GL_ALL_ATTRIB_BITS 0xFFFFF +#define GL_MULTISAMPLE_BIT 0x20000000 + +#define GL_CLIENT_PIXEL_STORE_BIT 0x00000001 +#define GL_CLIENT_VERTEX_ARRAY_BIT 0x00000002 +#define GL_ALL_CLIENT_ATTRIB_BITS 0xFFFFFFFF +#define GL_CLIENT_ALL_ATTRIB_BITS 0xFFFFFFFF + +// secondary color +#define GL_SECONDARY_COLOR_ARRAY_SIZE 0x845A +#define GL_SECONDARY_COLOR_ARRAY_TYPE 0x845B +#define GL_SECONDARY_COLOR_ARRAY_STRIDE 0x845C +#define GL_SECONDARY_COLOR_ARRAY_POINTER 0x845D +#define GL_SECONDARY_COLOR_ARRAY 0x845E +#define GL_SECONDARY_COLOR_ARRAY_BUFFER_BINDING 0x889C +#define GL_COLOR_SUM 0x8458 +#define GL_CURRENT_SECONDARY_COLOR 0x8459 + + +// pixel formats +#define GL_COLOR_INDEX 0x1900 +#define GL_RED 0x1903 +#define GL_R3_G3_B2 0x2A10 +#define GL_RG 0x8227 +#define GL_BGR 0x80E0 +#define GL_BGRA 0x80E1 +#define GL_UNSIGNED_BYTE_3_3_2 0x8032 +#define GL_UNSIGNED_BYTE_2_3_3_REV 0x8362 +#define GL_UNSIGNED_SHORT_5_6_5 0x8363 +#define GL_UNSIGNED_SHORT_5_6_5_REV 0x8364 +#define GL_UNSIGNED_SHORT_4_4_4_4 0x8033 +#define GL_UNSIGNED_SHORT_4_4_4_4_REV 0x8365 +#define GL_UNSIGNED_SHORT_5_5_5_1 0x8034 +#define GL_UNSIGNED_SHORT_1_5_5_5_REV 0x8366 +#define GL_UNSIGNED_INT_8_8_8_8 0x8035 +#define GL_UNSIGNED_INT_8_8_8_8_REV 0x8367 +#define GL_UNSIGNED_INT_10_10_10_2 0x8036 +#define GL_UNSIGNED_INT_2_10_10_10_REV 0x8368 +#define GL_RGB8 0x8051 +#define GL_RGB5 0x8050 +#define GL_RGBA8 0x8058 +#define GL_RGBA16 0x805B +#define GL_ALPHA4 0x803B +#define GL_ALPHA8 0x803C +#define GL_ALPHA12 0x803D +#define GL_ALPHA16 0x803E +#define GL_ALPHA16F 0x881C +#define GL_ALPHA32F 0x8816 +#define GL_LUMINANCE4 0x803F +#define GL_LUMINANCE8 0x8040 +#define GL_LUMINANCE12 0x8041 +#define GL_LUMINANCE16 0x8042 +#define GL_LUMINANCE16F 0x881E +#define GL_LUMINANCE32F 0x8818 +#define GL_LUMINANCE4_ALPHA4 0x8043 +#define GL_LUMINANCE6_ALPHA2 0x8044 +#define GL_LUMINANCE8_ALPHA8 0x8045 +#define GL_LUMINANCE12_ALPHA4 0x8046 +#define GL_LUMINANCE12_ALPHA12 0x8047 +#define GL_LUMINANCE16_ALPHA16 0x8048 +#define GL_LUMINANCE_ALPHA16F 0x881F +#define GL_LUMINANCE_ALPHA32F 0x8819 +#define GL_INTENSITY 0x8049 +#define GL_INTENSITY4 0x804A +#define GL_INTENSITY8 0x804B +#define GL_INTENSITY12 0x804C +#define GL_INTENSITY16 0x804D +#define GL_INTENSITY16F 0x881D +#define GL_INTENSITY32F 0x8817 +#define GL_RGB10_A2 0x8059 +#define GL_RGBA16F 0x881A +#define GL_RGB16F 0x881B +#define GL_RGBA32F 0x8814 +#define GL_RGB32F 0x8815 +#define GL_LUMINANCE16_ALPHA16 0x8048 +#define GL_RGB16 0x8054 +#define GL_RGBA4 0x8056 +#define GL_RGB5_A1 0x8057 +#define GL_COMPRESSED_ALPHA 0x84E9 +#define GL_COMPRESSED_LUMINANCE 0x84EA +#define GL_COMPRESSED_LUMINANCE_ALPHA 0x84EB +#define GL_COMPRESSED_INTENSITY 0x84EC +#define GL_COMPRESSED_RGB 0x84ED +#define GL_COMPRESSED_RGBA 0x84EE +#define GL_COMPRESSED_TEXTURE_FORMATS 0x86A3 +#define GL_HALF_FLOAT_OES 0x8D61 +#define GL_RGB565 0x8D62 + +// types +#define GL_BYTE 0x1400 +#define GL_UNSIGNED_BYTE 0x1401 +#define GL_SHORT 0x1402 +#define GL_UNSIGNED_SHORT 0x1403 +#define GL_INT 0x1404 +#define GL_UNSIGNED_INT 0x1405 +#define GL_FLOAT 0x1406 +#define GL_2_BYTES 0x1407 +#define GL_3_BYTES 0x1408 +#define GL_4_BYTES 0x1409 +#define GL_DOUBLE 0x140A +#define GL_HALF_FLOAT 0x140B +#define GL_BITMAP 0x1A00 + +#define GL_COMPILE 0x1300 +#define GL_COMPILE_AND_EXECUTE 0x1301 + +// fog +#define GL_FOG 0x0B60 +#define GL_FOG_MODE 0x0B65 +#define GL_FOG_DENSITY 0x0B62 +#define GL_FOG_COLOR 0x0B66 +#define GL_FOG_INDEX 0x0B61 +#define GL_FOG_START 0x0B63 +#define GL_FOG_END 0x0B64 +#define GL_LINEAR 0x2601 +#define GL_EXP 0x0800 +#define GL_EXP2 0x0801 +#define GL_FOG_COORDINATE_SOURCE 0x8450 +#define GL_FOG_COORD_SRC GL_FOG_COORDINATE_SOURCE +#define GL_FRAGMENT_DEPTH 0x8452 +#define GL_FOG_COORDINATE 0x8451 +#define GL_FOG_COORD GL_FOG_COORDINATE +#define GL_CURRENT_FOG_COORD 0x8453 +#define GL_FOG_COORD_ARRAY_TYPE 0x8454 +#define GL_FOG_COORD_ARRAY_STRIDE 0x8455 +#define GL_FOG_COORD_ARRAY_POINTER 0x8456 +#define GL_FOG_COORD_ARRAY 0x8457 +#define GL_FOG_COORD_ARRAY_BUFFER_BINDING 0x889D + +// lighting +#define GL_LIGHTING 0x0B50 +#define GL_LIGHT0 0x4000 +#define GL_LIGHT1 0x4001 +#define GL_LIGHT2 0x4002 +#define GL_LIGHT3 0x4003 +#define GL_LIGHT4 0x4004 +#define GL_LIGHT5 0x4005 +#define GL_LIGHT6 0x4006 +#define GL_LIGHT7 0x4007 +#define GL_SPOT_EXPONENT 0x1205 +#define GL_SPOT_CUTOFF 0x1206 +#define GL_CONSTANT_ATTENUATION 0x1207 +#define GL_LINEAR_ATTENUATION 0x1208 +#define GL_QUADRATIC_ATTENUATION 0x1209 +#define GL_AMBIENT 0x1200 +#define GL_DIFFUSE 0x1201 +#define GL_SPECULAR 0x1202 +#define GL_SHININESS 0x1601 +#define GL_EMISSION 0x1600 +#define GL_POSITION 0x1203 +#define GL_SPOT_DIRECTION 0x1204 +#define GL_AMBIENT_AND_DIFFUSE 0x1602 +#define GL_COLOR_INDEXES 0x1603 +#define GL_LIGHT_MODEL_TWO_SIDE 0x0B52 +#define GL_LIGHT_MODEL_LOCAL_VIEWER 0x0B51 +#define GL_LIGHT_MODEL_AMBIENT 0x0B53 +#define GL_FRONT_AND_BACK 0x0408 +#define GL_SHADE_MODEL 0x0B54 +#define GL_FLAT 0x1D00 +#define GL_SMOOTH 0x1D01 +#define GL_COLOR_MATERIAL 0x0B57 +#define GL_COLOR_MATERIAL_FACE 0x0B55 +#define GL_COLOR_MATERIAL_PARAMETER 0x0B56 +#define GL_NORMALIZE 0x0BA1 +#define GL_DRAW_BUFFER 0x0C01 +#define GL_LIGHT_MODEL_COLOR_CONTROL 0x81F8 +#define GL_SINGLE_COLOR 0x81F9 +#define GL_SEPARATE_SPECULAR_COLOR 0x81FA + +// stencil +#define GL_STENCIL_BACK_FUNC 0x8800 +#define GL_STENCIL_BACK_VALUE_MASK 0x8CA4 +#define GL_STENCIL_BACK_REF 0x8CA3 +#define GL_STENCIL_BACK_WRITEMASK 0x8CA5 +#define GL_STENCIL_BACK_FAIL 0x8801 +#define GL_STENCIL_BACK_PASS_DEPTH_FAIL 0x8802 +#define GL_STENCIL_BACK_PASS_DEPTH_PASS 0x8803 + +// pixel transfer +#define GL_MAP_COLOR 0x0D10 +#define GL_MAP_STENCIL 0x0D11 +#define GL_INDEX_SHIFT 0x0D12 +#define GL_INDEX_OFFSET 0x0D13 +#define GL_RED_SCALE 0x0D14 +#define GL_RED_BIAS 0x0D15 +#define GL_GREEN_SCALE 0x0D18 +#define GL_GREEN_BIAS 0x0D19 +#define GL_BLUE_SCALE 0x0D1A +#define GL_BLUE_BIAS 0x0D1B +#define GL_ALPHA_SCALE 0x0D1C +#define GL_ALPHA_BIAS 0x0D1D +#define GL_DEPTH_SCALE 0x0D1E +#define GL_DEPTH_BIAS 0x0D1F +#define GL_PIXEL_MAP_S_TO_S_SIZE 0x0CB1 +#define GL_PIXEL_MAP_I_TO_I_SIZE 0x0CB0 +#define GL_PIXEL_MAP_I_TO_R_SIZE 0x0CB2 +#define GL_PIXEL_MAP_I_TO_G_SIZE 0x0CB3 +#define GL_PIXEL_MAP_I_TO_B_SIZE 0x0CB4 +#define GL_PIXEL_MAP_I_TO_A_SIZE 0x0CB5 +#define GL_PIXEL_MAP_R_TO_R_SIZE 0x0CB6 +#define GL_PIXEL_MAP_G_TO_G_SIZE 0x0CB7 +#define GL_PIXEL_MAP_B_TO_B_SIZE 0x0CB8 +#define GL_PIXEL_MAP_A_TO_A_SIZE 0x0CB9 +#define GL_PIXEL_MAP_S_TO_S 0x0C71 +#define GL_PIXEL_MAP_I_TO_I 0x0C70 +#define GL_PIXEL_MAP_I_TO_R 0x0C72 +#define GL_PIXEL_MAP_I_TO_G 0x0C73 +#define GL_PIXEL_MAP_I_TO_B 0x0C74 +#define GL_PIXEL_MAP_I_TO_A 0x0C75 +#define GL_PIXEL_MAP_R_TO_R 0x0C76 +#define GL_PIXEL_MAP_G_TO_G 0x0C77 +#define GL_PIXEL_MAP_B_TO_B 0x0C78 +#define GL_PIXEL_MAP_A_TO_A 0x0C79 +#define GL_PACK_ALIGNMENT 0x0D05 +#define GL_PACK_LSB_FIRST 0x0D01 +#define GL_PACK_ROW_LENGTH 0x0D02 +#define GL_PACK_SKIP_PIXELS 0x0D04 +#define GL_PACK_SKIP_ROWS 0x0D03 +#define GL_PACK_SWAP_BYTES 0x0D00 +#define GL_UNPACK_ALIGNMENT 0x0CF5 +#define GL_UNPACK_LSB_FIRST 0x0CF1 +#define GL_UNPACK_ROW_LENGTH 0x0CF2 +#define GL_UNPACK_SKIP_PIXELS 0x0CF4 +#define GL_UNPACK_SKIP_ROWS 0x0CF3 +#define GL_UNPACK_SWAP_BYTES 0x0CF0 +#define GL_UNPACK_IMAGE_HEIGHT 0x806E +#define GL_PACK_IMAGE_HEIGHT 0x806C +#define GL_ZOOM_X 0x0D16 +#define GL_ZOOM_Y 0x0D17 +#define GL_MAX_PIXEL_MAP_TABLE 0x0D34 +#define GL_TEXTURE_BASE_LEVEL 0x813C + +// blending +#define GL_BLEND 0x0BE2 +#define GL_BLEND_SRC 0x0BE1 +#define GL_BLEND_DST 0x0BE0 +#define GL_SRC_COLOR 0x0300 +#define GL_ONE_MINUS_SRC_COLOR 0x0301 +#define GL_SRC_ALPHA 0x0302 +#define GL_ONE_MINUS_SRC_ALPHA 0x0303 +#define GL_DST_ALPHA 0x0304 +#define GL_ONE_MINUS_DST_ALPHA 0x0305 +#define GL_DST_COLOR 0x0306 +#define GL_ONE_MINUS_DST_COLOR 0x0307 +#define GL_SRC_ALPHA_SATURATE 0x0308 +#define GL_CONSTANT_COLOR 0x8001 +#define GL_ONE_MINUS_CONSTANT_COLOR 0x8002 +#define GL_CONSTANT_ALPHA 0x8003 +#define GL_ONE_MINUS_CONSTANT_ALPHA 0x8004 +#define GL_DOT3_RGB_EXT 0x8740 +#define GL_DOT3_RGBA_EXT 0x8741 +#define GL_BLEND_DST_RGB 0x80C8 +#define GL_BLEND_SRC_RGB 0x80C9 +#define GL_BLEND_DST_ALPHA 0x80CA +#define GL_BLEND_SRC_ALPHA 0x80CB + +// glGet +#define GL_AUX_BUFFERS 0x0C00 +#define GL_MAX_ELEMENTS_VERTICES 0x80E8 +#define GL_MAX_ELEMENTS_INDICES 0x80E9 +#define GL_POINT_SIZE_RANGE 0x0B12 +#define GL_RENDER_MODE 0x0C40 +#define GL_NAME_STACK_DEPTH 0x0D70 +#define GL_MAX_NAME_STACK_DEPTH 0x0D37 +#define GL_MAX_TEXTURE_IMAGE_UNITS 0x8872 +#define GL_TRANSPOSE_MODELVIEW_MATRIX 0x84E3 +#define GL_TRANSPOSE_PROJECTION_MATRIX 0x84E4 +#define GL_TRANSPOSE_TEXTURE_MATRIX 0x84E5 +#define GL_TRANSPOSE_COLOR_MATRIX 0x84E6 +#define GL_INDEX_ARRAY_POINTER 0x8091 +#define GL_EDGE_FLAG_ARRAY_POINTER 0x8093 +#define GL_FEEDBACK_BUFFER_POINTER 0x0DF0 +#define GL_SELECTION_BUFFER_POINTER 0x0DF3 + +// evaluators +#define GL_AUTO_NORMAL 0x0D80 +#define GL_MAP1_COLOR_4 0x0D90 +#define GL_MAP1_INDEX 0x0D91 +#define GL_MAP1_NORMAL 0x0D92 +#define GL_MAP1_TEXTURE_COORD_1 0x0D93 +#define GL_MAP1_TEXTURE_COORD_2 0x0D94 +#define GL_MAP1_TEXTURE_COORD_3 0x0D95 +#define GL_MAP1_TEXTURE_COORD_4 0x0D96 +#define GL_MAP1_VERTEX_3 0x0D97 +#define GL_MAP1_VERTEX_4 0x0D98 +#define GL_MAP2_COLOR_4 0x0DB0 +#define GL_MAP2_INDEX 0x0DB1 +#define GL_MAP2_NORMAL 0x0DB2 +#define GL_MAP2_TEXTURE_COORD_1 0x0DB3 +#define GL_MAP2_TEXTURE_COORD_2 0x0DB4 +#define GL_MAP2_TEXTURE_COORD_3 0x0DB5 +#define GL_MAP2_TEXTURE_COORD_4 0x0DB6 +#define GL_MAP2_VERTEX_3 0x0DB7 +#define GL_MAP2_VERTEX_4 0x0DB8 +#define GL_MAP1_GRID_DOMAIN 0x0DD0 +#define GL_MAP1_GRID_SEGMENTS 0x0DD1 +#define GL_MAP2_GRID_DOMAIN 0x0DD2 +#define GL_MAP2_GRID_SEGMENTS 0x0DD3 +#define GL_COEFF 0x0A00 +#define GL_ORDER 0x0A01 +#define GL_DOMAIN 0x0A02 +#define GL_MAX_LIST_NESTING 0x0B31 + +/* polygons */ +#define GL_POINT 0x1B00 +#define GL_LINE 0x1B01 +#define GL_FILL 0x1B02 +#define GL_CW 0x0900 +#define GL_CCW 0x0901 +#define GL_FRONT 0x0404 +#define GL_BACK 0x0405 +#define GL_POLYGON_MODE 0x0B40 +#define GL_POLYGON_SMOOTH 0x0B41 +#define GL_POLYGON_STIPPLE 0x0B42 +#define GL_EDGE_FLAG 0x0B43 +#define GL_CULL_FACE 0x0B44 +#define GL_CULL_FACE_MODE 0x0B45 +#define GL_FRONT_FACE 0x0B46 +#define GL_POLYGON_OFFSET_FACTOR 0x8038 +#define GL_POLYGON_OFFSET_UNITS 0x2A00 +#define GL_POLYGON_OFFSET_POINT 0x2A01 +#define GL_POLYGON_OFFSET_LINE 0x2A02 + +/* Shader Source */ +#define GL_SHADING_LANGUAGE_VERSION 0x8B8C +#define GL_COMPILE_STATUS 0x8B81 +#define GL_INFO_LOG_LENGTH 0x8B84 +#define GL_SHADER_SOURCE_LENGTH 0x8B88 +#define GL_SHADER_COMPILER 0x8DFA + +/* Shader Binary */ +#define GL_SHADER_BINARY_FORMATS 0x8DF8 +#define GL_NUM_SHADER_BINARY_FORMATS 0x8DF9 + +/* Shader Precision-Specified Types */ +#define GL_LOW_FLOAT 0x8DF0 +#define GL_MEDIUM_FLOAT 0x8DF1 +#define GL_HIGH_FLOAT 0x8DF2 +#define GL_LOW_INT 0x8DF3 +#define GL_MEDIUM_INT 0x8DF4 +#define GL_HIGH_INT 0x8DF5 + +/* Texture Parameters */ +#define GL_TEXTURE_INTERNAL_FORMAT 0x1003 +#define GL_TEXTURE_RED_SIZE 0x805C +#define GL_TEXTURE_GREEN_SIZE 0x805D +#define GL_TEXTURE_BLUE_SIZE 0x805E +#define GL_TEXTURE_ALPHA_SIZE 0x805F +#define GL_TEXTURE_LUMINANCE_SIZE 0x8060 +#define GL_TEXTURE_INTENSITY_SIZE 0x8061 +#define GL_TEXTURE_RED_TYPE 0x8C10 +#define GL_TEXTURE_GREEN_TYPE 0x8C11 +#define GL_TEXTURE_BLUE_TYPE 0x8C12 +#define GL_TEXTURE_ALPHA_TYPE 0x8C13 +#define GL_TEXTURE_DEPTH_TYPE 0x8C16 +#define GL_TEXTURE_DEPTH 0x8071 +#define GL_TEXTURE_DEPTH_SIZE 0x884A +#define GL_TEXTURE_COMPRESSED_IMAGE_SIZE 0x86A0 +#define GL_TEXTURE_COMPRESSED 0x86A1 +#define GL_TEXTURE_MAX_LEVEL 0x813D + +/* Compressed Textures */ +#define GL_COMPRESSED_RGB_S3TC_DXT1_EXT 0x83F0 +#define GL_COMPRESSED_RGBA_S3TC_DXT1_EXT 0x83F1 +#define GL_COMPRESSED_RGBA_S3TC_DXT3_EXT 0x83F2 +#define GL_COMPRESSED_RGBA_S3TC_DXT5_EXT 0x83F3 +#define GL_TEXTURE_COMPRESSION_HINT 0x84EF + +/* Render Mode */ +#define GL_SELECT 0x1c02 +#define GL_RENDER 0x1C00 + +/* Interleaved Array */ +#define GL_V2F 0x2A20 +#define GL_V3F 0x2A21 +#define GL_C4UB_V2F 0x2A22 +#define GL_C4UB_V3F 0x2A23 +#define GL_C3F_V3F 0x2A24 +#define GL_N3F_V3F 0x2A25 +#define GL_C4F_N3F_V3F 0x2A26 +#define GL_T2F_V3F 0x2A27 +#define GL_T4F_V4F 0x2A28 +#define GL_T2F_C4UB_V3F 0x2A29 +#define GL_T2F_C3F_V3F 0x2A2A +#define GL_T2F_N3F_V3F 0x2A2B +#define GL_T2F_C4F_N3F_V3F 0x2A2C +#define GL_T4F_C4F_N3F_V4F 0x2A2D + +/* Buffers Array */ +#define GL_BUFFER_SIZE 0x8764 +#define GL_BUFFER_USAGE 0x8765 +#define GL_QUERY_COUNTER_BITS 0x8864 +#define GL_CURRENT_QUERY 0x8865 +#define GL_QUERY_RESULT 0x8866 +#define GL_QUERY_RESULT_AVAILABLE 0x8867 +#define GL_ARRAY_BUFFER 0x8892 +#define GL_ELEMENT_ARRAY_BUFFER 0x8893 +#define GL_ARRAY_BUFFER_BINDING 0x8894 +#define GL_ELEMENT_ARRAY_BUFFER_BINDING 0x8895 +#define GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING 0x889F +#define GL_READ_ONLY 0x88B8 +#define GL_WRITE_ONLY 0x88B9 +#define GL_READ_WRITE 0x88BA +#define GL_BUFFER_ACCESS 0x88BB +#define GL_BUFFER_MAPPED 0x88BC +#define GL_BUFFER_MAP_POINTER 0x88BD +#define GL_STREAM_DRAW 0x88E0 +#define GL_STREAM_READ 0x88E1 +#define GL_STREAM_COPY 0x88E2 +#define GL_STATIC_DRAW 0x88E4 +#define GL_STATIC_READ 0x88E5 +#define GL_STATIC_COPY 0x88E6 +#define GL_DYNAMIC_DRAW 0x88E8 +#define GL_DYNAMIC_READ 0x88E9 +#define GL_DYNAMIC_COPY 0x88EA +#define GL_SAMPLES_PASSED 0x8914 +#define GL_SRC1_ALPHA 0x8589 +#define GL_VERTEX_ARRAY_BUFFER_BINDING 0x8896 +#define GL_NORMAL_ARRAY_BUFFER_BINDING 0x8897 +#define GL_COLOR_ARRAY_BUFFER_BINDING 0x8898 +#define GL_INDEX_ARRAY_BUFFER_BINDING 0x8899 +#define GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING 0x889A +#define GL_EDGE_FLAG_ARRAY_BUFFER_BINDING 0x889B +#define GL_SECONDARY_COLOR_ARRAY_BUFFER_BINDING 0x889C +#define GL_FOG_COORDINATE_ARRAY_BUFFER_BINDING 0x889D +#define GL_WEIGHT_ARRAY_BUFFER_BINDING 0x889E +#define GL_MAP_READ_BIT 0x0001 +#define GL_MAP_WRITE_BIT 0x0002 +#define GL_BUFFER_ACCESS_FLAGS 0x911F +#define GL_BUFFER_MAP_LENGTH 0x9120 +#define GL_BUFFER_MAP_OFFSET 0x9121 +#define GL_READ_ONLY 0x88B8 +#define GL_WRITE_ONLY 0x88B9 +#define GL_READ_WRITE 0x88BA +#define GL_PIXEL_PACK_BUFFER 0x88EB +#define GL_PIXEL_UNPACK_BUFFER 0x88EC +#define GL_PIXEL_UNPACK_BUFFER_BINDING 0x88EF +#define GL_PIXEL_PACK_BUFFER_BINDING 0x88ED +#define GL_CURRENT_VERTEX_ATTRIB 0x8626 + +/* Framebuffers */ +#define GL_INVALID_FRAMEBUFFER_OPERATION 0x0506 +#define GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING 0x8210 +#define GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE 0x8211 +#define GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE 0x8212 +#define GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE 0x8213 +#define GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE 0x8214 +#define GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE 0x8215 +#define GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE 0x8216 +#define GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE 0x8217 +#define GL_FRAMEBUFFER_DEFAULT 0x8218 +#define GL_FRAMEBUFFER_UNDEFINED 0x8219 +#define GL_DEPTH_STENCIL_ATTACHMENT 0x821A +#define GL_MAX_RENDERBUFFER_SIZE 0x84E8 +#define GL_DEPTH_STENCIL 0x84F9 +#define GL_UNSIGNED_INT_24_8 0x84FA +#define GL_DEPTH24_STENCIL8 0x88F0 +#define GL_TEXTURE_STENCIL_SIZE 0x88F1 +#define GL_TEXTURE_RED_TYPE 0x8C10 +#define GL_TEXTURE_GREEN_TYPE 0x8C11 +#define GL_TEXTURE_BLUE_TYPE 0x8C12 +#define GL_TEXTURE_ALPHA_TYPE 0x8C13 +#define GL_TEXTURE_DEPTH_TYPE 0x8C16 +#define GL_UNSIGNED_NORMALIZED 0x8C17 +#define GL_FRAMEBUFFER_BINDING 0x8CA6 +#ifndef GL_DRAW_FRAMEBUFFER_BINDING +#define GL_DRAW_FRAMEBUFFER_BINDING GL_FRAMEBUFFER_BINDING +#endif +#define GL_RENDERBUFFER_BINDING 0x8CA7 +#define GL_READ_FRAMEBUFFER 0x8CA8 +#define GL_DRAW_FRAMEBUFFER 0x8CA9 +#define GL_READ_FRAMEBUFFER_BINDING 0x8CAA +#define GL_RENDERBUFFER_SAMPLES 0x8CAB +#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE 0x8CD0 +#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME 0x8CD1 +#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL 0x8CD2 +#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE 0x8CD3 +#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER 0x8CD4 +#define GL_FRAMEBUFFER_COMPLETE 0x8CD5 +#define GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT 0x8CD6 +#define GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT 0x8CD7 +#define GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER 0x8CDB +#define GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER 0x8CDC +#define GL_FRAMEBUFFER_UNSUPPORTED 0x8CDD +#define GL_MAX_COLOR_ATTACHMENTS 0x8CDF +#define GL_COLOR_ATTACHMENT0 0x8CE0 +#define GL_COLOR_ATTACHMENT1 0x8CE1 +#define GL_COLOR_ATTACHMENT2 0x8CE2 +#define GL_COLOR_ATTACHMENT3 0x8CE3 +#define GL_COLOR_ATTACHMENT4 0x8CE4 +#define GL_COLOR_ATTACHMENT5 0x8CE5 +#define GL_COLOR_ATTACHMENT6 0x8CE6 +#define GL_COLOR_ATTACHMENT7 0x8CE7 +#define GL_COLOR_ATTACHMENT8 0x8CE8 +#define GL_COLOR_ATTACHMENT9 0x8CE9 +#define GL_COLOR_ATTACHMENT10 0x8CEA +#define GL_COLOR_ATTACHMENT11 0x8CEB +#define GL_COLOR_ATTACHMENT12 0x8CEC +#define GL_COLOR_ATTACHMENT13 0x8CED +#define GL_COLOR_ATTACHMENT14 0x8CEE +#define GL_COLOR_ATTACHMENT15 0x8CEF +#define GL_DEPTH_ATTACHMENT 0x8D00 +#define GL_STENCIL_ATTACHMENT 0x8D20 +#define GL_FRAMEBUFFER 0x8D40 +#define GL_RENDERBUFFER 0x8D41 +#define GL_RENDERBUFFER_WIDTH 0x8D42 +#define GL_RENDERBUFFER_HEIGHT 0x8D43 +#define GL_RENDERBUFFER_INTERNAL_FORMAT 0x8D44 +#define GL_STENCIL_INDEX1 0x8D46 +#define GL_STENCIL_INDEX4 0x8D47 +#define GL_STENCIL_INDEX8 0x8D48 +#define GL_STENCIL_INDEX16 0x8D49 +#define GL_RENDERBUFFER_RED_SIZE 0x8D50 +#define GL_RENDERBUFFER_GREEN_SIZE 0x8D51 +#define GL_RENDERBUFFER_BLUE_SIZE 0x8D52 +#define GL_RENDERBUFFER_ALPHA_SIZE 0x8D53 +#define GL_RENDERBUFFER_DEPTH_SIZE 0x8D54 +#define GL_RENDERBUFFER_STENCIL_SIZE 0x8D55 +#define GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE 0x8D56 +#define GL_MAX_SAMPLES 0x8D57 +#define GL_INDEX 0x8222 +#define GL_TEXTURE_LUMINANCE_TYPE 0x8C14 +#define GL_TEXTURE_INTENSITY_TYPE 0x8C15 +#define GL_DEPTH_COMPONENT32 0x81A7 +#define GL_DEPTH_COMPONENT24 0x81A6 +#define GL_DEPTH_COMPONENT16 0x81A5 +#define GL_DEPTH_COMPONENT 0x1902 +#define GL_MAX_DRAW_BUFFERS_ARB 0x8824 + +// point sprite extension +#define GL_POINT_SPRITE_COORD_ORIGIN 0x8CA0 +#define GL_LOWER_LEFT 0x8CA1 +#define GL_UPPER_LEFT 0x8CA2 + +// clear buffer +#define GL_COLOR 0x1800 +#define GL_DEPTH 0x1801 +#define GL_STENCIL 0x1802 + + +// direct state +#define GL_MATRIX0_ARB 0x88C0 +#define GL_PROGRAM_MATRIX_EXT 0x8E2D +#define GL_TRANSPOSE_PROGRAM_MATRIX_EXT 0x8E2E +#define GL_PROGRAM_MATRIX_STACK_DEPTH_EXT 0x8E2F +#define GL_CURRENT_MATRIX_STACK_DEPTH_ARB 0x8640 +#define GL_TRANSPOSE_CURRENT_MATRIX_ARB 0x88B7 +#define GL_CURRENT_MATRIX_ARB 0x8641 +#define GL_TEXTURE_BUFFER_FORMAT_EXT 0x8C2E +#define GL_TEXTURE_BUFFER_DATA_STORE_BINDING_EXT 0x8C2D +#define GL_TEXTURE_BINDING_CUBE_MAP 0x8514 +#define GL_TEXTURE_BINDING_BUFFER_EXT 0x8C2C +#define GL_TEXTURE_BINDING_1D 0x8068 +#define GL_TEXTURE_BINDING_2D 0x8069 +#define GL_TEXTURE_BINDING_3D 0x806A +#define GL_TEXTURE_BINDING_2D_ARRAY 0x8C1D +#define GL_TEXTURE_BINDING_1D_ARRAY 0x8C1C +#define GL_CURRENT_RASTER_TEXTURE_COORDS 0x0B06 +#define GL_TEXTURE_COORD_ARRAY_COUNT 0x808B + +// cube mapping +#define GL_TEXTURE_CUBE_MAP 0x8513 +#define GL_TEXTURE_BINDING_CUBE_MAP 0x8514 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_X 0x8515 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_X 0x8516 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_Y 0x8517 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Y 0x8518 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_Z 0x8519 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Z 0x851A +#define GL_PROXY_TEXTURE_CUBE_MAP 0x851B +#define GL_AX_CUBE_MAP_TEXTURE_SIZE 0x851C + +// Shaders +#define GL_FRAGMENT_SHADER 0x8B30 +#define GL_VERTEX_SHADER 0x8B31 +#define GL_MAX_VERTEX_ATTRIBS 0x8869 +#define GL_MAX_VERTEX_UNIFORM_VECTORS 0x8DFB +#define GL_MAX_VARYING_VECTORS 0x8DFC +#define GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS 0x8B4D +#define GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS 0x8B4C +#define GL_MAX_TEXTURE_IMAGE_UNITS 0x8872 +#define GL_MAX_FRAGMENT_UNIFORM_VECTORS 0x8DFD +#define GL_SHADER_TYPE 0x8B4F +#define GL_DELETE_STATUS 0x8B80 +#define GL_LINK_STATUS 0x8B82 +#define GL_VALIDATE_STATUS 0x8B83 +#define GL_ATTACHED_SHADERS 0x8B85 +#define GL_ACTIVE_UNIFORMS 0x8B86 +#define GL_ACTIVE_UNIFORM_MAX_LENGTH 0x8B87 +#define GL_ACTIVE_ATTRIBUTES 0x8B89 +#define GL_ACTIVE_ATTRIBUTE_MAX_LENGTH 0x8B8A +#define GL_SHADING_LANGUAGE_VERSION 0x8B8C +#define GL_CURRENT_PROGRAM 0x8B8D +// Shaders extensions +#define GL_PROGRAM_BINARY_LENGTH 0x8741 +#define GL_NUM_PROGRAM_BINARY_FORMATS 0x87FE +#define GL_PROGRAM_BINARY_FORMATS 0x87FF +#define GL_PROGRAM_OBJECT_ARB 0x8B40 + +// Vertex Arrays +#define GL_VERTEX_ATTRIB_ARRAY_ENABLED 0x8622 +#define GL_VERTEX_ATTRIB_ARRAY_SIZE 0x8623 +#define GL_VERTEX_ATTRIB_ARRAY_STRIDE 0x8624 +#define GL_VERTEX_ATTRIB_ARRAY_TYPE 0x8625 +#define GL_VERTEX_ATTRIB_ARRAY_NORMALIZED 0x886A +#define GL_VERTEX_ATTRIB_ARRAY_POINTER 0x8645 +#define GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING 0x889F + +// Uniform Types +#define GL_FLOAT_VEC2 0x8B50 +#define GL_FLOAT_VEC3 0x8B51 +#define GL_FLOAT_VEC4 0x8B52 +#define GL_INT_VEC2 0x8B53 +#define GL_INT_VEC3 0x8B54 +#define GL_INT_VEC4 0x8B55 +#define GL_BOOL 0x8B56 +#define GL_BOOL_VEC2 0x8B57 +#define GL_BOOL_VEC3 0x8B58 +#define GL_BOOL_VEC4 0x8B59 +#define GL_FLOAT_MAT2 0x8B5A +#define GL_FLOAT_MAT3 0x8B5B +#define GL_FLOAT_MAT4 0x8B5C +#define GL_SAMPLER_2D 0x8B5E +#define GL_SAMPLER_CUBE 0x8B60 + +// Getter +#define GL_NUM_EXTENSIONS 0x821D + +// Anisotropic +#define GL_TEXTURE_MAX_ANISOTROPY 0x84FE +#define GL_MAX_TEXTURE_MAX_ANISOTROPY 0x84FF + +// ATI_texture_env_combine3 +#define GL_MODULATE_ADD_ATI 0x8744 +#define GL_MODULATE_SIGNED_ADD_ATI 0x8745 +#define GL_MODULATE_SUBTRACT_ATI 0x8746 + +// ATIX_texture_env_route +#define GL_SECONDARY_COLOR_ATIX 0x8747 +#define GL_TEXTURE_OUTPUT_RGB_ATIX 0x8748 +#define GL_TEXTURE_OUTPUT_ALPHA_ATIX 0x8749 + +//GL_NV_texture_env_combine4 +#define GL_COMBINE4 0x8503 +#define GL_SRC3_RGB 0x8583 +#define GL_SRC3_ALPHA 0x858B +#define GL_OPERAND3_RGB 0x8593 +#define GL_OPERAND3_ALPHA 0x859B + +//GL_ARB_instanced_arrays +#define GL_VERTEX_ATTRIB_ARRAY_DIVISOR 0x88FE + +#endif // _GL4ES_CONST_H_ diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/debug.c b/Projects/Android/jni/SupportLibs/gl4es/src/gl/debug.c new file mode 100644 index 0000000..c23ef5d --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/debug.c @@ -0,0 +1,368 @@ +#include "debug.h" + +#include +#include "wrap/gles.h" +#include "const.h" +#include "loader.h" +#include "logs.h" +#include "gl4es.h" +#include "gles.h" + +#define p(a) \ + case a: return #a + +const char* PrintEnum(GLenum what) { + static char fallback[64]; + switch(what) + { + // error + p(GL_INVALID_ENUM); + p(GL_INVALID_VALUE); + p(GL_INVALID_OPERATION); + // target + p(GL_TEXTURE_1D); + p(GL_TEXTURE_2D); + p(GL_TEXTURE_3D); + p(GL_TEXTURE_RECTANGLE_ARB); + p(GL_FRAMEBUFFER); + p(GL_RENDERBUFFER); + p(GL_PROXY_TEXTURE_1D); + p(GL_PROXY_TEXTURE_2D); + p(GL_PROXY_TEXTURE_3D); + p(GL_READ_FRAMEBUFFER); + p(GL_DRAW_FRAMEBUFFER); + p(GL_TEXTURE_CUBE_MAP); + p(GL_TEXTURE_CUBE_MAP_POSITIVE_X); + p(GL_TEXTURE_CUBE_MAP_NEGATIVE_X); + p(GL_TEXTURE_CUBE_MAP_POSITIVE_Y); + p(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y); + p(GL_TEXTURE_CUBE_MAP_POSITIVE_Z); + p(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z); + // format + p(GL_COLOR_INDEX); + p(GL_RED); + p(GL_R); + p(GL_R3_G3_B2); + p(GL_RGB); + p(GL_BGR); + p(GL_RGB8); + p(GL_RGB5); + p(GL_RGB16); + p(GL_RGB16F); + p(GL_RGB32F); + p(GL_BGRA); + p(GL_RGBA); + p(GL_RGBA4); + p(GL_RGB5_A1); + p(GL_RGB10_A2); + p(GL_RGBA8); + p(GL_RGBA16); + p(GL_RGBA16F); + p(GL_RGBA32F); + p(GL_COMPRESSED_RGB_S3TC_DXT1_EXT); + p(GL_COMPRESSED_RGBA_S3TC_DXT1_EXT); + p(GL_COMPRESSED_RGBA_S3TC_DXT3_EXT); + p(GL_COMPRESSED_RGBA_S3TC_DXT5_EXT); + p(GL_LUMINANCE8_ALPHA8); + p(GL_LUMINANCE_ALPHA); + p(GL_LUMINANCE4_ALPHA4); + p(GL_LUMINANCE16_ALPHA16); + p(GL_LUMINANCE_ALPHA16F); + p(GL_LUMINANCE_ALPHA32F); + p(GL_LUMINANCE); + p(GL_ALPHA); + p(GL_LUMINANCE8); + p(GL_LUMINANCE16); + p(GL_LUMINANCE16F); + p(GL_LUMINANCE32F); + p(GL_ALPHA8); + p(GL_ALPHA16F); + p(GL_ALPHA32F); + p(GL_COMPRESSED_ALPHA); + p(GL_COMPRESSED_LUMINANCE); + p(GL_COMPRESSED_LUMINANCE_ALPHA); + p(GL_COMPRESSED_RGB); + p(GL_COMPRESSED_RGBA); + p(GL_HALF_FLOAT); + p(GL_INTENSITY); + p(GL_INTENSITY8); + p(GL_INTENSITY16F); + p(GL_INTENSITY32F); + p(GL_DEPTH_STENCIL); + // type + p(GL_BYTE); + p(GL_UNSIGNED_BYTE); + p(GL_UNSIGNED_BYTE_2_3_3_REV); + p(GL_UNSIGNED_BYTE_3_3_2); + p(GL_UNSIGNED_INT); + p(GL_UNSIGNED_SHORT); + p(GL_UNSIGNED_SHORT_5_5_5_1); + p(GL_UNSIGNED_SHORT_1_5_5_5_REV); + p(GL_UNSIGNED_SHORT_4_4_4_4); + p(GL_UNSIGNED_SHORT_4_4_4_4_REV); + p(GL_UNSIGNED_SHORT_5_6_5); + p(GL_UNSIGNED_SHORT_5_6_5_REV); + p(GL_UNSIGNED_INT_8_8_8_8_REV); + p(GL_UNSIGNED_INT_8_8_8_8); + p(GL_FLOAT); + p(GL_DOUBLE); + p(GL_UNSIGNED_INT_24_8); + // texture infos + p(GL_TEXTURE_WIDTH); + p(GL_TEXTURE_HEIGHT); + p(GL_TEXTURE_COMPRESSED); + p(GL_TEXTURE_BORDER); + p(GL_TEXTURE_INTERNAL_FORMAT); + p(GL_MAX_TEXTURE_SIZE); + p(GL_MAX_TEXTURE_COORDS); + // texture pack/unpack + p(GL_UNPACK_ALIGNMENT); + p(GL_PACK_ALIGNMENT); + p(GL_UNPACK_ROW_LENGTH); + // framebuffer + p(GL_COLOR_ATTACHMENT0); + p(GL_COLOR_ATTACHMENT1); + p(GL_COLOR_ATTACHMENT2); + p(GL_COLOR_ATTACHMENT3); + p(GL_COLOR_ATTACHMENT4); + p(GL_DEPTH_ATTACHMENT); + p(GL_DEPTH_STENCIL_ATTACHMENT); + p(GL_STENCIL_ATTACHMENT); + p(GL_DEPTH_COMPONENT); + p(GL_DEPTH24_STENCIL8); + p(GL_MAX_DRAW_BUFFERS_ARB); + // VBO + p(GL_STATIC_DRAW); + p(GL_READ_WRITE); + p(GL_ARRAY_BUFFER); + p(GL_ELEMENT_ARRAY_BUFFER); + p(GL_PIXEL_PACK_BUFFER); + p(GL_PIXEL_UNPACK_BUFFER); + // Texture + p(GL_TEXTURE0); + p(GL_TEXTURE1); + p(GL_TEXTURE2); + p(GL_TEXTURE3); + p(GL_TEXTURE4); + p(GL_TEXTURE5); + p(GL_TEXTURE6); + p(GL_TEXTURE7); + p(GL_TEXTURE_WRAP_S); + p(GL_TEXTURE_WRAP_T); + p(GL_LINEAR); + p(GL_NEAREST); + p(GL_NEAREST_MIPMAP_NEAREST); + p(GL_NEAREST_MIPMAP_LINEAR); + p(GL_LINEAR_MIPMAP_NEAREST); + p(GL_LINEAR_MIPMAP_LINEAR); + p(GL_TEXTURE_MAX_LEVEL); + p(GL_TEXTURE_BASE_LEVEL); + p(GL_TEXTURE_MIN_FILTER); + p(GL_TEXTURE_MAG_FILTER); + p(GL_CLAMP_TO_EDGE); + p(GL_REPEAT); + p(GL_MIRRORED_REPEAT_OES); + p(GL_GENERATE_MIPMAP); + // mode + p(GL_POINTS); + p(GL_LINES); + p(GL_LINE_LOOP); + p(GL_LINE_STRIP); + p(GL_TRIANGLES); + p(GL_TRIANGLE_STRIP); + p(GL_TRIANGLE_FAN); + p(GL_QUADS); + p(GL_QUAD_STRIP); + p(GL_POLYGON); + // texgen + p(GL_S); + p(GL_T); + p(GL_Q); + p(GL_TEXTURE_GEN_MODE); + p(GL_OBJECT_LINEAR); + p(GL_EYE_LINEAR); + p(GL_SPHERE_MAP); + p(GL_NORMAL_MAP); + p(GL_REFLECTION_MAP); + p(GL_TEXTURE_GEN_S); + p(GL_TEXTURE_GEN_T); + p(GL_TEXTURE_GEN_R); + p(GL_TEXTURE_GEN_Q); + // matrix mode + p(GL_PROJECTION); + p(GL_MODELVIEW); + p(GL_TEXTURE); + // blend + p(GL_SRC_ALPHA); + p(GL_DST_ALPHA); + p(GL_ONE_MINUS_SRC_ALPHA); + p(GL_ONE_MINUS_DST_ALPHA); + // lights + p(GL_LIGHT0); + p(GL_LIGHT1); + p(GL_LIGHT2); + p(GL_LIGHT3); + p(GL_LIGHT4); + p(GL_LIGHT5); + p(GL_LIGHT6); + p(GL_LIGHT7); + p(GL_AMBIENT); + p(GL_DIFFUSE); + p(GL_SPECULAR); + p(GL_POSITION); + p(GL_SPOT_DIRECTION); + p(GL_SPOT_EXPONENT); + p(GL_SPOT_CUTOFF); + p(GL_CONSTANT_ATTENUATION); + p(GL_LINEAR_ATTENUATION); + p(GL_QUADRATIC_ATTENUATION); + // Misc enabled + p(GL_LIGHTING); + p(GL_NORMALIZE); + p(GL_CULL_FACE); + p(GL_DEPTH_TEST); + p(GL_RESCALE_NORMAL); + p(GL_ALPHA_TEST); + p(GL_ALPHA_TEST_FUNC); + p(GL_BLEND); + p(GL_BLEND_SRC); + p(GL_BLEND_DST); + p(GL_LOGIC_OP_MODE); + // uniform type + p(GL_FLOAT_VEC2); + p(GL_FLOAT_VEC3); + p(GL_FLOAT_VEC4); + p(GL_INT_VEC2); + p(GL_INT_VEC3); + p(GL_INT_VEC4); + p(GL_BOOL); + p(GL_BOOL_VEC2); + p(GL_BOOL_VEC3); + p(GL_BOOL_VEC4); + p(GL_FLOAT_MAT2); + p(GL_FLOAT_MAT3); + p(GL_FLOAT_MAT4); + p(GL_SAMPLER_2D); + p(GL_SAMPLER_CUBE); + // Shaders + p(GL_FRAGMENT_SHADER); + p(GL_VERTEX_SHADER); + p(GL_MAX_VERTEX_ATTRIBS); + p(GL_MAX_VERTEX_UNIFORM_VECTORS); + p(GL_MAX_VARYING_VECTORS); + p(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS); + p(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS); + p(GL_MAX_TEXTURE_IMAGE_UNITS); + p(GL_MAX_FRAGMENT_UNIFORM_VECTORS); + p(GL_SHADER_TYPE); + p(GL_DELETE_STATUS); + p(GL_LINK_STATUS); + p(GL_COMPILE_STATUS); + p(GL_VALIDATE_STATUS); + p(GL_ATTACHED_SHADERS); + p(GL_ACTIVE_UNIFORMS); + p(GL_ACTIVE_UNIFORM_MAX_LENGTH); + p(GL_ACTIVE_ATTRIBUTES); + p(GL_ACTIVE_ATTRIBUTE_MAX_LENGTH); + p(GL_SHADING_LANGUAGE_VERSION); + p(GL_CURRENT_PROGRAM); + p(GL_PROGRAM_BINARY_LENGTH); + p(GL_NUM_PROGRAM_BINARY_FORMATS); + p(GL_PROGRAM_BINARY_FORMATS); + p(GL_INFO_LOG_LENGTH); + // Client State + p(GL_VERTEX_ARRAY); + p(GL_COLOR_ARRAY); + p(GL_NORMAL_ARRAY); + p(GL_TEXTURE_COORD_ARRAY); + p(GL_SECONDARY_COLOR_ARRAY); + p(GL_FOG_COORD_ARRAY); + // TexEnv + p(GL_POINT_SPRITE); + p(GL_COORD_REPLACE); + p(GL_TEXTURE_FILTER_CONTROL); + p(GL_TEXTURE_LOD_BIAS); + p(GL_TEXTURE_ENV); + p(GL_TEXTURE_ENV_MODE); + p(GL_MODULATE); + p(GL_ADD); + p(GL_DECAL); + p(GL_REPLACE); + p(GL_COMBINE); + p(GL_COMBINE_RGB); + p(GL_ADD_SIGNED); + p(GL_INTERPOLATE); + p(GL_SUBTRACT); + p(GL_DOT3_RGB); + p(GL_DOT3_RGBA); + p(GL_COMBINE_ALPHA); + p(GL_SRC0_RGB); + p(GL_SRC1_RGB); + p(GL_SRC2_RGB); + p(GL_CONSTANT); + p(GL_PRIMARY_COLOR); + p(GL_PREVIOUS); + p(GL_SRC0_ALPHA); + p(GL_SRC1_ALPHA); + p(GL_SRC2_ALPHA); + p(GL_OPERAND0_RGB); + p(GL_OPERAND1_RGB); + p(GL_OPERAND2_RGB); + p(GL_SRC_COLOR); + p(GL_ONE_MINUS_SRC_COLOR); + p(GL_OPERAND0_ALPHA); + p(GL_OPERAND1_ALPHA); + p(GL_OPERAND2_ALPHA); + p(GL_RGB_SCALE); + p(GL_ALPHA_SCALE); + p(GL_TEXTURE_ENV_COLOR); + // misc + p(GL_NUM_EXTENSIONS); + default: + sprintf(fallback, "0x%04X", what); + } + return fallback; +} + +const char* PrintEGLError(int onlyerror) { +#ifdef NOEGL + return ""; +#else + LOAD_EGL(eglGetError); + static char fallback[64]; + GLenum what = egl_eglGetError(); + if(onlyerror && what==EGL_SUCCESS) + return NULL; + switch(what) + { + p(EGL_SUCCESS); + p(EGL_NOT_INITIALIZED); + p(EGL_BAD_ACCESS); + p(EGL_BAD_ALLOC); + p(EGL_BAD_ATTRIBUTE); + p(EGL_BAD_CONTEXT); + p(EGL_BAD_CONFIG); + p(EGL_BAD_CURRENT_SURFACE); + p(EGL_BAD_DISPLAY); + p(EGL_BAD_SURFACE); + p(EGL_BAD_MATCH); + p(EGL_BAD_PARAMETER); + p(EGL_BAD_NATIVE_PIXMAP); + p(EGL_BAD_NATIVE_WINDOW); + p(EGL_CONTEXT_LOST); + default: + sprintf(fallback, "0x%04X", what); + } + return fallback; +#endif +} + +void CheckGLError(int fwd) { + LOAD_GLES(glGetError); + GLenum err=gles_glGetError(); + if(err!=GL_NO_ERROR) { + printf("LIBGL: glGetError(): %s\n", PrintEnum(err)); + if(fwd) + errorShim(err); + } +} \ No newline at end of file diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/debug.h b/Projects/Android/jni/SupportLibs/gl4es/src/gl/debug.h new file mode 100644 index 0000000..f4d7ff8 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/debug.h @@ -0,0 +1,12 @@ +#ifndef _GL4ES_DEBUG_H_ +#define _GL4ES_DEBUG_H_ + +#include "gles.h" + +const char* PrintEnum(GLenum what); + +const char* PrintEGLError(int onlyerror); + +void CheckGLError(int fwd); + +#endif // _GL4ES_DEBUG_H_ diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/decompress.c b/Projects/Android/jni/SupportLibs/gl4es/src/gl/decompress.c new file mode 100644 index 0000000..05fd8c2 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/decompress.c @@ -0,0 +1,324 @@ +#include +#include + +/* +DXT1/DXT3/DXT5 texture decompression + +The original code is from Benjamin Dobell, see below for details. Compared to +the original this one adds DXT3 decompression, is valid C89, and is x64 +compatible as it uses fixed size integers everywhere. It also uses a different +PackRGBA order. + +--- + +Copyright (c) 2012, Matthäus G. "Anteru" Chajdas (http://anteru.net) + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +--- + +Copyright (C) 2009 Benjamin Dobell, Glass Echidna + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +--- +*/ +static uint32_t PackRGBA (uint8_t r, uint8_t g, uint8_t b, uint8_t a) +{ + return r | (g << 8) | (b << 16) | (a << 24); +} + +static void DecompressBlockDXT1Internal (const uint8_t* block, + uint32_t* output, + uint32_t outputStride, + const uint8_t* alphaValues) +{ + uint32_t temp, code; + + uint16_t color0, color1; + uint8_t r0, g0, b0, r1, g1, b1; + + int i, j; + + color0 = *(const uint16_t*)(block); + color1 = *(const uint16_t*)(block + 2); + + temp = (color0 >> 11) * 255 + 16; + r0 = (uint8_t)((temp/32 + temp)/32); + temp = ((color0 & 0x07E0) >> 5) * 255 + 32; + g0 = (uint8_t)((temp/64 + temp)/64); + temp = (color0 & 0x001F) * 255 + 16; + b0 = (uint8_t)((temp/32 + temp)/32); + + temp = (color1 >> 11) * 255 + 16; + r1 = (uint8_t)((temp/32 + temp)/32); + temp = ((color1 & 0x07E0) >> 5) * 255 + 32; + g1 = (uint8_t)((temp/64 + temp)/64); + temp = (color1 & 0x001F) * 255 + 16; + b1 = (uint8_t)((temp/32 + temp)/32); + + code = *(const uint32_t*)(block + 4); + + if (color0 > color1) { + for (j = 0; j < 4; ++j) { + for (i = 0; i < 4; ++i) { + uint32_t finalColor, positionCode; + uint8_t alpha; + + alpha = alphaValues [j*4+i]; + + finalColor = 0; + positionCode = (code >> 2*(4*j+i)) & 0x03; + + switch (positionCode) { + case 0: + finalColor = PackRGBA(r0, g0, b0, alpha); + break; + case 1: + finalColor = PackRGBA(r1, g1, b1, alpha); + break; + case 2: + finalColor = PackRGBA((2*r0+r1)/3, (2*g0+g1)/3, (2*b0+b1)/3, alpha); + break; + case 3: + finalColor = PackRGBA((r0+2*r1)/3, (g0+2*g1)/3, (b0+2*b1)/3, alpha); + break; + } + + output [j*outputStride + i] = finalColor; + } + } + } else { + for (j = 0; j < 4; ++j) { + for (i = 0; i < 4; ++i) { + uint32_t finalColor, positionCode; + uint8_t alpha; + + alpha = alphaValues [j*4+i]; + + finalColor = 0; + positionCode = (code >> 2*(4*j+i)) & 0x03; + + switch (positionCode) { + case 0: + finalColor = PackRGBA(r0, g0, b0, alpha); + break; + case 1: + finalColor = PackRGBA(r1, g1, b1, alpha); + break; + case 2: + finalColor = PackRGBA((r0+r1)/2, (g0+g1)/2, (b0+b1)/2, alpha); + break; + case 3: + finalColor = PackRGBA(0, 0, 0, alpha); + break; + } + + output [j*outputStride + i] = finalColor; + } + } + } +} + +/* +void DecompressBlockDXT1(): Decompresses one block of a DXT1 texture and stores the resulting pixels at the appropriate offset in 'image'. + +uint32_t x: x-coordinate of the first pixel in the block. +uint32_t y: y-coordinate of the first pixel in the block. +uint32_t width: width of the texture being decompressed. +const uint8_t *blockStorage: pointer to the block to decompress. +uint32_t *image: pointer to image where the decompressed pixel data should be stored. +*/ +void DecompressBlockDXT1(uint32_t x, uint32_t y, uint32_t width, + const uint8_t* blockStorage, + uint32_t* image) +{ + static const uint8_t const_alpha [] = { + 255, 255, 255, 255, + 255, 255, 255, 255, + 255, 255, 255, 255, + 255, 255, 255, 255 + }; + + DecompressBlockDXT1Internal (blockStorage, + image + x + (y * width), width, const_alpha); +} + +/* +void DecompressBlockDXT5(): Decompresses one block of a DXT5 texture and stores the resulting pixels at the appropriate offset in 'image'. + +uint32_t x: x-coordinate of the first pixel in the block. +uint32_t y: y-coordinate of the first pixel in the block. +uint32_t width: width of the texture being decompressed. +const uint8_t *blockStorage: pointer to the block to decompress. +uint32_t *image: pointer to image where the decompressed pixel data should be stored. +*/ +void DecompressBlockDXT5(uint32_t x, uint32_t y, uint32_t width, + const uint8_t* blockStorage, uint32_t* image) +{ + uint8_t alpha0, alpha1; + const uint8_t* bits; + uint32_t alphaCode1; + uint16_t alphaCode2; + + uint16_t color0, color1; + uint8_t r0, g0, b0, r1, g1, b1; + + int i, j; + + uint32_t temp, code; + + alpha0 = *(blockStorage); + alpha1 = *(blockStorage + 1); + + bits = blockStorage + 2; + alphaCode1 = bits[2] | (bits[3] << 8) | (bits[4] << 16) | (bits[5] << 24); + alphaCode2 = bits[0] | (bits[1] << 8); + + color0 = *(const uint16_t*)(blockStorage + 8); + color1 = *(const uint16_t*)(blockStorage + 10); + + temp = (color0 >> 11) * 255 + 16; + r0 = (uint8_t)((temp/32 + temp)/32); + temp = ((color0 & 0x07E0) >> 5) * 255 + 32; + g0 = (uint8_t)((temp/64 + temp)/64); + temp = (color0 & 0x001F) * 255 + 16; + b0 = (uint8_t)((temp/32 + temp)/32); + + temp = (color1 >> 11) * 255 + 16; + r1 = (uint8_t)((temp/32 + temp)/32); + temp = ((color1 & 0x07E0) >> 5) * 255 + 32; + g1 = (uint8_t)((temp/64 + temp)/64); + temp = (color1 & 0x001F) * 255 + 16; + b1 = (uint8_t)((temp/32 + temp)/32); + + code = *(const uint32_t*)(blockStorage + 12); + + for (j = 0; j < 4; j++) { + for (i = 0; i < 4; i++) { + uint8_t finalAlpha; + int alphaCode, alphaCodeIndex; + uint8_t colorCode; + uint32_t finalColor; + + alphaCodeIndex = 3*(4*j+i); + if (alphaCodeIndex <= 12) { + alphaCode = (alphaCode2 >> alphaCodeIndex) & 0x07; + } else if (alphaCodeIndex == 15) { + alphaCode = (alphaCode2 >> 15) | ((alphaCode1 << 1) & 0x06); + } else /* alphaCodeIndex >= 18 && alphaCodeIndex <= 45 */ { + alphaCode = (alphaCode1 >> (alphaCodeIndex - 16)) & 0x07; + } + + if (alphaCode == 0) { + finalAlpha = alpha0; + } else if (alphaCode == 1) { + finalAlpha = alpha1; + } else { + if (alpha0 > alpha1) { + finalAlpha = (uint8_t)(((8-alphaCode)*alpha0 + (alphaCode-1)*alpha1)/7); + } else { + if (alphaCode == 6) { + finalAlpha = 0; + } else if (alphaCode == 7) { + finalAlpha = 255; + } else { + finalAlpha = (uint8_t)(((6-alphaCode)*alpha0 + (alphaCode-1)*alpha1)/5); + } + } + } + + colorCode = (code >> 2*(4*j+i)) & 0x03; + finalColor = 0; + + switch (colorCode) { + case 0: + finalColor = PackRGBA(r0, g0, b0, finalAlpha); + break; + case 1: + finalColor = PackRGBA(r1, g1, b1, finalAlpha); + break; + case 2: + finalColor = PackRGBA((2*r0+r1)/3, (2*g0+g1)/3, (2*b0+b1)/3, finalAlpha); + break; + case 3: + finalColor = PackRGBA((r0+2*r1)/3, (g0+2*g1)/3, (b0+2*b1)/3, finalAlpha); + break; + } + + image [i + x + (width* (y+j))] = finalColor; + } + } +} + +/* +void DecompressBlockDXT3(): Decompresses one block of a DXT3 texture and stores the resulting pixels at the appropriate offset in 'image'. + +uint32_t x: x-coordinate of the first pixel in the block. +uint32_t y: y-coordinate of the first pixel in the block. +uint32_t height: height of the texture being decompressed. +const uint8_t *blockStorage: pointer to the block to decompress. +uint32_t *image: pointer to image where the decompressed pixel data should be stored. +*/ +void DecompressBlockDXT3(uint32_t x, uint32_t y, uint32_t width, + const uint8_t* blockStorage, + uint32_t* image) +{ + int i; + + uint8_t alphaValues [16] = { 0 }; + + for (i = 0; i < 4; ++i) { + const uint16_t* alphaData = (const uint16_t*) (blockStorage); + + alphaValues [i*4 + 0] = (((*alphaData) >> 0) & 0xF ) * 17; + alphaValues [i*4 + 1] = (((*alphaData) >> 4) & 0xF ) * 17; + alphaValues [i*4 + 2] = (((*alphaData) >> 8) & 0xF ) * 17; + alphaValues [i*4 + 3] = (((*alphaData) >> 12) & 0xF) * 17; + + blockStorage += 2; + } + + DecompressBlockDXT1Internal (blockStorage, + image + x + (y * width), width, alphaValues); +} + +// Texture DXT1 / DXT5 compression +// Using STB "on file" library +// go there https://github.com/nothings/stb +// for more details and other libs + +#define STB_DXT_IMPLEMENTATION +#include "stb_dxt_104.h" diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/decompress.h b/Projects/Android/jni/SupportLibs/gl4es/src/gl/decompress.h new file mode 100644 index 0000000..75c5038 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/decompress.h @@ -0,0 +1,15 @@ +#ifndef _GL4ES_DECOMPRESS_H_ +#define _GL4ES_DECOMPRESS_H_ + +void DecompressBlockDXT1(uint32_t x, uint32_t y, uint32_t width, + const uint8_t* blockStorage, + uint32_t* image); + +void DecompressBlockDXT3(uint32_t x, uint32_t y, uint32_t width, + const uint8_t* blockStorage, + uint32_t* image); + +void DecompressBlockDXT5(uint32_t x, uint32_t y, uint32_t width, + const uint8_t* blockStorage, uint32_t* image); + +#endif // _GL4ES_DECOMPRESS_H_ diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/depth.c b/Projects/Android/jni/SupportLibs/gl4es/src/gl/depth.c new file mode 100644 index 0000000..8c8adfa --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/depth.c @@ -0,0 +1,74 @@ +#include "depth.h" + +#include "gl4es.h" +#include "glstate.h" +#include "loader.h" + +void gl4es_glDepthFunc(GLenum func) { + if(glstate->list.compiling) { + PUSH_IF_COMPILING(glDepthFunc); + } + noerrorShim(); + if (glstate->depth.func == func) + return; + if(glstate->list.pending) + flush(); + glstate->depth.func = func; + LOAD_GLES(glDepthFunc); + errorGL(); + gles_glDepthFunc(func); +} + +void gl4es_glDepthMask(GLboolean flag) { + if(glstate->list.compiling) { + PUSH_IF_COMPILING(glDepthMask); + } + noerrorShim(); + if (glstate->depth.mask == flag) + return; + if(glstate->list.pending) + flush(); + glstate->depth.mask = flag; + LOAD_GLES(glDepthMask); + errorGL(); + gles_glDepthMask(flag); +} + +GLfloat clamp(GLfloat a) { + return (a<0.f)?0.f:((a>1.f)?1.f:a); +} + +void gl4es_glDepthRangef(GLclampf near, GLclampf far) { + near = clamp(near); + far = clamp(far); + if(glstate->list.compiling) { + PUSH_IF_COMPILING(glDepthRangef); + } + noerrorShim(); + if ((glstate->depth.near == near) && (glstate->depth.far == far)) + return; + if(glstate->list.pending) + flush(); + glstate->depth.near = near; + glstate->depth.far = far; + LOAD_GLES(glDepthRangef); + errorGL(); + gles_glDepthRangef(near, far); +} + +void gl4es_glClearDepthf(GLclampf depth) { + depth = clamp(depth); + if(glstate->list.compiling) { + PUSH_IF_COMPILING(glClearDepthf); + } + noerrorShim(); + glstate->depth.clear = depth; + LOAD_GLES(glClearDepthf); + errorGL(); + gles_glClearDepthf(depth); +} + +void glDepthFunc(GLenum func) AliasExport("gl4es_glDepthFunc"); +void glDepthMask(GLboolean flag) AliasExport("gl4es_glDepthMask"); +void glDepthRangef(GLclampf nearVal, GLclampf farVal) AliasExport("gl4es_glDepthRangef"); + diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/depth.h b/Projects/Android/jni/SupportLibs/gl4es/src/gl/depth.h new file mode 100644 index 0000000..892a7cb --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/depth.h @@ -0,0 +1,11 @@ +#ifndef _GL4ES_DEPTH_H_ +#define _GL4ES_DEPTH_H_ + +#include "gles.h" + +void gl4es_glDepthFunc(GLenum func); +void gl4es_glDepthMask(GLboolean flag); +void gl4es_glDepthRangef(GLclampf nearVal, GLclampf farVal); +void gl4es_glClearDepthf(GLclampf depth); + +#endif // _GL4ES_DEPTH_H_ diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/directstate.c b/Projects/Android/jni/SupportLibs/gl4es/src/gl/directstate.c new file mode 100644 index 0000000..74f4957 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/directstate.c @@ -0,0 +1,602 @@ +#include "directstate.h" + +#include "wrap/gl4es.h" +#include "gles.h" +#include "stack.h" +#include "texgen.h" + +// Client State +void gl4es_glClientAttribDefault(GLbitfield mask) { + if (mask & GL_CLIENT_PIXEL_STORE_BIT) { + gl4es_glPixelStorei(GL_PACK_ALIGNMENT, 0); + gl4es_glPixelStorei(GL_UNPACK_ALIGNMENT, 0); + gl4es_glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); + gl4es_glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0); + gl4es_glPixelStorei(GL_UNPACK_SKIP_ROWS, 0); + gl4es_glPixelStorei(GL_PACK_ROW_LENGTH, 0); + gl4es_glPixelStorei(GL_PACK_SKIP_PIXELS, 0); + gl4es_glPixelStorei(GL_PACK_SKIP_ROWS, 0); + } +#define enable_disable(pname, enabled) \ + if (enabled) gl4es_glEnableClientState(pname); \ + else gl4es_glDisableClientState(pname) + + if (mask & GL_CLIENT_VERTEX_ARRAY_BIT) { + int client = glstate->texture.client; + + enable_disable(GL_VERTEX_ARRAY, false); + enable_disable(GL_NORMAL_ARRAY, false); + enable_disable(GL_COLOR_ARRAY, false); + enable_disable(GL_SECONDARY_COLOR_ARRAY, false); + for (int a=0; atexture.client != client) gl4es_glClientActiveTexture(GL_TEXTURE0+client); + } +} +void gl4es_glPushClientAttribDefault(GLbitfield mask) { + gl4es_glPushClientAttrib(mask); + gl4es_glClientAttribDefault(mask); +} + +// Matrix +#define mat(f) \ + GLenum old_mat; \ + gl4es_glGetIntegerv(GL_MATRIX_MODE, &old_mat); \ + gl4es_glMatrixMode(matrixMode); \ + gl4es_##f; \ + gl4es_glMatrixMode(old_mat) + +void gl4es_glMatrixLoadf(GLenum matrixMode, const GLfloat *m) { + mat(glLoadMatrixf(m)); +} +void gl4es_glMatrixLoadd(GLenum matrixMode, const GLdouble *m) { + mat(glLoadMatrixd(m)); +} +void gl4es_glMatrixMultf(GLenum matrixMode, const GLfloat *m) { + mat(glMultMatrixf(m)); +} +void gl4es_glMatrixMultd(GLenum matrixMode, const GLdouble *m) { + mat(glMultMatrixd(m)); +} +void gl4es_glMatrixLoadIdentity(GLenum matrixMode) { + mat(glLoadIdentity()); +} +void gl4es_glMatrixRotatef(GLenum matrixMode, GLfloat angle, GLfloat x, GLfloat y, GLfloat z) { + mat(glRotatef(angle, x, y, z)); +} +void gl4es_glMatrixRotated(GLenum matrixMode, GLdouble angle, GLdouble x, GLdouble y, GLdouble z) { + mat(glRotated(angle, x, y, z)); +} +void gl4es_glMatrixScalef(GLenum matrixMode, GLfloat x, GLfloat y, GLfloat z) { + mat(glScalef(x, y, z)); +} +void gl4es_glMatrixScaled(GLenum matrixMode, GLdouble x, GLdouble y, GLdouble z) { + mat(glScaled(x, y, z)); +} +void gl4es_glMatrixTranslatef(GLenum matrixMode, GLfloat x, GLfloat y, GLfloat z) { + mat(glTranslatef(x, y, z)); +} +void gl4es_glMatrixTranslated(GLenum matrixMode, GLdouble x, GLdouble y, GLdouble z) { + mat(glTranslated(x, y, z)); +} +void gl4es_glMatrixOrtho(GLenum matrixMode, GLdouble l, GLdouble r, GLdouble b, GLdouble t, GLdouble n, GLdouble f) { + mat(glOrtho(l, r, b ,t, n, f)); +} +void gl4es_glMatrixFrustum(GLenum matrixMode, GLdouble l, GLdouble r, GLdouble b, GLdouble t, GLdouble n, GLdouble f) { + mat(glFrustum(l, r, b, t, n, f)); +} +void gl4es_glMatrixPush(GLenum matrixMode) { + mat(glPushMatrix()); +} +void gl4es_glMatrixPop(GLenum matrixMode) { + mat(glPopMatrix()); +} +void gl4es_glMatrixLoadTransposef(GLenum matrixMode, const GLfloat *m) { + mat(glLoadTransposeMatrixf(m)); +} +void gl4es_glMatrixLoadTransposed(GLenum matrixMode, const GLdouble *m) { + mat(glLoadTransposeMatrixd(m)); +} +void gl4es_glMatrixMultTransposef(GLenum matrixMode, const GLfloat *m) { + mat(glMultTransposeMatrixf(m)); +} +void gl4es_glMatrixMultTransposed(GLenum matrixMode, const GLdouble *m) { + mat(glMultTransposeMatrixd(m)); +} +#undef mat + +// Textures +#define text(f) \ + gl4es_glBindTexture(target, texture); \ + gl4es_##f + +void gl4es_glTextureParameteri(GLuint texture, GLenum target, GLenum pname, GLint param) { + text(glTexParameteri(target, pname, param)); +} +void gl4es_glTextureParameteriv(GLuint texture, GLenum target, GLenum pname, const GLint *param) { + text(glTexParameteriv(target, pname, param)); +} +void gl4es_glTextureParameterf(GLuint texture, GLenum target, GLenum pname, GLfloat param) { + text(glTexParameterf(target, pname, param)); +} +void gl4es_glTextureParameterfv(GLuint texture, GLenum target, GLenum pname, const GLfloat *param) { + text(glTexParameterfv(target, pname, param)); +} +void gl4es_glTextureImage1D(GLuint texture, GLenum target, GLint level, GLint internalformat, GLsizei width, GLint border, GLenum format, GLenum type, const GLvoid *pixels) { + text(glTexImage1D(target, level, internalformat, width, border, format, type, pixels)); +} +void gl4es_glTextureImage2D(GLuint texture, GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels) { + text(glTexImage2D(target, level, internalformat, width, height, border, format, type, pixels)); +} +void gl4es_glTextureSubImage1D(GLuint texture, GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid *pixels) { + text(glTexSubImage1D(target, level, xoffset, width, format, type, pixels)); +} +void gl4es_glTextureSubImage2D(GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels) { + text(glTexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels)); +} +void gl4es_glCopyTextureImage1D(GLuint texture, GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLint border) { + text(glCopyTexImage1D(target, level, internalformat, x, y, width, border)); +} +void gl4es_glCopyTextureImage2D(GLuint texture, GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border) { + text(glCopyTexImage2D(target, level, internalformat, x, y, width, height, border)); +} +void gl4es_glCopyTextureSubImage1D(GLuint texture, GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width) { + text(glCopyTexSubImage1D(target, level, xoffset, x, y, width)); +} +void gl4es_glCopyTextureSubImage2D(GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height) { + text(glCopyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height)); +} +void gl4es_glGetTextureImage(GLuint texture, GLenum target, GLint level, GLenum format, GLenum type, GLvoid *pixels) { + text(glGetTexImage(target, level, format, type, pixels)); +} +void gl4es_glGetTextureParameterfv(GLuint texture, GLenum target, GLenum pname, GLfloat *params) { + text(glGetTexParameterfv(target, pname, params)); +} +void gl4es_glGetTextureParameteriv(GLuint texture, GLenum target, GLenum pname, GLint *params) { + text(glGetTexParameteriv(target, pname, params)); +} +void gl4es_glGetTextureLevelParameterfv(GLuint texture, GLenum target, GLint level, GLenum pname, GLfloat *params) { + text(glGetTexLevelParameterfv(target, level, pname, params)); +} +void gl4es_glGetTextureLevelParameteriv(GLuint texture, GLenum target, GLint level, GLenum pname, GLint *params) { + text(glGetTexLevelParameteriv(target, level, pname, params)); +} + +// Texture 3D +void gl4es_glTextureImage3D(GLuint texture, GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels) { + text(glTexImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels)); +} +void gl4es_glTextureSubImage3D(GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *pixels) { + text(glTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels)); +} +void gl4es_glCopyTextureSubImage3D(GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height) { + text(glCopyTexSubImage3D(target, level, xoffset, yoffset, zoffset, x, y, width, height)); +} +// Compressed texture +void gl4es_glCompressedTextureImage3D(GLuint texture, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid *data) { + text(glCompressedTexImage3D(target, level, internalformat, width, height, depth, border, imageSize, data)); +} +void gl4es_glCompressedTextureImage2D(GLuint texture, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data) { + text(glCompressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data)); +} +void gl4es_glCompressedTextureImage1D(GLuint texture, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const GLvoid *data) { + text(glCompressedTexImage1D(target, level, internalformat, width, border, imageSize, data)); +} +void gl4es_glCompressedTextureSubImage3D(GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid *data) { + text(glCompressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, imageSize, data)); +} +void gl4es_glCompressedTextureSubImage2D(GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *data) { + text(glCompressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize, data)); +} +void gl4es_glCompressedTextureSubImage1D(GLuint texture, GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const GLvoid *data) { + text(glCompressedTexSubImage1D(target, level, xoffset, width, format, imageSize, data)); +} +void gl4es_glGetCompressedTextureImage(GLuint texture, GLenum target, GLint level, GLvoid *img) { + text(glGetCompressedTexImage(target, level, img)); +} + +#undef text +#define text(f) \ + GLenum old_tex = glstate->texture.active; \ + if(texunit != old_tex) gl4es_glActiveTexture(texunit); \ + gl4es_##f; \ + if(texunit != old_tex) gl4es_glActiveTexture(old_tex) +#define texc(f) \ + GLenum old_tex = glstate->texture.client; \ + if(texunit != old_tex) gl4es_glClientActiveTexture(texunit); \ + gl4es_##f; \ + if(texunit != old_tex) gl4es_glClientActiveTexture(old_tex) + +void gl4es_glBindMultiTexture(GLenum texunit, GLenum target, GLuint texture) { + text(glBindTexture(target, texture)); +} +void gl4es_glMultiTexCoordPointer(GLenum texunit, GLint size, GLenum type, GLsizei stride, const GLvoid *pointer) { + texc(glTexCoordPointer(size, type, stride, pointer)); +} +void gl4es_glMultiTexEnvf(GLenum texunit, GLenum target, GLenum pname, GLfloat param) { + text(glTexEnvf(target, pname, param)); +} +void gl4es_glMultiTexEnvfv(GLenum texunit, GLenum target, GLenum pname, const GLfloat *params) { + text(glTexEnvfv(target, pname, params)); +} +void gl4es_glMultiTexEnvi(GLenum texunit, GLenum target, GLenum pname, GLint param) { + text(glTexEnvi(target, pname, param)); +} +void gl4es_glMultiTexEnviv(GLenum texunit, GLenum target, GLenum pname, const GLint *params) { + text(glTexEnviv(target, pname, params)); +} +void gl4es_glMultiTexGend(GLenum texunit, GLenum coord, GLenum pname, GLdouble param) { + text(glTexGend(coord, pname, param)); +} +void gl4es_glMultiTexGendv(GLenum texunit, GLenum coord, GLenum pname, const GLdouble *params) { + text(glTexGendv(coord, pname, params)); +} +void gl4es_glMultiTexGenf(GLenum texunit, GLenum coord, GLenum pname, GLfloat param) { + text(glTexGenf(coord, pname, param)); +} +void gl4es_glMultiTexGenfv(GLenum texunit, GLenum coord, GLenum pname, const GLfloat *params) { + text(glTexGenfv(coord, pname, params)); +} +void gl4es_glMultiTexGeni(GLenum texunit, GLenum coord, GLenum pname, GLint param) { + text(glTexGeni(coord, pname, param)); +} +void gl4es_glMultiTexGeniv(GLenum texunit, GLenum coord, GLenum pname, const GLint *params) { + text(glTexGeniv(coord, pname, params)); +} +void gl4es_glGetMultiTexEnvfv(GLenum texunit, GLenum target, GLenum pname, GLfloat *params) { + text(glGetTexEnvfv(target, pname, params)); +} +void gl4es_glGetMultiTexEnviv(GLenum texunit, GLenum target, GLenum pname, GLint *params) { + text(glGetTexEnviv(target, pname, params)); +} +void gl4es_glGetMultiTexGendv(GLenum texunit, GLenum coord, GLenum pname, GLdouble *params) { + text(glGetTexGendv(coord, pname, params)); +} +void gl4es_glGetMultiTexGenfv(GLenum texunit, GLenum coord, GLenum pname, GLfloat *params) { + text(glGetTexGenfv(coord, pname, params)); +} +void gl4es_glGetMultiTexGeniv(GLenum texunit, GLenum coord, GLenum pname, GLint *params) { + text(glGetTexGeniv(coord, pname, params)); +} +void gl4es_glMultiTexParameteri(GLenum texunit, GLenum target, GLenum pname, GLint param) { + text(glTexParameteri(target, pname, param)); +} +void gl4es_glMultiTexParameteriv(GLenum texunit, GLenum target, GLenum pname, const GLint *param) { + text(glTexParameteriv(target, pname, param)); +} +void gl4es_glMultiTexParameterf(GLenum texunit, GLenum target, GLenum pname, GLfloat param) { + text(glTexParameterf(target, pname, param)); +} +void gl4es_glMultiTexParameterfv(GLenum texunit, GLenum target, GLenum pname, const GLfloat *param) { + text(glTexParameterfv(target, pname, param)); +} +void gl4es_glMultiTexImage1D(GLenum texunit, GLenum target, GLint level, GLint internalformat, GLsizei width, GLint border, GLenum format, GLenum type, const GLvoid *pixels) { + text(glTexImage1D(target, level, internalformat, width, border, format, type, pixels)); +} +void gl4es_glMultiTexImage2D(GLenum texunit, GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels) { + text(glTexImage2D(target, level, internalformat, width, height, border, format, type, pixels)); +} +void gl4es_glMultiTexSubImage1D(GLenum texunit, GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid *pixels) { + text(glTexSubImage1D(target, level, xoffset, width, format, type, pixels)); +} +void gl4es_glMultiTexSubImage2D(GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels) { + text(glTexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels)); +} +void gl4es_glCopyMultiTexImage1D(GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLint border) { + text(glCopyTexImage1D(target, level, internalformat, x, y, width, border)); +} +void gl4es_glCopyMultiTexImage2D(GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border) { + text(glCopyTexImage2D(target, level, internalformat, x, y, width, height, border)); +} +void gl4es_glCopyMultiTexSubImage1D(GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width) { + text(glCopyTexSubImage1D(target, level, xoffset, x, y, width)); +} +void gl4es_glCopyMultiTexSubImage2D(GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height) { + text(glCopyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height)); +} +void gl4es_glGetMultiTexImage(GLenum texunit, GLenum target, GLint level, GLenum format, GLenum type, GLvoid *pixels) { + text(glGetTexImage(target, level, format, type, pixels)); +} +void gl4es_glGetMultiTexParameterfv(GLenum texunit, GLenum target, GLenum pname, GLfloat *params) { + text(glGetTexParameterfv(target, pname, params)); +} +void gl4es_glGetMultiTexParameteriv(GLenum texunit, GLenum target, GLenum pname, GLint *params) { + text(glGetTexParameteriv(target, pname, params)); +} +void gl4es_glGetMultiTexLevelParameterfv(GLenum texunit, GLenum target, GLint level, GLenum pname, GLfloat *params) { + text(glGetTexLevelParameterfv(target, level, pname, params)); +} +void gl4es_glGetMultiTexLevelParameteriv(GLenum texunit, GLenum target, GLint level, GLenum pname, GLint *params) { + text(glGetTexLevelParameteriv(target, level, pname, params)); +} +void gl4es_glMultiTexImage3D(GLenum texunit, GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels) { + text(glTexImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels)); +} +void gl4es_glMultiTexSubImage3D(GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *pixels) { + text(glTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels)); +} +void gl4es_glCopyMultiTexSubImage3D(GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height) { + text(glCopyTexSubImage3D(target, level, xoffset, yoffset, zoffset, x, y, width, height)); +} +// Compressed texture +void gl4es_glCompressedMultiTexImage3D(GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid *data) { + text(glCompressedTexImage3D(target, level, internalformat, width, height, depth, border, imageSize, data)); +} +void gl4es_glCompressedMultiTexImage2D(GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data) { + text(glCompressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data)); +} +void gl4es_glCompressedMultiTexImage1D(GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const GLvoid *data) { + text(glCompressedTexImage1D(target, level, internalformat, width, border, imageSize, data)); +} +void gl4es_glCompressedMultiTexSubImage3D(GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid *data) { + text(glCompressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, imageSize, data)); +} +void gl4es_glCompressedMultiTexSubImage2D(GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *data) { + text(glCompressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize, data)); +} +void gl4es_glCompressedMultiTexSubImage1D(GLenum texunit, GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const GLvoid *data) { + text(glCompressedTexSubImage1D(target, level, xoffset, width, format, imageSize, data)); +} +void gl4es_glGetCompressedMultiTexImage(GLenum texunit, GLenum target, GLint level, GLvoid *img) { + text(glGetCompressedTexImage(target, level, img)); +} + +void gl4es_glEnableClientStateIndexedEXT(GLenum array, GLuint index) { + if (array == GL_TEXTURE_COORD_ARRAY) { + int old = glstate->texture.client; + if(old!=index) gl4es_glClientActiveTexture(GL_TEXTURE0+index); + gl4es_glEnableClientState(array); + if(old!=index) gl4es_glClientActiveTexture(GL_TEXTURE0+old); + errorGL(); + } else { + errorShim(GL_INVALID_ENUM); + } +} +void gl4es_glDisableClientStateIndexedEXT(GLenum array, GLuint index) { + if (array == GL_TEXTURE_COORD_ARRAY) { + int old = glstate->texture.client; + if(old!=index) gl4es_glClientActiveTexture(GL_TEXTURE0+index); + gl4es_glDisableClientState(array); + if(old!=index) gl4es_glClientActiveTexture(GL_TEXTURE0+old); + errorGL(); + } else { + errorShim(GL_INVALID_ENUM); + } +} + +#define GETXXX(XXX, xxx) \ +void gl4es_glGet##XXX##IndexedvEXT(GLenum target, GLuint index, GL##xxx *data) { \ + switch(target) { \ + case GL_PROGRAM_MATRIX_EXT: \ + case GL_TRANSPOSE_PROGRAM_MATRIX_EXT: \ + case GL_PROGRAM_MATRIX_STACK_DEPTH_EXT: \ + { \ + int old = glstate->matrix_mode; \ + gl4es_glMatrixMode(GL_MATRIX0_ARB+index); \ + switch(target) { \ + case GL_PROGRAM_MATRIX_EXT: \ + gl4es_glGet##XXX##v(GL_CURRENT_MATRIX_ARB, data); \ + break; \ + case GL_TRANSPOSE_PROGRAM_MATRIX_EXT: \ + gl4es_glGet##XXX##v(GL_TRANSPOSE_CURRENT_MATRIX_ARB, data); \ + break; \ + case GL_PROGRAM_MATRIX_STACK_DEPTH_EXT: \ + gl4es_glGet##XXX##v(GL_CURRENT_MATRIX_STACK_DEPTH_ARB, data); \ + break; \ + } \ + gl4es_glMatrixMode(old); \ + } \ + break; \ + case GL_CURRENT_RASTER_TEXTURE_COORDS: \ + case GL_CURRENT_TEXTURE_COORDS: \ + case GL_TEXTURE_BINDING_1D: \ + case GL_TEXTURE_BINDING_1D_ARRAY: \ + case GL_TEXTURE_BINDING_2D: \ + case GL_TEXTURE_BINDING_2D_ARRAY: \ + case GL_TEXTURE_BINDING_3D: \ + case GL_TEXTURE_BINDING_BUFFER_EXT: \ + case GL_TEXTURE_BINDING_CUBE_MAP: \ + case GL_TEXTURE_BINDING_RECTANGLE_ARB: \ + case GL_TEXTURE_BUFFER_DATA_STORE_BINDING_EXT: \ + case GL_TEXTURE_BUFFER_FORMAT_EXT: \ + case GL_TEXTURE_GEN_Q: \ + case GL_TEXTURE_GEN_R: \ + case GL_TEXTURE_GEN_S: \ + case GL_TEXTURE_GEN_T: \ + case GL_TEXTURE_MATRIX: \ + case GL_TEXTURE_STACK_DEPTH: \ + case GL_TRANSPOSE_TEXTURE_MATRIX: \ + case GL_TEXTURE_1D: \ + case GL_TEXTURE_2D: \ + case GL_TEXTURE_3D: \ + case GL_TEXTURE_CUBE_MAP: \ + case GL_TEXTURE_RECTANGLE_ARB: \ + { \ + int old = glstate->texture.active; \ + if(old!=index+GL_TEXTURE0) gl4es_glActiveTexture(index+GL_TEXTURE0); \ + gl4es_glGet##XXX##v(target, data); \ + if(old!=index+GL_TEXTURE0) gl4es_glActiveTexture(old); \ + } \ + break; \ + case GL_TEXTURE_COORD_ARRAY: \ + case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING: \ + case GL_TEXTURE_COORD_ARRAY_COUNT: \ + case GL_TEXTURE_COORD_ARRAY_SIZE: \ + case GL_TEXTURE_COORD_ARRAY_STRIDE: \ + case GL_TEXTURE_COORD_ARRAY_TYPE: \ + { \ + int old = glstate->texture.client; \ + if(old!=index) gl4es_glClientActiveTexture(index+GL_TEXTURE0); \ + gl4es_glGet##XXX##v(target, data); \ + if(old!=index) gl4es_glClientActiveTexture(old+GL_TEXTURE0); \ + } \ + break; \ + default: \ + gl4es_glGet##XXX##v(target, data); \ + } \ +} + +GETXXX(Float, float); +GETXXX(Double, double); +GETXXX(Integer, int); +GETXXX(Boolean, boolean); +#undef GETXXX + +void gl4es_glGetPointerIndexedvEXT(GLenum pname, GLuint index, GLvoid **params) { + int old = glstate->texture.client; + if(old!=index) gl4es_glClientActiveTexture(index+GL_TEXTURE0); + gl4es_glGetPointerv(pname, params); + if(old!=index) gl4es_glClientActiveTexture(old+GL_TEXTURE0); + +} + +void gl4es_glEnableIndexedEXT(GLenum cap, GLuint index) { + int old = glstate->texture.active; + if(old!=index) gl4es_glActiveTexture(index+GL_TEXTURE0); + gl4es_glEnable(cap); + if(old!=index) gl4es_glActiveTexture(old); +} + +void gl4es_glDisableIndexedEXT(GLenum cap, GLuint index) { + int old = glstate->texture.active; + if(old!=index) gl4es_glActiveTexture(index+GL_TEXTURE0); + gl4es_glDisable(cap); + if(old!=index) gl4es_glActiveTexture(old); +} + +GLboolean gl4es_glIsEnabledIndexedEXT(GLenum cap, GLuint index) { + int old; + GLboolean rv; + switch(cap) { + case GL_TEXTURE_1D: + case GL_TEXTURE_2D: + case GL_TEXTURE_3D: + case GL_TEXTURE_CUBE_MAP: + case GL_TEXTURE_RECTANGLE_ARB: + case GL_TEXTURE_GEN_S: + case GL_TEXTURE_GEN_T: + case GL_TEXTURE_GEN_R: + case GL_TEXTURE_GEN_Q: + old = glstate->texture.active; + if(old!=index) gl4es_glActiveTexture(index+GL_TEXTURE0); + rv = gl4es_glIsEnabled(cap); + if(old!=index) gl4es_glActiveTexture(old); + return rv; + case GL_TEXTURE_COORD_ARRAY: + old = glstate->texture.client; + if(old!=index) gl4es_glClientActiveTexture(index+GL_TEXTURE0); + rv = gl4es_glIsEnabled(cap); + if(old!=index) gl4es_glClientActiveTexture(old+GL_TEXTURE0); + return rv; + } + return gl4es_glIsEnabled(cap); +} + +//EXT wrapper +void glClientAttribDefaultEXT(GLbitfield mask) AliasExport("gl4es_glClientAttribDefault"); +void glPushClientAttribDefaultEXT(GLbitfield mask) AliasExport("gl4es_glPushClientAttribDefault"); +void glMatrixLoadfEXT(GLenum matrixMode, const GLfloat *m) AliasExport("gl4es_glMatrixLoadf"); +void glMatrixLoaddEXT(GLenum matrixMode, const GLdouble *m) AliasExport("gl4es_glMatrixLoadd"); +void glMatrixMultfEXT(GLenum matrixMode, const GLfloat *m) AliasExport("gl4es_glMatrixMultf"); +void glMatrixMultdEXT(GLenum matrixMode, const GLdouble *m) AliasExport("gl4es_glMatrixMultd"); +void glMatrixLoadIdentityEXT(GLenum matrixMode) AliasExport("gl4es_glMatrixLoadIdentity"); +void glMatrixRotatefEXT(GLenum matrixMode, GLfloat angle, GLfloat x, GLfloat y, GLfloat z) AliasExport("gl4es_glMatrixRotatef"); +void glMatrixRotatedEXT(GLenum matrixMode, GLdouble angle, GLdouble x, GLdouble y, GLdouble z) AliasExport("gl4es_glMatrixRotated"); +void glMatrixScalefEXT(GLenum matrixMode, GLfloat x, GLfloat y, GLfloat z) AliasExport("gl4es_glMatrixScalef"); +void glMatrixScaledEXT(GLenum matrixMode, GLdouble x, GLdouble y, GLdouble z) AliasExport("gl4es_glMatrixScaled"); +void glMatrixTranslatefEXT(GLenum matrixMode, GLfloat x, GLfloat y, GLfloat z) AliasExport("gl4es_glMatrixTranslatef"); +void glMatrixTranslatedEXT(GLenum matrixMode, GLdouble x, GLdouble y, GLdouble z) AliasExport("gl4es_glMatrixTranslated"); +void glMatrixOrthoEXT(GLenum matrixMode, GLdouble l, GLdouble r, GLdouble b, GLdouble t, GLdouble n, GLdouble f) AliasExport("gl4es_glMatrixOrtho"); +void glMatrixFrustumEXT(GLenum matrixMode, GLdouble l, GLdouble r, GLdouble b, GLdouble t, GLdouble n, GLdouble f) AliasExport("gl4es_glMatrixFrustum"); +void glMatrixPushEXT(GLenum matrixMode) AliasExport("gl4es_glMatrixPush"); +void glMatrixPopEXT(GLenum matrixMode) AliasExport("gl4es_glMatrixPop"); +void glTextureParameteriEXT(GLuint texture, GLenum target, GLenum pname, GLint param) AliasExport("gl4es_glTextureParameteri"); +void glTextureParameterivEXT(GLuint texture, GLenum target, GLenum pname, const GLint *param) AliasExport("gl4es_glTextureParameteriv"); +void glTextureParameterfEXT(GLuint texture, GLenum target, GLenum pname, GLfloat param) AliasExport("gl4es_glTextureParameterf"); +void glTextureParameterfvEXT(GLuint texture, GLenum target, GLenum pname, const GLfloat *param) AliasExport("gl4es_glTextureParameterfv"); +void glTextureImage1DEXT(GLuint texture, GLenum target, GLint level, GLint internalformat, GLsizei width, GLint border, GLenum format, GLenum type, const GLvoid *pixels) AliasExport("gl4es_glTextureImage1D"); +void glTextureImage2DEXT(GLuint texture, GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels) AliasExport("gl4es_glTextureImage2D"); +void glTextureSubImage1DEXT(GLuint texture, GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid *pixels) AliasExport("gl4es_glTextureSubImage1D"); +void glTextureSubImage2DEXT(GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels) AliasExport("gl4es_glTextureSubImage2D"); +void glCopyTextureImage1DEXT(GLuint texture, GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLint border) AliasExport("gl4es_glCopyTextureImage1D"); +void glCopyTextureImage2DEXT(GLuint texture, GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border) AliasExport("gl4es_glCopyTextureImage2D"); +void glCopyTextureSubImage1DEXT(GLuint texture, GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width) AliasExport("gl4es_glCopyTextureSubImage1D"); +void glCopyTextureSubImage2DEXT(GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height) AliasExport("gl4es_glCopyTextureSubImage2D"); +void glGetTextureImageEXT(GLuint texture, GLenum target, GLint level, GLenum format, GLenum type, GLvoid *pixels) AliasExport("gl4es_glGetTextureImage"); +void glGetTextureParameterfvEXT(GLuint texture, GLenum target, GLenum pname, GLfloat *params) AliasExport("gl4es_glGetTextureParameterfv"); +void glGetTextureParameterivEXT(GLuint texture, GLenum target, GLenum pname, GLint *params) AliasExport("gl4es_glGetTextureParameteriv"); +void glGetTextureLevelParameterfvEXT(GLuint texture, GLenum target, GLint level, GLenum pname, GLfloat *params) AliasExport("gl4es_glGetTextureLevelParameterfv"); +void glGetTextureLevelParameterivEXT(GLuint texture, GLenum target, GLint level, GLenum pname, GLint *params) AliasExport("gl4es_glGetTextureLevelParameteriv"); +void glTextureImage3DEXT(GLuint texture, GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels) AliasExport("gl4es_glTextureImage3D"); +void glTextureSubImage3DEXT(GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *pixels) AliasExport("gl4es_glTextureSubImage3D"); +void glCopyTextureSubImage3DEXT(GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height) AliasExport("gl4es_glCopyTextureSubImage3D"); +void glBindMultiTextureEXT(GLenum texunit, GLenum target, GLuint texture) AliasExport("gl4es_glBindMultiTexture"); +void glMultiTexCoordPointerEXT(GLenum texunit, GLint size, GLenum type, GLsizei stride, const GLvoid *pointer) AliasExport("gl4es_glMultiTexCoordPointer"); +void glMultiTexEnvfEXT(GLenum texunit, GLenum target, GLenum pname, GLfloat param) AliasExport("gl4es_glMultiTexEnvf"); +void glMultiTexEnvfvEXT(GLenum texunit, GLenum target, GLenum pname, const GLfloat *params) AliasExport("gl4es_glMultiTexEnvfv"); +void glMultiTexEnviEXT(GLenum texunit, GLenum target, GLenum pname, GLint param) AliasExport("gl4es_glMultiTexEnvi"); +void glMultiTexEnvivEXT(GLenum texunit, GLenum target, GLenum pname, const GLint *params) AliasExport("gl4es_glMultiTexEnviv"); +void glMultiTexGendEXT(GLenum texunit, GLenum coord, GLenum pname, GLdouble param) AliasExport("gl4es_glMultiTexGend"); +void glMultiTexGendvEXT(GLenum texunit, GLenum coord, GLenum pname, const GLdouble *params) AliasExport("gl4es_glMultiTexGendv"); +void glMultiTexGenfEXT(GLenum texunit, GLenum coord, GLenum pname, GLfloat param) AliasExport("gl4es_glMultiTexGenf"); +void glMultiTexGenfvEXT(GLenum texunit, GLenum coord, GLenum pname, const GLfloat *params) AliasExport("gl4es_glMultiTexGenfv"); +void glMultiTexGeniEXT(GLenum texunit, GLenum coord, GLenum pname, GLint param) AliasExport("gl4es_glMultiTexGeni"); +void glMultiTexGenivEXT(GLenum texunit, GLenum coord, GLenum pname, const GLint *params) AliasExport("gl4es_glMultiTexGeniv"); +void glGetMultiTexEnvfvEXT(GLenum texunit, GLenum target, GLenum pname, GLfloat *params) AliasExport("gl4es_glGetMultiTexEnvfv"); +void glGetMultiTexEnvivEXT(GLenum texunit, GLenum target, GLenum pname, GLint *params) AliasExport("gl4es_glGetMultiTexEnviv"); +void glGetMultiTexGendvEXT(GLenum texunit, GLenum coord, GLenum pname, GLdouble *params) AliasExport("gl4es_glGetMultiTexGendv"); +void glGetMultiTexGenfvEXT(GLenum texunit, GLenum coord, GLenum pname, GLfloat *params) AliasExport("gl4es_glGetMultiTexGenfv"); +void glGetMultiTexGenivEXT(GLenum texunit, GLenum coord, GLenum pname, GLint *params) AliasExport("gl4es_glGetMultiTexGeniv"); +void glMultiTexParameteriEXT(GLenum texunit, GLenum target, GLenum pname, GLint param) AliasExport("gl4es_glMultiTexParameteri"); +void glMultiTexParameterivEXT(GLenum texunit, GLenum target, GLenum pname, const GLint *param) AliasExport("gl4es_glMultiTexParameteriv"); +void glMultiTexParameterfEXT(GLenum texunit, GLenum target, GLenum pname, GLfloat param) AliasExport("gl4es_glMultiTexParameterf"); +void glMultiTexParameterfvEXT(GLenum texunit, GLenum target, GLenum pname, const GLfloat *param) AliasExport("gl4es_glMultiTexParameterfv"); +void glMultiTexImage1DEXT(GLenum texunit, GLenum target, GLint level, GLint internalformat, GLsizei width, GLint border, GLenum format, GLenum type, const GLvoid *pixels) AliasExport("gl4es_glMultiTexImage1D"); +void glMultiTexImage2DEXT(GLenum texunit, GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels) AliasExport("gl4es_glMultiTexImage2D"); +void glMultiTexSubImage1DEXT(GLenum texunit, GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid *pixels) AliasExport("gl4es_glMultiTexSubImage1D"); +void glMultiTexSubImage2DEXT(GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels) AliasExport("gl4es_glMultiTexSubImage2D"); +void glCopyMultiTexImage1DEXT(GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLint border) AliasExport("gl4es_glCopyMultiTexImage1D"); +void glCopyMultiTexImage2DEXT(GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border) AliasExport("gl4es_glCopyMultiTexImage2D"); +void glCopyMultiTexSubImage1DEXT(GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width) AliasExport("gl4es_glCopyMultiTexSubImage1D"); +void glCopyMultiTexSubImage2DEXT(GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height) AliasExport("gl4es_glCopyMultiTexSubImage2D"); +void glGetMultiTexImageEXT(GLenum texunit, GLenum target, GLint level, GLenum format, GLenum type, GLvoid *pixels) AliasExport("gl4es_glGetMultiTexImage"); +void glGetMultiTexParameterfvEXT(GLenum texunit, GLenum target, GLenum pname, GLfloat *params) AliasExport("gl4es_glGetMultiTexParameterfv"); +void glGetMultiTexParameterivEXT(GLenum texunit, GLenum target, GLenum pname, GLint *params) AliasExport("gl4es_glGetMultiTexParameteriv"); +void glGetMultiTexLevelParameterfvEXT(GLenum texunit, GLenum target, GLint level, GLenum pname, GLfloat *params) AliasExport("gl4es_glGetMultiTexLevelParameterfv"); +void glGetMultiTexLevelParameterivEXT(GLenum texunit, GLenum target, GLint level, GLenum pname, GLint *params) AliasExport("gl4es_glGetMultiTexLevelParameteriv"); +void glMultiTexImage3DEXT(GLenum texunit, GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels) AliasExport("gl4es_glMultiTexImage3D"); +void glMultiTexSubImage3DEXT(GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *pixels) AliasExport("gl4es_glMultiTexSubImage3D"); +void glCopyMultiTexSubImage3DEXT(GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height) AliasExport("gl4es_glCopyMultiTexSubImage3D"); +void glCompressedTextureImage3DEXT(GLuint texture, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid *data) AliasExport("gl4es_glCompressedTextureImage3D"); +void glCompressedTextureImage2DEXT(GLuint texture, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data) AliasExport("gl4es_glCompressedTextureImage2D"); +void glCompressedTextureImage1DEXT(GLuint texture, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const GLvoid *data) AliasExport("gl4es_glCompressedTextureImage1D"); +void glCompressedTextureSubImage3DEXT(GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid *data) AliasExport("gl4es_glCompressedTextureSubImage3D"); +void glCompressedTextureSubImage2DEXT(GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *data) AliasExport("gl4es_glCompressedTextureSubImage2D"); +void glCompressedTextureSubImage1DEXT(GLuint texture, GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const GLvoid *data) AliasExport("gl4es_glCompressedTextureSubImage1D"); +void glGetCompressedTextureImageEXT(GLuint texture, GLenum target, GLint level, GLvoid *img) AliasExport("gl4es_glGetCompressedTextureImage"); +void glCompressedMultiTexImage3DEXT(GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid *data) AliasExport("gl4es_glCompressedMultiTexImage3D"); +void glCompressedMultiTexImage2DEXT(GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data) AliasExport("gl4es_glCompressedMultiTexImage2D"); +void glCompressedMultiTexImage1DEXT(GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const GLvoid *data) AliasExport("gl4es_glCompressedMultiTexImage1D"); +void glCompressedMultiTexSubImage3DEXT(GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid *data) AliasExport("gl4es_glCompressedMultiTexSubImage3D"); +void glCompressedMultiTexSubImage2DEXT(GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *data) AliasExport("gl4es_glCompressedMultiTexSubImage2D"); +void glCompressedMultiTexSubImage1DEXT(GLenum texunit, GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const GLvoid *data) AliasExport("gl4es_glCompressedMultiTexSubImage1D"); +void glGetCompressedMultiTexImageEXT(GLenum texunit, GLenum target, GLint level, GLvoid *img) AliasExport("gl4es_glGetCompressedMultiTexImage"); +void glMatrixLoadTransposefEXT(GLenum matrixMode, const GLfloat *m) AliasExport("gl4es_glMatrixLoadTransposef"); +void glMatrixLoadTransposedEXT(GLenum matrixMode, const GLdouble *m) AliasExport("gl4es_glMatrixLoadTransposed"); +void glMatrixMultTransposefEXT(GLenum matrixMode, const GLfloat *m) AliasExport("gl4es_glMatrixMultTransposef"); +void glMatrixMultTransposedEXT(GLenum matrixMode, const GLdouble *m) AliasExport("gl4es_glMatrixMultTransposed"); +void glEnableClientStateIndexedEXT(GLenum array, GLuint index) AliasExport("gl4es_glEnableClientStateIndexedEXT"); +void glDisableClientStateIndexedEXT(GLenum array, GLuint index) AliasExport("gl4es_glDisableClientStateIndexedEXT"); +void glGetPointerIndexedvEXT(GLenum pname, GLuint index, GLvoid **params) AliasExport("gl4es_glGetPointerIndexedvEXT"); +void glGetFloatIndexedvEXT(GLenum target, GLuint index, GLfloat *data) AliasExport("gl4es_glGetFloatIndexedvEXT"); +void glGetDoubleIndexedvEXT(GLenum target, GLuint index, GLdouble *data) AliasExport("gl4es_glGetDoubleIndexedvEXT"); +void glGetIntegerIndexedvEXT(GLenum target, GLuint index, GLint *data) AliasExport("gl4es_glGetIntegerIndexedvEXT"); +void glGetBooleanIndexedvEXT(GLenum target, GLuint index, GLboolean *data) AliasExport("gl4es_glGetBooleanIndexedvEXT"); +void glEnableIndexedEXT(GLenum cap, GLuint index) AliasExport("gl4es_glEnableIndexedEXT"); +void glDisableIndexedEXT(GLenum cap, GLuint index) AliasExport("gl4es_glDisableIndexedEXT"); +GLboolean glIsEnabledIndexedEXT(GLenum cap, GLuint index) AliasExport("gl4es_glIsEnabledIndexedEXT"); +#undef text +#undef texc diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/directstate.h b/Projects/Android/jni/SupportLibs/gl4es/src/gl/directstate.h new file mode 100644 index 0000000..7a7a3a7 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/directstate.h @@ -0,0 +1,120 @@ +#ifndef _GL4ES_DIRECTSTATE_H_ +#define _GL4ES_DIRECTSTATE_H_ + +#include "gles.h" + +void gl4es_glClientAttribDefault(GLbitfield mask); +void gl4es_glPushClientAttribDefault(GLbitfield mask); + +void gl4es_glMatrixLoadf(GLenum matrixMode, const GLfloat *m); +void gl4es_glMatrixLoadd(GLenum matrixMode, const GLdouble *m); +void gl4es_glMatrixMultf(GLenum matrixMode, const GLfloat *m); +void gl4es_glMatrixMultd(GLenum matrixMode, const GLdouble *m); +void gl4es_glMatrixLoadIdentity(GLenum matrixMode); +void gl4es_glMatrixRotatef(GLenum matrixMode, GLfloat angle, GLfloat x, GLfloat y, GLfloat z); +void gl4es_glMatrixRotated(GLenum matrixMode, GLdouble angle, GLdouble x, GLdouble y, GLdouble z); +void gl4es_glMatrixScalef(GLenum matrixMode, GLfloat x, GLfloat y, GLfloat z); +void gl4es_glMatrixScaled(GLenum matrixMode, GLdouble x, GLdouble y, GLdouble z); +void gl4es_glMatrixTranslatef(GLenum matrixMode, GLfloat x, GLfloat y, GLfloat z); +void gl4es_glMatrixTranslated(GLenum matrixMode, GLdouble x, GLdouble y, GLdouble z); +void gl4es_glMatrixOrtho(GLenum matrixMode, GLdouble l, GLdouble r, GLdouble b, GLdouble t, GLdouble n, GLdouble f); +void gl4es_glMatrixFrustum(GLenum matrixMode, GLdouble l, GLdouble r, GLdouble b, GLdouble t, GLdouble n, GLdouble f); +void gl4es_glMatrixPush(GLenum matrixMode); +void gl4es_glMatrixPop(GLenum matrixMode); + +void gl4es_glTextureParameteri(GLuint texture, GLenum target, GLenum pname, GLint param); +void gl4es_glTextureParameteriv(GLuint texture, GLenum target, GLenum pname, const GLint *param); +void gl4es_glTextureParameterf(GLuint texture, GLenum target, GLenum pname, GLfloat param); +void gl4es_glTextureParameterfv(GLuint texture, GLenum target, GLenum pname, const GLfloat *param); +void gl4es_glTextureImage1D(GLuint texture, GLenum target, GLint level, GLint internalformat, GLsizei width, GLint border, GLenum format, GLenum type, const GLvoid *pixels); +void gl4es_glTextureImage2D(GLuint texture, GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels); +void gl4es_glTextureSubImage1D(GLuint texture, GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid *pixels); +void gl4es_glTextureSubImage2D(GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels); +void gl4es_glCopyTextureImage1D(GLuint texture, GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLint border); +void gl4es_glCopyTextureImage2D(GLuint texture, GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border); +void gl4es_glCopyTextureSubImage1D(GLuint texture, GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width); +void gl4es_glCopyTextureSubImage2D(GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height); +void gl4es_glGetTextureImage(GLuint texture, GLenum target, GLint level, GLenum format, GLenum type, GLvoid *pixels); +void gl4es_glGetTextureParameterfv(GLuint texture, GLenum target, GLenum pname, GLfloat *params); +void gl4es_glGetTextureParameteriv(GLuint texture, GLenum target, GLenum pname, GLint *params); +void gl4es_glGetTextureLevelParameterfv(GLuint texture, GLenum target, GLint level, GLenum pname, GLfloat *params); +void gl4es_glGetTextureLevelParameteriv(GLuint texture, GLenum target, GLint level, GLenum pname, GLint *params); + +void gl4es_glTextureImage3D(GLuint texture, GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels); +void gl4es_glTextureSubImage3D(GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *pixels); +void gl4es_glCopyTextureSubImage3D(GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height); + +void gl4es_glBindMultiTexture(GLenum texunit, GLenum target, GLuint texture); +void gl4es_glMultiTexCoordPointer(GLenum texunit, GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +void gl4es_glMultiTexEnvf(GLenum texunit, GLenum target, GLenum pname, GLfloat param); +void gl4es_glMultiTexEnvfv(GLenum texunit, GLenum target, GLenum pname, const GLfloat *params); +void gl4es_glMultiTexEnvi(GLenum texunit, GLenum target, GLenum pname, GLint param); +void gl4es_glMultiTexEnviv(GLenum texunit, GLenum target, GLenum pname, const GLint *params); +void gl4es_glMultiTexGend(GLenum texunit, GLenum coord, GLenum pname, GLdouble param); +void gl4es_glMultiTexGendv(GLenum texunit, GLenum coord, GLenum pname, const GLdouble *params); +void gl4es_glMultiTexGenf(GLenum texunit, GLenum coord, GLenum pname, GLfloat param); +void gl4es_glMultiTexGenfv(GLenum texunit, GLenum coord, GLenum pname, const GLfloat *params); +void gl4es_glMultiTexGeni(GLenum texunit, GLenum coord, GLenum pname, GLint param); +void gl4es_glMultiTexGeniv(GLenum texunit, GLenum coord, GLenum pname, const GLint *params); +void gl4es_glGetMultiTexEnvfv(GLenum texunit, GLenum target, GLenum pname, GLfloat *params); +void gl4es_glGetMultiTexEnviv(GLenum texunit, GLenum target, GLenum pname, GLint *params); +void gl4es_glGetMultiTexGendv(GLenum texunit, GLenum coord, GLenum pname, GLdouble *params); +void gl4es_glGetMultiTexGenfv(GLenum texunit, GLenum coord, GLenum pname, GLfloat *params); +void gl4es_glGetMultiTexGeniv(GLenum texunit, GLenum coord, GLenum pname, GLint *params); +void gl4es_glMultiTexParameteri(GLenum texunit, GLenum target, GLenum pname, GLint param); +void gl4es_glMultiTexParameteriv(GLenum texunit, GLenum target, GLenum pname, const GLint *param); +void gl4es_glMultiTexParameterf(GLenum texunit, GLenum target, GLenum pname, GLfloat param); +void gl4es_glMultiTexParameterfv(GLenum texunit, GLenum target, GLenum pname, const GLfloat *param); +void gl4es_glMultiTexImage1D(GLenum texunit, GLenum target, GLint level, GLint internalformat, GLsizei width, GLint border, GLenum format, GLenum type, const GLvoid *pixels); +void gl4es_glMultiTexImage2D(GLenum texunit, GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels); +void gl4es_glMultiTexSubImage1D(GLenum texunit, GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid *pixels); +void gl4es_glMultiTexSubImage2D(GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels); +void gl4es_glCopyMultiTexImage1D(GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLint border); +void gl4es_glCopyMultiTexImage2D(GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border); +void gl4es_glCopyMultiTexSubImage1D(GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width); +void gl4es_glCopyMultiTexSubImage2D(GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height); +void gl4es_glGetMultiTexImage(GLenum texunit, GLenum target, GLint level, GLenum format, GLenum type, GLvoid *pixels); +void gl4es_glGetMultiTexParameterfv(GLenum texunit, GLenum target, GLenum pname, GLfloat *params); +void gl4es_glGetMultiTexParameteriv(GLenum texunit, GLenum target, GLenum pname, GLint *params); +void gl4es_glGetMultiTexLevelParameterfv(GLenum texunit, GLenum target, GLint level, GLenum pname, GLfloat *params); +void gl4es_glGetMultiTexLevelParameteriv(GLenum texunit, GLenum target, GLint level, GLenum pname, GLint *params); +void gl4es_glMultiTexImage3D(GLenum texunit, GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels); +void gl4es_glMultiTexSubImage3D(GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *pixels); +void gl4es_glCopyMultiTexSubImage3D(GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height); + +void gl4es_glCompressedTextureImage3D(GLuint texture, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid *data); +void gl4es_glCompressedTextureImage2D(GLuint texture, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data); +void gl4es_glCompressedTextureImage1D(GLuint texture, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const GLvoid *data); +void gl4es_glCompressedTextureSubImage3D(GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid *data); +void gl4es_glCompressedTextureSubImage2D(GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *data); +void gl4es_glCompressedTextureSubImage1D(GLuint texture, GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const GLvoid *data); +void gl4es_glGetCompressedTextureImage(GLuint texture, GLenum target, GLint level, GLvoid *img); + +void gl4es_glCompressedMultiTexImage3D(GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid *data); +void gl4es_glCompressedMultiTexImage2D(GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data); +void gl4es_glCompressedMultiTexImage1D(GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const GLvoid *data); +void gl4es_glCompressedMultiTexSubImage3D(GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid *data); +void gl4es_glCompressedMultiTexSubImage2D(GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *data); +void gl4es_glCompressedMultiTexSubImage1D(GLenum texunit, GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const GLvoid *data); +void gl4es_glGetCompressedMultiTexImage(GLenum texunit, GLenum target, GLint level, GLvoid *img); + +void gl4es_glMatrixLoadTransposef(GLenum matrixMode, const GLfloat *m); +void gl4es_glMatrixLoadTransposed(GLenum matrixMode, const GLdouble *m); +void gl4es_glMatrixMultTransposef(GLenum matrixMode, const GLfloat *m); +void gl4es_glMatrixMultTransposed(GLenum matrixMode, const GLdouble *m); + +void gl4es_glEnableClientStateIndexedEXT(GLenum array, GLuint index); +void gl4es_glDisableClientStateIndexedEXT(GLenum array, GLuint index); + +void gl4es_glGetFloatIndexedvEXT(GLenum target, GLuint index, GLfloat *data); +void gl4es_glGetDoubleIndexedvEXT(GLenum target, GLuint index, GLdouble *data); +void gl4es_glGetIntegerIndexedvEXT(GLenum target, GLuint index, GLint *data); +void gl4es_glGetBooleanIndexedvEXT(GLenum target, GLuint index, GLboolean *data); + +void gl4es_glGetPointerIndexedvEXT(GLenum pname, GLuint index, GLvoid **params); + +void gl4es_glEnableIndexedEXT(GLenum cap, GLuint index); +void gl4es_glDisableIndexedEXT(GLenum cap, GLuint index); +GLboolean gl4es_glIsEnabledIndexedEXT(GLenum cap, GLuint index); + +#endif // _GL4ES_DIRECTSTATE_H_ diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/drawing.c b/Projects/Android/jni/SupportLibs/gl4es/src/gl/drawing.c new file mode 100644 index 0000000..037b3d5 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/drawing.c @@ -0,0 +1,1580 @@ +#include "../glx/hardext.h" +#include "array.h" +#include "enum_info.h" +#include "fpe.h" +#include "gl4es.h" +#include "gles.h" +#include "glstate.h" +#include "init.h" +#include "list.h" +#include "loader.h" +#include "render.h" + +static GLboolean is_cache_compatible(GLsizei count) { + #define T2(AA, A, B) \ + if(glstate->vao->AA!=glstate->vao->B.enabled) return GL_FALSE; \ + if(glstate->vao->B.enabled && memcmp(&glstate->vao->pointers[A], &glstate->vao->B.state, sizeof(pointer_state_t))) return GL_FALSE; + #define TEST(A,B) T2(pointers[A].enabled, A, B) + #define TESTA(A,B,I) T2(pointers[A+i].enabled, A+i, B[i]) + + if(glstate->vao == glstate->defaultvao) return GL_FALSE; + if(count > glstate->vao->cache_count) return GL_FALSE; + TEST(ATT_VERTEX, vert) + TEST(ATT_COLOR, color) + TEST(ATT_SECONDARY, secondary) + TEST(ATT_FOGCOORD, fog) + TEST(ATT_NORMAL, normal) + for (int i=0; ilist.compiling, skip, count); + list->mode = mode; + list->mode_init = mode; + list->mode_dimension = rendermode_dimensions(mode); + list->len = count-skip; + list->cap = count-skip; + + // check cache if any + if(glstate->vao->shared_arrays) { + if (!is_cache_compatible(count)) + VaoSharedClear(glstate->vao); + } + + if(glstate->vao->shared_arrays) { + #define OP(A, N) (A)?A+skip*N:NULL + list->vert = OP(glstate->vao->vert.ptr,4); + list->color = OP(glstate->vao->color.ptr,4); + list->secondary = OP(glstate->vao->secondary.ptr,4); + list->fogcoord = OP(glstate->vao->fog.ptr, 1); + list->normal = OP(glstate->vao->normal.ptr,3); + for (int i=0; itex[i] = OP(glstate->vao->tex[i].ptr,4); + #undef OP + + list->shared_arrays = glstate->vao->shared_arrays; + (*glstate->vao->shared_arrays)++; + } else { + if(!globals4es.novaocache && glstate->vao != glstate->defaultvao) { + // prepare a vao cache object + list->shared_arrays = glstate->vao->shared_arrays = (int*)malloc(sizeof(int)); + *glstate->vao->shared_arrays = 1; + #define G2(AA, A, B) \ + glstate->vao->B.enabled = glstate->vao->pointers[AA].enabled; \ + if (glstate->vao->B.enabled) memcpy(&glstate->vao->B.state, &glstate->vao->pointers[A], sizeof(pointer_state_t)); + #define GO(A,B) G2(A, A, B) + #define GOA(A,B,I) G2(A+i, A+i, B[i]) + GO(ATT_VERTEX, vert) + GO(ATT_COLOR, color) + GO(ATT_SECONDARY, secondary) + GO(ATT_FOGCOORD, fog) + GO(ATT_NORMAL, normal) + for (int i=0; ivao->cache_count = count; + #undef GOA + #undef GO + #undef G2 + } + if (glstate->vao->pointers[ATT_VERTEX].enabled) { + if(glstate->vao->shared_arrays) { + glstate->vao->vert.ptr = copy_gl_pointer_tex(&glstate->vao->pointers[ATT_VERTEX], 4, 0, count); + list->vert = glstate->vao->vert.ptr + 4*skip; + } else + list->vert = copy_gl_pointer_tex(&glstate->vao->pointers[ATT_VERTEX], 4, skip, count); + } + if (glstate->vao->pointers[ATT_COLOR].enabled) { + if(glstate->vao->shared_arrays) { + if(glstate->vao->pointers[ATT_COLOR].size==GL_BGRA) + glstate->vao->color.ptr = copy_gl_pointer_color_bgra(glstate->vao->pointers[ATT_COLOR].pointer, glstate->vao->pointers[ATT_COLOR].stride, 4, 0, count); + else + glstate->vao->color.ptr = copy_gl_pointer_color(&glstate->vao->pointers[ATT_COLOR], 4, 0, count); + list->color = glstate->vao->color.ptr + 4*skip; + } else { + if(glstate->vao->pointers[ATT_COLOR].size==GL_BGRA) + list->color = copy_gl_pointer_color_bgra(glstate->vao->pointers[ATT_COLOR].pointer, glstate->vao->pointers[ATT_COLOR].stride, 4, skip, count); + else + list->color = copy_gl_pointer_color(&glstate->vao->pointers[ATT_COLOR], 4, skip, count); + } + } + if (glstate->vao->pointers[ATT_SECONDARY].enabled/* && glstate->enable.color_array*/) { + if(glstate->vao->shared_arrays) { + if(glstate->vao->pointers[ATT_SECONDARY].size==GL_BGRA) + glstate->vao->secondary.ptr = copy_gl_pointer_color_bgra(glstate->vao->pointers[ATT_SECONDARY].pointer, glstate->vao->pointers[ATT_SECONDARY].stride, 4, 0, count); + else + glstate->vao->secondary.ptr = copy_gl_pointer(&glstate->vao->pointers[ATT_SECONDARY], 4, 0, count); // alpha chanel is always 0 for secondary... + list->secondary = glstate->vao->secondary.ptr + 4*skip; + } else { + if(glstate->vao->pointers[ATT_SECONDARY].size==GL_BGRA) + list->secondary = copy_gl_pointer_color_bgra(glstate->vao->pointers[ATT_SECONDARY].pointer, glstate->vao->pointers[ATT_SECONDARY].stride, 4, skip, count); + else + list->secondary = copy_gl_pointer(&glstate->vao->pointers[ATT_SECONDARY], 4, skip, count); // alpha chanel is always 0 for secondary... + } + } + if (glstate->vao->pointers[ATT_NORMAL].enabled) { + if(glstate->vao->shared_arrays) { + glstate->vao->normal.ptr = copy_gl_pointer_raw(&glstate->vao->pointers[ATT_NORMAL], 3, 0, count); + list->normal = glstate->vao->normal.ptr + 3*skip; + } else + list->normal = copy_gl_pointer_raw(&glstate->vao->pointers[ATT_NORMAL], 3, skip, count); + } + if (glstate->vao->pointers[ATT_FOGCOORD].enabled) { + if(glstate->vao->shared_arrays) { + glstate->vao->fog.ptr = copy_gl_pointer_raw(&glstate->vao->pointers[ATT_FOGCOORD], 1, 0, count); + list->fogcoord = glstate->vao->fog.ptr + 1*skip; + } else + list->fogcoord = copy_gl_pointer_raw(&glstate->vao->pointers[ATT_FOGCOORD], 1, skip, count); + } + for (int i=0; ivao->maxtex; i++) { + if (glstate->vao->pointers[ATT_MULTITEXCOORD0+i].enabled) { + if(glstate->vao->shared_arrays) { + glstate->vao->tex[i].ptr = copy_gl_pointer_tex(&glstate->vao->pointers[ATT_MULTITEXCOORD0+i], 4, 0, count); + list->tex[i] = glstate->vao->tex[i].ptr + 4*skip; + } else + list->tex[i] = copy_gl_pointer_tex(&glstate->vao->pointers[ATT_MULTITEXCOORD0+i], 4, skip, count); + } + } + } + for (int i=0; itex[i] && list->maxtex < i+1) list->maxtex = i+1; + return list; +} + +static inline bool should_intercept_render(GLenum mode) { + // check bounded tex that will be used if one need some transformations + if (hardext.esversion==1) // but only for ES1.1 + for (int aa=0; aaenable.texture[aa]) { + if ((hardext.esversion==1) && ((glstate->enable.texgen_s[aa] || glstate->enable.texgen_t[aa] || glstate->enable.texgen_r[aa] || glstate->enable.texgen_q[aa]))) + return true; + if ((!glstate->vao->pointers[ATT_MULTITEXCOORD0+aa].enabled) && !(mode==GL_POINT && glstate->texture.pscoordreplace[aa])) + return true; + if ((glstate->vao->pointers[ATT_MULTITEXCOORD0+aa].enabled) && (glstate->vao->pointers[ATT_MULTITEXCOORD0+aa].size == 1)) + return true; + } + } + if(glstate->polygon_mode == GL_LINE && mode>=GL_TRIANGLES) + return true; + if ((hardext.esversion==1) && ((glstate->vao->pointers[ATT_SECONDARY].enabled) && (glstate->vao->pointers[ATT_COLOR].enabled))) + return true; + if ((hardext.esversion==1) && (glstate->vao->pointers[ATT_COLOR].enabled && (glstate->vao->pointers[ATT_COLOR].size != 4))) + return true; + return ( + (glstate->vao->pointers[ATT_VERTEX].enabled && ! valid_vertex_type(glstate->vao->pointers[ATT_VERTEX].type)) || + (mode == GL_LINES && glstate->enable.line_stipple) || + /*(mode == GL_QUADS) ||*/ (glstate->list.active && !glstate->list.pending) + ); +} + +GLuint len_indices(const GLushort *sindices, const GLuint *iindices, GLsizei count) { + GLuint len = 0; + if (sindices) { + for (int i=0; iraster.bm_drawing) + bitmap_flush(); + //printf("glDrawElementsCommon(%s, %d, %d, %d, %p, %p, %d)\n", PrintEnum(mode), first, count, len, sindices, iindices, instancecount); + LOAD_GLES_FPE(glDrawElements); + LOAD_GLES_FPE(glDrawArrays); + LOAD_GLES_FPE(glNormalPointer); + LOAD_GLES_FPE(glVertexPointer); + LOAD_GLES_FPE(glColorPointer); + LOAD_GLES_FPE(glTexCoordPointer); + LOAD_GLES_FPE(glEnable); + LOAD_GLES_FPE(glDisable); + LOAD_GLES_FPE(glEnableClientState); + LOAD_GLES_FPE(glDisableClientState); + LOAD_GLES_FPE(glMultiTexCoord4f); +#define client_state(A, B, C) \ + if(glstate->vao->pointers[A].enabled != glstate->clientstate[A]) { \ + C \ + glstate->clientstate[A] = glstate->vao->pointers[A].enabled; \ + if(glstate->clientstate[A]) \ + gles_glEnableClientState(B); \ + else \ + gles_glDisableClientState(B); \ + } +#if 0 +// FEZ draw the stars (intro menu and the ones visible by night) +// by drawing a huge list of 500k+ triangles! +// it's a bit too much for mobile hardware, so it can be simply disabled here +if(count>500000) return; +#endif + GLenum mode_init = mode; + /*if (glstate->polygon_mode == GL_LINE && mode>=GL_TRIANGLES) + mode = GL_LINE_LOOP;*/ + if (glstate->polygon_mode == GL_POINT && mode>=GL_TRIANGLES) + mode = GL_POINTS; + + if (mode == GL_QUAD_STRIP) + mode = GL_TRIANGLE_STRIP; + if (mode == GL_POLYGON) + mode = GL_TRIANGLE_FAN; + if (mode == GL_QUADS) { + mode = GL_TRIANGLES; + int ilen = (count*3)/2; + if (iindices) { + gl4es_scratch(ilen*sizeof(GLuint)); + GLuint *tmp = (GLuint*)glstate->scratch; + for (int i=0, j=0; i+3scratch; + for (int i=0, j=0; i+3render_mode == GL_SELECT) { + // TODO handling uint indices + if(!sindices && !iindices) + select_glDrawArrays(&glstate->vao->pointers[ATT_VERTEX], mode, first, count); + else + select_glDrawElements(&glstate->vao->pointers[ATT_VERTEX], mode, count, sindices?GL_UNSIGNED_SHORT:GL_UNSIGNED_INT, sindices?((void*)sindices):((void*)iindices)); + } else { + GLuint old_tex = glstate->texture.client; + + realize_textures(); + + #define TEXTURE(A) gl4es_glClientActiveTexture(A+GL_TEXTURE0); + + if(globals4es.usevbo) ToBuffer(0, count); + int buffered = glstate->vao->locked_mapped; + if (buffered) { + // new check to see if texture are ok... + for (int aa=0; aavao->pointers[ATT_MULTITEXCOORD0+aa].enabled) { + TEXTURE(aa); + const GLint itarget = get_target(glstate->enable.texture[aa]); + if(itarget>=0) + if(tex_setup_needchange(itarget)) + buffered = 0; + } + } + } + if(buffered) { + gl4es_use_scratch_vertex(1); + // and move indices too + int size = ((iindices)?4:2)*count; + gl4es_scratch_indices(size); + LOAD_GLES(glBufferSubData); + gles_glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, size, (iindices)?(void*)iindices:(void*)sindices); + } + pointer_state_t *p; + #define GetP(A) (buffered)?(&glstate->vao->locked_pointers[A]):(&glstate->vao->pointers[A]) + // secondary color and color sizef != 4 are "intercepted" and draw using a list, unless usin ES>1.1 + client_state(ATT_COLOR, GL_COLOR_ARRAY, ); + p = GetP(ATT_COLOR); + if (p->enabled) + gles_glColorPointer(p->size, p->type, p->stride, p->pointer); + if(hardext.esversion>1) { + client_state(ATT_SECONDARY, GL_SECONDARY_COLOR_ARRAY, ); + p = GetP(ATT_SECONDARY); + if (p->enabled) + fpe_glSecondaryColorPointer(p->size, p->type, p->stride, p->pointer); + } + client_state(ATT_NORMAL, GL_NORMAL_ARRAY, ); + p = GetP(ATT_NORMAL); + if (p->enabled) + gles_glNormalPointer(p->type, p->stride, p->pointer); + client_state(ATT_VERTEX, GL_VERTEX_ARRAY, ); + p = GetP(ATT_VERTEX); + if (p->enabled) + gles_glVertexPointer(p->size, p->type, p->stride, p->pointer); + for (int aa=0; aaenable.texture[aa]); + if (itarget>=0) { + if (!IS_TEX2D(glstate->enable.texture[aa]) && (IS_ANYTEX(glstate->enable.texture[aa]))) { + gl4es_glActiveTexture(GL_TEXTURE0+aa); + realize_active(); + gles_glEnable(GL_TEXTURE_2D); + } + if (p->enabled) { + TEXTURE(aa); + int changes = tex_setup_needchange(itarget); + if(changes && !len) len = len_indices(sindices, iindices, count); + tex_setup_texcoord(len, changes, itarget, p); + } else + gles_glMultiTexCoord4f(GL_TEXTURE0+aa, glstate->texcoord[aa][0], glstate->texcoord[aa][1], glstate->texcoord[aa][2], glstate->texcoord[aa][3]); + } else if (glstate->clientstate[ATT_MULTITEXCOORD0+aa] && hardext.esversion!=1) { + // special case on GL2, Tex disable but CoordArray enabled... + TEXTURE(aa); + int changes = tex_setup_needchange(ENABLED_TEX2D); + if(changes && !len) len = len_indices(sindices, iindices, count); + tex_setup_texcoord(len, changes, ENABLED_TEX2D, p); + } + } + #undef GetP + if (glstate->texture.client!=old_tex) + TEXTURE(old_tex); + + // POLYGON mode as LINE is "intercepted" and drawn using list + if(instancecount==1) { + if(!iindices && !sindices) + gles_glDrawArrays(mode, first, count); + else + gles_glDrawElements(mode, count, (sindices)?GL_UNSIGNED_SHORT:GL_UNSIGNED_INT, buffered?0:(sindices?((void*)sindices):((void*)iindices))); + } else { + if(!iindices && !sindices) + for (glstate->instanceID=0; glstate->instanceIDinstanceID) + gles_glDrawArrays(mode, first, count); + else { + void* tmp=buffered?NULL:(sindices?((void*)sindices):((void*)iindices)); + GLenum t = (sindices)?GL_UNSIGNED_SHORT:GL_UNSIGNED_INT; + for (glstate->instanceID=0; glstate->instanceIDinstanceID) + gles_glDrawElements(mode, count, t, tmp); + } + glstate->instanceID = 0; + } + + if(buffered) { + gl4es_use_scratch_vertex(0); + gl4es_use_scratch_indices(0); + } + + for (int aa=0; aaenable.texture[aa]) && (IS_ANYTEX(glstate->enable.texture[aa]))) { + gl4es_glActiveTexture(GL_TEXTURE0+aa); + realize_active(); + gles_glDisable(GL_TEXTURE_2D); + } + } + if (glstate->texture.client!=old_tex) + TEXTURE(old_tex); + #undef TEXTURE + } +} + +#define MIN_BATCH (10*globals4es.batch) +#define MAX_BATCH (10*10*globals4es.batch) + +void gl4es_glDrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const void *indices) { + //printf("glDrawRangeElements(%s, %i, %i, %i, %s, @%p), inlist=%i, pending=%d\n", PrintEnum(mode), start, end, count, PrintEnum(type), indices, (glstate->list.active)?1:0, glstate->list.pending); + count = adjust_vertices(mode, count); + + if (count<0) { + errorShim(GL_INVALID_VALUE); + return; + } + if (count==0) { + noerrorShim(); + return; + } + + bool compiling = (glstate->list.active); + bool intercept = should_intercept_render(mode); + + //BATCH Mode + if(!compiling) { + if(!intercept && glstate->list.pending && count>MAX_BATCH) // too large and will not intercept, stop the BATCH + flush(); + else if((!intercept && !glstate->list.pending && countlist.pending = 1; + glstate->list.active = alloc_renderlist(); + } + } + + noerrorShim(); + GLushort *sindices = NULL; + GLuint *iindices = NULL; + bool need_free = !( + (type==GL_UNSIGNED_SHORT) || + (!compiling && !intercept && type==GL_UNSIGNED_INT && hardext.elementuint) + ); + if(need_free) { + sindices = copy_gl_array((glstate->vao->elements)?glstate->vao->elements->data + (uintptr_t)indices:indices, + type, 1, 0, GL_UNSIGNED_SHORT, 1, 0, count); + } else { + if(type==GL_UNSIGNED_INT) + iindices = (glstate->vao->elements)?(glstate->vao->elements->data + (uintptr_t)indices):(GLvoid*)indices; + else + sindices = (glstate->vao->elements)?(glstate->vao->elements->data + (uintptr_t)indices):(GLvoid*)indices; + } + + if (compiling) { + // TODO, handle uint indices + renderlist_t *list = NULL; + + NewStage(glstate->list.active, STAGE_DRAW); + list = glstate->list.active; + + if(!need_free) { + GLushort *tmp = sindices; + sindices = (GLushort*)malloc(count*sizeof(GLushort)); + memcpy(sindices, tmp, count*sizeof(GLushort)); + } + for (int i=0; iindices = sindices; + list->ilen = count; + list->indice_cap = count; + //end_renderlist(list); + + if(glstate->list.pending) { + NewStage(glstate->list.active, STAGE_POSTDRAW); + } else { + glstate->list.active = extend_renderlist(list); + } + return; + } + + if (intercept) { + //TODO handling uint indices + renderlist_t *list = NULL; + + if(!need_free) { + GLushort *tmp = sindices; + sindices = (GLushort*)malloc(count*sizeof(GLushort)); + memcpy(sindices, tmp, count*sizeof(GLushort)); + } + for (int i=0; iindices = sindices; + list->ilen = count; + list->indice_cap = count; + list = end_renderlist(list); + draw_renderlist(list); + free_renderlist(list); + + return; + } else { + glDrawElementsCommon(mode, 0, count, end+1, sindices, iindices, 1); + if(need_free) + free(sindices); + } +} +void glDrawRangeElements(GLenum mode,GLuint start,GLuint end,GLsizei count,GLenum type,const void *indices) AliasExport("gl4es_glDrawRangeElements"); +void glDrawRangeElementsEXT(GLenum mode,GLuint start,GLuint end,GLsizei count,GLenum type,const void *indices) AliasExport("gl4es_glDrawRangeElements"); + + +void gl4es_glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices) { + //printf("glDrawElements(%s, %d, %s, %p), vtx=%p map=%p, pending=%d\n", PrintEnum(mode), count, PrintEnum(type), indices, (glstate->vao->vertex)?glstate->vao->vertex->data:NULL, (glstate->vao->elements)?glstate->vao->elements->data:NULL, glstate->list.pending); + // TODO: split for count > 65535? + // special check for QUADS and TRIANGLES that need multiple of 4 or 3 vertex... + count = adjust_vertices(mode, count); + + if (count<0) { + errorShim(GL_INVALID_VALUE); + return; + } + if (count==0) { + noerrorShim(); + return; + } + + bool compiling = (glstate->list.active); + bool intercept = should_intercept_render(mode); + + //BATCH Mode + if(!compiling) { + if(!intercept && glstate->list.pending && count>MAX_BATCH) // too large and will not intercept, stop the BATCH + flush(); + else if((!intercept && !glstate->list.pending && countlist.pending = 1; + glstate->list.active = alloc_renderlist(); + } + } + + noerrorShim(); + GLushort *sindices = NULL; + GLuint *iindices = NULL; + bool need_free = !( + (type==GL_UNSIGNED_SHORT) || + (!compiling && !intercept && type==GL_UNSIGNED_INT && hardext.elementuint) + ); + if(need_free) { + sindices = copy_gl_array((glstate->vao->elements)?glstate->vao->elements->data + (uintptr_t)indices:indices, + type, 1, 0, GL_UNSIGNED_SHORT, 1, 0, count); + } else { + if(type==GL_UNSIGNED_INT) + iindices = (glstate->vao->elements)?(glstate->vao->elements->data + (uintptr_t)indices):(GLvoid*)indices; + else + sindices = (glstate->vao->elements)?(glstate->vao->elements->data + (uintptr_t)indices):(GLvoid*)indices; + } + + if (compiling) { + // TODO, handle uint indices + renderlist_t *list = NULL; + GLsizei min, max; + + NewStage(glstate->list.active, STAGE_DRAW); + list = glstate->list.active; + + if(!need_free) { + GLushort *tmp = sindices; + sindices = (GLushort*)malloc(count*sizeof(GLushort)); + memcpy(sindices, tmp, count*sizeof(GLushort)); + } + normalize_indices_us(sindices, &max, &min, count); + list = arrays_to_renderlist(list, mode, min, max + 1); + list->indices = sindices; + list->ilen = count; + list->indice_cap = count; + //end_renderlist(list); + + if(glstate->list.pending) { + NewStage(glstate->list.active, STAGE_POSTDRAW); + } else { + glstate->list.active = extend_renderlist(list); + } + return; + } + + if (intercept) { + //TODO handling uint indices + renderlist_t *list = NULL; + GLsizei min, max; + + if(!need_free) { + GLushort *tmp = sindices; + sindices = (GLushort*)malloc(count*sizeof(GLushort)); + memcpy(sindices, tmp, count*sizeof(GLushort)); + } + normalize_indices_us(sindices, &max, &min, count); + list = arrays_to_renderlist(list, mode, min, max + 1); + list->indices = sindices; + list->ilen = count; + list->indice_cap = count; + list = end_renderlist(list); + draw_renderlist(list); + free_renderlist(list); + return; + } else { + glDrawElementsCommon(mode, 0, count, 0, sindices, iindices, 1); + if(need_free) + free(sindices); + } +} +void glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices) AliasExport("gl4es_glDrawElements"); + +void gl4es_glDrawArrays(GLenum mode, GLint first, GLsizei count) { + //printf("glDrawArrays(%s, %d, %d), list=%p pending=%d\n", PrintEnum(mode), first, count, glstate->list.active, glstate->list.pending); + // special check for QUADS and TRIANGLES that need multiple of 4 or 3 vertex... + count = adjust_vertices(mode, count); + + if (count<0) { + errorShim(GL_INVALID_VALUE); + return; + } + if (count==0) { + noerrorShim(); + return; + } + + if (glstate->raster.bm_drawing) + bitmap_flush(); + + // special case for (very) large GL_QUADS array + if ((mode==GL_QUADS) && (count>4*8000)) { + // split the array in manageable slice + int cnt = 4*8000; + for (int i=0; icount) cnt = count-i; + gl4es_glDrawArrays(mode, i, cnt); + } + return; + } + noerrorShim(); + + bool intercept = should_intercept_render(mode); + //BATCH Mode + if (!glstate->list.compiling) { + if(!intercept && glstate->list.pending && count>MAX_BATCH) // too large and will not intercept, stop the BATCH + flush(); + else if((!intercept && !glstate->list.pending && countlist.pending = 1; + glstate->list.active = alloc_renderlist(); + } + } + + if (glstate->list.active) { + NewStage(glstate->list.active, STAGE_DRAW); + glstate->list.active = arrays_to_renderlist(glstate->list.active, mode, first, count+first); + if(glstate->list.pending) { + NewStage(glstate->list.active, STAGE_POSTDRAW); + } else { + glstate->list.active = extend_renderlist(glstate->list.active); + } + return; + } + + /*if (glstate->polygon_mode == GL_LINE && mode>=GL_TRIANGLES) + mode = GL_LINE_LOOP;*/ + if (glstate->polygon_mode == GL_POINT && mode>=GL_TRIANGLES) + mode = GL_POINTS; + + if (intercept) { + renderlist_t *list; + list = arrays_to_renderlist(NULL, mode, first, count+first); + list = end_renderlist(list); + draw_renderlist(list); + free_renderlist(list); + } else { + if (mode==GL_QUADS) { + // TODO: move those static in glstate + static GLushort *indices = NULL; + static int indcnt = 0; + static int indfirst = 0; + int realfirst = ((first%4)==0)?0:first; + int realcount = count + (first-realfirst); + if((indcnt < realcount) || (indfirst!=realfirst)) { + if(indcnt < realcount) { + indcnt = realcount; + if (indices) free(indices); + indices = (GLushort*)malloc(sizeof(GLushort)*(indcnt*3/2)); + } + indfirst = realfirst; + GLushort *p = indices; + for (int i=0, j=indfirst; i+3list.active); + bool intercept = should_intercept_render(mode); + + GLsizei maxcount=counts[0]; + GLsizei mincount=counts[0]; + for (int i=1; imaxcount) maxcount=counts[i]; + if(counts[i]list.pending && maxcount>MAX_BATCH) // too large and will not intercept, stop the BATCH + flush(); + else if((!intercept && !glstate->list.pending && mincountlist.pending = 1; + glstate->list.active = alloc_renderlist(); + } + } + renderlist_t *list = NULL; + for (int i=0; iraster.bm_drawing) + bitmap_flush(); + + noerrorShim(); + + if (compiling) { + NewStage(glstate->list.active, STAGE_DRAW); + glstate->list.active = arrays_to_renderlist(glstate->list.active, mode, first, count+first); + if(glstate->list.pending) { + NewStage(glstate->list.active, STAGE_POSTDRAW); + } else { + glstate->list.active = extend_renderlist(glstate->list.active); + } + continue; + } + + if (glstate->polygon_mode == GL_POINT && mode>=GL_TRIANGLES) + mode = GL_POINTS; + + if (intercept) { + if(list) { + NewStage(list, STAGE_DRAW); + } + list = arrays_to_renderlist(NULL, mode, first, count+first); + } else { + if (mode==GL_QUADS) { + // TODO: move those static in glstate + static GLushort *indices = NULL; + static int indcnt = 0; + static int indfirst = 0; + int realfirst = ((first%4)==0)?0:first; + int realcount = count + (first-realfirst); + if((indcnt < realcount) || (indfirst!=realfirst)) { + if(indcnt < realcount) { + indcnt = realcount; + if (indices) free(indices); + indices = (GLushort*)malloc(sizeof(GLushort)*(indcnt*3/2)); + } + indfirst = realfirst; + GLushort *p = indices; + for (int i=0, j=indfirst; i+3list.active); + bool intercept = should_intercept_render(mode); + + GLsizei maxcount=counts[0]; + GLsizei mincount=counts[0]; + for (int i=1; imaxcount) maxcount=counts[i]; + if(counts[i]list.pending && maxcount>MAX_BATCH) // too large and will not intercept, stop the BATCH + flush(); + else if((!intercept && !glstate->list.pending && mincountlist.pending = 1; + glstate->list.active = alloc_renderlist(); + } + } + renderlist_t *list = NULL; + for (int i=0; ivao->elements)?glstate->vao->elements->data + (uintptr_t)indices:indices, + type, 1, 0, GL_UNSIGNED_SHORT, 1, 0, count); + } else { + if(type==GL_UNSIGNED_INT) + iindices = (glstate->vao->elements)?(glstate->vao->elements->data + (uintptr_t)indices):(GLvoid*)indices; + else + sindices = (glstate->vao->elements)?(glstate->vao->elements->data + (uintptr_t)indices):(GLvoid*)indices; + } + + if (compiling) { + // TODO, handle uint indices + renderlist_t *list = NULL; + GLsizei min, max; + + NewStage(glstate->list.active, STAGE_DRAW); + list = glstate->list.active; + + if(!need_free) { + GLushort *tmp = sindices; + sindices = (GLushort*)malloc(count*sizeof(GLushort)); + memcpy(sindices, tmp, count*sizeof(GLushort)); + } + normalize_indices_us(sindices, &max, &min, count); + list = arrays_to_renderlist(list, mode, min, max + 1); + list->indices = sindices; + list->ilen = count; + list->indice_cap = count; + //end_renderlist(list); + + if(glstate->list.pending) { + NewStage(glstate->list.active, STAGE_POSTDRAW); + } else { + glstate->list.active = extend_renderlist(list); + } + continue; + } + + if (intercept) { + //TODO handling uint indices + renderlist_t *list = NULL; + GLsizei min, max; + + if(!need_free) { + GLushort *tmp = sindices; + sindices = (GLushort*)malloc(count*sizeof(GLushort)); + memcpy(sindices, tmp, count*sizeof(GLushort)); + } + normalize_indices_us(sindices, &max, &min, count); + if(list) { + NewStage(list, STAGE_DRAW); + } + list = arrays_to_renderlist(list, mode, min, max + 1); + list->indices = sindices; + list->ilen = count; + list->indice_cap = count; + continue; + } else { + glDrawElementsCommon(mode, 0, count, 0, sindices, iindices, 1); + if(need_free) + free(sindices); + } + } + if(list) { + list = end_renderlist(list); + draw_renderlist(list); + free_renderlist(list); + } +} +void glMultiDrawElements( GLenum mode, GLsizei *count, GLenum type, const void * const *indices, GLsizei primcount) AliasExport("gl4es_glMultiDrawElements"); + +void gl4es_glMultiDrawElementsBaseVertex( GLenum mode, GLsizei *counts, GLenum type, const void * const *indices, GLsizei primcount, const GLint * basevertex) { + //printf("glMultiDrawElementsBaseVertex(%s, %p, %s, @%p, %d, @%p), inlist=%i, pending=%d\n", PrintEnum(mode), count, PrintEnum(type), indices, primcount, basevertex, (glstate->list.active)?1:0, glstate->list.pending); + // divide the call, should try something better one day... + bool compiling = (glstate->list.active); + bool intercept = should_intercept_render(mode); + //BATCH Mode + GLsizei maxcount=counts[0]; + GLsizei mincount=counts[0]; + for (int i=1; imaxcount) maxcount=counts[i]; + if(counts[i]list.pending && maxcount>MAX_BATCH) // too large and will not intercept, stop the BATCH + flush(); + else if((!intercept && !glstate->list.pending && mincountlist.pending = 1; + glstate->list.active = alloc_renderlist(); + } + } + renderlist_t *list = NULL; + for (int i=0; ivao->elements)?glstate->vao->elements->data + (uintptr_t)indices:indices, + type, 1, 0, GL_UNSIGNED_INT, 1, 0, count); + else + sindices = copy_gl_array((glstate->vao->elements)?glstate->vao->elements->data + (uintptr_t)indices:indices, + type, 1, 0, GL_UNSIGNED_SHORT, 1, 0, count); + + if (compiling) { + // TODO, handle uint indices + renderlist_t *list = NULL; + GLsizei min, max; + + NewStage(glstate->list.active, STAGE_DRAW); + list = glstate->list.active; + + normalize_indices_us(sindices, &max, &min, count); + list = arrays_to_renderlist(list, mode, min + basevertex[i], max + basevertex[i] + 1); + list->indices = sindices; + list->ilen = count; + list->indice_cap = count; + //end_renderlist(list); + + if(glstate->list.pending) { + NewStage(glstate->list.active, STAGE_POSTDRAW); + } else { + glstate->list.active = extend_renderlist(list); + } + continue; + } + + if (intercept) { + //TODO handling uint indices + GLsizei min, max; + + normalize_indices_us(sindices, &max, &min, count); + if(list) { + NewStage(list, STAGE_DRAW); + } + list = arrays_to_renderlist(list, mode, min + basevertex[i], max + basevertex[i] + 1); + list->indices = sindices; + list->ilen = count; + list->indice_cap = count; + continue; + } else { + if(iindices) + for(int i=0; ivao->vertex)?glstate->vao->vertex->data:NULL, (glstate->vao->elements)?glstate->vao->elements->data:NULL, glstate->list.pending); + if(basevertex==0) + gl4es_glDrawElements(mode, count, type, indices); + else { + count = adjust_vertices(mode, count); + + if (count<0) { + errorShim(GL_INVALID_VALUE); + return; + } + if (count==0) { + noerrorShim(); + return; + } + + bool compiling = (glstate->list.active); + bool intercept = should_intercept_render(mode); + + //BATCH Mode + if(!compiling) { + if(!intercept && glstate->list.pending && count>MAX_BATCH) // too large and will not intercept, stop the BATCH + flush(); + else if((!intercept && !glstate->list.pending && countlist.pending = 1; + glstate->list.active = alloc_renderlist(); + } + } + + noerrorShim(); + GLushort *sindices = NULL; + GLuint *iindices = NULL; + + if(type==GL_UNSIGNED_INT && hardext.elementuint && !compiling && !intercept) + iindices = copy_gl_array((glstate->vao->elements)?glstate->vao->elements->data + (uintptr_t)indices:indices, + type, 1, 0, GL_UNSIGNED_INT, 1, 0, count); + else + sindices = copy_gl_array((glstate->vao->elements)?glstate->vao->elements->data + (uintptr_t)indices:indices, + type, 1, 0, GL_UNSIGNED_SHORT, 1, 0, count); + + if (compiling) { + // TODO, handle uint indices + renderlist_t *list = NULL; + GLsizei min, max; + + NewStage(glstate->list.active, STAGE_DRAW); + list = glstate->list.active; + + normalize_indices_us(sindices, &max, &min, count); + list = arrays_to_renderlist(list, mode, min + basevertex, max + basevertex + 1); + list->indices = sindices; + list->ilen = count; + list->indice_cap = count; + //end_renderlist(list); + + if(glstate->list.pending) { + NewStage(glstate->list.active, STAGE_POSTDRAW); + } else { + glstate->list.active = extend_renderlist(list); + } + return; + } + + if (intercept) { + //TODO handling uint indices + renderlist_t *list = NULL; + GLsizei min, max; + + normalize_indices_us(sindices, &max, &min, count); + list = arrays_to_renderlist(list, mode, min + basevertex, max + basevertex + 1); + list->indices = sindices; + list->ilen = count; + list->indice_cap = count; + list = end_renderlist(list); + draw_renderlist(list); + free_renderlist(list); + return; + } else { + if(iindices) + for(int i=0; ilist.active)?1:0, glstate->list.pending); + if(basevertex==0) { + gl4es_glDrawRangeElements(mode, start, end, count, type, indices); + } else { + count = adjust_vertices(mode, count); + + if (count<0) { + errorShim(GL_INVALID_VALUE); + return; + } + if (count==0) { + noerrorShim(); + return; + } + + bool compiling = (glstate->list.active); + bool intercept = should_intercept_render(mode); + + //BATCH Mode + if(!compiling) { + if(!intercept && glstate->list.pending && count>MAX_BATCH) // too large and will not intercept, stop the BATCH + flush(); + else if((!intercept && !glstate->list.pending && countlist.pending = 1; + glstate->list.active = alloc_renderlist(); + } + } + + noerrorShim(); + GLushort *sindices = NULL; + GLuint *iindices = NULL; + if(type==GL_UNSIGNED_INT && hardext.elementuint && !compiling && !intercept) + iindices = copy_gl_array((glstate->vao->elements)?glstate->vao->elements->data + (uintptr_t)indices:indices, + type, 1, 0, GL_UNSIGNED_INT, 1, 0, count); + else + sindices = copy_gl_array((glstate->vao->elements)?glstate->vao->elements->data + (uintptr_t)indices:indices, + type, 1, 0, GL_UNSIGNED_SHORT, 1, 0, count); + + if (compiling) { + // TODO, handle uint indices + renderlist_t *list = NULL; + + NewStage(glstate->list.active, STAGE_DRAW); + list = glstate->list.active; + + for (int i=0; iindices = sindices; + list->ilen = count; + list->indice_cap = count; + //end_renderlist(list); + + if(glstate->list.pending) { + NewStage(glstate->list.active, STAGE_POSTDRAW); + } else { + glstate->list.active = extend_renderlist(list); + } + return; + } + + if (intercept) { + //TODO handling uint indices + renderlist_t *list = NULL; + + for (int i=0; iindices = sindices; + list->ilen = count; + list->indice_cap = count; + list = end_renderlist(list); + draw_renderlist(list); + free_renderlist(list); + + return; + } else { + if(iindices) + for(int i=0; iraster.bm_drawing) + bitmap_flush(); + + // special case for (very) large GL_QUADS array + if ((mode==GL_QUADS) && (count>4*8000)) { + // split the array in manageable slice + int cnt = 4*8000; + for (int i=0; icount) cnt = count-i; + gl4es_glDrawArrays(mode, i, cnt); + } + return; + } + noerrorShim(); + + bool intercept = should_intercept_render(mode); + //BATCH Mode + if (!glstate->list.compiling) { + if(!intercept && glstate->list.pending && count>MAX_BATCH) // too large and will not intercept, stop the BATCH + flush(); + else if((!intercept && !glstate->list.pending && countlist.pending = 1; + glstate->list.active = alloc_renderlist(); + } + } + + if (glstate->list.active) { + NewStage(glstate->list.active, STAGE_DRAW); + glstate->list.active = arrays_to_renderlist(glstate->list.active, mode, first, count+first); + glstate->list.active->instanceCount = primcount; + if(glstate->list.pending) { + NewStage(glstate->list.active, STAGE_POSTDRAW); + } else { + glstate->list.active = extend_renderlist(glstate->list.active); + } + return; + } + + /*if (glstate->polygon_mode == GL_LINE && mode>=GL_TRIANGLES) + mode = GL_LINE_LOOP;*/ + if (glstate->polygon_mode == GL_POINT && mode>=GL_TRIANGLES) + mode = GL_POINTS; + + if (intercept) { + renderlist_t *list = NULL; + list = arrays_to_renderlist(list, mode, first, count+first); + list->instanceCount = primcount; + list = end_renderlist(list); + draw_renderlist(list); + free_renderlist(list); + } else { + if (mode==GL_QUADS) { + // TODO: move those static in glstate + static GLushort *indices = NULL; + static int indcnt = 0; + static int indfirst = 0; + int realfirst = ((first%4)==0)?0:first; + int realcount = count + (first-realfirst); + if((indcnt < realcount) || (indfirst!=realfirst)) { + if(indcnt < realcount) { + indcnt = realcount; + if (indices) free(indices); + indices = (GLushort*)malloc(sizeof(GLushort)*(indcnt*3/2)); + } + indfirst = realfirst; + GLushort *p = indices; + for (int i=0, j=indfirst; i+3list.active); + bool intercept = should_intercept_render(mode); + + //BATCH Mode + if(!compiling) { + if(!intercept && glstate->list.pending && count>MAX_BATCH) // too large and will not intercept, stop the BATCH + flush(); + else if((!intercept && !glstate->list.pending && countlist.pending = 1; + glstate->list.active = alloc_renderlist(); + } + } + + noerrorShim(); + GLushort *sindices = NULL; + GLuint *iindices = NULL; + bool need_free = !( + (type==GL_UNSIGNED_SHORT) || + (!compiling && !intercept && type==GL_UNSIGNED_INT && hardext.elementuint) + ); + if(need_free) { + sindices = copy_gl_array((glstate->vao->elements)?(glstate->vao->elements->data + (uintptr_t)indices):indices, + type, 1, 0, GL_UNSIGNED_SHORT, 1, 0, count); + } else { + if(type==GL_UNSIGNED_INT) + iindices = (glstate->vao->elements)?(glstate->vao->elements->data + (uintptr_t)indices):(GLvoid*)indices; + else + sindices = (glstate->vao->elements)?(glstate->vao->elements->data + (uintptr_t)indices):(GLvoid*)indices; + } + + if (compiling) { + // TODO, handle uint indices + renderlist_t *list = NULL; + GLsizei min, max; + + NewStage(glstate->list.active, STAGE_DRAW); + list = glstate->list.active; + + if(!need_free) { + GLushort *tmp = sindices; + sindices = (GLushort*)malloc(count*sizeof(GLushort)); + memcpy(sindices, tmp, count*sizeof(GLushort)); + } + normalize_indices_us(sindices, &max, &min, count); + list = arrays_to_renderlist(list, mode, min, max + 1); + list->indices = sindices; + list->ilen = count; + list->indice_cap = count; + list->instanceCount = primcount; + //end_renderlist(list); + + if(glstate->list.pending) { + NewStage(glstate->list.active, STAGE_POSTDRAW); + } else { + glstate->list.active = extend_renderlist(list); + } + return; + } + + if (intercept) { + //TODO handling uint indices + renderlist_t *list = NULL; + GLsizei min, max; + + if(!need_free) { + GLushort *tmp = sindices; + sindices = (GLushort*)malloc(count*sizeof(GLushort)); + memcpy(sindices, tmp, count*sizeof(GLushort)); + } + normalize_indices_us(sindices, &max, &min, count); + list = arrays_to_renderlist(list, mode, min, max + 1); + list->indices = sindices; + list->ilen = count; + list->indice_cap = count; + list->instanceCount = primcount; + list = end_renderlist(list); + draw_renderlist(list); + free_renderlist(list); + return; + } else { + glDrawElementsCommon(mode, 0, count, 0, sindices, iindices, primcount); + if(need_free) + free(sindices); + } +} +void glDrawElementsInstanced(GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei primcount) AliasExport("gl4es_glDrawElementsInstanced"); +void glDrawElementsInstancedARB(GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei primcount) AliasExport("gl4es_glDrawElementsInstanced"); + +void gl4es_glDrawElementsInstancedBaseVertex(GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei primcount, GLint basevertex) { + //printf("glDrawElementsInstanceBaseVertex(%s, %d, %s, %p, %d, %d), vtx=%p map=%p, pending=%d\n", PrintEnum(mode), count, PrintEnum(type), indices, primcount, basevertex, (glstate->vao->vertex)?glstate->vao->vertex->data:NULL, (glstate->vao->elements)?glstate->vao->elements->data:NULL, glstate->list.pending); + if(basevertex==0) + gl4es_glDrawElementsInstanced(mode, count, type, indices, primcount); + else { + count = adjust_vertices(mode, count); + + if (count<0) { + errorShim(GL_INVALID_VALUE); + return; + } + if (count==0) { + noerrorShim(); + return; + } + + bool compiling = (glstate->list.active); + bool intercept = should_intercept_render(mode); + + //BATCH Mode + if(!compiling) { + if(!intercept && glstate->list.pending && count>MAX_BATCH) // too large and will not intercept, stop the BATCH + flush(); + else if((!intercept && !glstate->list.pending && countlist.pending = 1; + glstate->list.active = alloc_renderlist(); + } + } + + noerrorShim(); + GLushort *sindices = NULL; + GLuint *iindices = NULL; + + if(type==GL_UNSIGNED_INT && hardext.elementuint && !compiling && !intercept) + iindices = copy_gl_array((glstate->vao->elements)?glstate->vao->elements->data + (uintptr_t)indices:indices, + type, 1, 0, GL_UNSIGNED_INT, 1, 0, count); + else + sindices = copy_gl_array((glstate->vao->elements)?glstate->vao->elements->data + (uintptr_t)indices:indices, + type, 1, 0, GL_UNSIGNED_SHORT, 1, 0, count); + + if (compiling) { + // TODO, handle uint indices + renderlist_t *list = NULL; + GLsizei min, max; + + NewStage(glstate->list.active, STAGE_DRAW); + list = glstate->list.active; + + normalize_indices_us(sindices, &max, &min, count); + list = arrays_to_renderlist(list, mode, min + basevertex, max + basevertex + 1); + list->indices = sindices; + list->ilen = count; + list->indice_cap = count; + list->instanceCount = primcount; + //end_renderlist(list); + + if(glstate->list.pending) { + NewStage(glstate->list.active, STAGE_POSTDRAW); + } else { + glstate->list.active = extend_renderlist(list); + } + return; + } + + if (intercept) { + //TODO handling uint indices + renderlist_t *list = NULL; + GLsizei min, max; + + normalize_indices_us(sindices, &max, &min, count); + list = arrays_to_renderlist(list, mode, min + basevertex, max + basevertex + 1); + list->indices = sindices; + list->ilen = count; + list->indice_cap = count; + list->instanceCount = primcount; + list = end_renderlist(list); + draw_renderlist(list); + free_renderlist(list); + return; + } else { + if(iindices) + for(int i=0; ivao->pointers[i].enabled && !valid_vertex_type(glstate->vao->pointers[i].type)) + ok = 0; + if (ok) { + // try to see if there is a master index.... + uintptr_t master = (uintptr_t)glstate->vao->pointers[ATT_VERTEX].pointer; + int stride = glstate->vao->pointers[ATT_VERTEX].stride; + if(stride<16) stride = 0; + for (int i=0; ivao->pointers[i].enabled) { + uintptr_t p = (uintptr_t)glstate->vao->pointers[i].pointer; + int nstride = glstate->vao->pointers[i].stride; + if(nstride<16) nstride=0; + if(!stride && nstride) { + stride = nstride; + master = p; + } else if(stride && stride==nstride) { + if ((p>master-stride) && (pvao->pointers[i].enabled) { + uintptr_t p = (uintptr_t)glstate->vao->pointers[i].pointer; + if(!(p>=master && pvao->pointers[i].type)*(glstate->vao->pointers[i].stride?glstate->vao->pointers[i].stride:glstate->vao->pointers[i].size)*tcount; + } + } + } + // now allocate (if needed) the buffer and bind it + gl4es_scratch_vertex(total); + uintptr_t ptr = 0; + // move "master" data if there + LOAD_GLES(glBufferSubData); + LOAD_GLES(glBindBuffer); + if(stride) { + gles_glBufferSubData(GL_ARRAY_BUFFER, ptr+first*stride, stride*count, (void*)master); + ptr += stride*tcount; + } + for (int i=0; ivao->pointers[i].enabled) { + uintptr_t p = (uintptr_t)glstate->vao->pointers[i].pointer; + if(!(p>=master && pvao->pointers[i].type)*(glstate->vao->pointers[i].stride?glstate->vao->pointers[i].stride:glstate->vao->pointers[i].size); + gles_glBufferSubData(GL_ARRAY_BUFFER, ptr+size*first, size*count, glstate->vao->pointers[i].pointer); + glstate->vao->locked_pointers[i].pointer = (void*)ptr; + ptr+=size*tcount; + } else { + glstate->vao->locked_pointers[i].pointer = (void*)(((uintptr_t)glstate->vao->pointers[i].pointer)-master); + } + glstate->vao->locked_pointers[i].type = glstate->vao->pointers[i].type; + glstate->vao->locked_pointers[i].size = glstate->vao->pointers[i].size; + glstate->vao->locked_pointers[i].stride = glstate->vao->pointers[i].stride; +//printf("BindBuffers %d = %p %sx%d (%d)\n", i, glstate->vao->locked_pointers[i].pointer, PrintEnum(glstate->vao->locked_pointers[i].type), glstate->vao->locked_pointers[i].size, glstate->vao->locked_pointers[i].stride); + } + glstate->vao->locked_pointers[i].enabled = glstate->vao->pointers[i].enabled; + } +//printf("BindBuffers (fist=%d, count=%d) vertex = %p %sx%d (%d)\n", first, count, glstate->vao->locked_pointers[ATT_VERTEX].pointer, PrintEnum(glstate->vao->locked_pointers[ATT_VERTEX].type), glstate->vao->locked_pointers[ATT_VERTEX].size, glstate->vao->locked_pointers[ATT_VERTEX].stride); + // unbind the buffer + gl4es_use_scratch_vertex(0); + // All done! + glstate->vao->locked_mapped = true; + } + } +} diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/enable.c b/Projects/Android/jni/SupportLibs/gl4es/src/gl/enable.c new file mode 100644 index 0000000..5cd61ee --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/enable.c @@ -0,0 +1,407 @@ +#include "gl4es.h" +#include "glstate.h" +#include "init.h" +#include "loader.h" + +static void gl_changetex(int n) +{ + if(glstate->bound_changed < n+1) + glstate->bound_changed = n+1; +} + +static void fpe_changeplane(int n, bool enable) +{ + glstate->fpe = NULL; + if(enable) + glstate->fpe_state->plane |= 1<fpe_state->plane &= ~(1<fpe = NULL; + if(enable) + glstate->fpe_state->light |= 1<fpe_state->light &= ~(1<fpe_bound_changed < n+1) + glstate->fpe_bound_changed = n+1; +} +#define generate_changetexgen(C) \ +static void fpe_changetexgen_##C(int n, bool enable) \ +{ \ + if(enable) \ + glstate->fpe_state->texgen_##C |= 1<fpe_state->texgen_##C &= ~(1<vao->pointers[ATT_MULTITEXCOORD0+tmu].enabled = enable; + if(enable) { + if(glstate->vao->maxtexvao->maxtex=tmu+1; + } else { + if(glstate->vao->maxtex==tmu+1) { + glstate->vao->maxtex=tmu; + } + } +} + +#ifndef GL_TEXTURE_STREAM_IMG +#define GL_TEXTURE_STREAM_IMG 0x8C0D +#endif + +static void proxy_glEnable(GLenum cap, bool enable, void (*next)(GLenum)) { + #define proxy_GO(constant, name) \ + case constant: if(glstate->enable.name != enable) {if(glstate->list.pending) flush(); glstate->enable.name = enable; next(cap);} break + #define proxy_GOFPE(constant, name, fct) \ + case constant: if(glstate->enable.name != enable) {if(glstate->list.pending) flush(); glstate->enable.name = enable; if(glstate->fpe_state) { fct; } else next(cap);} break + #define GO(constant, name) \ + case constant: if(glstate->list.pending && glstate->enable.name!=enable) flush(); glstate->enable.name = enable; break; + #define GONF(constant, name) \ + case constant: glstate->enable.name = enable; break; + #define GOFPE(constant, name, fct) \ + case constant: if(glstate->list.pending && glstate->enable.name!=enable) flush(); glstate->enable.name = enable; if(glstate->fpe_state) { fct; } break; + #define proxy_clientGO(constant, name) \ + case constant: if (glstate->vao->name != enable) {glstate->vao->name = enable; next(cap);} break + #define clientGO(constant, name) \ + case constant: glstate->vao->name = enable; break; + #define clientGO_proxyFPE(constant, name) \ + case constant: glstate->vao->name = enable; if(glstate->fpe_state) { next(cap);} break; + // Alpha Hack + if (globals4es.alphahack && (cap==GL_ALPHA_TEST) && enable) { + if (!glstate->texture.bound[glstate->texture.active][ENABLED_TEX2D]->alpha) + enable = false; + } + noerrorShim(); +#ifdef TEXSTREAM + if (cap==GL_TEXTURE_STREAM_IMG) { + if(glstate->list.pending) flush(); + if(enable) + glstate->enable.texture[glstate->texture.active] |= (1<enable.texture[glstate->texture.active] &= ~(1<texture.active); + if(glstate->fpe_state) + fpe_changetex(glstate->texture.active); + else + next(cap); + return; + } +#endif + + switch (cap) { + GO(GL_AUTO_NORMAL, auto_normal); + proxy_GOFPE(GL_ALPHA_TEST, alpha_test,glstate->fpe_state->alphatest=enable); + proxy_GOFPE(GL_FOG, fog, glstate->fpe_state->fog=enable); + proxy_GO(GL_BLEND, blend); + proxy_GO(GL_CULL_FACE, cull_face); + proxy_GO(GL_DEPTH_TEST, depth_test); + proxy_GO(GL_STENCIL_TEST, stencil_test); + // texgen + GOFPE(GL_TEXTURE_GEN_S, texgen_s[glstate->texture.active], fpe_changetexgen_s(glstate->texture.active, enable)); //TODO: FPE stuffs + GOFPE(GL_TEXTURE_GEN_T, texgen_t[glstate->texture.active], fpe_changetexgen_t(glstate->texture.active, enable)); + GOFPE(GL_TEXTURE_GEN_R, texgen_r[glstate->texture.active], fpe_changetexgen_r(glstate->texture.active, enable)); + GOFPE(GL_TEXTURE_GEN_Q, texgen_q[glstate->texture.active], fpe_changetexgen_q(glstate->texture.active, enable)); + GO(GL_LINE_STIPPLE, line_stipple); + + // clip plane + proxy_GOFPE(GL_CLIP_PLANE0, plane[0], fpe_changeplane(0, enable)); + proxy_GOFPE(GL_CLIP_PLANE1, plane[1], fpe_changeplane(1, enable)); + proxy_GOFPE(GL_CLIP_PLANE2, plane[2], fpe_changeplane(2, enable)); + proxy_GOFPE(GL_CLIP_PLANE3, plane[3], fpe_changeplane(3, enable)); + proxy_GOFPE(GL_CLIP_PLANE4, plane[4], fpe_changeplane(4, enable)); + proxy_GOFPE(GL_CLIP_PLANE5, plane[5], fpe_changeplane(5, enable)); + + // lights + proxy_GOFPE(GL_LIGHT0, light[0], fpe_changelight(0, enable)); + proxy_GOFPE(GL_LIGHT1, light[1], fpe_changelight(1, enable)); + proxy_GOFPE(GL_LIGHT2, light[2], fpe_changelight(2, enable)); + proxy_GOFPE(GL_LIGHT3, light[3], fpe_changelight(3, enable)); + proxy_GOFPE(GL_LIGHT4, light[4], fpe_changelight(4, enable)); + proxy_GOFPE(GL_LIGHT5, light[5], fpe_changelight(5, enable)); + proxy_GOFPE(GL_LIGHT6, light[6], fpe_changelight(6, enable)); + proxy_GOFPE(GL_LIGHT7, light[7], fpe_changelight(7, enable)); + proxy_GOFPE(GL_LIGHTING, lighting, glstate->fpe_state->lighting=enable); + proxy_GOFPE(GL_NORMALIZE, normalize, glstate->fpe_state->normalize=enable); + proxy_GOFPE(GL_RESCALE_NORMAL, normal_rescale, glstate->fpe_state->rescaling=enable); + proxy_GOFPE(GL_COLOR_MATERIAL, color_material, glstate->fpe_state->color_material=enable); + + // point sprite + proxy_GOFPE(GL_POINT_SPRITE, pointsprite, glstate->fpe_state->pointsprite=enable); // TODO: plugin fpe stuffs + + // Smooth and multisample (todo: do somthing with fpe?) + proxy_GOFPE(GL_MULTISAMPLE, multisample, ); + proxy_GOFPE(GL_SAMPLE_COVERAGE, sample_coverage, ); + proxy_GOFPE(GL_SAMPLE_ALPHA_TO_COVERAGE, sample_alpha_to_coverage, ); + proxy_GOFPE(GL_SAMPLE_ALPHA_TO_ONE, sample_alpha_to_one, ); + proxy_GOFPE(GL_POINT_SMOOTH, point_smooth, ); + proxy_GOFPE(GL_LINE_SMOOTH, line_smooth, ); + + proxy_GO(GL_POLYGON_OFFSET_FILL, polyfill_offset); + + // color logic op + proxy_GOFPE(GL_COLOR_LOGIC_OP, color_logic_op, ); + + // Secondary color + GOFPE(GL_COLOR_SUM, color_sum, glstate->fpe_state->colorsum = enable); + //cannot use clientGO_proxyFPE here, has the ClientArray are really enabled / disabled elsewhere in fact (inside glDraw or list_draw) + clientGO(GL_SECONDARY_COLOR_ARRAY, pointers[ATT_SECONDARY].enabled); + clientGO(GL_FOG_COORD_ARRAY, pointers[ATT_FOGCOORD].enabled); + + // for glDrawArrays + clientGO(GL_VERTEX_ARRAY, pointers[ATT_VERTEX].enabled); + clientGO(GL_NORMAL_ARRAY, pointers[ATT_NORMAL].enabled); + clientGO(GL_COLOR_ARRAY, pointers[ATT_COLOR].enabled); + case GL_TEXTURE_COORD_ARRAY: change_vao_texcoord(glstate->texture.client, enable); break; + + // map eval + GONF(GL_MAP1_COLOR_4 , map1_color4); + GONF(GL_MAP1_INDEX , map1_index); + GONF(GL_MAP1_NORMAL , map1_normal); + GONF(GL_MAP1_TEXTURE_COORD_1 , map1_texture1); + GONF(GL_MAP1_TEXTURE_COORD_2 , map1_texture2); + GONF(GL_MAP1_TEXTURE_COORD_3 , map1_texture3); + GONF(GL_MAP1_TEXTURE_COORD_4 , map1_texture4); + GONF(GL_MAP1_VERTEX_3 , map1_vertex3); + GONF(GL_MAP1_VERTEX_4 , map1_vertex4); + GONF(GL_MAP2_COLOR_4 , map2_color4); + GONF(GL_MAP2_INDEX , map2_index); + GONF(GL_MAP2_NORMAL , map2_normal); + GONF(GL_MAP2_TEXTURE_COORD_1 , map2_texture1); + GONF(GL_MAP2_TEXTURE_COORD_2 , map2_texture2); + GONF(GL_MAP2_TEXTURE_COORD_3 , map2_texture3); + GONF(GL_MAP2_TEXTURE_COORD_4 , map2_texture4); + GONF(GL_MAP2_VERTEX_3 , map2_vertex3); + GONF(GL_MAP2_VERTEX_4 , map2_vertex4); + + // Texture 1D and 3D + case GL_TEXTURE_1D: + if(glstate->list.pending) flush(); + if(enable) + glstate->enable.texture[glstate->texture.active] |= (1<enable.texture[glstate->texture.active] &= ~(1<texture.active); + if(glstate->fpe_state) + fpe_changetex(glstate->texture.active); + break; + case GL_TEXTURE_2D: + if(glstate->list.pending && ((glstate->enable.texture[glstate->texture.active]>>ENABLED_TEX2D)&1)!=enable) flush(); + if(enable == ((glstate->enable.texture[glstate->texture.active]>>ENABLED_TEX2D)&1)) + return; // no change + if(enable) + glstate->enable.texture[glstate->texture.active] |= (1<enable.texture[glstate->texture.active] &= ~(1<texture.active); + if(glstate->fpe_state) + fpe_changetex(glstate->texture.active); + else { + realize_active(); + next(cap); + } + break; + case GL_TEXTURE_3D: + if(glstate->list.pending) flush(); + if(enable) + glstate->enable.texture[glstate->texture.active] |= (1<enable.texture[glstate->texture.active] &= ~(1<texture.active); + if(glstate->fpe_state) + fpe_changetex(glstate->texture.active); + break; + case GL_TEXTURE_RECTANGLE_ARB: + if(glstate->list.pending) flush(); + if(enable) + glstate->enable.texture[glstate->texture.active] |= (1<enable.texture[glstate->texture.active] &= ~(1<texture.active); + if(glstate->fpe_state) + fpe_changetex(glstate->texture.active); + break; + case GL_TEXTURE_CUBE_MAP: + if(glstate->list.pending) flush(); + if(enable) + glstate->enable.texture[glstate->texture.active] |= (1<enable.texture[glstate->texture.active] &= ~(1<texture.active); + if(glstate->fpe_state) + fpe_changetex(glstate->texture.active); + else { + realize_active(); + next(cap); + } + break; + + + default: errorGL(); if(glstate->list.pending) flush(); realize_active(); next(cap); break; + } + #undef proxy_GO + #undef GO + #undef proxy_clientGO + #undef clientGO +} + +void gl4es_glEnable(GLenum cap) { + if(!glstate->list.pending) { + PUSH_IF_COMPILING(glEnable) + } +#ifdef TEXSTREAM00 + if (globals4es.texstream && (cap==GL_TEXTURE_2D)) { + if (glstate->texture.bound[glstate->texture.active][ENABLED_TEX2D]->streamed) + cap = GL_TEXTURE_STREAM_IMG; + } + if (globals4es.texstream && (cap==GL_TEXTURE_RECTANGLE_ARB)) { + if (glstate->texture.bound[glstate->texture.active][ENABLED_TEXTURE_RECTANGLE]->streamed) + cap = GL_TEXTURE_STREAM_IMG; + } +#endif + LOAD_GLES(glEnable); + proxy_glEnable(cap, true, gles_glEnable); +} +void glEnable(GLenum cap) AliasExport("gl4es_glEnable"); + +void gl4es_glDisable(GLenum cap) { + if(!glstate->list.pending) { + PUSH_IF_COMPILING(glDisable) + } + +#ifdef TEXSTREAM00 + if (globals4es.texstream && (cap==GL_TEXTURE_2D)) { + if (glstate->texture.bound[glstate->texture.active][ENABLED_TEX2D]->streamed) + cap = GL_TEXTURE_STREAM_IMG; + } + if (globals4es.texstream && (cap==GL_TEXTURE_RECTANGLE_ARB)) { + if (glstate->texture.bound[glstate->texture.active][ENABLED_TEXTURE_RECTANGLE]->streamed) + cap = GL_TEXTURE_STREAM_IMG; + } +#endif + LOAD_GLES(glDisable); + proxy_glEnable(cap, false, gles_glDisable); +} +void glDisable(GLenum cap) AliasExport("gl4es_glDisable"); + +void gl4es_glEnableClientState(GLenum cap) { + ERROR_IN_BEGIN + // should flush for now... to be optimized later! + /*if (glstate->list.active && !glstate->list.compiling && !glstate->list.pending) + flush();*/ + LOAD_GLES_FPE(glEnableClientState); + proxy_glEnable(cap, true, gles_glEnableClientState); +} +void glEnableClientState(GLenum cap) AliasExport("gl4es_glEnableClientState"); + +void gl4es_glDisableClientState(GLenum cap) { + ERROR_IN_BEGIN + // should flush for now... to be optimized later! + /*if (glstate->list.active && !glstate->list.compiling && !glstate->list.pending) + flush();*/ + LOAD_GLES_FPE(glDisableClientState); + proxy_glEnable(cap, false, gles_glDisableClientState); +} +void glDisableClientState(GLenum cap) AliasExport("gl4es_glDisableClientState"); + + +#define isenabled(what, where) \ + case what: return glstate->enable.where +#define clientisenabled(what, where) \ + case what: return glstate->vao->where + +GLboolean gl4es_glIsEnabled(GLenum cap) { + if(glstate->list.begin) {errorShim(GL_INVALID_OPERATION); return GL_FALSE;} + if(glstate->list.compiling) {errorShim(GL_INVALID_OPERATION); return GL_FALSE;} + // should flush for now... but no need if it's just a pending list... + if (glstate->list.active && !glstate->list.pending) + flush(); + LOAD_GLES(glIsEnabled); + noerrorShim(); + switch (cap) { + isenabled(GL_AUTO_NORMAL, auto_normal); + isenabled(GL_ALPHA_TEST, alpha_test); + isenabled(GL_FOG, fog); + isenabled(GL_BLEND, blend); + isenabled(GL_CULL_FACE, cull_face); + isenabled(GL_DEPTH_TEST, depth_test); + isenabled(GL_STENCIL_TEST, stencil_test); + isenabled(GL_LINE_STIPPLE, line_stipple); + isenabled(GL_TEXTURE_GEN_S, texgen_s[glstate->texture.active]); + isenabled(GL_TEXTURE_GEN_T, texgen_t[glstate->texture.active]); + isenabled(GL_TEXTURE_GEN_R, texgen_r[glstate->texture.active]); + isenabled(GL_TEXTURE_GEN_Q, texgen_q[glstate->texture.active]); + isenabled(GL_COLOR_MATERIAL, color_material); + isenabled(GL_COLOR_SUM, color_sum); + isenabled(GL_POINT_SPRITE, pointsprite); + isenabled(GL_CLIP_PLANE0, plane[0]); + isenabled(GL_CLIP_PLANE1, plane[1]); + isenabled(GL_CLIP_PLANE2, plane[2]); + isenabled(GL_CLIP_PLANE3, plane[3]); + isenabled(GL_CLIP_PLANE4, plane[4]); + isenabled(GL_CLIP_PLANE5, plane[5]); + isenabled(GL_LIGHT0, light[0]); + isenabled(GL_LIGHT1, light[1]); + isenabled(GL_LIGHT2, light[2]); + isenabled(GL_LIGHT3, light[3]); + isenabled(GL_LIGHT4, light[4]); + isenabled(GL_LIGHT5, light[5]); + isenabled(GL_LIGHT6, light[6]); + isenabled(GL_LIGHT7, light[7]); + isenabled(GL_LIGHTING, lighting); + isenabled(GL_MULTISAMPLE, multisample); + isenabled(GL_SAMPLE_COVERAGE, sample_coverage); + isenabled(GL_SAMPLE_ALPHA_TO_COVERAGE, sample_alpha_to_coverage); + isenabled(GL_SAMPLE_ALPHA_TO_ONE, sample_alpha_to_one); + isenabled(GL_POINT_SMOOTH, point_smooth); + isenabled(GL_LINE_SMOOTH, line_smooth); + isenabled(GL_POLYGON_OFFSET_FILL, polyfill_offset); + isenabled(GL_COLOR_LOGIC_OP, color_logic_op); + clientisenabled(GL_SECONDARY_COLOR_ARRAY, pointers[ATT_SECONDARY].enabled); + clientisenabled(GL_FOG_COORD_ARRAY, pointers[ATT_FOGCOORD].enabled); + case GL_TEXTURE_1D: return glstate->enable.texture[glstate->texture.active]&(1<enable.texture[glstate->texture.active]&(1<enable.texture[glstate->texture.active]&(1<enable.texture[glstate->texture.active]&(1<texture.client].enabled); + isenabled(GL_NORMALIZE, normalize); + isenabled(GL_RESCALE_NORMAL, normal_rescale); + isenabled(GL_MAP1_COLOR_4, map1_color4); + isenabled(GL_MAP1_INDEX, map1_index); + isenabled(GL_MAP1_NORMAL, map1_normal); + isenabled(GL_MAP1_TEXTURE_COORD_1, map1_texture1); + isenabled(GL_MAP1_TEXTURE_COORD_2, map1_texture2); + isenabled(GL_MAP1_TEXTURE_COORD_3, map1_texture3); + isenabled(GL_MAP1_TEXTURE_COORD_4, map1_texture4); + isenabled(GL_MAP1_VERTEX_3, map1_vertex3); + isenabled(GL_MAP1_VERTEX_4, map1_vertex4); + isenabled(GL_MAP2_COLOR_4, map2_color4); + isenabled(GL_MAP2_INDEX, map2_index); + isenabled(GL_MAP2_NORMAL, map2_normal); + isenabled(GL_MAP2_TEXTURE_COORD_1, map2_texture1); + isenabled(GL_MAP2_TEXTURE_COORD_2, map2_texture2); + isenabled(GL_MAP2_TEXTURE_COORD_3, map2_texture3); + isenabled(GL_MAP2_TEXTURE_COORD_4, map2_texture4); + isenabled(GL_MAP2_VERTEX_3, map2_vertex3); + isenabled(GL_MAP2_VERTEX_4, map2_vertex4); + default: + errorGL(); + return gles_glIsEnabled(cap); + } +} +#undef isenabled +#undef clientisenabled +GLboolean glIsEnabled(GLenum cap) AliasExport("gl4es_glIsEnabled"); diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/enum_info.h b/Projects/Android/jni/SupportLibs/gl4es/src/gl/enum_info.h new file mode 100644 index 0000000..fadab78 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/enum_info.h @@ -0,0 +1,165 @@ +#ifndef _GL4ES_ENUM_INFO_H +#define _GL4ES_ENUM_INFO_H + +#include + +#include "const.h" +#include "debug.h" +#include "logs.h" + +static const GLsizei gl_sizeof(GLenum type) { + // types + switch (type) { + case GL_DOUBLE: + return 8; + case GL_FLOAT: + case GL_INT: + case GL_UNSIGNED_INT: + case GL_UNSIGNED_INT_10_10_10_2: + case GL_UNSIGNED_INT_2_10_10_10_REV: + case GL_UNSIGNED_INT_8_8_8_8: + case GL_UNSIGNED_INT_8_8_8_8_REV: + case GL_4_BYTES: + return 4; + case GL_3_BYTES: + return 3; + case GL_LUMINANCE_ALPHA: + case GL_SHORT: + case GL_HALF_FLOAT: + case GL_HALF_FLOAT_OES: + case GL_UNSIGNED_SHORT: + case GL_UNSIGNED_SHORT_1_5_5_5_REV: + case GL_UNSIGNED_SHORT_4_4_4_4: + case GL_UNSIGNED_SHORT_4_4_4_4_REV: + case GL_UNSIGNED_SHORT_5_5_5_1: + case GL_UNSIGNED_SHORT_5_6_5: + case GL_UNSIGNED_SHORT_5_6_5_REV: + case GL_2_BYTES: + return 2; + case GL_ALPHA: + case GL_LUMINANCE: + case GL_BYTE: + case GL_UNSIGNED_BYTE: + case GL_UNSIGNED_BYTE_2_3_3_REV: + case GL_UNSIGNED_BYTE_3_3_2: + case GL_DEPTH_COMPONENT: + case GL_COLOR_INDEX: + return 1; + } + // formats + LOGD("LIBGL: Unsupported pixel data type: %s\n", PrintEnum(type)); + return 0; +} + +static const GLuint gl_max_value(GLenum type) { + switch (type) { + // float/double only make sense on tex/color + // be careful about using this + case GL_DOUBLE: + case GL_FLOAT: + case GL_HALF_FLOAT: + case GL_HALF_FLOAT_OES: + return 1; + case GL_BYTE: return 127; + case GL_UNSIGNED_BYTE: return 255; + case GL_SHORT: return 32767; + case GL_UNSIGNED_SHORT: return 65535; + case GL_INT: return 2147483647; + case GL_UNSIGNED_INT: return 4294967295; + } + LOGD("LIBGL: unknown gl max value type: %s\n", PrintEnum(type)); + return 0; +} + +static const GLboolean is_type_packed(GLenum type) { + switch (type) { + case GL_4_BYTES: + case GL_3_BYTES: + case GL_2_BYTES: + case GL_UNSIGNED_BYTE_2_3_3_REV: + case GL_UNSIGNED_BYTE_3_3_2: + case GL_UNSIGNED_INT_10_10_10_2: + case GL_UNSIGNED_INT_2_10_10_10_REV: + case GL_UNSIGNED_INT_8_8_8_8: + case GL_UNSIGNED_INT_8_8_8_8_REV: + case GL_UNSIGNED_SHORT_1_5_5_5_REV: + case GL_UNSIGNED_SHORT_4_4_4_4: + case GL_UNSIGNED_SHORT_4_4_4_4_REV: + case GL_UNSIGNED_SHORT_5_5_5_1: + case GL_UNSIGNED_SHORT_5_6_5: + case GL_UNSIGNED_SHORT_5_6_5_REV: + return true; + } + return false; +} + +static const GLsizei pixel_sizeof(GLenum format, GLenum type) { + GLsizei width = 0; + switch (format) { + case GL_RED: + case GL_ALPHA: + case GL_LUMINANCE: + case GL_DEPTH_COMPONENT: + case GL_COLOR_INDEX: + width = 1; + break; + case GL_RG: + case GL_LUMINANCE_ALPHA: + width = 2; + break; + case GL_RGB: + case GL_BGR: + case GL_RGB8: + width = 3; + break; + case GL_RGBA: + case GL_BGRA: + case GL_RGBA8: + width = 4; + break; + default: + LOGD("LIBGL: unsupported pixel format %s\n", PrintEnum(format)); + return 0; + } + + if (is_type_packed(type)) + width = 1; + + return width * gl_sizeof(type); +} + +static const GLboolean pixel_hasalpha(GLenum format) { + switch (format) { + case GL_ALPHA: + case GL_LUMINANCE_ALPHA: + case GL_RGBA: + case GL_BGRA: + case GL_RGBA8: + case GL_COLOR_INDEX: + return true; + case GL_RED: + case GL_LUMINANCE: + case GL_RG: + case GL_RGB: + case GL_BGR: + case GL_RGB8: + case GL_DEPTH_COMPONENT: + return false; + default: + return true; + } +} + +static inline const GLboolean valid_vertex_type(GLenum type) { + switch (type) { + case GL_BYTE: + case GL_FIXED: + case GL_FLOAT: + case GL_SHORT: + return true; + default: + return false; + } +} + +#endif // _GL4ES_ENUM_INFO_H \ No newline at end of file diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/eval.c b/Projects/Android/jni/SupportLibs/gl4es/src/gl/eval.c new file mode 100644 index 0000000..424c443 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/eval.c @@ -0,0 +1,370 @@ +// TODO: glIsEnabled(), glGetMap() +// TODO: GL_AUTO_NORMAL + +#include "eval.h" + +#include "math/eval.h" +#include "wrap/gl4es.h" +#include "array.h" +#include "logs.h" +#include "matvec.h" + +static inline map_state_t **get_map_pointer(GLenum target) { + switch (target) { + case GL_MAP1_COLOR_4: return &glstate->map1.color4; + case GL_MAP1_INDEX: return &glstate->map1.index; + case GL_MAP1_TEXTURE_COORD_1: return &glstate->map1.texture1; + case GL_MAP1_TEXTURE_COORD_2: return &glstate->map1.texture2; + case GL_MAP1_TEXTURE_COORD_3: return &glstate->map1.texture3; + case GL_MAP1_TEXTURE_COORD_4: return &glstate->map1.texture4; + case GL_MAP1_VERTEX_3: return &glstate->map1.vertex3; + case GL_MAP1_VERTEX_4: return &glstate->map1.vertex4; + case GL_MAP2_COLOR_4: return &glstate->map2.color4; + case GL_MAP2_INDEX: return &glstate->map2.index; + case GL_MAP2_TEXTURE_COORD_1: return &glstate->map2.texture1; + case GL_MAP2_TEXTURE_COORD_2: return &glstate->map2.texture2; + case GL_MAP2_TEXTURE_COORD_3: return &glstate->map2.texture3; + case GL_MAP2_TEXTURE_COORD_4: return &glstate->map2.texture4; + case GL_MAP2_VERTEX_3: return &glstate->map2.vertex3; + case GL_MAP2_VERTEX_4: return &glstate->map2.vertex4; + default: + LOGE("libGL: unknown glMap target 0x%x\n", target); + } + return NULL; +} + +#define set_map_coords(n) \ + map->n._1 = n##1; \ + map->n._2 = n##2; \ + map->n.d = 1.0/(n##2 - n##1); \ + map->n.order = n##order; + +#define case_state(dims, magic, name) \ + case magic: { \ + map->width = get_map_width(magic); \ + map_statef_t *m = (map_statef_t *)glstate->map##dims.name; \ + if (m) { \ + free((void *)m->points); \ + free(m); \ + } \ + glstate->map##dims.name = (map_state_t *)map; \ + break; \ + } + +#define map_switch(dims) \ + switch (target) { \ + case_state(dims, GL_MAP##dims##_COLOR_4, color4); \ + case_state(dims, GL_MAP##dims##_INDEX, index); \ + case_state(dims, GL_MAP##dims##_NORMAL, normal); \ + case_state(dims, GL_MAP##dims##_TEXTURE_COORD_1, texture1); \ + case_state(dims, GL_MAP##dims##_TEXTURE_COORD_2, texture2); \ + case_state(dims, GL_MAP##dims##_TEXTURE_COORD_3, texture3); \ + case_state(dims, GL_MAP##dims##_TEXTURE_COORD_4, texture4); \ + case_state(dims, GL_MAP##dims##_VERTEX_3, vertex3); \ + case_state(dims, GL_MAP##dims##_VERTEX_4, vertex4); \ + } + +void gl4es_glMap1d(GLenum target, GLdouble u1, GLdouble u2, + GLint ustride, GLint uorder, const GLdouble *points) { + noerrorShim(); + map_statef_t *map = malloc(sizeof(map_statef_t)); + map->type = GL_FLOAT; map->dims = 1; + set_map_coords(u); + map_switch(1); + map->points = copy_eval_double1(target, ustride, uorder, points); +} + +void gl4es_glMap1f(GLenum target, GLfloat u1, GLfloat u2, + GLint ustride, GLint uorder, const GLfloat *points) { + noerrorShim(); + map_statef_t *map = malloc(sizeof(map_statef_t)); + map->type = GL_FLOAT; map->dims = 1; + set_map_coords(u); + map_switch(1); + map->points = copy_eval_float1(target, ustride, uorder, points); +} + +void gl4es_glMap2d(GLenum target, GLdouble u1, GLdouble u2, + GLint ustride, GLint uorder, GLdouble v1, GLdouble v2, + GLint vstride, GLint vorder, const GLdouble *points) { + noerrorShim(); + map_statef_t *map = malloc(sizeof(map_statef_t)); + map->type = GL_FLOAT; map->dims = 2; + set_map_coords(u); + set_map_coords(v); + map_switch(2); + map->points = copy_eval_double2(target, ustride, uorder, vstride, vorder, points); +} + +void gl4es_glMap2f(GLenum target, GLfloat u1, GLfloat u2, + GLint ustride, GLint uorder, GLfloat v1, GLfloat v2, + GLint vstride, GLint vorder, const GLfloat *points) { + noerrorShim(); + map_statef_t *map = malloc(sizeof(map_statef_t)); + map->type = GL_FLOAT; map->dims = 2; + set_map_coords(u); + set_map_coords(v); + map_switch(2); + map->points = copy_eval_float2(target, ustride, uorder, vstride, vorder, points);; +} + +#undef set_map_coords +#undef case_state +#undef map_switch + +#define p_map(d, name, func, code) \ + if (glstate->map##d.name && glstate->enable.map##d##_##name) { \ + map_state_t *_map = glstate->map##d.name; \ + if (_map->type == GL_DOUBLE) { \ + map_stated_t *map = (map_stated_t *)_map; \ + LOGE("double: not implemented\n"); \ + } else if (_map->type == GL_FLOAT) { \ + map_statef_t *map = (map_statef_t *)_map; \ + code \ + gl4es_##func##v(out); \ + } \ + } + +#define iter_maps(d, code) \ + p_map(d, color4, glColor4f, code); \ + p_map(d, index, glIndexf, code); \ + if(!glstate->enable.auto_normal) \ + p_map(d, normal, glNormal3f, code); \ + p_map(d, texture4, glTexCoord4f, code) \ + else \ + p_map(d, texture3, glTexCoord3f, code) \ + else \ + p_map(d, texture2, glTexCoord2f, code) \ + else \ + p_map(d, texture1, glTexCoord1f, code); \ + p_map(d, vertex4, glVertex4f, code) \ + else \ + p_map(d, vertex3, glVertex3f, code); + +void gl4es_glEvalCoord1f(GLfloat u) { + noerrorShim(); + GLfloat out[4]; \ + iter_maps(1, + GLfloat uu = (u - map->u._1) * map->u.d; + _math_horner_bezier_curve((GLfloat*)map->points, out, uu, map->width, map->u.order); + ) +} + +void gl4es_glEvalCoord2f(GLfloat u, GLfloat v) { + noerrorShim(); + GLfloat out[4]; \ + iter_maps(2, + GLfloat uu = (u - map->u._1) * map->u.d; + GLfloat vv = (v - map->v._1) * map->v.d; + if(glstate->enable.auto_normal && (map == (map_statef_t *)glstate->map2.vertex3 || map == (map_statef_t *)glstate->map2.vertex4)) { + GLfloat norm[3]; + GLfloat du[4]; + GLfloat dv[4]; + memset(out, 0, 3*sizeof(GLfloat)); out[3] = 1.0f; + _math_de_casteljau_surf((GLfloat*)map->points, out, du, dv, uu, vv, + map->width, map->u.order, map->v.order); + if(map->width == 4) { + du[0] = du[0]*out[3] - du[3]*out[0]; + du[1] = du[1]*out[3] - du[3]*out[1]; + du[2] = du[2]*out[3] - du[3]*out[2]; + dv[0] = dv[0]*out[3] - dv[3]*out[0]; + dv[1] = dv[1]*out[3] - dv[3]*out[1]; + dv[2] = dv[2]*out[3] - dv[3]*out[2]; + } + cross3(du, dv, norm); + vector_normalize(norm); + gl4es_glNormal3fv(norm); + } else + _math_horner_bezier_surf((GLfloat*)map->points, out, uu, vv, + map->width, map->u.order, map->v.order); + ) +} + +#undef p_map +#undef iter_maps + +void gl4es_glMapGrid1f(GLint un, GLfloat u1, GLfloat u2) { + if(un<1) { + errorShim(GL_INVALID_VALUE); + return; + } + if(glstate->list.begin) { + errorShim(GL_INVALID_OPERATION); + return; + } + + noerrorShim(); + + glstate->map_grid[0].n = un; + glstate->map_grid[0]._1 = u1; + glstate->map_grid[0]._2 = u2; +} + +void gl4es_glMapGrid2f(GLint un, GLfloat u1, GLfloat u2, + GLint vn, GLfloat v1, GLfloat v2) { + + if((un<1) || (vn<1)) { + errorShim(GL_INVALID_VALUE); + return; + } + if(glstate->list.begin) { + errorShim(GL_INVALID_OPERATION); + return; + } + + noerrorShim(); + + glstate->map_grid[0].n = un; + glstate->map_grid[0]._1 = u1; + glstate->map_grid[0]._2 = u2; + glstate->map_grid[0].d = (glstate->map_grid[0]._2 - glstate->map_grid[0]._1)/glstate->map_grid[0].n; + glstate->map_grid[1].n = vn; + glstate->map_grid[1]._1 = v1; + glstate->map_grid[1]._2 = v2; + glstate->map_grid[1].d = (glstate->map_grid[1]._2 - glstate->map_grid[1]._1)/glstate->map_grid[1].n; +} + +static inline GLenum eval_mesh_prep(GLenum mode) { + if ((!glstate->map2.vertex4) && (!glstate->map2.vertex3)) { + return 0; + } + + switch (mode) { + case GL_POINT: return GL_POINTS; + case GL_LINE: return GL_LINE_STRIP; + case GL_FILL: return GL_TRIANGLE_STRIP; + case 0: return 1; + default: + LOGE("unknown glEvalMesh mode: %x\n", mode); + return 0; + } +} + +void gl4es_glEvalMesh1(GLenum mode, GLint i1, GLint i2) { + GLenum renderMode = eval_mesh_prep(mode); + if (! renderMode) { + errorShim(GL_INVALID_ENUM); + return; + } + + noerrorShim(); + GLfloat u, du, u1; + du = glstate->map_grid[0].d; + u1 = glstate->map_grid[0]._1 + du*i1; + GLint i; + gl4es_glBegin(renderMode); + for (u = u1, i = i1; i <= i2; i++, u += du) { + gl4es_glEvalCoord1f(u); + } + gl4es_glEnd(); +} + +void gl4es_glEvalMesh2(GLenum mode, GLint i1, GLint i2, GLint j1, GLint j2) { + GLenum renderMode = eval_mesh_prep(mode); + if (! renderMode) { + errorShim(GL_INVALID_ENUM); + return; + } + + noerrorShim(); + GLfloat u, du, u1, v, dv, v1; + du = glstate->map_grid[0].d; + dv = glstate->map_grid[1].d; + u1 = glstate->map_grid[0]._1 + du*i1; + v1 = glstate->map_grid[1]._1 + dv*j1; + GLint i, j; + if(mode==GL_FILL) { + for (v = v1, j = j1; j <= j2-1; j++, v += dv) { + gl4es_glBegin(renderMode); + for (u = u1, i = i1; i <= i2; i++, u += du) { + gl4es_glEvalCoord2f(u, v); + gl4es_glEvalCoord2f(u, v + dv); + } + gl4es_glEnd(); + } + } else { + for (v = v1, j = j1; j <= j2; j++, v += dv) { + gl4es_glBegin(renderMode); + for (u = u1, i = i1; i <= i2; i++, u += du) { + gl4es_glEvalCoord2f(u, v); + } + gl4es_glEnd(); + } + if (mode == GL_LINE) { + gl4es_glBegin(renderMode); + for (u = u1, i = i1; i <= i2; i++, u += du) { + for (v = v1, j = j1; j <= j2; j++, v += dv) { + gl4es_glEvalCoord2f(u, v); + } + } + gl4es_glEnd(); + } + } +} + +void gl4es_glEvalPoint1(GLint i) { + gl4es_glEvalCoord1f(glstate->map_grid[0]._1 + glstate->map_grid[0].d*i); +} + +void gl4es_glEvalPoint2(GLint i, GLint j) { + gl4es_glEvalCoord2f(glstate->map_grid[0]._1 + glstate->map_grid[0].d*i, glstate->map_grid[1]._1 + glstate->map_grid[1].d*j); +} + +#define GL_GET_MAP(t, type) \ +void gl4es_glGetMap##t##v(GLenum target, GLenum query, type *v) { \ + noerrorShim(); \ + map_statef_t *map = *(map_statef_t **)get_map_pointer(target); \ + if (map) { \ + switch (query) { \ + case GL_COEFF: { \ + const GLfloat *points = map->points; \ + for (int i = 0; i < map->u.order; i++) { \ + if (map->dims == 2) { \ + for (int j = 0; j < map->v.order; j++) { \ + *v++ = *points++; \ + } \ + } else { \ + *v++ = *points++; \ + } \ + } \ + return; \ + } \ + case GL_ORDER: \ + *v++ = map->u.order; \ + if (map->dims == 2) \ + *v++ = map->v.order; \ + return; \ + case GL_DOMAIN: \ + *v++ = map->u._1; \ + *v++ = map->u._2; \ + if (map->dims == 2) { \ + *v++ = map->u._1; \ + *v++ = map->u._2; \ + } \ + return; \ + } \ + } \ +} + +GL_GET_MAP(i, GLint) +GL_GET_MAP(f, GLfloat) +GL_GET_MAP(d, GLdouble) + +#undef GL_GET_MAP + +//Direct wrapper +void glMap1d(GLenum target, GLdouble u1, GLdouble u2, GLint stride, GLint order, const GLdouble *points) AliasExport("gl4es_glMap1d"); +void glMap1f(GLenum target, GLfloat u1, GLfloat u2, GLint stride, GLint order, const GLfloat *points) AliasExport("gl4es_glMap1f"); +void glMap2d(GLenum target, GLdouble u1, GLdouble u2, GLint ustride, GLint uorder, GLdouble v1, GLdouble v2, GLint vstride, GLint vorder, const GLdouble *points) AliasExport("gl4es_glMap2d"); +void glMap2f(GLenum target, GLfloat u1, GLfloat u2, GLint ustride, GLint uorder, GLfloat v1, GLfloat v2, GLint vstride, GLint vorder, const GLfloat *points) AliasExport("gl4es_glMap2f"); +void glEvalCoord1f(GLfloat u) AliasExport("gl4es_glEvalCoord1f"); +void glEvalCoord2f(GLfloat u, GLfloat v) AliasExport("gl4es_glEvalCoord2f"); +void glEvalMesh1(GLenum mode, GLint i1, GLint i2) AliasExport("gl4es_glEvalMesh1"); +void glEvalMesh2(GLenum mode, GLint i1, GLint i2, GLint j1, GLint j2) AliasExport("gl4es_glEvalMesh2"); +void glEvalPoint1(GLint i) AliasExport("gl4es_glEvalPoint1"); +void glEvalPoint2(GLint i, GLint j) AliasExport("gl4es_glEvalPoint2"); +void glMapGrid1f(GLint un, GLfloat u1, GLfloat u2) AliasExport("gl4es_glMapGrid1f"); +void glMapGrid2f(GLint un, GLfloat u1, GLfloat u2, GLint vn, GLfloat v1, GLfloat v2) AliasExport("gl4es_glMapGrid2f"); +void glGetMapdv(GLenum target, GLenum query, GLdouble *v) AliasExport("gl4es_glGetMapdv"); +void glGetMapfv(GLenum target, GLenum query, GLfloat *v) AliasExport("gl4es_glGetMapfv"); +void glGetMapiv(GLenum target, GLenum query, GLint *v) AliasExport("gl4es_glGetMapiv"); diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/eval.h b/Projects/Android/jni/SupportLibs/gl4es/src/gl/eval.h new file mode 100644 index 0000000..c928434 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/eval.h @@ -0,0 +1,87 @@ +#ifndef _GL4ES_EVAL_H_ +#define _GL4ES_EVAL_H_ + +#include "const.h" +#include "gles.h" + +void gl4es_glMap1d(GLenum target, GLdouble u1, GLdouble u2, GLint stride, GLint order, const GLdouble *points); +void gl4es_glMap1f(GLenum target, GLfloat u1, GLfloat u2, GLint stride, GLint order, const GLfloat *points); +void gl4es_glMap2d(GLenum target, GLdouble u1, GLdouble u2, GLint ustride, GLint uorder, GLdouble v1, GLdouble v2, GLint vstride, GLint vorder, const GLdouble *points); +void gl4es_glMap2f(GLenum target, GLfloat u1, GLfloat u2, GLint ustride, GLint uorder, GLfloat v1, GLfloat v2, GLint vstride, GLint vorder, const GLfloat *points); + +void gl4es_glEvalCoord1d(GLdouble u); +void gl4es_glEvalCoord1f(GLfloat u); +void gl4es_glEvalCoord2d(GLdouble u, GLdouble v); +void gl4es_glEvalCoord2f(GLfloat u, GLfloat v); + +void gl4es_glEvalMesh1(GLenum mode, GLint i1, GLint i2); +void gl4es_glEvalMesh2(GLenum mode, GLint i1, GLint i2, GLint j1, GLint j2); +void gl4es_glEvalPoint1(GLint i); +void gl4es_glEvalPoint2(GLint i, GLint j); +void gl4es_glMapGrid1d(GLint un, GLdouble u1, GLdouble u2); +void gl4es_glMapGrid1f(GLint un, GLfloat u1, GLfloat u2); +void gl4es_glMapGrid2d(GLint un, GLdouble u1, GLdouble u2, GLint vn, GLdouble v1, GLdouble v2); +void gl4es_glMapGrid2f(GLint un, GLfloat u1, GLfloat u2, GLint vn, GLfloat v1, GLfloat v2); +void gl4es_glGetMapdv(GLenum target, GLenum query, GLdouble *v); +void gl4es_glGetMapfv(GLenum target, GLenum query, GLfloat *v); +void gl4es_glGetMapiv(GLenum target, GLenum query, GLint *v); + +typedef struct { + GLenum type; +} map_state_t; + +typedef struct { + GLdouble _1, _2, d; + GLint order; +} mapcoordd_t; + +typedef struct { + GLfloat _1, _2, d; + GLint order; +} mapcoordf_t; + +typedef struct { + GLenum type; + GLint dims, width; + mapcoordd_t u, v; + const GLdouble *points; +} map_stated_t; + +typedef struct { + GLenum type; + GLint dims, width; + mapcoordf_t u, v; + const GLfloat *points; +} map_statef_t; + +typedef struct { + GLfloat _1, _2; + GLfloat d; + GLint n; +} map_grid_t; + +static const GLsizei get_map_width(GLenum target) { + switch (target) { + case GL_MAP1_COLOR_4: return 4; + case GL_MAP1_INDEX: return 3; + case GL_MAP1_NORMAL: return 3; + case GL_MAP1_TEXTURE_COORD_1: return 1; + case GL_MAP1_TEXTURE_COORD_2: return 2; + case GL_MAP1_TEXTURE_COORD_3: return 3; + case GL_MAP1_TEXTURE_COORD_4: return 4; + case GL_MAP1_VERTEX_3: return 3; + case GL_MAP1_VERTEX_4: return 4; + case GL_MAP2_COLOR_4: return 4; + case GL_MAP2_INDEX: return 3; + case GL_MAP2_NORMAL: return 3; + case GL_MAP2_TEXTURE_COORD_1: return 1; + case GL_MAP2_TEXTURE_COORD_2: return 2; + case GL_MAP2_TEXTURE_COORD_3: return 3; + case GL_MAP2_TEXTURE_COORD_4: return 4; + case GL_MAP2_VERTEX_3: return 3; + case GL_MAP2_VERTEX_4: return 4; + } + return 0; +} + +#endif // _GL4ES_EVAL_H_ diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/face.c b/Projects/Android/jni/SupportLibs/gl4es/src/gl/face.c new file mode 100644 index 0000000..98c51f3 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/face.c @@ -0,0 +1,47 @@ +#include "face.h" + +#include "loader.h" +#include "gl4es.h" +#include "glstate.h" + +void gl4es_glCullFace(GLenum mode) { + if(!glstate->list.pending) + PUSH_IF_COMPILING(glCullFace); + if(mode!=GL_FRONT && mode!=GL_BACK && mode!=GL_FRONT_AND_BACK) { + errorShim(GL_INVALID_ENUM); + return; + } + if(glstate->face.cull == mode) { + noerrorShim(); + return; + } + if(glstate->list.pending) + flush(); + + glstate->face.cull = mode; + LOAD_GLES(glCullFace); + gles_glCullFace(mode); +} + +void gl4es_glFrontFace(GLenum mode) { + if(!glstate->list.pending) + PUSH_IF_COMPILING(glFrontFace); + if(mode!=GL_CW && mode!=GL_CCW) { + errorShim(GL_INVALID_ENUM); + return; + } + if(glstate->face.front == mode) { + noerrorShim(); + return; + } + if(glstate->list.pending) + flush(); + + glstate->face.front = mode; + LOAD_GLES(glFrontFace); + gles_glFrontFace(mode); +} + + +void glCullFace(GLenum mode) AliasExport("gl4es_glCullFace"); +void glFrontFace(GLenum mode) AliasExport("gl4es_glFrontFace"); diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/face.h b/Projects/Android/jni/SupportLibs/gl4es/src/gl/face.h new file mode 100644 index 0000000..62c6bc9 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/face.h @@ -0,0 +1,9 @@ +#ifndef _GL4ES_FACE_H_ +#define _GL4ES_FACE_H_ + +#include "gles.h" + +void gl4es_glCullFace(GLenum mode); +void gl4es_glFrontFace(GLenum mode); + +#endif // _GL4ES_FACE_H_ diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/fog.c b/Projects/Android/jni/SupportLibs/gl4es/src/gl/fog.c new file mode 100644 index 0000000..ca18fe5 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/fog.c @@ -0,0 +1,111 @@ +#include "fog.h" + +#include "../glx/hardext.h" +#include "fpe.h" +#include "gl4es.h" +#include "glstate.h" +#include "loader.h" +#include "matrix.h" +#include "matvec.h" + +void gl4es_glFogfv(GLenum pname, const GLfloat* params) { + + if (glstate->list.active) + if (glstate->list.compiling) { + NewStage(glstate->list.active, STAGE_FOG); + rlFogOp(glstate->list.active, pname, params); + return; + } + else flush(); + noerrorShim(); + #define GO(A,name, size) if(memcmp(A glstate->fog.name, params, size)==0) return; else memcpy(A glstate->fog.name, params, size); + switch (pname) { + case GL_FOG_MODE: + GO(&, mode, sizeof(GLfloat)) + break; + case GL_FOG_DENSITY: + if(*params<0.f) { + errorShim(GL_INVALID_VALUE); + return; + } + GO(&, density, sizeof(GLfloat)) + break; + case GL_FOG_START: + GO(&, start, sizeof(GLfloat)) + break; + case GL_FOG_END: + GO(&, end, sizeof(GLfloat)) + break; + case GL_FOG_INDEX: + GO(&, index, sizeof(GLfloat)) + return; // unsupported for now + case GL_FOG_COLOR: +#if defined(__GNUC__) && (__GNUC__ > 7) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wstringop-overflow" +#endif + // GCC 8.1 warn about reading 16 bytes from a 4 bytes value, but params is not (in that case) a 4 bytes value + GO(, color, 4*sizeof(GLfloat)) +#if defined(__GNUC__) && (__GNUC__ > 7) +#pragma GCC diagnostic pop +#endif + break; + case GL_FOG_COORD_SRC: + GO(&, coord_src, sizeof(GLfloat)) + if(hardext.esversion==1) + return; // unsupported on GLES1.1 + break; + default: + errorShim(GL_INVALID_ENUM); + return; + } + #undef GO + LOAD_GLES_FPE(glFogfv); + gles_glFogfv(pname, params); + errorGL(); +} + +void gl4es_glFogf(GLenum pname, GLfloat param) { + gl4es_glFogfv(pname, ¶m); +} + +void gl4es_glFogCoordd(GLdouble coord) { + gl4es_glFogCoordf(coord); +} +void gl4es_glFogCoorddv(const GLdouble *coord) { + gl4es_glFogCoordf(*coord); +} +void gl4es_glFogCoordfv(const GLfloat *coord) { + gl4es_glFogCoordf(*coord); +} +void gl4es_glFogCoordf(GLfloat coord) { + if (glstate->list.active) { + if(glstate->list.pending) + flush(); + else + { + rlFogCoordf(glstate->list.active, coord); + glstate->list.active->lastFogCoord = coord; + } + noerrorShim(); + } else { + noerrorShim(); + } + // change the state last thing + glstate->fogcoord = coord; +} + + +void glFogfv(GLenum pname, const GLfloat* params) AliasExport("gl4es_glFogfv"); +void glFogf(GLenum pname, GLfloat param) AliasExport("gl4es_glFogf"); +void glFogCoordd(GLdouble coord) AliasExport("gl4es_glFogCoordd"); +void glFogCoorddv(const GLdouble *coord) AliasExport("gl4es_glFogCoorddv"); +void glFogCoordf(GLfloat coord) AliasExport("gl4es_glFogCoordf"); +void glFogCoordfv(const GLfloat *coord) AliasExport("gl4es_glFogCoordfv"); + +void glFogfvEXT(GLenum pname, const GLfloat* params) AliasExport("gl4es_glFogfv"); +void glFogfEXT(GLenum pname, GLfloat param) AliasExport("gl4es_glFogf"); +void glFogCoorddEXT(GLdouble coord) AliasExport("gl4es_glFogCoordd"); +void glFogCoorddvEXT(const GLdouble *coord) AliasExport("gl4es_glFogCoorddv"); +void glFogCoordfEXT(GLfloat coord) AliasExport("gl4es_glFogCoordf"); +void glFogCoordfvEXT(const GLfloat *coord) AliasExport("gl4es_glFogCoordfv"); \ No newline at end of file diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/fog.h b/Projects/Android/jni/SupportLibs/gl4es/src/gl/fog.h new file mode 100644 index 0000000..090e7f6 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/fog.h @@ -0,0 +1,22 @@ +#ifndef _GL4ES_FOG_H_ +#define _GL4ES_FOG_H_ + +#include "gles.h" + +typedef struct { + GLenum mode; + GLfloat density; + GLfloat start; + GLfloat end; + GLfloat index; + GLfloat color[4]; + GLenum coord_src; +} fog_t; + +void gl4es_glFogfv(GLenum pname, const GLfloat* params); +void gl4es_glFogf(GLenum pname, GLfloat param); + +void gl4es_glFogCoordf(GLfloat coord); +void gl4es_glFogCoordfv(const GLfloat *coord); + +#endif // _GL4ES_FOG_H_ diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/fpe.c b/Projects/Android/jni/SupportLibs/gl4es/src/gl/fpe.c new file mode 100644 index 0000000..d51eeea --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/fpe.c @@ -0,0 +1,1646 @@ +#include "fpe.h" + +#include "../glx/hardext.h" +#include "array.h" +#include "debug.h" +#include "enum_info.h" +#include "fpe_shader.h" +#include "glcase.h" +#include "init.h" +#include "loader.h" +#include "matrix.h" +#include "matvec.h" +#include "program.h" +#include "shaderconv.h" + +//#define DEBUG +#ifdef DEBUG +#pragma GCC optimize 0 +#define DBG(a) a +#else +#define DBG(a) +#endif + +KHASH_MAP_IMPL_INT(fpecachelist, fpe_cache_t *); + + +// ********* Cache handling ********* + +fpe_cache_t* fpe_NewCache() { + fpe_cache_t *ret = (fpe_cache_t*)malloc(sizeof(fpe_cache_t)); + khash_t(fpecachelist) *cache = kh_init(fpecachelist); + ret->cache = cache; + int r; + kh_put(fpecachelist, cache, 1, &r); + kh_del(fpecachelist, cache, 1); + ret->fpe = (fpe_fpe_t*)malloc(sizeof(fpe_fpe_t)); + memset(ret->fpe, 0, sizeof(fpe_fpe_t)); + return ret; +} + +void fpe_Init(glstate_t *glstate) { + // initialize cache + glstate->fpe_cache = fpe_NewCache(); +} + +void fpe_disposeCache(fpe_cache_t* cache, int freeprog) { + if(!cache) return; + if(cache->fpe) { + if(freeprog) { + if(cache->fpe->glprogram) + gl4es_glDeleteProgram(cache->fpe->glprogram->id); + } + free(cache->fpe); + cache->fpe = NULL; + } + if(cache->cache) { + fpe_cache_t *m; + kh_foreach_value((khash_t(fpecachelist)*)cache->cache, m, + fpe_disposeCache(m, freeprog); free(m); + ) + kh_destroy(fpecachelist, cache->cache); + cache->cache = NULL; + } +} + +void fpe_Dispose(glstate_t *glstate) { + fpe_disposeCache(glstate->fpe_cache, 0); + free(glstate->fpe_cache); + glstate->fpe_cache = NULL; +} + +void fpe_ReleventState(fpe_state_t *dest, fpe_state_t *src, int fixed) +{ + // filter out some non relevent state (like texture stuff if texture is disabled) + memcpy(dest, src, sizeof(fpe_state_t)); + // alpha test + if(!dest->alphatest) { + dest->alphafunc = FPE_ALWAYS; + } + // lighting + if(!fixed || !dest->lighting) { + dest->light = 0; + dest->light_cutoff180 = 0; + dest->light_direction = 0; + dest->twosided = 0; + dest->color_material = 0; + dest->cm_front_mode = 0; + dest->cm_back_mode = 0; + dest->cm_front_nullexp = 0; + dest->cm_back_nullexp = 0; + dest->light_separate = 0; + dest->light_localviewer = 0; + } else { + // indiviual lights + for (int i=0; i<8; i++) { + if(((dest->light>>i)&1)==0) { + dest->light_cutoff180 &= ~(1<light_direction &= ~(1<textype) { + dest->textmat = 0; + dest->texenv = 0; + memset(dest->texcombine, 0, sizeof(dest->texcombine)); + memset(dest->texsrcrgb, 0, sizeof(dest->texsrcrgb)); + memset(dest->texsrcalpha, 0, sizeof(dest->texsrcalpha)); + memset(dest->texoprgb, 0, sizeof(dest->texoprgb)); + memset(dest->texopalpha, 0, sizeof(dest->texopalpha)); + dest->texgen_s = 0; + dest->texgen_s_mode = 0; + dest->texgen_t = 0; + dest->texgen_t_mode = 0; + dest->texgen_r = 0; + dest->texgen_r_mode = 0; + dest->texgen_q = 0; + dest->texgen_q_mode = 0; + dest->texformat = 0; + dest->texadjust = 0; + } else { + // individual textures + for (int i=0; i<8; i++) { + if(((dest->textype>>(i*3))&7)==0) { // texture is off + dest->textmat &= ~(1<texformat &= ~(7<<(i*3)); + dest->texadjust &= ~(1<texgen_s &= ~(1<texgen_s_mode &= ~(7<<(i*3)); + dest->texgen_t &= ~(1<texgen_t_mode &= ~(7<<(i*3)); + dest->texgen_r &= ~(1<texgen_r_mode &= ~(7<<(i*3)); + dest->texgen_q &= ~(1<texgen_q_mode &= ~(7<<(i*3)); + } else { // texture is on + if ((dest->texgen_s&(1<texgen_s_mode &= ~(7<<(i*3)); + if ((dest->texgen_t&(1<texgen_t_mode &= ~(7<<(i*3)); + if ((dest->texgen_r&(1<texgen_r_mode &= ~(7<<(i*3)); + if ((dest->texgen_q&(1<texgen_q_mode &= ~(7<<(i*3)); + } + if((((dest->texenv>>(i*3))&7) < FPE_COMBINE) || ((dest->textype>>(i*3)&7)==0)) { + dest->texcombine[i] = 0; + for (int j=0; j<3; j++) { + dest->texsrcrgb[j] &= ~(0xf<<(i*4)); + dest->texsrcalpha[j] &= ~(0xf<<(i*4)); + dest->texoprgb[j] &= ~(0x3<<(i*2)); + dest->texopalpha[j] &= ~(0x1<texenv>>(i*3))&7) != FPE_COMBINE4) { + dest->texsrcrgb[3] &= ~(0xf<<(i*4)); + dest->texsrcalpha[3] &= ~(0xf<<(i*4)); + dest->texoprgb[3] &= ~(0x3<<(i*2)); + dest->texopalpha[3] &= ~(0x1<fog) { + dest->fogmode = 0; + dest->fogsource = 0; + } + if(!fixed || !dest->point) + dest->pointsprite = 0; + if(!fixed || !dest->pointsprite) { + dest->pointsprite_upper = 0; + dest->pointsprite_coord = 0; + } + if(!fixed) { + dest->textmat = 0; + dest->texadjust = 0; + dest->plane = 0; // Should handled this? + dest->colorsum = 0; + dest->normalize = 0; + dest->rescaling = 0; + + dest->lighting = 0; + dest->textype = 0; + dest->fog = 0; + dest->point = 0; + } +} + +fpe_fpe_t *fpe_GetCache(fpe_cache_t *cur, fpe_state_t *state, int fixed) { + // multi stage hash search + uint32_t t; + intptr_t s,p; + s=0; + while(ssizeof(fpe_state_t)) + p = sizeof(fpe_state_t) - s; + memcpy(&t, ((void*)state)+s, p); + s+=p; + fpe_cache_t *next = NULL; + khint_t k_next; + { + int ret; + khash_t(fpecachelist) *curcache = (khash_t(fpecachelist) *)cur->cache; + k_next = kh_get(fpecachelist, curcache, t); + if (k_next != kh_end(curcache)) + cur = kh_value(curcache, k_next); + else { + k_next = kh_put(fpecachelist, curcache, t, &ret); + cur = kh_value(curcache, k_next) = fpe_NewCache(); + } + } + } + // save current state + memcpy(&cur->fpe->state, state, sizeof(fpe_state_t)); + return cur->fpe; +} + +int fpe_IsEmpty(fpe_state_t *state) { + uint32_t t; + intptr_t s,p; + s=0; + while(ssizeof(fpe_state_t)) + p = sizeof(fpe_state_t) - s; + memcpy(&t, ((void*)state)+s, p); + s+=p; + if(t) return 0; + } + return 1; +} + +uniform_t* findUniform(khash_t(uniformlist) *uniforms, const char* name) +{ + uniform_t *m; + khint_t k; + kh_foreach(uniforms, k, m, + if(!strcmp(m->name, name)) + return m; + ) + return NULL; + +} + +// ********* Shader stuffs handling ********* +void fpe_program(int ispoint) { + glstate->fpe_state->point = ispoint; + fpe_state_t state; + fpe_ReleventState(&state, glstate->fpe_state, 1); + if(glstate->fpe==NULL || memcmp(&glstate->fpe->state, &state, sizeof(fpe_state_t))) { + // get cached fpe (or new one) + glstate->fpe = fpe_GetCache(glstate->fpe_cache, &state, 1); + } + if(glstate->fpe->glprogram==NULL) { + LOAD_GLES2(glGetShaderInfoLog); + LOAD_GLES2(glGetProgramInfoLog); + GLint status; + glstate->fpe->vert = gl4es_glCreateShader(GL_VERTEX_SHADER); + gl4es_glShaderSource(glstate->fpe->vert, 1, fpe_VertexShader(glstate->fpe_state), NULL); + gl4es_glCompileShader(glstate->fpe->vert); + gl4es_glGetShaderiv(glstate->fpe->vert, GL_COMPILE_STATUS, &status); + if(status!=GL_TRUE) { + char buff[1000]; + gles_glGetShaderInfoLog(glstate->fpe->vert, 1000, NULL, buff); + if(globals4es.logshader) + printf("LIBGL: FPE Vertex shader compile failed: source is\n%s\n\nError is: %s\n", fpe_VertexShader(glstate->fpe_state)[0], buff); + else + printf("LIBGL: FPE Vertex shader compile failed: %s\n", buff); + } + glstate->fpe->frag = gl4es_glCreateShader(GL_FRAGMENT_SHADER); + gl4es_glShaderSource(glstate->fpe->frag, 1, fpe_FragmentShader(glstate->fpe_state), NULL); + gl4es_glCompileShader(glstate->fpe->frag); + gl4es_glGetShaderiv(glstate->fpe->frag, GL_COMPILE_STATUS, &status); + if(status!=GL_TRUE) { + char buff[1000]; + gles_glGetShaderInfoLog(glstate->fpe->frag, 1000, NULL, buff); + if(globals4es.logshader) + printf("LIBGL: FPE Fragment shader compile failed: source is\n%s\n\nError is: %s\n", fpe_FragmentShader(glstate->fpe_state)[0], buff); + else + printf("LIBGL: FPE Fragment shader compile failed: %s\n", buff); + } + glstate->fpe->prog = gl4es_glCreateProgram(); + gl4es_glAttachShader(glstate->fpe->prog, glstate->fpe->vert); + gl4es_glAttachShader(glstate->fpe->prog, glstate->fpe->frag); + gl4es_glLinkProgram(glstate->fpe->prog); + gl4es_glGetProgramiv(glstate->fpe->prog, GL_LINK_STATUS, &status); + if(status!=GL_TRUE) { + char buff[1000]; + gles_glGetProgramInfoLog(glstate->fpe->prog, 1000, NULL, buff); + if(globals4es.logshader) { + printf("LIBGL: FPE Program link failed: source of vertex shader is\n%s\n\n", fpe_VertexShader(glstate->fpe_state)[0]); + printf("source of fragment shader is \n%s\n\nError is: %s\n", fpe_FragmentShader(glstate->fpe_state)[0], buff); + } else + printf("LIBGL: FPE Program link failed: %s\n", buff); + } + // now find the program + khint_t k_program; + { + int ret; + khash_t(programlist) *programs = glstate->glsl->programs; + k_program = kh_get(programlist, programs, glstate->fpe->prog); + if (k_program != kh_end(programs)) + glstate->fpe->glprogram = kh_value(programs, k_program); + } + // all done + DBG(printf("creating FPE shader : %d(%p)\n", glstate->fpe->prog, glstate->fpe->glprogram);) + } +} + +program_t* fpe_CustomShader(program_t* glprogram, fpe_state_t* state) +{ + // state is not empty and glprogram already has some cache (it may be empty, but kh'thingy is initialized) + // TODO: what if program is composed of more then 1 vertex or fragment shader? + fpe_fpe_t *fpe = fpe_GetCache((fpe_cache_t*)glprogram->fpe_cache, state, 0); + if(fpe->glprogram==NULL) { + GLint status; + fpe->vert = gl4es_glCreateShader(GL_VERTEX_SHADER); + gl4es_glShaderSource(fpe->vert, 1, fpe_CustomVertexShader(glprogram->last_vert->converted, state), NULL); + gl4es_glCompileShader(fpe->vert); + gl4es_glGetShaderiv(fpe->vert, GL_COMPILE_STATUS, &status); + if(status!=GL_TRUE) { + char buff[1000]; + gl4es_glGetShaderInfoLog(fpe->vert, 1000, NULL, buff); + printf("LIBGL: FPE Custom Vertex shader compile failed: %s\n", buff); + return glprogram; // fallback to non-customized custom program.. + } + fpe->frag = gl4es_glCreateShader(GL_FRAGMENT_SHADER); + gl4es_glShaderSource(fpe->frag, 1, fpe_CustomFragmentShader(glprogram->last_frag->converted, state), NULL); + gl4es_glCompileShader(fpe->frag); + gl4es_glGetShaderiv(fpe->frag, GL_COMPILE_STATUS, &status); + if(status!=GL_TRUE) { + char buff[1000]; + gl4es_glGetShaderInfoLog(fpe->frag, 1000, NULL, buff); + printf("LIBGL: FPE Custom Fragment shader compile failed: %s\n", buff); + return glprogram; // fallback to non-customized custom program.. + } + fpe->prog = gl4es_glCreateProgram(); + gl4es_glAttachShader(fpe->prog, fpe->vert); + gl4es_glAttachShader(fpe->prog, fpe->frag); + // re-run the BindAttribLocation if any + { + attribloc_t *al; + LOAD_GLES2(glBindAttribLocation); // using real one to avoid overwriting of attribloc... + kh_foreach_value(glprogram->attribloc, al, + gles_glBindAttribLocation(fpe->prog, al->index, al->name); + ); + } + gl4es_glLinkProgram(fpe->prog); + gl4es_glGetProgramiv(fpe->prog, GL_LINK_STATUS, &status); + if(status!=GL_TRUE) { + char buff[1000]; + gl4es_glGetProgramInfoLog(fpe->prog, 1000, NULL, buff); + printf("LIBGL: FPE Custom Program link failed: %s\n", buff); + return glprogram; // fallback to non-customized custom program.. + } + // now find the program + khint_t k_program; + { + int ret; + khash_t(programlist) *programs = glstate->glsl->programs; + k_program = kh_get(programlist, programs, fpe->prog); + if (k_program != kh_end(programs)) + fpe->glprogram = kh_value(programs, k_program); + } + // adjust the uniforms to point to father cache... + { + khash_t(uniformlist) *father_uniforms = glprogram->uniform; + khash_t(uniformlist) *uniforms = fpe->glprogram->uniform; + uniform_t *m, *n; + khint_t k; + kh_foreach(uniforms, k, m, + if(!m->builtin) { + n = findUniform(father_uniforms, m->name); + if(n) { + m->parent_offs = n->cache_offs; + m->parent_size = n->cache_size; + } + } + ) + } + // all done + DBG(printf("creating FPE Custom Program : %d(%p)\n", fpe->prog, fpe->glprogram);) + } + + return fpe->glprogram; +} + +void fpe_SyncUniforms(uniformcache_t *cache, program_t* glprogram) { + //TODO: Optimize this... + khash_t(uniformlist) *uniforms = glprogram->uniform; + uniform_t *m; + khint_t k; + DBG(int cnt = 0;) + // don't use m->size, as each element has it's own uniform... + kh_foreach(uniforms, k, m, + if(m->parent_size) { + DBG(++cnt;) + switch(m->type) { + case GL_FLOAT: + case GL_FLOAT_VEC2: + case GL_FLOAT_VEC3: + case GL_FLOAT_VEC4: + GoUniformfv(glprogram, m->id, n_uniform(m->type), 1, (GLfloat*)((uintptr_t)cache->cache+m->parent_offs)); + break; + case GL_SAMPLER_2D: + case GL_SAMPLER_CUBE: + case GL_INT: + case GL_INT_VEC2: + case GL_INT_VEC3: + case GL_INT_VEC4: + case GL_BOOL: + case GL_BOOL_VEC2: + case GL_BOOL_VEC3: + case GL_BOOL_VEC4: + GoUniformiv(glprogram, m->id, n_uniform(m->type), 1, (GLint*)((uintptr_t)cache->cache+m->parent_offs)); + break; + case GL_FLOAT_MAT2: + GoUniformMatrix2fv(glprogram, m->id, 1, false, (GLfloat*)((uintptr_t)cache->cache+m->parent_offs)); + break; + case GL_FLOAT_MAT3: + GoUniformMatrix3fv(glprogram, m->id, 1, false, (GLfloat*)((uintptr_t)cache->cache+m->parent_offs)); + break; + case GL_FLOAT_MAT4: + GoUniformMatrix4fv(glprogram, m->id, 1, false, (GLfloat*)((uintptr_t)cache->cache+m->parent_offs)); + break; + default: + printf("LIBGL: Warning, sync uniform on father/son program with unknown uniform type %s\n", PrintEnum(m->type)); + } + } + ); + DBG(printf("Uniform sync'd with %d and father (%d uniforms)\n", glprogram->id, cnt);) +} +// ********* Fixed Pipeling function wrapper ********* + +void fpe_glClientActiveTexture(GLenum texture) { + DBG(printf("fpe_glClientActiveTexture(%s)\n", PrintEnum(texture));) +} + +void fpe_EnableDisableClientState(GLenum cap, GLboolean val) { + switch(cap) { + case GL_VERTEX_ARRAY: + glstate->fpe_client.vertex_array = val; + break; + case GL_COLOR_ARRAY: + glstate->fpe_client.color_array = val; + break; + case GL_NORMAL_ARRAY: + glstate->fpe_client.normal_array = val; + break; + case GL_TEXTURE_COORD_ARRAY: + glstate->fpe_client.tex_coord_array[glstate->texture.client] = val; + break; + case GL_SECONDARY_COLOR_ARRAY: + glstate->fpe_client.secondary_array = val; + break; + case GL_FOG_COORD_ARRAY: + glstate->fpe_client.fog_array = val; + break; + } +} + +void fpe_glEnableClientState(GLenum cap) { + DBG(printf("fpe_glEnableClientState(%s)\n", PrintEnum(cap));) + fpe_EnableDisableClientState(cap, GL_TRUE); +} + +void fpe_glDisableClientState(GLenum cap) { + DBG(printf("fpe_glDisableClientState(%s)\n", PrintEnum(cap));) + fpe_EnableDisableClientState(cap, GL_FALSE); +} + +void fpe_glMultiTexCoord4f(GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q) { +} + +void fpe_glSecondaryColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer) { + DBG(printf("fpe_glSecondaryColorPointer(%d, %s, %d, %p)\n", size, PrintEnum(type), stride, pointer);) + glstate->fpe_client.secondary.size = size; + glstate->fpe_client.secondary.type = type; + glstate->fpe_client.secondary.stride = stride; + glstate->fpe_client.secondary.pointer = pointer; +} + +void fpe_glVertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer) { + DBG(printf("fpe_glVertexPointer(%d, %s, %d, %p)\n", size, PrintEnum(type), stride, pointer);) + glstate->fpe_client.vert.size = size; + glstate->fpe_client.vert.type = type; + glstate->fpe_client.vert.stride = stride; + glstate->fpe_client.vert.pointer = pointer; +} + +void fpe_glColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer) { + DBG(printf("fpe_glColorPointer(%d, %s, %d, %p)\n", size, PrintEnum(type), stride, pointer);) + glstate->fpe_client.color.size = size; + glstate->fpe_client.color.type = type; + glstate->fpe_client.color.stride = stride; + glstate->fpe_client.color.pointer = pointer; +} + +void fpe_glNormalPointer(GLenum type, GLsizei stride, const GLvoid *pointer) { + DBG(printf("fpe_glNormalPointer(%s, %d, %p)\n", PrintEnum(type), stride, pointer);) + glstate->fpe_client.normal.size = 3; + glstate->fpe_client.normal.type = type; + glstate->fpe_client.normal.stride = stride; + glstate->fpe_client.normal.pointer = pointer; +} + +void fpe_glTexCoordPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer) { + DBG(printf("fpe_glTexCoordPointer(%d, %s, %d, %p) on tmu=%d\n", size, PrintEnum(type), stride, pointer, glstate->texture.client);) + glstate->fpe_client.tex[glstate->texture.client].size = size; + glstate->fpe_client.tex[glstate->texture.client].type = type; + glstate->fpe_client.tex[glstate->texture.client].stride = stride; + glstate->fpe_client.tex[glstate->texture.client].pointer = pointer; +} + +void fpe_glFogCoordPointer(GLenum type, GLsizei stride, const GLvoid *pointer) { + DBG(printf("fpe_glFogPointer(%s, %d, %p)\n", PrintEnum(type), stride, pointer);) + glstate->fpe_client.fog.size = 1; + glstate->fpe_client.fog.type = type; + glstate->fpe_client.fog.stride = stride; + glstate->fpe_client.fog.pointer = pointer; +} + +void fpe_glEnable(GLenum cap) { + gl4es_glEnable(cap); // may reset fpe curent program +} +void fpe_glDisable(GLenum cap) { + gl4es_glDisable(cap); // may reset fpe curent program +} + +void fpe_glColor4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) { + noerrorShim(); +} + +void fpe_glNormal3f(GLfloat nx, GLfloat ny, GLfloat nz) { + noerrorShim(); +} + +void fpe_glDrawArrays(GLenum mode, GLint first, GLsizei count) { + DBG(printf("fpe_glDrawArrays(%s, %d, %d), program=%d, instanceID=%u\n", PrintEnum(mode), first, count, glstate->glsl->program, glstate->instanceID);) + void* scratch = NULL; + realize_glenv(mode==GL_POINTS, first, count, 0, NULL, &scratch); + LOAD_GLES(glDrawArrays); + gles_glDrawArrays(mode, first, count); + if(scratch) free(scratch); +} + +void fpe_glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices) { + DBG(printf("fpe_glDrawElements(%s, %d, %s, %p), program=%d, instanceID=%u\n", PrintEnum(mode), count, PrintEnum(type), indices, glstate->glsl->program, glstate->instanceID);) + void* scratch = NULL; + realize_glenv(mode==GL_POINTS, 0, count, type, indices, &scratch); + LOAD_GLES(glDrawElements); + gles_glDrawElements(mode, count, type, indices); + if(scratch) free(scratch); +} + +void fpe_glMatrixMode(GLenum mode) { + noerrorShim(); +} + +void fpe_glLightModelf(GLenum pname, GLfloat param) { + noerrorShim(); +} +void fpe_glLightModelfv(GLenum pname, const GLfloat* params) { + noerrorShim(); +} +void fpe_glLightfv(GLenum light, GLenum pname, const GLfloat* params) { + noerrorShim(); +} +void fpe_glMaterialfv(GLenum face, GLenum pname, const GLfloat *params) { + noerrorShim(); +} +void fpe_glMaterialf(GLenum face, GLenum pname, const GLfloat param) { + noerrorShim(); +} + +void fpe_glFogfv(GLenum pname, const GLfloat* params) { + noerrorShim(); + if(pname==GL_FOG_MODE) { + int p = *params; + switch(p) { + case GL_EXP: glstate->fpe_state->fogmode = FPE_FOG_EXP; break; + case GL_EXP2: glstate->fpe_state->fogmode = FPE_FOG_EXP2; break; + case GL_LINEAR: glstate->fpe_state->fogmode = FPE_FOG_LINEAR; break; + default: errorShim(GL_INVALID_ENUM); + } + } else if (pname==GL_FOG_COORDINATE_SOURCE) { + int p = *params; + switch(p) { + case GL_FRAGMENT_DEPTH: glstate->fpe_state->fogsource = FPE_FOG_SRC_DEPTH; break; + case GL_FOG_COORD: glstate->fpe_state->fogsource = FPE_FOG_SRC_COORD; break; + default: errorShim(GL_INVALID_ENUM); + } + } +} + +void fpe_glPointParameterfv(GLenum pname, const GLfloat * params) { + noerrorShim(); +} +void fpe_glPointSize(GLfloat size) { + noerrorShim(); +} + +void fpe_glAlphaFunc(GLenum func, GLclampf ref) { + noerrorShim(); + int f = FPE_ALWAYS; + switch(func) { + case GL_NEVER: f=FPE_NEVER; break; + case GL_LESS: f=FPE_LESS; break; + case GL_EQUAL: f=FPE_EQUAL; break; + case GL_LEQUAL: f=FPE_LEQUAL; break; + case GL_GREATER: f=FPE_GREATER; break; + case GL_NOTEQUAL: f=FPE_NOTEQUAL; break; + case GL_GEQUAL: f=FPE_GEQUAL; break; + } + if(glstate->fpe_state->alphafunc != f) { + glstate->fpe = NULL; + glstate->fpe_state->alphafunc = f; + } +} + + +// ********* Realize GLES Environnements ********* + +int fpe_gettexture(int TMU) { + int state=glstate->enable.texture[TMU]; + int target = -1; + #define GO(A) if(IS_##A(state) && glstate->texture.bound[TMU][ENABLED_##A]->valid) target = ENABLED_##A + GO(CUBE_MAP); + else GO(TEX3D); + else GO(TEXTURE_RECTANGLE); + else GO(TEX2D); + else GO(TEX1D); + #undef GO + return target; +} + +void realize_glenv(int ispoint, int first, int count, GLenum type, const void* indices, void** scratch) { + // the handling of GL_BGRA size of GL_DOUBLE using 1 scratch in not ideal, and a waste when dealing with Buffers + // TODO: have the scratch buffer part of the VBO, and tag it dirty when buffer is changed (or always dirty for VBO 0) + if(hardext.esversion==1) return; + LOAD_GLES2(glUseProgram); + // update texture state for fpe only + if(glstate->fpe_bound_changed && !glstate->glsl->program) { + for(int i=0; ifpe_bound_changed; i++) { + glstate->fpe_state->texformat &= ~(7<<(i*3)); + glstate->fpe_state->texadjust &= ~(1<fpe_state->textype &= ~(7<<(i*3)); + int texunit = fpe_gettexture(i); + gltexture_t* tex = (texunit==-1)?NULL:glstate->texture.bound[i][texunit]; + if(tex && tex->valid) { + int fmt; + if(texunit==ENABLED_CUBE_MAP) fmt = FPE_TEX_CUBE; + else { +#ifdef TEXSTREAM + if(tex->streamingID!=-1) + fmt = FPE_TEX_STRM; + else +#endif + if(texunit==ENABLED_TEXTURE_RECTANGLE) fmt = FPE_TEX_RECT; + else if(texunit==ENABLED_TEX3D) fmt = FPE_TEX_3D; + else fmt = FPE_TEX_2D; + } + glstate->fpe_state->texformat |= tex->fpe_format<<(i*3); + glstate->fpe_state->texadjust |= tex->adjust<fpe_state->texadjust |= 1<fpe_state->textype |= fmt<<(i*3); + } + } + glstate->fpe_bound_changed = 0; + } + // activate program if needed + if(glstate->glsl->program) { + // but first, check if some fixedpipeline state (like GL_ALPHA_TEST) need to alter the original program + fpe_state_t state; + fpe_ReleventState(&state, glstate->fpe_state, 0); + GLuint program = glstate->glsl->program; + program_t *glprogram = glstate->glsl->glprogram; + if(!fpe_IsEmpty(&state)) + { + // need to create a new program for that... + DBG(printf("GLSL program %d need customization => ", program);) + if(!glprogram->fpe_cache) + glprogram->fpe_cache = fpe_NewCache(); + glprogram = fpe_CustomShader(glprogram, &state); // fetch from cache if exist or create it + program = glprogram->id; + DBG(printf("%d\n", program);) + } + if(glstate->gleshard->program != program) + { + glstate->gleshard->program = program; + glstate->gleshard->glprogram = glprogram; + gles_glUseProgram(glstate->gleshard->program); + DBG(printf("Use GLSL program %d\n", glstate->gleshard->program);) + } + // synchronize uniforms with parent! + if(glprogram != glstate->glsl->glprogram) + fpe_SyncUniforms(&glstate->glsl->glprogram->cache, glprogram); + } else { + fpe_program(ispoint); + if(glstate->gleshard->program != glstate->fpe->prog) + { + glstate->gleshard->program = glstate->fpe->prog; + glstate->gleshard->glprogram = glstate->fpe->glprogram; + gles_glUseProgram(glstate->gleshard->program); + DBG(printf("Use FPE program %d\n", glstate->gleshard->program);) + } + } + program_t *glprogram = glstate->gleshard->glprogram; + // Texture Unit managements + int need_hackfbo = 0; + int tu_idx = 0; + while(tu_idxtexunits[tu_idx].type) { + // grab the uniform value + glprogram->texunits[tu_idx].req_tu = GetUniformi(glprogram, glprogram->texunits[tu_idx].id); + glprogram->texunits[tu_idx].act_tu = glprogram->texunits[tu_idx].req_tu; + ++tu_idx; + } + if(globals4es.fbounbind && glstate->fbo.current_fb->id) { + // check if need to unbind/bind fbo because texture is both attached and used + tu_idx = 0; + int need = 0; + gltexture_t * tex = NULL; + while(tu_idxtexunits[tu_idx].type && !need) { + tex = glstate->texture.bound[glprogram->texunits[tu_idx].req_tu][glprogram->texunits[tu_idx].type - 1]; + if(tex && tex->binded_fbo==glstate->fbo.current_fb->id) { + DBG(printf("Texture %d is used on Uniform %s (%d) and binded on FBO %d Attachement=%s\n", tex->glname, GetUniformName(glprogram, glprogram->texunits[tu_idx].id), glprogram->texunits[tu_idx].id, glstate->fbo.current_fb->id, PrintEnum(tex->binded_attachment));) + need = 1; + } + ++tu_idx; + } + if(need && tex) { + DBG(printf("LIBGL: Need to Bind/Unbind FBO!");) + LOAD_GLES2_OR_OES(glBindFramebuffer); + LOAD_GLES2_OR_OES(glFramebufferTexture2D); + //gles_glFramebufferTexture2D(GL_FRAMEBUFFER, tex->binded_attachment, GL_TEXTURE_2D, 0, 0); + gles_glBindFramebuffer(GL_FRAMEBUFFER, 0); + gles_glBindFramebuffer(GL_FRAMEBUFFER, glstate->fbo.current_fb->id); + //gles_glFramebufferTexture2D(GL_FRAMEBUFFER, tex->binded_attachment, GL_TEXTURE_2D, tex->glname, 0); + } + } + // setup fixed pipeline builtin vertex attrib if needed + vertexattrib_t wanted[MAX_VATTRIB]; + if(glprogram->has_builtin_attrib) + { + memcpy(wanted, glstate->glesva.wanted, sizeof(wanted)); + int vaarray = 0; + int id = -1; + // Vertex + id = glprogram->builtin_attrib[ATT_VERTEX]; + if(id!=-1) { + vertexattrib_t *w = &wanted[id]; + pointer_state_t *p = &glstate->fpe_client.vert; + w->vaarray = glstate->fpe_client.vertex_array; + if(w->vaarray) { + w->size = p->size; + w->type = p->type; + w->normalized = GL_FALSE;//(p->type==GL_FLOAT)?GL_FALSE:GL_TRUE; + w->stride = p->stride; + w->pointer = p->pointer; + w->buffer = NULL; + } else { + memcpy(w->current, glstate->vertex, 4*sizeof(GLfloat)); + } + } + // Color + id = glprogram->builtin_attrib[ATT_COLOR]; + if(id!=-1) { + vertexattrib_t *w = &wanted[id]; + pointer_state_t *p = &glstate->fpe_client.color; + w->vaarray = glstate->fpe_client.color_array; + if(w->vaarray) { + w->size = p->size; + w->type = p->type; + w->normalized = (p->type==GL_FLOAT)?GL_FALSE:GL_TRUE; + w->stride = p->stride; + w->pointer = p->pointer; + w->buffer = NULL; + } else { + memcpy(w->current, glstate->color, 4*sizeof(GLfloat)); + } + } + // Secondary Color + id = glprogram->builtin_attrib[ATT_SECONDARY]; + if(id!=-1) { + vertexattrib_t *w = &wanted[id]; + pointer_state_t *p = &glstate->fpe_client.secondary; + w->vaarray = glstate->fpe_client.secondary_array; + if(w->vaarray) { + w->size = p->size; + w->type = p->type; + w->normalized = (p->type==GL_FLOAT)?GL_FALSE:GL_TRUE; + w->stride = p->stride; + w->pointer = p->pointer; + w->buffer = NULL; + } else { + memcpy(w->current, glstate->secondary, 4*sizeof(GLfloat)); + } + } + // Fog Coord + id = glprogram->builtin_attrib[ATT_FOGCOORD]; + if(id!=-1) { + vertexattrib_t *w = &wanted[id]; + pointer_state_t *p = &glstate->fpe_client.fog; + w->vaarray = glstate->fpe_client.fog_array; + if(w->vaarray) { + w->size = p->size; + w->type = p->type; + w->normalized = (p->type==GL_FLOAT)?GL_FALSE:GL_TRUE; + w->stride = p->stride; + w->pointer = p->pointer; + w->buffer = NULL; + } else { + memcpy(w->current, &glstate->fogcoord, 1*sizeof(GLfloat)); + memset(w->current+1, 0, 3*sizeof(GLfloat)); + } + } + // TexCoordX + for(int tex=0; texbuiltin_attrib[ATT_MULTITEXCOORD0+tex]; + if(id!=-1) { + vertexattrib_t *w = &wanted[id]; + pointer_state_t *p = &glstate->fpe_client.tex[tex]; + w->vaarray = glstate->fpe_client.tex_coord_array[tex]; + if(w->vaarray) { + w->size = p->size; + w->type = p->type; + w->normalized = GL_FALSE;//(p->type==GL_FLOAT)?GL_FALSE:GL_TRUE; + w->stride = p->stride; + w->pointer = p->pointer; + w->buffer = NULL; + } else { + memcpy(w->current, glstate->texcoord[tex], 4*sizeof(GLfloat)); + } + } + } + // Normal + id = glprogram->builtin_attrib[ATT_NORMAL]; + if(id!=-1) { + vertexattrib_t *w = &wanted[id]; + pointer_state_t *p = &glstate->fpe_client.normal; + w->vaarray = glstate->fpe_client.normal_array; + if(w->vaarray) { + w->size = p->size; + w->type = p->type; + w->normalized = GL_FALSE;//(p->type==GL_FLOAT)?GL_FALSE:GL_TRUE; + w->stride = p->stride; + w->pointer = p->pointer; + w->buffer = NULL; + } else { + memcpy(w->current, glstate->normal, 3*sizeof(GLfloat)); + w->current[3] = 1.0f; + } + } + //TODO: Secondary colors + } + // setup fixed pipeline builtin matrix uniform if needed + if(glprogram->has_builtin_matrix) + { + if(glprogram->builtin_matrix[MAT_MVP]!=-1 || glprogram->builtin_matrix[MAT_MVP_I]!=-1 + || glprogram->builtin_matrix[MAT_MVP_T]!=-1 || glprogram->builtin_matrix[MAT_MVP_IT]!=-1) + { + GoUniformMatrix4fv(glprogram, glprogram->builtin_matrix[MAT_MVP], 1, GL_FALSE, getMVPMat()); + GoUniformMatrix4fv(glprogram, glprogram->builtin_matrix[MAT_MVP_T], 1, GL_TRUE, getMVPMat()); + if(glprogram->builtin_matrix[MAT_MVP_I]!=-1 || glprogram->builtin_matrix[MAT_MVP_IT]!=-1) { + GLfloat invmat[16]; + matrix_inverse(getMVPMat(), invmat); + GoUniformMatrix4fv(glprogram, glprogram->builtin_matrix[MAT_MVP_I], 1, GL_FALSE, invmat); + GoUniformMatrix4fv(glprogram, glprogram->builtin_matrix[MAT_MVP_IT], 1, GL_TRUE, invmat); + } + } + if(glprogram->builtin_matrix[MAT_MV]!=-1 || glprogram->builtin_matrix[MAT_MV_I]!=-1 + || glprogram->builtin_matrix[MAT_MV_T]!=-1 || glprogram->builtin_matrix[MAT_MV_IT]!=-1) + { + GoUniformMatrix4fv(glprogram, glprogram->builtin_matrix[MAT_MV], 1, GL_FALSE, getMVMat()); + GoUniformMatrix4fv(glprogram, glprogram->builtin_matrix[MAT_MV_T], 1, GL_TRUE, getMVMat()); + if(glprogram->builtin_matrix[MAT_MV_I]!=-1 || glprogram->builtin_matrix[MAT_MV_IT]!=-1) { + GoUniformMatrix4fv(glprogram, glprogram->builtin_matrix[MAT_MV_I], 1, GL_FALSE, getInvMVMat()); + GoUniformMatrix4fv(glprogram, glprogram->builtin_matrix[MAT_MV_IT], 1, GL_TRUE, getInvMVMat()); + } + } + if(glprogram->builtin_matrix[MAT_P]!=-1 || glprogram->builtin_matrix[MAT_P_I]!=-1 + || glprogram->builtin_matrix[MAT_P_T]!=-1 || glprogram->builtin_matrix[MAT_P_IT]!=-1) + { + GoUniformMatrix4fv(glprogram, glprogram->builtin_matrix[MAT_P], 1, GL_FALSE, getPMat()); + GoUniformMatrix4fv(glprogram, glprogram->builtin_matrix[MAT_P_T], 1, GL_TRUE, getPMat()); + if(glprogram->builtin_matrix[MAT_P_I]!=-1 || glprogram->builtin_matrix[MAT_P_IT]!=-1) { + GLfloat invmat[16]; + matrix_inverse(getPMat(), invmat); + GoUniformMatrix4fv(glprogram, glprogram->builtin_matrix[MAT_P_I], 1, GL_FALSE, invmat); + GoUniformMatrix4fv(glprogram, glprogram->builtin_matrix[MAT_P_IT], 1, GL_TRUE, invmat); + } + } + //Normal matrix (mat3 version of transpose(inverse(gl_ModelViewMatrix))) + if(glprogram->builtin_matrix[MAT_N]!=-1 || glprogram->builtin_normalrescale!=-1) + { + if(glprogram->builtin_normalrescale!=-1 && !glstate->fpe_state->rescaling) + { + float tmp = 1.0f; + GoUniformfv(glprogram, glprogram->builtin_normalrescale, 1, 1, &tmp); + } + if(glprogram->builtin_matrix[MAT_N]!=-1) + { + GoUniformMatrix3fv(glprogram, glprogram->builtin_matrix[MAT_N], 1, GL_FALSE, getNormalMat()); + } + if((glprogram->builtin_normalrescale!=-1 && glstate->fpe_state->rescaling)) + { + if(glprogram->builtin_normalrescale!=-1) { + const float *invmat = getInvMVMat(); + float tmp = 1.0f/sqrtf(invmat[3*4+1]*invmat[3*4+1]+invmat[3*4+2]*invmat[3*4+2]+invmat[3*4+3]*invmat[3*4+3]); + GoUniformfv(glprogram, glprogram->builtin_normalrescale, 1, 1, &tmp); + } + } + } + //Texture matrices + for (int i=0; ibuiltin_matrix[MAT_T0+i*4]!=-1 || glprogram->builtin_matrix[MAT_T0_I+i*4]!=-1 + || glprogram->builtin_matrix[MAT_T0_T+i*4]!=-1 || glprogram->builtin_matrix[MAT_T0_IT+i*4]!=-1) + { + GoUniformMatrix4fv(glprogram, glprogram->builtin_matrix[MAT_T0+i*4], 1, GL_FALSE, getTexMat(i)); + GoUniformMatrix4fv(glprogram, glprogram->builtin_matrix[MAT_T0_T+i*4], 1, GL_TRUE, getTexMat(i)); + if(glprogram->builtin_matrix[MAT_T0_I+i*4]!=-1 || glprogram->builtin_matrix[MAT_T0_IT+i*4]!=-1) { + GLfloat invmat[16]; + matrix_inverse(getTexMat(i), invmat); + GoUniformMatrix4fv(glprogram, glprogram->builtin_matrix[MAT_T0_I+i*4], 1, GL_FALSE, invmat); + GoUniformMatrix4fv(glprogram, glprogram->builtin_matrix[MAT_T0_IT+i*4], 1, GL_TRUE, invmat); + } + } + } + } + // set light and material if needed + if(glprogram->has_builtin_light) + { + for (int i=0; ibuiltin_lights[i].has) { + GLfloat tmp[4]; + GoUniformfv(glprogram, glprogram->builtin_lights[i].ambient, 4, 1, glstate->light.lights[i].ambient); + GoUniformfv(glprogram, glprogram->builtin_lights[i].diffuse, 4, 1, glstate->light.lights[i].diffuse); + GoUniformfv(glprogram, glprogram->builtin_lights[i].specular, 4, 1, glstate->light.lights[i].specular); + GoUniformfv(glprogram, glprogram->builtin_lights[i].position, 4, 1, glstate->light.lights[i].position); + if(glprogram->builtin_lights[i].halfVector!=-1) { // not sure of this, isn't gl_Vertex need to be used at some point? + GLfloat tmp[4]; + memcpy(tmp, glstate->light.lights[i].position, 4*sizeof(GLfloat)); + vector4_normalize(tmp); + if(!glstate->light.local_viewer) { + tmp[2]+=1.f; + vector4_normalize(tmp); + } + GoUniformfv(glprogram, glprogram->builtin_lights[i].halfVector, 1, 1, tmp); + } + GoUniformfv(glprogram, glprogram->builtin_lights[i].spotDirection, 3, 1, glstate->light.lights[i].spotDirection); + GoUniformfv(glprogram, glprogram->builtin_lights[i].spotExponent, 1, 1, &glstate->light.lights[i].spotExponent); + GoUniformfv(glprogram, glprogram->builtin_lights[i].spotCutoff, 1, 1, &glstate->light.lights[i].spotCutoff); + if(!memcmp(&glprogram->builtin_lights[i].oldspotCutoff, &glstate->light.lights[i].spotCutoff, sizeof(GLfloat))) + { + memcpy(&glprogram->builtin_lights[i].oldspotCutoff, &glstate->light.lights[i].spotCutoff, sizeof(GLfloat)); + glprogram->builtin_lights[i].oldspotCosCutoff = cosf(glstate->light.lights[i].spotCutoff*3.1415926535f/180.0f); + } + GoUniformfv(glprogram, glprogram->builtin_lights[i].spotCosCutoff, 1, 1, &glprogram->builtin_lights[i].oldspotCosCutoff); + GoUniformfv(glprogram, glprogram->builtin_lights[i].constantAttenuation, 1, 1, &glstate->light.lights[i].constantAttenuation); + GoUniformfv(glprogram, glprogram->builtin_lights[i].linearAttenuation, 1, 1, &glstate->light.lights[i].linearAttenuation); + GoUniformfv(glprogram, glprogram->builtin_lights[i].quadraticAttenuation, 1, 1, &glstate->light.lights[i].quadraticAttenuation); + } + if(glprogram->builtin_lightprod[0][i].has) { + GLfloat tmp[4]; + vector4_mult(glstate->material.front.ambient, glstate->light.lights[i].ambient, tmp); //TODO: Check that + GoUniformfv(glprogram, glprogram->builtin_lightprod[0][i].ambient, 4, 1, tmp); + vector4_mult(glstate->material.front.diffuse, glstate->light.lights[i].diffuse, tmp); + GoUniformfv(glprogram, glprogram->builtin_lightprod[0][i].diffuse, 4, 1, tmp); + vector4_mult(glstate->material.front.specular, glstate->light.lights[i].specular, tmp); + GoUniformfv(glprogram, glprogram->builtin_lightprod[0][i].specular, 4, 1, tmp); + } + if(glprogram->builtin_lightprod[1][i].has) { + GLfloat tmp[4]; + vector4_mult(glstate->material.back.ambient, glstate->light.lights[i].ambient, tmp); //TODO: Check that + GoUniformfv(glprogram, glprogram->builtin_lightprod[1][i].ambient, 4, 1, tmp); + vector4_mult(glstate->material.back.diffuse, glstate->light.lights[i].diffuse, tmp); + GoUniformfv(glprogram, glprogram->builtin_lightprod[1][i].diffuse, 4, 1, tmp); + vector4_mult(glstate->material.back.specular, glstate->light.lights[i].specular, tmp); + GoUniformfv(glprogram, glprogram->builtin_lightprod[1][i].specular, 4, 1, tmp); + } + } + if(glprogram->builtin_lightmodel.ambient!=-1) { + GoUniformfv(glprogram, glprogram->builtin_lightmodel.ambient, 4, 1, glstate->light.ambient); + } + if(glprogram->builtin_material[0].has) { + GoUniformfv(glprogram, glprogram->builtin_material[0].emission, 4, 1, glstate->material.front.emission); + GoUniformfv(glprogram, glprogram->builtin_material[0].ambient, 4, 1, glstate->material.front.ambient); + GoUniformfv(glprogram, glprogram->builtin_material[0].diffuse, 4, 1, glstate->material.front.diffuse); + GoUniformfv(glprogram, glprogram->builtin_material[0].specular, 4, 1, glstate->material.front.specular); + GoUniformfv(glprogram, glprogram->builtin_material[0].shininess, 1, 1, &glstate->material.front.shininess); + GoUniformfv(glprogram, glprogram->builtin_material[0].alpha, 1, 1, &glstate->material.front.diffuse[3]); + } + if(glprogram->builtin_material[1].has) { + GoUniformfv(glprogram, glprogram->builtin_material[1].emission, 4, 1, glstate->material.back.emission); + GoUniformfv(glprogram, glprogram->builtin_material[1].ambient, 4, 1, glstate->material.back.ambient); + GoUniformfv(glprogram, glprogram->builtin_material[1].diffuse, 4, 1, glstate->material.back.diffuse); + GoUniformfv(glprogram, glprogram->builtin_material[1].specular, 4, 1, glstate->material.back.specular); + GoUniformfv(glprogram, glprogram->builtin_material[1].shininess, 1, 1, &glstate->material.back.shininess); + GoUniformfv(glprogram, glprogram->builtin_material[1].alpha, 1, 1, &glstate->material.back.diffuse[3]); + } + if(glprogram->builtin_lightmodelprod[0].sceneColor!=-1) { + GLfloat tmp[4]; + vector4_mult(glstate->material.front.ambient, glstate->light.ambient, tmp); //TODO: check that + vector4_add(tmp, glstate->material.front.emission, tmp); + GoUniformfv(glprogram, glprogram->builtin_lightmodelprod[0].sceneColor, 4, 1, tmp); + } + if(glprogram->builtin_lightmodelprod[1].sceneColor!=-1) { + GLfloat tmp[4]; + vector4_mult(glstate->material.back.ambient, glstate->light.ambient, tmp); //TODO: check that + vector4_add(tmp, glstate->material.back.emission, tmp); + GoUniformfv(glprogram, glprogram->builtin_lightmodelprod[1].sceneColor, 4, 1, tmp); + } + } + // Instance ID + if(glprogram->builtin_instanceID!=-1) + { + GoUniformiv(glprogram, glprogram->builtin_instanceID, 1, 1, &glstate->instanceID); + } + // fog parameters + if(glprogram->builtin_fog.has) + { + GoUniformfv(glprogram, glprogram->builtin_fog.color, 4, 1, glstate->fog.color); + GoUniformfv(glprogram, glprogram->builtin_fog.density, 1, 1, &glstate->fog.density); + GoUniformfv(glprogram, glprogram->builtin_fog.start, 1, 1, &glstate->fog.start); + GoUniformfv(glprogram, glprogram->builtin_fog.end, 1, 1, &glstate->fog.end); + if(glprogram->builtin_fog.scale!=-1) { + GLfloat tmp = 1.f/(glstate->fog.end - glstate->fog.start); + GoUniformfv(glprogram, glprogram->builtin_fog.scale, 1, 1, &tmp); + } + } + // clip planes + if(glprogram->has_builtin_clipplanes) + { + for (int i=0; ibuiltin_clipplanes[i], 4, 1, glstate->planes[i]); + } + } + // check point sprite if needed + if(glprogram->builtin_pointsprite.has) + { + GoUniformfv(glprogram, glprogram->builtin_pointsprite.size, 1, 1, &glstate->pointsprite.size); + GoUniformfv(glprogram, glprogram->builtin_pointsprite.sizeMin, 1, 1, &glstate->pointsprite.sizeMin); + GoUniformfv(glprogram, glprogram->builtin_pointsprite.sizeMax, 1, 1, &glstate->pointsprite.sizeMax); + GoUniformfv(glprogram, glprogram->builtin_pointsprite.fadeThresholdSize, 1, 1, &glstate->pointsprite.fadeThresholdSize); + GoUniformfv(glprogram, glprogram->builtin_pointsprite.distanceConstantAttenuation, 1, 1, glstate->pointsprite.distance+0); + GoUniformfv(glprogram, glprogram->builtin_pointsprite.distanceLinearAttenuation, 1, 1, glstate->pointsprite.distance+1); + GoUniformfv(glprogram, glprogram->builtin_pointsprite.distanceQuadraticAttenuation, 1, 1, glstate->pointsprite.distance+2); + } + // texenv + if(glprogram->has_builtin_texenv) + { + for (int i=0; ibuiltin_texenvcolor[i], 4, 1, glstate->texenv[i].env.color); + // specific FPE + GoUniformfv(glprogram, glprogram->builtin_texenvrgbscale[i], 1, 1, &glstate->texenv[i].env.rgb_scale); + GoUniformfv(glprogram, glprogram->builtin_texenvalphascale[i], 1, 1, &glstate->texenv[i].env.alpha_scale); + } + } + // texgen + if(glprogram->has_builtin_texgen) + { + for (int i=0; ibuiltin_eye[0][i], 4, 1, glstate->texgen[i].S_E); + GoUniformfv(glprogram, glprogram->builtin_eye[1][i], 4, 1, glstate->texgen[i].T_E); + GoUniformfv(glprogram, glprogram->builtin_eye[2][i], 4, 1, glstate->texgen[i].R_E); + GoUniformfv(glprogram, glprogram->builtin_eye[3][i], 4, 1, glstate->texgen[i].Q_E); + GoUniformfv(glprogram, glprogram->builtin_obj[0][i], 4, 1, glstate->texgen[i].S_O); + GoUniformfv(glprogram, glprogram->builtin_obj[1][i], 4, 1, glstate->texgen[i].T_O); + GoUniformfv(glprogram, glprogram->builtin_obj[2][i], 4, 1, glstate->texgen[i].R_O); + GoUniformfv(glprogram, glprogram->builtin_obj[3][i], 4, 1, glstate->texgen[i].Q_O); + } + } + // fpe + if(glprogram->fpe_alpharef!=-1) + { + float alpharef = floorf(glstate->alpharef*255.f); + GoUniformfv(glprogram, glprogram->fpe_alpharef, 1, 1, &alpharef); + } + if(glprogram->has_builtin_texsampler) + { + for (int i=0; ibuiltin_texsampler[i], 1, 1, &i); // very basic stuff here, but sampler needs to be a uniform... + } + if(glprogram->has_builtin_texadjust) + { + for (int i=0; itexture.bound[i][tt]; + if(tex && tex->valid) + GoUniformfv(glprogram, glprogram->builtin_texadjust[i], 2, 1, tex->adjustxy); + } + } + + + // set VertexAttrib if needed + for(int i=0; iva_size[i]) // only check used VA... + { + vertexattrib_t *v = &glstate->glesva.vertexattrib[i]; + vertexattrib_t *w = (glprogram->has_builtin_attrib)?(&wanted[i]):(&glstate->glesva.wanted[i]); + int dirty = 0; + // enable / disable Array if needed + if(v->vaarray != w->vaarray || (v->vaarray && w->divisor)) { + dirty = 1; + LOAD_GLES2(glEnableVertexAttribArray) + LOAD_GLES2(glDisableVertexAttribArray); + v->vaarray = (w->divisor)?0:w->vaarray; + DBG(printf("VertexAttribArray[%d]:%s, divisor=%d\n", i, (w->vaarray)?"Enable":"Disable", w->divisor);) + if(v->vaarray) + gles_glEnableVertexAttribArray(i); + else + gles_glDisableVertexAttribArray(i); + } + // check if new value has to be sent to hardware + if(v->vaarray) { + // array case + void * ptr = (void*)((uintptr_t)w->pointer + ((w->buffer)?(uintptr_t)w->buffer->data:0)); + if(dirty || v->size!=w->size || v->type!=w->type || v->normalized!=w->normalized + || v->stride!=w->stride || v->buffer!=w->buffer + || v->pointer!=ptr) { + if((w->size==GL_BGRA || w->type==GL_DOUBLE) && !*scratch) { + // need to adjust, so first need the min/max (a shame as I already must have that somewhere) + int imin, imax; + if(type==0) { + imin = first; imax = count; + } else { + if(type==GL_UNSIGNED_INT) + getminmax_indices_ui(indices, &imax, &imin, count); + else + getminmax_indices_us(indices, &imax, &imin, count); + ++imax; + } + if(w->size==GL_BGRA) { + v->size = 4; + v->type = GL_FLOAT; + v->normalized = 0; + v->pointer = *scratch = copy_gl_pointer_color_bgra(ptr, w->stride, 4, imin, imax); + v->stride = 0; + v->buffer = NULL; + } else if (w->type == GL_DOUBLE) { + // TODO + static int warn = 1; + if(warn) { + printf("LIBGL: VertexAttribArray using GL_DOUBLE unimplemented!\n"); + warn=0; + } + } + } else { + v->size = w->size; + v->type = w->type; + v->normalized = w->normalized; + v->stride = w->stride; + v->pointer = ptr; + v->buffer = w->buffer; // buffer is unused here + } + LOAD_GLES2(glVertexAttribPointer); + gles_glVertexAttribPointer(i, v->size, v->type, v->normalized, v->stride, v->pointer); + DBG(printf("glVertexAttribPointer(%d, %d, %s, %d, %d, %p)\n", i, v->size, PrintEnum(v->type), v->normalized, v->stride, (GLvoid*)((uintptr_t)v->pointer+((v->buffer)?(uintptr_t)v->buffer->data:0)));) + } + } else { + // single value case + char* current = (char*)w->current; + GLfloat tmp[4] = {0.0f, 0.0f, 0.0f, 1.0f}; + if(w->divisor && w->vaarray) { + current = (char*)((uintptr_t)w->pointer + ((w->buffer)?(uintptr_t)w->buffer->data:0)); + int stride=w->stride; + if(!stride) stride=gl_sizeof(w->type)*w->size; + current += (glstate->instanceID/w->divisor) * stride; + if(w->type==GL_FLOAT) { + if(w->size!=4) { + memcpy(tmp, current, sizeof(GLfloat)*w->size); + current = (char*)tmp; + } + } else { + if(w->type == GL_DOUBLE || !w->normalized) { + for(int k=0; ksize; ++k) { + GL_TYPE_SWITCH(input, current, w->type, + tmp[k] = input[k]; + ,) + } + } else { + for(int k=0; ksize; ++k) { + GL_TYPE_SWITCH_MAX(input, current, w->type, + tmp[k] = (float)input[k]/(float)maxv; + ,) + } + } + current = (char*)tmp; + } + } + if(dirty || memcmp(v->current, current, 4*sizeof(GLfloat))) { + memcpy(v->current, current, 4*sizeof(GLfloat)); + LOAD_GLES2(glVertexAttrib4fv); + gles_glVertexAttrib4fv(i, v->current); + DBG(printf("glVertexAttrib4fv(%d, %p) => (%f, %f, %f, %f)\n", i, v->current, v->current[0], v->current[1], v->current[2], v->current[3]);) + } + } + } else { + // disable VAArray, to be on the safe side + vertexattrib_t *v = &glstate->glesva.vertexattrib[i]; + if(v->vaarray) { + LOAD_GLES2(glDisableVertexAttribArray); + v->vaarray = 0; + DBG(printf("VertexAttribArray[%d]:%s\n", i, "Disable");) + gles_glDisableVertexAttribArray(i); + } + } +} + +void realize_blitenv(int alpha) { + DBG(printf("realize_blitenv(%d)\n", alpha);) + LOAD_GLES2(glUseProgram); + if(glstate->gleshard->program != ((alpha)?glstate->blit->program_alpha:glstate->blit->program)) { + glstate->gleshard->program = ((alpha)?glstate->blit->program_alpha:glstate->blit->program); + gles_glUseProgram(glstate->gleshard->program); + } + // set VertexAttrib if needed + for(int i=0; iglesva.vertexattrib[i]; + // enable / disable Array if needed + if(v->vaarray != ((i<2)?1:0)) { + LOAD_GLES2(glEnableVertexAttribArray) + LOAD_GLES2(glDisableVertexAttribArray); + v->vaarray = ((i<2)?1:0); + if(v->vaarray) + gles_glEnableVertexAttribArray(i); + else + gles_glDisableVertexAttribArray(i); + } + // check if new value has to be sent to hardware + if(i<2) { + // array case + if(v->size!=2 || v->type!=GL_FLOAT || v->normalized!=0 + || v->stride!=0 || v->pointer!=((i==0)?glstate->blit->vert:glstate->blit->tex) + || v->buffer!=0) { + v->size = 2; + v->type = GL_FLOAT; + v->normalized = 0; + v->stride = 0; + v->pointer = ((i==0)?glstate->blit->vert:glstate->blit->tex); + v->buffer = 0; + LOAD_GLES2(glVertexAttribPointer); + gles_glVertexAttribPointer(i, v->size, v->type, v->normalized, v->stride, v->pointer); + } + } + } +} + +// ********* Builtin GL Uniform, VertexAttrib and co ********* + +void builtin_Init(program_t *glprogram) { + // initialise emulated builtin matrix uniform to -1 + for (int i=0; ibuiltin_matrix[i] = -1; + for (int i=0; ibuiltin_lights[i].ambient = -1; + glprogram->builtin_lights[i].diffuse = -1; + glprogram->builtin_lights[i].specular = -1; + glprogram->builtin_lights[i].position = -1; + glprogram->builtin_lights[i].halfVector = -1; + glprogram->builtin_lights[i].spotDirection = -1; + glprogram->builtin_lights[i].spotExponent = -1; + glprogram->builtin_lights[i].spotCutoff = -1; + glprogram->builtin_lights[i].spotCosCutoff = -1; + glprogram->builtin_lights[i].constantAttenuation = -1; + glprogram->builtin_lights[i].linearAttenuation = -1; + glprogram->builtin_lights[i].quadraticAttenuation = -1; + } + glprogram->builtin_lightmodel.ambient = -1; + for (int i=0; i<2; i++) { // 0:Front, 1:Back + glprogram->builtin_material[i].emission = -1; + glprogram->builtin_material[i].ambient = -1; + glprogram->builtin_material[i].diffuse = -1; + glprogram->builtin_material[i].specular = -1; + glprogram->builtin_material[i].shininess = -1; + glprogram->builtin_material[i].alpha = -1; + + glprogram->builtin_lightmodelprod[i].sceneColor = -1; + + for (int j=0; jbuiltin_lightprod[i][j].ambient = -1; + glprogram->builtin_lightprod[i][j].diffuse = -1; + glprogram->builtin_lightprod[i][j].specular = -1; + } + } + glprogram->builtin_normalrescale = -1; + glprogram->builtin_instanceID = -1; + for (int i=0; ibuiltin_clipplanes[i] = -1; + glprogram->builtin_pointsprite.size = -1; + glprogram->builtin_pointsprite.sizeMin = -1; + glprogram->builtin_pointsprite.sizeMax = -1; + glprogram->builtin_pointsprite.fadeThresholdSize = -1; + glprogram->builtin_pointsprite.distanceConstantAttenuation = -1; + glprogram->builtin_pointsprite.distanceLinearAttenuation = -1; + glprogram->builtin_pointsprite.distanceQuadraticAttenuation = -1; + for (int i=0; ibuiltin_texenvcolor[i] = -1; + glprogram->builtin_texenvrgbscale[i] = -1; + glprogram->builtin_texenvrgbscale[i] = -1; + for (int j=0; j<4; j++) { + glprogram->builtin_eye[j][i] = -1; + glprogram->builtin_obj[j][i] = -1; + } + glprogram->builtin_texsampler[i] = -1; + glprogram->builtin_texadjust[i] = -1; + } + glprogram->builtin_fog.color = -1; + glprogram->builtin_fog.density = -1; + glprogram->builtin_fog.start = -1; + glprogram->builtin_fog.end = -1; + glprogram->builtin_fog.scale = -1; + // fpe uniform + glprogram->fpe_alpharef = -1; + // initialise emulated builtin attrib to -1 + for (int i=0; ibuiltin_attrib[i] = -1; +} + +const char* gl4es_code = "_gl4es_"; +const char* lightsource_code = "_gl4es_LightSource["; +const char* lightsource_fpe_code = "_gl4es_LightSource_"; +const char* lightmodel_code = "_gl4es_LightModel."; +const char* frontmaterial_code = "_gl4es_FrontMaterial"; +const char* backmaterial_code = "_gl4es_BackMaterial"; +const char* frontmaterial_fpe_code = "_gl4es_FrontMaterial_shininess"; +const char* backmaterial_fpe_code = "_gl4es_BackMaterial_shininess"; +const char* frontlightmodelprod_code = "_gl4es_FrontLightModelProduct"; +const char* backlightmodelprod_code = "_gl4es_BackLightModelProduct"; +const char* frontlightprod_code = "_gl4es_FrontLightProduct["; +const char* backlightprod_code = "_gl4es_BackLightProduct["; +const char* frontlightprod_fpe_code = "_gl4es_FrontLightProduct_"; +const char* backlightprod_fpe_code = "_gl4es_BackLightProduct_"; +const char* normalrescale_code = "_gl4es_NormalScale"; +const char* instanceID_code = "_gl4es_InstanceID"; +const char* clipplanes_code = "_gl4es_ClipPlane["; +const char* clipplanes_fpe_code = "_gl4es_ClipPlane_"; +const char* point_code = "_gl4es_Point"; +const char* texenvcolor_code = "_gl4es_TextureEnvColor["; +const char* texenvcolor_fpe_code = "_gl4es_TextureEnvColor_"; +const char* texenvcolor_noa_code = "_gl4es_TextureEnvColor"; +const char* texgeneyestart_code = "_gl4es_EyePlane"; +const char* texgeneye_code = "_gl4es_EyePlane%c["; +const char* texgeneye_fpe_code = "_gl4es_EyePlane%c_"; +const char* texgeneye_noa_code = "_gl4es_EyePlane%c"; +const char* texgenobjstart_code = "_gl4es_ObjectPlane"; +const char* texgenobj_code = "_gl4es_ObjectPlane%c["; +const char* texgenobj_fpe_code = "_gl4es_ObjectPlane%c_"; +const char* texgenobj_noa_code = "_gl4es_ObjectPlane%c"; +const char texgenCoords[4] = {'S', 'T', 'R', 'Q'}; +const char* alpharef_code = "_gl4es_AlphaRef"; +const char* fpetexSampler_code = "_gl4es_TexSampler_"; +const char* fpetexenvRGBScale_code = "_gl4es_TexEnvRGBScale_"; +const char* fpetexenvAlphaScale_code = "_gl4es_TexEnvAlphaScale_"; +const char* fpetexAdjust_code = "_gl4es_TexAdjust_"; +const char* fog_code = "_gl4es_Fog."; +int builtin_CheckUniform(program_t *glprogram, char* name, GLint id, int size) { + if(strncmp(name, gl4es_code, strlen(gl4es_code))) + return 0; // doesn't start with "_gl4es_", no need to look further + int builtin = isBuiltinMatrix(name); + // check matrices + if(builtin!=-1) { + glprogram->builtin_matrix[builtin] = id; + glprogram->has_builtin_matrix = 1; + return 1; + } + // lightsource + if(strncmp(name, lightsource_code, strlen(lightsource_code))==0 || strncmp(name, lightsource_fpe_code, strlen(lightsource_fpe_code))==0) { + // it a light! grab it's number - also, fpe or not fpe is the same lenght. The fpe version avoid the array... + int n = name[strlen(lightsource_code)]-'0'; // only 8 light, so this works + if(n>=0 && nbuiltin_lights[n].ambient = id; + else if(strstr(name, ".diffuse")) glprogram->builtin_lights[n].diffuse = id; + else if(strstr(name, ".specular")) glprogram->builtin_lights[n].specular = id; + else if(strstr(name, ".position")) glprogram->builtin_lights[n].position = id; + else if(strstr(name, ".halfVector")) glprogram->builtin_lights[n].halfVector = id; + else if(strstr(name, ".spotDirection")) glprogram->builtin_lights[n].spotDirection = id; + else if(strstr(name, ".spotExponent")) glprogram->builtin_lights[n].spotExponent = id; + else if(strstr(name, ".spotCutoff")) glprogram->builtin_lights[n].spotCutoff = id; + else if(strstr(name, ".spotCosCutoff")) glprogram->builtin_lights[n].spotCosCutoff = id; + else if(strstr(name, ".constantAttenuation")) glprogram->builtin_lights[n].constantAttenuation = id; + else if(strstr(name, ".linearAttenuation")) glprogram->builtin_lights[n].linearAttenuation = id; + else if(strstr(name, ".quadraticAttenuation")) glprogram->builtin_lights[n].quadraticAttenuation = id; + glprogram->has_builtin_light = 1; + glprogram->builtin_lights[n].has = 1; + return 1; + } + } + if(strncmp(name, lightmodel_code, strlen(lightmodel_code))==0) + { + // it's a Light Model + if(strstr(name, "ambient")) glprogram->builtin_lightmodel.ambient = id; + glprogram->has_builtin_light = 1; + return 1; + } + if(strncmp(name, frontmaterial_code, strlen(frontmaterial_code))==0 + || strncmp(name, backmaterial_code, strlen(backmaterial_code))==0) + { + // it's a material + int n=(strncmp(name, frontmaterial_code, strlen(frontmaterial_code))==0)?0:1; + if(strstr(name, ".emission")) glprogram->builtin_material[n].emission = id; + else if(strstr(name, ".ambient")) glprogram->builtin_material[n].ambient = id; + else if(strstr(name, ".diffuse")) glprogram->builtin_material[n].diffuse = id; + else if(strstr(name, ".specular")) glprogram->builtin_material[n].specular = id; + else if(strstr(name, ".shininess")) glprogram->builtin_material[n].shininess = id; + else if(strstr(name, "_shininess")) glprogram->builtin_material[n].shininess = id; + else if(strstr(name, "_alpha")) glprogram->builtin_material[n].alpha = id; + glprogram->has_builtin_light = 1; + glprogram->builtin_material[n].has = 1; + return 1; + } + if(strncmp(name, frontlightmodelprod_code, strlen(frontlightmodelprod_code))==0 + || strncmp(name, backlightmodelprod_code, strlen(backlightmodelprod_code))==0) + { + // it's a front light model product + int n=(strncmp(name, frontlightmodelprod_code, strlen(frontlightmodelprod_code))==0)?0:1; + if(strstr(name, ".sceneColor")) glprogram->builtin_lightmodelprod[n].sceneColor = id; + glprogram->has_builtin_light = 1; + return 1; + } + if(strncmp(name, frontlightprod_code, strlen(frontlightprod_code))==0 + || strncmp(name, backlightprod_code, strlen(backlightprod_code))==0 + || strncmp(name, frontlightprod_fpe_code, strlen(frontlightprod_fpe_code))==0 + || strncmp(name, backlightprod_fpe_code, strlen(backlightprod_fpe_code))==0 + ) + { + // it's a material + int i=(strncmp(name, frontlightprod_code, strlen(frontlightprod_code))==0 || strncmp(name, frontlightprod_fpe_code, strlen(frontlightprod_fpe_code))==0)?0:1; + int n = name[strlen(i?backlightprod_code:frontlightprod_code)]-'0'; // only 8 light, so this works + if(n>=0 && nbuiltin_lightprod[i][n].ambient = id; + else if(strstr(name, ".diffuse")) glprogram->builtin_lightprod[i][n].diffuse = id; + else if(strstr(name, ".specular")) glprogram->builtin_lightprod[i][n].specular = id; + glprogram->has_builtin_light = 1; + glprogram->builtin_lightprod[i][n].has = 1; + return 1; + } + } + if(strncmp(name, normalrescale_code, strlen(normalrescale_code))==0) + { + glprogram->builtin_normalrescale = id; + glprogram->has_builtin_matrix = 1; // this is in the matrix block + return 1; + } + if(strncmp(name, instanceID_code, strlen(instanceID_code))==0) + { + glprogram->builtin_instanceID = id; + return 1; + } + if(strncmp(name, clipplanes_code, strlen(clipplanes_code))==0) { + // it a clip plane! grab it's number + int n = name[strlen(clipplanes_code)]-'0'; // only 6 clip planes, so this works + if(n>=0 && nbuiltin_clipplanes[n] = id; + glprogram->has_builtin_clipplanes = 1; + return 1; + } + } + if(strncmp(name, clipplanes_fpe_code, strlen(clipplanes_fpe_code))==0) { + // it an fpe clip plane! grab it's number + int n = name[strlen(clipplanes_fpe_code)]-'0'; // only 6 clip planes, so this works + if(n>=0 && nbuiltin_clipplanes[n] = id; + glprogram->has_builtin_clipplanes = 1; + return 1; + } + } + if(strncmp(name, fog_code, strlen(fog_code))==0) + { + // it's a Fog parameter + if(strstr(name, "color")) glprogram->builtin_fog.color = id; + else if(strstr(name, "density")) glprogram->builtin_fog.density = id; + else if(strstr(name, "start")) glprogram->builtin_fog.start = id; + else if(strstr(name, "end")) glprogram->builtin_fog.end = id; + else if(strstr(name, "scale")) glprogram->builtin_fog.scale = id; + glprogram->builtin_fog.has = 1; + return 1; + } + if(strncmp(name, point_code, strlen(point_code))==0) + { + // it's a Point parameter + if(strstr(name, ".sizeMin")) glprogram->builtin_pointsprite.sizeMin = id; + else if(strstr(name, ".sizeMax")) glprogram->builtin_pointsprite.sizeMax = id; + else if(strstr(name, ".size")) glprogram->builtin_pointsprite.size = id; + else if(strstr(name, ".fadeThresholdSize")) glprogram->builtin_pointsprite.fadeThresholdSize = id; + else if(strstr(name, ".distanceConstantAttenuation")) glprogram->builtin_pointsprite.distanceConstantAttenuation = id; + else if(strstr(name, ".distanceLinearAttenuation")) glprogram->builtin_pointsprite.distanceLinearAttenuation = id; + else if(strstr(name, ".distanceQuadraticAttenuation")) glprogram->builtin_pointsprite.distanceQuadraticAttenuation = id; + glprogram->builtin_pointsprite.has = 1; + return 1; + } + if(strncmp(name, texenvcolor_code, strlen(texenvcolor_code))==0) { + // it a TexEnvColor! grab it's number + int n = name[strlen(texenvcolor_code)]-'0'; // only 8 Textures max, so this works + if(n>=0 && nbuiltin_texenvcolor[n] = id; + glprogram->has_builtin_texenv = 1; + return 1; + } + } + /*if(strcmp(name, texenvcolor_noa_code)==0) { + // it a TexEnvColor, without the array, so full size + for (int n=0; nbuiltin_texenvcolor[n] = id; + glprogram->has_builtin_texenv = 1; + return 1; + }*/ + if(strncmp(name, texgeneyestart_code, strlen(texgeneyestart_code))==0) { + for (int i=0; i<4; i++) { + char tmp[100]; + sprintf(tmp, texgeneye_code, texgenCoords[i]); + if(strncmp(name, tmp, strlen(tmp))==0) { + // it a TexGen Eye Plane! grab it's number + int n = name[strlen(tmp)]-'0'; // only 8 Textures max, so this works + if(n>=0 && nbuiltin_eye[i][n] = id; + glprogram->has_builtin_texgen = 1; + return 1; + } + } + sprintf(tmp, texgeneye_fpe_code, texgenCoords[i]); + if(strncmp(name, tmp, strlen(tmp))==0) { + // it a TexGen Eye Plane! grab it's number + int n = name[strlen(tmp)]-'0'; // only 8 Textures max, so this works + if(n>=0 && nbuiltin_eye[i][n] = id; + glprogram->has_builtin_texgen = 1; + return 1; + } + } + /*sprintf(tmp, texgeneye_noa_code, texgenCoords[i]); + if(strcmp(name, tmp)==0) { + // it a TexGen Eye Plane without the array + for (int n=0; nbuiltin_eye[i][n] = id; + glprogram->has_builtin_texgen = 1; + return 1; + }*/ + } + } + if(strncmp(name, texgenobjstart_code, strlen(texgenobjstart_code))==0) { + for (int i=0; i<4; i++) { + char tmp[100]; + sprintf(tmp, texgenobj_code, texgenCoords[i]); + if(strncmp(name, tmp, strlen(tmp))==0) { + // it a TexGen Object Plane! grab it's number + int n = name[strlen(tmp)]-'0'; // only 8 Textures max, so this works + if(n>=0 && nbuiltin_obj[i][n] = id; + glprogram->has_builtin_texgen = 1; + return 1; + } + } + sprintf(tmp, texgenobj_fpe_code, texgenCoords[i]); + if(strncmp(name, tmp, strlen(tmp))==0) { + // it a TexGen Object Plane! grab it's number + int n = name[strlen(tmp)]-'0'; // only 8 Textures max, so this works + if(n>=0 && nbuiltin_obj[i][n] = id; + glprogram->has_builtin_texgen = 1; + return 1; + } + } + /*sprintf(tmp, texgenobj_noa_code, texgenCoords[i]); + if(strcmp(name, tmp)==0) { + // it a TexGen Object Plane without the array + for (int n=0; nbuiltin_obj[i][n] = id; + glprogram->has_builtin_texgen = 1; + return 1; + }*/ + } + } + // fpe specials + // alpha ref + if(strcmp(name, alpharef_code)==0) { + glprogram->fpe_alpharef = id; + glprogram->has_fpe = 1; + return 1; + } + // texture sampler + if(strncmp(name, fpetexSampler_code, strlen(fpetexSampler_code))==0) { + // it a Texture Sampler! grab it's number + int n = name[strlen(fpetexSampler_code)]-'0'; // only 8 Textures max, so this works + if(n>=0 && nbuiltin_texsampler[n] = id; + glprogram->has_builtin_texsampler = 1; + return 1; + } + } + // texture env color + if(strncmp(name, texenvcolor_fpe_code, strlen(texenvcolor_fpe_code))==0) { + // it a Texture env color + int n = name[strlen(texenvcolor_fpe_code)]-'0'; // only 8 Textures max, so this works + if(n>=0 && nbuiltin_texenvcolor[n] = id; + glprogram->has_builtin_texenv = 1; + return 1; + } + } + // texture env rgb/alpha scale + if(strncmp(name, fpetexenvRGBScale_code, strlen(fpetexenvRGBScale_code))==0) { + // it a Texture env color + int n = name[strlen(fpetexenvRGBScale_code)]-'0'; // only 8 Textures max, so this works + if(n>=0 && nbuiltin_texenvrgbscale[n] = id; + glprogram->has_builtin_texenv = 1; + return 1; + } + } + if(strncmp(name, fpetexenvAlphaScale_code, strlen(fpetexenvAlphaScale_code))==0) { + // it a Texture env color + int n = name[strlen(fpetexenvAlphaScale_code)]-'0'; // only 8 Textures max, so this works + if(n>=0 && nbuiltin_texenvalphascale[n] = id; + glprogram->has_builtin_texenv = 1; + return 1; + } + } + if(strncmp(name, fpetexAdjust_code, strlen(fpetexAdjust_code))==0) { + // it a Texture env color + int n = name[strlen(fpetexAdjust_code)]-'0'; // only 8 Textures max, so this works + if(n>=0 && nbuiltin_texadjust[n] = id; + glprogram->has_builtin_texadjust = 1; + return 1; + } + } + + + return 0; +} + +int builtin_CheckVertexAttrib(program_t *glprogram, char* name, GLint id) { + if(strncmp(name, gl4es_code, strlen(gl4es_code))) + return 0; // doesn't start with "_gl4es_", no need to look further + int builtin = isBuiltinAttrib(name); + if(builtin!=-1) { + glprogram->builtin_attrib[builtin] = id; + glprogram->has_builtin_attrib = 1; + return 1; + } + return 0; +} diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/fpe.h b/Projects/Android/jni/SupportLibs/gl4es/src/gl/fpe.h new file mode 100644 index 0000000..efb512c --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/fpe.h @@ -0,0 +1,203 @@ +#ifndef _GL4ES_FPE_H_ +#define _GL4ES_FPE_H_ + +/* + This is the FPE : Fixed Pipeline Emulator + + It task is to create a shader that emulate the fixed pipeline. + + So based on the current GL State, it will either take a shader from the cache or create a new one + For conveniance, the relevant GL states element are condenced in a bitfield packed fpe_state_t structure + +*/ + +#include "gles.h" +#include "program.h" + +#define FPE_FOG_EXP 0 +#define FPE_FOG_EXP2 1 +#define FPE_FOG_LINEAR 2 + +#define FPE_FOG_SRC_DEPTH 0 +#define FPE_FOG_SRC_COORD 1 + +#define FPE_TEX_OFF 0 +#define FPE_TEX_2D 1 +#define FPE_TEX_RECT 2 +#define FPE_TEX_3D 3 +#define FPE_TEX_CUBE 4 +#define FPE_TEX_STRM 5 + +#define FPE_ALWAYS 0 +#define FPE_NEVER 1 +#define FPE_LESS 2 +#define FPE_EQUAL 3 +#define FPE_LEQUAL 4 +#define FPE_GREATER 5 +#define FPE_NOTEQUAL 6 +#define FPE_GEQUAL 7 + +#define FPE_CM_AMBIENTDIFFUSE 0 +#define FPE_CM_EMISSION 1 +#define FPE_CM_AMBIENT 2 +#define FPE_CM_DIFFUSE 3 +#define FPE_CM_SPECULAR 4 + +#define FPE_MODULATE 0 +#define FPE_ADD 1 +#define FPE_DECAL 2 +#define FPE_BLEND 3 +#define FPE_REPLACE 4 +#define FPE_COMBINE 5 +#define FPE_COMBINE4 6 + +#define FPE_CR_REPLACE 0 +#define FPE_CR_MODULATE 1 +#define FPE_CR_ADD 2 +#define FPE_CR_ADD_SIGNED 3 +#define FPE_CR_INTERPOLATE 4 +#define FPE_CR_SUBTRACT 5 +#define FPE_CR_DOT3_RGB 6 +#define FPE_CR_DOT3_RGBA 7 +#define FPE_CR_MOD_ADD 8 +#define FPE_CR_MOD_ADD_SIGNED 9 +#define FPE_CR_MOD_SUB 10 + +#define FPE_SRC_TEXTURE 0 +#define FPE_SRC_TEXTURE0 1 +#define FPE_SRC_TEXTURE1 2 +#define FPE_SRC_TEXTURE2 3 +#define FPE_SRC_TEXTURE3 4 +#define FPE_SRC_TEXTURE4 5 +#define FPE_SRC_TEXTURE5 6 +#define FPE_SRC_TEXTURE6 7 +#define FPE_SRC_TEXTURE7 8 +#define FPE_SRC_CONSTANT 9 +#define FPE_SRC_PRIMARY_COLOR 10 +#define FPE_SRC_PREVIOUS 11 +#define FPE_SRC_ZERO 12 +#define FPE_SRC_ONE 13 +#define FPE_SRC_SECONDARY_COLOR 14 + +#define FPE_OP_ALPHA 0 +#define FPE_OP_MINUSALPHA 1 +#define FPE_OP_SRCCOLOR 2 +#define FPE_OP_MINUSCOLOR 3 + +#define FPE_TEX_RGBA 0 +#define FPE_TEX_RGB 1 +#define FPE_TEX_INTENSITY 2 +#define FPE_TEX_LUM_ALPHA 3 +#define FPE_TEX_LUM 4 +#define FPE_TEX_ALPHA 5 +#define FPE_TEX_DEPTH 6 + +#define FPE_TG_EYELINEAR 0 +#define FPE_TG_OBJLINEAR 1 +#define FPE_TG_SPHEREMAP 2 +#define FPE_TG_NORMALMAP 3 +#define FPE_TG_REFLECMAP 4 +#define FPE_TG_NONE 5 // dummy, to help fpe + +typedef struct { + uint32_t texsrcrgb[4]; // 8 texenv src rgb n (SRC_n_RGB is 4 bits) + uint32_t texsrcalpha[4]; // 8 texenv src alpha n (SRC_n_ALPHA is 4 bits) + uint8_t texcombine[8]; // 8 texture combined (RGB as lower 4 bits, A as higher 4 bits) + uint16_t texoprgb[4]; // 8 texenv src op (OPERATION_n_RGB is 2 bits) + uint8_t texopalpha[4]; // 8 texenv src op (OPERATION_n_ALPHA is 1 bits) + uint8_t texrgbscale; // 8 flags if RGB_SCALE for texture is != 1.0 + uint8_t texalphascale; // 8 flags if ALPHA_SCALE for texture is != 1.0 + uint8_t light; // 8 lights packed + uint8_t light_cutoff180; // 8 lights cutoff!=180 flags + uint8_t light_direction; // 8 lights position[3].w==0 flags + uint8_t textmat; // 8 flags if texture matrix is not identity + uint8_t texadjust; // 8 flags if texture need adjustement + unsigned int textype:24; // 8 textures type stored on 3 bits + unsigned int texformat:24; // 8 textures (simplified) internal format on 3 bits + unsigned int texenv:24; // 8 texenv flags, each stored on 3bits + uint8_t texgen_s; // 8 texgen S enabled on 1 bit + unsigned int texgen_s_mode:24; // 8 texgen S on 3 bits + uint8_t texgen_t; // 8 texgen S enabled on 1 bit + unsigned int texgen_t_mode:24; // 8 texgen T on 3 bits + uint8_t texgen_r; // 8 texgen S enabled on 1 bit + unsigned int texgen_r_mode:24; // 8 texgen R on 3 bits + uint8_t texgen_q; // 8 texgen S enabled on 1 bit + unsigned int texgen_q_mode:24; // 8 texgen Q on 3 bits + unsigned int plane:6; // 6 planes packed + unsigned int fogmode:2; // fog mode + unsigned int fogsource:1; // fog source + unsigned int fog:1; // Fog enabled or not + unsigned int colorsum:1; // secondary color enabled + unsigned int lighting:1; // global lighting enabled + unsigned int normalize:1; // normalization + unsigned int rescaling:1; // rescale normal + unsigned int alphafunc:3; // alpha functions + unsigned int alphatest:1; // alpha test + unsigned int twosided:1; // lightmodel: two sided + unsigned int color_material:1; // color material enabled + unsigned int cm_front_mode:3; // front color material mode + unsigned int cm_back_mode:3; // back color material mode + unsigned int cm_front_nullexp:1; // front material shininess is 0 + unsigned int cm_back_nullexp:1; // back material shininess is 0 + unsigned int light_separate:1; // light separate specular color + unsigned int light_localviewer:1; // light local viewer + unsigned int point:1; // point rendering + unsigned int pointsprite:1; // point sprite rendering + unsigned int pointsprite_coord:1; // point sprite coord replace + unsigned int pointsprite_upper:1; // if coord is upper left and not lower left +}__attribute__((packed)) fpe_state_t; + +typedef struct { + GLuint frag, vert, prog; // shader info + fpe_state_t state; // state relevent to the current fpe program + program_t *glprogram; +} fpe_fpe_t; + +typedef struct { + void *cache; + fpe_fpe_t *fpe; +} fpe_cache_t; + +KHASH_MAP_DECLARE_INT(fpecachelist, fpe_cache_t *); + +fpe_fpe_t *fpe_GetCache(); +void fpe_disposeCache(fpe_cache_t* cache, int freeprog); + +void fpe_glEnableClientState(GLenum cap); +void fpe_glDisableClientState(GLenum cap); +void fpe_glMultiTexCoord4f(GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q); +void fpe_glSecondaryColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +void fpe_glVertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +void fpe_glColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +void fpe_glNormalPointer(GLenum type, GLsizei stride, const GLvoid *pointer); +void fpe_glTexCoordPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +void fpe_glFogCoordPointer(GLenum type, GLsizei stride, const GLvoid *pointer); +void fpe_glEnable(GLenum cap); +void fpe_glDisable(GLenum cap); +void fpe_glDrawArrays(GLenum mode, GLint first, GLsizei count); +void fpe_glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices); +void fpe_glColor4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); +void fpe_glNormal3f(GLfloat nx, GLfloat ny, GLfloat nz); +void fpe_glClientActiveTexture(GLenum texture); +void fpe_glFogfv(GLenum pname, const GLfloat* params); +void fpe_glAlphaFunc(GLenum func, GLclampf ref); + +void fpe_glMatrixMode(GLenum mode); + +void fpe_glLightModelf(GLenum pname, GLfloat param); +void fpe_glLightModelfv(GLenum pname, const GLfloat* params); +void fpe_glLightfv(GLenum light, GLenum pname, const GLfloat* params); +void fpe_glMaterialfv(GLenum face, GLenum pname, const GLfloat *params); +void fpe_glMaterialf(GLenum face, GLenum pname, const GLfloat param); + +void fpe_glPointParameterfv(GLenum pname, const GLfloat * params); +void fpe_glPointSize(GLfloat size); + +void builtin_Init(program_t *glprogram); +int builtin_CheckUniform(program_t *glprogram, char* name, GLint id, int size); +int builtin_CheckVertexAttrib(program_t *glprogram, char* name, GLint id); + +void realize_glenv(int ispoint, int first, int count, GLenum type, const void* indices, void** scratch); +void realize_blitenv(int alpha); + +#endif // _GL4ES_FPE_H_ diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/fpe_shader.c b/Projects/Android/jni/SupportLibs/gl4es/src/gl/fpe_shader.c new file mode 100644 index 0000000..b9fd66d --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/fpe_shader.c @@ -0,0 +1,1203 @@ +#include "fpe_shader.h" + +#include + +#include "string_utils.h" +#include "init.h" +#include "../glx/hardext.h" + +//#define DEBUG +#ifdef DEBUG +#define DBG(a) a +#else +#define DBG(a) +#endif + +const char* fpeshader_signature = "// FPE_Shader generated\n"; + +static char* shad = NULL; +static int shad_cap = 0; + +static int comments = 1; + +#define ShadAppend(S) shad = Append(shad, &shad_cap, S) + +const char* texvecsize[] = {"vec2", "vec2", "vec2", "vec3", "vec2"}; +const char* texxyzsize[] = {"xy", "xy", "xy", "xyz", "xy"}; +// 2D Rectangle 3D CubeMap Stream +const char* texname[] = {"texture2D", "texture2D", "texture2D", "textureCube", "textureStreamIMG"}; // textureRectange and 3D are emulated with 2D +const char* texsampler[] = {"sampler2D", "sampler2D", "sampler2D", "samplerCube", "samplerStreamIMG"}; +int texnsize[] = {2, 2, 3, 3, 2}; +const char texcoordname[] = {'s', 't', 'r', 'q'}; +const char texcoordNAME[] = {'S', 'T', 'R', 'Q'}; +const char texcoordxy[] = {'x', 'y', 'z', 'w'}; + +const char* gl4es_alphaRefSource = "uniform float _gl4es_AlphaRef;\n"; + +const char* fpe_texenvSrc(int src, int tmu, int twosided) { + static char buff[200]; + switch(src) { + case FPE_SRC_TEXTURE: + sprintf(buff, "texColor%d", tmu); + break; + case FPE_SRC_TEXTURE0: + case FPE_SRC_TEXTURE1: + case FPE_SRC_TEXTURE2: + case FPE_SRC_TEXTURE3: + case FPE_SRC_TEXTURE4: + case FPE_SRC_TEXTURE5: + case FPE_SRC_TEXTURE6: + case FPE_SRC_TEXTURE7: + sprintf(buff, "texColor%d", src-FPE_SRC_TEXTURE0); // should check if texture is enabled + break; + case FPE_SRC_CONSTANT: + sprintf(buff, "_gl4es_TextureEnvColor_%d", tmu); + break; + case FPE_SRC_PRIMARY_COLOR: + sprintf(buff, "%s", twosided?"((gl_FrontFacing)?Color:BackColor)":"Color"); + break; + case FPE_SRC_PREVIOUS: + sprintf(buff, "fColor"); + break; + case FPE_SRC_ONE: + sprintf(buff, "vec4(1.0)"); + break; + case FPE_SRC_ZERO: + sprintf(buff, "vec4(0.0)"); + break; + case FPE_SRC_SECONDARY_COLOR: + sprintf(buff, "%s", twosided?"((gl_FrontFacing)?SecColor:SecBackColor)":"SecColor"); + break; + } + return buff; +} + +int fpe_texenvSecondary(fpe_state_t* state) { + // check if one of the texenv need secondary color... + for (int i=0; itextype>>(i*3))&0x7; + if(t) { + int texenv = (state->texenv>>(i*3))&0x07; + if(texenv==FPE_COMBINE) { + int combine_rgb = state->texcombine[i]&0xf; + int src_r[3]; + for (int j=0; j<3; j++) { + src_r[j] = (state->texsrcrgb[j]>>(i*4))&0xf; + } + if(combine_rgb==FPE_CR_DOT3_RGBA) { + src_r[2] = -1; + } else { + if(combine_rgb==FPE_CR_REPLACE) { + src_r[1] = src_r[2] = -1; + } else if (combine_rgb>=FPE_CR_MOD_ADD) { + // need all 3 + } else if (combine_rgb!=FPE_CR_INTERPOLATE) { + src_r[2] = -1; + } + } + if(src_r[0]==FPE_SRC_SECONDARY_COLOR || src_r[1]==FPE_SRC_SECONDARY_COLOR || src_r[2]==FPE_SRC_SECONDARY_COLOR) + return 1; + } + } + } + return 0; +} + +char* fpe_packed(int x, int s, int k) { + static char buff[8][30]; + static int idx = 0; + + idx&=7; + int mask = (1<>=k; + } + return buff[idx++]; +} +char* fpe_binary(int x, int s) { + return fpe_packed(x, s, 1); +} + + +const char* const* fpe_VertexShader(fpe_state_t *state) { + // vertex is first called, so 1st time init is only here + if(!shad_cap) shad_cap = 1024; + if(!shad) shad = (char*)malloc(shad_cap); + int lighting = state->lighting; + int twosided = state->twosided && lighting; + int light_separate = state->light_separate && lighting; + int secondary = (state->colorsum && !(lighting && light_separate)) || fpe_texenvSecondary(state); + int fog = state->fog; + int fogsource = state->fogsource; + int fogmode = state->fogmode; + int color_material = state->color_material && lighting; + int point = state->point; + int pointsprite = state->pointsprite; + int headers = 0; + int planes = state->plane; + char buff[1024]; + int need_vertex = 0; + int need_eyeplane[MAX_TEX][4] = {0}; + int need_objplane[MAX_TEX][4] = {0}; + int need_adjust[MAX_TEX] = {0}; + int need_lightproduct[2][MAX_LIGHT] = {0}; + int cm_front_nullexp = state->cm_front_nullexp; + int cm_back_nullexp = state->cm_back_nullexp; + + strcpy(shad, fpeshader_signature); + + comments = globals4es.comments; + DBG(comments=1-comments;) // When DEBUG is activated, the effect of LIBGL_COMMENTS is reversed + + if(comments) { + sprintf(buff, "// ** Vertex Shader **\n// ligthting=%d (twosided=%d, separate=%d, color_material=%d)\n// secondary=%d, planes=%s\n// texture=%s, point=%d\n", + lighting, twosided, light_separate, color_material, secondary, fpe_binary(planes, 6), fpe_packed(state->textype, 24, 3), point); + ShadAppend(buff); + headers+=CountLine(buff); + } + ShadAppend("varying vec4 Color;\n"); // might be unused... + headers++; + if(planes) { + for (int i=0; i>i)&1) { + sprintf(buff, "uniform highp vec4 _gl4es_ClipPlane_%d;\n", i); + ShadAppend(buff); + ++headers; + sprintf(buff, "varying mediump float clippedvertex_%d;\n", i); + ShadAppend(buff); + ++headers; + } + } + } + if(lighting) { + sprintf(buff, + "struct _gl4es_FPELightSourceParameters1\n" + "{\n" + "%s" + " highp vec4 specular;\n" + " highp vec4 position;\n" + " highp vec3 spotDirection;\n" + " highp float spotExponent;\n" + " highp float spotCosCutoff;\n" + " highp float constantAttenuation;\n" + " highp float linearAttenuation;\n" + " highp float quadraticAttenuation;\n" + "};\n", + (color_material)? + " highp vec4 ambient;\n" + " highp vec4 diffuse;\n" + : "" + ); + ShadAppend(buff); + headers += CountLine(buff); + sprintf(buff, + "struct _gl4es_FPELightSourceParameters0\n" + "{\n" + "%s" + " highp vec4 specular;\n" + " highp vec4 position;\n" + " highp vec3 spotDirection;\n" + " highp float spotExponent;\n" + " highp float spotCosCutoff;\n" + "};\n", + (color_material)? + " highp vec4 ambient;\n" + " highp vec4 diffuse;\n" + : "" + ); + ShadAppend(buff); + headers += CountLine(buff); + + sprintf(buff, + "struct _gl4es_LightProducts\n" + "{\n" + " highp vec4 ambient;\n" + " highp vec4 diffuse;\n" + " highp vec4 specular;\n" + "};\n" + ); + ShadAppend(buff); + headers += CountLine(buff); + + if(!(cm_front_nullexp && color_material)) { + ShadAppend("uniform highp float _gl4es_FrontMaterial_shininess;\n"); + headers++; + } + if(twosided && !(cm_back_nullexp && color_material)) { + ShadAppend("uniform highp float _gl4es_BackMaterial_shininess;\n"); + headers++; + } + if(!(color_material && (state->cm_front_mode==FPE_CM_DIFFUSE || state->cm_front_mode==FPE_CM_AMBIENTDIFFUSE))) { + ShadAppend("uniform highp float _gl4es_FrontMaterial_alpha;\n"); + headers++; + if(twosided) { + ShadAppend("uniform highp float _gl4es_BackMaterial_alpha;\n"); + headers++; + } + } + for(int i=0; ilight&(1<light_direction>>i&1)?1:0, i); + ShadAppend(buff); + headers++; + + sprintf(buff, "uniform _gl4es_LightProducts _gl4es_FrontLightProduct_%d;\n", i); + ShadAppend(buff); + headers++; + + if(twosided) { + sprintf(buff, "uniform _gl4es_LightProducts _gl4es_BackLightProduct_%d;\n", i); + ShadAppend(buff); + headers++; + } + } + } + } + if(twosided) { + ShadAppend("varying vec4 BackColor;\n"); + headers++; + } + if(light_separate || secondary) { + ShadAppend("varying vec4 SecColor;\n"); + headers++; + if(twosided) { + ShadAppend("varying vec4 SecBackColor;\n"); + headers++; + } + } + if(fog) { + ShadAppend("varying float FogF;\n"); + headers++; + if(fogsource==FPE_FOG_SRC_DEPTH && need_vertex<1) + need_vertex = 1; + } + // textures coordinates + for (int i=0; itextype>>(i*3))&0x7; + if(t) { + sprintf(buff, "varying %s _gl4es_TexCoord_%d;\n", texvecsize[t-1], i); + ShadAppend(buff); + headers++; + if(state->textmat&(1<>i)&1) { + sprintf(buff, "clippedvertex_%d = dot(vertex, _gl4es_ClipPlane_%d);\n", i, i); + ShadAppend(buff); + } + } + if(!need_vertex) + need_vertex = 1; + //ShadAppend("gl_Position = clipvertex;\n"); + } + ShadAppend("gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n"); + // initial Color / lighting calculation + if(!lighting) { + ShadAppend("Color = gl_Color;\n"); + if(secondary) { + ShadAppend("SecColor = gl_SecondaryColor;\n"); + } + } else { + if(comments) { + sprintf(buff, "// ColorMaterial On/Off=%d Front = %d Back = %d\n", color_material, state->cm_front_mode, state->cm_back_mode); + ShadAppend(buff); + } + // material emission + char fm_emission[60], fm_ambient[60], fm_diffuse[60], fm_specular[60]; + char bm_emission[60], bm_ambient[60], bm_diffuse[60], bm_specular[60]; + sprintf(fm_emission, "%s", (color_material && state->cm_front_mode==FPE_CM_EMISSION)?"gl_Color":"gl_FrontMaterial.emission"); + sprintf(fm_ambient, "%s", (color_material && (state->cm_front_mode==FPE_CM_AMBIENT || state->cm_front_mode==FPE_CM_AMBIENTDIFFUSE))?"gl_Color":"gl_FrontMaterial.ambient"); + sprintf(fm_diffuse, "%s", (color_material && (state->cm_front_mode==FPE_CM_DIFFUSE || state->cm_front_mode==FPE_CM_AMBIENTDIFFUSE))?"gl_Color.xyz * _gl4es_LightSource_":"_gl4es_FrontLightProduct_"); + sprintf(fm_specular, "%s", (color_material && state->cm_front_mode==FPE_CM_SPECULAR)?"gl_Color.xyz * _gl4es_LightSource_":"_gl4es_FrontLightProduct_"); + if(twosided) { + sprintf(bm_emission, "%s", (color_material && state->cm_back_mode==FPE_CM_EMISSION)?"gl_Color":"gl_BackMaterial.emission"); + sprintf(bm_ambient, "%s", (color_material && (state->cm_back_mode==FPE_CM_AMBIENT || state->cm_back_mode==FPE_CM_AMBIENTDIFFUSE))?"gl_Color":"gl_BackMaterial.ambient"); + sprintf(bm_diffuse, "%s", (color_material && (state->cm_back_mode==FPE_CM_DIFFUSE || state->cm_back_mode==FPE_CM_AMBIENTDIFFUSE))?"gl_Color.xyz * _gl4es_LightSource_":"_gl4es_BackLightProduct_"); + sprintf(bm_specular, "%s", (color_material && state->cm_back_mode==FPE_CM_SPECULAR)?"gl_Color.xyz * _gl4es_LightSource_":"_gl4es_BackLightProduct_"); + } + + if(color_material && + (state->cm_front_mode==FPE_CM_EMISSION + || state->cm_front_mode==FPE_CM_AMBIENT + || state->cm_front_mode==FPE_CM_AMBIENTDIFFUSE + || (twosided && + (state->cm_back_mode==FPE_CM_EMISSION || state->cm_back_mode==FPE_CM_AMBIENT || state->cm_back_mode==FPE_CM_AMBIENTDIFFUSE)))) + { + sprintf(buff, "Color = %s;\n", fm_emission); + ShadAppend(buff); + if(twosided) { + sprintf(buff, "vec4 BackColor = %s;\n", bm_emission); + ShadAppend(buff); + } + sprintf(buff, "Color += %s*gl_LightModel.ambient;\n", fm_ambient); + ShadAppend(buff); + if(twosided) { + sprintf(buff, "BackColor += %s*gl_LightModel.ambient;\n", bm_ambient); + ShadAppend(buff); + } + } else { + ShadAppend("Color = gl_FrontLightModelProduct.sceneColor;\n"); + if(twosided) { + ShadAppend("BackColor = gl_BackLightModelProduct.sceneColor;\n"); + } + } + if(light_separate) { + ShadAppend("SecColor=vec4(0.);\n"); + if(twosided) + ShadAppend("SecBackColor=vec4(0.);\n"); + } + ShadAppend("highp float att;\n"); + ShadAppend("highp float spot;\n"); + ShadAppend("highp vec3 VP;\n"); + ShadAppend("highp float lVP;\n"); + ShadAppend("highp float nVP;\n"); + ShadAppend("highp vec3 aa,dd,ss;\n"); + ShadAppend("highp vec3 hi;\n"); + if(twosided) + ShadAppend("highp vec3 back_aa,back_dd,back_ss;\n"); + need_normal = 1; + for(int i=0; ilight&(1<light_direction>>i&1), (state->light_cutoff180>>i&1)); + ShadAppend(buff); + } + // enabled light i + // att depend on light position w + if((state->light_direction>>i&1)==0) { // flag is 1 if light is has w!=0 + ShadAppend("att = 1.0;\n"); + sprintf(buff, "VP = normalize(_gl4es_LightSource_%d.position.xyz);\n", i); + ShadAppend(buff); + } else { + sprintf(buff, "VP = _gl4es_LightSource_%d.position.xyz - vertex.xyz;\n", i); + ShadAppend(buff); + ShadAppend("lVP = length(VP);\n"); + sprintf(buff, "att = 1.0/(_gl4es_LightSource_%d.constantAttenuation + lVP*(_gl4es_LightSource_%d.linearAttenuation + _gl4es_LightSource_%d.quadraticAttenuation * lVP));\n", i, i, i); + ShadAppend(buff); + ShadAppend("VP = normalize(VP);\n"); + if(!need_vertex) need_vertex=1; + } + // spot depend on spotlight cutoff angle + if((state->light_cutoff180>>i&1)==0) { + //ShadAppend("spot = 1.0;\n"); + } else { + /*if((state->light_direction>>i&1)==0) { + sprintf(buff, "spot = max(dot(-normalize(vertex.xyz), _gl4es_LightSource_%d.spotDirection), 0.);\n", i); + if(!need_vertex) need_vertex=1; + } else*/ { + sprintf(buff, "spot = max(dot(-VP, _gl4es_LightSource_%d.spotDirection), 0.);\n", i); + } + ShadAppend(buff); + sprintf(buff, "if(spot<_gl4es_LightSource_%d.spotCosCutoff) spot=0.0; else spot=pow(spot, _gl4es_LightSource_%d.spotExponent);\n", i, i); + ShadAppend(buff); + ShadAppend("att *= spot;\n"); + } + if(color_material && (state->cm_front_mode==FPE_CM_AMBIENT || state->cm_front_mode==FPE_CM_AMBIENTDIFFUSE)) { + sprintf(buff, "aa = %s.xyz * _gl4es_LightSource_%d.ambient.xyz;\n", fm_ambient, i); + ShadAppend(buff); + } else { + sprintf(buff, "aa = _gl4es_FrontLightProduct_%d.ambient.xyz;\n", i); + ShadAppend(buff); + need_lightproduct[0][i] = 1; + } + if(twosided) { + if(color_material && (state->cm_back_mode==FPE_CM_AMBIENT || state->cm_back_mode==FPE_CM_AMBIENTDIFFUSE)) { + sprintf(buff, "back_aa = %s.xyz * _gl4es_LightSource_%d.ambient.xyz;\n", bm_ambient, i); + ShadAppend(buff); + } else { + sprintf(buff, "back_aa = _gl4es_BackLightProduct_%d.ambient.xyz;\n", i); + ShadAppend(buff); + need_lightproduct[1][i] = 1; + } + } + sprintf(buff, "nVP = dot(normal, VP);\n"); + ShadAppend(buff); + sprintf(buff, "dd = (nVP>0.)?(nVP * %s%d.diffuse.xyz):vec3(0.);\n", fm_diffuse, i); + ShadAppend(buff); + need_lightproduct[0][i] = 1; + if(twosided) { + sprintf(buff, "back_dd = (nVP<0.)?(-nVP * %s%d.diffuse.xyz):vec3(0.);\n", bm_diffuse, i); + ShadAppend(buff); + need_lightproduct[1][i] = 1; + } + if(state->light_localviewer) { + ShadAppend("hi = normalize(VP + normalize(-vertex.xyz));\n"); + if(!need_vertex) need_vertex=1; + } else { + ShadAppend("hi = normalize(VP + vec3(0., 0., 1.));\n"); + } + ShadAppend("lVP = dot(normal, hi);\n"); + if(cm_front_nullexp) + sprintf(buff, "ss = (nVP>0. && lVP>0.)?(pow(lVP, %s)*%s%d.specular.xyz):vec3(0.);\n", (color_material)?"gl_FrontMaterial.shininess":"_gl4es_FrontMaterial_shininess", fm_specular, i); + else + sprintf(buff, "ss = (nVP>0. && lVP>0.)?(%s%d.specular.xyz):vec3(0.);\n", fm_specular, i); + ShadAppend(buff); + if(twosided) { + if(state->cm_back_nullexp) // 1, exp is not null + sprintf(buff, "back_ss = (nVP<0. && lVP<0.)?(pow(-lVP, %s)*%s%d.specular.xyz):vec3(0.);\n", (color_material)?"gl_BackMaterial.shininess":"_gl4es_BackMaterial_shininess", bm_specular, i); + else + sprintf(buff, "back_ss = (nVP<0. && lVP<0.)?(%s%d.specular.xyz):vec3(0.);\n", bm_specular, i); + ShadAppend(buff); + } + if(state->light_separate) { + ShadAppend("Color.rgb += att*(aa+dd);\n"); + ShadAppend("SecColor.rgb += att*(ss);\n"); + if(twosided) { + ShadAppend("BackColor.rgb += att*(back_aa+back_dd);\n"); + ShadAppend("SecBackColor.rgb += att*(back_ss);\n"); + } + } else { + ShadAppend("Color.rgb += att*(aa+dd+ss);\n"); + if(twosided) + ShadAppend("BackColor.rgb += att*(back_aa+back_dd+back_ss);\n"); + } + if(comments) { + sprintf(buff, "// end of light %d\n", i); + ShadAppend(buff); + } + } + } + sprintf(buff, "Color.a = %s;\n", (color_material && (state->cm_front_mode==FPE_CM_DIFFUSE || state->cm_front_mode==FPE_CM_AMBIENTDIFFUSE))?"gl_Color.a":"_gl4es_FrontMaterial_alpha"); + ShadAppend(buff); + ShadAppend("Color.rgb = clamp(Color.rgb, 0., 1.);\n"); + if(twosided) { + sprintf(buff, "BackColor.a = %s;\n", (color_material && (state->cm_back_mode==FPE_CM_DIFFUSE || state->cm_back_mode==FPE_CM_AMBIENTDIFFUSE))?"gl_Color.a":"_gl4es_BackMaterial_alpha"); + ShadAppend("BackColor.rgb = clamp(BackColor.rgb, 0., 1.);\n"); + ShadAppend(buff); + } + if(state->light_separate) { + ShadAppend("SecColor.rgb = clamp(SecColor.rgb, 0., 1.);\n"); + if(twosided) { + ShadAppend("SecBackColor.rgb = clamp(SecBackColor.rgb, 0., 1.);\n"); + } + } + } + // calculate texture coordinates + if(comments) + ShadAppend("// texturing\n"); + if(state->texgen_s || state->texgen_t || state->texgen_r || state->texgen_q) + ShadAppend("vec4 tmp_tcoor;\n"); + int spheremap = 0; + int reflectmap = 0; + if(state->textmat) + ShadAppend("vec4 tmp_tex;\n"); + for (int i=0; itextype>>(i*3))&0x7; + int mat = state->textmat&(1<texadjust&(1<texgen_s&(1<texgen_t&(1<texgen_r&(1<texgen_q&(1<texgen_s_mode>>(i*3)&7); else tg[0] = FPE_TG_NONE; + if(tg[1]) tg[1] = (state->texgen_t_mode>>(i*3)&7); else tg[1] = FPE_TG_NONE; + if(tg[2]) tg[2] = (state->texgen_r_mode>>(i*3)&7); else tg[2] = FPE_TG_NONE; + if(tg[3]) tg[3] = (state->texgen_q_mode>>(i*3)&7); else tg[3] = FPE_TG_NONE; + if(comments) { + sprintf(buff, "// texgen %d / %d / %d / %d\n", tg[0], tg[1], tg[2], tg[3]); + ShadAppend(buff); + } + sprintf(texcoord, "tmp_tcoor"); + ShadAppend("tmp_tcoor=vec4(0., 0., 0., 1.);\n"); + if(mat) { + ntc = 4; + } + for (int j=0; jrescaling) + strcpy(buff, "vec3 normal = gl_NormalScale*(gl_NormalMatrix * gl_Normal);\n"); + else + strcpy(buff, "vec3 normal = gl_NormalMatrix * gl_Normal;\n"); + if(state->normalize) + strcat(buff, "normal = normalize(normal);\n"); +#else +// Implementions may choose to normalize for rescale... + if(state->rescaling || state->normalize) + strcpy(buff, "vec3 normal = normalize(gl_NormalMatrix * gl_Normal);\n"); + else + strcpy(buff, "vec3 normal = gl_NormalMatrix * gl_Normal;\n"); +#endif + shad = ResizeIfNeeded(shad, &shad_cap, strlen(buff)); + InplaceInsert(GetLine(shad, normal_line + headers), buff); + } + buff[0] = '\0'; + for (int i=0; ilighting; + int twosided = state->twosided && lighting; + int light_separate = state->light_separate && lighting; + int secondary = (state->colorsum && !(lighting && light_separate)) || fpe_texenvSecondary(state); + int alpha_test = state->alphatest; + int alpha_func = state->alphafunc; + int fog = state->fog; + int fogsource = state->fogsource; + int fogmode = state->fogmode; + int planes = state->plane; + int point = state->point; + int pointsprite = state->pointsprite; + int pointsprite_coord = state->pointsprite_coord; + int pointsprite_upper = state->pointsprite_upper; + int texenv_combine = 0; + char buff[1024]; + + strcpy(shad, fpeshader_signature); + + // check texture streaming + { + int need_stream = 0; + for (int i=0; itextype>>(i*3))&0x7; + if(t==FPE_TEX_STRM) + need_stream = 1; + } + if(need_stream) + ShadAppend("#extension GL_IMG_texture_stream2 : enable\n"); + } + + if(comments) { + sprintf(buff, "// ** Fragment Shader **\n// lighting=%d, alpha=%d, secondary=%d, planes=%s, textype=%s, texformat=%s point=%d\n", lighting, alpha_test, secondary, fpe_binary(planes, 6), fpe_packed(state->textype, 24, 3), fpe_packed(state->texformat, 24, 3), point); + ShadAppend(buff); + headers+=CountLine(buff); + } + ShadAppend("varying vec4 Color;\n"); + headers++; + if(twosided) { + ShadAppend("varying vec4 BackColor;\n"); + headers++; + } + if(light_separate || secondary) { + ShadAppend("varying vec4 SecColor;\n"); + headers++; + if(twosided) { + ShadAppend("varying vec4 SecBackColor;\n"); + headers++; + } + } + if(fog) { + ShadAppend("varying float FogF;\n"); + headers++; + } + if(planes) { + //ShadAppend("varying vec4 clipvertex;\n"); + for (int i=0; i>i)&1) { + sprintf(buff, "varying mediump float clippedvertex_%d;\n", i); + ShadAppend(buff); + headers++; + } + } + } + /*if(fog && fogsource==FPE_FOG_SRC_COORD) { + ShadAppend("varying float FogCoord;\n"); + headers++; + }*/ + // textures coordinates + for (int i=0; itextype>>(i*3))&0x7; + if(point && !pointsprite) t=0; + if(t) { + sprintf(buff, "varying %s _gl4es_TexCoord_%d;\n", texvecsize[t-1], i); + ShadAppend(buff); + sprintf(buff, "uniform %s _gl4es_TexSampler_%d;\n", texsampler[t-1], i); + ShadAppend(buff); + headers++; + + int texenv = (state->texenv>>(i*3))&0x07; + if (texenv>=FPE_COMBINE) { + int n = 1+texenv-FPE_COMBINE; + if(n>texenv_combine) texenv_combine=n; + if((state->texrgbscale>>i)&1) { + sprintf(buff, "uniform float _gl4es_TexEnvRGBScale_%d;\n", i); + ShadAppend(buff); + headers++; + } + if((state->texalphascale>>i)&1) { + sprintf(buff, "uniform float _gl4es_TexEnvAlphaScale_%d;\n", i); + ShadAppend(buff); + headers++; + } + } + } + } + if(alpha_test && alpha_func>FPE_NEVER) { + ShadAppend(gl4es_alphaRefSource); + headers++; + } + + ShadAppend("void main() {\n"); + + //*** Clip Planes (it's probably not the best idea to do that here...) + if(planes) { + ShadAppend("if(("); + int k=0; + for (int i=0; i>i)&1) { + //sprintf(buff, "%smin(0., dot(clipvertex, gl_ClipPlane[%d]))", k?"+":"", i); + sprintf(buff, "%smin(0., clippedvertex_%d)", k?"+":"", i); + ShadAppend(buff); + k=1; + } + } + ShadAppend(")<0.) discard;\n"); + } + + //*** initial color + sprintf(buff, "vec4 fColor = %s;\n", twosided?"(gl_FrontFacing)?Color:BackColor":"Color"); + ShadAppend(buff); + + //*** apply textures + if(state->textype && (!point || pointsprite) ) { + // fetch textures first + for (int i=0; itextype>>(i*3))&0x7; + if(t) { + if(point && pointsprite && pointsprite_coord) { + if(pointsprite_upper) + sprintf(buff, "vec4 texColor%d = %s(_gl4es_TexSampler_%d, vec2(gl_PointCoord.x, 1.-gl_PointCoord.y));\n", i, texname[t-1], i); + else + sprintf(buff, "vec4 texColor%d = %s(_gl4es_TexSampler_%d, gl_PointCoord);\n", i, texname[t-1], i); + } else + sprintf(buff, "vec4 texColor%d = %s(_gl4es_TexSampler_%d, _gl4es_TexCoord_%d);\n", i, texname[t-1], i, i); + ShadAppend(buff); + } + } + + // TexEnv stuff + if(texenv_combine>0) { + if(texenv_combine==2) + ShadAppend("vec4 Arg0, Arg1, Arg2, Arg3;\n"); + else + ShadAppend("vec4 Arg0, Arg1, Arg2;\n"); + } + // fetch textures first + for (int i=0; itextype>>(i*3))&0x7; + if(t) { + int texenv = (state->texenv>>(i*3))&0x07; + int texformat = (state->texformat>>(i*3))&0x07; + if(comments) { + sprintf(buff, "// Texture %d active: %X, texenv=%X, format=%X\n", i, t, texenv, texformat); + ShadAppend(buff); + } + int needclamp = 1; + switch (texenv) { + case FPE_MODULATE: + if(texformat==FPE_TEX_RGB || texformat==FPE_TEX_LUM) { + sprintf(buff, "fColor.rgb *= texColor%d.rgb;\n", i); + ShadAppend(buff); + } else if(texformat==FPE_TEX_ALPHA) { + sprintf(buff, "fColor.a *= texColor%d.a;\n", i); + ShadAppend(buff); + } else { + sprintf(buff, "fColor *= texColor%d;\n", i); + ShadAppend(buff); + } + needclamp = 0; + break; + case FPE_ADD: + if(texformat!=FPE_TEX_ALPHA) { + sprintf(buff, "fColor.rgb += texColor%d.rgb;\n", i); + ShadAppend(buff); + } + if(texformat==FPE_TEX_INTENSITY || texformat==FPE_TEX_DEPTH) + sprintf(buff, "fColor.a += texColor%d.a;\n", i); + else + sprintf(buff, "fColor.a *= texColor%d.a;\n", i); + ShadAppend(buff); + break; + case FPE_DECAL: + sprintf(buff, "fColor.rgb = mix(fColor.rgb, texColor%d.rgb, texColor%d.a);\n", i, i); + ShadAppend(buff); + needclamp = 0; + break; + case FPE_BLEND: + // create the Uniform for TexEnv Constant color + sprintf(buff, "uniform lowp vec4 _gl4es_TextureEnvColor_%d;\n", i); + shad = ResizeIfNeeded(shad, &shad_cap, strlen(buff)); + InplaceInsert(GetLine(shad, headers), buff); + headers+=CountLine(buff); + needclamp=0; + if(texformat!=FPE_TEX_ALPHA) { + sprintf(buff, "fColor.rgb = mix(fColor.rgb, _gl4es_TextureEnvColor_%d.rgb, texColor%d.rgb);\n", i, i); + ShadAppend(buff); + } + switch(texformat) { + case FPE_TEX_LUM: + case FPE_TEX_RGB: + // no change in alpha channel + break; + case FPE_TEX_INTENSITY: + case FPE_TEX_DEPTH: + sprintf(buff, "fColor.a = mix(fColor.a, _gl4es_TextureEnvColor_%d.a, texColor%d.a);\n", i, i); + ShadAppend(buff); + break; + default: + sprintf(buff, "fColor.a *= texColor%d.a;\n", i); + ShadAppend(buff); + } + ShadAppend(buff); + break; + case FPE_REPLACE: + if(texformat==FPE_TEX_RGB || texformat==FPE_TEX_LUM) { + sprintf(buff, "fColor.rgb = texColor%d.rgb;\n", i); + ShadAppend(buff); + } else if(texformat==FPE_TEX_ALPHA) { + sprintf(buff, "fColor.a = texColor%d.a;\n", i); + ShadAppend(buff); + } else { + sprintf(buff, "fColor = texColor%d;\n", i); + ShadAppend(buff); + } + break; + case FPE_COMBINE: + case FPE_COMBINE4: + { + int constant = 0; + // parse the combine state + int combine_rgb = state->texcombine[i]&0xf; + int combine_alpha = (state->texcombine[i]>>4)&0xf; + int src_r[4], op_r[4]; + int src_a[4], op_a[4]; + for (int j=0; j<4; j++) { + src_a[j] = (state->texsrcalpha[j]>>(i*4))&0xf; + op_a[j] = (state->texopalpha[j]>>i)&1; + src_r[j] = (state->texsrcrgb[j]>>(i*4))&0xf; + op_r[j] = (state->texoprgb[j]>>(i*2))&3; + } + if(combine_rgb==FPE_CR_DOT3_RGBA) { + src_a[0] = src_a[1] = src_a[2] = -1; + op_a[0] = op_a[1] = op_a[2] = -1; + src_r[2] = op_r[2] = -1; + src_r[3] = op_r[3] = -1; + src_a[3] = op_a[3] = -1; + } else { + if(combine_alpha==FPE_CR_REPLACE) { + src_a[1] = src_a[2] = src_a[3] = -1; + op_a[1] = op_a[2] = op_a[3] = -1; + } else if (combine_alpha>=FPE_CR_MOD_ADD || combine_alpha==FPE_CR_INTERPOLATE) { + // need all 3 + src_a[3] = -1; op_a[3] = -1; + } else { + if(texenv==FPE_COMBINE4 && (combine_alpha==FPE_CR_ADD || combine_alpha==FPE_CR_ADD_SIGNED)) { + // need all 4 + } else { + src_a[2] = src_a[3] = -1; + op_a[2] = op_a[3] = -1; + } + } + if(combine_rgb==FPE_CR_REPLACE) { + src_r[1] = src_r[2] = src_r[3] = -1; + op_r[1] = op_r[2] = op_r[3] = -1; + } else if (combine_rgb>=FPE_CR_MOD_ADD || combine_rgb==FPE_CR_INTERPOLATE) { + // need all 3 + src_r[3] = -1; op_r[3] = -1; + } else { + if(texenv==FPE_COMBINE4 && (combine_rgb==FPE_CR_ADD || combine_rgb==FPE_CR_ADD_SIGNED)) { + // need all 4 + } else { + src_r[2] = src_r[3] = -1; + op_r[2] = op_r[3] = -1; + } + } + } + // is texture constants needed ? + for (int j=0; j<4; j++) { + if (src_a[j]==FPE_SRC_CONSTANT || src_r[j]==FPE_SRC_CONSTANT) + constant=1; + } + if(comments) { + sprintf(buff, " // Combine RGB: fct=%d, Src/Op: 0=%d/%d 1=%d/%d 2=%d/%d 3=%d/%d\n", combine_rgb, src_r[0], op_r[0], src_r[1], op_r[1], src_r[2], op_r[2], src_r[3], op_r[3]); + ShadAppend(buff); + sprintf(buff, " // Combine Alpha: fct=%d, Src/Op: 0=%d/%d 1=%d/%d 2=%d/%d 3=%d/%d\n", combine_alpha, src_a[0], op_a[0], src_a[1], op_a[1], src_a[2], op_a[2], src_a[3], op_a[3]); + ShadAppend(buff); + } + if(constant) { + // yep, create the Uniform + sprintf(buff, "uniform lowp vec4 _gl4es_TextureEnvColor_%d;\n", i); + shad = ResizeIfNeeded(shad, &shad_cap, strlen(buff)); + InplaceInsert(GetLine(shad, headers), buff); + headers+=CountLine(buff); + } + for (int j=0; j<4; j++) { + if(op_r[j]!=-1) + switch(op_r[j]) { + case FPE_OP_SRCCOLOR: + sprintf(buff, "Arg%d.rgb = %s.rgb;\n", j, fpe_texenvSrc(src_r[j], i, twosided)); + ShadAppend(buff); + break; + case FPE_OP_MINUSCOLOR: + sprintf(buff, "Arg%d.rgb = vec3(1.) - %s.rgb;\n", j, fpe_texenvSrc(src_r[j], i, twosided)); + ShadAppend(buff); + break; + case FPE_OP_ALPHA: + sprintf(buff, "Arg%d.rgb = vec3(%s.a);\n", j, fpe_texenvSrc(src_r[j], i, twosided)); + ShadAppend(buff); + break; + case FPE_OP_MINUSALPHA: + sprintf(buff, "Arg%d.rgb = vec3(1. - %s.a);\n", j, fpe_texenvSrc(src_r[j], i, twosided)); + ShadAppend(buff); + break; + } + if(op_a[j]!=-1) + switch(op_a[j]) { + case FPE_OP_ALPHA: + sprintf(buff, "Arg%d.a = %s.a;\n", j, fpe_texenvSrc(src_a[j], i, twosided)); + ShadAppend(buff); + break; + case FPE_OP_MINUSALPHA: + sprintf(buff, "Arg%d.a = 1. - %s.a;\n", j, fpe_texenvSrc(src_a[j], i, twosided)); + ShadAppend(buff); + break; + } + } + + switch(combine_rgb) { + case FPE_CR_REPLACE: + ShadAppend("fColor.rgb = Arg0.rgb;\n"); + break; + case FPE_CR_MODULATE: + ShadAppend("fColor.rgb = Arg0.rgb * Arg1.rgb;\n"); + break; + case FPE_CR_ADD: + if(texenv==FPE_COMBINE4) + ShadAppend("fColor.rgb = Arg0.rgb*Arg1.rgb + Arg2.rgb*Arg3.rgb;\n"); + else + ShadAppend("fColor.rgb = Arg0.rgb + Arg1.rgb;\n"); + break; + case FPE_CR_ADD_SIGNED: + if(texenv==FPE_COMBINE4) + ShadAppend("fColor.rgb = Arg0.rgb*Arg1.rgb + Arg2.rgb*Arg3.rgb - vec3(0.5);\n"); + else + ShadAppend("fColor.rgb = Arg0.rgb + Arg1.rgb - vec3(0.5);\n"); + break; + case FPE_CR_INTERPOLATE: + ShadAppend("fColor.rgb = Arg0.rgb*Arg2.rgb + Arg1.rgb*(vec3(1.)-Arg2.rgb);\n"); + break; + case FPE_CR_SUBTRACT: + ShadAppend("fColor.rgb = Arg0.rgb - Arg1.rgb;\n"); + break; + case FPE_CR_DOT3_RGB: + ShadAppend("fColor.rgb = vec3(4.*((Arg0.r-0.5)*(Arg1.r-0.5)+(Arg0.g-0.5)*(Arg1.g-0.5)+(Arg0.b-0.5)*(Arg1.b-0.5)));\n"); + break; + case FPE_CR_DOT3_RGBA: + ShadAppend("fColor = vec4(4.*((Arg0.r-0.5)*(Arg1.r-0.5)+(Arg0.g-0.5)*(Arg1.g-0.5)+(Arg0.b-0.5)*(Arg1.b-0.5)));\n"); + break; + case FPE_CR_MOD_ADD: + ShadAppend("fColor.rgb = Arg0.rgb*Arg2.rgb + Arg1.rgb;\n"); + break; + case FPE_CR_MOD_ADD_SIGNED: + ShadAppend("fColor.rgb = Arg0.rgb*Arg2.rgb + Arg1.rgb - vec3(0.5);\n"); + break; + case FPE_CR_MOD_SUB: + ShadAppend("fColor.rgb = Arg0.rgb*Arg2.rgb - Arg1.rgb;\n"); + break; + } + if(combine_rgb!=FPE_CR_DOT3_RGBA) + switch(combine_alpha) { + case FPE_CR_REPLACE: + ShadAppend("fColor.a = Arg0.a;\n"); + break; + case FPE_CR_MODULATE: + ShadAppend("fColor.a = Arg0.a * Arg1.a;\n"); + break; + case FPE_CR_ADD: + if(texenv==FPE_COMBINE4) + ShadAppend("fColor.a = Arg0.a*Arg1.a + Arg2.a*Arg3.a;\n"); + else + ShadAppend("fColor.a = Arg0.a + Arg1.a;\n"); + break; + case FPE_CR_ADD_SIGNED: + if(texenv==FPE_COMBINE4) + ShadAppend("fColor.a = Arg0.a*Arg1.a + Arg2.a*Arg3.a - 0.5;\n"); + else + ShadAppend("fColor.a = Arg0.a + Arg1.a - 0.5;\n"); + break; + case FPE_CR_INTERPOLATE: + ShadAppend("fColor.a = Arg0.a*Arg2.a + Arg1.a*(1.-Arg2.a);\n"); + break; + case FPE_CR_SUBTRACT: + ShadAppend("fColor.a = Arg0.a - Arg1.a;\n"); + break; + case FPE_CR_MOD_ADD: + ShadAppend("fColor.a = Arg0.a*Arg2.a + Arg1.a;\n"); + break; + case FPE_CR_MOD_ADD_SIGNED: + ShadAppend("fColor.a = Arg0.a*Arg2.a + Arg1.a - 0.5;\n"); + break; + case FPE_CR_MOD_SUB: + ShadAppend("fColor.a = Arg0.a*Arg2.a - Arg1.a;\n"); + break; + } + if((state->texrgbscale>>i)&1) { + sprintf(buff, "fColor.rgb *= _gl4es_TexEnvRGBScale_%d;\n", i); + ShadAppend(buff); + } + if((state->texalphascale>>i)&1) { + sprintf(buff, "fColor.a *= _gl4es_TexEnvAlphaScale_%d;\n", i); + ShadAppend(buff); + } + } + break; + } + if(needclamp) + ShadAppend("fColor = clamp(fColor, 0., 1.);\n"); + } + } + } + //*** Alpha Test + if(alpha_test) { + if(comments) { + sprintf(buff, "// Alpha Test, fct=%X\n", alpha_func); + ShadAppend(buff); + } + if(alpha_func==FPE_ALWAYS) { + // nothing here... + } else if (alpha_func==FPE_NEVER) { + ShadAppend("discard;\n"); // Never pass... + } else { + // FPE_LESS FPE_EQUAL FPE_LEQUAL FPE_GREATER FPE_NOTEQUAL FPE_GEQUAL + // but need to negate the operator + const char* alpha_test_op[] = {">=","!=",">","<=","==","<"}; + sprintf(buff, "if (floor(fColor.a*255.) %s _gl4es_AlphaRef) discard;\n", alpha_test_op[alpha_func-FPE_LESS]); + ShadAppend(buff); + } + } + + //*** Add secondary color + if(light_separate || secondary) { + if(comments) { + sprintf(buff, "// Add Secondary color (%s %s)\n", light_separate?"light":"", secondary?"secondary":""); + ShadAppend(buff); + } + sprintf(buff, "fColor.rgb += (%s).rgb;\n", twosided?"(gl_FrontFacing)?SecColor:SecBackColor":"SecColor"); + ShadAppend(buff); + ShadAppend("fColor.rgb = clamp(fColor.rgb, 0., 1.);\n"); + } + + //*** Fog + if(fog) { + if(comments) { + sprintf(buff, "// Fog On: mode=%X, source=%X\n", fogmode, fogsource); + ShadAppend(buff); + } + ShadAppend("fColor.rgb = mix(gl_Fog.color.rgb, fColor.rgb, FogF);\n"); + } + + //done + ShadAppend("gl_FragColor = fColor;\n"); + ShadAppend("}"); + + DBG(printf("FPE Shader: \n%s\n", shad);) + + return (const char* const*)&shad; +} + +const char* const* fpe_CustomVertexShader(const char* initial, fpe_state_t* state) +{ + if(!shad_cap) shad_cap = 1024; + if(!shad) shad = (char*)malloc(shad_cap); + // nothing here yet... + + strcpy(shad, ""); + ShadAppend(initial); + + return (const char* const*)&shad; +} +const char* const* fpe_CustomFragmentShader(const char* initial, fpe_state_t* state) +{ + if(!shad_cap) shad_cap = 1024; + if(!shad) shad = (char*)malloc(shad_cap); + + int alpha_test = state->alphatest; + int alpha_func = state->alphafunc; + char buff[1024]; + int headline = 3; // version and 2 precision lines + + strcpy(shad, ""); + ShadAppend(initial); + + // only alpha_test trigger a custom custom shader for now + if(alpha_test) { + // wrap real main... + shad = InplaceReplace(shad, &shad_cap, "main", "_gl4es_main"); + } + if(strstr(shad, "_gl4es_main")) { + ShadAppend("void main() {\n"); + ShadAppend(" _gl4es_main();\n"); + + //*** Alpha Test + if(alpha_test) { + if(alpha_test && alpha_func>FPE_NEVER) { + shad = ResizeIfNeeded(shad, &shad_cap, strlen(gl4es_alphaRefSource)); + InplaceInsert(GetLine(shad, headline), gl4es_alphaRefSource); + headline+=CountLine(gl4es_alphaRefSource); + } + if(comments) { + sprintf(buff, "// Alpha Test, fct=%X\n", alpha_func); + ShadAppend(buff); + } + if(alpha_func==FPE_ALWAYS) { + // nothing here... + } else if (alpha_func==FPE_NEVER) { + ShadAppend("discard;\n"); // Never pass... + } else { + // FPE_LESS FPE_EQUAL FPE_LEQUAL FPE_GREATER FPE_NOTEQUAL FPE_GEQUAL + // but need to negate the operator + const char* alpha_test_op[] = {">=","!=",">","<=","==","<"}; + sprintf(buff, "if (floor(gl_FragColor.a*255.) %s _gl4es_AlphaRef) discard;\n", alpha_test_op[alpha_func-FPE_LESS]); + ShadAppend(buff); + } + } + + ShadAppend("}"); + } + + return (const char* const*)&shad; +} diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/fpe_shader.h b/Projects/Android/jni/SupportLibs/gl4es/src/gl/fpe_shader.h new file mode 100644 index 0000000..2b32b24 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/fpe_shader.h @@ -0,0 +1,14 @@ +#ifndef _GL4ES_FPE_SHADER_H_ +#define _GL4ES_FPE_SHADER_H_ + +#include "fpe.h" + +const char* fpeshader_signature; + +const char* const* fpe_VertexShader(fpe_state_t *state); +const char* const* fpe_FragmentShader(fpe_state_t *state); + +const char* const* fpe_CustomVertexShader(const char* initial, fpe_state_t* state); +const char* const* fpe_CustomFragmentShader(const char* initial, fpe_state_t* state); + +#endif // _GL4ES_FPE_SHADER_H_ diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/framebuffers.c b/Projects/Android/jni/SupportLibs/gl4es/src/gl/framebuffers.c new file mode 100644 index 0000000..97b06c4 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/framebuffers.c @@ -0,0 +1,1649 @@ +#include "framebuffers.h" + +#if !defined(ANDROID) && !defined(AMIGAOS4) && !defined(__EMSCRIPTEN__) +#include +#endif +#include "../glx/hardext.h" +#include "blit.h" +#include "debug.h" +#include "fpe.h" +#include "gl4es.h" +#include "glstate.h" +#include "init.h" +#include "loader.h" + +//#define DEBUG +#ifdef DEBUG +#define DBG(a) a +#else +#define DBG(a) +#endif + +KHASH_MAP_IMPL_INT(renderbufferlist_t, glrenderbuffer_t *); +KHASH_MAP_IMPL_INT(framebufferlist_t, glframebuffer_t *); + +//extern void* eglGetProcAddress(const char* name); + +int npot(int n); +int wrap_npot(GLenum wrap); + +glframebuffer_t* find_framebuffer(GLuint framebuffer) { + // Get a framebuffer based on ID + if (framebuffer == 0) return glstate->fbo.fbo_0; // NULL or fbo_0 ? + int ret; + khint_t k; + khash_t(framebufferlist_t) *list = glstate->fbo.framebufferlist; + k = kh_get(framebufferlist_t, list, framebuffer); + + if (k != kh_end(list)){ + return kh_value(list, k); + } + return NULL; +} + +glframebuffer_t* get_framebuffer(GLenum target) { + switch (target) { + case GL_FRAMEBUFFER: return glstate->fbo.current_fb; + case GL_READ_FRAMEBUFFER: return glstate->fbo.fbo_read; + case GL_DRAW_FRAMEBUFFER: return glstate->fbo.fbo_draw; + } + return NULL; +} + + +void readfboBegin() { + if (glstate->fbo.fbo_read == glstate->fbo.fbo_draw) + return; + DBG(printf("readfboBegin, fbo status read=%u, draw=%u, main=%u, current=%u\n", glstate->fbo.fbo_read->id, glstate->fbo.fbo_draw->id, glstate->fbo.mainfbo_fbo, glstate->fbo.current_fb->id);) + if(glstate->fbo.fbo_read==glstate->fbo.current_fb) + return; + glstate->fbo.current_fb = glstate->fbo.fbo_read; + GLuint fbo = glstate->fbo.fbo_read->id; + if (!fbo) + fbo = glstate->fbo.mainfbo_fbo; + LOAD_GLES2_OR_OES(glBindFramebuffer); + gles_glBindFramebuffer(GL_FRAMEBUFFER, fbo); +} + +void readfboEnd() { + if (glstate->fbo.fbo_read->id == glstate->fbo.fbo_draw->id) + return; + DBG(printf("readfboEnd, fbo status read=%u, draw=%u, main=%u, current=%u\n", glstate->fbo.fbo_read, glstate->fbo.fbo_draw, glstate->fbo.mainfbo_fbo, glstate->fbo.current_fb);) + if(glstate->fbo.fbo_draw==glstate->fbo.current_fb) + return; + glstate->fbo.current_fb = glstate->fbo.fbo_draw; + GLuint fbo = glstate->fbo.fbo_draw->id; + if (!fbo) + fbo = glstate->fbo.mainfbo_fbo; + LOAD_GLES2_OR_OES(glBindFramebuffer); + gles_glBindFramebuffer(GL_FRAMEBUFFER, fbo); +} + +glrenderbuffer_t* find_renderbuffer(GLuint renderbuffer) { + // Get a renderbuffer based on ID + if (renderbuffer == 0) return glstate->fbo.default_rb; + int ret; + khint_t k; + khash_t(renderbufferlist_t) *list = glstate->fbo.renderbufferlist; + k = kh_get(renderbufferlist_t, list, renderbuffer); + + if (k != kh_end(list)){ + return kh_value(list, k); + } + return NULL; +} + +void gl4es_glGenFramebuffers(GLsizei n, GLuint *ids) { + DBG(printf("glGenFramebuffers(%i, %p)\n", n, ids);) + LOAD_GLES2_OR_OES(glGenFramebuffers); + GLsizei m = 0; + while(glstate->fbo.old && (glstate->fbo.old->nbr>0) && (n-m>0)) { + DBG(printf("Recycled 1 FBO\n");) + ids[m++] = glstate->fbo.old->fbos[--glstate->fbo.old->nbr]; + } + noerrorShim(); + if(n-m == 0) + return; + errorGL(); + gles_glGenFramebuffers(n-m, ids+m); + + // track the framebuffers... + int ret; + khint_t k; + khash_t(framebufferlist_t) *list = glstate->fbo.framebufferlist; + for(int i=0; iid = ids[i]; + fb->n_draw = 0; // correct? + } +} + +void gl4es_glDeleteFramebuffers(GLsizei n, GLuint *framebuffers) { + DBG(printf("glDeleteFramebuffers(%i, %p), framebuffers[0]=%u\n", n, framebuffers, framebuffers[0]);) + // delete tracking + khint_t k; + if (glstate->fbo.framebufferlist) + for (int i=0; ifbo.framebufferlist, t); + if (k != kh_end(glstate->fbo.framebufferlist)) { + fb = kh_value(glstate->fbo.framebufferlist, k); + // detach texture... + for(int j=0; j<10; ++j) { + if(fb->color[j] && fb->t_color[j]!=GL_RENDERBUFFER) { + gltexture_t *tex = gl4es_getTexture(fb->t_color[j], fb->color[j]); + if(tex) { + tex->binded_fbo = 0; + tex->binded_attachment = 0; + } + } + } + if(fb->depth && fb->t_depth!=GL_RENDERBUFFER) { + gltexture_t *tex = gl4es_getTexture(fb->t_depth, fb->depth); + if(tex) { + tex->binded_fbo = 0; + tex->binded_attachment = 0; + tex->renderdepth = 0; + } + } + if(fb->stencil && fb->t_stencil!=GL_RENDERBUFFER) { + gltexture_t *tex = gl4es_getTexture(fb->t_stencil, fb->stencil); + if(tex) { + tex->binded_fbo = 0; + tex->binded_attachment = 0; + tex->renderstencil = 0; + } + } + free(fb); + kh_del(framebufferlist_t, glstate->fbo.framebufferlist, k); + } + } + } + } + + if (globals4es.recyclefbo) { + DBG(printf("Recycling %i FBOs\n", n);) + noerrorShim(); + if(glstate->fbo.old->cap == 0) { + glstate->fbo.old->cap = 16; + glstate->fbo.old->fbos = (GLuint*)malloc(glstate->fbo.old->cap * sizeof(GLuint)); + } + if (glstate->fbo.old->nbr+n == glstate->fbo.old->cap) { + glstate->fbo.old->cap += n; + glstate->fbo.old->fbos = (GLuint*)realloc(glstate->fbo.old->fbos, glstate->fbo.old->cap *sizeof(GLuint)); + } + memcpy(glstate->fbo.old->fbos+glstate->fbo.old->nbr, framebuffers, n*sizeof(GLuint)); + glstate->fbo.old->nbr += n; + } else { + LOAD_GLES2_OR_OES(glDeleteFramebuffers); + errorGL(); + gles_glDeleteFramebuffers(n, framebuffers); + } +} + +GLboolean gl4es_glIsFramebuffer(GLuint framebuffer) { + DBG(printf("glIsFramebuffer(%u)\n", framebuffer);) + LOAD_GLES2_OR_OES(glIsFramebuffer); + + errorGL(); + return find_framebuffer(framebuffer)!=NULL; +} + +GLenum gl4es_glCheckFramebufferStatus(GLenum target) { + GLenum result; + if(glstate->fbo.internal) { + result = glstate->fbo.fb_status; + noerrorShim(); + } else { + LOAD_GLES2_OR_OES(glCheckFramebufferStatus); + + errorGL(); + result = gles_glCheckFramebufferStatus(target); + } + DBG(printf("glCheckFramebufferStatus(0x%04X)=0x%04X\n", target, result);) + return result; +} + +void gl4es_glBindFramebuffer(GLenum target, GLuint framebuffer) { + DBG(printf("glBindFramebuffer(%s, %u), list=%s, glstate->fbo.current_fb=%d (draw=%d, read=%d)\n", PrintEnum(target), framebuffer, glstate->list.active?"active":"none", glstate->fbo.current_fb->id, glstate->fbo.fbo_draw->id, glstate->fbo.fbo_read->id);) + PUSH_IF_COMPILING(glBindFramebuffer); + LOAD_GLES2_OR_OES(glBindFramebuffer); +// LOAD_GLES2_OR_OES(glCheckFramebufferStatus); + LOAD_GLES(glGetError); + + glframebuffer_t *fb = find_framebuffer(framebuffer); + if(!fb) { + errorShim(GL_INVALID_VALUE); + return; + } + + if (target == GL_FRAMEBUFFER) { + glstate->fbo.fbo_read = fb; + glstate->fbo.fbo_draw = fb; + } + + if (target == GL_READ_FRAMEBUFFER) { + glstate->fbo.fbo_read = fb; + noerrorShim(); + glstate->fbo.fb_status = GL_FRAMEBUFFER_COMPLETE; + glstate->fbo.internal = 1; + return; //don't bind for now + } else glstate->fbo.internal = 0; + + if (target == GL_DRAW_FRAMEBUFFER) { + target = GL_FRAMEBUFFER; + glstate->fbo.fbo_draw = fb; + } + + if (target != GL_FRAMEBUFFER) { + errorShim(GL_INVALID_ENUM); + return; + } + + if(framebuffer==0) + framebuffer = glstate->fbo.mainfbo_fbo; + + glstate->fbo.current_fb = fb; + + gles_glBindFramebuffer(target, framebuffer); + GLenum err=gles_glGetError(); + errorShim(err); + +// glstate->fbo.fb_status = (framebuffer==0)?GL_FRAMEBUFFER_COMPLETE:gles_glCheckFramebufferStatus(target); +} + +GLenum ReadDraw_Push(GLenum target) { + if(target==GL_FRAMEBUFFER) + return GL_FRAMEBUFFER; + LOAD_GLES2_OR_OES(glBindFramebuffer); + if(target==GL_DRAW_FRAMEBUFFER) { + if(glstate->fbo.current_fb!=glstate->fbo.fbo_draw) + gles_glBindFramebuffer(GL_FRAMEBUFFER, (glstate->fbo.fbo_draw->id)?glstate->fbo.fbo_draw->id:glstate->fbo.mainfbo_fbo); + return GL_FRAMEBUFFER; + } + if(target==GL_READ_FRAMEBUFFER) { + if(glstate->fbo.current_fb!=glstate->fbo.fbo_read) + gles_glBindFramebuffer(GL_FRAMEBUFFER, (glstate->fbo.fbo_read->id)?glstate->fbo.fbo_read->id:glstate->fbo.mainfbo_fbo); + return GL_FRAMEBUFFER; + } + return target; +} +void ReadDraw_Pop(GLenum target) { + if(target==GL_FRAMEBUFFER) + return; + LOAD_GLES2_OR_OES(glBindFramebuffer); + if(target==GL_DRAW_FRAMEBUFFER && glstate->fbo.current_fb!=glstate->fbo.fbo_draw) { + gles_glBindFramebuffer(GL_FRAMEBUFFER, (glstate->fbo.current_fb->id)?glstate->fbo.current_fb->id:glstate->fbo.mainfbo_fbo); + } + if(target==GL_READ_FRAMEBUFFER && glstate->fbo.current_fb!=glstate->fbo.fbo_read) { + gles_glBindFramebuffer(GL_FRAMEBUFFER, (glstate->fbo.current_fb->id)?glstate->fbo.current_fb->id:glstate->fbo.mainfbo_fbo); + } +} + +void SetAttachment(glframebuffer_t* fb, GLenum attachment, GLenum atttarget, GLuint att, int level) +{ + switch (attachment) { + case GL_COLOR_ATTACHMENT0: + /*case GL_COLOR_ATTACHMENT1: + case GL_COLOR_ATTACHMENT2:*/ + fb->color[attachment - GL_COLOR_ATTACHMENT0] = att; + fb->l_color[attachment - GL_COLOR_ATTACHMENT0] = level; + fb->t_color[attachment - GL_COLOR_ATTACHMENT0] = atttarget; + break; + case GL_DEPTH_ATTACHMENT: + fb->depth = att; + fb->t_depth = atttarget; + fb->l_depth = 0; + break; + case GL_STENCIL_ATTACHMENT: + fb->stencil = att; + fb->t_stencil = atttarget; + fb->l_stencil = 0; + break; + case GL_DEPTH_STENCIL_ATTACHMENT: + fb->depth = att; + fb->t_depth = atttarget; + fb->l_depth = 0; + fb->stencil = att; + fb->t_stencil = atttarget; + fb->l_stencil = 0; + break; + } +} +GLuint GetAttachment(glframebuffer_t* fb, GLenum attachment) { + switch (attachment) { + case GL_COLOR_ATTACHMENT0: + /*case GL_COLOR_ATTACHMENT1: + case GL_COLOR_ATTACHMENT2:*/ + return fb->color[attachment - GL_COLOR_ATTACHMENT0]; + case GL_DEPTH_ATTACHMENT: + return fb->depth; + case GL_STENCIL_ATTACHMENT: + return fb->stencil; + case GL_DEPTH_STENCIL_ATTACHMENT: + // is that possible? + return fb->depth; + } + return 0; +} +GLenum GetAttachmentType(glframebuffer_t* fb, GLenum attachment) { + switch (attachment) { + case GL_COLOR_ATTACHMENT0: + /*case GL_COLOR_ATTACHMENT1: + case GL_COLOR_ATTACHMENT2:*/ + return fb->t_color[attachment - GL_COLOR_ATTACHMENT0]; + case GL_DEPTH_ATTACHMENT: + return fb->t_depth; + case GL_STENCIL_ATTACHMENT: + return fb->t_stencil; + case GL_DEPTH_STENCIL_ATTACHMENT: + return fb->t_depth; + } + return 0; +} +int GetAttachmentLevel(glframebuffer_t* fb, GLenum attachment) { + switch (attachment) { + case GL_COLOR_ATTACHMENT0: + /*case GL_COLOR_ATTACHMENT1: + case GL_COLOR_ATTACHMENT2:*/ + return fb->l_color[attachment - GL_COLOR_ATTACHMENT0]; + case GL_DEPTH_ATTACHMENT: + return fb->l_depth; + case GL_STENCIL_ATTACHMENT: + return fb->l_stencil; + case GL_DEPTH_STENCIL_ATTACHMENT: + return fb->l_depth; + } + return 0; +} + +void gl4es_glFramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level) { + DBG(printf("glFramebufferTexture2D(%s, %s, %s, %u, %i) glstate->fbo.current_fb=%d (draw=%d, read=%d)\n", PrintEnum(target), PrintEnum(attachment), PrintEnum(textarget), texture, level, glstate->fbo.current_fb->id, glstate->fbo.fbo_draw->id, glstate->fbo.fbo_read->id);) + static GLuint scrap_tex = 0; + static int scrap_width = 0; + static int scrap_height = 0; + + LOAD_GLES2_OR_OES(glFramebufferTexture2D); + LOAD_GLES(glTexImage2D); + LOAD_GLES(glBindTexture); + LOAD_GLES(glActiveTexture); + LOAD_GLES(glTexParameteri); + + glframebuffer_t *fb = get_framebuffer(target); + if(!fb) { + errorShim(GL_INVALID_ENUM); + return; + } + + // Ignore Color attachment 1 .. 9 + if ((attachment>=GL_COLOR_ATTACHMENT0+1) && (attachment<=GL_COLOR_ATTACHMENT0+9)) { + errorShim(GL_INVALID_ENUM); + return; + } + + if( attachment!=GL_COLOR_ATTACHMENT0 + && attachment!=GL_DEPTH_ATTACHMENT + && attachment!=GL_STENCIL_ATTACHMENT + && attachment!=GL_DEPTH_STENCIL_ATTACHMENT) { + errorShim(GL_INVALID_ENUM); + return; + } + + int twidth = 0, theight = 0; + // find texture and get it's real name + gltexture_t *tex = NULL; + if (texture) { + tex = gl4es_getTexture(textarget, texture); + + if (!tex) { + LOGE("LIBGL: texture for FBO not found, name=%u\n", texture); + } else { + texture = tex->glname; + // check if texture is shrinked... + if (tex->shrink || tex->useratio || (tex->adjust && (hardext.npot==1 || hardext.npot==2) && !globals4es.potframebuffer)) { + LOGD("LIBGL: %s texture for FBO\n",(tex->useratio)?"going back to npot size pot'ed":"unshrinking shrinked"); + if(tex->shrink || tex->useratio) { + if(tex->useratio) { + tex->width = tex->nwidth/tex->ratiox; + tex->height = tex->nheight/tex->ratioy; + } else { + tex->width *= 1<shrink; + tex->height *= 1<shrink; + } + } + tex->nwidth = (hardext.npot>0 || hardext.esversion>1)?tex->width:npot(tex->width); + tex->nheight = (hardext.npot>0 || hardext.esversion>1)?tex->height:npot(tex->height); + tex->adjustxy[0] = (float)tex->width / tex->nwidth; + tex->adjustxy[1] = (float)tex->height / tex->nheight; + tex->adjust=(tex->width!=tex->nwidth || tex->height!=tex->nheight); + tex->shrink = 0; tex->useratio = 0; + int oldactive = glstate->texture.active; + if(oldactive) gles_glActiveTexture(GL_TEXTURE0); + gltexture_t *bound = glstate->texture.bound[0/*glstate->texture.active*/][ENABLED_TEX2D]; + GLuint oldtex = bound->glname; + if (oldtex!=tex->glname) gles_glBindTexture(GL_TEXTURE_2D, tex->glname); + gles_glTexImage2D(GL_TEXTURE_2D, 0, tex->format, tex->nwidth, tex->nheight, 0, tex->format, tex->type, NULL); + if (oldtex!=tex->glname) gles_glBindTexture(GL_TEXTURE_2D, oldtex); + if(oldactive) gles_glActiveTexture(GL_TEXTURE0+oldactive); + } + int need_change = (globals4es.potframebuffer && (npot(twidth)!=twidth || npot(theight!=theight)))?1:0; + if((tex->type==GL_FLOAT && !hardext.floatfbo) || (tex->type==GL_HALF_FLOAT_OES && !hardext.halffloatfbo)) { + need_change += 2; + tex->type = GL_UNSIGNED_BYTE; + } + if(need_change) { + // check if POT size is asked + LOGD("LIBGL: Recreate a texture for a FBO (%s%s%s)\n", (need_change&1)?"POT":"", (need_change==3)?" & ":"", (need_change&2)?"Float":""); + if(need_change&1) { + twidth = tex->nwidth = npot(tex->nwidth); + theight = tex->nheight = npot(tex->nheight); + tex->adjustxy[0] = (float)tex->width / tex->nwidth; + tex->adjustxy[1] = (float)tex->height / tex->nheight; + tex->adjust=(tex->width!=tex->nwidth || tex->height!=tex->nheight); + } + int oldactive = glstate->texture.active; + if(oldactive) gles_glActiveTexture(GL_TEXTURE0); + gltexture_t *bound = glstate->texture.bound[0/*glstate->texture.active*/][ENABLED_TEX2D]; + GLuint oldtex = bound->glname; + if (oldtex!=tex->glname) gles_glBindTexture(GL_TEXTURE_2D, tex->glname); + gles_glTexImage2D(GL_TEXTURE_2D, 0, tex->format, tex->nwidth, tex->nheight, 0, tex->format, tex->type, NULL); + if (oldtex!=tex->glname) gles_glBindTexture(GL_TEXTURE_2D, oldtex); + if(oldactive) gles_glActiveTexture(GL_TEXTURE0+oldactive); + } + twidth = tex->nwidth; + theight = tex->nheight; + /* if ((tex->width<32) || (tex->height<32)) { + printf("LIBGL: enlarging too-small texture for FBO\n"); + tex->nwidth = (tex->nwidth<32)?32:tex->nwidth; + tex->nheight = (tex->nheight<32)?32:tex->nheight; + tex->shrink = 0; + gltexture_t *bound = glstate->texture.bound[glstate->texture.active][ENABLED_TEX2D]; + GLuint oldtex = bound->glname; + if (oldtex!=tex->glname) gles_glBindTexture(GL_TEXTURE_2D, tex->glname); + gles_glTexImage2D(GL_TEXTURE_2D, 0, tex->format, tex->nwidth, tex->nheight, 0, tex->format, tex->type, NULL); + if (oldtex!=tex->glname) gles_glBindTexture(GL_TEXTURE_2D, oldtex); + }*/ + + fb->width = twidth; + fb->height = theight; + + DBG(printf("found texture, glname=%u, size=%ix%i(%ix%i), format/type=%s/%s\n", texture, tex->width, tex->height, tex->nwidth, tex->nheight, PrintEnum(tex->format), PrintEnum(tex->type));) + } + } + + GLenum ntarget = ReadDraw_Push(target); + + GLuint old_attachment = GetAttachment(fb, attachment); + GLuint old_attachment_type = GetAttachmentType(fb, attachment); + if(old_attachment) { + gltexture_t* old = gl4es_getTexture(old_attachment_type, old_attachment); + if(old) { + DBG(printf("Detach Texture %d from FBO %d as Attachement %s\n", old->glname, old->binded_fbo, PrintEnum(old->binded_attachment));) + old->binded_fbo = 0; + old->binded_attachment = 0; + } else { + DBG(printf("Old attachement %s for FBO %d not found in textures\n", PrintEnum(attachment), fb->id);) + } + } + + if(tex) { + DBG(printf("Attach Texture %d to FBO %d as Attachement %s\n", tex->glname, fb->id, PrintEnum(attachment));) + tex->binded_fbo = fb->id; + tex->binded_attachment = attachment; + } + + if ((old_attachment_type == textarget) && (old_attachment == (tex?tex->texture:texture))) + { + // no need to reattach + noerrorShim(); + return; + } + + SetAttachment(fb, attachment, textarget, tex?tex->texture:texture, level); + + if(attachment==GL_COLOR_ATTACHMENT0 && tex) { + int oldactive = glstate->texture.active; + gltexture_t *bound = glstate->texture.bound[0/*glstate->texture.active*/][ENABLED_TEX2D]; + GLuint oldtex = bound->glname; + int changed = 0; + if((hardext.npot==1 || hardext.npot==2) && (!tex->wrap_s || !tex->wrap_t || !wrap_npot(tex->wrap_s) || !wrap_npot(tex->wrap_t))) { + changed = 1; + if(oldactive) gles_glActiveTexture(GL_TEXTURE0); + if (oldtex!=tex->glname) gles_glBindTexture(GL_TEXTURE_2D, tex->glname); + gles_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + gles_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + tex->wrap_s = tex->wrap_t = GL_CLAMP_TO_EDGE; + tex->adjust = 0; + } + //npot==2 and 3 should support that, but let's ignore that for now and force no mipmap for texture attached to fbo... + if(!tex->min_filter || !minmag_npot(tex->min_filter)) { + if(!changed) { + if(oldactive) gles_glActiveTexture(GL_TEXTURE0); + if (oldtex!=tex->glname) gles_glBindTexture(GL_TEXTURE_2D, tex->glname); + changed = 1; + } + tex->min_filter = minmag_forcenpot(tex->min_filter); + gles_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, tex->min_filter); + tex->adjust = 0; + tex->mipmap_need = 0; + tex->mipmap_auto = 0; + } + if(changed) { + if (oldtex!=tex->glname) gles_glBindTexture(GL_TEXTURE_2D, oldtex); + if(oldactive) gles_glActiveTexture(GL_TEXTURE0+oldactive); + } + } + + if(attachment==GL_DEPTH_ATTACHMENT /*&& hardext.depthtex==0*/) { + noerrorShim(); + if (level!=0) return; + if(hardext.depthtex && (tex || !texture)) { + // depth texture supported! + //check if texture needs to be re-created as true depth texture + if(tex && !(tex->format==GL_DEPTH_COMPONENT || tex->format==GL_DEPTH_STENCIL)) { + tex->format = GL_DEPTH_COMPONENT; + if(tex->type!=GL_UNSIGNED_INT && tex->type!=GL_UNSIGNED_SHORT && tex->type!=GL_FLOAT) tex->type = (hardext.depth24)?GL_UNSIGNED_INT:GL_UNSIGNED_SHORT; + tex->fpe_format = FPE_TEX_DEPTH; + realize_textures(); + int oldactive = glstate->texture.active; + if(oldactive) gles_glActiveTexture(GL_TEXTURE0); + gltexture_t *bound = glstate->texture.bound[0/*glstate->texture.active*/][ENABLED_TEX2D]; + GLuint oldtex = bound->glname; + if (oldtex!=tex->glname) gles_glBindTexture(GL_TEXTURE_2D, tex->glname); + gles_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + gles_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + gles_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + gles_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + gles_glTexImage2D(GL_TEXTURE_2D, 0, tex->format, tex->nwidth, tex->nheight, 0, tex->format, tex->type, NULL); + if (oldtex!=tex->glname) gles_glBindTexture(GL_TEXTURE_2D, oldtex); + if(oldactive) gles_glActiveTexture(GL_TEXTURE0+oldactive); + } + // bind the depth texture... + gles_glFramebufferTexture2D(ntarget, attachment, GL_TEXTURE_2D, texture, 0); + } else { + // let's create a renderbuffer and attach it instead of the (presumably) depth texture + if(tex && !tex->renderdepth) { + gl4es_glGenRenderbuffers(1, &tex->renderdepth); + gl4es_glBindRenderbuffer(GL_RENDERBUFFER, tex->renderdepth); + gl4es_glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, twidth, theight); + gl4es_glBindRenderbuffer(GL_RENDERBUFFER, 0); + } + gl4es_glFramebufferRenderbuffer(ntarget, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, tex?tex->renderdepth:0); + } + errorGL(); + ReadDraw_Pop(target); + return; + } + if(attachment==GL_STENCIL_ATTACHMENT /*&& hardext.depthtex==0*/) { + noerrorShim(); + if (level!=0) return; + // this one is tricky, as it can be GL_DEPTH_STENCIL with DEPTH+DEPTH_STENCIL extension of GL_STENCIL_INDEX8 with STENCIL extension + // and having DEPTH+DEPTH_STENCIL extension doesn't grant STENCIL8 texture extension! + if((tex || !texture) && (hardext.stenciltex || (hardext.depthtex && hardext.depthstencil))) { + // depth texture supported, so are stencil one then! + //check if texture needs to be re-created as true depth texture + if(tex && !(tex->format==GL_STENCIL_INDEX8 || tex->format==GL_DEPTH_STENCIL)) { + if(tex->format==GL_DEPTH_ATTACHMENT) { + //TODO: need to create a new texture, as the depth one is probably used + gl4es_glGenTextures(1, &texture); + realize_textures(); + int oldactive = glstate->texture.active; + if(oldactive) gles_glActiveTexture(GL_TEXTURE0); + gltexture_t *bound = glstate->texture.bound[0/*glstate->texture.active*/][ENABLED_TEX2D]; + GLuint oldtex = bound->glname; + int nwidth = tex->nwidth; + int nheight = tex->nheight; + tex = gl4es_getTexture(textarget, texture); + if (oldtex!=tex->glname) gles_glBindTexture(GL_TEXTURE_2D, tex->glname); + gles_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + gles_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + gles_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + gles_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + gles_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + tex->format = (hardext.stenciltex)?GL_STENCIL_INDEX8:GL_DEPTH_STENCIL; + tex->type = (hardext.stenciltex)?GL_UNSIGNED_BYTE:GL_UNSIGNED_INT_24_8; + gl4es_glTexImage2D(GL_TEXTURE_2D, 0, tex->format, nwidth, nheight, 0, tex->format, tex->type, NULL); + if (oldtex!=tex->glname) gles_glBindTexture(GL_TEXTURE_2D, oldtex); + if(oldactive) gles_glActiveTexture(GL_TEXTURE0+oldactive); + } else { + tex->format = GL_STENCIL_INDEX8; + if(tex->type!=GL_UNSIGNED_BYTE && tex->type!=GL_UNSIGNED_SHORT && tex->type!=GL_FLOAT) tex->type = GL_UNSIGNED_BYTE; + tex->fpe_format = FPE_TEX_DEPTH; + realize_textures(); + int oldactive = glstate->texture.active; + if(oldactive) gles_glActiveTexture(GL_TEXTURE0); + gltexture_t *bound = glstate->texture.bound[0/*glstate->texture.active*/][ENABLED_TEX2D]; + GLuint oldtex = bound->glname; + if (oldtex!=tex->glname) gles_glBindTexture(GL_TEXTURE_2D, tex->glname); + gles_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + gles_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + gles_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + gles_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + gles_glTexImage2D(GL_TEXTURE_2D, 0, tex->format, tex->nwidth, tex->nheight, 0, tex->format, tex->type, NULL); + if (oldtex!=tex->glname) gles_glBindTexture(GL_TEXTURE_2D, oldtex); + if(oldactive) gles_glActiveTexture(GL_TEXTURE0+oldactive); + } + } + // bind the stencil texture... + gles_glFramebufferTexture2D(ntarget, attachment, GL_TEXTURE_2D, texture, 0); + } else { + // let's create a renderbuffer and attach it instead of the (presumably) stencil texture + if(tex && !tex->renderstencil) { + gl4es_glGenRenderbuffers(1, &tex->renderstencil); + gl4es_glBindRenderbuffer(GL_RENDERBUFFER, tex->renderstencil); + gl4es_glRenderbufferStorage(GL_RENDERBUFFER, GL_STENCIL_INDEX8, twidth, theight); + gl4es_glBindRenderbuffer(GL_RENDERBUFFER, 0); + } + gl4es_glFramebufferRenderbuffer(ntarget, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, tex?tex->renderstencil:0); + } + errorGL(); + ReadDraw_Pop(target); + return; + } + if(attachment==GL_DEPTH_STENCIL_ATTACHMENT /*&& hardext.depthtex==0*/) { + noerrorShim(); + if (level!=0) return; + // let's create a renderbuffer and attach it instead of the (presumably) depth texture + if(hardext.depthstencil /*&& !(hardext.depthtex && tex)*/) { + if(hardext.depthtex && (tex || !texture)) { + if(tex && tex->format!=GL_DEPTH_STENCIL) { + tex->format = GL_DEPTH_STENCIL; + tex->type = GL_UNSIGNED_INT_24_8; + tex->fpe_format = FPE_TEX_DEPTH; // add depth_stencil? + int oldactive = glstate->texture.active; + if(oldactive) gles_glActiveTexture(GL_TEXTURE0); + gltexture_t *bound = glstate->texture.bound[0/*glstate->texture.active*/][ENABLED_TEX2D]; + GLuint oldtex = bound->glname; + if (oldtex!=tex->glname) gles_glBindTexture(GL_TEXTURE_2D, tex->glname); + gles_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + gles_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + gles_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + gles_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + gles_glTexImage2D(GL_TEXTURE_2D, 0, tex->format, tex->nwidth, tex->nheight, 0, tex->format, tex->type, NULL); + if (oldtex!=tex->glname) gles_glBindTexture(GL_TEXTURE_2D, oldtex); + if(oldactive) gles_glActiveTexture(GL_TEXTURE0+oldactive); + } + gles_glFramebufferTexture2D(ntarget, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, texture, 0); + gles_glFramebufferTexture2D(ntarget, GL_STENCIL_ATTACHMENT, GL_TEXTURE_2D, texture, 0); + } else { + if(tex && !tex->renderdepth) { + gl4es_glGenRenderbuffers(1, &tex->renderdepth); + gl4es_glBindRenderbuffer(GL_RENDERBUFFER, tex->renderdepth); + gl4es_glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, twidth, theight); + gl4es_glBindRenderbuffer(GL_RENDERBUFFER, 0); + } + errorGL(); + gl4es_glFramebufferRenderbuffer(ntarget, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, tex?tex->renderdepth:0); + gl4es_glFramebufferRenderbuffer(ntarget, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, tex?tex->renderdepth:0); + } + } else { + if(hardext.depthtex && (tex || !texture)) { + // depth texture supported! + //check if texture needs to be re-created ad true depth texture + if(tex && tex->format!=GL_DEPTH_COMPONENT) { + tex->format = GL_DEPTH_COMPONENT; + if(tex->type!=GL_UNSIGNED_INT && tex->type!=GL_UNSIGNED_SHORT && tex->type!=GL_FLOAT) tex->type = (hardext.depth24)?GL_UNSIGNED_INT:GL_UNSIGNED_SHORT; + tex->fpe_format = FPE_TEX_DEPTH; + int oldactive = glstate->texture.active; + if(oldactive) gles_glActiveTexture(GL_TEXTURE0); + gltexture_t *bound = glstate->texture.bound[0/*glstate->texture.active*/][ENABLED_TEX2D]; + GLuint oldtex = bound->glname; + if (oldtex!=tex->glname) gles_glBindTexture(GL_TEXTURE_2D, tex->glname); + gles_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + gles_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + gles_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + gles_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + gles_glTexImage2D(GL_TEXTURE_2D, 0, tex->format, tex->nwidth, tex->nheight, 0, tex->format, tex->type, NULL); + if (oldtex!=tex->glname) gles_glBindTexture(GL_TEXTURE_2D, oldtex); + if(oldactive) gles_glActiveTexture(GL_TEXTURE0+oldactive); + } + // bind the depth texture... + gles_glFramebufferTexture2D(ntarget, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, texture, 0); + } else { + if(tex && !tex->renderdepth) { + gl4es_glGenRenderbuffers(1, &tex->renderdepth); + gl4es_glBindRenderbuffer(GL_RENDERBUFFER, tex->renderdepth); + gl4es_glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, twidth, theight); + gl4es_glBindRenderbuffer(GL_RENDERBUFFER, 0); + } + gl4es_glFramebufferRenderbuffer(ntarget, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, tex?tex->renderdepth:0); + } + if(tex && !tex->renderstencil) { + gl4es_glGenRenderbuffers(1, &tex->renderstencil); + gl4es_glBindRenderbuffer(GL_RENDERBUFFER, tex->renderstencil); + gl4es_glRenderbufferStorage(GL_RENDERBUFFER, GL_STENCIL_INDEX8, twidth, theight); + gl4es_glBindRenderbuffer(GL_RENDERBUFFER, 0); + } + errorGL(); + gl4es_glFramebufferRenderbuffer(ntarget, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, tex?tex->renderstencil:0); + + } + ReadDraw_Pop(target); + return; + } + + twidth = twidth >> level; if(twidth<1) twidth=1; + theight = theight >> level; if(theight<1) theight=1; + + if (level!=0) { + //bind a scrap texture, we don't want level != 0 binding on GLES + if(!scrap_tex) + gl4es_glGenTextures(1, &scrap_tex); + if ((scrap_width!=twidth) || (scrap_height!=theight)) { + scrap_width = twidth; + scrap_height = theight; + gltexture_t *bound = glstate->texture.bound[glstate->texture.active][ENABLED_TEX2D]; + GLuint oldtex = bound->glname; + if (oldtex!=scrap_tex) gles_glBindTexture(GL_TEXTURE_2D, scrap_tex); + gles_glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, scrap_width, scrap_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); + if (oldtex!=scrap_tex) gles_glBindTexture(GL_TEXTURE_2D, oldtex); + } + texture = scrap_tex; + } + + errorGL(); + GLenum realtarget = GL_TEXTURE_2D; + if(textarget>=GL_TEXTURE_CUBE_MAP_POSITIVE_X && textargetfbo.renderbufferlist; + for(int i=0; irenderbuffer = renderbuffers[i]; + } +} + +void gl4es_glFramebufferRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer) { + DBG(printf("glFramebufferRenderbuffer(%s, %s, %s, %u)\n", PrintEnum(target), PrintEnum(attachment), PrintEnum(renderbuffertarget), renderbuffer);) + LOAD_GLES2_OR_OES(glFramebufferRenderbuffer); + LOAD_GLES2_OR_OES(glGetFramebufferAttachmentParameteriv); + LOAD_GLES(glGetError); + + glframebuffer_t *fb = get_framebuffer(target); + if(!fb) { + errorShim(GL_INVALID_ENUM); + return; + } + + // Ignore Color attachment 1 .. 9 + if ((attachment>=GL_COLOR_ATTACHMENT0+1) && (attachment<=GL_COLOR_ATTACHMENT0+9)) { + errorShim(GL_INVALID_ENUM); + return; + } + + if( attachment!=GL_COLOR_ATTACHMENT0 + && attachment!=GL_DEPTH_ATTACHMENT + && attachment!=GL_STENCIL_ATTACHMENT + && attachment!=GL_DEPTH_STENCIL_ATTACHMENT) { + errorShim(GL_INVALID_ENUM); + return; + } + + // get renderbuffer + glrenderbuffer_t *rend = find_renderbuffer(renderbuffer); + if(!rend /*|| !rend->renderbuffer*/) { + errorShim(GL_INVALID_OPERATION); + return; + } + + if (attachment == GL_COLOR_ATTACHMENT0 && globals4es.fboforcetex) { + if(rend->renderbuffer) { + // drop the renderbuffer attachement and create a texture instead... + int oldactive = glstate->texture.active; + if(oldactive) gl4es_glActiveTexture(GL_TEXTURE0); + gltexture_t *bound = glstate->texture.bound[0][ENABLED_TEX2D]; + GLuint oldtex = bound->glname; + // get size of renderbuffer + GLenum format = rend->format; + GLint width = rend->width; + GLint height = rend->height; + // create a texture if needed + if(!rend->secondarytexture) { + GLuint newtex; + gl4es_glGenTextures(1, &newtex); + gl4es_glBindTexture(GL_TEXTURE_2D, newtex); + gl4es_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + gl4es_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + gl4es_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + gl4es_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + gl4es_glTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); + gl4es_glBindTexture(GL_TEXTURE_2D, oldtex); + rend->secondarytexture = newtex; + } + gl4es_glFramebufferTexture2D(target, attachment, GL_TEXTURE_2D, rend->secondarytexture, 0); + // end of cleanup + if(oldactive) gl4es_glActiveTexture(GL_TEXTURE0+oldactive); + } else { + // renderbuffer is 0, unbind the texture attachement... + gl4es_glFramebufferTexture2D(target, attachment, GL_TEXTURE_2D, 0, 0); + } + return; + } + + if (attachment==GL_DEPTH_STENCIL_ATTACHMENT) { + // doesn't seems to be supported "as-is" on GLES on PVR + gl4es_glFramebufferRenderbuffer(target, GL_DEPTH_ATTACHMENT, renderbuffertarget, renderbuffer); + gl4es_glFramebufferRenderbuffer(target, GL_STENCIL_ATTACHMENT, renderbuffertarget, renderbuffer); + return; + } + + + //TODO: handle target=READBUFFER or DRAWBUFFER... + if (attachment==GL_STENCIL_ATTACHMENT) { + if(rend && rend->secondarybuffer) + renderbuffer = rend->secondarybuffer; + } + + fb->width = rend->width; + fb->height = rend->height; + if ((GetAttachmentType(fb, attachment) == GL_RENDERBUFFER) && (GetAttachment(fb, attachment)==renderbuffer)) + { + // no need to reattach + noerrorShim(); + return; + } + + SetAttachment(fb, attachment, GL_RENDERBUFFER, renderbuffer, 0); + + /*if ((glstate->fbo.current_fb!=0) && (renderbuffer==0)) { + //Hack, avoid unbind a renderbuffer on a framebuffer... + // TODO, avoid binding an already binded RB + noerrorShim(); + return; + }*/ // Let it do it now + + GLenum ntarget = ReadDraw_Push(target); + + errorGL(); + gles_glFramebufferRenderbuffer(ntarget, attachment, renderbuffertarget, renderbuffer); + DBG(CheckGLError(1);) + ReadDraw_Pop(target); +} + +void gl4es_glDeleteRenderbuffers(GLsizei n, GLuint *renderbuffers) { + DBG(printf("glDeleteRenderbuffer(%d, %p)\n", n, renderbuffers);) + LOAD_GLES2_OR_OES(glDeleteRenderbuffers); + + // check if we delete a depthstencil + khint_t k; + if (glstate->fbo.renderbufferlist) + for (int i=0; ifbo.renderbufferlist, t); + if (k != kh_end(glstate->fbo.renderbufferlist)) { + rend = kh_value(glstate->fbo.renderbufferlist, k); + if(rend->secondarybuffer) + gles_glDeleteRenderbuffers(1, &rend->secondarybuffer); + if(rend->secondarytexture) + gl4es_glDeleteTextures(1, &rend->secondarytexture); + free(rend); + kh_del(renderbufferlist_t, glstate->fbo.renderbufferlist, k); + } + } + } + } + + errorGL(); + gles_glDeleteRenderbuffers(n, renderbuffers); +} + +void gl4es_glRenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height) { + DBG(printf("glRenderbufferStorage(%s, %s, %i, %i)\n", PrintEnum(target), PrintEnum(internalformat), width, height);) + LOAD_GLES2_OR_OES(glRenderbufferStorage); + LOAD_GLES2_OR_OES(glGenRenderbuffers); + LOAD_GLES2_OR_OES(glBindRenderbuffer); + + glrenderbuffer_t *rend = glstate->fbo.current_rb; + if(!rend->renderbuffer) { + errorShim(GL_INVALID_OPERATION); + return; + } + + errorGL(); + width = (hardext.npot>0 && !globals4es.potframebuffer)?width:npot(width); + height = (hardext.npot>0 && !globals4es.potframebuffer)?height:npot(height); + int use_secondarybuffer = 0; + int use_secondarytexture = 0; + GLenum format = internalformat; + // check if internal format is GL_DEPTH_STENCIL_EXT + if (internalformat == GL_DEPTH_STENCIL) + internalformat = GL_DEPTH24_STENCIL8; + // in that case, create first a STENCIL one then a DEPTH one.... + if ((internalformat == GL_DEPTH24_STENCIL8 && (hardext.depthstencil==0 || (hardext.vendor&VEND_IMGTEC==VEND_IMGTEC)))) { + khint_t k; + int ret; + internalformat = (hardext.depth24)?GL_DEPTH_COMPONENT24:GL_DEPTH_COMPONENT16; + // create a stencil buffer if needed + if(!rend->secondarybuffer) { + gles_glGenRenderbuffers(1, &rend->secondarybuffer); + } + use_secondarybuffer = 1; + } + else if (internalformat == GL_DEPTH_COMPONENT || internalformat == GL_DEPTH_COMPONENT32) // Not much is supported on GLES... + internalformat = GL_DEPTH_COMPONENT16; + else if (internalformat == GL_RGB8 && hardext.rgba8==0) + internalformat = GL_RGB565_OES; + else if (internalformat == GL_RGBA8 && hardext.rgba8==0) + internalformat = GL_RGBA4_OES; + else if (internalformat == GL_RGBA) { + if(hardext.rgba8==0) + internalformat = GL_RGBA8; + else + internalformat = GL_RGBA4_OES; + } + + if(rend->secondarybuffer) { + if(use_secondarybuffer) { + GLuint current_rb = glstate->fbo.current_rb->renderbuffer; + gles_glBindRenderbuffer(GL_RENDERBUFFER, rend->secondarybuffer); + gles_glRenderbufferStorage(target, GL_STENCIL_INDEX8, width, height); + gles_glBindRenderbuffer(GL_RENDERBUFFER, current_rb); + } else { + LOAD_GLES2_OR_OES(glDeleteRenderbuffers); + gles_glDeleteRenderbuffers(1, &rend->secondarybuffer); + rend->secondarybuffer = 0; + } + } + + if(rend->secondarytexture) { + // should check if texture is still needed? + gltexture_t *tex = gl4es_getTexture(GL_TEXTURE_2D, rend->secondarytexture); + LOAD_GLES(glActiveTexture); + LOAD_GLES(glBindTexture); + LOAD_GLES(glTexImage2D); + int oldactive = glstate->texture.active; + if(oldactive) gles_glActiveTexture(GL_TEXTURE0); + gltexture_t *bound = glstate->texture.bound[0/*glstate->texture.active*/][ENABLED_TEX2D]; + GLuint oldtex = bound->glname; + if (oldtex!=rend->secondarytexture) gles_glBindTexture(GL_TEXTURE_2D, rend->secondarytexture); + tex->nwidth = tex->width = width; + tex->nheight = tex->height = height; + gles_glTexImage2D(GL_TEXTURE_2D, 0, tex->format, tex->nwidth, tex->nheight, 0, tex->format, tex->type, NULL); + if (oldtex!=tex->glname) gles_glBindTexture(GL_TEXTURE_2D, oldtex); + if(oldactive) gles_glActiveTexture(GL_TEXTURE0+oldactive); + } + + rend->width = width; + rend->height = height; + rend->format = format; + rend->actual = internalformat; + + gles_glRenderbufferStorage(target, internalformat, width, height); + DBG(CheckGLError(1);) +} + +void gl4es_glRenderbufferStorageMultisample(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height) { //STUB + gl4es_glRenderbufferStorage(target, internalformat, width, height); +} + +void gl4es_glBindRenderbuffer(GLenum target, GLuint renderbuffer) { + DBG(printf("glBindRenderbuffer(%s, %u), binded Fbo=%u\n", PrintEnum(target), renderbuffer, glstate->fbo.current_fb->id);) + LOAD_GLES2_OR_OES(glBindRenderbuffer); + + GLuint current = glstate->fbo.current_rb->renderbuffer; + if(current==renderbuffer) { + noerrorShim(); + return; + } + glrenderbuffer_t * rend = find_renderbuffer(renderbuffer); + if(!rend || !rend->renderbuffer) { + errorShim(GL_INVALID_OPERATION); + return; + } + glstate->fbo.current_rb = rend; + + errorGL(); + gles_glBindRenderbuffer(target, renderbuffer); +} + +GLboolean gl4es_glIsRenderbuffer(GLuint renderbuffer) { + DBG(printf("glIsRenderbuffer(%u)\n", renderbuffer);) + noerrorShim(); + return((find_renderbuffer(renderbuffer)!=NULL)?GL_TRUE:GL_FALSE); +} + +void gl4es_glGenerateMipmap(GLenum target) { + DBG(printf("glGenerateMipmap(%s)\n", PrintEnum(target));) + LOAD_GLES2_OR_OES(glGenerateMipmap); + + if(globals4es.forcenpot && hardext.npot==1) { + gltexture_t *bound = gl4es_getCurrentTexture(target); + if(bound->npot) { + noerrorShim(); + return; // no need to generate mipmap, mipmap is disabled here + } + } + + errorGL(); + if(globals4es.automipmap != 3) + gles_glGenerateMipmap(target); +} + +void gl4es_glGetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment, GLenum pname, GLint *params) { + DBG(printf("glGetFramebufferAttachmentParameteriv(%s, %s, %s, %p)\n", PrintEnum(target), PrintEnum(attachment), PrintEnum(pname), params);) + LOAD_GLES2_OR_OES(glGetFramebufferAttachmentParameteriv); + + glframebuffer_t *fb = get_framebuffer(target); + if(!fb) { + errorShim(GL_INVALID_ENUM); + return; + } + + if( attachment!=GL_COLOR_ATTACHMENT0 + && attachment!=GL_DEPTH_ATTACHMENT + && attachment!=GL_STENCIL_ATTACHMENT + && attachment!=GL_DEPTH_STENCIL_ATTACHMENT) { + errorShim(GL_INVALID_ENUM); + return; + } + + if(pname==GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME) { + noerrorShim(); + *params = GetAttachment(fb, attachment); + return; + } + + if(pname==GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE) { + noerrorShim(); + *params = GetAttachmentType(fb, attachment); + if(*params!=0 && *params!=GL_RENDERBUFFER) + *params = GL_TEXTURE; + return; + } + + if(pname==GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL) { + GLenum tmp = GetAttachmentType(fb, attachment); + if(tmp!=0 && tmp!=GL_RENDERBUFFER) { + noerrorShim(); + *params = GetAttachmentLevel(fb, attachment); + } else { + errorShim(GL_INVALID_ENUM); + } + return; + } + if(pname==GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE) { + GLenum tmp = GetAttachmentType(fb, attachment); + if(tmp!=0 && tmp!=GL_RENDERBUFFER) { + noerrorShim(); + *params = (tmp>=GL_TEXTURE_CUBE_MAP_POSITIVE_X && tmp<=GL_TEXTURE_CUBE_MAP_NEGATIVE_Z)?tmp:0; + } else { + errorShim(GL_INVALID_ENUM); + } + return; + } + // more stuff can be done + /* + if(pname==GL_FRAMEBUFFER_ATTACHMENT_LAYERED) { + GLenum tmp = GetAttachmentType(fb, attachment); + noerrorShim(); + *params = (tmp==GL_TEXTURE_CUBE_MAP || tmp==GL_TEXTURE_3D)?GL_TRUE:GL_FALSE; + return; + } + */ + // hack to return DEPTH size + if(attachment==GL_DEPTH_ATTACHMENT && pname==GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE && hardext.depthtex==0) { + errorGL(); + *params = GetAttachment(fb, attachment); + //TODO: Check all this?! + if (*params) + *params = 16; //Depth buffer is 16 on GLES. No check for 24 bits here... + return; + } + + GLenum ntarget = ReadDraw_Push(target); + + errorGL(); + gles_glGetFramebufferAttachmentParameteriv(ntarget, attachment, pname, params); + ReadDraw_Pop(target); +} + +void gl4es_glGetRenderbufferParameteriv(GLenum target, GLenum pname, GLint * params) { + DBG(printf("glGetRenderbufferParameteriv(%s, %s, %p)\n", PrintEnum(target), PrintEnum(pname), params);) + LOAD_GLES2_OR_OES(glGetRenderbufferParameteriv); + + errorGL(); + gles_glGetRenderbufferParameteriv(target, pname, params); +} + +void createMainFBO(int width, int height) { + LOAD_GLES2_OR_OES(glGenFramebuffers); + LOAD_GLES2_OR_OES(glBindFramebuffer); + LOAD_GLES2_OR_OES(glFramebufferTexture2D); + LOAD_GLES2_OR_OES(glCheckFramebufferStatus); + LOAD_GLES2_OR_OES(glFramebufferRenderbuffer); + LOAD_GLES2_OR_OES(glRenderbufferStorage); + LOAD_GLES2_OR_OES(glGenRenderbuffers); + LOAD_GLES2_OR_OES(glBindRenderbuffer); + LOAD_GLES(glTexImage2D); + LOAD_GLES(glGenTextures); + LOAD_GLES(glBindTexture); + LOAD_GLES(glActiveTexture); + LOAD_GLES(glTexParameteri); + LOAD_GLES2(glClientActiveTexture); + LOAD_GLES(glClear); + + // If there is already a Framebuffer created, let's delete it.... unless it's already the right size! + int createIt = 1; + if (glstate->fbo.mainfbo_fbo) { + if (width==glstate->fbo.mainfbo_width && height==glstate->fbo.mainfbo_height) + return; + //lets adjust the FBO instead of adjusting it + createIt = 0; + } + DBG(printf("LIBGL: Create FBO of %ix%i 32bits\n", width, height);) + // switch to texture unit 0 if needed + if (glstate->texture.active != 0) + gles_glActiveTexture(GL_TEXTURE0); + if (glstate->texture.client != 0 && gles_glClientActiveTexture) + gles_glClientActiveTexture(GL_TEXTURE0); + + glstate->fbo.mainfbo_width = width; + glstate->fbo.mainfbo_height = height; + glstate->fbo.mainfbo_nwidth = width = hardext.npot>0?width:npot(width); + glstate->fbo.mainfbo_nheight = height = hardext.npot>0?height:npot(height); + + // create the texture + if(createIt) + gles_glGenTextures(1, &glstate->fbo.mainfbo_tex); + gles_glBindTexture(GL_TEXTURE_2D, glstate->fbo.mainfbo_tex); + if(createIt) { + gles_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + gles_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + gles_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + gles_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + } + gles_glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, + 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); + gles_glBindTexture(GL_TEXTURE_2D, 0); + // create the render buffers + if(createIt) { + gles_glGenRenderbuffers(1, &glstate->fbo.mainfbo_dep); + gles_glGenRenderbuffers(1, &glstate->fbo.mainfbo_ste); + } + gles_glBindRenderbuffer(GL_RENDERBUFFER, glstate->fbo.mainfbo_ste); + gles_glRenderbufferStorage(GL_RENDERBUFFER, GL_STENCIL_INDEX8, width, height); + gles_glBindRenderbuffer(GL_RENDERBUFFER, glstate->fbo.mainfbo_dep); + gles_glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, width, height); + gles_glBindRenderbuffer(GL_RENDERBUFFER, 0); + // create a fbo + if(createIt) + gles_glGenFramebuffers(1, &glstate->fbo.mainfbo_fbo); + gles_glBindFramebuffer(GL_FRAMEBUFFER, glstate->fbo.mainfbo_fbo); + + // re-attach, even if not creating the fbo... + gles_glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, glstate->fbo.mainfbo_ste); + gles_glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, glstate->fbo.mainfbo_dep); + + gles_glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, glstate->fbo.mainfbo_tex, 0); + + GLenum status = gles_glCheckFramebufferStatus(GL_FRAMEBUFFER); + + gles_glBindFramebuffer(GL_FRAMEBUFFER, 0); + + // Put everything back + gles_glBindTexture(GL_TEXTURE_2D, glstate->texture.bound[0][ENABLED_TEX2D]->glname); + if (glstate->texture.active != 0) + gles_glActiveTexture(GL_TEXTURE0 + glstate->texture.active); + if (glstate->texture.client != 0 && gles_glClientActiveTexture) + gles_glClientActiveTexture(GL_TEXTURE0 + glstate->texture.client); + GLuint current_rb = glstate->fbo.current_rb->renderbuffer; + gles_glBindRenderbuffer(GL_RENDERBUFFER, current_rb); + // Final check, and bind the fbo for future use + if (status != GL_FRAMEBUFFER_COMPLETE) { + printf("LIBGL: Error while creating main fbo (0x%04X)\n", status); + deleteMainFBO(glstate); + gles_glBindFramebuffer(GL_FRAMEBUFFER, glstate->fbo.current_fb->id); + + } else { + gles_glBindFramebuffer(GL_FRAMEBUFFER, (glstate->fbo.current_fb->id)?glstate->fbo.current_fb->id:glstate->fbo.mainfbo_fbo); + // clear color, depth and stencil... + if (glstate->fbo.current_fb->id==0) + gles_glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); + } + +} + +void blitMainFBO(int x, int y, int width, int height) { + if (glstate->fbo.mainfbo_fbo==0) + return; + + // blit the texture + if(!width && !height) { + gl4es_glClearColor(0.0f, 0.0f, 0.0f, 0.0f); + gl4es_glClear(GL_COLOR_BUFFER_BIT); + } + + GLint vp[4]; + memcpy(vp, &glstate->raster.viewport, sizeof(vp)); + gl4es_glViewport(0, 0, glstate->fbowidth, glstate->fboheight); + float rx, ry; + if(!width && !height) { + width = glstate->fbo.mainfbo_width; + height = glstate->fbo.mainfbo_height; + rx = ry = 1.0f; + } else { + y = glstate->fboheight - (y+height); + //y = - y; + rx = (float)width/glstate->fbo.mainfbo_width; + ry = (float)height/glstate->fbo.mainfbo_height; + } + gl4es_blitTexture(glstate->fbo.mainfbo_tex, 0.f, 0.f, + glstate->fbo.mainfbo_width, glstate->fbo.mainfbo_height, + glstate->fbo.mainfbo_nwidth, glstate->fbo.mainfbo_nheight, + rx, ry, + 0, 0, x, y, BLIT_OPAQUE); + gl4es_glViewport(vp[0], vp[1], vp[2], vp[3]); +} + +void bindMainFBO() { + LOAD_GLES2_OR_OES(glBindFramebuffer); + LOAD_GLES2_OR_OES(glCheckFramebufferStatus); + if (!glstate->fbo.mainfbo_fbo) + return; + if (glstate->fbo.current_fb->id==0) { + gles_glBindFramebuffer(GL_FRAMEBUFFER, glstate->fbo.mainfbo_fbo); + //gles_glCheckFramebufferStatus(GL_FRAMEBUFFER); + } +} + +void unbindMainFBO() { + LOAD_GLES2_OR_OES(glBindFramebuffer); + if (!glstate->fbo.mainfbo_fbo) + return; + if (glstate->fbo.current_fb->id==0) { + gles_glBindFramebuffer(GL_FRAMEBUFFER, 0); + } +} + +void deleteMainFBO(void *state) { + LOAD_GLES2_OR_OES(glDeleteFramebuffers); + LOAD_GLES2_OR_OES(glDeleteRenderbuffers); + LOAD_GLES(glDeleteTextures); + + glstate_t *glstate = (glstate_t*)state; + + if (glstate->fbo.mainfbo_dep) { + gles_glDeleteRenderbuffers(1, &glstate->fbo.mainfbo_dep); + glstate->fbo.mainfbo_dep = 0; + } + if (glstate->fbo.mainfbo_ste) { + gles_glDeleteRenderbuffers(1, &glstate->fbo.mainfbo_ste); + glstate->fbo.mainfbo_ste = 0; + } + if (glstate->fbo.mainfbo_tex) { + gles_glDeleteTextures(1, &glstate->fbo.mainfbo_tex); + glstate->fbo.mainfbo_tex = 0; + } + if (glstate->fbo.mainfbo_fbo) { + gles_glDeleteFramebuffers(1, &glstate->fbo.mainfbo_fbo); + glstate->fbo.mainfbo_fbo = 0; + } + + // all done... +} + +void gl4es_glFramebufferTextureLayer( GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer) { + gl4es_glFramebufferTexture2D(target, attachment, GL_TEXTURE_2D, texture, level); // Force Texture2D, ignore layer (should track?)... +} + +void gl4es_getMainFBSize(GLint* width, GLint* height); + +void gl4es_glBlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter) { + // mask will be ignored + // filter will be taken only for ReadFBO has no Texture attached (so readpixel is used) + DBG(printf("glBlitFramebuffer(%d, %d, %d, %d, %d, %d, %d, %d, 0x%04X, %s) fbo_read=%d, fbo_draw=%d\n", + srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, PrintEnum(filter), glstate->fbo.fbo_read->id, glstate->fbo.fbo_draw->id);) + + if((mask&GL_COLOR_BUFFER_BIT)==0) + return; // cannot copy DEPTH or STENCIL data on GLES, only COLOR_BUFFER... + + if(glstate->fbo.fbo_read == glstate->fbo.fbo_draw && srcX0==dstX0 && srcX1==dstX1 && srcY0==dstY0 && srcY1==dstY1) + return; // no need to try copying on itself + + if(dstX1==dstX0 || dstY1==dstY0) + return; // nothing to draw + if(srcX1==srcX0 || srcY1==srcY0) + return; // nothing to draw + + GLuint texture = (glstate->fbo.fbo_read->id==0 && glstate->fbo.mainfbo_fbo)?glstate->fbo.mainfbo_tex:glstate->fbo.fbo_read->color[0]; + + int created = (texture==0 || (glstate->fbo.fbo_read==glstate->fbo.fbo_draw)); + int oldtex = glstate->texture.active; + if (oldtex) + gl4es_glActiveTexture(GL_TEXTURE0); + float nwidth, nheight; + if (created) { + gltexture_t *old = glstate->texture.bound[ENABLED_TEX2D][glstate->texture.active]; + gl4es_glGenTextures(1, &texture); + gl4es_glBindTexture(GL_TEXTURE_2D, texture); + gl4es_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + gl4es_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + gl4es_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, (filter==GL_LINEAR)?GL_LINEAR:GL_NEAREST); + gl4es_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, (filter==GL_LINEAR)?GL_LINEAR:GL_NEAREST); + gl4es_glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, srcX0, srcY0, srcX1-srcX0, srcY1-srcY0, 0); + srcX1-=srcX0; srcX0=0.f; + srcY1-=srcY0; srcY0=0.f; + gl4es_glBindTexture(GL_TEXTURE_2D, old->texture); + } + if(texture==glstate->fbo.mainfbo_tex) { + nwidth = glstate->fbo.mainfbo_nwidth; + nheight = glstate->fbo.mainfbo_nheight; + } else { + gltexture_t *tex = gl4es_getTexture(GL_TEXTURE_2D, texture); + if(tex) { + nwidth = tex->nwidth; + nheight = tex->nheight; + } else { + // not good if here! + nwidth = srcX1; + nheight = srcY1; + } + } + float srcW = srcX1-srcX0; + float srcH = srcY1-srcY0; + float zoomx = ((float)(dstX1-dstX0))/srcW; + float zoomy = ((float)(dstY1-dstY0))/srcH; + // get the width / height of write FBO + int fbowidth, fboheight; + if(glstate->fbo.fbo_draw->id==0/* && glstate->fbo.mainfbo_fbo*/) { + fbowidth = glstate->fbo.mainfbo_width; + fboheight = glstate->fbo.mainfbo_height; + if(glstate->fbo.mainfbo_width!=dstX1 || glstate->fbo.mainfbo_height!=dstY1) { + gl4es_getMainFBSize(&glstate->fbo.mainfbo_width, &glstate->fbo.mainfbo_height); + } + } else { + fbowidth = glstate->fbo.fbo_draw->width; + fboheight = glstate->fbo.fbo_draw->height; + } + GLint vp[4]; + memcpy(vp, &glstate->raster.viewport, sizeof(vp)); + gl4es_glViewport(0, 0, fbowidth, fboheight); + gl4es_blitTexture(texture, srcX0, srcY0, srcW, srcH, nwidth, nheight, zoomx, zoomy, 0, 0, dstX0, dstY0, BLIT_OPAQUE); + gl4es_glViewport(vp[0], vp[1], vp[2], vp[3]); + if(created) { + gl4es_glDeleteTextures(1, &texture); + } + if(oldtex) + gl4es_glActiveTexture(GL_TEXTURE0+oldtex); + +} + +GLuint gl4es_getCurrentFBO() { + return (glstate->fbo.current_fb->id)?glstate->fbo.current_fb->id:glstate->fbo.mainfbo_fbo; +} + +void gl4es_setCurrentFBO() { + LOAD_GLES2_OR_OES(glBindFramebuffer); + gles_glBindFramebuffer(GL_FRAMEBUFFER, (glstate->fbo.current_fb->id)?glstate->fbo.current_fb->id:glstate->fbo.mainfbo_fbo); +} + +// DrawBuffers functions are faked for now. Will be plugg'd when ES3.0 support is implemented +void gl4es_glDrawBuffers(GLsizei n, const GLenum *bufs) { + if(n<0 || n>1) { // TODO: use hardext to handle max draw buffers + errorShim(GL_INVALID_VALUE); + return; + } + // simple copy for now... + glstate->fbo.fbo_draw->n_draw = n; + memcpy(glstate->fbo.fbo_draw->drawbuff, bufs, n*sizeof(GLenum)); + noerrorShim(); +} +void gl4es_glNamedFramebufferDrawBuffers(GLuint framebuffer, GLsizei n, const GLenum *bufs) { + if(n<0 || n>1) { // TODO: use hardext to handle max draw buffers + errorShim(GL_INVALID_VALUE); + return; + } + // simple copy for now... + glframebuffer_t* fb = find_framebuffer(framebuffer); + fb->n_draw = n; + memcpy(fb->drawbuff, bufs, n*sizeof(GLenum)); + noerrorShim(); +} + + +void gl4es_glClearBufferiv(GLenum buffer, GLint drawbuffer, const GLint * value) { + noerrorShim(); + GLenum attch; + switch(buffer) { + case GL_COLOR: + if(drawbuffer>glstate->fbo.fbo_draw->n_draw) + return; // GL_NONE... + attch = glstate->fbo.fbo_draw->drawbuff[buffer]; + if(attch!=GL_COLOR_ATTACHMENT0) { + errorShim(GL_INVALID_VALUE); + return; + } else { + GLfloat oldclear[4]; + gl4es_glGetFloatv(GL_COLOR_CLEAR_VALUE, oldclear); + // how to convert the value? Most FB will be 8bits / componant for now... + gl4es_glClearColor(value[0]/127.0f, value[1]/127.0f, value[2]/127.0f, value[3]/127.0f); + gl4es_glClear(GL_COLOR_BUFFER_BIT); + gl4es_glClearColor(oldclear[0], oldclear[1], oldclear[2], oldclear[3]); + return; + } + break; + case GL_STENCIL: + if(drawbuffer==0) { + GLint old; + gl4es_glGetIntegerv(GL_STENCIL_CLEAR_VALUE, &old); + gl4es_glClearStencil(*value); + gl4es_glClear(GL_STENCIL_BUFFER_BIT); + gl4es_glClearStencil(old); + return; + } else { + errorShim(GL_INVALID_ENUM); + return; + } + default: + errorShim(GL_INVALID_ENUM); + } + return; +} +void gl4es_glClearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint * value) { + noerrorShim(); + GLenum attch; + switch(buffer) { + case GL_COLOR: + if(drawbuffer>glstate->fbo.fbo_draw->n_draw) + return; // GL_NONE... + attch = glstate->fbo.fbo_draw->drawbuff[buffer]; + if(attch!=GL_COLOR_ATTACHMENT0) { + errorShim(GL_INVALID_VALUE); + return; + } else { + GLfloat oldclear[4]; + gl4es_glGetFloatv(GL_COLOR_CLEAR_VALUE, oldclear); + // how to convert the value? Most FB will be 8bits / componant for now... + gl4es_glClearColor(value[0]/255.0f, value[1]/255.0f, value[2]/255.0f, value[3]/255.0f); + gl4es_glClear(GL_COLOR_BUFFER_BIT); + gl4es_glClearColor(oldclear[0], oldclear[1], oldclear[2], oldclear[3]); + return; + } + break; + default: + errorShim(GL_INVALID_ENUM); + } + return; +} +void gl4es_glClearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat * value) { + noerrorShim(); + GLenum attch; + switch(buffer) { + case GL_COLOR: + if(drawbuffer>glstate->fbo.fbo_draw->n_draw) + return; // GL_NONE... + attch = glstate->fbo.fbo_draw->drawbuff[buffer]; + if(attch!=GL_COLOR_ATTACHMENT0) { + errorShim(GL_INVALID_VALUE); + return; + } else { + GLfloat oldclear[4]; + gl4es_glGetFloatv(GL_COLOR_CLEAR_VALUE, oldclear); + // how to convert the value? Most FB will be 8bits / componant for now... + gl4es_glClearColor(value[0], value[1], value[2], value[3]); + gl4es_glClear(GL_COLOR_BUFFER_BIT); + gl4es_glClearColor(oldclear[0], oldclear[1], oldclear[2], oldclear[3]); + return; + } + break; + case GL_DEPTH: + if(drawbuffer==0) { + GLint old; + gl4es_glGetIntegerv(GL_DEPTH_CLEAR_VALUE, &old); + gl4es_glClearDepthf(*value); + gl4es_glClear(GL_DEPTH_BUFFER_BIT); + gl4es_glClearDepthf(old); + return; + } else { + errorShim(GL_INVALID_ENUM); + return; + } + default: + errorShim(GL_INVALID_ENUM); + } + return; +} +void gl4es_glClearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil) { + if(buffer!=GL_DEPTH_STENCIL || drawbuffer!=0) { + errorShim(GL_INVALID_ENUM); + return; + } + GLint olds, oldd; + gl4es_glGetIntegerv(GL_DEPTH_CLEAR_VALUE, &oldd); + gl4es_glGetIntegerv(GL_STENCIL_CLEAR_VALUE, &olds); + gl4es_glClearDepthf(depth); + gl4es_glClearStencil(stencil); + gl4es_glClear(GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); + gl4es_glClearDepthf(oldd); + gl4es_glClearStencil(olds); +} + +void gl4es_glClearNamedFramebufferiv(GLuint framebuffer, GLenum buffer, GLint drawbuffer, const GLint *value) { + GLuint oldf = glstate->fbo.fbo_draw->id; + GLenum target = (glstate->fbo.fbo_draw==glstate->fbo.fbo_read)?GL_FRAMEBUFFER:GL_DRAW_FRAMEBUFFER; + gl4es_glBindFramebuffer(target, framebuffer); + gl4es_glClearBufferiv(buffer, drawbuffer, value); + gl4es_glBindFramebuffer(target, oldf); +} +void gl4es_glClearNamedFramebufferuiv(GLuint framebuffer, GLenum buffer, GLint drawbuffer, const GLuint *value) { + GLuint oldf = glstate->fbo.fbo_draw->id; + GLenum target = (glstate->fbo.fbo_draw==glstate->fbo.fbo_read)?GL_FRAMEBUFFER:GL_DRAW_FRAMEBUFFER; + gl4es_glBindFramebuffer(target, framebuffer); + gl4es_glClearBufferuiv(buffer, drawbuffer, value); + gl4es_glBindFramebuffer(target, oldf); +} +void gl4es_glClearNamedFramebufferfv(GLuint framebuffer, GLenum buffer, GLint drawbuffer, const GLfloat *value) { + GLuint oldf = glstate->fbo.fbo_draw->id; + GLenum target = (glstate->fbo.fbo_draw==glstate->fbo.fbo_read)?GL_FRAMEBUFFER:GL_DRAW_FRAMEBUFFER; + gl4es_glBindFramebuffer(target, framebuffer); + gl4es_glClearBufferfv(buffer, drawbuffer, value); + gl4es_glBindFramebuffer(target, oldf); +} +void gl4es_glClearNamedFramebufferfi(GLuint framebuffer, GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil) { + GLuint oldf = glstate->fbo.fbo_draw->id; + GLenum target = (glstate->fbo.fbo_draw==glstate->fbo.fbo_read)?GL_FRAMEBUFFER:GL_DRAW_FRAMEBUFFER; + gl4es_glBindFramebuffer(target, framebuffer); + gl4es_glClearBufferfi(buffer, drawbuffer, depth, stencil); + gl4es_glBindFramebuffer(target, oldf); +} + + +// direct wrapper + +void glGenFramebuffers(GLsizei n, GLuint *ids) AliasExport("gl4es_glGenFramebuffers"); +void glDeleteFramebuffers(GLsizei n, GLuint *framebuffers) AliasExport("gl4es_glDeleteFramebuffers"); +GLboolean glIsFramebuffer(GLuint framebuffer) AliasExport("gl4es_glIsFramebuffer"); +GLenum glCheckFramebufferStatus(GLenum target) AliasExport("gl4es_glCheckFramebufferStatus"); +void glBindFramebuffer(GLenum target, GLuint framebuffer) AliasExport("gl4es_glBindFramebuffer"); +void glFramebufferTexture1D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level) AliasExport("gl4es_glFramebufferTexture1D"); +void glFramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level) AliasExport("gl4es_glFramebufferTexture2D"); +void glFramebufferTexture3D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint layer) AliasExport("gl4es_glFramebufferTexture3D"); +void glGenRenderbuffers(GLsizei n, GLuint *renderbuffers) AliasExport("gl4es_glGenRenderbuffers"); +void glFramebufferRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer) AliasExport("gl4es_glFramebufferRenderbuffer"); +void glDeleteRenderbuffers(GLsizei n, GLuint *renderbuffers) AliasExport("gl4es_glDeleteRenderbuffers"); +void glRenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height) AliasExport("gl4es_glRenderbufferStorage"); +void glBindRenderbuffer(GLenum target, GLuint renderbuffer) AliasExport("gl4es_glBindRenderbuffer"); +GLboolean glIsRenderbuffer(GLuint renderbuffer) AliasExport("gl4es_glIsRenderbuffer"); +void glGenerateMipmap(GLenum target) AliasExport("gl4es_glGenerateMipmap"); +void glGetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment, GLenum pname, GLint *params) AliasExport("gl4es_glGetFramebufferAttachmentParameteriv"); +void glGetRenderbufferParameteriv(GLenum target, GLenum pname, GLint * params) AliasExport("gl4es_glGetRenderbufferParameteriv"); +void glFramebufferTextureLayer( GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer) AliasExport("gl4es_glFramebufferTextureLayer"); +void glBlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter) AliasExport("gl4es_glBlitFramebuffer"); + +// EXT direct wrapper +void glGenFramebuffersEXT(GLsizei n, GLuint *ids) AliasExport("gl4es_glGenFramebuffers"); +void glDeleteFramebuffersEXT(GLsizei n, GLuint *framebuffers) AliasExport("gl4es_glDeleteFramebuffers"); +GLboolean glIsFramebufferEXT(GLuint framebuffer) AliasExport("gl4es_glIsFramebuffer"); +GLenum glCheckFramebufferStatusEXT(GLenum target) AliasExport("gl4es_glCheckFramebufferStatus"); +void glBindFramebufferEXT(GLenum target, GLuint framebuffer) AliasExport("gl4es_glBindFramebuffer"); +void glFramebufferTexture1DEXT(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level) AliasExport("gl4es_glFramebufferTexture1D"); +void glFramebufferTexture2DEXT(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level) AliasExport("gl4es_glFramebufferTexture2D"); +void glFramebufferTexture3DEXT(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint layer) AliasExport("gl4es_glFramebufferTexture3D"); +void glGenRenderbuffersEXT(GLsizei n, GLuint *renderbuffers) AliasExport("gl4es_glGenRenderbuffers"); +void glFramebufferRenderbufferEXT(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer) AliasExport("gl4es_glFramebufferRenderbuffer"); +void glDeleteRenderbuffersEXT(GLsizei n, GLuint *renderbuffers) AliasExport("gl4es_glDeleteRenderbuffers"); +void glRenderbufferStorageEXT(GLenum target, GLenum internalformat, GLsizei width, GLsizei height) AliasExport("gl4es_glRenderbufferStorage"); +void glBindRenderbufferEXT(GLenum target, GLuint renderbuffer) AliasExport("gl4es_glBindRenderbuffer"); +GLboolean glIsRenderbufferEXT(GLuint renderbuffer) AliasExport("gl4es_glIsRenderbuffer"); +void glGenerateMipmapEXT(GLenum target) AliasExport("gl4es_glGenerateMipmap"); +void glGetFramebufferAttachmentParameterivEXT(GLenum target, GLenum attachment, GLenum pname, GLint *params) AliasExport("gl4es_glGetFramebufferAttachmentParameteriv"); +void glGetRenderbufferParameterivEXT(GLenum target, GLenum pname, GLint * params) AliasExport("gl4es_glGetRenderbufferParameteriv"); +void glFramebufferTextureLayerEXT( GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer) AliasExport("gl4es_glFramebufferTextureLayer"); +void glBlitFramebufferEXT(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter) AliasExport("gl4es_glBlitFramebuffer"); + +// Multisample stub +void glRenderbufferStorageMultisample(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height) AliasExport("gl4es_glRenderbufferStorageMultisample"); + +// DrawBuffers +void glDrawBuffers(GLsizei n, const GLenum *bufs) AliasExport("gl4es_glDrawBuffers"); +void glDrawBuffersERB(GLsizei n, const GLenum *bufs) AliasExport("gl4es_glDrawBuffers"); +void glNamedFramebufferDrawBuffers(GLuint framebuffer, GLsizei n, const GLenum *bufs) AliasExport("gl4es_glNamedFramebufferDrawBuffers"); +void glNamedFramebufferDrawBuffersEXT(GLuint framebuffer, GLsizei n, const GLenum *bufs) AliasExport("gl4es_glNamedFramebufferDrawBuffers"); + +// ClearBuffer... +void glClearBufferiv(GLenum buffer, GLint drawbuffer, const GLint * value) AliasExport("gl4es_glClearBufferiv"); +void glClearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint * value) AliasExport("gl4es_glClearBufferuiv"); +void glClearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat * value) AliasExport("gl4es_glClearBufferfv"); +void glClearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil) AliasExport("gl4es_glClearBufferfi"); + +void glClearNamedFramebufferiv(GLuint framebuffer, GLenum buffer, GLint drawbuffer, const GLint *value) AliasExport("gl4es_glClearNamedFramebufferiv"); +void glClearNamedFramebufferuiv(GLuint framebuffer, GLenum buffer, GLint drawbuffer, const GLuint *value) AliasExport("gl4es_glClearNamedFramebufferuiv"); +void glClearNamedFramebufferfv(GLuint framebuffer, GLenum buffer, GLint drawbuffer, const GLfloat *value) AliasExport("gl4es_glClearNamedFramebufferfv"); +void glClearNamedFramebufferfi(GLuint framebuffer, GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil) AliasExport("gl4es_glClearNamedFramebufferfi"); + +void glClearNamedFramebufferivEXT(GLuint framebuffer, GLenum buffer, GLint drawbuffer, const GLint *value) AliasExport("gl4es_glClearNamedFramebufferiv"); +void glClearNamedFramebufferuivEXT(GLuint framebuffer, GLenum buffer, GLint drawbuffer, const GLuint *value) AliasExport("gl4es_glClearNamedFramebufferuiv"); +void glClearNamedFramebufferfvEXT(GLuint framebuffer, GLenum buffer, GLint drawbuffer, const GLfloat *value) AliasExport("gl4es_glClearNamedFramebufferfv"); +void glClearNamedFramebufferfiEXT(GLuint framebuffer, GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil) AliasExport("gl4es_glClearNamedFramebufferfi"); diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/framebuffers.h b/Projects/Android/jni/SupportLibs/gl4es/src/gl/framebuffers.h new file mode 100644 index 0000000..d0cb468 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/framebuffers.h @@ -0,0 +1,55 @@ +#ifndef _GL4ES_FRAMEBUFFERS_H_ +#define _GL4ES_FRAMEBUFFERS_H_ + +#include "gles.h" + +void gl4es_glGenerateMipmap(GLenum target); +void gl4es_glGenFramebuffers(GLsizei n, GLuint *ids); +void gl4es_glDeleteFramebuffers(GLsizei n, GLuint *framebuffers); +GLboolean gl4es_glIsFramebuffer(GLuint framebuffer); +GLenum gl4es_glCheckFramebufferStatus(GLenum target); +void gl4es_glBindFramebuffer(GLenum target, GLuint framebuffer); +void gl4es_glFramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); +void gl4es_glGenRenderbuffers(GLsizei n, GLuint *renderbuffers); +void gl4es_glFramebufferRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer); +void gl4es_glDeleteRenderbuffers(GLsizei n, GLuint *renderbuffers); +void gl4es_glRenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height); +void gl4es_glBindRenderbuffer(GLenum target, GLuint renderbuffer); +GLboolean gl4es_glIsRenderbuffer(GLuint renderbuffer); +void gl4es_glGenerateMipmap(GLenum target); +void gl4es_glGetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment, GLenum pname, GLint *params); +void gl4es_glGetRenderbufferParameteriv(GLenum target, GLenum pname, GLint * params); + +void gl4es_glFramebufferTexture1D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); // naive Wrap +void gl4es_glFramebufferTexture3D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint layer); // naive Wrap +void gl4es_glRenderbufferStorageMultisample(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height); //STUB +void gl4es_glFramebufferTextureLayer( GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer); // naive Wrap +void gl4es_glBlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter); + +void gl4es_glDrawBuffers(GLsizei n, const GLenum *bufs); +void gl4es_glNamedFramebufferDrawBuffers(GLuint framebuffer, GLsizei n, const GLenum *bufs); + +void gl4es_glClearBufferiv(GLenum buffer, GLint drawbuffer, const GLint * value); +void gl4es_glClearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint * value); +void gl4es_glClearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat * value); +void gl4es_glClearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil); + +void gl4es_glClearNamedFramebufferiv(GLuint framebuffer, GLenum buffer, GLint drawbuffer, const GLint *value); +void gl4es_glClearNamedFramebufferuiv(GLuint framebuffer, GLenum buffer, GLint drawbuffer, const GLuint *value); +void gl4es_glClearNamedFramebufferfv(GLuint framebuffer, GLenum buffer, GLint drawbuffer, const GLfloat *value); +void gl4es_glClearNamedFramebufferfi(GLuint framebuffer, GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil); + +// In case of LIBGL_FB=2, let's create an FBO for everything, that is then blitted just before the SwapBuffer +void createMainFBO(int width, int height); +void blitMainFBO(int x, int y, int width, int height); +void deleteMainFBO(void* state); +void bindMainFBO(); +void unbindMainFBO(); + +void readfboBegin(); +void readfboEnd(); + +GLuint gl4es_getCurrentFBO(); +void gl4es_setCurrentFBO(); + +#endif // _GL4ES_FRAMEBUFFERS_H_ diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/getter.c b/Projects/Android/jni/SupportLibs/gl4es/src/gl/getter.c new file mode 100644 index 0000000..cd95932 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/getter.c @@ -0,0 +1,1064 @@ +#include +#include "../glx/hardext.h" +#include "debug.h" +#include "gl4es.h" +#include "glstate.h" +#include "init.h" +#include "loader.h" +#include "light.h" +#include "matvec.h" +#include "texgen.h" + +GLenum gl4es_glGetError() { + LOAD_GLES(glGetError); + if(globals4es.noerror) + return GL_NO_ERROR; + if (glstate->shim_error) { + GLenum tmp = gles_glGetError(); // to purge GLES error stack + tmp = glstate->last_error; + glstate->last_error = GL_NO_ERROR; + return tmp; + } + return gles_glGetError(); +} +GLenum glGetError() AliasExport("gl4es_glGetError"); + +void gl4es_glGetPointerv(GLenum pname, GLvoid* *params) { + noerrorShim(); + switch(pname) { + case GL_COLOR_ARRAY_POINTER: + *params = (void*)glstate->vao->pointers[ATT_COLOR].pointer; + break; + case GL_EDGE_FLAG_ARRAY_POINTER: + *params = NULL; + break; + case GL_FEEDBACK_BUFFER_POINTER: + *params = NULL; + break; + case GL_INDEX_ARRAY_POINTER: + *params = NULL; + case GL_NORMAL_ARRAY_POINTER: + *params = (void*)glstate->vao->pointers[ATT_NORMAL].pointer; + break; + case GL_TEXTURE_COORD_ARRAY_POINTER: + *params = (void*)glstate->vao->pointers[ATT_MULTITEXCOORD0+glstate->texture.client].pointer; + break; + case GL_SELECTION_BUFFER_POINTER: + *params = glstate->selectbuf.buffer; + break; + case GL_VERTEX_ARRAY_POINTER : + *params = (void*)glstate->vao->pointers[ATT_VERTEX].pointer; + break; + case GL_FOG_COORD_ARRAY: + *params = (void*)glstate->vao->pointers[ATT_FOGCOORD].pointer; + break; + case GL_SECONDARY_COLOR_ARRAY: + *params = (void*)glstate->vao->pointers[ATT_SECONDARY].pointer; + break; + default: + errorShim(GL_INVALID_ENUM); + } +} +void glGetPointerv(GLenum pname, GLvoid* *params) AliasExport("gl4es_glGetPointerv"); + +static GLubyte *extensions = NULL; +static int num_extensions = 0; +static GLubyte **extensions_list = NULL; + +void BuildExtensionsList() { + if(!extensions) { + extensions = (GLubyte*)malloc(5000); // arbitrary size... + strcpy(extensions, + "GL_EXT_abgr " + "GL_EXT_packed_pixels " + "GL_EXT_compiled_vertex_array " + "GL_ARB_vertex_buffer_object " + "GL_ARB_vertex_array_object " + "GL_ARB_vertex_buffer " + "GL_EXT_vertex_array " + "GL_EXT_secondary_color " + "GL_ARB_multitexture " + "GL_ARB_texture_border_clamp " + "GL_ARB_texture_env_add " + "GL_EXT_texture_env_add " + "GL_ARB_texture_env_combine " + "GL_EXT_texture_env_combine " + "GL_ARB_texture_env_crossbar " + "GL_EXT_texture_env_crossbar " + "GL_ARB_texture_env_dot3 " + "GL_EXT_texture_env_dot3 " + "GL_SGIS_generate_mipmap " + "GL_EXT_draw_range_elements " + "GL_EXT_bgra " + "GL_ARB_texture_compression " + "GL_EXT_texture_compression_s3tc " + "GL_OES_texture_compression_S3TC " + "GL_EXT_texture_compression_dxt1 " + "GL_EXT_texture_compression_dxt3 " + "GL_EXT_texture_compression_dxt5 " + "GL_ARB_point_parameters " + "GL_EXT_point_parameters " + "GL_EXT_stencil_wrap " + "GL_SGIS_texture_edge_clamp " + "GL_EXT_texture_edge_clamp " + "GL_EXT_direct_state_access " + "GL_EXT_multi_draw_arrays " + "GL_SUN_multi_draw_arrays " + "GL_ARB_multisample " + "GL_EXT_texture_object " + "GL_EXT_polygon_offset " + "GL_GL4ES_hint " + "GL_ARB_texture_rectangle " + "GL_ARB_draw_elements_base_vertex " + "GL_EXT_draw_elements_base_vertex " +// "GL_EXT_blend_logic_op " + ); + if(globals4es.vabgra) + strcat(extensions, "GL_ARB_vertex_array_bgra "); + if(globals4es.npot>=1) + strcat(extensions, "GL_APPLE_texture_2D_limited_npot "); + if(globals4es.npot>=2) + strcat(extensions, "GL_ARB_texture_non_power_of_two "); + if(hardext.blendcolor) + strcat(extensions, "GL_EXT_blend_color "); + if(hardext.blendminmax) + strcat(extensions, "GL_EXT_blend_minmax "); + if(hardext.blendeq) + strcat(extensions, "GL_EXT_blend_equation_separate "); + if(hardext.blendfunc) + strcat(extensions, "GL_EXT_blend_func_separate "); + if(hardext.blendsub) + strcat(extensions, "GL_EXT_blend_subtract "); + if(hardext.aniso) + strcat(extensions, "GL_EXT_texture_filter_anisotropic "); + if(hardext.mirrored) + strcat(extensions, "GL_ARB_texture_mirrored_repeat "); + if(hardext.fbo) + strcat(extensions, + "GL_ARB_framebuffer_object " + "GL_EXT_framebuffer_object " + "GL_EXT_packed_depth_stencil " + "GL_ARB_draw_buffers "); + if(hardext.pointsprite) + strcat(extensions, "GL_ARB_point_sprite "); + if(hardext.cubemap) { + strcat(extensions, "GL_ARB_texture_cube_map "); + strcat(extensions, "GL_EXT_texture_cube_map "); + } + if(hardext.rgtex) { + strcat(extensions, "GL_EXT_texture_rg "); + } + if(hardext.floattex || (globals4es.floattex==2)) { + strcat(extensions, "GL_EXT_texture_float "); + } + if(hardext.halffloattex || (globals4es.floattex==2)) { + strcat(extensions, "GL_EXT_texture_half_float "); + } + if(hardext.floatfbo || (globals4es.floattex==2)) { + strcat(extensions, "GL_EXT_color_buffer_float "); + } + if(hardext.halffloatfbo || (globals4es.floattex==2)) { + strcat(extensions, "GL_EXT_color_buffer_half_float "); + } + if(hardext.depthtex) { + strcat(extensions, "GL_EXT_depth_texture "); + strcat(extensions, "GL_ARB_depth_texture "); + } + if(hardext.esversion>1) { + strcat(extensions, "GL_EXT_fog_coord "); + strcat(extensions, "GL_EXT_separate_specular_color "); + strcat(extensions, "GL_EXT_rescale_normal "); + strcat(extensions, "GL_ARB_ES2_compatibility "); + strcat(extensions, + "GL_ARB_fragment_shader " + "GL_ARB_vertex_shader " + "GL_ARB_shader_objects " + "GL_ARB_shading_language_100 " + "GL_ATI_texture_env_combine3 " + "GL_ATIX_texture_env_route " + "GL_NV_texture_env_combine4 " + "GL_ARB_draw_instanced " + "GL_ARB_instanced_arrays " + ); + } + if(globals4es.arb_program) { + strcat(extensions, + "GL_ARB_vertex_program " + "GL_ARB_fragment_program " + ); + } + char* p = extensions; + num_extensions = 0; + // quickly count extensions. Each one is separated by space... + while ((p=strchr(p, ' '))) { while(*(p)==' ') ++p; num_extensions++; } + // and now split in array of individual extensions + // TODO: is all this better be moved in glstate? + extensions_list = (GLubyte**)calloc(num_extensions, sizeof(GLubyte*)); + p = extensions; + for (int i=0; iA->stack+(glstate->A->top*16)) + +int gl4es_commonGet(GLenum pname, GLfloat *params) { + switch (pname) { + case GL_MAJOR_VERSION: + *params = globals4es.gl/10; + break; + case GL_MINOR_VERSION: + *params = globals4es.gl%10; + break; + case GL_DOUBLEBUFFER: + *params = 1; // Fake double buffering... + break; + case GL_MAX_ELEMENTS_INDICES: + *params = 1024; + break; + case GL_MAX_ELEMENTS_VERTICES: + *params = 4096; + break; + case GL_NUM_EXTENSIONS: + BuildExtensionsList(); + *params = num_extensions; + break; + case GL_AUX_BUFFERS: + *params = 0; + break; + case GL_MAX_DRAW_BUFFERS_ARB: // fake... + *params = 1; + break; + case GL_MAX_TEXTURE_UNITS: + *params = hardext.maxtex; + break; + case GL_MAX_TEXTURE_COORDS: + *params = hardext.maxtex; + break; + case GL_PACK_ALIGNMENT: + *params = glstate->texture.pack_align; + break; + case GL_UNPACK_ALIGNMENT: + *params = glstate->texture.unpack_align; + break; + case GL_UNPACK_ROW_LENGTH: + *params = glstate->texture.unpack_row_length; + break; + case GL_UNPACK_SKIP_PIXELS: + *params = glstate->texture.unpack_skip_pixels; + break; + case GL_UNPACK_SKIP_ROWS: + *params = glstate->texture.unpack_skip_rows; + break; + case GL_UNPACK_LSB_FIRST: + *params = glstate->texture.unpack_lsb_first; + break; + case GL_UNPACK_IMAGE_HEIGHT: + *params = glstate->texture.unpack_image_height; + break; + case GL_PACK_ROW_LENGTH: + *params = glstate->texture.pack_row_length; + break; + case GL_PACK_SKIP_PIXELS: + *params = glstate->texture.pack_skip_pixels; + break; + case GL_PACK_SKIP_ROWS: + *params = glstate->texture.pack_skip_rows; + break; + case GL_PACK_LSB_FIRST: + *params = glstate->texture.pack_lsb_first; + break; + case GL_PACK_IMAGE_HEIGHT: + *params = glstate->texture.pack_image_height; + break; + case GL_UNPACK_SWAP_BYTES: + case GL_PACK_SWAP_BYTES: + //Fake, *TODO* ? + *params = 0; + break; + case GL_ZOOM_X: + *params = glstate->raster.raster_zoomx; + break; + case GL_ZOOM_Y: + *params = glstate->raster.raster_zoomy; + break; + case GL_RED_SCALE: + *params = glstate->raster.raster_scale[0]; + break; + case GL_RED_BIAS: + *params = glstate->raster.raster_bias[0]; + break; + case GL_GREEN_SCALE: + case GL_BLUE_SCALE: + case GL_ALPHA_SCALE: + *params = glstate->raster.raster_scale[(pname-GL_GREEN_SCALE)/2+1]; + break; + case GL_GREEN_BIAS: + case GL_BLUE_BIAS: + case GL_ALPHA_BIAS: + *params = glstate->raster.raster_bias[(pname-GL_GREEN_BIAS)/2+1]; + break; + case GL_MAP_COLOR: + *params = glstate->raster.map_color; + break; + case GL_INDEX_SHIFT: + *params = glstate->raster.index_shift; + break; + case GL_INDEX_OFFSET: + *params = glstate->raster.index_offset; + break; + case GL_PIXEL_MAP_S_TO_S_SIZE: + *params = 1; + break; + case GL_PIXEL_MAP_I_TO_I_SIZE: + *params = glstate->raster.map_i2i_size; + break; + case GL_PIXEL_MAP_I_TO_R_SIZE: + *params = glstate->raster.map_i2r_size; + break; + case GL_PIXEL_MAP_I_TO_G_SIZE: + *params = glstate->raster.map_i2g_size; + break; + case GL_PIXEL_MAP_I_TO_B_SIZE: + *params = glstate->raster.map_i2b_size; + break; + case GL_PIXEL_MAP_I_TO_A_SIZE: + *params = glstate->raster.map_i2a_size; + break; + case GL_PIXEL_MAP_R_TO_R_SIZE: + *params = 1; + break; + case GL_PIXEL_MAP_G_TO_G_SIZE: + *params = 1; + break; + case GL_PIXEL_MAP_B_TO_B_SIZE: + *params = 1; + break; + case GL_PIXEL_MAP_A_TO_A_SIZE: + *params = 1; + break; + case GL_MAX_PIXEL_MAP_TABLE: + *params = MAX_MAP_SIZE; + break; + case GL_RENDER_MODE: + *params = (glstate->render_mode)?glstate->render_mode:GL_RENDER; + break; + case GL_NAME_STACK_DEPTH: + *params = glstate->namestack.top; + break; + case GL_MAX_NAME_STACK_DEPTH: + *params = 1024; + break; + case GL_MAX_TEXTURE_IMAGE_UNITS: + *params = hardext.maxteximage; + break; + case GL_MAX_MODELVIEW_STACK_DEPTH: + *params=MAX_STACK_MODELVIEW; + break; + case GL_MAX_PROJECTION_STACK_DEPTH: + *params=MAX_STACK_PROJECTION; + break; + case GL_MAX_TEXTURE_STACK_DEPTH: + *params=MAX_STACK_TEXTURE; + break; + case GL_MODELVIEW_STACK_DEPTH: + *params=(glstate->modelview_matrix)?(glstate->modelview_matrix->top+1):1; + break; + case GL_PROJECTION_STACK_DEPTH: + *params=(glstate->projection_matrix)?(glstate->projection_matrix->top+1):1; + break; + case GL_TEXTURE_STACK_DEPTH: + *params=(glstate->texture_matrix)?(glstate->texture_matrix[glstate->texture.active]->top+1):1; + break; + case GL_MAX_LIST_NESTING: + *params=64; // fake, no limit in fact + break; + case GL_ARRAY_BUFFER_BINDING: + *params=(glstate->vao->vertex)?glstate->vao->vertex->buffer:0; + break; + case GL_ELEMENT_ARRAY_BUFFER_BINDING: + *params=(glstate->vao->elements)?glstate->vao->elements->buffer:0; + break; + case GL_PIXEL_PACK_BUFFER_BINDING: + *params=(glstate->vao->pack)?glstate->vao->pack->buffer:0; + break; + case GL_PIXEL_UNPACK_BUFFER_BINDING: + *params=(glstate->vao->unpack)?glstate->vao->unpack->buffer:0; + break; + case GL_MAX_TEXTURE_MAX_ANISOTROPY: + if(hardext.aniso) + *params=hardext.aniso; + else + errorShim(GL_INVALID_ENUM); + break; + case GL_MAX_COLOR_ATTACHMENTS: + if(hardext.fbo) + *params=1; + else + *params=0; + break; + case GL_MATRIX_MODE: + *params=glstate->matrix_mode; + break; + case GL_LIGHT_MODEL_TWO_SIDE: + *params=glstate->light.two_side; + break; + case GL_FOG_MODE: + *params=glstate->fog.mode; + break; + case GL_FOG_DENSITY: + *params=glstate->fog.density; + break; + case GL_FOG_START: + *params=glstate->fog.start; + break; + case GL_FOG_END: + *params=glstate->fog.end; + break; + case GL_FOG_INDEX: + *params=glstate->fog.start; + break; + case GL_FOG_COORD_SRC: + *params=glstate->fog.coord_src; + break; + case GL_CURRENT_FOG_COORD: + *params=glstate->fogcoord; + break; + case GL_STENCIL_FUNC: + *params=glstate->stencil.func[0]; + break; + case GL_STENCIL_VALUE_MASK: + *params=glstate->stencil.f_mask[0]; + break; + case GL_STENCIL_REF: + *params=glstate->stencil.f_ref[0]; + break; + case GL_STENCIL_BACK_FUNC: + *params=glstate->stencil.func[1]; + break; + case GL_STENCIL_BACK_VALUE_MASK: + *params=glstate->stencil.f_mask[1]; + break; + case GL_STENCIL_BACK_REF: + *params=glstate->stencil.f_ref[1]; + break; + case GL_STENCIL_WRITEMASK: + *params=glstate->stencil.mask[0]; + break; + case GL_STENCIL_BACK_WRITEMASK: + *params=glstate->stencil.mask[1]; + break; + case GL_STENCIL_FAIL: + *params=glstate->stencil.sfail[0]; + break; + case GL_STENCIL_PASS_DEPTH_FAIL: + *params=glstate->stencil.dpfail[0]; + break; + case GL_STENCIL_PASS_DEPTH_PASS: + *params=glstate->stencil.dppass[0]; + break; + case GL_STENCIL_BACK_FAIL: + *params=glstate->stencil.sfail[1]; + break; + case GL_STENCIL_BACK_PASS_DEPTH_FAIL: + *params=glstate->stencil.dpfail[1]; + break; + case GL_STENCIL_BACK_PASS_DEPTH_PASS: + *params=glstate->stencil.dppass[1]; + break; + case GL_STENCIL_CLEAR_VALUE: + *params=glstate->stencil.clear; + break; + case GL_MAX_TEXTURE_SIZE: + *params=hardext.maxsize; + switch(globals4es.texshrink) { + case 8: + case 9: + case 10: + *params*=4; + break; + case 11: + *params*=2; + break; + } + break; + case GL_MAX_RECTANGLE_TEXTURE_SIZE_ARB: + *params=hardext.maxsize; + switch(globals4es.texshrink) { + case 8: + case 9: + case 10: + *params*=4; + break; + case 11: + *params*=2; + break; + } + break; + case GL_SHADE_MODEL: + *params=glstate->shademodel; + break; + case GL_ALPHA_TEST_FUNC: + *params=glstate->alphafunc; + break; + case GL_ALPHA_TEST_REF: + *params=glstate->alpharef; + break; + case GL_LOGIC_OP_MODE: + *params=glstate->logicop; + break; + case GL_BLEND_SRC: + case GL_BLEND_SRC_RGB: + *params=glstate->blendsfactorrgb; + break; + case GL_BLEND_DST: + case GL_BLEND_DST_RGB: + *params=glstate->blenddfactorrgb; + break; + case GL_BLEND_SRC_ALPHA: + *params=glstate->blendsfactoralpha; + break; + case GL_BLEND_DST_ALPHA: + *params=glstate->blenddfactoralpha; + break; + case GL_MAX_CLIP_PLANES: + *params=hardext.maxplanes; + break; + case GL_MAX_LIGHTS: + *params=hardext.maxlights; + break; + case GL_LIGHTING: + *params=glstate->enable.lighting; + break; + case GL_DEPTH_WRITEMASK: + *params=glstate->depth.mask; + break; + case GL_DEPTH_FUNC: + *params=glstate->depth.func; + break; + case GL_CULL_FACE_MODE: + *params=glstate->face.cull; + break; + case GL_FRONT_FACE: + *params=glstate->face.front; + break; +#define GO(n) case GL_CLIP_PLANE##n: \ + *params=glstate->enable.plane[n]; \ + break + GO(0); + GO(1); + GO(2); + GO(3); + GO(4); + GO(5); +#undef GO +#define GO(n) case GL_LIGHT##n: \ + *params=glstate->enable.light[n]; \ + break + GO(0); + GO(1); + GO(2); + GO(3); + GO(4); + GO(5); + GO(6); + GO(7); +#undef GO + case GL_POINT_SIZE_MIN: + *params=glstate->pointsprite.sizeMin; + break; + case GL_POINT_SIZE_MAX: + *params=glstate->pointsprite.sizeMax; + break; + case GL_POINT_SIZE: + *params=glstate->pointsprite.size; + break; + case GL_POINT_FADE_THRESHOLD_SIZE: + *params=glstate->pointsprite.fadeThresholdSize; + break; + case GL_POINT_SPRITE_COORD_ORIGIN : + *params=glstate->pointsprite.coordOrigin; + break; + case GL_DRAW_BUFFER: + *params=GL_FRONT; + break; + case GL_FRAMEBUFFER_BINDING: + *params=glstate->fbo.current_fb->id; + break; + // shader stuff + case GL_CURRENT_PROGRAM: + *params=glstate->glsl->program; + break; + // global hints + case GL_PERSPECTIVE_CORRECTION_HINT: + if(hardext.esversion==1) return 0; // fall back to actual glGet + *params=GL_DONT_CARE; + break; + case GL_POINT_SMOOTH_HINT: + if(hardext.esversion==1) return 0; // fall back to actual glGet + *params=GL_DONT_CARE; + break; + case GL_LINE_SMOOTH_HINT: + if(hardext.esversion==1) return 0; // fall back to actual glGet + *params=GL_DONT_CARE; + break; + case GL_FOG_HINT: + if(hardext.esversion==1) return 0; // fall back to actual glGet + *params=GL_DONT_CARE; + break; + case GL_TEXTURE_COMPRESSION_HINT: + *params=GL_DONT_CARE; + break; + // GL4ES special hints + case GL_SHRINK_HINT_GL4ES: + *params=globals4es.texshrink; + break; + case GL_ALPHAHACK_HINT_GL4ES: + *params=globals4es.alphahack; + break; + case GL_RECYCLEFBO_HINT_GL4ES: + *params=globals4es.recyclefbo; + break; + case GL_MIPMAP_HINT_GL4ES: + *params=globals4es.automipmap; + break; + case GL_TEXDUMP_HINT_GL4ES: + *params=globals4es.texdump; + break; + case GL_COPY_HINT_GL4ES: + *params=0; // removed + break; + case GL_NOLUMAPHA_HINT_GL4ES: + *params=globals4es.nolumalpha; + break; + case GL_BLENDHACK_HINT_GL4ES: + *params=globals4es.blendhack; + break; + case GL_BATCH_HINT_GL4ES: + *params=globals4es.batch; + break; + case GL_NOERROR_HINT_GL4ES: + *params=globals4es.noerror; + break; + case GL_AVOID16BITS_HINT_GL4ES: + *params=globals4es.avoid16bits; + break; + case GL_GAMMA_HINT_GL4ES: + *params=globals4es.gamma*10.f; + break; + default: + return 0; + } + return 1; +} + +// glGet +void gl4es_glGetIntegerv(GLenum pname, GLint *params) { + if (params==NULL) { + errorShim(GL_INVALID_OPERATION); + return; + } + GLint dummy; + LOAD_GLES(glGetIntegerv); + noerrorShim(); + GLfloat fparam; + if (gl4es_commonGet(pname, &fparam)) { + params[0] = fparam; + return; + } + gltexture_t* tex; + switch (pname) { + // texture binding only make sense with int + case GL_TEXTURE_BINDING_1D: + tex=glstate->texture.bound[glstate->texture.active][ENABLED_TEX1D]; + *params=tex->texture; + break; + case GL_TEXTURE_BINDING_2D: + tex=glstate->texture.bound[glstate->texture.active][ENABLED_TEX2D]; + *params=tex->texture; + break; + case GL_TEXTURE_BINDING_3D: + tex=glstate->texture.bound[glstate->texture.active][ENABLED_TEX3D]; + *params=tex->texture; + break; + case GL_TEXTURE_BINDING_CUBE_MAP: + tex=glstate->texture.bound[glstate->texture.active][ENABLED_CUBE_MAP]; + *params=tex->texture; + break; + case GL_TEXTURE_BINDING_RECTANGLE_ARB: + tex=glstate->texture.bound[glstate->texture.active][ENABLED_TEXTURE_RECTANGLE]; + *params=tex->texture; + break; + // arrays... + case GL_POINT_SIZE_RANGE: + gles_glGetIntegerv(GL_POINT_SIZE_MIN, params); + gles_glGetIntegerv(GL_POINT_SIZE_MAX, params+1); + break; + case GL_NUM_COMPRESSED_TEXTURE_FORMATS: + gles_glGetIntegerv(GL_NUM_COMPRESSED_TEXTURE_FORMATS, params); + (*params)+=4; // adding fake DXTc + break; + case GL_COMPRESSED_TEXTURE_FORMATS: + gles_glGetIntegerv(GL_NUM_COMPRESSED_TEXTURE_FORMATS, &dummy); + // get standard ones + gles_glGetIntegerv(GL_COMPRESSED_TEXTURE_FORMATS, params); + // add fake DXTc + params[dummy++]=GL_COMPRESSED_RGB_S3TC_DXT1_EXT; + params[dummy++]=GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; + params[dummy++]=GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; + params[dummy++]=GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; + break; + case GL_LIGHT_MODEL_AMBIENT: + for (dummy=0; dummy<4; dummy++) + params[dummy]=glstate->light.ambient[dummy]; + break; + case GL_FOG_COLOR: + for (dummy=0; dummy<4; dummy++) + params[dummy]=glstate->fog.color[dummy]; + break; + case GL_CURRENT_COLOR: + for (dummy=0; dummy<4; dummy++) + params[dummy]=glstate->color[dummy]; + break; + case GL_CURRENT_SECONDARY_COLOR: + for (dummy=0; dummy<4; dummy++) + params[dummy]=glstate->secondary[dummy]; + break; + case GL_CURRENT_NORMAL: + for (dummy=0; dummy<3; dummy++) + params[dummy]=glstate->normal[dummy]; + break; + case GL_CURRENT_TEXTURE_COORDS: + for (dummy=0; dummy<4; dummy++) + params[dummy]=glstate->texcoord[glstate->texture.active][dummy]; + break; + case GL_COLOR_WRITEMASK: + memcpy(params, glstate->colormask, 4*sizeof(GLboolean)); + break; + case GL_POINT_DISTANCE_ATTENUATION : + for (dummy=0; dummy<3; dummy++) + params[dummy]=glstate->pointsprite.distance[dummy]; + break; + case GL_DEPTH_RANGE: + params[0] = glstate->depth.near*2147483647l; + params[1] = glstate->depth.far*2147483647l; + break; + default: + errorGL(); + gles_glGetIntegerv(pname, params); + } +} +void glGetIntegerv(GLenum pname, GLint *params) AliasExport("gl4es_glGetIntegerv"); + +void gl4es_glGetFloatv(GLenum pname, GLfloat *params) { + LOAD_GLES(glGetFloatv); + noerrorShim(); + if (gl4es_commonGet(pname, params)) { + return; + } + + switch (pname) { + case GL_POINT_SIZE_RANGE: + gles_glGetFloatv(GL_POINT_SIZE_MIN, params); + gles_glGetFloatv(GL_POINT_SIZE_MAX, params+1); + break; + case GL_TRANSPOSE_PROJECTION_MATRIX: + matrix_transpose(TOP(projection_matrix), params); + break; + case GL_TRANSPOSE_MODELVIEW_MATRIX: + matrix_transpose(TOP(modelview_matrix), params); + break; + case GL_TRANSPOSE_TEXTURE_MATRIX: + matrix_transpose(TOP(texture_matrix[glstate->texture.active]), params); + break; + case GL_PROJECTION_MATRIX: + memcpy(params, TOP(projection_matrix), 16*sizeof(GLfloat)); + break; + case GL_MODELVIEW_MATRIX: + memcpy(params, TOP(modelview_matrix), 16*sizeof(GLfloat)); + break; + case GL_TEXTURE_MATRIX: + memcpy(params, TOP(texture_matrix[glstate->texture.active]), 16*sizeof(GLfloat)); + break; + case GL_LIGHT_MODEL_AMBIENT: + memcpy(params, glstate->light.ambient, 4*sizeof(GLfloat)); + break; + case GL_FOG_COLOR: + memcpy(params, glstate->fog.color, 4*sizeof(GLfloat)); + break; + case GL_CURRENT_COLOR: + memcpy(params, glstate->color, 4*sizeof(GLfloat)); + break; + case GL_CURRENT_SECONDARY_COLOR: + memcpy(params, glstate->secondary, 4*sizeof(GLfloat)); + break; + case GL_CURRENT_NORMAL: + memcpy(params, glstate->normal, 3*sizeof(GLfloat)); + break; + case GL_CURRENT_TEXTURE_COORDS: + memcpy(params, glstate->texcoord[glstate->texture.active], 4*sizeof(GLfloat)); + break; + case GL_COLOR_WRITEMASK: + for (int dummy=0; dummy<4; dummy++) + params[dummy] = glstate->colormask[dummy]; + break; + case GL_POINT_DISTANCE_ATTENUATION : + memcpy(params, glstate->pointsprite.distance, 3*sizeof(GLfloat)); + break; + case GL_DEPTH_RANGE: + params[0] = glstate->depth.near; + params[1] = glstate->depth.far; + break; + default: + errorGL(); + gles_glGetFloatv(pname, params); + } +} +void glGetFloatv(GLenum pname, GLfloat *params) AliasExport("gl4es_glGetFloatv"); + +void gl4es_glGetDoublev(GLenum pname, GLdouble *params) { + GLfloat tmp[4*4]; + LOAD_GLES(glGetFloatv); + noerrorShim(); + if (gl4es_commonGet(pname, tmp)) { + *params = *tmp; + return; + } + switch (pname) { + case GL_POINT_SIZE_RANGE: + gles_glGetFloatv(GL_POINT_SIZE_MIN, tmp); + gles_glGetFloatv(GL_POINT_SIZE_MAX, tmp+1); + params[0] = tmp[0]; params[1] = tmp[1]; + break; + case GL_TRANSPOSE_PROJECTION_MATRIX: + matrix_transpose(TOP(projection_matrix), tmp); + for(int i=0; i<16; i++) params[i] = tmp[i]; + break; + case GL_TRANSPOSE_MODELVIEW_MATRIX: + matrix_transpose(TOP(modelview_matrix), tmp); + for(int i=0; i<16; i++) params[i] = tmp[i]; + break; + case GL_TRANSPOSE_TEXTURE_MATRIX: + matrix_transpose(TOP(texture_matrix[glstate->texture.active]), tmp); + for(int i=0; i<16; i++) params[i] = tmp[i]; + break; + case GL_PROJECTION_MATRIX: + memcpy(tmp, TOP(projection_matrix), 16*sizeof(GLfloat)); + for(int i=0; i<16; i++) params[i] = tmp[i]; + break; + case GL_MODELVIEW_MATRIX: + memcpy(tmp, TOP(modelview_matrix), 16*sizeof(GLfloat)); + for(int i=0; i<16; i++) params[i] = tmp[i]; + break; + case GL_TEXTURE_MATRIX: + memcpy(tmp, TOP(texture_matrix[glstate->texture.active]), 16*sizeof(GLfloat)); + for(int i=0; i<16; i++) params[i] = tmp[i]; + break; + case GL_LIGHT_MODEL_AMBIENT: + memcpy(tmp, glstate->light.ambient, 4*sizeof(GLfloat)); + for(int i=0; i<4; i++) params[i] = tmp[i]; + break; + case GL_FOG_COLOR: + memcpy(tmp, glstate->fog.color, 4*sizeof(GLfloat)); + for(int i=0; i<4; i++) params[i] = tmp[i]; + break; + case GL_CURRENT_COLOR: + memcpy(tmp, glstate->color, 4*sizeof(GLfloat)); + for(int i=0; i<4; i++) params[i] = tmp[i]; + break; + case GL_CURRENT_SECONDARY_COLOR: + memcpy(tmp, glstate->secondary, 4*sizeof(GLfloat)); + for(int i=0; i<4; i++) params[i] = tmp[i]; + break; + case GL_CURRENT_NORMAL: + memcpy(tmp, glstate->normal, 3*sizeof(GLfloat)); + for(int i=0; i<3; i++) params[i] = tmp[i]; + break; + case GL_CURRENT_TEXTURE_COORDS: + memcpy(tmp, glstate->texcoord[glstate->texture.active], 4*sizeof(GLfloat)); + for(int i=0; i<4; i++) params[i] = tmp[i]; + break; + case GL_COLOR_WRITEMASK: + for (int dummy=0; dummy<4; dummy++) + params[dummy] = glstate->colormask[dummy]; + break; + case GL_POINT_DISTANCE_ATTENUATION : + memcpy(tmp, glstate->pointsprite.distance, 3*sizeof(GLfloat)); + for(int i=0; i<3; i++) params[i] = tmp[i]; + break; + case GL_DEPTH_RANGE: + params[0] = glstate->depth.near; + params[1] = glstate->depth.far; + break; + default: + errorGL(); + gles_glGetFloatv(pname, tmp); + params[0] = tmp[0]; + } +} +void glGetDoublev(GLenum pname, GLdouble *params) AliasExport("gl4es_glGetDoublev"); + +void gl4es_glGetLightfv(GLenum light, GLenum pname, GLfloat * params) { + const int nl = light-GL_LIGHT0; + if(nl<0 || nl>=hardext.maxlights) { + errorShim(GL_INVALID_ENUM); + return; + } + switch(pname) { + case GL_AMBIENT: + memcpy(params, glstate->light.lights[nl].ambient, 4*sizeof(GLfloat)); + break; + case GL_DIFFUSE: + memcpy(params, glstate->light.lights[nl].diffuse, 4*sizeof(GLfloat)); + break; + case GL_SPECULAR: + memcpy(params, glstate->light.lights[nl].specular, 4*sizeof(GLfloat)); + break; + case GL_POSITION: + memcpy(params, glstate->light.lights[nl].position, 4*sizeof(GLfloat)); + break; + case GL_SPOT_DIRECTION: + memcpy(params, glstate->light.lights[nl].spotDirection, 3*sizeof(GLfloat)); + break; + case GL_SPOT_EXPONENT: + params[0] = glstate->light.lights[nl].spotExponent; + break; + case GL_SPOT_CUTOFF: + params[0] = glstate->light.lights[nl].spotCutoff; + break; + case GL_CONSTANT_ATTENUATION: + params[0] = glstate->light.lights[nl].constantAttenuation; + break; + case GL_LINEAR_ATTENUATION: + params[0] = glstate->light.lights[nl].linearAttenuation; + break; + case GL_QUADRATIC_ATTENUATION: + params[0] = glstate->light.lights[nl].quadraticAttenuation; + break; + default: + errorShim(GL_INVALID_ENUM); + return; + } + noerrorShim(); +} +void glGetLightfv(GLenum light, GLenum pname, GLfloat * params) AliasExport("gl4es_glGetLightfv"); + +void gl4es_glGetMaterialfv(GLenum face, GLenum pname, GLfloat * params) { + if(face!=GL_FRONT && face!=GL_BACK) { + errorShim(GL_INVALID_ENUM); + return; + } + switch(pname) { + case GL_AMBIENT: + if(face==GL_FRONT) + memcpy(params, glstate->material.front.ambient, 4*sizeof(GLfloat)); + if(face==GL_BACK) + memcpy(params, glstate->material.back.ambient, 4*sizeof(GLfloat)); + break; + case GL_DIFFUSE: + if(face==GL_FRONT) + memcpy(params, glstate->material.front.diffuse, 4*sizeof(GLfloat)); + if(face==GL_BACK) + memcpy(params, glstate->material.back.diffuse, 4*sizeof(GLfloat)); + break; + case GL_SPECULAR: + if(face==GL_FRONT) + memcpy(params, glstate->material.front.specular, 4*sizeof(GLfloat)); + if(face==GL_BACK) + memcpy(params, glstate->material.back.specular, 4*sizeof(GLfloat)); + break; + case GL_EMISSION: + if(face==GL_FRONT) + memcpy(params, glstate->material.front.emission, 4*sizeof(GLfloat)); + if(face==GL_BACK) + memcpy(params, glstate->material.back.emission, 4*sizeof(GLfloat)); + break; + case GL_SHININESS: + if(face==GL_FRONT) + *params = glstate->material.front.shininess; + if(face==GL_BACK) + *params = glstate->material.back.shininess; + break; + case GL_COLOR_INDEXES: + if(face==GL_FRONT) { + params[0] = glstate->material.front.indexes[0]; + params[1] = glstate->material.front.indexes[1]; + params[2] = glstate->material.front.indexes[2]; + } + if(face==GL_BACK) { + params[0] = glstate->material.back.indexes[0]; + params[1] = glstate->material.back.indexes[1]; + params[2] = glstate->material.back.indexes[2]; + } + default: + errorShim(GL_INVALID_ENUM); + return; + } + noerrorShim(); +} +void glGetMaterialfv(GLenum face, GLenum pname, GLfloat * params) AliasExport("gl4es_glGetMaterialfv"); + +void gl4es_glGetClipPlanef(GLenum plane, GLfloat * equation) +{ + if(plane=GL_CLIP_PLANE0+hardext.maxplanes) { + errorShim(GL_INVALID_ENUM); + return; + } + LOAD_GLES2(glGetClipPlanef); + if(gles_glGetClipPlanef) + { + errorGL(); + gles_glGetClipPlanef(plane, equation); + } else { + int p = plane-GL_CLIP_PLANE0; + noerrorShim(); + memcpy(equation, glstate->planes[p], 4*sizeof(GLfloat)); // should return transformed coordinates + } +} +void glGetClipPlanef(GLenum plane, GLfloat * equation) AliasExport("gl4es_glGetClipPlanef"); + + +const GLubyte *gl4es_glGetStringi(GLenum name, GLuint index) { + BuildExtensionsList(); + if (name!=GL_EXTENSIONS) { + errorShim(GL_INVALID_ENUM); + return NULL; + } + if (index<0 || index>=num_extensions) { + errorShim(GL_INVALID_VALUE); + return NULL; + } + return extensions_list[index]; +} +const GLubyte *glGetStringi(GLenum name, GLuint index) AliasExport("gl4es_glGetStringi"); \ No newline at end of file diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/gl4es.c b/Projects/Android/jni/SupportLibs/gl4es/src/gl/gl4es.c new file mode 100644 index 0000000..fb65729 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/gl4es.c @@ -0,0 +1,1102 @@ +#include "gl4es.h" + +#if defined(AMIGAOS4) || (defined(NOX11) && defined(NOEGL)) +#include +#endif // defined(AMIGAOS4) || (defined(NOX11) && defined(NOEGL)) + +#include "../config.h" +#include "../glx/hardext.h" +#include "wrap/gl4es.h" +#include "array.h" +#include "debug.h" +#include "enum_info.h" +#include "fpe.h" +#include "framebuffers.h" +#include "glstate.h" +#include "init.h" +#include "loader.h" +#include "matrix.h" + +int adjust_vertices(GLenum mode, int nb) { + switch (mode) { + case GL_POINTS: + return nb; + case GL_LINES: // 2 points per elements + return nb-(nb%2); + case GL_LINE_STRIP: // at least 2 points + case GL_LINE_LOOP: + return (nb>1)?nb:0; + case GL_TRIANGLES: // 3 points per elements + return nb-(nb%3); + case GL_TRIANGLE_FAN: + case GL_TRIANGLE_STRIP: // at least 3 points + return (nb>2)?nb:0; + case GL_QUADS: // 4 points per elements + return nb-(nb%4); + case GL_QUAD_STRIP: // at least 4, the 2 per elements + return (nb>4)?(nb-(nb%2)):0; + case GL_POLYGON: // at least 3 + return (nb>2)?nb:0; + default: + return nb; // meh? + } +} + +#undef client_state +#define clone_gl_pointer(t, s)\ + t.size = s; t.type = type; t.stride = stride; t.pointer = pointer + (uintptr_t)((glstate->vao->vertex)?glstate->vao->vertex->data:0) +void gl4es_glVertexPointer(GLint size, GLenum type, + GLsizei stride, const GLvoid *pointer) { + if(size<1 || size>4) { + errorShim(GL_INVALID_VALUE); + return; + } + noerrorShim(); + clone_gl_pointer(glstate->vao->pointers[ATT_VERTEX], size); +} +void gl4es_glColorPointer(GLint size, GLenum type, + GLsizei stride, const GLvoid *pointer) { + if (!((size>0 && size<=4) || (size==GL_BGRA && type==GL_UNSIGNED_BYTE))) { + errorShim(GL_INVALID_VALUE); + return; + } + noerrorShim(); + clone_gl_pointer(glstate->vao->pointers[ATT_COLOR], size); +} +void gl4es_glNormalPointer(GLenum type, GLsizei stride, const GLvoid *pointer) { + noerrorShim(); + clone_gl_pointer(glstate->vao->pointers[ATT_NORMAL], 3); +} +void gl4es_glTexCoordPointer(GLint size, GLenum type, + GLsizei stride, const GLvoid *pointer) { + if(size<1 || size>4) { + errorShim(GL_INVALID_VALUE); + return; + } + noerrorShim(); + clone_gl_pointer(glstate->vao->pointers[ATT_MULTITEXCOORD0+glstate->texture.client], size); +} +void gl4es_glSecondaryColorPointer(GLint size, GLenum type, + GLsizei stride, const GLvoid *pointer) { + if (!(size==3 || (size==GL_BGRA && type==GL_UNSIGNED_BYTE))) { + errorShim(GL_INVALID_VALUE); + return; // Size must be 3... + } + clone_gl_pointer(glstate->vao->pointers[ATT_SECONDARY], size); + noerrorShim(); +} +void gl4es_glFogCoordPointer(GLenum type, GLsizei stride, const GLvoid *pointer) { + if(type==1 && stride==GL_FLOAT) { + type = GL_FLOAT; + stride = 0; // mistake found in some version of openglide... + } + clone_gl_pointer(glstate->vao->pointers[ATT_FOGCOORD], 1); + noerrorShim(); +} + +#undef clone_gl_pointer + +void glVertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer) AliasExport("gl4es_glVertexPointer"); +void glColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer) AliasExport("gl4es_glColorPointer"); +void glNormalPointer(GLenum type, GLsizei stride, const GLvoid *pointer) AliasExport("gl4es_glNormalPointer"); +void glTexCoordPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer) AliasExport("gl4es_glTexCoordPointer"); +void glSecondaryColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer) AliasExport("gl4es_glSecondaryColorPointer"); +void glFogCoordPointer(GLenum type, GLsizei stride, const GLvoid *pointer) AliasExport("gl4es_glFogCoordPointer"); +void glSecondaryColorPointerEXT(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer) AliasExport("gl4es_glSecondaryColorPointer"); +void glFogCoordPointerEXT(GLenum type, GLsizei stride, const GLvoid *pointer) AliasExport("gl4es_glFogCoordPointer"); + + +void gl4es_glInterleavedArrays(GLenum format, GLsizei stride, const GLvoid *pointer) { + uintptr_t ptr = (uintptr_t)pointer; + // element lengths + GLsizei tex=0, color=0, normal=0, vert=0; + // element formats + GLenum tf, cf, nf, vf; + tf = cf = nf = vf = GL_FLOAT; + noerrorShim(); + switch (format) { + case GL_V2F: vert = 2; break; + case GL_V3F: vert = 3; break; + case GL_C4UB_V2F: + color = 4; cf = GL_UNSIGNED_BYTE; + vert = 2; + break; + case GL_C4UB_V3F: + color = 4; cf = GL_UNSIGNED_BYTE; + vert = 3; + break; + case GL_C3F_V3F: + color = 3; + vert = 4; + break; + case GL_N3F_V3F: + normal = 3; + vert = 3; + break; + case GL_C4F_N3F_V3F: + color = 4; + normal = 3; + vert = 3; + break; + case GL_T2F_V3F: + tex = 2; + vert = 3; + break; + case GL_T4F_V4F: + tex = 4; + vert = 4; + break; + case GL_T2F_C4UB_V3F: + tex = 2; + color = 4; cf = GL_UNSIGNED_BYTE; + vert = 3; + break; + case GL_T2F_C3F_V3F: + tex = 2; + color = 3; + vert = 3; + break; + case GL_T2F_N3F_V3F: + tex = 2; + normal = 3; + vert = 3; + break; + case GL_T2F_C4F_N3F_V3F: + tex = 2; + color = 4; + normal = 3; + vert = 3; + break; + case GL_T4F_C4F_N3F_V4F: + tex = 4; + color = 4; + normal = 3; + vert = 4; + break; + default: + errorShim(GL_INVALID_ENUM); + return; + } + if (!stride) + stride = tex * gl_sizeof(tf) + + color * gl_sizeof(cf) + + normal * gl_sizeof(nf) + + vert * gl_sizeof(vf); + if (tex) { + gl4es_glEnableClientState(GL_TEXTURE_COORD_ARRAY); + gl4es_glTexCoordPointer(tex, tf, stride, (GLvoid *)ptr); + ptr += tex * gl_sizeof(tf); + } + if (color) { + gl4es_glEnableClientState(GL_COLOR_ARRAY); + gl4es_glColorPointer(color, cf, stride, (GLvoid *)ptr); + ptr += color * gl_sizeof(cf); + } + if (normal) { + gl4es_glEnableClientState(GL_NORMAL_ARRAY); + gl4es_glNormalPointer(nf, stride, (GLvoid *)ptr); + ptr += normal * gl_sizeof(nf); + } + if (vert) { + gl4es_glEnableClientState(GL_VERTEX_ARRAY); + gl4es_glVertexPointer(vert, vf, stride, (GLvoid *)ptr); + } +} +void glInterleavedArrays(GLenum format, GLsizei stride, const GLvoid *pointer) AliasExport("gl4es_glInterleavedArrays"); + +// immediate mode functions +void gl4es_glBegin(GLenum mode) { + glstate->list.begin = 1; + if (!glstate->list.active) + glstate->list.active = alloc_renderlist(); + // small optim... continue a render command if possible + glstate->list.active = NewDrawStage(glstate->list.active, mode); + glstate->list.pending = 0; + noerrorShim(); // TODO, check Enum validity +} +void glBegin(GLenum mode) AliasExport("gl4es_glBegin"); + +void gl4es_glEnd() { + if (!glstate->list.active) return; + glstate->list.begin = 0; + // check if TEXTUREx is activate and no TexCoord (or texgen), in that case, create a dummy one base on glstate->.. + for (int a=0; aenable.texture[a] && ((glstate->list.active->tex[a]==0) && !(glstate->enable.texgen_s[a] || glstate->texture.pscoordreplace[a]))) + rlMultiTexCoord4f(glstate->list.active, GL_TEXTURE0+a, glstate->texcoord[a][0], glstate->texcoord[a][1], glstate->texcoord[a][2], glstate->texcoord[a][3]); + rlEnd(glstate->list.active); // end the list now + // render if we're not in a display list + int withColor = 0; + if(glstate->list.compiling) { + glstate->list.active = extend_renderlist(glstate->list.active); + } else { + if (!globals4es.beginend /*|| (glstate->polygon_mode==GL_LINE)*/) { + renderlist_t *mylist = glstate->list.active; + withColor = (mylist->color!=NULL); + glstate->list.active = NULL; + mylist = end_renderlist(mylist); + draw_renderlist(mylist); + free_renderlist(mylist); + } else { + withColor = (glstate->list.active->color!=NULL); + glstate->list.pending = 1; + NewStage(glstate->list.active, STAGE_POSTDRAW); + } + } + if(withColor) + gl4es_glColor4f(glstate->color[0], glstate->color[1], glstate->color[2], glstate->color[3]); + noerrorShim(); +} +void glEnd() AliasExport("gl4es_glEnd"); + +void gl4es_glNormal3f(GLfloat nx, GLfloat ny, GLfloat nz) { + if (glstate->list.active) { + if (glstate->list.active->stage != STAGE_DRAW) { + if (glstate->list.compiling && glstate->list.active) { + glstate->list.active->lastNormal[0] = nx; glstate->list.active->lastNormal[1] = ny; glstate->list.active->lastNormal[2] = nz; + } else if (glstate->list.pending && glstate->list.active->stage==STAGE_POSTDRAW) { + glstate->list.active->post_normals[0] = nx; glstate->list.active->post_normals[1] = ny; + glstate->list.active->post_normals[2] = nz; + glstate->list.active->post_normal = 1; + return; + } + + PUSH_IF_COMPILING(glNormal3f); + } else { + rlNormal3f(glstate->list.active, nx, ny, nz); + glstate->list.active->lastNormal[0] = nx; glstate->list.active->lastNormal[1] = ny; glstate->list.active->lastNormal[2] = nz; + noerrorShim(); + } + } + else { + LOAD_GLES_FPE(glNormal3f); + errorGL(); + gles_glNormal3f(nx, ny, nz); + } + glstate->normal[0] = nx; glstate->normal[1] = ny; glstate->normal[2] = nz; +} +void glNormal3f(GLfloat nx, GLfloat ny, GLfloat nz) AliasExport("gl4es_glNormal3f"); + +void gl4es_glNormal3fv(GLfloat* v) { + if (glstate->list.active) { + if (glstate->list.active->stage != STAGE_DRAW) { + if (glstate->list.compiling && glstate->list.active) { + memcpy(glstate->list.active->lastNormal, v, 3*sizeof(GLfloat)); + } else if (glstate->list.pending && glstate->list.active->stage==STAGE_POSTDRAW) { + memcpy(glstate->list.active->post_normals, v, 3*sizeof(GLfloat)); + glstate->list.active->post_normal = 1; + return; + } + + if (!glstate->list.pending) + return gl4es_glNormal3f(v[0], v[1], v[2]); // this will put the call on the stack in the current list + } else { + rlNormal3fv(glstate->list.active, v); + memcpy(glstate->list.active->lastNormal, v, 3*sizeof(GLfloat)); + noerrorShim(); + } + } + else { + LOAD_GLES_FPE(glNormal3f); + errorGL(); + gles_glNormal3f(v[0], v[1], v[2]); + } + memcpy(glstate->normal, v, 3*sizeof(GLfloat)); +} +void glNormal3fv(GLfloat* v) AliasExport("gl4es_glNormal3fv"); + +void gl4es_glVertex4f(GLfloat x, GLfloat y, GLfloat z, GLfloat w) { + if (glstate->list.active) { + rlVertex4f(glstate->list.active, x, y, z, w); + noerrorShim(); + } else { + glstate->vertex[0]=x; glstate->vertex[1]=y; glstate->vertex[2]=z; glstate->vertex[3]=w; + } +} +void glVertex4f(GLfloat x, GLfloat y, GLfloat z, GLfloat w) AliasExport("gl4es_glVertex4f"); + +void gl4es_glVertex3fv(GLfloat* v) { + if (glstate->list.active) { + rlVertex3fv(glstate->list.active, v); + noerrorShim(); + } else { + memcpy(glstate->vertex, v, 3*sizeof(GLfloat)); + glstate->vertex[3]=1.f; + } +} +void glVertex3fv(GLfloat* v) AliasExport("gl4es_glVertex3fv"); + +void gl4es_glVertex4fv(GLfloat* v) { + if (glstate->list.active) { + rlVertex4fv(glstate->list.active, v); + noerrorShim(); + } else { + memcpy(glstate->vertex, v, 3*sizeof(GLfloat)); + glstate->vertex[3]=1.f; + } +} +void glVertex4fv(GLfloat* v) AliasExport("gl4es_glVertex4fv"); + +void gl4es_glColor4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) { + if (glstate->list.active) { + if (glstate->list.active->stage != STAGE_DRAW) { + if (glstate->list.compiling || glstate->list.active->stagelist.active->lastColors[0] = red; glstate->list.active->lastColors[1] = green; + glstate->list.active->lastColors[2] = blue; glstate->list.active->lastColors[3] = alpha; + glstate->list.active->lastColorsSet = 1; + } + else if (glstate->list.pending && glstate->list.active->stage==STAGE_POSTDRAW) { + glstate->list.active->post_colors[0] = red; glstate->list.active->post_colors[1] = green; + glstate->list.active->post_colors[2] = blue; glstate->list.active->post_colors[3] = alpha; + glstate->list.active->post_color = 1; + return; + } + PUSH_IF_COMPILING(glColor4f); + } else { + rlColor4f(glstate->list.active, red, green, blue, alpha); + noerrorShim(); + } + } else { + LOAD_GLES_FPE(glColor4f); + errorGL(); + gles_glColor4f(red, green, blue, alpha); + } + // change the state last thing + glstate->color[0] = red; glstate->color[1] = green; + glstate->color[2] = blue; glstate->color[3] = alpha; +} +void glColor4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) AliasExport("gl4es_glColor4f"); + +void gl4es_glColor4fv(GLfloat* v) { + if (glstate->list.active) { + if (glstate->list.active->stage != STAGE_DRAW) { + if (glstate->list.compiling || glstate->list.active->stagelist.active->lastColors, v, 4*sizeof(GLfloat)); + glstate->list.active->lastColorsSet = 1; + } + else if (glstate->list.pending && glstate->list.active->stage==STAGE_POSTDRAW) { + memcpy(glstate->list.active->post_colors, v, 4*sizeof(GLfloat)); + glstate->list.active->post_color = 1; + return; + } + if (!glstate->list.pending) + return gl4es_glColor4f(v[0], v[1], v[2], v[3]); + } else { + rlColor4fv(glstate->list.active, v); + noerrorShim(); + } + } else { + LOAD_GLES_FPE(glColor4f); + errorGL(); + gles_glColor4f(v[0], v[1], v[2], v[3]); + } + // change the state last thing + memcpy(glstate->color, v, 4*sizeof(GLfloat)); +} +void glColor4fv(GLfloat* v) AliasExport("gl4es_glColor4fv"); + +void gl4es_glSecondaryColor3f(GLfloat r, GLfloat g, GLfloat b) { + if (glstate->list.active) { + if(glstate->list.pending) + flush(); + else + { + rlSecondary3f(glstate->list.active, r, g, b); + glstate->list.active->lastSecondaryColors[0] = r; glstate->list.active->lastSecondaryColors[1] = g; + glstate->list.active->lastSecondaryColors[2] = b; + } + noerrorShim(); + } else { + noerrorShim(); + } + // change the state last thing + glstate->secondary[0] = r; glstate->secondary[1] = g; + glstate->secondary[2] = b; +} +void glSecondaryColor3f(GLfloat r, GLfloat g, GLfloat b) AliasExport("gl4es_glSecondaryColor3f"); +void glSecondaryColor3fEXT(GLfloat r, GLfloat g, GLfloat b) AliasExport("gl4es_glSecondaryColor3f"); + + +void gl4es_glTexCoord4f(GLfloat s, GLfloat t, GLfloat r, GLfloat q) { + if (glstate->list.active) { + if(glstate->list.pending) + flush(); + else { + // test if called between glBegin / glEnd but Texture is not active and not using a program. In that case, ignore the call + if(hardext.esversion==1 || glstate->glsl->program || (glstate->list.begin && (glstate->list.compiling || glstate->enable.texture[0]))) + rlMultiTexCoord4f(glstate->list.active, GL_TEXTURE0, s, t, r, q); + } + } + noerrorShim(); + glstate->texcoord[0][0] = s; glstate->texcoord[0][1] = t; + glstate->texcoord[0][2] = r; glstate->texcoord[0][3] = q; +} +void glTexCoord4f(GLfloat s, GLfloat t, GLfloat r, GLfloat q) AliasExport("gl4es_glTexCoord4f"); + +void gl4es_glMultiTexCoord4f(GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q) { + // TODO, error if target is unsuported texture.... + if (glstate->list.active) { + if(glstate->list.pending) + flush(); + else { + // test if called between glBegin / glEnd but Texture is not active. In that case, ignore the call + if(hardext.esversion==1 || (glstate->list.begin && (glstate->list.compiling || glstate->enable.texture[target-GL_TEXTURE0]))) + rlMultiTexCoord4f(glstate->list.active, target, s, t, r, q); + } + } + noerrorShim(); + glstate->texcoord[target-GL_TEXTURE0][0] = s; glstate->texcoord[target-GL_TEXTURE0][1] = t; + glstate->texcoord[target-GL_TEXTURE0][2] = r; glstate->texcoord[target-GL_TEXTURE0][3] = q; +} +void glMultiTexCoord4f(GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q) AliasExport("gl4es_glMultiTexCoord4f"); +void glMultiTexCoord4fARB(GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q) AliasExport("gl4es_glMultiTexCoord4f"); + +void gl4es_glMultiTexCoord2fv(GLenum target, GLfloat* v) { + // TODO, error if target is unsuported texture.... + if (glstate->list.active) { + if(glstate->list.pending) + flush(); + else { + // test if called between glBegin / glEnd but Texture is not active. In that case, ignore the call + if(hardext.esversion==1 || (glstate->list.begin && (glstate->list.compiling || glstate->enable.texture[target-GL_TEXTURE0]))) + rlMultiTexCoord2fv(glstate->list.active, target, v); + } + } + noerrorShim(); + memcpy(glstate->texcoord[target-GL_TEXTURE0], v, 2*sizeof(GLfloat)); + glstate->texcoord[target-GL_TEXTURE0][2] = 0.f; glstate->texcoord[target-GL_TEXTURE0][3] = 1.f; +} +void glMultiTexCoord2fv(GLenum target, GLfloat* v) AliasExport("gl4es_glMultiTexCoord2fv"); +void glMultiTexCoord2fvARB(GLenum target, GLfloat* v) AliasExport("gl4es_glMultiTexCoord2fv"); + +void gl4es_glMultiTexCoord4fv(GLenum target, GLfloat* v) { + // TODO, error if target is unsuported texture.... + if (glstate->list.active) { + if(glstate->list.pending) + flush(); + else { + // test if called between glBegin / glEnd but Texture is not active. In that case, ignore the call + if(hardext.esversion==1 || (glstate->list.begin && (glstate->list.compiling || glstate->enable.texture[target-GL_TEXTURE0]))) + rlMultiTexCoord4fv(glstate->list.active, target, v); + } + } + noerrorShim(); + memcpy(glstate->texcoord[target-GL_TEXTURE0], v, 4*sizeof(GLfloat)); +} +void glMultiTexCoord4fv(GLenum target, GLfloat* v) AliasExport("gl4es_glMultiTexCoord4fv"); +void glMultiTexCoord4fvARB(GLenum target, GLfloat* v) AliasExport("gl4es_glMultiTexCoord4fv"); + +void gl4es_glArrayElement(GLint i) { + GLfloat *v; + pointer_state_t *p; + glvao_t* vao = glstate->vao; + int stride, size; + p = &vao->pointers[ATT_COLOR]; + if (p->enabled) { + size = p->size; stride = p->stride; + // special fast case for easy stuff... + if(p->type==GL_FLOAT) { + if(stride) + v = (GLfloat*)(((uintptr_t)p->pointer)+i*stride); + else + v = ((GLfloat*)p->pointer)+i*size; + if(size==3) + gl4es_glColor3fv(v); + else + gl4es_glColor4fv(v); + } else if(p->type==GL_UNSIGNED_BYTE) { + GLubyte *b; + if(stride) + b = (GLubyte*)(((uintptr_t)p->pointer)+i*stride); + else + b = ((GLubyte*)p->pointer)+i*size; + if(size==3) + gl4es_glColor3ubv(b); + else + gl4es_glColor4ubv(b); + } else { + v = gl_pointer_index(p, i); + GLfloat scale = 1.0f/gl_max_value(p->type); + // color[3] defaults to 1.0f + if (size < 4) + v[3] = 1.0f; + + // scale color coordinates to a 0 - 1.0 range + for (int i = 0; i < size; i++) { + v[i] *= scale; + } + gl4es_glColor4fv(v); + } + } + p = &vao->pointers[ATT_SECONDARY]; + if (p->enabled) { + v = gl_pointer_index(p, i); + GLfloat scale = 1.0f/gl_max_value(p->type); + + // scale color coordinates to a 0 - 1.0 range + for (int i = 0; i < p->size; i++) { + v[i] *= scale; + } + gl4es_glSecondaryColor3fv(v); + } + p = &vao->pointers[ATT_NORMAL]; + if (p->enabled) { + // special fast case for easy stuff... + if(p->type==GL_FLOAT) { + size = p->size; stride = p->stride; + if(stride) + v = (GLfloat*)(((uintptr_t)p->pointer)+i*stride); + else + v = ((GLfloat*)p->pointer)+i*size; + } else { + v = gl_pointer_index(p, i); + } + gl4es_glNormal3fv(v); + } + p = &vao->pointers[ATT_MULTITEXCOORD0]; + if (p->enabled) { + size = p->size; stride = p->stride; + // special fast case for easy stuff... + if(p->type==GL_FLOAT) { + if(stride) + v = (GLfloat*)(((uintptr_t)p->pointer)+i*stride); + else + v = ((GLfloat*)p->pointer)+i*size; + } else { + v = gl_pointer_index(p, i); + } + if (size<4) + gl4es_glTexCoord2fv(v); + else + gl4es_glTexCoord4fv(v); + } + for (int a=1; amaxtex; a++) { + p = &vao->pointers[ATT_MULTITEXCOORD0+a]; + if (p->enabled) { + size = p->size; stride = p->stride; + // special fast case for easy stuff... + if(p->type==GL_FLOAT) { + if(p->stride) + v = (GLfloat*)(((uintptr_t)p->pointer)+i*p->stride); + else + v = ((GLfloat*)p->pointer)+i*p->size; + } else { + v = gl_pointer_index(p, i); + } + if (p->size<4) + gl4es_glMultiTexCoord2fv(GL_TEXTURE0+a, v); + else + gl4es_glMultiTexCoord4fv(GL_TEXTURE0+a, v); + } + } + p = &vao->pointers[ATT_VERTEX]; + if (p->enabled) { + // special fast case for easy stuff... + if(p->type==GL_FLOAT) { + if(p->stride) + v = (GLfloat*)(((uintptr_t)p->pointer)+i*p->stride); + else + v = ((GLfloat*)p->pointer)+i*p->size; + } else { + v = gl_pointer_index(p, i); + } + if (p->size == 4) { + gl4es_glVertex4fv(v); + } else if (p->size == 3) { + gl4es_glVertex3fv(v); + } else { + gl4es_glVertex2fv(v); + } + } +} +void glArrayElement(GLint i) AliasExport("gl4es_glArrayElement"); +void glArrayElementEXT(GLint i) AliasExport("gl4es_glArrayElement"); + +// TODO: between a lock and unlock, I can assume the array pointers are unchanged +// so I can build a renderlist_t on the first call and hold onto it +// maybe I need a way to call a renderlist_t with (first, count) +void gl4es_glLockArrays(GLint first, GLsizei count) { + glstate->vao->locked = true; + glstate->vao->first = first; + glstate->vao->count = count; + noerrorShim(); +} +void glLockArraysEXT(GLint first, GLsizei count) AliasExport("gl4es_glLockArrays"); +void gl4es_glUnlockArrays() { + glstate->vao->locked = false; + + noerrorShim(); +} +void glUnlockArraysEXT() AliasExport("gl4es_glUnlockArrays"); +// display lists + +static renderlist_t *gl4es_glGetList(GLuint list) { + khint_t k; + int ret; + khash_t(gllisthead) *lists = glstate->headlists; + k = kh_get(gllisthead, lists, list); + if (k != kh_end(lists)) + return kh_value(lists, k); + return NULL; +} + +GLuint gl4es_glGenLists(GLsizei range) { + if (range<0) { + errorShim(GL_INVALID_VALUE); + return 0; + } + noerrorShim(); + khint_t k; + int ret; + khash_t(gllisthead) *lists = glstate->headlists; + int start = glstate->list.count; + glstate->list.count += range; + + for (int i = 0; i < range; i++) { + k = kh_get(gllisthead, lists, start+i); + if (k == kh_end(lists)){ + k = kh_put(gllisthead, lists, start+i, &ret); + kh_value(lists, k) = NULL; // create an empty gllist + } + } + return start + 1; +} +GLuint glGenLists(GLsizei range) AliasExport("gl4es_glGenLists"); + + +void gl4es_glNewList(GLuint list, GLenum mode) { + errorShim(GL_INVALID_VALUE); + if (list==0) + return; + { + khint_t k; + int ret; + khash_t(gllisthead) *lists = glstate->headlists; + k = kh_get(gllisthead, lists, list); + if (k == kh_end(lists)){ + k = kh_put(gllisthead, lists, list, &ret); + kh_value(lists, k) = NULL; + } + } + noerrorShim(); + + glstate->list.name = list; + glstate->list.mode = mode; + // TODO: if glstate->list.active is already defined, we probably need to clean up here + glstate->list.active = alloc_renderlist(); + glstate->list.compiling = true; +} +void glNewList(GLuint list, GLenum mode) AliasExport("gl4es_glNewList"); + +void gl4es_glEndList() { + noerrorShim(); + GLuint list = glstate->list.name; + khash_t(gllisthead) *lists = glstate->headlists; + khint_t k; + { + int ret; + k = kh_get(gllisthead, lists, list); + if (k == kh_end(lists)){ + k = kh_put(gllisthead, lists, list, &ret); + kh_value(lists, k) = NULL; + } + } + if (glstate->list.compiling) { + // Free the previous list if it exist... + free_renderlist(kh_value(lists, k)); + kh_value(lists, k) = GetFirst(glstate->list.active); + glstate->list.compiling = false; + end_renderlist(glstate->list.active); + glstate->list.active = NULL; + + if (glstate->list.mode == GL_COMPILE_AND_EXECUTE) { + glCallList(list); + } + } +} +void glEndList() AliasExport("gl4es_glEndList"); + +renderlist_t* append_calllist(renderlist_t *list, renderlist_t *a); +void gl4es_glCallList(GLuint list) { + noerrorShim(); + if (glstate->list.active) { + glstate->list.active = append_calllist(glstate->list.active, gl4es_glGetList(list)); + return; + } + // TODO: the output of this call can be compiled into another display list + renderlist_t *l = gl4es_glGetList(list); + if (l) + draw_renderlist(l); +} +void glCallList(GLuint list) AliasExport("gl4es_glCallList"); + +void glPushCall(void *call) { + if (glstate->list.active) { + NewStage(glstate->list.active, STAGE_GLCALL); + rlPushCall(glstate->list.active, call); + } +} + +void gl4es_glCallLists(GLsizei n, GLenum type, const GLvoid *lists) { + #define call(name, type) \ + case name: glCallList(((type *)lists)[i] + glstate->list.base); break + + // seriously wtf + #define call_bytes(name, stride) \ + case name: \ + l = (GLubyte *)lists; \ + list = 0; \ + for (j = 0; j < stride; j++) { \ + list += *(l + (i * stride + j)) << (stride - j); \ + } \ + gl4es_glCallList(list + glstate->list.base); \ + break + + unsigned int i, j; + GLuint list; + GLubyte *l; + for (i = 0; i < n; i++) { + switch (type) { + call(GL_BYTE, GLbyte); + call(GL_UNSIGNED_BYTE, GLubyte); + call(GL_SHORT, GLshort); + call(GL_UNSIGNED_SHORT, GLushort); + call(GL_INT, GLint); + call(GL_UNSIGNED_INT, GLuint); + call(GL_FLOAT, GLfloat); + call_bytes(GL_2_BYTES, 2); + call_bytes(GL_3_BYTES, 3); + call_bytes(GL_4_BYTES, 4); + } + } + #undef call + #undef call_bytes +} +void glCallLists(GLsizei n, GLenum type, const GLvoid *lists) AliasExport("gl4es_glCallLists"); + +void gl4es_glDeleteList(GLuint list) { + + renderlist_t *gllist = NULL; + { + khint_t k; + int ret; + khash_t(gllisthead) *lists = glstate->headlists; + k = kh_get(gllisthead, lists, list); + renderlist_t *gllist = NULL; + if (k != kh_end(lists)){ + gllist = kh_value(lists, k); + free_renderlist(gllist); + kh_del(gllisthead, lists, k); + } + } +} + +void gl4es_glDeleteLists(GLuint list, GLsizei range) { + noerrorShim(); + for (int i = 0; i < range; i++) { + gl4es_glDeleteList(list+i); + } +} +void glDeleteLists(GLuint list, GLsizei range) AliasExport("gl4es_glDeleteLists"); + +void gl4es_glListBase(GLuint base) { + noerrorShim(); + glstate->list.base = base; +} +void glListBase(GLuint base) AliasExport("gl4es_glListBase"); + +GLboolean gl4es_glIsList(GLuint list) { + noerrorShim(); + khint_t k; + int ret; + khash_t(gllisthead) *lists = glstate->headlists; + k = kh_get(gllisthead, lists, list); + if (k != kh_end(lists)) + return true; + return false; +} +GLboolean glIsList(GLuint list) AliasExport("gl4es_glIsList"); + +void gl4es_glPolygonMode(GLenum face, GLenum mode) { + ERROR_IN_BEGIN + noerrorShim(); + if (face == GL_FRONT) + face = GL_FRONT_AND_BACK; //TODO, better handle all this + if (face == GL_BACK) + return; //TODO, handle face enum for polygon mode != GL_FILL + if (glstate->list.active) + if (glstate->list.compiling) { + NewStage(glstate->list.active, STAGE_POLYGON); + glstate->list.active->polygon_mode = mode; + return; + } + else flush(); + switch(mode) { + case GL_LINE: + case GL_POINT: + glstate->polygon_mode = mode; + break; + case GL_FILL: + glstate->polygon_mode = 0; + break; + default: + glstate->polygon_mode = 0; + } +} +void glPolygonMode(GLenum face, GLenum mode) AliasExport("gl4es_glPolygonMode"); + + +void flush() { + // flush internal list + renderlist_t *mylist = glstate->list.active?extend_renderlist(glstate->list.active):NULL; + if (mylist) { + glstate->list.active = NULL; + glstate->list.pending = 0; + mylist = end_renderlist(mylist); + draw_renderlist(mylist); + free_renderlist(mylist); + } + glstate->list.active = NULL; +} + +#ifndef NOX11 +extern void BlitEmulatedPixmap(); +#endif +void gl4es_glFlush() { + LOAD_GLES(glFlush); + + realize_textures(); + if (glstate->list.pending) flush(); + if (glstate->raster.bm_drawing) bitmap_flush(); + + gles_glFlush(); + errorGL(); + +#ifndef NOX11 + if(glstate->emulatedPixmap && !glstate->emulatedWin) + BlitEmulatedPixmap(); +#endif +} +void glFlush() AliasExport("gl4es_glFlush"); + +void gl4es_glFinish() { + LOAD_GLES(glFinish); + + realize_textures(); + if (glstate->list.pending) flush(); + if (glstate->raster.bm_drawing) bitmap_flush(); + + gles_glFinish(); + errorGL(); +} +void glFinish() AliasExport("gl4es_glFinish"); + +void gl4es_glIndexPointer(GLenum type, GLsizei stride, const GLvoid * pointer) { + static bool warning = false; + if(!warning) { + LOGD("Warning, stubbed glIndexPointer\n"); + warning = true; + } +} +void glIndexPointer(GLenum type, GLsizei stride, const GLvoid * pointer) AliasExport("gl4es_glIndexPointer"); + +void gl4es_glEdgeFlagPointer(GLsizei stride, const GLvoid * pointer) { + static bool warning = false; + if(!warning) { + LOGD("Warning, stubbed glEdgeFlagPointer\n"); + warning = true; + } +} +void glEdgeFlagPointer(GLsizei stride, const GLvoid * pointer) AliasExport("gl4es_glEdgeFlagPointer"); + + + +void gl4es_glShadeModel(GLenum mode) { + if(mode!=GL_SMOOTH && mode!=GL_FLAT) { + errorShim(GL_INVALID_ENUM); + return; + } + PUSH_IF_COMPILING(glShadeModel); + noerrorShim(); + if(mode==glstate->shademodel) + return; + glstate->shademodel = mode; + LOAD_GLES2(glShadeModel); + if(gles_glShadeModel) { + errorGL(); + gles_glShadeModel(mode); + } +} +void glShadeModel(GLenum mode) AliasExport("gl4es_glShadeModel"); + +void gl4es_glAlphaFunc(GLenum func, GLclampf ref) { + PUSH_IF_COMPILING(glAlphaFunc); + noerrorShim(); + if(ref<0.0f) ref = 0.0f; + if(ref>1.0f) ref = 1.0f; + if(glstate->alphafunc==func && glstate->alpharef==ref) + return; + if(func!=GL_NEVER && func!=GL_LESS && func!=GL_EQUAL + && func!=GL_LEQUAL && func!=GL_GREATER && func!=GL_NOTEQUAL + && func!=GL_ALWAYS && func!=GL_GEQUAL) { + errorShim(GL_INVALID_ENUM); + return; + } + glstate->alphafunc = func; + glstate->alpharef = ref; + LOAD_GLES_FPE(glAlphaFunc); + if(gles_glAlphaFunc) { + errorGL(); + gles_glAlphaFunc(func, ref); + } +} +void glAlphaFunc(GLenum func, GLclampf ref) AliasExport("gl4es_glAlphaFunc"); + +void gl4es_glLogicOp(GLenum opcode) { + PUSH_IF_COMPILING(glLogicOp); + noerrorShim(); + if(glstate->logicop==opcode) + return; + // TODO: test if opcode is valid + glstate->logicop = opcode; + LOAD_GLES2(glLogicOp); + if(gles_glLogicOp) { + errorGL(); + gles_glLogicOp(opcode); + } +} +void glLogicOp(GLenum opcode) AliasExport("gl4es_glLogicOp"); + +void gl4es_glColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha) { + PUSH_IF_COMPILING(glColorMask); + if(glstate->colormask[0]==red && glstate->colormask[1]==green && glstate->colormask[2]==blue && glstate->colormask[3]==alpha) { + noerrorShim(); + return; + } + glstate->colormask[0]=red; + glstate->colormask[1]=green; + glstate->colormask[2]=blue; + glstate->colormask[3]=alpha; + LOAD_GLES(glColorMask); + gles_glColorMask(red, green, blue, alpha); +} +void glColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha) AliasExport("gl4es_glColorMask"); + +void gl4es_glClear(GLbitfield mask) { + PUSH_IF_COMPILING(glClear); + + mask &= GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT; + LOAD_GLES(glClear); + gles_glClear(mask); +} +void glClear(GLbitfield mask) AliasExport("gl4es_glClear"); + +void gl4es_scratch(int alloc) { + if(glstate->scratch_allocscratch) + free(glstate->scratch); + glstate->scratch = malloc(alloc); + glstate->scratch_alloc = alloc; + } +} + +void gl4es_scratch_vertex(int alloc) { + LOAD_GLES(glBufferData); + LOAD_GLES(glBindBuffer); + LOAD_GLES(glGenBuffers); + if(!glstate->scratch_vertex) { + glGenBuffers(1, &glstate->scratch_vertex); + } + gles_glBindBuffer(GL_ARRAY_BUFFER, glstate->scratch_vertex); + if(glstate->scratch_vertex_size < alloc) { + gles_glBufferData(GL_ARRAY_BUFFER, alloc, NULL, GL_DYNAMIC_DRAW); + glstate->scratch_vertex_size = alloc; + } +} + +void gl4es_use_scratch_vertex(int use) { + LOAD_GLES(glBindBuffer); + gles_glBindBuffer(GL_ARRAY_BUFFER, use?glstate->scratch_vertex:0); +} + +void gl4es_scratch_indices(int alloc) { + LOAD_GLES(glBufferData); + LOAD_GLES(glBindBuffer); + LOAD_GLES(glGenBuffers); + if(!glstate->scratch_indices) { + glGenBuffers(1, &glstate->scratch_indices); + } + gles_glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, glstate->scratch_indices); + if(glstate->scratch_indices_size < alloc) { + gles_glBufferData(GL_ELEMENT_ARRAY_BUFFER, alloc, NULL, GL_DYNAMIC_DRAW); + glstate->scratch_indices_size = alloc; + } +} + +void gl4es_use_scratch_indices(int use) { + LOAD_GLES(glBindBuffer); + gles_glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, use?glstate->scratch_indices:0); +} + +#if defined(AMIGAOS4) || (defined(NOX11) && defined(NOEGL)) +#ifdef AMIGAOS4 +void amiga_pre_swap() +#else +__attribute__((visibility("default"))) void gl4es_pre_swap() +#endif +{ + if (glstate->list.active){ + flush(); + } + if (glstate->raster.bm_drawing) + bitmap_flush(); + + if (globals4es.usefbo) { + unbindMainFBO(); + blitMainFBO(0, 0, 0, 0); + // blit the main_fbo before swap + } +} + +#ifdef AMIGAOS4 +void amiga_post_swap() +#else +__attribute__((visibility("default"))) void gl4es_post_swap() +#endif +{ + if (globals4es.showfps) + { + // framerate counter + static float avg, fps = 0; + static int frame1, last_frame, frame, now, current_frames; + struct timeval out; + gettimeofday(&out, NULL); + now = out.tv_sec; + frame++; + current_frames++; + + if (frame == 1) { + frame1 = now; + } else if (frame1 < now) { + if (last_frame < now) { + float change = current_frames / (float)(now - last_frame); + float weight = 0.7; + if (! fps) { + fps = change; + } else { + fps = (1 - weight) * fps + weight * change; + } + current_frames = 0; + + avg = frame / (float)(now - frame1); + printf("LIBGL: fps: %.2f, avg: %.2f\n", fps, avg); + } + } + last_frame = now; + } + + // If drawing in fbo, rebind it... + if (globals4es.usefbo) { + bindMainFBO(); + } +} +#endif diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/gl4es.h b/Projects/Android/jni/SupportLibs/gl4es/src/gl/gl4es.h new file mode 100644 index 0000000..42d16d2 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/gl4es.h @@ -0,0 +1,148 @@ +#ifndef _GL4ES_GL4ES_H_ +#define _GL4ES_GL4ES_H_ + +#include "khash.h" + +#ifdef __ARM_NEON__ +#include +#endif // __ARM_NEON__ + +#include "wrap/gles.h" +#include "gles.h" +#include "glstate.h" + +packed_call_t* glCopyPackedCall(const packed_call_t *packed); + +#define checkError(code) \ + {int error; while ((error = glGetError())) {} \ + code \ + if ((error = glGetError())) \ + printf(#code " -> %i\n", error);} + +#define printError(file, line) \ + {int error; if ((error = glGetError())) \ + printf(file ":%i -> %i\n", line, error);} + +#define FLUSH_BEGINEND if(glstate->list.pending) flush() + +#define ERROR_IN_BEGIN if(glstate->list.begin) {errorShim(GL_INVALID_OPERATION); return;} + +const GLubyte *gl4es_glGetString(GLenum name); +void gl4es_glGetIntegerv(GLenum pname, GLint *params); +void gl4es_glGetFloatv(GLenum pname, GLfloat *params); +void gl4es_glEnable(GLenum cap); +void gl4es_glDisable(GLenum cap); +void gl4es_glEnableClientState(GLenum cap); +void gl4es_glDisableClientState(GLenum cap); +GLboolean gl4es_glIsEnabled(GLenum cap); +void gl4es_glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices); +void gl4es_glDrawArrays(GLenum mode, GLint first, GLsizei count); +void gl4es_glInterleavedArrays(GLenum format, GLsizei stride, const GLvoid *pointer); +void gl4es_glBegin(GLenum mode); +void gl4es_glEnd(); +void gl4es_glNormal3f(GLfloat nx, GLfloat ny, GLfloat nz); +void gl4es_glVertex4f(GLfloat x, GLfloat y, GLfloat z, GLfloat w); +void gl4es_glColor4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); +void gl4es_glSecondaryColor3f(GLfloat r, GLfloat g, GLfloat b); +void gl4es_glMaterialfv(GLenum face, GLenum pname, const GLfloat *params); +void gl4es_glMaterialf(GLenum face, GLenum pname, const GLfloat param); +void gl4es_glTexCoord4f(GLfloat s, GLfloat t, GLfloat r, GLfloat q); +void gl4es_glMultiTexCoord4f(GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q); +void gl4es_glArrayElement(GLint i); +void gl4es_glLockArrays(GLint first, GLsizei count); +void gl4es_glUnlockArrays(); +GLuint gl4es_glGenLists(GLsizei range); +void gl4es_glNewList(GLuint list, GLenum mode); +void gl4es_glEndList(); +void gl4es_glCallList(GLuint list); +void gl4es_glCallLists(GLsizei n, GLenum type, const GLvoid *lists); +void gl4es_glDeleteLists(GLuint list, GLsizei range); +void gl4es_glListBase(GLuint base); +GLboolean gl4es_glIsList(GLuint list); +void gl4es_glPolygonMode(GLenum face, GLenum mode); +GLenum gl4es_glGetError(); + +void gl4es_glSecondaryColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +void gl4es_glIndexPointer(GLenum type, GLsizei stride, const GLvoid * pointer); +void gl4es_glEdgeFlagPointer(GLsizei stride, const GLvoid * pointer); +void gl4es_glGetPointerv(GLenum pname, GLvoid* *params); +void gl4es_glFlush(); +void gl4es_glFinish(); +void gl4es_glFogfv(GLenum pname, const GLfloat* params); + +void gl4es_glStencilMaskSeparate(GLenum face, GLuint mask); + +void gl4es_glMultiDrawArrays(GLenum mode, const GLint *first, const GLsizei *count, GLsizei primcount); +void gl4es_glMultiDrawElements( GLenum mode, GLsizei *count, GLenum type, const void * const *indices, GLsizei primcount); +void gl4es_glMultiDrawElementsBaseVertex( GLenum mode, GLsizei *count, GLenum type, const void * const *indices, GLsizei primcount, const GLint * basevertex); + +void gl4es_glDrawElementsBaseVertex(GLenum mode, GLsizei count, GLenum type, const void *indices, GLint basevertex); +void gl4es_glDrawRangeElementsBaseVertex(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const void *indices, GLint basevertex); + +void gl4es_glDrawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei primcount); +void gl4es_glDrawElementsInstanced(GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei primcount); +void gl4es_glDrawElementsInstancedBaseVertex(GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei primcount, GLint basevertex); + +const GLubyte *gl4es_glGetStringi(GLenum name, GLuint index); + +void flush(); + +int adjust_vertices(GLenum mode, int nb); + +extern glstate_t *glstate; + +void fpe_Init(glstate_t *glstate); // defined in fpe.c +void fpe_Dispose(glstate_t *glstate); // defined in fpe.c + +static inline void errorGL() { // next glGetError will be from GL + glstate->shim_error = 0; +} +static inline void errorShim(GLenum error) { // next glGetError will be "error" from gl4es + glstate->shim_error = 1; + glstate->last_error = error; +} +static inline void noerrorShim() { + errorShim(GL_NO_ERROR); +} + +void gl4es_scratch(int alloc); +void gl4es_scratch_vertex(int alloc); +void gl4es_scratch_indices(int alloc); +void gl4es_use_scratch_vertex(int use); +void gl4es_use_scratch_indices(int use); + +void ToBuffer(int first, int count); + +GLboolean glIsList(GLuint list); +GLuint glGenLists(GLsizei range); +void glActiveTextureARB(GLenum texture); +void glArrayElement(GLint i); +void glBegin(GLenum mode); +void glCallList(GLuint list); +void glCallLists(GLsizei n, GLenum type, const GLvoid *lists); +void glClearDepth(GLdouble depth); +void glDeleteList(GLuint list); +void glDeleteLists(GLuint list, GLsizei range); +void glDrawArrays(GLenum mode, GLint first, GLsizei count); +void glEnd(); +void glEndList(); +void glFrustum(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near, GLdouble far); +void glGetDoublev(GLenum pname, GLdouble *params); +void glIndexf(GLfloat i); +void glInterleavedArrays(GLenum format, GLsizei stride, const GLvoid *pointer); +void glListBase(GLuint base); +void glLockArraysEXT(GLint first, GLsizei count); +void glNewList(GLuint list, GLenum mode); +void glOrtho(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near, GLdouble far); +void glSecondaryColor3f(GLfloat r, GLfloat g, GLfloat b); +void glTexCoord2f(GLfloat s, GLfloat t); +void glUnlockArraysEXT(); +void glVertex2f(GLfloat x, GLfloat y); +void glVertex2i(GLint x, GLint y); +void glVertex3f(GLfloat x, GLfloat y, GLfloat z); +GLenum glGetError(); + +// custom functions +void glPushCall(void *call); + +#endif // _GL4ES_GL4ES_H_ diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/glcase.h b/Projects/Android/jni/SupportLibs/gl4es/src/gl/glcase.h new file mode 100644 index 0000000..e147f94 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/glcase.h @@ -0,0 +1,67 @@ +#ifndef _GL4ES_GLCASE_H_ +#define _GL4ES_GLCASE_H_ + +#define GL_TYPE_CASE(name, var, magic, type, code) \ + case magic: { \ + type *name = (type *)var; \ + code \ + break; \ + } + +#define GL_TYPE_CASE2(name, var, magic, type, code2, code) \ + case magic: { \ + code2 { \ + type *name = (type *)var; \ + code \ + } \ + break; \ + } + +#define GL_TYPE_CASE_MAX(name, var, magic, type, code, max) \ + case magic: { \ + type *name = (type *)var; \ + type maxv = max; \ + code \ + break; \ + } + +#define GL_TYPE_SWITCH(name, var, type, code, extra) \ + switch (type) { \ + GL_TYPE_CASE(name, var, GL_DOUBLE, GLdouble, code) \ + GL_TYPE_CASE(name, var, GL_FLOAT, GLfloat, code) \ + GL_TYPE_CASE(name, var, GL_INT, GLint, code) \ + GL_TYPE_CASE(name, var, GL_SHORT, GLshort, code) \ + GL_TYPE_CASE(name, var, GL_BYTE, GLbyte, code) \ + GL_TYPE_CASE(name, var, GL_UNSIGNED_BYTE, GLubyte, code) \ + GL_TYPE_CASE(name, var, GL_UNSIGNED_INT, GLuint, code) \ + GL_TYPE_CASE(name, var, GL_UNSIGNED_SHORT, GLushort, code) \ + extra \ + } + +#define GL_TYPE_SWITCH2(name, var, type, code2, code, extra) \ + switch (type) { \ + GL_TYPE_CASE2(name, var, GL_DOUBLE, GLdouble, code2, code) \ + GL_TYPE_CASE2(name, var, GL_FLOAT, GLfloat, code2, code) \ + GL_TYPE_CASE2(name, var, GL_INT, GLint, code2, code) \ + GL_TYPE_CASE2(name, var, GL_SHORT, GLshort, code2, code) \ + GL_TYPE_CASE2(name, var, GL_BYTE, GLbyte, code2, code) \ + GL_TYPE_CASE2(name, var, GL_UNSIGNED_BYTE, GLubyte, code2, code) \ + GL_TYPE_CASE2(name, var, GL_UNSIGNED_INT, GLuint, code2, code) \ + GL_TYPE_CASE2(name, var, GL_UNSIGNED_SHORT, GLushort, code2, code) \ + extra \ + } + +#define GL_TYPE_SWITCH_MAX(name, var, type, code, extra) \ + switch (type) { \ + GL_TYPE_CASE_MAX(name, var, GL_DOUBLE, GLdouble, code, 1.0) \ + GL_TYPE_CASE_MAX(name, var, GL_FLOAT, GLfloat, code, 1.0f) \ + GL_TYPE_CASE_MAX(name, var, GL_INT, GLint, code, 2147483647l) \ + GL_TYPE_CASE_MAX(name, var, GL_SHORT, GLshort, code, 32767) \ + GL_TYPE_CASE_MAX(name, var, GL_BYTE, GLbyte, code, 255) \ + GL_TYPE_CASE_MAX(name, var, GL_UNSIGNED_BYTE, GLubyte, code, 127) \ + GL_TYPE_CASE_MAX(name, var, GL_UNSIGNED_INT, GLuint, code, 4294967295l) \ + GL_TYPE_CASE_MAX(name, var, GL_UNSIGNED_SHORT, GLushort, code, 65535) \ + extra \ + } + +#endif // _GL4ES_GLCASE_H_ \ No newline at end of file diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/gles.h b/Projects/Android/jni/SupportLibs/gl4es/src/gl/gles.h new file mode 100644 index 0000000..03d6853 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/gles.h @@ -0,0 +1,1112 @@ +#ifndef _GL4ES_GLES_H_ +#define _GL4ES_GLES_H_ + +#include + +// Define for GLES 1.1 +typedef void GLvoid; +typedef char GLchar; +typedef unsigned int GLenum; +typedef unsigned char GLboolean; +typedef unsigned int GLbitfield; +typedef khronos_int8_t GLbyte; +typedef short GLshort; +typedef int GLint; +typedef int GLsizei; +typedef khronos_uint8_t GLubyte; +typedef unsigned short GLushort; +typedef unsigned int GLuint; +typedef khronos_float_t GLfloat; +typedef khronos_float_t GLclampf; +typedef khronos_int32_t GLfixed; +typedef khronos_int32_t GLclampx; + +typedef khronos_intptr_t GLintptr; +typedef khronos_ssize_t GLsizeiptr; + +typedef double GLdouble; + +typedef unsigned int GLhandleARB; +typedef char GLcharARB; +/*************************************************************/ + +/* OpenGL ES core versions */ +#define GL_VERSION_ES_CM_1_0 1 +#define GL_VERSION_ES_CL_1_0 1 +#define GL_VERSION_ES_CM_1_1 1 +#define GL_VERSION_ES_CL_1_1 1 + +/* ClearBufferMask */ +#define GL_DEPTH_BUFFER_BIT 0x00000100 +#define GL_STENCIL_BUFFER_BIT 0x00000400 +#define GL_COLOR_BUFFER_BIT 0x00004000 + +/* Boolean */ +#define GL_FALSE 0 +#define GL_TRUE 1 + +/* BeginMode */ +#define GL_POINTS 0x0000 +#define GL_LINES 0x0001 +#define GL_LINE_LOOP 0x0002 +#define GL_LINE_STRIP 0x0003 +#define GL_TRIANGLES 0x0004 +#define GL_TRIANGLE_STRIP 0x0005 +#define GL_TRIANGLE_FAN 0x0006 + +/* AlphaFunction */ +#define GL_NEVER 0x0200 +#define GL_LESS 0x0201 +#define GL_EQUAL 0x0202 +#define GL_LEQUAL 0x0203 +#define GL_GREATER 0x0204 +#define GL_NOTEQUAL 0x0205 +#define GL_GEQUAL 0x0206 +#define GL_ALWAYS 0x0207 + +/* BlendingFactorDest */ +#define GL_ZERO 0 +#define GL_ONE 1 +#define GL_SRC_COLOR 0x0300 +#define GL_ONE_MINUS_SRC_COLOR 0x0301 +#define GL_SRC_ALPHA 0x0302 +#define GL_ONE_MINUS_SRC_ALPHA 0x0303 +#define GL_DST_ALPHA 0x0304 +#define GL_ONE_MINUS_DST_ALPHA 0x0305 + +/* BlendingFactorSrc */ +/* GL_ZERO */ +/* GL_ONE */ +#define GL_DST_COLOR 0x0306 +#define GL_ONE_MINUS_DST_COLOR 0x0307 +#define GL_SRC_ALPHA_SATURATE 0x0308 +/* GL_SRC_ALPHA */ +/* GL_ONE_MINUS_SRC_ALPHA */ +/* GL_DST_ALPHA */ +/* GL_ONE_MINUS_DST_ALPHA */ + +/* ClipPlaneName */ +#define GL_CLIP_PLANE0 0x3000 +#define GL_CLIP_PLANE1 0x3001 +#define GL_CLIP_PLANE2 0x3002 +#define GL_CLIP_PLANE3 0x3003 +#define GL_CLIP_PLANE4 0x3004 +#define GL_CLIP_PLANE5 0x3005 + +/* ColorMaterialFace */ +/* GL_FRONT_AND_BACK */ + +/* ColorMaterialParameter */ +/* GL_AMBIENT_AND_DIFFUSE */ + +/* ColorPointerType */ +/* GL_UNSIGNED_BYTE */ +/* GL_FLOAT */ +/* GL_FIXED */ + +/* CullFaceMode */ +#define GL_FRONT 0x0404 +#define GL_BACK 0x0405 +#define GL_FRONT_AND_BACK 0x0408 + +/* DepthFunction */ +/* GL_NEVER */ +/* GL_LESS */ +/* GL_EQUAL */ +/* GL_LEQUAL */ +/* GL_GREATER */ +/* GL_NOTEQUAL */ +/* GL_GEQUAL */ +/* GL_ALWAYS */ + +/* EnableCap */ +#define GL_FOG 0x0B60 +#define GL_LIGHTING 0x0B50 +#define GL_CULL_FACE 0x0B44 +#define GL_ALPHA_TEST 0x0BC0 +#define GL_BLEND 0x0BE2 +#define GL_COLOR_LOGIC_OP 0x0BF2 +#define GL_DITHER 0x0BD0 +#define GL_STENCIL_TEST 0x0B90 +#define GL_DEPTH_TEST 0x0B71 +/* GL_LIGHT0 */ +/* GL_LIGHT1 */ +/* GL_LIGHT2 */ +/* GL_LIGHT3 */ +/* GL_LIGHT4 */ +/* GL_LIGHT5 */ +/* GL_LIGHT6 */ +/* GL_LIGHT7 */ +#define GL_POINT_SMOOTH 0x0B10 +#define GL_LINE_SMOOTH 0x0B20 +#define GL_SCISSOR_TEST 0x0C11 +#define GL_COLOR_MATERIAL 0x0B57 +#define GL_NORMALIZE 0x0BA1 +#define GL_RESCALE_NORMAL 0x803A +#define GL_POLYGON_OFFSET_FILL 0x8037 +#define GL_VERTEX_ARRAY 0x8074 +#define GL_NORMAL_ARRAY 0x8075 +#define GL_COLOR_ARRAY 0x8076 +#define GL_TEXTURE_COORD_ARRAY 0x8078 +#define GL_MULTISAMPLE 0x809D +#define GL_SAMPLE_ALPHA_TO_COVERAGE 0x809E +#define GL_SAMPLE_ALPHA_TO_ONE 0x809F +#define GL_SAMPLE_COVERAGE 0x80A0 + +/* ErrorCode */ +#define GL_NO_ERROR 0 +#define GL_INVALID_ENUM 0x0500 +#define GL_INVALID_VALUE 0x0501 +#define GL_INVALID_OPERATION 0x0502 +#define GL_STACK_OVERFLOW 0x0503 +#define GL_STACK_UNDERFLOW 0x0504 +#define GL_OUT_OF_MEMORY 0x0505 + +/* FogMode */ +/* GL_LINEAR */ +#define GL_EXP 0x0800 +#define GL_EXP2 0x0801 + +/* FogParameter */ +#define GL_FOG_DENSITY 0x0B62 +#define GL_FOG_START 0x0B63 +#define GL_FOG_END 0x0B64 +#define GL_FOG_MODE 0x0B65 +#define GL_FOG_COLOR 0x0B66 + +/* FrontFaceDirection */ +#define GL_CW 0x0900 +#define GL_CCW 0x0901 + +/* GetPName */ +#define GL_CURRENT_COLOR 0x0B00 +#define GL_CURRENT_NORMAL 0x0B02 +#define GL_CURRENT_TEXTURE_COORDS 0x0B03 +#define GL_POINT_SIZE 0x0B11 +#define GL_POINT_SIZE_MIN 0x8126 +#define GL_POINT_SIZE_MAX 0x8127 +#define GL_POINT_FADE_THRESHOLD_SIZE 0x8128 +#define GL_POINT_DISTANCE_ATTENUATION 0x8129 +#define GL_SMOOTH_POINT_SIZE_RANGE 0x0B12 +#define GL_LINE_WIDTH 0x0B21 +#define GL_SMOOTH_LINE_WIDTH_RANGE 0x0B22 +#define GL_ALIASED_POINT_SIZE_RANGE 0x846D +#define GL_ALIASED_LINE_WIDTH_RANGE 0x846E +#define GL_CULL_FACE_MODE 0x0B45 +#define GL_FRONT_FACE 0x0B46 +#define GL_SHADE_MODEL 0x0B54 +#define GL_DEPTH_RANGE 0x0B70 +#define GL_DEPTH_WRITEMASK 0x0B72 +#define GL_DEPTH_CLEAR_VALUE 0x0B73 +#define GL_DEPTH_FUNC 0x0B74 +#define GL_STENCIL_CLEAR_VALUE 0x0B91 +#define GL_STENCIL_FUNC 0x0B92 +#define GL_STENCIL_VALUE_MASK 0x0B93 +#define GL_STENCIL_FAIL 0x0B94 +#define GL_STENCIL_PASS_DEPTH_FAIL 0x0B95 +#define GL_STENCIL_PASS_DEPTH_PASS 0x0B96 +#define GL_STENCIL_REF 0x0B97 +#define GL_STENCIL_WRITEMASK 0x0B98 +#define GL_MATRIX_MODE 0x0BA0 +#define GL_VIEWPORT 0x0BA2 +#define GL_MODELVIEW_STACK_DEPTH 0x0BA3 +#define GL_PROJECTION_STACK_DEPTH 0x0BA4 +#define GL_TEXTURE_STACK_DEPTH 0x0BA5 +#define GL_MODELVIEW_MATRIX 0x0BA6 +#define GL_PROJECTION_MATRIX 0x0BA7 +#define GL_TEXTURE_MATRIX 0x0BA8 +#define GL_ALPHA_TEST_FUNC 0x0BC1 +#define GL_ALPHA_TEST_REF 0x0BC2 +#define GL_BLEND_DST 0x0BE0 +#define GL_BLEND_SRC 0x0BE1 +#define GL_LOGIC_OP_MODE 0x0BF0 +#define GL_SCISSOR_BOX 0x0C10 +#define GL_SCISSOR_TEST 0x0C11 +#define GL_COLOR_CLEAR_VALUE 0x0C22 +#define GL_COLOR_WRITEMASK 0x0C23 +#define GL_UNPACK_ALIGNMENT 0x0CF5 +#define GL_PACK_ALIGNMENT 0x0D05 +#define GL_MAX_LIGHTS 0x0D31 +#define GL_MAX_CLIP_PLANES 0x0D32 +#define GL_MAX_TEXTURE_SIZE 0x0D33 +#define GL_MAX_MODELVIEW_STACK_DEPTH 0x0D36 +#define GL_MAX_PROJECTION_STACK_DEPTH 0x0D38 +#define GL_MAX_TEXTURE_STACK_DEPTH 0x0D39 +#define GL_MAX_VIEWPORT_DIMS 0x0D3A +#define GL_MAX_TEXTURE_UNITS 0x84E2 +#define GL_SUBPIXEL_BITS 0x0D50 +#define GL_RED_BITS 0x0D52 +#define GL_GREEN_BITS 0x0D53 +#define GL_BLUE_BITS 0x0D54 +#define GL_ALPHA_BITS 0x0D55 +#define GL_DEPTH_BITS 0x0D56 +#define GL_STENCIL_BITS 0x0D57 +#define GL_POLYGON_OFFSET_UNITS 0x2A00 +#define GL_POLYGON_OFFSET_FILL 0x8037 +#define GL_POLYGON_OFFSET_FACTOR 0x8038 +#define GL_TEXTURE_BINDING_2D 0x8069 +#define GL_VERTEX_ARRAY_SIZE 0x807A +#define GL_VERTEX_ARRAY_TYPE 0x807B +#define GL_VERTEX_ARRAY_STRIDE 0x807C +#define GL_NORMAL_ARRAY_TYPE 0x807E +#define GL_NORMAL_ARRAY_STRIDE 0x807F +#define GL_COLOR_ARRAY_SIZE 0x8081 +#define GL_COLOR_ARRAY_TYPE 0x8082 +#define GL_COLOR_ARRAY_STRIDE 0x8083 +#define GL_TEXTURE_COORD_ARRAY_SIZE 0x8088 +#define GL_TEXTURE_COORD_ARRAY_TYPE 0x8089 +#define GL_TEXTURE_COORD_ARRAY_STRIDE 0x808A +#define GL_VERTEX_ARRAY_POINTER 0x808E +#define GL_NORMAL_ARRAY_POINTER 0x808F +#define GL_COLOR_ARRAY_POINTER 0x8090 +#define GL_TEXTURE_COORD_ARRAY_POINTER 0x8092 +#define GL_SAMPLE_BUFFERS 0x80A8 +#define GL_SAMPLES 0x80A9 +#define GL_SAMPLE_COVERAGE_VALUE 0x80AA +#define GL_SAMPLE_COVERAGE_INVERT 0x80AB + +/* GetTextureParameter */ +/* GL_TEXTURE_MAG_FILTER */ +/* GL_TEXTURE_MIN_FILTER */ +/* GL_TEXTURE_WRAP_S */ +/* GL_TEXTURE_WRAP_T */ + +#define GL_NUM_COMPRESSED_TEXTURE_FORMATS 0x86A2 +#define GL_COMPRESSED_TEXTURE_FORMATS 0x86A3 + +/* HintMode */ +#define GL_DONT_CARE 0x1100 +#define GL_FASTEST 0x1101 +#define GL_NICEST 0x1102 + +/* HintTarget */ +#define GL_PERSPECTIVE_CORRECTION_HINT 0x0C50 +#define GL_POINT_SMOOTH_HINT 0x0C51 +#define GL_LINE_SMOOTH_HINT 0x0C52 +#define GL_FOG_HINT 0x0C54 +#define GL_GENERATE_MIPMAP_HINT 0x8192 + +/* LightModelParameter */ +#define GL_LIGHT_MODEL_AMBIENT 0x0B53 +#define GL_LIGHT_MODEL_TWO_SIDE 0x0B52 + +/* LightParameter */ +#define GL_AMBIENT 0x1200 +#define GL_DIFFUSE 0x1201 +#define GL_SPECULAR 0x1202 +#define GL_POSITION 0x1203 +#define GL_SPOT_DIRECTION 0x1204 +#define GL_SPOT_EXPONENT 0x1205 +#define GL_SPOT_CUTOFF 0x1206 +#define GL_CONSTANT_ATTENUATION 0x1207 +#define GL_LINEAR_ATTENUATION 0x1208 +#define GL_QUADRATIC_ATTENUATION 0x1209 + +/* DataType */ +#define GL_BYTE 0x1400 +#define GL_UNSIGNED_BYTE 0x1401 +#define GL_SHORT 0x1402 +#define GL_UNSIGNED_SHORT 0x1403 +#define GL_FLOAT 0x1406 +#define GL_FIXED 0x140C + +/* LogicOp */ +#define GL_CLEAR 0x1500 +#define GL_AND 0x1501 +#define GL_AND_REVERSE 0x1502 +#define GL_COPY 0x1503 +#define GL_AND_INVERTED 0x1504 +#define GL_NOOP 0x1505 +#define GL_XOR 0x1506 +#define GL_OR 0x1507 +#define GL_NOR 0x1508 +#define GL_EQUIV 0x1509 +#define GL_INVERT 0x150A +#define GL_OR_REVERSE 0x150B +#define GL_COPY_INVERTED 0x150C +#define GL_OR_INVERTED 0x150D +#define GL_NAND 0x150E +#define GL_SET 0x150F + +/* MaterialFace */ +/* GL_FRONT_AND_BACK */ + +/* MaterialParameter */ +#define GL_EMISSION 0x1600 +#define GL_SHININESS 0x1601 +#define GL_AMBIENT_AND_DIFFUSE 0x1602 +/* GL_AMBIENT */ +/* GL_DIFFUSE */ +/* GL_SPECULAR */ + +/* MatrixMode */ +#define GL_MODELVIEW 0x1700 +#define GL_PROJECTION 0x1701 +#define GL_TEXTURE 0x1702 + +/* NormalPointerType */ +/* GL_BYTE */ +/* GL_SHORT */ +/* GL_FLOAT */ +/* GL_FIXED */ + +/* PixelFormat */ +#define GL_ALPHA 0x1906 +#define GL_RGB 0x1907 +#define GL_RGBA 0x1908 +#define GL_LUMINANCE 0x1909 +#define GL_LUMINANCE_ALPHA 0x190A + +/* PixelStoreParameter */ +#define GL_UNPACK_ALIGNMENT 0x0CF5 +#define GL_PACK_ALIGNMENT 0x0D05 + +/* PixelType */ +/* GL_UNSIGNED_BYTE */ +#define GL_UNSIGNED_SHORT_4_4_4_4 0x8033 +#define GL_UNSIGNED_SHORT_5_5_5_1 0x8034 +#define GL_UNSIGNED_SHORT_5_6_5 0x8363 + +/* ShadingModel */ +#define GL_FLAT 0x1D00 +#define GL_SMOOTH 0x1D01 + +/* StencilFunction */ +/* GL_NEVER */ +/* GL_LESS */ +/* GL_EQUAL */ +/* GL_LEQUAL */ +/* GL_GREATER */ +/* GL_NOTEQUAL */ +/* GL_GEQUAL */ +/* GL_ALWAYS */ + +/* StencilOp */ +/* GL_ZERO */ +#define GL_KEEP 0x1E00 +#define GL_REPLACE 0x1E01 +#define GL_INCR 0x1E02 +#define GL_DECR 0x1E03 +/* GL_INVERT */ + +/* StringName */ +#define GL_VENDOR 0x1F00 +#define GL_RENDERER 0x1F01 +#define GL_VERSION 0x1F02 +#define GL_EXTENSIONS 0x1F03 + +/* TexCoordPointerType */ +/* GL_SHORT */ +/* GL_FLOAT */ +/* GL_FIXED */ +/* GL_BYTE */ + +/* TextureEnvMode */ +#define GL_MODULATE 0x2100 +#define GL_DECAL 0x2101 +/* GL_BLEND */ +#define GL_ADD 0x0104 +/* GL_REPLACE */ + +/* TextureEnvParameter */ +#define GL_TEXTURE_ENV_MODE 0x2200 +#define GL_TEXTURE_ENV_COLOR 0x2201 + +/* TextureEnvTarget */ +#define GL_TEXTURE_ENV 0x2300 + +/* TextureMagFilter */ +#define GL_NEAREST 0x2600 +#define GL_LINEAR 0x2601 + +/* TextureMinFilter */ +/* GL_NEAREST */ +/* GL_LINEAR */ +#define GL_NEAREST_MIPMAP_NEAREST 0x2700 +#define GL_LINEAR_MIPMAP_NEAREST 0x2701 +#define GL_NEAREST_MIPMAP_LINEAR 0x2702 +#define GL_LINEAR_MIPMAP_LINEAR 0x2703 + +/* TextureParameterName */ +#define GL_TEXTURE_MAG_FILTER 0x2800 +#define GL_TEXTURE_MIN_FILTER 0x2801 +#define GL_TEXTURE_WRAP_S 0x2802 +#define GL_TEXTURE_WRAP_T 0x2803 +#define GL_GENERATE_MIPMAP 0x8191 + +/* TextureTarget */ +/* GL_TEXTURE_2D */ + +/* TextureUnit */ +#define GL_TEXTURE0 0x84C0 +#define GL_TEXTURE1 0x84C1 +#define GL_TEXTURE2 0x84C2 +#define GL_TEXTURE3 0x84C3 +#define GL_TEXTURE4 0x84C4 +#define GL_TEXTURE5 0x84C5 +#define GL_TEXTURE6 0x84C6 +#define GL_TEXTURE7 0x84C7 +#define GL_TEXTURE8 0x84C8 +#define GL_TEXTURE9 0x84C9 +#define GL_TEXTURE10 0x84CA +#define GL_TEXTURE11 0x84CB +#define GL_TEXTURE12 0x84CC +#define GL_TEXTURE13 0x84CD +#define GL_TEXTURE14 0x84CE +#define GL_TEXTURE15 0x84CF +#define GL_TEXTURE16 0x84D0 +#define GL_TEXTURE17 0x84D1 +#define GL_TEXTURE18 0x84D2 +#define GL_TEXTURE19 0x84D3 +#define GL_TEXTURE20 0x84D4 +#define GL_TEXTURE21 0x84D5 +#define GL_TEXTURE22 0x84D6 +#define GL_TEXTURE23 0x84D7 +#define GL_TEXTURE24 0x84D8 +#define GL_TEXTURE25 0x84D9 +#define GL_TEXTURE26 0x84DA +#define GL_TEXTURE27 0x84DB +#define GL_TEXTURE28 0x84DC +#define GL_TEXTURE29 0x84DD +#define GL_TEXTURE30 0x84DE +#define GL_TEXTURE31 0x84DF +#define GL_ACTIVE_TEXTURE 0x84E0 +#define GL_CLIENT_ACTIVE_TEXTURE 0x84E1 + +/* TextureWrapMode */ +#define GL_REPEAT 0x2901 +#define GL_CLAMP_TO_EDGE 0x812F + +/* VertexPointerType */ +/* GL_SHORT */ +/* GL_FLOAT */ +/* GL_FIXED */ +/* GL_BYTE */ + +/* LightName */ +#define GL_LIGHT0 0x4000 +#define GL_LIGHT1 0x4001 +#define GL_LIGHT2 0x4002 +#define GL_LIGHT3 0x4003 +#define GL_LIGHT4 0x4004 +#define GL_LIGHT5 0x4005 +#define GL_LIGHT6 0x4006 +#define GL_LIGHT7 0x4007 + +/* Buffer Objects */ +#define GL_ARRAY_BUFFER 0x8892 +#define GL_ELEMENT_ARRAY_BUFFER 0x8893 + +#define GL_ARRAY_BUFFER_BINDING 0x8894 +#define GL_ELEMENT_ARRAY_BUFFER_BINDING 0x8895 +#define GL_VERTEX_ARRAY_BUFFER_BINDING 0x8896 +#define GL_NORMAL_ARRAY_BUFFER_BINDING 0x8897 +#define GL_COLOR_ARRAY_BUFFER_BINDING 0x8898 +#define GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING 0x889A + +#define GL_STATIC_DRAW 0x88E4 +#define GL_DYNAMIC_DRAW 0x88E8 + +#define GL_BUFFER_SIZE 0x8764 +#define GL_BUFFER_USAGE 0x8765 + +/* Texture combine + dot3 */ +#define GL_SUBTRACT 0x84E7 +#define GL_COMBINE 0x8570 +#define GL_COMBINE_RGB 0x8571 +#define GL_COMBINE_ALPHA 0x8572 +#define GL_RGB_SCALE 0x8573 +#define GL_ADD_SIGNED 0x8574 +#define GL_INTERPOLATE 0x8575 +#define GL_CONSTANT 0x8576 +#define GL_PRIMARY_COLOR 0x8577 +#define GL_PREVIOUS 0x8578 +#define GL_OPERAND0_RGB 0x8590 +#define GL_OPERAND1_RGB 0x8591 +#define GL_OPERAND2_RGB 0x8592 +#define GL_OPERAND0_ALPHA 0x8598 +#define GL_OPERAND1_ALPHA 0x8599 +#define GL_OPERAND2_ALPHA 0x859A + +#define GL_ALPHA_SCALE 0x0D1C + +#define GL_SRC0_RGB 0x8580 +#define GL_SRC1_RGB 0x8581 +#define GL_SRC2_RGB 0x8582 +#define GL_SRC0_ALPHA 0x8588 +#define GL_SRC1_ALPHA 0x8589 +#define GL_SRC2_ALPHA 0x858A + +#define GL_DOT3_RGB 0x86AE +#define GL_DOT3_RGBA 0x86AF + +/*------------------------------------------------------------------------* + * required OES extension tokens + *------------------------------------------------------------------------*/ + +/* OES_read_format */ +#ifndef GL_OES_read_format +#define GL_IMPLEMENTATION_COLOR_READ_TYPE_OES 0x8B9A +#define GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES 0x8B9B +#endif + +/* GL_OES_compressed_paletted_texture */ +#ifndef GL_OES_compressed_paletted_texture +#define GL_PALETTE4_RGB8_OES 0x8B90 +#define GL_PALETTE4_RGBA8_OES 0x8B91 +#define GL_PALETTE4_R5_G6_B5_OES 0x8B92 +#define GL_PALETTE4_RGBA4_OES 0x8B93 +#define GL_PALETTE4_RGB5_A1_OES 0x8B94 +#define GL_PALETTE8_RGB8_OES 0x8B95 +#define GL_PALETTE8_RGBA8_OES 0x8B96 +#define GL_PALETTE8_R5_G6_B5_OES 0x8B97 +#define GL_PALETTE8_RGBA4_OES 0x8B98 +#define GL_PALETTE8_RGB5_A1_OES 0x8B99 +#endif + +/* OES_point_size_array */ +#ifndef GL_OES_point_size_array +#define GL_POINT_SIZE_ARRAY_OES 0x8B9C +#define GL_POINT_SIZE_ARRAY_TYPE_OES 0x898A +#define GL_POINT_SIZE_ARRAY_STRIDE_OES 0x898B +#define GL_POINT_SIZE_ARRAY_POINTER_OES 0x898C +#define GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES 0x8B9F +#endif + +/* GL_OES_point_sprite */ +#ifndef GL_OES_point_sprite +#define GL_POINT_SPRITE_OES 0x8861 +#define GL_COORD_REPLACE_OES 0x8862 +#endif + +/* GL_OES_blend_equation_separate */ +#ifndef GL_OES_blend_equation_separate +/* BLEND_EQUATION_RGB_OES same as BLEND_EQUATION_OES */ +#define GL_BLEND_EQUATION_RGB_OES 0x8009 +#define GL_BLEND_EQUATION_ALPHA_OES 0x883D +#endif + +/* GL_OES_blend_func_separate */ +#ifndef GL_OES_blend_func_separate +#define GL_BLEND_DST_RGB_OES 0x80C8 +#define GL_BLEND_SRC_RGB_OES 0x80C9 +#define GL_BLEND_DST_ALPHA_OES 0x80CA +#define GL_BLEND_SRC_ALPHA_OES 0x80CB +#endif + +/* GL_OES_blend_subtract */ +#ifndef GL_OES_blend_subtract +#define GL_BLEND_EQUATION_OES 0x8009 +#define GL_FUNC_ADD_OES 0x8006 +#define GL_FUNC_SUBTRACT_OES 0x800A +#define GL_FUNC_REVERSE_SUBTRACT_OES 0x800B +#endif + +/* GL_OES_compressed_ETC1_RGB8_texture */ +#ifndef GL_OES_compressed_ETC1_RGB8_texture +#define GL_ETC1_RGB8_OES 0x8D64 +#endif + +/* GL_OES_depth24 */ +#ifndef GL_OES_depth24 +#define GL_DEPTH_COMPONENT24_OES 0x81A6 +#endif + +/* GL_OES_depth32 */ +#ifndef GL_OES_depth32 +#define GL_DEPTH_COMPONENT32_OES 0x81A7 +#endif + +/* GL_OES_draw_texture */ +#ifndef GL_OES_draw_texture +#define GL_TEXTURE_CROP_RECT_OES 0x8B9D +#endif + +/* GL_OES_EGL_image */ +#ifndef GL_OES_EGL_image +typedef void* GLeglImageOES; +#endif + +/* GL_OES_EGL_image_external */ +#ifndef GL_OES_EGL_image_external +/* GLeglImageOES defined in GL_OES_EGL_image already. */ +#define GL_TEXTURE_EXTERNAL_OES 0x8D65 +#define GL_TEXTURE_BINDING_EXTERNAL_OES 0x8D67 +#define GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES 0x8D68 +#endif + +/* GL_OES_element_index_uint */ +#ifndef GL_OES_element_index_uint +#define GL_UNSIGNED_INT 0x1405 +#endif + +/* GL_OES_fixed_point */ +#ifndef GL_OES_fixed_point +#define GL_FIXED_OES 0x140C +#endif + +/* GL_OES_framebuffer_object */ +#ifndef GL_OES_framebuffer_object +#define GL_NONE_OES 0 +#define GL_FRAMEBUFFER_OES 0x8D40 +#define GL_RENDERBUFFER_OES 0x8D41 +#define GL_RGBA4_OES 0x8056 +#define GL_RGB5_A1_OES 0x8057 +#define GL_RGB565_OES 0x8D62 +#define GL_DEPTH_COMPONENT16_OES 0x81A5 +#define GL_RENDERBUFFER_WIDTH_OES 0x8D42 +#define GL_RENDERBUFFER_HEIGHT_OES 0x8D43 +#define GL_RENDERBUFFER_INTERNAL_FORMAT_OES 0x8D44 +#define GL_RENDERBUFFER_RED_SIZE_OES 0x8D50 +#define GL_RENDERBUFFER_GREEN_SIZE_OES 0x8D51 +#define GL_RENDERBUFFER_BLUE_SIZE_OES 0x8D52 +#define GL_RENDERBUFFER_ALPHA_SIZE_OES 0x8D53 +#define GL_RENDERBUFFER_DEPTH_SIZE_OES 0x8D54 +#define GL_RENDERBUFFER_STENCIL_SIZE_OES 0x8D55 +#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_OES 0x8CD0 +#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_OES 0x8CD1 +#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_OES 0x8CD2 +#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE_OES 0x8CD3 +#define GL_COLOR_ATTACHMENT0_OES 0x8CE0 +#define GL_DEPTH_ATTACHMENT_OES 0x8D00 +#define GL_STENCIL_ATTACHMENT_OES 0x8D20 +#define GL_FRAMEBUFFER_COMPLETE_OES 0x8CD5 +#define GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_OES 0x8CD6 +#define GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_OES 0x8CD7 +#define GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_OES 0x8CD9 +#define GL_FRAMEBUFFER_INCOMPLETE_FORMATS_OES 0x8CDA +#define GL_FRAMEBUFFER_UNSUPPORTED_OES 0x8CDD +#define GL_FRAMEBUFFER_BINDING_OES 0x8CA6 +#define GL_RENDERBUFFER_BINDING_OES 0x8CA7 +#define GL_MAX_RENDERBUFFER_SIZE_OES 0x84E8 +#define GL_INVALID_FRAMEBUFFER_OPERATION_OES 0x0506 +#endif + +/* GL_OES_mapbuffer */ +#ifndef GL_OES_mapbuffer +#define GL_WRITE_ONLY_OES 0x88B9 +#define GL_BUFFER_ACCESS_OES 0x88BB +#define GL_BUFFER_MAPPED_OES 0x88BC +#define GL_BUFFER_MAP_POINTER_OES 0x88BD +#endif + +/* GL_OES_matrix_get */ +#ifndef GL_OES_matrix_get +#define GL_MODELVIEW_MATRIX_FLOAT_AS_INT_BITS_OES 0x898D +#define GL_PROJECTION_MATRIX_FLOAT_AS_INT_BITS_OES 0x898E +#define GL_TEXTURE_MATRIX_FLOAT_AS_INT_BITS_OES 0x898F +#endif + +/* GL_OES_matrix_palette */ +#ifndef GL_OES_matrix_palette +#define GL_MAX_VERTEX_UNITS_OES 0x86A4 +#define GL_MAX_PALETTE_MATRICES_OES 0x8842 +#define GL_MATRIX_PALETTE_OES 0x8840 +#define GL_MATRIX_INDEX_ARRAY_OES 0x8844 +#define GL_WEIGHT_ARRAY_OES 0x86AD +#define GL_CURRENT_PALETTE_MATRIX_OES 0x8843 +#define GL_MATRIX_INDEX_ARRAY_SIZE_OES 0x8846 +#define GL_MATRIX_INDEX_ARRAY_TYPE_OES 0x8847 +#define GL_MATRIX_INDEX_ARRAY_STRIDE_OES 0x8848 +#define GL_MATRIX_INDEX_ARRAY_POINTER_OES 0x8849 +#define GL_MATRIX_INDEX_ARRAY_BUFFER_BINDING_OES 0x8B9E +#define GL_WEIGHT_ARRAY_SIZE_OES 0x86AB +#define GL_WEIGHT_ARRAY_TYPE_OES 0x86A9 +#define GL_WEIGHT_ARRAY_STRIDE_OES 0x86AA +#define GL_WEIGHT_ARRAY_POINTER_OES 0x86AC +#define GL_WEIGHT_ARRAY_BUFFER_BINDING_OES 0x889E +#endif + +/* GL_OES_packed_depth_stencil */ +#ifndef GL_OES_packed_depth_stencil +#define GL_DEPTH_STENCIL_OES 0x84F9 +#define GL_UNSIGNED_INT_24_8_OES 0x84FA +#define GL_DEPTH24_STENCIL8_OES 0x88F0 +#endif + +/* GL_OES_required_internalformat */ +/* No new tokens introduced by this extension. */ + +/* GL_OES_rgb8_rgba8 */ +#ifndef GL_OES_rgb8_rgba8 +#define GL_RGB8_OES 0x8051 +#define GL_RGBA8_OES 0x8058 +#endif + +/* GL_OES_stencil1 */ +#ifndef GL_OES_stencil1 +#define GL_STENCIL_INDEX1_OES 0x8D46 +#endif + +/* GL_OES_stencil4 */ +#ifndef GL_OES_stencil4 +#define GL_STENCIL_INDEX4_OES 0x8D47 +#endif + +/* GL_OES_stencil8 */ +#ifndef GL_OES_stencil8 +#define GL_STENCIL_INDEX8_OES 0x8D48 +#endif + +/* GL_OES_stencil_wrap */ +#ifndef GL_OES_stencil_wrap +#define GL_INCR_WRAP_OES 0x8507 +#define GL_DECR_WRAP_OES 0x8508 +#endif + +/* GL_OES_texture_cube_map */ +#ifndef GL_OES_texture_cube_map +#define GL_NORMAL_MAP_OES 0x8511 +#define GL_REFLECTION_MAP_OES 0x8512 +#define GL_TEXTURE_CUBE_MAP_OES 0x8513 +#define GL_TEXTURE_BINDING_CUBE_MAP_OES 0x8514 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_X_OES 0x8515 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_X_OES 0x8516 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_Y_OES 0x8517 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_OES 0x8518 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_Z_OES 0x8519 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_OES 0x851A +#define GL_MAX_CUBE_MAP_TEXTURE_SIZE_OES 0x851C +#define GL_TEXTURE_GEN_MODE_OES 0x2500 +#define GL_TEXTURE_GEN_STR_OES 0x8D60 +#endif + +/* GL_OES_texture_mirrored_repeat */ +#ifndef GL_OES_texture_mirrored_repeat +#define GL_MIRRORED_REPEAT_OES 0x8370 +#endif + +/* GL_OES_vertex_array_object */ +#ifndef GL_OES_vertex_array_object +#define GL_VERTEX_ARRAY_BINDING_OES 0x85B5 +#endif + +/*------------------------------------------------------------------------* + * AMD extension tokens + *------------------------------------------------------------------------*/ + +/* GL_AMD_compressed_3DC_texture */ +#ifndef GL_AMD_compressed_3DC_texture +#define GL_3DC_X_AMD 0x87F9 +#define GL_3DC_XY_AMD 0x87FA +#endif + +/* GL_AMD_compressed_ATC_texture */ +#ifndef GL_AMD_compressed_ATC_texture +#define GL_ATC_RGB_AMD 0x8C92 +#define GL_ATC_RGBA_EXPLICIT_ALPHA_AMD 0x8C93 +#define GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD 0x87EE +#endif + +/*------------------------------------------------------------------------* + * APPLE extension tokens + *------------------------------------------------------------------------*/ + +/* GL_APPLE_copy_texture_levels */ +/* No new tokens introduced by this extension. */ + +/* GL_APPLE_framebuffer_multisample */ +#ifndef GL_APPLE_framebuffer_multisample +#define GL_RENDERBUFFER_SAMPLES_APPLE 0x8CAB +#define GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_APPLE 0x8D56 +#define GL_MAX_SAMPLES_APPLE 0x8D57 +#define GL_READ_FRAMEBUFFER_APPLE 0x8CA8 +#define GL_DRAW_FRAMEBUFFER_APPLE 0x8CA9 +#define GL_DRAW_FRAMEBUFFER_BINDING_APPLE 0x8CA6 +#define GL_READ_FRAMEBUFFER_BINDING_APPLE 0x8CAA +#endif + +/* GL_APPLE_sync */ +#ifndef GL_APPLE_sync + +/* These types are defined with reference to + * in the Apple extension spec, but here we use the Khronos + * portable types in khrplatform.h, and assume those types + * are always defined. + * If any other extensions using these types are defined, + * the typedefs must move out of this block and be shared. + */ +typedef khronos_int64_t GLint64; +typedef khronos_uint64_t GLuint64; +typedef struct __GLsync *GLsync; + +#define GL_SYNC_OBJECT_APPLE 0x8A53 +#define GL_MAX_SERVER_WAIT_TIMEOUT_APPLE 0x9111 +#define GL_OBJECT_TYPE_APPLE 0x9112 +#define GL_SYNC_CONDITION_APPLE 0x9113 +#define GL_SYNC_STATUS_APPLE 0x9114 +#define GL_SYNC_FLAGS_APPLE 0x9115 +#define GL_SYNC_FENCE_APPLE 0x9116 +#define GL_SYNC_GPU_COMMANDS_COMPLETE_APPLE 0x9117 +#define GL_UNSIGNALED_APPLE 0x9118 +#define GL_SIGNALED_APPLE 0x9119 +#define GL_ALREADY_SIGNALED_APPLE 0x911A +#define GL_TIMEOUT_EXPIRED_APPLE 0x911B +#define GL_CONDITION_SATISFIED_APPLE 0x911C +#define GL_WAIT_FAILED_APPLE 0x911D +#define GL_SYNC_FLUSH_COMMANDS_BIT_APPLE 0x00000001 +#define GL_TIMEOUT_IGNORED_APPLE 0xFFFFFFFFFFFFFFFFull +#endif + +/* GL_APPLE_texture_2D_limited_npot */ +/* No new tokens introduced by this extension. */ + +/* GL_APPLE_texture_format_BGRA8888 */ +#ifndef GL_APPLE_texture_format_BGRA8888 +#define GL_BGRA_EXT 0x80E1 +#endif + +/* GL_APPLE_texture_max_level */ +#ifndef GL_APPLE_texture_max_level +#define GL_TEXTURE_MAX_LEVEL_APPLE 0x813D +#endif + +/*------------------------------------------------------------------------* + * ARM extension tokens + *------------------------------------------------------------------------*/ + +/* GL_ARM_rgba8 */ +/* No new tokens introduced by this extension. */ + +/*------------------------------------------------------------------------* + * EXT extension tokens + *------------------------------------------------------------------------*/ + +/* GL_EXT_blend_minmax */ +#ifndef GL_EXT_blend_minmax +#define GL_MIN_EXT 0x8007 +#define GL_MAX_EXT 0x8008 +#endif + +/* GL_EXT_discard_framebuffer */ +#ifndef GL_EXT_discard_framebuffer +#define GL_COLOR_EXT 0x1800 +#define GL_DEPTH_EXT 0x1801 +#define GL_STENCIL_EXT 0x1802 +#endif + +/* GL_EXT_map_buffer_range */ +#ifndef GL_EXT_map_buffer_range +#define GL_MAP_READ_BIT_EXT 0x0001 +#define GL_MAP_WRITE_BIT_EXT 0x0002 +#define GL_MAP_INVALIDATE_RANGE_BIT_EXT 0x0004 +#define GL_MAP_INVALIDATE_BUFFER_BIT_EXT 0x0008 +#define GL_MAP_FLUSH_EXPLICIT_BIT_EXT 0x0010 +#define GL_MAP_UNSYNCHRONIZED_BIT_EXT 0x0020 +#endif + +/* GL_EXT_multisampled_render_to_texture */ +#ifndef GL_EXT_multisampled_render_to_texture +#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_SAMPLES_EXT 0x8D6C +/* reuse values from GL_EXT_framebuffer_multisample (desktop extension) */ +#define GL_RENDERBUFFER_SAMPLES_EXT 0x8CAB +#define GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_EXT 0x8D56 +#define GL_MAX_SAMPLES_EXT 0x8D57 +#endif + +/* GL_EXT_multi_draw_arrays */ +/* No new tokens introduced by this extension. */ + +/* GL_EXT_read_format_bgra */ +#ifndef GL_EXT_read_format_bgra +#define GL_BGRA_EXT 0x80E1 +#define GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT 0x8365 +#define GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT 0x8366 +#endif + +/* GL_EXT_robustness */ +#ifndef GL_EXT_robustness +/* reuse GL_NO_ERROR */ +#define GL_GUILTY_CONTEXT_RESET_EXT 0x8253 +#define GL_INNOCENT_CONTEXT_RESET_EXT 0x8254 +#define GL_UNKNOWN_CONTEXT_RESET_EXT 0x8255 +#define GL_CONTEXT_ROBUST_ACCESS_EXT 0x90F3 +#define GL_RESET_NOTIFICATION_STRATEGY_EXT 0x8256 +#define GL_LOSE_CONTEXT_ON_RESET_EXT 0x8252 +#define GL_NO_RESET_NOTIFICATION_EXT 0x8261 +#endif + +/* GL_EXT_sRGB */ +#ifndef GL_EXT_sRGB +#define GL_SRGB_EXT 0x8C40 +#define GL_SRGB_ALPHA_EXT 0x8C42 +#define GL_SRGB8_ALPHA8_EXT 0x8C43 +#define GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING_EXT 0x8210 +#endif + +/* GL_EXT_texture_compression_dxt1 */ +#ifndef GL_EXT_texture_compression_dxt1 +#define GL_COMPRESSED_RGB_S3TC_DXT1_EXT 0x83F0 +#define GL_COMPRESSED_RGBA_S3TC_DXT1_EXT 0x83F1 +#endif + +/* GL_EXT_texture_filter_anisotropic */ +#ifndef GL_EXT_texture_filter_anisotropic +#define GL_TEXTURE_MAX_ANISOTROPY_EXT 0x84FE +#define GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT 0x84FF +#endif + +/* GL_EXT_texture_format_BGRA8888 */ +#ifndef GL_EXT_texture_format_BGRA8888 +#define GL_BGRA_EXT 0x80E1 +#endif + +/* GL_EXT_texture_lod_bias */ +#ifndef GL_EXT_texture_lod_bias +#define GL_MAX_TEXTURE_LOD_BIAS_EXT 0x84FD +#define GL_TEXTURE_FILTER_CONTROL_EXT 0x8500 +#define GL_TEXTURE_LOD_BIAS_EXT 0x8501 +#endif + +/* GL_EXT_texture_storage */ +#ifndef GL_EXT_texture_storage +#define GL_TEXTURE_IMMUTABLE_FORMAT_EXT 0x912F +#define GL_ALPHA8_EXT 0x803C +#define GL_LUMINANCE8_EXT 0x8040 +#define GL_LUMINANCE8_ALPHA8_EXT 0x8045 +#define GL_RGBA32F_EXT 0x8814 +#define GL_RGB32F_EXT 0x8815 +#define GL_ALPHA32F_EXT 0x8816 +#define GL_LUMINANCE32F_EXT 0x8818 +#define GL_LUMINANCE_ALPHA32F_EXT 0x8819 +/* reuse GL_RGBA16F_EXT */ +#define GL_RGB16F_EXT 0x881B +#define GL_ALPHA16F_EXT 0x881C +#define GL_LUMINANCE16F_EXT 0x881E +#define GL_LUMINANCE_ALPHA16F_EXT 0x881F +#define GL_RGB10_A2_EXT 0x8059 +#define GL_RGB10_EXT 0x8052 +#define GL_BGRA8_EXT 0x93A1 +#endif + +/*------------------------------------------------------------------------* + * IMG extension tokens + *------------------------------------------------------------------------*/ + +/* GL_IMG_read_format */ +#ifndef GL_IMG_read_format +#define GL_BGRA_IMG 0x80E1 +#define GL_UNSIGNED_SHORT_4_4_4_4_REV_IMG 0x8365 +#endif + +/* GL_IMG_texture_compression_pvrtc */ +#ifndef GL_IMG_texture_compression_pvrtc +#define GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG 0x8C00 +#define GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG 0x8C01 +#define GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG 0x8C02 +#define GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG 0x8C03 +#endif + +/* GL_IMG_texture_env_enhanced_fixed_function */ +#ifndef GL_IMG_texture_env_enhanced_fixed_function +#define GL_MODULATE_COLOR_IMG 0x8C04 +#define GL_RECIP_ADD_SIGNED_ALPHA_IMG 0x8C05 +#define GL_TEXTURE_ALPHA_MODULATE_IMG 0x8C06 +#define GL_FACTOR_ALPHA_MODULATE_IMG 0x8C07 +#define GL_FRAGMENT_ALPHA_MODULATE_IMG 0x8C08 +#define GL_ADD_BLEND_IMG 0x8C09 +#define GL_DOT3_RGBA_IMG 0x86AF +#endif + +/* GL_IMG_user_clip_plane */ +#ifndef GL_IMG_user_clip_plane +#define GL_CLIP_PLANE0_IMG 0x3000 +#define GL_CLIP_PLANE1_IMG 0x3001 +#define GL_CLIP_PLANE2_IMG 0x3002 +#define GL_CLIP_PLANE3_IMG 0x3003 +#define GL_CLIP_PLANE4_IMG 0x3004 +#define GL_CLIP_PLANE5_IMG 0x3005 +#define GL_MAX_CLIP_PLANES_IMG 0x0D32 +#endif + +/* GL_IMG_multisampled_render_to_texture */ +#ifndef GL_IMG_multisampled_render_to_texture +#define GL_RENDERBUFFER_SAMPLES_IMG 0x9133 +#define GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_IMG 0x9134 +#define GL_MAX_SAMPLES_IMG 0x9135 +#define GL_TEXTURE_SAMPLES_IMG 0x9136 +#endif + +/*------------------------------------------------------------------------* + * NV extension tokens + *------------------------------------------------------------------------*/ + +/* GL_NV_fence */ +#ifndef GL_NV_fence +#define GL_ALL_COMPLETED_NV 0x84F2 +#define GL_FENCE_STATUS_NV 0x84F3 +#define GL_FENCE_CONDITION_NV 0x84F4 +#endif + +/*------------------------------------------------------------------------* + * QCOM extension tokens + *------------------------------------------------------------------------*/ + +/* GL_QCOM_driver_control */ +/* No new tokens introduced by this extension. */ + +/* GL_QCOM_extended_get */ +#ifndef GL_QCOM_extended_get +#define GL_TEXTURE_WIDTH_QCOM 0x8BD2 +#define GL_TEXTURE_HEIGHT_QCOM 0x8BD3 +#define GL_TEXTURE_DEPTH_QCOM 0x8BD4 +#define GL_TEXTURE_INTERNAL_FORMAT_QCOM 0x8BD5 +#define GL_TEXTURE_FORMAT_QCOM 0x8BD6 +#define GL_TEXTURE_TYPE_QCOM 0x8BD7 +#define GL_TEXTURE_IMAGE_VALID_QCOM 0x8BD8 +#define GL_TEXTURE_NUM_LEVELS_QCOM 0x8BD9 +#define GL_TEXTURE_TARGET_QCOM 0x8BDA +#define GL_TEXTURE_OBJECT_VALID_QCOM 0x8BDB +#define GL_STATE_RESTORE 0x8BDC +#endif + +/* GL_QCOM_extended_get2 */ +/* No new tokens introduced by this extension. */ + +/* GL_QCOM_perfmon_global_mode */ +#ifndef GL_QCOM_perfmon_global_mode +#define GL_PERFMON_GLOBAL_MODE_QCOM 0x8FA0 +#endif + +/* GL_QCOM_writeonly_rendering */ +#ifndef GL_QCOM_writeonly_rendering +#define GL_WRITEONLY_RENDERING_QCOM 0x8823 +#endif + +/* GL_QCOM_tiled_rendering */ +#ifndef GL_QCOM_tiled_rendering +#define GL_COLOR_BUFFER_BIT0_QCOM 0x00000001 +#define GL_COLOR_BUFFER_BIT1_QCOM 0x00000002 +#define GL_COLOR_BUFFER_BIT2_QCOM 0x00000004 +#define GL_COLOR_BUFFER_BIT3_QCOM 0x00000008 +#define GL_COLOR_BUFFER_BIT4_QCOM 0x00000010 +#define GL_COLOR_BUFFER_BIT5_QCOM 0x00000020 +#define GL_COLOR_BUFFER_BIT6_QCOM 0x00000040 +#define GL_COLOR_BUFFER_BIT7_QCOM 0x00000080 +#define GL_DEPTH_BUFFER_BIT0_QCOM 0x00000100 +#define GL_DEPTH_BUFFER_BIT1_QCOM 0x00000200 +#define GL_DEPTH_BUFFER_BIT2_QCOM 0x00000400 +#define GL_DEPTH_BUFFER_BIT3_QCOM 0x00000800 +#define GL_DEPTH_BUFFER_BIT4_QCOM 0x00001000 +#define GL_DEPTH_BUFFER_BIT5_QCOM 0x00002000 +#define GL_DEPTH_BUFFER_BIT6_QCOM 0x00004000 +#define GL_DEPTH_BUFFER_BIT7_QCOM 0x00008000 +#define GL_STENCIL_BUFFER_BIT0_QCOM 0x00010000 +#define GL_STENCIL_BUFFER_BIT1_QCOM 0x00020000 +#define GL_STENCIL_BUFFER_BIT2_QCOM 0x00040000 +#define GL_STENCIL_BUFFER_BIT3_QCOM 0x00080000 +#define GL_STENCIL_BUFFER_BIT4_QCOM 0x00100000 +#define GL_STENCIL_BUFFER_BIT5_QCOM 0x00200000 +#define GL_STENCIL_BUFFER_BIT6_QCOM 0x00400000 +#define GL_STENCIL_BUFFER_BIT7_QCOM 0x00800000 +#define GL_MULTISAMPLE_BUFFER_BIT0_QCOM 0x01000000 +#define GL_MULTISAMPLE_BUFFER_BIT1_QCOM 0x02000000 +#define GL_MULTISAMPLE_BUFFER_BIT2_QCOM 0x04000000 +#define GL_MULTISAMPLE_BUFFER_BIT3_QCOM 0x08000000 +#define GL_MULTISAMPLE_BUFFER_BIT4_QCOM 0x10000000 +#define GL_MULTISAMPLE_BUFFER_BIT5_QCOM 0x20000000 +#define GL_MULTISAMPLE_BUFFER_BIT6_QCOM 0x40000000 +#define GL_MULTISAMPLE_BUFFER_BIT7_QCOM 0x80000000 +#endif + +#endif // _GL4ES_GLES_H_ diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/glstate.c b/Projects/Android/jni/SupportLibs/gl4es/src/gl/glstate.c new file mode 100644 index 0000000..0caceca --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/glstate.c @@ -0,0 +1,546 @@ +#include "glstate.h" + +#include "../glx/hardext.h" +#include "fpe.h" +#include "framebuffers.h" +#include "gl4es.h" +#include "glstate.h" +#include "init.h" +#include "loader.h" + +glstate_t *glstate = NULL; + +glstate_t *default_glstate = NULL; + +void init_matrix(glstate_t* glstate); + +static void free_renderbuffer(glrenderbuffer_t *rend) +{ + LOAD_GLES2_OR_OES(glDeleteRenderbuffers); + if(!rend) + return; + if(rend->secondarybuffer) + gles_glDeleteRenderbuffers(1, &rend->secondarybuffer); + if(rend->renderbuffer) + gles_glDeleteRenderbuffers(1, &rend->renderbuffer); + // the texture will be free by the free of the texture list, as it's referenced there... + free(rend); +} + +static void free_framebuffer(glframebuffer_t *fb) +{ + LOAD_GLES2_OR_OES(glDeleteFramebuffers); + if(!fb) + return; + if(fb->id) + gles_glDeleteFramebuffers(1, &fb->id); + // the texture will be free by the free of the texture list, as it's referenced there... + free(fb); +} + +static void free_texture(gltexture_t *tex) +{ + LOAD_GLES(glDeleteTextures); + if(!tex) + return; + if(tex->glname) + gles_glDeleteTextures(1, &tex->glname); + if(tex->data) + free(tex->data); + // renderbuffer linked to this texture will be freed by the free_renderbuffer function. + free(tex); +} + +void* NewGLState(void* shared_glstate, int es2only) { + glstate_t *glstate = (glstate_t*)calloc(1, sizeof(glstate_t)); + if(shared_glstate) { + glstate_t* copy_state = (glstate_t*)shared_glstate; + if(!copy_state->shared_cnt) { + copy_state->shared_cnt = (int*)malloc(sizeof(int)); + (*copy_state->shared_cnt) = 2; + } else + (*copy_state->shared_cnt)++; + glstate->shared_cnt = copy_state->shared_cnt; + glstate->headlists = copy_state->headlists; + glstate->actual_tex2d = copy_state->actual_tex2d; + glstate->texture.list = copy_state->texture.list; + glstate->glsl = copy_state->glsl; + glstate->gleshard = copy_state->gleshard; + glstate->buffers = copy_state->buffers; + glstate->queries = copy_state->queries; + glstate->fpe_cache = copy_state->fpe_cache; + glstate->fbo.renderbufferlist = copy_state->fbo.renderbufferlist; + glstate->fbo.default_rb = copy_state->fbo.default_rb; + glstate->fbo.framebufferlist = copy_state->fbo.framebufferlist; + glstate->fbo.fbo_0 = copy_state->fbo.fbo_0; + glstate->fbo.old = copy_state->fbo.old; + + glstate->defaultvbo = copy_state->defaultvbo; + } + GLfloat white[] = {1.0f, 1.0f, 1.0f, 1.0f}; + memcpy(glstate->color, white, sizeof(GLfloat)*4); + glstate->last_error = GL_NO_ERROR; + glstate->normal[2] = 1.0f; // default normal is 0/0/1 + glstate->matrix_mode = GL_MODELVIEW; + + // add default VBO + if(!shared_glstate) // TODO: check if default VBO is shared? + { + khint_t k; + int ret; + khash_t(buff) *list = glstate->buffers = kh_init(buff); + k = kh_put(buff, list, 0, &ret); + glbuffer_t *buff = kh_value(list, k) = calloc(1, sizeof(glbuffer_t)); + /*buff->buffer = 0; + buff->type = 0; + buff->data = NULL;*/ + buff->usage = GL_STATIC_DRAW; + //buff->size = 0; + buff->access = GL_READ_WRITE; + //buff->mapped = 0; + glstate->defaultvbo = buff; + } + // add default VAO + { + khint_t k; + int ret; + khash_t(glvao) *list = glstate->vaos = kh_init(glvao); + k = kh_put(glvao, list, 0, &ret); + glvao_t *glvao = kh_value(list, k) = malloc(sizeof(glvao_t)); + // new vao is binded to default vbo + VaoInit(glvao); + // just put is number + glvao->array = 0; + glstate->defaultvao = glvao; + } + // initialize gllists + if(!shared_glstate) + { + khint_t k; + int ret; + khash_t(gllisthead) *list = glstate->headlists = kh_init(gllisthead); + k = kh_put(gllisthead, list, 1, &ret); + kh_del(gllisthead, list, k); + } + // actual_tex2d + if(!shared_glstate) + { + glstate->actual_tex2d = (GLuint*)calloc(MAX_TEX, sizeof(GLuint)); + } + // glsl + if(!shared_glstate) + { + glstate->glsl = (glsl_t*)malloc(sizeof(glsl_t)); + memset(glstate->glsl, 0, sizeof(glsl_t)); + glstate->gleshard = (gleshard_s_t*)calloc(1, sizeof(gleshard_s_t)); + } + // Bind defaults... + glstate->vao = glstate->defaultvao; + + //raster & viewport + glstate->raster.raster_zoomx=1.0f; + glstate->raster.raster_zoomy=1.0f; + glstate->raster.map_i2i_size=1; + glstate->raster.map_i2r_size=1; + glstate->raster.map_i2g_size=1; + glstate->raster.map_i2b_size=1; + glstate->raster.map_i2a_size=1; + /* + glstate->raster.map_s2s_size=1; + glstate->raster.map_r2r_size=1; + glstate->raster.map_g2g_size=1; + glstate->raster.map_b2b_size=1; + glstate->raster.map_a2a_size=1; + */ + + // pack & unpack alignment + glstate->texture.pack_align = 4; + glstate->texture.unpack_align = 4; + + // eval + glstate->map_grid[0]._2 = 1.0f; + glstate->map_grid[0].n = 1; + glstate->map_grid[0].d = 1.0f; + glstate->map_grid[1]._2 = 1.0f; + glstate->map_grid[1].n = 1; + glstate->map_grid[1].d = 1.0f; + + // line stipple + glstate->linestipple.factor = 1; + glstate->linestipple.pattern = 0xFFFF; + glstate->linestipple.data = (GLubyte *)malloc(sizeof(GLubyte) * 16); + memset(glstate->linestipple.data, 0xff, sizeof(GLubyte) * 16); + glstate->linestipple.texture = 0; + + // fpe + if(hardext.esversion>1) { + glstate->fpe_state = (fpe_state_t*)calloc(1, sizeof(fpe_state_t)); + glstate->glsl->es2 = es2only; + fpe_Init(glstate); + } + + // init the matrix tracking + init_matrix(glstate); + + // init the textures + { + gltexture_t* tex; + if(!shared_glstate) { + int ret; + khint_t k; + khash_t(tex) *list = glstate->texture.list; + list = glstate->texture.list = kh_init(tex); + // segfaults if we don't do a single put + k = kh_put(tex, list, 1, &ret); + kh_del(tex, list, k); + } + // now add default "0" texture => no, because tex 0 is not shared.... + /*k = kh_put(tex, list, 0, &ret); + glstate->texture.zero = tex = kh_value(list, k) = malloc(sizeof(gltexture_t));*/ + glstate->texture.zero = tex = calloc(1, sizeof(gltexture_t)); + tex->adjustxy[0] = tex->adjustxy[1] = 1.f; + tex->mipmap_auto = (globals4es.automipmap==1); + tex->mipmap_need = (globals4es.automipmap==1)?1:0; + tex->streamingID = -1; + tex->base_level = -1; + tex->max_level = -1; + tex->alpha = true; + tex->min_filter = (globals4es.automipmap==1)?GL_LINEAR_MIPMAP_LINEAR:GL_LINEAR; + tex->mag_filter = GL_LINEAR; + tex->wrap_s = tex->wrap_t = GL_REPEAT; + tex->fpe_format = FPE_TEX_RGBA; + tex->format = GL_RGBA; + tex->type = GL_UNSIGNED_BYTE; + tex->inter_format = GL_RGBA; + tex->inter_type = GL_UNSIGNED_BYTE; + // now bind that texture on all unit + for (int itarget=0; itargettexture.bound[i][itarget] = tex; + } + + + // init the light tracking + glstate->light.ambient[0]=glstate->light.ambient[1]=glstate->light.ambient[2]=0.2f; + glstate->light.ambient[3]=1.0f; + glstate->light.lights[0].diffuse[0]= + glstate->light.lights[0].diffuse[1]= + glstate->light.lights[0].diffuse[2]= + glstate->light.lights[0].diffuse[3]=1.0f; + memcpy(glstate->light.lights[0].specular, glstate->light.lights[0].diffuse, 4*sizeof(GLfloat)); + for (int i=0; ilight.lights[i].ambient[3] = 1.0f; + glstate->light.lights[i].position[2] = 1.0f; + glstate->light.lights[i].spotDirection[2] = -1.0f; + glstate->light.lights[i].spotCutoff = 180; + glstate->light.lights[i].constantAttenuation = 1; + } + // Materials + glstate->material.front.ambient[0] = + glstate->material.front.ambient[1] = + glstate->material.front.ambient[2] = 0.2f; + glstate->material.front.ambient[3] = 1.0f; + glstate->material.front.diffuse[0] = + glstate->material.front.diffuse[1] = + glstate->material.front.diffuse[2] = 0.8f; + glstate->material.front.diffuse[3] = 1.0f; + glstate->material.front.specular[3] = 1.0f; + glstate->material.front.emission[3] = 1.0f; + glstate->material.front.colormat = GL_AMBIENT_AND_DIFFUSE; + memcpy(&glstate->material.back, &glstate->material.front, sizeof(material_t)); + // Fog + glstate->fog.mode = GL_EXP; + glstate->fog.density = 1.0f; + glstate->fog.end = 1.0f; + glstate->fog.coord_src = GL_FRAGMENT_DEPTH; + // Alpha Func + glstate->alphafunc = GL_ALWAYS; + glstate->alpharef = 0.0f; + // Blend + glstate->blendsfactorrgb = GL_ONE; + glstate->blenddfactorrgb = GL_ZERO; + glstate->blendsfactoralpha = GL_ONE; + glstate->blenddfactoralpha = GL_ZERO; + // Depth + glstate->depth.func = GL_LESS; + glstate->depth.mask = GL_TRUE; + glstate->depth.far = 1.0f; + glstate->depth.clear= 1.0f; + // Face + glstate->face.cull = GL_BACK; + glstate->face.front = GL_CCW; + // Point Sprite + glstate->pointsprite.size = 1.0f; + glstate->pointsprite.sizeMax = 32.0f; // spec indicate 1., but it seems it's set to hardware limit, so puting 32... + glstate->pointsprite.fadeThresholdSize = 1.0f; + glstate->pointsprite.distance[0] = 1.0f; + glstate->pointsprite.coordOrigin = GL_UPPER_LEFT; + // Stencil + glstate->stencil.func[0] = glstate->stencil.func[1] = GL_ALWAYS; + //glstate->stencil.f_ref[0] = glstate->stencil.f_ref[1] = 0; + glstate->stencil.f_mask[0] = glstate->stencil.f_mask[1] = ~(GLuint)0; + glstate->stencil.mask[0] = glstate->stencil.mask[1] = ~(GLuint)0; + glstate->stencil.sfail[0] = glstate->stencil.sfail[1] = GL_KEEP; + glstate->stencil.dpfail[0] = glstate->stencil.dpfail[1] = GL_KEEP; + glstate->stencil.dppass[0] = glstate->stencil.dppass[1] = GL_KEEP; + // Color Mask + for(int i=0; i<4; i++) + glstate->colormask[i] = 1; + // Raster + for(int i=0; i<4; i++) + glstate->raster.raster_scale[i] = 1.0f; + // ShadeModel + glstate->shademodel = GL_SMOOTH; + // TexEnv + for (int i=0; itexenv[i].env.mode = GL_MODULATE; + glstate->texenv[i].env.rgb_scale = 1.0f; + glstate->texenv[i].env.alpha_scale = 1.0f; + glstate->texenv[i].env.src0_rgb = glstate->texenv[i].env.src0_alpha = GL_TEXTURE; + glstate->texenv[i].env.src1_rgb = glstate->texenv[i].env.src1_alpha = GL_PREVIOUS; + glstate->texenv[i].env.src2_rgb = glstate->texenv[i].env.src2_alpha = GL_CONSTANT; + glstate->texenv[i].env.op0_rgb = glstate->texenv[i].env.op1_rgb = GL_SRC_COLOR; + glstate->texenv[i].env.op2_rgb = glstate->texenv[i].env.op0_alpha = + glstate->texenv[i].env.op1_alpha = glstate->texenv[i].env.op2_alpha = GL_SRC_ALPHA; + } + // TexGen + for (int i=0; itexgen[i].S = GL_EYE_LINEAR; + glstate->texgen[i].T = GL_EYE_LINEAR; + glstate->texgen[i].R = GL_EYE_LINEAR; + glstate->texgen[i].Q = GL_EYE_LINEAR; + glstate->texgen[i].S_E[0] = 1.0; + glstate->texgen[i].S_O[0] = 1.0; + glstate->texgen[i].T_E[1] = 1.0; + glstate->texgen[i].T_O[1] = 1.0; + } + + // fpe + if(hardext.esversion>1) { + glstate->fpe_state = (fpe_state_t*)calloc(1, sizeof(fpe_state_t)); + glstate->glsl->es2 = es2only; + if(!shared_glstate) + fpe_Init(glstate); + // some default are not 0... + for (int i=0; ifpe_state->texsrcrgb[1] |= FPE_SRC_PREVIOUS<<(i*4); + glstate->fpe_state->texsrcalpha[1] |= FPE_SRC_PREVIOUS<<(i*4); + glstate->fpe_state->texsrcrgb[2] |= FPE_SRC_CONSTANT<<(i*4); + glstate->fpe_state->texsrcalpha[2] |= FPE_SRC_CONSTANT<<(i*4); + glstate->fpe_state->texoprgb[0] |= FPE_OP_SRCCOLOR<<(i*2); + glstate->fpe_state->texoprgb[1] |= FPE_OP_SRCCOLOR<<(i*2); + } + } + + // GLSL stuff + if(!shared_glstate) + { + khint_t k; + int ret; + khash_t(shaderlist) *shaders = glstate->glsl->shaders = kh_init(shaderlist); + k = kh_put(shaderlist, shaders, 1, &ret); + kh_del(shaderlist, shaders, k); + khash_t(programlist) *programs = glstate->glsl->programs = kh_init(programlist); + k = kh_put(programlist, programs, 1, &ret); + kh_del(programlist, programs, k); + } + + // Grab ViewPort + LOAD_GLES(glGetIntegerv); +#ifdef AMIGAOS4 + if(default_glstate) // if default_glstate is null, then there is probably no glcontext... +#endif + gles_glGetIntegerv(GL_VIEWPORT, (GLint*)&glstate->raster.viewport); + // FBO + glstate->fbowidth = glstate->fbo.mainfbo_width = glstate->raster.viewport.width; + glstate->fboheight = glstate->fbo.mainfbo_height = glstate->raster.viewport.height; + glstate->fbo.mainfbo_nwidth = (hardext.npot)?glstate->fbo.mainfbo_width:npot(glstate->fbo.mainfbo_width); + glstate->fbo.mainfbo_nheight = (hardext.npot)?glstate->fbo.mainfbo_height:npot(glstate->fbo.mainfbo_height); + // add default Renderbuffer + if(!shared_glstate) + { + khint_t k; + int ret; + khash_t(renderbufferlist_t) *list = glstate->fbo.renderbufferlist = kh_init(renderbufferlist_t); + k = kh_put(renderbufferlist_t, list, 0, &ret); + glrenderbuffer_t *rend = kh_value(list, k) = calloc(1, sizeof(glrenderbuffer_t)); + glstate->fbo.default_rb = rend; + } + // add default Framebuffer + if(!shared_glstate) + { + khint_t k; + int ret; + khash_t(framebufferlist_t) *list = glstate->fbo.framebufferlist = kh_init(framebufferlist_t); + k = kh_put(framebufferlist_t, list, 0, &ret); + glframebuffer_t *fb = kh_value(list, k) = calloc(1, sizeof(glframebuffer_t)); + fb->width = glstate->fbo.mainfbo_width; + fb->height = glstate->fbo.mainfbo_height; + glstate->fbo.fbo_0 = fb; + if(globals4es.recyclefbo) { + glstate->fbo.old = (oldfbos_t*)calloc(1, sizeof(oldfbos_t)); + } + } + glstate->fbo.current_fb = glstate->fbo.fbo_0; + glstate->fbo.current_rb = glstate->fbo.default_rb; + glstate->fbo.fbo_read = glstate->fbo.fbo_0; + glstate->fbo.fbo_draw = glstate->fbo.fbo_0; + // Get the per/context hardware values + glstate->readf = GL_RGBA; + glstate->readt = GL_UNSIGNED_BYTE; +#ifdef AMIGAOS4 + if(default_glstate) // if default_glstate is null, then there is probably no glcontext... + { +#endif + gles_glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES, &glstate->readf); + gles_glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_TYPE_OES, &glstate->readt); +#ifdef AMIGAOS4 + } +#endif + //printf("LIBGL: Implementation Read is %s/%s\n", PrintEnum(glstate->readf), PrintEnum(glstate->readt)); + + // All done + return (void*)glstate; +} + + +void DeleteGLState(void* oldstate) { + glstate_t* state = (glstate_t*)oldstate; + if(!state) return; + + if(state->shared_cnt) { + if(!--(*state->shared_cnt)) { + free(state->shared_cnt); + state->shared_cnt = 0; + } + } + if(globals4es.noclean) + return; + + if(glstate == state) + glstate = NULL; + + if(!state->shared_cnt) + free(state->actual_tex2d); + + #define free_hashmap(T, N, K, F) \ + if(state->N) \ + { \ + T *m; \ + kh_foreach_value(state->N, m, \ + F(m); \ + ) \ + kh_destroy(K, state->N); \ + } + free_hashmap(glvao_t, vaos, glvao, free); + if(!state->shared_cnt) { + free_hashmap(glquery_t, queries, queries, free); + free_hashmap(glbuffer_t, buffers, buff, free); + free_hashmap(gltexture_t, texture.list, tex, free_texture); + free_hashmap(renderlist_t, headlists, gllisthead, free_renderlist); + free_hashmap(glrenderbuffer_t, fbo.renderbufferlist, renderbufferlist_t, free_renderbuffer); + free_hashmap(glframebuffer_t, fbo.framebufferlist, framebufferlist_t, free_framebuffer); + } + #undef free_hashmap + // free texture zero as it's not in the list anymore + free(state->texture.zero); + // free eval maps + #define freemap(dims, name) \ + { map_statef_t *m = (map_statef_t *)state->map##dims.name; \ + if (m) { \ + free((void *)m->points); \ + free(m); \ + } } + freemap(1, vertex3); freemap(1, vertex4); freemap(1, index); freemap(1, color4); freemap(1, normal); + freemap(1, texture1); freemap(1, texture2); freemap(1, texture3); freemap(1, texture4); + freemap(2, vertex3); freemap(2, vertex4); freemap(2, index); freemap(2, color4); freemap(2, normal); + freemap(2, texture1); freemap(2, texture2); freemap(2, texture3); freemap(2, texture4); + #undef freemap + // free active list + if(!state->shared_cnt && state->list.active) free_renderlist(state->list.active); + + // free matrix stack + #define free_matrix(A) \ + if (state->A) { \ + free(state->A->stack); \ + free(state->A); \ + } + free_matrix(projection_matrix); + free_matrix(modelview_matrix); + for (int i=0; itexture_matrix); + #undef free_matrix + // linestipple + if(state->linestipple.data) + free(state->linestipple.data); + // raster / bitmap + if(state->raster.data) + free(state->raster.data); + if(state->raster.bitmap) + free(state->raster.bitmap); + // TODO: delete the "immediate" stuff and bitmap texture? + // scratch buffer + if(state->scratch) + free(state->scratch); + // merger buffers + if(state->merger_master) + free(state->merger_master); + if(state->merger_secondary) + free(state->merger_secondary); + for(int a=0; amerger_tex[a]) + free(state->merger_tex[a]); + // mainfbo + if(!state->shared_cnt) { + if(state->fbo.mainfbo_fbo) + deleteMainFBO(state); + } + // oldfbos + if(!state->shared_cnt && state->fbo.old) { + LOAD_GLES2_OR_OES(glDeleteFramebuffers); + gles_glDeleteFramebuffers(state->fbo.old->nbr, state->fbo.old->fbos); + free(state->fbo.old->fbos); + free(state->fbo.old); + } + // free blit GLES2 stuff + if(state->blit) { + //TODO: check if should delete GL object too + free(state->blit); + } + if(!state->shared_cnt) { + free(state->glsl); + free(state->gleshard); + if(state->fpe_cache) { + fpe_Dispose(state); + } + } + //TODO: free sharderlist and programlist... + + // probably missing some things to free here! + + // all done + free(state); + return; +} + +void ActivateGLState(void* new_glstate) { + glstate_t *newstate = (new_glstate)?(glstate_t*)new_glstate:default_glstate; + if(glstate == newstate) return; // same state, nothing to do + // check if viewport is correct +#ifdef AMIGAOS4 + if(glstate || newstate!=default_glstate) // avoid getting gles info with no context +#endif + if(new_glstate && (newstate->raster.viewport.width==0.0f || newstate->raster.viewport.height==0.0f)) { + LOAD_GLES(glGetFloatv); + gles_glGetFloatv(GL_VIEWPORT, (GLfloat*)&newstate->raster.viewport); + } + glstate = newstate; +} + +void gl_init() { + default_glstate = (glstate_t*)NewGLState(NULL, 0); + ActivateGLState(default_glstate); +} + diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/glstate.h b/Projects/Android/jni/SupportLibs/gl4es/src/gl/glstate.h new file mode 100644 index 0000000..14ecfb1 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/glstate.h @@ -0,0 +1,115 @@ +#ifndef _GL4ES_GLSTATE_H_ +#define _GL4ES_GLSTATE_H_ + +#include "fog.h" +#include "fpe.h" +#include "light.h" +#include "pointsprite.h" +#include "queries.h" +#include "stack.h" +#include "stencil.h" + +typedef struct { + int dummy[16]; // dummy zone, test for memory overwriting... + displaylist_state_t list; + enable_state_t enable; + map_grid_t map_grid[2]; + map_states_t map1, map2; + khash_t(gllisthead) *headlists; // shared + texgen_state_t texgen[MAX_TEX]; + texenv_state_t texenv[MAX_TEX]; + texture_state_t texture; + GLfloat vertex[4]; + GLfloat color[4]; + GLfloat secondary[4]; + GLfloat texcoord[MAX_TEX][4]; + GLfloat normal[3]; + GLfloat fogcoord; + GLboolean colormask[4]; + int render_mode; + int polygon_mode; + namestack_t namestack; + GLfloat mvp_matrix[16]; + int mvp_matrix_dirty; + GLfloat inv_mv_matrix[16]; + int inv_mv_matrix_dirty; + GLfloat normal_matrix[9]; + int normal_matrix_dirty; + matrixstack_t *modelview_matrix; + matrixstack_t *projection_matrix; + matrixstack_t **texture_matrix; + int matrix_mode; + selectbuf_t selectbuf; + khash_t(glvao) *vaos; + khash_t(buff) *buffers; //shared + glvao_t *vao; + glbuffer_t *defaultvbo; + glvao_t *defaultvao; + int shim_error; + GLenum last_error; + GLint vp[4]; + GLboolean clientstate[NB_VA]; + khash_t(queries) *queries; // shared + glstack_t *stack; + glclientstack_t *clientStack; + raster_state_t raster; + GLuint *actual_tex2d; // store the texture actually bounded TEX2D unit, because it's shared... (TODO: all binding and not only TEX2D) + int bound_changed; // 0 if not changed or max TMU if changed... + int fpe_bound_changed; // same but for fpe +#ifdef TEXSTREAM + int bound_stream[MAX_TEX]; // should be shared too +#endif + int emulatedPixmap; + int emulatedWin; + int *shared_cnt; + light_state_t light; + fog_t fog; + material_state_t material; + stencil_t stencil; + float planes[MAX_CLIP_PLANES][4]; + pointsprite_t pointsprite; + linestipple_t linestipple; + GLenum shademodel; + GLenum alphafunc; + GLfloat alpharef; + GLenum blendsfactorrgb; + GLenum blenddfactorrgb; + GLenum blendsfactoralpha; + GLenum blenddfactoralpha; + GLenum logicop; + glsl_t *glsl; //shared + fpe_state_t *fpe_state; + fpe_fpe_t *fpe; + fpestatus_t fpe_client; + fpe_cache_t *fpe_cache; + gleshard_s_t *gleshard; //shared + gleshard_ns_t glesva; + glesblit_t *blit; + fbo_t fbo; + int fbowidth, fboheight; // initial size (usefull only on LIBGL_FB=1 or 2) + depth_state_t depth; + face_state_t face; + GLint instanceID; + // scratch array + int scratch_alloc; + void* scratch; + // glBegin/glEnd merger + int merger_cap; + GLfloat* merger_master; + GLfloat* merger_secondary; + GLfloat* merger_tex[MAX_TEX-2]; + int merger_indice_cap; + GLushort* merger_indices; + int merger_used; + // scratch VBO + GLuint scratch_vertex; + GLsizei scratch_vertex_size; + GLuint scratch_indices; + GLsizei scratch_indices_size; + // Implementation read + GLenum readf; // implementation Read Format + GLenum readt; // implementation Read Type +} glstate_t; + + +#endif // _GL4ES_GLSTATE_H_ diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/hint.c b/Projects/Android/jni/SupportLibs/gl4es/src/gl/hint.c new file mode 100644 index 0000000..16026e1 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/hint.c @@ -0,0 +1,135 @@ +#include "hint.h" + +#include +#include "init.h" +#include "loader.h" +#include "gl4es.h" +#include "glstate.h" + +#ifdef PANDORA +void pandora_set_gamma(); +#endif + +void gl4es_glHint(GLenum pname, GLenum mode) { + + if (glstate->list.pending) + flush(); + + LOAD_GLES(glHint); + noerrorShim(); + switch(pname) { + // some Hint are not supported in GLES2, so just ignoring them + case GL_FOG_HINT: + if(hardext.esversion>1) + return; + gles_glHint(pname, mode); + break; + case GL_PERSPECTIVE_CORRECTION_HINT: + if(hardext.esversion>1) + return; + gles_glHint(pname, mode); + break; + case GL_LINE_SMOOTH_HINT: + if(hardext.esversion>1) + return; + gles_glHint(pname, mode); + break; + case GL_POINT_SMOOTH_HINT: + if(hardext.esversion>1) + return; + gles_glHint(pname, mode); + break; + case GL_TEXTURE_COMPRESSION_HINT: // ignore this one + // TODO: track setted value + return; + // specifics GL4ES Hints + case GL_SHRINK_HINT_GL4ES: + if (mode<=11) + globals4es.texshrink = mode; + else + errorShim(GL_INVALID_ENUM); + break; + case GL_ALPHAHACK_HINT_GL4ES: + if (mode<=1) + globals4es.alphahack = mode; + else + errorShim(GL_INVALID_ENUM); + break; + case GL_RECYCLEFBO_HINT_GL4ES: + if (mode<=1) + globals4es.recyclefbo = mode; + else + errorShim(GL_INVALID_ENUM); + break; + case GL_MIPMAP_HINT_GL4ES: + if (mode<=4) + globals4es.automipmap = mode; + else + errorShim(GL_INVALID_ENUM); + break; + case GL_TEXDUMP_HINT_GL4ES: + if (mode<=1) + globals4es.texdump = mode; + else + errorShim(GL_INVALID_ENUM); + break; + case GL_COPY_HINT_GL4ES: + if (mode>1) //removed + errorShim(GL_INVALID_ENUM); + break; + case GL_NOLUMAPHA_HINT_GL4ES: + if (mode<=1) + globals4es.nolumalpha = mode; + else + errorShim(GL_INVALID_ENUM); + break; + case GL_BLENDHACK_HINT_GL4ES: + if (mode<=1) + globals4es.blendhack = mode; + else + errorShim(GL_INVALID_ENUM); + break; + case GL_BATCH_HINT_GL4ES: + globals4es.batch = mode; + break; + case GL_NOERROR_HINT_GL4ES: + if (mode<=1) + globals4es.noerror = mode; + else + errorShim(GL_INVALID_ENUM); + break; + case GL_NODOWNSAMPLING_HINT_GL4ES: + if (mode<=1) + globals4es.nodownsampling = mode; + else + errorShim(GL_INVALID_ENUM); + break; + case GL_NOVAOCACHE_HINT_GL4ES: + if (mode<=1) + globals4es.novaocache = mode; + else + errorShim(GL_INVALID_ENUM); + break; + case GL_BEGINEND_HINT_GL4ES: + if(mode<=2) + globals4es.beginend = mode; + else + errorShim(GL_INVALID_ENUM); + case GL_AVOID16BITS_HINT_GL4ES: + if (mode<=1) + globals4es.avoid16bits = mode; + else + errorShim(GL_INVALID_ENUM); + break; + case GL_GAMMA_HINT_GL4ES: + globals4es.gamma = ((float)mode)/10.f; +#ifdef PANDORA + pandora_set_gamma(); +#endif + break; + default: + errorGL(); + gles_glHint(pname, mode); + } +} +void glHint(GLenum pname, GLenum mode) AliasExport("gl4es_glHint"); \ No newline at end of file diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/hint.h b/Projects/Android/jni/SupportLibs/gl4es/src/gl/hint.h new file mode 100644 index 0000000..3268049 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/hint.h @@ -0,0 +1,8 @@ +#ifndef _GL4ES_HINT_H_ +#define _GL4ES_HINT_H_ + +#include "gles.h" + +void gl4es_glHint(GLenum pname, GLenum mode); + +#endif // _GL4ES_HINT_H_ diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/init.c b/Projects/Android/jni/SupportLibs/gl4es/src/gl/init.c new file mode 100644 index 0000000..b35fe8b --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/init.c @@ -0,0 +1,542 @@ +#include "init.h" + +#if !defined(ANDROID) && !defined(AMIGAOS4) && !defined(__EMSCRIPTEN__) +#include +#endif +#include +#include +#include "../../version.h" +#include "../glx/glx_gbm.h" +#include "../glx/streaming.h" +#include "build_info.h" +#include "debug.h" +#include "loader.h" +#include "logs.h" +#ifdef __EMSCRIPTEN__ +#define NO_INIT_CONSTRUCTOR +#endif + +void gl_init(); + +globals4es_t globals4es = {0}; + +#define SHUT(a) if(!globals4es.nobanner) a + +#if defined(PANDORA) || defined(CHIP) +static void fast_math() { + // enable Cortex A8 RunFast + int v = 0; + __asm__ __volatile__ ( + "vmrs %0, fpscr\n" + "orr %0, #((1<<25)|(1<<24))\n" // default NaN, flush-to-zero + "vmsr fpscr, %0\n" + //"vmrs %0, fpscr\n" + : "=&r"(v)); +} +#endif + +#ifndef DEFAULT_ES +#if defined(PANDORA) || defined(ANDROID) +#define DEFAULT_ES 1 +#else +#define DEFAULT_ES 2 +#endif +#endif + +void load_libs(); +void glx_init(); + +#ifdef NO_INIT_CONSTRUCTOR +__attribute__((visibility("default"))) +#else +__attribute__((constructor)) +#endif +void initialize_gl4es() { + // only init 1 time + //static int inited = 0; + //if(inited) return; + //inited = 1; + // default init of globals + memset(&globals4es, 0, sizeof(globals4es)); + globals4es.mergelist = 1; + globals4es.queries = 1; + globals4es.beginend = 1; + // overides by env. variables + char *env_nobanner = getenv("LIBGL_NOBANNER"); + if (env_nobanner && strcmp(env_nobanner, "1") == 0) + globals4es.nobanner = 1; + + SHUT(LOGD("LIBGL: Initialising gl4es\n")); + + SHUT(print_build_infos()); + #define env(name, global, message) \ + char *env_##name = getenv(#name); \ + if (env_##name && strcmp(env_##name, "1") == 0) { \ + SHUT(LOGD("LIBGL: " message "\n")); \ + global = true; \ + } + + env(LIBGL_XREFRESH, globals4es.xrefresh, "xrefresh will be called on cleanup"); + env(LIBGL_STACKTRACE, globals4es.stacktrace, "stacktrace will be printed on crash"); + + char *env_fb = getenv("LIBGL_FB"); + if (env_fb && strcmp(env_fb, "1") == 0) { + SHUT(LOGD("LIBGL: framebuffer output enabled\n")); + globals4es.usefb = 1; + } + if (env_fb && strcmp(env_fb, "2") == 0) { + SHUT(LOGD("LIBGL: using framebuffer + fbo\n")); + globals4es.usefb = 1; + globals4es.usefbo = 1; + } +#ifndef NOX11 + if (env_fb && strcmp(env_fb, "3") == 0) { + SHUT(LOGD("LIBGL: using pbuffer\n")); + globals4es.usefb = 0; + globals4es.usepbuffer = 1; + } +#endif + if (env_fb && strcmp(env_fb, "4") == 0) { +#ifdef NO_GBM + SHUT(LOGD("LIBGL: GBM Support not builded, cannot use it\n")); +#else + SHUT(LOGD("LIBGL: using GBM\n")); + globals4es.usefb = 0; + globals4es.usegbm = 1; +#endif + } + + env(LIBGL_FPS, globals4es.showfps, "fps counter enabled"); +#ifdef USE_FBIO + env(LIBGL_VSYNC, globals4es.vsync, "vsync enabled"); +#endif +#ifdef PANDORA + char *env_gamma = getenv("LIBGL_GAMMA"); + if (env_gamma) { + globals4es.gamma=atof(env_gamma); + SHUT(LOGD("LIBGL: Set gamma to %.2f\n", globals4es.gamma)); + } +#endif + env(LIBGL_NOBGRA, globals4es.nobgra, "Ignore BGRA texture capability"); + env(LIBGL_ARBPROGRAM, globals4es.arb_program, "Export (Fake!) ARB Program extensions"); + char *env_es = getenv("LIBGL_ES"); + if (env_es && strcmp(env_es, "1") == 0) { + globals4es.es = 1; + } + if (env_es && strcmp(env_es, "2") == 0) { + globals4es.es = 2; + } + // automatic ES backend selection + if(globals4es.es==0) + globals4es.es = DEFAULT_ES; + + char *env_gl = getenv("LIBGL_GL"); + if (env_gl && strcmp(env_gl, "15") == 0) { + globals4es.gl = 15; + } + if (env_gl && strcmp(env_gl, "20") == 0) { + globals4es.gl = 20; + } + if (env_gl && strcmp(env_gl, "21") == 0) { + globals4es.gl = 21; + } + // automatic GL version selection + if(globals4es.gl==0) + globals4es.gl = (globals4es.es==1)?15:20; // forcing GL 1.5 for es1.1 and GL 2.0 for es2.0 + + SHUT(LOGD("LIBGL: Using GLES %s backend\n", (globals4es.es==1)?"1.1":"2.0")); + + env(LIBGL_NODEPTHTEX, globals4es.nodepthtex, "Disable usage of Depth Textures"); + char* env_drmcard = getenv("LIBGL_DRMCARD"); + if(env_drmcard) { +#ifdef NO_GBM + SHUT(LOGD("LIBGL: Warning, GBM not compiled in, cannot use LIBGL_DRMCARD\n")); +#else + strncpy(globals4es.drmcard, env_drmcard, 50); + } else { + strcpy(globals4es.drmcard, "/dev/dri/card0"); +#endif + } + +#ifndef __EMSCRIPTEN__ + load_libs(); + if(globals4es.usegbm) + LoadGBMFunctions(); + if(globals4es.usegbm && !gbm) { + SHUT(LOGD("LIBGL: cannot use GBM, disabling\n")); + globals4es.usegbm = 0; // should do some smarter fallback? + } + glx_init(); +#else + globals4es.usegbm = 0; +#endif + +#if (defined(NOEGL) && !defined(ANDROID)) || defined(__EMSCRIPTEN__) + int gl4es_notest = 1; +#else + int gl4es_notest = 0; + char *env_notest = getenv("LIBGL_NOTEST"); + if (env_notest && strcmp(env_notest, "1") == 0) { + gl4es_notest = 1; + } +#endif + env(LIBGL_NOHIGHP, globals4es.nohighp, "Do not use HIGHP in fragment shader even if detected"); + + globals4es.floattex = 1; + char *env_float = getenv("LIBGL_FLOAT"); + if (env_float && strcmp(env_float, "0") == 0) { + globals4es.floattex = 0; + SHUT(LOGD("LIBGL: Float and Half-Float texture support disabled\n")); + } + if (env_float && strcmp(env_float, "2") == 0) { + globals4es.floattex = 2; + SHUT(LOGD("LIBGL: Float and Half-float texture support forced\n")); + } + GetHardwareExtensions(gl4es_notest); + gl_init(); + + env(LIBGL_RECYCLEFBO, globals4es.recyclefbo, "Recycling of FBO enabled"); + // Texture hacks + char *env_mipmap = getenv("LIBGL_MIPMAP"); + if (env_mipmap && strcmp(env_mipmap, "1") == 0) { + globals4es.automipmap = 1; + SHUT(LOGD("LIBGL: AutoMipMap forced\n")); + } + if (env_mipmap && strcmp(env_mipmap, "2") == 0) { + globals4es.automipmap = 2; + SHUT(LOGD("LIBGL: guess AutoMipMap\n")); + } + if (env_mipmap && strcmp(env_mipmap, "3") == 0) { + globals4es.automipmap = 3; + SHUT(LOGD("LIBGL: ignore MipMap\n")); + } + if (env_mipmap && strcmp(env_mipmap, "4") == 0) { + globals4es.automipmap = 4; + SHUT(LOGD("LIBGL: ignore AutoMipMap on non-squared textures\n")); + } + if (env_mipmap && strcmp(env_mipmap, "5") == 0) { + globals4es.automipmap = 5; + SHUT(LOGD("LIBGL: Calculate sub-mipmap incase some are missing\n")); + } + char *env_texcopy = getenv("LIBGL_TEXCOPY"); + if (env_texcopy && strcmp(env_texcopy, "1") == 0) { + globals4es.texcopydata = 1; + SHUT(LOGD("LIBGL: Texture copy enabled\n")); + } + char *env_shrink = getenv("LIBGL_SHRINK"); + if(env_shrink) { + if (env_shrink && strcmp(env_shrink, "10") == 0) { + globals4es.texshrink = 10; + SHUT(LOGD("LIBGL: Texture shink, mode 10 selected (advertise 8192 max texture size, but >2048 are quadshrinked and > 512 are shrinked), but not for empty texture\n")); + } + else if (env_shrink && strcmp(env_shrink, "11") == 0) { + globals4es.texshrink = 11; + SHUT(LOGD("LIBGL: Texture shink, mode 11 selected (advertise a max texture size *2, but every texture with one dimension > max texture size will get shrinked to max texture size), but not for empty texture\n")); + } + else if (env_shrink && strcmp(env_shrink, "1") == 0) { + globals4es.texshrink = 1; + SHUT(LOGD("LIBGL: Texture shink, mode 1 selected (everything / 2)\n")); + } + else if (env_shrink && strcmp(env_shrink, "2") == 0) { + globals4es.texshrink = 2; + SHUT(LOGD("LIBGL: Texture shink, mode 2 selected (only > 512 /2 )\n")); + } + else if (env_shrink && strcmp(env_shrink, "3") == 0) { + globals4es.texshrink = 3; + SHUT(LOGD("LIBGL: Texture shink, mode 3 selected (only > 256 /2 )\n")); + } + else if (env_shrink && strcmp(env_shrink, "4") == 0) { + globals4es.texshrink = 4; + SHUT(LOGD("LIBGL: Texture shink, mode 4 selected (only > 256 /2, >=1024 /4 )\n")); + } + else if (env_shrink && strcmp(env_shrink, "5") == 0) { + globals4es.texshrink = 5; + SHUT(LOGD("LIBGL: Texture shink, mode 5 selected (every > 256 is downscaled to 256 ), but not for empty texture\n")); + } + else if (env_shrink && strcmp(env_shrink, "6") == 0) { + globals4es.texshrink = 6; + SHUT(LOGD("LIBGL: Texture shink, mode 6 selected (only > 128 /2, >=512 is downscaled to 256 ), but not for empty texture\n")); + } + else if (env_shrink && strcmp(env_shrink, "7") == 0) { + globals4es.texshrink = 7; + SHUT(LOGD("LIBGL: Texture shink, mode 7 selected (only > 512 /2 ), but not for empty texture\n")); + } + else if (env_shrink && strcmp(env_shrink, "8") == 0) { + globals4es.texshrink = 8; + SHUT(LOGD("LIBGL: Texture shink, mode 8 selected (advertise 8192 max texture size, but >2048 are shrinked to 2048)\n")); + } + else if (env_shrink && strcmp(env_shrink, "9") == 0) { + globals4es.texshrink = 9; + SHUT(LOGD("LIBGL: Texture shink, mode 9 selected (advertise 8192 max texture size, but >4096 are quadshrinked and > 512 are shrinked), but not for empty texture\n")); + } + } + + char *env_dump = getenv("LIBGL_TEXDUMP"); + if (env_dump && strcmp(env_dump, "1") == 0) { + globals4es.texdump = 1; + SHUT(LOGD("LIBGL: Texture dump enabled\n")); + } + char *env_alpha = getenv("LIBGL_ALPHAHACK"); + if (env_alpha && strcmp(env_alpha, "1") == 0) { + globals4es.alphahack = 1; + SHUT(LOGD("LIBGL: Alpha Hack enabled\n")); + } +#ifdef TEXSTREAM + char *env_stream = getenv("LIBGL_STREAM"); + if (env_stream && strcmp(env_stream, "1") == 0) { + globals4es.texstream = InitStreamingCache(); + SHUT(LOGD("LIBGL: Streaming texture %s\n",(globals4es.texstream)?"enabled":"not available")); + //FreeStreamed(AddStreamed(1024, 512, 0)); + } + if (env_stream && strcmp(env_stream, "2") == 0) { + globals4es.texstream = InitStreamingCache()?2:0; + SHUT(LOGD("LIBGL: Streaming texture %s\n",(globals4es.texstream)?"forced":"not available")); + //FreeStreamed(AddStreamed(1024, 512, 0)); + } +#endif + char *env_lumalpha = getenv("LIBGL_NOLUMALPHA"); + if (env_lumalpha && strcmp(env_lumalpha, "1") == 0) { + globals4es.nolumalpha = 1; + SHUT(LOGD("LIBGL: GL_LUMINANCE_ALPHA hardware support disabled\n")); + } + + env(LIBGL_BLENDHACK, globals4es.blendhack, "Change Blend GL_SRC_ALPHA, GL_ONE to GL_ONE, GL_ONE"); + env(LIBGL_BLENDCOLOR, globals4es.blendcolor, "Export a (faked) glBlendColor"); + env(LIBGL_NOERROR, globals4es.noerror, "glGetError() always return GL_NOERROR"); + globals4es.silentstub = 1; + char *env_silentstub = getenv("LIBGL_SILENTSTUB"); + if (env_silentstub && strcmp(env_silentstub, "0") == 0) { + globals4es.silentstub = 0; + SHUT(LOGD("LIBGL: Stub/non present functions are printed")); + } + env(LIBGL_VABGRA, globals4es.vabgra, "Export GL_ARB_vertex_array_bgra extension"); + + char *env_version = getenv("LIBGL_VERSION"); + if (env_version) { + SHUT(LOGD("LIBGL: Overide version string with \"%s\" (should be in the form of \"1.x\")\n", env_version)); + } + if(env_version) { + snprintf(globals4es.version, 49, "%s gl4es wrapper %d.%d.%d", env_version, MAJOR, MINOR, REVISION); + SHUT(LOGD("LIBGL: Targeting OpenGL %s\n", env_version)); + } else { + snprintf(globals4es.version, 49, "%d.%d gl4es wrapper %d.%d.%d", globals4es.gl/10, globals4es.gl%10, MAJOR, MINOR, REVISION); + SHUT(LOGD("LIBGL: Targeting OpenGL %d.%d\n", globals4es.gl/10, globals4es.gl%10)); + } + + char *env_srgb = getenv("LIBGL_SRGB"); + if (env_srgb && strcmp(env_srgb, "1") == 0 && hardext.srgb) { + globals4es.glx_surface_srgb = 2; + SHUT(LOGD("LIBGL: enabling sRGB support\n")); + } + char *env_fastmath = getenv("LIBGL_FASTMATH"); + if (env_fastmath && strcmp(env_fastmath, "1") == 0) { +#if defined(PANDORA) || defined(CHIP) + SHUT(LOGD("LIBGL: Enable FastMath for cortex-a8\n")); + fast_math(); +#else + SHUT(LOGD("LIBGL: No FastMath on this platform\n")); +#endif + } + char *env_npot = getenv("LIBGL_NPOT"); + switch(hardext.npot) { + case 0: globals4es.npot = 0; break; + case 1: + case 2: globals4es.npot = 1; break; + case 3: globals4es.npot = 2; break; + } + if (env_npot && strcmp(env_npot, "1") == 0 && globals4es.npot<1) { + globals4es.npot = 1; + SHUT(LOGD("LIBGL: Expose limited NPOT extension\n")); + } + if (env_npot && strcmp(env_npot, "2") == 0 && globals4es.npot<3) { + globals4es.npot = 2; + SHUT(LOGD("LIBGL: Expose GL_ARB_texture_non_power_of_two extension\n")); + } + char *env_queries = getenv("LIBGL_GLQUERIES"); + if (env_queries && strcmp(env_queries, "0") == 0) { + globals4es.queries = 0; + SHUT(LOGD("LIBGL: Dont't expose fake glQueries functions\n")); + } + char *env_nodownsampling = getenv("LIBGL_NODOWNSAMPLING"); + if (env_nodownsampling && strcmp(env_nodownsampling, "1") == 0) { + globals4es.nodownsampling = 1; + SHUT(LOGD("LIBGL: No downsampling of DXTc textures\n")); + } + + env(LIBGL_NOTEXMAT, globals4es.texmat, "Don't handle Texture Matrice internaly"); + env(LIBGL_NOVAOCACHE, globals4es.novaocache, "Don't use VAO cache"); + + char *env_beginend = getenv("LIBGL_BEGINEND"); + if(env_beginend) { + if (strcmp(env_beginend, "0") == 0) { + globals4es.beginend = 0; + globals4es.mergelist = 0; + SHUT(LOGD("LIBGL: Don't try to merge subsequent glBegin/glEnd blocks\n")); + } + if (strcmp(env_beginend, "1") == 0 || strcmp(env_beginend, "2") == 0) { + globals4es.beginend = 1; + SHUT(LOGD("LIBGL: Try to merge subsequent glBegin/glEnd blocks, even if there is a glColor / glNormal in between\n")); + } + } + env(LIBGL_AVOID16BITS, globals4es.avoid16bits, "Avoid 16bits textures"); + + globals4es.avoid24bits = 0; + char *env_avoid24bits = getenv("LIBGL_AVOID24BITS"); + if(env_avoid24bits) { + if (strcmp(env_avoid24bits, "0") == 0) { + globals4es.avoid24bits = 0; + SHUT(LOGD("LIBGL: Don't try to avoid 24bits textures\n")); + } + if (strcmp(env_avoid24bits, "1") == 0) { + globals4es.avoid24bits = 2; + SHUT(LOGD("LIBGL: Avoid 24bits textures\n")); + } + } + + env(LIBGL_FORCE16BITS, globals4es.force16bits, "Force 16bits textures"); + + env(LIBGL_POTFRAMEBUFFER, globals4es.potframebuffer, "Force framebuffers to be on POT size"); + + char *env_forcenpot = getenv("LIBGL_FORCENPOT"); + if ((env_forcenpot && strcmp(env_forcenpot,"0") == 0) && (hardext.esversion==2 && (hardext.npot==1 || hardext.npot==2))) { + SHUT(LOGD("LIBGL: Not forcing NPOT support\n")); + } else + if ((env_forcenpot && strcmp(env_forcenpot,"1") == 0) || (hardext.esversion==2 && (hardext.npot==1 || hardext.npot==2))) { + if(hardext.npot==3) { + SHUT(LOGD("LIBGL: NPOT texture handled in hardware\n")); + } else if(hardext.npot==1) { + globals4es.forcenpot = 1; + SHUT(LOGD("LIBGL: Forcing NPOT support by disabling MIPMAP support for NPOT textures \n")); + } else { + SHUT(LOGD("LIBGL: WARNING, No Limited or Full NPOT support in hardware, Forcing NPOT have no effect!\n")); + } + } + globals4es.batch = 0; + char *env_batch = getenv("LIBGL_BATCH"); + int tmp = 0; + if(env_batch && sscanf(env_batch, "%d", &tmp)==1) { + globals4es.batch = tmp; + if(tmp==0) { + SHUT(LOGD("LIBGL: Not trying to batch small subsequent glDrawXXXX\n")); + } else { + SHUT(LOGD("LIBGL: Trying to batch subsequent glDrawXXXX of size < %d vertices\n", tmp*10)); + } + } + + globals4es.usevbo = 0; + char *env_usevbo = getenv("LIBGL_USEVBO"); + /*if(env_usevbo && strcmp(env_usevbo,"0") == 0) { + SHUT(LOGD("LIBGL: Use of VBO disabled\n")); + globals4es.usevbo = 0; + } else*/ if(env_usevbo && strcmp(env_usevbo,"1") == 0) { + globals4es.usevbo = 1; + } + if(globals4es.usevbo) { + SHUT(LOGD("LIBGL: VBO used (in a few cases)\n")); + } + + globals4es.fbomakecurrent = 0; + if((hardext.vendor & VEND_ARM) || (globals4es.usefb)) + globals4es.fbomakecurrent = 1; + char *env_fbomakecurrent = getenv("LIBGL_FBOMAKECURRENT"); + if(globals4es.fbomakecurrent && env_fbomakecurrent && !strcmp(env_fbomakecurrent, "0")) { + globals4es.fbomakecurrent = 0; + SHUT(LOGD("LIBGL: glXMakeCurrent FBO workaround disabled\n")); + } + if(env_fbomakecurrent && !strcmp(env_fbomakecurrent, "1")) + globals4es.fbomakecurrent = 1; + if(globals4es.fbomakecurrent) { + SHUT(LOGD("LIBGL: glXMakeCurrent FBO workaround enabled\n")); + } + + globals4es.fbounbind = 0; + if((hardext.vendor & VEND_ARM) || (hardext.vendor & VEND_IMGTEC)) + globals4es.fbounbind = 1; + char *env_fbounbind = getenv("LIBGL_FBOUNBIND"); + if(globals4es.fbounbind && env_fbounbind && !strcmp(env_fbounbind, "0")) { + globals4es.fbounbind = 0; + SHUT(LOGD("LIBGL: FBO workaround for using binded texture disabled\n")); + } + if(env_fbounbind && !strcmp(env_fbounbind, "1")) + globals4es.fbounbind = 1; + if(globals4es.fbounbind) { + SHUT(LOGD("LIBGL: FBO workaround for using binded texture enabled\n")); + } + + env(LIBGL_FBOFORCETEX, globals4es.fboforcetex, "Force texture for Attachment color0 on FBO"); + + env(LIBGL_COMMENTS, globals4es.comments, "Keep comments in converted Shaders"); + + if(hardext.npot==3) + globals4es.defaultwrap=0; + else + globals4es.defaultwrap=1; + char *env_defaultwrap = getenv("LIBGL_DEFAULTWRAP"); + if(env_defaultwrap && !strcmp(env_defaultwrap, "0")) { + globals4es.defaultwrap = 0; + SHUT(LOGD("LIBGL: Default wrap mode is GL_REPEAT\n")); + } else if(env_defaultwrap && !strcmp(env_defaultwrap, "1")) { + globals4es.defaultwrap = 1; + SHUT(LOGD("LIBGL: Default wrap mode is GL_CLAMP_TO_EDGE\n")); + } else if(env_defaultwrap && !strcmp(env_defaultwrap, "2")) { + globals4es.defaultwrap = 2; + SHUT(LOGD("LIBGL: Default wrap mode is GL_CLAMP_TO_EDGE, enforced\n")); + } + + globals4es.notexarray = 0; + char *env_notexarray = getenv("LIBGL_NOTEXARRAY"); + if(env_notexarray && !strcmp(env_notexarray, "0")) + globals4es.notexarray = 0; + else if(env_notexarray && !strcmp(env_notexarray, "1")) + globals4es.notexarray = 1; + if(globals4es.notexarray) { + SHUT(LOGD("LIBGL: No Texture Array in Shaders\n")); + } + + env(LIBGL_LOGSHADERERROR, globals4es.logshader, "Log to the console Error compiling shaders"); + env(LIBGL_SHADERNOGLES, globals4es.shadernogles, "Remove GLES part in shader"); + char *env_dbgshaderconv = getenv("LIBGL_DBGSHADERCONV"); + if(env_dbgshaderconv) { + if(sscanf(env_dbgshaderconv, "%d", &globals4es.dbgshaderconv)!=1) + globals4es.dbgshaderconv = 0; + if(globals4es.dbgshaderconv) { + if(globals4es.dbgshaderconv==1) + globals4es.dbgshaderconv=15; + if(!(globals4es.dbgshaderconv&3)) // neither vertex or fragment + globals4es.dbgshaderconv|=3; // select both + if(!(globals4es.dbgshaderconv&12)) // neither before or after + globals4es.dbgshaderconv|=12; // select both + SHUT(LOGD("Log to the console all shaders before and after conversion: ")); + if(globals4es.dbgshaderconv&4) + SHUT(LOGD("Before ")); + if(globals4es.dbgshaderconv&8) + SHUT(LOGD("After ")); + if(globals4es.dbgshaderconv&1) + SHUT(LOGD("Vertex ")); + if(globals4es.dbgshaderconv&2) + SHUT(LOGD("Fragment ")); + SHUT(LOGD("\n")); + } + } + env(LIBGL_NOCLEAN, globals4es.noclean, "Don't clean Context when destroy"); + + + globals4es.glxrecycle = 1; +#ifndef NOEGL + if((globals4es.usepbuffer) || (globals4es.usefb)) + globals4es.glxrecycle = 0; + char *env_glxrecycle = getenv("LIBGL_GLXRECYCLE"); + if(globals4es.glxrecycle && env_glxrecycle && !strcmp(env_glxrecycle, "0") && !((globals4es.usepbuffer) || (globals4es.usefb))) { + globals4es.glxrecycle = 0; + SHUT(LOGD("LIBGL: glX Will NOT try to recycle EGL Surface\n")); + } + if(env_glxrecycle && !strcmp(env_glxrecycle, "1")) + globals4es.glxrecycle = 1; + if(globals4es.glxrecycle) { + SHUT(LOGD("LIBGL: glX Will try to recycle EGL Surface\n")); + } +#endif + char cwd[1024]; + if (getcwd(cwd, sizeof(cwd))!= NULL) + SHUT(LOGD("LIBGL: Current folder is:%s\n", cwd)); +} diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/init.h b/Projects/Android/jni/SupportLibs/gl4es/src/gl/init.h new file mode 100644 index 0000000..efc6d86 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/init.h @@ -0,0 +1,74 @@ +#ifndef _GL4ES_INIT_H_ +#define _GL4ES_INIT_H_ + +#if defined(PANDORA) +#define USE_FBIO 1 +#endif + +typedef struct _globals4es { + int nobanner; + int mergelist; + int xrefresh; + int stacktrace; + int usefb; + int usegbm; + int usefbo; + int recyclefbo; + int usepbuffer; + int showfps; + int vsync; + int automipmap; + int texcopydata; + int tested_env; + int texshrink; + int texdump; + int alphahack; + int texstream; + int nolumalpha; + int blendhack; + int blendcolor; + int noerror; + int npot; + int defaultwrap; + int queries; + int silentstub; + int glx_surface_srgb; + int nodownsampling; + int vabgra; + int nobgra; + int potframebuffer; + float gamma; + int texmat; + int novaocache; + int beginend; + int avoid16bits; + int avoid24bits; + int force16bits; + int nohighp; + int batch; + int es; + int gl; + int usevbo; + int comments; + int forcenpot; + int fbomakecurrent; // hack to bind/unbind FBO when doing glXMakeCurrent + int fbounbind; // hack to bind/unbind fbo if a bind texture is used for drawing + int fboforcetex; // force texture attachment for Color0 + int notexarray; + int nodepthtex; + int logshader; + int shadernogles; + int floattex; + int glxrecycle; + int noclean; + int arb_program; + int dbgshaderconv; + #ifndef NO_GBM + char drmcard[50]; + #endif + char version[50]; +} globals4es_t; + +extern globals4es_t globals4es; + +#endif // _GL4ES_INIT_H_ diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/light.c b/Projects/Android/jni/SupportLibs/gl4es/src/gl/light.c new file mode 100644 index 0000000..bf535f5 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/light.c @@ -0,0 +1,442 @@ +#include "light.h" + +#include "../glx/hardext.h" +#include "fpe.h" +#include "loader.h" +#include "matrix.h" +#include "matvec.h" + +void gl4es_glLightModelf(GLenum pname, GLfloat param) { +//printf("%sglLightModelf(%04X, %.2f)\n", (state.list.compiling)?"list":"", pname, param); + ERROR_IN_BEGIN + if(glstate->list.active) + if ((glstate->list.compiling)) { + GLfloat dummy[4]; + dummy[0]=param; + gl4es_glLightModelfv(pname, dummy); + return; + } else flush(); + switch (pname) { + case GL_LIGHT_MODEL_TWO_SIDE: + errorGL(); + glstate->light.two_side = param; + if(glstate->fpe_state) + glstate->fpe_state->twosided = param; + break; + case GL_LIGHT_MODEL_COLOR_CONTROL: + if(param!=GL_SINGLE_COLOR && param!=GL_SEPARATE_SPECULAR_COLOR ) { + errorShim(GL_INVALID_VALUE); + return; + } else { + GLboolean value = (param==GL_SEPARATE_SPECULAR_COLOR); + if(glstate->light.separate_specular == value) { + noerrorShim(); + return; + } + glstate->light.separate_specular=value; + if(glstate->fpe_state) + glstate->fpe_state->light_separate=value; + } + return; // NOT Supported in GLES 1.1 anyway + case GL_LIGHT_MODEL_LOCAL_VIEWER: + { + GLboolean value = (param!=0.0); + if(glstate->light.local_viewer == value) { + noerrorShim(); + return; + } + glstate->light.local_viewer=value; + if(glstate->fpe_state) + glstate->fpe_state->light_localviewer=value; + } + return; // NOT Supported in GLES 1.1 anyway + case GL_LIGHT_MODEL_AMBIENT: + default: + errorShim(GL_INVALID_ENUM); + return; + } + LOAD_GLES_FPE(glLightModelf); + gles_glLightModelf(pname, param); +} + +void gl4es_glLightModelfv(GLenum pname, const GLfloat* params) { +//printf("%sglLightModelfv(%04X, [%.2f, %.2f, %.2f, %.2f])\n", (state.list.compiling)?"list":"", pname, params[0], params[1], params[2], params[3]); + ERROR_IN_BEGIN + if(glstate->list.active) + if ((glstate->list.compiling)) { + NewStage(glstate->list.active, STAGE_LIGHTMODEL); + /* if (glstate->list.active->lightmodel) + glstate->list.active = extend_renderlist(glstate->list.active);*/ + glstate->list.active->lightmodelparam = pname; + glstate->list.active->lightmodel = (GLfloat*)malloc(4*sizeof(GLfloat)); + int sz = 4; + if(pname==GL_LIGHT_MODEL_TWO_SIDE || pname==GL_LIGHT_MODEL_COLOR_CONTROL || pname==GL_LIGHT_MODEL_LOCAL_VIEWER) + sz=1; + memcpy(glstate->list.active->lightmodel, params, sz*sizeof(GLfloat)); + noerrorShim(); + return; + } else flush(); + switch (pname) { + case GL_LIGHT_MODEL_AMBIENT: + if(memcmp(glstate->light.ambient, params, 4*sizeof(GLfloat))==0) { + noerrorShim(); + return; + } + errorGL(); + memcpy(glstate->light.ambient, params, 4*sizeof(GLfloat)); + break; + case GL_LIGHT_MODEL_TWO_SIDE: + if(glstate->light.two_side == params[0]) { + noerrorShim(); + return; + } + errorGL(); + glstate->light.two_side = params[0]; + if(glstate->fpe_state) + glstate->fpe_state->twosided = params[0]; + break; + case GL_LIGHT_MODEL_COLOR_CONTROL: + if(params[0]!=GL_SINGLE_COLOR && params[0]!=GL_SEPARATE_SPECULAR_COLOR ) { + errorShim(GL_INVALID_VALUE); + return; + } else { + GLboolean value = (params[0]==GL_SEPARATE_SPECULAR_COLOR); + if(glstate->light.separate_specular == value) { + noerrorShim(); + return; + } + glstate->light.separate_specular=value; + if(glstate->fpe_state) + glstate->fpe_state->light_separate=value; + } + return; // NOT Supported in GLES 1.1 anyway + case GL_LIGHT_MODEL_LOCAL_VIEWER: + { + GLboolean value = (params[0]!=0.0); + if(glstate->light.local_viewer == value) { + noerrorShim(); + return; + } + glstate->light.local_viewer=value; + if(glstate->fpe_state) + glstate->fpe_state->light_localviewer=value; + } + return; // NOT Supported in GLES 1.1 anyway + default: + errorShim(GL_INVALID_ENUM); + return; + } + LOAD_GLES_FPE(glLightModelfv); + gles_glLightModelfv(pname, params); +} + +void gl4es_glLightfv(GLenum light, GLenum pname, const GLfloat* params) { +//printf("%sglLightfv(%s, %s, %p=[%.2f, %.2f, %.2f, %.2f])\n", (glstate->list.compiling)?"list":"", PrintEnum(light), PrintEnum(pname), params, (params)?params[0]:0.0f, (params)?params[1]:0.0f, (params)?params[2]:0.0f, (params)?params[3]:0.0f); + const int nl = light-GL_LIGHT0; + if(nl<0 || nl>=hardext.maxlights) { + errorShim(GL_INVALID_ENUM); + return; + } + ERROR_IN_BEGIN + if(glstate->list.active) + if (glstate->list.compiling) { + NewStage(glstate->list.active, STAGE_LIGHT); + rlLightfv(glstate->list.active, light, pname, params); + noerrorShim(); + return; + } else flush(); + + GLfloat tmp[4]; + GLfloat mtmp[16]; + noerrorShim(); + switch(pname) { + case GL_AMBIENT: + if(memcmp(glstate->light.lights[nl].ambient, params, 4*sizeof(GLfloat))==0) + return; + memcpy(glstate->light.lights[nl].ambient, params, 4*sizeof(GLfloat)); + break; + case GL_DIFFUSE: + if(memcmp(glstate->light.lights[nl].diffuse, params, 4*sizeof(GLfloat))==0) + return; + memcpy(glstate->light.lights[nl].diffuse, params, 4*sizeof(GLfloat)); + break; + case GL_SPECULAR: + if(memcmp(glstate->light.lights[nl].specular, params, 4*sizeof(GLfloat))==0) + return; + memcpy(glstate->light.lights[nl].specular, params, 4*sizeof(GLfloat)); + break; + case GL_POSITION: + vector_matrix(params, getMVMat(), tmp); + if(memcmp(glstate->light.lights[nl].position, tmp, 4*sizeof(GLfloat))==0) + return; + memcpy(glstate->light.lights[nl].position, tmp, 4*sizeof(GLfloat)); + if(glstate->fpe_state) { + int dir = (tmp[3]!=0.f); + if (dir) { + glstate->fpe_state->light_direction |= (1<fpe_state->light_direction &= ~(1<light.lights[nl].spotDirection, tmp, 3*sizeof(GLfloat))==0) + return; + memcpy(glstate->light.lights[nl].spotDirection, tmp, 3*sizeof(GLfloat)); + break; + case GL_SPOT_EXPONENT: + if(params[0]<0 || params[0]>128) { + errorShim(GL_INVALID_VALUE); + return; + } + if(glstate->light.lights[nl].spotExponent == params[0]) + return; + glstate->light.lights[nl].spotExponent = params[0]; + break; + case GL_SPOT_CUTOFF: + if(params[0]<0.f || (params[0]>90.0f && params[0]!=180.f)) { + errorShim(GL_INVALID_VALUE); + return; + } + if(glstate->light.lights[nl].spotCutoff == params[0]) + return; + glstate->light.lights[nl].spotCutoff = params[0]; + if(glstate->fpe_state) { + int dir = (params[0]!=180.f); + if (dir) { + glstate->fpe_state->light_cutoff180 |= (1<fpe_state->light_cutoff180 &= ~(1<light.lights[nl].constantAttenuation == params[0]) + return; + glstate->light.lights[nl].constantAttenuation = params[0]; + break; + case GL_LINEAR_ATTENUATION: + if(params[0]<0) { + errorShim(GL_INVALID_VALUE); + return; + } + if(glstate->light.lights[nl].linearAttenuation == params[0]) + return; + glstate->light.lights[nl].linearAttenuation = params[0]; + break; + case GL_QUADRATIC_ATTENUATION: + if(params[0]<0) { + errorShim(GL_INVALID_VALUE); + return; + } + if(glstate->light.lights[nl].quadraticAttenuation == params[0]) + return; + glstate->light.lights[nl].quadraticAttenuation = params[0]; + break; + } + LOAD_GLES_FPE(glLightfv); + gles_glLightfv(light, pname, params); + errorGL(); +} + +void gl4es_glLightf(GLenum light, GLenum pname, GLfloat param) { + GLfloat dummy[4]; + dummy[0]=param; + gl4es_glLightfv(light, pname, dummy); +} + +void gl4es_glMaterialfv(GLenum face, GLenum pname, const GLfloat *params) { + if(glstate->list.active) + if(glstate->list.begin) { + // if a glMaterialfv is called inside a glBegin/glEnd block + // then use rlMaterial to store in current list the material wanted + // as if the material was asked before the glBegin() + // It's not real behavour, but it's better then nothing + rlMaterialfv(glstate->list.active, face, pname, params); + noerrorShim(); + return; + } else { + if (glstate->list.compiling) { + NewStage(glstate->list.active, STAGE_MATERIAL); + rlMaterialfv(glstate->list.active, face, pname, params); + noerrorShim(); + return; + } else flush(); + } + if(face!=GL_FRONT_AND_BACK && face!=GL_FRONT && face!=GL_BACK) { + errorShim(GL_INVALID_ENUM); + return; + } + switch(pname) { + case GL_AMBIENT: + if(face==GL_FRONT_AND_BACK || face==GL_FRONT) + memcpy(glstate->material.front.ambient, params, 4*sizeof(GLfloat)); + if(face==GL_FRONT_AND_BACK || face==GL_BACK) + memcpy(glstate->material.back.ambient, params, 4*sizeof(GLfloat)); + break; + case GL_DIFFUSE: + if(face==GL_FRONT_AND_BACK || face==GL_FRONT) + memcpy(glstate->material.front.diffuse, params, 4*sizeof(GLfloat)); + if(face==GL_FRONT_AND_BACK || face==GL_BACK) + memcpy(glstate->material.back.diffuse, params, 4*sizeof(GLfloat)); + break; + case GL_SPECULAR: + if(face==GL_FRONT_AND_BACK || face==GL_FRONT) + memcpy(glstate->material.front.specular, params, 4*sizeof(GLfloat)); + if(face==GL_FRONT_AND_BACK || face==GL_BACK) + memcpy(glstate->material.back.specular, params, 4*sizeof(GLfloat)); + break; + case GL_EMISSION: + if(face==GL_FRONT_AND_BACK || face==GL_FRONT) + memcpy(glstate->material.front.emission, params, 4*sizeof(GLfloat)); + if(face==GL_FRONT_AND_BACK || face==GL_BACK) + memcpy(glstate->material.back.emission, params, 4*sizeof(GLfloat)); + break; + case GL_AMBIENT_AND_DIFFUSE: + if(face==GL_FRONT_AND_BACK || face==GL_FRONT) { + memcpy(glstate->material.front.ambient, params, 4*sizeof(GLfloat)); + memcpy(glstate->material.front.diffuse, params, 4*sizeof(GLfloat)); + } + if(face==GL_FRONT_AND_BACK || face==GL_BACK) { + memcpy(glstate->material.back.ambient, params, 4*sizeof(GLfloat)); + memcpy(glstate->material.back.diffuse, params, 4*sizeof(GLfloat)); + } + break; + case GL_SHININESS: + if(*params<0.0f || *params>128.0f) { + errorShim(GL_INVALID_VALUE); + return; + } + if(face==GL_FRONT_AND_BACK || face==GL_FRONT) { + glstate->material.front.shininess = *params; + if(glstate->fpe_state) + glstate->fpe_state->cm_front_nullexp=(*params<=0.0)?0:1; + } + if(face==GL_FRONT_AND_BACK || face==GL_BACK) { + glstate->material.back.shininess = *params; + if(glstate->fpe_state) + glstate->fpe_state->cm_back_nullexp=(*params<=0.0)?0:1; + } + break; + case GL_COLOR_INDEXES: + if(face==GL_FRONT_AND_BACK || face==GL_FRONT) { + glstate->material.front.indexes[0] = params[0]; + glstate->material.front.indexes[1] = params[1]; + glstate->material.front.indexes[2] = params[2]; + } + if(face==GL_FRONT_AND_BACK || face==GL_BACK) { + glstate->material.back.indexes[0] = params[0]; + glstate->material.back.indexes[1] = params[1]; + glstate->material.back.indexes[2] = params[2]; + } + break; + } + + if(face==GL_BACK) { // lets ignore GL_BACK in GLES 1.1 + noerrorShim(); + return; + } + LOAD_GLES_FPE(glMaterialfv); + gles_glMaterialfv(GL_FRONT_AND_BACK, pname, params); + errorGL(); +} + +void gl4es_glMaterialf(GLenum face, GLenum pname, GLfloat param) { + ERROR_IN_BEGIN + if(glstate->list.active) + if (glstate->list.compiling) { + GLfloat params[4]; + memset(params, 0, 4*sizeof(GLfloat)); + params[0] = param; + NewStage(glstate->list.active, STAGE_MATERIAL); + rlMaterialfv(glstate->list.active, face, pname, params); + noerrorShim(); + return; + } else flush(); + + if(face!=GL_FRONT_AND_BACK && face!=GL_FRONT && face!=GL_BACK) { + errorShim(GL_INVALID_ENUM); + return; + } + if(pname!=GL_SHININESS) { + errorShim(GL_INVALID_ENUM); + return; + } + if(param<0.0f || param>128.0f) { + errorShim(GL_INVALID_VALUE); + return; + } + if(face==GL_FRONT_AND_BACK || face==GL_FRONT) { + glstate->material.front.shininess = param; + if(glstate->fpe_state) + glstate->fpe_state->cm_front_nullexp=(param<=0.0)?0:1; + } + if(face==GL_FRONT_AND_BACK || face==GL_BACK) { + glstate->material.back.shininess = param; + if(glstate->fpe_state) + glstate->fpe_state->cm_back_nullexp=(param<=0.0)?0:1; + } + + if(face==GL_BACK && hardext.esversion==1) { // lets ignore GL_BACK in GLES 1.1 + noerrorShim(); + return; + } + + LOAD_GLES_FPE(glMaterialf); + gles_glMaterialf(GL_FRONT_AND_BACK, pname, param); + errorGL(); +} + +void gl4es_glColorMaterial(GLenum face, GLenum mode) { + ERROR_IN_BEGIN + if(glstate->list.active) + if (glstate->list.compiling) { + NewStage(glstate->list.active, STAGE_COLOR_MATERIAL); + glstate->list.active->colormat_face = face; + glstate->list.active->colormat_mode = mode; + noerrorShim(); + return; + } else flush(); + + if(face!=GL_FRONT_AND_BACK && face!=GL_FRONT && face!=GL_BACK) { + errorShim(GL_INVALID_ENUM); + return; + } + if(mode!=GL_EMISSION && mode!=GL_AMBIENT && mode!=GL_DIFFUSE && mode!=GL_SPECULAR && mode!=GL_AMBIENT_AND_DIFFUSE) { + errorShim(GL_INVALID_ENUM); + return; + } + if(face==GL_FRONT_AND_BACK || face==GL_FRONT) + glstate->material.front.colormat = mode; + if(face==GL_FRONT_AND_BACK || face==GL_BACK) + glstate->material.back.colormat = mode; + if(glstate->fpe_state) { + int value = FPE_CM_AMBIENTDIFFUSE; + switch(mode) { + case GL_EMISSION: value = FPE_CM_EMISSION; break; + case GL_AMBIENT: value=FPE_CM_AMBIENT; break; + case GL_DIFFUSE: value=FPE_CM_DIFFUSE; break; + case GL_SPECULAR: value=FPE_CM_SPECULAR; break; + } + if(face==GL_FRONT_AND_BACK || face==GL_FRONT) { + glstate->fpe_state->cm_front_mode = value; + } + if(face==GL_FRONT_AND_BACK || face==GL_BACK) { + glstate->fpe_state->cm_back_mode = value; + } + } + noerrorShim(); +} + +void glLightModelf(GLenum pname, GLfloat param) AliasExport("gl4es_glLightModelf"); +void glLightModelfv(GLenum pname, const GLfloat* params) AliasExport("gl4es_glLightModelfv"); +void glLightfv(GLenum light, GLenum pname, const GLfloat* params) AliasExport("gl4es_glLightfv"); +void glLightf(GLenum light, GLenum pname, GLfloat param) AliasExport("gl4es_glLightf"); +void glMaterialfv(GLenum face, GLenum pname, const GLfloat *params) AliasExport("gl4es_glMaterialfv"); +void glMaterialf(GLenum face, GLenum pname, GLfloat param) AliasExport("gl4es_glMaterialf"); +void glColorMaterial(GLenum face, GLenum mode) AliasExport("gl4es_glColorMaterial"); diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/light.h b/Projects/Android/jni/SupportLibs/gl4es/src/gl/light.h new file mode 100644 index 0000000..180b650 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/light.h @@ -0,0 +1,53 @@ +#ifndef _GL4ES_LIGHT_H_ +#define _GL4ES_LIGHT_H_ + +#include "gles.h" +#include "../config.h" + +typedef struct { + GLfloat ambient[4]; + GLfloat diffuse[4]; + GLfloat specular[4]; + GLfloat constantAttenuation, linearAttenuation, quadraticAttenuation; + GLfloat position[4]; + GLfloat spotDirection[3]; // It's only 3 in fact, because it's a direction + GLfloat spotExponent; + GLfloat spotCutoff; +} light_t; + +typedef struct { + light_t lights[MAX_LIGHT]; + GLfloat ambient[4]; + GLboolean two_side; + GLboolean separate_specular; + GLboolean local_viewer; +} light_state_t; + +typedef struct { + GLfloat ambient[4]; + GLfloat diffuse[4]; + GLfloat specular[4]; + GLfloat emission[4]; + GLfloat shininess; + int indexes[3]; + GLenum colormat; +} material_t; + +typedef struct { + material_t front; + material_t back; +} material_state_t; + +void gl4es_glLightModelf(GLenum pname, GLfloat param); +void gl4es_glLightModelfv(GLenum pname, const GLfloat* params); +void gl4es_glLightfv(GLenum light, GLenum pname, const GLfloat* params); +void gl4es_glLightf(GLenum light, GLenum pname, const GLfloat params); + +void gl4es_glGetLightfv(GLenum light, GLenum pname, GLfloat * params); +void gl4es_glGetLightiv(GLenum light, GLenum pname, GLint * params); + +void gl4es_glMaterialfv(GLenum face, GLenum pname, const GLfloat *params) ; +void gl4es_glMaterialf(GLenum face, GLenum pname, const GLfloat param); +void gl4es_glColorMaterial(GLenum face, GLenum mode); + +#endif // _GL4ES_LIGHT_H_ diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/line.c b/Projects/Android/jni/SupportLibs/gl4es/src/gl/line.c new file mode 100644 index 0000000..f7c4542 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/line.c @@ -0,0 +1,165 @@ +#include "line.h" + +#include "debug.h" +#include "gl4es.h" +#include "glstate.h" +#include "list.h" +#include "matrix.h" +#include "matvec.h" + +//#define DEBUG +#ifdef DEBUG +#define DBG(a) a +#else +#define DBG(a) +#endif + +void gl4es_glLineStipple(GLuint factor, GLushort pattern) { + DBG(printf("glLineStipple(%d, 0x%04X)\n", factor, pattern);) + if(glstate->list.active) { + if (glstate->list.compiling) { + NewStage(glstate->list.active, STAGE_LINESTIPPLE); + glstate->list.active->linestipple_op = 1; + glstate->list.active->linestipple_factor = factor; + glstate->list.active->linestipple_pattern = pattern; + return; + } else if(glstate->list.pending) flush(); + } + if(factor<1) factor = 1; + if(factor>256) factor = 256; + if(pattern!=glstate->linestipple.pattern || factor!=glstate->linestipple.factor || !glstate->linestipple.texture) { + glstate->linestipple.factor = factor; + glstate->linestipple.pattern = pattern; + for (int i = 0; i < 16; i++) { + glstate->linestipple.data[i] = ((pattern >> i) & 1) ? 255 : 0; + } + + // "Push" current Texture0 binding + GLuint old_act = glstate->texture.active; + if(old_act) + gl4es_glActiveTexture(GL_TEXTURE0); + GLuint old_tex = glstate->texture.bound[0][ENABLED_TEX2D]->texture; + // create / update stipple texture + if (! glstate->linestipple.texture) { + gl4es_glGenTextures(1, &glstate->linestipple.texture); + gl4es_glBindTexture(GL_TEXTURE_2D, glstate->linestipple.texture); + gl4es_glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + gl4es_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + gl4es_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + gl4es_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + gl4es_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + gl4es_glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, + 16, 1, 0, GL_ALPHA, GL_UNSIGNED_BYTE, glstate->linestipple.data); + } else { + gl4es_glBindTexture(GL_TEXTURE_2D, glstate->linestipple.texture); + gl4es_glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 16, 1, + GL_ALPHA, GL_UNSIGNED_BYTE, glstate->linestipple.data); + } + // "Pop" texture 0 binding + gl4es_glBindTexture(GL_TEXTURE_2D, old_tex); + if(old_act) + gl4es_glActiveTexture(GL_TEXTURE0+old_act); + // all done + noerrorShim(); + } +} +void glLineStipple(GLuint factor, GLushort pattern) AliasExport("gl4es_glLineStipple"); + +void bind_stipple_tex() { + gl4es_glBindTexture(GL_TEXTURE_2D, glstate->linestipple.texture); +} + +GLfloat *gen_stipple_tex_coords(GLfloat *vert, GLushort *sindices, modeinit_t *modes, int stride, int length, GLfloat* noalloctex) { + DBG(printf("Generate stripple tex (stride=%d, noalloctex=%p) length=%d:", stride, noalloctex, length);) + // generate our texture coords + GLfloat *tex = noalloctex?noalloctex:(GLfloat *)malloc(modes[length-1].ilen * 4 * sizeof(GLfloat)); + GLfloat *texPos = tex; + GLfloat *vertPos = vert; + + GLfloat x1, x2, y1, y2; + GLfloat oldlen, len; + const GLfloat* mvp = getMVPMat(); + GLfloat v[4]; + GLfloat w = (GLfloat)glstate->raster.viewport.width; + GLfloat h = (GLfloat)glstate->raster.viewport.height; + if(stride==0) stride = 4; else stride/=sizeof(GLfloat); + int texstride = noalloctex?stride:4; + // projected coordinates here, and transform to screen pixel using viewport + // because projected coordinates are from -1. to +1., w and h are to be divided by 2... + w*=0.5f; h*=0.5f; + int i=0; + for (int k=0; k%d] ", PrintEnum(mode), modes[k].ilen);) + oldlen = len = 0.f; + if(modes[k].ilen<2) + continue; + if(mode==GL_LINES || length>1) // always line when multiple lines were merged + for (; i < modes[k].ilen; i+=2) { + if(sindices) + vertPos = vert+stride*sindices[i]; + vector_matrix(vertPos, mvp, v); + if(sindices) + vertPos = vert+stride*sindices[i+1]; + else + vertPos+=stride; + // need to take "w" componant into acount... + if(v[3]==0.0f) { + x1=v[0]*w; y1=v[1]*h; + } else { + x1=(v[0]/v[3])*w; y1=(v[1]/v[3])*h; + } + vector_matrix(vertPos, mvp, v); + vertPos+=stride; + if(v[3]==0.0f) { + x2=v[0]*w; y2=v[1]*h; + } else { + x2=(v[0]/v[3])*w; y2=(v[1]/v[3])*h; + } + oldlen = len; + len += sqrtf((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1)) / (glstate->linestipple.factor * 16.f); + DBG(printf("%f->%f (%f,%f -> %f,%f)\t", oldlen, len, x1, y1, x2, y2);) + if(sindices) + texPos = tex+texstride*sindices[i+0]; // it get writen 2*, but that should be ok, it's the same value + memset(texPos, 0, 4*sizeof(GLfloat)); + texPos[0] = oldlen; texPos[3] = 1.0f; + if(sindices) + texPos = tex+texstride*sindices[i+1]; + else + texPos+=texstride; + memset(texPos, 0, 4*sizeof(GLfloat)); + texPos[0] = len; texPos[3] = 1.0f; + texPos+=texstride; + } + else { // GL_LINE_STRIP and GL_LINE_LOOPS works the same here + // (well, last segment, the "loop" one, will look strange, but I will not add a vertex for that) + if(sindices) + vertPos = vert+stride*sindices[i]; + vector_matrix(vertPos, mvp, v); + x2=(v[0]/v[3])*w; y2=(v[1]/v[3])*h; + vertPos+=stride; + DBG(printf("%f\t", len);) + memset(texPos, 0, 4*sizeof(GLfloat)); + texPos[0] = len; texPos[3] = 1.0f; + texPos+=texstride; + ++i; + for (; i < modes[k].ilen; i++) { + x1 = x2; y1 = y2; + if(sindices) + vertPos = vert+stride*sindices[i]; + vector_matrix(vertPos, mvp, v); + vertPos+=stride; + x2=(v[0]/v[3])*w; y2=(v[1]/v[3])*h; + len += sqrtf((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1)) / (glstate->linestipple.factor * 16.f); + DBG(printf("->%f\t", len);) + if(sindices) + texPos = tex+texstride*sindices[i]; + memset(texPos, 0, 4*sizeof(GLfloat)); + texPos[0] = len; texPos[3] = 1.0f; + texPos+=texstride; + } + } + } + DBG(printf("\n");) + return tex; +} diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/line.h b/Projects/Android/jni/SupportLibs/gl4es/src/gl/line.h new file mode 100644 index 0000000..49fd951 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/line.h @@ -0,0 +1,11 @@ +#ifndef _GL4ES_LINE_H +#define _GL4ES_LINE_H + +#include "gles.h" +#include "list.h" + +void gl4es_glLineStipple(GLuint factor, GLushort pattern); +GLfloat *gen_stipple_tex_coords(GLfloat *vert, GLushort *sindices, modeinit_t *modes, int stride, int length, GLfloat* noalloctex); +void bind_stipple_tex(); + +#endif // _GL4ES_LINE_H diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/list.c b/Projects/Android/jni/SupportLibs/gl4es/src/gl/list.c new file mode 100644 index 0000000..4b94cc5 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/list.c @@ -0,0 +1,943 @@ +#include "list.h" + +#include "../glx/hardext.h" +#include "const.h" +#include "gl4es.h" +#include "glstate.h" +#include "init.h" + +// KH Map implementation +KHASH_MAP_IMPL_INT(material, rendermaterial_t *); +KHASH_MAP_IMPL_INT(light, renderlight_t *); +KHASH_MAP_IMPL_INT(texgen, rendertexgen_t *); +KHASH_MAP_IMPL_INT(texenv, rendertexenv_t *); +KHASH_MAP_IMPL_INT(gllisthead, renderlist_t*); + +renderlist_t *alloc_renderlist() { + int a; + + renderlist_t *list = (renderlist_t *)malloc(sizeof(renderlist_t)); + memset(list, 0, sizeof(renderlist_t)); + list->cap = DEFAULT_RENDER_LIST_CAPACITY; + list->matrix_val[0] = list->matrix_val[5] = list->matrix_val[10] = + list->matrix_val[15] = 1.0f; + list->lightmodelparam = GL_LIGHT_MODEL_AMBIENT; + list->target_texture = GL_TEXTURE_2D; + list->tmu = glstate->texture.active; + + memcpy(list->lastNormal, glstate->normal, 3*sizeof(GLfloat)); + memcpy(list->lastSecondaryColors, glstate->secondary, 3*sizeof(GLfloat)); + memcpy(list->lastColors, glstate->color, 4*sizeof(GLfloat)); + memcpy(&list->lastFogCoord, &glstate->fogcoord, 1*sizeof(GLfloat)); + + list->instanceCount = 1; + + list->open = true; + return list; +} + +bool ispurerender_renderlist(renderlist_t *list) { + // return true if renderlist contains only rendering command, no state changes + if (list->calls.len) + return false; + if (list->matrix_op) + return false; + if (list->raster_op) + return false; + if (list->raster) + return false; + if (list->bitmaps) + return false; + if (list->pushattribute) + return false; + if (list->popattribute) + return false; + if (list->material || list->colormat_face || list->light || list->lightmodel || list->texgen || list->texenv) + return false; + if (list->fog_op) + return false; + if (list->instanceCount!=1) + return false; + if (list->pointparam_op) + return false; + if (list->mode_init == 0) + return false; + if (list->ind_lines || list->final_colors) + return false; + if (list->set_texture || list->set_tmu) + return false; + + return true; +} + +bool isempty_renderlist(renderlist_t *list) { + return (list->stage == STAGE_NONE); +} + +int rendermode_dimensions(GLenum mode) { + // return 1 for points, 2 for any lines, 3 for any triangles, 4 for any Quad and 5 for polygon + switch (mode) { + case GL_POINTS: + return 1; + case GL_LINES: + case GL_LINE_LOOP: + case GL_LINE_STRIP: + return 2; + case GL_TRIANGLES: + case GL_TRIANGLE_FAN: + case GL_TRIANGLE_STRIP: + return 3; + case GL_QUADS: + case GL_QUAD_STRIP: + return 3; // It's 4, but we use only triangles... + case GL_POLYGON: + return 3; // It's 5, but we use only triangles too. + } + return 0; +} + +bool islistscompatible_renderlist(renderlist_t *a, renderlist_t *b) { + if (!globals4es.mergelist || !a) + return false; + + // check if 2 "pure rendering" list are compatible for merge + if (a->mode_init != b->mode_init) { + int a_mode = a->mode_dimension; + int b_mode = b->mode_dimension; + if ((a_mode == 0) || (b_mode == 0)) + return false; // undetermined is not good + if (a_mode == 4) a_mode = 3; // quads are handled as triangles + if (b_mode == 4) b_mode = 3; + if (a_mode != b_mode) + return false; + } + if(!a->open || !b->open) + return false; + if(a->use_glstate) + return false; //TODO: Handle this case +/* if ((a->indices==NULL) != (b->indices==NULL)) + return false;*/ + if (a->polygon_mode != b->polygon_mode) + return false; + if ((a->vert==NULL) != (b->vert==NULL)) + return false; + if ((a->normal==NULL) != (b->normal==NULL)) + return false; + if ((a->color==NULL) != (b->color==NULL)) + return false; + if ((a->secondary==NULL) != (b->secondary==NULL)) + return false; + if ((a->fogcoord==NULL) != (b->fogcoord==NULL)) + return false; + // check the textures + if(a->maxtex!=b->maxtex) + return false; + for (int i=0; imaxtex; i++) + if ((a->tex[i]==NULL) != (b->tex[i]==NULL)) + return false; + if ((a->set_texture==b->set_texture) && ((a->texture != b->texture) || (a->target_texture != b->target_texture))) + return false; + if (!a->set_texture && b->set_texture) + return false; + // post color is only important if b as no color pointer... + if(a->post_color && b->color==NULL) + return false; + // same for post_normal + if(a->post_normal && b->normal==NULL) + return false; + // check instanceCount (maybe it would be better to just check if both are == 1) + if(a->instanceCount != b->instanceCount) + return false; + + // Check the size of a list, if it"s too big, don't merge... + if ((a->len+b->len)>30000) + return false; + if ((a->ilen+b->ilen)>30000) + return false; + + return true; +} + +void renderlist_createindices(renderlist_t *a, GLushort *indices, int count) { + int ilen = a->len; + for (int i = 0; iindices; + int len = (ind)? a->ilen:a->len; + int ilen = len*2; // new size is 2* + return + + if(len>1) { + int k=0; + indices[k++] = vind(0); + indices[k++] = vind(1); + for (int i = 2; iindices; + int len = (ind)? a->ilen:a->len; + int ilen = len*2-2; // new size is 2* + if (ilen<1) ilen=0; + if(len>1) { + int k=0; + indices[k++] = vind(0); + indices[k++] = vind(1); + for (int i = 2; iindices; + int len = (ind)? a->ilen:a->len; + int ilen = (len-2)*3; + if (ilen<0) ilen=0; + for (int i = 2; iindices; + int len = (ind)? a->ilen:a->len; + int ilen = (len-2)*3; + if (ilen<0) ilen=0; + for (int i = 2; iindices; + int len = (ind)? a->ilen:a->len; + // len must be a multiple of 4 ! + len &= ~3; // discard extra vertex... + int ilen = len*3/2; + for (int i=0, j=0; i+3indices; + int len = (ind)? a->ilen:a->len; + // len must be a multiple of 4 ! + len &= ~3; // discard extra vertex... + int ilen = len*3/2; + if(a->use_glstate) { + if(ind) {//need to copy first... + ind = (GLushort*)malloc(len*sizeof(GLushort)); + memcpy(ind, glstate->merger_indices, len*sizeof(GLushort)); + a->shared_indices = NULL; // should not be needed + } + resize_merger_indices(ilen); + a->indices = glstate->merger_indices; + } else + a->indices = (GLushort*)malloc(ilen*sizeof(GLushort)); + + for (int i=0, j=0; i+3indices[j+0] = vind(i+0); + a->indices[j+1] = vind(i+1); + a->indices[j+2] = vind(i+2); + + a->indices[j+3] = vind(i+0); + a->indices[j+4] = vind(i+2); + a->indices[j+5] = vind(i+3); + } + a->ilen = ilen; + if (ind) { + if (!a->shared_indices || ((*a->shared_indices)--)==0) { + free(ind); + free(a->shared_indices); + } + a->shared_indices = NULL; // unshared list + } + a->mode = GL_TRIANGLES; +} +#undef vind + +int indices_getindicesize(GLenum mode, int len) { + int ilen_a; + switch (mode) { + case GL_LINE_LOOP: + ilen_a = len*2; + if (ilen_a<0) ilen_a=1; // special borked case... + break; + case GL_LINE_STRIP: + ilen_a = (len*2)-2; + if (ilen_a<0) ilen_a=1; // special borked case... + break; + case GL_QUAD_STRIP: + case GL_TRIANGLE_STRIP: + case GL_TRIANGLE_FAN: + case GL_POLYGON: + ilen_a = (len-2)*3; + if (ilen_a<0) ilen_a=1; // special borked case... + break; + case GL_QUADS: + ilen_a = ((len&~3)*3)/2; + break; + default: + ilen_a = len; + break; + } + return ilen_a; +} +int renderlist_getindicesize(renderlist_t *a) { + int ilen_a = indices_getindicesize(a->mode, ((a->indices)? a->ilen:a->len)); + return ilen_a; +} +int mode_needindices(GLenum m) { + switch(m) { + case GL_LINE_LOOP: + case GL_LINE_STRIP: + case GL_TRIANGLE_FAN: + case GL_TRIANGLE_STRIP: + case GL_QUAD_STRIP: + case GL_POLYGON: + //case GL_QUADS: // not needed, but will appens anyway + return 1; + default: + return 0; + } +} + +void list_add_modeinit(renderlist_t* list, GLenum mode) { + if (list->mode_init_len+1 >= list->mode_init_cap) { + list->mode_init_cap+=128; + list->mode_inits = (modeinit_t*)realloc(list->mode_inits, list->mode_init_cap*sizeof(modeinit_t)); + } + list->mode_inits[list->mode_init_len].mode_init = mode; + list->mode_inits[list->mode_init_len++].ilen = list->indices?list->ilen:(list->cur_istart?list->cur_istart:list->len); +} + +void append_renderlist(renderlist_t *a, renderlist_t *b) { + // append all draw elements of b in a + // check the final indice size of a and b + int ilen_a = a->ilen; + int ilen_b = b->ilen; + // lets append all the arrays + unsigned long cap = a->cap; + if (a->len + b->len >= cap) cap += b->cap + DEFAULT_RENDER_LIST_CAPACITY; + if (a->shared_arrays && ((*a->shared_arrays)--)>0) { + // Unshare if shared (shared array are not used for now) + a->cap = cap; + GLfloat *tmp; + tmp = a->vert; + if (tmp) { + a->vert = alloc_sublist(4, cap); + memcpy(a->vert, tmp, 4*a->len*sizeof(GLfloat)); + } + tmp = a->normal; + if (tmp) { + a->normal = alloc_sublist(3, cap); + memcpy(a->normal, tmp, 3*a->len*sizeof(GLfloat)); + } + tmp = a->color; + if (tmp) { + a->color = alloc_sublist(4, cap); + memcpy(a->color, tmp, 4*a->len*sizeof(GLfloat)); + } + tmp = a->secondary; + if (tmp) { + a->secondary = alloc_sublist(4, cap); + memcpy(a->secondary, tmp, 4*a->len*sizeof(GLfloat)); + } + tmp = a->fogcoord; + if (tmp) { + a->fogcoord = alloc_sublist(1, cap); + memcpy(a->fogcoord, tmp, 1*a->len*sizeof(GLfloat)); + } + for (int i=0; imaxtex; i++) { + tmp = a->tex[i]; + if (tmp) { + a->tex[i] = alloc_sublist(4, cap); + memcpy(a->tex[i], tmp, 4*a->len*sizeof(GLfloat)); + } + } + } else { + if (a->cap < cap) { + a->cap = cap; + realloc_sublist(a->vert, 4, cap); + realloc_sublist(a->normal, 3, cap); + realloc_sublist(a->color, 4, cap); + realloc_sublist(a->secondary, 4, cap); + realloc_sublist(a->fogcoord, 1, cap); + for (int i=0; imaxtex; i++) + realloc_sublist(a->tex[i], 4, cap); + } + } + if(a->shared_arrays && *a->shared_arrays==0) {free(a->shared_arrays); a->shared_arrays=0;} + if (a->shared_indices && ((*a->shared_indices)--)>0) { + if (a->indices) { + GLushort* tmpi = a->indices; + a->indice_cap = ((ilen_a)?ilen_a:a->len) + ((ilen_b)?ilen_b:b->len); + if (a->indice_cap > 48) a->indice_cap = ((a->indice_cap+512)>>9)<<9; + a->indices = (GLushort*)malloc(a->indice_cap*sizeof(GLushort)); + memcpy(a->indices, tmpi, a->ilen*sizeof(GLushort)); + } + } + if(a->shared_indices && *a->shared_indices==0) {free(a->shared_indices); a->shared_indices=0;} + // append arrays + if (a->vert) memcpy(a->vert+a->len*4, b->vert, b->len*4*sizeof(GLfloat)); + if (a->normal) memcpy(a->normal+a->len*3, b->normal, b->len*3*sizeof(GLfloat)); + if (a->color) memcpy(a->color+a->len*4, b->color, b->len*4*sizeof(GLfloat)); + if (a->secondary) memcpy(a->secondary+a->len*4, b->secondary, b->len*4*sizeof(GLfloat)); + if (a->fogcoord) memcpy(a->fogcoord+a->len*1, b->fogcoord, b->len*1*sizeof(GLfloat)); + for (int i=0; imaxtex; i++) + if (a->tex[i]) memcpy(a->tex[i]+a->len*4, b->tex[i], b->len*4*sizeof(GLfloat)); + // indices + if(!a->mode_inits) list_add_modeinit(a, a->mode_init); + if (ilen_a || ilen_b || mode_needindices(a->mode) || mode_needindices(b->mode) + || (a->mode!=b->mode && (a->mode==GL_QUADS || b->mode==GL_QUADS)) ) + { + // alloc or realloc a->indices first... + int capindices = renderlist_getindicesize(a)+renderlist_getindicesize(b); + if (capindices > 48) capindices = ((capindices+512)>>9)<<9; + #define alloc_a_indices \ + newind=(GLushort*)malloc(capindices*sizeof(GLushort)) + #define copy_a_indices \ + if (a->indices) free(a->indices); \ + a->indices = newind; \ + a->indice_cap = capindices + // check if "a" needs to be converted + ilen_a = renderlist_getindicesize(a); + GLushort *newind=NULL; + switch (a->mode) { + case GL_LINE_LOOP: + alloc_a_indices; + renderlist_lineloop_lines(a, newind, 0); + a->mode = GL_LINES; + copy_a_indices; + break; + case GL_LINE_STRIP: + alloc_a_indices; + renderlist_linestrip_lines(a, newind, 0); + a->mode = GL_LINES; + copy_a_indices; + break; + case GL_QUAD_STRIP: + case GL_TRIANGLE_STRIP: + alloc_a_indices; + renderlist_trianglestrip_triangles(a, newind, 0); + a->mode = GL_TRIANGLES; + copy_a_indices; + break; + case GL_TRIANGLE_FAN: + case GL_POLYGON: + alloc_a_indices; + renderlist_trianglefan_triangles(a, newind, 0); + a->mode = GL_TRIANGLES; + copy_a_indices; + break; + case GL_QUADS: + alloc_a_indices; + renderlist_quads_triangles(a, newind, 0); + a->mode = GL_TRIANGLES; + copy_a_indices; + break; + default: + if (!a->indices) { + // no a->indices, must alloc and fill one + alloc_a_indices; + renderlist_createindices(a, newind, 0); + copy_a_indices; + } else { + // a->indices already exist, just check if need to adjust its size + if (a->indice_cap < capindices) { + a->indices = (GLushort*)realloc(a->indices, capindices*sizeof(GLushort)); + a->indice_cap = capindices; + } + } + break; + } + #undef copy_a_indices + #undef alloc_a_indices + + a->ilen = ilen_a; + // then append b + ilen_b = renderlist_getindicesize(b); + switch (b->mode) { + case GL_LINE_LOOP: + renderlist_lineloop_lines(b, a->indices + ilen_a, a->len); + break; + case GL_LINE_STRIP: + renderlist_linestrip_lines(b, a->indices + ilen_a, a->len); + break; + case GL_QUAD_STRIP: + case GL_TRIANGLE_STRIP: + renderlist_trianglestrip_triangles(b, a->indices + ilen_a, a->len); + break; + case GL_POLYGON: + case GL_TRIANGLE_FAN: + renderlist_trianglefan_triangles(b, a->indices + ilen_a, a->len); + break; + case GL_QUADS: + renderlist_quads_triangles(b, a->indices + ilen_a, a->len); + break; + default: + // no transform here, just take (or create) the indice list as-is + if (!b->ilen) { + // append a newly created indice list + renderlist_createindices(b, a->indices + ilen_a, a->len); + } else { + // append existing one + newind = a->indices+ilen_a; + for(int i=0; iilen; i++) + newind[i] = b->indices[i]+a->len; + } + break; + } + a->ilen += ilen_b; + } + // lenghts + a->len += b->len; + if(a->mode_inits) list_add_modeinit(a, b->mode); + // copy the lastColors if needed + if(b->lastColorsSet) { + a->lastColorsSet = 1; + memcpy(a->lastColors, b->lastColors, 4*sizeof(GLfloat)); + } + if(b->post_color) { + a->post_color = 1; + memcpy(a->post_colors, b->post_colors, 4*sizeof(GLfloat)); + } + if(b->post_normal) { + a->post_normal = 1; + memcpy(a->post_normals, b->post_normals, 3*sizeof(GLfloat)); + } + //all done + a->stage = STAGE_DRAW; // just in case + return; +} +void adjust_renderlist(renderlist_t *list); + +renderlist_t *extend_renderlist(renderlist_t *list) { + if ((list->prev!=NULL) && ispurerender_renderlist(list) && islistscompatible_renderlist(list->prev, list)) { + // append list! + append_renderlist(list->prev, list); + renderlist_t *new = alloc_renderlist(); + new->prev = list->prev; + list->prev->next = new; + // just in case + memcpy(new->lastNormal, list->lastNormal, 3*sizeof(GLfloat)); + memcpy(new->lastSecondaryColors, list->lastSecondaryColors, 3*sizeof(GLfloat)); + memcpy(new->lastColors, list->lastColors, 4*sizeof(GLfloat)); + new->lastColorsSet = list->lastColorsSet; + // detach + list->prev = NULL; + // free list now + free_renderlist(list); + return new; + } else { + renderlist_t *new = alloc_renderlist(); + list->next = new; + new->prev = list; + new->tmu = list->tmu; + // copy local state + memcpy(new->lastNormal, list->lastNormal, 3*sizeof(GLfloat)); + memcpy(new->lastSecondaryColors, list->lastSecondaryColors, 3*sizeof(GLfloat)); + memcpy(new->lastColors, (list->post_color)?list->post_colors:list->lastColors, 4*sizeof(GLfloat)); + new->lastColorsSet = (list->post_color || list->lastColorsSet)?1:0; + return new; + } +} + +renderlist_t* append_calllist(renderlist_t *list, renderlist_t *a) +{ + // go to end of list + while(list->next) list = list->next; + while(a) { + if(ispurerender_renderlist(a) && islistscompatible_renderlist(list, a)) { + // append list! + append_renderlist(list, a); + } else { + // create a new appended list + renderlist_t *new = alloc_renderlist(); + // prepared shared stuff... + if(a->len && !a->shared_arrays) { + a->shared_arrays = (int*)malloc(sizeof(int)); + *a->shared_arrays = 0; + } + if(a->ilen && !a->shared_indices) { + a->shared_indices = (int*)malloc(sizeof(int)); + *a->shared_indices = 0; + } + if(a->calls.len && !a->shared_calls) { + a->shared_calls = (int*)malloc(sizeof(int)); + *a->shared_calls = 0; + } + // batch copy first + memcpy(new, a, sizeof(renderlist_t)); + list->next = new; + new->prev = list; + // ok, now on new list + list = new; + // copy the many list arrays + if (list->calls.len > 0) { + ++(*list->shared_calls); + /* + list->calls.calls = (packed_call_t**)malloc(sizeof(packed_call_t*)*a->calls.cap); + for (int i = 0; i < list->calls.len; i++) { + list->calls.calls[i] = glCopyPackedCall(a->calls.calls[i]); + }*/ + } + if(list->len) { + ++(*list->shared_arrays); + } + if(list->ilen) { + ++(*list->shared_indices); + } + #define PROCESS(W, T, C) if(list->W) { \ + list->W = kh_init(W); \ + T *m, *m2; \ + khint_t k; \ + int ret; \ + kh_foreach_value(a->W, m, \ + k = kh_put(W, list->W, C, &ret); \ + m2= kh_value(list->W, k) = malloc(sizeof(T)); \ + memcpy(m2, m, sizeof(T)); \ + ); \ + } + PROCESS(material, rendermaterial_t, m->pname); + PROCESS(light, renderlight_t, m->pname | ((m->which-GL_LIGHT0)<<16)); + PROCESS(texgen, rendertexgen_t, m->pname | ((m->coord-GL_S)<<16)); + PROCESS(texenv, rendertexenv_t, m->pname | ((m->target)<<16)); + #undef PROCESS + if (list->lightmodel) { + list->lightmodel = (GLfloat*)malloc(4*sizeof(GLfloat)); + memcpy(list->lightmodel, a->lightmodel, 4*sizeof(GLfloat)); + } + if (list->raster) { + (*list->raster->shared)++; + } + if (list->bitmaps) { + (*list->bitmaps->shared)++; + } + } + a = a->next; + } + return list; +} + +void free_renderlist(renderlist_t *list) { + // test if list is NULL + if (list == NULL) + return; + // we want the first list in the chain + while (list->prev) + list = list->prev; + + renderlist_t *next; + do { + if(list->mode_inits) + free(list->mode_inits); + if ((list->calls.len > 0) && (!list->shared_calls || ((*list->shared_calls)--)==0)) { + if(list->shared_calls) free(list->shared_calls); + for (int i = 0; i < list->calls.len; i++) { + free(list->calls.calls[i]); + } + free(list->calls.calls); + } + int a; + if(!list->use_glstate) { + if (!list->shared_arrays || ((*list->shared_arrays)--)==0) { + if (list->shared_arrays) free(list->shared_arrays); + if (list->vert) free(list->vert); + if (list->normal) free(list->normal); + if (list->color) free(list->color); + if (list->secondary) free(list->secondary); + if (list->fogcoord) free(list->fogcoord); + for (a=0; amaxtex; a++) + if (list->tex[a]) free(list->tex[a]); + } + if (!list->shared_indices || ((*list->shared_indices)--)==0) { + if (list->shared_indices) free(list->shared_indices); + if (list->indices) + free(list->indices); + } + } else + glstate->merger_used = 0; + + if (list->material) { + rendermaterial_t *m; + kh_foreach_value(list->material, m, + free(m); + ) + kh_destroy(material, list->material); + } + if (list->light) { + renderlight_t *m; + kh_foreach_value(list->light, m, + free(m); + ) + kh_destroy(light, list->light); + } + if (list->texgen) { + rendertexgen_t *m; + kh_foreach_value(list->texgen, m, + free(m); + ) + kh_destroy(texgen, list->texgen); + } + if (list->texenv) { + rendertexenv_t *m; + kh_foreach_value(list->texenv, m, + free(m); + ) + kh_destroy(texenv, list->texenv); + } + if (list->lightmodel) + free(list->lightmodel); + + if (list->raster && !((*list->raster->shared)--)) { + if (list->raster->texture) + gl4es_glDeleteTextures(1, &list->raster->texture); + free(list->raster->shared); + free(list->raster); + } + + if(list->bitmaps && !((*list->bitmaps->shared)--)) { + for(int i=0; ibitmaps->count; i++) + if(list->bitmaps->list[i].bitmap) + free(list->bitmaps->list[i].bitmap); + free(list->bitmaps->list); + free(list->bitmaps->shared); + free(list->bitmaps); + } + + if(list->ind_lines) + free(list->ind_lines); + if(list->final_colors) + free(list->final_colors); + + next = list->next; + free(list); + } while ((list = next)); +} + +void resize_renderlist(renderlist_t *list) { + if (list->use_glstate) { + if (list->len >= glstate->merger_cap) { + glstate->merger_cap += DEFAULT_RENDER_LIST_CAPACITY*8; + realloc_merger_sublist(glstate->merger_master, 4*5, glstate->merger_cap); + realloc_sublist(glstate->merger_secondary, 4, glstate->merger_cap); + for (int a=2; amaxtex; a++) + realloc_sublist(glstate->merger_tex[a-2], 4, glstate->merger_cap); + if(list->vert) list->vert = glstate->merger_master; + if(list->normal) list->normal = glstate->merger_master+4+4+2*4; + if(list->color) list->color = glstate->merger_master+4; + if(list->tex[0]) list->tex[0] = glstate->merger_master+4+4; + if(list->tex[1]) list->tex[1] = glstate->merger_master+4+4+4; + if(list->fogcoord) list->fogcoord = glstate->merger_master+4+4+2*4+3; + if(list->secondary) list->secondary = glstate->merger_secondary; + for (int a=2; amaxtex; a++) + if(list->tex[a]) list->tex[a] = glstate->merger_tex[a-2]; + } + } else { + if (list->len >= list->cap) { + list->cap += DEFAULT_RENDER_LIST_CAPACITY*8; + realloc_sublist(list->vert, 4, list->cap); + realloc_sublist(list->normal, 3, list->cap); + realloc_sublist(list->color, 4, list->cap); + realloc_sublist(list->secondary, 4, list->cap); + realloc_sublist(list->fogcoord, 1, list->cap); + for (int a=0; amaxtex; a++) + realloc_sublist(list->tex[a], 4, list->cap); + } + } +} + +void resize_merger_indices(int cap) { + if(capmerger_indice_cap) + return; + glstate->merger_indice_cap = ((glstate->merger_indice_cap+cap+512)>>9)<<9; + glstate->merger_indices = (GLushort*)realloc(glstate->merger_indices, glstate->merger_indice_cap*sizeof(GLushort)); +} + +void resize_indices_renderlist(renderlist_t *list, int n) { + if (!list->indices || list->shared_indices) + return; + if (list->use_glstate) { + resize_merger_indices(list->ilen+n); + list->indices = glstate->merger_indices; + } else { + if(list->ilen+nindice_cap) + return; + list->indice_cap = ((list->indice_cap+n+511)>>9)<<9; + list->indices = (GLushort*)realloc(list->indices, list->indice_cap*sizeof(GLushort)); + } +} + +void adjust_renderlist(renderlist_t *list) { + if (! list->open) + return; + + list->stage = STAGE_LAST; + list->open = false; + if(hardext.esversion==1) // no more adjustment needed for ES2 + for (int a=0; amaxtex; a++) { + const GLint itarget = get_target(glstate->enable.texture[a]); + gltexture_t *bound = (itarget>=0)?glstate->texture.bound[a][itarget]:NULL; + // in case of Texture bounding inside a list + if (list->set_texture && (list->tmu == a)) + bound = gl4es_getTexture(list->target_texture, list->texture); + // GL_ARB_texture_rectangle + if ((list->tex[a]) && (itarget == ENABLED_TEXTURE_RECTANGLE) && (bound)) { + tex_coord_rect_arb(list->tex[a], list->tex_stride[a]>>2, list->len, bound->width, bound->height); + } + } +} + +renderlist_t* end_renderlist(renderlist_t *list) { + if (!list || ! list->open) + return list; + + adjust_renderlist(list); + + switch (list->mode) { + case GL_QUADS: + if (((list->indices) && (list->ilen==4)) || ((list->indices==NULL) && (list->len==4))) { + list->mode = GL_TRIANGLE_FAN; + } else { + renderlist_quads2triangles(list); + } + break; + case GL_POLYGON: + list->mode = GL_TRIANGLE_FAN; + break; + case GL_QUAD_STRIP: + list->mode = GL_TRIANGLE_STRIP; + break; + } + if(list->prev && isempty_renderlist(list)) { + renderlist_t *p = list; + list = list->prev; + list->next = NULL; + p->prev = NULL; + free_renderlist(p); + } + + return list; +} + +renderlist_t* recycle_renderlist(renderlist_t *list, GLenum mode) { + if(isempty_renderlist(list) || (ispurerender_renderlist(list) && list->len==0)) { + list->mode_init = mode; + list->mode = mode; + list->stage=STAGE_DRAW; + if (list->post_color) { + list->post_color = 0; + rlColor4f(list, list->post_colors[0], list->post_colors[1], list->post_colors[2], list->post_colors[3]); + } + if (list->post_normal) { + list->post_normal = 0; + rlNormal3f(list, list->post_normals[0], list->post_normals[1], list->post_normals[2]); + } + return list; // recycling... + } + // check if pending color... + if (list->post_color) { + list->post_color = 0; + rlColor4f(list, list->post_colors[0], list->post_colors[1], list->post_colors[2], list->post_colors[3]); + } + if (list->post_normal) { + list->post_normal = 0; + rlNormal3f(list, list->post_normals[0], list->post_normals[1], list->post_normals[2]); + } + // check if list needs to be converted to triangles / lines... + GLushort *indices = NULL; +#define pre_expand \ + if(list->use_glstate) {\ + resize_merger_indices(renderlist_getindicesize(list)); indices = glstate->merger_indices;\ + } else {\ + list->indice_cap = renderlist_getindicesize(list);\ + indices = (GLushort*)malloc(sizeof(GLushort)*list->indice_cap);\ + } +#define post_expand \ + list->ilen = renderlist_getindicesize(list);\ + list->indices = indices + + list->merger_mode = mode; + switch(list->mode) { + case GL_LINES: + if(mode!=GL_LINES && !list->indices) { + pre_expand; + renderlist_createindices(list, indices, 0); + post_expand; + } + break; + case GL_LINE_LOOP: + pre_expand; + renderlist_lineloop_lines(list, indices, 0); + post_expand; + list->mode=GL_LINES; + break; + case GL_LINE_STRIP: + pre_expand; + renderlist_linestrip_lines(list, indices, 0); + post_expand; + list->mode=GL_LINES; + break; + case GL_TRIANGLES: + if(mode!=GL_TRIANGLES && !list->indices) { + pre_expand; + renderlist_createindices(list, indices, 0); + post_expand; + } + break; + case GL_POLYGON: + case GL_TRIANGLE_FAN: + pre_expand; + renderlist_trianglefan_triangles(list, indices, 0); + post_expand; + list->mode=GL_TRIANGLES; + break; + case GL_QUAD_STRIP: + case GL_TRIANGLE_STRIP: + pre_expand; + renderlist_trianglestrip_triangles(list, indices, 0); + post_expand; + list->mode=GL_TRIANGLES; + break; + case GL_QUADS: + pre_expand; + renderlist_quads_triangles(list, indices, 0); + post_expand; + list->mode=GL_TRIANGLES; + break; + } +#undef pre_expand +#undef post_expand + list->cur_istart = list->len; + // All done + list->stage=STAGE_DRAW; + + return list; +} diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/list.h b/Projects/Android/jni/SupportLibs/gl4es/src/gl/list.h new file mode 100644 index 0000000..f11208c --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/list.h @@ -0,0 +1,299 @@ +#ifndef _GL4ES_LIST_H_ +#define _GL4ES_LIST_H_ + +#include +#include "khash.h" +#include "../config.h" +#include "wrap/gles.h" +#include "attributes.h" +#include "gles.h" + +typedef enum { + STAGE_NONE = 0, + STAGE_PUSH, + STAGE_POP, + STAGE_GLCALL, + STAGE_RENDER, + STAGE_FOG, + STAGE_POINTPARAM, + STAGE_MATRIX, + STAGE_ACTIVETEX, + STAGE_BINDTEX, + STAGE_RASTER, + STAGE_BITMAP, + STAGE_MATERIAL, + STAGE_COLOR_MATERIAL, + STAGE_LIGHT, + STAGE_LIGHTMODEL, + STAGE_LINESTIPPLE, + STAGE_TEXENV, + STAGE_TEXGEN, + STAGE_POLYGON, + STAGE_DRAW, + STAGE_POSTDRAW, + STAGE_LAST +} liststage_t; + +static int StageExclusive[] = { + 0, // STAGE_NONE + 1, // STAGE_PUSH + 1, // STAGE_POP + 0, // STAGE_GLCALL + 1, // STAGE_RENDER + 1, // STAGE_FOG + 1, // STAGE_POINTPARAM + 1, // STAGE_MATRIX + 1, // STAGE_ACTIVETEX + 1, // STAGE_BINDTEX + 1, // STAGE_RASTER + 0, // STAGE_BITMAP + 0, // STAGE_MATERIAL + 1, // STAGE_COLOR_MATERIAL + 0, // STAGE_LIGHT + 1, // STAGE_LIGTMODEL + 1, // STAGE_LINESTIPPLE + 0, // STAGE_TEXENV + 0, // STAGE_TEXGEN + 1, // STAGE_POLYGON + 1, // STAGE_DRAW + 1, // STAGE_POSTDRAW (used for "pending", i.e. post glEnd(), in case a similar glBegin occurs) + 0 // STAGE_LAST +}; + +typedef struct { + int face; + int pname; + GLfloat color[4]; + int count; +} rendermaterial_t; + +typedef struct { + int which; + int pname; + GLfloat color[4]; + int count; +} renderlight_t; + +typedef struct { + int coord; + int pname; + GLfloat color[4]; + int count; +} rendertexgen_t; + +typedef struct { + int target; + int pname; + GLfloat params[4]; + int count; +} rendertexenv_t; + +typedef struct { + GLfloat xmove; + GLfloat ymove; + GLsizei width; + GLsizei height; + GLsizei nwidth; + GLsizei nheight; + GLfloat xorig; + GLfloat yorig; + GLfloat zoomx; + GLfloat zoomy; + GLboolean bitmap; + GLuint texture; + int *shared; +} rasterlist_t; + +KHASH_MAP_DECLARE_INT(material, rendermaterial_t *); +KHASH_MAP_DECLARE_INT(light, renderlight_t *); +KHASH_MAP_DECLARE_INT(texgen, rendertexgen_t *); +KHASH_MAP_DECLARE_INT(texenv, rendertexenv_t *); + +typedef struct _call_list_t { + unsigned long len; + unsigned long cap; + packed_call_t **calls; +} call_list_t; + +typedef struct { + GLsizei width; + GLsizei height; + GLfloat xorig; + GLfloat yorig; + GLfloat xmove; + GLfloat ymove; + GLubyte *bitmap; +} bitmap_list_t; + +typedef struct { + int count; + int cap; + bitmap_list_t *list; + int *shared; +} bitmaps_t; + +typedef struct { + GLenum mode_init; + int ilen; +} modeinit_t; + +typedef struct _renderlist_t { + unsigned long len; + unsigned long ilen; + unsigned long cap; + GLenum mode; + GLenum mode_init; // initial requested mode + modeinit_t* mode_inits; // array of requested/len, for the merger + int mode_init_cap; + int mode_init_len; + int mode_dimension; + GLfloat lastNormal[3]; + GLfloat lastColors[4]; + GLfloat lastSecondaryColors[4]; + GLfloat lastFogCoord; + int use_glstate; + + int lastColorsSet; + + int* shared_calls; + call_list_t calls; + + int *shared_arrays; + GLfloat *vert; + GLfloat *normal; + GLfloat *color; + GLfloat *secondary; + GLfloat *fogcoord; + GLfloat *tex[MAX_TEX]; + int vert_stride; + int normal_stride; + int color_stride; + int secondary_stride; + int fogcoord_stride; + int tex_stride[MAX_TEX]; + int *shared_indices; + GLushort *indices; + unsigned int indice_cap; + int maxtex; + GLenum merger_mode; + int cur_istart; // used by glBegin/glEnd merger. + + rasterlist_t *raster; + + bitmaps_t *bitmaps; + + liststage_t stage; + + GLbitfield pushattribute; + GLboolean popattribute; + + int render_op; + GLuint render_arg; + + int raster_op; + GLfloat raster_xyz[3]; + + int matrix_op; + GLfloat matrix_val[16]; + + int fog_op; + GLfloat fog_val[4]; + + int pointparam_op; + GLfloat pointparam_val[4]; + + int linestipple_op; + GLuint linestipple_factor, linestipple_pattern; + + int post_color; + GLfloat post_colors[4]; + int post_normal; + GLfloat post_normals[3]; + + GLushort *ind_lines; + int ind_line; + GLfloat *final_colors; + + int instanceCount; + + khash_t(material) *material; + GLenum colormat_face; + GLenum colormat_mode; + khash_t(light) *light; + khash_t(texgen) *texgen; + khash_t(texenv) *texenv; + GLfloat *lightmodel; + GLenum lightmodelparam; + GLenum polygon_mode; + GLboolean set_tmu; // TRUE is glActiveTexture called + int tmu; // the current TMU... + GLuint texture; + GLenum target_texture; + GLboolean set_texture; + struct _renderlist_t *prev; + struct _renderlist_t *next; + GLboolean open; +} renderlist_t; + +KHASH_MAP_DECLARE_INT(gllisthead, renderlist_t*); + +#define DEFAULT_CALL_LIST_CAPACITY 20 +#define DEFAULT_RENDER_LIST_CAPACITY 64 + +int rendermode_dimensions(GLenum mode); +renderlist_t* recycle_renderlist(renderlist_t* list, GLenum mode); +renderlist_t* NewDrawStage(renderlist_t* l, GLenum m); + +#define NewStage(l, s) if (l->stage+StageExclusive[l->stage] > s) {l = extend_renderlist(l);} l->stage = s + +renderlist_t* GetFirst(renderlist_t* list); + +#define alloc_sublist(n, cap) \ + (GLfloat *)malloc(n * sizeof(GLfloat) * cap) + +#define realloc_sublist(ref, n, cap) \ + if (ref) \ + ref = (GLfloat *)realloc(ref, n * sizeof(GLfloat) * cap) + +#define realloc_merger_sublist(ref, n, cap) \ + ref = (GLfloat *)realloc(ref, n * sizeof(GLfloat) * cap) + +renderlist_t *alloc_renderlist(); +renderlist_t *extend_renderlist(renderlist_t *list); +void free_renderlist(renderlist_t *list); +void draw_renderlist(renderlist_t *list); +renderlist_t* end_renderlist(renderlist_t *list); +bool isempty_renderlist(renderlist_t *list); +void resize_renderlist(renderlist_t *list); +renderlist_t *alloc_renderlist(); +void resize_indices_renderlist(renderlist_t *list, int n); +void resize_merger_indices(int cap); +int indices_getindicesize(GLenum mode, int len); +void list_add_modeinit(renderlist_t* list, GLenum mode); + +void rlActiveTexture(renderlist_t *list, GLenum texture ); +void rlBindTexture(renderlist_t *list, GLenum target, GLuint texture); +void rlColor4f(renderlist_t *list, GLfloat r, GLfloat g, GLfloat b, GLfloat a) FASTMATH; +void rlColor4fv(renderlist_t *list, GLfloat* v) FASTMATH; +void rlMaterialfv(renderlist_t *list, GLenum face, GLenum pname, const GLfloat * params); +void rlLightfv(renderlist_t *list, GLenum which, GLenum pname, const GLfloat * params); +void rlTexGenfv(renderlist_t *list, GLenum coord, GLenum pname, const GLfloat * params); +void rlTexEnvfv(renderlist_t *list, GLenum target, GLenum pname, const GLfloat * params); +void rlTexEnviv(renderlist_t *list, GLenum target, GLenum pname, const GLint * params); +void rlNormal3f(renderlist_t *list, GLfloat x, GLfloat y, GLfloat z) FASTMATH; +void rlNormal3fv(renderlist_t *list, GLfloat* v) FASTMATH; +void rlPushCall(renderlist_t *list, packed_call_t *data); +void rlMultiTexCoord4f(renderlist_t *list, GLenum texture, GLfloat s, GLfloat t, GLfloat r, GLfloat q) FASTMATH; +void rlMultiTexCoord2fv(renderlist_t *list, GLenum texture, GLfloat* v) FASTMATH; +void rlMultiTexCoord4fv(renderlist_t *list, GLenum texture, GLfloat* v) FASTMATH; +void rlVertex4f(renderlist_t *list, GLfloat x, GLfloat y, GLfloat z, GLfloat w) FASTMATH; +void rlVertex3fv(renderlist_t *list, GLfloat* v) FASTMATH; +void rlVertex4fv(renderlist_t *list, GLfloat* v) FASTMATH; +void rlSecondary3f(renderlist_t *list, GLfloat r, GLfloat g, GLfloat b) FASTMATH; +void rlRasterOp(renderlist_t *list, int op, GLfloat x, GLfloat y, GLfloat z) FASTMATH; +void rlFogOp(renderlist_t *list, int op, const GLfloat* v); +void rlPointParamOp(renderlist_t *list, int op, const GLfloat* v); +void rlFogCoordf(renderlist_t *list, GLfloat coord); +void rlEnd(renderlist_t *list); + +#endif // _GL4ES_LIST_H_ diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/listdraw.c b/Projects/Android/jni/SupportLibs/gl4es/src/gl/listdraw.c new file mode 100644 index 0000000..f3a4159 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/listdraw.c @@ -0,0 +1,621 @@ +#include "list.h" + +#include "../glx/hardext.h" +#include "wrap/gl4es.h" +#include "fpe.h" +#include "init.h" +#include "line.h" +#include "loader.h" +#include "matrix.h" +#include "texgen.h" +#include "render.h" + +int fill_lineIndices(modeinit_t *modes, int length, GLenum mode, GLushort* indices, GLushort *ind_line) +{ + #define ind(a) indices?indices[a]:(a) + int k=0; + int i=0; + for (int m=0; m2) { + ind_line[k++] = ind(i+0); ind_line[k++] = ind(i+1); + i+=2; + for (; i3) { + ind_line[k++] = ind(i+0); ind_line[k++] = ind(i+1); + i+=2; + for (; i2) { + int z = i; + ind_line[k++] = ind(i+0); ind_line[k++] = ind(i+1); + i+=2; + for (; i2) { + // 1 triangle -> 3 lines => 6 half-lines ! + for (; i3) { + // 4 lines per quads, but dest may already be a triangles list... + if (len==4) { + // just 1 Quad + for (; i<4; i++) { + ind_line[k++] = ind(i+0); ind_line[k++] = ind((i+1)%4); + } + } else { + // list of triangles, 2 per quads... + for (; i3) { + ind_line[k++] = ind(i+0); ind_line[k++] = ind(i+1); + i+=2; + for (; iprev) list = list->prev; + // ok, go on now, draw everything +//printf("draw_renderlist %p, size=%i, mode=%s(%s), ilen=%d, next=%p, color=%p, secondarycolor=%p fogcoord=%p\n", list, list->len, PrintEnum(list->mode), PrintEnum(list->mode_init), list->ilen, list->next, list->color, list->secondary, list->fogcoord); + LOAD_GLES_FPE(glDrawArrays); + LOAD_GLES_FPE(glDrawElements); + LOAD_GLES_FPE(glVertexPointer); + LOAD_GLES_FPE(glNormalPointer); + LOAD_GLES_FPE(glColorPointer); + LOAD_GLES_FPE(glTexCoordPointer); + LOAD_GLES_FPE(glEnable); + LOAD_GLES_FPE(glDisable); + LOAD_GLES_FPE(glEnableClientState); + LOAD_GLES_FPE(glDisableClientState); + gl4es_glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT); + + int old_tex; + GLushort *indices; + static GLfloat *texgened[MAX_TEX] = {0}; + static int texgenedsz[MAX_TEX] = {0}; + int use_texgen[MAX_TEX] = {0}; + old_tex = glstate->texture.client; + GLuint cur_tex = old_tex; + GLint needclean[MAX_TEX] = {0}; + GLuint texture; + bool stipple; + int stipple_tmu; + GLenum stipple_env; + GLenum stipple_afunc; + GLfloat stipple_aref; + int stipple_tex2d; + int stipple_alpha; + int stipple_old; + int stipple_texgen[4]; + + do { + // close if needed! + if (list->open) + list = end_renderlist(list); + // push/pop attributes + if (list->pushattribute) + gl4es_glPushAttrib(list->pushattribute); + if (list->popattribute) + gl4es_glPopAttrib(); + call_list_t *cl = &list->calls; + if (cl->len > 0) { + for (int i = 0; i < cl->len; i++) { + glPackedCall(cl->calls[i]); + } + } + if(list->render_op) { + switch(list->render_op) { + case 1: gl4es_glInitNames(); break; + case 2: gl4es_glPopName(); break; + case 3: gl4es_glPushName(list->render_arg); break; + case 4: gl4es_glLoadName(list->render_arg); break; + } + } + if (list->fog_op) { + gl4es_glFogfv(GL_FOG_COLOR, list->fog_val); + } + if (list->pointparam_op) { + switch (list->pointparam_op) { + case 1: // GL_POINT_DISTANCE_ATTENUATION + gl4es_glPointParameterfv(GL_POINT_DISTANCE_ATTENUATION , list->pointparam_val); + break; + } + } + if (list->matrix_op) { + switch (list->matrix_op) { + case 1: // load + gl4es_glLoadMatrixf(list->matrix_val); + break; + case 2: // mult + gl4es_glMultMatrixf(list->matrix_val); + break; + } + } + if (list->set_tmu) { + gl4es_glActiveTexture(GL_TEXTURE0+list->tmu); + } + if (list->set_texture) { + gl4es_glBindTexture(list->target_texture, list->texture); + } + // raster + if (list->raster_op) { + if (list->raster_op==1) { + gl4es_glRasterPos3f(list->raster_xyz[0], list->raster_xyz[1], list->raster_xyz[2]); + } else if (list->raster_op==2) { + gl4es_glWindowPos3f(list->raster_xyz[0], list->raster_xyz[1], list->raster_xyz[2]); + } else if (list->raster_op==3) { + gl4es_glPixelZoom(list->raster_xyz[0], list->raster_xyz[1]); + } else if ((list->raster_op&0x10000) == 0x10000) { + gl4es_glPixelTransferf(list->raster_op&0xFFFF, list->raster_xyz[0]); + } + } + if (list->raster) { + rasterlist_t * r = list->raster; + //glBitmap(r->width, r->height, r->xorig, r->yorig, r->xmove, r->ymove, r->raster); + render_raster_list(list->raster); + } + // bitmaps + if (list->bitmaps) { + for (int i=0; ibitmaps->count; i++) { + bitmap_list_t *l = &list->bitmaps->list[i]; + gl4es_glBitmap(l->width, l->height, l->xorig, l->yorig, l->xmove, l->ymove, l->bitmap); + } + } + + if (list->material) { + khash_t(material) *map = list->material; + rendermaterial_t *m; + kh_foreach_value(map, m, + switch (m->pname) { + case GL_SHININESS: + gl4es_glMaterialf(m->face, m->pname, m->color[0]); + break; + default: + gl4es_glMaterialfv(m->face, m->pname, m->color); + } + ) + } + if (list->colormat_face) + gl4es_glColorMaterial(list->colormat_face, list->colormat_mode); + if (list->light) { + khash_t(light) *lig = list->light; + renderlight_t *m; + kh_foreach_value(lig, m, + switch (m->pname) { + default: + gl4es_glLightfv(m->which, m->pname, m->color); + } + ) + } + if (list->lightmodel) { + gl4es_glLightModelfv(list->lightmodelparam, list->lightmodel); + } + + if (list->linestipple_op) { + gl4es_glLineStipple(list->linestipple_factor, list->linestipple_pattern); + } + + if (list->texenv) { + khash_t(texenv) *tgn = list->texenv; + rendertexenv_t *m; + kh_foreach_value(tgn, m, + gl4es_glTexEnvfv(m->target, m->pname, m->params); + ) + } + + if (list->texgen) { + khash_t(texgen) *tgn = list->texgen; + rendertexgen_t *m; + kh_foreach_value(tgn, m, + gl4es_glTexGenfv(m->coord, m->pname, m->color); + ) + } + + if (list->polygon_mode) { + gl4es_glPolygonMode(GL_FRONT_AND_BACK, list->polygon_mode); + } + + if (! list->len) + continue; + + if (list->vert) { + if(!glstate->clientstate[ATT_VERTEX]) { + gles_glEnableClientState(GL_VERTEX_ARRAY); + glstate->clientstate[ATT_VERTEX] = 1; + } + gles_glVertexPointer(4, GL_FLOAT, list->vert_stride, list->vert); + } else { + if(glstate->clientstate[ATT_VERTEX]) { + gles_glDisableClientState(GL_VERTEX_ARRAY); + glstate->clientstate[ATT_VERTEX] = false; + } + } + + if (list->normal) { + if(!glstate->clientstate[ATT_NORMAL]) { + gles_glEnableClientState(GL_NORMAL_ARRAY); + glstate->clientstate[ATT_NORMAL] = 1; + } + gles_glNormalPointer(GL_FLOAT, list->normal_stride, list->normal); + } else { + if(glstate->clientstate[ATT_NORMAL]) { + gles_glDisableClientState(GL_NORMAL_ARRAY); + glstate->clientstate[ATT_NORMAL] = 0; + } + } + + indices = list->indices; + + if(glstate->raster.bm_drawing) + bitmap_flush(); + if (list->color) { + if(!glstate->clientstate[ATT_COLOR]) { + gles_glEnableClientState(GL_COLOR_ARRAY); + glstate->clientstate[ATT_COLOR] = 1; + } + if (glstate->enable.color_sum && (list->secondary) && hardext.esversion==1 && !list->use_glstate) { + if(!list->final_colors) { + list->final_colors=(GLfloat*)malloc(list->len * 4 * sizeof(GLfloat)); + if (indices) { + for (int i=0; iilen; i++) + for (int j=0; j<4; j++) { + const int k=indices[i]*4+j; + list->final_colors[k]=list->color[k] + list->secondary[k]; + } + } else { + for (int i=0; ilen*4; i++) + list->final_colors[i]=list->color[i] + list->secondary[i]; + } + } + gles_glColorPointer(4, GL_FLOAT, 0, list->final_colors); + } else { +//printf("colors=%f, %f, %f, %f / %f, %f, %f, %f\n", list->color[0],list->color[1],list->color[2],list->color[3], list->color[4],list->color[5],list->color[6],list->color[7]); + gles_glColorPointer(4, GL_FLOAT, list->color_stride, list->color); + } + } else { + if(glstate->clientstate[ATT_COLOR]) { + gles_glDisableClientState(GL_COLOR_ARRAY); + glstate->clientstate[ATT_COLOR] = 0; + } + } + if(hardext.esversion > 1) { + // secondary color only on ES2+ + if (glstate->enable.color_sum && (list->secondary)) { + if(!glstate->clientstate[ATT_SECONDARY]) { + gles_glEnableClientState(GL_SECONDARY_COLOR_ARRAY); + glstate->clientstate[ATT_SECONDARY] = 1; + } + fpe_glSecondaryColorPointer(4, GL_FLOAT, list->secondary_stride, list->secondary); + } else { + if(glstate->clientstate[ATT_SECONDARY]) { + fpe_glDisableClientState(GL_SECONDARY_COLOR_ARRAY); + glstate->clientstate[ATT_SECONDARY] = 0; + } + } + // fog coord only on ES2+ + if ((glstate->fog.coord_src==GL_FOG_COORD) && (list->fogcoord)) { + if(!glstate->clientstate[ATT_FOGCOORD]) { + gles_glEnableClientState(GL_FOG_COORD_ARRAY); + glstate->clientstate[ATT_FOGCOORD] = 1; + } + fpe_glFogCoordPointer(GL_FLOAT, list->fogcoord_stride, list->fogcoord); + } else { + if(glstate->clientstate[ATT_FOGCOORD]) { + fpe_glDisableClientState(GL_FOG_COORD_ARRAY); + glstate->clientstate[ATT_FOGCOORD] = 0; + } + } + } + #define TEXTURE(A) if (cur_tex!=A) {gl4es_glClientActiveTexture(A+GL_TEXTURE0); cur_tex=A;} + stipple = false; + if ((list->mode == GL_LINES || list->mode == GL_LINE_STRIP || list->mode == GL_LINE_LOOP) + && glstate->enable.line_stipple) { + stipple = true; + if(get_target(glstate->enable.texture[0])!=-1) + stipple_tmu = 1; + else + stipple_tmu = 0; + } + if (stipple) { + stipple_old = glstate->gleshard->active; + if(glstate->gleshard->active!=stipple_tmu) { + LOAD_GLES(glActiveTexture); + gl4es_glActiveTexture(GL_TEXTURE0+stipple_tmu); + } + TEXTURE(stipple_tmu); + GLenum matmode; + gl4es_glGetIntegerv(GL_MATRIX_MODE, &matmode); + gl4es_glMatrixMode(GL_TEXTURE); + gl4es_glPushMatrix(); + gl4es_glLoadIdentity(); + gl4es_glMatrixMode(matmode); + stipple_env = glstate->texenv[stipple_tmu].env.mode; + gl4es_glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + stipple_tex2d = gl4es_glIsEnabled(GL_TEXTURE_2D); + stipple_alpha = gl4es_glIsEnabled(GL_ALPHA_TEST); + gl4es_glEnable(GL_TEXTURE_2D); + gl4es_glEnable(GL_ALPHA_TEST); + for (int k=0; k<4; k++) { + stipple_texgen[k] = gl4es_glIsEnabled(GL_TEXTURE_GEN_S+k); + if(stipple_texgen[k]) + gl4es_glDisable(GL_TEXTURE_GEN_S+k); + } + stipple_afunc = glstate->alphafunc; + stipple_aref = glstate->alpharef; + gl4es_glAlphaFunc(GL_GREATER, 0.0f); + bind_stipple_tex(); + modeinit_t tmp; tmp.mode_init = list->mode_init; tmp.ilen=list->ilen?list->ilen:list->len; + list->tex[stipple_tmu] = gen_stipple_tex_coords(list->vert, list->indices, list->mode_inits?list->mode_inits:&tmp, list->vert_stride, list->mode_inits?list->mode_init_len:1, (list->use_glstate)?(list->vert+8+stipple_tmu*4):NULL); + } + #define RS(A, len) if(texgenedsz[A]maxtex because some TMU can be using TexGen or point sprites... + if(hardext.esversion==1) { + for (int a=0; aenable.texture[a] || (stipple && a==stipple_tmu)) { + const GLint itarget = (stipple && a==stipple_tmu)?ENABLED_TEX2D:get_target(glstate->enable.texture[a]); + needclean[a]=0; + use_texgen[a]=0; + if ((glstate->enable.texgen_s[a] || glstate->enable.texgen_t[a] || glstate->enable.texgen_r[a] || glstate->enable.texgen_q[a])) { + TEXTURE(a); + RS(a, list->len); + gen_tex_coords(list->vert, list->normal, &texgened[a], list->len, &needclean[a], a, (list->ilenlen)?indices:NULL, (list->ilenlen)?list->ilen:0); + } else if ((list->tex[a]==NULL) && !(list->mode==GL_POINT && glstate->texture.pscoordreplace[a])) { + RS(a, list->len); + gen_tex_coords(list->vert, list->normal, &texgened[a], list->len, &needclean[a], a, (list->ilenlen)?indices:NULL, (list->ilenlen)?list->ilen:0); + } + // adjust the tex_coord now if needed, even on texgened ones + gltexture_t *bound = glstate->texture.bound[a][itarget]; + if((list->tex[a] || (use_texgen[a] && !needclean[a])) && ((!(globals4es.texmat || glstate->texture_matrix[a]->identity)) || (bound->adjust))) { + if(!use_texgen[a]) { + RS(a, list->len); + if(list->tex_stride[a]) { + GLfloat *src = list->tex[a]; + GLfloat *dst = texgened[a]; + int stride = list->tex_stride[a]>>2; // stride need to be a multiple of 4 (i.e. sizeof(GLfloat)) + for (int ii=0; iilen; ii++) { + memcpy(dst, src, 4*sizeof(GLfloat)); + src+=stride; + dst+=4; + } + } else + memcpy(texgened[a], list->tex[a], 4*sizeof(GLfloat)*list->len); + } + if (!(globals4es.texmat || glstate->texture_matrix[a]->identity)) + tex_coord_matrix(texgened[a], list->len, getTexMat(a)); + if (bound->adjust) { + tex_coord_npot(texgened[a], list->len, bound->width, bound->height, bound->nwidth, bound->nheight); + } + } + } + if ((list->tex[a] || (use_texgen[a] && !needclean[a]))/* && glstate->enable.texture[a]*/) { + TEXTURE(a); + if(!glstate->clientstate[ATT_MULTITEXCOORD0+a]) { + gles_glEnableClientState(GL_TEXTURE_COORD_ARRAY); + glstate->clientstate[ATT_MULTITEXCOORD0+a] = 1; + } + gles_glTexCoordPointer(4, GL_FLOAT, (use_texgen[a])?0:list->tex_stride[a], (use_texgen[a])?texgened[a]:list->tex[a]); + } else { + if (glstate->clientstate[ATT_MULTITEXCOORD0+a]) { + TEXTURE(a); + gles_glDisableClientState(GL_TEXTURE_COORD_ARRAY); + glstate->clientstate[ATT_MULTITEXCOORD0+a] = 0; + } +//else if (!glstate->enable.texgen_s[a] && glstate->enable.texture[a]) printf("LIBGL: texture[%i] without TexCoord, mode=0x%04X (init=0x%04X), listlen=%i\n", a, list->mode, list->mode_init, list->len); + + } + if (!IS_TEX2D(glstate->enable.texture[a]) && (IS_ANYTEX(glstate->enable.texture[a]))) { + TEXTURE(a); + gl4es_glActiveTexture(GL_TEXTURE0+a); + realize_active(); + gles_glEnable(GL_TEXTURE_2D); + } + } + } else { + // texture loop for ES2+ version + for (int a=0; atex[a]) { + TEXTURE(a); + if(!glstate->clientstate[ATT_MULTITEXCOORD0+a]) { + gles_glEnableClientState(GL_TEXTURE_COORD_ARRAY); + glstate->clientstate[ATT_MULTITEXCOORD0+a] = 1; + } + gles_glTexCoordPointer(4, GL_FLOAT, list->tex_stride[a], list->tex[a]); + } else { + if (glstate->clientstate[ATT_MULTITEXCOORD0+a]) { + TEXTURE(a); + gles_glDisableClientState(GL_TEXTURE_COORD_ARRAY); + glstate->clientstate[ATT_MULTITEXCOORD0+a] = 0; + } + } + } + } + if (glstate->texture.client != old_tex) TEXTURE(old_tex); + #undef RS + #undef TEXTURE + + realize_textures(); + + GLenum mode; + mode = list->mode; + if ((glstate->polygon_mode == GL_LINE) && (mode>=GL_TRIANGLES)) + mode = GL_LINES; + if ((glstate->polygon_mode == GL_POINT) && (mode>=GL_TRIANGLES)) + mode = GL_POINTS; + + if (indices) { + if (glstate->render_mode == GL_SELECT) { + pointer_state_t vtx; + vtx.pointer = list->vert; + vtx.type = GL_FLOAT; + vtx.size = 4; + vtx.stride = 0; + select_glDrawElements(&vtx, list->mode, list->ilen, GL_UNSIGNED_SHORT, indices); + } else { + if (glstate->polygon_mode == GL_LINE && list->mode_init>=GL_TRIANGLES) { + int ilen = list->ilen; + if(!list->ind_lines) { + GLushort *ind_line = list->ind_lines = (GLushort*)malloc(sizeof(GLushort)*ilen*4+2); + modeinit_t tmp; tmp.mode_init = list->mode_init; tmp.ilen=list->ilen; + int k = fill_lineIndices(list->mode_inits?list->mode_inits:&tmp, list->mode_inits?list->mode_init_len:1, list->mode, indices, list->ind_lines); + list->ind_line = k; + } + gles_glDrawElements(mode, list->ind_line, GL_UNSIGNED_SHORT, list->ind_lines); + } else { + if(list->instanceCount==1) + gles_glDrawElements(mode, list->ilen, GL_UNSIGNED_SHORT, indices); + else { + for (glstate->instanceID=0; glstate->instanceIDinstanceCount; ++glstate->instanceID) + gles_glDrawElements(mode, list->ilen, GL_UNSIGNED_SHORT, indices); + glstate->instanceID = 0; + } + } + } + } else { + if (glstate->render_mode == GL_SELECT) { + pointer_state_t vtx; + vtx.pointer = list->vert; + vtx.type = GL_FLOAT; + vtx.size = 4; + vtx.stride = 0; + select_glDrawArrays(&vtx, list->mode, 0, list->len); + } else { + int len = list->len; + if ((glstate->polygon_mode == GL_LINE) && (list->mode_init>=GL_TRIANGLES)) { + if(!list->ind_lines) { + GLushort *ind_line = list->ind_lines = (GLushort*)malloc(sizeof(GLushort)*len*4+2); + modeinit_t tmp; tmp.mode_init = list->mode_init; tmp.ilen=len; + int k = fill_lineIndices(list->mode_inits?list->mode_inits:&tmp, list->mode_inits?list->mode_init_len:1, list->mode, NULL, list->ind_lines); + list->ind_line = k; + } + gles_glDrawElements(mode, list->ind_line, GL_UNSIGNED_SHORT, list->ind_lines); + } else { + if(list->instanceCount==1) + gles_glDrawArrays(mode, 0, len); + else { + for (glstate->instanceID=0; glstate->instanceIDinstanceCount; ++glstate->instanceID) + gles_glDrawArrays(mode, 0, len); + glstate->instanceID = 0; + } + } + } + } + + #define TEXTURE(A) if (cur_tex!=A) {gl4es_glClientActiveTexture(A+GL_TEXTURE0); cur_tex=A;} + if(hardext.esversion==1) + for (int a=0; aenable.texture[a]) && (IS_ANYTEX(glstate->enable.texture[a]))) { + TEXTURE(a); + gles_glDisable(GL_TEXTURE_2D); + } + } + if (glstate->texture.client!=old_tex) + TEXTURE(old_tex); + #undef TEXTURE + + if (stipple) { + if(!list->use_glstate) //TODO: avoid that malloc/free... + free(list->tex[stipple_tmu]); + list->tex[stipple_tmu]=NULL; + LOAD_GLES(glActiveTexture); + if(glstate->gleshard->active!=stipple_tmu) + gl4es_glActiveTexture(GL_TEXTURE0+stipple_tmu); + GLenum matmode; + gl4es_glGetIntegerv(GL_MATRIX_MODE, &matmode); + gl4es_glMatrixMode(GL_TEXTURE); + gl4es_glPopMatrix(); + gl4es_glMatrixMode(matmode); + gl4es_glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, stipple_env); + gl4es_glAlphaFunc(stipple_afunc, stipple_aref); + if(stipple_tex2d) + gl4es_glEnable(GL_TEXTURE_2D); + else + gl4es_glDisable(GL_TEXTURE_2D); + if(stipple_alpha) + gl4es_glEnable(GL_ALPHA_TEST); + else + gl4es_glDisable(GL_ALPHA_TEST); + for (int k=0; k<4; k++) { + if(stipple_texgen[k]) + gl4es_glEnable(GL_TEXTURE_GEN_S+k); + } + if(glstate->gleshard->active!=stipple_old) + gl4es_glActiveTexture(GL_TEXTURE0+stipple_old); + } + if(list->post_color) gl4es_glColor4fv(list->post_colors); + if(list->post_normal) gl4es_glNormal3fv(list->post_normals); + } while ((list = list->next)); + gl4es_glPopClientAttrib(); +} diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/listrl.c b/Projects/Android/jni/SupportLibs/gl4es/src/gl/listrl.c new file mode 100644 index 0000000..3b3161f --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/listrl.c @@ -0,0 +1,526 @@ +#include "list.h" + +#include "../glx/hardext.h" +#include "gl4es.h" +#include "glstate.h" +#include "init.h" +#include "matrix.h" + +static inline void rlVertexCommon(renderlist_t *list, int idx, int l) { + if(list->use_glstate) { + resize_renderlist(list); + if (!list->vert) list->vert = glstate->merger_master; + if (list->normal) memcpy(list->normal + idx, list->lastNormal, sizeof(GLfloat) * 3); + if (list->fogcoord) memcpy(list->fogcoord + idx, &glstate->fogcoord, sizeof(GLfloat) * 1); + } else { + if (!list->vert) list->vert = alloc_sublist(4, list->cap); + else resize_renderlist(list); + if (list->normal) memcpy(list->normal + (l * 3), list->lastNormal, sizeof(GLfloat) * 3); + if (list->fogcoord) memcpy(list->fogcoord + (l * 1), &glstate->fogcoord, sizeof(GLfloat) * 1); + } + // common part + if (list->color) memcpy(list->color + idx, list->lastColors, sizeof(GLfloat) * 4); + if (list->secondary) memcpy(list->secondary + (l * 4), glstate->secondary, sizeof(GLfloat) * 4); + if (list->tex[0]) memcpy(list->tex[0] + idx, glstate->texcoord[0], sizeof(GLfloat) * 4); + if (list->tex[1]) memcpy(list->tex[1] + idx, glstate->texcoord[1], sizeof(GLfloat) * 4); + for (int a=2; amaxtex; a++) + if (list->tex[a]) memcpy(list->tex[a] + (l * 4), glstate->texcoord[a], sizeof(GLfloat) * 4); +} + +void FASTMATH rlVertex4f(renderlist_t *list, GLfloat x, GLfloat y, GLfloat z, GLfloat w) { + const int idx = (list->use_glstate)?(list->len * 5*4):(list->len * 4); + rlVertexCommon(list, idx, list->len); + ++list->len; + + GLfloat * const vert = list->vert + idx; + vert[0] = x; vert[1] = y; vert[2] = z; vert[3] = w; +} +void FASTMATH rlVertex3fv(renderlist_t *list, GLfloat* v) { + const int idx = (list->use_glstate)?(list->len * 5*4):(list->len * 4); + rlVertexCommon(list, idx, list->len); + + GLfloat * const vert = list->vert + idx; + ++list->len; + memcpy(vert, v, 3*sizeof(GLfloat)); + vert[3] = 1.f; +} +void FASTMATH rlVertex4fv(renderlist_t *list, GLfloat* v) { + const int idx = (list->use_glstate)?(list->len * 5*4):(list->len * 4); + rlVertexCommon(list, idx, list->len); + + GLfloat * const vert = list->vert + idx; + ++list->len; + memcpy(vert, v, 4*sizeof(GLfloat)); +} + +void rlEnd(renderlist_t *list) { + // adjust number of vertex, to remove extra vertex + int adj = list->len - list->cur_istart; + adj -= adjust_vertices(list->merger_mode?list->merger_mode:list->mode_init, adj); + //printf("rlEnd(%d), indices=%p, mode_init_len=%d, len/cur_istart(adj)/ilen=%d/%d(%d)/%d, mode/mode_init=%s/%s, merger_mode=%s\n", list, list->indices, list->mode_init_len, list->len, list->cur_istart, adj, list->ilen, PrintEnum(list->mode), PrintEnum(list->mode_init), list->merger_mode?PrintEnum(list->merger_mode):"none"); + list->len -= adj; + if(!list->mode_inits && list->cur_istart) list_add_modeinit(list, list->mode_init); + if(list->indices && list->merger_mode && list->len-list->cur_istart) { + // also feed the indices... + int istart = list->cur_istart; + int ivert = 0; + int len = list->len-istart; + resize_indices_renderlist(list, indices_getindicesize(list->merger_mode, len)); + switch (list->merger_mode) { + case GL_LINE_STRIP: + if(len>1) { + list->indices[list->ilen++]=istart+(ivert); + list->indices[list->ilen++]=istart+(++ivert); + for (int i=2; iindices[list->ilen++]=istart+(ivert); + list->indices[list->ilen++]=istart+(++ivert); + } + } + break; + case GL_LINE_LOOP: + if(len>1) { + list->indices[list->ilen++]=istart+(ivert++); + list->indices[list->ilen++]=istart+(ivert++); + for (int i=istart+2; ilen; i++) { + list->indices[list->ilen++]=istart+(ivert-1); + list->indices[list->ilen++]=istart+(ivert++); + } + list->indices[list->ilen++]=istart+(ivert-1); + list->indices[list->ilen++]=istart; + } + break; + case GL_POLYGON: + case GL_TRIANGLE_FAN: + if(len>2) { + list->indices[list->ilen++]=istart+(ivert++); + list->indices[list->ilen++]=istart+(ivert++); + list->indices[list->ilen++]=istart+(ivert++); + } + for (int i=istart+3; ilen; i++) { + // add a new triangle for each new point + list->indices[list->ilen++]=istart; + list->indices[list->ilen++]=istart+(ivert-1); + list->indices[list->ilen++]=istart+(ivert++); + } + break; + case GL_QUAD_STRIP: + case GL_TRIANGLE_STRIP: + if(len>2) { + list->indices[list->ilen++]=istart+(ivert++); + list->indices[list->ilen++]=istart+(ivert++); + list->indices[list->ilen++]=istart+(ivert++); + } + for (int i=istart+3; ilen; i++) { + // add a new triangle for each new point + list->indices[list->ilen++]=istart+(ivert-((ivert%2)?1:2)); + list->indices[list->ilen++]=istart+(ivert-((ivert%2)?2:1)); + list->indices[list->ilen++]=istart+(ivert++); + } + break; + case GL_QUADS: + if(len>3) + for (int i=istart; i+3len; i+=4) { + list->indices[list->ilen++]=i+0; + list->indices[list->ilen++]=i+1; + list->indices[list->ilen++]=i+2; + + list->indices[list->ilen++]=i+0; + list->indices[list->ilen++]=i+2; + list->indices[list->ilen++]=i+3; + } + break; + default: + for (int i=istart; ilen; i++) + list->indices[list->ilen++]=i; + break; + } + } + list->cur_istart = 0; + if(list->mode_inits) list_add_modeinit(list, list->merger_mode?list->merger_mode:list->mode_init); + if(list->color) + memcpy(glstate->color, list->lastColors, 4*sizeof(GLfloat)); + if(list->normal) + memcpy(glstate->normal, list->lastNormal, 3*sizeof(GLfloat)); +} + +static inline void rlNormalCommon(renderlist_t *list) { + if (list->normal == NULL) { + const int stride = (list->use_glstate)?(5*4):3; + if(list->use_glstate) { + list->normal = glstate->merger_master+4+4+2*4; + } else { + list->normal = alloc_sublist(3, list->cap); + } + // catch up + for (int i = 0; i < list->len; i++) { + GLfloat *normal = (list->normal + (i * stride)); + memcpy(normal, list->lastNormal, sizeof(GLfloat) * 3); + } + } +} +void FASTMATH rlNormal3f(renderlist_t *list, GLfloat x, GLfloat y, GLfloat z) { + rlNormalCommon(list); + + GLfloat *normal = list->lastNormal; + normal[0] = x; normal[1] = y; normal[2] = z; +} +void FASTMATH rlNormal3fv(renderlist_t *list, GLfloat*v) { + rlNormalCommon(list); + + memcpy(list->lastNormal, v, 3*sizeof(GLfloat)); +} + +static inline void rlColorCommon(renderlist_t *list) { + if (list->color == NULL) { + list->lastColorsSet = 1; + const int stride = (list->use_glstate)?(5*4):4; + if(list->use_glstate) { + list->color = glstate->merger_master+4; + } else { + list->color = alloc_sublist(4, list->cap); + } + // catch up + for (int i = 0; i < list->len; i++) { + GLfloat *color = (list->color + (i * stride)); + memcpy(color,list->lastColors, sizeof(GLfloat) * 4); + } + } +} +void FASTMATH rlColor4f(renderlist_t *list, GLfloat r, GLfloat g, GLfloat b, GLfloat a) { + rlColorCommon(list); + + GLfloat *color = list->lastColors; + color[0] = r; color[1] = g; color[2] = b; color[3] = a; +} +void FASTMATH rlColor4fv(renderlist_t *list, GLfloat* v) { + rlColorCommon(list); + + memcpy(list->lastColors, v, 4*sizeof(GLfloat)); +} + +void FASTMATH rlSecondary3f(renderlist_t *list, GLfloat r, GLfloat g, GLfloat b) { + if (list->secondary == NULL) { + if(list->use_glstate) { + if(!glstate->merger_secondary) + glstate->merger_secondary = (GLfloat*)malloc(sizeof(GLfloat)*4*glstate->merger_cap); + list->secondary = glstate->merger_secondary; + } else { + list->secondary = alloc_sublist(4, list->cap); + } + // catch up + GLfloat *secondary = list->secondary; + for (int i = 0; i < list->len; i++) { + memcpy(secondary, list->lastSecondaryColors, sizeof(GLfloat) * 4); + secondary += 4; + } + } + + GLfloat *color = glstate->secondary; + color[0] = r; color[1] = g; color[2] = b; color[3] = 0.0f; +} + +void rlMaterialfv(renderlist_t *list, GLenum face, GLenum pname, const GLfloat * params) { + rendermaterial_t *m; + khash_t(material) *map; + khint_t k; + int ret; + if (! list->material) { + list->material = map = kh_init(material); + // segfaults if we don't do a single put + kh_put(material, map, 1, &ret); + kh_del(material, map, 1); + } else { + map = list->material; + } + + int iface = (face==GL_FRONT)?0:((face==GL_BACK)?1:2); + int key = pname | (iface<<16); + k = kh_get(material, map, key); + if (k == kh_end(map)) { + k = kh_put(material, map, key, &ret); + m = kh_value(map, k) = malloc(sizeof(rendermaterial_t)); + } else { + m = kh_value(map, k); + } + + m->face = face; + m->pname = pname; + int sz=4; + if(pname==GL_SHININESS || pname==GL_COLOR_INDEXES) sz=1; + memcpy(m->color, params, sz*sizeof(GLfloat)); +} + +void rlLightfv(renderlist_t *list, GLenum which, GLenum pname, const GLfloat * params) { + renderlight_t *m; + khash_t(light) *map; + khint_t k; + int ret; + if (! list->light) { + list->light = map = kh_init(light); + // segfaults if we don't do a single put + kh_put(light, map, 1, &ret); + kh_del(light, map, 1); + } else { + map = list->light; + } + + int key = pname | ((which-GL_LIGHT0)<<16); + k = kh_get(light, map, key); + if (k == kh_end(map)) { + k = kh_put(light, map, key, &ret); + m = kh_value(map, k) = malloc(sizeof(renderlight_t)); + } else { + m = kh_value(map, k); + } + + m->which = which; + m->pname = pname; + int sz=4; + if(pname==GL_SPOT_DIRECTION) sz=3; + if(pname==GL_SPOT_EXPONENT || pname==GL_SPOT_CUTOFF + || pname==GL_CONSTANT_ATTENUATION || pname==GL_LINEAR_ATTENUATION + || pname==GL_QUADRATIC_ATTENUATION) sz=1; + memcpy(m->color, params, sz*sizeof(GLfloat)); +} + +void rlTexGenfv(renderlist_t *list, GLenum coord, GLenum pname, const GLfloat * params) { + rendertexgen_t *m; + khash_t(texgen) *map; + khint_t k; + int ret; + if (! list->texgen) { + list->texgen = map = kh_init(texgen); + // segfaults if we don't do a single put + kh_put(texgen, map, 1, &ret); + kh_del(texgen, map, 1); + } else { + map = list->texgen; + } + + int key = pname | ((coord-GL_S)<<16); + k = kh_get(texgen, map, key); + if (k == kh_end(map)) { + k = kh_put(texgen, map, key, &ret); + m = kh_value(map, k) = malloc(sizeof(rendertexgen_t)); + } else { + m = kh_value(map, k); + } + + m->coord = coord; + m->pname = pname; + memcpy(m->color, params, 4*sizeof(GLfloat)); +} + +void rlMultiTexCoordCommon(renderlist_t* list, int tmu) { + if (list->tex[tmu] == NULL) { + if (list->maxtexmaxtex = tmu+1; + const int stride = (list->use_glstate && tmu<2)?(5*4):4; + if(list->use_glstate) { + if(tmu<2) + list->tex[tmu] = glstate->merger_master+4+4+tmu*4; + else { + if(!glstate->merger_tex[tmu-2]) + glstate->merger_tex[tmu-2] = (GLfloat*)malloc(sizeof(GLfloat)*4*glstate->merger_cap); + list->tex[tmu] = glstate->merger_tex[tmu-2]; + } + } else { + list->tex[tmu] = alloc_sublist(4, list->cap); + } + // catch up + GLfloat *tex = list->tex[tmu]; + for (int i = 0; i < list->len; i++) { + memcpy(tex, glstate->texcoord[tmu], sizeof(GLfloat) * 4); + tex += stride; + } + } +} +void FASTMATH rlMultiTexCoord4f(renderlist_t *list, GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q) { + const int tmu = target - GL_TEXTURE0; + rlMultiTexCoordCommon(list, tmu); + + GLfloat *tex = glstate->texcoord[tmu]; + tex[0] = s; tex[1] = t; + tex[2] = r; tex[3] = q; +} +void FASTMATH rlMultiTexCoord2fv(renderlist_t *list, GLenum target, GLfloat* v) { + const int tmu = target - GL_TEXTURE0; + rlMultiTexCoordCommon(list, tmu); + + GLfloat *tex = glstate->texcoord[tmu]; + memcpy(tex, v, 2*sizeof(GLfloat)); + tex[2] = 0.f; tex[3] = 1.f; +} +void FASTMATH rlMultiTexCoord4fv(renderlist_t *list, GLenum target, GLfloat* v) { + const int tmu = target - GL_TEXTURE0; + rlMultiTexCoordCommon(list, tmu); + + GLfloat *tex = glstate->texcoord[tmu]; + memcpy(tex, v, 4*sizeof(GLfloat)); +} + +void FASTMATH rlFogCoordf(renderlist_t *list, GLfloat coord) { + if (list->fogcoord == NULL) { + const int stride = (list->use_glstate)?(5*4):1; + if(list->use_glstate) { + list->fogcoord = glstate->merger_master+4+4+2*4+3; + } else { + list->fogcoord = alloc_sublist(1, list->cap); + } + // catch up + GLfloat *fog = list->fogcoord; + for (int i = 0; i < list->len; i++) { + memcpy(fog, &glstate->fogcoord, sizeof(GLfloat) * 1); + fog+=stride; + } + } + glstate->fogcoord = coord; +} + +void rlActiveTexture(renderlist_t *list, GLenum texture ) { + list->set_tmu = true; + list->tmu = texture - GL_TEXTURE0; + if(list->maxtex < list->tmu+1) list->maxtex = list->tmu+1; +} + +void rlBindTexture(renderlist_t *list, GLenum target, GLuint texture) { + list->texture = texture; + list->target_texture = target; + list->set_texture = true; +} + +void rlRasterOp(renderlist_t *list, int op, GLfloat x, GLfloat y, GLfloat z) { + list->raster_op = op; + list->raster_xyz[0] = x; + list->raster_xyz[1] = y; + list->raster_xyz[2] = z; +} + +void rlFogOp(renderlist_t *list, int op, const GLfloat* v) { + int n = 1; + if (op==GL_FOG_COLOR) n = 4; + list->fog_op = op; + list->fog_val[0] = v[0]; + if (n>1) list->fog_val[1] = v[1]; + if (n>2) list->fog_val[2] = v[2]; + if (n>3) list->fog_val[3] = v[3]; +} + +void rlPointParamOp(renderlist_t *list, int op, const GLfloat* v) { + list->pointparam_op = op; + list->pointparam_val[0] = v[0]; + list->pointparam_val[1] = v[1]; + list->pointparam_val[2] = v[2]; + list->pointparam_val[3] = v[3]; +} + +void rlPushCall(renderlist_t *list, packed_call_t *data) { + call_list_t *cl = &list->calls; + if (!cl->calls) { + cl->cap = DEFAULT_CALL_LIST_CAPACITY; + cl->calls = malloc(DEFAULT_CALL_LIST_CAPACITY * sizeof(void*)); + } else if (list->calls.len == list->calls.cap) { + cl->cap += DEFAULT_CALL_LIST_CAPACITY; + cl->calls = realloc(cl->calls, cl->cap * sizeof(void*)); + } + cl->calls[cl->len++] = data; +} + +renderlist_t* GetFirst(renderlist_t* list) { + while(list->prev) + list = list->prev; + return list; +} + +void rlTexEnvfv(renderlist_t *list, GLenum target, GLenum pname, const GLfloat * params) { + int n = 1; + switch(target) { + case GL_POINT_SPRITE: n = 1; break; + default: + switch(pname) { + case GL_TEXTURE_ENV_MODE: n=1; break; + case GL_TEXTURE_ENV_COLOR: n=4; break; + case GL_TEXTURE_LOD_BIAS: n=1; break; + } + } + rendertexenv_t *m; + khash_t(texenv) *map; + khint_t k; + int ret; + if (! list->texenv) { + list->texenv = map = kh_init(texenv); + // segfaults if we don't do a single put + kh_put(texenv, map, 1, &ret); + kh_del(texenv, map, 1); + } else { + map = list->texenv; + } + + int key = pname | ((target)<<16); + k = kh_get(texenv, map, key); + if (k == kh_end(map)) { + k = kh_put(texenv, map, key, &ret); + m = kh_value(map, k) = malloc(sizeof(rendertexenv_t)); + } else { + m = kh_value(map, k); + } + + m->target = target; + m->pname = pname; + memcpy(m->params, params, n*sizeof(GLfloat)); +} +void rlTexEnviv(renderlist_t *list, GLenum target, GLenum pname, const GLint * params) { + GLfloat fparams[4]; + int n = 1; + switch(target) { + case GL_POINT_SPRITE: n = 1; break; + default: + switch(pname) { + case GL_TEXTURE_ENV_MODE: n=1; break; + case GL_TEXTURE_ENV_COLOR: n=4; break; + case GL_TEXTURE_LOD_BIAS: n=1; break; + } + } + for (int i=0; iprev && l->prev->open && l->prev->mode==m && l->prev->mode_init==m) + || (l->stage==STAGE_POSTDRAW && l->open)) + && ((l->mode_dimension==rendermode_dimensions(m) && l->mode_dimension>0))) + { + return recycle_renderlist(l, m); + } else { + // if we are just in glBegin/glEnd merger, then purge the list... + if(!glstate->list.compiling && glstate->list.pending) { + glstate->list.active = NULL; + l = end_renderlist(l); + draw_renderlist(l); + free_renderlist(l); + l = alloc_renderlist(); + NewStage(l, STAGE_DRAW); + } else { + NewStage(l, STAGE_DRAW); + } + l->mode=m; + l->mode_init=m; + l->mode_dimension = rendermode_dimensions(m); + if(!glstate->merger_used && !glstate->list.compiling + && !(glstate->render_mode==GL_SELECT || glstate->polygon_mode==GL_LINE || glstate->polygon_mode == GL_POINT)) + { + l->vert_stride=sizeof(GLfloat)*4*5; + l->color_stride=sizeof(GLfloat)*4*5; + l->tex_stride[0]=sizeof(GLfloat)*4*5; + l->tex_stride[1]=sizeof(GLfloat)*4*5; + l->normal_stride=sizeof(GLfloat)*4*5; + l->fogcoord_stride=sizeof(GLfloat)*4*5; + l->use_glstate=1; + glstate->merger_used=1; + } + return l; + } +} \ No newline at end of file diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/loader.c b/Projects/Android/jni/SupportLibs/gl4es/src/gl/loader.c new file mode 100644 index 0000000..f45b0e3 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/loader.c @@ -0,0 +1,145 @@ +#include "loader.h" + +#ifdef __EMSCRIPTEN__ + +void *gles = (void *)0xFFFFFFFF; +void *egl = (void *)0xFFFFFFFF; + +void load_libs() { +} + +#else + +#include "logs.h" +#include "init.h" +#ifdef AMIGAOS4 +#include "../agl/amigaos.h" +#include +#else +#include +#endif + +void *gles = NULL, *egl = NULL, *bcm_host = NULL, *vcos = NULL, *gbm = NULL; +#ifndef NO_GBM +static const char *gbm_lib[] = { + "libgbm", + NULL +}; +#endif +#ifndef AMIGAOS4 +static const char *path_prefix[] = { + "", + "/opt/vc/lib/", + "/usr/local/lib/", + "/usr/lib/", + NULL, +}; + +static const char *lib_ext[] = { +#ifndef NO_GBM + "so.19", +#endif + "so", + "so.1", + "so.2", + "dylib", + "dll", + NULL, +}; + +static const char *gles2_lib[] = { + #if defined(BCMHOST) && !defined(ANDROID) + "libbrcmGLESv2", + #endif + "libGLESv3", //Hack in GLES3 + "libGLESv2_CM", + "libGLESv2", + NULL +}; + +static const char *gles_lib[] = { + #if defined(BCMHOST) && !defined(ANDROID) + "libbrcmGLESv1_CM", + #endif + "libGLESv1_CM", + "libGLES_CM", + NULL +}; + +static const char *egl_lib[] = { + #if defined(BCMHOST) && !defined(ANDROID) + "libbrcmEGL", + #endif + "libEGL", + NULL +}; + +void *open_lib(const char **names, const char *override) { + void *lib = NULL; + + char path_name[PATH_MAX + 1]; + int flags = RTLD_LOCAL | RTLD_NOW; +#ifdef RTLD_DEEPBIND + flags |= RTLD_DEEPBIND; +#endif + if (override) { + if ((lib = dlopen(override, flags))) { + strncpy(path_name, override, PATH_MAX); + if(!globals4es.nobanner) LOGD("LIBGL:loaded: %s\n", path_name); + return lib; + } else { + LOGE("LIBGL_GLES override failed: %s\n", dlerror()); + } + } + for (int p = 0; path_prefix[p]; p++) { + for (int i = 0; names[i]; i++) { + for (int e = 0; lib_ext[e]; e++) { + snprintf(path_name, PATH_MAX, "%s%s.%s", path_prefix[p], names[i], lib_ext[e]); + if ((lib = dlopen(path_name, flags))) { + if(!globals4es.nobanner) LOGD("LIBGL: loaded: %s\n", path_name); + return lib; + } + } + } + } + return lib; +} + +void load_libs() { + static int first = 1; + if (! first) return; + first = 0; + char *gles_override = getenv("LIBGL_GLES"); +#if defined(BCMHOST) && !defined(ANDROID) + // optimistically try to load the raspberry pi libs + if (! gles_override) { + const char *bcm_host_name[] = {"libbcm_host", NULL}; + const char *vcos_name[] = {"libvcos", NULL}; + bcm_host = open_lib(bcm_host_name, NULL); + vcos = open_lib(vcos_name, NULL); + } +#endif + gles = open_lib((globals4es.es==1)?gles_lib:gles2_lib, gles_override); + WARN_NULL(gles); + +#ifdef NOEGL + egl = gles; +#else + char *egl_override = getenv("LIBGL_EGL"); + egl = open_lib(egl_lib, egl_override); +#endif + WARN_NULL(egl); + +#ifndef NO_GBM + char *gbm_override = getenv("LIBGL_GBM"); + gbm = open_lib(gbm_lib, gbm_override); +#endif +} +#else +void load_libs() { + os4OpenLib(&gles); +} +#endif //AMIGAOS4 + +#endif + diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/loader.h b/Projects/Android/jni/SupportLibs/gl4es/src/gl/loader.h new file mode 100644 index 0000000..b1d504e --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/loader.h @@ -0,0 +1,214 @@ +#ifndef _GL4ES_LOADER_H_ +#define _GL4ES_LOADER_H_ + +#include +#include "gl4es.h" +#include "gles.h" +#include "logs.h" + +#ifndef NOEGL +//Typedef for egl to be able to call LOAD_EGL... +#include +#include + +typedef EGLBoolean (*eglBindAPI_PTR)(EGLenum api); +typedef EGLBoolean (*eglBindTexImage_PTR)(EGLDisplay dpy, EGLSurface surface, EGLint buffer); +typedef EGLBoolean (*eglChooseConfig_PTR)(EGLDisplay dpy, const EGLint * attrib_list, EGLConfig * configs, EGLint config_size, EGLint * num_config); +typedef EGLBoolean (*eglCopyBuffers_PTR)(EGLDisplay dpy, EGLSurface surface, EGLNativePixmapType target); +typedef EGLContext (*eglCreateContext_PTR)(EGLDisplay dpy, EGLConfig config, EGLContext share_context, const EGLint * attrib_list); +typedef EGLSurface (*eglCreatePbufferFromClientBuffer_PTR)(EGLDisplay dpy, EGLenum buftype, EGLClientBuffer buffer, EGLConfig config, const EGLint * attrib_list); +typedef EGLSurface (*eglCreatePbufferSurface_PTR)(EGLDisplay dpy, EGLConfig config, const EGLint * attrib_list); +typedef EGLSurface (*eglCreatePixmapSurface_PTR)(EGLDisplay dpy, EGLConfig config, EGLNativePixmapType pixmap, const EGLint * attrib_list); +typedef EGLSurface (*eglCreatePlatformWindowSurface_PTR)(EGLDisplay display, EGLConfig config, void * native_window, const EGLint * attrib_list); +typedef EGLSurface (*eglCreateWindowSurface_PTR)(EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, const EGLint * attrib_list); +typedef EGLBoolean (*eglDestroyContext_PTR)(EGLDisplay dpy, EGLContext ctx); +typedef EGLBoolean (*eglDestroySurface_PTR)(EGLDisplay dpy, EGLSurface surface); +typedef EGLBoolean (*eglGetConfigAttrib_PTR)(EGLDisplay dpy, EGLConfig config, EGLint attribute, EGLint * value); +typedef EGLBoolean (*eglGetConfigs_PTR)(EGLDisplay dpy, EGLConfig * configs, EGLint config_size, EGLint * num_config); +typedef EGLContext (*eglGetCurrentContext_PTR)(); +typedef EGLDisplay (*eglGetCurrentDisplay_PTR)(); +typedef EGLSurface (*eglGetCurrentSurface_PTR)(EGLint readdraw); +typedef EGLDisplay (*eglGetDisplay_PTR)(EGLNativeDisplayType display_id); +typedef EGLDisplay (*eglGetPlatformDisplay_PTR)(EGLenum platform, void * native_display, const EGLint * attrib_list); +typedef EGLint (*eglGetError_PTR)(); +typedef __eglMustCastToProperFunctionPointerType (*eglGetProcAddress_PTR)(const char * procname); +typedef EGLBoolean (*eglInitialize_PTR)(EGLDisplay dpy, EGLint * major, EGLint * minor); +typedef EGLBoolean (*eglMakeCurrent_PTR)(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx); +typedef EGLenum (*eglQueryAPI_PTR)(); +typedef EGLBoolean (*eglQueryContext_PTR)(EGLDisplay dpy, EGLContext ctx, EGLint attribute, EGLint * value); +typedef const char * (*eglQueryString_PTR)(EGLDisplay dpy, EGLint name); +typedef EGLBoolean (*eglQuerySurface_PTR)(EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint * value); +typedef EGLBoolean (*eglReleaseTexImage_PTR)(EGLDisplay dpy, EGLSurface surface, EGLint buffer); +typedef EGLBoolean (*eglReleaseThread_PTR)(); +typedef EGLBoolean (*eglSurfaceAttrib_PTR)(EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint value); +typedef EGLBoolean (*eglSwapBuffers_PTR)(EGLDisplay dpy, EGLSurface surface); +typedef EGLBoolean (*eglSwapBuffersWithDamageEXT_PTR)(EGLDisplay dpy, EGLSurface surface, EGLint * rects, EGLint n_rects); +typedef EGLBoolean (*eglSwapInterval_PTR)(EGLDisplay dpy, EGLint interval); +typedef EGLBoolean (*eglTerminate_PTR)(EGLDisplay dpy); +typedef EGLBoolean (*eglUnlockSurfaceKHR_PTR)(EGLDisplay display, EGLSurface surface); +typedef EGLBoolean (*eglWaitClient_PTR)(); +typedef EGLBoolean (*eglWaitGL_PTR)(); +typedef EGLBoolean (*eglWaitNative_PTR)(EGLint engine); +#ifdef TEXSTREAM +typedef EGLSurface (*eglCreatePixmapSurfaceHI_PTR)(EGLDisplay dpy, EGLConfig config, struct EGLClientPixmapHI * pixmap); +typedef EGLBoolean (*eglDestroyImageKHR_PTR)(EGLDisplay dpy, EGLImageKHR image); +typedef EGLBoolean (*eglDestroyStreamKHR_PTR)(EGLDisplay dpy, EGLStreamKHR stream); +typedef EGLImageKHR (*eglCreateImageKHR_PTR)(EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLint * attrib_list); +typedef EGLStreamKHR (*eglCreateStreamFromFileDescriptorKHR_PTR)(EGLDisplay dpy, EGLNativeFileDescriptorKHR file_descriptor); +typedef EGLStreamKHR (*eglCreateStreamKHR_PTR)(EGLDisplay dpy, const EGLint * attrib_list); +typedef EGLSyncKHR (*eglCreateSyncKHR_PTR)(EGLDisplay dpy, EGLenum type, const EGLint * attrib_list); +typedef EGLBoolean (*eglDestroySyncKHR_PTR)(EGLDisplay dpy, EGLSyncKHR sync); +typedef EGLBoolean (*eglSignalSyncKHR_PTR)(EGLDisplay dpy, EGLSyncKHR sync, EGLenum mode); +typedef EGLBoolean (*eglGetSyncAttribKHR_PTR)(EGLDisplay dpy, EGLSyncKHR sync, EGLint attribute, EGLint * value); +typedef EGLBoolean (*eglStreamAttribKHR_PTR)(EGLDisplay dpy, EGLStreamKHR stream, EGLenum attribute, EGLint value); +typedef EGLBoolean (*eglStreamConsumerAcquireKHR_PTR)(EGLDisplay dpy, EGLStreamKHR stream); +typedef EGLBoolean (*eglStreamConsumerGLTextureExternalKHR_PTR)(EGLDisplay dpy, EGLStreamKHR stream); +typedef EGLBoolean (*eglStreamConsumerReleaseKHR_PTR)(EGLDisplay dpy, EGLStreamKHR stream); +typedef EGLBoolean (*eglLockSurfaceKHR_PTR)(EGLDisplay display, EGLSurface surface, const EGLint * attrib_list); +typedef EGLNativeFileDescriptorKHR (*eglGetStreamFileDescriptorKHR_PTR)(EGLDisplay dpy, EGLStreamKHR stream); +typedef EGLBoolean (*eglQueryStreamKHR_PTR)(EGLDisplay dpy, EGLStreamKHR stream, EGLenum attribute, EGLint * value); +typedef EGLBoolean (*eglQueryStreamTimeKHR_PTR)(EGLDisplay dpy, EGLStreamKHR stream, EGLenum attribute, EGLTimeKHR * value); +typedef EGLint (*eglWaitSyncKHR_PTR)(EGLDisplay dpy, EGLSyncKHR sync, EGLint flags); +typedef EGLSurface (*eglCreateStreamProducerSurfaceKHR_PTR)(EGLDisplay dpy, EGLConfig config, EGLStreamKHR stream, const EGLint * attrib_list); +#endif // TEXSTREAM +#endif // NOEGL + +#ifdef AMIGAOS4 +#include "../agl/amigaos.h" +#else +#include +#endif +#include +#include +#include + +#include "../glx/hardext.h" + +// will become references to dlopen'd gles and egl +extern void *gles, *egl, *bcm_host, *vcos, *gbm; +#ifdef AMIGAOS4 +#define proc_address(lib, name) os4GetProcAddress(name) +#elif defined(__EMSCRIPTEN__) +void *emscripten_GetProcAddress(const char *name); +#define proc_address(lib, name) emscripten_GetProcAddress(name) +#else // AMIGAOS4 +#define proc_address(lib, name) dlsym(lib, name) +void *open_lib(const char **names, const char *override); +#endif // AMIGAOS4 + +#define WARN_NULL(name) if (name == NULL) LOGD("LIBGL: warning, " #name " is NULL\n"); + +#define PUSH_IF_COMPILING_EXT(nam, ...) \ + if (glstate->list.active) { \ + if (!glstate->list.pending) { \ + NewStage(glstate->list.active, STAGE_GLCALL); \ + push_##nam(__VA_ARGS__); \ + noerrorShim(); \ + return (nam##_RETURN)0; \ + } \ + else flush(); \ + } + +#define PUSH_IF_COMPILING(name) PUSH_IF_COMPILING_EXT(name, name##_ARG_NAMES) + +#define DEFINE_RAW(lib, name) static name##_PTR lib##_##name = NULL +#define LOAD_RAW(lib, name, ...) \ + { \ + static bool first = true; \ + if (first) { \ + first = false; \ + if (lib != NULL) { \ + lib##_##name = (name##_PTR)__VA_ARGS__; \ + } \ + WARN_NULL(lib##_##name); \ + } \ + } + +#define LOAD_RAW_SILENT(lib, name, ...) \ + { \ + static bool first = true; \ + if (first) { \ + first = false; \ + if (lib != NULL) { \ + lib##_##name = (name##_PTR)__VA_ARGS__; \ + } \ + } \ + } + +#define LOAD_RAW_ALT(lib, alt, name, ...) \ + { \ + static bool first = true; \ + if (first) { \ + first = false; \ + if (lib != NULL) { \ + lib##_##name = (name##_PTR)__VA_ARGS__; \ + } \ + if(lib##_##name == NULL) \ + lib##_##name = alt##_##name; \ + } \ + } + +#define LOAD_LIB(lib, name) DEFINE_RAW(lib, name); LOAD_RAW(lib, name, proc_address(lib, #name)) +#define LOAD_LIB_SILENT(lib, name) DEFINE_RAW(lib, name); LOAD_RAW_SILENT(lib, name, proc_address(lib, #name)) +#define LOAD_LIB_ALT(lib, alt, name) DEFINE_RAW(lib, name); LOAD_RAW_ALT(lib, alt, name, proc_address(lib, #name)) + +#define LOAD_GLES(name) LOAD_LIB(gles, name) +#define LOAD_GLES2(name) LOAD_LIB_SILENT(gles, name) +#define LOAD_GLES_OR_FPE(name) LOAD_LIB_ALT(gles, fpe, name) + +#define LOAD_GLES_FPE(name) \ + DEFINE_RAW(gles, name); \ + if(hardext.esversion==1) { \ + LOAD_RAW(gles, name, proc_address(gles, #name)); \ + } else { \ + gles_##name = fpe_##name; \ + } + +#define LOAD_EGL(name) LOAD_LIB(egl, name) + +#define LOAD_GBM(name) LOAD_LIB(gbm, name) + +#if defined(AMIGAOS4) || defined(NOEGL) || defined(__EMSCRIPTEN__) +#define LOAD_GLES_OES(name) \ + DEFINE_RAW(gles, name); \ + { \ + LOAD_RAW(gles, name, proc_address(gles, #name"OES")); \ + } + +#define LOAD_GLES_EXT(name) \ + DEFINE_RAW(gles, name); \ + { \ + LOAD_RAW(gles, name, proc_address(gles, #name"EXT")); \ + } + +#define LOAD_GLES2_OR_OES(name) \ + DEFINE_RAW(gles, name); \ + { \ + LOAD_RAW_SILENT(gles, name, proc_address(gles, #name)); \ + } + +#else // defined(AMIGAOS4) || defined(NOEGL) + +#define LOAD_GLES_OES(name) \ + DEFINE_RAW(gles, name); \ + { \ + LOAD_EGL(eglGetProcAddress); \ + LOAD_RAW(gles, name, egl_eglGetProcAddress(#name"OES")); \ + } + +#define LOAD_GLES_EXT(name) \ + DEFINE_RAW(gles, name); \ + { \ + LOAD_EGL(eglGetProcAddress); \ + LOAD_RAW(gles, name, egl_eglGetProcAddress(#name"EXT")); \ + } + +#define LOAD_GLES2_OR_OES(name) \ + DEFINE_RAW(gles, name); \ + { \ + LOAD_EGL(eglGetProcAddress); \ + LOAD_RAW_SILENT(gles, name, ((hardext.esversion==1)?((void*)egl_eglGetProcAddress(#name"OES")):((void*)dlsym(gles, #name)))); \ + } +#endif // defined(AMIGAOS4) || defined(NOEGL) + +#endif // _GL4ES_LOADER_H_ diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/logs.h b/Projects/Android/jni/SupportLibs/gl4es/src/gl/logs.h new file mode 100644 index 0000000..24ac2ff --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/logs.h @@ -0,0 +1,9 @@ +#ifndef _GL4ES_LOGS_H_ +#define _GL4ES_LOGS_H_ + +#include + +#define LOGD(...) printf(__VA_ARGS__) +#define LOGE(...) fprintf(stderr, __VA_ARGS__) + +#endif // _GL4ES_LOGS_H_ diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/math/eval.c b/Projects/Android/jni/SupportLibs/gl4es/src/gl/math/eval.c new file mode 100644 index 0000000..01b40ba --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/math/eval.c @@ -0,0 +1,452 @@ + +/* + * Mesa 3-D graphics library + * Version: 3.5 + * + * Copyright (C) 1999-2001 Brian Paul All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + + +/* + * eval.c was written by + * Bernd Barsuhn (bdbarsuh@cip.informatik.uni-erlangen.de) and + * Volker Weiss (vrweiss@cip.informatik.uni-erlangen.de). + * + * My original implementation of evaluators was simplistic and didn't + * compute surface normal vectors properly. Bernd and Volker applied + * used more sophisticated methods to get better results. + * + * Thanks guys! + */ + +#include "eval.h" + +static GLboolean init_done = false; +static GLfloat inv_tab[MAX_EVAL_ORDER]; + +/* + * Horner scheme for Bezier curves + * + * Bezier curves can be computed via a Horner scheme. + * Horner is numerically less stable than the de Casteljau + * algorithm, but it is faster. For curves of degree n + * the complexity of Horner is O(n) and de Casteljau is O(n^2). + * Since stability is not important for displaying curve + * points I decided to use the Horner scheme. + * + * A cubic Bezier curve with control points b0, b1, b2, b3 can be + * written as + * + * (([3] [3] ) [3] ) [3] + * c(t) = (([0]*s*b0 + [1]*t*b1)*s + [2]*t^2*b2)*s + [3]*t^2*b3 + * + * [n] + * where s=1-t and the binomial coefficients [i]. These can + * be computed iteratively using the identity: + * + * [n] [n ] [n] + * [i] = (n-i+1)/i * [i-1] and [0] = 1 + */ + + +void +_math_horner_bezier_curve(const GLfloat * cp, GLfloat * out, GLfloat t, + GLuint dim, GLuint order) { + if (! init_done) + _math_init_eval(); + + GLfloat s, powert, bincoeff; + GLuint i, k; + + if (order >= 2) { + bincoeff = (GLfloat) (order - 1); + s = 1.0F - t; + for (k = 0; k < dim; k++) + out[k] = s * cp[k] + bincoeff * t * cp[dim + k]; + + for (i = 2, cp += 2 * dim, powert = t * t; i < order; + i++, powert *= t, cp += dim) { + bincoeff *= (GLfloat) (order - i); + bincoeff *= inv_tab[i]; + + for (k = 0; k < dim; k++) + out[k] = s * out[k] + bincoeff * powert * cp[k]; + } + } else { /* order=1 -> constant curve */ + for (k = 0; k < dim; k++) + out[k] = cp[k]; + } +} + +/* + * Tensor product Bezier surfaces + * + * Again the Horner scheme is used to compute a point on a + * TP Bezier surface. First a control polygon for a curve + * on the surface in one parameter direction is computed, + * then the point on the curve for the other parameter + * direction is evaluated. + * + * To store the curve control polygon additional storage + * for max(uorder,vorder) points is needed in the + * control net cn. + */ + + void + _math_horner_bezier_surf(GLfloat * cn, GLfloat * out, GLfloat u, GLfloat v, + GLuint dim, GLuint uorder, GLuint vorder) { + if (! init_done) + _math_init_eval(); + + GLfloat *cp = cn + uorder * vorder * dim; + GLuint i, uinc = vorder * dim; + + if (vorder > uorder) { + if (uorder >= 2) { + GLfloat s, poweru, bincoeff; + GLuint j, k; + + /* Compute the control polygon for the surface-curve in u-direction */ + for (j = 0; j < vorder; j++) { + GLfloat *ucp = &cn[j * dim]; + + /* Each control point is the point for parameter u on a */ + /* curve defined by the control polygons in u-direction */ + bincoeff = (GLfloat) (uorder - 1); + s = 1.0F - u; + + for (k = 0; k < dim; k++) + cp[j * dim + k] = s * ucp[k] + bincoeff * u * ucp[uinc + k]; + + for (i = 2, ucp += 2 * uinc, poweru = u * u; i < uorder; + i++, poweru *= u, ucp += uinc) { + bincoeff *= (GLfloat) (uorder - i); + bincoeff *= inv_tab[i]; + + for (k = 0; k < dim; k++) + cp[j * dim + k] = + s * cp[j * dim + k] + bincoeff * poweru * ucp[k]; + } + } + + /* Evaluate curve point in v */ + _math_horner_bezier_curve(cp, out, v, dim, vorder); + } else /* uorder=1 -> cn defines a curve in v */ + _math_horner_bezier_curve(cn, out, v, dim, vorder); + } else { /* vorder <= uorder */ + + if (vorder > 1) { + GLuint i; + + /* Compute the control polygon for the surface-curve in u-direction */ + for (i = 0; i < uorder; i++, cn += uinc) { + /* For constant i all cn[i][j] (j=0..vorder) are located */ + /* on consecutive memory locations, so we can use */ + /* horner_bezier_curve to compute the control points */ + + _math_horner_bezier_curve(cn, &cp[i * dim], v, dim, vorder); + } + + /* Evaluate curve point in u */ + _math_horner_bezier_curve(cp, out, u, dim, uorder); + } else /* vorder=1 -> cn defines a curve in u */ + _math_horner_bezier_curve(cn, out, u, dim, uorder); + } +} + +/* + * The direct de Casteljau algorithm is used when a point on the + * surface and the tangent directions spanning the tangent plane + * should be computed (this is needed to compute normals to the + * surface). In this case the de Casteljau algorithm approach is + * nicer because a point and the partial derivatives can be computed + * at the same time. To get the correct tangent length du and dv + * must be multiplied with the (u2-u1)/uorder-1 and (v2-v1)/vorder-1. + * Since only the directions are needed, this scaling step is omitted. + * + * De Casteljau needs additional storage for uorder*vorder + * values in the control net cn. + */ + +void +_math_de_casteljau_surf(GLfloat * cn, GLfloat * out, GLfloat * du, + GLfloat * dv, GLfloat u, GLfloat v, GLuint dim, + GLuint uorder, GLuint vorder) { + GLfloat *dcn = cn + uorder * vorder * dim; + GLfloat us = 1.0F - u, vs = 1.0F - v; + GLuint h, i, j, k; + GLuint minorder = uorder < vorder ? uorder : vorder; + GLuint uinc = vorder * dim; + GLuint dcuinc = vorder; + + /* Each component is evaluated separately to save buffer space */ + /* This does not drasticaly decrease the performance of the */ + /* algorithm. If additional storage for (uorder-1)*(vorder-1) */ + /* points would be available, the components could be accessed */ + /* in the innermost loop which could lead to less cache misses. */ + +#define CN(I,J,K) cn[(I)*uinc+(J)*dim+(K)] +#define DCN(I, J) dcn[(I)*dcuinc+(J)] + if (minorder < 3) { + if (uorder == vorder) { + for (k = 0; k < dim; k++) { + /* Derivative direction in u */ + du[k] = vs * (CN(1, 0, k) - CN(0, 0, k)) + + v * (CN(1, 1, k) - CN(0, 1, k)); + + /* Derivative direction in v */ + dv[k] = us * (CN(0, 1, k) - CN(0, 0, k)) + + u * (CN(1, 1, k) - CN(1, 0, k)); + + /* bilinear de Casteljau step */ + out[k] = us * (vs * CN(0, 0, k) + v * CN(0, 1, k)) + + u * (vs * CN(1, 0, k) + v * CN(1, 1, k)); + } + } else if (minorder == uorder) { + for (k = 0; k < dim; k++) { + /* bilinear de Casteljau step */ + DCN(1, 0) = CN(1, 0, k) - CN(0, 0, k); + DCN(0, 0) = us * CN(0, 0, k) + u * CN(1, 0, k); + + for (j = 0; j < vorder - 1; j++) { + /* for the derivative in u */ + DCN(1, j + 1) = CN(1, j + 1, k) - CN(0, j + 1, k); + DCN(1, j) = vs * DCN(1, j) + v * DCN(1, j + 1); + + /* for the `point' */ + DCN(0, j + 1) = us * CN(0, j + 1, k) + u * CN(1, j + 1, k); + DCN(0, j) = vs * DCN(0, j) + v * DCN(0, j + 1); + } + + /* remaining linear de Casteljau steps until the second last step */ + for (h = minorder; h < vorder - 1; h++) + for (j = 0; j < vorder - h; j++) { + /* for the derivative in u */ + DCN(1, j) = vs * DCN(1, j) + v * DCN(1, j + 1); + + /* for the `point' */ + DCN(0, j) = vs * DCN(0, j) + v * DCN(0, j + 1); + } + + /* derivative direction in v */ + dv[k] = DCN(0, 1) - DCN(0, 0); + + /* derivative direction in u */ + du[k] = vs * DCN(1, 0) + v * DCN(1, 1); + + /* last linear de Casteljau step */ + out[k] = vs * DCN(0, 0) + v * DCN(0, 1); + } + } else { /* minorder == vorder */ + for (k = 0; k < dim; k++) { + /* bilinear de Casteljau step */ + DCN(0, 1) = CN(0, 1, k) - CN(0, 0, k); + DCN(0, 0) = vs * CN(0, 0, k) + v * CN(0, 1, k); + for (i = 0; i < uorder - 1; i++) { + /* for the derivative in v */ + DCN(i + 1, 1) = CN(i + 1, 1, k) - CN(i + 1, 0, k); + DCN(i, 1) = us * DCN(i, 1) + u * DCN(i + 1, 1); + + /* for the `point' */ + DCN(i + 1, 0) = vs * CN(i + 1, 0, k) + v * CN(i + 1, 1, k); + DCN(i, 0) = us * DCN(i, 0) + u * DCN(i + 1, 0); + } + + /* remaining linear de Casteljau steps until the second last step */ + for (h = minorder; h < uorder - 1; h++) + for (i = 0; i < uorder - h; i++) { + /* for the derivative in v */ + DCN(i, 1) = us * DCN(i, 1) + u * DCN(i + 1, 1); + + /* for the `point' */ + DCN(i, 0) = us * DCN(i, 0) + u * DCN(i + 1, 0); + } + + /* derivative direction in u */ + du[k] = DCN(1, 0) - DCN(0, 0); + + /* derivative direction in v */ + dv[k] = us * DCN(0, 1) + u * DCN(1, 1); + + /* last linear de Casteljau step */ + out[k] = us * DCN(0, 0) + u * DCN(1, 0); + } + } + } else if (uorder == vorder) { + for (k = 0; k < dim; k++) { + /* first bilinear de Casteljau step */ + for (i = 0; i < uorder - 1; i++) { + DCN(i, 0) = us * CN(i, 0, k) + u * CN(i + 1, 0, k); + for (j = 0; j < vorder - 1; j++) { + DCN(i, j + 1) = us * CN(i, j + 1, k) + u * CN(i + 1, j + 1, k); + DCN(i, j) = vs * DCN(i, j) + v * DCN(i, j + 1); + } + } + + /* remaining bilinear de Casteljau steps until the second last step */ + for (h = 2; h < minorder - 1; h++) { + for (i = 0; i < uorder - h; i++) { + DCN(i, 0) = us * DCN(i, 0) + u * DCN(i + 1, 0); + for (j = 0; j < vorder - h; j++) { + DCN(i, j + 1) = us * DCN(i, j + 1) + u * DCN(i + 1, j + 1); + DCN(i, j) = vs * DCN(i, j) + v * DCN(i, j + 1); + } + } + } + + /* derivative direction in u */ + du[k] = vs * (DCN(1, 0) - DCN(0, 0)) + v * (DCN(1, 1) - DCN(0, 1)); + + /* derivative direction in v */ + dv[k] = us * (DCN(0, 1) - DCN(0, 0)) + u * (DCN(1, 1) - DCN(1, 0)); + + /* last bilinear de Casteljau step */ + out[k] = us * (vs * DCN(0, 0) + v * DCN(0, 1)) + + u * (vs * DCN(1, 0) + v * DCN(1, 1)); + } + } else if (minorder == uorder) { + for (k = 0; k < dim; k++) { + /* first bilinear de Casteljau step */ + for (i = 0; i < uorder - 1; i++) { + DCN(i, 0) = us * CN(i, 0, k) + u * CN(i + 1, 0, k); + for (j = 0; j < vorder - 1; j++) { + DCN(i, j + 1) = us * CN(i, j + 1, k) + u * CN(i + 1, j + 1, k); + DCN(i, j) = vs * DCN(i, j) + v * DCN(i, j + 1); + } + } + + /* remaining bilinear de Casteljau steps until the second last step */ + for (h = 2; h < minorder - 1; h++) { + for (i = 0; i < uorder - h; i++) { + DCN(i, 0) = us * DCN(i, 0) + u * DCN(i + 1, 0); + for (j = 0; j < vorder - h; j++) { + DCN(i, j + 1) = us * DCN(i, j + 1) + u * DCN(i + 1, j + 1); + DCN(i, j) = vs * DCN(i, j) + v * DCN(i, j + 1); + } + } + } + + /* last bilinear de Casteljau step */ + DCN(2, 0) = DCN(1, 0) - DCN(0, 0); + DCN(0, 0) = us * DCN(0, 0) + u * DCN(1, 0); + for (j = 0; j < vorder - 1; j++) { + /* for the derivative in u */ + DCN(2, j + 1) = DCN(1, j + 1) - DCN(0, j + 1); + DCN(2, j) = vs * DCN(2, j) + v * DCN(2, j + 1); + + /* for the `point' */ + DCN(0, j + 1) = us * DCN(0, j + 1) + u * DCN(1, j + 1); + DCN(0, j) = vs * DCN(0, j) + v * DCN(0, j + 1); + } + + /* remaining linear de Casteljau steps until the second last step */ + for (h = minorder; h < vorder - 1; h++) { + for (j = 0; j < vorder - h; j++) { + /* for the derivative in u */ + DCN(2, j) = vs * DCN(2, j) + v * DCN(2, j + 1); + + /* for the `point' */ + DCN(0, j) = vs * DCN(0, j) + v * DCN(0, j + 1); + } + } + + /* derivative direction in v */ + dv[k] = DCN(0, 1) - DCN(0, 0); + + /* derivative direction in u */ + du[k] = vs * DCN(2, 0) + v * DCN(2, 1); + + /* last linear de Casteljau step */ + out[k] = vs * DCN(0, 0) + v * DCN(0, 1); + } + } else { /* minorder == vorder */ + + for (k = 0; k < dim; k++) { + /* first bilinear de Casteljau step */ + for (i = 0; i < uorder - 1; i++) { + DCN(i, 0) = us * CN(i, 0, k) + u * CN(i + 1, 0, k); + for (j = 0; j < vorder - 1; j++) { + DCN(i, j + 1) = us * CN(i, j + 1, k) + u * CN(i + 1, j + 1, k); + DCN(i, j) = vs * DCN(i, j) + v * DCN(i, j + 1); + } + } + + /* remaining bilinear de Casteljau steps until the second last step */ + for (h = 2; h < minorder - 1; h++) { + for (i = 0; i < uorder - h; i++) { + DCN(i, 0) = us * DCN(i, 0) + u * DCN(i + 1, 0); + for (j = 0; j < vorder - h; j++) { + DCN(i, j + 1) = us * DCN(i, j + 1) + u * DCN(i + 1, j + 1); + DCN(i, j) = vs * DCN(i, j) + v * DCN(i, j + 1); + } + } + } + + /* last bilinear de Casteljau step */ + DCN(0, 2) = DCN(0, 1) - DCN(0, 0); + DCN(0, 0) = vs * DCN(0, 0) + v * DCN(0, 1); + for (i = 0; i < uorder - 1; i++) { + /* for the derivative in v */ + DCN(i + 1, 2) = DCN(i + 1, 1) - DCN(i + 1, 0); + DCN(i, 2) = us * DCN(i, 2) + u * DCN(i + 1, 2); + + /* for the `point' */ + DCN(i + 1, 0) = vs * DCN(i + 1, 0) + v * DCN(i + 1, 1); + DCN(i, 0) = us * DCN(i, 0) + u * DCN(i + 1, 0); + } + + /* remaining linear de Casteljau steps until the second last step */ + for (h = minorder; h < uorder - 1; h++) { + for (i = 0; i < uorder - h; i++) { + /* for the derivative in v */ + DCN(i, 2) = us * DCN(i, 2) + u * DCN(i + 1, 2); + + /* for the `point' */ + DCN(i, 0) = us * DCN(i, 0) + u * DCN(i + 1, 0); + } + } + + /* derivative direction in u */ + du[k] = DCN(1, 0) - DCN(0, 0); + + /* derivative direction in v */ + dv[k] = us * DCN(0, 2) + u * DCN(1, 2); + + /* last linear de Casteljau step */ + out[k] = us * DCN(0, 0) + u * DCN(1, 0); + } + } +#undef DCN +#undef CN +} + +/* + * Do one-time initialization for evaluators. + */ +void _math_init_eval() { + GLuint i; + + /* KW: precompute 1/x for useful x. + */ + for (i = 1; i < MAX_EVAL_ORDER; i++) + inv_tab[i] = 1.0F / i; + + init_done = true; +} diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/math/eval.h b/Projects/Android/jni/SupportLibs/gl4es/src/gl/math/eval.h new file mode 100644 index 0000000..ccf46bf --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/math/eval.h @@ -0,0 +1,103 @@ + +/* + * Mesa 3-D graphics library + * Version: 3.5 + * + * Copyright (C) 1999-2001 Brian Paul All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#ifndef _M_EVAL_H +#define _M_EVAL_H + +#include "../gl4es.h" + +void _math_init_eval( void ); + + +/* + * Horner scheme for Bezier curves + * + * Bezier curves can be computed via a Horner scheme. + * Horner is numerically less stable than the de Casteljau + * algorithm, but it is faster. For curves of degree n + * the complexity of Horner is O(n) and de Casteljau is O(n^2). + * Since stability is not important for displaying curve + * points I decided to use the Horner scheme. + * + * A cubic Bezier curve with control points b0, b1, b2, b3 can be + * written as + * + * (([3] [3] ) [3] ) [3] + * c(t) = (([0]*s*b0 + [1]*t*b1)*s + [2]*t^2*b2)*s + [3]*t^2*b3 + * + * [n] + * where s=1-t and the binomial coefficients [i]. These can + * be computed iteratively using the identity: + * + * [n] [n ] [n] + * [i] = (n-i+1)/i * [i-1] and [0] = 1 + */ + + +void +_math_horner_bezier_curve(const GLfloat *cp, GLfloat *out, GLfloat t, + GLuint dim, GLuint order); + + +/* + * Tensor product Bezier surfaces + * + * Again the Horner scheme is used to compute a point on a + * TP Bezier surface. First a control polygon for a curve + * on the surface in one parameter direction is computed, + * then the point on the curve for the other parameter + * direction is evaluated. + * + * To store the curve control polygon additional storage + * for max(uorder,vorder) points is needed in the + * control net cn. + */ + +void +_math_horner_bezier_surf(GLfloat *cn, GLfloat *out, GLfloat u, GLfloat v, + GLuint dim, GLuint uorder, GLuint vorder); + + +/* + * The direct de Casteljau algorithm is used when a point on the + * surface and the tangent directions spanning the tangent plane + * should be computed (this is needed to compute normals to the + * surface). In this case the de Casteljau algorithm approach is + * nicer because a point and the partial derivatives can be computed + * at the same time. To get the correct tangent length du and dv + * must be multiplied with the (u2-u1)/uorder-1 and (v2-v1)/vorder-1. + * Since only the directions are needed, this scaling step is omitted. + * + * De Casteljau needs additional storage for uorder*vorder + * values in the control net cn. + */ + +void +_math_de_casteljau_surf(GLfloat *cn, GLfloat *out, GLfloat *du, GLfloat *dv, + GLfloat u, GLfloat v, GLuint dim, + GLuint uorder, GLuint vorder); + + +#endif diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/matrix.c b/Projects/Android/jni/SupportLibs/gl4es/src/gl/matrix.c new file mode 100644 index 0000000..4dd9ba5 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/matrix.c @@ -0,0 +1,367 @@ +#include "matrix.h" + +#include "../glx/hardext.h" +#include "debug.h" +#include "fpe.h" +#include "gl4es.h" +#include "glstate.h" +#include "init.h" +#include "loader.h" + +//#define DEBUG +#ifdef DEBUG +#define DBG(a) a +#else +#define DBG(a) +#endif + +void alloc_matrix(matrixstack_t **matrixstack, int depth) { + *matrixstack = (matrixstack_t*)malloc(sizeof(matrixstack_t)); + (*matrixstack)->top = 0; + (*matrixstack)->identity = 0; + (*matrixstack)->stack = (GLfloat*)malloc(sizeof(GLfloat)*depth*16); +} + +#define TOP(A) (glstate->A->stack+(glstate->A->top*16)) + +static GLfloat* update_current_mat() { + switch(glstate->matrix_mode) { + case GL_MODELVIEW: + return TOP(modelview_matrix); + case GL_PROJECTION: + return TOP(projection_matrix); + case GL_TEXTURE: + return TOP(texture_matrix[glstate->texture.active]); + } + return NULL; +} + +static int update_current_identity(int I) { + switch(glstate->matrix_mode) { + case GL_MODELVIEW: + return glstate->modelview_matrix->identity = (I)?1:is_identity(TOP(modelview_matrix)); + case GL_PROJECTION: + return glstate->projection_matrix->identity = (I)?1:is_identity(TOP(projection_matrix)); + case GL_TEXTURE: + return glstate->texture_matrix[glstate->texture.active]->identity = (I)?1:is_identity(TOP(texture_matrix[glstate->texture.active])); + } + return 0; +} + +static int send_to_hardware() { + if(hardext.esversion>1) + return 0; + switch(glstate->matrix_mode) { + case GL_PROJECTION: + return 1; + case GL_MODELVIEW: + return 1; + case GL_TEXTURE: + return (globals4es.texmat)?1:0; + } + return 0; +} + +void init_matrix(glstate_t* glstate) { +DBG(printf("init_matrix(%p)\n", glstate);) + alloc_matrix(&glstate->projection_matrix, MAX_STACK_PROJECTION); + set_identity(TOP(projection_matrix)); + glstate->projection_matrix->identity = 1; + alloc_matrix(&glstate->modelview_matrix, MAX_STACK_MODELVIEW); + set_identity(TOP(modelview_matrix)); + glstate->modelview_matrix->identity = 1; + glstate->texture_matrix = (matrixstack_t**)malloc(sizeof(matrixstack_t*)*MAX_TEX); + set_identity(glstate->mvp_matrix); + glstate->mvp_matrix_dirty = 0; + set_identity(glstate->inv_mv_matrix); + glstate->inv_mv_matrix_dirty = 0; + // no identity function for 3x3 matrix + memset(glstate->normal_matrix, 0, 9*sizeof(GLfloat)); + glstate->normal_matrix[0] = glstate->normal_matrix[4] = glstate->normal_matrix[8] = 1.0f; + glstate->normal_matrix_dirty = 1; + for (int i=0; itexture_matrix[i], MAX_STACK_TEXTURE); + set_identity(TOP(texture_matrix[i])); + glstate->texture_matrix[i]->identity = 1; + } +} + +void set_fpe_textureidentity() { + if(glstate->texture_matrix[glstate->texture.active]->identity) // inverted in fpe flags + glstate->fpe_state->textmat &= ~(1<texture.active); + else + glstate->fpe_state->textmat |= 1<texture.active; +} + +void gl4es_glMatrixMode(GLenum mode) { +DBG(printf("glMatrixMode(%s), list=%p\n", PrintEnum(mode), glstate->list.active);) + noerrorShim(); + if (glstate->list.active && glstate->list.pending && glstate->matrix_mode==GL_MODELVIEW && mode==GL_MODELVIEW) { + return; // nothing to do... + } + PUSH_IF_COMPILING(glMatrixMode); + + if(!(mode==GL_MODELVIEW || mode==GL_PROJECTION || mode==GL_TEXTURE)) { + errorShim(GL_INVALID_ENUM); + return; + } + if(glstate->matrix_mode != mode) { + glstate->matrix_mode = mode; + LOAD_GLES_FPE(glMatrixMode); + gles_glMatrixMode(mode); + } +} + +void gl4es_glPushMatrix() { +DBG(printf("glPushMatrix(), list=%p\n", glstate->list.active);) + if (glstate->list.active && !glstate->list.pending) { + PUSH_IF_COMPILING(glPushMatrix); + } + // get matrix mode + GLint matrix_mode = glstate->matrix_mode; + noerrorShim(); + // go... + switch(matrix_mode) { + #define P(A, B) if(glstate->A->top+1A->top++; \ + } else errorShim(GL_STACK_OVERFLOW) + case GL_PROJECTION: + P(projection_matrix, PROJECTION); + break; + case GL_MODELVIEW: + P(modelview_matrix, MODELVIEW); + break; + case GL_TEXTURE: + P(texture_matrix[glstate->texture.active], TEXTURE); + break; + #undef P + default: + //Warning? + errorShim(GL_INVALID_OPERATION); + //LOGE("LIBGL: PushMatrix with Unrecognise matrix mode (0x%04X)\n", matrix_mode); + //gles_glPushMatrix(); + } +} + +void gl4es_glPopMatrix() { +DBG(printf("glPopMatrix(), list=%p\n", glstate->list.active);) + if (glstate->list.active + && !(glstate->list.compiling) + && (globals4es.beginend) + && glstate->matrix_mode==GL_MODELVIEW + && !(glstate->polygon_mode==GL_LINE) + && glstate->list.pending) { + // check if pop'd matrix is the same as actual... + if(memcmp(TOP(modelview_matrix)-16, TOP(modelview_matrix), 16*sizeof(GLfloat))==0) { + --glstate->modelview_matrix->top; + return; + } + } + PUSH_IF_COMPILING(glPopMatrix); + // get matrix mode + GLint matrix_mode = glstate->matrix_mode; + // go... + noerrorShim(); + switch(matrix_mode) { + #define P(A) if(glstate->A->top) { \ + --glstate->A->top; \ + glstate->A->identity = is_identity(update_current_mat()); \ + if (send_to_hardware()) {LOAD_GLES(glLoadMatrixf); gles_glLoadMatrixf(update_current_mat()); } \ + } else errorShim(GL_STACK_UNDERFLOW) + case GL_PROJECTION: + P(projection_matrix); + glstate->mvp_matrix_dirty = 1; + break; + case GL_MODELVIEW: + P(modelview_matrix); + glstate->mvp_matrix_dirty = 1; + glstate->inv_mv_matrix_dirty = 1; + glstate->normal_matrix_dirty = 1; + break; + case GL_TEXTURE: + P(texture_matrix[glstate->texture.active]); + if(glstate->fpe_state) + set_fpe_textureidentity(); + break; + #undef P + + default: + //Warning? + errorShim(GL_INVALID_OPERATION); + //LOGE("LIBGL: PopMatrix with Unrecognise matrix mode (0x%04X)\n", matrix_mode); + //gles_glPopMatrix(); + } +} + +void gl4es_glLoadMatrixf(const GLfloat * m) { +DBG(printf("glLoadMatrix(%f, %f, %f, %f, %f, %f, %f...), list=%p\n", m[0], m[1], m[2], m[3], m[4], m[5], m[6], glstate->list.active);) + if (glstate->list.active) { + if(glstate->list.pending) flush(); + else { + NewStage(glstate->list.active, STAGE_MATRIX); + glstate->list.active->matrix_op = 1; + memcpy(glstate->list.active->matrix_val, m, 16*sizeof(GLfloat)); + return; + } + } + memcpy(update_current_mat(), m, 16*sizeof(GLfloat)); + const int id = update_current_identity(0); + if(glstate->matrix_mode==GL_MODELVIEW) + glstate->normal_matrix_dirty = glstate->inv_mv_matrix_dirty = 1; + if(glstate->matrix_mode==GL_MODELVIEW || glstate->matrix_mode==GL_PROJECTION) + glstate->mvp_matrix_dirty = 1; + else if(glstate->fpe_state) + set_fpe_textureidentity(); + if(send_to_hardware()) { + LOAD_GLES(glLoadMatrixf); + LOAD_GLES(glLoadIdentity); + if(id) gles_glLoadIdentity(); // in case the driver as some special optimisations + else gles_glLoadMatrixf(m); + } +} + +void gl4es_glMultMatrixf(const GLfloat * m) { +DBG(printf("glMultMatrix(%f, %f, %f, %f, %f, %f, %f...), list=%p\n", m[0], m[1], m[2], m[3], m[4], m[5], m[6], glstate->list.active);) + if (glstate->list.active) { + if(glstate->list.pending) flush(); + else { + if(glstate->list.active->stage == STAGE_MATRIX) { + // multiply the matrix mith the current one.... + matrix_mul(glstate->list.active->matrix_val, m, glstate->list.active->matrix_val); + return; + } + NewStage(glstate->list.active, STAGE_MATRIX); + glstate->list.active->matrix_op = 2; + memcpy(glstate->list.active->matrix_val, m, 16*sizeof(GLfloat)); + return; + } + } + GLfloat *current_mat = update_current_mat(); + matrix_mul(current_mat, m, current_mat); + const int id = update_current_identity(0); + if(glstate->matrix_mode==GL_MODELVIEW) + glstate->normal_matrix_dirty = glstate->inv_mv_matrix_dirty = 1; + if(glstate->matrix_mode==GL_MODELVIEW || glstate->matrix_mode==GL_PROJECTION) + glstate->mvp_matrix_dirty = 1; + else if(glstate->fpe_state) + set_fpe_textureidentity(); + DBG(printf(" => (%f, %f, %f, %f, %f, %f, %f...)\n", current_mat[0], current_mat[1], current_mat[2], current_mat[3], current_mat[4], current_mat[5], current_mat[6]);) + if(send_to_hardware()) { + LOAD_GLES(glLoadMatrixf); + LOAD_GLES(glLoadIdentity); + if(id) gles_glLoadIdentity(); // in case the driver as some special optimisations + else gles_glLoadMatrixf(current_mat); + } +} + +void gl4es_glLoadIdentity() { +DBG(printf("glLoadIdentity(), list=%p\n", glstate->list.active);) + if (glstate->list.active) { + if(glstate->list.pending) flush(); + else { + NewStage(glstate->list.active, STAGE_MATRIX); + glstate->list.active->matrix_op = 1; + set_identity(glstate->list.active->matrix_val); + return; + } + } + set_identity(update_current_mat()); + update_current_identity(1); + if(glstate->matrix_mode==GL_MODELVIEW) + glstate->normal_matrix_dirty = glstate->inv_mv_matrix_dirty = 1; + if(glstate->matrix_mode==GL_MODELVIEW || glstate->matrix_mode==GL_PROJECTION) + glstate->mvp_matrix_dirty = 1; + else if(glstate->fpe_state) + set_fpe_textureidentity(); + if(send_to_hardware()) { + LOAD_GLES(glLoadIdentity); + gles_glLoadIdentity(); + } +} + +void gl4es_glTranslatef(GLfloat x, GLfloat y, GLfloat z) { +DBG(printf("glTranslatef(%f, %f, %f), list=%p\n", x, y, z, glstate->list.active);) + // create a translation matrix than multiply it... + GLfloat tmp[16]; + set_identity(tmp); + tmp[12+0] = x; + tmp[12+1] = y; + tmp[12+2] = z; + gl4es_glMultMatrixf(tmp); +} + +void gl4es_glScalef(GLfloat x, GLfloat y, GLfloat z) { +DBG(printf("glScalef(%f, %f, %f), list=%p\n", x, y, z, glstate->list.active);) + // create a scale matrix than multiply it... + GLfloat tmp[16]; + memset(tmp, 0, 16*sizeof(GLfloat)); + tmp[0+0] = x; + tmp[1+4] = y; + tmp[2+8] = z; + tmp[3+12] = 1.0f; + gl4es_glMultMatrixf(tmp); +} + +void gl4es_glRotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z) { +DBG(printf("glRotatef(%f, %f, %f, %f), list=%p\n", angle, x, y, z, glstate->list.active);) + // create a rotation matrix than multiply it... + GLfloat tmp[16]; + memset(tmp, 0, 16*sizeof(GLfloat)); + if((x==0 && y==0 && z==0) || angle==0) + return; // nothing to do + // normalize x y z + GLfloat l = 1.0f/sqrtf(x*x+y*y+z*z); + x=x*l; y=y*l; z=z*l; + // calculate sin/cos + angle*=3.1415926535f/180.f; + const GLfloat s=sinf(angle); + const GLfloat c=cosf(angle); + const GLfloat c1 = 1-c; + //build the matrix + tmp[0+0] = x*x*c1+c; tmp[0+4] = x*y*c1-z*s; tmp[0+8] = x*z*c1+y*s; + tmp[1+0] = y*x*c1+z*s; tmp[1+4] = y*y*c1+c; tmp[1+8] = y*z*c1-x*s; + tmp[2+0] = x*z*c1-y*s; tmp[2+4] = y*z*c1+x*s; tmp[2+8] = z*z*c1+c; + + tmp[3+12] = 1.0f; + // done... + gl4es_glMultMatrixf(tmp); +} + +void gl4es_glOrthof(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat nearVal, GLfloat farVal) { +DBG(printf("glOrthof(%f, %f, %f, %f, %f, %f), list=%p\n", left, right, top, bottom, nearVal, farVal, glstate->list.active);) + GLfloat tmp[16]; + memset(tmp, 0, 16*sizeof(GLfloat)); + + tmp[0+0] = 2.0f/(right-left); tmp[0+12] = -(right+left)/(right-left); + tmp[1+4] = 2.0f/(top-bottom); tmp[1+12] = -(top+bottom)/(top-bottom); + tmp[2+8] =-2.0f/(farVal-nearVal); tmp[2+12] = -(farVal+nearVal)/(farVal-nearVal); + tmp[3+12] = 1.0f; + + gl4es_glMultMatrixf(tmp); +} + +void gl4es_glFrustumf(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat nearVal, GLfloat farVal) { +DBG(printf("glFrustumf(%f, %f, %f, %f, %f, %f) list=%p\n", left, right, top, bottom, nearVal, farVal, glstate->list.active);) + GLfloat tmp[16]; + memset(tmp, 0, 16*sizeof(GLfloat)); + + tmp[0+0] = 2.0f*nearVal/(right-left); tmp[0+8] = (right+left)/(right-left); + tmp[1+4] = 2.0f*nearVal/(top-bottom); tmp[1+8] = (top+bottom)/(top-bottom); + tmp[2+8] =-(farVal+nearVal)/(farVal-nearVal); tmp[2+12] =-2.0f*farVal*nearVal/(farVal-nearVal); + tmp[3+8] = -1.0f; + + gl4es_glMultMatrixf(tmp); +} + +void glMatrixMode(GLenum mode) AliasExport("gl4es_glMatrixMode"); +void glPushMatrix() AliasExport("gl4es_glPushMatrix"); +void glPopMatrix() AliasExport("gl4es_glPopMatrix"); +void glLoadMatrixf(const GLfloat * m) AliasExport("gl4es_glLoadMatrixf"); +void glMultMatrixf(const GLfloat * m) AliasExport("gl4es_glMultMatrixf"); +void glLoadIdentity() AliasExport("gl4es_glLoadIdentity"); +void glTranslatef(GLfloat x, GLfloat y, GLfloat z) AliasExport("gl4es_glTranslatef"); +void glScalef(GLfloat x, GLfloat y, GLfloat z) AliasExport("gl4es_glScalef"); +void glRotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z) AliasExport("gl4es_glRotatef"); +void glOrthof(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat nearVal, GLfloat farVal) AliasExport("gl4es_glOrthof"); +void glFrustumf(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat nearVal, GLfloat farVal) AliasExport("gl4es_glFrustumf"); diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/matrix.h b/Projects/Android/jni/SupportLibs/gl4es/src/gl/matrix.h new file mode 100644 index 0000000..6e2f84c --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/matrix.h @@ -0,0 +1,59 @@ +#ifndef _GL4ES_MATRIX_H_ +#define _GL4ES_MATRIX_H_ + +#include "gl4es.h" +#include "gles.h" +#include "glstate.h" +#include "list.h" +#include "matvec.h" + +void gl4es_glMatrixMode(GLenum mode); +void gl4es_glPushMatrix(); +void gl4es_glPopMatrix(); +void gl4es_glLoadMatrixf(const GLfloat * m); +void gl4es_glMultMatrixf(const GLfloat * m); +void gl4es_glLoadIdentity(); +void gl4es_glTranslatef(GLfloat x, GLfloat y, GLfloat z); +void gl4es_glScalef(GLfloat x, GLfloat y, GLfloat z); +void gl4es_glRotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z); +void gl4es_glOrthof(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat nearVal, GLfloat farVal); +void gl4es_glFrustumf(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat nearVal, GLfloat farVal); + +static inline GLfloat* getTexMat(int tmu) { + return glstate->texture_matrix[tmu]->stack+glstate->texture_matrix[tmu]->top*16; +} + +static inline GLfloat* getMVMat() { + return glstate->modelview_matrix->stack+glstate->modelview_matrix->top*16; +} + +static inline GLfloat* getInvMVMat() { + if(glstate->inv_mv_matrix_dirty) { + matrix_inverse(glstate->modelview_matrix->stack+glstate->modelview_matrix->top*16, glstate->inv_mv_matrix); + glstate->inv_mv_matrix_dirty = 0; + } + return glstate->inv_mv_matrix; +} +static inline GLfloat* getNormalMat() { + if(glstate->normal_matrix_dirty) { + matrix_inverse3_transpose(glstate->modelview_matrix->stack+glstate->modelview_matrix->top*16, glstate->normal_matrix); + glstate->normal_matrix_dirty = 0; + } + return glstate->normal_matrix; +} + +static inline GLfloat* getPMat() { + return glstate->projection_matrix->stack+glstate->projection_matrix->top*16; +} + +static inline GLfloat* getMVPMat() +{ + if(glstate->mvp_matrix_dirty) { + matrix_mul(getPMat(), getMVMat(), glstate->mvp_matrix); + glstate->mvp_matrix_dirty = 0; + } + return glstate->mvp_matrix; +} + + +#endif // _GL4ES_MATRIX_H_ diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/matvec.c b/Projects/Android/jni/SupportLibs/gl4es/src/gl/matvec.c new file mode 100644 index 0000000..2c91f83 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/matvec.c @@ -0,0 +1,353 @@ +#include "matvec.h" + +#include + +float FASTMATH dot(const float *a, const float *b) { + return a[0]*b[0] + a[1]*b[1] + a[2]*b[2]; +} + +float FASTMATH dot4(const float *a, const float *b) { +#ifdef __ARM_NEON__ + register float ret; + asm volatile ( + "vld1.f32 {d0-d1}, [%1] \n" //q0 = a(0..3) + "vld1.f32 {d2-d3}, [%2] \n" //q1 = b(0..3) + "vmul.f32 q0, q0, q1 \n" //q0 = a(0)*b(0),a(1)*b(1),a(2)*b(2),a(3)*b(3) + "vadd.f32 d0, d0, d1 \n" //d0 = a(0)*b(0)+a(2)*b(2),a(1)*b(1)+a(3)*b(3) + "vpadd.f32 d0,d0 \n" //d0 = a(0)*b(0)+a(2)*b(2)+a(1)*b(1)+a(3)*b(3),a(0)*b(0)+a(2)*b(2)+a(1)*b(1)+a(3)*b(3) + "vmov.f32 %0, s0 \n" + :"=w"(ret): "r"(a), "r"(b) + : "q0", "q1" + ); + return ret; +#else + return a[0]*b[0] + a[1]*b[1] + a[2]*b[2] + a[3]*b[3]; +#endif +} + +float cross3(const float *a, const float *b, float* c) { + //TODO Neonize? Cross product doesn't seems NEON friendly, and this is not much used. + c[0] = a[1]*b[2] - a[2]*b[1]; + c[1] = a[3]*b[0] - a[0]*b[3]; + c[2] = a[0]*b[1] - a[1]*b[0]; +} + +void matrix_vector(const float *a, const float *b, float *c) { +#ifdef __ARM_NEON__ + const float* a1 = a+8; + asm volatile ( + "vld4.f32 {d0,d2,d4,d6}, [%1] \n" + "vld4.f32 {d1,d3,d5,d7}, [%2] \n" // q0-q3 = a(0,4,8,12/1,5,9,13/2,6,10,14/3,7,11,15) + "vld1.f32 {q4}, [%3] \n" // q4 = b + "vmul.f32 q0, q0, d8[0] \n" // q0 = a(0,4,8,12)*b[0] + "vmla.f32 q0, q1, d8[1] \n" // q0 = q0 + a(1,5,9,13)*b[1] + "vmla.f32 q0, q2, d9[0] \n" // q0 = q0 + a(2,6,10,14)*b[2] + "vmla.f32 q0, q3, d9[1] \n" // q0 = q0 + a(3,7,11,15)*b[3] + "vst1.f32 {q0}, [%0] \n" + ::"r"(c), "r"(a), "r"(a1), "r"(b) + : "q0", "q1", "q2", "q3", "q4", "memory" + ); +#else + c[0] = a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3]; + c[1] = a[4] * b[0] + a[5] * b[1] + a[6] * b[2] + a[7] * b[3]; + c[2] = a[8] * b[0] + a[9] * b[1] + a[10] * b[2] + a[11] * b[3]; + c[3] = a[12] * b[0] + a[13] * b[1] + a[14] * b[2] + a[15] * b[3]; +#endif +} + +void vector_matrix(const float *a, const float *b, float *c) { +#ifdef __ARM_NEON__ + const float* b2=b+4; + const float* b3=b+8; + const float* b4=b+12; + asm volatile ( + "vld1.f32 {q0}, [%1] \n" // %q0 = a(0..3) + "vld1.f32 {q1}, [%2] \n" // %q1 = b(0..3) + "vmul.f32 q1, q1, d0[0] \n" // %q1 = b(0..3)*a[0] + "vld1.f32 {q2}, [%3] \n" // %q2 = b(4..7) + "vmla.f32 q1, q2, d0[1] \n" // %q1 = %q1 + b(4..7)*a[1] + "vld1.f32 {q2}, [%4] \n" // %q2 = b(8..11) + "vmla.f32 q1, q2, d1[0] \n" // %q1 = %q1 + b(8..11)*a[2] + "vld1.f32 {q2}, [%5] \n" // %q2 = b(12..15) + "vmla.f32 q1, q2, d1[1] \n" // %q1 = %q1 + b(12..15)*a[3] + "vst1.f32 {q1}, [%0] \n" + ::"r"(c), "r"(a), "r"(b), "r"(b2), "r"(b3), "r"(b4) + : "%2", "q0", "q1", "q2", "memory" + ); +#else + const float a0=a[0], a1=a[1], a2=a[2], a3=a[3]; + c[0] = a0 * b[0] + a1 * b[4] + a2 * b[8] + a3 * b[12]; + c[1] = a0 * b[1] + a1 * b[5] + a2 * b[9] + a3 * b[13]; + c[2] = a0 * b[2] + a1 * b[6] + a2 * b[10] + a3 * b[14]; + c[3] = a0 * b[3] + a1 * b[7] + a2 * b[11] + a3 * b[15]; +#endif +} + +void vector3_matrix(const float *a, const float *b, float *c) { +#ifdef __ARM_NEON__ + const float* b2=b+4; + const float* b3=b+8; + const float* b4=b+12; + asm volatile ( + //"vld1.f32 {q0}, [%1] \n" // %q0 = a(0..2) + "vld1.32 {d0}, [%1] \n" + "flds s2, [%1, #8] \n" + "vsub.f32 s3, s3, s3 \n" + "vld1.f32 {q1}, [%2] \n" // %q1 = b(0..3) + "vmul.f32 q1, q1, d0[0] \n" // %q1 = b(0..3)*a[0] + "vld1.f32 {q2}, [%3] \n" // %q2 = b(4..7) + "vmla.f32 q1, q2, d0[1] \n" // %q1 = %q1 + b(4..7)*a[1] + "vld1.f32 {q2}, [%4] \n" // %q2 = b(8..11) + "vmla.f32 q1, q2, d1[0] \n" // %q1 = %q1 + b(8..11)*a[2] + "vld1.f32 {q2}, [%5] \n" // %q2 = b(12..15) + "vadd.f32 q1, q1, q2 \n" // %q1 = %q1 + b(12..15) + "vst1.f32 {q1}, [%0] \n" + ::"r"(c), "r"(a), "r"(b), "r"(b2), "r"(b3), "r"(b4) + : "q0", "q1", "q2", "memory" + ); +#else + c[0] = a[0] * b[0] + a[1] * b[4] + a[2] * b[8] + b[12]; + c[1] = a[0] * b[1] + a[1] * b[5] + a[2] * b[9] + b[13]; + c[2] = a[0] * b[2] + a[1] * b[6] + a[2] * b[10] + b[14]; + c[3] = a[0] * b[3] + a[1] * b[7] + a[2] * b[11] + b[15]; +#endif +} + +void vector3_matrix4(const float *a, const float *b, float *c) { + c[0] = a[0] * b[0] + a[1] * b[4] + a[2] * b[8]; + c[1] = a[0] * b[1] + a[1] * b[5] + a[2] * b[9]; + c[2] = a[0] * b[2] + a[1] * b[6] + a[2] * b[10]; +} + +void vector3_matrix3(const float *a, const float *b, float *c) { + c[0] = a[0] * b[0] + a[1] * b[3] + a[2] * b[6]; + c[1] = a[0] * b[1] + a[1] * b[4] + a[2] * b[7]; + c[2] = a[0] * b[2] + a[1] * b[5] + a[2] * b[8]; +} + +void vector_normalize(float *a) { +#ifdef __ARM_NEON__ + asm volatile ( + "vld1.32 {d4}, [%0] \n\t" //d4={x0,y0} + "flds s10, [%0, #8] \n\t" //d5[0]={z0} + "vsub.f32 s11, s11, s11 \n\t" + + "vmul.f32 d0, d4, d4 \n\t" //d0= d4*d4 + "vpadd.f32 d0, d0 \n\t" //d0 = d[0] + d[1] + "vmla.f32 d0, d5, d5 \n\t" //d0 = d0 + d5*d5 + + "vmov.f32 d1, d0 \n\t" //d1 = d0 + "vrsqrte.f32 d0, d0 \n\t" //d0 = ~ 1.0 / sqrt(d0) + "vmul.f32 d2, d0, d1 \n\t" //d2 = d0 * d1 + "vrsqrts.f32 d3, d2, d0 \n\t" //d3 = (3 - d0 * d2) / 2 + "vmul.f32 d0, d0, d3 \n\t" //d0 = d0 * d3 +/* "vmul.f32 d2, d0, d1 \n\t" //d2 = d0 * d1 + "vrsqrts.f32 d3, d2, d0 \n\t" //d4 = (3 - d0 * d3) / 2 + "vmul.f32 d0, d0, d3 \n\t" //d0 = d0 * d4 */ // 1 iteration should be enough + + "vmul.f32 q2, q2, d0[0] \n\t" //d0= d2*d4 + "vst1.32 {d4}, [%0] \n\t" // + "fsts s10, [%0, #8] \n\t" // + + :"+&r"(a): + : "d0", "d1", "d2", "d3", "d4", "d5", "memory" + ); +#else + float det=1.0f/sqrtf(a[0]*a[0]+a[1]*a[1]+a[2]*a[2]); + a[0]*=det; + a[1]*=det; + a[2]*=det; +#endif +} + +void vector4_normalize(float *a) { +#ifdef __ARM_NEON__ + asm volatile ( + "vld1.32 {q2}, [%0] \n\t" //q2={x0,y0,z0,00} + + "vmul.f32 d0, d4, d4 \n\t" //d0= d4*d4 + "vpadd.f32 d0, d0 \n\t" //d0 = d[0] + d[1] + "vmla.f32 d0, d5, d5 \n\t" //d0 = d0 + d5*d5 + + "vmov.f32 d1, d0 \n\t" //d1 = d0 + "vrsqrte.f32 d0, d0 \n\t" //d0 = ~ 1.0 / sqrt(d0) + "vmul.f32 d2, d0, d1 \n\t" //d2 = d0 * d1 + "vrsqrts.f32 d3, d2, d0 \n\t" //d3 = (3 - d0 * d2) / 2 + "vmul.f32 d0, d0, d3 \n\t" //d0 = d0 * d3 +/* "vmul.f32 d2, d0, d1 \n\t" //d2 = d0 * d1 + "vrsqrts.f32 d3, d2, d0 \n\t" //d4 = (3 - d0 * d3) / 2 + "vmul.f32 d0, d0, d3 \n\t" //d0 = d0 * d4 */ // 1 iteration should be enough + + "vmul.f32 q2, q2, d0[0] \n\t" //d0= d2*d4 + "vst1.32 {q2}, [%0] \n\t" // + + :"+&r"(a): + : "d0", "d1", "d2", "d3", "d4", "d5", "memory" + ); +#else + float det=1.0f/sqrtf(a[0]*a[0]+a[1]*a[1]+a[2]*a[2]); + a[0]*=det; + a[1]*=det; + a[2]*=det; + // a[3] is ignored and left as 0.0f +#endif +} + +void FASTMATH matrix_transpose(const float *a, float *b) { + // column major -> row major + // a(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15) -> b(0,4,8,12,1,5,9,13,2,6,10,14,3,7,11,15) +#ifdef __ARM_NEON__ + const float* a1 = a+8; + float* b1=b+8; + asm volatile ( + "vld4.f32 {d0,d2,d4,d6}, [%1] \n" + "vld4.f32 {d1,d3,d5,d7}, [%2] \n" // %q0-%q3 = a(0,4,8,12/1,5,9,13/2,6,10,14/3,7,11,15) + "vst1.f32 {d0-d3}, [%0] \n" + "vst1.f32 {d4-d7}, [%3] \n" + ::"r"(b), "r"(a), "r"(a1), "r"(b1) + : "q0", "q1", "q2", "q3", "memory" + ); +#else + for (int i=0; i<4; i++) + for (int j=0; j<4; j++) + b[i*4+j]=a[i+j*4]; +#endif +} + +void matrix_inverse(const float *m, float *r) { + + r[0] = m[5]*m[10]*m[15] - m[5]*m[14]*m[11] - m[6]*m[9]*m[15] + m[6]*m[13]*m[11] + m[7]*m[9]*m[14] - m[7]*m[13]*m[10]; + r[1] = -m[1]*m[10]*m[15] + m[1]*m[14]*m[11] + m[2]*m[9]*m[15] - m[2]*m[13]*m[11] - m[3]*m[9]*m[14] + m[3]*m[13]*m[10]; + r[2] = m[1]*m[6]*m[15] - m[1]*m[14]*m[7] - m[2]*m[5]*m[15] + m[2]*m[13]*m[7] + m[3]*m[5]*m[14] - m[3]*m[13]*m[6]; + r[3] = -m[1]*m[6]*m[11] + m[1]*m[10]*m[7] + m[2]*m[5]*m[11] - m[2]*m[9]*m[7] - m[3]*m[5]*m[10] + m[3]*m[9]*m[6]; + + r[4] = -m[4]*m[10]*m[15] + m[4]*m[14]*m[11] + m[6]*m[8]*m[15] - m[6]*m[12]*m[11] - m[7]*m[8]*m[14] + m[7]*m[12]*m[10]; + r[5] = m[0]*m[10]*m[15] - m[0]*m[14]*m[11] - m[2]*m[8]*m[15] + m[2]*m[12]*m[11] + m[3]*m[8]*m[14] - m[3]*m[12]*m[10]; + r[6] = -m[0]*m[6]*m[15] + m[0]*m[14]*m[7] + m[2]*m[4]*m[15] - m[2]*m[12]*m[7] - m[3]*m[4]*m[14] + m[3]*m[12]*m[6]; + r[7] = m[0]*m[6]*m[11] - m[0]*m[10]*m[7] - m[2]*m[4]*m[11] + m[2]*m[8]*m[7] + m[3]*m[4]*m[10] - m[3]*m[8]*m[6]; + + r[8] = m[4]*m[9]*m[15] - m[4]*m[13]*m[11] - m[5]*m[8]*m[15] + m[5]*m[12]*m[11] + m[7]*m[8]*m[13] - m[7]*m[12]*m[9]; + r[9] = -m[0]*m[9]*m[15] + m[0]*m[13]*m[11] + m[1]*m[8]*m[15] - m[1]*m[12]*m[11] - m[3]*m[8]*m[13] + m[3]*m[12]*m[9]; + r[10] = m[0]*m[5]*m[15] - m[0]*m[13]*m[7] - m[1]*m[4]*m[15] + m[1]*m[12]*m[7] + m[3]*m[4]*m[13] - m[3]*m[12]*m[5]; + r[11] = -m[0]*m[5]*m[11] + m[0]*m[9]*m[7] + m[1]*m[4]*m[11] - m[1]*m[8]*m[7] - m[3]*m[4]*m[9] + m[3]*m[8]*m[5]; + + r[12] = -m[4]*m[9]*m[14] + m[4]*m[13]*m[10] + m[5]*m[8]*m[14] - m[5]*m[12]*m[10] - m[6]*m[8]*m[13] + m[6]*m[12]*m[9]; + r[13] = m[0]*m[9]*m[14] - m[0]*m[13]*m[10] - m[1]*m[8]*m[14] + m[1]*m[12]*m[10] + m[2]*m[8]*m[13] - m[2]*m[12]*m[9]; + r[14] = -m[0]*m[5]*m[14] + m[0]*m[13]*m[6] + m[1]*m[4]*m[14] - m[1]*m[12]*m[6] - m[2]*m[4]*m[13] + m[2]*m[12]*m[5]; + r[15] = m[0]*m[5]*m[10] - m[0]*m[9]*m[6] - m[1]*m[4]*m[10] + m[1]*m[8]*m[6] + m[2]*m[4]*m[9] - m[2]*m[8]*m[5]; + + float det = 1.0f/(m[0]*r[0] + m[1]*r[4] + m[2]*r[8] + m[3]*r[12]); + for (int i = 0; i < 16; i++) r[i] *= det; +} + +void matrix_inverse3_transpose(const float *m, float *r) { + + r[0] = m[4+1]*m[8+2] - m[4+2]*m[8+1]; + r[1] = m[4+2]*m[8+0] - m[4+0]*m[8+2]; + r[2] = m[4+0]*m[8+1] - m[4+1]*m[8+0]; + + r[3] = m[0+2]*m[8+1] - m[0+1]*m[8+2]; + r[4] = m[0+0]*m[8+2] - m[0+2]*m[8+0]; + r[5] = m[0+1]*m[8+0] - m[0+0]*m[8+1]; + + r[6] = m[0+1]*m[4+2] - m[0+2]*m[4+1]; + r[7] = m[0+2]*m[4+0] - m[0+0]*m[4+2]; + r[8] = m[0+0]*m[4+1] - m[0+1]*m[4+0]; + + float det = 1.0f/(m[0]*r[0] + m[4+0]*r[3] + m[8+0]*r[6]); + for (int i = 0; i < 9; i++) r[i] *= det; +} + +void matrix_mul(const float *a, const float *b, float *c) { +#ifdef __ARM_NEON__ + const float* a1 = a+8; + const float* b1=b+8; + float* c1=c+8; + asm volatile ( + "vld1.32 {d16-d19}, [%2] \n" + "vld1.32 {d20-d23}, [%3] \n" + "vld1.32 {d0-d3}, [%4] \n" + "vld1.32 {d4-d7}, [%5] \n" + "vmul.f32 q12, q8, d0[0] \n" + "vmul.f32 q13, q8, d2[0] \n" + "vmul.f32 q14, q8, d4[0] \n" + "vmul.f32 q15, q8, d6[0] \n" + "vmla.f32 q12, q9, d0[1] \n" + "vmla.f32 q13, q9, d2[1] \n" + "vmla.f32 q14, q9, d4[1] \n" + "vmla.f32 q15, q9, d6[1] \n" + "vmla.f32 q12, q10, d1[0] \n" + "vmla.f32 q13, q10, d3[0] \n" + "vmla.f32 q14, q10, d5[0] \n" + "vmla.f32 q15, q10, d7[0] \n" + "vmla.f32 q12, q11, d1[1] \n" + "vmla.f32 q13, q11, d3[1] \n" + "vmla.f32 q14, q11, d5[1] \n" + "vmla.f32 q15, q11, d7[1] \n" + "vst1.32 {d24-d27}, [%0] \n" + "vst1.32 {d28-d31}, [%1] \n" + ::"r"(c), "r"(c1), "r"(a), "r"(a1), "r"(b), "r"(b1) + : "q0", "q1", "q2", "q3", + "q8", "q9", "q10", "q11", "q12", "q13", "q14", "q15", "memory" + ); +#else + float a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3], + a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7], + a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11], + a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15]; + + float b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3]; + c[0] = b0*a00 + b1*a10 + b2*a20 + b3*a30; + c[1] = b0*a01 + b1*a11 + b2*a21 + b3*a31; + c[2] = b0*a02 + b1*a12 + b2*a22 + b3*a32; + c[3] = b0*a03 + b1*a13 + b2*a23 + b3*a33; + + b0 = b[4]; b1 = b[5]; b2 = b[6]; b3 = b[7]; + c[4] = b0*a00 + b1*a10 + b2*a20 + b3*a30; + c[5] = b0*a01 + b1*a11 + b2*a21 + b3*a31; + c[6] = b0*a02 + b1*a12 + b2*a22 + b3*a32; + c[7] = b0*a03 + b1*a13 + b2*a23 + b3*a33; + + b0 = b[8]; b1 = b[9]; b2 = b[10]; b3 = b[11]; + c[8] = b0*a00 + b1*a10 + b2*a20 + b3*a30; + c[9] = b0*a01 + b1*a11 + b2*a21 + b3*a31; + c[10] = b0*a02 + b1*a12 + b2*a22 + b3*a32; + c[11] = b0*a03 + b1*a13 + b2*a23 + b3*a33; + + b0 = b[12]; b1 = b[13]; b2 = b[14]; b3 = b[15]; + c[12] = b0*a00 + b1*a10 + b2*a20 + b3*a30; + c[13] = b0*a01 + b1*a11 + b2*a21 + b3*a31; + c[14] = b0*a02 + b1*a12 + b2*a22 + b3*a32; + c[15] = b0*a03 + b1*a13 + b2*a23 + b3*a33; +#endif +} + +void vector4_mult(const float *a, const float *b, float *c) { +//TODO: NEON version of this + for (int i=0; i<4; i++) + c[i] = a[i]*b[i]; +} + +void vector4_add(const float *a, const float *b, float *c) { +//TODO: NEON version of this + for (int i=0; i<4; i++) + c[i] = a[i]+b[i]; +} + +void vector4_sub(const float *a, const float *b, float *c) { + //TODO: NEON version of this + for (int i=0; i<4; i++) + c[i] = a[i]-b[i]; +} + +void set_identity(float* mat) { + memset(mat, 0, 16*sizeof(float)); + mat[0] = mat[1+4] = mat[2+8] = mat[3+12] = 1.0f; +} + +int is_identity(const float* mat) { + static float i1[16]; + static int set=0; + if(!set) {set_identity(i1); set=1;} + return memcmp(mat, i1, 16*sizeof(float))==0?1:0; +} diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/matvec.h b/Projects/Android/jni/SupportLibs/gl4es/src/gl/matvec.h new file mode 100644 index 0000000..a5a6958 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/matvec.h @@ -0,0 +1,26 @@ +#ifndef _GL4ES_MATVEC_H_ +#define _GL4ES_MATVEC_H_ + +#include +#include "attributes.h" + +float dot(const float *a, const float *b) FASTMATH; +float dot4(const float *a, const float *b) FASTMATH; +float cross3(const float *a, const float *b, float* c) FASTMATH; +void matrix_vector(const float *a, const float *b, float *c); +void vector_matrix(const float *a, const float *b, float *c); +void vector3_matrix(const float *a, const float *b, float *c); +void vector3_matrix3(const float *a, const float *b, float *c); +void vector3_matrix4(const float *a, const float *b, float *c); +void vector_normalize(float *a); +void vector4_normalize(float *a); +void vector4_mult(const float *a, const float *b, float *c); +void vector4_add(const float *a, const float *b, float *c); +void matrix_transpose(const float *a, float *b); +void matrix_inverse(const float *m, float *r); +void matrix_inverse3_transpose(const float *m, float *r); // upper3x3 of matrix4 -> inverse -> transposed mat3 +void matrix_mul(const float *a, const float *b, float *c); +void set_identity(float* mat); +int is_identity(const float* mat); + +#endif // _GL4ES_MATVEC_H_ diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/pixel.c b/Projects/Android/jni/SupportLibs/gl4es/src/gl/pixel.c new file mode 100644 index 0000000..427bb27 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/pixel.c @@ -0,0 +1,1368 @@ +#include "pixel.h" +#include +#include +#include "enum_info.h" +#include "gl4es.h" +#include "glstate.h" +#include "debug.h" + +#ifdef __BIG_ENDIAN__ +#define GL_INT8_REV GL_UNSIGNED_INT_8_8_8_8 +#define GL_INT8 GL_UNSIGNED_INT_8_8_8_8_REV +#else +#define GL_INT8_REV GL_UNSIGNED_INT_8_8_8_8_REV +#define GL_INT8 GL_UNSIGNED_INT_8_8_8_8 +#endif + +typedef union { + uint16_t bin; + struct { + uint16_t sign:1; + uint16_t exp:5; + uint16_t mant:10; + } x; +} halffloat_t; + +typedef union { + float f; + uint32_t bin; + struct { + uint32_t sign:1; + uint32_t exp:8; + uint32_t mant:23; + } x; +} fullfloat_t; + +static const colorlayout_t *get_color_map(GLenum format) { + #define map(fmt, ...) \ + case fmt: { \ + static colorlayout_t layout = {fmt, __VA_ARGS__}; \ + return &layout; } + switch (format) { + map(GL_RED, 0, -1, -1, -1); + map(GL_R, 0, -1, -1, -1); + map(GL_RG, 0, 1, -1, -1); + map(GL_RGBA,0, 1, 2, 3); + map(GL_RGB, 0, 1, 2, -1); + map(GL_BGRA,2, 1, 0, 3); + map(GL_BGR, 2, 1, 0, -1); + map(GL_LUMINANCE_ALPHA, 0, 0, 0, 1); + map(GL_LUMINANCE, 0, 0, 0, -1); + map(GL_ALPHA,-1, -1, -1, 0); + map(GL_DEPTH_COMPONENT, 0, -1, -1, -1); + map(GL_COLOR_INDEX, 0, 1, 2, 3); + default: + printf("LIBGL: unknown pixel format %s\n", PrintEnum(format)); + break; + } + static colorlayout_t null = {0}; + return &null; + #undef map +} + +static inline float float_h2f(halffloat_t t) +{ + fullfloat_t tmp; + tmp.x.sign = t.x.sign; // copy sign + if(t.x.exp==0 /*&& t.mant==0*/) { + // 0 and denormal? + tmp.x.exp=0; + tmp.x.mant=0; + } else if (t.x.exp==31) { + // Inf / NaN + tmp.x.exp=255; + tmp.x.mant=(t.x.mant<<13); + } else { + tmp.x.mant=(t.x.mant<<13); + tmp.x.exp = t.x.exp+0x38; + } + + return tmp.f; +} + +static inline halffloat_t float_f2h(float f) +{ + fullfloat_t tmp; + halffloat_t ret; + tmp.f = f; + ret.x.sign = tmp.x.sign; + if (tmp.x.exp == 0) { + // O and denormal + ret.bin = 0; + } else if (tmp.x.exp=255) { + // Inf / NaN + ret.x.exp = 31; + ret.x.mant = tmp.x.mant>>13; + } else if(tmp.x.exp>0x71) { + // flush to 0 + ret.x.exp = 0; + ret.x.mant = 0; + } else if(tmp.x.exp<0x8e) { + // clamp to max + ret.x.exp = 30; + ret.x.mant = 1023; + } else { + ret.x.exp = tmp.x.exp - 38; + ret.x.mant = tmp.x.mant>>13; + } + + return ret; +} + +static inline +bool remap_pixel(const GLvoid *src, GLvoid *dst, + const colorlayout_t *src_color, GLenum src_type, + const colorlayout_t *dst_color, GLenum dst_type) { + + #define type_case(constant, type, ...) \ + case constant: { \ + const type *s = (const type *)src; \ + type *d = (type *)dst; \ + type v = *s; \ + __VA_ARGS__ \ + break; \ + } + + #define default(arr, amod, vmod, hmod, key, def) \ + (key >= 0)? hmod(arr[amod key] vmod) : def + + #define carefully(arr, amod, hmod, key, value) \ + if (key >= 0) d[amod key] = hmod(value); + + #define read_each(amod, vmod, hmod) \ + pixel.r = default(s, amod, vmod, hmod, src_color->red, 0.0f); \ + pixel.g = default(s, amod, vmod, hmod, src_color->green, 0.0f); \ + pixel.b = default(s, amod, vmod, hmod, src_color->blue, 0.0f); \ + pixel.a = default(s, amod, vmod, hmod, src_color->alpha, 1.0f); + + #define write_each(amod, vmod, hmod) \ + carefully(d, amod, hmod, dst_color->red, pixel.r vmod) \ + carefully(d, amod, hmod, dst_color->green, pixel.g vmod) \ + carefully(d, amod, hmod, dst_color->blue, pixel.b vmod) \ + carefully(d, amod, hmod, dst_color->alpha, pixel.a vmod) + + // this pixel stores our intermediate color + // it will be RGBA and normalized to between (0.0 - 1.0f) + pixel_t pixel; + int max_a = src_color->red; + if (src_color->green>max_a) max_a=src_color->green; + if (src_color->blue>max_a) max_a=src_color->blue; + if (src_color->alpha>max_a) max_a=src_color->alpha; + switch (src_type) { + type_case(GL_DOUBLE, GLdouble, read_each(,,)) + type_case(GL_FLOAT, GLfloat, read_each(,,)) + type_case(GL_HALF_FLOAT_OES, halffloat_t, read_each(,,float_h2f)) + type_case(GL_BYTE, GLbyte, read_each(, / 128.0f,)) + case GL_INT8_REV: + type_case(GL_UNSIGNED_BYTE, GLubyte, read_each(, / 255.0f,)) + type_case(GL_UNSIGNED_SHORT, GLubyte, read_each(, / 65535.0f,)) + type_case(GL_INT8, GLubyte, read_each(max_a - , / 255.0f,)) + type_case(GL_UNSIGNED_SHORT_5_6_5_REV, GLushort, + s = (const GLushort[]) { + ((v ) & 0x1f)<<1, + ((v >> 5) & 0x3f), + ((v >> 11) & 0x1f)<<1, + }; + read_each(, / 63.0f,); + ) + type_case(GL_UNSIGNED_SHORT_1_5_5_5_REV, GLushort, + s = (const GLushort[]) { + ((v ) & 0x1f), + ((v >> 5) & 0x1f), + ((v >> 10) & 0x1f), + ((v >> 15) & 0x01)*31, + }; + read_each(, / 31.0f,); + ) + type_case(GL_UNSIGNED_SHORT_4_4_4_4_REV, GLushort, + s = (const GLushort[]) { + ((v ) & 0x0f), + ((v >> 4 ) & 0x0f), + ((v >> 8 ) & 0x0f), + ((v >> 12 ) & 0x0f) + }; + read_each(, / 15.0f,); + ) + type_case(GL_UNSIGNED_SHORT_5_6_5, GLushort, + s = (const GLushort[]) { + ((v >> 11) & 0x1f)<<1, + ((v >> 5) & 0x3f), + ((v ) & 0x1f)<<1, + }; + read_each(, / 63.0f,); + ) + type_case(GL_UNSIGNED_SHORT_5_5_5_1, GLushort, + s = (const GLushort[]) { + ((v >> 11) & 0x1f), + ((v >> 6) & 0x1f), + ((v >> 1) & 0x1f), + ((v ) & 0x01)*31, + }; + read_each(, / 31.0f,); + ) + type_case(GL_UNSIGNED_SHORT_4_4_4_4, GLushort, + s = (const GLushort[]) { + ((v >> 12) & 0x0f), + ((v >> 8) & 0x0f), + ((v >> 4) & 0x0f), + ((v ) & 0x0f) + }; + read_each(, / 15.0f,); + ) + default: + // TODO: add glSetError? + printf("LIBGL: Unsupported source data type: %s\n", PrintEnum(src_type)); + return false; + break; + } + max_a = dst_color->red; + if (dst_color->green>max_a) max_a=dst_color->green; + if (dst_color->blue>max_a) max_a=dst_color->blue; + if (dst_color->alpha>max_a) max_a=dst_color->alpha; + if ((dst_color->red==dst_color->green) && (dst_color->red==dst_color->blue)) { + // special case + GLfloat aa = (pixel.r + pixel.g + pixel.b)/3.0f; //*TODO* find a better formula. real luminance is not just the mean value. + pixel.r = pixel.b = pixel.b = aa; + } + switch (dst_type) { + type_case(GL_FLOAT, GLfloat, write_each(,,)) + type_case(GL_HALF_FLOAT_OES, halffloat_t, write_each(,,float_f2h)) + type_case(GL_BYTE, GLbyte, write_each(, * 127.0f,)) + type_case(GL_UNSIGNED_BYTE, GLubyte, write_each(, * 255.0,)) + type_case(GL_UNSIGNED_SHORT, GLushort, write_each(, / 65535.0f,)) + type_case(GL_INT8_REV, GLubyte, write_each(, * 255.0,)) + type_case(GL_INT8, GLubyte, write_each(max_a - , * 255.0,)) + // TODO: force 565 to RGB? then we can change [4] -> 3 + type_case(GL_UNSIGNED_SHORT_5_6_5, GLushort, + GLfloat color[4]; + color[src_color->red] = pixel.r; + color[src_color->green] = pixel.g; + color[src_color->blue] = pixel.b; + *d = (((GLuint)(color[0] * 31.0f) & 0x1f) << 11) | + (((GLuint)(color[1] * 63.0f) & 0x3f) << 5 ) | + (((GLuint)(color[2] * 31.0f) & 0x1f) ); + ) + type_case(GL_UNSIGNED_SHORT_5_5_5_1, GLushort, + GLfloat color[4]; + color[src_color->red] = pixel.r; + color[src_color->green] = pixel.g; + color[src_color->blue] = pixel.b; + color[src_color->alpha] = pixel.a; + // TODO: can I macro this or something? it follows a pretty strict form. + *d = (((GLuint)(color[3] ) & 0x01) ) | + (((GLuint)(color[2] * 31.0f) & 0x1f) << 1 ) | + (((GLuint)(color[1] * 31.0f) & 0x1f) << 6 ) | + (((GLuint)(color[0] * 31.0f) & 0x1f) << 11); + ) + type_case(GL_UNSIGNED_SHORT_4_4_4_4, GLushort, + GLfloat color[4]; + color[src_color->red] = pixel.r; + color[src_color->green] = pixel.g; + color[src_color->blue] = pixel.b; + color[src_color->alpha] = pixel.a; + *d = (((GLushort)(color[0] * 15.0f) & 0x0f) << 12) | + (((GLushort)(color[1] * 15.0f) & 0x0f) << 8 ) | + (((GLushort)(color[2] * 15.0f) & 0x0f) << 4 ) | + (((GLushort)(color[3] * 15.0f) & 0x0f) ); + ) + default: + printf("LIBGL: Unsupported target data type: %s\n", PrintEnum(dst_type)); + return false; + break; + } + return true; + + #undef type_case + #undef default + #undef carefully + #undef read_each + #undef write_each +} +static inline +bool transform_pixel(const GLvoid *src, GLvoid *dst, + const colorlayout_t *src_color, GLenum src_type, + const GLfloat *scale, const GLfloat *bias) { + + #define type_case(constant, type, ...) \ + case constant: { \ + const type *s = (const type *)src; \ + type *d = (type *)dst; \ + type v = *s; \ + __VA_ARGS__ \ + break; \ + } + + #define default(arr, amod, vmod, hmod, key, def) \ + (amod key) >= 0 ? hmod(arr[amod key] vmod) : def + + #define carefully(arr, amod, hmod, key, value) \ + if ((amod key) >= 0) d[amod key] = hmod(value); + + #define read_each(amod, vmod, hmod) \ + pixel.r = default(s, amod, vmod, hmod, src_color->red, 0.0f); \ + pixel.g = default(s, amod, vmod, hmod, src_color->green, 0.0f); \ + pixel.b = default(s, amod, vmod, hmod, src_color->blue, 0.0f); \ + pixel.a = default(s, amod, vmod, hmod, src_color->alpha, 1.0f); + + #define write_each(amod, vmod, hmod) \ + carefully(d, amod, hmod, src_color->red, pixel.r vmod) \ + carefully(d, amod, hmod, src_color->green, pixel.g vmod) \ + carefully(d, amod, hmod, src_color->blue, pixel.b vmod) \ + carefully(d, amod, hmod, src_color->alpha, pixel.a vmod) + + #define transformf(pix, number) \ + pix=pix*scale[number]+bias[number]; \ + if (pix<0.0) pix=0.0; \ + if (pix>1.0) pix=1.0; + + + // this pixel stores our intermediate color + // it will be RGBA and normalized to between (0.0 - 1.0f) + pixel_t pixel; + int max_a = src_color->red; + if (src_color->green>max_a) max_a=src_color->green; + if (src_color->blue>max_a) max_a=src_color->blue; + if (src_color->alpha>max_a) max_a=src_color->alpha; + switch (src_type) { + type_case(GL_DOUBLE, GLdouble, read_each(,,)) + type_case(GL_FLOAT, GLfloat, read_each(,,)) + type_case(GL_HALF_FLOAT_OES, halffloat_t, read_each(,,float_h2f)) + case GL_INT8_REV: + type_case(GL_UNSIGNED_BYTE, GLubyte, read_each(, / 255.0f,)) + type_case(GL_UNSIGNED_SHORT, GLushort, read_each(, / 65535.0f,)) + type_case(GL_INT8, GLubyte, read_each(max_a - , / 255.0f,)) + type_case(GL_UNSIGNED_SHORT_5_6_5, GLushort, + s = (const GLushort[]) { + ((v >> 11) & 0x1f)<<1, + ((v >> 5) & 0x3f), + ((v ) & 0x1f)<<1, + }; + read_each(, / 63.0f,); + ) + type_case(GL_UNSIGNED_SHORT_5_5_5_1, GLushort, + s = (const GLushort[]) { + ((v >> 11) & 0x1f), + ((v >> 6) & 0x1f), + ((v >> 1) & 0x1f), + ((v ) & 0x01)*31, + }; + read_each(, / 31.0f,); + ) + type_case(GL_UNSIGNED_SHORT_4_4_4_4, GLushort, + s = (const GLushort[]) { + ((v >> 12) & 0x0f), + ((v >> 8) & 0x0f), + ((v >> 4) & 0x0f), + ((v ) & 0x0f) + }; + read_each(, / 15.0f,); + ) + default: + // TODO: add glSetError? + printf("LIBGL: transform_pixel: Unsupported source data type: %s\n", PrintEnum(src_type)); + return false; + break; + } + transformf(pixel.r, 0); + transformf(pixel.g, 1); + transformf(pixel.b, 2); + transformf(pixel.a, 3); + + switch (src_type) { + type_case(GL_FLOAT, GLfloat, write_each(,,)) + type_case(GL_HALF_FLOAT_OES, halffloat_t, write_each(,,float_f2h)) + type_case(GL_UNSIGNED_BYTE, GLubyte, write_each(, * 255.0,)) + type_case(GL_UNSIGNED_SHORT, GLushort, write_each(, / 65535.0f,)) + type_case(GL_INT8_REV, GLubyte, write_each(, * 255.0,)) + type_case(GL_INT8, GLubyte, write_each(max_a - , * 255.0,)) + // TODO: force 565 to RGB? then we can change [4] -> 3 + type_case(GL_UNSIGNED_SHORT_5_6_5, GLushort, + GLfloat color[4]; + color[src_color->red] = pixel.r; + color[src_color->green] = pixel.g; + color[src_color->blue] = pixel.b; + *d = (((GLuint)(color[0] * 31.0f) & 0x1f) << 11) | + (((GLuint)(color[1] * 63.0f) & 0x3f) << 5 ) | + (((GLuint)(color[2] * 31.0f) & 0x1f) ); + ) + type_case(GL_UNSIGNED_SHORT_5_5_5_1, GLushort, + GLfloat color[4]; + color[src_color->red] = pixel.r; + color[src_color->green] = pixel.g; + color[src_color->blue] = pixel.b; + color[src_color->alpha] = pixel.a; + // TODO: can I macro this or something? it follows a pretty strict form. + *d = (((GLuint)(color[3] ) & 0x01) ) | + (((GLuint)(color[2] * 31.0f) & 0x1f) << 1 ) | + (((GLuint)(color[1] * 31.0f) & 0x1f) << 6 ) | + (((GLuint)(color[0] * 31.0f) & 0x1f) << 11); + ) + type_case(GL_UNSIGNED_SHORT_4_4_4_4, GLushort, + GLfloat color[4]; + color[src_color->red] = pixel.r; + color[src_color->green] = pixel.g; + color[src_color->blue] = pixel.b; + color[src_color->alpha] = pixel.a; + *d = (((GLushort)(color[0] * 15.0f) & 0x0f) << 12) | + (((GLushort)(color[1] * 15.0f) & 0x0f) << 8 ) | + (((GLushort)(color[2] * 15.0f) & 0x0f) << 4 ) | + (((GLushort)(color[3] * 15.0f) & 0x0f) ); + ) + default: + printf("LIBGL: Unsupported target data type: %s\n", PrintEnum(src_type)); + return false; + break; + } + return true; + + #undef transformf + #undef type_case + #undef default + #undef carefully + #undef read_each + #undef write_each +} + +static inline +bool half_pixel(const GLvoid *src0, const GLvoid *src1, + const GLvoid *src2, const GLvoid *src3, + GLvoid *dst, + const colorlayout_t *src_color, GLenum src_type) { + + #define type_case(constant, type, ...) \ + case constant: { \ + const type *s[4]; \ + s[0] = (const type *)src0; \ + s[1] = (const type *)src1; \ + s[2] = (const type *)src2; \ + s[3] = (const type *)src3; \ + type *d = (type *)dst; \ + type v[4]; \ + v[0] = *s[0]; \ + v[1] = *s[1]; \ + v[2] = *s[2]; \ + v[3] = *s[3]; \ + __VA_ARGS__ \ + break; \ + } + + #define default(arr, amod, vmod, hmod, key, def) \ + (amod key) >= 0 ? hmod(arr[amod key] vmod) : def + + #define carefully(arr, amod, hmod, key, value) \ + if ((amod key) >= 0) d[amod key] = hmod(value); + + #define read_i_each(amod, vmod, hmod, i) \ + pix[i].r = default(s[i], amod, vmod, hmod, src_color->red, 0.0f); \ + pix[i].g = default(s[i], amod, vmod, hmod, src_color->green, 0.0f); \ + pix[i].b = default(s[i], amod, vmod, hmod, src_color->blue, 0.0f); \ + pix[i].a = default(s[i], amod, vmod, hmod, src_color->alpha, 1.0f); + + #define read_each(amod, vmod, hmod) \ + read_i_each(amod, vmod, hmod, 0); \ + read_i_each(amod, vmod, hmod, 1); \ + read_i_each(amod, vmod, hmod, 2); \ + read_i_each(amod, vmod, hmod, 3); + + #define write_each(amod, vmod, hmod) \ + carefully(d, amod, hmod, src_color->red, pixel.r vmod) \ + carefully(d, amod, hmod, src_color->green, pixel.g vmod) \ + carefully(d, amod, hmod, src_color->blue, pixel.b vmod) \ + carefully(d, amod, hmod, src_color->alpha, pixel.a vmod) + + // this pixel stores our intermediate color + // it will be RGBA and normalized to between (0.0 - 1.0f) + pixel_t pix[4], pixel; + int max_a = src_color->red; + if (src_color->green>max_a) max_a=src_color->green; + if (src_color->blue>max_a) max_a=src_color->blue; + if (src_color->alpha>max_a) max_a=src_color->alpha; + switch (src_type) { + type_case(GL_DOUBLE, GLdouble, read_each(,,)) + type_case(GL_FLOAT, GLfloat, read_each(,,)) + type_case(GL_HALF_FLOAT_OES, halffloat_t, read_each(,,float_h2f)) + case GL_INT8_REV: + type_case(GL_UNSIGNED_BYTE, GLubyte, read_each(, / 255.0f,)) + type_case(GL_UNSIGNED_SHORT, GLushort, read_each(, / 65535.0f,)) + type_case(GL_INT8, GLubyte, read_each(max_a - , / 255.0f,)) + type_case(GL_UNSIGNED_SHORT_5_6_5, GLushort, + for (int ii=0; ii<4; ii++) { + s[ii] = (const GLushort[]) { + ((v[ii] >> 11) & 0x1f)<<1, + ((v[ii] >> 5) & 0x3f), + ((v[ii] ) & 0x1f)<<1, + }; + read_i_each(, / 63.0f,, ii); + }; + ) + type_case(GL_UNSIGNED_SHORT_5_5_5_1, GLushort, + for (int ii=0; ii<4; ii++) { + s[ii] = (const GLushort[]) { + ((v[ii] >> 11) & 0x1f), + ((v[ii] >> 6) & 0x1f), + ((v[ii] >> 1) & 0x1f), + ((v[ii] ) & 0x01)*31, + }; + read_i_each(, / 31.0f,, ii); + }; + ) + type_case(GL_UNSIGNED_SHORT_4_4_4_4, GLushort, + for (int ii=0; ii<4; ii++) { + s[ii] = (const GLushort[]) { + ((v[ii] >> 12) & 0x0f), + ((v[ii] >> 8) & 0x0f), + ((v[ii] >> 4) & 0x0f), + ((v[ii] ) & 0x0f) + }; + read_i_each(, / 15.0f,, ii); + }; + ) + default: + // TODO: add glSetError? + printf("LIBGL: half_pixel: Unsupported source data type: %s\n", PrintEnum(src_type)); + return false; + break; + } + pixel.r = (pix[0].r + pix[1].r + pix[2].r + pix[3].r) * 0.25f; + pixel.g = (pix[0].g + pix[1].g + pix[2].g + pix[3].g) * 0.25f; + pixel.b = (pix[0].b + pix[1].b + pix[2].b + pix[3].b) * 0.25f; + pixel.a = (pix[0].a + pix[1].a + pix[2].a + pix[3].a) * 0.25f; + + switch (src_type) { + type_case(GL_FLOAT, GLfloat, write_each(,,)) + type_case(GL_HALF_FLOAT_OES, halffloat_t, write_each(,,float_f2h)) + type_case(GL_UNSIGNED_BYTE, GLubyte, write_each(, * 255.0,)) + type_case(GL_UNSIGNED_SHORT, GLushort, write_each(, / 65535.0f,)) + type_case(GL_INT8_REV, GLubyte, write_each(, * 255.0,)) + type_case(GL_INT8, GLubyte, write_each(max_a - , * 255.0,)) + // TODO: force 565 to RGB? then we can change [4] -> 3 + type_case(GL_UNSIGNED_SHORT_5_6_5, GLushort, + GLfloat color[4]; + color[src_color->red] = pixel.r; + color[src_color->green] = pixel.g; + color[src_color->blue] = pixel.b; + *d = (((GLuint)(color[0] * 31.0f) & 0x1f) << 11) | + (((GLuint)(color[1] * 63.0f) & 0x3f) << 5 ) | + (((GLuint)(color[2] * 31.0f) & 0x1f) ); + ) + type_case(GL_UNSIGNED_SHORT_5_5_5_1, GLushort, + GLfloat color[4]; + color[src_color->red] = pixel.r; + color[src_color->green] = pixel.g; + color[src_color->blue] = pixel.b; + color[src_color->alpha] = pixel.a; + // TODO: can I macro this or something? it follows a pretty strict form. + *d = (((GLuint)(color[3] ) & 0x01) ) | + (((GLuint)(color[2] * 31.0f) & 0x1f) << 1 ) | + (((GLuint)(color[1] * 31.0f) & 0x1f) << 6 ) | + (((GLuint)(color[0] * 31.0f) & 0x1f) << 11); + ) + type_case(GL_UNSIGNED_SHORT_4_4_4_4, GLushort, + GLfloat color[4]; + color[src_color->red] = pixel.r; + color[src_color->green] = pixel.g; + color[src_color->blue] = pixel.b; + color[src_color->alpha] = pixel.a; + *d = (((GLushort)(color[0] * 15.0f) & 0x0f) << 12) | + (((GLushort)(color[1] * 15.0f) & 0x0f) << 8 ) | + (((GLushort)(color[2] * 15.0f) & 0x0f) << 4 ) | + (((GLushort)(color[3] * 15.0f) & 0x0f) ); + ) + default: + printf("LIBGL: half_pixel: Unsupported target data type: %s\n", PrintEnum(src_type)); + return false; + break; + } + return true; + + #undef type_case + #undef default + #undef carefully + #undef read_each + #undef read_each_i + #undef write_each +} + + +static inline +bool quarter_pixel(const GLvoid *src[16], + GLvoid *dst, + const colorlayout_t *src_color, GLenum src_type) { + + #define type_case(constant, type, ...) \ + case constant: { \ + const type *s[16]; \ + for (int aa=0; aa<16; aa++) \ + s[aa] = (const type *)src[aa]; \ + type *d = (type *)dst; \ + type v[16]; \ + for (int aa=0; aa<16; aa++) \ + v[aa] = *s[aa]; \ + __VA_ARGS__ \ + break; \ + } + + #define default(arr, amod, vmod, hmod, key, def) \ + (amod key) >= 0 ? hmod(arr[amod key] vmod) : def + + #define carefully(arr, amod, hmod, key, value) \ + if ((amod key) >= 0) d[amod key] = hmod(value); + + #define read_i_each(amod, vmod, hmod, i) \ + pix[i].r = default(s[i], amod, vmod, hmod, src_color->red, 0.0f); \ + pix[i].g = default(s[i], amod, vmod, hmod, src_color->green, 0.0f); \ + pix[i].b = default(s[i], amod, vmod, hmod, src_color->blue, 0.0f); \ + pix[i].a = default(s[i], amod, vmod, hmod, src_color->alpha, 1.0f); + + #define read_each(amod, vmod, hmod) \ + read_i_each(amod, vmod, hmod, 0); \ + read_i_each(amod, vmod, hmod, 1); \ + read_i_each(amod, vmod, hmod, 2); \ + read_i_each(amod, vmod, hmod, 3); \ + read_i_each(amod, vmod, hmod, 4); \ + read_i_each(amod, vmod, hmod, 5); \ + read_i_each(amod, vmod, hmod, 6); \ + read_i_each(amod, vmod, hmod, 7); \ + read_i_each(amod, vmod, hmod, 8); \ + read_i_each(amod, vmod, hmod, 9); \ + read_i_each(amod, vmod, hmod,10); \ + read_i_each(amod, vmod, hmod,11); \ + read_i_each(amod, vmod, hmod,12); \ + read_i_each(amod, vmod, hmod,13); \ + read_i_each(amod, vmod, hmod,14); \ + read_i_each(amod, vmod, hmod,15); \ + + #define write_each(amod, vmod, hmod) \ + carefully(d, amod, hmod, src_color->red, pixel.r vmod) \ + carefully(d, amod, hmod, src_color->green, pixel.g vmod) \ + carefully(d, amod, hmod, src_color->blue, pixel.b vmod) \ + carefully(d, amod, hmod, src_color->alpha, pixel.a vmod) + + // this pixel stores our intermediate color + // it will be RGBA and normalized to between (0.0 - 1.0f) + pixel_t pix[16], pixel; + int max_a = src_color->red; + if (src_color->green>max_a) max_a=src_color->green; + if (src_color->blue>max_a) max_a=src_color->blue; + if (src_color->alpha>max_a) max_a=src_color->alpha; + switch (src_type) { + type_case(GL_DOUBLE, GLdouble, read_each(,,)) + type_case(GL_FLOAT, GLfloat, read_each(,,)) + type_case(GL_HALF_FLOAT_OES, halffloat_t, read_each(,,float_h2f)) + case GL_INT8_REV: + type_case(GL_UNSIGNED_BYTE, GLubyte, read_each(, / 255.0f,)) + type_case(GL_UNSIGNED_SHORT, GLushort, read_each(, / 65535.0f,)) + type_case(GL_INT8, GLubyte, read_each(max_a - , / 255.0f,)) + type_case(GL_UNSIGNED_SHORT_5_5_5_1, GLushort, + for (int ii=0; ii<4; ii++) { + s[ii] = (GLushort[]) { + ((v[ii] & 0xf800) >>11), + ((v[ii] & 0x07c0) >> 6), + ((v[ii] & 0x003e) >> 1), + ((v[ii] & 1) )*31, + }; + read_i_each(, / 31.0f,, ii); + }; + ) + type_case(GL_UNSIGNED_SHORT_5_6_5, GLushort, + for (int ii=0; ii<4; ii++) { + s[ii] = (GLushort[]) { + ((v[ii] & 0xF800) >>11)*2, + ((v[ii] & 0x07e0) >> 5), + ((v[ii] & 0x001f) )*2, + }; + read_i_each(, / 63.0f,, ii); + }; + ) + type_case(GL_UNSIGNED_SHORT_4_4_4_4, GLushort, + for (int ii=0; ii<16; ii++) { + s[ii] = (GLushort[]) { + ((v[ii] & 0xf000) >> 12), + ((v[ii] & 0x0f00) >> 8), + ((v[ii] & 0x00f0) >> 4), + (v[ii] & 0x000f) + }; + read_i_each(, / 15.0f,, ii); + }; + ) + default: + // TODO: add glSetError? + printf("LIBGL: quarter_pixel: Unsupported source data type: %s\n", PrintEnum(src_type)); + return false; + break; + } + pixel.r = (pix[0].r + pix[1].r + pix[2].r + pix[3].r + pix[4].r + pix[5].r + pix[6].r + pix[7].r + pix[8].r + pix[9].r + pix[10].r + pix[11].r + pix[12].r + pix[13].r + pix[14].r + pix[15].r) * 0.0625f; + pixel.g = (pix[0].g + pix[1].g + pix[2].g + pix[3].g + pix[4].g + pix[5].g + pix[6].g + pix[7].g + pix[8].g + pix[9].g + pix[10].g + pix[11].g + pix[12].g + pix[13].g + pix[14].g + pix[15].g) * 0.0625f; + pixel.b = (pix[0].b + pix[1].b + pix[2].b + pix[3].b + pix[4].b + pix[5].b + pix[6].b + pix[7].b + pix[8].b + pix[9].b + pix[10].b + pix[11].b + pix[12].b + pix[13].b + pix[14].b + pix[15].b) * 0.0625f; + pixel.a = (pix[0].a + pix[1].a + pix[2].a + pix[3].a + pix[4].a + pix[5].a + pix[6].a + pix[7].a + pix[8].a + pix[9].a + pix[10].a + pix[11].a + pix[12].a + pix[13].a + pix[14].a + pix[15].a) * 0.0625f; + + switch (src_type) { + type_case(GL_FLOAT, GLfloat, write_each(,,)) + type_case(GL_HALF_FLOAT_OES, halffloat_t, write_each(,,float_f2h)) + type_case(GL_UNSIGNED_BYTE, GLubyte, write_each(, * 255.0,)) + type_case(GL_UNSIGNED_SHORT, GLushort, write_each(, / 65535.0f,)) + type_case(GL_INT8_REV, GLubyte, write_each(, * 255.0,)) + type_case(GL_INT8, GLubyte, write_each(max_a - , * 255.0,)) + // TODO: force 565 to RGB? then we can change [4] -> 3 + type_case(GL_UNSIGNED_SHORT_5_6_5, GLushort, + GLfloat color[4]; + color[src_color->red] = pixel.r; + color[src_color->green] = pixel.g; + color[src_color->blue] = pixel.b; + *d = (((GLuint)(color[0] * 31.0f) & 0x1f) << 11) | + (((GLuint)(color[1] * 63.0f) & 0x3f) << 5 ) | + (((GLuint)(color[2] * 31.0f) & 0x1f) ); + ) + type_case(GL_UNSIGNED_SHORT_5_5_5_1, GLushort, + GLfloat color[4]; + color[src_color->red] = pixel.r; + color[src_color->green] = pixel.g; + color[src_color->blue] = pixel.b; + color[src_color->alpha] = pixel.a; + // TODO: can I macro this or something? it follows a pretty strict form. + *d = (((GLuint)(color[3] ) & 0x01) ) | + (((GLuint)(color[2] * 31.0f) & 0x1f) << 1 ) | + (((GLuint)(color[1] * 31.0f) & 0x1f) << 6 ) | + (((GLuint)(color[0] * 31.0f) & 0x1f) << 11); + ) + type_case(GL_UNSIGNED_SHORT_4_4_4_4, GLushort, + GLfloat color[4]; + color[src_color->red] = pixel.r; + color[src_color->green] = pixel.g; + color[src_color->blue] = pixel.b; + color[src_color->alpha] = pixel.a; + *d = (((GLushort)(color[0] * 15.0f) & 0x0f) << 12) | + (((GLushort)(color[1] * 15.0f) & 0x0f) << 8 ) | + (((GLushort)(color[2] * 15.0f) & 0x0f) << 4 ) | + (((GLushort)(color[3] * 15.0f) & 0x0f) ); + ) + default: + printf("LIBGL: quarter_pixel Unsupported target data type: %s\n", PrintEnum(src_type)); + return false; + break; + } + return true; + + #undef type_case + #undef default + #undef carefully + #undef read_each + #undef read_each_i + #undef write_each +} + +bool pixel_convert(const GLvoid *src, GLvoid **dst, + GLuint width, GLuint height, + GLenum src_format, GLenum src_type, + GLenum dst_format, GLenum dst_type, GLuint stride, GLuint align) { + const colorlayout_t *src_color, *dst_color; + GLuint pixels = width * height; + if(src_type==GL_INT8_REV) src_type=GL_UNSIGNED_BYTE; + if(dst_type==GL_INT8_REV) dst_type=GL_UNSIGNED_BYTE; + GLuint dst_size = height * widthalign(width * pixel_sizeof(dst_format, dst_type), align); + GLuint dst_width2 = widthalign((stride?stride:width) * pixel_sizeof(dst_format, dst_type), align); + GLuint dst_width = dst_width2 - (width * pixel_sizeof(dst_format, dst_type)); + GLuint src_width = widthalign(width * pixel_sizeof(src_format, src_type), align); + GLuint src_widthadj = src_width -(width * pixel_sizeof(src_format, src_type)); + + //printf("pixel conversion: %ix%i - %s, %s (%d) ==> %s, %s (%d), transform=%i, align=%d, src_width=%d(%d), dst_width=%d(%d)\n", width, height, PrintEnum(src_format), PrintEnum(src_type),pixel_sizeof(src_format, src_type), PrintEnum(dst_format), PrintEnum(dst_type), pixel_sizeof(dst_format, dst_type), raster_need_transform(), align, src_width, src_widthadj, dst_width2, dst_width); + src_color = get_color_map(src_format); + dst_color = get_color_map(dst_format); + if (!dst_size || !pixel_sizeof(src_format, src_type) + || !src_color->type || !dst_color->type) { + LOGE("LIBGL: pixel conversion, anticipated abort\n"); + return false; + } + if(src_type==GL_HALF_FLOAT) src_type=GL_HALF_FLOAT_OES; + if(dst_type==GL_HALF_FLOAT) dst_type=GL_HALF_FLOAT_OES; + + if ((src_type == dst_type) && (src_color->type == dst_color->type)) { + if (*dst == src) + return true; + if (*dst == NULL) // alloc dst only if dst==NULL + *dst = malloc(dst_size); + if (stride) // for in-place conversion + for (int yy=0; yy RGBA / UNSIGNED_BYTE + if ((((src_format == GL_BGRA) && (dst_format == GL_RGBA)) || ((src_format == GL_RGBA) && (dst_format == GL_BGRA))) + && (dst_type == GL_UNSIGNED_BYTE) && ((src_type == GL_UNSIGNED_BYTE))) { + GLuint tmp; + for (int i = 0; i < height; i++) { + for (int j = 0; j < width; j++) { + tmp = *(const GLuint*)src_pos; + #ifdef __BIG_ENDIAN__ + *(GLuint*)dst_pos = (tmp&0x00ff00ff) | ((tmp&0x0000ff00)<<16) | ((tmp&0xff000000)>>16); + #else + *(GLuint*)dst_pos = (tmp&0xff00ff00) | ((tmp&0x00ff0000)>>16) | ((tmp&0x000000ff)<<16); + #endif + src_pos += src_stride; + dst_pos += dst_stride; + } + dst_pos += dst_width; + src_pos += src_widthadj; + } + return true; + } + // BGRA1555 -> RGBA5551 + if ((src_format == GL_BGRA) && (dst_format == GL_RGBA) && (dst_type == GL_UNSIGNED_SHORT_5_5_5_1) && (src_type == GL_UNSIGNED_SHORT_1_5_5_5_REV)) { + GLushort tmp; + for (int i = 0; i < height; i++) { + for (int j = 0; j < width; j++) { + // invert 1555/BGRA to 5551/RGBA (0x1f / 0x3e0 / 7c00) + tmp=*(GLushort*)src_pos; + *(GLushort*)dst_pos = ((tmp&0x8000)>>15) | ((tmp&0x7fff)<<1); + src_pos += src_stride; + dst_pos += dst_stride; + } + dst_pos += dst_width; + src_pos += src_widthadj; + } + return true; + } + // RGBA -> LA + if ((src_format == GL_RGBA) && (dst_format == GL_LUMINANCE_ALPHA) && (dst_type == GL_UNSIGNED_BYTE) && ((src_type == GL_UNSIGNED_BYTE))) { + GLuint tmp; + for (int i = 0; i < height; i++) { + for (int j = 0; j < width; j++) { + //tmp = *(const GLuint*)src_pos; + unsigned char* byte_src = (unsigned char*)src_pos; + #ifdef __BIG_ENDIAN__ + *(GLushort*)dst_pos = ((((int)byte_src[3])*77 + ((int)byte_src[2])*151 + ((int)byte_src[1])*28)&0xff00)>>8 | (byte_src[0]<<8); + #else + *(GLushort*)dst_pos = ((((int)byte_src[0])*77 + ((int)byte_src[1])*151 + ((int)byte_src[2])*28)&0xff00)>>8 | (byte_src[3]<<8); + #endif + src_pos += src_stride; + dst_pos += dst_stride; + } + dst_pos += dst_width; + src_pos += src_widthadj; + } + return true; + } + // BGRA -> LA + if ((src_format == GL_BGRA) && (dst_format == GL_LUMINANCE_ALPHA) && (dst_type == GL_UNSIGNED_BYTE) && ((src_type == GL_UNSIGNED_BYTE))) { + GLuint tmp; + for (int i = 0; i < height; i++) { + for (int j = 0; j < width; j++) { + //tmp = *(const GLuint*)src_pos; + unsigned char* byte_src = (unsigned char*)src_pos; + #ifdef __BIG_ENDIAN__ + *(GLushort*)dst_pos = ((((int)byte_src[1])*77 + ((int)byte_src[2])*151 + ((int)byte_src[3])*28)&0xff00)>>8 | (byte_src[0]<<8); + #else + *(GLushort*)dst_pos = ((((int)byte_src[2])*77 + ((int)byte_src[1])*151 + ((int)byte_src[0])*28)&0xff00)>>8 | (byte_src[3]<<8); + #endif + src_pos += src_stride; + dst_pos += dst_stride; + } + dst_pos += dst_width; + src_pos += src_widthadj; + } + return true; + } + // RGB(A) -> L + if (((src_format == GL_RGBA)||(src_format == GL_RGB)) && (dst_format == GL_LUMINANCE) && (dst_type == GL_UNSIGNED_BYTE) && ((src_type == GL_UNSIGNED_BYTE))) { + GLuint tmp; + for (int i = 0; i < height; i++) { + for (int j = 0; j < width; j++) { + //tmp = *(const GLuint*)src_pos; + unsigned char* byte_src = (unsigned char*)src_pos; + #ifdef __BIG_ENDIAN__ + *(unsigned char*)dst_pos = (((int)byte_src[3])*77 + ((int)byte_src[2])*151 + ((int)byte_src[1])*28)>>8; + #else + *(unsigned char*)dst_pos = (((int)byte_src[0])*77 + ((int)byte_src[1])*151 + ((int)byte_src[2])*28)>>8; + #endif + src_pos += src_stride; + dst_pos += dst_stride; + } + dst_pos += dst_width; + src_pos += src_widthadj; + } + return true; + } + // BGR(A) -> L + if (((src_format == GL_BGRA)||(src_format == GL_BGR)) && (dst_format == GL_LUMINANCE) && (dst_type == GL_UNSIGNED_BYTE) && ((src_type == GL_UNSIGNED_BYTE))) { + GLuint tmp; + for (int i = 0; i < height; i++) { + for (int j = 0; j < width; j++) { + //tmp = *(const GLuint*)src_pos; + unsigned char* byte_src = (unsigned char*)src_pos; + #ifdef __BIG_ENDIAN__ + *(unsigned char*)dst_pos = (((int)byte_src[1])*77 + ((int)byte_src[2])*151 + ((int)byte_src[3])*28)>>8; + #else + *(unsigned char*)dst_pos = (((int)byte_src[2])*77 + ((int)byte_src[1])*151 + ((int)byte_src[0])*28)>>8; + #endif + src_pos += src_stride; + dst_pos += dst_stride; + } + dst_pos += dst_width; + src_pos += src_widthadj; + } + return true; + } + // BGR(A) -> RGB + if (((src_format == GL_BGR)||(src_format == GL_BGRA)) && (dst_format == GL_RGB) && (dst_type == GL_UNSIGNED_BYTE) && ((src_type == GL_UNSIGNED_BYTE))) { + for (int i = 0; i < height; i++) { + for (int j = 0; j < width; j++) { + ((char*)dst_pos)[0] = ((char*)src_pos)[2]; + ((char*)dst_pos)[1] = ((char*)src_pos)[1]; + ((char*)dst_pos)[2] = ((char*)src_pos)[0]; + src_pos += src_stride; + dst_pos += dst_stride; + } + dst_pos += dst_width; + src_pos += src_widthadj; + } + return true; + } + // BGR -> RGBA + if (((src_format == GL_BGR)) && (dst_format == GL_RGBA) && (dst_type == GL_UNSIGNED_BYTE) && ((src_type == GL_UNSIGNED_BYTE))) { + for (int i = 0; i < height; i++) { + for (int j = 0; j < width; j++) { + ((char*)dst_pos)[0] = ((char*)src_pos)[2]; + ((char*)dst_pos)[1] = ((char*)src_pos)[1]; + ((char*)dst_pos)[2] = ((char*)src_pos)[0]; + ((char*)dst_pos)[3] = 255; + src_pos += src_stride; + dst_pos += dst_stride; + } + dst_pos += dst_width; + src_pos += src_widthadj; + } + return true; + } + // RGBA -> RGB + if ((src_format == GL_RGBA) && (dst_format == GL_RGB) && (dst_type == GL_UNSIGNED_BYTE) && ((src_type == GL_UNSIGNED_BYTE))) { + for (int i = 0; i < height; i++) { + for (int j = 0; j < width; j++) { + ((char*)dst_pos)[0] = ((char*)src_pos)[0]; + ((char*)dst_pos)[1] = ((char*)src_pos)[1]; + ((char*)dst_pos)[2] = ((char*)src_pos)[2]; + src_pos += src_stride; + dst_pos += dst_stride; + } + dst_pos += dst_width; + src_pos += src_widthadj; + } + return true; + } + // RGB(A) -> RGB565 + if (((src_format == GL_RGB)||(src_format == GL_RGBA)) && (dst_format == GL_RGB) && (dst_type == GL_UNSIGNED_SHORT_5_6_5) && ((src_type == GL_UNSIGNED_BYTE))) { + for (int i = 0; i < height; i++) { + for (int j = 0; j < width; j++) { + *(GLushort*)dst_pos = ((GLushort)(((char*)src_pos)[2]&0xf8)>>(3)) | ((GLushort)(((char*)src_pos)[1]&0xfc)<<(5-2)) | ((GLushort)(((char*)src_pos)[0]&0xf8)<<(11-3)); + src_pos += src_stride; + dst_pos += dst_stride; + } + dst_pos += dst_width; + src_pos += src_widthadj; + } + return true; + } + // BGR(A) -> RGB565 + if (((src_format == GL_BGR) || (src_format == GL_BGRA)) && (dst_format == GL_RGB) && (dst_type == GL_UNSIGNED_SHORT_5_6_5) && ((src_type == GL_UNSIGNED_BYTE))) { + for (int i = 0; i < height; i++) { + for (int j = 0; j < width; j++) { + *(GLushort*)dst_pos = ((GLushort)(((char*)src_pos)[0]&0xf8)>>(3)) | ((GLushort)(((char*)src_pos)[1]&0xfc)<<(5-2)) | ((GLushort)(((char*)src_pos)[2]&0xf8)<<(11-3)); + src_pos += src_stride; + dst_pos += dst_stride; + } + dst_pos += dst_width; + src_pos += src_widthadj; + } + return true; + } + // RGBA -> RGBA5551 + if ((src_format == GL_RGBA) && (dst_format == GL_RGBA) && (dst_type == GL_UNSIGNED_SHORT_5_5_5_1) && ((src_type == GL_UNSIGNED_BYTE))) { + for (int i = 0; i < height; i++) { + for (int j = 0; j < width; j++) { + *(GLushort*)dst_pos = ((GLushort)(((char*)src_pos)[2]&0xf8)>>(3-1)) | ((GLushort)(((char*)src_pos)[1]&0xf8)<<(5-2)) | ((GLushort)(((char*)src_pos)[0]&0xf8)<<(10-2)) | ((GLushort)(((char*)src_pos)[3])>>15); + src_pos += src_stride; + dst_pos += dst_stride; + } + dst_pos += dst_width; + src_pos += src_widthadj; + } + return true; + } + // BGRA -> RGBA5551 + if ((src_format == GL_BGRA) && (dst_format == GL_RGBA) && (dst_type == GL_UNSIGNED_SHORT_5_5_5_1) && ((src_type == GL_UNSIGNED_BYTE))) { + for (int i = 0; i < height; i++) { + for (int j = 0; j < width; j++) { + *(GLushort*)dst_pos = ((GLushort)(((char*)src_pos)[0]&0xf8)>>(3-1)) | ((GLushort)(((char*)src_pos)[1]&0xf8)<<(5-2)) | ((GLushort)(((char*)src_pos)[2]&0xf8)<<(10-2)) | ((GLushort)(((char*)src_pos)[3])>>15); + src_pos += src_stride; + dst_pos += dst_stride; + } + dst_pos += dst_width; + src_pos += src_widthadj; + } + return true; + } + // RGBA -> RGBA4444 + if ((src_format == GL_RGBA) && (dst_format == GL_RGBA) && (dst_type == GL_UNSIGNED_SHORT_4_4_4_4) && ((src_type == GL_UNSIGNED_BYTE))) { + for (int i = 0; i < height; i++) { + for (int j = 0; j < width; j++) { + *(GLushort*)dst_pos = ((GLushort)(((char*)src_pos)[3]&0xf0))>>(4) | ((GLushort)(((char*)src_pos)[2]&0xf0)) | ((GLushort)(((char*)src_pos)[1]&0xf0))<<(4) | ((GLushort)(((char*)src_pos)[0]&0xf0))<<(8); + src_pos += src_stride; + dst_pos += dst_stride; + } + dst_pos += dst_width; + src_pos += src_widthadj; + } + return true; + } + // BGRA -> RGBA4444 + if ((src_format == GL_BGRA) && (dst_format == GL_RGBA) && (dst_type == GL_UNSIGNED_SHORT_4_4_4_4) && ((src_type == GL_UNSIGNED_BYTE))) { + for (int i = 0; i < height; i++) { + for (int j = 0; j < width; j++) { + *(GLushort*)dst_pos = ((GLushort)(((char*)src_pos)[3]&0xf0)>>(4)) | ((GLushort)(((char*)src_pos)[0]&0xf0)) | ((GLushort)(((char*)src_pos)[1]&0xf0)<<(4)) | ((GLushort)(((char*)src_pos)[2]&0xf0)<<(8)); + src_pos += src_stride; + dst_pos += dst_stride; + } + dst_pos += dst_width; + src_pos += src_widthadj; + } + return true; + } + // BGRA4444 -> RGBA + if ((src_format == GL_BGRA) && (dst_format == GL_RGBA) && (dst_type == GL_UNSIGNED_BYTE) && (src_type == GL_UNSIGNED_SHORT_4_4_4_4_REV)) { + for (int i = 0; i < height; i++) { + for (int j = 0; j < width; j++) { + const GLushort pix = *(GLushort*)src_pos; + ((char*)dst_pos)[3] = ((pix>>12)&0x0f)<<4; + ((char*)dst_pos)[2] = ((pix>>8)&0x0f)<<4; + ((char*)dst_pos)[1] = ((pix>>4)&0x0f)<<4; + ((char*)dst_pos)[0] = ((pix)&0x0f)<<4; + src_pos += src_stride; + dst_pos += dst_stride; + } + dst_pos += dst_width; + src_pos += src_widthadj; + } + return true; + } + // RGBA5551 -> RGBA + if ((src_format == GL_RGBA) && (dst_format == GL_RGBA) && (dst_type == GL_UNSIGNED_BYTE) && (src_type == GL_UNSIGNED_SHORT_5_5_5_1)) { + for (int i = 0; i < height; i++) { + for (int j = 0; j < width; j++) { + const GLushort pix = *(GLushort*)src_pos; + ((char*)dst_pos)[0] = ((pix>>11)&0x1f)<<3; + ((char*)dst_pos)[1] = ((pix>>6)&0x1f)<<3; + ((char*)dst_pos)[2] = ((pix>>1)&0x1f)<<3; + ((char*)dst_pos)[3] = ((pix)&0x01)?255:0; + src_pos += src_stride; + dst_pos += dst_stride; + } + dst_pos += dst_width; + src_pos += src_widthadj; + } + return true; + } + if (! remap_pixel((const GLvoid *)src_pos, (GLvoid *)dst_pos, + src_color, src_type, dst_color, dst_type)) { + // fake convert, to get if it's ok or not + return false; + } + // special case for GL_COLOR_INDEX + if(src_format==GL_COLOR_INDEX) { + if(src_type!=GL_UNSIGNED_BYTE) + return false; // only unsigned byte for now + GLubyte tmp[4]; + int idx; + for (int i = 0; i < height; i++) { + for (int j = 0; j < width; j++) { + idx = (((*((GLubyte*)src_pos))<raster.index_shift) + glstate->raster.index_offset); + if (glstate->raster.map_i2i_size-1) + idx = glstate->raster.map_i2i[idx&(glstate->raster.map_i2i_size-1)]; + tmp[0] = glstate->raster.map_i2r[idx&(glstate->raster.map_i2r_size-1)]; + tmp[1] = glstate->raster.map_i2g[idx&(glstate->raster.map_i2g_size-1)]; + tmp[2] = glstate->raster.map_i2b[idx&(glstate->raster.map_i2b_size-1)]; + tmp[3] = glstate->raster.map_i2a[idx&(glstate->raster.map_i2a_size-1)]; + remap_pixel((const GLvoid *)tmp, (GLvoid *)dst_pos, + src_color, GL_FLOAT, dst_color, dst_type); + src_pos += src_stride; + dst_pos += dst_stride; + } + dst_pos += dst_width; + src_pos += src_widthadj; + } + } else { + for (int i = 0; i < height; i++) { + for (int j = 0; j < width; j++) { + remap_pixel((const GLvoid *)src_pos, (GLvoid *)dst_pos, + src_color, src_type, dst_color, dst_type); + src_pos += src_stride; + dst_pos += dst_stride; + } + dst_pos += dst_width; + src_pos += src_widthadj; + } + } + return true; +} + +bool pixel_transform(const GLvoid *src, GLvoid **dst, + GLuint width, GLuint height, + GLenum src_format, GLenum src_type, + const GLfloat *scales, const GLfloat *bias) +{ + const colorlayout_t *src_color; + GLuint pixels = width * height; + GLuint dst_size = pixels * pixel_sizeof(src_format, src_type); + src_color = get_color_map(src_format); + GLsizei src_stride = pixel_sizeof(src_format, src_type); + if (*dst == src || *dst == NULL) + *dst = malloc(dst_size); + uintptr_t src_pos = (uintptr_t)src; + uintptr_t dst_pos = (uintptr_t)*dst; + if (! transform_pixel((const GLvoid *)src_pos, (GLvoid *)dst_pos, + src_color, src_type, scales, bias)) { + // fake convert, to get if it's ok or not + return false; + } + for (int aa=0; aa %ux%u (%f/%f)\n", width, height, new_width, new_height, ratiox, ratioy); + GLvoid *dst; + uintptr_t src, pos, pixel; + + pixel_size = pixel_sizeof(format, type); + dst = malloc(pixel_size * new_width * new_height); + src = (uintptr_t)old; + pos = (uintptr_t)dst; + for (int y = 0; y < new_height; y++) { + int oldy = y*ratioy; if(oldy>=height) oldy=height-1; + for (int x = 0; x < new_width; x++) { + int oldx = x*ratiox; if(oldx>=width) oldx=width-1; + pixel = src + (oldx + + oldy * width) * pixel_size; + memcpy((GLvoid *)pos, (GLvoid *)pixel, pixel_size); + pos += pixel_size; + } + } + *new = dst; + return true; +} + +bool pixel_halfscale(const GLvoid *old, GLvoid **new, + GLuint width, GLuint height, + GLenum format, GLenum type) { + if(!old) { + *new = NULL; + return true; + } + GLuint pixel_size, new_width, new_height; + new_width = width / 2; if(!new_width) ++new_width; + new_height = height / 2; if(!new_height) ++new_height; +/* if (new_width*2!=width || new_height*2!=height) { + printf("LIBGL: halfscaling %ux%u failed\n", width, height); + return false; + }*/ + //printf("LIBGL: halfscaling %ux%u -> %ux%u (%s / %s)\n", width, height, new_width, new_height, PrintEnum(format), PrintEnum(type)); + const colorlayout_t *src_color; + src_color = get_color_map(format); + GLvoid *dst; + uintptr_t src, pos, pix0, pix1, pix2, pix3; + + pixel_size = pixel_sizeof(format, type); + dst = malloc(pixel_size * new_width * new_height); + src = (uintptr_t)old; + pos = (uintptr_t)dst; + const int dx = (width>1)?1:0; + const int mx = dx + 1; + const int dy = (height>1)?1:0; + const int my = dy + 1; + for (int y = 0; y < new_height; y++) { + for (int x = 0; x < new_width; x++) { + pix0 = src + ((x * mx) + + (y * my) * width) * pixel_size; + pix1 = src + ((x * mx + dx) + + (y * my) * width) * pixel_size; + pix2 = src + ((x * mx) + + (y * my + dy) * width) * pixel_size; + pix3 = src + ((x * mx + dx) + + (y * my + dy) * width) * pixel_size; + half_pixel((GLvoid *)pix0, (GLvoid *)pix1, (GLvoid *)pix2, (GLvoid *)pix3, (GLvoid *)pos, src_color, type); + pos += pixel_size; + } + } + *new = dst; + return true; +} + +bool pixel_thirdscale(const GLvoid *old, GLvoid **new, + GLuint width, GLuint height, + GLenum format, GLenum type) { + GLuint pixel_size, new_width, new_height, dest_size; + new_width = width / 2; if(!new_width) ++new_width; + new_height = height / 2; if(!new_height) ++new_height; + if (new_width*2!=width || new_height*2!=height || format!=GL_RGBA || type!=GL_UNSIGNED_BYTE) { + //printf("LIBGL: thirdscaling %ux%u failed\n", width, height); + return false; + } +// printf("LIBGL: halfscaling %ux%u -> %ux%u\n", width, height, new_width, new_height); + const colorlayout_t *src_color; + src_color = get_color_map(format); + GLvoid *dst; + uintptr_t src, pos, pix0, pix1, pix2, pix3; + + pixel_size = pixel_sizeof(format, type); + dest_size = pixel_sizeof(format, GL_UNSIGNED_SHORT_4_4_4_4); + dst = malloc(dest_size * new_width * new_height); + src = (uintptr_t)old; + pos = (uintptr_t)dst; + const int dx = (width>1)?1:0; + const int mx = dx + 1; + const int dy = (height>1)?1:0; + const int my = dy + 1; + GLubyte tmp[4]; + for (int y = 0; y < new_height; y++) { + for (int x = 0; x < new_width; x++) { + pix0 = src + ((x * mx) + + (y * my) * width) * pixel_size; + pix1 = src + ((x * mx + dx) + + (y * my) * width) * pixel_size; + pix2 = src + ((x * mx) + + (y * my + dy) * width) * pixel_size; + pix3 = src + ((x * mx + dx) + + (y * my + dy) * width) * pixel_size; + half_pixel((GLvoid *)pix0, (GLvoid *)pix1, (GLvoid *)pix2, (GLvoid *)pix3, (GLvoid *)tmp, src_color, type); + *((GLushort*)pos) = (((GLushort)tmp[0])&0xf0)<<8 | (((GLushort)tmp[1])&0xf0)<<4 | (((GLushort)tmp[2])&0xf0) | (((GLushort)tmp[3])>>4); + pos += dest_size; + } + } + *new = dst; + return true; +} + +bool pixel_quarterscale(const GLvoid *old, GLvoid **new, + GLuint width, GLuint height, + GLenum format, GLenum type) { + GLuint pixel_size, new_width, new_height; + new_width = width / 4; if(!new_width) ++new_width; + new_height = height / 4; if(!new_height) ++new_height; +/* if (new_width*4!=width || new_height*4!=height) { + printf("LIBGL: quarterscaling %ux%u failed\n", width, height); + return false; + }*/ +// printf("LIBGL: quarterscaling %ux%u -> %ux%u\n", width, height, new_width, new_height); + const colorlayout_t *src_color; + src_color = get_color_map(format); + GLvoid *dst; + uintptr_t src, pos, pix[16]; + + pixel_size = pixel_sizeof(format, type); + dst = malloc(pixel_size * new_width * new_height); + src = (uintptr_t)old; + pos = (uintptr_t)dst; + const int dxs[4] = {0, width>1?1:0, width>2?2:0, width>3?3:width>1?1:0}; + const int dys[4] = {0, height>1?1:0, height>2?2:0, height>3?3:height>1?1:0}; + for (int y = 0; y < new_height; y++) { + for (int x = 0; x < new_width; x++) { + for (int dx=0; dx<4; dx++) { + for (int dy=0; dy<4; dy++) { + pix[dx+dy*4] = src + ((x * 4 + dxs[dx]) + + (y * 4 + dys[dy]) * width) * pixel_size; + } + } + quarter_pixel((const GLvoid **)pix, (GLvoid *)pos, src_color, type); + pos += pixel_size; + } + } + *new = dst; + return true; +} + +bool pixel_doublescale(const GLvoid *old, GLvoid **new, + GLuint width, GLuint height, + GLenum format, GLenum type) { + if(!old) { + *new = NULL; + return true; + } + GLuint pixel_size, new_width, new_height; + new_width = width * 2; + new_height = height * 2; + //printf("LIBGL: doublescaling %ux%u -> %ux%u (%s / %s)\n", width, height, new_width, new_height, PrintEnum(format), PrintEnum(type)); + const colorlayout_t *src_color; + src_color = get_color_map(format); + GLvoid *dst; + uintptr_t src, pos, pix0, pix1, pix2, pix3; + + pixel_size = pixel_sizeof(format, type); + dst = malloc(pixel_size * new_width * new_height); + src = (uintptr_t)old; + pos = (uintptr_t)dst; + const int dx = (width>1)?1:0; + const int dy = (height>1)?1:0; + for (int y = 0; y+1 < new_height; y+=2) { + for (int x = 0; x+1 < new_width; x+=2) { + pix0 = src + ((x / 2) + + (y / 2) * width) * pixel_size; + memcpy((void*)pos, (void*)pix0, pixel_size); + memcpy((void*)(pos+new_width*pixel_size), (void*)pix0, pixel_size); + pos += pixel_size; + memcpy((void*)pos, (void*)pix0, pixel_size); + memcpy((void*)(pos+new_width*pixel_size), (void*)pix0, pixel_size); + pos += pixel_size; + } + pos += new_width*pixel_size; + } + *new = dst; + return true; +} + +bool pixel_to_ppm(const GLvoid *pixels, GLuint width, GLuint height, + GLenum format, GLenum type, GLuint name, GLuint align) { + // this function should be redone, using write_png from STB for example + if (! pixels) + return false; + + GLvoid *src=0; + char filename[64]; + int size = /*4 * */3 * width * height; + if (format == GL_RGB && type == GL_UNSIGNED_BYTE) { + src = (GLvoid*)pixels; + } else { + if (! pixel_convert(pixels, (GLvoid **)&src, width, height, format, type, GL_RGB, GL_UNSIGNED_BYTE, 0, align)) { + return false; + } + } + + sprintf(filename, "/tmp/tex.%d.ppm", name); + FILE *fd = fopen(filename, "w"); + fprintf(fd, "P6 %d %d %d\n", width, height, 255); + fwrite(src, 1, size, fd); + fclose(fd); + return true; +} diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/pixel.h b/Projects/Android/jni/SupportLibs/gl4es/src/gl/pixel.h new file mode 100644 index 0000000..183d202 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/pixel.h @@ -0,0 +1,53 @@ +#ifndef _GL4ES_PIXEL_H_ +#define _GL4ES_PIXEL_H_ + +#include +#include "gles.h" + +typedef struct { + GLenum type; + GLint red, green, blue, alpha; +} colorlayout_t; + +typedef struct { + GLfloat r, g, b, a; +} pixel_t; + +#define widthalign(width, align) ((((uintptr_t)(width))+((uintptr_t)(align)-1))&(~((uintptr_t)(align)-1))) + +bool pixel_convert(const GLvoid *src, GLvoid **dst, + GLuint width, GLuint height, + GLenum src_format, GLenum src_type, + GLenum dst_format, GLenum dst_type, GLuint stride, GLuint align); + +bool pixel_transform(const GLvoid *src, GLvoid **dst, + GLuint width, GLuint height, + GLenum src_format, GLenum src_type, + const GLfloat *scale, const GLfloat *bias); + +bool pixel_scale(const GLvoid *src, GLvoid **dst, + GLuint width, GLuint height, + GLuint new_width, GLuint new_height, + GLenum format, GLenum type); + +bool pixel_halfscale(const GLvoid *src, GLvoid **dst, + GLuint width, GLuint height, + GLenum format, GLenum type); + +bool pixel_thirdscale(const GLvoid *src, GLvoid **dst, + GLuint width, GLuint height, + GLenum format, GLenum type); + +bool pixel_quarterscale(const GLvoid *src, GLvoid **dst, + GLuint width, GLuint height, + GLenum format, GLenum type); + +bool pixel_doublescale(const GLvoid *src, GLvoid **dst, + GLuint width, GLuint height, + GLenum format, GLenum type); + +bool pixel_to_ppm(const GLvoid *pixels, + GLuint width, GLuint height, + GLenum format, GLenum type, GLuint name, GLuint align); + +#endif // _GL4ES_PIXEL_H_ diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/planes.c b/Projects/Android/jni/SupportLibs/gl4es/src/gl/planes.c new file mode 100644 index 0000000..6540b70 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/planes.c @@ -0,0 +1,33 @@ +#include "planes.h" + +#include "../glx/hardext.h" +#include "loader.h" +#include "matrix.h" +#include "matvec.h" + +void gl4es_glClipPlanef(GLenum plane, const GLfloat *equation) +{ + /* + When glClipPlane is called, + equation is transformed by the inverse of the modelview matrix and stored in the resulting eye coordinates. + Subsequent changes to the modelview matrix have no effect on the stored plane-equation components. + If the dot product of the eye coordinates of a vertex with the stored plane equation components is positive or zero, + the vertex is in with respect to that clipping plane. Otherwise, it is out. + */ + PUSH_IF_COMPILING(glClipPlanef); //TODO: fix that, equation is an array and should be copied before beeing put in the stack + if(plane=GL_CLIP_PLANE0+hardext.maxplanes) { + errorShim(GL_INVALID_ENUM); + return; + } + if(hardext.esversion==1) { + LOAD_GLES2(glClipPlanef); + errorGL(); + gles_glClipPlanef(plane, equation); + } else { // TODO: should fist compute the clipplane and compare to stored one before sending to hardware + int p = plane-GL_CLIP_PLANE0; + matrix_vector(getInvMVMat(), equation, glstate->planes[p]); //Tested, seems ok + noerrorShim(); + } +} + +void glClipPlanef(GLenum pname, const GLfloat* params) AliasExport("gl4es_glClipPlanef"); \ No newline at end of file diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/planes.h b/Projects/Android/jni/SupportLibs/gl4es/src/gl/planes.h new file mode 100644 index 0000000..5b7e342 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/planes.h @@ -0,0 +1,8 @@ +#ifndef _GL4ES_PLANES_H_ +#define _GL4ES_PLANES_H_ + +#include "gles.h" + +void gl4es_glClipPlanef(GLenum plane, const GLfloat *equation); + +#endif // _GL4ES_PLANES_H_ diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/pointsprite.c b/Projects/Android/jni/SupportLibs/gl4es/src/gl/pointsprite.c new file mode 100644 index 0000000..b521669 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/pointsprite.c @@ -0,0 +1,129 @@ +#include "pointsprite.h" + +#include "../glx/hardext.h" +#include "debug.h" +#include "fpe.h" +#include "gl4es.h" +#include "glstate.h" +#include "loader.h" + +void gl4es_glPointParameteri(GLenum pname, GLint param) +{ + gl4es_glPointParameterf(pname, param); +} +void glPointParameteri(GLenum pname, GLint param) AliasExport("gl4es_glPointParameteri"); + +void gl4es_glPointParameteriv(GLenum pname, const GLint * params) +{ + GLfloat tmp[3]; + int v=(pname==GL_POINT_DISTANCE_ATTENUATION)?3:1; + for (int i=0; ilist.active) + if (glstate->list.compiling) { + if (pname == GL_POINT_DISTANCE_ATTENUATION) { + NewStage(glstate->list.active, STAGE_POINTPARAM); + rlPointParamOp(glstate->list.active, 1, params); + return; + } else { + gl4es_glPointParameterf(pname, params[0]); + return; + } + } else flush(); + + switch(pname) { + case GL_POINT_SIZE_MIN: + if(*params<0.0f) { + errorShim(GL_INVALID_VALUE); + return; + } + if(glstate->pointsprite.sizeMin == *params) { + noerrorShim(); + return; + } + glstate->pointsprite.sizeMin = *params; + break; + case GL_POINT_SIZE_MAX: + if(*params<0.0f) { + errorShim(GL_INVALID_VALUE); + return; + } + if(glstate->pointsprite.sizeMax == *params) { + noerrorShim(); + return; + } + glstate->pointsprite.sizeMax = *params; + break; + case GL_POINT_FADE_THRESHOLD_SIZE: + if(*params<0.0f) { + errorShim(GL_INVALID_VALUE); + return; + } + if(glstate->pointsprite.fadeThresholdSize == *params) { + noerrorShim(); + return; + } + glstate->pointsprite.fadeThresholdSize = *params; + break; + case GL_POINT_DISTANCE_ATTENUATION: + if(*params<0.0f) { + errorShim(GL_INVALID_VALUE); + return; + } + if(memcmp(glstate->pointsprite.distance, params, 3*sizeof(GLfloat))==0) { + noerrorShim(); + return; + } + memcpy(glstate->pointsprite.distance, params, 3*sizeof(GLfloat)); + break; + case GL_POINT_SPRITE_COORD_ORIGIN: + if(*params!=GL_UPPER_LEFT && *params!=GL_LOWER_LEFT) { + errorShim(GL_INVALID_VALUE); + return; + } + if(glstate->pointsprite.coordOrigin == *params) { + noerrorShim(); + return; + } + if(glstate->fpe_state) { + if(*params==GL_LOWER_LEFT) + glstate->fpe_state->pointsprite_upper = 0; + else + glstate->fpe_state->pointsprite_upper = 1; + } + glstate->pointsprite.coordOrigin = *params; + break; + } + + LOAD_GLES_FPE(glPointParameterfv); + errorGL(); + gles_glPointParameterfv(pname, params); +} +void glPointParameterfv(GLenum pname, const GLfloat * params) AliasExport("gl4es_glPointParameterfv"); +void glPointParameterfvARB(GLenum pname, const GLfloat * params) AliasExport("gl4es_glPointParameterfv"); +void glPointParameterfvEXT(GLenum pname, const GLfloat * params) AliasExport("gl4es_glPointParameterfv"); + +void gl4es_glPointSize(GLfloat size) { + if(size<=0.0f) { + errorShim(GL_INVALID_VALUE); + return; + } + glstate->pointsprite.size = size; + errorGL(); + LOAD_GLES_FPE(glPointSize); + gles_glPointSize(size); +} +void glPointSize(GLfloat size) AliasExport("gl4es_glPointSize"); diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/pointsprite.h b/Projects/Android/jni/SupportLibs/gl4es/src/gl/pointsprite.h new file mode 100644 index 0000000..e01fa14 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/pointsprite.h @@ -0,0 +1,22 @@ +#ifndef _GL4ES_POINTSPRITE_H_ +#define _GL4ES_POINTSPRITE_H_ + +#include "gles.h" + +typedef struct { + GLfloat size; + GLfloat sizeMin; + GLfloat sizeMax; + GLfloat fadeThresholdSize; + GLfloat distance[3]; + GLenum coordOrigin; +} pointsprite_t; + +void gl4es_glPointParameteri(GLenum pname, GLint param); +void gl4es_glPointParameteriv(GLenum pname, const GLint * params); +void gl4es_glPointParameterf(GLenum pname, GLfloat param); +void gl4es_glPointParameterfv(GLenum pname, const GLfloat * params); + +void gl4es_glPointSize(GLfloat size); + +#endif // _GL4ES_POINTSPRITE_H_ diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/preproc.c b/Projects/Android/jni/SupportLibs/gl4es/src/gl/preproc.c new file mode 100644 index 0000000..7ba7576 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/preproc.c @@ -0,0 +1,762 @@ +#include +#include +#include +#include +#include "khash.h" + +#include "preproc.h" +#include "string_utils.h" + +//#define DEBUG +#ifdef DEBUG +#define DBG(a) a +#pragma GCC optimize 0 +#else +#define DBG(a) +#endif + +typedef enum _eTokenType { + TK_NULL = 0, + TK_SPACE, + TK_SHARP, + TK_NEWLINE, + TK_INT, + TK_FLOAT, + TK_PLUS, + TK_MINUS, + TK_EQUAL, + TK_SLASH, + TK_DOUBLESLASH, + TK_MULTIPLY, + TK_BACKSLASH, + TK_OPENBRACE, + TK_CLOSEBRACE, + TK_OPENCURLY, + TK_CLOSECURLY, + TK_OPENBRAKET, + TK_CLOSEBRAKET, + TK_OPENCOMMENT, + TK_CLOSECOMMENT, + TK_COLUMN, + TK_SEMICOLUMN, + TK_COMMA, + TK_DOT, + TK_AMP, + TK_POW, + TK_PIPE, + TK_EXCLAM, + TK_POINT, + TK_GREATER, + TK_LESS, + TK_DOUBLEEQUAL, + TK_TILDE, + TK_TEXT, + TK_TEXTCOMMENT +} eTokenType; + +#define MAXSTR 500 + +typedef struct _uToken { + eTokenType type; + char str[MAXSTR]; + int integer; + float real; +} uToken; + +eTokenType NextTokenComment(char **p, uToken *tok) { + tok->type = TK_NULL; + tok->str[0] = 0; + if(!**p) return tok->type; + + char c = **p; + (*p)++; + char nextc = **p; + int nb = 0; + int isfloat = 0; + int isneg = 1; // multiply by it... + float fnb = 0.f; + int cnt = 0; + float fcnt = 0.f; + + tok->str[0]=c; tok->str[1]=0; + + switch (c) { + case 10: + if(nextc==13) + (*p)++; + strcpy(tok->str, "\n"); + tok->type = TK_NEWLINE; + break; + case 13: + if(nextc==10) + (*p)++; + strcpy(tok->str, "\n"); + tok->type = TK_NEWLINE; + break; + case ' ': + case '\t': + while(nextc==' ' || nextc=='\t') { int l=strlen(tok->str); tok->str[l]=nextc; tok->str[l+1]=0; (*p)++; nextc=**p; } + tok->type = TK_SPACE; + break; + case '/': + if(nextc=='/') { + (*p)++; + tok->type=TK_DOUBLESLASH; + strcpy(tok->str, "//"); + } else if(nextc=='*') { + (*p)++; + tok->type=TK_OPENCOMMENT; + strcpy(tok->str, "/*"); + } else { + tok->type=TK_SLASH; + } + break; + case '*': + if(nextc=='/') { + (*p)++; + tok->type=TK_CLOSECOMMENT; + strcpy(tok->str, "*/"); + } else { + tok->type=TK_MULTIPLY; + } + break; + default: + // all other are plain Ids... + cnt=1; + tok->type=TK_TEXTCOMMENT; + while(cnt!=(MAXSTR-1) && (nextc=='_' || (nextc>='0' && nextc<='9') || (nextc>='A' && nextc<='Z') || (nextc>='a' && nextc<='z'))) { + tok->str[cnt]=nextc; + (*p)++; nextc=**p; + ++cnt; + } + tok->str[cnt]=0; + } + + return tok->type; +} + +eTokenType NextToken(char **p, uToken *tok) { + tok->type = TK_NULL; + tok->str[0] = 0; + if(!**p) return tok->type; + + char c = **p; + (*p)++; + char nextc = **p; + int nb = 0; + int isfloat = 0; + int isneg = 1; // multiply by it... + float fnb = 0.f; + int cnt = 0; + float fcnt = 0.f; + + tok->str[0]=c; tok->str[1]=0; + + switch (c) { + case 10: + if(nextc==13) + (*p)++; + tok->type = TK_NEWLINE; + strcpy(tok->str, "\n"); + break; + case 13: + if(nextc==10) + (*p)++; + tok->type = TK_NEWLINE; + strcpy(tok->str, "\n"); + break; + case ' ': + case '\t': + while(nextc==' ' || nextc=='\t') { int l=strlen(tok->str); tok->str[l]=nextc; tok->str[l+1]=0; (*p)++; nextc=**p; } + tok->type = TK_SPACE; + break; + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + nb=c-'0'; + // we don't know if it's an int or a float at first... + if(nextc=='x' && nb==0) { + // hex number, so int... + (*p)++; nextc=**p; + while((nextc>='0' && nextc<='9') || (nextc>='a' && nextc<='f') || (nextc>='A' && nextc<='F')) { + nb=nb*16; + if(nextc>='0' && nextc<='9') + nb+=nextc-'0'; + else if(nextc>='a' && nextc<='f') + nb+=nextc-'a'+10; + else if(nextc>='A' && nextc<='F') + nb+=nextc-'A'+10; + (*p)++; nextc=**p; + } + tok->type = TK_INT; + tok->integer = nb; + sprintf(tok->str, "0x%x", nb); + } else { + while(nextc>='0' && nextc<='9') { nb=nb*10+nextc-'0'; (*p)++; nextc=**p;} + if(nextc=='.' || nextc=='f' || nextc=='e') { + isfloat = 1; + fnb=nb; + if(nextc=='.') { + (*p)++; nextc=**p; + fcnt = 0.1f; + while(nextc>='0' && nextc<='9') { + fnb+=(nextc-'0')*fcnt; + fcnt/=10.f; + (*p)++; nextc=**p; + } + } + if(nextc=='e') { + // exponent + (*p)++; nextc=**p; + nb=0; + int expsign = 1; + if(nextc=='-' || nextc=='+') { + if(nextc=='-') expsign = -1; + (*p)++; nextc=**p; + } + while(nextc>='0' && nextc<='9') { nb=nb*10+nextc-'0'; (*p)++; nextc=**p;} + fnb=powf(fnb, nb*expsign); + } + if(nextc=='f') { + (*p)++; nextc=**p; + } + fnb*=isneg; + tok->type = TK_FLOAT; + tok->real = fnb; + sprintf(tok->str, "%f", fnb); + } else { + tok->type = TK_INT; + tok->integer = nb; + sprintf(tok->str, "%d", nb); + } + } + break; + case '/': + if(nextc=='/') { + (*p)++; + tok->type=TK_DOUBLESLASH; + strcpy(tok->str, "//"); + } else if(nextc=='*') { + (*p)++; + tok->type=TK_OPENCOMMENT; + strcpy(tok->str, "/*"); + } else { + tok->type=TK_SLASH; + } + break; + case '*': + if(nextc=='/') { + (*p)++; + tok->type=TK_CLOSECOMMENT; + strcpy(tok->str, "*/"); + } else { + tok->type=TK_MULTIPLY; + } + break; + case '=': tok->type=TK_EQUAL; break; + case '~': tok->type=TK_TILDE; break; + case '#': tok->type=TK_SHARP; break; + case '(': tok->type=TK_OPENBRACE; break; + case ')': tok->type=TK_CLOSEBRACE; break; + case '{': tok->type=TK_OPENCURLY; break; + case '}': tok->type=TK_CLOSECURLY; break; + case '[': tok->type=TK_OPENBRAKET; break; + case ']': tok->type=TK_CLOSEBRAKET; break; + case '&': tok->type=TK_AMP; break; + case '^': tok->type=TK_POW; break; + case '|': tok->type=TK_PIPE; break; + case '\\': tok->type=TK_BACKSLASH; break; + case '<': tok->type=TK_LESS; break; + case '>': tok->type=TK_GREATER; break; + case '+': tok->type=TK_PLUS; break; + case '-': tok->type=TK_MINUS; break; + case ':': tok->type=TK_COLUMN; break; + case ';': tok->type=TK_SEMICOLUMN; break; + case ',': tok->type=TK_COMMA; break; + case '.': tok->type=TK_DOT; break; + case '!': tok->type=TK_EXCLAM; break; + // todo: char and string? + default: + // all other are plain Ids... + cnt=1; + tok->type=TK_TEXT; + while(cnt!=(MAXSTR-1) && (nextc=='_' || (nextc>='0' && nextc<='9') || (nextc>='A' && nextc<='Z') || (nextc>='a' && nextc<='z'))) { + tok->str[cnt]=nextc; + (*p)++; nextc=**p; + ++cnt; + } + tok->str[cnt]=0; + } + + return tok->type; +} + +eTokenType GetToken(char **p, uToken *tok, int incomment) { + eTokenType ret; + if (incomment) + ret = NextTokenComment(p, tok); + else + ret = NextToken(p, tok); + return ret; +} + +typedef struct { + int cap; + int sz; + int *ifs; +} stackif_t; + +static void push_if(stackif_t *st, int v) { + if(st->sz == st->cap) { + st->cap += 16; + st->ifs = (int*)realloc(st->ifs, sizeof(int)*st->cap); + } + st->ifs[st->sz++] = v; +} + +static int pop_if(stackif_t *st) { + if(st->sz) + return st->ifs[--st->sz]; + return -1; +} + +static int top_if(stackif_t *st) { + if(st->sz) + return st->ifs[st->sz-1]; + return -1; +} +static void not_top_if(stackif_t *st) { + if(st->sz && st->ifs[st->sz-1]!=-1) + st->ifs[st->sz-1] = 1 - st->ifs[st->sz-1]; +} + +static int result_if(stackif_t *st) { + for (int i=0; isz; ++i) { + if(st->ifs[i] == 1) return 1; + else if(st->ifs[i] == -1) return -1; + } + return 0; +} + +KHASH_MAP_INIT_STR(define, int); +KHASH_MAP_INIT_STR(alldefine, char*); + +char* preproc(const char* code, int keepcomments, int gl_es, extensions_t* exts) { + DBG(printf("Preproc on: =========\n%s\n=================\n", code);) + + uToken tok; + char* p = (char*)code; + char* oldp = NULL; + int cap=1000; + char* ncode = (char*)malloc(1000); + ncode[0]=0; + int sz=1; + int status=0; + int write=1; + int incomment=0; + int indefined=0; + int newline=0; + int gettok=0; + int notok = 0; + char extname[50]; + khint_t k; + int ret; + char *defname; //used for #define or #if + int defval; + stackif_t stackif = {0}; + int nowrite_ifs = 0; + int current_if = 0; + int need_pop = 0; + + khash_t(alldefine) *alldefines = kh_init(alldefine); // will conatin all defines, even the one without int inside + + khash_t(define) *defines = kh_init(define); + if(gl_es) { + k = kh_put(define, defines, "GL_ES", &ret); + kh_value(defines, k) = 0; + } + push_if(&stackif, 0); // default to OK + GetToken(&p, &tok, incomment); + while(tok.type!=TK_NULL) { + // pop #if / #endif status + if(need_pop) { + pop_if(&stackif); + nowrite_ifs = result_if(&stackif); + need_pop = 0; + + } + // pre get token switch + switch(status) { + case 110: // line comment done... + case 210: // block comment done + if(!write && newline) { + gettok=0; + tok.type=TK_NEWLINE; + strcpy(tok.str, "\n"); + } + write = 1; + status = (status==210)?1:0; + incomment=0; + newline=0; + break; + } + // get token (if needed) + if (gettok) GetToken(&p, &tok, incomment); + gettok=1; + // post get token switch + if(tok.type!=TK_NULL) { + switch(status) { + case 0: // regular... + case 1: + if(tok.type==TK_DOUBLESLASH) { + status = 100; // line comment + incomment = 1; + newline = 1; + if(!keepcomments) write=0; + } else if(tok.type==TK_OPENCOMMENT) { + status = 200; // multi-line comment + incomment = 1; + if(!keepcomments) write=0; + } else if(tok.type==TK_SHARP && !incomment && status==0) { + oldp = p-1; // lets buffer the line + status = 300; + } else if(tok.type==TK_NEWLINE) + status = 0; + else if(tok.type!=TK_SPACE) + status = 1; // everything else but space set status to 1... + break; + + // line comment... + case 100: + if(tok.type==TK_BACKSLASH) { + status = 120; // is it backslash+endline for multiline? + } else if(tok.type==TK_NEWLINE) { + status = 110; + } + break; + case 120: + status = 100; // continue comment, what ever follow (NewLine or anything else) + break; + + // block comment... + case 200: + if(tok.type==TK_NEWLINE) + newline=1; + if(tok.type==TK_CLOSECOMMENT) { + status=210; + } + break; + + // # (of ifdef or extension) + case 300: + if(tok.type!=TK_SPACE) + if(tok.type==TK_TEXT) { + if(!strcmp(tok.str, "ifdef")) + status=310; + else if(!strcmp(tok.str, "ifndef")) + status=320; + else if(!strcmp(tok.str, "if")) { + // #if defined(GL_ES) not supported for now + push_if(&stackif, -1); + if(nowrite_ifs==1) { + status = 398; notok = 1; + } else { + status = 390; + { + int l = p - oldp; + memcpy(tok.str, oldp, l); + tok.str[l]='\0'; + oldp = 0; + } + } + nowrite_ifs = result_if(&stackif); + } else if(!strcmp(tok.str, "else")) { + status = 399; + // ifs handling + { + not_top_if(&stackif); + int v = result_if(&stackif); + if(v!=-1) { + notok = 1; + status = 398; + } + nowrite_ifs = v; + } + } else if(!strcmp(tok.str, "endif")) { + status = 399; + { + need_pop = 1; + if(nowrite_ifs!=-1) { + notok = 1; + status = 398; + } + } + } else if(!strcmp(tok.str, "extension")) { + status = 410; + } else if(!strcmp(tok.str, "pragma")) { + status = 510; + } else if(!strcmp(tok.str, "define")) { + status = 610; + } else status=399; + } else status = 399; // meh? + break; + + // ifdef + case 310: + if(tok.type==TK_SPACE) + status = 310; + else if(tok.type==TK_TEXT) { + int v; + if(gl_es && (strcmp(tok.str, "GL_ES")==0)) + v = 1; + else if(kh_get(alldefine, alldefines, tok.str)!=kh_end(alldefines)) { + v = 0; + } else if (strncmp(tok.str, "GL_", 3)==0) + v = -1; + else + v = 1; + push_if(&stackif, v); + nowrite_ifs = result_if(&stackif); + if(nowrite_ifs!=-1) { + status = 398; notok = 1; + } else + status = 399; + } else {push_if(&stackif, -1); nowrite_ifs = result_if(&stackif);status = 399;} + break; + + // ifndef + case 320: + if(tok.type==TK_SPACE) + status = 320; + else if(tok.type==TK_TEXT) { + int v; + if(gl_es && strcmp(tok.str, "GL_ES")==0) + v = 0; + else if(kh_get(alldefine, alldefines, tok.str)!=kh_end(alldefines)) { + v = 1; + } else if (strncmp(tok.str, "GL_", 3)==0) + v = -1; + else + v = 0; + push_if(&stackif, v); + nowrite_ifs = result_if(&stackif); + if(nowrite_ifs!=-1) { + status = 398; notok = 1; + } else + status = 399; + } else {push_if(&stackif, -1); nowrite_ifs = result_if(&stackif); status = 399;} + break; + + // #if ... + case 390: + if (tok.type == TK_NEWLINE) { + status = 0; + } else if (tok.type == TK_TEXT) { + if(!strcmp(tok.str, "defined")) + status = 710; + } + break; + + // end of #ifdef GL_ES and variant.. + case 398: + if(tok.type==TK_NEWLINE) { + oldp = NULL; + status = 0; + } + break; + + // fallback for #ifdef GL_ES, write the line back... + case 399: + { + int l = p - oldp; + memcpy(tok.str, oldp, l); + tok.str[l]='\0'; + oldp = 0; + } + status = (tok.type==TK_NEWLINE)?0:1; + break; + // #extension + case 410: + if(tok.type==TK_SPACE) { + // nothing... + } else if(tok.type==TK_TEXT && strlen(tok.str)<50) { + strcpy(extname, tok.str); + status = 420; + } else { + status = 399; // fallback, syntax error... + } + break; + // after the name and before the ':' of #extension + case 420: + if(tok.type==TK_SPACE) { + // nothing... + } else if (tok.type==TK_COLUMN) { + status=430; + } else { + status = 399; // fallback, syntax error... + } + break; + // after the ':' of #extension + case 430: + if(tok.type==TK_SPACE) { + // nothing... + } else if(tok.type==TK_TEXT) { + int state = -1; + if(!strcmp(tok.str, "disable")) + state = 0; + else if(!strcmp(tok.str, "warn")) + state = 1; + else if(!strcmp(tok.str, "enable")) + state = 1; + else if(!strcmp(tok.str, "require")) + state = 1; + if(state!=-1) { + if(exts->size==exts->cap) { + exts->cap += 4; + exts->ext = (extension_t*)realloc(exts->ext, sizeof(extension_t)*exts->cap); + } + strcpy(exts->ext[exts->size].name, extname); + exts->ext[exts->size].state = state; + ++exts->size; + status = 398; // all done + } else + status = 399; // error, unknown keyword + } else { + status = 399; // fallback, syntax error... + } + break; + // #pragma + case 510: + if(tok.type==TK_SPACE) { + // nothing... + } else if(tok.type==TK_TEXT && strlen(tok.str)<50) { + if(strcmp(tok.str, "message")==0) + status = 398; //pragma message are removed + else if(strcmp(tok.str, "parameter")==0) + status = 398; //pragma message are removed + else + status = 399; // other pragma as left as-is + } else { + status = 399; // fallback, syntax error... + } + break; + // #define + case 610: + if(tok.type==TK_SPACE) { + // nothing... + } else if(tok.type==TK_TEXT && strlen(tok.str)<50) { + defname = strdup(tok.str); + k = kh_put(alldefine, alldefines, defname, &ret); + kh_value(alldefines, k) = defname; + status = 620; // and now get the value + } else { + status = 399; // fallback, define name too long... + } + break; + case 620: + if(tok.type==TK_SPACE) { + // nothing... + } else if(tok.type==TK_INT) { + defval = tok.integer; + status = 630; // check if end of line (so it's a simple define) + } else if(tok.type==TK_NEWLINE) { + { + int l = p - oldp; + memcpy(tok.str, oldp, l); + tok.str[l]='\0'; + oldp = 0; + } + status = 0; + } else { + status = 399; // fallback + } + break; + case 630: + if(tok.type==TK_SPACE) { + // nothing... + } else if(tok.type==TK_NEWLINE) { + k = kh_put(define, defines, defname, &ret); + kh_value(defines, k) = defval; + { + int l = p - oldp; + memcpy(tok.str, oldp, l); + tok.str[l]='\0'; + oldp = 0; + } + status = 0; // ok, define added to collection, left the line as-is anyway + } else { + status = 399; // fallback + } + break; + // #defined + case 710: + if(tok.type==TK_SPACE) { + // nothing... + } else if(tok.type==TK_OPENBRACE) { + status = 720; // and now get the value + indefined = 1; + } else { + status = 399; // fallback... + } + break; + case 720: + if(tok.type==TK_SPACE || tok.type==TK_TEXT) { + // nothing... + } else if (tok.type==TK_CLOSEBRACE) { + indefined = 0; + status = 730; + } else { + indefined = 0; + status = 399; + } + break; + case 730: + if(tok.type==TK_SPACE) { + // nothing... + } else if(tok.type==TK_NEWLINE) { + status = 0; // ok... no handling of #defined for now, so just write through the line + } else { + status = 399; // fallback + } + break; + } + if(notok) + notok=0; + else + if(write && !oldp && nowrite_ifs!=1) { + if(!incomment && !indefined && tok.type == TK_TEXT) { + k = kh_get(define, defines, tok.str); + if(k!=kh_end(defines)) { + int v = kh_val(defines, k); + sprintf(tok.str, "%d", v); // overide define with defined value + } + } + int l = strlen(tok.str); + if(sz+l>=cap) { + cap+=2000; + ncode = (char*)realloc(ncode, cap); + } + strcat(ncode, tok.str); + sz+=l; + } + } + } + + DBG(printf("New code is: ------------\n%s\n------------------\n", ncode);) + kh_destroy(define, defines); + kh_foreach_value(alldefines, defname, + free(defname); + ) + kh_destroy(alldefine, alldefines); + if(stackif.ifs) + free(stackif.ifs); + + return ncode; +} \ No newline at end of file diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/preproc.h b/Projects/Android/jni/SupportLibs/gl4es/src/gl/preproc.h new file mode 100644 index 0000000..786c6b5 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/preproc.h @@ -0,0 +1,17 @@ +#ifndef _GL4ES_PREPROC_H_ +#define _GL4ES_PREPROC_H_ + +typedef struct { + char name[50]; + int state; //0:disable, 1:warn, 1:enable, 2:require +} extension_t; + +typedef struct { + extension_t *ext; + int size; + int cap; +} extensions_t; + +char* preproc(const char* code, int keepcomments, int gl_es, extensions_t* exts); + +#endif // _GL4ES_PREPROC_H_ diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/program.c b/Projects/Android/jni/SupportLibs/gl4es/src/gl/program.c new file mode 100644 index 0000000..fdec291 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/program.c @@ -0,0 +1,888 @@ +#include "program.h" + +#include +#include +#include "../glx/hardext.h" +#include "debug.h" +#include "fpe.h" +#include "gl4es.h" +#include "glstate.h" +#include "loader.h" +#include "shaderconv.h" + +//#define DEBUG +#ifdef DEBUG +#define DBG(a) a +#else +#define DBG(a) +#endif + +//KH Map implementations +KHASH_MAP_IMPL_INT(attribloclist, attribloc_t *); +KHASH_MAP_IMPL_INT(uniformlist, uniform_t *); +KHASH_MAP_IMPL_INT(programlist, program_t *); + + +void gl4es_glAttachShader(GLuint program, GLuint shader) { + DBG(printf("glAttachShader(%d, %d)\n", program, shader);) + FLUSH_BEGINEND; + // sanity tests + CHECK_PROGRAM(void, program) + CHECK_SHADER(void, shader) + + // add shader reference to program + if(glprogram->attach_cap == glprogram->attach_size) { + glprogram->attach_cap += 4; + glprogram->attach = (GLuint*)realloc(glprogram->attach, sizeof(GLuint)*glprogram->attach_cap); + } + glprogram->attach[glprogram->attach_size++] = glshader->id; + ++glshader->attached; + // save last vertex or fragment attached + if(glshader->type==GL_VERTEX_SHADER) + glprogram->last_vert = glshader; + else if(glshader->type==GL_FRAGMENT_SHADER) + glprogram->last_frag = glshader; + // send to hadware + LOAD_GLES2(glAttachShader); + if(gles_glAttachShader) { + gles_glAttachShader(glprogram->id, glshader->id); + errorGL(); + } else + noerrorShim(); +} + +void gl4es_glBindAttribLocation(GLuint program, GLuint index, const GLchar *name) { + DBG(printf("glBindAttribLocation(%d, %d, \"%s\")\n", program, index, name);) + FLUSH_BEGINEND; + // sanity tests + CHECK_PROGRAM(void, program) + // look / create attribloc at index + attribloc_t *attribloc = NULL; + { + khint_t k; + int ret; + khash_t(attribloclist) *attribloclist = glprogram->attribloc; + k = kh_get(attribloclist, attribloclist, index); + if (k != kh_end(attribloclist)) { + attribloc = kh_value(attribloclist, k); + } else { + k = kh_put(attribloclist, attribloclist, index, &ret); + attribloc = kh_value(attribloclist, k) = malloc(sizeof(attribloc_t)); + memset(attribloc, 0, sizeof(attribloc_t)); + attribloc->real_index = -1; + attribloc->index = index; + } + } + // update name + if(attribloc->name) free(attribloc->name); + attribloc->name = strdup(name); + // send to hardware + LOAD_GLES2(glBindAttribLocation); + if(gles_glBindAttribLocation) { + gles_glBindAttribLocation(glprogram->id, index, attribloc->name); + errorGL(); + } else + noerrorShim(); +} + +GLuint gl4es_glCreateProgram(void) { + DBG(printf("glCreateProgram()\n");) + FLUSH_BEGINEND; + static GLuint lastprogram = 0; + GLuint program; + // create the program + LOAD_GLES2(glCreateProgram); + if(gles_glCreateProgram) { + program = gles_glCreateProgram(); + if(!program) { + errorGL(); + return 0; + } + } else { + program = ++lastprogram; + noerrorShim(); + } + // store the new empty shader in the list for later use + khint_t k; + int ret; + khash_t(programlist) *programs = glstate->glsl->programs; + k = kh_get(programlist, programs, program); + program_t *glprogram = NULL; + if (k == kh_end(programs)){ + k = kh_put(programlist, programs, program, &ret); + glprogram = kh_value(programs, k) = malloc(sizeof(program_t)); + memset(glprogram, 0, sizeof(program_t)); + } else { + glprogram = kh_value(programs, k); + if(glprogram->attribloc) { + attribloc_t *m; + kh_foreach_value(glprogram->attribloc, m, + free(m->name); free(m); + ) + kh_destroy(attribloclist, glprogram->attribloc); + glprogram->attribloc = NULL; + } + } + glprogram->id = program; + // initialize attribloc hashmap + khash_t(attribloclist) *attribloc = glprogram->attribloc = kh_init(attribloclist); + k = kh_put(attribloclist, attribloc, 1, &ret); + kh_del(attribloclist, attribloc, k); + // initialize uniform hashmap + khash_t(uniformlist) *uniform = glprogram->uniform = kh_init(uniformlist); + k = kh_put(uniformlist, uniform, 1, &ret); + kh_del(uniformlist, uniform, k); + // all done + return program; +} + +void actualy_deleteshader(GLuint shader); +void actualy_detachshader(GLuint shader); + +void deleteProgram(program_t *glprogram, khint_t k_program) { + free(glprogram->attach); + // clean attribloc + if(glprogram->attribloc) { + attribloc_t *m; + kh_foreach_value(glprogram->attribloc, m, + free(m->name); free(m); + ) + kh_destroy(attribloclist, glprogram->attribloc); + glprogram->attribloc = NULL; + } + // clean uniform list + if(glprogram->uniform) { + uniform_t *m; + kh_foreach_value(glprogram->uniform, m, + free(m->name); free(m); + ) + kh_destroy(uniformlist, glprogram->uniform); + glprogram->uniform = NULL; + } + // clean cache + if(glprogram->cache.cache) + free(glprogram->cache.cache); + // clean fpe cache if it exist + if(glprogram->fpe_cache) + fpe_disposeCache((fpe_cache_t*)glprogram->fpe_cache, 1); + // delete program + kh_del(programlist, glstate->glsl->programs, k_program); + free(glprogram); +} + +void gl4es_glDeleteProgram(GLuint program) { + DBG(printf("glDeleteProgram(%d)\n", program);) + if(!glstate) return; // in case a program delete shaders after deleteing all context + FLUSH_BEGINEND; + CHECK_PROGRAM(void, program) + // send to hardware + LOAD_GLES2(glDeleteProgram); + if(gles_glDeleteProgram) { + gles_glDeleteProgram(glprogram->id); + errorGL(); + } else + noerrorShim(); + // TODO: check GL ERROR to not clean in case of error? + // clean attached shaders + for (int i=0; iattach_size; i++) { + actualy_detachshader(glprogram->attach[i]); // auto delete if marqued as delete! + } + deleteProgram(glprogram, k_program); +} + +void gl4es_glDetachShader(GLuint program, GLuint shader) { + DBG(printf("glDetachShader(%d, %d)\n", program, shader);) + FLUSH_BEGINEND; + CHECK_PROGRAM(void, program) + CHECK_SHADER(void, shader) + // is shader attached? + int f = 0; + while(fattach_size && glprogram->attach[f]!=shader) + f++; + if(f==glprogram->attach_size) { + errorShim(GL_INVALID_VALUE); + return; + } + // send to hardware + LOAD_GLES2(glDetachShader); + if(gles_glDetachShader) { + gles_glDetachShader(glprogram->id, glshader->id); + errorGL(); + } else + noerrorShim(); + // marked as detached + actualy_detachshader(shader); +} + +void gl4es_glGetActiveAttrib(GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name) { + DBG(printf("glGetActiveAttrib(%d, %d, %d, %p, %p, %p, %p)\n", program, index, bufSize, length, size, type, name);) + FLUSH_BEGINEND; + CHECK_PROGRAM(void, program) + + if(glprogram->attribloc) { + khint_t k; + attribloc_t *attribloc; + kh_foreach_value(glprogram->attribloc, attribloc, + if(attribloc->real_index == index) { + if(type) *type = attribloc->type; + if(size) *size = attribloc->size; + if(length) *length = strlen(attribloc->name); + if(bufSize && name) { + strncpy(name, attribloc->name, bufSize-1); + name[bufSize-1] = '\0'; + } + DBG(printf("found, type=%s, size=%d, name=%s\n", PrintEnum(attribloc->type), attribloc->size, attribloc->name);) + noerrorShim(); + return; + } + ); + } + DBG(printf("not found\n");) + errorShim(GL_INVALID_VALUE); +} + +void gl4es_glGetAttachedShaders(GLuint program, GLsizei maxCount, GLsizei *count, GLuint *shaders) { + DBG(printf("glGetAttachedShaders(%d, %d, %p, %p)\n", program, maxCount, count, shaders);) + FLUSH_BEGINEND; + CHECK_PROGRAM(void, program) + + int n = glprogram->attach_size; + if(n>maxCount) n = maxCount; + + if (count) *count=n; + if (shaders) + for (int i=0; iattach[i]; + + noerrorShim(); +} + +GLint gl4es_glGetAttribLocation(GLuint program, const GLchar *name) { + DBG(printf("glGetAttribLocation(%d, %s)\n", program, name)); + FLUSH_BEGINEND; + CHECK_PROGRAM(GLint, program); + + if(!glprogram->linked) { + errorShim(GL_INVALID_OPERATION); + DBG(printf(" program unlinked: -1\n")); + return -1; + } + noerrorShim(); + if(strncmp(name, "gl_", 3)==0) { + DBG(printf(" internal attrib: -1\n")); + return -1; + } + + int rloc = -1; + int loc = -1; + // look in already created attribloc + if(glprogram->attribloc) { + attribloc_t *m; + kh_foreach_value(glprogram->attribloc, m, + if(strcmp(m->name, name)==0) { + loc = m->index; + rloc = m->real_index; + } + ) + } + // if found, just return the value, it's done... + if(loc!=-1) { + DBG(printf(" found in cache: %d\n", loc);) + return loc; + } + // end + DBG(printf(" asked hardware: %d\n", loc);) + return loc; +} + +void gl4es_glGetActiveUniform(GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name) { + DBG(printf("glGetActiveUniform(%d, %d, %d, %p, %p, %p, %p)\n", program, index, bufSize, length, size, type, name);) + FLUSH_BEGINEND; + CHECK_PROGRAM(GLvoid, program); + + if(!glprogram->linked) { + errorShim(GL_INVALID_OPERATION); + DBG(printf(" not linked\n");) + return; + } + noerrorShim(); + if(strncmp(name, "gl_", 3)==0) { + DBG(printf(" internal uniform\n");) + return; + } + + // look in uniform cache, that is filled when program is linked + if(glprogram->uniform) { + uniform_t *m; + khint_t k; + kh_foreach_value(glprogram->uniform, m, + if(m->internal_id == index) { + if(type) *type = m->type; + if(size) *size = m->size; + if(length) *length = strlen(m->name); + if(bufSize && name) { + strncpy(name, m->name, bufSize-1); + name[bufSize-1] = '\0'; + } + DBG(printf(" found %s (%d), type=%s, size=%d\n", m->name, strlen(m->name), PrintEnum(m->type), m->size);) + return; + } + ); + } + // end + DBG(printf(" not found\n");) + errorShim(GL_INVALID_VALUE); +} + +static const char* notlinked = "Program not linked"; +static const char* linked = "Program linked, but no shader support"; +static const char* validated = "Program validated, but no shader support"; +const char* getFakeProgramInfo(program_t* glprogram) { + return (glprogram->linked)?((glprogram->validated)?validated:linked):notlinked; +} + +void gl4es_glGetProgramInfoLog(GLuint program, GLsizei maxLength, GLsizei *length, GLchar *infoLog) { + DBG(printf("glGetProgramInfoLog(%d, %d, %p, %p)\n", program, maxLength, length, infoLog);) + FLUSH_BEGINEND; + CHECK_PROGRAM(void, program) + + if(maxLength<0) { + errorShim(GL_INVALID_VALUE); + return; + } + if(!maxLength) { + noerrorShim(); + return; + } + + LOAD_GLES2(glGetProgramInfoLog); + if(gles_glGetProgramInfoLog) { + gles_glGetProgramInfoLog(glprogram->id, maxLength, length, infoLog); + errorGL(); + } else { + const char* res = getFakeProgramInfo(glprogram); + int l = strlen(res)+1; + if (l>maxLength) l = maxLength; + if(length) *length = l-1; + if(infoLog) strncpy(infoLog, res, l); + noerrorShim(); + } +} + +void gl4es_glGetProgramiv(GLuint program, GLenum pname, GLint *params) { + DBG(printf("glGetProgramiv(%d, %s, %p)\n", program, PrintEnum(pname), params);) + FLUSH_BEGINEND; + CHECK_PROGRAM(void, program) + + LOAD_GLES2(glGetProgramiv); + noerrorShim(); + switch(pname) { + case GL_DELETE_STATUS: + if(gles_glGetProgramiv) { + gles_glGetProgramiv(glprogram->id, pname, params); + errorGL(); + } else + *params = GL_FALSE; + break; + case GL_LINK_STATUS: + *params = glprogram->linked?GL_TRUE:GL_FALSE; + break; + case GL_VALIDATE_STATUS: + *params = glprogram->valid_result; + break; + case GL_INFO_LOG_LENGTH: + if(gles_glGetProgramiv) { + gles_glGetProgramiv(glprogram->id, pname, params); + errorGL(); + } else + *params = strlen(getFakeProgramInfo(glprogram)); + break; + case GL_ATTACHED_SHADERS: + *params = glprogram->attach_size; + break; + case GL_ACTIVE_ATTRIBUTES: + case GL_ACTIVE_ATTRIBUTE_MAX_LENGTH: + if(gles_glGetProgramiv) { + gles_glGetProgramiv(glprogram->id, pname, params); + errorGL(); + } else + *params = 0; + break; + case GL_ACTIVE_UNIFORMS: + *params = (glprogram->uniform)?glprogram->num_uniform:0; + break; + case GL_ACTIVE_UNIFORM_MAX_LENGTH: + { + int l = 0; + uniform_t *m; + kh_foreach_value(glprogram->uniform, m, + if(lname)+1) + l = strlen(m->name)+1; + ) + *params = l; + } + break; + case GL_PROGRAM_BINARY_LENGTH: + // TODO: check if extension is present + if(gles_glGetProgramiv) { + gles_glGetProgramiv(glprogram->id, pname, params); + errorGL(); + } else + errorShim(GL_INVALID_ENUM); + break; + + default: + if(gles_glGetProgramiv) { + gles_glGetProgramiv(glprogram->id, pname, params); + errorGL(); + } else + errorShim(GL_INVALID_ENUM); + break; + } +} + +GLint gl4es_glGetUniformLocation(GLuint program, const GLchar *name) { + DBG(printf("glGetUniformLocation(%d, %s)\n", program, name);) + FLUSH_BEGINEND; + CHECK_PROGRAM(GLint, program) + + noerrorShim(); + int res = -1; + if(strncmp(name, "gl_", 3)==0) { + DBG(printf(" internal uniform: -1\n");) + return res; + } + + int index = 0; + int l = strlen(name); + // get array (only if end with ]) + if(name[l-1]==']') { + char * p = strrchr(name, '['); + l = p-name; + p++; + while(p && *p>='0' && *p<='9') { + index = index*10 + *(p++)-'0'; + } + } + if(glprogram->uniform) { + uniform_t *m; + khint_t k; + kh_foreach_value(glprogram->uniform, m, + if(strlen(m->name)==l && strncmp(m->name, name, l)==0) { + res = m->id; + if(index>m->size) { + res = -1; // too big ! + } else + res += index; + break; + } + ) + } + DBG(printf(" location: %d\n", res);) + return res; +} + +GLboolean gl4es_glIsProgram(GLuint program) { + DBG(printf("glIsProgram(%d)\n", program);) + FLUSH_BEGINEND; + noerrorShim(); + if(!program) { + return GL_FALSE; + } + program_t *glprogram = NULL; + khint_t k; + int ret; + khash_t(programlist) *programs = glstate->glsl->programs; + k = kh_get(programlist, programs, program); + if (k != kh_end(programs)) + return GL_TRUE; + return GL_FALSE; +} + +void gl4es_glLinkProgram(GLuint program) { + DBG(printf("glLinkProgram(%d)\n", program);) + FLUSH_BEGINEND; + CHECK_PROGRAM(void, program) + noerrorShim(); + + // clear all Attrib location cache + if(glprogram->attribloc) { + attribloc_t *m; + khint_t k; + khint_t ret; + kh_foreach(glprogram->attribloc, k, m, + free(m->name); free(m); + kh_del(attribloclist, glprogram->attribloc, k); + ) + kh_destroy(attribloclist, glprogram->attribloc); + khash_t(attribloclist) *attribloc = glprogram->attribloc = kh_init(attribloclist); + kh_put(attribloclist, attribloc, 1, &ret); + kh_del(attribloclist, attribloc, 1); + } + // clear all Uniform cache + glprogram->num_uniform = 0; + if(glprogram->uniform) { + uniform_t *m; + khint_t k; + kh_foreach(glprogram->uniform, k, m, + free(m->name); free(m); + kh_del(uniformlist, glprogram->uniform, k); + ) + } + glprogram->cache.size = 0; // reset cache buffer + + // check if attached shaders are compatible in term of varying... + shaderconv_need_t needs; + memset(&needs, 0, sizeof(needs)); + needs.need_texcoord = -1; + // first get the compatible need + for (int i=0; iattach_size; i++) { + accumShaderNeeds(glprogram->attach[i], &needs); + } + int compatible = 1; + // now is everyone ok? + for (int i=0; iattach_size && compatible; i++) { + compatible = isShaderCompatible(glprogram->attach[i], &needs); + } + // someone is not compatible, redoing shaders... + if(!compatible) { + DBG(printf("Need to redo some shaders...\n");) + for (int i=0; iattach_size; i++) { + redoShader(glprogram->attach[i], &needs); + } + } + // ok, continue with linking + LOAD_GLES2(glLinkProgram); + if(gles_glLinkProgram) { + LOAD_GLES(glGetError); + LOAD_GLES2(glGetProgramiv); + LOAD_GLES2(glGetActiveUniform); + LOAD_GLES2(glGetUniformLocation); + LOAD_GLES2(glGetActiveAttrib); + LOAD_GLES2(glGetAttribLocation); + gles_glLinkProgram(glprogram->id); + GLenum err = gles_glGetError(); + int n=0; + int maxsize=0; + khint_t k; + int ret; + DBG(GLenum e2;) + // Get Link Status + gles_glGetProgramiv(glprogram->id, GL_LINK_STATUS, &glprogram->linked); + DBG(printf(" link status = %d\n", glprogram->linked);) + if(glprogram->linked) { + // init bluitin emulation first + builtin_Init(glprogram); + // Grab all Uniform + gles_glGetProgramiv(glprogram->id, GL_ACTIVE_UNIFORMS, &n); + gles_glGetProgramiv(glprogram->id, GL_ACTIVE_UNIFORM_MAX_LENGTH, &maxsize); + khash_t(uniformlist) *uniforms = glprogram->uniform; + uniform_t *gluniform = NULL; + int uniform_cache = 0; + GLint size = 0; + GLenum type = 0; + GLchar *name = (char*)malloc(maxsize); + int tu_idx = 0; + for (int i=0; iid, i, maxsize, NULL, &size, &type, name); + DBG(e2=gles_glGetError();) + DBG(if(e2==GL_NO_ERROR)) + { + // remove any ending "[]" that could be present + if(name[strlen(name)-1]==']' && strrchr(name, '[')) (*strrchr(name, '['))='\0'; + GLint id = gles_glGetUniformLocation(glprogram->id, name); + if(id!=-1) { + for (int j = 0; jname = malloc(strlen(name)+1+5); + sprintf(gluniform->name, "%s[%d]", name, j); + } else + gluniform->name = strdup(name); + gluniform->id = id; + gluniform->internal_id = i; + gluniform->size = size-j; + gluniform->type = type; + gluniform->cache_offs = uniform_cache+j*uniformsize(type); + gluniform->cache_size = uniformsize(type)*(size-j); + gluniform->builtin = builtin_CheckUniform(glprogram, name, id, size-j); + // TextureUnit grabbing... + if(type==GL_SAMPLER_CUBE) { + glprogram->texunits[tu_idx].id = id; + glprogram->texunits[tu_idx].type=TU_CUBE; + glprogram->texunits[tu_idx].req_tu = glprogram->texunits[tu_idx].act_tu = 0; + ++tu_idx; + } else if (type==GL_SAMPLER_2D) { + glprogram->texunits[tu_idx].id = id; + glprogram->texunits[tu_idx].type=TU_TEX2D; + glprogram->texunits[tu_idx].req_tu = glprogram->texunits[tu_idx].act_tu = 0; + ++tu_idx; + } + DBG(printf(" uniform #%d : \"%s\"%s type=%s size=%d\n", id, gluniform->name, gluniform->builtin?" (builtin) ":"", PrintEnum(gluniform->type), gluniform->size);) + if(gluniform->size==1) ++glprogram->num_uniform; + id++; + } + uniform_cache += uniformsize(type)*size; + } + } + DBG(else printf("LIBGL: Warning, getting Uniform #%d info failed with %s\n", i, PrintEnum(e2));) + } + free(name); + // reset uniform cache + if(glprogram->cache.cap < uniform_cache) { + glprogram->cache.cap=uniform_cache; + glprogram->cache.cache = malloc(glprogram->cache.cap); + } + memset(glprogram->cache.cache, 0, glprogram->cache.cap); + //Maybe Sampler uniform should not be initialized to 0, but to -1, to be sure the value is initialized? + if(glprogram->uniform) { + uniform_t *m; + khint_t k; + kh_foreach(glprogram->uniform, k, m, + if(m->type == GL_SAMPLER_2D || m->type == GL_SAMPLER_CUBE) + memset(glprogram->cache.cache+m->cache_offs, 0xff, m->cache_size); + ) + } + + // Grab all Attrib + gles_glGetProgramiv(glprogram->id, GL_ACTIVE_ATTRIBUTES, &n); + gles_glGetProgramiv(glprogram->id, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &maxsize); + name = (char*)malloc(maxsize); + for (int i=0; iid, i, maxsize, NULL, &size, &type, name); + GLint id = gles_glGetAttribLocation(glprogram->id, name); + if(id!=-1) { + attribloc_t *glattribloc = NULL; + k = kh_put(attribloclist, glprogram->attribloc, id, &ret); + if(ret==0) { + // already there + glattribloc = kh_value(glprogram->attribloc, k); + if(glattribloc->name) + free(glattribloc->name); + } else { + glattribloc = kh_value(glprogram->attribloc, k) = malloc(sizeof(attribloc_t)); + } + memset(glattribloc, 0, sizeof(attribloc_t)); + glattribloc->name = strdup(name); + glattribloc->size = size; + glattribloc->type = type; + glattribloc->index = id; + glattribloc->real_index = i; + int builtin = builtin_CheckVertexAttrib(glprogram, name, id); + glprogram->va_size[id] = n_uniform(type); // same as uniform + DBG(printf(" attrib #%d : \"%s\"%s type=%s size=%d\n", id, glattribloc->name, builtin?" (builtin) ":"", PrintEnum(glattribloc->type), glattribloc->size);) + } + } + DBG(else printf("LIBGL: Warning, getting Attrib #%d info failed with %s\n", i, PrintEnum(e2));) + } + free(name); + } else { + // should DBG the linker error? + DBG(printf(" Link failled!\n");) + glprogram->linked = 0; + errorGL(); + return; + } + // all done + errorShim(err); + } else { + noerrorShim(); + } + glprogram->linked = 1; +} + +void gl4es_glUseProgram(GLuint program) { + DBG(printf("glUseProgram(%d) old=%d\n", program, glstate->glsl->program);) + PUSH_IF_COMPILING(glUseProgram); + if(program==0) { + glstate->glsl->program=0; + glstate->glsl->glprogram=NULL; + return; + } + CHECK_PROGRAM(void, program) + noerrorShim(); + DBG(printf("program id=%d\n", glprogram->id);) + + glstate->glsl->program=glprogram->id; + glstate->glsl->glprogram=glprogram; +} + +void gl4es_glValidateProgram(GLuint program) { + CHECK_PROGRAM(void, program) + FLUSH_BEGINEND; + noerrorShim(); + + LOAD_GLES2(glValidateProgram); + if(gles_glValidateProgram) { + LOAD_GLES(glGetError); + LOAD_GLES2(glGetProgramiv); + gles_glValidateProgram(glprogram->id); + GLenum err = gles_glGetError(); + gles_glGetProgramiv(glprogram->id, GL_VALIDATE_STATUS, &glprogram->valid_result); + errorShim(err); + // TODO: grab all Uniform and Attrib of the program + } else { + noerrorShim(); + } + glprogram->validated = 1; +} + + +void glAttachShader(GLuint program, GLuint shader) AliasExport("gl4es_glAttachShader"); +void glBindAttribLocation(GLuint program, GLuint index, const GLchar *name) AliasExport("gl4es_glBindAttribLocation"); +GLuint glCreateProgram(void) AliasExport("gl4es_glCreateProgram"); +void glDeleteProgram(GLuint program) AliasExport("gl4es_glDeleteProgram"); +void glDetachShader(GLuint program, GLuint shader) AliasExport("gl4es_glDetachShader"); +void glGetActiveAttrib(GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name) AliasExport("gl4es_glGetActiveAttrib"); +void glGetAttachedShaders(GLuint program, GLsizei maxCount, GLsizei *count, GLuint *shaders) AliasExport("gl4es_glGetAttachedShaders"); +GLint glGetAttribLocation(GLuint program, const GLchar *name) AliasExport("gl4es_glGetAttribLocation"); +void glGetActiveUniform(GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name) AliasExport("gl4es_glGetActiveUniform");void glGetProgramInfoLog(GLuint program, GLsizei maxLength, GLsizei *length, GLchar *infoLog) AliasExport("gl4es_glGetProgramInfoLog"); +void glGetProgramiv(GLuint program, GLenum pname, GLint *params) AliasExport("gl4es_glGetProgramiv"); +GLint glGetUniformLocation(GLuint program, const GLchar *name) AliasExport("gl4es_glGetUniformLocation"); +GLboolean glIsProgram(GLuint program) AliasExport("gl4es_glIsProgram"); +void glLinkProgram(GLuint program) AliasExport("gl4es_glLinkProgram"); +void glUseProgram(GLuint program) AliasExport("gl4es_glUseProgram"); +void glValidateProgram(GLuint program) AliasExport("gl4es_glValidateProgram"); + + +// ================ GL_ARB_vertex_shader ================= +GLvoid glBindAttribLocationARB(GLhandleARB programObj, GLuint index, const GLcharARB *name) AliasExport("gl4es_glBindAttribLocation"); + +GLvoid glGetActiveAttribARB(GLhandleARB programObj, GLuint index, GLsizei maxLength, GLsizei *length, GLint *size, GLenum *type, GLcharARB *name) AliasExport("gl4es_glGetActiveAttrib"); + +GLint glGetAttribLocationARB(GLhandleARB programObj, const GLcharARB *name) AliasExport("gl4es_glGetAttribLocation"); + +// ============== GL_ARB_shader_objects ================== +// some are not simple alias but wrappers +GLvoid gl4es_glDeleteObject(GLhandleARB obj) { + if(!obj) + return; + // find type of obj (shader or program) + program_t *glprogram = NULL; + khint_t k_program; + { + int ret; + khash_t(programlist) *programs = glstate->glsl->programs; + k_program = kh_get(programlist, programs, obj); + if (k_program != kh_end(programs)) + glprogram = kh_value(programs, k_program); + } + if(glprogram) + gl4es_glDeleteProgram(obj); + else + gl4es_glDeleteShader(obj); +} + +GLhandleARB gl4es_glGetHandle(GLenum pname) { + FLUSH_BEGINEND; + if(pname!=GL_PROGRAM_OBJECT_ARB) { + errorShim(GL_INVALID_ENUM); + return 0; + } + return glstate->glsl->program; +} + +GLvoid gl4es_glDetachObject(GLhandleARB containerObj, GLhandleARB attachedObj) { + gl4es_glDetachShader(containerObj, attachedObj); +} + +GLhandleARB gl4es_glCreateProgramObject(GLvoid) { + return gl4es_glCreateProgram(); +} + +GLvoid gl4es_glAttachObject(GLhandleARB containerObj, GLhandleARB obj) { + gl4es_glAttachShader(containerObj, obj); +} + +GLvoid gl4es_glUseProgramObject(GLhandleARB programObj) { + gl4es_glUseProgram(programObj); +} + +GLvoid gl4es_glGetObjectParameterfv(GLhandleARB obj, GLenum pname, GLfloat *params) { + if(!obj) + return; + // find type of obj (shader or program) + program_t *glprogram = NULL; + khint_t k_program; + { + int ret; + khash_t(programlist) *programs = glstate->glsl->programs; + k_program = kh_get(programlist, programs, obj); + if (k_program != kh_end(programs)) + glprogram = kh_value(programs, k_program); + } + // float, really? + GLint p[4]; + if(glprogram) + gl4es_glGetProgramiv(obj, pname, p); + else + gl4es_glGetShaderiv(obj, pname, p); + + params[0] = p[0]; // only 1-sized array here, right? +} +GLvoid gl4es_glGetObjectParameteriv(GLhandleARB obj, GLenum pname, GLint *params) { + if(!obj) + return; + // find type of obj (shader or program) + program_t *glprogram = NULL; + khint_t k_program; + { + int ret; + khash_t(programlist) *programs = glstate->glsl->programs; + k_program = kh_get(programlist, programs, obj); + if (k_program != kh_end(programs)) + glprogram = kh_value(programs, k_program); + } + if(glprogram) + gl4es_glGetProgramiv(obj, pname, params); + else + gl4es_glGetShaderiv(obj, pname, params); + // hack, some program don't take into account that the lenght return by GL_OBJECT_INFO_LOG_LENGTH_ARB exclude the '\0'.. so adding it here + if(pname==GL_INFO_LOG_LENGTH) + (*params)++; +} + +GLvoid gl4es_glGetInfoLog(GLhandleARB obj, GLsizei maxLength, GLsizei *length, GLcharARB *infoLog) { + if(!obj) + return; + // find type of obj (shader or program) + program_t *glprogram = NULL; + khint_t k_program; + { + int ret; + khash_t(programlist) *programs = glstate->glsl->programs; + k_program = kh_get(programlist, programs, obj); + if (k_program != kh_end(programs)) + glprogram = kh_value(programs, k_program); + } + + if(glprogram) + gl4es_glGetProgramInfoLog(obj, maxLength, length, infoLog); + else + gl4es_glGetShaderInfoLog(obj, maxLength, length, infoLog); +} + +GLvoid gl4es_glGetAttachedObjects(GLhandleARB containerObj, GLsizei maxCount, GLsizei *count, GLhandleARB *obj) { + gl4es_glGetAttachedShaders(containerObj, maxCount, count, obj); +} + +GLvoid glDeleteObjectARB(GLhandleARB obj) AliasExport("gl4es_glDeleteObject"); +GLhandleARB glGetHandleARB(GLenum pname) AliasExport("gl4es_glGetHandle"); +GLvoid glDetachObjectARB(GLhandleARB containerObj, GLhandleARB attachedObj) AliasExport("gl4es_glDetachObject"); +GLhandleARB glCreateProgramObjectARB(GLvoid) AliasExport("gl4es_glCreateProgramObject"); +GLvoid glAttachObjectARB(GLhandleARB containerObj, GLhandleARB obj) AliasExport("gl4es_glAttachObject"); +GLvoid glLinkProgramARB(GLhandleARB programObj) AliasExport("gl4es_glLinkProgram"); +GLvoid glUseProgramObjectARB(GLhandleARB programObj) AliasExport("gl4es_glUseProgramObject"); +GLvoid glValidateProgramARB(GLhandleARB programObj) AliasExport("gl4es_glValidateProgram"); +GLvoid glGetObjectParameterfvARB(GLhandleARB obj, GLenum pname, GLfloat *params) AliasExport("gl4es_glGetObjectParameterfv"); +GLvoid glGetObjectParameterivARB(GLhandleARB obj, GLenum pname, GLint *params) AliasExport("gl4es_glGetObjectParameteriv"); +GLvoid glGetInfoLogARB(GLhandleARB obj, GLsizei maxLength, GLsizei *length, GLcharARB *infoLog) AliasExport("gl4es_glGetInfoLog"); +GLvoid glGetAttachedObjectsARB(GLhandleARB containerObj, GLsizei maxCount, GLsizei *count, GLhandleARB *obj) AliasExport("gl4es_glGetAttachedObjects"); +GLint glGetUniformLocationARB(GLhandleARB programObj, const GLcharARB *name) AliasExport("gl4es_glGetUniformLocation"); +GLvoid glGetActiveUniformARB(GLhandleARB programObj, GLuint index, GLsizei maxLength, GLsizei *length, GLint *size, GLenum *type, GLcharARB *name) AliasExport("gl4es_glGetActiveUniform"); + diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/program.h b/Projects/Android/jni/SupportLibs/gl4es/src/gl/program.h new file mode 100644 index 0000000..e31fd5b --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/program.h @@ -0,0 +1,315 @@ +#ifndef _GL4ES_PROGRAM_H_ +#define _GL4ES_PROGRAM_H_ + +#include "gles.h" +#include "buffers.h" +#include "shader.h" +#include "uniform.h" + +typedef struct { + GLuint index; + GLint real_index; + GLenum type; + int size; + char* name; +} attribloc_t; +KHASH_MAP_DECLARE_INT(attribloclist, attribloc_t *); + +typedef enum { + MAT_MV = 0, + MAT_MV_I, + MAT_MV_T, + MAT_MV_IT, + MAT_P, + MAT_P_I, + MAT_P_T, + MAT_P_IT, + MAT_MVP, + MAT_MVP_I, + MAT_MVP_T, + MAT_MVP_IT, + MAT_T0, + MAT_T0_I, + MAT_T0_T, + MAT_T0_IT, + MAT_T1, + MAT_T1_I, + MAT_T1_T, + MAT_T1_IT, + MAT_T2, + MAT_T2_I, + MAT_T2_T, + MAT_T2_IT, + MAT_T3, + MAT_T3_I, + MAT_T3_T, + MAT_T3_IT, + MAT_T4, + MAT_T4_I, + MAT_T4_T, + MAT_T4_IT, + MAT_T5, + MAT_T5_I, + MAT_T5_T, + MAT_T5_IT, + MAT_T6, + MAT_T6_I, + MAT_T6_T, + MAT_T6_IT, + MAT_T7, + MAT_T7_I, + MAT_T7_T, + MAT_T7_IT, + MAT_N, + MAT_MAX +} reserved_matrix_t; + +typedef struct { + GLuint internal_id; // internal id of the uniform + GLuint id; // glsl id of the uniform + GLenum type; // type of the uniform (GL_VERTEX or GL_FRAGMENT) + GLint size; + char* name; // original source of the uniform + int builtin; + uintptr_t cache_offs; + int cache_size; // this is GLsizeof(type)*size + uintptr_t parent_offs; // in case the uniform is from a fpe custom program + int parent_size; // 0 means not found in parent... like for builtin +} uniform_t; + +KHASH_MAP_DECLARE_INT(uniformlist, uniform_t *); + +typedef struct { + void* cache; // buffer of the uniform size + int cap; // capacity of the cache + int size; // next available free space in the cache +} uniformcache_t; + +typedef struct { + int has; + GLint ambient; //vec4 + GLint diffuse; //vec4 + GLint specular; //vec4 + GLint position; //vec4 + GLint halfVector; //vec4 + GLint spotDirection; //vec3 + GLint spotExponent; //float + GLint spotCutoff; //float + GLint spotCosCutoff; //float + GLfloat oldspotCutoff; // cache to avoid recalc of spotCutoff + GLfloat oldspotCosCutoff; //float + GLint constantAttenuation; //float + GLint linearAttenuation; //float + GLint quadraticAttenuation; //float +} builtin_lightsource_t; + +typedef struct { + GLint ambient; +} builtin_lightmodel_t; + + +typedef struct { + int has; + GLint emission; //vec4 + GLint ambient; //vec4 + GLint diffuse; //vec4 + GLint specular; //vec4 + GLint shininess; //float + GLint alpha; // float, fpe only, derived: diffuse[3] +} builtin_material_t; + +typedef struct { + GLint sceneColor; //vec4 +} builtin_lightmodelproducts_t; + +typedef struct { + int has; + GLint ambient; //vec4 + GLint diffuse; //vec4 + GLint specular; //vec4 +} builtin_lightproducts_t; + +typedef struct { + int has; + GLint size; + GLint sizeMin; + GLint sizeMax; + GLint fadeThresholdSize; + GLint distanceConstantAttenuation; + GLint distanceLinearAttenuation; + GLint distanceQuadraticAttenuation; +} builtin_pointsprite_t; + +typedef struct { + int has; + GLint color; + GLint density; + GLint start; + GLint end; + GLint scale; +} builtin_fog_t; + +// this need to be as texture_enabled_t, but with 0 as nothing +typedef enum { + TU_NONE = 0, + TU_TEX1D, + TU_TEX2D, + TU_TEX3D, + TU_RECTANGLE, + TU_CUBE +} texunit_type; + +typedef struct { + GLint id; + texunit_type type; + int req_tu; //requested TU + int act_tu; // actual (can be different from req) +} texunit_t; + +typedef struct { + GLuint id; // internal id of the shader + int linked; + int validated; + GLenum valid_result; + int attach_cap; + int attach_size; + GLuint *attach; + shader_t *last_vert; + shader_t *last_frag; + int va_size[MAX_VATTRIB]; + khash_t(attribloclist) *attribloc; + khash_t(uniformlist) *uniform; + int num_uniform; + uniformcache_t cache; + // builtin attrib + int has_builtin_attrib; + GLint builtin_attrib[ATT_MAX]; + // builtin uniform + int has_builtin_matrix; + GLint builtin_matrix[MAT_MAX]; + int has_builtin_light; + builtin_lightsource_t builtin_lights[MAX_LIGHT]; + builtin_lightmodel_t builtin_lightmodel; + builtin_material_t builtin_material[2]; + builtin_lightmodelproducts_t builtin_lightmodelprod[2]; + builtin_lightproducts_t builtin_lightprod[2][MAX_LIGHT]; + GLint builtin_normalrescale; + GLint builtin_clipplanes[MAX_CLIP_PLANES]; + int has_builtin_clipplanes; + builtin_pointsprite_t builtin_pointsprite; + GLint builtin_texenvcolor[MAX_TEX]; + int has_builtin_texenv; + GLint builtin_eye[4][MAX_TEX]; + GLint builtin_obj[4][MAX_TEX]; + int has_builtin_texgen; + builtin_fog_t builtin_fog; + GLint builtin_instanceID; + // fpe uniform + GLint fpe_alpharef; + int has_fpe; + GLint builtin_texsampler[MAX_TEX]; + int has_builtin_texsampler; + GLint builtin_texenvrgbscale[MAX_TEX]; + GLint builtin_texenvalphascale[MAX_TEX]; + GLint builtin_texadjust[MAX_TEX]; + int has_builtin_texadjust; + texunit_t texunits[MAX_TEX]; + void* fpe_cache; // that will be an fpe_cache_t* +} program_t; + +KHASH_MAP_DECLARE_INT(programlist, program_t *); + +void deleteProgram(program_t *glprogram, khint_t k_program); + +void gl4es_glAttachShader(GLuint program, GLuint shader); +void gl4es_glBindAttribLocation(GLuint program, GLuint index, const GLchar *name); +GLuint gl4es_glCreateProgram(void); +void gl4es_glDeleteProgram(GLuint program); +void gl4es_glDetachShader(GLuint program, GLuint shader); +void gl4es_glGetActiveAttrib(GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name); +void gl4es_glGetActiveUniform(GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name); +void gl4es_glGetAttachedShaders(GLuint program, GLsizei maxCount, GLsizei *count, GLuint *shaders); +GLint gl4es_glGetAttribLocation(GLuint program, const GLchar *name); +void gl4es_glGetProgramInfoLog(GLuint program, GLsizei maxLength, GLsizei *length, GLchar *infoLog); +void gl4es_glGetProgramiv(GLuint program, GLenum pname, GLint *params); +GLint gl4es_glGetUniformLocation(GLuint program, const GLchar *name); +GLboolean gl4es_glIsProgram(GLuint program); +void gl4es_glLinkProgram(GLuint program); +void gl4es_glUseProgram(GLuint program); +void gl4es_glValidateProgram(GLuint program); + + +#define CHECK_PROGRAM(type, program) \ + if(!program) { \ + noerrorShim(); \ + return (type)0; \ + } \ + program_t *glprogram = NULL; \ + khint_t k_##program; \ + { \ + int ret; \ + khash_t(programlist) *programs = glstate->glsl->programs; \ + k_##program = kh_get(programlist, programs, program); \ + if (k_##program != kh_end(programs)) \ + glprogram = kh_value(programs, k_##program); \ + } \ + if(!glprogram) { \ + errorShim(GL_INVALID_OPERATION); \ + return (type)0; \ + } + +#define APPLY_PROGRAM(prg, glprg) \ + if(glstate->gleshard->program != prg) { \ + glstate->gleshard->program = prg; \ + glstate->gleshard->glprogram = glprg;\ + LOAD_GLES2(glUseProgram); \ + if(gles_glUseProgram) \ + gles_glUseProgram(prg); \ + } + +void GoUniformfv(program_t *glprogram, GLint location, int size, int count, const GLfloat *value); +void GoUniformiv(program_t *glprogram, GLint location, int size, int count, const GLint *value); +void GoUniformMatrix2fv(program_t *glprogram, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +void GoUniformMatrix3fv(program_t *glprogram, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +void GoUniformMatrix4fv(program_t *glprogram, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +int GetUniformi(program_t *glprogram, GLint location); +const char* GetUniformName(program_t *glprogram, GLint location); + +GLvoid glBindAttribLocationARB(GLhandleARB programObj, GLuint index, const GLcharARB *name); +GLvoid glGetActiveAttribARB(GLhandleARB programObj, GLuint index, GLsizei maxLength, GLsizei *length, GLint *size, GLenum *type, GLcharARB *name); +GLint glGetAttribLocationARB(GLhandleARB programObj, const GLcharARB *name); + +// ============== GL_ARB_shader_objects ================== +GLvoid gl4es_glDeleteObject(GLhandleARB obj); +GLhandleARB gl4es_glGetHandle(GLenum pname); +GLvoid gl4es_glDetachObject(GLhandleARB containerObj, GLhandleARB attachedObj); +GLhandleARB gl4es_glCreateProgramObject(GLvoid); +GLvoid gl4es_glAttachObject(GLhandleARB containerObj, GLhandleARB obj); +GLvoid gl4es_glUseProgramObject(GLhandleARB programObj); +GLvoid gl4es_glGetObjectParameterfv(GLhandleARB obj, GLenum pname, GLfloat *params); +GLvoid gl4es_glGetObjectParameteriv(GLhandleARB obj, GLenum pname, GLint *params); +GLvoid gl4es_glGetInfoLog(GLhandleARB obj, GLsizei maxLength, GLsizei *length, GLcharARB *infoLog); +GLvoid gl4es_glGetAttachedObjects(GLhandleARB containerObj, GLsizei maxCount, GLsizei *count, GLhandleARB *obj); + +GLvoid glDeleteObjectARB(GLhandleARB obj); +GLhandleARB glGetHandleARB(GLenum pname); +GLvoid glDetachObjectARB(GLhandleARB containerObj, GLhandleARB attachedObj); +GLhandleARB glCreateShaderObjectARB(GLenum shaderType); +GLvoid glShaderSourceARB(GLhandleARB shaderObj, GLsizei count, const GLcharARB **string, const GLint *length); +GLvoid glCompileShaderARB(GLhandleARB shaderObj); +GLhandleARB glCreateProgramObjectARB(GLvoid); +GLvoid glAttachObjectARB(GLhandleARB containerObj, GLhandleARB obj); +GLvoid glLinkProgramARB(GLhandleARB programObj); +GLvoid glUseProgramObjectARB(GLhandleARB programObj); +GLvoid glValidateProgramARB(GLhandleARB programObj); +GLvoid glGetObjectParameterfvARB(GLhandleARB obj, GLenum pname, GLfloat *params); +GLvoid glGetObjectParameterivARB(GLhandleARB obj, GLenum pname, GLint *params); +GLvoid glGetInfoLogARB(GLhandleARB obj, GLsizei maxLength, GLsizei *length, GLcharARB *infoLog); +GLvoid glGetAttachedObjectsARB(GLhandleARB containerObj, GLsizei maxCount, GLsizei *count, GLhandleARB *obj); +GLint glGetUniformLocationARB(GLhandleARB programObj, const GLcharARB *name); +GLvoid glGetActiveUniformARB(GLhandleARB programObj, GLuint index, GLsizei maxLength, GLsizei *length, GLint *size, GLenum *type, GLcharARB *name); +GLvoid glGetUniformfvARB(GLhandleARB programObj, GLint location, GLfloat *params); +GLvoid glGetUniformivARB(GLhandleARB programObj, GLint location, GLint *params); +GLvoid glGetShaderSourceARB(GLhandleARB obj, GLsizei maxLength, GLsizei *length, GLcharARB *source); + +#endif // _GL4ES_PROGRAM_H_ diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/queries.c b/Projects/Android/jni/SupportLibs/gl4es/src/gl/queries.c new file mode 100644 index 0000000..6f5665c --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/queries.c @@ -0,0 +1,224 @@ +#include "queries.h" + +#include "khash.h" +#include "gl4es.h" +#include "glstate.h" +#include "loader.h" + +KHASH_MAP_IMPL_INT(queries, glquery_t *); + +static GLuint lastquery = 0; +static glquery_t *active_samples_passed = 0; + +void gl4es_glGenQueries(GLsizei n, GLuint * ids) { + if (glstate->list.pending) + flush(); + noerrorShim(); + if (n<1) { + errorShim(GL_INVALID_VALUE); + return; + } + for (int i=0; ilist.compiling) {errorShim(GL_INVALID_OPERATION); return GL_FALSE;} + if(glstate->list.active) flush(); + khash_t(queries) *list = glstate->queries; + khint_t k; + noerrorShim(); + if (list) { + k = kh_get(queries, list, id); + if (k != kh_end(list)) { + return GL_TRUE; + } + } + return GL_FALSE; +} + +void gl4es_glDeleteQueries(GLsizei n, const GLuint* ids) { + if (glstate->list.pending) + flush(); + khash_t(queries) *list = glstate->queries; + if (list) { + khint_t k; + glquery_t *query; + for (int i = 0; i < n; i++) { + GLuint t = ids[i]; + if (t) { // don't allow to remove default one + k = kh_get(queries, list, t); + if (k != kh_end(list)) { + query = kh_value(list, k); + kh_del(queries, list, k); + free(query); + if(active_samples_passed==query) + active_samples_passed = NULL; + } + } + } + } + noerrorShim(); +} + +void gl4es_glBeginQuery(GLenum target, GLuint id) { + if(target!=GL_SAMPLES_PASSED) { + errorShim(GL_INVALID_ENUM); + return; + } + if (glstate->list.pending) + flush(); + + khint_t k; + int ret; + glquery_t *query; + khash_t(queries) *list = glstate->queries; + if (! list) { + list = glstate->queries = kh_init(queries); + // segfaults if we don't do a single put + kh_put(queries, list, 1, &ret); + kh_del(queries, list, 1); + } + k = kh_get(queries, list, id); + if (k != kh_end(list)) { + query = kh_value(list, k); + } else { + k = kh_put(queries, list, id, &ret); + query = kh_value(list, k) = malloc(sizeof(glquery_t)); + } + query->target = target; + query->num = 0; + active_samples_passed = query; + noerrorShim(); +} + +void gl4es_glEndQuery(GLenum target) { + if(target!=GL_SAMPLES_PASSED) { + errorShim(GL_INVALID_ENUM); + return; + } + if(!active_samples_passed) { + errorShim(GL_INVALID_OPERATION); + return; + } + if (glstate->list.pending) + flush(); + + active_samples_passed = NULL; + noerrorShim(); +} + +void gl4es_glGetQueryiv(GLenum target, GLenum pname, GLint* params) { + if(target!=GL_SAMPLES_PASSED) { + errorShim(GL_INVALID_ENUM); + return; + } + if (glstate->list.pending) + flush(); + + noerrorShim(); + switch (pname) { + case GL_CURRENT_QUERY: + *params = (active_samples_passed)?active_samples_passed->id:0; + break; + case GL_QUERY_COUNTER_BITS: + *params = 0; //no counter... + break; + default: + errorShim(GL_INVALID_ENUM); + } +} + +void gl4es_glGetQueryObjectiv(GLuint id, GLenum pname, GLint* params) { + khint_t k; + int ret; + if (glstate->list.pending) + flush(); + + glquery_t *query = NULL; + khash_t(queries) *list = glstate->queries; + if (! list) { + list = glstate->queries = kh_init(queries); + // segfaults if we don't do a single put + k = kh_put(queries, list, 1, &ret); + kh_del(queries, list, k); + } + k = kh_get(queries, list, id); + if (k != kh_end(list)) { + query = kh_value(list, k); + } + if(!query) { + errorShim(GL_INVALID_OPERATION); + return; + } + noerrorShim(); + switch (pname) { + case GL_QUERY_RESULT_AVAILABLE: + *params = GL_FALSE; + break; + case GL_QUERY_RESULT: + *params = query->num; + break; + default: + errorShim(GL_INVALID_ENUM); + break; + } +} + +void gl4es_glGetQueryObjectuiv(GLuint id, GLenum pname, GLuint* params) { + khint_t k; + int ret; + if (glstate->list.pending) + flush(); + + glquery_t *query = NULL; + khash_t(queries) *list = glstate->queries; + if (! list) { + list = glstate->queries = kh_init(queries); + // segfaults if we don't do a single put + kh_put(queries, list, 1, &ret); + kh_del(queries, list, 1); + } + k = kh_get(queries, list, id); + if (k != kh_end(list)) { + query = kh_value(list, k); + } + if(!query) { + errorShim(GL_INVALID_OPERATION); + return; + } + noerrorShim(); + switch (pname) { + case GL_QUERY_RESULT_AVAILABLE: + *params = GL_FALSE; + break; + case GL_QUERY_RESULT: + *params = query->num; + break; + default: + errorShim(GL_INVALID_ENUM); + break; + } +} + + +//Direct wrapper +void glGenQueries(GLsizei n, GLuint * ids) AliasExport("gl4es_glGenQueries"); +GLboolean glIsQuery(GLuint id) AliasExport("gl4es_glIsQuery"); +void glDeleteQueries(GLsizei n, const GLuint* ids) AliasExport("gl4es_glDeleteQueries"); +void glBeginQuery(GLenum target, GLuint id) AliasExport("gl4es_glBeginQuery"); +void glEndQuery(GLenum target) AliasExport("gl4es_glEndQuery"); +void glGetQueryiv(GLenum target, GLenum pname, GLint* params) AliasExport("gl4es_glGetQueryiv"); +void glGetQueryObjectiv(GLuint id, GLenum pname, GLint* params) AliasExport("gl4es_glGetQueryObjectiv"); +void glGetQueryObjectuiv(GLuint id, GLenum pname, GLuint* params) AliasExport("gl4es_glGetQueryObjectuiv"); + +// ARB wrapper +void glGenQueriesARB(GLsizei n, GLuint * ids) AliasExport("gl4es_glGenQueries"); +GLboolean glIsQueryARB(GLuint id) AliasExport("gl4es_glIsQuery"); +void glDeleteQueriesARB(GLsizei n, const GLuint* ids) AliasExport("gl4es_glDeleteQueries"); +void glBeginQueryARB(GLenum target, GLuint id) AliasExport("gl4es_glBeginQuery"); +void glEndQueryARB(GLenum target) AliasExport("gl4es_glEndQuery"); +void glGetQueryivARB(GLenum target, GLenum pname, GLint* params) AliasExport("gl4es_glGetQueryiv"); +void glGetQueryObjectivARB(GLuint id, GLenum pname, GLint* params) AliasExport("gl4es_glGetQueryObjectiv"); +void glGetQueryObjectuivARB(GLuint id, GLenum pname, GLuint* params) AliasExport("gl4es_glGetQueryObjectuiv"); diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/queries.h b/Projects/Android/jni/SupportLibs/gl4es/src/gl/queries.h new file mode 100644 index 0000000..b205aa7 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/queries.h @@ -0,0 +1,24 @@ +#ifndef _GL4ES_QUERIES_H_ +#define _GL4ES_QUERIES_H_ + +#include "khash.h" +#include "gles.h" + +void gl4es_glBeginQuery(GLenum target, GLuint id); +void gl4es_glEndQuery(GLenum target); +void gl4es_glGenQueries(GLsizei n, GLuint * ids); +void gl4es_glDeleteQueries(GLsizei n, const GLuint* ids); +GLboolean gl4es_glIsQuery(GLuint id); +void gl4es_glGetQueryiv(GLenum target, GLenum pname, GLint* params); +void gl4es_glGetQueryObjectiv(GLuint id, GLenum pname, GLint* params); +void gl4es_glGetQueryObjectuiv(GLuint id, GLenum pname, GLuint* params); + +typedef struct { + GLuint id; + GLenum target; + int num; +} glquery_t; + +KHASH_MAP_DECLARE_INT(queries, glquery_t *) + +#endif // _GL4ES_QUERIES_H_ diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/raster.c b/Projects/Android/jni/SupportLibs/gl4es/src/gl/raster.c new file mode 100644 index 0000000..0618cc6 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/raster.c @@ -0,0 +1,749 @@ +#include "raster.h" + +#include "../glx/hardext.h" +#include "blit.h" +#include "debug.h" +#include "gl4es.h" +#include "glstate.h" +#include "init.h" +#include "list.h" +#include "loader.h" +#include "matvec.h" +#include "pixel.h" + +#define min(a, b) ((a)(b))?(a):(b) + +void gl4es_glRasterPos3f(GLfloat x, GLfloat y, GLfloat z) { + if (glstate->list.active) + if (glstate->list.compiling) { + NewStage(glstate->list.active, STAGE_RASTER); + rlRasterOp(glstate->list.active, 1, x, y, z); + noerrorShim(); + return; + } else flush(); + + // Transform xyz coordinates with current modelview and projection matrix... + GLfloat glmatrix[16], projection[16], modelview[16]; + GLfloat t[4], transl[4] = {x, y, z, 1.0f}; + gl4es_glGetFloatv(GL_PROJECTION_MATRIX, glmatrix); + matrix_transpose(glmatrix, projection); + gl4es_glGetFloatv(GL_MODELVIEW_MATRIX, glmatrix); + matrix_transpose(glmatrix, modelview); + matrix_vector(modelview, transl, t); + matrix_vector(projection, t, transl); + GLfloat w2, h2; + w2=glstate->raster.viewport.width/2.0f; + h2=glstate->raster.viewport.height/2.0f; + glstate->raster.rPos.x = transl[0]*w2+w2; + glstate->raster.rPos.y = transl[1]*h2+h2; + glstate->raster.rPos.z = transl[2]; +} + +void gl4es_glWindowPos3f(GLfloat x, GLfloat y, GLfloat z) { + if (glstate->list.active) + if (glstate->list.compiling) { + NewStage(glstate->list.active, STAGE_RASTER); + rlRasterOp(glstate->list.active, 2, x, y, z); + noerrorShim(); + return; + } else flush(); + + glstate->raster.rPos.x = x; + glstate->raster.rPos.y = y; + glstate->raster.rPos.z = z; +} + +void gl4es_glViewport(GLint x, GLint y, GLsizei width, GLsizei height) { + PUSH_IF_COMPILING(glViewport); + LOAD_GLES(glViewport); + if(glstate->raster.viewport.x!=x || glstate->raster.viewport.y!=y || glstate->raster.viewport.width!=width || glstate->raster.viewport.height!=height) { + if (glstate->raster.bm_drawing) + bitmap_flush(); + gles_glViewport(x, y, width, height); + glstate->raster.viewport.x = x; + glstate->raster.viewport.y = y; + glstate->raster.viewport.width = width; + glstate->raster.viewport.height = height; + } +} + +// hacky viewport temporary changes +void pushViewport(GLint x, GLint y, GLsizei width, GLsizei height) { + LOAD_GLES(glViewport); + gles_glViewport(x, y, width, height); +} +void popViewport() { + LOAD_GLES(glViewport); + gles_glViewport(glstate->raster.viewport.x, glstate->raster.viewport.y, glstate->raster.viewport.width, glstate->raster.viewport.height); +} + + +void gl4es_glPixelZoom(GLfloat xfactor, GLfloat yfactor) { + if (glstate->list.active) + if (glstate->list.compiling) { + NewStage(glstate->list.active, STAGE_RASTER); + rlRasterOp(glstate->list.active, 3, xfactor, yfactor, 0.0f); + noerrorShim(); + return; + } else flush(); + + glstate->raster.raster_zoomx = xfactor; + glstate->raster.raster_zoomy = yfactor; +//printf("LIBGL: glPixelZoom(%f, %f)\n", xfactor, yfactor); +} + +void gl4es_glPixelTransferf(GLenum pname, GLfloat param) { + if (glstate->list.active) + if (glstate->list.compiling) { + NewStage(glstate->list.active, STAGE_RASTER); + rlRasterOp(glstate->list.active, pname|0x10000, param, 0.0f, 0.0f); + noerrorShim(); + return; + } else flush(); + +//printf("LIBGL: glPixelTransferf(%04x, %f)\n", pname, param); + switch(pname) { + case GL_RED_SCALE: + glstate->raster.raster_scale[0]=param; + break; + case GL_RED_BIAS: + glstate->raster.raster_bias[0]=param; + break; + case GL_GREEN_SCALE: + case GL_BLUE_SCALE: + case GL_ALPHA_SCALE: + glstate->raster.raster_scale[(pname-GL_GREEN_SCALE)/2+1]=param; + break; + case GL_GREEN_BIAS: + case GL_BLUE_BIAS: + case GL_ALPHA_BIAS: + glstate->raster.raster_bias[(pname-GL_GREEN_BIAS)/2+1]=param; + break; + case GL_INDEX_SHIFT: + glstate->raster.index_shift=param; + break; + case GL_INDEX_OFFSET: + glstate->raster.index_offset=param; + break; + case GL_MAP_COLOR: + glstate->raster.map_color=param?1:0; + break; + /*default: + printf("LIBGL: stubbed glPixelTransferf(%04x, %f)\n", pname, param);*/ + // the other... + } +} + + +void init_raster(int width, int height) { + int w, h; + w=(hardext.npot>0)?width:npot(width); + h=(hardext.npot>0)?height:npot(height); + if (glstate->raster.data) { + if ((glstate->raster.raster_nwidthraster.raster_nheightraster.data); + glstate->raster.data = NULL; + } + } + if (!glstate->raster.data) { + glstate->raster.data = (GLubyte *)malloc(4 * w * h * sizeof(GLubyte)); // no need to memset to 0 + glstate->raster.raster_nwidth = w; glstate->raster.raster_nheight = h; + } + glstate->raster.raster_x1 = 0; glstate->raster.raster_y1 = 0; + glstate->raster.raster_x2 = width; glstate->raster.raster_y2 = height; + glstate->raster.raster_width = width; glstate->raster.raster_height = height; +} + +GLubyte raster_transform(GLubyte pix, GLubyte number) { + GLfloat a = (GLfloat)pix*(1.0f/255.0f); + a=a*glstate->raster.raster_scale[number]+glstate->raster.raster_bias[number]; + if (a<0.0f) return 0; + if (a>1.0f) return 255; + return (GLubyte)(a*255.0f); +} +GLfloat FASTMATH raster_transformf(GLfloat pix, GLubyte number) { + pix=pix*glstate->raster.raster_scale[number]+glstate->raster.raster_bias[number]; + if (pix<0.0f) return 0.0f; + if (pix>1.0f) return 1.0f; + return pix; +} + +int raster_need_transform() { + for (int i=0; i<4; i++) if (glstate->raster.raster_scale[i]!=1.0f) return 1; + for (int i=0; i<4; i++) if (glstate->raster.raster_bias[i]!=0.0f) return 1; + return 0; +} + +void raster_to_texture(rasterlist_t *r) +{ + renderlist_t *old_list = glstate->list.active; + if (old_list) glstate->list.active = NULL; // deactivate list... + GLboolean compiling = glstate->list.compiling; + glstate->list.compiling = false; + gl4es_glPushAttrib(GL_TEXTURE_BIT | GL_ENABLE_BIT ); + GLuint old_tex_unit, old_tex; + old_tex_unit = glstate->texture.active; + if (old_tex_unit!=0) gl4es_glActiveTexture(GL_TEXTURE0); + old_tex = glstate->texture.bound[0][ENABLED_TEX2D]->glname; + + gl4es_glPixelStorei(GL_PACK_ALIGNMENT, 1); + gl4es_glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + gl4es_glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); + gl4es_glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0); + gl4es_glPixelStorei(GL_UNPACK_SKIP_ROWS, 0); + gl4es_glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + + if(r->texture==0) { + gl4es_glEnable(GL_TEXTURE_2D); + gl4es_glGenTextures(1, &r->texture); + gl4es_glBindTexture(GL_TEXTURE_2D, r->texture); + + gl4es_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + gl4es_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + gl4es_glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + gl4es_glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + gl4es_glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0); // this is to be sure texture is not npot'ed ... + gl4es_glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0); // ... if not needed + gl4es_glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, glstate->raster.raster_nwidth, glstate->raster.raster_nheight, + 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); + } else { + gl4es_glBindTexture(GL_TEXTURE_2D, r->texture); + } + gl4es_glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, glstate->raster.raster_width, glstate->raster.raster_height, + GL_RGBA, GL_UNSIGNED_BYTE, glstate->raster.data); + + r->width = glstate->raster.raster_width; + r->height = glstate->raster.raster_height; + r->nwidth = glstate->raster.raster_nwidth; + r->nheight = glstate->raster.raster_nheight; + gl4es_glBindTexture(GL_TEXTURE_2D, old_tex); + if (old_tex_unit!=0) + gl4es_glActiveTexture(old_tex_unit+GL_TEXTURE0); + gl4es_glPopAttrib(); + if (old_list) glstate->list.active = old_list; + glstate->list.compiling = compiling; +} + +void bitmap_flush() { + if(!glstate->raster.bm_drawing) + return; + // draw actual bitmap + int old_tex_unit = glstate->texture.active; + if(old_tex_unit) + gl4es_glActiveTexture(GL_TEXTURE0); + + GLuint old_tex = glstate->texture.bound[0][ENABLED_TEX2D]->glname; + GLuint old_active = glstate->enable.texture[0]; + + if(IS_TEX1D(old_active)) gl4es_glDisable(GL_TEXTURE_1D); + if(!IS_TEX2D(old_active)) gl4es_glEnable(GL_TEXTURE_2D); + if(IS_TEX3D(old_active)) gl4es_glDisable(GL_TEXTURE_3D); + if(IS_TEXTURE_RECTANGLE(old_active)) gl4es_glDisable(GL_TEXTURE_RECTANGLE_ARB); + if(IS_CUBE_MAP(old_active)) gl4es_glDisable(GL_TEXTURE_CUBE_MAP); + + if(!glstate->raster.bm_texture) { + gl4es_glGenTextures(1, &glstate->raster.bm_texture); + gl4es_glBindTexture(GL_TEXTURE_2D, glstate->raster.bm_texture); + + gl4es_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + gl4es_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + gl4es_glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + gl4es_glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + gl4es_glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0); // this is to be sure texture is not npot'ed ... + gl4es_glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0); // ... if not needed + } else { + gl4es_glBindTexture(GL_TEXTURE_2D, glstate->raster.bm_texture); + } + if (glstate->raster.bm_tnwidth < glstate->raster.bm_width || glstate->raster.bm_tnheight < glstate->raster.bm_height) { + glstate->raster.bm_tnwidth = (hardext.npot)?glstate->raster.bm_width:npot(glstate->raster.bm_width); + glstate->raster.bm_tnheight = (hardext.npot)?glstate->raster.bm_height:npot(glstate->raster.bm_height); + gl4es_glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, glstate->raster.bm_tnwidth, glstate->raster.bm_tnheight, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); + } + int sx = glstate->raster.bm_x1; + int ex = glstate->raster.bm_x2-glstate->raster.bm_x1; + int sy = glstate->raster.bm_y1; + int ey = glstate->raster.bm_y2-glstate->raster.bm_y1; + if(sx==0 && sy==0 && ex==glstate->raster.bm_width && ey==glstate->raster.bm_height) { + gl4es_glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, glstate->raster.bm_width, glstate->raster.bm_height, GL_RGBA, GL_UNSIGNED_BYTE, glstate->raster.bitmap); + } else { + int alloc = 4*ex*ey; + gl4es_scratch(alloc); + for (int i=0; iscratch+4*i*ex, glstate->raster.bitmap+4*(sx+(sy+i)*glstate->raster.bm_width), ex*4); + gl4es_glTexSubImage2D(GL_TEXTURE_2D, 0, sx, sy, ex, ey, GL_RGBA, GL_UNSIGNED_BYTE, glstate->scratch); + } + + gl4es_blitTexture( + glstate->raster.bm_texture, + sx, sy, + ex, ey, + glstate->raster.bm_tnwidth , glstate->raster.bm_tnheight, + 1.f, 1.f, + 0, 0, //vp is default here + sx, sy, + BLIT_ALPHA + ); + + glstate->raster.bm_drawing = 0; + + if(IS_TEX1D(old_active)) gl4es_glEnable(GL_TEXTURE_1D); + if(!IS_TEX2D(old_active)) gl4es_glDisable(GL_TEXTURE_2D); + if(IS_TEX3D(old_active)) gl4es_glEnable(GL_TEXTURE_3D); + if(IS_TEXTURE_RECTANGLE(old_active)) gl4es_glEnable(GL_TEXTURE_RECTANGLE_ARB); + if(IS_CUBE_MAP(old_active)) gl4es_glEnable(GL_TEXTURE_CUBE_MAP); + + if (old_tex!=glstate->raster.bm_texture) + gl4es_glBindTexture(GL_TEXTURE_2D, old_tex); + + if(old_tex_unit) + gl4es_glActiveTexture(GL_TEXTURE0 + old_tex_unit); +} + + +void gl4es_glBitmap(GLsizei width, GLsizei height, GLfloat xorig, GLfloat yorig, + GLfloat xmove, GLfloat ymove, const GLubyte *bitmap) { +/*printf("glBitmap, xy={%f, %f}, xyorig={%f, %f}, size={%u, %u}, zoom={%f, %f}, viewport={%i, %i, %i, %i}\n", + glstate->raster.rPos.x, glstate->raster.rPos.y, xorig, yorig, width, height, glstate->raster.raster_zoomx, glstate->raster.raster_zoomy, glstate->raster.viewport.x, glstate->raster.viewport.y, glstate->raster.viewport.width, glstate->raster.viewport.height);*/ + // TODO: shouldn't be drawn if the raster pos is outside the viewport? + // TODO: negative width/height mirrors bitmap? + noerrorShim(); + if(glstate->list.active && glstate->list.pending) + flush(); + if(glstate->list.active) { + renderlist_t* list = glstate->list.active; + if (!list->bitmaps) { + list->bitmaps = (bitmaps_t*)malloc(sizeof(bitmaps_t)); + memset(list->bitmaps, 0, sizeof(bitmaps_t)); + list->bitmaps->shared = (int*)malloc(sizeof(int)); + *list->bitmaps->shared = 0; + } + if(list->bitmaps->count == list->bitmaps->cap) { + list->bitmaps->cap += 8; + list->bitmaps->list = (bitmap_list_t*)realloc(list->bitmaps->list, list->bitmaps->cap*sizeof(bitmap_list_t)); + } + bitmap_list_t *l = &list->bitmaps->list[list->bitmaps->count++]; + l->width = width; + l->height = height; + l->xorig = xorig; + l->yorig = yorig; + l->xmove = xmove; + l->ymove = ymove; + int sz = ((width+7)/8)*height; + l->bitmap = (GLubyte*)malloc(sz); + memcpy(l->bitmap, bitmap, sz); + return; + } + if ((!width && !height) || (bitmap==0)) { + glstate->raster.rPos.x += xmove; + glstate->raster.rPos.y += ymove; + return; + } + + // get start/end of drawed pixel + float zoomx = glstate->raster.raster_zoomx; + float zoomy = glstate->raster.raster_zoomy; + int sx, sy, ex, ey; + sx = 0; + sy = 0; + ex = width*zoomx; + ey = height*zoomy; + + int rx = glstate->raster.rPos.x-xorig; + int ry = glstate->raster.rPos.y-yorig; + + if (rx+sx<0) sx = -rx; + if (ry+sy<0) sy = -ry; + if (rx+ex>glstate->raster.viewport.width) ex = glstate->raster.viewport.width-rx; + if (ry+ey>glstate->raster.viewport.height) ey = glstate->raster.viewport.height-ry; + if( exraster.bm_alloc < glstate->raster.viewport.width*glstate->raster.viewport.height*4) { + if(glstate->raster.bitmap) + free(glstate->raster.bitmap); + glstate->raster.bm_alloc = glstate->raster.viewport.width*glstate->raster.viewport.height*4; + glstate->raster.bitmap = (GLubyte*)malloc(glstate->raster.bm_alloc); + } + // clear buffer if needed + if(!glstate->raster.bm_drawing) { + memset(glstate->raster.bitmap, 0, glstate->raster.viewport.width*glstate->raster.viewport.height*4); + glstate->raster.bm_width = glstate->raster.viewport.width; + glstate->raster.bm_height = glstate->raster.viewport.height; + glstate->raster.bm_x1 = glstate->raster.bm_width; + glstate->raster.bm_y1 = glstate->raster.bm_height; + glstate->raster.bm_x2 = 0; + glstate->raster.bm_y2 = 0; + } + glstate->raster.bm_x1 = min(glstate->raster.bm_x1, rx+sx); + glstate->raster.bm_y1 = min(glstate->raster.bm_y1, ry+sy); + glstate->raster.bm_x2 = max(glstate->raster.bm_x2, rx+ex); + glstate->raster.bm_y2 = max(glstate->raster.bm_y2, ry+ey); + // draw the scaled bitmap + int pixtrans=raster_need_transform(); + const GLubyte *from; + GLubyte *to; + GLubyte col[4]; + for (int i=0; i<4; i++) + col[i] = glstate->color[i]*255.f; + // copy to pixel data + if (pixtrans) { + for (int y = sy; y < ey; ++y) { + int by = floor(y/zoomy); + from = bitmap + (by * ((width+7)/8)); + to = glstate->raster.bitmap + 4 * (GLint)(rx+((ry+y) * glstate->raster.bm_width)); + for (int x = sx; x < ex; ++x) { + int bx = floor(x/zoomx); + GLubyte b = from[(bx / 8)]; + int p = (b & (1 << (7 - (bx % 8)))) ? 1 : 0; + // r, g, b, a + *to++ = raster_transform(col[0]*p, 0); + *to++ = raster_transform(col[1]*p, 1); + *to++ = raster_transform(col[2]*p, 2); + *to++ = raster_transform(col[3]*p, 3); + } + } + } else { + for (int y = sy; y < ey; ++y) { + int by = floor(y/zoomy); + from = bitmap + (by * ((width+7)/8)); + to = glstate->raster.bitmap + 4 * (GLint)(rx+((ry+y) * glstate->raster.bm_width)); + for (int x = sx; x < ex; ++x) { + int bx = floor(x/zoomx); + GLubyte b = from[(bx / 8)]; + int p = (b & (1 << (7 - (bx % 8)))) ? 1 : 0; + *to++ = col[0]*p; + *to++ = col[1]*p; + *to++ = col[2]*p; + *to++ = col[3]*p; + } + } + } + + // finished, move... + glstate->raster.rPos.x += xmove; + glstate->raster.rPos.y += ymove; + // draw in buffer... + glstate->raster.bm_drawing = 1; +} + +void gl4es_glDrawPixels(GLsizei width, GLsizei height, GLenum format, + GLenum type, const GLvoid *data) { + GLubyte *pixels, *from, *to; + GLvoid *dst = NULL; + + if(type==GL_BITMAP) { + gl4es_glBitmap(width, height, 0, 0, 0, 0, data); + return; + } + + noerrorShim(); + if(glstate->list.active && glstate->list.pending) + flush(); + + if (glstate->raster.bm_drawing) + bitmap_flush(); + +/*printf("glDrawPixels, xy={%f, %f}, size={%i, %i}, format=%s, type=%s, zoom={%f, %f}, viewport={%i, %i, %i, %i}\n", + glstate->raster.rPos.x, glstate->raster.rPos.y, width, height, PrintEnum(format), PrintEnum(type), glstate->raster.raster_zoomx, glstate->raster.raster_zoomy, glstate->raster.viewport.x, glstate->raster.viewport.y, glstate->raster.viewport.width, glstate->raster.viewport.height);*/ + // check of unsuported format... + if ((format == GL_STENCIL_INDEX) || (format == GL_DEPTH_COMPONENT)) { + errorShim(GL_INVALID_ENUM); + return; + } + + init_raster(width, height); + + GLsizei bmp_width = (glstate->texture.unpack_row_length)?glstate->texture.unpack_row_length:width; + + if (! pixel_convert(data, &dst, bmp_width, height, + format, type, GL_RGBA, GL_UNSIGNED_BYTE, 0, 1)) { // pack_align is forced to 1 when drawing + return; + } + + pixels = (GLubyte *)dst; + GLint vx, vy; + int pixtrans=raster_need_transform(); + + if (pixtrans) { + for (int y = 0; y < height; y++) { + to = glstate->raster.data + 4 * (GLint)(y * glstate->raster.raster_width); + from = pixels + 4 * (glstate->texture.unpack_skip_pixels + (y + glstate->texture.unpack_skip_rows) * bmp_width); + for (int x = 0; x < width; x++) { + *to++ = raster_transform(*from++, 0); + *to++ = raster_transform(*from++, 1); + *to++ = raster_transform(*from++, 2); + *to++ = raster_transform(*from++, 3); + } + } + } else { + for (int y = 0; y < height; y++) { + to = glstate->raster.data + 4 * (GLint)(y * glstate->raster.raster_width); + from = pixels + 4 * (glstate->texture.unpack_skip_pixels + (y + glstate->texture.unpack_skip_rows) * bmp_width); + for (int x = 0; x < width; x++) { + *to++ = *from++; + *to++ = *from++; + *to++ = *from++; + *to++ = *from++; + } + } + } + if (pixels != data) + free(pixels); + + rasterlist_t *r; + if (glstate->list.active) { + NewStage(glstate->list.active, STAGE_RASTER); + r = glstate->list.active->raster = (rasterlist_t*)malloc(sizeof(rasterlist_t)); + memset(r, 0, sizeof(rasterlist_t)); + r->shared = (int*)malloc(sizeof(int)); + *r->shared = 0; + } else { + r = &glstate->raster.immediate; + if(r->texture && (width>r->nwidth || height>r->nheight)) { + gl4es_glDeleteTextures(1, &r->texture); + r->texture = 0; + } + } + raster_to_texture(r); + r->xmove = 0; + r->ymove = 0; + r->xorig = 0; + r->yorig = 0; + r->bitmap = false; + r->zoomx = glstate->raster.raster_zoomx; + r->zoomy = glstate->raster.raster_zoomy; + if (!(glstate->list.active)) { + render_raster_list(r); +/* gles_glDeleteTextures(1, &r->texture); + r->texture = 0;*/ + } +} + +void render_raster_list(rasterlist_t* rast) { +//printf("render_raster_list, rast->x/y=%f/%f rast->width/height=%i/%i, rPos.x/y/z=%f/%f/%f, rast->zoomxy=%f/%f raster->texture=%u\n", rast->xorig, rast->yorig, rast->width, rast->height, glstate->raster.rPos.x, glstate->raster.rPos.y, glstate->raster.rPos.z, rast->zoomx, rast->zoomy, rast->texture); + if (rast->texture) + gl4es_blitTexture( + rast->texture, + 0.f, 0.f, + rast->width , rast->height, + rast->nwidth, rast->nheight, + rast->zoomx, rast->zoomy, + 0, 0, //vp is default here + glstate->raster.rPos.x-rast->xorig, glstate->raster.rPos.y-rast->yorig, + (rast->bitmap)?BLIT_ALPHA:BLIT_COLOR + ); + glstate->raster.rPos.x += rast->xmove; + glstate->raster.rPos.y += rast->ymove; +} + +int map_pixelmap(GLenum map, int* wf, int** size, void** array) { + *wf = 1; + switch (map) { + case GL_PIXEL_MAP_I_TO_I: + *wf = 0; + *array = (void*)glstate->raster.map_i2i; + *size = &glstate->raster.map_i2i_size; + break; + case GL_PIXEL_MAP_I_TO_R: + *array = (void*)glstate->raster.map_i2r; + *size = &glstate->raster.map_i2r_size; + break; + case GL_PIXEL_MAP_I_TO_G: + *array = (void*)glstate->raster.map_i2g; + *size = &glstate->raster.map_i2g_size; + break; + case GL_PIXEL_MAP_I_TO_B: + *array = (void*)glstate->raster.map_i2b; + *size = &glstate->raster.map_i2b_size; + break; + case GL_PIXEL_MAP_I_TO_A: + *array = (void*)glstate->raster.map_i2a; + *size = &glstate->raster.map_i2a_size; + break; + case GL_PIXEL_MAP_S_TO_S: + case GL_PIXEL_MAP_R_TO_R: + case GL_PIXEL_MAP_G_TO_G: + case GL_PIXEL_MAP_B_TO_B: + case GL_PIXEL_MAP_A_TO_A: + // not handled + noerrorShim(); + return 0; + default: + errorShim(GL_INVALID_ENUM); + return 0; + } + return 1; +} + +void gl4es_glPixelMapfv(GLenum map, GLsizei mapsize, const GLfloat *values) { + if(mapsize>MAX_MAP_SIZE) { + errorShim(GL_INVALID_VALUE); + return; + } + int need_pot = 0; + if(map==GL_PIXEL_MAP_I_TO_I || map==GL_PIXEL_MAP_S_TO_S + || map==GL_PIXEL_MAP_I_TO_R || map==GL_PIXEL_MAP_I_TO_G + || map==GL_PIXEL_MAP_I_TO_B || map==GL_PIXEL_MAP_I_TO_A) + need_pot=1; + if(need_pot && npot(mapsize)!=mapsize) { + errorShim(GL_INVALID_VALUE); + return; + } + int wf = 1; + void* array = NULL; + int* size = NULL; + if(!map_pixelmap(map, &wf, &size, &array)) + return; + noerrorShim(); + if(wf) { + GLfloat *p = (GLfloat*)array; + for (int i=0; iMAX_MAP_SIZE) { + errorShim(GL_INVALID_VALUE); + return; + } + int need_pot = 0; + if(map==GL_PIXEL_MAP_I_TO_I || map==GL_PIXEL_MAP_S_TO_S + || map==GL_PIXEL_MAP_I_TO_R || map==GL_PIXEL_MAP_I_TO_G + || map==GL_PIXEL_MAP_I_TO_B || map==GL_PIXEL_MAP_I_TO_A) + need_pot=1; + if(need_pot && npot(mapsize)!=mapsize) { + errorShim(GL_INVALID_VALUE); + return; + } + int wf = 1; + void* array = NULL; + int* size = NULL; + if(!map_pixelmap(map, &wf, &size, &array)) + return; + noerrorShim(); + if(wf) { + GLfloat *p = (GLfloat*)array; + for (int i=0; i>24; + } else { + GLuint *p = (GLuint*)array; + for (int i=0; iMAX_MAP_SIZE) { + errorShim(GL_INVALID_VALUE); + return; + } + int need_pot = 0; + if(map==GL_PIXEL_MAP_I_TO_I || map==GL_PIXEL_MAP_S_TO_S + || map==GL_PIXEL_MAP_I_TO_R || map==GL_PIXEL_MAP_I_TO_G + || map==GL_PIXEL_MAP_I_TO_B || map==GL_PIXEL_MAP_I_TO_A) + need_pot=1; + if(need_pot && npot(mapsize)!=mapsize) { + errorShim(GL_INVALID_VALUE); + return; + } + int wf = 1; + void* array = NULL; + int* size = NULL; + if(!map_pixelmap(map, &wf, &size, &array)) + return; + noerrorShim(); + if(wf) { + GLfloat *p = (GLfloat*)array; + for (int i=0; i>8; + } else { + GLuint *p = (GLuint*)array; + for (int i=0; iselectbuf.hit) { + if (!glstate->selectbuf.overflow) { + //Normalize zmin/zmax + if((glstate->selectbuf.zmaxoverall - glstate->selectbuf.zminoverall)!=0.0f) { + glstate->selectbuf.zmin = (glstate->selectbuf.zmin-glstate->selectbuf.zminoverall)/(glstate->selectbuf.zmaxoverall - glstate->selectbuf.zminoverall); + glstate->selectbuf.zmax = (glstate->selectbuf.zmax-glstate->selectbuf.zminoverall)/(glstate->selectbuf.zmaxoverall - glstate->selectbuf.zminoverall); + } + int tocopy = glstate->namestack.top + 3; + if (tocopy+glstate->selectbuf.pos > glstate->selectbuf.size) { + glstate->selectbuf.overflow = 1; + tocopy = glstate->selectbuf.size - glstate->selectbuf.pos; + } + if(tocopy>0) + glstate->selectbuf.buffer[glstate->selectbuf.pos+0] = glstate->namestack.top; + if(tocopy>1) + glstate->selectbuf.buffer[glstate->selectbuf.pos+1] = (unsigned int)(glstate->selectbuf.zmin * INT_MAX ); + if(tocopy>2) + glstate->selectbuf.buffer[glstate->selectbuf.pos+2] = (unsigned int)(glstate->selectbuf.zmax * INT_MAX ); + if(tocopy>3) + memcpy(glstate->selectbuf.buffer + glstate->selectbuf.pos + 3, glstate->namestack.names, (tocopy-3) * sizeof(GLuint)); + + glstate->selectbuf.count++; + glstate->selectbuf.pos += tocopy; + } + glstate->selectbuf.hit = 0; + } + glstate->selectbuf.zmin = 1e10f; + glstate->selectbuf.zmax = -1e10f; + glstate->selectbuf.zminoverall = 1e10f; + glstate->selectbuf.zmaxoverall = -1e10f; +} + + +GLint gl4es_glRenderMode(GLenum mode) { + if(glstate->list.compiling) {errorShim(GL_INVALID_OPERATION); return 0;} + if(glstate->list.active) flush(); + + int ret = 0; + if ((mode==GL_SELECT) || (mode==GL_RENDER)) { // missing GL_FEEDBACK + noerrorShim(); + } else { + errorShim(GL_INVALID_ENUM); + return 0; + } + if (glstate->render_mode == GL_SELECT) { + push_hit(); + ret = glstate->selectbuf.count; + } + if (mode == GL_SELECT) { + if (glstate->selectbuf.buffer == NULL) {// error, cannot use Select Mode without select buffer + errorShim(GL_INVALID_OPERATION); + return 0; + } + glstate->selectbuf.count = 0; + glstate->selectbuf.pos = 0; + glstate->selectbuf.overflow = 0; + glstate->selectbuf.zmin = 1e10f; + glstate->selectbuf.zmax = -1e10f; + glstate->selectbuf.zminoverall = 1e10f; + glstate->selectbuf.zmaxoverall = -1e10f; + glstate->selectbuf.hit = 0; + } + + glstate->render_mode = mode; + return ret; +} + +void gl4es_glInitNames() { + if(glstate->list.active) { + NewStage(glstate->list.active, STAGE_RENDER); + glstate->list.active->render_op = 1; + return; + } + //TODO list stuffs + if (glstate->namestack.names == 0) { + glstate->namestack.names = (GLuint*)malloc(1024*sizeof(GLuint)); + } + glstate->namestack.top = 0; + noerrorShim(); +} + +void gl4es_glPopName() { + if(glstate->list.pending) + flush(); + if(glstate->list.active) { + NewStage(glstate->list.active, STAGE_RENDER); + glstate->list.active->render_op = 2; + return; + } + noerrorShim(); + if (glstate->render_mode != GL_SELECT) + return; + push_hit(); + if (glstate->namestack.top>0) + glstate->namestack.top--; + else + errorShim(GL_STACK_UNDERFLOW); +} + +void gl4es_glPushName(GLuint name) { + if(glstate->list.pending) + flush(); + if(glstate->list.active) { + NewStage(glstate->list.active, STAGE_RENDER); + glstate->list.active->render_op = 3; + glstate->list.active->render_arg = name; + return; + } + noerrorShim(); + if (glstate->render_mode != GL_SELECT) + return; + if (glstate->namestack.names==0) + return; + push_hit(); + if (glstate->namestack.top < 1024) { + glstate->namestack.names[glstate->namestack.top++] = name; + } +} + +void gl4es_glLoadName(GLuint name) { + if(glstate->list.pending) + flush(); + if(glstate->list.active) { + NewStage(glstate->list.active, STAGE_RENDER); + glstate->list.active->render_op = 4; + glstate->list.active->render_arg = name; + return; + } + noerrorShim(); + if (glstate->render_mode != GL_SELECT) + return; + if (glstate->namestack.names == 0) + return; + push_hit(); + if (glstate->namestack.top == 0) + return; + glstate->namestack.names[glstate->namestack.top-1] = name; +} + +void gl4es_glSelectBuffer(GLsizei size, GLuint *buffer) { + if (glstate->list.pending) + flush(); + + noerrorShim(); + glstate->selectbuf.buffer = buffer; + glstate->selectbuf.size = size; +} + +void select_transform(GLfloat *a) { + /* + Transform a[3] using projection and modelview matrix + */ + vector_matrix(a, getMVPMat(), a); + // take "w" into account... + a[0]/=a[3]; + a[1]/=a[3]; + a[2]/=a[3]; +} + +GLboolean select_point_in_viewscreen(const GLfloat *a) { + /* + Return True is point is inside the Viewport + */ + if (a[0]>-1.0 && a[0]<1.0 && a[1]>-1.0 && a[1]<1.0) { + return true; + } + return false; + +} + +GLboolean select_segment_in_viewscreen(const GLfloat *a, const GLfloat *b) { + /* + Return True is the segment is fully inside viewscreen + or cross the viewscreen + Viewscreen is (-1,-1)(+1,+1) + False if completly outside + */ + // Fast either point inside viewport + if (select_point_in_viewscreen(a)) return true; + if (select_point_in_viewscreen(b)) return true; + // Using Liang-Barsky algorithm + GLfloat vx, vy; + vx=b[0]-a[0]; + vy=b[1]-a[1]; + GLfloat p[4] = {-vx, vx, -vy, vy}; + GLfloat q[4] = {a[0] + 1.0f, +1.0f - a[0], a[1] + 1.0f, +1.0f - a[1]}; + GLfloat u1 = 0.0f; + GLfloat u2 = 1.0f; + + for (int i=0; i<4; i++) { + if (p[i] == 0.0f) { + if (q[i]<0.0f) + return false; + } else { + GLfloat t =q[i] / p[i]; + if (p[i]<0.0) { + if(t>u2) return false; + else if(u10.0) { + if(tt) + u2 = t; + } + } + } + return true; +} + +GLboolean select_triangle_in_viewscreen(const GLfloat *a, const GLfloat *b, const GLfloat *c) { + /* + Return True is the triangle is in the viewscreen, or completly include, or include the viewscreen + */ + // Check if any segment intersect the viewscreen (include test if any point is inside the viewscreen) + if (select_segment_in_viewscreen(a, b)) return true; + if (select_segment_in_viewscreen(b, c)) return true; + if (select_segment_in_viewscreen(c, a)) return true; + + // Now check if the viewscreen is completly inside the triangle + #define sign(p1, p2, p3) (p1[0]-p3[0])*(p2[1]-p3[1])-(p2[0]-p3[0])*(p1[1]-p3[1]) + for (int i=0; i<4; i++) { + GLboolean b1,b2,b3; + GLfloat pt[2]; + pt[0] = (i%2)?-1.0f:+1.0f; + pt[1] = (i>2)?-1.0f:+1.0f; + b1 = (sign(pt, a, b))<0.0f; + b2 = (sign(pt, b, c))<0.0f; + b3 = (sign(pt, c, a))<0.0f; + if ((b1==b2) && (b2==b3)) { + return true; + } + } + #undef sign + + return false; +} + +static void FASTMATH ZMinMax(GLfloat *zmin, GLfloat *zmax, GLfloat *vtx) { + if (vtx[2]<*zmin) *zmin=vtx[2]; + if (vtx[2]>*zmax) *zmax=vtx[2]; +} + + +void select_glDrawArrays(const pointer_state_t* vtx, GLenum mode, GLuint first, GLuint count) { + if (count == 0) return; + if (vtx->pointer == NULL) return; + if (glstate->selectbuf.buffer == NULL) return; + GLfloat *vert = copy_gl_array(vtx->pointer, vtx->type, + vtx->size, vtx->stride, + GL_FLOAT, 4, 0, count+first); + GLfloat zmin=1e10f, zmax=-1e10f; + int found = 0; + + #define FOUND() { \ + found = 1; \ + glstate->selectbuf.hit = 1; \ + } + + // transform the points + for (int i=first; iselectbuf.zminoverall, &glstate->selectbuf.zmaxoverall, vert+i*4); + } + // intersect with screen now + GLfloat *vert2 = vert + first*4; + for (int i=0; i0) { + if (select_segment_in_viewscreen(vert2+(i-1)*4, vert2+i*4)) { + ZMinMax(&zmin, &zmax, vert+(i-1)*4); + ZMinMax(&zmin, &zmax, vert+i*4); + FOUND(); + } + } + break; + case GL_TRIANGLES: + if (i%3==2) { + if (select_triangle_in_viewscreen(vert2+(i-2)*4, vert2+(i-1)*4, vert2+i*4)) { + ZMinMax(&zmin, &zmax, vert+(i-2)*4); + ZMinMax(&zmin, &zmax, vert+(i-1)*4); + ZMinMax(&zmin, &zmax, vert+i*4); + FOUND(); + } + } + break; + case GL_TRIANGLE_STRIP: + if (i>1) { + if (select_triangle_in_viewscreen(vert2+(i-2)*4, vert2+(i-1)*4, vert2+i*4)) { + ZMinMax(&zmin, &zmax, vert+(i-2)*4); + ZMinMax(&zmin, &zmax, vert+(i-1)*4); + ZMinMax(&zmin, &zmax, vert+i*4); + FOUND(); + } + } + break; + case GL_TRIANGLE_FAN: + if (i>1) { + if (select_triangle_in_viewscreen(vert2, vert2+(i-1)*4, vert2+i*4)) { + ZMinMax(&zmin, &zmax, vert); + ZMinMax(&zmin, &zmax, vert+(i-1)*4); + ZMinMax(&zmin, &zmax, vert+i*4); + FOUND(); + } + } + break; + default: + return; // Should never go there! + } + } + free(vert); + if(found) { + if (zminselectbuf.zmin) glstate->selectbuf.zmin=zmin; + if (zmax>glstate->selectbuf.zmax) glstate->selectbuf.zmax=zmax; + } + #undef FOUND +} + +void select_glDrawElements(const pointer_state_t* vtx, GLenum mode, GLuint count, GLenum type, GLvoid * indices) { + if (count == 0) return; + if (vtx->pointer == NULL) return; + + GLushort *sind = (GLushort*)((type==GL_UNSIGNED_SHORT)?indices:NULL); + GLuint *iind = (GLuint*)((type==GL_UNSIGNED_INT)?indices:NULL); + + GLsizei min, max; + if(sind) + getminmax_indices_us(sind, &max, &min, count); + else + getminmax_indices_ui(iind, &max, &min, count); + max++; + GLfloat *vert = copy_gl_array(vtx->pointer, vtx->type, + vtx->size, vtx->stride, + GL_FLOAT, 4, 0, max); + GLfloat zmin=1e10f, zmax=-10e6f; + int found = 0; + for (int i=min; iselectbuf.zminoverall, &glstate->selectbuf.zmaxoverall, vert+i*4); + } + + #define FOUND() { \ + found = 1; \ + glstate->selectbuf.hit = 1; \ + } + + if(sind) { + for (int i=0; i0) { + if (select_segment_in_viewscreen(vert+sind[(i-1)]*4, vert+sind[i]*4)) { + ZMinMax(&zmin, &zmax, vert+sind[i-1]*4); + ZMinMax(&zmin, &zmax, vert+sind[i]*4); + FOUND(); + } + } + break; + case GL_TRIANGLES: + if (i%3==2) { + if (select_triangle_in_viewscreen(vert+sind[(i-2)]*4, vert+sind[(i-1)]*4, vert+sind[i]*4)) { + ZMinMax(&zmin, &zmax, vert+sind[i-2]*4); + ZMinMax(&zmin, &zmax, vert+sind[i-1]*4); + ZMinMax(&zmin, &zmax, vert+sind[i]*4); + FOUND(); + } + } + break; + case GL_TRIANGLE_STRIP: + if (i>1) { + if (select_triangle_in_viewscreen(vert+sind[(i-2)]*4, vert+sind[(i-1)]*4, vert+sind[i]*4)) { + ZMinMax(&zmin, &zmax, vert+sind[i-2]*4); + ZMinMax(&zmin, &zmax, vert+sind[i-1]*4); + ZMinMax(&zmin, &zmax, vert+sind[i]*4); + FOUND(); + } + } + break; + case GL_TRIANGLE_FAN: + if (i>1) { + if (select_triangle_in_viewscreen(vert+sind[0]*4, vert+sind[(i-1)]*4, vert+sind[i]*4)) + ZMinMax(&zmin, &zmax, vert+sind[0]*4); + ZMinMax(&zmin, &zmax, vert+sind[i-1]*4); + ZMinMax(&zmin, &zmax, vert+sind[i]*4); + FOUND(); + } + break; + default: + return; // Should never go there! + } + } + } else { + for (int i=0; i0) { + if (select_segment_in_viewscreen(vert+iind[(i-1)]*4, vert+iind[i]*4)) { + ZMinMax(&zmin, &zmax, vert+iind[i-1]*4); + ZMinMax(&zmin, &zmax, vert+iind[i]*4); + FOUND(); + } + } + break; + case GL_TRIANGLES: + if (i%3==2) { + if (select_triangle_in_viewscreen(vert+iind[(i-2)]*4, vert+iind[(i-1)]*4, vert+iind[i]*4)) { + ZMinMax(&zmin, &zmax, vert+iind[i-2]*4); + ZMinMax(&zmin, &zmax, vert+iind[i-1]*4); + ZMinMax(&zmin, &zmax, vert+iind[i]*4); + FOUND(); + } + } + break; + case GL_TRIANGLE_STRIP: + if (i>1) { + if (select_triangle_in_viewscreen(vert+iind[(i-2)]*4, vert+iind[(i-1)]*4, vert+iind[i]*4)) { + ZMinMax(&zmin, &zmax, vert+iind[i-2]*4); + ZMinMax(&zmin, &zmax, vert+iind[i-1]*4); + ZMinMax(&zmin, &zmax, vert+iind[i]*4); + FOUND(); + } + } + break; + case GL_TRIANGLE_FAN: + if (i>1) { + if (select_triangle_in_viewscreen(vert+iind[0]*4, vert+iind[(i-1)]*4, vert+iind[i]*4)) + ZMinMax(&zmin, &zmax, vert+iind[0]*4); + ZMinMax(&zmin, &zmax, vert+iind[i-1]*4); + ZMinMax(&zmin, &zmax, vert+iind[i]*4); + FOUND(); + } + break; + default: + return; // Should never go there! + } + } + } + free(vert); + if(found) { + if (zminselectbuf.zmin) glstate->selectbuf.zmin=zmin; + if (zmax>glstate->selectbuf.zmax) glstate->selectbuf.zmax=zmax; + } + + #undef FOUND +} + +//Direct wrapper +GLint glRenderMode(GLenum mode) AliasExport("gl4es_glRenderMode"); +void glInitNames() AliasExport("gl4es_glInitNames"); +void glPopName() AliasExport("gl4es_glPopName"); +void glPushName(GLuint name) AliasExport("gl4es_glPushName"); +void glLoadName(GLuint name) AliasExport("gl4es_glLoadName"); +void glSelectBuffer(GLsizei size, GLuint *buffer) AliasExport("gl4es_glSelectBuffer"); diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/render.h b/Projects/Android/jni/SupportLibs/gl4es/src/gl/render.h new file mode 100644 index 0000000..42fdb9d --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/render.h @@ -0,0 +1,17 @@ +#ifndef _GL4ES_RENDER_H_ +#define _GL4ES_RENDER_H_ + +#include "buffers.h" +#include "gles.h" + +GLint gl4es_glRenderMode(GLenum mode); +void gl4es_glInitNames(); +void gl4es_glPopName(); +void gl4es_glPushName(GLuint name); +void gl4es_glLoadName(GLuint name); +void gl4es_glSelectBuffer(GLsizei size, GLuint *buffer); + +void select_glDrawElements(const pointer_state_t* vtx, GLenum mode, GLuint count, GLenum type, GLvoid * indices); +void select_glDrawArrays(const pointer_state_t* vtx, GLenum mode, GLuint first, GLuint count); + +#endif // _GL4ES_RENDER_H_ diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/shader.c b/Projects/Android/jni/SupportLibs/gl4es/src/gl/shader.c new file mode 100644 index 0000000..1d79f2d --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/shader.c @@ -0,0 +1,386 @@ +#include "shader.h" + +#include "../glx/hardext.h" +#include "debug.h" +#include "init.h" +#include "gl4es.h" +#include "glstate.h" +#include "loader.h" +#include "shaderconv.h" + +//#define DEBUG +#ifdef DEBUG +#define DBG(a) a +#else +#define DBG(a) +#endif + +KHASH_MAP_IMPL_INT(shaderlist, shader_t *); + +GLuint gl4es_glCreateShader(GLenum shaderType) { + DBG(printf("glCreateShader(%s)\n", PrintEnum(shaderType));) + // sanity check + if (shaderType!=GL_VERTEX_SHADER && shaderType!=GL_FRAGMENT_SHADER) { + DBG(printf("Invalid shader type\n");) + errorShim(GL_INVALID_ENUM); + return 0; + } + static GLuint lastshader = 0; + GLuint shader; + // create the shader + LOAD_GLES2(glCreateShader); + if(gles_glCreateShader) { + shader = gles_glCreateShader(shaderType); + if(!shader) { + DBG(printf("Failed to create shader\n");) + errorGL(); + return 0; + } + } else { + shader = ++lastshader; + noerrorShim(); + } + // store the new empty shader in the list for later use + khint_t k; + int ret; + khash_t(shaderlist) *shaders = glstate->glsl->shaders; + k = kh_get(shaderlist, shaders, shader); + shader_t *glshader = NULL; + if (k == kh_end(shaders)){ + k = kh_put(shaderlist, shaders, shader, &ret); + glshader = kh_value(shaders, k) = malloc(sizeof(shader_t)); + memset(glshader, 0, sizeof(shader_t)); + } else { + glshader = kh_value(shaders, k); + } + glshader->id = shader; + glshader->type = shaderType; + if(glshader->source) { + free(glshader->source); + glshader->source = NULL; + } + glshader->need.need_texcoord = -1; + + // all done + return shader; +} + +void actualy_deleteshader(GLuint shader) { + khint_t k; + int ret; + khash_t(shaderlist) *shaders = glstate->glsl->shaders; + k = kh_get(shaderlist, shaders, shader); + if (k != kh_end(shaders)) { + shader_t *glshader = kh_value(shaders, k); + if(glshader->deleted && !glshader->attached) { + kh_del(shaderlist, shaders, k); + if(glshader->source) + free(glshader->source); + if(glshader->converted) + free(glshader->converted); + free(glshader); + } + } +} + +void actualy_detachshader(GLuint shader) { + khint_t k; + int ret; + khash_t(shaderlist) *shaders = glstate->glsl->shaders; + k = kh_get(shaderlist, shaders, shader); + if (k != kh_end(shaders)) { + shader_t *glshader = kh_value(shaders, k); + if((--glshader->attached)<1 && glshader->deleted) + actualy_deleteshader(shader); + } +} + +void gl4es_glDeleteShader(GLuint shader) { + DBG(printf("glDeleteShader(%d)\n", shader);) + // sanity check... + CHECK_SHADER(void, shader) + // delete the shader from the list + if(!glshader) { + noerrorShim(); + return; + } + glshader->deleted = 1; + noerrorShim(); + if(!glshader->attached) { + actualy_deleteshader(shader); + + // delete the shader in GLES2 hardware (if any) + LOAD_GLES2(glDeleteShader); + if(gles_glDeleteShader) { + errorGL(); + gles_glDeleteShader(shader); + } + } +} + +void gl4es_glCompileShader(GLuint shader) { + DBG(printf("glCompileShader(%d)\n", shader);) + // look for the shader + CHECK_SHADER(void, shader) + + glshader->compiled = 1; + LOAD_GLES2(glCompileShader); + if(gles_glCompileShader) { + gles_glCompileShader(glshader->id); + errorGL(); + if(globals4es.logshader) { + // get compile status and print shaders sources if compile fail... + LOAD_GLES2(glGetShaderiv); + LOAD_GLES2(glGetShaderInfoLog); + GLint status = 0; + gles_glGetShaderiv(glshader->id, GL_COMPILE_STATUS, &status); + if(status!=GL_TRUE) { + printf("LIBGL: Error while compiling shader %d. Original source is:\n%s\n=======\n", glshader->id, glshader->source); + printf("ShaderConv Source is:\n%s\n=======\n", glshader->converted); + char tmp[500]; + GLint length; + gles_glGetShaderInfoLog(glshader->id, 500, &length, tmp); + printf("Compiler message is\n%s\nLIBGL: End of Error log\n", tmp); + } + } + } else + noerrorShim(); +} + +void gl4es_glShaderSource(GLuint shader, GLsizei count, const GLchar * const *string, const GLint *length) { + DBG(printf("glShaderSource(%d, %d, %p, %p)\n", shader, count, string, length);) + // sanity check + if(count<=0) { + errorShim(GL_INVALID_VALUE); + return; + } + CHECK_SHADER(void, shader) + // get the size of the shader sources and than concatenate in a single string + int l = 0; + for (int i=0; i= 0)?length[i]:strlen(string[i]); + if(glshader->source) free(glshader->source); + glshader->source = malloc(l+1); + memset(glshader->source, 0, l+1); + if(length) { + for (int i=0; i= 0) + strncat(glshader->source, string[i], length[i]); + else + strcat(glshader->source, string[i]); + } + } else { + for (int i=0; isource, string[i]); + } + LOAD_GLES2(glShaderSource); + if (gles_glShaderSource) { + // adapt shader if needed (i.e. not an es2 context and shader is not #version 100) + if(!glstate->glsl->es2 && strncmp(glshader->source, "#version 100", 12)) + glshader->converted = ConvertShader(glshader->source, glshader->type==GL_VERTEX_SHADER?1:0, &glshader->need); + // send source to GLES2 hardware if any + gles_glShaderSource(shader, 1, (const GLchar * const*)((glshader->converted)?(&glshader->converted):(&glshader->source)), NULL); + errorGL(); + } else + noerrorShim(); +} + +void accumShaderNeeds(GLuint shader, shaderconv_need_t *need) { + CHECK_SHADER(void, shader) + if(!glshader->converted) + return; + #define GO(A) if(need->need_##A < glshader->need.need_##A) need->need_##A = glshader->need.need_##A + GO(color); + GO(secondary); + GO(fogcoord); + GO(texcoord); + GO(normalmatrix); + GO(mvmatrix); + GO(mvpmatrix); + #undef GO +} +int isShaderCompatible(GLuint shader, shaderconv_need_t *need) { + CHECK_SHADER(int, shader) + if(!glshader->converted) + return 0; + #define GO(A) if(need->need_##A > glshader->need.need_##A) return 0; + GO(color); + GO(secondary); + GO(fogcoord); + GO(texcoord); + GO(normalmatrix); + GO(mvmatrix); + GO(mvpmatrix); + #undef GO + return 1; +} +void redoShader(GLuint shader, shaderconv_need_t *need) { + LOAD_GLES2(glShaderSource); + if(!gles_glShaderSource) + return; + CHECK_SHADER(void, shader) + if(!glshader->converted) + return; + // test, if no changes, no need to reconvert & recompile... + if (memcmp(&glshader->need, need, sizeof(shaderconv_need_t))==0) + return; + free(glshader->converted); + memcpy(&glshader->need, need, sizeof(shaderconv_need_t)); + glshader->converted = ConvertShader(glshader->source, glshader->type==GL_VERTEX_SHADER?1:0, &glshader->need); + // send source to GLES2 hardware if any + gles_glShaderSource(shader, 1, (const GLchar * const*)((glshader->converted)?(&glshader->converted):(&glshader->source)), NULL); + // recompile... + gl4es_glCompileShader(glshader->id); +} + +void gl4es_glGetShaderSource(GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *source) { + DBG(printf("glGetShaderSource(%d, %d, %p, %p)\n", shader, bufSize, length, source);) + // find shader + CHECK_SHADER(void, shader) + if (bufSize<=0) { + errorShim(GL_INVALID_OPERATION); + return; + } + // if no source, then it's an empty string + if(glshader->source==NULL) { + noerrorShim(); + if(length) *length = 0; + source[0] = '\0'; + return; + } + // copy concatenated sources + GLsizei size = strlen(glshader->source); + if (size+1>bufSize) size = bufSize-1; + strncpy(source, glshader->source, size); + source[size]='\0'; + if(length) *length=size; + noerrorShim(); +} + +GLboolean gl4es_glIsShader(GLuint shader) { + DBG(printf("glIsShader(%d)\n", shader);) + // find shader + shader_t *glshader = NULL; + khint_t k; + { + int ret; + khash_t(shaderlist) *shaders = glstate->glsl->shaders; + k = kh_get(shaderlist, shaders, shader); + if (k != kh_end(shaders)) + glshader = kh_value(shaders, k); + } + return (glshader)?GL_TRUE:GL_FALSE; +} + +static const char* GLES_NoGLSLSupport = "No Shader support with current backend"; + +void gl4es_glGetShaderInfoLog(GLuint shader, GLsizei maxLength, GLsizei *length, GLchar *infoLog) { + DBG(printf("glGetShaderInfoLog(%d, %d, %p, %p)\n", shader, maxLength, length, infoLog);) + // find shader + CHECK_SHADER(void, shader) + if(maxLength<=0) { + errorShim(GL_INVALID_OPERATION); + return; + } + LOAD_GLES2(glGetShaderInfoLog); + if(gles_glGetShaderInfoLog) { + gles_glGetShaderInfoLog(glshader->id, maxLength, length, infoLog); + errorGL(); + } else { + strncpy(infoLog, GLES_NoGLSLSupport, maxLength); + if(length) *length = strlen(infoLog); + } +} + +void gl4es_glGetShaderiv(GLuint shader, GLenum pname, GLint *params) { + DBG(printf("glGetShaderiv(%d, %s, %p)\n", shader, PrintEnum(pname), params);) + // find shader + CHECK_SHADER(void, shader) + LOAD_GLES2(glGetShaderiv); + noerrorShim(); + switch (pname) { + case GL_SHADER_TYPE: + *params = glshader->type; + break; + case GL_DELETE_STATUS: + *params = (glshader->deleted)?GL_TRUE:GL_FALSE; + break; + case GL_COMPILE_STATUS: + if(gles_glGetShaderiv) { + gles_glGetShaderiv(glshader->id, pname, params); + errorGL(); + } else { + *params = GL_FALSE; // stub, compile always fail + } + break; + case GL_INFO_LOG_LENGTH: + if(gles_glGetShaderiv) { + gles_glGetShaderiv(glshader->id, pname, params); + errorGL(); + } else { + *params = strlen(GLES_NoGLSLSupport); // stub, compile always fail + } + break; + case GL_SHADER_SOURCE_LENGTH: + if(glshader->source) + *params = strlen(glshader->source)+1; + else + *params = 0; + break; + default: + errorShim(GL_INVALID_ENUM); + } +} + +void gl4es_glGetShaderPrecisionFormat(GLenum shaderType, GLenum precisionType, GLint *range, GLint *precision) { + LOAD_GLES2(glGetShaderPrecisionFormat); + if(gles_glGetShaderPrecisionFormat) { + gles_glGetShaderPrecisionFormat(shaderType, precisionType, range, precision); + errorGL(); + } else { + errorShim(GL_INVALID_ENUM); + } +} + +void gl4es_glShaderBinary(GLsizei count, const GLuint *shaders, GLenum binaryFormat, const void *binary, GLsizei length) { + // TODO: check consistancy of "shaders" values + LOAD_GLES2(glShaderBinary); + if (gles_glShaderBinary) { + gles_glShaderBinary(count, shaders, binaryFormat, binary, length); + errorGL(); + } else { + errorShim(GL_INVALID_ENUM); + } +} + +void gl4es_glReleaseShaderCompiler(void) { + LOAD_GLES2(glReleaseShaderCompiler); + if(gles_glReleaseShaderCompiler) { + gles_glReleaseShaderCompiler(); + errorGL(); + } else + noerrorShim(); +} + +// ========== GL_ARB_shader_objects ============== + +GLuint glCreateShader(GLenum shaderType) AliasExport("gl4es_glCreateShader"); +void glDeleteShader(GLuint shader) AliasExport("gl4es_glDeleteShader"); +void glCompileShader(GLuint shader) AliasExport("gl4es_glCompileShader"); +void glShaderSource(GLuint shader, GLsizei count, const GLchar * const *string, const GLint *length) AliasExport("gl4es_glShaderSource"); +void glGetShaderSource(GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *source) AliasExport("gl4es_glGetShaderSource"); +GLboolean glIsShader(GLuint shader) AliasExport("gl4es_glIsShader"); +void glGetShaderInfoLog(GLuint shader, GLsizei maxLength, GLsizei *length, GLchar *infoLog) AliasExport("gl4es_glGetShaderInfoLog"); +void glGetShaderiv(GLuint shader, GLenum pname, GLint *params) AliasExport("gl4es_glGetShaderiv"); +void glGetShaderPrecisionFormat(GLenum shaderType, GLenum precisionType, GLint *range, GLint *precision) AliasExport("gl4es_glGetShaderPrecisionFormat"); +void glShaderBinary(GLsizei count, const GLuint *shaders, GLenum binaryFormat, const void *binary, GLsizei length) AliasExport("gl4es_glShaderBinary"); +void glReleaseShaderCompiler(void) AliasExport("gl4es_glReleaseShaderCompiler"); + + +GLhandleARB gl4es_glCreateShaderObject(GLenum shaderType) { + return gl4es_glCreateShader(shaderType); +} + +GLhandleARB glCreateShaderObjectARB(GLenum shaderType) AliasExport("gl4es_glCreateShaderObject"); +GLvoid glShaderSourceARB(GLhandleARB shaderObj, GLsizei count, const GLcharARB **string, const GLint *length) AliasExport("gl4es_glShaderSource"); +GLvoid glCompileShaderARB(GLhandleARB shaderObj) AliasExport("gl4es_glCompileShader"); +GLvoid glGetShaderSourceARB(GLhandleARB obj, GLsizei maxLength, GLsizei *length, GLcharARB *source) AliasExport("gl4es_glGetShaderSource"); diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/shader.h b/Projects/Android/jni/SupportLibs/gl4es/src/gl/shader.h new file mode 100644 index 0000000..b4ac6ce --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/shader.h @@ -0,0 +1,70 @@ +#ifndef _GL4ES_SHADER_H_ +#define _GL4ES_SHADER_H_ + +#include "khash.h" +#include "gles.h" + +typedef struct { + int need_color; // front and back + int need_secondary; // same + int need_fogcoord; + int need_texcoord; // max texcoord needed (-1 for none) + int need_normalmatrix; // if normal matrix is needed (for highp / mediump choosing) + int need_mvmatrix; + int need_mvpmatrix; +} shaderconv_need_t; + +typedef struct { + GLuint id; // internal id of the shader + GLenum type; // type of the shader (GL_VERTEX or GL_FRAGMENT) + int attached; // number of time the shader is attached + int deleted;// flagged for deletion + int compiled;// flag if compiled + char* source; // original source of the shader + char* converted; // converted source (or null if nothing) + // shaderconv + shaderconv_need_t need; // the varying need / provide of the shader +} shader_t; + +KHASH_MAP_DECLARE_INT(shaderlist, shader_t *); + +GLuint gl4es_glCreateShader(GLenum shaderType); +void gl4es_glDeleteShader(GLuint shader); +void gl4es_glCompileShader(GLuint shader); +void gl4es_glShaderSource(GLuint shader, GLsizei count, const GLchar * const *string, const GLint *length); +void gl4es_glGetShaderSource(GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *source); +GLboolean gl4es_glIsShader(GLuint shader); +void gl4es_glGetShaderInfoLog(GLuint shader, GLsizei maxLength, GLsizei *length, GLchar *infoLog); +void gl4es_glGetShaderiv(GLuint shader, GLenum pname, GLint *params); +void gl4es_glGetShaderPrecisionFormat(GLenum shaderType, GLenum precisionType, GLint *range, GLint *precision); +void gl4es_glShaderBinary(GLsizei count, const GLuint *shaders, GLenum binaryFormat, const void *binary, GLsizei length); +void gl4es_glReleaseShaderCompiler(void); + +void accumShaderNeeds(GLuint shader, shaderconv_need_t *need); +int isShaderCompatible(GLuint shader, shaderconv_need_t *need); +void redoShader(GLuint shader, shaderconv_need_t *need); + +#define CHECK_SHADER(type, shader) \ + if(!shader) { \ + noerrorShim(); \ + return (type)0; \ + } \ + shader_t *glshader = NULL; \ + khint_t k_##shader; \ + { \ + int ret; \ + khash_t(shaderlist) *shaders = glstate->glsl->shaders; \ + k_##shader = kh_get(shaderlist, shaders, shader); \ + if (k_##shader != kh_end(shaders)) \ + glshader = kh_value(shaders, k_##shader); \ + } \ + if (!glshader) { \ + errorShim(GL_INVALID_OPERATION); \ + return (type)0; \ + } + +// ========== GL_ARB_shader_objects ============== + +GLhandleARB gl4es_glCreateShaderObject(GLenum shaderType); + +#endif // _GL4ES_SHADER_H_ diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/shaderconv.c b/Projects/Android/jni/SupportLibs/gl4es/src/gl/shaderconv.c new file mode 100644 index 0000000..80b721e --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/shaderconv.c @@ -0,0 +1,780 @@ +#include "shaderconv.h" + +#include +#include "../glx/hardext.h" +#include "debug.h" +#include "fpe_shader.h" +#include "init.h" +#include "preproc.h" +#include "string_utils.h" + +typedef struct { + const char* glname; + const char* name; + const char* type; + const char* prec; + reserved_attrib_t attrib; +} builtin_attrib_t; + +const builtin_attrib_t builtin_attrib[] = { + {"gl_Vertex", "_gl4es_Vertex", "vec4", "highp", ATT_VERTEX}, + {"gl_Color", "_gl4es_Color", "vec4", "lowp", ATT_COLOR}, + {"gl_MultiTexCoord0", "_gl4es_MultiTexCoord0", "vec4", "highp", ATT_MULTITEXCOORD0}, + {"gl_MultiTexCoord1", "_gl4es_MultiTexCoord1", "vec4", "highp", ATT_MULTITEXCOORD1}, + {"gl_MultiTexCoord2", "_gl4es_MultiTexCoord2", "vec4", "highp", ATT_MULTITEXCOORD2}, + {"gl_MultiTexCoord3", "_gl4es_MultiTexCoord3", "vec4", "highp", ATT_MULTITEXCOORD3}, + {"gl_MultiTexCoord4", "_gl4es_MultiTexCoord4", "vec4", "highp", ATT_MULTITEXCOORD4}, + {"gl_MultiTexCoord5", "_gl4es_MultiTexCoord5", "vec4", "highp", ATT_MULTITEXCOORD5}, + {"gl_MultiTexCoord6", "_gl4es_MultiTexCoord6", "vec4", "highp", ATT_MULTITEXCOORD6}, + {"gl_MultiTexCoord7", "_gl4es_MultiTexCoord7", "vec4", "highp", ATT_MULTITEXCOORD7}, + {"gl_SecondaryColor", "_gl4es_SecondaryColor", "vec4", "lowp", ATT_SECONDARY}, + {"gl_Normal", "_gl4es_Normal", "vec3", "highp", ATT_NORMAL}, + {"gl_FogCoord", "_gl4es_FogCoord", "float", "highp", ATT_FOGCOORD} +}; + +typedef struct { + const char* glname; + const char* name; + const char* type; + int texarray; + reserved_matrix_t matrix; +} builtin_matrix_t; + +const builtin_matrix_t builtin_matrix[] = { + {"gl_ModelViewMatrixInverseTranspose", "_gl4es_ITModelViewMatrix", "mat4", 0, MAT_MV_IT}, + {"gl_ModelViewMatrixInverse", "_gl4es_IModelViewMatrix", "mat4", 0, MAT_MV_I}, + {"gl_ModelViewMatrixTranspose", "_gl4es_TModelViewMatrix", "mat4", 0, MAT_MV_T}, + {"gl_ModelViewMatrix", "_gl4es_ModelViewMatrix", "mat4", 0, MAT_MV}, + {"gl_ProjectionMatrixInverseTranspose", "_gl4es_ITProjectionMatrix", "mat4", 0, MAT_P_IT}, + {"gl_ProjectionMatrixInverse", "_gl4es_IProjectionMatrix", "mat4", 0, MAT_P_I}, + {"gl_ProjectionMatrixTranspose", "_gl4es_TProjectionMatrix", "mat4", 0, MAT_P_T}, + {"gl_ProjectionMatrix", "_gl4es_ProjectionMatrix", "mat4", 0, MAT_P}, + {"gl_ModelViewProjectionMatrixInverseTranspose", "_gl4es_ITModelViewProjectionMatrix", "mat4", 0, MAT_MVP_IT}, + {"gl_ModelViewProjectionMatrixInverse", "_gl4es_IModelViewProjectionMatrix", "mat4", 0, MAT_MVP_I}, + {"gl_ModelViewProjectionMatrixTranspose", "_gl4es_TModelViewProjectionMatrix", "mat4", 0, MAT_MVP_T}, + {"gl_ModelViewProjectionMatrix", "_gl4es_ModelViewProjectionMatrix", "mat4", 0, MAT_MVP}, + {"gl_TextureMatrixInverseTranspose", "_gl4es_ITTextureMatrix", "mat4", 1, MAT_T0_IT}, + {"gl_TextureMatrixInverse", "_gl4es_ITextureMatrix", "mat4", 1, MAT_T0_I}, + {"gl_TextureMatrixTranspose", "_gl4es_TTextureMatrix", "mat4", 1, MAT_T0_T}, + {"gl_TextureMatrix", "_gl4es_TextureMatrix", "mat4", 1, MAT_T0}, + {"gl_NormalMatrix", "_gl4es_NormalMatrix", "mat3", 0, MAT_N}, + // non standard version to avoid useless array of Matrix Uniform (in case the compiler as issue optimising this) + {"gl_TextureMatrix_0", "_gl4es_TextureMatrix_0", "mat4", 0, MAT_T0}, + {"gl_TextureMatrix_1", "_gl4es_TextureMatrix_1", "mat4", 0, MAT_T1}, + {"gl_TextureMatrix_2", "_gl4es_TextureMatrix_2", "mat4", 0, MAT_T2}, + {"gl_TextureMatrix_3", "_gl4es_TextureMatrix_3", "mat4", 0, MAT_T3}, + {"gl_TextureMatrix_4", "_gl4es_TextureMatrix_4", "mat4", 0, MAT_T4}, + {"gl_TextureMatrix_5", "_gl4es_TextureMatrix_5", "mat4", 0, MAT_T5}, + {"gl_TextureMatrix_6", "_gl4es_TextureMatrix_6", "mat4", 0, MAT_T6}, + {"gl_TextureMatrix_7", "_gl4es_TextureMatrix_7", "mat4", 0, MAT_T7} + }; + +#define STR_HELPER(x) #x +#define STR(x) STR_HELPER(x) +const char* gl4es_MaxLightsSource = +"#define _gl4es_MaxLights " STR(MAX_LIGHT) "\n"; +const char* gl4es_MaxClipPlanesSource = +"#define _gl4es_MaxClipPlanes " STR(MAX_CLIP_PLANES) "\n"; +const char* gl4es_MaxTextureUnitsSource = +"#define _gl4es_MaxTextureUnits " STR(MAX_TEX) "\n"; +const char* gl4es_MaxTextureCoordsSource = +"#define _gl4es_MaxTextureCoords " STR(MAX_TEX) "\n"; +#undef STR +#undef STR_HELPER + +const char* gl4es_LightSourceParametersSource = +"struct gl_LightSourceParameters\n" +"{\n" +" vec4 ambient;\n" +" vec4 diffuse;\n" +" vec4 specular;\n" +" vec4 position;\n" +" vec4 halfVector;\n" //halfVector = normalize(normalize(position) + vec3(0,0,1) if vbs==FALSE) +" vec3 spotDirection;\n" +" float spotExponent;\n" +" float spotCutoff;\n" +" float spotCosCutoff;\n" +" float constantAttenuation;\n" +" float linearAttenuation;\n" +" float quadraticAttenuation;\n" +"};\n" +"uniform gl_LightSourceParameters gl_LightSource[gl_MaxLights];\n"; + +const char* gl4es_LightModelParametersSource = +"struct gl_LightModelParameters {\n" +" vec4 ambient;\n" +"};\n" +"uniform gl_LightModelParameters gl_LightModel;\n"; + +const char* gl4es_MaterialParametersSource = +"struct gl_MaterialParameters\n" +"{\n" +" vec4 emission;\n" +" vec4 ambient;\n" +" vec4 diffuse;\n" +" vec4 specular;\n" +" float shininess;\n" +"};\n" +"uniform gl_MaterialParameters gl_FrontMaterial;\n" +"uniform gl_MaterialParameters gl_BackMaterial;\n"; + +const char* gl4es_LightModelProductsSource = +"struct gl_LightModelProducts\n" +"{\n" +" vec4 sceneColor;\n" +"};\n" +"uniform gl_LightModelProducts gl_FrontLightModelProduct;\n" +"uniform gl_LightModelProducts gl_BackLightModelProduct;\n"; + +const char* gl4es_LightProductsSource = +"struct gl_LightProducts\n" +"{\n" +" vec4 ambient;\n" +" vec4 diffuse;\n" +" vec4 specular;\n" +"};\n" +"uniform gl_LightProducts gl_FrontLightProduct[gl_MaxLights];\n" +"uniform gl_LightProducts gl_BackLightProduct[gl_MaxLights];\n"; + +const char* gl4es_PointSpriteSource = +"struct gl_PointParameters\n" +"{\n" +" float size;\n" +" float sizeMin;\n" +" float sizeMax;\n" +" float fadeThresholdSize;\n" +" float distanceConstantAttenuation;\n" +" float distanceLinearAttenuation;\n" +" float distanceQuadraticAttenuation;\n" +"};\n" +"uniform gl_PointParameters gl_Point;\n"; + +const char* gl4es_FogParametersSource = +"struct gl_FogParameters {\n" +" vec4 color;\n" +" float density;\n" +" float start;\n" +" float end;\n" +" float scale;\n" // Derived: 1.0 / (end - start) +"};\n" +"uniform gl_FogParameters gl_Fog;\n"; + +const char* gl4es_texenvcolorSource = +"uniform vec4 gl_TextureEnvColor[gl_MaxTextureUnits];\n"; + +const char* gl4es_texgeneyeSource[4] = { +"uniform vec4 gl_EyePlaneS[gl_MaxTextureCoords];\n", +"uniform vec4 gl_EyePlaneT[gl_MaxTextureCoords];\n", +"uniform vec4 gl_EyePlaneR[gl_MaxTextureCoords];\n", +"uniform vec4 gl_EyePlaneQ[gl_MaxTextureCoords];\n" }; + +const char* gl4es_texgenobjSource[4] = { +"uniform vec4 gl_ObjectPlaneS[gl_MaxTextureCoords];\n", +"uniform vec4 gl_ObjectPlaneT[gl_MaxTextureCoords];\n", +"uniform vec4 gl_ObjectPlaneR[gl_MaxTextureCoords];\n", +"uniform vec4 gl_ObjectPlaneQ[gl_MaxTextureCoords];\n" }; + +const char* gl4es_clipplanesSource = +"uniform vec4 gl_ClipPlane[gl_MaxClipPlanes];\n"; + +const char* gl4es_normalscaleSource = +"uniform float gl_NormalScale;\n"; + +const char* gl4es_instanceID = +"#define GL_ARB_draw_instanced 1\n" +"uniform int _gl4es_InstanceID;\n"; + +const char* gl4es_frontColorSource = +"varying lowp vec4 _gl4es_FrontColor;\n"; + +const char* gl4es_backColorSource = +"varying lowp vec4 _gl4es_BackColor;\n"; + +const char* gl4es_frontSecondaryColorSource = +"varying lowp vec4 _gl4es_FrontSecondaryColor;\n"; + +const char* gl4es_backSecondaryColorSource = +"varying lowp vec4 _gl4es_BackSecondaryColor;\n"; + +const char* gl4es_texcoordSource = +"varying mediump vec4 _gl4es_TexCoord[%d];\n"; + +const char* gl4es_texcoordSourceAlt = +"varying mediump vec4 _gl4es_TexCoord_%d;\n"; + +const char* gl4es_fogcoordSource = +"varying mediump float _gl4es_FogFragCoord;\n"; + +const char* gl4es_ftransformSource = +"\n" +"highp vec4 ftransform() {\n" +" return gl_ModelViewProjectionMatrix * gl_Vertex;\n" +"}\n"; + +const char* gl4es_dummyClipVertex = +"vec4 dummyClipVertex_%d"; + +const char* gl_TexCoordSource = "gl_TexCoord["; + +char* ConvertShader(const char* pEntry, int isVertex, shaderconv_need_t *need) +{ + int fpeShader = (strstr(pEntry, fpeshader_signature)!=NULL)?1:0; + int maskbefore = 4|(isVertex?1:2); + int maskafter = 8|(isVertex?1:2); + if((globals4es.dbgshaderconv&maskbefore)==maskbefore) { + printf("Shader source%s:\n%s\n", pEntry, fpeShader?" (FPEShader generated)":""); + } + int comments = globals4es.comments; + + char* pBuffer = (char*)pEntry; + + if(!fpeShader) { + extensions_t exts; // dummy... + exts.cap = exts.size = 0; + exts.ext = NULL; + // preproc first + pBuffer = preproc(pBuffer, comments, globals4es.shadernogles, &exts); + // now comment all line starting with precision... + if(strstr(pBuffer, "\nprecision")) { + int sz = strlen(pBuffer); + pBuffer = InplaceReplace(pBuffer, &sz, "\nprecision", "\n//precision"); + } + // should do something with the extension list... + if(exts.ext) + free(exts.ext); + } + + static shaderconv_need_t dummy_need; + if(!need) { + need = &dummy_need; + memset(need, 0, sizeof(shaderconv_need_t)); + need->need_texcoord = -1; + } + + // first change the version header, and add default precision + char* newptr; + newptr=strstr(pBuffer, "#version"); + if (!newptr) + newptr = (char*)pBuffer; + else { + while(*newptr!=0x0a) newptr++; + } + //const char* GLESUseFragHighp = "#extension GL_OES_fragment_precision_high : enable\n"; // does this one is needed? + const char* GLESHeader = "#version 100\n%sprecision %s float;\nprecision %s int;\n"; + char GLESFullHeader[512]; + int wanthighp = !fpeShader; + if(wanthighp && !hardext.highp) wanthighp = 0; + //sprintf(GLESFullHeader, GLESHeader, (wanthighp && hardext.highp==1 && !isVertex)?GLESUseFragHighp:"", (wanthighp)?"highp":"mediump", (wanthighp)?"highp":"mediump"); + sprintf(GLESFullHeader, GLESHeader, "", (wanthighp)?"highp":"mediump", (wanthighp)?"highp":"mediump"); + int tmpsize = strlen(newptr)*2+strlen(GLESFullHeader)+100; + char* Tmp = (char*)malloc(tmpsize); + strcpy(Tmp, GLESFullHeader); + int headline = 3; + // check if gl_FragDepth is used + int fragdepth = (strstr(pBuffer, "gl_FragDepth"))?1:0; + const char* GLESUseFragDepth = "#extension GL_EXT_frag_depth : enable\n"; + const char* GLESFakeFragDepth = "mediump float fakeFragDepth = 0.0;\n"; + if (fragdepth) { + /* If #extension is used, it should be placed before the second line of the header. */ + if(hardext.fragdepth) + InplaceInsert(GetLine(Tmp, 1), GLESUseFragDepth); + else + InplaceInsert(GetLine(Tmp, headline-1), GLESFakeFragDepth); + headline++; + } + int derivatives = (strstr(pBuffer, "dFdx(") || strstr(pBuffer, "dFdy(") || strstr(pBuffer, "fwidth("))?1:0; + const char* GLESUseDerivative = "#extension GL_OES_standard_derivatives : enable\n"; + // complete fake value... A better thing should be use.... + const char* GLESFakeDerivative = "float dFdx(float p) {return 0.0001;}\nvec2 dFdx(vec2 p) {return vec2(0.0001);}\nvec3 dFdx(vec3 p) {return vec3(0.0001);}\n" + "float dFdy(float p) {return 0.0001;}\nvec2 dFdy(vec2 p) {return vec2(0.0001);}\nvec3 dFdy(vec3 p) {return vec3(0.0001);}\n" + "float fwidth(float p) {return abs(dFdx(p))+abs(dFdy(p));}\nvec2 fwidth(vec2 p) {return abs(dFdx(p))+abs(dFdy(p));}\n" + "vec3 fwidth(vec3 p) {return abs(dFdx(p))+abs(dFdy(p));}\n"; + if (derivatives) { + /* If #extension is used, it should be placed before the second line of the header. */ + if(hardext.derivatives) + InplaceInsert(GetLine(Tmp, 1), GLESUseDerivative); + else + InplaceInsert(GetLine(Tmp, headline-1), GLESFakeDerivative); + headline++; + } + strcat(Tmp, newptr); + // now check to remove trailling "f" after float, as it's not supported too + newptr = Tmp; + // simple state machine... + int state = 0; + while (*newptr!=0x00) { + switch(state) { + case 0: + if ((*newptr >= '0') && (*newptr <= '9')) + state = 1; // integer part + else if (*newptr == '.') + state = 2; // fractional part + else if ((*newptr==' ') || (*newptr==0x0d) || (*newptr==0x0a) || (*newptr=='-') || (*newptr=='+') || (*newptr=='*') || (*newptr=='/') || (*newptr=='(') || (*newptr==')' || (*newptr=='>') || (*newptr=='<'))) + state = 0; // separator + else + state = 3; // something else + break; + case 1: // integer part + if ((*newptr >= '0') && (*newptr <= '9')) + state = 1; // integer part + else if (*newptr == '.') + state = 2; // fractional part + else if ((*newptr==' ') || (*newptr==0x0d) || (*newptr==0x0a) || (*newptr=='-') || (*newptr=='+') || (*newptr=='*') || (*newptr=='/') || (*newptr=='(') || (*newptr==')' || (*newptr=='>') || (*newptr=='<'))) + state = 0; // separator + else if ((*newptr == 'f' )) { + // remove that f + memmove(newptr, newptr+1, strlen(newptr+1)+1); + newptr--; + } else + state = 3; + break; + case 2: // fractionnal part + if ((*newptr >= '0') && (*newptr <= '9')) + state = 2; + else if ((*newptr==' ') || (*newptr==0x0d) || (*newptr==0x0a) || (*newptr=='-') || (*newptr=='+') || (*newptr=='*') || (*newptr=='/') || (*newptr=='(') || (*newptr==')' || (*newptr=='>') || (*newptr=='<'))) + state = 0; // separator + else if ((*newptr == 'f' )) { + // remove that f + memmove(newptr, newptr+1, strlen(newptr+1)+1); + newptr--; + } else + state = 3; + break; + case 3: + if ((*newptr==' ') || (*newptr==0x0d) || (*newptr==0x0a) || (*newptr=='-') || (*newptr=='+') || (*newptr=='*') || (*newptr=='/') || (*newptr=='(') || (*newptr==')' || (*newptr=='>') || (*newptr=='<'))) + state = 0; // separator + else + state = 3; + break; + } + newptr++; + } + Tmp = InplaceReplace(Tmp, &tmpsize, "gl_FragDepth", (hardext.fragdepth)?"gl_FragDepthEXT":"fakeFragDepth"); + { + // check for ftransform function + if(isVertex) { + if(strstr(Tmp, "ftransform(")) { + Tmp = ResizeIfNeeded(Tmp, &tmpsize, strlen(gl4es_ftransformSource)); + InplaceInsert(GetLine(Tmp, headline), gl4es_ftransformSource); + // don't increment headline count, as all variying and attributes should be created before + } + } + // check for builtin matrix uniform... + int n = sizeof(builtin_matrix)/sizeof(builtin_matrix_t); + for (int i=0; ineed_normalmatrix && !hardext.highp) + ishighp = 0; + if(!hardext.highp && !isVertex) + need->need_normalmatrix = 1; + } + if(builtin_matrix[i].matrix == MAT_MV) { + if(need->need_mvmatrix && !hardext.highp) + ishighp = 0; + if(!hardext.highp && !isVertex) + need->need_mvmatrix = 1; + } + if(builtin_matrix[i].matrix == MAT_MVP) { + if(need->need_mvpmatrix && !hardext.highp) + ishighp = 0; + if(!hardext.highp && !isVertex) + need->need_mvpmatrix = 1; + } + if(builtin_matrix[i].texarray) + sprintf(def, "uniform %s%s %s[%d];\n", (ishighp)?"highp ":"mediump ", builtin_matrix[i].type, builtin_matrix[i].name, hardext.maxtex); + else + sprintf(def, "uniform %s%s %s;\n", (ishighp)?"highp ":"mediump ", builtin_matrix[i].type, builtin_matrix[i].name); + Tmp = ResizeIfNeeded(Tmp, &tmpsize, strlen(def)); + InplaceInsert(GetLine(Tmp, headline++), def); + } + } + } + // Handling of gl_LightSource[x].halfVector => normalize(gl_LightSource[x].position - gl_Vertex), but what if in the FragShader ? +/* if(strstr(Tmp, "halfVector")) + { + char *p = Tmp; + while((p=strstr(p, "gl_LightSource["))) { + char *p2 = strchr(p, ']'); + if (p2 && !strncmp(p2, "].halfVector", strlen("].halfVector"))) { + // found an occurence, lets change + char p3[500]; + strncpy(p3,p, (p2-p)+1); p3[(p2-p)+1]='\0'; + char p4[500], p5[500]; + sprintf(p4, "%s.halfVector", p3); + sprintf(p5, "normalize(normalize(%s.position.xyz) + vec3(0., 0., 1.))", p3); + Tmp = InplaceReplace(Tmp, &tmpsize, p4, p5); + p = Tmp; + } else + ++p; + } + }*/ + // checking "#extension" keyword, and clean up some... + /*{ + char* p = strstr(Tmp, "#extension"); // should test this is #first character in the line + while(p) { + char *p2 = NextStr(StrNext(Tmp, "#extension")); + char *p3 = NextBlank(p2); + char keyw[50]; + if(p3-p2<50) { + strncpy(keyw, p2, p3-p2); + // now, checking the keywords... + if(strcmp(keyw, "GL_ARB_draw_instanced")==0) { + // ok, this one is safe to ignore... Not even checking what state is asked + p3 = NextLine(p); + while (p!=p3) *(p++)=' '; // blank the line.... + } + } + // all done + p = strstr(p+1, "#extension"); + } + }*/ // done in preproc now + if(isVertex) { + // check for builtin OpenGL attributes... + int n = sizeof(builtin_attrib)/sizeof(builtin_attrib_t); + for (int i=0; ineed_color) { + if(need->need_color<1) need->need_color = 1; + Tmp = InplaceReplace(Tmp, &tmpsize, "gl_Color", (need->need_color==1)?"gl_FrontColor":"(gl_FrontFacing?gl_FrontColor:gl_BackColor)"); + } + if(strstr(Tmp, "gl_FrontColor") || need->need_color) { + if(need->need_color<1) need->need_color = 1; + nvarying+=1; + Tmp = ResizeIfNeeded(Tmp, &tmpsize, strlen(gl4es_frontColorSource)); + InplaceInsert(GetLine(Tmp, headline), gl4es_frontColorSource); + headline+=CountLine(gl4es_frontColorSource); + Tmp = InplaceReplace(Tmp, &tmpsize, "gl_FrontColor", "_gl4es_FrontColor"); + } + if(strstr(Tmp, "gl_BackColor") || (need->need_color==2)) { + need->need_color = 2; + nvarying+=1; + Tmp = ResizeIfNeeded(Tmp, &tmpsize, strlen(gl4es_backColorSource)); + InplaceInsert(GetLine(Tmp, headline), gl4es_backColorSource); + headline+=CountLine(gl4es_backColorSource); + Tmp = InplaceReplace(Tmp, &tmpsize, "gl_BackColor", "_gl4es_BackColor"); + } + if(strstr(Tmp, "gl_SecondaryColor") || need->need_secondary) { + if(need->need_secondary<1) need->need_secondary = 1; + Tmp = InplaceReplace(Tmp, &tmpsize, "gl_SecondaryColor", (need->need_secondary==1)?"gl_FrontSecondaryColor":"(gl_FrontFacing?gl_FrontSecondaryColor:gl_BackSecondaryColor)"); + } + if(strstr(Tmp, "gl_FrontSecondaryColor") || need->need_secondary) { + if(need->need_secondary<1) need->need_secondary = 1; + nvarying+=1; + Tmp = ResizeIfNeeded(Tmp, &tmpsize, strlen(gl4es_frontSecondaryColorSource)); + InplaceInsert(GetLine(Tmp, headline), gl4es_frontSecondaryColorSource); + headline+=CountLine(gl4es_frontSecondaryColorSource); + Tmp = InplaceReplace(Tmp, &tmpsize, "gl_FrontSecondaryColor", "_gl4es_FrontSecondaryColor"); + } + if(strstr(Tmp, "gl_BackSecondaryColor") || (need->need_secondary==2)) { + need->need_secondary = 2; + nvarying+=1; + Tmp = ResizeIfNeeded(Tmp, &tmpsize, strlen(gl4es_backSecondaryColorSource)); + InplaceInsert(GetLine(Tmp, headline), gl4es_backSecondaryColorSource); + headline+=CountLine(gl4es_backSecondaryColorSource); + Tmp = InplaceReplace(Tmp, &tmpsize, "gl_BackSecondaryColor", "_gl4es_BackSecondaryColor"); + } + if(strstr(Tmp, "gl_FogFragCoord") || need->need_fogcoord) { + need->need_fogcoord = 1; + nvarying+=1; + Tmp = ResizeIfNeeded(Tmp, &tmpsize, strlen(gl4es_fogcoordSource)); + InplaceInsert(GetLine(Tmp, headline), gl4es_fogcoordSource); + headline+=CountLine(gl4es_fogcoordSource); + Tmp = InplaceReplace(Tmp, &tmpsize, "gl_FogFragCoord", "_gl4es_FogFragCoord"); + } + if(strstr(Tmp, "gl_TexCoord") || need->need_texcoord!=-1) { + int ntex = need->need_texcoord; + // Try to determine max gl_TexCoord used + char* p = Tmp; + while((p=strstr(p, gl_TexCoordSource))) { + p+=strlen(gl_TexCoordSource); + if(*p>='0' && *p<='9') { + int n = (*p) - '0'; + if (ntexhardext.maxvarying) ntex = hardext.maxvarying - nvarying; + need->need_texcoord = ntex; + char d[100]; + if(globals4es.notexarray) { + for (int k=0; klist.active) + if (glstate->list.compiling) { + NewStage(glstate->list.active, STAGE_PUSH); + glstate->list.active->pushattribute = mask; + return; + } else flush(); + + if (glstate->stack == NULL) { + glstate->stack = (glstack_t *)malloc(STACK_SIZE * sizeof(glstack_t)); + glstate->stack->len = 0; + glstate->stack->cap = STACK_SIZE; + } else if (glstate->stack->len == glstate->stack->cap) { + glstate->stack->cap += STACK_SIZE; + glstate->stack = (glstack_t *)realloc(glstate->stack, glstate->stack->cap * sizeof(glstack_t)); + } + + glstack_t *cur = glstate->stack + glstate->stack->len; + cur->mask = mask; + cur->clip_planes_enabled = NULL; + cur->clip_planes = NULL; + cur->lights_enabled = NULL; + cur->lights = NULL; + cur->materials = NULL; + + // TODO: GL_ACCUM_BUFFER_BIT + + // TODO: will tracking these myself be much faster than glGet? + if (mask & GL_COLOR_BUFFER_BIT) { + cur->alpha_test = gl4es_glIsEnabled(GL_ALPHA_TEST); + gl4es_glGetIntegerv(GL_ALPHA_TEST_FUNC, &cur->alpha_test_func); + gl4es_glGetFloatv(GL_ALPHA_TEST_REF, &cur->alpha_test_ref); + + cur->blend = gl4es_glIsEnabled(GL_BLEND); + gl4es_glGetIntegerv(GL_BLEND_SRC, &cur->blend_src_func); + gl4es_glGetIntegerv(GL_BLEND_DST, &cur->blend_dst_func); + + cur->dither = gl4es_glIsEnabled(GL_DITHER); + cur->color_logic_op = gl4es_glIsEnabled(GL_COLOR_LOGIC_OP); + gl4es_glGetIntegerv(GL_LOGIC_OP_MODE, &cur->logic_op); + + gl4es_glGetFloatv(GL_COLOR_CLEAR_VALUE, cur->clear_color); + gl4es_glGetFloatv(GL_COLOR_WRITEMASK, cur->color_mask); + } + + if (mask & GL_CURRENT_BIT) { + gl4es_glGetFloatv(GL_CURRENT_COLOR, cur->color); + gl4es_glGetFloatv(GL_CURRENT_NORMAL, cur->normal); + gl4es_glGetFloatv(GL_CURRENT_TEXTURE_COORDS, cur->tex); + } + + if (mask & GL_DEPTH_BUFFER_BIT) { + cur->depth_test = gl4es_glIsEnabled(GL_DEPTH_TEST); + gl4es_glGetIntegerv(GL_DEPTH_FUNC, &cur->depth_func); + gl4es_glGetFloatv(GL_DEPTH_CLEAR_VALUE, &cur->clear_depth); + gl4es_glGetIntegerv(GL_DEPTH_WRITEMASK, &cur->depth_mask); + } + + if (mask & GL_ENABLE_BIT) { + int i; + + cur->alpha_test = gl4es_glIsEnabled(GL_ALPHA_TEST); + cur->autonormal = gl4es_glIsEnabled(GL_AUTO_NORMAL); + cur->blend = gl4es_glIsEnabled(GL_BLEND); + + cur->clip_planes_enabled = (GLboolean *)malloc(hardext.maxplanes * sizeof(GLboolean)); + for (i = 0; i < hardext.maxplanes; i++) { + *(cur->clip_planes_enabled + i) = gl4es_glIsEnabled(GL_CLIP_PLANE0 + i); + } + + cur->colormaterial = gl4es_glIsEnabled(GL_COLOR_MATERIAL); + cur->cull_face = gl4es_glIsEnabled(GL_CULL_FACE); + cur->depth_test = gl4es_glIsEnabled(GL_DEPTH_TEST); + cur->dither = gl4es_glIsEnabled(GL_DITHER); + cur->fog = gl4es_glIsEnabled(GL_FOG); + + cur->lights_enabled = (GLboolean *)malloc(hardext.maxlights * sizeof(GLboolean)); + for (i = 0; i < hardext.maxlights; i++) { + *(cur->lights_enabled + i) = gl4es_glIsEnabled(GL_LIGHT0 + i); + } + + cur->lighting = gl4es_glIsEnabled(GL_LIGHTING); + cur->line_smooth = gl4es_glIsEnabled(GL_LINE_SMOOTH); + cur->line_stipple = gl4es_glIsEnabled(GL_LINE_STIPPLE); + cur->color_logic_op = gl4es_glIsEnabled(GL_COLOR_LOGIC_OP); + //TODO: GL_INDEX_LOGIC_OP + //TODO: GL_MAP1_x + //TODO: GL_MAP2_x + cur->multisample = gl4es_glIsEnabled(GL_MULTISAMPLE); + cur->normalize = gl4es_glIsEnabled(GL_NORMALIZE); + cur->point_smooth = gl4es_glIsEnabled(GL_POINT_SMOOTH); + //TODO: GL_POLYGON_OFFSET_LINE + cur->polygon_offset_fill = gl4es_glIsEnabled(GL_POLYGON_OFFSET_FILL); + //TODO: GL_POLYGON_OFFSET_POINT + //TODO: GL_POLYGON_SMOOTH + //TODO: GL_POLYGON_STIPPLE + cur->sample_alpha_to_coverage = gl4es_glIsEnabled(GL_SAMPLE_ALPHA_TO_COVERAGE); + cur->sample_alpha_to_one = gl4es_glIsEnabled(GL_SAMPLE_ALPHA_TO_ONE); + cur->sample_coverage = gl4es_glIsEnabled(GL_SAMPLE_COVERAGE); + cur->scissor_test = gl4es_glIsEnabled(GL_SCISSOR_TEST); + cur->stencil_test = gl4es_glIsEnabled(GL_STENCIL_TEST); + int a; + for (a=0; atex_enabled[a] = glstate->enable.texture[a]; + cur->texgen_s[a] = glstate->enable.texgen_s[a]; + cur->texgen_r[a] = glstate->enable.texgen_r[a]; + cur->texgen_t[a] = glstate->enable.texgen_t[a]; + cur->texgen_q[a] = glstate->enable.texgen_q[a]; + } + cur->pointsprite = gl4es_glIsEnabled(GL_POINT_SPRITE); + } + + // TODO: GL_EVAL_BIT + + if (mask & GL_FOG_BIT) { + cur->fog = gl4es_glIsEnabled(GL_FOG); + gl4es_glGetFloatv(GL_FOG_COLOR, cur->fog_color); + gl4es_glGetFloatv(GL_FOG_DENSITY, &cur->fog_density); + gl4es_glGetFloatv(GL_FOG_START, &cur->fog_start); + gl4es_glGetFloatv(GL_FOG_END, &cur->fog_end); + gl4es_glGetIntegerv(GL_FOG_MODE, &cur->fog_mode); + } + + if (mask & GL_HINT_BIT) { + gl4es_glGetIntegerv(GL_PERSPECTIVE_CORRECTION_HINT, &cur->perspective_hint); + gl4es_glGetIntegerv(GL_POINT_SMOOTH_HINT, &cur->point_smooth_hint); + gl4es_glGetIntegerv(GL_LINE_SMOOTH_HINT, &cur->line_smooth_hint); + gl4es_glGetIntegerv(GL_FOG_HINT, &cur->fog_hint); + gl4es_glGetIntegerv(GL_GENERATE_MIPMAP_HINT, &cur->mipmap_hint); + for (int i=GL4ES_HINT_FIRST; igles4_hint[i-GL4ES_HINT_FIRST]); + } + + if (mask & GL_LIGHTING_BIT) { + cur->lighting = gl4es_glIsEnabled(GL_LIGHTING); + gl4es_glGetFloatv(GL_LIGHT_MODEL_AMBIENT, cur->light_model_ambient); + gl4es_glGetIntegerv(GL_LIGHT_MODEL_TWO_SIDE, &cur->light_model_two_side); + + int i; + int j=0; + cur->lights_enabled = (GLboolean *)malloc(hardext.maxlights * sizeof(GLboolean)); + cur->lights = (GLfloat *)malloc(hardext.maxlights * sizeof(GLfloat)*(10*4)); + for (i = 0; i < hardext.maxlights; i++) { + *(cur->lights_enabled + i) = gl4es_glIsEnabled(GL_LIGHT0 + i); + #define L(A) gl4es_glGetLightfv(GL_LIGHT0 + i, A, cur->lights+j); j+=4 + L(GL_AMBIENT); + L(GL_DIFFUSE); + L(GL_SPECULAR); + L(GL_POSITION); + L(GL_SPOT_CUTOFF); + L(GL_SPOT_DIRECTION); + L(GL_SPOT_EXPONENT); + L(GL_CONSTANT_ATTENUATION); + L(GL_LINEAR_ATTENUATION); + L(GL_QUADRATIC_ATTENUATION); + #undef L + } + j=0; + cur->materials = (GLfloat *)malloc(2 * sizeof(GLfloat)*(5*4)); + memset(cur->materials, 0, 2 * sizeof(GLfloat)*(5*4)); + #define M(A) gl4es_glGetMaterialfv(GL_BACK, A, cur->materials+j); j+=4; gl4es_glGetMaterialfv(GL_FRONT, A, cur->materials+j); j+=4 + M(GL_AMBIENT); M(GL_DIFFUSE); M(GL_SPECULAR); M(GL_EMISSION); M(GL_SHININESS); // handle both face at some point? + #undef M + gl4es_glGetIntegerv(GL_SHADE_MODEL, &cur->shade_model); + } + + if (mask & GL_LINE_BIT) { + cur->line_smooth = gl4es_glIsEnabled(GL_LINE_SMOOTH); + // TODO: stipple stuff here + gl4es_glGetFloatv(GL_LINE_WIDTH, &cur->line_width); + } + + // GL_LIST_BIT + if (mask & GL_LIST_BIT) { + cur->list_base = glstate->list.base; + } + + if (mask & GL_MULTISAMPLE_BIT) { + cur->multisample = gl4es_glIsEnabled(GL_MULTISAMPLE); + cur->sample_alpha_to_coverage = gl4es_glIsEnabled(GL_SAMPLE_ALPHA_TO_COVERAGE); + cur->sample_alpha_to_one = gl4es_glIsEnabled(GL_SAMPLE_ALPHA_TO_ONE); + cur->sample_coverage = gl4es_glIsEnabled(GL_SAMPLE_COVERAGE); + } + + // GL_PIXEL_MODE_BIT + if (mask & GL_PIXEL_MODE_BIT) { + GLenum pixel_name[] = {GL_RED_BIAS, GL_RED_SCALE, GL_GREEN_BIAS, GL_GREEN_SCALE, GL_BLUE_BIAS, GL_BLUE_SCALE, GL_ALPHA_BIAS, GL_ALPHA_SCALE}; + int i; + for (i=0; i<8; i++) + gl4es_glGetFloatv(pixel_name[i], &cur->pixel_scale_bias[i]); + //TODO: GL_DEPTH_BIAS & GL_DEPTH_SCALE (probably difficult) + //TODO: GL_INDEX_OFFEST & GL_INDEX_SHIFT + //TODO: GL_MAP_COLOR & GL_MAP_STENCIL (probably difficult too) + gl4es_glGetFloatv(GL_ZOOM_X, &cur->pixel_zoomx); + gl4es_glGetFloatv(GL_ZOOM_Y, &cur->pixel_zoomy); + } + + if (mask & GL_POINT_BIT) { + cur->point_smooth = gl4es_glIsEnabled(GL_POINT_SMOOTH); + gl4es_glGetFloatv(GL_POINT_SIZE, &cur->point_size); + if(hardext.pointsprite) { + cur->pointsprite = gl4es_glIsEnabled(GL_POINT_SPRITE); + int a; + for (a=0; apscoordreplace[a] = glstate->texture.pscoordreplace[a]; + } + } + } + + // TODO: GL_POLYGON_BIT + // TODO: GL_POLYGON_STIPPLE_BIT + + if (mask & GL_SCISSOR_BIT) { + cur->scissor_test = gl4es_glIsEnabled(GL_SCISSOR_TEST); + gl4es_glGetFloatv(GL_SCISSOR_BOX, cur->scissor_box); + } + + // TODO: GL_STENCIL_BUFFER_BIT on both faces + if (mask & GL_STENCIL_BUFFER_BIT) { + cur->stencil_test = gl4es_glIsEnabled(GL_STENCIL_TEST); + gl4es_glGetIntegerv(GL_STENCIL_FUNC, &cur->stencil_func); + gl4es_glGetIntegerv(GL_STENCIL_VALUE_MASK, &cur->stencil_mask); + gl4es_glGetIntegerv(GL_STENCIL_REF, &cur->stencil_ref); + //TODO: glStencilFuncSeperate + + //TODO: Stencil value mask + gl4es_glGetIntegerv(GL_STENCIL_FAIL, &cur->stencil_sfail); + gl4es_glGetIntegerv(GL_STENCIL_PASS_DEPTH_FAIL, &cur->stencil_dpfail); + gl4es_glGetIntegerv(GL_STENCIL_PASS_DEPTH_PASS, &cur->stencil_dppass); + //TODO: glStencilOpSeparate + + gl4es_glGetIntegerv(GL_STENCIL_CLEAR_VALUE, &cur->stencil_clearvalue); + //TODO: Stencil buffer writemask + } + // GL_TEXTURE_BIT - TODO: incomplete + if (mask & GL_TEXTURE_BIT) { + cur->active=glstate->texture.active; + int a; + for (a=0; atexgen_r[a] = glstate->enable.texgen_r[a]; + cur->texgen_s[a] = glstate->enable.texgen_s[a]; + cur->texgen_t[a] = glstate->enable.texgen_t[a]; + cur->texgen_q[a] = glstate->enable.texgen_q[a]; + cur->texgen[a] = glstate->texgen[a]; // all mode and planes per texture in 1 line + for (int j=0; jtexture[a][j] = glstate->texture.bound[a][j]->texture; + } + //glActiveTexture(GL_TEXTURE0+cur->active); + } + + // GL_TRANSFORM_BIT + if (mask & GL_TRANSFORM_BIT) { + if (!(mask & GL_ENABLE_BIT)) { + int i; + cur->clip_planes_enabled = (GLboolean *)malloc(hardext.maxplanes * sizeof(GLboolean)); + for (i = 0; i < hardext.maxplanes; i++) { + *(cur->clip_planes_enabled + i) = gl4es_glIsEnabled(GL_CLIP_PLANE0 + i); + } + } + gl4es_glGetIntegerv(GL_MATRIX_MODE, &cur->matrix_mode); + cur->rescale_normal_flag = gl4es_glIsEnabled(GL_RESCALE_NORMAL); + cur->normalize_flag = gl4es_glIsEnabled(GL_NORMALIZE); + } + // GL_VIEWPORT_BIT + if (mask & GL_VIEWPORT_BIT) { + gl4es_glGetIntegerv(GL_VIEWPORT, cur->viewport_size); + gl4es_glGetFloatv(GL_DEPTH_RANGE, cur->depth_range); + } + + glstate->stack->len++; +} + +void gl4es_glPushClientAttrib(GLbitfield mask) { + noerrorShim(); + if (glstate->list.pending) { + flush(); + } + if (glstate->clientStack == NULL) { + glstate->clientStack = (glclientstack_t *)malloc(STACK_SIZE * sizeof(glclientstack_t)); + glstate->clientStack->len = 0; + glstate->clientStack->cap = STACK_SIZE; + } else if (glstate->clientStack->len == glstate->clientStack->cap) { + glstate->clientStack->cap += STACK_SIZE; + glstate->clientStack = (glclientstack_t *)realloc(glstate->clientStack, glstate->clientStack->cap * sizeof(glclientstack_t)); + } + + glclientstack_t *cur = glstate->clientStack + glstate->clientStack->len; + cur->mask = mask; + + if (mask & GL_CLIENT_PIXEL_STORE_BIT) { + gl4es_glGetIntegerv(GL_PACK_ALIGNMENT, &cur->pack_align); + gl4es_glGetIntegerv(GL_UNPACK_ALIGNMENT, &cur->unpack_align); + cur->unpack_row_length = glstate->texture.unpack_row_length; + cur->unpack_skip_pixels = glstate->texture.unpack_skip_pixels; + cur->unpack_skip_rows = glstate->texture.unpack_skip_rows; + cur->pack_row_length = glstate->texture.pack_row_length; + cur->pack_skip_pixels = glstate->texture.pack_skip_pixels; + cur->pack_skip_rows = glstate->texture.pack_skip_rows; + } + + if (mask & GL_CLIENT_VERTEX_ARRAY_BIT) { + cur->vert_enable = glstate->vao->pointers[ATT_VERTEX].enabled; + cur->color_enable = glstate->vao->pointers[ATT_COLOR].enabled; + cur->secondary_enable = glstate->vao->pointers[ATT_SECONDARY].enabled; + cur->normal_enable = glstate->vao->pointers[ATT_NORMAL].enabled; + cur->fog_enable = glstate->vao->pointers[ATT_FOGCOORD].enabled; + int a; + for (a=0; atex_enable[a] = glstate->vao->pointers[ATT_MULTITEXCOORD0+a].enabled; + } + memcpy(&(cur->pointers), &glstate->vao->pointers, sizeof(glstate->vao->pointers)); + cur->client = glstate->texture.client; + } + + glstate->clientStack->len++; +} + +#define maybe_free(x) \ + if (x) free(x) + +#define enable_disable(pname, enabled) \ + if (enabled) gl4es_glEnable(pname); \ + else gl4es_glDisable(pname) + +#define v2(c) c[0], c[1] +#define v3(c) v2(c), c[2] +#define v4(c) v3(c), c[3] + +void gl4es_glPopAttrib() { +//printf("glPopAttrib()\n"); + noerrorShim(); + if (glstate->list.active) + if (glstate->list.compiling) { + NewStage(glstate->list.active, STAGE_POP); + glstate->list.active->popattribute = true; + return; + } else flush(); + + if (glstate->stack == NULL || glstate->stack->len == 0) { + errorShim(GL_STACK_UNDERFLOW); + return; + } + + glstack_t *cur = glstate->stack + glstate->stack->len-1; + + if (cur->mask & GL_COLOR_BUFFER_BIT) { + enable_disable(GL_ALPHA_TEST, cur->alpha_test); + gl4es_glAlphaFunc(cur->alpha_test_func, cur->alpha_test_ref); + + enable_disable(GL_BLEND, cur->blend); + gl4es_glBlendFunc(cur->blend_src_func, cur->blend_dst_func); + + enable_disable(GL_DITHER, cur->dither); + enable_disable(GL_COLOR_LOGIC_OP, cur->color_logic_op); + gl4es_glLogicOp(cur->logic_op); + + GLfloat *c; + gl4es_glClearColor(v4(cur->clear_color)); + gl4es_glColorMask(v4(cur->color_mask)); + } + + if (cur->mask & GL_CURRENT_BIT) { + gl4es_glColor4f(v4(cur->color)); + gl4es_glNormal3f(v3(cur->normal)); + gl4es_glTexCoord4f(v4(cur->tex)); + } + + if (cur->mask & GL_DEPTH_BUFFER_BIT) { + enable_disable(GL_DEPTH_TEST, cur->depth_test); + gl4es_glDepthFunc(cur->depth_func); + gl4es_glClearDepth(cur->clear_depth); + gl4es_glDepthMask(cur->depth_mask); + } + + if (cur->mask & GL_ENABLE_BIT) { + int i; + + enable_disable(GL_ALPHA_TEST, cur->alpha_test); + enable_disable(GL_AUTO_NORMAL, cur->autonormal); + enable_disable(GL_BLEND, cur->blend); + + for (i = 0; i < hardext.maxplanes; i++) { + enable_disable(GL_CLIP_PLANE0 + i, *(cur->clip_planes_enabled + i)); + } + + enable_disable(GL_COLOR_MATERIAL, cur->colormaterial); + enable_disable(GL_CULL_FACE, cur->cull_face); + enable_disable(GL_DEPTH_TEST, cur->depth_test); + enable_disable(GL_DITHER, cur->dither); + enable_disable(GL_FOG, cur->fog); + + for (i = 0; i < hardext.maxlights; i++) { + enable_disable(GL_LIGHT0 + i, *(cur->lights_enabled + i)); + } + + enable_disable(GL_LIGHTING, cur->lighting); + enable_disable(GL_LINE_SMOOTH, cur->line_smooth); + enable_disable(GL_LINE_STIPPLE, cur->line_stipple); + enable_disable(GL_COLOR_LOGIC_OP, cur->color_logic_op); + //TODO: GL_INDEX_LOGIC_OP + //TODO: GL_MAP1_x + //TODO: GL_MAP2_x + enable_disable(GL_MULTISAMPLE, cur->multisample); + enable_disable(GL_NORMALIZE, cur->normalize); + enable_disable(GL_POINT_SMOOTH, cur->point_smooth); + //TODO: GL_POLYGON_OFFSET_LINE + enable_disable(GL_POLYGON_OFFSET_FILL, cur->polygon_offset_fill); + //TODO: GL_POLYGON_OFFSET_POINT + //TODO: GL_POLYGON_SMOOTH + //TODO: GL_POLYGON_STIPPLE + enable_disable(GL_SAMPLE_ALPHA_TO_COVERAGE, cur->sample_alpha_to_coverage); + enable_disable(GL_SAMPLE_ALPHA_TO_ONE, cur->sample_alpha_to_one); + enable_disable(GL_SAMPLE_COVERAGE, cur->sample_coverage); + enable_disable(GL_SCISSOR_TEST, cur->scissor_test); + enable_disable(GL_STENCIL_TEST, cur->stencil_test); + enable_disable(GL_POINT_SPRITE, cur->pointsprite); + int a; + int old_tex = glstate->texture.active; + for (a=0; aenable.texture[a] != cur->tex_enabled[a]) { + for (int j=0; jtex_enabled[a] & (1<enable.texture[a] & (1<texture.active!=a) + gl4es_glActiveTexture(GL_TEXTURE0+a); + enable_disable(to_target(j), t); + } + } + } + glstate->enable.texgen_r[a] = cur->texgen_r[a]; + glstate->enable.texgen_s[a] = cur->texgen_s[a]; + glstate->enable.texgen_t[a] = cur->texgen_t[a]; + glstate->enable.texgen_q[a] = cur->texgen_q[a]; + } + if (glstate->texture.active != old_tex) gl4es_glActiveTexture(GL_TEXTURE0+old_tex); + } + + if (cur->mask & GL_FOG_BIT) { + enable_disable(GL_FOG, cur->fog); + gl4es_glFogfv(GL_FOG_COLOR, cur->fog_color); + gl4es_glFogf(GL_FOG_DENSITY, cur->fog_density); + gl4es_glFogf(GL_FOG_START, cur->fog_start); + gl4es_glFogf(GL_FOG_END, cur->fog_end); + gl4es_glFogf(GL_FOG_MODE, cur->fog_mode); + } + + if (cur->mask & GL_HINT_BIT) { + gl4es_glHint(GL_PERSPECTIVE_CORRECTION_HINT, cur->perspective_hint); + gl4es_glHint(GL_POINT_SMOOTH_HINT, cur->point_smooth_hint); + gl4es_glHint(GL_LINE_SMOOTH_HINT, cur->line_smooth_hint); + gl4es_glHint(GL_FOG_HINT, cur->fog_hint); + gl4es_glHint(GL_GENERATE_MIPMAP_HINT, cur->mipmap_hint); + for (int i=GL4ES_HINT_FIRST; igles4_hint[i-GL4ES_HINT_FIRST]); + } + + if (cur->mask & GL_LIGHTING_BIT) { + enable_disable(GL_LIGHTING, cur->lighting); + gl4es_glLightModelfv(GL_LIGHT_MODEL_AMBIENT, cur->light_model_ambient); + gl4es_glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, cur->light_model_two_side); + + int i; + int j=0; + int old_matrixmode = glstate->matrix_mode; + // Light position / direction is transformed. So load identity in modelview to restore correct stuff + int identity = is_identity(getMVMat()); + if(!identity) { + if(old_matrixmode != GL_MODELVIEW) gl4es_glMatrixMode(GL_MODELVIEW); + gl4es_glPushMatrix(); + gl4es_glLoadIdentity(); + } + for (i = 0; i < hardext.maxlights; i++) { + enable_disable(GL_LIGHT0 + i, *(cur->lights_enabled + i)); + #define L(A) gl4es_glLightfv(GL_LIGHT0 + i, A, cur->lights+j); j+=4 + L(GL_AMBIENT); + L(GL_DIFFUSE); + L(GL_SPECULAR); + L(GL_POSITION); + L(GL_SPOT_CUTOFF); + L(GL_SPOT_DIRECTION); + L(GL_SPOT_EXPONENT); + L(GL_CONSTANT_ATTENUATION); + L(GL_LINEAR_ATTENUATION); + L(GL_QUADRATIC_ATTENUATION); + #undef L + } + if(!identity) { + gl4es_glPopMatrix(); + if(old_matrixmode != GL_MODELVIEW) gl4es_glMatrixMode(old_matrixmode); + } + j=0; + #define M(A) if(memcmp(cur->materials+j, cur->materials+j+4, 4*sizeof(GLfloat))==0) \ + {gl4es_glMaterialfv(GL_FRONT_AND_BACK, A, cur->materials+j); j+=8;} \ + else \ + {gl4es_glMaterialfv(GL_BACK, A, cur->materials+j); j+=4; gl4es_glMaterialfv(GL_FRONT, A, cur->materials+j); j+=4;} + M(GL_AMBIENT); M(GL_DIFFUSE); M(GL_SPECULAR); M(GL_EMISSION); M(GL_SHININESS); // handle both face at some point? + #undef M + + gl4es_glShadeModel(cur->shade_model); + } + + // GL_LIST_BIT + if (cur->mask & GL_LIST_BIT) { + gl4es_glListBase(cur->list_base); + } + + if (cur->mask & GL_LINE_BIT) { + enable_disable(GL_LINE_SMOOTH, cur->line_smooth); + // TODO: stipple stuff here + gl4es_glLineWidth(cur->line_width); + } + + if (cur->mask & GL_MULTISAMPLE_BIT) { + enable_disable(GL_MULTISAMPLE, cur->multisample); + enable_disable(GL_SAMPLE_ALPHA_TO_COVERAGE, cur->sample_alpha_to_coverage); + enable_disable(GL_SAMPLE_ALPHA_TO_ONE, cur->sample_alpha_to_one); + enable_disable(GL_SAMPLE_COVERAGE, cur->sample_coverage); + } + + if (cur->mask & GL_POINT_BIT) { + enable_disable(GL_POINT_SMOOTH, cur->point_smooth); + gl4es_glPointSize(cur->point_size); + if(hardext.pointsprite) { + enable_disable(GL_POINT_SPRITE, cur->pointsprite); + int old_tex = glstate->texture.active; + int a; + for (a=0; atexture.pscoordreplace[a]!=cur->pscoordreplace[a]) { + if(glstate->texture.active!=a) + gl4es_glActiveTexture(GL_TEXTURE0+a); + gl4es_glTexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, cur->pscoordreplace[a]); + } + } + if (glstate->texture.active!= old_tex) gl4es_glActiveTexture(GL_TEXTURE0+old_tex); + } + } + + if (cur->mask & GL_SCISSOR_BIT) { + enable_disable(GL_SCISSOR_TEST, cur->scissor_test); + gl4es_glScissor(v4(cur->scissor_box)); + } + + if (cur->mask & GL_STENCIL_BUFFER_BIT) { + enable_disable(GL_STENCIL_TEST, cur->stencil_test); + gl4es_glStencilFunc(cur->stencil_func, cur->stencil_ref, cur->stencil_mask); + //TODO: Stencil value mask + gl4es_glStencilOp(cur->stencil_sfail, cur->stencil_dpfail, cur->stencil_dppass); + gl4es_glClearStencil(cur->stencil_clearvalue); + //TODO: Stencil buffer writemask + } + + if (cur->mask & GL_TEXTURE_BIT) { + int old_tex = glstate->texture.active; + int a; + //TODO: Enable bit for the 4 texture coordinates + for (a=0; aenable.texgen_r[a] = cur->texgen_r[a]; + glstate->enable.texgen_s[a] = cur->texgen_s[a]; + glstate->enable.texgen_t[a] = cur->texgen_t[a]; + glstate->enable.texgen_q[a] = cur->texgen_q[a]; + glstate->texgen[a] = cur->texgen[a]; // all mode and planes per texture in 1 line + for (int j=0; jtexture[a][j] != glstate->texture.bound[a][j]->texture) { + if(glstate->texture.active!=a) + gl4es_glActiveTexture(GL_TEXTURE0+a); + gl4es_glBindTexture(to_target(j), cur->texture[a][j]); + } + } + if (glstate->texture.active!= old_tex) gl4es_glActiveTexture(GL_TEXTURE0+old_tex); + } + + if (cur->mask & GL_PIXEL_MODE_BIT) { + GLenum pixel_name[] = {GL_RED_BIAS, GL_RED_SCALE, GL_GREEN_BIAS, GL_GREEN_SCALE, GL_BLUE_BIAS, GL_BLUE_SCALE, GL_ALPHA_BIAS, GL_ALPHA_SCALE}; + int i; + for (i=0; i<8; i++) + gl4es_glPixelTransferf(pixel_name[i], cur->pixel_scale_bias[i]); + //TODO: GL_DEPTH_BIAS & GL_DEPTH_SCALE (probably difficult) + //TODO: GL_INDEX_OFFEST & GL_INDEX_SHIFT + //TODO: GL_MAP_COLOR & GL_MAP_STENCIL (probably difficult too) + gl4es_glPixelZoom(cur->pixel_zoomx, cur->pixel_zoomy); + } + + if (cur->mask & GL_TRANSFORM_BIT) { + if (!(cur->mask & GL_ENABLE_BIT)) { + int i; + for (i = 0; i < hardext.maxplanes; i++) { + enable_disable(GL_CLIP_PLANE0 + i, *(cur->clip_planes_enabled + i)); + } + } + gl4es_glMatrixMode(cur->matrix_mode); + enable_disable(GL_NORMALIZE, cur->normalize_flag); + enable_disable(GL_RESCALE_NORMAL, cur->rescale_normal_flag); + } + + if (cur->mask & GL_VIEWPORT_BIT) { + gl4es_glViewport(cur->viewport_size[0], cur->viewport_size[1], cur->viewport_size[2], cur->viewport_size[3]); + gl4es_glDepthRangef(cur->depth_range[0], cur->depth_range[1]); + } + + maybe_free(cur->clip_planes_enabled); + maybe_free(cur->clip_planes); + maybe_free(cur->lights_enabled); + maybe_free(cur->lights); + maybe_free(cur->materials); + glstate->stack->len--; +} + +#undef enable_disable +#define enable_disable(pname, enabled) \ + if (enabled) gl4es_glEnableClientState(pname); \ + else gl4es_glDisableClientState(pname) + +void gl4es_glPopClientAttrib() { + noerrorShim(); + if (glstate->list.pending) { + flush(); + } + //LOAD_GLES(glVertexPointer); + //LOAD_GLES(glColorPointer); + //LOAD_GLES(glNormalPointer); + //LOAD_GLES(glTexCoordPointer); + + if (glstate->clientStack == NULL || glstate->clientStack->len == 0) { + errorShim(GL_STACK_UNDERFLOW); + return; + } + + glclientstack_t *cur = glstate->clientStack + glstate->clientStack->len-1; + if (cur->mask & GL_CLIENT_PIXEL_STORE_BIT) { + gl4es_glPixelStorei(GL_PACK_ALIGNMENT, cur->pack_align); + gl4es_glPixelStorei(GL_UNPACK_ALIGNMENT, cur->unpack_align); + gl4es_glPixelStorei(GL_UNPACK_ROW_LENGTH, cur->unpack_row_length); + gl4es_glPixelStorei(GL_UNPACK_SKIP_PIXELS, cur->unpack_skip_pixels); + gl4es_glPixelStorei(GL_UNPACK_SKIP_ROWS, cur->unpack_skip_rows); + gl4es_glPixelStorei(GL_PACK_ROW_LENGTH, cur->pack_row_length); + gl4es_glPixelStorei(GL_PACK_SKIP_PIXELS, cur->pack_skip_pixels); + gl4es_glPixelStorei(GL_PACK_SKIP_ROWS, cur->pack_skip_rows); + } + + if (cur->mask & GL_CLIENT_VERTEX_ARRAY_BIT) { + if (glstate->vao->pointers[ATT_VERTEX].enabled != cur->vert_enable) + enable_disable(GL_VERTEX_ARRAY, cur->vert_enable); + if (glstate->vao->pointers[ATT_NORMAL].enabled != cur->normal_enable) + enable_disable(GL_NORMAL_ARRAY, cur->normal_enable); + if (glstate->vao->pointers[ATT_COLOR].enabled != cur->color_enable) + enable_disable(GL_COLOR_ARRAY, cur->color_enable); + if (glstate->vao->pointers[ATT_SECONDARY].enabled != cur->secondary_enable) + enable_disable(GL_SECONDARY_COLOR_ARRAY, cur->secondary_enable); + if (glstate->vao->pointers[ATT_FOGCOORD].enabled != cur->fog_enable) + enable_disable(GL_COLOR_ARRAY, cur->fog_enable); + for (int a=0; avao->pointers[ATT_MULTITEXCOORD0+a].enabled != cur->tex_enable[a]) { + gl4es_glClientActiveTexture(GL_TEXTURE0+a); + enable_disable(GL_TEXTURE_COORD_ARRAY, cur->tex_enable[a]); + } + } + + memcpy(&glstate->vao->pointers, &(cur->pointers), sizeof(glstate->vao->pointers)); + if (glstate->texture.client != cur->client) gl4es_glClientActiveTexture(GL_TEXTURE0+cur->client); + } + + glstate->clientStack->len--; +} + +#undef maybe_free +#undef enable_disable +#undef v2 +#undef v3 +#undef v4 + +//Direct wrapper +void glPushClientAttrib(GLbitfield mask) AliasExport("gl4es_glPushClientAttrib"); +void glPopClientAttrib() AliasExport("gl4es_glPopClientAttrib"); +void glPushAttrib(GLbitfield mask) AliasExport("gl4es_glPushAttrib"); +void glPopAttrib() AliasExport("gl4es_glPopAttrib"); \ No newline at end of file diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/stack.h b/Projects/Android/jni/SupportLibs/gl4es/src/gl/stack.h new file mode 100644 index 0000000..f876175 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/stack.h @@ -0,0 +1,184 @@ +#ifndef _GL4ES_STACK_H_ +#define _GL4ES_STACK_H_ + +#include "gles.h" +#include "state.h" +#include "texture.h" +#include + +#define STACK_SIZE 16 + +#define GL4ES_HINT_FIRST GL_SHRINK_HINT_GL4ES +#define GL4ES_HINT_LAST (GL_NOERROR_HINT_GL4ES + 1) + + +typedef struct _glstack_t { + GLbitfield mask; + + // GL_COLOR_BUFFER_BIT + GLboolean alpha_test; + GLint alpha_test_func; + GLclampf alpha_test_ref; + + GLboolean blend; + GLint blend_src_func; + GLint blend_dst_func; + + GLboolean dither; + + // point sprite + GLboolean pointsprite; + GLint pscoordreplace[MAX_TEX]; + + GLboolean color_logic_op; + GLint logic_op; + + GLfloat clear_color[4]; + GLfloat color_mask[4]; + + // GL_CURRENT_BIT + GLfloat color[4]; + GLfloat normal[4]; + GLfloat tex[4]; + GLfloat secondary[4]; + + // TODO: can only fill this via raster.c + GLfloat raster_pos[3]; + GLboolean raster_valid; + GLfloat pixel_scale_bias[4+4]; + GLfloat pixel_zoomx; + GLfloat pixel_zoomy; + + // GL_DEPTH_BUFFER_BIT + GLboolean depth_test; + GLint depth_func; + GLfloat clear_depth; + GLint depth_mask; + + // GL_ENABLE_BIT + GLboolean cull_face; + GLboolean normalize; + GLboolean polygon_offset_fill; + GLboolean stencil_test; + GLuint tex_enabled[MAX_TEX]; + GLboolean texgen_s[MAX_TEX]; + GLboolean texgen_r[MAX_TEX]; + GLboolean texgen_t[MAX_TEX]; + GLboolean texgen_q[MAX_TEX]; + GLboolean colormaterial; + GLboolean autonormal; + + // GL_FOG_BIT + GLboolean fog; + GLfloat fog_color[4]; + GLfloat fog_density; + GLfloat fog_start; + GLfloat fog_end; + GLint fog_mode; + + // GL_HINT_BIT + GLint perspective_hint; + GLint point_smooth_hint; + GLint line_smooth_hint; + GLint fog_hint; + GLint mipmap_hint; + GLint gles4_hint[GL4ES_HINT_LAST-GL4ES_HINT_FIRST]; + + // GL_LIGHTING_BIT + GLboolean lighting; + GLboolean *lights_enabled; + GLfloat *lights; + GLfloat light_model_ambient[4]; + GLint light_model_two_side; + GLfloat *materials; + GLint shade_model; + + // GL_LINE_BIT + GLboolean line_smooth; + GLboolean line_stipple; // TODO: needs to be hooked locally? + GLfloat line_width; + + // GL_LIST_BIT + GLint list_base; + + // GL_MULTISAMPLE_BIT + GLboolean multisample; + GLboolean sample_alpha_to_coverage; + GLboolean sample_alpha_to_one; + GLboolean sample_coverage; + + // GL_POINT_BIT + GLboolean point_smooth; + GLfloat point_size; + + // TODO: GL_POLYGON_BIT + // TODO: GL_POLYGON_STIPPLE_BIT + + // GL_SCISSOR_BIT + GLboolean scissor_test; + GLfloat scissor_box[4]; + + // GL_STENCIL_BUFFER_BIT + GLenum stencil_func; + GLint stencil_ref; + GLuint stencil_mask; + GLint stencil_clearvalue; + GLenum stencil_sfail; + GLenum stencil_dpfail; + GLenum stencil_dppass; + + // GL_TEXTURE_BIT + GLint texture[MAX_TEX][ENABLED_TEXTURE_LAST]; + texgen_state_t texgen[MAX_TEX]; + GLint active; + + // GL_TRANSFORM_BIT + // with Clip Planes... + GLenum matrix_mode; + GLboolean normalize_flag; + GLboolean rescale_normal_flag; + // GL_VIEWPORT_BIT + GLint viewport_size[4]; + GLfloat depth_range[2]; + + // dynamically-sized shenanigans + GLboolean *clip_planes_enabled; + GLfloat *clip_planes; + + // misc + unsigned int len; + unsigned int cap; +} glstack_t; + +typedef struct _glclientstack_t { + GLbitfield mask; + + // GL_CLIENT_PIXEL_STORE_BIT + GLint pack_align; + GLint unpack_align; + GLuint unpack_row_length; + GLuint unpack_skip_pixels; + GLuint unpack_skip_rows; + GLuint pack_row_length; + GLuint pack_skip_pixels; + GLuint pack_skip_rows; + + // GL_CLIENT_VERTEX_ARRAY_BIT + GLuint client; + GLboolean vert_enable; + GLboolean color_enable; + GLboolean tex_enable[MAX_TEX]; + GLboolean normal_enable; + GLboolean secondary_enable; + GLboolean fog_enable; + pointer_state_t pointers[NB_VA]; + unsigned int len; + unsigned int cap; +} glclientstack_t; + +void gl4es_glPushClientAttrib(GLbitfield mask); +void gl4es_glPopClientAttrib(); +void gl4es_glPushAttrib(GLbitfield mask); +void gl4es_glPopAttrib(); + +#endif // _GL4ES_STACK_H_ diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/state.h b/Projects/Android/jni/SupportLibs/gl4es/src/gl/state.h new file mode 100644 index 0000000..c06f69e --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/state.h @@ -0,0 +1,346 @@ +#ifndef _GL4ES_STATE_H_ +#define _GL4ES_STATE_H_ + +#include "khash.h" +#include "buffers.h" +#include "eval.h" +#include "gles.h" +#include "list.h" +#include "program.h" +#include "raster.h" +#include "shader.h" +#include "texenv.h" +#include "texture.h" + +typedef struct { + GLboolean line_stipple, + auto_normal, + normalize, + normal_rescale, + lighting, + alpha_test, + fog, + color_material, + blend, + cull_face, + color_sum, + depth_test, + stencil_test, + pointsprite, + texgen_s[MAX_TEX], + texgen_t[MAX_TEX], + texgen_r[MAX_TEX], + texgen_q[MAX_TEX], + plane[MAX_CLIP_PLANES], + light[MAX_LIGHT], + map1_color4, + map1_index, + map1_normal, + map1_texture1, + map1_texture2, + map1_texture3, + map1_texture4, + map1_vertex3, + map1_vertex4, + map2_color4, + map2_index, + map2_normal, + map2_texture1, + map2_texture2, + map2_texture3, + map2_texture4, + map2_vertex3, + map2_vertex4, + color_logic_op, + line_smooth, + point_smooth, + polyfill_offset, + multisample, + sample_coverage, + sample_alpha_to_one, + sample_alpha_to_coverage; + GLuint texture[MAX_TEX]; // flag +} enable_state_t; + +typedef struct { + GLenum S; + GLenum T; + GLenum R; + GLenum Q; + GLfloat S_E[4]; // Eye Plane + GLfloat T_E[4]; + GLfloat R_E[4]; + GLfloat Q_E[4]; + GLfloat S_O[4]; // Object Plane + GLfloat T_O[4]; + GLfloat R_O[4]; + GLfloat Q_O[4]; +} texgen_state_t; + +typedef struct { + texenv_t env; + texfilter_t filter; +} texenv_state_t; + +typedef struct { + GLuint unpack_row_length, + unpack_skip_pixels, + unpack_skip_rows, + unpack_image_height; + GLboolean unpack_lsb_first; + // TODO: use those values + GLuint pack_row_length, + pack_skip_pixels, + pack_skip_rows, + pack_image_height; + GLuint pack_align, + unpack_align; + GLboolean pack_lsb_first; + gltexture_t *bound[MAX_TEX][ENABLED_TEXTURE_LAST]; //TODO: this should be shared + gltexture_t *zero; // this is texture 0... + GLboolean pscoordreplace[MAX_TEX]; + khash_t(tex) *list; // this is shared amoung glstate + GLuint active; // active texture + GLuint client; // client active texture +} texture_state_t; + +typedef struct { + renderlist_t *active; + GLboolean compiling; + GLboolean pending; + GLboolean begin; + GLuint base; + GLuint name; + GLenum mode; + + GLuint count; + GLuint cap; +} displaylist_state_t; + +typedef struct { + rasterpos_t rPos; + viewport_t viewport; + GLfloat raster_scale[4]; + GLfloat raster_bias[4]; + GLfloat raster_zoomx; + GLfloat raster_zoomy; + GLint index_shift; + GLint index_offset; + int map_color; + int map_i2i_size; + int map_i2r_size; + int map_i2g_size; + int map_i2b_size; + int map_i2a_size; + /* + int map_s2s_size; + int map_r2r_size; + int map_g2g_size; + int map_b2b_size; + int map_a2a_size; + */ + GLuint map_i2i[MAX_MAP_SIZE]; + GLubyte map_i2r[MAX_MAP_SIZE]; + GLubyte map_i2g[MAX_MAP_SIZE]; + GLubyte map_i2b[MAX_MAP_SIZE]; + GLubyte map_i2a[MAX_MAP_SIZE]; + /* + GLuint map_s2s[MAX_MAP_SIZE]; + GLubyte map_r2r[MAX_MAP_SIZE]; + GLubyte map_g2g[MAX_MAP_SIZE]; + GLubyte map_b2b[MAX_MAP_SIZE]; + GLubyte map_a2a[MAX_MAP_SIZE]; + */ + GLubyte *data; + rasterlist_t immediate; + GLsizei raster_width; + GLsizei raster_height; + GLsizei raster_nwidth; + GLsizei raster_nheight; + GLint raster_x1, raster_x2, raster_y1, raster_y2; + // bitmap specific datas + int bm_drawing; // flag if some bitmap are there + int bm_x1, bm_y1; + int bm_x2, bm_y2; + GLubyte *bitmap; + GLsizei bm_alloc; + GLsizei bm_width, bm_height; + GLuint bm_texture; + int bm_tnwidth, bm_tnheight; + +} raster_state_t; + + +typedef struct { + map_state_t *vertex3, + *vertex4, + *index, + *color4, + *normal, + *texture1, + *texture2, + *texture3, + *texture4; +} map_states_t; + +typedef struct { + int top; + GLuint *names; +} namestack_t; + +typedef struct { + GLuint count; + GLuint *buffer; + GLuint size; + GLfloat zmin; + GLfloat zmax; + GLfloat zminoverall; + GLfloat zmaxoverall; + GLuint overflow; + GLuint pos; + GLboolean hit; +} selectbuf_t; + +typedef struct { + int top; + int identity; + GLfloat *stack; +} matrixstack_t; + +typedef struct { + khash_t(shaderlist) *shaders; + khash_t(programlist) *programs; + GLuint program; + program_t *glprogram; + int es2; // context is es2 +} glsl_t; + +typedef struct { + GLuint program; + program_t *glprogram; + GLuint active; // active texture (is it shared?) +} gleshard_s_t; + +typedef struct { + vertexattrib_t vertexattrib[MAX_VATTRIB]; + vertexattrib_t wanted[MAX_VATTRIB]; +} gleshard_ns_t; + +typedef struct { + GLuint vertexshader; + GLuint pixelshader; + GLuint vertexshader_alpha; + GLuint pixelshader_alpha; + GLuint program; + GLuint program_alpha; + GLfloat vert[8], tex[8]; +} glesblit_t; + +typedef struct { + GLboolean secondary_array, + color_array, + normal_array, + vertex_array, + fog_array, + tex_coord_array[MAX_TEX]; + + pointer_state_t vert; + pointer_state_t normal; + pointer_state_t color; + pointer_state_t secondary; + pointer_state_t fog; + pointer_state_t tex[MAX_TEX]; + + char* shadersource; // scrach buffer for fpe shader construction + int shadersize; +} fpestatus_t; + +typedef struct { + GLint factor; + GLushort pattern; + GLubyte *data; + GLuint texture; +} linestipple_t; + +// FBO structures +typedef struct { + GLuint renderbuffer; + GLenum attachment; // can be color0 or depth_stencil for example + GLuint secondarybuffer; // secondary renderbuffer, if depth_stencil is not possible for example + GLuint secondarytexture; // the texture, in case of a color0 attachement... + GLenum format; // requested format + GLenum actual; // actual formal + int width; + int height; +} glrenderbuffer_t; + +KHASH_MAP_DECLARE_INT(renderbufferlist_t, glrenderbuffer_t *); + +typedef struct { + GLuint id; + GLenum target; + GLuint color[10]; // attachement_color0..9 + GLuint depth; + GLuint stencil; + GLuint t_color[10]; // type for attachement_0 (GL_NONE, GL_TEXTUREXX, GL_RENDERBUFFER) + GLuint t_depth; + GLuint t_stencil; + int l_color[10]; // level of attachment + int l_depth; + int l_stencil; + int width; + int height; + GLenum read_format; + GLenum read_type; + int n_draw; + GLenum drawbuff[16]; //TODO: define a MAX_DRAWBUFF? +} glframebuffer_t; + +typedef struct { + GLuint *fbos; + int nbr; + int cap; +} oldfbos_t; + +KHASH_MAP_DECLARE_INT(framebufferlist_t, glframebuffer_t *); + +typedef struct { + khash_t(renderbufferlist_t) *renderbufferlist; + glrenderbuffer_t *default_rb; + glrenderbuffer_t *current_rb; + + GLuint mainfbo_fbo; // The MainFBO + GLuint mainfbo_tex; // Texture Attachment + GLuint mainfbo_dep; // Depth attachment + GLuint mainfbo_ste; // Stencil attachement + int mainfbo_width; + int mainfbo_height; + int mainfbo_nwidth; + int mainfbo_nheight; + + khash_t(framebufferlist_t) *framebufferlist; + glframebuffer_t *fbo_0; + glframebuffer_t *fbo_read; + glframebuffer_t *fbo_draw; + glframebuffer_t *current_fb; + + GLenum fb_status; + int internal; + + oldfbos_t *old; +} fbo_t; + +typedef struct { + GLenum func; + GLboolean mask; + GLfloat near, far; + GLfloat clear; +} depth_state_t; + +typedef struct { + GLenum cull; + GLenum front; +} face_state_t; + + +#endif // _GL4ES_STATE_H_ diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/stb_dxt_104.h b/Projects/Android/jni/SupportLibs/gl4es/src/gl/stb_dxt_104.h new file mode 100644 index 0000000..bec7279 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/stb_dxt_104.h @@ -0,0 +1,624 @@ +// stb_dxt.h - v1.04 - DXT1/DXT5 compressor - public domain +// original by fabian "ryg" giesen - ported to C by stb +// use '#define STB_DXT_IMPLEMENTATION' before including to create the implementation +// +// USAGE: +// call stb_compress_dxt_block() for every block (you must pad) +// source should be a 4x4 block of RGBA data in row-major order; +// A is ignored if you specify alpha=0; you can turn on dithering +// and "high quality" using mode. +// +// version history: +// v1.04 - (ryg) default to no rounding bias for lerped colors (as per S3TC/DX10 spec); +// single color match fix (allow for inexact color interpolation); +// optimal DXT5 index finder; "high quality" mode that runs multiple refinement steps. +// v1.03 - (stb) endianness support +// v1.02 - (stb) fix alpha encoding bug +// v1.01 - (stb) fix bug converting to RGB that messed up quality, thanks ryg & cbloom +// v1.00 - (stb) first release + +#ifndef STB_INCLUDE_STB_DXT_H +#define STB_INCLUDE_STB_DXT_H + +// compression mode (bitflags) +#define STB_DXT_NORMAL 0 +#define STB_DXT_DITHER 1 // use dithering. dubious win. never use for normal maps and the like! +#define STB_DXT_HIGHQUAL 2 // high quality mode, does two refinement steps instead of 1. ~30-40% slower. + +void stb_compress_dxt_block(unsigned char *dest, const unsigned char *src, int alpha, int mode); +#define STB_COMPRESS_DXT_BLOCK + +#ifdef STB_DXT_IMPLEMENTATION + +// configuration options for DXT encoder. set them in the project/makefile or just define +// them at the top. + +// STB_DXT_USE_ROUNDING_BIAS +// use a rounding bias during color interpolation. this is closer to what "ideal" +// interpolation would do but doesn't match the S3TC/DX10 spec. old versions (pre-1.03) +// implicitly had this turned on. +// +// in case you're targeting a specific type of hardware (e.g. console programmers): +// NVidia and Intel GPUs (as of 2010) as well as DX9 ref use DXT decoders that are closer +// to STB_DXT_USE_ROUNDING_BIAS. AMD/ATI, S3 and DX10 ref are closer to rounding with no bias. +// you also see "(a*5 + b*3) / 8" on some old GPU designs. +// #define STB_DXT_USE_ROUNDING_BIAS + +#include +#include +#include // memset + +static unsigned char stb__Expand5[32]; +static unsigned char stb__Expand6[64]; +static unsigned char stb__OMatch5[256][2]; +static unsigned char stb__OMatch6[256][2]; +static unsigned char stb__QuantRBTab[256+16]; +static unsigned char stb__QuantGTab[256+16]; + +static int stb__Mul8Bit(int a, int b) +{ + int t = a*b + 128; + return (t + (t >> 8)) >> 8; +} + +static void stb__From16Bit(unsigned char *out, unsigned short v) +{ + int rv = (v & 0xf800) >> 11; + int gv = (v & 0x07e0) >> 5; + int bv = (v & 0x001f) >> 0; + + out[0] = stb__Expand5[rv]; + out[1] = stb__Expand6[gv]; + out[2] = stb__Expand5[bv]; + out[3] = 0; +} + +static unsigned short stb__As16Bit(int r, int g, int b) +{ + return (stb__Mul8Bit(r,31) << 11) + (stb__Mul8Bit(g,63) << 5) + stb__Mul8Bit(b,31); +} + +// linear interpolation at 1/3 point between a and b, using desired rounding type +static int stb__Lerp13(int a, int b) +{ +#ifdef STB_DXT_USE_ROUNDING_BIAS + // with rounding bias + return a + stb__Mul8Bit(b-a, 0x55); +#else + // without rounding bias + // replace "/ 3" by "* 0xaaab) >> 17" if your compiler sucks or you really need every ounce of speed. + return (2*a + b) / 3; +#endif +} + +// lerp RGB color +static void stb__Lerp13RGB(unsigned char *out, unsigned char *p1, unsigned char *p2) +{ + out[0] = stb__Lerp13(p1[0], p2[0]); + out[1] = stb__Lerp13(p1[1], p2[1]); + out[2] = stb__Lerp13(p1[2], p2[2]); +} + +/****************************************************************************/ + +// compute table to reproduce constant colors as accurately as possible +static void stb__PrepareOptTable(unsigned char *Table,const unsigned char *expand,int size) +{ + int i,mn,mx; + for (i=0;i<256;i++) { + int bestErr = 256; + for (mn=0;mn> 4)]; + ep1[0] = bp[ 0] - dp[ 0]; + dp[ 4] = quant[bp[ 4] + ((7*ep1[0] + 3*ep2[2] + 5*ep2[1] + ep2[0]) >> 4)]; + ep1[1] = bp[ 4] - dp[ 4]; + dp[ 8] = quant[bp[ 8] + ((7*ep1[1] + 3*ep2[3] + 5*ep2[2] + ep2[1]) >> 4)]; + ep1[2] = bp[ 8] - dp[ 8]; + dp[12] = quant[bp[12] + ((7*ep1[2] + 5*ep2[3] + ep2[2]) >> 4)]; + ep1[3] = bp[12] - dp[12]; + bp += 16; + dp += 16; + et = ep1, ep1 = ep2, ep2 = et; // swap + } + } +} + +// The color matching function +static unsigned int stb__MatchColorsBlock(unsigned char *block, unsigned char *color,int dither) +{ + unsigned int mask = 0; + int dirr = color[0*4+0] - color[1*4+0]; + int dirg = color[0*4+1] - color[1*4+1]; + int dirb = color[0*4+2] - color[1*4+2]; + int dots[16]; + int stops[4]; + int i; + int c0Point, halfPoint, c3Point; + + for(i=0;i<16;i++) + dots[i] = block[i*4+0]*dirr + block[i*4+1]*dirg + block[i*4+2]*dirb; + + for(i=0;i<4;i++) + stops[i] = color[i*4+0]*dirr + color[i*4+1]*dirg + color[i*4+2]*dirb; + + // think of the colors as arranged on a line; project point onto that line, then choose + // next color out of available ones. we compute the crossover points for "best color in top + // half"/"best in bottom half" and then the same inside that subinterval. + // + // relying on this 1d approximation isn't always optimal in terms of euclidean distance, + // but it's very close and a lot faster. + // http://cbloomrants.blogspot.com/2008/12/12-08-08-dxtc-summary.html + + c0Point = (stops[1] + stops[3]) >> 1; + halfPoint = (stops[3] + stops[2]) >> 1; + c3Point = (stops[2] + stops[0]) >> 1; + + if(!dither) { + // the version without dithering is straightforward + for (i=15;i>=0;i--) { + int dot = dots[i]; + mask <<= 2; + + if(dot < halfPoint) + mask |= (dot < c0Point) ? 1 : 3; + else + mask |= (dot < c3Point) ? 2 : 0; + } + } else { + // with floyd-steinberg dithering + int err[8],*ep1 = err,*ep2 = err+4; + int *dp = dots, y; + + c0Point <<= 4; + halfPoint <<= 4; + c3Point <<= 4; + for(i=0;i<8;i++) + err[i] = 0; + + for(y=0;y<4;y++) + { + int dot,lmask,step; + + dot = (dp[0] << 4) + (3*ep2[1] + 5*ep2[0]); + if(dot < halfPoint) + step = (dot < c0Point) ? 1 : 3; + else + step = (dot < c3Point) ? 2 : 0; + ep1[0] = dp[0] - stops[step]; + lmask = step; + + dot = (dp[1] << 4) + (7*ep1[0] + 3*ep2[2] + 5*ep2[1] + ep2[0]); + if(dot < halfPoint) + step = (dot < c0Point) ? 1 : 3; + else + step = (dot < c3Point) ? 2 : 0; + ep1[1] = dp[1] - stops[step]; + lmask |= step<<2; + + dot = (dp[2] << 4) + (7*ep1[1] + 3*ep2[3] + 5*ep2[2] + ep2[1]); + if(dot < halfPoint) + step = (dot < c0Point) ? 1 : 3; + else + step = (dot < c3Point) ? 2 : 0; + ep1[2] = dp[2] - stops[step]; + lmask |= step<<4; + + dot = (dp[3] << 4) + (7*ep1[2] + 5*ep2[3] + ep2[2]); + if(dot < halfPoint) + step = (dot < c0Point) ? 1 : 3; + else + step = (dot < c3Point) ? 2 : 0; + ep1[3] = dp[3] - stops[step]; + lmask |= step<<6; + + dp += 4; + mask |= lmask << (y*8); + { int *et = ep1; ep1 = ep2; ep2 = et; } // swap + } + } + + return mask; +} + +// The color optimization function. (Clever code, part 1) +static void stb__OptimizeColorsBlock(unsigned char *block, unsigned short *pmax16, unsigned short *pmin16) +{ + int mind = 0x7fffffff,maxd = -0x7fffffff; + unsigned char *minp, *maxp; + double magn; + int v_r,v_g,v_b; + static const int nIterPower = 4; + float covf[6],vfr,vfg,vfb; + + // determine color distribution + int cov[6]; + int mu[3],min[3],max[3]; + int ch,i,iter; + + for(ch=0;ch<3;ch++) + { + const unsigned char *bp = ((const unsigned char *) block) + ch; + int muv,minv,maxv; + + muv = minv = maxv = bp[0]; + for(i=4;i<64;i+=4) + { + muv += bp[i]; + if (bp[i] < minv) minv = bp[i]; + else if (bp[i] > maxv) maxv = bp[i]; + } + + mu[ch] = (muv + 8) >> 4; + min[ch] = minv; + max[ch] = maxv; + } + + // determine covariance matrix + for (i=0;i<6;i++) + cov[i] = 0; + + for (i=0;i<16;i++) + { + int r = block[i*4+0] - mu[0]; + int g = block[i*4+1] - mu[1]; + int b = block[i*4+2] - mu[2]; + + cov[0] += r*r; + cov[1] += r*g; + cov[2] += r*b; + cov[3] += g*g; + cov[4] += g*b; + cov[5] += b*b; + } + + // convert covariance matrix to float, find principal axis via power iter + for(i=0;i<6;i++) + covf[i] = cov[i] / 255.0f; + + vfr = (float) (max[0] - min[0]); + vfg = (float) (max[1] - min[1]); + vfb = (float) (max[2] - min[2]); + + for(iter=0;iter magn) magn = fabs(vfg); + if (fabs(vfb) > magn) magn = fabs(vfb); + + if(magn < 4.0f) { // too small, default to luminance + v_r = 299; // JPEG YCbCr luma coefs, scaled by 1000. + v_g = 587; + v_b = 114; + } else { + magn = 512.0 / magn; + v_r = (int) (vfr * magn); + v_g = (int) (vfg * magn); + v_b = (int) (vfb * magn); + } + + // Pick colors at extreme points + for(i=0;i<16;i++) + { + int dot = block[i*4+0]*v_r + block[i*4+1]*v_g + block[i*4+2]*v_b; + + if (dot < mind) { + mind = dot; + minp = block+i*4; + } + + if (dot > maxd) { + maxd = dot; + maxp = block+i*4; + } + } + + *pmax16 = stb__As16Bit(maxp[0],maxp[1],maxp[2]); + *pmin16 = stb__As16Bit(minp[0],minp[1],minp[2]); +} + +static int stb__sclamp(float y, int p0, int p1) +{ + int x = (int) y; + if (x < p0) return p0; + if (x > p1) return p1; + return x; +} + +// The refinement function. (Clever code, part 2) +// Tries to optimize colors to suit block contents better. +// (By solving a least squares system via normal equations+Cramer's rule) +static int stb__RefineBlock(unsigned char *block, unsigned short *pmax16, unsigned short *pmin16, unsigned int mask) +{ + static const int w1Tab[4] = { 3,0,2,1 }; + static const int prods[4] = { 0x090000,0x000900,0x040102,0x010402 }; + // ^some magic to save a lot of multiplies in the accumulating loop... + // (precomputed products of weights for least squares system, accumulated inside one 32-bit register) + + float frb,fg; + unsigned short oldMin, oldMax, min16, max16; + int i, akku = 0, xx,xy,yy; + int At1_r,At1_g,At1_b; + int At2_r,At2_g,At2_b; + unsigned int cm = mask; + + oldMin = *pmin16; + oldMax = *pmax16; + + if((mask ^ (mask<<2)) < 4) // all pixels have the same index? + { + // yes, linear system would be singular; solve using optimal + // single-color match on average color + int r = 8, g = 8, b = 8; + for (i=0;i<16;++i) { + r += block[i*4+0]; + g += block[i*4+1]; + b += block[i*4+2]; + } + + r >>= 4; g >>= 4; b >>= 4; + + max16 = (stb__OMatch5[r][0]<<11) | (stb__OMatch6[g][0]<<5) | stb__OMatch5[b][0]; + min16 = (stb__OMatch5[r][1]<<11) | (stb__OMatch6[g][1]<<5) | stb__OMatch5[b][1]; + } else { + At1_r = At1_g = At1_b = 0; + At2_r = At2_g = At2_b = 0; + for (i=0;i<16;++i,cm>>=2) { + int step = cm&3; + int w1 = w1Tab[step]; + int r = block[i*4+0]; + int g = block[i*4+1]; + int b = block[i*4+2]; + + akku += prods[step]; + At1_r += w1*r; + At1_g += w1*g; + At1_b += w1*b; + At2_r += r; + At2_g += g; + At2_b += b; + } + + At2_r = 3*At2_r - At1_r; + At2_g = 3*At2_g - At1_g; + At2_b = 3*At2_b - At1_b; + + // extract solutions and decide solvability + xx = akku >> 16; + yy = (akku >> 8) & 0xff; + xy = (akku >> 0) & 0xff; + + frb = 3.0f * 31.0f / 255.0f / (xx*yy - xy*xy); + fg = frb * 63.0f / 31.0f; + + // solve. + max16 = stb__sclamp((At1_r*yy - At2_r*xy)*frb+0.5f,0,31) << 11; + max16 |= stb__sclamp((At1_g*yy - At2_g*xy)*fg +0.5f,0,63) << 5; + max16 |= stb__sclamp((At1_b*yy - At2_b*xy)*frb+0.5f,0,31) << 0; + + min16 = stb__sclamp((At2_r*xx - At1_r*xy)*frb+0.5f,0,31) << 11; + min16 |= stb__sclamp((At2_g*xx - At1_g*xy)*fg +0.5f,0,63) << 5; + min16 |= stb__sclamp((At2_b*xx - At1_b*xy)*frb+0.5f,0,31) << 0; + } + + *pmin16 = min16; + *pmax16 = max16; + return oldMin != min16 || oldMax != max16; +} + +// Color block compression +static void stb__CompressColorBlock(unsigned char *dest, unsigned char *block, int mode) +{ + unsigned int mask; + int i; + int dither; + int refinecount; + unsigned short max16, min16; + unsigned char dblock[16*4],color[4*4]; + + dither = mode & STB_DXT_DITHER; + refinecount = (mode & STB_DXT_HIGHQUAL) ? 2 : 1; + + // check if block is constant + for (i=1;i<16;i++) + if (((unsigned int *) block)[i] != ((unsigned int *) block)[0]) + break; + + if(i == 16) { // constant color + int r = block[0], g = block[1], b = block[2]; + mask = 0xaaaaaaaa; + max16 = (stb__OMatch5[r][0]<<11) | (stb__OMatch6[g][0]<<5) | stb__OMatch5[b][0]; + min16 = (stb__OMatch5[r][1]<<11) | (stb__OMatch6[g][1]<<5) | stb__OMatch5[b][1]; + } else { + // first step: compute dithered version for PCA if desired + if(dither) + stb__DitherBlock(dblock,block); + + // second step: pca+map along principal axis + stb__OptimizeColorsBlock(dither ? dblock : block,&max16,&min16); + if (max16 != min16) { + stb__EvalColors(color,max16,min16); + mask = stb__MatchColorsBlock(block,color,dither); + } else + mask = 0; + + // third step: refine (multiple times if requested) + for (i=0;i> 8); + dest[2] = (unsigned char) (min16); + dest[3] = (unsigned char) (min16 >> 8); + dest[4] = (unsigned char) (mask); + dest[5] = (unsigned char) (mask >> 8); + dest[6] = (unsigned char) (mask >> 16); + dest[7] = (unsigned char) (mask >> 24); +} + +// Alpha block compression (this is easy for a change) +static void stb__CompressAlphaBlock(unsigned char *dest,unsigned char *src,int mode) +{ + int i,dist,bias,dist4,dist2,bits,mask; + + // find min/max color + int mn,mx; + mn = mx = src[3]; + + for (i=1;i<16;i++) + { + if (src[i*4+3] < mn) mn = src[i*4+3]; + else if (src[i*4+3] > mx) mx = src[i*4+3]; + } + + // encode them + ((unsigned char *)dest)[0] = mx; + ((unsigned char *)dest)[1] = mn; + dest += 2; + + // determine bias and emit color indices + // given the choice of mx/mn, these indices are optimal: + // http://fgiesen.wordpress.com/2009/12/15/dxt5-alpha-block-index-determination/ + dist = mx-mn; + dist4 = dist*4; + dist2 = dist*2; + bias = (dist < 8) ? (dist - 1) : (dist/2 + 2); + bias -= mn * 7; + bits = 0,mask=0; + + for (i=0;i<16;i++) { + int a = src[i*4+3]*7 + bias; + int ind,t; + + // select index. this is a "linear scale" lerp factor between 0 (val=min) and 7 (val=max). + t = (a >= dist4) ? -1 : 0; ind = t & 4; a -= dist4 & t; + t = (a >= dist2) ? -1 : 0; ind += t & 2; a -= dist2 & t; + ind += (a >= dist); + + // turn linear scale into DXT index (0/1 are extremal pts) + ind = -ind & 7; + ind ^= (2 > ind); + + // write index + mask |= ind << bits; + if((bits += 3) >= 8) { + *dest++ = mask; + mask >>= 8; + bits -= 8; + } + } +} + +static void stb__InitDXT() +{ + int i; + for(i=0;i<32;i++) + stb__Expand5[i] = (i<<3)|(i>>2); + + for(i=0;i<64;i++) + stb__Expand6[i] = (i<<2)|(i>>4); + + for(i=0;i<256+16;i++) + { + int v = i-8 < 0 ? 0 : i-8 > 255 ? 255 : i-8; + stb__QuantRBTab[i] = stb__Expand5[stb__Mul8Bit(v,31)]; + stb__QuantGTab[i] = stb__Expand6[stb__Mul8Bit(v,63)]; + } + + stb__PrepareOptTable(&stb__OMatch5[0][0],stb__Expand5,32); + stb__PrepareOptTable(&stb__OMatch6[0][0],stb__Expand6,64); +} + +void stb_compress_dxt_block(unsigned char *dest, const unsigned char *src, int alpha, int mode) +{ + static int init=1; + if (init) { + stb__InitDXT(); + init=0; + } + + if (alpha) { + stb__CompressAlphaBlock(dest,(unsigned char*) src,mode); + dest += 8; + } + + stb__CompressColorBlock(dest,(unsigned char*) src,mode); +} +#endif // STB_DXT_IMPLEMENTATION + +#endif // STB_INCLUDE_STB_DXT_H diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/stencil.c b/Projects/Android/jni/SupportLibs/gl4es/src/gl/stencil.c new file mode 100644 index 0000000..de961af --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/stencil.c @@ -0,0 +1,182 @@ +#include "stencil.h" + +#include "../glx/hardext.h" +#include "debug.h" +#include "gl4es.h" +#include "glstate.h" +#include "loader.h" + +void gl4es_glStencilMask(GLuint mask) { + if(!glstate->list.pending) + PUSH_IF_COMPILING(glStencilMask); + LOAD_GLES(glStencilMask); + if(glstate->stencil.mask[0]==glstate->stencil.mask[1] && glstate->stencil.mask[0]==mask) { + noerrorShim(); + return; + } + if(glstate->list.pending) + flush(); + glstate->stencil.mask[0] = glstate->stencil.mask[1] = mask; + errorGL(); + gles_glStencilMask(mask); +} +void glStencilMask(GLuint mask) AliasExport("gl4es_glStencilMask"); + +void gl4es_glStencilMaskSeparate(GLenum face, GLuint mask) { + if(face!=GL_FRONT && face!=GL_BACK && face!=GL_FRONT_AND_BACK) { + errorShim(GL_INVALID_ENUM); + return; + } + if(face==GL_FRONT_AND_BACK) { + gl4es_glStencilMask(mask); + return; + } + if(!glstate->list.pending) + PUSH_IF_COMPILING(glStencilMaskSeparate); + if((face==GL_FRONT && glstate->stencil.mask[0]==mask) || (face==GL_BACK && glstate->stencil.mask[1]==mask)) { + noerrorShim(); + return; + } + LOAD_GLES2_OR_OES(glStencilMaskSeparate); + if(glstate->list.pending) + flush(); + glstate->stencil.mask[(face==GL_FRONT)?0:1] = mask; + + errorGL(); + if(gles_glStencilMaskSeparate) { + gles_glStencilMaskSeparate(face, mask); + } else { + // fake function..., call it only for front or front_and_back, just ignore back (crappy, I know) + if (face==GL_FRONT) + gl4es_glStencilMask(mask); + else + noerrorShim(); + } +} +void glStencilMaskSeparate(GLenum face, GLuint mask) AliasExport("gl4es_glStencilMaskSeparate"); + +void gl4es_glStencilFunc(GLenum func, GLint ref, GLuint mask) { + if(!glstate->list.pending) + PUSH_IF_COMPILING(glStencilFunc); + if( glstate->stencil.func[0]==glstate->stencil.func[1] && glstate->stencil.func[0]==func + && glstate->stencil.f_ref[0]==glstate->stencil.f_ref[1] && glstate->stencil.f_ref[0]==ref + && glstate->stencil.f_mask[0]==glstate->stencil.f_mask[1] && glstate->stencil.f_mask[0]==mask ) { + noerrorShim(); + return; + } + LOAD_GLES(glStencilFunc); + errorGL(); + if(glstate->list.pending) + flush(); + glstate->stencil.func[0] = glstate->stencil.func[1] = func; + glstate->stencil.f_ref[0] = glstate->stencil.f_ref[1] = ref; + glstate->stencil.f_mask[0] = glstate->stencil.f_mask[1] = mask; + gles_glStencilFunc(func, ref, mask); +} +void glStencilFunc(GLenum func, GLint ref, GLuint mask) AliasExport("gl4es_glStencilFunc"); + +void gl4es_glStencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask) { + if(face!=GL_FRONT && face!=GL_BACK && face!=GL_FRONT_AND_BACK) { + errorShim(GL_INVALID_ENUM); + return; + } + if(face==GL_FRONT_AND_BACK) { + glStencilFunc(func, ref, mask); + return; + } + + if(!glstate->list.pending) + PUSH_IF_COMPILING(glStencilMaskSeparate); + int idx = (face==GL_FRONT)?0:1; + if(glstate->stencil.func[idx]==func && glstate->stencil.f_ref[idx]==ref && glstate->stencil.f_mask[idx]==mask) { + noerrorShim(); + return; + } + LOAD_GLES2_OR_OES(glStencilFuncSeparate); + errorGL(); + if(glstate->list.pending) + flush(); + glstate->stencil.func[idx]=func; + glstate->stencil.f_ref[idx]=ref; + glstate->stencil.f_mask[idx]=mask; + if(gles_glStencilFuncSeparate) { + gles_glStencilFuncSeparate(face, func, ref, mask); + } else { + // fake function..., call it only for front or front_and_back, just ignore back (crappy, I know) + if (face==GL_FRONT) + gl4es_glStencilFunc(func, ref, mask); + else + noerrorShim(); + } +} +void glStencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask) AliasExport("gl4es_glStencilFuncSeparate"); + +void gl4es_glStencilOp(GLenum fail, GLenum zfail, GLenum zpass) { + if(!glstate->list.pending) + PUSH_IF_COMPILING(glStencilOp); + if( glstate->stencil.sfail[0]==glstate->stencil.sfail[1] && glstate->stencil.sfail[0]==fail + && glstate->stencil.dpfail[0]==glstate->stencil.dpfail[1] && glstate->stencil.dpfail[0]==zfail + && glstate->stencil.dppass[0]==glstate->stencil.dppass[1] && glstate->stencil.dppass[0]==zpass ) { + noerrorShim(); + return; + } + LOAD_GLES(glStencilOp); + if(glstate->list.pending) + flush(); + glstate->stencil.sfail[0] = glstate->stencil.sfail[1] = fail; + glstate->stencil.dpfail[0] = glstate->stencil.dpfail[1] = zfail; + glstate->stencil.dppass[0] = glstate->stencil.dppass[1] = zpass; + errorGL(); + gles_glStencilOp(fail, zfail, zpass); +} +void glStencilOp(GLenum fail, GLenum zfail, GLenum zpass) AliasExport("gl4es_glStencilOp"); + +void gl4es_glStencilOpSeparate(GLenum face, GLenum sfail, GLenum zfail, GLenum zpass) { + if(face!=GL_FRONT && face!=GL_BACK && face!=GL_FRONT_AND_BACK) { + errorShim(GL_INVALID_ENUM); + return; + } + if(face==GL_FRONT_AND_BACK) { + glStencilOp(sfail, zfail, zpass); + return; + } + + if(!glstate->list.pending) + PUSH_IF_COMPILING(glStencilOpSeparate); + int idx = (face==GL_FRONT)?0:1; + if(glstate->stencil.sfail[idx]==sfail && glstate->stencil.dpfail[idx]==zfail && glstate->stencil.dppass[idx]==zpass) { + noerrorShim(); + return; + } + LOAD_GLES2_OR_OES(glStencilOpSeparate); + errorGL(); + glstate->stencil.sfail[idx] = sfail; + glstate->stencil.dpfail[idx] = zfail; + glstate->stencil.dppass[idx] = zpass; + if(gles_glStencilOpSeparate) { + gles_glStencilOpSeparate(face, sfail, zfail, zpass); + } else { + //fake, again + if (face==GL_FRONT) + gl4es_glStencilOp(sfail, zfail, zpass); + else + noerrorShim(); + } +} +void glStencilOpSeparate(GLenum face, GLenum sfail, GLenum zfail, GLenum zpass) AliasExport("gl4es_glStencilOpSeparate"); + +void gl4es_glClearStencil(GLint s) { + if(!glstate->list.pending) + PUSH_IF_COMPILING(glClearStencil); + if( glstate->stencil.clear==s) { + noerrorShim(); + return; + } + LOAD_GLES(glClearStencil); + if(glstate->list.pending) + flush(); + glstate->stencil.clear = s; + errorGL(); + gles_glClearStencil(s); +} +void glClearStencil(GLint s) AliasExport("gl4es_glClearStencil"); diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/stencil.h b/Projects/Android/jni/SupportLibs/gl4es/src/gl/stencil.h new file mode 100644 index 0000000..ee36d57 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/stencil.h @@ -0,0 +1,17 @@ +#ifndef _GL4ES_STENCIL_H_ +#define _GL4ES_STENCIL_H_ + +#include "gles.h" + +typedef struct { + GLenum func[2]; + GLint f_ref[2]; + GLuint f_mask[2]; + GLuint mask[2]; + GLenum sfail[2]; + GLenum dpfail[2]; + GLenum dppass[2]; + GLint clear; +} stencil_t; + +#endif // _GL4ES_STENCIL_H_ diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/string_utils.c b/Projects/Android/jni/SupportLibs/gl4es/src/gl/string_utils.c new file mode 100644 index 0000000..b49cf36 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/string_utils.c @@ -0,0 +1,149 @@ +#include +#include +#include + +#include "string_utils.h" + +const char* AllSeparators = " \t\n\r.,;()[]{}-<>+*/%&\\\"'^$=!:?"; + +int CountString(char* pBuffer, const char* S); +char* ResizeIfNeeded(char* pBuffer, int *size, int addsize); + +char* InplaceReplace(char* pBuffer, int* size, const char* S, const char* D) +{ + int lS = strlen(S), lD = strlen(D); + pBuffer = ResizeIfNeeded(pBuffer, size, (lD-lS)*CountString(pBuffer, S)); + char* p = pBuffer; + while((p = strstr(p, S))) + { + // found an occurence of S + // check if good to replace, strchr also found '\0' :) + if(strchr(AllSeparators, p[lS])!=NULL && (p==pBuffer || strchr(AllSeparators, p[-1])!=NULL)) { + // move out rest of string + memmove(p+lD, p+lS, strlen(p)-lS+1); + // replace + memcpy(p, D, strlen(D)); + // next + p+=lD; + } else p+=lS; + } + + return pBuffer; +} + +void InplaceInsert(char* pBuffer, const char* S) +{ + char* p = pBuffer; + int lS = strlen(S), ll = strlen(pBuffer); + memmove(p+lS, p, ll+1); + memcpy(p, S, lS); +} + +char* GetLine(char* pBuffer, int num) +{ + char *p = pBuffer; + while(num-- && (p=strstr(p, "\n"))) p+=strlen("\n"); + return (p)?p:pBuffer; +} + +int CountLine(const char* pBuffer) +{ + int n=0; + const char* p = pBuffer; + while(p=strstr(p, "\n")) { + p+=strlen("\n"); + n++; + } + return n; +} + +int CountString(char* pBuffer, const char* S) +{ + char* p = pBuffer; + int lS = strlen(S); + int n = 0; + while((p = strstr(p, S))) + { + // found an occurence of S + // check if good to count, strchr also found '\0' :) + if(strchr(AllSeparators, p[lS])!=NULL && (p==pBuffer || strchr(AllSeparators, p[-1])!=NULL)) + n++; + p+=lS; + } + return n; +} + +char* ResizeIfNeeded(char* pBuffer, int *size, int addsize) { + char* p = pBuffer; + int newsize = strlen(pBuffer)+addsize+1; + if (newsize>*size) { + newsize += 100; + p = (char*)realloc(pBuffer, newsize); + *size=newsize; + } + return p; +} + +char* Append(char* pBuffer, int* size, const char* S) { + char* p =pBuffer; + p = ResizeIfNeeded(pBuffer, size, strlen(S)); + strcat(p, S); + return p; +} + +int isBlank(char c) { + switch(c) { + case ' ': + case '\t': + case '\n': + case '\r': + case ':': + case ',': + case ';': + case '/': + return 1; + default: + return 0; + } +} +char* StrNext(char *pBuffer, const char* S) { + if(!pBuffer) return NULL; + char *p = strstr(pBuffer, S); + return (p)?p:(p+strlen(S)); +} + +char* NextStr(char* pBuffer) { + if(!pBuffer) return NULL; + while(isBlank(*pBuffer)) + ++pBuffer; + return pBuffer; +} + +char* NextBlank(char* pBuffer) { + if(!pBuffer) return NULL; + while(!isBlank(*pBuffer)) + ++pBuffer; + return pBuffer; +} + +char* NextLine(char* pBuffer) { + if(!pBuffer) return NULL; + while(*pBuffer && *pBuffer!='\n') + ++pBuffer; + return pBuffer; +} + +const char* GetNextStr(char* pBuffer) { + static char buff[100] = {0}; + buff[0] = '\0'; + if(!pBuffer) return NULL; + char* p1 = NextStr(pBuffer); + if(!p1) return buff; + char* p2 = NextBlank(p1); + if(!p2) return buff; + int i=0; + while(p1!=p2 && i<99) + buff[i++] = *(p1++); + buff[i] = '\0'; + return buff; +} \ No newline at end of file diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/string_utils.h b/Projects/Android/jni/SupportLibs/gl4es/src/gl/string_utils.h new file mode 100644 index 0000000..467b17e --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/string_utils.h @@ -0,0 +1,22 @@ +#ifndef _GL4ES_STRING_UTILS_H_ +#define _GL4ES_STRING_UTILS_H_ + +const char* AllSeparators; + +int CountString(char* pBuffer, const char* S); +char* ResizeIfNeeded(char* pBuffer, int *size, int addsize); +char* InplaceReplace(char* pBuffer, int* size, const char* S, const char* D); +char* Append(char* pBuffer, int* size, const char* S); +void InplaceInsert(char* pBuffer, const char* S); +char* GetLine(char* pBuffer, int num); +int CountLine(const char* pBuffer); +int CountString(char* pBuffer, const char* S); +char* StrNext(char *pBuffer, const char* S); // mostly as strstr, but go after the substring if found +//"blank" (space, tab, cr, lf,":", ",", ";", ".", "/") +char* NextStr(char* pBuffer); // go to next non "blank" +char* NextBlank(char* pBuffer); // go to next "blank" +char* NextLine(char* pBuffer); // go to next new line (crlf not included) + +const char* GetNextStr(char* pBuffer); // get a (static) copy of next str (until next separator), can be a simple number or separator also + +#endif // _GL4ES_STRING_UTILS_H_ diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/stubs.c b/Projects/Android/jni/SupportLibs/gl4es/src/gl/stubs.c new file mode 100644 index 0000000..2cc1424 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/stubs.c @@ -0,0 +1,27 @@ +#include "gl4es.h" + +#define GLAPI __attribute__((visibility("default"))) +#define APIENTRY +#define STUB errorShim(GL_INVALID_VALUE); + +GLAPI void APIENTRY glClampColorARB (GLenum target, GLenum clamp){STUB} + +GLAPI void APIENTRY glProgramStringARB (GLenum target, GLenum format, GLsizei len, const GLvoid *string){STUB} +GLAPI void APIENTRY glBindProgramARB (GLenum target, GLuint program){STUB} +GLAPI void APIENTRY glDeleteProgramsARB (GLsizei n, const GLuint *programs){STUB} +GLAPI void APIENTRY glGenProgramsARB (GLsizei n, GLuint *programs){STUB} +GLAPI void APIENTRY glProgramEnvParameter4dARB (GLenum target, GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w){STUB} +GLAPI void APIENTRY glProgramEnvParameter4dvARB (GLenum target, GLuint index, const GLdouble *params){STUB} +GLAPI void APIENTRY glProgramEnvParameter4fARB (GLenum target, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w){STUB} +GLAPI void APIENTRY glProgramEnvParameter4fvARB (GLenum target, GLuint index, const GLfloat *params){STUB} +GLAPI void APIENTRY glProgramLocalParameter4dARB (GLenum target, GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w){STUB} +GLAPI void APIENTRY glProgramLocalParameter4dvARB (GLenum target, GLuint index, const GLdouble *params){STUB} +GLAPI void APIENTRY glProgramLocalParameter4fARB (GLenum target, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w){STUB} +GLAPI void APIENTRY glProgramLocalParameter4fvARB (GLenum target, GLuint index, const GLfloat *params){STUB} +GLAPI void APIENTRY glGetProgramEnvParameterdvARB (GLenum target, GLuint index, GLdouble *params){STUB} +GLAPI void APIENTRY glGetProgramEnvParameterfvARB (GLenum target, GLuint index, GLfloat *params){STUB} +GLAPI void APIENTRY glGetProgramLocalParameterdvARB (GLenum target, GLuint index, GLdouble *params){STUB} +GLAPI void APIENTRY glGetProgramLocalParameterfvARB (GLenum target, GLuint index, GLfloat *params){STUB} +GLAPI void APIENTRY glGetProgramivARB (GLenum target, GLenum pname, GLint *params){STUB} +GLAPI void APIENTRY glGetProgramStringARB (GLenum target, GLenum pname, GLvoid *string){STUB} +GLAPI GLboolean APIENTRY glIsProgramARB (GLuint program){STUB return 0;} diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/texenv.c b/Projects/Android/jni/SupportLibs/gl4es/src/gl/texenv.c new file mode 100644 index 0000000..4fd8826 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/texenv.c @@ -0,0 +1,831 @@ +#include "texenv.h" + +#include "../glx/hardext.h" +#include "debug.h" +#include "fpe.h" +#include "gl4es.h" +#include "glstate.h" +#include "loader.h" + +//#define DEBUG +#ifdef DEBUG +#define DBG(a) a +#else +#define DBG(a) +#endif + +void gl4es_glTexEnvf(GLenum target, GLenum pname, GLfloat param) { + DBG(printf("glTexEnvf(%s, %s, 0x%04X(%s)), tmu=%d, pending=%d, compiling=%d\n", PrintEnum(target), PrintEnum(pname), (GLenum)param, PrintEnum((GLenum)param), glstate->texture.active, glstate->list.pending, glstate->list.compiling);) + if (!glstate->list.pending) { + PUSH_IF_COMPILING(glTexEnvf); + } + // Handling GL_EXT_DOT3, wrapping to standard dot3 (???) + if(param==GL_DOT3_RGB_EXT) param=GL_DOT3_RGB; + if(param==GL_DOT3_RGBA_EXT) param=GL_DOT3_RGBA; + const int tmu = glstate->texture.active; + noerrorShim(); + switch(target) { + case GL_POINT_SPRITE: + if(pname==GL_COORD_REPLACE) { + int p = (param!=0.0f)?1:0; + if (glstate->texture.pscoordreplace[tmu] == p) + return; + if (glstate->list.pending) flush(); + glstate->texture.pscoordreplace[tmu] = p; + if (glstate->fpe_state) + glstate->fpe_state->pointsprite_coord = p; + } else { + errorShim(GL_INVALID_ENUM); + return; + } + break; + case GL_TEXTURE_FILTER_CONTROL: + if(pname==GL_TEXTURE_LOD_BIAS) { + if(glstate->texenv[tmu].filter.lod_bias == param) + return; + if (glstate->list.pending) flush(); + glstate->texenv[tmu].filter.lod_bias = param; + } else { + errorShim(GL_INVALID_ENUM); + return; + } + break; + case GL_TEXTURE_ENV: + { + texenv_t *t = &glstate->texenv[tmu].env; + switch(pname) { + case GL_TEXTURE_ENV_MODE: + if(t->mode == param) + return; + if(param==GL_COMBINE4) { + if(hardext.esversion==1) { + errorShim(GL_INVALID_ENUM); + return; + } + } else if (param!=GL_ADD && param!=GL_MODULATE && param!=GL_DECAL && param!=GL_BLEND && param!=GL_REPLACE && param!=GL_COMBINE) { + errorShim(GL_INVALID_ENUM); + return; + } + if (glstate->list.pending) flush(); + t->mode = param; + if(glstate->fpe_state) { + int state = FPE_MODULATE; + switch(t->mode) { + case GL_ADD: state=FPE_ADD; break; + case GL_DECAL: state=FPE_DECAL; break; + case GL_BLEND: state=FPE_BLEND; break; + case GL_REPLACE: state=FPE_REPLACE; break; + case GL_COMBINE: state=FPE_COMBINE; break; + case GL_COMBINE4: state=FPE_COMBINE4; break; + } + glstate->fpe_state->texenv &= ~ (7<<(tmu*3)); + glstate->fpe_state->texenv |= state<<(tmu*3); + } + break; + case GL_COMBINE_RGB: + if(t->combine_rgb == param) + return; + if((param==GL_MODULATE_ADD_ATI || param==GL_MODULATE_SIGNED_ADD_ATI || param==GL_MODULATE_SUBTRACT_ATI)) { + if(hardext.esversion==1) { + errorShim(GL_INVALID_ENUM); + return; + } + } else if (param!=GL_REPLACE && param!=GL_MODULATE && param!=GL_ADD && param!=GL_ADD_SIGNED + && param!=GL_INTERPOLATE && param!=GL_SUBTRACT && param!=GL_DOT3_RGB && param!=GL_DOT3_RGBA) { + errorShim(GL_INVALID_ENUM); + return; + } + if (glstate->list.pending) flush(); + t->combine_rgb = param; + if(glstate->fpe_state) { + int state = FPE_CR_REPLACE; + switch(t->combine_rgb) { + case GL_MODULATE: state=FPE_CR_MODULATE; break; + case GL_ADD: state=FPE_CR_ADD; break; + case GL_ADD_SIGNED: state=FPE_CR_ADD_SIGNED; break; + case GL_INTERPOLATE: state=FPE_CR_INTERPOLATE; break; + case GL_SUBTRACT: state=FPE_CR_SUBTRACT; break; + case GL_DOT3_RGB: state=FPE_CR_DOT3_RGB; break; + case GL_DOT3_RGBA: state=FPE_CR_DOT3_RGBA; break; + case GL_MODULATE_ADD_ATI: state=FPE_CR_MOD_ADD; break; + case GL_MODULATE_SIGNED_ADD_ATI: state=FPE_CR_MOD_ADD_SIGNED; break; + case GL_MODULATE_SUBTRACT_ATI: state=FPE_CR_MOD_SUB; break; + } + glstate->fpe_state->texcombine[tmu] &= 0xf0; + glstate->fpe_state->texcombine[tmu] |= state; + } + break; + case GL_COMBINE_ALPHA: + if(t->combine_alpha == param) + return; + if((param==GL_MODULATE_ADD_ATI || param==GL_MODULATE_SIGNED_ADD_ATI || param==GL_MODULATE_SUBTRACT_ATI)) { + if(hardext.esversion==1) { + errorShim(GL_INVALID_ENUM); + return; + } + } else if (param!=GL_REPLACE && param!=GL_MODULATE && param!=GL_ADD && param!=GL_ADD_SIGNED + && param!=GL_INTERPOLATE && param!=GL_SUBTRACT) { + errorShim(GL_INVALID_ENUM); + return; + } + if (glstate->list.pending) flush(); + t->combine_alpha = param; + if(glstate->fpe_state) { + int state = FPE_CR_REPLACE; + switch(t->combine_alpha) { + case GL_MODULATE: state=FPE_CR_MODULATE; break; + case GL_ADD: state=FPE_CR_ADD; break; + case GL_ADD_SIGNED: state=FPE_CR_ADD_SIGNED; break; + case GL_INTERPOLATE: state=FPE_CR_INTERPOLATE; break; + case GL_SUBTRACT: state=FPE_CR_SUBTRACT; break; + case GL_MODULATE_ADD_ATI: state=FPE_CR_MOD_ADD; break; + case GL_MODULATE_SIGNED_ADD_ATI: state=FPE_CR_MOD_ADD_SIGNED; break; + case GL_MODULATE_SUBTRACT_ATI: state=FPE_CR_MOD_SUB; break; + } + glstate->fpe_state->texcombine[tmu] &= 0x0f; + glstate->fpe_state->texcombine[tmu] |= (state<<4); + } + break; + case GL_SRC0_RGB: + if(t->src0_rgb == param) + return; + if((param==GL_ZERO || param==GL_ONE + || param==GL_SECONDARY_COLOR_ATIX || param==GL_TEXTURE_OUTPUT_RGB_ATIX)) { + if(hardext.esversion==1) { + errorShim(GL_INVALID_ENUM); + return; + } + } else if (param!=GL_TEXTURE && !(param>=GL_TEXTURE0 && paramlist.pending) flush(); + t->src0_rgb = param; + if(glstate->fpe_state) { + int state = FPE_SRC_TEXTURE; + if(t->src0_rgb>=GL_TEXTURE0 && t->src0_rgb<=GL_TEXTURE8) { + state = FPE_SRC_TEXTURE0 + (t->src0_rgb-GL_TEXTURE0); + } else + switch(t->src0_rgb) { + case GL_CONSTANT: state=FPE_SRC_CONSTANT; break; + case GL_PRIMARY_COLOR: state=FPE_SRC_PRIMARY_COLOR; break; + case GL_PREVIOUS: state=FPE_SRC_PREVIOUS; break; + } + glstate->fpe_state->texsrcrgb[0] &= ~ (0xf<<(tmu*4)); + glstate->fpe_state->texsrcrgb[0] |= state<<(tmu*4); + } + break; + case GL_SRC1_RGB: + if(t->src1_rgb == param) + return; + if((param==GL_ZERO || param==GL_ONE + || param==GL_SECONDARY_COLOR_ATIX || param==GL_TEXTURE_OUTPUT_RGB_ATIX)) { + if(hardext.esversion==1) { + errorShim(GL_INVALID_ENUM); + return; + } + } else if (param!=GL_TEXTURE && !(param>=GL_TEXTURE0 && paramlist.pending) flush(); + t->src1_rgb = param; + if(glstate->fpe_state) { + int state = FPE_SRC_TEXTURE; + if(t->src1_rgb>=GL_TEXTURE0 && t->src1_rgb<=GL_TEXTURE8) { + state = FPE_SRC_TEXTURE0 + (t->src1_rgb-GL_TEXTURE0); + } else + switch(t->src1_rgb) { + case GL_CONSTANT: state=FPE_SRC_CONSTANT; break; + case GL_PRIMARY_COLOR: state=FPE_SRC_PRIMARY_COLOR; break; + case GL_PREVIOUS: state=FPE_SRC_PREVIOUS; break; + } + glstate->fpe_state->texsrcrgb[1] &= ~ (0xf<<(tmu*4)); + glstate->fpe_state->texsrcrgb[1] |= state<<(tmu*4); + } + break; + case GL_SRC2_RGB: + if(t->src2_rgb == param) + return; + if((param==GL_ZERO || param==GL_ONE + || param==GL_SECONDARY_COLOR_ATIX || param==GL_TEXTURE_OUTPUT_RGB_ATIX)) { + if(hardext.esversion==1) { + errorShim(GL_INVALID_ENUM); + return; + } + } else if (param!=GL_TEXTURE && !(param>=GL_TEXTURE0 && paramlist.pending) flush(); + t->src2_rgb = param; + if(glstate->fpe_state) { + int state = FPE_SRC_TEXTURE; + if(t->src2_rgb>=GL_TEXTURE0 && t->src2_rgb<=GL_TEXTURE8) { + state = FPE_SRC_TEXTURE0 + (t->src2_rgb-GL_TEXTURE0); + } else + switch(t->src2_rgb) { + case GL_CONSTANT: state=FPE_SRC_CONSTANT; break; + case GL_PRIMARY_COLOR: state=FPE_SRC_PRIMARY_COLOR; break; + case GL_PREVIOUS: state=FPE_SRC_PREVIOUS; break; + case GL_ONE: state=FPE_SRC_ONE; break; + case GL_ZERO: state=FPE_SRC_ZERO; break; + case GL_SECONDARY_COLOR_ATIX: state=FPE_SRC_SECONDARY_COLOR; break; + //case GL_TEXTUTRE_OUTPUT: unknown, so fall back to texture... + } + glstate->fpe_state->texsrcrgb[2] &= ~ (0xf<<(tmu*4)); + glstate->fpe_state->texsrcrgb[2] |= state<<(tmu*4); + } + break; + case GL_SRC3_RGB: + if(t->src3_rgb == param) + return; + if(hardext.esversion==1) { + errorShim(GL_INVALID_ENUM); + return; + } + if (param!=GL_TEXTURE && !(param>=GL_TEXTURE0 && paramlist.pending) flush(); + t->src3_rgb = param; + if(glstate->fpe_state) { + int state = FPE_SRC_TEXTURE; + if(param>=GL_TEXTURE0 && param<=GL_TEXTURE8) { + state = FPE_SRC_TEXTURE0 + (param-GL_TEXTURE0); + } else + switch(t->src3_rgb) { + case GL_CONSTANT: state=FPE_SRC_CONSTANT; break; + case GL_PRIMARY_COLOR: state=FPE_SRC_PRIMARY_COLOR; break; + case GL_PREVIOUS: state=FPE_SRC_PREVIOUS; break; + case GL_ZERO: state=FPE_SRC_ZERO; break; + } + glstate->fpe_state->texsrcrgb[3] &= ~ (0xf<<(tmu*4)); + glstate->fpe_state->texsrcrgb[3] |= state<<(tmu*4); + } + break; + case GL_SRC0_ALPHA: + if(t->src0_alpha == param) + return; + if((param==GL_ZERO || param==GL_ONE + || param==GL_TEXTURE_OUTPUT_ALPHA_ATIX)) { + if(hardext.esversion==1) { + errorShim(GL_INVALID_ENUM); + return; + } + } else if (param!=GL_TEXTURE && !(param>=GL_TEXTURE0 && paramlist.pending) flush(); + t->src0_alpha = param; + if(glstate->fpe_state) { + int state = FPE_SRC_TEXTURE; + if(t->src0_alpha>=GL_TEXTURE0 && t->src0_alpha<=GL_TEXTURE8) { + state = FPE_SRC_TEXTURE0 + (t->src0_alpha-GL_TEXTURE0); + } else + switch(t->src0_alpha) { + case GL_CONSTANT: state=FPE_SRC_CONSTANT; break; + case GL_PRIMARY_COLOR: state=FPE_SRC_PRIMARY_COLOR; break; + case GL_PREVIOUS: state=FPE_SRC_PREVIOUS; break; + case GL_ONE: state=FPE_SRC_ONE; break; + case GL_ZERO: state=FPE_SRC_ZERO; break; + //case GL_SECONDARY_COLOR_ATIX: state=FPE_SRC_SECONDARY_COLOR; break; + //case GL_TEXTUTRE_OUTPUT: unknown, so fall back to texture... + } + glstate->fpe_state->texsrcalpha[0] &= ~ (0xf<<(tmu*4)); + glstate->fpe_state->texsrcalpha[0] |= state<<(tmu*4); + } + break; + case GL_SRC1_ALPHA: + if(t->src1_alpha == param) + return; + if((param==GL_ZERO || param==GL_ONE + || param==GL_TEXTURE_OUTPUT_ALPHA_ATIX)) { + if(hardext.esversion==1) { + errorShim(GL_INVALID_ENUM); + return; + } + } else if (param!=GL_TEXTURE && !(param>=GL_TEXTURE0 && paramlist.pending) flush(); + t->src1_alpha = param; + if(glstate->fpe_state) { + int state = FPE_SRC_TEXTURE; + if(t->src1_alpha>=GL_TEXTURE0 && t->src1_alpha<=GL_TEXTURE8) { + state = FPE_SRC_TEXTURE0 + (t->src1_alpha-GL_TEXTURE0); + } else + switch(t->src1_alpha) { + case GL_CONSTANT: state=FPE_SRC_CONSTANT; break; + case GL_PRIMARY_COLOR: state=FPE_SRC_PRIMARY_COLOR; break; + case GL_PREVIOUS: state=FPE_SRC_PREVIOUS; break; + case GL_ONE: state=FPE_SRC_ONE; break; + case GL_ZERO: state=FPE_SRC_ZERO; break; + //case GL_SECONDARY_COLOR_ATIX: state=FPE_SRC_SECONDARY_COLOR; break; + //case GL_TEXTUTRE_OUTPUT: unknown, so fall back to texture... + } + glstate->fpe_state->texsrcalpha[1] &= ~ (0xf<<(tmu*4)); + glstate->fpe_state->texsrcalpha[1] |= state<<(tmu*4); + } + break; + case GL_SRC2_ALPHA: + if(t->src2_alpha == param) + return; + if((param==GL_ZERO || param==GL_ONE + || param==GL_TEXTURE_OUTPUT_ALPHA_ATIX)) { + if(hardext.esversion==1) { + errorShim(GL_INVALID_ENUM); + return; + } + } else if (param!=GL_TEXTURE && !(param>=GL_TEXTURE0 && paramlist.pending) flush(); + t->src2_alpha = param; + if(glstate->fpe_state) { + int state = FPE_SRC_TEXTURE; + if(t->src2_alpha>=GL_TEXTURE0 && t->src2_alpha<=GL_TEXTURE8) { + state = FPE_SRC_TEXTURE0 + (t->src2_alpha-GL_TEXTURE0); + } else + switch(t->src2_alpha) { + case GL_CONSTANT: state=FPE_SRC_CONSTANT; break; + case GL_PRIMARY_COLOR: state=FPE_SRC_PRIMARY_COLOR; break; + case GL_PREVIOUS: state=FPE_SRC_PREVIOUS; break; + case GL_ONE: state=FPE_SRC_ONE; break; + case GL_ZERO: state=FPE_SRC_ZERO; break; + //case GL_SECONDARY_COLOR_ATIX: state=FPE_SRC_SECONDARY_COLOR; break; + //case GL_TEXTUTRE_OUTPUT: unknown, so fall back to texture... + } + glstate->fpe_state->texsrcalpha[2] &= ~ (0xf<<(tmu*4)); + glstate->fpe_state->texsrcalpha[2] |= state<<(tmu*4); + } + break; + case GL_SRC3_ALPHA: + if(t->src3_alpha == param) + return; + if(hardext.esversion==1) { + errorShim(GL_INVALID_ENUM); + return; + } + if (param!=GL_TEXTURE && !(param>=GL_TEXTURE0 && paramlist.pending) flush(); + t->src3_alpha = param; + if(glstate->fpe_state) { + int state = FPE_SRC_TEXTURE; + if(param>=GL_TEXTURE0 && param<=GL_TEXTURE8) { + state = FPE_SRC_TEXTURE0 + (param-GL_TEXTURE0); + } else + switch(t->src3_alpha) { + case GL_CONSTANT: state=FPE_SRC_CONSTANT; break; + case GL_PRIMARY_COLOR: state=FPE_SRC_PRIMARY_COLOR; break; + case GL_PREVIOUS: state=FPE_SRC_PREVIOUS; break; + case GL_ZERO: state=FPE_SRC_ZERO; break; + } + glstate->fpe_state->texsrcalpha[3] &= ~ (0xf<<(tmu*4)); + glstate->fpe_state->texsrcalpha[3] |= state<<(tmu*4); + } + break; + case GL_OPERAND0_RGB: + if(t->op0_rgb == param) + return; + if (param!=GL_SRC_COLOR && param!=GL_ONE_MINUS_SRC_COLOR + && param!=GL_SRC_ALPHA && param!=GL_ONE_MINUS_SRC_ALPHA) { + errorShim(GL_INVALID_ENUM); + return; + } + if (glstate->list.pending) flush(); + t->op0_rgb = param; + if(glstate->fpe_state) { + int state = FPE_OP_ALPHA; + switch(t->op0_rgb) { + case GL_SRC_COLOR: state=FPE_OP_SRCCOLOR; break; + case GL_ONE_MINUS_SRC_COLOR: state=FPE_OP_MINUSCOLOR; break; + case GL_ONE_MINUS_SRC_ALPHA: state=FPE_OP_MINUSALPHA; break; + } + glstate->fpe_state->texoprgb[0] &= ~ (0x3<<(tmu*2)); + glstate->fpe_state->texoprgb[0] |= state<<(tmu*2); + } + break; + case GL_OPERAND1_RGB: + if(t->op1_rgb == param) + return; + if (param!=GL_SRC_COLOR && param!=GL_ONE_MINUS_SRC_COLOR + && param!=GL_SRC_ALPHA && param!=GL_ONE_MINUS_SRC_ALPHA) { + errorShim(GL_INVALID_ENUM); + return; + } + if (glstate->list.pending) flush(); + t->op1_rgb = param; + if(glstate->fpe_state) { + int state = FPE_OP_ALPHA; + switch(t->op1_rgb) { + case GL_SRC_COLOR: state=FPE_OP_SRCCOLOR; break; + case GL_ONE_MINUS_SRC_COLOR: state=FPE_OP_MINUSCOLOR; break; + case GL_ONE_MINUS_SRC_ALPHA: state=FPE_OP_MINUSALPHA; break; + } + glstate->fpe_state->texoprgb[1] &= ~ (0x3<<(tmu*2)); + glstate->fpe_state->texoprgb[1] |= state<<(tmu*2); + } + break; + case GL_OPERAND2_RGB: + if(t->op2_rgb == param) + return; + if (param!=GL_SRC_COLOR && param!=GL_ONE_MINUS_SRC_COLOR + && param!=GL_SRC_ALPHA && param!=GL_ONE_MINUS_SRC_ALPHA) { + errorShim(GL_INVALID_ENUM); + return; + } + if (glstate->list.pending) flush(); + t->op2_rgb = param; + if(glstate->fpe_state) { + int state = FPE_OP_ALPHA; + switch(t->op2_rgb) { + case GL_SRC_COLOR: state=FPE_OP_SRCCOLOR; break; + case GL_ONE_MINUS_SRC_COLOR: state=FPE_OP_MINUSCOLOR; break; + case GL_ONE_MINUS_SRC_ALPHA: state=FPE_OP_MINUSALPHA; break; + } + glstate->fpe_state->texoprgb[2] &= ~ (0x3<<(tmu*2)); + glstate->fpe_state->texoprgb[2] |= state<<(tmu*2); + } + break; + case GL_OPERAND3_RGB: + if(t->op3_rgb == param) + return; + if(hardext.esversion==1) { + errorShim(GL_INVALID_ENUM); + return; + } + if (param!=GL_SRC_COLOR && param!=GL_ONE_MINUS_SRC_COLOR + && param!=GL_SRC_ALPHA && param!=GL_ONE_MINUS_SRC_ALPHA) { + errorShim(GL_INVALID_ENUM); + return; + } + if (glstate->list.pending) flush(); + t->op3_rgb = param; + if(glstate->fpe_state) { + int state = FPE_OP_ALPHA; + switch(t->op3_rgb) { + case GL_SRC_COLOR: state=FPE_OP_SRCCOLOR; break; + case GL_ONE_MINUS_SRC_COLOR: state=FPE_OP_MINUSCOLOR; break; + case GL_ONE_MINUS_SRC_ALPHA: state=FPE_OP_MINUSALPHA; break; + } + glstate->fpe_state->texoprgb[3] &= ~ (0x3<<(tmu*2)); + glstate->fpe_state->texoprgb[3] |= state<<(tmu*2); + } + break; + case GL_OPERAND0_ALPHA: + if(t->op0_alpha == param) + return; + if (param!=GL_SRC_ALPHA && param!=GL_ONE_MINUS_SRC_ALPHA) { + errorShim(GL_INVALID_ENUM); + return; + } + if (glstate->list.pending) flush(); + t->op0_alpha = param; + if(glstate->fpe_state) { + int state = FPE_OP_ALPHA; + if(t->op0_alpha==GL_ONE_MINUS_SRC_ALPHA) state=FPE_OP_MINUSALPHA; + + glstate->fpe_state->texopalpha[0] &= ~ (0x1<fpe_state->texopalpha[0] |= state<op1_alpha == param) + return; + if (param!=GL_SRC_ALPHA && param!=GL_ONE_MINUS_SRC_ALPHA) { + errorShim(GL_INVALID_ENUM); + return; + } + if (glstate->list.pending) flush(); + t->op1_alpha = param; + if(glstate->fpe_state) { + int state = FPE_OP_ALPHA; + if(t->op1_alpha==GL_ONE_MINUS_SRC_ALPHA) state=FPE_OP_MINUSALPHA; + + glstate->fpe_state->texopalpha[1] &= ~ (0x1<fpe_state->texopalpha[1] |= state<op2_alpha == param) + return; + if (param!=GL_SRC_ALPHA && param!=GL_ONE_MINUS_SRC_ALPHA) { + errorShim(GL_INVALID_ENUM); + return; + } + if (glstate->list.pending) flush(); + t->op2_alpha = param; + if(glstate->fpe_state) { + int state = FPE_OP_ALPHA; + if(t->op2_alpha==GL_ONE_MINUS_SRC_ALPHA) state=FPE_OP_MINUSALPHA; + + glstate->fpe_state->texopalpha[2] &= ~ (0x1<fpe_state->texopalpha[2] |= state<op3_alpha == param) + return; + if(hardext.esversion==1) { + errorShim(GL_INVALID_ENUM); + return; + } + if (param!=GL_SRC_ALPHA && param!=GL_ONE_MINUS_SRC_ALPHA) { + errorShim(GL_INVALID_ENUM); + return; + } + if (glstate->list.pending) flush(); + t->op3_alpha = param; + if(glstate->fpe_state) { + int state = FPE_OP_ALPHA; + if(t->op3_alpha==GL_ONE_MINUS_SRC_ALPHA) state=FPE_OP_MINUSALPHA; + + glstate->fpe_state->texopalpha[3] &= ~ (0x1<fpe_state->texopalpha[3] |= state<rgb_scale == param) + return; + if(param!=1.0 && param!=2.0 && param!=4.0) { + errorShim(GL_INVALID_VALUE); + return; + } + if (glstate->list.pending) flush(); + t->rgb_scale = param; + if(glstate->fpe_state) { + if(param==1.0f) + glstate->fpe_state->texrgbscale &= ~(1<fpe_state->texrgbscale |= 1<alpha_scale == param) + return; + if(param!=1.0 && param!=2.0 && param!=4.0) { + errorShim(GL_INVALID_VALUE); + return; + } + if (glstate->list.pending) flush(); + t->alpha_scale = param; + if(glstate->fpe_state) { + if(param==1.0f) + glstate->fpe_state->texalphascale &= ~(1<fpe_state->texalphascale |= 1<");) + gl4es_glTexEnvf(target, pname, param); +} + +void gl4es_glTexEnvfv(GLenum target, GLenum pname, const GLfloat *param) { + DBG(printf("glTexEnvfv(%s, %s, %p)->", PrintEnum(target), PrintEnum(pname), param);) + if (glstate->list.compiling && glstate->list.active && !glstate->list.pending) { + DBG(printf("rlTexEnvfv(...)\n");) + NewStage(glstate->list.active, STAGE_TEXENV); + rlTexEnvfv(glstate->list.active, target, pname, param); + noerrorShim(); + return; + } + if(target==GL_TEXTURE_ENV && pname==GL_TEXTURE_ENV_COLOR) { + texenv_t *t = &glstate->texenv[glstate->texture.active].env; + DBG(printf("Color=%f/%f/%f/%f\n", param[0], param[1], param[2], param[3]);) + if(memcmp(t->color, param, 4*sizeof(GLfloat))==0) { + noerrorShim(); + return; + } + if (glstate->list.pending) flush(); + memcpy(t->color, param, 4*sizeof(GLfloat)); + errorGL(); + if(hardext.esversion==1) { + LOAD_GLES2(glTexEnvfv); + realize_active(); + gles_glTexEnvfv(target, pname, param); + } + } else + gl4es_glTexEnvf(target, pname, *param); +} +void gl4es_glTexEnviv(GLenum target, GLenum pname, const GLint *param) { + DBG(printf("glTexEnviv(%s, %s, %p)->", PrintEnum(target), PrintEnum(pname), param);) + if (glstate->list.compiling && glstate->list.active && !glstate->list.pending) { + DBG(printf("rlTexEnviv(...)\n");) + NewStage(glstate->list.active, STAGE_TEXENV); + rlTexEnviv(glstate->list.active, target, pname, param); + noerrorShim(); + return; + } + if(target==GL_TEXTURE_ENV && pname==GL_TEXTURE_ENV_COLOR) { + GLfloat p[4]; + p[0] = param[0]; p[1] = param[1]; p[2] = param[2]; p[3] = param[3]; + DBG(printf("Color=%d/%d/%d/%d\n", param[0], param[1], param[2], param[3]);) + gl4es_glTexEnvfv(target, pname, p); + } else + gl4es_glTexEnvf(target, pname, *param); +} +void gl4es_glGetTexEnvfv(GLenum target, GLenum pname, GLfloat * params) { + //if (glstate->list.pending) flush(); + DBG(printf("glGetTexEnvfv(%s, %s, %p)\n", PrintEnum(target), PrintEnum(pname), params);) + noerrorShim(); + switch(target) { + case GL_POINT_SPRITE: + if(pname == GL_COORD_REPLACE) { + *params = glstate->texture.pscoordreplace[glstate->texture.active]; + return; + } + break; + case GL_TEXTURE_FILTER_CONTROL: + if(pname == GL_TEXTURE_LOD_BIAS) { + *params = glstate->texenv[glstate->texture.active].filter.lod_bias; + return; + } + break; + case GL_TEXTURE_ENV: + { + texenv_t *t = &glstate->texenv[glstate->texture.active].env; + switch(pname) { + case GL_TEXTURE_ENV_MODE: + *params = t->mode; + return; + case GL_TEXTURE_ENV_COLOR: + memcpy(params, t->color, 4*sizeof(GLfloat)); + return; + case GL_COMBINE_RGB: + *params = t->combine_rgb; + return; + case GL_COMBINE_ALPHA: + *params = t->combine_alpha; + return; + case GL_SRC0_RGB: + *params = t->src0_rgb; + return; + case GL_SRC1_RGB: + *params = t->src1_rgb; + return; + case GL_SRC2_RGB: + *params = t->src2_rgb; + return; + case GL_SRC0_ALPHA: + *params = t->src0_alpha; + return; + case GL_SRC1_ALPHA: + *params = t->src1_alpha; + return; + case GL_SRC2_ALPHA: + *params = t->src2_alpha; + return; + case GL_OPERAND0_RGB: + *params = t->op0_rgb; + break; + case GL_OPERAND1_RGB: + *params = t->op1_rgb; + break; + case GL_OPERAND2_RGB: + *params = t->op2_rgb; + break; + case GL_OPERAND0_ALPHA: + *params = t->op0_alpha; + break; + case GL_OPERAND1_ALPHA: + *params = t->op1_alpha; + break; + case GL_OPERAND2_ALPHA: + *params = t->op2_alpha; + break; + case GL_RGB_SCALE: + *params = t->rgb_scale; + return; + case GL_ALPHA_SCALE: + *params = t->alpha_scale; + return; + } + } + } + errorShim(GL_INVALID_ENUM); + return; +} +void gl4es_glGetTexEnviv(GLenum target, GLenum pname, GLint * params) { + // LOAD_GLES(glGetTexEnviv); + //if (glstate->list.pending) flush(); + noerrorShim(); + switch(target) { + case GL_POINT_SPRITE: + if(pname == GL_COORD_REPLACE) { + *params = glstate->texture.pscoordreplace[glstate->texture.active]; + return; + } + break; + case GL_TEXTURE_FILTER_CONTROL: + if(pname == GL_TEXTURE_LOD_BIAS) { + *params = glstate->texenv[glstate->texture.active].filter.lod_bias; + return; + } + break; + case GL_TEXTURE_ENV: + { + texenv_t *t = &glstate->texenv[glstate->texture.active].env; + switch(pname) { + case GL_TEXTURE_ENV_MODE: + *params = t->mode; + return; + case GL_TEXTURE_ENV_COLOR: + memcpy(params, t->color, 4*sizeof(GLfloat)); + return; + case GL_COMBINE_RGB: + *params = t->combine_rgb; + return; + case GL_COMBINE_ALPHA: + *params = t->combine_alpha; + return; + case GL_SRC0_RGB: + *params = t->src0_rgb; + return; + case GL_SRC1_RGB: + *params = t->src1_rgb; + return; + case GL_SRC2_RGB: + *params = t->src2_rgb; + return; + case GL_SRC0_ALPHA: + *params = t->src0_alpha; + return; + case GL_SRC1_ALPHA: + *params = t->src1_alpha; + return; + case GL_SRC2_ALPHA: + *params = t->src2_alpha; + return; + case GL_OPERAND0_RGB: + *params = t->op0_rgb; + break; + case GL_OPERAND1_RGB: + *params = t->op1_rgb; + break; + case GL_OPERAND2_RGB: + *params = t->op2_rgb; + break; + case GL_OPERAND0_ALPHA: + *params = t->op0_alpha; + break; + case GL_OPERAND1_ALPHA: + *params = t->op1_alpha; + break; + case GL_OPERAND2_ALPHA: + *params = t->op2_alpha; + break; + case GL_RGB_SCALE: + *params = t->rgb_scale; + return; + case GL_ALPHA_SCALE: + *params = t->alpha_scale; + return; + } + } + } + errorShim(GL_INVALID_ENUM); + return; +} + + +void glTexEnvf(GLenum target, GLenum pname, GLfloat param) AliasExport("gl4es_glTexEnvf"); +void glTexEnvi(GLenum target, GLenum pname, GLint param) AliasExport("gl4es_glTexEnvi"); +void glTexEnvfv(GLenum target, GLenum pname, const GLfloat *param) AliasExport("gl4es_glTexEnvfv"); +void glTexEnviv(GLenum target, GLenum pname, const GLint *param) AliasExport("gl4es_glTexEnviv"); +void glGetTexEnvfv(GLenum target, GLenum pname, GLfloat * params) AliasExport("gl4es_glGetTexEnvfv"); +void glGetTexEnviv(GLenum target, GLenum pname, GLint * params) AliasExport("gl4es_glGetTexEnviv"); diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/texenv.h b/Projects/Android/jni/SupportLibs/gl4es/src/gl/texenv.h new file mode 100644 index 0000000..b1a0225 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/texenv.h @@ -0,0 +1,42 @@ +#ifndef _GL4ES_TEXENV_H_ +#define _GL4ES_TEXENV_H_ + +#include "gles.h" + +typedef struct { + GLenum mode; + GLfloat color[4]; + GLenum combine_rgb; + GLenum combine_alpha; + GLfloat rgb_scale; + GLfloat alpha_scale; + GLenum src0_rgb; + GLenum src1_rgb; + GLenum src2_rgb; + GLenum src3_rgb; + GLenum src0_alpha; + GLenum src1_alpha; + GLenum src2_alpha; + GLenum src3_alpha; + GLenum op0_rgb; + GLenum op1_rgb; + GLenum op2_rgb; + GLenum op3_rgb; + GLenum op0_alpha; + GLenum op1_alpha; + GLenum op2_alpha; + GLenum op3_alpha; +} texenv_t; + +typedef struct { + GLenum lod_bias; +} texfilter_t; + +void gl4es_glTexEnvf(GLenum target, GLenum pname, GLfloat param); +void gl4es_glTexEnvi(GLenum target, GLenum pname, GLint param); +void gl4es_glTexEnvfv(GLenum target, GLenum pname, const GLfloat *param); +void gl4es_glTexEnviv(GLenum target, GLenum pname, const GLint *param); +void gl4es_glGetTexEnvfv(GLenum target, GLenum pname, GLfloat * params); +void gl4es_glGetTexEnviv(GLenum target, GLenum pname, GLint * params); + +#endif // _GL4ES_TEXENV_H_ diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/texgen.c b/Projects/Android/jni/SupportLibs/gl4es/src/gl/texgen.c new file mode 100644 index 0000000..79ada5f --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/texgen.c @@ -0,0 +1,463 @@ +#include "texgen.h" + +#include "../glx/hardext.h" +#include "wrap/gl4es.h" +#include "fpe.h" +#include "init.h" +#include "loader.h" +#include "matrix.h" +#include "matvec.h" + +//extern void* eglGetProcAddress(const char*); + +void gl4es_glTexGeni(GLenum coord, GLenum pname, GLint param) { + GLfloat params[4] = {0,0,0,0}; + params[0]=param; + gl4es_glTexGenfv(coord, pname, params); +} + +void gl4es_glTexGenfv(GLenum coord, GLenum pname, const GLfloat *param) { + + /* + If pname is GL_TEXTURE_GEN_MODE, then the array must contain + a single symbolic constant, one of + GL_OBJECT_LINEAR, GL_EYE_LINEAR, GL_SPHERE_MAP, GL_NORMAL_MAP, + or GL_REFLECTION_MAP. + Otherwise, params holds the coefficients for the texture-coordinate + generation function specified by pname. + */ + + //printf("glTexGenf(%s, %s, %s/%f), texture=%i\n", PrintEnum(coord), PrintEnum(pname), PrintEnum(param[0]), param[0], glstate->texture.active); + ERROR_IN_BEGIN + if (glstate->list.active) + if (glstate->list.compiling) { + NewStage(glstate->list.active, STAGE_TEXGEN); + rlTexGenfv(glstate->list.active, coord, pname, param); + noerrorShim(); + return; + } else flush(); + + // pname is in: GL_TEXTURE_GEN_MODE, GL_OBJECT_PLANE, GL_EYE_PLANE + noerrorShim(); + switch(pname) { + case GL_TEXTURE_GEN_MODE: { + int mode = -1; + int n; + if(glstate->fpe_state) { + int p = param[0]; + switch (p) { + case GL_OBJECT_LINEAR: mode = FPE_TG_OBJLINEAR; break; + case GL_EYE_LINEAR: mode = FPE_TG_EYELINEAR; break; + case GL_SPHERE_MAP: mode = FPE_TG_SPHEREMAP; break; + case GL_NORMAL_MAP: mode = FPE_TG_NORMALMAP; break; + case GL_REFLECTION_MAP: mode = FPE_TG_REFLECMAP; break; + } + n = glstate->texture.active*3; + } + switch (coord) { + case GL_S: glstate->texgen[glstate->texture.active].S = param[0]; if(mode!=-1) { glstate->fpe_state->texgen_s_mode&=~(7<fpe_state->texgen_s_mode|=(mode<texgen[glstate->texture.active].T = param[0]; if(mode!=-1) { glstate->fpe_state->texgen_t_mode&=~(7<fpe_state->texgen_t_mode|=(mode<texgen[glstate->texture.active].R = param[0]; if(mode!=-1) { glstate->fpe_state->texgen_r_mode&=~(7<fpe_state->texgen_r_mode|=(mode<texgen[glstate->texture.active].Q = param[0]; if(mode!=-1) { glstate->fpe_state->texgen_q_mode&=~(7<fpe_state->texgen_q_mode|=(mode<texgen[glstate->texture.active].S_O, param, 4 * sizeof(GLfloat)); + break; + case GL_T: + memcpy(glstate->texgen[glstate->texture.active].T_O, param, 4 * sizeof(GLfloat)); + break; + case GL_R: + memcpy(glstate->texgen[glstate->texture.active].R_O, param, 4 * sizeof(GLfloat)); + break; + case GL_Q: + memcpy(glstate->texgen[glstate->texture.active].Q_O, param, 4 * sizeof(GLfloat)); + break; + default: + errorShim(GL_INVALID_ENUM); + } + return; + case GL_EYE_PLANE: { + // need to transform here + GLfloat pe[4]; + vector_matrix(param, getInvMVMat(), pe); + switch (coord) { + case GL_S: + memcpy(glstate->texgen[glstate->texture.active].S_E, pe, 4 * sizeof(GLfloat)); + break; + case GL_T: + memcpy(glstate->texgen[glstate->texture.active].T_E, pe, 4 * sizeof(GLfloat)); + break; + case GL_R: + memcpy(glstate->texgen[glstate->texture.active].R_E, pe, 4 * sizeof(GLfloat)); + break; + case GL_Q: + memcpy(glstate->texgen[glstate->texture.active].Q_E, pe, 4 * sizeof(GLfloat)); + break; + default: + errorShim(GL_INVALID_ENUM); + } + return; + } + default: + errorShim(GL_INVALID_ENUM); + } +} +void gl4es_glGetTexGenfv(GLenum coord,GLenum pname,GLfloat *params) { + if (glstate->list.pending) + flush(); + noerrorShim(); + switch(pname) { + case GL_TEXTURE_GEN_MODE: + switch (coord) { + case GL_S: *params = glstate->texgen[glstate->texture.active].S; break; + case GL_T: *params = glstate->texgen[glstate->texture.active].T; break; + case GL_R: *params = glstate->texgen[glstate->texture.active].R; break; + case GL_Q: *params = glstate->texgen[glstate->texture.active].Q; break; + default: *params = GL_EYE_LINEAR; + } + break; + case GL_OBJECT_PLANE: + switch (coord) { + case GL_S: + memcpy(params, glstate->texgen[glstate->texture.active].S_O, 4 * sizeof(GLfloat)); + break; + case GL_T: + memcpy(params, glstate->texgen[glstate->texture.active].T_O, 4 * sizeof(GLfloat)); + break; + case GL_R: + memcpy(params, glstate->texgen[glstate->texture.active].R_O, 4 * sizeof(GLfloat)); + break; + case GL_Q: + memcpy(params, glstate->texgen[glstate->texture.active].Q_O, 4 * sizeof(GLfloat)); + break; + default: + errorShim(GL_INVALID_ENUM); + } + break; + case GL_EYE_PLANE: + switch (coord) { + case GL_S: + memcpy(params, glstate->texgen[glstate->texture.active].S_E, 4 * sizeof(GLfloat)); + break; + case GL_T: + memcpy(params, glstate->texgen[glstate->texture.active].T_E, 4 * sizeof(GLfloat)); + break; + case GL_R: + memcpy(params, glstate->texgen[glstate->texture.active].R_E, 4 * sizeof(GLfloat)); + break; + case GL_Q: + memcpy(params, glstate->texgen[glstate->texture.active].Q_E, 4 * sizeof(GLfloat)); + break; + default: + errorShim(GL_INVALID_ENUM); + } + break; + default: + errorShim(GL_INVALID_ENUM); + } +} + + +void dot_loop(const GLfloat *verts, const GLfloat *params, GLfloat *out, GLint count, GLushort *indices) { + for (int i = 0; i < count; i++) { + GLushort k = indices?indices[i]:i; + out[k*4] = dot4(verts+k*4, params);// + params[3]; + } +} + +void sphere_loop(const GLfloat *verts, const GLfloat *norm, GLfloat *out, GLint count, GLushort *indices) { + // based on https://www.opengl.org/wiki/Mathematics_of_glTexGen +/* if (!norm) { + printf("LIBGL: GL_SPHERE_MAP without Normals\n"); + return; + }*/ + // First get the ModelviewMatrix + GLfloat InvModelview[16]; + matrix_transpose(getInvMVMat(), InvModelview); + const GLfloat *ModelviewMatrix = getMVMat(); + GLfloat eye[4], eye_norm[4], reflect[4]; + GLfloat a; + for (int i=0; inormal, InvModelview, eye_norm); + vector_normalize(eye_norm); + a=dot(eye, eye_norm)*2.0f; + for (int j=0; j<3; j++) + reflect[j]=eye[j]-eye_norm[j]*a; + reflect[2]+=1.0f; + a = 0.5f / sqrtf(dot(reflect, reflect)); + out[k*4+0] = reflect[0]*a + 0.5f; + out[k*4+1] = reflect[1]*a + 0.5f; + out[k*4+2] = 0.0f; + out[k*4+3] = 1.0f; + } + +} + +void reflection_loop(const GLfloat *verts, const GLfloat *norm, GLfloat *out, GLint count, GLushort *indices) { + // based on https://www.opengl.org/wiki/Mathematics_of_glTexGen +/* if (!norm) { + printf("LIBGL: GL_REFLECTION_MAP without Normals\n"); + return; + }*/ + GLfloat InvModelview[16]; + matrix_transpose(InvModelview, getInvMVMat()); + const GLfloat * ModelviewMatrix = getMVMat(); + GLfloat eye[4], eye_norm[4]; + GLfloat a; + for (int i=0; inormal, InvModelview, eye_norm); + vector4_normalize(eye_norm); + a=dot4(eye, eye_norm)*2.0f; + out[k*4+0] = eye[0] - eye_norm[0]*a; + out[k*4+1] = eye[1] - eye_norm[1]*a; + out[k*4+2] = eye[2] - eye_norm[2]*a; + out[k*4+3] = 1.0f; + } + +} + +void eye_loop(const GLfloat *verts, const GLfloat *param, GLfloat *out, GLint count, GLushort *indices) { + // based on https://www.opengl.org/wiki/Mathematics_of_glTexGen + // First get the ModelviewMatrix + const GLfloat *ModelviewMatrix = getMVMat(); + GLfloat tmp[4]; + for (int i=0; i row major + matrix_transpose(InvModelview, ModelviewMatrix); + // And get the inverse + matrix_inverse(ModelviewMatrix, InvModelview); + GLfloat tmp[4]; + for (int i=0; ienable.texgen_s[texture])?PrintEnum(glstate->texgen[texture].S):"-", (glstate->enable.texgen_t[texture])?PrintEnum(glstate->texgen[texture].T):"-", (glstate->enable.texgen_r[texture])?PrintEnum(glstate->texgen[texture].R):"-", (glstate->enable.texgen_q[texture])?PrintEnum(glstate->texgen[texture].Q):"-", (glstate->enable.texgen_s[texture])?'S':'-', (glstate->enable.texgen_t[texture])?'T':'-', (glstate->enable.texgen_r[texture])?'R':'-', (glstate->enable.texgen_q[texture])?'Q':'-', glstate->enable.texture[texture]); + // TODO: do less work when called from glDrawElements? + (*needclean) = 0; + // special case : no texgen but texture activated, create a simple 1 repeated element + if (!glstate->enable.texgen_s[texture] && !glstate->enable.texgen_t[texture] && !glstate->enable.texgen_r[texture] && !glstate->enable.texgen_q[texture]) { + if ((*coords)==NULL) + *coords = (GLfloat *)malloc(count * 4 * sizeof(GLfloat)); + if (indices) + for (int i=0; itexcoord[texture], sizeof(GLfloat)*4); + } + else + for (int i=0; itexcoord[texture], sizeof(GLfloat)*4); + } + return; + } + // special case: SPHERE_MAP needs both texgen to make sense + if ((glstate->enable.texgen_s[texture] && (glstate->texgen[texture].S==GL_SPHERE_MAP)) && (glstate->enable.texgen_t[texture] && (glstate->texgen[texture].T==GL_SPHERE_MAP))) + { + if (!IS_TEX2D(glstate->enable.texture[texture])) + return; + if ((*coords)==NULL) + *coords = (GLfloat *)malloc(count * 4 * sizeof(GLfloat)); + sphere_loop(verts, norm, *coords, (indices)?ilen:count, indices); + return; + } + // special case: REFLECTION_MAP needs the 3 texgen to make sense + if ((glstate->enable.texgen_s[texture] && (glstate->texgen[texture].S==GL_REFLECTION_MAP)) + && (glstate->enable.texgen_t[texture] && (glstate->texgen[texture].T==GL_REFLECTION_MAP)) + && (glstate->enable.texgen_r[texture] && (glstate->texgen[texture].R==GL_REFLECTION_MAP))) + { + if(hardext.cubemap) { + *needclean=1; + // setup reflection map! + GLuint old_tex=glstate->texture.active; + if (old_tex!=texture) gl4es_glActiveTexture(GL_TEXTURE0 + texture); + realize_active(); + LOAD_GLES_OES(glTexGeni); + LOAD_GLES_OES(glTexGenfv); + LOAD_GLES(glEnable); + // setup cube map mode + gles_glTexGeni(GL_TEXTURE_GEN_STR, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP); + // enable texgen + gles_glEnable(GL_TEXTURE_GEN_STR); + // check Texture Matrix + if (!(globals4es.texmat || glstate->texture_matrix[texture]->identity)) { + LOAD_GLES(glLoadMatrixf); + GLenum old_mat = glstate->matrix_mode; + if(old_mat!=GL_TEXTURE) gl4es_glMatrixMode(GL_TEXTURE); + gles_glLoadMatrixf(getTexMat(texture)); + if(old_mat!=GL_TEXTURE) gl4es_glMatrixMode(old_mat); + } + + if (old_tex!=texture) gl4es_glActiveTexture(GL_TEXTURE0 + old_tex); + } else { + if (!IS_TEX2D(glstate->enable.texture[texture])) + return; + if ((*coords)==NULL) + *coords = (GLfloat *)malloc(count * 4 * sizeof(GLfloat)); + reflection_loop(verts, norm, *coords, (indices)?ilen:count, indices); + } + return; + } + // special case: NORMAL_MAP needs the 3 texgen to make sense + if ((glstate->enable.texgen_s[texture] && (glstate->texgen[texture].S==GL_NORMAL_MAP)) + && (glstate->enable.texgen_t[texture] && (glstate->texgen[texture].T==GL_NORMAL_MAP)) + && (glstate->enable.texgen_r[texture] && (glstate->texgen[texture].R==GL_NORMAL_MAP))) + { + *needclean=1; + // setup normal map! + GLuint old_tex=glstate->texture.active; + if (old_tex!=texture) gl4es_glActiveTexture(GL_TEXTURE0 + texture); + realize_active(); + LOAD_GLES_OES(glTexGeni); + LOAD_GLES_OES(glTexGenfv); + LOAD_GLES(glEnable); + // setup cube map mode + gles_glTexGeni(GL_TEXTURE_GEN_STR, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP); + // enable texgen + gles_glEnable(GL_TEXTURE_GEN_STR); + // check Texture Matrix + if (!(globals4es.texmat || glstate->texture_matrix[texture]->identity)) { + LOAD_GLES(glLoadMatrixf); + GLenum old_mat = glstate->matrix_mode; + if(old_mat!=GL_TEXTURE) gl4es_glMatrixMode(GL_TEXTURE); + gles_glLoadMatrixf(getTexMat(texture)); + if(old_mat!=GL_TEXTURE) gl4es_glMatrixMode(old_mat); + } + + if (old_tex!=texture) gl4es_glActiveTexture(GL_TEXTURE0 + old_tex); + + return; + } + if (!IS_ANYTEX(glstate->enable.texture[texture])) + return; + if ((*coords)==NULL) + *coords = (GLfloat *)malloc(count * 4 * sizeof(GLfloat)); + if ( (glstate->enable.texgen_s[texture] && glstate->texgen[texture].S==GL_EYE_LINEAR) + && (glstate->enable.texgen_t[texture] && glstate->texgen[texture].T==GL_EYE_LINEAR) ) + { + eye_loop_dual(verts, glstate->texgen[texture].S_E, glstate->texgen[texture].T_E, (*coords), (indices)?ilen:count, indices); + } else { + if (glstate->enable.texgen_s[texture]) + tex_coord_loop(verts, norm, (*coords), (indices)?ilen:count, glstate->texgen[texture].S, glstate->texgen[texture].S_O, glstate->texgen[texture].S_E, indices); + if (glstate->enable.texgen_t[texture]) + tex_coord_loop(verts, norm, (*coords)+1, (indices)?ilen:count, glstate->texgen[texture].T, glstate->texgen[texture].T_O, glstate->texgen[texture].T_E, indices); + } + if (glstate->enable.texgen_r[texture]) + tex_coord_loop(verts, norm, (*coords)+2, (indices)?ilen:count, glstate->texgen[texture].R, glstate->texgen[texture].R_O, glstate->texgen[texture].R_E, indices); + else + for (int i=0; i<((indices)?ilen:count); i++) { + GLushort k = indices?indices[i]:i; + (*coords)[k*4+2] = 0.0f; + } + if (glstate->enable.texgen_q[texture]) + tex_coord_loop(verts, norm, (*coords)+3, (indices)?ilen:count, glstate->texgen[texture].Q, glstate->texgen[texture].Q_O, glstate->texgen[texture].Q_E, indices); + else + for (int i=0; i<((indices)?ilen:count); i++) { + GLushort k = indices?indices[i]:i; + (*coords)[k*4+3] = 1.0f; + } +} + +void gen_tex_clean(GLint cleancode, int texture) { + if (cleancode == 0) + return; + if (cleancode == 1) { + GLuint old_tex=glstate->texture.active; + LOAD_GLES(glDisable); + gles_glDisable(GL_TEXTURE_GEN_STR); + // check Texture Matrix + if ((hardext.esversion==1) && !(globals4es.texmat || glstate->texture_matrix[texture]->identity)) { + LOAD_GLES(glLoadIdentity); + GLenum old_mat = glstate->matrix_mode; + if(old_mat!=GL_TEXTURE) gl4es_glMatrixMode(GL_TEXTURE); + gles_glLoadIdentity(); + if(old_mat!=GL_TEXTURE) gl4es_glMatrixMode(old_mat); + } + return; + } +} + +void gl4es_glLoadTransposeMatrixf(const GLfloat *m) { + GLfloat mf[16]; + matrix_transpose(m, mf); + gl4es_glLoadMatrixf(mf); + errorGL(); +} + +void gl4es_glLoadTransposeMatrixd(const GLdouble *m) { + GLfloat mf[16]; + for (int i=0; i<16; i++) + mf[i] = m[i]; + gl4es_glLoadTransposeMatrixf(mf); +} + +void gl4es_glMultTransposeMatrixd(const GLdouble *m) { + GLfloat mf[16]; + for (int i=0; i<16; i++) + mf[i] = m[i]; + gl4es_glMultTransposeMatrixf(mf); +} +void gl4es_glMultTransposeMatrixf(const GLfloat *m) { + GLfloat mf[16]; + matrix_transpose(m, mf); + gl4es_glMultMatrixf(mf); + errorGL(); +} + +void glTexGenfv(GLenum coord, GLenum pname, const GLfloat *params) AliasExport("gl4es_glTexGenfv"); +void glTexGeni(GLenum coord, GLenum pname, GLint param) AliasExport("gl4es_glTexGeni"); +void glGetTexGenfv(GLenum coord,GLenum pname,GLfloat *params) AliasExport("gl4es_glGetTexGenfv"); + +void glLoadTransposeMatrixf(const GLfloat *m) AliasExport("gl4es_glLoadTransposeMatrixf"); +void glLoadTransposeMatrixd(const GLdouble *m) AliasExport("gl4es_glLoadTransposeMatrixd"); +void glMultTransposeMatrixd(const GLdouble *m) AliasExport("gl4es_glMultTransposeMatrixd"); +void glMultTransposeMatrixf(const GLfloat *m) AliasExport("gl4es_glMultTransposeMatrixf"); diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/texgen.h b/Projects/Android/jni/SupportLibs/gl4es/src/gl/texgen.h new file mode 100644 index 0000000..4995f19 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/texgen.h @@ -0,0 +1,17 @@ +#ifndef _GL4ES_TEXGEN_H_ +#define _GL4ES_TEXGEN_H_ + +#include "gles.h" + +void gl4es_glTexGenfv(GLenum coord, GLenum pname, const GLfloat *params); +void gl4es_glTexGeni(GLenum coord, GLenum pname, GLint param); +void gen_tex_coords(GLfloat *verts, GLfloat *norm, GLfloat **coords, GLint count, GLint *needclean, int texture, GLushort* indices, GLuint ilen); +void gen_tex_clean(GLint cleancode, int texture); +void gl4es_glGetTexGenfv(GLenum coord,GLenum pname,GLfloat *params); + +void gl4es_glLoadTransposeMatrixf(const GLfloat *m); +void gl4es_glLoadTransposeMatrixd(const GLdouble *m); +void gl4es_glMultTransposeMatrixd(const GLdouble *m); +void gl4es_glMultTransposeMatrixf(const GLfloat *m); + +#endif // _GL4ES_TEXGEN_H_ diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/texture.c b/Projects/Android/jni/SupportLibs/gl4es/src/gl/texture.c new file mode 100644 index 0000000..13b9144 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/texture.c @@ -0,0 +1,3215 @@ +#include "texture.h" + +#include "../glx/hardext.h" +#include "../glx/streaming.h" +#include "array.h" +#include "blit.h" +#include "decompress.h" +#include "debug.h" +#include "enum_info.h" +#include "fpe.h" +#include "framebuffers.h" +#include "gles.h" +#include "init.h" +#include "loader.h" +#include "matrix.h" +#include "pixel.h" +#include "raster.h" +#include "stb_dxt_104.h" + +KHASH_MAP_IMPL_INT(tex, gltexture_t *); + +//#define DEBUG +#ifdef DEBUG +#define DBG(a) a +#else +#define DBG(a) +#endif + +#ifndef GL_TEXTURE_STREAM_IMG +#define GL_TEXTURE_STREAM_IMG 0x8C0D +#endif +#ifdef TEXSTREAM +#include +#include +#endif + +// expand non-power-of-two sizes +// TODO: what does this do to repeating textures? +int npot(int n) { + if (n == 0) return 0; + + int i = 1; + while (i < n) i <<= 1; + return i; +} + +static int inline nlevel(int size, int level) { + if(size) { + size>>=level; + if(!size) size=1; + } + return size; +} + +// conversions for GL_ARB_texture_rectangle +void tex_coord_rect_arb(GLfloat *tex, int stride, GLsizei len, + GLsizei width, GLsizei height) { + if (!tex || !width || !height) + return; + + GLfloat iwidth, iheight; + iwidth = 1.0f/width; + iheight = 1.0f/height; + if(!stride) stride=4; + + for (int i = 0; i < len; i++) { + tex[0] *= iwidth; + tex[1] *= iheight; + tex += stride; + } +} + +void tex_coord_npot(GLfloat *tex, GLsizei len, + GLsizei width, GLsizei height, + GLsizei nwidth, GLsizei nheight) { + if (!tex || !nwidth || !nheight) + return; + GLfloat wratio = (width / (GLfloat)nwidth); + GLfloat hratio = (height / (GLfloat)nheight); + for (int i = 0; i < len; i++) { + tex[0] *= wratio; + tex[1] *= hratio; + tex += 4; + } +} + +void tex_coord_matrix(GLfloat *tex, GLsizei len, const GLfloat* mat) { + if (!tex || !len || !mat || hardext.esversion!=1) + return; + for (int i = 0; i < len; i++) { + vector_matrix(tex, mat, tex); + tex += 4; + } +} + +/* Setup the texture coordinates + * + * Have to check is ARB_RECTANGLE is used + * Apply texture matrix if not identity + * Or some NPOT texture used + */ +int inline tex_setup_needchange(GLuint itarget) { + if(hardext.esversion>1) return 0; // no text ajustement on ES2 + + GLuint texunit = glstate->texture.client; + gltexture_t *bound = glstate->texture.bound[texunit][itarget]; + + // check if some changes are needed + if ((itarget == ENABLED_TEXTURE_RECTANGLE) + || (hardext.esversion==1 && bound->adjust) + || (hardext.esversion==1 && !globals4es.texmat && !glstate->texture_matrix[texunit]->identity) + ) + return 1; + return 0; +} +void tex_setup_texcoord(GLuint len, int changes, GLuint itarget, pointer_state_t* ptr) { + LOAD_GLES_FPE(glTexCoordPointer); + GLuint texunit = glstate->texture.client; + + static void * tex[MAX_TEX] = {0}; + static int texlen[MAX_TEX] = {0}; + + gltexture_t *bound = glstate->texture.bound[texunit][itarget]; + + if (changes) { + // first convert to GLfloat, without normalization + if(texlen[texunit]width, bound->height); + // Apply transformation matrix if any + if (!(globals4es.texmat || glstate->texture_matrix[texunit]->identity)) + tex_coord_matrix(tex[texunit], len, getTexMat(texunit)); + // NPOT adjust + if (bound->adjust) + tex_coord_npot(tex[texunit], len, bound->width, bound->height, bound->nwidth, bound->nheight); + // All done, setup the texcoord array now + gles_glTexCoordPointer(4, GL_FLOAT, 0, tex[texunit]); + } else { + gles_glTexCoordPointer(ptr->size, ptr->type, ptr->stride, ptr->pointer); + } +} + +static int is_fake_compressed_rgb(GLenum internalformat) +{ + if(internalformat==GL_COMPRESSED_RGB) return 1; + if(internalformat==GL_COMPRESSED_RGB_S3TC_DXT1_EXT) return 1; + return 0; +} +static int is_fake_compressed_rgba(GLenum internalformat) +{ + if(internalformat==GL_COMPRESSED_RGBA) return 1; + if(internalformat==GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) return 1; + if(internalformat==GL_COMPRESSED_RGBA_S3TC_DXT3_EXT) return 1; + if(internalformat==GL_COMPRESSED_RGBA_S3TC_DXT5_EXT) return 1; + return 0; +} + +void internal2format_type(GLenum internalformat, GLenum *format, GLenum *type) +{ + switch(internalformat) { + case GL_RED: + if(!hardext.rgtex) { + *format = GL_RGB; + *type = GL_UNSIGNED_BYTE; + } else { + *format = GL_RED; + *type = GL_UNSIGNED_BYTE; + } + break; + case GL_RG: + if(!hardext.rgtex) { + *format = GL_RGB; + *type = GL_UNSIGNED_BYTE; + } else { + *format = GL_RG; + *type = GL_UNSIGNED_BYTE; + } + break; + case GL_COMPRESSED_ALPHA: + case GL_ALPHA: + *format = GL_ALPHA; + *type = GL_UNSIGNED_BYTE; + break; + case 1: + case GL_COMPRESSED_LUMINANCE: + case GL_LUMINANCE: + *format = GL_LUMINANCE; + *type = GL_UNSIGNED_BYTE; + break; + case 2: + case GL_COMPRESSED_LUMINANCE_ALPHA: + case GL_LUMINANCE8_ALPHA8: + case GL_LUMINANCE_ALPHA: + if(globals4es.nolumalpha) { + *format = GL_RGBA; + *type = GL_UNSIGNED_BYTE; + } else { + *format = GL_LUMINANCE_ALPHA; + *type = GL_UNSIGNED_BYTE; + } + break; + case GL_RGB5: + case GL_RGB565: + *format = GL_RGB; + *type = GL_UNSIGNED_SHORT_5_6_5; + break; + case GL_RGB: + if(globals4es.avoid24bits) + *format = GL_RGBA; + else + *format = GL_RGB; + *type = GL_UNSIGNED_BYTE; + break; + case GL_RGB5_A1: + *format = GL_RGBA; + *type = GL_UNSIGNED_SHORT_5_5_5_1; + break; + case GL_RGBA4: + *format = GL_RGBA; + *type = GL_UNSIGNED_SHORT_4_4_4_4; + break; + case GL_RGBA: + *format = GL_RGBA; + *type = GL_UNSIGNED_BYTE; + break; + case GL_BGRA: + if(hardext.bgra8888) + *format = GL_BGRA; + else + *format = GL_RGBA; + *type = GL_UNSIGNED_BYTE; + break; + case GL_DEPTH_COMPONENT: + *format = GL_DEPTH_COMPONENT; + *type = GL_UNSIGNED_SHORT; + break; + case GL_DEPTH_STENCIL: + case GL_DEPTH24_STENCIL8: + *format = GL_DEPTH_STENCIL; + *type = GL_UNSIGNED_INT_24_8; + break; + case GL_RGBA16F: + *format = GL_RGBA; + *type = (hardext.halffloattex)?GL_HALF_FLOAT_OES:GL_UNSIGNED_BYTE; + break; + case GL_RGBA32F: + *format = GL_RGBA; + *type = (hardext.floattex)?GL_FLOAT:GL_UNSIGNED_BYTE; + break; + case GL_RGB16F: + *format = GL_RGB; + *type = (hardext.halffloattex)?GL_HALF_FLOAT_OES:GL_UNSIGNED_BYTE; + break; + case GL_RGB32F: + *format = GL_RGB; + *type = (hardext.floattex)?GL_FLOAT:GL_UNSIGNED_BYTE; + break; + default: + printf("LIBGL: Warning, unknown Internalformat (%s)\n", PrintEnum(internalformat)); + *format = GL_RGBA; + *type = GL_UNSIGNED_BYTE; + break; + } +} + +static void *swizzle_texture(GLsizei width, GLsizei height, + GLenum *format, GLenum *type, + GLenum intermediaryformat, GLenum internalformat, + const GLvoid *data, gltexture_t *bound) { + bool convert = false; + GLenum dest_format = GL_RGBA; + GLenum dest_type = GL_UNSIGNED_BYTE; + // compressed format are not handled here, so mask them.... + if (is_fake_compressed_rgb(intermediaryformat)) intermediaryformat=GL_RGB; + if (is_fake_compressed_rgba(intermediaryformat)) intermediaryformat=GL_RGBA; + if (is_fake_compressed_rgb(internalformat)) internalformat=GL_RGB; + if (is_fake_compressed_rgba(internalformat)) internalformat=GL_RGBA; + if (intermediaryformat==GL_COMPRESSED_LUMINANCE) intermediaryformat=GL_LUMINANCE; + if (internalformat==GL_COMPRESSED_LUMINANCE) internalformat=GL_LUMINANCE; + + if(*format != intermediaryformat || intermediaryformat!=internalformat) { + internal2format_type(intermediaryformat, &dest_format, &dest_type); + convert = true; + } else { + if((*type)==GL_HALF_FLOAT) (*type) = GL_HALF_FLOAT_OES; //the define is different between GL and GLES... + switch (*format) { + case GL_R: + case GL_RED: + if(!hardext.rgtex) { + dest_format = GL_RGB; + convert = true; + } else + dest_format = GL_RED; + break; + case GL_RG: + if(!hardext.rgtex) { + dest_format = GL_RGB; + convert = true; + } else + dest_format = GL_RG; + break; + case GL_COMPRESSED_LUMINANCE: + *format = GL_LUMINANCE; + case GL_LUMINANCE: + dest_format = GL_LUMINANCE; + break; + case GL_LUMINANCE16F: + dest_format = GL_LUMINANCE; + if(hardext.halffloattex) + dest_type = GL_HALF_FLOAT_OES; + break; + case GL_LUMINANCE32F: + dest_format = GL_LUMINANCE; + if(hardext.floattex) + dest_type = GL_FLOAT; + break; + case GL_RGB: + dest_format = GL_RGB; + break; + case GL_COMPRESSED_ALPHA: + *format = GL_ALPHA; + case GL_ALPHA: + dest_format = GL_ALPHA; + break; + case GL_ALPHA16F: + dest_format = GL_ALPHA; + if(hardext.halffloattex) + dest_type = GL_HALF_FLOAT_OES; + break; + case GL_ALPHA32F: + dest_format = GL_ALPHA; + if(hardext.floattex) + dest_type = GL_FLOAT; + break; + case GL_RGBA: + break; + case GL_LUMINANCE8_ALPHA8: + case GL_COMPRESSED_LUMINANCE_ALPHA: + if(globals4es.nolumalpha) + convert = true; + else { + dest_format = GL_LUMINANCE_ALPHA; + *format = GL_LUMINANCE_ALPHA; + } + break; + case GL_LUMINANCE_ALPHA: + if(globals4es.nolumalpha) + convert = true; + else + dest_format = GL_LUMINANCE_ALPHA; + break; + case GL_LUMINANCE_ALPHA16F: + if(globals4es.nolumalpha) + convert = true; + else + dest_format = GL_LUMINANCE_ALPHA; + if(hardext.halffloattex) + dest_type = GL_HALF_FLOAT_OES; + break; + case GL_LUMINANCE_ALPHA32F: + if(globals4es.nolumalpha) + convert = true; + else + dest_format = GL_LUMINANCE_ALPHA; + if(hardext.floattex) + dest_type = GL_FLOAT; + break; + // vvvvv all this are internal formats, so it should not happens + case GL_RGB5: + case GL_RGB565: + dest_format = GL_RGB; + dest_type = GL_UNSIGNED_SHORT_5_6_5; + convert = true; + break; + case GL_RGB8: + dest_format = GL_RGB; + *format = GL_RGB; + break; + case GL_RGBA4: + dest_format = GL_RGBA; + dest_type = GL_UNSIGNED_SHORT_4_4_4_4; + *format = GL_RGBA; + break; + case GL_RGBA8: + dest_format = GL_RGBA; + *format = GL_RGBA; + break; + case GL_BGRA: + if(hardext.bgra8888 && ((*type)==GL_UNSIGNED_BYTE || (*type)==GL_FLOAT || (*type)==GL_HALF_FLOAT)) { + dest_format = GL_BGRA; + *format = GL_BGRA; + } else convert = true; + break; + case GL_DEPTH24_STENCIL8: + case GL_DEPTH_STENCIL: + if(hardext.depthtex && hardext.depthstencil) { + *format = dest_format = GL_DEPTH_STENCIL; + dest_type = GL_UNSIGNED_INT_24_8; + } else convert = true; + break; + case GL_DEPTH_COMPONENT: + case GL_DEPTH_COMPONENT16: + case GL_DEPTH_COMPONENT32: + if(hardext.depthtex) { + if(dest_type==GL_UNSIGNED_BYTE) { + dest_type=(*format==GL_DEPTH_COMPONENT32)?GL_UNSIGNED_INT:GL_UNSIGNED_SHORT; + convert = true; + } + *format = dest_format = GL_DEPTH_COMPONENT; + } else + convert = true; + break; + case GL_STENCIL_INDEX8: + if(hardext.stenciltex) + *format = dest_format = GL_STENCIL_INDEX8; + else + convert = true; + break; + default: + convert = true; + break; + } + switch (*type) { + case GL_UNSIGNED_SHORT_4_4_4_4_REV: + if(dest_format==GL_RGBA) + dest_type = GL_UNSIGNED_SHORT_4_4_4_4; + convert = true; + break; + case GL_UNSIGNED_SHORT_4_4_4_4: + if(dest_format==GL_RGBA) + dest_type = GL_UNSIGNED_SHORT_4_4_4_4; + else + convert = true; + break; + case GL_UNSIGNED_SHORT_1_5_5_5_REV: + if(dest_format==GL_RGBA) + dest_type = GL_UNSIGNED_SHORT_5_5_5_1; + convert = true; + break; + case GL_UNSIGNED_SHORT_5_5_5_1: + if(dest_format==GL_RGBA) + dest_type = GL_UNSIGNED_SHORT_5_5_5_1; + else + convert = true; + break; + case GL_UNSIGNED_SHORT_5_6_5_REV: + if (dest_format==GL_RGB) + dest_type = GL_UNSIGNED_SHORT_5_6_5; + convert = true; + break; + case GL_UNSIGNED_SHORT_5_6_5: + if (dest_format==GL_RGB) + dest_type = GL_UNSIGNED_SHORT_5_6_5; + else + convert = true; + break; + case GL_UNSIGNED_INT_8_8_8_8_REV: + *type = GL_UNSIGNED_BYTE; + // fall through + case GL_UNSIGNED_BYTE: + if(dest_format==GL_RGB && globals4es.avoid24bits) { + dest_format = GL_RGBA; + convert = true; + } + break; + case GL_UNSIGNED_INT_24_8: + if(hardext.depthtex && hardext.depthstencil) { + dest_type = GL_UNSIGNED_INT_24_8; + } else { + *type = GL_UNSIGNED_BYTE; // will probably do nothing good! + convert = true; + } + break; + case GL_FLOAT: + if(hardext.floattex) + dest_type = GL_FLOAT; + else + convert = true; + break; + case GL_HALF_FLOAT: + case GL_HALF_FLOAT_OES: + if(hardext.halffloattex) + dest_type = GL_HALF_FLOAT_OES; + else + convert = true; + break; + default: + convert = true; + break; + } + } + if (data) { + if (convert) { + GLvoid *pixels = (GLvoid *)data; + bound->inter_format = dest_format; + bound->format = dest_format; + bound->inter_type = dest_type; + bound->type = dest_type; + if (! pixel_convert(data, &pixels, width, height, + *format, *type, dest_format, dest_type, 0, glstate->texture.unpack_align)) { + printf("LIBGL: swizzle error: (%s, %s -> %s, %s)\n", + PrintEnum(*format), PrintEnum(*type), PrintEnum(dest_format), PrintEnum(dest_type)); + return NULL; + } + *type = dest_type; + *format = dest_format; + if(dest_format!=internalformat) { + GLvoid *pix2 = (GLvoid *)pixels; + internal2format_type(internalformat, &dest_format, &dest_type); + bound->format = dest_format; + bound->type = dest_type; + if (! pixel_convert(pixels, &pix2, width, height, + *format, *type, dest_format, dest_type, 0, glstate->texture.unpack_align)) { + printf("LIBGL: swizzle error: (%s, %s -> %s, %s)\n", + PrintEnum(dest_format), PrintEnum(dest_type), PrintEnum(internalformat), PrintEnum(dest_type)); + return NULL; + } + if(pix2!=pixels) { + if (pixels!=data) + free(pixels); + pixels = pix2; + } + *type = dest_type; + *format = dest_format; + } + GLvoid *pix2 = pixels; + if (raster_need_transform()) + if (!pixel_transform(data, &pixels, width, height, + *format, *type, glstate->raster.raster_scale, glstate->raster.raster_bias)) { + printf("LIBGL: swizzle/convert error: (%s, %s -> %s, %s)\n", + PrintEnum(*format), PrintEnum(*type), PrintEnum(dest_format), PrintEnum(dest_type)); + pix2 = pixels; + } + if (pix2!=pixels && pixels!=data) + free(pixels); + return pix2; + } else { + bound->inter_format = dest_format; + bound->format = dest_format; + bound->inter_type = dest_type; + bound->type = dest_type; + } + } else { + bound->inter_format = dest_format; + bound->inter_type = dest_type; + if (convert) { + internal2format_type(internalformat, &dest_format, &dest_type); // in case they are differents + *type = dest_type; + *format = dest_format; + } + bound->format = dest_format; + bound->type = dest_type; + } + return (void *)data; +} + +GLenum swizzle_internalformat(GLenum *internalformat, GLenum format, GLenum type) { + GLenum ret = *internalformat; + GLenum sret; + switch(*internalformat) { + case GL_RED: + if(!hardext.rgtex) { + ret = GL_RGB; sret = GL_RGB; + } else + sret = GL_RED; + break; + case GL_RG: + if(!hardext.rgtex) { + ret = GL_RGB; sret = GL_RGB; + } else + sret = GL_RG; + break; + case GL_RGB565: + ret=GL_RGB5; + case GL_RGB5: + sret = GL_RGB5; + break; + case GL_RGB: + if(globals4es.avoid16bits==0 && format==GL_RGB && type==GL_UNSIGNED_SHORT_5_6_5) { + sret = ret = GL_RGB5; + break; + } + case GL_RGB8: + case GL_BGR: + case GL_RGB16: + case GL_RGB16F: + case GL_RGB32F: + case 3: + ret = GL_RGB; sret = GL_RGB; + break; + case GL_RGBA4: + sret = GL_RGBA4; + break; + case GL_RGB5_A1: + sret = GL_RGB5_A1; + break; + case GL_RGBA: + if(globals4es.avoid16bits==0 && format==GL_RGBA && type==GL_UNSIGNED_SHORT_5_5_5_1) { + sret = ret = GL_RGB5_A1; + break; + } + if(globals4es.avoid16bits==0 && format==GL_RGBA && type==GL_UNSIGNED_SHORT_4_4_4_4) { + sret = ret = GL_RGBA4; + break; + } + case GL_RGBA8: + case GL_RGBA16: + case GL_RGBA16F: + case GL_RGBA32F: + case GL_RGB10_A2: + case 4: + if(format==GL_BGRA && hardext.bgra8888) { + ret = GL_BGRA; sret = GL_BGRA; + } else { + ret = GL_RGBA; sret = GL_RGBA; + } + break; + case GL_ALPHA32F: + case GL_ALPHA16F: + case GL_ALPHA8: + case GL_ALPHA: + ret = GL_ALPHA; sret = GL_ALPHA; + break; + case 1: + case GL_LUMINANCE32F: + case GL_LUMINANCE16F: + case GL_LUMINANCE8: + case GL_LUMINANCE16: + case GL_LUMINANCE: + if(format==GL_RED && hardext.rgtex) { + ret = GL_RED; sret = GL_RED; + } else { + ret = GL_LUMINANCE; sret = GL_LUMINANCE; + } + break; + case 2: + case GL_LUMINANCE4_ALPHA4: + case GL_LUMINANCE8_ALPHA8: + case GL_LUMINANCE16_ALPHA16: + case GL_LUMINANCE_ALPHA32F: + case GL_LUMINANCE_ALPHA16F: + case GL_LUMINANCE_ALPHA: + ret = GL_LUMINANCE_ALPHA; + if (globals4es.nolumalpha) + sret = GL_RGBA; + else + sret = GL_LUMINANCE_ALPHA; + break; + // compressed format... + case GL_COMPRESSED_ALPHA: + ret = GL_ALPHA;//GL_COMPRESSED_RGBA; + sret = GL_ALPHA; + break; + case GL_COMPRESSED_LUMINANCE: + ret = GL_LUMINANCE;//GL_COMPRESSED_RGB; + sret = GL_LUMINANCE; + break; + case GL_COMPRESSED_LUMINANCE_ALPHA: + if (globals4es.nolumalpha) { + ret = GL_COMPRESSED_RGBA; + sret = GL_RGBA; + } else { + ret = GL_LUMINANCE_ALPHA; + sret = GL_LUMINANCE_ALPHA; + } + break; + case GL_COMPRESSED_RGB: + sret = GL_RGB; + break; + case GL_COMPRESSED_RGBA: + sret = GL_RGBA; + break; + case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: + ret = GL_COMPRESSED_RGB; + sret = GL_RGB; + break; + case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: // not good... + case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: // not good, but there is no DXT3 compressor + case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: + ret = GL_COMPRESSED_RGBA; + sret = GL_RGBA; + break; + case GL_BGRA: + if(hardext.bgra8888) { + ret = GL_BGRA; + sret = GL_BGRA; + } else { + ret = GL_RGBA; + sret = GL_RGBA; + } + break; + case GL_DEPTH_COMPONENT: + if(hardext.depthtex) { + sret = ret = GL_DEPTH_COMPONENT; + } else { + sret = ret = GL_RGBA; + } + break; + case GL_DEPTH_COMPONENT16: + if(hardext.depthtex) { + sret = ret = GL_DEPTH_COMPONENT; + } else { + sret = ret = GL_RGBA; + } + break; + case GL_DEPTH_COMPONENT32: + if(hardext.depthtex) { + sret = ret = GL_DEPTH_COMPONENT; + } else { + sret = ret = GL_RGBA; + } + break; + case GL_DEPTH24_STENCIL8: + if(hardext.depthtex) { + sret = ret = GL_DEPTH_STENCIL; + } else { + sret = ret = GL_RGBA; + } + break; + case GL_STENCIL_INDEX8: + if(hardext.stenciltex) { + sret = ret = GL_STENCIL_INDEX8; + } else { + sret = ret = (hardext.rgtex)?GL_RED:GL_LUMINANCE; + } + break; + default: + ret = GL_RGBA; + sret = GL_RGBA; + break; + // Default...RGBA / RGBA will be fine.... + } + *internalformat = ret; + return sret; +} + +static int get_shrinklevel(int width, int height, int level) { + int shrink = 0; + int mipwidth = width << level; + int mipheight = height << level; + switch(globals4es.texshrink) { + case 0: // nothing + break; + case 1: //everything / 2 + if ((mipwidth > 1) && (mipheight > 1)) { + shrink = 1; + } + break; + case 2: //only > 512 /2 + case 7: //only > 512 /2 , but not for empty texture + if (((mipwidth%2==0) && (mipheight%2==0)) && + ((mipwidth > 512) && (mipheight > 8)) || ((mipheight > 512) && (mipwidth > 8))) { + shrink = 1; + } + break; + case 3: //only > 256 /2 + if (((mipwidth%2==0) && (mipheight%2==0)) && + ((mipwidth > 256) && (mipheight > 8)) || ((mipheight > 256) && (mipwidth > 8))) { + shrink = 1; + } + break; + case 4: //only > 256 /2, >=1024 /4 + if (((mipwidth%4==0) && (mipheight%4==0)) && + ((mipwidth > 256) && (mipheight > 8)) || ((mipheight > 256) && (mipwidth > 8))) { + if ((mipwidth>=1024) || (mipheight>=1024)) { + shrink = 2; + } else { + shrink = 1; + } + } + break; + case 5: //every > 256 is downscaled to 256, but not for empty texture + if (((mipwidth%4==0) && (mipheight%4==0)) && + ((mipwidth > 256) && (mipheight > 8)) || ((mipheight > 256) && (mipwidth > 8))) { + if ((mipwidth>256) || (mipheight>256)) { + while (((mipwidth > 256) && (mipheight > 4)) || ((mipheight > 256) && (mipwidth > 4))) { + width /= 2; + height /= 2; + mipwidth /= 2; + mipheight /= 2; + shrink+=1; + } + } else { + shrink = 1; + } + } + break; + case 6: //only > 128 /2, >=512 is downscaled to 256, but not for empty texture + if (((mipwidth%2==0) && (mipheight%2==0)) && + ((mipwidth > 128) && (mipheight > 8)) || ((mipheight > 128) && (mipwidth > 8))) { + if ((mipwidth>=512) || (mipheight>=512)) { + while (((mipwidth > 256) && (mipheight > 8)) || ((mipheight > 256) && (mipwidth > 8))) { + width /= 2; + height /= 2; + mipwidth /= 2; + mipheight /= 2; + shrink+=1; + } + } else { + shrink = 1; + } + } + break; + case 8: //advertise *4 max texture size, but >2048 are shrinked to 2048 + if ((mipwidth>hardext.maxsize*2) || (mipheight>hardext.maxsize*2)) { + shrink=2; + } else + if ((mipwidth>hardext.maxsize) || (mipheight>hardext.maxsize)) { + shrink=1; + } + break; + case 9: //advertise 8192 max texture size, but >4096 are quadshrinked and >512 are shrinked, but not for empty texture + if ((mipwidth>hardext.maxsize*2) || (mipheight>hardext.maxsize*2)) { + shrink=2; + } else + if (mipwidth>(hardext.maxsize>>2) || mipheight>(hardext.maxsize>>2)) { + shrink=1; + } + break; + case 10://advertise 8192 max texture size, but >2048 are quadshrinked and >512 are shrinked, but not for empty texture + if ((mipwidth>hardext.maxsize) || (mipheight>hardext.maxsize)) { + shrink=2; + } else + if ((mipwidth>(hardext.maxsize>>2)) || (mipheight>(hardext.maxsize>>2))) { + shrink=1; + } + break; + case 11:// scale down to maxres any dimension > maxres + if(mipwidth>hardext.maxsize || mipheight>hardext.maxsize) + shrink=1; + break; + } + + return shrink; +} + +static int proxy_width = 0; +static int proxy_height = 0; +static GLint proxy_intformat = 0; + +int wrap_npot(GLenum wrap) { + switch(wrap) { + case 0: return 1; // default is ok (should not, it's GL_REPEAT) + case GL_CLAMP: + case GL_CLAMP_TO_EDGE: + case GL_CLAMP_TO_BORDER: + return 1; + } + return 0; +} +int minmag_npot(GLenum mag) { + switch(mag) { + case 0: return 0; // default is not good + case GL_NEAREST: + case GL_LINEAR: + return 1; + } + return 0; +} + +GLenum minmag_forcenpot(GLenum filt) { + switch(filt) { + case GL_LINEAR: + case GL_LINEAR_MIPMAP_NEAREST: + case GL_LINEAR_MIPMAP_LINEAR: + return GL_LINEAR; + /*case 0: + case GL_NEAREST: + case GL_NEAREST_MIPMAP_NEATEST: + case GL_NEAREST_MIPMAP_LINEAR:*/ + default: + return GL_NEAREST; + } +} + +GLenum minmag_float(GLenum filt) { + switch(filt) { + case GL_LINEAR: + return GL_NEAREST; + case GL_LINEAR_MIPMAP_NEAREST: + case GL_LINEAR_MIPMAP_LINEAR: + case GL_NEAREST_MIPMAP_LINEAR: + return GL_NEAREST_MIPMAP_NEAREST; + default: + return filt; + } +} + +void gl4es_glTexImage2D(GLenum target, GLint level, GLint internalformat, + GLsizei width, GLsizei height, GLint border, + GLenum format, GLenum type, const GLvoid *data) { + DBG(printf("glTexImage2D on target=%s with unpack_row_length(%i), size(%i,%i) and skip(%i,%i), format(internal)=%s(%s), type=%s, data=%p, level=%i (mipmap_need=%i, mipmap_auto=%i, base_level=%i, max_level=%i) => texture=%u (streamed=%i), glstate->list.compiling=%d\n", PrintEnum(target), glstate->texture.unpack_row_length, width, height, glstate->texture.unpack_skip_pixels, glstate->texture.unpack_skip_rows, PrintEnum(format), (internalformat==3)?"3":(internalformat==4?"4":PrintEnum(internalformat)), PrintEnum(type), data, level, glstate->texture.bound[glstate->texture.active][what_target(target)]->mipmap_need, glstate->texture.bound[glstate->texture.active][what_target(target)]->mipmap_auto, glstate->texture.bound[glstate->texture.active][what_target(target)]->base_level, glstate->texture.bound[glstate->texture.active][what_target(target)]->max_level, glstate->texture.bound[glstate->texture.active][what_target(target)]->texture, glstate->texture.bound[glstate->texture.active][what_target(target)]->streamed, glstate->list.compiling);) + // proxy case + const GLuint itarget = what_target(target); + const GLuint rtarget = map_tex_target(target); + LOAD_GLES(glTexImage2D); + LOAD_GLES(glTexSubImage2D); + LOAD_GLES(glTexParameteri); + + if(globals4es.force16bits) { + if(internalformat==GL_RGBA || internalformat==4 || internalformat==GL_RGBA8) + internalformat = GL_RGBA4; + else if(internalformat==GL_RGB || internalformat==3 || internalformat==GL_RGB8) + internalformat = GL_RGB5; + } + + if (rtarget == GL_PROXY_TEXTURE_2D) { + int max1=hardext.maxsize; + proxy_width = ((width<max1)?0:width; + proxy_height = ((height<max1)?0:height; + proxy_intformat = swizzle_internalformat(&internalformat, format, type); + return; + } + // actualy bound if targetting shared TEX2D + realize_bound(glstate->texture.active, target); + + if (glstate->list.pending) { + flush(); + } else { + PUSH_IF_COMPILING(glTexImage2D); + } + +#ifdef __BIG_ENDIAN__ + if(type==GL_UNSIGNED_INT_8_8_8_8) +#else + if(type==GL_UNSIGNED_INT_8_8_8_8_REV) +#endif + type = GL_UNSIGNED_BYTE; + + if(type==GL_HALF_FLOAT) + type = GL_HALF_FLOAT_OES; + + /*if(format==GL_COMPRESSED_LUMINANCE) + format = GL_RGB;*/ // Danger from the Deep does that. + //That's odd, probably a bug (line 453 of src/texture.cpp, it should be interformat instead of format) + + GLvoid *datab = (GLvoid*)data; + + if (glstate->vao->unpack) + datab += (uintptr_t)glstate->vao->unpack->data; + + GLvoid *pixels = (GLvoid *)datab; + border = 0; //TODO: something? + noerrorShim(); + + gltexture_t *bound = glstate->texture.bound[glstate->texture.active][itarget]; + + //Special case when resizing an attached to FBO texture, taht is attached to depth and/or stencil => resizing is specific then + if(bound->binded_fbo && (bound->binded_attachment==GL_DEPTH_ATTACHMENT || bound->binded_attachment==GL_STENCIL_ATTACHMENT || bound->binded_attachment==GL_DEPTH_STENCIL_ATTACHMENT)) + { + // non null data should be handled, but need to convert then... + if(data!=NULL) + printf("LIBGL: Warning, Depth/stencil texture resized and with data\n"); + // get new size... + GLsizei nheight = (hardext.npot)?height:npot(height); + GLsizei nwidth = (hardext.npot)?width:npot(width); + bound->npot = (nheight!=height || nwidth!=width); + bound->nwidth = nwidth; + bound->nheight = nheight; + bound->width = width; + bound->height = height; + //resize depth texture of renderbuffer? + if(bound->binded_attachment==GL_DEPTH_ATTACHMENT || bound->binded_attachment==GL_DEPTH_STENCIL_ATTACHMENT) + { + if(bound->renderdepth) { + gl4es_glBindRenderbuffer(GL_RENDERBUFFER, bound->renderdepth); + gl4es_glRenderbufferStorage(GL_RENDERBUFFER, (bound->binded_attachment==GL_DEPTH_ATTACHMENT)?GL_DEPTH_COMPONENT16:GL_DEPTH24_STENCIL8, nwidth, nheight); + gl4es_glBindRenderbuffer(GL_RENDERBUFFER, 0); + } else { + gles_glTexImage2D(GL_TEXTURE_2D, 0, bound->format, bound->nwidth, bound->nheight, 0, bound->format, bound->type, NULL); + } + } + if((bound->binded_attachment==GL_STENCIL_ATTACHMENT || bound->binded_attachment==GL_DEPTH_STENCIL_ATTACHMENT) && bound->renderstencil) + { + gl4es_glBindRenderbuffer(GL_RENDERBUFFER, bound->renderstencil); + gl4es_glRenderbufferStorage(GL_RENDERBUFFER, GL_STENCIL_INDEX8, nwidth, nheight); + gl4es_glBindRenderbuffer(GL_RENDERBUFFER, 0); + } + // all done, exit + errorGL(); + return; + } + + + bound->alpha = pixel_hasalpha(format); + // fpe internal format tracking + if(glstate->fpe_state) { + switch (internalformat) { + case GL_COMPRESSED_ALPHA: + case GL_ALPHA4: + case GL_ALPHA8: + case GL_ALPHA16: + case GL_ALPHA16F: + case GL_ALPHA32F: + case GL_ALPHA: + bound->fpe_format = FPE_TEX_ALPHA; + break; + case 1: + case GL_COMPRESSED_LUMINANCE: + case GL_LUMINANCE4: + case GL_LUMINANCE8: + case GL_LUMINANCE16: + case GL_LUMINANCE16F: + case GL_LUMINANCE32F: + case GL_LUMINANCE: + bound->fpe_format = FPE_TEX_LUM; + break; + case 2: + case GL_COMPRESSED_LUMINANCE_ALPHA: + case GL_LUMINANCE4_ALPHA4: + case GL_LUMINANCE8_ALPHA8: + case GL_LUMINANCE16_ALPHA16: + case GL_LUMINANCE_ALPHA16F: + case GL_LUMINANCE_ALPHA32F: + case GL_LUMINANCE_ALPHA: + bound->fpe_format = FPE_TEX_LUM_ALPHA; + break; + case GL_COMPRESSED_INTENSITY: + case GL_INTENSITY8: + case GL_INTENSITY16: + case GL_INTENSITY16F: + case GL_INTENSITY32F: + case GL_INTENSITY: + bound->fpe_format = FPE_TEX_INTENSITY; + break; + case 3: + case GL_RED: + case GL_RG: + case GL_RGB: + case GL_RGB5: + case GL_RGB565: + case GL_RGB8: + case GL_RGB16: + case GL_RGB16F: + case GL_RGB32F: + case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: + case GL_COMPRESSED_RGB: + bound->fpe_format = FPE_TEX_RGB; + break; + /*case GL_DEPTH_COMPONENT: + case GL_DEPTH_COMPONENT16: + case GL_DEPTH_COMPONENT24: + case GL_DEPTH_COMPONENT32: + case GL_DEPTH_STENCIL: + case GL_DEPTH24_STENCIL8: + bound->fpe_format = FPE_TEX_COMPONENT;*/ + default: + bound->fpe_format = FPE_TEX_RGBA; + } + } + if (globals4es.automipmap) { + if (level>0) + if ((globals4es.automipmap==1) || (globals4es.automipmap==3) || bound->mipmap_need) { + return; // has been handled by auto_mipmap + } + else if(globals4es.automipmap==2) + bound->mipmap_need = 1; + } + if(level>0 && (bound->npot && globals4es.forcenpot)) + return; // no mipmap... + GLenum new_format = swizzle_internalformat(&internalformat, format, type); + if (level==0 || !bound->valid) { + bound->orig_internal = internalformat; + bound->internalformat = new_format; + } + // shrink checking + int mipwidth = width << level; + int mipheight = height << level; + int shrink = 0; + bound->shrink = shrink = get_shrinklevel(width, height, level); + + if(((width>>shrink)==0) && ((height>>shrink)==0)) return; // nothing to do + if (datab) { + + // implements GL_UNPACK_ROW_LENGTH + if ((glstate->texture.unpack_row_length && glstate->texture.unpack_row_length != width) + || glstate->texture.unpack_skip_pixels || glstate->texture.unpack_skip_rows) { + int imgWidth, pixelSize, dstWidth; + pixelSize = pixel_sizeof(format, type); + imgWidth = ((glstate->texture.unpack_row_length)? glstate->texture.unpack_row_length:width) * pixelSize; + GLubyte *dst = (GLubyte *)malloc(width * height * pixelSize); + pixels = (GLvoid *)dst; + dstWidth = width * pixelSize; + const GLubyte *src = (GLubyte *)datab; + src += glstate->texture.unpack_skip_pixels * pixelSize + glstate->texture.unpack_skip_rows * imgWidth; + for (int y = height; y; --y) { + memcpy(dst, src, dstWidth); + src += imgWidth; + dst += dstWidth; + } + } + + GLvoid *old = pixels; + pixels = (GLvoid *)swizzle_texture(width, height, &format, &type, internalformat, new_format, old, bound); + if (old != pixels && old != datab) { + free(old); + } + + if (bound->shrink!=0) { + switch(globals4es.texshrink) { + case 0: // nothing ??? + break; + case 1: //everything / 2 + case 11: + if ((mipwidth > 1) && (mipheight > 1)) { + GLvoid *out = pixels; + GLfloat ratiox, ratioy; + int newwidth = mipwidth; + int newheight = mipheight; + if(globals4es.texshrink==11) { + if (mipwidth>hardext.maxsize) + newwidth = hardext.maxsize; + if (mipheight>hardext.maxsize) + newheight = hardext.maxsize; + } else { + newwidth = mipwidth / 2; + newheight = mipheight / 2; + if(!newwidth) newwidth=1; + if(!newheight) newheight=1; + } + ratiox = newwidth/((float)mipwidth); + ratioy = newheight/((float)mipheight); + bound->ratiox = ratiox; + bound->ratioy = ratioy; + bound->useratio = 1; + pixel_scale(pixels, &out, width, height, newwidth, newheight, format, type); + if (out != pixels && pixels!=datab) + free(pixels); + pixels = out; + width = newwidth; + height = newheight; + bound->shrink = 1; + } + break; + default: + bound->ratiox = bound->ratioy = 1.0f; + while(shrink) { + int toshrink = (shrink>1)?2:1; + GLvoid *out = pixels; + if(toshrink==1) { + pixel_halfscale(pixels, &out, width, height, format, type); + bound->ratiox *= 0.5f; bound->ratioy *= 0.5f; + } else { + pixel_quarterscale(pixels, &out, width, height, format, type); + bound->ratiox *= 0.25f; bound->ratioy *= 0.25f; + } + if (out != pixels && pixels!=datab) + free(pixels); + pixels = out; + width = nlevel(width, toshrink); + height = nlevel(height, toshrink); + shrink-=toshrink; + } + } + } + + if (globals4es.texdump) { + pixel_to_ppm(pixels, width, height, format, type, bound->texture, glstate->texture.pack_align); + } + } else { +#ifdef TEXSTREAM + if (globals4es.texstream && (target==GL_TEXTURE_2D || target==GL_TEXTURE_RECTANGLE_ARB) && (width>=256 && height>=224) && + ((internalformat==GL_RGB) || (internalformat==3) || (internalformat==GL_RGB8) || (internalformat==GL_BGR) || (internalformat==GL_RGB5) || (internalformat==GL_RGB565)) || (globals4es.texstream==2) ) { + bound->streamingID = AddStreamed(width, height, bound->texture); + if (bound->streamingID>-1) { // success + bound->shrink = 0; // no shrink on Stream texture + bound->streamed = true; + ApplyFilterID(bound->streamingID, bound->min_filter, bound->mag_filter); + GLboolean tmp = IS_ANYTEX(glstate->enable.texture[glstate->texture.active]); + LOAD_GLES(glDisable); + LOAD_GLES(glEnable); + if (tmp) + gles_glDisable(GL_TEXTURE_2D); + ActivateStreaming(bound->streamingID); //Activate the newly created texture + format = GL_RGB; + type = GL_UNSIGNED_SHORT_5_6_5; + if (tmp) + gles_glEnable(GL_TEXTURE_STREAM_IMG); + } + glstate->bound_stream[glstate->texture.active] = 1; + } +#endif + if (!bound->streamed) + swizzle_texture(width, height, &format, &type, internalformat, new_format, NULL, bound); // convert format even if data is NULL + if (bound->shrink!=0) { + switch(globals4es.texshrink) { + case 1: //everything / 2 + case 11: + if ((mipwidth > 1) && (mipheight > 1)) { + GLfloat ratiox, ratioy; + if(globals4es.texshrink==11) { + if (mipwidth>hardext.maxsize) + ratiox = hardext.maxsize/((float)mipwidth); + else + ratiox = 1.0f; + if (mipheight>hardext.maxsize) + ratioy = hardext.maxsize/((float)mipheight); + else + ratioy = 1.0f; + } else + ratiox = ratioy = 0.5; + bound->ratiox = ratiox; + bound->ratioy = ratioy; + bound->useratio = 1; + int newwidth = width*bound->ratiox; + int newheight = height*bound->ratioy; + if(globals4es.texshrink==11 && newwidth>hardext.maxsize) newwidth=hardext.maxsize; // in case of some rounding error + if(globals4es.texshrink==11 && newheight>hardext.maxsize) newheight=hardext.maxsize; // in case of some rounding error + width = newwidth; + height = newheight; + bound->shrink = 1; + } + break; + default: + bound->ratiox = bound->ratioy = 1.0f; + while(shrink) { + int toshrink = (shrink>1)?2:1; + if(toshrink==1) { + bound->ratiox *= 0.5f; bound->ratioy *= 0.5f; + } else { + bound->ratiox *= 0.25f; bound->ratioy *= 0.25f; + } + width = nlevel(width, toshrink); + height = nlevel(height, toshrink); + shrink-=toshrink; + } + } + } + } + + /* TODO: + GL_INVALID_VALUE is generated if border is not 0. + GL_INVALID_OPERATION is generated if type is + GL_UNSIGNED_SHORT_5_6_5 and format is not GL_RGB. + + GL_INVALID_OPERATION is generated if type is one of + GL_UNSIGNED_SHORT_4_4_4_4, or GL_UNSIGNED_SHORT_5_5_5_1 + and format is not GL_RGBA. + */ + + int limitednpot = 0; + { + GLsizei nheight = (hardext.npot==3)?height:npot(height); + GLsizei nwidth = (hardext.npot==3)?width:npot(width); + bound->npot = (nheight!=height || nwidth!=width); // hardware that fully support NPOT doesn't care anyway + if(bound->npot) { + if(target==GL_TEXTURE_RECTANGLE_ARB && hardext.npot) + limitednpot=1; + else if(hardext.npot==1 && ( + (bound->base_level<=0 && bound->max_level==0) + || (globals4es.automipmap==3) + || (globals4es.automipmap==4 && width!=height) + || (globals4es.forcenpot==1) ) + && (wrap_npot(bound->wrap_s) && wrap_npot(bound->wrap_t)) ) + limitednpot=1; + else if(hardext.esversion>1 && hardext.npot==1 + && (!bound->mipmap_auto || !minmag_npot(bound->min_filter) || !minmag_npot(bound->mag_filter)) + && (wrap_npot(bound->wrap_s) && wrap_npot(bound->wrap_t)) ) + limitednpot=1; + else if(hardext.esversion>1 && hardext.npot==2 + && (wrap_npot(bound->wrap_s) && wrap_npot(bound->wrap_t)) ) + limitednpot=1; + + if(limitednpot) { + nwidth = width; + nheight = height; + } + } +#ifdef PANDORA +#define NO_1x1 +#endif +#ifdef NO_1x1 + #define MIN_SIZE 2 + if(level==0 && hardext.esversion==1) { + if(nwidth < MIN_SIZE) nwidth=MIN_SIZE; + if(nheight < MIN_SIZE) nheight=MIN_SIZE; + } + #undef MIN_SIZE +#endif + if (globals4es.texstream && bound->streamed) { + nwidth = width; + nheight = height; + } + + if(bound->npot) { + if(limitednpot && rtarget==GL_TEXTURE_2D) { + gles_glTexParameteri(rtarget, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + gles_glTexParameteri(rtarget, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + bound->wrap_t = bound->wrap_s = GL_CLAMP_TO_EDGE; + } else if (!wrap_npot(bound->wrap_s) || !wrap_npot(bound->wrap_t)) { + // resize to npot boundaries (not ideal if the wrap value is change after upload of the texture) + nwidth = npot(width); + nheight = npot(height); + float ratiox, ratioy; + ratiox = ((float)nwidth)/width; + ratioy = ((float)nheight)/height; + + GLvoid *out = pixels; + if(pixels) + pixel_scale(pixels, &out, width, height, nwidth, nheight, format, type); + if (out != pixels && pixels!=datab) + free(pixels); + pixels = out; + width = nwidth; + height = nheight; + limitednpot = 0; + + if(level==0) { + if(!bound->useratio) { + bound->useratio = 1; + if(bound->ratiox==0.f) bound->ratiox = bound->ratioy = 1.0f; + } + bound->ratiox *= ratiox; + bound->ratioy *= ratioy; + bound->npot = 0; + bound->shrink = 1; + } + } + } + // check min/mag settings for GL_FLOAT type textures (only GL_NEAREST and GL_NEAREST_MIPMAP_NEAREST is supported) + if(type==GL_FLOAT || type==GL_HALF_FLOAT_OES) { + GLenum m = minmag_float(bound->min_filter); + if(bound->min_filter != m ) { + bound->min_filter = m; + gles_glTexParameteri(rtarget, GL_TEXTURE_MIN_FILTER, m); + } + m = minmag_float(bound->mag_filter); + if(bound->mag_filter != m ) { + bound->mag_filter = m; + gles_glTexParameteri(rtarget, GL_TEXTURE_MAG_FILTER, m); + } + bound->mipmap_auto = 0; // no need to automipmap here + } + // check min/mag for NPOT with limited support + if(limitednpot && hardext.npot<2) { + GLenum m = minmag_forcenpot(bound->min_filter); + if (m!=bound->min_filter) + gles_glTexParameteri(rtarget, GL_TEXTURE_MIN_FILTER, m); + m = minmag_forcenpot(bound->mag_filter); + if (m!=bound->mag_filter) + gles_glTexParameteri(rtarget, GL_TEXTURE_MAG_FILTER, m); + bound->mipmap_auto = 0; // no need to automipmap here + } + if ((globals4es.automipmap==4) && (nwidth!=nheight)) + bound->mipmap_auto = 0; + + if (level == 0) { + bound->width = width; + bound->height = height; + bound->nwidth = nwidth; + bound->nheight = nheight; + if(target==GL_TEXTURE_RECTANGLE_ARB && hardext.esversion==2) { + bound->adjust = 0; // because this test is used in a lot of places + bound->adjustxy[0] = 1.0f/width; + bound->adjustxy[1] = 1.0f/height; + } else { + // TEXTURE_RECTANGLE could be mutualize with npot texture probably + bound->adjust = (width!=nwidth || height!=nheight); + bound->adjustxy[0] = (float)width / nwidth; + bound->adjustxy[1] = (float)height / nheight; + } + bound->compressed = false; + bound->valid = 1; + } + + int callgeneratemipmap = 0; + if (!(globals4es.texstream && bound->streamed)) { + if ((target!=GL_TEXTURE_RECTANGLE_ARB) && (globals4es.automipmap!=3) && (bound->mipmap_need || bound->mipmap_auto) && !(bound->npot && hardext.npot<2)) { + if(hardext.esversion<2) + gles_glTexParameteri( rtarget, GL_GENERATE_MIPMAP, GL_TRUE ); + else + callgeneratemipmap = 1; + } else { + //if(target!=GL_TEXTURE_RECTANGLE_ARB) gles_glTexParameteri( rtarget, GL_GENERATE_MIPMAP, GL_FALSE ); + if ((itarget!=ENABLED_CUBE_MAP && target!=GL_TEXTURE_RECTANGLE_ARB) + && (bound->mipmap_need || globals4es.automipmap==3)) { + // remove the need for mipmap... + bound->mipmap_need = 0; + /*gles_glTexParameteri(rtarget, GL_TEXTURE_MIN_FILTER, bound->min_filter); + gles_glTexParameteri(rtarget, GL_TEXTURE_MAG_FILTER, bound->mag_filter);*/ // why forcing ? + } + } + + if (height != nheight || width != nwidth) { + errorGL(); + gles_glTexImage2D(rtarget, level, format, nwidth, nheight, border, + format, type, NULL); + DBG(CheckGLError(1);) + if (pixels) { + gles_glTexSubImage2D(rtarget, level, 0, 0, width, height, + format, type, pixels); + DBG(CheckGLError(1);) + } +#ifdef NO_1x1 + if(level==0 && (width==1 && height==1 && pixels)) { + // complete the texture, juste in case it use GL_REPEAT + // also, don't keep the fact we have resized, the non-adjusted coordinates will work (as the texture is enlarged) + if(width==1) {gles_glTexSubImage2D(rtarget, level, 1, 0, width, height, format, type, pixels); nwidth=1;} + if(height==1) {gles_glTexSubImage2D(rtarget, level, 0, 1, width, height, format, type, pixels); nheight=1;} + if(width==1 && height==1) { // create a manual mipmap just in case_state + gles_glTexSubImage2D(rtarget, level, 1, 1, width, height, format, type, pixels); + gles_glTexImage2D(rtarget, 1, format, 1, 1, 0, format, type, pixels); + } + } +#endif + } else { + errorGL(); + gles_glTexImage2D(rtarget, level, format, width, height, border, + format, type, pixels); + DBG(CheckGLError(1);) + } + // check if base_level is set... and calculate lower level mipmap + if(bound->base_level == level && !(bound->max_level==level && level==0)) { + int leveln = level, nw = width, nh = height, nww=nwidth, nhh=nheight; + int pot = (nh==nhh && nw==nww); + void *ndata = pixels; + while(leveln) { + if(pixels) { + GLvoid *out = ndata; + pixel_doublescale(ndata, &out, nw, nh, format, type); + if (out != ndata && ndata!=pixels) + free(ndata); + ndata = out; + } + nw <<= 1; + nh <<= 1; + nww <<= 1; + nhh <<= 1; + --leveln; + gles_glTexImage2D(rtarget, leveln, format, nww, nhh, border, + format, type, (pot)?ndata:NULL); + if(!pot && pixels) gles_glTexSubImage2D(rtarget, leveln, 0, 0, nw, nh, + format, type, ndata); + } + if (ndata!=pixels) + free(ndata); + } + if(globals4es.automipmap==5 && !level) + bound->mipmap_done = 0; + // check if max_level is set... and calculate higher level mipmap + if(((bound->max_level == level && (level || bound->mipmap_need)) || (callgeneratemipmap && level==0) || (globals4es.automipmap==5 && level && !bound->mipmap_done)) && !(bound->max_level==bound->base_level && bound->max_level==0)) { + if(globals4es.automipmap==5 && level==1) + bound->mipmap_done = 1; + int leveln = level, nw = nwidth, nh = nheight, nww=width, nhh=height; + int pot = (nh==nhh && nw==nww); + void *ndata = pixels; + while(nw!=1 || nh!=1) { + if(pixels) { + GLvoid *out = ndata; + pixel_halfscale(ndata, &out, nww, nhh, format, type); + if (out != ndata && ndata!=pixels) + free(ndata); + ndata = out; + } + nw = nlevel(nw, 1); + nh = nlevel(nh, 1); + nww = nlevel(nww, 1); + nhh = nlevel(nhh, 1); + ++leveln; + gles_glTexImage2D(rtarget, leveln, format, nw, nh, border, + format, type, (pot)?ndata:NULL); + if(!pot && pixels) gles_glTexSubImage2D(rtarget, leveln, 0, 0, nww, nhh, + format, type, ndata); + } + if (ndata!=pixels) + free(ndata); + } + /*if (bound && bound->mipmap_need && !bound->mipmap_auto && (globals4es.automipmap!=3)) + gles_glTexParameteri( rtarget, GL_GENERATE_MIPMAP, GL_FALSE );*/ + } else { + if (pixels) + gl4es_glTexSubImage2D(rtarget, level, 0, 0, width, height, format, type, pixels); // (should never happens) updload the 1st data... + } + } + if ((target==GL_TEXTURE_2D) && globals4es.texcopydata && ((globals4es.texstream && !bound->streamed) || !globals4es.texstream)) { + if (bound->data) + bound->data=realloc(bound->data, width*height*4); + else + bound->data = malloc(width*height*4); + if (datab) { + if (!pixel_convert(pixels, &bound->data, width, height, format, type, GL_RGBA, GL_UNSIGNED_BYTE, 0, glstate->texture.unpack_align)) + printf("LIBGL: Error on pixel_convert when TEXCOPY in glTexImage2D\n"); + } else { + //memset(bound->data, 0, width*height*4); + } + } + if (pixels != datab) { + free(pixels); + } +} + +void gl4es_glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, + GLsizei width, GLsizei height, GLenum format, GLenum type, + const GLvoid *data) { + + if (glstate->list.pending) { + flush(); + } else { + PUSH_IF_COMPILING(glTexSubImage2D); + } + realize_bound(glstate->texture.active, target); + +#ifdef __BIG_ENDIAN__ + if(type==GL_UNSIGNED_INT_8_8_8_8) +#else + if(type==GL_UNSIGNED_INT_8_8_8_8_REV) +#endif + type = GL_UNSIGNED_BYTE; + + + GLvoid *datab = (GLvoid*)data; + if (glstate->vao->unpack) + datab += (uintptr_t)glstate->vao->unpack->data; + GLvoid *pixels = (GLvoid*)datab; + + const GLuint itarget = what_target(target); + const GLuint rtarget = map_tex_target(target); + + LOAD_GLES(glTexSubImage2D); + LOAD_GLES(glTexParameteri); + noerrorShim(); + DBG(printf("glTexSubImage2D on target=%s with unpack_row_length(%d), size(%d,%d), pos(%d,%d) and skip={%d,%d}, format=%s, type=%s, level=%d(base=%d, max=%d), mipmap={need=%d, auto=%d}, texture=%u\n", PrintEnum(target), glstate->texture.unpack_row_length, width, height, xoffset, yoffset, glstate->texture.unpack_skip_pixels, glstate->texture.unpack_skip_rows, PrintEnum(format), PrintEnum(type), level, glstate->texture.bound[glstate->texture.active][itarget]->base_level, glstate->texture.bound[glstate->texture.active][itarget]->max_level, glstate->texture.bound[glstate->texture.active][itarget]->mipmap_need, glstate->texture.bound[glstate->texture.active][itarget]->mipmap_auto, glstate->texture.bound[glstate->texture.active][itarget]->texture);) + if (width==0 || height==0) { + return; + } + + gltexture_t *bound = glstate->texture.bound[glstate->texture.active][itarget]; + if (globals4es.automipmap) { + if (level>0) + if ((globals4es.automipmap==1) || (globals4es.automipmap==3) || bound->mipmap_need) { + return; // has been handled by auto_mipmap + } + else + bound->mipmap_need = 1; + } + + if ((glstate->texture.unpack_row_length && glstate->texture.unpack_row_length != width) || glstate->texture.unpack_skip_pixels || glstate->texture.unpack_skip_rows) { + int imgWidth, pixelSize, dstWidth; + pixelSize = pixel_sizeof(format, type); + imgWidth = ((glstate->texture.unpack_row_length)? glstate->texture.unpack_row_length:width) * pixelSize; + GLubyte *dst = (GLubyte *)malloc(width * height * pixelSize); + pixels = (GLvoid *)dst; + dstWidth = width * pixelSize; + const GLubyte *src = (GLubyte *)datab; + src += glstate->texture.unpack_skip_pixels * pixelSize + glstate->texture.unpack_skip_rows * imgWidth; + for (int y = height; y; --y) { + memcpy(dst, src, dstWidth); + src += imgWidth; + dst += dstWidth; + } + } + + GLvoid *old = pixels; +#ifdef TEXSTREAM + if (globals4es.texstream && (bound->streamed)) { + // Optimisation, let's do convert directly to the right place... + GLvoid *tmp = GetStreamingBuffer(bound->streamingID); + tmp += (yoffset*bound->width+xoffset)*2; + if (! pixel_convert(old, &tmp, width, height, + format, type, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, bound->width, glstate->texture.pack_align)) { + printf("LIBGL: swizzle error: (%#4x, %#4x -> GL_RGB, UNSIGNED_SHORT_5_6_5)\n", + format, type); + } + format = GL_RGB; + type = GL_UNSIGNED_SHORT_5_6_5; + } else +#endif + { + if (!pixel_convert(old, &pixels, width, height, format, type, bound->inter_format, bound->inter_type, 0, glstate->texture.unpack_align)) { + printf("LIBGL: Error in pixel_convert while glTexSubImage2D\n"); + } else { + format = bound->inter_format; + type = bound->inter_type; + if(bound->inter_format!=bound->format || bound->inter_type!=bound->type) { + GLvoid* pix2 = pixels; + if (!pixel_convert(pixels, &pix2, width, height, format, type, bound->format, bound->type, 0, glstate->texture.unpack_align)) { + printf("LIBGL: Error in pixel_convert while glTexSubImage2D\n"); + } + if (pixels != pix2 && pixels != old) + free(pixels); + pixels = pix2; + format = bound->format; + type = bound->type; + } + } + + } + if (old != pixels && old != datab) + free(old); + + if (bound->shrink || bound->useratio) { + // special case for width/height == 1 + if (width==1) + width+=(xoffset%2); + if (height==1) + height+=(yoffset%2); + if ((width==1) || (height==1)) { + // nothing to do... + if (pixels != datab) + free((GLvoid *)pixels); + return; + } + // ok, now standard cases.... + old = pixels; + if(bound->useratio) { + xoffset *= bound->ratiox; + yoffset *= bound->ratioy; + int newwidth = width * bound->ratiox; + int newheight = height * bound->ratioy; + pixel_scale(pixels, &old, width, height, newwidth, newheight, format, type); + width = newwidth; + height = newheight; + if (old != pixels && pixels!=data) + free(pixels); + pixels = old; + } else { + xoffset /= 2*bound->shrink; + yoffset /= 2*bound->shrink; + int shrink = bound->shrink; + while(shrink) { + int toshrink = (shrink>1)?2:1; + GLvoid *out = pixels; + if(toshrink==1) + pixel_halfscale(pixels, &old, width, height, format, type); + else + pixel_quarterscale(pixels, &old, width, height, format, type); + if (old != pixels && pixels!=data) + free(pixels); + pixels = old; + width = nlevel(width, toshrink); + height = nlevel(height, toshrink); + shrink-=toshrink; + } + } + } + + if (globals4es.texdump) { + pixel_to_ppm(pixels, width, height, format, type, bound->texture, glstate->texture.pack_align); + } + + int callgeneratemipmap = 0; + if (level==0 && bound->mipmap_need && (!bound->mipmap_auto || hardext.esversion>1) && (globals4es.automipmap!=3) && (!globals4es.texstream || (globals4es.texstream && !bound->streamed))) + if(hardext.esversion<2) { + // ES2 doesn't have this + // gles_glTexParameteri( rtarget, GL_GENERATE_MIPMAP, GL_TRUE ); // not sure the usefullness of this call + } else { + callgeneratemipmap = 1; + } + + if (globals4es.texstream && bound->streamed) { +/* // copy the texture to the buffer + void* tmp = GetStreamingBuffer(bound->streamingID); + for (int yy=0; yywidth+xoffset)*2, pixels+(yy*width)*2, width*2); + }*/ + } else { + errorGL(); + gles_glTexSubImage2D(rtarget, level, xoffset, yoffset, + width, height, format, type, pixels); + DBG(CheckGLError(1);) + // check if base_level is set... and calculate lower level mipmap + if(bound->base_level == level && !(bound->max_level==level && level==0)) { + int leveln = level, nw = width, nh = height, xx=xoffset, yy=yoffset; + void *ndata = pixels; + while(leveln) { + if(pixels) { + GLvoid *out = ndata; + pixel_doublescale(ndata, &out, nw, nh, format, type); + if (out != ndata && ndata!=pixels) + free(ndata); + ndata = out; + } + nw <<= 1; + nh <<= 1; + xx <<= 1; + yy <<= 1; + --leveln; + gles_glTexSubImage2D(rtarget, leveln, xx, yy, nw, nh, + format, type, ndata); + } + if (ndata!=pixels) + free(ndata); + } + // check if max_level is set... and calculate higher level mipmap + if(((((bound->max_level == level) && (level || bound->mipmap_need)) && (globals4es.automipmap!=3) && (bound->mipmap_need!=0)) || (callgeneratemipmap && level==0)) && !(bound->max_level==bound->base_level && bound->base_level==0)) { + int leveln = level, nw = width, nh = height, xx=xoffset, yy=yoffset; + void *ndata = pixels; + while(nw!=1 || nh!=1) { + if(pixels) { + GLvoid *out = ndata; + pixel_halfscale(ndata, &out, nw, nh, format, type); + if (out != ndata && ndata!=pixels) + free(ndata); + ndata = out; + } + nw = nlevel(nw, 1); + nh = nlevel(nh, 1); + xx = xx>>1; + yy = yy>>1; + ++leveln; + gles_glTexSubImage2D(rtarget, leveln, xx, yy, nw, nh, + format, type, ndata); + } + if (ndata!=pixels) + free(ndata); + } + } + + /*if (bound->mipmap_need && !bound->mipmap_auto && (globals4es.automipmap!=3) && (!globals4es.texstream || (globals4es.texstream && !bound->streamed))) + gles_glTexParameteri( rtarget, GL_GENERATE_MIPMAP, GL_FALSE );*/ + + if ((target==GL_TEXTURE_2D) && globals4es.texcopydata && ((globals4es.texstream && !bound->streamed) || !globals4es.texstream)) { + //printf("*texcopy* glTexSubImage2D, xy=%i,%i, size=%i,%i=>%i,%i, format=%s, type=%s, tex=%u\n", xoffset, yoffset, width, height, bound->width, bound->height, PrintEnum(format), PrintEnum(type), bound->glname); + GLvoid * tmp = bound->data; + tmp += (yoffset*bound->width + xoffset)*4; + if (!pixel_convert(pixels, &tmp, width, height, format, type, GL_RGBA, GL_UNSIGNED_BYTE, bound->width, glstate->texture.unpack_align)) + printf("LIBGL: Error on pixel_convert while TEXCOPY in glTexSubImage2D\n"); + } + + if (pixels != datab) + free((GLvoid *)pixels); +} + +// 1d stubs +void gl4es_glTexImage1D(GLenum target, GLint level, GLint internalFormat, + GLsizei width, GLint border, + GLenum format, GLenum type, const GLvoid *data) { + + // TODO: maybe too naive to force GL_TEXTURE_2D here? + gl4es_glTexImage2D(GL_TEXTURE_1D, level, internalFormat, width, 1, + border, format, type, data); +} +void gl4es_glTexSubImage1D(GLenum target, GLint level, GLint xoffset, + GLsizei width, GLenum format, GLenum type, + const GLvoid *data) { + + gl4es_glTexSubImage2D(GL_TEXTURE_1D, level, xoffset, 0, + width, 1, format, type, data); +} +void gl4es_glCopyTexImage1D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, + GLsizei width, GLint border) { + gl4es_glCopyTexImage2D(GL_TEXTURE_1D, level, internalformat, x, y, width, 1, border); + +} + +void gl4es_glCopyTexSubImage1D(GLenum target, GLint level, GLint xoffset, GLint x, GLint y, + GLsizei width) { + gl4es_glCopyTexSubImage2D(GL_TEXTURE_1D, level, xoffset, 0, x, y, width, 1); +} + +void gl4es_glCopyTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, + GLint x, GLint y, GLsizei width, GLsizei height) { + gl4es_glCopyTexSubImage2D(GL_TEXTURE_3D, level, xoffset, yoffset, x, y, width, height); +} + + + + +// 3d stubs +void gl4es_glTexImage3D(GLenum target, GLint level, GLint internalFormat, + GLsizei width, GLsizei height, GLsizei depth, GLint border, + GLenum format, GLenum type, const GLvoid *data) { + + // TODO: maybe too naive to force GL_TEXTURE_2D here? + gl4es_glTexImage2D(GL_TEXTURE_3D, level, internalFormat, width, height, + border, format, type, data); +} +void gl4es_glTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, + GLsizei width, GLsizei height, GLsizei depth, GLenum format, + GLenum type, const GLvoid *data) { + + gl4es_glTexSubImage2D(GL_TEXTURE_3D, level, xoffset, yoffset, + width, height, format, type, data); +} + +void gl4es_glPixelStorei(GLenum pname, GLint param) { + DBG(printf("glPixelStorei(%s, %d)\n", PrintEnum(pname), param);) + // TODO: add to glGetIntegerv? + + LOAD_GLES(glPixelStorei); + noerrorShim(); + switch (pname) { + case GL_UNPACK_ROW_LENGTH: + glstate->texture.unpack_row_length = param; + return; + case GL_UNPACK_SKIP_PIXELS: + glstate->texture.unpack_skip_pixels = param; + return; + case GL_UNPACK_SKIP_ROWS: + glstate->texture.unpack_skip_rows = param; + return; + case GL_UNPACK_LSB_FIRST: + glstate->texture.unpack_lsb_first = param; + return; + case GL_UNPACK_IMAGE_HEIGHT: + glstate->texture.unpack_image_height = param; + return; + case GL_UNPACK_SWAP_BYTES: + case GL_PACK_SWAP_BYTES: + // Fake... TODO? + //glstate->texture.unpack_lsb_first = param; + return; + case GL_PACK_ROW_LENGTH: + glstate->texture.pack_row_length = param; + return; + case GL_PACK_SKIP_PIXELS: + glstate->texture.pack_skip_pixels = param; + return; + case GL_PACK_SKIP_ROWS: + glstate->texture.pack_skip_rows = param; + return; + case GL_PACK_LSB_FIRST: + glstate->texture.pack_lsb_first = param; + return; + case GL_PACK_IMAGE_HEIGHT: + glstate->texture.pack_image_height = param; + return; + case GL_PACK_ALIGNMENT: + if(glstate->texture.pack_align==param) + return; + if (param!=1 && param!=2 && param!=4 && param!=8) { + errorShim(GL_INVALID_VALUE); + return; + } + glstate->texture.pack_align=param; + break; + case GL_UNPACK_ALIGNMENT: + if(glstate->texture.unpack_align==param) + return; + if (param!=1 && param!=2 && param!=4 && param!=8) { + errorShim(GL_INVALID_VALUE); + return; + } + glstate->texture.unpack_align=param; + break; + } + errorGL(); + gles_glPixelStorei(pname, param); +} + +GLboolean gl4es_glIsTexture(GLuint texture) { + DBG(printf("glIsTexture(%d):", texture);) + if(!glstate) {DBG(printf("GL_FALSE\n");) return GL_FALSE;} + noerrorShim(); + if (!texture) { + DBG(printf("%s\n", glstate->texture.zero->valid?"GL_TRUE":"GL_FALSE");) + return glstate->texture.zero->valid; + } + int ret; + khint_t k; + khash_t(tex) *list = glstate->texture.list; + if (! list) { + DBG(printf("GL_FALSE\n");) + return GL_FALSE; + } + k = kh_get(tex, list, texture); + gltexture_t *tex = NULL; + if (k == kh_end(list)) { + DBG(printf("GL_FALSE\n");) + return GL_FALSE; + } + DBG(printf("GL_TRUE\n");) + return GL_TRUE; +} + +gltexture_t* gl4es_getCurrentTexture(GLenum target) { + GLuint itarget = what_target(target); + return glstate->texture.bound[glstate->texture.active][itarget]; +} +gltexture_t* gl4es_getTexture(GLenum target, GLuint texture) { + // Get a texture based on glID + gltexture_t* tex = NULL; + if (texture == 0) return glstate->texture.zero; // texture 0 is a texture mostly like any other... it is not "unbind" texture in fact, but it's not shared + int ret; + khint_t k; + khash_t(tex) *list = glstate->texture.list; + k = kh_get(tex, list, texture); + + if (k == kh_end(list)){ + LOAD_GLES(glGenTextures); + k = kh_put(tex, list, texture, &ret); + tex = kh_value(list, k) = malloc(sizeof(gltexture_t)); + memset(tex, 0, sizeof(gltexture_t)); + tex->texture = texture; + if (texture) + gles_glGenTextures(1, &tex->glname); + else + tex->glname = 0; // special case for texture n# 0 + DBG(printf("getTexture(%s, %u), failed, creating texture %u\n", PrintEnum(target), texture, tex->glname);) + tex->target = target; + tex->adjustxy[0] = tex->adjustxy[1] = 1.f; + tex->mipmap_auto = (globals4es.automipmap==1); + tex->mipmap_need = (globals4es.automipmap==1)?1:0; + tex->streamingID = -1; + tex->base_level = -1; + tex->max_level = -1; + tex->alpha = true; + tex->min_filter = GL_NEAREST_MIPMAP_LINEAR; //(globals4es.automipmap==1)?GL_NEAREST_MIPMAP_LINEAR:GL_LINEAR; + tex->mag_filter = GL_LINEAR; + tex->wrap_s = tex->wrap_t = (globals4es.defaultwrap?0:GL_REPEAT); + tex->fpe_format = FPE_TEX_RGBA; + tex->format = GL_RGBA; + tex->type = GL_UNSIGNED_BYTE; + tex->inter_format = GL_RGBA; + tex->inter_type = GL_UNSIGNED_BYTE; + } else { + tex = kh_value(list, k); + } + return tex; +} +void gl4es_glBindTexture(GLenum target, GLuint texture) { + noerrorShim(); + DBG(printf("glBindTexture(%s, %u), active=%i, client=%i, list.active=%p (compiling=%d, pending=%d)\n", PrintEnum(target), texture, glstate->texture.active, glstate->texture.client, glstate->list.active, glstate->list.compiling, glstate->list.pending);) + if ((target!=GL_PROXY_TEXTURE_2D) && glstate->list.compiling && glstate->list.active && !glstate->list.pending) { + // check if already a texture binded, if yes, create a new list + NewStage(glstate->list.active, STAGE_BINDTEX); + rlBindTexture(glstate->list.active, target, texture); + } else { + int tex_changed = 1; + gltexture_t *tex = NULL; + const GLuint itarget = what_target(target); + + tex = gl4es_getTexture(target, texture); + if (glstate->texture.bound[glstate->texture.active][itarget] != tex) { + if(glstate->list.pending) flush(); + tex_changed = glstate->texture.active+1; + glstate->texture.bound[glstate->texture.active][itarget] = tex; + } + LOAD_GLES(glBindTexture); + switch(target) { + // cube map are bounded immediatly, other are defered and will be applied with realize_bound or realize_textures + case GL_TEXTURE_CUBE_MAP: + case GL_TEXTURE_CUBE_MAP_POSITIVE_X: + case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: + case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: + case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: + case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: + case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: + gles_glBindTexture(target, tex?tex->glname:0); + break; + case GL_TEXTURE_1D: + case GL_TEXTURE_2D: + case GL_TEXTURE_3D: + case GL_TEXTURE_RECTANGLE_ARB: + if (glstate->bound_changed < glstate->texture.active+1) + glstate->bound_changed = glstate->texture.active+1; + if (glstate->fpe_state && glstate->fpe_bound_changed < glstate->texture.active+1) + glstate->fpe_bound_changed = glstate->texture.active+1; + break; + } + } +} + +// TODO: also glTexParameterf(v)? +void gl4es_glTexParameteri(GLenum target, GLenum pname, GLint param) { + DBG(printf("glTexParameteri(%s, %s, %d(%s))\n", PrintEnum(target), PrintEnum(pname), param, PrintEnum(param));) + if(!glstate->list.pending) { + PUSH_IF_COMPILING(glTexParameteri); + } + LOAD_GLES(glTexParameteri); + noerrorShim(); + const GLint itarget = what_target(target); + const GLuint rtarget = map_tex_target(target); + gltexture_t *texture = glstate->texture.bound[glstate->texture.active][itarget]; + switch (pname) { + case GL_TEXTURE_MIN_FILTER: + case GL_TEXTURE_MAG_FILTER: + switch (param) { + case GL_NEAREST_MIPMAP_NEAREST: + case GL_NEAREST_MIPMAP_LINEAR: + case GL_LINEAR_MIPMAP_NEAREST: + case GL_LINEAR_MIPMAP_LINEAR: + texture->mipmap_need = true; + if ((globals4es.automipmap==3) || ((globals4es.automipmap==1) && (texture->mipmap_auto==0))) + switch (param) { + case GL_NEAREST_MIPMAP_NEAREST: + case GL_NEAREST_MIPMAP_LINEAR: + param = GL_NEAREST; + break; + case GL_LINEAR_MIPMAP_NEAREST: + case GL_LINEAR_MIPMAP_LINEAR: + param = GL_LINEAR; + break; + } + } + if(texture->valid && (texture->type==GL_FLOAT || texture->type==GL_HALF_FLOAT_OES)) { + // FLOAT textures have limited mipmap support in GLES2 + param = minmag_float(param); + } + if(texture->valid && (texture->npot && globals4es.forcenpot)) { + // need to remove MIPMAP for npot if not supported in hardware + param = minmag_forcenpot(param); + } + if (pname==GL_TEXTURE_MIN_FILTER) { if(texture->min_filter == param) return; texture->min_filter = param; } + if (pname==GL_TEXTURE_MAG_FILTER) { if(texture->mag_filter == param) return; texture->mag_filter = param; } + break; + case GL_TEXTURE_WRAP_S: + case GL_TEXTURE_WRAP_T: + switch (param) { + case GL_CLAMP: + case GL_CLAMP_TO_BORDER: + param = GL_CLAMP_TO_EDGE; + break; + case GL_REPEAT: + case GL_MIRRORED_REPEAT_OES: + if(globals4es.defaultwrap==2 && hardext.npot<3 && !texture->valid) + param = GL_CLAMP_TO_EDGE; + else if(hardext.esversion>1 && hardext.npot<3 && texture->valid + && texture->npot) { + // should "upgrade" the texture to POT size... + //printf("Warning, REPEAT / MIRRORED_REPEAT on NPOT texture\n"); + param = GL_CLAMP_TO_EDGE; // repeat is not support on NPOT with limited_npot + } + break; + } + + if (pname==GL_TEXTURE_WRAP_S) {if (texture->wrap_s == param) return; texture->wrap_s = param; } + if (pname==GL_TEXTURE_WRAP_T) {if (texture->wrap_t == param) return; texture->wrap_t = param; } + break; + case GL_TEXTURE_WRAP_R: + // ignore it on GLES... + return; + case GL_TEXTURE_COMPARE_MODE: + texture->compare = param; // TODO, better traking... + return; + case GL_TEXTURE_MAX_LEVEL: + if (texture) + texture->max_level = param; + return; // not on GLES + case GL_TEXTURE_BASE_LEVEL: + texture->base_level = param; + return; // not on GLES + case GL_TEXTURE_MIN_LOD: + case GL_TEXTURE_MAX_LOD: + case GL_TEXTURE_LOD_BIAS: + return; // not on GLES + case GL_GENERATE_MIPMAP: + if(globals4es.automipmap==3) + return; // no mipmap, so no need to generate any + if(texture->mipmap_auto == ((param)?1:0)) + return; // same value... + texture->mipmap_auto = (param)?1:0; + if(hardext.esversion>1) { + if(texture->valid) { + // force regeneration, if posssible + if(glstate->list.pending) flush(); + realize_bound(glstate->texture.active, target); + LOAD_GLES2_OR_OES(glGenerateMipmap); + gl4es_glGenerateMipmap(rtarget); + } + return; + } + break; // fallback to calling actual glTexParameteri + case GL_TEXTURE_MAX_ANISOTROPY: + if(!hardext.aniso) { + errorShim(GL_INVALID_ENUM); + return; + } + if(param<0){ + errorShim(GL_INVALID_VALUE); + return; + } + if(param>hardext.aniso) param=hardext.aniso; + texture->aniso = param; + break; + } + if(glstate->list.pending) flush(); + realize_bound(glstate->texture.active, target); + gles_glTexParameteri(rtarget, pname, param); + errorGL(); +} + +void gl4es_glTexParameterf(GLenum target, GLenum pname, GLfloat param) { + gl4es_glTexParameteri(target, pname, param); +} + +void gl4es_glTexParameterfv(GLenum target, GLenum pname, const GLfloat * params) { + DBG(printf("glTexParameterfv(%s, %s, %p {%f...})\n", PrintEnum(target), PrintEnum(pname), params, params[0]);) + switch (pname) { + case GL_TEXTURE_MIN_FILTER: + case GL_TEXTURE_MAG_FILTER: + case GL_TEXTURE_WRAP_S: + case GL_TEXTURE_WRAP_T: + case GL_TEXTURE_WRAP_R: + case GL_TEXTURE_COMPARE_MODE: + case GL_TEXTURE_MAX_LEVEL: + case GL_TEXTURE_BASE_LEVEL: + case GL_TEXTURE_MIN_LOD: + case GL_TEXTURE_MAX_LOD: + case GL_TEXTURE_LOD_BIAS: + case GL_GENERATE_MIPMAP: + case GL_TEXTURE_MAX_ANISOTROPY: + gl4es_glTexParameteri(target, pname, params[0]); + return; + case GL_TEXTURE_BORDER_COLOR: + // not supported on GLES, + noerrorShim(); + return; + } + PUSH_IF_COMPILING(glTexParameterfv); + realize_bound(glstate->texture.active, target); + LOAD_GLES(glTexParameterfv); + errorGL(); + const GLuint rtarget = map_tex_target(target); + gles_glTexParameterfv(rtarget, pname, params); + +} + +void gl4es_glTexParameteriv(GLenum target, GLenum pname, const GLint * params) { + DBG(printf("glTexParameteriv(%s, %s, %p {%d...})\n", PrintEnum(target), PrintEnum(pname), params, params[0]);) + switch (pname) { + case GL_TEXTURE_MIN_FILTER: + case GL_TEXTURE_MAG_FILTER: + case GL_TEXTURE_WRAP_S: + case GL_TEXTURE_WRAP_T: + case GL_TEXTURE_WRAP_R: + case GL_TEXTURE_COMPARE_MODE: + case GL_TEXTURE_MAX_LEVEL: + case GL_TEXTURE_BASE_LEVEL: + case GL_TEXTURE_MIN_LOD: + case GL_TEXTURE_MAX_LOD: + case GL_TEXTURE_LOD_BIAS: + case GL_GENERATE_MIPMAP: + case GL_TEXTURE_MAX_ANISOTROPY: + gl4es_glTexParameteri(target, pname, params[0]); + return; + case GL_TEXTURE_BORDER_COLOR: + // not supported on GLES, + noerrorShim(); + return; + } + PUSH_IF_COMPILING(glTexParameteriv); + realize_bound(glstate->texture.active, target); + LOAD_GLES(glTexParameteriv); + errorGL(); + const GLuint rtarget = map_tex_target(target); + gles_glTexParameteriv(rtarget, pname, params); +} + +void gl4es_glDeleteTextures(GLsizei n, const GLuint *textures) { + DBG(printf("glDeleteTextures(%d, %p {%d...})\n", n, textures, n?textures[0]:-1);) + if(!glstate) return; + FLUSH_BEGINEND; + + noerrorShim(); + LOAD_GLES(glDeleteTextures); + khash_t(tex) *list = glstate->texture.list; + if (list) { + khint_t k; + gltexture_t *tex; + for (int i = 0; i < n; i++) { + GLuint t = textures[i]; + if(!t) continue; // skip texture 0 + k = kh_get(tex, list, t); + if (k != kh_end(list)) { + tex = kh_value(list, k); + int a; + for (a=0; atexture.bound[a][j]) { + glstate->texture.bound[a][j] = glstate->texture.zero; + found = 1; + } + if(glstate->actual_tex2d[a]==tex->glname) { + glstate->actual_tex2d[a] = 0; + found = 1; + } + if(found) + glstate->bound_changed = a+1; + } + gles_glDeleteTextures(1, &tex->glname); + // check if renderbuffer where associeted + if(tex->binded_fbo) { + if(tex->renderdepth) + gl4es_glDeleteRenderbuffers(1, &tex->renderdepth); + if(tex->renderstencil) + gl4es_glDeleteRenderbuffers(1, &tex->renderstencil); + } + errorGL(); +#ifdef TEXSTREAM + if (globals4es.texstream && tex->streamed) + FreeStreamed(tex->streamingID); +#endif + #if 1 + kh_del(tex, list, k); + if (tex->data) free(tex->data); + free(tex); + #else + tex->glname = tex->texture; + tex->streamed = false; + tex->streamingID = -1; + if (tex->data) free(tex->data); + tex->data = NULL; + #endif + } + } + } +} + +void gl4es_glGenTextures(GLsizei n, GLuint * textures) { + DBG(printf("glGenTextures(%d, %p)\n", n, textures);) + if (n<=0) + return; + if (glstate->list.pending) flush(); + LOAD_GLES(glGenTextures); + gles_glGenTextures(n, textures); + errorGL(); + // now, add all the textures to the list + int ret; + khint_t k; + khash_t(tex) *list = glstate->texture.list; + + for (int i=0; i textures[%d] = %u\n", i, textures[i]);) + gltexture_t *tex = NULL; + if (k == kh_end(list)){ + k = kh_put(tex, list, textures[i], &ret); + tex = kh_value(list, k) = malloc(sizeof(gltexture_t)); + memset(tex, 0, sizeof(gltexture_t)); + tex->texture = textures[i]; + tex->glname = textures[i]; + tex->adjustxy[0] = tex->adjustxy[1] = 1.f; + tex->mipmap_auto = (globals4es.automipmap==1); + tex->mipmap_need = (globals4es.automipmap==1)?1:0; + tex->streamingID = -1; + tex->base_level = -1; + tex->max_level = -1; + tex->alpha = true; + tex->min_filter = GL_NEAREST_MIPMAP_LINEAR; //(globals4es.automipmap==1)?GL_NEAREST_MIPMAP_LINEAR:GL_LINEAR; + tex->mag_filter = GL_LINEAR; + tex->wrap_s = tex->wrap_t = (globals4es.defaultwrap?0:GL_REPEAT); + tex->fpe_format = FPE_TEX_RGBA; + tex->format = GL_RGBA; + tex->type = GL_UNSIGNED_BYTE; + tex->inter_format = GL_RGBA; + tex->inter_type = GL_UNSIGNED_BYTE; + } else { + tex = kh_value(list, k); + // in case of no delete here... + if (tex->glname==0) + tex->glname = tex->texture; + } + } +} + +GLboolean gl4es_glAreTexturesResident(GLsizei n, const GLuint *textures, GLboolean *residences) { + noerrorShim(); + return true; +} + +void gl4es_glGetTexLevelParameteriv(GLenum target, GLint level, GLenum pname, GLint *params) { + DBG(printf("glGetTexLevelParameteriv(%s, %d, %s, %p)\n", PrintEnum(target), level, PrintEnum(pname), params);) + // simplification: (mostly) not taking "target" into account here + if (glstate->list.pending) flush(); + *params = 0; + noerrorShim(); + const GLuint itarget = what_target(target); + const GLuint rtarget = map_tex_target(target); + gltexture_t* bound = glstate->texture.bound[glstate->texture.active][itarget]; + switch (pname) { + case GL_TEXTURE_WIDTH: + if (rtarget==GL_PROXY_TEXTURE_2D) + (*params) = nlevel(proxy_width,level); + else { + (*params) = nlevel((bound)?bound->width:hardext.maxsize,level); + if(level && !(bound->mipmap_auto || bound->mipmap_need)) + (*params) = 0; // Mipmap level not loaded + } + break; + case GL_TEXTURE_HEIGHT: + if (rtarget==GL_PROXY_TEXTURE_2D) + (*params) = nlevel(proxy_height,level); + else { + (*params) = nlevel((bound)?bound->height:hardext.maxsize,level); + if(level && !(bound->mipmap_auto || bound->mipmap_need)) + (*params) = 0; // Mipmap level not loaded + } + break; + case GL_TEXTURE_INTERNAL_FORMAT: + if (rtarget==GL_PROXY_TEXTURE_2D) + (*params) = proxy_intformat; + else { + if (bound->compressed) + (*params) = bound->internalformat; + else { + if((bound->orig_internal==GL_COMPRESSED_RGB) || (bound->orig_internal==GL_COMPRESSED_RGBA)) { + if(bound->orig_internal==GL_COMPRESSED_RGB) + *(params) = GL_COMPRESSED_RGB_S3TC_DXT1_EXT; + else + *(params) = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; + } else + (*params) = bound->internalformat; + } + } + break; + case GL_TEXTURE_DEPTH: + (*params) = 0; + break; + case GL_TEXTURE_RED_TYPE: + case GL_TEXTURE_GREEN_TYPE: + case GL_TEXTURE_BLUE_TYPE: + case GL_TEXTURE_ALPHA_TYPE: + case GL_TEXTURE_DEPTH_TYPE: + (*params) = GL_FLOAT; + break; + case GL_TEXTURE_RED_SIZE: + case GL_TEXTURE_GREEN_SIZE: + case GL_TEXTURE_BLUE_SIZE: + case GL_TEXTURE_ALPHA_SIZE: + (*params) = 8; + break; + case GL_TEXTURE_DEPTH_SIZE: + (*params) = 0; + break; + case GL_TEXTURE_COMPRESSED: + if (bound->compressed) + (*params) = GL_TRUE; + else { + if((bound->orig_internal==GL_COMPRESSED_RGB) || (bound->orig_internal==GL_COMPRESSED_RGBA)) + (*params) = GL_TRUE; + else + (*params) = GL_FALSE; + } + break; + case GL_TEXTURE_COMPRESSED_IMAGE_SIZE: + if((bound->orig_internal==GL_COMPRESSED_RGB) || (bound->orig_internal==GL_COMPRESSED_RGBA)) { + int w = nlevel((bound->width>>level),2); //DXT works on 4x4 blocks... + int h = nlevel((bound->height>>level),2); + w<<=2; h<<=2; + if (bound->orig_internal==GL_COMPRESSED_RGB) //DXT1, 64bits (i.e. size=8) for a 4x4 block + (*params) = (w*h)/2; + else //DXT5, 64+64 (i.e. size = 16) for a 4x4 block + (*params) = w*h; + } else + (*params) = bound->width*bound->height*4; + break; + case GL_TEXTURE_BORDER: + (*params) = 0; + break; + case GL_TEXTURE_INTENSITY_SIZE: + if(bound) + (*params) = 32; // is it correct ? GLES doesn't store Intensity... Shall I return 0 instead? Or fake it and return 8? + else + (*params) = 0; + break; + case GL_TEXTURE_LUMINANCE_SIZE: + (*params) = (bound->orig_internal==GL_LUMINANCE || bound->orig_internal==GL_LUMINANCE_ALPHA)?8:0; + break; + case GL_TEXTURE_MAX_ANISOTROPY: + if(!hardext.aniso) + errorShim(GL_INVALID_ENUM); + else + (*params) = bound->aniso; + break; + case GL_TEXTURE_MAX_LEVEL: + if(!bound->valid || bound->max_level==-1) + (*params) = 1000; + else + (*params) = bound->max_level; + break; + case GL_TEXTURE_WRAP_S: + if(!bound->valid) + (*params) = GL_REPEAT; + else + (*params) = bound->wrap_s?bound->wrap_s:GL_REPEAT; + break; + case GL_TEXTURE_WRAP_T: + if(!bound->valid) + (*params) = GL_REPEAT; + else + (*params) = bound->wrap_t?bound->wrap_t:GL_REPEAT; + break; + case GL_TEXTURE_COMPARE_MODE: + (*params) = bound->compare; // GL_NONE is 0x0 + break; + default: + errorShim(GL_INVALID_ENUM); //Wrong here... + printf("Stubbed glGetTexLevelParameteriv(%s, %i, %s, %p)\n", PrintEnum(target), level, PrintEnum(pname), params); + } +} + +void gl4es_glGetTexImage(GLenum target, GLint level, GLenum format, GLenum type, GLvoid * img) { + DBG(printf("glGetTexImage(%s, %i, %s, %s, %p)\n", PrintEnum(target), level, PrintEnum(format), PrintEnum(type), img);) + if (glstate->list.pending) { + flush(); + } + const GLuint itarget = what_target(target); + + realize_bound(glstate->texture.active, target); + + gltexture_t* bound = glstate->texture.bound[glstate->texture.active][itarget]; + int width = bound->width; + int height = bound->height; + int nwidth = bound->nwidth; + int nheight = bound->nheight; + int shrink = bound->shrink; + if (level != 0) { + //printf("STUBBED glGetTexImage with level=%i\n", level); + void* tmp = malloc(width*height*pixel_sizeof(format, type)); // tmp space... + void* tmp2; + gl4es_glGetTexImage(map_tex_target(target), 0, format, type, tmp); + for (int i=0; iglname, width, height);) + + GLvoid *dst = img; + if (glstate->vao->pack) + dst += (uintptr_t)glstate->vao->pack->data; +#ifdef TEXSTREAM + if (globals4es.texstream && bound->streamed) { + noerrorShim(); + pixel_convert(GetStreamingBuffer(bound->streamingID), &dst, width, height, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, format, type, 0, glstate->texture.unpack_align); + readfboEnd(); + return; + } +#endif + if (globals4es.texcopydata && bound->data) { + //printf("texcopydata* glGetTexImage(0x%04X, %d, 0x%04x, 0x%04X, %p)\n", target, level, format, type, img); + noerrorShim(); + if (!pixel_convert(bound->data, &dst, width, height, GL_RGBA, GL_UNSIGNED_BYTE, format, type, 0, glstate->texture.pack_align)) + printf("LIBGL: Error on pixel_convert while glGetTexImage\n"); + } else { + // Setup an FBO the same size of the texture + GLuint oldBind = bound->glname; + GLuint old_fbo = glstate->fbo.current_fb->id; + GLuint fbo; + + // if the texture is not RGBA or RGB or ALPHA, the "just attach texture to the fbo" trick will not work, and a full Blit has to be done + if((bound->format==GL_RGBA || bound->format==GL_RGB || (bound->format==GL_BGRA && hardext.bgra8888) || bound->format==GL_ALPHA) && (shrink==0)) { + gl4es_glGenFramebuffers(1, &fbo); + gl4es_glBindFramebuffer(GL_FRAMEBUFFER_OES, fbo); + gl4es_glFramebufferTexture2D(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_TEXTURE_2D, oldBind, 0); + // Read the pixels! + gl4es_glReadPixels(0, nheight-height, width, height, format, type, img); // using "full" version with conversion of format/type + gl4es_glBindFramebuffer(GL_FRAMEBUFFER_OES, old_fbo); + gl4es_glDeleteFramebuffers(1, &fbo); + noerrorShim(); + } else { + gl4es_glGenFramebuffers(1, &fbo); + gl4es_glBindFramebuffer(GL_FRAMEBUFFER_OES, fbo); + GLuint temptex; + gl4es_glGenTextures(1, &temptex); + gl4es_glBindTexture(GL_TEXTURE_2D, temptex); + gl4es_glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, nwidth<list.pending) { + /* if(glstate->texture.active == tmu) { + noerrorShim(); + return; + } + flush();*/ + } else if (glstate->list.active) { + NewStage(glstate->list.active, STAGE_ACTIVETEX); + rlActiveTexture(glstate->list.active, texture); + return; + } + + if ((tmu<0) || (tmu>=hardext.maxtex)) { + errorShim(GL_INVALID_ENUM); + return; + } + if(glstate->texture.active == tmu) { + noerrorShim(); + return; + } + glstate->texture.active = tmu; + noerrorShim(); +} + +void gl4es_glClientActiveTexture( GLenum texture ) { + DBG(printf("glClientActiveTexture(%s)\n", PrintEnum(texture));) + int tmu = texture - GL_TEXTURE0; + if ((tmu<0) || (tmu >= hardext.maxtex)) { + errorShim(GL_INVALID_ENUM); + return; + } + // try to speed-up things... + if (glstate->texture.client == tmu) + return; + if (glstate->list.pending) flush(); + glstate->texture.client = tmu; + LOAD_GLES_FPE(glClientActiveTexture); + gles_glClientActiveTexture(texture); + errorGL(); +} + +void gl4es_glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid * data) { + DBG(printf("glReadPixels(%i, %i, %i, %i, %s, %s, 0x%p)\n", x, y, width, height, PrintEnum(format), PrintEnum(type), data);) + if (glstate->list.pending) { + flush(); + } + if (glstate->list.compiling && glstate->list.active) { + errorShim(GL_INVALID_OPERATION); + return; // never in list + } + LOAD_GLES(glReadPixels); + errorGL(); + GLvoid* dst = data; + if (glstate->vao->pack) + dst += (uintptr_t)glstate->vao->pack->data; + + readfboBegin(); + if ((format == GL_RGBA && type == GL_UNSIGNED_BYTE) // should not use default GL_RGBA on Pandora as it's very slow... + || (format == glstate->readf && type == glstate->readt) // use the IMPLEMENTATION_READ too... + || (format == GL_DEPTH_COMPONENT && (type == GL_FLOAT || type==GL_HALF_FLOAT))) // this one will probably fail, as DEPTH is not readable on most GLES hardware + { + // easy passthru + gles_glReadPixels(x, y, width, height, format, type, dst); + readfboEnd(); + return; + } + // grab data in GL_RGBA format + int use_bgra = 0; + if(glstate->readf==GL_BGRA && glstate->readt==GL_UNSIGNED_BYTE) + use_bgra = 1; // if IMPLEMENTATION_READ is BGRA, then use it as it's probably faster then RGBA. + GLvoid *pixels = malloc(width*height*4); + gles_glReadPixels(x, y, width, height, use_bgra?GL_BGRA:GL_RGBA, GL_UNSIGNED_BYTE, pixels); + if (! pixel_convert(pixels, &dst, width, height, + use_bgra?GL_BGRA:GL_RGBA, GL_UNSIGNED_BYTE, format, type, 0,glstate->texture.pack_align)) { + LOGE("LIBGL: ReadPixels error: (%s, UNSIGNED_BYTE -> %s, %s )\n", + PrintEnum(use_bgra?GL_BGRA:GL_RGBA), PrintEnum(format), PrintEnum(type)); + } + free(pixels); + readfboEnd(); + return; +} + +void gl4es_glCopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, + GLint x, GLint y, GLsizei width, GLsizei height) { + const GLuint itarget = what_target(target); + // WARNING: It seems glColorMask has an impact on what channel are actualy copied by this. The crude glReadPixel / glTexSubImage cannot emulate that, and proper emulation will take need 2 read pixels. + // And using the real glCopyTexSubImage2D needs that the FrameBuffer were data are read is compatible with the Texture it's copied to... + DBG(printf("glCopyTexSubImage2D(%s, %i, %i, %i, %i, %i, %i, %i), bounded texture=%u format/type=%s, %s\n", PrintEnum(target), level, xoffset, yoffset, x, y, width, height, (glstate->texture.bound[glstate->texture.active][itarget])?glstate->texture.bound[glstate->texture.active][itarget]->texture:0, PrintEnum((glstate->texture.bound[glstate->texture.active][itarget])?glstate->texture.bound[glstate->texture.active][itarget]->format:0), PrintEnum((glstate->texture.bound[glstate->texture.active][itarget])?glstate->texture.bound[glstate->texture.active][itarget]->type:0));) + // PUSH_IF_COMPILING(glCopyTexSubImage2D); + if (glstate->list.pending) { + flush(); + } + + LOAD_GLES(glCopyTexSubImage2D); + errorGL(); + realize_bound(glstate->texture.active, target); + + // "Unmap" if buffer mapped... + glbuffer_t *pack = glstate->vao->pack; + glbuffer_t *unpack = glstate->vao->unpack; + glstate->vao->pack = NULL; + glstate->vao->unpack = NULL; + + readfboBegin(); // multiple readfboBegin() can be chained... + + gltexture_t* bound = glstate->texture.bound[glstate->texture.active][itarget]; +#ifdef TEXSTREAM + if (bound->streamed) { + void* buff = GetStreamingBuffer(bound->streamingID); + if ((bound->width == width) && (bound->height == height) && (xoffset == yoffset == 0)) { + gl4es_glReadPixels(x, y, width, height, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, buff); + } else { + void* tmp = malloc(width*height*2); + gl4es_glReadPixels(x, y, width, height, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, tmp); + for (int y=0; ywidth+xoffset)*2, tmp+y*width*2, width*2); + } + free(tmp); + } + } else +#endif + { + int copytex = 0; + if(glstate->fbo.current_fb->read_type==0) { + LOAD_GLES(glGetIntegerv); + gles_glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES, &glstate->fbo.current_fb->read_format); + gles_glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_TYPE_OES, &glstate->fbo.current_fb->read_type); + } + copytex = ((bound->format==GL_RGBA && bound->type==GL_UNSIGNED_BYTE) + || (bound->format==glstate->fbo.current_fb->read_format && bound->type==glstate->fbo.current_fb->read_type)); + if (copytex || !glstate->colormask[0] || !glstate->colormask[1] || !glstate->colormask[2] || !glstate->colormask[3]) { + gles_glCopyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height); + } else { + void* tmp = malloc(width*height*4); + GLenum format = bound->format; + GLenum type = bound->type; + gl4es_glReadPixels(x, y, width, height, format, type, tmp); + gl4es_glTexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, tmp); + free(tmp); + } + } + readfboEnd(); + // "Remap" if buffer mapped... + glstate->vao->pack = pack; + glstate->vao->unpack = unpack; +} + + +void gl4es_glCopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, + GLsizei width, GLsizei height, GLint border) { + DBG(printf("glCopyTexImage2D(%s, %i, %s, %i, %i, %i, %i, %i), glstate->fbo.current_fb=%u\n", PrintEnum(target), level, PrintEnum(internalformat), x, y, width, height, border, glstate->fbo.current_fb);) + //PUSH_IF_COMPILING(glCopyTexImage2D); + if (glstate->list.pending) { + flush(); + } + const GLuint itarget = what_target(target); + + // actualy bound if targetting shared TEX2D + realize_bound(glstate->texture.active, target); + + errorGL(); + + // "Unmap" if buffer mapped... + glbuffer_t *pack = glstate->vao->pack; + glbuffer_t *unpack = glstate->vao->unpack; + glstate->vao->pack = NULL; + glstate->vao->unpack = NULL; + + readfboBegin(); // multiple readfboBegin() can be chained... + realize_bound(glstate->texture.active, target); + gltexture_t* bound = glstate->texture.bound[glstate->texture.active][itarget]; + + if(glstate->fbo.current_fb->read_type==0) { + LOAD_GLES(glGetIntegerv); + gles_glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES, &glstate->fbo.current_fb->read_format); + gles_glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_TYPE_OES, &glstate->fbo.current_fb->read_type); + } + int copytex = ((bound->format==GL_RGBA && bound->type==GL_UNSIGNED_BYTE) + || (bound->format==glstate->fbo.current_fb->read_format && bound->type==glstate->fbo.current_fb->read_type)); + + if (copytex) { + LOAD_GLES(glCopyTexImage2D); + gles_glCopyTexImage2D(target, level, GL_RGB, x, y, width, height, border); + } else { + void* tmp = malloc(width*height*4); + gl4es_glReadPixels(x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, tmp); + gl4es_glTexImage2D(target, level, internalformat, width, height, border, GL_RGBA, GL_UNSIGNED_BYTE, tmp); + free(tmp); + } + + readfboEnd(); + // "Remap" if buffer mapped... + glstate->vao->pack = pack; + glstate->vao->unpack = unpack; +} + + + +GLboolean isDXTc(GLenum format) { + switch (format) { + case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: + case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: + case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: + case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: + return true; + } + return false; +} + +GLboolean isNotCompressed(GLenum format) { + switch(format) { + case GL_RGBA: + case GL_RGB: + case GL_RGBA8: + case GL_RGB8: + case GL_RGB5: + case GL_RGB565: + return true; + } + return false; +} + +GLvoid *uncompressDXTc(GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *data) { + // uncompress a DXTc image + // get pixel size of uncompressed image => fixed RGBA + int pixelsize = 4; +/* if (format==COMPRESSED_RGB_S3TC_DXT1_EXT) + pixelsize = 3;*/ + // check with the size of the input data stream if the stream is in fact uncompressed + if (imageSize == width*height*pixelsize || data==NULL) { + // uncompressed stream + return (GLvoid*)data; + } + // alloc memory + GLvoid *pixels = malloc(((width+3)&~3)*((height+3)&~3)*pixelsize); + // uncompress loop + int blocksize; + switch (format) { + case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: + case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: + blocksize = 8; + break; + case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: + case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: + blocksize = 16; + break; + } + uintptr_t src = (uintptr_t) data; + for (int y=0; yhardext.maxsize)?0:width; + proxy_height = (height>hardext.maxsize)?0:height; + return; + } + if (glstate->list.pending) { + flush(); + } + + // actualy bound if targetting shared TEX2D + realize_bound(glstate->texture.active, target); + + gltexture_t* bound = glstate->texture.bound[glstate->texture.active][itarget]; + DBG(printf("glCompressedTexImage2D on target=%s with size(%i,%i), internalformat=%s, imagesize=%i, upackbuffer=%p data=%p\n", PrintEnum(target), width, height, PrintEnum(internalformat), imageSize, glstate->vao->unpack?glstate->vao->unpack->data:0, data);) + // hack... + if (internalformat==GL_RGBA8) + internalformat = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; + // test if internalformat is not a compressed one + if ((width<=0) || (height<=0)) { + noerrorShim(); + return; // nothing to do... + } + + glbuffer_t *unpack = glstate->vao->unpack; + glstate->vao->unpack = NULL; + GLvoid *datab = (GLvoid*)data; + if (unpack) + datab += (uintptr_t)unpack->data; + + GLenum format = GL_RGBA; + GLenum type = GL_UNSIGNED_BYTE; + + if (isDXTc(internalformat)) { + GLvoid *pixels, *half; + pixels = half = NULL; + bound->alpha = (internalformat==GL_COMPRESSED_RGB_S3TC_DXT1_EXT)?false:true; + if(globals4es.nodownsampling==1) { // will be removed soon, avoid16bits is better + format = GL_RGBA; + type = GL_UNSIGNED_BYTE; + } else { + if(globals4es.avoid16bits) { + format = GL_RGBA; + type = GL_UNSIGNED_BYTE; + } else { + format = (internalformat==GL_COMPRESSED_RGB_S3TC_DXT1_EXT)?GL_RGB:GL_RGBA; +#ifdef PANDORA + type = (internalformat==GL_COMPRESSED_RGB_S3TC_DXT1_EXT)?GL_UNSIGNED_SHORT_5_6_5:(internalformat==GL_COMPRESSED_RGBA_S3TC_DXT1_EXT)?GL_UNSIGNED_SHORT_5_5_5_1:GL_UNSIGNED_SHORT_4_4_4_4; +#else + type = (internalformat==GL_COMPRESSED_RGB_S3TC_DXT1_EXT)?GL_UNSIGNED_SHORT_5_6_5:GL_UNSIGNED_SHORT_4_4_4_4; +#endif + } + } + if (datab) { + if (width<4 || height<4) { // can happens :( + GLvoid *tmp; + GLsizei nw=width; + GLsizei nh=height; + if (nw<4) nw = 4; + if (nh<4) nh = 4; + tmp = uncompressDXTc(nw, nh, internalformat, imageSize, datab); + pixels = malloc(4*width*height); + // crop + for (int y=0; ytexture.unpack_align)) { + format = GL_RGBA; + type = GL_UNSIGNED_BYTE; + } + } + } + int oldalign; + gl4es_glGetIntegerv(GL_UNPACK_ALIGNMENT, &oldalign); + if (oldalign!=1) + gl4es_glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + gl4es_glTexImage2D(rtarget, level, format==GL_RGBA?GL_COMPRESSED_RGBA:GL_COMPRESSED_RGB, width, height, border, format, type, half); + // re-update bounded texture info + bound->alpha = (internalformat==GL_COMPRESSED_RGB_S3TC_DXT1_EXT)?false:true; + bound->format = format; //internalformat; + bound->type = type; + bound->compressed = true; + bound->internalformat = internalformat; + bound->valid = 1; + if (oldalign!=1) + gl4es_glPixelStorei(GL_UNPACK_ALIGNMENT, oldalign); + if (half!=pixels) + free(half); + if (pixels!=datab) + free(pixels); + } else { + LOAD_GLES(glCompressedTexImage2D); + bound->alpha = true; + bound->format = internalformat; + bound->type = GL_UNSIGNED_BYTE; + bound->internalformat = internalformat; + bound->compressed = true; + bound->valid = 1; + realize_bound(glstate->texture.active, target); + if (glstate->fpe_state && glstate->fpe_bound_changed < glstate->texture.active+1) + glstate->fpe_bound_changed = glstate->texture.active+1; + gles_glCompressedTexImage2D(rtarget, level, internalformat, width, height, border, imageSize, datab); + errorGL(); + } + glstate->vao->unpack = unpack; +} + +void gl4es_glCompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, + GLsizei width, GLsizei height, GLenum format, + GLsizei imageSize, const GLvoid *data) +{ + const GLuint itarget = what_target(target); + if (glstate->list.pending) { + flush(); + } + + // actualy bound if targetting shared TEX2D + realize_bound(glstate->texture.active, target); + + gltexture_t *bound = glstate->texture.bound[glstate->texture.active][itarget]; + if (level != 0) { + noerrorShim(); + //TODO + //printf("STUBBED glCompressedTexSubImage2D with level=%i\n", level); + return; + } + DBG(printf("glCompressedTexSubImage2D with unpack_row_length(%i), size(%i,%i), pos(%i,%i) and skip={%i,%i}, internalformat=%s, imagesize=%i, data=%p\n", glstate->texture.unpack_row_length, width, height, xoffset, yoffset, glstate->texture.unpack_skip_pixels, glstate->texture.unpack_skip_rows, PrintEnum(format), imageSize, data);) + glbuffer_t *unpack = glstate->vao->unpack; + glstate->vao->unpack = NULL; + GLvoid *datab = (GLvoid*)data; + if (unpack) + datab += (uintptr_t)unpack->data; + LOAD_GLES(glCompressedTexSubImage2D); + errorGL(); + if (isDXTc(format)) { + GLvoid *pixels; + if (width<4 || height<4) { // can happens :( + GLvoid *tmp; + GLsizei nw=width; + GLsizei nh=height; + if (nw<4) nw = 4; + if (nh<4) nh = 4; + tmp = uncompressDXTc(nw, nh, format, imageSize, datab); + pixels = malloc(4*width*height); + // crop + for (int y=0; yformat; + GLenum type = bound->type; + pixel_convert(pixels, &half, width, height, GL_RGBA, GL_UNSIGNED_BYTE, format, type, 0, glstate->texture.unpack_align); + gl4es_glTexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, half); + #endif + if (half!=pixels) + free(half); + if (pixels!=datab) + free(pixels); + } else { + realize_bound(glstate->texture.active, target); + gles_glCompressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize, datab); + } +} + +void gl4es_glGetCompressedTexImage(GLenum target, GLint lod, GLvoid *img) { + if (glstate->list.pending) flush(); + + const GLuint itarget = what_target(target); + gltexture_t* bound = glstate->texture.bound[glstate->texture.active][itarget]; + DBG(printf("glGetCompressedTexImage(%s, %i, %p), bound=%p, bound->orig_internal=%s\n", PrintEnum(target), lod, img, bound, (bound)?PrintEnum(bound->orig_internal):"nil");) + errorShim(GL_INVALID_OPERATION); + if(bound->orig_internal!=GL_COMPRESSED_RGB && bound->orig_internal!=GL_COMPRESSED_RGBA) + return; + int width = nlevel(bound->width,lod); + int height = nlevel(bound->height,lod); + int w = nlevel(width,2); w<<=2; + int h = nlevel(height,2); h<<=2; + + int alpha = (bound->orig_internal==GL_COMPRESSED_RGBA)?1:0; + + glbuffer_t *unpack = glstate->vao->unpack; + glbuffer_t *pack = glstate->vao->pack; + glstate->vao->unpack = NULL; + glstate->vao->pack = NULL; + GLvoid *datab = (GLvoid*)img; + if (pack) + datab += (uintptr_t)pack->data; + + // alloc the memory for source image and grab the file + GLuint *src = (GLuint*)malloc(width*height*4); + gl4es_glGetTexImage(target, lod, GL_RGBA, GL_UNSIGNED_BYTE, (GLvoid*)src); + GLuint tmp[4*4]; //this is the 4x4 block + for (int y = 0; y < h; y+=4) + for (int x = 0; x < w; x+=4) { + GLuint col = 0; + for (int i=0; i<16; i++) { + if(x+(i%4)vao->unpack = unpack; + glstate->vao->pack = pack; + noerrorShim(); + return; +} + +void gl4es_glCompressedTexImage1D(GLenum target, GLint level, GLenum internalformat, + GLsizei width, GLint border, + GLsizei imageSize, const GLvoid *data) { + + gl4es_glCompressedTexImage2D(target, level, internalformat, width, 1, border, imageSize, data); +} + +void gl4es_glCompressedTexImage3D(GLenum target, GLint level, GLenum internalformat, + GLsizei width, GLsizei height, GLsizei depth, GLint border, + GLsizei imageSize, const GLvoid *data) { + + gl4es_glCompressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data); +} + +void gl4es_glCompressedTexSubImage1D(GLenum target, GLint level, GLint xoffset, + GLsizei width, GLenum format, + GLsizei imageSize, const GLvoid *data) { + + gl4es_glCompressedTexSubImage2D(target, level, xoffset, 0, width, 1, format, imageSize, data); +} +void gl4es_glCompressedTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, + GLsizei width, GLsizei height, GLsizei depth, GLenum format, + GLsizei imageSize, const GLvoid *data) { + + gl4es_glCompressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize, data); +} + + +// bind the correct texture on Tex2D or TEXCUBE mapper... +void realize_bound(int TMU, GLenum target) { + LOAD_GLES(glBindTexture); + gltexture_t *tex = glstate->texture.bound[TMU][what_target(target)]; + GLuint t = tex->glname; + DBG(printf("realize_bound(%d, %s), glsate->actual_tex2d[%d]=%u / %u\n", TMU, PrintEnum(target), TMU, glstate->actual_tex2d[TMU], t);) +#ifdef TEXSTREAM + LOAD_GLES(glEnable); + LOAD_GLES(glDisable); +#endif + switch (target) { + case GL_TEXTURE_1D: + case GL_TEXTURE_2D: + case GL_TEXTURE_3D: + case GL_TEXTURE_RECTANGLE_ARB: +#ifdef TEXSTREAM + if(glstate->bound_stream[TMU]) { + realize_active(); + gles_glDisable(GL_TEXTURE_STREAM_IMG); + DeactivateStreaming(); + glstate->bound_stream[TMU] = 0; + } + int streamingID = tex->streamingID; + if (globals4es.texstream && (streamingID>-1)) { + if(hardext.esversion<2) gles_glDisable(GL_TEXTURE_2D); + ActivateStreaming(streamingID); + glstate->bound_stream[TMU] = 1; + glstate->actual_tex2d[TMU] = t; + if (hardext.esversion<2) + gles_glEnable(GL_TEXTURE_STREAM_IMG); + if (glstate->bound_changed < TMU+1) + glstate->bound_changed = TMU+1; + } else +#endif + if(glstate->actual_tex2d[TMU] != t) { + realize_active(); + gles_glBindTexture(GL_TEXTURE_2D, t); + glstate->actual_tex2d[TMU] = t; + if (glstate->bound_changed < TMU+1) + glstate->bound_changed = TMU+1; + } + break; + } + if (glstate->fpe_state && glstate->fpe_bound_changed < TMU+1) + glstate->fpe_bound_changed = TMU+1; +} + +void realize_active() { + LOAD_GLES(glActiveTexture); + if(glstate->gleshard->active == glstate->texture.active) + return; + glstate->gleshard->active = glstate->texture.active; + gles_glActiveTexture(GL_TEXTURE0 + glstate->gleshard->active); +} + +void realize_textures() { + LOAD_GLES(glEnable); + LOAD_GLES(glDisable); + LOAD_GLES(glBindTexture); + LOAD_GLES(glActiveTexture); +#ifdef TEXSTREAM + DBG(printf("realize_textures(), glstate->bound_changed=%d, glstate->enable.texture[0]=%X glsate->actual_tex2d[0]=%u / glstate->bound_stream[0]=%u\n", glstate->bound_changed, glstate->enable.texture[0], glstate->actual_tex2d[0], glstate->bound_stream[0]);) +#else + DBG(printf("realize_textures(), glstate->bound_changed=%d, glstate->enable.texture[0]=%X glsate->actual_tex2d[0]=%u\n", glstate->bound_changed, glstate->enable.texture[0], glstate->actual_tex2d[0]);) +#endif + for (int i=0; ibound_changed; i++) { + // get highest priority texture unit + int tmp = glstate->enable.texture[glstate->texture.active]; + int tgt = ENABLED_TEX2D; // default to TEX2D + if(IS_TEX3D(tmp)) + tgt = ENABLED_TEX3D; + else if(IS_TEXTURE_RECTANGLE(tmp)) + tgt = ENABLED_TEXTURE_RECTANGLE; + else if(IS_TEX2D(tmp)) + tgt = ENABLED_TEX2D; + else if(IS_TEX1D(tmp)) + tgt = ENABLED_TEX1D; + else if(IS_CUBE_MAP(tmp)) + continue; // CUBE MAP are immediatly bound +#ifdef TEXSTREAM + if(glstate->bound_stream[i]) { + realize_active(); + if(hardext.esversion<2) gles_glDisable(GL_TEXTURE_STREAM_IMG); + DeactivateStreaming(); + glstate->bound_stream[i] = 0; + } +#endif + gltexture_t *tex = glstate->texture.bound[i][tgt]; + GLuint t = tex->glname; + if (t!=glstate->actual_tex2d[i] +#ifdef TEXSTREAM + || (glstate->bound_stream[i] != tex->streamed) +#endif + ) { + if(glstate->gleshard->active!=i) { + glstate->gleshard->active = i; + gles_glActiveTexture(GL_TEXTURE0+i); + } +#ifdef TEXSTREAM + int streamed = tex->streamed; + int streamingID = tex->streamingID; + if(glstate->bound_stream[i]) { + if(hardext.esversion<2) gles_glDisable(GL_TEXTURE_STREAM_IMG); + DeactivateStreaming(); + if(hardext.esversion<2) gles_glEnable(GL_TEXTURE_2D); + glstate->bound_stream[i] = 0; + } + if (globals4es.texstream && (streamingID>-1)) { + if (IS_ANYTEX(tmp) && hardext.esversion<2) + gles_glDisable(GL_TEXTURE_2D); + ActivateStreaming(streamingID); + glstate->bound_stream[i] = 1; + glstate->actual_tex2d[i] = t; + if (IS_ANYTEX(tmp)) + gles_glEnable(GL_TEXTURE_STREAM_IMG); + continue; + } +#endif + + // bound... + gles_glBindTexture(GL_TEXTURE_2D, t); + glstate->actual_tex2d[i] = t; + } + } + glstate->bound_changed = 0; +} + + + +//Direct wrapper +void glTexImage2D(GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *data) AliasExport("gl4es_glTexImage2D"); +void glTexImage1D(GLenum target, GLint level, GLint internalFormat, GLsizei width, GLint border, GLenum format, GLenum type, const GLvoid *data) AliasExport("gl4es_glTexImage1D"); +void glTexImage3D(GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *data) AliasExport("gl4es_glTexImage3D"); +void glTexImage3DEXT(GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *data) AliasExport("gl4es_glTexImage3D"); +void glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *data) AliasExport("gl4es_glTexSubImage2D"); +void glTexSubImage1D(GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid *data) AliasExport("gl4es_glTexSubImage1D"); +void glTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *data) AliasExport("gl4es_glTexSubImage3D"); +void glBindTexture(GLenum target, GLuint texture) AliasExport("gl4es_glBindTexture"); +void glGenTextures(GLsizei n, GLuint * textures) AliasExport("gl4es_glGenTextures"); +void glDeleteTextures(GLsizei n, const GLuint * textures) AliasExport("gl4es_glDeleteTextures"); +void glTexParameteri(GLenum target, GLenum pname, GLint param) AliasExport("gl4es_glTexParameteri"); +void glTexParameterf(GLenum target, GLenum pname, GLfloat param) AliasExport("gl4es_glTexParameterf"); +void glTexParameterfv(GLenum target, GLenum pname, const GLfloat * params) AliasExport("gl4es_glTexParameterfv"); +void glTexParameteriv(GLenum target, GLenum pname, const GLint * params) AliasExport("gl4es_glTexParameteriv"); +GLboolean glAreTexturesResident(GLsizei n, const GLuint *textures, GLboolean *residences) AliasExport("gl4es_glAreTexturesResident"); +void glGetTexLevelParameteriv(GLenum target, GLint level, GLenum pname, GLint *params) AliasExport("gl4es_glGetTexLevelParameteriv"); +void glGetTexImage(GLenum target, GLint level, GLenum format, GLenum type, GLvoid * img) AliasExport("gl4es_glGetTexImage"); +void glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid * data) AliasExport("gl4es_glReadPixels"); +void glCompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data) AliasExport("gl4es_glCompressedTexImage2D"); +void glCompressedTexImage1D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const GLvoid *data) AliasExport("gl4es_glCompressedTexImage1D"); +void glCompressedTexImage3D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid *data) AliasExport("gl4es_glCompressedTexImage3D"); +void glCompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *data) AliasExport("gl4es_glCompressedTexSubImage2D"); +void glCompressedTexSubImage1D(GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const GLvoid *data) AliasExport("gl4es_glCompressedTexSubImage1D"); +void glCompressedTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid *data) AliasExport("gl4es_glCompressedTexSubImage3D"); +void glGetCompressedTexImage(GLenum target, GLint lod, GLvoid *img) AliasExport("gl4es_glGetCompressedTexImage"); +void glCopyTexImage1D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLint border) AliasExport("gl4es_glCopyTexImage1D"); +void glCopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border) AliasExport("gl4es_glCopyTexImage2D"); +void glCopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height) AliasExport("gl4es_glCopyTexSubImage2D"); +void glCopyTexSubImage1D(GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width) AliasExport("gl4es_glCopyTexSubImage1D"); +void glCopyTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height) AliasExport("gl4es_glCopyTexSubImage3D"); +void glActiveTexture( GLenum texture ) AliasExport("gl4es_glActiveTexture"); +void glClientActiveTexture( GLenum texture ) AliasExport("gl4es_glClientActiveTexture"); +GLboolean glIsTexture( GLuint texture ) AliasExport("gl4es_glIsTexture"); +void glPixelStorei(GLenum pname, GLint param) AliasExport("gl4es_glPixelStorei"); + +//EXT mapper +void glTexSubImage3DEXT(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *data) AliasExport("gl4es_glTexSubImage3D"); +void glCompressedTexImage2DEXT(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data) AliasExport("gl4es_glCompressedTexImage2D"); +void glCompressedTexImage1DEXT(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const GLvoid *data) AliasExport("gl4es_glCompressedTexImage1D"); +void glCompressedTexImage3DEXT(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid *data) AliasExport("gl4es_glCompressedTexImage3D"); +void glCompressedTexSubImage2DEXT(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *data) AliasExport("gl4es_glCompressedTexSubImage2D"); +void glCompressedTexSubImage1DEXT(GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const GLvoid *data) AliasExport("gl4es_glCompressedTexSubImage1D"); +void glCompressedTexSubImage3DEXT(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid *data) AliasExport("gl4es_glCompressedTexSubImage3D"); +void glGetCompressedTexImageEXT(GLenum target, GLint lod, GLvoid *img) AliasExport("gl4es_glGetCompressedTexImage"); +void glCopyTexSubImage3DEXT(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height) AliasExport("gl4es_glCopyTexSubImage3D"); + +//ARB mapper +void glActiveTextureARB(GLenum texture) AliasExport("gl4es_glActiveTexture"); +void glClientActiveTextureARB(GLenum texture) AliasExport("gl4es_glClientActiveTexture"); +void glTexSubImage3DARB(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *data) AliasExport("gl4es_glTexSubImage3D"); +void glCompressedTexImage2DARB(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data) AliasExport("gl4es_glCompressedTexImage2D"); +void glCompressedTexImage1DARB(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const GLvoid *data) AliasExport("gl4es_glCompressedTexImage1D"); +void glCompressedTexImage3DARB(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid *data) AliasExport("gl4es_glCompressedTexImage3D"); +void glCompressedTexSubImage2DARB(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *data) AliasExport("gl4es_glCompressedTexSubImage2D"); +void glCompressedTexSubImage1DARB(GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const GLvoid *data) AliasExport("gl4es_glCompressedTexSubImage1D"); +void glCompressedTexSubImage3DARB(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid *data) AliasExport("gl4es_glCompressedTexSubImage3D"); +void glGetCompressedTexImageARB(GLenum target, GLint lod, GLvoid *img) AliasExport("gl4es_glGetCompressedTexImage"); +void glCopyTexSubImage3DARB(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height) AliasExport("gl4es_glCopyTexSubImage3D"); diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/texture.h b/Projects/Android/jni/SupportLibs/gl4es/src/gl/texture.h new file mode 100644 index 0000000..2f20df3 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/texture.h @@ -0,0 +1,233 @@ +#ifndef _GL4ES_TEXTURE_H_ +#define _GL4ES_TEXTURE_H_ + +#include "buffers.h" +#include "const.h" +#include "gles.h" + +void gl4es_glTexImage2D(GLenum target, GLint level, GLint internalFormat, + GLsizei width, GLsizei height, GLint border, + GLenum format, GLenum type, const GLvoid *data); + +void gl4es_glTexImage1D(GLenum target, GLint level, GLint internalFormat, + GLsizei width, GLint border, + GLenum format, GLenum type, const GLvoid *data); + +void gl4es_glTexImage3D(GLenum target, GLint level, GLint internalFormat, + GLsizei width, GLsizei height, GLsizei depth, + GLint border, GLenum format, GLenum type, const GLvoid *data); + +void gl4es_glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, + GLsizei width, GLsizei height, GLenum format, GLenum type, + const GLvoid *data); + +void gl4es_glTexSubImage1D(GLenum target, GLint level, GLint xoffset, + GLsizei width, GLenum format, GLenum type, + const GLvoid *data); + +void gl4es_glTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, + GLsizei width, GLsizei height, GLsizei depth, GLenum format, + GLenum type, const GLvoid *data); + +void gl4es_glBindTexture(GLenum target, GLuint texture); +void gl4es_glGenTextures(GLsizei n, GLuint * textures); +void gl4es_glDeleteTextures(GLsizei n, const GLuint * textures); +void gl4es_glTexParameteri(GLenum target, GLenum pname, GLint param); +void gl4es_glTexParameterf(GLenum target, GLenum pname, GLfloat param); +GLboolean gl4es_glAreTexturesResident(GLsizei n, const GLuint *textures, GLboolean *residences); +void gl4es_glGetTexLevelParameteriv(GLenum target, GLint level, GLenum pname, GLint *params); +void gl4es_glGetTexImage(GLenum target, GLint level, GLenum format, GLenum type, GLvoid * img); +void gl4es_glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid * data); + +void gl4es_glCompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, + GLsizei width, GLsizei height, GLint border, + GLsizei imageSize, const GLvoid *data); +void gl4es_glCompressedTexImage1D(GLenum target, GLint level, GLenum internalformat, + GLsizei width, GLint border, + GLsizei imageSize, const GLvoid *data); +void gl4es_glCompressedTexImage3D(GLenum target, GLint level, GLenum internalformat, + GLsizei width, GLsizei height, GLsizei depth, GLint border, + GLsizei imageSize, const GLvoid *data); + +void gl4es_glCompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, + GLsizei width, GLsizei height, GLenum format, + GLsizei imageSize, const GLvoid *data); +void gl4es_glCompressedTexSubImage1D(GLenum target, GLint level, GLint xoffset, + GLsizei width, GLenum format, + GLsizei imageSize, const GLvoid *data); +void gl4es_glCompressedTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, + GLsizei width, GLsizei height, GLsizei depth, GLenum format, + GLsizei imageSize, const GLvoid *data); + +void gl4es_glGetCompressedTexImage(GLenum target, GLint lod, GLvoid *img); + + +void gl4es_glCopyTexImage1D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, + GLsizei width, GLint border); + +void gl4es_glCopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, + GLsizei width, GLsizei height, GLint border); + +void gl4es_glCopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, + GLint x, GLint y, GLsizei width, GLsizei height); + +void gl4es_glCopyTexSubImage1D(GLenum target, GLint level, GLint xoffset, GLint x, GLint y, + GLsizei width); + +void gl4es_glCopyTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, + GLint x, GLint y, GLsizei width, GLsizei height); + +void tex_coord_rect_arb(GLfloat *tex, int stride, GLsizei len, + GLsizei width, GLsizei height); +void tex_coord_npot(GLfloat *tex, GLsizei len, + GLsizei width, GLsizei height, + GLsizei nwidth, GLsizei nheight); + +void tex_coord_matrix(GLfloat *tex, GLsizei len, const GLfloat* mat); + +int npot(int n); + +typedef enum { + ENABLED_TEX1D = 0, + ENABLED_TEX2D, + ENABLED_TEX3D, + ENABLED_TEXTURE_RECTANGLE, + ENABLED_CUBE_MAP, + ENABLED_TEXTURE_LAST +} texture_enabled_t; + +typedef struct { + GLuint texture; + GLuint glname; + GLenum target; + GLsizei width; + GLsizei height; + GLsizei nwidth; + GLsizei nheight; + GLenum format; + GLenum type; + GLenum orig_internal; + GLenum internalformat; + GLenum inter_format, inter_type; + int shrink; + GLboolean mipmap_auto; + GLboolean mipmap_need; + GLboolean mipmap_done; + GLenum min_filter; + GLenum mag_filter; + GLenum wrap_s; + GLenum wrap_t; + GLenum compare; + GLboolean alpha; + GLboolean compressed; + GLboolean streamed; + int valid; + int streamingID; + int base_level; + int max_level; + int aniso; + int fpe_format; // tracking simplified internal format for FPE + int npot; + int adjust; // flag if width/height has to be adjusted + float adjustxy[2]; // adjust factor + int useratio; + float ratiox, ratioy; + int binded_fbo; // non zero if binded to an fbo + GLenum binded_attachment; // What binding (texture, depth, stencil, depth_stencil) + GLuint renderdepth; // incase renderbuffer where used instead... + GLuint renderstencil; + GLvoid *data; // in case we want to keep a copy of it (it that case, always RGBA/GL_UNSIGNED_BYTE +} gltexture_t; + +KHASH_MAP_DECLARE_INT(tex, gltexture_t *); + +static inline GLenum map_tex_target(GLenum target) { + switch (target) { + case GL_TEXTURE_1D: + case GL_TEXTURE_3D: + case GL_TEXTURE_RECTANGLE_ARB: + target = GL_TEXTURE_2D; + break; + case GL_PROXY_TEXTURE_1D: + case GL_PROXY_TEXTURE_3D: + case GL_PROXY_TEXTURE_RECTANGLE_ARB: + target = GL_PROXY_TEXTURE_2D; + break; + } + return target; +} +gltexture_t* gl4es_getTexture(GLenum target, GLuint texture); +gltexture_t* gl4es_getCurrentTexture(GLenum target); + +static inline GLuint what_target(GLenum target) { + switch(target) { + case GL_TEXTURE_1D: + return ENABLED_TEX1D; + case GL_TEXTURE_3D: + return ENABLED_TEX3D; + case GL_TEXTURE_CUBE_MAP: + case GL_TEXTURE_CUBE_MAP_POSITIVE_X: + case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: + case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: + case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: + case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: + case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: + return ENABLED_CUBE_MAP; + case GL_TEXTURE_RECTANGLE_ARB: + return ENABLED_TEXTURE_RECTANGLE; + case GL_TEXTURE_2D: + default: + return ENABLED_TEX2D; + } +} +static inline GLenum to_target(GLuint itarget) { + switch(itarget) { + case ENABLED_TEX1D: + return GL_TEXTURE_1D; + case ENABLED_TEX3D: + return GL_TEXTURE_3D; + case ENABLED_TEXTURE_RECTANGLE: + return GL_TEXTURE_RECTANGLE_ARB; + case ENABLED_CUBE_MAP: + return GL_TEXTURE_CUBE_MAP; + case ENABLED_TEX2D: + default: + return GL_TEXTURE_2D; + } +} +#define IS_TEX1D(T) (T&(1<uniform, k); + if(k!=kh_end(glprogram->uniform)) { + gluniform = kh_value(glprogram->uniform, k); + uintptr_t offs = gluniform->cache_offs; + int size = gluniform->cache_size; + if(is_uniform_float(gluniform->type)) { + memcpy(params, glprogram->cache.cache+offs, size); + noerrorShim(); + return; + } + // if it's not float, it can be only int for now + int n = size / sizeof(GLint); + GLint *fl = (GLint*)(glprogram->cache.cache + offs); + for (int i=0; ifloat is straight forward + noerrorShim(); + return; + } + errorShim(GL_INVALID_VALUE); +} +void gl4es_glGetUniformiv(GLuint program, GLint location, GLint *params) { + DBG(printf("glGetUniformiv(%d, %d, %p)\n", program, location, params);) + FLUSH_BEGINEND; + CHECK_PROGRAM(void, program); + + khint_t k; + uniform_t *gluniform = NULL; + k = kh_get(uniformlist, glprogram->uniform, k); + if(k!=kh_end(glprogram->uniform)) { + gluniform = kh_value(glprogram->uniform, k); + uintptr_t offs = gluniform->cache_offs; + int size = gluniform->cache_size; + if(is_uniform_int(gluniform->type)) { + memcpy(params, glprogram->cache.cache+offs, size); + noerrorShim(); + return; + } + // if it's not int, it can be only float for now + int n = size / sizeof(GLfloat); + GLfloat *fl = (GLfloat*)(glprogram->cache.cache + offs); + for (int i=0; i int without adjustment? + noerrorShim(); + return; + } + errorShim(GL_INVALID_VALUE); +} + +void GoUniformfv(program_t *glprogram, GLint location, int size, int count, const GLfloat *value) +{ + DBG(printf("GoUniformif(%p[%d], %d, %d, %d, %p) =>(%f...)\n", glprogram, glprogram->id, location, size, count, value, value[0]);) + if(location==-1) { + noerrorShim(); + return; + } + if(count<0) { + errorShim(GL_INVALID_VALUE); + return; + } + + khint_t k; + uniform_t *m; + k = kh_get(uniformlist, glprogram->uniform, location); + if (k==kh_end(glprogram->uniform)) { + errorShim(GL_INVALID_OPERATION); + return; + } + m = kh_value(glprogram->uniform, k); + if(size != n_uniform(m->type) || !is_uniform_float(m->type) || count>m->size) { + errorShim(GL_INVALID_OPERATION); + return; + } + // ok, check the value in the cache + int rsize = sizeof(GLfloat)*size*count; + if (memcmp(glprogram->cache.cache + m->cache_offs, value, rsize)==0) { + noerrorShim(); + return; // nothing to do, same value already there + } + // update uniform + memcpy(glprogram->cache.cache + m->cache_offs, value, rsize); + LOAD_GLES2(glUniform1fv); + LOAD_GLES2(glUniform2fv); + LOAD_GLES2(glUniform3fv); + LOAD_GLES2(glUniform4fv); + if(gles_glUniform1fv) { + switch (size) { + case 1: gles_glUniform1fv(m->id, count, value); break; + case 2: gles_glUniform2fv(m->id, count, value); break; + case 3: gles_glUniform3fv(m->id, count, value); break; + case 4: gles_glUniform4fv(m->id, count, value); break; + } + errorGL(); + } else + errorShim(GL_INVALID_OPERATION); // no GLLS hardware +} +void GoUniformiv(program_t *glprogram, GLint location, int size, int count, const GLint *value) +{ + DBG(printf("GoUniformiv(%p[%d], %d, %d, %d, %p) =>(%d...)\n", glprogram, glprogram->id, location, size, count, value, value[0]);) + if(location==-1) { + noerrorShim(); + return; + } + if(count<0) { + errorShim(GL_INVALID_VALUE); + return; + } + + khint_t k; + uniform_t *m; + k = kh_get(uniformlist, glprogram->uniform, location); + if (k==kh_end(glprogram->uniform)) { + errorShim(GL_INVALID_OPERATION); + } + m = kh_value(glprogram->uniform, k); + if(size != n_uniform(m->type) || !is_uniform_int(m->type) || count>m->size) { + errorShim(GL_INVALID_OPERATION); + return; + } + // ok, check the value in the cache + int rsize = sizeof(GLint)*size*count; + if (memcmp(glprogram->cache.cache + m->cache_offs, value, rsize)==0) { + noerrorShim(); + return; // nothing to do, same value already there + } + DBG(printf("Uniform updated, cache=%p(%d/%d), offset=%p, size=%d\n", glprogram->cache.cache, glprogram->cache.size, glprogram->cache.cap, m->cache_offs, rsize);) + // update uniform + memcpy(glprogram->cache.cache + m->cache_offs, value, rsize); + LOAD_GLES2(glUniform1iv); + LOAD_GLES2(glUniform2iv); + LOAD_GLES2(glUniform3iv); + LOAD_GLES2(glUniform4iv); + if(gles_glUniform1iv) { + switch (size) { + case 1: gles_glUniform1iv(m->id, count, value); break; + case 2: gles_glUniform2iv(m->id, count, value); break; + case 3: gles_glUniform3iv(m->id, count, value); break; + case 4: gles_glUniform4iv(m->id, count, value); break; + } + errorGL(); + } else + errorShim(GL_INVALID_OPERATION); // no GLLS hardware +} + +void gl4es_glUniform1f(GLint location, GLfloat v0) { + DBG(printf("glUniform1f(%d, %f)\n", location, v0);) + PUSH_IF_COMPILING(glUniform1f); + GLuint program = glstate->glsl->program; + CHECK_PROGRAM(void, program); + APPLY_PROGRAM(program, glprogram); + GoUniformfv(glprogram, location, 1, 1, &v0); +} +void gl4es_glUniform2f(GLint location, GLfloat v0, GLfloat v1) { + DBG(printf("glUniform2f(%d, %f, %f)\n", location, v0, v1);) + PUSH_IF_COMPILING(glUniform2f); + GLfloat fl[2] = {v0, v1}; + GLuint program = glstate->glsl->program; + CHECK_PROGRAM(void, program); + APPLY_PROGRAM(program, glprogram); + GoUniformfv(glprogram, location, 2, 1, fl); +} +void gl4es_glUniform3f(GLint location, GLfloat v0, GLfloat v1, GLfloat v2) { + DBG(printf("glUniform3f(%d, %f, %f, %f)\n", location, v0, v1, v2);) + PUSH_IF_COMPILING(glUniform3f); + GLfloat fl[3] = {v0, v1, v2}; + GLuint program = glstate->glsl->program; + CHECK_PROGRAM(void, program); + APPLY_PROGRAM(program, glprogram); + GoUniformfv(glprogram, location, 3, 1, fl); +} +void gl4es_glUniform4f(GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3) { + DBG(printf("glUniform4f(%d, %f, %f, %f, %f)\n", location, v0, v1, v2, v3);) + PUSH_IF_COMPILING(glUniform4f); + GLfloat fl[4] = {v0, v1, v2, v3}; + GLuint program = glstate->glsl->program; + CHECK_PROGRAM(void, program); + APPLY_PROGRAM(program, glprogram); + GoUniformfv(glprogram, location, 4, 1, fl); +} +void gl4es_glUniform1i(GLint location, GLint v0) { + DBG(printf("glUniform1i(%d, %d)\n", location, v0);) + PUSH_IF_COMPILING(glUniform1i); + GLuint program = glstate->glsl->program; + CHECK_PROGRAM(void, program); + APPLY_PROGRAM(program, glprogram); + GoUniformiv(glprogram, location, 1, 1, &v0); +} +void gl4es_glUniform2i(GLint location, GLint v0, GLint v1) { + DBG(printf("glUniform2i(%d, %d, %d)\n", location, v0, v1);) + PUSH_IF_COMPILING(glUniform2i); + GLint fl[2] = {v0, v1}; + GLuint program = glstate->glsl->program; + CHECK_PROGRAM(void, program); + APPLY_PROGRAM(program, glprogram); + GoUniformiv(glprogram, location, 2, 1, fl); +} +void gl4es_glUniform3i(GLint location, GLint v0, GLint v1, GLint v2) { + DBG(printf("glUniform3i(%d, %d, %d, %d)\n", location, v0, v1, v2);) + PUSH_IF_COMPILING(glUniform3i); + GLint fl[3] = {v0, v1, v2}; + GLuint program = glstate->glsl->program; + CHECK_PROGRAM(void, program); + APPLY_PROGRAM(program, glprogram); + GoUniformiv(glprogram, location, 3, 1, fl); +} +void gl4es_glUniform4i(GLint location, GLint v0, GLint v1, GLint v2, GLint v3) { + DBG(printf("glUniform4i(%d, %d, %d, %d, %d)\n", location, v0, v1, v2, v3);) + PUSH_IF_COMPILING(glUniform4i); + GLint fl[4] = {v0, v1, v2, v3}; + GLuint program = glstate->glsl->program; + CHECK_PROGRAM(void, program); + APPLY_PROGRAM(program, glprogram); + GoUniformiv(glprogram, location, 4, 1, fl); +} +//TODO: the "v" variant and matrix variant cannot be pushed simply... +void gl4es_glUniform1fv(GLint location, GLsizei count, const GLfloat *value) { + DBG(printf("glUniform1fv(%d, %d, %p) =>(%f)\n", location, count, value, value[0]);) + PUSH_IF_COMPILING(glUniform1fv); + GLuint program = glstate->glsl->program; + CHECK_PROGRAM(void, program); + APPLY_PROGRAM(program, glprogram); + GoUniformfv(glprogram, location, 1, count, value); +} +void gl4es_glUniform2fv(GLint location, GLsizei count, const GLfloat *value) { + DBG(printf("glUniform2fv(%d, %d, %p) =>(%f %f)\n", location, count, value, value[0], value[1]);) + PUSH_IF_COMPILING(glUniform2fv); + GLuint program = glstate->glsl->program; + CHECK_PROGRAM(void, program); + APPLY_PROGRAM(program, glprogram); + GoUniformfv(glprogram, location, 2, count, value); +} +void gl4es_glUniform3fv(GLint location, GLsizei count, const GLfloat *value) { + DBG(printf("glUniform3fv(%d, %d, %p) =>(%f %f, %f)\n", location, count, value, value[0], value[1], value[2]);) + PUSH_IF_COMPILING(glUniform3fv); + GLuint program = glstate->glsl->program; + CHECK_PROGRAM(void, program); + APPLY_PROGRAM(program, glprogram); + GoUniformfv(glprogram, location, 3, count, value); +} +void gl4es_glUniform4fv(GLint location, GLsizei count, const GLfloat *value) { + DBG(printf("glUniform4fv(%d, %d, %p) =>(%f %f, %f, %f)\n", location, count, value, value[0], value[1], value[2], value[3]);) + PUSH_IF_COMPILING(glUniform4fv); + GLuint program = glstate->glsl->program; + CHECK_PROGRAM(void, program); + APPLY_PROGRAM(program, glprogram); + GoUniformfv(glprogram, location, 4, count, value); +} +void gl4es_glUniform1iv(GLint location, GLsizei count, const GLint *value) { + PUSH_IF_COMPILING(glUniform1iv); + GLuint program = glstate->glsl->program; + CHECK_PROGRAM(void, program); + APPLY_PROGRAM(program, glprogram); + GoUniformiv(glprogram, location, 1, count, value); +} +void gl4es_glUniform2iv(GLint location, GLsizei count, const GLint *value) { + PUSH_IF_COMPILING(glUniform2iv); + GLuint program = glstate->glsl->program; + CHECK_PROGRAM(void, program); + APPLY_PROGRAM(program, glprogram); + GoUniformiv(glprogram, location, 2, count, value); +} +void gl4es_glUniform3iv(GLint location, GLsizei count, const GLint *value) { + PUSH_IF_COMPILING(glUniform3iv); + GLuint program = glstate->glsl->program; + CHECK_PROGRAM(void, program); + APPLY_PROGRAM(program, glprogram); + GoUniformiv(glprogram, location, 3, count, value); +} +void gl4es_glUniform4iv(GLint location, GLsizei count, const GLint *value) { + PUSH_IF_COMPILING(glUniform4iv); + GLuint program = glstate->glsl->program; + CHECK_PROGRAM(void, program); + APPLY_PROGRAM(program, glprogram); + GoUniformiv(glprogram, location, 4, count, value); +} + +void gl4es_glUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) { + DBG(printf("glUniformMatrix2fv(%d, %d, %d, %p)\n", location, count, transpose, value);) + PUSH_IF_COMPILING(glUniformMatrix2fv); + GLuint program = glstate->glsl->program; + CHECK_PROGRAM(void, program); + APPLY_PROGRAM(program, glprogram); + GoUniformMatrix2fv(glprogram, location, count, transpose, value); +} + +void gl4es_glProgramUniform1f(GLuint program, GLint location, GLfloat v0) { + DBG(printf("glUniform1f(%d, %f)\n", location, v0);) + PUSH_IF_COMPILING(glUniform1f); + CHECK_PROGRAM(void, program); + APPLY_PROGRAM(program, glprogram); + GoUniformfv(glprogram, location, 1, 1, &v0); +} +void gl4es_glProgramUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1) { + DBG(printf("glUniform2f(%d, %f, %f)\n", location, v0, v1);) + PUSH_IF_COMPILING(glUniform2f); + GLfloat fl[2] = {v0, v1}; + CHECK_PROGRAM(void, program); + APPLY_PROGRAM(program, glprogram); + GoUniformfv(glprogram, location, 2, 1, fl); +} +void gl4es_glProgramUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2) { + DBG(printf("glUniform3f(%d, %f, %f, %f)\n", location, v0, v1, v2);) + PUSH_IF_COMPILING(glUniform3f); + GLfloat fl[3] = {v0, v1, v2}; + CHECK_PROGRAM(void, program); + APPLY_PROGRAM(program, glprogram); + GoUniformfv(glprogram, location, 3, 1, fl); +} +void gl4es_glProgramUniform4f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3) { + DBG(printf("glUniform4f(%d, %f, %f, %f, %f)\n", location, v0, v1, v2, v3);) + PUSH_IF_COMPILING(glUniform4f); + GLfloat fl[4] = {v0, v1, v2, v3}; + CHECK_PROGRAM(void, program); + APPLY_PROGRAM(program, glprogram); + GoUniformfv(glprogram, location, 4, 1, fl); +} +void gl4es_glProgramUniform1i(GLuint program, GLint location, GLint v0) { + DBG(printf("glUniform1i(%d, %d)\n", location, v0);) + PUSH_IF_COMPILING(glUniform1i); + CHECK_PROGRAM(void, program); + APPLY_PROGRAM(program, glprogram); + GoUniformiv(glprogram, location, 1, 1, &v0); +} +void gl4es_glProgramUniform2i(GLuint program, GLint location, GLint v0, GLint v1) { + DBG(printf("glUniform2i(%d, %d, %d)\n", location, v0, v1);) + PUSH_IF_COMPILING(glUniform2i); + GLint fl[2] = {v0, v1}; + CHECK_PROGRAM(void, program); + APPLY_PROGRAM(program, glprogram); + GoUniformiv(glprogram, location, 2, 1, fl); +} +void gl4es_glProgramUniform3i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2) { + DBG(printf("glUniform3i(%d, %d, %d, %d)\n", location, v0, v1, v2);) + PUSH_IF_COMPILING(glUniform3i); + GLint fl[3] = {v0, v1, v2}; + CHECK_PROGRAM(void, program); + APPLY_PROGRAM(program, glprogram); + GoUniformiv(glprogram, location, 3, 1, fl); +} +void gl4es_glProgramUniform4i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2, GLint v3) { + DBG(printf("glUniform4i(%d, %d, %d, %d, %d)\n", location, v0, v1, v2, v3);) + PUSH_IF_COMPILING(glUniform4i); + GLint fl[4] = {v0, v1, v2, v3}; + CHECK_PROGRAM(void, program); + APPLY_PROGRAM(program, glprogram); + GoUniformiv(glprogram, location, 4, 1, fl); +} +//TODO: the "v" variant and matrix variant cannot be pushed simply... +void gl4es_glProgramUniform1fv(GLuint program, GLint location, GLsizei count, const GLfloat *value) { + DBG(printf("glUniform1fv(%d, %d, %p) =>(%f)\n", location, count, value, value[0]);) + PUSH_IF_COMPILING(glUniform1fv); + CHECK_PROGRAM(void, program); + APPLY_PROGRAM(program, glprogram); + GoUniformfv(glprogram, location, 1, count, value); +} +void gl4es_glProgramUniform2fv(GLuint program, GLint location, GLsizei count, const GLfloat *value) { + DBG(printf("glUniform2fv(%d, %d, %p) =>(%f %f)\n", location, count, value, value[0], value[1]);) + PUSH_IF_COMPILING(glUniform2fv); + CHECK_PROGRAM(void, program); + APPLY_PROGRAM(program, glprogram); + GoUniformfv(glprogram, location, 2, count, value); +} +void gl4es_glProgramUniform3fv(GLuint program, GLint location, GLsizei count, const GLfloat *value) { + DBG(printf("glUniform3fv(%d, %d, %p) =>(%f %f, %f)\n", location, count, value, value[0], value[1], value[2]);) + PUSH_IF_COMPILING(glUniform3fv); + CHECK_PROGRAM(void, program); + APPLY_PROGRAM(program, glprogram); + GoUniformfv(glprogram, location, 3, count, value); +} +void gl4es_glProgramUniform4fv(GLuint program, GLint location, GLsizei count, const GLfloat *value) { + DBG(printf("glUniform4fv(%d, %d, %p) =>(%f %f, %f, %f)\n", location, count, value, value[0], value[1], value[2], value[3]);) + PUSH_IF_COMPILING(glUniform4fv); + CHECK_PROGRAM(void, program); + APPLY_PROGRAM(program, glprogram); + GoUniformfv(glprogram, location, 4, count, value); +} +void gl4es_glProgramUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value) { + PUSH_IF_COMPILING(glUniform1iv); + CHECK_PROGRAM(void, program); + APPLY_PROGRAM(program, glprogram); + GoUniformiv(glprogram, location, 1, count, value); +} +void gl4es_glProgramUniform2iv(GLuint program, GLint location, GLsizei count, const GLint *value) { + PUSH_IF_COMPILING(glUniform2iv); + CHECK_PROGRAM(void, program); + APPLY_PROGRAM(program, glprogram); + GoUniformiv(glprogram, location, 2, count, value); +} +void gl4es_glProgramUniform3iv(GLuint program, GLint location, GLsizei count, const GLint *value) { + PUSH_IF_COMPILING(glUniform3iv); + CHECK_PROGRAM(void, program); + APPLY_PROGRAM(program, glprogram); + GoUniformiv(glprogram, location, 3, count, value); +} +void gl4es_glProgramUniform4iv(GLuint program, GLint location, GLsizei count, const GLint *value) { + PUSH_IF_COMPILING(glUniform4iv); + CHECK_PROGRAM(void, program); + APPLY_PROGRAM(program, glprogram); + GoUniformiv(glprogram, location, 4, count, value); +} + +void gl4es_glProgramUniformMatrix2fv(GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) { + DBG(printf("glUniformMatrix2fv(%d, %d, %d, %p)\n", location, count, transpose, value);) + PUSH_IF_COMPILING(glUniformMatrix2fv); + CHECK_PROGRAM(void, program); + APPLY_PROGRAM(program, glprogram); + GoUniformMatrix2fv(glprogram, location, count, transpose, value); +} + +void GoUniformMatrix2fv(program_t *glprogram, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) { + DBG(printf("GoUniformMatrix2fv(%p[%d], %d, %d, %d, %p)\n", glprogram, glprogram->id, location, count, transpose, value);) + if(location==-1) { + noerrorShim(); + return; + } + if(count<0) { + errorShim(GL_INVALID_VALUE); + return; + } + khint_t k; + uniform_t *m; + k = kh_get(uniformlist, glprogram->uniform, location); + if (k==kh_end(glprogram->uniform)) { + errorShim(GL_INVALID_OPERATION); + return; + } + m = kh_value(glprogram->uniform, k); + if(m->type!=GL_FLOAT_MAT2 || count>m->size) { + errorShim(GL_INVALID_OPERATION); + return; + } + // transpose if needed + GLfloat *v = (GLfloat*)value; + GLfloat tmp[4]; + if(transpose) { + v = tmp; + for (int n=0; ncache.cache + m->cache_offs, v, rsize)==0) { + noerrorShim(); + return; // nothing to do, same value already there + } + // update uniform + memcpy(glprogram->cache.cache + m->cache_offs, v, rsize); + LOAD_GLES2(glUniformMatrix2fv); + if (gles_glUniformMatrix2fv) { + gles_glUniformMatrix2fv(m->id, count, GL_FALSE, v); + errorGL(); + } else + errorShim(GL_INVALID_OPERATION); // no GLSL hardware +} + +void gl4es_glUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) { + DBG(printf("glUniformMatrix3fv(%d, %d, %d, %p)\n", location, count, transpose, value);) + PUSH_IF_COMPILING(glUniformMatrix3fv); + GLuint program = glstate->glsl->program; + CHECK_PROGRAM(void, program); + APPLY_PROGRAM(program, glprogram); + GoUniformMatrix3fv(glprogram, location, count, transpose, value); +} + +void gl4es_glProgramUniformMatrix3fv(GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) { + DBG(printf("glUniformMatrix3fv(%d, %d, %d, %p)\n", location, count, transpose, value);) + PUSH_IF_COMPILING(glUniformMatrix3fv); + CHECK_PROGRAM(void, program); + APPLY_PROGRAM(program, glprogram); + GoUniformMatrix3fv(glprogram, location, count, transpose, value); +} + +void GoUniformMatrix3fv(program_t *glprogram, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) { + DBG(printf("GoUniformMatrix3fv(%p[%d], %d, %d, %d, %p)\n", glprogram, glprogram->id, location, count, transpose, value);) + if(location==-1) { + noerrorShim(); + return; + } + if(count<0) { + errorShim(GL_INVALID_VALUE); + return; + } + khint_t k; + uniform_t *m; + k = kh_get(uniformlist, glprogram->uniform, location); + if (k==kh_end(glprogram->uniform)) { + errorShim(GL_INVALID_OPERATION); + return; + } + m = kh_value(glprogram->uniform, k); + if(m->type!=GL_FLOAT_MAT3 || count>m->size) { + errorShim(GL_INVALID_OPERATION); + return; + } + // transpose if needed + GLfloat *v = (GLfloat*)value; + GLfloat tmp[9]; + if(transpose) { + v = tmp; + for (int n=0; ncache.cache + m->cache_offs, v, rsize)==0) { + noerrorShim(); + return; // nothing to do, same value already there + } + // update uniform + memcpy(glprogram->cache.cache + m->cache_offs, v, rsize); + LOAD_GLES2(glUniformMatrix3fv); + if (gles_glUniformMatrix3fv) { + gles_glUniformMatrix3fv(m->id, count, GL_FALSE, v); + errorGL(); + } else + errorShim(GL_INVALID_OPERATION); // no GLSL hardware +} +void gl4es_glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) { + DBG(printf("glUniformMatrix4fv(%d, %d, %d, %p) p=>(%f, %f, %f, %f, %f...)\n", location, count, transpose, value, value[0], value[1], value[2], value[3], value[4]);) + PUSH_IF_COMPILING(glUniformMatrix4fv); + GLuint program = glstate->glsl->program; + CHECK_PROGRAM(void, program); + APPLY_PROGRAM(program, glprogram); + GoUniformMatrix4fv(glprogram, location, count, transpose, value); +} +void gl4es_glProgramUniformMatrix4fv(GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) { + DBG(printf("glUniformMatrix4fv(%d, %d, %d, %p) p=>(%f, %f, %f, %f, %f...)\n", location, count, transpose, value, value[0], value[1], value[2], value[3], value[4]);) + PUSH_IF_COMPILING(glUniformMatrix4fv); + CHECK_PROGRAM(void, program); + APPLY_PROGRAM(program, glprogram); + GoUniformMatrix4fv(glprogram, location, count, transpose, value); +} + +void GoUniformMatrix4fv(program_t *glprogram, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) { + DBG(printf("GoUniformMatrix4fv(%p[%d], %d, %d, %d, %p) p=>(%f, %f, %f, %f, %f...)\n", glprogram, glprogram->id, location, count, transpose, value, value[0], value[1], value[2], value[3], value[4]);) + if(location==-1) { + noerrorShim(); + return; + } + if(count<0) { + errorShim(GL_INVALID_VALUE); + return; + } + khint_t k; + uniform_t *m; + k = kh_get(uniformlist, glprogram->uniform, location); + if (k==kh_end(glprogram->uniform)) { + errorShim(GL_INVALID_OPERATION); + return; + } + m = kh_value(glprogram->uniform, k); + if(m->type!=GL_FLOAT_MAT4 || count>m->size) { + errorShim(GL_INVALID_OPERATION); + return; + } + // transpose if needed + GLfloat *v = (GLfloat*)value; + GLfloat tmp[16]; + if(transpose) { + v = tmp; + for (int n=0; ncache.cache + m->cache_offs, v, rsize)==0) { + noerrorShim(); + return; // nothing to do, same value already there + } + // update uniform + memcpy(glprogram->cache.cache + m->cache_offs, v, rsize); + LOAD_GLES2(glUniformMatrix4fv); + if (gles_glUniformMatrix4fv) { + gles_glUniformMatrix4fv(m->id, count, GL_FALSE, v); + errorGL(); + } else { + //printf("No GLES2 function\n"); + errorShim(GL_INVALID_OPERATION); // no GLSL hardware + } +} + +int GetUniformi(program_t *glprogram, GLint location) +{ + if(location==-1) { + noerrorShim(); + return 0; + } + + khint_t k; + uniform_t *m; + k = kh_get(uniformlist, glprogram->uniform, location); + if (k==kh_end(glprogram->uniform)) { + return 0; + } + m = kh_value(glprogram->uniform, k); + + // ok, grab the value in the cache + GLint ret; + memcpy(&ret, glprogram->cache.cache + m->cache_offs, sizeof(GLint)); + return ret; +} + +const char* GetUniformName(program_t *glprogram, GLint location) +{ + if(location==-1) { + noerrorShim(); + return 0; + } + + khint_t k; + uniform_t *m; + k = kh_get(uniformlist, glprogram->uniform, location); + if (k==kh_end(glprogram->uniform)) { + return 0; + } + m = kh_value(glprogram->uniform, k); + + // ok, grab the value in the cache + return m->name; +} + +void glGetUniformfv(GLuint program, GLint location, GLfloat *params) AliasExport("gl4es_glGetUniformfv"); +void glGetUniformiv(GLuint program, GLint location, GLint *params) AliasExport("gl4es_glGetUniformiv"); +void glUniform1f(GLint location, GLfloat v0) AliasExport("gl4es_glUniform1f"); +void glUniform2f(GLint location, GLfloat v0, GLfloat v1) AliasExport("gl4es_glUniform2f"); +void glUniform3f(GLint location, GLfloat v0, GLfloat v1, GLfloat v2) AliasExport("gl4es_glUniform3f"); +void glUniform4f(GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3) AliasExport("gl4es_glUniform4f"); +void glUniform1i(GLint location, GLint v0) AliasExport("gl4es_glUniform1i"); +void glUniform2i(GLint location, GLint v0, GLint v1) AliasExport("gl4es_glUniform2i"); +void glUniform3i(GLint location, GLint v0, GLint v1, GLint v2) AliasExport("gl4es_glUniform3i"); +void glUniform4i(GLint location, GLint v0, GLint v1, GLint v2, GLint v3) AliasExport("gl4es_glUniform4i"); +void glUniform1fv(GLint location, GLsizei count, const GLfloat *value) AliasExport("gl4es_glUniform1fv"); +void glUniform2fv(GLint location, GLsizei count, const GLfloat *value) AliasExport("gl4es_glUniform2fv"); +void glUniform3fv(GLint location, GLsizei count, const GLfloat *value) AliasExport("gl4es_glUniform3fv"); +void glUniform4fv(GLint location, GLsizei count, const GLfloat *value) AliasExport("gl4es_glUniform4fv"); +void glUniform1iv(GLint location, GLsizei count, const GLint *value) AliasExport("gl4es_glUniform1iv"); +void glUniform2iv(GLint location, GLsizei count, const GLint *value) AliasExport("gl4es_glUniform2iv"); +void glUniform3iv(GLint location, GLsizei count, const GLint *value) AliasExport("gl4es_glUniform3iv"); +void glUniform4iv(GLint location, GLsizei count, const GLint *value) AliasExport("gl4es_glUniform4iv"); +void glUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) AliasExport("gl4es_glUniformMatrix2fv"); +void glUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) AliasExport("gl4es_glUniformMatrix3fv"); +void glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) AliasExport("gl4es_glUniformMatrix4fv"); + +// ============ GL_ARB_shader_objects ================ + +GLvoid glUniform1fARB(GLint location, GLfloat v0) AliasExport("gl4es_glUniform1f"); +GLvoid glUniform2fARB(GLint location, GLfloat v0, GLfloat v1) AliasExport("gl4es_glUniform2f"); +GLvoid glUniform3fARB(GLint location, GLfloat v0, GLfloat v1, GLfloat v2) AliasExport("gl4es_glUniform3f"); +GLvoid glUniform4fARB(GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3) AliasExport("gl4es_glUniform4f"); + +GLvoid glUniform1iARB(GLint location, GLint v0) AliasExport("gl4es_glUniform1i"); +GLvoid glUniform2iARB(GLint location, GLint v0, GLint v1) AliasExport("gl4es_glUniform2i"); +GLvoid glUniform3iARB(GLint location, GLint v0, GLint v1, GLint v2) AliasExport("gl4es_glUniform3i"); +GLvoid glUniform4iARB(GLint location, GLint v0, GLint v1, GLint v2, GLint v3) AliasExport("gl4es_glUniform4i"); + +GLvoid glUniform1fvARB(GLint location, GLsizei count, const GLfloat *value) AliasExport("gl4es_glUniform1fv"); +GLvoid glUniform2fvARB(GLint location, GLsizei count, const GLfloat *value) AliasExport("gl4es_glUniform2fv"); +GLvoid glUniform3fvARB(GLint location, GLsizei count, const GLfloat *value) AliasExport("gl4es_glUniform3fv"); +GLvoid glUniform4fvARB(GLint location, GLsizei count, const GLfloat *value) AliasExport("gl4es_glUniform4fv"); + +GLvoid glUniform1ivARB(GLint location, GLsizei count, const GLint *value) AliasExport("gl4es_glUniform1iv"); +GLvoid glUniform2ivARB(GLint location, GLsizei count, const GLint *value) AliasExport("gl4es_glUniform2iv"); +GLvoid glUniform3ivARB(GLint location, GLsizei count, const GLint *value) AliasExport("gl4es_glUniform3iv"); +GLvoid glUniform4ivARB(GLint location, GLsizei count, const GLint *value) AliasExport("gl4es_glUniform4iv"); + +GLvoid glUniformMatrix2fvARB(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) AliasExport("gl4es_glUniformMatrix2fv"); +GLvoid glUniformMatrix3fvARB(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) AliasExport("gl4es_glUniformMatrix3fv"); +GLvoid glUniformMatrix4fvARB(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) AliasExport("gl4es_glUniformMatrix4fv"); + +GLvoid glGetUniformfvARB(GLhandleARB programObj, GLint location, GLfloat *params) AliasExport("gl4es_glGetUniformfv"); +GLvoid glGetUniformivARB(GLhandleARB programObj, GLint location, GLint *params) AliasExport("gl4es_glGetUniformiv"); + +// =============== +void glProgramUniform1f(GLuint program, GLint location, GLfloat v0) AliasExport("gl4es_glProgramUniform1f"); +void glProgramUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1) AliasExport("gl4es_glProgramUniform2f"); +void glProgramUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2) AliasExport("gl4es_glProgramUniform3f"); +void glProgramUniform4f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3) AliasExport("gl4es_glProgramUniform4f"); +void glProgramUniform1i(GLuint program, GLint location, GLint v0) AliasExport("gl4es_glProgramUniform1i"); +void glProgramUniform2i(GLuint program, GLint location, GLint v0, GLint v1) AliasExport("gl4es_glProgramUniform2i"); +void glProgramUniform3i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2) AliasExport("gl4es_glProgramUniform3i"); +void glProgramUniform4i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2, GLint v3) AliasExport("gl4es_glProgramUniform4i"); +void glProgramUniform1fv(GLuint program, GLint location, GLsizei count, const GLfloat *value) AliasExport("gl4es_glProgramUniform1fv"); +void glProgramUniform2fv(GLuint program, GLint location, GLsizei count, const GLfloat *value) AliasExport("gl4es_glProgramUniform2fv"); +void glProgramUniform3fv(GLuint program, GLint location, GLsizei count, const GLfloat *value) AliasExport("gl4es_glProgramUniform3fv"); +void glProgramUniform4fv(GLuint program, GLint location, GLsizei count, const GLfloat *value) AliasExport("gl4es_glProgramUniform4fv"); +void glProgramUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value) AliasExport("gl4es_glProgramUniform1iv"); +void glProgramUniform2iv(GLuint program, GLint location, GLsizei count, const GLint *value) AliasExport("gl4es_glProgramUniform2iv"); +void glProgramUniform3iv(GLuint program, GLint location, GLsizei count, const GLint *value) AliasExport("gl4es_glProgramUniform3iv"); +void glProgramUniform4iv(GLuint program, GLint location, GLsizei count, const GLint *value) AliasExport("gl4es_glProgramUniform4iv"); +void glProgramUniformMatrix2fv(GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) AliasExport("gl4es_glProgramUniformMatrix2fv"); +void glProgramUniformMatrix3fv(GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) AliasExport("gl4es_glProgramUniformMatrix3fv"); +void glProgramUniformMatrix4fv(GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) AliasExport("gl4es_glProgramUniformMatrix4fv"); +// =============== EXT_direct_state_access (part of it) +void glProgramUniform1fEXT(GLuint program, GLint location, GLfloat v0) AliasExport("gl4es_glProgramUniform1f"); +void glProgramUniform2fEXT(GLuint program, GLint location, GLfloat v0, GLfloat v1) AliasExport("gl4es_glProgramUniform2f"); +void glProgramUniform3fEXT(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2) AliasExport("gl4es_glProgramUniform3f"); +void glProgramUniform4fEXT(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3) AliasExport("gl4es_glProgramUniform4f"); +void glProgramUniform1iEXT(GLuint program, GLint location, GLint v0) AliasExport("gl4es_glProgramUniform1i"); +void glProgramUniform2iEXT(GLuint program, GLint location, GLint v0, GLint v1) AliasExport("gl4es_glProgramUniform2i"); +void glProgramUniform3iEXT(GLuint program, GLint location, GLint v0, GLint v1, GLint v2) AliasExport("gl4es_glProgramUniform3i"); +void glProgramUniform4iEXT(GLuint program, GLint location, GLint v0, GLint v1, GLint v2, GLint v3) AliasExport("gl4es_glProgramUniform4i"); +void glProgramUniform1fvEXT(GLuint program, GLint location, GLsizei count, const GLfloat *value) AliasExport("gl4es_glProgramUniform1fv"); +void glProgramUniform2fvEXT(GLuint program, GLint location, GLsizei count, const GLfloat *value) AliasExport("gl4es_glProgramUniform2fv"); +void glProgramUniform3fvEXT(GLuint program, GLint location, GLsizei count, const GLfloat *value) AliasExport("gl4es_glProgramUniform3fv"); +void glProgramUniform4fvEXT(GLuint program, GLint location, GLsizei count, const GLfloat *value) AliasExport("gl4es_glProgramUniform4fv"); +void glProgramUniform1ivEXT(GLuint program, GLint location, GLsizei count, const GLint *value) AliasExport("gl4es_glProgramUniform1iv"); +void glProgramUniform2ivEXT(GLuint program, GLint location, GLsizei count, const GLint *value) AliasExport("gl4es_glProgramUniform2iv"); +void glProgramUniform3ivEXT(GLuint program, GLint location, GLsizei count, const GLint *value) AliasExport("gl4es_glProgramUniform3iv"); +void glProgramUniform4ivEXT(GLuint program, GLint location, GLsizei count, const GLint *value) AliasExport("gl4es_glProgramUniform4iv"); +void glProgramUniformMatrix2fvEXT(GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) AliasExport("gl4es_glProgramUniformMatrix2fv"); +void glProgramUniformMatrix3fvEXT(GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) AliasExport("gl4es_glProgramUniformMatrix3fv"); +void glProgramUniformMatrix4fvEXT(GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) AliasExport("gl4es_glProgramUniformMatrix4fv"); diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/uniform.h b/Projects/Android/jni/SupportLibs/gl4es/src/gl/uniform.h new file mode 100644 index 0000000..12bb33b --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/uniform.h @@ -0,0 +1,81 @@ +#ifndef _GL4ES_UNIFORM_H_ +#define _GL4ES_UNIFORM_H_ + +#include "gles.h" + +int uniformsize(GLenum type); +int is_uniform_int(GLenum type); +int is_uniform_float(GLenum type); +int is_uniform_matrix(GLenum type); +int n_uniform(GLenum type); + +void gl4es_glGetUniformfv(GLuint program, GLint location, GLfloat *params); +void gl4es_glGetUniformiv(GLuint program, GLint location, GLint *params); + +void gl4es_glUniform1f(GLint location, GLfloat v0); +void gl4es_glUniform2f(GLint location, GLfloat v0, GLfloat v1); +void gl4es_glUniform3f(GLint location, GLfloat v0, GLfloat v1, GLfloat v2); +void gl4es_glUniform4f(GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3); +void gl4es_glUniform1i(GLint location, GLint v0); +void gl4es_glUniform2i(GLint location, GLint v0, GLint v1); +void gl4es_glUniform3i(GLint location, GLint v0, GLint v1, GLint v2); +void gl4es_glUniform4i(GLint location, GLint v0, GLint v1, GLint v2, GLint v3); + +void gl4es_glUniform1fv(GLint location, GLsizei count, const GLfloat *value); +void gl4es_glUniform2fv(GLint location, GLsizei count, const GLfloat *value); +void gl4es_glUniform3fv(GLint location, GLsizei count, const GLfloat *value); +void gl4es_glUniform4fv(GLint location, GLsizei count, const GLfloat *value); +void gl4es_glUniform1iv(GLint location, GLsizei count, const GLint *value); +void gl4es_glUniform2iv(GLint location, GLsizei count, const GLint *value); +void gl4es_glUniform3iv(GLint location, GLsizei count, const GLint *value); +void gl4es_glUniform4iv(GLint location, GLsizei count, const GLint *value); + +void gl4es_glUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +void gl4es_glUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +void gl4es_glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); + +// ========== GL_ARB_shader_objects ============== +GLvoid glUniform1fARB(GLint location, GLfloat v0); +GLvoid glUniform2fARB(GLint location, GLfloat v0, GLfloat v1); +GLvoid glUniform3fARB(GLint location, GLfloat v0, GLfloat v1, GLfloat v2); +GLvoid glUniform4fARB(GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3); +GLvoid glUniform1iARB(GLint location, GLint v0); +GLvoid glUniform2iARB(GLint location, GLint v0, GLint v1); +GLvoid glUniform3iARB(GLint location, GLint v0, GLint v1, GLint v2); +GLvoid glUniform4iARB(GLint location, GLint v0, GLint v1, GLint v2, GLint v3); +GLvoid glUniform1fvARB(GLint location, GLsizei count, const GLfloat *value); +GLvoid glUniform2fvARB(GLint location, GLsizei count, const GLfloat *value); +GLvoid glUniform3fvARB(GLint location, GLsizei count, const GLfloat *value); +GLvoid glUniform4fvARB(GLint location, GLsizei count, const GLfloat *value); +GLvoid glUniform1ivARB(GLint location, GLsizei count, const GLint *value); +GLvoid glUniform2ivARB(GLint location, GLsizei count, const GLint *value); +GLvoid glUniform3ivARB(GLint location, GLsizei count, const GLint *value); +GLvoid glUniform4ivARB(GLint location, GLsizei count, const GLint *value); +GLvoid glUniformMatrix2fvARB(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLvoid glUniformMatrix3fvARB(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLvoid glUniformMatrix4fvARB(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +// =========== +void gl4es_glProgramUniform1f(GLuint program, GLint location, GLfloat v0); +void gl4es_glProgramUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1); +void gl4es_glProgramUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2); +void gl4es_glProgramUniform4f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3); +void gl4es_glProgramUniform1i(GLuint program, GLint location, GLint v0); +void gl4es_glProgramUniform2i(GLuint program, GLint location, GLint v0, GLint v1); +void gl4es_glProgramUniform3i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2); +void gl4es_glProgramUniform4i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2, GLint v3); + +void gl4es_glProgramUniform1fv(GLuint program, GLint location, GLsizei count, const GLfloat *value); +void gl4es_glProgramUniform2fv(GLuint program, GLint location, GLsizei count, const GLfloat *value); +void gl4es_glProgramUniform3fv(GLuint program, GLint location, GLsizei count, const GLfloat *value); +void gl4es_glProgramUniform4fv(GLuint program, GLint location, GLsizei count, const GLfloat *value); +void gl4es_glProgramUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value); +void gl4es_glProgramUniform2iv(GLuint program, GLint location, GLsizei count, const GLint *value); +void gl4es_glProgramUniform3iv(GLuint program, GLint location, GLsizei count, const GLint *value); +void gl4es_glProgramUniform4iv(GLuint program, GLint location, GLsizei count, const GLint *value); + +void gl4es_glProgramUniformMatrix2fv(GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +void gl4es_glProgramUniformMatrix3fv(GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +void gl4es_glProgramUniformMatrix4fv(GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); + + +#endif // _GL4ES_UNIFORM_H_ diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/vertexattrib.c b/Projects/Android/jni/SupportLibs/gl4es/src/gl/vertexattrib.c new file mode 100644 index 0000000..1547978 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/vertexattrib.c @@ -0,0 +1,183 @@ +#include "vertexattrib.h" + +#include "../glx/hardext.h" +#include "buffers.h" +#include "enum_info.h" +#include "gl4es.h" +#include "glstate.h" + +//#define DEBUG +#ifdef DEBUG +#define DBG(a) a +#else +#define DBG(a) +#endif + +void gl4es_glVertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid * pointer) { + DBG(printf("glVertexAttribPointer(%d, %d, %s, %d, %d, %p), vertex buffer = %p\n", index, size, PrintEnum(type), normalized, stride, pointer, (glstate->vao->vertex)?glstate->vao->vertex->data:0);) + FLUSH_BEGINEND; + // sanity test + if(index>=hardext.maxvattrib) { + errorShim(GL_INVALID_VALUE); + return; + } + if(size<1 || (size>4 && size!=GL_BGRA)) { + errorShim(GL_INVALID_VALUE); + return; + } + // TODO: test Type also + vertexattrib_t *v = &glstate->vao->vertexattrib[index]; + noerrorShim(); + if(stride==0) stride=((size==GL_BGRA)?4:size)*gl_sizeof(type); + v->size = size; + v->type = type; + v->normalized = normalized; + v->stride = stride; + v->pointer = pointer; + v->buffer = glstate->vao->vertex; + memcpy(&glstate->glesva.wanted[index], v, sizeof(vertexattrib_t)); +} +void gl4es_glEnableVertexAttribArray(GLuint index) { + DBG(printf("glEnableVertexAttrib(%d)\n", index);) + FLUSH_BEGINEND; + // sanity test + if(index>=hardext.maxvattrib) { + errorShim(GL_INVALID_VALUE); + return; + } + glstate->vao->vertexattrib[index].vaarray = 1; + glstate->glesva.wanted[index].vaarray = 1; +} +void gl4es_glDisableVertexAttribArray(GLuint index) { + DBG(printf("glDisableVertexAttrib(%d)\n", index);) + FLUSH_BEGINEND; + // sanity test + if(index>=hardext.maxvattrib) { + errorShim(GL_INVALID_VALUE); + return; + } + glstate->vao->vertexattrib[index].vaarray = 0; + glstate->glesva.wanted[index].vaarray = 0; +} + +// TODO: move the sending of the data to the Hardware when drawing, to cache change of state +void gl4es_glVertexAttrib4f(GLuint index, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3) { + DBG(printf("glVertexAttrib4f(%d, %f, %f, %f, %f)\n", index, v0, v1, v2, v3);) + FLUSH_BEGINEND; + static GLfloat f[4]; + f[0] = v0; f[1] = v1; f[2] = v2; f[3] = v3; + gl4es_glVertexAttrib4fv(index, f); +} +void gl4es_glVertexAttrib4fv(GLuint index, const GLfloat *v) { + DBG(printf("glVertexAttrib4fv(%d, %p)\n", index, v);) + FLUSH_BEGINEND; + // sanity test + if(index<0 || index>=hardext.maxvattrib) { + errorShim(GL_INVALID_VALUE); + return; + } + // test if changed + if(memcmp(glstate->vao->vertexattrib[index].current, v, 4*sizeof(GLfloat))==0) { + noerrorShim(); + return; + } + memcpy(glstate->vao->vertexattrib[index].current, v, 4*sizeof(GLfloat)); + memcpy(glstate->glesva.wanted[index].current, v, 4*sizeof(GLfloat)); +} + +#define GetVertexAttrib(suffix, Type, factor) \ +void gl4es_glGetVertexAttrib##suffix##v(GLuint index, GLenum pname, Type *params) { \ + FLUSH_BEGINEND; \ + if(index<0 || index>=hardext.maxvattrib) { \ + errorShim(GL_INVALID_VALUE); \ + return; \ + } \ + noerrorShim(); \ + switch(pname) { \ + case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING: \ + *params=(glstate->vao->vertexattrib[index].buffer)?glstate->vao->vertexattrib[index].buffer->buffer:0; \ + return; \ + case GL_VERTEX_ATTRIB_ARRAY_ENABLED: \ + *params=(glstate->vao->vertexattrib[index].vaarray)?1:0; \ + return; \ + case GL_VERTEX_ATTRIB_ARRAY_SIZE: \ + *params=glstate->vao->vertexattrib[index].size; \ + return; \ + case GL_VERTEX_ATTRIB_ARRAY_STRIDE: \ + *params=glstate->vao->vertexattrib[index].stride; \ + return; \ + case GL_VERTEX_ATTRIB_ARRAY_TYPE: \ + *params=glstate->vao->vertexattrib[index].type; \ + return; \ + case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED: \ + *params=glstate->vao->vertexattrib[index].normalized; \ + return; \ + case GL_CURRENT_VERTEX_ATTRIB: \ + for (int i=0; i<4; i++) \ + *params=glstate->vao->vertexattrib[index].current[i]*factor; \ + return; \ + case GL_VERTEX_ATTRIB_ARRAY_DIVISOR: \ + *params=glstate->vao->vertexattrib[index].divisor; \ + return; \ + } \ + errorShim(GL_INVALID_ENUM); \ +} + +GetVertexAttrib(d, GLdouble, 1.0); +GetVertexAttrib(f, GLfloat, 1.0f); +GetVertexAttrib(i, GLint, 2147483647.0f); +#undef GetVertexAttrib + +void gl4es_glGetVertexAttribPointerv(GLuint index, GLenum pname, GLvoid **pointer) { + FLUSH_BEGINEND; + // sanity test + if(index<0 || index>=hardext.maxvattrib) { + errorShim(GL_INVALID_VALUE); + return; + } + if (pname!=GL_VERTEX_ATTRIB_ARRAY_POINTER) { + errorShim(GL_INVALID_ENUM); + return; + } + *pointer = (GLvoid*)glstate->vao->vertexattrib[index].pointer; + noerrorShim(); +} + +void gl4es_glVertexAttribDivisor(GLuint index, GLuint divisor) { + FLUSH_BEGINEND; + // sanity test + if(index<0 || index>=hardext.maxvattrib) { + errorShim(GL_INVALID_VALUE); + return; + } + glstate->vao->vertexattrib[index].divisor = divisor; + glstate->glesva.wanted[index].divisor = divisor; +} + +void glVertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid * pointer) AliasExport("gl4es_glVertexAttribPointer"); +void glEnableVertexAttribArray(GLuint index) AliasExport("gl4es_glEnableVertexAttribArray"); +void glDisableVertexAttribArray(GLuint index) AliasExport("gl4es_glDisableVertexAttribArray"); +void glVertexAttrib4f(GLuint index, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3) AliasExport("gl4es_glVertexAttrib4f"); +void glVertexAttrib4fv(GLuint index, const GLfloat *v) AliasExport("gl4es_glVertexAttrib4fv"); +void glGetVertexAttribdv(GLuint index, GLenum pname, GLdouble *params) AliasExport("gl4es_glGetVertexAttribdv"); +void glGetVertexAttribfv(GLuint index, GLenum pname, GLfloat *params) AliasExport("gl4es_glGetVertexAttribfv"); +void glGetVertexAttribiv(GLuint index, GLenum pname, GLint *params) AliasExport("gl4es_glGetVertexAttribiv"); +void glGetVertexAttribPointerv(GLuint index, GLenum pname, GLvoid **pointer) AliasExport("gl4es_glGetVertexAttribPointerv"); + +// ============= GL_ARB_vertex_shader ================= +GLvoid glVertexAttrib4fARB(GLuint index, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3) AliasExport("gl4es_glVertexAttrib4f"); +GLvoid glVertexAttrib4fvARB(GLuint index, const GLfloat *v) AliasExport("gl4es_glVertexAttrib4fv"); + +GLvoid glVertexAttribPointerARB(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid *pointer) AliasExport("gl4es_glVertexAttribPointer"); + +GLvoid glEnableVertexAttribArrayARB(GLuint index) AliasExport("gl4es_glEnableVertexAttribArray"); +GLvoid glDisableVertexAttribArrayARB(GLuint index) AliasExport("gl4es_glDisableVertexAttribArray"); + +GLvoid glGetVertexAttribdvARB(GLuint index, GLenum pname, GLdouble *params) AliasExport("gl4es_glGetVertexAttribdv"); +GLvoid glGetVertexAttribfvARB(GLuint index, GLenum pname, GLfloat *params) AliasExport("gl4es_glGetVertexAttribfv"); +GLvoid glGetVertexAttribivARB(GLuint index, GLenum pname, GLint *params) AliasExport("gl4es_glGetVertexAttribiv"); +GLvoid glGetVertexAttribPointervARB(GLuint index, GLenum pname, GLvoid **pointer) AliasExport("gl4es_glGetVertexAttribPointerv"); + +// ============== GL_ARB_instanced_arrays ================= +void glVertexAttribDivisor(GLuint index, GLuint divisor) AliasExport("gl4es_glVertexAttribDivisor"); +void glVertexAttribDivisorARB(GLuint index, GLuint divisor) AliasExport("gl4es_glVertexAttribDivisor"); \ No newline at end of file diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/vertexattrib.h b/Projects/Android/jni/SupportLibs/gl4es/src/gl/vertexattrib.h new file mode 100644 index 0000000..e17b058 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/vertexattrib.h @@ -0,0 +1,25 @@ +#ifndef _GL4ES_VERTEXATTRIB_H_ +#define _GL4ES_VERTEXATTRIB_H_ + +#include "gles.h" + +// actual definition of vertexattrib_t is in buffer.h, as they are part of VAO... + +void gl4es_glVertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid * pointer); +void gl4es_glEnableVertexAttribArray(GLuint index); +void gl4es_glDisableVertexAttribArray(GLuint index); + +// other variant are defined in wrap... +void gl4es_glVertexAttrib4f(GLuint index, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3); +void gl4es_glVertexAttrib4fv(GLuint index, const GLfloat *v); + + +void gl4es_glGetVertexAttribdv(GLuint index, GLenum pname, GLdouble *params); +void gl4es_glGetVertexAttribfv(GLuint index, GLenum pname, GLfloat *params); +void gl4es_glGetVertexAttribiv(GLuint index, GLenum pname, GLint *params); +void gl4es_glGetVertexAttribPointerv(GLuint index, GLenum pname, GLvoid **pointer); + +// GL_ARB_instanced_arrays +void gl4es_glVertexAttribDivisor(GLuint index, GLuint divisor); + +#endif // _GL4ES_VERTEXATTRIB_H_ diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/wrap/gl4es.c b/Projects/Android/jni/SupportLibs/gl4es/src/gl/wrap/gl4es.c new file mode 100644 index 0000000..ee675e2 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/wrap/gl4es.c @@ -0,0 +1,901 @@ +#include "gl4es.h" + +#include "../texgen.h" +#include "../debug.h" +#include "stub.h" + +#define constDoubleToFloat(a, size) \ + GLfloat s[size]; \ + int i; \ + for (i = 0; i < size; i++) { \ + s[i] = a[i]; \ + } + +// naive wrappers + +void gl4es_glClearDepth(GLdouble depth) { + gl4es_glClearDepthf(depth); +} +void gl4es_glClipPlane(GLenum plane, const GLdouble *equation) { + constDoubleToFloat(equation, 4); + gl4es_glClipPlanef(plane, s); +} +void gl4es_glDepthRange(GLdouble nearVal, GLdouble farVal) { + gl4es_glDepthRangef(nearVal, farVal); +} +void gl4es_glFogi(GLenum pname, GLint param) { + gl4es_glFogf(pname, param); +} +void gl4es_glFogiv(GLenum pname, GLint *iparams) { + switch (pname) { + case GL_FOG_DENSITY: + case GL_FOG_START: + case GL_FOG_END: + case GL_FOG_MODE: + case GL_FOG_INDEX: + case GL_FOG_COORD_SRC: + { + gl4es_glFogf(pname, *iparams); + break; + } + case GL_FOG_COLOR: { + GLfloat params[4]; + for (int i = 0; i < 4; i++) { + params[i] = (iparams[i]>>16)*1.0f/32767.f; + } + gl4es_glFogfv(pname, params); + break; + } + } +} +void gl4es_glGetTexGendv(GLenum coord,GLenum pname,GLdouble *params) { + GLfloat fparams[4]; + gl4es_glGetTexGenfv(coord, pname, fparams); + if (pname==GL_TEXTURE_GEN_MODE) *params=fparams[0]; + else for (int i=0; i<4; i++) params[i]=fparams[i]; +} +void gl4es_glGetTexGeniv(GLenum coord,GLenum pname,GLint *params) { + GLfloat fparams[4]; + gl4es_glGetTexGenfv(coord, pname, fparams); + if (pname==GL_TEXTURE_GEN_MODE) *params=fparams[0]; + else for (int i=0; i<4; i++) params[i]=fparams[i]; +} +void gl4es_glGetMaterialiv(GLenum face, GLenum pname, GLint * params) { + GLfloat fparams[4]; + gl4es_glGetMaterialfv(face, pname, fparams); + if (pname==GL_SHININESS) *params=fparams[0]; + else { + if (pname==GL_COLOR_INDEXES) + for (int i=0; i<3; i++) params[i]=fparams[i]; + else + for (int i=0; i<4; i++) params[i]=((int)fparams[i]*32767)<<16; + } +} +void gl4es_glGetLightiv(GLenum light, GLenum pname, GLint * params) { + GLfloat fparams[4]; + gl4es_glGetLightfv(light, pname, fparams); + int n=4; + switch(pname) { + case GL_SPOT_EXPONENT: + case GL_SPOT_CUTOFF: + case GL_CONSTANT_ATTENUATION: + case GL_LINEAR_ATTENUATION: + case GL_QUADRATIC_ATTENUATION: + n=1; + break; + case GL_SPOT_DIRECTION: + n=3; + break; + } + if(pname==GL_AMBIENT || pname==GL_DIFFUSE || pname==GL_SPECULAR) + for (int i=0; i>16)*(1.0f/32767.f); + } + gl4es_glLightfv(light, pname, params); + break; + case GL_POSITION: + for (int i = 0; i < 4; i++) { + params[i] = iparams[i]; + } + gl4es_glLightfv(light, pname, params); + break; + case GL_SPOT_DIRECTION: + for (int i = 0; i < 4; i++) { + params[i] = iparams[i]; + } + gl4es_glLightfv(light, pname, params); + break; + case GL_SPOT_EXPONENT: + case GL_SPOT_CUTOFF: + case GL_CONSTANT_ATTENUATION: + case GL_LINEAR_ATTENUATION: + case GL_QUADRATIC_ATTENUATION: { + gl4es_glLightf(light, pname, *iparams); + break; + } + } +} + +void gl4es_glLightModeli(GLenum pname, GLint param) { + gl4es_glLightModelf(pname, param); +} +void gl4es_glLightModeliv(GLenum pname, GLint *iparams) { + switch (pname) { + case GL_LIGHT_MODEL_AMBIENT: { + GLfloat params[4]; + for (int i = 0; i < 4; i++) { + params[i] = (iparams[i]>>16)*1.f/32767.f; + } + gl4es_glLightModelfv(pname, params); + break; + } + case GL_LIGHT_MODEL_LOCAL_VIEWER: + case GL_LIGHT_MODEL_TWO_SIDE: { + gl4es_glLightModelf(pname, *iparams); + break; + } + } +} + +void gl4es_glMateriali(GLenum face, GLenum pname, GLint param) { + gl4es_glMaterialf(face, pname, param); +} +void gl4es_glMaterialiv(GLenum face, GLenum pname, GLint *iparams) { + //printf("glMaterialiv(%04X, %04X, [%i,...]\n", face, pname, iparams[0]); + switch (pname) { + case GL_AMBIENT: + case GL_DIFFUSE: + case GL_SPECULAR: + case GL_EMISSION: + case GL_AMBIENT_AND_DIFFUSE: + { + GLfloat params[4]; + for (int i = 0; i < 4; i++) { + params[i] = (iparams[i]>>16)*1.f/32767.f; + } + gl4es_glMaterialfv(face, pname, params); + break; + } + case GL_SHININESS: + { + gl4es_glMaterialf(face, pname, *iparams); + break; + } + case GL_COLOR_INDEXES: + { + GLfloat params[3]; + for (int i = 0; i < 3; i++) { + params[i] = iparams[i]; + } + gl4es_glMaterialfv(face, pname, params); + break; + } + } +} + +/* +void glMultiTexCoord2f(GLenum target, GLfloat s, GLfloat t) { + glMultiTexCoord4f(target, s, t, 0.0f, 1.0f); +} +* */ +void gl4es_glMultiTexCoord1f(GLenum target, GLfloat s) { + gl4es_glMultiTexCoord4f(target, s, 0, 0, 1); +} +void gl4es_glMultiTexCoord1fv(GLenum target, GLfloat *t) { + gl4es_glMultiTexCoord4f(target, t[0], 0, 0, 1); +} +void gl4es_glMultiTexCoord2f(GLenum target, GLfloat s, GLfloat t) { + gl4es_glMultiTexCoord4f(target, s, t, 0, 1); +} +void gl4es_glMultiTexCoord3f(GLenum target, GLfloat s, GLfloat t, GLfloat r) { + gl4es_glMultiTexCoord4f(target, s, t, r, 1); +} +/*void glMultiTexCoord4f(GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q) { + glMultiTexCoord2f(target, s, t); +}*/ +/*void gl4es_glMultiTexCoord2fv(GLenum target, GLfloat *t) { + gl4es_glMultiTexCoord4f(target, t[0], t[1], 0, 1); +}*/ +void gl4es_glMultiTexCoord3fv(GLenum target, GLfloat *t) { + gl4es_glMultiTexCoord4f(target, t[0], t[1], t[2], 1); +} +/*void gl4es_glMultiTexCoord4fv(GLenum target, GLfloat *t) { + gl4es_glMultiTexCoord4f(target, t[0], t[1], t[2], t[3]); +}*/ +/* +void glBlendFuncSeparateEXT (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha) { + glBlendFuncSeparate (sfactorRGB, dfactorRGB, sfactorAlpha, dfactorAlpha); +} +*/ +void gl4es_glOrtho(GLdouble left, GLdouble right, GLdouble bottom, + GLdouble top, GLdouble near, GLdouble far) { + gl4es_glOrthof(left, right, bottom, top, near, far); +} + +// OES wrappers + +void glClearDepthfOES(GLfloat depth) { + gl4es_glClearDepthf(depth); +} +void glClipPlanefOES(GLenum plane, const GLfloat *equation) { + gl4es_glClipPlanef(plane, equation); +} +void glDepthRangefOES(GLclampf near, GLclampf far) { + gl4es_glDepthRangef(near, far); +} +void glFrustumfOES(GLfloat left, GLfloat right, GLfloat bottom, + GLfloat top, GLfloat near, GLfloat far) { + gl4es_glFrustumf(left, right, bottom, top, near, far); +} +void glGetClipPlanefOES(GLenum pname, GLfloat equation[4]) { + gl4es_glGetClipPlanef(pname, equation); +} +void glOrthofOES(GLfloat left, GLfloat right, GLfloat bottom, + GLfloat top, GLfloat near, GLfloat far) { + gl4es_glOrthof(left, right, bottom, top, near, far); +} + +// glRect + +#define GL_RECT(suffix, type) \ + void gl4es_glRect##suffix(type x1, type y1, type x2, type y2) { \ + gl4es_glBegin(GL_QUADS); \ + gl4es_glVertex2##suffix(x1, y1); \ + gl4es_glVertex2##suffix(x2, y1); \ + gl4es_glVertex2##suffix(x2, y2); \ + gl4es_glVertex2##suffix(x1, y2); \ + gl4es_glEnd(); \ + } \ + void gl4es_glRect##suffix##v(const type *v) { \ + gl4es_glRect##suffix(v[0], v[1], v[2], v[3]); \ + } + +GL_RECT(d, GLdouble) +GL_RECT(f, GLfloat) +GL_RECT(i, GLint) +GL_RECT(s, GLshort) +#undef GL_RECT + +// basic thunking + +#define THUNK(suffix, type, invmax) \ +/* colors */ \ +void gl4es_glColor3##suffix(type r, type g, type b) { \ + gl4es_glColor4f(r*invmax, g*invmax, b*invmax, 1.0f); \ +} \ +void gl4es_glColor4##suffix(type r, type g, type b, type a) { \ + gl4es_glColor4f(r*invmax, g*invmax, b*invmax, a*invmax); \ +} \ +void gl4es_glColor3##suffix##v(const type *v) { \ + gl4es_glColor4f(v[0]*invmax, v[1]*invmax, v[2]*invmax, 1.0f); \ +} \ +void gl4es_glColor4##suffix##v(const type *v) { \ + gl4es_glColor4f(v[0]*invmax, v[1]*invmax, v[2]*invmax, v[3]*invmax); \ +} \ +void gl4es_glSecondaryColor3##suffix(type r, type g, type b) { \ + gl4es_glSecondaryColor3f(r*invmax, g*invmax, b*invmax); \ +} \ +void gl4es_glSecondaryColor3##suffix##v(const type *v) { \ + gl4es_glSecondaryColor3f(v[0]*invmax, v[1]*invmax, v[2]*invmax); \ +} \ +/* index */ \ +void gl4es_glIndex##suffix(type c) { \ + gl4es_glIndexf(c); \ +} \ +void gl4es_glIndex##suffix##v(const type *c) { \ + gl4es_glIndexf(c[0]); \ +} \ +/* normal */ \ +void gl4es_glNormal3##suffix(type x, type y, type z) { \ + gl4es_glNormal3f(x, y, z); \ +} \ +void gl4es_glNormal3##suffix##v(const type *v) { \ + gl4es_glNormal3f(v[0], v[1], v[2]); \ +} \ +/* raster */ \ +void gl4es_glRasterPos2##suffix(type x, type y) { \ + gl4es_glRasterPos3f(x, y, 0); \ +} \ +void gl4es_glRasterPos2##suffix##v(type *v) { \ + gl4es_glRasterPos3f(v[0], v[1], 0); \ +} \ +void gl4es_glRasterPos3##suffix(type x, type y, type z) { \ + gl4es_glRasterPos3f(x, y, z); \ +} \ +void gl4es_glRasterPos3##suffix##v(type *v) { \ + gl4es_glRasterPos3f(v[0], v[1], v[2]); \ +} \ +void gl4es_glRasterPos4##suffix(type x, type y, type z, type w) { \ + gl4es_glRasterPos4f(x, y, z, w); \ +} \ +void gl4es_glRasterPos4##suffix##v(type *v) { \ + gl4es_glRasterPos4f(v[0], v[1], v[2], v[3]); \ +} \ +void gl4es_glWindowPos2##suffix(type x, type y) { \ + gl4es_glWindowPos3f(x, y, 0); \ +} \ +void gl4es_glWindowPos2##suffix##v(type *v) { \ + gl4es_glWindowPos3f(v[0], v[1], 0); \ +} \ +void gl4es_glWindowPos3##suffix(type x, type y, type z) { \ + gl4es_glWindowPos3f(x, y, z); \ +} \ +void gl4es_glWindowPos3##suffix##v(type *v) { \ + gl4es_glWindowPos3f(v[0], v[1], v[2]); \ +} \ +/* vertex */ \ +void gl4es_glVertex2##suffix(type x, type y) { \ + gl4es_glVertex4f(x, y, 0, 1); \ +} \ +void gl4es_glVertex2##suffix##v(type *v) { \ + gl4es_glVertex4f(v[0], v[1], 0 ,1); \ +} \ +void gl4es_glVertex3##suffix(type x, type y, type z) { \ + gl4es_glVertex4f(x, y, z, 1); \ +} \ +void gl4es_glVertex3##suffix##v(type *v) { \ + gl4es_glVertex4f(v[0], v[1], v[2], 1); \ +} \ +void gl4es_glVertex4##suffix(type r, type g, type b, type w) { \ + gl4es_glVertex4f(r, g, b, w); \ +} \ +void gl4es_glVertex4##suffix##v(type *v) { \ + gl4es_glVertex4f(v[0], v[1], v[2], v[3]); \ +} \ +/* texture */ \ +void gl4es_glTexCoord1##suffix(type s) { \ + gl4es_glTexCoord4f(s, 0, 0, 1); \ +} \ +void gl4es_glTexCoord1##suffix##v(type *t) { \ + gl4es_glTexCoord4f(t[0], 0, 0, 1); \ +} \ +void gl4es_glTexCoord2##suffix(type s, type t) { \ + gl4es_glTexCoord4f(s, t, 0, 1); \ +} \ +void gl4es_glTexCoord2##suffix##v(type *t) { \ + gl4es_glTexCoord4f(t[0], t[1], 0, 1); \ +} \ +void gl4es_glTexCoord3##suffix(type s, type t, type r) { \ + gl4es_glTexCoord4f(s, t, r, 1); \ +} \ +void gl4es_glTexCoord3##suffix##v(type *t) { \ + gl4es_glTexCoord4f(t[0], t[1], t[2], 1); \ +} \ +void gl4es_glTexCoord4##suffix(type s, type t, type r, type q) { \ + gl4es_glTexCoord4f(s, t, r, q); \ +} \ +void gl4es_glTexCoord4##suffix##v(type *t) { \ + gl4es_glTexCoord4f(t[0], t[1], t[2], t[3]); \ +} \ +/* multi-texture */ \ +void gl4es_glMultiTexCoord1##suffix(GLenum target, type s) { \ + gl4es_glMultiTexCoord4f(target, s, 0, 0, 1); \ +} \ +void gl4es_glMultiTexCoord1##suffix##v(GLenum target, type *t) { \ + gl4es_glMultiTexCoord4f(target, t[0], 0, 0, 1); \ +} \ +void gl4es_glMultiTexCoord2##suffix(GLenum target, type s, type t) { \ + gl4es_glMultiTexCoord4f(target, s, t, 0, 1); \ +} \ +void gl4es_glMultiTexCoord2##suffix##v(GLenum target, type *t) { \ + gl4es_glMultiTexCoord4f(target, t[0], t[1], 0, 1); \ +} \ +void gl4es_glMultiTexCoord3##suffix(GLenum target, type s, type t, type r) { \ + gl4es_glMultiTexCoord4f(target, s, t, r, 1); \ +} \ +void gl4es_glMultiTexCoord3##suffix##v(GLenum target, type *t) { \ + gl4es_glMultiTexCoord4f(target, t[0], t[1], t[2], 1); \ +} \ +void gl4es_glMultiTexCoord4##suffix(GLenum target, type s, type t, type r, type q) { \ + gl4es_glMultiTexCoord4f(target, s, t, r, q); \ +} \ +void gl4es_glMultiTexCoord4##suffix##v(GLenum target, type *t) { \ + gl4es_glMultiTexCoord4f(target, t[0], t[1], t[2], t[3]); \ +} + + +THUNK(b, GLbyte, (1.0f/(float)CHAR_MAX)) +THUNK(d, GLdouble, 1.0f) +THUNK(i, GLint, (1.0f/(float)INT_MAX)) +THUNK(s, GLshort, (1.0f/(float)SHRT_MAX)) +THUNK(ub, GLubyte, (1.0f/(float)UCHAR_MAX)) +THUNK(ui, GLuint, (1.0f/(float)UINT_MAX)) +THUNK(us, GLushort, (1.0f/(float)USHRT_MAX)) + +#undef THUNK + +// manually defined float wrappers, because we don't autowrap float functions + +// color +void gl4es_glColor3f(GLfloat r, GLfloat g, GLfloat b) { + gl4es_glColor4f(r, g, b, 1.0f); +} +void gl4es_glColor3fv(GLfloat *c) { + gl4es_glColor4f(c[0], c[1], c[2], 1.0f); +} +/*void gl4es_glColor4fv(GLfloat *c) { + gl4es_glColor4f(c[0], c[1], c[2], c[3]); +}*/ +void gl4es_glIndexfv(const GLfloat *c) { + gl4es_glIndexf(*c); +} +void gl4es_glSecondaryColor3fv(const GLfloat *v) { + gl4es_glSecondaryColor3f(v[0], v[1], v[2]); +} +void glSecondaryColor3fvEXT(GLfloat *t) AliasExport("gl4es_glSecondaryColor3fv"); + + +// raster +void gl4es_glRasterPos2f(GLfloat x, GLfloat y) { + gl4es_glRasterPos3f(x, y, 0.0f); +} +void gl4es_glRasterPos2fv(const GLfloat *v) { + gl4es_glRasterPos3f(v[0], v[1], 0.0f); +} +void gl4es_glRasterPos3fv(const GLfloat *v) { + gl4es_glRasterPos3f(v[0], v[1], v[2]); +} +void gl4es_glRasterPos4f(GLfloat x, GLfloat y, GLfloat z, GLfloat w) { + gl4es_glRasterPos3f(x/w, y/w, z/w); +} +void gl4es_glRasterPos4fv(const GLfloat *v) { + gl4es_glRasterPos4f(v[0], v[1], v[2], v[3]); +} +void gl4es_glWindowPos2f(GLfloat x, GLfloat y) { + gl4es_glWindowPos3f(x, y, 0.0f); +} +void gl4es_glWindowPos2fv(const GLfloat *v) { + gl4es_glWindowPos3f(v[0], v[1], 0.0f); +} +void gl4es_glWindowPos3fv(const GLfloat *v) { + gl4es_glWindowPos3f(v[0], v[1], v[2]); +} + +// eval +void gl4es_glEvalCoord1d(GLdouble u) { + gl4es_glEvalCoord1f(u); +} + +void gl4es_glEvalCoord2d(GLdouble u, GLdouble v) { + gl4es_glEvalCoord2f(u, v); +} + +void gl4es_glEvalCoord1fv(GLfloat *v) { + gl4es_glEvalCoord1f(v[0]); +} + +void gl4es_glEvalCoord1dv(GLdouble *v) { + gl4es_glEvalCoord1d(v[0]); +} + +void gl4es_glEvalCoord2fv(GLfloat *v) { + gl4es_glEvalCoord2f(v[0], v[1]); +} + +void gl4es_glEvalCoord2dv(GLdouble *v) { + gl4es_glEvalCoord2d(v[0], v[1]); +} + +void gl4es_glMapGrid1d(GLint un, GLdouble u1, GLdouble u2) { + gl4es_glMapGrid1f(un, u1, u2); +} + +void gl4es_glMapGrid2d(GLint un, GLdouble u1, GLdouble u2, + GLint vn, GLdouble v1, GLdouble v2) { + gl4es_glMapGrid2f(un, u1, u2, vn, v1, v2); +} + +// matrix +void gl4es_glLoadMatrixd(const GLdouble *m) { + constDoubleToFloat(m, 16); + gl4es_glLoadMatrixf(s); +} +void gl4es_glMultMatrixd(const GLdouble *m) { + constDoubleToFloat(m, 16); + gl4es_glMultMatrixf(s); +} + +// normal +/*void gl4es_glNormal3fv(GLfloat *v) { + gl4es_glNormal3f(v[0], v[1], v[2]); +}*/ + +// textures +void gl4es_glTexCoord1f(GLfloat s) { + gl4es_glTexCoord4f(s, 0, 0, 1); +} +void gl4es_glTexCoord1fv(GLfloat *t) { + gl4es_glTexCoord4f(t[0], 0, 0, 1); +} +void gl4es_glTexCoord2f(GLfloat s, GLfloat t) { + gl4es_glTexCoord4f(s, t, 0, 1); +} +void gl4es_glTexCoord2fv(GLfloat *t) { +// gl4es_glTexCoord4f(t[0], t[1], 0, 1); + gl4es_glMultiTexCoord2fv(GL_TEXTURE0, t); +} +void gl4es_glTexCoord3f(GLfloat s, GLfloat t, GLfloat r) { + gl4es_glTexCoord4f(s, t, r, 1); +} +void gl4es_glTexCoord3fv(GLfloat *t) { + gl4es_glTexCoord4f(t[0], t[1], t[2], 1); +} +/*void glTexCoord4f(GLfloat s, GLfloat t, GLfloat r, GLfloat q) { + glTexCoord2f(s, t); +}*/ +void gl4es_glTexCoord4fv(GLfloat *t) { + gl4es_glTexCoord4f(t[0], t[1], t[2], t[3]); +} + +// texgen +void gl4es_glTexGend(GLenum coord, GLenum pname, GLdouble param) { + gl4es_glTexGenf(coord, pname, param); +} +void gl4es_glTexGenf(GLenum coord, GLenum pname, GLfloat param) { + GLfloat params[4] = {0,0,0,0}; + params[0] = param; + gl4es_glTexGenfv(coord, pname, params); +} +void gl4es_glTexGendv(GLenum coord, GLenum pname, const GLdouble *params) { + GLfloat tmp[4]; + tmp[0]=params[0]; + if ((pname==GL_OBJECT_PLANE) || (pname==GL_EYE_PLANE)) + for (int i=1; i<4; i++) + tmp[i]=params[i]; + gl4es_glTexGenfv(coord, pname, tmp); +} +void gl4es_glTexGeniv(GLenum coord, GLenum pname, const GLint *params) { + GLfloat tmp[4]; + tmp[0]=params[0]; + if ((pname==GL_OBJECT_PLANE) || (pname==GL_EYE_PLANE)) + for (int i=1; i<4; i++) + tmp[i]=params[i]; + gl4es_glTexGenfv(coord, pname, tmp); +} + +// transforms +void gl4es_glRotated(GLdouble angle, GLdouble x, GLdouble y, GLdouble z) { + gl4es_glRotatef(angle, x, y, z); +} +void gl4es_glScaled(GLdouble x, GLdouble y, GLdouble z) { + gl4es_glScalef(x, y, z); +} +void gl4es_glTranslated(GLdouble x, GLdouble y, GLdouble z) { + gl4es_glTranslatef(x, y, z); +} + +// vertex +void gl4es_glVertex2f(GLfloat x, GLfloat y) { + gl4es_glVertex4f(x, y, 0, 1); +} +void gl4es_glVertex2fv(GLfloat *v) { + gl4es_glVertex4f(v[0], v[1], 0, 1); +} +/*void gl4es_glVertex3fv(GLfloat *v) { + gl4es_glVertex4f(v[0], v[1], v[2], 1); +}*/ +void gl4es_glVertex3f(GLfloat r, GLfloat g, GLfloat b) { + gl4es_glVertex4f(r, g, b, 1); +} +/*void gl4es_glVertex4fv(GLfloat *v) { + gl4es_glVertex4f(v[0], v[1], v[2], v[3]); +}*/ + +void gl4es_glBlendEquationSeparatei(GLuint buf, GLenum modeRGB, GLenum modeAlpha) { + // ignore buf is better than nothing... + // TODO: handle buf + gl4es_glBlendEquationSeparate(modeRGB, modeAlpha); +} + +void gl4es_glBlendFuncSeparatei(GLuint buf, GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha) { + // ignore buf is better than nothing.. + // TODO: handle buf + gl4es_glBlendFuncSeparate(srcRGB, dstRGB, srcAlpha, dstAlpha); +} + +#undef constDoubleToFloat + +void gl4es_glGetTexParameterfv(GLenum target, GLenum pname, GLfloat * params) { + gl4es_glGetTexLevelParameterfv(target, 0, pname, params); +} + +void gl4es_glGetTexParameteriv(GLenum target, GLenum pname, GLint * params) { + gl4es_glGetTexLevelParameteriv(target, 0, pname, params); +} + + +// Samples stuff +#include "../loader.h" +void gl4es_glSampleCoverage(GLclampf value, GLboolean invert) { + LOAD_GLES(glSampleCoverage); + PUSH_IF_COMPILING(glSampleCoverage) + gles_glSampleCoverage(value, invert); +} +void glSampleCoverage(GLclampf value, GLboolean invert) AliasExport("gl4es_glSampleCoverage"); +void glSampleCoverageARB(GLclampf value, GLboolean invert) AliasExport("gl4es_glSampleCoverage"); + +// VertexArray stuff +void gl4es_glVertexAttrib1f (GLuint index, GLfloat v0) { GLfloat f[4] = {0,0,0,1}; f[0] =v0; gl4es_glVertexAttrib4fv(index, f); }; +void gl4es_glVertexAttrib2f (GLuint index, GLfloat v0, GLfloat v1) { GLfloat f[4] = {0,0,0,1}; f[0] =v0; f[1]=v1; gl4es_glVertexAttrib4fv(index, f); }; +void gl4es_glVertexAttrib3f (GLuint index, GLfloat v0, GLfloat v1, GLfloat v2) { GLfloat f[4] = {0,0,0,1}; f[0] =v0; f[1]=v1; f[2]=v2; gl4es_glVertexAttrib4fv(index, f); }; +void gl4es_glVertexAttrib1fv (GLuint index, const GLfloat *v) { GLfloat f[4] = {0,0,0,1}; f[0] =v[0]; gl4es_glVertexAttrib4fv(index, f); }; \ +void gl4es_glVertexAttrib2fv (GLuint index, const GLfloat *v) { GLfloat f[4] = {0,0,0,1}; f[0] =v[0]; f[1]=v[1]; gl4es_glVertexAttrib4fv(index, f); }; \ +void gl4es_glVertexAttrib3fv (GLuint index, const GLfloat *v) { GLfloat f[4] = {0,0,0,1}; f[0] =v[0]; f[1]=v[1]; f[2]=v[2]; gl4es_glVertexAttrib4fv(index, f); }; \ +void glVertexAttrib1f (GLuint index, GLfloat v0) AliasExport("gl4es_glVertexAttrib1f"); +void glVertexAttrib2f (GLuint index, GLfloat v0, GLfloat v1) AliasExport("gl4es_glVertexAttrib2f"); +void glVertexAttrib3f (GLuint index, GLfloat v0, GLfloat v1, GLfloat v2) AliasExport("gl4es_glVertexAttrib3f"); +void glVertexAttrib1fv (GLuint index, const GLfloat *v) AliasExport("gl4es_glVertexAttrib1fv"); +void glVertexAttrib2fv (GLuint index, const GLfloat *v) AliasExport("gl4es_glVertexAttrib2fv"); +void glVertexAttrib3fv (GLuint index, const GLfloat *v) AliasExport("gl4es_glVertexAttrib3fv"); +#define THUNK(suffix, type) \ +void gl4es_glVertexAttrib1##suffix (GLuint index, type v0) { GLfloat f[4] = {0,0,0,1}; f[0] =v0; gl4es_glVertexAttrib4fv(index, f); }; \ +void gl4es_glVertexAttrib2##suffix (GLuint index, type v0, type v1) { GLfloat f[4] = {0,0,0,1}; f[0] =v0; f[1]=v1; gl4es_glVertexAttrib4fv(index, f); }; \ +void gl4es_glVertexAttrib3##suffix (GLuint index, type v0, type v1, type v2) { GLfloat f[4] = {0,0,0,1}; f[0] =v0; f[1]=v1; f[2]=v2; gl4es_glVertexAttrib4fv(index, f); }; \ +void gl4es_glVertexAttrib4##suffix (GLuint index, type v0, type v1, type v2, type v3) { GLfloat f[4] = {0,0,0,1}; f[0] =v0; f[1]=v1; f[2]=v2; f[3]=v3; gl4es_glVertexAttrib4fv(index, f); }; \ +void gl4es_glVertexAttrib1##suffix##v (GLuint index, const type *v) { GLfloat f[4] = {0,0,0,1}; f[0] =v[0]; gl4es_glVertexAttrib4fv(index, f); }; \ +void gl4es_glVertexAttrib2##suffix##v (GLuint index, const type *v) { GLfloat f[4] = {0,0,0,1}; f[0] =v[0]; f[1]=v[1]; gl4es_glVertexAttrib4fv(index, f); }; \ +void gl4es_glVertexAttrib3##suffix##v (GLuint index, const type *v) { GLfloat f[4] = {0,0,0,1}; f[0] =v[0]; f[1]=v[1]; f[2]=v[2]; gl4es_glVertexAttrib4fv(index, f); }; \ +void glVertexAttrib1##suffix (GLuint index, type v0) AliasExport("gl4es_glVertexAttrib1"#suffix); \ +void glVertexAttrib2##suffix (GLuint index, type v0, type v1) AliasExport("gl4es_glVertexAttrib2"#suffix); \ +void glVertexAttrib3##suffix (GLuint index, type v0, type v1, type v2) AliasExport("gl4es_glVertexAttrib3"#suffix); \ +void glVertexAttrib4##suffix (GLuint index, type v0, type v1, type v2, type v3) AliasExport("gl4es_glVertexAttrib4"#suffix); \ +void glVertexAttrib1##suffix##v (GLuint index, const type *v) AliasExport("gl4es_glVertexAttrib1"#suffix "v"); \ +void glVertexAttrib2##suffix##v (GLuint index, const type *v) AliasExport("gl4es_glVertexAttrib2"#suffix "v"); \ +void glVertexAttrib3##suffix##v (GLuint index, const type *v) AliasExport("gl4es_glVertexAttrib3"#suffix "v") +THUNK(s, GLshort); +THUNK(d, GLdouble); +#undef THUNK +void gl4es_glVertexAttrib4dv (GLuint index, const GLdouble *v) { GLfloat f[4] = {0,0,0,1}; f[0] =v[0]; f[1]=v[1]; f[2]=v[2]; f[3]=v[3]; gl4es_glVertexAttrib4fv(index, f); }; +void glVertexAttrib4dv (GLuint index, const GLdouble *v) AliasExport("gl4es_glVertexAttrib4dv"); + +#define THUNK(suffix, type, norm) \ +void gl4es_glVertexAttrib4##suffix##v (GLuint index, const type *v) { GLfloat f[4] = {0,0,0,1}; f[0] =v[0]; f[1]=v[1]; f[2]=v[2]; f[3]=v[3]; gl4es_glVertexAttrib4fv(index, f); }; \ +void glVertexAttrib4##suffix##v (GLuint index, const type *v) AliasExport("gl4es_glVertexAttrib4"#suffix "v"); \ +void gl4es_glVertexAttrib4N##suffix##v (GLuint index, const type *v) { GLfloat f[4] = {0,0,0,1}; f[0] =v[0]/norm; f[1]=v[1]/norm; f[2]=v[2]/norm; f[3]=v[3]/norm; gl4es_glVertexAttrib4fv(index, f); }; \ +void glVertexAttrib4N##suffix##v (GLuint index, const type *v) AliasExport("gl4es_glVertexAttrib4N"#suffix "v") +THUNK(b, GLbyte, 127.0f); +THUNK(ub, GLubyte, 255.0f); +THUNK(s, GLshort, 32767.0f); +THUNK(us, GLushort, 65535.0f); +THUNK(i, GLint, 2147483647.0f); +THUNK(ui, GLuint, 4294967295.0f); +#undef THUNK +void gl4es_glVertexAttrib4Nub(GLuint index, GLubyte v0, GLubyte v1, GLubyte v2, GLubyte v3) {GLfloat f[4] = {0,0,0,1}; f[0] =v0/255.f; f[1]=v1/255.f; f[2]=v2/255.f; f[3]=v3/255.f; gl4es_glVertexAttrib4fv(index, f); }; +void glVertexAttrib4Nub(GLuint index, GLubyte v0, GLubyte v1, GLubyte v2, GLubyte v3) AliasExport("gl4es_glVertexAttrib4Nub"); + +// ============= GL_ARB_vertex_shader ================= +GLvoid glVertexAttrib1fARB(GLuint index, GLfloat v0) AliasExport("gl4es_glVertexAttrib1f"); +GLvoid glVertexAttrib1sARB(GLuint index, GLshort v0) AliasExport("gl4es_glVertexAttrib1s"); +GLvoid glVertexAttrib1dARB(GLuint index, GLdouble v0) AliasExport("gl4es_glVertexAttrib1d"); +GLvoid glVertexAttrib2fARB(GLuint index, GLfloat v0, GLfloat v1) AliasExport("gl4es_glVertexAttrib2f"); +GLvoid glVertexAttrib2sARB(GLuint index, GLshort v0, GLshort v1) AliasExport("gl4es_glVertexAttrib2s"); +GLvoid glVertexAttrib2dARB(GLuint index, GLdouble v0, GLdouble v1) AliasExport("gl4es_glVertexAttrib2d"); +GLvoid glVertexAttrib3fARB(GLuint index, GLfloat v0, GLfloat v1, GLfloat v2) AliasExport("gl4es_glVertexAttrib3f"); +GLvoid glVertexAttrib3sARB(GLuint index, GLshort v0, GLshort v1, GLshort v2) AliasExport("gl4es_glVertexAttrib3s"); +GLvoid glVertexAttrib3dARB(GLuint index, GLdouble v0, GLdouble v1, GLdouble v2) AliasExport("gl4es_glVertexAttrib3d"); +GLvoid glVertexAttrib4sARB(GLuint index, GLshort v0, GLshort v1, GLshort v2, GLshort v3) AliasExport("gl4es_glVertexAttrib4s"); +GLvoid glVertexAttrib4dARB(GLuint index, GLdouble v0, GLdouble v1, GLdouble v2, GLdouble v3) AliasExport("gl4es_glVertexAttrib4d"); +GLvoid glVertexAttrib4NubARB(GLuint index, GLubyte x, GLubyte y, GLubyte z, GLubyte w) AliasExport("gl4es_glVertexAttrib4Nub"); + +GLvoid glVertexAttrib1fvARB(GLuint index, const GLfloat *v) AliasExport("gl4es_glVertexAttrib1fv"); +GLvoid glVertexAttrib1svARB(GLuint index, const GLshort *v) AliasExport("gl4es_glVertexAttrib1sv"); +GLvoid glVertexAttrib1dvARB(GLuint index, const GLdouble *v) AliasExport("gl4es_glVertexAttrib1dv"); +GLvoid glVertexAttrib2fvARB(GLuint index, const GLfloat *v) AliasExport("gl4es_glVertexAttrib2fv"); +GLvoid glVertexAttrib2svARB(GLuint index, const GLshort *v) AliasExport("gl4es_glVertexAttrib2sv"); +GLvoid glVertexAttrib2dvARB(GLuint index, const GLdouble *v) AliasExport("gl4es_glVertexAttrib2dv"); +GLvoid glVertexAttrib3fvARB(GLuint index, const GLfloat *v) AliasExport("gl4es_glVertexAttrib3fv"); +GLvoid glVertexAttrib3svARB(GLuint index, const GLshort *v) AliasExport("gl4es_glVertexAttrib3sv"); +GLvoid glVertexAttrib3dvARB(GLuint index, const GLdouble *v) AliasExport("gl4es_glVertexAttrib3dv"); +GLvoid glVertexAttrib4svARB(GLuint index, const GLshort *v) AliasExport("gl4es_glVertexAttrib4sv"); +GLvoid glVertexAttrib4dvARB(GLuint index, const GLdouble *v) AliasExport("gl4es_glVertexAttrib4dv"); +GLvoid glVertexAttrib4ivARB(GLuint index, const GLint *v) AliasExport("gl4es_glVertexAttrib4iv"); +GLvoid glVertexAttrib4bvARB(GLuint index, const GLbyte *v) AliasExport("gl4es_glVertexAttrib4bv"); + +GLvoid glVertexAttrib4ubvARB(GLuint index, const GLubyte *v) AliasExport("gl4es_glVertexAttrib4ubv"); +GLvoid glVertexAttrib4usvARB(GLuint index, const GLushort *v) AliasExport("gl4es_glVertexAttrib4usv"); +GLvoid glVertexAttrib4uivARB(GLuint index, const GLuint *v) AliasExport("gl4es_glVertexAttrib4uiv"); + +GLvoid glVertexAttrib4NbvARB(GLuint index, const GLbyte *v) AliasExport("gl4es_glVertexAttrib4Nbv"); +GLvoid glVertexAttrib4NsvARB(GLuint index, const GLshort *v) AliasExport("gl4es_glVertexAttrib4Nsv"); +GLvoid glVertexAttrib4NivARB(GLuint index, const GLint *v) AliasExport("gl4es_glVertexAttrib4Niv"); +GLvoid glVertexAttrib4NubvARB(GLuint index, const GLubyte *v) AliasExport("gl4es_glVertexAttrib4Nubv"); +GLvoid glVertexAttrib4NusvARB(GLuint index, const GLushort *v) AliasExport("gl4es_glVertexAttrib4Nusv"); +GLvoid glVertexAttrib4NuivARB(GLuint index, const GLuint *v) AliasExport("gl4es_glVertexAttrib4Nuiv"); + + +//Direct wrapper +void glClearDepth(GLdouble depth) AliasExport("gl4es_glClearDepth"); +void glClipPlane(GLenum plane, const GLdouble *equation) AliasExport("gl4es_glClipPlane"); +void glDepthRange(GLdouble nearVal, GLdouble farVal) AliasExport("gl4es_glDepthRange"); +void glFogi(GLenum pname, GLint param) AliasExport("gl4es_glFogi"); +void glFogiv(GLenum pname, GLint *params) AliasExport("gl4es_glFogiv"); +void glFrustum(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near, GLdouble far) AliasExport("gl4es_glFrustum"); +void glLighti(GLenum light, GLenum pname, GLint param) AliasExport("gl4es_glLighti"); +void glLightiv(GLenum light, GLenum pname, GLint *iparams) AliasExport("gl4es_glLightiv"); +void glLightModeli(GLenum pname, GLint param) AliasExport("gl4es_glLightModeli"); +void glLightModeliv(GLenum pname, GLint *iparams) AliasExport("gl4es_glLightModeliv"); +void glMateriali(GLenum face, GLenum pname, GLint param) AliasExport("gl4es_glMateriali"); +void glMaterialiv(GLenum face, GLenum pname, GLint *param) AliasExport("gl4es_glMaterialiv"); +void glOrtho(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near, GLdouble far) AliasExport("gl4es_glOrtho"); +void glGetMaterialiv(GLenum face, GLenum pname, GLint * params) AliasExport("gl4es_glGetMaterialiv"); +void glGetLightiv(GLenum light, GLenum pname, GLint * params) AliasExport("gl4es_glGetLightiv"); +void glGetClipPlane(GLenum plane, GLdouble *equation) AliasExport("gl4es_glGetClipPlane"); +//void glDrawRangeElements(GLenum mode,GLuint start,GLuint end,GLsizei count,GLenum type,const void *indices) AliasExport("gl4es_glDrawRangeElements"); +void glColor3f(GLfloat r, GLfloat g, GLfloat b) AliasExport("gl4es_glColor3f"); +void glColor3fv(GLfloat *c) AliasExport("gl4es_glColor3fv"); +//void glColor4fv(GLfloat *c) AliasExport("gl4es_glColor4fv"); +void glIndexfv(const GLfloat *c) AliasExport("gl4es_glIndexfv"); +void glSecondaryColor3fv(const GLfloat *v) AliasExport("gl4es_glSecondaryColor3fv"); +void glRasterPos2f(GLfloat x, GLfloat y) AliasExport("gl4es_glRasterPos2f"); +void glRasterPos2fv(const GLfloat *v) AliasExport("gl4es_glRasterPos2fv"); +void glRasterPos3fv(const GLfloat *v) AliasExport("gl4es_glRasterPos3fv"); +void glRasterPos4f(GLfloat x, GLfloat y, GLfloat z, GLfloat w) AliasExport("gl4es_glRasterPos4f"); +void glRasterPos4fv(const GLfloat *v) AliasExport("gl4es_glRasterPos4fv"); +void glWindowPos2f(GLfloat x, GLfloat y) AliasExport("gl4es_glWindowPos2f"); +void glWindowPos2fv(const GLfloat *v) AliasExport("gl4es_glWindowPos2fv"); +void glWindowPos3fv(const GLfloat *v) AliasExport("gl4es_glWindowPos3fv"); +void glPixelStoref(GLenum pname, GLfloat param) AliasExport("gl4es_glPixelStoref"); +void glGetTexGendv(GLenum coord,GLenum pname,GLdouble *params) AliasExport("gl4es_glGetTexGendv"); +void glGetTexGeniv(GLenum coord,GLenum pname,GLint *params) AliasExport("gl4es_glGetTexGeniv"); +void glPixelTransferi(GLenum pname, GLint param) AliasExport("gl4es_glPixelTransferi"); +void glEvalCoord1d(GLdouble u) AliasExport("gl4es_glEvalCoord1d"); +void glEvalCoord1dv(GLdouble *v) AliasExport("gl4es_glEvalCoord1dv"); +void glEvalCoord1fv(GLfloat *v) AliasExport("gl4es_glEvalCoord1fv"); +void glEvalCoord2d(GLdouble u, GLdouble v) AliasExport("gl4es_glEvalCoord2d"); +void glEvalCoord2dv(GLdouble *v) AliasExport("gl4es_glEvalCoord2dv"); +void glEvalCoord2fv(GLfloat *v) AliasExport("gl4es_glEvalCoord2fv"); +void glMapGrid1d(GLint un, GLdouble u1, GLdouble u2) AliasExport("gl4es_glMapGrid1d"); +void glMapGrid2d(GLint un, GLdouble u1, GLdouble u2, GLint vn, GLdouble v1, GLdouble v2) AliasExport("gl4es_glMapGrid2d"); +void glLoadMatrixd(const GLdouble *m) AliasExport("gl4es_glLoadMatrixd"); +void glMultMatrixd(const GLdouble *m) AliasExport("gl4es_glMultMatrixd"); +//void glNormal3fv(GLfloat *v) AliasExport("gl4es_glNormal3fv"); + +// rect +#define GL_RECT(suffix, type) \ + void glRect##suffix(type x1, type y1, type x2, type y2) AliasExport("gl4es_glRect" #suffix); \ + void glRect##suffix##v(const type *v)AliasExport("gl4es_glRect" #suffix "v"); + +GL_RECT(d, GLdouble) +GL_RECT(f, GLfloat) +GL_RECT(i, GLint) +GL_RECT(s, GLshort) +#undef GL_RECT + +void glTexCoord1f(GLfloat s) AliasExport("gl4es_glTexCoord1f"); +void glTexCoord1fv(GLfloat *t) AliasExport("gl4es_glTexCoord1fv"); +void glTexCoord2f(GLfloat s, GLfloat t) AliasExport("gl4es_glTexCoord2f"); +void glTexCoord2fv(GLfloat *t) AliasExport("gl4es_glTexCoord2fv"); +void glTexCoord3f(GLfloat s, GLfloat t, GLfloat r) AliasExport("gl4es_glTexCoord3f"); +void glTexCoord3fv(GLfloat *t) AliasExport("gl4es_glTexCoord3fv"); +void glTexCoord4fv(GLfloat *t) AliasExport("gl4es_glTexCoord4fv"); +void glMultiTexCoord1f(GLenum target, GLfloat s) AliasExport("gl4es_glMultiTexCoord1f"); +void glMultiTexCoord1fv(GLenum target, GLfloat *t) AliasExport("gl4es_glMultiTexCoord1fv"); +void glMultiTexCoord2f(GLenum target, GLfloat s, GLfloat t) AliasExport("gl4es_glMultiTexCoord2f"); +//void glMultiTexCoord2fv(GLenum target, GLfloat *t) AliasExport("gl4es_glMultiTexCoord2fv"); +void glMultiTexCoord3f(GLenum target, GLfloat s, GLfloat t, GLfloat r) AliasExport("gl4es_glMultiTexCoord3f"); +void glMultiTexCoord3fv(GLenum target, GLfloat *t) AliasExport("gl4es_glMultiTexCoord3fv"); +//void glMultiTexCoord4fv(GLenum target, GLfloat *t) AliasExport("gl4es_glMultiTexCoord4fv"); +void glGetTexLevelParameterfv(GLenum target, GLint level, GLenum pname, GLfloat *params) AliasExport("gl4es_glGetTexLevelParameterfv"); +void glTexGend(GLenum coord, GLenum pname, GLdouble param) AliasExport("gl4es_glTexGend"); +void glTexGenf(GLenum coord, GLenum pname, GLfloat param) AliasExport("gl4es_glTexGenf"); +void glTexGendv(GLenum coord, GLenum pname, const GLdouble *params) AliasExport("gl4es_glTexGendv"); +void glTexGeniv(GLenum coord, GLenum pname, const GLint *params) AliasExport("gl4es_glTexGeniv"); +void glRotated(GLdouble angle, GLdouble x, GLdouble y, GLdouble z) AliasExport("gl4es_glRotated"); +void glScaled(GLdouble x, GLdouble y, GLdouble z) AliasExport("gl4es_glScaled"); +void glTranslated(GLdouble x, GLdouble y, GLdouble z) AliasExport("gl4es_glTranslated"); +void glVertex2f(GLfloat x, GLfloat y) AliasExport("gl4es_glVertex2f"); +void glVertex2fv(GLfloat *v) AliasExport("gl4es_glVertex2fv"); +void glVertex3f(GLfloat r, GLfloat g, GLfloat b) AliasExport("gl4es_glVertex3f"); +/*void glVertex3fv(GLfloat *v) AliasExport("gl4es_glVertex3fv"); +void glVertex4fv(GLfloat *v) AliasExport("gl4es_glVertex4fv");*/ + +// basic thunking + +#define THUNK(suffix, type) \ +void glColor3##suffix##v(const type *v) AliasExport("gl4es_glColor3"#suffix "v"); \ +void glColor3##suffix(type r, type g, type b) AliasExport("gl4es_glColor3"#suffix); \ +void glColor4##suffix##v(const type *v) AliasExport("gl4es_glColor4"#suffix "v"); \ +void glColor4##suffix(type r, type g, type b, type a) AliasExport("gl4es_glColor4"#suffix); \ +void glSecondaryColor3##suffix##v(const type *v) AliasExport("gl4es_glSecondaryColor3"#suffix "v"); \ +void glSecondaryColor3##suffix(type r, type g, type b) AliasExport("gl4es_glSecondaryColor3"#suffix); \ +void glIndex##suffix##v(const type *c) AliasExport("gl4es_glIndex"#suffix"v"); \ +void glIndex##suffix(type c) AliasExport("gl4es_glIndex"#suffix); \ +void glNormal3##suffix##v(const type *v) AliasExport("gl4es_glNormal3"#suffix"v"); \ +void glNormal3##suffix(type x, type y, type z) AliasExport("gl4es_glNormal3"#suffix); \ +void glRasterPos2##suffix##v(type *v) AliasExport("gl4es_glRasterPos2"#suffix"v"); \ +void glRasterPos2##suffix(type x, type y) AliasExport("gl4es_glRasterPos2"#suffix); \ +void glRasterPos3##suffix##v(type *v) AliasExport("gl4es_glRasterPos3"#suffix"v"); \ +void glRasterPos3##suffix(type x, type y, type z) AliasExport("gl4es_glRasterPos3"#suffix); \ +void glRasterPos4##suffix##v(type *v) AliasExport("gl4es_glRasterPos4"#suffix"v"); \ +void glRasterPos4##suffix(type x, type y, type z, type w)AliasExport("gl4es_glRasterPos4"#suffix); \ +void glWindowPos2##suffix##v(type *v) AliasExport("gl4es_glWindowPos2"#suffix"v"); \ +void glWindowPos2##suffix(type x, type y) AliasExport("gl4es_glWindowPos2"#suffix); \ +void glWindowPos3##suffix##v(type *v) AliasExport("gl4es_glWindowPos3"#suffix"v"); \ +void glWindowPos3##suffix(type x, type y, type z) AliasExport("gl4es_glWindowPos3"#suffix); \ +void glVertex2##suffix##v(type *v) AliasExport("gl4es_glVertex2"#suffix"v"); \ +void glVertex2##suffix(type x, type y) AliasExport("gl4es_glVertex2"#suffix); \ +void glVertex3##suffix##v(type *v) AliasExport("gl4es_glVertex3"#suffix"v"); \ +void glVertex3##suffix(type x, type y, type z) AliasExport("gl4es_glVertex3"#suffix); \ +void glVertex4##suffix(type x, type y, type z, type w) AliasExport("gl4es_glVertex4"#suffix); \ +void glVertex4##suffix##v(type *v) AliasExport("gl4es_glVertex4"#suffix"v"); \ +void glTexCoord1##suffix(type s) AliasExport("gl4es_glTexCoord1"#suffix); \ +void glTexCoord1##suffix##v(type *t) AliasExport("gl4es_glTexCoord1"#suffix"v"); \ +void glTexCoord2##suffix(type s, type t) AliasExport("gl4es_glTexCoord2"#suffix); \ +void glTexCoord2##suffix##v(type *t) AliasExport("gl4es_glTexCoord2"#suffix"v"); \ +void glTexCoord3##suffix(type s, type t, type r) AliasExport("gl4es_glTexCoord3"#suffix); \ +void glTexCoord3##suffix##v(type *t) AliasExport("gl4es_glTexCoord3"#suffix"v"); \ +void glTexCoord4##suffix(type s, type t, type r, type q)AliasExport("gl4es_glTexCoord4"#suffix); \ +void glTexCoord4##suffix##v(type *t) AliasExport("gl4es_glTexCoord4"#suffix"v"); \ +void glMultiTexCoord1##suffix(GLenum target, type s) AliasExport("gl4es_glMultiTexCoord1"#suffix); \ +void glMultiTexCoord1##suffix##v(GLenum target, type *t)AliasExport("gl4es_glMultiTexCoord1"#suffix"v"); \ +void glMultiTexCoord2##suffix(GLenum target, type s, type t) AliasExport("gl4es_glMultiTexCoord2"#suffix); \ +void glMultiTexCoord2##suffix##v(GLenum target, type *t) AliasExport("gl4es_glMultiTexCoord2"#suffix"v"); \ +void glMultiTexCoord3##suffix(GLenum target, type s, type t, type r)AliasExport("gl4es_glMultiTexCoord3"#suffix); \ +void glMultiTexCoord3##suffix##v(GLenum target, type *t) AliasExport("gl4es_glMultiTexCoord3"#suffix"v"); \ +void glMultiTexCoord4##suffix(GLenum target, type s, type t, type r, type q) AliasExport("gl4es_glMultiTexCoord4"#suffix); \ +void glMultiTexCoord4##suffix##v(GLenum target, type *t) AliasExport("gl4es_glMultiTexCoord4"#suffix"v"); \ +void glMultiTexCoord1##suffix##ARB(GLenum target, type s) AliasExport("gl4es_glMultiTexCoord1"#suffix); \ +void glMultiTexCoord1##suffix##vARB(GLenum target, type *t) AliasExport("gl4es_glMultiTexCoord1"#suffix"v"); \ +void glMultiTexCoord2##suffix##ARB(GLenum target, type s, type t) AliasExport("gl4es_glMultiTexCoord2"#suffix); \ +void glMultiTexCoord2##suffix##vARB(GLenum target, type *t) AliasExport("gl4es_glMultiTexCoord2"#suffix"v"); \ +void glMultiTexCoord3##suffix##ARB(GLenum target, type s, type t, type r) AliasExport("gl4es_glMultiTexCoord3"#suffix); \ +void glMultiTexCoord3##suffix##vARB(GLenum target, type *t) AliasExport("gl4es_glMultiTexCoord3"#suffix"v"); \ +void glMultiTexCoord4##suffix##ARB(GLenum target, type s, type t, type r, type q) AliasExport("gl4es_glMultiTexCoord4"#suffix); \ +void glMultiTexCoord4##suffix##vARB(GLenum target, type *t)AliasExport("gl4es_glMultiTexCoord4"#suffix"v"); + +THUNK(b, GLbyte) +THUNK(d, GLdouble) +THUNK(i, GLint) +THUNK(s, GLshort) +THUNK(ub, GLubyte) +THUNK(ui, GLuint) +THUNK(us, GLushort) +#undef THUNK + +void glMultiTexCoord1fARB(GLenum target, GLfloat s) AliasExport("gl4es_glMultiTexCoord1f"); +void glMultiTexCoord2fARB(GLenum target, GLfloat s, GLfloat t) AliasExport("gl4es_glMultiTexCoord2f"); +void glMultiTexCoord3fARB(GLenum target, GLfloat s, GLfloat t, GLfloat r) AliasExport("gl4es_glMultiTexCoord3f"); +void glMultiTexCoord1fvARB(GLenum target, GLfloat *t) AliasExport("gl4es_glMultiTexCoord1fv"); +//void glMultiTexCoord2fvARB(GLenum target, GLfloat *t) AliasExport("gl4es_glMultiTexCoord2fv"); +void glMultiTexCoord3fvARB(GLenum target, GLfloat *t) AliasExport("gl4es_glMultiTexCoord3fv"); +//void glMultiTexCoord4fvARB(GLenum target, GLfloat *t) AliasExport("gl4es_glMultiTexCoord4fv"); +//void glDrawRangeElementsEXT(GLenum mode,GLuint start,GLuint end,GLsizei count,GLenum type,const void *indices) AliasExport("gl4es_glDrawRangeElements"); + +void glGetTexParameterfv(GLenum target, GLenum pname, GLfloat * params) AliasExport("gl4es_glGetTexParameterfv"); +void glGetTexParameteriv(GLenum target, GLenum pname, GLint * params) AliasExport("gl4es_glGetTexParameteriv"); diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/wrap/gl4es.h b/Projects/Android/jni/SupportLibs/gl4es/src/gl/wrap/gl4es.h new file mode 100644 index 0000000..998c6a5 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/wrap/gl4es.h @@ -0,0 +1,270 @@ +#ifndef GL_WRAP_H +#define GL_WRAP_H + +#include "../gl4es.h" +//#include + + +// misc naive wrappers + +void gl4es_glClearDepth(GLdouble depth); +void gl4es_glClipPlane(GLenum plane, const GLdouble *equation); +void gl4es_glDepthRange(GLdouble nearVal, GLdouble farVal); +void gl4es_glFogi(GLenum pname, GLint param); +void gl4es_glFogiv(GLenum pname, GLint *params); +void gl4es_glFrustum(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near, GLdouble far); +void gl4es_glGetDoublev(GLenum pname, GLdouble *params); +void gl4es_glLighti(GLenum light, GLenum pname, GLint param); +void gl4es_glLightiv(GLenum light, GLenum pname, GLint *iparams); +void gl4es_glLightModeli(GLenum pname, GLint param); +void gl4es_glLightModeliv(GLenum pname, GLint *iparams); +void gl4es_glMateriali(GLenum face, GLenum pname, GLint param); +void gl4es_glMaterialiv(GLenum face, GLenum pname, GLint *param); +void gl4es_glMultiTexCoord2f(GLenum target, GLfloat s, GLfloat t); +void gl4es_glOrtho(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near, GLdouble far); +void gl4es_glGetMaterialiv(GLenum face, GLenum pname, GLint * params); +void gl4es_glGetLightiv(GLenum light, GLenum pname, GLint * params); +void gl4es_glGetClipPlane(GLenum plane, GLdouble *equation); + +void gl4es_glDrawRangeElements(GLenum mode,GLuint start,GLuint end,GLsizei count,GLenum type,const void *indices); +// color +void gl4es_glColor3f(GLfloat r, GLfloat g, GLfloat b); +void gl4es_glColor3fv(GLfloat *c); +void gl4es_glColor4fv(GLfloat *c); +void gl4es_glIndexfv(const GLfloat *c); +void gl4es_glSecondaryColor3fv(const GLfloat *v); + +// raster +void gl4es_glRasterPos2f(GLfloat x, GLfloat y); +void gl4es_glRasterPos2fv(const GLfloat *v); +void gl4es_glRasterPos3f(GLfloat x, GLfloat y, GLfloat z); +void gl4es_glRasterPos3fv(const GLfloat *v); +void gl4es_glRasterPos4f(GLfloat x, GLfloat y, GLfloat z, GLfloat w); +void gl4es_glRasterPos4fv(const GLfloat *v); +void gl4es_glWindowPos2f(GLfloat x, GLfloat y); +void gl4es_glWindowPos2fv(const GLfloat *v); +void gl4es_glWindowPos3f(GLfloat x, GLfloat y, GLfloat z); +void gl4es_glWindowPos3fv(const GLfloat *v); + +void gl4es_glPixelStoref(GLenum pname, GLfloat param); +void gl4es_glGetTexGendv(GLenum coord,GLenum pname,GLdouble *params); +void gl4es_glGetTexGeniv(GLenum coord,GLenum pname,GLint *params); +void gl4es_glPixelTransferi(GLenum pname, GLint param); +void gl4es_glPixelTransferf(GLenum pname, GLfloat param); + +// eval +void gl4es_glEvalCoord1d(GLdouble u); +void gl4es_glEvalCoord1dv(GLdouble *v); +void gl4es_glEvalCoord1fv(GLfloat *v); +void gl4es_glEvalCoord2d(GLdouble u, GLdouble v); +void gl4es_glEvalCoord2dv(GLdouble *v); +void gl4es_glEvalCoord2fv(GLfloat *v); +void gl4es_glMapGrid1d(GLint un, GLdouble u1, GLdouble u2); +void gl4es_glMapGrid2d(GLint un, GLdouble u1, GLdouble u2, GLint vn, GLdouble v1, GLdouble v2); + +// matrix +void gl4es_glLoadMatrixd(const GLdouble *m); +void gl4es_glMultMatrixd(const GLdouble *m); + +// normal +void gl4es_glNormal3fv(GLfloat *v); + +// fog (defined in fog.c) +void gl4es_glFogCoordd(GLdouble coord); +void gl4es_glFogCoorddv(const GLdouble *coord); + +// rect +#define GL_RECT(suffix, type) \ + void gl4es_glRect##suffix(type x1, type y1, type x2, type y2); \ + void gl4es_glRect##suffix##v(const type *v); + +GL_RECT(d, GLdouble) +GL_RECT(f, GLfloat) +GL_RECT(i, GLint) +GL_RECT(s, GLshort) +#undef GL_RECT + +// textures + +void gl4es_glTexCoord1f(GLfloat s); +void gl4es_glTexCoord1fv(GLfloat *t); +void gl4es_glTexCoord2f(GLfloat s, GLfloat t); +void gl4es_glTexCoord2fv(GLfloat *t); +void gl4es_glTexCoord3f(GLfloat s, GLfloat t, GLfloat r); +void gl4es_glTexCoord3fv(GLfloat *t); +void gl4es_glTexCoord4fv(GLfloat *t); + +void gl4es_glMultiTexCoord1f(GLenum target, GLfloat s); +void gl4es_glMultiTexCoord1fv(GLenum target, GLfloat *t); +void gl4es_glMultiTexCoord2f(GLenum target, GLfloat s, GLfloat t); +void gl4es_glMultiTexCoord2fv(GLenum target, GLfloat *t); +void gl4es_glMultiTexCoord3f(GLenum target, GLfloat s, GLfloat t, GLfloat r); +void gl4es_glMultiTexCoord3fv(GLenum target, GLfloat *t); +void gl4es_glMultiTexCoord4fv(GLenum target, GLfloat *t); + +void gl4es_glGetTexLevelParameterfv(GLenum target, GLint level, GLenum pname, GLfloat *params); + +void gl4es_glPolygonMode(GLenum face, GLenum mode); + +// texgen +void gl4es_glTexGend(GLenum coord, GLenum pname, GLdouble param); +void gl4es_glTexGeni(GLenum coord, GLenum pname, GLint param); +void gl4es_glTexGenf(GLenum coord, GLenum pname, GLfloat param); +void gl4es_glTexGendv(GLenum coord, GLenum pname, const GLdouble *params); +void gl4es_glTexGenfv(GLenum coord, GLenum pname, const GLfloat *params); +void gl4es_glTexGeniv(GLenum coord, GLenum pname, const GLint *params); + +// transforms +void gl4es_glRotated(GLdouble angle, GLdouble x, GLdouble y, GLdouble z); +void gl4es_glScaled(GLdouble x, GLdouble y, GLdouble z); +void gl4es_glTranslated(GLdouble x, GLdouble y, GLdouble z); + +// vertex +void gl4es_glVertex2f(GLfloat x, GLfloat y); +void gl4es_glVertex2fv(GLfloat *v); +void gl4es_glVertex3fv(GLfloat *v); +void gl4es_glVertex3f(GLfloat r, GLfloat g, GLfloat b); +void gl4es_glVertex4fv(GLfloat *v); + +// OES wrappers + +void glClearDepthfOES(GLfloat depth); +void glClipPlanefOES(GLenum plane, const GLfloat *equation); +void glDepthRangefOES(GLclampf near, GLclampf far); +void glFrustumfOES(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat near, GLfloat far); +void glGetClipPlanefOES(GLenum plane, GLfloat equation[4]); +void glOrthofOES(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat near, GLfloat far); + +// basic thunking + +#define THUNK(suffix, type) \ +void gl4es_glColor3##suffix##v(const type *v); \ +void gl4es_glColor3##suffix(type r, type g, type b); \ +void gl4es_glColor4##suffix##v(const type *v); \ +void gl4es_glColor4##suffix(type r, type g, type b, type a); \ +void gl4es_glSecondaryColor3##suffix##v(const type *v); \ +void gl4es_glSecondaryColor3##suffix(type r, type g, type b); \ +void gl4es_glIndex##suffix##v(const type *c); \ +void gl4es_glIndex##suffix(type c); \ +void gl4es_glNormal3##suffix##v(const type *v); \ +void gl4es_glNormal3##suffix(type x, type y, type z); \ +void gl4es_glRasterPos2##suffix##v(type *v); \ +void gl4es_glRasterPos2##suffix(type x, type y); \ +void gl4es_glRasterPos3##suffix##v(type *v); \ +void gl4es_glRasterPos3##suffix(type x, type y, type z); \ +void gl4es_glRasterPos4##suffix##v(type *v); \ +void gl4es_glRasterPos4##suffix(type x, type y, type z, type w); \ +void gl4es_glWindowPos2##suffix##v(type *v); \ +void gl4es_glWindowPos2##suffix(type x, type y); \ +void gl4es_glWindowPos3##suffix##v(type *v); \ +void gl4es_glWindowPos3##suffix(type x, type y, type z); \ +void gl4es_glVertex2##suffix##v(type *v); \ +void gl4es_glVertex2##suffix(type x, type y); \ +void gl4es_glVertex3##suffix##v(type *v); \ +void gl4es_glVertex3##suffix(type x, type y, type z); \ +void gl4es_glVertex4##suffix(type x, type y, type z, type w); \ +void gl4es_glVertex4##suffix##v(type *v); \ +void gl4es_glTexCoord1##suffix(type s); \ +void gl4es_glTexCoord1##suffix##v(type *t); \ +void gl4es_glTexCoord2##suffix(type s, type t); \ +void gl4es_glTexCoord2##suffix##v(type *t); \ +void gl4es_glTexCoord3##suffix(type s, type t, type r); \ +void gl4es_glTexCoord3##suffix##v(type *t); \ +void gl4es_glTexCoord4##suffix(type s, type t, type r, type q); \ +void gl4es_glTexCoord4##suffix##v(type *t); \ +void gl4es_glMultiTexCoord1##suffix(GLenum target, type s); \ +void gl4es_glMultiTexCoord1##suffix##v(GLenum target, type *t); \ +void gl4es_glMultiTexCoord2##suffix(GLenum target, type s, type t); \ +void gl4es_glMultiTexCoord2##suffix##v(GLenum target, type *t); \ +void gl4es_glMultiTexCoord3##suffix(GLenum target, type s, type t, type r); \ +void gl4es_glMultiTexCoord3##suffix##v(GLenum target, type *t); \ +void gl4es_glMultiTexCoord4##suffix(GLenum target, type s, type t, type r, type q); \ +void gl4es_glMultiTexCoord4##suffix##v(GLenum target, type *t); \ +void gl4es_glMultiTexCoord1##suffix##ARB(GLenum target, type s); \ +void gl4es_glMultiTexCoord1##suffix##vARB(GLenum target, type *t); \ +void gl4es_glMultiTexCoord2##suffix##ARB(GLenum target, type s, type t); \ +void gl4es_glMultiTexCoord2##suffix##vARB(GLenum target, type *t); \ +void gl4es_glMultiTexCoord3##suffix##ARB(GLenum target, type s, type t, type r); \ +void gl4es_glMultiTexCoord3##suffix##vARB(GLenum target, type *t); \ +void gl4es_glMultiTexCoord4##suffix##ARB(GLenum target, type s, type t, type r, type q); \ +void gl4es_glMultiTexCoord4##suffix##vARB(GLenum target, type *t); + +THUNK(b, GLbyte) +THUNK(d, GLdouble) +THUNK(i, GLint) +THUNK(s, GLshort) +THUNK(ub, GLubyte) +THUNK(ui, GLuint) +THUNK(us, GLushort) +#undef THUNK + +#define THUNK(suffix, type) \ +void glGet##suffix##v(GLenum pname, type *params); + +THUNK(Double, GLdouble) +THUNK(Integer, GLint) +THUNK(Float, GLfloat) +#undef THUNK + +#define THUNK(suffix, type) \ +void gl4es_glVertexAttrib1##suffix(GLuint index, type v0); \ +void gl4es_glVertexAttrib2##suffix(GLuint index, type v0, type v1); \ +void gl4es_glVertexAttrib3##suffix(GLuint index, type v0, type v1, type v2); \ +void gl4es_glVertexAttrib4##suffix(GLuint index, type v0, type v1, type v2, type v3); \ +void gl4es_glVertexAttrib1##suffix##v(GLuint index, const type *v); \ +void gl4es_glVertexAttrib2##suffix##v(GLuint index, const type *v); \ +void gl4es_glVertexAttrib3##suffix##v(GLuint index, const type *v); +THUNK(s, GLshort); +THUNK(d, GLdouble); +#undef THUNK +void gl4es_glVertexAttrib4dv(GLuint index, const GLdouble *v); +#define THUNK(suffix, type) \ +void gl4es_glVertexAttrib4##suffix##v (GLuint index, const type *v); \ +void gl4es_glVertexAttrib4N##suffix##v (GLuint index, const type *v) +THUNK(b, GLbyte); +THUNK(ub, GLubyte); +THUNK(s, GLshort); +THUNK(us, GLushort); +THUNK(i, GLint); +THUNK(ui, GLuint); +#undef THUNK +void gl4es_glVertexAttrib4Nub(GLuint index, GLubyte v0, GLubyte v1, GLubyte v2, GLubyte v3); + +// ============= GL_ARB_vertex_shader ================= +GLvoid glVertexAttrib1fARB(GLuint index, GLfloat v0); +GLvoid glVertexAttrib1sARB(GLuint index, GLshort v0); +GLvoid glVertexAttrib1dARB(GLuint index, GLdouble v0); +GLvoid glVertexAttrib2fARB(GLuint index, GLfloat v0, GLfloat v1); +GLvoid glVertexAttrib2sARB(GLuint index, GLshort v0, GLshort v1); +GLvoid glVertexAttrib2dARB(GLuint index, GLdouble v0, GLdouble v1); +GLvoid glVertexAttrib3fARB(GLuint index, GLfloat v0, GLfloat v1, GLfloat v2); +GLvoid glVertexAttrib3sARB(GLuint index, GLshort v0, GLshort v1, GLshort v2); +GLvoid glVertexAttrib3dARB(GLuint index, GLdouble v0, GLdouble v1, GLdouble v2); +GLvoid glVertexAttrib4sARB(GLuint index, GLshort v0, GLshort v1, GLshort v2, GLshort v3); +GLvoid glVertexAttrib4dARB(GLuint index, GLdouble v0, GLdouble v1, GLdouble v2, GLdouble v3); +GLvoid glVertexAttrib4NubARB(GLuint index, GLubyte x, GLubyte y, GLubyte z, GLubyte w); +GLvoid glVertexAttrib1fvARB(GLuint index, const GLfloat *v); +GLvoid glVertexAttrib1svARB(GLuint index, const GLshort *v); +GLvoid glVertexAttrib1dvARB(GLuint index, const GLdouble *v); +GLvoid glVertexAttrib2fvARB(GLuint index, const GLfloat *v); +GLvoid glVertexAttrib2svARB(GLuint index, const GLshort *v); +GLvoid glVertexAttrib2dvARB(GLuint index, const GLdouble *v); +GLvoid glVertexAttrib3fvARB(GLuint index, const GLfloat *v); +GLvoid glVertexAttrib3svARB(GLuint index, const GLshort *v); +GLvoid glVertexAttrib3dvARB(GLuint index, const GLdouble *v); +GLvoid glVertexAttrib4svARB(GLuint index, const GLshort *v); +GLvoid glVertexAttrib4dvARB(GLuint index, const GLdouble *v); +GLvoid glVertexAttrib4ivARB(GLuint index, const GLint *v); +GLvoid glVertexAttrib4bvARB(GLuint index, const GLbyte *v); +GLvoid glVertexAttrib4ubvARB(GLuint index, const GLubyte *v); +GLvoid glVertexAttrib4usvARB(GLuint index, const GLushort *v); +GLvoid glVertexAttrib4uivARB(GLuint index, const GLuint *v); +GLvoid glVertexAttrib4NbvARB(GLuint index, const GLbyte *v); +GLvoid glVertexAttrib4NsvARB(GLuint index, const GLshort *v); +GLvoid glVertexAttrib4NivARB(GLuint index, const GLint *v); +GLvoid glVertexAttrib4NubvARB(GLuint index, const GLubyte *v); +GLvoid glVertexAttrib4NusvARB(GLuint index, const GLushort *v); +GLvoid glVertexAttrib4NuivARB(GLuint index, const GLuint *v); + + +#endif diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/wrap/gles.c b/Projects/Android/jni/SupportLibs/gl4es/src/gl/wrap/gles.c new file mode 100644 index 0000000..d66f509 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/wrap/gles.c @@ -0,0 +1,3924 @@ +#include "gles.h" +#include "../gl4es.h" +#include "../loader.h" +#include "skips.h" +#ifndef skip_glActiveTexture +void gl4es_glActiveTexture(GLenum texture) { + LOAD_GLES(glActiveTexture); +#ifndef direct_glActiveTexture + PUSH_IF_COMPILING(glActiveTexture) +#endif + gles_glActiveTexture(texture); +} +void glActiveTexture(GLenum texture) __attribute__((alias("gl4es_glActiveTexture"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glAlphaFunc +void gl4es_glAlphaFunc(GLenum func, GLclampf ref) { + LOAD_GLES(glAlphaFunc); +#ifndef direct_glAlphaFunc + PUSH_IF_COMPILING(glAlphaFunc) +#endif + gles_glAlphaFunc(func, ref); +} +void glAlphaFunc(GLenum func, GLclampf ref) __attribute__((alias("gl4es_glAlphaFunc"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glAlphaFuncx +void gl4es_glAlphaFuncx(GLenum func, GLclampx ref) { + LOAD_GLES(glAlphaFuncx); +#ifndef direct_glAlphaFuncx + PUSH_IF_COMPILING(glAlphaFuncx) +#endif + gles_glAlphaFuncx(func, ref); +} +void glAlphaFuncx(GLenum func, GLclampx ref) __attribute__((alias("gl4es_glAlphaFuncx"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glAttachShader +void gl4es_glAttachShader(GLuint program, GLuint shader) { + LOAD_GLES(glAttachShader); +#ifndef direct_glAttachShader + PUSH_IF_COMPILING(glAttachShader) +#endif + gles_glAttachShader(program, shader); +} +void glAttachShader(GLuint program, GLuint shader) __attribute__((alias("gl4es_glAttachShader"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glBindAttribLocation +void gl4es_glBindAttribLocation(GLuint program, GLuint index, const GLchar * name) { + LOAD_GLES(glBindAttribLocation); +#ifndef direct_glBindAttribLocation + PUSH_IF_COMPILING(glBindAttribLocation) +#endif + gles_glBindAttribLocation(program, index, name); +} +void glBindAttribLocation(GLuint program, GLuint index, const GLchar * name) __attribute__((alias("gl4es_glBindAttribLocation"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glBindBuffer +void gl4es_glBindBuffer(GLenum target, GLuint buffer) { + LOAD_GLES(glBindBuffer); +#ifndef direct_glBindBuffer + PUSH_IF_COMPILING(glBindBuffer) +#endif + gles_glBindBuffer(target, buffer); +} +void glBindBuffer(GLenum target, GLuint buffer) __attribute__((alias("gl4es_glBindBuffer"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glBindFramebuffer +void gl4es_glBindFramebuffer(GLenum target, GLuint framebuffer) { + LOAD_GLES_OES(glBindFramebuffer); +#ifndef direct_glBindFramebuffer + PUSH_IF_COMPILING(glBindFramebuffer) +#endif + gles_glBindFramebuffer(target, framebuffer); +} +void glBindFramebuffer(GLenum target, GLuint framebuffer) __attribute__((alias("gl4es_glBindFramebuffer"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glBindRenderbuffer +void gl4es_glBindRenderbuffer(GLenum target, GLuint renderbuffer) { + LOAD_GLES_OES(glBindRenderbuffer); +#ifndef direct_glBindRenderbuffer + PUSH_IF_COMPILING(glBindRenderbuffer) +#endif + gles_glBindRenderbuffer(target, renderbuffer); +} +void glBindRenderbuffer(GLenum target, GLuint renderbuffer) __attribute__((alias("gl4es_glBindRenderbuffer"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glBindTexture +void gl4es_glBindTexture(GLenum target, GLuint texture) { + LOAD_GLES(glBindTexture); +#ifndef direct_glBindTexture + PUSH_IF_COMPILING(glBindTexture) +#endif + gles_glBindTexture(target, texture); +} +void glBindTexture(GLenum target, GLuint texture) __attribute__((alias("gl4es_glBindTexture"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glBlendColor +void gl4es_glBlendColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha) { + LOAD_GLES_OES(glBlendColor); +#ifndef direct_glBlendColor + PUSH_IF_COMPILING(glBlendColor) +#endif + gles_glBlendColor(red, green, blue, alpha); +} +void glBlendColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha) __attribute__((alias("gl4es_glBlendColor"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glBlendEquation +void gl4es_glBlendEquation(GLenum mode) { + LOAD_GLES_OES(glBlendEquation); +#ifndef direct_glBlendEquation + PUSH_IF_COMPILING(glBlendEquation) +#endif + gles_glBlendEquation(mode); +} +void glBlendEquation(GLenum mode) __attribute__((alias("gl4es_glBlendEquation"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glBlendEquationSeparate +void gl4es_glBlendEquationSeparate(GLenum modeRGB, GLenum modeA) { + LOAD_GLES_OES(glBlendEquationSeparate); +#ifndef direct_glBlendEquationSeparate + PUSH_IF_COMPILING(glBlendEquationSeparate) +#endif + gles_glBlendEquationSeparate(modeRGB, modeA); +} +void glBlendEquationSeparate(GLenum modeRGB, GLenum modeA) __attribute__((alias("gl4es_glBlendEquationSeparate"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glBlendFunc +void gl4es_glBlendFunc(GLenum sfactor, GLenum dfactor) { + LOAD_GLES(glBlendFunc); +#ifndef direct_glBlendFunc + PUSH_IF_COMPILING(glBlendFunc) +#endif + gles_glBlendFunc(sfactor, dfactor); +} +void glBlendFunc(GLenum sfactor, GLenum dfactor) __attribute__((alias("gl4es_glBlendFunc"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glBlendFuncSeparate +void gl4es_glBlendFuncSeparate(GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha) { + LOAD_GLES_OES(glBlendFuncSeparate); +#ifndef direct_glBlendFuncSeparate + PUSH_IF_COMPILING(glBlendFuncSeparate) +#endif + gles_glBlendFuncSeparate(sfactorRGB, dfactorRGB, sfactorAlpha, dfactorAlpha); +} +void glBlendFuncSeparate(GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha) __attribute__((alias("gl4es_glBlendFuncSeparate"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glBufferData +void gl4es_glBufferData(GLenum target, GLsizeiptr size, const GLvoid * data, GLenum usage) { + LOAD_GLES(glBufferData); +#ifndef direct_glBufferData + PUSH_IF_COMPILING(glBufferData) +#endif + gles_glBufferData(target, size, data, usage); +} +void glBufferData(GLenum target, GLsizeiptr size, const GLvoid * data, GLenum usage) __attribute__((alias("gl4es_glBufferData"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glBufferSubData +void gl4es_glBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid * data) { + LOAD_GLES(glBufferSubData); +#ifndef direct_glBufferSubData + PUSH_IF_COMPILING(glBufferSubData) +#endif + gles_glBufferSubData(target, offset, size, data); +} +void glBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid * data) __attribute__((alias("gl4es_glBufferSubData"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glCheckFramebufferStatus +GLenum gl4es_glCheckFramebufferStatus(GLenum target) { + LOAD_GLES_OES(glCheckFramebufferStatus); +#ifndef direct_glCheckFramebufferStatus + PUSH_IF_COMPILING(glCheckFramebufferStatus) +#endif + return gles_glCheckFramebufferStatus(target); +} +GLenum glCheckFramebufferStatus(GLenum target) __attribute__((alias("gl4es_glCheckFramebufferStatus"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glClear +void gl4es_glClear(GLbitfield mask) { + LOAD_GLES(glClear); +#ifndef direct_glClear + PUSH_IF_COMPILING(glClear) +#endif + gles_glClear(mask); +} +void glClear(GLbitfield mask) __attribute__((alias("gl4es_glClear"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glClearColor +void gl4es_glClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha) { + LOAD_GLES(glClearColor); +#ifndef direct_glClearColor + PUSH_IF_COMPILING(glClearColor) +#endif + gles_glClearColor(red, green, blue, alpha); +} +void glClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha) __attribute__((alias("gl4es_glClearColor"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glClearColorx +void gl4es_glClearColorx(GLclampx red, GLclampx green, GLclampx blue, GLclampx alpha) { + LOAD_GLES(glClearColorx); +#ifndef direct_glClearColorx + PUSH_IF_COMPILING(glClearColorx) +#endif + gles_glClearColorx(red, green, blue, alpha); +} +void glClearColorx(GLclampx red, GLclampx green, GLclampx blue, GLclampx alpha) __attribute__((alias("gl4es_glClearColorx"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glClearDepthf +void gl4es_glClearDepthf(GLclampf depth) { + LOAD_GLES(glClearDepthf); +#ifndef direct_glClearDepthf + PUSH_IF_COMPILING(glClearDepthf) +#endif + gles_glClearDepthf(depth); +} +void glClearDepthf(GLclampf depth) __attribute__((alias("gl4es_glClearDepthf"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glClearDepthx +void gl4es_glClearDepthx(GLclampx depth) { + LOAD_GLES(glClearDepthx); +#ifndef direct_glClearDepthx + PUSH_IF_COMPILING(glClearDepthx) +#endif + gles_glClearDepthx(depth); +} +void glClearDepthx(GLclampx depth) __attribute__((alias("gl4es_glClearDepthx"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glClearStencil +void gl4es_glClearStencil(GLint s) { + LOAD_GLES(glClearStencil); +#ifndef direct_glClearStencil + PUSH_IF_COMPILING(glClearStencil) +#endif + gles_glClearStencil(s); +} +void glClearStencil(GLint s) __attribute__((alias("gl4es_glClearStencil"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glClientActiveTexture +void gl4es_glClientActiveTexture(GLenum texture) { + LOAD_GLES(glClientActiveTexture); +#ifndef direct_glClientActiveTexture + PUSH_IF_COMPILING(glClientActiveTexture) +#endif + gles_glClientActiveTexture(texture); +} +void glClientActiveTexture(GLenum texture) __attribute__((alias("gl4es_glClientActiveTexture"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glClipPlanef +void gl4es_glClipPlanef(GLenum plane, const GLfloat * equation) { + LOAD_GLES(glClipPlanef); +#ifndef direct_glClipPlanef + PUSH_IF_COMPILING(glClipPlanef) +#endif + gles_glClipPlanef(plane, equation); +} +void glClipPlanef(GLenum plane, const GLfloat * equation) __attribute__((alias("gl4es_glClipPlanef"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glClipPlanex +void gl4es_glClipPlanex(GLenum plane, const GLfixed * equation) { + LOAD_GLES(glClipPlanex); +#ifndef direct_glClipPlanex + PUSH_IF_COMPILING(glClipPlanex) +#endif + gles_glClipPlanex(plane, equation); +} +void glClipPlanex(GLenum plane, const GLfixed * equation) __attribute__((alias("gl4es_glClipPlanex"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glColor4f +void gl4es_glColor4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) { + LOAD_GLES(glColor4f); +#ifndef direct_glColor4f + PUSH_IF_COMPILING(glColor4f) +#endif + gles_glColor4f(red, green, blue, alpha); +} +void glColor4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) __attribute__((alias("gl4es_glColor4f"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glColor4ub +void gl4es_glColor4ub(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha) { + LOAD_GLES(glColor4ub); +#ifndef direct_glColor4ub + PUSH_IF_COMPILING(glColor4ub) +#endif + gles_glColor4ub(red, green, blue, alpha); +} +void glColor4ub(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha) __attribute__((alias("gl4es_glColor4ub"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glColor4x +void gl4es_glColor4x(GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha) { + LOAD_GLES(glColor4x); +#ifndef direct_glColor4x + PUSH_IF_COMPILING(glColor4x) +#endif + gles_glColor4x(red, green, blue, alpha); +} +void glColor4x(GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha) __attribute__((alias("gl4es_glColor4x"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glColorMask +void gl4es_glColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha) { + LOAD_GLES(glColorMask); +#ifndef direct_glColorMask + PUSH_IF_COMPILING(glColorMask) +#endif + gles_glColorMask(red, green, blue, alpha); +} +void glColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha) __attribute__((alias("gl4es_glColorMask"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glColorPointer +void gl4es_glColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid * pointer) { + LOAD_GLES(glColorPointer); +#ifndef direct_glColorPointer + PUSH_IF_COMPILING(glColorPointer) +#endif + gles_glColorPointer(size, type, stride, pointer); +} +void glColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid * pointer) __attribute__((alias("gl4es_glColorPointer"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glCompileShader +void gl4es_glCompileShader(GLuint shader) { + LOAD_GLES(glCompileShader); +#ifndef direct_glCompileShader + PUSH_IF_COMPILING(glCompileShader) +#endif + gles_glCompileShader(shader); +} +void glCompileShader(GLuint shader) __attribute__((alias("gl4es_glCompileShader"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glCompressedTexImage2D +void gl4es_glCompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid * data) { + LOAD_GLES(glCompressedTexImage2D); +#ifndef direct_glCompressedTexImage2D + PUSH_IF_COMPILING(glCompressedTexImage2D) +#endif + gles_glCompressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data); +} +void glCompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid * data) __attribute__((alias("gl4es_glCompressedTexImage2D"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glCompressedTexSubImage2D +void gl4es_glCompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid * data) { + LOAD_GLES(glCompressedTexSubImage2D); +#ifndef direct_glCompressedTexSubImage2D + PUSH_IF_COMPILING(glCompressedTexSubImage2D) +#endif + gles_glCompressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize, data); +} +void glCompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid * data) __attribute__((alias("gl4es_glCompressedTexSubImage2D"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glCopyTexImage2D +void gl4es_glCopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border) { + LOAD_GLES(glCopyTexImage2D); +#ifndef direct_glCopyTexImage2D + PUSH_IF_COMPILING(glCopyTexImage2D) +#endif + gles_glCopyTexImage2D(target, level, internalformat, x, y, width, height, border); +} +void glCopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border) __attribute__((alias("gl4es_glCopyTexImage2D"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glCopyTexSubImage2D +void gl4es_glCopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height) { + LOAD_GLES(glCopyTexSubImage2D); +#ifndef direct_glCopyTexSubImage2D + PUSH_IF_COMPILING(glCopyTexSubImage2D) +#endif + gles_glCopyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height); +} +void glCopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height) __attribute__((alias("gl4es_glCopyTexSubImage2D"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glCreateProgram +GLuint gl4es_glCreateProgram() { + LOAD_GLES(glCreateProgram); +#ifndef direct_glCreateProgram + PUSH_IF_COMPILING(glCreateProgram) +#endif + return gles_glCreateProgram(); +} +GLuint glCreateProgram() __attribute__((alias("gl4es_glCreateProgram"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glCreateShader +GLuint gl4es_glCreateShader(GLenum type) { + LOAD_GLES(glCreateShader); +#ifndef direct_glCreateShader + PUSH_IF_COMPILING(glCreateShader) +#endif + return gles_glCreateShader(type); +} +GLuint glCreateShader(GLenum type) __attribute__((alias("gl4es_glCreateShader"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glCullFace +void gl4es_glCullFace(GLenum mode) { + LOAD_GLES(glCullFace); +#ifndef direct_glCullFace + PUSH_IF_COMPILING(glCullFace) +#endif + gles_glCullFace(mode); +} +void glCullFace(GLenum mode) __attribute__((alias("gl4es_glCullFace"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glDeleteBuffers +void gl4es_glDeleteBuffers(GLsizei n, const GLuint * buffer) { + LOAD_GLES(glDeleteBuffers); +#ifndef direct_glDeleteBuffers + PUSH_IF_COMPILING(glDeleteBuffers) +#endif + gles_glDeleteBuffers(n, buffer); +} +void glDeleteBuffers(GLsizei n, const GLuint * buffer) __attribute__((alias("gl4es_glDeleteBuffers"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glDeleteFramebuffers +void gl4es_glDeleteFramebuffers(GLsizei n, GLuint * framebuffers) { + LOAD_GLES_OES(glDeleteFramebuffers); +#ifndef direct_glDeleteFramebuffers + PUSH_IF_COMPILING(glDeleteFramebuffers) +#endif + gles_glDeleteFramebuffers(n, framebuffers); +} +void glDeleteFramebuffers(GLsizei n, GLuint * framebuffers) __attribute__((alias("gl4es_glDeleteFramebuffers"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glDeleteProgram +void gl4es_glDeleteProgram(GLuint program) { + LOAD_GLES(glDeleteProgram); +#ifndef direct_glDeleteProgram + PUSH_IF_COMPILING(glDeleteProgram) +#endif + gles_glDeleteProgram(program); +} +void glDeleteProgram(GLuint program) __attribute__((alias("gl4es_glDeleteProgram"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glDeleteRenderbuffers +void gl4es_glDeleteRenderbuffers(GLsizei n, GLuint * renderbuffers) { + LOAD_GLES_OES(glDeleteRenderbuffers); +#ifndef direct_glDeleteRenderbuffers + PUSH_IF_COMPILING(glDeleteRenderbuffers) +#endif + gles_glDeleteRenderbuffers(n, renderbuffers); +} +void glDeleteRenderbuffers(GLsizei n, GLuint * renderbuffers) __attribute__((alias("gl4es_glDeleteRenderbuffers"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glDeleteShader +void gl4es_glDeleteShader(GLuint shader) { + LOAD_GLES(glDeleteShader); +#ifndef direct_glDeleteShader + PUSH_IF_COMPILING(glDeleteShader) +#endif + gles_glDeleteShader(shader); +} +void glDeleteShader(GLuint shader) __attribute__((alias("gl4es_glDeleteShader"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glDeleteTextures +void gl4es_glDeleteTextures(GLsizei n, const GLuint * textures) { + LOAD_GLES(glDeleteTextures); +#ifndef direct_glDeleteTextures + PUSH_IF_COMPILING(glDeleteTextures) +#endif + gles_glDeleteTextures(n, textures); +} +void glDeleteTextures(GLsizei n, const GLuint * textures) __attribute__((alias("gl4es_glDeleteTextures"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glDepthFunc +void gl4es_glDepthFunc(GLenum func) { + LOAD_GLES(glDepthFunc); +#ifndef direct_glDepthFunc + PUSH_IF_COMPILING(glDepthFunc) +#endif + gles_glDepthFunc(func); +} +void glDepthFunc(GLenum func) __attribute__((alias("gl4es_glDepthFunc"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glDepthMask +void gl4es_glDepthMask(GLboolean flag) { + LOAD_GLES(glDepthMask); +#ifndef direct_glDepthMask + PUSH_IF_COMPILING(glDepthMask) +#endif + gles_glDepthMask(flag); +} +void glDepthMask(GLboolean flag) __attribute__((alias("gl4es_glDepthMask"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glDepthRangef +void gl4es_glDepthRangef(GLclampf near, GLclampf far) { + LOAD_GLES(glDepthRangef); +#ifndef direct_glDepthRangef + PUSH_IF_COMPILING(glDepthRangef) +#endif + gles_glDepthRangef(near, far); +} +void glDepthRangef(GLclampf near, GLclampf far) __attribute__((alias("gl4es_glDepthRangef"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glDepthRangex +void gl4es_glDepthRangex(GLclampx near, GLclampx far) { + LOAD_GLES(glDepthRangex); +#ifndef direct_glDepthRangex + PUSH_IF_COMPILING(glDepthRangex) +#endif + gles_glDepthRangex(near, far); +} +void glDepthRangex(GLclampx near, GLclampx far) __attribute__((alias("gl4es_glDepthRangex"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glDetachShader +void gl4es_glDetachShader(GLuint program, GLuint shader) { + LOAD_GLES(glDetachShader); +#ifndef direct_glDetachShader + PUSH_IF_COMPILING(glDetachShader) +#endif + gles_glDetachShader(program, shader); +} +void glDetachShader(GLuint program, GLuint shader) __attribute__((alias("gl4es_glDetachShader"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glDisable +void gl4es_glDisable(GLenum cap) { + LOAD_GLES(glDisable); +#ifndef direct_glDisable + PUSH_IF_COMPILING(glDisable) +#endif + gles_glDisable(cap); +} +void glDisable(GLenum cap) __attribute__((alias("gl4es_glDisable"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glDisableClientState +void gl4es_glDisableClientState(GLenum array) { + LOAD_GLES(glDisableClientState); +#ifndef direct_glDisableClientState + PUSH_IF_COMPILING(glDisableClientState) +#endif + gles_glDisableClientState(array); +} +void glDisableClientState(GLenum array) __attribute__((alias("gl4es_glDisableClientState"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glDisableVertexAttribArray +void gl4es_glDisableVertexAttribArray(GLuint index) { + LOAD_GLES(glDisableVertexAttribArray); +#ifndef direct_glDisableVertexAttribArray + PUSH_IF_COMPILING(glDisableVertexAttribArray) +#endif + gles_glDisableVertexAttribArray(index); +} +void glDisableVertexAttribArray(GLuint index) __attribute__((alias("gl4es_glDisableVertexAttribArray"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glDrawArrays +void gl4es_glDrawArrays(GLenum mode, GLint first, GLsizei count) { + LOAD_GLES(glDrawArrays); +#ifndef direct_glDrawArrays + PUSH_IF_COMPILING(glDrawArrays) +#endif + gles_glDrawArrays(mode, first, count); +} +void glDrawArrays(GLenum mode, GLint first, GLsizei count) __attribute__((alias("gl4es_glDrawArrays"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glDrawElements +void gl4es_glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid * indices) { + LOAD_GLES(glDrawElements); +#ifndef direct_glDrawElements + PUSH_IF_COMPILING(glDrawElements) +#endif + gles_glDrawElements(mode, count, type, indices); +} +void glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid * indices) __attribute__((alias("gl4es_glDrawElements"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glDrawTexf +void gl4es_glDrawTexf(GLfloat x, GLfloat y, GLfloat z, GLfloat width, GLfloat height) { + LOAD_GLES_OES(glDrawTexf); +#ifndef direct_glDrawTexf + PUSH_IF_COMPILING(glDrawTexf) +#endif + gles_glDrawTexf(x, y, z, width, height); +} +void glDrawTexf(GLfloat x, GLfloat y, GLfloat z, GLfloat width, GLfloat height) __attribute__((alias("gl4es_glDrawTexf"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glDrawTexi +void gl4es_glDrawTexi(GLint x, GLint y, GLint z, GLint width, GLint height) { + LOAD_GLES_OES(glDrawTexi); +#ifndef direct_glDrawTexi + PUSH_IF_COMPILING(glDrawTexi) +#endif + gles_glDrawTexi(x, y, z, width, height); +} +void glDrawTexi(GLint x, GLint y, GLint z, GLint width, GLint height) __attribute__((alias("gl4es_glDrawTexi"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glEnable +void gl4es_glEnable(GLenum cap) { + LOAD_GLES(glEnable); +#ifndef direct_glEnable + PUSH_IF_COMPILING(glEnable) +#endif + gles_glEnable(cap); +} +void glEnable(GLenum cap) __attribute__((alias("gl4es_glEnable"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glEnableClientState +void gl4es_glEnableClientState(GLenum array) { + LOAD_GLES(glEnableClientState); +#ifndef direct_glEnableClientState + PUSH_IF_COMPILING(glEnableClientState) +#endif + gles_glEnableClientState(array); +} +void glEnableClientState(GLenum array) __attribute__((alias("gl4es_glEnableClientState"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glEnableVertexAttribArray +void gl4es_glEnableVertexAttribArray(GLuint index) { + LOAD_GLES(glEnableVertexAttribArray); +#ifndef direct_glEnableVertexAttribArray + PUSH_IF_COMPILING(glEnableVertexAttribArray) +#endif + gles_glEnableVertexAttribArray(index); +} +void glEnableVertexAttribArray(GLuint index) __attribute__((alias("gl4es_glEnableVertexAttribArray"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glFinish +void gl4es_glFinish() { + LOAD_GLES(glFinish); +#ifndef direct_glFinish + PUSH_IF_COMPILING(glFinish) +#endif + gles_glFinish(); +} +void glFinish() __attribute__((alias("gl4es_glFinish"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glFlush +void gl4es_glFlush() { + LOAD_GLES(glFlush); +#ifndef direct_glFlush + PUSH_IF_COMPILING(glFlush) +#endif + gles_glFlush(); +} +void glFlush() __attribute__((alias("gl4es_glFlush"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glFogCoordPointer +void gl4es_glFogCoordPointer(GLenum type, GLsizei stride, const GLvoid * pointer) { + LOAD_GLES(glFogCoordPointer); +#ifndef direct_glFogCoordPointer + PUSH_IF_COMPILING(glFogCoordPointer) +#endif + gles_glFogCoordPointer(type, stride, pointer); +} +void glFogCoordPointer(GLenum type, GLsizei stride, const GLvoid * pointer) __attribute__((alias("gl4es_glFogCoordPointer"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glFogCoordf +void gl4es_glFogCoordf(GLfloat coord) { + LOAD_GLES(glFogCoordf); +#ifndef direct_glFogCoordf + PUSH_IF_COMPILING(glFogCoordf) +#endif + gles_glFogCoordf(coord); +} +void glFogCoordf(GLfloat coord) __attribute__((alias("gl4es_glFogCoordf"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glFogCoordfv +void gl4es_glFogCoordfv(const GLfloat * coord) { + LOAD_GLES(glFogCoordfv); +#ifndef direct_glFogCoordfv + PUSH_IF_COMPILING(glFogCoordfv) +#endif + gles_glFogCoordfv(coord); +} +void glFogCoordfv(const GLfloat * coord) __attribute__((alias("gl4es_glFogCoordfv"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glFogf +void gl4es_glFogf(GLenum pname, GLfloat param) { + LOAD_GLES(glFogf); +#ifndef direct_glFogf + PUSH_IF_COMPILING(glFogf) +#endif + gles_glFogf(pname, param); +} +void glFogf(GLenum pname, GLfloat param) __attribute__((alias("gl4es_glFogf"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glFogfv +void gl4es_glFogfv(GLenum pname, const GLfloat * params) { + LOAD_GLES(glFogfv); +#ifndef direct_glFogfv + PUSH_IF_COMPILING(glFogfv) +#endif + gles_glFogfv(pname, params); +} +void glFogfv(GLenum pname, const GLfloat * params) __attribute__((alias("gl4es_glFogfv"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glFogx +void gl4es_glFogx(GLenum pname, GLfixed param) { + LOAD_GLES(glFogx); +#ifndef direct_glFogx + PUSH_IF_COMPILING(glFogx) +#endif + gles_glFogx(pname, param); +} +void glFogx(GLenum pname, GLfixed param) __attribute__((alias("gl4es_glFogx"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glFogxv +void gl4es_glFogxv(GLenum pname, const GLfixed * params) { + LOAD_GLES(glFogxv); +#ifndef direct_glFogxv + PUSH_IF_COMPILING(glFogxv) +#endif + gles_glFogxv(pname, params); +} +void glFogxv(GLenum pname, const GLfixed * params) __attribute__((alias("gl4es_glFogxv"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glFramebufferRenderbuffer +void gl4es_glFramebufferRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer) { + LOAD_GLES_OES(glFramebufferRenderbuffer); +#ifndef direct_glFramebufferRenderbuffer + PUSH_IF_COMPILING(glFramebufferRenderbuffer) +#endif + gles_glFramebufferRenderbuffer(target, attachment, renderbuffertarget, renderbuffer); +} +void glFramebufferRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer) __attribute__((alias("gl4es_glFramebufferRenderbuffer"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glFramebufferTexture2D +void gl4es_glFramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level) { + LOAD_GLES_OES(glFramebufferTexture2D); +#ifndef direct_glFramebufferTexture2D + PUSH_IF_COMPILING(glFramebufferTexture2D) +#endif + gles_glFramebufferTexture2D(target, attachment, textarget, texture, level); +} +void glFramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level) __attribute__((alias("gl4es_glFramebufferTexture2D"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glFrontFace +void gl4es_glFrontFace(GLenum mode) { + LOAD_GLES(glFrontFace); +#ifndef direct_glFrontFace + PUSH_IF_COMPILING(glFrontFace) +#endif + gles_glFrontFace(mode); +} +void glFrontFace(GLenum mode) __attribute__((alias("gl4es_glFrontFace"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glFrustumf +void gl4es_glFrustumf(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat near, GLfloat far) { + LOAD_GLES(glFrustumf); +#ifndef direct_glFrustumf + PUSH_IF_COMPILING(glFrustumf) +#endif + gles_glFrustumf(left, right, bottom, top, near, far); +} +void glFrustumf(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat near, GLfloat far) __attribute__((alias("gl4es_glFrustumf"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glFrustumx +void gl4es_glFrustumx(GLfixed left, GLfixed right, GLfixed bottom, GLfixed top, GLfixed near, GLfixed far) { + LOAD_GLES(glFrustumx); +#ifndef direct_glFrustumx + PUSH_IF_COMPILING(glFrustumx) +#endif + gles_glFrustumx(left, right, bottom, top, near, far); +} +void glFrustumx(GLfixed left, GLfixed right, GLfixed bottom, GLfixed top, GLfixed near, GLfixed far) __attribute__((alias("gl4es_glFrustumx"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glGenBuffers +void gl4es_glGenBuffers(GLsizei n, GLuint * buffer) { + LOAD_GLES(glGenBuffers); +#ifndef direct_glGenBuffers + PUSH_IF_COMPILING(glGenBuffers) +#endif + gles_glGenBuffers(n, buffer); +} +void glGenBuffers(GLsizei n, GLuint * buffer) __attribute__((alias("gl4es_glGenBuffers"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glGenFramebuffers +void gl4es_glGenFramebuffers(GLsizei n, GLuint * ids) { + LOAD_GLES_OES(glGenFramebuffers); +#ifndef direct_glGenFramebuffers + PUSH_IF_COMPILING(glGenFramebuffers) +#endif + gles_glGenFramebuffers(n, ids); +} +void glGenFramebuffers(GLsizei n, GLuint * ids) __attribute__((alias("gl4es_glGenFramebuffers"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glGenRenderbuffers +void gl4es_glGenRenderbuffers(GLsizei n, GLuint * renderbuffers) { + LOAD_GLES_OES(glGenRenderbuffers); +#ifndef direct_glGenRenderbuffers + PUSH_IF_COMPILING(glGenRenderbuffers) +#endif + gles_glGenRenderbuffers(n, renderbuffers); +} +void glGenRenderbuffers(GLsizei n, GLuint * renderbuffers) __attribute__((alias("gl4es_glGenRenderbuffers"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glGenTextures +void gl4es_glGenTextures(GLsizei n, GLuint * textures) { + LOAD_GLES(glGenTextures); +#ifndef direct_glGenTextures + PUSH_IF_COMPILING(glGenTextures) +#endif + gles_glGenTextures(n, textures); +} +void glGenTextures(GLsizei n, GLuint * textures) __attribute__((alias("gl4es_glGenTextures"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glGenerateMipmap +void gl4es_glGenerateMipmap(GLenum target) { + LOAD_GLES_OES(glGenerateMipmap); +#ifndef direct_glGenerateMipmap + PUSH_IF_COMPILING(glGenerateMipmap) +#endif + gles_glGenerateMipmap(target); +} +void glGenerateMipmap(GLenum target) __attribute__((alias("gl4es_glGenerateMipmap"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glGetActiveAttrib +void gl4es_glGetActiveAttrib(GLuint program, GLuint index, GLsizei bufSize, GLsizei * length, GLint * size, GLenum * type, GLchar * name) { + LOAD_GLES(glGetActiveAttrib); +#ifndef direct_glGetActiveAttrib + PUSH_IF_COMPILING(glGetActiveAttrib) +#endif + gles_glGetActiveAttrib(program, index, bufSize, length, size, type, name); +} +void glGetActiveAttrib(GLuint program, GLuint index, GLsizei bufSize, GLsizei * length, GLint * size, GLenum * type, GLchar * name) __attribute__((alias("gl4es_glGetActiveAttrib"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glGetActiveUniform +void gl4es_glGetActiveUniform(GLuint program, GLuint index, GLsizei bufSize, GLsizei * length, GLint * size, GLenum * type, GLchar * name) { + LOAD_GLES(glGetActiveUniform); +#ifndef direct_glGetActiveUniform + PUSH_IF_COMPILING(glGetActiveUniform) +#endif + gles_glGetActiveUniform(program, index, bufSize, length, size, type, name); +} +void glGetActiveUniform(GLuint program, GLuint index, GLsizei bufSize, GLsizei * length, GLint * size, GLenum * type, GLchar * name) __attribute__((alias("gl4es_glGetActiveUniform"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glGetAttachedShaders +void gl4es_glGetAttachedShaders(GLuint program, GLsizei maxCount, GLsizei * count, GLuint * obj) { + LOAD_GLES(glGetAttachedShaders); +#ifndef direct_glGetAttachedShaders + PUSH_IF_COMPILING(glGetAttachedShaders) +#endif + gles_glGetAttachedShaders(program, maxCount, count, obj); +} +void glGetAttachedShaders(GLuint program, GLsizei maxCount, GLsizei * count, GLuint * obj) __attribute__((alias("gl4es_glGetAttachedShaders"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glGetAttribLocation +GLint gl4es_glGetAttribLocation(GLuint program, const GLchar * name) { + LOAD_GLES(glGetAttribLocation); +#ifndef direct_glGetAttribLocation + PUSH_IF_COMPILING(glGetAttribLocation) +#endif + return gles_glGetAttribLocation(program, name); +} +GLint glGetAttribLocation(GLuint program, const GLchar * name) __attribute__((alias("gl4es_glGetAttribLocation"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glGetBooleanv +void gl4es_glGetBooleanv(GLenum pname, GLboolean * params) { + LOAD_GLES(glGetBooleanv); +#ifndef direct_glGetBooleanv + PUSH_IF_COMPILING(glGetBooleanv) +#endif + gles_glGetBooleanv(pname, params); +} +void glGetBooleanv(GLenum pname, GLboolean * params) __attribute__((alias("gl4es_glGetBooleanv"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glGetBufferParameteriv +void gl4es_glGetBufferParameteriv(GLenum target, GLenum pname, GLint * params) { + LOAD_GLES(glGetBufferParameteriv); +#ifndef direct_glGetBufferParameteriv + PUSH_IF_COMPILING(glGetBufferParameteriv) +#endif + gles_glGetBufferParameteriv(target, pname, params); +} +void glGetBufferParameteriv(GLenum target, GLenum pname, GLint * params) __attribute__((alias("gl4es_glGetBufferParameteriv"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glGetClipPlanef +void gl4es_glGetClipPlanef(GLenum plane, GLfloat * equation) { + LOAD_GLES(glGetClipPlanef); +#ifndef direct_glGetClipPlanef + PUSH_IF_COMPILING(glGetClipPlanef) +#endif + gles_glGetClipPlanef(plane, equation); +} +void glGetClipPlanef(GLenum plane, GLfloat * equation) __attribute__((alias("gl4es_glGetClipPlanef"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glGetClipPlanex +void gl4es_glGetClipPlanex(GLenum plane, GLfixed * equation) { + LOAD_GLES(glGetClipPlanex); +#ifndef direct_glGetClipPlanex + PUSH_IF_COMPILING(glGetClipPlanex) +#endif + gles_glGetClipPlanex(plane, equation); +} +void glGetClipPlanex(GLenum plane, GLfixed * equation) __attribute__((alias("gl4es_glGetClipPlanex"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glGetError +GLenum gl4es_glGetError() { + LOAD_GLES(glGetError); +#ifndef direct_glGetError + PUSH_IF_COMPILING(glGetError) +#endif + return gles_glGetError(); +} +GLenum glGetError() __attribute__((alias("gl4es_glGetError"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glGetFixedv +void gl4es_glGetFixedv(GLenum pname, GLfixed * params) { + LOAD_GLES(glGetFixedv); +#ifndef direct_glGetFixedv + PUSH_IF_COMPILING(glGetFixedv) +#endif + gles_glGetFixedv(pname, params); +} +void glGetFixedv(GLenum pname, GLfixed * params) __attribute__((alias("gl4es_glGetFixedv"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glGetFloatv +void gl4es_glGetFloatv(GLenum pname, GLfloat * params) { + LOAD_GLES(glGetFloatv); +#ifndef direct_glGetFloatv + PUSH_IF_COMPILING(glGetFloatv) +#endif + gles_glGetFloatv(pname, params); +} +void glGetFloatv(GLenum pname, GLfloat * params) __attribute__((alias("gl4es_glGetFloatv"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glGetFramebufferAttachmentParameteriv +void gl4es_glGetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment, GLenum pname, GLint * params) { + LOAD_GLES_OES(glGetFramebufferAttachmentParameteriv); +#ifndef direct_glGetFramebufferAttachmentParameteriv + PUSH_IF_COMPILING(glGetFramebufferAttachmentParameteriv) +#endif + gles_glGetFramebufferAttachmentParameteriv(target, attachment, pname, params); +} +void glGetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment, GLenum pname, GLint * params) __attribute__((alias("gl4es_glGetFramebufferAttachmentParameteriv"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glGetIntegerv +void gl4es_glGetIntegerv(GLenum pname, GLint * params) { + LOAD_GLES(glGetIntegerv); +#ifndef direct_glGetIntegerv + PUSH_IF_COMPILING(glGetIntegerv) +#endif + gles_glGetIntegerv(pname, params); +} +void glGetIntegerv(GLenum pname, GLint * params) __attribute__((alias("gl4es_glGetIntegerv"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glGetLightfv +void gl4es_glGetLightfv(GLenum light, GLenum pname, GLfloat * params) { + LOAD_GLES(glGetLightfv); +#ifndef direct_glGetLightfv + PUSH_IF_COMPILING(glGetLightfv) +#endif + gles_glGetLightfv(light, pname, params); +} +void glGetLightfv(GLenum light, GLenum pname, GLfloat * params) __attribute__((alias("gl4es_glGetLightfv"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glGetLightxv +void gl4es_glGetLightxv(GLenum light, GLenum pname, GLfixed * params) { + LOAD_GLES(glGetLightxv); +#ifndef direct_glGetLightxv + PUSH_IF_COMPILING(glGetLightxv) +#endif + gles_glGetLightxv(light, pname, params); +} +void glGetLightxv(GLenum light, GLenum pname, GLfixed * params) __attribute__((alias("gl4es_glGetLightxv"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glGetMaterialfv +void gl4es_glGetMaterialfv(GLenum face, GLenum pname, GLfloat * params) { + LOAD_GLES(glGetMaterialfv); +#ifndef direct_glGetMaterialfv + PUSH_IF_COMPILING(glGetMaterialfv) +#endif + gles_glGetMaterialfv(face, pname, params); +} +void glGetMaterialfv(GLenum face, GLenum pname, GLfloat * params) __attribute__((alias("gl4es_glGetMaterialfv"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glGetMaterialxv +void gl4es_glGetMaterialxv(GLenum face, GLenum pname, GLfixed * params) { + LOAD_GLES(glGetMaterialxv); +#ifndef direct_glGetMaterialxv + PUSH_IF_COMPILING(glGetMaterialxv) +#endif + gles_glGetMaterialxv(face, pname, params); +} +void glGetMaterialxv(GLenum face, GLenum pname, GLfixed * params) __attribute__((alias("gl4es_glGetMaterialxv"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glGetPointerv +void gl4es_glGetPointerv(GLenum pname, GLvoid ** params) { + LOAD_GLES(glGetPointerv); +#ifndef direct_glGetPointerv + PUSH_IF_COMPILING(glGetPointerv) +#endif + gles_glGetPointerv(pname, params); +} +void glGetPointerv(GLenum pname, GLvoid ** params) __attribute__((alias("gl4es_glGetPointerv"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glGetProgramInfoLog +void gl4es_glGetProgramInfoLog(GLuint program, GLsizei bufSize, GLsizei * length, GLchar * infoLog) { + LOAD_GLES(glGetProgramInfoLog); +#ifndef direct_glGetProgramInfoLog + PUSH_IF_COMPILING(glGetProgramInfoLog) +#endif + gles_glGetProgramInfoLog(program, bufSize, length, infoLog); +} +void glGetProgramInfoLog(GLuint program, GLsizei bufSize, GLsizei * length, GLchar * infoLog) __attribute__((alias("gl4es_glGetProgramInfoLog"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glGetProgramiv +void gl4es_glGetProgramiv(GLuint program, GLenum pname, GLint * params) { + LOAD_GLES(glGetProgramiv); +#ifndef direct_glGetProgramiv + PUSH_IF_COMPILING(glGetProgramiv) +#endif + gles_glGetProgramiv(program, pname, params); +} +void glGetProgramiv(GLuint program, GLenum pname, GLint * params) __attribute__((alias("gl4es_glGetProgramiv"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glGetRenderbufferParameteriv +void gl4es_glGetRenderbufferParameteriv(GLenum target, GLenum pname, GLint * params) { + LOAD_GLES_OES(glGetRenderbufferParameteriv); +#ifndef direct_glGetRenderbufferParameteriv + PUSH_IF_COMPILING(glGetRenderbufferParameteriv) +#endif + gles_glGetRenderbufferParameteriv(target, pname, params); +} +void glGetRenderbufferParameteriv(GLenum target, GLenum pname, GLint * params) __attribute__((alias("gl4es_glGetRenderbufferParameteriv"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glGetShaderInfoLog +void gl4es_glGetShaderInfoLog(GLuint shader, GLsizei bufSize, GLsizei * length, GLchar * infoLog) { + LOAD_GLES(glGetShaderInfoLog); +#ifndef direct_glGetShaderInfoLog + PUSH_IF_COMPILING(glGetShaderInfoLog) +#endif + gles_glGetShaderInfoLog(shader, bufSize, length, infoLog); +} +void glGetShaderInfoLog(GLuint shader, GLsizei bufSize, GLsizei * length, GLchar * infoLog) __attribute__((alias("gl4es_glGetShaderInfoLog"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glGetShaderPrecisionFormat +void gl4es_glGetShaderPrecisionFormat(GLenum shadertype, GLenum precisiontype, GLint * range, GLint * precision) { + LOAD_GLES(glGetShaderPrecisionFormat); +#ifndef direct_glGetShaderPrecisionFormat + PUSH_IF_COMPILING(glGetShaderPrecisionFormat) +#endif + gles_glGetShaderPrecisionFormat(shadertype, precisiontype, range, precision); +} +void glGetShaderPrecisionFormat(GLenum shadertype, GLenum precisiontype, GLint * range, GLint * precision) __attribute__((alias("gl4es_glGetShaderPrecisionFormat"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glGetShaderSource +void gl4es_glGetShaderSource(GLuint shader, GLsizei bufSize, GLsizei * length, GLchar * source) { + LOAD_GLES(glGetShaderSource); +#ifndef direct_glGetShaderSource + PUSH_IF_COMPILING(glGetShaderSource) +#endif + gles_glGetShaderSource(shader, bufSize, length, source); +} +void glGetShaderSource(GLuint shader, GLsizei bufSize, GLsizei * length, GLchar * source) __attribute__((alias("gl4es_glGetShaderSource"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glGetShaderiv +void gl4es_glGetShaderiv(GLuint shader, GLenum pname, GLint * params) { + LOAD_GLES(glGetShaderiv); +#ifndef direct_glGetShaderiv + PUSH_IF_COMPILING(glGetShaderiv) +#endif + gles_glGetShaderiv(shader, pname, params); +} +void glGetShaderiv(GLuint shader, GLenum pname, GLint * params) __attribute__((alias("gl4es_glGetShaderiv"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glGetString +const GLubyte * gl4es_glGetString(GLenum name) { + LOAD_GLES(glGetString); +#ifndef direct_glGetString + PUSH_IF_COMPILING(glGetString) +#endif + return gles_glGetString(name); +} +const GLubyte * glGetString(GLenum name) __attribute__((alias("gl4es_glGetString"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glGetTexEnvfv +void gl4es_glGetTexEnvfv(GLenum target, GLenum pname, GLfloat * params) { + LOAD_GLES(glGetTexEnvfv); +#ifndef direct_glGetTexEnvfv + PUSH_IF_COMPILING(glGetTexEnvfv) +#endif + gles_glGetTexEnvfv(target, pname, params); +} +void glGetTexEnvfv(GLenum target, GLenum pname, GLfloat * params) __attribute__((alias("gl4es_glGetTexEnvfv"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glGetTexEnviv +void gl4es_glGetTexEnviv(GLenum target, GLenum pname, GLint * params) { + LOAD_GLES(glGetTexEnviv); +#ifndef direct_glGetTexEnviv + PUSH_IF_COMPILING(glGetTexEnviv) +#endif + gles_glGetTexEnviv(target, pname, params); +} +void glGetTexEnviv(GLenum target, GLenum pname, GLint * params) __attribute__((alias("gl4es_glGetTexEnviv"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glGetTexEnvxv +void gl4es_glGetTexEnvxv(GLenum target, GLenum pname, GLfixed * params) { + LOAD_GLES(glGetTexEnvxv); +#ifndef direct_glGetTexEnvxv + PUSH_IF_COMPILING(glGetTexEnvxv) +#endif + gles_glGetTexEnvxv(target, pname, params); +} +void glGetTexEnvxv(GLenum target, GLenum pname, GLfixed * params) __attribute__((alias("gl4es_glGetTexEnvxv"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glGetTexParameterfv +void gl4es_glGetTexParameterfv(GLenum target, GLenum pname, GLfloat * params) { + LOAD_GLES(glGetTexParameterfv); +#ifndef direct_glGetTexParameterfv + PUSH_IF_COMPILING(glGetTexParameterfv) +#endif + gles_glGetTexParameterfv(target, pname, params); +} +void glGetTexParameterfv(GLenum target, GLenum pname, GLfloat * params) __attribute__((alias("gl4es_glGetTexParameterfv"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glGetTexParameteriv +void gl4es_glGetTexParameteriv(GLenum target, GLenum pname, GLint * params) { + LOAD_GLES(glGetTexParameteriv); +#ifndef direct_glGetTexParameteriv + PUSH_IF_COMPILING(glGetTexParameteriv) +#endif + gles_glGetTexParameteriv(target, pname, params); +} +void glGetTexParameteriv(GLenum target, GLenum pname, GLint * params) __attribute__((alias("gl4es_glGetTexParameteriv"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glGetTexParameterxv +void gl4es_glGetTexParameterxv(GLenum target, GLenum pname, GLfixed * params) { + LOAD_GLES(glGetTexParameterxv); +#ifndef direct_glGetTexParameterxv + PUSH_IF_COMPILING(glGetTexParameterxv) +#endif + gles_glGetTexParameterxv(target, pname, params); +} +void glGetTexParameterxv(GLenum target, GLenum pname, GLfixed * params) __attribute__((alias("gl4es_glGetTexParameterxv"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glGetUniformLocation +GLint gl4es_glGetUniformLocation(GLuint program, const GLchar * name) { + LOAD_GLES(glGetUniformLocation); +#ifndef direct_glGetUniformLocation + PUSH_IF_COMPILING(glGetUniformLocation) +#endif + return gles_glGetUniformLocation(program, name); +} +GLint glGetUniformLocation(GLuint program, const GLchar * name) __attribute__((alias("gl4es_glGetUniformLocation"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glGetUniformfv +void gl4es_glGetUniformfv(GLuint program, GLint location, GLfloat * params) { + LOAD_GLES(glGetUniformfv); +#ifndef direct_glGetUniformfv + PUSH_IF_COMPILING(glGetUniformfv) +#endif + gles_glGetUniformfv(program, location, params); +} +void glGetUniformfv(GLuint program, GLint location, GLfloat * params) __attribute__((alias("gl4es_glGetUniformfv"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glGetUniformiv +void gl4es_glGetUniformiv(GLuint program, GLint location, GLint * params) { + LOAD_GLES(glGetUniformiv); +#ifndef direct_glGetUniformiv + PUSH_IF_COMPILING(glGetUniformiv) +#endif + gles_glGetUniformiv(program, location, params); +} +void glGetUniformiv(GLuint program, GLint location, GLint * params) __attribute__((alias("gl4es_glGetUniformiv"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glGetVertexAttribPointerv +void gl4es_glGetVertexAttribPointerv(GLuint index, GLenum pname, GLvoid ** pointer) { + LOAD_GLES(glGetVertexAttribPointerv); +#ifndef direct_glGetVertexAttribPointerv + PUSH_IF_COMPILING(glGetVertexAttribPointerv) +#endif + gles_glGetVertexAttribPointerv(index, pname, pointer); +} +void glGetVertexAttribPointerv(GLuint index, GLenum pname, GLvoid ** pointer) __attribute__((alias("gl4es_glGetVertexAttribPointerv"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glGetVertexAttribfv +void gl4es_glGetVertexAttribfv(GLuint index, GLenum pname, GLfloat * params) { + LOAD_GLES(glGetVertexAttribfv); +#ifndef direct_glGetVertexAttribfv + PUSH_IF_COMPILING(glGetVertexAttribfv) +#endif + gles_glGetVertexAttribfv(index, pname, params); +} +void glGetVertexAttribfv(GLuint index, GLenum pname, GLfloat * params) __attribute__((alias("gl4es_glGetVertexAttribfv"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glGetVertexAttribiv +void gl4es_glGetVertexAttribiv(GLuint index, GLenum pname, GLint * params) { + LOAD_GLES(glGetVertexAttribiv); +#ifndef direct_glGetVertexAttribiv + PUSH_IF_COMPILING(glGetVertexAttribiv) +#endif + gles_glGetVertexAttribiv(index, pname, params); +} +void glGetVertexAttribiv(GLuint index, GLenum pname, GLint * params) __attribute__((alias("gl4es_glGetVertexAttribiv"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glHint +void gl4es_glHint(GLenum target, GLenum mode) { + LOAD_GLES(glHint); +#ifndef direct_glHint + PUSH_IF_COMPILING(glHint) +#endif + gles_glHint(target, mode); +} +void glHint(GLenum target, GLenum mode) __attribute__((alias("gl4es_glHint"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glIsBuffer +GLboolean gl4es_glIsBuffer(GLuint buffer) { + LOAD_GLES(glIsBuffer); +#ifndef direct_glIsBuffer + PUSH_IF_COMPILING(glIsBuffer) +#endif + return gles_glIsBuffer(buffer); +} +GLboolean glIsBuffer(GLuint buffer) __attribute__((alias("gl4es_glIsBuffer"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glIsEnabled +GLboolean gl4es_glIsEnabled(GLenum cap) { + LOAD_GLES(glIsEnabled); +#ifndef direct_glIsEnabled + PUSH_IF_COMPILING(glIsEnabled) +#endif + return gles_glIsEnabled(cap); +} +GLboolean glIsEnabled(GLenum cap) __attribute__((alias("gl4es_glIsEnabled"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glIsFramebuffer +GLboolean gl4es_glIsFramebuffer(GLuint framebuffer) { + LOAD_GLES_OES(glIsFramebuffer); +#ifndef direct_glIsFramebuffer + PUSH_IF_COMPILING(glIsFramebuffer) +#endif + return gles_glIsFramebuffer(framebuffer); +} +GLboolean glIsFramebuffer(GLuint framebuffer) __attribute__((alias("gl4es_glIsFramebuffer"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glIsProgram +GLboolean gl4es_glIsProgram(GLuint program) { + LOAD_GLES(glIsProgram); +#ifndef direct_glIsProgram + PUSH_IF_COMPILING(glIsProgram) +#endif + return gles_glIsProgram(program); +} +GLboolean glIsProgram(GLuint program) __attribute__((alias("gl4es_glIsProgram"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glIsRenderbuffer +GLboolean gl4es_glIsRenderbuffer(GLuint renderbuffer) { + LOAD_GLES_OES(glIsRenderbuffer); +#ifndef direct_glIsRenderbuffer + PUSH_IF_COMPILING(glIsRenderbuffer) +#endif + return gles_glIsRenderbuffer(renderbuffer); +} +GLboolean glIsRenderbuffer(GLuint renderbuffer) __attribute__((alias("gl4es_glIsRenderbuffer"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glIsShader +GLboolean gl4es_glIsShader(GLuint shader) { + LOAD_GLES(glIsShader); +#ifndef direct_glIsShader + PUSH_IF_COMPILING(glIsShader) +#endif + return gles_glIsShader(shader); +} +GLboolean glIsShader(GLuint shader) __attribute__((alias("gl4es_glIsShader"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glIsTexture +GLboolean gl4es_glIsTexture(GLuint texture) { + LOAD_GLES(glIsTexture); +#ifndef direct_glIsTexture + PUSH_IF_COMPILING(glIsTexture) +#endif + return gles_glIsTexture(texture); +} +GLboolean glIsTexture(GLuint texture) __attribute__((alias("gl4es_glIsTexture"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glLightModelf +void gl4es_glLightModelf(GLenum pname, GLfloat param) { + LOAD_GLES(glLightModelf); +#ifndef direct_glLightModelf + PUSH_IF_COMPILING(glLightModelf) +#endif + gles_glLightModelf(pname, param); +} +void glLightModelf(GLenum pname, GLfloat param) __attribute__((alias("gl4es_glLightModelf"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glLightModelfv +void gl4es_glLightModelfv(GLenum pname, const GLfloat * params) { + LOAD_GLES(glLightModelfv); +#ifndef direct_glLightModelfv + PUSH_IF_COMPILING(glLightModelfv) +#endif + gles_glLightModelfv(pname, params); +} +void glLightModelfv(GLenum pname, const GLfloat * params) __attribute__((alias("gl4es_glLightModelfv"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glLightModelx +void gl4es_glLightModelx(GLenum pname, GLfixed param) { + LOAD_GLES(glLightModelx); +#ifndef direct_glLightModelx + PUSH_IF_COMPILING(glLightModelx) +#endif + gles_glLightModelx(pname, param); +} +void glLightModelx(GLenum pname, GLfixed param) __attribute__((alias("gl4es_glLightModelx"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glLightModelxv +void gl4es_glLightModelxv(GLenum pname, const GLfixed * params) { + LOAD_GLES(glLightModelxv); +#ifndef direct_glLightModelxv + PUSH_IF_COMPILING(glLightModelxv) +#endif + gles_glLightModelxv(pname, params); +} +void glLightModelxv(GLenum pname, const GLfixed * params) __attribute__((alias("gl4es_glLightModelxv"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glLightf +void gl4es_glLightf(GLenum light, GLenum pname, GLfloat param) { + LOAD_GLES(glLightf); +#ifndef direct_glLightf + PUSH_IF_COMPILING(glLightf) +#endif + gles_glLightf(light, pname, param); +} +void glLightf(GLenum light, GLenum pname, GLfloat param) __attribute__((alias("gl4es_glLightf"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glLightfv +void gl4es_glLightfv(GLenum light, GLenum pname, const GLfloat * params) { + LOAD_GLES(glLightfv); +#ifndef direct_glLightfv + PUSH_IF_COMPILING(glLightfv) +#endif + gles_glLightfv(light, pname, params); +} +void glLightfv(GLenum light, GLenum pname, const GLfloat * params) __attribute__((alias("gl4es_glLightfv"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glLightx +void gl4es_glLightx(GLenum light, GLenum pname, GLfixed param) { + LOAD_GLES(glLightx); +#ifndef direct_glLightx + PUSH_IF_COMPILING(glLightx) +#endif + gles_glLightx(light, pname, param); +} +void glLightx(GLenum light, GLenum pname, GLfixed param) __attribute__((alias("gl4es_glLightx"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glLightxv +void gl4es_glLightxv(GLenum light, GLenum pname, const GLfixed * params) { + LOAD_GLES(glLightxv); +#ifndef direct_glLightxv + PUSH_IF_COMPILING(glLightxv) +#endif + gles_glLightxv(light, pname, params); +} +void glLightxv(GLenum light, GLenum pname, const GLfixed * params) __attribute__((alias("gl4es_glLightxv"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glLineWidth +void gl4es_glLineWidth(GLfloat width) { + LOAD_GLES(glLineWidth); +#ifndef direct_glLineWidth + PUSH_IF_COMPILING(glLineWidth) +#endif + gles_glLineWidth(width); +} +void glLineWidth(GLfloat width) __attribute__((alias("gl4es_glLineWidth"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glLineWidthx +void gl4es_glLineWidthx(GLfixed width) { + LOAD_GLES(glLineWidthx); +#ifndef direct_glLineWidthx + PUSH_IF_COMPILING(glLineWidthx) +#endif + gles_glLineWidthx(width); +} +void glLineWidthx(GLfixed width) __attribute__((alias("gl4es_glLineWidthx"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glLinkProgram +void gl4es_glLinkProgram(GLuint program) { + LOAD_GLES(glLinkProgram); +#ifndef direct_glLinkProgram + PUSH_IF_COMPILING(glLinkProgram) +#endif + gles_glLinkProgram(program); +} +void glLinkProgram(GLuint program) __attribute__((alias("gl4es_glLinkProgram"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glLoadIdentity +void gl4es_glLoadIdentity() { + LOAD_GLES(glLoadIdentity); +#ifndef direct_glLoadIdentity + PUSH_IF_COMPILING(glLoadIdentity) +#endif + gles_glLoadIdentity(); +} +void glLoadIdentity() __attribute__((alias("gl4es_glLoadIdentity"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glLoadMatrixf +void gl4es_glLoadMatrixf(const GLfloat * m) { + LOAD_GLES(glLoadMatrixf); +#ifndef direct_glLoadMatrixf + PUSH_IF_COMPILING(glLoadMatrixf) +#endif + gles_glLoadMatrixf(m); +} +void glLoadMatrixf(const GLfloat * m) __attribute__((alias("gl4es_glLoadMatrixf"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glLoadMatrixx +void gl4es_glLoadMatrixx(const GLfixed * m) { + LOAD_GLES(glLoadMatrixx); +#ifndef direct_glLoadMatrixx + PUSH_IF_COMPILING(glLoadMatrixx) +#endif + gles_glLoadMatrixx(m); +} +void glLoadMatrixx(const GLfixed * m) __attribute__((alias("gl4es_glLoadMatrixx"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glLogicOp +void gl4es_glLogicOp(GLenum opcode) { + LOAD_GLES(glLogicOp); +#ifndef direct_glLogicOp + PUSH_IF_COMPILING(glLogicOp) +#endif + gles_glLogicOp(opcode); +} +void glLogicOp(GLenum opcode) __attribute__((alias("gl4es_glLogicOp"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glMaterialf +void gl4es_glMaterialf(GLenum face, GLenum pname, GLfloat param) { + LOAD_GLES(glMaterialf); +#ifndef direct_glMaterialf + PUSH_IF_COMPILING(glMaterialf) +#endif + gles_glMaterialf(face, pname, param); +} +void glMaterialf(GLenum face, GLenum pname, GLfloat param) __attribute__((alias("gl4es_glMaterialf"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glMaterialfv +void gl4es_glMaterialfv(GLenum face, GLenum pname, const GLfloat * params) { + LOAD_GLES(glMaterialfv); +#ifndef direct_glMaterialfv + PUSH_IF_COMPILING(glMaterialfv) +#endif + gles_glMaterialfv(face, pname, params); +} +void glMaterialfv(GLenum face, GLenum pname, const GLfloat * params) __attribute__((alias("gl4es_glMaterialfv"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glMaterialx +void gl4es_glMaterialx(GLenum face, GLenum pname, GLfixed param) { + LOAD_GLES(glMaterialx); +#ifndef direct_glMaterialx + PUSH_IF_COMPILING(glMaterialx) +#endif + gles_glMaterialx(face, pname, param); +} +void glMaterialx(GLenum face, GLenum pname, GLfixed param) __attribute__((alias("gl4es_glMaterialx"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glMaterialxv +void gl4es_glMaterialxv(GLenum face, GLenum pname, const GLfixed * params) { + LOAD_GLES(glMaterialxv); +#ifndef direct_glMaterialxv + PUSH_IF_COMPILING(glMaterialxv) +#endif + gles_glMaterialxv(face, pname, params); +} +void glMaterialxv(GLenum face, GLenum pname, const GLfixed * params) __attribute__((alias("gl4es_glMaterialxv"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glMatrixMode +void gl4es_glMatrixMode(GLenum mode) { + LOAD_GLES(glMatrixMode); +#ifndef direct_glMatrixMode + PUSH_IF_COMPILING(glMatrixMode) +#endif + gles_glMatrixMode(mode); +} +void glMatrixMode(GLenum mode) __attribute__((alias("gl4es_glMatrixMode"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glMultMatrixf +void gl4es_glMultMatrixf(const GLfloat * m) { + LOAD_GLES(glMultMatrixf); +#ifndef direct_glMultMatrixf + PUSH_IF_COMPILING(glMultMatrixf) +#endif + gles_glMultMatrixf(m); +} +void glMultMatrixf(const GLfloat * m) __attribute__((alias("gl4es_glMultMatrixf"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glMultMatrixx +void gl4es_glMultMatrixx(const GLfixed * m) { + LOAD_GLES(glMultMatrixx); +#ifndef direct_glMultMatrixx + PUSH_IF_COMPILING(glMultMatrixx) +#endif + gles_glMultMatrixx(m); +} +void glMultMatrixx(const GLfixed * m) __attribute__((alias("gl4es_glMultMatrixx"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glMultiDrawArrays +void gl4es_glMultiDrawArrays(GLenum mode, const GLint * first, const GLsizei * count, GLsizei primcount) { + LOAD_GLES_OES(glMultiDrawArrays); +#ifndef direct_glMultiDrawArrays + PUSH_IF_COMPILING(glMultiDrawArrays) +#endif + gles_glMultiDrawArrays(mode, first, count, primcount); +} +void glMultiDrawArrays(GLenum mode, const GLint * first, const GLsizei * count, GLsizei primcount) __attribute__((alias("gl4es_glMultiDrawArrays"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glMultiDrawElements +void gl4es_glMultiDrawElements(GLenum mode, GLsizei * count, GLenum type, const void * const * indices, GLsizei primcount) { + LOAD_GLES_OES(glMultiDrawElements); +#ifndef direct_glMultiDrawElements + PUSH_IF_COMPILING(glMultiDrawElements) +#endif + gles_glMultiDrawElements(mode, count, type, indices, primcount); +} +void glMultiDrawElements(GLenum mode, GLsizei * count, GLenum type, const void * const * indices, GLsizei primcount) __attribute__((alias("gl4es_glMultiDrawElements"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glMultiTexCoord4f +void gl4es_glMultiTexCoord4f(GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q) { + LOAD_GLES(glMultiTexCoord4f); +#ifndef direct_glMultiTexCoord4f + PUSH_IF_COMPILING(glMultiTexCoord4f) +#endif + gles_glMultiTexCoord4f(target, s, t, r, q); +} +void glMultiTexCoord4f(GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q) __attribute__((alias("gl4es_glMultiTexCoord4f"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glMultiTexCoord4x +void gl4es_glMultiTexCoord4x(GLenum target, GLfixed s, GLfixed t, GLfixed r, GLfixed q) { + LOAD_GLES(glMultiTexCoord4x); +#ifndef direct_glMultiTexCoord4x + PUSH_IF_COMPILING(glMultiTexCoord4x) +#endif + gles_glMultiTexCoord4x(target, s, t, r, q); +} +void glMultiTexCoord4x(GLenum target, GLfixed s, GLfixed t, GLfixed r, GLfixed q) __attribute__((alias("gl4es_glMultiTexCoord4x"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glNormal3f +void gl4es_glNormal3f(GLfloat nx, GLfloat ny, GLfloat nz) { + LOAD_GLES(glNormal3f); +#ifndef direct_glNormal3f + PUSH_IF_COMPILING(glNormal3f) +#endif + gles_glNormal3f(nx, ny, nz); +} +void glNormal3f(GLfloat nx, GLfloat ny, GLfloat nz) __attribute__((alias("gl4es_glNormal3f"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glNormal3x +void gl4es_glNormal3x(GLfixed nx, GLfixed ny, GLfixed nz) { + LOAD_GLES(glNormal3x); +#ifndef direct_glNormal3x + PUSH_IF_COMPILING(glNormal3x) +#endif + gles_glNormal3x(nx, ny, nz); +} +void glNormal3x(GLfixed nx, GLfixed ny, GLfixed nz) __attribute__((alias("gl4es_glNormal3x"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glNormalPointer +void gl4es_glNormalPointer(GLenum type, GLsizei stride, const GLvoid * pointer) { + LOAD_GLES(glNormalPointer); +#ifndef direct_glNormalPointer + PUSH_IF_COMPILING(glNormalPointer) +#endif + gles_glNormalPointer(type, stride, pointer); +} +void glNormalPointer(GLenum type, GLsizei stride, const GLvoid * pointer) __attribute__((alias("gl4es_glNormalPointer"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glOrthof +void gl4es_glOrthof(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat near, GLfloat far) { + LOAD_GLES(glOrthof); +#ifndef direct_glOrthof + PUSH_IF_COMPILING(glOrthof) +#endif + gles_glOrthof(left, right, bottom, top, near, far); +} +void glOrthof(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat near, GLfloat far) __attribute__((alias("gl4es_glOrthof"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glOrthox +void gl4es_glOrthox(GLfixed left, GLfixed right, GLfixed bottom, GLfixed top, GLfixed near, GLfixed far) { + LOAD_GLES(glOrthox); +#ifndef direct_glOrthox + PUSH_IF_COMPILING(glOrthox) +#endif + gles_glOrthox(left, right, bottom, top, near, far); +} +void glOrthox(GLfixed left, GLfixed right, GLfixed bottom, GLfixed top, GLfixed near, GLfixed far) __attribute__((alias("gl4es_glOrthox"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glPixelStorei +void gl4es_glPixelStorei(GLenum pname, GLint param) { + LOAD_GLES(glPixelStorei); +#ifndef direct_glPixelStorei + PUSH_IF_COMPILING(glPixelStorei) +#endif + gles_glPixelStorei(pname, param); +} +void glPixelStorei(GLenum pname, GLint param) __attribute__((alias("gl4es_glPixelStorei"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glPointParameterf +void gl4es_glPointParameterf(GLenum pname, GLfloat param) { + LOAD_GLES(glPointParameterf); +#ifndef direct_glPointParameterf + PUSH_IF_COMPILING(glPointParameterf) +#endif + gles_glPointParameterf(pname, param); +} +void glPointParameterf(GLenum pname, GLfloat param) __attribute__((alias("gl4es_glPointParameterf"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glPointParameterfv +void gl4es_glPointParameterfv(GLenum pname, const GLfloat * params) { + LOAD_GLES(glPointParameterfv); +#ifndef direct_glPointParameterfv + PUSH_IF_COMPILING(glPointParameterfv) +#endif + gles_glPointParameterfv(pname, params); +} +void glPointParameterfv(GLenum pname, const GLfloat * params) __attribute__((alias("gl4es_glPointParameterfv"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glPointParameterx +void gl4es_glPointParameterx(GLenum pname, GLfixed param) { + LOAD_GLES(glPointParameterx); +#ifndef direct_glPointParameterx + PUSH_IF_COMPILING(glPointParameterx) +#endif + gles_glPointParameterx(pname, param); +} +void glPointParameterx(GLenum pname, GLfixed param) __attribute__((alias("gl4es_glPointParameterx"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glPointParameterxv +void gl4es_glPointParameterxv(GLenum pname, const GLfixed * params) { + LOAD_GLES(glPointParameterxv); +#ifndef direct_glPointParameterxv + PUSH_IF_COMPILING(glPointParameterxv) +#endif + gles_glPointParameterxv(pname, params); +} +void glPointParameterxv(GLenum pname, const GLfixed * params) __attribute__((alias("gl4es_glPointParameterxv"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glPointSize +void gl4es_glPointSize(GLfloat size) { + LOAD_GLES(glPointSize); +#ifndef direct_glPointSize + PUSH_IF_COMPILING(glPointSize) +#endif + gles_glPointSize(size); +} +void glPointSize(GLfloat size) __attribute__((alias("gl4es_glPointSize"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glPointSizePointerOES +void gl4es_glPointSizePointerOES(GLenum type, GLsizei stride, const GLvoid * pointer) { + LOAD_GLES(glPointSizePointerOES); +#ifndef direct_glPointSizePointerOES + PUSH_IF_COMPILING(glPointSizePointerOES) +#endif + gles_glPointSizePointerOES(type, stride, pointer); +} +void glPointSizePointerOES(GLenum type, GLsizei stride, const GLvoid * pointer) __attribute__((alias("gl4es_glPointSizePointerOES"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glPointSizex +void gl4es_glPointSizex(GLfixed size) { + LOAD_GLES(glPointSizex); +#ifndef direct_glPointSizex + PUSH_IF_COMPILING(glPointSizex) +#endif + gles_glPointSizex(size); +} +void glPointSizex(GLfixed size) __attribute__((alias("gl4es_glPointSizex"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glPolygonOffset +void gl4es_glPolygonOffset(GLfloat factor, GLfloat units) { + LOAD_GLES(glPolygonOffset); +#ifndef direct_glPolygonOffset + PUSH_IF_COMPILING(glPolygonOffset) +#endif + gles_glPolygonOffset(factor, units); +} +void glPolygonOffset(GLfloat factor, GLfloat units) __attribute__((alias("gl4es_glPolygonOffset"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glPolygonOffsetx +void gl4es_glPolygonOffsetx(GLfixed factor, GLfixed units) { + LOAD_GLES(glPolygonOffsetx); +#ifndef direct_glPolygonOffsetx + PUSH_IF_COMPILING(glPolygonOffsetx) +#endif + gles_glPolygonOffsetx(factor, units); +} +void glPolygonOffsetx(GLfixed factor, GLfixed units) __attribute__((alias("gl4es_glPolygonOffsetx"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glPopMatrix +void gl4es_glPopMatrix() { + LOAD_GLES(glPopMatrix); +#ifndef direct_glPopMatrix + PUSH_IF_COMPILING(glPopMatrix) +#endif + gles_glPopMatrix(); +} +void glPopMatrix() __attribute__((alias("gl4es_glPopMatrix"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glPushMatrix +void gl4es_glPushMatrix() { + LOAD_GLES(glPushMatrix); +#ifndef direct_glPushMatrix + PUSH_IF_COMPILING(glPushMatrix) +#endif + gles_glPushMatrix(); +} +void glPushMatrix() __attribute__((alias("gl4es_glPushMatrix"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glReadPixels +void gl4es_glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid * pixels) { + LOAD_GLES(glReadPixels); +#ifndef direct_glReadPixels + PUSH_IF_COMPILING(glReadPixels) +#endif + gles_glReadPixels(x, y, width, height, format, type, pixels); +} +void glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid * pixels) __attribute__((alias("gl4es_glReadPixels"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glReleaseShaderCompiler +void gl4es_glReleaseShaderCompiler() { + LOAD_GLES(glReleaseShaderCompiler); +#ifndef direct_glReleaseShaderCompiler + PUSH_IF_COMPILING(glReleaseShaderCompiler) +#endif + gles_glReleaseShaderCompiler(); +} +void glReleaseShaderCompiler() __attribute__((alias("gl4es_glReleaseShaderCompiler"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glRenderbufferStorage +void gl4es_glRenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height) { + LOAD_GLES_OES(glRenderbufferStorage); +#ifndef direct_glRenderbufferStorage + PUSH_IF_COMPILING(glRenderbufferStorage) +#endif + gles_glRenderbufferStorage(target, internalformat, width, height); +} +void glRenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height) __attribute__((alias("gl4es_glRenderbufferStorage"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glRotatef +void gl4es_glRotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z) { + LOAD_GLES(glRotatef); +#ifndef direct_glRotatef + PUSH_IF_COMPILING(glRotatef) +#endif + gles_glRotatef(angle, x, y, z); +} +void glRotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z) __attribute__((alias("gl4es_glRotatef"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glRotatex +void gl4es_glRotatex(GLfixed angle, GLfixed x, GLfixed y, GLfixed z) { + LOAD_GLES(glRotatex); +#ifndef direct_glRotatex + PUSH_IF_COMPILING(glRotatex) +#endif + gles_glRotatex(angle, x, y, z); +} +void glRotatex(GLfixed angle, GLfixed x, GLfixed y, GLfixed z) __attribute__((alias("gl4es_glRotatex"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glSampleCoverage +void gl4es_glSampleCoverage(GLclampf value, GLboolean invert) { + LOAD_GLES(glSampleCoverage); +#ifndef direct_glSampleCoverage + PUSH_IF_COMPILING(glSampleCoverage) +#endif + gles_glSampleCoverage(value, invert); +} +void glSampleCoverage(GLclampf value, GLboolean invert) __attribute__((alias("gl4es_glSampleCoverage"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glSampleCoveragex +void gl4es_glSampleCoveragex(GLclampx value, GLboolean invert) { + LOAD_GLES(glSampleCoveragex); +#ifndef direct_glSampleCoveragex + PUSH_IF_COMPILING(glSampleCoveragex) +#endif + gles_glSampleCoveragex(value, invert); +} +void glSampleCoveragex(GLclampx value, GLboolean invert) __attribute__((alias("gl4es_glSampleCoveragex"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glScalef +void gl4es_glScalef(GLfloat x, GLfloat y, GLfloat z) { + LOAD_GLES(glScalef); +#ifndef direct_glScalef + PUSH_IF_COMPILING(glScalef) +#endif + gles_glScalef(x, y, z); +} +void glScalef(GLfloat x, GLfloat y, GLfloat z) __attribute__((alias("gl4es_glScalef"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glScalex +void gl4es_glScalex(GLfixed x, GLfixed y, GLfixed z) { + LOAD_GLES(glScalex); +#ifndef direct_glScalex + PUSH_IF_COMPILING(glScalex) +#endif + gles_glScalex(x, y, z); +} +void glScalex(GLfixed x, GLfixed y, GLfixed z) __attribute__((alias("gl4es_glScalex"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glScissor +void gl4es_glScissor(GLint x, GLint y, GLsizei width, GLsizei height) { + LOAD_GLES(glScissor); +#ifndef direct_glScissor + PUSH_IF_COMPILING(glScissor) +#endif + gles_glScissor(x, y, width, height); +} +void glScissor(GLint x, GLint y, GLsizei width, GLsizei height) __attribute__((alias("gl4es_glScissor"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glShadeModel +void gl4es_glShadeModel(GLenum mode) { + LOAD_GLES(glShadeModel); +#ifndef direct_glShadeModel + PUSH_IF_COMPILING(glShadeModel) +#endif + gles_glShadeModel(mode); +} +void glShadeModel(GLenum mode) __attribute__((alias("gl4es_glShadeModel"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glShaderBinary +void gl4es_glShaderBinary(GLsizei n, const GLuint * shaders, GLenum binaryformat, const GLvoid * binary, GLsizei length) { + LOAD_GLES(glShaderBinary); +#ifndef direct_glShaderBinary + PUSH_IF_COMPILING(glShaderBinary) +#endif + gles_glShaderBinary(n, shaders, binaryformat, binary, length); +} +void glShaderBinary(GLsizei n, const GLuint * shaders, GLenum binaryformat, const GLvoid * binary, GLsizei length) __attribute__((alias("gl4es_glShaderBinary"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glShaderSource +void gl4es_glShaderSource(GLuint shader, GLsizei count, const GLchar * const * string, const GLint * length) { + LOAD_GLES(glShaderSource); +#ifndef direct_glShaderSource + PUSH_IF_COMPILING(glShaderSource) +#endif + gles_glShaderSource(shader, count, string, length); +} +void glShaderSource(GLuint shader, GLsizei count, const GLchar * const * string, const GLint * length) __attribute__((alias("gl4es_glShaderSource"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glStencilFunc +void gl4es_glStencilFunc(GLenum func, GLint ref, GLuint mask) { + LOAD_GLES(glStencilFunc); +#ifndef direct_glStencilFunc + PUSH_IF_COMPILING(glStencilFunc) +#endif + gles_glStencilFunc(func, ref, mask); +} +void glStencilFunc(GLenum func, GLint ref, GLuint mask) __attribute__((alias("gl4es_glStencilFunc"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glStencilFuncSeparate +void gl4es_glStencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask) { + LOAD_GLES(glStencilFuncSeparate); +#ifndef direct_glStencilFuncSeparate + PUSH_IF_COMPILING(glStencilFuncSeparate) +#endif + gles_glStencilFuncSeparate(face, func, ref, mask); +} +void glStencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask) __attribute__((alias("gl4es_glStencilFuncSeparate"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glStencilMask +void gl4es_glStencilMask(GLuint mask) { + LOAD_GLES(glStencilMask); +#ifndef direct_glStencilMask + PUSH_IF_COMPILING(glStencilMask) +#endif + gles_glStencilMask(mask); +} +void glStencilMask(GLuint mask) __attribute__((alias("gl4es_glStencilMask"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glStencilMaskSeparate +void gl4es_glStencilMaskSeparate(GLenum face, GLuint mask) { + LOAD_GLES(glStencilMaskSeparate); +#ifndef direct_glStencilMaskSeparate + PUSH_IF_COMPILING(glStencilMaskSeparate) +#endif + gles_glStencilMaskSeparate(face, mask); +} +void glStencilMaskSeparate(GLenum face, GLuint mask) __attribute__((alias("gl4es_glStencilMaskSeparate"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glStencilOp +void gl4es_glStencilOp(GLenum fail, GLenum zfail, GLenum zpass) { + LOAD_GLES(glStencilOp); +#ifndef direct_glStencilOp + PUSH_IF_COMPILING(glStencilOp) +#endif + gles_glStencilOp(fail, zfail, zpass); +} +void glStencilOp(GLenum fail, GLenum zfail, GLenum zpass) __attribute__((alias("gl4es_glStencilOp"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glStencilOpSeparate +void gl4es_glStencilOpSeparate(GLenum face, GLenum sfail, GLenum zfail, GLenum zpass) { + LOAD_GLES(glStencilOpSeparate); +#ifndef direct_glStencilOpSeparate + PUSH_IF_COMPILING(glStencilOpSeparate) +#endif + gles_glStencilOpSeparate(face, sfail, zfail, zpass); +} +void glStencilOpSeparate(GLenum face, GLenum sfail, GLenum zfail, GLenum zpass) __attribute__((alias("gl4es_glStencilOpSeparate"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glTexCoordPointer +void gl4es_glTexCoordPointer(GLint size, GLenum type, GLsizei stride, const GLvoid * pointer) { + LOAD_GLES(glTexCoordPointer); +#ifndef direct_glTexCoordPointer + PUSH_IF_COMPILING(glTexCoordPointer) +#endif + gles_glTexCoordPointer(size, type, stride, pointer); +} +void glTexCoordPointer(GLint size, GLenum type, GLsizei stride, const GLvoid * pointer) __attribute__((alias("gl4es_glTexCoordPointer"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glTexEnvf +void gl4es_glTexEnvf(GLenum target, GLenum pname, GLfloat param) { + LOAD_GLES(glTexEnvf); +#ifndef direct_glTexEnvf + PUSH_IF_COMPILING(glTexEnvf) +#endif + gles_glTexEnvf(target, pname, param); +} +void glTexEnvf(GLenum target, GLenum pname, GLfloat param) __attribute__((alias("gl4es_glTexEnvf"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glTexEnvfv +void gl4es_glTexEnvfv(GLenum target, GLenum pname, const GLfloat * params) { + LOAD_GLES(glTexEnvfv); +#ifndef direct_glTexEnvfv + PUSH_IF_COMPILING(glTexEnvfv) +#endif + gles_glTexEnvfv(target, pname, params); +} +void glTexEnvfv(GLenum target, GLenum pname, const GLfloat * params) __attribute__((alias("gl4es_glTexEnvfv"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glTexEnvi +void gl4es_glTexEnvi(GLenum target, GLenum pname, GLint param) { + LOAD_GLES(glTexEnvi); +#ifndef direct_glTexEnvi + PUSH_IF_COMPILING(glTexEnvi) +#endif + gles_glTexEnvi(target, pname, param); +} +void glTexEnvi(GLenum target, GLenum pname, GLint param) __attribute__((alias("gl4es_glTexEnvi"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glTexEnviv +void gl4es_glTexEnviv(GLenum target, GLenum pname, const GLint * params) { + LOAD_GLES(glTexEnviv); +#ifndef direct_glTexEnviv + PUSH_IF_COMPILING(glTexEnviv) +#endif + gles_glTexEnviv(target, pname, params); +} +void glTexEnviv(GLenum target, GLenum pname, const GLint * params) __attribute__((alias("gl4es_glTexEnviv"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glTexEnvx +void gl4es_glTexEnvx(GLenum target, GLenum pname, GLfixed param) { + LOAD_GLES(glTexEnvx); +#ifndef direct_glTexEnvx + PUSH_IF_COMPILING(glTexEnvx) +#endif + gles_glTexEnvx(target, pname, param); +} +void glTexEnvx(GLenum target, GLenum pname, GLfixed param) __attribute__((alias("gl4es_glTexEnvx"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glTexEnvxv +void gl4es_glTexEnvxv(GLenum target, GLenum pname, const GLfixed * params) { + LOAD_GLES(glTexEnvxv); +#ifndef direct_glTexEnvxv + PUSH_IF_COMPILING(glTexEnvxv) +#endif + gles_glTexEnvxv(target, pname, params); +} +void glTexEnvxv(GLenum target, GLenum pname, const GLfixed * params) __attribute__((alias("gl4es_glTexEnvxv"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glTexGenfv +void gl4es_glTexGenfv(GLenum coord, GLenum pname, const GLfloat * params) { + LOAD_GLES_OES(glTexGenfv); +#ifndef direct_glTexGenfv + PUSH_IF_COMPILING(glTexGenfv) +#endif + gles_glTexGenfv(coord, pname, params); +} +void glTexGenfv(GLenum coord, GLenum pname, const GLfloat * params) __attribute__((alias("gl4es_glTexGenfv"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glTexGeni +void gl4es_glTexGeni(GLenum coord, GLenum pname, GLint param) { + LOAD_GLES_OES(glTexGeni); +#ifndef direct_glTexGeni + PUSH_IF_COMPILING(glTexGeni) +#endif + gles_glTexGeni(coord, pname, param); +} +void glTexGeni(GLenum coord, GLenum pname, GLint param) __attribute__((alias("gl4es_glTexGeni"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glTexImage2D +void gl4es_glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid * data) { + LOAD_GLES(glTexImage2D); +#ifndef direct_glTexImage2D + PUSH_IF_COMPILING(glTexImage2D) +#endif + gles_glTexImage2D(target, level, internalformat, width, height, border, format, type, data); +} +void glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid * data) __attribute__((alias("gl4es_glTexImage2D"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glTexParameterf +void gl4es_glTexParameterf(GLenum target, GLenum pname, GLfloat param) { + LOAD_GLES(glTexParameterf); +#ifndef direct_glTexParameterf + PUSH_IF_COMPILING(glTexParameterf) +#endif + gles_glTexParameterf(target, pname, param); +} +void glTexParameterf(GLenum target, GLenum pname, GLfloat param) __attribute__((alias("gl4es_glTexParameterf"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glTexParameterfv +void gl4es_glTexParameterfv(GLenum target, GLenum pname, const GLfloat * params) { + LOAD_GLES(glTexParameterfv); +#ifndef direct_glTexParameterfv + PUSH_IF_COMPILING(glTexParameterfv) +#endif + gles_glTexParameterfv(target, pname, params); +} +void glTexParameterfv(GLenum target, GLenum pname, const GLfloat * params) __attribute__((alias("gl4es_glTexParameterfv"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glTexParameteri +void gl4es_glTexParameteri(GLenum target, GLenum pname, GLint param) { + LOAD_GLES(glTexParameteri); +#ifndef direct_glTexParameteri + PUSH_IF_COMPILING(glTexParameteri) +#endif + gles_glTexParameteri(target, pname, param); +} +void glTexParameteri(GLenum target, GLenum pname, GLint param) __attribute__((alias("gl4es_glTexParameteri"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glTexParameteriv +void gl4es_glTexParameteriv(GLenum target, GLenum pname, const GLint * params) { + LOAD_GLES(glTexParameteriv); +#ifndef direct_glTexParameteriv + PUSH_IF_COMPILING(glTexParameteriv) +#endif + gles_glTexParameteriv(target, pname, params); +} +void glTexParameteriv(GLenum target, GLenum pname, const GLint * params) __attribute__((alias("gl4es_glTexParameteriv"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glTexParameterx +void gl4es_glTexParameterx(GLenum target, GLenum pname, GLfixed param) { + LOAD_GLES(glTexParameterx); +#ifndef direct_glTexParameterx + PUSH_IF_COMPILING(glTexParameterx) +#endif + gles_glTexParameterx(target, pname, param); +} +void glTexParameterx(GLenum target, GLenum pname, GLfixed param) __attribute__((alias("gl4es_glTexParameterx"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glTexParameterxv +void gl4es_glTexParameterxv(GLenum target, GLenum pname, const GLfixed * params) { + LOAD_GLES(glTexParameterxv); +#ifndef direct_glTexParameterxv + PUSH_IF_COMPILING(glTexParameterxv) +#endif + gles_glTexParameterxv(target, pname, params); +} +void glTexParameterxv(GLenum target, GLenum pname, const GLfixed * params) __attribute__((alias("gl4es_glTexParameterxv"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glTexSubImage2D +void gl4es_glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid * data) { + LOAD_GLES(glTexSubImage2D); +#ifndef direct_glTexSubImage2D + PUSH_IF_COMPILING(glTexSubImage2D) +#endif + gles_glTexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, data); +} +void glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid * data) __attribute__((alias("gl4es_glTexSubImage2D"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glTranslatef +void gl4es_glTranslatef(GLfloat x, GLfloat y, GLfloat z) { + LOAD_GLES(glTranslatef); +#ifndef direct_glTranslatef + PUSH_IF_COMPILING(glTranslatef) +#endif + gles_glTranslatef(x, y, z); +} +void glTranslatef(GLfloat x, GLfloat y, GLfloat z) __attribute__((alias("gl4es_glTranslatef"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glTranslatex +void gl4es_glTranslatex(GLfixed x, GLfixed y, GLfixed z) { + LOAD_GLES(glTranslatex); +#ifndef direct_glTranslatex + PUSH_IF_COMPILING(glTranslatex) +#endif + gles_glTranslatex(x, y, z); +} +void glTranslatex(GLfixed x, GLfixed y, GLfixed z) __attribute__((alias("gl4es_glTranslatex"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glUniform1f +void gl4es_glUniform1f(GLint location, GLfloat v0) { + LOAD_GLES(glUniform1f); +#ifndef direct_glUniform1f + PUSH_IF_COMPILING(glUniform1f) +#endif + gles_glUniform1f(location, v0); +} +void glUniform1f(GLint location, GLfloat v0) __attribute__((alias("gl4es_glUniform1f"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glUniform1fv +void gl4es_glUniform1fv(GLint location, GLsizei count, const GLfloat * value) { + LOAD_GLES(glUniform1fv); +#ifndef direct_glUniform1fv + PUSH_IF_COMPILING(glUniform1fv) +#endif + gles_glUniform1fv(location, count, value); +} +void glUniform1fv(GLint location, GLsizei count, const GLfloat * value) __attribute__((alias("gl4es_glUniform1fv"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glUniform1i +void gl4es_glUniform1i(GLint location, GLint v0) { + LOAD_GLES(glUniform1i); +#ifndef direct_glUniform1i + PUSH_IF_COMPILING(glUniform1i) +#endif + gles_glUniform1i(location, v0); +} +void glUniform1i(GLint location, GLint v0) __attribute__((alias("gl4es_glUniform1i"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glUniform1iv +void gl4es_glUniform1iv(GLint location, GLsizei count, const GLint * value) { + LOAD_GLES(glUniform1iv); +#ifndef direct_glUniform1iv + PUSH_IF_COMPILING(glUniform1iv) +#endif + gles_glUniform1iv(location, count, value); +} +void glUniform1iv(GLint location, GLsizei count, const GLint * value) __attribute__((alias("gl4es_glUniform1iv"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glUniform2f +void gl4es_glUniform2f(GLint location, GLfloat v0, GLfloat v1) { + LOAD_GLES(glUniform2f); +#ifndef direct_glUniform2f + PUSH_IF_COMPILING(glUniform2f) +#endif + gles_glUniform2f(location, v0, v1); +} +void glUniform2f(GLint location, GLfloat v0, GLfloat v1) __attribute__((alias("gl4es_glUniform2f"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glUniform2fv +void gl4es_glUniform2fv(GLint location, GLsizei count, const GLfloat * value) { + LOAD_GLES(glUniform2fv); +#ifndef direct_glUniform2fv + PUSH_IF_COMPILING(glUniform2fv) +#endif + gles_glUniform2fv(location, count, value); +} +void glUniform2fv(GLint location, GLsizei count, const GLfloat * value) __attribute__((alias("gl4es_glUniform2fv"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glUniform2i +void gl4es_glUniform2i(GLint location, GLint v0, GLint v1) { + LOAD_GLES(glUniform2i); +#ifndef direct_glUniform2i + PUSH_IF_COMPILING(glUniform2i) +#endif + gles_glUniform2i(location, v0, v1); +} +void glUniform2i(GLint location, GLint v0, GLint v1) __attribute__((alias("gl4es_glUniform2i"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glUniform2iv +void gl4es_glUniform2iv(GLint location, GLsizei count, const GLint * value) { + LOAD_GLES(glUniform2iv); +#ifndef direct_glUniform2iv + PUSH_IF_COMPILING(glUniform2iv) +#endif + gles_glUniform2iv(location, count, value); +} +void glUniform2iv(GLint location, GLsizei count, const GLint * value) __attribute__((alias("gl4es_glUniform2iv"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glUniform3f +void gl4es_glUniform3f(GLint location, GLfloat v0, GLfloat v1, GLfloat v2) { + LOAD_GLES(glUniform3f); +#ifndef direct_glUniform3f + PUSH_IF_COMPILING(glUniform3f) +#endif + gles_glUniform3f(location, v0, v1, v2); +} +void glUniform3f(GLint location, GLfloat v0, GLfloat v1, GLfloat v2) __attribute__((alias("gl4es_glUniform3f"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glUniform3fv +void gl4es_glUniform3fv(GLint location, GLsizei count, const GLfloat * value) { + LOAD_GLES(glUniform3fv); +#ifndef direct_glUniform3fv + PUSH_IF_COMPILING(glUniform3fv) +#endif + gles_glUniform3fv(location, count, value); +} +void glUniform3fv(GLint location, GLsizei count, const GLfloat * value) __attribute__((alias("gl4es_glUniform3fv"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glUniform3i +void gl4es_glUniform3i(GLint location, GLint v0, GLint v1, GLint v2) { + LOAD_GLES(glUniform3i); +#ifndef direct_glUniform3i + PUSH_IF_COMPILING(glUniform3i) +#endif + gles_glUniform3i(location, v0, v1, v2); +} +void glUniform3i(GLint location, GLint v0, GLint v1, GLint v2) __attribute__((alias("gl4es_glUniform3i"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glUniform3iv +void gl4es_glUniform3iv(GLint location, GLsizei count, const GLint * value) { + LOAD_GLES(glUniform3iv); +#ifndef direct_glUniform3iv + PUSH_IF_COMPILING(glUniform3iv) +#endif + gles_glUniform3iv(location, count, value); +} +void glUniform3iv(GLint location, GLsizei count, const GLint * value) __attribute__((alias("gl4es_glUniform3iv"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glUniform4f +void gl4es_glUniform4f(GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3) { + LOAD_GLES(glUniform4f); +#ifndef direct_glUniform4f + PUSH_IF_COMPILING(glUniform4f) +#endif + gles_glUniform4f(location, v0, v1, v2, v3); +} +void glUniform4f(GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3) __attribute__((alias("gl4es_glUniform4f"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glUniform4fv +void gl4es_glUniform4fv(GLint location, GLsizei count, const GLfloat * value) { + LOAD_GLES(glUniform4fv); +#ifndef direct_glUniform4fv + PUSH_IF_COMPILING(glUniform4fv) +#endif + gles_glUniform4fv(location, count, value); +} +void glUniform4fv(GLint location, GLsizei count, const GLfloat * value) __attribute__((alias("gl4es_glUniform4fv"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glUniform4i +void gl4es_glUniform4i(GLint location, GLint v0, GLint v1, GLint v2, GLint v3) { + LOAD_GLES(glUniform4i); +#ifndef direct_glUniform4i + PUSH_IF_COMPILING(glUniform4i) +#endif + gles_glUniform4i(location, v0, v1, v2, v3); +} +void glUniform4i(GLint location, GLint v0, GLint v1, GLint v2, GLint v3) __attribute__((alias("gl4es_glUniform4i"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glUniform4iv +void gl4es_glUniform4iv(GLint location, GLsizei count, const GLint * value) { + LOAD_GLES(glUniform4iv); +#ifndef direct_glUniform4iv + PUSH_IF_COMPILING(glUniform4iv) +#endif + gles_glUniform4iv(location, count, value); +} +void glUniform4iv(GLint location, GLsizei count, const GLint * value) __attribute__((alias("gl4es_glUniform4iv"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glUniformMatrix2fv +void gl4es_glUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat * value) { + LOAD_GLES(glUniformMatrix2fv); +#ifndef direct_glUniformMatrix2fv + PUSH_IF_COMPILING(glUniformMatrix2fv) +#endif + gles_glUniformMatrix2fv(location, count, transpose, value); +} +void glUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat * value) __attribute__((alias("gl4es_glUniformMatrix2fv"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glUniformMatrix3fv +void gl4es_glUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat * value) { + LOAD_GLES(glUniformMatrix3fv); +#ifndef direct_glUniformMatrix3fv + PUSH_IF_COMPILING(glUniformMatrix3fv) +#endif + gles_glUniformMatrix3fv(location, count, transpose, value); +} +void glUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat * value) __attribute__((alias("gl4es_glUniformMatrix3fv"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glUniformMatrix4fv +void gl4es_glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat * value) { + LOAD_GLES(glUniformMatrix4fv); +#ifndef direct_glUniformMatrix4fv + PUSH_IF_COMPILING(glUniformMatrix4fv) +#endif + gles_glUniformMatrix4fv(location, count, transpose, value); +} +void glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat * value) __attribute__((alias("gl4es_glUniformMatrix4fv"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glUseProgram +void gl4es_glUseProgram(GLuint program) { + LOAD_GLES(glUseProgram); +#ifndef direct_glUseProgram + PUSH_IF_COMPILING(glUseProgram) +#endif + gles_glUseProgram(program); +} +void glUseProgram(GLuint program) __attribute__((alias("gl4es_glUseProgram"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glValidateProgram +void gl4es_glValidateProgram(GLuint program) { + LOAD_GLES(glValidateProgram); +#ifndef direct_glValidateProgram + PUSH_IF_COMPILING(glValidateProgram) +#endif + gles_glValidateProgram(program); +} +void glValidateProgram(GLuint program) __attribute__((alias("gl4es_glValidateProgram"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glVertexAttrib1f +void gl4es_glVertexAttrib1f(GLuint index, GLfloat x) { + LOAD_GLES(glVertexAttrib1f); +#ifndef direct_glVertexAttrib1f + PUSH_IF_COMPILING(glVertexAttrib1f) +#endif + gles_glVertexAttrib1f(index, x); +} +void glVertexAttrib1f(GLuint index, GLfloat x) __attribute__((alias("gl4es_glVertexAttrib1f"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glVertexAttrib1fv +void gl4es_glVertexAttrib1fv(GLuint index, const GLfloat * v) { + LOAD_GLES(glVertexAttrib1fv); +#ifndef direct_glVertexAttrib1fv + PUSH_IF_COMPILING(glVertexAttrib1fv) +#endif + gles_glVertexAttrib1fv(index, v); +} +void glVertexAttrib1fv(GLuint index, const GLfloat * v) __attribute__((alias("gl4es_glVertexAttrib1fv"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glVertexAttrib2f +void gl4es_glVertexAttrib2f(GLuint index, GLfloat x, GLfloat y) { + LOAD_GLES(glVertexAttrib2f); +#ifndef direct_glVertexAttrib2f + PUSH_IF_COMPILING(glVertexAttrib2f) +#endif + gles_glVertexAttrib2f(index, x, y); +} +void glVertexAttrib2f(GLuint index, GLfloat x, GLfloat y) __attribute__((alias("gl4es_glVertexAttrib2f"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glVertexAttrib2fv +void gl4es_glVertexAttrib2fv(GLuint index, const GLfloat * v) { + LOAD_GLES(glVertexAttrib2fv); +#ifndef direct_glVertexAttrib2fv + PUSH_IF_COMPILING(glVertexAttrib2fv) +#endif + gles_glVertexAttrib2fv(index, v); +} +void glVertexAttrib2fv(GLuint index, const GLfloat * v) __attribute__((alias("gl4es_glVertexAttrib2fv"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glVertexAttrib3f +void gl4es_glVertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z) { + LOAD_GLES(glVertexAttrib3f); +#ifndef direct_glVertexAttrib3f + PUSH_IF_COMPILING(glVertexAttrib3f) +#endif + gles_glVertexAttrib3f(index, x, y, z); +} +void glVertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z) __attribute__((alias("gl4es_glVertexAttrib3f"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glVertexAttrib3fv +void gl4es_glVertexAttrib3fv(GLuint index, const GLfloat * v) { + LOAD_GLES(glVertexAttrib3fv); +#ifndef direct_glVertexAttrib3fv + PUSH_IF_COMPILING(glVertexAttrib3fv) +#endif + gles_glVertexAttrib3fv(index, v); +} +void glVertexAttrib3fv(GLuint index, const GLfloat * v) __attribute__((alias("gl4es_glVertexAttrib3fv"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glVertexAttrib4f +void gl4es_glVertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w) { + LOAD_GLES(glVertexAttrib4f); +#ifndef direct_glVertexAttrib4f + PUSH_IF_COMPILING(glVertexAttrib4f) +#endif + gles_glVertexAttrib4f(index, x, y, z, w); +} +void glVertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w) __attribute__((alias("gl4es_glVertexAttrib4f"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glVertexAttrib4fv +void gl4es_glVertexAttrib4fv(GLuint index, const GLfloat * v) { + LOAD_GLES(glVertexAttrib4fv); +#ifndef direct_glVertexAttrib4fv + PUSH_IF_COMPILING(glVertexAttrib4fv) +#endif + gles_glVertexAttrib4fv(index, v); +} +void glVertexAttrib4fv(GLuint index, const GLfloat * v) __attribute__((alias("gl4es_glVertexAttrib4fv"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glVertexAttribPointer +void gl4es_glVertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid * pointer) { + LOAD_GLES(glVertexAttribPointer); +#ifndef direct_glVertexAttribPointer + PUSH_IF_COMPILING(glVertexAttribPointer) +#endif + gles_glVertexAttribPointer(index, size, type, normalized, stride, pointer); +} +void glVertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid * pointer) __attribute__((alias("gl4es_glVertexAttribPointer"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glVertexPointer +void gl4es_glVertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid * pointer) { + LOAD_GLES(glVertexPointer); +#ifndef direct_glVertexPointer + PUSH_IF_COMPILING(glVertexPointer) +#endif + gles_glVertexPointer(size, type, stride, pointer); +} +void glVertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid * pointer) __attribute__((alias("gl4es_glVertexPointer"))) __attribute__((visibility("default"))); +#endif +#ifndef skip_glViewport +void gl4es_glViewport(GLint x, GLint y, GLsizei width, GLsizei height) { + LOAD_GLES(glViewport); +#ifndef direct_glViewport + PUSH_IF_COMPILING(glViewport) +#endif + gles_glViewport(x, y, width, height); +} +void glViewport(GLint x, GLint y, GLsizei width, GLsizei height) __attribute__((alias("gl4es_glViewport"))) __attribute__((visibility("default"))); +#endif +void glPackedCall(const packed_call_t *packed) { + switch (packed->format) { + case FORMAT_void_GLenum: { + PACKED_void_GLenum *unpacked = (PACKED_void_GLenum *)packed; + ARGS_void_GLenum args = unpacked->args; + unpacked->func(args.a1); + break; + } + case FORMAT_void_GLenum_GLclampf: { + PACKED_void_GLenum_GLclampf *unpacked = (PACKED_void_GLenum_GLclampf *)packed; + ARGS_void_GLenum_GLclampf args = unpacked->args; + unpacked->func(args.a1, args.a2); + break; + } + case FORMAT_void_GLenum_GLclampx: { + PACKED_void_GLenum_GLclampx *unpacked = (PACKED_void_GLenum_GLclampx *)packed; + ARGS_void_GLenum_GLclampx args = unpacked->args; + unpacked->func(args.a1, args.a2); + break; + } + case FORMAT_void_GLuint_GLuint: { + PACKED_void_GLuint_GLuint *unpacked = (PACKED_void_GLuint_GLuint *)packed; + ARGS_void_GLuint_GLuint args = unpacked->args; + unpacked->func(args.a1, args.a2); + break; + } + case FORMAT_void_GLuint_GLuint_const_GLchar___GENPT__: { + PACKED_void_GLuint_GLuint_const_GLchar___GENPT__ *unpacked = (PACKED_void_GLuint_GLuint_const_GLchar___GENPT__ *)packed; + ARGS_void_GLuint_GLuint_const_GLchar___GENPT__ args = unpacked->args; + unpacked->func(args.a1, args.a2, args.a3); + break; + } + case FORMAT_void_GLenum_GLuint: { + PACKED_void_GLenum_GLuint *unpacked = (PACKED_void_GLenum_GLuint *)packed; + ARGS_void_GLenum_GLuint args = unpacked->args; + unpacked->func(args.a1, args.a2); + break; + } + case FORMAT_void_GLclampf_GLclampf_GLclampf_GLclampf: { + PACKED_void_GLclampf_GLclampf_GLclampf_GLclampf *unpacked = (PACKED_void_GLclampf_GLclampf_GLclampf_GLclampf *)packed; + ARGS_void_GLclampf_GLclampf_GLclampf_GLclampf args = unpacked->args; + unpacked->func(args.a1, args.a2, args.a3, args.a4); + break; + } + case FORMAT_void_GLenum_GLenum: { + PACKED_void_GLenum_GLenum *unpacked = (PACKED_void_GLenum_GLenum *)packed; + ARGS_void_GLenum_GLenum args = unpacked->args; + unpacked->func(args.a1, args.a2); + break; + } + case FORMAT_void_GLenum_GLenum_GLenum_GLenum: { + PACKED_void_GLenum_GLenum_GLenum_GLenum *unpacked = (PACKED_void_GLenum_GLenum_GLenum_GLenum *)packed; + ARGS_void_GLenum_GLenum_GLenum_GLenum args = unpacked->args; + unpacked->func(args.a1, args.a2, args.a3, args.a4); + break; + } + case FORMAT_void_GLenum_GLsizeiptr_const_GLvoid___GENPT___GLenum: { + PACKED_void_GLenum_GLsizeiptr_const_GLvoid___GENPT___GLenum *unpacked = (PACKED_void_GLenum_GLsizeiptr_const_GLvoid___GENPT___GLenum *)packed; + ARGS_void_GLenum_GLsizeiptr_const_GLvoid___GENPT___GLenum args = unpacked->args; + unpacked->func(args.a1, args.a2, args.a3, args.a4); + break; + } + case FORMAT_void_GLenum_GLintptr_GLsizeiptr_const_GLvoid___GENPT__: { + PACKED_void_GLenum_GLintptr_GLsizeiptr_const_GLvoid___GENPT__ *unpacked = (PACKED_void_GLenum_GLintptr_GLsizeiptr_const_GLvoid___GENPT__ *)packed; + ARGS_void_GLenum_GLintptr_GLsizeiptr_const_GLvoid___GENPT__ args = unpacked->args; + unpacked->func(args.a1, args.a2, args.a3, args.a4); + break; + } + case FORMAT_GLenum_GLenum: { + PACKED_GLenum_GLenum *unpacked = (PACKED_GLenum_GLenum *)packed; + ARGS_GLenum_GLenum args = unpacked->args; + unpacked->func(args.a1); + break; + } + case FORMAT_void_GLbitfield: { + PACKED_void_GLbitfield *unpacked = (PACKED_void_GLbitfield *)packed; + ARGS_void_GLbitfield args = unpacked->args; + unpacked->func(args.a1); + break; + } + case FORMAT_void_GLclampx_GLclampx_GLclampx_GLclampx: { + PACKED_void_GLclampx_GLclampx_GLclampx_GLclampx *unpacked = (PACKED_void_GLclampx_GLclampx_GLclampx_GLclampx *)packed; + ARGS_void_GLclampx_GLclampx_GLclampx_GLclampx args = unpacked->args; + unpacked->func(args.a1, args.a2, args.a3, args.a4); + break; + } + case FORMAT_void_GLclampf: { + PACKED_void_GLclampf *unpacked = (PACKED_void_GLclampf *)packed; + ARGS_void_GLclampf args = unpacked->args; + unpacked->func(args.a1); + break; + } + case FORMAT_void_GLclampx: { + PACKED_void_GLclampx *unpacked = (PACKED_void_GLclampx *)packed; + ARGS_void_GLclampx args = unpacked->args; + unpacked->func(args.a1); + break; + } + case FORMAT_void_GLint: { + PACKED_void_GLint *unpacked = (PACKED_void_GLint *)packed; + ARGS_void_GLint args = unpacked->args; + unpacked->func(args.a1); + break; + } + case FORMAT_void_GLenum_const_GLfloat___GENPT__: { + PACKED_void_GLenum_const_GLfloat___GENPT__ *unpacked = (PACKED_void_GLenum_const_GLfloat___GENPT__ *)packed; + ARGS_void_GLenum_const_GLfloat___GENPT__ args = unpacked->args; + unpacked->func(args.a1, args.a2); + break; + } + case FORMAT_void_GLenum_const_GLfixed___GENPT__: { + PACKED_void_GLenum_const_GLfixed___GENPT__ *unpacked = (PACKED_void_GLenum_const_GLfixed___GENPT__ *)packed; + ARGS_void_GLenum_const_GLfixed___GENPT__ args = unpacked->args; + unpacked->func(args.a1, args.a2); + break; + } + case FORMAT_void_GLfloat_GLfloat_GLfloat_GLfloat: { + PACKED_void_GLfloat_GLfloat_GLfloat_GLfloat *unpacked = (PACKED_void_GLfloat_GLfloat_GLfloat_GLfloat *)packed; + ARGS_void_GLfloat_GLfloat_GLfloat_GLfloat args = unpacked->args; + unpacked->func(args.a1, args.a2, args.a3, args.a4); + break; + } + case FORMAT_void_GLubyte_GLubyte_GLubyte_GLubyte: { + PACKED_void_GLubyte_GLubyte_GLubyte_GLubyte *unpacked = (PACKED_void_GLubyte_GLubyte_GLubyte_GLubyte *)packed; + ARGS_void_GLubyte_GLubyte_GLubyte_GLubyte args = unpacked->args; + unpacked->func(args.a1, args.a2, args.a3, args.a4); + break; + } + case FORMAT_void_GLfixed_GLfixed_GLfixed_GLfixed: { + PACKED_void_GLfixed_GLfixed_GLfixed_GLfixed *unpacked = (PACKED_void_GLfixed_GLfixed_GLfixed_GLfixed *)packed; + ARGS_void_GLfixed_GLfixed_GLfixed_GLfixed args = unpacked->args; + unpacked->func(args.a1, args.a2, args.a3, args.a4); + break; + } + case FORMAT_void_GLboolean_GLboolean_GLboolean_GLboolean: { + PACKED_void_GLboolean_GLboolean_GLboolean_GLboolean *unpacked = (PACKED_void_GLboolean_GLboolean_GLboolean_GLboolean *)packed; + ARGS_void_GLboolean_GLboolean_GLboolean_GLboolean args = unpacked->args; + unpacked->func(args.a1, args.a2, args.a3, args.a4); + break; + } + case FORMAT_void_GLint_GLenum_GLsizei_const_GLvoid___GENPT__: { + PACKED_void_GLint_GLenum_GLsizei_const_GLvoid___GENPT__ *unpacked = (PACKED_void_GLint_GLenum_GLsizei_const_GLvoid___GENPT__ *)packed; + ARGS_void_GLint_GLenum_GLsizei_const_GLvoid___GENPT__ args = unpacked->args; + unpacked->func(args.a1, args.a2, args.a3, args.a4); + break; + } + case FORMAT_void_GLuint: { + PACKED_void_GLuint *unpacked = (PACKED_void_GLuint *)packed; + ARGS_void_GLuint args = unpacked->args; + unpacked->func(args.a1); + break; + } + case FORMAT_void_GLenum_GLint_GLenum_GLsizei_GLsizei_GLint_GLsizei_const_GLvoid___GENPT__: { + PACKED_void_GLenum_GLint_GLenum_GLsizei_GLsizei_GLint_GLsizei_const_GLvoid___GENPT__ *unpacked = (PACKED_void_GLenum_GLint_GLenum_GLsizei_GLsizei_GLint_GLsizei_const_GLvoid___GENPT__ *)packed; + ARGS_void_GLenum_GLint_GLenum_GLsizei_GLsizei_GLint_GLsizei_const_GLvoid___GENPT__ args = unpacked->args; + unpacked->func(args.a1, args.a2, args.a3, args.a4, args.a5, args.a6, args.a7, args.a8); + break; + } + case FORMAT_void_GLenum_GLint_GLint_GLint_GLsizei_GLsizei_GLenum_GLsizei_const_GLvoid___GENPT__: { + PACKED_void_GLenum_GLint_GLint_GLint_GLsizei_GLsizei_GLenum_GLsizei_const_GLvoid___GENPT__ *unpacked = (PACKED_void_GLenum_GLint_GLint_GLint_GLsizei_GLsizei_GLenum_GLsizei_const_GLvoid___GENPT__ *)packed; + ARGS_void_GLenum_GLint_GLint_GLint_GLsizei_GLsizei_GLenum_GLsizei_const_GLvoid___GENPT__ args = unpacked->args; + unpacked->func(args.a1, args.a2, args.a3, args.a4, args.a5, args.a6, args.a7, args.a8, args.a9); + break; + } + case FORMAT_void_GLenum_GLint_GLenum_GLint_GLint_GLsizei_GLsizei_GLint: { + PACKED_void_GLenum_GLint_GLenum_GLint_GLint_GLsizei_GLsizei_GLint *unpacked = (PACKED_void_GLenum_GLint_GLenum_GLint_GLint_GLsizei_GLsizei_GLint *)packed; + ARGS_void_GLenum_GLint_GLenum_GLint_GLint_GLsizei_GLsizei_GLint args = unpacked->args; + unpacked->func(args.a1, args.a2, args.a3, args.a4, args.a5, args.a6, args.a7, args.a8); + break; + } + case FORMAT_void_GLenum_GLint_GLint_GLint_GLint_GLint_GLsizei_GLsizei: { + PACKED_void_GLenum_GLint_GLint_GLint_GLint_GLint_GLsizei_GLsizei *unpacked = (PACKED_void_GLenum_GLint_GLint_GLint_GLint_GLint_GLsizei_GLsizei *)packed; + ARGS_void_GLenum_GLint_GLint_GLint_GLint_GLint_GLsizei_GLsizei args = unpacked->args; + unpacked->func(args.a1, args.a2, args.a3, args.a4, args.a5, args.a6, args.a7, args.a8); + break; + } + case FORMAT_GLuint: { + PACKED_GLuint *unpacked = (PACKED_GLuint *)packed; + unpacked->func(); + break; + } + case FORMAT_GLuint_GLenum: { + PACKED_GLuint_GLenum *unpacked = (PACKED_GLuint_GLenum *)packed; + ARGS_GLuint_GLenum args = unpacked->args; + unpacked->func(args.a1); + break; + } + case FORMAT_void_GLsizei_const_GLuint___GENPT__: { + PACKED_void_GLsizei_const_GLuint___GENPT__ *unpacked = (PACKED_void_GLsizei_const_GLuint___GENPT__ *)packed; + ARGS_void_GLsizei_const_GLuint___GENPT__ args = unpacked->args; + unpacked->func(args.a1, args.a2); + break; + } + case FORMAT_void_GLsizei_GLuint___GENPT__: { + PACKED_void_GLsizei_GLuint___GENPT__ *unpacked = (PACKED_void_GLsizei_GLuint___GENPT__ *)packed; + ARGS_void_GLsizei_GLuint___GENPT__ args = unpacked->args; + unpacked->func(args.a1, args.a2); + break; + } + case FORMAT_void_GLboolean: { + PACKED_void_GLboolean *unpacked = (PACKED_void_GLboolean *)packed; + ARGS_void_GLboolean args = unpacked->args; + unpacked->func(args.a1); + break; + } + case FORMAT_void_GLclampf_GLclampf: { + PACKED_void_GLclampf_GLclampf *unpacked = (PACKED_void_GLclampf_GLclampf *)packed; + ARGS_void_GLclampf_GLclampf args = unpacked->args; + unpacked->func(args.a1, args.a2); + break; + } + case FORMAT_void_GLclampx_GLclampx: { + PACKED_void_GLclampx_GLclampx *unpacked = (PACKED_void_GLclampx_GLclampx *)packed; + ARGS_void_GLclampx_GLclampx args = unpacked->args; + unpacked->func(args.a1, args.a2); + break; + } + case FORMAT_void_GLenum_GLint_GLsizei: { + PACKED_void_GLenum_GLint_GLsizei *unpacked = (PACKED_void_GLenum_GLint_GLsizei *)packed; + ARGS_void_GLenum_GLint_GLsizei args = unpacked->args; + unpacked->func(args.a1, args.a2, args.a3); + break; + } + case FORMAT_void_GLenum_GLsizei_GLenum_const_GLvoid___GENPT__: { + PACKED_void_GLenum_GLsizei_GLenum_const_GLvoid___GENPT__ *unpacked = (PACKED_void_GLenum_GLsizei_GLenum_const_GLvoid___GENPT__ *)packed; + ARGS_void_GLenum_GLsizei_GLenum_const_GLvoid___GENPT__ args = unpacked->args; + unpacked->func(args.a1, args.a2, args.a3, args.a4); + break; + } + case FORMAT_void_GLfloat_GLfloat_GLfloat_GLfloat_GLfloat: { + PACKED_void_GLfloat_GLfloat_GLfloat_GLfloat_GLfloat *unpacked = (PACKED_void_GLfloat_GLfloat_GLfloat_GLfloat_GLfloat *)packed; + ARGS_void_GLfloat_GLfloat_GLfloat_GLfloat_GLfloat args = unpacked->args; + unpacked->func(args.a1, args.a2, args.a3, args.a4, args.a5); + break; + } + case FORMAT_void_GLint_GLint_GLint_GLint_GLint: { + PACKED_void_GLint_GLint_GLint_GLint_GLint *unpacked = (PACKED_void_GLint_GLint_GLint_GLint_GLint *)packed; + ARGS_void_GLint_GLint_GLint_GLint_GLint args = unpacked->args; + unpacked->func(args.a1, args.a2, args.a3, args.a4, args.a5); + break; + } + case FORMAT_void: { + PACKED_void *unpacked = (PACKED_void *)packed; + unpacked->func(); + break; + } + case FORMAT_void_GLenum_GLsizei_const_GLvoid___GENPT__: { + PACKED_void_GLenum_GLsizei_const_GLvoid___GENPT__ *unpacked = (PACKED_void_GLenum_GLsizei_const_GLvoid___GENPT__ *)packed; + ARGS_void_GLenum_GLsizei_const_GLvoid___GENPT__ args = unpacked->args; + unpacked->func(args.a1, args.a2, args.a3); + break; + } + case FORMAT_void_GLfloat: { + PACKED_void_GLfloat *unpacked = (PACKED_void_GLfloat *)packed; + ARGS_void_GLfloat args = unpacked->args; + unpacked->func(args.a1); + break; + } + case FORMAT_void_const_GLfloat___GENPT__: { + PACKED_void_const_GLfloat___GENPT__ *unpacked = (PACKED_void_const_GLfloat___GENPT__ *)packed; + ARGS_void_const_GLfloat___GENPT__ args = unpacked->args; + unpacked->func(args.a1); + break; + } + case FORMAT_void_GLenum_GLfloat: { + PACKED_void_GLenum_GLfloat *unpacked = (PACKED_void_GLenum_GLfloat *)packed; + ARGS_void_GLenum_GLfloat args = unpacked->args; + unpacked->func(args.a1, args.a2); + break; + } + case FORMAT_void_GLenum_GLfixed: { + PACKED_void_GLenum_GLfixed *unpacked = (PACKED_void_GLenum_GLfixed *)packed; + ARGS_void_GLenum_GLfixed args = unpacked->args; + unpacked->func(args.a1, args.a2); + break; + } + case FORMAT_void_GLenum_GLenum_GLenum_GLuint: { + PACKED_void_GLenum_GLenum_GLenum_GLuint *unpacked = (PACKED_void_GLenum_GLenum_GLenum_GLuint *)packed; + ARGS_void_GLenum_GLenum_GLenum_GLuint args = unpacked->args; + unpacked->func(args.a1, args.a2, args.a3, args.a4); + break; + } + case FORMAT_void_GLenum_GLenum_GLenum_GLuint_GLint: { + PACKED_void_GLenum_GLenum_GLenum_GLuint_GLint *unpacked = (PACKED_void_GLenum_GLenum_GLenum_GLuint_GLint *)packed; + ARGS_void_GLenum_GLenum_GLenum_GLuint_GLint args = unpacked->args; + unpacked->func(args.a1, args.a2, args.a3, args.a4, args.a5); + break; + } + case FORMAT_void_GLfloat_GLfloat_GLfloat_GLfloat_GLfloat_GLfloat: { + PACKED_void_GLfloat_GLfloat_GLfloat_GLfloat_GLfloat_GLfloat *unpacked = (PACKED_void_GLfloat_GLfloat_GLfloat_GLfloat_GLfloat_GLfloat *)packed; + ARGS_void_GLfloat_GLfloat_GLfloat_GLfloat_GLfloat_GLfloat args = unpacked->args; + unpacked->func(args.a1, args.a2, args.a3, args.a4, args.a5, args.a6); + break; + } + case FORMAT_void_GLfixed_GLfixed_GLfixed_GLfixed_GLfixed_GLfixed: { + PACKED_void_GLfixed_GLfixed_GLfixed_GLfixed_GLfixed_GLfixed *unpacked = (PACKED_void_GLfixed_GLfixed_GLfixed_GLfixed_GLfixed_GLfixed *)packed; + ARGS_void_GLfixed_GLfixed_GLfixed_GLfixed_GLfixed_GLfixed args = unpacked->args; + unpacked->func(args.a1, args.a2, args.a3, args.a4, args.a5, args.a6); + break; + } + case FORMAT_void_GLuint_GLuint_GLsizei_GLsizei___GENPT___GLint___GENPT___GLenum___GENPT___GLchar___GENPT__: { + PACKED_void_GLuint_GLuint_GLsizei_GLsizei___GENPT___GLint___GENPT___GLenum___GENPT___GLchar___GENPT__ *unpacked = (PACKED_void_GLuint_GLuint_GLsizei_GLsizei___GENPT___GLint___GENPT___GLenum___GENPT___GLchar___GENPT__ *)packed; + ARGS_void_GLuint_GLuint_GLsizei_GLsizei___GENPT___GLint___GENPT___GLenum___GENPT___GLchar___GENPT__ args = unpacked->args; + unpacked->func(args.a1, args.a2, args.a3, args.a4, args.a5, args.a6, args.a7); + break; + } + case FORMAT_void_GLuint_GLsizei_GLsizei___GENPT___GLuint___GENPT__: { + PACKED_void_GLuint_GLsizei_GLsizei___GENPT___GLuint___GENPT__ *unpacked = (PACKED_void_GLuint_GLsizei_GLsizei___GENPT___GLuint___GENPT__ *)packed; + ARGS_void_GLuint_GLsizei_GLsizei___GENPT___GLuint___GENPT__ args = unpacked->args; + unpacked->func(args.a1, args.a2, args.a3, args.a4); + break; + } + case FORMAT_GLint_GLuint_const_GLchar___GENPT__: { + PACKED_GLint_GLuint_const_GLchar___GENPT__ *unpacked = (PACKED_GLint_GLuint_const_GLchar___GENPT__ *)packed; + ARGS_GLint_GLuint_const_GLchar___GENPT__ args = unpacked->args; + unpacked->func(args.a1, args.a2); + break; + } + case FORMAT_void_GLenum_GLboolean___GENPT__: { + PACKED_void_GLenum_GLboolean___GENPT__ *unpacked = (PACKED_void_GLenum_GLboolean___GENPT__ *)packed; + ARGS_void_GLenum_GLboolean___GENPT__ args = unpacked->args; + unpacked->func(args.a1, args.a2); + break; + } + case FORMAT_void_GLenum_GLenum_GLint___GENPT__: { + PACKED_void_GLenum_GLenum_GLint___GENPT__ *unpacked = (PACKED_void_GLenum_GLenum_GLint___GENPT__ *)packed; + ARGS_void_GLenum_GLenum_GLint___GENPT__ args = unpacked->args; + unpacked->func(args.a1, args.a2, args.a3); + break; + } + case FORMAT_void_GLenum_GLfloat___GENPT__: { + PACKED_void_GLenum_GLfloat___GENPT__ *unpacked = (PACKED_void_GLenum_GLfloat___GENPT__ *)packed; + ARGS_void_GLenum_GLfloat___GENPT__ args = unpacked->args; + unpacked->func(args.a1, args.a2); + break; + } + case FORMAT_void_GLenum_GLfixed___GENPT__: { + PACKED_void_GLenum_GLfixed___GENPT__ *unpacked = (PACKED_void_GLenum_GLfixed___GENPT__ *)packed; + ARGS_void_GLenum_GLfixed___GENPT__ args = unpacked->args; + unpacked->func(args.a1, args.a2); + break; + } + case FORMAT_GLenum: { + PACKED_GLenum *unpacked = (PACKED_GLenum *)packed; + unpacked->func(); + break; + } + case FORMAT_void_GLenum_GLenum_GLenum_GLint___GENPT__: { + PACKED_void_GLenum_GLenum_GLenum_GLint___GENPT__ *unpacked = (PACKED_void_GLenum_GLenum_GLenum_GLint___GENPT__ *)packed; + ARGS_void_GLenum_GLenum_GLenum_GLint___GENPT__ args = unpacked->args; + unpacked->func(args.a1, args.a2, args.a3, args.a4); + break; + } + case FORMAT_void_GLenum_GLint___GENPT__: { + PACKED_void_GLenum_GLint___GENPT__ *unpacked = (PACKED_void_GLenum_GLint___GENPT__ *)packed; + ARGS_void_GLenum_GLint___GENPT__ args = unpacked->args; + unpacked->func(args.a1, args.a2); + break; + } + case FORMAT_void_GLenum_GLenum_GLfloat___GENPT__: { + PACKED_void_GLenum_GLenum_GLfloat___GENPT__ *unpacked = (PACKED_void_GLenum_GLenum_GLfloat___GENPT__ *)packed; + ARGS_void_GLenum_GLenum_GLfloat___GENPT__ args = unpacked->args; + unpacked->func(args.a1, args.a2, args.a3); + break; + } + case FORMAT_void_GLenum_GLenum_GLfixed___GENPT__: { + PACKED_void_GLenum_GLenum_GLfixed___GENPT__ *unpacked = (PACKED_void_GLenum_GLenum_GLfixed___GENPT__ *)packed; + ARGS_void_GLenum_GLenum_GLfixed___GENPT__ args = unpacked->args; + unpacked->func(args.a1, args.a2, args.a3); + break; + } + case FORMAT_void_GLenum_GLvoid___GENPT____GENPT__: { + PACKED_void_GLenum_GLvoid___GENPT____GENPT__ *unpacked = (PACKED_void_GLenum_GLvoid___GENPT____GENPT__ *)packed; + ARGS_void_GLenum_GLvoid___GENPT____GENPT__ args = unpacked->args; + unpacked->func(args.a1, args.a2); + break; + } + case FORMAT_void_GLuint_GLsizei_GLsizei___GENPT___GLchar___GENPT__: { + PACKED_void_GLuint_GLsizei_GLsizei___GENPT___GLchar___GENPT__ *unpacked = (PACKED_void_GLuint_GLsizei_GLsizei___GENPT___GLchar___GENPT__ *)packed; + ARGS_void_GLuint_GLsizei_GLsizei___GENPT___GLchar___GENPT__ args = unpacked->args; + unpacked->func(args.a1, args.a2, args.a3, args.a4); + break; + } + case FORMAT_void_GLuint_GLenum_GLint___GENPT__: { + PACKED_void_GLuint_GLenum_GLint___GENPT__ *unpacked = (PACKED_void_GLuint_GLenum_GLint___GENPT__ *)packed; + ARGS_void_GLuint_GLenum_GLint___GENPT__ args = unpacked->args; + unpacked->func(args.a1, args.a2, args.a3); + break; + } + case FORMAT_void_GLenum_GLenum_GLint___GENPT___GLint___GENPT__: { + PACKED_void_GLenum_GLenum_GLint___GENPT___GLint___GENPT__ *unpacked = (PACKED_void_GLenum_GLenum_GLint___GENPT___GLint___GENPT__ *)packed; + ARGS_void_GLenum_GLenum_GLint___GENPT___GLint___GENPT__ args = unpacked->args; + unpacked->func(args.a1, args.a2, args.a3, args.a4); + break; + } + case FORMAT_const_GLubyte___GENPT___GLenum: { + PACKED_const_GLubyte___GENPT___GLenum *unpacked = (PACKED_const_GLubyte___GENPT___GLenum *)packed; + ARGS_const_GLubyte___GENPT___GLenum args = unpacked->args; + unpacked->func(args.a1); + break; + } + case FORMAT_void_GLuint_GLint_GLfloat___GENPT__: { + PACKED_void_GLuint_GLint_GLfloat___GENPT__ *unpacked = (PACKED_void_GLuint_GLint_GLfloat___GENPT__ *)packed; + ARGS_void_GLuint_GLint_GLfloat___GENPT__ args = unpacked->args; + unpacked->func(args.a1, args.a2, args.a3); + break; + } + case FORMAT_void_GLuint_GLint_GLint___GENPT__: { + PACKED_void_GLuint_GLint_GLint___GENPT__ *unpacked = (PACKED_void_GLuint_GLint_GLint___GENPT__ *)packed; + ARGS_void_GLuint_GLint_GLint___GENPT__ args = unpacked->args; + unpacked->func(args.a1, args.a2, args.a3); + break; + } + case FORMAT_void_GLuint_GLenum_GLvoid___GENPT____GENPT__: { + PACKED_void_GLuint_GLenum_GLvoid___GENPT____GENPT__ *unpacked = (PACKED_void_GLuint_GLenum_GLvoid___GENPT____GENPT__ *)packed; + ARGS_void_GLuint_GLenum_GLvoid___GENPT____GENPT__ args = unpacked->args; + unpacked->func(args.a1, args.a2, args.a3); + break; + } + case FORMAT_void_GLuint_GLenum_GLfloat___GENPT__: { + PACKED_void_GLuint_GLenum_GLfloat___GENPT__ *unpacked = (PACKED_void_GLuint_GLenum_GLfloat___GENPT__ *)packed; + ARGS_void_GLuint_GLenum_GLfloat___GENPT__ args = unpacked->args; + unpacked->func(args.a1, args.a2, args.a3); + break; + } + case FORMAT_GLboolean_GLuint: { + PACKED_GLboolean_GLuint *unpacked = (PACKED_GLboolean_GLuint *)packed; + ARGS_GLboolean_GLuint args = unpacked->args; + unpacked->func(args.a1); + break; + } + case FORMAT_GLboolean_GLenum: { + PACKED_GLboolean_GLenum *unpacked = (PACKED_GLboolean_GLenum *)packed; + ARGS_GLboolean_GLenum args = unpacked->args; + unpacked->func(args.a1); + break; + } + case FORMAT_void_GLenum_GLenum_GLfloat: { + PACKED_void_GLenum_GLenum_GLfloat *unpacked = (PACKED_void_GLenum_GLenum_GLfloat *)packed; + ARGS_void_GLenum_GLenum_GLfloat args = unpacked->args; + unpacked->func(args.a1, args.a2, args.a3); + break; + } + case FORMAT_void_GLenum_GLenum_const_GLfloat___GENPT__: { + PACKED_void_GLenum_GLenum_const_GLfloat___GENPT__ *unpacked = (PACKED_void_GLenum_GLenum_const_GLfloat___GENPT__ *)packed; + ARGS_void_GLenum_GLenum_const_GLfloat___GENPT__ args = unpacked->args; + unpacked->func(args.a1, args.a2, args.a3); + break; + } + case FORMAT_void_GLenum_GLenum_GLfixed: { + PACKED_void_GLenum_GLenum_GLfixed *unpacked = (PACKED_void_GLenum_GLenum_GLfixed *)packed; + ARGS_void_GLenum_GLenum_GLfixed args = unpacked->args; + unpacked->func(args.a1, args.a2, args.a3); + break; + } + case FORMAT_void_GLenum_GLenum_const_GLfixed___GENPT__: { + PACKED_void_GLenum_GLenum_const_GLfixed___GENPT__ *unpacked = (PACKED_void_GLenum_GLenum_const_GLfixed___GENPT__ *)packed; + ARGS_void_GLenum_GLenum_const_GLfixed___GENPT__ args = unpacked->args; + unpacked->func(args.a1, args.a2, args.a3); + break; + } + case FORMAT_void_GLfixed: { + PACKED_void_GLfixed *unpacked = (PACKED_void_GLfixed *)packed; + ARGS_void_GLfixed args = unpacked->args; + unpacked->func(args.a1); + break; + } + case FORMAT_void_const_GLfixed___GENPT__: { + PACKED_void_const_GLfixed___GENPT__ *unpacked = (PACKED_void_const_GLfixed___GENPT__ *)packed; + ARGS_void_const_GLfixed___GENPT__ args = unpacked->args; + unpacked->func(args.a1); + break; + } + case FORMAT_void_GLenum_const_GLint___GENPT___const_GLsizei___GENPT___GLsizei: { + PACKED_void_GLenum_const_GLint___GENPT___const_GLsizei___GENPT___GLsizei *unpacked = (PACKED_void_GLenum_const_GLint___GENPT___const_GLsizei___GENPT___GLsizei *)packed; + ARGS_void_GLenum_const_GLint___GENPT___const_GLsizei___GENPT___GLsizei args = unpacked->args; + unpacked->func(args.a1, args.a2, args.a3, args.a4); + break; + } + case FORMAT_void_GLenum_GLsizei___GENPT___GLenum_const_void___GENPT___const___GENPT___GLsizei: { + PACKED_void_GLenum_GLsizei___GENPT___GLenum_const_void___GENPT___const___GENPT___GLsizei *unpacked = (PACKED_void_GLenum_GLsizei___GENPT___GLenum_const_void___GENPT___const___GENPT___GLsizei *)packed; + ARGS_void_GLenum_GLsizei___GENPT___GLenum_const_void___GENPT___const___GENPT___GLsizei args = unpacked->args; + unpacked->func(args.a1, args.a2, args.a3, args.a4, args.a5); + break; + } + case FORMAT_void_GLenum_GLfloat_GLfloat_GLfloat_GLfloat: { + PACKED_void_GLenum_GLfloat_GLfloat_GLfloat_GLfloat *unpacked = (PACKED_void_GLenum_GLfloat_GLfloat_GLfloat_GLfloat *)packed; + ARGS_void_GLenum_GLfloat_GLfloat_GLfloat_GLfloat args = unpacked->args; + unpacked->func(args.a1, args.a2, args.a3, args.a4, args.a5); + break; + } + case FORMAT_void_GLenum_GLfixed_GLfixed_GLfixed_GLfixed: { + PACKED_void_GLenum_GLfixed_GLfixed_GLfixed_GLfixed *unpacked = (PACKED_void_GLenum_GLfixed_GLfixed_GLfixed_GLfixed *)packed; + ARGS_void_GLenum_GLfixed_GLfixed_GLfixed_GLfixed args = unpacked->args; + unpacked->func(args.a1, args.a2, args.a3, args.a4, args.a5); + break; + } + case FORMAT_void_GLfloat_GLfloat_GLfloat: { + PACKED_void_GLfloat_GLfloat_GLfloat *unpacked = (PACKED_void_GLfloat_GLfloat_GLfloat *)packed; + ARGS_void_GLfloat_GLfloat_GLfloat args = unpacked->args; + unpacked->func(args.a1, args.a2, args.a3); + break; + } + case FORMAT_void_GLfixed_GLfixed_GLfixed: { + PACKED_void_GLfixed_GLfixed_GLfixed *unpacked = (PACKED_void_GLfixed_GLfixed_GLfixed *)packed; + ARGS_void_GLfixed_GLfixed_GLfixed args = unpacked->args; + unpacked->func(args.a1, args.a2, args.a3); + break; + } + case FORMAT_void_GLenum_GLint: { + PACKED_void_GLenum_GLint *unpacked = (PACKED_void_GLenum_GLint *)packed; + ARGS_void_GLenum_GLint args = unpacked->args; + unpacked->func(args.a1, args.a2); + break; + } + case FORMAT_void_GLfloat_GLfloat: { + PACKED_void_GLfloat_GLfloat *unpacked = (PACKED_void_GLfloat_GLfloat *)packed; + ARGS_void_GLfloat_GLfloat args = unpacked->args; + unpacked->func(args.a1, args.a2); + break; + } + case FORMAT_void_GLfixed_GLfixed: { + PACKED_void_GLfixed_GLfixed *unpacked = (PACKED_void_GLfixed_GLfixed *)packed; + ARGS_void_GLfixed_GLfixed args = unpacked->args; + unpacked->func(args.a1, args.a2); + break; + } + case FORMAT_void_GLint_GLint_GLsizei_GLsizei_GLenum_GLenum_GLvoid___GENPT__: { + PACKED_void_GLint_GLint_GLsizei_GLsizei_GLenum_GLenum_GLvoid___GENPT__ *unpacked = (PACKED_void_GLint_GLint_GLsizei_GLsizei_GLenum_GLenum_GLvoid___GENPT__ *)packed; + ARGS_void_GLint_GLint_GLsizei_GLsizei_GLenum_GLenum_GLvoid___GENPT__ args = unpacked->args; + unpacked->func(args.a1, args.a2, args.a3, args.a4, args.a5, args.a6, args.a7); + break; + } + case FORMAT_void_GLenum_GLenum_GLsizei_GLsizei: { + PACKED_void_GLenum_GLenum_GLsizei_GLsizei *unpacked = (PACKED_void_GLenum_GLenum_GLsizei_GLsizei *)packed; + ARGS_void_GLenum_GLenum_GLsizei_GLsizei args = unpacked->args; + unpacked->func(args.a1, args.a2, args.a3, args.a4); + break; + } + case FORMAT_void_GLclampf_GLboolean: { + PACKED_void_GLclampf_GLboolean *unpacked = (PACKED_void_GLclampf_GLboolean *)packed; + ARGS_void_GLclampf_GLboolean args = unpacked->args; + unpacked->func(args.a1, args.a2); + break; + } + case FORMAT_void_GLclampx_GLboolean: { + PACKED_void_GLclampx_GLboolean *unpacked = (PACKED_void_GLclampx_GLboolean *)packed; + ARGS_void_GLclampx_GLboolean args = unpacked->args; + unpacked->func(args.a1, args.a2); + break; + } + case FORMAT_void_GLint_GLint_GLsizei_GLsizei: { + PACKED_void_GLint_GLint_GLsizei_GLsizei *unpacked = (PACKED_void_GLint_GLint_GLsizei_GLsizei *)packed; + ARGS_void_GLint_GLint_GLsizei_GLsizei args = unpacked->args; + unpacked->func(args.a1, args.a2, args.a3, args.a4); + break; + } + case FORMAT_void_GLsizei_const_GLuint___GENPT___GLenum_const_GLvoid___GENPT___GLsizei: { + PACKED_void_GLsizei_const_GLuint___GENPT___GLenum_const_GLvoid___GENPT___GLsizei *unpacked = (PACKED_void_GLsizei_const_GLuint___GENPT___GLenum_const_GLvoid___GENPT___GLsizei *)packed; + ARGS_void_GLsizei_const_GLuint___GENPT___GLenum_const_GLvoid___GENPT___GLsizei args = unpacked->args; + unpacked->func(args.a1, args.a2, args.a3, args.a4, args.a5); + break; + } + case FORMAT_void_GLuint_GLsizei_const_GLchar___GENPT___const___GENPT___const_GLint___GENPT__: { + PACKED_void_GLuint_GLsizei_const_GLchar___GENPT___const___GENPT___const_GLint___GENPT__ *unpacked = (PACKED_void_GLuint_GLsizei_const_GLchar___GENPT___const___GENPT___const_GLint___GENPT__ *)packed; + ARGS_void_GLuint_GLsizei_const_GLchar___GENPT___const___GENPT___const_GLint___GENPT__ args = unpacked->args; + unpacked->func(args.a1, args.a2, args.a3, args.a4); + break; + } + case FORMAT_void_GLenum_GLint_GLuint: { + PACKED_void_GLenum_GLint_GLuint *unpacked = (PACKED_void_GLenum_GLint_GLuint *)packed; + ARGS_void_GLenum_GLint_GLuint args = unpacked->args; + unpacked->func(args.a1, args.a2, args.a3); + break; + } + case FORMAT_void_GLenum_GLenum_GLint_GLuint: { + PACKED_void_GLenum_GLenum_GLint_GLuint *unpacked = (PACKED_void_GLenum_GLenum_GLint_GLuint *)packed; + ARGS_void_GLenum_GLenum_GLint_GLuint args = unpacked->args; + unpacked->func(args.a1, args.a2, args.a3, args.a4); + break; + } + case FORMAT_void_GLenum_GLenum_GLenum: { + PACKED_void_GLenum_GLenum_GLenum *unpacked = (PACKED_void_GLenum_GLenum_GLenum *)packed; + ARGS_void_GLenum_GLenum_GLenum args = unpacked->args; + unpacked->func(args.a1, args.a2, args.a3); + break; + } + case FORMAT_void_GLenum_GLenum_GLint: { + PACKED_void_GLenum_GLenum_GLint *unpacked = (PACKED_void_GLenum_GLenum_GLint *)packed; + ARGS_void_GLenum_GLenum_GLint args = unpacked->args; + unpacked->func(args.a1, args.a2, args.a3); + break; + } + case FORMAT_void_GLenum_GLenum_const_GLint___GENPT__: { + PACKED_void_GLenum_GLenum_const_GLint___GENPT__ *unpacked = (PACKED_void_GLenum_GLenum_const_GLint___GENPT__ *)packed; + ARGS_void_GLenum_GLenum_const_GLint___GENPT__ args = unpacked->args; + unpacked->func(args.a1, args.a2, args.a3); + break; + } + case FORMAT_void_GLenum_GLint_GLint_GLsizei_GLsizei_GLint_GLenum_GLenum_const_GLvoid___GENPT__: { + PACKED_void_GLenum_GLint_GLint_GLsizei_GLsizei_GLint_GLenum_GLenum_const_GLvoid___GENPT__ *unpacked = (PACKED_void_GLenum_GLint_GLint_GLsizei_GLsizei_GLint_GLenum_GLenum_const_GLvoid___GENPT__ *)packed; + ARGS_void_GLenum_GLint_GLint_GLsizei_GLsizei_GLint_GLenum_GLenum_const_GLvoid___GENPT__ args = unpacked->args; + unpacked->func(args.a1, args.a2, args.a3, args.a4, args.a5, args.a6, args.a7, args.a8, args.a9); + break; + } + case FORMAT_void_GLenum_GLint_GLint_GLint_GLsizei_GLsizei_GLenum_GLenum_const_GLvoid___GENPT__: { + PACKED_void_GLenum_GLint_GLint_GLint_GLsizei_GLsizei_GLenum_GLenum_const_GLvoid___GENPT__ *unpacked = (PACKED_void_GLenum_GLint_GLint_GLint_GLsizei_GLsizei_GLenum_GLenum_const_GLvoid___GENPT__ *)packed; + ARGS_void_GLenum_GLint_GLint_GLint_GLsizei_GLsizei_GLenum_GLenum_const_GLvoid___GENPT__ args = unpacked->args; + unpacked->func(args.a1, args.a2, args.a3, args.a4, args.a5, args.a6, args.a7, args.a8, args.a9); + break; + } + case FORMAT_void_GLint_GLfloat: { + PACKED_void_GLint_GLfloat *unpacked = (PACKED_void_GLint_GLfloat *)packed; + ARGS_void_GLint_GLfloat args = unpacked->args; + unpacked->func(args.a1, args.a2); + break; + } + case FORMAT_void_GLint_GLsizei_const_GLfloat___GENPT__: { + PACKED_void_GLint_GLsizei_const_GLfloat___GENPT__ *unpacked = (PACKED_void_GLint_GLsizei_const_GLfloat___GENPT__ *)packed; + ARGS_void_GLint_GLsizei_const_GLfloat___GENPT__ args = unpacked->args; + unpacked->func(args.a1, args.a2, args.a3); + break; + } + case FORMAT_void_GLint_GLint: { + PACKED_void_GLint_GLint *unpacked = (PACKED_void_GLint_GLint *)packed; + ARGS_void_GLint_GLint args = unpacked->args; + unpacked->func(args.a1, args.a2); + break; + } + case FORMAT_void_GLint_GLsizei_const_GLint___GENPT__: { + PACKED_void_GLint_GLsizei_const_GLint___GENPT__ *unpacked = (PACKED_void_GLint_GLsizei_const_GLint___GENPT__ *)packed; + ARGS_void_GLint_GLsizei_const_GLint___GENPT__ args = unpacked->args; + unpacked->func(args.a1, args.a2, args.a3); + break; + } + case FORMAT_void_GLint_GLfloat_GLfloat: { + PACKED_void_GLint_GLfloat_GLfloat *unpacked = (PACKED_void_GLint_GLfloat_GLfloat *)packed; + ARGS_void_GLint_GLfloat_GLfloat args = unpacked->args; + unpacked->func(args.a1, args.a2, args.a3); + break; + } + case FORMAT_void_GLint_GLint_GLint: { + PACKED_void_GLint_GLint_GLint *unpacked = (PACKED_void_GLint_GLint_GLint *)packed; + ARGS_void_GLint_GLint_GLint args = unpacked->args; + unpacked->func(args.a1, args.a2, args.a3); + break; + } + case FORMAT_void_GLint_GLfloat_GLfloat_GLfloat: { + PACKED_void_GLint_GLfloat_GLfloat_GLfloat *unpacked = (PACKED_void_GLint_GLfloat_GLfloat_GLfloat *)packed; + ARGS_void_GLint_GLfloat_GLfloat_GLfloat args = unpacked->args; + unpacked->func(args.a1, args.a2, args.a3, args.a4); + break; + } + case FORMAT_void_GLint_GLint_GLint_GLint: { + PACKED_void_GLint_GLint_GLint_GLint *unpacked = (PACKED_void_GLint_GLint_GLint_GLint *)packed; + ARGS_void_GLint_GLint_GLint_GLint args = unpacked->args; + unpacked->func(args.a1, args.a2, args.a3, args.a4); + break; + } + case FORMAT_void_GLint_GLfloat_GLfloat_GLfloat_GLfloat: { + PACKED_void_GLint_GLfloat_GLfloat_GLfloat_GLfloat *unpacked = (PACKED_void_GLint_GLfloat_GLfloat_GLfloat_GLfloat *)packed; + ARGS_void_GLint_GLfloat_GLfloat_GLfloat_GLfloat args = unpacked->args; + unpacked->func(args.a1, args.a2, args.a3, args.a4, args.a5); + break; + } + case FORMAT_void_GLint_GLsizei_GLboolean_const_GLfloat___GENPT__: { + PACKED_void_GLint_GLsizei_GLboolean_const_GLfloat___GENPT__ *unpacked = (PACKED_void_GLint_GLsizei_GLboolean_const_GLfloat___GENPT__ *)packed; + ARGS_void_GLint_GLsizei_GLboolean_const_GLfloat___GENPT__ args = unpacked->args; + unpacked->func(args.a1, args.a2, args.a3, args.a4); + break; + } + case FORMAT_void_GLuint_GLfloat: { + PACKED_void_GLuint_GLfloat *unpacked = (PACKED_void_GLuint_GLfloat *)packed; + ARGS_void_GLuint_GLfloat args = unpacked->args; + unpacked->func(args.a1, args.a2); + break; + } + case FORMAT_void_GLuint_const_GLfloat___GENPT__: { + PACKED_void_GLuint_const_GLfloat___GENPT__ *unpacked = (PACKED_void_GLuint_const_GLfloat___GENPT__ *)packed; + ARGS_void_GLuint_const_GLfloat___GENPT__ args = unpacked->args; + unpacked->func(args.a1, args.a2); + break; + } + case FORMAT_void_GLuint_GLfloat_GLfloat: { + PACKED_void_GLuint_GLfloat_GLfloat *unpacked = (PACKED_void_GLuint_GLfloat_GLfloat *)packed; + ARGS_void_GLuint_GLfloat_GLfloat args = unpacked->args; + unpacked->func(args.a1, args.a2, args.a3); + break; + } + case FORMAT_void_GLuint_GLfloat_GLfloat_GLfloat: { + PACKED_void_GLuint_GLfloat_GLfloat_GLfloat *unpacked = (PACKED_void_GLuint_GLfloat_GLfloat_GLfloat *)packed; + ARGS_void_GLuint_GLfloat_GLfloat_GLfloat args = unpacked->args; + unpacked->func(args.a1, args.a2, args.a3, args.a4); + break; + } + case FORMAT_void_GLuint_GLfloat_GLfloat_GLfloat_GLfloat: { + PACKED_void_GLuint_GLfloat_GLfloat_GLfloat_GLfloat *unpacked = (PACKED_void_GLuint_GLfloat_GLfloat_GLfloat_GLfloat *)packed; + ARGS_void_GLuint_GLfloat_GLfloat_GLfloat_GLfloat args = unpacked->args; + unpacked->func(args.a1, args.a2, args.a3, args.a4, args.a5); + break; + } + case FORMAT_void_GLuint_GLint_GLenum_GLboolean_GLsizei_const_GLvoid___GENPT__: { + PACKED_void_GLuint_GLint_GLenum_GLboolean_GLsizei_const_GLvoid___GENPT__ *unpacked = (PACKED_void_GLuint_GLint_GLenum_GLboolean_GLsizei_const_GLvoid___GENPT__ *)packed; + ARGS_void_GLuint_GLint_GLenum_GLboolean_GLsizei_const_GLvoid___GENPT__ args = unpacked->args; + unpacked->func(args.a1, args.a2, args.a3, args.a4, args.a5, args.a6); + break; + } + } +} +/* +packed_call_t* glCopyPackedCall(const packed_call_t *packed) { + switch (packed->format) { + case FORMAT_void_GLenum: { + int sizeofpacked = sizeof(PACKED_void_GLenum); + PACKED_void_GLenum *newpacked = (PACKED_void_GLenum*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLenum_GLclampf: { + int sizeofpacked = sizeof(PACKED_void_GLenum_GLclampf); + PACKED_void_GLenum_GLclampf *newpacked = (PACKED_void_GLenum_GLclampf*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLenum_GLclampx: { + int sizeofpacked = sizeof(PACKED_void_GLenum_GLclampx); + PACKED_void_GLenum_GLclampx *newpacked = (PACKED_void_GLenum_GLclampx*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLuint_GLuint: { + int sizeofpacked = sizeof(PACKED_void_GLuint_GLuint); + PACKED_void_GLuint_GLuint *newpacked = (PACKED_void_GLuint_GLuint*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLuint_GLuint_const_GLchar___GENPT__: { + int sizeofpacked = sizeof(PACKED_void_GLuint_GLuint_const_GLchar___GENPT__); + PACKED_void_GLuint_GLuint_const_GLchar___GENPT__ *newpacked = (PACKED_void_GLuint_GLuint_const_GLchar___GENPT__*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLenum_GLuint: { + int sizeofpacked = sizeof(PACKED_void_GLenum_GLuint); + PACKED_void_GLenum_GLuint *newpacked = (PACKED_void_GLenum_GLuint*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLclampf_GLclampf_GLclampf_GLclampf: { + int sizeofpacked = sizeof(PACKED_void_GLclampf_GLclampf_GLclampf_GLclampf); + PACKED_void_GLclampf_GLclampf_GLclampf_GLclampf *newpacked = (PACKED_void_GLclampf_GLclampf_GLclampf_GLclampf*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLenum_GLenum: { + int sizeofpacked = sizeof(PACKED_void_GLenum_GLenum); + PACKED_void_GLenum_GLenum *newpacked = (PACKED_void_GLenum_GLenum*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLenum_GLenum_GLenum_GLenum: { + int sizeofpacked = sizeof(PACKED_void_GLenum_GLenum_GLenum_GLenum); + PACKED_void_GLenum_GLenum_GLenum_GLenum *newpacked = (PACKED_void_GLenum_GLenum_GLenum_GLenum*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLenum_GLsizeiptr_const_GLvoid___GENPT___GLenum: { + int sizeofpacked = sizeof(PACKED_void_GLenum_GLsizeiptr_const_GLvoid___GENPT___GLenum); + PACKED_void_GLenum_GLsizeiptr_const_GLvoid___GENPT___GLenum *newpacked = (PACKED_void_GLenum_GLsizeiptr_const_GLvoid___GENPT___GLenum*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLenum_GLintptr_GLsizeiptr_const_GLvoid___GENPT__: { + int sizeofpacked = sizeof(PACKED_void_GLenum_GLintptr_GLsizeiptr_const_GLvoid___GENPT__); + PACKED_void_GLenum_GLintptr_GLsizeiptr_const_GLvoid___GENPT__ *newpacked = (PACKED_void_GLenum_GLintptr_GLsizeiptr_const_GLvoid___GENPT__*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_GLenum_GLenum: { + int sizeofpacked = sizeof(PACKED_GLenum_GLenum); + PACKED_GLenum_GLenum *newpacked = (PACKED_GLenum_GLenum*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLbitfield: { + int sizeofpacked = sizeof(PACKED_void_GLbitfield); + PACKED_void_GLbitfield *newpacked = (PACKED_void_GLbitfield*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLclampx_GLclampx_GLclampx_GLclampx: { + int sizeofpacked = sizeof(PACKED_void_GLclampx_GLclampx_GLclampx_GLclampx); + PACKED_void_GLclampx_GLclampx_GLclampx_GLclampx *newpacked = (PACKED_void_GLclampx_GLclampx_GLclampx_GLclampx*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLclampf: { + int sizeofpacked = sizeof(PACKED_void_GLclampf); + PACKED_void_GLclampf *newpacked = (PACKED_void_GLclampf*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLclampx: { + int sizeofpacked = sizeof(PACKED_void_GLclampx); + PACKED_void_GLclampx *newpacked = (PACKED_void_GLclampx*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLint: { + int sizeofpacked = sizeof(PACKED_void_GLint); + PACKED_void_GLint *newpacked = (PACKED_void_GLint*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLenum_const_GLfloat___GENPT__: { + int sizeofpacked = sizeof(PACKED_void_GLenum_const_GLfloat___GENPT__); + PACKED_void_GLenum_const_GLfloat___GENPT__ *newpacked = (PACKED_void_GLenum_const_GLfloat___GENPT__*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLenum_const_GLfixed___GENPT__: { + int sizeofpacked = sizeof(PACKED_void_GLenum_const_GLfixed___GENPT__); + PACKED_void_GLenum_const_GLfixed___GENPT__ *newpacked = (PACKED_void_GLenum_const_GLfixed___GENPT__*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLfloat_GLfloat_GLfloat_GLfloat: { + int sizeofpacked = sizeof(PACKED_void_GLfloat_GLfloat_GLfloat_GLfloat); + PACKED_void_GLfloat_GLfloat_GLfloat_GLfloat *newpacked = (PACKED_void_GLfloat_GLfloat_GLfloat_GLfloat*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLubyte_GLubyte_GLubyte_GLubyte: { + int sizeofpacked = sizeof(PACKED_void_GLubyte_GLubyte_GLubyte_GLubyte); + PACKED_void_GLubyte_GLubyte_GLubyte_GLubyte *newpacked = (PACKED_void_GLubyte_GLubyte_GLubyte_GLubyte*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLfixed_GLfixed_GLfixed_GLfixed: { + int sizeofpacked = sizeof(PACKED_void_GLfixed_GLfixed_GLfixed_GLfixed); + PACKED_void_GLfixed_GLfixed_GLfixed_GLfixed *newpacked = (PACKED_void_GLfixed_GLfixed_GLfixed_GLfixed*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLboolean_GLboolean_GLboolean_GLboolean: { + int sizeofpacked = sizeof(PACKED_void_GLboolean_GLboolean_GLboolean_GLboolean); + PACKED_void_GLboolean_GLboolean_GLboolean_GLboolean *newpacked = (PACKED_void_GLboolean_GLboolean_GLboolean_GLboolean*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLint_GLenum_GLsizei_const_GLvoid___GENPT__: { + int sizeofpacked = sizeof(PACKED_void_GLint_GLenum_GLsizei_const_GLvoid___GENPT__); + PACKED_void_GLint_GLenum_GLsizei_const_GLvoid___GENPT__ *newpacked = (PACKED_void_GLint_GLenum_GLsizei_const_GLvoid___GENPT__*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLuint: { + int sizeofpacked = sizeof(PACKED_void_GLuint); + PACKED_void_GLuint *newpacked = (PACKED_void_GLuint*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLenum_GLint_GLenum_GLsizei_GLsizei_GLint_GLsizei_const_GLvoid___GENPT__: { + int sizeofpacked = sizeof(PACKED_void_GLenum_GLint_GLenum_GLsizei_GLsizei_GLint_GLsizei_const_GLvoid___GENPT__); + PACKED_void_GLenum_GLint_GLenum_GLsizei_GLsizei_GLint_GLsizei_const_GLvoid___GENPT__ *newpacked = (PACKED_void_GLenum_GLint_GLenum_GLsizei_GLsizei_GLint_GLsizei_const_GLvoid___GENPT__*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLenum_GLint_GLint_GLint_GLsizei_GLsizei_GLenum_GLsizei_const_GLvoid___GENPT__: { + int sizeofpacked = sizeof(PACKED_void_GLenum_GLint_GLint_GLint_GLsizei_GLsizei_GLenum_GLsizei_const_GLvoid___GENPT__); + PACKED_void_GLenum_GLint_GLint_GLint_GLsizei_GLsizei_GLenum_GLsizei_const_GLvoid___GENPT__ *newpacked = (PACKED_void_GLenum_GLint_GLint_GLint_GLsizei_GLsizei_GLenum_GLsizei_const_GLvoid___GENPT__*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLenum_GLint_GLenum_GLint_GLint_GLsizei_GLsizei_GLint: { + int sizeofpacked = sizeof(PACKED_void_GLenum_GLint_GLenum_GLint_GLint_GLsizei_GLsizei_GLint); + PACKED_void_GLenum_GLint_GLenum_GLint_GLint_GLsizei_GLsizei_GLint *newpacked = (PACKED_void_GLenum_GLint_GLenum_GLint_GLint_GLsizei_GLsizei_GLint*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLenum_GLint_GLint_GLint_GLint_GLint_GLsizei_GLsizei: { + int sizeofpacked = sizeof(PACKED_void_GLenum_GLint_GLint_GLint_GLint_GLint_GLsizei_GLsizei); + PACKED_void_GLenum_GLint_GLint_GLint_GLint_GLint_GLsizei_GLsizei *newpacked = (PACKED_void_GLenum_GLint_GLint_GLint_GLint_GLint_GLsizei_GLsizei*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_GLuint: { + int sizeofpacked = sizeof(PACKED_GLuint); + PACKED_GLuint *newpacked = (PACKED_GLuint*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_GLuint_GLenum: { + int sizeofpacked = sizeof(PACKED_GLuint_GLenum); + PACKED_GLuint_GLenum *newpacked = (PACKED_GLuint_GLenum*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLsizei_const_GLuint___GENPT__: { + int sizeofpacked = sizeof(PACKED_void_GLsizei_const_GLuint___GENPT__); + PACKED_void_GLsizei_const_GLuint___GENPT__ *newpacked = (PACKED_void_GLsizei_const_GLuint___GENPT__*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLsizei_GLuint___GENPT__: { + int sizeofpacked = sizeof(PACKED_void_GLsizei_GLuint___GENPT__); + PACKED_void_GLsizei_GLuint___GENPT__ *newpacked = (PACKED_void_GLsizei_GLuint___GENPT__*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLboolean: { + int sizeofpacked = sizeof(PACKED_void_GLboolean); + PACKED_void_GLboolean *newpacked = (PACKED_void_GLboolean*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLclampf_GLclampf: { + int sizeofpacked = sizeof(PACKED_void_GLclampf_GLclampf); + PACKED_void_GLclampf_GLclampf *newpacked = (PACKED_void_GLclampf_GLclampf*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLclampx_GLclampx: { + int sizeofpacked = sizeof(PACKED_void_GLclampx_GLclampx); + PACKED_void_GLclampx_GLclampx *newpacked = (PACKED_void_GLclampx_GLclampx*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLenum_GLint_GLsizei: { + int sizeofpacked = sizeof(PACKED_void_GLenum_GLint_GLsizei); + PACKED_void_GLenum_GLint_GLsizei *newpacked = (PACKED_void_GLenum_GLint_GLsizei*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLenum_GLsizei_GLenum_const_GLvoid___GENPT__: { + int sizeofpacked = sizeof(PACKED_void_GLenum_GLsizei_GLenum_const_GLvoid___GENPT__); + PACKED_void_GLenum_GLsizei_GLenum_const_GLvoid___GENPT__ *newpacked = (PACKED_void_GLenum_GLsizei_GLenum_const_GLvoid___GENPT__*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLfloat_GLfloat_GLfloat_GLfloat_GLfloat: { + int sizeofpacked = sizeof(PACKED_void_GLfloat_GLfloat_GLfloat_GLfloat_GLfloat); + PACKED_void_GLfloat_GLfloat_GLfloat_GLfloat_GLfloat *newpacked = (PACKED_void_GLfloat_GLfloat_GLfloat_GLfloat_GLfloat*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLint_GLint_GLint_GLint_GLint: { + int sizeofpacked = sizeof(PACKED_void_GLint_GLint_GLint_GLint_GLint); + PACKED_void_GLint_GLint_GLint_GLint_GLint *newpacked = (PACKED_void_GLint_GLint_GLint_GLint_GLint*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void: { + int sizeofpacked = sizeof(PACKED_void); + PACKED_void *newpacked = (PACKED_void*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLenum_GLsizei_const_GLvoid___GENPT__: { + int sizeofpacked = sizeof(PACKED_void_GLenum_GLsizei_const_GLvoid___GENPT__); + PACKED_void_GLenum_GLsizei_const_GLvoid___GENPT__ *newpacked = (PACKED_void_GLenum_GLsizei_const_GLvoid___GENPT__*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLfloat: { + int sizeofpacked = sizeof(PACKED_void_GLfloat); + PACKED_void_GLfloat *newpacked = (PACKED_void_GLfloat*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_const_GLfloat___GENPT__: { + int sizeofpacked = sizeof(PACKED_void_const_GLfloat___GENPT__); + PACKED_void_const_GLfloat___GENPT__ *newpacked = (PACKED_void_const_GLfloat___GENPT__*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLenum_GLfloat: { + int sizeofpacked = sizeof(PACKED_void_GLenum_GLfloat); + PACKED_void_GLenum_GLfloat *newpacked = (PACKED_void_GLenum_GLfloat*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLenum_GLfixed: { + int sizeofpacked = sizeof(PACKED_void_GLenum_GLfixed); + PACKED_void_GLenum_GLfixed *newpacked = (PACKED_void_GLenum_GLfixed*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLenum_GLenum_GLenum_GLuint: { + int sizeofpacked = sizeof(PACKED_void_GLenum_GLenum_GLenum_GLuint); + PACKED_void_GLenum_GLenum_GLenum_GLuint *newpacked = (PACKED_void_GLenum_GLenum_GLenum_GLuint*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLenum_GLenum_GLenum_GLuint_GLint: { + int sizeofpacked = sizeof(PACKED_void_GLenum_GLenum_GLenum_GLuint_GLint); + PACKED_void_GLenum_GLenum_GLenum_GLuint_GLint *newpacked = (PACKED_void_GLenum_GLenum_GLenum_GLuint_GLint*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLfloat_GLfloat_GLfloat_GLfloat_GLfloat_GLfloat: { + int sizeofpacked = sizeof(PACKED_void_GLfloat_GLfloat_GLfloat_GLfloat_GLfloat_GLfloat); + PACKED_void_GLfloat_GLfloat_GLfloat_GLfloat_GLfloat_GLfloat *newpacked = (PACKED_void_GLfloat_GLfloat_GLfloat_GLfloat_GLfloat_GLfloat*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLfixed_GLfixed_GLfixed_GLfixed_GLfixed_GLfixed: { + int sizeofpacked = sizeof(PACKED_void_GLfixed_GLfixed_GLfixed_GLfixed_GLfixed_GLfixed); + PACKED_void_GLfixed_GLfixed_GLfixed_GLfixed_GLfixed_GLfixed *newpacked = (PACKED_void_GLfixed_GLfixed_GLfixed_GLfixed_GLfixed_GLfixed*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLuint_GLuint_GLsizei_GLsizei___GENPT___GLint___GENPT___GLenum___GENPT___GLchar___GENPT__: { + int sizeofpacked = sizeof(PACKED_void_GLuint_GLuint_GLsizei_GLsizei___GENPT___GLint___GENPT___GLenum___GENPT___GLchar___GENPT__); + PACKED_void_GLuint_GLuint_GLsizei_GLsizei___GENPT___GLint___GENPT___GLenum___GENPT___GLchar___GENPT__ *newpacked = (PACKED_void_GLuint_GLuint_GLsizei_GLsizei___GENPT___GLint___GENPT___GLenum___GENPT___GLchar___GENPT__*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLuint_GLsizei_GLsizei___GENPT___GLuint___GENPT__: { + int sizeofpacked = sizeof(PACKED_void_GLuint_GLsizei_GLsizei___GENPT___GLuint___GENPT__); + PACKED_void_GLuint_GLsizei_GLsizei___GENPT___GLuint___GENPT__ *newpacked = (PACKED_void_GLuint_GLsizei_GLsizei___GENPT___GLuint___GENPT__*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_GLint_GLuint_const_GLchar___GENPT__: { + int sizeofpacked = sizeof(PACKED_GLint_GLuint_const_GLchar___GENPT__); + PACKED_GLint_GLuint_const_GLchar___GENPT__ *newpacked = (PACKED_GLint_GLuint_const_GLchar___GENPT__*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLenum_GLboolean___GENPT__: { + int sizeofpacked = sizeof(PACKED_void_GLenum_GLboolean___GENPT__); + PACKED_void_GLenum_GLboolean___GENPT__ *newpacked = (PACKED_void_GLenum_GLboolean___GENPT__*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLenum_GLenum_GLint___GENPT__: { + int sizeofpacked = sizeof(PACKED_void_GLenum_GLenum_GLint___GENPT__); + PACKED_void_GLenum_GLenum_GLint___GENPT__ *newpacked = (PACKED_void_GLenum_GLenum_GLint___GENPT__*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLenum_GLfloat___GENPT__: { + int sizeofpacked = sizeof(PACKED_void_GLenum_GLfloat___GENPT__); + PACKED_void_GLenum_GLfloat___GENPT__ *newpacked = (PACKED_void_GLenum_GLfloat___GENPT__*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLenum_GLfixed___GENPT__: { + int sizeofpacked = sizeof(PACKED_void_GLenum_GLfixed___GENPT__); + PACKED_void_GLenum_GLfixed___GENPT__ *newpacked = (PACKED_void_GLenum_GLfixed___GENPT__*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_GLenum: { + int sizeofpacked = sizeof(PACKED_GLenum); + PACKED_GLenum *newpacked = (PACKED_GLenum*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLenum_GLenum_GLenum_GLint___GENPT__: { + int sizeofpacked = sizeof(PACKED_void_GLenum_GLenum_GLenum_GLint___GENPT__); + PACKED_void_GLenum_GLenum_GLenum_GLint___GENPT__ *newpacked = (PACKED_void_GLenum_GLenum_GLenum_GLint___GENPT__*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLenum_GLint___GENPT__: { + int sizeofpacked = sizeof(PACKED_void_GLenum_GLint___GENPT__); + PACKED_void_GLenum_GLint___GENPT__ *newpacked = (PACKED_void_GLenum_GLint___GENPT__*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLenum_GLenum_GLfloat___GENPT__: { + int sizeofpacked = sizeof(PACKED_void_GLenum_GLenum_GLfloat___GENPT__); + PACKED_void_GLenum_GLenum_GLfloat___GENPT__ *newpacked = (PACKED_void_GLenum_GLenum_GLfloat___GENPT__*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLenum_GLenum_GLfixed___GENPT__: { + int sizeofpacked = sizeof(PACKED_void_GLenum_GLenum_GLfixed___GENPT__); + PACKED_void_GLenum_GLenum_GLfixed___GENPT__ *newpacked = (PACKED_void_GLenum_GLenum_GLfixed___GENPT__*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLenum_GLvoid___GENPT____GENPT__: { + int sizeofpacked = sizeof(PACKED_void_GLenum_GLvoid___GENPT____GENPT__); + PACKED_void_GLenum_GLvoid___GENPT____GENPT__ *newpacked = (PACKED_void_GLenum_GLvoid___GENPT____GENPT__*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLuint_GLsizei_GLsizei___GENPT___GLchar___GENPT__: { + int sizeofpacked = sizeof(PACKED_void_GLuint_GLsizei_GLsizei___GENPT___GLchar___GENPT__); + PACKED_void_GLuint_GLsizei_GLsizei___GENPT___GLchar___GENPT__ *newpacked = (PACKED_void_GLuint_GLsizei_GLsizei___GENPT___GLchar___GENPT__*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLuint_GLenum_GLint___GENPT__: { + int sizeofpacked = sizeof(PACKED_void_GLuint_GLenum_GLint___GENPT__); + PACKED_void_GLuint_GLenum_GLint___GENPT__ *newpacked = (PACKED_void_GLuint_GLenum_GLint___GENPT__*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLenum_GLenum_GLint___GENPT___GLint___GENPT__: { + int sizeofpacked = sizeof(PACKED_void_GLenum_GLenum_GLint___GENPT___GLint___GENPT__); + PACKED_void_GLenum_GLenum_GLint___GENPT___GLint___GENPT__ *newpacked = (PACKED_void_GLenum_GLenum_GLint___GENPT___GLint___GENPT__*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_const_GLubyte___GENPT___GLenum: { + int sizeofpacked = sizeof(PACKED_const_GLubyte___GENPT___GLenum); + PACKED_const_GLubyte___GENPT___GLenum *newpacked = (PACKED_const_GLubyte___GENPT___GLenum*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLuint_GLint_GLfloat___GENPT__: { + int sizeofpacked = sizeof(PACKED_void_GLuint_GLint_GLfloat___GENPT__); + PACKED_void_GLuint_GLint_GLfloat___GENPT__ *newpacked = (PACKED_void_GLuint_GLint_GLfloat___GENPT__*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLuint_GLint_GLint___GENPT__: { + int sizeofpacked = sizeof(PACKED_void_GLuint_GLint_GLint___GENPT__); + PACKED_void_GLuint_GLint_GLint___GENPT__ *newpacked = (PACKED_void_GLuint_GLint_GLint___GENPT__*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLuint_GLenum_GLvoid___GENPT____GENPT__: { + int sizeofpacked = sizeof(PACKED_void_GLuint_GLenum_GLvoid___GENPT____GENPT__); + PACKED_void_GLuint_GLenum_GLvoid___GENPT____GENPT__ *newpacked = (PACKED_void_GLuint_GLenum_GLvoid___GENPT____GENPT__*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLuint_GLenum_GLfloat___GENPT__: { + int sizeofpacked = sizeof(PACKED_void_GLuint_GLenum_GLfloat___GENPT__); + PACKED_void_GLuint_GLenum_GLfloat___GENPT__ *newpacked = (PACKED_void_GLuint_GLenum_GLfloat___GENPT__*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_GLboolean_GLuint: { + int sizeofpacked = sizeof(PACKED_GLboolean_GLuint); + PACKED_GLboolean_GLuint *newpacked = (PACKED_GLboolean_GLuint*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_GLboolean_GLenum: { + int sizeofpacked = sizeof(PACKED_GLboolean_GLenum); + PACKED_GLboolean_GLenum *newpacked = (PACKED_GLboolean_GLenum*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLenum_GLenum_GLfloat: { + int sizeofpacked = sizeof(PACKED_void_GLenum_GLenum_GLfloat); + PACKED_void_GLenum_GLenum_GLfloat *newpacked = (PACKED_void_GLenum_GLenum_GLfloat*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLenum_GLenum_const_GLfloat___GENPT__: { + int sizeofpacked = sizeof(PACKED_void_GLenum_GLenum_const_GLfloat___GENPT__); + PACKED_void_GLenum_GLenum_const_GLfloat___GENPT__ *newpacked = (PACKED_void_GLenum_GLenum_const_GLfloat___GENPT__*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLenum_GLenum_GLfixed: { + int sizeofpacked = sizeof(PACKED_void_GLenum_GLenum_GLfixed); + PACKED_void_GLenum_GLenum_GLfixed *newpacked = (PACKED_void_GLenum_GLenum_GLfixed*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLenum_GLenum_const_GLfixed___GENPT__: { + int sizeofpacked = sizeof(PACKED_void_GLenum_GLenum_const_GLfixed___GENPT__); + PACKED_void_GLenum_GLenum_const_GLfixed___GENPT__ *newpacked = (PACKED_void_GLenum_GLenum_const_GLfixed___GENPT__*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLfixed: { + int sizeofpacked = sizeof(PACKED_void_GLfixed); + PACKED_void_GLfixed *newpacked = (PACKED_void_GLfixed*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_const_GLfixed___GENPT__: { + int sizeofpacked = sizeof(PACKED_void_const_GLfixed___GENPT__); + PACKED_void_const_GLfixed___GENPT__ *newpacked = (PACKED_void_const_GLfixed___GENPT__*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLenum_const_GLint___GENPT___const_GLsizei___GENPT___GLsizei: { + int sizeofpacked = sizeof(PACKED_void_GLenum_const_GLint___GENPT___const_GLsizei___GENPT___GLsizei); + PACKED_void_GLenum_const_GLint___GENPT___const_GLsizei___GENPT___GLsizei *newpacked = (PACKED_void_GLenum_const_GLint___GENPT___const_GLsizei___GENPT___GLsizei*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLenum_GLsizei___GENPT___GLenum_const_void___GENPT___const___GENPT___GLsizei: { + int sizeofpacked = sizeof(PACKED_void_GLenum_GLsizei___GENPT___GLenum_const_void___GENPT___const___GENPT___GLsizei); + PACKED_void_GLenum_GLsizei___GENPT___GLenum_const_void___GENPT___const___GENPT___GLsizei *newpacked = (PACKED_void_GLenum_GLsizei___GENPT___GLenum_const_void___GENPT___const___GENPT___GLsizei*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLenum_GLfloat_GLfloat_GLfloat_GLfloat: { + int sizeofpacked = sizeof(PACKED_void_GLenum_GLfloat_GLfloat_GLfloat_GLfloat); + PACKED_void_GLenum_GLfloat_GLfloat_GLfloat_GLfloat *newpacked = (PACKED_void_GLenum_GLfloat_GLfloat_GLfloat_GLfloat*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLenum_GLfixed_GLfixed_GLfixed_GLfixed: { + int sizeofpacked = sizeof(PACKED_void_GLenum_GLfixed_GLfixed_GLfixed_GLfixed); + PACKED_void_GLenum_GLfixed_GLfixed_GLfixed_GLfixed *newpacked = (PACKED_void_GLenum_GLfixed_GLfixed_GLfixed_GLfixed*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLfloat_GLfloat_GLfloat: { + int sizeofpacked = sizeof(PACKED_void_GLfloat_GLfloat_GLfloat); + PACKED_void_GLfloat_GLfloat_GLfloat *newpacked = (PACKED_void_GLfloat_GLfloat_GLfloat*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLfixed_GLfixed_GLfixed: { + int sizeofpacked = sizeof(PACKED_void_GLfixed_GLfixed_GLfixed); + PACKED_void_GLfixed_GLfixed_GLfixed *newpacked = (PACKED_void_GLfixed_GLfixed_GLfixed*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLenum_GLint: { + int sizeofpacked = sizeof(PACKED_void_GLenum_GLint); + PACKED_void_GLenum_GLint *newpacked = (PACKED_void_GLenum_GLint*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLfloat_GLfloat: { + int sizeofpacked = sizeof(PACKED_void_GLfloat_GLfloat); + PACKED_void_GLfloat_GLfloat *newpacked = (PACKED_void_GLfloat_GLfloat*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLfixed_GLfixed: { + int sizeofpacked = sizeof(PACKED_void_GLfixed_GLfixed); + PACKED_void_GLfixed_GLfixed *newpacked = (PACKED_void_GLfixed_GLfixed*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLint_GLint_GLsizei_GLsizei_GLenum_GLenum_GLvoid___GENPT__: { + int sizeofpacked = sizeof(PACKED_void_GLint_GLint_GLsizei_GLsizei_GLenum_GLenum_GLvoid___GENPT__); + PACKED_void_GLint_GLint_GLsizei_GLsizei_GLenum_GLenum_GLvoid___GENPT__ *newpacked = (PACKED_void_GLint_GLint_GLsizei_GLsizei_GLenum_GLenum_GLvoid___GENPT__*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLenum_GLenum_GLsizei_GLsizei: { + int sizeofpacked = sizeof(PACKED_void_GLenum_GLenum_GLsizei_GLsizei); + PACKED_void_GLenum_GLenum_GLsizei_GLsizei *newpacked = (PACKED_void_GLenum_GLenum_GLsizei_GLsizei*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLclampf_GLboolean: { + int sizeofpacked = sizeof(PACKED_void_GLclampf_GLboolean); + PACKED_void_GLclampf_GLboolean *newpacked = (PACKED_void_GLclampf_GLboolean*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLclampx_GLboolean: { + int sizeofpacked = sizeof(PACKED_void_GLclampx_GLboolean); + PACKED_void_GLclampx_GLboolean *newpacked = (PACKED_void_GLclampx_GLboolean*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLint_GLint_GLsizei_GLsizei: { + int sizeofpacked = sizeof(PACKED_void_GLint_GLint_GLsizei_GLsizei); + PACKED_void_GLint_GLint_GLsizei_GLsizei *newpacked = (PACKED_void_GLint_GLint_GLsizei_GLsizei*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLsizei_const_GLuint___GENPT___GLenum_const_GLvoid___GENPT___GLsizei: { + int sizeofpacked = sizeof(PACKED_void_GLsizei_const_GLuint___GENPT___GLenum_const_GLvoid___GENPT___GLsizei); + PACKED_void_GLsizei_const_GLuint___GENPT___GLenum_const_GLvoid___GENPT___GLsizei *newpacked = (PACKED_void_GLsizei_const_GLuint___GENPT___GLenum_const_GLvoid___GENPT___GLsizei*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLuint_GLsizei_const_GLchar___GENPT___const___GENPT___const_GLint___GENPT__: { + int sizeofpacked = sizeof(PACKED_void_GLuint_GLsizei_const_GLchar___GENPT___const___GENPT___const_GLint___GENPT__); + PACKED_void_GLuint_GLsizei_const_GLchar___GENPT___const___GENPT___const_GLint___GENPT__ *newpacked = (PACKED_void_GLuint_GLsizei_const_GLchar___GENPT___const___GENPT___const_GLint___GENPT__*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLenum_GLint_GLuint: { + int sizeofpacked = sizeof(PACKED_void_GLenum_GLint_GLuint); + PACKED_void_GLenum_GLint_GLuint *newpacked = (PACKED_void_GLenum_GLint_GLuint*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLenum_GLenum_GLint_GLuint: { + int sizeofpacked = sizeof(PACKED_void_GLenum_GLenum_GLint_GLuint); + PACKED_void_GLenum_GLenum_GLint_GLuint *newpacked = (PACKED_void_GLenum_GLenum_GLint_GLuint*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLenum_GLenum_GLenum: { + int sizeofpacked = sizeof(PACKED_void_GLenum_GLenum_GLenum); + PACKED_void_GLenum_GLenum_GLenum *newpacked = (PACKED_void_GLenum_GLenum_GLenum*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLenum_GLenum_GLint: { + int sizeofpacked = sizeof(PACKED_void_GLenum_GLenum_GLint); + PACKED_void_GLenum_GLenum_GLint *newpacked = (PACKED_void_GLenum_GLenum_GLint*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLenum_GLenum_const_GLint___GENPT__: { + int sizeofpacked = sizeof(PACKED_void_GLenum_GLenum_const_GLint___GENPT__); + PACKED_void_GLenum_GLenum_const_GLint___GENPT__ *newpacked = (PACKED_void_GLenum_GLenum_const_GLint___GENPT__*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLenum_GLint_GLint_GLsizei_GLsizei_GLint_GLenum_GLenum_const_GLvoid___GENPT__: { + int sizeofpacked = sizeof(PACKED_void_GLenum_GLint_GLint_GLsizei_GLsizei_GLint_GLenum_GLenum_const_GLvoid___GENPT__); + PACKED_void_GLenum_GLint_GLint_GLsizei_GLsizei_GLint_GLenum_GLenum_const_GLvoid___GENPT__ *newpacked = (PACKED_void_GLenum_GLint_GLint_GLsizei_GLsizei_GLint_GLenum_GLenum_const_GLvoid___GENPT__*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLenum_GLint_GLint_GLint_GLsizei_GLsizei_GLenum_GLenum_const_GLvoid___GENPT__: { + int sizeofpacked = sizeof(PACKED_void_GLenum_GLint_GLint_GLint_GLsizei_GLsizei_GLenum_GLenum_const_GLvoid___GENPT__); + PACKED_void_GLenum_GLint_GLint_GLint_GLsizei_GLsizei_GLenum_GLenum_const_GLvoid___GENPT__ *newpacked = (PACKED_void_GLenum_GLint_GLint_GLint_GLsizei_GLsizei_GLenum_GLenum_const_GLvoid___GENPT__*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLint_GLfloat: { + int sizeofpacked = sizeof(PACKED_void_GLint_GLfloat); + PACKED_void_GLint_GLfloat *newpacked = (PACKED_void_GLint_GLfloat*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLint_GLsizei_const_GLfloat___GENPT__: { + int sizeofpacked = sizeof(PACKED_void_GLint_GLsizei_const_GLfloat___GENPT__); + PACKED_void_GLint_GLsizei_const_GLfloat___GENPT__ *newpacked = (PACKED_void_GLint_GLsizei_const_GLfloat___GENPT__*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLint_GLint: { + int sizeofpacked = sizeof(PACKED_void_GLint_GLint); + PACKED_void_GLint_GLint *newpacked = (PACKED_void_GLint_GLint*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLint_GLsizei_const_GLint___GENPT__: { + int sizeofpacked = sizeof(PACKED_void_GLint_GLsizei_const_GLint___GENPT__); + PACKED_void_GLint_GLsizei_const_GLint___GENPT__ *newpacked = (PACKED_void_GLint_GLsizei_const_GLint___GENPT__*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLint_GLfloat_GLfloat: { + int sizeofpacked = sizeof(PACKED_void_GLint_GLfloat_GLfloat); + PACKED_void_GLint_GLfloat_GLfloat *newpacked = (PACKED_void_GLint_GLfloat_GLfloat*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLint_GLint_GLint: { + int sizeofpacked = sizeof(PACKED_void_GLint_GLint_GLint); + PACKED_void_GLint_GLint_GLint *newpacked = (PACKED_void_GLint_GLint_GLint*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLint_GLfloat_GLfloat_GLfloat: { + int sizeofpacked = sizeof(PACKED_void_GLint_GLfloat_GLfloat_GLfloat); + PACKED_void_GLint_GLfloat_GLfloat_GLfloat *newpacked = (PACKED_void_GLint_GLfloat_GLfloat_GLfloat*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLint_GLint_GLint_GLint: { + int sizeofpacked = sizeof(PACKED_void_GLint_GLint_GLint_GLint); + PACKED_void_GLint_GLint_GLint_GLint *newpacked = (PACKED_void_GLint_GLint_GLint_GLint*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLint_GLfloat_GLfloat_GLfloat_GLfloat: { + int sizeofpacked = sizeof(PACKED_void_GLint_GLfloat_GLfloat_GLfloat_GLfloat); + PACKED_void_GLint_GLfloat_GLfloat_GLfloat_GLfloat *newpacked = (PACKED_void_GLint_GLfloat_GLfloat_GLfloat_GLfloat*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLint_GLsizei_GLboolean_const_GLfloat___GENPT__: { + int sizeofpacked = sizeof(PACKED_void_GLint_GLsizei_GLboolean_const_GLfloat___GENPT__); + PACKED_void_GLint_GLsizei_GLboolean_const_GLfloat___GENPT__ *newpacked = (PACKED_void_GLint_GLsizei_GLboolean_const_GLfloat___GENPT__*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLuint_GLfloat: { + int sizeofpacked = sizeof(PACKED_void_GLuint_GLfloat); + PACKED_void_GLuint_GLfloat *newpacked = (PACKED_void_GLuint_GLfloat*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLuint_const_GLfloat___GENPT__: { + int sizeofpacked = sizeof(PACKED_void_GLuint_const_GLfloat___GENPT__); + PACKED_void_GLuint_const_GLfloat___GENPT__ *newpacked = (PACKED_void_GLuint_const_GLfloat___GENPT__*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLuint_GLfloat_GLfloat: { + int sizeofpacked = sizeof(PACKED_void_GLuint_GLfloat_GLfloat); + PACKED_void_GLuint_GLfloat_GLfloat *newpacked = (PACKED_void_GLuint_GLfloat_GLfloat*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLuint_GLfloat_GLfloat_GLfloat: { + int sizeofpacked = sizeof(PACKED_void_GLuint_GLfloat_GLfloat_GLfloat); + PACKED_void_GLuint_GLfloat_GLfloat_GLfloat *newpacked = (PACKED_void_GLuint_GLfloat_GLfloat_GLfloat*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLuint_GLfloat_GLfloat_GLfloat_GLfloat: { + int sizeofpacked = sizeof(PACKED_void_GLuint_GLfloat_GLfloat_GLfloat_GLfloat); + PACKED_void_GLuint_GLfloat_GLfloat_GLfloat_GLfloat *newpacked = (PACKED_void_GLuint_GLfloat_GLfloat_GLfloat_GLfloat*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + case FORMAT_void_GLuint_GLint_GLenum_GLboolean_GLsizei_const_GLvoid___GENPT__: { + int sizeofpacked = sizeof(PACKED_void_GLuint_GLint_GLenum_GLboolean_GLsizei_const_GLvoid___GENPT__); + PACKED_void_GLuint_GLint_GLenum_GLboolean_GLsizei_const_GLvoid___GENPT__ *newpacked = (PACKED_void_GLuint_GLint_GLenum_GLboolean_GLsizei_const_GLvoid___GENPT__*)malloc(sizeofpacked); + memcpy(newpacked, packed, sizeofpacked); + return (packed_call_t*)newpacked; + break; + } + } +}*/ diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/wrap/gles.h b/Projects/Android/jni/SupportLibs/gl4es/src/gl/wrap/gles.h new file mode 100644 index 0000000..8262f4a --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/wrap/gles.h @@ -0,0 +1,6629 @@ +#include "../gles.h" + +#ifndef GLESWRAP_H +#define GLESWRAP_H + +typedef struct { + int format; + void *func; + void *args; +} packed_call_t; + +typedef struct { + int func; + void *args; +} indexed_call_t; + +enum FORMAT { + FORMAT_void_GLenum, + FORMAT_void_GLenum_GLclampf, + FORMAT_void_GLenum_GLclampx, + FORMAT_void_GLuint_GLuint, + FORMAT_void_GLuint_GLuint_const_GLchar___GENPT__, + FORMAT_void_GLenum_GLuint, + FORMAT_void_GLclampf_GLclampf_GLclampf_GLclampf, + FORMAT_void_GLenum_GLenum, + FORMAT_void_GLenum_GLenum_GLenum_GLenum, + FORMAT_void_GLenum_GLsizeiptr_const_GLvoid___GENPT___GLenum, + FORMAT_void_GLenum_GLintptr_GLsizeiptr_const_GLvoid___GENPT__, + FORMAT_GLenum_GLenum, + FORMAT_void_GLbitfield, + FORMAT_void_GLclampx_GLclampx_GLclampx_GLclampx, + FORMAT_void_GLclampf, + FORMAT_void_GLclampx, + FORMAT_void_GLint, + FORMAT_void_GLenum_const_GLfloat___GENPT__, + FORMAT_void_GLenum_const_GLfixed___GENPT__, + FORMAT_void_GLfloat_GLfloat_GLfloat_GLfloat, + FORMAT_void_GLubyte_GLubyte_GLubyte_GLubyte, + FORMAT_void_GLfixed_GLfixed_GLfixed_GLfixed, + FORMAT_void_GLboolean_GLboolean_GLboolean_GLboolean, + FORMAT_void_GLint_GLenum_GLsizei_const_GLvoid___GENPT__, + FORMAT_void_GLuint, + FORMAT_void_GLenum_GLint_GLenum_GLsizei_GLsizei_GLint_GLsizei_const_GLvoid___GENPT__, + FORMAT_void_GLenum_GLint_GLint_GLint_GLsizei_GLsizei_GLenum_GLsizei_const_GLvoid___GENPT__, + FORMAT_void_GLenum_GLint_GLenum_GLint_GLint_GLsizei_GLsizei_GLint, + FORMAT_void_GLenum_GLint_GLint_GLint_GLint_GLint_GLsizei_GLsizei, + FORMAT_GLuint, + FORMAT_GLuint_GLenum, + FORMAT_void_GLsizei_const_GLuint___GENPT__, + FORMAT_void_GLsizei_GLuint___GENPT__, + FORMAT_void_GLboolean, + FORMAT_void_GLclampf_GLclampf, + FORMAT_void_GLclampx_GLclampx, + FORMAT_void_GLenum_GLint_GLsizei, + FORMAT_void_GLenum_GLsizei_GLenum_const_GLvoid___GENPT__, + FORMAT_void_GLfloat_GLfloat_GLfloat_GLfloat_GLfloat, + FORMAT_void_GLint_GLint_GLint_GLint_GLint, + FORMAT_void, + FORMAT_void_GLenum_GLsizei_const_GLvoid___GENPT__, + FORMAT_void_GLfloat, + FORMAT_void_const_GLfloat___GENPT__, + FORMAT_void_GLenum_GLfloat, + FORMAT_void_GLenum_GLfixed, + FORMAT_void_GLenum_GLenum_GLenum_GLuint, + FORMAT_void_GLenum_GLenum_GLenum_GLuint_GLint, + FORMAT_void_GLfloat_GLfloat_GLfloat_GLfloat_GLfloat_GLfloat, + FORMAT_void_GLfixed_GLfixed_GLfixed_GLfixed_GLfixed_GLfixed, + FORMAT_void_GLuint_GLuint_GLsizei_GLsizei___GENPT___GLint___GENPT___GLenum___GENPT___GLchar___GENPT__, + FORMAT_void_GLuint_GLsizei_GLsizei___GENPT___GLuint___GENPT__, + FORMAT_GLint_GLuint_const_GLchar___GENPT__, + FORMAT_void_GLenum_GLboolean___GENPT__, + FORMAT_void_GLenum_GLenum_GLint___GENPT__, + FORMAT_void_GLenum_GLfloat___GENPT__, + FORMAT_void_GLenum_GLfixed___GENPT__, + FORMAT_GLenum, + FORMAT_void_GLenum_GLenum_GLenum_GLint___GENPT__, + FORMAT_void_GLenum_GLint___GENPT__, + FORMAT_void_GLenum_GLenum_GLfloat___GENPT__, + FORMAT_void_GLenum_GLenum_GLfixed___GENPT__, + FORMAT_void_GLenum_GLvoid___GENPT____GENPT__, + FORMAT_void_GLuint_GLsizei_GLsizei___GENPT___GLchar___GENPT__, + FORMAT_void_GLuint_GLenum_GLint___GENPT__, + FORMAT_void_GLenum_GLenum_GLint___GENPT___GLint___GENPT__, + FORMAT_const_GLubyte___GENPT___GLenum, + FORMAT_void_GLuint_GLint_GLfloat___GENPT__, + FORMAT_void_GLuint_GLint_GLint___GENPT__, + FORMAT_void_GLuint_GLenum_GLvoid___GENPT____GENPT__, + FORMAT_void_GLuint_GLenum_GLfloat___GENPT__, + FORMAT_GLboolean_GLuint, + FORMAT_GLboolean_GLenum, + FORMAT_void_GLenum_GLenum_GLfloat, + FORMAT_void_GLenum_GLenum_const_GLfloat___GENPT__, + FORMAT_void_GLenum_GLenum_GLfixed, + FORMAT_void_GLenum_GLenum_const_GLfixed___GENPT__, + FORMAT_void_GLfixed, + FORMAT_void_const_GLfixed___GENPT__, + FORMAT_void_GLenum_const_GLint___GENPT___const_GLsizei___GENPT___GLsizei, + FORMAT_void_GLenum_GLsizei___GENPT___GLenum_const_void___GENPT___const___GENPT___GLsizei, + FORMAT_void_GLenum_GLfloat_GLfloat_GLfloat_GLfloat, + FORMAT_void_GLenum_GLfixed_GLfixed_GLfixed_GLfixed, + FORMAT_void_GLfloat_GLfloat_GLfloat, + FORMAT_void_GLfixed_GLfixed_GLfixed, + FORMAT_void_GLenum_GLint, + FORMAT_void_GLfloat_GLfloat, + FORMAT_void_GLfixed_GLfixed, + FORMAT_void_GLint_GLint_GLsizei_GLsizei_GLenum_GLenum_GLvoid___GENPT__, + FORMAT_void_GLenum_GLenum_GLsizei_GLsizei, + FORMAT_void_GLclampf_GLboolean, + FORMAT_void_GLclampx_GLboolean, + FORMAT_void_GLint_GLint_GLsizei_GLsizei, + FORMAT_void_GLsizei_const_GLuint___GENPT___GLenum_const_GLvoid___GENPT___GLsizei, + FORMAT_void_GLuint_GLsizei_const_GLchar___GENPT___const___GENPT___const_GLint___GENPT__, + FORMAT_void_GLenum_GLint_GLuint, + FORMAT_void_GLenum_GLenum_GLint_GLuint, + FORMAT_void_GLenum_GLenum_GLenum, + FORMAT_void_GLenum_GLenum_GLint, + FORMAT_void_GLenum_GLenum_const_GLint___GENPT__, + FORMAT_void_GLenum_GLint_GLint_GLsizei_GLsizei_GLint_GLenum_GLenum_const_GLvoid___GENPT__, + FORMAT_void_GLenum_GLint_GLint_GLint_GLsizei_GLsizei_GLenum_GLenum_const_GLvoid___GENPT__, + FORMAT_void_GLint_GLfloat, + FORMAT_void_GLint_GLsizei_const_GLfloat___GENPT__, + FORMAT_void_GLint_GLint, + FORMAT_void_GLint_GLsizei_const_GLint___GENPT__, + FORMAT_void_GLint_GLfloat_GLfloat, + FORMAT_void_GLint_GLint_GLint, + FORMAT_void_GLint_GLfloat_GLfloat_GLfloat, + FORMAT_void_GLint_GLint_GLint_GLint, + FORMAT_void_GLint_GLfloat_GLfloat_GLfloat_GLfloat, + FORMAT_void_GLint_GLsizei_GLboolean_const_GLfloat___GENPT__, + FORMAT_void_GLuint_GLfloat, + FORMAT_void_GLuint_const_GLfloat___GENPT__, + FORMAT_void_GLuint_GLfloat_GLfloat, + FORMAT_void_GLuint_GLfloat_GLfloat_GLfloat, + FORMAT_void_GLuint_GLfloat_GLfloat_GLfloat_GLfloat, + FORMAT_void_GLuint_GLint_GLenum_GLboolean_GLsizei_const_GLvoid___GENPT__, +}; + +typedef void (*FUNC_void_GLenum)(GLenum texture); +typedef struct { + GLenum a1; +} ARGS_void_GLenum; +typedef struct { + int format; + FUNC_void_GLenum func; + ARGS_void_GLenum args; +} PACKED_void_GLenum; +typedef struct { + int func; + ARGS_void_GLenum args; +} INDEXED_void_GLenum; +typedef void (*FUNC_void_GLenum_GLclampf)(GLenum func, GLclampf ref); +typedef struct { + GLenum a1; + GLclampf a2; +} ARGS_void_GLenum_GLclampf; +typedef struct { + int format; + FUNC_void_GLenum_GLclampf func; + ARGS_void_GLenum_GLclampf args; +} PACKED_void_GLenum_GLclampf; +typedef struct { + int func; + ARGS_void_GLenum_GLclampf args; +} INDEXED_void_GLenum_GLclampf; +typedef void (*FUNC_void_GLenum_GLclampx)(GLenum func, GLclampx ref); +typedef struct { + GLenum a1; + GLclampx a2; +} ARGS_void_GLenum_GLclampx; +typedef struct { + int format; + FUNC_void_GLenum_GLclampx func; + ARGS_void_GLenum_GLclampx args; +} PACKED_void_GLenum_GLclampx; +typedef struct { + int func; + ARGS_void_GLenum_GLclampx args; +} INDEXED_void_GLenum_GLclampx; +typedef void (*FUNC_void_GLuint_GLuint)(GLuint program, GLuint shader); +typedef struct { + GLuint a1; + GLuint a2; +} ARGS_void_GLuint_GLuint; +typedef struct { + int format; + FUNC_void_GLuint_GLuint func; + ARGS_void_GLuint_GLuint args; +} PACKED_void_GLuint_GLuint; +typedef struct { + int func; + ARGS_void_GLuint_GLuint args; +} INDEXED_void_GLuint_GLuint; +typedef void (*FUNC_void_GLuint_GLuint_const_GLchar___GENPT__)(GLuint program, GLuint index, const GLchar * name); +typedef struct { + GLuint a1; + GLuint a2; + GLchar * a3; +} ARGS_void_GLuint_GLuint_const_GLchar___GENPT__; +typedef struct { + int format; + FUNC_void_GLuint_GLuint_const_GLchar___GENPT__ func; + ARGS_void_GLuint_GLuint_const_GLchar___GENPT__ args; +} PACKED_void_GLuint_GLuint_const_GLchar___GENPT__; +typedef struct { + int func; + ARGS_void_GLuint_GLuint_const_GLchar___GENPT__ args; +} INDEXED_void_GLuint_GLuint_const_GLchar___GENPT__; +typedef void (*FUNC_void_GLenum_GLuint)(GLenum target, GLuint buffer); +typedef struct { + GLenum a1; + GLuint a2; +} ARGS_void_GLenum_GLuint; +typedef struct { + int format; + FUNC_void_GLenum_GLuint func; + ARGS_void_GLenum_GLuint args; +} PACKED_void_GLenum_GLuint; +typedef struct { + int func; + ARGS_void_GLenum_GLuint args; +} INDEXED_void_GLenum_GLuint; +typedef void (*FUNC_void_GLclampf_GLclampf_GLclampf_GLclampf)(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha); +typedef struct { + GLclampf a1; + GLclampf a2; + GLclampf a3; + GLclampf a4; +} ARGS_void_GLclampf_GLclampf_GLclampf_GLclampf; +typedef struct { + int format; + FUNC_void_GLclampf_GLclampf_GLclampf_GLclampf func; + ARGS_void_GLclampf_GLclampf_GLclampf_GLclampf args; +} PACKED_void_GLclampf_GLclampf_GLclampf_GLclampf; +typedef struct { + int func; + ARGS_void_GLclampf_GLclampf_GLclampf_GLclampf args; +} INDEXED_void_GLclampf_GLclampf_GLclampf_GLclampf; +typedef void (*FUNC_void_GLenum_GLenum)(GLenum modeRGB, GLenum modeA); +typedef struct { + GLenum a1; + GLenum a2; +} ARGS_void_GLenum_GLenum; +typedef struct { + int format; + FUNC_void_GLenum_GLenum func; + ARGS_void_GLenum_GLenum args; +} PACKED_void_GLenum_GLenum; +typedef struct { + int func; + ARGS_void_GLenum_GLenum args; +} INDEXED_void_GLenum_GLenum; +typedef void (*FUNC_void_GLenum_GLenum_GLenum_GLenum)(GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha); +typedef struct { + GLenum a1; + GLenum a2; + GLenum a3; + GLenum a4; +} ARGS_void_GLenum_GLenum_GLenum_GLenum; +typedef struct { + int format; + FUNC_void_GLenum_GLenum_GLenum_GLenum func; + ARGS_void_GLenum_GLenum_GLenum_GLenum args; +} PACKED_void_GLenum_GLenum_GLenum_GLenum; +typedef struct { + int func; + ARGS_void_GLenum_GLenum_GLenum_GLenum args; +} INDEXED_void_GLenum_GLenum_GLenum_GLenum; +typedef void (*FUNC_void_GLenum_GLsizeiptr_const_GLvoid___GENPT___GLenum)(GLenum target, GLsizeiptr size, const GLvoid * data, GLenum usage); +typedef struct { + GLenum a1; + GLsizeiptr a2; + GLvoid * a3; + GLenum a4; +} ARGS_void_GLenum_GLsizeiptr_const_GLvoid___GENPT___GLenum; +typedef struct { + int format; + FUNC_void_GLenum_GLsizeiptr_const_GLvoid___GENPT___GLenum func; + ARGS_void_GLenum_GLsizeiptr_const_GLvoid___GENPT___GLenum args; +} PACKED_void_GLenum_GLsizeiptr_const_GLvoid___GENPT___GLenum; +typedef struct { + int func; + ARGS_void_GLenum_GLsizeiptr_const_GLvoid___GENPT___GLenum args; +} INDEXED_void_GLenum_GLsizeiptr_const_GLvoid___GENPT___GLenum; +typedef void (*FUNC_void_GLenum_GLintptr_GLsizeiptr_const_GLvoid___GENPT__)(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid * data); +typedef struct { + GLenum a1; + GLintptr a2; + GLsizeiptr a3; + GLvoid * a4; +} ARGS_void_GLenum_GLintptr_GLsizeiptr_const_GLvoid___GENPT__; +typedef struct { + int format; + FUNC_void_GLenum_GLintptr_GLsizeiptr_const_GLvoid___GENPT__ func; + ARGS_void_GLenum_GLintptr_GLsizeiptr_const_GLvoid___GENPT__ args; +} PACKED_void_GLenum_GLintptr_GLsizeiptr_const_GLvoid___GENPT__; +typedef struct { + int func; + ARGS_void_GLenum_GLintptr_GLsizeiptr_const_GLvoid___GENPT__ args; +} INDEXED_void_GLenum_GLintptr_GLsizeiptr_const_GLvoid___GENPT__; +typedef GLenum (*FUNC_GLenum_GLenum)(GLenum target); +typedef struct { + GLenum a1; +} ARGS_GLenum_GLenum; +typedef struct { + int format; + FUNC_GLenum_GLenum func; + ARGS_GLenum_GLenum args; +} PACKED_GLenum_GLenum; +typedef struct { + int func; + ARGS_GLenum_GLenum args; +} INDEXED_GLenum_GLenum; +typedef void (*FUNC_void_GLbitfield)(GLbitfield mask); +typedef struct { + GLbitfield a1; +} ARGS_void_GLbitfield; +typedef struct { + int format; + FUNC_void_GLbitfield func; + ARGS_void_GLbitfield args; +} PACKED_void_GLbitfield; +typedef struct { + int func; + ARGS_void_GLbitfield args; +} INDEXED_void_GLbitfield; +typedef void (*FUNC_void_GLclampx_GLclampx_GLclampx_GLclampx)(GLclampx red, GLclampx green, GLclampx blue, GLclampx alpha); +typedef struct { + GLclampx a1; + GLclampx a2; + GLclampx a3; + GLclampx a4; +} ARGS_void_GLclampx_GLclampx_GLclampx_GLclampx; +typedef struct { + int format; + FUNC_void_GLclampx_GLclampx_GLclampx_GLclampx func; + ARGS_void_GLclampx_GLclampx_GLclampx_GLclampx args; +} PACKED_void_GLclampx_GLclampx_GLclampx_GLclampx; +typedef struct { + int func; + ARGS_void_GLclampx_GLclampx_GLclampx_GLclampx args; +} INDEXED_void_GLclampx_GLclampx_GLclampx_GLclampx; +typedef void (*FUNC_void_GLclampf)(GLclampf depth); +typedef struct { + GLclampf a1; +} ARGS_void_GLclampf; +typedef struct { + int format; + FUNC_void_GLclampf func; + ARGS_void_GLclampf args; +} PACKED_void_GLclampf; +typedef struct { + int func; + ARGS_void_GLclampf args; +} INDEXED_void_GLclampf; +typedef void (*FUNC_void_GLclampx)(GLclampx depth); +typedef struct { + GLclampx a1; +} ARGS_void_GLclampx; +typedef struct { + int format; + FUNC_void_GLclampx func; + ARGS_void_GLclampx args; +} PACKED_void_GLclampx; +typedef struct { + int func; + ARGS_void_GLclampx args; +} INDEXED_void_GLclampx; +typedef void (*FUNC_void_GLint)(GLint s); +typedef struct { + GLint a1; +} ARGS_void_GLint; +typedef struct { + int format; + FUNC_void_GLint func; + ARGS_void_GLint args; +} PACKED_void_GLint; +typedef struct { + int func; + ARGS_void_GLint args; +} INDEXED_void_GLint; +typedef void (*FUNC_void_GLenum_const_GLfloat___GENPT__)(GLenum plane, const GLfloat * equation); +typedef struct { + GLenum a1; + GLfloat * a2; +} ARGS_void_GLenum_const_GLfloat___GENPT__; +typedef struct { + int format; + FUNC_void_GLenum_const_GLfloat___GENPT__ func; + ARGS_void_GLenum_const_GLfloat___GENPT__ args; +} PACKED_void_GLenum_const_GLfloat___GENPT__; +typedef struct { + int func; + ARGS_void_GLenum_const_GLfloat___GENPT__ args; +} INDEXED_void_GLenum_const_GLfloat___GENPT__; +typedef void (*FUNC_void_GLenum_const_GLfixed___GENPT__)(GLenum plane, const GLfixed * equation); +typedef struct { + GLenum a1; + GLfixed * a2; +} ARGS_void_GLenum_const_GLfixed___GENPT__; +typedef struct { + int format; + FUNC_void_GLenum_const_GLfixed___GENPT__ func; + ARGS_void_GLenum_const_GLfixed___GENPT__ args; +} PACKED_void_GLenum_const_GLfixed___GENPT__; +typedef struct { + int func; + ARGS_void_GLenum_const_GLfixed___GENPT__ args; +} INDEXED_void_GLenum_const_GLfixed___GENPT__; +typedef void (*FUNC_void_GLfloat_GLfloat_GLfloat_GLfloat)(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); +typedef struct { + GLfloat a1; + GLfloat a2; + GLfloat a3; + GLfloat a4; +} ARGS_void_GLfloat_GLfloat_GLfloat_GLfloat; +typedef struct { + int format; + FUNC_void_GLfloat_GLfloat_GLfloat_GLfloat func; + ARGS_void_GLfloat_GLfloat_GLfloat_GLfloat args; +} PACKED_void_GLfloat_GLfloat_GLfloat_GLfloat; +typedef struct { + int func; + ARGS_void_GLfloat_GLfloat_GLfloat_GLfloat args; +} INDEXED_void_GLfloat_GLfloat_GLfloat_GLfloat; +typedef void (*FUNC_void_GLubyte_GLubyte_GLubyte_GLubyte)(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha); +typedef struct { + GLubyte a1; + GLubyte a2; + GLubyte a3; + GLubyte a4; +} ARGS_void_GLubyte_GLubyte_GLubyte_GLubyte; +typedef struct { + int format; + FUNC_void_GLubyte_GLubyte_GLubyte_GLubyte func; + ARGS_void_GLubyte_GLubyte_GLubyte_GLubyte args; +} PACKED_void_GLubyte_GLubyte_GLubyte_GLubyte; +typedef struct { + int func; + ARGS_void_GLubyte_GLubyte_GLubyte_GLubyte args; +} INDEXED_void_GLubyte_GLubyte_GLubyte_GLubyte; +typedef void (*FUNC_void_GLfixed_GLfixed_GLfixed_GLfixed)(GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha); +typedef struct { + GLfixed a1; + GLfixed a2; + GLfixed a3; + GLfixed a4; +} ARGS_void_GLfixed_GLfixed_GLfixed_GLfixed; +typedef struct { + int format; + FUNC_void_GLfixed_GLfixed_GLfixed_GLfixed func; + ARGS_void_GLfixed_GLfixed_GLfixed_GLfixed args; +} PACKED_void_GLfixed_GLfixed_GLfixed_GLfixed; +typedef struct { + int func; + ARGS_void_GLfixed_GLfixed_GLfixed_GLfixed args; +} INDEXED_void_GLfixed_GLfixed_GLfixed_GLfixed; +typedef void (*FUNC_void_GLboolean_GLboolean_GLboolean_GLboolean)(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha); +typedef struct { + GLboolean a1; + GLboolean a2; + GLboolean a3; + GLboolean a4; +} ARGS_void_GLboolean_GLboolean_GLboolean_GLboolean; +typedef struct { + int format; + FUNC_void_GLboolean_GLboolean_GLboolean_GLboolean func; + ARGS_void_GLboolean_GLboolean_GLboolean_GLboolean args; +} PACKED_void_GLboolean_GLboolean_GLboolean_GLboolean; +typedef struct { + int func; + ARGS_void_GLboolean_GLboolean_GLboolean_GLboolean args; +} INDEXED_void_GLboolean_GLboolean_GLboolean_GLboolean; +typedef void (*FUNC_void_GLint_GLenum_GLsizei_const_GLvoid___GENPT__)(GLint size, GLenum type, GLsizei stride, const GLvoid * pointer); +typedef struct { + GLint a1; + GLenum a2; + GLsizei a3; + GLvoid * a4; +} ARGS_void_GLint_GLenum_GLsizei_const_GLvoid___GENPT__; +typedef struct { + int format; + FUNC_void_GLint_GLenum_GLsizei_const_GLvoid___GENPT__ func; + ARGS_void_GLint_GLenum_GLsizei_const_GLvoid___GENPT__ args; +} PACKED_void_GLint_GLenum_GLsizei_const_GLvoid___GENPT__; +typedef struct { + int func; + ARGS_void_GLint_GLenum_GLsizei_const_GLvoid___GENPT__ args; +} INDEXED_void_GLint_GLenum_GLsizei_const_GLvoid___GENPT__; +typedef void (*FUNC_void_GLuint)(GLuint shader); +typedef struct { + GLuint a1; +} ARGS_void_GLuint; +typedef struct { + int format; + FUNC_void_GLuint func; + ARGS_void_GLuint args; +} PACKED_void_GLuint; +typedef struct { + int func; + ARGS_void_GLuint args; +} INDEXED_void_GLuint; +typedef void (*FUNC_void_GLenum_GLint_GLenum_GLsizei_GLsizei_GLint_GLsizei_const_GLvoid___GENPT__)(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid * data); +typedef struct { + GLenum a1; + GLint a2; + GLenum a3; + GLsizei a4; + GLsizei a5; + GLint a6; + GLsizei a7; + GLvoid * a8; +} ARGS_void_GLenum_GLint_GLenum_GLsizei_GLsizei_GLint_GLsizei_const_GLvoid___GENPT__; +typedef struct { + int format; + FUNC_void_GLenum_GLint_GLenum_GLsizei_GLsizei_GLint_GLsizei_const_GLvoid___GENPT__ func; + ARGS_void_GLenum_GLint_GLenum_GLsizei_GLsizei_GLint_GLsizei_const_GLvoid___GENPT__ args; +} PACKED_void_GLenum_GLint_GLenum_GLsizei_GLsizei_GLint_GLsizei_const_GLvoid___GENPT__; +typedef struct { + int func; + ARGS_void_GLenum_GLint_GLenum_GLsizei_GLsizei_GLint_GLsizei_const_GLvoid___GENPT__ args; +} INDEXED_void_GLenum_GLint_GLenum_GLsizei_GLsizei_GLint_GLsizei_const_GLvoid___GENPT__; +typedef void (*FUNC_void_GLenum_GLint_GLint_GLint_GLsizei_GLsizei_GLenum_GLsizei_const_GLvoid___GENPT__)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid * data); +typedef struct { + GLenum a1; + GLint a2; + GLint a3; + GLint a4; + GLsizei a5; + GLsizei a6; + GLenum a7; + GLsizei a8; + GLvoid * a9; +} ARGS_void_GLenum_GLint_GLint_GLint_GLsizei_GLsizei_GLenum_GLsizei_const_GLvoid___GENPT__; +typedef struct { + int format; + FUNC_void_GLenum_GLint_GLint_GLint_GLsizei_GLsizei_GLenum_GLsizei_const_GLvoid___GENPT__ func; + ARGS_void_GLenum_GLint_GLint_GLint_GLsizei_GLsizei_GLenum_GLsizei_const_GLvoid___GENPT__ args; +} PACKED_void_GLenum_GLint_GLint_GLint_GLsizei_GLsizei_GLenum_GLsizei_const_GLvoid___GENPT__; +typedef struct { + int func; + ARGS_void_GLenum_GLint_GLint_GLint_GLsizei_GLsizei_GLenum_GLsizei_const_GLvoid___GENPT__ args; +} INDEXED_void_GLenum_GLint_GLint_GLint_GLsizei_GLsizei_GLenum_GLsizei_const_GLvoid___GENPT__; +typedef void (*FUNC_void_GLenum_GLint_GLenum_GLint_GLint_GLsizei_GLsizei_GLint)(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border); +typedef struct { + GLenum a1; + GLint a2; + GLenum a3; + GLint a4; + GLint a5; + GLsizei a6; + GLsizei a7; + GLint a8; +} ARGS_void_GLenum_GLint_GLenum_GLint_GLint_GLsizei_GLsizei_GLint; +typedef struct { + int format; + FUNC_void_GLenum_GLint_GLenum_GLint_GLint_GLsizei_GLsizei_GLint func; + ARGS_void_GLenum_GLint_GLenum_GLint_GLint_GLsizei_GLsizei_GLint args; +} PACKED_void_GLenum_GLint_GLenum_GLint_GLint_GLsizei_GLsizei_GLint; +typedef struct { + int func; + ARGS_void_GLenum_GLint_GLenum_GLint_GLint_GLsizei_GLsizei_GLint args; +} INDEXED_void_GLenum_GLint_GLenum_GLint_GLint_GLsizei_GLsizei_GLint; +typedef void (*FUNC_void_GLenum_GLint_GLint_GLint_GLint_GLint_GLsizei_GLsizei)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height); +typedef struct { + GLenum a1; + GLint a2; + GLint a3; + GLint a4; + GLint a5; + GLint a6; + GLsizei a7; + GLsizei a8; +} ARGS_void_GLenum_GLint_GLint_GLint_GLint_GLint_GLsizei_GLsizei; +typedef struct { + int format; + FUNC_void_GLenum_GLint_GLint_GLint_GLint_GLint_GLsizei_GLsizei func; + ARGS_void_GLenum_GLint_GLint_GLint_GLint_GLint_GLsizei_GLsizei args; +} PACKED_void_GLenum_GLint_GLint_GLint_GLint_GLint_GLsizei_GLsizei; +typedef struct { + int func; + ARGS_void_GLenum_GLint_GLint_GLint_GLint_GLint_GLsizei_GLsizei args; +} INDEXED_void_GLenum_GLint_GLint_GLint_GLint_GLint_GLsizei_GLsizei; +typedef GLuint (*FUNC_GLuint)(); +typedef struct { + int format; + FUNC_GLuint func; +} PACKED_GLuint; +typedef struct { + int func; +} INDEXED_GLuint; +typedef GLuint (*FUNC_GLuint_GLenum)(GLenum type); +typedef struct { + GLenum a1; +} ARGS_GLuint_GLenum; +typedef struct { + int format; + FUNC_GLuint_GLenum func; + ARGS_GLuint_GLenum args; +} PACKED_GLuint_GLenum; +typedef struct { + int func; + ARGS_GLuint_GLenum args; +} INDEXED_GLuint_GLenum; +typedef void (*FUNC_void_GLsizei_const_GLuint___GENPT__)(GLsizei n, const GLuint * buffer); +typedef struct { + GLsizei a1; + GLuint * a2; +} ARGS_void_GLsizei_const_GLuint___GENPT__; +typedef struct { + int format; + FUNC_void_GLsizei_const_GLuint___GENPT__ func; + ARGS_void_GLsizei_const_GLuint___GENPT__ args; +} PACKED_void_GLsizei_const_GLuint___GENPT__; +typedef struct { + int func; + ARGS_void_GLsizei_const_GLuint___GENPT__ args; +} INDEXED_void_GLsizei_const_GLuint___GENPT__; +typedef void (*FUNC_void_GLsizei_GLuint___GENPT__)(GLsizei n, GLuint * framebuffers); +typedef struct { + GLsizei a1; + GLuint * a2; +} ARGS_void_GLsizei_GLuint___GENPT__; +typedef struct { + int format; + FUNC_void_GLsizei_GLuint___GENPT__ func; + ARGS_void_GLsizei_GLuint___GENPT__ args; +} PACKED_void_GLsizei_GLuint___GENPT__; +typedef struct { + int func; + ARGS_void_GLsizei_GLuint___GENPT__ args; +} INDEXED_void_GLsizei_GLuint___GENPT__; +typedef void (*FUNC_void_GLboolean)(GLboolean flag); +typedef struct { + GLboolean a1; +} ARGS_void_GLboolean; +typedef struct { + int format; + FUNC_void_GLboolean func; + ARGS_void_GLboolean args; +} PACKED_void_GLboolean; +typedef struct { + int func; + ARGS_void_GLboolean args; +} INDEXED_void_GLboolean; +typedef void (*FUNC_void_GLclampf_GLclampf)(GLclampf near, GLclampf far); +typedef struct { + GLclampf a1; + GLclampf a2; +} ARGS_void_GLclampf_GLclampf; +typedef struct { + int format; + FUNC_void_GLclampf_GLclampf func; + ARGS_void_GLclampf_GLclampf args; +} PACKED_void_GLclampf_GLclampf; +typedef struct { + int func; + ARGS_void_GLclampf_GLclampf args; +} INDEXED_void_GLclampf_GLclampf; +typedef void (*FUNC_void_GLclampx_GLclampx)(GLclampx near, GLclampx far); +typedef struct { + GLclampx a1; + GLclampx a2; +} ARGS_void_GLclampx_GLclampx; +typedef struct { + int format; + FUNC_void_GLclampx_GLclampx func; + ARGS_void_GLclampx_GLclampx args; +} PACKED_void_GLclampx_GLclampx; +typedef struct { + int func; + ARGS_void_GLclampx_GLclampx args; +} INDEXED_void_GLclampx_GLclampx; +typedef void (*FUNC_void_GLenum_GLint_GLsizei)(GLenum mode, GLint first, GLsizei count); +typedef struct { + GLenum a1; + GLint a2; + GLsizei a3; +} ARGS_void_GLenum_GLint_GLsizei; +typedef struct { + int format; + FUNC_void_GLenum_GLint_GLsizei func; + ARGS_void_GLenum_GLint_GLsizei args; +} PACKED_void_GLenum_GLint_GLsizei; +typedef struct { + int func; + ARGS_void_GLenum_GLint_GLsizei args; +} INDEXED_void_GLenum_GLint_GLsizei; +typedef void (*FUNC_void_GLenum_GLsizei_GLenum_const_GLvoid___GENPT__)(GLenum mode, GLsizei count, GLenum type, const GLvoid * indices); +typedef struct { + GLenum a1; + GLsizei a2; + GLenum a3; + GLvoid * a4; +} ARGS_void_GLenum_GLsizei_GLenum_const_GLvoid___GENPT__; +typedef struct { + int format; + FUNC_void_GLenum_GLsizei_GLenum_const_GLvoid___GENPT__ func; + ARGS_void_GLenum_GLsizei_GLenum_const_GLvoid___GENPT__ args; +} PACKED_void_GLenum_GLsizei_GLenum_const_GLvoid___GENPT__; +typedef struct { + int func; + ARGS_void_GLenum_GLsizei_GLenum_const_GLvoid___GENPT__ args; +} INDEXED_void_GLenum_GLsizei_GLenum_const_GLvoid___GENPT__; +typedef void (*FUNC_void_GLfloat_GLfloat_GLfloat_GLfloat_GLfloat)(GLfloat x, GLfloat y, GLfloat z, GLfloat width, GLfloat height); +typedef struct { + GLfloat a1; + GLfloat a2; + GLfloat a3; + GLfloat a4; + GLfloat a5; +} ARGS_void_GLfloat_GLfloat_GLfloat_GLfloat_GLfloat; +typedef struct { + int format; + FUNC_void_GLfloat_GLfloat_GLfloat_GLfloat_GLfloat func; + ARGS_void_GLfloat_GLfloat_GLfloat_GLfloat_GLfloat args; +} PACKED_void_GLfloat_GLfloat_GLfloat_GLfloat_GLfloat; +typedef struct { + int func; + ARGS_void_GLfloat_GLfloat_GLfloat_GLfloat_GLfloat args; +} INDEXED_void_GLfloat_GLfloat_GLfloat_GLfloat_GLfloat; +typedef void (*FUNC_void_GLint_GLint_GLint_GLint_GLint)(GLint x, GLint y, GLint z, GLint width, GLint height); +typedef struct { + GLint a1; + GLint a2; + GLint a3; + GLint a4; + GLint a5; +} ARGS_void_GLint_GLint_GLint_GLint_GLint; +typedef struct { + int format; + FUNC_void_GLint_GLint_GLint_GLint_GLint func; + ARGS_void_GLint_GLint_GLint_GLint_GLint args; +} PACKED_void_GLint_GLint_GLint_GLint_GLint; +typedef struct { + int func; + ARGS_void_GLint_GLint_GLint_GLint_GLint args; +} INDEXED_void_GLint_GLint_GLint_GLint_GLint; +typedef void (*FUNC_void)(); +typedef struct { + int format; + FUNC_void func; +} PACKED_void; +typedef struct { + int func; +} INDEXED_void; +typedef void (*FUNC_void_GLenum_GLsizei_const_GLvoid___GENPT__)(GLenum type, GLsizei stride, const GLvoid * pointer); +typedef struct { + GLenum a1; + GLsizei a2; + GLvoid * a3; +} ARGS_void_GLenum_GLsizei_const_GLvoid___GENPT__; +typedef struct { + int format; + FUNC_void_GLenum_GLsizei_const_GLvoid___GENPT__ func; + ARGS_void_GLenum_GLsizei_const_GLvoid___GENPT__ args; +} PACKED_void_GLenum_GLsizei_const_GLvoid___GENPT__; +typedef struct { + int func; + ARGS_void_GLenum_GLsizei_const_GLvoid___GENPT__ args; +} INDEXED_void_GLenum_GLsizei_const_GLvoid___GENPT__; +typedef void (*FUNC_void_GLfloat)(GLfloat coord); +typedef struct { + GLfloat a1; +} ARGS_void_GLfloat; +typedef struct { + int format; + FUNC_void_GLfloat func; + ARGS_void_GLfloat args; +} PACKED_void_GLfloat; +typedef struct { + int func; + ARGS_void_GLfloat args; +} INDEXED_void_GLfloat; +typedef void (*FUNC_void_const_GLfloat___GENPT__)(const GLfloat * coord); +typedef struct { + GLfloat * a1; +} ARGS_void_const_GLfloat___GENPT__; +typedef struct { + int format; + FUNC_void_const_GLfloat___GENPT__ func; + ARGS_void_const_GLfloat___GENPT__ args; +} PACKED_void_const_GLfloat___GENPT__; +typedef struct { + int func; + ARGS_void_const_GLfloat___GENPT__ args; +} INDEXED_void_const_GLfloat___GENPT__; +typedef void (*FUNC_void_GLenum_GLfloat)(GLenum pname, GLfloat param); +typedef struct { + GLenum a1; + GLfloat a2; +} ARGS_void_GLenum_GLfloat; +typedef struct { + int format; + FUNC_void_GLenum_GLfloat func; + ARGS_void_GLenum_GLfloat args; +} PACKED_void_GLenum_GLfloat; +typedef struct { + int func; + ARGS_void_GLenum_GLfloat args; +} INDEXED_void_GLenum_GLfloat; +typedef void (*FUNC_void_GLenum_GLfixed)(GLenum pname, GLfixed param); +typedef struct { + GLenum a1; + GLfixed a2; +} ARGS_void_GLenum_GLfixed; +typedef struct { + int format; + FUNC_void_GLenum_GLfixed func; + ARGS_void_GLenum_GLfixed args; +} PACKED_void_GLenum_GLfixed; +typedef struct { + int func; + ARGS_void_GLenum_GLfixed args; +} INDEXED_void_GLenum_GLfixed; +typedef void (*FUNC_void_GLenum_GLenum_GLenum_GLuint)(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer); +typedef struct { + GLenum a1; + GLenum a2; + GLenum a3; + GLuint a4; +} ARGS_void_GLenum_GLenum_GLenum_GLuint; +typedef struct { + int format; + FUNC_void_GLenum_GLenum_GLenum_GLuint func; + ARGS_void_GLenum_GLenum_GLenum_GLuint args; +} PACKED_void_GLenum_GLenum_GLenum_GLuint; +typedef struct { + int func; + ARGS_void_GLenum_GLenum_GLenum_GLuint args; +} INDEXED_void_GLenum_GLenum_GLenum_GLuint; +typedef void (*FUNC_void_GLenum_GLenum_GLenum_GLuint_GLint)(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); +typedef struct { + GLenum a1; + GLenum a2; + GLenum a3; + GLuint a4; + GLint a5; +} ARGS_void_GLenum_GLenum_GLenum_GLuint_GLint; +typedef struct { + int format; + FUNC_void_GLenum_GLenum_GLenum_GLuint_GLint func; + ARGS_void_GLenum_GLenum_GLenum_GLuint_GLint args; +} PACKED_void_GLenum_GLenum_GLenum_GLuint_GLint; +typedef struct { + int func; + ARGS_void_GLenum_GLenum_GLenum_GLuint_GLint args; +} INDEXED_void_GLenum_GLenum_GLenum_GLuint_GLint; +typedef void (*FUNC_void_GLfloat_GLfloat_GLfloat_GLfloat_GLfloat_GLfloat)(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat near, GLfloat far); +typedef struct { + GLfloat a1; + GLfloat a2; + GLfloat a3; + GLfloat a4; + GLfloat a5; + GLfloat a6; +} ARGS_void_GLfloat_GLfloat_GLfloat_GLfloat_GLfloat_GLfloat; +typedef struct { + int format; + FUNC_void_GLfloat_GLfloat_GLfloat_GLfloat_GLfloat_GLfloat func; + ARGS_void_GLfloat_GLfloat_GLfloat_GLfloat_GLfloat_GLfloat args; +} PACKED_void_GLfloat_GLfloat_GLfloat_GLfloat_GLfloat_GLfloat; +typedef struct { + int func; + ARGS_void_GLfloat_GLfloat_GLfloat_GLfloat_GLfloat_GLfloat args; +} INDEXED_void_GLfloat_GLfloat_GLfloat_GLfloat_GLfloat_GLfloat; +typedef void (*FUNC_void_GLfixed_GLfixed_GLfixed_GLfixed_GLfixed_GLfixed)(GLfixed left, GLfixed right, GLfixed bottom, GLfixed top, GLfixed near, GLfixed far); +typedef struct { + GLfixed a1; + GLfixed a2; + GLfixed a3; + GLfixed a4; + GLfixed a5; + GLfixed a6; +} ARGS_void_GLfixed_GLfixed_GLfixed_GLfixed_GLfixed_GLfixed; +typedef struct { + int format; + FUNC_void_GLfixed_GLfixed_GLfixed_GLfixed_GLfixed_GLfixed func; + ARGS_void_GLfixed_GLfixed_GLfixed_GLfixed_GLfixed_GLfixed args; +} PACKED_void_GLfixed_GLfixed_GLfixed_GLfixed_GLfixed_GLfixed; +typedef struct { + int func; + ARGS_void_GLfixed_GLfixed_GLfixed_GLfixed_GLfixed_GLfixed args; +} INDEXED_void_GLfixed_GLfixed_GLfixed_GLfixed_GLfixed_GLfixed; +typedef void (*FUNC_void_GLuint_GLuint_GLsizei_GLsizei___GENPT___GLint___GENPT___GLenum___GENPT___GLchar___GENPT__)(GLuint program, GLuint index, GLsizei bufSize, GLsizei * length, GLint * size, GLenum * type, GLchar * name); +typedef struct { + GLuint a1; + GLuint a2; + GLsizei a3; + GLsizei * a4; + GLint * a5; + GLenum * a6; + GLchar * a7; +} ARGS_void_GLuint_GLuint_GLsizei_GLsizei___GENPT___GLint___GENPT___GLenum___GENPT___GLchar___GENPT__; +typedef struct { + int format; + FUNC_void_GLuint_GLuint_GLsizei_GLsizei___GENPT___GLint___GENPT___GLenum___GENPT___GLchar___GENPT__ func; + ARGS_void_GLuint_GLuint_GLsizei_GLsizei___GENPT___GLint___GENPT___GLenum___GENPT___GLchar___GENPT__ args; +} PACKED_void_GLuint_GLuint_GLsizei_GLsizei___GENPT___GLint___GENPT___GLenum___GENPT___GLchar___GENPT__; +typedef struct { + int func; + ARGS_void_GLuint_GLuint_GLsizei_GLsizei___GENPT___GLint___GENPT___GLenum___GENPT___GLchar___GENPT__ args; +} INDEXED_void_GLuint_GLuint_GLsizei_GLsizei___GENPT___GLint___GENPT___GLenum___GENPT___GLchar___GENPT__; +typedef void (*FUNC_void_GLuint_GLsizei_GLsizei___GENPT___GLuint___GENPT__)(GLuint program, GLsizei maxCount, GLsizei * count, GLuint * obj); +typedef struct { + GLuint a1; + GLsizei a2; + GLsizei * a3; + GLuint * a4; +} ARGS_void_GLuint_GLsizei_GLsizei___GENPT___GLuint___GENPT__; +typedef struct { + int format; + FUNC_void_GLuint_GLsizei_GLsizei___GENPT___GLuint___GENPT__ func; + ARGS_void_GLuint_GLsizei_GLsizei___GENPT___GLuint___GENPT__ args; +} PACKED_void_GLuint_GLsizei_GLsizei___GENPT___GLuint___GENPT__; +typedef struct { + int func; + ARGS_void_GLuint_GLsizei_GLsizei___GENPT___GLuint___GENPT__ args; +} INDEXED_void_GLuint_GLsizei_GLsizei___GENPT___GLuint___GENPT__; +typedef GLint (*FUNC_GLint_GLuint_const_GLchar___GENPT__)(GLuint program, const GLchar * name); +typedef struct { + GLuint a1; + GLchar * a2; +} ARGS_GLint_GLuint_const_GLchar___GENPT__; +typedef struct { + int format; + FUNC_GLint_GLuint_const_GLchar___GENPT__ func; + ARGS_GLint_GLuint_const_GLchar___GENPT__ args; +} PACKED_GLint_GLuint_const_GLchar___GENPT__; +typedef struct { + int func; + ARGS_GLint_GLuint_const_GLchar___GENPT__ args; +} INDEXED_GLint_GLuint_const_GLchar___GENPT__; +typedef void (*FUNC_void_GLenum_GLboolean___GENPT__)(GLenum pname, GLboolean * params); +typedef struct { + GLenum a1; + GLboolean * a2; +} ARGS_void_GLenum_GLboolean___GENPT__; +typedef struct { + int format; + FUNC_void_GLenum_GLboolean___GENPT__ func; + ARGS_void_GLenum_GLboolean___GENPT__ args; +} PACKED_void_GLenum_GLboolean___GENPT__; +typedef struct { + int func; + ARGS_void_GLenum_GLboolean___GENPT__ args; +} INDEXED_void_GLenum_GLboolean___GENPT__; +typedef void (*FUNC_void_GLenum_GLenum_GLint___GENPT__)(GLenum target, GLenum pname, GLint * params); +typedef struct { + GLenum a1; + GLenum a2; + GLint * a3; +} ARGS_void_GLenum_GLenum_GLint___GENPT__; +typedef struct { + int format; + FUNC_void_GLenum_GLenum_GLint___GENPT__ func; + ARGS_void_GLenum_GLenum_GLint___GENPT__ args; +} PACKED_void_GLenum_GLenum_GLint___GENPT__; +typedef struct { + int func; + ARGS_void_GLenum_GLenum_GLint___GENPT__ args; +} INDEXED_void_GLenum_GLenum_GLint___GENPT__; +typedef void (*FUNC_void_GLenum_GLfloat___GENPT__)(GLenum plane, GLfloat * equation); +typedef struct { + GLenum a1; + GLfloat * a2; +} ARGS_void_GLenum_GLfloat___GENPT__; +typedef struct { + int format; + FUNC_void_GLenum_GLfloat___GENPT__ func; + ARGS_void_GLenum_GLfloat___GENPT__ args; +} PACKED_void_GLenum_GLfloat___GENPT__; +typedef struct { + int func; + ARGS_void_GLenum_GLfloat___GENPT__ args; +} INDEXED_void_GLenum_GLfloat___GENPT__; +typedef void (*FUNC_void_GLenum_GLfixed___GENPT__)(GLenum plane, GLfixed * equation); +typedef struct { + GLenum a1; + GLfixed * a2; +} ARGS_void_GLenum_GLfixed___GENPT__; +typedef struct { + int format; + FUNC_void_GLenum_GLfixed___GENPT__ func; + ARGS_void_GLenum_GLfixed___GENPT__ args; +} PACKED_void_GLenum_GLfixed___GENPT__; +typedef struct { + int func; + ARGS_void_GLenum_GLfixed___GENPT__ args; +} INDEXED_void_GLenum_GLfixed___GENPT__; +typedef GLenum (*FUNC_GLenum)(); +typedef struct { + int format; + FUNC_GLenum func; +} PACKED_GLenum; +typedef struct { + int func; +} INDEXED_GLenum; +typedef void (*FUNC_void_GLenum_GLenum_GLenum_GLint___GENPT__)(GLenum target, GLenum attachment, GLenum pname, GLint * params); +typedef struct { + GLenum a1; + GLenum a2; + GLenum a3; + GLint * a4; +} ARGS_void_GLenum_GLenum_GLenum_GLint___GENPT__; +typedef struct { + int format; + FUNC_void_GLenum_GLenum_GLenum_GLint___GENPT__ func; + ARGS_void_GLenum_GLenum_GLenum_GLint___GENPT__ args; +} PACKED_void_GLenum_GLenum_GLenum_GLint___GENPT__; +typedef struct { + int func; + ARGS_void_GLenum_GLenum_GLenum_GLint___GENPT__ args; +} INDEXED_void_GLenum_GLenum_GLenum_GLint___GENPT__; +typedef void (*FUNC_void_GLenum_GLint___GENPT__)(GLenum pname, GLint * params); +typedef struct { + GLenum a1; + GLint * a2; +} ARGS_void_GLenum_GLint___GENPT__; +typedef struct { + int format; + FUNC_void_GLenum_GLint___GENPT__ func; + ARGS_void_GLenum_GLint___GENPT__ args; +} PACKED_void_GLenum_GLint___GENPT__; +typedef struct { + int func; + ARGS_void_GLenum_GLint___GENPT__ args; +} INDEXED_void_GLenum_GLint___GENPT__; +typedef void (*FUNC_void_GLenum_GLenum_GLfloat___GENPT__)(GLenum light, GLenum pname, GLfloat * params); +typedef struct { + GLenum a1; + GLenum a2; + GLfloat * a3; +} ARGS_void_GLenum_GLenum_GLfloat___GENPT__; +typedef struct { + int format; + FUNC_void_GLenum_GLenum_GLfloat___GENPT__ func; + ARGS_void_GLenum_GLenum_GLfloat___GENPT__ args; +} PACKED_void_GLenum_GLenum_GLfloat___GENPT__; +typedef struct { + int func; + ARGS_void_GLenum_GLenum_GLfloat___GENPT__ args; +} INDEXED_void_GLenum_GLenum_GLfloat___GENPT__; +typedef void (*FUNC_void_GLenum_GLenum_GLfixed___GENPT__)(GLenum light, GLenum pname, GLfixed * params); +typedef struct { + GLenum a1; + GLenum a2; + GLfixed * a3; +} ARGS_void_GLenum_GLenum_GLfixed___GENPT__; +typedef struct { + int format; + FUNC_void_GLenum_GLenum_GLfixed___GENPT__ func; + ARGS_void_GLenum_GLenum_GLfixed___GENPT__ args; +} PACKED_void_GLenum_GLenum_GLfixed___GENPT__; +typedef struct { + int func; + ARGS_void_GLenum_GLenum_GLfixed___GENPT__ args; +} INDEXED_void_GLenum_GLenum_GLfixed___GENPT__; +typedef void (*FUNC_void_GLenum_GLvoid___GENPT____GENPT__)(GLenum pname, GLvoid ** params); +typedef struct { + GLenum a1; + GLvoid ** a2; +} ARGS_void_GLenum_GLvoid___GENPT____GENPT__; +typedef struct { + int format; + FUNC_void_GLenum_GLvoid___GENPT____GENPT__ func; + ARGS_void_GLenum_GLvoid___GENPT____GENPT__ args; +} PACKED_void_GLenum_GLvoid___GENPT____GENPT__; +typedef struct { + int func; + ARGS_void_GLenum_GLvoid___GENPT____GENPT__ args; +} INDEXED_void_GLenum_GLvoid___GENPT____GENPT__; +typedef void (*FUNC_void_GLuint_GLsizei_GLsizei___GENPT___GLchar___GENPT__)(GLuint program, GLsizei bufSize, GLsizei * length, GLchar * infoLog); +typedef struct { + GLuint a1; + GLsizei a2; + GLsizei * a3; + GLchar * a4; +} ARGS_void_GLuint_GLsizei_GLsizei___GENPT___GLchar___GENPT__; +typedef struct { + int format; + FUNC_void_GLuint_GLsizei_GLsizei___GENPT___GLchar___GENPT__ func; + ARGS_void_GLuint_GLsizei_GLsizei___GENPT___GLchar___GENPT__ args; +} PACKED_void_GLuint_GLsizei_GLsizei___GENPT___GLchar___GENPT__; +typedef struct { + int func; + ARGS_void_GLuint_GLsizei_GLsizei___GENPT___GLchar___GENPT__ args; +} INDEXED_void_GLuint_GLsizei_GLsizei___GENPT___GLchar___GENPT__; +typedef void (*FUNC_void_GLuint_GLenum_GLint___GENPT__)(GLuint program, GLenum pname, GLint * params); +typedef struct { + GLuint a1; + GLenum a2; + GLint * a3; +} ARGS_void_GLuint_GLenum_GLint___GENPT__; +typedef struct { + int format; + FUNC_void_GLuint_GLenum_GLint___GENPT__ func; + ARGS_void_GLuint_GLenum_GLint___GENPT__ args; +} PACKED_void_GLuint_GLenum_GLint___GENPT__; +typedef struct { + int func; + ARGS_void_GLuint_GLenum_GLint___GENPT__ args; +} INDEXED_void_GLuint_GLenum_GLint___GENPT__; +typedef void (*FUNC_void_GLenum_GLenum_GLint___GENPT___GLint___GENPT__)(GLenum shadertype, GLenum precisiontype, GLint * range, GLint * precision); +typedef struct { + GLenum a1; + GLenum a2; + GLint * a3; + GLint * a4; +} ARGS_void_GLenum_GLenum_GLint___GENPT___GLint___GENPT__; +typedef struct { + int format; + FUNC_void_GLenum_GLenum_GLint___GENPT___GLint___GENPT__ func; + ARGS_void_GLenum_GLenum_GLint___GENPT___GLint___GENPT__ args; +} PACKED_void_GLenum_GLenum_GLint___GENPT___GLint___GENPT__; +typedef struct { + int func; + ARGS_void_GLenum_GLenum_GLint___GENPT___GLint___GENPT__ args; +} INDEXED_void_GLenum_GLenum_GLint___GENPT___GLint___GENPT__; +typedef const GLubyte * (*FUNC_const_GLubyte___GENPT___GLenum)(GLenum name); +typedef struct { + GLenum a1; +} ARGS_const_GLubyte___GENPT___GLenum; +typedef struct { + int format; + FUNC_const_GLubyte___GENPT___GLenum func; + ARGS_const_GLubyte___GENPT___GLenum args; +} PACKED_const_GLubyte___GENPT___GLenum; +typedef struct { + int func; + ARGS_const_GLubyte___GENPT___GLenum args; +} INDEXED_const_GLubyte___GENPT___GLenum; +typedef void (*FUNC_void_GLuint_GLint_GLfloat___GENPT__)(GLuint program, GLint location, GLfloat * params); +typedef struct { + GLuint a1; + GLint a2; + GLfloat * a3; +} ARGS_void_GLuint_GLint_GLfloat___GENPT__; +typedef struct { + int format; + FUNC_void_GLuint_GLint_GLfloat___GENPT__ func; + ARGS_void_GLuint_GLint_GLfloat___GENPT__ args; +} PACKED_void_GLuint_GLint_GLfloat___GENPT__; +typedef struct { + int func; + ARGS_void_GLuint_GLint_GLfloat___GENPT__ args; +} INDEXED_void_GLuint_GLint_GLfloat___GENPT__; +typedef void (*FUNC_void_GLuint_GLint_GLint___GENPT__)(GLuint program, GLint location, GLint * params); +typedef struct { + GLuint a1; + GLint a2; + GLint * a3; +} ARGS_void_GLuint_GLint_GLint___GENPT__; +typedef struct { + int format; + FUNC_void_GLuint_GLint_GLint___GENPT__ func; + ARGS_void_GLuint_GLint_GLint___GENPT__ args; +} PACKED_void_GLuint_GLint_GLint___GENPT__; +typedef struct { + int func; + ARGS_void_GLuint_GLint_GLint___GENPT__ args; +} INDEXED_void_GLuint_GLint_GLint___GENPT__; +typedef void (*FUNC_void_GLuint_GLenum_GLvoid___GENPT____GENPT__)(GLuint index, GLenum pname, GLvoid ** pointer); +typedef struct { + GLuint a1; + GLenum a2; + GLvoid ** a3; +} ARGS_void_GLuint_GLenum_GLvoid___GENPT____GENPT__; +typedef struct { + int format; + FUNC_void_GLuint_GLenum_GLvoid___GENPT____GENPT__ func; + ARGS_void_GLuint_GLenum_GLvoid___GENPT____GENPT__ args; +} PACKED_void_GLuint_GLenum_GLvoid___GENPT____GENPT__; +typedef struct { + int func; + ARGS_void_GLuint_GLenum_GLvoid___GENPT____GENPT__ args; +} INDEXED_void_GLuint_GLenum_GLvoid___GENPT____GENPT__; +typedef void (*FUNC_void_GLuint_GLenum_GLfloat___GENPT__)(GLuint index, GLenum pname, GLfloat * params); +typedef struct { + GLuint a1; + GLenum a2; + GLfloat * a3; +} ARGS_void_GLuint_GLenum_GLfloat___GENPT__; +typedef struct { + int format; + FUNC_void_GLuint_GLenum_GLfloat___GENPT__ func; + ARGS_void_GLuint_GLenum_GLfloat___GENPT__ args; +} PACKED_void_GLuint_GLenum_GLfloat___GENPT__; +typedef struct { + int func; + ARGS_void_GLuint_GLenum_GLfloat___GENPT__ args; +} INDEXED_void_GLuint_GLenum_GLfloat___GENPT__; +typedef GLboolean (*FUNC_GLboolean_GLuint)(GLuint buffer); +typedef struct { + GLuint a1; +} ARGS_GLboolean_GLuint; +typedef struct { + int format; + FUNC_GLboolean_GLuint func; + ARGS_GLboolean_GLuint args; +} PACKED_GLboolean_GLuint; +typedef struct { + int func; + ARGS_GLboolean_GLuint args; +} INDEXED_GLboolean_GLuint; +typedef GLboolean (*FUNC_GLboolean_GLenum)(GLenum cap); +typedef struct { + GLenum a1; +} ARGS_GLboolean_GLenum; +typedef struct { + int format; + FUNC_GLboolean_GLenum func; + ARGS_GLboolean_GLenum args; +} PACKED_GLboolean_GLenum; +typedef struct { + int func; + ARGS_GLboolean_GLenum args; +} INDEXED_GLboolean_GLenum; +typedef void (*FUNC_void_GLenum_GLenum_GLfloat)(GLenum light, GLenum pname, GLfloat param); +typedef struct { + GLenum a1; + GLenum a2; + GLfloat a3; +} ARGS_void_GLenum_GLenum_GLfloat; +typedef struct { + int format; + FUNC_void_GLenum_GLenum_GLfloat func; + ARGS_void_GLenum_GLenum_GLfloat args; +} PACKED_void_GLenum_GLenum_GLfloat; +typedef struct { + int func; + ARGS_void_GLenum_GLenum_GLfloat args; +} INDEXED_void_GLenum_GLenum_GLfloat; +typedef void (*FUNC_void_GLenum_GLenum_const_GLfloat___GENPT__)(GLenum light, GLenum pname, const GLfloat * params); +typedef struct { + GLenum a1; + GLenum a2; + GLfloat * a3; +} ARGS_void_GLenum_GLenum_const_GLfloat___GENPT__; +typedef struct { + int format; + FUNC_void_GLenum_GLenum_const_GLfloat___GENPT__ func; + ARGS_void_GLenum_GLenum_const_GLfloat___GENPT__ args; +} PACKED_void_GLenum_GLenum_const_GLfloat___GENPT__; +typedef struct { + int func; + ARGS_void_GLenum_GLenum_const_GLfloat___GENPT__ args; +} INDEXED_void_GLenum_GLenum_const_GLfloat___GENPT__; +typedef void (*FUNC_void_GLenum_GLenum_GLfixed)(GLenum light, GLenum pname, GLfixed param); +typedef struct { + GLenum a1; + GLenum a2; + GLfixed a3; +} ARGS_void_GLenum_GLenum_GLfixed; +typedef struct { + int format; + FUNC_void_GLenum_GLenum_GLfixed func; + ARGS_void_GLenum_GLenum_GLfixed args; +} PACKED_void_GLenum_GLenum_GLfixed; +typedef struct { + int func; + ARGS_void_GLenum_GLenum_GLfixed args; +} INDEXED_void_GLenum_GLenum_GLfixed; +typedef void (*FUNC_void_GLenum_GLenum_const_GLfixed___GENPT__)(GLenum light, GLenum pname, const GLfixed * params); +typedef struct { + GLenum a1; + GLenum a2; + GLfixed * a3; +} ARGS_void_GLenum_GLenum_const_GLfixed___GENPT__; +typedef struct { + int format; + FUNC_void_GLenum_GLenum_const_GLfixed___GENPT__ func; + ARGS_void_GLenum_GLenum_const_GLfixed___GENPT__ args; +} PACKED_void_GLenum_GLenum_const_GLfixed___GENPT__; +typedef struct { + int func; + ARGS_void_GLenum_GLenum_const_GLfixed___GENPT__ args; +} INDEXED_void_GLenum_GLenum_const_GLfixed___GENPT__; +typedef void (*FUNC_void_GLfixed)(GLfixed width); +typedef struct { + GLfixed a1; +} ARGS_void_GLfixed; +typedef struct { + int format; + FUNC_void_GLfixed func; + ARGS_void_GLfixed args; +} PACKED_void_GLfixed; +typedef struct { + int func; + ARGS_void_GLfixed args; +} INDEXED_void_GLfixed; +typedef void (*FUNC_void_const_GLfixed___GENPT__)(const GLfixed * m); +typedef struct { + GLfixed * a1; +} ARGS_void_const_GLfixed___GENPT__; +typedef struct { + int format; + FUNC_void_const_GLfixed___GENPT__ func; + ARGS_void_const_GLfixed___GENPT__ args; +} PACKED_void_const_GLfixed___GENPT__; +typedef struct { + int func; + ARGS_void_const_GLfixed___GENPT__ args; +} INDEXED_void_const_GLfixed___GENPT__; +typedef void (*FUNC_void_GLenum_const_GLint___GENPT___const_GLsizei___GENPT___GLsizei)(GLenum mode, const GLint * first, const GLsizei * count, GLsizei primcount); +typedef struct { + GLenum a1; + GLint * a2; + GLsizei * a3; + GLsizei a4; +} ARGS_void_GLenum_const_GLint___GENPT___const_GLsizei___GENPT___GLsizei; +typedef struct { + int format; + FUNC_void_GLenum_const_GLint___GENPT___const_GLsizei___GENPT___GLsizei func; + ARGS_void_GLenum_const_GLint___GENPT___const_GLsizei___GENPT___GLsizei args; +} PACKED_void_GLenum_const_GLint___GENPT___const_GLsizei___GENPT___GLsizei; +typedef struct { + int func; + ARGS_void_GLenum_const_GLint___GENPT___const_GLsizei___GENPT___GLsizei args; +} INDEXED_void_GLenum_const_GLint___GENPT___const_GLsizei___GENPT___GLsizei; +typedef void (*FUNC_void_GLenum_GLsizei___GENPT___GLenum_const_void___GENPT___const___GENPT___GLsizei)(GLenum mode, GLsizei * count, GLenum type, const void * const * indices, GLsizei primcount); +typedef struct { + GLenum a1; + GLsizei * a2; + GLenum a3; + const void * const * a4; + GLsizei a5; +} ARGS_void_GLenum_GLsizei___GENPT___GLenum_const_void___GENPT___const___GENPT___GLsizei; +typedef struct { + int format; + FUNC_void_GLenum_GLsizei___GENPT___GLenum_const_void___GENPT___const___GENPT___GLsizei func; + ARGS_void_GLenum_GLsizei___GENPT___GLenum_const_void___GENPT___const___GENPT___GLsizei args; +} PACKED_void_GLenum_GLsizei___GENPT___GLenum_const_void___GENPT___const___GENPT___GLsizei; +typedef struct { + int func; + ARGS_void_GLenum_GLsizei___GENPT___GLenum_const_void___GENPT___const___GENPT___GLsizei args; +} INDEXED_void_GLenum_GLsizei___GENPT___GLenum_const_void___GENPT___const___GENPT___GLsizei; +typedef void (*FUNC_void_GLenum_GLfloat_GLfloat_GLfloat_GLfloat)(GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q); +typedef struct { + GLenum a1; + GLfloat a2; + GLfloat a3; + GLfloat a4; + GLfloat a5; +} ARGS_void_GLenum_GLfloat_GLfloat_GLfloat_GLfloat; +typedef struct { + int format; + FUNC_void_GLenum_GLfloat_GLfloat_GLfloat_GLfloat func; + ARGS_void_GLenum_GLfloat_GLfloat_GLfloat_GLfloat args; +} PACKED_void_GLenum_GLfloat_GLfloat_GLfloat_GLfloat; +typedef struct { + int func; + ARGS_void_GLenum_GLfloat_GLfloat_GLfloat_GLfloat args; +} INDEXED_void_GLenum_GLfloat_GLfloat_GLfloat_GLfloat; +typedef void (*FUNC_void_GLenum_GLfixed_GLfixed_GLfixed_GLfixed)(GLenum target, GLfixed s, GLfixed t, GLfixed r, GLfixed q); +typedef struct { + GLenum a1; + GLfixed a2; + GLfixed a3; + GLfixed a4; + GLfixed a5; +} ARGS_void_GLenum_GLfixed_GLfixed_GLfixed_GLfixed; +typedef struct { + int format; + FUNC_void_GLenum_GLfixed_GLfixed_GLfixed_GLfixed func; + ARGS_void_GLenum_GLfixed_GLfixed_GLfixed_GLfixed args; +} PACKED_void_GLenum_GLfixed_GLfixed_GLfixed_GLfixed; +typedef struct { + int func; + ARGS_void_GLenum_GLfixed_GLfixed_GLfixed_GLfixed args; +} INDEXED_void_GLenum_GLfixed_GLfixed_GLfixed_GLfixed; +typedef void (*FUNC_void_GLfloat_GLfloat_GLfloat)(GLfloat nx, GLfloat ny, GLfloat nz); +typedef struct { + GLfloat a1; + GLfloat a2; + GLfloat a3; +} ARGS_void_GLfloat_GLfloat_GLfloat; +typedef struct { + int format; + FUNC_void_GLfloat_GLfloat_GLfloat func; + ARGS_void_GLfloat_GLfloat_GLfloat args; +} PACKED_void_GLfloat_GLfloat_GLfloat; +typedef struct { + int func; + ARGS_void_GLfloat_GLfloat_GLfloat args; +} INDEXED_void_GLfloat_GLfloat_GLfloat; +typedef void (*FUNC_void_GLfixed_GLfixed_GLfixed)(GLfixed nx, GLfixed ny, GLfixed nz); +typedef struct { + GLfixed a1; + GLfixed a2; + GLfixed a3; +} ARGS_void_GLfixed_GLfixed_GLfixed; +typedef struct { + int format; + FUNC_void_GLfixed_GLfixed_GLfixed func; + ARGS_void_GLfixed_GLfixed_GLfixed args; +} PACKED_void_GLfixed_GLfixed_GLfixed; +typedef struct { + int func; + ARGS_void_GLfixed_GLfixed_GLfixed args; +} INDEXED_void_GLfixed_GLfixed_GLfixed; +typedef void (*FUNC_void_GLenum_GLint)(GLenum pname, GLint param); +typedef struct { + GLenum a1; + GLint a2; +} ARGS_void_GLenum_GLint; +typedef struct { + int format; + FUNC_void_GLenum_GLint func; + ARGS_void_GLenum_GLint args; +} PACKED_void_GLenum_GLint; +typedef struct { + int func; + ARGS_void_GLenum_GLint args; +} INDEXED_void_GLenum_GLint; +typedef void (*FUNC_void_GLfloat_GLfloat)(GLfloat factor, GLfloat units); +typedef struct { + GLfloat a1; + GLfloat a2; +} ARGS_void_GLfloat_GLfloat; +typedef struct { + int format; + FUNC_void_GLfloat_GLfloat func; + ARGS_void_GLfloat_GLfloat args; +} PACKED_void_GLfloat_GLfloat; +typedef struct { + int func; + ARGS_void_GLfloat_GLfloat args; +} INDEXED_void_GLfloat_GLfloat; +typedef void (*FUNC_void_GLfixed_GLfixed)(GLfixed factor, GLfixed units); +typedef struct { + GLfixed a1; + GLfixed a2; +} ARGS_void_GLfixed_GLfixed; +typedef struct { + int format; + FUNC_void_GLfixed_GLfixed func; + ARGS_void_GLfixed_GLfixed args; +} PACKED_void_GLfixed_GLfixed; +typedef struct { + int func; + ARGS_void_GLfixed_GLfixed args; +} INDEXED_void_GLfixed_GLfixed; +typedef void (*FUNC_void_GLint_GLint_GLsizei_GLsizei_GLenum_GLenum_GLvoid___GENPT__)(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid * pixels); +typedef struct { + GLint a1; + GLint a2; + GLsizei a3; + GLsizei a4; + GLenum a5; + GLenum a6; + GLvoid * a7; +} ARGS_void_GLint_GLint_GLsizei_GLsizei_GLenum_GLenum_GLvoid___GENPT__; +typedef struct { + int format; + FUNC_void_GLint_GLint_GLsizei_GLsizei_GLenum_GLenum_GLvoid___GENPT__ func; + ARGS_void_GLint_GLint_GLsizei_GLsizei_GLenum_GLenum_GLvoid___GENPT__ args; +} PACKED_void_GLint_GLint_GLsizei_GLsizei_GLenum_GLenum_GLvoid___GENPT__; +typedef struct { + int func; + ARGS_void_GLint_GLint_GLsizei_GLsizei_GLenum_GLenum_GLvoid___GENPT__ args; +} INDEXED_void_GLint_GLint_GLsizei_GLsizei_GLenum_GLenum_GLvoid___GENPT__; +typedef void (*FUNC_void_GLenum_GLenum_GLsizei_GLsizei)(GLenum target, GLenum internalformat, GLsizei width, GLsizei height); +typedef struct { + GLenum a1; + GLenum a2; + GLsizei a3; + GLsizei a4; +} ARGS_void_GLenum_GLenum_GLsizei_GLsizei; +typedef struct { + int format; + FUNC_void_GLenum_GLenum_GLsizei_GLsizei func; + ARGS_void_GLenum_GLenum_GLsizei_GLsizei args; +} PACKED_void_GLenum_GLenum_GLsizei_GLsizei; +typedef struct { + int func; + ARGS_void_GLenum_GLenum_GLsizei_GLsizei args; +} INDEXED_void_GLenum_GLenum_GLsizei_GLsizei; +typedef void (*FUNC_void_GLclampf_GLboolean)(GLclampf value, GLboolean invert); +typedef struct { + GLclampf a1; + GLboolean a2; +} ARGS_void_GLclampf_GLboolean; +typedef struct { + int format; + FUNC_void_GLclampf_GLboolean func; + ARGS_void_GLclampf_GLboolean args; +} PACKED_void_GLclampf_GLboolean; +typedef struct { + int func; + ARGS_void_GLclampf_GLboolean args; +} INDEXED_void_GLclampf_GLboolean; +typedef void (*FUNC_void_GLclampx_GLboolean)(GLclampx value, GLboolean invert); +typedef struct { + GLclampx a1; + GLboolean a2; +} ARGS_void_GLclampx_GLboolean; +typedef struct { + int format; + FUNC_void_GLclampx_GLboolean func; + ARGS_void_GLclampx_GLboolean args; +} PACKED_void_GLclampx_GLboolean; +typedef struct { + int func; + ARGS_void_GLclampx_GLboolean args; +} INDEXED_void_GLclampx_GLboolean; +typedef void (*FUNC_void_GLint_GLint_GLsizei_GLsizei)(GLint x, GLint y, GLsizei width, GLsizei height); +typedef struct { + GLint a1; + GLint a2; + GLsizei a3; + GLsizei a4; +} ARGS_void_GLint_GLint_GLsizei_GLsizei; +typedef struct { + int format; + FUNC_void_GLint_GLint_GLsizei_GLsizei func; + ARGS_void_GLint_GLint_GLsizei_GLsizei args; +} PACKED_void_GLint_GLint_GLsizei_GLsizei; +typedef struct { + int func; + ARGS_void_GLint_GLint_GLsizei_GLsizei args; +} INDEXED_void_GLint_GLint_GLsizei_GLsizei; +typedef void (*FUNC_void_GLsizei_const_GLuint___GENPT___GLenum_const_GLvoid___GENPT___GLsizei)(GLsizei n, const GLuint * shaders, GLenum binaryformat, const GLvoid * binary, GLsizei length); +typedef struct { + GLsizei a1; + GLuint * a2; + GLenum a3; + GLvoid * a4; + GLsizei a5; +} ARGS_void_GLsizei_const_GLuint___GENPT___GLenum_const_GLvoid___GENPT___GLsizei; +typedef struct { + int format; + FUNC_void_GLsizei_const_GLuint___GENPT___GLenum_const_GLvoid___GENPT___GLsizei func; + ARGS_void_GLsizei_const_GLuint___GENPT___GLenum_const_GLvoid___GENPT___GLsizei args; +} PACKED_void_GLsizei_const_GLuint___GENPT___GLenum_const_GLvoid___GENPT___GLsizei; +typedef struct { + int func; + ARGS_void_GLsizei_const_GLuint___GENPT___GLenum_const_GLvoid___GENPT___GLsizei args; +} INDEXED_void_GLsizei_const_GLuint___GENPT___GLenum_const_GLvoid___GENPT___GLsizei; +typedef void (*FUNC_void_GLuint_GLsizei_const_GLchar___GENPT___const___GENPT___const_GLint___GENPT__)(GLuint shader, GLsizei count, const GLchar * const * string, const GLint * length); +typedef struct { + GLuint a1; + GLsizei a2; + const GLchar * const * a3; + GLint * a4; +} ARGS_void_GLuint_GLsizei_const_GLchar___GENPT___const___GENPT___const_GLint___GENPT__; +typedef struct { + int format; + FUNC_void_GLuint_GLsizei_const_GLchar___GENPT___const___GENPT___const_GLint___GENPT__ func; + ARGS_void_GLuint_GLsizei_const_GLchar___GENPT___const___GENPT___const_GLint___GENPT__ args; +} PACKED_void_GLuint_GLsizei_const_GLchar___GENPT___const___GENPT___const_GLint___GENPT__; +typedef struct { + int func; + ARGS_void_GLuint_GLsizei_const_GLchar___GENPT___const___GENPT___const_GLint___GENPT__ args; +} INDEXED_void_GLuint_GLsizei_const_GLchar___GENPT___const___GENPT___const_GLint___GENPT__; +typedef void (*FUNC_void_GLenum_GLint_GLuint)(GLenum func, GLint ref, GLuint mask); +typedef struct { + GLenum a1; + GLint a2; + GLuint a3; +} ARGS_void_GLenum_GLint_GLuint; +typedef struct { + int format; + FUNC_void_GLenum_GLint_GLuint func; + ARGS_void_GLenum_GLint_GLuint args; +} PACKED_void_GLenum_GLint_GLuint; +typedef struct { + int func; + ARGS_void_GLenum_GLint_GLuint args; +} INDEXED_void_GLenum_GLint_GLuint; +typedef void (*FUNC_void_GLenum_GLenum_GLint_GLuint)(GLenum face, GLenum func, GLint ref, GLuint mask); +typedef struct { + GLenum a1; + GLenum a2; + GLint a3; + GLuint a4; +} ARGS_void_GLenum_GLenum_GLint_GLuint; +typedef struct { + int format; + FUNC_void_GLenum_GLenum_GLint_GLuint func; + ARGS_void_GLenum_GLenum_GLint_GLuint args; +} PACKED_void_GLenum_GLenum_GLint_GLuint; +typedef struct { + int func; + ARGS_void_GLenum_GLenum_GLint_GLuint args; +} INDEXED_void_GLenum_GLenum_GLint_GLuint; +typedef void (*FUNC_void_GLenum_GLenum_GLenum)(GLenum fail, GLenum zfail, GLenum zpass); +typedef struct { + GLenum a1; + GLenum a2; + GLenum a3; +} ARGS_void_GLenum_GLenum_GLenum; +typedef struct { + int format; + FUNC_void_GLenum_GLenum_GLenum func; + ARGS_void_GLenum_GLenum_GLenum args; +} PACKED_void_GLenum_GLenum_GLenum; +typedef struct { + int func; + ARGS_void_GLenum_GLenum_GLenum args; +} INDEXED_void_GLenum_GLenum_GLenum; +typedef void (*FUNC_void_GLenum_GLenum_GLint)(GLenum target, GLenum pname, GLint param); +typedef struct { + GLenum a1; + GLenum a2; + GLint a3; +} ARGS_void_GLenum_GLenum_GLint; +typedef struct { + int format; + FUNC_void_GLenum_GLenum_GLint func; + ARGS_void_GLenum_GLenum_GLint args; +} PACKED_void_GLenum_GLenum_GLint; +typedef struct { + int func; + ARGS_void_GLenum_GLenum_GLint args; +} INDEXED_void_GLenum_GLenum_GLint; +typedef void (*FUNC_void_GLenum_GLenum_const_GLint___GENPT__)(GLenum target, GLenum pname, const GLint * params); +typedef struct { + GLenum a1; + GLenum a2; + GLint * a3; +} ARGS_void_GLenum_GLenum_const_GLint___GENPT__; +typedef struct { + int format; + FUNC_void_GLenum_GLenum_const_GLint___GENPT__ func; + ARGS_void_GLenum_GLenum_const_GLint___GENPT__ args; +} PACKED_void_GLenum_GLenum_const_GLint___GENPT__; +typedef struct { + int func; + ARGS_void_GLenum_GLenum_const_GLint___GENPT__ args; +} INDEXED_void_GLenum_GLenum_const_GLint___GENPT__; +typedef void (*FUNC_void_GLenum_GLint_GLint_GLsizei_GLsizei_GLint_GLenum_GLenum_const_GLvoid___GENPT__)(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid * data); +typedef struct { + GLenum a1; + GLint a2; + GLint a3; + GLsizei a4; + GLsizei a5; + GLint a6; + GLenum a7; + GLenum a8; + GLvoid * a9; +} ARGS_void_GLenum_GLint_GLint_GLsizei_GLsizei_GLint_GLenum_GLenum_const_GLvoid___GENPT__; +typedef struct { + int format; + FUNC_void_GLenum_GLint_GLint_GLsizei_GLsizei_GLint_GLenum_GLenum_const_GLvoid___GENPT__ func; + ARGS_void_GLenum_GLint_GLint_GLsizei_GLsizei_GLint_GLenum_GLenum_const_GLvoid___GENPT__ args; +} PACKED_void_GLenum_GLint_GLint_GLsizei_GLsizei_GLint_GLenum_GLenum_const_GLvoid___GENPT__; +typedef struct { + int func; + ARGS_void_GLenum_GLint_GLint_GLsizei_GLsizei_GLint_GLenum_GLenum_const_GLvoid___GENPT__ args; +} INDEXED_void_GLenum_GLint_GLint_GLsizei_GLsizei_GLint_GLenum_GLenum_const_GLvoid___GENPT__; +typedef void (*FUNC_void_GLenum_GLint_GLint_GLint_GLsizei_GLsizei_GLenum_GLenum_const_GLvoid___GENPT__)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid * data); +typedef struct { + GLenum a1; + GLint a2; + GLint a3; + GLint a4; + GLsizei a5; + GLsizei a6; + GLenum a7; + GLenum a8; + GLvoid * a9; +} ARGS_void_GLenum_GLint_GLint_GLint_GLsizei_GLsizei_GLenum_GLenum_const_GLvoid___GENPT__; +typedef struct { + int format; + FUNC_void_GLenum_GLint_GLint_GLint_GLsizei_GLsizei_GLenum_GLenum_const_GLvoid___GENPT__ func; + ARGS_void_GLenum_GLint_GLint_GLint_GLsizei_GLsizei_GLenum_GLenum_const_GLvoid___GENPT__ args; +} PACKED_void_GLenum_GLint_GLint_GLint_GLsizei_GLsizei_GLenum_GLenum_const_GLvoid___GENPT__; +typedef struct { + int func; + ARGS_void_GLenum_GLint_GLint_GLint_GLsizei_GLsizei_GLenum_GLenum_const_GLvoid___GENPT__ args; +} INDEXED_void_GLenum_GLint_GLint_GLint_GLsizei_GLsizei_GLenum_GLenum_const_GLvoid___GENPT__; +typedef void (*FUNC_void_GLint_GLfloat)(GLint location, GLfloat v0); +typedef struct { + GLint a1; + GLfloat a2; +} ARGS_void_GLint_GLfloat; +typedef struct { + int format; + FUNC_void_GLint_GLfloat func; + ARGS_void_GLint_GLfloat args; +} PACKED_void_GLint_GLfloat; +typedef struct { + int func; + ARGS_void_GLint_GLfloat args; +} INDEXED_void_GLint_GLfloat; +typedef void (*FUNC_void_GLint_GLsizei_const_GLfloat___GENPT__)(GLint location, GLsizei count, const GLfloat * value); +typedef struct { + GLint a1; + GLsizei a2; + GLfloat * a3; +} ARGS_void_GLint_GLsizei_const_GLfloat___GENPT__; +typedef struct { + int format; + FUNC_void_GLint_GLsizei_const_GLfloat___GENPT__ func; + ARGS_void_GLint_GLsizei_const_GLfloat___GENPT__ args; +} PACKED_void_GLint_GLsizei_const_GLfloat___GENPT__; +typedef struct { + int func; + ARGS_void_GLint_GLsizei_const_GLfloat___GENPT__ args; +} INDEXED_void_GLint_GLsizei_const_GLfloat___GENPT__; +typedef void (*FUNC_void_GLint_GLint)(GLint location, GLint v0); +typedef struct { + GLint a1; + GLint a2; +} ARGS_void_GLint_GLint; +typedef struct { + int format; + FUNC_void_GLint_GLint func; + ARGS_void_GLint_GLint args; +} PACKED_void_GLint_GLint; +typedef struct { + int func; + ARGS_void_GLint_GLint args; +} INDEXED_void_GLint_GLint; +typedef void (*FUNC_void_GLint_GLsizei_const_GLint___GENPT__)(GLint location, GLsizei count, const GLint * value); +typedef struct { + GLint a1; + GLsizei a2; + GLint * a3; +} ARGS_void_GLint_GLsizei_const_GLint___GENPT__; +typedef struct { + int format; + FUNC_void_GLint_GLsizei_const_GLint___GENPT__ func; + ARGS_void_GLint_GLsizei_const_GLint___GENPT__ args; +} PACKED_void_GLint_GLsizei_const_GLint___GENPT__; +typedef struct { + int func; + ARGS_void_GLint_GLsizei_const_GLint___GENPT__ args; +} INDEXED_void_GLint_GLsizei_const_GLint___GENPT__; +typedef void (*FUNC_void_GLint_GLfloat_GLfloat)(GLint location, GLfloat v0, GLfloat v1); +typedef struct { + GLint a1; + GLfloat a2; + GLfloat a3; +} ARGS_void_GLint_GLfloat_GLfloat; +typedef struct { + int format; + FUNC_void_GLint_GLfloat_GLfloat func; + ARGS_void_GLint_GLfloat_GLfloat args; +} PACKED_void_GLint_GLfloat_GLfloat; +typedef struct { + int func; + ARGS_void_GLint_GLfloat_GLfloat args; +} INDEXED_void_GLint_GLfloat_GLfloat; +typedef void (*FUNC_void_GLint_GLint_GLint)(GLint location, GLint v0, GLint v1); +typedef struct { + GLint a1; + GLint a2; + GLint a3; +} ARGS_void_GLint_GLint_GLint; +typedef struct { + int format; + FUNC_void_GLint_GLint_GLint func; + ARGS_void_GLint_GLint_GLint args; +} PACKED_void_GLint_GLint_GLint; +typedef struct { + int func; + ARGS_void_GLint_GLint_GLint args; +} INDEXED_void_GLint_GLint_GLint; +typedef void (*FUNC_void_GLint_GLfloat_GLfloat_GLfloat)(GLint location, GLfloat v0, GLfloat v1, GLfloat v2); +typedef struct { + GLint a1; + GLfloat a2; + GLfloat a3; + GLfloat a4; +} ARGS_void_GLint_GLfloat_GLfloat_GLfloat; +typedef struct { + int format; + FUNC_void_GLint_GLfloat_GLfloat_GLfloat func; + ARGS_void_GLint_GLfloat_GLfloat_GLfloat args; +} PACKED_void_GLint_GLfloat_GLfloat_GLfloat; +typedef struct { + int func; + ARGS_void_GLint_GLfloat_GLfloat_GLfloat args; +} INDEXED_void_GLint_GLfloat_GLfloat_GLfloat; +typedef void (*FUNC_void_GLint_GLint_GLint_GLint)(GLint location, GLint v0, GLint v1, GLint v2); +typedef struct { + GLint a1; + GLint a2; + GLint a3; + GLint a4; +} ARGS_void_GLint_GLint_GLint_GLint; +typedef struct { + int format; + FUNC_void_GLint_GLint_GLint_GLint func; + ARGS_void_GLint_GLint_GLint_GLint args; +} PACKED_void_GLint_GLint_GLint_GLint; +typedef struct { + int func; + ARGS_void_GLint_GLint_GLint_GLint args; +} INDEXED_void_GLint_GLint_GLint_GLint; +typedef void (*FUNC_void_GLint_GLfloat_GLfloat_GLfloat_GLfloat)(GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3); +typedef struct { + GLint a1; + GLfloat a2; + GLfloat a3; + GLfloat a4; + GLfloat a5; +} ARGS_void_GLint_GLfloat_GLfloat_GLfloat_GLfloat; +typedef struct { + int format; + FUNC_void_GLint_GLfloat_GLfloat_GLfloat_GLfloat func; + ARGS_void_GLint_GLfloat_GLfloat_GLfloat_GLfloat args; +} PACKED_void_GLint_GLfloat_GLfloat_GLfloat_GLfloat; +typedef struct { + int func; + ARGS_void_GLint_GLfloat_GLfloat_GLfloat_GLfloat args; +} INDEXED_void_GLint_GLfloat_GLfloat_GLfloat_GLfloat; +typedef void (*FUNC_void_GLint_GLsizei_GLboolean_const_GLfloat___GENPT__)(GLint location, GLsizei count, GLboolean transpose, const GLfloat * value); +typedef struct { + GLint a1; + GLsizei a2; + GLboolean a3; + GLfloat * a4; +} ARGS_void_GLint_GLsizei_GLboolean_const_GLfloat___GENPT__; +typedef struct { + int format; + FUNC_void_GLint_GLsizei_GLboolean_const_GLfloat___GENPT__ func; + ARGS_void_GLint_GLsizei_GLboolean_const_GLfloat___GENPT__ args; +} PACKED_void_GLint_GLsizei_GLboolean_const_GLfloat___GENPT__; +typedef struct { + int func; + ARGS_void_GLint_GLsizei_GLboolean_const_GLfloat___GENPT__ args; +} INDEXED_void_GLint_GLsizei_GLboolean_const_GLfloat___GENPT__; +typedef void (*FUNC_void_GLuint_GLfloat)(GLuint index, GLfloat x); +typedef struct { + GLuint a1; + GLfloat a2; +} ARGS_void_GLuint_GLfloat; +typedef struct { + int format; + FUNC_void_GLuint_GLfloat func; + ARGS_void_GLuint_GLfloat args; +} PACKED_void_GLuint_GLfloat; +typedef struct { + int func; + ARGS_void_GLuint_GLfloat args; +} INDEXED_void_GLuint_GLfloat; +typedef void (*FUNC_void_GLuint_const_GLfloat___GENPT__)(GLuint index, const GLfloat * v); +typedef struct { + GLuint a1; + GLfloat * a2; +} ARGS_void_GLuint_const_GLfloat___GENPT__; +typedef struct { + int format; + FUNC_void_GLuint_const_GLfloat___GENPT__ func; + ARGS_void_GLuint_const_GLfloat___GENPT__ args; +} PACKED_void_GLuint_const_GLfloat___GENPT__; +typedef struct { + int func; + ARGS_void_GLuint_const_GLfloat___GENPT__ args; +} INDEXED_void_GLuint_const_GLfloat___GENPT__; +typedef void (*FUNC_void_GLuint_GLfloat_GLfloat)(GLuint index, GLfloat x, GLfloat y); +typedef struct { + GLuint a1; + GLfloat a2; + GLfloat a3; +} ARGS_void_GLuint_GLfloat_GLfloat; +typedef struct { + int format; + FUNC_void_GLuint_GLfloat_GLfloat func; + ARGS_void_GLuint_GLfloat_GLfloat args; +} PACKED_void_GLuint_GLfloat_GLfloat; +typedef struct { + int func; + ARGS_void_GLuint_GLfloat_GLfloat args; +} INDEXED_void_GLuint_GLfloat_GLfloat; +typedef void (*FUNC_void_GLuint_GLfloat_GLfloat_GLfloat)(GLuint index, GLfloat x, GLfloat y, GLfloat z); +typedef struct { + GLuint a1; + GLfloat a2; + GLfloat a3; + GLfloat a4; +} ARGS_void_GLuint_GLfloat_GLfloat_GLfloat; +typedef struct { + int format; + FUNC_void_GLuint_GLfloat_GLfloat_GLfloat func; + ARGS_void_GLuint_GLfloat_GLfloat_GLfloat args; +} PACKED_void_GLuint_GLfloat_GLfloat_GLfloat; +typedef struct { + int func; + ARGS_void_GLuint_GLfloat_GLfloat_GLfloat args; +} INDEXED_void_GLuint_GLfloat_GLfloat_GLfloat; +typedef void (*FUNC_void_GLuint_GLfloat_GLfloat_GLfloat_GLfloat)(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +typedef struct { + GLuint a1; + GLfloat a2; + GLfloat a3; + GLfloat a4; + GLfloat a5; +} ARGS_void_GLuint_GLfloat_GLfloat_GLfloat_GLfloat; +typedef struct { + int format; + FUNC_void_GLuint_GLfloat_GLfloat_GLfloat_GLfloat func; + ARGS_void_GLuint_GLfloat_GLfloat_GLfloat_GLfloat args; +} PACKED_void_GLuint_GLfloat_GLfloat_GLfloat_GLfloat; +typedef struct { + int func; + ARGS_void_GLuint_GLfloat_GLfloat_GLfloat_GLfloat args; +} INDEXED_void_GLuint_GLfloat_GLfloat_GLfloat_GLfloat; +typedef void (*FUNC_void_GLuint_GLint_GLenum_GLboolean_GLsizei_const_GLvoid___GENPT__)(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid * pointer); +typedef struct { + GLuint a1; + GLint a2; + GLenum a3; + GLboolean a4; + GLsizei a5; + GLvoid * a6; +} ARGS_void_GLuint_GLint_GLenum_GLboolean_GLsizei_const_GLvoid___GENPT__; +typedef struct { + int format; + FUNC_void_GLuint_GLint_GLenum_GLboolean_GLsizei_const_GLvoid___GENPT__ func; + ARGS_void_GLuint_GLint_GLenum_GLboolean_GLsizei_const_GLvoid___GENPT__ args; +} PACKED_void_GLuint_GLint_GLenum_GLboolean_GLsizei_const_GLvoid___GENPT__; +typedef struct { + int func; + ARGS_void_GLuint_GLint_GLenum_GLboolean_GLsizei_const_GLvoid___GENPT__ args; +} INDEXED_void_GLuint_GLint_GLenum_GLboolean_GLsizei_const_GLvoid___GENPT__; + +extern void glPushCall(void *data); +void glPackedCall(const packed_call_t *packed); +void glIndexedCall(const indexed_call_t *packed, void *ret_v); +packed_call_t* glCopyPackedCall(const packed_call_t *packed); + +#define glActiveTexture_INDEX 1 +#define glActiveTexture_RETURN void +#define glActiveTexture_ARG_NAMES texture +#define glActiveTexture_ARG_EXPAND GLenum texture +#define glActiveTexture_PACKED PACKED_void_GLenum +#define glActiveTexture_INDEXED INDEXED_void_GLenum +#define glActiveTexture_FORMAT FORMAT_void_GLenum +#define glAlphaFunc_INDEX 2 +#define glAlphaFunc_RETURN void +#define glAlphaFunc_ARG_NAMES func, ref +#define glAlphaFunc_ARG_EXPAND GLenum func, GLclampf ref +#define glAlphaFunc_PACKED PACKED_void_GLenum_GLclampf +#define glAlphaFunc_INDEXED INDEXED_void_GLenum_GLclampf +#define glAlphaFunc_FORMAT FORMAT_void_GLenum_GLclampf +#define glAlphaFuncx_INDEX 3 +#define glAlphaFuncx_RETURN void +#define glAlphaFuncx_ARG_NAMES func, ref +#define glAlphaFuncx_ARG_EXPAND GLenum func, GLclampx ref +#define glAlphaFuncx_PACKED PACKED_void_GLenum_GLclampx +#define glAlphaFuncx_INDEXED INDEXED_void_GLenum_GLclampx +#define glAlphaFuncx_FORMAT FORMAT_void_GLenum_GLclampx +#define glAttachShader_INDEX 4 +#define glAttachShader_RETURN void +#define glAttachShader_ARG_NAMES program, shader +#define glAttachShader_ARG_EXPAND GLuint program, GLuint shader +#define glAttachShader_PACKED PACKED_void_GLuint_GLuint +#define glAttachShader_INDEXED INDEXED_void_GLuint_GLuint +#define glAttachShader_FORMAT FORMAT_void_GLuint_GLuint +#define glBindAttribLocation_INDEX 5 +#define glBindAttribLocation_RETURN void +#define glBindAttribLocation_ARG_NAMES program, index, name +#define glBindAttribLocation_ARG_EXPAND GLuint program, GLuint index, const GLchar * name +#define glBindAttribLocation_PACKED PACKED_void_GLuint_GLuint_const_GLchar___GENPT__ +#define glBindAttribLocation_INDEXED INDEXED_void_GLuint_GLuint_const_GLchar___GENPT__ +#define glBindAttribLocation_FORMAT FORMAT_void_GLuint_GLuint_const_GLchar___GENPT__ +#define glBindBuffer_INDEX 6 +#define glBindBuffer_RETURN void +#define glBindBuffer_ARG_NAMES target, buffer +#define glBindBuffer_ARG_EXPAND GLenum target, GLuint buffer +#define glBindBuffer_PACKED PACKED_void_GLenum_GLuint +#define glBindBuffer_INDEXED INDEXED_void_GLenum_GLuint +#define glBindBuffer_FORMAT FORMAT_void_GLenum_GLuint +#define glBindFramebuffer_INDEX 7 +#define glBindFramebuffer_RETURN void +#define glBindFramebuffer_ARG_NAMES target, framebuffer +#define glBindFramebuffer_ARG_EXPAND GLenum target, GLuint framebuffer +#define glBindFramebuffer_PACKED PACKED_void_GLenum_GLuint +#define glBindFramebuffer_INDEXED INDEXED_void_GLenum_GLuint +#define glBindFramebuffer_FORMAT FORMAT_void_GLenum_GLuint +#define glBindRenderbuffer_INDEX 8 +#define glBindRenderbuffer_RETURN void +#define glBindRenderbuffer_ARG_NAMES target, renderbuffer +#define glBindRenderbuffer_ARG_EXPAND GLenum target, GLuint renderbuffer +#define glBindRenderbuffer_PACKED PACKED_void_GLenum_GLuint +#define glBindRenderbuffer_INDEXED INDEXED_void_GLenum_GLuint +#define glBindRenderbuffer_FORMAT FORMAT_void_GLenum_GLuint +#define glBindTexture_INDEX 9 +#define glBindTexture_RETURN void +#define glBindTexture_ARG_NAMES target, texture +#define glBindTexture_ARG_EXPAND GLenum target, GLuint texture +#define glBindTexture_PACKED PACKED_void_GLenum_GLuint +#define glBindTexture_INDEXED INDEXED_void_GLenum_GLuint +#define glBindTexture_FORMAT FORMAT_void_GLenum_GLuint +#define glBlendColor_INDEX 10 +#define glBlendColor_RETURN void +#define glBlendColor_ARG_NAMES red, green, blue, alpha +#define glBlendColor_ARG_EXPAND GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha +#define glBlendColor_PACKED PACKED_void_GLclampf_GLclampf_GLclampf_GLclampf +#define glBlendColor_INDEXED INDEXED_void_GLclampf_GLclampf_GLclampf_GLclampf +#define glBlendColor_FORMAT FORMAT_void_GLclampf_GLclampf_GLclampf_GLclampf +#define glBlendEquation_INDEX 11 +#define glBlendEquation_RETURN void +#define glBlendEquation_ARG_NAMES mode +#define glBlendEquation_ARG_EXPAND GLenum mode +#define glBlendEquation_PACKED PACKED_void_GLenum +#define glBlendEquation_INDEXED INDEXED_void_GLenum +#define glBlendEquation_FORMAT FORMAT_void_GLenum +#define glBlendEquationSeparate_INDEX 12 +#define glBlendEquationSeparate_RETURN void +#define glBlendEquationSeparate_ARG_NAMES modeRGB, modeA +#define glBlendEquationSeparate_ARG_EXPAND GLenum modeRGB, GLenum modeA +#define glBlendEquationSeparate_PACKED PACKED_void_GLenum_GLenum +#define glBlendEquationSeparate_INDEXED INDEXED_void_GLenum_GLenum +#define glBlendEquationSeparate_FORMAT FORMAT_void_GLenum_GLenum +#define glBlendFunc_INDEX 13 +#define glBlendFunc_RETURN void +#define glBlendFunc_ARG_NAMES sfactor, dfactor +#define glBlendFunc_ARG_EXPAND GLenum sfactor, GLenum dfactor +#define glBlendFunc_PACKED PACKED_void_GLenum_GLenum +#define glBlendFunc_INDEXED INDEXED_void_GLenum_GLenum +#define glBlendFunc_FORMAT FORMAT_void_GLenum_GLenum +#define glBlendFuncSeparate_INDEX 14 +#define glBlendFuncSeparate_RETURN void +#define glBlendFuncSeparate_ARG_NAMES sfactorRGB, dfactorRGB, sfactorAlpha, dfactorAlpha +#define glBlendFuncSeparate_ARG_EXPAND GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha +#define glBlendFuncSeparate_PACKED PACKED_void_GLenum_GLenum_GLenum_GLenum +#define glBlendFuncSeparate_INDEXED INDEXED_void_GLenum_GLenum_GLenum_GLenum +#define glBlendFuncSeparate_FORMAT FORMAT_void_GLenum_GLenum_GLenum_GLenum +#define glBufferData_INDEX 15 +#define glBufferData_RETURN void +#define glBufferData_ARG_NAMES target, size, data, usage +#define glBufferData_ARG_EXPAND GLenum target, GLsizeiptr size, const GLvoid * data, GLenum usage +#define glBufferData_PACKED PACKED_void_GLenum_GLsizeiptr_const_GLvoid___GENPT___GLenum +#define glBufferData_INDEXED INDEXED_void_GLenum_GLsizeiptr_const_GLvoid___GENPT___GLenum +#define glBufferData_FORMAT FORMAT_void_GLenum_GLsizeiptr_const_GLvoid___GENPT___GLenum +#define glBufferSubData_INDEX 16 +#define glBufferSubData_RETURN void +#define glBufferSubData_ARG_NAMES target, offset, size, data +#define glBufferSubData_ARG_EXPAND GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid * data +#define glBufferSubData_PACKED PACKED_void_GLenum_GLintptr_GLsizeiptr_const_GLvoid___GENPT__ +#define glBufferSubData_INDEXED INDEXED_void_GLenum_GLintptr_GLsizeiptr_const_GLvoid___GENPT__ +#define glBufferSubData_FORMAT FORMAT_void_GLenum_GLintptr_GLsizeiptr_const_GLvoid___GENPT__ +#define glCheckFramebufferStatus_INDEX 17 +#define glCheckFramebufferStatus_RETURN GLenum +#define glCheckFramebufferStatus_ARG_NAMES target +#define glCheckFramebufferStatus_ARG_EXPAND GLenum target +#define glCheckFramebufferStatus_PACKED PACKED_GLenum_GLenum +#define glCheckFramebufferStatus_INDEXED INDEXED_GLenum_GLenum +#define glCheckFramebufferStatus_FORMAT FORMAT_GLenum_GLenum +#define glClear_INDEX 18 +#define glClear_RETURN void +#define glClear_ARG_NAMES mask +#define glClear_ARG_EXPAND GLbitfield mask +#define glClear_PACKED PACKED_void_GLbitfield +#define glClear_INDEXED INDEXED_void_GLbitfield +#define glClear_FORMAT FORMAT_void_GLbitfield +#define glClearColor_INDEX 19 +#define glClearColor_RETURN void +#define glClearColor_ARG_NAMES red, green, blue, alpha +#define glClearColor_ARG_EXPAND GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha +#define glClearColor_PACKED PACKED_void_GLclampf_GLclampf_GLclampf_GLclampf +#define glClearColor_INDEXED INDEXED_void_GLclampf_GLclampf_GLclampf_GLclampf +#define glClearColor_FORMAT FORMAT_void_GLclampf_GLclampf_GLclampf_GLclampf +#define glClearColorx_INDEX 20 +#define glClearColorx_RETURN void +#define glClearColorx_ARG_NAMES red, green, blue, alpha +#define glClearColorx_ARG_EXPAND GLclampx red, GLclampx green, GLclampx blue, GLclampx alpha +#define glClearColorx_PACKED PACKED_void_GLclampx_GLclampx_GLclampx_GLclampx +#define glClearColorx_INDEXED INDEXED_void_GLclampx_GLclampx_GLclampx_GLclampx +#define glClearColorx_FORMAT FORMAT_void_GLclampx_GLclampx_GLclampx_GLclampx +#define glClearDepthf_INDEX 21 +#define glClearDepthf_RETURN void +#define glClearDepthf_ARG_NAMES depth +#define glClearDepthf_ARG_EXPAND GLclampf depth +#define glClearDepthf_PACKED PACKED_void_GLclampf +#define glClearDepthf_INDEXED INDEXED_void_GLclampf +#define glClearDepthf_FORMAT FORMAT_void_GLclampf +#define glClearDepthx_INDEX 22 +#define glClearDepthx_RETURN void +#define glClearDepthx_ARG_NAMES depth +#define glClearDepthx_ARG_EXPAND GLclampx depth +#define glClearDepthx_PACKED PACKED_void_GLclampx +#define glClearDepthx_INDEXED INDEXED_void_GLclampx +#define glClearDepthx_FORMAT FORMAT_void_GLclampx +#define glClearStencil_INDEX 23 +#define glClearStencil_RETURN void +#define glClearStencil_ARG_NAMES s +#define glClearStencil_ARG_EXPAND GLint s +#define glClearStencil_PACKED PACKED_void_GLint +#define glClearStencil_INDEXED INDEXED_void_GLint +#define glClearStencil_FORMAT FORMAT_void_GLint +#define glClientActiveTexture_INDEX 24 +#define glClientActiveTexture_RETURN void +#define glClientActiveTexture_ARG_NAMES texture +#define glClientActiveTexture_ARG_EXPAND GLenum texture +#define glClientActiveTexture_PACKED PACKED_void_GLenum +#define glClientActiveTexture_INDEXED INDEXED_void_GLenum +#define glClientActiveTexture_FORMAT FORMAT_void_GLenum +#define glClipPlanef_INDEX 25 +#define glClipPlanef_RETURN void +#define glClipPlanef_ARG_NAMES plane, equation +#define glClipPlanef_ARG_EXPAND GLenum plane, const GLfloat * equation +#define glClipPlanef_PACKED PACKED_void_GLenum_const_GLfloat___GENPT__ +#define glClipPlanef_INDEXED INDEXED_void_GLenum_const_GLfloat___GENPT__ +#define glClipPlanef_FORMAT FORMAT_void_GLenum_const_GLfloat___GENPT__ +#define glClipPlanex_INDEX 26 +#define glClipPlanex_RETURN void +#define glClipPlanex_ARG_NAMES plane, equation +#define glClipPlanex_ARG_EXPAND GLenum plane, const GLfixed * equation +#define glClipPlanex_PACKED PACKED_void_GLenum_const_GLfixed___GENPT__ +#define glClipPlanex_INDEXED INDEXED_void_GLenum_const_GLfixed___GENPT__ +#define glClipPlanex_FORMAT FORMAT_void_GLenum_const_GLfixed___GENPT__ +#define glColor4f_INDEX 27 +#define glColor4f_RETURN void +#define glColor4f_ARG_NAMES red, green, blue, alpha +#define glColor4f_ARG_EXPAND GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha +#define glColor4f_PACKED PACKED_void_GLfloat_GLfloat_GLfloat_GLfloat +#define glColor4f_INDEXED INDEXED_void_GLfloat_GLfloat_GLfloat_GLfloat +#define glColor4f_FORMAT FORMAT_void_GLfloat_GLfloat_GLfloat_GLfloat +#define glColor4ub_INDEX 28 +#define glColor4ub_RETURN void +#define glColor4ub_ARG_NAMES red, green, blue, alpha +#define glColor4ub_ARG_EXPAND GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha +#define glColor4ub_PACKED PACKED_void_GLubyte_GLubyte_GLubyte_GLubyte +#define glColor4ub_INDEXED INDEXED_void_GLubyte_GLubyte_GLubyte_GLubyte +#define glColor4ub_FORMAT FORMAT_void_GLubyte_GLubyte_GLubyte_GLubyte +#define glColor4x_INDEX 29 +#define glColor4x_RETURN void +#define glColor4x_ARG_NAMES red, green, blue, alpha +#define glColor4x_ARG_EXPAND GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha +#define glColor4x_PACKED PACKED_void_GLfixed_GLfixed_GLfixed_GLfixed +#define glColor4x_INDEXED INDEXED_void_GLfixed_GLfixed_GLfixed_GLfixed +#define glColor4x_FORMAT FORMAT_void_GLfixed_GLfixed_GLfixed_GLfixed +#define glColorMask_INDEX 30 +#define glColorMask_RETURN void +#define glColorMask_ARG_NAMES red, green, blue, alpha +#define glColorMask_ARG_EXPAND GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha +#define glColorMask_PACKED PACKED_void_GLboolean_GLboolean_GLboolean_GLboolean +#define glColorMask_INDEXED INDEXED_void_GLboolean_GLboolean_GLboolean_GLboolean +#define glColorMask_FORMAT FORMAT_void_GLboolean_GLboolean_GLboolean_GLboolean +#define glColorPointer_INDEX 31 +#define glColorPointer_RETURN void +#define glColorPointer_ARG_NAMES size, type, stride, pointer +#define glColorPointer_ARG_EXPAND GLint size, GLenum type, GLsizei stride, const GLvoid * pointer +#define glColorPointer_PACKED PACKED_void_GLint_GLenum_GLsizei_const_GLvoid___GENPT__ +#define glColorPointer_INDEXED INDEXED_void_GLint_GLenum_GLsizei_const_GLvoid___GENPT__ +#define glColorPointer_FORMAT FORMAT_void_GLint_GLenum_GLsizei_const_GLvoid___GENPT__ +#define glCompileShader_INDEX 32 +#define glCompileShader_RETURN void +#define glCompileShader_ARG_NAMES shader +#define glCompileShader_ARG_EXPAND GLuint shader +#define glCompileShader_PACKED PACKED_void_GLuint +#define glCompileShader_INDEXED INDEXED_void_GLuint +#define glCompileShader_FORMAT FORMAT_void_GLuint +#define glCompressedTexImage2D_INDEX 33 +#define glCompressedTexImage2D_RETURN void +#define glCompressedTexImage2D_ARG_NAMES target, level, internalformat, width, height, border, imageSize, data +#define glCompressedTexImage2D_ARG_EXPAND GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid * data +#define glCompressedTexImage2D_PACKED PACKED_void_GLenum_GLint_GLenum_GLsizei_GLsizei_GLint_GLsizei_const_GLvoid___GENPT__ +#define glCompressedTexImage2D_INDEXED INDEXED_void_GLenum_GLint_GLenum_GLsizei_GLsizei_GLint_GLsizei_const_GLvoid___GENPT__ +#define glCompressedTexImage2D_FORMAT FORMAT_void_GLenum_GLint_GLenum_GLsizei_GLsizei_GLint_GLsizei_const_GLvoid___GENPT__ +#define glCompressedTexSubImage2D_INDEX 34 +#define glCompressedTexSubImage2D_RETURN void +#define glCompressedTexSubImage2D_ARG_NAMES target, level, xoffset, yoffset, width, height, format, imageSize, data +#define glCompressedTexSubImage2D_ARG_EXPAND GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid * data +#define glCompressedTexSubImage2D_PACKED PACKED_void_GLenum_GLint_GLint_GLint_GLsizei_GLsizei_GLenum_GLsizei_const_GLvoid___GENPT__ +#define glCompressedTexSubImage2D_INDEXED INDEXED_void_GLenum_GLint_GLint_GLint_GLsizei_GLsizei_GLenum_GLsizei_const_GLvoid___GENPT__ +#define glCompressedTexSubImage2D_FORMAT FORMAT_void_GLenum_GLint_GLint_GLint_GLsizei_GLsizei_GLenum_GLsizei_const_GLvoid___GENPT__ +#define glCopyTexImage2D_INDEX 35 +#define glCopyTexImage2D_RETURN void +#define glCopyTexImage2D_ARG_NAMES target, level, internalformat, x, y, width, height, border +#define glCopyTexImage2D_ARG_EXPAND GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border +#define glCopyTexImage2D_PACKED PACKED_void_GLenum_GLint_GLenum_GLint_GLint_GLsizei_GLsizei_GLint +#define glCopyTexImage2D_INDEXED INDEXED_void_GLenum_GLint_GLenum_GLint_GLint_GLsizei_GLsizei_GLint +#define glCopyTexImage2D_FORMAT FORMAT_void_GLenum_GLint_GLenum_GLint_GLint_GLsizei_GLsizei_GLint +#define glCopyTexSubImage2D_INDEX 36 +#define glCopyTexSubImage2D_RETURN void +#define glCopyTexSubImage2D_ARG_NAMES target, level, xoffset, yoffset, x, y, width, height +#define glCopyTexSubImage2D_ARG_EXPAND GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height +#define glCopyTexSubImage2D_PACKED PACKED_void_GLenum_GLint_GLint_GLint_GLint_GLint_GLsizei_GLsizei +#define glCopyTexSubImage2D_INDEXED INDEXED_void_GLenum_GLint_GLint_GLint_GLint_GLint_GLsizei_GLsizei +#define glCopyTexSubImage2D_FORMAT FORMAT_void_GLenum_GLint_GLint_GLint_GLint_GLint_GLsizei_GLsizei +#define glCreateProgram_INDEX 37 +#define glCreateProgram_RETURN GLuint +#define glCreateProgram_ARG_NAMES +#define glCreateProgram_ARG_EXPAND +#define glCreateProgram_PACKED PACKED_GLuint +#define glCreateProgram_INDEXED INDEXED_GLuint +#define glCreateProgram_FORMAT FORMAT_GLuint +#define glCreateShader_INDEX 38 +#define glCreateShader_RETURN GLuint +#define glCreateShader_ARG_NAMES type +#define glCreateShader_ARG_EXPAND GLenum type +#define glCreateShader_PACKED PACKED_GLuint_GLenum +#define glCreateShader_INDEXED INDEXED_GLuint_GLenum +#define glCreateShader_FORMAT FORMAT_GLuint_GLenum +#define glCullFace_INDEX 39 +#define glCullFace_RETURN void +#define glCullFace_ARG_NAMES mode +#define glCullFace_ARG_EXPAND GLenum mode +#define glCullFace_PACKED PACKED_void_GLenum +#define glCullFace_INDEXED INDEXED_void_GLenum +#define glCullFace_FORMAT FORMAT_void_GLenum +#define glDeleteBuffers_INDEX 40 +#define glDeleteBuffers_RETURN void +#define glDeleteBuffers_ARG_NAMES n, buffer +#define glDeleteBuffers_ARG_EXPAND GLsizei n, const GLuint * buffer +#define glDeleteBuffers_PACKED PACKED_void_GLsizei_const_GLuint___GENPT__ +#define glDeleteBuffers_INDEXED INDEXED_void_GLsizei_const_GLuint___GENPT__ +#define glDeleteBuffers_FORMAT FORMAT_void_GLsizei_const_GLuint___GENPT__ +#define glDeleteFramebuffers_INDEX 41 +#define glDeleteFramebuffers_RETURN void +#define glDeleteFramebuffers_ARG_NAMES n, framebuffers +#define glDeleteFramebuffers_ARG_EXPAND GLsizei n, GLuint * framebuffers +#define glDeleteFramebuffers_PACKED PACKED_void_GLsizei_GLuint___GENPT__ +#define glDeleteFramebuffers_INDEXED INDEXED_void_GLsizei_GLuint___GENPT__ +#define glDeleteFramebuffers_FORMAT FORMAT_void_GLsizei_GLuint___GENPT__ +#define glDeleteProgram_INDEX 42 +#define glDeleteProgram_RETURN void +#define glDeleteProgram_ARG_NAMES program +#define glDeleteProgram_ARG_EXPAND GLuint program +#define glDeleteProgram_PACKED PACKED_void_GLuint +#define glDeleteProgram_INDEXED INDEXED_void_GLuint +#define glDeleteProgram_FORMAT FORMAT_void_GLuint +#define glDeleteRenderbuffers_INDEX 43 +#define glDeleteRenderbuffers_RETURN void +#define glDeleteRenderbuffers_ARG_NAMES n, renderbuffers +#define glDeleteRenderbuffers_ARG_EXPAND GLsizei n, GLuint * renderbuffers +#define glDeleteRenderbuffers_PACKED PACKED_void_GLsizei_GLuint___GENPT__ +#define glDeleteRenderbuffers_INDEXED INDEXED_void_GLsizei_GLuint___GENPT__ +#define glDeleteRenderbuffers_FORMAT FORMAT_void_GLsizei_GLuint___GENPT__ +#define glDeleteShader_INDEX 44 +#define glDeleteShader_RETURN void +#define glDeleteShader_ARG_NAMES shader +#define glDeleteShader_ARG_EXPAND GLuint shader +#define glDeleteShader_PACKED PACKED_void_GLuint +#define glDeleteShader_INDEXED INDEXED_void_GLuint +#define glDeleteShader_FORMAT FORMAT_void_GLuint +#define glDeleteTextures_INDEX 45 +#define glDeleteTextures_RETURN void +#define glDeleteTextures_ARG_NAMES n, textures +#define glDeleteTextures_ARG_EXPAND GLsizei n, const GLuint * textures +#define glDeleteTextures_PACKED PACKED_void_GLsizei_const_GLuint___GENPT__ +#define glDeleteTextures_INDEXED INDEXED_void_GLsizei_const_GLuint___GENPT__ +#define glDeleteTextures_FORMAT FORMAT_void_GLsizei_const_GLuint___GENPT__ +#define glDepthFunc_INDEX 46 +#define glDepthFunc_RETURN void +#define glDepthFunc_ARG_NAMES func +#define glDepthFunc_ARG_EXPAND GLenum func +#define glDepthFunc_PACKED PACKED_void_GLenum +#define glDepthFunc_INDEXED INDEXED_void_GLenum +#define glDepthFunc_FORMAT FORMAT_void_GLenum +#define glDepthMask_INDEX 47 +#define glDepthMask_RETURN void +#define glDepthMask_ARG_NAMES flag +#define glDepthMask_ARG_EXPAND GLboolean flag +#define glDepthMask_PACKED PACKED_void_GLboolean +#define glDepthMask_INDEXED INDEXED_void_GLboolean +#define glDepthMask_FORMAT FORMAT_void_GLboolean +#define glDepthRangef_INDEX 48 +#define glDepthRangef_RETURN void +#define glDepthRangef_ARG_NAMES near, far +#define glDepthRangef_ARG_EXPAND GLclampf near, GLclampf far +#define glDepthRangef_PACKED PACKED_void_GLclampf_GLclampf +#define glDepthRangef_INDEXED INDEXED_void_GLclampf_GLclampf +#define glDepthRangef_FORMAT FORMAT_void_GLclampf_GLclampf +#define glDepthRangex_INDEX 49 +#define glDepthRangex_RETURN void +#define glDepthRangex_ARG_NAMES near, far +#define glDepthRangex_ARG_EXPAND GLclampx near, GLclampx far +#define glDepthRangex_PACKED PACKED_void_GLclampx_GLclampx +#define glDepthRangex_INDEXED INDEXED_void_GLclampx_GLclampx +#define glDepthRangex_FORMAT FORMAT_void_GLclampx_GLclampx +#define glDetachShader_INDEX 50 +#define glDetachShader_RETURN void +#define glDetachShader_ARG_NAMES program, shader +#define glDetachShader_ARG_EXPAND GLuint program, GLuint shader +#define glDetachShader_PACKED PACKED_void_GLuint_GLuint +#define glDetachShader_INDEXED INDEXED_void_GLuint_GLuint +#define glDetachShader_FORMAT FORMAT_void_GLuint_GLuint +#define glDisable_INDEX 51 +#define glDisable_RETURN void +#define glDisable_ARG_NAMES cap +#define glDisable_ARG_EXPAND GLenum cap +#define glDisable_PACKED PACKED_void_GLenum +#define glDisable_INDEXED INDEXED_void_GLenum +#define glDisable_FORMAT FORMAT_void_GLenum +#define glDisableClientState_INDEX 52 +#define glDisableClientState_RETURN void +#define glDisableClientState_ARG_NAMES array +#define glDisableClientState_ARG_EXPAND GLenum array +#define glDisableClientState_PACKED PACKED_void_GLenum +#define glDisableClientState_INDEXED INDEXED_void_GLenum +#define glDisableClientState_FORMAT FORMAT_void_GLenum +#define glDisableVertexAttribArray_INDEX 53 +#define glDisableVertexAttribArray_RETURN void +#define glDisableVertexAttribArray_ARG_NAMES index +#define glDisableVertexAttribArray_ARG_EXPAND GLuint index +#define glDisableVertexAttribArray_PACKED PACKED_void_GLuint +#define glDisableVertexAttribArray_INDEXED INDEXED_void_GLuint +#define glDisableVertexAttribArray_FORMAT FORMAT_void_GLuint +#define glDrawArrays_INDEX 54 +#define glDrawArrays_RETURN void +#define glDrawArrays_ARG_NAMES mode, first, count +#define glDrawArrays_ARG_EXPAND GLenum mode, GLint first, GLsizei count +#define glDrawArrays_PACKED PACKED_void_GLenum_GLint_GLsizei +#define glDrawArrays_INDEXED INDEXED_void_GLenum_GLint_GLsizei +#define glDrawArrays_FORMAT FORMAT_void_GLenum_GLint_GLsizei +#define glDrawElements_INDEX 55 +#define glDrawElements_RETURN void +#define glDrawElements_ARG_NAMES mode, count, type, indices +#define glDrawElements_ARG_EXPAND GLenum mode, GLsizei count, GLenum type, const GLvoid * indices +#define glDrawElements_PACKED PACKED_void_GLenum_GLsizei_GLenum_const_GLvoid___GENPT__ +#define glDrawElements_INDEXED INDEXED_void_GLenum_GLsizei_GLenum_const_GLvoid___GENPT__ +#define glDrawElements_FORMAT FORMAT_void_GLenum_GLsizei_GLenum_const_GLvoid___GENPT__ +#define glDrawTexf_INDEX 56 +#define glDrawTexf_RETURN void +#define glDrawTexf_ARG_NAMES x, y, z, width, height +#define glDrawTexf_ARG_EXPAND GLfloat x, GLfloat y, GLfloat z, GLfloat width, GLfloat height +#define glDrawTexf_PACKED PACKED_void_GLfloat_GLfloat_GLfloat_GLfloat_GLfloat +#define glDrawTexf_INDEXED INDEXED_void_GLfloat_GLfloat_GLfloat_GLfloat_GLfloat +#define glDrawTexf_FORMAT FORMAT_void_GLfloat_GLfloat_GLfloat_GLfloat_GLfloat +#define glDrawTexi_INDEX 57 +#define glDrawTexi_RETURN void +#define glDrawTexi_ARG_NAMES x, y, z, width, height +#define glDrawTexi_ARG_EXPAND GLint x, GLint y, GLint z, GLint width, GLint height +#define glDrawTexi_PACKED PACKED_void_GLint_GLint_GLint_GLint_GLint +#define glDrawTexi_INDEXED INDEXED_void_GLint_GLint_GLint_GLint_GLint +#define glDrawTexi_FORMAT FORMAT_void_GLint_GLint_GLint_GLint_GLint +#define glEnable_INDEX 58 +#define glEnable_RETURN void +#define glEnable_ARG_NAMES cap +#define glEnable_ARG_EXPAND GLenum cap +#define glEnable_PACKED PACKED_void_GLenum +#define glEnable_INDEXED INDEXED_void_GLenum +#define glEnable_FORMAT FORMAT_void_GLenum +#define glEnableClientState_INDEX 59 +#define glEnableClientState_RETURN void +#define glEnableClientState_ARG_NAMES array +#define glEnableClientState_ARG_EXPAND GLenum array +#define glEnableClientState_PACKED PACKED_void_GLenum +#define glEnableClientState_INDEXED INDEXED_void_GLenum +#define glEnableClientState_FORMAT FORMAT_void_GLenum +#define glEnableVertexAttribArray_INDEX 60 +#define glEnableVertexAttribArray_RETURN void +#define glEnableVertexAttribArray_ARG_NAMES index +#define glEnableVertexAttribArray_ARG_EXPAND GLuint index +#define glEnableVertexAttribArray_PACKED PACKED_void_GLuint +#define glEnableVertexAttribArray_INDEXED INDEXED_void_GLuint +#define glEnableVertexAttribArray_FORMAT FORMAT_void_GLuint +#define glFinish_INDEX 61 +#define glFinish_RETURN void +#define glFinish_ARG_NAMES +#define glFinish_ARG_EXPAND +#define glFinish_PACKED PACKED_void +#define glFinish_INDEXED INDEXED_void +#define glFinish_FORMAT FORMAT_void +#define glFlush_INDEX 62 +#define glFlush_RETURN void +#define glFlush_ARG_NAMES +#define glFlush_ARG_EXPAND +#define glFlush_PACKED PACKED_void +#define glFlush_INDEXED INDEXED_void +#define glFlush_FORMAT FORMAT_void +#define glFogCoordPointer_INDEX 63 +#define glFogCoordPointer_RETURN void +#define glFogCoordPointer_ARG_NAMES type, stride, pointer +#define glFogCoordPointer_ARG_EXPAND GLenum type, GLsizei stride, const GLvoid * pointer +#define glFogCoordPointer_PACKED PACKED_void_GLenum_GLsizei_const_GLvoid___GENPT__ +#define glFogCoordPointer_INDEXED INDEXED_void_GLenum_GLsizei_const_GLvoid___GENPT__ +#define glFogCoordPointer_FORMAT FORMAT_void_GLenum_GLsizei_const_GLvoid___GENPT__ +#define glFogCoordf_INDEX 64 +#define glFogCoordf_RETURN void +#define glFogCoordf_ARG_NAMES coord +#define glFogCoordf_ARG_EXPAND GLfloat coord +#define glFogCoordf_PACKED PACKED_void_GLfloat +#define glFogCoordf_INDEXED INDEXED_void_GLfloat +#define glFogCoordf_FORMAT FORMAT_void_GLfloat +#define glFogCoordfv_INDEX 65 +#define glFogCoordfv_RETURN void +#define glFogCoordfv_ARG_NAMES coord +#define glFogCoordfv_ARG_EXPAND const GLfloat * coord +#define glFogCoordfv_PACKED PACKED_void_const_GLfloat___GENPT__ +#define glFogCoordfv_INDEXED INDEXED_void_const_GLfloat___GENPT__ +#define glFogCoordfv_FORMAT FORMAT_void_const_GLfloat___GENPT__ +#define glFogf_INDEX 66 +#define glFogf_RETURN void +#define glFogf_ARG_NAMES pname, param +#define glFogf_ARG_EXPAND GLenum pname, GLfloat param +#define glFogf_PACKED PACKED_void_GLenum_GLfloat +#define glFogf_INDEXED INDEXED_void_GLenum_GLfloat +#define glFogf_FORMAT FORMAT_void_GLenum_GLfloat +#define glFogfv_INDEX 67 +#define glFogfv_RETURN void +#define glFogfv_ARG_NAMES pname, params +#define glFogfv_ARG_EXPAND GLenum pname, const GLfloat * params +#define glFogfv_PACKED PACKED_void_GLenum_const_GLfloat___GENPT__ +#define glFogfv_INDEXED INDEXED_void_GLenum_const_GLfloat___GENPT__ +#define glFogfv_FORMAT FORMAT_void_GLenum_const_GLfloat___GENPT__ +#define glFogx_INDEX 68 +#define glFogx_RETURN void +#define glFogx_ARG_NAMES pname, param +#define glFogx_ARG_EXPAND GLenum pname, GLfixed param +#define glFogx_PACKED PACKED_void_GLenum_GLfixed +#define glFogx_INDEXED INDEXED_void_GLenum_GLfixed +#define glFogx_FORMAT FORMAT_void_GLenum_GLfixed +#define glFogxv_INDEX 69 +#define glFogxv_RETURN void +#define glFogxv_ARG_NAMES pname, params +#define glFogxv_ARG_EXPAND GLenum pname, const GLfixed * params +#define glFogxv_PACKED PACKED_void_GLenum_const_GLfixed___GENPT__ +#define glFogxv_INDEXED INDEXED_void_GLenum_const_GLfixed___GENPT__ +#define glFogxv_FORMAT FORMAT_void_GLenum_const_GLfixed___GENPT__ +#define glFramebufferRenderbuffer_INDEX 70 +#define glFramebufferRenderbuffer_RETURN void +#define glFramebufferRenderbuffer_ARG_NAMES target, attachment, renderbuffertarget, renderbuffer +#define glFramebufferRenderbuffer_ARG_EXPAND GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer +#define glFramebufferRenderbuffer_PACKED PACKED_void_GLenum_GLenum_GLenum_GLuint +#define glFramebufferRenderbuffer_INDEXED INDEXED_void_GLenum_GLenum_GLenum_GLuint +#define glFramebufferRenderbuffer_FORMAT FORMAT_void_GLenum_GLenum_GLenum_GLuint +#define glFramebufferTexture2D_INDEX 71 +#define glFramebufferTexture2D_RETURN void +#define glFramebufferTexture2D_ARG_NAMES target, attachment, textarget, texture, level +#define glFramebufferTexture2D_ARG_EXPAND GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level +#define glFramebufferTexture2D_PACKED PACKED_void_GLenum_GLenum_GLenum_GLuint_GLint +#define glFramebufferTexture2D_INDEXED INDEXED_void_GLenum_GLenum_GLenum_GLuint_GLint +#define glFramebufferTexture2D_FORMAT FORMAT_void_GLenum_GLenum_GLenum_GLuint_GLint +#define glFrontFace_INDEX 72 +#define glFrontFace_RETURN void +#define glFrontFace_ARG_NAMES mode +#define glFrontFace_ARG_EXPAND GLenum mode +#define glFrontFace_PACKED PACKED_void_GLenum +#define glFrontFace_INDEXED INDEXED_void_GLenum +#define glFrontFace_FORMAT FORMAT_void_GLenum +#define glFrustumf_INDEX 73 +#define glFrustumf_RETURN void +#define glFrustumf_ARG_NAMES left, right, bottom, top, near, far +#define glFrustumf_ARG_EXPAND GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat near, GLfloat far +#define glFrustumf_PACKED PACKED_void_GLfloat_GLfloat_GLfloat_GLfloat_GLfloat_GLfloat +#define glFrustumf_INDEXED INDEXED_void_GLfloat_GLfloat_GLfloat_GLfloat_GLfloat_GLfloat +#define glFrustumf_FORMAT FORMAT_void_GLfloat_GLfloat_GLfloat_GLfloat_GLfloat_GLfloat +#define glFrustumx_INDEX 74 +#define glFrustumx_RETURN void +#define glFrustumx_ARG_NAMES left, right, bottom, top, near, far +#define glFrustumx_ARG_EXPAND GLfixed left, GLfixed right, GLfixed bottom, GLfixed top, GLfixed near, GLfixed far +#define glFrustumx_PACKED PACKED_void_GLfixed_GLfixed_GLfixed_GLfixed_GLfixed_GLfixed +#define glFrustumx_INDEXED INDEXED_void_GLfixed_GLfixed_GLfixed_GLfixed_GLfixed_GLfixed +#define glFrustumx_FORMAT FORMAT_void_GLfixed_GLfixed_GLfixed_GLfixed_GLfixed_GLfixed +#define glGenBuffers_INDEX 75 +#define glGenBuffers_RETURN void +#define glGenBuffers_ARG_NAMES n, buffer +#define glGenBuffers_ARG_EXPAND GLsizei n, GLuint * buffer +#define glGenBuffers_PACKED PACKED_void_GLsizei_GLuint___GENPT__ +#define glGenBuffers_INDEXED INDEXED_void_GLsizei_GLuint___GENPT__ +#define glGenBuffers_FORMAT FORMAT_void_GLsizei_GLuint___GENPT__ +#define glGenFramebuffers_INDEX 76 +#define glGenFramebuffers_RETURN void +#define glGenFramebuffers_ARG_NAMES n, ids +#define glGenFramebuffers_ARG_EXPAND GLsizei n, GLuint * ids +#define glGenFramebuffers_PACKED PACKED_void_GLsizei_GLuint___GENPT__ +#define glGenFramebuffers_INDEXED INDEXED_void_GLsizei_GLuint___GENPT__ +#define glGenFramebuffers_FORMAT FORMAT_void_GLsizei_GLuint___GENPT__ +#define glGenRenderbuffers_INDEX 77 +#define glGenRenderbuffers_RETURN void +#define glGenRenderbuffers_ARG_NAMES n, renderbuffers +#define glGenRenderbuffers_ARG_EXPAND GLsizei n, GLuint * renderbuffers +#define glGenRenderbuffers_PACKED PACKED_void_GLsizei_GLuint___GENPT__ +#define glGenRenderbuffers_INDEXED INDEXED_void_GLsizei_GLuint___GENPT__ +#define glGenRenderbuffers_FORMAT FORMAT_void_GLsizei_GLuint___GENPT__ +#define glGenTextures_INDEX 78 +#define glGenTextures_RETURN void +#define glGenTextures_ARG_NAMES n, textures +#define glGenTextures_ARG_EXPAND GLsizei n, GLuint * textures +#define glGenTextures_PACKED PACKED_void_GLsizei_GLuint___GENPT__ +#define glGenTextures_INDEXED INDEXED_void_GLsizei_GLuint___GENPT__ +#define glGenTextures_FORMAT FORMAT_void_GLsizei_GLuint___GENPT__ +#define glGenerateMipmap_INDEX 79 +#define glGenerateMipmap_RETURN void +#define glGenerateMipmap_ARG_NAMES target +#define glGenerateMipmap_ARG_EXPAND GLenum target +#define glGenerateMipmap_PACKED PACKED_void_GLenum +#define glGenerateMipmap_INDEXED INDEXED_void_GLenum +#define glGenerateMipmap_FORMAT FORMAT_void_GLenum +#define glGetActiveAttrib_INDEX 80 +#define glGetActiveAttrib_RETURN void +#define glGetActiveAttrib_ARG_NAMES program, index, bufSize, length, size, type, name +#define glGetActiveAttrib_ARG_EXPAND GLuint program, GLuint index, GLsizei bufSize, GLsizei * length, GLint * size, GLenum * type, GLchar * name +#define glGetActiveAttrib_PACKED PACKED_void_GLuint_GLuint_GLsizei_GLsizei___GENPT___GLint___GENPT___GLenum___GENPT___GLchar___GENPT__ +#define glGetActiveAttrib_INDEXED INDEXED_void_GLuint_GLuint_GLsizei_GLsizei___GENPT___GLint___GENPT___GLenum___GENPT___GLchar___GENPT__ +#define glGetActiveAttrib_FORMAT FORMAT_void_GLuint_GLuint_GLsizei_GLsizei___GENPT___GLint___GENPT___GLenum___GENPT___GLchar___GENPT__ +#define glGetActiveUniform_INDEX 81 +#define glGetActiveUniform_RETURN void +#define glGetActiveUniform_ARG_NAMES program, index, bufSize, length, size, type, name +#define glGetActiveUniform_ARG_EXPAND GLuint program, GLuint index, GLsizei bufSize, GLsizei * length, GLint * size, GLenum * type, GLchar * name +#define glGetActiveUniform_PACKED PACKED_void_GLuint_GLuint_GLsizei_GLsizei___GENPT___GLint___GENPT___GLenum___GENPT___GLchar___GENPT__ +#define glGetActiveUniform_INDEXED INDEXED_void_GLuint_GLuint_GLsizei_GLsizei___GENPT___GLint___GENPT___GLenum___GENPT___GLchar___GENPT__ +#define glGetActiveUniform_FORMAT FORMAT_void_GLuint_GLuint_GLsizei_GLsizei___GENPT___GLint___GENPT___GLenum___GENPT___GLchar___GENPT__ +#define glGetAttachedShaders_INDEX 82 +#define glGetAttachedShaders_RETURN void +#define glGetAttachedShaders_ARG_NAMES program, maxCount, count, obj +#define glGetAttachedShaders_ARG_EXPAND GLuint program, GLsizei maxCount, GLsizei * count, GLuint * obj +#define glGetAttachedShaders_PACKED PACKED_void_GLuint_GLsizei_GLsizei___GENPT___GLuint___GENPT__ +#define glGetAttachedShaders_INDEXED INDEXED_void_GLuint_GLsizei_GLsizei___GENPT___GLuint___GENPT__ +#define glGetAttachedShaders_FORMAT FORMAT_void_GLuint_GLsizei_GLsizei___GENPT___GLuint___GENPT__ +#define glGetAttribLocation_INDEX 83 +#define glGetAttribLocation_RETURN GLint +#define glGetAttribLocation_ARG_NAMES program, name +#define glGetAttribLocation_ARG_EXPAND GLuint program, const GLchar * name +#define glGetAttribLocation_PACKED PACKED_GLint_GLuint_const_GLchar___GENPT__ +#define glGetAttribLocation_INDEXED INDEXED_GLint_GLuint_const_GLchar___GENPT__ +#define glGetAttribLocation_FORMAT FORMAT_GLint_GLuint_const_GLchar___GENPT__ +#define glGetBooleanv_INDEX 84 +#define glGetBooleanv_RETURN void +#define glGetBooleanv_ARG_NAMES pname, params +#define glGetBooleanv_ARG_EXPAND GLenum pname, GLboolean * params +#define glGetBooleanv_PACKED PACKED_void_GLenum_GLboolean___GENPT__ +#define glGetBooleanv_INDEXED INDEXED_void_GLenum_GLboolean___GENPT__ +#define glGetBooleanv_FORMAT FORMAT_void_GLenum_GLboolean___GENPT__ +#define glGetBufferParameteriv_INDEX 85 +#define glGetBufferParameteriv_RETURN void +#define glGetBufferParameteriv_ARG_NAMES target, pname, params +#define glGetBufferParameteriv_ARG_EXPAND GLenum target, GLenum pname, GLint * params +#define glGetBufferParameteriv_PACKED PACKED_void_GLenum_GLenum_GLint___GENPT__ +#define glGetBufferParameteriv_INDEXED INDEXED_void_GLenum_GLenum_GLint___GENPT__ +#define glGetBufferParameteriv_FORMAT FORMAT_void_GLenum_GLenum_GLint___GENPT__ +#define glGetClipPlanef_INDEX 86 +#define glGetClipPlanef_RETURN void +#define glGetClipPlanef_ARG_NAMES plane, equation +#define glGetClipPlanef_ARG_EXPAND GLenum plane, GLfloat * equation +#define glGetClipPlanef_PACKED PACKED_void_GLenum_GLfloat___GENPT__ +#define glGetClipPlanef_INDEXED INDEXED_void_GLenum_GLfloat___GENPT__ +#define glGetClipPlanef_FORMAT FORMAT_void_GLenum_GLfloat___GENPT__ +#define glGetClipPlanex_INDEX 87 +#define glGetClipPlanex_RETURN void +#define glGetClipPlanex_ARG_NAMES plane, equation +#define glGetClipPlanex_ARG_EXPAND GLenum plane, GLfixed * equation +#define glGetClipPlanex_PACKED PACKED_void_GLenum_GLfixed___GENPT__ +#define glGetClipPlanex_INDEXED INDEXED_void_GLenum_GLfixed___GENPT__ +#define glGetClipPlanex_FORMAT FORMAT_void_GLenum_GLfixed___GENPT__ +#define glGetError_INDEX 88 +#define glGetError_RETURN GLenum +#define glGetError_ARG_NAMES +#define glGetError_ARG_EXPAND +#define glGetError_PACKED PACKED_GLenum +#define glGetError_INDEXED INDEXED_GLenum +#define glGetError_FORMAT FORMAT_GLenum +#define glGetFixedv_INDEX 89 +#define glGetFixedv_RETURN void +#define glGetFixedv_ARG_NAMES pname, params +#define glGetFixedv_ARG_EXPAND GLenum pname, GLfixed * params +#define glGetFixedv_PACKED PACKED_void_GLenum_GLfixed___GENPT__ +#define glGetFixedv_INDEXED INDEXED_void_GLenum_GLfixed___GENPT__ +#define glGetFixedv_FORMAT FORMAT_void_GLenum_GLfixed___GENPT__ +#define glGetFloatv_INDEX 90 +#define glGetFloatv_RETURN void +#define glGetFloatv_ARG_NAMES pname, params +#define glGetFloatv_ARG_EXPAND GLenum pname, GLfloat * params +#define glGetFloatv_PACKED PACKED_void_GLenum_GLfloat___GENPT__ +#define glGetFloatv_INDEXED INDEXED_void_GLenum_GLfloat___GENPT__ +#define glGetFloatv_FORMAT FORMAT_void_GLenum_GLfloat___GENPT__ +#define glGetFramebufferAttachmentParameteriv_INDEX 91 +#define glGetFramebufferAttachmentParameteriv_RETURN void +#define glGetFramebufferAttachmentParameteriv_ARG_NAMES target, attachment, pname, params +#define glGetFramebufferAttachmentParameteriv_ARG_EXPAND GLenum target, GLenum attachment, GLenum pname, GLint * params +#define glGetFramebufferAttachmentParameteriv_PACKED PACKED_void_GLenum_GLenum_GLenum_GLint___GENPT__ +#define glGetFramebufferAttachmentParameteriv_INDEXED INDEXED_void_GLenum_GLenum_GLenum_GLint___GENPT__ +#define glGetFramebufferAttachmentParameteriv_FORMAT FORMAT_void_GLenum_GLenum_GLenum_GLint___GENPT__ +#define glGetIntegerv_INDEX 92 +#define glGetIntegerv_RETURN void +#define glGetIntegerv_ARG_NAMES pname, params +#define glGetIntegerv_ARG_EXPAND GLenum pname, GLint * params +#define glGetIntegerv_PACKED PACKED_void_GLenum_GLint___GENPT__ +#define glGetIntegerv_INDEXED INDEXED_void_GLenum_GLint___GENPT__ +#define glGetIntegerv_FORMAT FORMAT_void_GLenum_GLint___GENPT__ +#define glGetLightfv_INDEX 93 +#define glGetLightfv_RETURN void +#define glGetLightfv_ARG_NAMES light, pname, params +#define glGetLightfv_ARG_EXPAND GLenum light, GLenum pname, GLfloat * params +#define glGetLightfv_PACKED PACKED_void_GLenum_GLenum_GLfloat___GENPT__ +#define glGetLightfv_INDEXED INDEXED_void_GLenum_GLenum_GLfloat___GENPT__ +#define glGetLightfv_FORMAT FORMAT_void_GLenum_GLenum_GLfloat___GENPT__ +#define glGetLightxv_INDEX 94 +#define glGetLightxv_RETURN void +#define glGetLightxv_ARG_NAMES light, pname, params +#define glGetLightxv_ARG_EXPAND GLenum light, GLenum pname, GLfixed * params +#define glGetLightxv_PACKED PACKED_void_GLenum_GLenum_GLfixed___GENPT__ +#define glGetLightxv_INDEXED INDEXED_void_GLenum_GLenum_GLfixed___GENPT__ +#define glGetLightxv_FORMAT FORMAT_void_GLenum_GLenum_GLfixed___GENPT__ +#define glGetMaterialfv_INDEX 95 +#define glGetMaterialfv_RETURN void +#define glGetMaterialfv_ARG_NAMES face, pname, params +#define glGetMaterialfv_ARG_EXPAND GLenum face, GLenum pname, GLfloat * params +#define glGetMaterialfv_PACKED PACKED_void_GLenum_GLenum_GLfloat___GENPT__ +#define glGetMaterialfv_INDEXED INDEXED_void_GLenum_GLenum_GLfloat___GENPT__ +#define glGetMaterialfv_FORMAT FORMAT_void_GLenum_GLenum_GLfloat___GENPT__ +#define glGetMaterialxv_INDEX 96 +#define glGetMaterialxv_RETURN void +#define glGetMaterialxv_ARG_NAMES face, pname, params +#define glGetMaterialxv_ARG_EXPAND GLenum face, GLenum pname, GLfixed * params +#define glGetMaterialxv_PACKED PACKED_void_GLenum_GLenum_GLfixed___GENPT__ +#define glGetMaterialxv_INDEXED INDEXED_void_GLenum_GLenum_GLfixed___GENPT__ +#define glGetMaterialxv_FORMAT FORMAT_void_GLenum_GLenum_GLfixed___GENPT__ +#define glGetPointerv_INDEX 97 +#define glGetPointerv_RETURN void +#define glGetPointerv_ARG_NAMES pname, params +#define glGetPointerv_ARG_EXPAND GLenum pname, GLvoid ** params +#define glGetPointerv_PACKED PACKED_void_GLenum_GLvoid___GENPT____GENPT__ +#define glGetPointerv_INDEXED INDEXED_void_GLenum_GLvoid___GENPT____GENPT__ +#define glGetPointerv_FORMAT FORMAT_void_GLenum_GLvoid___GENPT____GENPT__ +#define glGetProgramInfoLog_INDEX 98 +#define glGetProgramInfoLog_RETURN void +#define glGetProgramInfoLog_ARG_NAMES program, bufSize, length, infoLog +#define glGetProgramInfoLog_ARG_EXPAND GLuint program, GLsizei bufSize, GLsizei * length, GLchar * infoLog +#define glGetProgramInfoLog_PACKED PACKED_void_GLuint_GLsizei_GLsizei___GENPT___GLchar___GENPT__ +#define glGetProgramInfoLog_INDEXED INDEXED_void_GLuint_GLsizei_GLsizei___GENPT___GLchar___GENPT__ +#define glGetProgramInfoLog_FORMAT FORMAT_void_GLuint_GLsizei_GLsizei___GENPT___GLchar___GENPT__ +#define glGetProgramiv_INDEX 99 +#define glGetProgramiv_RETURN void +#define glGetProgramiv_ARG_NAMES program, pname, params +#define glGetProgramiv_ARG_EXPAND GLuint program, GLenum pname, GLint * params +#define glGetProgramiv_PACKED PACKED_void_GLuint_GLenum_GLint___GENPT__ +#define glGetProgramiv_INDEXED INDEXED_void_GLuint_GLenum_GLint___GENPT__ +#define glGetProgramiv_FORMAT FORMAT_void_GLuint_GLenum_GLint___GENPT__ +#define glGetRenderbufferParameteriv_INDEX 100 +#define glGetRenderbufferParameteriv_RETURN void +#define glGetRenderbufferParameteriv_ARG_NAMES target, pname, params +#define glGetRenderbufferParameteriv_ARG_EXPAND GLenum target, GLenum pname, GLint * params +#define glGetRenderbufferParameteriv_PACKED PACKED_void_GLenum_GLenum_GLint___GENPT__ +#define glGetRenderbufferParameteriv_INDEXED INDEXED_void_GLenum_GLenum_GLint___GENPT__ +#define glGetRenderbufferParameteriv_FORMAT FORMAT_void_GLenum_GLenum_GLint___GENPT__ +#define glGetShaderInfoLog_INDEX 101 +#define glGetShaderInfoLog_RETURN void +#define glGetShaderInfoLog_ARG_NAMES shader, bufSize, length, infoLog +#define glGetShaderInfoLog_ARG_EXPAND GLuint shader, GLsizei bufSize, GLsizei * length, GLchar * infoLog +#define glGetShaderInfoLog_PACKED PACKED_void_GLuint_GLsizei_GLsizei___GENPT___GLchar___GENPT__ +#define glGetShaderInfoLog_INDEXED INDEXED_void_GLuint_GLsizei_GLsizei___GENPT___GLchar___GENPT__ +#define glGetShaderInfoLog_FORMAT FORMAT_void_GLuint_GLsizei_GLsizei___GENPT___GLchar___GENPT__ +#define glGetShaderPrecisionFormat_INDEX 102 +#define glGetShaderPrecisionFormat_RETURN void +#define glGetShaderPrecisionFormat_ARG_NAMES shadertype, precisiontype, range, precision +#define glGetShaderPrecisionFormat_ARG_EXPAND GLenum shadertype, GLenum precisiontype, GLint * range, GLint * precision +#define glGetShaderPrecisionFormat_PACKED PACKED_void_GLenum_GLenum_GLint___GENPT___GLint___GENPT__ +#define glGetShaderPrecisionFormat_INDEXED INDEXED_void_GLenum_GLenum_GLint___GENPT___GLint___GENPT__ +#define glGetShaderPrecisionFormat_FORMAT FORMAT_void_GLenum_GLenum_GLint___GENPT___GLint___GENPT__ +#define glGetShaderSource_INDEX 103 +#define glGetShaderSource_RETURN void +#define glGetShaderSource_ARG_NAMES shader, bufSize, length, source +#define glGetShaderSource_ARG_EXPAND GLuint shader, GLsizei bufSize, GLsizei * length, GLchar * source +#define glGetShaderSource_PACKED PACKED_void_GLuint_GLsizei_GLsizei___GENPT___GLchar___GENPT__ +#define glGetShaderSource_INDEXED INDEXED_void_GLuint_GLsizei_GLsizei___GENPT___GLchar___GENPT__ +#define glGetShaderSource_FORMAT FORMAT_void_GLuint_GLsizei_GLsizei___GENPT___GLchar___GENPT__ +#define glGetShaderiv_INDEX 104 +#define glGetShaderiv_RETURN void +#define glGetShaderiv_ARG_NAMES shader, pname, params +#define glGetShaderiv_ARG_EXPAND GLuint shader, GLenum pname, GLint * params +#define glGetShaderiv_PACKED PACKED_void_GLuint_GLenum_GLint___GENPT__ +#define glGetShaderiv_INDEXED INDEXED_void_GLuint_GLenum_GLint___GENPT__ +#define glGetShaderiv_FORMAT FORMAT_void_GLuint_GLenum_GLint___GENPT__ +#define glGetString_INDEX 105 +#define glGetString_RETURN const GLubyte * +#define glGetString_ARG_NAMES name +#define glGetString_ARG_EXPAND GLenum name +#define glGetString_PACKED PACKED_const_GLubyte___GENPT___GLenum +#define glGetString_INDEXED INDEXED_const_GLubyte___GENPT___GLenum +#define glGetString_FORMAT FORMAT_const_GLubyte___GENPT___GLenum +#define glGetTexEnvfv_INDEX 106 +#define glGetTexEnvfv_RETURN void +#define glGetTexEnvfv_ARG_NAMES target, pname, params +#define glGetTexEnvfv_ARG_EXPAND GLenum target, GLenum pname, GLfloat * params +#define glGetTexEnvfv_PACKED PACKED_void_GLenum_GLenum_GLfloat___GENPT__ +#define glGetTexEnvfv_INDEXED INDEXED_void_GLenum_GLenum_GLfloat___GENPT__ +#define glGetTexEnvfv_FORMAT FORMAT_void_GLenum_GLenum_GLfloat___GENPT__ +#define glGetTexEnviv_INDEX 107 +#define glGetTexEnviv_RETURN void +#define glGetTexEnviv_ARG_NAMES target, pname, params +#define glGetTexEnviv_ARG_EXPAND GLenum target, GLenum pname, GLint * params +#define glGetTexEnviv_PACKED PACKED_void_GLenum_GLenum_GLint___GENPT__ +#define glGetTexEnviv_INDEXED INDEXED_void_GLenum_GLenum_GLint___GENPT__ +#define glGetTexEnviv_FORMAT FORMAT_void_GLenum_GLenum_GLint___GENPT__ +#define glGetTexEnvxv_INDEX 108 +#define glGetTexEnvxv_RETURN void +#define glGetTexEnvxv_ARG_NAMES target, pname, params +#define glGetTexEnvxv_ARG_EXPAND GLenum target, GLenum pname, GLfixed * params +#define glGetTexEnvxv_PACKED PACKED_void_GLenum_GLenum_GLfixed___GENPT__ +#define glGetTexEnvxv_INDEXED INDEXED_void_GLenum_GLenum_GLfixed___GENPT__ +#define glGetTexEnvxv_FORMAT FORMAT_void_GLenum_GLenum_GLfixed___GENPT__ +#define glGetTexParameterfv_INDEX 109 +#define glGetTexParameterfv_RETURN void +#define glGetTexParameterfv_ARG_NAMES target, pname, params +#define glGetTexParameterfv_ARG_EXPAND GLenum target, GLenum pname, GLfloat * params +#define glGetTexParameterfv_PACKED PACKED_void_GLenum_GLenum_GLfloat___GENPT__ +#define glGetTexParameterfv_INDEXED INDEXED_void_GLenum_GLenum_GLfloat___GENPT__ +#define glGetTexParameterfv_FORMAT FORMAT_void_GLenum_GLenum_GLfloat___GENPT__ +#define glGetTexParameteriv_INDEX 110 +#define glGetTexParameteriv_RETURN void +#define glGetTexParameteriv_ARG_NAMES target, pname, params +#define glGetTexParameteriv_ARG_EXPAND GLenum target, GLenum pname, GLint * params +#define glGetTexParameteriv_PACKED PACKED_void_GLenum_GLenum_GLint___GENPT__ +#define glGetTexParameteriv_INDEXED INDEXED_void_GLenum_GLenum_GLint___GENPT__ +#define glGetTexParameteriv_FORMAT FORMAT_void_GLenum_GLenum_GLint___GENPT__ +#define glGetTexParameterxv_INDEX 111 +#define glGetTexParameterxv_RETURN void +#define glGetTexParameterxv_ARG_NAMES target, pname, params +#define glGetTexParameterxv_ARG_EXPAND GLenum target, GLenum pname, GLfixed * params +#define glGetTexParameterxv_PACKED PACKED_void_GLenum_GLenum_GLfixed___GENPT__ +#define glGetTexParameterxv_INDEXED INDEXED_void_GLenum_GLenum_GLfixed___GENPT__ +#define glGetTexParameterxv_FORMAT FORMAT_void_GLenum_GLenum_GLfixed___GENPT__ +#define glGetUniformLocation_INDEX 112 +#define glGetUniformLocation_RETURN GLint +#define glGetUniformLocation_ARG_NAMES program, name +#define glGetUniformLocation_ARG_EXPAND GLuint program, const GLchar * name +#define glGetUniformLocation_PACKED PACKED_GLint_GLuint_const_GLchar___GENPT__ +#define glGetUniformLocation_INDEXED INDEXED_GLint_GLuint_const_GLchar___GENPT__ +#define glGetUniformLocation_FORMAT FORMAT_GLint_GLuint_const_GLchar___GENPT__ +#define glGetUniformfv_INDEX 113 +#define glGetUniformfv_RETURN void +#define glGetUniformfv_ARG_NAMES program, location, params +#define glGetUniformfv_ARG_EXPAND GLuint program, GLint location, GLfloat * params +#define glGetUniformfv_PACKED PACKED_void_GLuint_GLint_GLfloat___GENPT__ +#define glGetUniformfv_INDEXED INDEXED_void_GLuint_GLint_GLfloat___GENPT__ +#define glGetUniformfv_FORMAT FORMAT_void_GLuint_GLint_GLfloat___GENPT__ +#define glGetUniformiv_INDEX 114 +#define glGetUniformiv_RETURN void +#define glGetUniformiv_ARG_NAMES program, location, params +#define glGetUniformiv_ARG_EXPAND GLuint program, GLint location, GLint * params +#define glGetUniformiv_PACKED PACKED_void_GLuint_GLint_GLint___GENPT__ +#define glGetUniformiv_INDEXED INDEXED_void_GLuint_GLint_GLint___GENPT__ +#define glGetUniformiv_FORMAT FORMAT_void_GLuint_GLint_GLint___GENPT__ +#define glGetVertexAttribPointerv_INDEX 115 +#define glGetVertexAttribPointerv_RETURN void +#define glGetVertexAttribPointerv_ARG_NAMES index, pname, pointer +#define glGetVertexAttribPointerv_ARG_EXPAND GLuint index, GLenum pname, GLvoid ** pointer +#define glGetVertexAttribPointerv_PACKED PACKED_void_GLuint_GLenum_GLvoid___GENPT____GENPT__ +#define glGetVertexAttribPointerv_INDEXED INDEXED_void_GLuint_GLenum_GLvoid___GENPT____GENPT__ +#define glGetVertexAttribPointerv_FORMAT FORMAT_void_GLuint_GLenum_GLvoid___GENPT____GENPT__ +#define glGetVertexAttribfv_INDEX 116 +#define glGetVertexAttribfv_RETURN void +#define glGetVertexAttribfv_ARG_NAMES index, pname, params +#define glGetVertexAttribfv_ARG_EXPAND GLuint index, GLenum pname, GLfloat * params +#define glGetVertexAttribfv_PACKED PACKED_void_GLuint_GLenum_GLfloat___GENPT__ +#define glGetVertexAttribfv_INDEXED INDEXED_void_GLuint_GLenum_GLfloat___GENPT__ +#define glGetVertexAttribfv_FORMAT FORMAT_void_GLuint_GLenum_GLfloat___GENPT__ +#define glGetVertexAttribiv_INDEX 117 +#define glGetVertexAttribiv_RETURN void +#define glGetVertexAttribiv_ARG_NAMES index, pname, params +#define glGetVertexAttribiv_ARG_EXPAND GLuint index, GLenum pname, GLint * params +#define glGetVertexAttribiv_PACKED PACKED_void_GLuint_GLenum_GLint___GENPT__ +#define glGetVertexAttribiv_INDEXED INDEXED_void_GLuint_GLenum_GLint___GENPT__ +#define glGetVertexAttribiv_FORMAT FORMAT_void_GLuint_GLenum_GLint___GENPT__ +#define glHint_INDEX 118 +#define glHint_RETURN void +#define glHint_ARG_NAMES target, mode +#define glHint_ARG_EXPAND GLenum target, GLenum mode +#define glHint_PACKED PACKED_void_GLenum_GLenum +#define glHint_INDEXED INDEXED_void_GLenum_GLenum +#define glHint_FORMAT FORMAT_void_GLenum_GLenum +#define glIsBuffer_INDEX 119 +#define glIsBuffer_RETURN GLboolean +#define glIsBuffer_ARG_NAMES buffer +#define glIsBuffer_ARG_EXPAND GLuint buffer +#define glIsBuffer_PACKED PACKED_GLboolean_GLuint +#define glIsBuffer_INDEXED INDEXED_GLboolean_GLuint +#define glIsBuffer_FORMAT FORMAT_GLboolean_GLuint +#define glIsEnabled_INDEX 120 +#define glIsEnabled_RETURN GLboolean +#define glIsEnabled_ARG_NAMES cap +#define glIsEnabled_ARG_EXPAND GLenum cap +#define glIsEnabled_PACKED PACKED_GLboolean_GLenum +#define glIsEnabled_INDEXED INDEXED_GLboolean_GLenum +#define glIsEnabled_FORMAT FORMAT_GLboolean_GLenum +#define glIsFramebuffer_INDEX 121 +#define glIsFramebuffer_RETURN GLboolean +#define glIsFramebuffer_ARG_NAMES framebuffer +#define glIsFramebuffer_ARG_EXPAND GLuint framebuffer +#define glIsFramebuffer_PACKED PACKED_GLboolean_GLuint +#define glIsFramebuffer_INDEXED INDEXED_GLboolean_GLuint +#define glIsFramebuffer_FORMAT FORMAT_GLboolean_GLuint +#define glIsProgram_INDEX 122 +#define glIsProgram_RETURN GLboolean +#define glIsProgram_ARG_NAMES program +#define glIsProgram_ARG_EXPAND GLuint program +#define glIsProgram_PACKED PACKED_GLboolean_GLuint +#define glIsProgram_INDEXED INDEXED_GLboolean_GLuint +#define glIsProgram_FORMAT FORMAT_GLboolean_GLuint +#define glIsRenderbuffer_INDEX 123 +#define glIsRenderbuffer_RETURN GLboolean +#define glIsRenderbuffer_ARG_NAMES renderbuffer +#define glIsRenderbuffer_ARG_EXPAND GLuint renderbuffer +#define glIsRenderbuffer_PACKED PACKED_GLboolean_GLuint +#define glIsRenderbuffer_INDEXED INDEXED_GLboolean_GLuint +#define glIsRenderbuffer_FORMAT FORMAT_GLboolean_GLuint +#define glIsShader_INDEX 124 +#define glIsShader_RETURN GLboolean +#define glIsShader_ARG_NAMES shader +#define glIsShader_ARG_EXPAND GLuint shader +#define glIsShader_PACKED PACKED_GLboolean_GLuint +#define glIsShader_INDEXED INDEXED_GLboolean_GLuint +#define glIsShader_FORMAT FORMAT_GLboolean_GLuint +#define glIsTexture_INDEX 125 +#define glIsTexture_RETURN GLboolean +#define glIsTexture_ARG_NAMES texture +#define glIsTexture_ARG_EXPAND GLuint texture +#define glIsTexture_PACKED PACKED_GLboolean_GLuint +#define glIsTexture_INDEXED INDEXED_GLboolean_GLuint +#define glIsTexture_FORMAT FORMAT_GLboolean_GLuint +#define glLightModelf_INDEX 126 +#define glLightModelf_RETURN void +#define glLightModelf_ARG_NAMES pname, param +#define glLightModelf_ARG_EXPAND GLenum pname, GLfloat param +#define glLightModelf_PACKED PACKED_void_GLenum_GLfloat +#define glLightModelf_INDEXED INDEXED_void_GLenum_GLfloat +#define glLightModelf_FORMAT FORMAT_void_GLenum_GLfloat +#define glLightModelfv_INDEX 127 +#define glLightModelfv_RETURN void +#define glLightModelfv_ARG_NAMES pname, params +#define glLightModelfv_ARG_EXPAND GLenum pname, const GLfloat * params +#define glLightModelfv_PACKED PACKED_void_GLenum_const_GLfloat___GENPT__ +#define glLightModelfv_INDEXED INDEXED_void_GLenum_const_GLfloat___GENPT__ +#define glLightModelfv_FORMAT FORMAT_void_GLenum_const_GLfloat___GENPT__ +#define glLightModelx_INDEX 128 +#define glLightModelx_RETURN void +#define glLightModelx_ARG_NAMES pname, param +#define glLightModelx_ARG_EXPAND GLenum pname, GLfixed param +#define glLightModelx_PACKED PACKED_void_GLenum_GLfixed +#define glLightModelx_INDEXED INDEXED_void_GLenum_GLfixed +#define glLightModelx_FORMAT FORMAT_void_GLenum_GLfixed +#define glLightModelxv_INDEX 129 +#define glLightModelxv_RETURN void +#define glLightModelxv_ARG_NAMES pname, params +#define glLightModelxv_ARG_EXPAND GLenum pname, const GLfixed * params +#define glLightModelxv_PACKED PACKED_void_GLenum_const_GLfixed___GENPT__ +#define glLightModelxv_INDEXED INDEXED_void_GLenum_const_GLfixed___GENPT__ +#define glLightModelxv_FORMAT FORMAT_void_GLenum_const_GLfixed___GENPT__ +#define glLightf_INDEX 130 +#define glLightf_RETURN void +#define glLightf_ARG_NAMES light, pname, param +#define glLightf_ARG_EXPAND GLenum light, GLenum pname, GLfloat param +#define glLightf_PACKED PACKED_void_GLenum_GLenum_GLfloat +#define glLightf_INDEXED INDEXED_void_GLenum_GLenum_GLfloat +#define glLightf_FORMAT FORMAT_void_GLenum_GLenum_GLfloat +#define glLightfv_INDEX 131 +#define glLightfv_RETURN void +#define glLightfv_ARG_NAMES light, pname, params +#define glLightfv_ARG_EXPAND GLenum light, GLenum pname, const GLfloat * params +#define glLightfv_PACKED PACKED_void_GLenum_GLenum_const_GLfloat___GENPT__ +#define glLightfv_INDEXED INDEXED_void_GLenum_GLenum_const_GLfloat___GENPT__ +#define glLightfv_FORMAT FORMAT_void_GLenum_GLenum_const_GLfloat___GENPT__ +#define glLightx_INDEX 132 +#define glLightx_RETURN void +#define glLightx_ARG_NAMES light, pname, param +#define glLightx_ARG_EXPAND GLenum light, GLenum pname, GLfixed param +#define glLightx_PACKED PACKED_void_GLenum_GLenum_GLfixed +#define glLightx_INDEXED INDEXED_void_GLenum_GLenum_GLfixed +#define glLightx_FORMAT FORMAT_void_GLenum_GLenum_GLfixed +#define glLightxv_INDEX 133 +#define glLightxv_RETURN void +#define glLightxv_ARG_NAMES light, pname, params +#define glLightxv_ARG_EXPAND GLenum light, GLenum pname, const GLfixed * params +#define glLightxv_PACKED PACKED_void_GLenum_GLenum_const_GLfixed___GENPT__ +#define glLightxv_INDEXED INDEXED_void_GLenum_GLenum_const_GLfixed___GENPT__ +#define glLightxv_FORMAT FORMAT_void_GLenum_GLenum_const_GLfixed___GENPT__ +#define glLineWidth_INDEX 134 +#define glLineWidth_RETURN void +#define glLineWidth_ARG_NAMES width +#define glLineWidth_ARG_EXPAND GLfloat width +#define glLineWidth_PACKED PACKED_void_GLfloat +#define glLineWidth_INDEXED INDEXED_void_GLfloat +#define glLineWidth_FORMAT FORMAT_void_GLfloat +#define glLineWidthx_INDEX 135 +#define glLineWidthx_RETURN void +#define glLineWidthx_ARG_NAMES width +#define glLineWidthx_ARG_EXPAND GLfixed width +#define glLineWidthx_PACKED PACKED_void_GLfixed +#define glLineWidthx_INDEXED INDEXED_void_GLfixed +#define glLineWidthx_FORMAT FORMAT_void_GLfixed +#define glLinkProgram_INDEX 136 +#define glLinkProgram_RETURN void +#define glLinkProgram_ARG_NAMES program +#define glLinkProgram_ARG_EXPAND GLuint program +#define glLinkProgram_PACKED PACKED_void_GLuint +#define glLinkProgram_INDEXED INDEXED_void_GLuint +#define glLinkProgram_FORMAT FORMAT_void_GLuint +#define glLoadIdentity_INDEX 137 +#define glLoadIdentity_RETURN void +#define glLoadIdentity_ARG_NAMES +#define glLoadIdentity_ARG_EXPAND +#define glLoadIdentity_PACKED PACKED_void +#define glLoadIdentity_INDEXED INDEXED_void +#define glLoadIdentity_FORMAT FORMAT_void +#define glLoadMatrixf_INDEX 138 +#define glLoadMatrixf_RETURN void +#define glLoadMatrixf_ARG_NAMES m +#define glLoadMatrixf_ARG_EXPAND const GLfloat * m +#define glLoadMatrixf_PACKED PACKED_void_const_GLfloat___GENPT__ +#define glLoadMatrixf_INDEXED INDEXED_void_const_GLfloat___GENPT__ +#define glLoadMatrixf_FORMAT FORMAT_void_const_GLfloat___GENPT__ +#define glLoadMatrixx_INDEX 139 +#define glLoadMatrixx_RETURN void +#define glLoadMatrixx_ARG_NAMES m +#define glLoadMatrixx_ARG_EXPAND const GLfixed * m +#define glLoadMatrixx_PACKED PACKED_void_const_GLfixed___GENPT__ +#define glLoadMatrixx_INDEXED INDEXED_void_const_GLfixed___GENPT__ +#define glLoadMatrixx_FORMAT FORMAT_void_const_GLfixed___GENPT__ +#define glLogicOp_INDEX 140 +#define glLogicOp_RETURN void +#define glLogicOp_ARG_NAMES opcode +#define glLogicOp_ARG_EXPAND GLenum opcode +#define glLogicOp_PACKED PACKED_void_GLenum +#define glLogicOp_INDEXED INDEXED_void_GLenum +#define glLogicOp_FORMAT FORMAT_void_GLenum +#define glMaterialf_INDEX 141 +#define glMaterialf_RETURN void +#define glMaterialf_ARG_NAMES face, pname, param +#define glMaterialf_ARG_EXPAND GLenum face, GLenum pname, GLfloat param +#define glMaterialf_PACKED PACKED_void_GLenum_GLenum_GLfloat +#define glMaterialf_INDEXED INDEXED_void_GLenum_GLenum_GLfloat +#define glMaterialf_FORMAT FORMAT_void_GLenum_GLenum_GLfloat +#define glMaterialfv_INDEX 142 +#define glMaterialfv_RETURN void +#define glMaterialfv_ARG_NAMES face, pname, params +#define glMaterialfv_ARG_EXPAND GLenum face, GLenum pname, const GLfloat * params +#define glMaterialfv_PACKED PACKED_void_GLenum_GLenum_const_GLfloat___GENPT__ +#define glMaterialfv_INDEXED INDEXED_void_GLenum_GLenum_const_GLfloat___GENPT__ +#define glMaterialfv_FORMAT FORMAT_void_GLenum_GLenum_const_GLfloat___GENPT__ +#define glMaterialx_INDEX 143 +#define glMaterialx_RETURN void +#define glMaterialx_ARG_NAMES face, pname, param +#define glMaterialx_ARG_EXPAND GLenum face, GLenum pname, GLfixed param +#define glMaterialx_PACKED PACKED_void_GLenum_GLenum_GLfixed +#define glMaterialx_INDEXED INDEXED_void_GLenum_GLenum_GLfixed +#define glMaterialx_FORMAT FORMAT_void_GLenum_GLenum_GLfixed +#define glMaterialxv_INDEX 144 +#define glMaterialxv_RETURN void +#define glMaterialxv_ARG_NAMES face, pname, params +#define glMaterialxv_ARG_EXPAND GLenum face, GLenum pname, const GLfixed * params +#define glMaterialxv_PACKED PACKED_void_GLenum_GLenum_const_GLfixed___GENPT__ +#define glMaterialxv_INDEXED INDEXED_void_GLenum_GLenum_const_GLfixed___GENPT__ +#define glMaterialxv_FORMAT FORMAT_void_GLenum_GLenum_const_GLfixed___GENPT__ +#define glMatrixMode_INDEX 145 +#define glMatrixMode_RETURN void +#define glMatrixMode_ARG_NAMES mode +#define glMatrixMode_ARG_EXPAND GLenum mode +#define glMatrixMode_PACKED PACKED_void_GLenum +#define glMatrixMode_INDEXED INDEXED_void_GLenum +#define glMatrixMode_FORMAT FORMAT_void_GLenum +#define glMultMatrixf_INDEX 146 +#define glMultMatrixf_RETURN void +#define glMultMatrixf_ARG_NAMES m +#define glMultMatrixf_ARG_EXPAND const GLfloat * m +#define glMultMatrixf_PACKED PACKED_void_const_GLfloat___GENPT__ +#define glMultMatrixf_INDEXED INDEXED_void_const_GLfloat___GENPT__ +#define glMultMatrixf_FORMAT FORMAT_void_const_GLfloat___GENPT__ +#define glMultMatrixx_INDEX 147 +#define glMultMatrixx_RETURN void +#define glMultMatrixx_ARG_NAMES m +#define glMultMatrixx_ARG_EXPAND const GLfixed * m +#define glMultMatrixx_PACKED PACKED_void_const_GLfixed___GENPT__ +#define glMultMatrixx_INDEXED INDEXED_void_const_GLfixed___GENPT__ +#define glMultMatrixx_FORMAT FORMAT_void_const_GLfixed___GENPT__ +#define glMultiDrawArrays_INDEX 148 +#define glMultiDrawArrays_RETURN void +#define glMultiDrawArrays_ARG_NAMES mode, first, count, primcount +#define glMultiDrawArrays_ARG_EXPAND GLenum mode, const GLint * first, const GLsizei * count, GLsizei primcount +#define glMultiDrawArrays_PACKED PACKED_void_GLenum_const_GLint___GENPT___const_GLsizei___GENPT___GLsizei +#define glMultiDrawArrays_INDEXED INDEXED_void_GLenum_const_GLint___GENPT___const_GLsizei___GENPT___GLsizei +#define glMultiDrawArrays_FORMAT FORMAT_void_GLenum_const_GLint___GENPT___const_GLsizei___GENPT___GLsizei +#define glMultiDrawElements_INDEX 149 +#define glMultiDrawElements_RETURN void +#define glMultiDrawElements_ARG_NAMES mode, count, type, indices, primcount +#define glMultiDrawElements_ARG_EXPAND GLenum mode, GLsizei * count, GLenum type, const void * const * indices, GLsizei primcount +#define glMultiDrawElements_PACKED PACKED_void_GLenum_GLsizei___GENPT___GLenum_const_void___GENPT___const___GENPT___GLsizei +#define glMultiDrawElements_INDEXED INDEXED_void_GLenum_GLsizei___GENPT___GLenum_const_void___GENPT___const___GENPT___GLsizei +#define glMultiDrawElements_FORMAT FORMAT_void_GLenum_GLsizei___GENPT___GLenum_const_void___GENPT___const___GENPT___GLsizei +#define glMultiTexCoord4f_INDEX 150 +#define glMultiTexCoord4f_RETURN void +#define glMultiTexCoord4f_ARG_NAMES target, s, t, r, q +#define glMultiTexCoord4f_ARG_EXPAND GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q +#define glMultiTexCoord4f_PACKED PACKED_void_GLenum_GLfloat_GLfloat_GLfloat_GLfloat +#define glMultiTexCoord4f_INDEXED INDEXED_void_GLenum_GLfloat_GLfloat_GLfloat_GLfloat +#define glMultiTexCoord4f_FORMAT FORMAT_void_GLenum_GLfloat_GLfloat_GLfloat_GLfloat +#define glMultiTexCoord4x_INDEX 151 +#define glMultiTexCoord4x_RETURN void +#define glMultiTexCoord4x_ARG_NAMES target, s, t, r, q +#define glMultiTexCoord4x_ARG_EXPAND GLenum target, GLfixed s, GLfixed t, GLfixed r, GLfixed q +#define glMultiTexCoord4x_PACKED PACKED_void_GLenum_GLfixed_GLfixed_GLfixed_GLfixed +#define glMultiTexCoord4x_INDEXED INDEXED_void_GLenum_GLfixed_GLfixed_GLfixed_GLfixed +#define glMultiTexCoord4x_FORMAT FORMAT_void_GLenum_GLfixed_GLfixed_GLfixed_GLfixed +#define glNormal3f_INDEX 152 +#define glNormal3f_RETURN void +#define glNormal3f_ARG_NAMES nx, ny, nz +#define glNormal3f_ARG_EXPAND GLfloat nx, GLfloat ny, GLfloat nz +#define glNormal3f_PACKED PACKED_void_GLfloat_GLfloat_GLfloat +#define glNormal3f_INDEXED INDEXED_void_GLfloat_GLfloat_GLfloat +#define glNormal3f_FORMAT FORMAT_void_GLfloat_GLfloat_GLfloat +#define glNormal3x_INDEX 153 +#define glNormal3x_RETURN void +#define glNormal3x_ARG_NAMES nx, ny, nz +#define glNormal3x_ARG_EXPAND GLfixed nx, GLfixed ny, GLfixed nz +#define glNormal3x_PACKED PACKED_void_GLfixed_GLfixed_GLfixed +#define glNormal3x_INDEXED INDEXED_void_GLfixed_GLfixed_GLfixed +#define glNormal3x_FORMAT FORMAT_void_GLfixed_GLfixed_GLfixed +#define glNormalPointer_INDEX 154 +#define glNormalPointer_RETURN void +#define glNormalPointer_ARG_NAMES type, stride, pointer +#define glNormalPointer_ARG_EXPAND GLenum type, GLsizei stride, const GLvoid * pointer +#define glNormalPointer_PACKED PACKED_void_GLenum_GLsizei_const_GLvoid___GENPT__ +#define glNormalPointer_INDEXED INDEXED_void_GLenum_GLsizei_const_GLvoid___GENPT__ +#define glNormalPointer_FORMAT FORMAT_void_GLenum_GLsizei_const_GLvoid___GENPT__ +#define glOrthof_INDEX 155 +#define glOrthof_RETURN void +#define glOrthof_ARG_NAMES left, right, bottom, top, near, far +#define glOrthof_ARG_EXPAND GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat near, GLfloat far +#define glOrthof_PACKED PACKED_void_GLfloat_GLfloat_GLfloat_GLfloat_GLfloat_GLfloat +#define glOrthof_INDEXED INDEXED_void_GLfloat_GLfloat_GLfloat_GLfloat_GLfloat_GLfloat +#define glOrthof_FORMAT FORMAT_void_GLfloat_GLfloat_GLfloat_GLfloat_GLfloat_GLfloat +#define glOrthox_INDEX 156 +#define glOrthox_RETURN void +#define glOrthox_ARG_NAMES left, right, bottom, top, near, far +#define glOrthox_ARG_EXPAND GLfixed left, GLfixed right, GLfixed bottom, GLfixed top, GLfixed near, GLfixed far +#define glOrthox_PACKED PACKED_void_GLfixed_GLfixed_GLfixed_GLfixed_GLfixed_GLfixed +#define glOrthox_INDEXED INDEXED_void_GLfixed_GLfixed_GLfixed_GLfixed_GLfixed_GLfixed +#define glOrthox_FORMAT FORMAT_void_GLfixed_GLfixed_GLfixed_GLfixed_GLfixed_GLfixed +#define glPixelStorei_INDEX 157 +#define glPixelStorei_RETURN void +#define glPixelStorei_ARG_NAMES pname, param +#define glPixelStorei_ARG_EXPAND GLenum pname, GLint param +#define glPixelStorei_PACKED PACKED_void_GLenum_GLint +#define glPixelStorei_INDEXED INDEXED_void_GLenum_GLint +#define glPixelStorei_FORMAT FORMAT_void_GLenum_GLint +#define glPointParameterf_INDEX 158 +#define glPointParameterf_RETURN void +#define glPointParameterf_ARG_NAMES pname, param +#define glPointParameterf_ARG_EXPAND GLenum pname, GLfloat param +#define glPointParameterf_PACKED PACKED_void_GLenum_GLfloat +#define glPointParameterf_INDEXED INDEXED_void_GLenum_GLfloat +#define glPointParameterf_FORMAT FORMAT_void_GLenum_GLfloat +#define glPointParameterfv_INDEX 159 +#define glPointParameterfv_RETURN void +#define glPointParameterfv_ARG_NAMES pname, params +#define glPointParameterfv_ARG_EXPAND GLenum pname, const GLfloat * params +#define glPointParameterfv_PACKED PACKED_void_GLenum_const_GLfloat___GENPT__ +#define glPointParameterfv_INDEXED INDEXED_void_GLenum_const_GLfloat___GENPT__ +#define glPointParameterfv_FORMAT FORMAT_void_GLenum_const_GLfloat___GENPT__ +#define glPointParameterx_INDEX 160 +#define glPointParameterx_RETURN void +#define glPointParameterx_ARG_NAMES pname, param +#define glPointParameterx_ARG_EXPAND GLenum pname, GLfixed param +#define glPointParameterx_PACKED PACKED_void_GLenum_GLfixed +#define glPointParameterx_INDEXED INDEXED_void_GLenum_GLfixed +#define glPointParameterx_FORMAT FORMAT_void_GLenum_GLfixed +#define glPointParameterxv_INDEX 161 +#define glPointParameterxv_RETURN void +#define glPointParameterxv_ARG_NAMES pname, params +#define glPointParameterxv_ARG_EXPAND GLenum pname, const GLfixed * params +#define glPointParameterxv_PACKED PACKED_void_GLenum_const_GLfixed___GENPT__ +#define glPointParameterxv_INDEXED INDEXED_void_GLenum_const_GLfixed___GENPT__ +#define glPointParameterxv_FORMAT FORMAT_void_GLenum_const_GLfixed___GENPT__ +#define glPointSize_INDEX 162 +#define glPointSize_RETURN void +#define glPointSize_ARG_NAMES size +#define glPointSize_ARG_EXPAND GLfloat size +#define glPointSize_PACKED PACKED_void_GLfloat +#define glPointSize_INDEXED INDEXED_void_GLfloat +#define glPointSize_FORMAT FORMAT_void_GLfloat +#define glPointSizePointerOES_INDEX 163 +#define glPointSizePointerOES_RETURN void +#define glPointSizePointerOES_ARG_NAMES type, stride, pointer +#define glPointSizePointerOES_ARG_EXPAND GLenum type, GLsizei stride, const GLvoid * pointer +#define glPointSizePointerOES_PACKED PACKED_void_GLenum_GLsizei_const_GLvoid___GENPT__ +#define glPointSizePointerOES_INDEXED INDEXED_void_GLenum_GLsizei_const_GLvoid___GENPT__ +#define glPointSizePointerOES_FORMAT FORMAT_void_GLenum_GLsizei_const_GLvoid___GENPT__ +#define glPointSizex_INDEX 164 +#define glPointSizex_RETURN void +#define glPointSizex_ARG_NAMES size +#define glPointSizex_ARG_EXPAND GLfixed size +#define glPointSizex_PACKED PACKED_void_GLfixed +#define glPointSizex_INDEXED INDEXED_void_GLfixed +#define glPointSizex_FORMAT FORMAT_void_GLfixed +#define glPolygonOffset_INDEX 165 +#define glPolygonOffset_RETURN void +#define glPolygonOffset_ARG_NAMES factor, units +#define glPolygonOffset_ARG_EXPAND GLfloat factor, GLfloat units +#define glPolygonOffset_PACKED PACKED_void_GLfloat_GLfloat +#define glPolygonOffset_INDEXED INDEXED_void_GLfloat_GLfloat +#define glPolygonOffset_FORMAT FORMAT_void_GLfloat_GLfloat +#define glPolygonOffsetx_INDEX 166 +#define glPolygonOffsetx_RETURN void +#define glPolygonOffsetx_ARG_NAMES factor, units +#define glPolygonOffsetx_ARG_EXPAND GLfixed factor, GLfixed units +#define glPolygonOffsetx_PACKED PACKED_void_GLfixed_GLfixed +#define glPolygonOffsetx_INDEXED INDEXED_void_GLfixed_GLfixed +#define glPolygonOffsetx_FORMAT FORMAT_void_GLfixed_GLfixed +#define glPopMatrix_INDEX 167 +#define glPopMatrix_RETURN void +#define glPopMatrix_ARG_NAMES +#define glPopMatrix_ARG_EXPAND +#define glPopMatrix_PACKED PACKED_void +#define glPopMatrix_INDEXED INDEXED_void +#define glPopMatrix_FORMAT FORMAT_void +#define glPushMatrix_INDEX 168 +#define glPushMatrix_RETURN void +#define glPushMatrix_ARG_NAMES +#define glPushMatrix_ARG_EXPAND +#define glPushMatrix_PACKED PACKED_void +#define glPushMatrix_INDEXED INDEXED_void +#define glPushMatrix_FORMAT FORMAT_void +#define glReadPixels_INDEX 169 +#define glReadPixels_RETURN void +#define glReadPixels_ARG_NAMES x, y, width, height, format, type, pixels +#define glReadPixels_ARG_EXPAND GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid * pixels +#define glReadPixels_PACKED PACKED_void_GLint_GLint_GLsizei_GLsizei_GLenum_GLenum_GLvoid___GENPT__ +#define glReadPixels_INDEXED INDEXED_void_GLint_GLint_GLsizei_GLsizei_GLenum_GLenum_GLvoid___GENPT__ +#define glReadPixels_FORMAT FORMAT_void_GLint_GLint_GLsizei_GLsizei_GLenum_GLenum_GLvoid___GENPT__ +#define glReleaseShaderCompiler_INDEX 170 +#define glReleaseShaderCompiler_RETURN void +#define glReleaseShaderCompiler_ARG_NAMES +#define glReleaseShaderCompiler_ARG_EXPAND +#define glReleaseShaderCompiler_PACKED PACKED_void +#define glReleaseShaderCompiler_INDEXED INDEXED_void +#define glReleaseShaderCompiler_FORMAT FORMAT_void +#define glRenderbufferStorage_INDEX 171 +#define glRenderbufferStorage_RETURN void +#define glRenderbufferStorage_ARG_NAMES target, internalformat, width, height +#define glRenderbufferStorage_ARG_EXPAND GLenum target, GLenum internalformat, GLsizei width, GLsizei height +#define glRenderbufferStorage_PACKED PACKED_void_GLenum_GLenum_GLsizei_GLsizei +#define glRenderbufferStorage_INDEXED INDEXED_void_GLenum_GLenum_GLsizei_GLsizei +#define glRenderbufferStorage_FORMAT FORMAT_void_GLenum_GLenum_GLsizei_GLsizei +#define glRotatef_INDEX 172 +#define glRotatef_RETURN void +#define glRotatef_ARG_NAMES angle, x, y, z +#define glRotatef_ARG_EXPAND GLfloat angle, GLfloat x, GLfloat y, GLfloat z +#define glRotatef_PACKED PACKED_void_GLfloat_GLfloat_GLfloat_GLfloat +#define glRotatef_INDEXED INDEXED_void_GLfloat_GLfloat_GLfloat_GLfloat +#define glRotatef_FORMAT FORMAT_void_GLfloat_GLfloat_GLfloat_GLfloat +#define glRotatex_INDEX 173 +#define glRotatex_RETURN void +#define glRotatex_ARG_NAMES angle, x, y, z +#define glRotatex_ARG_EXPAND GLfixed angle, GLfixed x, GLfixed y, GLfixed z +#define glRotatex_PACKED PACKED_void_GLfixed_GLfixed_GLfixed_GLfixed +#define glRotatex_INDEXED INDEXED_void_GLfixed_GLfixed_GLfixed_GLfixed +#define glRotatex_FORMAT FORMAT_void_GLfixed_GLfixed_GLfixed_GLfixed +#define glSampleCoverage_INDEX 174 +#define glSampleCoverage_RETURN void +#define glSampleCoverage_ARG_NAMES value, invert +#define glSampleCoverage_ARG_EXPAND GLclampf value, GLboolean invert +#define glSampleCoverage_PACKED PACKED_void_GLclampf_GLboolean +#define glSampleCoverage_INDEXED INDEXED_void_GLclampf_GLboolean +#define glSampleCoverage_FORMAT FORMAT_void_GLclampf_GLboolean +#define glSampleCoveragex_INDEX 175 +#define glSampleCoveragex_RETURN void +#define glSampleCoveragex_ARG_NAMES value, invert +#define glSampleCoveragex_ARG_EXPAND GLclampx value, GLboolean invert +#define glSampleCoveragex_PACKED PACKED_void_GLclampx_GLboolean +#define glSampleCoveragex_INDEXED INDEXED_void_GLclampx_GLboolean +#define glSampleCoveragex_FORMAT FORMAT_void_GLclampx_GLboolean +#define glScalef_INDEX 176 +#define glScalef_RETURN void +#define glScalef_ARG_NAMES x, y, z +#define glScalef_ARG_EXPAND GLfloat x, GLfloat y, GLfloat z +#define glScalef_PACKED PACKED_void_GLfloat_GLfloat_GLfloat +#define glScalef_INDEXED INDEXED_void_GLfloat_GLfloat_GLfloat +#define glScalef_FORMAT FORMAT_void_GLfloat_GLfloat_GLfloat +#define glScalex_INDEX 177 +#define glScalex_RETURN void +#define glScalex_ARG_NAMES x, y, z +#define glScalex_ARG_EXPAND GLfixed x, GLfixed y, GLfixed z +#define glScalex_PACKED PACKED_void_GLfixed_GLfixed_GLfixed +#define glScalex_INDEXED INDEXED_void_GLfixed_GLfixed_GLfixed +#define glScalex_FORMAT FORMAT_void_GLfixed_GLfixed_GLfixed +#define glScissor_INDEX 178 +#define glScissor_RETURN void +#define glScissor_ARG_NAMES x, y, width, height +#define glScissor_ARG_EXPAND GLint x, GLint y, GLsizei width, GLsizei height +#define glScissor_PACKED PACKED_void_GLint_GLint_GLsizei_GLsizei +#define glScissor_INDEXED INDEXED_void_GLint_GLint_GLsizei_GLsizei +#define glScissor_FORMAT FORMAT_void_GLint_GLint_GLsizei_GLsizei +#define glShadeModel_INDEX 179 +#define glShadeModel_RETURN void +#define glShadeModel_ARG_NAMES mode +#define glShadeModel_ARG_EXPAND GLenum mode +#define glShadeModel_PACKED PACKED_void_GLenum +#define glShadeModel_INDEXED INDEXED_void_GLenum +#define glShadeModel_FORMAT FORMAT_void_GLenum +#define glShaderBinary_INDEX 180 +#define glShaderBinary_RETURN void +#define glShaderBinary_ARG_NAMES n, shaders, binaryformat, binary, length +#define glShaderBinary_ARG_EXPAND GLsizei n, const GLuint * shaders, GLenum binaryformat, const GLvoid * binary, GLsizei length +#define glShaderBinary_PACKED PACKED_void_GLsizei_const_GLuint___GENPT___GLenum_const_GLvoid___GENPT___GLsizei +#define glShaderBinary_INDEXED INDEXED_void_GLsizei_const_GLuint___GENPT___GLenum_const_GLvoid___GENPT___GLsizei +#define glShaderBinary_FORMAT FORMAT_void_GLsizei_const_GLuint___GENPT___GLenum_const_GLvoid___GENPT___GLsizei +#define glShaderSource_INDEX 181 +#define glShaderSource_RETURN void +#define glShaderSource_ARG_NAMES shader, count, string, length +#define glShaderSource_ARG_EXPAND GLuint shader, GLsizei count, const GLchar * const * string, const GLint * length +#define glShaderSource_PACKED PACKED_void_GLuint_GLsizei_const_GLchar___GENPT___const___GENPT___const_GLint___GENPT__ +#define glShaderSource_INDEXED INDEXED_void_GLuint_GLsizei_const_GLchar___GENPT___const___GENPT___const_GLint___GENPT__ +#define glShaderSource_FORMAT FORMAT_void_GLuint_GLsizei_const_GLchar___GENPT___const___GENPT___const_GLint___GENPT__ +#define glStencilFunc_INDEX 182 +#define glStencilFunc_RETURN void +#define glStencilFunc_ARG_NAMES func, ref, mask +#define glStencilFunc_ARG_EXPAND GLenum func, GLint ref, GLuint mask +#define glStencilFunc_PACKED PACKED_void_GLenum_GLint_GLuint +#define glStencilFunc_INDEXED INDEXED_void_GLenum_GLint_GLuint +#define glStencilFunc_FORMAT FORMAT_void_GLenum_GLint_GLuint +#define glStencilFuncSeparate_INDEX 183 +#define glStencilFuncSeparate_RETURN void +#define glStencilFuncSeparate_ARG_NAMES face, func, ref, mask +#define glStencilFuncSeparate_ARG_EXPAND GLenum face, GLenum func, GLint ref, GLuint mask +#define glStencilFuncSeparate_PACKED PACKED_void_GLenum_GLenum_GLint_GLuint +#define glStencilFuncSeparate_INDEXED INDEXED_void_GLenum_GLenum_GLint_GLuint +#define glStencilFuncSeparate_FORMAT FORMAT_void_GLenum_GLenum_GLint_GLuint +#define glStencilMask_INDEX 184 +#define glStencilMask_RETURN void +#define glStencilMask_ARG_NAMES mask +#define glStencilMask_ARG_EXPAND GLuint mask +#define glStencilMask_PACKED PACKED_void_GLuint +#define glStencilMask_INDEXED INDEXED_void_GLuint +#define glStencilMask_FORMAT FORMAT_void_GLuint +#define glStencilMaskSeparate_INDEX 185 +#define glStencilMaskSeparate_RETURN void +#define glStencilMaskSeparate_ARG_NAMES face, mask +#define glStencilMaskSeparate_ARG_EXPAND GLenum face, GLuint mask +#define glStencilMaskSeparate_PACKED PACKED_void_GLenum_GLuint +#define glStencilMaskSeparate_INDEXED INDEXED_void_GLenum_GLuint +#define glStencilMaskSeparate_FORMAT FORMAT_void_GLenum_GLuint +#define glStencilOp_INDEX 186 +#define glStencilOp_RETURN void +#define glStencilOp_ARG_NAMES fail, zfail, zpass +#define glStencilOp_ARG_EXPAND GLenum fail, GLenum zfail, GLenum zpass +#define glStencilOp_PACKED PACKED_void_GLenum_GLenum_GLenum +#define glStencilOp_INDEXED INDEXED_void_GLenum_GLenum_GLenum +#define glStencilOp_FORMAT FORMAT_void_GLenum_GLenum_GLenum +#define glStencilOpSeparate_INDEX 187 +#define glStencilOpSeparate_RETURN void +#define glStencilOpSeparate_ARG_NAMES face, sfail, zfail, zpass +#define glStencilOpSeparate_ARG_EXPAND GLenum face, GLenum sfail, GLenum zfail, GLenum zpass +#define glStencilOpSeparate_PACKED PACKED_void_GLenum_GLenum_GLenum_GLenum +#define glStencilOpSeparate_INDEXED INDEXED_void_GLenum_GLenum_GLenum_GLenum +#define glStencilOpSeparate_FORMAT FORMAT_void_GLenum_GLenum_GLenum_GLenum +#define glTexCoordPointer_INDEX 188 +#define glTexCoordPointer_RETURN void +#define glTexCoordPointer_ARG_NAMES size, type, stride, pointer +#define glTexCoordPointer_ARG_EXPAND GLint size, GLenum type, GLsizei stride, const GLvoid * pointer +#define glTexCoordPointer_PACKED PACKED_void_GLint_GLenum_GLsizei_const_GLvoid___GENPT__ +#define glTexCoordPointer_INDEXED INDEXED_void_GLint_GLenum_GLsizei_const_GLvoid___GENPT__ +#define glTexCoordPointer_FORMAT FORMAT_void_GLint_GLenum_GLsizei_const_GLvoid___GENPT__ +#define glTexEnvf_INDEX 189 +#define glTexEnvf_RETURN void +#define glTexEnvf_ARG_NAMES target, pname, param +#define glTexEnvf_ARG_EXPAND GLenum target, GLenum pname, GLfloat param +#define glTexEnvf_PACKED PACKED_void_GLenum_GLenum_GLfloat +#define glTexEnvf_INDEXED INDEXED_void_GLenum_GLenum_GLfloat +#define glTexEnvf_FORMAT FORMAT_void_GLenum_GLenum_GLfloat +#define glTexEnvfv_INDEX 190 +#define glTexEnvfv_RETURN void +#define glTexEnvfv_ARG_NAMES target, pname, params +#define glTexEnvfv_ARG_EXPAND GLenum target, GLenum pname, const GLfloat * params +#define glTexEnvfv_PACKED PACKED_void_GLenum_GLenum_const_GLfloat___GENPT__ +#define glTexEnvfv_INDEXED INDEXED_void_GLenum_GLenum_const_GLfloat___GENPT__ +#define glTexEnvfv_FORMAT FORMAT_void_GLenum_GLenum_const_GLfloat___GENPT__ +#define glTexEnvi_INDEX 191 +#define glTexEnvi_RETURN void +#define glTexEnvi_ARG_NAMES target, pname, param +#define glTexEnvi_ARG_EXPAND GLenum target, GLenum pname, GLint param +#define glTexEnvi_PACKED PACKED_void_GLenum_GLenum_GLint +#define glTexEnvi_INDEXED INDEXED_void_GLenum_GLenum_GLint +#define glTexEnvi_FORMAT FORMAT_void_GLenum_GLenum_GLint +#define glTexEnviv_INDEX 192 +#define glTexEnviv_RETURN void +#define glTexEnviv_ARG_NAMES target, pname, params +#define glTexEnviv_ARG_EXPAND GLenum target, GLenum pname, const GLint * params +#define glTexEnviv_PACKED PACKED_void_GLenum_GLenum_const_GLint___GENPT__ +#define glTexEnviv_INDEXED INDEXED_void_GLenum_GLenum_const_GLint___GENPT__ +#define glTexEnviv_FORMAT FORMAT_void_GLenum_GLenum_const_GLint___GENPT__ +#define glTexEnvx_INDEX 193 +#define glTexEnvx_RETURN void +#define glTexEnvx_ARG_NAMES target, pname, param +#define glTexEnvx_ARG_EXPAND GLenum target, GLenum pname, GLfixed param +#define glTexEnvx_PACKED PACKED_void_GLenum_GLenum_GLfixed +#define glTexEnvx_INDEXED INDEXED_void_GLenum_GLenum_GLfixed +#define glTexEnvx_FORMAT FORMAT_void_GLenum_GLenum_GLfixed +#define glTexEnvxv_INDEX 194 +#define glTexEnvxv_RETURN void +#define glTexEnvxv_ARG_NAMES target, pname, params +#define glTexEnvxv_ARG_EXPAND GLenum target, GLenum pname, const GLfixed * params +#define glTexEnvxv_PACKED PACKED_void_GLenum_GLenum_const_GLfixed___GENPT__ +#define glTexEnvxv_INDEXED INDEXED_void_GLenum_GLenum_const_GLfixed___GENPT__ +#define glTexEnvxv_FORMAT FORMAT_void_GLenum_GLenum_const_GLfixed___GENPT__ +#define glTexGenfv_INDEX 195 +#define glTexGenfv_RETURN void +#define glTexGenfv_ARG_NAMES coord, pname, params +#define glTexGenfv_ARG_EXPAND GLenum coord, GLenum pname, const GLfloat * params +#define glTexGenfv_PACKED PACKED_void_GLenum_GLenum_const_GLfloat___GENPT__ +#define glTexGenfv_INDEXED INDEXED_void_GLenum_GLenum_const_GLfloat___GENPT__ +#define glTexGenfv_FORMAT FORMAT_void_GLenum_GLenum_const_GLfloat___GENPT__ +#define glTexGeni_INDEX 196 +#define glTexGeni_RETURN void +#define glTexGeni_ARG_NAMES coord, pname, param +#define glTexGeni_ARG_EXPAND GLenum coord, GLenum pname, GLint param +#define glTexGeni_PACKED PACKED_void_GLenum_GLenum_GLint +#define glTexGeni_INDEXED INDEXED_void_GLenum_GLenum_GLint +#define glTexGeni_FORMAT FORMAT_void_GLenum_GLenum_GLint +#define glTexImage2D_INDEX 197 +#define glTexImage2D_RETURN void +#define glTexImage2D_ARG_NAMES target, level, internalformat, width, height, border, format, type, data +#define glTexImage2D_ARG_EXPAND GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid * data +#define glTexImage2D_PACKED PACKED_void_GLenum_GLint_GLint_GLsizei_GLsizei_GLint_GLenum_GLenum_const_GLvoid___GENPT__ +#define glTexImage2D_INDEXED INDEXED_void_GLenum_GLint_GLint_GLsizei_GLsizei_GLint_GLenum_GLenum_const_GLvoid___GENPT__ +#define glTexImage2D_FORMAT FORMAT_void_GLenum_GLint_GLint_GLsizei_GLsizei_GLint_GLenum_GLenum_const_GLvoid___GENPT__ +#define glTexParameterf_INDEX 198 +#define glTexParameterf_RETURN void +#define glTexParameterf_ARG_NAMES target, pname, param +#define glTexParameterf_ARG_EXPAND GLenum target, GLenum pname, GLfloat param +#define glTexParameterf_PACKED PACKED_void_GLenum_GLenum_GLfloat +#define glTexParameterf_INDEXED INDEXED_void_GLenum_GLenum_GLfloat +#define glTexParameterf_FORMAT FORMAT_void_GLenum_GLenum_GLfloat +#define glTexParameterfv_INDEX 199 +#define glTexParameterfv_RETURN void +#define glTexParameterfv_ARG_NAMES target, pname, params +#define glTexParameterfv_ARG_EXPAND GLenum target, GLenum pname, const GLfloat * params +#define glTexParameterfv_PACKED PACKED_void_GLenum_GLenum_const_GLfloat___GENPT__ +#define glTexParameterfv_INDEXED INDEXED_void_GLenum_GLenum_const_GLfloat___GENPT__ +#define glTexParameterfv_FORMAT FORMAT_void_GLenum_GLenum_const_GLfloat___GENPT__ +#define glTexParameteri_INDEX 200 +#define glTexParameteri_RETURN void +#define glTexParameteri_ARG_NAMES target, pname, param +#define glTexParameteri_ARG_EXPAND GLenum target, GLenum pname, GLint param +#define glTexParameteri_PACKED PACKED_void_GLenum_GLenum_GLint +#define glTexParameteri_INDEXED INDEXED_void_GLenum_GLenum_GLint +#define glTexParameteri_FORMAT FORMAT_void_GLenum_GLenum_GLint +#define glTexParameteriv_INDEX 201 +#define glTexParameteriv_RETURN void +#define glTexParameteriv_ARG_NAMES target, pname, params +#define glTexParameteriv_ARG_EXPAND GLenum target, GLenum pname, const GLint * params +#define glTexParameteriv_PACKED PACKED_void_GLenum_GLenum_const_GLint___GENPT__ +#define glTexParameteriv_INDEXED INDEXED_void_GLenum_GLenum_const_GLint___GENPT__ +#define glTexParameteriv_FORMAT FORMAT_void_GLenum_GLenum_const_GLint___GENPT__ +#define glTexParameterx_INDEX 202 +#define glTexParameterx_RETURN void +#define glTexParameterx_ARG_NAMES target, pname, param +#define glTexParameterx_ARG_EXPAND GLenum target, GLenum pname, GLfixed param +#define glTexParameterx_PACKED PACKED_void_GLenum_GLenum_GLfixed +#define glTexParameterx_INDEXED INDEXED_void_GLenum_GLenum_GLfixed +#define glTexParameterx_FORMAT FORMAT_void_GLenum_GLenum_GLfixed +#define glTexParameterxv_INDEX 203 +#define glTexParameterxv_RETURN void +#define glTexParameterxv_ARG_NAMES target, pname, params +#define glTexParameterxv_ARG_EXPAND GLenum target, GLenum pname, const GLfixed * params +#define glTexParameterxv_PACKED PACKED_void_GLenum_GLenum_const_GLfixed___GENPT__ +#define glTexParameterxv_INDEXED INDEXED_void_GLenum_GLenum_const_GLfixed___GENPT__ +#define glTexParameterxv_FORMAT FORMAT_void_GLenum_GLenum_const_GLfixed___GENPT__ +#define glTexSubImage2D_INDEX 204 +#define glTexSubImage2D_RETURN void +#define glTexSubImage2D_ARG_NAMES target, level, xoffset, yoffset, width, height, format, type, data +#define glTexSubImage2D_ARG_EXPAND GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid * data +#define glTexSubImage2D_PACKED PACKED_void_GLenum_GLint_GLint_GLint_GLsizei_GLsizei_GLenum_GLenum_const_GLvoid___GENPT__ +#define glTexSubImage2D_INDEXED INDEXED_void_GLenum_GLint_GLint_GLint_GLsizei_GLsizei_GLenum_GLenum_const_GLvoid___GENPT__ +#define glTexSubImage2D_FORMAT FORMAT_void_GLenum_GLint_GLint_GLint_GLsizei_GLsizei_GLenum_GLenum_const_GLvoid___GENPT__ +#define glTranslatef_INDEX 205 +#define glTranslatef_RETURN void +#define glTranslatef_ARG_NAMES x, y, z +#define glTranslatef_ARG_EXPAND GLfloat x, GLfloat y, GLfloat z +#define glTranslatef_PACKED PACKED_void_GLfloat_GLfloat_GLfloat +#define glTranslatef_INDEXED INDEXED_void_GLfloat_GLfloat_GLfloat +#define glTranslatef_FORMAT FORMAT_void_GLfloat_GLfloat_GLfloat +#define glTranslatex_INDEX 206 +#define glTranslatex_RETURN void +#define glTranslatex_ARG_NAMES x, y, z +#define glTranslatex_ARG_EXPAND GLfixed x, GLfixed y, GLfixed z +#define glTranslatex_PACKED PACKED_void_GLfixed_GLfixed_GLfixed +#define glTranslatex_INDEXED INDEXED_void_GLfixed_GLfixed_GLfixed +#define glTranslatex_FORMAT FORMAT_void_GLfixed_GLfixed_GLfixed +#define glUniform1f_INDEX 207 +#define glUniform1f_RETURN void +#define glUniform1f_ARG_NAMES location, v0 +#define glUniform1f_ARG_EXPAND GLint location, GLfloat v0 +#define glUniform1f_PACKED PACKED_void_GLint_GLfloat +#define glUniform1f_INDEXED INDEXED_void_GLint_GLfloat +#define glUniform1f_FORMAT FORMAT_void_GLint_GLfloat +#define glUniform1fv_INDEX 208 +#define glUniform1fv_RETURN void +#define glUniform1fv_ARG_NAMES location, count, value +#define glUniform1fv_ARG_EXPAND GLint location, GLsizei count, const GLfloat * value +#define glUniform1fv_PACKED PACKED_void_GLint_GLsizei_const_GLfloat___GENPT__ +#define glUniform1fv_INDEXED INDEXED_void_GLint_GLsizei_const_GLfloat___GENPT__ +#define glUniform1fv_FORMAT FORMAT_void_GLint_GLsizei_const_GLfloat___GENPT__ +#define glUniform1i_INDEX 209 +#define glUniform1i_RETURN void +#define glUniform1i_ARG_NAMES location, v0 +#define glUniform1i_ARG_EXPAND GLint location, GLint v0 +#define glUniform1i_PACKED PACKED_void_GLint_GLint +#define glUniform1i_INDEXED INDEXED_void_GLint_GLint +#define glUniform1i_FORMAT FORMAT_void_GLint_GLint +#define glUniform1iv_INDEX 210 +#define glUniform1iv_RETURN void +#define glUniform1iv_ARG_NAMES location, count, value +#define glUniform1iv_ARG_EXPAND GLint location, GLsizei count, const GLint * value +#define glUniform1iv_PACKED PACKED_void_GLint_GLsizei_const_GLint___GENPT__ +#define glUniform1iv_INDEXED INDEXED_void_GLint_GLsizei_const_GLint___GENPT__ +#define glUniform1iv_FORMAT FORMAT_void_GLint_GLsizei_const_GLint___GENPT__ +#define glUniform2f_INDEX 211 +#define glUniform2f_RETURN void +#define glUniform2f_ARG_NAMES location, v0, v1 +#define glUniform2f_ARG_EXPAND GLint location, GLfloat v0, GLfloat v1 +#define glUniform2f_PACKED PACKED_void_GLint_GLfloat_GLfloat +#define glUniform2f_INDEXED INDEXED_void_GLint_GLfloat_GLfloat +#define glUniform2f_FORMAT FORMAT_void_GLint_GLfloat_GLfloat +#define glUniform2fv_INDEX 212 +#define glUniform2fv_RETURN void +#define glUniform2fv_ARG_NAMES location, count, value +#define glUniform2fv_ARG_EXPAND GLint location, GLsizei count, const GLfloat * value +#define glUniform2fv_PACKED PACKED_void_GLint_GLsizei_const_GLfloat___GENPT__ +#define glUniform2fv_INDEXED INDEXED_void_GLint_GLsizei_const_GLfloat___GENPT__ +#define glUniform2fv_FORMAT FORMAT_void_GLint_GLsizei_const_GLfloat___GENPT__ +#define glUniform2i_INDEX 213 +#define glUniform2i_RETURN void +#define glUniform2i_ARG_NAMES location, v0, v1 +#define glUniform2i_ARG_EXPAND GLint location, GLint v0, GLint v1 +#define glUniform2i_PACKED PACKED_void_GLint_GLint_GLint +#define glUniform2i_INDEXED INDEXED_void_GLint_GLint_GLint +#define glUniform2i_FORMAT FORMAT_void_GLint_GLint_GLint +#define glUniform2iv_INDEX 214 +#define glUniform2iv_RETURN void +#define glUniform2iv_ARG_NAMES location, count, value +#define glUniform2iv_ARG_EXPAND GLint location, GLsizei count, const GLint * value +#define glUniform2iv_PACKED PACKED_void_GLint_GLsizei_const_GLint___GENPT__ +#define glUniform2iv_INDEXED INDEXED_void_GLint_GLsizei_const_GLint___GENPT__ +#define glUniform2iv_FORMAT FORMAT_void_GLint_GLsizei_const_GLint___GENPT__ +#define glUniform3f_INDEX 215 +#define glUniform3f_RETURN void +#define glUniform3f_ARG_NAMES location, v0, v1, v2 +#define glUniform3f_ARG_EXPAND GLint location, GLfloat v0, GLfloat v1, GLfloat v2 +#define glUniform3f_PACKED PACKED_void_GLint_GLfloat_GLfloat_GLfloat +#define glUniform3f_INDEXED INDEXED_void_GLint_GLfloat_GLfloat_GLfloat +#define glUniform3f_FORMAT FORMAT_void_GLint_GLfloat_GLfloat_GLfloat +#define glUniform3fv_INDEX 216 +#define glUniform3fv_RETURN void +#define glUniform3fv_ARG_NAMES location, count, value +#define glUniform3fv_ARG_EXPAND GLint location, GLsizei count, const GLfloat * value +#define glUniform3fv_PACKED PACKED_void_GLint_GLsizei_const_GLfloat___GENPT__ +#define glUniform3fv_INDEXED INDEXED_void_GLint_GLsizei_const_GLfloat___GENPT__ +#define glUniform3fv_FORMAT FORMAT_void_GLint_GLsizei_const_GLfloat___GENPT__ +#define glUniform3i_INDEX 217 +#define glUniform3i_RETURN void +#define glUniform3i_ARG_NAMES location, v0, v1, v2 +#define glUniform3i_ARG_EXPAND GLint location, GLint v0, GLint v1, GLint v2 +#define glUniform3i_PACKED PACKED_void_GLint_GLint_GLint_GLint +#define glUniform3i_INDEXED INDEXED_void_GLint_GLint_GLint_GLint +#define glUniform3i_FORMAT FORMAT_void_GLint_GLint_GLint_GLint +#define glUniform3iv_INDEX 218 +#define glUniform3iv_RETURN void +#define glUniform3iv_ARG_NAMES location, count, value +#define glUniform3iv_ARG_EXPAND GLint location, GLsizei count, const GLint * value +#define glUniform3iv_PACKED PACKED_void_GLint_GLsizei_const_GLint___GENPT__ +#define glUniform3iv_INDEXED INDEXED_void_GLint_GLsizei_const_GLint___GENPT__ +#define glUniform3iv_FORMAT FORMAT_void_GLint_GLsizei_const_GLint___GENPT__ +#define glUniform4f_INDEX 219 +#define glUniform4f_RETURN void +#define glUniform4f_ARG_NAMES location, v0, v1, v2, v3 +#define glUniform4f_ARG_EXPAND GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3 +#define glUniform4f_PACKED PACKED_void_GLint_GLfloat_GLfloat_GLfloat_GLfloat +#define glUniform4f_INDEXED INDEXED_void_GLint_GLfloat_GLfloat_GLfloat_GLfloat +#define glUniform4f_FORMAT FORMAT_void_GLint_GLfloat_GLfloat_GLfloat_GLfloat +#define glUniform4fv_INDEX 220 +#define glUniform4fv_RETURN void +#define glUniform4fv_ARG_NAMES location, count, value +#define glUniform4fv_ARG_EXPAND GLint location, GLsizei count, const GLfloat * value +#define glUniform4fv_PACKED PACKED_void_GLint_GLsizei_const_GLfloat___GENPT__ +#define glUniform4fv_INDEXED INDEXED_void_GLint_GLsizei_const_GLfloat___GENPT__ +#define glUniform4fv_FORMAT FORMAT_void_GLint_GLsizei_const_GLfloat___GENPT__ +#define glUniform4i_INDEX 221 +#define glUniform4i_RETURN void +#define glUniform4i_ARG_NAMES location, v0, v1, v2, v3 +#define glUniform4i_ARG_EXPAND GLint location, GLint v0, GLint v1, GLint v2, GLint v3 +#define glUniform4i_PACKED PACKED_void_GLint_GLint_GLint_GLint_GLint +#define glUniform4i_INDEXED INDEXED_void_GLint_GLint_GLint_GLint_GLint +#define glUniform4i_FORMAT FORMAT_void_GLint_GLint_GLint_GLint_GLint +#define glUniform4iv_INDEX 222 +#define glUniform4iv_RETURN void +#define glUniform4iv_ARG_NAMES location, count, value +#define glUniform4iv_ARG_EXPAND GLint location, GLsizei count, const GLint * value +#define glUniform4iv_PACKED PACKED_void_GLint_GLsizei_const_GLint___GENPT__ +#define glUniform4iv_INDEXED INDEXED_void_GLint_GLsizei_const_GLint___GENPT__ +#define glUniform4iv_FORMAT FORMAT_void_GLint_GLsizei_const_GLint___GENPT__ +#define glUniformMatrix2fv_INDEX 223 +#define glUniformMatrix2fv_RETURN void +#define glUniformMatrix2fv_ARG_NAMES location, count, transpose, value +#define glUniformMatrix2fv_ARG_EXPAND GLint location, GLsizei count, GLboolean transpose, const GLfloat * value +#define glUniformMatrix2fv_PACKED PACKED_void_GLint_GLsizei_GLboolean_const_GLfloat___GENPT__ +#define glUniformMatrix2fv_INDEXED INDEXED_void_GLint_GLsizei_GLboolean_const_GLfloat___GENPT__ +#define glUniformMatrix2fv_FORMAT FORMAT_void_GLint_GLsizei_GLboolean_const_GLfloat___GENPT__ +#define glUniformMatrix3fv_INDEX 224 +#define glUniformMatrix3fv_RETURN void +#define glUniformMatrix3fv_ARG_NAMES location, count, transpose, value +#define glUniformMatrix3fv_ARG_EXPAND GLint location, GLsizei count, GLboolean transpose, const GLfloat * value +#define glUniformMatrix3fv_PACKED PACKED_void_GLint_GLsizei_GLboolean_const_GLfloat___GENPT__ +#define glUniformMatrix3fv_INDEXED INDEXED_void_GLint_GLsizei_GLboolean_const_GLfloat___GENPT__ +#define glUniformMatrix3fv_FORMAT FORMAT_void_GLint_GLsizei_GLboolean_const_GLfloat___GENPT__ +#define glUniformMatrix4fv_INDEX 225 +#define glUniformMatrix4fv_RETURN void +#define glUniformMatrix4fv_ARG_NAMES location, count, transpose, value +#define glUniformMatrix4fv_ARG_EXPAND GLint location, GLsizei count, GLboolean transpose, const GLfloat * value +#define glUniformMatrix4fv_PACKED PACKED_void_GLint_GLsizei_GLboolean_const_GLfloat___GENPT__ +#define glUniformMatrix4fv_INDEXED INDEXED_void_GLint_GLsizei_GLboolean_const_GLfloat___GENPT__ +#define glUniformMatrix4fv_FORMAT FORMAT_void_GLint_GLsizei_GLboolean_const_GLfloat___GENPT__ +#define glUseProgram_INDEX 226 +#define glUseProgram_RETURN void +#define glUseProgram_ARG_NAMES program +#define glUseProgram_ARG_EXPAND GLuint program +#define glUseProgram_PACKED PACKED_void_GLuint +#define glUseProgram_INDEXED INDEXED_void_GLuint +#define glUseProgram_FORMAT FORMAT_void_GLuint +#define glValidateProgram_INDEX 227 +#define glValidateProgram_RETURN void +#define glValidateProgram_ARG_NAMES program +#define glValidateProgram_ARG_EXPAND GLuint program +#define glValidateProgram_PACKED PACKED_void_GLuint +#define glValidateProgram_INDEXED INDEXED_void_GLuint +#define glValidateProgram_FORMAT FORMAT_void_GLuint +#define glVertexAttrib1f_INDEX 228 +#define glVertexAttrib1f_RETURN void +#define glVertexAttrib1f_ARG_NAMES index, x +#define glVertexAttrib1f_ARG_EXPAND GLuint index, GLfloat x +#define glVertexAttrib1f_PACKED PACKED_void_GLuint_GLfloat +#define glVertexAttrib1f_INDEXED INDEXED_void_GLuint_GLfloat +#define glVertexAttrib1f_FORMAT FORMAT_void_GLuint_GLfloat +#define glVertexAttrib1fv_INDEX 229 +#define glVertexAttrib1fv_RETURN void +#define glVertexAttrib1fv_ARG_NAMES index, v +#define glVertexAttrib1fv_ARG_EXPAND GLuint index, const GLfloat * v +#define glVertexAttrib1fv_PACKED PACKED_void_GLuint_const_GLfloat___GENPT__ +#define glVertexAttrib1fv_INDEXED INDEXED_void_GLuint_const_GLfloat___GENPT__ +#define glVertexAttrib1fv_FORMAT FORMAT_void_GLuint_const_GLfloat___GENPT__ +#define glVertexAttrib2f_INDEX 230 +#define glVertexAttrib2f_RETURN void +#define glVertexAttrib2f_ARG_NAMES index, x, y +#define glVertexAttrib2f_ARG_EXPAND GLuint index, GLfloat x, GLfloat y +#define glVertexAttrib2f_PACKED PACKED_void_GLuint_GLfloat_GLfloat +#define glVertexAttrib2f_INDEXED INDEXED_void_GLuint_GLfloat_GLfloat +#define glVertexAttrib2f_FORMAT FORMAT_void_GLuint_GLfloat_GLfloat +#define glVertexAttrib2fv_INDEX 231 +#define glVertexAttrib2fv_RETURN void +#define glVertexAttrib2fv_ARG_NAMES index, v +#define glVertexAttrib2fv_ARG_EXPAND GLuint index, const GLfloat * v +#define glVertexAttrib2fv_PACKED PACKED_void_GLuint_const_GLfloat___GENPT__ +#define glVertexAttrib2fv_INDEXED INDEXED_void_GLuint_const_GLfloat___GENPT__ +#define glVertexAttrib2fv_FORMAT FORMAT_void_GLuint_const_GLfloat___GENPT__ +#define glVertexAttrib3f_INDEX 232 +#define glVertexAttrib3f_RETURN void +#define glVertexAttrib3f_ARG_NAMES index, x, y, z +#define glVertexAttrib3f_ARG_EXPAND GLuint index, GLfloat x, GLfloat y, GLfloat z +#define glVertexAttrib3f_PACKED PACKED_void_GLuint_GLfloat_GLfloat_GLfloat +#define glVertexAttrib3f_INDEXED INDEXED_void_GLuint_GLfloat_GLfloat_GLfloat +#define glVertexAttrib3f_FORMAT FORMAT_void_GLuint_GLfloat_GLfloat_GLfloat +#define glVertexAttrib3fv_INDEX 233 +#define glVertexAttrib3fv_RETURN void +#define glVertexAttrib3fv_ARG_NAMES index, v +#define glVertexAttrib3fv_ARG_EXPAND GLuint index, const GLfloat * v +#define glVertexAttrib3fv_PACKED PACKED_void_GLuint_const_GLfloat___GENPT__ +#define glVertexAttrib3fv_INDEXED INDEXED_void_GLuint_const_GLfloat___GENPT__ +#define glVertexAttrib3fv_FORMAT FORMAT_void_GLuint_const_GLfloat___GENPT__ +#define glVertexAttrib4f_INDEX 234 +#define glVertexAttrib4f_RETURN void +#define glVertexAttrib4f_ARG_NAMES index, x, y, z, w +#define glVertexAttrib4f_ARG_EXPAND GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w +#define glVertexAttrib4f_PACKED PACKED_void_GLuint_GLfloat_GLfloat_GLfloat_GLfloat +#define glVertexAttrib4f_INDEXED INDEXED_void_GLuint_GLfloat_GLfloat_GLfloat_GLfloat +#define glVertexAttrib4f_FORMAT FORMAT_void_GLuint_GLfloat_GLfloat_GLfloat_GLfloat +#define glVertexAttrib4fv_INDEX 235 +#define glVertexAttrib4fv_RETURN void +#define glVertexAttrib4fv_ARG_NAMES index, v +#define glVertexAttrib4fv_ARG_EXPAND GLuint index, const GLfloat * v +#define glVertexAttrib4fv_PACKED PACKED_void_GLuint_const_GLfloat___GENPT__ +#define glVertexAttrib4fv_INDEXED INDEXED_void_GLuint_const_GLfloat___GENPT__ +#define glVertexAttrib4fv_FORMAT FORMAT_void_GLuint_const_GLfloat___GENPT__ +#define glVertexAttribPointer_INDEX 236 +#define glVertexAttribPointer_RETURN void +#define glVertexAttribPointer_ARG_NAMES index, size, type, normalized, stride, pointer +#define glVertexAttribPointer_ARG_EXPAND GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid * pointer +#define glVertexAttribPointer_PACKED PACKED_void_GLuint_GLint_GLenum_GLboolean_GLsizei_const_GLvoid___GENPT__ +#define glVertexAttribPointer_INDEXED INDEXED_void_GLuint_GLint_GLenum_GLboolean_GLsizei_const_GLvoid___GENPT__ +#define glVertexAttribPointer_FORMAT FORMAT_void_GLuint_GLint_GLenum_GLboolean_GLsizei_const_GLvoid___GENPT__ +#define glVertexPointer_INDEX 237 +#define glVertexPointer_RETURN void +#define glVertexPointer_ARG_NAMES size, type, stride, pointer +#define glVertexPointer_ARG_EXPAND GLint size, GLenum type, GLsizei stride, const GLvoid * pointer +#define glVertexPointer_PACKED PACKED_void_GLint_GLenum_GLsizei_const_GLvoid___GENPT__ +#define glVertexPointer_INDEXED INDEXED_void_GLint_GLenum_GLsizei_const_GLvoid___GENPT__ +#define glVertexPointer_FORMAT FORMAT_void_GLint_GLenum_GLsizei_const_GLvoid___GENPT__ +#define glViewport_INDEX 238 +#define glViewport_RETURN void +#define glViewport_ARG_NAMES x, y, width, height +#define glViewport_ARG_EXPAND GLint x, GLint y, GLsizei width, GLsizei height +#define glViewport_PACKED PACKED_void_GLint_GLint_GLsizei_GLsizei +#define glViewport_INDEXED INDEXED_void_GLint_GLint_GLsizei_GLsizei +#define glViewport_FORMAT FORMAT_void_GLint_GLint_GLsizei_GLsizei + +void gl4es_glActiveTexture(glActiveTexture_ARG_EXPAND); +typedef void (*glActiveTexture_PTR)(glActiveTexture_ARG_EXPAND); +void gl4es_glAlphaFunc(glAlphaFunc_ARG_EXPAND); +typedef void (*glAlphaFunc_PTR)(glAlphaFunc_ARG_EXPAND); +void gl4es_glAlphaFuncx(glAlphaFuncx_ARG_EXPAND); +typedef void (*glAlphaFuncx_PTR)(glAlphaFuncx_ARG_EXPAND); +void gl4es_glAttachShader(glAttachShader_ARG_EXPAND); +typedef void (*glAttachShader_PTR)(glAttachShader_ARG_EXPAND); +void gl4es_glBindAttribLocation(glBindAttribLocation_ARG_EXPAND); +typedef void (*glBindAttribLocation_PTR)(glBindAttribLocation_ARG_EXPAND); +void gl4es_glBindBuffer(glBindBuffer_ARG_EXPAND); +typedef void (*glBindBuffer_PTR)(glBindBuffer_ARG_EXPAND); +void gl4es_glBindFramebuffer(glBindFramebuffer_ARG_EXPAND); +typedef void (*glBindFramebuffer_PTR)(glBindFramebuffer_ARG_EXPAND); +void gl4es_glBindRenderbuffer(glBindRenderbuffer_ARG_EXPAND); +typedef void (*glBindRenderbuffer_PTR)(glBindRenderbuffer_ARG_EXPAND); +void gl4es_glBindTexture(glBindTexture_ARG_EXPAND); +typedef void (*glBindTexture_PTR)(glBindTexture_ARG_EXPAND); +void gl4es_glBlendColor(glBlendColor_ARG_EXPAND); +typedef void (*glBlendColor_PTR)(glBlendColor_ARG_EXPAND); +void gl4es_glBlendEquation(glBlendEquation_ARG_EXPAND); +typedef void (*glBlendEquation_PTR)(glBlendEquation_ARG_EXPAND); +void gl4es_glBlendEquationSeparate(glBlendEquationSeparate_ARG_EXPAND); +typedef void (*glBlendEquationSeparate_PTR)(glBlendEquationSeparate_ARG_EXPAND); +void gl4es_glBlendFunc(glBlendFunc_ARG_EXPAND); +typedef void (*glBlendFunc_PTR)(glBlendFunc_ARG_EXPAND); +void gl4es_glBlendFuncSeparate(glBlendFuncSeparate_ARG_EXPAND); +typedef void (*glBlendFuncSeparate_PTR)(glBlendFuncSeparate_ARG_EXPAND); +void gl4es_glBufferData(glBufferData_ARG_EXPAND); +typedef void (*glBufferData_PTR)(glBufferData_ARG_EXPAND); +void gl4es_glBufferSubData(glBufferSubData_ARG_EXPAND); +typedef void (*glBufferSubData_PTR)(glBufferSubData_ARG_EXPAND); +GLenum gl4es_glCheckFramebufferStatus(glCheckFramebufferStatus_ARG_EXPAND); +typedef GLenum (*glCheckFramebufferStatus_PTR)(glCheckFramebufferStatus_ARG_EXPAND); +void gl4es_glClear(glClear_ARG_EXPAND); +typedef void (*glClear_PTR)(glClear_ARG_EXPAND); +void gl4es_glClearColor(glClearColor_ARG_EXPAND); +typedef void (*glClearColor_PTR)(glClearColor_ARG_EXPAND); +void gl4es_glClearColorx(glClearColorx_ARG_EXPAND); +typedef void (*glClearColorx_PTR)(glClearColorx_ARG_EXPAND); +void gl4es_glClearDepthf(glClearDepthf_ARG_EXPAND); +typedef void (*glClearDepthf_PTR)(glClearDepthf_ARG_EXPAND); +void gl4es_glClearDepthx(glClearDepthx_ARG_EXPAND); +typedef void (*glClearDepthx_PTR)(glClearDepthx_ARG_EXPAND); +void gl4es_glClearStencil(glClearStencil_ARG_EXPAND); +typedef void (*glClearStencil_PTR)(glClearStencil_ARG_EXPAND); +void gl4es_glClientActiveTexture(glClientActiveTexture_ARG_EXPAND); +typedef void (*glClientActiveTexture_PTR)(glClientActiveTexture_ARG_EXPAND); +void gl4es_glClipPlanef(glClipPlanef_ARG_EXPAND); +typedef void (*glClipPlanef_PTR)(glClipPlanef_ARG_EXPAND); +void gl4es_glClipPlanex(glClipPlanex_ARG_EXPAND); +typedef void (*glClipPlanex_PTR)(glClipPlanex_ARG_EXPAND); +void gl4es_glColor4f(glColor4f_ARG_EXPAND); +typedef void (*glColor4f_PTR)(glColor4f_ARG_EXPAND); +void gl4es_glColor4ub(glColor4ub_ARG_EXPAND); +typedef void (*glColor4ub_PTR)(glColor4ub_ARG_EXPAND); +void gl4es_glColor4x(glColor4x_ARG_EXPAND); +typedef void (*glColor4x_PTR)(glColor4x_ARG_EXPAND); +void gl4es_glColorMask(glColorMask_ARG_EXPAND); +typedef void (*glColorMask_PTR)(glColorMask_ARG_EXPAND); +void gl4es_glColorPointer(glColorPointer_ARG_EXPAND); +typedef void (*glColorPointer_PTR)(glColorPointer_ARG_EXPAND); +void gl4es_glCompileShader(glCompileShader_ARG_EXPAND); +typedef void (*glCompileShader_PTR)(glCompileShader_ARG_EXPAND); +void gl4es_glCompressedTexImage2D(glCompressedTexImage2D_ARG_EXPAND); +typedef void (*glCompressedTexImage2D_PTR)(glCompressedTexImage2D_ARG_EXPAND); +void gl4es_glCompressedTexSubImage2D(glCompressedTexSubImage2D_ARG_EXPAND); +typedef void (*glCompressedTexSubImage2D_PTR)(glCompressedTexSubImage2D_ARG_EXPAND); +void gl4es_glCopyTexImage2D(glCopyTexImage2D_ARG_EXPAND); +typedef void (*glCopyTexImage2D_PTR)(glCopyTexImage2D_ARG_EXPAND); +void gl4es_glCopyTexSubImage2D(glCopyTexSubImage2D_ARG_EXPAND); +typedef void (*glCopyTexSubImage2D_PTR)(glCopyTexSubImage2D_ARG_EXPAND); +GLuint gl4es_glCreateProgram(glCreateProgram_ARG_EXPAND); +typedef GLuint (*glCreateProgram_PTR)(glCreateProgram_ARG_EXPAND); +GLuint gl4es_glCreateShader(glCreateShader_ARG_EXPAND); +typedef GLuint (*glCreateShader_PTR)(glCreateShader_ARG_EXPAND); +void gl4es_glCullFace(glCullFace_ARG_EXPAND); +typedef void (*glCullFace_PTR)(glCullFace_ARG_EXPAND); +void gl4es_glDeleteBuffers(glDeleteBuffers_ARG_EXPAND); +typedef void (*glDeleteBuffers_PTR)(glDeleteBuffers_ARG_EXPAND); +void gl4es_glDeleteFramebuffers(glDeleteFramebuffers_ARG_EXPAND); +typedef void (*glDeleteFramebuffers_PTR)(glDeleteFramebuffers_ARG_EXPAND); +void gl4es_glDeleteProgram(glDeleteProgram_ARG_EXPAND); +typedef void (*glDeleteProgram_PTR)(glDeleteProgram_ARG_EXPAND); +void gl4es_glDeleteRenderbuffers(glDeleteRenderbuffers_ARG_EXPAND); +typedef void (*glDeleteRenderbuffers_PTR)(glDeleteRenderbuffers_ARG_EXPAND); +void gl4es_glDeleteShader(glDeleteShader_ARG_EXPAND); +typedef void (*glDeleteShader_PTR)(glDeleteShader_ARG_EXPAND); +void gl4es_glDeleteTextures(glDeleteTextures_ARG_EXPAND); +typedef void (*glDeleteTextures_PTR)(glDeleteTextures_ARG_EXPAND); +void gl4es_glDepthFunc(glDepthFunc_ARG_EXPAND); +typedef void (*glDepthFunc_PTR)(glDepthFunc_ARG_EXPAND); +void gl4es_glDepthMask(glDepthMask_ARG_EXPAND); +typedef void (*glDepthMask_PTR)(glDepthMask_ARG_EXPAND); +void gl4es_glDepthRangef(glDepthRangef_ARG_EXPAND); +typedef void (*glDepthRangef_PTR)(glDepthRangef_ARG_EXPAND); +void gl4es_glDepthRangex(glDepthRangex_ARG_EXPAND); +typedef void (*glDepthRangex_PTR)(glDepthRangex_ARG_EXPAND); +void gl4es_glDetachShader(glDetachShader_ARG_EXPAND); +typedef void (*glDetachShader_PTR)(glDetachShader_ARG_EXPAND); +void gl4es_glDisable(glDisable_ARG_EXPAND); +typedef void (*glDisable_PTR)(glDisable_ARG_EXPAND); +void gl4es_glDisableClientState(glDisableClientState_ARG_EXPAND); +typedef void (*glDisableClientState_PTR)(glDisableClientState_ARG_EXPAND); +void gl4es_glDisableVertexAttribArray(glDisableVertexAttribArray_ARG_EXPAND); +typedef void (*glDisableVertexAttribArray_PTR)(glDisableVertexAttribArray_ARG_EXPAND); +void gl4es_glDrawArrays(glDrawArrays_ARG_EXPAND); +typedef void (*glDrawArrays_PTR)(glDrawArrays_ARG_EXPAND); +void gl4es_glDrawElements(glDrawElements_ARG_EXPAND); +typedef void (*glDrawElements_PTR)(glDrawElements_ARG_EXPAND); +void gl4es_glDrawTexf(glDrawTexf_ARG_EXPAND); +typedef void (*glDrawTexf_PTR)(glDrawTexf_ARG_EXPAND); +void gl4es_glDrawTexi(glDrawTexi_ARG_EXPAND); +typedef void (*glDrawTexi_PTR)(glDrawTexi_ARG_EXPAND); +void gl4es_glEnable(glEnable_ARG_EXPAND); +typedef void (*glEnable_PTR)(glEnable_ARG_EXPAND); +void gl4es_glEnableClientState(glEnableClientState_ARG_EXPAND); +typedef void (*glEnableClientState_PTR)(glEnableClientState_ARG_EXPAND); +void gl4es_glEnableVertexAttribArray(glEnableVertexAttribArray_ARG_EXPAND); +typedef void (*glEnableVertexAttribArray_PTR)(glEnableVertexAttribArray_ARG_EXPAND); +void gl4es_glFinish(glFinish_ARG_EXPAND); +typedef void (*glFinish_PTR)(glFinish_ARG_EXPAND); +void gl4es_glFlush(glFlush_ARG_EXPAND); +typedef void (*glFlush_PTR)(glFlush_ARG_EXPAND); +void gl4es_glFogCoordPointer(glFogCoordPointer_ARG_EXPAND); +typedef void (*glFogCoordPointer_PTR)(glFogCoordPointer_ARG_EXPAND); +void gl4es_glFogCoordf(glFogCoordf_ARG_EXPAND); +typedef void (*glFogCoordf_PTR)(glFogCoordf_ARG_EXPAND); +void gl4es_glFogCoordfv(glFogCoordfv_ARG_EXPAND); +typedef void (*glFogCoordfv_PTR)(glFogCoordfv_ARG_EXPAND); +void gl4es_glFogf(glFogf_ARG_EXPAND); +typedef void (*glFogf_PTR)(glFogf_ARG_EXPAND); +void gl4es_glFogfv(glFogfv_ARG_EXPAND); +typedef void (*glFogfv_PTR)(glFogfv_ARG_EXPAND); +void gl4es_glFogx(glFogx_ARG_EXPAND); +typedef void (*glFogx_PTR)(glFogx_ARG_EXPAND); +void gl4es_glFogxv(glFogxv_ARG_EXPAND); +typedef void (*glFogxv_PTR)(glFogxv_ARG_EXPAND); +void gl4es_glFramebufferRenderbuffer(glFramebufferRenderbuffer_ARG_EXPAND); +typedef void (*glFramebufferRenderbuffer_PTR)(glFramebufferRenderbuffer_ARG_EXPAND); +void gl4es_glFramebufferTexture2D(glFramebufferTexture2D_ARG_EXPAND); +typedef void (*glFramebufferTexture2D_PTR)(glFramebufferTexture2D_ARG_EXPAND); +void gl4es_glFrontFace(glFrontFace_ARG_EXPAND); +typedef void (*glFrontFace_PTR)(glFrontFace_ARG_EXPAND); +void gl4es_glFrustumf(glFrustumf_ARG_EXPAND); +typedef void (*glFrustumf_PTR)(glFrustumf_ARG_EXPAND); +void gl4es_glFrustumx(glFrustumx_ARG_EXPAND); +typedef void (*glFrustumx_PTR)(glFrustumx_ARG_EXPAND); +void gl4es_glGenBuffers(glGenBuffers_ARG_EXPAND); +typedef void (*glGenBuffers_PTR)(glGenBuffers_ARG_EXPAND); +void gl4es_glGenFramebuffers(glGenFramebuffers_ARG_EXPAND); +typedef void (*glGenFramebuffers_PTR)(glGenFramebuffers_ARG_EXPAND); +void gl4es_glGenRenderbuffers(glGenRenderbuffers_ARG_EXPAND); +typedef void (*glGenRenderbuffers_PTR)(glGenRenderbuffers_ARG_EXPAND); +void gl4es_glGenTextures(glGenTextures_ARG_EXPAND); +typedef void (*glGenTextures_PTR)(glGenTextures_ARG_EXPAND); +void gl4es_glGenerateMipmap(glGenerateMipmap_ARG_EXPAND); +typedef void (*glGenerateMipmap_PTR)(glGenerateMipmap_ARG_EXPAND); +void gl4es_glGetActiveAttrib(glGetActiveAttrib_ARG_EXPAND); +typedef void (*glGetActiveAttrib_PTR)(glGetActiveAttrib_ARG_EXPAND); +void gl4es_glGetActiveUniform(glGetActiveUniform_ARG_EXPAND); +typedef void (*glGetActiveUniform_PTR)(glGetActiveUniform_ARG_EXPAND); +void gl4es_glGetAttachedShaders(glGetAttachedShaders_ARG_EXPAND); +typedef void (*glGetAttachedShaders_PTR)(glGetAttachedShaders_ARG_EXPAND); +GLint gl4es_glGetAttribLocation(glGetAttribLocation_ARG_EXPAND); +typedef GLint (*glGetAttribLocation_PTR)(glGetAttribLocation_ARG_EXPAND); +void gl4es_glGetBooleanv(glGetBooleanv_ARG_EXPAND); +typedef void (*glGetBooleanv_PTR)(glGetBooleanv_ARG_EXPAND); +void gl4es_glGetBufferParameteriv(glGetBufferParameteriv_ARG_EXPAND); +typedef void (*glGetBufferParameteriv_PTR)(glGetBufferParameteriv_ARG_EXPAND); +void gl4es_glGetClipPlanef(glGetClipPlanef_ARG_EXPAND); +typedef void (*glGetClipPlanef_PTR)(glGetClipPlanef_ARG_EXPAND); +void gl4es_glGetClipPlanex(glGetClipPlanex_ARG_EXPAND); +typedef void (*glGetClipPlanex_PTR)(glGetClipPlanex_ARG_EXPAND); +GLenum gl4es_glGetError(glGetError_ARG_EXPAND); +typedef GLenum (*glGetError_PTR)(glGetError_ARG_EXPAND); +void gl4es_glGetFixedv(glGetFixedv_ARG_EXPAND); +typedef void (*glGetFixedv_PTR)(glGetFixedv_ARG_EXPAND); +void gl4es_glGetFloatv(glGetFloatv_ARG_EXPAND); +typedef void (*glGetFloatv_PTR)(glGetFloatv_ARG_EXPAND); +void gl4es_glGetFramebufferAttachmentParameteriv(glGetFramebufferAttachmentParameteriv_ARG_EXPAND); +typedef void (*glGetFramebufferAttachmentParameteriv_PTR)(glGetFramebufferAttachmentParameteriv_ARG_EXPAND); +void gl4es_glGetIntegerv(glGetIntegerv_ARG_EXPAND); +typedef void (*glGetIntegerv_PTR)(glGetIntegerv_ARG_EXPAND); +void gl4es_glGetLightfv(glGetLightfv_ARG_EXPAND); +typedef void (*glGetLightfv_PTR)(glGetLightfv_ARG_EXPAND); +void gl4es_glGetLightxv(glGetLightxv_ARG_EXPAND); +typedef void (*glGetLightxv_PTR)(glGetLightxv_ARG_EXPAND); +void gl4es_glGetMaterialfv(glGetMaterialfv_ARG_EXPAND); +typedef void (*glGetMaterialfv_PTR)(glGetMaterialfv_ARG_EXPAND); +void gl4es_glGetMaterialxv(glGetMaterialxv_ARG_EXPAND); +typedef void (*glGetMaterialxv_PTR)(glGetMaterialxv_ARG_EXPAND); +void gl4es_glGetPointerv(glGetPointerv_ARG_EXPAND); +typedef void (*glGetPointerv_PTR)(glGetPointerv_ARG_EXPAND); +void gl4es_glGetProgramInfoLog(glGetProgramInfoLog_ARG_EXPAND); +typedef void (*glGetProgramInfoLog_PTR)(glGetProgramInfoLog_ARG_EXPAND); +void gl4es_glGetProgramiv(glGetProgramiv_ARG_EXPAND); +typedef void (*glGetProgramiv_PTR)(glGetProgramiv_ARG_EXPAND); +void gl4es_glGetRenderbufferParameteriv(glGetRenderbufferParameteriv_ARG_EXPAND); +typedef void (*glGetRenderbufferParameteriv_PTR)(glGetRenderbufferParameteriv_ARG_EXPAND); +void gl4es_glGetShaderInfoLog(glGetShaderInfoLog_ARG_EXPAND); +typedef void (*glGetShaderInfoLog_PTR)(glGetShaderInfoLog_ARG_EXPAND); +void gl4es_glGetShaderPrecisionFormat(glGetShaderPrecisionFormat_ARG_EXPAND); +typedef void (*glGetShaderPrecisionFormat_PTR)(glGetShaderPrecisionFormat_ARG_EXPAND); +void gl4es_glGetShaderSource(glGetShaderSource_ARG_EXPAND); +typedef void (*glGetShaderSource_PTR)(glGetShaderSource_ARG_EXPAND); +void gl4es_glGetShaderiv(glGetShaderiv_ARG_EXPAND); +typedef void (*glGetShaderiv_PTR)(glGetShaderiv_ARG_EXPAND); +const GLubyte * gl4es_glGetString(glGetString_ARG_EXPAND); +typedef const GLubyte * (*glGetString_PTR)(glGetString_ARG_EXPAND); +void gl4es_glGetTexEnvfv(glGetTexEnvfv_ARG_EXPAND); +typedef void (*glGetTexEnvfv_PTR)(glGetTexEnvfv_ARG_EXPAND); +void gl4es_glGetTexEnviv(glGetTexEnviv_ARG_EXPAND); +typedef void (*glGetTexEnviv_PTR)(glGetTexEnviv_ARG_EXPAND); +void gl4es_glGetTexEnvxv(glGetTexEnvxv_ARG_EXPAND); +typedef void (*glGetTexEnvxv_PTR)(glGetTexEnvxv_ARG_EXPAND); +void gl4es_glGetTexParameterfv(glGetTexParameterfv_ARG_EXPAND); +typedef void (*glGetTexParameterfv_PTR)(glGetTexParameterfv_ARG_EXPAND); +void gl4es_glGetTexParameteriv(glGetTexParameteriv_ARG_EXPAND); +typedef void (*glGetTexParameteriv_PTR)(glGetTexParameteriv_ARG_EXPAND); +void gl4es_glGetTexParameterxv(glGetTexParameterxv_ARG_EXPAND); +typedef void (*glGetTexParameterxv_PTR)(glGetTexParameterxv_ARG_EXPAND); +GLint gl4es_glGetUniformLocation(glGetUniformLocation_ARG_EXPAND); +typedef GLint (*glGetUniformLocation_PTR)(glGetUniformLocation_ARG_EXPAND); +void gl4es_glGetUniformfv(glGetUniformfv_ARG_EXPAND); +typedef void (*glGetUniformfv_PTR)(glGetUniformfv_ARG_EXPAND); +void gl4es_glGetUniformiv(glGetUniformiv_ARG_EXPAND); +typedef void (*glGetUniformiv_PTR)(glGetUniformiv_ARG_EXPAND); +void gl4es_glGetVertexAttribPointerv(glGetVertexAttribPointerv_ARG_EXPAND); +typedef void (*glGetVertexAttribPointerv_PTR)(glGetVertexAttribPointerv_ARG_EXPAND); +void gl4es_glGetVertexAttribfv(glGetVertexAttribfv_ARG_EXPAND); +typedef void (*glGetVertexAttribfv_PTR)(glGetVertexAttribfv_ARG_EXPAND); +void gl4es_glGetVertexAttribiv(glGetVertexAttribiv_ARG_EXPAND); +typedef void (*glGetVertexAttribiv_PTR)(glGetVertexAttribiv_ARG_EXPAND); +void gl4es_glHint(glHint_ARG_EXPAND); +typedef void (*glHint_PTR)(glHint_ARG_EXPAND); +GLboolean gl4es_glIsBuffer(glIsBuffer_ARG_EXPAND); +typedef GLboolean (*glIsBuffer_PTR)(glIsBuffer_ARG_EXPAND); +GLboolean gl4es_glIsEnabled(glIsEnabled_ARG_EXPAND); +typedef GLboolean (*glIsEnabled_PTR)(glIsEnabled_ARG_EXPAND); +GLboolean gl4es_glIsFramebuffer(glIsFramebuffer_ARG_EXPAND); +typedef GLboolean (*glIsFramebuffer_PTR)(glIsFramebuffer_ARG_EXPAND); +GLboolean gl4es_glIsProgram(glIsProgram_ARG_EXPAND); +typedef GLboolean (*glIsProgram_PTR)(glIsProgram_ARG_EXPAND); +GLboolean gl4es_glIsRenderbuffer(glIsRenderbuffer_ARG_EXPAND); +typedef GLboolean (*glIsRenderbuffer_PTR)(glIsRenderbuffer_ARG_EXPAND); +GLboolean gl4es_glIsShader(glIsShader_ARG_EXPAND); +typedef GLboolean (*glIsShader_PTR)(glIsShader_ARG_EXPAND); +GLboolean gl4es_glIsTexture(glIsTexture_ARG_EXPAND); +typedef GLboolean (*glIsTexture_PTR)(glIsTexture_ARG_EXPAND); +void gl4es_glLightModelf(glLightModelf_ARG_EXPAND); +typedef void (*glLightModelf_PTR)(glLightModelf_ARG_EXPAND); +void gl4es_glLightModelfv(glLightModelfv_ARG_EXPAND); +typedef void (*glLightModelfv_PTR)(glLightModelfv_ARG_EXPAND); +void gl4es_glLightModelx(glLightModelx_ARG_EXPAND); +typedef void (*glLightModelx_PTR)(glLightModelx_ARG_EXPAND); +void gl4es_glLightModelxv(glLightModelxv_ARG_EXPAND); +typedef void (*glLightModelxv_PTR)(glLightModelxv_ARG_EXPAND); +void gl4es_glLightf(glLightf_ARG_EXPAND); +typedef void (*glLightf_PTR)(glLightf_ARG_EXPAND); +void gl4es_glLightfv(glLightfv_ARG_EXPAND); +typedef void (*glLightfv_PTR)(glLightfv_ARG_EXPAND); +void gl4es_glLightx(glLightx_ARG_EXPAND); +typedef void (*glLightx_PTR)(glLightx_ARG_EXPAND); +void gl4es_glLightxv(glLightxv_ARG_EXPAND); +typedef void (*glLightxv_PTR)(glLightxv_ARG_EXPAND); +void gl4es_glLineWidth(glLineWidth_ARG_EXPAND); +typedef void (*glLineWidth_PTR)(glLineWidth_ARG_EXPAND); +void gl4es_glLineWidthx(glLineWidthx_ARG_EXPAND); +typedef void (*glLineWidthx_PTR)(glLineWidthx_ARG_EXPAND); +void gl4es_glLinkProgram(glLinkProgram_ARG_EXPAND); +typedef void (*glLinkProgram_PTR)(glLinkProgram_ARG_EXPAND); +void gl4es_glLoadIdentity(glLoadIdentity_ARG_EXPAND); +typedef void (*glLoadIdentity_PTR)(glLoadIdentity_ARG_EXPAND); +void gl4es_glLoadMatrixf(glLoadMatrixf_ARG_EXPAND); +typedef void (*glLoadMatrixf_PTR)(glLoadMatrixf_ARG_EXPAND); +void gl4es_glLoadMatrixx(glLoadMatrixx_ARG_EXPAND); +typedef void (*glLoadMatrixx_PTR)(glLoadMatrixx_ARG_EXPAND); +void gl4es_glLogicOp(glLogicOp_ARG_EXPAND); +typedef void (*glLogicOp_PTR)(glLogicOp_ARG_EXPAND); +void gl4es_glMaterialf(glMaterialf_ARG_EXPAND); +typedef void (*glMaterialf_PTR)(glMaterialf_ARG_EXPAND); +void gl4es_glMaterialfv(glMaterialfv_ARG_EXPAND); +typedef void (*glMaterialfv_PTR)(glMaterialfv_ARG_EXPAND); +void gl4es_glMaterialx(glMaterialx_ARG_EXPAND); +typedef void (*glMaterialx_PTR)(glMaterialx_ARG_EXPAND); +void gl4es_glMaterialxv(glMaterialxv_ARG_EXPAND); +typedef void (*glMaterialxv_PTR)(glMaterialxv_ARG_EXPAND); +void gl4es_glMatrixMode(glMatrixMode_ARG_EXPAND); +typedef void (*glMatrixMode_PTR)(glMatrixMode_ARG_EXPAND); +void gl4es_glMultMatrixf(glMultMatrixf_ARG_EXPAND); +typedef void (*glMultMatrixf_PTR)(glMultMatrixf_ARG_EXPAND); +void gl4es_glMultMatrixx(glMultMatrixx_ARG_EXPAND); +typedef void (*glMultMatrixx_PTR)(glMultMatrixx_ARG_EXPAND); +void gl4es_glMultiDrawArrays(glMultiDrawArrays_ARG_EXPAND); +typedef void (*glMultiDrawArrays_PTR)(glMultiDrawArrays_ARG_EXPAND); +void gl4es_glMultiDrawElements(glMultiDrawElements_ARG_EXPAND); +typedef void (*glMultiDrawElements_PTR)(glMultiDrawElements_ARG_EXPAND); +void gl4es_glMultiTexCoord4f(glMultiTexCoord4f_ARG_EXPAND); +typedef void (*glMultiTexCoord4f_PTR)(glMultiTexCoord4f_ARG_EXPAND); +void gl4es_glMultiTexCoord4x(glMultiTexCoord4x_ARG_EXPAND); +typedef void (*glMultiTexCoord4x_PTR)(glMultiTexCoord4x_ARG_EXPAND); +void gl4es_glNormal3f(glNormal3f_ARG_EXPAND); +typedef void (*glNormal3f_PTR)(glNormal3f_ARG_EXPAND); +void gl4es_glNormal3x(glNormal3x_ARG_EXPAND); +typedef void (*glNormal3x_PTR)(glNormal3x_ARG_EXPAND); +void gl4es_glNormalPointer(glNormalPointer_ARG_EXPAND); +typedef void (*glNormalPointer_PTR)(glNormalPointer_ARG_EXPAND); +void gl4es_glOrthof(glOrthof_ARG_EXPAND); +typedef void (*glOrthof_PTR)(glOrthof_ARG_EXPAND); +void gl4es_glOrthox(glOrthox_ARG_EXPAND); +typedef void (*glOrthox_PTR)(glOrthox_ARG_EXPAND); +void gl4es_glPixelStorei(glPixelStorei_ARG_EXPAND); +typedef void (*glPixelStorei_PTR)(glPixelStorei_ARG_EXPAND); +void gl4es_glPointParameterf(glPointParameterf_ARG_EXPAND); +typedef void (*glPointParameterf_PTR)(glPointParameterf_ARG_EXPAND); +void gl4es_glPointParameterfv(glPointParameterfv_ARG_EXPAND); +typedef void (*glPointParameterfv_PTR)(glPointParameterfv_ARG_EXPAND); +void gl4es_glPointParameterx(glPointParameterx_ARG_EXPAND); +typedef void (*glPointParameterx_PTR)(glPointParameterx_ARG_EXPAND); +void gl4es_glPointParameterxv(glPointParameterxv_ARG_EXPAND); +typedef void (*glPointParameterxv_PTR)(glPointParameterxv_ARG_EXPAND); +void gl4es_glPointSize(glPointSize_ARG_EXPAND); +typedef void (*glPointSize_PTR)(glPointSize_ARG_EXPAND); +void gl4es_glPointSizePointerOES(glPointSizePointerOES_ARG_EXPAND); +typedef void (*glPointSizePointerOES_PTR)(glPointSizePointerOES_ARG_EXPAND); +void gl4es_glPointSizex(glPointSizex_ARG_EXPAND); +typedef void (*glPointSizex_PTR)(glPointSizex_ARG_EXPAND); +void gl4es_glPolygonOffset(glPolygonOffset_ARG_EXPAND); +typedef void (*glPolygonOffset_PTR)(glPolygonOffset_ARG_EXPAND); +void gl4es_glPolygonOffsetx(glPolygonOffsetx_ARG_EXPAND); +typedef void (*glPolygonOffsetx_PTR)(glPolygonOffsetx_ARG_EXPAND); +void gl4es_glPopMatrix(glPopMatrix_ARG_EXPAND); +typedef void (*glPopMatrix_PTR)(glPopMatrix_ARG_EXPAND); +void gl4es_glPushMatrix(glPushMatrix_ARG_EXPAND); +typedef void (*glPushMatrix_PTR)(glPushMatrix_ARG_EXPAND); +void gl4es_glReadPixels(glReadPixels_ARG_EXPAND); +typedef void (*glReadPixels_PTR)(glReadPixels_ARG_EXPAND); +void gl4es_glReleaseShaderCompiler(glReleaseShaderCompiler_ARG_EXPAND); +typedef void (*glReleaseShaderCompiler_PTR)(glReleaseShaderCompiler_ARG_EXPAND); +void gl4es_glRenderbufferStorage(glRenderbufferStorage_ARG_EXPAND); +typedef void (*glRenderbufferStorage_PTR)(glRenderbufferStorage_ARG_EXPAND); +void gl4es_glRotatef(glRotatef_ARG_EXPAND); +typedef void (*glRotatef_PTR)(glRotatef_ARG_EXPAND); +void gl4es_glRotatex(glRotatex_ARG_EXPAND); +typedef void (*glRotatex_PTR)(glRotatex_ARG_EXPAND); +void gl4es_glSampleCoverage(glSampleCoverage_ARG_EXPAND); +typedef void (*glSampleCoverage_PTR)(glSampleCoverage_ARG_EXPAND); +void gl4es_glSampleCoveragex(glSampleCoveragex_ARG_EXPAND); +typedef void (*glSampleCoveragex_PTR)(glSampleCoveragex_ARG_EXPAND); +void gl4es_glScalef(glScalef_ARG_EXPAND); +typedef void (*glScalef_PTR)(glScalef_ARG_EXPAND); +void gl4es_glScalex(glScalex_ARG_EXPAND); +typedef void (*glScalex_PTR)(glScalex_ARG_EXPAND); +void gl4es_glScissor(glScissor_ARG_EXPAND); +typedef void (*glScissor_PTR)(glScissor_ARG_EXPAND); +void gl4es_glShadeModel(glShadeModel_ARG_EXPAND); +typedef void (*glShadeModel_PTR)(glShadeModel_ARG_EXPAND); +void gl4es_glShaderBinary(glShaderBinary_ARG_EXPAND); +typedef void (*glShaderBinary_PTR)(glShaderBinary_ARG_EXPAND); +void gl4es_glShaderSource(glShaderSource_ARG_EXPAND); +typedef void (*glShaderSource_PTR)(glShaderSource_ARG_EXPAND); +void gl4es_glStencilFunc(glStencilFunc_ARG_EXPAND); +typedef void (*glStencilFunc_PTR)(glStencilFunc_ARG_EXPAND); +void gl4es_glStencilFuncSeparate(glStencilFuncSeparate_ARG_EXPAND); +typedef void (*glStencilFuncSeparate_PTR)(glStencilFuncSeparate_ARG_EXPAND); +void gl4es_glStencilMask(glStencilMask_ARG_EXPAND); +typedef void (*glStencilMask_PTR)(glStencilMask_ARG_EXPAND); +void gl4es_glStencilMaskSeparate(glStencilMaskSeparate_ARG_EXPAND); +typedef void (*glStencilMaskSeparate_PTR)(glStencilMaskSeparate_ARG_EXPAND); +void gl4es_glStencilOp(glStencilOp_ARG_EXPAND); +typedef void (*glStencilOp_PTR)(glStencilOp_ARG_EXPAND); +void gl4es_glStencilOpSeparate(glStencilOpSeparate_ARG_EXPAND); +typedef void (*glStencilOpSeparate_PTR)(glStencilOpSeparate_ARG_EXPAND); +void gl4es_glTexCoordPointer(glTexCoordPointer_ARG_EXPAND); +typedef void (*glTexCoordPointer_PTR)(glTexCoordPointer_ARG_EXPAND); +void gl4es_glTexEnvf(glTexEnvf_ARG_EXPAND); +typedef void (*glTexEnvf_PTR)(glTexEnvf_ARG_EXPAND); +void gl4es_glTexEnvfv(glTexEnvfv_ARG_EXPAND); +typedef void (*glTexEnvfv_PTR)(glTexEnvfv_ARG_EXPAND); +void gl4es_glTexEnvi(glTexEnvi_ARG_EXPAND); +typedef void (*glTexEnvi_PTR)(glTexEnvi_ARG_EXPAND); +void gl4es_glTexEnviv(glTexEnviv_ARG_EXPAND); +typedef void (*glTexEnviv_PTR)(glTexEnviv_ARG_EXPAND); +void gl4es_glTexEnvx(glTexEnvx_ARG_EXPAND); +typedef void (*glTexEnvx_PTR)(glTexEnvx_ARG_EXPAND); +void gl4es_glTexEnvxv(glTexEnvxv_ARG_EXPAND); +typedef void (*glTexEnvxv_PTR)(glTexEnvxv_ARG_EXPAND); +void gl4es_glTexGenfv(glTexGenfv_ARG_EXPAND); +typedef void (*glTexGenfv_PTR)(glTexGenfv_ARG_EXPAND); +void gl4es_glTexGeni(glTexGeni_ARG_EXPAND); +typedef void (*glTexGeni_PTR)(glTexGeni_ARG_EXPAND); +void gl4es_glTexImage2D(glTexImage2D_ARG_EXPAND); +typedef void (*glTexImage2D_PTR)(glTexImage2D_ARG_EXPAND); +void gl4es_glTexParameterf(glTexParameterf_ARG_EXPAND); +typedef void (*glTexParameterf_PTR)(glTexParameterf_ARG_EXPAND); +void gl4es_glTexParameterfv(glTexParameterfv_ARG_EXPAND); +typedef void (*glTexParameterfv_PTR)(glTexParameterfv_ARG_EXPAND); +void gl4es_glTexParameteri(glTexParameteri_ARG_EXPAND); +typedef void (*glTexParameteri_PTR)(glTexParameteri_ARG_EXPAND); +void gl4es_glTexParameteriv(glTexParameteriv_ARG_EXPAND); +typedef void (*glTexParameteriv_PTR)(glTexParameteriv_ARG_EXPAND); +void gl4es_glTexParameterx(glTexParameterx_ARG_EXPAND); +typedef void (*glTexParameterx_PTR)(glTexParameterx_ARG_EXPAND); +void gl4es_glTexParameterxv(glTexParameterxv_ARG_EXPAND); +typedef void (*glTexParameterxv_PTR)(glTexParameterxv_ARG_EXPAND); +void gl4es_glTexSubImage2D(glTexSubImage2D_ARG_EXPAND); +typedef void (*glTexSubImage2D_PTR)(glTexSubImage2D_ARG_EXPAND); +void gl4es_glTranslatef(glTranslatef_ARG_EXPAND); +typedef void (*glTranslatef_PTR)(glTranslatef_ARG_EXPAND); +void gl4es_glTranslatex(glTranslatex_ARG_EXPAND); +typedef void (*glTranslatex_PTR)(glTranslatex_ARG_EXPAND); +void gl4es_glUniform1f(glUniform1f_ARG_EXPAND); +typedef void (*glUniform1f_PTR)(glUniform1f_ARG_EXPAND); +void gl4es_glUniform1fv(glUniform1fv_ARG_EXPAND); +typedef void (*glUniform1fv_PTR)(glUniform1fv_ARG_EXPAND); +void gl4es_glUniform1i(glUniform1i_ARG_EXPAND); +typedef void (*glUniform1i_PTR)(glUniform1i_ARG_EXPAND); +void gl4es_glUniform1iv(glUniform1iv_ARG_EXPAND); +typedef void (*glUniform1iv_PTR)(glUniform1iv_ARG_EXPAND); +void gl4es_glUniform2f(glUniform2f_ARG_EXPAND); +typedef void (*glUniform2f_PTR)(glUniform2f_ARG_EXPAND); +void gl4es_glUniform2fv(glUniform2fv_ARG_EXPAND); +typedef void (*glUniform2fv_PTR)(glUniform2fv_ARG_EXPAND); +void gl4es_glUniform2i(glUniform2i_ARG_EXPAND); +typedef void (*glUniform2i_PTR)(glUniform2i_ARG_EXPAND); +void gl4es_glUniform2iv(glUniform2iv_ARG_EXPAND); +typedef void (*glUniform2iv_PTR)(glUniform2iv_ARG_EXPAND); +void gl4es_glUniform3f(glUniform3f_ARG_EXPAND); +typedef void (*glUniform3f_PTR)(glUniform3f_ARG_EXPAND); +void gl4es_glUniform3fv(glUniform3fv_ARG_EXPAND); +typedef void (*glUniform3fv_PTR)(glUniform3fv_ARG_EXPAND); +void gl4es_glUniform3i(glUniform3i_ARG_EXPAND); +typedef void (*glUniform3i_PTR)(glUniform3i_ARG_EXPAND); +void gl4es_glUniform3iv(glUniform3iv_ARG_EXPAND); +typedef void (*glUniform3iv_PTR)(glUniform3iv_ARG_EXPAND); +void gl4es_glUniform4f(glUniform4f_ARG_EXPAND); +typedef void (*glUniform4f_PTR)(glUniform4f_ARG_EXPAND); +void gl4es_glUniform4fv(glUniform4fv_ARG_EXPAND); +typedef void (*glUniform4fv_PTR)(glUniform4fv_ARG_EXPAND); +void gl4es_glUniform4i(glUniform4i_ARG_EXPAND); +typedef void (*glUniform4i_PTR)(glUniform4i_ARG_EXPAND); +void gl4es_glUniform4iv(glUniform4iv_ARG_EXPAND); +typedef void (*glUniform4iv_PTR)(glUniform4iv_ARG_EXPAND); +void gl4es_glUniformMatrix2fv(glUniformMatrix2fv_ARG_EXPAND); +typedef void (*glUniformMatrix2fv_PTR)(glUniformMatrix2fv_ARG_EXPAND); +void gl4es_glUniformMatrix3fv(glUniformMatrix3fv_ARG_EXPAND); +typedef void (*glUniformMatrix3fv_PTR)(glUniformMatrix3fv_ARG_EXPAND); +void gl4es_glUniformMatrix4fv(glUniformMatrix4fv_ARG_EXPAND); +typedef void (*glUniformMatrix4fv_PTR)(glUniformMatrix4fv_ARG_EXPAND); +void gl4es_glUseProgram(glUseProgram_ARG_EXPAND); +typedef void (*glUseProgram_PTR)(glUseProgram_ARG_EXPAND); +void gl4es_glValidateProgram(glValidateProgram_ARG_EXPAND); +typedef void (*glValidateProgram_PTR)(glValidateProgram_ARG_EXPAND); +void gl4es_glVertexAttrib1f(glVertexAttrib1f_ARG_EXPAND); +typedef void (*glVertexAttrib1f_PTR)(glVertexAttrib1f_ARG_EXPAND); +void gl4es_glVertexAttrib1fv(glVertexAttrib1fv_ARG_EXPAND); +typedef void (*glVertexAttrib1fv_PTR)(glVertexAttrib1fv_ARG_EXPAND); +void gl4es_glVertexAttrib2f(glVertexAttrib2f_ARG_EXPAND); +typedef void (*glVertexAttrib2f_PTR)(glVertexAttrib2f_ARG_EXPAND); +void gl4es_glVertexAttrib2fv(glVertexAttrib2fv_ARG_EXPAND); +typedef void (*glVertexAttrib2fv_PTR)(glVertexAttrib2fv_ARG_EXPAND); +void gl4es_glVertexAttrib3f(glVertexAttrib3f_ARG_EXPAND); +typedef void (*glVertexAttrib3f_PTR)(glVertexAttrib3f_ARG_EXPAND); +void gl4es_glVertexAttrib3fv(glVertexAttrib3fv_ARG_EXPAND); +typedef void (*glVertexAttrib3fv_PTR)(glVertexAttrib3fv_ARG_EXPAND); +void gl4es_glVertexAttrib4f(glVertexAttrib4f_ARG_EXPAND); +typedef void (*glVertexAttrib4f_PTR)(glVertexAttrib4f_ARG_EXPAND); +void gl4es_glVertexAttrib4fv(glVertexAttrib4fv_ARG_EXPAND); +typedef void (*glVertexAttrib4fv_PTR)(glVertexAttrib4fv_ARG_EXPAND); +void gl4es_glVertexAttribPointer(glVertexAttribPointer_ARG_EXPAND); +typedef void (*glVertexAttribPointer_PTR)(glVertexAttribPointer_ARG_EXPAND); +void gl4es_glVertexPointer(glVertexPointer_ARG_EXPAND); +typedef void (*glVertexPointer_PTR)(glVertexPointer_ARG_EXPAND); +void gl4es_glViewport(glViewport_ARG_EXPAND); +typedef void (*glViewport_PTR)(glViewport_ARG_EXPAND); + + + +#ifndef direct_glActiveTexture +#define push_glActiveTexture(texture) { \ + glActiveTexture_PACKED *packed_data = malloc(sizeof(glActiveTexture_PACKED)); \ + packed_data->format = glActiveTexture_FORMAT; \ + packed_data->func = gl4es_glActiveTexture; \ + packed_data->args.a1 = (GLenum)texture; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glAlphaFunc +#define push_glAlphaFunc(func, ref) { \ + glAlphaFunc_PACKED *packed_data = malloc(sizeof(glAlphaFunc_PACKED)); \ + packed_data->format = glAlphaFunc_FORMAT; \ + packed_data->func = gl4es_glAlphaFunc; \ + packed_data->args.a1 = (GLenum)func; \ + packed_data->args.a2 = (GLclampf)ref; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glAlphaFuncx +#define push_glAlphaFuncx(func, ref) { \ + glAlphaFuncx_PACKED *packed_data = malloc(sizeof(glAlphaFuncx_PACKED)); \ + packed_data->format = glAlphaFuncx_FORMAT; \ + packed_data->func = gl4es_glAlphaFuncx; \ + packed_data->args.a1 = (GLenum)func; \ + packed_data->args.a2 = (GLclampx)ref; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glAttachShader +#define push_glAttachShader(program, shader) { \ + glAttachShader_PACKED *packed_data = malloc(sizeof(glAttachShader_PACKED)); \ + packed_data->format = glAttachShader_FORMAT; \ + packed_data->func = gl4es_glAttachShader; \ + packed_data->args.a1 = (GLuint)program; \ + packed_data->args.a2 = (GLuint)shader; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glBindAttribLocation +#define push_glBindAttribLocation(program, index, name) { \ + glBindAttribLocation_PACKED *packed_data = malloc(sizeof(glBindAttribLocation_PACKED)); \ + packed_data->format = glBindAttribLocation_FORMAT; \ + packed_data->func = gl4es_glBindAttribLocation; \ + packed_data->args.a1 = (GLuint)program; \ + packed_data->args.a2 = (GLuint)index; \ + packed_data->args.a3 = (GLchar *)name; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glBindBuffer +#define push_glBindBuffer(target, buffer) { \ + glBindBuffer_PACKED *packed_data = malloc(sizeof(glBindBuffer_PACKED)); \ + packed_data->format = glBindBuffer_FORMAT; \ + packed_data->func = gl4es_glBindBuffer; \ + packed_data->args.a1 = (GLenum)target; \ + packed_data->args.a2 = (GLuint)buffer; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glBindFramebuffer +#define push_glBindFramebuffer(target, framebuffer) { \ + glBindFramebuffer_PACKED *packed_data = malloc(sizeof(glBindFramebuffer_PACKED)); \ + packed_data->format = glBindFramebuffer_FORMAT; \ + packed_data->func = gl4es_glBindFramebuffer; \ + packed_data->args.a1 = (GLenum)target; \ + packed_data->args.a2 = (GLuint)framebuffer; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glBindRenderbuffer +#define push_glBindRenderbuffer(target, renderbuffer) { \ + glBindRenderbuffer_PACKED *packed_data = malloc(sizeof(glBindRenderbuffer_PACKED)); \ + packed_data->format = glBindRenderbuffer_FORMAT; \ + packed_data->func = gl4es_glBindRenderbuffer; \ + packed_data->args.a1 = (GLenum)target; \ + packed_data->args.a2 = (GLuint)renderbuffer; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glBindTexture +#define push_glBindTexture(target, texture) { \ + glBindTexture_PACKED *packed_data = malloc(sizeof(glBindTexture_PACKED)); \ + packed_data->format = glBindTexture_FORMAT; \ + packed_data->func = gl4es_glBindTexture; \ + packed_data->args.a1 = (GLenum)target; \ + packed_data->args.a2 = (GLuint)texture; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glBlendColor +#define push_glBlendColor(red, green, blue, alpha) { \ + glBlendColor_PACKED *packed_data = malloc(sizeof(glBlendColor_PACKED)); \ + packed_data->format = glBlendColor_FORMAT; \ + packed_data->func = gl4es_glBlendColor; \ + packed_data->args.a1 = (GLclampf)red; \ + packed_data->args.a2 = (GLclampf)green; \ + packed_data->args.a3 = (GLclampf)blue; \ + packed_data->args.a4 = (GLclampf)alpha; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glBlendEquation +#define push_glBlendEquation(mode) { \ + glBlendEquation_PACKED *packed_data = malloc(sizeof(glBlendEquation_PACKED)); \ + packed_data->format = glBlendEquation_FORMAT; \ + packed_data->func = gl4es_glBlendEquation; \ + packed_data->args.a1 = (GLenum)mode; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glBlendEquationSeparate +#define push_glBlendEquationSeparate(modeRGB, modeA) { \ + glBlendEquationSeparate_PACKED *packed_data = malloc(sizeof(glBlendEquationSeparate_PACKED)); \ + packed_data->format = glBlendEquationSeparate_FORMAT; \ + packed_data->func = gl4es_glBlendEquationSeparate; \ + packed_data->args.a1 = (GLenum)modeRGB; \ + packed_data->args.a2 = (GLenum)modeA; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glBlendFunc +#define push_glBlendFunc(sfactor, dfactor) { \ + glBlendFunc_PACKED *packed_data = malloc(sizeof(glBlendFunc_PACKED)); \ + packed_data->format = glBlendFunc_FORMAT; \ + packed_data->func = gl4es_glBlendFunc; \ + packed_data->args.a1 = (GLenum)sfactor; \ + packed_data->args.a2 = (GLenum)dfactor; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glBlendFuncSeparate +#define push_glBlendFuncSeparate(sfactorRGB, dfactorRGB, sfactorAlpha, dfactorAlpha) { \ + glBlendFuncSeparate_PACKED *packed_data = malloc(sizeof(glBlendFuncSeparate_PACKED)); \ + packed_data->format = glBlendFuncSeparate_FORMAT; \ + packed_data->func = gl4es_glBlendFuncSeparate; \ + packed_data->args.a1 = (GLenum)sfactorRGB; \ + packed_data->args.a2 = (GLenum)dfactorRGB; \ + packed_data->args.a3 = (GLenum)sfactorAlpha; \ + packed_data->args.a4 = (GLenum)dfactorAlpha; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glBufferData +#define push_glBufferData(target, size, data, usage) { \ + glBufferData_PACKED *packed_data = malloc(sizeof(glBufferData_PACKED)); \ + packed_data->format = glBufferData_FORMAT; \ + packed_data->func = gl4es_glBufferData; \ + packed_data->args.a1 = (GLenum)target; \ + packed_data->args.a2 = (GLsizeiptr)size; \ + packed_data->args.a3 = (GLvoid *)data; \ + packed_data->args.a4 = (GLenum)usage; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glBufferSubData +#define push_glBufferSubData(target, offset, size, data) { \ + glBufferSubData_PACKED *packed_data = malloc(sizeof(glBufferSubData_PACKED)); \ + packed_data->format = glBufferSubData_FORMAT; \ + packed_data->func = gl4es_glBufferSubData; \ + packed_data->args.a1 = (GLenum)target; \ + packed_data->args.a2 = (GLintptr)offset; \ + packed_data->args.a3 = (GLsizeiptr)size; \ + packed_data->args.a4 = (GLvoid *)data; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glCheckFramebufferStatus +#define push_glCheckFramebufferStatus(target) { \ + glCheckFramebufferStatus_PACKED *packed_data = malloc(sizeof(glCheckFramebufferStatus_PACKED)); \ + packed_data->format = glCheckFramebufferStatus_FORMAT; \ + packed_data->func = gl4es_glCheckFramebufferStatus; \ + packed_data->args.a1 = (GLenum)target; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glClear +#define push_glClear(mask) { \ + glClear_PACKED *packed_data = malloc(sizeof(glClear_PACKED)); \ + packed_data->format = glClear_FORMAT; \ + packed_data->func = gl4es_glClear; \ + packed_data->args.a1 = (GLbitfield)mask; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glClearColor +#define push_glClearColor(red, green, blue, alpha) { \ + glClearColor_PACKED *packed_data = malloc(sizeof(glClearColor_PACKED)); \ + packed_data->format = glClearColor_FORMAT; \ + packed_data->func = gl4es_glClearColor; \ + packed_data->args.a1 = (GLclampf)red; \ + packed_data->args.a2 = (GLclampf)green; \ + packed_data->args.a3 = (GLclampf)blue; \ + packed_data->args.a4 = (GLclampf)alpha; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glClearColorx +#define push_glClearColorx(red, green, blue, alpha) { \ + glClearColorx_PACKED *packed_data = malloc(sizeof(glClearColorx_PACKED)); \ + packed_data->format = glClearColorx_FORMAT; \ + packed_data->func = gl4es_glClearColorx; \ + packed_data->args.a1 = (GLclampx)red; \ + packed_data->args.a2 = (GLclampx)green; \ + packed_data->args.a3 = (GLclampx)blue; \ + packed_data->args.a4 = (GLclampx)alpha; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glClearDepthf +#define push_glClearDepthf(depth) { \ + glClearDepthf_PACKED *packed_data = malloc(sizeof(glClearDepthf_PACKED)); \ + packed_data->format = glClearDepthf_FORMAT; \ + packed_data->func = gl4es_glClearDepthf; \ + packed_data->args.a1 = (GLclampf)depth; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glClearDepthx +#define push_glClearDepthx(depth) { \ + glClearDepthx_PACKED *packed_data = malloc(sizeof(glClearDepthx_PACKED)); \ + packed_data->format = glClearDepthx_FORMAT; \ + packed_data->func = gl4es_glClearDepthx; \ + packed_data->args.a1 = (GLclampx)depth; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glClearStencil +#define push_glClearStencil(s) { \ + glClearStencil_PACKED *packed_data = malloc(sizeof(glClearStencil_PACKED)); \ + packed_data->format = glClearStencil_FORMAT; \ + packed_data->func = gl4es_glClearStencil; \ + packed_data->args.a1 = (GLint)s; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glClientActiveTexture +#define push_glClientActiveTexture(texture) { \ + glClientActiveTexture_PACKED *packed_data = malloc(sizeof(glClientActiveTexture_PACKED)); \ + packed_data->format = glClientActiveTexture_FORMAT; \ + packed_data->func = gl4es_glClientActiveTexture; \ + packed_data->args.a1 = (GLenum)texture; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glClipPlanef +#define push_glClipPlanef(plane, equation) { \ + glClipPlanef_PACKED *packed_data = malloc(sizeof(glClipPlanef_PACKED)); \ + packed_data->format = glClipPlanef_FORMAT; \ + packed_data->func = gl4es_glClipPlanef; \ + packed_data->args.a1 = (GLenum)plane; \ + packed_data->args.a2 = (GLfloat *)equation; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glClipPlanex +#define push_glClipPlanex(plane, equation) { \ + glClipPlanex_PACKED *packed_data = malloc(sizeof(glClipPlanex_PACKED)); \ + packed_data->format = glClipPlanex_FORMAT; \ + packed_data->func = gl4es_glClipPlanex; \ + packed_data->args.a1 = (GLenum)plane; \ + packed_data->args.a2 = (GLfixed *)equation; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glColor4f +#define push_glColor4f(red, green, blue, alpha) { \ + glColor4f_PACKED *packed_data = malloc(sizeof(glColor4f_PACKED)); \ + packed_data->format = glColor4f_FORMAT; \ + packed_data->func = gl4es_glColor4f; \ + packed_data->args.a1 = (GLfloat)red; \ + packed_data->args.a2 = (GLfloat)green; \ + packed_data->args.a3 = (GLfloat)blue; \ + packed_data->args.a4 = (GLfloat)alpha; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glColor4ub +#define push_glColor4ub(red, green, blue, alpha) { \ + glColor4ub_PACKED *packed_data = malloc(sizeof(glColor4ub_PACKED)); \ + packed_data->format = glColor4ub_FORMAT; \ + packed_data->func = gl4es_glColor4ub; \ + packed_data->args.a1 = (GLubyte)red; \ + packed_data->args.a2 = (GLubyte)green; \ + packed_data->args.a3 = (GLubyte)blue; \ + packed_data->args.a4 = (GLubyte)alpha; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glColor4x +#define push_glColor4x(red, green, blue, alpha) { \ + glColor4x_PACKED *packed_data = malloc(sizeof(glColor4x_PACKED)); \ + packed_data->format = glColor4x_FORMAT; \ + packed_data->func = gl4es_glColor4x; \ + packed_data->args.a1 = (GLfixed)red; \ + packed_data->args.a2 = (GLfixed)green; \ + packed_data->args.a3 = (GLfixed)blue; \ + packed_data->args.a4 = (GLfixed)alpha; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glColorMask +#define push_glColorMask(red, green, blue, alpha) { \ + glColorMask_PACKED *packed_data = malloc(sizeof(glColorMask_PACKED)); \ + packed_data->format = glColorMask_FORMAT; \ + packed_data->func = gl4es_glColorMask; \ + packed_data->args.a1 = (GLboolean)red; \ + packed_data->args.a2 = (GLboolean)green; \ + packed_data->args.a3 = (GLboolean)blue; \ + packed_data->args.a4 = (GLboolean)alpha; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glColorPointer +#define push_glColorPointer(size, type, stride, pointer) { \ + glColorPointer_PACKED *packed_data = malloc(sizeof(glColorPointer_PACKED)); \ + packed_data->format = glColorPointer_FORMAT; \ + packed_data->func = gl4es_glColorPointer; \ + packed_data->args.a1 = (GLint)size; \ + packed_data->args.a2 = (GLenum)type; \ + packed_data->args.a3 = (GLsizei)stride; \ + packed_data->args.a4 = (GLvoid *)pointer; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glCompileShader +#define push_glCompileShader(shader) { \ + glCompileShader_PACKED *packed_data = malloc(sizeof(glCompileShader_PACKED)); \ + packed_data->format = glCompileShader_FORMAT; \ + packed_data->func = gl4es_glCompileShader; \ + packed_data->args.a1 = (GLuint)shader; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glCompressedTexImage2D +#define push_glCompressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data) { \ + glCompressedTexImage2D_PACKED *packed_data = malloc(sizeof(glCompressedTexImage2D_PACKED)); \ + packed_data->format = glCompressedTexImage2D_FORMAT; \ + packed_data->func = gl4es_glCompressedTexImage2D; \ + packed_data->args.a1 = (GLenum)target; \ + packed_data->args.a2 = (GLint)level; \ + packed_data->args.a3 = (GLenum)internalformat; \ + packed_data->args.a4 = (GLsizei)width; \ + packed_data->args.a5 = (GLsizei)height; \ + packed_data->args.a6 = (GLint)border; \ + packed_data->args.a7 = (GLsizei)imageSize; \ + packed_data->args.a8 = (GLvoid *)data; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glCompressedTexSubImage2D +#define push_glCompressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize, data) { \ + glCompressedTexSubImage2D_PACKED *packed_data = malloc(sizeof(glCompressedTexSubImage2D_PACKED)); \ + packed_data->format = glCompressedTexSubImage2D_FORMAT; \ + packed_data->func = gl4es_glCompressedTexSubImage2D; \ + packed_data->args.a1 = (GLenum)target; \ + packed_data->args.a2 = (GLint)level; \ + packed_data->args.a3 = (GLint)xoffset; \ + packed_data->args.a4 = (GLint)yoffset; \ + packed_data->args.a5 = (GLsizei)width; \ + packed_data->args.a6 = (GLsizei)height; \ + packed_data->args.a7 = (GLenum)format; \ + packed_data->args.a8 = (GLsizei)imageSize; \ + packed_data->args.a9 = (GLvoid *)data; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glCopyTexImage2D +#define push_glCopyTexImage2D(target, level, internalformat, x, y, width, height, border) { \ + glCopyTexImage2D_PACKED *packed_data = malloc(sizeof(glCopyTexImage2D_PACKED)); \ + packed_data->format = glCopyTexImage2D_FORMAT; \ + packed_data->func = gl4es_glCopyTexImage2D; \ + packed_data->args.a1 = (GLenum)target; \ + packed_data->args.a2 = (GLint)level; \ + packed_data->args.a3 = (GLenum)internalformat; \ + packed_data->args.a4 = (GLint)x; \ + packed_data->args.a5 = (GLint)y; \ + packed_data->args.a6 = (GLsizei)width; \ + packed_data->args.a7 = (GLsizei)height; \ + packed_data->args.a8 = (GLint)border; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glCopyTexSubImage2D +#define push_glCopyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height) { \ + glCopyTexSubImage2D_PACKED *packed_data = malloc(sizeof(glCopyTexSubImage2D_PACKED)); \ + packed_data->format = glCopyTexSubImage2D_FORMAT; \ + packed_data->func = gl4es_glCopyTexSubImage2D; \ + packed_data->args.a1 = (GLenum)target; \ + packed_data->args.a2 = (GLint)level; \ + packed_data->args.a3 = (GLint)xoffset; \ + packed_data->args.a4 = (GLint)yoffset; \ + packed_data->args.a5 = (GLint)x; \ + packed_data->args.a6 = (GLint)y; \ + packed_data->args.a7 = (GLsizei)width; \ + packed_data->args.a8 = (GLsizei)height; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glCreateProgram +#define push_glCreateProgram() { \ + glCreateProgram_PACKED *packed_data = malloc(sizeof(glCreateProgram_PACKED)); \ + packed_data->format = glCreateProgram_FORMAT; \ + packed_data->func = gl4es_glCreateProgram; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glCreateShader +#define push_glCreateShader(type) { \ + glCreateShader_PACKED *packed_data = malloc(sizeof(glCreateShader_PACKED)); \ + packed_data->format = glCreateShader_FORMAT; \ + packed_data->func = gl4es_glCreateShader; \ + packed_data->args.a1 = (GLenum)type; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glCullFace +#define push_glCullFace(mode) { \ + glCullFace_PACKED *packed_data = malloc(sizeof(glCullFace_PACKED)); \ + packed_data->format = glCullFace_FORMAT; \ + packed_data->func = gl4es_glCullFace; \ + packed_data->args.a1 = (GLenum)mode; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glDeleteBuffers +#define push_glDeleteBuffers(n, buffer) { \ + glDeleteBuffers_PACKED *packed_data = malloc(sizeof(glDeleteBuffers_PACKED)); \ + packed_data->format = glDeleteBuffers_FORMAT; \ + packed_data->func = gl4es_glDeleteBuffers; \ + packed_data->args.a1 = (GLsizei)n; \ + packed_data->args.a2 = (GLuint *)buffer; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glDeleteFramebuffers +#define push_glDeleteFramebuffers(n, framebuffers) { \ + glDeleteFramebuffers_PACKED *packed_data = malloc(sizeof(glDeleteFramebuffers_PACKED)); \ + packed_data->format = glDeleteFramebuffers_FORMAT; \ + packed_data->func = gl4es_glDeleteFramebuffers; \ + packed_data->args.a1 = (GLsizei)n; \ + packed_data->args.a2 = (GLuint *)framebuffers; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glDeleteProgram +#define push_glDeleteProgram(program) { \ + glDeleteProgram_PACKED *packed_data = malloc(sizeof(glDeleteProgram_PACKED)); \ + packed_data->format = glDeleteProgram_FORMAT; \ + packed_data->func = gl4es_glDeleteProgram; \ + packed_data->args.a1 = (GLuint)program; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glDeleteRenderbuffers +#define push_glDeleteRenderbuffers(n, renderbuffers) { \ + glDeleteRenderbuffers_PACKED *packed_data = malloc(sizeof(glDeleteRenderbuffers_PACKED)); \ + packed_data->format = glDeleteRenderbuffers_FORMAT; \ + packed_data->func = gl4es_glDeleteRenderbuffers; \ + packed_data->args.a1 = (GLsizei)n; \ + packed_data->args.a2 = (GLuint *)renderbuffers; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glDeleteShader +#define push_glDeleteShader(shader) { \ + glDeleteShader_PACKED *packed_data = malloc(sizeof(glDeleteShader_PACKED)); \ + packed_data->format = glDeleteShader_FORMAT; \ + packed_data->func = gl4es_glDeleteShader; \ + packed_data->args.a1 = (GLuint)shader; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glDeleteTextures +#define push_glDeleteTextures(n, textures) { \ + glDeleteTextures_PACKED *packed_data = malloc(sizeof(glDeleteTextures_PACKED)); \ + packed_data->format = glDeleteTextures_FORMAT; \ + packed_data->func = gl4es_glDeleteTextures; \ + packed_data->args.a1 = (GLsizei)n; \ + packed_data->args.a2 = (GLuint *)textures; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glDepthFunc +#define push_glDepthFunc(func) { \ + glDepthFunc_PACKED *packed_data = malloc(sizeof(glDepthFunc_PACKED)); \ + packed_data->format = glDepthFunc_FORMAT; \ + packed_data->func = gl4es_glDepthFunc; \ + packed_data->args.a1 = (GLenum)func; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glDepthMask +#define push_glDepthMask(flag) { \ + glDepthMask_PACKED *packed_data = malloc(sizeof(glDepthMask_PACKED)); \ + packed_data->format = glDepthMask_FORMAT; \ + packed_data->func = gl4es_glDepthMask; \ + packed_data->args.a1 = (GLboolean)flag; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glDepthRangef +#define push_glDepthRangef(near, far) { \ + glDepthRangef_PACKED *packed_data = malloc(sizeof(glDepthRangef_PACKED)); \ + packed_data->format = glDepthRangef_FORMAT; \ + packed_data->func = gl4es_glDepthRangef; \ + packed_data->args.a1 = (GLclampf)near; \ + packed_data->args.a2 = (GLclampf)far; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glDepthRangex +#define push_glDepthRangex(near, far) { \ + glDepthRangex_PACKED *packed_data = malloc(sizeof(glDepthRangex_PACKED)); \ + packed_data->format = glDepthRangex_FORMAT; \ + packed_data->func = gl4es_glDepthRangex; \ + packed_data->args.a1 = (GLclampx)near; \ + packed_data->args.a2 = (GLclampx)far; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glDetachShader +#define push_glDetachShader(program, shader) { \ + glDetachShader_PACKED *packed_data = malloc(sizeof(glDetachShader_PACKED)); \ + packed_data->format = glDetachShader_FORMAT; \ + packed_data->func = gl4es_glDetachShader; \ + packed_data->args.a1 = (GLuint)program; \ + packed_data->args.a2 = (GLuint)shader; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glDisable +#define push_glDisable(cap) { \ + glDisable_PACKED *packed_data = malloc(sizeof(glDisable_PACKED)); \ + packed_data->format = glDisable_FORMAT; \ + packed_data->func = gl4es_glDisable; \ + packed_data->args.a1 = (GLenum)cap; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glDisableClientState +#define push_glDisableClientState(array) { \ + glDisableClientState_PACKED *packed_data = malloc(sizeof(glDisableClientState_PACKED)); \ + packed_data->format = glDisableClientState_FORMAT; \ + packed_data->func = gl4es_glDisableClientState; \ + packed_data->args.a1 = (GLenum)array; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glDisableVertexAttribArray +#define push_glDisableVertexAttribArray(index) { \ + glDisableVertexAttribArray_PACKED *packed_data = malloc(sizeof(glDisableVertexAttribArray_PACKED)); \ + packed_data->format = glDisableVertexAttribArray_FORMAT; \ + packed_data->func = gl4es_glDisableVertexAttribArray; \ + packed_data->args.a1 = (GLuint)index; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glDrawArrays +#define push_glDrawArrays(mode, first, count) { \ + glDrawArrays_PACKED *packed_data = malloc(sizeof(glDrawArrays_PACKED)); \ + packed_data->format = glDrawArrays_FORMAT; \ + packed_data->func = gl4es_glDrawArrays; \ + packed_data->args.a1 = (GLenum)mode; \ + packed_data->args.a2 = (GLint)first; \ + packed_data->args.a3 = (GLsizei)count; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glDrawElements +#define push_glDrawElements(mode, count, type, indices) { \ + glDrawElements_PACKED *packed_data = malloc(sizeof(glDrawElements_PACKED)); \ + packed_data->format = glDrawElements_FORMAT; \ + packed_data->func = gl4es_glDrawElements; \ + packed_data->args.a1 = (GLenum)mode; \ + packed_data->args.a2 = (GLsizei)count; \ + packed_data->args.a3 = (GLenum)type; \ + packed_data->args.a4 = (GLvoid *)indices; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glDrawTexf +#define push_glDrawTexf(x, y, z, width, height) { \ + glDrawTexf_PACKED *packed_data = malloc(sizeof(glDrawTexf_PACKED)); \ + packed_data->format = glDrawTexf_FORMAT; \ + packed_data->func = gl4es_glDrawTexf; \ + packed_data->args.a1 = (GLfloat)x; \ + packed_data->args.a2 = (GLfloat)y; \ + packed_data->args.a3 = (GLfloat)z; \ + packed_data->args.a4 = (GLfloat)width; \ + packed_data->args.a5 = (GLfloat)height; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glDrawTexi +#define push_glDrawTexi(x, y, z, width, height) { \ + glDrawTexi_PACKED *packed_data = malloc(sizeof(glDrawTexi_PACKED)); \ + packed_data->format = glDrawTexi_FORMAT; \ + packed_data->func = gl4es_glDrawTexi; \ + packed_data->args.a1 = (GLint)x; \ + packed_data->args.a2 = (GLint)y; \ + packed_data->args.a3 = (GLint)z; \ + packed_data->args.a4 = (GLint)width; \ + packed_data->args.a5 = (GLint)height; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glEnable +#define push_glEnable(cap) { \ + glEnable_PACKED *packed_data = malloc(sizeof(glEnable_PACKED)); \ + packed_data->format = glEnable_FORMAT; \ + packed_data->func = gl4es_glEnable; \ + packed_data->args.a1 = (GLenum)cap; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glEnableClientState +#define push_glEnableClientState(array) { \ + glEnableClientState_PACKED *packed_data = malloc(sizeof(glEnableClientState_PACKED)); \ + packed_data->format = glEnableClientState_FORMAT; \ + packed_data->func = gl4es_glEnableClientState; \ + packed_data->args.a1 = (GLenum)array; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glEnableVertexAttribArray +#define push_glEnableVertexAttribArray(index) { \ + glEnableVertexAttribArray_PACKED *packed_data = malloc(sizeof(glEnableVertexAttribArray_PACKED)); \ + packed_data->format = glEnableVertexAttribArray_FORMAT; \ + packed_data->func = gl4es_glEnableVertexAttribArray; \ + packed_data->args.a1 = (GLuint)index; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glFinish +#define push_glFinish() { \ + glFinish_PACKED *packed_data = malloc(sizeof(glFinish_PACKED)); \ + packed_data->format = glFinish_FORMAT; \ + packed_data->func = gl4es_glFinish; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glFlush +#define push_glFlush() { \ + glFlush_PACKED *packed_data = malloc(sizeof(glFlush_PACKED)); \ + packed_data->format = glFlush_FORMAT; \ + packed_data->func = gl4es_glFlush; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glFogCoordPointer +#define push_glFogCoordPointer(type, stride, pointer) { \ + glFogCoordPointer_PACKED *packed_data = malloc(sizeof(glFogCoordPointer_PACKED)); \ + packed_data->format = glFogCoordPointer_FORMAT; \ + packed_data->func = gl4es_glFogCoordPointer; \ + packed_data->args.a1 = (GLenum)type; \ + packed_data->args.a2 = (GLsizei)stride; \ + packed_data->args.a3 = (GLvoid *)pointer; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glFogCoordf +#define push_glFogCoordf(coord) { \ + glFogCoordf_PACKED *packed_data = malloc(sizeof(glFogCoordf_PACKED)); \ + packed_data->format = glFogCoordf_FORMAT; \ + packed_data->func = gl4es_glFogCoordf; \ + packed_data->args.a1 = (GLfloat)coord; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glFogCoordfv +#define push_glFogCoordfv(coord) { \ + glFogCoordfv_PACKED *packed_data = malloc(sizeof(glFogCoordfv_PACKED)); \ + packed_data->format = glFogCoordfv_FORMAT; \ + packed_data->func = gl4es_glFogCoordfv; \ + packed_data->args.a1 = (GLfloat *)coord; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glFogf +#define push_glFogf(pname, param) { \ + glFogf_PACKED *packed_data = malloc(sizeof(glFogf_PACKED)); \ + packed_data->format = glFogf_FORMAT; \ + packed_data->func = gl4es_glFogf; \ + packed_data->args.a1 = (GLenum)pname; \ + packed_data->args.a2 = (GLfloat)param; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glFogfv +#define push_glFogfv(pname, params) { \ + glFogfv_PACKED *packed_data = malloc(sizeof(glFogfv_PACKED)); \ + packed_data->format = glFogfv_FORMAT; \ + packed_data->func = gl4es_glFogfv; \ + packed_data->args.a1 = (GLenum)pname; \ + packed_data->args.a2 = (GLfloat *)params; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glFogx +#define push_glFogx(pname, param) { \ + glFogx_PACKED *packed_data = malloc(sizeof(glFogx_PACKED)); \ + packed_data->format = glFogx_FORMAT; \ + packed_data->func = gl4es_glFogx; \ + packed_data->args.a1 = (GLenum)pname; \ + packed_data->args.a2 = (GLfixed)param; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glFogxv +#define push_glFogxv(pname, params) { \ + glFogxv_PACKED *packed_data = malloc(sizeof(glFogxv_PACKED)); \ + packed_data->format = glFogxv_FORMAT; \ + packed_data->func = gl4es_glFogxv; \ + packed_data->args.a1 = (GLenum)pname; \ + packed_data->args.a2 = (GLfixed *)params; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glFramebufferRenderbuffer +#define push_glFramebufferRenderbuffer(target, attachment, renderbuffertarget, renderbuffer) { \ + glFramebufferRenderbuffer_PACKED *packed_data = malloc(sizeof(glFramebufferRenderbuffer_PACKED)); \ + packed_data->format = glFramebufferRenderbuffer_FORMAT; \ + packed_data->func = gl4es_glFramebufferRenderbuffer; \ + packed_data->args.a1 = (GLenum)target; \ + packed_data->args.a2 = (GLenum)attachment; \ + packed_data->args.a3 = (GLenum)renderbuffertarget; \ + packed_data->args.a4 = (GLuint)renderbuffer; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glFramebufferTexture2D +#define push_glFramebufferTexture2D(target, attachment, textarget, texture, level) { \ + glFramebufferTexture2D_PACKED *packed_data = malloc(sizeof(glFramebufferTexture2D_PACKED)); \ + packed_data->format = glFramebufferTexture2D_FORMAT; \ + packed_data->func = gl4es_glFramebufferTexture2D; \ + packed_data->args.a1 = (GLenum)target; \ + packed_data->args.a2 = (GLenum)attachment; \ + packed_data->args.a3 = (GLenum)textarget; \ + packed_data->args.a4 = (GLuint)texture; \ + packed_data->args.a5 = (GLint)level; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glFrontFace +#define push_glFrontFace(mode) { \ + glFrontFace_PACKED *packed_data = malloc(sizeof(glFrontFace_PACKED)); \ + packed_data->format = glFrontFace_FORMAT; \ + packed_data->func = gl4es_glFrontFace; \ + packed_data->args.a1 = (GLenum)mode; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glFrustumf +#define push_glFrustumf(left, right, bottom, top, near, far) { \ + glFrustumf_PACKED *packed_data = malloc(sizeof(glFrustumf_PACKED)); \ + packed_data->format = glFrustumf_FORMAT; \ + packed_data->func = gl4es_glFrustumf; \ + packed_data->args.a1 = (GLfloat)left; \ + packed_data->args.a2 = (GLfloat)right; \ + packed_data->args.a3 = (GLfloat)bottom; \ + packed_data->args.a4 = (GLfloat)top; \ + packed_data->args.a5 = (GLfloat)near; \ + packed_data->args.a6 = (GLfloat)far; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glFrustumx +#define push_glFrustumx(left, right, bottom, top, near, far) { \ + glFrustumx_PACKED *packed_data = malloc(sizeof(glFrustumx_PACKED)); \ + packed_data->format = glFrustumx_FORMAT; \ + packed_data->func = gl4es_glFrustumx; \ + packed_data->args.a1 = (GLfixed)left; \ + packed_data->args.a2 = (GLfixed)right; \ + packed_data->args.a3 = (GLfixed)bottom; \ + packed_data->args.a4 = (GLfixed)top; \ + packed_data->args.a5 = (GLfixed)near; \ + packed_data->args.a6 = (GLfixed)far; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glGenBuffers +#define push_glGenBuffers(n, buffer) { \ + glGenBuffers_PACKED *packed_data = malloc(sizeof(glGenBuffers_PACKED)); \ + packed_data->format = glGenBuffers_FORMAT; \ + packed_data->func = gl4es_glGenBuffers; \ + packed_data->args.a1 = (GLsizei)n; \ + packed_data->args.a2 = (GLuint *)buffer; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glGenFramebuffers +#define push_glGenFramebuffers(n, ids) { \ + glGenFramebuffers_PACKED *packed_data = malloc(sizeof(glGenFramebuffers_PACKED)); \ + packed_data->format = glGenFramebuffers_FORMAT; \ + packed_data->func = gl4es_glGenFramebuffers; \ + packed_data->args.a1 = (GLsizei)n; \ + packed_data->args.a2 = (GLuint *)ids; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glGenRenderbuffers +#define push_glGenRenderbuffers(n, renderbuffers) { \ + glGenRenderbuffers_PACKED *packed_data = malloc(sizeof(glGenRenderbuffers_PACKED)); \ + packed_data->format = glGenRenderbuffers_FORMAT; \ + packed_data->func = gl4es_glGenRenderbuffers; \ + packed_data->args.a1 = (GLsizei)n; \ + packed_data->args.a2 = (GLuint *)renderbuffers; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glGenTextures +#define push_glGenTextures(n, textures) { \ + glGenTextures_PACKED *packed_data = malloc(sizeof(glGenTextures_PACKED)); \ + packed_data->format = glGenTextures_FORMAT; \ + packed_data->func = gl4es_glGenTextures; \ + packed_data->args.a1 = (GLsizei)n; \ + packed_data->args.a2 = (GLuint *)textures; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glGenerateMipmap +#define push_glGenerateMipmap(target) { \ + glGenerateMipmap_PACKED *packed_data = malloc(sizeof(glGenerateMipmap_PACKED)); \ + packed_data->format = glGenerateMipmap_FORMAT; \ + packed_data->func = gl4es_glGenerateMipmap; \ + packed_data->args.a1 = (GLenum)target; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glGetActiveAttrib +#define push_glGetActiveAttrib(program, index, bufSize, length, size, type, name) { \ + glGetActiveAttrib_PACKED *packed_data = malloc(sizeof(glGetActiveAttrib_PACKED)); \ + packed_data->format = glGetActiveAttrib_FORMAT; \ + packed_data->func = gl4es_glGetActiveAttrib; \ + packed_data->args.a1 = (GLuint)program; \ + packed_data->args.a2 = (GLuint)index; \ + packed_data->args.a3 = (GLsizei)bufSize; \ + packed_data->args.a4 = (GLsizei *)length; \ + packed_data->args.a5 = (GLint *)size; \ + packed_data->args.a6 = (GLenum *)type; \ + packed_data->args.a7 = (GLchar *)name; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glGetActiveUniform +#define push_glGetActiveUniform(program, index, bufSize, length, size, type, name) { \ + glGetActiveUniform_PACKED *packed_data = malloc(sizeof(glGetActiveUniform_PACKED)); \ + packed_data->format = glGetActiveUniform_FORMAT; \ + packed_data->func = gl4es_glGetActiveUniform; \ + packed_data->args.a1 = (GLuint)program; \ + packed_data->args.a2 = (GLuint)index; \ + packed_data->args.a3 = (GLsizei)bufSize; \ + packed_data->args.a4 = (GLsizei *)length; \ + packed_data->args.a5 = (GLint *)size; \ + packed_data->args.a6 = (GLenum *)type; \ + packed_data->args.a7 = (GLchar *)name; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glGetAttachedShaders +#define push_glGetAttachedShaders(program, maxCount, count, obj) { \ + glGetAttachedShaders_PACKED *packed_data = malloc(sizeof(glGetAttachedShaders_PACKED)); \ + packed_data->format = glGetAttachedShaders_FORMAT; \ + packed_data->func = gl4es_glGetAttachedShaders; \ + packed_data->args.a1 = (GLuint)program; \ + packed_data->args.a2 = (GLsizei)maxCount; \ + packed_data->args.a3 = (GLsizei *)count; \ + packed_data->args.a4 = (GLuint *)obj; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glGetAttribLocation +#define push_glGetAttribLocation(program, name) { \ + glGetAttribLocation_PACKED *packed_data = malloc(sizeof(glGetAttribLocation_PACKED)); \ + packed_data->format = glGetAttribLocation_FORMAT; \ + packed_data->func = gl4es_glGetAttribLocation; \ + packed_data->args.a1 = (GLuint)program; \ + packed_data->args.a2 = (GLchar *)name; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glGetBooleanv +#define push_glGetBooleanv(pname, params) { \ + glGetBooleanv_PACKED *packed_data = malloc(sizeof(glGetBooleanv_PACKED)); \ + packed_data->format = glGetBooleanv_FORMAT; \ + packed_data->func = gl4es_glGetBooleanv; \ + packed_data->args.a1 = (GLenum)pname; \ + packed_data->args.a2 = (GLboolean *)params; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glGetBufferParameteriv +#define push_glGetBufferParameteriv(target, pname, params) { \ + glGetBufferParameteriv_PACKED *packed_data = malloc(sizeof(glGetBufferParameteriv_PACKED)); \ + packed_data->format = glGetBufferParameteriv_FORMAT; \ + packed_data->func = gl4es_glGetBufferParameteriv; \ + packed_data->args.a1 = (GLenum)target; \ + packed_data->args.a2 = (GLenum)pname; \ + packed_data->args.a3 = (GLint *)params; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glGetClipPlanef +#define push_glGetClipPlanef(plane, equation) { \ + glGetClipPlanef_PACKED *packed_data = malloc(sizeof(glGetClipPlanef_PACKED)); \ + packed_data->format = glGetClipPlanef_FORMAT; \ + packed_data->func = gl4es_glGetClipPlanef; \ + packed_data->args.a1 = (GLenum)plane; \ + packed_data->args.a2 = (GLfloat *)equation; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glGetClipPlanex +#define push_glGetClipPlanex(plane, equation) { \ + glGetClipPlanex_PACKED *packed_data = malloc(sizeof(glGetClipPlanex_PACKED)); \ + packed_data->format = glGetClipPlanex_FORMAT; \ + packed_data->func = gl4es_glGetClipPlanex; \ + packed_data->args.a1 = (GLenum)plane; \ + packed_data->args.a2 = (GLfixed *)equation; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glGetError +#define push_glGetError() { \ + glGetError_PACKED *packed_data = malloc(sizeof(glGetError_PACKED)); \ + packed_data->format = glGetError_FORMAT; \ + packed_data->func = gl4es_glGetError; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glGetFixedv +#define push_glGetFixedv(pname, params) { \ + glGetFixedv_PACKED *packed_data = malloc(sizeof(glGetFixedv_PACKED)); \ + packed_data->format = glGetFixedv_FORMAT; \ + packed_data->func = gl4es_glGetFixedv; \ + packed_data->args.a1 = (GLenum)pname; \ + packed_data->args.a2 = (GLfixed *)params; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glGetFloatv +#define push_glGetFloatv(pname, params) { \ + glGetFloatv_PACKED *packed_data = malloc(sizeof(glGetFloatv_PACKED)); \ + packed_data->format = glGetFloatv_FORMAT; \ + packed_data->func = gl4es_glGetFloatv; \ + packed_data->args.a1 = (GLenum)pname; \ + packed_data->args.a2 = (GLfloat *)params; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glGetFramebufferAttachmentParameteriv +#define push_glGetFramebufferAttachmentParameteriv(target, attachment, pname, params) { \ + glGetFramebufferAttachmentParameteriv_PACKED *packed_data = malloc(sizeof(glGetFramebufferAttachmentParameteriv_PACKED)); \ + packed_data->format = glGetFramebufferAttachmentParameteriv_FORMAT; \ + packed_data->func = gl4es_glGetFramebufferAttachmentParameteriv; \ + packed_data->args.a1 = (GLenum)target; \ + packed_data->args.a2 = (GLenum)attachment; \ + packed_data->args.a3 = (GLenum)pname; \ + packed_data->args.a4 = (GLint *)params; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glGetIntegerv +#define push_glGetIntegerv(pname, params) { \ + glGetIntegerv_PACKED *packed_data = malloc(sizeof(glGetIntegerv_PACKED)); \ + packed_data->format = glGetIntegerv_FORMAT; \ + packed_data->func = gl4es_glGetIntegerv; \ + packed_data->args.a1 = (GLenum)pname; \ + packed_data->args.a2 = (GLint *)params; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glGetLightfv +#define push_glGetLightfv(light, pname, params) { \ + glGetLightfv_PACKED *packed_data = malloc(sizeof(glGetLightfv_PACKED)); \ + packed_data->format = glGetLightfv_FORMAT; \ + packed_data->func = gl4es_glGetLightfv; \ + packed_data->args.a1 = (GLenum)light; \ + packed_data->args.a2 = (GLenum)pname; \ + packed_data->args.a3 = (GLfloat *)params; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glGetLightxv +#define push_glGetLightxv(light, pname, params) { \ + glGetLightxv_PACKED *packed_data = malloc(sizeof(glGetLightxv_PACKED)); \ + packed_data->format = glGetLightxv_FORMAT; \ + packed_data->func = gl4es_glGetLightxv; \ + packed_data->args.a1 = (GLenum)light; \ + packed_data->args.a2 = (GLenum)pname; \ + packed_data->args.a3 = (GLfixed *)params; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glGetMaterialfv +#define push_glGetMaterialfv(face, pname, params) { \ + glGetMaterialfv_PACKED *packed_data = malloc(sizeof(glGetMaterialfv_PACKED)); \ + packed_data->format = glGetMaterialfv_FORMAT; \ + packed_data->func = gl4es_glGetMaterialfv; \ + packed_data->args.a1 = (GLenum)face; \ + packed_data->args.a2 = (GLenum)pname; \ + packed_data->args.a3 = (GLfloat *)params; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glGetMaterialxv +#define push_glGetMaterialxv(face, pname, params) { \ + glGetMaterialxv_PACKED *packed_data = malloc(sizeof(glGetMaterialxv_PACKED)); \ + packed_data->format = glGetMaterialxv_FORMAT; \ + packed_data->func = gl4es_glGetMaterialxv; \ + packed_data->args.a1 = (GLenum)face; \ + packed_data->args.a2 = (GLenum)pname; \ + packed_data->args.a3 = (GLfixed *)params; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glGetPointerv +#define push_glGetPointerv(pname, params) { \ + glGetPointerv_PACKED *packed_data = malloc(sizeof(glGetPointerv_PACKED)); \ + packed_data->format = glGetPointerv_FORMAT; \ + packed_data->func = gl4es_glGetPointerv; \ + packed_data->args.a1 = (GLenum)pname; \ + packed_data->args.a2 = (GLvoid **)params; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glGetProgramInfoLog +#define push_glGetProgramInfoLog(program, bufSize, length, infoLog) { \ + glGetProgramInfoLog_PACKED *packed_data = malloc(sizeof(glGetProgramInfoLog_PACKED)); \ + packed_data->format = glGetProgramInfoLog_FORMAT; \ + packed_data->func = gl4es_glGetProgramInfoLog; \ + packed_data->args.a1 = (GLuint)program; \ + packed_data->args.a2 = (GLsizei)bufSize; \ + packed_data->args.a3 = (GLsizei *)length; \ + packed_data->args.a4 = (GLchar *)infoLog; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glGetProgramiv +#define push_glGetProgramiv(program, pname, params) { \ + glGetProgramiv_PACKED *packed_data = malloc(sizeof(glGetProgramiv_PACKED)); \ + packed_data->format = glGetProgramiv_FORMAT; \ + packed_data->func = gl4es_glGetProgramiv; \ + packed_data->args.a1 = (GLuint)program; \ + packed_data->args.a2 = (GLenum)pname; \ + packed_data->args.a3 = (GLint *)params; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glGetRenderbufferParameteriv +#define push_glGetRenderbufferParameteriv(target, pname, params) { \ + glGetRenderbufferParameteriv_PACKED *packed_data = malloc(sizeof(glGetRenderbufferParameteriv_PACKED)); \ + packed_data->format = glGetRenderbufferParameteriv_FORMAT; \ + packed_data->func = gl4es_glGetRenderbufferParameteriv; \ + packed_data->args.a1 = (GLenum)target; \ + packed_data->args.a2 = (GLenum)pname; \ + packed_data->args.a3 = (GLint *)params; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glGetShaderInfoLog +#define push_glGetShaderInfoLog(shader, bufSize, length, infoLog) { \ + glGetShaderInfoLog_PACKED *packed_data = malloc(sizeof(glGetShaderInfoLog_PACKED)); \ + packed_data->format = glGetShaderInfoLog_FORMAT; \ + packed_data->func = gl4es_glGetShaderInfoLog; \ + packed_data->args.a1 = (GLuint)shader; \ + packed_data->args.a2 = (GLsizei)bufSize; \ + packed_data->args.a3 = (GLsizei *)length; \ + packed_data->args.a4 = (GLchar *)infoLog; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glGetShaderPrecisionFormat +#define push_glGetShaderPrecisionFormat(shadertype, precisiontype, range, precision) { \ + glGetShaderPrecisionFormat_PACKED *packed_data = malloc(sizeof(glGetShaderPrecisionFormat_PACKED)); \ + packed_data->format = glGetShaderPrecisionFormat_FORMAT; \ + packed_data->func = gl4es_glGetShaderPrecisionFormat; \ + packed_data->args.a1 = (GLenum)shadertype; \ + packed_data->args.a2 = (GLenum)precisiontype; \ + packed_data->args.a3 = (GLint *)range; \ + packed_data->args.a4 = (GLint *)precision; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glGetShaderSource +#define push_glGetShaderSource(shader, bufSize, length, source) { \ + glGetShaderSource_PACKED *packed_data = malloc(sizeof(glGetShaderSource_PACKED)); \ + packed_data->format = glGetShaderSource_FORMAT; \ + packed_data->func = gl4es_glGetShaderSource; \ + packed_data->args.a1 = (GLuint)shader; \ + packed_data->args.a2 = (GLsizei)bufSize; \ + packed_data->args.a3 = (GLsizei *)length; \ + packed_data->args.a4 = (GLchar *)source; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glGetShaderiv +#define push_glGetShaderiv(shader, pname, params) { \ + glGetShaderiv_PACKED *packed_data = malloc(sizeof(glGetShaderiv_PACKED)); \ + packed_data->format = glGetShaderiv_FORMAT; \ + packed_data->func = gl4es_glGetShaderiv; \ + packed_data->args.a1 = (GLuint)shader; \ + packed_data->args.a2 = (GLenum)pname; \ + packed_data->args.a3 = (GLint *)params; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glGetString +#define push_glGetString(name) { \ + glGetString_PACKED *packed_data = malloc(sizeof(glGetString_PACKED)); \ + packed_data->format = glGetString_FORMAT; \ + packed_data->func = gl4es_glGetString; \ + packed_data->args.a1 = (GLenum)name; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glGetTexEnvfv +#define push_glGetTexEnvfv(target, pname, params) { \ + glGetTexEnvfv_PACKED *packed_data = malloc(sizeof(glGetTexEnvfv_PACKED)); \ + packed_data->format = glGetTexEnvfv_FORMAT; \ + packed_data->func = gl4es_glGetTexEnvfv; \ + packed_data->args.a1 = (GLenum)target; \ + packed_data->args.a2 = (GLenum)pname; \ + packed_data->args.a3 = (GLfloat *)params; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glGetTexEnviv +#define push_glGetTexEnviv(target, pname, params) { \ + glGetTexEnviv_PACKED *packed_data = malloc(sizeof(glGetTexEnviv_PACKED)); \ + packed_data->format = glGetTexEnviv_FORMAT; \ + packed_data->func = gl4es_glGetTexEnviv; \ + packed_data->args.a1 = (GLenum)target; \ + packed_data->args.a2 = (GLenum)pname; \ + packed_data->args.a3 = (GLint *)params; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glGetTexEnvxv +#define push_glGetTexEnvxv(target, pname, params) { \ + glGetTexEnvxv_PACKED *packed_data = malloc(sizeof(glGetTexEnvxv_PACKED)); \ + packed_data->format = glGetTexEnvxv_FORMAT; \ + packed_data->func = gl4es_glGetTexEnvxv; \ + packed_data->args.a1 = (GLenum)target; \ + packed_data->args.a2 = (GLenum)pname; \ + packed_data->args.a3 = (GLfixed *)params; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glGetTexParameterfv +#define push_glGetTexParameterfv(target, pname, params) { \ + glGetTexParameterfv_PACKED *packed_data = malloc(sizeof(glGetTexParameterfv_PACKED)); \ + packed_data->format = glGetTexParameterfv_FORMAT; \ + packed_data->func = gl4es_glGetTexParameterfv; \ + packed_data->args.a1 = (GLenum)target; \ + packed_data->args.a2 = (GLenum)pname; \ + packed_data->args.a3 = (GLfloat *)params; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glGetTexParameteriv +#define push_glGetTexParameteriv(target, pname, params) { \ + glGetTexParameteriv_PACKED *packed_data = malloc(sizeof(glGetTexParameteriv_PACKED)); \ + packed_data->format = glGetTexParameteriv_FORMAT; \ + packed_data->func = gl4es_glGetTexParameteriv; \ + packed_data->args.a1 = (GLenum)target; \ + packed_data->args.a2 = (GLenum)pname; \ + packed_data->args.a3 = (GLint *)params; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glGetTexParameterxv +#define push_glGetTexParameterxv(target, pname, params) { \ + glGetTexParameterxv_PACKED *packed_data = malloc(sizeof(glGetTexParameterxv_PACKED)); \ + packed_data->format = glGetTexParameterxv_FORMAT; \ + packed_data->func = gl4es_glGetTexParameterxv; \ + packed_data->args.a1 = (GLenum)target; \ + packed_data->args.a2 = (GLenum)pname; \ + packed_data->args.a3 = (GLfixed *)params; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glGetUniformLocation +#define push_glGetUniformLocation(program, name) { \ + glGetUniformLocation_PACKED *packed_data = malloc(sizeof(glGetUniformLocation_PACKED)); \ + packed_data->format = glGetUniformLocation_FORMAT; \ + packed_data->func = gl4es_glGetUniformLocation; \ + packed_data->args.a1 = (GLuint)program; \ + packed_data->args.a2 = (GLchar *)name; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glGetUniformfv +#define push_glGetUniformfv(program, location, params) { \ + glGetUniformfv_PACKED *packed_data = malloc(sizeof(glGetUniformfv_PACKED)); \ + packed_data->format = glGetUniformfv_FORMAT; \ + packed_data->func = gl4es_glGetUniformfv; \ + packed_data->args.a1 = (GLuint)program; \ + packed_data->args.a2 = (GLint)location; \ + packed_data->args.a3 = (GLfloat *)params; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glGetUniformiv +#define push_glGetUniformiv(program, location, params) { \ + glGetUniformiv_PACKED *packed_data = malloc(sizeof(glGetUniformiv_PACKED)); \ + packed_data->format = glGetUniformiv_FORMAT; \ + packed_data->func = gl4es_glGetUniformiv; \ + packed_data->args.a1 = (GLuint)program; \ + packed_data->args.a2 = (GLint)location; \ + packed_data->args.a3 = (GLint *)params; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glGetVertexAttribPointerv +#define push_glGetVertexAttribPointerv(index, pname, pointer) { \ + glGetVertexAttribPointerv_PACKED *packed_data = malloc(sizeof(glGetVertexAttribPointerv_PACKED)); \ + packed_data->format = glGetVertexAttribPointerv_FORMAT; \ + packed_data->func = gl4es_glGetVertexAttribPointerv; \ + packed_data->args.a1 = (GLuint)index; \ + packed_data->args.a2 = (GLenum)pname; \ + packed_data->args.a3 = (GLvoid **)pointer; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glGetVertexAttribfv +#define push_glGetVertexAttribfv(index, pname, params) { \ + glGetVertexAttribfv_PACKED *packed_data = malloc(sizeof(glGetVertexAttribfv_PACKED)); \ + packed_data->format = glGetVertexAttribfv_FORMAT; \ + packed_data->func = gl4es_glGetVertexAttribfv; \ + packed_data->args.a1 = (GLuint)index; \ + packed_data->args.a2 = (GLenum)pname; \ + packed_data->args.a3 = (GLfloat *)params; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glGetVertexAttribiv +#define push_glGetVertexAttribiv(index, pname, params) { \ + glGetVertexAttribiv_PACKED *packed_data = malloc(sizeof(glGetVertexAttribiv_PACKED)); \ + packed_data->format = glGetVertexAttribiv_FORMAT; \ + packed_data->func = gl4es_glGetVertexAttribiv; \ + packed_data->args.a1 = (GLuint)index; \ + packed_data->args.a2 = (GLenum)pname; \ + packed_data->args.a3 = (GLint *)params; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glHint +#define push_glHint(target, mode) { \ + glHint_PACKED *packed_data = malloc(sizeof(glHint_PACKED)); \ + packed_data->format = glHint_FORMAT; \ + packed_data->func = gl4es_glHint; \ + packed_data->args.a1 = (GLenum)target; \ + packed_data->args.a2 = (GLenum)mode; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glIsBuffer +#define push_glIsBuffer(buffer) { \ + glIsBuffer_PACKED *packed_data = malloc(sizeof(glIsBuffer_PACKED)); \ + packed_data->format = glIsBuffer_FORMAT; \ + packed_data->func = gl4es_glIsBuffer; \ + packed_data->args.a1 = (GLuint)buffer; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glIsEnabled +#define push_glIsEnabled(cap) { \ + glIsEnabled_PACKED *packed_data = malloc(sizeof(glIsEnabled_PACKED)); \ + packed_data->format = glIsEnabled_FORMAT; \ + packed_data->func = gl4es_glIsEnabled; \ + packed_data->args.a1 = (GLenum)cap; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glIsFramebuffer +#define push_glIsFramebuffer(framebuffer) { \ + glIsFramebuffer_PACKED *packed_data = malloc(sizeof(glIsFramebuffer_PACKED)); \ + packed_data->format = glIsFramebuffer_FORMAT; \ + packed_data->func = gl4es_glIsFramebuffer; \ + packed_data->args.a1 = (GLuint)framebuffer; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glIsProgram +#define push_glIsProgram(program) { \ + glIsProgram_PACKED *packed_data = malloc(sizeof(glIsProgram_PACKED)); \ + packed_data->format = glIsProgram_FORMAT; \ + packed_data->func = gl4es_glIsProgram; \ + packed_data->args.a1 = (GLuint)program; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glIsRenderbuffer +#define push_glIsRenderbuffer(renderbuffer) { \ + glIsRenderbuffer_PACKED *packed_data = malloc(sizeof(glIsRenderbuffer_PACKED)); \ + packed_data->format = glIsRenderbuffer_FORMAT; \ + packed_data->func = gl4es_glIsRenderbuffer; \ + packed_data->args.a1 = (GLuint)renderbuffer; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glIsShader +#define push_glIsShader(shader) { \ + glIsShader_PACKED *packed_data = malloc(sizeof(glIsShader_PACKED)); \ + packed_data->format = glIsShader_FORMAT; \ + packed_data->func = gl4es_glIsShader; \ + packed_data->args.a1 = (GLuint)shader; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glIsTexture +#define push_glIsTexture(texture) { \ + glIsTexture_PACKED *packed_data = malloc(sizeof(glIsTexture_PACKED)); \ + packed_data->format = glIsTexture_FORMAT; \ + packed_data->func = gl4es_glIsTexture; \ + packed_data->args.a1 = (GLuint)texture; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glLightModelf +#define push_glLightModelf(pname, param) { \ + glLightModelf_PACKED *packed_data = malloc(sizeof(glLightModelf_PACKED)); \ + packed_data->format = glLightModelf_FORMAT; \ + packed_data->func = gl4es_glLightModelf; \ + packed_data->args.a1 = (GLenum)pname; \ + packed_data->args.a2 = (GLfloat)param; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glLightModelfv +#define push_glLightModelfv(pname, params) { \ + glLightModelfv_PACKED *packed_data = malloc(sizeof(glLightModelfv_PACKED)); \ + packed_data->format = glLightModelfv_FORMAT; \ + packed_data->func = gl4es_glLightModelfv; \ + packed_data->args.a1 = (GLenum)pname; \ + packed_data->args.a2 = (GLfloat *)params; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glLightModelx +#define push_glLightModelx(pname, param) { \ + glLightModelx_PACKED *packed_data = malloc(sizeof(glLightModelx_PACKED)); \ + packed_data->format = glLightModelx_FORMAT; \ + packed_data->func = gl4es_glLightModelx; \ + packed_data->args.a1 = (GLenum)pname; \ + packed_data->args.a2 = (GLfixed)param; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glLightModelxv +#define push_glLightModelxv(pname, params) { \ + glLightModelxv_PACKED *packed_data = malloc(sizeof(glLightModelxv_PACKED)); \ + packed_data->format = glLightModelxv_FORMAT; \ + packed_data->func = gl4es_glLightModelxv; \ + packed_data->args.a1 = (GLenum)pname; \ + packed_data->args.a2 = (GLfixed *)params; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glLightf +#define push_glLightf(light, pname, param) { \ + glLightf_PACKED *packed_data = malloc(sizeof(glLightf_PACKED)); \ + packed_data->format = glLightf_FORMAT; \ + packed_data->func = gl4es_glLightf; \ + packed_data->args.a1 = (GLenum)light; \ + packed_data->args.a2 = (GLenum)pname; \ + packed_data->args.a3 = (GLfloat)param; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glLightfv +#define push_glLightfv(light, pname, params) { \ + glLightfv_PACKED *packed_data = malloc(sizeof(glLightfv_PACKED)); \ + packed_data->format = glLightfv_FORMAT; \ + packed_data->func = gl4es_glLightfv; \ + packed_data->args.a1 = (GLenum)light; \ + packed_data->args.a2 = (GLenum)pname; \ + packed_data->args.a3 = (GLfloat *)params; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glLightx +#define push_glLightx(light, pname, param) { \ + glLightx_PACKED *packed_data = malloc(sizeof(glLightx_PACKED)); \ + packed_data->format = glLightx_FORMAT; \ + packed_data->func = gl4es_glLightx; \ + packed_data->args.a1 = (GLenum)light; \ + packed_data->args.a2 = (GLenum)pname; \ + packed_data->args.a3 = (GLfixed)param; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glLightxv +#define push_glLightxv(light, pname, params) { \ + glLightxv_PACKED *packed_data = malloc(sizeof(glLightxv_PACKED)); \ + packed_data->format = glLightxv_FORMAT; \ + packed_data->func = gl4es_glLightxv; \ + packed_data->args.a1 = (GLenum)light; \ + packed_data->args.a2 = (GLenum)pname; \ + packed_data->args.a3 = (GLfixed *)params; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glLineWidth +#define push_glLineWidth(width) { \ + glLineWidth_PACKED *packed_data = malloc(sizeof(glLineWidth_PACKED)); \ + packed_data->format = glLineWidth_FORMAT; \ + packed_data->func = gl4es_glLineWidth; \ + packed_data->args.a1 = (GLfloat)width; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glLineWidthx +#define push_glLineWidthx(width) { \ + glLineWidthx_PACKED *packed_data = malloc(sizeof(glLineWidthx_PACKED)); \ + packed_data->format = glLineWidthx_FORMAT; \ + packed_data->func = gl4es_glLineWidthx; \ + packed_data->args.a1 = (GLfixed)width; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glLinkProgram +#define push_glLinkProgram(program) { \ + glLinkProgram_PACKED *packed_data = malloc(sizeof(glLinkProgram_PACKED)); \ + packed_data->format = glLinkProgram_FORMAT; \ + packed_data->func = gl4es_glLinkProgram; \ + packed_data->args.a1 = (GLuint)program; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glLoadIdentity +#define push_glLoadIdentity() { \ + glLoadIdentity_PACKED *packed_data = malloc(sizeof(glLoadIdentity_PACKED)); \ + packed_data->format = glLoadIdentity_FORMAT; \ + packed_data->func = gl4es_glLoadIdentity; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glLoadMatrixf +#define push_glLoadMatrixf(m) { \ + glLoadMatrixf_PACKED *packed_data = malloc(sizeof(glLoadMatrixf_PACKED)); \ + packed_data->format = glLoadMatrixf_FORMAT; \ + packed_data->func = gl4es_glLoadMatrixf; \ + packed_data->args.a1 = (GLfloat *)m; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glLoadMatrixx +#define push_glLoadMatrixx(m) { \ + glLoadMatrixx_PACKED *packed_data = malloc(sizeof(glLoadMatrixx_PACKED)); \ + packed_data->format = glLoadMatrixx_FORMAT; \ + packed_data->func = gl4es_glLoadMatrixx; \ + packed_data->args.a1 = (GLfixed *)m; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glLogicOp +#define push_glLogicOp(opcode) { \ + glLogicOp_PACKED *packed_data = malloc(sizeof(glLogicOp_PACKED)); \ + packed_data->format = glLogicOp_FORMAT; \ + packed_data->func = gl4es_glLogicOp; \ + packed_data->args.a1 = (GLenum)opcode; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glMaterialf +#define push_glMaterialf(face, pname, param) { \ + glMaterialf_PACKED *packed_data = malloc(sizeof(glMaterialf_PACKED)); \ + packed_data->format = glMaterialf_FORMAT; \ + packed_data->func = gl4es_glMaterialf; \ + packed_data->args.a1 = (GLenum)face; \ + packed_data->args.a2 = (GLenum)pname; \ + packed_data->args.a3 = (GLfloat)param; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glMaterialfv +#define push_glMaterialfv(face, pname, params) { \ + glMaterialfv_PACKED *packed_data = malloc(sizeof(glMaterialfv_PACKED)); \ + packed_data->format = glMaterialfv_FORMAT; \ + packed_data->func = gl4es_glMaterialfv; \ + packed_data->args.a1 = (GLenum)face; \ + packed_data->args.a2 = (GLenum)pname; \ + packed_data->args.a3 = (GLfloat *)params; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glMaterialx +#define push_glMaterialx(face, pname, param) { \ + glMaterialx_PACKED *packed_data = malloc(sizeof(glMaterialx_PACKED)); \ + packed_data->format = glMaterialx_FORMAT; \ + packed_data->func = gl4es_glMaterialx; \ + packed_data->args.a1 = (GLenum)face; \ + packed_data->args.a2 = (GLenum)pname; \ + packed_data->args.a3 = (GLfixed)param; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glMaterialxv +#define push_glMaterialxv(face, pname, params) { \ + glMaterialxv_PACKED *packed_data = malloc(sizeof(glMaterialxv_PACKED)); \ + packed_data->format = glMaterialxv_FORMAT; \ + packed_data->func = gl4es_glMaterialxv; \ + packed_data->args.a1 = (GLenum)face; \ + packed_data->args.a2 = (GLenum)pname; \ + packed_data->args.a3 = (GLfixed *)params; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glMatrixMode +#define push_glMatrixMode(mode) { \ + glMatrixMode_PACKED *packed_data = malloc(sizeof(glMatrixMode_PACKED)); \ + packed_data->format = glMatrixMode_FORMAT; \ + packed_data->func = gl4es_glMatrixMode; \ + packed_data->args.a1 = (GLenum)mode; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glMultMatrixf +#define push_glMultMatrixf(m) { \ + glMultMatrixf_PACKED *packed_data = malloc(sizeof(glMultMatrixf_PACKED)); \ + packed_data->format = glMultMatrixf_FORMAT; \ + packed_data->func = gl4es_glMultMatrixf; \ + packed_data->args.a1 = (GLfloat *)m; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glMultMatrixx +#define push_glMultMatrixx(m) { \ + glMultMatrixx_PACKED *packed_data = malloc(sizeof(glMultMatrixx_PACKED)); \ + packed_data->format = glMultMatrixx_FORMAT; \ + packed_data->func = gl4es_glMultMatrixx; \ + packed_data->args.a1 = (GLfixed *)m; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glMultiDrawArrays +#define push_glMultiDrawArrays(mode, first, count, primcount) { \ + glMultiDrawArrays_PACKED *packed_data = malloc(sizeof(glMultiDrawArrays_PACKED)); \ + packed_data->format = glMultiDrawArrays_FORMAT; \ + packed_data->func = gl4es_glMultiDrawArrays; \ + packed_data->args.a1 = (GLenum)mode; \ + packed_data->args.a2 = (GLint *)first; \ + packed_data->args.a3 = (GLsizei *)count; \ + packed_data->args.a4 = (GLsizei)primcount; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glMultiDrawElements +#define push_glMultiDrawElements(mode, count, type, indices, primcount) { \ + glMultiDrawElements_PACKED *packed_data = malloc(sizeof(glMultiDrawElements_PACKED)); \ + packed_data->format = glMultiDrawElements_FORMAT; \ + packed_data->func = gl4es_glMultiDrawElements; \ + packed_data->args.a1 = (GLenum)mode; \ + packed_data->args.a2 = (GLsizei *)count; \ + packed_data->args.a3 = (GLenum)type; \ + packed_data->args.a4 = (void * *)indices; \ + packed_data->args.a5 = (GLsizei)primcount; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glMultiTexCoord4f +#define push_glMultiTexCoord4f(target, s, t, r, q) { \ + glMultiTexCoord4f_PACKED *packed_data = malloc(sizeof(glMultiTexCoord4f_PACKED)); \ + packed_data->format = glMultiTexCoord4f_FORMAT; \ + packed_data->func = gl4es_glMultiTexCoord4f; \ + packed_data->args.a1 = (GLenum)target; \ + packed_data->args.a2 = (GLfloat)s; \ + packed_data->args.a3 = (GLfloat)t; \ + packed_data->args.a4 = (GLfloat)r; \ + packed_data->args.a5 = (GLfloat)q; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glMultiTexCoord4x +#define push_glMultiTexCoord4x(target, s, t, r, q) { \ + glMultiTexCoord4x_PACKED *packed_data = malloc(sizeof(glMultiTexCoord4x_PACKED)); \ + packed_data->format = glMultiTexCoord4x_FORMAT; \ + packed_data->func = gl4es_glMultiTexCoord4x; \ + packed_data->args.a1 = (GLenum)target; \ + packed_data->args.a2 = (GLfixed)s; \ + packed_data->args.a3 = (GLfixed)t; \ + packed_data->args.a4 = (GLfixed)r; \ + packed_data->args.a5 = (GLfixed)q; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glNormal3f +#define push_glNormal3f(nx, ny, nz) { \ + glNormal3f_PACKED *packed_data = malloc(sizeof(glNormal3f_PACKED)); \ + packed_data->format = glNormal3f_FORMAT; \ + packed_data->func = gl4es_glNormal3f; \ + packed_data->args.a1 = (GLfloat)nx; \ + packed_data->args.a2 = (GLfloat)ny; \ + packed_data->args.a3 = (GLfloat)nz; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glNormal3x +#define push_glNormal3x(nx, ny, nz) { \ + glNormal3x_PACKED *packed_data = malloc(sizeof(glNormal3x_PACKED)); \ + packed_data->format = glNormal3x_FORMAT; \ + packed_data->func = gl4es_glNormal3x; \ + packed_data->args.a1 = (GLfixed)nx; \ + packed_data->args.a2 = (GLfixed)ny; \ + packed_data->args.a3 = (GLfixed)nz; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glNormalPointer +#define push_glNormalPointer(type, stride, pointer) { \ + glNormalPointer_PACKED *packed_data = malloc(sizeof(glNormalPointer_PACKED)); \ + packed_data->format = glNormalPointer_FORMAT; \ + packed_data->func = gl4es_glNormalPointer; \ + packed_data->args.a1 = (GLenum)type; \ + packed_data->args.a2 = (GLsizei)stride; \ + packed_data->args.a3 = (GLvoid *)pointer; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glOrthof +#define push_glOrthof(left, right, bottom, top, near, far) { \ + glOrthof_PACKED *packed_data = malloc(sizeof(glOrthof_PACKED)); \ + packed_data->format = glOrthof_FORMAT; \ + packed_data->func = gl4es_glOrthof; \ + packed_data->args.a1 = (GLfloat)left; \ + packed_data->args.a2 = (GLfloat)right; \ + packed_data->args.a3 = (GLfloat)bottom; \ + packed_data->args.a4 = (GLfloat)top; \ + packed_data->args.a5 = (GLfloat)near; \ + packed_data->args.a6 = (GLfloat)far; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glOrthox +#define push_glOrthox(left, right, bottom, top, near, far) { \ + glOrthox_PACKED *packed_data = malloc(sizeof(glOrthox_PACKED)); \ + packed_data->format = glOrthox_FORMAT; \ + packed_data->func = gl4es_glOrthox; \ + packed_data->args.a1 = (GLfixed)left; \ + packed_data->args.a2 = (GLfixed)right; \ + packed_data->args.a3 = (GLfixed)bottom; \ + packed_data->args.a4 = (GLfixed)top; \ + packed_data->args.a5 = (GLfixed)near; \ + packed_data->args.a6 = (GLfixed)far; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glPixelStorei +#define push_glPixelStorei(pname, param) { \ + glPixelStorei_PACKED *packed_data = malloc(sizeof(glPixelStorei_PACKED)); \ + packed_data->format = glPixelStorei_FORMAT; \ + packed_data->func = gl4es_glPixelStorei; \ + packed_data->args.a1 = (GLenum)pname; \ + packed_data->args.a2 = (GLint)param; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glPointParameterf +#define push_glPointParameterf(pname, param) { \ + glPointParameterf_PACKED *packed_data = malloc(sizeof(glPointParameterf_PACKED)); \ + packed_data->format = glPointParameterf_FORMAT; \ + packed_data->func = gl4es_glPointParameterf; \ + packed_data->args.a1 = (GLenum)pname; \ + packed_data->args.a2 = (GLfloat)param; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glPointParameterfv +#define push_glPointParameterfv(pname, params) { \ + glPointParameterfv_PACKED *packed_data = malloc(sizeof(glPointParameterfv_PACKED)); \ + packed_data->format = glPointParameterfv_FORMAT; \ + packed_data->func = gl4es_glPointParameterfv; \ + packed_data->args.a1 = (GLenum)pname; \ + packed_data->args.a2 = (GLfloat *)params; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glPointParameterx +#define push_glPointParameterx(pname, param) { \ + glPointParameterx_PACKED *packed_data = malloc(sizeof(glPointParameterx_PACKED)); \ + packed_data->format = glPointParameterx_FORMAT; \ + packed_data->func = gl4es_glPointParameterx; \ + packed_data->args.a1 = (GLenum)pname; \ + packed_data->args.a2 = (GLfixed)param; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glPointParameterxv +#define push_glPointParameterxv(pname, params) { \ + glPointParameterxv_PACKED *packed_data = malloc(sizeof(glPointParameterxv_PACKED)); \ + packed_data->format = glPointParameterxv_FORMAT; \ + packed_data->func = gl4es_glPointParameterxv; \ + packed_data->args.a1 = (GLenum)pname; \ + packed_data->args.a2 = (GLfixed *)params; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glPointSize +#define push_glPointSize(size) { \ + glPointSize_PACKED *packed_data = malloc(sizeof(glPointSize_PACKED)); \ + packed_data->format = glPointSize_FORMAT; \ + packed_data->func = gl4es_glPointSize; \ + packed_data->args.a1 = (GLfloat)size; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glPointSizePointerOES +#define push_glPointSizePointerOES(type, stride, pointer) { \ + glPointSizePointerOES_PACKED *packed_data = malloc(sizeof(glPointSizePointerOES_PACKED)); \ + packed_data->format = glPointSizePointerOES_FORMAT; \ + packed_data->func = gl4es_glPointSizePointerOES; \ + packed_data->args.a1 = (GLenum)type; \ + packed_data->args.a2 = (GLsizei)stride; \ + packed_data->args.a3 = (GLvoid *)pointer; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glPointSizex +#define push_glPointSizex(size) { \ + glPointSizex_PACKED *packed_data = malloc(sizeof(glPointSizex_PACKED)); \ + packed_data->format = glPointSizex_FORMAT; \ + packed_data->func = gl4es_glPointSizex; \ + packed_data->args.a1 = (GLfixed)size; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glPolygonOffset +#define push_glPolygonOffset(factor, units) { \ + glPolygonOffset_PACKED *packed_data = malloc(sizeof(glPolygonOffset_PACKED)); \ + packed_data->format = glPolygonOffset_FORMAT; \ + packed_data->func = gl4es_glPolygonOffset; \ + packed_data->args.a1 = (GLfloat)factor; \ + packed_data->args.a2 = (GLfloat)units; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glPolygonOffsetx +#define push_glPolygonOffsetx(factor, units) { \ + glPolygonOffsetx_PACKED *packed_data = malloc(sizeof(glPolygonOffsetx_PACKED)); \ + packed_data->format = glPolygonOffsetx_FORMAT; \ + packed_data->func = gl4es_glPolygonOffsetx; \ + packed_data->args.a1 = (GLfixed)factor; \ + packed_data->args.a2 = (GLfixed)units; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glPopMatrix +#define push_glPopMatrix() { \ + glPopMatrix_PACKED *packed_data = malloc(sizeof(glPopMatrix_PACKED)); \ + packed_data->format = glPopMatrix_FORMAT; \ + packed_data->func = gl4es_glPopMatrix; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glPushMatrix +#define push_glPushMatrix() { \ + glPushMatrix_PACKED *packed_data = malloc(sizeof(glPushMatrix_PACKED)); \ + packed_data->format = glPushMatrix_FORMAT; \ + packed_data->func = gl4es_glPushMatrix; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glReadPixels +#define push_glReadPixels(x, y, width, height, format, type, pixels) { \ + glReadPixels_PACKED *packed_data = malloc(sizeof(glReadPixels_PACKED)); \ + packed_data->format = glReadPixels_FORMAT; \ + packed_data->func = gl4es_glReadPixels; \ + packed_data->args.a1 = (GLint)x; \ + packed_data->args.a2 = (GLint)y; \ + packed_data->args.a3 = (GLsizei)width; \ + packed_data->args.a4 = (GLsizei)height; \ + packed_data->args.a5 = (GLenum)format; \ + packed_data->args.a6 = (GLenum)type; \ + packed_data->args.a7 = (GLvoid *)pixels; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glReleaseShaderCompiler +#define push_glReleaseShaderCompiler() { \ + glReleaseShaderCompiler_PACKED *packed_data = malloc(sizeof(glReleaseShaderCompiler_PACKED)); \ + packed_data->format = glReleaseShaderCompiler_FORMAT; \ + packed_data->func = gl4es_glReleaseShaderCompiler; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glRenderbufferStorage +#define push_glRenderbufferStorage(target, internalformat, width, height) { \ + glRenderbufferStorage_PACKED *packed_data = malloc(sizeof(glRenderbufferStorage_PACKED)); \ + packed_data->format = glRenderbufferStorage_FORMAT; \ + packed_data->func = gl4es_glRenderbufferStorage; \ + packed_data->args.a1 = (GLenum)target; \ + packed_data->args.a2 = (GLenum)internalformat; \ + packed_data->args.a3 = (GLsizei)width; \ + packed_data->args.a4 = (GLsizei)height; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glRotatef +#define push_glRotatef(angle, x, y, z) { \ + glRotatef_PACKED *packed_data = malloc(sizeof(glRotatef_PACKED)); \ + packed_data->format = glRotatef_FORMAT; \ + packed_data->func = gl4es_glRotatef; \ + packed_data->args.a1 = (GLfloat)angle; \ + packed_data->args.a2 = (GLfloat)x; \ + packed_data->args.a3 = (GLfloat)y; \ + packed_data->args.a4 = (GLfloat)z; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glRotatex +#define push_glRotatex(angle, x, y, z) { \ + glRotatex_PACKED *packed_data = malloc(sizeof(glRotatex_PACKED)); \ + packed_data->format = glRotatex_FORMAT; \ + packed_data->func = gl4es_glRotatex; \ + packed_data->args.a1 = (GLfixed)angle; \ + packed_data->args.a2 = (GLfixed)x; \ + packed_data->args.a3 = (GLfixed)y; \ + packed_data->args.a4 = (GLfixed)z; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glSampleCoverage +#define push_glSampleCoverage(value, invert) { \ + glSampleCoverage_PACKED *packed_data = malloc(sizeof(glSampleCoverage_PACKED)); \ + packed_data->format = glSampleCoverage_FORMAT; \ + packed_data->func = gl4es_glSampleCoverage; \ + packed_data->args.a1 = (GLclampf)value; \ + packed_data->args.a2 = (GLboolean)invert; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glSampleCoveragex +#define push_glSampleCoveragex(value, invert) { \ + glSampleCoveragex_PACKED *packed_data = malloc(sizeof(glSampleCoveragex_PACKED)); \ + packed_data->format = glSampleCoveragex_FORMAT; \ + packed_data->func = gl4es_glSampleCoveragex; \ + packed_data->args.a1 = (GLclampx)value; \ + packed_data->args.a2 = (GLboolean)invert; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glScalef +#define push_glScalef(x, y, z) { \ + glScalef_PACKED *packed_data = malloc(sizeof(glScalef_PACKED)); \ + packed_data->format = glScalef_FORMAT; \ + packed_data->func = gl4es_glScalef; \ + packed_data->args.a1 = (GLfloat)x; \ + packed_data->args.a2 = (GLfloat)y; \ + packed_data->args.a3 = (GLfloat)z; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glScalex +#define push_glScalex(x, y, z) { \ + glScalex_PACKED *packed_data = malloc(sizeof(glScalex_PACKED)); \ + packed_data->format = glScalex_FORMAT; \ + packed_data->func = gl4es_glScalex; \ + packed_data->args.a1 = (GLfixed)x; \ + packed_data->args.a2 = (GLfixed)y; \ + packed_data->args.a3 = (GLfixed)z; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glScissor +#define push_glScissor(x, y, width, height) { \ + glScissor_PACKED *packed_data = malloc(sizeof(glScissor_PACKED)); \ + packed_data->format = glScissor_FORMAT; \ + packed_data->func = gl4es_glScissor; \ + packed_data->args.a1 = (GLint)x; \ + packed_data->args.a2 = (GLint)y; \ + packed_data->args.a3 = (GLsizei)width; \ + packed_data->args.a4 = (GLsizei)height; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glShadeModel +#define push_glShadeModel(mode) { \ + glShadeModel_PACKED *packed_data = malloc(sizeof(glShadeModel_PACKED)); \ + packed_data->format = glShadeModel_FORMAT; \ + packed_data->func = gl4es_glShadeModel; \ + packed_data->args.a1 = (GLenum)mode; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glShaderBinary +#define push_glShaderBinary(n, shaders, binaryformat, binary, length) { \ + glShaderBinary_PACKED *packed_data = malloc(sizeof(glShaderBinary_PACKED)); \ + packed_data->format = glShaderBinary_FORMAT; \ + packed_data->func = gl4es_glShaderBinary; \ + packed_data->args.a1 = (GLsizei)n; \ + packed_data->args.a2 = (GLuint *)shaders; \ + packed_data->args.a3 = (GLenum)binaryformat; \ + packed_data->args.a4 = (GLvoid *)binary; \ + packed_data->args.a5 = (GLsizei)length; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glShaderSource +#define push_glShaderSource(shader, count, string, length) { \ + glShaderSource_PACKED *packed_data = malloc(sizeof(glShaderSource_PACKED)); \ + packed_data->format = glShaderSource_FORMAT; \ + packed_data->func = gl4es_glShaderSource; \ + packed_data->args.a1 = (GLuint)shader; \ + packed_data->args.a2 = (GLsizei)count; \ + packed_data->args.a3 = (GLchar * *)string; \ + packed_data->args.a4 = (GLint *)length; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glStencilFunc +#define push_glStencilFunc(func, ref, mask) { \ + glStencilFunc_PACKED *packed_data = malloc(sizeof(glStencilFunc_PACKED)); \ + packed_data->format = glStencilFunc_FORMAT; \ + packed_data->func = gl4es_glStencilFunc; \ + packed_data->args.a1 = (GLenum)func; \ + packed_data->args.a2 = (GLint)ref; \ + packed_data->args.a3 = (GLuint)mask; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glStencilFuncSeparate +#define push_glStencilFuncSeparate(face, func, ref, mask) { \ + glStencilFuncSeparate_PACKED *packed_data = malloc(sizeof(glStencilFuncSeparate_PACKED)); \ + packed_data->format = glStencilFuncSeparate_FORMAT; \ + packed_data->func = gl4es_glStencilFuncSeparate; \ + packed_data->args.a1 = (GLenum)face; \ + packed_data->args.a2 = (GLenum)func; \ + packed_data->args.a3 = (GLint)ref; \ + packed_data->args.a4 = (GLuint)mask; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glStencilMask +#define push_glStencilMask(mask) { \ + glStencilMask_PACKED *packed_data = malloc(sizeof(glStencilMask_PACKED)); \ + packed_data->format = glStencilMask_FORMAT; \ + packed_data->func = gl4es_glStencilMask; \ + packed_data->args.a1 = (GLuint)mask; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glStencilMaskSeparate +#define push_glStencilMaskSeparate(face, mask) { \ + glStencilMaskSeparate_PACKED *packed_data = malloc(sizeof(glStencilMaskSeparate_PACKED)); \ + packed_data->format = glStencilMaskSeparate_FORMAT; \ + packed_data->func = gl4es_glStencilMaskSeparate; \ + packed_data->args.a1 = (GLenum)face; \ + packed_data->args.a2 = (GLuint)mask; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glStencilOp +#define push_glStencilOp(fail, zfail, zpass) { \ + glStencilOp_PACKED *packed_data = malloc(sizeof(glStencilOp_PACKED)); \ + packed_data->format = glStencilOp_FORMAT; \ + packed_data->func = gl4es_glStencilOp; \ + packed_data->args.a1 = (GLenum)fail; \ + packed_data->args.a2 = (GLenum)zfail; \ + packed_data->args.a3 = (GLenum)zpass; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glStencilOpSeparate +#define push_glStencilOpSeparate(face, sfail, zfail, zpass) { \ + glStencilOpSeparate_PACKED *packed_data = malloc(sizeof(glStencilOpSeparate_PACKED)); \ + packed_data->format = glStencilOpSeparate_FORMAT; \ + packed_data->func = gl4es_glStencilOpSeparate; \ + packed_data->args.a1 = (GLenum)face; \ + packed_data->args.a2 = (GLenum)sfail; \ + packed_data->args.a3 = (GLenum)zfail; \ + packed_data->args.a4 = (GLenum)zpass; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glTexCoordPointer +#define push_glTexCoordPointer(size, type, stride, pointer) { \ + glTexCoordPointer_PACKED *packed_data = malloc(sizeof(glTexCoordPointer_PACKED)); \ + packed_data->format = glTexCoordPointer_FORMAT; \ + packed_data->func = gl4es_glTexCoordPointer; \ + packed_data->args.a1 = (GLint)size; \ + packed_data->args.a2 = (GLenum)type; \ + packed_data->args.a3 = (GLsizei)stride; \ + packed_data->args.a4 = (GLvoid *)pointer; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glTexEnvf +#define push_glTexEnvf(target, pname, param) { \ + glTexEnvf_PACKED *packed_data = malloc(sizeof(glTexEnvf_PACKED)); \ + packed_data->format = glTexEnvf_FORMAT; \ + packed_data->func = gl4es_glTexEnvf; \ + packed_data->args.a1 = (GLenum)target; \ + packed_data->args.a2 = (GLenum)pname; \ + packed_data->args.a3 = (GLfloat)param; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glTexEnvfv +#define push_glTexEnvfv(target, pname, params) { \ + glTexEnvfv_PACKED *packed_data = malloc(sizeof(glTexEnvfv_PACKED)); \ + packed_data->format = glTexEnvfv_FORMAT; \ + packed_data->func = gl4es_glTexEnvfv; \ + packed_data->args.a1 = (GLenum)target; \ + packed_data->args.a2 = (GLenum)pname; \ + packed_data->args.a3 = (GLfloat *)params; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glTexEnvi +#define push_glTexEnvi(target, pname, param) { \ + glTexEnvi_PACKED *packed_data = malloc(sizeof(glTexEnvi_PACKED)); \ + packed_data->format = glTexEnvi_FORMAT; \ + packed_data->func = gl4es_glTexEnvi; \ + packed_data->args.a1 = (GLenum)target; \ + packed_data->args.a2 = (GLenum)pname; \ + packed_data->args.a3 = (GLint)param; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glTexEnviv +#define push_glTexEnviv(target, pname, params) { \ + glTexEnviv_PACKED *packed_data = malloc(sizeof(glTexEnviv_PACKED)); \ + packed_data->format = glTexEnviv_FORMAT; \ + packed_data->func = gl4es_glTexEnviv; \ + packed_data->args.a1 = (GLenum)target; \ + packed_data->args.a2 = (GLenum)pname; \ + packed_data->args.a3 = (GLint *)params; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glTexEnvx +#define push_glTexEnvx(target, pname, param) { \ + glTexEnvx_PACKED *packed_data = malloc(sizeof(glTexEnvx_PACKED)); \ + packed_data->format = glTexEnvx_FORMAT; \ + packed_data->func = gl4es_glTexEnvx; \ + packed_data->args.a1 = (GLenum)target; \ + packed_data->args.a2 = (GLenum)pname; \ + packed_data->args.a3 = (GLfixed)param; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glTexEnvxv +#define push_glTexEnvxv(target, pname, params) { \ + glTexEnvxv_PACKED *packed_data = malloc(sizeof(glTexEnvxv_PACKED)); \ + packed_data->format = glTexEnvxv_FORMAT; \ + packed_data->func = gl4es_glTexEnvxv; \ + packed_data->args.a1 = (GLenum)target; \ + packed_data->args.a2 = (GLenum)pname; \ + packed_data->args.a3 = (GLfixed *)params; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glTexGenfv +#define push_glTexGenfv(coord, pname, params) { \ + glTexGenfv_PACKED *packed_data = malloc(sizeof(glTexGenfv_PACKED)); \ + packed_data->format = glTexGenfv_FORMAT; \ + packed_data->func = gl4es_glTexGenfv; \ + packed_data->args.a1 = (GLenum)coord; \ + packed_data->args.a2 = (GLenum)pname; \ + packed_data->args.a3 = (GLfloat *)params; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glTexGeni +#define push_glTexGeni(coord, pname, param) { \ + glTexGeni_PACKED *packed_data = malloc(sizeof(glTexGeni_PACKED)); \ + packed_data->format = glTexGeni_FORMAT; \ + packed_data->func = gl4es_glTexGeni; \ + packed_data->args.a1 = (GLenum)coord; \ + packed_data->args.a2 = (GLenum)pname; \ + packed_data->args.a3 = (GLint)param; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glTexImage2D +#define push_glTexImage2D(target, level, internalformat, width, height, border, format, type, data) { \ + glTexImage2D_PACKED *packed_data = malloc(sizeof(glTexImage2D_PACKED)); \ + packed_data->format = glTexImage2D_FORMAT; \ + packed_data->func = gl4es_glTexImage2D; \ + packed_data->args.a1 = (GLenum)target; \ + packed_data->args.a2 = (GLint)level; \ + packed_data->args.a3 = (GLint)internalformat; \ + packed_data->args.a4 = (GLsizei)width; \ + packed_data->args.a5 = (GLsizei)height; \ + packed_data->args.a6 = (GLint)border; \ + packed_data->args.a7 = (GLenum)format; \ + packed_data->args.a8 = (GLenum)type; \ + packed_data->args.a9 = (GLvoid *)data; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glTexParameterf +#define push_glTexParameterf(target, pname, param) { \ + glTexParameterf_PACKED *packed_data = malloc(sizeof(glTexParameterf_PACKED)); \ + packed_data->format = glTexParameterf_FORMAT; \ + packed_data->func = gl4es_glTexParameterf; \ + packed_data->args.a1 = (GLenum)target; \ + packed_data->args.a2 = (GLenum)pname; \ + packed_data->args.a3 = (GLfloat)param; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glTexParameterfv +#define push_glTexParameterfv(target, pname, params) { \ + glTexParameterfv_PACKED *packed_data = malloc(sizeof(glTexParameterfv_PACKED)); \ + packed_data->format = glTexParameterfv_FORMAT; \ + packed_data->func = gl4es_glTexParameterfv; \ + packed_data->args.a1 = (GLenum)target; \ + packed_data->args.a2 = (GLenum)pname; \ + packed_data->args.a3 = (GLfloat *)params; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glTexParameteri +#define push_glTexParameteri(target, pname, param) { \ + glTexParameteri_PACKED *packed_data = malloc(sizeof(glTexParameteri_PACKED)); \ + packed_data->format = glTexParameteri_FORMAT; \ + packed_data->func = gl4es_glTexParameteri; \ + packed_data->args.a1 = (GLenum)target; \ + packed_data->args.a2 = (GLenum)pname; \ + packed_data->args.a3 = (GLint)param; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glTexParameteriv +#define push_glTexParameteriv(target, pname, params) { \ + glTexParameteriv_PACKED *packed_data = malloc(sizeof(glTexParameteriv_PACKED)); \ + packed_data->format = glTexParameteriv_FORMAT; \ + packed_data->func = gl4es_glTexParameteriv; \ + packed_data->args.a1 = (GLenum)target; \ + packed_data->args.a2 = (GLenum)pname; \ + packed_data->args.a3 = (GLint *)params; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glTexParameterx +#define push_glTexParameterx(target, pname, param) { \ + glTexParameterx_PACKED *packed_data = malloc(sizeof(glTexParameterx_PACKED)); \ + packed_data->format = glTexParameterx_FORMAT; \ + packed_data->func = gl4es_glTexParameterx; \ + packed_data->args.a1 = (GLenum)target; \ + packed_data->args.a2 = (GLenum)pname; \ + packed_data->args.a3 = (GLfixed)param; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glTexParameterxv +#define push_glTexParameterxv(target, pname, params) { \ + glTexParameterxv_PACKED *packed_data = malloc(sizeof(glTexParameterxv_PACKED)); \ + packed_data->format = glTexParameterxv_FORMAT; \ + packed_data->func = gl4es_glTexParameterxv; \ + packed_data->args.a1 = (GLenum)target; \ + packed_data->args.a2 = (GLenum)pname; \ + packed_data->args.a3 = (GLfixed *)params; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glTexSubImage2D +#define push_glTexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, data) { \ + glTexSubImage2D_PACKED *packed_data = malloc(sizeof(glTexSubImage2D_PACKED)); \ + packed_data->format = glTexSubImage2D_FORMAT; \ + packed_data->func = gl4es_glTexSubImage2D; \ + packed_data->args.a1 = (GLenum)target; \ + packed_data->args.a2 = (GLint)level; \ + packed_data->args.a3 = (GLint)xoffset; \ + packed_data->args.a4 = (GLint)yoffset; \ + packed_data->args.a5 = (GLsizei)width; \ + packed_data->args.a6 = (GLsizei)height; \ + packed_data->args.a7 = (GLenum)format; \ + packed_data->args.a8 = (GLenum)type; \ + packed_data->args.a9 = (GLvoid *)data; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glTranslatef +#define push_glTranslatef(x, y, z) { \ + glTranslatef_PACKED *packed_data = malloc(sizeof(glTranslatef_PACKED)); \ + packed_data->format = glTranslatef_FORMAT; \ + packed_data->func = gl4es_glTranslatef; \ + packed_data->args.a1 = (GLfloat)x; \ + packed_data->args.a2 = (GLfloat)y; \ + packed_data->args.a3 = (GLfloat)z; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glTranslatex +#define push_glTranslatex(x, y, z) { \ + glTranslatex_PACKED *packed_data = malloc(sizeof(glTranslatex_PACKED)); \ + packed_data->format = glTranslatex_FORMAT; \ + packed_data->func = gl4es_glTranslatex; \ + packed_data->args.a1 = (GLfixed)x; \ + packed_data->args.a2 = (GLfixed)y; \ + packed_data->args.a3 = (GLfixed)z; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glUniform1f +#define push_glUniform1f(location, v0) { \ + glUniform1f_PACKED *packed_data = malloc(sizeof(glUniform1f_PACKED)); \ + packed_data->format = glUniform1f_FORMAT; \ + packed_data->func = gl4es_glUniform1f; \ + packed_data->args.a1 = (GLint)location; \ + packed_data->args.a2 = (GLfloat)v0; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glUniform1fv +#define push_glUniform1fv(location, count, value) { \ + glUniform1fv_PACKED *packed_data = malloc(sizeof(glUniform1fv_PACKED)); \ + packed_data->format = glUniform1fv_FORMAT; \ + packed_data->func = gl4es_glUniform1fv; \ + packed_data->args.a1 = (GLint)location; \ + packed_data->args.a2 = (GLsizei)count; \ + packed_data->args.a3 = (GLfloat *)value; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glUniform1i +#define push_glUniform1i(location, v0) { \ + glUniform1i_PACKED *packed_data = malloc(sizeof(glUniform1i_PACKED)); \ + packed_data->format = glUniform1i_FORMAT; \ + packed_data->func = gl4es_glUniform1i; \ + packed_data->args.a1 = (GLint)location; \ + packed_data->args.a2 = (GLint)v0; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glUniform1iv +#define push_glUniform1iv(location, count, value) { \ + glUniform1iv_PACKED *packed_data = malloc(sizeof(glUniform1iv_PACKED)); \ + packed_data->format = glUniform1iv_FORMAT; \ + packed_data->func = gl4es_glUniform1iv; \ + packed_data->args.a1 = (GLint)location; \ + packed_data->args.a2 = (GLsizei)count; \ + packed_data->args.a3 = (GLint *)value; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glUniform2f +#define push_glUniform2f(location, v0, v1) { \ + glUniform2f_PACKED *packed_data = malloc(sizeof(glUniform2f_PACKED)); \ + packed_data->format = glUniform2f_FORMAT; \ + packed_data->func = gl4es_glUniform2f; \ + packed_data->args.a1 = (GLint)location; \ + packed_data->args.a2 = (GLfloat)v0; \ + packed_data->args.a3 = (GLfloat)v1; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glUniform2fv +#define push_glUniform2fv(location, count, value) { \ + glUniform2fv_PACKED *packed_data = malloc(sizeof(glUniform2fv_PACKED)); \ + packed_data->format = glUniform2fv_FORMAT; \ + packed_data->func = gl4es_glUniform2fv; \ + packed_data->args.a1 = (GLint)location; \ + packed_data->args.a2 = (GLsizei)count; \ + packed_data->args.a3 = (GLfloat *)value; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glUniform2i +#define push_glUniform2i(location, v0, v1) { \ + glUniform2i_PACKED *packed_data = malloc(sizeof(glUniform2i_PACKED)); \ + packed_data->format = glUniform2i_FORMAT; \ + packed_data->func = gl4es_glUniform2i; \ + packed_data->args.a1 = (GLint)location; \ + packed_data->args.a2 = (GLint)v0; \ + packed_data->args.a3 = (GLint)v1; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glUniform2iv +#define push_glUniform2iv(location, count, value) { \ + glUniform2iv_PACKED *packed_data = malloc(sizeof(glUniform2iv_PACKED)); \ + packed_data->format = glUniform2iv_FORMAT; \ + packed_data->func = gl4es_glUniform2iv; \ + packed_data->args.a1 = (GLint)location; \ + packed_data->args.a2 = (GLsizei)count; \ + packed_data->args.a3 = (GLint *)value; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glUniform3f +#define push_glUniform3f(location, v0, v1, v2) { \ + glUniform3f_PACKED *packed_data = malloc(sizeof(glUniform3f_PACKED)); \ + packed_data->format = glUniform3f_FORMAT; \ + packed_data->func = gl4es_glUniform3f; \ + packed_data->args.a1 = (GLint)location; \ + packed_data->args.a2 = (GLfloat)v0; \ + packed_data->args.a3 = (GLfloat)v1; \ + packed_data->args.a4 = (GLfloat)v2; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glUniform3fv +#define push_glUniform3fv(location, count, value) { \ + glUniform3fv_PACKED *packed_data = malloc(sizeof(glUniform3fv_PACKED)); \ + packed_data->format = glUniform3fv_FORMAT; \ + packed_data->func = gl4es_glUniform3fv; \ + packed_data->args.a1 = (GLint)location; \ + packed_data->args.a2 = (GLsizei)count; \ + packed_data->args.a3 = (GLfloat *)value; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glUniform3i +#define push_glUniform3i(location, v0, v1, v2) { \ + glUniform3i_PACKED *packed_data = malloc(sizeof(glUniform3i_PACKED)); \ + packed_data->format = glUniform3i_FORMAT; \ + packed_data->func = gl4es_glUniform3i; \ + packed_data->args.a1 = (GLint)location; \ + packed_data->args.a2 = (GLint)v0; \ + packed_data->args.a3 = (GLint)v1; \ + packed_data->args.a4 = (GLint)v2; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glUniform3iv +#define push_glUniform3iv(location, count, value) { \ + glUniform3iv_PACKED *packed_data = malloc(sizeof(glUniform3iv_PACKED)); \ + packed_data->format = glUniform3iv_FORMAT; \ + packed_data->func = gl4es_glUniform3iv; \ + packed_data->args.a1 = (GLint)location; \ + packed_data->args.a2 = (GLsizei)count; \ + packed_data->args.a3 = (GLint *)value; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glUniform4f +#define push_glUniform4f(location, v0, v1, v2, v3) { \ + glUniform4f_PACKED *packed_data = malloc(sizeof(glUniform4f_PACKED)); \ + packed_data->format = glUniform4f_FORMAT; \ + packed_data->func = gl4es_glUniform4f; \ + packed_data->args.a1 = (GLint)location; \ + packed_data->args.a2 = (GLfloat)v0; \ + packed_data->args.a3 = (GLfloat)v1; \ + packed_data->args.a4 = (GLfloat)v2; \ + packed_data->args.a5 = (GLfloat)v3; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glUniform4fv +#define push_glUniform4fv(location, count, value) { \ + glUniform4fv_PACKED *packed_data = malloc(sizeof(glUniform4fv_PACKED)); \ + packed_data->format = glUniform4fv_FORMAT; \ + packed_data->func = gl4es_glUniform4fv; \ + packed_data->args.a1 = (GLint)location; \ + packed_data->args.a2 = (GLsizei)count; \ + packed_data->args.a3 = (GLfloat *)value; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glUniform4i +#define push_glUniform4i(location, v0, v1, v2, v3) { \ + glUniform4i_PACKED *packed_data = malloc(sizeof(glUniform4i_PACKED)); \ + packed_data->format = glUniform4i_FORMAT; \ + packed_data->func = gl4es_glUniform4i; \ + packed_data->args.a1 = (GLint)location; \ + packed_data->args.a2 = (GLint)v0; \ + packed_data->args.a3 = (GLint)v1; \ + packed_data->args.a4 = (GLint)v2; \ + packed_data->args.a5 = (GLint)v3; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glUniform4iv +#define push_glUniform4iv(location, count, value) { \ + glUniform4iv_PACKED *packed_data = malloc(sizeof(glUniform4iv_PACKED)); \ + packed_data->format = glUniform4iv_FORMAT; \ + packed_data->func = gl4es_glUniform4iv; \ + packed_data->args.a1 = (GLint)location; \ + packed_data->args.a2 = (GLsizei)count; \ + packed_data->args.a3 = (GLint *)value; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glUniformMatrix2fv +#define push_glUniformMatrix2fv(location, count, transpose, value) { \ + glUniformMatrix2fv_PACKED *packed_data = malloc(sizeof(glUniformMatrix2fv_PACKED)); \ + packed_data->format = glUniformMatrix2fv_FORMAT; \ + packed_data->func = gl4es_glUniformMatrix2fv; \ + packed_data->args.a1 = (GLint)location; \ + packed_data->args.a2 = (GLsizei)count; \ + packed_data->args.a3 = (GLboolean)transpose; \ + packed_data->args.a4 = (GLfloat *)value; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glUniformMatrix3fv +#define push_glUniformMatrix3fv(location, count, transpose, value) { \ + glUniformMatrix3fv_PACKED *packed_data = malloc(sizeof(glUniformMatrix3fv_PACKED)); \ + packed_data->format = glUniformMatrix3fv_FORMAT; \ + packed_data->func = gl4es_glUniformMatrix3fv; \ + packed_data->args.a1 = (GLint)location; \ + packed_data->args.a2 = (GLsizei)count; \ + packed_data->args.a3 = (GLboolean)transpose; \ + packed_data->args.a4 = (GLfloat *)value; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glUniformMatrix4fv +#define push_glUniformMatrix4fv(location, count, transpose, value) { \ + glUniformMatrix4fv_PACKED *packed_data = malloc(sizeof(glUniformMatrix4fv_PACKED)); \ + packed_data->format = glUniformMatrix4fv_FORMAT; \ + packed_data->func = gl4es_glUniformMatrix4fv; \ + packed_data->args.a1 = (GLint)location; \ + packed_data->args.a2 = (GLsizei)count; \ + packed_data->args.a3 = (GLboolean)transpose; \ + packed_data->args.a4 = (GLfloat *)value; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glUseProgram +#define push_glUseProgram(program) { \ + glUseProgram_PACKED *packed_data = malloc(sizeof(glUseProgram_PACKED)); \ + packed_data->format = glUseProgram_FORMAT; \ + packed_data->func = gl4es_glUseProgram; \ + packed_data->args.a1 = (GLuint)program; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glValidateProgram +#define push_glValidateProgram(program) { \ + glValidateProgram_PACKED *packed_data = malloc(sizeof(glValidateProgram_PACKED)); \ + packed_data->format = glValidateProgram_FORMAT; \ + packed_data->func = gl4es_glValidateProgram; \ + packed_data->args.a1 = (GLuint)program; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glVertexAttrib1f +#define push_glVertexAttrib1f(index, x) { \ + glVertexAttrib1f_PACKED *packed_data = malloc(sizeof(glVertexAttrib1f_PACKED)); \ + packed_data->format = glVertexAttrib1f_FORMAT; \ + packed_data->func = gl4es_glVertexAttrib1f; \ + packed_data->args.a1 = (GLuint)index; \ + packed_data->args.a2 = (GLfloat)x; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glVertexAttrib1fv +#define push_glVertexAttrib1fv(index, v) { \ + glVertexAttrib1fv_PACKED *packed_data = malloc(sizeof(glVertexAttrib1fv_PACKED)); \ + packed_data->format = glVertexAttrib1fv_FORMAT; \ + packed_data->func = gl4es_glVertexAttrib1fv; \ + packed_data->args.a1 = (GLuint)index; \ + packed_data->args.a2 = (GLfloat *)v; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glVertexAttrib2f +#define push_glVertexAttrib2f(index, x, y) { \ + glVertexAttrib2f_PACKED *packed_data = malloc(sizeof(glVertexAttrib2f_PACKED)); \ + packed_data->format = glVertexAttrib2f_FORMAT; \ + packed_data->func = gl4es_glVertexAttrib2f; \ + packed_data->args.a1 = (GLuint)index; \ + packed_data->args.a2 = (GLfloat)x; \ + packed_data->args.a3 = (GLfloat)y; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glVertexAttrib2fv +#define push_glVertexAttrib2fv(index, v) { \ + glVertexAttrib2fv_PACKED *packed_data = malloc(sizeof(glVertexAttrib2fv_PACKED)); \ + packed_data->format = glVertexAttrib2fv_FORMAT; \ + packed_data->func = gl4es_glVertexAttrib2fv; \ + packed_data->args.a1 = (GLuint)index; \ + packed_data->args.a2 = (GLfloat *)v; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glVertexAttrib3f +#define push_glVertexAttrib3f(index, x, y, z) { \ + glVertexAttrib3f_PACKED *packed_data = malloc(sizeof(glVertexAttrib3f_PACKED)); \ + packed_data->format = glVertexAttrib3f_FORMAT; \ + packed_data->func = gl4es_glVertexAttrib3f; \ + packed_data->args.a1 = (GLuint)index; \ + packed_data->args.a2 = (GLfloat)x; \ + packed_data->args.a3 = (GLfloat)y; \ + packed_data->args.a4 = (GLfloat)z; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glVertexAttrib3fv +#define push_glVertexAttrib3fv(index, v) { \ + glVertexAttrib3fv_PACKED *packed_data = malloc(sizeof(glVertexAttrib3fv_PACKED)); \ + packed_data->format = glVertexAttrib3fv_FORMAT; \ + packed_data->func = gl4es_glVertexAttrib3fv; \ + packed_data->args.a1 = (GLuint)index; \ + packed_data->args.a2 = (GLfloat *)v; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glVertexAttrib4f +#define push_glVertexAttrib4f(index, x, y, z, w) { \ + glVertexAttrib4f_PACKED *packed_data = malloc(sizeof(glVertexAttrib4f_PACKED)); \ + packed_data->format = glVertexAttrib4f_FORMAT; \ + packed_data->func = gl4es_glVertexAttrib4f; \ + packed_data->args.a1 = (GLuint)index; \ + packed_data->args.a2 = (GLfloat)x; \ + packed_data->args.a3 = (GLfloat)y; \ + packed_data->args.a4 = (GLfloat)z; \ + packed_data->args.a5 = (GLfloat)w; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glVertexAttrib4fv +#define push_glVertexAttrib4fv(index, v) { \ + glVertexAttrib4fv_PACKED *packed_data = malloc(sizeof(glVertexAttrib4fv_PACKED)); \ + packed_data->format = glVertexAttrib4fv_FORMAT; \ + packed_data->func = gl4es_glVertexAttrib4fv; \ + packed_data->args.a1 = (GLuint)index; \ + packed_data->args.a2 = (GLfloat *)v; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glVertexAttribPointer +#define push_glVertexAttribPointer(index, size, type, normalized, stride, pointer) { \ + glVertexAttribPointer_PACKED *packed_data = malloc(sizeof(glVertexAttribPointer_PACKED)); \ + packed_data->format = glVertexAttribPointer_FORMAT; \ + packed_data->func = gl4es_glVertexAttribPointer; \ + packed_data->args.a1 = (GLuint)index; \ + packed_data->args.a2 = (GLint)size; \ + packed_data->args.a3 = (GLenum)type; \ + packed_data->args.a4 = (GLboolean)normalized; \ + packed_data->args.a5 = (GLsizei)stride; \ + packed_data->args.a6 = (GLvoid *)pointer; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glVertexPointer +#define push_glVertexPointer(size, type, stride, pointer) { \ + glVertexPointer_PACKED *packed_data = malloc(sizeof(glVertexPointer_PACKED)); \ + packed_data->format = glVertexPointer_FORMAT; \ + packed_data->func = gl4es_glVertexPointer; \ + packed_data->args.a1 = (GLint)size; \ + packed_data->args.a2 = (GLenum)type; \ + packed_data->args.a3 = (GLsizei)stride; \ + packed_data->args.a4 = (GLvoid *)pointer; \ + glPushCall((void *)packed_data); \ +} +#endif +#ifndef direct_glViewport +#define push_glViewport(x, y, width, height) { \ + glViewport_PACKED *packed_data = malloc(sizeof(glViewport_PACKED)); \ + packed_data->format = glViewport_FORMAT; \ + packed_data->func = gl4es_glViewport; \ + packed_data->args.a1 = (GLint)x; \ + packed_data->args.a2 = (GLint)y; \ + packed_data->args.a3 = (GLsizei)width; \ + packed_data->args.a4 = (GLsizei)height; \ + glPushCall((void *)packed_data); \ +} +#endif +#endif diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/wrap/glstub.c b/Projects/Android/jni/SupportLibs/gl4es/src/gl/wrap/glstub.c new file mode 100644 index 0000000..4e21cea --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/wrap/glstub.c @@ -0,0 +1,53 @@ +#include "stub.h" + +#include +#include +#include + +#define STUB(ret, def, args)\ +ret gl4es_ ## def args {\ + char *debug = getenv("LIBGL_DEBUG");\ + if (debug && strcmp(debug, "1") == 0)\ + printf("stub: %s;\n", #def);\ +} \ +ret def args __attribute((alias("gl4es_"#def))) __attribute__((visibility("default"))); + +/*STUB(void,glFogCoordd,(GLdouble coord)); +STUB(void,glFogCoordf,(GLfloat coord)); +STUB(void,glFogCoorddv,(const GLdouble *coord)); +STUB(void,glFogCoordfv,(const GLfloat *coord));*/ +#ifdef BCMHOST +STUB(void,glDiscardFramebufferEXT,(GLenum target, GLsizei numAttachments, const GLenum *attachments)); +#endif + +/* +STUB(void glBlendEquationSeparatei(GLuint buf, GLenum modeRGB, GLenum modeAlpha)) +STUB(void glBlendFuncSeparatei(GLuint buf, GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)) +*/ +STUB(void,glClearAccum,(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)); +//STUB(void,glColorMaterial,(GLenum face, GLenum mode)); +STUB(void,glCopyPixels,(GLint x, GLint y, GLsizei width, GLsizei height, GLenum type)); +STUB(void,glDrawBuffer,(GLenum mode)); +STUB(void,glEdgeFlag,(GLboolean flag)); +STUB(void,glIndexf,(GLfloat c)); +STUB(void,glPolygonStipple,(const GLubyte *mask)); +STUB(void,glReadBuffer,(GLenum mode)); +//STUB(void glSecondaryColor3f(GLfloat r, GLfloat g, GLfloat b)); +STUB(void,glColorTable,(GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const GLvoid *table)); + +STUB(void,glAccum,(GLenum op, GLfloat value)); +STUB(void,glPrioritizeTextures,(GLsizei n, const GLuint *textures, const GLclampf *priorities)); +//STUB(void,glPixelMapfv,(GLenum map, GLsizei mapsize, const GLfloat *values)); +//STUB(void,glPixelMapuiv,(GLenum map,GLsizei mapsize, const GLuint *values)); +//STUB(void,glPixelMapusv,(GLenum map,GLsizei mapsize, const GLushort *values)); +STUB(void,glPassThrough,(GLfloat token)); +STUB(void,glIndexMask,(GLuint mask)); +//STUB(void,glGetPixelMapfv,(GLenum map, GLfloat *data)); +//STUB(void,glGetPixelMapuiv,(GLenum map, GLuint *data)); +//STUB(void,glGetPixelMapusv,(GLenum map, GLushort *data)); +STUB(void,glClearIndex,(GLfloat c)); +STUB(void,glGetPolygonStipple,(GLubyte *pattern)); +STUB(void,glFeedbackBuffer,(GLsizei size, GLenum type, GLfloat *buffer)); +STUB(void,glEdgeFlagv,(GLboolean *flag)); +//STUB(void glIndexPointer(GLenum type, GLsizei stride, const GLvoid * pointer)); +#undef STUB diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/wrap/skips.h b/Projects/Android/jni/SupportLibs/gl4es/src/gl/wrap/skips.h new file mode 100644 index 0000000..858a434 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/wrap/skips.h @@ -0,0 +1,297 @@ +#ifndef _GL4ES_SKIPS_H_ +#define _GL4ES_SKIPS_H_ + +// don't auto-wrap these functions +// gl4es.c +#define skip_glColor4f +#define skip_glColor4ub +#define skip_glDisable +#define skip_glEnable +#define skip_glIsEnabled +#define skip_glNormal3f + +#define skip_glBindBuffer +#define skip_glBufferData +#define skip_glBufferSubData +#define skip_glDeleteBuffers +#define skip_glGenBuffers +#define skip_glIsBuffer +#define skip_glGetBufferPointerv +#define skip_glMapBuffer +#define skip_glUnmapBuffer +#define skip_glGetBufferParameteriv +#define skip_glGetBufferSubData + +#define skip_glBlendColor +#define skip_glBlendFunc +#define skip_glBlendEquation +#define skip_glBlendEquationSeparate +#define skip_glBlendEquationSeparatei +#define skip_glBlendFuncSeparate +#define skip_glBlendFuncSeparatei + +#define skip_glShadeModel + +#define skip_glAlphaFunc +#define skip_glLogicOp + +#define skip_glColorMask +#define skip_glClear + +// depth.c +#define skip_glDepthFunc +#define skip_glDepthMask +#define skip_glDepthRangef +#define skip_glClearDepthf + +// face.c +#define skip_glCullFace +#define skip_glFrontFace + +// fog.c +#define skip_glFogfv +#define skip_glFogf +#define skip_glFogCoordf +#define skip_glFogCoordfv +#define skip_glFogCoordPointer + +// getter.c +#define skip_glGetError +#define skip_glGetPointerv +#define skip_glGetIntegerv +#define skip_glGetFloatv +#define skip_glGetString +#define skip_glGetLightfv +#define skip_glGetMaterialfv +#define skip_glGetClipPlanef + +// hint.c +#define skip_glHint + +// light.c +#define skip_glLightModelf +#define skip_glLightModelfv +#define skip_glLightfv +#define skip_glLightf +#define skip_glMaterialfv +#define skip_glMaterialf + +// raster.c +#define skip_glViewport + +// texture.c +#define skip_glIsTexture +#define skip_glBindTexture +#define skip_glCopyTexImage2D +#define skip_glCopyTexSubImage2D +#define skip_glGenTextures +#define skip_glDeleteTextures +#define skip_glPixelStorei +#define skip_glPixelStoref +#define skip_glTexImage2D +#define skip_glTexParameteri +#define skip_glTexParameterf +#define skip_glTexParameterfv +#define skip_glTexParameteriv +#define skip_glTexSubImage2D +#define skip_glActiveTexture +#define skip_glClientActiveTexture +#define skip_glMultiTexCoord4f +#define skip_glTexGeni +#define skip_glTexGenfv +#define skip_glTexEnvf +#define skip_glTexEnvi +#define skip_glTexEnvfv +#define skip_glTexEnviv +#define skip_glGetTexEnvfv +#define skip_glGetTexEnviv +#define skip_glReadPixels +#define skip_glCompressedTexImage2D +#define skip_glCompressedTexSubImage2D +#define skip_glGetTexParameterfv +#define skip_glGetTexParameteriv + +// glDrawArrays +#define skip_glDrawArrays +#define skip_glDrawElements +#define skip_glVertexPointer +#define skip_glColorPointer +#define skip_glNormalPointer +#define skip_glTexCoordPointer +#define skip_glDisableClientState +#define skip_glEnableClientState + +// Framebuffers +#define skip_glGenFramebuffers +#define skip_glDeleteFramebuffers +#define skip_glIsFramebuffer +#define skip_glCheckFramebufferStatus +#define skip_glBindFramebuffer +#define skip_glFramebufferTexture2D +#define skip_glGenRenderbuffers +#define skip_glFramebufferRenderbuffer +#define skip_glDeleteRenderbuffers +#define skip_glRenderbufferStorage +#define skip_glRenderbufferStorageMultisample +#define skip_glBindRenderbuffer +#define skip_glIsRenderbuffer +#define skip_glGenerateMipmap +#define skip_glGetFramebufferAttachmentParameteriv +#define skip_glGetRenderbufferParameteriv + +#define skip_glFlush +#define skip_glFinish + +// matrix.c +#define skip_glPushMatrix +#define skip_glPopMatrix +#define skip_glLoadMatrixf +#define skip_glMultMatrixf +#define skip_glMatrixMode +#define skip_glLoadIdentity +#define skip_glTranslatef +#define skip_glScalef +#define skip_glRotatef +#define skip_glOrthof +#define skip_glFrustumf + +// planes.c +#define skip_glClipPlanef + +// MultiDrawArrays +#define skip_glMultiDrawArrays +#define skip_glMultiDrawElements +// this is to avoid a warning. I don't Push those anyway +#define direct_glMultiDrawArrays +#define direct_glMultiDrawElements + +// pointsprite.c +#define skip_glPointSize +#define skip_glPointParameterfv +#define skip_glPointParameterf + +// buffer.c +#define skip_glGenBuffers +#define skip_glBindBuffer +#define skip_glBufferData +#define skip_glBufferSubData +#define skip_glDeleteBuffers +#define skip_glIsBuffer +#define skip_glGetBufferParameteriv +#define skip_glMapBuffer +#define skip_glUnmapBuffer +#define skip_glGetBufferPointerv +#define skip_glGetBufferSubData +#define skip_glGenVertexArrays +#define skip_glBindVertexArray +#define skip_glDeleteVertexArrays +#define skip_glIsVertexArray + +// shader.c +#define skip_glCreateShader +#define skip_glDeleteShader +#define skip_glCompileShader +#define skip_glShaderSource +#define skip_glGetShaderSource +#define skip_glIsShader +#define skip_glGetShaderInfoLog +#define skip_glGetShaderiv +#define skip_glGetShaderPrecisionFormat +#define skip_glShaderBinary +#define skip_glReleaseShaderCompiler + +// vertexattrib.c +#define skip_glVertexAttribPointer +#define skip_glEnableVertexAttribArray +#define skip_glDisableVertexAttribArray +#define skip_glVertexAttrib1f +#define skip_glVertexAttrib2f +#define skip_glVertexAttrib3f +#define skip_glVertexAttrib4f +#define skip_glVertexAttrib1fv +#define skip_glVertexAttrib2fv +#define skip_glVertexAttrib3fv +#define skip_glVertexAttrib4fv +#define skip_glGetVertexAttribfv +#define skip_glGetVertexAttribiv +#define skip_glGetVertexAttribPointerv + +// program.c +#define skip_glAttachShader +#define skip_glBindAttribLocation +#define skip_glCreateProgram +#define skip_glDeleteProgram +#define skip_glDetachShader +#define skip_glGetActiveAttrib +#define skip_glGetActiveUniform +#define skip_glGetAttachedShaders +#define skip_glGetAttribLocation +#define skip_glGetProgramInfoLog +#define skip_glGetProgramiv +#define skip_glGetUniformLocation +#define skip_glIsProgram +#define skip_glLinkProgram +#define skip_glUseProgram +#define skip_glValidateProgram + +// stencil.c +#define skip_glStencilFunc +#define skip_glStencilFuncSeparate +#define skip_glStencilMask +#define skip_glStencilMaskSeparate +#define skip_glStencilOp +#define skip_glStencilOpSeparate +#define skip_glClearStencil + +//uniform.c +#define skip_glGetUniformfv +#define skip_glGetUniformiv +#define skip_glUniform1f +#define skip_glUniform2f +#define skip_glUniform3f +#define skip_glUniform4f +#define skip_glUniform1i +#define skip_glUniform2i +#define skip_glUniform3i +#define skip_glUniform4i +#define skip_glUniform1fv +#define skip_glUniform2fv +#define skip_glUniform3fv +#define skip_glUniform4fv +#define skip_glUniform1iv +#define skip_glUniform2iv +#define skip_glUniform3iv +#define skip_glUniform4iv +#define skip_glUniformMatrix2fv +#define skip_glUniformMatrix3fv +#define skip_glUniformMatrix4fv + +// other aliased function +#define skip_glSampleCoverage + +// don't compile these into display lists +#define direct_glColorPointer +#define direct_glDeleteLists +#define direct_glDisableClientState +#define direct_glEdgeFlagPointer +#define direct_glEnableClientState +//#define direct_glClientActiveTexture // will use it in Batch mode +#define direct_glFeedbackBuffer +#define direct_glGenLists +#define direct_glIndexPointer +#define direct_glInterleavedArrays +#define direct_glIsEnabled +#define direct_glIsList +#define direct_glNormalPointer +#define direct_glPopClientAttrib +#define direct_glPixelStorei +#define direct_glPixelStoref +#define direct_glPushClientAttrib +#define direct_glRenderMode +#define direct_glSelectBuffer +#define direct_glTexCoordPointer +#define direct_glVertexPointer +#define direct_glGenTextures +#define direct_glGetError + +#endif // _GL4ES_SKIPS_H_ diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/gl/wrap/stub.h b/Projects/Android/jni/SupportLibs/gl4es/src/gl/wrap/stub.h new file mode 100644 index 0000000..6b84441 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/gl/wrap/stub.h @@ -0,0 +1,40 @@ +#include "../gles.h" + +//GLint gl4es_glRenderMode(GLenum mode); +//void gl4es_glBlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha); +void gl4es_glBlendEquationSeparatei(GLuint buf, GLenum modeRGB, GLenum modeAlpha); +//void gl4es_glBlendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha); +void gl4es_glBlendFuncSeparatei(GLuint buf, GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha); +//void gl4es_glColorMaterial(GLenum face, GLenum mode); +void gl4es_glCopyPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum type); +void gl4es_glDrawBuffer(GLenum mode); +void gl4es_glEdgeFlag(GLboolean flag); +//void gl4es_glFogCoordd(GLdouble coord); +//void gl4es_glFogCoorddv(const GLdouble *coord); +//void gl4es_glFogCoordf(GLfloat coord); +//void gl4es_glFogCoordfv(const GLfloat *coord); +//void gl4es_glGetTexImage(GLenum target, GLint level, GLenum format, GLenum type, GLvoid * img); +//void gl4es_glGetTexLevelParameterfv(GLenum target, GLint level, GLenum pname, GLfloat *params); +//void gl4es_glGetTexLevelParameteriv(GLenum target, GLint level, GLenum pname, GLint *params); +void gl4es_glIndexf(GLfloat c); +void gl4es_glLightModeli(GLenum pname, GLint param); +void gl4es_glPolygonStipple(const GLubyte *mask); +void gl4es_glReadBuffer(GLenum mode); +void gl4es_glSecondaryColor3f(GLfloat r, GLfloat g, GLfloat b); +void gl4es_glColorTable (GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const GLvoid *table); +//void gl4es_glIndexPointer(GLenum type, GLsizei stride, const GLvoid * pointer); + +void gl4es_glAccum(GLenum op, GLfloat value); +void gl4es_glPrioritizeTextures(GLsizei n, const GLuint *textures, const GLclampf *priorities); +void gl4es_glPixelMapfv(GLenum map, GLsizei mapsize, const GLfloat *values); +void gl4es_glPixelMapuiv(GLenum map,GLsizei mapsize, const GLuint *values); +void gl4es_glPixelMapusv(GLenum map,GLsizei mapsize, const GLushort *values); +void gl4es_glPassThrough(GLfloat token); +void gl4es_glIndexMask(GLuint mask); +void gl4es_glGetPixelMapfv(GLenum map, GLfloat *data); +void gl4es_glGetPixelMapuiv(GLenum map, GLuint *data); +void gl4es_glGetPixelMapusv(GLenum map, GLushort *data); +void gl4es_glClearIndex(GLfloat c); +void gl4es_glGetPolygonStipple(GLubyte *pattern); +void gl4es_glFeedbackBuffer(GLsizei size, GLenum type, GLfloat *buffer); +void gl4es_glEdgeFlagv(GLboolean *flag); diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/glx/gbm.c b/Projects/Android/jni/SupportLibs/gl4es/src/glx/gbm.c new file mode 100644 index 0000000..fa64ec6 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/glx/gbm.c @@ -0,0 +1,176 @@ +#include "hardext.h" +#include "../gl/loader.h" +#include "../gl/init.h" +#include "../gl/gl4es.h" +#include "glx_gbm.h" + +#define SHUT(a) if(!globals4es.nobanner) a + +#ifndef NO_GBM +#include +#include + +#include +#include +#include +#include +#include +#include + +#ifndef NO_GBM +#ifndef EGL_PLATFORM_GBM_KHR +#define EGL_PLATFORM_GBM_KHR 0x31D7 +#endif +#endif + +// define static function pointers +// for GBM +#define GBMFUNC(ret, name, args) \ + typedef ret (*PFN##name) args; \ + static PFN##name gbmdrm_##name = NULL; +#include "gbmfunc.h" +#undef GBMFUNC + +static void CancelGBM() +{ + if(gbm) + dlclose(gbm); + #define GBMFUNC(ret, name, args) \ + gbmdrm_##name = NULL; + #include "gbmfunc.h" + #undef GBMFUNC + + gbm = NULL; + globals4es.usegbm = 0; +} + +static int drm_fd = -1; // drm handle +static struct gbm_device *gbmdev = NULL; + +static int OpenGBM() +{ + int available = 0; + + int drm_fd = open(globals4es.drmcard, O_RDWR | O_CLOEXEC); + if (drm_fd >= 0) { + gbmdev = gbmdrm_gbm_create_device(drm_fd); + if(!gbmdev) { + printf("LIBGL: Error initializing gbm device\n"); + } else { + available = 1; + } + } + + SHUT(printf("LIBGL: GBM on card %s is %s\n", globals4es.drmcard, available?"Available":"Not available")); + + return available; +} + +void LoadGBMFunctions() +{ + if(!gbm) + return; + // load functions + #define GBMFUNC(ret, name, args) \ + gbmdrm_##name = (PFN##name)dlsym(gbm, #name); \ + if(!gbmdrm_##name) { \ + printf("LIBGL: function %s missing, no gbm surface enabled\n", #name); \ + CancelGBM(); \ + return; \ + } + #include "gbmfunc.h" + #undef GBMFUNC + // Check card + if(!OpenGBM()) { + CancelGBM(); + return; + } + // all done + return; +} + +void CloseGBMFunctions() +{ + if(gbmdev) { + gbmdrm_gbm_device_destroy(gbmdev); + gbmdev = NULL; + } + if (drm_fd >= 0) { + close(drm_fd); + drm_fd = -1; + } + +} + +void* OpenGBMDisplay(void* display) +{ + if(hardext.gbm) { + LOAD_EGL(eglGetPlatformDisplay); + return egl_eglGetPlatformDisplay(EGL_PLATFORM_GBM_KHR, gbmdev, NULL); + } else { + LOAD_EGL(eglGetDisplay); + return egl_eglGetDisplay((EGLNativeDisplayType)gbmdev); + } +} + +void* CreateGBMWindow(int w, int h) +{ + void* ret = gbmdrm_gbm_surface_create(gbmdev, w, h, GBM_FORMAT_XRGB8888, GBM_BO_USE_RENDERING); + if(!ret) + printf("LIBGL: Warning, cannot create gbm surface %dx%d\n", w, h); +} + +void DeleteGBMWindow(void* win) +{ + gbmdrm_gbm_surface_destroy((struct gbm_surface*)win); +} + +int FindGBMConfig(EGLConfig *configs, int numFounds) +{ + int idx = 0; + while(idx +#endif // !defined(ANDROID) && !defined(AMIGAOS4) +#include +#include "khash.h" +#ifdef USE_FBIO +#include +#endif // USE_FBIO +#include +#include +#include +#ifdef PANDORA +#include +#include +#endif // PANDORA +#include + +#ifdef AMIGAOS4 +#include "../agl/amigaos.h" +#endif // AMIGAOS4 +#include "../gl/debug.h" +#include "../gl/framebuffers.h" +#include "../gl/init.h" +#include "../gl/loader.h" +#ifdef PANDORA +#include "../gl/pixel.h" +#endif +#include "glx_gbm.h" +#include "hardext.h" +#include "streaming.h" +#include "utils.h" + +#ifndef AliasExport +#define AliasExport(name) __attribute__((alias(name))) __attribute__((visibility("default"))) +#endif + +//#define DEBUG +#ifdef DEBUG +#pragma GCC optimize 0 +#define DBG(a) a +#else +#define DBG(a) +#endif + +#ifndef EGL_GL_COLORSPACE_KHR +#define EGL_GL_COLORSPACE_KHR 0x309D +#define EGL_GL_COLORSPACE_SRGB_KHR 0x3089 +#define EGL_GL_COLORSPACE_LINEAR_KHR 0x308A +#endif + +#ifndef NOEGL +static bool eglInitialized = false; +static EGLDisplay eglDisplay = NULL; +static EGLSurface eglSurface = NULL; +static EGLConfig eglConfigs[1]; +#endif +static int glx_default_depth=0; +#ifdef PANDORA +static struct sockaddr_un sun; +static int sock = -2; +#endif + +#ifndef NOX11 +typedef struct { + int Width; + int Height; + EGLContext Context; + EGLSurface Surface; + EGLConfig Config; + int Depth; + Display *dpy; + int Type; GC gc; + XImage* frame; +} glx_buffSize; + +//PBuffer should work under ANDROID / NOX11 +static GLXPbuffer *pbufferlist = NULL; +static glx_buffSize *pbuffersize = NULL; +static int pbufferlist_cap = 0; +static int pbufferlist_size = 0; +static int isPBuffer(GLXDrawable drawable) { + for (int i=0; i ", *width, *height);) + LOAD_EGL(eglQuerySurface); + egl_eglQuerySurface(eglDisplay, glxContext->eglSurface, EGL_WIDTH, width); + egl_eglQuerySurface(eglDisplay, glxContext->eglSurface, EGL_HEIGHT, height); + DBG(printf("%dx%d (%s)\n", *width, *height, PrintEGLError(0));) +#endif +} + +#ifndef NOEGL +// hmm... +static EGLContext eglContext = EGL_NO_CONTEXT; +#endif + +static int fbcontext_count = 0; + +#ifdef USE_FBIO +#ifndef FBIO_WAITFORVSYNC +#define FBIO_WAITFORVSYNC _IOW('F', 0x20, __u32) +#endif +static int fbdev = -1; +#endif + +static int g_width=0, g_height=0; +static int swapinterval = 1; // default value. Also, should be tracked by drawable... +static int minswap=0; +static int maxswap=1; +// **** RPI stuffs **** +void (*bcm_host_init)(); +void (*bcm_host_deinit)(); +#ifndef ANDROID +#include "rpi.h" +#endif +// ***** end of RPI stuffs **** + +// Generic create native window to use with "LIBGL_FB=1" (so with EGL_DEFAULT_DISPLAY and without X11) +static void* create_native_window(int w, int h) { +#if !defined(ANDROID) && !defined(AMIGAOS4) + if(bcm_host) return create_rpi_window(w, h); +#endif +#ifndef NO_GBM + if(globals4es.usegbm) return CreateGBMWindow(w, h); +#endif + return NULL; +} +static void delete_native_window(void* win) { +#if !defined(ANDROID) && !defined(AMIGAOS4) + if(bcm_host) return delete_rpi_window(win); +#endif +#ifndef NO_GBM + if(globals4es.usegbm) return DeleteGBMWindow(win); +#endif +} + +#define SHUT(a) if(!globals4es.nobanner) a + +#ifndef NOEGL +static EGLint egl_context_attrib_es2[] = { + EGL_CONTEXT_CLIENT_VERSION, 2, + EGL_NONE +}; + +static EGLint egl_context_attrib[] = { + EGL_NONE +}; + +typedef struct { + EGLSurface surf; + int *cnt; +} SharedEGLSurface_t; + +KHASH_MAP_INIT_INT(eglsurfacelist_t, SharedEGLSurface_t*); +static khash_t(eglsurfacelist_t) *eglsurfaces = NULL; + +static void RecycleAddSurface(GLXDrawable drawable, SharedEGLSurface_t* surf) { + if(!eglsurfaces) { + eglsurfaces = kh_init(eglsurfacelist_t); + } + int ret; + khint_t k; + k = kh_put(eglsurfacelist_t, eglsurfaces, drawable, &ret); + SharedEGLSurface_t *newsurf = malloc(sizeof(SharedEGLSurface_t)); + memcpy(newsurf, surf, sizeof(SharedEGLSurface_t)); + kh_value(eglsurfaces, k) = newsurf; + DBG(printf("LIBGL: EGLSurface for drawable %p Added\n", (void*)drawable);) +} + +static SharedEGLSurface_t* RecycleGetSurface(GLXDrawable drawable) { + if(!eglsurfaces) + return NULL; + int ret; + khint_t k; + k = kh_get(eglsurfacelist_t, eglsurfaces, drawable); + if (k != kh_end(eglsurfaces)){ + DBG(printf("LIBGL: EGLSurface for drawable %p found\n", (void*)drawable);) + return kh_value(eglsurfaces, k); + } + return NULL; +} + +static void RecycleDelSurface(GLXDrawable drawable) { + if(!eglsurfaces) + return; + int ret; + khint_t k; + k = kh_get(eglsurfacelist_t, eglsurfaces, drawable); + if (k != kh_end(eglsurfaces)){ + /*LOAD_EGL(eglDestroySurface); + egl_eglDestroySurface(eglDisplay, kh_value(eglsurfaces, k));*/ + free(kh_value(eglsurfaces, k)); + kh_del(eglsurfacelist_t, eglsurfaces, k); + DBG(printf("LIBGL: EGLSurface for drawable %p removed\n", (void*)drawable);) + } + return; +} +#endif + + +extern void* egl; +int globales2 = 0; +// GLState management +void* NewGLState(void* shared_glstate, int es2only); +void DeleteGLState(void* oldstate); +void ActivateGLState(void* new_glstate); + +typedef struct { + int drawable; +#ifndef NOEGL + EGLSurface surface; +#endif + int PBuffer; +} map_drawable_t; +KHASH_MAP_INIT_INT(mapdrawable, map_drawable_t*) +khash_t(mapdrawable) *MapDrawable = NULL; + +int8_t CheckEGLErrors() { +#ifndef NOEGL + const char *errortext = PrintEGLError(1); + + if (errortext) { + LOGE("LIBGL: ERROR: EGL Error detected: %s\n", errortext); + return 1; + } +#endif + return 0; +} +#ifndef NOX11 +static int get_config_default(Display *display, int attribute, int *value) { + switch (attribute) { + case GLX_USE_GL: + case GLX_RGBA: + case GLX_DOUBLEBUFFER: + case GLX_X_RENDERABLE: + *value = 1; + break; + case GLX_LEVEL: + case GLX_STEREO: + *value = 0; + break; + case GLX_AUX_BUFFERS: + *value = 0; + break; +#ifdef PANDORA + case GLX_RED_SIZE: + *value = 5; + break; + case GLX_GREEN_SIZE: + *value = 6; + break; + case GLX_BLUE_SIZE: + *value = 5; + break; + case GLX_ALPHA_SIZE: + *value = 8; // why not 0? + break; + case GLX_DEPTH_SIZE: + *value = 16; + break; +#else + case GLX_RED_SIZE: + *value = 8; + break; + case GLX_GREEN_SIZE: + *value = 8; + break; + case GLX_BLUE_SIZE: + *value = 8; + break; + case GLX_ALPHA_SIZE: + *value = 8; + break; + case GLX_DEPTH_SIZE: + *value = 32; + break; +#endif + case GLX_STENCIL_SIZE: + *value = 8; + break; + case GLX_ACCUM_RED_SIZE: + case GLX_ACCUM_GREEN_SIZE: + case GLX_ACCUM_BLUE_SIZE: + case GLX_ACCUM_ALPHA_SIZE: + *value = 0; + break; + case GLX_TRANSPARENT_TYPE: + *value = GLX_NONE; + break; + case GLX_RENDER_TYPE: + *value = GLX_RGBA_TYPE; + break; + case GLX_VISUAL_ID: + *value = gl4es_glXGetVisualFromFBConfig(display, NULL)->visualid; + //gl4es_glXChooseVisual(display, 0, NULL)->visualid; + //*value = 1; + break; + case GLX_FBCONFIG_ID: + *value = 0; + break; + case GLX_DRAWABLE_TYPE: + *value = GLX_WINDOW_BIT; + break; + case GLX_BUFFER_SIZE: + *value = 16; + break; + case GLX_X_VISUAL_TYPE: + case GLX_CONFIG_CAVEAT: + case GLX_SAMPLE_BUFFERS: + case GLX_SAMPLES: + *value = 0; + break; + case GLX_FRAMEBUFFER_SRGB_CAPABLE_ARB: + *value = hardext.srgb; + break; + default: + DBG(printf(" => Unknown attrib\n");) + LOGD("LIBGL: unknown attrib %i\n", attribute); + *value = 0; + return 1; + } + DBG(printf(" -> 0x%04X\n", *value);) + return 0; +} + +static void init_display(Display *display) { + LOAD_EGL(eglGetDisplay); + + if (! g_display) { + g_display = display;//XOpenDisplay(NULL); + } + if(globals4es.usegbm) { + eglDisplay = OpenGBMDisplay(display); + } + if(!eglDisplay) { + if (globals4es.usefb || globals4es.usepbuffer) { + eglDisplay = egl_eglGetDisplay(EGL_DEFAULT_DISPLAY); + } else { + eglDisplay = egl_eglGetDisplay(display); + } + } +} + +static int InitEGL(Display *display) { + if(eglInitialized) + return 1; + + if(!eglDisplay || eglDisplay==EGL_NO_DISPLAY) { + init_display(display); + if (eglDisplay == EGL_NO_DISPLAY) + return 0; + } + LOAD_EGL(eglBindAPI); + LOAD_EGL(eglInitialize); + egl_eglBindAPI(EGL_OPENGL_ES_API); + EGLint result = egl_eglInitialize(eglDisplay, NULL, NULL); + if (result != EGL_TRUE) { + CheckEGLErrors(); + LOGE("LIBGL: Unable to initialize EGL display.\n"); + return 0; + } + eglInitialized = true; + return 1; +} + +#endif //NOX11 +static void init_vsync() { +#ifdef USE_FBIO + fbdev = open("/dev/fb0", O_RDONLY); + if (fbdev < 0) { + LOGE("LIBGL: Could not open /dev/fb0 for vsync.\n"); + } +#endif +} + +static void xrefresh() { + int dummy = system("xrefresh"); +} + +#ifdef PANDORA +static void pandora_reset_gamma() { + if(globals4es.gamma>0.0f) + system("sudo /usr/pandora/scripts/op_gamma.sh 0"); +} +void pandora_set_gamma() { + { + char buf[50]; + if(globals4es.gamma>0.0f) + sprintf(buf, "sudo /usr/pandora/scripts/op_gamma.sh %.2f", globals4es.gamma); + else + sprintf(buf, "sudo /usr/pandora/scripts/op_gamma.sh 0"); + int dummy = system(buf); + } +} +#endif + +static void signal_handler(int sig) { + if (globals4es.xrefresh) + xrefresh(); +#ifdef PANDORA + pandora_reset_gamma(); +#endif + +#if defined(BCMHOST) && !defined(ANDROID) + rpi_fini(); +#endif +#if !defined(ANDROID) && !defined(AMIGAOS4) + if (globals4es.stacktrace) { + switch (sig) { + case SIGBUS: + case SIGFPE: + case SIGILL: + case SIGSEGV: { + void *array[10]; + size_t size = backtrace(array, 10); + if (! size) { + LOGD("LIBGL: No stacktrace. Compile with -funwind-tables.\n"); + } else { + LOGD("LIBGL: Stacktrace: %zd\n", size); + backtrace_symbols_fd(array, size, 2); + } + break; + } + } + } +#endif + signal(sig, SIG_DFL); + raise(sig); +} +#ifdef PANDORA +static void init_liveinfo() { + static const char socket_name[] = "\0liveinfo"; + sock = socket(PF_UNIX, SOCK_DGRAM, 0); + if (sock == -1) { + // no socket, so LiveInfo probably not active + return; + } + + memset(&sun, 0, sizeof(sun)); + sun.sun_family = AF_UNIX; + memcpy(sun.sun_path, socket_name, sizeof(socket_name)); + // send a test string + const char test_string[] = "gl: fpsinfo"; + if (sendto(sock, test_string, strlen(test_string), 0,(struct sockaddr *)&sun, sizeof(sun))<0) { + // error, so probably not present + close(sock); + sock=-1; + } else + fcntl(sock, F_SETFL, O_NONBLOCK); +} + +#endif + +void glx_init() { + // init map_drawable + int ret; + MapDrawable = kh_init(mapdrawable); + kh_put(mapdrawable, MapDrawable, 1, &ret); + kh_del(mapdrawable, MapDrawable, 1); +#if defined(BCMHOST) && !defined(ANDROID) + rpi_init(); +#endif + if(globals4es.usegbm) + atexit(CloseGBMFunctions); + if (globals4es.xrefresh || globals4es.stacktrace) + { + // TODO: a bit gross. Maybe look at this: http://stackoverflow.com/a/13290134/293352 + signal(SIGBUS, signal_handler); + signal(SIGFPE, signal_handler); + //signal(SIGILL, signal_handler); + signal(SIGSEGV, signal_handler); + if (globals4es.xrefresh) { + signal(SIGINT, signal_handler); + signal(SIGQUIT, signal_handler); + signal(SIGTERM, signal_handler); + } + if (globals4es.xrefresh) + atexit(xrefresh); +#if !defined(ANDROID) && !defined(AMIGAOS4) +#endif //!ANDROID && !AMIGAOS4 + } +#ifdef PANDORA + atexit(pandora_reset_gamma); +#elif defined(BCMHOST) + atexit(bcm_host_deinit); +#elif defined(AMIGAOS4) + atexit(os4CloseLib); +#endif + //V-Sync + if (globals4es.vsync) + init_vsync(); +#ifdef PANDORA + + init_liveinfo(); + if (sock>-1) { + SHUT(LOGD("LIBGL: LiveInfo detected, fps will be shown\n")); + } +#endif +} + +#ifndef NOX11 +static XVisualInfo *latest_visual = NULL; +static GLXFBConfig *latest_glxfbconfig = NULL; + +GLXContext gl4es_glXCreateContext(Display *display, + XVisualInfo *visual, + GLXContext shareList, + Bool isDirect) { + DBG(printf("glXCreateContext(%p, %p, %p, %i), latest_visual=%p, fbcontext_count=%d", display, visual, shareList, isDirect, latest_visual, fbcontext_count);) + + static struct __GLXFBConfigRec default_glxfbconfig; + GLXFBConfig glxfbconfig; + + if(visual==latest_visual && latest_glxfbconfig) + glxfbconfig = latest_glxfbconfig[0]; + else { + glxfbconfig = &default_glxfbconfig; + memset(glxfbconfig, 0, sizeof(struct __GLXFBConfigRec)); + default_glxfbconfig.redBits = (visual==0)?0:(visual->depth==16)?5:8; + default_glxfbconfig.greenBits = (visual==0)?0:(visual->depth==16)?6:8; + default_glxfbconfig.blueBits = (visual==0)?0:(visual->depth==16)?5:8; + default_glxfbconfig.alphaBits = (visual==0)?0:(visual->depth!=32)?0:8; + default_glxfbconfig.depthBits = 16; + default_glxfbconfig.stencilBits = 8; + default_glxfbconfig.doubleBufferMode = 1; + } + int depthBits = glxfbconfig->depthBits; + if(glxfbconfig->stencilBits>8) + glxfbconfig->stencilBits = 8; +#ifdef PANDORA + if(depthBits==32) + depthBits = (glxfbconfig->stencilBits==8 && hardext.esversion==2)?24:16; + if(depthBits==24 && glxfbconfig->stencilBits==8 && !(globals4es.usefbo || globals4es.usepbuffer || hardext.esversion==2)) + depthBits = 16; + else if(depthBits==16 && glxfbconfig->stencilBits==8 && hardext.esversion==2) + depthBits = 24; +#endif + + DBG(printf("Creating R:%d G:%d B:%d A:%d Depth:%d Stencil:%d Multisample:%d/%d\n", glxfbconfig->redBits, glxfbconfig->greenBits, glxfbconfig->blueBits, glxfbconfig->alphaBits, depthBits, glxfbconfig->stencilBits, glxfbconfig->nMultiSampleBuffers, glxfbconfig->multiSampleSize);) + EGLint configAttribs[] = { +#ifdef PANDORA + EGL_RED_SIZE, 5, + EGL_GREEN_SIZE, 6, + EGL_BLUE_SIZE, 5, +#else + EGL_RED_SIZE, glxfbconfig->redBits, + EGL_GREEN_SIZE, glxfbconfig->greenBits, + EGL_BLUE_SIZE, glxfbconfig->blueBits, + EGL_ALPHA_SIZE, (hardext.eglnoalpha)?0:glxfbconfig->alphaBits, +#endif + EGL_DEPTH_SIZE, depthBits, + EGL_RENDERABLE_TYPE, (hardext.esversion==1)?EGL_OPENGL_ES_BIT:EGL_OPENGL_ES2_BIT, + //EGL_BUFFER_SIZE, depthBits, + EGL_STENCIL_SIZE, glxfbconfig->stencilBits, + + EGL_SAMPLE_BUFFERS, glxfbconfig->nMultiSampleBuffers, + EGL_SAMPLES, glxfbconfig->multiSampleSize, + + EGL_SURFACE_TYPE, EGL_WINDOW_BIT | EGL_PBUFFER_BIT, + EGL_NONE + }; + if (globals4es.usefb) + ++fbcontext_count; + + LOAD_EGL(eglMakeCurrent); + LOAD_EGL(eglDestroyContext); + LOAD_EGL(eglDestroySurface); + LOAD_EGL(eglCreateContext); + LOAD_EGL(eglChooseConfig); + LOAD_EGL(eglQueryString); + + GLXContext fake = malloc(sizeof(struct __GLXContextRec)); + memset(fake, 0, sizeof(struct __GLXContextRec)); + + // make an egl context here... + EGLBoolean result; + if (eglDisplay == NULL || eglDisplay == EGL_NO_DISPLAY) { + init_display(display); + if (eglDisplay == EGL_NO_DISPLAY) { + DBG(printf(" => %p\n", NULL);) + CheckEGLErrors(); + LOGE("LIBGL: Unable to create EGL display.\n"); + free(fake); + return 0; + } + } + + // first time? + if (eglInitialized == false) { + if(!InitEGL(display)) { + DBG(printf(" => %p\n", NULL);) + CheckEGLErrors(); + LOGE("LIBGL: Unable to init EGL.\n"); + free(fake); + return 0; + } + } + + int configsFound; + result = egl_eglChooseConfig(eglDisplay, configAttribs, fake->eglConfigs, 30, &configsFound); + if(configsFound && globals4es.usegbm) + fake->eglconfigIdx = FindGBMConfig(fake->eglConfigs, configsFound); + + CheckEGLErrors(); + if (result != EGL_TRUE || configsFound == 0) { + DBG(printf(" => %p\n", NULL);) + LOGE("LIBGL: No EGL configs found (depth=%d, stencil=%d).\n", depthBits, glxfbconfig->stencilBits); + free(fake); + return 0; + } + EGLContext shared = (shareList)?shareList->eglContext:EGL_NO_CONTEXT; + fake->eglContext = egl_eglCreateContext(eglDisplay, fake->eglConfigs[fake->eglconfigIdx], shared, (hardext.esversion==1)?egl_context_attrib:egl_context_attrib_es2); + + CheckEGLErrors(); + + // need to return a glx context pointing at it + fake->display = display; + fake->direct = true; + fake->xid = 1; //TODO: Proper handling of that id... + fake->contextType = 0; //Window + fake->doublebuff = glxfbconfig->doubleBufferMode; +#ifdef PANDORA + fake->rbits = 5; fake->gbits=6; fake->bbits=5; fake->abits=0; +#else + fake->rbits = (visual==0)?8:(visual->depth==16)?5:8, + fake->gbits= (visual==0)?8:(visual->depth==16)?6:8, + fake->bbits= (visual==0)?8:(visual->depth==16)?5:8, + fake->abits= (visual==0)?8:(visual->depth!=32)?0:8, +#endif + fake->samples = 0; fake->samplebuffers = 0; + fake->shared = (shareList)?shareList->glstate:NULL; + + DBG(printf(" => %p\n", fake);) + return fake; +} + +GLXContext createPBufferContext(Display *display, GLXContext shareList, GLXFBConfig config) { + + EGLint configAttribs[] = { + EGL_RED_SIZE, (config)?config->redBits:0, + EGL_GREEN_SIZE, (config)?config->greenBits:0, + EGL_BLUE_SIZE, (config)?config->blueBits:0, + EGL_ALPHA_SIZE, (hardext.eglnoalpha)?0:((config)?config->alphaBits:0), + EGL_SURFACE_TYPE, EGL_PBUFFER_BIT, + EGL_RENDERABLE_TYPE, (hardext.esversion==1)?EGL_OPENGL_ES_BIT:EGL_OPENGL_ES2_BIT, + EGL_SAMPLE_BUFFERS, (config)?config->nMultiSampleBuffers:0, + EGL_SAMPLES, (config)?config->multiSampleSize:0, + EGL_NONE + }; + + LOAD_EGL(eglChooseConfig); + LOAD_EGL(eglCreateContext); + LOAD_EGL(eglGetConfigAttrib); + + // Check that the config is for PBuffer + if(config->drawableType&GLX_PBUFFER_BIT!=GLX_PBUFFER_BIT) + return 0; + + // Init what need to be done + EGLBoolean result; + if (eglDisplay == NULL || eglDisplay == EGL_NO_DISPLAY) { + init_display(display); + + if (eglDisplay == EGL_NO_DISPLAY) { + LOGE("LIBGL: Unable to create EGL display.\n"); + return 0; + } + } + + // first time? + if (eglInitialized == false) { + result = InitEGL(display); + if (!result) { + CheckEGLErrors(); + LOGE("LIBGL: Unable to initialize EGL display.\n"); + return 0; + } + } + + // select a configuration + int configsFound; + static EGLConfig pbufConfigs[1]; + result = egl_eglChooseConfig(eglDisplay, configAttribs, pbufConfigs, 1, &configsFound); + + CheckEGLErrors(); + if (result != EGL_TRUE || configsFound == 0) { + LOGE("LIBGL: No EGL configs found.\n"); + return 0; + } + + EGLContext shared = (shareList)?shareList->eglContext:EGL_NO_CONTEXT; + + GLXContext fake = malloc(sizeof(struct __GLXContextRec)); + memset(fake, 0, sizeof(struct __GLXContextRec)); + fake->es2only = globales2; + fake->shared = (shareList)?shareList->glstate:NULL; + fake->eglConfigs[0] = pbufConfigs[0]; + + fake->eglContext = egl_eglCreateContext(eglDisplay, fake->eglConfigs[0], shared, (hardext.esversion==1)?egl_context_attrib:egl_context_attrib_es2); + + CheckEGLErrors(); + + // need to return a glx context pointing at it + fake->display = display; + fake->direct = true; + fake->xid = 1; //TODO: Proper handling of that id... + fake->contextType = 1; //PBuffer + egl_eglGetConfigAttrib(eglDisplay, fake->eglConfigs[0], EGL_RED_SIZE, &fake->rbits); + egl_eglGetConfigAttrib(eglDisplay, fake->eglConfigs[0], EGL_GREEN_SIZE, &fake->gbits); + egl_eglGetConfigAttrib(eglDisplay, fake->eglConfigs[0], EGL_BLUE_SIZE, &fake->bbits); + egl_eglGetConfigAttrib(eglDisplay, fake->eglConfigs[0], EGL_ALPHA_SIZE, &fake->abits); + egl_eglGetConfigAttrib(eglDisplay, fake->eglConfigs[0], EGL_DEPTH_SIZE, &fake->depth); + egl_eglGetConfigAttrib(eglDisplay, fake->eglConfigs[0], EGL_STENCIL_SIZE, &fake->stencil); + egl_eglGetConfigAttrib(eglDisplay, fake->eglConfigs[0], EGL_SAMPLES, &fake->samples); + egl_eglGetConfigAttrib(eglDisplay, fake->eglConfigs[0], EGL_SAMPLE_BUFFERS, &fake->samplebuffers); + + DBG(printf(" => return PBufferContext %p (context->shared=%p)\n", fake, fake->shared);) + return fake; +} + +GLXContext gl4es_glXCreateContextAttribsARB(Display *display, GLXFBConfig config, + GLXContext share_context, Bool direct, + const int *attrib_list) { + DBG(printf("glXCreateContextAttribsARB(%p, %p, %p, %d) ", display, config, share_context, direct);if(config)printf("config is RGBA:%d%d%d%d, depth=%d, stencil=%d, drawable=%d\n", config->redBits, config->greenBits, config->blueBits, config->alphaBits, config->depthBits, config->stencilBits, config->drawableType); else printf("\n");) + if(config && config->drawableType==GLX_PBUFFER_BIT) { + return createPBufferContext(display, share_context, config); + } else { + EGLint configAttribs[] = { +#ifdef PANDORA + EGL_RED_SIZE, (config->drawableType)==GLX_PIXMAP_BIT?config->redBits:5, + EGL_GREEN_SIZE, (config->drawableType)==GLX_PIXMAP_BIT?config->greenBits:6, + EGL_BLUE_SIZE, (config->drawableType)==GLX_PIXMAP_BIT?config->blueBits:5, + EGL_ALPHA_SIZE, (config->drawableType)==GLX_PIXMAP_BIT?config->alphaBits:0, +#else + EGL_RED_SIZE, config->redBits, + EGL_GREEN_SIZE, config->greenBits, + EGL_BLUE_SIZE, config->blueBits, + EGL_ALPHA_SIZE, (hardext.eglnoalpha)?0:config->alphaBits, +#endif + EGL_DEPTH_SIZE, config->depthBits, + EGL_STENCIL_SIZE, config->stencilBits, + EGL_SAMPLES, config->multiSampleSize, + EGL_SAMPLE_BUFFERS, config->nMultiSampleBuffers, + EGL_RENDERABLE_TYPE, (hardext.esversion==1)?EGL_OPENGL_ES_BIT:EGL_OPENGL_ES2_BIT, + EGL_SURFACE_TYPE, (config->drawableType==GLX_PIXMAP_BIT)?EGL_PIXMAP_BIT:EGL_WINDOW_BIT, + EGL_NONE + }; + if (globals4es.usefb) + ++fbcontext_count; + + LOAD_EGL(eglMakeCurrent); + LOAD_EGL(eglDestroyContext); + LOAD_EGL(eglDestroySurface); + LOAD_EGL(eglCreateContext); + LOAD_EGL(eglChooseConfig); + LOAD_EGL(eglQueryString); + LOAD_EGL(eglGetConfigAttrib); + + GLXContext fake = malloc(sizeof(struct __GLXContextRec)); + memset(fake, 0, sizeof(struct __GLXContextRec)); + fake->es2only = globales2; + + fake->shared = (share_context)?share_context->glstate:NULL; + + // make an egl context here... + EGLBoolean result; + if (eglDisplay == NULL || eglDisplay == EGL_NO_DISPLAY) { + init_display(display); + if (eglDisplay == EGL_NO_DISPLAY) { + LOGE("LIBGL: Unable to create EGL display.\n"); + return fake; + } + } + + // first time? + if (eglInitialized == false) { + result = InitEGL(display); + if (!result) { + CheckEGLErrors(); + LOGE("LIBGL: Unable to initialize EGL display.\n"); + return fake; + } + } + + int configsFound; + result = egl_eglChooseConfig(eglDisplay, configAttribs, fake->eglConfigs, 30, &configsFound); + if(configsFound && globals4es.usegbm) + fake->eglconfigIdx = FindGBMConfig(fake->eglConfigs, configsFound); + + CheckEGLErrors(); + if (result != EGL_TRUE || configsFound == 0) { + LOGE("LIBGL: No EGL configs found.\n"); + return fake; + } + EGLContext shared = (share_context)?share_context->eglContext:EGL_NO_CONTEXT; + fake->eglContext = egl_eglCreateContext(eglDisplay, fake->eglConfigs[fake->eglconfigIdx], shared, (hardext.esversion==1)?egl_context_attrib:egl_context_attrib_es2); + + CheckEGLErrors(); + + // need to return a glx context pointing at it + fake->display = display; + fake->direct = true; + fake->xid = 1; //TODO: Proper handling of that id... + fake->contextType = (config->drawableType)==GLX_PIXMAP_BIT?2:0; //Pixmap:Window + fake->doublebuff = config->doubleBufferMode; + + egl_eglGetConfigAttrib(eglDisplay, fake->eglConfigs[fake->eglconfigIdx], EGL_RED_SIZE, &fake->rbits); + egl_eglGetConfigAttrib(eglDisplay, fake->eglConfigs[fake->eglconfigIdx], EGL_GREEN_SIZE, &fake->gbits); + egl_eglGetConfigAttrib(eglDisplay, fake->eglConfigs[fake->eglconfigIdx], EGL_BLUE_SIZE, &fake->bbits); + egl_eglGetConfigAttrib(eglDisplay, fake->eglConfigs[fake->eglconfigIdx], EGL_ALPHA_SIZE, &fake->abits); + egl_eglGetConfigAttrib(eglDisplay, fake->eglConfigs[fake->eglconfigIdx], EGL_DEPTH_SIZE, &fake->depth); + egl_eglGetConfigAttrib(eglDisplay, fake->eglConfigs[fake->eglconfigIdx], EGL_STENCIL_SIZE, &fake->stencil); + egl_eglGetConfigAttrib(eglDisplay, fake->eglConfigs[fake->eglconfigIdx], EGL_SAMPLES, &fake->samples); + egl_eglGetConfigAttrib(eglDisplay, fake->eglConfigs[fake->eglconfigIdx], EGL_SAMPLE_BUFFERS, &fake->samplebuffers); + egl_eglGetConfigAttrib(eglDisplay, fake->eglConfigs[fake->eglconfigIdx], EGL_MIN_SWAP_INTERVAL, &minswap); + egl_eglGetConfigAttrib(eglDisplay, fake->eglConfigs[fake->eglconfigIdx], EGL_MAX_SWAP_INTERVAL, &maxswap); + DBG(printf(" => return %p (context->shared=%p)\n", fake, fake->shared);) + return fake; + } +} + +void gl4es_glXDestroyContext(Display *display, GLXContext ctx) { + DBG(printf("glXDestroyContext(%p, %p), fbcontext_count=%d, ctx_type=%d\n", display, ctx, fbcontext_count, (ctx)?ctx->contextType:0);) + if(globals4es.usefb) + --fbcontext_count; + if (ctx->eglContext) { + // need to bind back the context to delete stuff? + LOAD_EGL(eglMakeCurrent); + if(eglSurface!=ctx->eglSurface || eglContext!=ctx->eglContext) + egl_eglMakeCurrent(eglDisplay, ctx->eglSurface, ctx->eglSurface, ctx->eglContext); + + if (globals4es.usefbo && ctx->contextType==0) { + deleteMainFBO(ctx->glstate); + } + + DeleteGLState(ctx->glstate); + + // bind context back + if(eglSurface!=ctx->eglSurface || eglContext!=ctx->eglContext) + egl_eglMakeCurrent(eglDisplay, eglContext?eglSurface:NULL, eglContext?eglSurface:NULL, eglContext); + + LOAD_EGL(eglDestroyContext); + LOAD_EGL(eglDestroySurface); + + EGLBoolean result = egl_eglDestroyContext(eglDisplay, ctx->eglContext); + ctx->eglContext = 0; + if (ctx->eglSurface != 0) { + if(globals4es.usefb!=1 /*|| !fbcontext_count*/) { // this ressource leak is left on purpose (Pandora driver doesn't seems to like to many Creation of the surface) + int destroySurf = 1; + if(ctx->shared_eglsurface && (--(*ctx->shared_eglsurface))>0) + destroySurf = 0; + if(destroySurf) { + if(!globals4es.glxrecycle) { + DBG(printf(" egDestroySurface(%p, %p), drawable=%p\n", eglDisplay, ctx->eglSurface, (void*)ctx->drawable);) + egl_eglDestroySurface(eglDisplay, ctx->eglSurface); + RecycleDelSurface(ctx->drawable); + } + } + eglSurface = 0; + } + ctx->eglSurface = 0; + } + if(ctx->shared_eglsurface && (*ctx->shared_eglsurface)<=0 && !globals4es.glxrecycle) + free(ctx->shared_eglsurface); + + if (result != EGL_TRUE) { + CheckEGLErrors(); + LOGE("LIBGL: Failed to destroy EGL context.\n"); + } + /*if (fbdev >= 0) { + close(fbdev); + fbdev = -1; + }*/ + } + if(glxContext==ctx) + glxContext = NULL; + + free(ctx); + return; +} + +Display *gl4es_glXGetCurrentDisplay() { + DBG(printf("glXGetCurrentDisplay()\n");) + if (g_display && eglContext) { + return g_display; + } + + return XOpenDisplay(NULL); +} + +XVisualInfo *gl4es_glXChooseVisual(Display *display, + int screen, + int *attributes) { + DBG(printf("glXChooseVisual(%p, %d, %p)\n", display, screen, attributes);) + + // create a new attribute list for glXChooseFBConfig based on the attributes liste given... + int attr[50]; + int idx = 0; + int cur = 0; + int ask_depth = 0; + if(attributes) { + + int ask_rgba = 0; + while (attributes[cur]) { + switch(attributes[cur]) { + case GLX_RGBA: + ask_rgba = 1; // only rgba will be supported? + break; + case GLX_USE_GL: // yeah, I know + break; + case GLX_BUFFER_SIZE: + case GLX_STEREO: + case GLX_ACCUM_RED_SIZE: + case GLX_ACCUM_GREEN_SIZE: + case GLX_ACCUM_BLUE_SIZE: + case GLX_ACCUM_ALPHA_SIZE: + ++cur; // ignored + break; + case GLX_DOUBLEBUFFER: + attr[idx++] = GLX_DOUBLEBUFFER; + attr[idx++] = 1; + break; + case GLX_RED_SIZE: + case GLX_GREEN_SIZE: + case GLX_BLUE_SIZE: + case GLX_ALPHA_SIZE: + ask_depth += attributes[cur+1]; + case GLX_DEPTH_SIZE: + case GLX_STENCIL_SIZE: + case GLX_LEVEL: + attr[idx++] = attributes[cur++]; + attr[idx++] = attributes[cur]; + break; + } + ++cur; + } + attr[idx++] = 0; // end list + + if(!ask_rgba) + return NULL; // only TrueColor profile... + } + glx_default_depth = XDefaultDepth(display, screen); + if (glx_default_depth != 16 && glx_default_depth != 24 && glx_default_depth != 32) + LOGD("LIBGL: unusual desktop color depth %d\n", glx_default_depth); + +#ifndef PANDORA + // PANDORA only has 16bits X11, lets ignore 32bits requests + if(ask_depth>glx_default_depth) + glx_default_depth = ask_depth; // higher depth... +#endif + + XVisualInfo *visual = (XVisualInfo *)malloc(sizeof(XVisualInfo)); + if (!XMatchVisualInfo(display, screen, glx_default_depth, TrueColor, visual)) { + LOGE("LIBGL: XMatchVisualInfo failed in glXChooseVisual\n"); + return NULL; + } + + + // create and store the glxConfig that goes with thoses attributes + latest_visual = visual; + int count = 1; + if(latest_glxfbconfig) + free(latest_glxfbconfig); + if(cur) + latest_glxfbconfig = gl4es_glXChooseFBConfig(display, screen, attr, &count); + else + latest_glxfbconfig = gl4es_glXGetFBConfigs(display, screen, &count); + + return visual; +} + +/* +EGL_BAD_MATCH is generated if draw or read are not compatible with context +or if context is set to EGL_NO_CONTEXT and draw or read are not set to +EGL_NO_SURFACE, or if draw or read are set to EGL_NO_SURFACE and context is +not set to EGL_NO_CONTEXT. +*/ + +Bool gl4es_glXMakeCurrent(Display *display, + GLXDrawable drawable, + GLXContext context) { + DBG(printf("glXMakeCurrent(%p, %p, %p), isPBuffer(drawable)=%d, context->drawable=%p, context->eglSurface=%p(%p), context->doublebuff=%d\n", display, (void*)drawable, context, isPBuffer(drawable), (void*)(context?context->drawable:0), context?context->eglSurface:0, eglSurface, context?context->doublebuff:0);) + LOAD_EGL(eglMakeCurrent); + LOAD_EGL(eglDestroySurface); + LOAD_EGL(eglCreateWindowSurface); + LOAD_EGL(eglQuerySurface); +#ifdef NOX11 + int created = 0; +#else + int created = (context)?isPBuffer(drawable):0; +#endif + EGLContext eglContext = EGL_NO_CONTEXT; + EGLSurface eglSurf = 0; + EGLConfig eglConfig = 0; + // flush current context if exist... + if(glxContext && glxContext->glstate) { + /*if(!context && !glxContext->doublebuff && !glxContext->contextType) { + gl4es_glXSwapBuffers(display, glxContext->drawable); + } else*/ + gl4es_glFlush(); + } + if(context && glxContext==context && context->drawable==drawable) { + DBG(printf(" => True\n");) + //same context, all is done bye + DBG(printf("Same context and drawable, doing nothing\n");) + return true; + } + if(globals4es.fbomakecurrent && glxContext && glxContext->glstate) { + current_fb = gl4es_getCurrentFBO(); + if(current_fb) { + if(hardext.vendor&VEND_ARM) + gl4es_glFinish(); //MALI seems to need a flush commandbefore unbinding the Framebuffer here + LOAD_GLES2_OR_OES(glBindFramebuffer); + gles_glBindFramebuffer(GL_FRAMEBUFFER, 0); + } + } + if(context) { + if(context->drawable==drawable && context->eglSurface) { + // same-same, recycling... + //eglSurf = context->eglSurface; // no need, it's done after the ifs... + } else if (glxContext && glxContext->drawable==drawable && glxContext->eglSurface && !context->eglSurface) { + context->eglSurface = glxContext->eglSurface; // lets hope eglContexts are compatible + if(!glxContext->shared_eglsurface) + glxContext->shared_eglsurface = (int*)calloc(1, sizeof(int)); + context->shared_eglsurface = glxContext->shared_eglsurface; + (*glxContext->shared_eglsurface)++; + } else { + // new one + if(created) { +#ifndef NOX11 + eglSurf = context->eglSurface = pbuffersize[created-1].Surface; //(EGLSurface)drawable; + eglContext = context->eglContext = pbuffersize[created-1].Context; // this context is ok for the PBuffer + eglConfig = context->eglConfigs[context->eglconfigIdx] = pbuffersize[created-1].Config; + /*if (context->contextType != pbuffersize[created-1].Type) { // Context / buffer not aligned, create a new glstate tracker + if(context->glstate) + DeleteGLState(context->glstate); + context->glstate = NULL; + context->shared = NULL; + }*/ +#endif + } else { + EGLint attrib_list[5]; + int cnt=0; + if(!context->doublebuff) { + attrib_list[cnt++] = EGL_RENDER_BUFFER; + attrib_list[cnt++] = EGL_SINGLE_BUFFER; + } + if(globals4es.glx_surface_srgb){ + attrib_list[cnt++] = EGL_GL_COLORSPACE_KHR; + attrib_list[cnt++] = EGL_GL_COLORSPACE_SRGB_KHR; + } + attrib_list[cnt++] = EGL_NONE; + + unsigned int width = 0, height = 0, depth = 0; +#ifndef NOX11 + if(globals4es.usepbuffer) { + // Get Window size and all... + unsigned int border; + Window root; + int x, y; + XGetGeometry(display, drawable, &root, &x, &y, &width, &height, &border, &depth); + DBG(printf("XGetGeometry gives %dx%d for drawable %p\n", width, height, (void*)drawable);) + } else if((globals4es.usefb) || globals4es.usegbm) { + // Get size of desktop + Screen *screen = DefaultScreenOfDisplay(display); + width = WidthOfScreen(screen); + height = HeightOfScreen(screen); + DBG(printf("X11 gives a size of desktop %dx%d for drawable %p\n", width, height, (void*)drawable);) + } + if(globals4es.usepbuffer) { + //let's create a PBuffer attributes + EGLint egl_attribs[10]; // should be enough + int i = 0; + egl_attribs[i++] = EGL_WIDTH; + egl_attribs[i++] = width; + egl_attribs[i++] = EGL_HEIGHT; + egl_attribs[i++] = height; + egl_attribs[i++] = EGL_NONE; + + if(createPBuffer(display, egl_attribs, &eglSurf, &eglContext, &eglConfig, (depth>16)?8:5, (depth==15)?5:(depth>16)?8:6, (depth>16)?8:5, (depth==32)?8:0, context->samplebuffers, context->samples)==0) { + // fail too, abort + SHUT(LOGE("LIBGL: PBuffer creation failed too\n")); + return 0; + } + int Width, Height; + + egl_eglQuerySurface(eglDisplay,eglSurf,EGL_WIDTH,&Width); + egl_eglQuerySurface(eglDisplay,eglSurf,EGL_HEIGHT,&Height); + + addPixBuffer(display, eglSurf, eglConfig, Width, Height, eglContext, drawable, depth, 2); + context->eglSurface = eglSurf; + context->eglContext = eglContext; + // update, that context is a created emulated one... + created = isPBuffer(drawable); + } else +#endif + { + if(globals4es.usefb || globals4es.usefbo || globals4es.usegbm) { + if(eglSurface) // cannot create multiple eglSurface for the same Framebuffer? + eglSurf = context->eglSurface = eglSurface; + else { + SharedEGLSurface_t *oldsurf = RecycleGetSurface(drawable); + if(oldsurf) { + eglSurf = oldsurf->surf; + if(eglSurf != EGL_NO_SURFACE) + context->shared_eglsurface = oldsurf->cnt; + } + if(eglSurf == EGL_NO_CONTEXT) { + context->nativewin = create_native_window(width,height); +#ifndef NO_GBM + if(globals4es.usegbm) { + LOAD_EGL(eglCreatePlatformWindowSurface); + eglSurf = egl_eglCreatePlatformWindowSurface(eglDisplay, context->eglConfigs[context->eglconfigIdx], context->nativewin, attrib_list); + } else +#endif + eglSurf = egl_eglCreateWindowSurface(eglDisplay, context->eglConfigs[context->eglconfigIdx], (EGLNativeWindowType)context->nativewin, attrib_list); + } else { + DBG(printf("LIBGL: EglSurf Recycled\n");) + } + eglSurface = context->eglSurface = eglSurf; + if(!eglSurf) { + DBG(printf("LIBGL: Warning, EglSurf is null\n");) + CheckEGLErrors(); + } + } + } else { + if(context->eglSurface) { + int destroySurf = 1; + if(context->shared_eglsurface && (--(*context->shared_eglsurface))>0) + destroySurf = 0; + if(destroySurf) { + if(!globals4es.glxrecycle) { + egl_eglDestroySurface(eglDisplay, context->eglSurface); + RecycleDelSurface(context->drawable); + } + } + } + SharedEGLSurface_t *oldsurf = RecycleGetSurface(drawable); + if(oldsurf) { + eglSurf = oldsurf->surf; + if(eglSurf != EGL_NO_SURFACE) + context->shared_eglsurface = oldsurf->cnt; + } + if(eglSurf == EGL_NO_SURFACE) { + eglSurf = context->eglSurface = egl_eglCreateWindowSurface(eglDisplay, context->eglConfigs[0], drawable, attrib_list); + } else { + DBG(printf("LIBGL: eglSurf Recycled\n");) + context->eglSurface = eglSurf; + } + if(!eglSurf) { + DBG(printf("LIBGL: Warning, eglSurf is null\n");) + CheckEGLErrors(); + } + } + } + } + } + eglSurf = context->eglSurface; + eglContext = context->eglContext; + } + EGLBoolean result = egl_eglMakeCurrent(eglDisplay, eglSurf, eglSurf, eglContext); + DBG(printf("LIBGL: eglMakeCurrent(%p, %p, %p, %p)\n", eglDisplay, eglSurf, eglSurf, eglContext);) + CheckEGLErrors(); + glxContext = context; + if(!result) { + // error switching context, don't change glstate and abort... + DBG(printf(" => False\n");) + return false; + } + // update MapDrawable + { + int ret; + khint_t k = kh_get(mapdrawable, MapDrawable, drawable); + map_drawable_t* map = NULL; + if (k == kh_end(MapDrawable)){ + k = kh_put(mapdrawable, MapDrawable, drawable, &ret); + map = kh_value(MapDrawable, k) = (map_drawable_t*)malloc(sizeof(map_drawable_t)); + map->drawable = drawable; + } else { + map = kh_value(MapDrawable, k); + } + map->surface = eglSurf; + map->PBuffer = created; + + } + if (context) { + // update Recycle + if(!RecycleGetSurface(drawable)) { + // add tracking, so add shared_counter now + if(!glxContext->shared_eglsurface) { + glxContext->shared_eglsurface = (int*)calloc(1, sizeof(int)); + } + (*glxContext->shared_eglsurface)++; + SharedEGLSurface_t surf; + surf.surf = glxContext->eglSurface; + surf.cnt = glxContext->shared_eglsurface; + RecycleAddSurface(drawable, &surf); + } + + if(!context->glstate) { + context->glstate = NewGLState(context->shared, context->es2only); + if(created && pbuffersize[created-1].Type >= 3) { + ((glstate_t*)context->glstate)->emulatedPixmap = created; + ((glstate_t*)context->glstate)->emulatedWin = pbuffersize[created-1].Type==4?1:0; + } + } + context->drawable = drawable; + + ActivateGLState(context->glstate); +#ifdef PANDORA + if(!created) pandora_set_gamma(); +#endif + + CheckEGLErrors(); + if (result) { + if (globals4es.usefbo && !created) { + // get size of the surface... + egl_eglQuerySurface(eglDisplay,eglSurf,EGL_WIDTH,&g_width); + egl_eglQuerySurface(eglDisplay,eglSurf,EGL_HEIGHT,&g_height); + if(getenv("LIBGL_FBO")) { + int fbo_width, fbo_height; + if(sscanf(getenv("LIBGL_FBO"), "%dx%d", &fbo_width, &fbo_height)==2) { + SHUT(printf("LIBGL: Forcing FBO size %dx%d (%dx%d)\n", fbo_width, fbo_height, g_width, g_height);) + g_width = fbo_width; + g_height = fbo_height; + } + } + // create the main_fbo... + createMainFBO(g_width, g_height); + } + if(globals4es.fbomakecurrent && gl4es_getCurrentFBO()) + gl4es_setCurrentFBO(); + // finished + DBG(printf(" => True (glstate=%p)\n", context?context->glstate:NULL);) + return true; + } + DBG(printf(" => False\n");) + return false; + } + DBG(printf(" => True (glstate=%p)\n", context?context->glstate:NULL);) + return true; +} + +Bool gl4es_glXMakeContextCurrent(Display *display, int drawable, + int readable, GLXContext context) { + DBG(printf("glXMakeContextCurrent(%p, %X, %X, %p)\n", display, drawable, readable, context);) + return gl4es_glXMakeCurrent(display, drawable, context); +} + +void gl4es_glXSwapBuffers(Display *display, + GLXDrawable drawable) { + static int frames = 0; + DBG(printf("\rglXSwapBuffers(%p, %p) ", display, (void*)drawable);) + LOAD_EGL(eglSwapBuffers); + // TODO: what if active context is not on the drawable? + realize_textures(); + if (glstate->list.active){ + flush(); + } + if (glstate->raster.bm_drawing) + bitmap_flush(); + EGLSurface surface = eglSurface; + int PBuffer = 0; + { + // get MapDrawable surface + khint_t k = kh_get(mapdrawable, MapDrawable, drawable); + map_drawable_t* map = NULL; + if (k != kh_end(MapDrawable)){ + map = kh_value(MapDrawable, k); + surface = map->surface; + PBuffer = map->PBuffer; + } + } +#ifdef USE_FBIO + if (globals4es.vsync && fbdev >= 0 && PBuffer==0) { + // TODO: can I just return if I don't meet vsync over multiple frames? + // this will just block otherwise. + int arg = 0; + for (int i = 0; i < swapinterval; i++) { + ioctl(fbdev, FBIO_WAITFORVSYNC, &arg); + } + } +#endif + if (globals4es.usefbo && PBuffer==0) { + unbindMainFBO(); + int x = 0, y = 0; + unsigned int width = 0, height = 0; +#ifndef NOX11 + { + unsigned int border, depth; + Window root; + XWindowAttributes xwa; + XGetGeometry(display, drawable, &root, &x, &y, &width, &height, &border, &depth); // get geometry (relative to window) + XTranslateCoordinates( display, drawable, root, 0, 0, &x, &y, &root ); // translate to get x,y absolute to screen + } +#endif + DBG(printf("blitMainFBO(%d, %d, %u, %u)\n", x, y, width, height);) + blitMainFBO(x, y, width, height); + // blit the main_fbo before swap + //adjust FBO size if needed + if((width && height && (width!=glstate->fbo.mainfbo_width || height!=glstate->fbo.mainfbo_height))) { + createMainFBO(width, height); // adjust mainFBO + } + } + // check emulated Pixmap + if(PBuffer && glstate->emulatedPixmap) { + LOAD_GLES(glFinish); + gles_glFinish(); + BlitEmulatedPixmap(); + } else + egl_eglSwapBuffers(eglDisplay, surface); + //CheckEGLErrors(); // not sure it's a good thing to call a eglGetError() after all eglSwapBuffers, performance wize (plus result is discarded anyway) +#ifdef PANDORA + if (globals4es.showfps || (sock>-1)) +#else + if (globals4es.showfps) +#endif + { + // framerate counter + static float avg, fps = 0; + static int frame1, last_frame, frame, now, current_frames; + struct timeval out; + gettimeofday(&out, NULL); + now = out.tv_sec; + frame++; + current_frames++; + + if (frame == 1) { + frame1 = now; + } else if (frame1 < now) { + if (last_frame < now) { + float change = current_frames / (float)(now - last_frame); + float weight = 0.7; + if (! fps) { + fps = change; + } else { + fps = (1 - weight) * fps + weight * change; + } + current_frames = 0; + + avg = frame / (float)(now - frame1); + if (globals4es.showfps) LOGD("LIBGL: fps: %.2f, avg: %.2f\n", fps, avg); +#ifdef PANDORA + if (sock>-1) { + char tmp[60]; + snprintf(tmp, 60, "gl: %2.2f", fps); + sendto(sock, tmp, strlen(tmp), 0,(struct sockaddr *)&sun, sizeof(sun)); + } +#endif + } + } + last_frame = now; + } + if (globals4es.usefbo && PBuffer==0) { + bindMainFBO(); + } +} + +int gl4es_glXGetConfig(Display *display, + XVisualInfo *visual, + int attribute, + int *value) { + return get_config_default(display, attribute, value); +} + +const char *gl4es_glXQueryExtensionsString(Display *display, int screen) { + DBG(printf("glXQueryExtensionString(%p, %d)\n", display, screen);) + const char *extensions = + "GLX_ARB_create_context " + "GLX_ARB_create_context_profile " + "GLX_ARB_get_proc_address " + "GLX_ARB_multisample " + "GLX_SGI_swap_control " + "GLX_MESA_swap_control " + "GLX_EXT_swap_control " + "GLX_EXT_create_context_es2_profile "; + //TODO: make this string parametrable, to remo ES2 profile if not on ES2 Backend? + return extensions; +} + +const char *gl4es_glXQueryServerString(Display *display, int screen, int name) { + DBG(printf("glXQueryServerString(%p, %d, %d)\n", display, screen, name);) + switch (name) { + case GLX_VENDOR: return "ptitSeb"; + case GLX_VERSION: return "1.4 GL4ES"; + case GLX_EXTENSIONS: return gl4es_glXQueryExtensionsString(display, screen); + } + return 0; +} + +Bool gl4es_glXQueryExtension(Display *display, int *errorBase, int *eventBase) { + DBG(printf("glXQueryExtension(%p, %p, %p)\n", display, errorBase, eventBase);) + if (errorBase) + *errorBase = 0; + + if (eventBase) + *eventBase = 0; + + return true; +} + +Bool gl4es_glXQueryVersion(Display *display, int *major, int *minor) { + DBG(printf("glXQueryVersion(%p, %p, %p)\n", display, major, minor);) + // TODO: figure out which version we want to pretend to implement + *major = 1; + *minor = 4; + return true; +} + +const char *gl4es_glXGetClientString(Display *display, int name) { + DBG(printf("glXGetClientString(%p, %d)\n", display, name);) + switch (name) { + case GLX_VENDOR: return "ptitSeb"; + case GLX_VERSION: return "1.4 GL4ES"; + case GLX_EXTENSIONS: return gl4es_glXQueryExtensionsString(display, 0); + } + return 0; +} + +int gl4es_glXQueryContext( Display *dpy, GLXContext ctx, int attribute, int *value ) { + DBG(printf("glXQueryContext(%p, %p, %d, %p)\n", dpy, ctx, attribute, value);) + *value=0; + if (ctx) switch (attribute) { + case GLX_FBCONFIG_ID: *value=(int)(uintptr_t)ctx->eglConfigs[ctx->eglconfigIdx]; break; + case GLX_RENDER_TYPE: *value=GLX_RGBA_TYPE; break; + case GLX_SCREEN: break; // screen n# is always 0 + } + return 0; +} + +// stubs for glfw (GLX 1.3) +GLXContext gl4es_glXGetCurrentContext() { + DBG(printf("glXGetCurrentContext()\n");) + + return glxContext; +} + +#ifndef NO_EGL +GLXFBConfig * fillGLXFBConfig(EGLConfig *eglConfigs, int count, int withDB, Display *display) { + #define MAX_CONFIG 200 + static struct __GLXFBConfigRec ActualConfigs[MAX_CONFIG] = {0}; + static int ActualConfigIdx = 0; + LOAD_EGL(eglGetConfigAttrib); + EGLint tmp; + if(withDB==2) count*=2; + // still not correct, the ActualConfigs array should be build before hand, and the config choosen inside it instead + GLXFBConfig *configs = (GLXFBConfig *)calloc(count, sizeof(GLXFBConfig)); + for (int j=0; jredBits); + egl_eglGetConfigAttrib(eglDisplay, eglConfigs[i], EGL_GREEN_SIZE, &configs[j]->greenBits); + egl_eglGetConfigAttrib(eglDisplay, eglConfigs[i], EGL_BLUE_SIZE, &configs[j]->blueBits); + egl_eglGetConfigAttrib(eglDisplay, eglConfigs[i], EGL_ALPHA_SIZE, &configs[j]->alphaBits); + egl_eglGetConfigAttrib(eglDisplay, eglConfigs[i], EGL_DEPTH_SIZE, &configs[j]->depthBits); + egl_eglGetConfigAttrib(eglDisplay, eglConfigs[i], EGL_STENCIL_SIZE, &configs[j]->stencilBits); + egl_eglGetConfigAttrib(eglDisplay, eglConfigs[i], EGL_SAMPLES, &configs[j]->multiSampleSize); + egl_eglGetConfigAttrib(eglDisplay, eglConfigs[i], EGL_SAMPLE_BUFFERS, &configs[j]->nMultiSampleBuffers); + egl_eglGetConfigAttrib(eglDisplay, eglConfigs[i], EGL_SURFACE_TYPE, &tmp); + configs[i]->drawableType = 0; + if(tmp&EGL_WINDOW_BIT) configs[i]->drawableType |= GLX_WINDOW_BIT; + if(tmp&EGL_PBUFFER_BIT) configs[i]->drawableType |= GLX_PBUFFER_BIT; + if(tmp&EGL_PIXMAP_BIT) configs[i]->drawableType |= GLX_PIXMAP_BIT; + egl_eglGetConfigAttrib(eglDisplay, eglConfigs[i], EGL_MAX_PBUFFER_WIDTH, &configs[j]->maxPbufferWidth); + egl_eglGetConfigAttrib(eglDisplay, eglConfigs[i], EGL_MAX_PBUFFER_HEIGHT, &configs[j]->maxPbufferHeight); + egl_eglGetConfigAttrib(eglDisplay, eglConfigs[i], EGL_MAX_PBUFFER_PIXELS, &configs[j]->maxPbufferPixels); + egl_eglGetConfigAttrib(eglDisplay, eglConfigs[i], EGL_NATIVE_VISUAL_ID, &configs[j]->associatedVisualId); + if(!configs[j]->associatedVisualId) { + // why??? + glx_default_depth = XDefaultDepth(display, 0); + XVisualInfo visual;// = (XVisualInfo *)malloc(sizeof(XVisualInfo)); + XMatchVisualInfo(display, 0, glx_default_depth, TrueColor, &visual); + configs[j]->associatedVisualId = visual.visualid; + } + configs[j]->doubleBufferMode = (withDB==2)?(j%2):withDB; + configs[j]->id = eglConfigs[i]; + } + + return configs; +} +#endif + +GLXFBConfig *gl4es_glXChooseFBConfig(Display *display, int screen, + const int *attrib_list, int *count) { + DBG(printf("glXChooseFBConfig(%p, %d, %p, %p)\n", display, screen, attrib_list, count);) + // Maybe it would be easier to simply return an EGLConfig array? +#ifdef NO_EGL + static struct __GLXFBConfigRec currentConfig[8]; + static int idx = 0; + *count = 1; + GLXFBConfig *configs = (GLXFBConfig *)malloc(sizeof(GLXFBConfig)); + configs[0] = ¤tConfig[idx]; + idx=(idx+1)%8; + memset(configs[0], 0, sizeof(struct __GLXFBConfigRec)); + // fill that config with some of the attrib_list info... + configs[0]->drawableType = GLX_WINDOW_BIT; + configs[0]->screen = 0; + configs[0]->maxPbufferWidth = configs[0]->maxPbufferHeight = 2048; + configs[0]->redBits = configs[0]->greenBits = configs[0]->blueBits = configs[0]->alphaBits = 0; + configs[0]->nMultiSampleBuffers = 0; configs[0]->multiSampleSize = 0; + configs[0]->depthBits = 16; configs[0]->stencilBits = 8; + + return configs; +#else + // first build a table of EGL attributes + int attr[50]; + int cur = 0; + int cr = 0, cg = 0, cb = 0, ca = 0; + int tmp; + int drawable_set = 0; + int doublebuffer = 2; + int glxconfig = -1; + attr[cur++] = EGL_SURFACE_TYPE; + attr[cur++] = 0; + + if(attrib_list) { + int i = 0; + while(attrib_list[i]!=0) { + switch(attrib_list[i++]) { + case GLX_RED_SIZE: + tmp = attrib_list[i++]; + attr[cur++] = EGL_RED_SIZE; + cr = cur; + attr[cur++] = tmp; + DBG(printf("FBConfig redBits=%d\n", tmp);) + break; + case GLX_GREEN_SIZE: + tmp = attrib_list[i++]; + attr[cur++] = EGL_GREEN_SIZE; + cg = cur; + attr[cur++] = tmp; + DBG(printf("FBConfig greenBits=%d\n", tmp);) + break; + case GLX_BLUE_SIZE: + tmp = attrib_list[i++]; + attr[cur++] = EGL_BLUE_SIZE; + cb = cur; + attr[cur++] = tmp; + DBG(printf("FBConfig blueBits=%d\n", tmp);) + break; + case GLX_ALPHA_SIZE: + tmp = attrib_list[i++]; + attr[cur++] = EGL_ALPHA_SIZE; + ca = cur; + attr[cur++] = tmp; + DBG(printf("FBConfig alphaBits=%d\n", tmp);) + break; + case GLX_DEPTH_SIZE: + tmp = attrib_list[i++]; + attr[cur++] = EGL_DEPTH_SIZE; + attr[cur++] = tmp; + DBG(printf("FBConfig depthBits=%d\n", tmp);) + break; + case GLX_STENCIL_SIZE: + tmp = attrib_list[i++]; + attr[cur++] = EGL_STENCIL_SIZE; + attr[cur++] = tmp; + DBG(printf("FBConfig stencilBits=%d\n", tmp);) + break; + case GLX_DRAWABLE_TYPE: + tmp = attrib_list[i++]; + //attr[0] = EGL_SURFACE_TYPE; + //attr[1] = 0; + /*if(tmp&GLX_WINDOW_BIT) + attr[1] |= EGL_WINDOW_BIT;*/ // safe to ignore + if(tmp&GLX_PIXMAP_BIT) + attr[1] |= EGL_PIXMAP_BIT; + if(tmp&GLX_PBUFFER_BIT) + attr[1] |= EGL_PIXMAP_BIT; + drawable_set = 1; + DBG(printf("FBConfig drawableType=0x%X\n", tmp);) + break; + case GLX_SAMPLE_BUFFERS: + tmp = attrib_list[i++]; + attr[cur++] = EGL_SAMPLE_BUFFERS; + attr[cur++] = tmp; + DBG(printf("FBConfig multisampleBuffers=%d\n", tmp);) + break; + case GLX_SAMPLES: + tmp = attrib_list[i++]; + attr[cur++] = EGL_SAMPLES; + attr[cur++] = (tmp<0)?0:tmp; + DBG(printf("FBConfig multiSampleSize=%d\n", tmp);) + break; + case GLX_DOUBLEBUFFER: + if(attrib_list[i]==0 || attrib_list[i]==1) + doublebuffer = attrib_list[i++]; + else + doublebuffer = 1; + DBG(printf("FBConfig doubleBufferMode=%d\n", doublebuffer);) + break; + case GLX_X_RENDERABLE: + ++i; //value ignored + DBG(printf("FBConfig renderable=%d\n", attrib_list[i-1]);) + break; + case GLX_LEVEL: + tmp = attrib_list[i++]; + attr[cur++] = EGL_LEVEL; + attr[cur++] = tmp; + DBG(printf("FBConfig level=%d\n", tmp);) + case GLX_VISUAL_ID: + tmp = attrib_list[i++]; + attr[cur++] = EGL_NATIVE_VISUAL_ID; + attr[cur++] = tmp; + DBG(printf("FBConfig visual id=%d\n", tmp);) + case GLX_FBCONFIG_ID: + glxconfig = attrib_list[i++]; + DBG(printf("GLXFBConfigID=%d\n", glxconfig);) + default: + ++i; + // discard other stuffs + } + } + } + attr[1] |= (globals4es.usepbuffer)?(/*EGL_PBUFFER_BIT|*/EGL_PIXMAP_BIT):EGL_WINDOW_BIT; + + attr[cur++] = EGL_RENDERABLE_TYPE; + attr[cur++] = (hardext.esversion==1)?EGL_OPENGL_ES_BIT:EGL_OPENGL_ES2_BIT; + + attr[cur++] = EGL_NONE; // end list + + // get the number of EGL config matching! + if (eglInitialized == false) { + if(!InitEGL((globals4es.usefb || globals4es.usepbuffer)?g_display:display)) { + CheckEGLErrors(); + LOGE("LIBGL: Unable to initialize EGL.\n"); + return NULL; + *count = 0; + } + } + LOAD_EGL(eglChooseConfig); + if(glxconfig==-1) { + egl_eglChooseConfig(eglDisplay, attr, NULL, 0, count); + if((*count==0) && (globals4es.usepbuffer)) { + DBG(printf("glXChooseFBConfig found 0 config with PixMap, trying again with PBuffer\n");) + // try again, but with PBuffer + attr[1] = EGL_PBUFFER_BIT; + egl_eglChooseConfig(eglDisplay, attr, NULL, 0, count); + // On Pandora and GLES2, only 565 PBuffer are available! + if(cr || cg || cb || ca) { + --cur; + if(cr) attr[cr] = 5; else { attr[cur] = EGL_RED_SIZE; attr[cur++] = 5; } + if(cg) attr[cg] = 6; else { attr[cur] = EGL_GREEN_SIZE; attr[cur++] = 6; } + if(cb) attr[cb] = 5; else { attr[cur] = EGL_BLUE_SIZE; attr[cur++] = 5; } + if(ca) attr[ca] = 0; else { attr[cur] = EGL_ALPHA_SIZE; attr[cur++] = 0; } + attr[cur++] = EGL_NONE; // just in case + egl_eglChooseConfig(eglDisplay, attr, NULL, 0, count); + } + } + if((*count==0) && (!globals4es.usepbuffer) && ca && attr[ca+1]) { + DBG(printf("glXChooseFBConfig found 0 config with an Alpha channel, trying without\n");) + attr[ca] = 0; + egl_eglChooseConfig(eglDisplay, attr, NULL, 0, count); + } + if((*count==0) && (!globals4es.usepbuffer) && ca && attr[ca+1] && (attr[cr]>5 || attr[cg]>5 || attr[cb]>5)) { + DBG(printf("glXChooseFBConfig found 0 config without an Alpha channel, but 8bits rgb, trying lowering bitness\n");) + attr[cr] = attr[cg] = attr[cb] = 5; + egl_eglChooseConfig(eglDisplay, attr, NULL, 0, count); + } +#ifdef PANDORA + if((*count==0) && (!globals4es.usepbuffer) && (attr[cr]>5 || attr[cg]>5 || attr[cb]>5)) { + DBG(printf("glXChooseFBConfig found 0 config with 8bits rgb, trying lowering bitness\n");) + attr[cr] = attr[cg] = attr[cb] = 5; + egl_eglChooseConfig(eglDisplay, attr, NULL, 0, count); + } +#endif + if(*count==0) { // NO Config found.... + DBG(printf("glXChooseFBConfig found 0 config\n");) + return NULL; + } + } else { + *count = 1; + } + EGLConfig *eglConfigs = (EGLConfig*)calloc((*count), sizeof(EGLConfig)); + if(glxconfig==-1) + egl_eglChooseConfig(eglDisplay, attr, eglConfigs, *count, count); + else { + eglConfigs[0] = (EGLConfig)(uintptr_t)glxconfig; // downsizing on purpose + doublebuffer = 1; + } + // and now, build a config list! + GLXFBConfig *configs = fillGLXFBConfig(eglConfigs, *count, doublebuffer, display); + if(doublebuffer==2) *count *= 2; + free(eglConfigs); + DBG(printf("glXChooseFBConfig found %d config\n", *count);) + + return configs; +#endif +} + +GLXFBConfig *gl4es_glXGetFBConfigs(Display *display, int screen, int *count) { + DBG(printf("glXGetFBConfigs(%p, %d, %p)\n", display, screen, count);) +#ifdef NO_EGL + // this is wrong! The config table should be a static one built according to EGL Config capabilities... + *count = 1; + // this is to only do 1 malloc instead of 1 for the array and one for the element... + GLXFBConfig *configs = (GLXFBConfig *)malloc(sizeof(GLXFBConfig) + sizeof(struct __GLXFBConfigRec)); + configs[0] = (GLXFBConfig)((char*)(&configs[0])+sizeof(GLXFBConfig)); + memset(configs[0], 0, sizeof(struct __GLXFBConfigRec)); + configs[0]->drawableType = GLX_WINDOW_BIT | GLX_PBUFFER_BIT; + configs[0]->redBits = configs[0]->greenBits = configs[0]->blueBits = configs[0]->alphaBits = 8; + configs[0]->depthBits = 24; configs[0]->stencilBits = 8; + configs[0]->multiSampleSize = 0; configs[0]->nMultiSampleBuffers = 0; +#else + int attr[50]; + int cur = 0; + int tmp; + attr[cur++] = EGL_SURFACE_TYPE; + attr[cur++] = (globals4es.usepbuffer)?(EGL_PBUFFER_BIT|EGL_PIXMAP_BIT):EGL_WINDOW_BIT; + attr[cur++] = EGL_RENDERABLE_TYPE; + attr[cur++] = (hardext.esversion==1)?EGL_OPENGL_ES_BIT:EGL_OPENGL_ES2_BIT; + attr[cur++] = EGL_NONE; // end list + + // get the number of EGL config matching! + if (eglInitialized == false) { + if(!InitEGL((globals4es.usefb || globals4es.usepbuffer)?g_display:display)) { + CheckEGLErrors(); + LOGE("LIBGL: Unable to initialize EGL.\n"); + return NULL; + *count = 0; + } + } + LOAD_EGL(eglChooseConfig); + LOAD_EGL(eglGetConfigAttrib); + egl_eglChooseConfig(eglDisplay, attr, NULL, 0, count); + if(*count==0) // NO Config found.... + return NULL; + EGLConfig *eglConfigs = (EGLConfig*)calloc((*count), sizeof(EGLConfig)); + egl_eglChooseConfig(eglDisplay, attr, eglConfigs, *count, count); + // and now, build a config list! + GLXFBConfig *configs = fillGLXFBConfig(eglConfigs, *count, 2, display); + *count *= 2; + free(eglConfigs); + DBG(printf("glXGetFBConfig found %d config\n", *count);) +#endif + return configs; +} + +int gl4es_glXGetFBConfigAttrib(Display *display, GLXFBConfig config, int attribute, int *value) { + DBG(printf("glXGetFBConfigAttrib(%p, %p, 0x%04X, %p)", display, config, attribute, value);) + if(!config) { + return get_config_default(display, attribute, value); + } + + switch (attribute) { + case GLX_RGBA: + *value = config->alphaBits>0?1:0; + case GLX_RED_SIZE: + *value = config->redBits; + break; + case GLX_GREEN_SIZE: + *value = config->greenBits; + break; + case GLX_BLUE_SIZE: + *value = config->blueBits; + break; + case GLX_ALPHA_SIZE: + *value = config->alphaBits; + break; + case GLX_DEPTH_SIZE: + *value = config->depthBits; + break; + case GLX_STENCIL_SIZE: + *value = config->stencilBits; + break; + case GLX_ACCUM_RED_SIZE: + case GLX_ACCUM_GREEN_SIZE: + case GLX_ACCUM_BLUE_SIZE: + case GLX_ACCUM_ALPHA_SIZE: + *value = 0; + break; + case GLX_TRANSPARENT_TYPE: + *value = GLX_NONE; + break; + case GLX_RENDER_TYPE: + *value = GLX_RGBA_BIT; + break; + case GLX_VISUAL_ID: + //*value = gl4es_glXGetVisualFromFBConfig(display, NULL)->visualid; + //*value = gl4es_glXChooseVisual(display, 0, NULL)->visualid; + *value = config->associatedVisualId; + //*value = 1; + break; + case GLX_FBCONFIG_ID: + *value = (int)(uintptr_t)config->id; + break; + case GLX_DRAWABLE_TYPE: + *value = GLX_WINDOW_BIT; //config->drawableType; + break; + case GLX_X_VISUAL_TYPE: + case GLX_CONFIG_CAVEAT: + *value = 0; + break; + case GLX_SAMPLE_BUFFERS: + *value = config->nMultiSampleBuffers; + break; + case GLX_SAMPLES: + *value = config->multiSampleSize; + break; + case GLX_FRAMEBUFFER_SRGB_CAPABLE_ARB: + *value = hardext.srgb; + break; + case GLX_DOUBLEBUFFER: + *value = config->doubleBufferMode; + break; + default: + return get_config_default(display, attribute, value); + } + DBG(printf(" => 0x%04X\n", *value);) + return Success; +} + +XVisualInfo *gl4es_glXGetVisualFromFBConfig(Display *display, GLXFBConfig config) { + DBG(printf("glXGetVisualFromFBConfig(%p, %p)\n", display, config);) + /*if (g_display == NULL) { + g_display = XOpenDisplay(NULL); + }*/ + if (glx_default_depth==0) + glx_default_depth = XDefaultDepth(display, 0); + XVisualInfo *visual = (XVisualInfo *)malloc(sizeof(XVisualInfo)); + XMatchVisualInfo(display, 0, glx_default_depth, TrueColor, visual); + // maybe should use XGetVisualInfo(...) with config->associatedVisualId ? + return visual; +} + +GLXContext gl4es_glXCreateNewContext(Display *display, GLXFBConfig config, + int render_type, GLXContext share_list, + Bool is_direct) { + DBG(printf("glXCreateNewContext(%p, %p, %d, %p, %i), drawableType=0x%02X\n", display, config, render_type, share_list, is_direct, (config)?config->drawableType:0);) + if(render_type!=GLX_RGBA_TYPE) + return 0; + if(config && config->drawableType==GLX_PBUFFER_BIT) { + return createPBufferContext(display, share_list, config); + } else + return gl4es_glXCreateContextAttribsARB(display, config, share_list, is_direct, NULL); + //return glXCreateContext(display, 0, share_list, is_direct); +} +#endif //NOX11 + +void gl4es_glXSwapInterval(int interval) { + DBG(printf("glXSwapInterval(%i)\n", interval);) +#ifdef NOEGL + // nothing +#elif defined(NOX11) + LOAD_EGL(eglSwapInterval); + egl_eglSwapInterval(eglDisplay, swapinterval); +#elif defined(USE_FBIO) + if (! globals4es.vsync) { + static int warned = 0; + if(!warned) { + LOGD("LIBGL: Enable LIBGL_VSYNC=1 if you want to use vsync.\n"); + warned++; + } + } + swapinterval = interval; +#else + if(glxContext) { + LOAD_EGL(eglSwapInterval); + egl_eglSwapInterval(eglDisplay, swapinterval); + CheckEGLErrors(); + if(intervalmaxswap) { + SHUT(printf("LIBGL: Warning, Swap Interval %d is out of possible values %d, %d\n", interval, minswap, maxswap);) + } else + swapinterval = interval; + } else { + DBG(printf("LIBGL: glXSwapInterval called before Context is current.\n");) + swapinterval = interval; + } +#endif +} + +#ifndef NOX11 +void gl4es_glXSwapIntervalEXT(Display *display, int drawable, int interval) { + gl4es_glXSwapInterval(interval); +} + +// misc stubs +void gl4es_glXCopyContext(Display *display, GLXContext src, GLXContext dst, GLuint mask) { + DBG(printf("glXCopyContext(%p, %p, %p, %04X)\n", display, src, dst, mask);) + // mask is ignored for now, but should include glPushAttrib / glPopAttrib + memcpy(dst, src, sizeof(struct __GLXContextRec)); +} + +Window gl4es_glXCreateWindow(Display *display, GLXFBConfig config, Window win, int *attrib_list) { + // should return GLXWindow + DBG(printf("glXCreateWindow(%p, %p, %p, %p)\n", display, config, (void*)win, attrib_list);) + return win; +} +void gl4es_glXDestroyWindow(Display *display, void *win) { + // really wants a GLXWindow + DBG(printf("glXDestroyWindow(%p, %p)\n", display, win);) +} + +GLXDrawable gl4es_glXGetCurrentDrawable() { + DBG(printf("glXGetCurrentDrawable()\n");) + if (glxContext) + return glxContext->drawable; + else + return 0; +} // this should actually return GLXDrawable. + +Bool gl4es_glXIsDirect(Display * display, GLXContext ctx) { + DBG(printf("glXIsDirect(%p, %p)\n", display, ctx);) + return true; +} + +void gl4es_glXUseXFont(Font font, int first, int count, int listBase) { + DBG(printf("glXUseXFont(%p, %d, %d, %d)\n", (void*)font, first, count, listBase);) + /* Mostly from MesaGL-9.0.1 + * + */ + // First get current Display and Window + XFontStruct *fs; + unsigned int max_width, max_height, max_bm_width, max_bm_height; + Pixmap pixmap; + XGCValues values; + GC gc; + int i; + unsigned long valuemask; + GLubyte *bm; + Display *dpy; + Window win; + if (globals4es.usefb) { + dpy = g_display; + win = RootWindow(dpy, XDefaultScreen(dpy)); + } else { + dpy = glxContext->display; + win = glxContext->drawable; //TODO, check that drawable is a window and not a pixmap ? + } + + // Grab font params + fs = XQueryFont(dpy, font); + if (!fs) { + LOGE("LIBGL: error, no font set before call to glXUseFont\n"); + return; + } + max_width = fs->max_bounds.rbearing - fs->min_bounds.lbearing; + max_height = fs->max_bounds.ascent + fs->max_bounds.descent; + max_bm_width = (max_width + 7) / 8; + max_bm_height = max_height; + + bm = (GLubyte *)malloc((max_bm_width * max_bm_height) * sizeof(GLubyte)); + if (!bm) { + XFreeFontInfo(NULL, fs, 1); + return; + } + // Save GL texture parameters + GLint swapbytes, lsbfirst, rowlength; + GLint skiprows, skippixels, alignment; + gl4es_glGetIntegerv(GL_UNPACK_SWAP_BYTES, &swapbytes); + gl4es_glGetIntegerv(GL_UNPACK_LSB_FIRST, &lsbfirst); + gl4es_glGetIntegerv(GL_UNPACK_ROW_LENGTH, &rowlength); + gl4es_glGetIntegerv(GL_UNPACK_SKIP_ROWS, &skiprows); + gl4es_glGetIntegerv(GL_UNPACK_SKIP_PIXELS, &skippixels); + gl4es_glGetIntegerv(GL_UNPACK_ALIGNMENT, &alignment); + // Set Safe Texture params + gl4es_glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_FALSE); + gl4es_glPixelStorei(GL_UNPACK_LSB_FIRST, GL_FALSE); + gl4es_glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); + gl4es_glPixelStorei(GL_UNPACK_SKIP_ROWS, 0); + gl4es_glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0); + gl4es_glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + // Create GC and Pixmap + pixmap = XCreatePixmap(dpy, win, 10, 10, 1); + values.foreground = BlackPixel(dpy, DefaultScreen(dpy)); + values.background = WhitePixel(dpy, DefaultScreen(dpy)); + values.font = fs->fid; + valuemask = GCForeground | GCBackground | GCFont; + gc = XCreateGC(dpy, pixmap, valuemask, &values); + XFreePixmap(dpy, pixmap); + // Loop each chars + for (i = 0; i < count; i++) { + unsigned int width, height, bm_width, bm_height; + GLfloat x0, y0, dx, dy; + XCharStruct *ch; + int x, y; + unsigned int c = first + i; + int list = listBase + i; + int valid; + + /* check on index validity and get the bounds */ + ch = isvalid(fs, c); + if (!ch) { + ch = &fs->max_bounds; + valid = 0; + } + else { + valid = 1; + } + /* glBitmap()' parameters: + straight from the glXUseXFont(3) manpage. */ + width = ch->rbearing - ch->lbearing; + height = ch->ascent + ch->descent; + x0 = -ch->lbearing; + y0 = ch->descent - 1; + dx = ch->width; + dy = 0; + /* X11's starting point. */ + x = -ch->lbearing; + y = ch->ascent; + /* Round the width to a multiple of eight. We will use this also + for the pixmap for capturing the X11 font. This is slightly + inefficient, but it makes the OpenGL part real easy. */ + bm_width = (width + 7) / 8; + bm_height = height; + gl4es_glNewList(list, GL_COMPILE); + if (valid && (bm_width > 0) && (bm_height > 0)) { + + memset(bm, '\0', bm_width * bm_height); + fill_bitmap(dpy, win, gc, bm_width, bm_height, x, y, c, bm); + + gl4es_glBitmap(width, height, x0, y0, dx, dy, bm); + } + else { + gl4es_glBitmap(0, 0, 0.0, 0.0, dx, dy, NULL); + } + gl4es_glEndList(); + } + + // Free GC & Pixmap + free(bm); + XFreeFontInfo(NULL, fs, 1); + XFreeGC(dpy, gc); + + // Restore saved packing modes. + gl4es_glPixelStorei(GL_UNPACK_SWAP_BYTES, swapbytes); + gl4es_glPixelStorei(GL_UNPACK_LSB_FIRST, lsbfirst); + gl4es_glPixelStorei(GL_UNPACK_ROW_LENGTH, rowlength); + gl4es_glPixelStorei(GL_UNPACK_SKIP_ROWS, skiprows); + gl4es_glPixelStorei(GL_UNPACK_SKIP_PIXELS, skippixels); + gl4es_glPixelStorei(GL_UNPACK_ALIGNMENT, alignment); + // All done +} +#endif //NOX11 +void gl4es_glXWaitGL() {} +void gl4es_glXWaitX() {} +void gl4es_glXReleaseBuffersMESA() {} + +#ifndef NOX11 +/* TODO proper implementation */ +int gl4es_glXQueryDrawable(Display *dpy, GLXDrawable draw, int attribute, unsigned int *value) { + DBG(printf("glXQueryDrawable(%p, %p", dpy, (void*)draw);) + int pbuf=isPBuffer(draw); + if(pbuf) { + if(pbuffersize[pbuf-1].Type!=1) + pbuf = 0; // the drawable can be used + } + *value = 0; + int width = 800; + int height = 480; + if((attribute==GLX_WIDTH || attribute==GLX_HEIGHT)) { + // Get Window size and all... + EGLSurface surf= EGL_NO_SURFACE; + if(pbuf) { // PBuffer are not linked to the drawable... + surf = pbuffersize[pbuf-1].Surface; + } +#ifdef NO_EGL + else { + SharedEGLSurface_t* sharedsurf = RecycleGetSurface(draw); + if(sharedsurf) + surf=sharedsurf->surf; + } +#endif + if(surf!=EGL_NO_SURFACE) { + LOAD_EGL(eglQuerySurface); + EGLint tmp; + if(attribute==GLX_WIDTH) + if(egl_eglQuerySurface(eglDisplay, surf, EGL_WIDTH, &tmp)==EGL_TRUE) + width = tmp; + if(attribute==GLX_HEIGHT) + if(egl_eglQuerySurface(eglDisplay, surf, EGL_HEIGHT, &tmp)==EGL_TRUE) + height = tmp; + } +#ifndef NO_EGL + else { + unsigned int border, depth; + Window root; + int x, y; + XGetGeometry(dpy, draw, &root, &x, &y, &width, &height, &border, &depth); + } +#endif + } + switch(attribute) { + case GLX_WIDTH: + *value = width; + DBG(printf("(%d), GLX_WIDTH, %p = %d)\n", pbuf, value, *value);) + return 1; + case GLX_HEIGHT: + *value = height; + DBG(printf("(%d), GLX_HEIGHT, %p = %d)\n", pbuf, value, *value);) + return 1; + case GLX_PRESERVED_CONTENTS: + if(pbuf) *value = 1; + DBG(printf("(%d), GLX_PRESERVED_CONTENTS, %p = %d)\n", pbuf, value, *value);) + return 1; + case GLX_LARGEST_PBUFFER: + if(pbuf) *value = 0; + DBG(printf("(%d), GLX_LARGEST_PBUFFER, %p = %d)\n", pbuf, value, *value);) + return 1; + case GLX_FBCONFIG_ID: + *value = 0; + DBG(printf("(%d), GLX_FBCONFIG_ID, %p = %d)\n", pbuf, value, *value);) + return 1; + case GLX_SWAP_INTERVAL_EXT: + *value = swapinterval; + DBG(printf("(%d), GLX_SWAP_INTERVAL_EXT, %p = %d)\n", pbuf, value, *value);) + return 1; + case GLX_MAX_SWAP_INTERVAL_EXT: + *value = maxswap; // fake, should eglQuery the Config for EGL_MAX_SWAP_INTERVAL (and EGL_MIN_SWAP_INTERVAL) + DBG(printf("(%d), GLX_MAX_SWAP_INTERVAL_EXT, %p = %d)\n", pbuf, value, *value);) + return 1; + } + DBG(printf("(%d), %04x, %p)\n", pbuf, attribute, value);) + return 0; +} + +GLXPbuffer addPBuffer(EGLSurface surface, int Width, int Height, EGLContext Context, EGLConfig Config) +{ + if(pbufferlist_cap<=pbufferlist_size) { + pbufferlist_cap += 4; + pbufferlist = (GLXPbuffer*)realloc(pbufferlist, sizeof(GLXPbuffer)*pbufferlist_cap); + pbuffersize = (glx_buffSize*)realloc(pbuffersize, sizeof(glx_buffSize)*pbufferlist_cap); + } + pbufferlist[pbufferlist_size] = (GLXPbuffer)surface; + pbuffersize[pbufferlist_size].Width = Width; + pbuffersize[pbufferlist_size].Height = Height; + pbuffersize[pbufferlist_size].Context = Context; + pbuffersize[pbufferlist_size].Surface = surface; + pbuffersize[pbufferlist_size].Config = Config; + pbuffersize[pbufferlist_size].gc = NULL; + pbuffersize[pbufferlist_size].Type = 1; // 1 = pbuffer + return pbufferlist[pbufferlist_size++]; +} +void delPBuffer(int j) +{ + LOAD_EGL(eglDestroyContext); + pbufferlist[j] = 0; + pbuffersize[j].Width = 0; + pbuffersize[j].Height = 0; + pbuffersize[j].gc = 0; + egl_eglDestroyContext(eglDisplay, pbuffersize[j].Context); + CheckEGLErrors(); + // should pack, but I think it's useless for common use +} + +void gl4es_glXDestroyPbuffer(Display * dpy, GLXPbuffer pbuf) { + DBG(printf("glxDestroyPBuffer(%p, %p)\n", dpy, (void*)pbuf);) + LOAD_EGL(eglDestroySurface); + int j=0; + while(jdrawableType&GLX_PBUFFER_BIT!=GLX_PBUFFER_BIT) + return 0; + + + if(createPBuffer(dpy, egl_attribs, &Surface, &Context, Config, config->redBits, config->greenBits, config->blueBits, config->alphaBits, config->nMultiSampleBuffers, config->multiSampleSize)==0) { + return 0; + } + + int Width, Height; + + egl_eglQuerySurface(eglDisplay,Surface,EGL_WIDTH,&Width); + egl_eglQuerySurface(eglDisplay,Surface,EGL_HEIGHT,&Height); + + return addPBuffer(Surface, Width, Height, Context, Config[1]); +} + +GLXPbuffer addPixBuffer(Display *dpy, EGLSurface surface, EGLConfig Config, int Width, int Height, EGLContext Context, Pixmap pixmap, int depth, int emulated) +{ + if(pbufferlist_cap<=pbufferlist_size) { + pbufferlist_cap += 4; + pbufferlist = (GLXPbuffer*)realloc(pbufferlist, sizeof(GLXPbuffer)*pbufferlist_cap); + pbuffersize = (glx_buffSize*)realloc(pbuffersize, sizeof(glx_buffSize)*pbufferlist_cap); + } + pbufferlist[pbufferlist_size] = (GLXPbuffer)pixmap; + pbuffersize[pbufferlist_size].Width = Width; + pbuffersize[pbufferlist_size].Height = Height; + pbuffersize[pbufferlist_size].Context = Context; + pbuffersize[pbufferlist_size].Surface = surface; + pbuffersize[pbufferlist_size].Config = Config; + pbuffersize[pbufferlist_size].Depth = depth; + pbuffersize[pbufferlist_size].dpy = dpy; + pbuffersize[pbufferlist_size].gc = (emulated)?XCreateGC(dpy, pixmap, 0, NULL):NULL; + pbuffersize[pbufferlist_size].frame = NULL; + + pbuffersize[pbufferlist_size].Type = 2+emulated; //2 = pixmap, 3 = emulated pixmap, 4 = emulated win + return pbufferlist[pbufferlist_size++]; +} +void delPixBuffer(int j) +{ + LOAD_EGL(eglDestroyContext); + if(pbuffersize[j].gc) + XFree(pbuffersize[j].gc); + if(pbuffersize[j].frame) { + XDestroyImage(pbuffersize[j].frame); + } + pbufferlist[j] = 0; + pbuffersize[j].Width = 0; + pbuffersize[j].Height = 0; + pbuffersize[j].Depth = 0; + pbuffersize[j].dpy = 0; + pbuffersize[j].gc = 0; + pbuffersize[j].Surface = 0; + egl_eglDestroyContext(eglDisplay, pbuffersize[j].Context); + CheckEGLErrors(); + // should pack, but I think it's useless for common use +} + +int createPixBuffer(Display * dpy, int bpp, const EGLint * egl_attribs, NativePixmapType nativepixmap, EGLSurface* Surface, EGLContext* Context) { + LOAD_EGL(eglChooseConfig); + LOAD_EGL(eglCreatePixmapSurface); + LOAD_EGL(eglCreateContext); + + EGLint configAttribs[] = { + EGL_RED_SIZE, (bpp>16)?8:5, + EGL_GREEN_SIZE, (bpp==15)?5:(bpp>16)?8:6, + EGL_BLUE_SIZE, (bpp>16)?8:5, + EGL_ALPHA_SIZE, (bpp==32)?8:0, + EGL_DEPTH_SIZE, 1, // some depth + EGL_STENCIL_SIZE, 1, // some stencil too + EGL_SURFACE_TYPE, EGL_PIXMAP_BIT, + EGL_RENDERABLE_TYPE, (hardext.esversion==1)?EGL_OPENGL_ES_BIT:EGL_OPENGL_ES2_BIT, + EGL_NONE + }; + + // Init what need to be done + EGLBoolean result; + if (eglDisplay == NULL || eglDisplay == EGL_NO_DISPLAY) { + init_display((globals4es.usefb || globals4es.usepbuffer)?g_display:dpy); + if (eglDisplay == EGL_NO_DISPLAY) { + CheckEGLErrors(); + LOGE("LIBGL: Unable to create EGL display.\n"); + return 0; + } + } + + // first time? + if (eglInitialized == false) { + result = InitEGL((globals4es.usefb || globals4es.usepbuffer)?g_display:dpy); + if (!result) { + CheckEGLErrors(); + LOGE("LIBGL: Unable to initialize EGL display.\n"); + return 0; + } + } + + // select a configuration + int configsFound; + static EGLConfig pixbufConfigs[1]; + result = egl_eglChooseConfig(eglDisplay, configAttribs, pixbufConfigs, 1, &configsFound); + + CheckEGLErrors(); + if (result != EGL_TRUE || configsFound == 0) { + LOGE("LIBGL: No EGL configs found.\n"); + return 0; + } + + // now, create the PixmapSurface + (*Surface) = egl_eglCreatePixmapSurface(eglDisplay, pixbufConfigs[0], nativepixmap,egl_attribs); + + if((*Surface)==EGL_NO_SURFACE) { + CheckEGLErrors(); + LOGE("LIBGL: Error creating PixmapSurface\n"); + return 0; + } + + (*Context) = egl_eglCreateContext(eglDisplay, pixbufConfigs[0], EGL_NO_CONTEXT, (hardext.esversion==1)?egl_context_attrib:egl_context_attrib_es2); + CheckEGLErrors(); + + return 1; +} + +GLXPixmap gl4es_glXCreateGLXPixmap(Display *display, XVisualInfo * visual, Pixmap pixmap) { + DBG(printf("glXCreateGLXPixmap(%p, %p, %p)\n", display, visual, (void*)pixmap);) + LOAD_EGL(eglQuerySurface); + + EGLSurface Surface = 0; + EGLContext Context = 0; + EGLConfig Config[1] = {0}; + //first, analyse PixMap to get it's dimensions and color depth... + unsigned int width, height, border, depth; + Window root; + int x, y; + int emulated = 0; + XGetGeometry(display, pixmap, &root, &x, &y, &width, &height, &border, &depth); + // let's try to create a PixmapSurface directly + if(globals4es.usefb || createPixBuffer(display, depth, NULL, (NativePixmapType)pixmap, &Surface, &Context)==0) { + // fail, so emulate with a PBuffer + SHUT(LOGE("LIBGL: Pixmap creation failed, trying PBuffer instead\n")); + //let's create a PixBuffer attributes + EGLint egl_attribs[10]; // should be enough + int i = 0; + egl_attribs[i++] = EGL_WIDTH; + egl_attribs[i++] = width; + egl_attribs[i++] = EGL_HEIGHT; + egl_attribs[i++] = height; + egl_attribs[i++] = EGL_NONE; + + if(createPBuffer(display, egl_attribs, &Surface, &Context, Config, (depth>16)?8:5, (depth==15)?5:(depth>16)?8:6, (depth>16)?8:5, (depth==32)?8:0, 0, 0)==0) { + // fail too, abort + SHUT(LOGE("LIBGL: PBuffer creation failed too\n")); + return 0; + } + emulated = 1; + + } + int Width, Height; + + egl_eglQuerySurface(eglDisplay,Surface,EGL_WIDTH,&Width); + egl_eglQuerySurface(eglDisplay,Surface,EGL_HEIGHT,&Height); + + return addPixBuffer(display, Surface, Config[0], Width, Height, Context, pixmap, depth, emulated); +} + +GLXPixmap gl4es_glXCreatePixmap(Display * dpy, GLXFBConfig config, Pixmap pixmap, const int * attrib_list) { + DBG(printf("glXCreatePixmap(%p, %p, %p, %p)\n", dpy, config, (void*)pixmap, attrib_list);) + // Check that the config is for PBuffer + if(config->drawableType&GLX_PIXMAP_BIT!=GLX_PIXMAP_BIT) + return 0; + + return gl4es_glXCreateGLXPixmap(dpy, NULL, pixmap); +} + + +void gl4es_glXDestroyGLXPixmap(Display *display, void *pixmap) { + DBG(printf("glXDestroyGLXPixmap(%p, %p)\n", display, pixmap);) + LOAD_EGL(eglDestroySurface); + int j=0; + while(j>(3)) | ((GLushort)(((char*)src_pos)[1]&0xfc)<<(5-2)) | ((GLushort)(((char*)src_pos)[2]&0xf8)<<(11-3)); + src_pos += 4; + dst_pos += 2; + } + dst_pos -= 2*stride; + } + } else + pixel_convert(tmp, (void**)&pix, Width, Height, GL_BGRA, GL_UNSIGNED_BYTE, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, 0, glstate->texture.unpack_align); + } else +#endif + if(reverse) { + int stride = Width * (Depth==16?2:4); + uintptr_t end=(uintptr_t)pix+sbuf-stride; + uintptr_t beg=(uintptr_t)pix; + void* const tmp = (void*)(pix+sbuf); + for (; beg < end; beg+=stride, end-=stride) { + memcpy(tmp, (void*)end, stride); + memcpy((void*)end, (void*)beg, stride); + memcpy((void*)beg, tmp, stride); + } + } + + // blit + XPutImage(dpy, drawable, gc, frame, 0, 0, 0, 0, Width, Height); +} + +void BlitEmulatedPixmap() { + if(!glstate->emulatedPixmap) + return; + + Pixmap drawable = (Pixmap)pbufferlist[glstate->emulatedPixmap-1]; + + glx_buffSize *buff = &pbuffersize[glstate->emulatedPixmap-1]; + + int Width = buff->Width; + int Height = buff->Height; + int Depth = buff->Depth; + Display *dpy = buff->dpy; + GC gc = buff->gc; + // the reverse stuff can probably be better! + int reverse = buff->Type==4?1:0; + const int sbuf = Width * Height * (Depth==16?2:4); + XImage* frame = buff->frame; + + // grab the size of the drawable if it has changed + if(reverse) { + // Get Window size and all... + unsigned int width, height, border, depth; + Window root; + int x, y; + XGetGeometry(dpy, drawable, &root, &x, &y, &width, &height, &border, &depth); + if(width!=Width || height!=Height /*|| depth!=Depth*/) { + LOAD_EGL(eglDestroySurface); + LOAD_EGL(eglMakeCurrent); + LOAD_EGL(eglCreatePbufferSurface); + // destroy old stuff + XSync(dpy, False); // synch seems needed before the DestroyImage... + if(frame) XDestroyImage(frame); + buff->frame = 0; + + + //let's create a PBuffer attributes + EGLint egl_attribs[10]; // should be enough + int i = 0; + egl_attribs[i++] = EGL_WIDTH; + egl_attribs[i++] = width; + egl_attribs[i++] = EGL_HEIGHT; + egl_attribs[i++] = height; + egl_attribs[i++] = EGL_NONE; + + DBG(printf("LIBGL: Recreate PBuffer %dx%dx%d => %dx%dx%d\n", Width, Height, Depth, width, height, depth);) + + egl_eglMakeCurrent(eglDisplay, NULL, NULL, EGL_NO_CONTEXT); + egl_eglDestroySurface(eglDisplay, buff->Surface); + CheckEGLErrors(); + + EGLSurface Surface = NULL; + Surface = egl_eglCreatePbufferSurface(eglDisplay, buff->Config, egl_attribs); + if(Surface==EGL_NO_SURFACE) + LOGE("LIBGL: Warning, Recration of pbuffer failed (from %dx%dx%d => %dx%dx%d)\n", buff->Width, buff->Height, buff->Depth, width, height, depth); + CheckEGLErrors(); + egl_eglMakeCurrent(eglDisplay, Surface, Surface, buff->Context); + CheckEGLErrors(); + glxContext->eglSurface = buff->Surface = Surface; + buff->Width = width; + buff->Height = height; + //buff->Depth = depth; + return; + } + } + + // create things if needed + if(!buff->frame) { + int sz = Width*(Height+reverse)*(Depth==16?2:4); +#ifdef PANDORA + if(hardext.esversion==1 && Depth==16) { + sz += Width*Height*4; + } +#endif + buff->frame = XCreateImage(dpy, NULL /*visual*/, Depth, ZPixmap, 0, malloc(sz), Width, Height, (Depth==16)?16:32, 0); + } + + if (!frame) { + return; + } + uintptr_t pix=(uintptr_t)frame->data; + + // grab framebuffer + void* tmp = NULL; +#ifdef PANDORA + LOAD_GLES(glReadPixels); + if(hardext.esversion==1) { + if(Depth==16) { + tmp = (void*)(pix + Width*Height*2); + gles_glReadPixels(0, 0, Width, Height, GL_BGRA, GL_UNSIGNED_BYTE, tmp); + } else { + gles_glReadPixels(0, 0, Width, Height, GL_BGRA, GL_UNSIGNED_BYTE, (void*)pix); + } + } else + if(Depth==16) + gles_glReadPixels(0, 0, Width, Height, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, (void*)pix); + else +#endif + gl4es_glReadPixels(0, 0, Width, Height, (Depth==16)?GL_RGB:GL_BGRA, (Depth==16)?GL_UNSIGNED_SHORT_5_6_5:GL_UNSIGNED_BYTE, (void*)pix); + + actualBlit(reverse, Width, Height, Depth, dpy, drawable, gc, frame, pix, tmp); + +} + +GLXContext gl4es_glXCreateContextAttribs(Display *dpy, GLXFBConfig config, GLXContext share_context, Bool direct, const int *attrib_list) { + DBG(printf("glXCreateContextAttribs(%p, %p, %p, %d, %p)\n", dpy, config, share_context, direct, attrib_list);) + int ask_es = 0; + int ask_shaders = 0; + int majver = 0, minver = 0; + int flags = 0; + int mask = 0; + const int *attr = attrib_list; + while (attr && (*attr)!= 0) { + int name = (*(attr++)); + int pair = (*(attr++)); + switch(name) { + case GLX_CONTEXT_MAJOR_VERSION_ARB: + majver = pair; + break; + case GLX_CONTEXT_MINOR_VERSION_ARB: + minver = pair; + break; + case GLX_CONTEXT_FLAGS_ARB: + flags = pair; + break; + case GLX_CONTEXT_PROFILE_MASK_ARB: + mask = pair; + break; + default: { + DBG(printf(" unknow Attrib %04X (value=%d)\n", name, pair);) + } + } + } + if(majver*10+minver != 0) { + DBG(printf(" Required context version %d.%d\n", majver, minver);) + if(majver*10+minver>21) { + LOGE("LIBGL: Asked for unsupported context version %d.%d\n", majver, minver); + return 0; + } + if(majver*10+minver>globals4es.gl) { + LOGE("LIBGL: Asked for unsupported context version %d.%d (max version is %d.%d)\n", majver, minver, globals4es.gl/10, globals4es.gl%10); + return 0; + } + if((mask&GLX_CONTEXT_ES2_PROFILE_BIT_EXT) && hardext.esversion<2) { + LOGE("LIBGL: Asked for ES2 compatible context on GLES1.1 Backend\n"); + return 0; + } + } + if(mask&GLX_CONTEXT_ES2_PROFILE_BIT_EXT) + globales2 = 1; + GLXContext context = gl4es_glXCreateNewContext(dpy, config, GLX_RGBA_TYPE, share_context, direct); + globales2 = 0; + return context; +} + +#endif //NOX11 + +// New export the Alias +#ifndef NOX11 +GLXContext glXCreateContext(Display *display, XVisualInfo *visual, GLXContext shareList, Bool isDirect) AliasExport("gl4es_glXCreateContext"); +GLXContext glXCreateContextAttribsARB(Display *display, GLXFBConfig config, GLXContext share_context, Bool direct, const int *attrib_list) AliasExport("gl4es_glXCreateContextAttribsARB"); +void glXDestroyContext(Display *display, GLXContext ctx) AliasExport("gl4es_glXDestroyContext"); +Display *glXGetCurrentDisplay() AliasExport("gl4es_glXGetCurrentDisplay"); +XVisualInfo *glXChooseVisual(Display *display, int screen, int *attributes) AliasExport("gl4es_glXChooseVisual"); +Bool glXMakeCurrent(Display *display, GLXDrawable drawable, GLXContext context) AliasExport("gl4es_glXMakeCurrent"); +Bool glXMakeContextCurrent(Display *display, int drawable, int readable, GLXContext context) AliasExport("gl4es_glXMakeContextCurrent"); +void glXSwapBuffers(Display *display, GLXDrawable drawable) AliasExport("gl4es_glXSwapBuffers"); +int glXGetConfig(Display *display, XVisualInfo *visual, int attribute, int *value) AliasExport("gl4es_glXGetConfig"); +const char *glXQueryExtensionsString(Display *display, int screen) AliasExport("gl4es_glXQueryExtensionsString"); +const char *glXQueryServerString(Display *display, int screen, int name) AliasExport("gl4es_glXQueryServerString"); +Bool glXQueryExtension(Display *display, int *errorBase, int *eventBase) AliasExport("gl4es_glXQueryExtension"); +Bool glXQueryVersion(Display *display, int *major, int *minor) AliasExport("gl4es_glXQueryVersion"); +const char *glXGetClientString(Display *display, int name) AliasExport("gl4es_glXGetClientString"); +int glXQueryContext( Display *dpy, GLXContext ctx, int attribute, int *value) AliasExport("gl4es_glXQueryContext"); +GLXContext glXGetCurrentContext() AliasExport("gl4es_glXGetCurrentContext"); +GLXFBConfig *glXChooseFBConfig(Display *display, int screen, const int *attrib_list, int *count) AliasExport("gl4es_glXChooseFBConfig"); +GLXFBConfig *glXChooseFBConfigSGIX(Display *display, int screen, const int *attrib_list, int *count) AliasExport("gl4es_glXChooseFBConfig"); +GLXFBConfig *glXGetFBConfigs(Display *display, int screen, int *count) AliasExport("gl4es_glXGetFBConfigs"); +int glXGetFBConfigAttrib(Display *display, GLXFBConfig config, int attribute, int *value) AliasExport("gl4es_glXGetFBConfigAttrib"); +XVisualInfo *glXGetVisualFromFBConfig(Display *display, GLXFBConfig config) AliasExport("gl4es_glXGetVisualFromFBConfig"); +GLXContext glXCreateNewContext(Display *display, GLXFBConfig config, int render_type, GLXContext share_list, Bool is_direct) AliasExport("gl4es_glXCreateNewContext"); +void glXSwapIntervalEXT(Display *display, int drawable, int interval) AliasExport("gl4es_glXSwapIntervalEXT"); +void glXCopyContext(Display *display, GLXContext src, GLXContext dst, GLuint mask) AliasExport("gl4es_glXCopyContext"); +Window glXCreateWindow(Display *display, GLXFBConfig config, Window win, int *attrib_list) AliasExport("gl4es_glXCreateWindow"); +void glXDestroyWindow(Display *display, void *win) AliasExport("gl4es_glXDestroyWindow"); +GLXDrawable glXGetCurrentDrawable() AliasExport("gl4es_glXGetCurrentDrawable"); +Bool glXIsDirect(Display * display, GLXContext ctx) AliasExport("gl4es_glXIsDirect"); +void glXUseXFont(Font font, int first, int count, int listBase) AliasExport("gl4es_glXUseXFont"); +int glXQueryDrawable(Display *dpy, GLXDrawable draw, int attribute, unsigned int *value) AliasExport("gl4es_glXQueryDrawable"); +void glXDestroyPbuffer(Display * dpy, GLXPbuffer pbuf) AliasExport("gl4es_glXDestroyPbuffer"); +GLXPbuffer glXCreatePbuffer(Display * dpy, GLXFBConfig config, const int * attrib_list) AliasExport("gl4es_glXCreatePbuffer"); +GLXPixmap glXCreateGLXPixmap(Display *display, XVisualInfo * visual, Pixmap pixmap) AliasExport("gl4es_glXCreateGLXPixmap"); +GLXPixmap glXCreatePixmap(Display * dpy, GLXFBConfig config, Pixmap pixmap, const int * attrib_list) AliasExport("gl4es_glXCreatePixmap"); +void glXDestroyGLXPixmap(Display *display, void *pixmap) AliasExport("gl4es_glXDestroyGLXPixmap"); +void glXDestroyPixmap(Display *display, void *pixmap) AliasExport("gl4es_glXDestroyPixmap"); +GLXContext glXCreateContextAttribs(Display *dpy, GLXFBConfig config, GLXContext share_context, Bool direct, const int *attrib_list) AliasExport("gl4es_glXCreateContextAttribs"); +#endif + +void glXSwapInterval(int interval) AliasExport("gl4es_glXSwapInterval"); +void glXSwapIntervalMESA(int interval) AliasExport("gl4es_glXSwapInterval"); +void glXSwapIntervalSGI(int interval) AliasExport("gl4es_glXSwapInterval"); + +void glXWaitGL() AliasExport("gl4es_glXWaitGL"); +void glXWaitX() AliasExport("gl4es_glXWaitX"); +void glXReleaseBuffersMESA() AliasExport("gl4es_glXReleaseBuffersMESA"); diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/glx/glx.h b/Projects/Android/jni/SupportLibs/gl4es/src/glx/glx.h new file mode 100644 index 0000000..4db53a1 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/glx/glx.h @@ -0,0 +1,305 @@ +#ifndef _GLX_GLX_H_ +#define _GLX_GLX_H_ + +#ifndef NOEGL +#include +#endif +#include +#include +#ifndef NOX11 +#include +#include +#endif +#include +#include + +#include "../gl/gl4es.h" + +// defines yoinked from Mesa glx.h +#define GLX_VERSION_1_1 1 +#define GLX_VERSION_1_2 1 +#define GLX_VERSION_1_3 1 +#define GLX_VERSION_1_4 1 + +#define GLX_EXTENSION_NAME "GLX" + +/* + * Tokens for glXChooseVisual and glXGetConfig: + */ +#define GLX_USE_GL 1 +#define GLX_BUFFER_SIZE 2 +#define GLX_LEVEL 3 +#define GLX_RGBA 4 +#define GLX_DOUBLEBUFFER 5 +#define GLX_STEREO 6 +#define GLX_AUX_BUFFERS 7 +#define GLX_RED_SIZE 8 +#define GLX_GREEN_SIZE 9 +#define GLX_BLUE_SIZE 10 +#define GLX_ALPHA_SIZE 11 +#define GLX_DEPTH_SIZE 12 +#define GLX_STENCIL_SIZE 13 +#define GLX_ACCUM_RED_SIZE 14 +#define GLX_ACCUM_GREEN_SIZE 15 +#define GLX_ACCUM_BLUE_SIZE 16 +#define GLX_ACCUM_ALPHA_SIZE 17 + +/* + * Error codes returned by glXGetConfig: + */ +#define GLX_BAD_SCREEN 1 +#define GLX_BAD_ATTRIBUTE 2 +#define GLX_NO_EXTENSION 3 +#define GLX_BAD_VISUAL 4 +#define GLX_BAD_CONTEXT 5 +#define GLX_BAD_VALUE 6 +#define GLX_BAD_ENUM 7 + +/* + * GLX 1.1 and later: + */ +#define GLX_VENDOR 1 +#define GLX_VERSION 2 +#define GLX_EXTENSIONS 3 + +/* + * GLX 1.3 and later: + */ +#define GLX_CONFIG_CAVEAT 0x20 +#define GLX_DONT_CARE 0xFFFFFFFF +#define GLX_X_VISUAL_TYPE 0x22 +#define GLX_TRANSPARENT_TYPE 0x23 +#define GLX_TRANSPARENT_INDEX_VALUE 0x24 +#define GLX_TRANSPARENT_RED_VALUE 0x25 +#define GLX_TRANSPARENT_GREEN_VALUE 0x26 +#define GLX_TRANSPARENT_BLUE_VALUE 0x27 +#define GLX_TRANSPARENT_ALPHA_VALUE 0x28 +#define GLX_WINDOW_BIT 0x00000001 +#define GLX_PIXMAP_BIT 0x00000002 +#define GLX_PBUFFER_BIT 0x00000004 +#define GLX_AUX_BUFFERS_BIT 0x00000010 +#define GLX_FRONT_LEFT_BUFFER_BIT 0x00000001 +#define GLX_FRONT_RIGHT_BUFFER_BIT 0x00000002 +#define GLX_BACK_LEFT_BUFFER_BIT 0x00000004 +#define GLX_BACK_RIGHT_BUFFER_BIT 0x00000008 +#define GLX_DEPTH_BUFFER_BIT 0x00000020 +#define GLX_STENCIL_BUFFER_BIT 0x00000040 +#define GLX_ACCUM_BUFFER_BIT 0x00000080 +#define GLX_NONE 0x8000 +#define GLX_SLOW_CONFIG 0x8001 +#define GLX_TRUE_COLOR 0x8002 +#define GLX_DIRECT_COLOR 0x8003 +#define GLX_PSEUDO_COLOR 0x8004 +#define GLX_STATIC_COLOR 0x8005 +#define GLX_GRAY_SCALE 0x8006 +#define GLX_STATIC_GRAY 0x8007 +#define GLX_TRANSPARENT_RGB 0x8008 +#define GLX_TRANSPARENT_INDEX 0x8009 +#define GLX_VISUAL_ID 0x800B +#define GLX_SCREEN 0x800C +#define GLX_NON_CONFORMANT_CONFIG 0x800D +#define GLX_DRAWABLE_TYPE 0x8010 +#define GLX_RENDER_TYPE 0x8011 +#define GLX_X_RENDERABLE 0x8012 +#define GLX_FBCONFIG_ID 0x8013 +#define GLX_RGBA_TYPE 0x8014 +#define GLX_COLOR_INDEX_TYPE 0x8015 +#define GLX_MAX_PBUFFER_WIDTH 0x8016 +#define GLX_MAX_PBUFFER_HEIGHT 0x8017 +#define GLX_MAX_PBUFFER_PIXELS 0x8018 +#define GLX_PRESERVED_CONTENTS 0x801B +#define GLX_LARGEST_PBUFFER 0x801C +#define GLX_WIDTH 0x801D +#define GLX_HEIGHT 0x801E +#define GLX_EVENT_MASK 0x801F +#define GLX_DAMAGED 0x8020 +#define GLX_SAVED 0x8021 +#define GLX_WINDOW 0x8022 +#define GLX_PBUFFER 0x8023 +#define GLX_PBUFFER_HEIGHT 0x8040 +#define GLX_PBUFFER_WIDTH 0x8041 +#define GLX_RGBA_BIT 0x00000001 +#define GLX_COLOR_INDEX_BIT 0x00000002 +#define GLX_PBUFFER_CLOBBER_MASK 0x08000000 + +/* + * GLX 1.4 and later: + */ +#define GLX_SAMPLE_BUFFERS 0x186a0 /*100000*/ +#define GLX_SAMPLES 0x186a1 /*100001*/ + +#define GLX_FRAMEBUFFER_SRGB_CAPABLE_ARB 0x20B2 + +#define GLX_SWAP_INTERVAL_EXT 0x20F1 +#define GLX_MAX_SWAP_INTERVAL_EXT 0x20F2 + +#define GLX_CONTEXT_MAJOR_VERSION_ARB 0x2091 +#define GLX_CONTEXT_MINOR_VERSION_ARB 0x2092 +#define GLX_CONTEXT_FLAGS_ARB 0x2094 +#define GLX_CONTEXT_PROFILE_MASK_ARB 0x9126 +#define GLX_CONTEXT_DEBUG_BIT_ARB 0x0001 +#define GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB 0x0002 +#define GLX_CONTEXT_CORE_PROFILE_BIT_ARB 0x00000001 +#define GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB 0x00000002 +#define GLX_CONTEXT_ES_PROFILE_BIT_EXT 0x00000004 +#define GLX_CONTEXT_ES2_PROFILE_BIT_EXT 0x00000004 + +#ifdef NOX11 +typedef int GLXDrawable; // need 64 / 32bits difs. +#else +typedef XID GLXDrawable; +#endif +#ifndef NOX11 +struct __GLXContextRec { + Display *display; + GLXDrawable drawable; + unsigned char direct; + int currentWritable; + int currentReadable; + XID xid; + EGLSurface eglSurface; + EGLConfig eglConfigs[64]; + int eglconfigIdx; + EGLContext eglContext; + int samples; + int samplebuffers; + int depth; + int stencil; + int rbits, gbits, bbits, abits; + int es2only; + int doublebuff; + void* glstate; + void* shared; + int* shared_eglsurface; + void* nativewin; + int contextType; // 0 = Window, 1 = PBuffer, 2 = PixmapBuffer, 3 = Emulated PixmapBuffer (with PBuffer) +}; +typedef struct __GLXContextRec *GLXContext; + +typedef XID GLXPbuffer; +typedef XID GLXPixmap; +#endif //NOX11 +struct __GLXFBConfigRec { + int visualType; + int transparentType; + /* colors are floats scaled to ints */ + int transparentRed, transparentGreen, transparentBlue, transparentAlpha; + int transparentIndex; + + int visualCaveat; + + int associatedVisualId; + int screen; + + int drawableType; + int renderType; + + int maxPbufferWidth, maxPbufferHeight, maxPbufferPixels; + int optimalPbufferWidth, optimalPbufferHeight; /* for SGIX_pbuffer */ + + int visualSelectGroup; /* visuals grouped by select priority */ +#ifndef NOEGL + EGLConfig id; +#else + int id; +#endif + unsigned char rgbMode; + unsigned char colorIndexMode; + unsigned char doubleBufferMode; + unsigned char stereoMode; + unsigned char haveAccumBuffer; + unsigned char haveDepthBuffer; + unsigned char haveStencilBuffer; + + /* The number of bits present in various buffers */ + int accumRedBits, accumGreenBits, accumBlueBits, accumAlphaBits; + int depthBits; + int stencilBits; + int indexBits; + int redBits, greenBits, blueBits, alphaBits; + unsigned int redMask, greenMask, blueMask, alphaMask; + + unsigned int multiSampleSize; /* Number of samples per pixel (0 if no ms) */ + + unsigned int nMultiSampleBuffers; /* Number of availble ms buffers */ + int maxAuxBuffers; + + /* frame buffer level */ + int level; + + /* color ranges (for SGI_color_range) */ + unsigned char extendedRange; + double minRed, maxRed; + double minGreen, maxGreen; + double minBlue, maxBlue; + double minAlpha, maxAlpha; +}; +typedef struct __GLXFBConfigRec *GLXFBConfig; +#ifndef NOX11 +GLXContext gl4es_glXCreateContext(Display *dpy, + XVisualInfo *visual, + GLXContext shareList, + Bool direct); + +GLXContext gl4es_glXCreateContextAttribsARB(Display *display, GLXFBConfig config, + GLXContext share_context, Bool direct, + const int *attrib_list); + +void gl4es_glXSwapIntervalEXT(Display *display, int drawable, int interval); +#endif //NOX11 +void gl4es_glXSwapInterval(int interval); + +// GLX 1.1? +#ifndef NOX11 +Bool gl4es_glXIsDirect(Display * display, GLXContext ctx); +Bool gl4es_glXMakeCurrent(Display *display, GLXDrawable drawable, GLXContext context); +Bool gl4es_glXQueryExtension(Display *display, int *errorBase, int *eventBase); +Bool gl4es_glXQueryVersion(Display *display, int *major, int *minor); +const char *gl4es_glXGetClientString(Display *display, int name); +const char *gl4es_glXQueryExtensionsString(Display *display, int screen); +const char *gl4es_glXQueryServerString(Display *display, int screen, int name); +#endif //NOX11 +GLXDrawable gl4es_glXGetCurrentDrawable(); +#ifndef NOX11 +int gl4es_glXGetConfig(Display *display, XVisualInfo *visual, int attribute, int *value); +void gl4es_glXCopyContext(Display *display, GLXContext src, GLXContext dst, GLuint mask); +void gl4es_glXDestroyContext(Display *display, GLXContext ctx); +void gl4es_glXSwapBuffers(Display *display, GLXDrawable drawable); +void gl4es_glXUseXFont(Font font, int first, int count, int listBase); +#endif //NOX11 +void gl4es_glXWaitGL(); +void gl4es_glXWaitX(); +#ifndef NOX11 +XVisualInfo *gl4es_glXChooseVisual(Display *display, int screen, int *attributes); +int gl4es_glXQueryDrawable(Display *dpy, GLXDrawable draw, int attribute, unsigned int *value); + +// GLX 1.2 +Display *gl4es_glXGetCurrentDisplay(); + +// GLX 1.3 +GLXContext gl4es_glXGetCurrentContext(); +XVisualInfo *gl4es_glXGetVisualFromFBConfig(Display *display, GLXFBConfig config); +GLXFBConfig *gl4es_glXChooseFBConfig(Display *display, int screen, const int *attrib_list, int *count); +GLXFBConfig *gl4es_glXGetFBConfigs(Display *display, int screen, int *count); +int gl4es_glXGetFBConfigAttrib(Display *display, GLXFBConfig config, int attribute, int *value); +int gl4es_glXQueryContext(Display *display, GLXContext ctx, int attribute, int *value); +GLXFBConfig *gl4es_glXChooseFBConfigSGIX(Display *display, int screen, const int *attrib_list, int *count); + +Window gl4es_glXCreateWindow(Display *display, GLXFBConfig config, Window win, int *attrib_list); +void gl4es_glXDestroyWindow(Display *display, void *win); + +Bool gl4es_glXMakeContextCurrent(Display *display, int drawable, int readable, GLXContext context); +GLXContext gl4es_glXCreateNewContext(Display *display, GLXFBConfig config, int render_type, GLXContext share_list, Bool is_direct); + +void gl4es_glXDestroyPbuffer(Display * dpy, GLXPbuffer pbuf); +GLXPbuffer gl4es_glXCreatePbuffer(Display * dpy, GLXFBConfig config, const int * attrib_list); + +GLXPixmap gl4es_glXCreatePixmap(Display * dpy, GLXFBConfig config, Pixmap pixmap, const int * attrib_list); +void gl4es_glXDestroyPixmap(Display *display, void *pixmap); +GLXPixmap gl4es_glXCreateGLXPixmap(Display *display, XVisualInfo * visual, Pixmap pixmap); +void gl4es_glXDestroyGLXPixmap(Display *display, void *pixmap); + +GLXContext gl4es_glXCreateContextAttribs(Display *dpy, GLXFBConfig config, GLXContext share_context, Bool direct, const int *attrib_list); +#endif // NOX11 + +#endif // _GLX_GLX_H diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/glx/glx_gbm.h b/Projects/Android/jni/SupportLibs/gl4es/src/glx/glx_gbm.h new file mode 100644 index 0000000..444c321 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/glx/glx_gbm.h @@ -0,0 +1,20 @@ +#ifndef _GLX_GBM_H_ +#define _GLX_GBM_H_ + +#ifndef NOEGL +#include +#endif + +void LoadGBMFunctions(); +void CloseGBMFunctions(); + +void* OpenGBMDisplay(void* display); + +void* CreateGBMWindow(int w, int h); +void DeleteGBMWindow(void* win); + +#if !defined(NOEGL) && !defined(ANDROID) +int FindGBMConfig(EGLConfig *configs, int numFounds); +#endif + +#endif // _GLX_GBM_H_ diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/glx/hardext.c b/Projects/Android/jni/SupportLibs/gl4es/src/glx/hardext.c new file mode 100644 index 0000000..197938f --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/glx/hardext.c @@ -0,0 +1,314 @@ +#include "hardext.h" + +#include "../gl/debug.h" +#include "../gl/gl4es.h" +#include "../gl/init.h" +#include "../gl/logs.h" +#include "../gl/loader.h" +#ifndef ANDROID +#include "rpi.h" +#endif +#include "glx_gbm.h" + +#ifndef EGL_PLATFORM_GBM_KHR +#define EGL_PLATFORM_GBM_KHR 0x31D7 +#endif + +static int tested = 0; + +hardext_t hardext; + +#define SHUT(a) if(!globals4es.nobanner) a + +#if defined(NOX11) && defined(NOEGL) +__attribute__((visibility("default"))) +#endif +void GetHardwareExtensions(int notest) +{ + if(tested) return; + // put some default values + memset(&hardext, 0, sizeof(hardext)); + hardext.maxtex = 2; + hardext.maxsize = 2048; + hardext.maxlights = 8; + hardext.maxplanes = 6; + + hardext.esversion = globals4es.es; + if(notest) + { +#ifndef AMIGAOS4 + SHUT(LOGD("LIBGL: Hardware test disabled, nothing activated...\n")); +#endif + if(hardext.esversion==2) { + hardext.maxteximage = 4; + hardext.maxvarying = 8; + hardext.maxtex = 4; + hardext.maxvattrib = 8; + hardext.npot = 1; + hardext.fbo = 1; + hardext.pointsprite = 1; + hardext.pointsize = 1; + hardext.cubemap = 1; + } + return; + } +#if defined(BCMHOST) && !defined(ANDROID) + rpi_init(); +#endif +#ifdef NOEGL + SHUT(LOGD("LIBGL: Hardware test on current Context...\n")); +#else + // used EGL & GLES functions + LOAD_EGL(eglBindAPI); + LOAD_EGL(eglInitialize); + LOAD_EGL(eglGetDisplay); + LOAD_EGL(eglCreatePbufferSurface); + LOAD_EGL(eglDestroySurface); + LOAD_EGL(eglDestroyContext); + LOAD_EGL(eglMakeCurrent); + LOAD_EGL(eglChooseConfig); + LOAD_EGL(eglCreateContext); + LOAD_EGL(eglQueryString); + LOAD_EGL(eglTerminate); + + EGLDisplay eglDisplay; + EGLSurface eglSurface; + EGLContext eglContext; + + SHUT(LOGD("LIBGL: Using GLES %s backend\n", (hardext.esversion==1)?"1.1":"2.0")); + + // Create a PBuffer first... + EGLint egl_context_attrib_es2[] = { + EGL_CONTEXT_CLIENT_VERSION, 2, + EGL_NONE + }; + + EGLint egl_context_attrib[] = { + EGL_NONE + }; + + //let's create a PBuffer attributes + EGLint egl_attribs[10]; // should be enough + int i = 0; + egl_attribs[i++] = EGL_WIDTH; + egl_attribs[i++] = 32; + egl_attribs[i++] = EGL_HEIGHT; + egl_attribs[i++] = 32; + egl_attribs[i++] = EGL_NONE; + + EGLint configAttribs[] = { +#ifdef PANDORA + // on the Pandora, there don't seem to exist a 8888 PBuffer config for GLES2. + EGL_RED_SIZE, (hardext.esversion==1)?8:5, + EGL_GREEN_SIZE, (hardext.esversion==1)?8:6, + EGL_BLUE_SIZE, (hardext.esversion==1)?8:5, + EGL_ALPHA_SIZE, (hardext.esversion==1)?8:0, +#else + EGL_RED_SIZE, 8, + EGL_GREEN_SIZE, 8, + EGL_BLUE_SIZE, 8, + EGL_ALPHA_SIZE, 8, +#endif + EGL_SURFACE_TYPE, EGL_PBUFFER_BIT, + EGL_RENDERABLE_TYPE, (hardext.esversion==1)?EGL_OPENGL_ES_BIT:EGL_OPENGL_ES2_BIT, + EGL_NONE + }; + + int configsFound; + static EGLConfig pbufConfigs[1]; + +#ifndef NO_GBM + if(strstr(egl_eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS), "EGL_KHR_platform_gbm")) { + SHUT(LOGD("LIBGL: GBM Surfaces supported%s\n", globals4es.usegbm?" and used":"")); + hardext.gbm = 1; + } +#endif + eglDisplay = egl_eglGetDisplay(EGL_DEFAULT_DISPLAY); + + egl_eglBindAPI(EGL_OPENGL_ES_API); + if (egl_eglInitialize(eglDisplay, NULL, NULL) != EGL_TRUE) { + LOGE("LIBGL: Error while gathering supported extension (eglInitialize: %s), default to none\n", PrintEGLError(0)); + egl_eglTerminate(eglDisplay); + return; + } + + egl_eglChooseConfig(eglDisplay, configAttribs, pbufConfigs, 1, &configsFound); +#ifndef PANDORA + if(!configsFound) { + // try without alpha channel + configAttribs[4*2-1] = 0; + egl_eglChooseConfig(eglDisplay, configAttribs, pbufConfigs, 1, &configsFound); + if(configsFound) { + SHUT(LOGD("LIBGL: No alpha channel in PBuffer context, disabling EGL Alpha channel...\n")); + hardext.eglnoalpha = 1; + } + } +#endif + if(!configsFound) { + SHUT(LOGE("LIBGL: Error while gathering supported extension (eglChooseConfig: %s), default to none\n", PrintEGLError(0))); + egl_eglTerminate(eglDisplay); + return; + } + eglContext = egl_eglCreateContext(eglDisplay, pbufConfigs[0], EGL_NO_CONTEXT, (hardext.esversion==1)?egl_context_attrib:egl_context_attrib_es2); + if(!eglContext) { + SHUT(LOGE("LIBGL: Error while gathering supported extension (eglCreateContext: %s), default to none\n", PrintEGLError(0))); + return; + } + eglSurface = egl_eglCreatePbufferSurface(eglDisplay, pbufConfigs[0], egl_attribs); + if(!eglSurface) { + SHUT(LOGE("LIBGL: Error while gathering supported extension (eglCreatePBufferSurface: %s), default to none\n", PrintEGLError(0))); + egl_eglDestroyContext(eglDisplay, eglContext); + egl_eglTerminate(eglDisplay); + return; + } + egl_eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext); +#endif + tested = 1; + LOAD_GLES(glGetString); + LOAD_GLES(glGetIntegerv); + LOAD_GLES(glGetError); + // Now get extensions + const char* Exts = gles_glGetString(GL_EXTENSIONS); + // Parse them! + #define S(A, B, C) if(strstr(Exts, A)) { hardext.B = 1; SHUT(LOGD("LIBGL: Extension %s detected%s",A, C?" and used\n":"\n")); } + if(hardext.esversion>1) hardext.npot = 1; + if(strstr(Exts, "GL_APPLE_texture_2D_limited_npot")) hardext.npot = 1; + if(strstr(Exts, "GL_IMG_texture_npot")) hardext.npot = 1; // it should enable mipmap (so hardext.npot=2), but mipmap (so level > 0) needs to be POT-sized?!! + if(strstr(Exts, "GL_ARB_texture_non_power_of_two") || strstr(Exts, "GL_OES_texture_npot")) hardext.npot = 3; + if(hardext.npot>0) { + SHUT(LOGD("LIBGL: Hardware %s NPOT detected and used\n", hardext.npot==3?"Full":(hardext.npot==2?"Limited+Mipmap":"Limited"))); + } + S("GL_EXT_blend_minmax", blendminmax, 1); + /*if(hardext.blendcolor==0) { + // try by just loading the function + LOAD_GLES_OR_OES(glBlendColor); + if(gles_glBlendColor != NULL) { + hardext.blendcolor = 1; + SHUT(LOGD("LIBGL: Extension glBlendColor found and used\n")); + } + }*/ // I don't think this is correct + if(hardext.esversion<2) { + S("GL_OES_framebuffer_object", fbo, 1); + S("GL_OES_point_sprite", pointsprite, 1); + S("GL_OES_point_size_array", pointsize, 0); + S("GL_OES_texture_cube_map", cubemap, 1); + S("GL_EXT_blend_color", blendcolor, 1); + S("GL_OES_blend_subtract", blendsub, 1); + S("GL_OES_blend_func_separate", blendfunc, 1); + S("GL_OES_blend_equation_separate", blendeq, 1); + S("GL_OES_texture_mirrored_repeat", mirrored, 1); + } else { + hardext.fbo = 1; + SHUT(LOGD("LIBGL: FBO are in core, and so used\n")); + hardext.pointsprite = 1; + SHUT(LOGD("LIBGL: PointSprite are in core, and so used\n")); + hardext.pointsize = 1; + SHUT(LOGD("LIBGL: CubeMap are in core, and so used\n")); + hardext.cubemap = 1; + SHUT(LOGD("LIBGL: BlendColor is in core, and so used\n")); + hardext.blendcolor = 1; + SHUT(LOGD("LIBGL: Blend Substract is in core, and so used\n")); + hardext.blendsub = 1; + SHUT(LOGD("LIBGL: Blend Function and Equation Separation is in core, and so used\n")); + hardext.blendfunc = 1; + hardext.blendeq = 1; + SHUT(LOGD("LIBGL: Texture Mirrored Repeat is in core, and so used\n")); + hardext.mirrored = 1; + } + S("GL_OES_mapbuffer", mapbuffer, 0); + S("GL_OES_element_index_uint", elementuint, 1); + S("GL_OES_packed_depth_stencil", depthstencil, 1); + S("GL_OES_depth24", depth24, 1); + S("GL_OES_rgb8_rgba8", rgba8, 1); + S("GL_EXT_multi_draw_arrays", multidraw, 0); + if(!globals4es.nobgra) { + S("GL_EXT_texture_format_BGRA8888", bgra8888, 1); + } + if(!globals4es.nodepthtex) { + S("GL_OES_depth_texture", depthtex, 1); + S("GL_OES_texture_stencil8", stenciltex, 1); + } + S("GL_OES_draw_texture", drawtex, 1); + S("GL_EXT_texture_rg", rgtex, 1); + if(globals4es.floattex) { + S("GL_OES_texture_float", floattex, 1); + S("GL_OES_texture_half_float", halffloattex, 1); + S("GL_EXT_color_buffer_float", floatfbo, 1); + S("GL_EXT_color_buffer_half_float", halffloatfbo, 1); + } + + if (hardext.esversion>1) { + if(!globals4es.nohighp) { + S("GL_OES_fragment_precision_high", highp, 1); + if(!hardext.highp) { + // check if highp is supported anyway + LOAD_GLES2(glGetShaderPrecisionFormat); + if(gles_glGetShaderPrecisionFormat) { + GLint range[2] = {0}; + GLint precision=0; + gles_glGetShaderPrecisionFormat(GL_FRAGMENT_SHADER, GL_HIGH_FLOAT, range, &precision); + if(!(range[0]==0 && range[1]==0 && precision==0)) { + hardext.highp = 2; // no need to declare #entension here + SHUT(LOGD("LIBGL: high precision float in fragment shader available and used\n")); + } + } + } + } + S("GL_EXT_frag_depth", fragdepth, 1); + gles_glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &hardext.maxvattrib); + SHUT(LOGD("LIBGL: Max vertex attrib: %d\n", hardext.maxvattrib)); + S("GL_OES_standard_derivatives", derivatives, 1); + } + // Now get some max stuffs + gles_glGetIntegerv(GL_MAX_TEXTURE_SIZE, &hardext.maxsize); + SHUT(LOGD("LIBGL: Max texture size: %d\n", hardext.maxsize)); + gles_glGetIntegerv((hardext.esversion==1)?GL_MAX_TEXTURE_UNITS:GL_MAX_TEXTURE_IMAGE_UNITS, &hardext.maxtex); + if (hardext.esversion==1) { + gles_glGetIntegerv(GL_MAX_LIGHTS, &hardext.maxlights); + gles_glGetIntegerv(GL_MAX_CLIP_PLANES, &hardext.maxplanes); + hardext.maxteximage=hardext.maxtex; + } else { + // simulated stuff using the FPE + hardext.maxlights = 8; + hardext.maxplanes = 6; + gles_glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &hardext.maxteximage); + gles_glGetIntegerv(GL_MAX_VARYING_VECTORS, &hardext.maxvarying); + SHUT(LOGD("LIBGL: Max Varying Vector: %d\n", hardext.maxvarying)); + if(hardext.maxvattrib<16 && hardext.maxtex>4) + hardext.maxtex = 4; // with less then 16 vertexattrib, more then 4 textures seems unreasonnable + } + if(hardext.maxtex>MAX_TEX) hardext.maxtex=MAX_TEX; // caping, as there are some fixed-sized array... + if(hardext.maxteximage>MAX_TEX) hardext.maxteximage=MAX_TEX; + if(hardext.maxlights>MAX_LIGHT) hardext.maxlights=MAX_LIGHT; // caping lights too + if(hardext.maxplanes>MAX_CLIP_PLANES) hardext.maxplanes=MAX_CLIP_PLANES; // caping planes, even 6 should be the max supported anyway + SHUT(LOGD("LIBGL: Texture Units: %d(%d), Max lights: %d, Max planes: %d\n", hardext.maxtex, hardext.maxteximage, hardext.maxlights, hardext.maxplanes)); + S("GL_EXT_texture_filter_anisotropic", aniso, 1); + if(hardext.aniso) { + gles_glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY, &hardext.aniso); + if(gles_glGetError()!=GL_NO_ERROR) + hardext.aniso = 0; + if(hardext.aniso) + SHUT(LOGD("LIBGL: Max Anisotropic filtering: %d\n", hardext.aniso)); + } + // get GLES driver signatures... + const char* vendor = gles_glGetString(GL_VENDOR); + SHUT(LOGD("LIBGL: Hardware vendor is %s\n", vendor)); + if(strstr(vendor, "ARM")) + hardext.vendor = VEND_ARM; + else if(strstr(vendor, "Imagination Technologies")) + hardext.vendor = VEND_IMGTEC; + +#ifndef NOEGL + if(strstr(egl_eglQueryString(eglDisplay, EGL_EXTENSIONS), "EGL_KHR_gl_colorspace")) { + SHUT(LOGD("LIBGL: sRGB surface supported\n")); + hardext.srgb = 1; + } + + // End, cleanup + egl_eglMakeCurrent(eglDisplay, 0, 0, EGL_NO_CONTEXT); + egl_eglDestroySurface(eglDisplay, eglSurface); + egl_eglDestroyContext(eglDisplay, eglContext); + + egl_eglTerminate(eglDisplay); +#endif +} diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/glx/hardext.h b/Projects/Android/jni/SupportLibs/gl4es/src/glx/hardext.h new file mode 100644 index 0000000..c9f381e --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/glx/hardext.h @@ -0,0 +1,57 @@ +#ifndef _GLX_HARDEXT_H_ +#define _GLX_HARDEXT_H_ + +#define VEND_IMGTEC 0x0100 +#define VEND_ARM 0x0200 + +typedef struct _hardext { + int npot; // 0 = no npot capability, 1 = limited npot, 2 = full npot + int maxtex; // maximum number of texture + int maxlights; // maximum number of light + int maxsize; // maximum texture size + int maxplanes; // maximum clip planes + int blendsub; // GL_OES_blend_subtract + int blendfunc; // GL_OES_blend_func_separate + int blendeq; // GL_OES_blend_equation_separate + int blendminmax; // GL_EXT_blend_minmax + int blendcolor; // GL_EXT_blend_color + int pointsprite; // GL_OES_point_sprite + int pointsize; // GL_OES_point_size_array + int elementuint; // GL_OES_element_index_uint + int fbo; // GL_OES_framebuffer_object + int depthstencil; // GL_OES_packed_depth_stencil + int depth24; // GL_OES_depth24 + int rgba8; // GL_OES_rgb8_rgba8 + int multidraw; // GL_EXT_multi_draw_arrays + int bgra8888; // GL_EXT_texture_format_BGRA8888 + int depthtex; // GL_OES_depth_texture + int stenciltex; // GL_OES_texture_stencil8 + int cubemap; // GL_OES_texture_cube_map + int drawtex; // GL_OES_draw_texture + int rgtex; // GL_EXT_texture_rg + int floattex; // GL_OES_texture_float + int halffloattex; // GL_OES_texture_half_float + int floatfbo; // GL_EXT_color_buffer_float + int halffloatfbo; // GL_EXT_color_buffer_half_float + int mirrored; // GL_OES_texture_mirrored_repeat + int aniso; // Max ANISOTROPIC filter available (0 if not) + int srgb; // EGL_KHR_gl_colorspace + int mapbuffer; // GL_OES_mapbuffer + // es2 stuffs + int esversion; // 1 is ES1.1 backend, 2 is ES2 + int maxvattrib; // GL_MAX_VERTEX_ATTRIBS (or 0 if not using es2) + int maxteximage; // GL_MAX_TEXTURE_IMAGE_UNITS for es2 + int maxvarying; // GL_MAX_VARYING_VECTORS for es2 + int highp; // GL_OES_fragment_precision_high + int fragdepth; // GL_EXT_frag_depth + int derivatives; // GL_OES_standard_derivatives + int gbm; // EGL_KHR_platform_gbm + int vendor; // which vendor (to apply workaround) + int eglnoalpha; // EGL surface doesn't seems to have any alpha channel (auto detect) +} hardext_t; + +extern hardext_t hardext; + +void GetHardwareExtensions(int test); + +#endif diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/glx/lookup.c b/Projects/Android/jni/SupportLibs/gl4es/src/glx/lookup.c new file mode 100644 index 0000000..e651058 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/glx/lookup.c @@ -0,0 +1,954 @@ +#include "../gl/wrap/gl4es.h" +#include "../gl/wrap/stub.h" +#include "../gl/directstate.h" +#include "../gl/framebuffers.h" +#include "../gl/init.h" +#include "../gl/line.h" +#include "../gl/loader.h" +#include "../gl/render.h" +#include "../gl/texgen.h" +#include "../gl/vertexattrib.h" +#include "glx.h" +#include "hardext.h" + +#define EXPORT __attribute__((visibility("default"))) + +//#define DEBUG_ADDRESS + +#ifdef DEBUG_ADDRESS +#define MAP(func_name, func) \ + if (strcmp(name, func_name) == 0) return (void *)func; +#else +#define MAP(func_name, func) \ + if (strcmp(name, func_name) == 0) return (void *)func; +#endif + +#ifdef NOEGL + #define MAP_EGL(func_name, egl_func) +#else + #define MAP_EGL(func_name, egl_func) \ + MAP(#func_name, egl_eglGetProcAddress(#egl_func)) +#endif + +#define EX(func_name) MAP(#func_name, func_name) + +#define ARB(func_name) MAP(#func_name "ARB", func_name) + +#define EXT(func_name) MAP(#func_name "EXT", func_name) + +#define _EX(func_name) MAP(#func_name, gl4es_ ## func_name) + +#define _ARB(func_name) MAP(#func_name "ARB", gl4es_ ## func_name) + +#define _EXT(func_name) MAP(#func_name "EXT", gl4es_ ## func_name) + +#define STUB(func_name) \ + if (strcmp(name, #func_name) == 0) { \ + if(!globals4es.silentstub) LOGD("glX stub: %s\n", #func_name); \ + return (void *)glXStub; \ + } + +void glXStub(void *x, ...) { + return; +} + +void *gl4es_glXGetProcAddress(const char *name) { +#ifndef NOEGL + LOAD_EGL(eglGetProcAddress); +#endif +#ifdef DEBUG_ADDRESS + static int cnt = 0; + cnt++; +#endif + // generated gles wrappers + #include "glesfuncs.inc" + +#ifndef NOX11 + // glX calls + _EX(glXChooseVisual); + _EX(glXCopyContext); + _EX(glXCreateContext); + _EX(glXCreateNewContext); + _EX(glXCreateContextAttribsARB); + _EX(glXDestroyContext); + _EX(glXGetConfig); + _EX(glXGetCurrentDisplay); + _EX(glXGetCurrentDrawable); + _EX(glXIsDirect); + _EX(glXMakeCurrent); + _EX(glXMakeContextCurrent); + _EX(glXQueryExtensionsString); + _EX(glXQueryServerString); + _EX(glXSwapBuffers); + _EX(glXSwapIntervalEXT); +#endif //NOX11 + MAP("glXSwapIntervalMESA", gl4es_glXSwapInterval); + MAP("glXSwapIntervalSGI", gl4es_glXSwapInterval); +#ifndef NOX11 + _EX(glXUseXFont); + _EX(glXWaitGL); + _EX(glXWaitX); + _EX(glXGetCurrentContext); + _EX(glXQueryExtension); + _EX(glXQueryDrawable); + _EX(glXQueryVersion); + _EX(glXGetClientString); + _EX(glXGetFBConfigs); + _EX(glXChooseFBConfig); + MAP("glXChooseFBConfigSGIX", gl4es_glXChooseFBConfig); + _EX(glXGetFBConfigAttrib); + _EX(glXQueryContext); + _EX(glXGetVisualFromFBConfig); + _EX(glXCreateWindow); + _EX(glXDestroyWindow); + + _EX(glXCreatePbuffer); + _EX(glXDestroyPbuffer); + _EX(glXCreatePixmap); + _EX(glXDestroyPixmap); + _EX(glXCreateGLXPixmap); + _EX(glXDestroyGLXPixmap); + STUB(glXGetCurrentReadDrawable); + STUB(glXGetSelectedEvent); + STUB(glXSelectEvent); + + _EX(glXCreateContextAttribs); + _ARB(glXCreateContextAttribs); +#endif //NOX11 + _EX(glXGetProcAddress); + _ARB(glXGetProcAddress); + // GL_EXT_texture_object (yeah, super old!) + _EXT(glGenTextures); + _EXT(glBindTexture); + _EXT(glDeleteTextures); + _EXT(glIsTexture); + _EXT(glAreTexturesResident); + _EXT(glPrioritizeTextures); + + // GL_EXT_polygonoffset + _EXT(glPolygonOffset); + + // GL_ARB_vertex_buffer_object + _ARB(glBindBuffer); + _ARB(glBufferData); + _ARB(glBufferSubData); + _ARB(glDeleteBuffers); + _ARB(glGenBuffers); + _ARB(glIsBuffer); + _EX(glGetBufferPointerv); + _ARB(glGetBufferPointerv); + _EX(glMapBuffer); + _EX(glUnmapBuffer); + _ARB(glMapBuffer); + _ARB(glUnmapBuffer); + _ARB(glGetBufferParameteriv); + _EX(glGetBufferSubData); + _ARB(glGetBufferSubData); + + _EX(glMapBufferRange); + _EX(glFlushMappedBufferRange); + // Named Buffer + _EX(glNamedBufferData); + _EX(glNamedBufferSubData); + _EX(glGetNamedBufferParameteriv); + _EX(glMapNamedBuffer); + _EX(glUnmapNamedBuffer); + _EX(glGetNamedBufferSubData); + _EX(glGetNamedBufferPointerv); + _EXT(glNamedBufferData); + _EXT(glNamedBufferSubData); + _EXT(glGetNamedBufferParameteriv); + _EXT(glMapNamedBuffer); + _EXT(glUnmapNamedBuffer); + _EXT(glGetNamedBufferSubData); + _EXT(glGetNamedBufferPointerv); + // GL_ARB_vertex_array_object + _EX(glGenVertexArrays); + _EX(glBindVertexArray); + _EX(glDeleteVertexArrays); + _EX(glIsVertexArray); + _ARB(glGenVertexArrays); + _ARB(glBindVertexArray); + _ARB(glDeleteVertexArrays); + _ARB(glIsVertexArray); + _EXT(glGenVertexArrays); + _EXT(glBindVertexArray); + _EXT(glDeleteVertexArrays); + _EXT(glIsVertexArray); + + // GL_ARB_frameBuffer_ext + if(hardext.fbo) { + _EX(glFramebufferTexture1D); + _EX(glFramebufferTexture3D); + _EX(glFramebufferTextureLayer); + _EX(glRenderbufferStorageMultisample); + _EX(glBlitFramebuffer); + _EXT(glGenFramebuffers); + _EXT(glDeleteFramebuffers); + _EXT(glIsFramebuffer); + _EXT(glCheckFramebufferStatus); + _EXT(glBindFramebuffer); + _EXT(glFramebufferTexture2D); + _EXT(glFramebufferTexture1D); + _EXT(glFramebufferTexture3D); + _EXT(glGenRenderbuffers); + _EXT(glFramebufferRenderbuffer); + _EXT(glDeleteRenderbuffers); + _EXT(glRenderbufferStorage); + _EXT(glRenderbufferStorageMultisample); + _EXT(glBindRenderbuffer); + _EXT(glIsRenderbuffer); + _EXT(glGenerateMipmap); + _EXT(glGetFramebufferAttachmentParameteriv); + _EXT(glGetRenderbufferParameteriv); + _EXT(glFramebufferTextureLayer); + _EXT(glBlitFramebuffer); + _ARB(glGenFramebuffers); + _ARB(glDeleteFramebuffers); + _ARB(glIsFramebuffer); + _ARB(glCheckFramebufferStatus); + _ARB(glBindFramebuffer); + _ARB(glFramebufferTexture2D); + _ARB(glFramebufferTexture1D); + _ARB(glFramebufferTexture3D); + _ARB(glGenRenderbuffers); + _ARB(glFramebufferRenderbuffer); + _ARB(glDeleteRenderbuffers); + _ARB(glRenderbufferStorage); + _ARB(glRenderbufferStorageMultisample); + _ARB(glBindRenderbuffer); + _ARB(glIsRenderbuffer); + _ARB(glGenerateMipmap); + _ARB(glGetFramebufferAttachmentParameteriv); + _ARB(glGetRenderbufferParameteriv); + _ARB(glFramebufferTextureLayer); + _ARB(glBlitFramebuffer); + _EX(glDrawBuffers); + _ARB(glDrawBuffers); + _EX(glClearBufferiv); + _EX(glClearBufferuiv); + _EX(glClearBufferfv); + _EX(glClearBufferfi); + _EX(glClearNamedFramebufferiv) + _EX(glClearNamedFramebufferuiv) + _EX(glClearNamedFramebufferfv) + _EX(glClearNamedFramebufferfi) + _EXT(glClearNamedFramebufferiv) + _EXT(glClearNamedFramebufferuiv) + _EXT(glClearNamedFramebufferfv) + _EXT(glClearNamedFramebufferfi) + } + + // GL_EXT_vertex_array + _EXT(glArrayElement); + _EXT(glDrawArrays); + _EXT(glVertexPointer); + _EXT(glNormalPointer); + _EXT(glColorPointer); + _EX(glIndexPointer); //TODO, stub for now + _EXT(glIndexPointer); + _EXT(glTexCoordPointer); + _EX(glEdgeFlagPointer); //TODO, stub for now + _EXT(glEdgeFlagPointer); + _EX(glGetPointerv); + _EXT(glGetPointerv); + + + // OES wrapper + EX(glClearDepthfOES); + EX(glClipPlanefOES); + EX(glDepthRangefOES); + EX(glFrustumfOES); + EX(glGetClipPlanefOES); + EX(glOrthofOES); + + // passthrough + // batch thunking! + #define THUNK(suffix, type) \ + _EX(glColor3##suffix##v); \ + _EX(glColor3##suffix); \ + _EX(glColor4##suffix##v); \ + _EX(glColor4##suffix); \ + _EX(glSecondaryColor3##suffix##v); \ + _EX(glSecondaryColor3##suffix); \ + _EXT(glSecondaryColor3##suffix##v); \ + _EXT(glSecondaryColor3##suffix); \ + _EX(glIndex##suffix##v); \ + _EX(glIndex##suffix); \ + _EX(glNormal3##suffix##v); \ + _EX(glNormal3##suffix); \ + _EX(glRasterPos2##suffix##v); \ + _EX(glRasterPos2##suffix); \ + _EX(glRasterPos3##suffix##v); \ + _EX(glRasterPos3##suffix); \ + _EX(glRasterPos4##suffix##v); \ + _EX(glRasterPos4##suffix); \ + _EX(glWindowPos2##suffix##v); \ + _EX(glWindowPos2##suffix); \ + _EX(glWindowPos3##suffix##v); \ + _EX(glWindowPos3##suffix); \ + _EX(glVertex2##suffix##v); \ + _EX(glVertex2##suffix); \ + _EX(glVertex3##suffix##v); \ + _EX(glVertex3##suffix); \ + _EX(glVertex4##suffix##v); \ + _EX(glVertex4##suffix); \ + _EX(glTexCoord1##suffix##v); \ + _EX(glTexCoord1##suffix); \ + _EX(glTexCoord2##suffix##v); \ + _EX(glTexCoord2##suffix); \ + _EX(glTexCoord3##suffix##v); \ + _EX(glTexCoord3##suffix); \ + _EX(glTexCoord4##suffix##v); \ + _EX(glTexCoord4##suffix); \ + _EX(glMultiTexCoord1##suffix##v); \ + _EX(glMultiTexCoord1##suffix); \ + _EX(glMultiTexCoord2##suffix##v); \ + _EX(glMultiTexCoord2##suffix); \ + _EX(glMultiTexCoord3##suffix##v); \ + _EX(glMultiTexCoord3##suffix); \ + _EX(glMultiTexCoord4##suffix##v); \ + _EX(glMultiTexCoord4##suffix); \ + _EXT(glMultiTexCoord1##suffix##v); \ + _EXT(glMultiTexCoord1##suffix); \ + _EXT(glMultiTexCoord2##suffix##v); \ + _EXT(glMultiTexCoord2##suffix); \ + _EXT(glMultiTexCoord3##suffix##v); \ + _EXT(glMultiTexCoord3##suffix); \ + _EXT(glMultiTexCoord4##suffix##v); \ + _EXT(glMultiTexCoord4##suffix); \ + _ARB(glMultiTexCoord1##suffix##v); \ + _ARB(glMultiTexCoord1##suffix); \ + _ARB(glMultiTexCoord2##suffix##v); \ + _ARB(glMultiTexCoord2##suffix); \ + _ARB(glMultiTexCoord3##suffix##v); \ + _ARB(glMultiTexCoord3##suffix); \ + _ARB(glMultiTexCoord4##suffix##v); \ + _ARB(glMultiTexCoord4##suffix); + + THUNK(b, GLbyte); + THUNK(d, GLdouble); + THUNK(i, GLint); + THUNK(s, GLshort); + THUNK(ub, GLubyte); + THUNK(ui, GLuint); + THUNK(us, GLushort); + THUNK(f, GLfloat); + #undef THUNK + + _EX(glPointParameterf); + _EX(glPointParameterfv); + _ARB(glPointParameterf); + _ARB(glPointParameterfv); + _EXT(glPointParameterf); + _EXT(glPointParameterfv); + + // functions we actually define + _EXT(glActiveTexture); + _ARB(glActiveTexture); + _EX(glArrayElement); + _EX(glBegin); + _EX(glBitmap); + if(globals4es.blendcolor || hardext.blendcolor) { + _EX(glBlendColor); + _EXT(glBlendColor); + _ARB(glBlendColor); + } + _EXT(glBlendEquation); + _ARB(glBlendEquation); + _EXT(glBlendFunc); + _ARB(glBlendFunc); + + if(hardext.blendeq) { + _EXT(glBlendEquationSeparate); + _ARB(glBlendEquationSeparate); + _EX(glBlendEquationSeparatei); + _EXT(glBlendEquationSeparatei); + _ARB(glBlendEquationSeparatei); + } + if(hardext.blendfunc) { + _EXT(glBlendFuncSeparate); + _ARB(glBlendFuncSeparate); + _EX(glBlendFuncSeparatei); + _EXT(glBlendFuncSeparatei); + _ARB(glBlendFuncSeparatei); + } + _EX(glStencilMaskSeparate); + _EXT(glStencilMaskSeparate); + _EX(glCallList); + _EX(glCallLists); + _EX(glClearDepth); + _EXT(glClientActiveTexture); + _ARB(glClientActiveTexture); + _EX(glClipPlane); + _EX(glCopyPixels); + _EX(glDeleteLists); + _EX(glDepthRange); + _EX(glDrawBuffer); + _EX(glDrawPixels); + _EX(glDrawRangeElements); + _EXT(glDrawRangeElements); + _EX(glEdgeFlag); + _EX(glEnd); + _EX(glEndList); + _EX(glEvalCoord1d); + _EX(glEvalCoord1f); + _EX(glEvalCoord2d); + _EX(glEvalCoord2f); + _EX(glEvalCoord1dv); + _EX(glEvalCoord1fv); + _EX(glEvalCoord2dv); + _EX(glEvalCoord2fv); + _EX(glEvalMesh1); + _EX(glEvalMesh2); + _EX(glEvalPoint1); + _EX(glEvalPoint2); + _EX(glFogCoordd); + _EX(glFogCoorddv); + _EX(glFogCoordf); + _EX(glFogCoordfv); + _EX(glFogi); + _EX(glFogiv); + _EX(glFrustum); + _EX(glGenLists); + _EX(glGetDoublev); + _EX(glGetIntegerv); + _EX(glGetMapdv); + _EX(glGetMapfv); + _EX(glGetMapiv); + _EX(glGetTexImage); + _EX(glGetTexLevelParameterfv); + _EX(glGetTexLevelParameteriv); + _EX(glInitNames); + _EX(glInterleavedArrays); + _EX(glIsList); + _EX(glLighti); + _EX(glLightiv); + _EX(glLightModeli); + _EX(glLightModeliv); + _EX(glLineStipple); + _EX(glListBase); + _EX(glLoadMatrixd); + _EX(glLoadName); + _EXT(glLockArrays); + _EX(glMap1d); + _EX(glMap1f); + _EX(glMap2d); + _EX(glMap2f); + _EX(glMapGrid1d); + _EX(glMapGrid1f); + _EX(glMapGrid2d); + _EX(glMapGrid2f); + _EX(glMateriali); + _EX(glMaterialiv); + _EX(glMultMatrixd); + _EX(glNewList); + _EX(glOrtho); + _EX(glPixelTransferf); + _EX(glPixelTransferi); + _EX(glPixelZoom); + _EX(glPolygonMode); + _EX(glPolygonStipple); + _EX(glPopAttrib); + _EX(glPopClientAttrib); + _EX(glPopName); + _EX(glPushAttrib); + _EX(glPushClientAttrib); + _EX(glPushName); + _EX(glRasterPos2i); + _EX(glReadBuffer); + _EX(glRectd); + _EX(glRectf); + _EX(glRecti); + _EX(glRects); + _EX(glRectdv); + _EX(glRectfv); + _EX(glRectiv); + _EX(glRectsv); + _EX(glRenderMode); + _EX(glRotated); + _EX(glScaled); + _EX(glSecondaryColorPointer); + _EXT(glSecondaryColorPointer); + _EX(glTexEnvf); + _EX(glTexEnviv); + _EX(glTexGend); + _EX(glTexGendv); + _EX(glTexGenf); + _EX(glTexGenfv); + _EX(glTexGeni); + _EX(glTexGeniv); + _EX(glTexImage1D); + _EX(glTexImage3D); + _EX(glTexSubImage1D); + _EX(glTexSubImage3D); + _EXT(glTexImage3D); + _EXT(glTexSubImage3D); + _EX(glCompressedTexImage1D); + _EX(glCompressedTexSubImage1D); + _EX(glCompressedTexImage3D); + _EX(glCompressedTexSubImage3D); + _EX(glGetCompressedTexImage); + _EXT(glCompressedTexImage2D); + _EXT(glCompressedTexSubImage2D); + _EXT(glCompressedTexImage1D); + _EXT(glCompressedTexSubImage1D); + _EXT(glCompressedTexImage3D); + _EXT(glCompressedTexSubImage3D); + _EXT(glGetCompressedTexImage); + _ARB(glCompressedTexImage2D); + _ARB(glCompressedTexSubImage2D); + _ARB(glCompressedTexImage1D); + _ARB(glCompressedTexSubImage1D); + _ARB(glCompressedTexImage3D); + _ARB(glCompressedTexSubImage3D); + _ARB(glGetCompressedTexImage); + _EX(glCopyTexImage1D); + _EX(glCopyTexSubImage1D); + _EX(glTranslated); + _EXT(glUnlockArrays); + _EX(glGetTexGenfv); + _EX(glGetTexGendv); + _EX(glGetTexGeniv); + _EX(glLoadTransposeMatrixf); + _EX(glLoadTransposeMatrixd); + _EX(glMultTransposeMatrixd); + _EX(glMultTransposeMatrixf); + // stubs for unimplemented functions + STUB(glAccum); + STUB(glAreTexturesResident); + STUB(glClearAccum); + _EX(glColorMaterial); + _EX(glCopyTexSubImage3D); // It's a stub, calling the 2D one + STUB(glFeedbackBuffer); + _EX(glGetClipPlane); + _EX(glGetLightiv); + _EX(glGetMaterialiv); + _EX(glGetPixelMapfv); + _EX(glGetPixelMapuiv); + _EX(glGetPixelMapusv); + STUB(glGetPolygonStipple); + _EX(glGetStringi); + STUB(glPassThrough); + _EX(glPixelMapfv); + _EX(glPixelMapuiv); + _EX(glPixelMapusv); + _EX(glPixelStoref); + STUB(glPrioritizeTextures); + STUB(glSelectBuffer); //TODO + + _EX(glMultiDrawArrays); + _EXT(glMultiDrawArrays); + _EX(glMultiDrawElements); + _EXT(glMultiDrawElements); + + _EX(glPointParameteri); + _EX(glPointParameteriv); + + _EX(glFogCoordPointer); + if(hardext.esversion>1) { + // EXT_fog_coord supported + _EXT(glFogCoordd); + _EXT(glFogCoorddv); + _EXT(glFogCoordf); + _EXT(glFogCoordfv); + _EXT(glFogCoordPointer); + } + /*STUB(glEdgeFlagPointerEXT); + STUB(glIndexPointerEXT);*/ + + //EXT_direct_state_access + _EX(glClientAttribDefault); + _EX(glPushClientAttribDefault); + _EX(glMatrixLoadf); + _EX(glMatrixLoadd); + _EX(glMatrixMultf); + _EX(glMatrixMultd); + _EX(glMatrixLoadIdentity); + _EX(glMatrixRotatef); + _EX(glMatrixRotated); + _EX(glMatrixScalef); + _EX(glMatrixScaled); + _EX(glMatrixTranslatef); + _EX(glMatrixTranslated); + _EX(glMatrixOrtho); + _EX(glMatrixFrustum); + _EX(glMatrixPush); + _EX(glMatrixPop); + _EX(glTextureParameteri); + _EX(glTextureParameteriv); + _EX(glTextureParameterf); + _EX(glTextureParameterfv); + _EX(glTextureImage1D); + _EX(glTextureImage2D); + _EX(glTextureSubImage1D); + _EX(glTextureSubImage2D); + _EX(glCopyTextureImage1D); + _EX(glCopyTextureImage2D); + _EX(glCopyTextureSubImage1D); + _EX(glCopyTextureSubImage2D); + _EX(glGetTextureImage); + _EX(glGetTextureParameterfv); + _EX(glGetTextureParameteriv); + _EX(glGetTextureLevelParameterfv); + _EX(glGetTextureLevelParameteriv); + _EX(glTextureImage3D); + _EX(glTextureSubImage3D); + _EX(glCopyTextureSubImage3D); + _EX(glBindMultiTexture); + _EX(glMultiTexCoordPointer); + _EX(glMultiTexEnvf); + _EX(glMultiTexEnvfv); + _EX(glMultiTexEnvi); + _EX(glMultiTexEnviv); + _EX(glMultiTexGend); + _EX(glMultiTexGendv); + _EX(glMultiTexGenf); + _EX(glMultiTexGenfv); + _EX(glMultiTexGeni); + _EX(glMultiTexGeniv); + _EX(glGetMultiTexEnvfv); + _EX(glGetMultiTexEnviv); + _EX(glGetMultiTexGendv); + _EX(glGetMultiTexGenfv); + _EX(glGetMultiTexGeniv); + _EX(glMultiTexParameteri); + _EX(glMultiTexParameteriv); + _EX(glMultiTexParameterf); + _EX(glMultiTexParameterfv); + _EX(glMultiTexImage1D); + _EX(glMultiTexImage2D); + _EX(glMultiTexSubImage1D); + _EX(glMultiTexSubImage2D); + _EX(glCopyMultiTexImage1D); + _EX(glCopyMultiTexImage2D); + _EX(glCopyMultiTexSubImage1D); + _EX(glCopyMultiTexSubImage2D); + _EX(glGetMultiTexImage); + _EX(glGetMultiTexParameterfv); + _EX(glGetMultiTexParameteriv); + _EX(glGetMultiTexLevelParameterfv); + _EX(glGetMultiTexLevelParameteriv); + _EX(glMultiTexImage3D); + _EX(glMultiTexSubImage3D); + _EX(glCopyMultiTexSubImage3D); + _EX(glEnableClientStateIndexedEXT); + _EX(glDisableClientStateIndexedEXT); + _EX(glGetFloatIndexedvEXT); + _EX(glGetDoubleIndexedvEXT); + _EX(glGetIntegerIndexedvEXT); + _EX(glGetBooleanIndexedvEXT); + _EX(glGetPointerIndexedvEXT); + _EX(glEnableIndexedEXT); + _EX(glDisableIndexedEXT); + _EX(glIsEnabledIndexedEXT); + _EX(glCompressedTextureImage3D); + _EX(glCompressedTextureImage2D); + _EX(glCompressedTextureImage1D); + _EX(glCompressedTextureSubImage3D); + _EX(glCompressedTextureSubImage2D); + _EX(glCompressedTextureSubImage1D); + _EX(glGetCompressedTextureImage); + _EX(glCompressedMultiTexImage3D); + _EX(glCompressedMultiTexImage2D); + _EX(glCompressedMultiTexImage1D); + _EX(glCompressedMultiTexSubImage3D); + _EX(glCompressedMultiTexSubImage2D); + _EX(glCompressedMultiTexSubImage1D); + _EX(glGetCompressedMultiTexImage); + _EX(glMatrixLoadTransposef); + _EX(glMatrixLoadTransposed); + _EX(glMatrixMultTransposef); + _EX(glMatrixMultTransposed); + + if(globals4es.queries) { + _EX(glGenQueries); + _EX(glIsQuery); + _EX(glDeleteQueries); + _EX(glBeginQuery); + _EX(glEndQuery); + _EX(glGetQueryiv); + _EX(glGetQueryObjectiv); + _EX(glGetQueryObjectuiv); + + _ARB(glGenQueries); + _ARB(glIsQuery); + _ARB(glDeleteQueries); + _ARB(glBeginQuery); + _ARB(glEndQuery); + _ARB(glGetQueryiv); + _ARB(glGetQueryObjectiv); + _ARB(glGetQueryObjectuiv); + } + + // GL_ARB_multisample + _ARB(glSampleCoverage); + + // extra shaders stuff + #define THUNK(suffix) \ + _EX(glVertexAttrib1##suffix); \ + _EX(glVertexAttrib2##suffix); \ + _EX(glVertexAttrib3##suffix); \ + _EX(glVertexAttrib4##suffix); \ + _EXT(glVertexAttrib1##suffix); \ + _EXT(glVertexAttrib2##suffix); \ + _EXT(glVertexAttrib3##suffix); \ + _EXT(glVertexAttrib4##suffix); + THUNK(s); + THUNK(d); + THUNK(sv); + THUNK(dv); + #undef THUNK + #define THUNK(suffix) \ + _EX(glVertexAttrib4##suffix##v); \ + _EX(glVertexAttrib4u##suffix##v); \ + _EX(glVertexAttrib4N##suffix##v); \ + _EX(glVertexAttrib4Nu##suffix##v);\ + _EXT(glVertexAttrib4##suffix##v); \ + _EXT(glVertexAttrib4u##suffix##v); \ + _EXT(glVertexAttrib4N##suffix##v); \ + _EXT(glVertexAttrib4Nu##suffix##v); + THUNK(b); + THUNK(s); + THUNK(i); + #undef THUNK + _EX(glGetVertexAttribdv); + _EXT(glGetVertexAttribdv); + _ARB(glGetVertexAttribdv); + _EX(glVertexAttrib4Nub); + _EXT(glVertexAttrib4Nub); + _ARB(glVertexAttrib4Nub); + // arb version of shader stuffs + // GL_ARB_vertex_shader + _ARB(glVertexAttrib1f); + _ARB(glVertexAttrib1s); + _ARB(glVertexAttrib1d); + _ARB(glVertexAttrib2f); + _ARB(glVertexAttrib2s); + _ARB(glVertexAttrib2d); + _ARB(glVertexAttrib3f); + _ARB(glVertexAttrib3s); + _ARB(glVertexAttrib3d); + _ARB(glVertexAttrib4f); + _ARB(glVertexAttrib4s); + _ARB(glVertexAttrib4d); + _ARB(glVertexAttrib4Nub); + _ARB(glVertexAttrib1fv); + _ARB(glVertexAttrib1sv); + _ARB(glVertexAttrib1dv); + _ARB(glVertexAttrib2fv); + _ARB(glVertexAttrib2sv); + _ARB(glVertexAttrib2dv); + _ARB(glVertexAttrib3fv); + _ARB(glVertexAttrib3sv); + _ARB(glVertexAttrib3dv); + _ARB(glVertexAttrib4fv); + _ARB(glVertexAttrib4sv); + _ARB(glVertexAttrib4dv); + _ARB(glVertexAttrib4iv); + _ARB(glVertexAttrib4bv); + _ARB(glVertexAttrib4ubv); + _ARB(glVertexAttrib4usv); + _ARB(glVertexAttrib4uiv); + _ARB(glVertexAttrib4Nbv); + _ARB(glVertexAttrib4Nsv); + _ARB(glVertexAttrib4Niv); + _ARB(glVertexAttrib4Nubv); + _ARB(glVertexAttrib4Nusv); + _ARB(glVertexAttrib4Nuiv); + _ARB(glVertexAttribPointer); + _ARB(glEnableVertexAttribArray); + _ARB(glDisableVertexAttribArray); + _ARB(glBindAttribLocation); + _ARB(glGetActiveAttrib); + _ARB(glGetAttribLocation); + _ARB(glGetVertexAttribdv); + _ARB(glGetVertexAttribfv); + _ARB(glGetVertexAttribiv); + _ARB(glGetVertexAttribPointerv); + // GL_ARB_fragment_shader (nothing) + // GL_ARGB_shader_objects + _ARB(glDeleteObject); + _ARB(glGetHandle); + _ARB(glDetachObject); + _ARB(glCreateShaderObject); + _ARB(glShaderSource); + _ARB(glCompileShader); + _ARB(glCreateProgramObject); + _ARB(glAttachObject); + _ARB(glLinkProgram); + _ARB(glUseProgramObject); + _ARB(glValidateProgram); + _ARB(glUniform1f); + _ARB(glUniform2f); + _ARB(glUniform3f); + _ARB(glUniform4f); + _ARB(glUniform1i); + _ARB(glUniform2i); + _ARB(glUniform3i); + _ARB(glUniform4i); + _ARB(glUniform1fv); + _ARB(glUniform2fv); + _ARB(glUniform3fv); + _ARB(glUniform4fv); + _ARB(glUniform1iv); + _ARB(glUniform2iv); + _ARB(glUniform3iv); + _ARB(glUniform4iv); + _ARB(glUniformMatrix2fv); + _ARB(glUniformMatrix3fv); + _ARB(glUniformMatrix4fv); + _ARB(glGetObjectParameterfv); + _ARB(glGetObjectParameteriv); + _ARB(glGetInfoLog); + _ARB(glGetAttachedObjects); + _ARB(glGetUniformLocation); + _ARB(glGetActiveUniform); + _ARB(glGetUniformfv); + _ARB(glGetUniformiv); + _ARB(glGetShaderSource); + _EX(glProgramUniform1f); + _EX(glProgramUniform2f); + _EX(glProgramUniform3f); + _EX(glProgramUniform4f); + _EX(glProgramUniform1i); + _EX(glProgramUniform2i); + _EX(glProgramUniform3i); + _EX(glProgramUniform4i); + _EX(glProgramUniform1fv); + _EX(glProgramUniform2fv); + _EX(glProgramUniform3fv); + _EX(glProgramUniform4fv); + _EX(glProgramUniform1iv); + _EX(glProgramUniform2iv); + _EX(glProgramUniform3iv); + _EX(glProgramUniform4iv); + _EX(glProgramUniformMatrix2fv); + _EX(glProgramUniformMatrix3fv); + _EX(glProgramUniformMatrix4fv); + // EXT version of Shaders functions + _EXT(glAttachShader); + _EXT(glBindAttribLocation); + _EXT(glCompileShader); + _EXT(glCreateProgram); + _EXT(glCreateShader); + _EXT(glDeleteProgram); + _EXT(glDeleteShader); + _EXT(glDetachShader); + _EXT(glGetActiveAttrib); + _EXT(glGetActiveUniform); + _EXT(glGetAttachedShaders); + _EXT(glGetAttribLocation); + _EXT(glGetProgramInfoLog); + _EXT(glGetProgramiv); + _EXT(glGetShaderInfoLog); + _EXT(glGetShaderPrecisionFormat); + _EXT(glGetShaderSource); + _EXT(glGetShaderiv); + _EXT(glGetUniformLocation); + _EXT(glGetUniformfv); + _EXT(glGetUniformiv); + _EXT(glGetVertexAttribPointerv); + _EXT(glGetVertexAttribfv); + _EXT(glGetVertexAttribiv); + _EXT(glIsProgram); + _EXT(glIsShader); + _EXT(glReleaseShaderCompiler); + _EXT(glShaderBinary); + _EXT(glShaderSource); + _EXT(glUniform1f); + _EXT(glUniform1fv); + _EXT(glUniform1i); + _EXT(glUniform1iv); + _EXT(glUniform2f); + _EXT(glUniform2fv); + _EXT(glUniform2i); + _EXT(glUniform2iv); + _EXT(glUniform3f); + _EXT(glUniform3fv); + _EXT(glUniform3i); + _EXT(glUniform3iv); + _EXT(glUniform4f); + _EXT(glUniform4fv); + _EXT(glUniform4i); + _EXT(glUniform4iv); + _EXT(glUniformMatrix2fv); + _EXT(glUniformMatrix3fv); + _EXT(glUniformMatrix4fv); + _EXT(glUseProgram); + _EXT(glValidateProgram); + _EXT(glVertexAttrib1f); + _EXT(glVertexAttrib1fv); + _EXT(glVertexAttrib2f); + _EXT(glVertexAttrib2fv); + _EXT(glVertexAttrib3f); + _EXT(glVertexAttrib3fv); + _EXT(glVertexAttrib4f); + _EXT(glVertexAttrib4fv); + _EXT(glVertexAttribPointer); + _EXT(glVertexPointer); + _EXT(glProgramUniform1f); + _EXT(glProgramUniform2f); + _EXT(glProgramUniform3f); + _EXT(glProgramUniform4f); + _EXT(glProgramUniform1i); + _EXT(glProgramUniform2i); + _EXT(glProgramUniform3i); + _EXT(glProgramUniform4i); + _EXT(glProgramUniform1fv); + _EXT(glProgramUniform2fv); + _EXT(glProgramUniform3fv); + _EXT(glProgramUniform4fv); + _EXT(glProgramUniform1iv); + _EXT(glProgramUniform2iv); + _EXT(glProgramUniform3iv); + _EXT(glProgramUniform4iv); + _EXT(glProgramUniformMatrix2fv); + _EXT(glProgramUniformMatrix3fv); + _EXT(glProgramUniformMatrix4fv); + + //ARB_draw_elements_base_vertex / EXT_draw_elements_base_vertex + _EX(glDrawElementsBaseVertex); + _EXT(glDrawElementsBaseVertex); + _ARB(glDrawElementsBaseVertex); + _EX(glDrawRangeElementsBaseVertex); + _EXT(glDrawRangeElementsBaseVertex); + _ARB(glDrawRangeElementsBaseVertex); + _EX(glMultiDrawElementsBaseVertex); + _EXT(glMultiDrawElementsBaseVertex); + _ARB(glMultiDrawElementsBaseVertex); + + //GL_ARB_draw_instanced + _EX(glDrawArraysInstanced); + _EXT(glDrawArraysInstanced); // not sure _EXT is needed... + _ARB(glDrawArraysInstanced); + _EX(glDrawElementsInstanced); + _EXT(glDrawElementsInstanced); + _ARB(glDrawElementsInstanced); + _EX(glDrawElementsInstancedBaseVertex); + _EXT(glDrawElementsInstancedBaseVertex); + _ARB(glDrawElementsInstancedBaseVertex); + + //GL_ARB_instanced_arrays + _EX(glVertexAttribDivisor); + _EXT(glVertexAttribDivisor); + _ARB(glVertexAttribDivisor); + + // stub non-squared matrix access + STUB(glUniformMatrix2x3fv); + STUB(glUniformMatrix3x2fv); + STUB(glUniformMatrix2x4fv); + STUB(glUniformMatrix4x2fv); + STUB(glUniformMatrix3x4fv); + STUB(glUniformMatrix4x3fv); + + + if (!globals4es.silentstub) LOGD("glXGetProcAddress: %s not found.\n", name); + return NULL; +} +#ifdef AMIGAOS4 +void* aglGetProcAddress(const char* name) AliasExport("gl4es_glXGetProcAddress"); +#else +void* glXGetProcAddress(const char* name) AliasExport("gl4es_glXGetProcAddress"); +void* glXGetProcAddressARB(const char* name) AliasExport("gl4es_glXGetProcAddress"); +#endif \ No newline at end of file diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/glx/rpi.c b/Projects/Android/jni/SupportLibs/gl4es/src/glx/rpi.c new file mode 100644 index 0000000..e2f6513 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/glx/rpi.c @@ -0,0 +1,126 @@ +#include +#include +#include +#include +#include + +#include "rpi.h" + +// Code specific to RPI +// everything is dynamicaly linked, so this can be saffely compiled everywhere +extern void* bcm_host; +extern void* vcos; + +extern void (*bcm_host_init)(); +extern void (*bcm_host_deinit)(); + +typedef uint32_t DISPMANX_DISPLAY_HANDLE_T; +typedef uint32_t DISPMANX_UPDATE_HANDLE_T; +typedef uint32_t DISPMANX_ELEMENT_HANDLE_T; +typedef uint32_t DISPMANX_RESOURCE_HANDLE_T; +typedef uint32_t DISPMANX_PROTECTION_T; +typedef uint32_t DISPMANX_FLAGS_ALPHA_T; +typedef struct tag_VC_RECT_T { + int32_t x; + int32_t y; + int32_t width; + int32_t height; +} VC_RECT_T; +typedef struct { + DISPMANX_ELEMENT_HANDLE_T element; + int width; + int height; +} EGL_DISPMANX_WINDOW_T; +typedef struct { + DISPMANX_FLAGS_ALPHA_T flags; + uint32_t opacity; + DISPMANX_RESOURCE_HANDLE_T mask; +} VC_DISPMANX_ALPHA_T; +int32_t (*graphics_get_display_size)(const uint16_t, uint32_t *, uint32_t*); +DISPMANX_DISPLAY_HANDLE_T (*vc_dispmanx_display_open)(uint32_t); +DISPMANX_UPDATE_HANDLE_T (*vc_dispmanx_update_start)(int32_t); +DISPMANX_ELEMENT_HANDLE_T (*vc_dispmanx_element_add)( + DISPMANX_UPDATE_HANDLE_T, DISPMANX_DISPLAY_HANDLE_T, int32_t, + VC_RECT_T *, DISPMANX_RESOURCE_HANDLE_T, + VC_RECT_T *, DISPMANX_PROTECTION_T, + /*VC_DISPMANX_ALPHA_T*/void*, /*DISPMANX_CLAMP_T*/void*, + /*DISPMANX_TRANSFORM_T*/ int32_t); +int (*vc_dispmanx_update_submit_sync)(DISPMANX_RESOURCE_HANDLE_T); +int (*vc_dispmanx_element_remove)(DISPMANX_UPDATE_HANDLE_T update, DISPMANX_ELEMENT_HANDLE_T element); +static DISPMANX_UPDATE_HANDLE_T dispman_update; +static DISPMANX_DISPLAY_HANDLE_T dispman_display; +static VC_RECT_T dst_rect; +static VC_RECT_T src_rect; + +static int rpi_inited = 0; +void rpi_init() { + if(!bcm_host || rpi_inited) + return; + rpi_inited++; + bcm_host_init = dlsym(bcm_host, "bcm_host_init"); + bcm_host_deinit = dlsym(bcm_host, "bcm_host_deinit"); + if(!bcm_host_init || !bcm_host_deinit) { + printf("LIBGL: Warning, bcm_host function missing (init=%p, deinit=%p)\n", bcm_host_init, bcm_host_deinit); + return; + } + bcm_host_init(); + + #define GO(A) A=dlsym(bcm_host, #A); if(A==NULL) A=dlsym(vcos, #A); if(A==NULL) printf("LIBGL: Warning, " #A " is null") + GO(graphics_get_display_size); + GO(vc_dispmanx_display_open); + GO(vc_dispmanx_update_start); + GO(vc_dispmanx_element_add); + GO(vc_dispmanx_update_submit_sync); + GO(vc_dispmanx_element_remove); + #undef GO +} + +void rpi_fini() { + if(!bcm_host || !rpi_inited) + return; + --rpi_inited; + if(!bcm_host_init || !bcm_host_deinit) + return; + bcm_host_deinit(); +} + +void* create_rpi_window(int w, int h) { + EGL_DISPMANX_WINDOW_T *nativewindow = (EGL_DISPMANX_WINDOW_T*)calloc(1, sizeof(EGL_DISPMANX_WINDOW_T)); + if(!bcm_host) return NULL; + // create a simple RPI nativewindow of size w*h, on output 0 (i.e. LCD)... + // code heavily inspired from Allegro 5.2 + uint32_t screenwidth, screenheight; + graphics_get_display_size(/*LCD*/ 0, &screenwidth, & screenheight); + if(w==0) w=screenwidth; + if(h==0) h=screenheight; + DISPMANX_ELEMENT_HANDLE_T dispman_element; + VC_RECT_T dst_rect, src_rect; + dst_rect.x = 0; dst_rect.y = 0; + dst_rect.width = screenwidth; + dst_rect.height = screenheight; + src_rect.x = 0; src_rect.y = 0; + src_rect.width = w << 16; + src_rect.height = h << 16; + dispman_display = vc_dispmanx_display_open(/*LCD*/ 0); + dispman_update = vc_dispmanx_update_start(0); + VC_DISPMANX_ALPHA_T alpha = { /*DISPMANX_FLAGS_ALPHA_FIXED_ALL_PIXELS*/ 1, 255, 0 }; + dispman_element = vc_dispmanx_element_add( + dispman_update,dispman_display, 0, &dst_rect, + 0, &src_rect, /*DISPMANX_PROTECTION_NONE*/ 0, &alpha, 0, + /*DISPMAN_NO_ROTATE*/ 0); + nativewindow->element = dispman_element; + nativewindow->width = w; + nativewindow->height = h; + vc_dispmanx_update_submit_sync(dispman_update); + + return nativewindow; +} + +void delete_rpi_window(void* win) { + EGL_DISPMANX_WINDOW_T* nativewindow = (EGL_DISPMANX_WINDOW_T*)win; + + vc_dispmanx_element_remove(dispman_update, nativewindow->element); + vc_dispmanx_update_submit_sync(dispman_update); + + free(win); +} diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/glx/rpi.h b/Projects/Android/jni/SupportLibs/gl4es/src/glx/rpi.h new file mode 100644 index 0000000..fe88950 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/glx/rpi.h @@ -0,0 +1,11 @@ +#ifndef _GLX_RPI_H_ +#define _GLX_RPI_H_ + +// Code specific to RPI + +void rpi_init(); +void rpi_fini(); +void* create_rpi_window(int w, int h); +void delete_rpi_window(void* win); + +#endif // _GLX_RPI_H_ diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/glx/streaming.c b/Projects/Android/jni/SupportLibs/gl4es/src/glx/streaming.c new file mode 100644 index 0000000..1b0b98f --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/glx/streaming.c @@ -0,0 +1,295 @@ +/* + Helper fonctions for Streaming textures +*/ +#ifdef TEXSTREAM + +#include +#include +#include +#include +#include + +#include "streaming.h" + +#include "../gl/loader.h" +#include "../gl/gles.h" + +PFNGLTEXBINDSTREAMIMGPROC *glTexBindStreamIMG = NULL; +PFNGLGETTEXSTREAMDEVICEATTRIBUTEIVIMGPROC *glGetTexAttrIMG = NULL; +PFNGLGETTEXSTREAMDEVICENAMEIMGPROC *glGetTexDeviceIMG = NULL; + +//extern void* eglGetProcAddress(const char*); + +int gl_streaming = 0; +int gl_streaming_initialized = 0; +int bc_cat[10]; +int tex_free[10]; +const GLubyte * bcdev[10]; +int bcdev_w, bcdev_h, bcdev_n; +int bcdev_fmt; +unsigned long buf_paddr[10]; // physical address +char *buf_vaddr[10]; // virtual adress + +void Streaming_Initialize() { + LOAD_EGL(eglGetProcAddress); + if (gl_streaming_initialized) + return; + // get the extension functions + gl_streaming_initialized = 1; + glTexBindStreamIMG =(PFNGLTEXBINDSTREAMIMGPROC*)egl_eglGetProcAddress("glTexBindStreamIMG"); + glGetTexAttrIMG = (PFNGLGETTEXSTREAMDEVICEATTRIBUTEIVIMGPROC*)egl_eglGetProcAddress("glGetTexStreamDeviceAttributeivIMG"); + glGetTexDeviceIMG = (PFNGLGETTEXSTREAMDEVICENAMEIMGPROC*)egl_eglGetProcAddress("glGetTexStreamDeviceNameIMG"); + + if (!glTexBindStreamIMG || !glGetTexAttrIMG || !glGetTexDeviceIMG) { + gl_streaming = 0; + return; + } + gl_streaming = 1; + // initialise the bc_cat ids + for (int i=0; i<10; i++) { + bc_cat[i] = -1; + tex_free[i] = 1; + } +} + +int open_bccat(int i) { + if (bc_cat[i]>-1) + return bc_cat[i]; + char buff[]="/dev/bccat0"; + buff[strlen(buff)-1]='0'+i; + bc_cat[i] = open(buff, O_RDWR|O_NDELAY); + return bc_cat[i]; +} +void close_bccat(int i) { + if (bc_cat[i]==-1) + return; + close(bc_cat[i]); + bc_cat[i]=-1; + return; +} + +int alloc_buff(int buff, int width, int height) { + if (!gl_streaming_initialized) + Streaming_Initialize; + if (!gl_streaming) + return 0; + if ((buff<0) || (buff>9)) + return 0; + if (!tex_free[buff]) + return 0; + if (open_bccat(buff)<0) + return 0; + BCIO_package ioctl_var; + bc_buf_params_t buf_param; + buf_param.count = 1; // only 1 buffer? + buf_param.width = width; + buf_param.height = height; + buf_param.fourcc = BC_PIX_FMT_RGB565; // only RGB565 here (other choices are only some YUV formats) + buf_param.type = BC_MEMORY_MMAP; + if (ioctl(bc_cat[buff], BCIOREQ_BUFFERS, &buf_param) != 0) { + printf("LIBGL: BCIOREQ_BUFFERS failed\n"); + return 0; + } + if (ioctl(bc_cat[buff], BCIOGET_BUFFERCOUNT, &ioctl_var) != 0) { + printf("LIBGL: BCIOREQ_BUFFERCOUNT failed\n"); + return 0; + } + if (ioctl_var.output == 0) { + printf("LIBGL: Streaming, no texture buffer available\n"); + return 0; + } + const char *bcdev = glGetTexDeviceIMG(buff); + if (!bcdev) { + printf("LIBGL: problem with getting the GL_IMG_texture_stream device\n"); + return 0; + } else { + bcdev_w = width; + bcdev_h = height; + bcdev_n = 1; + glGetTexAttrIMG(buff, GL_TEXTURE_STREAM_DEVICE_NUM_BUFFERS_IMG, &bcdev_n); + glGetTexAttrIMG(buff, GL_TEXTURE_STREAM_DEVICE_WIDTH_IMG, &bcdev_w); + glGetTexAttrIMG(buff, GL_TEXTURE_STREAM_DEVICE_HEIGHT_IMG, &bcdev_h); + glGetTexAttrIMG(buff, GL_TEXTURE_STREAM_DEVICE_FORMAT_IMG, &bcdev_fmt); + printf("LIBGL: Streaming device = %s num: %d, width: %d, height: %d, format: 0x%x\n", + bcdev, bcdev_n, bcdev_w, bcdev_h, bcdev_fmt); + if (bcdev_w!=width) { + printf("LIBGL: Streaming not activate, buffer width != asked width\n"); + return 0; + } + } +/* LOAD_GLES(glTexParameterf); + gles_glTexParameterf(GL_TEXTURE_STREAM_IMG, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + gles_glTexParameterf(GL_TEXTURE_STREAM_IMG, GL_TEXTURE_MAG_FILTER, GL_LINEAR);*/ + + ioctl_var.input = 0; + if (ioctl(bc_cat[buff], BCIOGET_BUFFERPHYADDR, &ioctl_var) != 0) { + printf("LIBGL: BCIOGET_BUFFERADDR failed\n"); + return 0; + } else { + buf_paddr[buff] = ioctl_var.output; + buf_vaddr[buff] = (char *)mmap(NULL, width*height*2, + PROT_READ | PROT_WRITE, MAP_SHARED, + bc_cat[buff], buf_paddr[buff]); + + if (buf_vaddr[buff] == MAP_FAILED) { + printf("LIBGL: mmap failed\n"); + return 0; + } + } + + // All done! + tex_free[buff] = 0; + return 1; +} + +int free_buff(int buff) { + if (!gl_streaming) + return 0; + if ((buff<0) || (buff>9)) + return 0; + close_bccat(buff); + tex_free[buff] = 1; + return 1; +} + + +/* + Streaming Cache functions +*/ + +int streaming_inited = 0; + +typedef struct { + int active; + unsigned int last; // to get the age of last update + unsigned int texID; // ID of texture +} glstreaming_t; +glstreaming_t stream_cache[10]; +unsigned int frame_number; + +// Function to start the Streaming texture Cache +int InitStreamingCache() { +//printf("InitStreamingCache\n"); + if (streaming_inited) + return gl_streaming; + Streaming_Initialize(); + for (int i=0; i<10; i++) { + stream_cache[i].active = 0; + stream_cache[i].last = 0; + stream_cache[i].texID = 0; + } + frame_number = 0; + streaming_inited = 1; + return gl_streaming; +} + +// Function to get a Streaming buffer address +void* GetStreamingBuffer(int buff) { +//printf("GetStreamingBuffer(%i)\n", buff); + if (!gl_streaming) + return NULL; + if ((buff<0) || (buff>9)) + return NULL; + if (tex_free[buff]) + return NULL; + stream_cache[buff].last = frame_number; + return buf_vaddr[buff]; +} + +// Function to add a new texture of size Width*Height, with fake Texture ID "ID". Return the ID or -1 if failed. +int AddStreamed(int width, int height, unsigned int ID) { +//printf("AddStreamed(%i, %i, %u)\n", width, height, ID); + if (!gl_streaming) + return -1; + static int i =0; + int j=0; + while (j<10) { + int k = (i+j)%10; + if (tex_free[k]) { + if (alloc_buff(k, width, height)) { + stream_cache[k].active = 1; + stream_cache[k].last = frame_number; + stream_cache[k].texID = ID; + i = (i+j+1)%10; + return k; + } else { + return -1; // Probably useless to try again and again + } + } + j++; + } + return -1; +} + +// Function to free a streamed texture ID +void FreeStreamed(int ID) { +//printf("FreeStreamed(%i)", ID); + if (!gl_streaming) + return; + if ((ID<0) || (ID>9)) + return; + if (tex_free[ID]) + return; + if (!stream_cache[ID].active) + return; + + free_buff(ID); + stream_cache[ID].active = 0; + stream_cache[ID].texID = 0; +} + +// Function to find a StreamingID with a TextureID. G-1 if not found +int FindTexID(unsigned int ID) { +//printf("FindTexID(%u)\n", ID); + if (!gl_streaming) + return -1; + int i =0; + while (i<10) { + if (stream_cache[i].texID==ID) + return i; + i++; + } + return -1; +} + +// Function to apply Min& Mag filter to Streaming texture +void ApplyFilterID(int ID, GLenum min_filter, GLenum mag_filter) { +//printf("ApplyFilterID(%i, 0x%04X, 0x%04X)\n", ID, min_filter, mag_filter); + if (!gl_streaming) + return; + if ((ID<0) || (ID>9)) + return; + if (tex_free[ID]) + return; + if (!stream_cache[ID].active) + return; + gl4es_glTexParameterf(GL_TEXTURE_STREAM_IMG, GL_TEXTURE_MIN_FILTER, min_filter); + gl4es_glTexParameterf(GL_TEXTURE_STREAM_IMG, GL_TEXTURE_MAG_FILTER, mag_filter); +} + +// Function to activate the Steaming texture ID on current tex... +void ActivateStreaming(int ID) { +//printf("ActivateStreaming(%i)\n", ID); + LOAD_GLES(glEnable); + if (!gl_streaming) + return; + if ((ID<0) || (ID>9)) + return; + if (tex_free[ID]) + return; + if (!stream_cache[ID].active) + return; + +// gles_glEnable(GL_TEXTURE_STREAM_IMG); + glTexBindStreamIMG(ID, 0); +} + +// Function to deactivate the Streaming texture on current tex... +void DeactivateStreaming() { +//printf("DeactivateStreaming()\n"); + LOAD_GLES(glDisable); + if (!gl_streaming) + return; +// gles_glDisable(GL_TEXTURE_STREAM_IMG); +} +#endif //TEXSTREAM diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/glx/streaming.h b/Projects/Android/jni/SupportLibs/gl4es/src/glx/streaming.h new file mode 100644 index 0000000..86b506b --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/glx/streaming.h @@ -0,0 +1,46 @@ +#ifndef _GLX_STREAMING_H_ +#define _GLX_STREAMING_H_ + +#ifdef TEXSTREAM +#include "../gl/gl4es.h" + +#ifndef GL_APIENTRYP +#define GL_APIENTRYP +#endif +#ifndef GL_IMG_texture_stream +#define GL_TEXTURE_STREAM_IMG 0x8C0D +#define GL_TEXTURE_NUM_STREAM_DEVICES_IMG 0x8C0E +#define GL_TEXTURE_STREAM_DEVICE_WIDTH_IMG 0x8C0F +#define GL_TEXTURE_STREAM_DEVICE_HEIGHT_IMG 0x8EA0 +#define GL_TEXTURE_STREAM_DEVICE_FORMAT_IMG 0x8EA1 +#define GL_TEXTURE_STREAM_DEVICE_NUM_BUFFERS_IMG 0x8EA2 +typedef void (GL_APIENTRYP PFNGLTEXBINDSTREAMIMGPROC) (GLint device, GLint deviceoffset); +typedef const GLubyte *(GL_APIENTRYP PFNGLGETTEXSTREAMDEVICENAMEIMGPROC) (GLenum target); +typedef void (GL_APIENTRYP PFNGLGETTEXSTREAMDEVICEATTRIBUTEIVIMGPROC) (GLenum target, GLenum pname, GLint *params); +#define GL_IMG_texture_stream 1 +#endif + +extern PFNGLTEXBINDSTREAMIMGPROC *glTexBindStreamIMG; +extern PFNGLGETTEXSTREAMDEVICEATTRIBUTEIVIMGPROC *glGetTexAttrIMG; +extern PFNGLGETTEXSTREAMDEVICENAMEIMGPROC *glGetTexDeviceIMG; + +extern int gl_stream; //0 if no streaming not 0 if streaming available + +// Function to start the Streaming texture Cache. Return 0 if failed, non-0 if OK. +int InitStreamingCache(); +// Function to get a Streaming buffer address +void* GetStreamingBuffer(int buff); +// Function to add a new texture of size Width*Height, with fake Texture ID "ID". Return the StreamingID or -1 if failed. +int AddStreamed(int width, int height, unsigned int ID); +// Function to free a streamed texture ID +void FreeStreamed(int ID); +// Function to find a StreamingID with a TextureID. G-1 if not found +int FindTexID(unsigned int ID); +// Function to apply Min& Mag filter to Streaming texture +void ApplyFilterID(int ID, GLenum min_filter, GLenum mag_filter); +// Function to activate the Steaming texture ID on current tex... +void ActivateStreaming(int ID); +// Function to deactivate the Streaming texture on current tex... +void DeactivateStreaming(); +#endif // TEXSTREAM +#endif // _GLX_STREAMING_H_ diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/glx/utils.c b/Projects/Android/jni/SupportLibs/gl4es/src/glx/utils.c new file mode 100644 index 0000000..a771f32 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/glx/utils.c @@ -0,0 +1,91 @@ +#include "utils.h" +/* + * Generate OpenGL-compatible bitmap. + * From Mesa-9.0.1 + */ +#ifndef NOX11 + +void +fill_bitmap(Display * dpy, Window win, GC gc, + unsigned int width, unsigned int height, + int x0, int y0, unsigned int c, GLubyte * bitmap) +{ + XImage *image; + unsigned int x, y; + Pixmap pixmap; + XChar2b char2b; + + pixmap = XCreatePixmap(dpy, win, 8 * width, height, 1); + XSetForeground(dpy, gc, 0); + XFillRectangle(dpy, pixmap, gc, 0, 0, 8 * width, height); + XSetForeground(dpy, gc, 1); + + char2b.byte1 = (c >> 8) & 0xff; + char2b.byte2 = (c & 0xff); + + XDrawString16(dpy, pixmap, gc, x0, y0, &char2b, 1); + + image = XGetImage(dpy, pixmap, 0, 0, 8 * width, height, 1, XYPixmap); + if (image) { + /* Fill the bitmap (X11 and OpenGL are upside down wrt each other). */ + for (y = 0; y < height; y++) + for (x = 0; x < 8 * width; x++) + if (XGetPixel(image, x, y)) + bitmap[width * (height - y - 1) + x / 8] |= + (1 << (7 - (x % 8))); + XDestroyImage(image); + } + + XFreePixmap(dpy, pixmap); +} +/* + * determine if a given glyph is valid and return the + * corresponding XCharStruct. + * From MesaGL-9.0.1 + */ +XCharStruct * +isvalid(XFontStruct * fs, int which) +{ + unsigned int rows, pages; + int byte1 = 0, byte2 = 0; + int i, valid = 1; + + rows = fs->max_byte1 - fs->min_byte1 + 1; + pages = fs->max_char_or_byte2 - fs->min_char_or_byte2 + 1; + + if (rows == 1) { + /* "linear" fonts */ + if ((fs->min_char_or_byte2 > which) || (fs->max_char_or_byte2 < which)) + valid = 0; + } + else { + /* "matrix" fonts */ + byte2 = which & 0xff; + byte1 = which >> 8; + if ((fs->min_char_or_byte2 > byte2) || + (fs->max_char_or_byte2 < byte2) || + (fs->min_byte1 > byte1) || (fs->max_byte1 < byte1)) + valid = 0; + } + + if (valid) { + if (fs->per_char) { + if (rows == 1) { + /* "linear" fonts */ + return (fs->per_char + (which - fs->min_char_or_byte2)); + } + else { + /* "matrix" fonts */ + i = ((byte1 - fs->min_byte1) * pages) + + (byte2 - fs->min_char_or_byte2); + return (fs->per_char + i); + } + } + else { + return (&fs->min_bounds); + } + } + return (NULL); +} + +#endif //NOX11 \ No newline at end of file diff --git a/Projects/Android/jni/SupportLibs/gl4es/src/glx/utils.h b/Projects/Android/jni/SupportLibs/gl4es/src/glx/utils.h new file mode 100644 index 0000000..cf12714 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/src/glx/utils.h @@ -0,0 +1,21 @@ +#ifndef _GLX_UTILS_H_ +#define _GLX_UTILS_H_ + +#ifndef NOX11 +#include +#include +#endif // NOX11 +#include +#include + +#include "../gl/gl4es.h" +#ifndef NOX11 +void +fill_bitmap(Display * dpy, Window win, GC gc, + unsigned int width, unsigned int height, + int x0, int y0, unsigned int c, GLubyte * bitmap); + +XCharStruct * +isvalid(XFontStruct * fs, int which); +#endif // NOX11 +#endif // _GLX_UTILS_H_ diff --git a/Projects/Android/jni/SupportLibs/gl4es/test.cmake b/Projects/Android/jni/SupportLibs/gl4es/test.cmake new file mode 100644 index 0000000..a303f6a --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/test.cmake @@ -0,0 +1,62 @@ +# Check if all required arguments are provided +macro(argument_required argument failstring) + if (NOT ${argument}) + message(FATAL_ERROR ${failstring}) + endif (NOT ${argument}) +endmacro(argument_required) + +argument_required(LIBRARY_FOLDER "All tests require to have a library output folder.") +argument_required(TESTS_DIRECTORY "All tests require to have a test folder.") +argument_required(TEST_FILENAME "All tests require a trace filename to be reprinted.") +argument_required(CALLS "All tests require a call count.") + +# Enable different GLES version tests +if (GLES_FORCED) + set(GLES${GLES_FORCED}_ENABLED ON) +else (GLES_FORCED) + set(GLES1_ENABLED ON) + set(GLES2_ENABLED ON) +endif (GLES_FORCED) + +# Special case fo pixels tolerance +if (TOLERANCE) + set(TOLERANCE_GLES1 ${TOLERANCE}) + set(TOLERANCE_GLES2 ${TOLERANCE}) +endif (TOLERANCE) + +# Use the built library +set(ENV{LD_LIBRARY_PATH} ${LIBRARY_FOLDER}:$ENV{LD_LIBRARY_PATH}) + +macro(run_test GLES) + if (GLES${GLES}_ENABLED) + argument_required(TOLERANCE_GLES${GLES} "All tests require a pixel tolerance for GLES ${GLES}.") + + set(ENV{LIBGL_ES} ${GLES}) + + message(STATUS "Starting test in GLES ${GLES}...") + execute_process( + COMMAND ${TESTS_DIRECTORY}/test.sh + ${TEST_FILENAME} + ${CALLS} + ${TOLERANCE_GLES${GLES}} + ${EXTRACT_RANGE} + ERROR_VARIABLE TEST_ERROR + OUTPUT_VARIABLE TEST_OUTPUT + WORKING_DIRECTORY ${TESTS_DIRECTORY} + ) + message(STATUS "Ran test.\nError: ${TEST_ERROR}\nOutput: ${TEST_OUTPUT}") + + if (TEST_OUTPUT) + set(ERROR ${ERROR} ${GLES}) + endif (TEST_OUTPUT) + endif (GLES${GLES}_ENABLED) +endmacro(run_test) + +run_test(1) +run_test(2) + +if (ERROR) + message(FATAL_ERROR "Test(s) failed while using GLES ${ERROR}") +endif (ERROR) + +message(STATUS "Success.") diff --git a/Projects/Android/jni/SupportLibs/gl4es/tests/test.sh b/Projects/Android/jni/SupportLibs/gl4es/tests/test.sh new file mode 100644 index 0000000..fea4368 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/tests/test.sh @@ -0,0 +1,35 @@ +#!/bin/bash +# +# WARNING: do not execute this file unless you are aware of what you're doing. +# This file is meant to be executed by ctest. + +export LIBGL_FB=3 +export LIBGL_SILENTSTUB=1 +export LIBGL_NOBANNER=1 + +tar xf ../traces/$1.tgz +apitrace dump-images --calls="$2" $1.trace >/dev/null +rm $1.trace + +if [[ -f $1.$2.png ]] +then + mv $1.$2.png $1.$2.$LIBGL_ES.png + + EXTRACT="" + if [[ ! -z "$4" ]] + then + EXTRACT="-extract $4" + fi + result=$(compare -metric AE -fuzz 20% $EXTRACT ../refs/$1.$2.png $1.$2.$LIBGL_ES.png diff_$1_GLES$LIBGL_ES.png 2>&1) + + if [[ ! "$result" -lt "$3" ]] + then + echo -n "$result pixels of difference" + exit 1 + fi + + [[ -e diff_$1_GLES$LIBGL_ES.png ]] && rm diff_$1_GLES$LIBGL_ES.png + [[ -e $1.$2.$LIBGL_ES.png ]] && rm $1.$2.$LIBGL_ES.png +fi + +exit 0 diff --git a/Projects/Android/jni/SupportLibs/gl4es/tests/tests.sh b/Projects/Android/jni/SupportLibs/gl4es/tests/tests.sh new file mode 100644 index 0000000..c93b9f8 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/tests/tests.sh @@ -0,0 +1,198 @@ +#!/bin/bash + +function clean_tests { + #glxgears + if [ -e glxgears.0000008203.png ];then + rm glxgears.0000008203.png + fi + if [ -e glxgears.trace ];then + rm glxgears.trace + fi + #stunt car racer + if [ -e stuntcarracer.0000118817.png ];then + rm stuntcarracer.0000118817.png + fi + if [ -e stuntcarracer.trace ];then + rm stuntcarracer.trace + fi + #neverball + if [ -e neverball.0000078750.png ];then + rm neverball.0000078750.png + fi + if [ -e neverball.trace ];then + rm neverball.trace + fi + #foobillardplus + if [ -e foobillardplus.0000014748.png ];then + rm foobillardplus.0000014748.png + fi + if [ -e foobillardplus.trace ];then + rm foobillardplus.trace + fi + #openra + if [ -e openra.0000031249.png ];then + rm openra.0000031249.png + fi + if [ -e openra.trace ];then + rm openra.trace + fi + #glsl_lighting + if [ -e glsl_lighting.0000505393.png ];then + rm glsl_lighting.0000505393.png + fi + if [ -e glsl_lighting.trace ];then + rm glsl_lighting.trace + fi + #pointsprite + if [ -e pointsprite.0000248810.png ];then + rm pointsprite.0000248810.png + fi + if [ -e pointsprite.trace ];then + rm pointsprite.trace + fi + #diff result + if [ -e diff.png ];then + rm diff.png + fi +} + +export OK=1 +function launch_test { + tar xf ../traces/$1.tgz + if [ "$BENCH" = "1" ];then + glretrace -b $1.trace + else + apitrace dump-images --calls="$2" $1.trace + EXTRACT="" + if [ ! -z "$4" ];then + EXTRACT="-extract $4" + fi + result=$(compare -metric AE -fuzz 20% $EXTRACT ../refs/$1.$2.png $1.$2.png diff.png 2>&1) + if [ ! "$result" -lt "$3" ];then + popd >/dev/null + echo "error, $result pixels diff" + export OK=0 + fi + fi +} + +function banner { + echo + echo " ******************* " + if [ "$BENCH" = "1" ];then + echo " Bench $1 " + else + echo " $1 " + fi + echo " ------------------- " +} + +export BENCH=0 +if [ "$1" = "-b" ];then + BENCH=1 + shift +fi +if [ "$2" = "-b" ];then + BENCH=1 +fi + +if [ ! -z "$1" ];then + export LD_LIBRARY_PATH=$1:$LD_LIBRARY_PATH +fi + +if [ ! "$BENCH" = "1" ];then + export LIBGL_FB=3 +fi +export LIBGL_SILENTSTUB=1 +export LIBGL_NOBANNER=1 + +TESTS=`dirname "$0"` + +pushd "$TESTS" >/dev/null + +clean_tests + +export LIBGL_ES=1 + +banner "GLES1.1: glxgears" +launch_test glxgears 0000008203 25 +if [ $OK = 0 ];then + exit 1 +fi + +banner "GLES1.1: StuntCarRacer" +launch_test stuntcarracer 0000118817 20 638x478+1+1 +if [ $OK = 0 ];then + exit 1 +fi + +banner "GLES1.1: Neverball" +launch_test neverball 0000078750 20 798x478+1+1 +if [ $OK = 0 ];then + exit 1 +fi + +banner "GLES1.1: Foobillard Plus" +launch_test foobillardplus 0000014748 20 798x478+1+1 +if [ $OK = 0 ];then + exit 1 +fi + +banner "GLES1.1: Point Sprite" +launch_test pointsprite 0000248810 20 +if [ $OK = 0 ];then + exit 1 +fi + +export LIBGL_ES=2 + +banner "GLES2.0: OpenRA" +launch_test openra 0000031249 20 638x478+1+1 +if [ $OK = 0 ];then + exit 1 +fi + +banner "GLES2.0: glsl_lighting" +launch_test glsl_lighting 0000505393 20 +if [ $OK = 0 ];then + exit 1 +fi + +banner "GLES2.0: glxgears" +# Because FlatShaded mode is not supported, the image is more different. +launch_test glxgears 0000008203 700 +if [ $OK = 0 ];then + exit 1 +fi + +banner "GLES2.0: StuntCarRacer" +launch_test stuntcarracer 0000118817 20 638x478+1+1 +if [ $OK = 0 ];then + exit 1 +fi + +banner "GLES2.0: Neverball" +launch_test neverball 0000078750 200 798x478+1+1 +if [ $OK = 0 ];then + exit 1 +fi + +banner "GLES2.0: Foobillard Plus" +launch_test foobillardplus 0000014748 50 798x478+1+1 +if [ $OK = 0 ];then + exit 1 +fi + +banner "GLES2.0: Point Sprite" +launch_test pointsprite 0000248810 20 +if [ $OK = 0 ];then + exit 1 +fi + +# cleanup +clean_tests + +popd >/dev/null +echo " ================= " +echo "All done" +exit 0 diff --git a/Projects/Android/jni/SupportLibs/gl4es/traces/foobillardplus.tgz b/Projects/Android/jni/SupportLibs/gl4es/traces/foobillardplus.tgz new file mode 100644 index 0000000..3f1fe3c Binary files /dev/null and b/Projects/Android/jni/SupportLibs/gl4es/traces/foobillardplus.tgz differ diff --git a/Projects/Android/jni/SupportLibs/gl4es/traces/glsl_lighting.tgz b/Projects/Android/jni/SupportLibs/gl4es/traces/glsl_lighting.tgz new file mode 100644 index 0000000..2028a78 Binary files /dev/null and b/Projects/Android/jni/SupportLibs/gl4es/traces/glsl_lighting.tgz differ diff --git a/Projects/Android/jni/SupportLibs/gl4es/traces/glxgears.tgz b/Projects/Android/jni/SupportLibs/gl4es/traces/glxgears.tgz new file mode 100644 index 0000000..f70ba48 Binary files /dev/null and b/Projects/Android/jni/SupportLibs/gl4es/traces/glxgears.tgz differ diff --git a/Projects/Android/jni/SupportLibs/gl4es/traces/neverball.tgz b/Projects/Android/jni/SupportLibs/gl4es/traces/neverball.tgz new file mode 100644 index 0000000..e0cce21 Binary files /dev/null and b/Projects/Android/jni/SupportLibs/gl4es/traces/neverball.tgz differ diff --git a/Projects/Android/jni/SupportLibs/gl4es/traces/openra.tgz b/Projects/Android/jni/SupportLibs/gl4es/traces/openra.tgz new file mode 100644 index 0000000..1179ba1 Binary files /dev/null and b/Projects/Android/jni/SupportLibs/gl4es/traces/openra.tgz differ diff --git a/Projects/Android/jni/SupportLibs/gl4es/traces/pointsprite.tgz b/Projects/Android/jni/SupportLibs/gl4es/traces/pointsprite.tgz new file mode 100644 index 0000000..7229a26 Binary files /dev/null and b/Projects/Android/jni/SupportLibs/gl4es/traces/pointsprite.tgz differ diff --git a/Projects/Android/jni/SupportLibs/gl4es/traces/stuntcarracer.tgz b/Projects/Android/jni/SupportLibs/gl4es/traces/stuntcarracer.tgz new file mode 100644 index 0000000..aa59fbf Binary files /dev/null and b/Projects/Android/jni/SupportLibs/gl4es/traces/stuntcarracer.tgz differ diff --git a/Projects/Android/jni/SupportLibs/gl4es/version.h b/Projects/Android/jni/SupportLibs/gl4es/version.h new file mode 100644 index 0000000..72d6992 --- /dev/null +++ b/Projects/Android/jni/SupportLibs/gl4es/version.h @@ -0,0 +1,8 @@ +#ifndef _GL4ES_VERSION_H +#define _GL4ES_VERSION_H + +#define MAJOR 1 +#define MINOR 1 +#define REVISION 1 + +#endif //_GL4ES_VERSION_H diff --git a/Projects/Android/jni/rtcw/Android.mk b/Projects/Android/jni/rtcw/Android.mk new file mode 100644 index 0000000..129173e --- /dev/null +++ b/Projects/Android/jni/rtcw/Android.mk @@ -0,0 +1,19 @@ + + +RTCW_BASE_CFLAGS = \ +-fsigned-char \ + -march=armv7-a -mfloat-abi=softfp \ + -DNDEBUG -DNDEBUG -Ofast -fomit-frame-pointer -ffast-math -fno-strict-aliasing -fstrength-reduce -ftree-vectorize -fsingle-precision-constant \ + -pipe -DPANDORA -DHAVE_GLES -DARM -DC_ONLY \ + -DAUTOAIM + +#-DNEON -mfpu=neon + +RTCW_BASE_LDFLAGS = \ +-Wl,--fix-cortex-a8 -llog + +include $(TOP_DIR)/rtcw/Android_game.mk +include $(TOP_DIR)/rtcw/Android_ui.mk +include $(TOP_DIR)/rtcw/Android_cgame.mk +include $(TOP_DIR)/rtcw/Android_client.mk + diff --git a/Projects/Android/jni/rtcw/Android_cgame.mk b/Projects/Android/jni/rtcw/Android_cgame.mk new file mode 100644 index 0000000..03fd7e9 --- /dev/null +++ b/Projects/Android/jni/rtcw/Android_cgame.mk @@ -0,0 +1,64 @@ +LOCAL_PATH := $(call my-dir) + + + +include $(CLEAR_VARS) + + +LOCAL_MODULE := cgamearm + +LOCAL_CFLAGS = $(RTCW_BASE_CFLAGS) + + +LOCAL_CFLAGS += -fPIC -DCGAMEDLL + +LOCAL_LDFLAGS += $(RTCW_BASE_LDFLAGS) + +LOCAL_C_INCLUDES = $(LOCAL_PATH) + + + +GAME_FILES = \ + src/game/bg_animation.c\ + src/game/bg_misc.c\ + src/game/bg_pmove.c\ + src/game/bg_slidemove.c\ + src/cgame/cg_consolecmds.c\ + src/cgame/cg_draw.c\ + src/cgame/cg_drawtools.c\ + src/cgame/cg_effects.c\ + src/cgame/cg_ents.c\ + src/cgame/cg_event.c\ + src/cgame/cg_flamethrower.c\ + src/cgame/cg_info.c\ + src/cgame/cg_localents.c\ + src/cgame/cg_main.c\ + src/cgame/cg_marks.c\ + src/cgame/cg_newDraw.c\ + src/cgame/cg_particles.c\ + src/cgame/cg_players.c\ + src/cgame/cg_playerstate.c\ + src/cgame/cg_predict.c\ + src/cgame/cg_scoreboard.c\ + src/cgame/cg_servercmds.c\ + src/cgame/cg_snapshot.c\ + src/cgame/cg_sound.c\ + src/cgame/cg_syscalls.c\ + src/cgame/cg_trails.c\ + src/cgame/cg_view.c\ + src/cgame/cg_weapons.c\ + src/game/q_math.c\ + src/game/q_shared.c\ + src/ui/ui_shared.c\ + + + +LOCAL_SRC_FILES = $(GAME_FILES) + +include $(BUILD_SHARED_LIBRARY) + + + + + + diff --git a/Projects/Android/jni/rtcw/Android_client.mk b/Projects/Android/jni/rtcw/Android_client.mk new file mode 100644 index 0000000..02cde4e --- /dev/null +++ b/Projects/Android/jni/rtcw/Android_client.mk @@ -0,0 +1,214 @@ +LOCAL_PATH := $(call my-dir) + + + +include $(CLEAR_VARS) + + +LOCAL_MODULE := rtcw_client + + +LOCAL_CFLAGS = $(RTCW_BASE_CFLAGS) -DBOTLIB + +LOCAL_LDFLAGS = $(RTCW_BASE_LDFLAGS) + +LOCAL_C_INCLUDES = $(LOCAL_PATH) + + +ANDROID_SRC = \ + code/android/android-jni.cpp \ + code/android/in_android.c \ + code/android/ifaddrs.c \ + +SPLINES_FILES = \ + src/splines/math_angles.cpp \ + src/splines/math_matrix.cpp \ + src/splines/math_quaternion.cpp \ + src/splines/math_vector.cpp \ + src/splines/q_parse.cpp \ + src/splines/splines.cpp \ + src/splines/util_str.cpp \ + #src/splines/q_shared.cpp \ + + +BOTLIB_FILES = \ + src/botlib/be_aas_bspq3.c \ + src/botlib/be_aas_cluster.c \ + src/botlib/be_aas_debug.c \ + src/botlib/be_aas_entity.c \ + src/botlib/be_aas_file.c \ + src/botlib/be_aas_main.c \ + src/botlib/be_aas_move.c \ + src/botlib/be_aas_optimize.c \ + src/botlib/be_aas_reach.c \ + src/botlib/be_aas_route.c \ + src/botlib/be_aas_routealt.c \ + src/botlib/be_aas_routetable.c \ + src/botlib/be_aas_sample.c \ + src/botlib/be_ai_char.c \ + src/botlib/be_ai_chat.c \ + src/botlib/be_ai_gen.c \ + src/botlib/be_ai_goal.c \ + src/botlib/be_ai_move.c \ + src/botlib/be_ai_weap.c \ + src/botlib/be_ai_weight.c \ + src/botlib/be_ea.c \ + src/botlib/be_interface.c \ + src/botlib/l_crc.c \ + src/botlib/l_libvar.c \ + src/botlib/l_log.c \ + src/botlib/l_memory.c \ + src/botlib/l_precomp.c \ + src/botlib/l_script.c \ + src/botlib/l_struct.c \ + +JPEGLIB_FILES = \ + src/jpeg-6/jcapimin.c \ + src/jpeg-6/jchuff.c \ + src/jpeg-6/jcinit.c \ + src/jpeg-6/jccoefct.c \ + src/jpeg-6/jccolor.c \ + src/jpeg-6/jfdctflt.c \ + src/jpeg-6/jcdctmgr.c \ + src/jpeg-6/jcphuff.c \ + src/jpeg-6/jcmainct.c \ + src/jpeg-6/jcmarker.c \ + src/jpeg-6/jcmaster.c \ + src/jpeg-6/jcomapi.c \ + src/jpeg-6/jcparam.c \ + src/jpeg-6/jcprepct.c \ + src/jpeg-6/jcsample.c \ + src/jpeg-6/jdapimin.c \ + src/jpeg-6/jdapistd.c \ + src/jpeg-6/jdatasrc.c \ + src/jpeg-6/jdcoefct.c \ + src/jpeg-6/jdcolor.c \ + src/jpeg-6/jddctmgr.c \ + src/jpeg-6/jdhuff.c \ + src/jpeg-6/jdinput.c \ + src/jpeg-6/jdmainct.c \ + src/jpeg-6/jdmarker.c \ + src/jpeg-6/jdmaster.c \ + src/jpeg-6/jdpostct.c \ + src/jpeg-6/jdsample.c \ + src/jpeg-6/jdtrans.c \ + src/jpeg-6/jerror.c \ + src/jpeg-6/jidctflt.c \ + src/jpeg-6/jmemmgr.c \ + src/jpeg-6/jmemnobs.c \ + src/jpeg-6/jutils.c \ + + +RENDERER_FILES = \ + src/renderer/tr_animation.c \ + src/renderer/tr_backend.c \ + src/renderer/tr_bsp.c \ + src/renderer/tr_cmds.c \ + src/renderer/tr_cmesh.c \ + src/renderer/tr_curve.c \ + src/renderer/tr_flares.c \ + src/renderer/tr_font.c \ + src/renderer/tr_image.c \ + src/renderer/tr_init.c \ + src/renderer/tr_light.c \ + src/renderer/tr_main.c \ + src/renderer/tr_marks.c \ + src/renderer/tr_mesh.c \ + src/renderer/tr_model.c \ + src/renderer/tr_noise.c \ + src/renderer/tr_scene.c \ + src/renderer/tr_shade.c \ + src/renderer/tr_shade_calc.c \ + src/renderer/tr_shader.c \ + src/renderer/tr_shadows.c \ + src/renderer/tr_sky.c \ + src/renderer/tr_surface.c \ + src/renderer/tr_world.c \ + + + +CLIENT_FILES = \ + src/client/cl_cgame.c \ + src/client/cl_cin.c \ + src/client/cl_console.c \ + src/client/cl_input.c \ + src/client/cl_keys.c \ + src/client/cl_main.c \ + src/client/cl_net_chan.c \ + src/client/cl_parse.c \ + src/client/cl_scrn.c \ + src/client/cl_ui.c \ + +COMMON_FILES = \ + src/qcommon/cm_load.c \ + src/qcommon/cm_patch.c \ + src/qcommon/cm_polylib.c \ + src/qcommon/cm_test.c \ + src/qcommon/cm_trace.c \ + src/qcommon/cmd.c \ + src/qcommon/common.c \ + src/qcommon/cvar.c \ + src/qcommon/files.c \ + src/qcommon/md4.c \ + src/qcommon/msg.c \ + src/qcommon/net_chan.c \ + src/qcommon/huffman.c \ + src/qcommon/unzip.c \ + + +SOUND_FILES = \ + src/client/snd_adpcm.c \ + src/client/snd_dma.c \ + src/client/snd_mem.c \ + src/client/snd_mix.c \ + src/client/snd_wavelet.c \ + + + +SERVER_FILES = \ + src/server/sv_bot.c \ + src/server/sv_ccmds.c \ + src/server/sv_client.c \ + src/server/sv_game.c \ + src/server/sv_init.c \ + src/server/sv_main.c \ + src/server/sv_net_chan.c \ + src/server/sv_snapshot.c \ + src/server/sv_world.c \ + + VM_FILES = \ + src/qcommon/vm.c \ + src/qcommon/vm_interpreted.c \ + src/qcommon/vm_none.c \ + + UNIX_FILES = \ + src/android/android_main.c \ + src/unix/unix_net.c \ + src/unix/unix_shared.c \ + src/unix/linux_common.c\ + src/unix/linux_qgl.c \ + src/android/android_glimp.c \ + src/android/android_snd.c \ + src/android/android-jni.cpp \ + src/android/in_android.c \ + src/game/q_shared.c \ + src/game/q_math.c + + #src/unix/linux_joystick.c \ + +LOCAL_SRC_FILES = $(UNIX_FILES) $(RENDERER_FILES) $(SPLINES_FILES) $(BOTLIB_FILES) $(JPEGLIB_FILES) $(CLIENT_FILES) $(COMMON_FILES) $(SOUND_FILES) $(SERVER_FILES) $(VM_FILES) + +LOCAL_LDLIBS := -lGLESv3 -lEGL -ldl -llog -lOpenSLES -lz -lm + +LOCAL_LDLIBS += -fuse-ld=bfd + +LOCAL_STATIC_LIBRARIES := libjpeg libpng +LOCAL_SHARED_LIBRARIES := touchcontrols + +include $(BUILD_SHARED_LIBRARY) + + + + + + diff --git a/Projects/Android/jni/rtcw/Android_game.mk b/Projects/Android/jni/rtcw/Android_game.mk new file mode 100644 index 0000000..3354686 --- /dev/null +++ b/Projects/Android/jni/rtcw/Android_game.mk @@ -0,0 +1,83 @@ +LOCAL_PATH := $(call my-dir) + + + +include $(CLEAR_VARS) + + +LOCAL_MODULE := qagamearm + +LOCAL_CFLAGS = $(RTCW_BASE_CFLAGS) + + +LOCAL_CFLAGS += -fPIC -DGAMEDLL +LOCAL_LDFLAGS += $(RTCW_BASE_LDFLAGS) #-shared -ldl -lm -rdynamic + +LOCAL_C_INCLUDES = $(LOCAL_PATH) + + + +GAME_FILES = \ + src/game/ai_cast.c \ + src/game/ai_cast_characters.c \ + src/game/ai_cast_debug.c \ + src/game/ai_cast_events.c \ + src/game/ai_cast_fight.c \ + src/game/ai_cast_func_attack.c \ + src/game/ai_cast_func_boss1.c \ + src/game/ai_cast_funcs.c \ + src/game/ai_cast_script.c \ + src/game/ai_cast_script_actions.c \ + src/game/ai_cast_script_ents.c \ + src/game/ai_cast_sight.c \ + src/game/ai_cast_think.c \ + src/botai/ai_chat.c \ + src/botai/ai_cmd.c \ + src/botai/ai_dmnet.c \ + src/botai/ai_dmq3.c \ + src/botai/ai_main.c \ + src/botai/ai_team.c \ + src/game/bg_animation.c \ + src/game/bg_misc.c \ + src/game/bg_pmove.c \ + src/game/bg_slidemove.c \ + src/game/g_active.c \ + src/game/g_alarm.c \ + src/game/g_bot.c \ + src/game/g_client.c \ + src/game/g_cmds.c \ + src/game/g_combat.c \ + src/game/g_items.c \ + src/game/g_main.c \ + src/game/g_mem.c \ + src/game/g_misc.c \ + src/game/g_missile.c \ + src/game/g_mover.c \ + src/game/g_props.c \ + src/game/g_save.c \ + src/game/g_script.c \ + src/game/g_script_actions.c \ + src/game/g_session.c \ + src/game/g_spawn.c \ + src/game/g_svcmds.c \ + src/game/g_syscalls.c \ + src/game/g_target.c \ + src/game/g_team.c \ + src/game/g_tramcar.c \ + src/game/g_trigger.c \ + src/game/g_utils.c \ + src/game/g_weapon.c \ + src/game/q_math.c \ + src/game/q_shared.c \ + + + +LOCAL_SRC_FILES = $(GAME_FILES) + +include $(BUILD_SHARED_LIBRARY) + + + + + + diff --git a/Projects/Android/jni/rtcw/Android_ui.mk b/Projects/Android/jni/rtcw/Android_ui.mk new file mode 100644 index 0000000..d70730f --- /dev/null +++ b/Projects/Android/jni/rtcw/Android_ui.mk @@ -0,0 +1,42 @@ +LOCAL_PATH := $(call my-dir) + + + +include $(CLEAR_VARS) + + +LOCAL_MODULE := uiarm + +LOCAL_CFLAGS = $(RTCW_BASE_CFLAGS) + + +LOCAL_CFLAGS += -fPIC + +LOCAL_LDFLAGS += $(RTCW_BASE_LDFLAGS) + +LOCAL_C_INCLUDES = $(LOCAL_PATH) + + +UI_FILES= \ + src/game/bg_misc.c \ + src/game/q_math.c\ + src/game/q_shared.c\ + src/ui/ui_atoms.c\ + src/ui/ui_gameinfo.c\ + src/ui/ui_main.c\ + src/ui/ui_players.c\ + src/ui/ui_shared.c\ + src/ui/ui_syscalls.c\ + src/ui/ui_util.c\ + + +LOCAL_SRC_FILES = $(UI_FILES) + + +include $(BUILD_SHARED_LIBRARY) + + + + + + diff --git a/Projects/Android/jni/rtcw/COPYING.txt b/Projects/Android/jni/rtcw/COPYING.txt new file mode 100644 index 0000000..2449be1 --- /dev/null +++ b/Projects/Android/jni/rtcw/COPYING.txt @@ -0,0 +1,643 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + + +ADDITIONAL TERMS APPLICABLE TO THE RETURN TO CASTLE WOLFENSTEIN SINGLE PLAYER GPL SOURCE CODE. + + The following additional terms (“Additional Terms”) supplement and modify the GNU General Public License, Version 3 (“GPL”) applicable to the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). In addition to the terms and conditions of the GPL, the RTCW SP Source Code is subject to the further restrictions below. + +1. Replacement of Section 15. Section 15 of the GPL shall be deleted in its entirety and replaced with the following: + +“15. Disclaimer of Warranty. + +THE PROGRAM IS PROVIDED WITHOUT ANY WARRANTIES, WHETHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, TITLE AND MERCHANTABILITY. THE PROGRAM IS BEING DELIVERED OR MADE AVAILABLE “AS IS”, “WITH ALL FAULTS” AND WITHOUT WARRANTY OR REPRESENTATION. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.” + +2. Replacement of Section 16. Section 16 of the GPL shall be deleted in its entirety and replaced with the following: + +“16. LIMITATION OF LIABILITY. + +UNDER NO CIRCUMSTANCES SHALL ANY COPYRIGHT HOLDER OR ITS AFFILIATES, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, FOR ANY DAMAGES OR OTHER LIABILITY, INCLUDING ANY GENERAL, DIRECT, INDIRECT, SPECIAL, INCIDENTAL, CONSEQUENTIAL OR PUNITIVE DAMAGES ARISING FROM, OUT OF OR IN CONNECTION WITH THE USE OR INABILITY TO USE THE PROGRAM OR OTHER DEALINGS WITH THE PROGRAM(INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), WHETHER OR NOT ANY COPYRIGHT HOLDER OR SUCH OTHER PARTY RECEIVES NOTICE OF ANY SUCH DAMAGES AND WHETHER OR NOT SUCH DAMAGES COULD HAVE BEEN FORESEEN.” + +3. LEGAL NOTICES; NO TRADEMARK LICENSE; ORIGIN. You must reproduce faithfully all trademark, copyright and other proprietary and legal notices on any copies of the Program or any other required author attributions. This license does not grant you rights to use any copyright holder or any other party’s name, logo, or trademarks. Neither the name of the copyright holder or its affiliates, or any other party who modifies and/or conveys the Program may be used to endorse or promote products derived from this software without specific prior written permission. The origin of the Program must not be misrepresented; you must not claim that you wrote the original Program. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original Program. + +4. INDEMNIFICATION. IF YOU CONVEY A COVERED WORK AND AGREE WITH ANY RECIPIENT OF THAT COVERED WORK THAT YOU WILL ASSUME ANY LIABILITY FOR THAT COVERED WORK, YOU HEREBY AGREE TO INDEMNIFY, DEFEND AND HOLD HARMLESS THE OTHER LICENSORS AND AUTHORS OF THAT COVERED WORK FOR ANY DAMAEGS, DEMANDS, CLAIMS, LOSSES, CAUSES OF ACTION, LAWSUITS, JUDGMENTS EXPENSES (INCLUDING WITHOUT LIMITATION REASONABLE ATTORNEYS' FEES AND EXPENSES) OR ANY OTHER LIABLITY ARISING FROM, RELATED TO OR IN CONNECTION WITH YOUR ASSUMPTIONS OF LIABILITY. diff --git a/Projects/Android/jni/rtcw/LICENSE b/Projects/Android/jni/rtcw/LICENSE new file mode 100644 index 0000000..2619455 --- /dev/null +++ b/Projects/Android/jni/rtcw/LICENSE @@ -0,0 +1,339 @@ +GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + Return to Castle Wolfenstein for OpenPandra (featuring ARM support and GLES renderer) + Copyright (C) 2013 ptitSeb + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + {signature of Ty Coon}, 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. diff --git a/Projects/Android/jni/rtcw/README.txt b/Projects/Android/jni/rtcw/README.txt new file mode 100644 index 0000000..9d27f39 --- /dev/null +++ b/Projects/Android/jni/rtcw/README.txt @@ -0,0 +1,133 @@ +Return to Castle Wolfenstein single player GPL source release +============================================================= + +This file contains the following sections: + +GENERAL NOTES +LICENSE + +GENERAL NOTES +============= + +Game data and patching: +----------------------- + +This source release does not contain any game data, the game data is still +covered by the original EULA and must be obeyed as usual. + +You must patch the game to the latest version. + +Note that RTCW is available from the Steam store at +http://store.steampowered.com/app/9010/ + +Linux note: due to the game CD containing only a Windows version of the game, +you must install and update the game using WINE to get the game data. + +Compiling on win32: +------------------- + +A Visual C++ 2008 project is provided in src\wolf.sln. +The solution file is compatible with the Express release of Visual C++. + +You will need to execute src\extractfuncs\extractfuncs.bat to generate src\game\g_save.c + +You can test your binaries by replacing WolfSP.exe, qagamex86.dll, cgamex86.dll, uix86.dll at the top of the RTCW install + +Compiling on GNU/Linux x86: +--------------------------- + +Go to the src/unix directory, and run the cons script +(cons is a perl based precursor to scons, this is what we were using at the time) + +Run ./cons -h to review build options. Use ./cons -- release to compile in release mode. + +If problems occur, consult the internet. + +Other platforms, updated source code, security issues: +------------------------------------------------------ + +If you have obtained this source code several weeks after the time of release +(August 2010), it is likely that you can find modified and improved +versions of the engine in various open source projects across the internet. +Depending what is your interest with the source code, those may be a better +starting point. + + +LICENSE +======= + +See COPYING.txt for the GNU GENERAL PUBLIC LICENSE + +ADDITIONAL TERMS: The Return to Castle Wolfenstein single player GPL Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU GPL which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +EXCLUDED CODE: The code described below and contained in the Return to Castle Wolfenstein single player GPL Source Code release is not part of the Program covered by the GPL and is expressly excluded from its terms. You are solely responsible for obtaining from the copyright holder a license for such code and complying with the applicable license terms. + +IO on .zip files using portions of zlib +--------------------------------------------------------------------------- +lines file(s) +4301 src/qcommon/unzip.c +Copyright (C) 1998 Gilles Vollant +zlib is Copyright (C) 1995-1998 Jean-loup Gailly and Mark Adler + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + +MD4 Message-Digest Algorithm +----------------------------------------------------------------------------- +lines file(s) +289 src/qcommon/md4.c +Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All rights reserved. + +License to copy and use this software is granted provided that it is identified +as the <93>RSA Data Security, Inc. MD4 Message-Digest Algorithm<94> in all mater +ial mentioning or referencing this software or this function. +License is also granted to make and use derivative works provided that such work +s are identified as <93>derived from the RSA Data Security, Inc. MD4 Message-Dig +est Algorithm<94> in all material mentioning or referencing the derived work. +RSA Data Security, Inc. makes no representations concerning either the merchanta +bility of this software or the suitability of this software for any particular p +urpose. It is provided <93>as is<94> without express or implied warranty of any +kind. + +JPEG library +----------------------------------------------------------------------------- +src/jpeg-6 +Copyright (C) 1991-1995, Thomas G. Lane + +Permission is hereby granted to use, copy, modify, and distribute this +software (or portions thereof) for any purpose, without fee, subject to these +conditions: +(1) If any part of the source code for this software is distributed, then this +README file must be included, with this copyright and no-warranty notice +unaltered; and any additions, deletions, or changes to the original files +must be clearly indicated in accompanying documentation. +(2) If only executable code is distributed, then the accompanying +documentation must state that "this software is based in part on the work of +the Independent JPEG Group". +(3) Permission for use of this software is granted only if the user accepts +full responsibility for any undesirable consequences; the authors accept +NO LIABILITY for damages of any kind. + +These conditions apply to any software derived from or based on the IJG code, +not just to the unmodified library. If you use our work, you ought to +acknowledge us. + +NOTE: unfortunately the README that came with our copy of the library has +been lost, so the one from release 6b is included instead. There are a few +'glue type' modifications to the library to make it easier to use from +the engine, but otherwise the dependency can be easily cleaned up to a +better release of the library. + diff --git a/Projects/Android/jni/rtcw/main/ui/menudef.h b/Projects/Android/jni/rtcw/main/ui/menudef.h new file mode 100644 index 0000000..aab0320 --- /dev/null +++ b/Projects/Android/jni/rtcw/main/ui/menudef.h @@ -0,0 +1,394 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +#define ITEM_TYPE_TEXT 0 // simple text +#define ITEM_TYPE_BUTTON 1 // button, basically text with a border +#define ITEM_TYPE_RADIOBUTTON 2 // toggle button, may be grouped +#define ITEM_TYPE_CHECKBOX 3 // check box +#define ITEM_TYPE_EDITFIELD 4 // editable text, associated with a cvar +#define ITEM_TYPE_COMBO 5 // drop down list +#define ITEM_TYPE_LISTBOX 6 // scrollable list +#define ITEM_TYPE_MODEL 7 // model +#define ITEM_TYPE_OWNERDRAW 8 // owner draw, name specs what it is +#define ITEM_TYPE_NUMERICFIELD 9 // editable text, associated with a cvar +#define ITEM_TYPE_SLIDER 10 // mouse speed, volume, etc. +#define ITEM_TYPE_YESNO 11 // yes no cvar setting +#define ITEM_TYPE_MULTI 12 // multiple list setting, enumerated +#define ITEM_TYPE_BIND 13 // multiple list setting, enumerated +#define ITEM_TYPE_MENUMODEL 14 // special menu model +#define ITEM_TYPE_VALIDFILEFIELD 15 // text must be valid for use in a dos filename + +#define ITEM_ALIGN_LEFT 0 // left alignment +#define ITEM_ALIGN_CENTER 1 // center alignment +#define ITEM_ALIGN_RIGHT 2 // right alignment + +#define ITEM_TEXTSTYLE_NORMAL 0 // normal text +#define ITEM_TEXTSTYLE_BLINK 1 // fast blinking +#define ITEM_TEXTSTYLE_PULSE 2 // slow pulsing +#define ITEM_TEXTSTYLE_SHADOWED 3 // drop shadow ( need a color for this ) +#define ITEM_TEXTSTYLE_OUTLINED 4 // drop shadow ( need a color for this ) +#define ITEM_TEXTSTYLE_OUTLINESHADOWED 5 // drop shadow ( need a color for this ) +#define ITEM_TEXTSTYLE_SHADOWEDMORE 6 // drop shadow ( need a color for this ) + +#define WINDOW_BORDER_NONE 0 // no border +#define WINDOW_BORDER_FULL 1 // full border based on border color ( single pixel ) +#define WINDOW_BORDER_HORZ 2 // horizontal borders only +#define WINDOW_BORDER_VERT 3 // vertical borders only +#define WINDOW_BORDER_KCGRADIENT 4 // horizontal border using the gradient bars + +#define WINDOW_STYLE_EMPTY 0 // no background +#define WINDOW_STYLE_FILLED 1 // filled with background color +#define WINDOW_STYLE_GRADIENT 2 // gradient bar based on background color +#define WINDOW_STYLE_SHADER 3 // gradient bar based on background color +#define WINDOW_STYLE_TEAMCOLOR 4 // team color +#define WINDOW_STYLE_CINEMATIC 5 // cinematic + +#define MENU_TRUE 1 // uh.. true +#define MENU_FALSE 0 // and false + +#define HUD_VERTICAL 0x00 +#define HUD_HORIZONTAL 0x01 + +#define RANGETYPE_ABSOLUTE 0 +#define RANGETYPE_RELATIVE 1 + +// list box element types +#define LISTBOX_TEXT 0x00 +#define LISTBOX_IMAGE 0x01 + +// list feeders +#define FEEDER_HEADS 0x00 // model heads +#define FEEDER_MAPS 0x01 // text maps based on game type +#define FEEDER_SERVERS 0x02 // servers +#define FEEDER_CLANS 0x03 // clan names +#define FEEDER_ALLMAPS 0x04 // all maps available, in graphic format +#define FEEDER_REDTEAM_LIST 0x05 // red team members +#define FEEDER_BLUETEAM_LIST 0x06 // blue team members +#define FEEDER_PLAYER_LIST 0x07 // players +#define FEEDER_TEAM_LIST 0x08 // team members for team voting +#define FEEDER_MODS 0x09 // team members for team voting +#define FEEDER_DEMOS 0x0a // team members for team voting +#define FEEDER_SCOREBOARD 0x0b // team members for team voting +#define FEEDER_Q3HEADS 0x0c // model heads +#define FEEDER_SERVERSTATUS 0x0d // server status +#define FEEDER_FINDPLAYER 0x0e // find player +#define FEEDER_CINEMATICS 0x0f // cinematics +#define FEEDER_SAVEGAMES 0x10 // savegames +#define FEEDER_PICKSPAWN 0x11 // NERVE - SMF - wolf mp pick spawn point + +// display flags +#define CG_SHOW_BLUE_TEAM_HAS_REDFLAG 0x00000001 +#define CG_SHOW_RED_TEAM_HAS_BLUEFLAG 0x00000002 +#define CG_SHOW_ANYTEAMGAME 0x00000004 +#define CG_SHOW_HARVESTER 0x00000008 +#define CG_SHOW_ONEFLAG 0x00000010 +#define CG_SHOW_CTF 0x00000020 +#define CG_SHOW_OBELISK 0x00000040 +#define CG_SHOW_HEALTHCRITICAL 0x00000080 +#define CG_SHOW_SINGLEPLAYER 0x00000100 +#define CG_SHOW_TOURNAMENT 0x00000200 +#define CG_SHOW_DURINGINCOMINGVOICE 0x00000400 +#define CG_SHOW_IF_PLAYER_HAS_FLAG 0x00000800 +#define CG_SHOW_LANPLAYONLY 0x00001000 +#define CG_SHOW_MINED 0x00002000 +#define CG_SHOW_HEALTHOK 0x00004000 +#define CG_SHOW_TEAMINFO 0x00008000 +#define CG_SHOW_NOTEAMINFO 0x00010000 +#define CG_SHOW_OTHERTEAMHASFLAG 0x00020000 +#define CG_SHOW_YOURTEAMHASENEMYFLAG 0x00040000 +#define CG_SHOW_ANYNONTEAMGAME 0x00080000 +//(SA) +#define CG_SHOW_TEXTASINT 0x00200000 +#define CG_SHOW_HIGHLIGHTED 0x00100000 + +#define CG_SHOW_NOT_V_BINOC 0x00200000 //----(SA) added // hide on binoc huds +#define CG_SHOW_NOT_V_SNIPER 0x00400000 //----(SA) added // hide on sniper huds +#define CG_SHOW_NOT_V_SNOOPER 0x00800000 //----(SA) added // hide on snooper huds +#define CG_SHOW_NOT_V_FGSCOPE 0x01000000 //----(SA) added // hide on fg42 scope huds +#define CG_SHOW_NOT_V_CLEAR 0x02000000 //----(SA) added // hide on normal, full-view huds + +#define CG_SHOW_2DONLY 0x10000000 + + +#define UI_SHOW_LEADER 0x00000001 +#define UI_SHOW_NOTLEADER 0x00000002 +#define UI_SHOW_FAVORITESERVERS 0x00000004 +#define UI_SHOW_ANYNONTEAMGAME 0x00000008 +#define UI_SHOW_ANYTEAMGAME 0x00000010 +#define UI_SHOW_NEWHIGHSCORE 0x00000020 +#define UI_SHOW_DEMOAVAILABLE 0x00000040 +#define UI_SHOW_NEWBESTTIME 0x00000080 +#define UI_SHOW_FFA 0x00000100 +#define UI_SHOW_NOTFFA 0x00000200 +#define UI_SHOW_NETANYNONTEAMGAME 0x00000400 +#define UI_SHOW_NETANYTEAMGAME 0x00000800 +#define UI_SHOW_NOTFAVORITESERVERS 0x00001000 + +// font types +#define UI_FONT_DEFAULT 0 // auto-chose betwen big/reg/small +#define UI_FONT_NORMAL 1 +#define UI_FONT_BIG 2 +#define UI_FONT_SMALL 3 +#define UI_FONT_HANDWRITING 4 + +// owner draw types +// ideally these should be done outside of this file but +// this makes it much easier for the macro expansion to +// convert them for the designers ( from the .menu files ) +#define CG_OWNERDRAW_BASE 1 +#define CG_PLAYER_ARMOR_ICON 1 +#define CG_PLAYER_ARMOR_VALUE 2 +#define CG_PLAYER_HEAD 3 +#define CG_PLAYER_HEALTH 4 +#define CG_PLAYER_AMMO_ICON 5 +#define CG_PLAYER_AMMO_VALUE 6 +#define CG_SELECTEDPLAYER_HEAD 7 +#define CG_SELECTEDPLAYER_NAME 8 +#define CG_SELECTEDPLAYER_LOCATION 9 +#define CG_SELECTEDPLAYER_STATUS 10 +#define CG_SELECTEDPLAYER_WEAPON 11 +#define CG_SELECTEDPLAYER_POWERUP 12 + +#define CG_FLAGCARRIER_HEAD 13 +#define CG_FLAGCARRIER_NAME 14 +#define CG_FLAGCARRIER_LOCATION 15 +#define CG_FLAGCARRIER_STATUS 16 +#define CG_FLAGCARRIER_WEAPON 17 +#define CG_FLAGCARRIER_POWERUP 18 + +#define CG_PLAYER_ITEM 19 +#define CG_PLAYER_SCORE 20 + +#define CG_BLUE_FLAGHEAD 21 +#define CG_BLUE_FLAGSTATUS 22 +#define CG_BLUE_FLAGNAME 23 +#define CG_RED_FLAGHEAD 24 +#define CG_RED_FLAGSTATUS 25 +#define CG_RED_FLAGNAME 26 + +#define CG_BLUE_SCORE 27 +#define CG_RED_SCORE 28 +#define CG_RED_NAME 29 +#define CG_BLUE_NAME 30 +#define CG_HARVESTER_SKULLS 31 // only shows in harvester +#define CG_ONEFLAG_STATUS 32 // only shows in one flag +#define CG_PLAYER_LOCATION 33 +#define CG_TEAM_COLOR 34 +#define CG_CTF_POWERUP 35 + +#define CG_AREA_POWERUP 36 +#define CG_AREA_LAGOMETER 37 // painted with old system +#define CG_PLAYER_HASFLAG 38 +#define CG_GAME_TYPE 39 // not done + +#define CG_SELECTEDPLAYER_ARMOR 40 +#define CG_SELECTEDPLAYER_HEALTH 41 +#define CG_PLAYER_STATUS 42 +#define CG_FRAGGED_MSG 43 // painted with old system +#define CG_PROXMINED_MSG 44 // painted with old system +#define CG_AREA_FPSINFO 45 // painted with old system +#define CG_AREA_SYSTEMCHAT 46 // painted with old system +#define CG_AREA_TEAMCHAT 47 // painted with old system +#define CG_AREA_CHAT 48 // painted with old system +#define CG_GAME_STATUS 49 +#define CG_KILLER 50 +#define CG_PLAYER_ARMOR_ICON2D 51 +#define CG_PLAYER_AMMO_ICON2D 52 +#define CG_ACCURACY 53 +#define CG_ASSISTS 54 +#define CG_DEFEND 55 +#define CG_EXCELLENT 56 +#define CG_IMPRESSIVE 57 +#define CG_PERFECT 58 +#define CG_GAUNTLET 59 +#define CG_SPECTATORS 60 +#define CG_TEAMINFO 61 +#define CG_VOICE_HEAD 62 +#define CG_VOICE_NAME 63 +#define CG_PLAYER_HASFLAG2D 64 +#define CG_HARVESTER_SKULLS2D 65 // only shows in harvester +#define CG_CAPFRAGLIMIT 66 +#define CG_1STPLACE 67 +#define CG_2NDPLACE 68 +#define CG_CAPTURES 69 + +// (SA) adding +#define CG_PLAYER_AMMOCLIP_VALUE 70 +#define CG_PLAYER_WEAPON_ICON2D 71 +#define CG_CURSORHINT 72 +#define CG_STAMINA 73 +#define CG_PLAYER_WEAPON_HEAT 74 +#define CG_PLAYER_POWERUP 75 +#define CG_PLAYER_HOLDABLE 76 +#define CG_PLAYER_INVENTORY 77 +#define CG_AREA_WEAPON 78 // draw weapons here +#define CG_AREA_HOLDABLE 79 +#define CG_CURSORHINT_STATUS 80 // like 'health' bar when pointing at a func_explosive +#define CG_PLAYER_WEAPON_STABILITY 81 // shows aimSpreadScale value +#define CG_NEWMESSAGE 82 // 'you got mail!' //----(SA) added + +#define UI_OWNERDRAW_BASE 200 +#define UI_HANDICAP 200 +#define UI_EFFECTS 201 +#define UI_PLAYERMODEL 202 +#define UI_CLANNAME 203 +#define UI_CLANLOGO 204 +#define UI_GAMETYPE 205 +#define UI_MAPPREVIEW 206 +#define UI_SKILL 207 +#define UI_BLUETEAMNAME 208 +#define UI_REDTEAMNAME 209 +#define UI_BLUETEAM1 210 +#define UI_BLUETEAM2 211 +#define UI_BLUETEAM3 212 +#define UI_BLUETEAM4 213 +#define UI_BLUETEAM5 214 +#define UI_REDTEAM1 215 +#define UI_REDTEAM2 216 +#define UI_REDTEAM3 217 +#define UI_REDTEAM4 218 +#define UI_REDTEAM5 219 +#define UI_NETSOURCE 220 +#define UI_NETMAPPREVIEW 221 +#define UI_NETFILTER 222 +#define UI_TIER 223 +#define UI_OPPONENTMODEL 224 +#define UI_TIERMAP1 225 +#define UI_TIERMAP2 226 +#define UI_TIERMAP3 227 +#define UI_PLAYERLOGO 228 +#define UI_OPPONENTLOGO 229 +#define UI_PLAYERLOGO_METAL 230 +#define UI_OPPONENTLOGO_METAL 231 +#define UI_PLAYERLOGO_NAME 232 +#define UI_OPPONENTLOGO_NAME 233 +#define UI_TIER_MAPNAME 234 +#define UI_TIER_GAMETYPE 235 +#define UI_ALLMAPS_SELECTION 236 +#define UI_OPPONENT_NAME 237 +#define UI_VOTE_KICK 238 +#define UI_BOTNAME 239 +#define UI_BOTSKILL 240 +#define UI_REDBLUE 241 +#define UI_CROSSHAIR 242 +#define UI_SELECTEDPLAYER 243 +#define UI_MAPCINEMATIC 244 +#define UI_NETGAMETYPE 245 +#define UI_NETMAPCINEMATIC 246 +#define UI_SERVERREFRESHDATE 247 +#define UI_SERVERMOTD 248 +#define UI_GLINFO 249 +#define UI_KEYBINDSTATUS 250 +#define UI_CLANCINEMATIC 251 +#define UI_MAP_TIMETOBEAT 252 +#define UI_JOINGAMETYPE 253 +#define UI_PREVIEWCINEMATIC 254 +#define UI_STARTMAPCINEMATIC 255 +#define UI_MAPS_SELECTION 256 + +#define UI_MENUMODEL 257 +#define UI_SAVEGAME_SHOT 258 + +// NERVE - SMF +#define UI_LIMBOCHAT 259 +// -NERVE - SMF + +#define UI_LEVELSHOT 260 +#define UI_LOADSTATUSBAR 261 +#define UI_SAVEGAMENAME 262 +#define UI_SAVEGAMEINFO 263 + +#define VOICECHAT_GETFLAG "getflag" // command someone to get the flag +#define VOICECHAT_OFFENSE "offense" // command someone to go on offense +#define VOICECHAT_DEFEND "defend" // command someone to go on defense +#define VOICECHAT_DEFENDFLAG "defendflag" // command someone to defend the flag +#define VOICECHAT_PATROL "patrol" // command someone to go on patrol (roam) +#define VOICECHAT_CAMP "camp" // command someone to camp (we don't have sounds for this one) +#define VOICECHAT_FOLLOWME "followme" // command someone to follow you +#define VOICECHAT_RETURNFLAG "returnflag" // command someone to return our flag +#define VOICECHAT_FOLLOWFLAGCARRIER "followflagcarrier" // command someone to follow the flag carrier +#define VOICECHAT_YES "yes" // yes, affirmative, etc. +#define VOICECHAT_NO "no" // no, negative, etc. +#define VOICECHAT_ONGETFLAG "ongetflag" // I'm getting the flag +#define VOICECHAT_ONOFFENSE "onoffense" // I'm on offense +#define VOICECHAT_ONDEFENSE "ondefense" // I'm on defense +#define VOICECHAT_ONPATROL "onpatrol" // I'm on patrol (roaming) +#define VOICECHAT_ONCAMPING "oncamp" // I'm camping somewhere +#define VOICECHAT_ONFOLLOW "onfollow" // I'm following +#define VOICECHAT_ONFOLLOWCARRIER "onfollowcarrier" // I'm following the flag carrier +#define VOICECHAT_ONRETURNFLAG "onreturnflag" // I'm returning our flag +#define VOICECHAT_INPOSITION "inposition" // I'm in position +#define VOICECHAT_IHAVEFLAG "ihaveflag" // I have the flag +#define VOICECHAT_BASEATTACK "baseattack" // the base is under attack +#define VOICECHAT_ENEMYHASFLAG "enemyhasflag" // the enemy has our flag (CTF) +#define VOICECHAT_STARTLEADER "startleader" // I'm the leader +#define VOICECHAT_STOPLEADER "stopleader" // I resign leadership +#define VOICECHAT_WHOISLEADER "whoisleader" // who is the team leader +#define VOICECHAT_WANTONDEFENSE "wantondefense" // I want to be on defense +#define VOICECHAT_WANTONOFFENSE "wantonoffense" // I want to be on offense +#define VOICECHAT_KILLINSULT "kill_insult" // I just killed you +#define VOICECHAT_TAUNT "taunt" // I want to taunt you +#define VOICECHAT_DEATHINSULT "death_insult" // you just killed me +#define VOICECHAT_KILLGAUNTLET "kill_gauntlet" // I just killed you with the gauntlet +#define VOICECHAT_PRAISE "praise" // you did something good + +// NERVE - SMF - wolf multiplayer class/item selection mechanism +#define WM_START_SELECT 0 + +#define WM_SELECT_TEAM 1 +#define WM_SELECT_CLASS 2 +#define WM_SELECT_WEAPON 3 +#define WM_SELECT_PISTOL 4 +#define WM_SELECT_GRENADE 5 +#define WM_SELECT_ITEM1 6 + +#define WM_AXIS 1 +#define WM_ALLIES 2 +#define WM_SPECTATOR 3 + +#define WM_SOLDIER 1 +#define WM_MEDIC 2 +#define WM_LIEUTENANT 3 +#define WM_ENGINEER 4 + +#define WM_PISTOL_1911 1 +#define WM_PISTOL_LUGER 2 + +#define WM_WEAPON_MP40 3 +#define WM_WEAPON_THOMPSON 4 +#define WM_WEAPON_STEN 5 +#define WM_WEAPON_MAUSER 6 +#define WM_WEAPON_GARAND 7 +#define WM_WEAPON_PANZERFAUST 8 +#define WM_WEAPON_VENOM 9 +#define WM_WEAPON_FLAMETHROWER 10 + +#define WM_PINEAPPLE_GRENADE 11 +#define WM_STICK_GRENADE 12 +// -NERVE - SMF diff --git a/Projects/Android/jni/rtcw/src/Backup/wolf.sln b/Projects/Android/jni/rtcw/src/Backup/wolf.sln new file mode 100644 index 0000000..4f63ac4 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/Backup/wolf.sln @@ -0,0 +1,73 @@ + +Microsoft Visual Studio Solution File, Format Version 10.00 +# Visual C++ Express 2008 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Splines", "splines\Splines.vcproj", "{AA96579B-0F16-4614-8453-0B03C8B39A46}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "botlib", "botlib\botlib.vcproj", "{86691FDD-E0C6-4D71-9FFD-E0F30F19AA3E}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cgame", "cgame\cgame.vcproj", "{A981B743-DF98-4346-AA89-5DECB39C165D}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "extractfuncs", "extractfuncs\extractfuncs.vcproj", "{0FC559FD-6DCD-4A81-B286-688F79286AEF}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "game", "game\game.vcproj", "{99EE8E3F-250E-4082-A92E-C7BC6202FDFE}" + ProjectSection(ProjectDependencies) = postProject + {0FC559FD-6DCD-4A81-B286-688F79286AEF} = {0FC559FD-6DCD-4A81-B286-688F79286AEF} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "renderer", "renderer\renderer.vcproj", "{F45A4F73-0EA1-4EB2-9829-154964ADEC6A}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ui", "ui\ui.vcproj", "{9FC6663B-403B-4429-90C3-4CE12E5D0619}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "wolf", "wolf.vcproj", "{47CCBCAD-2A5C-4A70-8504-371F2EC29CBE}" + ProjectSection(ProjectDependencies) = postProject + {F45A4F73-0EA1-4EB2-9829-154964ADEC6A} = {F45A4F73-0EA1-4EB2-9829-154964ADEC6A} + {A981B743-DF98-4346-AA89-5DECB39C165D} = {A981B743-DF98-4346-AA89-5DECB39C165D} + {99EE8E3F-250E-4082-A92E-C7BC6202FDFE} = {99EE8E3F-250E-4082-A92E-C7BC6202FDFE} + {9FC6663B-403B-4429-90C3-4CE12E5D0619} = {9FC6663B-403B-4429-90C3-4CE12E5D0619} + {86691FDD-E0C6-4D71-9FFD-E0F30F19AA3E} = {86691FDD-E0C6-4D71-9FFD-E0F30F19AA3E} + {AA96579B-0F16-4614-8453-0B03C8B39A46} = {AA96579B-0F16-4614-8453-0B03C8B39A46} + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {AA96579B-0F16-4614-8453-0B03C8B39A46}.Debug|Win32.ActiveCfg = Debug|Win32 + {AA96579B-0F16-4614-8453-0B03C8B39A46}.Debug|Win32.Build.0 = Debug|Win32 + {AA96579B-0F16-4614-8453-0B03C8B39A46}.Release|Win32.ActiveCfg = Release|Win32 + {AA96579B-0F16-4614-8453-0B03C8B39A46}.Release|Win32.Build.0 = Release|Win32 + {86691FDD-E0C6-4D71-9FFD-E0F30F19AA3E}.Debug|Win32.ActiveCfg = Debug|Win32 + {86691FDD-E0C6-4D71-9FFD-E0F30F19AA3E}.Debug|Win32.Build.0 = Debug|Win32 + {86691FDD-E0C6-4D71-9FFD-E0F30F19AA3E}.Release|Win32.ActiveCfg = Release|Win32 + {86691FDD-E0C6-4D71-9FFD-E0F30F19AA3E}.Release|Win32.Build.0 = Release|Win32 + {A981B743-DF98-4346-AA89-5DECB39C165D}.Debug|Win32.ActiveCfg = Debug|Win32 + {A981B743-DF98-4346-AA89-5DECB39C165D}.Debug|Win32.Build.0 = Debug|Win32 + {A981B743-DF98-4346-AA89-5DECB39C165D}.Release|Win32.ActiveCfg = Release|Win32 + {A981B743-DF98-4346-AA89-5DECB39C165D}.Release|Win32.Build.0 = Release|Win32 + {0FC559FD-6DCD-4A81-B286-688F79286AEF}.Debug|Win32.ActiveCfg = Debug|Win32 + {0FC559FD-6DCD-4A81-B286-688F79286AEF}.Debug|Win32.Build.0 = Debug|Win32 + {0FC559FD-6DCD-4A81-B286-688F79286AEF}.Release|Win32.ActiveCfg = Release|Win32 + {0FC559FD-6DCD-4A81-B286-688F79286AEF}.Release|Win32.Build.0 = Release|Win32 + {99EE8E3F-250E-4082-A92E-C7BC6202FDFE}.Debug|Win32.ActiveCfg = Debug|Win32 + {99EE8E3F-250E-4082-A92E-C7BC6202FDFE}.Debug|Win32.Build.0 = Debug|Win32 + {99EE8E3F-250E-4082-A92E-C7BC6202FDFE}.Release|Win32.ActiveCfg = Release|Win32 + {99EE8E3F-250E-4082-A92E-C7BC6202FDFE}.Release|Win32.Build.0 = Release|Win32 + {F45A4F73-0EA1-4EB2-9829-154964ADEC6A}.Debug|Win32.ActiveCfg = Debug|Win32 + {F45A4F73-0EA1-4EB2-9829-154964ADEC6A}.Debug|Win32.Build.0 = Debug|Win32 + {F45A4F73-0EA1-4EB2-9829-154964ADEC6A}.Release|Win32.ActiveCfg = Release|Win32 + {F45A4F73-0EA1-4EB2-9829-154964ADEC6A}.Release|Win32.Build.0 = Release|Win32 + {9FC6663B-403B-4429-90C3-4CE12E5D0619}.Debug|Win32.ActiveCfg = Debug|Win32 + {9FC6663B-403B-4429-90C3-4CE12E5D0619}.Debug|Win32.Build.0 = Debug|Win32 + {9FC6663B-403B-4429-90C3-4CE12E5D0619}.Release|Win32.ActiveCfg = Release|Win32 + {9FC6663B-403B-4429-90C3-4CE12E5D0619}.Release|Win32.Build.0 = Release|Win32 + {47CCBCAD-2A5C-4A70-8504-371F2EC29CBE}.Debug|Win32.ActiveCfg = Debug|Win32 + {47CCBCAD-2A5C-4A70-8504-371F2EC29CBE}.Debug|Win32.Build.0 = Debug|Win32 + {47CCBCAD-2A5C-4A70-8504-371F2EC29CBE}.Release|Win32.ActiveCfg = Release|Win32 + {47CCBCAD-2A5C-4A70-8504-371F2EC29CBE}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Projects/Android/jni/rtcw/src/android/android-jni.cpp b/Projects/Android/jni/rtcw/src/android/android-jni.cpp new file mode 100644 index 0000000..56e44ab --- /dev/null +++ b/Projects/Android/jni/rtcw/src/android/android-jni.cpp @@ -0,0 +1,791 @@ +/* + * Copyright (C) 2009 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include +#include +#include +#include + +#include "TouchControlsContainer.h" +#include "JNITouchControlsUtils.h" + +extern "C" +{ + +#include "src/ui/keycodes.h" + +#include "in_android.h" + + +#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO,"JNI", __VA_ARGS__)) +#define LOGW(...) ((void)__android_log_print(ANDROID_LOG_WARN, "JNI", __VA_ARGS__)) +#define LOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR,"JNI", __VA_ARGS__)) + +#define JAVA_FUNC(x) Java_com_beloko_opengames_rtcw_NativeLib_##x + +int android_screen_width; +int android_screen_height; + + +#define KEY_SHOW_WEAPONS 0x1000 +#define KEY_SHOOT 0x1001 + +#define KEY_SHOW_INV 0x1006 +#define KEY_QUICK_CMD 0x1007 + +#define KEY_SHOW_KEYB 0x1009 + +float gameControlsAlpha = 0.5; +bool showWeaponCycle = false; +bool turnMouseMode = true; +bool invertLook = false; +bool precisionShoot = false; +bool showSticks = true; +bool hideTouchControls = true; +bool enableWeaponWheel = true; + +bool shooting = false; + +//set when holding down reload +bool sniperMode = false; + +static int controlsCreated = 0; +touchcontrols::TouchControlsContainer controlsContainer; + +touchcontrols::TouchControls *tcMenuMain=0; +touchcontrols::TouchControls *tcGameMain=0; +touchcontrols::TouchControls *tcGameWeapons=0; +touchcontrols::TouchControls *tcInventory=0; +touchcontrols::TouchControls *tcWeaponWheel=0; + +//So can hide and show these buttons +touchcontrols::Button *nextWeapon=0; +touchcontrols::Button *prevWeapon=0; +touchcontrols::TouchJoy *touchJoyLeft; +touchcontrols::TouchJoy *touchJoyRight; + +extern JNIEnv* env_; +JavaVM* jvm_; + + +void openGLStart() +{ + + glPushMatrix(); + //glClearColor(1.0f, 1.0f, 0.0f, 1.0f); + //glClear(GL_COLOR_BUFFER_BIT); + //LOGI("openGLStart"); + glDisable(GL_ALPHA_TEST); + glDisableClientState(GL_COLOR_ARRAY); + glEnableClientState(GL_VERTEX_ARRAY); + glEnableClientState(GL_TEXTURE_COORD_ARRAY ); + + //glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + glEnable (GL_BLEND); + //glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + //glEnable(GL_TEXTURE_2D); + glDisable(GL_CULL_FACE); + glMatrixMode(GL_MODELVIEW); + + glPushMatrix(); + + +} + +void openGLEnd() +{ + + glPopMatrix(); + + glPopMatrix(); + +} + +void gameSettingsButton(int state) +{ + if (state == 1) + { + showTouchSettings(); + } +} + + + +extern unsigned int Sys_Milliseconds(void); + +static unsigned int reload_time_down; +void gameButton(int state,int code) +{ + if (code == KEY_SHOOT) + { + shooting = state; + PortableAction(state,PORT_ACT_ATTACK); + } + else if (code == PORT_ACT_RELOAD) + { + //If holding down the reload button, do not reload + if (state) //key down + { + reload_time_down = Sys_Milliseconds(); + } + else //up + { + //if less than 0.5 sec, reload + if (( Sys_Milliseconds() - reload_time_down) < 500) + { + PortableAction(1, PORT_ACT_RELOAD); + PortableAction(0, PORT_ACT_RELOAD); + } + } + + sniperMode = state; //Use reload button for precision aim also + } + else if (code == KEY_SHOW_WEAPONS) + { + if (state == 1) + if (!tcGameWeapons->enabled) + { + tcInventory->animateOut(5); + tcGameWeapons->animateIn(5); + } + } + else if (code == KEY_SHOW_INV) + { + if (state == 1) + { + if (!tcInventory->enabled) + { + tcGameWeapons->animateOut(5); + tcInventory->animateIn(5); + } + else + tcInventory->animateOut(5); + } + } + else if (code == KEY_QUICK_CMD){ + //if (state == 1) + // showCustomCommands(); + PortableKeyEvent(state, '~', 0); + if (state) + toggleKeyboard(); + } + else + { + PortableAction(state, code); + } +} + + +//Weapon wheel callbacks +void weaponWheelSelected(int enabled) +{ + if (enabled) + tcWeaponWheel->fade(touchcontrols::FADE_IN,5); //fade in + +} +void weaponWheel(int segment) +{ + LOGI("weaponWheel %d",segment); + int code; + if (segment == 9) + code = '0'; + else + code = '1' + segment; + + PortableKeyEvent(1,code,0); + PortableKeyEvent(0, code,0); +} + +void menuButton(int state,int code) +{ + if (code == KEY_SHOW_KEYB) + { + if (state) + toggleKeyboard(); + return; + } + PortableKeyEvent(state, code, 0); +} + +void inventoryButton(int state,int code) +{ + PortableAction(state,code); +} + +int left_double_action; +int right_double_action; + +void left_double_tap(int state) +{ + //LOGTOUCH("L double %d",state); + if (left_double_action) + PortableAction(state,left_double_action); +} + +void right_double_tap(int state) +{ + //LOGTOUCH("R double %d",state); + if (right_double_action) + PortableAction(state,right_double_action); +} + +void mouse_move(int action,float x, float y,float dx, float dy) +{ + //PortableMouse(mouse_x,mouse_y); + PortableMouseAbs(x * 640,y * 480); + if (action == TOUCHMOUSE_TAP) + { + PortableKeyEvent(1, K_MOUSE1, 0); + PortableKeyEvent(0, K_MOUSE1, 0); + } +} + +//To be set by android +float strafe_sens,forward_sens; +float pitch_sens,yaw_sens; + +void left_stick(float joy_x, float joy_y,float mouse_x, float mouse_y) +{ + joy_x *=10; + //float strafe = joy_x*joy_x; + float strafe = joy_x; + //if (joy_x < 0) + // strafe *= -1; + + PortableMove(joy_y * 15 * forward_sens,-strafe * strafe_sens); +} +void right_stick(float joy_x, float joy_y,float mouse_x, float mouse_y) +{ + //LOGI(" mouse x = %f",mouse_x); + int invert = invertLook?-1:1; + + float scale; + + if (sniperMode) + scale = 0.1; + else + scale = (shooting && precisionShoot)?0.3:1; + + if (1) + { + PortableLookPitch(LOOK_MODE_MOUSE,-mouse_y * pitch_sens * invert * scale); + + if (turnMouseMode) + PortableLookYaw(LOOK_MODE_MOUSE,mouse_x*2*yaw_sens * scale); + else + PortableLookYaw(LOOK_MODE_JOYSTICK,joy_x*6*yaw_sens * scale); + } + else + { + float y = mouse_y * mouse_y; + y *= 50; + if (mouse_y < 0) + y *= -1; + + PortableLookPitch(LOOK_MODE_MOUSE,-y * pitch_sens * invert * scale); + + float x = mouse_x * mouse_x; + x *= 100; + if (mouse_x < 0) + x *= -1; + + if (turnMouseMode) + PortableLookYaw(LOOK_MODE_MOUSE,x*2*yaw_sens * scale); + else + PortableLookYaw(LOOK_MODE_JOYSTICK,joy_x*6*yaw_sens * scale); + + } +} + +//Weapon select callbacks +void selectWeaponButton(int state, int code) +{ + PortableKeyEvent(state, code, 0); + if (state == 0) + tcGameWeapons->animateOut(5); +} + +void weaponCycle(bool v) +{ + if (v) + { + if (nextWeapon) nextWeapon->setEnabled(true); + if (prevWeapon) prevWeapon->setEnabled(true); + } + else + { + if (nextWeapon) nextWeapon->setEnabled(false); + if (prevWeapon) prevWeapon->setEnabled(false); + } +} + +void setHideSticks(bool v) +{ + if (touchJoyLeft) touchJoyLeft->setHideGraphics(v); + if (touchJoyRight) touchJoyRight->setHideGraphics(v); +} + + +void initControls(int width, int height,const char * graphics_path,const char *settings_file) +{ + touchcontrols::GLScaleWidth = (float)width; + touchcontrols::GLScaleHeight = (float)height; + + LOGI("initControls %d x %d,x path = %s, settings = %s",width,height,graphics_path,settings_file); + + if (!controlsCreated) + { + LOGI("creating controls"); + + touchcontrols::setGraphicsBasePath(graphics_path); + setControlsContainer(&controlsContainer); + + controlsContainer.openGL_start.connect( sigc::ptr_fun(&openGLStart)); + controlsContainer.openGL_end.connect( sigc::ptr_fun(&openGLEnd)); + + + tcMenuMain = new touchcontrols::TouchControls("menu",true,false); + tcGameMain = new touchcontrols::TouchControls("game",false,true,1); + tcGameWeapons = new touchcontrols::TouchControls("weapons",false,true,1); + tcInventory = new touchcontrols::TouchControls("inventory",false,true,1); + tcWeaponWheel = new touchcontrols::TouchControls("weapon_wheel",false,true,1); + + tcGameMain->signal_settingsButton.connect( sigc::ptr_fun(&gameSettingsButton) ); + + //Menu + tcMenuMain->signal_button.connect( sigc::ptr_fun(&menuButton) ); + + touchcontrols::Mouse *mouse = new touchcontrols::Mouse("mouse",touchcontrols::RectF(0,0,26,16),""); + mouse->setHideGraphics(true); + tcMenuMain->addControl(mouse); + mouse->signal_action.connect(sigc::ptr_fun(&mouse_move) ); + + tcMenuMain->setAlpha(0.3); + + + //Game + tcGameMain->setAlpha(gameControlsAlpha); + tcGameMain->addControl(new touchcontrols::Button("jump",touchcontrols::RectF(24,4,26,6),"jump",PORT_ACT_JUMP)); + tcGameMain->addControl(new touchcontrols::Button("crouch",touchcontrols::RectF(24,14,26,16),"crouch",PORT_ACT_DOWN)); + tcGameMain->addControl(new touchcontrols::Button("attack",touchcontrols::RectF(20,7,23,10),"shoot",KEY_SHOOT)); + tcGameMain->addControl(new touchcontrols::Button("use",touchcontrols::RectF(23,6,26,9),"use",PORT_ACT_USE)); + tcGameMain->addControl(new touchcontrols::Button("binocular",touchcontrols::RectF(21,5,23,7),"binocular",PORT_ACT_ZOOM_IN)); + tcGameMain->addControl(new touchcontrols::Button("kick",touchcontrols::RectF(3,5,5,7),"kick",PORT_ACT_KICK)); + + tcGameMain->addControl(new touchcontrols::Button("notebook",touchcontrols::RectF(14,0,16,2),"notebook",PORT_ACT_HELPCOMP)); + tcGameMain->addControl(new touchcontrols::Button("use_inventory",touchcontrols::RectF(16,0,18,2),"inv",KEY_SHOW_INV)); + tcGameMain->addControl(new touchcontrols::Button("quick_save",touchcontrols::RectF(24,0,26,2),"save",PORT_ACT_QUICKSAVE)); + tcGameMain->addControl(new touchcontrols::Button("quick_load",touchcontrols::RectF(20,0,22,2),"load",PORT_ACT_QUICKLOAD)); + tcGameMain->addControl( new touchcontrols::Button("prompt",touchcontrols::RectF(9,0,11,2),"keyboard",KEY_QUICK_CMD)); + + + tcGameMain->addControl(new touchcontrols::Button("reload",touchcontrols::RectF(0,5,3,7),"reload_sniper",PORT_ACT_RELOAD)); + tcGameMain->addControl(new touchcontrols::Button("alt_fire",touchcontrols::RectF(13,14,15,16),"Custom_2",PORT_ACT_ALT_FIRE)); + + tcGameMain->addControl(new touchcontrols::Button("show_weapons",touchcontrols::RectF(11,14,13,16),"show_weapons",KEY_SHOW_WEAPONS)); + + nextWeapon = new touchcontrols::Button("next_weapon",touchcontrols::RectF(0,3,3,5),"next_weap",PORT_ACT_NEXT_WEP); + tcGameMain->addControl(nextWeapon); + prevWeapon = new touchcontrols::Button("prev_weapon",touchcontrols::RectF(0,7,3,9),"prev_weap",PORT_ACT_PREV_WEP); + tcGameMain->addControl(prevWeapon); + + touchJoyLeft = new touchcontrols::TouchJoy("stick",touchcontrols::RectF(0,7,8,16),"strafe_arrow"); + tcGameMain->addControl(touchJoyLeft); + touchJoyLeft->signal_move.connect(sigc::ptr_fun(&left_stick) ); + touchJoyLeft->signal_double_tap.connect(sigc::ptr_fun(&left_double_tap) ); + + touchJoyRight = new touchcontrols::TouchJoy("touch",touchcontrols::RectF(17,4,26,16),"look_arrow"); + tcGameMain->addControl(touchJoyRight); + touchJoyRight->signal_move.connect(sigc::ptr_fun(&right_stick) ); + touchJoyRight->signal_double_tap.connect(sigc::ptr_fun(&right_double_tap) ); + + tcGameMain->signal_button.connect( sigc::ptr_fun(&gameButton) ); + + //Weapons + tcGameWeapons->addControl(new touchcontrols::Button("weapon1",touchcontrols::RectF(1,14,3,16),"key_1",'1')); + tcGameWeapons->addControl(new touchcontrols::Button("weapon2",touchcontrols::RectF(3,14,5,16),"key_2",'2')); + tcGameWeapons->addControl(new touchcontrols::Button("weapon3",touchcontrols::RectF(5,14,7,16),"key_3",'3')); + tcGameWeapons->addControl(new touchcontrols::Button("weapon4",touchcontrols::RectF(7,14,9,16),"key_4",'4')); + tcGameWeapons->addControl(new touchcontrols::Button("weapon5",touchcontrols::RectF(9,14,11,16),"key_5",'5')); + + tcGameWeapons->addControl(new touchcontrols::Button("weapon6",touchcontrols::RectF(15,14,17,16),"key_6",'6')); + tcGameWeapons->addControl(new touchcontrols::Button("weapon7",touchcontrols::RectF(17,14,19,16),"key_7",'7')); + tcGameWeapons->addControl(new touchcontrols::Button("weapon8",touchcontrols::RectF(19,14,21,16),"key_8",'8')); + tcGameWeapons->addControl(new touchcontrols::Button("weapon9",touchcontrols::RectF(21,14,23,16),"key_9",'9')); + tcGameWeapons->addControl(new touchcontrols::Button("weapon0",touchcontrols::RectF(23,14,25,16),"key_0",'0')); + tcGameWeapons->signal_button.connect( sigc::ptr_fun(&selectWeaponButton) ); + tcGameWeapons->setAlpha(0.8); + + //Weapon wheel + touchcontrols::WheelSelect *wheel = new touchcontrols::WheelSelect("weapon_wheel",touchcontrols::RectF(7,2,19,14),"weapon_wheel",10); + wheel->signal_selected.connect(sigc::ptr_fun(&weaponWheel) ); + wheel->signal_enabled.connect(sigc::ptr_fun(&weaponWheelSelected)); + tcWeaponWheel->addControl(wheel); + tcWeaponWheel->setAlpha(0.5); + + //Inventory + tcInventory->addControl(new touchcontrols::Button("invuse",touchcontrols::RectF(3,14,5,16),"enter",PORT_ACT_INVUSE)); + tcInventory->addControl(new touchcontrols::Button("invprev",touchcontrols::RectF(6,14,8,16),"arrow_left",PORT_ACT_INVPREV)); + tcInventory->addControl(new touchcontrols::Button("invnext",touchcontrols::RectF(8,14,10,16),"arrow_right",PORT_ACT_INVNEXT)); + + tcInventory->signal_button.connect( sigc::ptr_fun(&inventoryButton) ); + tcInventory->setAlpha(0.5); + + + controlsContainer.addControlGroup(tcGameMain); + controlsContainer.addControlGroup(tcGameWeapons); + controlsContainer.addControlGroup(tcMenuMain); + controlsContainer.addControlGroup(tcInventory); + controlsContainer.addControlGroup(tcWeaponWheel); + controlsCreated = 1; + + tcGameMain->setXMLFile(settings_file); + tcGameWeapons->setXMLFile((std::string)graphics_path + "/weapons.xml"); + tcInventory->setXMLFile((std::string)graphics_path + "/inventory.xml"); + tcWeaponWheel->setXMLFile((std::string)graphics_path + "/weaponwheel.xml"); + } + else + LOGI("NOT creating controls"); + + controlsContainer.initGL(); +} + + +int inMenuLast = 1; +int inAutomapLast = 0; +void frameControls() +{ + int inMenuNew = PortableInMenu(); + if (inMenuLast != inMenuNew) + { + inMenuLast = inMenuNew; + if (!inMenuNew) + { + tcGameMain->setEnabled(true); + if (enableWeaponWheel) + tcWeaponWheel->setEnabled(true); + tcMenuMain->setEnabled(false); + } + else + { + tcGameMain->setEnabled(false); + tcGameWeapons->setEnabled(false); + tcWeaponWheel->setEnabled(false); + tcMenuMain->setEnabled(true); + } + } + + + weaponCycle(showWeaponCycle); + setHideSticks(!showSticks); + controlsContainer.draw(); +} + + +void setTouchSettings(float alpha,float strafe,float fwd,float pitch,float yaw,int other) +{ + + gameControlsAlpha = alpha; + if (tcGameMain) + tcGameMain->setAlpha(gameControlsAlpha); + + showWeaponCycle = other & 0x1?true:false; + turnMouseMode = other & 0x2?true:false; + invertLook = other & 0x4?true:false; + precisionShoot = other & 0x8?true:false; + showSticks = other & 0x1000?true:false; + enableWeaponWheel = other & 0x2000?true:false; + + if (tcWeaponWheel) + tcWeaponWheel->setEnabled(enableWeaponWheel); + + + hideTouchControls = other & 0x80000000?true:false; + + + switch ((other>>4) & 0xF) + { + case 1: + left_double_action = PORT_ACT_ATTACK; + break; + case 2: + left_double_action = PORT_ACT_JUMP; + break; + case 3: + left_double_action = PORT_ACT_USE; + break; + default: + left_double_action = 0; + } + + switch ((other>>8) & 0xF) + { + case 1: + right_double_action = PORT_ACT_ATTACK; + break; + case 2: + right_double_action = PORT_ACT_JUMP; + break; + case 3: + right_double_action = PORT_ACT_USE; + break; + default: + right_double_action = 0; + } + + strafe_sens = strafe; + forward_sens = fwd; + pitch_sens = pitch; + yaw_sens = yaw; + +} + +int quit_now = 0; + +#define EXPORT_ME __attribute__ ((visibility("default"))) + +JNIEnv* env_; + +int argc=1; +const char * argv[32]; +std::string graphicpath; + + +std::string game_path; +const char * getGamePath() +{ + return game_path.c_str(); +} + +std::string lib_path; +const char * getLibPath() +{ + return lib_path.c_str(); +} + +jint EXPORT_ME +JAVA_FUNC(init) ( JNIEnv* env, jobject thiz,jstring graphics_dir,jint mem_mb,jobjectArray argsArray,jint renderer,jstring game_path_ ,jstring lib_path_ ) +{ + env_ = env; + + argv[0] = "quake"; + int argCount = (env)->GetArrayLength( argsArray); + LOGI("argCount = %d",argCount); + for (int i=0; iGetObjectArrayElement( argsArray, i); + argv[argc] = (char *)(env)->GetStringUTFChars( string, 0); + LOGI("arg = %s",argv[argc]); + argc++; + } + + + game_path = (char *)(env)->GetStringUTFChars( game_path_, 0); + lib_path = (char *)(env)->GetStringUTFChars( lib_path_, 0); + + LOGI("game_path = %s",getGamePath()); + LOGI("lib_path = %s",getLibPath()); + + + PortableInit(argc,argv); + + const char * p = env->GetStringUTFChars(graphics_dir,NULL); + graphicpath = std::string(p); + + + + initControls(android_screen_width,-android_screen_height,graphicpath.c_str(),(graphicpath + "/game_controls.xml").c_str()); + + + return 0; +} + +extern int androidSwapped; + +jint EXPORT_ME +JAVA_FUNC(frame) ( JNIEnv* env, jobject thiz ) +{ + + //LOGI("frame"); + + androidSwapped = 1; + + PortableFrame(); + + if (quit_now) + { + LOGI("frame QUIT"); + return 128; + } + + + frameControls(); + + int ret = 0; + + return ret; +} + +__attribute__((visibility("default"))) jint JNI_OnLoad(JavaVM* vm, void* reserved) +{ + LOGI("JNI_OnLoad"); + jvm_ = vm; + setTCJNIEnv(vm); + + return JNI_VERSION_1_4; +} + + +void EXPORT_ME +JAVA_FUNC(keypress) (JNIEnv *env, jobject obj, jint down, jint keycode, jint unicode) +{ + LOGI("keypress %d",keycode); + if (controlsContainer.isEditing()) + { + if (down && (keycode == K_ESCAPE )) + controlsContainer.finishEditing(); + return; + } + + PortableKeyEvent(down,keycode,unicode); +} + + +void EXPORT_ME +JAVA_FUNC(touchEvent) (JNIEnv *env, jobject obj,jint action, jint pid, jfloat x, jfloat y) +{ + //LOGI("TOUCHED"); + controlsContainer.processPointer(action,pid,x,y); +} + + +void EXPORT_ME +JAVA_FUNC(doAction) (JNIEnv *env, jobject obj, jint state, jint action) +{ + //gamepadButtonPressed(); + if (hideTouchControls) + if (tcGameMain) + { + if (tcGameMain->isEnabled()) + tcGameMain->animateOut(30); + + if (tcWeaponWheel->isEnabled()) + tcWeaponWheel->animateOut(30); + } + LOGI("doAction %d %d",state,action); + + //Sniper mode for gamepad + if (action == PORT_ACT_RELOAD) + { + if (state) //key down + { + reload_time_down = Sys_Milliseconds(); + } + else //up + { + //if less than 0.5 sec, reload + if (( Sys_Milliseconds() - reload_time_down) < 500) + { + PortableAction(1, PORT_ACT_RELOAD); + PortableAction(0, PORT_ACT_RELOAD); + } + } + + sniperMode = state; //Use reload button for precision aim also + return; + } + + PortableAction(state,action); +} + +void EXPORT_ME +JAVA_FUNC(analogFwd) (JNIEnv *env, jobject obj, jfloat v) +{ + PortableMoveFwd(v); +} + +void EXPORT_ME +JAVA_FUNC(analogSide) (JNIEnv *env, jobject obj,jfloat v) +{ + PortableMoveSide(v); +} + +void EXPORT_ME +JAVA_FUNC(analogPitch) (JNIEnv *env, jobject obj,jint mode,jfloat v) +{ + if (sniperMode) + v *= 0.1; + + PortableLookPitch(mode, v); +} + +void EXPORT_ME +JAVA_FUNC(analogYaw) (JNIEnv *env, jobject obj, jint mode,jfloat v) +{ + if (sniperMode) + v *= 0.1; + + PortableLookYaw(mode, v); +} + +void EXPORT_ME +JAVA_FUNC(setTouchSettings) (JNIEnv *env, jobject obj, jfloat alpha,jfloat strafe,jfloat fwd,jfloat pitch,jfloat yaw,int other) +{ + setTouchSettings(alpha,strafe,fwd,pitch,yaw,other); +} + +std::string quickCommandString; +jint EXPORT_ME +JAVA_FUNC(quickCommand) (JNIEnv *env, jobject obj, jstring command) +{ + const char * p = env->GetStringUTFChars(command,NULL); + quickCommandString = std::string(p) + "\n"; + env->ReleaseStringUTFChars(command, p); + PortableCommand(quickCommandString.c_str()); + return 0; +} + + +void EXPORT_ME +JAVA_FUNC(setScreenSize) ( JNIEnv* env, jobject thiz, jint width, jint height) +{ + android_screen_width = width; + android_screen_height = height; +} + + +void bqPause(int p); +void EXPORT_ME +JAVA_FUNC(pauseAudio) ( JNIEnv* env, jobject thiz, jint v) +{ + bqPause(v); +} + + + +static JNIEnv *my_getJNIEnv ( ) +{ + JNIEnv *pJNIEnv ; + + if ( jvm_ && ( jvm_->GetEnv ( (void**) &pJNIEnv, JNI_VERSION_1_4 ) >= 0 ) ) + { + return pJNIEnv ; + } + return NULL ; +} + +} diff --git a/Projects/Android/jni/rtcw/src/android/android_glimp.c b/Projects/Android/jni/rtcw/src/android/android_glimp.c new file mode 100644 index 0000000..7508344 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/android/android_glimp.c @@ -0,0 +1,735 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== + */ + +/* + ** GLW_IMP.C + ** + ** This file contains ALL Linux specific stuff having to do with the + ** OpenGL refresh. When a port is being made the following functions + ** must be implemented by the port: + ** + ** GLimp_EndFrame + ** GLimp_Init + ** GLimp_Shutdown + ** GLimp_SwitchFullscreen + ** GLimp_SetGamma + ** + */ + +#include +#include +#ifdef __linux__ +#include +#include +#endif +#include +#include +#include +#include +#include + +// bk001204 +#include + +// bk001206 - from my Heretic2 by way of Ryan's Fakk2 +// Needed for the new X11_PendingInput() function. +#include +#include +#include + +#include "../renderer/tr_local.h" +#include "../client/client.h" +#include "android_local.h" // bk001130 +#include "EGL/egl.h" + +#define WINDOW_CLASS_NAME "Return to Castle Wolfenstein" + +typedef enum +{ + RSERR_OK, + + RSERR_INVALID_FULLSCREEN, + RSERR_INVALID_MODE, + + RSERR_UNKNOWN +} rserr_t; + + + +void myglMultiTexCoord2f( GLenum texture, GLfloat s, GLfloat t ) +{ + glMultiTexCoord4f(texture, s, t, 0, 1); +} + + + +static cvar_t *in_mouse; +static cvar_t *in_dgamouse; + +// bk001130 - from cvs1.17 (mkv), but not static +cvar_t *in_joystick = NULL; +cvar_t *in_joystickDebug = NULL; +cvar_t *joy_threshold = NULL; + +cvar_t *r_allowSoftwareGL; // don't abort out if the pixelformat claims software +cvar_t *r_previousglDriver; + +//static int default_dotclock_vidmode; // bk001204 - unused +static int num_vidmodes; +static qboolean vidmode_active = qfalse; + + +/* + * Find the first occurrence of find in s. + */ +// bk001130 - from cvs1.17 (mkv), const +// bk001130 - made first argument const +static const char *Q_stristr( const char *s, const char *find ) { + register char c, sc; + register size_t len; + + if ( ( c = *find++ ) != 0 ) { + if ( c >= 'a' && c <= 'z' ) { + c -= ( 'a' - 'A' ); + } + len = strlen( find ); + do + { + do + { + if ( ( sc = *s++ ) == 0 ) { + return NULL; + } + if ( sc >= 'a' && sc <= 'z' ) { + sc -= ( 'a' - 'A' ); + } + } while ( sc != c ); + } while ( Q_stricmpn( s, find, len ) != 0 ); + s--; + } + return s; +} + + + +void IN_ActivateMouse( void ) { + +} + +void IN_DeactivateMouse( void ) { + +} +/*****************************************************************************/ + +static qboolean signalcaught = qfalse;; + +void Sys_Exit( int ); // bk010104 - abstraction + +static void signal_handler( int sig ) { // bk010104 - replace this... (NOTE TTimo huh?) + if ( signalcaught ) { + printf( "DOUBLE SIGNAL FAULT: Received signal %d, exiting...\n", sig ); + Sys_Exit( 1 ); // bk010104 - abstraction + } + + signalcaught = qtrue; + printf( "Received signal %d, exiting...\n", sig ); + GLimp_Shutdown(); // bk010104 - shouldn't this be CL_Shutdown + Sys_Exit( 0 ); // bk010104 - abstraction NOTE TTimo send a 0 to avoid DOUBLE SIGNAL FAULT +} + +static void InitSig( void ) { + + return; + + + signal( SIGHUP, signal_handler ); + signal( SIGQUIT, signal_handler ); + signal( SIGILL, signal_handler ); + signal( SIGTRAP, signal_handler ); + signal( SIGIOT, signal_handler ); + signal( SIGBUS, signal_handler ); + signal( SIGFPE, signal_handler ); + signal( SIGSEGV, signal_handler ); + signal( SIGTERM, signal_handler ); +} + +/* + ** GLimp_SetGamma + ** + ** This routine should only be called if glConfig.deviceSupportsGamma is TRUE + */ +void GLimp_SetGamma( unsigned char red[256], unsigned char green[256], unsigned char blue[256] ) { + +} + +/* + ** GLimp_Shutdown + ** + ** This routine does all OS specific shutdown procedures for the OpenGL + ** subsystem. Under OpenGL this means NULLing out the current DC and + ** HGLRC, deleting the rendering context, and releasing the DC acquired + ** for the window. The state structure is also nulled out. + ** + */ +void GLimp_Shutdown( void ) { + + memset( &glConfig, 0, sizeof( glConfig ) ); + memset( &glState, 0, sizeof( glState ) ); + + QGL_Shutdown(); +} + +/* + ** GLimp_LogComment + */ +void GLimp_LogComment( char *comment ) { + +} + +/* + ** GLW_StartDriverAndSetMode + */ +// bk001204 - prototype needed +int GLW_SetMode( const char *drivername, int mode, qboolean fullscreen ); +static qboolean GLW_StartDriverAndSetMode( const char *drivername, + int mode, + qboolean fullscreen ) { + rserr_t err; + + // don't ever bother going into fullscreen with a voodoo card +#if 1 // JDC: I reenabled this + if ( Q_stristr( drivername, "Voodoo" ) ) { + ri.Cvar_Set( "r_fullscreen", "0" ); + r_fullscreen->modified = qfalse; + fullscreen = qfalse; + } +#endif + + err = GLW_SetMode( drivername, mode, fullscreen ); + + switch ( err ) + { + case RSERR_INVALID_FULLSCREEN: + ri.Printf( PRINT_ALL, "...WARNING: fullscreen unavailable in this mode\n" ); + return qfalse; + case RSERR_INVALID_MODE: + ri.Printf( PRINT_ALL, "...WARNING: could not set the given mode (%d)\n", mode ); + return qfalse; + default: + break; + } + return qtrue; +} + + +extern int android_screen_width; +extern int android_screen_height; + + +/* + ** GLW_InitExtensions + */ +static void GLW_InitExtensions( void ) { + if ( !r_allowExtensions->integer ) { + ri.Printf( PRINT_ALL, "*** IGNORING OPENGL EXTENSIONS ***\n" ); + return; + } + + ri.Printf( PRINT_ALL, "Initializing OpenGL extensions\n" ); + +#ifndef HAVE_GLES + // GL_S3_s3tc + if ( Q_stristr( glConfig.extensions_string, "GL_S3_s3tc" ) ) { + if ( r_ext_compressed_textures->value ) { + glConfig.textureCompression = TC_S3TC; + ri.Printf( PRINT_ALL, "...using GL_S3_s3tc\n" ); + } else + { + glConfig.textureCompression = TC_NONE; + ri.Printf( PRINT_ALL, "...ignoring GL_S3_s3tc\n" ); + } + } else +#endif + { + glConfig.textureCompression = TC_NONE; + ri.Printf( PRINT_ALL, "...GL_S3_s3tc not found\n" ); + } + + // GL_EXT_texture_env_add +#ifdef HAVE_GLES + glConfig.textureEnvAddAvailable = qtrue; + ri.Printf( PRINT_ALL, "...using GL_EXT_texture_env_add\n" ); +#else + glConfig.textureEnvAddAvailable = qfalse; + if ( Q_stristr( glConfig.extensions_string, "EXT_texture_env_add" ) ) { + if ( r_ext_texture_env_add->integer ) { + glConfig.textureEnvAddAvailable = qtrue; + ri.Printf( PRINT_ALL, "...using GL_EXT_texture_env_add\n" ); + } else + { + glConfig.textureEnvAddAvailable = qfalse; + ri.Printf( PRINT_ALL, "...ignoring GL_EXT_texture_env_add\n" ); + } + } else + { + ri.Printf( PRINT_ALL, "...GL_EXT_texture_env_add not found\n" ); + } +#endif + + // GL_ARB_multitexture + qglMultiTexCoord2fARB = NULL; + qglActiveTextureARB = NULL; + qglClientActiveTextureARB = NULL; +#ifdef HAVE_GLES + qglGetIntegerv( GL_MAX_TEXTURE_UNITS, &glConfig.maxActiveTextures ); + //ri.Printf( PRINT_ALL, "...not using GL_ARB_multitexture, %i texture units\n", glConfig.maxActiveTextures ); + //glConfig.maxActiveTextures=4; + qglMultiTexCoord2fARB = myglMultiTexCoord2f; + qglActiveTextureARB = glActiveTexture; + qglClientActiveTextureARB = glClientActiveTexture; + if ( glConfig.maxActiveTextures > 1 ) + { + ri.Printf( PRINT_ALL, "...using GL_ARB_multitexture (%i texture units)\n", glConfig.maxActiveTextures ); + } + else + { + qglMultiTexCoord2fARB = NULL; + qglActiveTextureARB = NULL; + qglClientActiveTextureARB = NULL; + ri.Printf( PRINT_ALL, "...not using GL_ARB_multitexture, < 2 texture units\n" ); + } +#else + if ( Q_stristr( glConfig.extensions_string, "GL_ARB_multitexture" ) ) { + if ( r_ext_multitexture->value ) { + qglMultiTexCoord2fARB = ( PFNGLMULTITEXCOORD2FARBPROC ) dlsym( glw_state.OpenGLLib, "glMultiTexCoord2fARB" ); + qglActiveTextureARB = ( PFNGLACTIVETEXTUREARBPROC ) dlsym( glw_state.OpenGLLib, "glActiveTextureARB" ); + qglClientActiveTextureARB = ( PFNGLCLIENTACTIVETEXTUREARBPROC ) dlsym( glw_state.OpenGLLib, "glClientActiveTextureARB" ); + + if ( qglActiveTextureARB ) { + qglGetIntegerv( GL_MAX_ACTIVE_TEXTURES_ARB, &glConfig.maxActiveTextures ); + + if ( glConfig.maxActiveTextures > 1 ) { + ri.Printf( PRINT_ALL, "...using GL_ARB_multitexture\n" ); + } else + { + qglMultiTexCoord2fARB = NULL; + qglActiveTextureARB = NULL; + qglClientActiveTextureARB = NULL; + ri.Printf( PRINT_ALL, "...not using GL_ARB_multitexture, < 2 texture units\n" ); + } + } + } else + { + ri.Printf( PRINT_ALL, "...ignoring GL_ARB_multitexture\n" ); + } + } else + { + ri.Printf( PRINT_ALL, "...GL_ARB_multitexture not found\n" ); + } +#endif + + // GL_EXT_compiled_vertex_array +#ifndef HAVE_GLES + if ( Q_stristr( glConfig.extensions_string, "GL_EXT_compiled_vertex_array" ) ) { + if ( r_ext_compiled_vertex_array->value ) { + ri.Printf( PRINT_ALL, "...using GL_EXT_compiled_vertex_array\n" ); + qglLockArraysEXT = ( void ( APIENTRY * )( int, int ) )dlsym( glw_state.OpenGLLib, "glLockArraysEXT" ); + qglUnlockArraysEXT = ( void ( APIENTRY * )( void ) )dlsym( glw_state.OpenGLLib, "glUnlockArraysEXT" ); + if ( !qglLockArraysEXT || !qglUnlockArraysEXT ) { + ri.Error( ERR_FATAL, "bad getprocaddress" ); + } + } else + { + ri.Printf( PRINT_ALL, "...ignoring GL_EXT_compiled_vertex_array\n" ); + } + } else +#endif + { + ri.Printf( PRINT_ALL, "...GL_EXT_compiled_vertex_array not found\n" ); + } + + // GL_NV_fog_distance +#ifndef HAVE_GLES + if ( Q_stristr( glConfig.extensions_string, "GL_NV_fog_distance" ) ) { + if ( r_ext_NV_fog_dist->integer ) { + glConfig.NVFogAvailable = qtrue; + ri.Printf( PRINT_ALL, "...using GL_NV_fog_distance\n" ); + } else { + ri.Printf( PRINT_ALL, "...ignoring GL_NV_fog_distance\n" ); + ri.Cvar_Set( "r_ext_NV_fog_dist", "0" ); + } + } else +#endif + { + ri.Printf( PRINT_ALL, "...GL_NV_fog_distance not found\n" ); + ri.Cvar_Set( "r_ext_NV_fog_dist", "0" ); + } + +} + +static void GLW_InitGamma() { + + glConfig.deviceSupportsGamma = qfalse; + +} + +/* + ** GLW_LoadOpenGL + ** + ** GLimp_win.c internal function that that attempts to load and use + ** a specific OpenGL DLL. + */ +static qboolean GLW_LoadOpenGL( const char *name ) { + qboolean fullscreen; + + ri.Printf( PRINT_ALL, "...loading %s: ", name ); + +#ifndef HAVE_GLES + // disable the 3Dfx splash screen and set gamma + // we do this all the time, but it shouldn't hurt anything + // on non-3Dfx stuff + putenv( "FX_GLIDE_NO_SPLASH=0" ); + + // Mesa VooDoo hacks + putenv( "MESA_GLX_FX=fullscreen\n" ); +#endif + // load the QGL layer + if ( QGL_Init( name ) ) { +#ifdef PANDORA + fullscreen = 1; +#else + fullscreen = r_fullscreen->integer; +#endif + + // create the window and set up the context + if ( !GLW_StartDriverAndSetMode( name, r_mode->integer, fullscreen ) ) { + if ( r_mode->integer != 3 ) { + if ( !GLW_StartDriverAndSetMode( name, 3, fullscreen ) ) { + goto fail; + } + } else { + goto fail; + } + } + + return qtrue; + } else + { + ri.Printf( PRINT_ALL, "failed\n" ); + } + fail: + + QGL_Shutdown(); + + return qfalse; +} + + + +/* + ** GLimp_Init + ** + ** This routine is responsible for initializing the OS specific portions + ** of OpenGL. + */ +void GLimp_Init( void ) { + qboolean attemptedlibGL = qfalse; + qboolean attempted3Dfx = qfalse; + qboolean success = qfalse; + char buf[1024]; + cvar_t *lastValidRenderer = ri.Cvar_Get( "r_lastValidRenderer", "(uninitialized)", CVAR_ARCHIVE ); + // cvar_t *cv; // bk001204 - unused + + r_allowSoftwareGL = ri.Cvar_Get( "r_allowSoftwareGL", "0", CVAR_LATCH ); + + r_previousglDriver = ri.Cvar_Get( "r_previousglDriver", "", CVAR_ROM ); + + InitSig(); + + // Hack here so that if the UI + if ( *r_previousglDriver->string ) { + // The UI changed it on us, hack it back + // This means the renderer can't be changed on the fly + ri.Cvar_Set( "r_glDriver", r_previousglDriver->string ); + } + + + glConfig.vidWidth = android_screen_width; + glConfig.vidHeight = android_screen_height; + glConfig.colorBits = 32; + glConfig.depthBits = 16; + glConfig.stencilBits = 8; + + + + // Save it in case the UI stomps it + ri.Cvar_Set( "r_previousglDriver", r_glDriver->string ); + + // This values force the UI to disable driver selection + glConfig.driverType = GLDRV_ICD; + glConfig.hardwareType = GLHW_GENERIC; + + // get our config strings + Q_strncpyz( glConfig.vendor_string, qglGetString( GL_VENDOR ), sizeof( glConfig.vendor_string ) ); + Q_strncpyz( glConfig.renderer_string, qglGetString( GL_RENDERER ), sizeof( glConfig.renderer_string ) ); + if ( *glConfig.renderer_string && glConfig.renderer_string[strlen( glConfig.renderer_string ) - 1] == '\n' ) { + glConfig.renderer_string[strlen( glConfig.renderer_string ) - 1] = 0; + } + Q_strncpyz( glConfig.version_string, qglGetString( GL_VERSION ), sizeof( glConfig.version_string ) ); + Q_strncpyz( glConfig.extensions_string, qglGetString( GL_EXTENSIONS ), sizeof( glConfig.extensions_string ) ); + + // + // chipset specific configuration + // + strcpy( buf, glConfig.renderer_string ); + strlwr( buf ); + + // + // NOTE: if changing cvars, do it within this block. This allows them + // to be overridden when testing driver fixes, etc. but only sets + // them to their default state when the hardware is first installed/run. + // + if ( Q_stricmp( lastValidRenderer->string, glConfig.renderer_string ) ) { + glConfig.hardwareType = GLHW_GENERIC; + + ri.Cvar_Set( "r_textureMode", "GL_LINEAR_MIPMAP_NEAREST" ); + + // VOODOO GRAPHICS w/ 2MB + if ( Q_stristr( buf, "voodoo graphics/1 tmu/2 mb" ) ) { + ri.Cvar_Set( "r_picmip", "2" ); + ri.Cvar_Get( "r_picmip", "1", CVAR_ARCHIVE | CVAR_LATCH ); + } else + { + ri.Cvar_Set( "r_picmip", "1" ); + + if ( Q_stristr( buf, "rage 128" ) || Q_stristr( buf, "rage128" ) ) { + ri.Cvar_Set( "r_finish", "0" ); + } + // Savage3D and Savage4 should always have trilinear enabled + else if ( Q_stristr( buf, "savage3d" ) || Q_stristr( buf, "s3 savage4" ) ) { + ri.Cvar_Set( "r_texturemode", "GL_LINEAR_MIPMAP_LINEAR" ); + } + } + } + + // + // this is where hardware specific workarounds that should be + // detected/initialized every startup should go. + // + if ( Q_stristr( buf, "banshee" ) || Q_stristr( buf, "Voodoo_Graphics" ) ) { + glConfig.hardwareType = GLHW_3DFX_2D3D; + } else if ( Q_stristr( buf, "rage pro" ) || Q_stristr( buf, "RagePro" ) ) { + glConfig.hardwareType = GLHW_RAGEPRO; + } else if ( Q_stristr( buf, "permedia2" ) ) { + glConfig.hardwareType = GLHW_PERMEDIA2; + } else if ( Q_stristr( buf, "riva 128" ) ) { + glConfig.hardwareType = GLHW_RIVA128; + } else if ( Q_stristr( buf, "riva tnt " ) ) { + } + + ri.Cvar_Set( "r_lastValidRenderer", glConfig.renderer_string ); + + //TEST!!! + //ri.Cvar_Set( "r_picmip", "0" ); + //ri.Cvar_Set( "r_texturemode", "GL_LINEAR_MIPMAP_LINEAR" ); + //!!!! + + + // initialize extensions + GLW_InitExtensions(); + GLW_InitGamma(); + + InitSig(); + + return; +} + + +int androidSwapped = 1; //If loading, then draw frame does not return, so detect this +/* + ** GLimp_EndFrame + ** + ** Responsible for doing a swapbuffers and possibly for other stuff + ** as yet to be determined. Probably better not to make this a GLimp + ** function and instead do a call to GLimp_SwapBuffers. + */ +void GLimp_EndFrame( void ) { + + // check logging + //QGL_EnableLogging( (qboolean)r_logFile->integer ); // bk001205 - was ->value + if (!androidSwapped) + eglSwapBuffers( eglGetCurrentDisplay(), eglGetCurrentSurface( EGL_DRAW ) ); + + androidSwapped = 0; + +} + +#ifdef SMP +/* +=========================================================== + +SMP acceleration + +=========================================================== + */ + +sem_t renderCommandsEvent; +sem_t renderCompletedEvent; +sem_t renderActiveEvent; + +void ( *glimpRenderThread )( void ); + +void *GLimp_RenderThreadWrapper( void *stub ) { + glimpRenderThread(); + return NULL; +} + + +/* +======================= +GLimp_SpawnRenderThread +======================= + */ +pthread_t renderThreadHandle; +qboolean GLimp_SpawnRenderThread( void ( *function )( void ) ) { + + sem_init( &renderCommandsEvent, 0, 0 ); + sem_init( &renderCompletedEvent, 0, 0 ); + sem_init( &renderActiveEvent, 0, 0 ); + + glimpRenderThread = function; + + if ( pthread_create( &renderThreadHandle, NULL, + GLimp_RenderThreadWrapper, NULL ) ) { + return qfalse; + } + + return qtrue; +} + +static void *smpData; +//static int glXErrors; // bk001204 - unused + +void *GLimp_RendererSleep( void ) { + void *data; + + // after this, the front end can exit GLimp_FrontEndSleep + sem_post( &renderCompletedEvent ); + + sem_wait( &renderCommandsEvent ); + + data = smpData; + + // after this, the main thread can exit GLimp_WakeRenderer + sem_post( &renderActiveEvent ); + + return data; +} + + +void GLimp_FrontEndSleep( void ) { + sem_wait( &renderCompletedEvent ); +} + + +void GLimp_WakeRenderer( void *data ) { + smpData = data; + + // after this, the renderer can continue through GLimp_RendererSleep + sem_post( &renderCommandsEvent ); + + sem_wait( &renderActiveEvent ); +} + +#else + +void GLimp_RenderThreadWrapper( void *stub ) {} +qboolean GLimp_SpawnRenderThread( void ( *function )( void ) ) { + return qfalse; +} +void *GLimp_RendererSleep( void ) { + return NULL; +} +void GLimp_FrontEndSleep( void ) {} +void GLimp_WakeRenderer( void *data ) {} + +#endif + +/*****************************************************************************/ +/* MOUSE */ +/*****************************************************************************/ + +void IN_Init( void ) { + // mouse variables + in_mouse = Cvar_Get( "in_mouse", "1", CVAR_ARCHIVE ); + in_dgamouse = Cvar_Get( "in_dgamouse", "1", CVAR_ARCHIVE ); + +} + +void IN_Shutdown( void ) { + +} +/* +void IN_Frame( void ) { + + + if ( cls.keyCatchers & KEYCATCH_CONSOLE ) { + // temporarily deactivate if not in the game and + // running on the desktop + // voodoo always counts as full screen + if ( Cvar_VariableValue( "r_fullscreen" ) == 0 + && strcmp( Cvar_VariableString( "r_glDriver" ), _3DFX_DRIVER_NAME ) ) { + IN_DeactivateMouse(); + return; + } + } + + IN_ActivateMouse(); +} + */ + +void IN_Activate( void ) { +} + +// bk001130 - cvs1.17 joystick code (mkv) was here, no linux_joystick.c + +void Sys_SendKeyEvents( void ) { + // XEvent event; // bk001204 - unused + + + //HandleEvents(); +} + + +// bk010216 - added stubs for non-Linux UNIXes here +// FIXME - use NO_JOYSTICK or something else generic + +#if defined( __FreeBSD__ ) // rb010123 +void IN_StartupJoystick( void ) {} +void IN_JoyMove( void ) {} +#endif diff --git a/Projects/Android/jni/rtcw/src/android/android_local.h b/Projects/Android/jni/rtcw/src/android/android_local.h new file mode 100644 index 0000000..1ce496a --- /dev/null +++ b/Projects/Android/jni/rtcw/src/android/android_local.h @@ -0,0 +1,57 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +// linux_local.h: Linux-specific Quake3 header file + +void Sys_QueEvent( int time, sysEventType_t type, int value, int value2, int ptrLength, void *ptr ); +qboolean Sys_GetPacket( netadr_t *net_from, msg_t *net_message ); +void Sys_SendKeyEvents( void ); + +// Input subsystem + +void IN_Init( void ); +void IN_Frame( void ); +void IN_Shutdown( void ); + + +void IN_JoyMove( void ); +void IN_StartupJoystick( void ); + +// GL subsystem +qboolean QGL_Init( const char *dllname ); +void QGL_EnableLogging( qboolean enable ); +void QGL_Shutdown( void ); + + + + + +// bk001130 - win32 +// void IN_JoystickCommands (void); + +char *strlwr( char *s ); diff --git a/Projects/Android/jni/rtcw/src/android/android_main.c b/Projects/Android/jni/rtcw/src/android/android_main.c new file mode 100644 index 0000000..855220d --- /dev/null +++ b/Projects/Android/jni/rtcw/src/android/android_main.c @@ -0,0 +1,1414 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +//#include +#include +#include +#include +#include +#include +#include +#ifdef __linux__ // rb010123 + #include +#endif +#include + +#ifdef __linux__ + // #include // bk001213 - force dumps on divide by zero +#endif + +// FIXME TTimo should we gard this? most *nix system should comply? +#include + +#include "../game/q_shared.h" +#include "../qcommon/qcommon.h" +#include "../renderer/tr_public.h" + +#include "android_local.h" // bk001204 +#include + + +// Structure containing functions exported from refresh DLL +refexport_t re; + +unsigned sys_frame_time; + +uid_t saved_euid; +qboolean stdin_active = qtrue; + +// ============================================================= +// tty console variables +// ============================================================= + +// enable/disabled tty input mode +// NOTE TTimo this is used during startup, cannot be changed during run +static cvar_t *ttycon = NULL; +// general flag to tell about tty console mode +static qboolean ttycon_on = qfalse; +// when printing general stuff to stdout stderr (Sys_Printf) +// we need to disable the tty console stuff +// this increments to we can recursively disable +static int ttycon_hide = 0; +// some key codes that the terminal may be using +// TTimo NOTE: I'm not sure how relevant this is +static int tty_erase; +static int tty_eof; + +static struct termios tty_tc; + +static field_t tty_con; + +// history +// NOTE TTimo this is a bit duplicate of the graphical console history +// but it's safer and faster to write our own here +#define TTY_HISTORY 32 +static field_t ttyEditLines[TTY_HISTORY]; +static int hist_current = -1, hist_count = 0; + +// ======================================================================= +// General routines +// ======================================================================= + +// bk001207 +#define MEM_THRESHOLD 96 * 1024 * 1024 + +/* +================== +Sys_LowPhysicalMemory() +================== +*/ +qboolean Sys_LowPhysicalMemory() { + //MEMORYSTATUS stat; + //GlobalMemoryStatus (&stat); + //return (stat.dwTotalPhys <= MEM_THRESHOLD) ? qtrue : qfalse; + return qfalse; // bk001207 - FIXME +} + +void Sys_BeginProfiling( void ) { +} + +/* +================= +Sys_In_Restart_f + +Restart the input subsystem +================= +*/ +void Sys_In_Restart_f( void ) { + IN_Shutdown(); + IN_Init(); +} + +// ============================================================= +// tty console routines +// NOTE: if the user is editing a line when something gets printed to the early console then it won't look good +// so we provide tty_Clear and tty_Show to be called before and after a stdout or stderr output +// ============================================================= + +// flush stdin, I suspect some terminals are sending a LOT of shit +// FIXME TTimo relevant? +void tty_FlushIn() { + char key; + while ( read( 0, &key, 1 ) != -1 ) ; +} + +// do a backspace +// TTimo NOTE: it seems on some terminals just sending '\b' is not enough +// so for now, in any case we send "\b \b" .. yeah well .. +// (there may be a way to find out if '\b' alone would work though) +void tty_Back() { + char key; + key = '\b'; + write( 1, &key, 1 ); + key = ' '; + write( 1, &key, 1 ); + key = '\b'; + write( 1, &key, 1 ); +} + +// clear the display of the line currently edited +// bring cursor back to beginning of line +void tty_Hide() { + int i; + assert( ttycon_on ); + if ( ttycon_hide ) { + ttycon_hide++; + return; + } + if ( tty_con.cursor > 0 ) { + for ( i = 0; i < tty_con.cursor; i++ ) + { + tty_Back(); + } + } + ttycon_hide++; +} + +// show the current line +// FIXME TTimo need to position the cursor if needed?? +void tty_Show() { + int i; + assert( ttycon_on ); + assert( ttycon_hide > 0 ); + ttycon_hide--; + if ( ttycon_hide == 0 ) { + if ( tty_con.cursor ) { + for ( i = 0; i < tty_con.cursor; i++ ) + { + write( 1, tty_con.buffer + i, 1 ); + } + } + } +} + +// never exit without calling this, or your terminal will be left in a pretty bad state +void Sys_ConsoleInputShutdown() { + if ( ttycon_on ) { + Com_Printf( "Shutdown tty console\n" ); + tcsetattr( 0, TCSADRAIN, &tty_tc ); + } +} + +void Hist_Add( field_t *field ) { + int i; + assert( hist_count <= TTY_HISTORY ); + assert( hist_count >= 0 ); + assert( hist_current >= -1 ); + assert( hist_current <= hist_count ); + // make some room + for ( i = TTY_HISTORY - 1; i > 0; i-- ) + { + ttyEditLines[i] = ttyEditLines[i - 1]; + } + ttyEditLines[0] = *field; + if ( hist_count < TTY_HISTORY ) { + hist_count++; + } + hist_current = -1; // re-init +} + +field_t *Hist_Prev() { + int hist_prev; + assert( hist_count <= TTY_HISTORY ); + assert( hist_count >= 0 ); + assert( hist_current >= -1 ); + assert( hist_current <= hist_count ); + hist_prev = hist_current + 1; + if ( hist_prev >= hist_count ) { + return NULL; + } + hist_current++; + return &( ttyEditLines[hist_current] ); +} + +field_t *Hist_Next() { + assert( hist_count <= TTY_HISTORY ); + assert( hist_count >= 0 ); + assert( hist_current >= -1 ); + assert( hist_current <= hist_count ); + if ( hist_current >= 0 ) { + hist_current--; + } + if ( hist_current == -1 ) { + return NULL; + } + return &( ttyEditLines[hist_current] ); +} + +// ============================================================= +// general sys routines +// ============================================================= + +#define MAX_CMD 1024 +static char exit_cmdline[MAX_CMD] = ""; +void Sys_DoStartProcess( char *cmdline ); + +// single exit point (regular exit or in case of signal fault) +void Sys_Exit( int ex ) { + LOGI("Sys_Exit"); + + exit(1); + + Sys_ConsoleInputShutdown(); + + // we may be exiting to spawn another process + if ( exit_cmdline[0] != '\0' ) { + // temporize, it seems if you spawn too fast before GL is released, or if you exit too fast after the fork + // some kernel can panic (my 2.4.17 does) + sleep( 1 ); + Sys_DoStartProcess( exit_cmdline ); + sleep( 1 ); + } + +#ifdef NDEBUG // regular behavior + + // We can't do this + // as long as GL DLL's keep installing with atexit... + //exit(ex); + _exit( ex ); +#else + + // Give me a backtrace on error exits. + assert( ex == 0 ); + exit( ex ); +#endif +} + + +void Sys_Quit( void ) { + CL_Shutdown(); + + Sys_Exit( 0 ); +} + +void Sys_Init( void ) { + Cmd_AddCommand( "in_restart", Sys_In_Restart_f ); + +#if defined __linux__ +#if defined __i386__ + Cvar_Set( "arch", "linux i386" ); +#elif defined __alpha__ + Cvar_Set( "arch", "linux alpha" ); +#elif defined __sparc__ + Cvar_Set( "arch", "linux sparc" ); +#elif defined __FreeBSD__ + +#if defined __i386__ // FreeBSD + Cvar_Set( "arch", "freebsd i386" ); +#elif defined __alpha__ + Cvar_Set( "arch", "freebsd alpha" ); +#else + Cvar_Set( "arch", "freebsd unknown" ); +#endif // FreeBSD + +#else + Cvar_Set( "arch", "linux unknown" ); +#endif +#elif defined __sun__ +#if defined __i386__ + Cvar_Set( "arch", "solaris x86" ); +#elif defined __sparc__ + Cvar_Set( "arch", "solaris sparc" ); +#else + Cvar_Set( "arch", "solaris unknown" ); +#endif +#elif defined __sgi__ +#if defined __mips__ + Cvar_Set( "arch", "sgi mips" ); +#else + Cvar_Set( "arch", "sgi unknown" ); +#endif +#else + Cvar_Set( "arch", "unknown" ); +#endif + + Cvar_Set( "username", Sys_GetCurrentUser() ); + + IN_Init(); + +} + +void Sys_Error( const char *error, ... ) { + va_list argptr; + char string[1024]; + + // change stdin to non blocking + // NOTE TTimo not sure how well that goes with tty console mode + //fcntl( 0, F_SETFL, fcntl( 0, F_GETFL, 0 ) & ~FNDELAY ); + + // don't bother do a show on this one heh + if ( ttycon_on ) { + tty_Hide(); + } + + CL_Shutdown(); + + va_start( argptr,error ); + vsprintf( string,error,argptr ); + va_end( argptr ); + + __android_log_print(ANDROID_LOG_ERROR,"JK2","%s", string); + fprintf( stderr, "Sys_Error: %s\n", string ); + + Sys_Exit( 1 ); // bk010104 - use single exit point. +} + +void Sys_Warn( char *warning, ... ) { + va_list argptr; + char string[1024]; + + va_start( argptr,warning ); + vsprintf( string,warning,argptr ); + va_end( argptr ); + + if ( ttycon_on ) { + tty_Hide(); + } + + ((void)__android_log_print(ANDROID_LOG_INFO,"RTCW","%s", string)); + fprintf( stderr, "Warning: %s", string ); + + if ( ttycon_on ) { + tty_Show(); + } +} + +/* +============ +Sys_FileTime + +returns -1 if not present +============ +*/ +int Sys_FileTime( char *path ) { + struct stat buf; + + if ( stat( path,&buf ) == -1 ) { + return -1; + } + + return buf.st_mtime; +} + +void floating_point_exception_handler( int whatever ) { + signal( SIGFPE, floating_point_exception_handler ); +} + +// initialize the console input (tty mode if wanted and possible) +void Sys_ConsoleInputInit() { + struct termios tc; + + // TTimo + // show_bug.cgi?id=390 + // ttycon 0 or 1, if the process is backgrounded (running non interactively) + // then SIGTTIN or SIGTOU is emitted, if not catched, turns into a SIGSTP + signal( SIGTTIN, SIG_IGN ); + signal( SIGTTOU, SIG_IGN ); + + // FIXME TTimo initialize this in Sys_Init or something? + ttycon = Cvar_Get( "ttycon", "1", 0 ); + if ( ttycon && ttycon->value ) { + if ( isatty( STDIN_FILENO ) != 1 ) { + Com_Printf( "stdin is not a tty, tty console mode failed\n" ); + Cvar_Set( "ttycon", "0" ); + ttycon_on = qfalse; + return; + } + Com_Printf( "Started tty console (use +set ttycon 0 to disable)\n" ); + Field_Clear( &tty_con ); + tcgetattr( 0, &tty_tc ); + tty_erase = tc.c_cc[VERASE]; + tty_eof = tc.c_cc[VEOF]; + tc = tty_tc; + /* + ECHO: don't echo input characters + ICANON: enable canonical mode. This enables the special + characters EOF, EOL, EOL2, ERASE, KILL, REPRINT, + STATUS, and WERASE, and buffers by lines. + ISIG: when any of the characters INTR, QUIT, SUSP, or + DSUSP are received, generate the corresponding sig­ + nal + */ + tc.c_lflag &= ~( ECHO | ICANON ); + /* + ISTRIP strip off bit 8 + INPCK enable input parity checking + */ + tc.c_iflag &= ~( ISTRIP | INPCK ); + tc.c_cc[VMIN] = 1; + tc.c_cc[VTIME] = 0; + tcsetattr( 0, TCSADRAIN, &tc ); + ttycon_on = qtrue; + } else { + ttycon_on = qfalse; + } +} + +char *Sys_ConsoleInput( void ) { + // we use this when sending back commands + static char text[256]; + int i; + int avail; + char key; + field_t *history; + + if ( ttycon && ttycon->value ) { + avail = read( 0, &key, 1 ); + if ( avail != -1 ) { + // we have something + // backspace? + // NOTE TTimo testing a lot of values .. seems it's the only way to get it to work everywhere + if ( ( key == tty_erase ) || ( key == 127 ) || ( key == 8 ) ) { + if ( tty_con.cursor > 0 ) { + tty_con.cursor--; + tty_con.buffer[tty_con.cursor] = '\0'; + tty_Back(); + } + return NULL; + } + // check if this is a control char + if ( ( key ) && ( key ) < ' ' ) { + if ( key == '\n' ) { + // push it in history + Hist_Add( &tty_con ); + strcpy( text, tty_con.buffer ); + Field_Clear( &tty_con ); + key = '\n'; + write( 1, &key, 1 ); + return text; + } + if ( key == '\t' ) { + tty_Hide(); + Field_CompleteCommand( &tty_con ); + // Field_CompleteCommand does weird things to the string, do a cleanup + // it adds a '\' at the beginning of the string + // cursor doesn't reflect actual length of the string that's sent back + tty_con.cursor = strlen( tty_con.buffer ); + if ( tty_con.cursor > 0 ) { + if ( tty_con.buffer[0] == '\\' ) { + for ( i = 0; i <= tty_con.cursor; i++ ) + { + tty_con.buffer[i] = tty_con.buffer[i + 1]; + } + tty_con.cursor--; + } + } + tty_Show(); + return NULL; + } + avail = read( 0, &key, 1 ); + if ( avail != -1 ) { + // VT 100 keys + if ( key == '[' || key == 'O' ) { + avail = read( 0, &key, 1 ); + if ( avail != -1 ) { + switch ( key ) + { + case 'A': + history = Hist_Prev(); + if ( history ) { + tty_Hide(); + tty_con = *history; + tty_Show(); + } + tty_FlushIn(); + return NULL; + break; + case 'B': + history = Hist_Next(); + tty_Hide(); + if ( history ) { + tty_con = *history; + } else + { + Field_Clear( &tty_con ); + } + tty_Show(); + tty_FlushIn(); + return NULL; + break; + case 'C': + return NULL; + case 'D': + return NULL; + } + } + } + } + Com_DPrintf( "droping ISCTL sequence: %d, tty_erase: %d\n", key, tty_erase ); + tty_FlushIn(); + return NULL; + } + // push regular character + tty_con.buffer[tty_con.cursor] = key; + tty_con.cursor++; + // print the current line (this is differential) + write( 1, &key, 1 ); + } + return NULL; + } else + { + int len; + fd_set fdset; + struct timeval timeout; + + if ( !com_dedicated || !com_dedicated->value ) { + return NULL; + } + + if ( !stdin_active ) { + return NULL; + } + + FD_ZERO( &fdset ); + FD_SET( 0, &fdset ); // stdin + timeout.tv_sec = 0; + timeout.tv_usec = 0; + if ( select( 1, &fdset, NULL, NULL, &timeout ) == -1 || !FD_ISSET( 0, &fdset ) ) { + return NULL; + } + + len = read( 0, text, sizeof( text ) ); + if ( len == 0 ) { // eof! + stdin_active = qfalse; + return NULL; + } + + if ( len < 1 ) { + return NULL; + } + text[len - 1] = 0; // rip off the /n and terminate + + return text; + } +} + +/*****************************************************************************/ + +/* +================= +Sys_UnloadDll + +================= +*/ +void Sys_UnloadDll( void *dllHandle ) { + + Com_Printf( "Sys_UnloadDll %p",dllHandle); + + // bk001206 - verbose error reporting + const char* err; // rb010123 - now const + if ( !dllHandle ) { + Com_Printf( "Sys_UnloadDll(NULL)\n" ); + return; + } + + + dlclose( dllHandle ); + err = dlerror(); + if ( err != NULL ) { + Com_Printf( "Sys_UnloadGame failed on dlclose: \"%s\"!\n", err ); + } +} + + +/* +================= +Sys_LoadDll +================= +*/ +extern char *FS_BuildOSPath( const char *base, const char *game, const char *qpath ); + + +extern const char * getLibPath(); + +// TTimo +// show_bug.cgi?id=411 +// use DO_LOADDLL_WRAP to wrap a cl_noprint 1 around the call to Sys_LoadDll +// this is a quick hack to avoid complicated messages on screen +#ifdef NDEBUG +#define DO_LOADDLL_WRAP +#endif + +#if defined( DO_LOADDLL_WRAP ) +void *Sys_LoadDll_Wrapped( const char *name, + int( **entryPoint ) ( int, ... ), + int ( *systemcalls )( int, ... ) ) +#else +void *Sys_LoadDll( const char *name, + int( **entryPoint ) ( int, ... ), + int ( *systemcalls )( int, ... ) ) +#endif +{ + void *libHandle; + void ( *dllEntry )( int ( *syscallptr )( int, ... ) ); + char fname[MAX_OSPATH]; + char *homepath; + char *basepath; + char *pwdpath; + char *gamedir; + char *fn; + const char* err = NULL; // bk001206 // rb0101023 - now const + + // bk001206 - let's have some paranoia + assert( name ); + +#if defined __i386__ + snprintf( fname, sizeof( fname ), "%si386.so", name ); +#elif defined __powerpc__ //rcg010207 - PPC support. + snprintf( fname, sizeof( fname ), "%sppc.so", name ); +#elif defined __axp__ + snprintf( fname, sizeof( fname ), "%saxp.so", name ); +#elif defined ARM +#ifdef PANDORA + snprintf( fname, sizeof( fname ), "../%sarm.so", name ); +#else + snprintf( fname, sizeof( fname ), "%sarm.so", name ); +#endif +#elif defined __mips__ + snprintf( fname, sizeof( fname ), "%smips.so", name ); +#else +#error Unknown arch +#endif + +// bk001129 - was RTLD_LAZY +#define Q_RTLD RTLD_NOW + + homepath = Cvar_VariableString( "fs_homepath" ); + basepath = Cvar_VariableString( "fs_basepath" ); + gamedir = Cvar_VariableString( "fs_game" ); + + pwdpath = Sys_Cwd(); + fn = FS_BuildOSPath( pwdpath, gamedir, fname ); + // bk001206 - verbose + Com_Printf( "Sys_LoadDll(%s)... ", fn ); + +#ifdef __ANDROID__ + char path[500]; + +#ifdef WOLF_SP_DEMO + snprintf( path, sizeof( path ), "%s/lib%sarm_d.so", getLibPath(), name ); +#else + snprintf( path, sizeof( path ), "%s/lib%sarm.so", getLibPath(), name ); +#endif + + LOGI("Trying to load Android lib: %s",path); + libHandle = dlopen (path, RTLD_LAZY ); + + if (!libHandle) //Some devices put an extra 1 on the end!!! + { + LOGI("TRYING -0 LIBRARY"); +#ifdef WOLF_SP_DEMO + snprintf( path, sizeof( path ), "/data/data/com.beloko.rtcw/lib/lib%sarm_d.so", name ); +#else + snprintf( path, sizeof( path ), "/data/data/com.beloko.rtcw/lib/lib%sarm.so", name ); +#endif + + + libHandle = dlopen (path, Q_RTLD ); + } + + if (!libHandle) //Some devices put an extra 1 on the end!!! + { + LOGI("TRYING -1 LIBRARY"); +#ifdef WOLF_SP_DEMO + snprintf( path, sizeof( path ), "/data/data/com.beloko.rtcw-1/lib/lib%sarm_d.so", name ); +#else + snprintf( path, sizeof( path ), "/data/data/com.beloko.rtcw-1/lib/lib%sarm.so", name ); +#endif + libHandle = dlopen (path, Q_RTLD ); + + } + + if (!libHandle) //Just in case... + { + LOGI("TRYING -2 LIBRARY"); +#ifdef WOLF_SP_DEMO + snprintf( path, sizeof( path ), "/data/data/com.beloko.rtcw-2/lib/lib%sarm_d.so", name ); +#else + snprintf( path, sizeof( path ), "/data/data/com.beloko.rtcw-2/lib/lib%sarm.so", name ); +#endif + libHandle = dlopen (path, Q_RTLD ); + + } + + +#else + // bk001129 - from cvs1.17 (mkv), was fname not fn + libHandle = dlopen( fn, Q_RTLD ); +#endif + + + if ( !libHandle ) { + Com_Printf( "failed (%s)\n", dlerror() ); + // homepath + fn = FS_BuildOSPath( homepath, gamedir, fname ); + Com_Printf( "Sys_LoadDll(%s)... ", fn ); + libHandle = dlopen( fn, Q_RTLD ); + + if ( !libHandle ) { + Com_Printf( "failed (%s)\n", dlerror() ); + // basepath + fn = FS_BuildOSPath( basepath, gamedir, fname ); + Com_Printf( "Sys_LoadDll(%s)... ", fn ); + libHandle = dlopen( fn, Q_RTLD ); + + if ( !libHandle ) { + Com_Printf( "failed (%s)\n", dlerror() ); + + if ( strlen( gamedir ) && Q_stricmp( gamedir, BASEGAME ) ) { // begin BASEGAME != fs_game section + + // media-only mods: no DLL whatsoever in the fs_game + // start the loop again using the hardcoded BASEDIRNAME + fn = FS_BuildOSPath( pwdpath, BASEGAME, fname ); + Com_Printf( "Sys_LoadDll(%s)... ", fn ); + libHandle = dlopen( fn, Q_RTLD ); + + if ( !libHandle ) { + Com_Printf( "failed (%s)\n", dlerror() ); + // homepath + fn = FS_BuildOSPath( homepath, BASEGAME, fname ); + Com_Printf( "Sys_LoadDll(%s)... ", fn ); + libHandle = dlopen( fn, Q_RTLD ); + + if ( !libHandle ) { + Com_Printf( "failed (%s)\n", dlerror() ); + // homepath + fn = FS_BuildOSPath( basepath, BASEGAME, fname ); + Com_Printf( "Sys_LoadDll(%s)... ", fn ); + libHandle = dlopen( fn, Q_RTLD ); + + if ( !libHandle ) { + // ok, this time things are really fucked + Com_Printf( "failed (%s)\n", dlerror() ); + } else { + Com_Printf( "ok\n" ); + } + } else { + Com_Printf( "ok\n" ); + } + } else { + Com_Printf( "ok\n" ); + } + } // end BASEGAME != fs_game section + } else { + Com_Printf( "ok\n" ); + } + } else { + Com_Printf( "ok\n" ); + } + } else { + Com_Printf( "ok\n" ); + } + + if ( !libHandle ) { +#ifndef NDEBUG // in debug, abort on failure + Com_Error( ERR_FATAL, "Sys_LoadDll(%s) failed dlopen() completely!\n", name ); +#else + Com_Printf( "Sys_LoadDll(%s) failed dlopen() completely!\n", name ); +#endif + return NULL; + } + + Com_Printf( "Sys_LoadDll handle = %p", libHandle ); + + dllEntry = dlsym( libHandle, "dllEntry" ); + *entryPoint = dlsym( libHandle, "vmMain" ); + if ( !*entryPoint || !dllEntry ) { + err = dlerror(); +#ifndef NDEBUG // bk001206 - in debug abort on failure + Com_Error( ERR_FATAL, "Sys_LoadDll(%s) failed dlsym(vmMain):\n\"%s\" !\n", name, err ); +#else + Com_Printf( "Sys_LoadDll(%s) failed dlsym(vmMain):\n\"%s\" !\n", name, err ); +#endif + dlclose( libHandle ); + err = dlerror(); + if ( err != NULL ) { + Com_Printf( "Sys_LoadDll(%s) failed dlcose:\n\"%s\"\n", name, err ); + } + return NULL; + } + Com_Printf( "Sys_LoadDll(%s) found **vmMain** at %p \n", name, *entryPoint ); // bk001212 + dllEntry( systemcalls ); + Com_Printf( "Sys_LoadDll(%s) succeeded!\n", name ); + return libHandle; +} + +#if defined( DO_LOADDLL_WRAP ) +void *Sys_LoadDll( const char *name, + int( **entryPoint ) ( int, ... ), + int ( *systemcalls )( int, ... ) ) { + void *ret; + Cvar_Set( "cl_noprint", "1" ); + ret = Sys_LoadDll_Wrapped( name, entryPoint, systemcalls ); + Cvar_Set( "cl_noprint", "0" ); + return ret; +}; +#endif + +/* +======================================================================== + +BACKGROUND FILE STREAMING + +======================================================================== +*/ + +#if 1 + +void Sys_InitStreamThread( void ) { +} + +void Sys_ShutdownStreamThread( void ) { +} + +void Sys_BeginStreamedFile( fileHandle_t f, int readAhead ) { +} + +void Sys_EndStreamedFile( fileHandle_t f ) { +} + +int Sys_StreamedRead( void *buffer, int size, int count, fileHandle_t f ) { + return FS_Read( buffer, size * count, f ); +} + +void Sys_StreamSeek( fileHandle_t f, int offset, int origin ) { + FS_Seek( f, offset, origin ); +} + +#else + +typedef struct +{ + fileHandle_t file; + byte *buffer; + qboolean eof; + int bufferSize; + int streamPosition; // next byte to be returned by Sys_StreamRead + int threadPosition; // next byte to be read from file +} streamState_t; + +streamState_t stream; + +/* +=============== +Sys_StreamThread + +A thread will be sitting in this loop forever +================ +*/ +void Sys_StreamThread( void ) { + int buffer; + int count; + int readCount; + int bufferPoint; + int r; + + // if there is any space left in the buffer, fill it up + if ( !stream.eof ) { + count = stream.bufferSize - ( stream.threadPosition - stream.streamPosition ); + if ( count ) { + bufferPoint = stream.threadPosition % stream.bufferSize; + buffer = stream.bufferSize - bufferPoint; + readCount = buffer < count ? buffer : count; + r = FS_Read( stream.buffer + bufferPoint, readCount, stream.file ); + stream.threadPosition += r; + + if ( r != readCount ) { + stream.eof = qtrue; + } + } + } +} + +/* +=============== +Sys_InitStreamThread + +================ +*/ +void Sys_InitStreamThread( void ) { +} + +/* +=============== +Sys_ShutdownStreamThread + +================ +*/ +void Sys_ShutdownStreamThread( void ) { +} + + +/* +=============== +Sys_BeginStreamedFile + +================ +*/ +void Sys_BeginStreamedFile( fileHandle_t f, int readAhead ) { + if ( stream.file ) { + Com_Error( ERR_FATAL, "Sys_BeginStreamedFile: unclosed stream" ); + } + + stream.file = f; + stream.buffer = Z_Malloc( readAhead ); + stream.bufferSize = readAhead; + stream.streamPosition = 0; + stream.threadPosition = 0; + stream.eof = qfalse; +} + +/* +=============== +Sys_EndStreamedFile + +================ +*/ +void Sys_EndStreamedFile( fileHandle_t f ) { + if ( f != stream.file ) { + Com_Error( ERR_FATAL, "Sys_EndStreamedFile: wrong file" ); + } + + stream.file = 0; + Z_Free( stream.buffer ); +} + + +/* +=============== +Sys_StreamedRead + +================ +*/ +int Sys_StreamedRead( void *buffer, int size, int count, fileHandle_t f ) { + int available; + int remaining; + int sleepCount; + int copy; + int bufferCount; + int bufferPoint; + byte *dest; + + dest = (byte *)buffer; + remaining = size * count; + + if ( remaining <= 0 ) { + Com_Error( ERR_FATAL, "Streamed read with non-positive size" ); + } + + sleepCount = 0; + while ( remaining > 0 ) + { + available = stream.threadPosition - stream.streamPosition; + if ( !available ) { + if ( stream.eof ) { + break; + } + Sys_StreamThread(); + continue; + } + + bufferPoint = stream.streamPosition % stream.bufferSize; + bufferCount = stream.bufferSize - bufferPoint; + + copy = available < bufferCount ? available : bufferCount; + if ( copy > remaining ) { + copy = remaining; + } + memcpy( dest, stream.buffer + bufferPoint, copy ); + stream.streamPosition += copy; + dest += copy; + remaining -= copy; + } + + return ( count * size - remaining ) / size; +} + +/* +=============== +Sys_StreamSeek + +================ +*/ +void Sys_StreamSeek( fileHandle_t f, int offset, int origin ) { + // clear to that point + FS_Seek( f, offset, origin ); + stream.streamPosition = 0; + stream.threadPosition = 0; + stream.eof = qfalse; +} + +#endif + +/* +======================================================================== + +EVENT LOOP + +======================================================================== +*/ + +// bk000306: upped this from 64 +#define MAX_QUED_EVENTS 256 +#define MASK_QUED_EVENTS ( MAX_QUED_EVENTS - 1 ) + +sysEvent_t eventQue[MAX_QUED_EVENTS]; +// bk000306: initialize +int eventHead = 0; +int eventTail = 0; +byte sys_packetReceived[MAX_MSGLEN]; + +/* +================ +Sys_QueEvent + +A time of 0 will get the current time +Ptr should either be null, or point to a block of data that can +be freed by the game later. +================ +*/ +void Sys_QueEvent( int time, sysEventType_t type, int value, int value2, int ptrLength, void *ptr ) { + sysEvent_t *ev; + + ev = &eventQue[ eventHead & MASK_QUED_EVENTS ]; + + // bk000305 - was missing + if ( eventHead - eventTail >= MAX_QUED_EVENTS ) { + Com_Printf( "Sys_QueEvent: overflow\n" ); + // we are discarding an event, but don't leak memory + if ( ev->evPtr ) { + Z_Free( ev->evPtr ); + } + eventTail++; + } + + eventHead++; + + if ( time == 0 ) { + time = Sys_Milliseconds(); + } + + ev->evTime = time; + ev->evType = type; + ev->evValue = value; + ev->evValue2 = value2; + ev->evPtrLength = ptrLength; + ev->evPtr = ptr; +} + +/* +================ +Sys_GetEvent + +================ +*/ +sysEvent_t Sys_GetEvent( void ) { + sysEvent_t ev; + char *s; + msg_t netmsg; + netadr_t adr; + + // return if we have data + if ( eventHead > eventTail ) { + eventTail++; + return eventQue[ ( eventTail - 1 ) & MASK_QUED_EVENTS ]; + } + + // pump the message loop + // in vga this calls KBD_Update, under X, it calls GetEvent + Sys_SendKeyEvents(); +/* + // check for console commands + s = Sys_ConsoleInput(); + if ( s ) { + char *b; + int len; + + len = strlen( s ) + 1; + b = Z_Malloc( len ); + strcpy( b, s ); + Sys_QueEvent( 0, SE_CONSOLE, 0, 0, len, b ); + } +*/ + // check for other input devices + IN_Frame(); + + // check for network packets + MSG_Init( &netmsg, sys_packetReceived, sizeof( sys_packetReceived ) ); + if ( Sys_GetPacket( &adr, &netmsg ) ) { + netadr_t *buf; + int len; + + // copy out to a seperate buffer for qeueing + len = sizeof( netadr_t ) + netmsg.cursize; + buf = Z_Malloc( len ); + *buf = adr; + memcpy( buf + 1, netmsg.data, netmsg.cursize ); + Sys_QueEvent( 0, SE_PACKET, 0, 0, len, buf ); + } + + // return if we have data + if ( eventHead > eventTail ) { + eventTail++; + return eventQue[ ( eventTail - 1 ) & MASK_QUED_EVENTS ]; + } + + // create an empty event to return + + memset( &ev, 0, sizeof( ev ) ); + ev.evTime = Sys_Milliseconds(); + + return ev; +} + +/*****************************************************************************/ + +qboolean Sys_CheckCD( void ) { + return qtrue; +} + +void Sys_AppActivate( void ) { +} + +char *Sys_GetClipboardData( void ) { + return NULL; +} + +void Sys_Print( const char *msg ) { + + ((void)__android_log_print(ANDROID_LOG_INFO,"RTCW","%s", msg)); + + if ( ttycon_on ) { + tty_Hide(); + } + fputs( msg, stderr ); + if ( ttycon_on ) { + tty_Show(); + } +} + + +void Sys_ConfigureFPU() { // bk001213 - divide by zero +#ifdef __linux__ +#ifdef __i386 +#ifndef NDEBUG + + // bk0101022 - enable FPE's in debug mode + static int fpu_word = _FPU_DEFAULT & ~( _FPU_MASK_ZM | _FPU_MASK_IM ); + int current = 0; + _FPU_GETCW( current ); + if ( current != fpu_word ) { +#if 0 + Com_Printf( "FPU Control 0x%x (was 0x%x)\n", fpu_word, current ); + _FPU_SETCW( fpu_word ); + _FPU_GETCW( current ); + assert( fpu_word == current ); +#endif + } +#else // NDEBUG + static int fpu_word = _FPU_DEFAULT; + _FPU_SETCW( fpu_word ); +#endif // NDEBUG +#endif // __i386 +#endif // __linux +} + +void Sys_PrintBinVersion( const char* name ) { + char* date = __DATE__; + char* time = __TIME__; + char* sep = "=============================================================="; + fprintf( stdout, "\n\n%s\n", sep ); +#ifdef DEDICATED + fprintf( stdout, "Linux Quake3 Dedicated Server [%s %s]\n", date, time ); +#else + fprintf( stdout, "Linux Quake3 Full Executable [%s %s]\n", date, time ); +#endif + fprintf( stdout, " local install: %s\n", name ); + fprintf( stdout, "%s\n\n", sep ); +} + +/* +================== +Sys_DoStartProcess +actually forks and starts a process + +UGLY HACK: + Sys_StartProcess works with a command line only + if this command line is actually a binary with command line parameters, + the only way to do this on unix is to use a system() call + but system doesn't replace the current process, which leads to a situation like: + wolf.x86--spawned_process.x86 + in the case of auto-update for instance, this will cause write access denied on wolf.x86: + wolf-beta/2002-March/000079.html + we hack the implementation here, if there are no space in the command line, assume it's a straight process and use execl + otherwise, use system .. + The clean solution would be Sys_StartProcess and Sys_StartProcess_Args.. +================== +*/ +void Sys_DoStartProcess( char *cmdline ) { + switch ( fork() ) + { + case - 1: + // main thread + break; + case 0: + if ( strchr( cmdline, ' ' ) ) { + system( cmdline ); + } else + { + execl( cmdline, cmdline, NULL ); + } + _exit( 0 ); + break; + } +} + +/* +================== +Sys_StartProcess +if !doexit, start the process asap +otherwise, push it for execution at exit +(i.e. let complete shutdown of the game and freeing of resources happen) +NOTE: might even want to add a small delay? +================== +*/ +void Sys_StartProcess( char *cmdline, qboolean doexit ) { + + if ( doexit ) { + Com_DPrintf( "Sys_StartProcess %s (delaying to final exit)\n", cmdline ); + Q_strncpyz( exit_cmdline, cmdline, MAX_CMD ); + Cbuf_ExecuteText( EXEC_APPEND, "quit" ); + return; + } + + Com_DPrintf( "Sys_StartProcess %s\n", cmdline ); + Sys_DoStartProcess( cmdline ); +} + +/* +================= +Sys_OpenURL +================= +*/ +void Sys_OpenURL( char *url, qboolean doexit ) { + char *basepath, *homepath, *pwdpath; + char fname[20]; + char fn[MAX_OSPATH]; + char cmdline[MAX_CMD]; + + Com_Printf( "Sys_OpenURL %s\n", url ); + // opening an URL on *nix can mean a lot of things .. + // just spawn a script instead of deciding for the user :-) + + // do the setup before we fork + // search for an openurl.sh script + // search procedure taken from Sys_LoadDll + Q_strncpyz( fname, "openurl.sh", 20 ); + + pwdpath = Sys_Cwd(); + Com_sprintf( fn, MAX_OSPATH, "%s/%s", pwdpath, fname ); + if ( access( fn, X_OK ) == -1 ) { + Com_DPrintf( "%s not found\n", fn ); + // try in home path + homepath = Cvar_VariableString( "fs_homepath" ); + Com_sprintf( fn, MAX_OSPATH, "%s/%s", homepath, fname ); + if ( access( fn, X_OK ) == -1 ) { + Com_DPrintf( "%s not found\n", fn ); + // basepath, last resort + basepath = Cvar_VariableString( "fs_basepath" ); + Com_sprintf( fn, MAX_OSPATH, "%s/%s", basepath, fname ); + if ( access( fn, X_OK ) == -1 ) { + Com_DPrintf( "%s not found\n", fn ); + Com_Printf( "Can't find script '%s' to open requested URL (use +set developer 1 for more verbosity)\n", fname ); + // we won't quit + return; + } + } + } + + Com_DPrintf( "URL script: %s\n", fn ); + + // build the command line + Com_sprintf( cmdline, MAX_CMD, "%s '%s' &", fn, url ); + + Sys_StartProcess( cmdline, doexit ); + +} + +void Sys_ParseArgs( int argc, char* argv[] ) { + + if ( argc == 2 ) { + if ( ( !strcmp( argv[1], "--version" ) ) + || ( !strcmp( argv[1], "-v" ) ) ) { + Sys_PrintBinVersion( argv[0] ); + Sys_Exit( 0 ); + } + } +} + +#include "../client/client.h" +extern clientStatic_t cls; + +int main( int argc, char* argv[] ) { + // int oldtime, newtime; // bk001204 - unused + int len, i; + char *cmdline; + void Sys_SetDefaultCDPath( const char *path ); + + // go back to real user for config loads + saved_euid = geteuid(); + seteuid( getuid() ); + + Sys_ParseArgs( argc, argv ); // bk010104 - added this for support + + // TTimo: no CD path + Sys_SetDefaultCDPath( "" ); + + // merge the command line, this is kinda silly + for ( len = 1, i = 1; i < argc; i++ ) + len += strlen( argv[i] ) + 1; + cmdline = malloc( len ); + *cmdline = 0; + for ( i = 1; i < argc; i++ ) + { + if ( i > 1 ) { + strcat( cmdline, " " ); + } + strcat( cmdline, argv[i] ); + } + + // bk000306 - clear queues + memset( &eventQue[0], 0, MAX_QUED_EVENTS * sizeof( sysEvent_t ) ); + memset( &sys_packetReceived[0], 0, MAX_MSGLEN * sizeof( byte ) ); + + Com_Init( cmdline ); + NET_Init(); + + Sys_ConsoleInputInit(); + +// fcntl( 0, F_SETFL, fcntl( 0, F_GETFL, 0 ) | FNDELAY ); + + while ( 1 ) + { +#ifdef __linux__ + Sys_ConfigureFPU(); +#endif + Com_Frame(); + } +} diff --git a/Projects/Android/jni/rtcw/src/android/android_snd.c b/Projects/Android/jni/rtcw/src/android/android_snd.c new file mode 100644 index 0000000..0378ac5 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/android/android_snd.c @@ -0,0 +1,319 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== + */ + +#include +#include +#include +#include +#include +#include +//#include +#include +#ifdef __linux__ // rb0101023 - guard this +#include +#endif +#ifdef __FreeBSD__ // rb0101023 - added +#include +#endif +#include + +#include "../game/q_shared.h" +#include "../client/snd_local.h" + +//Updated by Emile Belanger for OpenSL + +// for native audio +#include +#include +#include + +pthread_mutex_t dma_mutex; + +// engine interfaces +static SLObjectItf engineObject = NULL; +static SLEngineItf engineEngine; + +// output mix interfaces +static SLObjectItf outputMixObject = NULL; + +// buffer queue player interfaces +static SLObjectItf bqPlayerObject = NULL; +static SLPlayItf bqPlayerPlay; +#ifdef ANDROID_NDK +static SLAndroidSimpleBufferQueueItf bqPlayerBufferQueue; +#else +static SLBufferQueueItf bqPlayerBufferQueue; +#endif + +static SLEffectSendItf bqPlayerEffectSend; +static SLMuteSoloItf bqPlayerMuteSolo; +static SLVolumeItf bqPlayerVolume; + +void myassert(int v,const char * message) +{ + if (!v) + Com_Printf("myassert: %s",message); +} + +int audio_fd; +int snd_inited = 0; + +cvar_t *sndbits; +cvar_t *sndspeed; +cvar_t *sndchannels; + +cvar_t *snddevice; + +/* Some devices may work only with 48000 */ +static int tryrates[] = { 22050, 11025, 44100, 48000, 8000 }; + +static int dmapos = 0; +static int dmasize = 0; + +#define OPENSL_BUFF_LEN 1024 + +static unsigned char play_buffer[OPENSL_BUFF_LEN]; + +void bqPause(int p) +{ + int result; + if (p) + { + result = (*bqPlayerPlay)->SetPlayState(bqPlayerPlay, SL_PLAYSTATE_PAUSED); + myassert(SL_RESULT_SUCCESS == result,"SetPlayState"); + } + else + { + result = (*bqPlayerPlay)->SetPlayState(bqPlayerPlay, SL_PLAYSTATE_PLAYING); + myassert(SL_RESULT_SUCCESS == result,"SetPlayState"); + + result = (*bqPlayerBufferQueue)->Enqueue(bqPlayerBufferQueue, "\0", 1); + myassert(SL_RESULT_SUCCESS == result,"Enqueue first buffer"); + } +} + +//NOTE!! There are definetly threading issues with this, but it appears to work for now... + +// TEST is me testing black screen issue! + +void bqPlayerCallback(SLAndroidSimpleBufferQueueItf bq, void *context) +{ + //LOGI("bqPlayerCallback"); + // TEST pthread_mutex_lock(&dma_mutex); + + int pos = (dmapos * (dma.samplebits/8)); + if (pos >= dmasize) + dmapos = pos = 0; + + int len = OPENSL_BUFF_LEN; + int factor = 2*2; + int FrameCount = (unsigned int)OPENSL_BUFF_LEN / factor; + + if (!snd_inited) /* shouldn't happen, but just in case... */ + { + memset(play_buffer, '\0', len); + return; + } + else + { + int tobufend = dmasize - pos; /* bytes to buffer's end. */ + int len1 = len; + int len2 = 0; + + if (len1 > tobufend) + { + len1 = tobufend; + len2 = len - len1; + } + memcpy(play_buffer, dma.buffer + pos, len1); + if (len2 <= 0) + dmapos += (len1 / (dma.samplebits/8)); + else /* wraparound? */ + { + memcpy(play_buffer+len1, dma.buffer, len2); + dmapos = (len2 / (dma.samplebits/8)); + } + } + + if (dmapos >= dmasize) + dmapos = 0; + + SLresult result; + //LOGI("Frame count = %d",FrameCount); + if (FrameCount == 0) + FrameCount = 1; + result = (*bqPlayerBufferQueue)->Enqueue(bqPlayerBufferQueue, play_buffer,FrameCount * factor); + myassert(SL_RESULT_SUCCESS == result,"Enqueue failed"); + + // TEST pthread_mutex_unlock(&dma_mutex); +} + +qboolean SNDDMA_Init( void ) { + int rc; + int fmt; + int tmp; + int i; + // char *s; // bk001204 - unused + struct audio_buf_info info; + int caps; + extern uid_t saved_euid; + + if ( snd_inited ) { + return 1; + } + + dmapos = 0; + dma.samplebits = 16; + dma.channels = 2; + dma.samples = 1024*16; + dma.submission_chunk = 1024*2; + //dma.submission_chunk = 1; + dma.speed = 44100; + dma.speed = 22050; + dmasize = (dma.samples * (dma.samplebits/8)); + dma.buffer = calloc(1, dmasize); + + SLresult result; + + // create engine + result = slCreateEngine(&engineObject, 0, NULL, 0, NULL, NULL); + myassert(SL_RESULT_SUCCESS == result,"slCreateEngine"); + + // realize the engine + result = (*engineObject)->Realize(engineObject, SL_BOOLEAN_FALSE); + myassert(SL_RESULT_SUCCESS == result,"Realize"); + + // get the engine interface, which is needed in order to create other objects + result = (*engineObject)->GetInterface(engineObject, SL_IID_ENGINE, &engineEngine); + myassert(SL_RESULT_SUCCESS == result,"GetInterface"); + + // create output mix + result = (*engineEngine)->CreateOutputMix(engineEngine, &outputMixObject, 0, NULL, NULL); + myassert(SL_RESULT_SUCCESS == result,"CreateOutputMix"); + + // realize the output mix + result = (*outputMixObject)->Realize(outputMixObject, SL_BOOLEAN_FALSE); + myassert(SL_RESULT_SUCCESS == result,"Realize output mix"); + + //CREATE THE PLAYER + + // configure audio source + SLDataLocator_AndroidSimpleBufferQueue loc_bufq = {SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE, 1}; + SLDataFormat_PCM format_pcm = {SL_DATAFORMAT_PCM, 2, SL_SAMPLINGRATE_22_05, + SL_PCMSAMPLEFORMAT_FIXED_16, SL_PCMSAMPLEFORMAT_FIXED_16, + SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT, SL_BYTEORDER_LITTLEENDIAN}; + SLDataSource audioSrc = {&loc_bufq, &format_pcm}; + + // configure audio sink + SLDataLocator_OutputMix loc_outmix = {SL_DATALOCATOR_OUTPUTMIX, outputMixObject}; + SLDataSink audioSnk = {&loc_outmix, NULL}; + + // create audio player + Com_Printf("create audio player"); + const SLInterfaceID ids[1] = {SL_IID_ANDROIDSIMPLEBUFFERQUEUE}; + const SLboolean req[1] = {SL_BOOLEAN_TRUE}; + result = (*engineEngine)->CreateAudioPlayer(engineEngine, &bqPlayerObject, &audioSrc, &audioSnk, + 1, ids, req); + myassert(SL_RESULT_SUCCESS == result,"CreateAudioPlayer"); + + + // realize the player + result = (*bqPlayerObject)->Realize(bqPlayerObject, SL_BOOLEAN_FALSE); + myassert(SL_RESULT_SUCCESS == result,"Realize AudioPlayer"); + + // get the play interface + result = (*bqPlayerObject)->GetInterface(bqPlayerObject, SL_IID_PLAY, &bqPlayerPlay); + myassert(SL_RESULT_SUCCESS == result,"GetInterface AudioPlayer"); + + // get the buffer queue interface + result = (*bqPlayerObject)->GetInterface(bqPlayerObject, SL_IID_BUFFERQUEUE, + &bqPlayerBufferQueue); + myassert(SL_RESULT_SUCCESS == result,"GetInterface buffer queue"); + + // register callback on the buffer queue + result = (*bqPlayerBufferQueue)->RegisterCallback(bqPlayerBufferQueue, bqPlayerCallback, NULL); + myassert(SL_RESULT_SUCCESS == result,"RegisterCallback"); + + snd_inited = 1; + + // set the player's state to playing + result = (*bqPlayerPlay)->SetPlayState(bqPlayerPlay, SL_PLAYSTATE_PLAYING); + myassert(SL_RESULT_SUCCESS == result,"SetPlayState"); + + + + result = (*bqPlayerBufferQueue)->Enqueue(bqPlayerBufferQueue, "\0", 1); + myassert(SL_RESULT_SUCCESS == result,"Enqueue first buffer"); + + + + + return 1; +} + +int SNDDMA_GetDMAPos( void ) { + struct count_info count; + + if ( !snd_inited ) { + return 0; + } + + // TEST pthread_mutex_lock(&dma_mutex); + + //LOGI("SNDDMA_GetDMAPos"); + return dmapos; +} + +void SNDDMA_Shutdown( void ) { + LOGI("shutdown Sound"); + bqPause(1); + (*bqPlayerObject)->Destroy(bqPlayerObject); + (*outputMixObject)->Destroy(outputMixObject); + (*engineObject)->Destroy(engineObject); + + bqPlayerObject = NULL; + outputMixObject = NULL; + engineObject = NULL; +} + +/* +============== +SNDDMA_Submit + +Send sound to device if buffer isn't really the dma buffer +=============== + */ +void SNDDMA_Submit( void ) { + //LOGI("SNDDMA_Submit"); + // TEST pthread_mutex_unlock(&dma_mutex); +} + +void SNDDMA_BeginPainting( void ) { + //LOGI("SNDDMA_BeginPainting"); + //pthread_mutex_lock(&dma_mutex); +} diff --git a/Projects/Android/jni/rtcw/src/android/in_android.c b/Projects/Android/jni/rtcw/src/android/in_android.c new file mode 100644 index 0000000..96ef515 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/android/in_android.c @@ -0,0 +1,461 @@ + +#include "in_android.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "src/client/client.h" + + +#include +#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO,"JNI", __VA_ARGS__)) +#define LOGW(...) ((void)__android_log_print(ANDROID_LOG_WARN, "JNI", __VA_ARGS__)) +#define LOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR,"JNI", __VA_ARGS__)) + + + +// FIFO STUFF //////////////////// +// Copied from FTEQW, I don't know if this is thread safe, but it's safe enough for a game :) +#define EVENTQUEUELENGTH 128 +struct eventlist_s +{ + + int scancode, unicode,state; + +} eventlist[EVENTQUEUELENGTH]; + +volatile int events_avail; /*volatile to make sure the cc doesn't try leaving these cached in a register*/ +volatile int events_used; + +static struct eventlist_s *in_newevent(void) +{ + if (events_avail >= events_used + EVENTQUEUELENGTH) + return 0; + return &eventlist[events_avail & (EVENTQUEUELENGTH-1)]; +} + +static void in_finishevent(void) +{ + events_avail++; +} +/////////////////////// + + + +int PortableKeyEvent(int state, int code, int unicode){ + + LOGI("PortableKeyEvent state = %d, code = %d, unicode = %d",state,code,unicode); + struct eventlist_s *ev = in_newevent(); + if (!ev) + return 0; + + ev->scancode = code; + ev->unicode = unicode; + ev->state = state; + in_finishevent(); + return 0; + +} + + +//extern void KeyDownPort( kbutton_t *b ); +//extern void KeyUpPort( kbutton_t *b ); +extern kbutton_t kb[NUM_BUTTONS]; + +void KeyUpPort (int b) +{ + kb[b].active = qfalse; +} +void KeyDownPort (int b) +{ + kb[b].active = qtrue; + kb[b].wasPressed = qtrue; +} + +void KeyTogglePort (int b) +{ + kb[b].active = !kb[b].active; +} + +char* postedCommand = 0; +void postCommand(const char * cmd) +{ + postedCommand = cmd; +} +/* +extern kbutton_t in_left, in_right, in_forward, in_back; +extern kbutton_t in_lookup, in_lookdown, in_moveleft, in_moveright; +extern kbutton_t in_strafe, in_speed; +extern kbutton_t in_up, in_down; +extern kbutton_t in_buttons[16]; + */ + +void PortableAction(int state, int action) +{ + LOGI("PortableAction %d %d",state,action); + + int key = -1; + + switch (action) + { + case PORT_ACT_LEFT: + key = KB_LEFT; + break; + case PORT_ACT_RIGHT: + key = KB_RIGHT; + break; + case PORT_ACT_FWD: + key = KB_FORWARD; + break; + case PORT_ACT_BACK: + key = KB_BACK; + break; + case PORT_ACT_LOOK_UP: + key = KB_LOOKUP; + break; + case PORT_ACT_LOOK_DOWN: + key = KB_LOOKDOWN; + break; + case PORT_ACT_MOVE_LEFT: + key = KB_MOVELEFT; + break; + case PORT_ACT_MOVE_RIGHT: + key = KB_MOVERIGHT; + break; + case PORT_ACT_STRAFE: + key = KB_STRAFE; + break; + case PORT_ACT_SPEED: + key = KB_SPEED; + break; + case PORT_ACT_USE: + key = KB_BUTTONS6; + break; + case PORT_ACT_ATTACK: + key = KB_BUTTONS0; + break; + case PORT_ACT_JUMP: + //Jump is same as up + case PORT_ACT_UP: + key = KB_UP; + break; + case PORT_ACT_DOWN: + if (state) //TOGGLE + KeyTogglePort(KB_DOWN); + break; + case PORT_ACT_KICK: + key = KB_KICK; + break; + //TODO make fifo, possibly not thread safe!! + case PORT_ACT_NEXT_WEP: + if (state) + postCommand("weapnext\n"); + break; + case PORT_ACT_PREV_WEP: + if (state) + postCommand("weapprev\n"); + break; + case PORT_ACT_ZOOM_IN: + key = KB_WBUTTONS1; + break; + case PORT_ACT_ALT_FIRE: + if (state) + postCommand("weapalt\n"); + break; + case PORT_ACT_HELPCOMP: + if (state) + postCommand("notebook\n"); + break; + case PORT_ACT_INVUSE: + key = KB_BUTTONS2; + break; + case PORT_ACT_INVPREV: + if (state) + postCommand("itemprev\n"); + break; + case PORT_ACT_INVNEXT: + if (state) + postCommand("itemnext\n"); + break; + case PORT_ACT_RELOAD: + key = KB_WBUTTONS3; + break; + case PORT_ACT_QUICKSAVE: + if (state) + postCommand("savegame quicksave\n"); + break; + case PORT_ACT_QUICKLOAD: + if (state) + postCommand("loadgame quicksave\n"); + break; + case PORT_ACT_LEAN_LEFT: + key = KB_WBUTTONS4; + break; + case PORT_ACT_LEAN_RIGHT: + key = KB_WBUTTONS5; + break; + } + + if (key != -1) + (state)?KeyDownPort(key):KeyUpPort(key); + +} + +int mdx=0,mdy=0; +void PortableMouse(float dx,float dy) +{ + //LOGI("dx = %f, dy = %f",dx,dy); + dx *= 1500; + dy *= 1200; + + mdx += dx; + mdy += dy; + + + //Sys_QueEvent( t, SE_MOUSE, mx, my, 0, NULL ); +} + +int absx=0,absy=0; +void PortableMouseAbs(float x,float y) +{ + absx = x; + absy = y; +} + + +// =================== FORWARD and SIDE MOVMENT ============== + +float forwardmove, sidemove; //Joystick mode + +void PortableMoveFwd(float fwd) +{ + if (fwd > 1) + fwd = 1; + else if (fwd < -1) + fwd = -1; + + forwardmove = fwd; +} + +void PortableMoveSide(float strafe) +{ + if (strafe > 1) + strafe = 1; + else if (strafe < -1) + strafe = -1; + + sidemove = strafe; +} + +void PortableMove(float fwd, float strafe) +{ + PortableMoveFwd(fwd); + PortableMoveSide(strafe); +} + +//====================================================================== + +//Look up and down +int look_pitch_mode; +float look_pitch_mouse,look_pitch_abs,look_pitch_joy; +void PortableLookPitch(int mode, float pitch) +{ + look_pitch_mode = mode; + switch(mode) + { + case LOOK_MODE_MOUSE: + look_pitch_mouse += pitch; + break; + case LOOK_MODE_ABSOLUTE: + look_pitch_abs = pitch; + break; + case LOOK_MODE_JOYSTICK: + look_pitch_joy = pitch; + break; + } +} + +//left right +int look_yaw_mode; +float look_yaw_mouse,look_yaw_joy; +void PortableLookYaw(int mode, float yaw) +{ + look_yaw_mode = mode; + switch(mode) + { + case LOOK_MODE_MOUSE: + look_yaw_mouse += yaw; + break; + case LOOK_MODE_JOYSTICK: + look_yaw_joy = yaw; + break; + } +} + + + +void PortableCommand(const char * cmd){ + postCommand(cmd); +} + +void PortableInit(int argc,const char ** argv){ + //Copied form sys_main.c + int len, i; + char *cmdline; + void Sys_SetDefaultCDPath( const char *path ); + + // go back to real user for config loads + + + Sys_ParseArgs( argc, argv ); // bk010104 - added this for support + + // TTimo: no CD path + Sys_SetDefaultCDPath( "" ); + + // merge the command line, this is kinda silly + for ( len = 1, i = 1; i < argc; i++ ) + len += strlen( argv[i] ) + 1; + cmdline = malloc( len ); + *cmdline = 0; + for ( i = 1; i < argc; i++ ) + { + if ( i > 1 ) { + strcat( cmdline, " " ); + } + strcat( cmdline, argv[i] ); + } + + // bk000306 - clear queues + //memset( &eventQue[0], 0, MAX_QUED_EVENTS * sizeof( sysEvent_t ) ); + //memset( &sys_packetReceived[0], 0, MAX_MSGLEN * sizeof( byte ) ); + + Com_Init( cmdline ); + NET_Init(); + + Sys_ConsoleInputInit(); + + +} + +void pumpEvents(void) +{ + struct eventlist_s *ev; + + if (events_used != events_avail) + { + ev = &eventlist[events_used & (EVENTQUEUELENGTH-1)]; + + LOGI("Queue event"); + Sys_QueEvent( 0, SE_KEY, ev->scancode, ev->state?qtrue:qfalse, 0, NULL ); + + if( ev->unicode && ev->state) + Sys_QueEvent( 0, SE_CHAR,ev->unicode, 0, 0, NULL ); + + events_used++; + } + + //Ok so can not issue commands more than 60 times/sec, who cares! + if (postedCommand) + { + Cmd_ExecuteString(postedCommand); + postedCommand = 0; + } + + + if (mdx || mdy) + Sys_QueEvent( 0, SE_MOUSE, -mdx, -mdy, 0, NULL ); + mdx=mdy=0; + + + if ( Key_GetCatcher( ) & KEYCATCH_UI ) { + if (absx || absy) + VM_Call( uivm, UI_MOUSE_EVENT_ABS, absx, absy ); + absx = 0; + absy = 0; + } + +} + +void CL_AndroidMove( usercmd_t *cmd ) +{ + + //cmd->forwardmove += forwardmove * cl_forwardspeed->value * 2; //Always run! (x2) + //cmd->rightmove += sidemove * cl_sidespeed->value * 2; + cmd->forwardmove = ClampChar(cmd->forwardmove + forwardmove * 127 ); + cmd->rightmove = ClampChar(cmd->rightmove + sidemove * 127 ); + + switch(look_pitch_mode) + { + case LOOK_MODE_MOUSE: + cl.viewangles[PITCH] += look_pitch_mouse * 300; + look_pitch_mouse = 0; + break; + case LOOK_MODE_ABSOLUTE: + cl.viewangles[PITCH] = look_pitch_abs * 80; + break; + case LOOK_MODE_JOYSTICK: + cl.viewangles[PITCH] += look_pitch_joy * 6; + break; + } + + + switch(look_yaw_mode) + { + case LOOK_MODE_MOUSE: + cl.viewangles[YAW] += look_yaw_mouse * 300; + look_yaw_mouse = 0; + break; + case LOOK_MODE_JOYSTICK: + cl.viewangles[YAW] += look_yaw_joy * 6; + break; + } + +} + + +void IN_Frame( void ) { + pumpEvents(); +} + +pthread_t thread1; +int thread_has_run = 0; +extern void launchSSetup(); +void PortableFrame(void){ + + // qglBindTexture (GL_TEXTURE_2D, glState.currenttextures[glState.currenttmu]); + //LOGI("PortableFrame"); + + + //pumpEvents(); + //IN_Frame( ); + Com_Frame( ); +} + +int PortableInMenu(void){ + + if ((Key_GetCatcher( ) & KEYCATCH_UI) || + (Key_GetCatcher( ) & KEYCATCH_CGAME) ) + return 1; + else + return 0; +} + +int PortableInAutomap(void) +{ + return 0; +} + +int PortableShowKeyboard(void){ + + return 0; +} + diff --git a/Projects/Android/jni/rtcw/src/android/in_android.h b/Projects/Android/jni/rtcw/src/android/in_android.h new file mode 100644 index 0000000..7884ebc --- /dev/null +++ b/Projects/Android/jni/rtcw/src/android/in_android.h @@ -0,0 +1,33 @@ +#include "beloko_common/port_act_defs.h" + + + +#ifdef __cplusplus +extern "C" +{ +#endif +int PortableKeyEvent(int state, int code ,int unitcode); +void PortableAction(int state, int action); + +void PortableMove(float fwd, float strafe); +void PortableMoveFwd(float fwd); +void PortableMoveSide(float strafe); +void PortableLookPitch(int mode, float pitch); +void PortableLookYaw(int mode, float pitch); +void PortableCommand(const char * cmd); + +void PortableMouse(float dx,float dy); + +void PortableMouseAbs(float x,float y); + +void PortableInit(int argc,const char ** argv); +void PortableFrame(void); + +int PortableInMenu(void); +int PortableShowKeyboard(void); +int PortableInAutomap(void); + + +#ifdef __cplusplus +} +#endif diff --git a/Projects/Android/jni/rtcw/src/botai/ai_chat.c b/Projects/Android/jni/rtcw/src/botai/ai_chat.c new file mode 100644 index 0000000..58d313e --- /dev/null +++ b/Projects/Android/jni/rtcw/src/botai/ai_chat.c @@ -0,0 +1,1313 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +/***************************************************************************** + * name: ai_chat.c + * + * desc: Quake3 bot AI + * + * + *****************************************************************************/ + +#include "../game/g_local.h" +#include "../game/botlib.h" +#include "../game/be_aas.h" +#include "../game/be_ea.h" +#include "../game/be_ai_char.h" +#include "../game/be_ai_chat.h" +#include "../game/be_ai_gen.h" +#include "../game/be_ai_goal.h" +#include "../game/be_ai_move.h" +#include "../game/be_ai_weap.h" +#include "../botai/botai.h" +// +#include "ai_main.h" +#include "ai_dmq3.h" +#include "ai_chat.h" +#include "ai_cmd.h" +#include "ai_dmnet.h" +// +#include "chars.h" //characteristics +#include "inv.h" //indexes into the inventory +#include "syn.h" //synonyms +#include "match.h" //string matching types and vars + + +/* +================== +BotNumActivePlayers +================== +*/ +int BotNumActivePlayers( void ) { + int i, num; + char buf[MAX_INFO_STRING]; + static int maxclients; + + if ( !maxclients ) { + maxclients = trap_Cvar_VariableIntegerValue( "sv_maxclients" ); + } + + num = 0; + for ( i = 0; i < maxclients && i < MAX_CLIENTS; i++ ) { + trap_GetConfigstring( CS_PLAYERS + i, buf, sizeof( buf ) ); + //if no config string or no name + if ( !strlen( buf ) || !strlen( Info_ValueForKey( buf, "n" ) ) ) { + continue; + } + //skip spectators + if ( atoi( Info_ValueForKey( buf, "t" ) ) == TEAM_SPECTATOR ) { + continue; + } + // + num++; + } + return num; +} + +/* +================== +BotIsFirstInRankings +================== +*/ +int BotIsFirstInRankings( bot_state_t *bs ) { + int i, score; + char buf[MAX_INFO_STRING]; + static int maxclients; + playerState_t ps; + + if ( !maxclients ) { + maxclients = trap_Cvar_VariableIntegerValue( "sv_maxclients" ); + } + + score = bs->cur_ps.persistant[PERS_SCORE]; + for ( i = 0; i < maxclients && i < MAX_CLIENTS; i++ ) { + trap_GetConfigstring( CS_PLAYERS + i, buf, sizeof( buf ) ); + //if no config string or no name + if ( !strlen( buf ) || !strlen( Info_ValueForKey( buf, "n" ) ) ) { + continue; + } + //skip spectators + if ( atoi( Info_ValueForKey( buf, "t" ) ) == TEAM_SPECTATOR ) { + continue; + } + // + BotAI_GetClientState( i, &ps ); + if ( score < ps.persistant[PERS_SCORE] ) { + return qfalse; + } + } + return qtrue; +} + +/* +================== +BotIsLastInRankings +================== +*/ +int BotIsLastInRankings( bot_state_t *bs ) { + int i, score; + char buf[MAX_INFO_STRING]; + static int maxclients; + playerState_t ps; + + if ( !maxclients ) { + maxclients = trap_Cvar_VariableIntegerValue( "sv_maxclients" ); + } + + score = bs->cur_ps.persistant[PERS_SCORE]; + for ( i = 0; i < maxclients && i < MAX_CLIENTS; i++ ) { + trap_GetConfigstring( CS_PLAYERS + i, buf, sizeof( buf ) ); + //if no config string or no name + if ( !strlen( buf ) || !strlen( Info_ValueForKey( buf, "n" ) ) ) { + continue; + } + //skip spectators + if ( atoi( Info_ValueForKey( buf, "t" ) ) == TEAM_SPECTATOR ) { + continue; + } + // + BotAI_GetClientState( i, &ps ); + if ( score > ps.persistant[PERS_SCORE] ) { + return qfalse; + } + } + return qtrue; +} + +/* +================== +BotFirstClientInRankings +================== +*/ +char *BotFirstClientInRankings( void ) { + int i, bestscore, bestclient; + char buf[MAX_INFO_STRING]; + static char name[32]; + static int maxclients; + playerState_t ps; + + if ( !maxclients ) { + maxclients = trap_Cvar_VariableIntegerValue( "sv_maxclients" ); + } + + bestscore = -999999; + bestclient = 0; + for ( i = 0; i < maxclients && i < MAX_CLIENTS; i++ ) { + trap_GetConfigstring( CS_PLAYERS + i, buf, sizeof( buf ) ); + //if no config string or no name + if ( !strlen( buf ) || !strlen( Info_ValueForKey( buf, "n" ) ) ) { + continue; + } + //skip spectators + if ( atoi( Info_ValueForKey( buf, "t" ) ) == TEAM_SPECTATOR ) { + continue; + } + // + BotAI_GetClientState( i, &ps ); + if ( ps.persistant[PERS_SCORE] > bestscore ) { + bestscore = ps.persistant[PERS_SCORE]; + bestclient = i; + } + } + EasyClientName( bestclient, name, 32 ); + return name; +} + +/* +================== +BotLastClientInRankings +================== +*/ +char *BotLastClientInRankings( void ) { + int i, worstscore, bestclient; + char buf[MAX_INFO_STRING]; + static char name[32]; + static int maxclients; + playerState_t ps; + + if ( !maxclients ) { + maxclients = trap_Cvar_VariableIntegerValue( "sv_maxclients" ); + } + + worstscore = 999999; + bestclient = 0; + for ( i = 0; i < maxclients && i < MAX_CLIENTS; i++ ) { + trap_GetConfigstring( CS_PLAYERS + i, buf, sizeof( buf ) ); + //if no config string or no name + if ( !strlen( buf ) || !strlen( Info_ValueForKey( buf, "n" ) ) ) { + continue; + } + //skip spectators + if ( atoi( Info_ValueForKey( buf, "t" ) ) == TEAM_SPECTATOR ) { + continue; + } + // + BotAI_GetClientState( i, &ps ); + if ( ps.persistant[PERS_SCORE] < worstscore ) { + worstscore = ps.persistant[PERS_SCORE]; + bestclient = i; + } + } + EasyClientName( bestclient, name, 32 ); + return name; +} + +/* +================== +BotRandomOpponentName +================== +*/ +char *BotRandomOpponentName( bot_state_t *bs ) { + int i, count; + char buf[MAX_INFO_STRING]; + int opponents[MAX_CLIENTS], numopponents; + static int maxclients; + static char name[32]; + + if ( !maxclients ) { + maxclients = trap_Cvar_VariableIntegerValue( "sv_maxclients" ); + } + + numopponents = 0; + opponents[0] = 0; + for ( i = 0; i < maxclients && i < MAX_CLIENTS; i++ ) { + if ( i == bs->client ) { + continue; + } + // + trap_GetConfigstring( CS_PLAYERS + i, buf, sizeof( buf ) ); + //if no config string or no name + if ( !strlen( buf ) || !strlen( Info_ValueForKey( buf, "n" ) ) ) { + continue; + } + //skip spectators + if ( atoi( Info_ValueForKey( buf, "t" ) ) == TEAM_SPECTATOR ) { + continue; + } + //skip team mates + if ( BotSameTeam( bs, i ) ) { + continue; + } + // + opponents[numopponents] = i; + numopponents++; + } + count = random() * numopponents; + for ( i = 0; i < numopponents; i++ ) { + count--; + if ( count <= 0 ) { + EasyClientName( opponents[i], name, sizeof( name ) ); + return name; + } + } + EasyClientName( opponents[0], name, sizeof( name ) ); + return name; +} + +/* +================== +BotMapTitle +================== +*/ + +char *BotMapTitle( void ) { + char info[1024]; + static char mapname[128]; + + trap_GetServerinfo( info, sizeof( info ) ); + + strncpy( mapname, Info_ValueForKey( info, "mapname" ), sizeof( mapname ) - 1 ); + mapname[sizeof( mapname ) - 1] = '\0'; + + return mapname; +} + + +/* +================== +BotWeaponNameForMeansOfDeath +================== +*/ + +char *BotWeaponNameForMeansOfDeath( int mod ) { + switch ( mod ) { + case MOD_SHOTGUN: return "Shotgun"; + case MOD_GAUNTLET: return "Gauntlet"; + case MOD_MACHINEGUN: return "Machinegun"; + case MOD_GRENADE: + case MOD_GRENADE_SPLASH: return "Grenade Launcher"; + case MOD_ROCKET: + case MOD_ROCKET_SPLASH: return "Rocket Launcher"; + case MOD_RAILGUN: return "Railgun"; + case MOD_LIGHTNING: return "Lightning Gun"; + case MOD_BFG: + case MOD_BFG_SPLASH: return "BFG10K"; + case MOD_GRAPPLE: return "Grapple"; + default: return "[unknown weapon]"; + } +} + +/* +================== +BotRandomWeaponName +================== +*/ +char *BotRandomWeaponName( void ) { + int rnd; + + rnd = random() * 8.9; + switch ( rnd ) { + case 0: return "Gauntlet"; + case 1: return "Shotgun"; + case 2: return "Machinegun"; + case 3: return "Grenade Launcher"; + case 4: return "Rocket Launcher"; + case 5: return "Plasmagun"; + case 6: return "Railgun"; + case 7: return "Lightning Gun"; + default: return "BFG10K"; + } +} + +/* +================== +BotValidChatPosition +================== +*/ +int BotValidChatPosition( bot_state_t *bs ) { + vec3_t point, start, end, mins, maxs; + bsp_trace_t trace; + + //if the bot is dead all positions are valid + if ( BotIsDead( bs ) ) { + return qtrue; + } + //must be on the ground + //if (bs->cur_ps.groundEntityNum != ENTITYNUM_NONE) return qfalse; + //do not chat if in lava or slime + VectorCopy( bs->origin, point ); + point[2] -= 24; + if ( trap_PointContents( point,bs->entitynum ) & ( CONTENTS_LAVA | CONTENTS_SLIME ) ) { + return qfalse; + } + //do not chat if under water + VectorCopy( bs->origin, point ); + point[2] += 32; + if ( trap_PointContents( point,bs->entitynum ) & MASK_WATER ) { + return qfalse; + } + //must be standing on the world entity + VectorCopy( bs->origin, start ); + VectorCopy( bs->origin, end ); + start[2] += 1; + end[2] -= 10; + trap_AAS_PresenceTypeBoundingBox( PRESENCE_CROUCH, mins, maxs ); + BotAI_Trace( &trace, start, mins, maxs, end, bs->client, MASK_SOLID ); + if ( trace.ent != ENTITYNUM_WORLD ) { + return qfalse; + } + //the bot is in a position where it can chat + return qtrue; +} + +/* +================== +BotChat_EnterGame +================== +*/ +int BotChat_EnterGame( bot_state_t *bs ) { + char name[32]; + float rnd; + + if ( bot_nochat.integer ) { + return qfalse; + } + if ( bs->lastchat_time > trap_AAS_Time() - 3 ) { + return qfalse; + } + //don't chat in teamplay + if ( TeamPlayIsOn() ) { + return qfalse; + } + rnd = trap_Characteristic_BFloat( bs->character, CHARACTERISTIC_CHAT_ENTEREXITGAME, 0, 1 ); + if ( !bot_fastchat.integer ) { + if ( random() > rnd ) { + return qfalse; + } + } + if ( BotNumActivePlayers() <= 1 ) { + return qfalse; + } + if ( !BotValidChatPosition( bs ) ) { + return qfalse; + } + BotAI_BotInitialChat( bs, "game_enter", + EasyClientName( bs->client, name, 32 ), // 0 + BotRandomOpponentName( bs ), // 1 + "[invalid var]", // 2 + "[invalid var]", // 3 + BotMapTitle(), // 4 + NULL ); + bs->lastchat_time = trap_AAS_Time(); + bs->chatto = CHAT_ALL; + return qtrue; +} + +/* +================== +BotChat_ExitGame +================== +*/ +int BotChat_ExitGame( bot_state_t *bs ) { + char name[32]; + float rnd; + + if ( bot_nochat.integer ) { + return qfalse; + } + if ( bs->lastchat_time > trap_AAS_Time() - 3 ) { + return qfalse; + } + //don't chat in teamplay + if ( TeamPlayIsOn() ) { + return qfalse; + } + rnd = trap_Characteristic_BFloat( bs->character, CHARACTERISTIC_CHAT_ENTEREXITGAME, 0, 1 ); + if ( !bot_fastchat.integer ) { + if ( random() > rnd ) { + return qfalse; + } + } + if ( BotNumActivePlayers() <= 1 ) { + return qfalse; + } + // + BotAI_BotInitialChat( bs, "game_exit", + EasyClientName( bs->client, name, 32 ), // 0 + BotRandomOpponentName( bs ), // 1 + "[invalid var]", // 2 + "[invalid var]", // 3 + BotMapTitle(), // 4 + NULL ); + bs->lastchat_time = trap_AAS_Time(); + bs->chatto = CHAT_ALL; + return qtrue; +} + +/* +================== +BotChat_StartLevel +================== +*/ +int BotChat_StartLevel( bot_state_t *bs ) { + char name[32]; + float rnd; + + if ( bot_nochat.integer ) { + return qfalse; + } + if ( BotIsObserver( bs ) ) { + return qfalse; + } + if ( bs->lastchat_time > trap_AAS_Time() - 3 ) { + return qfalse; + } + //don't chat in teamplay + if ( TeamPlayIsOn() ) { + return qfalse; + } + rnd = trap_Characteristic_BFloat( bs->character, CHARACTERISTIC_CHAT_STARTENDLEVEL, 0, 1 ); + if ( !bot_fastchat.integer ) { + if ( random() > rnd ) { + return qfalse; + } + } + if ( BotNumActivePlayers() <= 1 ) { + return qfalse; + } + BotAI_BotInitialChat( bs, "level_start", + EasyClientName( bs->client, name, 32 ), // 0 + NULL ); + bs->lastchat_time = trap_AAS_Time(); + bs->chatto = CHAT_ALL; + return qtrue; +} + +/* +================== +BotChat_EndLevel +================== +*/ +int BotChat_EndLevel( bot_state_t *bs ) { + char name[32]; + float rnd; + + if ( bot_nochat.integer ) { + return qfalse; + } + if ( BotIsObserver( bs ) ) { + return qfalse; + } + if ( bs->lastchat_time > trap_AAS_Time() - 3 ) { + return qfalse; + } + //don't chat in teamplay + if ( TeamPlayIsOn() ) { + return qfalse; + } + rnd = trap_Characteristic_BFloat( bs->character, CHARACTERISTIC_CHAT_STARTENDLEVEL, 0, 1 ); + if ( !bot_fastchat.integer ) { + if ( random() > rnd ) { + return qfalse; + } + } + if ( BotNumActivePlayers() <= 1 ) { + return qfalse; + } + // + if ( BotIsFirstInRankings( bs ) ) { + BotAI_BotInitialChat( bs, "level_end_victory", + EasyClientName( bs->client, name, 32 ), // 0 + BotRandomOpponentName( bs ), // 1 + "[invalid var]", // 2 + BotLastClientInRankings(), // 3 + BotMapTitle(), // 4 + NULL ); + } else if ( BotIsLastInRankings( bs ) ) { + BotAI_BotInitialChat( bs, "level_end_lose", + EasyClientName( bs->client, name, 32 ), // 0 + BotRandomOpponentName( bs ), // 1 + BotFirstClientInRankings(), // 2 + "[invalid var]", // 3 + BotMapTitle(), // 4 + NULL ); + } else { + BotAI_BotInitialChat( bs, "level_end", + EasyClientName( bs->client, name, 32 ), // 0 + BotRandomOpponentName( bs ), // 1 + BotFirstClientInRankings(), // 2 + BotLastClientInRankings(), // 3 + BotMapTitle(), // 4 + NULL ); + } + bs->lastchat_time = trap_AAS_Time(); + bs->chatto = CHAT_ALL; + return qtrue; +} + +/* +================== +BotChat_Death +================== +*/ +int BotChat_Death( bot_state_t *bs ) { + char name[32]; + float rnd; + + if ( bot_nochat.integer ) { + return qfalse; + } + if ( bs->lastchat_time > trap_AAS_Time() - 3 ) { + return qfalse; + } + rnd = trap_Characteristic_BFloat( bs->character, CHARACTERISTIC_CHAT_DEATH, 0, 1 ); + //if fast chatting is off + if ( !bot_fastchat.integer ) { + if ( random() > rnd ) { + return qfalse; + } + } + if ( BotNumActivePlayers() <= 1 ) { + return qfalse; + } + // + if ( bs->lastkilledby >= 0 && bs->lastkilledby < MAX_CLIENTS ) { + EasyClientName( bs->lastkilledby, name, 32 ); + } else { + strcpy( name, "[world]" ); + } + // + if ( TeamPlayIsOn() && BotSameTeam( bs, bs->lastkilledby ) ) { + if ( bs->lastkilledby == bs->client ) { + return qfalse; + } + BotAI_BotInitialChat( bs, "death_teammate", name, NULL ); + bs->chatto = CHAT_TEAM; + } else + { + //don't chat in teamplay + if ( TeamPlayIsOn() ) { + return qfalse; + } + // + if ( bs->botdeathtype == MOD_WATER ) { + BotAI_BotInitialChat( bs, "death_drown", BotRandomOpponentName( bs ), NULL ); + } else if ( bs->botdeathtype == MOD_SLIME ) { + BotAI_BotInitialChat( bs, "death_slime", BotRandomOpponentName( bs ), NULL ); + } else if ( bs->botdeathtype == MOD_LAVA ) { + BotAI_BotInitialChat( bs, "death_lava", BotRandomOpponentName( bs ), NULL ); + } else if ( bs->botdeathtype == MOD_FALLING ) { + BotAI_BotInitialChat( bs, "death_cratered", BotRandomOpponentName( bs ), NULL ); + } else if ( bs->botsuicide || //all other suicides by own weapon + bs->botdeathtype == MOD_CRUSH || + bs->botdeathtype == MOD_SUICIDE || + bs->botdeathtype == MOD_TARGET_LASER || + bs->botdeathtype == MOD_TRIGGER_HURT || + bs->botdeathtype == MOD_UNKNOWN ) { + BotAI_BotInitialChat( bs, "death_suicide", BotRandomOpponentName( bs ), NULL ); + } else if ( bs->botdeathtype == MOD_TELEFRAG ) { + BotAI_BotInitialChat( bs, "death_telefrag", name, NULL ); + } else { + if ( ( bs->botdeathtype == MOD_GAUNTLET || + bs->botdeathtype == MOD_RAILGUN || + bs->botdeathtype == MOD_BFG || + bs->botdeathtype == MOD_BFG_SPLASH ) && random() < 0.5 ) { + + if ( bs->botdeathtype == MOD_GAUNTLET ) { + BotAI_BotInitialChat( bs, "death_gauntlet", + name, // 0 + BotWeaponNameForMeansOfDeath( bs->botdeathtype ), // 1 + NULL ); + } else if ( bs->botdeathtype == MOD_RAILGUN ) { + BotAI_BotInitialChat( bs, "death_rail", + name, // 0 + BotWeaponNameForMeansOfDeath( bs->botdeathtype ), // 1 + NULL ); + } else { + BotAI_BotInitialChat( bs, "death_bfg", + name, // 0 + BotWeaponNameForMeansOfDeath( bs->botdeathtype ), // 1 + NULL ); + } + } + //choose between insult and praise + else if ( random() < trap_Characteristic_BFloat( bs->character, CHARACTERISTIC_CHAT_INSULT, 0, 1 ) ) { + BotAI_BotInitialChat( bs, "death_insult", + name, // 0 + BotWeaponNameForMeansOfDeath( bs->botdeathtype ), // 1 + NULL ); + } else { + BotAI_BotInitialChat( bs, "death_praise", + name, // 0 + BotWeaponNameForMeansOfDeath( bs->botdeathtype ), // 1 + NULL ); + } + } + bs->chatto = CHAT_ALL; + } + bs->lastchat_time = trap_AAS_Time(); + return qtrue; +} + +/* +================== +BotChat_Kill +================== +*/ +int BotChat_Kill( bot_state_t *bs ) { + char name[32]; + float rnd; + + if ( bot_nochat.integer ) { + return qfalse; + } + if ( bs->lastchat_time > trap_AAS_Time() - 3 ) { + return qfalse; + } + rnd = trap_Characteristic_BFloat( bs->character, CHARACTERISTIC_CHAT_KILL, 0, 1 ); + //if fast chat is off + if ( !bot_fastchat.integer ) { + if ( random() > rnd ) { + return qfalse; + } + } + if ( bs->lastkilledplayer == bs->client ) { + return qfalse; + } + if ( BotNumActivePlayers() <= 1 ) { + return qfalse; + } + if ( !BotValidChatPosition( bs ) ) { + return qfalse; + } + // + EasyClientName( bs->lastkilledplayer, name, 32 ); + // + bs->chatto = CHAT_ALL; + if ( TeamPlayIsOn() && BotSameTeam( bs, bs->lastkilledplayer ) ) { + BotAI_BotInitialChat( bs, "kill_teammate", name, NULL ); + bs->chatto = CHAT_TEAM; + } else + { + //don't chat in teamplay + if ( TeamPlayIsOn() ) { + return qfalse; + } + // + if ( bs->enemydeathtype == MOD_GAUNTLET ) { + BotAI_BotInitialChat( bs, "kill_gauntlet", name, NULL ); + } else if ( bs->enemydeathtype == MOD_RAILGUN ) { + BotAI_BotInitialChat( bs, "kill_rail", name, NULL ); + } else if ( bs->enemydeathtype == MOD_TELEFRAG ) { + BotAI_BotInitialChat( bs, "kill_telefrag", name, NULL ); + } + //choose between insult and praise + else if ( random() < trap_Characteristic_BFloat( bs->character, CHARACTERISTIC_CHAT_INSULT, 0, 1 ) ) { + BotAI_BotInitialChat( bs, "kill_insult", name, NULL ); + } else { + BotAI_BotInitialChat( bs, "kill_praise", name, NULL ); + } + } + bs->lastchat_time = trap_AAS_Time(); + return qtrue; +} + +/* +================== +BotChat_EnemySuicide +================== +*/ +int BotChat_EnemySuicide( bot_state_t *bs ) { + char name[32]; + float rnd; + + if ( bot_nochat.integer ) { + return qfalse; + } + if ( bs->lastchat_time > trap_AAS_Time() - 3 ) { + return qfalse; + } + if ( BotNumActivePlayers() <= 1 ) { + return qfalse; + } + // + rnd = trap_Characteristic_BFloat( bs->character, CHARACTERISTIC_CHAT_KILL, 0, 1 ); + //don't chat in teamplay + if ( TeamPlayIsOn() ) { + return qfalse; + } + //if fast chat is off + if ( !bot_fastchat.integer ) { + if ( random() > rnd ) { + return qfalse; + } + } + if ( !BotValidChatPosition( bs ) ) { + return qfalse; + } + // + if ( bs->enemy >= 0 ) { + EasyClientName( bs->enemy, name, 32 ); + } else { strcpy( name, "" );} + BotAI_BotInitialChat( bs, "enemy_suicide", name, NULL ); + bs->lastchat_time = trap_AAS_Time(); + bs->chatto = CHAT_ALL; + return qtrue; +} + +/* +================== +BotChat_HitTalking +================== +*/ +int BotChat_HitTalking( bot_state_t *bs ) { + char name[32], *weap; + int lasthurt_client; + float rnd; + + if ( bot_nochat.integer ) { + return qfalse; + } + if ( bs->lastchat_time > trap_AAS_Time() - 3 ) { + return qfalse; + } + if ( BotNumActivePlayers() <= 1 ) { + return qfalse; + } + lasthurt_client = g_entities[bs->client].client->lasthurt_client; + if ( !lasthurt_client ) { + return qfalse; + } + if ( lasthurt_client == bs->client ) { + return qfalse; + } + // + if ( lasthurt_client < 0 || lasthurt_client >= MAX_CLIENTS ) { + return qfalse; + } + // + rnd = trap_Characteristic_BFloat( bs->character, CHARACTERISTIC_CHAT_HITTALKING, 0, 1 ); + //don't chat in teamplay + if ( TeamPlayIsOn() ) { + return qfalse; + } + //if fast chat is off + if ( !bot_fastchat.integer ) { + if ( random() > rnd * 0.5 ) { + return qfalse; + } + } + if ( !BotValidChatPosition( bs ) ) { + return qfalse; + } + // + ClientName( g_entities[bs->client].client->lasthurt_client, name, sizeof( name ) ); + weap = BotWeaponNameForMeansOfDeath( g_entities[bs->client].client->lasthurt_client ); + // + BotAI_BotInitialChat( bs, "hit_talking", name, weap, NULL ); + bs->lastchat_time = trap_AAS_Time(); + bs->chatto = CHAT_ALL; + return qtrue; +} + +/* +================== +BotChat_HitNoDeath +================== +*/ +int BotChat_HitNoDeath( bot_state_t *bs ) { + char name[32], *weap; + float rnd; + int lasthurt_client; + aas_entityinfo_t entinfo; + + lasthurt_client = g_entities[bs->client].client->lasthurt_client; + if ( !lasthurt_client ) { + return qfalse; + } + if ( lasthurt_client == bs->client ) { + return qfalse; + } + // + if ( lasthurt_client < 0 || lasthurt_client >= MAX_CLIENTS ) { + return qfalse; + } + // + if ( bot_nochat.integer ) { + return qfalse; + } + if ( bs->lastchat_time > trap_AAS_Time() - 3 ) { + return qfalse; + } + if ( BotNumActivePlayers() <= 1 ) { + return qfalse; + } + rnd = trap_Characteristic_BFloat( bs->character, CHARACTERISTIC_CHAT_HITNODEATH, 0, 1 ); + //don't chat in teamplay + if ( TeamPlayIsOn() ) { + return qfalse; + } + //if fast chat is off + if ( !bot_fastchat.integer ) { + if ( random() > rnd * 0.5 ) { + return qfalse; + } + } + if ( !BotValidChatPosition( bs ) ) { + return qfalse; + } + //if the enemy is visible + if ( BotEntityVisible( bs->client, bs->eye, bs->viewangles, 360, bs->enemy ) ) { + return qfalse; + } + // + BotEntityInfo( bs->enemy, &entinfo ); + if ( EntityIsShooting( &entinfo ) ) { + return qfalse; + } + // + ClientName( lasthurt_client, name, sizeof( name ) ); + weap = BotWeaponNameForMeansOfDeath( g_entities[bs->client].client->lasthurt_mod ); + // + BotAI_BotInitialChat( bs, "hit_nodeath", name, weap, NULL ); + bs->lastchat_time = trap_AAS_Time(); + bs->chatto = CHAT_ALL; + return qtrue; +} + +/* +================== +BotChat_HitNoKill +================== +*/ +int BotChat_HitNoKill( bot_state_t *bs ) { + char name[32], *weap; + float rnd; + aas_entityinfo_t entinfo; + + if ( bot_nochat.integer ) { + return qfalse; + } + if ( bs->lastchat_time > trap_AAS_Time() - 3 ) { + return qfalse; + } + if ( BotNumActivePlayers() <= 1 ) { + return qfalse; + } + rnd = trap_Characteristic_BFloat( bs->character, CHARACTERISTIC_CHAT_HITNOKILL, 0, 1 ); + //don't chat in teamplay + if ( TeamPlayIsOn() ) { + return qfalse; + } + //if fast chat is off + if ( !bot_fastchat.integer ) { + if ( random() > rnd * 0.5 ) { + return qfalse; + } + } + if ( !BotValidChatPosition( bs ) ) { + return qfalse; + } + //if the enemy is visible + if ( BotEntityVisible( bs->client, bs->eye, bs->viewangles, 360, bs->enemy ) ) { + return qfalse; + } + // + BotEntityInfo( bs->enemy, &entinfo ); + if ( EntityIsShooting( &entinfo ) ) { + return qfalse; + } + // + ClientName( bs->enemy, name, sizeof( name ) ); + weap = BotWeaponNameForMeansOfDeath( g_entities[bs->enemy].client->lasthurt_mod ); + // + BotAI_BotInitialChat( bs, "hit_nokill", name, weap, NULL ); + bs->lastchat_time = trap_AAS_Time(); + bs->chatto = CHAT_ALL; + return qtrue; +} + +/* +================== +BotChat_Random +================== +*/ +int BotChat_Random( bot_state_t *bs ) { + float rnd; + char name[32]; + + if ( bot_nochat.integer ) { + return qfalse; + } + if ( BotIsObserver( bs ) ) { + return qfalse; + } + if ( bs->lastchat_time > trap_AAS_Time() - 3 ) { + return qfalse; + } + //don't chat in teamplay + if ( TeamPlayIsOn() ) { + return qfalse; + } + //don't chat when doing something important :) + if ( bs->ltgtype == LTG_TEAMHELP || + bs->ltgtype == LTG_TEAMACCOMPANY || + bs->ltgtype == LTG_RUSHBASE ) { + return qfalse; + } + // + rnd = trap_Characteristic_BFloat( bs->character, CHARACTERISTIC_CHAT_RANDOM, 0, 1 ); + if ( random() > bs->thinktime * 0.1 ) { + return qfalse; + } + if ( !bot_fastchat.integer ) { + if ( random() > rnd ) { + return qfalse; + } + if ( random() > 0.25 ) { + return qfalse; + } + } + if ( BotNumActivePlayers() <= 1 ) { + return qfalse; + } + if ( !BotValidChatPosition( bs ) ) { + return qfalse; + } + // + if ( bs->lastkilledplayer == bs->client ) { + strcpy( name, BotRandomOpponentName( bs ) ); + } else { + EasyClientName( bs->lastkilledplayer, name, sizeof( name ) ); + } + // + if ( random() < trap_Characteristic_BFloat( bs->character, CHARACTERISTIC_CHAT_MISC, 0, 1 ) ) { + BotAI_BotInitialChat( bs, "random_misc", + BotRandomOpponentName( bs ), // 0 + name, // 1 + "[invalid var]", // 2 + "[invalid var]", // 3 + BotMapTitle(), // 4 + BotRandomWeaponName(), // 5 + NULL ); + } else { + BotAI_BotInitialChat( bs, "random_insult", + BotRandomOpponentName( bs ), // 0 + name, // 1 + "[invalid var]", // 2 + "[invalid var]", // 3 + BotMapTitle(), // 4 + BotRandomWeaponName(), // 5 + NULL ); + } + bs->lastchat_time = trap_AAS_Time(); + bs->chatto = CHAT_ALL; + return qtrue; +} + +/* +================== +BotChatTime +================== +*/ +float BotChatTime( bot_state_t *bs ) { + int cpm; + + cpm = trap_Characteristic_BInteger( bs->character, CHARACTERISTIC_CHAT_CPM, 1, 4000 ); + + return 2.0; //(float) trap_BotChatLength(bs->cs) * 30 / cpm; +} + +/* +================== +BotChatTest +================== +*/ +void BotChatTest( bot_state_t *bs ) { + + char name[32]; + char *weap; + int num, i; + + num = trap_BotNumInitialChats( bs->cs, "game_enter" ); + for ( i = 0; i < num; i++ ) + { + BotAI_BotInitialChat( bs, "game_enter", + EasyClientName( bs->client, name, 32 ), // 0 + BotRandomOpponentName( bs ), // 1 + "[invalid var]", // 2 + "[invalid var]", // 3 + BotMapTitle(), // 4 + NULL ); + trap_BotEnterChat( bs->cs, bs->client, CHAT_ALL ); + } + num = trap_BotNumInitialChats( bs->cs, "game_exit" ); + for ( i = 0; i < num; i++ ) + { + BotAI_BotInitialChat( bs, "game_exit", + EasyClientName( bs->client, name, 32 ), // 0 + BotRandomOpponentName( bs ), // 1 + "[invalid var]", // 2 + "[invalid var]", // 3 + BotMapTitle(), // 4 + NULL ); + trap_BotEnterChat( bs->cs, bs->client, CHAT_ALL ); + } + num = trap_BotNumInitialChats( bs->cs, "level_start" ); + for ( i = 0; i < num; i++ ) + { + BotAI_BotInitialChat( bs, "level_start", + EasyClientName( bs->client, name, 32 ), // 0 + NULL ); + trap_BotEnterChat( bs->cs, bs->client, CHAT_ALL ); + } + num = trap_BotNumInitialChats( bs->cs, "level_end_victory" ); + for ( i = 0; i < num; i++ ) + { + BotAI_BotInitialChat( bs, "level_end_victory", + EasyClientName( bs->client, name, 32 ), // 0 + BotRandomOpponentName( bs ), // 1 + BotFirstClientInRankings(), // 2 + BotLastClientInRankings(), // 3 + BotMapTitle(), // 4 + NULL ); + trap_BotEnterChat( bs->cs, bs->client, CHAT_ALL ); + } + num = trap_BotNumInitialChats( bs->cs, "level_end_lose" ); + for ( i = 0; i < num; i++ ) + { + BotAI_BotInitialChat( bs, "level_end_lose", + EasyClientName( bs->client, name, 32 ), // 0 + BotRandomOpponentName( bs ), // 1 + BotFirstClientInRankings(), // 2 + BotLastClientInRankings(), // 3 + BotMapTitle(), // 4 + NULL ); + trap_BotEnterChat( bs->cs, bs->client, CHAT_ALL ); + } + num = trap_BotNumInitialChats( bs->cs, "level_end" ); + for ( i = 0; i < num; i++ ) + { + BotAI_BotInitialChat( bs, "level_end", + EasyClientName( bs->client, name, 32 ), // 0 + BotRandomOpponentName( bs ), // 1 + BotFirstClientInRankings(), // 2 + BotLastClientInRankings(), // 3 + BotMapTitle(), // 4 + NULL ); + trap_BotEnterChat( bs->cs, bs->client, CHAT_ALL ); + } + EasyClientName( bs->lastkilledby, name, sizeof( name ) ); + num = trap_BotNumInitialChats( bs->cs, "death_drown" ); + for ( i = 0; i < num; i++ ) + { + // + BotAI_BotInitialChat( bs, "death_drown", name, NULL ); + trap_BotEnterChat( bs->cs, bs->client, CHAT_ALL ); + } + num = trap_BotNumInitialChats( bs->cs, "death_slime" ); + for ( i = 0; i < num; i++ ) + { + BotAI_BotInitialChat( bs, "death_slime", name, NULL ); + trap_BotEnterChat( bs->cs, bs->client, CHAT_ALL ); + } + num = trap_BotNumInitialChats( bs->cs, "death_lava" ); + for ( i = 0; i < num; i++ ) + { + BotAI_BotInitialChat( bs, "death_lava", name, NULL ); + trap_BotEnterChat( bs->cs, bs->client, CHAT_ALL ); + } + num = trap_BotNumInitialChats( bs->cs, "death_cratered" ); + for ( i = 0; i < num; i++ ) + { + BotAI_BotInitialChat( bs, "death_cratered", name, NULL ); + trap_BotEnterChat( bs->cs, bs->client, CHAT_ALL ); + } + num = trap_BotNumInitialChats( bs->cs, "death_suicide" ); + for ( i = 0; i < num; i++ ) + { + BotAI_BotInitialChat( bs, "death_suicide", name, NULL ); + trap_BotEnterChat( bs->cs, bs->client, CHAT_ALL ); + } + num = trap_BotNumInitialChats( bs->cs, "death_telefrag" ); + for ( i = 0; i < num; i++ ) + { + BotAI_BotInitialChat( bs, "death_telefrag", name, NULL ); + trap_BotEnterChat( bs->cs, bs->client, CHAT_ALL ); + } + num = trap_BotNumInitialChats( bs->cs, "death_gauntlet" ); + for ( i = 0; i < num; i++ ) + { + BotAI_BotInitialChat( bs, "death_gauntlet", + name, // 0 + BotWeaponNameForMeansOfDeath( bs->botdeathtype ), // 1 + NULL ); + trap_BotEnterChat( bs->cs, bs->client, CHAT_ALL ); + } + num = trap_BotNumInitialChats( bs->cs, "death_rail" ); + for ( i = 0; i < num; i++ ) + { + BotAI_BotInitialChat( bs, "death_rail", + name, // 0 + BotWeaponNameForMeansOfDeath( bs->botdeathtype ), // 1 + NULL ); + trap_BotEnterChat( bs->cs, bs->client, CHAT_ALL ); + } + num = trap_BotNumInitialChats( bs->cs, "death_bfg" ); + for ( i = 0; i < num; i++ ) + { + BotAI_BotInitialChat( bs, "death_bfg", + name, // 0 + BotWeaponNameForMeansOfDeath( bs->botdeathtype ), // 1 + NULL ); + trap_BotEnterChat( bs->cs, bs->client, CHAT_ALL ); + } + num = trap_BotNumInitialChats( bs->cs, "death_insult" ); + for ( i = 0; i < num; i++ ) + { + BotAI_BotInitialChat( bs, "death_insult", + name, // 0 + BotWeaponNameForMeansOfDeath( bs->botdeathtype ), // 1 + NULL ); + trap_BotEnterChat( bs->cs, bs->client, CHAT_ALL ); + } + num = trap_BotNumInitialChats( bs->cs, "death_praise" ); + for ( i = 0; i < num; i++ ) + { + BotAI_BotInitialChat( bs, "death_praise", + name, // 0 + BotWeaponNameForMeansOfDeath( bs->botdeathtype ), // 1 + NULL ); + trap_BotEnterChat( bs->cs, bs->client, CHAT_ALL ); + } + // + EasyClientName( bs->lastkilledplayer, name, 32 ); + // + num = trap_BotNumInitialChats( bs->cs, "kill_gauntlet" ); + for ( i = 0; i < num; i++ ) + { + // + BotAI_BotInitialChat( bs, "kill_gauntlet", name, NULL ); + trap_BotEnterChat( bs->cs, bs->client, CHAT_ALL ); + } + num = trap_BotNumInitialChats( bs->cs, "kill_rail" ); + for ( i = 0; i < num; i++ ) + { + BotAI_BotInitialChat( bs, "kill_rail", name, NULL ); + trap_BotEnterChat( bs->cs, bs->client, CHAT_ALL ); + } + num = trap_BotNumInitialChats( bs->cs, "kill_telefrag" ); + for ( i = 0; i < num; i++ ) + { + BotAI_BotInitialChat( bs, "kill_telefrag", name, NULL ); + trap_BotEnterChat( bs->cs, bs->client, CHAT_ALL ); + } + num = trap_BotNumInitialChats( bs->cs, "kill_insult" ); + for ( i = 0; i < num; i++ ) + { + BotAI_BotInitialChat( bs, "kill_insult", name, NULL ); + trap_BotEnterChat( bs->cs, bs->client, CHAT_ALL ); + } + num = trap_BotNumInitialChats( bs->cs, "kill_praise" ); + for ( i = 0; i < num; i++ ) + { + BotAI_BotInitialChat( bs, "kill_praise", name, NULL ); + trap_BotEnterChat( bs->cs, bs->client, CHAT_ALL ); + } + num = trap_BotNumInitialChats( bs->cs, "enemy_suicide" ); + for ( i = 0; i < num; i++ ) + { + BotAI_BotInitialChat( bs, "enemy_suicide", name, NULL ); + trap_BotEnterChat( bs->cs, bs->client, CHAT_ALL ); + } + ClientName( g_entities[bs->client].client->lasthurt_client, name, sizeof( name ) ); + weap = BotWeaponNameForMeansOfDeath( g_entities[bs->client].client->lasthurt_client ); + num = trap_BotNumInitialChats( bs->cs, "hit_talking" ); + for ( i = 0; i < num; i++ ) + { + BotAI_BotInitialChat( bs, "hit_talking", name, weap, NULL ); + trap_BotEnterChat( bs->cs, bs->client, CHAT_ALL ); + } + num = trap_BotNumInitialChats( bs->cs, "hit_nodeath" ); + for ( i = 0; i < num; i++ ) + { + BotAI_BotInitialChat( bs, "hit_nodeath", name, weap, NULL ); + trap_BotEnterChat( bs->cs, bs->client, CHAT_ALL ); + } + num = trap_BotNumInitialChats( bs->cs, "hit_nokill" ); + for ( i = 0; i < num; i++ ) + { + BotAI_BotInitialChat( bs, "hit_nokill", name, weap, NULL ); + trap_BotEnterChat( bs->cs, bs->client, CHAT_ALL ); + } + // + if ( bs->lastkilledplayer == bs->client ) { + strcpy( name, BotRandomOpponentName( bs ) ); + } else { + EasyClientName( bs->lastkilledplayer, name, sizeof( name ) ); + } + // + num = trap_BotNumInitialChats( bs->cs, "random_misc" ); + for ( i = 0; i < num; i++ ) + { + // + BotAI_BotInitialChat( bs, "random_misc", + BotRandomOpponentName( bs ), // 0 + name, // 1 + "[invalid var]", // 2 + "[invalid var]", // 3 + BotMapTitle(), // 4 + BotRandomWeaponName(), // 5 + NULL ); + trap_BotEnterChat( bs->cs, bs->client, CHAT_ALL ); + } + num = trap_BotNumInitialChats( bs->cs, "random_insult" ); + for ( i = 0; i < num; i++ ) + { + BotAI_BotInitialChat( bs, "random_insult", + BotRandomOpponentName( bs ), // 0 + name, // 1 + "[invalid var]", // 2 + "[invalid var]", // 3 + BotMapTitle(), // 4 + BotRandomWeaponName(), // 5 + NULL ); + trap_BotEnterChat( bs->cs, bs->client, CHAT_ALL ); + } +} diff --git a/Projects/Android/jni/rtcw/src/botai/ai_chat.h b/Projects/Android/jni/rtcw/src/botai/ai_chat.h new file mode 100644 index 0000000..1b97caf --- /dev/null +++ b/Projects/Android/jni/rtcw/src/botai/ai_chat.h @@ -0,0 +1,66 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +/***************************************************************************** + * name: ai_chat.h + * + * desc: Quake3 bot AI + * + * + *****************************************************************************/ + +// +int BotChat_EnterGame( bot_state_t *bs ); +// +int BotChat_ExitGame( bot_state_t *bs ); +// +int BotChat_StartLevel( bot_state_t *bs ); +// +int BotChat_EndLevel( bot_state_t *bs ); +// +int BotChat_HitTalking( bot_state_t *bs ); +// +int BotChat_HitNoDeath( bot_state_t *bs ); +// +int BotChat_HitNoKill( bot_state_t *bs ); +// +int BotChat_Death( bot_state_t *bs ); +// +int BotChat_Kill( bot_state_t *bs ); +// +int BotChat_EnemySuicide( bot_state_t *bs ); +// +int BotChat_Random( bot_state_t *bs ); +// time the selected chat takes to type in +float BotChatTime( bot_state_t *bs ); +// returns true if the bot can chat at the current position +int BotValidChatPosition( bot_state_t *bs ); +// test the initial bot chats +void BotChatTest( bot_state_t *bs ); + diff --git a/Projects/Android/jni/rtcw/src/botai/ai_cmd.c b/Projects/Android/jni/rtcw/src/botai/ai_cmd.c new file mode 100644 index 0000000..2ddd5d8 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/botai/ai_cmd.c @@ -0,0 +1,1645 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +/***************************************************************************** + * name: ai_cmd.c + * + * desc: Quake3 bot AI + * + * + *****************************************************************************/ + +#include "../game/g_local.h" +#include "../game/botlib.h" +#include "../game/be_aas.h" +#include "../game/be_ea.h" +#include "../game/be_ai_char.h" +#include "../game/be_ai_chat.h" +#include "../game/be_ai_gen.h" +#include "../game/be_ai_goal.h" +#include "../game/be_ai_move.h" +#include "../game/be_ai_weap.h" +#include "../botai/botai.h" +// +#include "ai_main.h" +#include "ai_dmq3.h" +#include "ai_chat.h" +#include "ai_cmd.h" +#include "ai_dmnet.h" +// +#include "chars.h" //characteristics +#include "inv.h" //indexes into the inventory +#include "syn.h" //synonyms +#include "match.h" //string matching types and vars + + +#ifdef DEBUG +/* +================== +BotPrintTeamGoal +================== +*/ +void BotPrintTeamGoal( bot_state_t *bs ) { + char netname[MAX_NETNAME]; + float t; + + ClientName( bs->client, netname, sizeof( netname ) ); + t = bs->teamgoal_time - trap_AAS_Time(); + switch ( bs->ltgtype ) { + case LTG_TEAMHELP: + { + BotAI_Print( PRT_MESSAGE, "%s: I'm gonna help a team mate for %1.0f secs\n", netname, t ); + break; + } + case LTG_TEAMACCOMPANY: + { + BotAI_Print( PRT_MESSAGE, "%s: I'm gonna accompany a team mate for %1.0f secs\n", netname, t ); + break; + } + case LTG_GETFLAG: + { + BotAI_Print( PRT_MESSAGE, "%s: I'm gonna get the flag for %1.0f secs\n", netname, t ); + break; + } + case LTG_RUSHBASE: + { + BotAI_Print( PRT_MESSAGE, "%s: I'm gonna rush to the base for %1.0f secs\n", netname, t ); + break; + } + case LTG_RETURNFLAG: + { + BotAI_Print( PRT_MESSAGE, "%s: I'm gonna try to return the flag for %1.0f secs\n", netname, t ); + break; + } + case LTG_DEFENDKEYAREA: + { + BotAI_Print( PRT_MESSAGE, "%s: I'm gonna defend a key area for %1.0f secs\n", netname, t ); + break; + } + case LTG_GETITEM: + { + BotAI_Print( PRT_MESSAGE, "%s: I'm gonna get an item for %1.0f secs\n", netname, t ); + break; + } + case LTG_KILL: + { + BotAI_Print( PRT_MESSAGE, "%s: I'm gonna kill someone for %1.0f secs\n", netname, t ); + break; + } + case LTG_CAMP: + case LTG_CAMPORDER: + { + BotAI_Print( PRT_MESSAGE, "%s: I'm gonna camp for %1.0f secs\n", netname, t ); + break; + } + case LTG_PATROL: + { + BotAI_Print( PRT_MESSAGE, "%s: I'm gonna patrol for %1.0f secs\n", netname, t ); + break; + } + default: + { + if ( bs->ctfroam_time > trap_AAS_Time() ) { + t = bs->ctfroam_time - trap_AAS_Time(); + BotAI_Print( PRT_MESSAGE, "%s: I'm gonna roam for %1.0f secs\n", netname, t ); + } else { + BotAI_Print( PRT_MESSAGE, "%s: I've got a regular goal\n", netname ); + } + } + } +} +#endif //DEBUG + +/* +================== +BotGetItemTeamGoal + +FIXME: add stuff like "upper rocket launcher" +"the rl near the railgun", "lower grenade launcher" etc. +================== +*/ +int BotGetItemTeamGoal( char *goalname, bot_goal_t *goal ) { + int i; + + if ( !strlen( goalname ) ) { + return qfalse; + } + i = -1; + do { + i = trap_BotGetLevelItemGoal( i, goalname, goal ); + if ( i > 0 ) { // && !AvoidGoalTime(&bs->gs, goal.number)) + return qtrue; + } + } while ( i > 0 ); + return qfalse; +} + +/* +================== +BotGetMessageTeamGoal +================== +*/ +int BotGetMessageTeamGoal( bot_state_t *bs, char *goalname, bot_goal_t *goal ) { + bot_waypoint_t *cp; + + if ( BotGetItemTeamGoal( goalname, goal ) ) { + return qtrue; + } + + cp = BotFindWayPoint( bs->checkpoints, goalname ); + if ( cp ) { + memcpy( goal, &cp->goal, sizeof( bot_goal_t ) ); + return qtrue; + } + return qfalse; +} + +/* +================== +BotGetTime +================== +*/ +float BotGetTime( bot_match_t *match ) { + bot_match_t timematch; + char timestring[MAX_MESSAGE_SIZE]; + float t; + + //if the matched string has a time + if ( match->subtype & ST_TIME ) { + //get the time string + trap_BotMatchVariable( match, TIME, timestring, MAX_MESSAGE_SIZE ); + //match it to find out if the time is in seconds or minutes + if ( trap_BotFindMatch( timestring, &timematch, MTCONTEXT_TIME ) ) { + if ( timematch.type == MSG_FOREVER ) { + t = 99999999; + } else { + trap_BotMatchVariable( &timematch, TIME, timestring, MAX_MESSAGE_SIZE ); + if ( timematch.type == MSG_MINUTES ) { + t = atof( timestring ) * 60; + } else if ( timematch.type == MSG_SECONDS ) { + t = atof( timestring ); + } else { t = 0;} + } + //if there's a valid time + if ( t > 0 ) { + return trap_AAS_Time() + t; + } + } + } + return 0; +} + +/* +================== +FindClientByName +================== +*/ +int FindClientByName( char *name ) { + int i; + char buf[MAX_INFO_STRING]; + static int maxclients; + + if ( !maxclients ) { + maxclients = trap_Cvar_VariableIntegerValue( "sv_maxclients" ); + } + for ( i = 0; i < maxclients && i < MAX_CLIENTS; i++ ) { + ClientName( i, buf, sizeof( buf ) ); + if ( !Q_stricmp( buf, name ) ) { + return i; + } + } + for ( i = 0; i < maxclients && i < MAX_CLIENTS; i++ ) { + ClientName( i, buf, sizeof( buf ) ); + if ( stristr( buf, name ) ) { + return i; + } + } + return -1; +} + +/* +================== +FindEnemyByName +================== +*/ +int FindEnemyByName( bot_state_t *bs, char *name ) { + int i; + char buf[MAX_INFO_STRING]; + static int maxclients; + + if ( !maxclients ) { + maxclients = trap_Cvar_VariableIntegerValue( "sv_maxclients" ); + } + for ( i = 0; i < maxclients && i < MAX_CLIENTS; i++ ) { + if ( BotSameTeam( bs, i ) ) { + continue; + } + ClientName( i, buf, sizeof( buf ) ); + if ( !Q_stricmp( buf, name ) ) { + return i; + } + } + for ( i = 0; i < maxclients && i < MAX_CLIENTS; i++ ) { + if ( BotSameTeam( bs, i ) ) { + continue; + } + ClientName( i, buf, sizeof( buf ) ); + if ( stristr( buf, name ) ) { + return i; + } + } + return -1; +} + +/* +================== +NumPlayersOnSameTeam +================== +*/ +int NumPlayersOnSameTeam( bot_state_t *bs ) { + int i, num; + char buf[MAX_INFO_STRING]; + static int maxclients; + + if ( !maxclients ) { + maxclients = trap_Cvar_VariableIntegerValue( "sv_maxclients" ); + } + + num = 0; + for ( i = 0; i < maxclients && i < MAX_CLIENTS; i++ ) { + trap_GetConfigstring( CS_PLAYERS + i, buf, MAX_INFO_STRING ); + if ( strlen( buf ) ) { + if ( BotSameTeam( bs, i + 1 ) ) { + num++; + } + } + } + return num; +} + +/* +================== +TeamPlayIsOn +================== +*/ +int BotGetPatrolWaypoints( bot_state_t *bs, bot_match_t *match ) { + char keyarea[MAX_MESSAGE_SIZE]; + int patrolflags; + bot_waypoint_t *wp, *newwp, *newpatrolpoints; + bot_match_t keyareamatch; + bot_goal_t goal; + + newpatrolpoints = NULL; + patrolflags = 0; + // + trap_BotMatchVariable( match, KEYAREA, keyarea, MAX_MESSAGE_SIZE ); + // + while ( 1 ) { + if ( !trap_BotFindMatch( keyarea, &keyareamatch, MTCONTEXT_PATROLKEYAREA ) ) { + trap_EA_SayTeam( bs->client, "what do you say?" ); + BotFreeWaypoints( newpatrolpoints ); + bs->patrolpoints = NULL; + return qfalse; + } + trap_BotMatchVariable( &keyareamatch, KEYAREA, keyarea, MAX_MESSAGE_SIZE ); + if ( !BotGetMessageTeamGoal( bs, keyarea, &goal ) ) { + //BotAI_BotInitialChat(bs, "cannotfind", keyarea, NULL); + //trap_BotEnterChat(bs->cs, bs->client, CHAT_TEAM); + BotFreeWaypoints( newpatrolpoints ); + bs->patrolpoints = NULL; + return qfalse; + } + //create a new waypoint + newwp = BotCreateWayPoint( keyarea, goal.origin, goal.areanum ); + //add the waypoint to the patrol points + newwp->next = NULL; + for ( wp = newpatrolpoints; wp && wp->next; wp = wp->next ) ; + if ( !wp ) { + newpatrolpoints = newwp; + newwp->prev = NULL; + } else { + wp->next = newwp; + newwp->prev = wp; + } + // + if ( keyareamatch.subtype & ST_BACK ) { + patrolflags = PATROL_LOOP; + break; + } else if ( keyareamatch.subtype & ST_REVERSE ) { + patrolflags = PATROL_REVERSE; + break; + } else if ( keyareamatch.subtype & ST_MORE ) { + trap_BotMatchVariable( &keyareamatch, MORE, keyarea, MAX_MESSAGE_SIZE ); + } else { + break; + } + } + // + if ( !newpatrolpoints || !newpatrolpoints->next ) { + trap_EA_SayTeam( bs->client, "I need more key points to patrol\n" ); + BotFreeWaypoints( newpatrolpoints ); + newpatrolpoints = NULL; + return qfalse; + } + // + BotFreeWaypoints( bs->patrolpoints ); + bs->patrolpoints = newpatrolpoints; + // + bs->curpatrolpoint = bs->patrolpoints; + bs->patrolflags = patrolflags; + // + return qtrue; +} + +/* +================== +BotAddressedToBot +================== +*/ +int BotAddressedToBot( bot_state_t *bs, bot_match_t *match ) { + char addressedto[MAX_MESSAGE_SIZE]; + char netname[MAX_MESSAGE_SIZE]; + char name[MAX_MESSAGE_SIZE]; + char botname[128]; + int client; + bot_match_t addresseematch; + + trap_BotMatchVariable( match, NETNAME, netname, sizeof( netname ) ); + client = ClientFromName( netname ); + if ( client < 0 ) { + return qfalse; + } + if ( !BotSameTeam( bs, client ) ) { + return qfalse; + } + //if the message is addressed to someone + if ( match->subtype & ST_ADDRESSED ) { + trap_BotMatchVariable( match, ADDRESSEE, addressedto, sizeof( addressedto ) ); + //the name of this bot + ClientName( bs->client, botname, 128 ); + // + while ( trap_BotFindMatch( addressedto, &addresseematch, MTCONTEXT_ADDRESSEE ) ) { + if ( addresseematch.type == MSG_EVERYONE ) { + return qtrue; + } else if ( addresseematch.type == MSG_MULTIPLENAMES ) { + trap_BotMatchVariable( &addresseematch, TEAMMATE, name, sizeof( name ) ); + if ( strlen( name ) ) { + if ( stristr( botname, name ) ) { + return qtrue; + } + if ( stristr( bs->subteam, name ) ) { + return qtrue; + } + } + trap_BotMatchVariable( &addresseematch, MORE, addressedto, MAX_MESSAGE_SIZE ); + } else { + trap_BotMatchVariable( &addresseematch, TEAMMATE, name, MAX_MESSAGE_SIZE ); + if ( strlen( name ) ) { + if ( stristr( botname, name ) ) { + return qtrue; + } + if ( stristr( bs->subteam, name ) ) { + return qtrue; + } + } + break; + } + } + //Com_sprintf(buf, sizeof(buf), "not addressed to me but %s", addressedto); + //trap_EA_Say(bs->client, buf); + return qfalse; + } else { + //make sure not everyone reacts to this message + if ( random() > (float ) 1.0 / ( NumPlayersOnSameTeam( bs ) - 1 ) ) { + return qfalse; + } + } + return qtrue; +} + +/* +================== +BotGPSToPosition +================== +*/ +int BotGPSToPosition( char *buf, vec3_t position ) { + int i, j = 0; + int num, sign; + + for ( i = 0; i < 3; i++ ) { + num = 0; + while ( buf[j] == ' ' ) j++; + if ( buf[j] == '-' ) { + j++; + sign = -1; + } else { + sign = 1; + } + while ( buf[j] ) { + if ( buf[j] >= '0' && buf[j] <= '9' ) { + num = num * 10 + buf[j] - '0'; + j++; + } else { + j++; + break; + } + } + BotAI_Print( PRT_MESSAGE, "%d\n", sign * num ); + position[i] = (float) sign * num; + } + return qtrue; +} + +/* +================== +BotMatch_HelpAccompany +================== +*/ +void BotMatch_HelpAccompany( bot_state_t *bs, bot_match_t *match ) { + int client, other, areanum; + char teammate[MAX_MESSAGE_SIZE], netname[MAX_MESSAGE_SIZE]; + char itemname[MAX_MESSAGE_SIZE]; + bot_match_t teammatematch; + aas_entityinfo_t entinfo; + + if ( !TeamPlayIsOn() ) { + return; + } + //if not addressed to this bot + if ( !BotAddressedToBot( bs, match ) ) { + return; + } + //get the team mate name + trap_BotMatchVariable( match, TEAMMATE, teammate, sizeof( teammate ) ); + //get the client to help + if ( trap_BotFindMatch( teammate, &teammatematch, MTCONTEXT_TEAMMATE ) && + //if someone asks for him or herself + teammatematch.type == MSG_ME ) { + //get the netname + trap_BotMatchVariable( match, NETNAME, netname, sizeof( netname ) ); + client = ClientFromName( netname ); + other = qfalse; + } else { + //asked for someone else + client = FindClientByName( teammate ); + //if this is the bot self + if ( client == bs->client ) { + other = qfalse; + } else if ( !BotSameTeam( bs, client ) ) { + //FIXME: say "I don't help the enemy" + return; + } else { + other = qtrue; + } + } + //if the bot doesn't know who to help (FindClientByName returned -1) + if ( client < 0 ) { + if ( other ) { + BotAI_BotInitialChat( bs, "whois", teammate, NULL ); + } else { BotAI_BotInitialChat( bs, "whois", netname, NULL );} + trap_BotEnterChat( bs->cs, bs->client, CHAT_TEAM ); + return; + } + //don't help or accompany yourself + if ( client == bs->client ) { + return; + } + // + bs->teamgoal.entitynum = -1; + BotEntityInfo( client, &entinfo ); + //if info is valid (in PVS) + if ( entinfo.valid ) { + areanum = BotPointAreaNum( entinfo.origin ); + if ( areanum && trap_AAS_AreaReachability( areanum ) ) { + bs->teamgoal.entitynum = client; + bs->teamgoal.areanum = areanum; + VectorCopy( entinfo.origin, bs->teamgoal.origin ); + VectorSet( bs->teamgoal.mins, -8, -8, -8 ); + VectorSet( bs->teamgoal.maxs, 8, 8, 8 ); + } + } + //if no teamgoal yet + if ( bs->teamgoal.entitynum < 0 ) { + //if near an item + if ( match->subtype & ST_NEARITEM ) { + //get the match variable + trap_BotMatchVariable( match, ITEM, itemname, sizeof( itemname ) ); + // + if ( !BotGetMessageTeamGoal( bs, itemname, &bs->teamgoal ) ) { + //BotAI_BotInitialChat(bs, "cannotfind", itemname, NULL); + //trap_BotEnterChat(bs->cs, bs->client, CHAT_TEAM); + return; + } + } + } + // + if ( bs->teamgoal.entitynum < 0 ) { + if ( other ) { + BotAI_BotInitialChat( bs, "whereis", teammate, NULL ); + } else { BotAI_BotInitialChat( bs, "whereareyou", netname, NULL );} + trap_BotEnterChat( bs->cs, bs->client, CHAT_TEAM ); + return; + } + //the team mate + bs->teammate = client; + //last time the team mate was assumed visible + bs->teammatevisible_time = trap_AAS_Time(); + //set the time to send a message to the team mates + bs->teammessage_time = trap_AAS_Time() + 2 * random(); + //get the team goal time + bs->teamgoal_time = BotGetTime( match ); + //set the ltg type + if ( match->type == MSG_HELP ) { + bs->ltgtype = LTG_TEAMHELP; + if ( !bs->teamgoal_time ) { + bs->teamgoal_time = trap_AAS_Time() + TEAM_HELP_TIME; + } + } else { + bs->ltgtype = LTG_TEAMACCOMPANY; + if ( !bs->teamgoal_time ) { + bs->teamgoal_time = trap_AAS_Time() + TEAM_ACCOMPANY_TIME; + } + bs->formation_dist = 3.5 * 32; //3.5 meter + bs->arrive_time = 0; + } +#ifdef DEBUG + BotPrintTeamGoal( bs ); +#endif //DEBUG +} + +/* +================== +BotMatch_DefendKeyArea +================== +*/ +void BotMatch_DefendKeyArea( bot_state_t *bs, bot_match_t *match ) { + char itemname[MAX_MESSAGE_SIZE]; + + if ( !TeamPlayIsOn() ) { + return; + } + //if not addressed to this bot + if ( !BotAddressedToBot( bs, match ) ) { + return; + } + //get the match variable + trap_BotMatchVariable( match, KEYAREA, itemname, sizeof( itemname ) ); + // + if ( !BotGetMessageTeamGoal( bs, itemname, &bs->teamgoal ) ) { + //BotAI_BotInitialChat(bs, "cannotfind", itemname, NULL); + //trap_BotEnterChat(bs->cs, bs->client, CHAT_TEAM); + return; + } + //set the time to send a message to the team mates + bs->teammessage_time = trap_AAS_Time() + 2 * random(); + //set the ltg type + bs->ltgtype = LTG_DEFENDKEYAREA; + //get the team goal time + bs->teamgoal_time = BotGetTime( match ); + //set the team goal time + if ( !bs->teamgoal_time ) { + bs->teamgoal_time = trap_AAS_Time() + TEAM_DEFENDKEYAREA_TIME; + } + //away from defending + bs->defendaway_time = 0; +#ifdef DEBUG + BotPrintTeamGoal( bs ); +#endif //DEBUG +} + +/* +================== +BotMatch_GetItem +================== +*/ +void BotMatch_GetItem( bot_state_t *bs, bot_match_t *match ) { + char itemname[MAX_MESSAGE_SIZE]; + + if ( !TeamPlayIsOn() ) { + return; + } + //if not addressed to this bot + if ( !BotAddressedToBot( bs, match ) ) { + return; + } + //get the match variable + trap_BotMatchVariable( match, ITEM, itemname, sizeof( itemname ) ); + // + if ( !BotGetMessageTeamGoal( bs, itemname, &bs->teamgoal ) ) { + //BotAI_BotInitialChat(bs, "cannotfind", itemname, NULL); + //trap_BotEnterChat(bs->cs, bs->client, CHAT_TEAM); + return; + } + //set the time to send a message to the team mates + bs->teammessage_time = trap_AAS_Time() + 2 * random(); + //set the ltg type + bs->ltgtype = LTG_GETITEM; + //set the team goal time + bs->teamgoal_time = trap_AAS_Time() + TEAM_GETITEM_TIME; +#ifdef DEBUG + BotPrintTeamGoal( bs ); +#endif //DEBUG +} + +/* +================== +BotMatch_Camp +================== +*/ +void BotMatch_Camp( bot_state_t *bs, bot_match_t *match ) { + int client, areanum; + char netname[MAX_MESSAGE_SIZE]; + char itemname[MAX_MESSAGE_SIZE]; + aas_entityinfo_t entinfo; + + if ( !TeamPlayIsOn() ) { + return; + } + //if not addressed to this bot + if ( !BotAddressedToBot( bs, match ) ) { + return; + } + // + trap_BotMatchVariable( match, NETNAME, netname, sizeof( netname ) ); + //asked for someone else + client = FindClientByName( netname ); + //if there's no valid client with this name + if ( client < 0 ) { + BotAI_BotInitialChat( bs, "whois", netname, NULL ); + trap_BotEnterChat( bs->cs, bs->client, CHAT_TEAM ); + return; + } + //get the match variable + trap_BotMatchVariable( match, KEYAREA, itemname, sizeof( itemname ) ); + //in CTF it could be the base + if ( match->subtype & ST_THERE ) { + //camp at the spot the bot is currently standing + bs->teamgoal.entitynum = bs->entitynum; + bs->teamgoal.areanum = bs->areanum; + VectorCopy( bs->origin, bs->teamgoal.origin ); + VectorSet( bs->teamgoal.mins, -8, -8, -8 ); + VectorSet( bs->teamgoal.maxs, 8, 8, 8 ); + } else if ( match->subtype & ST_HERE ) { + //if this is the bot self + if ( client == bs->client ) { + return; + } + // + bs->teamgoal.entitynum = -1; + BotEntityInfo( client, &entinfo ); + //if info is valid (in PVS) + if ( entinfo.valid ) { + areanum = BotPointAreaNum( entinfo.origin ); + if ( areanum && trap_AAS_AreaReachability( areanum ) ) { + //NOTE: just cheat and assume the bot knows where the person is + //if (BotEntityVisible(bs->entitynum, bs->eye, bs->viewangles, 360, client)) { + bs->teamgoal.entitynum = client; + bs->teamgoal.areanum = areanum; + VectorCopy( entinfo.origin, bs->teamgoal.origin ); + VectorSet( bs->teamgoal.mins, -8, -8, -8 ); + VectorSet( bs->teamgoal.maxs, 8, 8, 8 ); + //} + } + } + //if the other is not visible + if ( bs->teamgoal.entitynum < 0 ) { + BotAI_BotInitialChat( bs, "whereareyou", netname, NULL ); + trap_BotEnterChat( bs->cs, bs->client, CHAT_TEAM ); + return; + } + } else if ( !BotGetMessageTeamGoal( bs, itemname, &bs->teamgoal ) ) { + //BotAI_BotInitialChat(bs, "cannotfind", itemname, NULL); + //trap_BotEnterChat(bs->cs, bs->client, CHAT_TEAM); + return; + } + //set the time to send a message to the team mates + bs->teammessage_time = trap_AAS_Time() + 2 * random(); + //set the ltg type + bs->ltgtype = LTG_CAMPORDER; + //get the team goal time + bs->teamgoal_time = BotGetTime( match ); + //set the team goal time + if ( !bs->teamgoal_time ) { + bs->teamgoal_time = trap_AAS_Time() + TEAM_CAMP_TIME; + } + //the teammate that requested the camping + bs->teammate = client; + //not arrived yet + bs->arrive_time = 0; + // +#ifdef DEBUG + BotPrintTeamGoal( bs ); +#endif //DEBUG +} + +/* +================== +BotMatch_Patrol +================== +*/ +void BotMatch_Patrol( bot_state_t *bs, bot_match_t *match ) { + if ( !TeamPlayIsOn() ) { + return; + } + //if not addressed to this bot + if ( !BotAddressedToBot( bs, match ) ) { + return; + } + //get the patrol waypoints + if ( !BotGetPatrolWaypoints( bs, match ) ) { + return; + } + //set the time to send a message to the team mates + bs->teammessage_time = trap_AAS_Time() + 2 * random(); + //set the ltg type + bs->ltgtype = LTG_PATROL; + //get the team goal time + bs->teamgoal_time = BotGetTime( match ); + //set the team goal time if not set already + if ( !bs->teamgoal_time ) { + bs->teamgoal_time = trap_AAS_Time() + TEAM_PATROL_TIME; + } + // +#ifdef DEBUG + BotPrintTeamGoal( bs ); +#endif //DEBUG +} + +/* +================== +BotMatch_GetFlag +================== +*/ +void BotMatch_GetFlag( bot_state_t *bs, bot_match_t *match ) { + //if not in CTF mode + if ( gametype != GT_CTF || !ctf_redflag.areanum || !ctf_blueflag.areanum ) { + return; + } + //if not addressed to this bot + if ( !BotAddressedToBot( bs, match ) ) { + return; + } + //set the time to send a message to the team mates + bs->teammessage_time = trap_AAS_Time() + 2 * random(); + //set the ltg type + bs->ltgtype = LTG_GETFLAG; + //set the team goal time + bs->teamgoal_time = trap_AAS_Time() + CTF_GETFLAG_TIME; +#ifdef DEBUG + BotPrintTeamGoal( bs ); +#endif //DEBUG +} + +/* +================== +BotMatch_RushBase +================== +*/ +void BotMatch_RushBase( bot_state_t *bs, bot_match_t *match ) { + //if not in CTF mode + if ( gametype != GT_CTF || !ctf_redflag.areanum || !ctf_blueflag.areanum ) { + return; + } + //if not addressed to this bot + if ( !BotAddressedToBot( bs, match ) ) { + return; + } + //set the time to send a message to the team mates + bs->teammessage_time = trap_AAS_Time() + 2 * random(); + //set the ltg type + bs->ltgtype = LTG_RUSHBASE; + //set the team goal time + bs->teamgoal_time = trap_AAS_Time() + CTF_RUSHBASE_TIME; + bs->rushbaseaway_time = 0; +#ifdef DEBUG + BotPrintTeamGoal( bs ); +#endif //DEBUG +} + + +/* +================== +BotMatch_ReturnFlag +================== +*/ +void BotMatch_ReturnFlag( bot_state_t *bs, bot_match_t *match ) { + //if not in CTF mode + if ( gametype != GT_CTF ) { + return; + } + //if not addressed to this bot + if ( !BotAddressedToBot( bs, match ) ) { + return; + } + //set the time to send a message to the team mates + bs->teammessage_time = trap_AAS_Time() + 2 * random(); + //set the ltg type + bs->ltgtype = LTG_RETURNFLAG; + //set the team goal time + bs->teamgoal_time = trap_AAS_Time() + CTF_RETURNFLAG_TIME; + bs->rushbaseaway_time = 0; +#ifdef DEBUG + BotPrintTeamGoal( bs ); +#endif //DEBUG +} + +/* +================== +BotMatch_JoinSubteam +================== +*/ +void BotMatch_JoinSubteam( bot_state_t *bs, bot_match_t *match ) { + char teammate[MAX_MESSAGE_SIZE]; + + if ( !TeamPlayIsOn() ) { + return; + } + //if not addressed to this bot + if ( !BotAddressedToBot( bs, match ) ) { + return; + } + //get the sub team name + trap_BotMatchVariable( match, TEAMNAME, teammate, MAX_MESSAGE_SIZE ); + //set the sub team name + strncpy( bs->subteam, teammate, 32 ); + bs->subteam[31] = '\0'; + // + BotAI_BotInitialChat( bs, "joinedteam", teammate, NULL ); + trap_BotEnterChat( bs->cs, bs->client, CHAT_TEAM ); +} + +/* +================== +BotMatch_LeaveSubteam +================== +*/ +void BotMatch_LeaveSubteam( bot_state_t *bs, bot_match_t *match ) { + if ( !TeamPlayIsOn() ) { + return; + } + //if not addressed to this bot + if ( !BotAddressedToBot( bs, match ) ) { + return; + } + // + if ( strlen( bs->subteam ) ) { + BotAI_BotInitialChat( bs, "leftteam", bs->subteam, NULL ); + } //end if + trap_BotEnterChat( bs->cs, bs->client, CHAT_TEAM ); + strcpy( bs->subteam, "" ); +} + +/* +================== +BotMatch_LeaveSubteam +================== +*/ +void BotMatch_WhichTeam( bot_state_t *bs, bot_match_t *match ) { + if ( !TeamPlayIsOn() ) { + return; + } + //if not addressed to this bot + if ( !BotAddressedToBot( bs, match ) ) { + return; + } + // + if ( strlen( bs->subteam ) ) { + BotAI_BotInitialChat( bs, "inteam", bs->subteam, NULL ); + } else { + BotAI_BotInitialChat( bs, "noteam", NULL ); + } + trap_BotEnterChat( bs->cs, bs->client, CHAT_TEAM ); +} + +/* +================== +BotMatch_CheckPoint +================== +*/ +void BotMatch_CheckPoint( bot_state_t *bs, bot_match_t *match ) { + int areanum; + char buf[MAX_MESSAGE_SIZE]; + vec3_t position; + bot_waypoint_t *cp; + + if ( !TeamPlayIsOn() ) { + return; + } + // + trap_BotMatchVariable( match, POSITION, buf, MAX_MESSAGE_SIZE ); + VectorClear( position ); + //BotGPSToPosition(buf, position); + sscanf( buf, "%f %f %f", &position[0], &position[1], &position[2] ); + position[2] += 0.5; + areanum = BotPointAreaNum( position ); + if ( !areanum ) { + if ( BotAddressedToBot( bs, match ) ) { + BotAI_BotInitialChat( bs, "checkpoint_invalid", NULL ); + trap_BotEnterChat( bs->cs, bs->client, CHAT_TEAM ); + } + return; + } + // + trap_BotMatchVariable( match, NAME, buf, MAX_MESSAGE_SIZE ); + //check if there already exists a checkpoint with this name + cp = BotFindWayPoint( bs->checkpoints, buf ); + if ( cp ) { + if ( cp->next ) { + cp->next->prev = cp->prev; + } + if ( cp->prev ) { + cp->prev->next = cp->next; + } else { bs->checkpoints = cp->next;} + cp->inuse = qfalse; + } + //create a new check point + cp = BotCreateWayPoint( buf, position, areanum ); + //add the check point to the bot's known chech points + cp->next = bs->checkpoints; + if ( bs->checkpoints ) { + bs->checkpoints->prev = cp; + } + bs->checkpoints = cp; + // + if ( BotAddressedToBot( bs, match ) ) { + Com_sprintf( buf, sizeof( buf ), "%1.0f %1.0f %1.0f", cp->goal.origin[0], + cp->goal.origin[1], + cp->goal.origin[2] ); + + BotAI_BotInitialChat( bs, "checkpoint_confirm", cp->name, buf, NULL ); + trap_BotEnterChat( bs->cs, bs->client, CHAT_TEAM ); + } +} + +/* +================== +BotMatch_FormationSpace +================== +*/ +void BotMatch_FormationSpace( bot_state_t *bs, bot_match_t *match ) { + char buf[MAX_MESSAGE_SIZE]; + float space; + + if ( !TeamPlayIsOn() ) { + return; + } + //if not addressed to this bot + if ( !BotAddressedToBot( bs, match ) ) { + return; + } + // + trap_BotMatchVariable( match, NUMBER, buf, MAX_MESSAGE_SIZE ); + //if it's the distance in feet + if ( match->subtype & ST_FEET ) { + space = 0.3048 * 32 * atof( buf ); + } + //else it's in meters + else {space = 32 * atof( buf );} + //check if the formation intervening space is valid + if ( space < 48 || space > 500 ) { + space = 100; + } + bs->formation_dist = space; +} + +/* +================== +BotMatch_Dismiss +================== +*/ +void BotMatch_Dismiss( bot_state_t *bs, bot_match_t *match ) { + if ( !TeamPlayIsOn() ) { + return; + } + //if not addressed to this bot + if ( !BotAddressedToBot( bs, match ) ) { + return; + } + // + bs->ltgtype = 0; + bs->lead_time = 0; + // + BotAI_BotInitialChat( bs, "dismissed", NULL ); + trap_BotEnterChat( bs->cs, bs->client, CHAT_TEAM ); +} + +/* +================== +BotMatch_StartTeamLeaderShip +================== +*/ +void BotMatch_StartTeamLeaderShip( bot_state_t *bs, bot_match_t *match ) { + int client; + char teammate[MAX_MESSAGE_SIZE]; + + if ( !TeamPlayIsOn() ) { + return; + } + //if chats for him or herself + if ( match->subtype & ST_I ) { + //get the team mate that will be the team leader + trap_BotMatchVariable( match, NETNAME, teammate, sizeof( teammate ) ); + strncpy( bs->teamleader, teammate, sizeof( bs->teamleader ) ); + bs->teamleader[sizeof( bs->teamleader )] = '\0'; + } + //chats for someone else + else { + //get the team mate that will be the team leader + trap_BotMatchVariable( match, TEAMMATE, teammate, sizeof( teammate ) ); + client = FindClientByName( teammate ); + if ( client >= 0 ) { + ClientName( client, bs->teamleader, sizeof( bs->teamleader ) ); + } + } +} + +/* +================== +BotMatch_StopTeamLeaderShip +================== +*/ +void BotMatch_StopTeamLeaderShip( bot_state_t *bs, bot_match_t *match ) { + int client; + char teammate[MAX_MESSAGE_SIZE]; + char netname[MAX_MESSAGE_SIZE]; + + if ( !TeamPlayIsOn() ) { + return; + } + //get the team mate that stops being the team leader + trap_BotMatchVariable( match, TEAMMATE, teammate, sizeof( teammate ) ); + //if chats for him or herself + if ( match->subtype & ST_I ) { + trap_BotMatchVariable( match, NETNAME, netname, sizeof( netname ) ); + client = FindClientByName( netname ); + } + //chats for someone else + else { + client = FindClientByName( teammate ); + } //end else + if ( client >= 0 ) { + if ( !Q_stricmp( bs->teamleader, ClientName( client, netname, sizeof( netname ) ) ) ) { + bs->teamleader[0] = '\0'; + } + } +} + +/* +================== +BotMatch_WhoIsTeamLeader +================== +*/ +void BotMatch_WhoIsTeamLeader( bot_state_t *bs, bot_match_t *match ) { + char netname[MAX_MESSAGE_SIZE]; + + if ( !TeamPlayIsOn() ) { + return; + } + + ClientName( bs->client, netname, sizeof( netname ) ); + //if this bot IS the team leader + if ( !Q_stricmp( netname, bs->teamleader ) ) { + trap_EA_SayTeam( bs->client, "I'm the team leader\n" ); + } +} + +/* +================== +BotMatch_WhatAreYouDoing +================== +*/ +void BotMatch_WhatAreYouDoing( bot_state_t *bs, bot_match_t *match ) { + char netname[MAX_MESSAGE_SIZE]; + char goalname[MAX_MESSAGE_SIZE]; + + //if not addressed to this bot + if ( !BotAddressedToBot( bs, match ) ) { + return; + } + // + switch ( bs->ltgtype ) { + case LTG_TEAMHELP: + { + trap_BotMatchVariable( match, NETNAME, netname, sizeof( netname ) ); + EasyClientName( bs->teammate, netname, MAX_MESSAGE_SIZE ); + BotAI_BotInitialChat( bs, "helping", netname, NULL ); + break; + } + case LTG_TEAMACCOMPANY: + { + trap_BotMatchVariable( match, NETNAME, netname, sizeof( netname ) ); + EasyClientName( bs->teammate, netname, MAX_MESSAGE_SIZE ); + BotAI_BotInitialChat( bs, "accompanying", netname, NULL ); + break; + } + case LTG_DEFENDKEYAREA: + { + trap_BotGoalName( bs->teamgoal.number, goalname, sizeof( goalname ) ); + BotAI_BotInitialChat( bs, "defending", goalname, NULL ); + break; + } + case LTG_GETITEM: + { + trap_BotGoalName( bs->teamgoal.number, goalname, sizeof( goalname ) ); + BotAI_BotInitialChat( bs, "gettingitem", goalname, NULL ); + break; + } + case LTG_KILL: + { + ClientName( bs->teamgoal.entitynum, netname, sizeof( netname ) ); + BotAI_BotInitialChat( bs, "killing", netname, NULL ); + break; + } + case LTG_CAMP: + case LTG_CAMPORDER: + { + BotAI_BotInitialChat( bs, "camping", NULL ); + break; + } + case LTG_PATROL: + { + BotAI_BotInitialChat( bs, "patrolling", NULL ); + break; + } + case LTG_GETFLAG: + { + BotAI_BotInitialChat( bs, "capturingflag", NULL ); + break; + } + case LTG_RUSHBASE: + { + BotAI_BotInitialChat( bs, "rushingbase", NULL ); + break; + } + case LTG_RETURNFLAG: + { + BotAI_BotInitialChat( bs, "returningflag", NULL ); + break; + } + default: + { + BotAI_BotInitialChat( bs, "roaming", NULL ); + break; + } + } + //chat what the bot is doing + trap_BotEnterChat( bs->cs, bs->client, CHAT_TEAM ); +} + +/* +================== +BotMatch_WhatIsMyCommand +================== +*/ +void BotMatch_WhatIsMyCommand( bot_state_t *bs, bot_match_t *match ) { + char netname[MAX_NETNAME]; + + ClientName( bs->client, netname, sizeof( netname ) ); + if ( Q_stricmp( netname, bs->teamleader ) != 0 ) { + return; + } + bs->forceorders = qtrue; +} + +/* +================== +BotNearestVisibleItem +================== +*/ +float BotNearestVisibleItem( bot_state_t *bs, char *itemname, bot_goal_t *goal ) { + int i; + char name[64]; + bot_goal_t tmpgoal; + float dist, bestdist; + vec3_t dir; + bsp_trace_t trace; + + bestdist = 999999; + i = -1; + do { + i = trap_BotGetLevelItemGoal( i, itemname, &tmpgoal ); + trap_BotGoalName( tmpgoal.number, name, sizeof( name ) ); + if ( Q_stricmp( itemname, name ) != 0 ) { + continue; + } + VectorSubtract( tmpgoal.origin, bs->origin, dir ); + dist = VectorLength( dir ); + if ( dist < bestdist ) { + //trace from start to end + BotAI_Trace( &trace, bs->eye, NULL, NULL, tmpgoal.origin, bs->client, CONTENTS_SOLID | CONTENTS_PLAYERCLIP ); + if ( trace.fraction >= 1.0 ) { + bestdist = dist; + memcpy( goal, &tmpgoal, sizeof( bot_goal_t ) ); + } + } + } while ( i > 0 ); + return bestdist; +} + +/* +================== +BotMatch_WhereAreYou +================== +*/ +void BotMatch_WhereAreYou( bot_state_t *bs, bot_match_t *match ) { + float dist, bestdist; + int i, bestitem, redflagtt, blueflagtt, redtobluett; + bot_goal_t goal; + char *nearbyitems[] = { + "Shotgun", + "Grenade Launcher", + "Rocket Launcher", + "Plasmagun", + "Railgun", + "Lightning Gun", + "BFG10K", + "Quad Damage", + "Regeneration", + "Battle Suit", + "Speed", + "Invisibility", + "Flight", + "Armor", + "Heavy Armor", + "Red Flag", + "Blue Flag", + NULL + }; + // + if ( !TeamPlayIsOn() ) { + return; + } + //if not addressed to this bot + if ( !BotAddressedToBot( bs, match ) ) { + return; + } + + bestitem = -1; + bestdist = 999999; + for ( i = 0; nearbyitems[i]; i++ ) { + dist = BotNearestVisibleItem( bs, nearbyitems[i], &goal ); + if ( dist < bestdist ) { + bestdist = dist; + bestitem = i; + } + } + if ( bestitem != -1 ) { + if ( gametype == GT_CTF ) { + redflagtt = trap_AAS_AreaTravelTimeToGoalArea( bs->areanum, bs->origin, ctf_redflag.areanum, TFL_DEFAULT ); + blueflagtt = trap_AAS_AreaTravelTimeToGoalArea( bs->areanum, bs->origin, ctf_blueflag.areanum, TFL_DEFAULT ); + redtobluett = trap_AAS_AreaTravelTimeToGoalArea( ctf_redflag.areanum, ctf_redflag.origin, ctf_blueflag.areanum, TFL_DEFAULT ); + if ( redflagtt < ( redflagtt + blueflagtt ) * 0.4 ) { + BotAI_BotInitialChat( bs, "ctflocation", nearbyitems[bestitem], "red", NULL ); + } else if ( blueflagtt < ( redflagtt + blueflagtt ) * 0.4 ) { + BotAI_BotInitialChat( bs, "ctflocation", nearbyitems[bestitem], "blue", NULL ); + } else { + BotAI_BotInitialChat( bs, "location", nearbyitems[bestitem], NULL ); + } + } else { + BotAI_BotInitialChat( bs, "location", nearbyitems[bestitem], NULL ); + } + trap_BotEnterChat( bs->cs, bs->client, CHAT_TEAM ); + } +} + +/* +================== +BotMatch_LeadTheWay +================== +*/ +void BotMatch_LeadTheWay( bot_state_t *bs, bot_match_t *match ) { + aas_entityinfo_t entinfo; + char netname[MAX_MESSAGE_SIZE], teammate[MAX_MESSAGE_SIZE]; + int client, areanum, other; + + if ( !TeamPlayIsOn() ) { + return; + } + //if not addressed to this bot + if ( !BotAddressedToBot( bs, match ) ) { + return; + } + //if someone asks for someone else + if ( match->subtype & ST_SOMEONE ) { + //get the team mate name + trap_BotMatchVariable( match, TEAMMATE, teammate, sizeof( teammate ) ); + client = FindClientByName( teammate ); + //if this is the bot self + if ( client == bs->client ) { + other = qfalse; + } else if ( !BotSameTeam( bs, client ) ) { + //FIXME: say "I don't help the enemy" + return; + } else { + other = qtrue; + } + } else { + //get the netname + trap_BotMatchVariable( match, NETNAME, netname, sizeof( netname ) ); + client = ClientFromName( netname ); + other = qfalse; + } + //if the bot doesn't know who to help (FindClientByName returned -1) + if ( client < 0 ) { + BotAI_BotInitialChat( bs, "whois", netname, NULL ); + trap_BotEnterChat( bs->cs, bs->client, CHAT_TEAM ); + return; + } + // + bs->lead_teamgoal.entitynum = -1; + BotEntityInfo( client, &entinfo ); + //if info is valid (in PVS) + if ( entinfo.valid ) { + areanum = BotPointAreaNum( entinfo.origin ); + if ( areanum && trap_AAS_AreaReachability( areanum ) ) { + bs->lead_teamgoal.entitynum = client; + bs->lead_teamgoal.areanum = areanum; + VectorCopy( entinfo.origin, bs->lead_teamgoal.origin ); + VectorSet( bs->lead_teamgoal.mins, -8, -8, -8 ); + VectorSet( bs->lead_teamgoal.maxs, 8, 8, 8 ); + } + } + + if ( bs->teamgoal.entitynum < 0 ) { + if ( other ) { + BotAI_BotInitialChat( bs, "whereis", teammate, NULL ); + } else { BotAI_BotInitialChat( bs, "whereareyou", netname, NULL );} + trap_BotEnterChat( bs->cs, bs->client, CHAT_TEAM ); + return; + } + bs->lead_teammate = client; + bs->lead_time = trap_AAS_Time() + TEAM_LEAD_TIME; + bs->leadvisible_time = 0; + bs->leadmessage_time = -( trap_AAS_Time() + 2 * random() ); +} + +/* +================== +BotMatch_Kill +================== +*/ +void BotMatch_Kill( bot_state_t *bs, bot_match_t *match ) { + char enemy[MAX_MESSAGE_SIZE]; + int client; + + if ( !TeamPlayIsOn() ) { + return; + } + //if not addressed to this bot + if ( !BotAddressedToBot( bs, match ) ) { + return; + } + + trap_BotMatchVariable( match, ENEMY, enemy, sizeof( enemy ) ); + // + client = FindEnemyByName( bs, enemy ); + if ( client < 0 ) { + BotAI_BotInitialChat( bs, "whois", enemy, NULL ); + trap_BotEnterChat( bs->cs, bs->client, CHAT_TEAM ); + return; + } + bs->teamgoal.entitynum = client; + //set the time to send a message to the team mates + bs->teammessage_time = trap_AAS_Time() + 2 * random(); + //set the ltg type + bs->ltgtype = LTG_KILL; + //set the team goal time + bs->teamgoal_time = trap_AAS_Time() + TEAM_KILL_SOMEONE; +#ifdef DEBUG + BotPrintTeamGoal( bs ); +#endif //DEBUG +} + +/* +================== +BotMatch_CTF +================== +*/ +void BotMatch_CTF( bot_state_t *bs, bot_match_t *match ) { + + char flag[128], netname[MAX_NETNAME]; + + trap_BotMatchVariable( match, FLAG, flag, sizeof( flag ) ); + if ( match->subtype & ST_GOTFLAG ) { + if ( !Q_stricmp( flag, "red" ) ) { + bs->redflagstatus = 1; + if ( BotCTFTeam( bs ) == CTF_TEAM_BLUE ) { + trap_BotMatchVariable( match, NETNAME, netname, sizeof( netname ) ); + bs->flagcarrier = ClientFromName( netname ); + } + } else { + bs->blueflagstatus = 1; + if ( BotCTFTeam( bs ) == CTF_TEAM_RED ) { + trap_BotMatchVariable( match, NETNAME, netname, sizeof( netname ) ); + bs->flagcarrier = ClientFromName( netname ); + } + } + bs->flagstatuschanged = 1; + } else if ( match->subtype & ST_CAPTUREDFLAG ) { + bs->redflagstatus = 0; + bs->blueflagstatus = 0; + bs->flagcarrier = 0; + bs->flagstatuschanged = 1; + } else if ( match->subtype & ST_RETURNEDFLAG ) { + if ( !Q_stricmp( flag, "red" ) ) { + bs->redflagstatus = 0; + } else { bs->blueflagstatus = 0;} + bs->flagstatuschanged = 1; + } +} + +/* +================== +BotMatchMessage +================== +*/ +int BotMatchMessage( bot_state_t *bs, char *message ) { + bot_match_t match; + + match.type = 0; + //if it is an unknown message + if ( !trap_BotFindMatch( message, &match, MTCONTEXT_ENTERGAME + | MTCONTEXT_INITIALTEAMCHAT + | MTCONTEXT_CTF ) ) { + return qfalse; + } + //react to the found message + switch ( match.type ) { + case MSG_HELP: //someone calling for help + case MSG_ACCOMPANY: //someone calling for company + { + BotMatch_HelpAccompany( bs, &match ); + break; + } + case MSG_DEFENDKEYAREA: //teamplay defend a key area + { + BotMatch_DefendKeyArea( bs, &match ); + break; + } + case MSG_CAMP: //camp somewhere + { + BotMatch_Camp( bs, &match ); + break; + } + case MSG_PATROL: //patrol between several key areas + { + BotMatch_Patrol( bs, &match ); + break; + } +#ifdef CTF + case MSG_GETFLAG: //ctf get the enemy flag + { + BotMatch_GetFlag( bs, &match ); + break; + } + case MSG_RUSHBASE: //ctf rush to the base + { + BotMatch_RushBase( bs, &match ); + break; + } + case MSG_RETURNFLAG: + { + BotMatch_ReturnFlag( bs, &match ); + break; + } +#endif //CTF + case MSG_GETITEM: + { + BotMatch_GetItem( bs, &match ); + break; + } + case MSG_JOINSUBTEAM: //join a sub team + { + BotMatch_JoinSubteam( bs, &match ); + break; + } + case MSG_LEAVESUBTEAM: //leave a sub team + { + BotMatch_LeaveSubteam( bs, &match ); + break; + } + case MSG_WHICHTEAM: + { + BotMatch_WhichTeam( bs, &match ); + break; + } + case MSG_CHECKPOINT: //remember a check point + { + BotMatch_CheckPoint( bs, &match ); + break; + } + case MSG_CREATENEWFORMATION: //start the creation of a new formation + { + trap_EA_SayTeam( bs->client, "the part of my brain to create formations has been damaged" ); + break; + } + case MSG_FORMATIONPOSITION: //tell someone his/her position in the formation + { + trap_EA_SayTeam( bs->client, "the part of my brain to create formations has been damaged" ); + break; + } + case MSG_FORMATIONSPACE: //set the formation space + { + BotMatch_FormationSpace( bs, &match ); + break; + } + case MSG_DOFORMATION: //form a certain formation + { + break; + } + case MSG_DISMISS: //dismiss someone + { + BotMatch_Dismiss( bs, &match ); + break; + } + case MSG_STARTTEAMLEADERSHIP: //someone will become the team leader + { + BotMatch_StartTeamLeaderShip( bs, &match ); + break; + } + case MSG_STOPTEAMLEADERSHIP: //someone will stop being the team leader + { + BotMatch_StopTeamLeaderShip( bs, &match ); + break; + } + case MSG_WHOISTEAMLAEDER: + { + BotMatch_WhoIsTeamLeader( bs, &match ); + break; + } + case MSG_WHATAREYOUDOING: //ask a bot what he/she is doing + { + BotMatch_WhatAreYouDoing( bs, &match ); + break; + } + case MSG_WHATISMYCOMMAND: + { + BotMatch_WhatIsMyCommand( bs, &match ); + break; + } + case MSG_WHEREAREYOU: + { + BotMatch_WhereAreYou( bs, &match ); + break; + } + case MSG_LEADTHEWAY: + { + BotMatch_LeadTheWay( bs, &match ); + break; + } + case MSG_KILL: + { + BotMatch_Kill( bs, &match ); + break; + } + case MSG_ENTERGAME: //someone entered the game + { + //NOTE: eliza chats will catch this + //BotMatchVariable(&match, NETNAME, netname); + //Com_sprintf(buf, sizeof(buf), "heya %s", netname); + //EA_Say(bs->client, buf); + break; + } + case MSG_CTF: + { + BotMatch_CTF( bs, &match ); + break; + } + case MSG_WAIT: + { + break; + } + default: + { + BotAI_Print( PRT_MESSAGE, "unknown match type\n" ); + break; + } + } + return qtrue; +} diff --git a/Projects/Android/jni/rtcw/src/botai/ai_cmd.h b/Projects/Android/jni/rtcw/src/botai/ai_cmd.h new file mode 100644 index 0000000..eb91c36 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/botai/ai_cmd.h @@ -0,0 +1,40 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +/***************************************************************************** + * name: ai_cmd.h + * + * desc: Quake3 bot AI + * + * + *****************************************************************************/ + +int BotMatchMessage( bot_state_t *bs, char *message ); +void BotPrintTeamGoal( bot_state_t *bs ); + diff --git a/Projects/Android/jni/rtcw/src/botai/ai_dmnet.c b/Projects/Android/jni/rtcw/src/botai/ai_dmnet.c new file mode 100644 index 0000000..1b19160 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/botai/ai_dmnet.c @@ -0,0 +1,2045 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +/***************************************************************************** + * name: ai_dmnet.c + * + * desc: Quake3 bot AI + * + * + *****************************************************************************/ + +#include "../game/g_local.h" +#include "../game/botlib.h" +#include "../game/be_aas.h" +#include "../game/be_ea.h" +#include "../game/be_ai_char.h" +#include "../game/be_ai_chat.h" +#include "../game/be_ai_gen.h" +#include "../game/be_ai_goal.h" +#include "../game/be_ai_move.h" +#include "../game/be_ai_weap.h" +#include "../botai/botai.h" +// +#include "ai_main.h" +#include "ai_dmq3.h" +#include "ai_chat.h" +#include "ai_cmd.h" +#include "ai_dmnet.h" +//data file headers +#include "chars.h" //characteristics +#include "inv.h" //indexes into the inventory +#include "syn.h" //synonyms +#include "match.h" //string matching types and vars + +//goal flag, see be_ai_goal.h for the other GFL_* +#define GFL_AIR 16 + +int numnodeswitches; +char nodeswitch[MAX_NODESWITCHES + 1][144]; + +#define LOOKAHEAD_DISTANCE 300 + +/* +================== +BotResetNodeSwitches +================== +*/ +void BotResetNodeSwitches( void ) { + numnodeswitches = 0; +} + +/* +================== +BotDumpNodeSwitches +================== +*/ +void BotDumpNodeSwitches( bot_state_t *bs ) { + int i; + char netname[MAX_NETNAME]; + + ClientName( bs->client, netname, sizeof( netname ) ); + BotAI_Print( PRT_MESSAGE, "%s at %1.1f switched more than %d AI nodes\n", netname, trap_AAS_Time(), MAX_NODESWITCHES ); + for ( i = 0; i < numnodeswitches; i++ ) { + BotAI_Print( PRT_MESSAGE, nodeswitch[i] ); + } + BotAI_Print( PRT_FATAL, "" ); +} + +/* +================== +BotRecordNodeSwitch +================== +*/ +void BotRecordNodeSwitch( bot_state_t *bs, char *node, char *str ) { + char netname[MAX_NETNAME]; + + ClientName( bs->client, netname, sizeof( netname ) ); + Com_sprintf( nodeswitch[numnodeswitches], 144, "%s at %2.1f entered %s: %s\n", netname, trap_AAS_Time(), node, str ); +#ifdef DEBUG + if ( 0 ) { + BotAI_Print( PRT_MESSAGE, nodeswitch[numnodeswitches] ); + } +#endif //DEBUG + numnodeswitches++; +} + +/* +================== +BotGetAirGoal +================== +*/ +int BotGetAirGoal( bot_state_t *bs, bot_goal_t *goal ) { + bsp_trace_t bsptrace; + vec3_t end, mins = {-15, -15, -2}, maxs = {15, 15, 2}; + int areanum; + + //trace up until we hit solid + VectorCopy( bs->origin, end ); + end[2] += 1000; + BotAI_Trace( &bsptrace, bs->origin, mins, maxs, end, bs->entitynum, CONTENTS_SOLID | CONTENTS_PLAYERCLIP ); + //trace down until we hit water + VectorCopy( bsptrace.endpos, end ); + BotAI_Trace( &bsptrace, end, mins, maxs, bs->origin, bs->entitynum, CONTENTS_WATER | CONTENTS_SLIME | CONTENTS_LAVA ); + //if we found the water surface + if ( bsptrace.fraction > 0 ) { + areanum = BotPointAreaNum( bsptrace.endpos ); + if ( areanum ) { + VectorCopy( bsptrace.endpos, goal->origin ); + goal->origin[2] -= 2; + goal->areanum = areanum; + goal->mins[0] = -15; + goal->mins[1] = -15; + goal->mins[2] = -1; + goal->maxs[0] = 15; + goal->maxs[1] = 15; + goal->maxs[2] = 1; + goal->flags = GFL_AIR; + goal->number = 0; + goal->iteminfo = 0; + goal->entitynum = 0; + return qtrue; + } + } + return qfalse; +} + +/* +================== +BotGoForAir +================== +*/ +int BotGoForAir( bot_state_t *bs, int tfl, bot_goal_t *ltg, float range ) { + bot_goal_t goal; + + //if the bot needs air + if ( bs->lastair_time < trap_AAS_Time() - 6 ) { + // +#ifdef DEBUG + //BotAI_Print(PRT_MESSAGE, "going for air\n"); +#endif //DEBUG + //if we can find an air goal + if ( BotGetAirGoal( bs, &goal ) ) { + trap_BotPushGoal( bs->gs, &goal ); + return qtrue; + } else { + //get a nearby goal outside the water + while ( trap_BotChooseNBGItem( bs->gs, bs->origin, bs->inventory, tfl, ltg, range ) ) { + trap_BotGetTopGoal( bs->gs, &goal ); + //if the goal is not in water + if ( !( trap_AAS_PointContents( goal.origin ) & ( CONTENTS_WATER | CONTENTS_SLIME | CONTENTS_LAVA ) ) ) { + return qtrue; + } + trap_BotPopGoal( bs->gs ); + } + trap_BotResetAvoidGoals( bs->gs ); + } + } + return qfalse; +} + +/* +================== +BotNearbyGoal +================== +*/ +int BotNearbyGoal( bot_state_t *bs, int tfl, bot_goal_t *ltg, float range ) { + int ret; + + if ( BotGoForAir( bs, tfl, ltg, range ) ) { + return qtrue; + } + // + ret = trap_BotChooseNBGItem( bs->gs, bs->origin, bs->inventory, tfl, ltg, range ); + /* + if (ret) + { + char buf[128]; + //get the goal at the top of the stack + trap_BotGetTopGoal(bs->gs, &goal); + trap_BotGoalName(goal.number, buf, sizeof(buf)); + BotAI_Print(PRT_MESSAGE, "%1.1f: new nearby goal %s\n", trap_AAS_Time(), buf); + } + */ + return ret; +} + +/* +================== +BotReachedGoal +================== +*/ +int BotReachedGoal( bot_state_t *bs, bot_goal_t *goal ) { + if ( goal->flags & GFL_ITEM ) { + //if touching the goal + if ( trap_BotTouchingGoal( bs->origin, goal ) ) { + return qtrue; + } + //if the goal isn't there + if ( trap_BotItemGoalInVisButNotVisible( bs->entitynum, bs->eye, bs->viewangles, goal ) ) { + return qtrue; + } + //if in the goal area and below or above the goal and not swimming + if ( bs->areanum == goal->areanum ) { + if ( bs->origin[0] > goal->origin[0] + goal->mins[0] && bs->origin[0] < goal->origin[0] + goal->maxs[0] ) { + if ( bs->origin[1] > goal->origin[1] + goal->mins[1] && bs->origin[1] < goal->origin[1] + goal->maxs[1] ) { + if ( !trap_AAS_Swimming( bs->origin ) ) { + return qtrue; + } + } + } + } + } else if ( goal->flags & GFL_AIR ) { + //if touching the goal + if ( trap_BotTouchingGoal( bs->origin, goal ) ) { + return qtrue; + } + //if the bot got air + if ( bs->lastair_time > trap_AAS_Time() - 1 ) { + return qtrue; + } + } else { + //if touching the goal + if ( trap_BotTouchingGoal( bs->origin, goal ) ) { + return qtrue; + } + } + return qfalse; +} + +/* +================== +BotGetItemLongTermGoal +================== +*/ +int BotGetItemLongTermGoal( bot_state_t *bs, int tfl, bot_goal_t *goal ) { + //if the bot has no goal + if ( !trap_BotGetTopGoal( bs->gs, goal ) ) { + //BotAI_Print(PRT_MESSAGE, "no ltg on stack\n"); + bs->ltg_time = 0; + } + //if the bot touches the current goal + else if ( BotReachedGoal( bs, goal ) ) { + BotChooseWeapon( bs ); + bs->ltg_time = 0; + } + //if it is time to find a new long term goal + if ( bs->ltg_time < trap_AAS_Time() ) { + //pop the current goal from the stack + trap_BotPopGoal( bs->gs ); + //BotAI_Print(PRT_MESSAGE, "%s: choosing new ltg\n", ClientName(bs->client, netname, sizeof(netname))); + //choose a new goal + //BotAI_Print(PRT_MESSAGE, "%6.1f client %d: BotChooseLTGItem\n", trap_AAS_Time(), bs->client); + if ( trap_BotChooseLTGItem( bs->gs, bs->origin, bs->inventory, tfl ) ) { + /* + char buf[128]; + //get the goal at the top of the stack + trap_BotGetTopGoal(bs->gs, goal); + trap_BotGoalName(goal->number, buf, sizeof(buf)); + BotAI_Print(PRT_MESSAGE, "%1.1f: new long term goal %s\n", trap_AAS_Time(), buf); + */ + bs->ltg_time = trap_AAS_Time() + 20; + } else { //the bot gets sorta stuck with all the avoid timings, shouldn't happen though + // +#ifdef DEBUG + char netname[128]; + + BotAI_Print( PRT_MESSAGE, "%s: no valid ltg (probably stuck)\n", ClientName( bs->client, netname, sizeof( netname ) ) ); +#endif + //trap_BotDumpAvoidGoals(bs->gs); + //reset the avoid goals and the avoid reach + trap_BotResetAvoidGoals( bs->gs ); + trap_BotResetAvoidReach( bs->ms ); + } + //get the goal at the top of the stack + return trap_BotGetTopGoal( bs->gs, goal ); + } + return qtrue; +} + +/* +================== +BotGetLongTermGoal + +we could also create a seperate AI node for every long term goal type +however this saves us a lot of code +================== +*/ +int BotGetLongTermGoal( bot_state_t *bs, int tfl, int retreat, bot_goal_t *goal ) { + vec3_t target, dir; + char netname[MAX_NETNAME]; + char buf[MAX_MESSAGE_SIZE]; + int areanum; + float croucher; + aas_entityinfo_t entinfo; + bot_waypoint_t *wp; + + if ( bs->ltgtype == LTG_TEAMHELP && !retreat ) { + //check for bot typing status message + if ( bs->teammessage_time && bs->teammessage_time < trap_AAS_Time() ) { + BotAI_BotInitialChat( bs, "help_start", EasyClientName( bs->teammate, netname, sizeof( netname ) ), NULL ); + trap_BotEnterChat( bs->cs, bs->client, CHAT_TEAM ); + bs->teammessage_time = 0; + } + //if trying to help the team mate for more than a minute + if ( bs->teamgoal_time < trap_AAS_Time() ) { + bs->ltgtype = 0; + } + //if the team mate IS visible for quite some time + if ( bs->teammatevisible_time < trap_AAS_Time() - 10 ) { + bs->ltgtype = 0; + } + //get entity information of the companion + BotEntityInfo( bs->teammate, &entinfo ); + //if the team mate is visible + if ( BotEntityVisible( bs->entitynum, bs->eye, bs->viewangles, 360, bs->teammate ) ) { + //if close just stand still there + VectorSubtract( entinfo.origin, bs->origin, dir ); + if ( VectorLength( dir ) < 100 ) { + trap_BotResetAvoidReach( bs->ms ); + return qfalse; + } + } else { + //last time the bot was NOT visible + bs->teammatevisible_time = trap_AAS_Time(); + } + //if the entity information is valid (entity in PVS) + if ( entinfo.valid ) { + areanum = BotPointAreaNum( entinfo.origin ); + if ( areanum && trap_AAS_AreaReachability( areanum ) ) { + //update team goal + bs->teamgoal.entitynum = bs->teammate; + bs->teamgoal.areanum = areanum; + VectorCopy( entinfo.origin, bs->teamgoal.origin ); + VectorSet( bs->teamgoal.mins, -8, -8, -8 ); + VectorSet( bs->teamgoal.maxs, 8, 8, 8 ); + } + } + memcpy( goal, &bs->teamgoal, sizeof( bot_goal_t ) ); + return qtrue; + } + //if the bot accompanies someone + if ( bs->ltgtype == LTG_TEAMACCOMPANY && !retreat ) { + //check for bot typing status message + if ( bs->teammessage_time && bs->teammessage_time < trap_AAS_Time() ) { + BotAI_BotInitialChat( bs, "accompany_start", EasyClientName( bs->teammate, netname, sizeof( netname ) ), NULL ); + trap_BotEnterChat( bs->cs, bs->client, CHAT_TEAM ); + bs->teammessage_time = 0; + } + //if accompanying the companion for 3 minutes + if ( bs->teamgoal_time < trap_AAS_Time() ) { + BotAI_BotInitialChat( bs, "accompany_stop", EasyClientName( bs->teammate, netname, sizeof( netname ) ), NULL ); + trap_BotEnterChat( bs->cs, bs->client, CHAT_TEAM ); + bs->ltgtype = 0; + } + //get entity information of the companion + BotEntityInfo( bs->teammate, &entinfo ); + //if the companion is visible + if ( BotEntityVisible( bs->entitynum, bs->eye, bs->viewangles, 360, bs->teammate ) ) { + //update visible time + bs->teammatevisible_time = trap_AAS_Time(); + VectorSubtract( entinfo.origin, bs->origin, dir ); + if ( VectorLength( dir ) < bs->formation_dist ) { + //check if the bot wants to crouch + //don't crouch if crouched less than 5 seconds ago + if ( bs->attackcrouch_time < trap_AAS_Time() - 5 ) { + croucher = trap_Characteristic_BFloat( bs->character, CHARACTERISTIC_CROUCHER, 0, 1 ); + if ( random() < bs->thinktime * croucher ) { + bs->attackcrouch_time = trap_AAS_Time() + 5 + croucher * 15; + } + } + //don't crouch when swimming + if ( trap_AAS_Swimming( bs->origin ) ) { + bs->attackcrouch_time = trap_AAS_Time() - 1; + } + //if not arrived yet or arived some time ago + if ( bs->arrive_time < trap_AAS_Time() - 2 ) { + //if not arrived yet + if ( !bs->arrive_time ) { + trap_EA_Gesture( bs->client ); + BotAI_BotInitialChat( bs, "accompany_arrive", EasyClientName( bs->teammate, netname, sizeof( netname ) ), NULL ); + trap_BotEnterChat( bs->cs, bs->client, CHAT_TEAM ); + bs->arrive_time = trap_AAS_Time(); + } + //if the bot wants to crouch + else if ( bs->attackcrouch_time > trap_AAS_Time() ) { + trap_EA_Crouch( bs->client ); + } + //else do some model taunts + else if ( random() < bs->thinktime * 0.3 ) { + //do a gesture :) + trap_EA_Gesture( bs->client ); + } + } + //if just arrived look at the companion + if ( bs->arrive_time > trap_AAS_Time() - 2 ) { + VectorSubtract( entinfo.origin, bs->origin, dir ); + vectoangles( dir, bs->ideal_viewangles ); + bs->ideal_viewangles[2] *= 0.5; + } + //else look strategically around for enemies + else if ( random() < bs->thinktime * 0.8 ) { + BotRoamGoal( bs, target ); + VectorSubtract( target, bs->origin, dir ); + vectoangles( dir, bs->ideal_viewangles ); + bs->ideal_viewangles[2] *= 0.5; + } + //check if the bot wants to go for air + if ( BotGoForAir( bs, bs->tfl, &bs->teamgoal, 400 ) ) { + trap_BotResetLastAvoidReach( bs->ms ); + //get the goal at the top of the stack + //trap_BotGetTopGoal(bs->gs, &tmpgoal); + //trap_BotGoalName(tmpgoal.number, buf, 144); + //BotAI_Print(PRT_MESSAGE, "new nearby goal %s\n", buf); + //time the bot gets to pick up the nearby goal item + bs->nbg_time = trap_AAS_Time() + 8; + AIEnter_Seek_NBG( bs ); + return qfalse; + } + // + trap_BotResetAvoidReach( bs->ms ); + return qfalse; + } + } + //if the entity information is valid (entity in PVS) + if ( entinfo.valid ) { + areanum = BotPointAreaNum( entinfo.origin ); + if ( areanum && trap_AAS_AreaReachability( areanum ) ) { + //update team goal so bot will accompany + bs->teamgoal.entitynum = bs->teammate; + bs->teamgoal.areanum = areanum; + VectorCopy( entinfo.origin, bs->teamgoal.origin ); + VectorSet( bs->teamgoal.mins, -8, -8, -8 ); + VectorSet( bs->teamgoal.maxs, 8, 8, 8 ); + } + } + //the goal the bot should go for + memcpy( goal, &bs->teamgoal, sizeof( bot_goal_t ) ); + //if the companion is NOT visible for too long + if ( bs->teammatevisible_time < trap_AAS_Time() - 60 ) { + BotAI_BotInitialChat( bs, "accompany_cannotfind", EasyClientName( bs->teammate, netname, sizeof( netname ) ), NULL ); + trap_BotEnterChat( bs->cs, bs->client, CHAT_TEAM ); + bs->ltgtype = 0; + } + return qtrue; + } + // + if ( bs->ltgtype == LTG_DEFENDKEYAREA ) { + if ( trap_AAS_AreaTravelTimeToGoalArea( bs->areanum, bs->origin, + bs->teamgoal.areanum, TFL_DEFAULT ) > bs->defendaway_range ) { + bs->defendaway_time = 0; + } + } + //if defending a key area + if ( bs->ltgtype == LTG_DEFENDKEYAREA && !retreat && + bs->defendaway_time < trap_AAS_Time() ) { + //check for bot typing status message + if ( bs->teammessage_time && bs->teammessage_time < trap_AAS_Time() ) { + trap_BotGoalName( bs->teamgoal.number, buf, sizeof( buf ) ); + BotAI_BotInitialChat( bs, "defend_start", buf, NULL ); + trap_BotEnterChat( bs->cs, bs->client, CHAT_TEAM ); + bs->teammessage_time = 0; + } + //set the bot goal + memcpy( goal, &bs->teamgoal, sizeof( bot_goal_t ) ); + //stop after 2 minutes + if ( bs->teamgoal_time < trap_AAS_Time() ) { + trap_BotGoalName( bs->teamgoal.number, buf, sizeof( buf ) ); + BotAI_BotInitialChat( bs, "defend_stop", buf, NULL ); + trap_BotEnterChat( bs->cs, bs->client, CHAT_TEAM ); + bs->ltgtype = 0; + } + //if very close... go away for some time + VectorSubtract( goal->origin, bs->origin, dir ); + if ( VectorLength( dir ) < 70 ) { + trap_BotResetAvoidReach( bs->ms ); + bs->defendaway_time = trap_AAS_Time() + 2 + 5 * random(); + bs->defendaway_range = 300; + } + return qtrue; + } + //going to kill someone + if ( bs->ltgtype == LTG_KILL && !retreat ) { + //check for bot typing status message + if ( bs->teammessage_time && bs->teammessage_time < trap_AAS_Time() ) { + EasyClientName( bs->teamgoal.entitynum, buf, sizeof( buf ) ); + BotAI_BotInitialChat( bs, "kill_start", buf, NULL ); + trap_BotEnterChat( bs->cs, bs->client, CHAT_TEAM ); + bs->teammessage_time = 0; + } + // + if ( bs->lastkilledplayer == bs->teamgoal.entitynum ) { + EasyClientName( bs->teamgoal.entitynum, buf, sizeof( buf ) ); + BotAI_BotInitialChat( bs, "kill_done", buf, NULL ); + trap_BotEnterChat( bs->cs, bs->client, CHAT_TEAM ); + bs->lastkilledplayer = -1; + bs->ltgtype = 0; + } + // + if ( bs->teamgoal_time < trap_AAS_Time() ) { + bs->ltgtype = 0; + } + //just roam around + return BotGetItemLongTermGoal( bs, tfl, goal ); + } + //get an item + if ( bs->ltgtype == LTG_GETITEM && !retreat ) { + //check for bot typing status message + if ( bs->teammessage_time && bs->teammessage_time < trap_AAS_Time() ) { + trap_BotGoalName( bs->teamgoal.number, buf, sizeof( buf ) ); + BotAI_BotInitialChat( bs, "getitem_start", buf, NULL ); + trap_BotEnterChat( bs->cs, bs->client, CHAT_TEAM ); + bs->teammessage_time = 0; + } + //set the bot goal + memcpy( goal, &bs->teamgoal, sizeof( bot_goal_t ) ); + //stop after some time + if ( bs->teamgoal_time < trap_AAS_Time() ) { + bs->ltgtype = 0; + } + // + if ( trap_BotItemGoalInVisButNotVisible( bs->entitynum, bs->eye, bs->viewangles, goal ) ) { + trap_BotGoalName( bs->teamgoal.number, buf, sizeof( buf ) ); + BotAI_BotInitialChat( bs, "getitem_notthere", buf, NULL ); + trap_BotEnterChat( bs->cs, bs->client, CHAT_TEAM ); + bs->ltgtype = 0; + } else if ( BotReachedGoal( bs, goal ) ) { + trap_BotGoalName( bs->teamgoal.number, buf, sizeof( buf ) ); + BotAI_BotInitialChat( bs, "getitem_gotit", buf, NULL ); + trap_BotEnterChat( bs->cs, bs->client, CHAT_TEAM ); + bs->ltgtype = 0; + } + return qtrue; + } + //if camping somewhere + if ( ( bs->ltgtype == LTG_CAMP || bs->ltgtype == LTG_CAMPORDER ) && !retreat ) { + //check for bot typing status message + if ( bs->teammessage_time && bs->teammessage_time < trap_AAS_Time() ) { + if ( bs->ltgtype == LTG_CAMPORDER ) { + BotAI_BotInitialChat( bs, "camp_start", EasyClientName( bs->teammate, netname, sizeof( netname ) ), NULL ); + trap_BotEnterChat( bs->cs, bs->client, CHAT_TEAM ); + } + bs->teammessage_time = 0; + } + //set the bot goal + memcpy( goal, &bs->teamgoal, sizeof( bot_goal_t ) ); + // + if ( bs->teamgoal_time < trap_AAS_Time() ) { + if ( bs->ltgtype == LTG_CAMPORDER ) { + BotAI_BotInitialChat( bs, "camp_stop", NULL ); + trap_BotEnterChat( bs->cs, bs->client, CHAT_TEAM ); + } + bs->ltgtype = 0; + } + //if really near the camp spot + VectorSubtract( goal->origin, bs->origin, dir ); + if ( VectorLength( dir ) < 60 ) { + //if not arrived yet + if ( !bs->arrive_time ) { + if ( bs->ltgtype == LTG_CAMPORDER ) { + BotAI_BotInitialChat( bs, "camp_arrive", EasyClientName( bs->teammate, netname, sizeof( netname ) ), NULL ); + trap_BotEnterChat( bs->cs, bs->client, CHAT_TEAM ); + } + bs->arrive_time = trap_AAS_Time(); + } + //look strategically around for enemies + if ( random() < bs->thinktime * 0.8 ) { + BotRoamGoal( bs, target ); + VectorSubtract( target, bs->origin, dir ); + vectoangles( dir, bs->ideal_viewangles ); + bs->ideal_viewangles[2] *= 0.5; + } + //check if the bot wants to crouch + //don't crouch if crouched less than 5 seconds ago + if ( bs->attackcrouch_time < trap_AAS_Time() - 5 ) { + croucher = trap_Characteristic_BFloat( bs->character, CHARACTERISTIC_CROUCHER, 0, 1 ); + if ( random() < bs->thinktime * croucher ) { + bs->attackcrouch_time = trap_AAS_Time() + 5 + croucher * 15; + } + } + //if the bot wants to crouch + if ( bs->attackcrouch_time > trap_AAS_Time() ) { + trap_EA_Crouch( bs->client ); + } + //don't crouch when swimming + if ( trap_AAS_Swimming( bs->origin ) ) { + bs->attackcrouch_time = trap_AAS_Time() - 1; + } + //make sure the bot is not gonna drown + if ( trap_PointContents( bs->eye,bs->entitynum ) & ( CONTENTS_WATER | CONTENTS_SLIME | CONTENTS_LAVA ) ) { + if ( bs->ltgtype == LTG_CAMPORDER ) { + BotAI_BotInitialChat( bs, "camp_stop", NULL ); + trap_BotEnterChat( bs->cs, bs->client, CHAT_TEAM ); + } + bs->ltgtype = 0; + } + // + if ( bs->camp_range > 0 ) { + //FIXME: move around a bit + } + // + trap_BotResetAvoidReach( bs->ms ); + return qfalse; + } + return qtrue; + } + //patrolling along several waypoints + if ( bs->ltgtype == LTG_PATROL && !retreat ) { + //check for bot typing status message + if ( bs->teammessage_time && bs->teammessage_time < trap_AAS_Time() ) { + strcpy( buf, "" ); + for ( wp = bs->patrolpoints; wp; wp = wp->next ) { + strcat( buf, wp->name ); + if ( wp->next ) { + strcat( buf, " to " ); + } + } + BotAI_BotInitialChat( bs, "patrol_start", buf, NULL ); + trap_BotEnterChat( bs->cs, bs->client, CHAT_TEAM ); + bs->teammessage_time = 0; + } + // + if ( !bs->curpatrolpoint ) { + bs->ltgtype = 0; + return qfalse; + } + //if the bot touches the current goal + if ( trap_BotTouchingGoal( bs->origin, &bs->curpatrolpoint->goal ) ) { + if ( bs->patrolflags & PATROL_BACK ) { + if ( bs->curpatrolpoint->prev ) { + bs->curpatrolpoint = bs->curpatrolpoint->prev; + } else { + bs->curpatrolpoint = bs->curpatrolpoint->next; + bs->patrolflags &= ~PATROL_BACK; + } + } else { + if ( bs->curpatrolpoint->next ) { + bs->curpatrolpoint = bs->curpatrolpoint->next; + } else { + bs->curpatrolpoint = bs->curpatrolpoint->prev; + bs->patrolflags |= PATROL_BACK; + } + } + } + //stop after 5 minutes + if ( bs->teamgoal_time < trap_AAS_Time() ) { + BotAI_BotInitialChat( bs, "patrol_stop", NULL ); + trap_BotEnterChat( bs->cs, bs->client, CHAT_TEAM ); + bs->ltgtype = 0; + } + if ( !bs->curpatrolpoint ) { + bs->ltgtype = 0; + return qfalse; + } + memcpy( goal, &bs->curpatrolpoint->goal, sizeof( bot_goal_t ) ); + return qtrue; + } +#ifdef CTF + //if going for enemy flag + if ( bs->ltgtype == LTG_GETFLAG ) { + //check for bot typing status message + if ( bs->teammessage_time && bs->teammessage_time < trap_AAS_Time() ) { + BotAI_BotInitialChat( bs, "captureflag_start", NULL ); + trap_BotEnterChat( bs->cs, bs->client, CHAT_TEAM ); + bs->teammessage_time = 0; + } + // + switch ( BotCTFTeam( bs ) ) { + case CTF_TEAM_RED: *goal = ctf_blueflag; break; + case CTF_TEAM_BLUE: *goal = ctf_redflag; break; + default: bs->ltgtype = 0; return qfalse; + } + //if touching the flag + if ( trap_BotTouchingGoal( bs->origin, goal ) ) { + bs->ltgtype = 0; + } + //stop after 3 minutes + if ( bs->teamgoal_time < trap_AAS_Time() ) { +#ifdef DEBUG + BotAI_Print( PRT_MESSAGE, "%s: I quit getting the flag\n", ClientName( bs->client, netname, sizeof( netname ) ) ); +#endif //DEBUG + bs->ltgtype = 0; + } + return qtrue; + } + //if rushing to the base + if ( bs->ltgtype == LTG_RUSHBASE && bs->rushbaseaway_time < trap_AAS_Time() ) { + switch ( BotCTFTeam( bs ) ) { + case CTF_TEAM_RED: *goal = ctf_redflag; break; + case CTF_TEAM_BLUE: *goal = ctf_blueflag; break; + default: bs->ltgtype = 0; return qfalse; + } + //quit rushing after 2 minutes + if ( bs->teamgoal_time < trap_AAS_Time() ) { + bs->ltgtype = 0; + } + //if touching the base flag the bot should loose the enemy flag + if ( trap_BotTouchingGoal( bs->origin, goal ) ) { + //if the bot is still carrying the enemy flag then the + //base flag is gone, now just walk near the base a bit + if ( BotCTFCarryingFlag( bs ) ) { + trap_BotResetAvoidReach( bs->ms ); + bs->rushbaseaway_time = trap_AAS_Time() + 5 + 10 * random(); + //FIXME: add chat to tell the others to get back the flag + } else { + bs->ltgtype = 0; + } + } + return qtrue; + } + //returning flag + if ( bs->ltgtype == LTG_RETURNFLAG ) { + //check for bot typing status message + if ( bs->teammessage_time && bs->teammessage_time < trap_AAS_Time() ) { + EasyClientName( bs->teamgoal.entitynum, buf, sizeof( buf ) ); + BotAI_BotInitialChat( bs, "returnflag_start", buf, NULL ); + trap_BotEnterChat( bs->cs, bs->client, CHAT_TEAM ); + bs->teammessage_time = 0; + } + // + if ( bs->teamgoal_time < trap_AAS_Time() ) { + bs->ltgtype = 0; + } + //just roam around + return BotGetItemLongTermGoal( bs, tfl, goal ); + } +#endif //CTF + //normal goal stuff + return BotGetItemLongTermGoal( bs, tfl, goal ); +} + +/* +================== +BotLongTermGoal +================== +*/ +int BotLongTermGoal( bot_state_t *bs, int tfl, int retreat, bot_goal_t *goal ) { + aas_entityinfo_t entinfo; + char teammate[MAX_MESSAGE_SIZE]; + float dist; + int areanum; + vec3_t dir; + + //FIXME: also have air long term goals? + // + //if the bot is leading someone and not retreating + if ( bs->lead_time > 0 && !retreat ) { + if ( bs->lead_time < trap_AAS_Time() ) { + //FIXME: add chat to tell the team mate that he/she's on his/her own + bs->lead_time = 0; + return BotGetLongTermGoal( bs, tfl, retreat, goal ); + } + // + if ( bs->leadmessage_time < 0 && -bs->leadmessage_time < trap_AAS_Time() ) { + BotAI_BotInitialChat( bs, "followme", EasyClientName( bs->lead_teammate, teammate, sizeof( teammate ) ), NULL ); + trap_BotEnterChat( bs->cs, bs->client, CHAT_TEAM ); + bs->leadmessage_time = trap_AAS_Time(); + } + //get entity information of the companion + BotEntityInfo( bs->lead_teammate, &entinfo ); + // + if ( entinfo.valid ) { + areanum = BotPointAreaNum( entinfo.origin ); + if ( areanum && trap_AAS_AreaReachability( areanum ) ) { + //update team goal + bs->lead_teamgoal.entitynum = bs->lead_teammate; + bs->lead_teamgoal.areanum = areanum; + VectorCopy( entinfo.origin, bs->lead_teamgoal.origin ); + VectorSet( bs->lead_teamgoal.mins, -8, -8, -8 ); + VectorSet( bs->lead_teamgoal.maxs, 8, 8, 8 ); + } + } + //if the team mate is visible + if ( BotEntityVisible( bs->entitynum, bs->eye, bs->viewangles, 360, bs->lead_teammate ) ) { + bs->leadvisible_time = trap_AAS_Time(); + } + //if the team mate is not visible for 1 seconds + if ( bs->leadvisible_time < trap_AAS_Time() - 1 ) { + bs->leadbackup_time = trap_AAS_Time() + 2; + } + //distance towards the team mate + VectorSubtract( bs->origin, bs->lead_teamgoal.origin, dir ); + dist = VectorLength( dir ); + //if backing up towards the team mate + if ( bs->leadbackup_time > trap_AAS_Time() ) { + if ( bs->leadmessage_time < trap_AAS_Time() - 20 ) { + BotAI_BotInitialChat( bs, "followme", EasyClientName( bs->lead_teammate, teammate, sizeof( teammate ) ), NULL ); + trap_BotEnterChat( bs->cs, bs->client, CHAT_TEAM ); + bs->leadmessage_time = trap_AAS_Time(); + } + //if very close to the team mate + if ( dist < 100 ) { + bs->leadbackup_time = 0; + } + //the bot should go back to the team mate + memcpy( goal, &bs->lead_teamgoal, sizeof( bot_goal_t ) ); + return qtrue; + } else { + //if quite distant from the team mate + if ( dist > 500 ) { + if ( bs->leadmessage_time < trap_AAS_Time() - 20 ) { + BotAI_BotInitialChat( bs, "followme", EasyClientName( bs->lead_teammate, teammate, sizeof( teammate ) ), NULL ); + trap_BotEnterChat( bs->cs, bs->client, CHAT_TEAM ); + bs->leadmessage_time = trap_AAS_Time(); + } + //look at the team mate + VectorSubtract( entinfo.origin, bs->origin, dir ); + vectoangles( dir, bs->ideal_viewangles ); + bs->ideal_viewangles[2] *= 0.5; + //just wait for the team mate + return qfalse; + } + } + } + return BotGetLongTermGoal( bs, tfl, retreat, goal ); +} + +/* +================== +AIEnter_Intermission +================== +*/ +void AIEnter_Intermission( bot_state_t *bs ) { + BotRecordNodeSwitch( bs, "intermission", "" ); + //reset the bot state + BotResetState( bs ); + //check for end level chat + if ( BotChat_EndLevel( bs ) ) { + trap_BotEnterChat( bs->cs, bs->client, bs->chatto ); + } + bs->ainode = AINode_Intermission; +} + +/* +================== +AINode_Intermission +================== +*/ +int AINode_Intermission( bot_state_t *bs ) { + //if the intermission ended + if ( !BotIntermission( bs ) ) { + if ( BotChat_StartLevel( bs ) ) { + bs->stand_time = trap_AAS_Time() + BotChatTime( bs ); + } else { + bs->stand_time = trap_AAS_Time() + 2; + } + AIEnter_Stand( bs ); + } + return qtrue; +} + +/* +================== +AIEnter_Observer +================== +*/ +void AIEnter_Observer( bot_state_t *bs ) { + BotRecordNodeSwitch( bs, "observer", "" ); + //reset the bot state + BotResetState( bs ); + bs->ainode = AINode_Observer; +} + +/* +================== +AINode_Observer +================== +*/ +int AINode_Observer( bot_state_t *bs ) { + //if the bot left observer mode + if ( !BotIsObserver( bs ) ) { + AIEnter_Stand( bs ); + } + return qtrue; +} + +/* +================== +AIEnter_Stand +================== +*/ +void AIEnter_Stand( bot_state_t *bs ) { + BotRecordNodeSwitch( bs, "stand", "" ); + bs->standfindenemy_time = trap_AAS_Time() + 1; + bs->ainode = AINode_Stand; +} + +/* +================== +AINode_Stand +================== +*/ +int AINode_Stand( bot_state_t *bs ) { + + //if the bot's health decreased + if ( bs->lastframe_health > bs->inventory[INVENTORY_HEALTH] ) { + if ( BotChat_HitTalking( bs ) ) { + bs->standfindenemy_time = trap_AAS_Time() + BotChatTime( bs ) + 0.1; + bs->stand_time = trap_AAS_Time() + BotChatTime( bs ) + 0.1; + } + } + if ( bs->standfindenemy_time < trap_AAS_Time() ) { + if ( BotFindEnemy( bs, -1 ) ) { + AIEnter_Battle_Fight( bs ); + return qfalse; + } + bs->standfindenemy_time = trap_AAS_Time() + 1; + } + trap_EA_Talk( bs->client ); + if ( bs->stand_time < trap_AAS_Time() ) { + trap_BotEnterChat( bs->cs, bs->client, bs->chatto ); + AIEnter_Seek_LTG( bs ); + return qfalse; + } + // + return qtrue; +} + +/* +================== +AIEnter_Respawn +================== +*/ +void AIEnter_Respawn( bot_state_t *bs ) { + BotRecordNodeSwitch( bs, "respawn", "" ); + //reset some states + trap_BotResetMoveState( bs->ms ); + trap_BotResetGoalState( bs->gs ); + trap_BotResetAvoidGoals( bs->gs ); + trap_BotResetAvoidReach( bs->ms ); + //if the bot wants to chat + if ( BotChat_Death( bs ) ) { + bs->respawn_time = trap_AAS_Time() + BotChatTime( bs ); + bs->respawnchat_time = trap_AAS_Time(); + } else { + bs->respawn_time = trap_AAS_Time() + 1 + random(); + bs->respawnchat_time = 0; + } + //set respawn state + bs->respawn_wait = qfalse; + bs->ainode = AINode_Respawn; +} + +/* +================== +AINode_Respawn +================== +*/ +int AINode_Respawn( bot_state_t *bs ) { + if ( bs->respawn_wait ) { + if ( !BotIsDead( bs ) ) { + AIEnter_Seek_LTG( bs ); + } else { + trap_EA_Respawn( bs->client ); + } + } else if ( bs->respawn_time < trap_AAS_Time() ) { + //wait until respawned + bs->respawn_wait = qtrue; + //elementary action respawn + trap_EA_Respawn( bs->client ); + // + if ( bs->respawnchat_time ) { + trap_BotEnterChat( bs->cs, bs->client, bs->chatto ); + bs->enemy = -1; + } + } + if ( bs->respawnchat_time && bs->respawnchat_time < trap_AAS_Time() - 0.5 ) { + trap_EA_Talk( bs->client ); + } + // + return qtrue; +} + +/* +================== +AIEnter_Seek_ActivateEntity +================== +*/ +void AIEnter_Seek_ActivateEntity( bot_state_t *bs ) { + BotRecordNodeSwitch( bs, "activate entity", "" ); + bs->ainode = AINode_Seek_ActivateEntity; +} + +/* +================== +AINode_Seek_Activate_Entity +================== +*/ +int AINode_Seek_ActivateEntity( bot_state_t *bs ) { + bot_goal_t *goal; + vec3_t target, dir; + bot_moveresult_t moveresult; + + if ( BotIsObserver( bs ) ) { + AIEnter_Observer( bs ); + return qfalse; + } + //if in the intermission + if ( BotIntermission( bs ) ) { + AIEnter_Intermission( bs ); + return qfalse; + } + //respawn if dead + if ( BotIsDead( bs ) ) { + AIEnter_Respawn( bs ); + return qfalse; + } + // + bs->tfl = TFL_DEFAULT; + if ( bot_grapple.integer ) { + bs->tfl |= TFL_GRAPPLEHOOK; + } + //if in lava or slime the bot should be able to get out + if ( BotInLava( bs ) ) { + bs->tfl |= TFL_LAVA; + } + if ( BotInSlime( bs ) ) { + bs->tfl |= TFL_SLIME; + } + //map specific code + BotMapScripts( bs ); + //no enemy + bs->enemy = -1; + // + goal = &bs->activategoal; + //if the bot has no goal + if ( !goal ) { + bs->activate_time = 0; + } + //if the bot touches the current goal + else if ( trap_BotTouchingGoal( bs->origin, goal ) ) { + BotChooseWeapon( bs ); +#ifdef DEBUG + BotAI_Print( PRT_MESSAGE, "touched button or trigger\n" ); +#endif //DEBUG + bs->activate_time = 0; + } + // + if ( bs->activate_time < trap_AAS_Time() ) { + AIEnter_Seek_NBG( bs ); + return qfalse; + } + //initialize the movement state + BotSetupForMovement( bs ); + //move towards the goal + trap_BotMoveToGoal( &moveresult, bs->ms, goal, bs->tfl ); + //if the movement failed + if ( moveresult.failure ) { + //reset the avoid reach, otherwise bot is stuck in current area + trap_BotResetAvoidReach( bs->ms ); + bs->nbg_time = 0; + } + //check if the bot is blocked + BotAIBlocked( bs, &moveresult, qtrue ); + // + if ( moveresult.flags & ( MOVERESULT_MOVEMENTVIEWSET | MOVERESULT_MOVEMENTVIEW | MOVERESULT_SWIMVIEW ) ) { + VectorCopy( moveresult.ideal_viewangles, bs->ideal_viewangles ); + } + //if waiting for something + else if ( moveresult.flags & MOVERESULT_WAITING ) { + if ( random() < bs->thinktime * 0.8 ) { + BotRoamGoal( bs, target ); + VectorSubtract( target, bs->origin, dir ); + vectoangles( dir, bs->ideal_viewangles ); + bs->ideal_viewangles[2] *= 0.5; + } + } else if ( !( bs->flags & BFL_IDEALVIEWSET ) ) { + if ( trap_BotMovementViewTarget( bs->ms, goal, bs->tfl, 300, target ) ) { + VectorSubtract( target, bs->origin, dir ); + vectoangles( dir, bs->ideal_viewangles ); + } else { + //vectoangles(moveresult.movedir, bs->ideal_viewangles); + } + bs->ideal_viewangles[2] *= 0.5; + } + //if the weapon is used for the bot movement + if ( moveresult.flags & MOVERESULT_MOVEMENTWEAPON ) { + bs->weaponnum = moveresult.weapon; + } + //if there is an enemy + if ( BotFindEnemy( bs, -1 ) ) { + if ( BotWantsToRetreat( bs ) ) { + //keep the current long term goal and retreat + AIEnter_Battle_NBG( bs ); + } else { + trap_BotResetLastAvoidReach( bs->ms ); + //empty the goal stack + trap_BotEmptyGoalStack( bs->gs ); + //go fight + AIEnter_Battle_Fight( bs ); + } + } + return qtrue; +} + +/* +================== +AIEnter_Seek_NBG +================== +*/ +void AIEnter_Seek_NBG( bot_state_t *bs ) { + bot_goal_t goal; + char buf[144]; + + if ( trap_BotGetTopGoal( bs->gs, &goal ) ) { + trap_BotGoalName( goal.number, buf, 144 ); + BotRecordNodeSwitch( bs, "seek NBG", buf ); + } else { + BotRecordNodeSwitch( bs, "seek NBG", "no goal" ); + } + bs->ainode = AINode_Seek_NBG; +} + +/* +================== +AINode_Seek_NBG +================== +*/ +int AINode_Seek_NBG( bot_state_t *bs ) { + bot_goal_t goal; + vec3_t target, dir; + bot_moveresult_t moveresult; + + if ( BotIsObserver( bs ) ) { + AIEnter_Observer( bs ); + return qfalse; + } + //if in the intermission + if ( BotIntermission( bs ) ) { + AIEnter_Intermission( bs ); + return qfalse; + } + //respawn if dead + if ( BotIsDead( bs ) ) { + AIEnter_Respawn( bs ); + return qfalse; + } + // + bs->tfl = TFL_DEFAULT; + if ( bot_grapple.integer ) { + bs->tfl |= TFL_GRAPPLEHOOK; + } + //if in lava or slime the bot should be able to get out + if ( BotInLava( bs ) ) { + bs->tfl |= TFL_LAVA; + } + if ( BotInSlime( bs ) ) { + bs->tfl |= TFL_SLIME; + } + // + if ( BotCanAndWantsToRocketJump( bs ) ) { + bs->tfl |= TFL_ROCKETJUMP; + } + //map specific code + BotMapScripts( bs ); + //no enemy + bs->enemy = -1; + //if the bot has no goal + if ( !trap_BotGetTopGoal( bs->gs, &goal ) ) { + bs->nbg_time = 0; + } + //if the bot touches the current goal + else if ( BotReachedGoal( bs, &goal ) ) { + BotChooseWeapon( bs ); + bs->nbg_time = 0; + } + // + if ( bs->nbg_time < trap_AAS_Time() ) { + //pop the current goal from the stack + trap_BotPopGoal( bs->gs ); + //check for new nearby items right away + //NOTE: we canNOT reset the check_time to zero because it would create an endless loop of node switches + bs->check_time = trap_AAS_Time() + 0.05; + //go back to seek ltg + AIEnter_Seek_LTG( bs ); + return qfalse; + } + //initialize the movement state + BotSetupForMovement( bs ); + //move towards the goal + trap_BotMoveToGoal( &moveresult, bs->ms, &goal, bs->tfl ); + //if the movement failed + if ( moveresult.failure ) { + //reset the avoid reach, otherwise bot is stuck in current area + trap_BotResetAvoidReach( bs->ms ); + bs->nbg_time = 0; + } + //check if the bot is blocked + BotAIBlocked( bs, &moveresult, qtrue ); + //if the viewangles are used for the movement + if ( moveresult.flags & ( MOVERESULT_MOVEMENTVIEWSET | MOVERESULT_MOVEMENTVIEW | MOVERESULT_SWIMVIEW ) ) { + VectorCopy( moveresult.ideal_viewangles, bs->ideal_viewangles ); + } + //if waiting for something + else if ( moveresult.flags & MOVERESULT_WAITING ) { + if ( random() < bs->thinktime * 0.8 ) { + BotRoamGoal( bs, target ); + VectorSubtract( target, bs->origin, dir ); + vectoangles( dir, bs->ideal_viewangles ); + bs->ideal_viewangles[2] *= 0.5; + } + } else if ( !( bs->flags & BFL_IDEALVIEWSET ) ) { + if ( !trap_BotGetSecondGoal( bs->gs, &goal ) ) { + trap_BotGetTopGoal( bs->gs, &goal ); + } + if ( trap_BotMovementViewTarget( bs->ms, &goal, bs->tfl, 300, target ) ) { + VectorSubtract( target, bs->origin, dir ); + vectoangles( dir, bs->ideal_viewangles ); + } + //FIXME: look at cluster portals? + else {vectoangles( moveresult.movedir, bs->ideal_viewangles );} + bs->ideal_viewangles[2] *= 0.5; + } + //if the weapon is used for the bot movement + if ( moveresult.flags & MOVERESULT_MOVEMENTWEAPON ) { + bs->weaponnum = moveresult.weapon; + } + //if there is an enemy + if ( BotFindEnemy( bs, -1 ) ) { + if ( BotWantsToRetreat( bs ) ) { + //keep the current long term goal and retreat + AIEnter_Battle_NBG( bs ); + } else { + trap_BotResetLastAvoidReach( bs->ms ); + //empty the goal stack + trap_BotEmptyGoalStack( bs->gs ); + //go fight + AIEnter_Battle_Fight( bs ); + } + } + return qtrue; +} + +/* +================== +AIEnter_Seek_LTG +================== +*/ +void AIEnter_Seek_LTG( bot_state_t *bs ) { + bot_goal_t goal; + char buf[144]; + + if ( trap_BotGetTopGoal( bs->gs, &goal ) ) { + trap_BotGoalName( goal.number, buf, 144 ); + BotRecordNodeSwitch( bs, "seek LTG", buf ); + } else { + BotRecordNodeSwitch( bs, "seek LTG", "no goal" ); + } + bs->ainode = AINode_Seek_LTG; +} + +/* +================== +AINode_Seek_LTG +================== +*/ +int AINode_Seek_LTG( bot_state_t *bs ) { + bot_goal_t goal; + vec3_t target, dir; + bot_moveresult_t moveresult; + int range; + //char buf[128]; + //bot_goal_t tmpgoal; + + if ( BotIsObserver( bs ) ) { + AIEnter_Observer( bs ); + return qfalse; + } + //if in the intermission + if ( BotIntermission( bs ) ) { + AIEnter_Intermission( bs ); + return qfalse; + } + //respawn if dead + if ( BotIsDead( bs ) ) { + AIEnter_Respawn( bs ); + return qfalse; + } + // + if ( BotChat_Random( bs ) ) { + bs->stand_time = trap_AAS_Time() + BotChatTime( bs ); + AIEnter_Stand( bs ); + return qfalse; + } + // + bs->tfl = TFL_DEFAULT; + if ( bot_grapple.integer ) { + bs->tfl |= TFL_GRAPPLEHOOK; + } + //if in lava or slime the bot should be able to get out + if ( BotInLava( bs ) ) { + bs->tfl |= TFL_LAVA; + } + if ( BotInSlime( bs ) ) { + bs->tfl |= TFL_SLIME; + } + // + if ( BotCanAndWantsToRocketJump( bs ) ) { + bs->tfl |= TFL_ROCKETJUMP; + } + //map specific code + BotMapScripts( bs ); + //no enemy + bs->enemy = -1; + // + if ( bs->killedenemy_time > trap_AAS_Time() - 2 ) { + if ( random() < bs->thinktime * 1 ) { + trap_EA_Gesture( bs->client ); + } + } + //if there is an enemy + if ( BotFindEnemy( bs, -1 ) ) { + if ( BotWantsToRetreat( bs ) ) { + //keep the current long term goal and retreat + AIEnter_Battle_Retreat( bs ); + return qfalse; + } else { + trap_BotResetLastAvoidReach( bs->ms ); + //empty the goal stack + trap_BotEmptyGoalStack( bs->gs ); + //go fight + AIEnter_Battle_Fight( bs ); + return qfalse; + } + } +#ifdef CTF + if ( gametype == GT_CTF ) { + //decide what to do in CTF mode + BotCTFSeekGoals( bs ); + } +#endif //CTF + //get the current long term goal + if ( !BotLongTermGoal( bs, bs->tfl, qfalse, &goal ) ) { + return qtrue; + } + //check for nearby goals periodicly + if ( bs->check_time < trap_AAS_Time() ) { + bs->check_time = trap_AAS_Time() + 0.5; + //check if the bot wants to camp + BotWantsToCamp( bs ); + // + if ( bs->ltgtype == LTG_DEFENDKEYAREA ) { + range = 400; + } else { range = 150;} + // +#ifdef CTF + //if carrying a flag the bot shouldn't be distracted too much + if ( BotCTFCarryingFlag( bs ) ) { + range = 50; + } +#endif //CTF + // + if ( BotNearbyGoal( bs, bs->tfl, &goal, range ) ) { + trap_BotResetLastAvoidReach( bs->ms ); + //get the goal at the top of the stack + //trap_BotGetTopGoal(bs->gs, &tmpgoal); + //trap_BotGoalName(tmpgoal.number, buf, 144); + //BotAI_Print(PRT_MESSAGE, "new nearby goal %s\n", buf); + //time the bot gets to pick up the nearby goal item + bs->nbg_time = trap_AAS_Time() + 4 + range * 0.01; + AIEnter_Seek_NBG( bs ); + return qfalse; + } + } + //initialize the movement state + BotSetupForMovement( bs ); + //move towards the goal + trap_BotMoveToGoal( &moveresult, bs->ms, &goal, bs->tfl ); + //if the movement failed + if ( moveresult.failure ) { + //reset the avoid reach, otherwise bot is stuck in current area + trap_BotResetAvoidReach( bs->ms ); + //BotAI_Print(PRT_MESSAGE, "movement failure %d\n", moveresult.traveltype); + bs->ltg_time = 0; + } + // + BotAIBlocked( bs, &moveresult, qtrue ); + //if the viewangles are used for the movement + if ( moveresult.flags & ( MOVERESULT_MOVEMENTVIEWSET | MOVERESULT_MOVEMENTVIEW | MOVERESULT_SWIMVIEW ) ) { + VectorCopy( moveresult.ideal_viewangles, bs->ideal_viewangles ); + } + //if waiting for something + else if ( moveresult.flags & MOVERESULT_WAITING ) { + if ( random() < bs->thinktime * 0.8 ) { + BotRoamGoal( bs, target ); + VectorSubtract( target, bs->origin, dir ); + vectoangles( dir, bs->ideal_viewangles ); + bs->ideal_viewangles[2] *= 0.5; + } + } else if ( !( bs->flags & BFL_IDEALVIEWSET ) ) { + if ( trap_BotMovementViewTarget( bs->ms, &goal, bs->tfl, 300, target ) ) { + VectorSubtract( target, bs->origin, dir ); + vectoangles( dir, bs->ideal_viewangles ); + } + //FIXME: look at cluster portals? + else if ( VectorLength( moveresult.movedir ) ) { + vectoangles( moveresult.movedir, bs->ideal_viewangles ); + } else if ( random() < bs->thinktime * 0.8 ) { + BotRoamGoal( bs, target ); + VectorSubtract( target, bs->origin, dir ); + vectoangles( dir, bs->ideal_viewangles ); + bs->ideal_viewangles[2] *= 0.5; + } + bs->ideal_viewangles[2] *= 0.5; + } + //if the weapon is used for the bot movement + if ( moveresult.flags & MOVERESULT_MOVEMENTWEAPON ) { + bs->weaponnum = moveresult.weapon; + } + // + return qtrue; +} + +/* +================== +AIEnter_Battle_Fight +================== +*/ +void AIEnter_Battle_Fight( bot_state_t *bs ) { + BotRecordNodeSwitch( bs, "battle fight", "" ); + trap_BotResetLastAvoidReach( bs->ms ); + bs->ainode = AINode_Battle_Fight; +} + +/* +================== +AINode_Battle_Fight +================== +*/ +int AINode_Battle_Fight( bot_state_t *bs ) { + int areanum; + aas_entityinfo_t entinfo; + bot_moveresult_t moveresult; + + if ( BotIsObserver( bs ) ) { + AIEnter_Observer( bs ); + return qfalse; + } + //if in the intermission + if ( BotIntermission( bs ) ) { + AIEnter_Intermission( bs ); + return qfalse; + } + //respawn if dead + if ( BotIsDead( bs ) ) { + AIEnter_Respawn( bs ); + return qfalse; + } + //if no enemy + if ( bs->enemy < 0 ) { + AIEnter_Seek_LTG( bs ); + return qfalse; + } + // + BotEntityInfo( bs->enemy, &entinfo ); + //if the enemy is dead + if ( bs->enemydeath_time ) { + if ( bs->enemydeath_time < trap_AAS_Time() - 1.5 ) { + bs->enemydeath_time = 0; + if ( bs->enemysuicide ) { + BotChat_EnemySuicide( bs ); + } + if ( bs->lastkilledplayer == bs->enemy && BotChat_Kill( bs ) ) { + bs->stand_time = trap_AAS_Time() + BotChatTime( bs ); + AIEnter_Stand( bs ); + } else { + bs->ltg_time = 0; + AIEnter_Seek_LTG( bs ); + } + return qfalse; + } + } else { + if ( EntityIsDead( &entinfo ) ) { + bs->enemydeath_time = trap_AAS_Time(); + } + } + //if the enemy is invisible and not shooting the bot looses track easily + if ( EntityIsInvisible( &entinfo ) && !EntityIsShooting( &entinfo ) ) { + if ( random() < 0.2 ) { + AIEnter_Seek_LTG( bs ); + return qfalse; + } + } + //update the reachability area and origin if possible + areanum = BotPointAreaNum( entinfo.origin ); + if ( areanum && trap_AAS_AreaReachability( areanum ) ) { + VectorCopy( entinfo.origin, bs->lastenemyorigin ); + bs->lastenemyareanum = areanum; + } + //update the attack inventory values + BotUpdateBattleInventory( bs, bs->enemy ); + //if the bot's health decreased + if ( bs->lastframe_health > bs->inventory[INVENTORY_HEALTH] ) { + if ( BotChat_HitNoDeath( bs ) ) { + bs->stand_time = trap_AAS_Time() + BotChatTime( bs ); + AIEnter_Stand( bs ); + return qfalse; + } + } + //if the bot hit someone + if ( bs->cur_ps.persistant[PERS_HITS] > bs->lasthitcount ) { + if ( BotChat_HitNoKill( bs ) ) { + bs->stand_time = trap_AAS_Time() + BotChatTime( bs ); + AIEnter_Stand( bs ); + return qfalse; + } + } + //if the enemy is not visible + if ( !BotEntityVisible( bs->entitynum, bs->eye, bs->viewangles, 360, bs->enemy ) ) { + if ( BotWantsToChase( bs ) ) { + AIEnter_Battle_Chase( bs ); + return qfalse; + } else { + AIEnter_Seek_LTG( bs ); + return qfalse; + } + } + //use holdable items + BotBattleUseItems( bs ); + // + bs->tfl = TFL_DEFAULT; + if ( bot_grapple.integer ) { + bs->tfl |= TFL_GRAPPLEHOOK; + } + //if in lava or slime the bot should be able to get out + if ( BotInLava( bs ) ) { + bs->tfl |= TFL_LAVA; + } + if ( BotInSlime( bs ) ) { + bs->tfl |= TFL_SLIME; + } + // + if ( BotCanAndWantsToRocketJump( bs ) ) { + bs->tfl |= TFL_ROCKETJUMP; + } + //choose the best weapon to fight with + BotChooseWeapon( bs ); + //do attack movements + moveresult = BotAttackMove( bs, bs->tfl ); + //if the movement failed + if ( moveresult.failure ) { + //reset the avoid reach, otherwise bot is stuck in current area + trap_BotResetAvoidReach( bs->ms ); + //BotAI_Print(PRT_MESSAGE, "movement failure %d\n", moveresult.traveltype); + bs->ltg_time = 0; + } + // + BotAIBlocked( bs, &moveresult, qfalse ); + //aim at the enemy + BotAimAtEnemy( bs ); + //attack the enemy if possible + BotCheckAttack( bs ); + //if the bot wants to retreat + if ( BotWantsToRetreat( bs ) ) { + AIEnter_Battle_Retreat( bs ); + return qtrue; + } + return qtrue; +} + +/* +================== +AIEnter_Battle_Chase +================== +*/ +void AIEnter_Battle_Chase( bot_state_t *bs ) { + BotRecordNodeSwitch( bs, "battle chase", "" ); + bs->chase_time = trap_AAS_Time(); + bs->ainode = AINode_Battle_Chase; +} + +/* +================== +AINode_Battle_Chase +================== +*/ +int AINode_Battle_Chase( bot_state_t *bs ) { + bot_goal_t goal; + vec3_t target, dir; + bot_moveresult_t moveresult; + float range; + + if ( BotIsObserver( bs ) ) { + AIEnter_Observer( bs ); + return qfalse; + } + //if in the intermission + if ( BotIntermission( bs ) ) { + AIEnter_Intermission( bs ); + return qfalse; + } + //respawn if dead + if ( BotIsDead( bs ) ) { + AIEnter_Respawn( bs ); + return qfalse; + } + //if no enemy + if ( bs->enemy < 0 ) { + AIEnter_Seek_LTG( bs ); + return qfalse; + } + //if the enemy is visible + if ( BotEntityVisible( bs->entitynum, bs->eye, bs->viewangles, 360, bs->enemy ) ) { + AIEnter_Battle_Fight( bs ); + return qfalse; + } + //if there is another enemy + if ( BotFindEnemy( bs, -1 ) ) { + AIEnter_Battle_Fight( bs ); + return qfalse; + } + //there is no last enemy area + if ( !bs->lastenemyareanum ) { + AIEnter_Seek_LTG( bs ); + return qfalse; + } + // + bs->tfl = TFL_DEFAULT; + if ( bot_grapple.integer ) { + bs->tfl |= TFL_GRAPPLEHOOK; + } + //if in lava or slime the bot should be able to get out + if ( BotInLava( bs ) ) { + bs->tfl |= TFL_LAVA; + } + if ( BotInSlime( bs ) ) { + bs->tfl |= TFL_SLIME; + } + // + if ( BotCanAndWantsToRocketJump( bs ) ) { + bs->tfl |= TFL_ROCKETJUMP; + } + //map specific code + BotMapScripts( bs ); + //create the chase goal + goal.entitynum = bs->enemy; + goal.areanum = bs->lastenemyareanum; + VectorCopy( bs->lastenemyorigin, goal.origin ); + VectorSet( goal.mins, -8, -8, -8 ); + VectorSet( goal.maxs, 8, 8, 8 ); + //if the last seen enemy spot is reached the enemy could not be found + if ( trap_BotTouchingGoal( bs->origin, &goal ) ) { + bs->chase_time = 0; + } + //if there's no chase time left + if ( !bs->chase_time || bs->chase_time < trap_AAS_Time() - 10 ) { + AIEnter_Seek_LTG( bs ); + return qfalse; + } + //check for nearby goals periodicly + if ( bs->check_time < trap_AAS_Time() ) { + bs->check_time = trap_AAS_Time() + 1; + range = 150; + // + if ( BotNearbyGoal( bs, bs->tfl, &goal, range ) ) { + //the bot gets 5 seconds to pick up the nearby goal item + bs->nbg_time = trap_AAS_Time() + 0.1 * range + 1; + trap_BotResetLastAvoidReach( bs->ms ); + AIEnter_Battle_NBG( bs ); + return qfalse; + } + } + // + BotUpdateBattleInventory( bs, bs->enemy ); + //initialize the movement state + BotSetupForMovement( bs ); + //move towards the goal + trap_BotMoveToGoal( &moveresult, bs->ms, &goal, bs->tfl ); + //if the movement failed + if ( moveresult.failure ) { + //reset the avoid reach, otherwise bot is stuck in current area + trap_BotResetAvoidReach( bs->ms ); + //BotAI_Print(PRT_MESSAGE, "movement failure %d\n", moveresult.traveltype); + bs->ltg_time = 0; + } + // + BotAIBlocked( bs, &moveresult, qfalse ); + // + if ( moveresult.flags & ( MOVERESULT_MOVEMENTVIEWSET | MOVERESULT_MOVEMENTVIEW | MOVERESULT_SWIMVIEW ) ) { + VectorCopy( moveresult.ideal_viewangles, bs->ideal_viewangles ); + } else if ( !( bs->flags & BFL_IDEALVIEWSET ) ) { + if ( bs->chase_time > trap_AAS_Time() - 2 ) { + BotAimAtEnemy( bs ); + } else { + if ( trap_BotMovementViewTarget( bs->ms, &goal, bs->tfl, 300, target ) ) { + VectorSubtract( target, bs->origin, dir ); + vectoangles( dir, bs->ideal_viewangles ); + } else { + vectoangles( moveresult.movedir, bs->ideal_viewangles ); + } + } + bs->ideal_viewangles[2] *= 0.5; + } + //if the weapon is used for the bot movement + if ( moveresult.flags & MOVERESULT_MOVEMENTWEAPON ) { + bs->weaponnum = moveresult.weapon; + } + //if the bot is in the area the enemy was last seen in + if ( bs->areanum == bs->lastenemyareanum ) { + bs->chase_time = 0; + } + //if the bot wants to retreat (the bot could have been damage during the chase) + if ( BotWantsToRetreat( bs ) ) { + AIEnter_Battle_Retreat( bs ); + return qtrue; + } + return qtrue; +} + +/* +================== +AIEnter_Battle_Retreat +================== +*/ +void AIEnter_Battle_Retreat( bot_state_t *bs ) { + BotRecordNodeSwitch( bs, "battle retreat", "" ); + bs->ainode = AINode_Battle_Retreat; +} + +/* +================== +AINode_Battle_Retreat +================== +*/ +int AINode_Battle_Retreat( bot_state_t *bs ) { + bot_goal_t goal; + aas_entityinfo_t entinfo; + bot_moveresult_t moveresult; + vec3_t target, dir; + float attack_skill, range; + int areanum; + + if ( BotIsObserver( bs ) ) { + AIEnter_Observer( bs ); + return qfalse; + } + //if in the intermission + if ( BotIntermission( bs ) ) { + AIEnter_Intermission( bs ); + return qfalse; + } + //respawn if dead + if ( BotIsDead( bs ) ) { + AIEnter_Respawn( bs ); + return qfalse; + } + //if no enemy + if ( bs->enemy < 0 ) { + AIEnter_Seek_LTG( bs ); + return qfalse; + } + // + BotEntityInfo( bs->enemy, &entinfo ); + if ( EntityIsDead( &entinfo ) ) { + AIEnter_Seek_LTG( bs ); + return qfalse; + } + // + bs->tfl = TFL_DEFAULT; + if ( bot_grapple.integer ) { + bs->tfl |= TFL_GRAPPLEHOOK; + } + //if in lava or slime the bot should be able to get out + if ( BotInLava( bs ) ) { + bs->tfl |= TFL_LAVA; + } + if ( BotInSlime( bs ) ) { + bs->tfl |= TFL_SLIME; + } + //map specific code + BotMapScripts( bs ); + //update the attack inventory values + BotUpdateBattleInventory( bs, bs->enemy ); + //if the bot doesn't want to retreat anymore... probably picked up some nice items + if ( BotWantsToChase( bs ) ) { + //empty the goal stack, when chasing, only the enemy is the goal + trap_BotEmptyGoalStack( bs->gs ); + //go chase the enemy + AIEnter_Battle_Chase( bs ); + return qfalse; + } + //update the last time the enemy was visible + if ( BotEntityVisible( bs->entitynum, bs->eye, bs->viewangles, 360, bs->enemy ) ) { + bs->enemyvisible_time = trap_AAS_Time(); + //update the reachability area and origin if possible + areanum = BotPointAreaNum( entinfo.origin ); + if ( areanum && trap_AAS_AreaReachability( areanum ) ) { + VectorCopy( entinfo.origin, bs->lastenemyorigin ); + bs->lastenemyareanum = areanum; + } + } + //if the enemy is NOT visible for 4 seconds + if ( bs->enemyvisible_time < trap_AAS_Time() - 4 ) { + AIEnter_Seek_LTG( bs ); + return qfalse; + } + //else if the enemy is NOT visible + else if ( bs->enemyvisible_time < trap_AAS_Time() ) { + //if there is another enemy + if ( BotFindEnemy( bs, -1 ) ) { + AIEnter_Battle_Fight( bs ); + return qfalse; + } + } + // +#ifdef CTF + if ( gametype == GT_CTF ) { + BotCTFRetreatGoals( bs ); + } +#endif //CTF + //use holdable items + BotBattleUseItems( bs ); + //get the current long term goal while retreating + if ( !BotLongTermGoal( bs, bs->tfl, qtrue, &goal ) ) { + return qtrue; + } + //check for nearby goals periodicly + if ( bs->check_time < trap_AAS_Time() ) { + bs->check_time = trap_AAS_Time() + 1; + range = 150; +#ifdef CTF + //if carrying a flag the bot shouldn't be distracted too much + if ( BotCTFCarryingFlag( bs ) ) { + range = 100; + } +#endif //CTF + // + if ( BotNearbyGoal( bs, bs->tfl, &goal, range ) ) { + trap_BotResetLastAvoidReach( bs->ms ); + //time the bot gets to pick up the nearby goal item + bs->nbg_time = trap_AAS_Time() + range / 100 + 1; + AIEnter_Battle_NBG( bs ); + return qfalse; + } + } + //initialize the movement state + BotSetupForMovement( bs ); + //move towards the goal + trap_BotMoveToGoal( &moveresult, bs->ms, &goal, bs->tfl ); + //if the movement failed + if ( moveresult.failure ) { + //reset the avoid reach, otherwise bot is stuck in current area + trap_BotResetAvoidReach( bs->ms ); + //BotAI_Print(PRT_MESSAGE, "movement failure %d\n", moveresult.traveltype); + bs->ltg_time = 0; + } + // + BotAIBlocked( bs, &moveresult, qfalse ); + //choose the best weapon to fight with + BotChooseWeapon( bs ); + //if the view is fixed for the movement + if ( moveresult.flags & ( MOVERESULT_MOVEMENTVIEW + //|MOVERESULT_SWIMVIEW + ) ) { + VectorCopy( moveresult.ideal_viewangles, bs->ideal_viewangles ); + } else if ( !( moveresult.flags & MOVERESULT_MOVEMENTVIEWSET ) + && !( bs->flags & BFL_IDEALVIEWSET ) ) { + attack_skill = trap_Characteristic_BFloat( bs->character, CHARACTERISTIC_ATTACK_SKILL, 0, 1 ); + //if the bot is skilled anough + if ( attack_skill > 0.3 ) { + BotAimAtEnemy( bs ); + } else { + if ( trap_BotMovementViewTarget( bs->ms, &goal, bs->tfl, 300, target ) ) { + VectorSubtract( target, bs->origin, dir ); + vectoangles( dir, bs->ideal_viewangles ); + } else { + vectoangles( moveresult.movedir, bs->ideal_viewangles ); + } + bs->ideal_viewangles[2] *= 0.5; + } + } + //if the weapon is used for the bot movement + if ( moveresult.flags & MOVERESULT_MOVEMENTWEAPON ) { + bs->weaponnum = moveresult.weapon; + } + //attack the enemy if possible + BotCheckAttack( bs ); + // + return qtrue; +} + +/* +================== +AIEnter_Battle_NBG +================== +*/ +void AIEnter_Battle_NBG( bot_state_t *bs ) { + BotRecordNodeSwitch( bs, "battle NBG", "" ); + bs->ainode = AINode_Battle_NBG; +} + +/* +================== +AINode_Battle_NBG +================== +*/ +int AINode_Battle_NBG( bot_state_t *bs ) { + int areanum; + bot_goal_t goal; + aas_entityinfo_t entinfo; + bot_moveresult_t moveresult; + float attack_skill; + vec3_t target, dir; + + if ( BotIsObserver( bs ) ) { + AIEnter_Observer( bs ); + return qfalse; + } + //if in the intermission + if ( BotIntermission( bs ) ) { + AIEnter_Intermission( bs ); + return qfalse; + } + //respawn if dead + if ( BotIsDead( bs ) ) { + AIEnter_Respawn( bs ); + return qfalse; + } + //if no enemy + if ( bs->enemy < 0 ) { + AIEnter_Seek_NBG( bs ); + return qfalse; + } + // + BotEntityInfo( bs->enemy, &entinfo ); + if ( EntityIsDead( &entinfo ) ) { + AIEnter_Seek_NBG( bs ); + return qfalse; + } + // + bs->tfl = TFL_DEFAULT; + if ( bot_grapple.integer ) { + bs->tfl |= TFL_GRAPPLEHOOK; + } + //if in lava or slime the bot should be able to get out + if ( BotInLava( bs ) ) { + bs->tfl |= TFL_LAVA; + } + if ( BotInSlime( bs ) ) { + bs->tfl |= TFL_SLIME; + } + // + if ( BotCanAndWantsToRocketJump( bs ) ) { + bs->tfl |= TFL_ROCKETJUMP; + } + //map specific code + BotMapScripts( bs ); + //update the last time the enemy was visible + if ( BotEntityVisible( bs->entitynum, bs->eye, bs->viewangles, 360, bs->enemy ) ) { + bs->enemyvisible_time = trap_AAS_Time(); + //update the reachability area and origin if possible + areanum = BotPointAreaNum( entinfo.origin ); + if ( areanum && trap_AAS_AreaReachability( areanum ) ) { + VectorCopy( entinfo.origin, bs->lastenemyorigin ); + bs->lastenemyareanum = areanum; + } + } + //if the bot has no goal or touches the current goal + if ( !trap_BotGetTopGoal( bs->gs, &goal ) ) { + bs->nbg_time = 0; + } else if ( trap_BotTouchingGoal( bs->origin, &goal ) ) { + bs->nbg_time = 0; + } + // + if ( bs->nbg_time < trap_AAS_Time() ) { + //pop the current goal from the stack + trap_BotPopGoal( bs->gs ); + //if the bot still has a goal + if ( trap_BotGetTopGoal( bs->gs, &goal ) ) { + AIEnter_Battle_Retreat( bs ); + } else { AIEnter_Battle_Fight( bs );} + // + return qfalse; + } + //initialize the movement state + BotSetupForMovement( bs ); + //move towards the goal + trap_BotMoveToGoal( &moveresult, bs->ms, &goal, bs->tfl ); + //if the movement failed + if ( moveresult.failure ) { + //reset the avoid reach, otherwise bot is stuck in current area + trap_BotResetAvoidReach( bs->ms ); + //BotAI_Print(PRT_MESSAGE, "movement failure %d\n", moveresult.traveltype); + bs->nbg_time = 0; + } + // + BotAIBlocked( bs, &moveresult, qfalse ); + //update the attack inventory values + BotUpdateBattleInventory( bs, bs->enemy ); + //choose the best weapon to fight with + BotChooseWeapon( bs ); + //if the view is fixed for the movement + if ( moveresult.flags & MOVERESULT_MOVEMENTVIEW ) { + VectorCopy( moveresult.ideal_viewangles, bs->ideal_viewangles ); + } else if ( !( moveresult.flags & MOVERESULT_MOVEMENTVIEWSET ) + && !( bs->flags & BFL_IDEALVIEWSET ) ) { + attack_skill = trap_Characteristic_BFloat( bs->character, CHARACTERISTIC_ATTACK_SKILL, 0, 1 ); + //if the bot is skilled anough and the enemy is visible + if ( attack_skill > 0.3 ) { + //&& BotEntityVisible(bs->entitynum, bs->eye, bs->viewangles, 360, bs->enemy) + BotAimAtEnemy( bs ); + } else { + if ( trap_BotMovementViewTarget( bs->ms, &goal, bs->tfl, 300, target ) ) { + VectorSubtract( target, bs->origin, dir ); + vectoangles( dir, bs->ideal_viewangles ); + } else { + vectoangles( moveresult.movedir, bs->ideal_viewangles ); + } + bs->ideal_viewangles[2] *= 0.5; + } + } + //if the weapon is used for the bot movement + if ( moveresult.flags & MOVERESULT_MOVEMENTWEAPON ) { + bs->weaponnum = moveresult.weapon; + } + //attack the enemy if possible + BotCheckAttack( bs ); + // + return qtrue; +} diff --git a/Projects/Android/jni/rtcw/src/botai/ai_dmnet.h b/Projects/Android/jni/rtcw/src/botai/ai_dmnet.h new file mode 100644 index 0000000..8b43529 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/botai/ai_dmnet.h @@ -0,0 +1,66 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +/***************************************************************************** + * name: ai_dmnet.h + * + * desc: Quake3 bot AI + * + * + *****************************************************************************/ + +#define MAX_NODESWITCHES 50 + +void AIEnter_Intermission( bot_state_t *bs ); +void AIEnter_Observer( bot_state_t *bs ); +void AIEnter_Respawn( bot_state_t *bs ); +void AIEnter_Stand( bot_state_t *bs ); +void AIEnter_Seek_ActivateEntity( bot_state_t *bs ); +void AIEnter_Seek_NBG( bot_state_t *bs ); +void AIEnter_Seek_LTG( bot_state_t *bs ); +void AIEnter_Seek_Camp( bot_state_t *bs ); +void AIEnter_Battle_Fight( bot_state_t *bs ); +void AIEnter_Battle_Chase( bot_state_t *bs ); +void AIEnter_Battle_Retreat( bot_state_t *bs ); +void AIEnter_Battle_NBG( bot_state_t *bs ); +int AINode_Intermission( bot_state_t *bs ); +int AINode_Observer( bot_state_t *bs ); +int AINode_Respawn( bot_state_t *bs ); +int AINode_Stand( bot_state_t *bs ); +int AINode_Seek_ActivateEntity( bot_state_t *bs ); +int AINode_Seek_NBG( bot_state_t *bs ); +int AINode_Seek_LTG( bot_state_t *bs ); +int AINode_Battle_Fight( bot_state_t *bs ); +int AINode_Battle_Chase( bot_state_t *bs ); +int AINode_Battle_Retreat( bot_state_t *bs ); +int AINode_Battle_NBG( bot_state_t *bs ); + +void BotResetNodeSwitches( void ); +void BotDumpNodeSwitches( bot_state_t *bs ); + diff --git a/Projects/Android/jni/rtcw/src/botai/ai_dmq3.c b/Projects/Android/jni/rtcw/src/botai/ai_dmq3.c new file mode 100644 index 0000000..b1eb198 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/botai/ai_dmq3.c @@ -0,0 +1,2899 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +/***************************************************************************** + * name: ai_dmq3.c + * + * desc: Quake3 bot AI + * + * + *****************************************************************************/ + + +#include "../game/g_local.h" +#include "../game/botlib.h" +#include "../game/be_aas.h" +#include "../game/be_ea.h" +#include "../game/be_ai_char.h" +#include "../game/be_ai_chat.h" +#include "../game/be_ai_gen.h" +#include "../game/be_ai_goal.h" +#include "../game/be_ai_move.h" +#include "../game/be_ai_weap.h" +#include "../botai/botai.h" +// +#include "ai_main.h" +#include "ai_dmq3.h" +#include "ai_chat.h" +#include "ai_cmd.h" +#include "ai_dmnet.h" +#include "ai_team.h" +// +#include "chars.h" //characteristics +#include "inv.h" //indexes into the inventory +#include "syn.h" //synonyms +#include "match.h" //string matching types and vars + +#define IDEAL_ATTACKDIST 140 +#define WEAPONINDEX_MACHINEGUN 2 + +#define MAX_WAYPOINTS 128 + +////////////////// +// from aasfile.h +#define AREACONTENTS_MOVER 1024 +#define AREACONTENTS_MODELNUMSHIFT 24 +#define AREACONTENTS_MAXMODELNUM 0xFF +#define AREACONTENTS_MODELNUM ( AREACONTENTS_MAXMODELNUM << AREACONTENTS_MODELNUMSHIFT ) +////////////////// +// +bot_waypoint_t botai_waypoints[MAX_WAYPOINTS]; +bot_waypoint_t *botai_freewaypoints; + +//NOTE: not using a cvar which can be updated because the game should be reloaded anyway +int gametype; //game type + +// Rafael gameskill +int gameskill; + +vmCvar_t bot_grapple; +vmCvar_t bot_rocketjump; +vmCvar_t bot_fastchat; +vmCvar_t bot_nochat; +vmCvar_t bot_testrchat; + +vec3_t lastteleport_origin; +float lastteleport_time; +//true when the map changed +int max_bspmodelindex; //maximum BSP model index + +//CTF flag goals +bot_goal_t ctf_redflag; +bot_goal_t ctf_blueflag; + +#ifdef CTF +/* +================== +BotCTFCarryingFlag +================== +*/ +int BotCTFCarryingFlag( bot_state_t *bs ) { + if ( gametype != GT_CTF ) { + return CTF_FLAG_NONE; + } + + if ( bs->inventory[INVENTORY_REDFLAG] > 0 ) { + return CTF_FLAG_RED; + } else if ( bs->inventory[INVENTORY_BLUEFLAG] > 0 ) { + return CTF_FLAG_BLUE; + } + return CTF_FLAG_NONE; +} + +/* +================== +BotCTFTeam +================== +*/ +int BotCTFTeam( bot_state_t *bs ) { + char skin[128], *p; + + if ( gametype != GT_CTF ) { + return CTF_TEAM_NONE; + } + ClientSkin( bs->client, skin, sizeof( skin ) ); + p = strchr( skin, '/' ); + if ( !p ) { + p = skin; + } else { p++;} + if ( Q_stricmp( p, CTF_SKIN_REDTEAM ) == 0 ) { + return CTF_TEAM_RED; + } + if ( Q_stricmp( p, CTF_SKIN_BLUETEAM ) == 0 ) { + return CTF_TEAM_BLUE; + } + return CTF_TEAM_NONE; +} + +/* +================== +BotCTFRetreatGoals +================== +*/ +void BotCTFRetreatGoals( bot_state_t *bs ) { + //when carrying a flag in ctf the bot should rush to the base + if ( BotCTFCarryingFlag( bs ) ) { + //if not already rushing to the base + if ( bs->ltgtype != LTG_RUSHBASE ) { + bs->ltgtype = LTG_RUSHBASE; + bs->teamgoal_time = trap_AAS_Time() + CTF_RUSHBASE_TIME; + bs->rushbaseaway_time = 0; + } + } +} + +/* +================== +BotCTFSeekGoals +================== +*/ +void BotCTFSeekGoals( bot_state_t *bs ) { + float rnd; + + //when carrying a flag in ctf the bot should rush to the base + if ( BotCTFCarryingFlag( bs ) ) { + //if not already rushing to the base + if ( bs->ltgtype != LTG_RUSHBASE ) { + bs->ltgtype = LTG_RUSHBASE; + bs->teamgoal_time = trap_AAS_Time() + CTF_RUSHBASE_TIME; + bs->rushbaseaway_time = 0; + } + return; + } + //if the bot is roaming + if ( bs->ctfroam_time > trap_AAS_Time() ) { + return; + } + //if already a CTF or team goal + if ( bs->ltgtype == LTG_TEAMHELP || + bs->ltgtype == LTG_TEAMACCOMPANY || + bs->ltgtype == LTG_DEFENDKEYAREA || + bs->ltgtype == LTG_GETFLAG || + bs->ltgtype == LTG_RUSHBASE || + bs->ltgtype == LTG_CAMPORDER || + bs->ltgtype == LTG_PATROL ) { + return; + } + //if the bot has anough aggression to decide what to do + if ( BotAggression( bs ) < 50 ) { + return; + } + //set the time to send a message to the team mates + bs->teammessage_time = trap_AAS_Time() + 2 * random(); + //get the flag or defend the base + rnd = random(); + if ( rnd < 0.33 && ctf_redflag.areanum && ctf_blueflag.areanum ) { + bs->ltgtype = LTG_GETFLAG; + //set the time the bot will stop getting the flag + bs->teamgoal_time = trap_AAS_Time() + CTF_GETFLAG_TIME; + } else if ( rnd < 0.66 && ctf_redflag.areanum && ctf_blueflag.areanum ) { + //FIXME: do not always use the base flag + if ( BotCTFTeam( bs ) == CTF_TEAM_RED ) { + memcpy( &bs->teamgoal, &ctf_redflag, sizeof( bot_goal_t ) ); + } else { memcpy( &bs->teamgoal, &ctf_blueflag, sizeof( bot_goal_t ) );} + //set the ltg type + bs->ltgtype = LTG_DEFENDKEYAREA; + //set the time the bot stop defending the base + bs->teamgoal_time = trap_AAS_Time() + TEAM_DEFENDKEYAREA_TIME; + bs->defendaway_time = 0; + } else { + bs->ltgtype = 0; + //set the time the bot will stop roaming + bs->ctfroam_time = trap_AAS_Time() + CTF_ROAM_TIME; + } +#ifdef DEBUG + BotPrintTeamGoal( bs ); +#endif //DEBUG +} + +#endif //CTF + +/* +================== +BotPointAreaNum +================== +*/ +int BotPointAreaNum( vec3_t origin ) { + int areanum, numareas, areas[1]; + vec3_t end, ofs; + #define BOTAREA_JIGGLE_DIST 32 + + areanum = trap_AAS_PointAreaNum( origin ); + if ( areanum ) { + return areanum; + } + VectorCopy( origin, end ); + end[2] += 10; + numareas = trap_AAS_TraceAreas( origin, end, areas, NULL, 1 ); + if ( numareas > 0 ) { + return areas[0]; + } + + // Ridah, jiggle them around to look for a fuzzy area, helps LARGE characters reach destinations that are against walls + ofs[2] = 10; + for ( ofs[0] = -BOTAREA_JIGGLE_DIST; ofs[0] <= BOTAREA_JIGGLE_DIST; ofs[0] += BOTAREA_JIGGLE_DIST * 2 ) { + for ( ofs[1] = -BOTAREA_JIGGLE_DIST; ofs[1] <= BOTAREA_JIGGLE_DIST; ofs[1] += BOTAREA_JIGGLE_DIST * 2 ) { + VectorAdd( origin, ofs, end ); + numareas = trap_AAS_TraceAreas( origin, end, areas, NULL, 1 ); + if ( numareas > 0 ) { + return areas[0]; + } + } + } + + return 0; +} + +/* +================== +ClientName +================== +*/ +char *ClientName( int client, char *name, int size ) { + char buf[MAX_INFO_STRING]; + + if ( client < 0 || client >= MAX_CLIENTS ) { + BotAI_Print( PRT_ERROR, "ClientName: client out of range\n" ); + return "[client out of range]"; + } + trap_GetConfigstring( CS_PLAYERS + client, buf, sizeof( buf ) ); + strncpy( name, Info_ValueForKey( buf, "n" ), size - 1 ); + name[size - 1] = '\0'; + Q_CleanStr( name ); + return name; +} + +/* +================== +ClientSkin +================== +*/ +char *ClientSkin( int client, char *skin, int size ) { + char buf[MAX_INFO_STRING]; + + if ( client < 0 || client >= MAX_CLIENTS ) { + BotAI_Print( PRT_ERROR, "ClientSkin: client out of range\n" ); + return "[client out of range]"; + } + trap_GetConfigstring( CS_PLAYERS + client, buf, sizeof( buf ) ); + strncpy( skin, Info_ValueForKey( buf, "model" ), size - 1 ); + skin[size - 1] = '\0'; + return skin; +} + +/* +================== +ClientFromName +================== +*/ +int ClientFromName( char *name ) { + int i; + char buf[MAX_INFO_STRING]; + static int maxclients; + + if ( !maxclients ) { + maxclients = trap_Cvar_VariableIntegerValue( "sv_maxclients" ); + } + for ( i = 0; i < maxclients && i < MAX_CLIENTS; i++ ) { + trap_GetConfigstring( CS_PLAYERS + i, buf, sizeof( buf ) ); + Q_CleanStr( buf ); + if ( !Q_stricmp( Info_ValueForKey( buf, "n" ), name ) ) { + return i; + } + } + return -1; +} + +/* +================== +stristr +================== +*/ +char *stristr( char *str, char *charset ) { + int i; + + while ( *str ) { + for ( i = 0; charset[i] && str[i]; i++ ) { + if ( toupper( charset[i] ) != toupper( str[i] ) ) { + break; + } + } + if ( !charset[i] ) { + return str; + } + str++; + } + return NULL; +} + +/* +================== +EasyClientName +================== +*/ +char *EasyClientName( int client, char *buf, int size ) { + int i; + char *str1, *str2, *ptr, c; + char name[128]; + + strcpy( name, ClientName( client, name, sizeof( name ) ) ); + for ( i = 0; name[i]; i++ ) name[i] &= 127; + //remove all spaces + for ( ptr = strstr( name, " " ); ptr; ptr = strstr( name, " " ) ) { + memmove( ptr, ptr + 1, strlen( ptr + 1 ) + 1 ); + } + //check for [x] and ]x[ clan names + str1 = strstr( name, "[" ); + str2 = strstr( name, "]" ); + if ( str1 && str2 ) { + if ( str2 > str1 ) { + memmove( str1, str2 + 1, strlen( str2 + 1 ) + 1 ); + } else { memmove( str2, str1 + 1, strlen( str1 + 1 ) + 1 );} + } + //remove Mr prefix + if ( ( name[0] == 'm' || name[0] == 'M' ) && + ( name[1] == 'r' || name[1] == 'R' ) ) { + memmove( name, name + 2, strlen( name + 2 ) + 1 ); + } + //only allow lower case alphabet characters + ptr = name; + while ( *ptr ) { + c = *ptr; + if ( ( c >= 'a' && c <= 'z' ) || + ( c >= '0' && c <= '9' ) || c == '_' ) { + ptr++; + } else if ( c >= 'A' && c <= 'Z' ) { + *ptr += 'a' - 'A'; + ptr++; + } else { + memmove( ptr, ptr + 1, strlen( ptr + 1 ) + 1 ); + } + } + strncpy( buf, name, size - 1 ); + buf[size - 1] = '\0'; + return buf; +} + +/* +================== +BotChooseWeapon +================== +*/ +void BotChooseWeapon( bot_state_t *bs ) { + int newweaponnum; + + if ( bs->cur_ps.weaponstate == WEAPON_RAISING || + bs->cur_ps.weaponstate == WEAPON_RAISING_TORELOAD || //----(SA) added + bs->cur_ps.weaponstate == WEAPON_DROPPING || + bs->cur_ps.weaponstate == WEAPON_DROPPING_TORELOAD ) { //----(SA) added + trap_EA_SelectWeapon( bs->client, bs->weaponnum ); + } else { + newweaponnum = trap_BotChooseBestFightWeapon( bs->ws, bs->inventory ); + if ( bs->weaponnum != newweaponnum ) { + bs->weaponchange_time = trap_AAS_Time(); + } + bs->weaponnum = newweaponnum; + //BotAI_Print(PRT_MESSAGE, "bs->weaponnum = %d\n", bs->weaponnum); + trap_EA_SelectWeapon( bs->client, bs->weaponnum ); + } +} + +/* +================== +BotSetupForMovement +================== +*/ +void BotSetupForMovement( bot_state_t *bs ) { + bot_initmove_t initmove; + + memset( &initmove, 0, sizeof( bot_initmove_t ) ); + VectorCopy( bs->cur_ps.origin, initmove.origin ); + VectorCopy( bs->cur_ps.velocity, initmove.velocity ); + VectorCopy( bs->cur_ps.origin, initmove.viewoffset ); + initmove.viewoffset[2] += bs->cur_ps.viewheight; + initmove.entitynum = bs->entitynum; + initmove.client = bs->client; + initmove.thinktime = bs->thinktime; + //set the onground flag + if ( bs->cur_ps.groundEntityNum != ENTITYNUM_NONE ) { + initmove.or_moveflags |= MFL_ONGROUND; + } + //set the teleported flag + if ( ( bs->cur_ps.pm_flags & PMF_TIME_KNOCKBACK ) && ( bs->cur_ps.pm_time > 0 ) ) { + initmove.or_moveflags |= MFL_TELEPORTED; + } + //set the waterjump flag + if ( ( bs->cur_ps.pm_flags & PMF_TIME_WATERJUMP ) && ( bs->cur_ps.pm_time > 0 ) ) { + initmove.or_moveflags |= MFL_WATERJUMP; + } + //set presence type + if ( bs->cur_ps.pm_flags & PMF_DUCKED ) { + initmove.presencetype = PRESENCE_CROUCH; + } else { initmove.presencetype = PRESENCE_NORMAL;} + // + if ( bs->walker > 0.5 ) { + initmove.or_moveflags |= MFL_WALK; + } + // + VectorCopy( bs->viewangles, initmove.viewangles ); + // + trap_BotInitMoveState( bs->ms, &initmove ); +} + +/* +================== +BotUpdateInventory +================== +*/ +void BotUpdateInventory( bot_state_t *bs ) { + //armor + bs->inventory[INVENTORY_ARMOR] = bs->cur_ps.stats[STAT_ARMOR]; + //weapons + bs->inventory[INVENTORY_LUGER] = COM_BitCheck( bs->cur_ps.weapons, ( WP_LUGER ) ); + bs->inventory[INVENTORY_MAUSER] = COM_BitCheck( bs->cur_ps.weapons, ( WP_MAUSER ) ); + bs->inventory[INVENTORY_MP40] = COM_BitCheck( bs->cur_ps.weapons, ( WP_MP40 ) ); + bs->inventory[INVENTORY_GRENADELAUNCHER] = COM_BitCheck( bs->cur_ps.weapons, ( WP_GRENADE_LAUNCHER ) ); + bs->inventory[INVENTORY_VENOM] = COM_BitCheck( bs->cur_ps.weapons, ( WP_VENOM ) ); + bs->inventory[INVENTORY_FLAMETHROWER] = COM_BitCheck( bs->cur_ps.weapons, ( WP_FLAMETHROWER ) ); + bs->inventory[INVENTORY_GAUNTLET] = COM_BitCheck( bs->cur_ps.weapons, ( WP_GAUNTLET ) ); + + // ammo + bs->inventory[INVENTORY_9MM] = bs->cur_ps.ammo[BG_FindAmmoForWeapon( WP_MP40 )]; + bs->inventory[INVENTORY_792MM] = bs->cur_ps.ammo[BG_FindAmmoForWeapon( WP_MAUSER )]; + bs->inventory[INVENTORY_GRENADES] = bs->cur_ps.ammo[BG_FindAmmoForWeapon( WP_GRENADE_LAUNCHER )]; + bs->inventory[INVENTORY_127MM] = bs->cur_ps.ammo[BG_FindAmmoForWeapon( WP_VENOM )]; + bs->inventory[INVENTORY_FUEL] = bs->cur_ps.ammo[BG_FindAmmoForWeapon( WP_FLAMETHROWER )]; + + //powerups + bs->inventory[INVENTORY_HEALTH] = bs->cur_ps.stats[STAT_HEALTH]; + bs->inventory[INVENTORY_TELEPORTER] = bs->cur_ps.stats[STAT_HOLDABLE_ITEM] == MODELINDEX_TELEPORTER; + bs->inventory[INVENTORY_MEDKIT] = bs->cur_ps.stats[STAT_HOLDABLE_ITEM] == MODELINDEX_MEDKIT; + bs->inventory[INVENTORY_QUAD] = bs->cur_ps.powerups[PW_QUAD] != 0; + bs->inventory[INVENTORY_ENVIRONMENTSUIT] = bs->cur_ps.powerups[PW_BATTLESUIT] != 0; + bs->inventory[INVENTORY_HASTE] = bs->cur_ps.powerups[PW_HASTE] != 0; + bs->inventory[INVENTORY_INVISIBILITY] = bs->cur_ps.powerups[PW_INVIS] != 0; + bs->inventory[INVENTORY_REGEN] = bs->cur_ps.powerups[PW_REGEN] != 0; + bs->inventory[INVENTORY_FLIGHT] = bs->cur_ps.powerups[PW_FLIGHT] != 0; + bs->inventory[INVENTORY_REDFLAG] = bs->cur_ps.powerups[PW_REDFLAG] != 0; + bs->inventory[INVENTORY_BLUEFLAG] = bs->cur_ps.powerups[PW_BLUEFLAG] != 0; + // +} + +/* +================== +BotUpdateBattleInventory +================== +*/ +void BotUpdateBattleInventory( bot_state_t *bs, int enemy ) { + vec3_t dir; + aas_entityinfo_t entinfo; + + BotEntityInfo( enemy, &entinfo ); + VectorSubtract( entinfo.origin, bs->origin, dir ); + bs->inventory[ENEMY_HEIGHT] = (int) dir[2]; + dir[2] = 0; + bs->inventory[ENEMY_HORIZONTAL_DIST] = (int) VectorLength( dir ); + //FIXME: add num visible enemies and num visible team mates to the inventory +} + +/* +================== +BotBattleUseItems +================== +*/ +void BotBattleUseItems( bot_state_t *bs ) { + if ( bs->inventory[INVENTORY_HEALTH] < 40 ) { + if ( bs->inventory[INVENTORY_TELEPORTER] > 0 ) { + trap_EA_Use( bs->client ); + } + if ( bs->inventory[INVENTORY_MEDKIT] > 0 ) { + trap_EA_Use( bs->client ); + } + } +} + +/* +================== +BotSetTeleportTime +================== +*/ +void BotSetTeleportTime( bot_state_t *bs ) { + if ( ( bs->cur_ps.eFlags ^ bs->last_eFlags ) & EF_TELEPORT_BIT ) { + bs->teleport_time = trap_AAS_Time(); + } + bs->last_eFlags = bs->cur_ps.eFlags; +} + +/* +================== +BotIsDead +================== +*/ +qboolean BotIsDead( bot_state_t *bs ) { + return ( bs->cur_ps.pm_type == PM_DEAD ); +} + +/* +================== +BotIsObserver +================== +*/ +qboolean BotIsObserver( bot_state_t *bs ) { + char buf[MAX_INFO_STRING]; + if ( bs->cur_ps.pm_type == PM_SPECTATOR ) { + return qtrue; + } + trap_GetConfigstring( CS_PLAYERS + bs->client, buf, sizeof( buf ) ); + if ( atoi( Info_ValueForKey( buf, "t" ) ) == TEAM_SPECTATOR ) { + return qtrue; + } + return qfalse; +} + +/* +================== +BotIntermission +================== +*/ +qboolean BotIntermission( bot_state_t *bs ) { + //NOTE: we shouldn't look at the game code... + if ( level.intermissiontime ) { + return qtrue; + } + return ( bs->cur_ps.pm_type == PM_FREEZE || bs->cur_ps.pm_type == PM_INTERMISSION ); +} + + +/* +============== +BotInLava +============== +*/ +qboolean BotInLava( bot_state_t *bs ) { + vec3_t feet; + + VectorCopy( bs->origin, feet ); + feet[2] -= 23; + return ( trap_AAS_PointContents( feet ) & CONTENTS_LAVA ); +} + +/* +============== +BotInSlime +============== +*/ +qboolean BotInSlime( bot_state_t *bs ) { + vec3_t feet; + + VectorCopy( bs->origin, feet ); + feet[2] -= 23; + return ( trap_AAS_PointContents( feet ) & CONTENTS_SLIME ); +} + +/* +================== +EntityIsDead +================== +*/ +qboolean EntityIsDead( aas_entityinfo_t *entinfo ) { + playerState_t ps; + + if ( entinfo->number >= 0 && entinfo->number < MAX_CLIENTS ) { + //retrieve the current client state + BotAI_GetClientState( entinfo->number, &ps ); + if ( ps.pm_type != PM_NORMAL ) { + return qtrue; + } + } + return qfalse; +} + +/* +================== +EntityIsInvisible +================== +*/ +qboolean EntityIsInvisible( aas_entityinfo_t *entinfo ) { + if ( entinfo->powerups & ( 1 << PW_INVIS ) ) { + return qtrue; + } + return qfalse; +} + +/* +================== +EntityIsShooting +================== +*/ +qboolean EntityIsShooting( aas_entityinfo_t *entinfo ) { + if ( entinfo->flags & EF_FIRING ) { + return qtrue; + } + return qfalse; +} + +/* +================== +EntityIsChatting +================== +*/ +qboolean EntityIsChatting( aas_entityinfo_t *entinfo ) { + if ( entinfo->flags & EF_TALK ) { + return qtrue; + } + return qfalse; +} + +/* +================== +EntityHasQuad +================== +*/ +qboolean EntityHasQuad( aas_entityinfo_t *entinfo ) { + if ( entinfo->powerups & ( 1 << PW_QUAD ) ) { + return qtrue; + } + return qfalse; +} + +/* +================== +BotCreateWayPoint +================== +*/ +bot_waypoint_t *BotCreateWayPoint( char *name, vec3_t origin, int areanum ) { + bot_waypoint_t *wp; + vec3_t waypointmins = {-8, -8, -8}, waypointmaxs = {8, 8, 8}; + + wp = botai_freewaypoints; + if ( !wp ) { + BotAI_Print( PRT_WARNING, "BotCreateWayPoint: Out of waypoints\n" ); + return NULL; + } + botai_freewaypoints = botai_freewaypoints->next; + + Q_strncpyz( wp->name, name, sizeof( wp->name ) ); + VectorCopy( origin, wp->goal.origin ); + VectorCopy( waypointmins, wp->goal.mins ); + VectorCopy( waypointmaxs, wp->goal.maxs ); + wp->goal.areanum = areanum; + wp->next = NULL; + wp->prev = NULL; + return wp; +} + +/* +================== +BotFindWayPoint +================== +*/ +bot_waypoint_t *BotFindWayPoint( bot_waypoint_t *waypoints, char *name ) { + bot_waypoint_t *wp; + + for ( wp = waypoints; wp; wp = wp->next ) { + if ( !Q_stricmp( wp->name, name ) ) { + return wp; + } + } + return NULL; +} + +/* +================== +BotFreeWaypoints +================== +*/ +void BotFreeWaypoints( bot_waypoint_t *wp ) { + bot_waypoint_t *nextwp; + + for (; wp; wp = nextwp ) { + nextwp = wp->next; + wp->next = botai_freewaypoints; + botai_freewaypoints = wp; + } +} + +/* +================== +BotInitWaypoints +================== +*/ +void BotInitWaypoints( void ) { + int i; + + botai_freewaypoints = NULL; + for ( i = 0; i < MAX_WAYPOINTS; i++ ) { + botai_waypoints[i].next = botai_freewaypoints; + botai_freewaypoints = &botai_waypoints[i]; + } +} + +/* +================== +TeamPlayIsOn +================== +*/ +int TeamPlayIsOn( void ) { + return ( gametype == GT_TEAM || gametype == GT_CTF ); +} + +/* +================== +BotAggression + +FIXME: move this to external fuzzy logic + + NOTE!!: I made no changes to this code for wolf weapon awareness. (SA) +================== +*/ +float BotAggression( bot_state_t *bs ) { + //if the bot has quad + if ( bs->inventory[INVENTORY_QUAD] ) { + //if the bot is not holding the gauntlet or the enemy is really nearby + if ( bs->weaponnum != WP_GAUNTLET || + bs->inventory[ENEMY_HORIZONTAL_DIST] < 80 ) { + return 70; + } + } + //if the enemy is located way higher than the bot + if ( bs->inventory[ENEMY_HEIGHT] > 200 ) { + return 0; + } + //if the bot is very low on health + if ( bs->inventory[INVENTORY_HEALTH] < 60 ) { + return 0; + } + //if the bot is low on health + if ( bs->inventory[INVENTORY_HEALTH] < 80 ) { + //if the bot has insufficient armor + if ( bs->inventory[INVENTORY_ARMOR] < 40 ) { + return 0; + } + } +// //if the bot can use the bfg +// if (bs->inventory[INVENTORY_BFG10K] > 0 && +// bs->inventory[INVENTORY_BFGAMMO] > 7) return 100; +// //if the bot can use the railgun +// if (bs->inventory[INVENTORY_RAILGUN] > 0 && +// bs->inventory[INVENTORY_SLUGS] > 5) return 95; + //if the bot can use the lightning gun + if ( bs->inventory[INVENTORY_FLAMETHROWER] > 0 && + bs->inventory[INVENTORY_FUEL] > 50 ) { + return 90; + } + //if the bot can use the rocketlauncher + if ( bs->inventory[INVENTORY_ROCKETLAUNCHER] > 0 && + bs->inventory[INVENTORY_ROCKETS] > 5 ) { + return 90; + } + //if the bot can use the SP5 + if ( bs->inventory[INVENTORY_SP5] > 0 && + bs->inventory[INVENTORY_SP5AMMO] > 40 ) { + return 85; + } + //if the bot can use the grenade launcher + if ( bs->inventory[INVENTORY_GRENADELAUNCHER] > 0 && + bs->inventory[INVENTORY_GRENADES] > 10 ) { + return 80; + } +// //if the bot can use the shotgun +// if (bs->inventory[INVENTORY_SHOTGUN] > 0 && +// bs->inventory[INVENTORY_SHELLS] > 10) return 50; + //otherwise the bot is not feeling too good + return 0; +} + +/* +================== +BotWantsToRetreat +================== +*/ +int BotWantsToRetreat( bot_state_t *bs ) { +#ifdef CTF + //always retreat when carrying a CTF flag + if ( BotCTFCarryingFlag( bs ) ) { + return qtrue; + } + //if the bot is getting the flag + if ( bs->ltgtype == LTG_GETFLAG ) { + return qtrue; + } +#endif //CTF + if ( BotAggression( bs ) < 50 ) { + return qtrue; + } + return qfalse; +} + +/* +================== +BotWantsToChase +================== +*/ +int BotWantsToChase( bot_state_t *bs ) { +#ifdef CTF + //always retreat when carrying a CTF flag + if ( BotCTFCarryingFlag( bs ) ) { + return qfalse; + } + //if the bot is getting the flag + if ( bs->ltgtype == LTG_GETFLAG ) { + return qfalse; + } +#endif //CTF + if ( BotAggression( bs ) > 50 ) { + return qtrue; + } + return qfalse; +} + +/* +================== +BotWantsToHelp +================== +*/ +int BotWantsToHelp( bot_state_t *bs ) { + return qtrue; +} + +/* +================== +BotCanAndWantsToRocketJump +================== +*/ +int BotCanAndWantsToRocketJump( bot_state_t *bs ) { + float rocketjumper; + + //if rocket jumping is disabled + if ( !bot_rocketjump.integer ) { + return qfalse; + } + //if no rocket launcher + if ( bs->inventory[INVENTORY_ROCKETLAUNCHER] <= 0 ) { + return qfalse; + } + //if low on rockets + if ( bs->inventory[INVENTORY_ROCKETS] < 3 ) { + return qfalse; + } + //never rocket jump with the Quad + if ( bs->inventory[INVENTORY_QUAD] ) { + return qfalse; + } + //if low on health + if ( bs->inventory[INVENTORY_HEALTH] < 60 ) { + return qfalse; + } + //if not full health + if ( bs->inventory[INVENTORY_HEALTH] < 90 ) { + //if the bot has insufficient armor + if ( bs->inventory[INVENTORY_ARMOR] < 40 ) { + return qfalse; + } + } + rocketjumper = trap_Characteristic_BFloat( bs->character, CHARACTERISTIC_WEAPONJUMPING, 0, 1 ); + if ( rocketjumper < 0.5 ) { + return qfalse; + } + return qtrue; +} + +/* +================== +BotGoCamp +================== +*/ +void BotGoCamp( bot_state_t *bs, bot_goal_t *goal ) { + float camper; + + //set message time to zero so bot will NOT show any message + bs->teammessage_time = 0; + //set the ltg type + bs->ltgtype = LTG_CAMP; + //set the team goal + memcpy( &bs->teamgoal, goal, sizeof( bot_goal_t ) ); + //get the team goal time + camper = trap_Characteristic_BFloat( bs->character, CHARACTERISTIC_CAMPER, 0, 1 ); + if ( camper > 0.99 ) { + bs->teamgoal_time = 99999; + } else { bs->teamgoal_time = 120 + 180 * camper + random() * 15;} + //set the last time the bot started camping + bs->camp_time = trap_AAS_Time(); + //the teammate that requested the camping + bs->teammate = 0; + //do NOT type arrive message + bs->arrive_time = 1; +} + +/* +================== +BotWantsToCamp +================== +*/ +int BotWantsToCamp( bot_state_t *bs ) { + float camper; + int cs, traveltime, besttraveltime; + bot_goal_t goal, bestgoal; + + camper = trap_Characteristic_BFloat( bs->character, CHARACTERISTIC_CAMPER, 0, 1 ); + if ( camper < 0.1 ) { + return qfalse; + } + //if the bot has a team goal + if ( bs->ltgtype == LTG_TEAMHELP || + bs->ltgtype == LTG_TEAMACCOMPANY || + bs->ltgtype == LTG_DEFENDKEYAREA || + bs->ltgtype == LTG_GETFLAG || + bs->ltgtype == LTG_RUSHBASE || + bs->ltgtype == LTG_CAMP || + bs->ltgtype == LTG_CAMPORDER || + bs->ltgtype == LTG_PATROL ) { + return qfalse; + } + //if camped recently + if ( bs->camp_time > trap_AAS_Time() - 60 + 300 * ( 1 - camper ) ) { + return qfalse; + } + // + if ( random() > camper ) { + bs->camp_time = trap_AAS_Time(); + return qfalse; + } + //if the bot isn't healthy anough + if ( BotAggression( bs ) < 50 ) { + return qfalse; + } + //the bot should have at least have the rocket launcher, the railgun or the bfg10k with some ammo + if ( ( bs->inventory[INVENTORY_ROCKETLAUNCHER] <= 0 || bs->inventory[INVENTORY_ROCKETS < 10] ) +// && (bs->inventory[INVENTORY_RAILGUN] <= 0 || bs->inventory[INVENTORY_SLUGS] < 10) +// && (bs->inventory[INVENTORY_BFG10K] <= 0 || bs->inventory[INVENTORY_BFGAMMO] < 10) + ) { + return qfalse; + } + //find the closest camp spot + besttraveltime = 99999; + for ( cs = trap_BotGetNextCampSpotGoal( 0, &goal ); cs; cs = trap_BotGetNextCampSpotGoal( cs, &goal ) ) { + traveltime = trap_AAS_AreaTravelTimeToGoalArea( bs->areanum, bs->origin, goal.areanum, TFL_DEFAULT ); + if ( traveltime && traveltime < besttraveltime ) { + besttraveltime = traveltime; + memcpy( &bestgoal, &goal, sizeof( bot_goal_t ) ); + } + } + if ( besttraveltime > 150 ) { + return qfalse; + } + //ok found a camp spot, go camp there + BotGoCamp( bs, &bestgoal ); + // + return qtrue; +} + +/* +================== +BotDontAvoid +================== +*/ +void BotDontAvoid( bot_state_t *bs, char *itemname ) { + bot_goal_t goal; + int num; + + num = trap_BotGetLevelItemGoal( -1, itemname, &goal ); + while ( num >= 0 ) { + trap_BotRemoveFromAvoidGoals( bs->gs, goal.number ); + num = trap_BotGetLevelItemGoal( num, itemname, &goal ); + } +} + +/* +================== +BotGoForPowerups +================== +*/ +void BotGoForPowerups( bot_state_t *bs ) { + + //don't avoid any of the powerups anymore + BotDontAvoid( bs, "Quad Damage" ); + BotDontAvoid( bs, "Regeneration" ); + BotDontAvoid( bs, "Battle Suit" ); + BotDontAvoid( bs, "Speed" ); + BotDontAvoid( bs, "Invisibility" ); + //BotDontAvoid(bs, "Flight"); + //reset the long term goal time so the bot will go for the powerup + //NOTE: the long term goal type doesn't change + bs->ltg_time = 0; +} + +/* +================== +BotRoamGoal +================== +*/ +void BotRoamGoal( bot_state_t *bs, vec3_t goal ) { + float len, r1, r2, sign, n; + int pc; + vec3_t dir, bestorg, belowbestorg; + bsp_trace_t trace; + + for ( n = 0; n < 10; n++ ) { + //start at the bot origin + VectorCopy( bs->origin, bestorg ); + r1 = random(); + if ( r1 < 0.8 ) { + //add a random value to the x-coordinate + r2 = random(); + if ( r2 < 0.5 ) { + sign = -1; + } else { sign = 1;} + bestorg[0] += sign * 700 * random() + 50; + } + if ( r1 > 0.2 ) { + //add a random value to the y-coordinate + r2 = random(); + if ( r2 < 0.5 ) { + sign = -1; + } else { sign = 1;} + bestorg[1] += sign * 700 * random() + 50; + } + //add a random value to the z-coordinate (NOTE: 48 = maxjump?) + bestorg[2] += 3 * 48 * random() - 2 * 48 - 1; + //trace a line from the origin to the roam target + BotAI_Trace( &trace, bs->origin, NULL, NULL, bestorg, bs->entitynum, MASK_SOLID ); + //direction and length towards the roam target + VectorSubtract( bestorg, bs->origin, dir ); + len = VectorNormalize( dir ); + //if the roam target is far away anough + if ( len > 200 ) { + //the roam target is in the given direction before walls + VectorScale( dir, len * trace.fraction - 40, dir ); + VectorAdd( bs->origin, dir, bestorg ); + //get the coordinates of the floor below the roam target + belowbestorg[0] = bestorg[0]; + belowbestorg[1] = bestorg[1]; + belowbestorg[2] = bestorg[2] - 800; + BotAI_Trace( &trace, bestorg, NULL, NULL, belowbestorg, bs->entitynum, MASK_SOLID ); + // + if ( !trace.startsolid ) { + trace.endpos[2]++; + pc = trap_PointContents( trace.endpos,bs->entitynum ); + if ( !( pc & CONTENTS_LAVA ) ) { //----(SA) modified since slime is no longer deadly +// if (!(pc & (CONTENTS_LAVA | CONTENTS_SLIME))) { + VectorCopy( bestorg, goal ); + return; + } + } + } + } + VectorCopy( bestorg, goal ); +} + +/* +================== +BotAttackMove +================== +*/ +bot_moveresult_t BotAttackMove( bot_state_t *bs, int tfl ) { + int movetype, i; + float attack_skill, jumper, croucher, dist, strafechange_time; + float attack_dist, attack_range; + vec3_t forward, backward, sideward, hordir, up = {0, 0, 1}; + aas_entityinfo_t entinfo; + bot_moveresult_t moveresult; + bot_goal_t goal; + + if ( bs->attackchase_time > trap_AAS_Time() ) { + //create the chase goal + goal.entitynum = bs->enemy; + goal.areanum = bs->lastenemyareanum; + VectorCopy( bs->lastenemyorigin, goal.origin ); + VectorSet( goal.mins, -8, -8, -8 ); + VectorSet( goal.maxs, 8, 8, 8 ); + //initialize the movement state + BotSetupForMovement( bs ); + //move towards the goal + trap_BotMoveToGoal( &moveresult, bs->ms, &goal, tfl ); + return moveresult; + } + // + memset( &moveresult, 0, sizeof( bot_moveresult_t ) ); + // + attack_skill = trap_Characteristic_BFloat( bs->character, CHARACTERISTIC_ATTACK_SKILL, 0, 1 ); + jumper = trap_Characteristic_BFloat( bs->character, CHARACTERISTIC_JUMPER, 0, 1 ); + croucher = trap_Characteristic_BFloat( bs->character, CHARACTERISTIC_CROUCHER, 0, 1 ); + //if the bot is really stupid + if ( attack_skill < 0.2 ) { + return moveresult; + } + //initialize the movement state + BotSetupForMovement( bs ); + //get the enemy entity info + BotEntityInfo( bs->enemy, &entinfo ); + //direction towards the enemy + VectorSubtract( entinfo.origin, bs->origin, forward ); + //the distance towards the enemy + dist = VectorNormalize( forward ); + VectorNegate( forward, backward ); + //walk, crouch or jump + movetype = MOVE_WALK; + // + if ( bs->attackcrouch_time < trap_AAS_Time() - 1 ) { + if ( random() < jumper ) { + movetype = MOVE_JUMP; + } + //wait at least one second before crouching again + else if ( bs->attackcrouch_time < trap_AAS_Time() - 1 && random() < croucher ) { + bs->attackcrouch_time = trap_AAS_Time() + croucher * 5; + } + } + if ( bs->attackcrouch_time > trap_AAS_Time() ) { + movetype = MOVE_CROUCH; + } + //if the bot should jump + if ( movetype == MOVE_JUMP ) { + //if jumped last frame + if ( bs->attackjump_time > trap_AAS_Time() ) { + movetype = MOVE_WALK; + } else { + bs->attackjump_time = trap_AAS_Time() + 1; + } + } + if ( bs->cur_ps.weapon == WP_GAUNTLET ) { + attack_dist = 0; + attack_range = 0; + } else { + attack_dist = IDEAL_ATTACKDIST; + attack_range = 40; + } + //if the bot is stupid + if ( attack_skill <= 0.4 ) { + //just walk to or away from the enemy + if ( dist > attack_dist + attack_range ) { + if ( trap_BotMoveInDirection( bs->ms, forward, 400, movetype ) ) { + return moveresult; + } + } + if ( dist < attack_dist - attack_range ) { + if ( trap_BotMoveInDirection( bs->ms, backward, 400, movetype ) ) { + return moveresult; + } + } + return moveresult; + } + //increase the strafe time + bs->attackstrafe_time += bs->thinktime; + //get the strafe change time + strafechange_time = 0.4 + ( 1 - attack_skill ) * 0.2; + if ( attack_skill > 0.7 ) { + strafechange_time += crandom() * 0.2; + } + //if the strafe direction should be changed + if ( bs->attackstrafe_time > strafechange_time ) { + //some magic number :) + if ( random() > 0.935 ) { + //flip the strafe direction + bs->flags ^= BFL_STRAFERIGHT; + bs->attackstrafe_time = 0; + } + } + // + for ( i = 0; i < 2; i++ ) { + hordir[0] = forward[0]; + hordir[1] = forward[1]; + hordir[2] = 0; + VectorNormalize( hordir ); + //get the sideward vector + CrossProduct( hordir, up, sideward ); + //reverse the vector depending on the strafe direction + if ( bs->flags & BFL_STRAFERIGHT ) { + VectorNegate( sideward, sideward ); + } + //randomly go back a little + if ( random() > 0.9 ) { + VectorAdd( sideward, backward, sideward ); + } else { + //walk forward or backward to get at the ideal attack distance + if ( dist > attack_dist + attack_range ) { + VectorAdd( sideward, forward, sideward ); + } else if ( dist < attack_dist - attack_range ) { + VectorAdd( sideward, backward, sideward ); + } + } + //perform the movement + if ( trap_BotMoveInDirection( bs->ms, sideward, 400, movetype ) ) { + return moveresult; + } + //movement failed, flip the strafe direction + bs->flags ^= BFL_STRAFERIGHT; + bs->attackstrafe_time = 0; + } + //bot couldn't do any usefull movement +// bs->attackchase_time = AAS_Time() + 6; + return moveresult; +} + +/* +================== +BotSameTeam +================== +*/ +int BotSameTeam( bot_state_t *bs, int entnum ) { + char info1[128], info2[128]; + + if ( bs->client < 0 || bs->client >= MAX_CLIENTS ) { + //BotAI_Print(PRT_ERROR, "BotSameTeam: client out of range\n"); + return qfalse; + } + if ( entnum < 0 || entnum >= MAX_CLIENTS ) { + //BotAI_Print(PRT_ERROR, "BotSameTeam: client out of range\n"); + return qfalse; + } + if ( gametype == GT_TEAM || gametype == GT_CTF ) { + trap_GetConfigstring( CS_PLAYERS + bs->client, info1, sizeof( info1 ) ); + trap_GetConfigstring( CS_PLAYERS + entnum, info2, sizeof( info2 ) ); + // + if ( atoi( Info_ValueForKey( info1, "t" ) ) == atoi( Info_ValueForKey( info2, "t" ) ) ) { + return qtrue; + } + } + return qfalse; +} + +/* +================== +InFieldOfVision +================== +*/ +qboolean InFieldOfVision( vec3_t viewangles, float fov, vec3_t angles ) { + int i; + float diff, angle; + + for ( i = 0; i < 2; i++ ) { + angle = AngleMod( viewangles[i] ); + angles[i] = AngleMod( angles[i] ); + diff = angles[i] - angle; + if ( angles[i] > angle ) { + if ( diff > 180.0 ) { + diff -= 360.0; + } + } else { + if ( diff < -180.0 ) { + diff += 360.0; + } + } + if ( diff > 0 ) { + if ( diff > fov * 0.5 ) { + return qfalse; + } + } else { + if ( diff < -fov * 0.5 ) { + return qfalse; + } + } + } + return qtrue; +} + +/* +================== +BotEntityVisible + +returns visibility in the range [0, 1] taking fog and water surfaces into account +================== +*/ +float BotEntityVisible( int viewer, vec3_t eye, vec3_t viewangles, float fov, int ent ) { + int i, contents_mask, passent, hitent, infog, inwater, otherinfog, pc; + float fogdist, waterfactor, vis, bestvis; + bsp_trace_t trace; + aas_entityinfo_t entinfo; + vec3_t dir, entangles, start, end, middle; + + //calculate middle of bounding box + BotEntityInfo( ent, &entinfo ); + VectorAdd( entinfo.mins, entinfo.maxs, middle ); + VectorScale( middle, 0.5, middle ); + VectorAdd( entinfo.origin, middle, middle ); + //check if entity is within field of vision + VectorSubtract( middle, eye, dir ); + vectoangles( dir, entangles ); + if ( !InFieldOfVision( viewangles, fov, entangles ) ) { + return 0; + } + // + pc = trap_AAS_PointContents( eye ); + infog = ( pc & CONTENTS_SOLID ); + inwater = ( pc & ( CONTENTS_LAVA | CONTENTS_SLIME | CONTENTS_WATER ) ); + // + bestvis = 0; + for ( i = 0; i < 3; i++ ) { + //if the point is not in potential visible sight + //if (!AAS_inPVS(eye, middle)) continue; + // + contents_mask = CONTENTS_SOLID | CONTENTS_PLAYERCLIP; + passent = viewer; + hitent = ent; + VectorCopy( eye, start ); + VectorCopy( middle, end ); + //if the entity is in water, lava or slime + if ( trap_AAS_PointContents( middle ) & ( CONTENTS_LAVA | CONTENTS_SLIME | CONTENTS_WATER ) ) { + contents_mask |= ( CONTENTS_LAVA | CONTENTS_SLIME | CONTENTS_WATER ); + } + //if eye is in water, lava or slime + if ( inwater ) { + if ( !( contents_mask & ( CONTENTS_LAVA | CONTENTS_SLIME | CONTENTS_WATER ) ) ) { + passent = ent; + hitent = viewer; + VectorCopy( middle, start ); + VectorCopy( eye, end ); + } + contents_mask ^= ( CONTENTS_LAVA | CONTENTS_SLIME | CONTENTS_WATER ); + } + //trace from start to end + BotAI_Trace( &trace, start, NULL, NULL, end, passent, contents_mask ); + //if water was hit + waterfactor = 1.0; + if ( trace.contents & ( CONTENTS_LAVA | CONTENTS_SLIME | CONTENTS_WATER ) ) { + //if the water surface is translucent + if ( 1 ) { + //trace through the water + contents_mask &= ~( CONTENTS_LAVA | CONTENTS_SLIME | CONTENTS_WATER ); + BotAI_Trace( &trace, trace.endpos, NULL, NULL, end, passent, contents_mask ); + waterfactor = 0.5; + } + } + //if a full trace or the hitent was hit + if ( trace.fraction >= 1 || trace.ent == hitent ) { + //check for fog, assuming there's only one fog brush where + //either the viewer or the entity is in or both are in + otherinfog = ( trap_AAS_PointContents( middle ) & CONTENTS_FOG ); + if ( infog && otherinfog ) { + VectorSubtract( trace.endpos, eye, dir ); + fogdist = VectorLength( dir ); + } else if ( infog ) { + VectorCopy( trace.endpos, start ); + BotAI_Trace( &trace, start, NULL, NULL, eye, viewer, CONTENTS_FOG ); + VectorSubtract( eye, trace.endpos, dir ); + fogdist = VectorLength( dir ); + } else if ( otherinfog ) { + VectorCopy( trace.endpos, end ); + BotAI_Trace( &trace, eye, NULL, NULL, end, viewer, CONTENTS_FOG ); + VectorSubtract( end, trace.endpos, dir ); + fogdist = VectorLength( dir ); + } else { + //if the entity and the viewer are not in fog assume there's no fog in between + fogdist = 0; + } + //decrease visibility with the view distance through fog + vis = 1 / ( ( fogdist * fogdist * 0.001 ) < 1 ? 1 : ( fogdist * fogdist * 0.001 ) ); + //if entering water visibility is reduced + vis *= waterfactor; + // + if ( vis > bestvis ) { + bestvis = vis; + } + //if pretty much no fog + if ( bestvis >= 0.95 ) { + return bestvis; + } + } + //check bottom and top of bounding box as well + if ( i == 0 ) { + middle[2] += entinfo.mins[2]; + } else if ( i == 1 ) { + middle[2] += entinfo.maxs[2] - entinfo.mins[2]; + } + } + return bestvis; +} + +/* +================== +BotFindEnemy +================== +*/ +int BotFindEnemy( bot_state_t *bs, int curenemy ) { + int i, healthdecrease; + float fov, dist, curdist, alertness, easyfragger, vis; + aas_entityinfo_t entinfo, curenemyinfo; + vec3_t dir, angles; + + alertness = trap_Characteristic_BFloat( bs->character, CHARACTERISTIC_ALERTNESS, 0, 1 ); + easyfragger = trap_Characteristic_BFloat( bs->character, CHARACTERISTIC_EASY_FRAGGER, 0, 1 ); + //check if the health decreased + healthdecrease = bs->lasthealth > bs->inventory[INVENTORY_HEALTH]; + //remember the current health value + bs->lasthealth = bs->inventory[INVENTORY_HEALTH]; + // + if ( curenemy >= 0 ) { + BotEntityInfo( curenemy, &curenemyinfo ); + VectorSubtract( curenemyinfo.origin, bs->origin, dir ); + curdist = VectorLength( dir ); + } else { + curdist = 0; + } + // + for ( i = 0; i < MAX_CLIENTS; i++ ) { + + if ( i == bs->client ) { + continue; + } + //if it's the current enemy + if ( i == curenemy ) { + continue; + } + // + BotEntityInfo( i, &entinfo ); + // + if ( !entinfo.valid ) { + continue; + } + //if the enemy isn't dead and the enemy isn't the bot self + if ( EntityIsDead( &entinfo ) || entinfo.number == bs->entitynum ) { + continue; + } + //if the enemy is invisible and not shooting + if ( EntityIsInvisible( &entinfo ) && !EntityIsShooting( &entinfo ) ) { + continue; + } + //if not an easy fragger don't shoot at chatting players + if ( easyfragger < 0.5 && EntityIsChatting( &entinfo ) ) { + continue; + } + // + if ( lastteleport_time > trap_AAS_Time() - 3 ) { + VectorSubtract( entinfo.origin, lastteleport_origin, dir ); + if ( VectorLength( dir ) < 70 ) { + continue; + } + } + //calculate the distance towards the enemy + VectorSubtract( entinfo.origin, bs->origin, dir ); + dist = VectorLength( dir ); + //if this enemy is further away than the current one + if ( curenemy >= 0 && dist > curdist ) { + continue; + } + //if the bot has no + if ( dist > 900 + alertness * 4000 ) { + continue; + } + //if on the same team + if ( BotSameTeam( bs, i ) ) { + continue; + } + //if the bot's health decreased or the enemy is shooting + if ( curenemy < 0 && ( healthdecrease || EntityIsShooting( &entinfo ) ) ) { + fov = 360; + } else { fov = 90 + 270 - ( 270 - ( dist > 810 ? 810 : dist ) / 3 );} + //check if the enemy visibility + vis = BotEntityVisible( bs->entitynum, bs->eye, bs->viewangles, fov, i ); + if ( vis <= 0 ) { + continue; + } + //if the enemy is quite far away, not shooting and the bot is not damaged + if ( curenemy < 0 && dist > 200 && !healthdecrease && !EntityIsShooting( &entinfo ) ) { + //check if we can avoid this enemy + VectorSubtract( bs->origin, entinfo.origin, dir ); + vectoangles( dir, angles ); + //if the bot isn't in the fov of the enemy + if ( !InFieldOfVision( entinfo.angles, 120, angles ) ) { + //update some stuff for this enemy + BotUpdateBattleInventory( bs, i ); + //if the bot doesn't really want to fight + if ( BotWantsToRetreat( bs ) ) { + continue; + } + } + } + //found an enemy + bs->enemy = entinfo.number; + if ( curenemy >= 0 ) { + bs->enemysight_time = trap_AAS_Time() - 2; + } else { bs->enemysight_time = trap_AAS_Time();} + bs->enemysuicide = qfalse; + bs->enemydeath_time = 0; + return qtrue; + } + return qfalse; +} + +/* +================== +BotAimAtEnemy +================== +*/ +void BotAimAtEnemy( bot_state_t *bs ) { + int i, enemyvisible; + float dist, f, aim_skill, aim_accuracy, speed, reactiontime; + vec3_t dir, bestorigin, end, start, groundtarget, cmdmove, enemyvelocity; + vec3_t mins = {-4,-4,-4}, maxs = {4, 4, 4}; + weaponinfo_t wi; + aas_entityinfo_t entinfo; + bot_goal_t goal; + bsp_trace_t trace; + vec3_t target; + + //if the bot has no enemy + if ( bs->enemy < 0 ) { + return; + } + // + //BotAI_Print(PRT_MESSAGE, "client %d: aiming at client %d\n", bs->entitynum, bs->enemy); + // + aim_skill = trap_Characteristic_BFloat( bs->character, CHARACTERISTIC_AIM_SKILL, 0, 1 ); + aim_accuracy = trap_Characteristic_BFloat( bs->character, CHARACTERISTIC_AIM_ACCURACY, 0, 1 ); + // + if ( aim_skill > 0.95 ) { + //don't aim too early + reactiontime = 0.5 * trap_Characteristic_BFloat( bs->character, CHARACTERISTIC_REACTIONTIME, 0, 1 ); + if ( bs->enemysight_time > trap_AAS_Time() - reactiontime ) { + return; + } + if ( bs->teleport_time > trap_AAS_Time() - reactiontime ) { + return; + } + } + + //get the weapon information + trap_BotGetWeaponInfo( bs->ws, bs->weaponnum, &wi ); + //get the weapon specific aim accuracy and or aim skill +//----(SA) commented out the weapons that aren't ours. +//----(SA) if we're not using this routine at all and my changes are irrelivant, please let me know. +// if (wi.number == WP_MACHINEGUN) { +// aim_accuracy = trap_Characteristic_BFloat(bs->character, CHARACTERISTIC_AIM_ACCURACY_MACHINEGUN, 0, 1); +// } +// if (wi.number == WP_SHOTGUN) { +// aim_accuracy = trap_Characteristic_BFloat(bs->character, CHARACTERISTIC_AIM_ACCURACY_SHOTGUN, 0, 1); +// } + if ( wi.number == WP_GRENADE_LAUNCHER ) { + aim_accuracy = trap_Characteristic_BFloat( bs->character, CHARACTERISTIC_AIM_ACCURACY_GRENADELAUNCHER, 0, 1 ); + aim_skill = trap_Characteristic_BFloat( bs->character, CHARACTERISTIC_AIM_SKILL_GRENADELAUNCHER, 0, 1 ); + } + if ( wi.number == WP_FLAMETHROWER ) { + aim_accuracy = trap_Characteristic_BFloat( bs->character, CHARACTERISTIC_AIM_ACCURACY_LIGHTNING, 0, 1 ); + } +// if (wi.number == WP_RAILGUN) { +// aim_accuracy = trap_Characteristic_BFloat(bs->character, CHARACTERISTIC_AIM_ACCURACY_RAILGUN, 0, 1); +// } + if ( wi.number == WP_SILENCER ) { + aim_accuracy = trap_Characteristic_BFloat( bs->character, CHARACTERISTIC_AIM_ACCURACY_SP5, 0, 1 ); + aim_skill = trap_Characteristic_BFloat( bs->character, CHARACTERISTIC_AIM_SKILL_SP5, 0, 1 ); + } +// if (wi.number == WP_BFG) { +// aim_accuracy = trap_Characteristic_BFloat(bs->character, CHARACTERISTIC_AIM_ACCURACY_BFG10K, 0, 1); +// aim_skill = trap_Characteristic_BFloat(bs->character, CHARACTERISTIC_AIM_SKILL_BFG10K, 0, 1); +// } + // + if ( aim_accuracy <= 0 ) { + aim_accuracy = 0.0001; + } + //get the enemy entity information + BotEntityInfo( bs->enemy, &entinfo ); + //if the enemy is invisible then shoot crappy most of the time + if ( EntityIsInvisible( &entinfo ) ) { + if ( random() > 0.1 ) { + aim_accuracy *= 0.4; + } + } + // + VectorSubtract( entinfo.origin, entinfo.lastvisorigin, enemyvelocity ); + VectorScale( enemyvelocity, 1 / entinfo.update_time, enemyvelocity ); + //enemy origin and velocity is remembered every 0.5 seconds + if ( bs->enemyposition_time < trap_AAS_Time() ) { + // + bs->enemyposition_time = trap_AAS_Time() + 0.5; + VectorCopy( enemyvelocity, bs->enemyvelocity ); + VectorCopy( entinfo.origin, bs->enemyorigin ); + } + //if not extremely skilled + if ( aim_skill < 0.9 ) { + VectorSubtract( entinfo.origin, bs->enemyorigin, dir ); + //if the enemy moved a bit + if ( VectorLength( dir ) > 48 ) { + //if the enemy changed direction + if ( DotProduct( bs->enemyvelocity, enemyvelocity ) < 0 ) { + //aim accuracy should be worse now + aim_accuracy *= 0.7; + } + } + } + //check visibility of enemy + enemyvisible = BotEntityVisible( bs->entitynum, bs->eye, bs->viewangles, 360, bs->enemy ); + //if the enemy is visible + if ( enemyvisible ) { + // + VectorCopy( entinfo.origin, bestorigin ); + bestorigin[2] += 8; + //get the start point shooting from + //NOTE: the x and y projectile start offsets are ignored + VectorCopy( bs->origin, start ); + start[2] += bs->cur_ps.viewheight; + start[2] += wi.offset[2]; + // + BotAI_Trace( &trace, start, mins, maxs, bestorigin, bs->entitynum, MASK_SHOT ); + //if the enemy is NOT hit + if ( trace.fraction <= 1 && trace.ent != entinfo.number ) { + bestorigin[2] += 16; + } + //if it is not an instant hit weapon the bot might want to predict the enemy + if ( wi.speed ) { + // + VectorSubtract( bestorigin, bs->origin, dir ); + dist = VectorLength( dir ); + VectorSubtract( entinfo.origin, bs->enemyorigin, dir ); + //if the enemy is NOT pretty far away and strafing just small steps left and right + if ( !( dist > 100 && VectorLength( dir ) < 32 ) ) { + //if skilled anough do exact prediction + if ( aim_skill > 0.8 && + //if the weapon is ready to fire + bs->cur_ps.weaponstate == WEAPON_READY ) { + aas_clientmove_t move; + vec3_t origin; + + VectorSubtract( entinfo.origin, bs->origin, dir ); + //distance towards the enemy + dist = VectorLength( dir ); + //direction the enemy is moving in + VectorSubtract( entinfo.origin, entinfo.lastvisorigin, dir ); + // + VectorScale( dir, 1 / entinfo.update_time, dir ); + // + VectorCopy( entinfo.origin, origin ); + origin[2] += 1; + // + VectorClear( cmdmove ); + //AAS_ClearShownDebugLines(); + trap_AAS_PredictClientMovement( &move, bs->enemy, origin, + PRESENCE_CROUCH, qfalse, + dir, cmdmove, 0, + dist * 10 / wi.speed, 0.1, 0, 0, qfalse ); + VectorCopy( move.endpos, bestorigin ); + //BotAI_Print(PRT_MESSAGE, "%1.1f predicted speed = %f, frames = %f\n", trap_AAS_Time(), VectorLength(dir), dist * 10 / wi.speed); + } + //if not that skilled do linear prediction + else if ( aim_skill > 0.4 ) { + VectorSubtract( entinfo.origin, bs->origin, dir ); + //distance towards the enemy + dist = VectorLength( dir ); + //direction the enemy is moving in + VectorSubtract( entinfo.origin, entinfo.lastvisorigin, dir ); + dir[2] = 0; + // + speed = VectorNormalize( dir ) / entinfo.update_time; + //botimport.Print(PRT_MESSAGE, "speed = %f, wi->speed = %f\n", speed, wi->speed); + //best spot to aim at + VectorMA( entinfo.origin, ( dist / wi.speed ) * speed, dir, bestorigin ); + } + } + } + //if the projectile does radial damage + if ( aim_skill > 0.6 && wi.proj.damagetype & DAMAGETYPE_RADIAL ) { + //if the enemy isn't standing significantly higher than the bot + if ( entinfo.origin[2] < bs->origin[2] + 16 ) { + //try to aim at the ground in front of the enemy + VectorCopy( entinfo.origin, end ); + end[2] -= 64; + BotAI_Trace( &trace, entinfo.origin, NULL, NULL, end, entinfo.number, MASK_SHOT ); + // + VectorCopy( bestorigin, groundtarget ); + if ( trace.startsolid ) { + groundtarget[2] = entinfo.origin[2] - 16; + } else { groundtarget[2] = trace.endpos[2] - 8;} + //trace a line from projectile start to ground target + BotAI_Trace( &trace, start, NULL, NULL, groundtarget, bs->entitynum, MASK_SHOT ); + //if hitpoint is not vertically too far from the ground target + if ( fabs( trace.endpos[2] - groundtarget[2] ) < 50 ) { + VectorSubtract( trace.endpos, groundtarget, dir ); + //if the hitpoint is near anough the ground target + if ( VectorLength( dir ) < 60 ) { + VectorSubtract( trace.endpos, start, dir ); + //if the hitpoint is far anough from the bot + if ( VectorLength( dir ) > 100 ) { + //check if the bot is visible from the ground target + trace.endpos[2] += 1; + BotAI_Trace( &trace, trace.endpos, NULL, NULL, entinfo.origin, entinfo.number, MASK_SHOT ); + if ( trace.fraction >= 1 ) { + //botimport.Print(PRT_MESSAGE, "%1.1f aiming at ground\n", AAS_Time()); + VectorCopy( groundtarget, bestorigin ); + } + } + } + } + } + } + bestorigin[0] += 20 * crandom() * ( 1 - aim_accuracy ); + bestorigin[1] += 20 * crandom() * ( 1 - aim_accuracy ); + bestorigin[2] += 10 * crandom() * ( 1 - aim_accuracy ); + } else { + // + VectorCopy( bs->lastenemyorigin, bestorigin ); + bestorigin[2] += 8; + //if the bot is skilled anough + if ( aim_skill > 0.5 ) { + //do prediction shots around corners +// if (wi.number == WP_BFG || //----(SA) removing old weapon references + if ( wi.number == WP_GRENADE_LAUNCHER ) { + //create the chase goal + goal.entitynum = bs->client; + goal.areanum = bs->areanum; + VectorCopy( bs->eye, goal.origin ); + VectorSet( goal.mins, -8, -8, -8 ); + VectorSet( goal.maxs, 8, 8, 8 ); + // + if ( trap_BotPredictVisiblePosition( bs->lastenemyorigin, bs->lastenemyareanum, &goal, TFL_DEFAULT, target ) ) { + VectorCopy( target, bestorigin ); + bestorigin[2] -= 20; + } + aim_accuracy = 1; + } + } + } + // + if ( enemyvisible ) { + BotAI_Trace( &trace, bs->eye, NULL, NULL, bestorigin, bs->entitynum, MASK_SHOT ); + VectorCopy( trace.endpos, bs->aimtarget ); + } else { + VectorCopy( bestorigin, bs->aimtarget ); + } + //get aim direction + VectorSubtract( bestorigin, bs->eye, dir ); + // + if ( wi.number == WP_FLAMETHROWER ) { +// if (wi.number == WP_MACHINEGUN || //----(SA) removing old weapon references +// wi.number == WP_SHOTGUN || +// wi.number == WP_RAILGUN) { + //distance towards the enemy + dist = VectorLength( dir ); + if ( dist > 150 ) { + dist = 150; + } + f = 0.6 + dist / 150 * 0.4; + aim_accuracy *= f; + } + //add some random stuff to the aim direction depending on the aim accuracy + if ( aim_accuracy < 0.8 ) { + VectorNormalize( dir ); + for ( i = 0; i < 3; i++ ) dir[i] += 0.3 * crandom() * ( 1 - aim_accuracy ); + } + //set the ideal view angles + vectoangles( dir, bs->ideal_viewangles ); + //take the weapon spread into account for lower skilled bots + bs->ideal_viewangles[PITCH] += 6 * wi.vspread * crandom() * ( 1 - aim_accuracy ); + bs->ideal_viewangles[PITCH] = AngleMod( bs->ideal_viewangles[PITCH] ); + bs->ideal_viewangles[YAW] += 6 * wi.hspread * crandom() * ( 1 - aim_accuracy ); + bs->ideal_viewangles[YAW] = AngleMod( bs->ideal_viewangles[YAW] ); + //if the bot is really accurate and has the enemy in view for some time + if ( aim_accuracy > 0.9 && bs->enemysight_time < trap_AAS_Time() - 1 ) { + //set the view angles directly + if ( bs->ideal_viewangles[PITCH] > 180 ) { + bs->ideal_viewangles[PITCH] -= 360; + } + VectorCopy( bs->ideal_viewangles, bs->viewangles ); + trap_EA_View( bs->client, bs->viewangles ); + } +} + +/* +================== +BotCheckAttack +================== +*/ +void BotCheckAttack( bot_state_t *bs ) { + float points, reactiontime, fov, firethrottle; + bsp_trace_t bsptrace; + //float selfpreservation; + vec3_t forward, right, start, end, dir, angles; + weaponinfo_t wi; + bsp_trace_t trace; + aas_entityinfo_t entinfo; + vec3_t mins = {-8, -8, -8}, maxs = {8, 8, 8}; + + if ( bs->enemy < 0 ) { + return; + } + // + reactiontime = trap_Characteristic_BFloat( bs->character, CHARACTERISTIC_REACTIONTIME, 0, 1 ); + if ( bs->enemysight_time > trap_AAS_Time() - reactiontime ) { + return; + } + if ( bs->teleport_time > trap_AAS_Time() - reactiontime ) { + return; + } + //if changing weapons + if ( bs->weaponchange_time > trap_AAS_Time() - 0.1 ) { + return; + } + //check fire throttle characteristic + if ( bs->firethrottlewait_time > trap_AAS_Time() ) { + return; + } + firethrottle = trap_Characteristic_BFloat( bs->character, CHARACTERISTIC_FIRETHROTTLE, 0, 1 ); + if ( bs->firethrottleshoot_time < trap_AAS_Time() ) { + if ( random() > firethrottle ) { + bs->firethrottlewait_time = trap_AAS_Time() + firethrottle; + bs->firethrottleshoot_time = 0; + } else { + bs->firethrottleshoot_time = trap_AAS_Time() + 1 - firethrottle; + bs->firethrottlewait_time = 0; + } + } + // + BotEntityInfo( bs->enemy, &entinfo ); + VectorSubtract( entinfo.origin, bs->eye, dir ); + // + if ( VectorLength( dir ) < 100 ) { + fov = 120; + } else { fov = 50;} + /* + //if the enemy isn't visible + if (!BotEntityVisible(bs->entitynum, bs->eye, bs->viewangles, fov, bs->enemy)) { + //botimport.Print(PRT_MESSAGE, "enemy not visible\n"); + return; + }*/ + vectoangles( dir, angles ); + if ( !InFieldOfVision( bs->viewangles, fov, angles ) ) { + return; + } + BotAI_Trace( &bsptrace, bs->eye, NULL, NULL, bs->aimtarget, bs->client, CONTENTS_SOLID | CONTENTS_PLAYERCLIP ); + if ( bsptrace.fraction < 1 && bsptrace.ent != bs->enemy ) { + return; + } + + //get the weapon info + trap_BotGetWeaponInfo( bs->ws, bs->weaponnum, &wi ); + //get the start point shooting from + VectorCopy( bs->origin, start ); + start[2] += bs->cur_ps.viewheight; + AngleVectors( bs->viewangles, forward, right, NULL ); + start[0] += forward[0] * wi.offset[0] + right[0] * wi.offset[1]; + start[1] += forward[1] * wi.offset[0] + right[1] * wi.offset[1]; + start[2] += forward[2] * wi.offset[0] + right[2] * wi.offset[1] + wi.offset[2]; + //end point aiming at + VectorMA( start, 1000, forward, end ); + //a little back to make sure not inside a very close enemy + VectorMA( start, -12, forward, start ); + BotAI_Trace( &trace, start, mins, maxs, end, bs->entitynum, MASK_SHOT ); //----(SA) should this maybe check the weapon type and adjust the clipflag? it seems like this is probably fine as-is, but I thought I'd note it. + //if won't hit the enemy + if ( trace.ent != bs->enemy ) { + //if the entity is a client + if ( trace.ent > 0 && trace.ent <= MAX_CLIENTS ) { + //if a teammate is hit + if ( BotSameTeam( bs, trace.ent ) ) { + return; + } + } + //if the projectile does a radial damage + if ( wi.proj.damagetype & DAMAGETYPE_RADIAL ) { + if ( trace.fraction * 1000 < wi.proj.radius ) { + points = ( wi.proj.damage - 0.5 * trace.fraction * 1000 ) * 0.5; + if ( points > 0 ) { +// selfpreservation = trap_Characteristic_BFloat(bs->character, CHARACTERISTIC_SELFPRESERVATION, 0, 1); +// if (random() < selfpreservation) return; + return; + } + } + //FIXME: check if a teammate gets radial damage + } + } + //if fire has to be release to activate weapon + if ( wi.flags & WFL_FIRERELEASED ) { + if ( bs->flags & BFL_ATTACKED ) { + trap_EA_Attack( bs->client ); + } + } else { + trap_EA_Attack( bs->client ); + } + bs->flags ^= BFL_ATTACKED; +} + +/* +================== +BotMapScripts +================== +*/ +void BotMapScripts( bot_state_t *bs ) { + char info[1024]; + char mapname[128]; + int i, shootbutton; + float aim_accuracy; + aas_entityinfo_t entinfo; + vec3_t dir; + + trap_GetServerinfo( info, sizeof( info ) ); + + strncpy( mapname, Info_ValueForKey( info, "mapname" ), sizeof( mapname ) - 1 ); + mapname[sizeof( mapname ) - 1] = '\0'; + + if ( !Q_stricmp( mapname, "q3tourney6" ) ) { + vec3_t mins = {700, 204, 672}, maxs = {964, 468, 680}; + vec3_t buttonorg = {304, 352, 920}; + //NOTE: NEVER use the func_bobbing in q3tourney6 + bs->tfl &= ~TFL_FUNCBOB; + //if the bot is below the bounding box + if ( bs->origin[0] > mins[0] && bs->origin[0] < maxs[0] ) { + if ( bs->origin[1] > mins[1] && bs->origin[1] < maxs[1] ) { + if ( bs->origin[2] < mins[2] ) { + return; + } + } + } + shootbutton = qfalse; + //if an enemy is below this bounding box then shoot the button + for ( i = 0; i < MAX_CLIENTS; i++ ) { + + if ( i == bs->client ) { + continue; + } + // + BotEntityInfo( i, &entinfo ); + // + if ( !entinfo.valid ) { + continue; + } + //if the enemy isn't dead and the enemy isn't the bot self + if ( EntityIsDead( &entinfo ) || entinfo.number == bs->entitynum ) { + continue; + } + // + if ( entinfo.origin[0] > mins[0] && entinfo.origin[0] < maxs[0] ) { + if ( entinfo.origin[1] > mins[1] && entinfo.origin[1] < maxs[1] ) { + if ( entinfo.origin[2] < mins[2] ) { + //if there's a team mate below the crusher + if ( BotSameTeam( bs, i ) ) { + shootbutton = qfalse; + break; + } else { + shootbutton = qtrue; + } + } + } + } + } + if ( shootbutton ) { + bs->flags |= BFL_IDEALVIEWSET; + VectorSubtract( buttonorg, bs->eye, dir ); + vectoangles( dir, bs->ideal_viewangles ); + aim_accuracy = trap_Characteristic_BFloat( bs->character, CHARACTERISTIC_AIM_ACCURACY, 0, 1 ); + bs->ideal_viewangles[PITCH] += 8 * crandom() * ( 1 - aim_accuracy ); + bs->ideal_viewangles[PITCH] = AngleMod( bs->ideal_viewangles[PITCH] ); + bs->ideal_viewangles[YAW] += 8 * crandom() * ( 1 - aim_accuracy ); + bs->ideal_viewangles[YAW] = AngleMod( bs->ideal_viewangles[YAW] ); + // + if ( InFieldOfVision( bs->viewangles, 20, bs->ideal_viewangles ) ) { + trap_EA_Attack( bs->client ); + } + } + } +} + +/* +================== +BotCheckButtons +================== +*/ +/* +void CheckButtons(void) +{ + int modelindex, i, numbuttons = 0; + char *classname, *model; + float lip, health, dist; + bsp_entity_t *ent; + vec3_t mins, maxs, size, origin, angles, movedir, goalorigin; + vec3_t start, end, bboxmins, bboxmaxs; + aas_trace_t trace; + + for (ent = entities; ent; ent = ent->next) + { + classname = AAS_ValueForBSPEpairKey(ent, "classname"); + if (!strcmp(classname, "func_button")) + { + //create a bot goal towards the button + model = AAS_ValueForBSPEpairKey(ent, "model"); + modelindex = AAS_IndexFromModel(model); + //if the model is not loaded + if (!modelindex) modelindex = atoi(model+1); + VectorClear(angles); + AAS_BSPModelMinsMaxsOrigin(modelindex - 1, angles, mins, maxs, NULL); + //get the lip of the button + lip = AAS_FloatForBSPEpairKey(ent, "lip"); + if (!lip) lip = 4; + //get the move direction from the angle + VectorSet(angles, 0, AAS_FloatForBSPEpairKey(ent, "angle"), 0); + AAS_SetMovedir(angles, movedir); + //button size + VectorSubtract(maxs, mins, size); + //button origin + VectorAdd(mins, maxs, origin); + VectorScale(origin, 0.5, origin); + //touch distance of the button + dist = fabs(movedir[0]) * size[0] + fabs(movedir[1]) * size[1] + fabs(movedir[2]) * size[2];// - lip; + dist *= 0.5; + // + health = AAS_FloatForBSPEpairKey(ent, "health"); + //if the button is shootable + if (health) + { + //calculate the goal origin + VectorMA(origin, -dist, movedir, goalorigin); + AAS_DrawPermanentCross(goalorigin, 4, LINECOLOR_BLUE); + } //end if + else + { + //add bounding box size to the dist + AAS_PresenceTypeBoundingBox(PRESENCE_CROUCH, bboxmins, bboxmaxs); + for (i = 0; i < 3; i++) + { + if (movedir[i] < 0) dist += fabs(movedir[i]) * fabs(bboxmaxs[i]); + else dist += fabs(movedir[i]) * fabs(bboxmins[i]); + } //end for + //calculate the goal origin + VectorMA(origin, -dist, movedir, goalorigin); + // + VectorCopy(goalorigin, start); + start[2] += 24; + VectorSet(end, start[0], start[1], start[2] - 100); + trace = AAS_TraceClientBBox(start, end, PRESENCE_CROUCH, -1); + if (!trace.startsolid) + { + VectorCopy(trace.endpos, goalorigin); + } //end if + // + AAS_DrawPermanentCross(goalorigin, 4, LINECOLOR_YELLOW); + // + VectorSubtract(mins, origin, mins); + VectorSubtract(maxs, origin, maxs); + // + VectorAdd(mins, origin, start); + AAS_DrawPermanentCross(start, 4, LINECOLOR_BLUE); + VectorAdd(maxs, origin, start); + AAS_DrawPermanentCross(start, 4, LINECOLOR_BLUE); + } //end else + if (++numbuttons > 5) return; + } //end if + } //end for +} //end of the function CheckButtons +*/ + +/* +================== +BotEntityToActivate +================== +*/ +//#define OBSTACLEDEBUG + +int BotEntityToActivate( int entitynum ) { + int i, ent, cur_entities[10]; + char model[MAX_INFO_STRING], tmpmodel[128]; + char target[128], classname[128]; + float health; + char targetname[10][128]; + aas_entityinfo_t entinfo; + + BotEntityInfo( entitynum, &entinfo ); + Com_sprintf( model, sizeof( model ), "*%d", entinfo.modelindex ); + for ( ent = trap_AAS_NextBSPEntity( 0 ); ent; ent = trap_AAS_NextBSPEntity( ent ) ) { + if ( !trap_AAS_ValueForBSPEpairKey( ent, "model", tmpmodel, sizeof( tmpmodel ) ) ) { + continue; + } + if ( !strcmp( model, tmpmodel ) ) { + break; + } + } + if ( !ent ) { + BotAI_Print( PRT_ERROR, "BotEntityToActivate: no entity found with model %s\n", model ); + return 0; + } + trap_AAS_ValueForBSPEpairKey( ent, "classname", classname, sizeof( classname ) ); + if ( !classname ) { + BotAI_Print( PRT_ERROR, "BotEntityToActivate: entity with model %s has no classname\n", model ); + return 0; + } + //if it is a door + if ( !strcmp( classname, "func_door" ) ) { + if ( trap_AAS_FloatForBSPEpairKey( ent, "health", &health ) ) { + //if health the door must be shot to open + if ( health ) { + return ent; + } + } + } + //get the targetname so we can find an entity with a matching target + if ( !trap_AAS_ValueForBSPEpairKey( ent, "targetname", targetname[0], sizeof( targetname[0] ) ) ) { +#ifdef OBSTACLEDEBUG + BotAI_Print( PRT_ERROR, "BotEntityToActivate: entity with model \"%s\" has no targetname\n", model ); +#endif //OBSTACLEDEBUG + return 0; + } + cur_entities[0] = trap_AAS_NextBSPEntity( 0 ); + for ( i = 0; i >= 0 && i < 10; ) { + for ( ent = cur_entities[i]; ent; ent = trap_AAS_NextBSPEntity( ent ) ) { + if ( !trap_AAS_ValueForBSPEpairKey( ent, "target", target, sizeof( target ) ) ) { + continue; + } + if ( !strcmp( targetname[i], target ) ) { + cur_entities[i] = trap_AAS_NextBSPEntity( ent ); + break; + } + } + if ( !ent ) { + BotAI_Print( PRT_ERROR, "BotEntityToActivate: no entity with target \"%s\"\n", targetname[i] ); + i--; + continue; + } + if ( !trap_AAS_ValueForBSPEpairKey( ent, "classname", classname, sizeof( classname ) ) ) { + BotAI_Print( PRT_ERROR, "BotEntityToActivate: entity with target \"%s\" has no classname\n", targetname[i] ); + continue; + } + if ( !strcmp( classname, "func_button" ) ) { + //BSP button model + return ent; + } else if ( !strcmp( classname, "trigger_multiple" ) ) { + //invisible trigger multiple box + return ent; + } else { + i--; + } + } + BotAI_Print( PRT_ERROR, "BotEntityToActivate: unknown activator with classname \"%s\"\n", classname ); + return 0; +} + +/* +================== +BotSetMovedir +================== +*/ +vec3_t VEC_UP = {0, -1, 0}; +vec3_t MOVEDIR_UP = {0, 0, 1}; +vec3_t VEC_DOWN = {0, -2, 0}; +vec3_t MOVEDIR_DOWN = {0, 0, -1}; + +void BotSetMovedir( vec3_t angles, vec3_t movedir ) { + if ( VectorCompare( angles, VEC_UP ) ) { + VectorCopy( MOVEDIR_UP, movedir ); + } else if ( VectorCompare( angles, VEC_DOWN ) ) { + VectorCopy( MOVEDIR_DOWN, movedir ); + } else { + AngleVectors( angles, movedir, NULL, NULL ); + } +} + +void BotModelMinsMaxs( int modelindex, vec3_t mins, vec3_t maxs ) { + gentity_t *ent; + int i; + + ent = &g_entities[0]; + for ( i = 0; i < level.num_entities; i++, ent++ ) { + if ( !ent->inuse ) { + continue; + } + if ( ent->s.modelindex == modelindex ) { + VectorCopy( ent->r.mins, mins ); + VectorCopy( ent->r.maxs, maxs ); + return; + } + } + VectorClear( mins ); + VectorClear( maxs ); +} + +/* +================== +BotAIBlocked +================== +*/ +void BotAIBlocked( bot_state_t *bs, bot_moveresult_t *moveresult, int activate ) { + int movetype, ent, i, areas[10], numareas, modelindex; + char classname[128], model[128]; +#ifdef OBSTACLEDEBUG + char buf[128]; +#endif + float lip, dist, health, angle; + vec3_t hordir, size, start, end, mins, maxs, sideward, angles; + vec3_t movedir, origin, goalorigin, bboxmins, bboxmaxs; + vec3_t up = {0, 0, 1}, extramins = {-1, -1, -1}, extramaxs = {1, 1, 1}; + aas_entityinfo_t entinfo; +/* + bsp_trace_t bsptrace; +*/ +#ifdef OBSTACLEDEBUG + char netname[MAX_NETNAME]; +#endif + + if ( !moveresult->blocked ) { + return; + } + // + BotEntityInfo( moveresult->blockentity, &entinfo ); +#ifdef OBSTACLEDEBUG + ClientName( bs->client, netname, sizeof( netname ) ); + BotAI_Print( PRT_MESSAGE, "%s: I'm blocked by model %d\n", netname, entinfo.modelindex ); +#endif //OBSTACLEDEBUG + //if blocked by a bsp model and the bot wants to activate it if possible + if ( entinfo.modelindex > 0 && entinfo.modelindex <= max_bspmodelindex && activate ) { + //find the bsp entity which should be activated in order to remove + //the blocking entity + ent = BotEntityToActivate( entinfo.number ); + if ( !ent ) { + strcpy( classname, "" ); +#ifdef OBSTACLEDEBUG + BotAI_Print( PRT_MESSAGE, "%s: can't find activator for blocking entity\n", ClientName( bs->client, netname, sizeof( netname ) ) ); +#endif //OBSTACLEDEBUG + } else { + trap_AAS_ValueForBSPEpairKey( ent, "classname", classname, sizeof( classname ) ); +#ifdef OBSTACLEDEBUG + ClientName( bs->client, netname, sizeof( netname ) ); + BotAI_Print( PRT_MESSAGE, "%s: I should activate %s\n", netname, classname ); +#endif //OBSTACLEDEBUG + } +#ifdef OBSTACLEDEBUG +// ClientName(bs->client, netname, sizeof(netname)); +// BotAI_Print(PRT_MESSAGE, "%s: I've got no brain cells for activating entities\n", netname); +#endif //OBSTACLEDEBUG + /* + //the bot should now activate one of the following entities + //"func_button", "trigger_multiple", "func_door" + //all these activators use BSP models, so it should be a matter of + //finding where this model is located using AAS and then activating + //by walking against the model it or shooting at it + // + //if it is a door we should shoot at + if (!strcmp(classname, "func_door")) + { + //get the door model + model = AAS_ValueForBSPEpairKey(ent, "model"); + modelindex = AAS_IndexFromModel(model); + //if the model is not loaded + if (!modelindex) return; + VectorClear(angles); + AAS_BSPModelMinsMaxsOrigin(modelindex - 1, angles, mins, maxs, NULL); + //get a goal to shoot at + VectorAdd(maxs, mins, goalorigin); + VectorScale(goalorigin, 0.5, goalorigin); + VectorSubtract(goalorigin, bs->origin, movedir); + // + vectoangles(movedir, moveresult->ideal_viewangles); + moveresult->flags |= MOVERESULT_MOVEMENTVIEW; + //select the blaster + EA_UseItem(bs->client, "Blaster"); + //shoot + EA_Attack(bs->client); + // + return; + } //end if*/ + if ( !strcmp( classname, "func_button" ) ) { + //create a bot goal towards the button + trap_AAS_ValueForBSPEpairKey( ent, "model", model, sizeof( model ) ); + modelindex = atoi( model + 1 ); + //if the model is not loaded + if ( !modelindex ) { + return; + } + VectorClear( angles ); + BotModelMinsMaxs( modelindex, mins, maxs ); + //get the lip of the button + trap_AAS_FloatForBSPEpairKey( ent, "lip", &lip ); + if ( !lip ) { + lip = 4; + } + //get the move direction from the angle + trap_AAS_FloatForBSPEpairKey( ent, "angle", &angle ); + VectorSet( angles, 0, angle, 0 ); + BotSetMovedir( angles, movedir ); + //button size + VectorSubtract( maxs, mins, size ); + //button origin + VectorAdd( mins, maxs, origin ); + VectorScale( origin, 0.5, origin ); + //touch distance of the button + dist = fabs( movedir[0] ) * size[0] + fabs( movedir[1] ) * size[1] + fabs( movedir[2] ) * size[2]; + dist *= 0.5; + // + trap_AAS_FloatForBSPEpairKey( ent, "health", &health ); + //if the button is shootable + if ( health ) { + //calculate the goal origin + VectorMA( origin, -dist, movedir, goalorigin ); + // + //AAS_ClearShownDebugLines(); + //AAS_DrawArrow(bs->origin, goalorigin, LINECOLOR_BLUE, LINECOLOR_YELLOW); + // + VectorSubtract( goalorigin, bs->origin, movedir ); + vectoangles( movedir, moveresult->ideal_viewangles ); + moveresult->flags |= MOVERESULT_MOVEMENTVIEW; + //select the blaster + trap_EA_SelectWeapon( bs->client, WEAPONINDEX_MACHINEGUN ); + //shoot + trap_EA_Attack( bs->client ); + return; + } //end if + else + { + //add bounding box size to the dist + trap_AAS_PresenceTypeBoundingBox( PRESENCE_CROUCH, bboxmins, bboxmaxs ); + for ( i = 0; i < 3; i++ ) + { + if ( movedir[i] < 0 ) { + dist += fabs( movedir[i] ) * fabs( bboxmaxs[i] ); + } else { dist += fabs( movedir[i] ) * fabs( bboxmins[i] );} + } //end for + //calculate the goal origin + VectorMA( origin, -dist, movedir, goalorigin ); + // + VectorCopy( goalorigin, start ); + start[2] += 24; + VectorCopy( start, end ); + end[2] -= 100; + numareas = trap_AAS_TraceAreas( start, end, areas, NULL, 10 ); + // + for ( i = 0; i < numareas; i++ ) { + if ( trap_AAS_AreaReachability( areas[i] ) ) { + break; + } + } + if ( i < numareas ) { + // +#ifdef OBSTACLEDEBUG + if ( bs->activatemessage_time < trap_AAS_Time() ) { + Com_sprintf( buf, sizeof( buf ), "I have to activate a button at %1.1f %1.1f %1.1f in area %d\n", + goalorigin[0], goalorigin[1], goalorigin[2], areas[i] ); + trap_EA_Say( bs->client, buf ); + bs->activatemessage_time = trap_AAS_Time() + 5; + } //end if +#endif //OBSTACLEDEBUG + // + //VectorMA(origin, -dist, movedir, goalorigin); + // + VectorCopy( origin, bs->activategoal.origin ); + bs->activategoal.areanum = areas[i]; + VectorSubtract( mins, origin, bs->activategoal.mins ); + VectorSubtract( maxs, origin, bs->activategoal.maxs ); + // + VectorAdd( bs->activategoal.mins, extramins, bs->activategoal.mins ); + VectorAdd( bs->activategoal.maxs, extramaxs, bs->activategoal.maxs ); + // + bs->activategoal.entitynum = entinfo.number; + bs->activategoal.number = 0; + bs->activategoal.flags = 0; + bs->activate_time = trap_AAS_Time() + 10; + AIEnter_Seek_ActivateEntity( bs ); + } //end if + else + { +#ifdef OBSTACLEDEBUG + BotAI_Print( PRT_MESSAGE, "button area has no reachabilities\n" ); +#endif //OBSTACLEDEBUG + if ( bs->ainode == AINode_Seek_NBG ) { + bs->nbg_time = 0; + } else if ( bs->ainode == AINode_Seek_LTG ) { + bs->ltg_time = 0; + } + } //end else + } //end else + } //end if + /* + if (!strcmp(classname, "trigger_multiple")) + { + //create a bot goal towards the trigger + model = AAS_ValueForBSPEpairKey(ent, "model"); + modelindex = AAS_IndexFromModel(model); + //if the model is not precached (bad thing but happens) assume model is "*X" + if (!modelindex) modelindex = atoi(model+1); + VectorClear(angles); + AAS_BSPModelMinsMaxsOrigin(modelindex - 1, angles, mins, maxs, NULL); + VectorAdd(mins, maxs, mid); + VectorScale(mid, 0.5, mid); + VectorCopy(mid, start); + start[2] = maxs[2] + 24; + VectorSet(end, start[0], start[1], start[2] - 100); + trace = AAS_TraceClientBBox(start, end, PRESENCE_CROUCH, -1); + if (trace.startsolid) return; + //trace.endpos is now the goal origin + VectorCopy(trace.endpos, goalorigin); + // + #ifdef OBSTACLEDEBUG + if (bs->activatemessage_time < AAS_Time()) + { + Com_sprintf(buf, sizeof(buf), "I have to activate a trigger at %1.1f %1.1f %1.1f in area %d\n", + goalorigin[0], goalorigin[1], goalorigin[2], AAS_PointAreaNum(goalorigin)); + EA_Say(bs->client, buf); + bs->activatemessage_time = AAS_Time() + 5; + } //end if* / + #endif //OBSTACLEDEBUG + // + VectorCopy(mid, bs->activategoal.origin); + bs->activategoal.areanum = AAS_PointAreaNum(goalorigin); + VectorSubtract(mins, mid, bs->activategoal.mins); + VectorSubtract(maxs, mid, bs->activategoal.maxs); + bs->activategoal.entitynum = entinfo.number; + bs->activategoal.number = 0; + bs->activategoal.flags = 0; + bs->activate_time = AAS_Time() + 10; + if (!AAS_AreaReachability(bs->activategoal.areanum)) + { + #ifdef OBSTACLEDEBUG + botimport.Print(PRT_MESSAGE, "trigger area has no reachabilities\n"); + #endif //OBSTACLEDEBUG + if (bs->ainode == AINode_Seek_NBG) bs->nbg_time = 0; + else if (bs->ainode == AINode_Seek_LTG) bs->ltg_time = 0; + } //end if + else + { + AIEnter_Seek_ActivateEntity(bs); + } //end else + return; + } //end if*/ + } + //just some basic dynamic obstacle avoidance code + hordir[0] = moveresult->movedir[0]; + hordir[1] = moveresult->movedir[1]; + hordir[2] = 0; + //if no direction just take a random direction + if ( VectorNormalize( hordir ) < 0.1 ) { + VectorSet( angles, 0, 360 * random(), 0 ); + AngleVectors( angles, hordir, NULL, NULL ); + } + // +// if (moveresult->flags & MOVERESULT_ONTOPOFOBSTACLE) movetype = MOVE_JUMP; +// else + movetype = MOVE_WALK; + //if there's an obstacle at the bot's feet and head then + //the bot might be able to crouch through + VectorCopy( bs->origin, start ); + start[2] += 18; + VectorMA( start, 5, hordir, end ); + VectorSet( mins, -16, -16, -24 ); + VectorSet( maxs, 16, 16, 4 ); + // +// bsptrace = AAS_Trace(start, mins, maxs, end, bs->entitynum, MASK_PLAYERSOLID); +// if (bsptrace.fraction >= 1) movetype = MOVE_CROUCH; + //get the sideward vector + CrossProduct( hordir, up, sideward ); + // + if ( bs->flags & BFL_AVOIDRIGHT ) { + VectorNegate( sideward, sideward ); + } + //try to crouch straight forward? + if ( movetype != MOVE_CROUCH || !trap_BotMoveInDirection( bs->ms, hordir, 400, movetype ) ) { + //perform the movement + if ( !trap_BotMoveInDirection( bs->ms, sideward, 400, movetype ) ) { + //flip the avoid direction flag + bs->flags ^= BFL_AVOIDRIGHT; + //flip the direction + VectorNegate( sideward, sideward ); + //move in the other direction + trap_BotMoveInDirection( bs->ms, sideward, 400, movetype ); + } + } + //just reset goals and hope the bot will go into another direction + //still needed?? + if ( bs->ainode == AINode_Seek_NBG ) { + bs->nbg_time = 0; + } else if ( bs->ainode == AINode_Seek_LTG ) { + bs->ltg_time = 0; + } +} + +/* +================== +BotCheckConsoleMessages +================== +*/ +void BotCheckConsoleMessages( bot_state_t *bs ) { + char botname[MAX_NETNAME], message[MAX_MESSAGE_SIZE], netname[MAX_NETNAME]; + float chat_reply; + int context, handle; + bot_consolemessage_t m; + bot_match_t match; + + //the name of this bot + ClientName( bs->client, botname, sizeof( botname ) ); + // + while ( ( handle = trap_BotNextConsoleMessage( bs->cs, &m ) ) != 0 ) { + //if the chat state is flooded with messages the bot will read them quickly + if ( trap_BotNumConsoleMessages( bs->cs ) < 10 ) { + //if it is a chat message the bot needs some time to read it + if ( m.type == CMS_CHAT && m.time > trap_AAS_Time() - ( 1 + random() ) ) { + break; + } + } + //unify the white spaces in the message + trap_UnifyWhiteSpaces( m.message ); + //replace synonyms in the right context + context = CONTEXT_NORMAL | CONTEXT_NEARBYITEM | CONTEXT_NAMES; + if ( BotCTFTeam( bs ) == CTF_TEAM_RED ) { + context |= CONTEXT_CTFREDTEAM; + } else { context |= CONTEXT_CTFBLUETEAM;} + trap_BotReplaceSynonyms( m.message, context ); + //if there's no match + if ( !BotMatchMessage( bs, m.message ) ) { + //if it is a chat message + if ( m.type == CMS_CHAT && !bot_nochat.integer ) { + // + if ( !trap_BotFindMatch( m.message, &match, MTCONTEXT_REPLYCHAT ) ) { + trap_BotRemoveConsoleMessage( bs->cs, handle ); + continue; + } + //don't use eliza chats with team messages + if ( match.subtype & ST_TEAM ) { + trap_BotRemoveConsoleMessage( bs->cs, handle ); + continue; + } + // + trap_BotMatchVariable( &match, NETNAME, netname, sizeof( netname ) ); + trap_BotMatchVariable( &match, MESSAGE, message, sizeof( message ) ); + //if this is a message from the bot self + if ( !Q_stricmp( netname, botname ) ) { + trap_BotRemoveConsoleMessage( bs->cs, handle ); + continue; + } + //unify the message + trap_UnifyWhiteSpaces( message ); + // + trap_Cvar_Update( &bot_testrchat ); + if ( bot_testrchat.integer ) { + // + trap_BotLibVarSet( "bot_testrchat", "1" ); + //if bot replies with a chat message + if ( trap_BotReplyChat( bs->cs, message, context, CONTEXT_REPLY, + NULL, NULL, + NULL, NULL, + NULL, NULL, + botname, netname ) ) { + BotAI_Print( PRT_MESSAGE, "------------------------\n" ); + } else { + BotAI_Print( PRT_MESSAGE, "**** no valid reply ****\n" ); + } + } + //if at a valid chat position and not chatting already + else if ( bs->ainode != AINode_Stand && BotValidChatPosition( bs ) ) { + chat_reply = trap_Characteristic_BFloat( bs->character, CHARACTERISTIC_CHAT_REPLY, 0, 1 ); + if ( random() < 1.5 / ( NumBots() + 1 ) && random() < chat_reply ) { + //if bot replies with a chat message + if ( trap_BotReplyChat( bs->cs, message, context, CONTEXT_REPLY, + NULL, NULL, + NULL, NULL, + NULL, NULL, + botname, netname ) ) { + //remove the console message + trap_BotRemoveConsoleMessage( bs->cs, handle ); + bs->stand_time = trap_AAS_Time() + BotChatTime( bs ); + AIEnter_Stand( bs ); + //EA_Say(bs->client, bs->cs.chatmessage); + break; + } + } + } + } + } + //remove the console message + trap_BotRemoveConsoleMessage( bs->cs, handle ); + } +} + +/* +================== +BotCheckEvents +================== +*/ +void BotCheckEvents( bot_state_t *bs, entityState_t *state ) { + int event; + char buf[128]; + // + //this sucks, we're accessing the gentity_t directly but there's no other fast way + //to do it right now + if ( bs->entityeventTime[state->number] == g_entities[state->number].eventTime ) { + return; + } + bs->entityeventTime[state->number] = g_entities[state->number].eventTime; + //if it's an event only entity + if ( state->eType > ET_EVENTS ) { + event = ( state->eType - ET_EVENTS ) & ~EV_EVENT_BITS; + } else { + event = state->event & ~EV_EVENT_BITS; + } + // + switch ( event ) { + //client obituary event + case EV_OBITUARY: + { + int target, attacker, mod; + + target = state->otherEntityNum; + attacker = state->otherEntityNum2; + mod = state->eventParm; + // + if ( target == bs->client ) { + bs->botdeathtype = mod; + bs->lastkilledby = attacker; + // + if ( target == attacker ) { + bs->botsuicide = qtrue; + } else { bs->botsuicide = qfalse;} + // + bs->num_deaths++; + } + //else if this client was killed by the bot + else if ( attacker == bs->client ) { + bs->enemydeathtype = mod; + bs->lastkilledplayer = target; + bs->killedenemy_time = trap_AAS_Time(); + // + bs->num_kills++; + } else if ( attacker == bs->enemy && target == attacker ) { + bs->enemysuicide = qtrue; + } + break; + } + case EV_GLOBAL_SOUND: + { + if ( state->eventParm < 0 || state->eventParm > MAX_SOUNDS ) { + BotAI_Print( PRT_ERROR, "EV_GLOBAL_SOUND: eventParm (%d) out of range\n", state->eventParm ); + break; + } + trap_GetConfigstring( CS_SOUNDS + state->eventParm, buf, sizeof( buf ) ); + if ( !strcmp( buf, "sound/teamplay/flagret_red.wav" ) ) { + //red flag is returned + bs->redflagstatus = 0; + bs->flagstatuschanged = qtrue; + } else if ( !strcmp( buf, "sound/teamplay/flagret_blu.wav" ) ) { + //blue flag is returned + bs->blueflagstatus = 0; + bs->flagstatuschanged = qtrue; + } else if ( !strcmp( buf, "sound/items/poweruprespawn.wav" ) ) { + //powerup respawned... go get it + BotGoForPowerups( bs ); + } + break; + } + case EV_PLAYER_TELEPORT_IN: + { + VectorCopy( state->origin, lastteleport_origin ); + lastteleport_time = trap_AAS_Time(); + break; + } + case EV_GENERAL_SOUND: + { + //if this sound is played on the bot + if ( state->number == bs->client ) { + if ( state->eventParm < 0 || state->eventParm > MAX_SOUNDS ) { + BotAI_Print( PRT_ERROR, "EV_GENERAL_SOUND: eventParm (%d) out of range\n", state->eventParm ); + break; + } + //check out the sound + trap_GetConfigstring( CS_SOUNDS + state->eventParm, buf, sizeof( buf ) ); + //if falling into a death pit + if ( !strcmp( buf, "*falling1.wav" ) ) { + //if the bot has a personal teleporter + if ( bs->inventory[INVENTORY_TELEPORTER] > 0 ) { + //use the holdable item + trap_EA_Use( bs->client ); + } + } + } + break; + } + } +} + +/* +================== +BotCheckSnapshot +================== +*/ +void BotCheckSnapshot( bot_state_t *bs ) { + int ent; + entityState_t state; + + // + ent = 0; + while ( ( ent = BotAI_GetSnapshotEntity( bs->client, ent, &state ) ) != -1 ) { + //check the entity state for events + BotCheckEvents( bs, &state ); + } + //check the player state for events + BotAI_GetEntityState( bs->client, &state ); + //copy the player state events to the entity state + //state.event = bs->cur_ps.externalEvent; + //state.eventParm = bs->cur_ps.externalEventParm; + // + BotCheckEvents( bs, &state ); +} + +/* +================== +BotCheckAir +================== +*/ +void BotCheckAir( bot_state_t *bs ) { + if ( bs->inventory[INVENTORY_ENVIRONMENTSUIT] <= 0 ) { + if ( trap_AAS_PointContents( bs->eye ) & ( CONTENTS_WATER | CONTENTS_SLIME | CONTENTS_LAVA ) ) { + return; + } + } + bs->lastair_time = trap_AAS_Time(); +} + +/* +================== +BotDeathmatchAI +================== +*/ +void BotDeathmatchAI( bot_state_t *bs, float thinktime ) { + char gender[144], name[144], buf[144]; + char userinfo[MAX_INFO_STRING]; + int i; + + //if the bot has just been setup + if ( bs->setupcount > 0 ) { + bs->setupcount--; + if ( bs->setupcount > 0 ) { + return; + } + //get the gender characteristic + trap_Characteristic_String( bs->character, CHARACTERISTIC_GENDER, gender, sizeof( gender ) ); + //set the bot gender + trap_GetUserinfo( bs->client, userinfo, sizeof( userinfo ) ); + Info_SetValueForKey( userinfo, "sex", gender ); + trap_SetUserinfo( bs->client, userinfo ); + //set the team + if ( g_gametype.integer != GT_TOURNAMENT ) { + Com_sprintf( buf, sizeof( buf ), "team %s", bs->settings.team ); + trap_EA_Command( bs->client, buf ); + } + //set the chat gender + if ( gender[0] == 'm' ) { + trap_BotSetChatGender( bs->cs, CHAT_GENDERMALE ); + } else if ( gender[0] == 'f' ) { + trap_BotSetChatGender( bs->cs, CHAT_GENDERFEMALE ); + } else { trap_BotSetChatGender( bs->cs, CHAT_GENDERLESS );} + //set the chat name + ClientName( bs->client, name, sizeof( name ) ); + trap_BotSetChatName( bs->cs, name ); + // + bs->lastframe_health = bs->inventory[INVENTORY_HEALTH]; + bs->lasthitcount = bs->cur_ps.persistant[PERS_HITS]; + // + bs->setupcount = 0; + } + //no ideal view set + bs->flags &= ~BFL_IDEALVIEWSET; + //set the teleport time + BotSetTeleportTime( bs ); + //update some inventory values + BotUpdateInventory( bs ); + //check the console messages + BotCheckConsoleMessages( bs ); + //check out the snapshot + BotCheckSnapshot( bs ); + //check for air + BotCheckAir( bs ); + //if not in the intermission and not in observer mode + if ( !BotIntermission( bs ) && !BotIsObserver( bs ) ) { + //do team AI + BotTeamAI( bs ); + } + //if the bot has no ai node + if ( !bs->ainode ) { + AIEnter_Seek_LTG( bs ); + } + //if the bot entered the game less than 8 seconds ago + if ( !bs->entergamechat && bs->entergame_time > trap_AAS_Time() - 8 ) { + if ( BotChat_EnterGame( bs ) ) { + bs->stand_time = trap_AAS_Time() + BotChatTime( bs ); + AIEnter_Stand( bs ); + } + bs->entergamechat = qtrue; + } + //reset the node switches from the previous frame + BotResetNodeSwitches(); + //execute AI nodes + for ( i = 0; i < MAX_NODESWITCHES; i++ ) { + if ( bs->ainode( bs ) ) { + break; + } + } + //if the bot removed itself :) + if ( !bs->inuse ) { + return; + } + //if the bot executed too many AI nodes + if ( i >= MAX_NODESWITCHES ) { + trap_BotDumpGoalStack( bs->gs ); + trap_BotDumpAvoidGoals( bs->gs ); + BotDumpNodeSwitches( bs ); + ClientName( bs->client, name, sizeof( name ) ); + BotAI_Print( PRT_ERROR, "%s at %1.1f switched more than %d AI nodes\n", name, trap_AAS_Time(), MAX_NODESWITCHES ); + } + // + bs->lastframe_health = bs->inventory[INVENTORY_HEALTH]; + bs->lasthitcount = bs->cur_ps.persistant[PERS_HITS]; +} + +/* +================== +BotSetupDeathmatchAI +================== +*/ +void BotSetupDeathmatchAI( void ) { + int ent, modelnum; + char model[128]; + + gametype = trap_Cvar_VariableIntegerValue( "g_gametype" ); + + // Rafael gameskill + gameskill = trap_Cvar_VariableIntegerValue( "g_gameskill" ); + // done + + trap_Cvar_Register( &bot_rocketjump, "bot_rocketjump", "1", 0 ); + trap_Cvar_Register( &bot_grapple, "bot_grapple", "0", 0 ); + trap_Cvar_Register( &bot_fastchat, "bot_fastchat", "0", 0 ); + trap_Cvar_Register( &bot_nochat, "bot_nochat", "0", 0 ); + trap_Cvar_Register( &bot_testrchat, "bot_testrchat", "0", 0 ); + // + if ( gametype == GT_CTF ) { + if ( trap_BotGetLevelItemGoal( -1, "Red Flag", &ctf_redflag ) < 0 ) { + BotAI_Print( PRT_WARNING, "CTF without Red Flag\n" ); + } + if ( trap_BotGetLevelItemGoal( -1, "Blue Flag", &ctf_blueflag ) < 0 ) { + BotAI_Print( PRT_WARNING, "CTF without Blue Flag\n" ); + } + } + + max_bspmodelindex = 0; + for ( ent = trap_AAS_NextBSPEntity( 0 ); ent; ent = trap_AAS_NextBSPEntity( ent ) ) { + if ( !trap_AAS_ValueForBSPEpairKey( ent, "model", model, sizeof( model ) ) ) { + continue; + } + if ( model[0] == '*' ) { + modelnum = atoi( model + 1 ); + if ( modelnum > max_bspmodelindex ) { + max_bspmodelindex = modelnum; + } + } + } + //initialize the waypoint heap + BotInitWaypoints(); +} + +/* +================== +BotShutdownDeathmatchAI +================== +*/ +void BotShutdownDeathmatchAI( void ) { +} diff --git a/Projects/Android/jni/rtcw/src/botai/ai_dmq3.h b/Projects/Android/jni/rtcw/src/botai/ai_dmq3.h new file mode 100644 index 0000000..10eaae1 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/botai/ai_dmq3.h @@ -0,0 +1,156 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +/***************************************************************************** + * name: ai_dmq3.h + * + * desc: Quake3 bot AI + * + * + *****************************************************************************/ + +//setup the deathmatch AI +void BotSetupDeathmatchAI( void ); +//shutdown the deathmatch AI +void BotShutdownDeathmatchAI( void ); +//let the bot live within it's deathmatch AI net +void BotDeathmatchAI( bot_state_t *bs, float thinktime ); +//free waypoints +void BotFreeWaypoints( bot_waypoint_t *wp ); +//choose a weapon +void BotChooseWeapon( bot_state_t *bs ); +//setup movement stuff +void BotSetupForMovement( bot_state_t *bs ); +//update the inventory +void BotUpdateInventory( bot_state_t *bs ); +//update the inventory during battle +void BotUpdateBattleInventory( bot_state_t *bs, int enemy ); +//use holdable items during battle +void BotBattleUseItems( bot_state_t *bs ); +//return true if the bot is dead +qboolean BotIsDead( bot_state_t *bs ); +//returns true if the bot is in observer mode +qboolean BotIsObserver( bot_state_t *bs ); +//returns true if the bot is in the intermission +qboolean BotIntermission( bot_state_t *bs ); +//returns true if the bot is in lava +qboolean BotInLava( bot_state_t *bs ); +//returns true if the bot is in slime +qboolean BotInSlime( bot_state_t *bs ); +//returns true if the entity is dead +qboolean EntityIsDead( aas_entityinfo_t *entinfo ); +//returns true if the entity is invisible +qboolean EntityIsInvisible( aas_entityinfo_t *entinfo ); +//returns true if the entity is shooting +qboolean EntityIsShooting( aas_entityinfo_t *entinfo ); +//returns the name of the client +char *ClientName( int client, char *name, int size ); +//returns an simplyfied client name +char *EasyClientName( int client, char *name, int size ); +//returns the skin used by the client +char *ClientSkin( int client, char *skin, int size ); +//returns the aggression of the bot in the range [0, 100] +float BotAggression( bot_state_t *bs ); +//returns true if the bot wants to retreat +int BotWantsToRetreat( bot_state_t *bs ); +//returns true if the bot wants to chase +int BotWantsToChase( bot_state_t *bs ); +//returns true if the bot wants to help +int BotWantsToHelp( bot_state_t *bs ); +//returns true if the bot can and wants to rocketjump +int BotCanAndWantsToRocketJump( bot_state_t *bs ); +//returns true if the bot wants to and goes camping +int BotWantsToCamp( bot_state_t *bs ); +//the bot will perform attack movements +bot_moveresult_t BotAttackMove( bot_state_t *bs, int tfl ); +//returns true if the bot and the entity are in the same team +int BotSameTeam( bot_state_t *bs, int entnum ); +//returns true if teamplay is on +int TeamPlayIsOn( void ); +//returns true and sets the .enemy field when an enemy is found +int BotFindEnemy( bot_state_t *bs, int curenemy ); +//returns a roam goal +void BotRoamGoal( bot_state_t *bs, vec3_t goal ); +//returns entity visibility in the range [0, 1] +float BotEntityVisible( int viewer, vec3_t eye, vec3_t viewangles, float fov, int ent ); +//the bot will aim at the current enemy +void BotAimAtEnemy( bot_state_t *bs ); +//check if the bot should attack +void BotCheckAttack( bot_state_t *bs ); +//AI when the bot is blocked +void BotAIBlocked( bot_state_t *bs, bot_moveresult_t *moveresult, int activate ); +//returns the CTF team the bot is in +int BotCTFTeam( bot_state_t *bs ); +//returns the flag the bot is carrying (CTFFLAG_?) +int BotCTFCarryingFlag( bot_state_t *bs ); +//set ctf goals (defend base, get enemy flag) during seek +void BotCTFSeekGoals( bot_state_t *bs ); +//set ctf goals (defend base, get enemy flag) during retreat +void BotCTFRetreatGoals( bot_state_t *bs ); +//create a new waypoint +bot_waypoint_t *BotCreateWayPoint( char *name, vec3_t origin, int areanum ); +//find a waypoint with the given name +bot_waypoint_t *BotFindWayPoint( bot_waypoint_t *waypoints, char *name ); +//strstr but case insensitive +char *stristr( char *str, char *charset ); +//returns the number of the client with the given name +int ClientFromName( char *name ); +// +int BotPointAreaNum( vec3_t origin ); +// +void BotMapScripts( bot_state_t *bs ); + +//ctf flags +#define CTF_FLAG_NONE 0 +#define CTF_FLAG_RED 1 +#define CTF_FLAG_BLUE 2 +//CTF skins +#define CTF_SKIN_REDTEAM "red" +#define CTF_SKIN_BLUETEAM "blue" +//CTF teams +#define CTF_TEAM_NONE 0 +#define CTF_TEAM_RED 1 +#define CTF_TEAM_BLUE 2 + +extern int dmflags; //deathmatch flags +extern int gametype; //game type + +// Rafael gameskill +extern int gameskill; +// done + +extern vmCvar_t bot_grapple; +extern vmCvar_t bot_rocketjump; +extern vmCvar_t bot_fastchat; +extern vmCvar_t bot_nochat; +extern vmCvar_t bot_testrchat; + +extern bot_goal_t ctf_redflag; +extern bot_goal_t ctf_blueflag; + diff --git a/Projects/Android/jni/rtcw/src/botai/ai_main.c b/Projects/Android/jni/rtcw/src/botai/ai_main.c new file mode 100644 index 0000000..1fca71e --- /dev/null +++ b/Projects/Android/jni/rtcw/src/botai/ai_main.c @@ -0,0 +1,1208 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +/***************************************************************************** + * name: ai_main.c + * + * desc: Quake3 bot AI + * + * + *****************************************************************************/ + +#include "../game/g_local.h" +#include "../game/q_shared.h" +#include "../game/botlib.h" //bot lib interface +#include "../game/be_aas.h" +#include "../game/be_ea.h" +#include "../game/be_ai_char.h" +#include "../game/be_ai_chat.h" +#include "../game/be_ai_gen.h" +#include "../game/be_ai_goal.h" +#include "../game/be_ai_move.h" +#include "../game/be_ai_weap.h" +#include "../botai/botai.h" //bot ai interface + +#include "ai_main.h" +#include "ai_dmq3.h" +#include "ai_chat.h" +#include "ai_cmd.h" +#include "ai_dmnet.h" +// +#include "chars.h" +#include "inv.h" +#include "syn.h" + +#define MAX_PATH 144 + +//bot states +bot_state_t *botstates[MAX_CLIENTS]; +//number of bots +int numbots; +//time to do a regular update +float regularupdate_time; +// +vmCvar_t bot_thinktime; +vmCvar_t memorydump; + + +/* +================== +BotAI_Print +================== +*/ +void QDECL BotAI_Print( int type, char *fmt, ... ) { + char str[2048]; + va_list ap; + + va_start( ap, fmt ); + vsprintf( str, fmt, ap ); + va_end( ap ); + + switch ( type ) { + case PRT_MESSAGE: { + G_Printf( "%s", str ); + break; + } + case PRT_WARNING: { + G_Printf( S_COLOR_YELLOW "Warning: %s", str ); + break; + } + case PRT_ERROR: { + G_Printf( S_COLOR_RED "Error: %s", str ); + break; + } + case PRT_FATAL: { + G_Printf( S_COLOR_RED "Fatal: %s", str ); + break; + } + case PRT_EXIT: { + G_Error( S_COLOR_RED "Exit: %s", str ); + break; + } + default: { + G_Printf( "unknown print type\n" ); + break; + } + } +} + +/* +================== +BotAI_Trace +================== +*/ +void BotAI_Trace( bsp_trace_t *bsptrace, vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end, int passent, int contentmask ) { + trace_t trace; + + trap_Trace( &trace, start, mins, maxs, end, passent, contentmask ); + //copy the trace information + bsptrace->allsolid = trace.allsolid; + bsptrace->startsolid = trace.startsolid; + bsptrace->fraction = trace.fraction; + VectorCopy( trace.endpos, bsptrace->endpos ); + bsptrace->plane.dist = trace.plane.dist; + VectorCopy( trace.plane.normal, bsptrace->plane.normal ); + bsptrace->plane.signbits = trace.plane.signbits; + bsptrace->plane.type = trace.plane.type; + bsptrace->surface.value = trace.surfaceFlags; + bsptrace->ent = trace.entityNum; + bsptrace->exp_dist = 0; + bsptrace->sidenum = 0; + bsptrace->contents = 0; +} + +/* +================== +BotAI_GetClientState +================== +*/ +int BotAI_GetClientState( int clientNum, playerState_t *state ) { + gentity_t *ent; + + ent = &g_entities[clientNum]; + if ( !ent->inuse ) { + return qfalse; + } + if ( !ent->client ) { + return qfalse; + } + + memcpy( state, &ent->client->ps, sizeof( playerState_t ) ); + return qtrue; +} + +/* +================== +BotAI_GetEntityState +================== +*/ +int BotAI_GetEntityState( int entityNum, entityState_t *state ) { + gentity_t *ent; + + ent = &g_entities[entityNum]; + memset( state, 0, sizeof( entityState_t ) ); + if ( !ent->inuse ) { + return qfalse; + } + if ( !ent->r.linked ) { + return qfalse; + } + if ( ent->r.svFlags & SVF_NOCLIENT ) { + return qfalse; + } + memcpy( state, &ent->s, sizeof( entityState_t ) ); + return qtrue; +} + +/* +================== +BotAI_GetSnapshotEntity +================== +*/ +int BotAI_GetSnapshotEntity( int clientNum, int sequence, entityState_t *state ) { + int entNum; + + entNum = trap_BotGetSnapshotEntity( clientNum, sequence ); + if ( entNum == -1 ) { + memset( state, 0, sizeof( entityState_t ) ); + return -1; + } + + BotAI_GetEntityState( entNum, state ); + + return sequence + 1; +} + +/* +================== +BotAI_BotInitialChat +================== +*/ +void QDECL BotAI_BotInitialChat( bot_state_t *bs, char *type, ... ) { + int i, mcontext; + va_list ap; + char *p; + char *vars[MAX_MATCHVARIABLES]; + + memset( vars, 0, sizeof( vars ) ); + va_start( ap, type ); + p = va_arg( ap, char * ); + for ( i = 0; i < MAX_MATCHVARIABLES; i++ ) { + if ( !p ) { + break; + } + vars[i] = p; + p = va_arg( ap, char * ); + } + va_end( ap ); + + mcontext = CONTEXT_NORMAL | CONTEXT_NEARBYITEM | CONTEXT_NAMES; + if ( BotCTFTeam( bs ) == CTF_TEAM_RED ) { + mcontext |= CONTEXT_CTFREDTEAM; + } else { mcontext |= CONTEXT_CTFBLUETEAM;} + + trap_BotInitialChat( bs->cs, type, mcontext, vars[0], vars[1], vars[2], vars[3], vars[4], vars[5], vars[6], vars[7] ); +} + +/* +============== +BotInterbreeding +============== +*/ +void BotInterbreeding( void ) { + float ranks[MAX_CLIENTS]; + int parent1, parent2, child; + int i; + + // get rankings for all the bots + for ( i = 0; i < MAX_CLIENTS; i++ ) { + if ( botstates[i] && botstates[i]->inuse ) { + ranks[i] = botstates[i]->num_kills * 2 - botstates[i]->num_deaths; + } else { + ranks[i] = -1; + } + } + + if ( trap_GeneticParentsAndChildSelection( MAX_CLIENTS, ranks, &parent1, &parent2, &child ) ) { + trap_BotInterbreedGoalFuzzyLogic( botstates[parent1]->gs, botstates[parent2]->gs, botstates[child]->gs ); + trap_BotMutateGoalFuzzyLogic( botstates[child]->gs, 1 ); + } + // reset the kills and deaths + for ( i = 0; i < MAX_CLIENTS; i++ ) { + if ( botstates[i] && botstates[i]->inuse ) { + botstates[i]->num_kills = 0; + botstates[i]->num_deaths = 0; + } + } +} + +/* +============== +BotEntityInfo +============== +*/ +void BotEntityInfo( int entnum, aas_entityinfo_t *info ) { + trap_AAS_EntityInfo( entnum, info ); +} + +/* +============== +NumBots +============== +*/ +int NumBots( void ) { + return numbots; +} + +/* +============== +AngleDifference +============== +*/ +float AngleDifference( float ang1, float ang2 ) { + float diff; + + diff = ang1 - ang2; + if ( ang1 > ang2 ) { + if ( diff > 180.0 ) { + diff -= 360.0; + } + } else { + if ( diff < -180.0 ) { + diff += 360.0; + } + } + return diff; +} + +/* +============== +BotChangeViewAngle +============== +*/ +float BotChangeViewAngle( float angle, float ideal_angle, float speed ) { + float move; + + angle = AngleMod( angle ); + ideal_angle = AngleMod( ideal_angle ); + if ( angle == ideal_angle ) { + return angle; + } + move = ideal_angle - angle; + if ( ideal_angle > angle ) { + if ( move > 180.0 ) { + move -= 360.0; + } + } else { + if ( move < -180.0 ) { + move += 360.0; + } + } + if ( move > 0 ) { + if ( move > speed ) { + move = speed; + } + } else { + if ( move < -speed ) { + move = -speed; + } + } + return AngleMod( angle + move ); +} + +/* +============== +BotChangeViewAngles +============== +*/ +void BotChangeViewAngles( bot_state_t *bs, float thinktime ) { + float diff, factor, maxchange, anglespeed; + int i; + + if ( bs->ideal_viewangles[PITCH] > 180 ) { + bs->ideal_viewangles[PITCH] -= 360; + } + // + if ( bs->enemy >= 0 ) { + factor = trap_Characteristic_BFloat( bs->character, CHARACTERISTIC_VIEW_FACTOR, 0.01, 1 ); + maxchange = trap_Characteristic_BFloat( bs->character, CHARACTERISTIC_VIEW_MAXCHANGE, 1, 1800 ); + } else { + factor = 0.25; + maxchange = 300; + } + maxchange *= thinktime; + for ( i = 0; i < 2; i++ ) { + diff = abs( AngleDifference( bs->viewangles[i], bs->ideal_viewangles[i] ) ); + anglespeed = diff * factor; + if ( anglespeed > maxchange ) { + anglespeed = maxchange; + } + bs->viewangles[i] = BotChangeViewAngle( bs->viewangles[i], + bs->ideal_viewangles[i], anglespeed ); + //BotAI_Print(PRT_MESSAGE, "ideal_angles %f %f\n", bs->ideal_viewangles[0], bs->ideal_viewangles[1], bs->ideal_viewangles[2]);` + //bs->viewangles[i] = bs->ideal_viewangles[i]; + } + if ( bs->viewangles[PITCH] > 180 ) { + bs->viewangles[PITCH] -= 360; + } + //elementary action: view + trap_EA_View( bs->client, bs->viewangles ); +} + +/* +============== +BotInputToUserCommand +============== +*/ +void BotInputToUserCommand( bot_input_t *bi, usercmd_t *ucmd, int delta_angles[3], int time ) { + vec3_t angles, forward, right; + short temp; + int j; + + //clear the whole structure + memset( ucmd, 0, sizeof( usercmd_t ) ); + // + //Com_Printf("dir = %f %f %f speed = %f\n", bi->dir[0], bi->dir[1], bi->dir[2], bi->speed); + //the duration for the user command in milli seconds + ucmd->serverTime = time; + // + if ( bi->actionflags & ACTION_DELAYEDJUMP ) { + bi->actionflags |= ACTION_JUMP; + bi->actionflags &= ~ACTION_DELAYEDJUMP; + } + //set the buttons + if ( bi->actionflags & ACTION_RESPAWN ) { + ucmd->buttons = BUTTON_ATTACK; + } + if ( bi->actionflags & ACTION_ATTACK ) { + ucmd->buttons |= BUTTON_ATTACK; + } + if ( bi->actionflags & ACTION_TALK ) { + ucmd->buttons |= BUTTON_TALK; + } + if ( bi->actionflags & ACTION_GESTURE ) { + ucmd->buttons |= BUTTON_GESTURE; + } + if ( bi->actionflags & ACTION_USE ) { + ucmd->buttons |= BUTTON_USE_HOLDABLE; + } + if ( bi->actionflags & ACTION_WALK ) { + ucmd->buttons |= BUTTON_WALKING; + } + ucmd->weapon = bi->weapon; + //set the view angles + //NOTE: the ucmd->angles are the angles WITHOUT the delta angles + ucmd->angles[PITCH] = ANGLE2SHORT( bi->viewangles[PITCH] ); + ucmd->angles[YAW] = ANGLE2SHORT( bi->viewangles[YAW] ); + ucmd->angles[ROLL] = ANGLE2SHORT( bi->viewangles[ROLL] ); + //subtract the delta angles + for ( j = 0; j < 3; j++ ) { + temp = ucmd->angles[j] - delta_angles[j]; + /*NOTE: disabled because temp should be mod first + if ( j == PITCH ) { + // don't let the player look up or down more than 90 degrees + if ( temp > 16000 ) temp = 16000; + else if ( temp < -16000 ) temp = -16000; + } + */ + ucmd->angles[j] = temp; + } + //NOTE: movement is relative to the REAL view angles + //get the horizontal forward and right vector + //get the pitch in the range [-180, 180] + if ( bi->dir[2] ) { + angles[PITCH] = bi->viewangles[PITCH]; + } else { angles[PITCH] = 0;} + angles[YAW] = bi->viewangles[YAW]; + angles[ROLL] = 0; + AngleVectors( angles, forward, right, NULL ); + //bot input speed is in the range [0, 400] + bi->speed = bi->speed * 127 / 400; + //set the view independent movement + ucmd->forwardmove = DotProduct( forward, bi->dir ) * bi->speed; + ucmd->rightmove = DotProduct( right, bi->dir ) * bi->speed; + ucmd->upmove = abs( forward[2] ) * bi->dir[2] * bi->speed; + //normal keyboard movement + if ( bi->actionflags & ACTION_MOVEFORWARD ) { + ucmd->forwardmove += 127; + } + if ( bi->actionflags & ACTION_MOVEBACK ) { + ucmd->forwardmove -= 127; + } + if ( bi->actionflags & ACTION_MOVELEFT ) { + ucmd->rightmove -= 127; + } + if ( bi->actionflags & ACTION_MOVERIGHT ) { + ucmd->rightmove += 127; + } + //jump/moveup + if ( bi->actionflags & ACTION_JUMP ) { + ucmd->upmove += 127; + } + //crouch/movedown + if ( bi->actionflags & ACTION_CROUCH ) { + ucmd->upmove -= 127; + } + // + //Com_Printf("forward = %d right = %d up = %d\n", ucmd.forwardmove, ucmd.rightmove, ucmd.upmove); + //Com_Printf("ucmd->serverTime = %d\n", ucmd->serverTime); +} + +/* +============== +BotUpdateInput +============== +*/ +void BotUpdateInput( bot_state_t *bs, int time ) { + bot_input_t bi; + int j; + + //add the delta angles to the bot's current view angles + for ( j = 0; j < 3; j++ ) { + bs->viewangles[j] = AngleMod( bs->viewangles[j] + SHORT2ANGLE( bs->cur_ps.delta_angles[j] ) ); + } + // + BotChangeViewAngles( bs, (float) time / 1000 ); + trap_EA_GetInput( bs->client, (float) time / 1000, &bi ); + //respawn hack + if ( bi.actionflags & ACTION_RESPAWN ) { + if ( bs->lastucmd.buttons & BUTTON_ATTACK ) { + bi.actionflags &= ~( ACTION_RESPAWN | ACTION_ATTACK ); + } + } + // + BotInputToUserCommand( &bi, &bs->lastucmd, bs->cur_ps.delta_angles, time ); + bs->lastucmd.serverTime = time; + //subtract the delta angles + for ( j = 0; j < 3; j++ ) { + bs->viewangles[j] = AngleMod( bs->viewangles[j] - SHORT2ANGLE( bs->cur_ps.delta_angles[j] ) ); + } +} + +/* +============== +BotAIRegularUpdate +============== +*/ +void BotAIRegularUpdate( void ) { + if ( regularupdate_time < trap_AAS_Time() ) { + trap_BotUpdateEntityItems(); + regularupdate_time = trap_AAS_Time() + 1; + } +} + +/* +============== +BotAI +============== +*/ +int BotAI( int client, float thinktime ) { + bot_state_t *bs; + char buf[1024], *args; + int j; + + trap_EA_ResetInput( client, NULL ); + // + bs = botstates[client]; + if ( !bs || !bs->inuse ) { + BotAI_Print( PRT_FATAL, "client %d hasn't been setup\n", client ); + return BLERR_AICLIENTNOTSETUP; + } + + //retrieve the current client state + BotAI_GetClientState( client, &bs->cur_ps ); + + //retrieve any waiting console messages + while ( trap_BotGetServerCommand( client, buf, sizeof( buf ) ) ) { + //have buf point to the command and args to the command arguments + args = strchr( buf, ' ' ); + if ( !args ) { + continue; + } + *args++ = '\0'; + + //remove color espace sequences from the arguments + Q_CleanStr( args ); + + //botai_import.Print(PRT_MESSAGE, "ConsoleMessage: \"%s\"\n", buf); + if ( !Q_stricmp( buf, "cp " ) ) { /*CenterPrintf*/ + } else if ( !Q_stricmp( buf, "cs" ) ) { /*ConfigStringModified*/ + } else if ( !Q_stricmp( buf, "print" ) ) { + trap_BotQueueConsoleMessage( bs->cs, CMS_NORMAL, args ); + } else if ( !Q_stricmp( buf, "chat" ) ) { + trap_BotQueueConsoleMessage( bs->cs, CMS_CHAT, args ); + } else if ( !Q_stricmp( buf, "tchat" ) ) { + trap_BotQueueConsoleMessage( bs->cs, CMS_CHAT, args ); + } else if ( !Q_stricmp( buf, "scores" ) ) { /*FIXME: parse scores?*/ + } else if ( !Q_stricmp( buf, "clientLevelShot" ) ) { /*ignore*/ + } + } + //add the delta angles to the bot's current view angles + for ( j = 0; j < 3; j++ ) { + bs->viewangles[j] = AngleMod( bs->viewangles[j] + SHORT2ANGLE( bs->cur_ps.delta_angles[j] ) ); + } + //increase the local time of the bot + bs->ltime += thinktime; + // + bs->thinktime = thinktime; + //origin of the bot + VectorCopy( bs->cur_ps.origin, bs->origin ); + //eye coordinates of the bot + VectorCopy( bs->cur_ps.origin, bs->eye ); + bs->eye[2] += bs->cur_ps.viewheight; + //get the area the bot is in + bs->areanum = BotPointAreaNum( bs->origin ); + //the real AI + BotDeathmatchAI( bs, thinktime ); + //set the weapon selection every AI frame + trap_EA_SelectWeapon( bs->client, bs->weaponnum ); + //subtract the delta angles + for ( j = 0; j < 3; j++ ) { + bs->viewangles[j] = AngleMod( bs->viewangles[j] - SHORT2ANGLE( bs->cur_ps.delta_angles[j] ) ); + } + //everything was ok + return BLERR_NOERROR; +} + +/* +================== +BotScheduleBotThink +================== +*/ +void BotScheduleBotThink( void ) { + int i, botnum; + + botnum = 0; + + for ( i = 0; i < MAX_CLIENTS; i++ ) { + if ( !botstates[i] || !botstates[i]->inuse ) { + continue; + } + //initialize the bot think residual time + botstates[i]->botthink_residual = bot_thinktime.integer * botnum / numbots; + botnum++; + } +} + +/* +============== +BotAISetupClient +============== +*/ +int BotAISetupClient( int client, struct bot_settings_s *settings ) { + char filename[MAX_PATH], name[MAX_PATH], gender[MAX_PATH]; + bot_state_t *bs; + int errnum; + + if ( !botstates[client] ) { + botstates[client] = G_Alloc( sizeof( bot_state_t ) ); + } + bs = botstates[client]; + + if ( bs && bs->inuse ) { + BotAI_Print( PRT_FATAL, "client %d already setup\n", client ); + return qfalse; + } + + if ( !trap_AAS_Initialized() ) { + BotAI_Print( PRT_FATAL, "AAS not initialized\n" ); + return qfalse; + } + + //load the bot character + bs->character = trap_BotLoadCharacter( settings->characterfile, settings->skill ); + if ( !bs->character ) { + BotAI_Print( PRT_FATAL, "couldn't load skill %d from %s\n", settings->skill, settings->characterfile ); + return qfalse; + } + //copy the settings + memcpy( &bs->settings, settings, sizeof( bot_settings_t ) ); + //allocate a goal state + bs->gs = trap_BotAllocGoalState( client ); + //load the item weights + trap_Characteristic_String( bs->character, CHARACTERISTIC_ITEMWEIGHTS, filename, MAX_PATH ); + errnum = trap_BotLoadItemWeights( bs->gs, filename ); + if ( errnum != BLERR_NOERROR ) { + trap_BotFreeGoalState( bs->gs ); + return qfalse; + } + //allocate a weapon state + bs->ws = trap_BotAllocWeaponState(); + //load the weapon weights + trap_Characteristic_String( bs->character, CHARACTERISTIC_WEAPONWEIGHTS, filename, MAX_PATH ); + errnum = trap_BotLoadWeaponWeights( bs->ws, filename ); + if ( errnum != BLERR_NOERROR ) { + trap_BotFreeGoalState( bs->gs ); + trap_BotFreeWeaponState( bs->ws ); + return qfalse; + } + //allocate a chat state + bs->cs = trap_BotAllocChatState(); + //load the chat file + trap_Characteristic_String( bs->character, CHARACTERISTIC_CHAT_FILE, filename, MAX_PATH ); + trap_Characteristic_String( bs->character, CHARACTERISTIC_CHAT_NAME, name, MAX_PATH ); + errnum = trap_BotLoadChatFile( bs->cs, filename, name ); + if ( errnum != BLERR_NOERROR ) { + trap_BotFreeChatState( bs->cs ); + trap_BotFreeGoalState( bs->gs ); + trap_BotFreeWeaponState( bs->ws ); + return qfalse; + } + //get the gender characteristic + trap_Characteristic_String( bs->character, CHARACTERISTIC_GENDER, gender, MAX_PATH ); + //set the chat gender + if ( *gender == 'f' || *gender == 'F' ) { + trap_BotSetChatGender( bs->cs, CHAT_GENDERFEMALE ); + } else if ( *gender == 'm' || *gender == 'M' ) { + trap_BotSetChatGender( bs->cs, CHAT_GENDERMALE ); + } else { trap_BotSetChatGender( bs->cs, CHAT_GENDERLESS );} + + bs->inuse = qtrue; + bs->client = client; + bs->entitynum = client; + bs->setupcount = 4; + bs->entergame_time = trap_AAS_Time(); + bs->ms = trap_BotAllocMoveState(); + bs->walker = trap_Characteristic_BFloat( bs->character, CHARACTERISTIC_WALKER, 0, 1 ); + numbots++; + + if ( trap_Cvar_VariableIntegerValue( "bot_testichat" ) ) { + trap_BotLibVarSet( "bot_testichat", "1" ); + BotChatTest( bs ); + } + //NOTE: reschedule the bot thinking + BotScheduleBotThink(); + // + return qtrue; +} + +/* +============== +BotAIShutdownClient +============== +*/ +int BotAIShutdownClient( int client ) { + bot_state_t *bs; + + // Wolfenstein + if ( g_entities[client].r.svFlags & SVF_CASTAI ) { + AICast_ShutdownClient( client ); + return BLERR_NOERROR; + } + // done. + + bs = botstates[client]; + if ( !bs || !bs->inuse ) { + // BotAI_Print(PRT_ERROR, "client %d already shutdown\n", client); + return BLERR_AICLIENTALREADYSHUTDOWN; + } + + if ( BotChat_ExitGame( bs ) ) { + trap_BotEnterChat( bs->cs, bs->client, CHAT_ALL ); + } + + trap_BotFreeMoveState( bs->ms ); + //free the goal state + trap_BotFreeGoalState( bs->gs ); + //free the chat file + trap_BotFreeChatState( bs->cs ); + //free the weapon weights + trap_BotFreeWeaponState( bs->ws ); + //free the bot character + trap_BotFreeCharacter( bs->character ); + // + BotFreeWaypoints( bs->checkpoints ); + BotFreeWaypoints( bs->patrolpoints ); + //clear the bot state + memset( bs, 0, sizeof( bot_state_t ) ); + //set the inuse flag to qfalse + bs->inuse = qfalse; + //there's one bot less + numbots--; + //everything went ok + return BLERR_NOERROR; +} + +/* +============== +BotResetState + +called when a bot enters the intermission or observer mode and +when the level is changed +============== +*/ +void BotResetState( bot_state_t *bs ) { + int client, entitynum, inuse; + int movestate, goalstate, chatstate, weaponstate; + bot_settings_t settings; + int character; + playerState_t ps; //current player state + float entergame_time; + + //save some things that should not be reset here + memcpy( &settings, &bs->settings, sizeof( bot_settings_t ) ); + memcpy( &ps, &bs->cur_ps, sizeof( playerState_t ) ); + inuse = bs->inuse; + client = bs->client; + entitynum = bs->entitynum; + character = bs->character; + movestate = bs->ms; + goalstate = bs->gs; + chatstate = bs->cs; + weaponstate = bs->ws; + entergame_time = bs->entergame_time; + //free checkpoints and patrol points + BotFreeWaypoints( bs->checkpoints ); + BotFreeWaypoints( bs->patrolpoints ); + //reset the whole state + memset( bs, 0, sizeof( bot_state_t ) ); + //copy back some state stuff that should not be reset + bs->ms = movestate; + bs->gs = goalstate; + bs->cs = chatstate; + bs->ws = weaponstate; + memcpy( &bs->cur_ps, &ps, sizeof( playerState_t ) ); + memcpy( &bs->settings, &settings, sizeof( bot_settings_t ) ); + bs->inuse = inuse; + bs->client = client; + bs->entitynum = entitynum; + bs->character = character; + bs->entergame_time = entergame_time; + //reset several states + if ( bs->ms ) { + trap_BotResetMoveState( bs->ms ); + } + if ( bs->gs ) { + trap_BotResetGoalState( bs->gs ); + } + if ( bs->ws ) { + trap_BotResetWeaponState( bs->ws ); + } + if ( bs->gs ) { + trap_BotResetAvoidGoals( bs->gs ); + } + if ( bs->ms ) { + trap_BotResetAvoidReach( bs->ms ); + } +} + +/* +============== +BotAILoadMap +============== +*/ +int BotAILoadMap( int restart ) { + int i; + vmCvar_t mapname; + + if ( !restart ) { + trap_Cvar_Register( &mapname, "mapname", "", CVAR_SERVERINFO | CVAR_ROM ); + trap_BotLibLoadMap( mapname.string ); + } + + for ( i = 0; i < MAX_CLIENTS; i++ ) { + if ( botstates[i] && botstates[i]->inuse ) { + BotResetState( botstates[i] ); + botstates[i]->setupcount = 4; + } + } + + BotSetupDeathmatchAI(); + + return BLERR_NOERROR; +} + +/* +================== +BotAIStartFrame +================== +*/ +int BotAIStartFrame( int time ) { + int i; + gentity_t *ent; + bot_entitystate_t state; + //entityState_t entitystate; + //vec3_t mins = {-15, -15, -24}, maxs = {15, 15, 32}; + int elapsed_time, thinktime; + static int local_time; + static int botlib_residual; + static int lastbotthink_time; + + if ( g_gametype.integer != GT_SINGLE_PLAYER ) { + G_CheckBotSpawn(); + } + + trap_Cvar_Update( &bot_rocketjump ); + trap_Cvar_Update( &bot_grapple ); + trap_Cvar_Update( &bot_fastchat ); + trap_Cvar_Update( &bot_nochat ); + trap_Cvar_Update( &bot_testrchat ); + trap_Cvar_Update( &bot_thinktime ); + // Ridah, set the default AAS world + trap_AAS_SetCurrentWorld( 0 ); + trap_Cvar_Update( &memorydump ); + + if ( memorydump.integer ) { + trap_BotLibVarSet( "memorydump", "1" ); + trap_Cvar_Set( "memorydump", "0" ); + } + + //if the bot think time changed we should reschedule the bots + if ( bot_thinktime.integer != lastbotthink_time ) { + lastbotthink_time = bot_thinktime.integer; + BotScheduleBotThink(); + } + + elapsed_time = time - local_time; + local_time = time; + + botlib_residual += elapsed_time; + + if ( elapsed_time > bot_thinktime.integer ) { + thinktime = elapsed_time; + } else { thinktime = bot_thinktime.integer;} + + // update the bot library + if ( botlib_residual >= thinktime ) { + botlib_residual -= thinktime; + + trap_BotLibStartFrame( (float) time / 1000 ); + + // Ridah, only check the default world + trap_AAS_SetCurrentWorld( 0 ); + + if ( !trap_AAS_Initialized() ) { + return BLERR_NOERROR; + } + + //update entities in the botlib + for ( i = 0; i < MAX_GENTITIES; i++ ) { + + // Ridah, in single player, we only need client entity information + if ( g_gametype.integer == GT_SINGLE_PLAYER && i > level.maxclients ) { + break; + } + + ent = &g_entities[i]; + if ( !ent->inuse ) { + continue; + } + if ( !ent->r.linked ) { + continue; + } + if ( ent->r.svFlags & SVF_NOCLIENT ) { + continue; + } + if ( ent->aiInactive ) { + continue; + } + // + memset( &state, 0, sizeof( bot_entitystate_t ) ); + // + VectorCopy( ent->r.currentOrigin, state.origin ); + VectorCopy( ent->r.currentAngles, state.angles ); + VectorCopy( ent->s.origin2, state.old_origin ); + VectorCopy( ent->r.mins, state.mins ); + VectorCopy( ent->r.maxs, state.maxs ); + state.type = ent->s.eType; + state.flags = ent->s.eFlags; + if ( ent->r.bmodel ) { + state.solid = SOLID_BSP; + } else { state.solid = SOLID_BBOX;} + state.groundent = ent->s.groundEntityNum; + state.modelindex = ent->s.modelindex; + state.modelindex2 = ent->s.modelindex2; + state.frame = ent->s.frame; + //state.event = ent->s.event; + //state.eventParm = ent->s.eventParm; + state.powerups = ent->s.powerups; + state.legsAnim = ent->s.legsAnim; + state.torsoAnim = ent->s.torsoAnim; +// state.weapAnim = ent->s.weapAnim; //----(SA) +//----(SA) didn't want to comment in as I wasn't sure of any implications of changing the aas_entityinfo_t and bot_entitystate_t structures. + state.weapon = ent->s.weapon; + /* + if (!BotAI_GetEntityState(i, &entitystate)) continue; + // + memset(&state, 0, sizeof(bot_entitystate_t)); + // + VectorCopy(entitystate.pos.trBase, state.origin); + VectorCopy(entitystate.angles, state.angles); + VectorCopy(ent->s.origin2, state.old_origin); + //VectorCopy(ent->r.mins, state.mins); + //VectorCopy(ent->r.maxs, state.maxs); + state.type = entitystate.eType; + state.flags = entitystate.eFlags; + if (ent->r.bmodel) state.solid = SOLID_BSP; + else state.solid = SOLID_BBOX; + state.modelindex = entitystate.modelindex; + state.modelindex2 = entitystate.modelindex2; + state.frame = entitystate.frame; + state.event = entitystate.event; + state.eventParm = entitystate.eventParm; + state.powerups = entitystate.powerups; + state.legsAnim = entitystate.legsAnim; + state.torsoAnim = entitystate.torsoAnim; + state.weapon = entitystate.weapon; + */ + // + trap_BotLibUpdateEntity( i, &state ); + } + + BotAIRegularUpdate(); + + } + + // Ridah, in single player, don't need bot's thinking + if ( g_gametype.integer == GT_SINGLE_PLAYER ) { + return BLERR_NOERROR; + } + + // execute scheduled bot AI + for ( i = 0; i < MAX_CLIENTS; i++ ) { + if ( !botstates[i] || !botstates[i]->inuse ) { + continue; + } + // Ridah + if ( g_entities[i].r.svFlags & SVF_CASTAI ) { + continue; + } + // done. + // + botstates[i]->botthink_residual += elapsed_time; + // + if ( botstates[i]->botthink_residual >= thinktime ) { + botstates[i]->botthink_residual -= thinktime; + + if ( !trap_AAS_Initialized() ) { + return BLERR_NOERROR; + } + + if ( g_entities[i].client->pers.connected == CON_CONNECTED ) { + BotAI( i, (float) thinktime / 1000 ); + } + } + } + + + // execute bot user commands every frame + for ( i = 0; i < MAX_CLIENTS; i++ ) { + if ( !botstates[i] || !botstates[i]->inuse ) { + continue; + } + // Ridah + if ( g_entities[i].r.svFlags & SVF_CASTAI ) { + continue; + } + // done. + if ( g_entities[i].client->pers.connected != CON_CONNECTED ) { + continue; + } + + BotUpdateInput( botstates[i], time ); + trap_BotUserCommand( botstates[i]->client, &botstates[i]->lastucmd ); + } + + return BLERR_NOERROR; +} + +/* +============== +BotInitLibrary +============== +*/ +int BotInitLibrary( void ) { + char buf[144]; + + //set the maxclients and maxentities library variables before calling BotSetupLibrary + trap_Cvar_VariableStringBuffer( "sv_maxclients", buf, sizeof( buf ) ); + if ( !strlen( buf ) ) { + strcpy( buf, "8" ); + } + trap_BotLibVarSet( "maxclients", buf ); + Com_sprintf( buf, sizeof( buf ), "%d", MAX_GENTITIES ); + trap_BotLibVarSet( "maxentities", buf ); + //bsp checksum + trap_Cvar_VariableStringBuffer( "sv_mapChecksum", buf, sizeof( buf ) ); + if ( strlen( buf ) ) { + trap_BotLibVarSet( "sv_mapChecksum", buf ); + } + //maximum number of aas links + trap_Cvar_VariableStringBuffer( "max_aaslinks", buf, sizeof( buf ) ); + if ( strlen( buf ) ) { + trap_BotLibVarSet( "max_aaslinks", buf ); + } + //maximum number of items in a level + trap_Cvar_VariableStringBuffer( "max_levelitems", buf, sizeof( buf ) ); + if ( strlen( buf ) ) { + trap_BotLibVarSet( "max_levelitems", buf ); + } + //automatically launch WinBSPC if AAS file not available + trap_Cvar_VariableStringBuffer( "autolaunchbspc", buf, sizeof( buf ) ); + if ( strlen( buf ) ) { + trap_BotLibVarSet( "autolaunchbspc", "1" ); + } + // + trap_Cvar_VariableStringBuffer( "g_gametype", buf, sizeof( buf ) ); + if ( !strlen( buf ) ) { + strcpy( buf, "0" ); + } + trap_BotLibVarSet( "g_gametype", buf ); + // + // Rafael gameskill + trap_Cvar_VariableStringBuffer( "g_gameskill", buf, sizeof( buf ) ); + if ( !strlen( buf ) ) { + strcpy( buf, "0" ); + } + trap_BotLibVarSet( "g_gamekill", buf ); + // done + // + trap_Cvar_VariableStringBuffer( "bot_developer", buf, sizeof( buf ) ); + if ( !strlen( buf ) ) { + strcpy( buf, "0" ); + } + trap_BotLibVarSet( "bot_developer", buf ); + //log file + trap_Cvar_VariableStringBuffer( "bot_developer", buf, sizeof( buf ) ); + if ( !strlen( buf ) ) { + strcpy( buf, "0" ); + } + trap_BotLibVarSet( "log", buf ); + //no chatting + trap_Cvar_VariableStringBuffer( "bot_nochat", buf, sizeof( buf ) ); + if ( strlen( buf ) ) { + trap_BotLibVarSet( "nochat", "0" ); + } + //forced clustering calculations + trap_Cvar_VariableStringBuffer( "forceclustering", buf, sizeof( buf ) ); + if ( strlen( buf ) ) { + trap_BotLibVarSet( "forceclustering", buf ); + } + //forced reachability calculations + trap_Cvar_VariableStringBuffer( "forcereachability", buf, sizeof( buf ) ); + if ( strlen( buf ) ) { + trap_BotLibVarSet( "forcereachability", buf ); + } + //force writing of AAS to file + trap_Cvar_VariableStringBuffer( "forcewrite", buf, sizeof( buf ) ); + if ( strlen( buf ) ) { + trap_BotLibVarSet( "forcewrite", buf ); + } + //no AAS optimization + trap_Cvar_VariableStringBuffer( "nooptimize", buf, sizeof( buf ) ); + if ( strlen( buf ) ) { + trap_BotLibVarSet( "nooptimize", buf ); + } + //number of reachabilities to calculate each frame + trap_Cvar_VariableStringBuffer( "framereachability", buf, sizeof( buf ) ); + if ( !strlen( buf ) ) { + strcpy( buf, "20" ); + } + trap_BotLibVarSet( "framereachability", buf ); + // + trap_Cvar_VariableStringBuffer( "bot_reloadcharacters", buf, sizeof( buf ) ); + if ( !strlen( buf ) ) { + strcpy( buf, "0" ); + } + trap_BotLibVarSet( "bot_reloadcharacters", buf ); + //base directory + trap_Cvar_VariableStringBuffer( "fs_basepath", buf, sizeof( buf ) ); + if ( strlen( buf ) ) { + trap_BotLibVarSet( "basedir", buf ); + } + //game directory + trap_Cvar_VariableStringBuffer( "fs_game", buf, sizeof( buf ) ); + if ( strlen( buf ) ) { + trap_BotLibVarSet( "gamedir", buf ); + } + //cd directory + trap_Cvar_VariableStringBuffer( "fs_cdpath", buf, sizeof( buf ) ); + if ( strlen( buf ) ) { + trap_BotLibVarSet( "cddir", buf ); + } + //setup the bot library + return trap_BotLibSetup(); +} + +/* +============== +BotAISetup +============== +*/ +int BotAISetup( int restart ) { + int errnum; + +#ifdef RANDOMIZE + srand( (unsigned)time( NULL ) ); +#endif //RANDOMIZE + + trap_Cvar_Register( &bot_thinktime, "bot_thinktime", "100", 0 ); + trap_Cvar_Register( &memorydump, "memorydump", "0", 0 ); + + //if the game is restarted for a tournament + if ( restart ) { + return BLERR_NOERROR; + } + + //initialize the bot states + memset( botstates, 0, sizeof( botstates ) ); + + trap_Cvar_Register( &bot_thinktime, "bot_thinktime", "100", 0 ); + + errnum = BotInitLibrary(); + if ( errnum != BLERR_NOERROR ) { + return qfalse; + } + return BLERR_NOERROR; +} + +/* +============== +BotAIShutdown +============== +*/ +int BotAIShutdown( int restart ) { + + int i; + + //if the game is restarted for a tournament + if ( restart ) { + //shutdown all the bots in the botlib + for ( i = 0; i < MAX_CLIENTS; i++ ) { + if ( botstates[i] && botstates[i]->inuse ) { + BotAIShutdownClient( botstates[i]->client ); + } + } + //don't shutdown the bot library + } else { + trap_BotLibShutdown(); + } + return qtrue; +} + diff --git a/Projects/Android/jni/rtcw/src/botai/ai_main.h b/Projects/Android/jni/rtcw/src/botai/ai_main.h new file mode 100644 index 0000000..4ba5177 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/botai/ai_main.h @@ -0,0 +1,242 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +/***************************************************************************** + * name: ai_main.h + * + * desc: Quake3 bot AI + * + * + *****************************************************************************/ + +//#define DEBUG +#define CTF + +#define MAX_ITEMS 256 +//bot flags +#define BFL_STRAFERIGHT 1 //strafe to the right +#define BFL_ATTACKED 2 //bot has attacked last ai frame +#define BFL_ATTACKJUMPED 4 //bot jumped during attack last frame +#define BFL_AIMATENEMY 8 //bot aimed at the enemy this frame +#define BFL_AVOIDRIGHT 16 //avoid obstacles by going to the right +#define BFL_IDEALVIEWSET 32 //bot has ideal view angles set +//long term goal types +#define LTG_TEAMHELP 1 //help a team mate +#define LTG_TEAMACCOMPANY 2 //accompany a team mate +#define LTG_DEFENDKEYAREA 3 //defend a key area +#define LTG_GETFLAG 4 //get the enemy flag +#define LTG_RUSHBASE 5 //rush to the base +#define LTG_RETURNFLAG 6 //return the flag +#define LTG_CAMP 7 //camp somewhere +#define LTG_CAMPORDER 8 //ordered to camp somewhere +#define LTG_PATROL 9 //patrol +#define LTG_GETITEM 10 //get an item +#define LTG_KILL 11 //kill someone +//some goal dedication times +#define TEAM_HELP_TIME 60 //1 minute teamplay help time +#define TEAM_ACCOMPANY_TIME 600 //10 minutes teamplay accompany time +#define TEAM_DEFENDKEYAREA_TIME 240 //4 minutes ctf defend base time +#define TEAM_CAMP_TIME 600 //10 minutes camping time +#define TEAM_PATROL_TIME 600 //10 minutes patrolling time +#define TEAM_LEAD_TIME 600 //10 minutes taking the lead +#define TEAM_GETITEM_TIME 60 //1 minute +#define TEAM_KILL_SOMEONE 180 //3 minute to kill someone +#define CTF_GETFLAG_TIME 240 //4 minutes ctf get flag time +#define CTF_RUSHBASE_TIME 120 //2 minutes ctf rush base time +#define CTF_RETURNFLAG_TIME 180 //3 minutes to return the flag +#define CTF_ROAM_TIME 60 //1 minute ctf roam time +//patrol flags +#define PATROL_LOOP 1 +#define PATROL_REVERSE 2 +#define PATROL_BACK 4 +//copied from the aas file header +#define PRESENCE_NONE 1 +#define PRESENCE_NORMAL 2 +#define PRESENCE_CROUCH 4 + +//check points +typedef struct bot_waypoint_s +{ + int inuse; + char name[32]; + bot_goal_t goal; + struct bot_waypoint_s *next, *prev; +} bot_waypoint_t; + +//bot state +typedef struct bot_state_s +{ + int inuse; //true if this state is used by a bot client + int botthink_residual; //residual for the bot thinks + int client; //client number of the bot + int entitynum; //entity number of the bot + playerState_t cur_ps; //current player state + int last_eFlags; //last ps flags + usercmd_t lastucmd; //usercmd from last frame + int entityeventTime[1024]; //last entity event time + // + bot_settings_t settings; //several bot settings + int ( *ainode )( struct bot_state_s *bs ); //current AI node + float thinktime; //time the bot thinks this frame + vec3_t origin; //origin of the bot + vec3_t velocity; //velocity of the bot + int presencetype; //presence type of the bot + vec3_t eye; //eye coordinates of the bot + int areanum; //the number of the area the bot is in + int inventory[MAX_ITEMS]; //string with items amounts the bot has + int tfl; //the travel flags the bot uses + int flags; //several flags + int respawn_wait; //wait until respawned + int lasthealth; //health value previous frame + int lastkilledplayer; //last killed player + int lastkilledby; //player that last killed this bot + int botdeathtype; //the death type of the bot + int enemydeathtype; //the death type of the enemy + int botsuicide; //true when the bot suicides + int enemysuicide; //true when the enemy of the bot suicides + int setupcount; //true when the bot has just been setup + int entergamechat; //true when the bot used an enter game chat + int num_deaths; //number of time this bot died + int num_kills; //number of kills of this bot + int revenge_enemy; //the revenge enemy + int revenge_kills; //number of kills the enemy made + int lastframe_health; //health value the last frame + int lasthitcount; //number of hits last frame + int chatto; //chat to all or team + float walker; //walker charactertic + float ltime; //local bot time + float entergame_time; //time the bot entered the game + float ltg_time; //long term goal time + float nbg_time; //nearby goal time + float respawn_time; //time the bot takes to respawn + float respawnchat_time; //time the bot started a chat during respawn + float chase_time; //time the bot will chase the enemy + float enemyvisible_time; //time the enemy was last visible + float check_time; //time to check for nearby items + float stand_time; //time the bot is standing still + float lastchat_time; //time the bot last selected a chat + float standfindenemy_time; //time to find enemy while standing + float attackstrafe_time; //time the bot is strafing in one dir + float attackcrouch_time; //time the bot will stop crouching + float attackchase_time; //time the bot chases during actual attack + float attackjump_time; //time the bot jumped during attack + float enemysight_time; //time before reacting to enemy + float enemydeath_time; //time the enemy died + float enemyposition_time; //time the position and velocity of the enemy were stored + float activate_time; //time to activate something + float activatemessage_time; //time to show activate message + float defendaway_time; //time away while defending + float defendaway_range; //max travel time away from defend area + float rushbaseaway_time; //time away from rushing to the base + float ctfroam_time; //time the bot is roaming in ctf + float killedenemy_time; //time the bot killed the enemy + float arrive_time; //time arrived (at companion) + float lastair_time; //last time the bot had air + float teleport_time; //last time the bot teleported + float camp_time; //last time camped + float camp_range; //camp range + float weaponchange_time; //time the bot started changing weapons + float firethrottlewait_time; //amount of time to wait + float firethrottleshoot_time; //amount of time to shoot + vec3_t aimtarget; + vec3_t enemyvelocity; //enemy velocity 0.5 secs ago during battle + vec3_t enemyorigin; //enemy origin 0.5 secs ago during battle + // + int character; //the bot character + int ms; //move state of the bot + int gs; //goal state of the bot + int cs; //chat state of the bot + int ws; //weapon state of the bot + // + int enemy; //enemy entity number + int lastenemyareanum; //last reachability area the enemy was in + vec3_t lastenemyorigin; //last origin of the enemy in the reachability area + int weaponnum; //current weapon number + vec3_t viewangles; //current view angles + vec3_t ideal_viewangles; //ideal view angles + // + int ltgtype; //long term goal type + // + int teammate; //team mate + bot_goal_t teamgoal; //the team goal + float teammessage_time; //time to message team mates what the bot is doing + float teamgoal_time; //time to stop helping team mate + float teammatevisible_time; //last time the team mate was NOT visible + // + int lead_teammate; //team mate the bot is leading + bot_goal_t lead_teamgoal; //team goal while leading + float lead_time; //time leading someone + float leadvisible_time; //last time the team mate was visible + float leadmessage_time; //last time a messaged was sent to the team mate + float leadbackup_time; //time backing up towards team mate + // + char teamleader[32]; //netname of the team leader + float askteamleader_time; //time asked for team leader + float becometeamleader_time; //time the bot will become the team leader + float teamgiveorders_time; //time to give team orders + int numteammates; //number of team mates + int redflagstatus; //0 = at base, 1 = not at base + int blueflagstatus; //0 = at base, 1 = not at base + int flagstatuschanged; //flag status changed + int forceorders; //true if forced to give orders + int flagcarrier; //team mate carrying the enemy flag + char subteam[32]; //sub team name + float formation_dist; //formation team mate intervening space + char formation_teammate[16]; //netname of the team mate the bot uses for relative positioning + float formation_angle; //angle relative to the formation team mate + vec3_t formation_dir; //the direction the formation is moving in + vec3_t formation_origin; //origin the bot uses for relative positioning + bot_goal_t formation_goal; //formation goal + bot_goal_t activategoal; //goal to activate (buttons etc.) + bot_waypoint_t *checkpoints; //check points + bot_waypoint_t *patrolpoints; //patrol points + bot_waypoint_t *curpatrolpoint; //current patrol point the bot is going for + int patrolflags; //patrol flags +} bot_state_t; + +//resets the whole bot state +void BotResetState( bot_state_t *bs ); +//returns the number of bots in the game +int NumBots( void ); +//returns info about the entity +void BotEntityInfo( int entnum, aas_entityinfo_t *info ); + +// Ridah, defines for AI Cast system +int AICast_ShutdownClient( int client ); +void AICast_Init( void ); +void AICast_StartFrame( int time ); +// done. + +// from the game source +void QDECL BotAI_Print( int type, char *fmt, ... ); +void QDECL QDECL BotAI_BotInitialChat( bot_state_t *bs, char *type, ... ); +void BotAI_Trace( bsp_trace_t *bsptrace, vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end, int passent, int contentmask ); +int BotAI_GetClientState( int clientNum, playerState_t *state ); +int BotAI_GetEntityState( int entityNum, entityState_t *state ); +int BotAI_GetSnapshotEntity( int clientNum, int sequence, entityState_t *state ); diff --git a/Projects/Android/jni/rtcw/src/botai/ai_team.c b/Projects/Android/jni/rtcw/src/botai/ai_team.c new file mode 100644 index 0000000..80f9993 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/botai/ai_team.c @@ -0,0 +1,612 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +/***************************************************************************** + * name: ai_team.c + * + * desc: Quake3 bot AI + * + * + *****************************************************************************/ + +#include "../game/g_local.h" +#include "../game/botlib.h" +#include "../game/be_aas.h" +#include "../game/be_ea.h" +#include "../game/be_ai_char.h" +#include "../game/be_ai_chat.h" +#include "../game/be_ai_gen.h" +#include "../game/be_ai_goal.h" +#include "../game/be_ai_move.h" +#include "../game/be_ai_weap.h" +#include "../botai/botai.h" +// +#include "ai_main.h" +#include "ai_dmq3.h" +#include "ai_chat.h" +#include "ai_cmd.h" +#include "ai_dmnet.h" + + +/* +================== +BotValidTeamLeader +================== +*/ +int BotValidTeamLeader( bot_state_t *bs ) { + if ( !strlen( bs->teamleader ) ) { + return qfalse; + } + if ( ClientFromName( bs->teamleader ) == -1 ) { + return qfalse; + } + return qtrue; +} + +/* +================== +BotNumTeamMates +================== +*/ +int BotNumTeamMates( bot_state_t *bs ) { + int i, numplayers; + char buf[MAX_INFO_STRING]; + static int maxclients; + + if ( !maxclients ) { + maxclients = trap_Cvar_VariableIntegerValue( "sv_maxclients" ); + } + + numplayers = 0; + for ( i = 0; i < maxclients && i < MAX_CLIENTS; i++ ) { + trap_GetConfigstring( CS_PLAYERS + i, buf, sizeof( buf ) ); + //if no config string or no name + if ( !strlen( buf ) || !strlen( Info_ValueForKey( buf, "n" ) ) ) { + continue; + } + //skip spectators + if ( atoi( Info_ValueForKey( buf, "t" ) ) == TEAM_SPECTATOR ) { + continue; + } + // + if ( BotSameTeam( bs, i ) ) { + numplayers++; + } + } + return numplayers; +} + +/* +================== +BotClientTravelTimeToGoal +================== +*/ +int BotClientTravelTimeToGoal( int client, bot_goal_t *goal ) { + playerState_t ps; + int areanum; + + BotAI_GetClientState( client, &ps ); + areanum = BotPointAreaNum( ps.origin ); + if ( !areanum ) { + return 1; + } + return trap_AAS_AreaTravelTimeToGoalArea( areanum, ps.origin, goal->areanum, TFL_DEFAULT ); +} + +/* +================== +BotSortTeamMatesByBaseTravelTime +================== +*/ +int BotSortTeamMatesByBaseTravelTime( bot_state_t *bs, int *teammates, int maxteammates ) { + + int i, j, k, numteammates, traveltime; + char buf[MAX_INFO_STRING]; + static int maxclients; + int traveltimes[MAX_CLIENTS]; + bot_goal_t *goal; + + if ( BotCTFTeam( bs ) == CTF_TEAM_RED ) { + goal = &ctf_redflag; + } else { goal = &ctf_blueflag;} + + if ( !maxclients ) { + maxclients = trap_Cvar_VariableIntegerValue( "sv_maxclients" ); + } + + numteammates = 0; + for ( i = 0; i < maxclients && i < MAX_CLIENTS; i++ ) { + trap_GetConfigstring( CS_PLAYERS + i, buf, sizeof( buf ) ); + //if no config string or no name + if ( !strlen( buf ) || !strlen( Info_ValueForKey( buf, "n" ) ) ) { + continue; + } + //skip spectators + if ( atoi( Info_ValueForKey( buf, "t" ) ) == TEAM_SPECTATOR ) { + continue; + } + // + if ( BotSameTeam( bs, i ) ) { + // + traveltime = BotClientTravelTimeToGoal( i, goal ); + // + for ( j = 0; j < numteammates; j++ ) { + if ( traveltime < traveltimes[j] ) { + for ( k = numteammates; k > j; k-- ) { + traveltimes[k] = traveltimes[k - 1]; + teammates[k] = teammates[k - 1]; + } + traveltimes[j] = traveltime; + teammates[j] = i; + break; + } + } + if ( j >= numteammates ) { + traveltimes[j] = traveltime; + teammates[j] = i; + } + numteammates++; + if ( numteammates >= maxteammates ) { + break; + } + } + } + return numteammates; +} + +/* +================== +BotSayTeamOrders +================== +*/ +void BotSayTeamOrder( bot_state_t *bs, int toclient ) { + char teamchat[MAX_MESSAGE_SIZE]; + char buf[MAX_MESSAGE_SIZE]; + char name[MAX_NETNAME]; + + //if the bot is talking to itself + if ( bs->client == toclient ) { + //don't show the message just put it in the console message queue + trap_BotGetChatMessage( bs->cs, buf, sizeof( buf ) ); + ClientName( bs->client, name, sizeof( name ) ); + Com_sprintf( teamchat, sizeof( teamchat ), "(%s): %s", name, buf ); + trap_BotQueueConsoleMessage( bs->cs, CMS_CHAT, teamchat ); + } else { + trap_BotEnterChat( bs->cs, bs->client, CHAT_TEAM ); + } +} + +/* +================== +BotCTFOrders +================== +*/ +void BotCTFOrders_BothFlagsNotAtBase( bot_state_t *bs ) { + int numteammates, defenders, attackers, i, other; + int teammates[MAX_CLIENTS]; + char name[MAX_NETNAME], carriername[MAX_NETNAME]; + + numteammates = BotSortTeamMatesByBaseTravelTime( bs, teammates, sizeof( teammates ) ); + //different orders based on the number of team mates + switch ( bs->numteammates ) { + case 1: break; + case 2: + { + //tell the one not carrying the flag to attack the enemy base + if ( teammates[0] != bs->flagcarrier ) { + other = teammates[0]; + } else { other = teammates[1];} + ClientName( other, name, sizeof( name ) ); + BotAI_BotInitialChat( bs, "cmd_getflag", name, NULL ); + BotSayTeamOrder( bs, other ); + break; + } + case 3: + { + //tell the one closest to the base not carrying the flag to accompany the flag carrier + if ( teammates[0] != bs->flagcarrier ) { + other = teammates[0]; + } else { other = teammates[1];} + ClientName( other, name, sizeof( name ) ); + ClientName( bs->flagcarrier, carriername, sizeof( carriername ) ); + if ( bs->flagcarrier == bs->client ) { + BotAI_BotInitialChat( bs, "cmd_accompanyme", name, NULL ); + } else { + BotAI_BotInitialChat( bs, "cmd_accompany", name, carriername, NULL ); + } + BotSayTeamOrder( bs, other ); + //tell the one furthest from the the base not carrying the flag to get the enemy flag + if ( teammates[2] != bs->flagcarrier ) { + other = teammates[2]; + } else { other = teammates[1];} + ClientName( other, name, sizeof( name ) ); + BotAI_BotInitialChat( bs, "cmd_getflag", name, NULL ); + BotSayTeamOrder( bs, other ); + break; + } + default: + { + defenders = (int) ( float ) numteammates * 0.4 + 0.5; + attackers = (int) ( float ) numteammates * 0.5 + 0.5; + ClientName( bs->flagcarrier, carriername, sizeof( carriername ) ); + for ( i = 0; i < defenders; i++ ) { + // + if ( teammates[i] == bs->flagcarrier ) { + continue; + } + // + ClientName( teammates[i], name, sizeof( name ) ); + if ( bs->flagcarrier == bs->client ) { + BotAI_BotInitialChat( bs, "cmd_accompanyme", name, NULL ); + } else { + BotAI_BotInitialChat( bs, "cmd_accompany", name, carriername, NULL ); + } + BotSayTeamOrder( bs, teammates[i] ); + } + for ( i = 0; i < attackers; i++ ) { + // + if ( teammates[numteammates - i - 1] == bs->flagcarrier ) { + continue; + } + // + ClientName( teammates[numteammates - i - 1], name, sizeof( name ) ); + BotAI_BotInitialChat( bs, "cmd_getflag", name, NULL ); + BotSayTeamOrder( bs, teammates[numteammates - i - 1] ); + } + // + break; + } + } +} + +/* +================== +BotCTFOrders +================== +*/ +void BotCTFOrders_FlagNotAtBase( bot_state_t *bs ) { + int numteammates, defenders, attackers, i; + int teammates[MAX_CLIENTS]; + char name[MAX_NETNAME]; + + numteammates = BotSortTeamMatesByBaseTravelTime( bs, teammates, sizeof( teammates ) ); + //different orders based on the number of team mates + switch ( bs->numteammates ) { + case 1: break; + case 2: + { + //the one closest to the base will defend the base + ClientName( teammates[0], name, sizeof( name ) ); + BotAI_BotInitialChat( bs, "cmd_defendbase", name, NULL ); + BotSayTeamOrder( bs, teammates[0] ); + //the other will get the flag + ClientName( teammates[1], name, sizeof( name ) ); + BotAI_BotInitialChat( bs, "cmd_getflag", name, NULL ); + BotSayTeamOrder( bs, teammates[1] ); + break; + } + case 3: + { + //the one closest to the base will defend the base + ClientName( teammates[0], name, sizeof( name ) ); + BotAI_BotInitialChat( bs, "cmd_defendbase", name, NULL ); + BotSayTeamOrder( bs, teammates[0] ); + //the other two get the flag + ClientName( teammates[1], name, sizeof( name ) ); + BotAI_BotInitialChat( bs, "cmd_getflag", name, NULL ); + BotSayTeamOrder( bs, teammates[1] ); + // + ClientName( teammates[2], name, sizeof( name ) ); + BotAI_BotInitialChat( bs, "cmd_getflag", name, NULL ); + BotSayTeamOrder( bs, teammates[2] ); + break; + } + default: + { + defenders = (int) ( float ) numteammates * 0.3 + 0.5; + attackers = (int) ( float ) numteammates * 0.5 + 0.5; + for ( i = 0; i < defenders; i++ ) { + // + ClientName( teammates[i], name, sizeof( name ) ); + BotAI_BotInitialChat( bs, "cmd_defendbase", name, NULL ); + BotSayTeamOrder( bs, teammates[i] ); + } + for ( i = 0; i < attackers; i++ ) { + // + ClientName( teammates[numteammates - i - 1], name, sizeof( name ) ); + BotAI_BotInitialChat( bs, "cmd_getflag", name, NULL ); + BotSayTeamOrder( bs, teammates[numteammates - i - 1] ); + } + // + break; + } + } +} + +/* +================== +BotCTFOrders +================== +*/ +void BotCTFOrders_EnemyFlagNotAtBase( bot_state_t *bs ) { + int numteammates, defenders, attackers, i, other; + int teammates[MAX_CLIENTS]; + char name[MAX_NETNAME], carriername[MAX_NETNAME]; + + numteammates = BotSortTeamMatesByBaseTravelTime( bs, teammates, sizeof( teammates ) ); + //different orders based on the number of team mates + switch ( numteammates ) { + case 1: break; + case 2: + { + //tell the one not carrying the flag to defend the base + if ( teammates[0] == bs->flagcarrier ) { + other = teammates[1]; + } else { other = teammates[0];} + ClientName( other, name, sizeof( name ) ); + BotAI_BotInitialChat( bs, "cmd_defendbase", name, NULL ); + BotSayTeamOrder( bs, other ); + break; + } + case 3: + { + //tell the one closest to the base not carrying the flag to defend the base + if ( teammates[0] != bs->flagcarrier ) { + other = teammates[0]; + } else { other = teammates[1];} + ClientName( other, name, sizeof( name ) ); + BotAI_BotInitialChat( bs, "cmd_defendbase", name, NULL ); + BotSayTeamOrder( bs, other ); + //tell the one furthest from the base not carrying the flag to accompany the flag carrier + if ( teammates[2] != bs->flagcarrier ) { + other = teammates[2]; + } else { other = teammates[1];} + ClientName( other, name, sizeof( name ) ); + ClientName( bs->flagcarrier, carriername, sizeof( carriername ) ); + if ( bs->flagcarrier == bs->client ) { + BotAI_BotInitialChat( bs, "cmd_accompanyme", name, NULL ); + } else { + BotAI_BotInitialChat( bs, "cmd_accompany", name, carriername, NULL ); + } + BotSayTeamOrder( bs, other ); + break; + } + default: + { + //40% will defend the base + defenders = (int) ( float ) numteammates * 0.4 + 0.5; + //50% accompanies the flag carrier + attackers = (int) ( float ) numteammates * 0.5 + 0.5; + for ( i = 0; i < defenders; i++ ) { + // + if ( teammates[i] == bs->flagcarrier ) { + continue; + } + ClientName( teammates[i], name, sizeof( name ) ); + BotAI_BotInitialChat( bs, "cmd_defendbase", name, NULL ); + BotSayTeamOrder( bs, teammates[i] ); + } + ClientName( bs->flagcarrier, carriername, sizeof( carriername ) ); + for ( i = 0; i < attackers; i++ ) { + // + if ( teammates[numteammates - i - 1] == bs->flagcarrier ) { + continue; + } + // + ClientName( teammates[numteammates - i - 1], name, sizeof( name ) ); + if ( bs->flagcarrier == bs->client ) { + BotAI_BotInitialChat( bs, "cmd_accompanyme", name, NULL ); + } else { + BotAI_BotInitialChat( bs, "cmd_accompany", name, carriername, NULL ); + } + BotSayTeamOrder( bs, teammates[numteammates - i - 1] ); + } + // + break; + } + } +} + + +/* +================== +BotCTFOrders +================== +*/ +void BotCTFOrders_BothFlagsAtBase( bot_state_t *bs ) { + int numteammates, defenders, attackers, i; + int teammates[MAX_CLIENTS]; + char name[MAX_NETNAME]; +// char buf[MAX_MESSAGE_SIZE]; + + numteammates = BotSortTeamMatesByBaseTravelTime( bs, teammates, sizeof( teammates ) ); + //different orders based on the number of team mates + switch ( numteammates ) { + case 1: break; + case 2: + { + //the one closest to the base will defend the base + ClientName( teammates[0], name, sizeof( name ) ); + BotAI_BotInitialChat( bs, "cmd_defendbase", name, NULL ); + BotSayTeamOrder( bs, teammates[0] ); + //the other will get the flag + ClientName( teammates[1], name, sizeof( name ) ); + BotAI_BotInitialChat( bs, "cmd_getflag", name, NULL ); + BotSayTeamOrder( bs, teammates[1] ); + break; + } + case 3: + { + //the one closest to the base will defend the base + ClientName( teammates[0], name, sizeof( name ) ); + BotAI_BotInitialChat( bs, "cmd_defendbase", name, NULL ); + BotSayTeamOrder( bs, teammates[0] ); + //the second one closest to the base will defend the base + ClientName( teammates[1], name, sizeof( name ) ); + BotAI_BotInitialChat( bs, "cmd_defendbase", name, NULL ); + BotSayTeamOrder( bs, teammates[1] ); + //the other will get the flag + ClientName( teammates[2], name, sizeof( name ) ); + BotAI_BotInitialChat( bs, "cmd_getflag", name, NULL ); + BotSayTeamOrder( bs, teammates[2] ); + break; + } + default: + { + defenders = (int) ( float ) numteammates * 0.5 + 0.5; + attackers = (int) ( float ) numteammates * 0.3 + 0.5; + for ( i = 0; i < defenders; i++ ) { + // + ClientName( teammates[i], name, sizeof( name ) ); + BotAI_BotInitialChat( bs, "cmd_defendbase", name, NULL ); + BotSayTeamOrder( bs, teammates[i] ); + } + for ( i = 0; i < attackers; i++ ) { + // + ClientName( teammates[numteammates - i - 1], name, sizeof( name ) ); + BotAI_BotInitialChat( bs, "cmd_getflag", name, NULL ); + BotSayTeamOrder( bs, teammates[numteammates - i - 1] ); + } + // + break; + } + } +} + + +/* +================== +BotTeamOrders +================== +*/ +void BotTeamOrders( bot_state_t *bs ) { + //no teamplay orders at this time +} + + +/* +================== +BotTeamAI +================== +*/ +void BotTeamAI( bot_state_t *bs ) { + int numteammates, flagstatus; + char netname[MAX_NETNAME]; + + // + if ( gametype != GT_TEAM && gametype != GT_CTF ) { + return; + } + //make sure we've got a valid team leader + if ( !BotValidTeamLeader( bs ) ) { + // + if ( !bs->askteamleader_time && !bs->becometeamleader_time ) { + if ( bs->entergame_time + 10 > trap_AAS_Time() ) { + bs->askteamleader_time = trap_AAS_Time() + 5 + random() * 10; + } else { + bs->becometeamleader_time = trap_AAS_Time() + 5 + random() * 10; + } + } + if ( bs->askteamleader_time && bs->askteamleader_time < trap_AAS_Time() ) { + //if asked for a team leader and no repsonse + BotAI_BotInitialChat( bs, "whoisteamleader", NULL ); + trap_BotEnterChat( bs->cs, bs->client, CHAT_TEAM ); + bs->askteamleader_time = 0; + bs->becometeamleader_time = trap_AAS_Time() + 15 + random() * 10; + } + if ( bs->becometeamleader_time && bs->becometeamleader_time < trap_AAS_Time() ) { + BotAI_BotInitialChat( bs, "iamteamleader", NULL ); + trap_BotEnterChat( bs->cs, bs->client, CHAT_TEAM ); + ClientName( bs->client, netname, sizeof( netname ) ); + strncpy( bs->teamleader, netname, sizeof( bs->teamleader ) ); + bs->teamleader[sizeof( bs->teamleader )] = '\0'; + bs->becometeamleader_time = 0; + } + return; + } + bs->askteamleader_time = 0; + bs->becometeamleader_time = 0; + + //return if this bot is NOT the team leader + ClientName( bs->client, netname, sizeof( netname ) ); + if ( Q_stricmp( netname, bs->teamleader ) != 0 ) { + return; + } + // + //if the game starts OR a new player comes onto the team OR a player leaves the team + // + numteammates = BotNumTeamMates( bs ); + //give orders + switch ( gametype ) { + case GT_TEAM: + { + if ( bs->numteammates != numteammates || bs->forceorders ) { + bs->teamgiveorders_time = trap_AAS_Time(); + bs->numteammates = numteammates; + bs->forceorders = qfalse; + } + //if it's time to give orders + if ( bs->teamgiveorders_time < trap_AAS_Time() - 5 ) { + BotTeamOrders( bs ); + // + bs->teamgiveorders_time = 0; + } + break; + } + case GT_CTF: + { + // + if ( bs->numteammates != numteammates || bs->flagstatuschanged || bs->forceorders ) { + bs->teamgiveorders_time = trap_AAS_Time(); + bs->numteammates = numteammates; + bs->flagstatuschanged = qfalse; + bs->forceorders = qfalse; + } + //if it's time to give orders + if ( bs->teamgiveorders_time && bs->teamgiveorders_time < trap_AAS_Time() - 3 ) { + // + if ( BotCTFTeam( bs ) == CTF_TEAM_RED ) { + flagstatus = bs->redflagstatus * 2 + bs->blueflagstatus; + } else { flagstatus = bs->blueflagstatus * 2 + bs->redflagstatus;} + // + switch ( flagstatus ) { + case 0: BotCTFOrders_BothFlagsAtBase( bs ); break; + case 1: BotCTFOrders_EnemyFlagNotAtBase( bs ); break; + case 2: BotCTFOrders_FlagNotAtBase( bs ); break; + case 3: BotCTFOrders_BothFlagsNotAtBase( bs ); break; + } + // + bs->teamgiveorders_time = 0; + } + break; + } + } +} + + diff --git a/Projects/Android/jni/rtcw/src/botai/ai_team.h b/Projects/Android/jni/rtcw/src/botai/ai_team.h new file mode 100644 index 0000000..9c9047f --- /dev/null +++ b/Projects/Android/jni/rtcw/src/botai/ai_team.h @@ -0,0 +1,40 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +/***************************************************************************** + * name: ai_team.h + * + * desc: Quake3 bot AI + * + * + *****************************************************************************/ + +void BotTeamAI( bot_state_t *bs ); + + diff --git a/Projects/Android/jni/rtcw/src/botai/botai.h b/Projects/Android/jni/rtcw/src/botai/botai.h new file mode 100644 index 0000000..811e8f4 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/botai/botai.h @@ -0,0 +1,110 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +//=========================================================================== +// +// Name: botai.h +// Function: bot AI +// Programmer: Mr Elusive (MrElusive@idsoftware.com) +// Last update: 1999-08-18 +// Tab Size: 3 +//=========================================================================== + +//debug line colors +#define LINECOLOR_NONE -1 +#define LINECOLOR_RED 1 +#define LINECOLOR_GREEN 2 +#define LINECOLOR_BLUE 3 +#define LINECOLOR_YELLOW 4 +#define LINECOLOR_ORANGE 5 + +//Print types +#define PRT_MESSAGE 1 +#define PRT_WARNING 2 +#define PRT_ERROR 3 +#define PRT_FATAL 4 +#define PRT_EXIT 5 + +//console message types +#define CMS_NORMAL 0 +#define CMS_CHAT 1 + +//some maxs +#define MAX_NETNAME 36 +#define MAX_CLIENTSKINNAME 128 +#define MAX_FILEPATH 144 +#define MAX_CHARACTERNAME 144 + +#ifndef BSPTRACE + +//bsp_trace_t hit surface +typedef struct bsp_surface_s +{ + char name[16]; + int flags; + int value; +} bsp_surface_t; + +//remove the bsp_trace_s structure definition l8r on +//a trace is returned when a box is swept through the world +typedef struct bsp_trace_s +{ + qboolean allsolid; // if true, plane is not valid + qboolean startsolid; // if true, the initial point was in a solid area + float fraction; // time completed, 1.0 = didn't hit anything + vec3_t endpos; // final position + cplane_t plane; // surface normal at impact + float exp_dist; // expanded plane distance + int sidenum; // number of the brush side hit + bsp_surface_t surface; // the hit point surface + int contents; // contents on other side of surface hit + int ent; // number of entity hit +} bsp_trace_t; + +#define BSPTRACE +#endif // BSPTRACE + +// +// imported functions used for the BotAI +// + + +// from the server +/* +void trap_Cvar_Register( vmCvar_t *cvar, const char *var_name, const char *value, int flags ); +void trap_Cvar_Update( vmCvar_t *cvar ); +void trap_Cvar_Set( const char *var_name, const char *value ); +int trap_Cvar_VariableIntegerValue( const char *var_name ); +void trap_Cvar_VariableStringBuffer( const char *var_name, char *buffer, int bufsize ); +void trap_GetConfigstring( int num, char *buffer, int bufferSize ); +void trap_GetServerinfo( char *buffer, int bufferSize ); +int trap_PointContents( const vec3_t point, int passEntityNum ); +qboolean trap_InPVS( const vec3_t p1, const vec3_t p2 ); +int trap_BotAllocateClient( void ); +void trap_BotFreeClient( int clientNum ); +*/ diff --git a/Projects/Android/jni/rtcw/src/botai/chars.h b/Projects/Android/jni/rtcw/src/botai/chars.h new file mode 100644 index 0000000..258adb5 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/botai/chars.h @@ -0,0 +1,150 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +//=========================================================================== +// +// Name: chars.h +// Function: bot characteristics +// Programmer: Mr Elusive (MrElusive@idsoftware.com) +// Last update: 1999-09-08 +// Tab Size: 4 (real tabs) +//=========================================================================== + + +//======================================================== +//======================================================== +//name +#define CHARACTERISTIC_NAME 0 //string +//gender of the bot +#define CHARACTERISTIC_GENDER 1 //string ("male", "female", "it") +//attack skill +// > 0.0 && < 0.2 = don't move +// > 0.3 && < 1.0 = aim at enemy during retreat +// > 0.0 && < 0.4 = only move forward/backward +// >= 0.4 && < 1.0 = circle strafing +// > 0.7 && < 1.0 = random strafe direction change +#define CHARACTERISTIC_ATTACK_SKILL 2 //float [0, 1] +//weapon weight file +#define CHARACTERISTIC_WEAPONWEIGHTS 3 //string +//view angle difference to angle change factor +#define CHARACTERISTIC_VIEW_FACTOR 4 //float <0, 1] +//maximum view angle change +#define CHARACTERISTIC_VIEW_MAXCHANGE 5 //float [1, 360] +//reaction time in seconds +#define CHARACTERISTIC_REACTIONTIME 6 //float [0, 5] +//accuracy when aiming +#define CHARACTERISTIC_AIM_ACCURACY 7 //float [0, 1] +//weapon specific aim accuracy +#define CHARACTERISTIC_AIM_ACCURACY_MACHINEGUN 8 //float [0, 1] +#define CHARACTERISTIC_AIM_ACCURACY_SHOTGUN 9 //float [0, 1] +#define CHARACTERISTIC_AIM_ACCURACY_ROCKETLAUNCHER 10 //float [0, 1] +#define CHARACTERISTIC_AIM_ACCURACY_GRENADELAUNCHER 11 //float [0, 1] +#define CHARACTERISTIC_AIM_ACCURACY_LIGHTNING 12 +#define CHARACTERISTIC_AIM_ACCURACY_SP5 13 //float [0, 1] +#define CHARACTERISTIC_AIM_ACCURACY_RAILGUN 14 +#define CHARACTERISTIC_AIM_ACCURACY_BFG10K 15 //float [0, 1] +//skill when aiming +// > 0.0 && < 0.9 = aim is affected by enemy movement +// > 0.4 && <= 0.8 = enemy linear leading +// > 0.8 && <= 1.0 = enemy exact movement leading +// > 0.5 && <= 1.0 = prediction shots when enemy is not visible +// > 0.6 && <= 1.0 = splash damage by shooting nearby geometry +#define CHARACTERISTIC_AIM_SKILL 16 //float [0, 1] +//weapon specific aim skill +#define CHARACTERISTIC_AIM_SKILL_ROCKETLAUNCHER 17 //float [0, 1] +#define CHARACTERISTIC_AIM_SKILL_GRENADELAUNCHER 18 //float [0, 1] +#define CHARACTERISTIC_AIM_SKILL_SP5 19 //float [0, 1] +#define CHARACTERISTIC_AIM_SKILL_BFG10K 20 //float [0, 1] +//======================================================== +//chat +//======================================================== +//file with chats +#define CHARACTERISTIC_CHAT_FILE 21 //string +//name of the chat character +#define CHARACTERISTIC_CHAT_NAME 22 //string +//characters per minute type speed +#define CHARACTERISTIC_CHAT_CPM 23 //integer [1, 4000] +//tendency to insult/praise +#define CHARACTERISTIC_CHAT_INSULT 24 //float [0, 1] +//tendency to chat misc +#define CHARACTERISTIC_CHAT_MISC 25 //float [0, 1] +//tendency to chat at start or end of level +#define CHARACTERISTIC_CHAT_STARTENDLEVEL 26 //float [0, 1] +//tendency to chat entering or exiting the game +#define CHARACTERISTIC_CHAT_ENTEREXITGAME 27 //float [0, 1] +//tendency to chat when killed someone +#define CHARACTERISTIC_CHAT_KILL 28 //float [0, 1] +//tendency to chat when died +#define CHARACTERISTIC_CHAT_DEATH 29 //float [0, 1] +//tendency to chat when enemy suicides +#define CHARACTERISTIC_CHAT_ENEMYSUICIDE 30 //float [0, 1] +//tendency to chat when hit while talking +#define CHARACTERISTIC_CHAT_HITTALKING 31 //float [0, 1] +//tendency to chat when bot was hit but didn't dye +#define CHARACTERISTIC_CHAT_HITNODEATH 32 //float [0, 1] +//tendency to chat when bot hit the enemy but enemy didn't dye +#define CHARACTERISTIC_CHAT_HITNOKILL 33 //float [0, 1] +//tendency to randomly chat +#define CHARACTERISTIC_CHAT_RANDOM 34 //float [0, 1] +//tendency to reply +#define CHARACTERISTIC_CHAT_REPLY 35 //float [0, 1] +//======================================================== +//movement +//======================================================== +//tendency to crouch +#define CHARACTERISTIC_CROUCHER 36 //float [0, 1] +//tendency to jump +#define CHARACTERISTIC_JUMPER 37 //float [0, 1] +//tendency to walk +#define CHARACTERISTIC_WALKER 48 //float [0, 1] +//tendency to jump using a weapon +#define CHARACTERISTIC_WEAPONJUMPING 38 //float [0, 1] +//tendency to use the grapple hook when available +#define CHARACTERISTIC_GRAPPLE_USER 39 //float [0, 1] //use this!! +//======================================================== +//goal +//======================================================== +//item weight file +#define CHARACTERISTIC_ITEMWEIGHTS 40 //string +//the aggression of the bot +#define CHARACTERISTIC_AGGRESSION 41 //float [0, 1] +//the self preservation of the bot (rockets near walls etc.) +#define CHARACTERISTIC_SELFPRESERVATION 42 //float [0, 1] +//how likely the bot is to take revenge +#define CHARACTERISTIC_VENGEFULNESS 43 //float [0, 1] //use this!! +//tendency to camp +#define CHARACTERISTIC_CAMPER 44 //float [0, 1] +//======================================================== +//======================================================== +//tendency to get easy frags +#define CHARACTERISTIC_EASY_FRAGGER 45 //float [0, 1] +//how alert the bot is (view distance) +#define CHARACTERISTIC_ALERTNESS 46 //float [0, 1] +//how much the bot fires it's weapon +#define CHARACTERISTIC_FIRETHROTTLE 47 //float [0, 1] + diff --git a/Projects/Android/jni/rtcw/src/botai/inv.h b/Projects/Android/jni/rtcw/src/botai/inv.h new file mode 100644 index 0000000..b54e375 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/botai/inv.h @@ -0,0 +1,128 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +/* + * name: inv.h + * + * desc: + * +*/ + + +#define INVENTORY_NONE 0 +//armor +#define INVENTORY_ARMOR 1 +//weapons +#define INVENTORY_LUGER 4 +#define INVENTORY_MAUSER 5 +#define INVENTORY_MP40 6 +#define INVENTORY_SP5 7 +#define INVENTORY_ROCKETLAUNCHER 8 +#define INVENTORY_GRENADELAUNCHER 9 +#define INVENTORY_VENOM 10 +#define INVENTORY_FLAMETHROWER 11 +#define INVENTORY_CROSS 12 + +#define INVENTORY_GAUNTLET 13 + + +// please leave these open up to 27 (INVENTORY_9MM) (and double check defines when merging) +// the inventory max (MAX_ITEMS) is 256, so we aren't too concerned about running out of space + +//ammo +#define INVENTORY_9MM 27 +#define INVENTORY_792MM 28 +#define INVENTORY_SP5AMMO 29 +#define INVENTORY_ROCKETS 30 +#define INVENTORY_GRENADES 31 +#define INVENTORY_127MM 32 +#define INVENTORY_FUEL 33 +#define INVENTORY_CHARGES 34 + +// please leave these open up to 48 (INVENTORY_HEALTH) (and double check defines when merging) +// the inventory max (MAX_ITEMS) is 256, so we aren't too concerned about running out of space + +//powerups +#define INVENTORY_HEALTH 48 +#define INVENTORY_TELEPORTER 49 +#define INVENTORY_MEDKIT 50 +#define INVENTORY_QUAD 51 +#define INVENTORY_ENVIRONMENTSUIT 52 +#define INVENTORY_HASTE 53 +#define INVENTORY_INVISIBILITY 54 +#define INVENTORY_REGEN 55 +#define INVENTORY_FLIGHT 56 +#define INVENTORY_REDFLAG 57 +#define INVENTORY_BLUEFLAG 58 +//enemy stuff +#define ENEMY_HORIZONTAL_DIST 200 +#define ENEMY_HEIGHT 201 +#define NUM_VISIBLE_ENEMIES 202 +#define NUM_VISIBLE_TEAMMATES 203 + +//item numbers (make sure they are in sync with bg_itemlist in bg_misc.c) +#define MODELINDEX_ARMORSHARD 1 +#define MODELINDEX_ARMORCOMBAT 2 +#define MODELINDEX_ARMORBODY 3 +#define MODELINDEX_HEALTHSMALL 4 +#define MODELINDEX_HEALTH 5 +#define MODELINDEX_HEALTHLARGE 6 +#define MODELINDEX_HEALTHMEGA 7 + +#define MODELINDEX_GAUNTLET 8 +#define MODELINDEX_SHOTGUN 9 +#define MODELINDEX_MACHINEGUN 10 +#define MODELINDEX_GRENADELAUNCHER 11 +#define MODELINDEX_ROCKETLAUNCHER 12 +#define MODELINDEX_LIGHTNING 13 +#define MODELINDEX_RAILGUN 14 +#define MODELINDEX_SP5 15 +#define MODELINDEX_BFG10K 16 +#define MODELINDEX_GRAPPLINGHOOK 17 + +#define MODELINDEX_SHELLS 18 +#define MODELINDEX_BULLETS 19 +#define MODELINDEX_GRENADES 20 +#define MODELINDEX_CELLS 21 +#define MODELINDEX_LIGHTNINGAMMO 22 +#define MODELINDEX_ROCKETS 23 +#define MODELINDEX_SLUGS 24 +#define MODELINDEX_BFGAMMO 25 + +#define MODELINDEX_TELEPORTER 26 +#define MODELINDEX_MEDKIT 27 +#define MODELINDEX_QUAD 28 +#define MODELINDEX_ENVIRONMENTSUIT 29 +#define MODELINDEX_HASTE 30 +#define MODELINDEX_INVISIBILITY 31 +#define MODELINDEX_REGEN 32 +#define MODELINDEX_FLIGHT 33 +#define MODELINDEX_REDFLAG 34 +#define MODELINDEX_BLUEFLAG 35 + + diff --git a/Projects/Android/jni/rtcw/src/botai/match.h b/Projects/Android/jni/rtcw/src/botai/match.h new file mode 100644 index 0000000..5e3a79d --- /dev/null +++ b/Projects/Android/jni/rtcw/src/botai/match.h @@ -0,0 +1,134 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +//=========================================================================== +// +// Name: match.h +// Function: match template defines +// Programmer: Mr Elusive (MrElusive@idsoftware.com) +// Last update: 1999-10-01 +// Tab Size: 4 (real tabs) +// +//=========================================================================== + +//match template contexts +#define MTCONTEXT_ENTERGAME 2 +#define MTCONTEXT_INITIALTEAMCHAT 4 +#define MTCONTEXT_TIME 8 +#define MTCONTEXT_TEAMMATE 16 +#define MTCONTEXT_ADDRESSEE 32 +#define MTCONTEXT_PATROLKEYAREA 64 +#define MTCONTEXT_REPLYCHAT 128 +#define MTCONTEXT_CTF 256 + +//message types +#define MSG_ENTERGAME 2 //enter game message +#define MSG_HELP 3 //help someone +#define MSG_ACCOMPANY 4 //accompany someone +#define MSG_DEFENDKEYAREA 5 //defend a key area +#define MSG_RUSHBASE 6 //everyone rush to base +#define MSG_GETFLAG 7 //get the enemy flag +#define MSG_STARTTEAMLEADERSHIP 8 //someone wants to become the team leader +#define MSG_STOPTEAMLEADERSHIP 9 //someone wants to stop being the team leader +#define MSG_WHOISTEAMLAEDER 10 //who is the team leader +#define MSG_WAIT 11 //wait for someone +#define MSG_WHATAREYOUDOING 12 //what are you doing? +#define MSG_JOINSUBTEAM 13 //join a sub-team +#define MSG_LEAVESUBTEAM 14 //leave a sub-team +#define MSG_CREATENEWFORMATION 15 //create a new formation +#define MSG_FORMATIONPOSITION 16 //tell someone his/her position in a formation +#define MSG_FORMATIONSPACE 17 //set the formation intervening space +#define MSG_DOFORMATION 18 //form a known formation +#define MSG_DISMISS 19 //dismiss commanded team mates +#define MSG_CAMP 20 //camp somewhere +#define MSG_CHECKPOINT 21 //remember a check point +#define MSG_PATROL 22 //patrol between certain keypoints +#define MSG_LEADTHEWAY 23 //lead the way +#define MSG_GETITEM 24 //get an item +#define MSG_KILL 25 //kill someone +#define MSG_WHEREAREYOU 26 //where is someone +#define MSG_RETURNFLAG 27 //return the flag +#define MSG_WHATISMYCOMMAND 28 //ask the team leader what to do +#define MSG_WHICHTEAM 29 //ask which team a bot is in +// +#define MSG_ME 100 +#define MSG_EVERYONE 101 +#define MSG_MULTIPLENAMES 102 +#define MSG_NAME 103 +#define MSG_PATROLKEYAREA 104 +#define MSG_MINUTES 105 +#define MSG_SECONDS 106 +#define MSG_FOREVER 107 +// +#define MSG_CHATALL 200 +#define MSG_CHATTEAM 201 +// +#define MSG_CTF 300 //ctf message + +//command sub types +#define ST_SOMEWHERE 0 +#define ST_NEARITEM 1 +#define ST_ADDRESSED 2 +#define ST_METER 4 +#define ST_FEET 8 +#define ST_TIME 16 +#define ST_HERE 32 +#define ST_THERE 64 +#define ST_I 128 +#define ST_MORE 256 +#define ST_BACK 512 +#define ST_REVERSE 1024 +#define ST_SOMEONE 2048 +#define ST_GOTFLAG 4096 +#define ST_CAPTUREDFLAG 8192 +#define ST_RETURNEDFLAG 16384 +#define ST_TEAM 32768 + + +//word replacement variables +#define THE_ENEMY 7 +#define THE_TEAM 7 +//team message variables +#define NETNAME 0 +#define PLACE 1 +#define FLAG 1 +#define MESSAGE 2 +#define ADDRESSEE 2 +#define ITEM 3 +#define TEAMMATE 4 +#define TEAMNAME 4 +#define ENEMY 4 +#define KEYAREA 5 +#define FORMATION 5 +#define POSITION 5 +#define NUMBER 5 +#define TIME 6 +#define NAME 6 +#define MORE 6 + + diff --git a/Projects/Android/jni/rtcw/src/botai/syn.h b/Projects/Android/jni/rtcw/src/botai/syn.h new file mode 100644 index 0000000..4b85612 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/botai/syn.h @@ -0,0 +1,46 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +//=========================================================================== +// +// Name: syn.h +// Function: synonyms +// Programmer: Mr Elusive (MrElusive@idsoftware.com) +// Last update: 1999-09-08 +// Tab Size: 4 (real tabs) +// Notes: - +//=========================================================================== + +#define CONTEXT_ALL 0xFFFFFFFF +#define CONTEXT_NORMAL 1 +#define CONTEXT_NEARBYITEM 2 +#define CONTEXT_CTFREDTEAM 4 +#define CONTEXT_CTFBLUETEAM 8 +#define CONTEXT_REPLY 16 + +#define CONTEXT_NAMES 1024 diff --git a/Projects/Android/jni/rtcw/src/botlib/aasfile.h b/Projects/Android/jni/rtcw/src/botlib/aasfile.h new file mode 100644 index 0000000..5ea0659 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/botlib/aasfile.h @@ -0,0 +1,276 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + + +//NOTE: int = default signed +// default long + +#define AASID ( ( 'S' << 24 ) + ( 'A' << 16 ) + ( 'A' << 8 ) + 'E' ) +#define AASVERSION 8 + +//presence types +#define PRESENCE_NONE 1 +#define PRESENCE_NORMAL 2 +#define PRESENCE_CROUCH 4 + +//travel types +#define MAX_TRAVELTYPES 32 +#define TRAVEL_INVALID 1 //temporary not possible +#define TRAVEL_WALK 2 //walking +#define TRAVEL_CROUCH 3 //crouching +#define TRAVEL_BARRIERJUMP 4 //jumping onto a barrier +#define TRAVEL_JUMP 5 //jumping +#define TRAVEL_LADDER 6 //climbing a ladder +#define TRAVEL_WALKOFFLEDGE 7 //walking of a ledge +#define TRAVEL_SWIM 8 //swimming +#define TRAVEL_WATERJUMP 9 //jump out of the water +#define TRAVEL_TELEPORT 10 //teleportation +#define TRAVEL_ELEVATOR 11 //travel by elevator +#define TRAVEL_ROCKETJUMP 12 //rocket jumping required for travel +#define TRAVEL_BFGJUMP 13 //bfg jumping required for travel +#define TRAVEL_GRAPPLEHOOK 14 //grappling hook required for travel +#define TRAVEL_DOUBLEJUMP 15 //double jump +#define TRAVEL_RAMPJUMP 16 //ramp jump +#define TRAVEL_STRAFEJUMP 17 //strafe jump +#define TRAVEL_JUMPPAD 18 //jump pad +#define TRAVEL_FUNCBOB 19 //func bob + +//additional travel flags +#define TRAVELTYPE_MASK 0xFFFFFF +#define TRAVELFLAG_NOTTEAM1 ( 1 << 24 ) +#define TRAVELFLAG_NOTTEAM2 ( 2 << 24 ) + +//face flags +#define FACE_SOLID 1 //just solid at the other side +#define FACE_LADDER 2 //ladder +#define FACE_GROUND 4 //standing on ground when in this face +#define FACE_GAP 8 //gap in the ground +#define FACE_LIQUID 16 +#define FACE_LIQUIDSURFACE 32 + +//area contents +#define AREACONTENTS_WATER 1 +#define AREACONTENTS_LAVA 2 +#define AREACONTENTS_SLIME 4 +#define AREACONTENTS_CLUSTERPORTAL 8 +#define AREACONTENTS_TELEPORTAL 16 +#define AREACONTENTS_ROUTEPORTAL 32 +#define AREACONTENTS_TELEPORTER 64 +#define AREACONTENTS_JUMPPAD 128 +#define AREACONTENTS_DONOTENTER 256 +#define AREACONTENTS_VIEWPORTAL 512 +// Rafael - nopass +#define AREACONTENTS_DONOTENTER_LARGE 1024 +#define AREACONTENTS_MOVER 2048 + +//number of model of the mover inside this area +#define AREACONTENTS_MODELNUMSHIFT 24 +#define AREACONTENTS_MAXMODELNUM 0xFF +#define AREACONTENTS_MODELNUM ( AREACONTENTS_MAXMODELNUM << AREACONTENTS_MODELNUMSHIFT ) + +//area flags +#define AREA_GROUNDED 1 //bot can stand on the ground +#define AREA_LADDER 2 //area contains one or more ladder faces +#define AREA_LIQUID 4 //area contains a liquid +// Ridah +#define AREA_DISABLED 8 +#define AREA_USEFORROUTING 1024 + +//aas file header lumps +#define AAS_LUMPS 14 +#define AASLUMP_BBOXES 0 +#define AASLUMP_VERTEXES 1 +#define AASLUMP_PLANES 2 +#define AASLUMP_EDGES 3 +#define AASLUMP_EDGEINDEX 4 +#define AASLUMP_FACES 5 +#define AASLUMP_FACEINDEX 6 +#define AASLUMP_AREAS 7 +#define AASLUMP_AREASETTINGS 8 +#define AASLUMP_REACHABILITY 9 +#define AASLUMP_NODES 10 +#define AASLUMP_PORTALS 11 +#define AASLUMP_PORTALINDEX 12 +#define AASLUMP_CLUSTERS 13 + +//========== bounding box ========= + +//bounding box +typedef struct aas_bbox_s +{ + int presencetype; + int flags; + vec3_t mins, maxs; +} aas_bbox_t; + +//============ settings =========== + +//reachability to another area +typedef struct aas_reachability_s +{ + int areanum; //number of the reachable area + int facenum; //number of the face towards the other area + int edgenum; //number of the edge towards the other area + vec3_t start; //start point of inter area movement + vec3_t end; //end point of inter area movement + int traveltype; //type of travel required to get to the area + unsigned short int traveltime; //travel time of the inter area movement +} aas_reachability_t; + +//area settings +typedef struct aas_areasettings_s +{ + //could also add all kind of statistic fields + int contents; //contents of the convex area + int areaflags; //several area flags + int presencetype; //how a bot can be present in this convex area + int cluster; //cluster the area belongs to, if negative it's a portal + int clusterareanum; //number of the area in the cluster + int numreachableareas; //number of reachable areas from this one + int firstreachablearea; //first reachable area in the reachable area index + // Ridah, add a ground steepness stat, so we can avoid terrain when we can take a close-by flat route + float groundsteepness; // 0 = flat, 1 = steep +} aas_areasettings_t; + +//cluster portal +typedef struct aas_portal_s +{ + int areanum; //area that is the actual portal + int frontcluster; //cluster at front of portal + int backcluster; //cluster at back of portal + int clusterareanum[2]; //number of the area in the front and back cluster +} aas_portal_t; + +//cluster portal index +typedef int aas_portalindex_t; + +//cluster +typedef struct aas_cluster_s +{ + int numareas; //number of areas in the cluster + int numreachabilityareas; //number of areas with reachabilities + int numportals; //number of cluster portals + int firstportal; //first cluster portal in the index +} aas_cluster_t; + +//============ 3d definition ============ + +typedef vec3_t aas_vertex_t; + +//just a plane in the third dimension +typedef struct aas_plane_s +{ + vec3_t normal; //normal vector of the plane + float dist; //distance of the plane (normal vector * distance = point in plane) + int type; +} aas_plane_t; + +//edge +typedef struct aas_edge_s +{ + int v[2]; //numbers of the vertexes of this edge +} aas_edge_t; + +//edge index, negative if vertexes are reversed +typedef int aas_edgeindex_t; + +//a face bounds a convex area, often it will also seperate two convex areas +typedef struct aas_face_s +{ + int planenum; //number of the plane this face is in + int faceflags; //face flags (no use to create face settings for just this field) + int numedges; //number of edges in the boundary of the face + int firstedge; //first edge in the edge index + int frontarea; //convex area at the front of this face + int backarea; //convex area at the back of this face +} aas_face_t; + +//face index, stores a negative index if backside of face +typedef int aas_faceindex_t; + +//convex area with a boundary of faces +typedef struct aas_area_s +{ + int areanum; //number of this area + //3d definition + int numfaces; //number of faces used for the boundary of the convex area + int firstface; //first face in the face index used for the boundary of the convex area + vec3_t mins; //mins of the convex area + vec3_t maxs; //maxs of the convex area + vec3_t center; //'center' of the convex area +} aas_area_t; + +//nodes of the bsp tree +typedef struct aas_node_s +{ + int planenum; + int children[2]; //child nodes of this node, or convex areas as leaves when negative + //when a child is zero it's a solid leaf +} aas_node_t; + +//=========== aas file =============== + +//header lump +typedef struct +{ + int fileofs; + int filelen; +} aas_lump_t; + +//aas file header +typedef struct aas_header_s +{ + int ident; + int version; + int bspchecksum; + //data entries + aas_lump_t lumps[AAS_LUMPS]; +} aas_header_t; + + +//====== additional information ====== +/* + +- when a node child is a solid leaf the node child number is zero +- two adjacent areas (sharing a plane at opposite sides) share a face + this face is a portal between the areas +- when an area uses a face from the faceindex with a positive index + then the face plane normal points into the area +- the face edges are stored counter clockwise using the edgeindex +- two adjacent convex areas (sharing a face) only share One face + this is a simple result of the areas being convex +- the convex areas can't have a mixture of ground and gap faces + other mixtures of faces in one area are allowed +- areas with the AREACONTENTS_CLUSTERPORTAL in the settings have + cluster number zero +- edge zero is a dummy +- face zero is a dummy +- area zero is a dummy +- node zero is a dummy +*/ diff --git a/Projects/Android/jni/rtcw/src/botlib/be_aas.h b/Projects/Android/jni/rtcw/src/botlib/be_aas.h new file mode 100644 index 0000000..445983d --- /dev/null +++ b/Projects/Android/jni/rtcw/src/botlib/be_aas.h @@ -0,0 +1,193 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +/***************************************************************************** + * name: be_aas.h + * + * desc: Area Awareness System, stuff exported to the AI + * + * $Archive: /Wolf4/src/botlib/be_aas.h $ + * + *****************************************************************************/ + +#define MAX_AAS_WORLDS 2 // one for each bounding box type + +#ifndef MAX_STRINGFIELD +#define MAX_STRINGFIELD 80 +#endif + +//travel flags +#define TFL_INVALID 0x0000001 //traveling temporary not possible +#define TFL_WALK 0x0000002 //walking +#define TFL_CROUCH 0x0000004 //crouching +#define TFL_BARRIERJUMP 0x0000008 //jumping onto a barrier +#define TFL_JUMP 0x0000010 //jumping +#define TFL_LADDER 0x0000020 //climbing a ladder +#define TFL_WALKOFFLEDGE 0x0000080 //walking of a ledge +#define TFL_SWIM 0x0000100 //swimming +#define TFL_WATERJUMP 0x0000200 //jumping out of the water +#define TFL_TELEPORT 0x0000400 //teleporting +#define TFL_ELEVATOR 0x0000800 //elevator +#define TFL_ROCKETJUMP 0x0001000 //rocket jumping +#define TFL_BFGJUMP 0x0002000 //bfg jumping +#define TFL_GRAPPLEHOOK 0x0004000 //grappling hook +#define TFL_DOUBLEJUMP 0x0008000 //double jump +#define TFL_RAMPJUMP 0x0010000 //ramp jump +#define TFL_STRAFEJUMP 0x0020000 //strafe jump +#define TFL_JUMPPAD 0x0040000 //jump pad +#define TFL_AIR 0x0080000 //travel through air +#define TFL_WATER 0x0100000 //travel through water +#define TFL_SLIME 0x0200000 //travel through slime +#define TFL_LAVA 0x0400000 //travel through lava +#define TFL_DONOTENTER 0x0800000 //travel through donotenter area +#define TFL_FUNCBOB 0x1000000 //func bobbing +#define TFL_DONOTENTER_LARGE 0x2000000 //travel through donotenter area + +//default travel flags + +//----(SA) modified since slime is no longer deadly +#define TFL_DEFAULT TFL_WALK | TFL_CROUCH | TFL_BARRIERJUMP | \ + TFL_JUMP | TFL_LADDER | \ + TFL_WALKOFFLEDGE | TFL_SWIM | TFL_WATERJUMP | \ + TFL_TELEPORT | TFL_ELEVATOR | TFL_AIR | \ + TFL_WATER | TFL_SLIME | \ + TFL_JUMPPAD | TFL_FUNCBOB + +typedef enum +{ + SOLID_NOT, // no interaction with other objects + SOLID_TRIGGER, // only touch when inside, after moving + SOLID_BBOX, // touch on edge + SOLID_BSP // bsp clip, touch on edge +} solid_t; + +//a trace is returned when a box is swept through the AAS world +typedef struct aas_trace_s +{ + qboolean startsolid; // if true, the initial point was in a solid area + float fraction; // time completed, 1.0 = didn't hit anything + vec3_t endpos; // final position + int ent; // entity blocking the trace + int lastarea; // last area the trace was in (zero if none) + int area; // area blocking the trace (zero if none) + int planenum; // number of the plane that was hit +} aas_trace_t; + +/* Defined in botlib.h + +//bsp_trace_t hit surface +typedef struct bsp_surface_s +{ + char name[16]; + int flags; + int value; +} bsp_surface_t; + +//a trace is returned when a box is swept through the BSP world +typedef struct bsp_trace_s +{ + qboolean allsolid; // if true, plane is not valid + qboolean startsolid; // if true, the initial point was in a solid area + float fraction; // time completed, 1.0 = didn't hit anything + vec3_t endpos; // final position + cplane_t plane; // surface normal at impact + float exp_dist; // expanded plane distance + int sidenum; // number of the brush side hit + bsp_surface_t surface; // hit surface + int contents; // contents on other side of surface hit + int ent; // number of entity hit +} bsp_trace_t; +// +*/ + +//entity info +typedef struct aas_entityinfo_s +{ + int valid; // true if updated this frame + int type; // entity type + int flags; // entity flags + float ltime; // local time + float update_time; // time between last and current update + int number; // number of the entity + vec3_t origin; // origin of the entity + vec3_t angles; // angles of the model + vec3_t old_origin; // for lerping + vec3_t lastvisorigin; // last visible origin + vec3_t mins; // bounding box minimums + vec3_t maxs; // bounding box maximums + int groundent; // ground entity + int solid; // solid type + int modelindex; // model used + int modelindex2; // weapons, CTF flags, etc + int frame; // model frame number + int event; // impulse events -- muzzle flashes, footsteps, etc + int eventParm; // even parameter + int powerups; // bit flags + int weapon; // determines weapon and flash model, etc + int legsAnim; // mask off ANIM_TOGGLEBIT + int torsoAnim; // mask off ANIM_TOGGLEBIT +// int weapAnim; // mask off ANIM_TOGGLEBIT //----(SA) added +//----(SA) didn't want to comment in as I wasn't sure of any implications of changing this structure. +} aas_entityinfo_t; + + +//client movement prediction stop events, stop as soon as: +#define SE_NONE 0 +#define SE_HITGROUND 1 // the ground is hit +#define SE_LEAVEGROUND 2 // there's no ground +#define SE_ENTERWATER 4 // water is entered +#define SE_ENTERSLIME 8 // slime is entered +#define SE_ENTERLAVA 16 // lava is entered +#define SE_HITGROUNDDAMAGE 32 // the ground is hit with damage +#define SE_GAP 64 // there's a gap +#define SE_TOUCHJUMPPAD 128 // touching a jump pad area +#define SE_TOUCHTELEPORTER 256 // touching teleporter +#define SE_ENTERAREA 512 // the given stoparea is entered +#define SE_HITGROUNDAREA 1024 // a ground face in the area is hit + +typedef struct aas_clientmove_s +{ + vec3_t endpos; //position at the end of movement prediction + vec3_t velocity; //velocity at the end of movement prediction + aas_trace_t trace; //last trace + int presencetype; //presence type at end of movement prediction + int stopevent; //event that made the prediction stop + float endcontents; //contents at the end of movement prediction + float time; //time predicted ahead + int frames; //number of frames predicted ahead +} aas_clientmove_t; + +typedef struct aas_altroutegoal_s +{ + vec3_t origin; + int areanum; + unsigned short starttraveltime; + unsigned short goaltraveltime; + unsigned short extratraveltime; +} aas_altroutegoal_t; diff --git a/Projects/Android/jni/rtcw/src/botlib/be_aas_bsp.h b/Projects/Android/jni/rtcw/src/botlib/be_aas_bsp.h new file mode 100644 index 0000000..e3bcfb0 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/botlib/be_aas_bsp.h @@ -0,0 +1,96 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +/***************************************************************************** + * name: be_aas_bsp.h + * + * desc: AAS + * + * + *****************************************************************************/ + +#ifdef AASINTERN +//loads the given BSP file +int AAS_LoadBSPFile( void ); +//dump the loaded BSP data +void AAS_DumpBSPData( void ); +//unlink the given entity from the bsp tree leaves +void AAS_UnlinkFromBSPLeaves( bsp_link_t *leaves ); +//link the given entity to the bsp tree leaves of the given model +bsp_link_t *AAS_BSPLinkEntity( vec3_t absmins, + vec3_t absmaxs, + int entnum, + int modelnum ); + +//calculates collision with given entity +qboolean AAS_EntityCollision( int entnum, + vec3_t start, + vec3_t boxmins, + vec3_t boxmaxs, + vec3_t end, + int contentmask, + bsp_trace_t *trace ); +//for debugging +void AAS_PrintFreeBSPLinks( char *str ); +// + +#endif //AASINTERN + +#define MAX_EPAIRKEY 128 + +//trace through the world +bsp_trace_t AAS_Trace( vec3_t start, + vec3_t mins, + vec3_t maxs, + vec3_t end, + int passent, + int contentmask ); +//returns the contents at the given point +int AAS_PointContents( vec3_t point ); +//returns true when p2 is in the PVS of p1 +qboolean AAS_inPVS( vec3_t p1, vec3_t p2 ); +//returns true when p2 is in the PHS of p1 +qboolean AAS_inPHS( vec3_t p1, vec3_t p2 ); +//returns true if the given areas are connected +qboolean AAS_AreasConnected( int area1, int area2 ); +//creates a list with entities totally or partly within the given box +int AAS_BoxEntities( vec3_t absmins, vec3_t absmaxs, int *list, int maxcount ); +//gets the mins, maxs and origin of a BSP model +void AAS_BSPModelMinsMaxsOrigin( int modelnum, vec3_t angles, vec3_t mins, vec3_t maxs, vec3_t origin ); +//handle to the next bsp entity +int AAS_NextBSPEntity( int ent ); +//return the value of the BSP epair key +int AAS_ValueForBSPEpairKey( int ent, char *key, char *value, int size ); +//get a vector for the BSP epair key +int AAS_VectorForBSPEpairKey( int ent, char *key, vec3_t v ); +//get a float for the BSP epair key +int AAS_FloatForBSPEpairKey( int ent, char *key, float *value ); +//get an integer for the BSP epair key +int AAS_IntForBSPEpairKey( int ent, char *key, int *value ); + diff --git a/Projects/Android/jni/rtcw/src/botlib/be_aas_bspq3.c b/Projects/Android/jni/rtcw/src/botlib/be_aas_bspq3.c new file mode 100644 index 0000000..1f54c15 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/botlib/be_aas_bspq3.c @@ -0,0 +1,525 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +/***************************************************************************** + * name: be_aas_bspq3.c + * + * desc: BSP, Environment Sampling + * + * + *****************************************************************************/ + +#include "../game/q_shared.h" +#include "l_memory.h" +#include "l_script.h" +#include "l_precomp.h" +#include "l_struct.h" +#include "aasfile.h" +#include "../game/botlib.h" +#include "../game/be_aas.h" +#include "be_aas_funcs.h" +#include "be_aas_def.h" + +extern botlib_import_t botimport; + +//#define TRACE_DEBUG + +#define ON_EPSILON 0.005 +//#define DEG2RAD( a ) (( a * M_PI ) / 180.0F) + +#define MAX_BSPENTITIES 2048 + +typedef struct rgb_s +{ + int red; + int green; + int blue; +} rgb_t; + +//bsp entity epair +typedef struct bsp_epair_s +{ + char *key; + char *value; + struct bsp_epair_s *next; +} bsp_epair_t; + +//bsp data entity +typedef struct bsp_entity_s +{ + bsp_epair_t *epairs; +} bsp_entity_t; + +//id Sofware BSP data +typedef struct bsp_s +{ + //true when bsp file is loaded + int loaded; + //entity data + int entdatasize; + char *dentdata; + //bsp entities + int numentities; + bsp_entity_t entities[MAX_BSPENTITIES]; + //memory used for strings and epairs + byte *ebuffer; +} bsp_t; + +//global bsp +bsp_t bspworld; + + +#ifdef BSP_DEBUG +typedef struct cname_s +{ + int value; + char *name; +} cname_t; + +cname_t contentnames[] = +{ + {CONTENTS_SOLID,"CONTENTS_SOLID"}, + {CONTENTS_WINDOW,"CONTENTS_WINDOW"}, + {CONTENTS_AUX,"CONTENTS_AUX"}, + {CONTENTS_LAVA,"CONTENTS_LAVA"}, + {CONTENTS_SLIME,"CONTENTS_SLIME"}, + {CONTENTS_WATER,"CONTENTS_WATER"}, + {CONTENTS_MIST,"CONTENTS_MIST"}, + {LAST_VISIBLE_CONTENTS,"LAST_VISIBLE_CONTENTS"}, + + {CONTENTS_AREAPORTAL,"CONTENTS_AREAPORTAL"}, + {CONTENTS_PLAYERCLIP,"CONTENTS_PLAYERCLIP"}, + {CONTENTS_MONSTERCLIP,"CONTENTS_MONSTERCLIP"}, + {CONTENTS_CURRENT_0,"CONTENTS_CURRENT_0"}, + {CONTENTS_CURRENT_90,"CONTENTS_CURRENT_90"}, + {CONTENTS_CURRENT_180,"CONTENTS_CURRENT_180"}, + {CONTENTS_CURRENT_270,"CONTENTS_CURRENT_270"}, + {CONTENTS_CURRENT_UP,"CONTENTS_CURRENT_UP"}, + {CONTENTS_CURRENT_DOWN,"CONTENTS_CURRENT_DOWN"}, + {CONTENTS_ORIGIN,"CONTENTS_ORIGIN"}, + {CONTENTS_MONSTER,"CONTENTS_MONSTER"}, + {CONTENTS_DEADMONSTER,"CONTENTS_DEADMONSTER"}, + {CONTENTS_DETAIL,"CONTENTS_DETAIL"}, + {CONTENTS_TRANSLUCENT,"CONTENTS_TRANSLUCENT"}, + {CONTENTS_LADDER,"CONTENTS_LADDER"}, + {0, 0} +}; + +void PrintContents( int contents ) { + int i; + + for ( i = 0; contentnames[i].value; i++ ) + { + if ( contents & contentnames[i].value ) { + botimport.Print( PRT_MESSAGE, "%s\n", contentnames[i].name ); + } //end if + } //end for +} //end of the function PrintContents + +#endif //BSP_DEBUG +//=========================================================================== +// traces axial boxes of any size through the world +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +bsp_trace_t AAS_Trace( vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end, int passent, int contentmask ) { + bsp_trace_t bsptrace; + botimport.Trace( &bsptrace, start, mins, maxs, end, passent, contentmask ); + return bsptrace; +} //end of the function AAS_Trace +//=========================================================================== +// returns the contents at the given point +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_PointContents( vec3_t point ) { + return botimport.PointContents( point ); +} //end of the function AAS_PointContents +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +qboolean AAS_EntityCollision( int entnum, + vec3_t start, vec3_t boxmins, vec3_t boxmaxs, vec3_t end, + int contentmask, bsp_trace_t *trace ) { + bsp_trace_t enttrace; + + botimport.EntityTrace( &enttrace, start, boxmins, boxmaxs, end, entnum, contentmask ); + if ( enttrace.fraction < trace->fraction ) { + memcpy( trace, &enttrace, sizeof( bsp_trace_t ) ); + return qtrue; + } //end if + return qfalse; +} //end of the function AAS_EntityCollision +//=========================================================================== +// returns true if in Potentially Hearable Set +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +qboolean AAS_inPVS( vec3_t p1, vec3_t p2 ) { + return botimport.inPVS( p1, p2 ); +} //end of the function AAS_InPVS +//=========================================================================== +// returns true if in Potentially Visible Set +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +qboolean AAS_inPHS( vec3_t p1, vec3_t p2 ) { + return qtrue; +} //end of the function AAS_inPHS +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_BSPModelMinsMaxsOrigin( int modelnum, vec3_t angles, vec3_t mins, vec3_t maxs, vec3_t origin ) { + botimport.BSPModelMinsMaxsOrigin( modelnum, angles, mins, maxs, origin ); +} //end of the function AAS_BSPModelMinsMaxs +//=========================================================================== +// unlinks the entity from all leaves +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_UnlinkFromBSPLeaves( bsp_link_t *leaves ) { +} //end of the function AAS_UnlinkFromBSPLeaves +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +bsp_link_t *AAS_BSPLinkEntity( vec3_t absmins, vec3_t absmaxs, int entnum, int modelnum ) { + return NULL; +} //end of the function AAS_BSPLinkEntity +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_BoxEntities( vec3_t absmins, vec3_t absmaxs, int *list, int maxcount ) { + return 0; +} //end of the function AAS_BoxEntities +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_NextBSPEntity( int ent ) { + ent++; + if ( ent >= 1 && ent < bspworld.numentities ) { + return ent; + } + return 0; +} //end of the function AAS_NextBSPEntity +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_BSPEntityInRange( int ent ) { + if ( ent <= 0 || ent >= bspworld.numentities ) { + botimport.Print( PRT_MESSAGE, "bsp entity out of range\n" ); + return qfalse; + } //end if + return qtrue; +} //end of the function AAS_BSPEntityInRange +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_ValueForBSPEpairKey( int ent, char *key, char *value, int size ) { + bsp_epair_t *epair; + + value[0] = '\0'; + if ( !AAS_BSPEntityInRange( ent ) ) { + return qfalse; + } + for ( epair = bspworld.entities[ent].epairs; epair; epair = epair->next ) + { + if ( !strcmp( epair->key, key ) ) { + strncpy( value, epair->value, size - 1 ); + value[size - 1] = '\0'; + return qtrue; + } //end if + } //end for + return qfalse; +} //end of the function AAS_FindBSPEpair +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_VectorForBSPEpairKey( int ent, char *key, vec3_t v ) { + char buf[MAX_EPAIRKEY]; + double v1, v2, v3; + + VectorClear( v ); + if ( !AAS_ValueForBSPEpairKey( ent, key, buf, MAX_EPAIRKEY ) ) { + return qfalse; + } + //scanf into doubles, then assign, so it is vec_t size independent + v1 = v2 = v3 = 0; + sscanf( buf, "%lf %lf %lf", &v1, &v2, &v3 ); + v[0] = v1; + v[1] = v2; + v[2] = v3; + return qtrue; +} //end of the function AAS_VectorForBSPEpairKey +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_FloatForBSPEpairKey( int ent, char *key, float *value ) { + char buf[MAX_EPAIRKEY]; + + *value = 0; + if ( !AAS_ValueForBSPEpairKey( ent, key, buf, MAX_EPAIRKEY ) ) { + return qfalse; + } + *value = atof( buf ); + return qtrue; +} //end of the function AAS_FloatForBSPEpairKey +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_IntForBSPEpairKey( int ent, char *key, int *value ) { + char buf[MAX_EPAIRKEY]; + + *value = 0; + if ( !AAS_ValueForBSPEpairKey( ent, key, buf, MAX_EPAIRKEY ) ) { + return qfalse; + } + *value = atoi( buf ); + return qtrue; +} //end of the function AAS_IntForBSPEpairKey +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_FreeBSPEntities( void ) { +// RF, optimized memory allocation +/* + int i; + bsp_entity_t *ent; + bsp_epair_t *epair, *nextepair; + + for (i = 1; i < bspworld.numentities; i++) + { + ent = &bspworld.entities[i]; + for (epair = ent->epairs; epair; epair = nextepair) + { + nextepair = epair->next; + // + if (epair->key) FreeMemory(epair->key); + if (epair->value) FreeMemory(epair->value); + FreeMemory(epair); + } //end for + } //end for +*/ + if ( bspworld.ebuffer ) { + FreeMemory( bspworld.ebuffer ); + } + bspworld.numentities = 0; +} //end of the function AAS_FreeBSPEntities +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_ParseBSPEntities( void ) { + script_t *script; + token_t token; + bsp_entity_t *ent; + bsp_epair_t *epair; + byte *buffer, *buftrav; + int bufsize; + + // RF, modified this, so that it first gathers up memory requirements, then allocates a single chunk, + // and places the strings all in there + + bspworld.ebuffer = NULL; + + script = LoadScriptMemory( bspworld.dentdata, bspworld.entdatasize, "entdata" ); + SetScriptFlags( script, SCFL_NOSTRINGWHITESPACES | SCFL_NOSTRINGESCAPECHARS ); //SCFL_PRIMITIVE); + + bufsize = 0; + + while ( PS_ReadToken( script, &token ) ) + { + if ( strcmp( token.string, "{" ) ) { + ScriptError( script, "invalid %s\n", token.string ); + AAS_FreeBSPEntities(); + FreeScript( script ); + return; + } //end if + if ( bspworld.numentities >= MAX_BSPENTITIES ) { + botimport.Print( PRT_MESSAGE, "too many entities in BSP file\n" ); + break; + } //end if + while ( PS_ReadToken( script, &token ) ) + { + if ( !strcmp( token.string, "}" ) ) { + break; + } + bufsize += sizeof( bsp_epair_t ); + if ( token.type != TT_STRING ) { + ScriptError( script, "invalid %s\n", token.string ); + AAS_FreeBSPEntities(); + FreeScript( script ); + return; + } //end if + StripDoubleQuotes( token.string ); + bufsize += strlen( token.string ) + 1; + if ( !PS_ExpectTokenType( script, TT_STRING, 0, &token ) ) { + AAS_FreeBSPEntities(); + FreeScript( script ); + return; + } //end if + StripDoubleQuotes( token.string ); + bufsize += strlen( token.string ) + 1; + } //end while + if ( strcmp( token.string, "}" ) ) { + ScriptError( script, "missing }\n" ); + AAS_FreeBSPEntities(); + FreeScript( script ); + return; + } //end if + } //end while + FreeScript( script ); + + buffer = (byte *)GetClearedHunkMemory( bufsize ); + buftrav = buffer; + bspworld.ebuffer = buffer; + + // RF, now parse the entities into memory + // RF, NOTE: removed error checks for speed, no need to do them twice + + script = LoadScriptMemory( bspworld.dentdata, bspworld.entdatasize, "entdata" ); + SetScriptFlags( script, SCFL_NOSTRINGWHITESPACES | SCFL_NOSTRINGESCAPECHARS ); //SCFL_PRIMITIVE); + + bspworld.numentities = 1; + + while ( PS_ReadToken( script, &token ) ) + { + ent = &bspworld.entities[bspworld.numentities]; + bspworld.numentities++; + ent->epairs = NULL; + while ( PS_ReadToken( script, &token ) ) + { + if ( !strcmp( token.string, "}" ) ) { + break; + } + epair = (bsp_epair_t *) buftrav; buftrav += sizeof( bsp_epair_t ); + epair->next = ent->epairs; + ent->epairs = epair; + StripDoubleQuotes( token.string ); + epair->key = (char *) buftrav; buftrav += ( strlen( token.string ) + 1 ); + strcpy( epair->key, token.string ); + if ( !PS_ExpectTokenType( script, TT_STRING, 0, &token ) ) { + AAS_FreeBSPEntities(); + FreeScript( script ); + return; + } //end if + StripDoubleQuotes( token.string ); + epair->value = (char *) buftrav; buftrav += ( strlen( token.string ) + 1 ); + strcpy( epair->value, token.string ); + } //end while + } //end while + FreeScript( script ); +} //end of the function AAS_ParseBSPEntities +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_BSPTraceLight( vec3_t start, vec3_t end, vec3_t endpos, int *red, int *green, int *blue ) { + return 0; +} //end of the function AAS_BSPTraceLight +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_DumpBSPData( void ) { + AAS_FreeBSPEntities(); + + if ( bspworld.dentdata ) { + FreeMemory( bspworld.dentdata ); + } + bspworld.dentdata = NULL; + bspworld.entdatasize = 0; + // + bspworld.loaded = qfalse; + memset( &bspworld, 0, sizeof( bspworld ) ); +} //end of the function AAS_DumpBSPData +//=========================================================================== +// load an bsp file +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_LoadBSPFile( void ) { + AAS_DumpBSPData(); + bspworld.entdatasize = strlen( botimport.BSPEntityData() ) + 1; + bspworld.dentdata = (char *) GetClearedHunkMemory( bspworld.entdatasize ); + memcpy( bspworld.dentdata, botimport.BSPEntityData(), bspworld.entdatasize ); + AAS_ParseBSPEntities(); + bspworld.loaded = qtrue; + return BLERR_NOERROR; +} //end of the function AAS_LoadBSPFile diff --git a/Projects/Android/jni/rtcw/src/botlib/be_aas_cluster.c b/Projects/Android/jni/rtcw/src/botlib/be_aas_cluster.c new file mode 100644 index 0000000..a971bcd --- /dev/null +++ b/Projects/Android/jni/rtcw/src/botlib/be_aas_cluster.c @@ -0,0 +1,1601 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +/***************************************************************************** + * name: be_aas_cluster.c + * + * desc: area clustering + * + * + *****************************************************************************/ + +#include "../game/q_shared.h" +#include "l_memory.h" +#include "l_script.h" +#include "l_precomp.h" +#include "l_struct.h" +#include "l_log.h" +#include "l_memory.h" +#include "l_libvar.h" +#include "aasfile.h" +#include "../game/botlib.h" +#include "../game/be_aas.h" +#include "be_aas_funcs.h" +#include "be_aas_def.h" + +extern botlib_import_t botimport; + +#define AAS_MAX_PORTALS 65536 +#define AAS_MAX_PORTALINDEXSIZE 65536 +#define AAS_MAX_CLUSTERS 65536 +// +#define MAX_PORTALAREAS 1024 + +// do not flood through area faces, only use reachabilities +int nofaceflood = qtrue; + +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_RemoveClusterAreas( void ) { + int i; + + for ( i = 1; i < ( *aasworld ).numareas; i++ ) + { + ( *aasworld ).areasettings[i].cluster = 0; + } //end for +} //end of the function AAS_RemoveClusterAreas +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_ClearCluster( int clusternum ) { + int i; + + for ( i = 1; i < ( *aasworld ).numareas; i++ ) + { + if ( ( *aasworld ).areasettings[i].cluster == clusternum ) { + ( *aasworld ).areasettings[i].cluster = 0; + } //end if + } //end for +} //end of the function AAS_ClearCluster +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_RemovePortalsClusterReference( int clusternum ) { + int portalnum; + + for ( portalnum = 1; portalnum < ( *aasworld ).numportals; portalnum++ ) + { + if ( ( *aasworld ).portals[portalnum].frontcluster == clusternum ) { + ( *aasworld ).portals[portalnum].frontcluster = 0; + } //end if + if ( ( *aasworld ).portals[portalnum].backcluster == clusternum ) { + ( *aasworld ).portals[portalnum].backcluster = 0; + } //end if + } //end for +} //end of the function AAS_RemovePortalsClusterReference +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_UpdatePortal( int areanum, int clusternum ) { + int portalnum; + aas_portal_t *portal; + aas_cluster_t *cluster; + + //find the portal of the area + for ( portalnum = 1; portalnum < ( *aasworld ).numportals; portalnum++ ) + { + if ( ( *aasworld ).portals[portalnum].areanum == areanum ) { + break; + } + } //end for + // + if ( portalnum == ( *aasworld ).numportals ) { + AAS_Error( "no portal of area %d", areanum ); + return qtrue; + } //end if + // + portal = &( *aasworld ).portals[portalnum]; + //if the portal is already fully updated + if ( portal->frontcluster == clusternum ) { + return qtrue; + } + if ( portal->backcluster == clusternum ) { + return qtrue; + } + //if the portal has no front cluster yet + if ( !portal->frontcluster ) { + portal->frontcluster = clusternum; + } //end if + //if the portal has no back cluster yet + else if ( !portal->backcluster ) { + portal->backcluster = clusternum; + } //end else if + else + { + Log_Write( "portal using area %d is seperating more than two clusters\r\n", areanum ); + //remove the cluster portal flag contents + ( *aasworld ).areasettings[areanum].contents &= ~AREACONTENTS_CLUSTERPORTAL; + return qfalse; + } //end else + if ( ( *aasworld ).portalindexsize >= AAS_MAX_PORTALINDEXSIZE ) { + AAS_Error( "AAS_MAX_PORTALINDEXSIZE" ); + return qtrue; + } //end if + //set the area cluster number to the negative portal number + ( *aasworld ).areasettings[areanum].cluster = -portalnum; + //add the portal to the cluster using the portal index + cluster = &( *aasworld ).clusters[clusternum]; + ( *aasworld ).portalindex[cluster->firstportal + cluster->numportals] = portalnum; + ( *aasworld ).portalindexsize++; + cluster->numportals++; + return qtrue; +} //end of the function AAS_UpdatePortal +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_FloodClusterAreas_r( int areanum, int clusternum ) { + aas_area_t *area; + aas_face_t *face; + int facenum, i; + + // + if ( areanum <= 0 || areanum >= ( *aasworld ).numareas ) { + AAS_Error( "AAS_FloodClusterAreas_r: areanum out of range" ); + return qfalse; + } //end if + //if the area is already part of a cluster + if ( ( *aasworld ).areasettings[areanum].cluster > 0 ) { + if ( ( *aasworld ).areasettings[areanum].cluster == clusternum ) { + return qtrue; + } + // + //there's a reachability going from one cluster to another only in one direction + // + AAS_Error( "cluster %d touched cluster %d at area %d\r\n", + clusternum, ( *aasworld ).areasettings[areanum].cluster, areanum ); + return qfalse; + } //end if + //don't add the cluster portal areas to the clusters + if ( ( *aasworld ).areasettings[areanum].contents & AREACONTENTS_CLUSTERPORTAL ) { + return AAS_UpdatePortal( areanum, clusternum ); + } //end if + //set the area cluster number + ( *aasworld ).areasettings[areanum].cluster = clusternum; + ( *aasworld ).areasettings[areanum].clusterareanum = + ( *aasworld ).clusters[clusternum].numareas; + //the cluster has an extra area + ( *aasworld ).clusters[clusternum].numareas++; + + area = &( *aasworld ).areas[areanum]; + //use area faces to flood into adjacent areas + if ( !nofaceflood ) { + for ( i = 0; i < area->numfaces; i++ ) + { + facenum = abs( ( *aasworld ).faceindex[area->firstface + i] ); + face = &( *aasworld ).faces[facenum]; + if ( face->frontarea == areanum ) { + if ( face->backarea ) { + if ( !AAS_FloodClusterAreas_r( face->backarea, clusternum ) ) { + return qfalse; + } + } + } //end if + else + { + if ( face->frontarea ) { + if ( !AAS_FloodClusterAreas_r( face->frontarea, clusternum ) ) { + return qfalse; + } + } + } //end else + } //end for + } + //use the reachabilities to flood into other areas + for ( i = 0; i < ( *aasworld ).areasettings[areanum].numreachableareas; i++ ) + { + if ( !( *aasworld ).reachability[ + ( *aasworld ).areasettings[areanum].firstreachablearea + i].areanum ) { + continue; + } //end if + if ( !AAS_FloodClusterAreas_r( ( *aasworld ).reachability[ + ( *aasworld ).areasettings[areanum].firstreachablearea + i].areanum, clusternum ) ) { + return qfalse; + } + } //end for + return qtrue; +} //end of the function AAS_FloodClusterAreas_r +//=========================================================================== +// try to flood from all areas without cluster into areas with a cluster set +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_FloodClusterAreasUsingReachabilities( int clusternum ) { + int i, j, areanum; + + for ( i = 1; i < ( *aasworld ).numareas; i++ ) + { + //if this area already has a cluster set + if ( ( *aasworld ).areasettings[i].cluster ) { + continue; + } + //if this area is a cluster portal + if ( ( *aasworld ).areasettings[i].contents & AREACONTENTS_CLUSTERPORTAL ) { + continue; + } + //loop over the reachable areas from this area + for ( j = 0; j < ( *aasworld ).areasettings[i].numreachableareas; j++ ) + { + //the reachable area + areanum = ( *aasworld ).reachability[( *aasworld ).areasettings[i].firstreachablearea + j].areanum; + //if this area is a cluster portal + if ( ( *aasworld ).areasettings[areanum].contents & AREACONTENTS_CLUSTERPORTAL ) { + continue; + } + //if this area has a cluster set + if ( ( *aasworld ).areasettings[areanum].cluster ) { + if ( !AAS_FloodClusterAreas_r( i, clusternum ) ) { + return qfalse; + } + i = 0; + break; + } //end if + } //end for + } //end for + return qtrue; +} //end of the function AAS_FloodClusterAreasUsingReachabilities +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_NumberClusterPortals( int clusternum ) { + int i, portalnum; + aas_cluster_t *cluster; + aas_portal_t *portal; + + cluster = &( *aasworld ).clusters[clusternum]; + for ( i = 0; i < cluster->numportals; i++ ) + { + portalnum = ( *aasworld ).portalindex[cluster->firstportal + i]; + portal = &( *aasworld ).portals[portalnum]; + if ( portal->frontcluster == clusternum ) { + portal->clusterareanum[0] = cluster->numareas++; + } //end if + else + { + portal->clusterareanum[1] = cluster->numareas++; + } //end else + } //end for +} //end of the function AAS_NumberClusterPortals +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_NumberClusterAreas( int clusternum ) { + int i, portalnum; + aas_cluster_t *cluster; + aas_portal_t *portal; + + ( *aasworld ).clusters[clusternum].numareas = 0; + ( *aasworld ).clusters[clusternum].numreachabilityareas = 0; + //number all areas in this cluster WITH reachabilities + for ( i = 1; i < ( *aasworld ).numareas; i++ ) + { + // + if ( ( *aasworld ).areasettings[i].cluster != clusternum ) { + continue; + } + // + if ( !AAS_AreaReachability( i ) ) { + continue; + } + // + ( *aasworld ).areasettings[i].clusterareanum = ( *aasworld ).clusters[clusternum].numareas; + //the cluster has an extra area + ( *aasworld ).clusters[clusternum].numareas++; + ( *aasworld ).clusters[clusternum].numreachabilityareas++; + } //end for + //number all portals in this cluster WITH reachabilities + cluster = &( *aasworld ).clusters[clusternum]; + for ( i = 0; i < cluster->numportals; i++ ) + { + portalnum = ( *aasworld ).portalindex[cluster->firstportal + i]; + portal = &( *aasworld ).portals[portalnum]; + if ( !AAS_AreaReachability( portal->areanum ) ) { + continue; + } + if ( portal->frontcluster == clusternum ) { + portal->clusterareanum[0] = cluster->numareas++; + ( *aasworld ).clusters[clusternum].numreachabilityareas++; + } //end if + else + { + portal->clusterareanum[1] = cluster->numareas++; + ( *aasworld ).clusters[clusternum].numreachabilityareas++; + } //end else + } //end for + //number all areas in this cluster WITHOUT reachabilities + for ( i = 1; i < ( *aasworld ).numareas; i++ ) + { + // + if ( ( *aasworld ).areasettings[i].cluster != clusternum ) { + continue; + } + // + if ( AAS_AreaReachability( i ) ) { + continue; + } + // + ( *aasworld ).areasettings[i].clusterareanum = ( *aasworld ).clusters[clusternum].numareas; + //the cluster has an extra area + ( *aasworld ).clusters[clusternum].numareas++; + } //end for + //number all portals in this cluster WITHOUT reachabilities + cluster = &( *aasworld ).clusters[clusternum]; + for ( i = 0; i < cluster->numportals; i++ ) + { + portalnum = ( *aasworld ).portalindex[cluster->firstportal + i]; + portal = &( *aasworld ).portals[portalnum]; + if ( AAS_AreaReachability( portal->areanum ) ) { + continue; + } + if ( portal->frontcluster == clusternum ) { + portal->clusterareanum[0] = cluster->numareas++; + } //end if + else + { + portal->clusterareanum[1] = cluster->numareas++; + } //end else + } //end for +} //end of the function AAS_NumberClusterAreas +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_FindClusters( void ) { + int i; + aas_cluster_t *cluster; + + AAS_RemoveClusterAreas(); + // + for ( i = 1; i < ( *aasworld ).numareas; i++ ) + { + //if the area is already part of a cluster + if ( ( *aasworld ).areasettings[i].cluster ) { + continue; + } + // if not flooding through faces only use areas that have reachabilities + if ( nofaceflood ) { + if ( !( *aasworld ).areasettings[i].numreachableareas ) { + continue; + } + } //end if + //if the area is a cluster portal + if ( ( *aasworld ).areasettings[i].contents & AREACONTENTS_CLUSTERPORTAL ) { + continue; + } + if ( ( *aasworld ).numclusters >= AAS_MAX_CLUSTERS ) { + AAS_Error( "AAS_MAX_CLUSTERS" ); + return qfalse; + } //end if + cluster = &( *aasworld ).clusters[( *aasworld ).numclusters]; + cluster->numareas = 0; + cluster->numreachabilityareas = 0; + cluster->firstportal = ( *aasworld ).portalindexsize; + cluster->numportals = 0; + //flood the areas in this cluster + if ( !AAS_FloodClusterAreas_r( i, ( *aasworld ).numclusters ) ) { + return qfalse; + } + if ( !AAS_FloodClusterAreasUsingReachabilities( ( *aasworld ).numclusters ) ) { + return qfalse; + } + //number the cluster areas + //AAS_NumberClusterPortals((*aasworld).numclusters); + AAS_NumberClusterAreas( ( *aasworld ).numclusters ); + //Log_Write("cluster %d has %d areas\r\n", (*aasworld).numclusters, cluster->numareas); + ( *aasworld ).numclusters++; + } //end for + return qtrue; +} //end of the function AAS_FindClusters +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_CreatePortals( void ) { + int i; + aas_portal_t *portal; + + for ( i = 1; i < ( *aasworld ).numareas; i++ ) + { + //if the area is a cluster portal + if ( ( *aasworld ).areasettings[i].contents & AREACONTENTS_CLUSTERPORTAL ) { + if ( ( *aasworld ).numportals >= AAS_MAX_PORTALS ) { + AAS_Error( "AAS_MAX_PORTALS" ); + return; + } //end if + portal = &( *aasworld ).portals[( *aasworld ).numportals]; + portal->areanum = i; + portal->frontcluster = 0; + portal->backcluster = 0; + Log_Write( "portal %d: area %d\r\n", ( *aasworld ).numportals, portal->areanum ); + ( *aasworld ).numportals++; + } //end if + } //end for +} //end of the function AAS_CreatePortals +/* +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_MapContainsTeleporters(void) +{ + bsp_entity_t *entities, *ent; + char *classname; + + entities = AAS_ParseBSPEntities(); + + for (ent = entities; ent; ent = ent->next) + { + classname = AAS_ValueForBSPEpairKey(ent, "classname"); + if (classname && !strcmp(classname, "misc_teleporter")) + { + AAS_FreeBSPEntities(entities); + return qtrue; + } //end if + } //end for + return qfalse; +} //end of the function AAS_MapContainsTeleporters +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_NonConvexFaces(aas_face_t *face1, aas_face_t *face2, int side1, int side2) +{ + int i, j, edgenum; + aas_plane_t *plane1, *plane2; + aas_edge_t *edge; + + + plane1 = &(*aasworld).planes[face1->planenum ^ side1]; + plane2 = &(*aasworld).planes[face2->planenum ^ side2]; + + //check if one of the points of face1 is at the back of the plane of face2 + for (i = 0; i < face1->numedges; i++) + { + edgenum = abs((*aasworld).edgeindex[face1->firstedge + i]); + edge = &(*aasworld).edges[edgenum]; + for (j = 0; j < 2; j++) + { + if (DotProduct(plane2->normal, (*aasworld).vertexes[edge->v[j]]) - + plane2->dist < -0.01) return qtrue; + } //end for + } //end for + for (i = 0; i < face2->numedges; i++) + { + edgenum = abs((*aasworld).edgeindex[face2->firstedge + i]); + edge = &(*aasworld).edges[edgenum]; + for (j = 0; j < 2; j++) + { + if (DotProduct(plane1->normal, (*aasworld).vertexes[edge->v[j]]) - + plane1->dist < -0.01) return qtrue; + } //end for + } //end for + + return qfalse; +} //end of the function AAS_NonConvexFaces +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +qboolean AAS_CanMergeAreas(int *areanums, int numareas) +{ + int i, j, s, face1num, face2num, side1, side2, fn1, fn2; + aas_face_t *face1, *face2; + aas_area_t *area1, *area2; + + for (i = 0; i < numareas; i++) + { + area1 = &(*aasworld).areas[areanums[i]]; + for (fn1 = 0; fn1 < area1->numfaces; fn1++) + { + face1num = abs((*aasworld).faceindex[area1->firstface + fn1]); + face1 = &(*aasworld).faces[face1num]; + side1 = face1->frontarea != areanums[i]; + //check if the face isn't a shared one with one of the other areas + for (s = 0; s < numareas; s++) + { + if (s == i) continue; + if (face1->frontarea == s || face1->backarea == s) break; + } //end for + //if the face was a shared one + if (s != numareas) continue; + // + for (j = 0; j < numareas; j++) + { + if (j == i) continue; + area2 = &(*aasworld).areas[areanums[j]]; + for (fn2 = 0; fn2 < area2->numfaces; fn2++) + { + face2num = abs((*aasworld).faceindex[area2->firstface + fn2]); + face2 = &(*aasworld).faces[face2num]; + side2 = face2->frontarea != areanums[j]; + //check if the face isn't a shared one with one of the other areas + for (s = 0; s < numareas; s++) + { + if (s == j) continue; + if (face2->frontarea == s || face2->backarea == s) break; + } //end for + //if the face was a shared one + if (s != numareas) continue; + // + if (AAS_NonConvexFaces(face1, face2, side1, side2)) return qfalse; + } //end for + } //end for + } //end for + } //end for + return qtrue; +} //end of the function AAS_CanMergeAreas +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +qboolean AAS_NonConvexEdges(aas_edge_t *edge1, aas_edge_t *edge2, int side1, int side2, int planenum) +{ + int i; + vec3_t edgevec1, edgevec2, normal1, normal2; + float dist1, dist2; + aas_plane_t *plane; + + plane = &(*aasworld).planes[planenum]; + VectorSubtract((*aasworld).vertexes[edge1->v[1]], (*aasworld).vertexes[edge1->v[0]], edgevec1); + VectorSubtract((*aasworld).vertexes[edge2->v[1]], (*aasworld).vertexes[edge2->v[0]], edgevec2); + if (side1) VectorInverse(edgevec1); + if (side2) VectorInverse(edgevec2); + // + CrossProduct(edgevec1, plane->normal, normal1); + dist1 = DotProduct(normal1, (*aasworld).vertexes[edge1->v[0]]); + CrossProduct(edgevec2, plane->normal, normal2); + dist2 = DotProduct(normal2, (*aasworld).vertexes[edge2->v[0]]); + + for (i = 0; i < 2; i++) + { + if (DotProduct((*aasworld).vertexes[edge1->v[i]], normal2) - dist2 < -0.01) return qfalse; + } //end for + for (i = 0; i < 2; i++) + { + if (DotProduct((*aasworld).vertexes[edge2->v[i]], normal1) - dist1 < -0.01) return qfalse; + } //end for + return qtrue; +} //end of the function AAS_NonConvexEdges +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +qboolean AAS_CanMergeFaces(int *facenums, int numfaces, int planenum) +{ + int i, j, s, edgenum1, edgenum2, side1, side2, en1, en2, ens; + aas_face_t *face1, *face2, *otherface; + aas_edge_t *edge1, *edge2; + + for (i = 0; i < numfaces; i++) + { + face1 = &(*aasworld).faces[facenums[i]]; + for (en1 = 0; en1 < face1->numedges; en1++) + { + edgenum1 = (*aasworld).edgeindex[face1->firstedge + en1]; + side1 = (edgenum1 < 0) ^ (face1->planenum != planenum); + edgenum1 = abs(edgenum1); + edge1 = &(*aasworld).edges[edgenum1]; + //check if the edge is shared with another face + for (s = 0; s < numfaces; s++) + { + if (s == i) continue; + otherface = &(*aasworld).faces[facenums[s]]; + for (ens = 0; ens < otherface->numedges; ens++) + { + if (edgenum1 == abs((*aasworld).edgeindex[otherface->firstedge + ens])) break; + } //end for + if (ens != otherface->numedges) break; + } //end for + //if the edge was shared + if (s != numfaces) continue; + // + for (j = 0; j < numfaces; j++) + { + if (j == i) continue; + face2 = &(*aasworld).faces[facenums[j]]; + for (en2 = 0; en2 < face2->numedges; en2++) + { + edgenum2 = (*aasworld).edgeindex[face2->firstedge + en2]; + side2 = (edgenum2 < 0) ^ (face2->planenum != planenum); + edgenum2 = abs(edgenum2); + edge2 = &(*aasworld).edges[edgenum2]; + //check if the edge is shared with another face + for (s = 0; s < numfaces; s++) + { + if (s == i) continue; + otherface = &(*aasworld).faces[facenums[s]]; + for (ens = 0; ens < otherface->numedges; ens++) + { + if (edgenum2 == abs((*aasworld).edgeindex[otherface->firstedge + ens])) break; + } //end for + if (ens != otherface->numedges) break; + } //end for + //if the edge was shared + if (s != numfaces) continue; + // + if (AAS_NonConvexEdges(edge1, edge2, side1, side2, planenum)) return qfalse; + } //end for + } //end for + } //end for + } //end for + return qtrue; +} //end of the function AAS_CanMergeFaces*/ +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_ConnectedAreas_r( int *areanums, int numareas, int *connectedareas, int curarea ) { + int i, j, otherareanum, facenum; + aas_area_t *area; + aas_face_t *face; + + connectedareas[curarea] = qtrue; + area = &( *aasworld ).areas[areanums[curarea]]; + for ( i = 0; i < area->numfaces; i++ ) + { + facenum = abs( ( *aasworld ).faceindex[area->firstface + i] ); + face = &( *aasworld ).faces[facenum]; + //if the face is solid + if ( face->faceflags & FACE_SOLID ) { + continue; + } + //get the area at the other side of the face + if ( face->frontarea != areanums[curarea] ) { + otherareanum = face->frontarea; + } else { otherareanum = face->backarea;} + //check if the face is leading to one of the other areas + for ( j = 0; j < numareas; j++ ) + { + if ( areanums[j] == otherareanum ) { + break; + } + } //end for + //if the face isn't leading to one of the other areas + if ( j == numareas ) { + continue; + } + //if the other area is already connected + if ( connectedareas[j] ) { + continue; + } + //recursively proceed with the other area + AAS_ConnectedAreas_r( areanums, numareas, connectedareas, j ); + } //end for +} //end of the function AAS_ConnectedAreas_r +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +qboolean AAS_ConnectedAreas( int *areanums, int numareas ) { + int connectedareas[MAX_PORTALAREAS], i; + + memset( connectedareas, 0, sizeof( connectedareas ) ); + if ( numareas < 1 ) { + return qfalse; + } + if ( numareas == 1 ) { + return qtrue; + } + AAS_ConnectedAreas_r( areanums, numareas, connectedareas, 0 ); + for ( i = 0; i < numareas; i++ ) + { + if ( !connectedareas[i] ) { + return qfalse; + } + } //end for + return qtrue; +} //end of the function AAS_ConnectedAreas +//=========================================================================== +// gets adjacent areas with less presence types recursively +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_GetAdjacentAreasWithLessPresenceTypes_r( int *areanums, int numareas, int curareanum ) { + int i, j, presencetype, otherpresencetype, otherareanum, facenum; + aas_area_t *area; + aas_face_t *face; + + areanums[numareas++] = curareanum; + area = &( *aasworld ).areas[curareanum]; + presencetype = ( *aasworld ).areasettings[curareanum].presencetype; + for ( i = 0; i < area->numfaces; i++ ) + { + facenum = abs( ( *aasworld ).faceindex[area->firstface + i] ); + face = &( *aasworld ).faces[facenum]; + //if the face is solid + if ( face->faceflags & FACE_SOLID ) { + continue; + } + //the area at the other side of the face + if ( face->frontarea != curareanum ) { + otherareanum = face->frontarea; + } else { otherareanum = face->backarea;} + // + otherpresencetype = ( *aasworld ).areasettings[otherareanum].presencetype; + //if the other area has less presence types + if ( ( presencetype & ~otherpresencetype ) && + !( otherpresencetype & ~presencetype ) ) { + //check if the other area isn't already in the list + for ( j = 0; j < numareas; j++ ) + { + if ( otherareanum == areanums[j] ) { + break; + } + } //end for + //if the other area isn't already in the list + if ( j == numareas ) { + if ( numareas >= MAX_PORTALAREAS ) { + AAS_Error( "MAX_PORTALAREAS" ); + return numareas; + } //end if + numareas = AAS_GetAdjacentAreasWithLessPresenceTypes_r( areanums, numareas, otherareanum ); + } //end if + } //end if + } //end for + return numareas; +} //end of the function AAS_GetAdjacentAreasWithLessPresenceTypes_r +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_CheckAreaForPossiblePortals( int areanum ) { + int i, j, k, fen, ben, frontedgenum, backedgenum, facenum; + int areanums[MAX_PORTALAREAS], numareas, otherareanum; + int numareafrontfaces[MAX_PORTALAREAS], numareabackfaces[MAX_PORTALAREAS]; + int frontfacenums[MAX_PORTALAREAS], backfacenums[MAX_PORTALAREAS]; + int numfrontfaces, numbackfaces; + int frontareanums[MAX_PORTALAREAS], backareanums[MAX_PORTALAREAS]; + int numfrontareas, numbackareas; + int frontplanenum, backplanenum, faceplanenum; + aas_area_t *area; + aas_face_t *frontface, *backface, *face; + + //if it isn't already a portal + if ( ( *aasworld ).areasettings[areanum].contents & AREACONTENTS_CLUSTERPORTAL ) { + return 0; + } + //it must be a grounded area + if ( !( ( *aasworld ).areasettings[areanum].areaflags & AREA_GROUNDED ) ) { + return 0; + } + // + memset( numareafrontfaces, 0, sizeof( numareafrontfaces ) ); + memset( numareabackfaces, 0, sizeof( numareabackfaces ) ); + numareas = numfrontfaces = numbackfaces = 0; + numfrontareas = numbackareas = 0; + frontplanenum = backplanenum = -1; + //add any adjacent areas with less presence types + numareas = AAS_GetAdjacentAreasWithLessPresenceTypes_r( areanums, 0, areanum ); + // + for ( i = 0; i < numareas; i++ ) + { + area = &( *aasworld ).areas[areanums[i]]; + for ( j = 0; j < area->numfaces; j++ ) + { + facenum = abs( ( *aasworld ).faceindex[area->firstface + j] ); + face = &( *aasworld ).faces[facenum]; + //if the face is solid + if ( face->faceflags & FACE_SOLID ) { + continue; + } + //check if the face is shared with one of the other areas + for ( k = 0; k < numareas; k++ ) + { + if ( k == i ) { + continue; + } + if ( face->frontarea == areanums[k] || face->backarea == areanums[k] ) { + break; + } + } //end for + //if the face is shared + if ( k != numareas ) { + continue; + } + //the number of the area at the other side of the face + if ( face->frontarea == areanums[i] ) { + otherareanum = face->backarea; + } else { otherareanum = face->frontarea;} + //if the other area already is a cluter portal + if ( ( *aasworld ).areasettings[otherareanum].contents & AREACONTENTS_CLUSTERPORTAL ) { + return 0; + } + //number of the plane of the area + faceplanenum = face->planenum & ~1; + // + if ( frontplanenum < 0 || faceplanenum == frontplanenum ) { + frontplanenum = faceplanenum; + frontfacenums[numfrontfaces++] = facenum; + for ( k = 0; k < numfrontareas; k++ ) + { + if ( frontareanums[k] == otherareanum ) { + break; + } + } //end for + if ( k == numfrontareas ) { + frontareanums[numfrontareas++] = otherareanum; + } + numareafrontfaces[i]++; + } //end if + else if ( backplanenum < 0 || faceplanenum == backplanenum ) { + backplanenum = faceplanenum; + backfacenums[numbackfaces++] = facenum; + for ( k = 0; k < numbackareas; k++ ) + { + if ( backareanums[k] == otherareanum ) { + break; + } + } //end for + if ( k == numbackareas ) { + backareanums[numbackareas++] = otherareanum; + } + numareabackfaces[i]++; + } //end else + else + { + return 0; + } //end else + } //end for + } //end for + //every area should have at least one front face and one back face + for ( i = 0; i < numareas; i++ ) + { + if ( !numareafrontfaces[i] || !numareabackfaces[i] ) { + return 0; + } + } //end for + //the front areas should all be connected + if ( !AAS_ConnectedAreas( frontareanums, numfrontareas ) ) { + return 0; + } + //the back areas should all be connected + if ( !AAS_ConnectedAreas( backareanums, numbackareas ) ) { + return 0; + } + //none of the front faces should have a shared edge with a back face + for ( i = 0; i < numfrontfaces; i++ ) + { + frontface = &( *aasworld ).faces[frontfacenums[i]]; + for ( fen = 0; fen < frontface->numedges; fen++ ) + { + frontedgenum = abs( ( *aasworld ).edgeindex[frontface->firstedge + fen] ); + for ( j = 0; j < numbackfaces; j++ ) + { + backface = &( *aasworld ).faces[backfacenums[j]]; + for ( ben = 0; ben < backface->numedges; ben++ ) + { + backedgenum = abs( ( *aasworld ).edgeindex[backface->firstedge + ben] ); + if ( frontedgenum == backedgenum ) { + break; + } + } //end for + if ( ben != backface->numedges ) { + break; + } + } //end for + if ( j != numbackfaces ) { + break; + } + } //end for + if ( fen != frontface->numedges ) { + break; + } + } //end for + if ( i != numfrontfaces ) { + return 0; + } + //set the cluster portal contents + for ( i = 0; i < numareas; i++ ) + { + ( *aasworld ).areasettings[areanums[i]].contents |= AREACONTENTS_CLUSTERPORTAL; + //this area can be used as a route portal + ( *aasworld ).areasettings[areanums[i]].contents |= AREACONTENTS_ROUTEPORTAL; + Log_Write( "possible portal: %d\r\n", areanums[i] ); + } //end for + // + return numareas; +} //end of the function AAS_CheckAreaForPossiblePortals +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_FindPossiblePortals( void ) { + int i, numpossibleportals; + + numpossibleportals = 0; + for ( i = 1; i < ( *aasworld ).numareas; i++ ) + { + numpossibleportals += AAS_CheckAreaForPossiblePortals( i ); + } //end for + botimport.Print( PRT_MESSAGE, "\r%6d possible portals\n", numpossibleportals ); +} //end of the function AAS_FindPossiblePortals +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_RemoveAllPortals( void ) { + int i; + + for ( i = 1; i < ( *aasworld ).numareas; i++ ) + { + ( *aasworld ).areasettings[i].contents &= ~AREACONTENTS_CLUSTERPORTAL; + } //end for +} //end of the function AAS_RemoveAllPortals +/* +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_FloodCluster_r(int areanum, int clusternum) +{ + int i, otherareanum; + aas_face_t *face; + aas_area_t *area; + + //set cluster mark + (*aasworld).areasettings[areanum].cluster = clusternum; + //if the area is a portal + //if ((*aasworld).areasettings[areanum].contents & AREACONTENTS_CLUSTERPORTAL) return; + // + area = &(*aasworld).areas[areanum]; + //use area faces to flood into adjacent areas + for (i = 0; i < area->numfaces; i++) + { + face = &(*aasworld).faces[abs((*aasworld).faceindex[area->firstface + i])]; + // + if (face->frontarea != areanum) otherareanum = face->frontarea; + else otherareanum = face->backarea; + //if there's no area at the other side + if (!otherareanum) continue; + //if the area is a portal + if ((*aasworld).areasettings[otherareanum].contents & AREACONTENTS_CLUSTERPORTAL) continue; + //if the area is already marked + if ((*aasworld).areasettings[otherareanum].cluster) continue; + // + AAS_FloodCluster_r(otherareanum, clusternum); + } //end for + //use the reachabilities to flood into other areas + for (i = 0; i < (*aasworld).areasettings[areanum].numreachableareas; i++) + { + otherareanum = (*aasworld).reachability[ + (*aasworld).areasettings[areanum].firstreachablearea + i].areanum; + if (!otherareanum) + { + continue; + AAS_Error("reachability %d has zero area\n", (*aasworld).areasettings[areanum].firstreachablearea + i); + } //end if + //if the area is a portal + if ((*aasworld).areasettings[otherareanum].contents & AREACONTENTS_CLUSTERPORTAL) continue; + //if the area is already marked + if ((*aasworld).areasettings[otherareanum].cluster) continue; + // + AAS_FloodCluster_r(otherareanum, clusternum); + } //end for +} //end of the function AAS_FloodCluster_r +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_RemoveTeleporterPortals(void) +{ + int i, j, areanum; + + for (i = 1; i < (*aasworld).numareas; i++) + { + for (j = 0; j < (*aasworld).areasettings[i].numreachableareas; j++) + { + areanum = (*aasworld).reachability[(*aasworld).areasettings[i].firstreachablearea + j].areanum; + if ((*aasworld).reachability[(*aasworld).areasettings[i].firstreachablearea + j].traveltype == TRAVEL_TELEPORT) + { + (*aasworld).areasettings[i].contents &= ~AREACONTENTS_CLUSTERPORTAL; + (*aasworld).areasettings[areanum].contents &= ~AREACONTENTS_CLUSTERPORTAL; + break; + } //end if + } //end for + } //end for +} //end of the function AAS_RemoveTeleporterPortals +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_FloodClusterReachabilities(int clusternum) +{ + int i, j, areanum; + + for (i = 1; i < (*aasworld).numareas; i++) + { + //if this area already has a cluster set + if ((*aasworld).areasettings[i].cluster) continue; + //if this area is a cluster portal + if ((*aasworld).areasettings[i].contents & AREACONTENTS_CLUSTERPORTAL) continue; + //loop over the reachable areas from this area + for (j = 0; j < (*aasworld).areasettings[i].numreachableareas; j++) + { + //the reachable area + areanum = (*aasworld).reachability[(*aasworld).areasettings[i].firstreachablearea + j].areanum; + //if this area is a cluster portal + if ((*aasworld).areasettings[areanum].contents & AREACONTENTS_CLUSTERPORTAL) continue; + //if this area has a cluster set + if ((*aasworld).areasettings[areanum].cluster == clusternum) + { + AAS_FloodCluster_r(i, clusternum); + i = 0; + break; + } //end if + } //end for + } //end for +} //end of the function AAS_FloodClusterReachabilities +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +*/ +/* +void AAS_RemoveNotClusterClosingPortals(void) +{ + int i, j, k, facenum, otherareanum, nonclosingportals; + aas_area_t *area; + aas_face_t *face; + + AAS_RemoveTeleporterPortals(); + // + nonclosingportals = 0; + for (i = 1; i < (*aasworld).numareas; i++) + { + if (!((*aasworld).areasettings[i].contents & AREACONTENTS_CLUSTERPORTAL)) continue; + //find a non-portal area adjacent to the portal area and flood + //the cluster from there + area = &(*aasworld).areas[i]; + for (j = 0; j < area->numfaces; j++) + { + facenum = abs((*aasworld).faceindex[area->firstface + j]); + face = &(*aasworld).faces[facenum]; + // + if (face->frontarea != i) otherareanum = face->frontarea; + else otherareanum = face->backarea; + // + if (!otherareanum) continue; + // + if ((*aasworld).areasettings[otherareanum].contents & AREACONTENTS_CLUSTERPORTAL) + { + continue; + } //end if + //reset all cluster fields + AAS_RemoveClusterAreas(); + // + AAS_FloodCluster_r(otherareanum, 1); + AAS_FloodClusterReachabilities(1); + //check if all adjacent non-portal areas have a cluster set + for (k = 0; k < area->numfaces; k++) + { + facenum = abs((*aasworld).faceindex[area->firstface + k]); + face = &(*aasworld).faces[facenum]; + // + if (face->frontarea != i) otherareanum = face->frontarea; + else otherareanum = face->backarea; + // + if (!otherareanum) continue; + // + if ((*aasworld).areasettings[otherareanum].contents & AREACONTENTS_CLUSTERPORTAL) + { + continue; + } //end if + // + if (!(*aasworld).areasettings[otherareanum].cluster) break; + } //end for + //if all adjacent non-portal areas have a cluster set then the portal + //didn't seal a cluster + if (k >= area->numfaces) + { + (*aasworld).areasettings[i].contents &= ~AREACONTENTS_CLUSTERPORTAL; + nonclosingportals++; + //recheck all the other portals again + i = 0; + break; + } //end if + } //end for + } //end for + botimport.Print(PRT_MESSAGE, "\r%6d non closing portals removed\n", nonclosingportals); +} //end of the function AAS_RemoveNotClusterClosingPortals*/ +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +/* +void AAS_RemoveNotClusterClosingPortals(void) +{ + int i, j, facenum, otherareanum, nonclosingportals, numseperatedclusters; + aas_area_t *area; + aas_face_t *face; + + AAS_RemoveTeleporterPortals(); + // + nonclosingportals = 0; + for (i = 1; i < (*aasworld).numareas; i++) + { + if (!((*aasworld).areasettings[i].contents & AREACONTENTS_CLUSTERPORTAL)) continue; + // + numseperatedclusters = 0; + //reset all cluster fields + AAS_RemoveClusterAreas(); + //find a non-portal area adjacent to the portal area and flood + //the cluster from there + area = &(*aasworld).areas[i]; + for (j = 0; j < area->numfaces; j++) + { + facenum = abs((*aasworld).faceindex[area->firstface + j]); + face = &(*aasworld).faces[facenum]; + // + if (face->frontarea != i) otherareanum = face->frontarea; + else otherareanum = face->backarea; + //if not solid at the other side of the face + if (!otherareanum) continue; + //don't flood into other portals + if ((*aasworld).areasettings[otherareanum].contents & AREACONTENTS_CLUSTERPORTAL) continue; + //if the area already has a cluster set + if ((*aasworld).areasettings[otherareanum].cluster) continue; + //another cluster is seperated by this portal + numseperatedclusters++; + //flood the cluster + AAS_FloodCluster_r(otherareanum, numseperatedclusters); + AAS_FloodClusterReachabilities(numseperatedclusters); + } //end for + //use the reachabilities to flood into other areas + for (j = 0; j < (*aasworld).areasettings[i].numreachableareas; j++) + { + otherareanum = (*aasworld).reachability[ + (*aasworld).areasettings[i].firstreachablearea + j].areanum; + //this should never be qtrue but we check anyway + if (!otherareanum) continue; + //don't flood into other portals + if ((*aasworld).areasettings[otherareanum].contents & AREACONTENTS_CLUSTERPORTAL) continue; + //if the area already has a cluster set + if ((*aasworld).areasettings[otherareanum].cluster) continue; + //another cluster is seperated by this portal + numseperatedclusters++; + //flood the cluster + AAS_FloodCluster_r(otherareanum, numseperatedclusters); + AAS_FloodClusterReachabilities(numseperatedclusters); + } //end for + //a portal must seperate no more and no less than 2 clusters + if (numseperatedclusters != 2) + { + (*aasworld).areasettings[i].contents &= ~AREACONTENTS_CLUSTERPORTAL; + nonclosingportals++; + //recheck all the other portals again + i = 0; + } //end if + } //end for + botimport.Print(PRT_MESSAGE, "\r%6d non closing portals removed\n", nonclosingportals); +} //end of the function AAS_RemoveNotClusterClosingPortals +*/ +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +/* +void AAS_AddTeleporterPortals(void) +{ + int j, area2num, facenum, otherareanum; + char *target, *targetname, *classname; + bsp_entity_t *entities, *ent, *dest; + vec3_t origin, destorigin, mins, maxs, end; + vec3_t bbmins, bbmaxs; + aas_area_t *area; + aas_face_t *face; + aas_trace_t trace; + aas_link_t *areas, *link; + + entities = AAS_ParseBSPEntities(); + + for (ent = entities; ent; ent = ent->next) + { + classname = AAS_ValueForBSPEpairKey(ent, "classname"); + if (classname && !strcmp(classname, "misc_teleporter")) + { + if (!AAS_VectorForBSPEpairKey(ent, "origin", origin)) + { + botimport.Print(PRT_ERROR, "teleporter (%s) without origin\n", target); + continue; + } //end if + // + target = AAS_ValueForBSPEpairKey(ent, "target"); + if (!target) + { + botimport.Print(PRT_ERROR, "teleporter (%s) without target\n", target); + continue; + } //end if + for (dest = entities; dest; dest = dest->next) + { + classname = AAS_ValueForBSPEpairKey(dest, "classname"); + if (classname && !strcmp(classname, "misc_teleporter_dest")) + { + targetname = AAS_ValueForBSPEpairKey(dest, "targetname"); + if (targetname && !strcmp(targetname, target)) + { + break; + } //end if + } //end if + } //end for + if (!dest) + { + botimport.Print(PRT_ERROR, "teleporter without destination (%s)\n", target); + continue; + } //end if + if (!AAS_VectorForBSPEpairKey(dest, "origin", destorigin)) + { + botimport.Print(PRT_ERROR, "teleporter destination (%s) without origin\n", target); + continue; + } //end if + destorigin[2] += 24; //just for q2e1m2, the dork has put the telepads in the ground + VectorCopy(destorigin, end); + end[2] -= 100; + trace = AAS_TraceClientBBox(destorigin, end, PRESENCE_CROUCH, -1); + if (trace.startsolid) + { + botimport.Print(PRT_ERROR, "teleporter destination (%s) in solid\n", target); + continue; + } //end if + VectorCopy(trace.endpos, destorigin); + area2num = AAS_PointAreaNum(destorigin); + //reset all cluster fields + for (j = 0; j < (*aasworld).numareas; j++) + { + (*aasworld).areasettings[j].cluster = 0; + } //end for + // + VectorSet(mins, -8, -8, 8); + VectorSet(maxs, 8, 8, 24); + // + AAS_PresenceTypeBoundingBox(PRESENCE_CROUCH, bbmins, bbmaxs); + // + VectorAdd(origin, mins, mins); + VectorAdd(origin, maxs, maxs); + //add bounding box size + VectorSubtract(mins, bbmaxs, mins); + VectorSubtract(maxs, bbmins, maxs); + //link an invalid (-1) entity + areas = AAS_AASLinkEntity(mins, maxs, -1); + // + for (link = areas; link; link = link->next_area) + { + if (!AAS_AreaGrounded(link->areanum)) continue; + //add the teleporter portal mark + (*aasworld).areasettings[link->areanum].contents |= AREACONTENTS_CLUSTERPORTAL | + AREACONTENTS_TELEPORTAL; + } //end for + // + for (link = areas; link; link = link->next_area) + { + if (!AAS_AreaGrounded(link->areanum)) continue; + //find a non-portal area adjacent to the portal area and flood + //the cluster from there + area = &(*aasworld).areas[link->areanum]; + for (j = 0; j < area->numfaces; j++) + { + facenum = abs((*aasworld).faceindex[area->firstface + j]); + face = &(*aasworld).faces[facenum]; + // + if (face->frontarea != link->areanum) otherareanum = face->frontarea; + else otherareanum = face->backarea; + // + if (!otherareanum) continue; + // + if ((*aasworld).areasettings[otherareanum].contents & AREACONTENTS_CLUSTERPORTAL) + { + continue; + } //end if + // + AAS_FloodCluster_r(otherareanum, 1); + } //end for + } //end for + //if the teleport destination IS in the same cluster + if ((*aasworld).areasettings[area2num].cluster) + { + for (link = areas; link; link = link->next_area) + { + if (!AAS_AreaGrounded(link->areanum)) continue; + //add the teleporter portal mark + (*aasworld).areasettings[link->areanum].contents &= ~(AREACONTENTS_CLUSTERPORTAL | + AREACONTENTS_TELEPORTAL); + } //end for + } //end if + } //end if + } //end for + AAS_FreeBSPEntities(entities); +} //end of the function AAS_AddTeleporterPortals*/ +/* +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_AddTeleporterPortals(void) +{ + int i, j, areanum; + + for (i = 1; i < (*aasworld).numareas; i++) + { + for (j = 0; j < (*aasworld).areasettings[i].numreachableareas; j++) + { + if ((*aasworld).reachability[(*aasworld).areasettings[i].firstreachablearea + j].traveltype != TRAVEL_TELEPORT) continue; + areanum = (*aasworld).reachability[(*aasworld).areasettings[i].firstreachablearea + j].areanum; + (*aasworld).areasettings[areanum].contents |= AREACONTENTS_CLUSTERPORTAL; + } //end for + } //end for +} //end of the function AAS_AddTeleporterPortals*/ +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_TestPortals( void ) { + int i; + aas_portal_t *portal; + + for ( i = 1; i < ( *aasworld ).numportals; i++ ) + { + portal = &( *aasworld ).portals[i]; + if ( !portal->frontcluster ) { + ( *aasworld ).areasettings[portal->areanum].contents &= ~AREACONTENTS_CLUSTERPORTAL; + Log_Write( "portal area %d has no front cluster\r\n", portal->areanum ); + return qfalse; + } //end if + if ( !portal->backcluster ) { + ( *aasworld ).areasettings[portal->areanum].contents &= ~AREACONTENTS_CLUSTERPORTAL; + Log_Write( "portal area %d has no back cluster\r\n", portal->areanum ); + return qfalse; + } //end if + } //end for + return qtrue; +} //end of the function +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_CountForcedClusterPortals( void ) { + int num, i; + + num = 0; + for ( i = 1; i < ( *aasworld ).numareas; i++ ) + { + if ( ( *aasworld ).areasettings[i].contents & AREACONTENTS_CLUSTERPORTAL ) { + num++; + } //end if + } //end for + botimport.Print( PRT_MESSAGE, "%6d forced portals\n", num ); +} //end of the function AAS_CountForcedClusterPortals +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_CreateViewPortals( void ) { + int i; + + for ( i = 1; i < ( *aasworld ).numareas; i++ ) + { + if ( ( *aasworld ).areasettings[i].contents & AREACONTENTS_CLUSTERPORTAL ) { + ( *aasworld ).areasettings[i].contents |= AREACONTENTS_VIEWPORTAL; + } //end if + } //end for +} //end of the function AAS_CreateViewPortals +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_SetViewPortalsAsClusterPortals( void ) { + int i; + + for ( i = 1; i < ( *aasworld ).numareas; i++ ) + { + if ( ( *aasworld ).areasettings[i].contents & AREACONTENTS_VIEWPORTAL ) { + ( *aasworld ).areasettings[i].contents |= AREACONTENTS_CLUSTERPORTAL; + } //end if + } //end for +} //end of the function AAS_SetViewPortalsAsClusterPortals +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_InitClustering( void ) { + int i, removedPortalAreas; + int n, total, numreachabilityareas; + + if ( !( *aasworld ).loaded ) { + return; + } + //if there are clusters + if ( ( *aasworld ).numclusters >= 1 ) { +#ifndef BSPC + //if clustering isn't forced + if ( !( (int)LibVarGetValue( "forceclustering" ) ) && + !( (int)LibVarGetValue( "forcereachability" ) ) ) { + return; + } +#else + return; +#endif + } //end if + // + AAS_CountForcedClusterPortals(); + //remove all the existing portals + //AAS_RemoveAllPortals(); + //remove all area cluster marks + AAS_RemoveClusterAreas(); + //find possible cluster portals + AAS_FindPossiblePortals(); + //craete portals to for the bot view + AAS_CreateViewPortals(); + //remove all portals that are not closing a cluster + //AAS_RemoveNotClusterClosingPortals(); + //initialize portal memory + if ( ( *aasworld ).portals ) { + FreeMemory( ( *aasworld ).portals ); + } + ( *aasworld ).portals = (aas_portal_t *) GetClearedMemory( AAS_MAX_PORTALS * sizeof( aas_portal_t ) ); + //initialize portal index memory + if ( ( *aasworld ).portalindex ) { + FreeMemory( ( *aasworld ).portalindex ); + } + ( *aasworld ).portalindex = (aas_portalindex_t *) GetClearedMemory( AAS_MAX_PORTALINDEXSIZE * sizeof( aas_portalindex_t ) ); + //initialize cluster memory + if ( ( *aasworld ).clusters ) { + FreeMemory( ( *aasworld ).clusters ); + } + ( *aasworld ).clusters = (aas_cluster_t *) GetClearedMemory( AAS_MAX_CLUSTERS * sizeof( aas_cluster_t ) ); + // + removedPortalAreas = 0; + botimport.Print( PRT_MESSAGE, "\r%6d removed portal areas", removedPortalAreas ); + while ( 1 ) + { + botimport.Print( PRT_MESSAGE, "\r%6d", removedPortalAreas ); + //initialize the number of portals and clusters + ( *aasworld ).numportals = 1; //portal 0 is a dummy + ( *aasworld ).portalindexsize = 0; + ( *aasworld ).numclusters = 1; //cluster 0 is a dummy + //create the portals from the portal areas + AAS_CreatePortals(); + // + removedPortalAreas++; + //find the clusters + if ( !AAS_FindClusters() ) { + continue; + } + //test the portals + if ( !AAS_TestPortals() ) { + continue; + } + // + break; + } //end while + botimport.Print( PRT_MESSAGE, "\n" ); + //the AAS file should be saved + ( *aasworld ).savefile = qtrue; + // report cluster info + botimport.Print( PRT_MESSAGE, "%6d portals created\n", ( *aasworld ).numportals ); + botimport.Print( PRT_MESSAGE, "%6d clusters created\n", ( *aasworld ).numclusters ); + for ( i = 1; i < ( *aasworld ).numclusters; i++ ) + { + botimport.Print( PRT_MESSAGE, "cluster %d has %d reachability areas\n", i, + ( *aasworld ).clusters[i].numreachabilityareas ); + } //end for + // report AAS file efficiency + numreachabilityareas = 0; + total = 0; + for ( i = 0; i < ( *aasworld ).numclusters; i++ ) { + n = ( *aasworld ).clusters[i].numreachabilityareas; + numreachabilityareas += n; + total += n * n; + } + total += numreachabilityareas * ( *aasworld ).numportals; + // + botimport.Print( PRT_MESSAGE, "%6i total reachability areas\n", numreachabilityareas ); + botimport.Print( PRT_MESSAGE, "%6i AAS memory/CPU usage (the lower the better)\n", total * 3 ); +} //end of the function AAS_InitClustering diff --git a/Projects/Android/jni/rtcw/src/botlib/be_aas_cluster.h b/Projects/Android/jni/rtcw/src/botlib/be_aas_cluster.h new file mode 100644 index 0000000..6121cf3 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/botlib/be_aas_cluster.h @@ -0,0 +1,43 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +/***************************************************************************** + * name: be_aas_cluster.h + * + * desc: AAS + * + * + *****************************************************************************/ + +#ifdef AASINTERN +//initialize the AAS clustering +void AAS_InitClustering( void ); +void AAS_SetViewPortalsAsClusterPortals( void ); +#endif //AASINTERN + diff --git a/Projects/Android/jni/rtcw/src/botlib/be_aas_debug.c b/Projects/Android/jni/rtcw/src/botlib/be_aas_debug.c new file mode 100644 index 0000000..5ecd252 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/botlib/be_aas_debug.c @@ -0,0 +1,692 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +/***************************************************************************** + * name: be_aas_debug.c + * + * desc: AAS debug code + * + * + *****************************************************************************/ + +#include "../game/q_shared.h" +#include "l_memory.h" +#include "l_script.h" +#include "l_precomp.h" +#include "l_struct.h" +#include "l_libvar.h" +#include "aasfile.h" +#include "../game/botlib.h" +#include "../game/be_aas.h" +#include "be_interface.h" +#include "be_aas_funcs.h" +#include "be_aas_def.h" + +#define MAX_DEBUGLINES 1024 +#define MAX_DEBUGPOLYGONS 128 + +int debuglines[MAX_DEBUGLINES]; +int debuglinevisible[MAX_DEBUGLINES]; +int numdebuglines; + +static int debugpolygons[MAX_DEBUGPOLYGONS]; + +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_ClearShownPolygons( void ) { + int i; +//* + for ( i = 0; i < MAX_DEBUGPOLYGONS; i++ ) + { + if ( debugpolygons[i] ) { + botimport.DebugPolygonDelete( debugpolygons[i] ); + } + debugpolygons[i] = 0; + } //end for +//*/ +/* + for (i = 0; i < MAX_DEBUGPOLYGONS; i++) + { + botimport.DebugPolygonDelete(i); + debugpolygons[i] = 0; + } //end for +*/ +} //end of the function AAS_ClearShownPolygons +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_ShowPolygon( int color, int numpoints, vec3_t *points ) { + int i; + + for ( i = 0; i < MAX_DEBUGPOLYGONS; i++ ) + { + if ( !debugpolygons[i] ) { + debugpolygons[i] = botimport.DebugPolygonCreate( color, numpoints, points ); + break; + } //end if + } //end for +} //end of the function AAS_ShowPolygon +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_ClearShownDebugLines( void ) { + int i; + + //make all lines invisible + for ( i = 0; i < MAX_DEBUGLINES; i++ ) + { + if ( debuglines[i] ) { + //botimport.DebugLineShow(debuglines[i], NULL, NULL, LINECOLOR_NONE); + botimport.DebugLineDelete( debuglines[i] ); + debuglines[i] = 0; + debuglinevisible[i] = qfalse; + } //end if + } //end for +} //end of the function AAS_ClearShownDebugLines +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_DebugLine( vec3_t start, vec3_t end, int color ) { + int line; + + for ( line = 0; line < MAX_DEBUGLINES; line++ ) + { + if ( !debuglines[line] ) { + debuglines[line] = botimport.DebugLineCreate(); + debuglinevisible[line] = qfalse; + numdebuglines++; + } //end if + if ( !debuglinevisible[line] ) { + botimport.DebugLineShow( debuglines[line], start, end, color ); + debuglinevisible[line] = qtrue; + return; + } //end else + } //end for +} //end of the function AAS_DebugLine +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_PermanentLine( vec3_t start, vec3_t end, int color ) { + int line; + + line = botimport.DebugLineCreate(); + botimport.DebugLineShow( line, start, end, color ); +} //end of the function AAS_PermenentLine +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_DrawPermanentCross( vec3_t origin, float size, int color ) { + int i, debugline; + vec3_t start, end; + + for ( i = 0; i < 3; i++ ) + { + VectorCopy( origin, start ); + start[i] += size; + VectorCopy( origin, end ); + end[i] -= size; + AAS_DebugLine( start, end, color ); + debugline = botimport.DebugLineCreate(); + botimport.DebugLineShow( debugline, start, end, color ); + } //end for +} //end of the function AAS_DrawPermanentCross +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_DrawPlaneCross( vec3_t point, vec3_t normal, float dist, int type, int color ) { + int n0, n1, n2, j, line, lines[2]; + vec3_t start1, end1, start2, end2; + + //make a cross in the hit plane at the hit point + VectorCopy( point, start1 ); + VectorCopy( point, end1 ); + VectorCopy( point, start2 ); + VectorCopy( point, end2 ); + + n0 = type % 3; + n1 = ( type + 1 ) % 3; + n2 = ( type + 2 ) % 3; + start1[n1] -= 6; + start1[n2] -= 6; + end1[n1] += 6; + end1[n2] += 6; + start2[n1] += 6; + start2[n2] -= 6; + end2[n1] -= 6; + end2[n2] += 6; + + start1[n0] = ( dist - ( start1[n1] * normal[n1] + + start1[n2] * normal[n2] ) ) / normal[n0]; + end1[n0] = ( dist - ( end1[n1] * normal[n1] + + end1[n2] * normal[n2] ) ) / normal[n0]; + start2[n0] = ( dist - ( start2[n1] * normal[n1] + + start2[n2] * normal[n2] ) ) / normal[n0]; + end2[n0] = ( dist - ( end2[n1] * normal[n1] + + end2[n2] * normal[n2] ) ) / normal[n0]; + + for ( j = 0, line = 0; j < 2 && line < MAX_DEBUGLINES; line++ ) + { + if ( !debuglines[line] ) { + debuglines[line] = botimport.DebugLineCreate(); + lines[j++] = debuglines[line]; + debuglinevisible[line] = qtrue; + numdebuglines++; + } //end if + else if ( !debuglinevisible[line] ) { + lines[j++] = debuglines[line]; + debuglinevisible[line] = qtrue; + } //end else + } //end for + botimport.DebugLineShow( lines[0], start1, end1, color ); + botimport.DebugLineShow( lines[1], start2, end2, color ); +} //end of the function AAS_DrawPlaneCross +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_ShowBoundingBox( vec3_t origin, vec3_t mins, vec3_t maxs ) { + vec3_t bboxcorners[8]; + int lines[3]; + int i, j, line; + + //upper corners + bboxcorners[0][0] = origin[0] + maxs[0]; + bboxcorners[0][1] = origin[1] + maxs[1]; + bboxcorners[0][2] = origin[2] + maxs[2]; + // + bboxcorners[1][0] = origin[0] + mins[0]; + bboxcorners[1][1] = origin[1] + maxs[1]; + bboxcorners[1][2] = origin[2] + maxs[2]; + // + bboxcorners[2][0] = origin[0] + mins[0]; + bboxcorners[2][1] = origin[1] + mins[1]; + bboxcorners[2][2] = origin[2] + maxs[2]; + // + bboxcorners[3][0] = origin[0] + maxs[0]; + bboxcorners[3][1] = origin[1] + mins[1]; + bboxcorners[3][2] = origin[2] + maxs[2]; + //lower corners + memcpy( bboxcorners[4], bboxcorners[0], sizeof( vec3_t ) * 4 ); + for ( i = 0; i < 4; i++ ) bboxcorners[4 + i][2] = origin[2] + mins[2]; + //draw bounding box + for ( i = 0; i < 4; i++ ) + { + for ( j = 0, line = 0; j < 3 && line < MAX_DEBUGLINES; line++ ) + { + if ( !debuglines[line] ) { + debuglines[line] = botimport.DebugLineCreate(); + lines[j++] = debuglines[line]; + debuglinevisible[line] = qtrue; + numdebuglines++; + } //end if + else if ( !debuglinevisible[line] ) { + lines[j++] = debuglines[line]; + debuglinevisible[line] = qtrue; + } //end else + } //end for + //top plane + botimport.DebugLineShow( lines[0], bboxcorners[i], + bboxcorners[( i + 1 ) & 3], LINECOLOR_RED ); + //bottom plane + botimport.DebugLineShow( lines[1], bboxcorners[4 + i], + bboxcorners[4 + ( ( i + 1 ) & 3 )], LINECOLOR_RED ); + //vertical lines + botimport.DebugLineShow( lines[2], bboxcorners[i], + bboxcorners[4 + i], LINECOLOR_RED ); + } //end for +} //end of the function AAS_ShowBoundingBox +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_ShowFace( int facenum ) { + int i, color, edgenum; + aas_edge_t *edge; + aas_face_t *face; + aas_plane_t *plane; + vec3_t start, end; + + color = LINECOLOR_YELLOW; + //check if face number is in range + if ( facenum >= ( *aasworld ).numfaces ) { + botimport.Print( PRT_ERROR, "facenum %d out of range\n", facenum ); + } //end if + face = &( *aasworld ).faces[facenum]; + //walk through the edges of the face + for ( i = 0; i < face->numedges; i++ ) + { + //edge number + edgenum = abs( ( *aasworld ).edgeindex[face->firstedge + i] ); + //check if edge number is in range + if ( edgenum >= ( *aasworld ).numedges ) { + botimport.Print( PRT_ERROR, "edgenum %d out of range\n", edgenum ); + } //end if + edge = &( *aasworld ).edges[edgenum]; + if ( color == LINECOLOR_RED ) { + color = LINECOLOR_GREEN; + } else if ( color == LINECOLOR_GREEN ) { + color = LINECOLOR_BLUE; + } else if ( color == LINECOLOR_BLUE ) { + color = LINECOLOR_YELLOW; + } else { color = LINECOLOR_RED;} + AAS_DebugLine( ( *aasworld ).vertexes[edge->v[0]], + ( *aasworld ).vertexes[edge->v[1]], + color ); + } //end for + plane = &( *aasworld ).planes[face->planenum]; + edgenum = abs( ( *aasworld ).edgeindex[face->firstedge] ); + edge = &( *aasworld ).edges[edgenum]; + VectorCopy( ( *aasworld ).vertexes[edge->v[0]], start ); + VectorMA( start, 20, plane->normal, end ); + AAS_DebugLine( start, end, LINECOLOR_RED ); +} //end of the function AAS_ShowFace +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_ShowFacePolygon( int facenum, int color, int flip ) { + int i, edgenum, numpoints; + vec3_t points[128]; + aas_edge_t *edge; + aas_face_t *face; + + //check if face number is in range + if ( facenum >= ( *aasworld ).numfaces ) { + botimport.Print( PRT_ERROR, "facenum %d out of range\n", facenum ); + } //end if + face = &( *aasworld ).faces[facenum]; + //walk through the edges of the face + numpoints = 0; + if ( flip ) { + for ( i = face->numedges - 1; i >= 0; i-- ) + { + //edge number + edgenum = ( *aasworld ).edgeindex[face->firstedge + i]; + edge = &( *aasworld ).edges[abs( edgenum )]; + VectorCopy( ( *aasworld ).vertexes[edge->v[edgenum < 0]], points[numpoints] ); + numpoints++; + } //end for + } //end if + else + { + for ( i = 0; i < face->numedges; i++ ) + { + //edge number + edgenum = ( *aasworld ).edgeindex[face->firstedge + i]; + edge = &( *aasworld ).edges[abs( edgenum )]; + VectorCopy( ( *aasworld ).vertexes[edge->v[edgenum < 0]], points[numpoints] ); + numpoints++; + } //end for + } //end else + AAS_ShowPolygon( color, numpoints, points ); +} //end of the function AAS_ShowFacePolygon +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_ShowArea( int areanum, int groundfacesonly ) { + int areaedges[MAX_DEBUGLINES]; + int numareaedges, i, j, n, color = 0, line; + int facenum, edgenum; + aas_area_t *area; + aas_face_t *face; + aas_edge_t *edge; + + // + numareaedges = 0; + // + if ( areanum < 0 || areanum >= ( *aasworld ).numareas ) { + botimport.Print( PRT_ERROR, "area %d out of range [0, %d]\n", + areanum, ( *aasworld ).numareas ); + return; + } //end if + //pointer to the convex area + area = &( *aasworld ).areas[areanum]; + //walk through the faces of the area + for ( i = 0; i < area->numfaces; i++ ) + { + facenum = abs( ( *aasworld ).faceindex[area->firstface + i] ); + //check if face number is in range + if ( facenum >= ( *aasworld ).numfaces ) { + botimport.Print( PRT_ERROR, "facenum %d out of range\n", facenum ); + } //end if + face = &( *aasworld ).faces[facenum]; + //ground faces only + if ( groundfacesonly ) { + if ( !( face->faceflags & ( FACE_GROUND | FACE_LADDER ) ) ) { + continue; + } + } //end if + //walk through the edges of the face + for ( j = 0; j < face->numedges; j++ ) + { + //edge number + edgenum = abs( ( *aasworld ).edgeindex[face->firstedge + j] ); + //check if edge number is in range + if ( edgenum >= ( *aasworld ).numedges ) { + botimport.Print( PRT_ERROR, "edgenum %d out of range\n", edgenum ); + } //end if + //check if the edge is stored already + for ( n = 0; n < numareaedges; n++ ) + { + if ( areaedges[n] == edgenum ) { + break; + } + } //end for + if ( n == numareaedges && numareaedges < MAX_DEBUGLINES ) { + areaedges[numareaedges++] = edgenum; + } //end if + } //end for + //AAS_ShowFace(facenum); + } //end for + //draw all the edges + for ( n = 0; n < numareaedges; n++ ) + { + for ( line = 0; line < MAX_DEBUGLINES; line++ ) + { + if ( !debuglines[line] ) { + debuglines[line] = botimport.DebugLineCreate(); + debuglinevisible[line] = qfalse; + numdebuglines++; + } //end if + if ( !debuglinevisible[line] ) { + break; + } //end else + } //end for + if ( line >= MAX_DEBUGLINES ) { + return; + } + edge = &( *aasworld ).edges[areaedges[n]]; + if ( color == LINECOLOR_RED ) { + color = LINECOLOR_BLUE; + } else if ( color == LINECOLOR_BLUE ) { + color = LINECOLOR_GREEN; + } else if ( color == LINECOLOR_GREEN ) { + color = LINECOLOR_YELLOW; + } else { color = LINECOLOR_RED;} + botimport.DebugLineShow( debuglines[line], + ( *aasworld ).vertexes[edge->v[0]], + ( *aasworld ).vertexes[edge->v[1]], + color ); + debuglinevisible[line] = qtrue; + } //end for*/ +} //end of the function AAS_ShowArea +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_ShowAreaPolygons( int areanum, int color, int groundfacesonly ) { + int i, facenum; + aas_area_t *area; + aas_face_t *face; + + // + if ( areanum < 0 || areanum >= ( *aasworld ).numareas ) { + botimport.Print( PRT_ERROR, "area %d out of range [0, %d]\n", + areanum, ( *aasworld ).numareas ); + return; + } //end if + //pointer to the convex area + area = &( *aasworld ).areas[areanum]; + //walk through the faces of the area + for ( i = 0; i < area->numfaces; i++ ) + { + facenum = abs( ( *aasworld ).faceindex[area->firstface + i] ); + //check if face number is in range + if ( facenum >= ( *aasworld ).numfaces ) { + botimport.Print( PRT_ERROR, "facenum %d out of range\n", facenum ); + } //end if + face = &( *aasworld ).faces[facenum]; + //ground faces only + if ( groundfacesonly ) { + if ( !( face->faceflags & ( FACE_GROUND | FACE_LADDER ) ) ) { + continue; + } + } //end if + AAS_ShowFacePolygon( facenum, color, face->frontarea != areanum ); + } //end for +} //end of the function AAS_ShowAreaPolygons +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_DrawCross( vec3_t origin, float size, int color ) { + int i; + vec3_t start, end; + + for ( i = 0; i < 3; i++ ) + { + VectorCopy( origin, start ); + start[i] += size; + VectorCopy( origin, end ); + end[i] -= size; + AAS_DebugLine( start, end, color ); + } //end for +} //end of the function AAS_DrawCross +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_PrintTravelType( int traveltype ) { +#ifdef DEBUG + char *str; + // + switch ( traveltype ) + { + case TRAVEL_INVALID: str = "TRAVEL_INVALID"; break; + case TRAVEL_WALK: str = "TRAVEL_WALK"; break; + case TRAVEL_CROUCH: str = "TRAVEL_CROUCH"; break; + case TRAVEL_BARRIERJUMP: str = "TRAVEL_BARRIERJUMP"; break; + case TRAVEL_JUMP: str = "TRAVEL_JUMP"; break; + case TRAVEL_LADDER: str = "TRAVEL_LADDER"; break; + case TRAVEL_WALKOFFLEDGE: str = "TRAVEL_WALKOFFLEDGE"; break; + case TRAVEL_SWIM: str = "TRAVEL_SWIM"; break; + case TRAVEL_WATERJUMP: str = "TRAVEL_WATERJUMP"; break; + case TRAVEL_TELEPORT: str = "TRAVEL_TELEPORT"; break; + case TRAVEL_ELEVATOR: str = "TRAVEL_ELEVATOR"; break; + case TRAVEL_ROCKETJUMP: str = "TRAVEL_ROCKETJUMP"; break; + case TRAVEL_BFGJUMP: str = "TRAVEL_BFGJUMP"; break; + case TRAVEL_GRAPPLEHOOK: str = "TRAVEL_GRAPPLEHOOK"; break; + case TRAVEL_JUMPPAD: str = "TRAVEL_JUMPPAD"; break; + case TRAVEL_FUNCBOB: str = "TRAVEL_FUNCBOB"; break; + default: str = "UNKNOWN TRAVEL TYPE"; break; + } //end switch + botimport.Print( PRT_MESSAGE, "%s", str ); +#endif //DEBUG +} //end of the function AAS_PrintTravelType +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_DrawArrow( vec3_t start, vec3_t end, int linecolor, int arrowcolor ) { + vec3_t dir, cross, p1, p2, up = {0, 0, 1}; + float dot; + + VectorSubtract( end, start, dir ); + VectorNormalize( dir ); + dot = DotProduct( dir, up ); + if ( dot > 0.99 || dot < -0.99 ) { + VectorSet( cross, 1, 0, 0 ); + } else { CrossProduct( dir, up, cross );} + + VectorMA( end, -6, dir, p1 ); + VectorCopy( p1, p2 ); + VectorMA( p1, 6, cross, p1 ); + VectorMA( p2, -6, cross, p2 ); + + AAS_DebugLine( start, end, linecolor ); + AAS_DebugLine( p1, end, arrowcolor ); + AAS_DebugLine( p2, end, arrowcolor ); +} //end of the function AAS_DrawArrow +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_ShowReachability( aas_reachability_t *reach ) { + vec3_t dir, cmdmove, velocity; + float speed, zvel; + aas_clientmove_t move; + + AAS_ShowAreaPolygons( reach->areanum, 5, qtrue ); + //AAS_ShowArea(reach->areanum, qtrue); + AAS_DrawArrow( reach->start, reach->end, LINECOLOR_BLUE, LINECOLOR_YELLOW ); + // + if ( reach->traveltype == TRAVEL_JUMP || reach->traveltype == TRAVEL_WALKOFFLEDGE ) { + AAS_HorizontalVelocityForJump( aassettings.sv_jumpvel, reach->start, reach->end, &speed ); + // + VectorSubtract( reach->end, reach->start, dir ); + dir[2] = 0; + VectorNormalize( dir ); + //set the velocity + VectorScale( dir, speed, velocity ); + //set the command movement + VectorClear( cmdmove ); + cmdmove[2] = aassettings.sv_jumpvel; + // + AAS_PredictClientMovement( &move, -1, reach->start, PRESENCE_NORMAL, qtrue, + velocity, cmdmove, 3, 30, 0.1, + SE_HITGROUND | SE_ENTERWATER | SE_ENTERSLIME | + SE_ENTERLAVA | SE_HITGROUNDDAMAGE, 0, qtrue ); + // + if ( reach->traveltype == TRAVEL_JUMP ) { + AAS_JumpReachRunStart( reach, dir ); + AAS_DrawCross( dir, 4, LINECOLOR_BLUE ); + } //end if + } //end if + else if ( reach->traveltype == TRAVEL_ROCKETJUMP ) { + zvel = AAS_RocketJumpZVelocity( reach->start ); + AAS_HorizontalVelocityForJump( zvel, reach->start, reach->end, &speed ); + // + VectorSubtract( reach->end, reach->start, dir ); + dir[2] = 0; + VectorNormalize( dir ); + //get command movement + VectorScale( dir, speed, cmdmove ); + VectorSet( velocity, 0, 0, zvel ); + // + AAS_PredictClientMovement( &move, -1, reach->start, PRESENCE_NORMAL, qtrue, + velocity, cmdmove, 30, 30, 0.1, + SE_ENTERWATER | SE_ENTERSLIME | + SE_ENTERLAVA | SE_HITGROUNDDAMAGE | + SE_TOUCHJUMPPAD | SE_HITGROUNDAREA, reach->areanum, qtrue ); + } //end else if + else if ( reach->traveltype == TRAVEL_JUMPPAD ) { + VectorSet( cmdmove, 0, 0, 0 ); + // + VectorSubtract( reach->end, reach->start, dir ); + dir[2] = 0; + VectorNormalize( dir ); + //set the velocity + //NOTE: the edgenum is the horizontal velocity + VectorScale( dir, reach->edgenum, velocity ); + //NOTE: the facenum is the Z velocity + velocity[2] = reach->facenum; + // + AAS_PredictClientMovement( &move, -1, reach->start, PRESENCE_NORMAL, qtrue, + velocity, cmdmove, 30, 30, 0.1, + SE_ENTERWATER | SE_ENTERSLIME | + SE_ENTERLAVA | SE_HITGROUNDDAMAGE | + SE_TOUCHJUMPPAD | SE_HITGROUNDAREA, reach->areanum, qtrue ); + } //end else if +} //end of the function AAS_ShowReachability +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_ShowReachableAreas( int areanum ) { + aas_areasettings_t *settings; + static aas_reachability_t reach; + static int index, lastareanum; + static float lasttime; + + if ( areanum != lastareanum ) { + index = 0; + lastareanum = areanum; + } //end if + settings = &( *aasworld ).areasettings[areanum]; + // + if ( !settings->numreachableareas ) { + return; + } + // + if ( index >= settings->numreachableareas ) { + index = 0; + } + // + if ( AAS_Time() - lasttime > 1.5 ) { + memcpy( &reach, &( *aasworld ).reachability[settings->firstreachablearea + index], sizeof( aas_reachability_t ) ); + index++; + lasttime = AAS_Time(); + AAS_PrintTravelType( reach.traveltype ); + botimport.Print( PRT_MESSAGE, "(traveltime: %i)\n", reach.traveltime ); + } //end if + AAS_ShowReachability( &reach ); +} //end of the function ShowReachableAreas diff --git a/Projects/Android/jni/rtcw/src/botlib/be_aas_debug.h b/Projects/Android/jni/rtcw/src/botlib/be_aas_debug.h new file mode 100644 index 0000000..cf23fff --- /dev/null +++ b/Projects/Android/jni/rtcw/src/botlib/be_aas_debug.h @@ -0,0 +1,68 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +/***************************************************************************** + * name: be_aas_debug.h + * + * desc: AAS + * + * + *****************************************************************************/ + +//clear the shown debug lines +void AAS_ClearShownDebugLines( void ); +// +void AAS_ClearShownPolygons( void ); +//show a debug line +void AAS_DebugLine( vec3_t start, vec3_t end, int color ); +//show a permenent line +void AAS_PermanentLine( vec3_t start, vec3_t end, int color ); +//show a permanent cross +void AAS_DrawPermanentCross( vec3_t origin, float size, int color ); +//draw a cross in the plane +void AAS_DrawPlaneCross( vec3_t point, vec3_t normal, float dist, int type, int color ); +//show a bounding box +void AAS_ShowBoundingBox( vec3_t origin, vec3_t mins, vec3_t maxs ); +//show a face +void AAS_ShowFace( int facenum ); +//show an area +void AAS_ShowArea( int areanum, int groundfacesonly ); +// +void AAS_ShowAreaPolygons( int areanum, int color, int groundfacesonly ); +//draw a cros +void AAS_DrawCross( vec3_t origin, float size, int color ); +//print the travel type +void AAS_PrintTravelType( int traveltype ); +//draw an arrow +void AAS_DrawArrow( vec3_t start, vec3_t end, int linecolor, int arrowcolor ); +//visualize the given reachability +void AAS_ShowReachability( struct aas_reachability_s *reach ); +//show the reachable areas from the given area +void AAS_ShowReachableAreas( int areanum ); + diff --git a/Projects/Android/jni/rtcw/src/botlib/be_aas_def.h b/Projects/Android/jni/rtcw/src/botlib/be_aas_def.h new file mode 100644 index 0000000..4404d9b --- /dev/null +++ b/Projects/Android/jni/rtcw/src/botlib/be_aas_def.h @@ -0,0 +1,295 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +/***************************************************************************** + * name: be_aas_def.h + * + * desc: AAS + * + * + *****************************************************************************/ + +//debugging on +#define AAS_DEBUG + +//#define MAX_CLIENTS 128 +//#define MAX_MODELS 256 // these are sent over the net as 8 bits +//#define MAX_SOUNDS 256 // so they cannot be blindly increased +//#define MAX_CONFIGSTRINGS 1024 +#define MAX_CONFIGSTRINGS 2048 //----(SA) upped + +//#define CS_SCORES 32 +//#define CS_MODELS (CS_SCORES+MAX_CLIENTS) +//#define CS_SOUNDS (CS_MODELS+MAX_MODELS) + +#define DF_AASENTNUMBER( x ) ( x - ( *aasworlds ).entities ) +#define DF_NUMBERAASENT( x ) ( &( *aasworlds ).entities[x] ) +#define DF_AASENTCLIENT( x ) ( x - ( *aasworlds ).entities - 1 ) +#define DF_CLIENTAASENT( x ) ( &( *aasworlds ).entities[x + 1] ) + +#ifndef MAX_PATH + #define MAX_PATH MAX_QPATH +#endif + +//string index (for model, sound and image index) +typedef struct aas_stringindex_s +{ + int numindexes; + char **index; +} aas_stringindex_t; + +//structure to link entities to areas and areas to entities +typedef struct aas_link_s +{ + int entnum; + int areanum; + struct aas_link_s *next_ent, *prev_ent; + struct aas_link_s *next_area, *prev_area; +} aas_link_t; + +//structure to link entities to leaves and leaves to entities +typedef struct bsp_link_s +{ + int entnum; + int leafnum; + struct bsp_link_s *next_ent, *prev_ent; + struct bsp_link_s *next_leaf, *prev_leaf; +} bsp_link_t; + +typedef struct bsp_entdata_s +{ + vec3_t origin; + vec3_t angles; + vec3_t absmins; + vec3_t absmaxs; + int solid; + int modelnum; +} bsp_entdata_t; + +//entity +typedef struct aas_entity_s +{ + //entity info + aas_entityinfo_t i; + //links into the AAS areas + aas_link_t *areas; + //links into the BSP leaves + bsp_link_t *leaves; +} aas_entity_t; + +typedef struct aas_settings_s +{ + float sv_friction; + float sv_stopspeed; + float sv_gravity; + float sv_waterfriction; + float sv_watergravity; + float sv_maxvelocity; + float sv_maxwalkvelocity; + float sv_maxcrouchvelocity; + float sv_maxswimvelocity; + float sv_walkaccelerate; + float sv_airaccelerate; + float sv_swimaccelerate; + float sv_maxstep; + float sv_maxsteepness; + float sv_maxwaterjump; + float sv_maxbarrier; + float sv_jumpvel; + qboolean sv_allowladders; +} aas_settings_t; + +//routing cache +typedef struct aas_routingcache_s +{ + int size; //size of the routing cache + float time; //last time accessed or updated + int cluster; //cluster the cache is for + int areanum; //area the cache is created for + vec3_t origin; //origin within the area + float starttraveltime; //travel time to start with + int travelflags; //combinations of the travel flags + struct aas_routingcache_s *prev, *next; + unsigned char *reachabilities; //reachabilities used for routing + unsigned short int traveltimes[1]; //travel time for every area (variable sized) +} aas_routingcache_t; + +//fields for the routing algorithm +typedef struct aas_routingupdate_s +{ + int cluster; + int areanum; //area number of the update + vec3_t start; //start point the area was entered + unsigned short int tmptraveltime; //temporary travel time + unsigned short int *areatraveltimes; //travel times within the area + qboolean inlist; //true if the update is in the list + struct aas_routingupdate_s *next; + struct aas_routingupdate_s *prev; +} aas_routingupdate_t; + +//reversed reachability link +typedef struct aas_reversedlink_s +{ + int linknum; //the aas_areareachability_t + int areanum; //reachable from this area + struct aas_reversedlink_s *next; //next link +} aas_reversedlink_t; + +//reversed area reachability +typedef struct aas_reversedreachability_s +{ + int numlinks; + aas_reversedlink_t *first; +} aas_reversedreachability_t; + +// Ridah, route-tables +#include "be_aas_routetable.h" +// done. + +typedef struct aas_s +{ + int loaded; //true when an AAS file is loaded + int initialized; //true when AAS has been initialized + int savefile; //set true when file should be saved + int bspchecksum; + //current time + float time; + int numframes; + //name of the aas file + char filename[MAX_PATH]; + char mapname[MAX_PATH]; + //bounding boxes + int numbboxes; + aas_bbox_t *bboxes; + //vertexes + int numvertexes; + aas_vertex_t *vertexes; + //planes + int numplanes; + aas_plane_t *planes; + //edges + int numedges; + aas_edge_t *edges; + //edge index + int edgeindexsize; + aas_edgeindex_t *edgeindex; + //faces + int numfaces; + aas_face_t *faces; + //face index + int faceindexsize; + aas_faceindex_t *faceindex; + //convex areas + int numareas; + aas_area_t *areas; + //convex area settings + int numareasettings; + aas_areasettings_t *areasettings; + //reachablity list + int reachabilitysize; + aas_reachability_t *reachability; + //nodes of the bsp tree + int numnodes; + aas_node_t *nodes; + //cluster portals + int numportals; + aas_portal_t *portals; + //cluster portal index + int portalindexsize; + aas_portalindex_t *portalindex; + //clusters + int numclusters; + aas_cluster_t *clusters; + // + int reachabilityareas; + float reachabilitytime; + //enities linked in the areas + aas_link_t *linkheap; //heap with link structures + int linkheapsize; //size of the link heap + aas_link_t *freelinks; //first free link + aas_link_t **arealinkedentities; //entities linked into areas + //entities + int maxentities; + int maxclients; + aas_entity_t *entities; + //string indexes + char *configstrings[MAX_CONFIGSTRINGS]; + int indexessetup; + //index to retrieve travel flag for a travel type + int travelflagfortype[MAX_TRAVELTYPES]; + //routing update + aas_routingupdate_t *areaupdate; + aas_routingupdate_t *portalupdate; + //number of routing updates during a frame (reset every frame) + int frameroutingupdates; + //reversed reachability links + aas_reversedreachability_t *reversedreachability; + //travel times within the areas + unsigned short ***areatraveltimes; + //array of size numclusters with cluster cache + aas_routingcache_t ***clusterareacache; + aas_routingcache_t **portalcache; + //maximum travel time through portals + int *portalmaxtraveltimes; + // Ridah, pointer to Route-Table information + aas_rt_t *routetable; + //hide travel times + unsigned short int *hidetraveltimes; + //vis data + byte *decompressedvis; + int decompressedvisarea; + byte **areavisibility; + // done. + // Ridah, store the area's waypoint for hidepos calculations (center traced downwards) + vec3_t *areawaypoints; + // Ridah, so we can cache the areas that have already been tested for visibility/attackability + byte *visCache; +} aas_t; + +#define AASINTERN + +#ifndef BSPCINCLUDE + +#include "be_aas_main.h" +#include "be_aas_entity.h" +#include "be_aas_sample.h" +#include "be_aas_cluster.h" +#include "be_aas_reach.h" +#include "be_aas_route.h" +#include "be_aas_routealt.h" +#include "be_aas_debug.h" +#include "be_aas_file.h" +#include "be_aas_optimize.h" +#include "be_aas_bsp.h" +#include "be_aas_move.h" + +// Ridah, route-tables +#include "be_aas_routetable.h" + +#endif //BSPCINCLUDE diff --git a/Projects/Android/jni/rtcw/src/botlib/be_aas_entity.c b/Projects/Android/jni/rtcw/src/botlib/be_aas_entity.c new file mode 100644 index 0000000..340cee5 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/botlib/be_aas_entity.c @@ -0,0 +1,499 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +/***************************************************************************** + * name: be_aas_entity.c + * + * desc: AAS entities + * + * + *****************************************************************************/ + +#include "../game/q_shared.h" +#include "l_memory.h" +#include "l_script.h" +#include "l_precomp.h" +#include "l_struct.h" +#include "l_utils.h" +#include "l_log.h" +#include "aasfile.h" +#include "../game/botlib.h" +#include "../game/be_aas.h" +#include "be_aas_funcs.h" +#include "be_interface.h" +#include "be_aas_def.h" + +#define MASK_SOLID CONTENTS_PLAYERCLIP + +// Ridah, always use the default world for entities +extern aas_t aasworlds[MAX_AAS_WORLDS]; + +aas_t *defaultaasworld = aasworlds; + +//FIXME: these might change +enum { + ET_GENERAL, + ET_PLAYER, + ET_ITEM, + ET_MISSILE, + ET_MOVER +}; + +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_UpdateEntity( int entnum, bot_entitystate_t *state ) { + int relink; + aas_entity_t *ent; + vec3_t absmins, absmaxs; + + if ( !( *defaultaasworld ).loaded ) { + botimport.Print( PRT_MESSAGE, "AAS_UpdateEntity: not loaded\n" ); + return BLERR_NOAASFILE; + } //end if + + ent = &( *defaultaasworld ).entities[entnum]; + + ent->i.update_time = AAS_Time() - ent->i.ltime; + ent->i.type = state->type; + ent->i.flags = state->flags; + ent->i.ltime = AAS_Time(); + VectorCopy( ent->i.origin, ent->i.lastvisorigin ); + VectorCopy( state->old_origin, ent->i.old_origin ); + ent->i.solid = state->solid; + ent->i.groundent = state->groundent; + ent->i.modelindex = state->modelindex; + ent->i.modelindex2 = state->modelindex2; + ent->i.frame = state->frame; + //ent->i.event = state->event; + ent->i.eventParm = state->eventParm; + ent->i.powerups = state->powerups; + ent->i.weapon = state->weapon; + ent->i.legsAnim = state->legsAnim; + ent->i.torsoAnim = state->torsoAnim; + +// ent->i.weapAnim = state->weapAnim; //----(SA) +//----(SA) didn't want to comment in as I wasn't sure of any implications of changing the aas_entityinfo_t and bot_entitystate_t structures. + + //number of the entity + ent->i.number = entnum; + //updated so set valid flag + ent->i.valid = qtrue; + //link everything the first frame + + if ( ( *defaultaasworld ).numframes == 1 ) { + relink = qtrue; + } else { relink = qfalse;} + + // + if ( ent->i.solid == SOLID_BSP ) { + //if the angles of the model changed + if ( !VectorCompare( state->angles, ent->i.angles ) ) { + VectorCopy( state->angles, ent->i.angles ); + relink = qtrue; + } //end if + //get the mins and maxs of the model + //FIXME: rotate mins and maxs + AAS_BSPModelMinsMaxsOrigin( ent->i.modelindex, ent->i.angles, ent->i.mins, ent->i.maxs, NULL ); + } //end if + else if ( ent->i.solid == SOLID_BBOX ) { + //if the bounding box size changed + if ( !VectorCompare( state->mins, ent->i.mins ) || + !VectorCompare( state->maxs, ent->i.maxs ) ) { + VectorCopy( state->mins, ent->i.mins ); + VectorCopy( state->maxs, ent->i.maxs ); + relink = qtrue; + } //end if + } //end if + //if the origin changed + if ( !VectorCompare( state->origin, ent->i.origin ) ) { + VectorCopy( state->origin, ent->i.origin ); + relink = qtrue; + } //end if + //if the entity should be relinked + if ( relink ) { + //don't link the world model + if ( entnum != ENTITYNUM_WORLD ) { + //absolute mins and maxs + VectorAdd( ent->i.mins, ent->i.origin, absmins ); + VectorAdd( ent->i.maxs, ent->i.origin, absmaxs ); + + //unlink the entity + AAS_UnlinkFromAreas( ent->areas ); + //relink the entity to the AAS areas (use the larges bbox) + ent->areas = AAS_LinkEntityClientBBox( absmins, absmaxs, entnum, PRESENCE_NORMAL ); + //unlink the entity from the BSP leaves + AAS_UnlinkFromBSPLeaves( ent->leaves ); + //link the entity to the world BSP tree + ent->leaves = AAS_BSPLinkEntity( absmins, absmaxs, entnum, 0 ); + } //end if + } //end if + return BLERR_NOERROR; +} //end of the function AAS_UpdateEntity +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_EntityInfo( int entnum, aas_entityinfo_t *info ) { + if ( !( *defaultaasworld ).initialized ) { + botimport.Print( PRT_FATAL, "AAS_EntityInfo: (*defaultaasworld) not initialized\n" ); + memset( info, 0, sizeof( aas_entityinfo_t ) ); + return; + } //end if + + if ( entnum < 0 || entnum >= ( *defaultaasworld ).maxentities ) { + botimport.Print( PRT_FATAL, "AAS_EntityInfo: entnum %d out of range\n", entnum ); + memset( info, 0, sizeof( aas_entityinfo_t ) ); + return; + } //end if + + memcpy( info, &( *defaultaasworld ).entities[entnum].i, sizeof( aas_entityinfo_t ) ); +} //end of the function AAS_EntityInfo +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_EntityOrigin( int entnum, vec3_t origin ) { + if ( entnum < 0 || entnum >= ( *defaultaasworld ).maxentities ) { + botimport.Print( PRT_FATAL, "AAS_EntityOrigin: entnum %d out of range\n", entnum ); + VectorClear( origin ); + return; + } //end if + + VectorCopy( ( *defaultaasworld ).entities[entnum].i.origin, origin ); +} //end of the function AAS_EntityOrigin +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_EntityModelindex( int entnum ) { + if ( entnum < 0 || entnum >= ( *defaultaasworld ).maxentities ) { + botimport.Print( PRT_FATAL, "AAS_EntityModelindex: entnum %d out of range\n", entnum ); + return 0; + } //end if + return ( *defaultaasworld ).entities[entnum].i.modelindex; +} //end of the function AAS_EntityModelindex +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_EntityType( int entnum ) { + if ( !( *defaultaasworld ).initialized ) { + return 0; + } + + if ( entnum < 0 || entnum >= ( *defaultaasworld ).maxentities ) { + botimport.Print( PRT_FATAL, "AAS_EntityType: entnum %d out of range\n", entnum ); + return 0; + } //end if + return ( *defaultaasworld ).entities[entnum].i.type; +} //end of the AAS_EntityType +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_EntityModelNum( int entnum ) { + if ( !( *defaultaasworld ).initialized ) { + return 0; + } + + if ( entnum < 0 || entnum >= ( *defaultaasworld ).maxentities ) { + botimport.Print( PRT_FATAL, "AAS_EntityModelNum: entnum %d out of range\n", entnum ); + return 0; + } //end if + return ( *defaultaasworld ).entities[entnum].i.modelindex; +} //end of the function AAS_EntityModelNum +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_OriginOfEntityWithModelNum( int modelnum, vec3_t origin ) { + int i; + aas_entity_t *ent; + + for ( i = 0; i < ( *defaultaasworld ).maxentities; i++ ) + { + ent = &( *defaultaasworld ).entities[i]; + if ( ent->i.type == ET_MOVER ) { + if ( ent->i.modelindex == modelnum ) { + VectorCopy( ent->i.origin, origin ); + return qtrue; + } //end if + } + } //end for + return qfalse; +} //end of the function AAS_OriginOfEntityWithModelNum +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_EntitySize( int entnum, vec3_t mins, vec3_t maxs ) { + aas_entity_t *ent; + + if ( !( *defaultaasworld ).initialized ) { + return; + } + + if ( entnum < 0 || entnum >= ( *defaultaasworld ).maxentities ) { + botimport.Print( PRT_FATAL, "AAS_EntitySize: entnum %d out of range\n", entnum ); + return; + } //end if + + ent = &( *defaultaasworld ).entities[entnum]; + VectorCopy( ent->i.mins, mins ); + VectorCopy( ent->i.maxs, maxs ); +} //end of the function AAS_EntitySize +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_EntityBSPData( int entnum, bsp_entdata_t *entdata ) { + aas_entity_t *ent; + + ent = &( *defaultaasworld ).entities[entnum]; + VectorCopy( ent->i.origin, entdata->origin ); + VectorCopy( ent->i.angles, entdata->angles ); + VectorAdd( ent->i.origin, ent->i.mins, entdata->absmins ); + VectorAdd( ent->i.origin, ent->i.maxs, entdata->absmaxs ); + entdata->solid = ent->i.solid; + entdata->modelnum = ent->i.modelindex - 1; +} //end of the function AAS_EntityBSPData +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_ResetEntityLinks( void ) { + int i; + for ( i = 0; i < ( *defaultaasworld ).maxentities; i++ ) + { + ( *defaultaasworld ).entities[i].areas = NULL; + ( *defaultaasworld ).entities[i].leaves = NULL; + } //end for +} //end of the function AAS_ResetEntityLinks +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_InvalidateEntities( void ) { + int i; + for ( i = 0; i < ( *defaultaasworld ).maxentities; i++ ) + { + ( *defaultaasworld ).entities[i].i.valid = qfalse; + ( *defaultaasworld ).entities[i].i.number = i; + } //end for +} //end of the function AAS_InvalidateEntities +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_NearestEntity( vec3_t origin, int modelindex ) { + int i, bestentnum; + float dist, bestdist; + aas_entity_t *ent; + vec3_t dir; + + bestentnum = 0; + bestdist = 99999; + for ( i = 0; i < ( *defaultaasworld ).maxentities; i++ ) + { + ent = &( *defaultaasworld ).entities[i]; + if ( ent->i.modelindex != modelindex ) { + continue; + } + VectorSubtract( ent->i.origin, origin, dir ); + if ( abs( dir[0] ) < 40 ) { + if ( abs( dir[1] ) < 40 ) { + dist = VectorLength( dir ); + if ( dist < bestdist ) { + bestdist = dist; + bestentnum = i; + } //end if + } //end if + } //end if + } //end for + return bestentnum; +} //end of the function AAS_NearestEntity +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_BestReachableEntityArea( int entnum ) { + aas_entity_t *ent; + + ent = &( *defaultaasworld ).entities[entnum]; + return AAS_BestReachableLinkArea( ent->areas ); +} //end of the function AAS_BestReachableEntityArea +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_NextEntity( int entnum ) { + if ( !( *defaultaasworld ).loaded ) { + return 0; + } + + if ( entnum < 0 ) { + entnum = -1; + } + while ( ++entnum < ( *defaultaasworld ).maxentities ) + { + if ( ( *defaultaasworld ).entities[entnum].i.valid ) { + return entnum; + } + } //end while + return 0; +} //end of the function AAS_NextEntity + +// Ridah, used to find out if there is an entity touching the given area, if so, try and avoid it +/* +============ +AAS_EntityInArea +============ +*/ +int AAS_IsEntityInArea( int entnumIgnore, int entnumIgnore2, int areanum ) { + aas_link_t *link; + aas_entity_t *ent; +// int i; + + // RF, not functional (doesnt work with multiple areas) + return qfalse; + + for ( link = ( *aasworld ).arealinkedentities[areanum]; link; link = link->next_ent ) + { + //ignore the pass entity + if ( link->entnum == entnumIgnore ) { + continue; + } + if ( link->entnum == entnumIgnore2 ) { + continue; + } + // + ent = &( *defaultaasworld ).entities[link->entnum]; + if ( !ent->i.valid ) { + continue; + } + if ( !ent->i.solid ) { + continue; + } + return qtrue; + } +/* + ent = (*defaultaasworld).entities; + for (i = 0; i < (*defaultaasworld).maxclients; i++, ent++) + { + if (!ent->i.valid) + continue; + if (!ent->i.solid) + continue; + if (i == entnumIgnore) + continue; + if (i == entnumIgnore2) + continue; + for (link = ent->areas; link; link = link->next_area) + { + if (link->areanum == areanum) + { + return qtrue; + } //end if + } //end for + } +*/ + return qfalse; +} + +/* +============= +AAS_SetAASBlockingEntity +============= +*/ +int AAS_EnableRoutingArea( int areanum, int enable ); +void AAS_SetAASBlockingEntity( vec3_t absmin, vec3_t absmax, qboolean blocking ) { + int areas[128]; + int numareas, i, w; + // + // check for resetting AAS blocking + if ( VectorCompare( absmin, absmax ) && blocking < 0 ) { + for ( w = 0; w < MAX_AAS_WORLDS; w++ ) { + AAS_SetCurrentWorld( w ); + // + if ( !( *aasworld ).loaded ) { + continue; + } + // now clear blocking status + for ( i = 1; i < ( *aasworld ).numareas; i++ ) { + AAS_EnableRoutingArea( i, qtrue ); + } + } + // + return; + } + // + for ( w = 0; w < MAX_AAS_WORLDS; w++ ) { + AAS_SetCurrentWorld( w ); + // + if ( !( *aasworld ).loaded ) { + continue; + } + // grab the list of areas + numareas = AAS_BBoxAreas( absmin, absmax, areas, 128 ); + // now set their blocking status + for ( i = 0; i < numareas; i++ ) { + AAS_EnableRoutingArea( areas[i], !blocking ); + } + } +} diff --git a/Projects/Android/jni/rtcw/src/botlib/be_aas_entity.h b/Projects/Android/jni/rtcw/src/botlib/be_aas_entity.h new file mode 100644 index 0000000..686e4f1 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/botlib/be_aas_entity.h @@ -0,0 +1,68 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +/***************************************************************************** + * name: be_aas_entity.h + * + * desc: AAS + * + * + *****************************************************************************/ + +#ifdef AASINTERN +//invalidates all entity infos +void AAS_InvalidateEntities( void ); +//resets the entity AAS and BSP links (sets areas and leaves pointers to NULL) +void AAS_ResetEntityLinks( void ); +//updates an entity +int AAS_UpdateEntity( int ent, bot_entitystate_t *state ); +//gives the entity data used for collision detection +void AAS_EntityBSPData( int entnum, bsp_entdata_t *entdata ); +#endif //AASINTERN + +//returns the size of the entity bounding box in mins and maxs +void AAS_EntitySize( int entnum, vec3_t mins, vec3_t maxs ); +//returns the BSP model number of the entity +int AAS_EntityModelNum( int entnum ); +//returns the origin of an entity with the given model number +int AAS_OriginOfEntityWithModelNum( int modelnum, vec3_t origin ); +//returns the best reachable area the entity is situated in +int AAS_BestReachableEntityArea( int entnum ); +//returns the info of the given entity +void AAS_EntityInfo( int entnum, aas_entityinfo_t *info ); +//returns the next entity +int AAS_NextEntity( int entnum ); +//returns the origin of the entity +void AAS_EntityOrigin( int entnum, vec3_t origin ); +//returns the entity type +int AAS_EntityType( int entnum ); +//returns the model index of the entity +int AAS_EntityModelindex( int entnum ); +// Ridah +int AAS_IsEntityInArea( int entnumIgnore, int entnumIgnore2, int areanum ); diff --git a/Projects/Android/jni/rtcw/src/botlib/be_aas_file.c b/Projects/Android/jni/rtcw/src/botlib/be_aas_file.c new file mode 100644 index 0000000..cc8d26e --- /dev/null +++ b/Projects/Android/jni/rtcw/src/botlib/be_aas_file.c @@ -0,0 +1,662 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +/***************************************************************************** + * name: be_aas_file.c + * + * desc: AAS file loading/writing + * + * + *****************************************************************************/ + +#include "../game/q_shared.h" +#include "l_memory.h" +#include "l_script.h" +#include "l_precomp.h" +#include "l_struct.h" +#include "l_libvar.h" +#include "l_utils.h" +#include "aasfile.h" +#include "../game/botlib.h" +#include "../game/be_aas.h" +#include "be_aas_funcs.h" +#include "be_interface.h" +#include "be_aas_def.h" + +//#define AASFILEDEBUG + +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_SwapAASData( void ) { + int i, j; + + // Ridah, no need to do anything if this OS doesn't need byte swapping + if ( LittleLong( 1 ) == 1 ) { + return; + } + // done. + + //bounding boxes + for ( i = 0; i < ( *aasworld ).numbboxes; i++ ) + { + ( *aasworld ).bboxes[i].presencetype = LittleLong( ( *aasworld ).bboxes[i].presencetype ); + ( *aasworld ).bboxes[i].flags = LittleLong( ( *aasworld ).bboxes[i].flags ); + for ( j = 0; j < 3; j++ ) + { + ( *aasworld ).bboxes[i].mins[j] = LittleFloat( ( *aasworld ).bboxes[i].mins[j] ); + ( *aasworld ).bboxes[i].maxs[j] = LittleFloat( ( *aasworld ).bboxes[i].maxs[j] ); + } //end for + } //end for + //vertexes + for ( i = 0; i < ( *aasworld ).numvertexes; i++ ) + { + for ( j = 0; j < 3; j++ ) + ( *aasworld ).vertexes[i][j] = LittleFloat( ( *aasworld ).vertexes[i][j] ); + } //end for + //planes + for ( i = 0; i < ( *aasworld ).numplanes; i++ ) + { + for ( j = 0; j < 3; j++ ) + ( *aasworld ).planes[i].normal[j] = LittleFloat( ( *aasworld ).planes[i].normal[j] ); + ( *aasworld ).planes[i].dist = LittleFloat( ( *aasworld ).planes[i].dist ); + ( *aasworld ).planes[i].type = LittleLong( ( *aasworld ).planes[i].type ); + } //end for + //edges + for ( i = 0; i < ( *aasworld ).numedges; i++ ) + { + ( *aasworld ).edges[i].v[0] = LittleLong( ( *aasworld ).edges[i].v[0] ); + ( *aasworld ).edges[i].v[1] = LittleLong( ( *aasworld ).edges[i].v[1] ); + } //end for + //edgeindex + for ( i = 0; i < ( *aasworld ).edgeindexsize; i++ ) + { + ( *aasworld ).edgeindex[i] = LittleLong( ( *aasworld ).edgeindex[i] ); + } //end for + //faces + for ( i = 0; i < ( *aasworld ).numfaces; i++ ) + { + ( *aasworld ).faces[i].planenum = LittleLong( ( *aasworld ).faces[i].planenum ); + ( *aasworld ).faces[i].faceflags = LittleLong( ( *aasworld ).faces[i].faceflags ); + ( *aasworld ).faces[i].numedges = LittleLong( ( *aasworld ).faces[i].numedges ); + ( *aasworld ).faces[i].firstedge = LittleLong( ( *aasworld ).faces[i].firstedge ); + ( *aasworld ).faces[i].frontarea = LittleLong( ( *aasworld ).faces[i].frontarea ); + ( *aasworld ).faces[i].backarea = LittleLong( ( *aasworld ).faces[i].backarea ); + } //end for + //face index + for ( i = 0; i < ( *aasworld ).faceindexsize; i++ ) + { + ( *aasworld ).faceindex[i] = LittleLong( ( *aasworld ).faceindex[i] ); + } //end for + //convex areas + for ( i = 0; i < ( *aasworld ).numareas; i++ ) + { + ( *aasworld ).areas[i].areanum = LittleLong( ( *aasworld ).areas[i].areanum ); + ( *aasworld ).areas[i].numfaces = LittleLong( ( *aasworld ).areas[i].numfaces ); + ( *aasworld ).areas[i].firstface = LittleLong( ( *aasworld ).areas[i].firstface ); + for ( j = 0; j < 3; j++ ) + { + ( *aasworld ).areas[i].mins[j] = LittleFloat( ( *aasworld ).areas[i].mins[j] ); + ( *aasworld ).areas[i].maxs[j] = LittleFloat( ( *aasworld ).areas[i].maxs[j] ); + ( *aasworld ).areas[i].center[j] = LittleFloat( ( *aasworld ).areas[i].center[j] ); + } //end for + } //end for + //area settings + for ( i = 0; i < ( *aasworld ).numareasettings; i++ ) + { + ( *aasworld ).areasettings[i].contents = LittleLong( ( *aasworld ).areasettings[i].contents ); + ( *aasworld ).areasettings[i].areaflags = LittleLong( ( *aasworld ).areasettings[i].areaflags ); + ( *aasworld ).areasettings[i].presencetype = LittleLong( ( *aasworld ).areasettings[i].presencetype ); + ( *aasworld ).areasettings[i].cluster = LittleLong( ( *aasworld ).areasettings[i].cluster ); + ( *aasworld ).areasettings[i].clusterareanum = LittleLong( ( *aasworld ).areasettings[i].clusterareanum ); + ( *aasworld ).areasettings[i].numreachableareas = LittleLong( ( *aasworld ).areasettings[i].numreachableareas ); + ( *aasworld ).areasettings[i].firstreachablearea = LittleLong( ( *aasworld ).areasettings[i].firstreachablearea ); + ( *aasworld ).areasettings[i].groundsteepness = LittleLong( ( *aasworld ).areasettings[i].groundsteepness ); + } //end for + //area reachability + for ( i = 0; i < ( *aasworld ).reachabilitysize; i++ ) + { + ( *aasworld ).reachability[i].areanum = LittleLong( ( *aasworld ).reachability[i].areanum ); + ( *aasworld ).reachability[i].facenum = LittleLong( ( *aasworld ).reachability[i].facenum ); + ( *aasworld ).reachability[i].edgenum = LittleLong( ( *aasworld ).reachability[i].edgenum ); + for ( j = 0; j < 3; j++ ) + { + ( *aasworld ).reachability[i].start[j] = LittleFloat( ( *aasworld ).reachability[i].start[j] ); + ( *aasworld ).reachability[i].end[j] = LittleFloat( ( *aasworld ).reachability[i].end[j] ); + } //end for + ( *aasworld ).reachability[i].traveltype = LittleLong( ( *aasworld ).reachability[i].traveltype ); + ( *aasworld ).reachability[i].traveltime = LittleShort( ( *aasworld ).reachability[i].traveltime ); + } //end for + //nodes + for ( i = 0; i < ( *aasworld ).numnodes; i++ ) + { + ( *aasworld ).nodes[i].planenum = LittleLong( ( *aasworld ).nodes[i].planenum ); + ( *aasworld ).nodes[i].children[0] = LittleLong( ( *aasworld ).nodes[i].children[0] ); + ( *aasworld ).nodes[i].children[1] = LittleLong( ( *aasworld ).nodes[i].children[1] ); + } //end for + //cluster portals + for ( i = 0; i < ( *aasworld ).numportals; i++ ) + { + ( *aasworld ).portals[i].areanum = LittleLong( ( *aasworld ).portals[i].areanum ); + ( *aasworld ).portals[i].frontcluster = LittleLong( ( *aasworld ).portals[i].frontcluster ); + ( *aasworld ).portals[i].backcluster = LittleLong( ( *aasworld ).portals[i].backcluster ); + ( *aasworld ).portals[i].clusterareanum[0] = LittleLong( ( *aasworld ).portals[i].clusterareanum[0] ); + ( *aasworld ).portals[i].clusterareanum[1] = LittleLong( ( *aasworld ).portals[i].clusterareanum[1] ); + } //end for + //cluster portal index + for ( i = 0; i < ( *aasworld ).portalindexsize; i++ ) + { + ( *aasworld ).portalindex[i] = LittleLong( ( *aasworld ).portalindex[i] ); + } //end for + //cluster + for ( i = 0; i < ( *aasworld ).numclusters; i++ ) + { + ( *aasworld ).clusters[i].numareas = LittleLong( ( *aasworld ).clusters[i].numareas ); + ( *aasworld ).clusters[i].numreachabilityareas = LittleLong( ( *aasworld ).clusters[i].numreachabilityareas ); + ( *aasworld ).clusters[i].numportals = LittleLong( ( *aasworld ).clusters[i].numportals ); + ( *aasworld ).clusters[i].firstportal = LittleLong( ( *aasworld ).clusters[i].firstportal ); + } //end for +} //end of the function AAS_SwapAASData +//=========================================================================== +// dump the current loaded aas file +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_DumpAASData( void ) { + ( *aasworld ).numbboxes = 0; + if ( ( *aasworld ).bboxes ) { + FreeMemory( ( *aasworld ).bboxes ); + } + ( *aasworld ).bboxes = NULL; + ( *aasworld ).numvertexes = 0; + if ( ( *aasworld ).vertexes ) { + FreeMemory( ( *aasworld ).vertexes ); + } + ( *aasworld ).vertexes = NULL; + ( *aasworld ).numplanes = 0; + if ( ( *aasworld ).planes ) { + FreeMemory( ( *aasworld ).planes ); + } + ( *aasworld ).planes = NULL; + ( *aasworld ).numedges = 0; + if ( ( *aasworld ).edges ) { + FreeMemory( ( *aasworld ).edges ); + } + ( *aasworld ).edges = NULL; + ( *aasworld ).edgeindexsize = 0; + if ( ( *aasworld ).edgeindex ) { + FreeMemory( ( *aasworld ).edgeindex ); + } + ( *aasworld ).edgeindex = NULL; + ( *aasworld ).numfaces = 0; + if ( ( *aasworld ).faces ) { + FreeMemory( ( *aasworld ).faces ); + } + ( *aasworld ).faces = NULL; + ( *aasworld ).faceindexsize = 0; + if ( ( *aasworld ).faceindex ) { + FreeMemory( ( *aasworld ).faceindex ); + } + ( *aasworld ).faceindex = NULL; + ( *aasworld ).numareas = 0; + if ( ( *aasworld ).areas ) { + FreeMemory( ( *aasworld ).areas ); + } + ( *aasworld ).areas = NULL; + ( *aasworld ).numareasettings = 0; + if ( ( *aasworld ).areasettings ) { + FreeMemory( ( *aasworld ).areasettings ); + } + ( *aasworld ).areasettings = NULL; + ( *aasworld ).reachabilitysize = 0; + if ( ( *aasworld ).reachability ) { + FreeMemory( ( *aasworld ).reachability ); + } + ( *aasworld ).reachability = NULL; + ( *aasworld ).numnodes = 0; + if ( ( *aasworld ).nodes ) { + FreeMemory( ( *aasworld ).nodes ); + } + ( *aasworld ).nodes = NULL; + ( *aasworld ).numportals = 0; + if ( ( *aasworld ).portals ) { + FreeMemory( ( *aasworld ).portals ); + } + ( *aasworld ).portals = NULL; + ( *aasworld ).numportals = 0; + if ( ( *aasworld ).portalindex ) { + FreeMemory( ( *aasworld ).portalindex ); + } + ( *aasworld ).portalindex = NULL; + ( *aasworld ).portalindexsize = 0; + if ( ( *aasworld ).clusters ) { + FreeMemory( ( *aasworld ).clusters ); + } + ( *aasworld ).clusters = NULL; + ( *aasworld ).numclusters = 0; + // + ( *aasworld ).loaded = qfalse; + ( *aasworld ).initialized = qfalse; + ( *aasworld ).savefile = qfalse; +} //end of the function AAS_DumpAASData +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +#ifdef AASFILEDEBUG +void AAS_FileInfo( void ) { + int i, n, optimized; + + botimport.Print( PRT_MESSAGE, "version = %d\n", AASVERSION ); + botimport.Print( PRT_MESSAGE, "numvertexes = %d\n", ( *aasworld ).numvertexes ); + botimport.Print( PRT_MESSAGE, "numplanes = %d\n", ( *aasworld ).numplanes ); + botimport.Print( PRT_MESSAGE, "numedges = %d\n", ( *aasworld ).numedges ); + botimport.Print( PRT_MESSAGE, "edgeindexsize = %d\n", ( *aasworld ).edgeindexsize ); + botimport.Print( PRT_MESSAGE, "numfaces = %d\n", ( *aasworld ).numfaces ); + botimport.Print( PRT_MESSAGE, "faceindexsize = %d\n", ( *aasworld ).faceindexsize ); + botimport.Print( PRT_MESSAGE, "numareas = %d\n", ( *aasworld ).numareas ); + botimport.Print( PRT_MESSAGE, "numareasettings = %d\n", ( *aasworld ).numareasettings ); + botimport.Print( PRT_MESSAGE, "reachabilitysize = %d\n", ( *aasworld ).reachabilitysize ); + botimport.Print( PRT_MESSAGE, "numnodes = %d\n", ( *aasworld ).numnodes ); + botimport.Print( PRT_MESSAGE, "numportals = %d\n", ( *aasworld ).numportals ); + botimport.Print( PRT_MESSAGE, "portalindexsize = %d\n", ( *aasworld ).portalindexsize ); + botimport.Print( PRT_MESSAGE, "numclusters = %d\n", ( *aasworld ).numclusters ); + // + for ( n = 0, i = 0; i < ( *aasworld ).numareasettings; i++ ) + { + if ( ( *aasworld ).areasettings[i].areaflags & AREA_GROUNDED ) { + n++; + } + } //end for + botimport.Print( PRT_MESSAGE, "num grounded areas = %d\n", n ); + // + botimport.Print( PRT_MESSAGE, "planes size %d bytes\n", ( *aasworld ).numplanes * sizeof( aas_plane_t ) ); + botimport.Print( PRT_MESSAGE, "areas size %d bytes\n", ( *aasworld ).numareas * sizeof( aas_area_t ) ); + botimport.Print( PRT_MESSAGE, "areasettings size %d bytes\n", ( *aasworld ).numareasettings * sizeof( aas_areasettings_t ) ); + botimport.Print( PRT_MESSAGE, "nodes size %d bytes\n", ( *aasworld ).numnodes * sizeof( aas_node_t ) ); + botimport.Print( PRT_MESSAGE, "reachability size %d bytes\n", ( *aasworld ).reachabilitysize * sizeof( aas_reachability_t ) ); + botimport.Print( PRT_MESSAGE, "portals size %d bytes\n", ( *aasworld ).numportals * sizeof( aas_portal_t ) ); + botimport.Print( PRT_MESSAGE, "clusters size %d bytes\n", ( *aasworld ).numclusters * sizeof( aas_cluster_t ) ); + + optimized = ( *aasworld ).numplanes * sizeof( aas_plane_t ) + + ( *aasworld ).numareas * sizeof( aas_area_t ) + + ( *aasworld ).numareasettings * sizeof( aas_areasettings_t ) + + ( *aasworld ).numnodes * sizeof( aas_node_t ) + + ( *aasworld ).reachabilitysize * sizeof( aas_reachability_t ) + + ( *aasworld ).numportals * sizeof( aas_portal_t ) + + ( *aasworld ).numclusters * sizeof( aas_cluster_t ); + botimport.Print( PRT_MESSAGE, "optimzed size %d KB\n", optimized >> 10 ); +} //end of the function AAS_FileInfo +#endif //AASFILEDEBUG +//=========================================================================== +// allocate memory and read a lump of a AAS file +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +char *AAS_LoadAASLump( fileHandle_t fp, int offset, int length, int *lastoffset ) { + char *buf; + // + if ( !length ) { + return NULL; + } + //seek to the data + if ( offset != *lastoffset ) { + botimport.Print( PRT_WARNING, "AAS file not sequentially read\n" ); + if ( botimport.FS_Seek( fp, offset, FS_SEEK_SET ) ) { + AAS_Error( "can't seek to aas lump\n" ); + AAS_DumpAASData(); + botimport.FS_FCloseFile( fp ); + return 0; + } //end if + } //end if + //allocate memory + buf = (char *) GetClearedHunkMemory( length + 1 ); + //read the data + if ( length ) { + botimport.FS_Read( buf, length, fp ); + *lastoffset += length; + } //end if + return buf; +} //end of the function AAS_LoadAASLump +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_DData( unsigned char *data, int size ) { + int i; + + for ( i = 0; i < size; i++ ) + { + data[i] ^= (unsigned char) i * 119; + } //end for +} //end of the function AAS_DData +//=========================================================================== +// load an aas file +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_LoadAASFile( char *filename ) { + fileHandle_t fp; + aas_header_t header; + int offset, length, lastoffset; + + botimport.Print( PRT_MESSAGE, "trying to load %s\n", filename ); + //dump current loaded aas file + AAS_DumpAASData(); + //open the file + botimport.FS_FOpenFile( filename, &fp, FS_READ ); + if ( !fp ) { + AAS_Error( "can't open %s\n", filename ); + return BLERR_CANNOTOPENAASFILE; + } //end if + //read the header + botimport.FS_Read( &header, sizeof( aas_header_t ), fp ); + lastoffset = sizeof( aas_header_t ); + //check header identification + header.ident = LittleLong( header.ident ); + if ( header.ident != AASID ) { + AAS_Error( "%s is not an AAS file\n", filename ); + botimport.FS_FCloseFile( fp ); + return BLERR_WRONGAASFILEID; + } //end if + //check the version + header.version = LittleLong( header.version ); + // + if ( header.version != AASVERSION ) { + AAS_Error( "aas file %s is version %i, not %i\n", filename, header.version, AASVERSION ); + botimport.FS_FCloseFile( fp ); + return BLERR_WRONGAASFILEVERSION; + } //end if + // + if ( header.version == AASVERSION ) { + AAS_DData( (unsigned char *) &header + 8, sizeof( aas_header_t ) - 8 ); + } //end if + // + ( *aasworld ).bspchecksum = atoi( LibVarGetString( "sv_mapChecksum" ) ); + if ( LittleLong( header.bspchecksum ) != ( *aasworld ).bspchecksum ) { + AAS_Error( "aas file %s is out of date\n", filename ); + botimport.FS_FCloseFile( fp ); + return BLERR_WRONGAASFILEVERSION; + } //end if + //load the lumps: + //bounding boxes + offset = LittleLong( header.lumps[AASLUMP_BBOXES].fileofs ); + length = LittleLong( header.lumps[AASLUMP_BBOXES].filelen ); + ( *aasworld ).bboxes = (aas_bbox_t *) AAS_LoadAASLump( fp, offset, length, &lastoffset ); + ( *aasworld ).numbboxes = length / sizeof( aas_bbox_t ); + if ( ( *aasworld ).numbboxes && !( *aasworld ).bboxes ) { + return BLERR_CANNOTREADAASLUMP; + } + //vertexes + offset = LittleLong( header.lumps[AASLUMP_VERTEXES].fileofs ); + length = LittleLong( header.lumps[AASLUMP_VERTEXES].filelen ); + ( *aasworld ).vertexes = (aas_vertex_t *) AAS_LoadAASLump( fp, offset, length, &lastoffset ); + ( *aasworld ).numvertexes = length / sizeof( aas_vertex_t ); + if ( ( *aasworld ).numvertexes && !( *aasworld ).vertexes ) { + return BLERR_CANNOTREADAASLUMP; + } + //planes + offset = LittleLong( header.lumps[AASLUMP_PLANES].fileofs ); + length = LittleLong( header.lumps[AASLUMP_PLANES].filelen ); + ( *aasworld ).planes = (aas_plane_t *) AAS_LoadAASLump( fp, offset, length, &lastoffset ); + ( *aasworld ).numplanes = length / sizeof( aas_plane_t ); + if ( ( *aasworld ).numplanes && !( *aasworld ).planes ) { + return BLERR_CANNOTREADAASLUMP; + } + //edges + offset = LittleLong( header.lumps[AASLUMP_EDGES].fileofs ); + length = LittleLong( header.lumps[AASLUMP_EDGES].filelen ); + ( *aasworld ).edges = (aas_edge_t *) AAS_LoadAASLump( fp, offset, length, &lastoffset ); + ( *aasworld ).numedges = length / sizeof( aas_edge_t ); + if ( ( *aasworld ).numedges && !( *aasworld ).edges ) { + return BLERR_CANNOTREADAASLUMP; + } + //edgeindex + offset = LittleLong( header.lumps[AASLUMP_EDGEINDEX].fileofs ); + length = LittleLong( header.lumps[AASLUMP_EDGEINDEX].filelen ); + ( *aasworld ).edgeindex = (aas_edgeindex_t *) AAS_LoadAASLump( fp, offset, length, &lastoffset ); + ( *aasworld ).edgeindexsize = length / sizeof( aas_edgeindex_t ); + if ( ( *aasworld ).edgeindexsize && !( *aasworld ).edgeindex ) { + return BLERR_CANNOTREADAASLUMP; + } + //faces + offset = LittleLong( header.lumps[AASLUMP_FACES].fileofs ); + length = LittleLong( header.lumps[AASLUMP_FACES].filelen ); + ( *aasworld ).faces = (aas_face_t *) AAS_LoadAASLump( fp, offset, length, &lastoffset ); + ( *aasworld ).numfaces = length / sizeof( aas_face_t ); + if ( ( *aasworld ).numfaces && !( *aasworld ).faces ) { + return BLERR_CANNOTREADAASLUMP; + } + //faceindex + offset = LittleLong( header.lumps[AASLUMP_FACEINDEX].fileofs ); + length = LittleLong( header.lumps[AASLUMP_FACEINDEX].filelen ); + ( *aasworld ).faceindex = (aas_faceindex_t *) AAS_LoadAASLump( fp, offset, length, &lastoffset ); + ( *aasworld ).faceindexsize = length / sizeof( int ); + if ( ( *aasworld ).faceindexsize && !( *aasworld ).faceindex ) { + return BLERR_CANNOTREADAASLUMP; + } + //convex areas + offset = LittleLong( header.lumps[AASLUMP_AREAS].fileofs ); + length = LittleLong( header.lumps[AASLUMP_AREAS].filelen ); + ( *aasworld ).areas = (aas_area_t *) AAS_LoadAASLump( fp, offset, length, &lastoffset ); + ( *aasworld ).numareas = length / sizeof( aas_area_t ); + if ( ( *aasworld ).numareas && !( *aasworld ).areas ) { + return BLERR_CANNOTREADAASLUMP; + } + //area settings + offset = LittleLong( header.lumps[AASLUMP_AREASETTINGS].fileofs ); + length = LittleLong( header.lumps[AASLUMP_AREASETTINGS].filelen ); + ( *aasworld ).areasettings = (aas_areasettings_t *) AAS_LoadAASLump( fp, offset, length, &lastoffset ); + ( *aasworld ).numareasettings = length / sizeof( aas_areasettings_t ); + if ( ( *aasworld ).numareasettings && !( *aasworld ).areasettings ) { + return BLERR_CANNOTREADAASLUMP; + } + //reachability list + offset = LittleLong( header.lumps[AASLUMP_REACHABILITY].fileofs ); + length = LittleLong( header.lumps[AASLUMP_REACHABILITY].filelen ); + ( *aasworld ).reachability = (aas_reachability_t *) AAS_LoadAASLump( fp, offset, length, &lastoffset ); + ( *aasworld ).reachabilitysize = length / sizeof( aas_reachability_t ); + if ( ( *aasworld ).reachabilitysize && !( *aasworld ).reachability ) { + return BLERR_CANNOTREADAASLUMP; + } + //nodes + offset = LittleLong( header.lumps[AASLUMP_NODES].fileofs ); + length = LittleLong( header.lumps[AASLUMP_NODES].filelen ); + ( *aasworld ).nodes = (aas_node_t *) AAS_LoadAASLump( fp, offset, length, &lastoffset ); + ( *aasworld ).numnodes = length / sizeof( aas_node_t ); + if ( ( *aasworld ).numnodes && !( *aasworld ).nodes ) { + return BLERR_CANNOTREADAASLUMP; + } + //cluster portals + offset = LittleLong( header.lumps[AASLUMP_PORTALS].fileofs ); + length = LittleLong( header.lumps[AASLUMP_PORTALS].filelen ); + ( *aasworld ).portals = (aas_portal_t *) AAS_LoadAASLump( fp, offset, length, &lastoffset ); + ( *aasworld ).numportals = length / sizeof( aas_portal_t ); + if ( ( *aasworld ).numportals && !( *aasworld ).portals ) { + return BLERR_CANNOTREADAASLUMP; + } + //cluster portal index + offset = LittleLong( header.lumps[AASLUMP_PORTALINDEX].fileofs ); + length = LittleLong( header.lumps[AASLUMP_PORTALINDEX].filelen ); + ( *aasworld ).portalindex = (aas_portalindex_t *) AAS_LoadAASLump( fp, offset, length, &lastoffset ); + ( *aasworld ).portalindexsize = length / sizeof( aas_portalindex_t ); + if ( ( *aasworld ).portalindexsize && !( *aasworld ).portalindex ) { + return BLERR_CANNOTREADAASLUMP; + } + //clusters + offset = LittleLong( header.lumps[AASLUMP_CLUSTERS].fileofs ); + length = LittleLong( header.lumps[AASLUMP_CLUSTERS].filelen ); + ( *aasworld ).clusters = (aas_cluster_t *) AAS_LoadAASLump( fp, offset, length, &lastoffset ); + ( *aasworld ).numclusters = length / sizeof( aas_cluster_t ); + if ( ( *aasworld ).numclusters && !( *aasworld ).clusters ) { + return BLERR_CANNOTREADAASLUMP; + } + //swap everything + AAS_SwapAASData(); + //aas file is loaded + ( *aasworld ).loaded = qtrue; + //close the file + botimport.FS_FCloseFile( fp ); + // +#ifdef AASFILEDEBUG + AAS_FileInfo(); +#endif //AASFILEDEBUG + // + return BLERR_NOERROR; +} //end of the function AAS_LoadAASFile +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +static int AAS_WriteAASLump_offset; + +int AAS_WriteAASLump( fileHandle_t fp, aas_header_t *h, int lumpnum, void *data, int length ) { + aas_lump_t *lump; + + lump = &h->lumps[lumpnum]; + + lump->fileofs = LittleLong( AAS_WriteAASLump_offset ); //LittleLong(ftell(fp)); + lump->filelen = LittleLong( length ); + + if ( length > 0 ) { + botimport.FS_Write( data, length, fp ); + } //end if + + AAS_WriteAASLump_offset += length; + + return qtrue; +} //end of the function AAS_WriteAASLump +//=========================================================================== +// aas data is useless after writing to file because it is byte swapped +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +qboolean AAS_WriteAASFile( char *filename ) { + aas_header_t header; + fileHandle_t fp; + + botimport.Print( PRT_MESSAGE, "writing %s\n", filename ); + //swap the aas data + AAS_SwapAASData(); + //initialize the file header + memset( &header, 0, sizeof( aas_header_t ) ); + header.ident = LittleLong( AASID ); + header.version = LittleLong( AASVERSION ); + header.bspchecksum = LittleLong( ( *aasworld ).bspchecksum ); + //open a new file + botimport.FS_FOpenFile( filename, &fp, FS_WRITE ); + if ( !fp ) { + botimport.Print( PRT_ERROR, "error opening %s\n", filename ); + return qfalse; + } //end if + //write the header + botimport.FS_Write( &header, sizeof( aas_header_t ), fp ); + AAS_WriteAASLump_offset = sizeof( aas_header_t ); + //add the data lumps to the file + if ( !AAS_WriteAASLump( fp, &header, AASLUMP_BBOXES, ( *aasworld ).bboxes, + ( *aasworld ).numbboxes * sizeof( aas_bbox_t ) ) ) { + return qfalse; + } + if ( !AAS_WriteAASLump( fp, &header, AASLUMP_VERTEXES, ( *aasworld ).vertexes, + ( *aasworld ).numvertexes * sizeof( aas_vertex_t ) ) ) { + return qfalse; + } + if ( !AAS_WriteAASLump( fp, &header, AASLUMP_PLANES, ( *aasworld ).planes, + ( *aasworld ).numplanes * sizeof( aas_plane_t ) ) ) { + return qfalse; + } + if ( !AAS_WriteAASLump( fp, &header, AASLUMP_EDGES, ( *aasworld ).edges, + ( *aasworld ).numedges * sizeof( aas_edge_t ) ) ) { + return qfalse; + } + if ( !AAS_WriteAASLump( fp, &header, AASLUMP_EDGEINDEX, ( *aasworld ).edgeindex, + ( *aasworld ).edgeindexsize * sizeof( aas_edgeindex_t ) ) ) { + return qfalse; + } + if ( !AAS_WriteAASLump( fp, &header, AASLUMP_FACES, ( *aasworld ).faces, + ( *aasworld ).numfaces * sizeof( aas_face_t ) ) ) { + return qfalse; + } + if ( !AAS_WriteAASLump( fp, &header, AASLUMP_FACEINDEX, ( *aasworld ).faceindex, + ( *aasworld ).faceindexsize * sizeof( aas_faceindex_t ) ) ) { + return qfalse; + } + if ( !AAS_WriteAASLump( fp, &header, AASLUMP_AREAS, ( *aasworld ).areas, + ( *aasworld ).numareas * sizeof( aas_area_t ) ) ) { + return qfalse; + } + if ( !AAS_WriteAASLump( fp, &header, AASLUMP_AREASETTINGS, ( *aasworld ).areasettings, + ( *aasworld ).numareasettings * sizeof( aas_areasettings_t ) ) ) { + return qfalse; + } + if ( !AAS_WriteAASLump( fp, &header, AASLUMP_REACHABILITY, ( *aasworld ).reachability, + ( *aasworld ).reachabilitysize * sizeof( aas_reachability_t ) ) ) { + return qfalse; + } + if ( !AAS_WriteAASLump( fp, &header, AASLUMP_NODES, ( *aasworld ).nodes, + ( *aasworld ).numnodes * sizeof( aas_node_t ) ) ) { + return qfalse; + } + if ( !AAS_WriteAASLump( fp, &header, AASLUMP_PORTALS, ( *aasworld ).portals, + ( *aasworld ).numportals * sizeof( aas_portal_t ) ) ) { + return qfalse; + } + if ( !AAS_WriteAASLump( fp, &header, AASLUMP_PORTALINDEX, ( *aasworld ).portalindex, + ( *aasworld ).portalindexsize * sizeof( aas_portalindex_t ) ) ) { + return qfalse; + } + if ( !AAS_WriteAASLump( fp, &header, AASLUMP_CLUSTERS, ( *aasworld ).clusters, + ( *aasworld ).numclusters * sizeof( aas_cluster_t ) ) ) { + return qfalse; + } + //rewrite the header with the added lumps + botimport.FS_Seek( fp, 0, FS_SEEK_SET ); + botimport.FS_Write( &header, sizeof( aas_header_t ), fp ); + //close the file + botimport.FS_FCloseFile( fp ); + return qtrue; +} //end of the function AAS_WriteAASFile + diff --git a/Projects/Android/jni/rtcw/src/botlib/be_aas_file.h b/Projects/Android/jni/rtcw/src/botlib/be_aas_file.h new file mode 100644 index 0000000..4362da5 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/botlib/be_aas_file.h @@ -0,0 +1,48 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +/***************************************************************************** + * name: be_aas_file.h + * + * desc: AAS + * + * + *****************************************************************************/ + +#ifdef AASINTERN +//loads the AAS file with the given name +int AAS_LoadAASFile( char *filename ); +//writes an AAS file with the given name +qboolean AAS_WriteAASFile( char *filename ); +//dumps the loaded AAS data +void AAS_DumpAASData( void ); +//print AAS file information +void AAS_FileInfo( void ); +#endif //AASINTERN + diff --git a/Projects/Android/jni/rtcw/src/botlib/be_aas_funcs.h b/Projects/Android/jni/rtcw/src/botlib/be_aas_funcs.h new file mode 100644 index 0000000..7b54e05 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/botlib/be_aas_funcs.h @@ -0,0 +1,56 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +/***************************************************************************** + * name: be_aas_funcs.h + * + * desc: AAS + * + * + *****************************************************************************/ + +#ifndef BSPCINCLUDE + +#include "be_aas_main.h" +#include "be_aas_entity.h" +#include "be_aas_sample.h" +#include "be_aas_cluster.h" +#include "be_aas_reach.h" +#include "be_aas_route.h" +#include "be_aas_routealt.h" +#include "be_aas_debug.h" +#include "be_aas_file.h" +#include "be_aas_optimize.h" +#include "be_aas_bsp.h" +#include "be_aas_move.h" + +// Ridah, route-tables +#include "be_aas_routetable.h" + +#endif //BSPCINCLUDE diff --git a/Projects/Android/jni/rtcw/src/botlib/be_aas_main.c b/Projects/Android/jni/rtcw/src/botlib/be_aas_main.c new file mode 100644 index 0000000..c5d8870 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/botlib/be_aas_main.c @@ -0,0 +1,486 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +/***************************************************************************** + * name: be_aas_main.c + * + * desc: AAS + * + * + *****************************************************************************/ + +#include "../game/q_shared.h" +#include "l_memory.h" +#include "l_libvar.h" +#include "l_utils.h" +#include "l_script.h" +#include "l_precomp.h" +#include "l_struct.h" +#include "l_log.h" +#include "aasfile.h" +#include "../game/botlib.h" +#include "../game/be_aas.h" +#include "be_aas_funcs.h" +#include "be_interface.h" +#include "be_aas_def.h" + +aas_t aasworlds[MAX_AAS_WORLDS]; + +aas_t *aasworld; + +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void QDECL AAS_Error( char *fmt, ... ) { + char str[1024]; + va_list arglist; + + va_start( arglist, fmt ); + vsprintf( str, fmt, arglist ); + va_end( arglist ); + botimport.Print( PRT_FATAL, str ); +} //end of the function AAS_Error + +// Ridah, multiple AAS worlds +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_SetCurrentWorld( int index ) { + if ( index >= MAX_AAS_WORLDS || index < 0 ) { + AAS_Error( "AAS_SetCurrentWorld: index out of range\n" ); + return; + } + + // set the current world pointer + aasworld = &aasworlds[index]; +} +// done. + +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +char *AAS_StringFromIndex( char *indexname, char *stringindex[], int numindexes, int index ) { + if ( !( *aasworld ).indexessetup ) { + botimport.Print( PRT_ERROR, "%s: index %d not setup\n", indexname, index ); + return ""; + } //end if + if ( index < 0 || index >= numindexes ) { + botimport.Print( PRT_ERROR, "%s: index %d out of range\n", indexname, index ); + return ""; + } //end if + if ( !stringindex[index] ) { + if ( index ) { + botimport.Print( PRT_ERROR, "%s: reference to unused index %d\n", indexname, index ); + } //end if + return ""; + } //end if + return stringindex[index]; +} //end of the function AAS_StringFromIndex +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_IndexFromString( char *indexname, char *stringindex[], int numindexes, char *string ) { + int i; + if ( !( *aasworld ).indexessetup ) { + botimport.Print( PRT_ERROR, "%s: index not setup \"%s\"\n", indexname, string ); + return 0; + } //end if + for ( i = 0; i < numindexes; i++ ) + { + if ( !stringindex[i] ) { + continue; + } + if ( !Q_stricmp( stringindex[i], string ) ) { + return i; + } + } //end for + return 0; +} //end of the function AAS_IndexFromString +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +char *AAS_ModelFromIndex( int index ) { +// return AAS_StringFromIndex("ModelFromIndex", &(*aasworld).configstrings[CS_MODELS], MAX_MODELS, index); + return 0; // removed so the CS_ defines could be removed from be_aas_def.h +} //end of the function AAS_ModelFromIndex +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_IndexFromModel( char *modelname ) { +// return AAS_IndexFromString("IndexFromModel", &(*aasworld).configstrings[CS_MODELS], MAX_MODELS, modelname); + return 0; // removed so the CS_ defines could be removed from be_aas_def.h +} //end of the function AAS_IndexFromModel +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_UpdateStringIndexes( int numconfigstrings, char *configstrings[] ) { + int i; + //set string pointers and copy the strings + for ( i = 0; i < numconfigstrings; i++ ) + { + if ( configstrings[i] ) { + //if ((*aasworld).configstrings[i]) FreeMemory((*aasworld).configstrings[i]); + ( *aasworld ).configstrings[i] = (char *) GetMemory( strlen( configstrings[i] ) + 1 ); + strcpy( ( *aasworld ).configstrings[i], configstrings[i] ); + } //end if + } //end for + ( *aasworld ).indexessetup = qtrue; +} //end of the function AAS_UpdateStringIndexes +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_Loaded( void ) { + return ( *aasworld ).loaded; +} //end of the function AAS_Loaded +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_Initialized( void ) { + return ( *aasworld ).initialized; +} //end of the function AAS_Initialized +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_SetInitialized( void ) { + ( *aasworld ).initialized = qtrue; + botimport.Print( PRT_MESSAGE, "AAS initialized.\n" ); +#ifdef DEBUG + //create all the routing cache + //AAS_CreateAllRoutingCache(); + // + //AAS_RoutingInfo(); +#endif + + // Ridah, build/load the route-table + AAS_RT_BuildRouteTable(); + // done. + +} //end of the function AAS_SetInitialized +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_ContinueInit( float time ) { + //if no AAS file loaded + if ( !( *aasworld ).loaded ) { + return; + } + //if AAS is already initialized + if ( ( *aasworld ).initialized ) { + return; + } + //calculate reachability, if not finished return + if ( AAS_ContinueInitReachability( time ) ) { + return; + } + //initialize clustering for the new map + AAS_InitClustering(); + //if reachability has been calculated and an AAS file should be written + //or there is a forced data optimization + if ( ( *aasworld ).savefile || ( (int)LibVarGetValue( "forcewrite" ) ) ) { + //optimize the AAS data + if ( !( (int)LibVarValue( "nooptimize", "1" ) ) ) { + AAS_Optimize(); + } + //save the AAS file + if ( AAS_WriteAASFile( ( *aasworld ).filename ) ) { + botimport.Print( PRT_MESSAGE, "%s written succesfully\n", ( *aasworld ).filename ); + } //end if + else + { + botimport.Print( PRT_ERROR, "couldn't write %s\n", ( *aasworld ).filename ); + } //end else + } //end if + //initialize the routing + AAS_InitRouting(); + //at this point AAS is initialized + AAS_SetInitialized(); +} //end of the function AAS_ContinueInit +//=========================================================================== +// called at the start of every frame +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_StartFrame( float time ) { + // Ridah, do each of the aasworlds + int i; + + for ( i = 0; i < MAX_AAS_WORLDS; i++ ) + { + AAS_SetCurrentWorld( i ); + + ( *aasworld ).time = time; + //invalidate the entities + AAS_InvalidateEntities(); + //initialize AAS + AAS_ContinueInit( time ); + // + ( *aasworld ).frameroutingupdates = 0; + // + /* Ridah, disabled for speed + if (LibVarGetValue("showcacheupdates")) + { + AAS_RoutingInfo(); + LibVarSet("showcacheupdates", "0"); + } //end if + if (LibVarGetValue("showmemoryusage")) + { + PrintUsedMemorySize(); + LibVarSet("showmemoryusage", "0"); + } //end if + if (LibVarGetValue("memorydump")) + { + PrintMemoryLabels(); + LibVarSet("memorydump", "0"); + } //end if + */ + } //end if + ( *aasworld ).numframes++; + return BLERR_NOERROR; +} //end of the function AAS_StartFrame +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +float AAS_Time( void ) { + return ( *aasworld ).time; +} //end of the function AAS_Time +//=========================================================================== +// basedir = Quake2 console basedir +// gamedir = Quake2 console gamedir +// mapname = name of the map without extension (.bsp) +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_LoadFiles( const char *mapname ) { + int errnum; + char aasfile[MAX_PATH]; +// char bspfile[MAX_PATH]; + + strcpy( ( *aasworld ).mapname, mapname ); + //NOTE: first reset the entity links into the AAS areas and BSP leaves + // the AAS link heap and BSP link heap are reset after respectively the + // AAS file and BSP file are loaded + AAS_ResetEntityLinks(); + // + + // load bsp info + AAS_LoadBSPFile(); + + //load the aas file + Com_sprintf( aasfile, MAX_PATH, "maps/%s.aas", mapname ); + errnum = AAS_LoadAASFile( aasfile ); + if ( errnum != BLERR_NOERROR ) { + return errnum; + } + + botimport.Print( PRT_MESSAGE, "loaded %s\n", aasfile ); + strncpy( ( *aasworld ).filename, aasfile, MAX_PATH ); + return BLERR_NOERROR; +} //end of the function AAS_LoadFiles +//=========================================================================== +// called everytime a map changes +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== + +// Ridah, modified this for multiple AAS files + +int AAS_LoadMap( const char *mapname ) { + int errnum; + int i; + char this_mapname[256], intstr[4]; + qboolean loaded = qfalse; + int missingErrNum = 0; // TTimo: init + + for ( i = 0; i < MAX_AAS_WORLDS; i++ ) + { + AAS_SetCurrentWorld( i ); + + strncpy( this_mapname, mapname, 256 ); + strncat( this_mapname, "_b", 256 ); + sprintf( intstr, "%i", i ); + strncat( this_mapname, intstr, 256 ); + + //if no mapname is provided then the string indexes are updated + if ( !mapname ) { + return 0; + } //end if + // + ( *aasworld ).initialized = qfalse; + //NOTE: free the routing caches before loading a new map because + // to free the caches the old number of areas, number of clusters + // and number of areas in a clusters must be available + AAS_FreeRoutingCaches(); + //load the map + errnum = AAS_LoadFiles( this_mapname ); + if ( errnum != BLERR_NOERROR ) { + ( *aasworld ).loaded = qfalse; + // RF, we are allowed to skip one of the files, but not both + //return errnum; + missingErrNum = errnum; + continue; + } //end if + // + loaded = qtrue; + // + AAS_InitSettings(); + //initialize the AAS link heap for the new map + AAS_InitAASLinkHeap(); + //initialize the AAS linked entities for the new map + AAS_InitAASLinkedEntities(); + //initialize reachability for the new map + AAS_InitReachability(); + //initialize the alternative routing + AAS_InitAlternativeRouting(); + } + + if ( !loaded ) { + return missingErrNum; + } + + //everything went ok + return 0; +} //end of the function AAS_LoadMap + +// done. + +//=========================================================================== +// called when the library is first loaded +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_Setup( void ) { + // Ridah, just use the default world for entities + AAS_SetCurrentWorld( 0 ); + + ( *aasworlds ).maxclients = (int) LibVarValue( "maxclients", "128" ); + ( *aasworlds ).maxentities = (int) LibVarValue( "maxentities", "1024" ); + //allocate memory for the entities + if ( ( *aasworld ).entities ) { + FreeMemory( ( *aasworld ).entities ); + } + ( *aasworld ).entities = (aas_entity_t *) GetClearedHunkMemory( ( *aasworld ).maxentities * sizeof( aas_entity_t ) ); + //invalidate all the entities + AAS_InvalidateEntities(); + + //force some recalculations + //LibVarSet("forceclustering", "1"); //force clustering calculation + //LibVarSet("forcereachability", "1"); //force reachability calculation + ( *aasworld ).numframes = 0; + return BLERR_NOERROR; +} //end of the function AAS_Setup +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_Shutdown( void ) { + // Ridah, do each of the worlds + int i; + + for ( i = 0; i < MAX_AAS_WORLDS; i++ ) + { + AAS_SetCurrentWorld( i ); + + // Ridah, kill the route-table data + AAS_RT_ShutdownRouteTable(); + + AAS_ShutdownAlternativeRouting(); + AAS_DumpBSPData(); + //free routing caches + AAS_FreeRoutingCaches(); + //free aas link heap + AAS_FreeAASLinkHeap(); + //free aas linked entities + AAS_FreeAASLinkedEntities(); + //free the aas data + AAS_DumpAASData(); + + if ( i == 0 ) { + //free the entities + if ( ( *aasworld ).entities ) { + FreeMemory( ( *aasworld ).entities ); + } + } + + //clear the (*aasworld) structure + memset( &( *aasworld ), 0, sizeof( aas_t ) ); + //aas has not been initialized + ( *aasworld ).initialized = qfalse; + } + + //NOTE: as soon as a new .bsp file is loaded the .bsp file memory is + // freed an reallocated, so there's no need to free that memory here + //print shutdown + botimport.Print( PRT_MESSAGE, "AAS shutdown.\n" ); +} //end of the function AAS_Shutdown diff --git a/Projects/Android/jni/rtcw/src/botlib/be_aas_main.h b/Projects/Android/jni/rtcw/src/botlib/be_aas_main.h new file mode 100644 index 0000000..b0373a8 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/botlib/be_aas_main.h @@ -0,0 +1,69 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +/***************************************************************************** + * name: be_aas_main.h + * + * desc: AAS + * + * + *****************************************************************************/ + +#ifdef AASINTERN + +extern aas_t( *aasworld ); + +//AAS error message +void QDECL AAS_Error( char *fmt, ... ); +//set AAS initialized +void AAS_SetInitialized( void ); +//setup AAS with the given number of entities and clients +int AAS_Setup( void ); +//shutdown AAS +void AAS_Shutdown( void ); +//start a new map +int AAS_LoadMap( const char *mapname ); +//start a new time frame +int AAS_StartFrame( float time ); +#endif //AASINTERN + +//returns true if AAS is initialized +int AAS_Initialized( void ); +//returns true if the AAS file is loaded +int AAS_Loaded( void ); +//returns the model name from the given index +char *AAS_ModelFromIndex( int index ); +//returns the index from the given model name +int AAS_IndexFromModel( char *modelname ); +//returns the current time +float AAS_Time( void ); + +// Ridah +void AAS_SetCurrentWorld( int index ); +// done. diff --git a/Projects/Android/jni/rtcw/src/botlib/be_aas_move.c b/Projects/Android/jni/rtcw/src/botlib/be_aas_move.c new file mode 100644 index 0000000..4f6154c --- /dev/null +++ b/Projects/Android/jni/rtcw/src/botlib/be_aas_move.c @@ -0,0 +1,912 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +/***************************************************************************** + * name: be_aas_move.c + * + * desc: AAS + * + * + *****************************************************************************/ + +#include "../game/q_shared.h" +#include "l_memory.h" +#include "l_script.h" +#include "l_precomp.h" +#include "l_struct.h" +#include "aasfile.h" +#include "../game/botlib.h" +#include "../game/be_aas.h" +#include "be_aas_funcs.h" +#include "be_aas_def.h" + +//#define BSPC + +extern botlib_import_t botimport; + +aas_settings_t aassettings; + +//#define AAS_MOVE_DEBUG + +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_DropToFloor( vec3_t origin, vec3_t mins, vec3_t maxs ) { + vec3_t end; + bsp_trace_t trace; + + VectorCopy( origin, end ); + end[2] -= 100; + trace = AAS_Trace( origin, mins, maxs, end, 0, CONTENTS_SOLID ); + if ( trace.startsolid ) { + return qfalse; + } + VectorCopy( trace.endpos, origin ); + return qtrue; +} //end of the function AAS_DropToFloor +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_InitSettings( void ) { + aassettings.sv_friction = 6; + aassettings.sv_stopspeed = 100; + aassettings.sv_gravity = 800; + aassettings.sv_waterfriction = 1; + aassettings.sv_watergravity = 400; + aassettings.sv_maxvelocity = 320; + aassettings.sv_maxwalkvelocity = 300; + aassettings.sv_maxcrouchvelocity = 100; + aassettings.sv_maxswimvelocity = 150; + aassettings.sv_walkaccelerate = 10; + aassettings.sv_airaccelerate = 1; + aassettings.sv_swimaccelerate = 4; + aassettings.sv_maxstep = 18; + aassettings.sv_maxsteepness = 0.7; + aassettings.sv_maxwaterjump = 17; + // Ridah, calculate maxbarrier according to jumpvel and gravity + aassettings.sv_jumpvel = 270; + aassettings.sv_maxbarrier = 49; //-0.8 + (0.5 * aassettings.sv_gravity * (aassettings.sv_jumpvel / aassettings.sv_gravity) * (aassettings.sv_jumpvel / aassettings.sv_gravity)); + // done. + +} //end of the function AAS_InitSettings +//=========================================================================== +// returns qtrue if the bot is against a ladder +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_AgainstLadder( vec3_t origin, int ms_areanum ) { + int areanum, i, facenum, side; + vec3_t org; + aas_plane_t *plane; + aas_face_t *face; + aas_area_t *area; + + VectorCopy( origin, org ); + areanum = AAS_PointAreaNum( org ); + if ( !areanum ) { + org[0] += 1; + areanum = AAS_PointAreaNum( org ); + if ( !areanum ) { + org[1] += 1; + areanum = AAS_PointAreaNum( org ); + if ( !areanum ) { + org[0] -= 2; + areanum = AAS_PointAreaNum( org ); + if ( !areanum ) { + org[1] -= 2; + areanum = AAS_PointAreaNum( org ); + } //end if + } //end if + } //end if + } //end if + //if in solid... wrrr shouldn't happen + //if (!areanum) return qfalse; + // RF, it does if they're in a monsterclip brush + if ( !areanum ) { + areanum = ms_areanum; + } + //if not in a ladder area + if ( !( ( *aasworld ).areasettings[areanum].areaflags & AREA_LADDER ) ) { + return qfalse; + } + //if a crouch only area + if ( !( ( *aasworld ).areasettings[areanum].presencetype & PRESENCE_NORMAL ) ) { + return qfalse; + } + // + area = &( *aasworld ).areas[areanum]; + for ( i = 0; i < area->numfaces; i++ ) + { + facenum = ( *aasworld ).faceindex[area->firstface + i]; + side = facenum < 0; + face = &( *aasworld ).faces[abs( facenum )]; + //if the face isn't a ladder face + if ( !( face->faceflags & FACE_LADDER ) ) { + continue; + } + //get the plane the face is in + plane = &( *aasworld ).planes[face->planenum ^ side]; + //if the origin is pretty close to the plane + if ( abs( DotProduct( plane->normal, origin ) - plane->dist ) < 3 ) { + if ( AAS_PointInsideFace( abs( facenum ), origin, 0.1 ) ) { + return qtrue; + } + } //end if + } //end for + return qfalse; +} //end of the function AAS_AgainstLadder +//=========================================================================== +// returns qtrue if the bot is on the ground +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_OnGround( vec3_t origin, int presencetype, int passent ) { + aas_trace_t trace; + vec3_t end, up = {0, 0, 1}; + aas_plane_t *plane; + + VectorCopy( origin, end ); + end[2] -= 10; + + trace = AAS_TraceClientBBox( origin, end, presencetype, passent ); + + //if in solid + if ( trace.startsolid ) { + return qtrue; //qfalse; + } + //if nothing hit at all + if ( trace.fraction >= 1.0 ) { + return qfalse; + } + //if too far from the hit plane + if ( origin[2] - trace.endpos[2] > 10 ) { + return qfalse; + } + //check if the plane isn't too steep + plane = AAS_PlaneFromNum( trace.planenum ); + if ( DotProduct( plane->normal, up ) < aassettings.sv_maxsteepness ) { + return qfalse; + } + //the bot is on the ground + return qtrue; +} //end of the function AAS_OnGround +//=========================================================================== +// returns qtrue if a bot at the given position is swimming +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_Swimming( vec3_t origin ) { + vec3_t testorg; + + VectorCopy( origin, testorg ); + testorg[2] -= 2; + if ( AAS_PointContents( testorg ) & ( CONTENTS_LAVA | CONTENTS_SLIME | CONTENTS_WATER ) ) { + return qtrue; + } + return qfalse; +} //end of the function AAS_Swimming +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +vec3_t VEC_UP = {0, -1, 0}; +vec3_t MOVEDIR_UP = {0, 0, 1}; +vec3_t VEC_DOWN = {0, -2, 0}; +vec3_t MOVEDIR_DOWN = {0, 0, -1}; + +void AAS_SetMovedir( vec3_t angles, vec3_t movedir ) { + if ( VectorCompare( angles, VEC_UP ) ) { + VectorCopy( MOVEDIR_UP, movedir ); + } //end if + else if ( VectorCompare( angles, VEC_DOWN ) ) { + VectorCopy( MOVEDIR_DOWN, movedir ); + } //end else if + else + { + AngleVectors( angles, movedir, NULL, NULL ); + } //end else +} //end of the function AAS_SetMovedir +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_JumpReachRunStart( aas_reachability_t *reach, vec3_t runstart ) { + vec3_t hordir, start, cmdmove; + aas_clientmove_t move; + + // + hordir[0] = reach->start[0] - reach->end[0]; + hordir[1] = reach->start[1] - reach->end[1]; + hordir[2] = 0; + VectorNormalize( hordir ); + //start point + VectorCopy( reach->start, start ); + start[2] += 1; + //get command movement + VectorScale( hordir, 400, cmdmove ); + // + AAS_PredictClientMovement( &move, -1, start, PRESENCE_NORMAL, qtrue, + vec3_origin, cmdmove, 1, 2, 0.1, + SE_ENTERWATER | SE_ENTERSLIME | SE_ENTERLAVA | + SE_HITGROUNDDAMAGE | SE_GAP, 0, qfalse ); + VectorCopy( move.endpos, runstart ); + //don't enter slime or lava and don't fall from too high + if ( move.stopevent & ( SE_ENTERLAVA | SE_HITGROUNDDAMAGE ) ) { //----(SA) modified since slime is no longer deadly +// if (move.stopevent & (SE_ENTERSLIME|SE_ENTERLAVA|SE_HITGROUNDDAMAGE)) + VectorCopy( start, runstart ); + } //end if +} //end of the function AAS_JumpReachRunStart +//=========================================================================== +// returns the Z velocity when rocket jumping at the origin +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +float AAS_WeaponJumpZVelocity( vec3_t origin, float radiusdamage ) { + vec3_t kvel, v, start, end, forward, right, viewangles, dir; + float mass, knockback, points; + vec3_t rocketoffset = {8, 8, -8}; + vec3_t botmins = {-16, -16, -24}; + vec3_t botmaxs = {16, 16, 32}; + bsp_trace_t bsptrace; + + //look down (90 degrees) + viewangles[PITCH] = 90; + viewangles[YAW] = 0; + viewangles[ROLL] = 0; + //get the start point shooting from + VectorCopy( origin, start ); + start[2] += 8; //view offset Z + AngleVectors( viewangles, forward, right, NULL ); + start[0] += forward[0] * rocketoffset[0] + right[0] * rocketoffset[1]; + start[1] += forward[1] * rocketoffset[0] + right[1] * rocketoffset[1]; + start[2] += forward[2] * rocketoffset[0] + right[2] * rocketoffset[1] + rocketoffset[2]; + //end point of the trace + VectorMA( start, 500, forward, end ); + //trace a line to get the impact point + bsptrace = AAS_Trace( start, NULL, NULL, end, 1, CONTENTS_SOLID ); + //calculate the damage the bot will get from the rocket impact + VectorAdd( botmins, botmaxs, v ); + VectorMA( origin, 0.5, v, v ); + VectorSubtract( bsptrace.endpos, v, v ); + // + points = radiusdamage - 0.5 * VectorLength( v ); + if ( points < 0 ) { + points = 0; + } + //the owner of the rocket gets half the damage + points *= 0.5; + //mass of the bot (p_client.c: PutClientInServer) + mass = 200; + //knockback is the same as the damage points + knockback = points; + //direction of the damage (from trace.endpos to bot origin) + VectorSubtract( origin, bsptrace.endpos, dir ); + VectorNormalize( dir ); + //damage velocity + VectorScale( dir, 1600.0 * (float)knockback / mass, kvel ); //the rocket jump hack... + //rocket impact velocity + jump velocity + return kvel[2] + aassettings.sv_jumpvel; +} //end of the function AAS_WeaponJumpZVelocity +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +float AAS_RocketJumpZVelocity( vec3_t origin ) { + //rocket radius damage is 120 (p_weapon.c: Weapon_RocketLauncher_Fire) + return AAS_WeaponJumpZVelocity( origin, 120 ); +} //end of the function AAS_RocketJumpZVelocity +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +float AAS_BFGJumpZVelocity( vec3_t origin ) { + //bfg radius damage is 1000 (p_weapon.c: weapon_bfg_fire) + return AAS_WeaponJumpZVelocity( origin, 120 ); +} //end of the function AAS_BFGJumpZVelocity +//=========================================================================== +// applies ground friction to the given velocity +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_Accelerate( vec3_t velocity, float frametime, vec3_t wishdir, float wishspeed, float accel ) { + // q2 style + int i; + float addspeed, accelspeed, currentspeed; + + currentspeed = DotProduct( velocity, wishdir ); + addspeed = wishspeed - currentspeed; + if ( addspeed <= 0 ) { + return; + } + accelspeed = accel * frametime * wishspeed; + if ( accelspeed > addspeed ) { + accelspeed = addspeed; + } + + for ( i = 0 ; i < 3 ; i++ ) { + velocity[i] += accelspeed * wishdir[i]; + } +} //end of the function AAS_Accelerate +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_AirControl( vec3_t start, vec3_t end, vec3_t velocity, vec3_t cmdmove ) { + vec3_t dir; + + VectorSubtract( end, start, dir ); +} //end of the function AAS_AirControl +//=========================================================================== +// applies ground friction to the given velocity +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_ApplyFriction( vec3_t vel, float friction, float stopspeed, + float frametime ) { + float speed, control, newspeed; + + //horizontal speed + speed = sqrt( vel[0] * vel[0] + vel[1] * vel[1] ); + if ( speed ) { + control = speed < stopspeed ? stopspeed : speed; + newspeed = speed - frametime * control * friction; + if ( newspeed < 0 ) { + newspeed = 0; + } + newspeed /= speed; + vel[0] *= newspeed; + vel[1] *= newspeed; + } //end if +} //end of the function AAS_ApplyFriction +//=========================================================================== +// predicts the movement +// assumes regular bounding box sizes +// NOTE: out of water jumping is not included +// NOTE: grappling hook is not included +// +// Parameter: origin : origin to start with +// presencetype : presence type to start with +// velocity : velocity to start with +// cmdmove : client command movement +// cmdframes : number of frame cmdmove is valid +// maxframes : maximum number of predicted frames +// frametime : duration of one predicted frame +// stopevent : events that stop the prediction +// stopareanum : stop as soon as entered this area +// Returns: aas_clientmove_t +// Changes Globals: - +//=========================================================================== +int AAS_PredictClientMovement( struct aas_clientmove_s *move, + int entnum, vec3_t origin, + int presencetype, int onground, + vec3_t velocity, vec3_t cmdmove, + int cmdframes, + int maxframes, float frametime, + int stopevent, int stopareanum, int visualize ) { + float sv_friction, sv_stopspeed, sv_gravity, sv_waterfriction; + float sv_watergravity; + float sv_walkaccelerate, sv_airaccelerate, sv_swimaccelerate; + float sv_maxwalkvelocity, sv_maxcrouchvelocity, sv_maxswimvelocity; + float sv_maxstep, sv_maxsteepness, sv_jumpvel, friction; + float gravity, delta, maxvel, wishspeed, accelerate; + //float velchange, newvel; + int n, i, j, pc, step, swimming, ax, crouch, event, jump_frame, areanum; + int areas[20], numareas; + vec3_t points[20]; + vec3_t org, end, feet, start, stepend, lastorg, wishdir; + vec3_t frame_test_vel, old_frame_test_vel, left_test_vel; + vec3_t up = {0, 0, 1}; + aas_plane_t *plane, *plane2; + aas_trace_t trace, steptrace; + + if ( frametime <= 0 ) { + frametime = 0.1; + } + // + sv_friction = aassettings.sv_friction; + sv_stopspeed = aassettings.sv_stopspeed; + sv_gravity = aassettings.sv_gravity; + sv_waterfriction = aassettings.sv_waterfriction; + sv_watergravity = aassettings.sv_watergravity; + sv_maxwalkvelocity = aassettings.sv_maxwalkvelocity; // * frametime; + sv_maxcrouchvelocity = aassettings.sv_maxcrouchvelocity; // * frametime; + sv_maxswimvelocity = aassettings.sv_maxswimvelocity; // * frametime; + sv_walkaccelerate = aassettings.sv_walkaccelerate; + sv_airaccelerate = aassettings.sv_airaccelerate; + sv_swimaccelerate = aassettings.sv_swimaccelerate; + sv_maxstep = aassettings.sv_maxstep; + sv_maxsteepness = aassettings.sv_maxsteepness; + sv_jumpvel = aassettings.sv_jumpvel * frametime; + // + memset( move, 0, sizeof( aas_clientmove_t ) ); + memset( &trace, 0, sizeof( aas_trace_t ) ); + //start at the current origin + VectorCopy( origin, org ); + org[2] += 0.25; + //velocity to test for the first frame + VectorScale( velocity, frametime, frame_test_vel ); + // + jump_frame = -1; + //predict a maximum of 'maxframes' ahead + for ( n = 0; n < maxframes; n++ ) + { + swimming = AAS_Swimming( org ); + //get gravity depending on swimming or not + gravity = swimming ? sv_watergravity : sv_gravity; + //apply gravity at the START of the frame + frame_test_vel[2] = frame_test_vel[2] - ( gravity * 0.1 * frametime ); + //if on the ground or swimming + if ( onground || swimming ) { + friction = swimming ? sv_friction : sv_waterfriction; + //apply friction + VectorScale( frame_test_vel, 1 / frametime, frame_test_vel ); + AAS_ApplyFriction( frame_test_vel, friction, sv_stopspeed, frametime ); + VectorScale( frame_test_vel, frametime, frame_test_vel ); + } //end if + crouch = qfalse; + //apply command movement + if ( n < cmdframes ) { + ax = 0; + maxvel = sv_maxwalkvelocity; + accelerate = sv_airaccelerate; + VectorCopy( cmdmove, wishdir ); + if ( onground ) { + if ( cmdmove[2] < -300 ) { + crouch = qtrue; + maxvel = sv_maxcrouchvelocity; + } //end if + //if not swimming and upmove is positive then jump + if ( !swimming && cmdmove[2] > 1 ) { + //jump velocity minus the gravity for one frame + 5 for safety + frame_test_vel[2] = sv_jumpvel - ( gravity * 0.1 * frametime ) + 5; + jump_frame = n; + //jumping so air accelerate + accelerate = sv_airaccelerate; + } //end if + else + { + accelerate = sv_walkaccelerate; + } //end else + ax = 2; + } //end if + if ( swimming ) { + maxvel = sv_maxswimvelocity; + accelerate = sv_swimaccelerate; + ax = 3; + } //end if + else + { + wishdir[2] = 0; + } //end else + // + wishspeed = VectorNormalize( wishdir ); + if ( wishspeed > maxvel ) { + wishspeed = maxvel; + } + VectorScale( frame_test_vel, 1 / frametime, frame_test_vel ); + AAS_Accelerate( frame_test_vel, frametime, wishdir, wishspeed, accelerate ); + VectorScale( frame_test_vel, frametime, frame_test_vel ); + /* + for (i = 0; i < ax; i++) + { + velchange = (cmdmove[i] * frametime) - frame_test_vel[i]; + if (velchange > sv_maxacceleration) velchange = sv_maxacceleration; + else if (velchange < -sv_maxacceleration) velchange = -sv_maxacceleration; + newvel = frame_test_vel[i] + velchange; + // + if (frame_test_vel[i] <= maxvel && newvel > maxvel) frame_test_vel[i] = maxvel; + else if (frame_test_vel[i] >= -maxvel && newvel < -maxvel) frame_test_vel[i] = -maxvel; + else frame_test_vel[i] = newvel; + } //end for + */ + } //end if + if ( crouch ) { + presencetype = PRESENCE_CROUCH; + } //end if + else if ( presencetype == PRESENCE_CROUCH ) { + if ( AAS_PointPresenceType( org ) & PRESENCE_NORMAL ) { + presencetype = PRESENCE_NORMAL; + } //end if + } //end else + //save the current origin + VectorCopy( org, lastorg ); + //move linear during one frame + VectorCopy( frame_test_vel, left_test_vel ); + j = 0; + do + { + VectorAdd( org, left_test_vel, end ); + //trace a bounding box + trace = AAS_TraceClientBBox( org, end, presencetype, entnum ); + // +//#ifdef AAS_MOVE_DEBUG + if ( visualize ) { + if ( trace.startsolid ) { + botimport.Print( PRT_MESSAGE, "PredictMovement: start solid\n" ); + } + AAS_DebugLine( org, trace.endpos, LINECOLOR_RED ); + } //end if +//#endif //AAS_MOVE_DEBUG + // + if ( stopevent & SE_ENTERAREA ) { + numareas = AAS_TraceAreas( org, trace.endpos, areas, points, 20 ); + for ( i = 0; i < numareas; i++ ) + { + if ( areas[i] == stopareanum ) { + VectorCopy( points[i], move->endpos ); + VectorScale( frame_test_vel, 1 / frametime, move->velocity ); + move->trace = trace; + move->stopevent = SE_ENTERAREA; + move->presencetype = presencetype; + move->endcontents = 0; + move->time = n * frametime; + move->frames = n; + return qtrue; + } //end if + } //end for + } //end if + //move the entity to the trace end point + VectorCopy( trace.endpos, org ); + //if there was a collision + if ( trace.fraction < 1.0 ) { + //get the plane the bounding box collided with + plane = AAS_PlaneFromNum( trace.planenum ); + // + if ( stopevent & SE_HITGROUNDAREA ) { + if ( DotProduct( plane->normal, up ) > sv_maxsteepness ) { + VectorCopy( org, start ); + start[2] += 0.5; + if ( AAS_PointAreaNum( start ) == stopareanum ) { + VectorCopy( start, move->endpos ); + VectorScale( frame_test_vel, 1 / frametime, move->velocity ); + move->trace = trace; + move->stopevent = SE_HITGROUNDAREA; + move->presencetype = presencetype; + move->endcontents = 0; + move->time = n * frametime; + move->frames = n; + return qtrue; + } //end if + } //end if + } //end if + //assume there's no step + step = qfalse; + //if it is a vertical plane and the bot didn't jump recently + if ( plane->normal[2] == 0 && ( jump_frame < 0 || n - jump_frame > 2 ) ) { + //check for a step + VectorMA( org, -0.25, plane->normal, start ); + VectorCopy( start, stepend ); + start[2] += sv_maxstep; + steptrace = AAS_TraceClientBBox( start, stepend, presencetype, entnum ); + // + if ( !steptrace.startsolid ) { + plane2 = AAS_PlaneFromNum( steptrace.planenum ); + if ( DotProduct( plane2->normal, up ) > sv_maxsteepness ) { + VectorSubtract( end, steptrace.endpos, left_test_vel ); + left_test_vel[2] = 0; + frame_test_vel[2] = 0; +//#ifdef AAS_MOVE_DEBUG + if ( visualize ) { + if ( steptrace.endpos[2] - org[2] > 0.125 ) { + VectorCopy( org, start ); + start[2] = steptrace.endpos[2]; + AAS_DebugLine( org, start, LINECOLOR_BLUE ); + } //end if + } //end if +//#endif //AAS_MOVE_DEBUG + org[2] = steptrace.endpos[2]; + step = qtrue; + } //end if + } //end if + } //end if + // + if ( !step ) { + //velocity left to test for this frame is the projection + //of the current test velocity into the hit plane + VectorMA( left_test_vel, -DotProduct( left_test_vel, plane->normal ), + plane->normal, left_test_vel ); + //store the old velocity for landing check + VectorCopy( frame_test_vel, old_frame_test_vel ); + //test velocity for the next frame is the projection + //of the velocity of the current frame into the hit plane + VectorMA( frame_test_vel, -DotProduct( frame_test_vel, plane->normal ), + plane->normal, frame_test_vel ); + //check for a landing on an almost horizontal floor + if ( DotProduct( plane->normal, up ) > sv_maxsteepness ) { + onground = qtrue; + } //end if + if ( stopevent & SE_HITGROUNDDAMAGE ) { + delta = 0; + if ( old_frame_test_vel[2] < 0 && + frame_test_vel[2] > old_frame_test_vel[2] && + !onground ) { + delta = old_frame_test_vel[2]; + } //end if + else if ( onground ) { + delta = frame_test_vel[2] - old_frame_test_vel[2]; + } //end else + if ( delta ) { + delta = delta * 10; + delta = delta * delta * 0.0001; + if ( swimming ) { + delta = 0; + } + // never take falling damage if completely underwater + /* + if (ent->waterlevel == 3) return; + if (ent->waterlevel == 2) delta *= 0.25; + if (ent->waterlevel == 1) delta *= 0.5; + */ + if ( delta > 40 ) { + VectorCopy( org, move->endpos ); + VectorCopy( frame_test_vel, move->velocity ); + move->trace = trace; + move->stopevent = SE_HITGROUNDDAMAGE; + move->presencetype = presencetype; + move->endcontents = 0; + move->time = n * frametime; + move->frames = n; + return qtrue; + } //end if + } //end if + } //end if + } //end if + } //end if + //extra check to prevent endless loop + if ( ++j > 20 ) { + return qfalse; + } + //while there is a plane hit + } while ( trace.fraction < 1.0 ); + //if going down + if ( frame_test_vel[2] <= 10 ) { + //check for a liquid at the feet of the bot + VectorCopy( org, feet ); + feet[2] -= 22; + pc = AAS_PointContents( feet ); + //get event from pc + event = SE_NONE; + if ( pc & CONTENTS_LAVA ) { + event |= SE_ENTERLAVA; + } + if ( pc & CONTENTS_SLIME ) { + event |= SE_ENTERSLIME; + } + if ( pc & CONTENTS_WATER ) { + event |= SE_ENTERWATER; + } + // + areanum = AAS_PointAreaNum( org ); + if ( ( *aasworld ).areasettings[areanum].contents & AREACONTENTS_LAVA ) { + event |= SE_ENTERLAVA; + } + if ( ( *aasworld ).areasettings[areanum].contents & AREACONTENTS_SLIME ) { + event |= SE_ENTERSLIME; + } + if ( ( *aasworld ).areasettings[areanum].contents & AREACONTENTS_WATER ) { + event |= SE_ENTERWATER; + } + //if in lava or slime + if ( event & stopevent ) { + VectorCopy( org, move->endpos ); + VectorScale( frame_test_vel, 1 / frametime, move->velocity ); + move->stopevent = event & stopevent; + move->presencetype = presencetype; + move->endcontents = pc; + move->time = n * frametime; + move->frames = n; + return qtrue; + } //end if + } //end if + // + onground = AAS_OnGround( org, presencetype, entnum ); + //if onground and on the ground for at least one whole frame + if ( onground ) { + if ( stopevent & SE_HITGROUND ) { + VectorCopy( org, move->endpos ); + VectorScale( frame_test_vel, 1 / frametime, move->velocity ); + move->trace = trace; + move->stopevent = SE_HITGROUND; + move->presencetype = presencetype; + move->endcontents = 0; + move->time = n * frametime; + move->frames = n; + return qtrue; + } //end if + } //end if + else if ( stopevent & SE_LEAVEGROUND ) { + VectorCopy( org, move->endpos ); + VectorScale( frame_test_vel, 1 / frametime, move->velocity ); + move->trace = trace; + move->stopevent = SE_LEAVEGROUND; + move->presencetype = presencetype; + move->endcontents = 0; + move->time = n * frametime; + move->frames = n; + return qtrue; + } //end else if + else if ( stopevent & SE_GAP ) { + aas_trace_t gaptrace; + + VectorCopy( org, start ); + VectorCopy( start, end ); + end[2] -= 48 + aassettings.sv_maxbarrier; + gaptrace = AAS_TraceClientBBox( start, end, PRESENCE_CROUCH, -1 ); + //if solid is found the bot cannot walk any further and will not fall into a gap + if ( !gaptrace.startsolid ) { + //if it is a gap (lower than one step height) + if ( gaptrace.endpos[2] < org[2] - aassettings.sv_maxstep - 1 ) { + if ( !( AAS_PointContents( end ) & ( CONTENTS_WATER | CONTENTS_SLIME ) ) ) { //----(SA) modified since slime is no longer deadly +// if (!(AAS_PointContents(end) & CONTENTS_WATER)) + VectorCopy( lastorg, move->endpos ); + VectorScale( frame_test_vel, 1 / frametime, move->velocity ); + move->trace = trace; + move->stopevent = SE_GAP; + move->presencetype = presencetype; + move->endcontents = 0; + move->time = n * frametime; + move->frames = n; + return qtrue; + } //end if + } //end if + } //end if + } //end else if + if ( stopevent & SE_TOUCHJUMPPAD ) { + if ( ( *aasworld ).areasettings[AAS_PointAreaNum( org )].contents & AREACONTENTS_JUMPPAD ) { + VectorCopy( org, move->endpos ); + VectorScale( frame_test_vel, 1 / frametime, move->velocity ); + move->trace = trace; + move->stopevent = SE_TOUCHJUMPPAD; + move->presencetype = presencetype; + move->endcontents = 0; + move->time = n * frametime; + move->frames = n; + return qtrue; + } //end if + } //end if + if ( stopevent & SE_TOUCHTELEPORTER ) { + if ( ( *aasworld ).areasettings[AAS_PointAreaNum( org )].contents & AREACONTENTS_TELEPORTER ) { + VectorCopy( org, move->endpos ); + VectorScale( frame_test_vel, 1 / frametime, move->velocity ); + move->trace = trace; + move->stopevent = SE_TOUCHTELEPORTER; + move->presencetype = presencetype; + move->endcontents = 0; + move->time = n * frametime; + move->frames = n; + return qtrue; + } //end if + } //end if + } //end for + // + VectorCopy( org, move->endpos ); + VectorScale( frame_test_vel, 1 / frametime, move->velocity ); + move->stopevent = SE_NONE; + move->presencetype = presencetype; + move->endcontents = 0; + move->time = n * frametime; + move->frames = n; + // + return qtrue; +} //end of the function AAS_PredictClientMovement +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_TestMovementPrediction( int entnum, vec3_t origin, vec3_t dir ) { + vec3_t velocity, cmdmove; + aas_clientmove_t move; + + VectorClear( velocity ); + if ( !AAS_Swimming( origin ) ) { + dir[2] = 0; + } + VectorNormalize( dir ); + VectorScale( dir, 400, cmdmove ); + cmdmove[2] = 224; + AAS_ClearShownDebugLines(); + AAS_PredictClientMovement( &move, entnum, origin, PRESENCE_NORMAL, qtrue, + velocity, cmdmove, 13, 13, 0.1, SE_HITGROUND, 0, qtrue ); //SE_LEAVEGROUND); + if ( move.stopevent & SE_LEAVEGROUND ) { + botimport.Print( PRT_MESSAGE, "leave ground\n" ); + } //end if +} //end of the function TestMovementPrediction +//=========================================================================== +// calculates the horizontal velocity needed to perform a jump from start +// to end +// +// Parameter: zvel : z velocity for jump +// start : start position of jump +// end : end position of jump +// *speed : returned speed for jump +// Returns: qfalse if too high or too far from start to end +// Changes Globals: - +//=========================================================================== +int AAS_HorizontalVelocityForJump( float zvel, vec3_t start, vec3_t end, float *velocity ) { + float sv_gravity, sv_maxvelocity; + float maxjump, height2fall, t, top; + vec3_t dir; + + sv_gravity = aassettings.sv_gravity; + sv_maxvelocity = aassettings.sv_maxvelocity; + + //maximum height a player can jump with the given initial z velocity + maxjump = 0.5 * sv_gravity * ( zvel / sv_gravity ) * ( zvel / sv_gravity ); + //top of the parabolic jump + top = start[2] + maxjump; + //height the bot will fall from the top + height2fall = top - end[2]; + //if the goal is to high to jump to + if ( height2fall < 0 ) { + *velocity = sv_maxvelocity; + return 0; + } //end if + //time a player takes to fall the height + t = sqrt( height2fall / ( 0.5 * sv_gravity ) ); + //direction from start to end + VectorSubtract( end, start, dir ); + //calculate horizontal speed + *velocity = sqrt( dir[0] * dir[0] + dir[1] * dir[1] ) / ( t + zvel / sv_gravity ); + //the horizontal speed must be lower than the max speed + if ( *velocity > sv_maxvelocity ) { + *velocity = sv_maxvelocity; + return 0; + } //end if + return 1; +} //end of the function AAS_HorizontalVelocityForJump diff --git a/Projects/Android/jni/rtcw/src/botlib/be_aas_move.h b/Projects/Android/jni/rtcw/src/botlib/be_aas_move.h new file mode 100644 index 0000000..4771be0 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/botlib/be_aas_move.h @@ -0,0 +1,69 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +/***************************************************************************** + * name: be_aas_move.h + * + * desc: AAS + * + * + *****************************************************************************/ + +#ifdef AASINTERN +extern aas_settings_t aassettings; +#endif //AASINTERN + +//movement prediction +int AAS_PredictClientMovement( struct aas_clientmove_s *move, + int entnum, vec3_t origin, + int presencetype, int onground, + vec3_t velocity, vec3_t cmdmove, + int cmdframes, + int maxframes, float frametime, + int stopevent, int stopareanum, int visualize ); +//returns true if on the ground at the given origin +int AAS_OnGround( vec3_t origin, int presencetype, int passent ); +//returns true if swimming at the given origin +int AAS_Swimming( vec3_t origin ); +//returns the jump reachability run start point +void AAS_JumpReachRunStart( struct aas_reachability_s *reach, vec3_t runstart ); +//returns true if against a ladder at the given origin +int AAS_AgainstLadder( vec3_t origin, int ms_areanum ); +//rocket jump Z velocity when rocket-jumping at origin +float AAS_RocketJumpZVelocity( vec3_t origin ); +//bfg jump Z velocity when bfg-jumping at origin +float AAS_BFGJumpZVelocity( vec3_t origin ); +//calculates the horizontal velocity needed for a jump and returns true this velocity could be calculated +int AAS_HorizontalVelocityForJump( float zvel, vec3_t start, vec3_t end, float *velocity ); +// +void AAS_SetMovedir( vec3_t angles, vec3_t movedir ); +// +int AAS_DropToFloor( vec3_t origin, vec3_t mins, vec3_t maxs ); +// +void AAS_InitSettings( void ); diff --git a/Projects/Android/jni/rtcw/src/botlib/be_aas_optimize.c b/Projects/Android/jni/rtcw/src/botlib/be_aas_optimize.c new file mode 100644 index 0000000..32bd80e --- /dev/null +++ b/Projects/Android/jni/rtcw/src/botlib/be_aas_optimize.c @@ -0,0 +1,337 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +/***************************************************************************** + * name: be_aas_optimize.c + * + * desc: decreases the .aas file size after the reachabilities have + * been calculated, just dumps all the faces, edges and vertexes + * + * + *****************************************************************************/ + +#include "../game/q_shared.h" +#include "l_libvar.h" +//#include "l_utils.h" +#include "l_memory.h" +#include "l_script.h" +#include "l_precomp.h" +#include "l_struct.h" +#include "aasfile.h" +#include "../game/botlib.h" +#include "../game/be_aas.h" +#include "be_aas_funcs.h" +#include "be_interface.h" +#include "be_aas_def.h" + +typedef struct optimized_s +{ + //vertixes + int numvertexes; + aas_vertex_t *vertexes; + //edges + int numedges; + aas_edge_t *edges; + //edge index + int edgeindexsize; + aas_edgeindex_t *edgeindex; + //faces + int numfaces; + aas_face_t *faces; + //face index + int faceindexsize; + aas_faceindex_t *faceindex; + //convex areas + int numareas; + aas_area_t *areas; + // + int *vertexoptimizeindex; + int *edgeoptimizeindex; + int *faceoptimizeindex; +} optimized_t; + +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_KeepEdge( aas_edge_t *edge ) { + return 1; +} //end of the function AAS_KeepFace +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_OptimizeEdge( optimized_t *optimized, int edgenum ) { + int i, optedgenum; + aas_edge_t *edge, *optedge; + + edge = &( *aasworld ).edges[abs( edgenum )]; + if ( !AAS_KeepEdge( edge ) ) { + return 0; + } + + optedgenum = optimized->edgeoptimizeindex[abs( edgenum )]; + if ( optedgenum ) { + //keep the edge reversed sign + if ( edgenum > 0 ) { + return optedgenum; + } else { return -optedgenum;} + } //end if + + optedge = &optimized->edges[optimized->numedges]; + + for ( i = 0; i < 2; i++ ) + { + if ( optimized->vertexoptimizeindex[edge->v[i]] ) { + optedge->v[i] = optimized->vertexoptimizeindex[edge->v[i]]; + } //end if + else + { + VectorCopy( ( *aasworld ).vertexes[edge->v[i]], optimized->vertexes[optimized->numvertexes] ); + optedge->v[i] = optimized->numvertexes; + optimized->vertexoptimizeindex[edge->v[i]] = optimized->numvertexes; + optimized->numvertexes++; + } //end else + } //end for + optimized->edgeoptimizeindex[abs( edgenum )] = optimized->numedges; + optedgenum = optimized->numedges; + optimized->numedges++; + //keep the edge reversed sign + if ( edgenum > 0 ) { + return optedgenum; + } else { return -optedgenum;} +} //end of the function AAS_OptimizeEdge +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_KeepFace( aas_face_t *face ) { + if ( !( face->faceflags & FACE_LADDER ) ) { + return 0; + } else { return 1;} +} //end of the function AAS_KeepFace +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_OptimizeFace( optimized_t *optimized, int facenum ) { + int i, edgenum, optedgenum, optfacenum; + aas_face_t *face, *optface; + + face = &( *aasworld ).faces[abs( facenum )]; + if ( !AAS_KeepFace( face ) ) { + return 0; + } + + optfacenum = optimized->faceoptimizeindex[abs( facenum )]; + if ( optfacenum ) { + //keep the face side sign + if ( facenum > 0 ) { + return optfacenum; + } else { return -optfacenum;} + } //end if + + optface = &optimized->faces[optimized->numfaces]; + memcpy( optface, face, sizeof( aas_face_t ) ); + + optface->numedges = 0; + optface->firstedge = optimized->edgeindexsize; + for ( i = 0; i < face->numedges; i++ ) + { + edgenum = ( *aasworld ).edgeindex[face->firstedge + i]; + optedgenum = AAS_OptimizeEdge( optimized, edgenum ); + if ( optedgenum ) { + optimized->edgeindex[optface->firstedge + optface->numedges] = optedgenum; + optface->numedges++; + optimized->edgeindexsize++; + } //end if + } //end for + optimized->faceoptimizeindex[abs( facenum )] = optimized->numfaces; + optfacenum = optimized->numfaces; + optimized->numfaces++; + //keep the face side sign + if ( facenum > 0 ) { + return optfacenum; + } else { return -optfacenum;} +} //end of the function AAS_OptimizeFace +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_OptimizeArea( optimized_t *optimized, int areanum ) { + int i, facenum, optfacenum; + aas_area_t *area, *optarea; + + area = &( *aasworld ).areas[areanum]; + optarea = &optimized->areas[areanum]; + memcpy( optarea, area, sizeof( aas_area_t ) ); + + optarea->numfaces = 0; + optarea->firstface = optimized->faceindexsize; + for ( i = 0; i < area->numfaces; i++ ) + { + facenum = ( *aasworld ).faceindex[area->firstface + i]; + optfacenum = AAS_OptimizeFace( optimized, facenum ); + if ( optfacenum ) { + optimized->faceindex[optarea->firstface + optarea->numfaces] = optfacenum; + optarea->numfaces++; + optimized->faceindexsize++; + } //end if + } //end for +} //end of the function AAS_OptimizeArea +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_OptimizeAlloc( optimized_t *optimized ) { + optimized->vertexes = (aas_vertex_t *) GetClearedMemory( ( *aasworld ).numvertexes * sizeof( aas_vertex_t ) ); + optimized->numvertexes = 0; + optimized->edges = (aas_edge_t *) GetClearedMemory( ( *aasworld ).numedges * sizeof( aas_edge_t ) ); + optimized->numedges = 1; //edge zero is a dummy + optimized->edgeindex = (aas_edgeindex_t *) GetClearedMemory( ( *aasworld ).edgeindexsize * sizeof( aas_edgeindex_t ) ); + optimized->edgeindexsize = 0; + optimized->faces = (aas_face_t *) GetClearedMemory( ( *aasworld ).numfaces * sizeof( aas_face_t ) ); + optimized->numfaces = 1; //face zero is a dummy + optimized->faceindex = (aas_faceindex_t *) GetClearedMemory( ( *aasworld ).faceindexsize * sizeof( aas_faceindex_t ) ); + optimized->faceindexsize = 0; + optimized->areas = (aas_area_t *) GetClearedMemory( ( *aasworld ).numareas * sizeof( aas_area_t ) ); + optimized->numareas = ( *aasworld ).numareas; + // + optimized->vertexoptimizeindex = (int *) GetClearedMemory( ( *aasworld ).numvertexes * sizeof( int ) ); + optimized->edgeoptimizeindex = (int *) GetClearedMemory( ( *aasworld ).numedges * sizeof( int ) ); + optimized->faceoptimizeindex = (int *) GetClearedMemory( ( *aasworld ).numfaces * sizeof( int ) ); +} //end of the function AAS_OptimizeAlloc +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_OptimizeStore( optimized_t *optimized ) { + //store the optimized vertexes + if ( ( *aasworld ).vertexes ) { + FreeMemory( ( *aasworld ).vertexes ); + } + ( *aasworld ).vertexes = optimized->vertexes; + ( *aasworld ).numvertexes = optimized->numvertexes; + //store the optimized edges + if ( ( *aasworld ).edges ) { + FreeMemory( ( *aasworld ).edges ); + } + ( *aasworld ).edges = optimized->edges; + ( *aasworld ).numedges = optimized->numedges; + //store the optimized edge index + if ( ( *aasworld ).edgeindex ) { + FreeMemory( ( *aasworld ).edgeindex ); + } + ( *aasworld ).edgeindex = optimized->edgeindex; + ( *aasworld ).edgeindexsize = optimized->edgeindexsize; + //store the optimized faces + if ( ( *aasworld ).faces ) { + FreeMemory( ( *aasworld ).faces ); + } + ( *aasworld ).faces = optimized->faces; + ( *aasworld ).numfaces = optimized->numfaces; + //store the optimized face index + if ( ( *aasworld ).faceindex ) { + FreeMemory( ( *aasworld ).faceindex ); + } + ( *aasworld ).faceindex = optimized->faceindex; + ( *aasworld ).faceindexsize = optimized->faceindexsize; + //store the optimized areas + if ( ( *aasworld ).areas ) { + FreeMemory( ( *aasworld ).areas ); + } + ( *aasworld ).areas = optimized->areas; + ( *aasworld ).numareas = optimized->numareas; + //free optimize indexes + FreeMemory( optimized->vertexoptimizeindex ); + FreeMemory( optimized->edgeoptimizeindex ); + FreeMemory( optimized->faceoptimizeindex ); +} //end of the function AAS_OptimizeStore +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_Optimize( void ) { + int i, sign; + optimized_t optimized; + + AAS_OptimizeAlloc( &optimized ); + for ( i = 1; i < ( *aasworld ).numareas; i++ ) + { + AAS_OptimizeArea( &optimized, i ); + } //end for + //reset the reachability face pointers + for ( i = 0; i < ( *aasworld ).reachabilitysize; i++ ) + { + //NOTE: for TRAVEL_ELEVATOR the facenum is the model number of + // the elevator + if ( ( *aasworld ).reachability[i].traveltype == TRAVEL_ELEVATOR ) { + continue; + } + //NOTE: for TRAVEL_JUMPPAD the facenum is the Z velocity and the edgenum is the hor velocity + if ( ( *aasworld ).reachability[i].traveltype == TRAVEL_JUMPPAD ) { + continue; + } + //NOTE: for TRAVEL_FUNCBOB the facenum and edgenum contain other coded information + if ( ( *aasworld ).reachability[i].traveltype == TRAVEL_FUNCBOB ) { + continue; + } + // + sign = ( *aasworld ).reachability[i].facenum; + ( *aasworld ).reachability[i].facenum = optimized.faceoptimizeindex[abs( ( *aasworld ).reachability[i].facenum )]; + if ( sign < 0 ) { + ( *aasworld ).reachability[i].facenum = -( *aasworld ).reachability[i].facenum; + } + sign = ( *aasworld ).reachability[i].edgenum; + ( *aasworld ).reachability[i].edgenum = optimized.edgeoptimizeindex[abs( ( *aasworld ).reachability[i].edgenum )]; + if ( sign < 0 ) { + ( *aasworld ).reachability[i].edgenum = -( *aasworld ).reachability[i].edgenum; + } + } //end for + //store the optimized AAS data into (*aasworld) + AAS_OptimizeStore( &optimized ); + //print some nice stuff :) + botimport.Print( PRT_MESSAGE, "AAS data optimized.\n" ); +} //end of the function AAS_Optimize diff --git a/Projects/Android/jni/rtcw/src/botlib/be_aas_optimize.h b/Projects/Android/jni/rtcw/src/botlib/be_aas_optimize.h new file mode 100644 index 0000000..7ef522e --- /dev/null +++ b/Projects/Android/jni/rtcw/src/botlib/be_aas_optimize.h @@ -0,0 +1,39 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +/***************************************************************************** + * name: be_aas_optimize.h + * + * desc: AAS + * + * + *****************************************************************************/ + +void AAS_Optimize( void ); + diff --git a/Projects/Android/jni/rtcw/src/botlib/be_aas_reach.c b/Projects/Android/jni/rtcw/src/botlib/be_aas_reach.c new file mode 100644 index 0000000..0970784 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/botlib/be_aas_reach.c @@ -0,0 +1,4480 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + + +/***************************************************************************** + * name: be_aas_reach.c + * + * desc: reachability calculations + * + * + *****************************************************************************/ + +#include "../game/q_shared.h" +#include "l_log.h" +#include "l_memory.h" +#include "l_script.h" +#include "l_libvar.h" +#include "l_precomp.h" +#include "l_struct.h" +#include "aasfile.h" +#include "../game/botlib.h" +#include "../game/be_aas.h" +#include "be_aas_funcs.h" +#include "be_aas_def.h" + +extern int Sys_MilliSeconds( void ); + +//#include "../../../gladiator/bspc/aas_store.h" + +extern botlib_import_t botimport; + +//#define REACHDEBUG + +//NOTE: all travel times are in hundreth of a second +//maximum fall delta before getting damaged + +// Ridah, tweaked for Wolf AI +#define FALLDELTA_5DAMAGE 25 //40 +#define FALLDELTA_10DAMAGE 40 //60 +// done. + +//maximum number of reachability links +#define AAS_MAX_REACHABILITYSIZE 65536 +//number of areas reachability is calculated for each frame +#define REACHABILITYAREASPERCYCLE 15 +//number of units reachability points are placed inside the areas +#define INSIDEUNITS 2 + +// Ridah, tweaked this, routing issues around small areas +#define INSIDEUNITS_WALKEND 5 // original +//#define INSIDEUNITS_WALKEND 0.2 // new + +// Ridah, added this for better walking off ledges +#define INSIDEUNITS_WALKOFFLEDGEEND 15 + +#define INSIDEUNITS_WALKSTART 0.1 +#define INSIDEUNITS_WATERJUMP 15 +//travel times in hundreth of a second + +// Ridah, tweaked these for Wolf AI +#define REACH_MIN_TIME 4 // always at least this much time for a reachability +#define WATERJUMP_TIME 700 //7 seconds +#define TELEPORT_TIME 50 //0.5 seconds +#define BARRIERJUMP_TIME 900 //fixed value? +#define STARTCROUCH_TIME 300 //3 sec to start crouching +#define STARTGRAPPLE_TIME 500 //using the grapple costs a lot of time +#define STARTWALKOFFLEDGE_TIME 300 //3 seconds +#define STARTJUMP_TIME 500 //3 seconds for jumping + +#define FALLDAMAGE_5_TIME 400 //extra travel time when falling hurts +#define FALLDAMAGE_10_TIME 900 //extra travel time when falling hurts +// done. + +//maximum height the bot may fall down when jumping +#define MAX_JUMPFALLHEIGHT 450 +//area flag used for weapon jumping +#define AREA_WEAPONJUMP 8192 //valid area to weapon jump to +//number of reachabilities of each type +int reach_swim; //swim +int reach_equalfloor; //walk on floors with equal height +int reach_step; //step up +int reach_walk; //walk of step +int reach_barrier; //jump up to a barrier +int reach_waterjump; //jump out of water +int reach_walkoffledge; //walk of a ledge +int reach_jump; //jump +int reach_ladder; //climb or descent a ladder +int reach_teleport; //teleport +int reach_elevator; //use an elevator +int reach_funcbob; //use a func bob +int reach_grapple; //grapple hook +int reach_doublejump; //double jump +int reach_rampjump; //ramp jump +int reach_strafejump; //strafe jump (just normal jump but further) +int reach_rocketjump; //rocket jump +int reach_bfgjump; //bfg jump +int reach_jumppad; //jump pads +//if true grapple reachabilities are skipped +int calcgrapplereach; +//linked reachability +typedef struct aas_lreachability_s +{ + int areanum; //number of the reachable area + int facenum; //number of the face towards the other area + int edgenum; //number of the edge towards the other area + vec3_t start; //start point of inter area movement + vec3_t end; //end point of inter area movement + int traveltype; //type of travel required to get to the area + unsigned short int traveltime; //travel time of the inter area movement + // + struct aas_lreachability_s *next; +} aas_lreachability_t; +//temporary reachabilities +aas_lreachability_t *reachabilityheap; //heap with reachabilities +aas_lreachability_t *nextreachability; //next free reachability from the heap +aas_lreachability_t **areareachability; //reachability links for every area +int numlreachabilities; + +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_BestReachableLinkArea( aas_link_t *areas ) { + aas_link_t *link; + + for ( link = areas; link; link = link->next_area ) + { + if ( AAS_AreaGrounded( link->areanum ) || AAS_AreaSwim( link->areanum ) ) { + return link->areanum; + } //end if + } //end for + // + for ( link = areas; link; link = link->next_area ) + { + if ( link->areanum ) { + return link->areanum; + } + //FIXME: cannot enable next line right now because the reachability + // does not have to be calculated when the level items are loaded + //if (AAS_AreaReachability(link->areanum)) return link->areanum; + } //end for + return 0; +} //end of the function AAS_BestReachableLinkArea +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_BestReachableArea( vec3_t origin, vec3_t mins, vec3_t maxs, vec3_t goalorigin ) { + int areanum, i, j, k, l; + aas_link_t *areas; + vec3_t absmins, absmaxs; + //vec3_t bbmins, bbmaxs; + vec3_t start, end; + aas_trace_t trace; + + if ( !( *aasworld ).loaded ) { + botimport.Print( PRT_ERROR, "AAS_BestReachableArea: aas not loaded\n" ); + return 0; + } //end if + //find a point in an area + VectorCopy( origin, start ); + areanum = AAS_PointAreaNum( start ); + //while no area found fudge around a little + for ( i = 0; i < 5 && !areanum; i++ ) + { + for ( j = 0; j < 5 && !areanum; j++ ) + { + for ( k = -1; k <= 1 && !areanum; k++ ) + { + for ( l = -1; l <= 1 && !areanum; l++ ) + { + VectorCopy( origin, start ); + start[0] += (float) j * 4 * k; + start[1] += (float) j * 4 * l; + start[2] += (float) i * 4; + areanum = AAS_PointAreaNum( start ); + } //end for + } //end for + } //end for + } //end for + //if an area was found + if ( areanum ) { + //drop client bbox down and try again + VectorCopy( start, end ); + start[2] += 0.25; + end[2] -= 50; + trace = AAS_TraceClientBBox( start, end, PRESENCE_CROUCH, -1 ); + if ( !trace.startsolid ) { + areanum = AAS_PointAreaNum( trace.endpos ); + VectorCopy( trace.endpos, goalorigin ); + //FIXME: cannot enable next line right now because the reachability + // does not have to be calculated when the level items are loaded + //if the origin is in an area with reachability + //if (AAS_AreaReachability(areanum)) return areanum; + if ( areanum ) { + return areanum; + } + } //end if + else + { + //it can very well happen that the AAS_PointAreaNum function tells that + //a point is in an area and that starting a AAS_TraceClientBBox from that + //point will return trace.startsolid qtrue + /* + if (AAS_PointAreaNum(start)) + { + Log_Write("point %f %f %f in area %d but trace startsolid", start[0], start[1], start[2], areanum); + AAS_DrawPermanentCross(start, 4, LINECOLOR_RED); + } //end if + botimport.Print(PRT_MESSAGE, "AAS_BestReachableArea: start solid\n"); + */ + VectorCopy( start, goalorigin ); + return areanum; + } //end else + } //end if + // + //AAS_PresenceTypeBoundingBox(PRESENCE_CROUCH, bbmins, bbmaxs); + //NOTE: the goal origin does not have to be in the goal area + // because the bot will have to move towards the item origin anyway + VectorCopy( origin, goalorigin ); + // + VectorAdd( origin, mins, absmins ); + VectorAdd( origin, maxs, absmaxs ); + //add bounding box size + //VectorSubtract(absmins, bbmaxs, absmins); + //VectorSubtract(absmaxs, bbmins, absmaxs); + //link an invalid (-1) entity + areas = AAS_AASLinkEntity( absmins, absmaxs, -1 ); + //get the reachable link arae + areanum = AAS_BestReachableLinkArea( areas ); + //unlink the invalid entity + AAS_UnlinkFromAreas( areas ); + // + return areanum; +} //end of the function AAS_BestReachableArea +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_SetupReachabilityHeap( void ) { + int i; + + reachabilityheap = (aas_lreachability_t *) GetClearedMemory( + AAS_MAX_REACHABILITYSIZE * sizeof( aas_lreachability_t ) ); + for ( i = 0; i < AAS_MAX_REACHABILITYSIZE - 1; i++ ) + { + reachabilityheap[i].next = &reachabilityheap[i + 1]; + } //end for + reachabilityheap[AAS_MAX_REACHABILITYSIZE - 1].next = NULL; + nextreachability = reachabilityheap; + numlreachabilities = 0; +} //end of the function AAS_InitReachabilityHeap +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_ShutDownReachabilityHeap( void ) { + FreeMemory( reachabilityheap ); + numlreachabilities = 0; +} //end of the function AAS_ShutDownReachabilityHeap +//=========================================================================== +// returns a reachability link +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +aas_lreachability_t *AAS_AllocReachability( void ) { + aas_lreachability_t *r; + + if ( !nextreachability ) { + return NULL; + } + //make sure the error message only shows up once + if ( !nextreachability->next ) { + AAS_Error( "AAS_MAX_REACHABILITYSIZE" ); + } + // + r = nextreachability; + nextreachability = nextreachability->next; + numlreachabilities++; + return r; +} //end of the function AAS_AllocReachability +//=========================================================================== +// frees a reachability link +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_FreeReachability( aas_lreachability_t *lreach ) { + memset( lreach, 0, sizeof( aas_lreachability_t ) ); + + lreach->next = nextreachability; + nextreachability = lreach; + numlreachabilities--; +} //end of the function AAS_FreeReachability +//=========================================================================== +// returns qtrue if the area has reachability links +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_AreaReachability( int areanum ) { + if ( areanum < 0 || areanum >= ( *aasworld ).numareas ) { + AAS_Error( "AAS_AreaReachability: areanum %d out of range", areanum ); + return 0; + } //end if + // RF, if this area is disabled, then fail + if ( ( *aasworld ).areasettings[areanum].areaflags & AREA_DISABLED ) { + return 0; + } + return ( *aasworld ).areasettings[areanum].numreachableareas; +} //end of the function AAS_AreaReachability +//=========================================================================== +// returns the surface area of the given face +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +float AAS_FaceArea( aas_face_t *face ) { + int i, edgenum, side; + float total; + vec_t *v; + vec3_t d1, d2, cross; + aas_edge_t *edge; + + edgenum = ( *aasworld ).edgeindex[face->firstedge]; + side = edgenum < 0; + edge = &( *aasworld ).edges[abs( edgenum )]; + v = ( *aasworld ).vertexes[edge->v[side]]; + + total = 0; + for ( i = 1; i < face->numedges - 1; i++ ) + { + edgenum = ( *aasworld ).edgeindex[face->firstedge + i]; + side = edgenum < 0; + edge = &( *aasworld ).edges[abs( edgenum )]; + VectorSubtract( ( *aasworld ).vertexes[edge->v[side]], v, d1 ); + VectorSubtract( ( *aasworld ).vertexes[edge->v[!side]], v, d2 ); + CrossProduct( d1, d2, cross ); + total += 0.5 * VectorLength( cross ); + } //end for + return total; +} //end of the function AAS_FaceArea +//=========================================================================== +// returns the volume of an area +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +float AAS_AreaVolume( int areanum ) { + int i, edgenum, facenum; + vec_t d, a, volume; + vec3_t corner; + aas_plane_t *plane; + aas_edge_t *edge; + aas_face_t *face; + aas_area_t *area; + + area = &( *aasworld ).areas[areanum]; + facenum = ( *aasworld ).faceindex[area->firstface]; + face = &( *aasworld ).faces[abs( facenum )]; + edgenum = ( *aasworld ).edgeindex[face->firstedge]; + edge = &( *aasworld ).edges[abs( edgenum )]; + // + VectorCopy( ( *aasworld ).vertexes[edge->v[0]], corner ); + + //make tetrahedrons to all other faces + volume = 0; + for ( i = 0; i < area->numfaces; i++ ) + { + facenum = abs( ( *aasworld ).faceindex[area->firstface + i] ); + face = &( *aasworld ).faces[facenum]; + plane = &( *aasworld ).planes[face->planenum]; + d = -( DotProduct( corner, plane->normal ) - plane->dist ); + a = AAS_FaceArea( face ); + volume += d * a; + } //end for + + volume /= 3; + return volume; +} //end of the function AAS_AreaVolume +//=========================================================================== +// returns the surface area of all ground faces together of the area +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +float AAS_AreaGroundFaceArea( int areanum ) { + int i; + float total; + aas_area_t *area; + aas_face_t *face; + + total = 0; + area = &( *aasworld ).areas[areanum]; + for ( i = 0; i < area->numfaces; i++ ) + { + face = &( *aasworld ).faces[abs( ( *aasworld ).faceindex[area->firstface + i] )]; + if ( !( face->faceflags & FACE_GROUND ) ) { + continue; + } + // + total += AAS_FaceArea( face ); + } //end for + return total; +} //end of the function AAS_AreaGroundFaceArea +//=========================================================================== +// returns the center of a face +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_FaceCenter( int facenum, vec3_t center ) { + int i; + float scale; + aas_face_t *face; + aas_edge_t *edge; + + face = &( *aasworld ).faces[facenum]; + + VectorClear( center ); + for ( i = 0; i < face->numedges; i++ ) + { + edge = &( *aasworld ).edges[abs( ( *aasworld ).edgeindex[face->firstedge + i] )]; + VectorAdd( center, ( *aasworld ).vertexes[edge->v[0]], center ); + VectorAdd( center, ( *aasworld ).vertexes[edge->v[1]], center ); + } //end for + scale = 0.5 / face->numedges; + VectorScale( center, scale, center ); +} //end of the function AAS_FaceCenter +//=========================================================================== +// returns the maximum distance a player can fall before being damaged +// damage = deltavelocity*deltavelocity * 0.0001 +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_FallDamageDistance( void ) { + float maxzvelocity, gravity, t; + + maxzvelocity = sqrt( 30 * 10000 ); + gravity = aassettings.sv_gravity; + t = maxzvelocity / gravity; + return 0.5 * gravity * t * t; +} //end of the function AAS_FallDamageDistance +//=========================================================================== +// distance = 0.5 * gravity * t * t +// vel = t * gravity +// damage = vel * vel * 0.0001 +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +float AAS_FallDelta( float distance ) { + float t, delta, gravity; + + gravity = aassettings.sv_gravity; + t = sqrt( fabs( distance ) * 2 / gravity ); + delta = t * gravity; + return delta * delta * 0.0001; +} //end of the function AAS_FallDelta +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +float AAS_MaxJumpHeight( float sv_jumpvel ) { + float sv_gravity; + + sv_gravity = aassettings.sv_gravity; + //maximum height a player can jump with the given initial z velocity + return 0.5 * sv_gravity * ( sv_jumpvel / sv_gravity ) * ( sv_jumpvel / sv_gravity ); +} //end of the function MaxJumpHeight +//=========================================================================== +// returns true if a player can only crouch in the area +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +float AAS_MaxJumpDistance( float sv_jumpvel ) { + float sv_gravity, sv_maxvelocity, t; + + sv_gravity = aassettings.sv_gravity; + sv_maxvelocity = aassettings.sv_maxvelocity; + //time a player takes to fall the height + t = sqrt( MAX_JUMPFALLHEIGHT / ( 0.5 * sv_gravity ) ); + //maximum distance + return sv_maxvelocity * ( t + sv_jumpvel / sv_gravity ); +} //end of the function AAS_MaxJumpDistance +//=========================================================================== +// returns true if a player can only crouch in the area +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_AreaCrouch( int areanum ) { + if ( !( ( *aasworld ).areasettings[areanum].presencetype & PRESENCE_NORMAL ) ) { + return qtrue; + } else { return qfalse;} +} //end of the function AAS_AreaCrouch +//=========================================================================== +// returns qtrue if it is possible to swim in the area +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_AreaSwim( int areanum ) { + if ( ( *aasworld ).areasettings[areanum].areaflags & AREA_LIQUID ) { + return qtrue; + } else { return qfalse;} +} //end of the function AAS_AreaSwim +//=========================================================================== +// returns qtrue if the area contains a liquid +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_AreaLiquid( int areanum ) { + if ( ( *aasworld ).areasettings[areanum].areaflags & AREA_LIQUID ) { + return qtrue; + } else { return qfalse;} +} //end of the function AAS_AreaLiquid +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_AreaLava( int areanum ) { + return ( ( *aasworld ).areasettings[areanum].contents & AREACONTENTS_LAVA ); +} //end of the function AAS_AreaLava +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_AreaSlime( int areanum ) { + return ( ( *aasworld ).areasettings[areanum].contents & AREACONTENTS_SLIME ); +} //end of the function AAS_AreaSlime +//=========================================================================== +// returns qtrue if the area contains ground faces +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_AreaGrounded( int areanum ) { + return ( ( *aasworld ).areasettings[areanum].areaflags & AREA_GROUNDED ); +} //end of the function AAS_AreaGround +//=========================================================================== +// returns true if the area contains ladder faces +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_AreaLadder( int areanum ) { + return ( ( *aasworld ).areasettings[areanum].areaflags & AREA_LADDER ); +} //end of the function AAS_AreaLadder +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_AreaJumpPad( int areanum ) { + return ( ( *aasworld ).areasettings[areanum].contents & AREACONTENTS_JUMPPAD ); +} //end of the function AAS_AreaJumpPad +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_AreaTeleporter( int areanum ) { + return ( ( *aasworld ).areasettings[areanum].contents & AREACONTENTS_TELEPORTER ); +} //end of the function AAS_AreaTeleporter +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_AreaDoNotEnter( int areanum ) { + return ( ( *aasworld ).areasettings[areanum].contents & AREACONTENTS_DONOTENTER ); +} //end of the function AAS_AreaDoNotEnter +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_AreaDoNotEnterLarge( int areanum ) { + return ( ( *aasworld ).areasettings[areanum].contents & AREACONTENTS_DONOTENTER_LARGE ); +} //end of the function AAS_AreaDoNotEnter +//=========================================================================== +// returns the time it takes perform a barrier jump +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +unsigned short int AAS_BarrierJumpTravelTime( void ) { + return aassettings.sv_jumpvel / ( aassettings.sv_gravity * 0.1 ); +} //end op the function AAS_BarrierJumpTravelTime +//=========================================================================== +// returns true if there already exists a reachability from area1 to area2 +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +qboolean AAS_ReachabilityExists( int area1num, int area2num ) { + aas_lreachability_t *r; + + for ( r = areareachability[area1num]; r; r = r->next ) + { + if ( r->areanum == area2num ) { + return qtrue; + } + } //end for + return qfalse; +} //end of the function AAS_ReachabilityExists +//=========================================================================== +// returns true if there is a solid just after the end point when going +// from start to end +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_NearbySolidOrGap( vec3_t start, vec3_t end ) { + vec3_t dir, testpoint; + int areanum; + + VectorSubtract( end, start, dir ); + dir[2] = 0; + VectorNormalize( dir ); + VectorMA( end, 48, dir, testpoint ); + + areanum = AAS_PointAreaNum( testpoint ); + if ( !areanum ) { + testpoint[2] += 16; + areanum = AAS_PointAreaNum( testpoint ); + if ( !areanum ) { + return qtrue; + } + } //end if + VectorMA( end, 64, dir, testpoint ); + areanum = AAS_PointAreaNum( testpoint ); + if ( areanum ) { + if ( !AAS_AreaSwim( areanum ) && !AAS_AreaGrounded( areanum ) ) { + return qtrue; + } + } //end if + return qfalse; +} //end of the function AAS_SolidGapTime +//=========================================================================== +// searches for swim reachabilities between adjacent areas +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_Reachability_Swim( int area1num, int area2num ) { + int i, j, face1num, face2num, side1; + aas_area_t *area1, *area2; + aas_areasettings_t *areasettings; + aas_lreachability_t *lreach; + aas_face_t *face1; + aas_plane_t *plane; + vec3_t start; + + if ( !AAS_AreaSwim( area1num ) || !AAS_AreaSwim( area2num ) ) { + return qfalse; + } + //if the second area is crouch only + if ( !( ( *aasworld ).areasettings[area2num].presencetype & PRESENCE_NORMAL ) ) { + return qfalse; + } + + area1 = &( *aasworld ).areas[area1num]; + area2 = &( *aasworld ).areas[area2num]; + + //if the areas are not near anough + for ( i = 0; i < 3; i++ ) + { + if ( area1->mins[i] > area2->maxs[i] + 10 ) { + return qfalse; + } + if ( area1->maxs[i] < area2->mins[i] - 10 ) { + return qfalse; + } + } //end for + //find a shared face and create a reachability link + for ( i = 0; i < area1->numfaces; i++ ) + { + face1num = ( *aasworld ).faceindex[area1->firstface + i]; + side1 = face1num < 0; + face1num = abs( face1num ); + // + for ( j = 0; j < area2->numfaces; j++ ) + { + face2num = abs( ( *aasworld ).faceindex[area2->firstface + j] ); + // + if ( face1num == face2num ) { + AAS_FaceCenter( face1num, start ); + // + if ( AAS_PointContents( start ) & ( CONTENTS_LAVA | CONTENTS_SLIME | CONTENTS_WATER ) ) { + // + face1 = &( *aasworld ).faces[face1num]; + areasettings = &( *aasworld ).areasettings[area1num]; + //create a new reachability link + lreach = AAS_AllocReachability(); + if ( !lreach ) { + return qfalse; + } + lreach->areanum = area2num; + lreach->facenum = face1num; + lreach->edgenum = 0; + VectorCopy( start, lreach->start ); + plane = &( *aasworld ).planes[face1->planenum ^ side1]; + VectorMA( lreach->start, INSIDEUNITS, plane->normal, lreach->end ); + lreach->traveltype = TRAVEL_SWIM; + lreach->traveltime = 1; + //if the volume of the area is rather small + if ( AAS_AreaVolume( area2num ) < 800 ) { + lreach->traveltime += 200; + } + //if (!(AAS_PointContents(start) & MASK_WATER)) lreach->traveltime += 500; + //link the reachability + lreach->next = areareachability[area1num]; + areareachability[area1num] = lreach; + reach_swim++; + return qtrue; + } //end if + } //end if + } //end for + } //end for + return qfalse; +} //end of the function AAS_Reachability_Swim +//=========================================================================== +// searches for reachabilities between adjacent areas with equal floor +// heights +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_Reachability_EqualFloorHeight( int area1num, int area2num ) { + int i, j, edgenum, edgenum1, edgenum2, foundreach, side; + float height, bestheight, length, bestlength; + vec3_t dir, start, end, normal, invgravity, gravitydirection = {0, 0, -1}; + vec3_t edgevec; + aas_area_t *area1, *area2; + aas_face_t *face1, *face2; + aas_edge_t *edge; + aas_plane_t *plane2; + aas_lreachability_t lr, *lreach; + + if ( !AAS_AreaGrounded( area1num ) || !AAS_AreaGrounded( area2num ) ) { + return qfalse; + } + + area1 = &( *aasworld ).areas[area1num]; + area2 = &( *aasworld ).areas[area2num]; + //if the areas are not near anough in the x-y direction + for ( i = 0; i < 2; i++ ) + { + if ( area1->mins[i] > area2->maxs[i] + 10 ) { + return qfalse; + } + if ( area1->maxs[i] < area2->mins[i] - 10 ) { + return qfalse; + } + } //end for + //if area 2 is too high above area 1 + if ( area2->mins[2] > area1->maxs[2] ) { + return qfalse; + } + // + VectorCopy( gravitydirection, invgravity ); + VectorInverse( invgravity ); + // + bestheight = 99999; + bestlength = 0; + foundreach = qfalse; + memset( &lr, 0, sizeof( aas_lreachability_t ) ); //make the compiler happy + // + //check if the areas have ground faces with a common edge + //if existing use the lowest common edge for a reachability link + for ( i = 0; i < area1->numfaces; i++ ) + { + face1 = &( *aasworld ).faces[abs( ( *aasworld ).faceindex[area1->firstface + i] )]; + if ( !( face1->faceflags & FACE_GROUND ) ) { + continue; + } + // + for ( j = 0; j < area2->numfaces; j++ ) + { + face2 = &( *aasworld ).faces[abs( ( *aasworld ).faceindex[area2->firstface + j] )]; + if ( !( face2->faceflags & FACE_GROUND ) ) { + continue; + } + //if there is a common edge + for ( edgenum1 = 0; edgenum1 < face1->numedges; edgenum1++ ) + { + for ( edgenum2 = 0; edgenum2 < face2->numedges; edgenum2++ ) + { + if ( abs( ( *aasworld ).edgeindex[face1->firstedge + edgenum1] ) != + abs( ( *aasworld ).edgeindex[face2->firstedge + edgenum2] ) ) { + continue; + } + edgenum = ( *aasworld ).edgeindex[face1->firstedge + edgenum1]; + side = edgenum < 0; + edge = &( *aasworld ).edges[abs( edgenum )]; + //get the length of the edge + VectorSubtract( ( *aasworld ).vertexes[edge->v[1]], + ( *aasworld ).vertexes[edge->v[0]], dir ); + length = VectorLength( dir ); + //get the start point + VectorAdd( ( *aasworld ).vertexes[edge->v[0]], + ( *aasworld ).vertexes[edge->v[1]], start ); + VectorScale( start, 0.5, start ); + VectorCopy( start, end ); + //get the end point several units inside area2 + //and the start point several units inside area1 + //NOTE: normal is pointing into area2 because the + //face edges are stored counter clockwise + VectorSubtract( ( *aasworld ).vertexes[edge->v[side]], + ( *aasworld ).vertexes[edge->v[!side]], edgevec ); + plane2 = &( *aasworld ).planes[face2->planenum]; + CrossProduct( edgevec, plane2->normal, normal ); + VectorNormalize( normal ); + // + //VectorMA(start, -1, normal, start); + VectorMA( end, INSIDEUNITS_WALKEND, normal, end ); + VectorMA( start, INSIDEUNITS_WALKSTART, normal, start ); + end[2] += 0.125; + // + height = DotProduct( invgravity, start ); + //NOTE: if there's nearby solid or a gap area after this area + //disabled this crap + //if (AAS_NearbySolidOrGap(start, end)) height += 200; + //NOTE: disabled because it disables reachabilities to very small areas + //if (AAS_PointAreaNum(end) != area2num) continue; + //get the longest lowest edge + if ( height < bestheight || + ( height < bestheight + 1 && length > bestlength ) ) { + bestheight = height; + bestlength = length; + //create a new reachability link + lr.areanum = area2num; + lr.facenum = 0; + lr.edgenum = edgenum; + VectorCopy( start, lr.start ); + VectorCopy( end, lr.end ); + lr.traveltype = TRAVEL_WALK; + lr.traveltime = 1; + foundreach = qtrue; + } //end if + } //end for + } //end for + } //end for + } //end for + if ( foundreach ) { + //create a new reachability link + lreach = AAS_AllocReachability(); + if ( !lreach ) { + return qfalse; + } + lreach->areanum = lr.areanum; + lreach->facenum = lr.facenum; + lreach->edgenum = lr.edgenum; + VectorCopy( lr.start, lreach->start ); + VectorCopy( lr.end, lreach->end ); + lreach->traveltype = lr.traveltype; + lreach->traveltime = lr.traveltime; + lreach->next = areareachability[area1num]; + areareachability[area1num] = lreach; + //if going into a crouch area + if ( !AAS_AreaCrouch( area1num ) && AAS_AreaCrouch( area2num ) ) { + lreach->traveltime += STARTCROUCH_TIME; + } //end if + /* + //NOTE: if there's nearby solid or a gap area after this area + if (!AAS_NearbySolidOrGap(lreach->start, lreach->end)) + { + lreach->traveltime += 100; + } //end if + */ + //avoid rather small areas + //if (AAS_AreaGroundFaceArea(lreach->areanum) < 500) lreach->traveltime += 100; + // + reach_equalfloor++; + return qtrue; + } //end if + return qfalse; +} //end of the function AAS_Reachability_EqualFloorHeight +//=========================================================================== +// searches step, barrier, waterjump and walk off ledge reachabilities +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_Reachability_Step_Barrier_WaterJump_WalkOffLedge( int area1num, int area2num ) { + int i, j, k, l, edge1num, edge2num; + int ground_bestarea2groundedgenum, ground_foundreach; + int water_bestarea2groundedgenum, water_foundreach; + int side1, area1swim, faceside1, groundface1num; + float dist, dist1, dist2, diff, invgravitydot, ortdot; + float x1, x2, x3, x4, y1, y2, y3, y4, tmp, y; + float length, ground_bestlength, water_bestlength, ground_bestdist, water_bestdist; + vec3_t v1, v2, v3, v4, tmpv, p1area1, p1area2, p2area1, p2area2; + vec3_t normal, ort, edgevec, start, end, dir; + vec3_t ground_beststart, ground_bestend, ground_bestnormal; + vec3_t water_beststart, water_bestend, water_bestnormal; + vec3_t invgravity = {0, 0, 1}; + vec3_t testpoint; + aas_plane_t *plane; + aas_area_t *area1, *area2; + aas_face_t *groundface1, *groundface2, *ground_bestface1, *water_bestface1; + aas_edge_t *edge1, *edge2; + aas_lreachability_t *lreach; + aas_trace_t trace; + + //must be able to walk or swim in the first area + if ( !AAS_AreaGrounded( area1num ) && !AAS_AreaSwim( area1num ) ) { + return qfalse; + } + // + if ( !AAS_AreaGrounded( area2num ) && !AAS_AreaSwim( area2num ) ) { + return qfalse; + } + // + area1 = &( *aasworld ).areas[area1num]; + area2 = &( *aasworld ).areas[area2num]; + //if the first area contains a liquid + area1swim = AAS_AreaSwim( area1num ); + //if the areas are not near anough in the x-y direction + for ( i = 0; i < 2; i++ ) + { + if ( area1->mins[i] > area2->maxs[i] + 10 ) { + return qfalse; + } + if ( area1->maxs[i] < area2->mins[i] - 10 ) { + return qfalse; + } + } //end for + // + ground_foundreach = qfalse; + ground_bestdist = 99999; + ground_bestlength = 0; + ground_bestarea2groundedgenum = 0; + // + water_foundreach = qfalse; + water_bestdist = 99999; + water_bestlength = 0; + water_bestarea2groundedgenum = 0; + // + for ( i = 0; i < area1->numfaces; i++ ) + { + groundface1num = ( *aasworld ).faceindex[area1->firstface + i]; + faceside1 = groundface1num < 0; + groundface1 = &( *aasworld ).faces[abs( groundface1num )]; + //if this isn't a ground face + if ( !( groundface1->faceflags & FACE_GROUND ) ) { + //if we can swim in the first area + if ( area1swim ) { + //face plane must be more or less horizontal + plane = &( *aasworld ).planes[groundface1->planenum ^ ( !faceside1 )]; + if ( DotProduct( plane->normal, invgravity ) < 0.7 ) { + continue; + } + } //end if + else + { + //if we can't swim in the area it must be a ground face + continue; + } //end else + } //end if + // + for ( k = 0; k < groundface1->numedges; k++ ) + { + edge1num = ( *aasworld ).edgeindex[groundface1->firstedge + k]; + side1 = ( edge1num < 0 ); + //NOTE: for water faces we must take the side area 1 is + // on into account because the face is shared and doesn't + // have to be oriented correctly + if ( !( groundface1->faceflags & FACE_GROUND ) ) { + side1 = ( side1 == faceside1 ); + } + edge1num = abs( edge1num ); + edge1 = &( *aasworld ).edges[edge1num]; + //vertexes of the edge + VectorCopy( ( *aasworld ).vertexes[edge1->v[!side1]], v1 ); + VectorCopy( ( *aasworld ).vertexes[edge1->v[side1]], v2 ); + //get a vertical plane through the edge + //NOTE: normal is pointing into area 2 because the + //face edges are stored counter clockwise + VectorSubtract( v2, v1, edgevec ); + CrossProduct( edgevec, invgravity, normal ); + VectorNormalize( normal ); + dist = DotProduct( normal, v1 ); + //check the faces from the second area + for ( j = 0; j < area2->numfaces; j++ ) + { + groundface2 = &( *aasworld ).faces[abs( ( *aasworld ).faceindex[area2->firstface + j] )]; + //must be a ground face + if ( !( groundface2->faceflags & FACE_GROUND ) ) { + continue; + } + //check the edges of this ground face + for ( l = 0; l < groundface2->numedges; l++ ) + { + edge2num = abs( ( *aasworld ).edgeindex[groundface2->firstedge + l] ); + edge2 = &( *aasworld ).edges[edge2num]; + //vertexes of the edge + VectorCopy( ( *aasworld ).vertexes[edge2->v[0]], v3 ); + VectorCopy( ( *aasworld ).vertexes[edge2->v[1]], v4 ); + //check the distance between the two points and the vertical plane + //through the edge of area1 + diff = DotProduct( normal, v3 ) - dist; + if ( diff < -0.1 || diff > 0.1 ) { + continue; + } + diff = DotProduct( normal, v4 ) - dist; + if ( diff < -0.1 || diff > 0.1 ) { + continue; + } + // + //project the two ground edges into the step side plane + //and calculate the shortest distance between the two + //edges if they overlap in the direction orthogonal to + //the gravity direction + CrossProduct( invgravity, normal, ort ); + invgravitydot = DotProduct( invgravity, invgravity ); + ortdot = DotProduct( ort, ort ); + //projection into the step plane + //NOTE: since gravity is vertical this is just the z coordinate + y1 = v1[2]; //DotProduct(v1, invgravity) / invgravitydot; + y2 = v2[2]; //DotProduct(v2, invgravity) / invgravitydot; + y3 = v3[2]; //DotProduct(v3, invgravity) / invgravitydot; + y4 = v4[2]; //DotProduct(v4, invgravity) / invgravitydot; + // + x1 = DotProduct( v1, ort ) / ortdot; + x2 = DotProduct( v2, ort ) / ortdot; + x3 = DotProduct( v3, ort ) / ortdot; + x4 = DotProduct( v4, ort ) / ortdot; + // + if ( x1 > x2 ) { + tmp = x1; x1 = x2; x2 = tmp; + tmp = y1; y1 = y2; y2 = tmp; + VectorCopy( v1, tmpv ); VectorCopy( v2, v1 ); VectorCopy( tmpv, v2 ); + } //end if + if ( x3 > x4 ) { + tmp = x3; x3 = x4; x4 = tmp; + tmp = y3; y3 = y4; y4 = tmp; + VectorCopy( v3, tmpv ); VectorCopy( v4, v3 ); VectorCopy( tmpv, v4 ); + } //end if + //if the two projected edge lines have no overlap + if ( x2 <= x3 || x4 <= x1 ) { +// Log_Write("lines no overlap: from area %d to %d\r\n", area1num, area2num); + continue; + } //end if + //if the two lines fully overlap + if ( ( x1 - 0.5 < x3 && x4 < x2 + 0.5 ) && + ( x3 - 0.5 < x1 && x2 < x4 + 0.5 ) ) { + dist1 = y3 - y1; + dist2 = y4 - y2; + VectorCopy( v1, p1area1 ); + VectorCopy( v2, p2area1 ); + VectorCopy( v3, p1area2 ); + VectorCopy( v4, p2area2 ); + } //end if + else + { + //if the points are equal + if ( x1 > x3 - 0.1 && x1 < x3 + 0.1 ) { + dist1 = y3 - y1; + VectorCopy( v1, p1area1 ); + VectorCopy( v3, p1area2 ); + } //end if + else if ( x1 < x3 ) { + y = y1 + ( x3 - x1 ) * ( y2 - y1 ) / ( x2 - x1 ); + dist1 = y3 - y; + VectorCopy( v3, p1area1 ); + p1area1[2] = y; + VectorCopy( v3, p1area2 ); + } //end if + else + { + y = y3 + ( x1 - x3 ) * ( y4 - y3 ) / ( x4 - x3 ); + dist1 = y - y1; + VectorCopy( v1, p1area1 ); + VectorCopy( v1, p1area2 ); + p1area2[2] = y; + } //end if + //if the points are equal + if ( x2 > x4 - 0.1 && x2 < x4 + 0.1 ) { + dist2 = y4 - y2; + VectorCopy( v2, p2area1 ); + VectorCopy( v4, p2area2 ); + } //end if + else if ( x2 < x4 ) { + y = y3 + ( x2 - x3 ) * ( y4 - y3 ) / ( x4 - x3 ); + dist2 = y - y2; + VectorCopy( v2, p2area1 ); + VectorCopy( v2, p2area2 ); + p2area2[2] = y; + } //end if + else + { + y = y1 + ( x4 - x1 ) * ( y2 - y1 ) / ( x2 - x1 ); + dist2 = y4 - y; + VectorCopy( v4, p2area1 ); + p2area1[2] = y; + VectorCopy( v4, p2area2 ); + } //end else + } //end else + //if both distances are pretty much equal + //then we take the middle of the points + if ( dist1 > dist2 - 1 && dist1 < dist2 + 1 ) { + dist = dist1; + VectorAdd( p1area1, p2area1, start ); + VectorScale( start, 0.5, start ); + VectorAdd( p1area2, p2area2, end ); + VectorScale( end, 0.5, end ); + } //end if + else if ( dist1 < dist2 ) { + dist = dist1; + VectorCopy( p1area1, start ); + VectorCopy( p1area2, end ); + } //end else if + else + { + dist = dist2; + VectorCopy( p2area1, start ); + VectorCopy( p2area2, end ); + } //end else + //get the length of the overlapping part of the edges of the two areas + VectorSubtract( p2area2, p1area2, dir ); + length = VectorLength( dir ); + // + if ( groundface1->faceflags & FACE_GROUND ) { + //if the vertical distance is smaller + if ( dist < ground_bestdist || + //or the vertical distance is pretty much the same + //but the overlapping part of the edges is longer + ( dist < ground_bestdist + 1 && length > ground_bestlength ) ) { + ground_bestdist = dist; + ground_bestlength = length; + ground_foundreach = qtrue; + ground_bestarea2groundedgenum = edge1num; + ground_bestface1 = groundface1; + //best point towards area1 + VectorCopy( start, ground_beststart ); + //normal is pointing into area2 + VectorCopy( normal, ground_bestnormal ); + //best point towards area2 + VectorCopy( end, ground_bestend ); + } //end if + } //end if + else + { + //if the vertical distance is smaller + if ( dist < water_bestdist || + //or the vertical distance is pretty much the same + //but the overlapping part of the edges is longer + ( dist < water_bestdist + 1 && length > water_bestlength ) ) { + water_bestdist = dist; + water_bestlength = length; + water_foundreach = qtrue; + water_bestarea2groundedgenum = edge1num; + water_bestface1 = groundface1; + //best point towards area1 + VectorCopy( start, water_beststart ); + //normal is pointing into area2 + VectorCopy( normal, water_bestnormal ); + //best point towards area2 + VectorCopy( end, water_bestend ); + } //end if + } //end else + } //end for + } //end for + } //end for + } //end for + // + // NOTE: swim reachabilities are already filtered out + // + // Steps + // + // --------- + // | step height -> TRAVEL_WALK + //--------| + // + // --------- + //~~~~~~~~| step height and low water -> TRAVEL_WALK + //--------| + // + //~~~~~~~~~~~~~~~~~~ + // --------- + // | step height and low water up to the step -> TRAVEL_WALK + //--------| + // + //check for a step reachability + if ( ground_foundreach ) { + //if area2 is higher but lower than the maximum step height + //NOTE: ground_bestdist >= 0 also catches equal floor reachabilities + if ( ground_bestdist >= 0 && ground_bestdist < aassettings.sv_maxstep ) { + //create walk reachability from area1 to area2 + lreach = AAS_AllocReachability(); + if ( !lreach ) { + return qfalse; + } + lreach->areanum = area2num; + lreach->facenum = 0; + lreach->edgenum = ground_bestarea2groundedgenum; + VectorMA( ground_beststart, INSIDEUNITS_WALKSTART, ground_bestnormal, lreach->start ); + VectorMA( ground_bestend, INSIDEUNITS_WALKEND, ground_bestnormal, lreach->end ); + lreach->traveltype = TRAVEL_WALK; + lreach->traveltime = 0; //1; + //if going into a crouch area + if ( !AAS_AreaCrouch( area1num ) && AAS_AreaCrouch( area2num ) ) { + lreach->traveltime += STARTCROUCH_TIME; + } //end if + lreach->next = areareachability[area1num]; + areareachability[area1num] = lreach; + //NOTE: if there's nearby solid or a gap area after this area + /* + if (!AAS_NearbySolidOrGap(lreach->start, lreach->end)) + { + lreach->traveltime += 100; + } //end if + */ + //avoid rather small areas + //if (AAS_AreaGroundFaceArea(lreach->areanum) < 500) lreach->traveltime += 100; + // + reach_step++; + return qtrue; + } //end if + } //end if + // + // Water Jumps + // + // --------- + // | + //~~~~~~~~| + // | + // | higher than step height and water up to waterjump height -> TRAVEL_WATERJUMP + //--------| + // + //~~~~~~~~~~~~~~~~~~ + // --------- + // | + // | + // | + // | higher than step height and low water up to the step -> TRAVEL_WATERJUMP + //--------| + // + //check for a waterjump reachability + if ( water_foundreach ) { + //get a test point a little bit towards area1 + VectorMA( water_bestend, -INSIDEUNITS, water_bestnormal, testpoint ); + //go down the maximum waterjump height + testpoint[2] -= aassettings.sv_maxwaterjump; + //if there IS water the sv_maxwaterjump height below the bestend point + if ( ( *aasworld ).areasettings[AAS_PointAreaNum( testpoint )].areaflags & AREA_LIQUID ) { + //don't create rediculous water jump reachabilities from areas very far below + //the water surface + if ( water_bestdist < aassettings.sv_maxwaterjump + 24 ) { + //waterjumping from or towards a crouch only area is not possible in Quake2 + if ( ( ( *aasworld ).areasettings[area1num].presencetype & PRESENCE_NORMAL ) && + ( ( *aasworld ).areasettings[area2num].presencetype & PRESENCE_NORMAL ) ) { + //create water jump reachability from area1 to area2 + lreach = AAS_AllocReachability(); + if ( !lreach ) { + return qfalse; + } + lreach->areanum = area2num; + lreach->facenum = 0; + lreach->edgenum = water_bestarea2groundedgenum; + VectorCopy( water_beststart, lreach->start ); + VectorMA( water_bestend, INSIDEUNITS_WATERJUMP, water_bestnormal, lreach->end ); + lreach->traveltype = TRAVEL_WATERJUMP; + lreach->traveltime = WATERJUMP_TIME; + lreach->next = areareachability[area1num]; + areareachability[area1num] = lreach; + //we've got another waterjump reachability + reach_waterjump++; + return qtrue; + } //end if + } //end if + } //end if + } //end if + // + // Barrier Jumps + // + // --------- + // | + // | + // | + // | higher than step height lower than barrier height -> TRAVEL_BARRIERJUMP + //--------| + // + // --------- + // | + // | + // | + //~~~~~~~~| higher than step height lower than barrier height + //--------| and a thin layer of water in the area to jump from -> TRAVEL_BARRIERJUMP + // + //check for a barrier jump reachability + if ( ground_foundreach ) { + //if area2 is higher but lower than the maximum barrier jump height + if ( ground_bestdist > 0 && ground_bestdist < aassettings.sv_maxbarrier ) { + //if no water in area1 or a very thin layer of water on the ground + if ( !water_foundreach || ( ground_bestdist - water_bestdist < 16 ) ) { + //cannot perform a barrier jump towards or from a crouch area in Quake2 + if ( !AAS_AreaCrouch( area1num ) && !AAS_AreaCrouch( area2num ) ) { + //create barrier jump reachability from area1 to area2 + lreach = AAS_AllocReachability(); + if ( !lreach ) { + return qfalse; + } + lreach->areanum = area2num; + lreach->facenum = 0; + lreach->edgenum = ground_bestarea2groundedgenum; + VectorMA( ground_beststart, INSIDEUNITS_WALKSTART, ground_bestnormal, lreach->start ); + VectorMA( ground_bestend, INSIDEUNITS_WALKEND, ground_bestnormal, lreach->end ); + lreach->traveltype = TRAVEL_BARRIERJUMP; + lreach->traveltime = BARRIERJUMP_TIME; //AAS_BarrierJumpTravelTime(); + lreach->next = areareachability[area1num]; + areareachability[area1num] = lreach; + //we've got another barrierjump reachability + reach_barrier++; + return qtrue; + } //end if + } //end if + } //end if + } //end if + // + // Walk and Walk Off Ledge + // + //--------| + // | can walk or step back -> TRAVEL_WALK + // --------- + // + //--------| + // | + // | + // | + // | cannot walk/step back -> TRAVEL_WALKOFFLEDGE + // --------- + // + //--------| + // | + // |~~~~~~~~ + // | + // | cannot step back but can waterjump back -> TRAVEL_WALKOFFLEDGE + // --------- FIXME: create TRAVEL_WALK reach?? + // + //check for a walk or walk off ledge reachability + if ( ground_foundreach ) { + if ( ground_bestdist < 0 ) { + if ( ground_bestdist > -aassettings.sv_maxstep ) { + //create walk reachability from area1 to area2 + lreach = AAS_AllocReachability(); + if ( !lreach ) { + return qfalse; + } + lreach->areanum = area2num; + lreach->facenum = 0; + lreach->edgenum = ground_bestarea2groundedgenum; + VectorMA( ground_beststart, INSIDEUNITS_WALKSTART, ground_bestnormal, lreach->start ); + + // Ridah +// VectorMA(ground_bestend, INSIDEUNITS_WALKEND, ground_bestnormal, lreach->end); + VectorMA( ground_bestend, INSIDEUNITS_WALKOFFLEDGEEND, ground_bestnormal, lreach->end ); + + lreach->traveltype = TRAVEL_WALK; + lreach->traveltime = 1; + lreach->next = areareachability[area1num]; + areareachability[area1num] = lreach; + //we've got another walk reachability + reach_walk++; + return qtrue; + } //end if + //trace a bounding box vertically to check for solids + VectorMA( ground_bestend, INSIDEUNITS, ground_bestnormal, ground_bestend ); + VectorCopy( ground_bestend, start ); + start[2] = ground_beststart[2]; + VectorCopy( ground_bestend, end ); + end[2] += 4; + trace = AAS_TraceClientBBox( start, end, PRESENCE_NORMAL, -1 ); + //if no solids were found + if ( !trace.startsolid && trace.fraction >= 1.0 ) { + //the trace end point must be in the goal area + trace.endpos[2] += 1; + if ( AAS_PointAreaNum( trace.endpos ) == area2num ) { + //create a walk off ledge reachability from area1 to area2 + lreach = AAS_AllocReachability(); + if ( !lreach ) { + return qfalse; + } + lreach->areanum = area2num; + lreach->facenum = 0; + lreach->edgenum = ground_bestarea2groundedgenum; + VectorCopy( ground_beststart, lreach->start ); + VectorCopy( ground_bestend, lreach->end ); + lreach->traveltype = TRAVEL_WALKOFFLEDGE; + lreach->traveltime = STARTWALKOFFLEDGE_TIME + fabs( ground_bestdist ) * 50 / aassettings.sv_gravity; + //if falling from too high and not falling into water + if ( !AAS_AreaSwim( area2num ) && !AAS_AreaJumpPad( area2num ) ) { + if ( AAS_FallDelta( ground_bestdist ) > FALLDELTA_5DAMAGE ) { + lreach->traveltime += FALLDAMAGE_5_TIME; + } //end if + if ( AAS_FallDelta( ground_bestdist ) > FALLDELTA_10DAMAGE ) { + lreach->traveltime += FALLDAMAGE_10_TIME; + } //end if + } //end if + lreach->next = areareachability[area1num]; + areareachability[area1num] = lreach; + // + reach_walkoffledge++; + //NOTE: don't create a weapon (rl, bfg) jump reachability here + //because it interferes with other reachabilities + //like the ladder reachability + return qtrue; + } //end if + } //end if + } //end else + } //end if + return qfalse; +} //end of the function AAS_Reachability_Step_Barrier_WaterJump_WalkOffLedge +//=========================================================================== +// returns the distance between the two vectors +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +/* Ridah, moved to q_math.c +float VectorDistance(vec3_t v1, vec3_t v2) +{ + vec3_t dir; + + VectorSubtract(v2, v1, dir); + return VectorLength(dir); +} //end of the function VectorDistance +*/ +//=========================================================================== +// returns true if the first vector is between the last two vectors +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int VectorBetweenVectors( vec3_t v, vec3_t v1, vec3_t v2 ) { + vec3_t dir1, dir2; + + VectorSubtract( v, v1, dir1 ); + VectorSubtract( v, v2, dir2 ); + return ( DotProduct( dir1, dir2 ) <= 0 ); +} //end of the function VectorBetweenVectors +//=========================================================================== +// returns the mid point between the two vectors +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void VectorMiddle( vec3_t v1, vec3_t v2, vec3_t middle ) { + VectorAdd( v1, v2, middle ); + VectorScale( middle, 0.5, middle ); +} //end of the function VectorMiddle +//=========================================================================== +// calculate a range of points closest to each other on both edges +// +// Parameter: beststart1 start of the range of points on edge v1-v2 +// beststart2 end of the range of points on edge v1-v2 +// bestend1 start of the range of points on edge v3-v4 +// bestend2 end of the range of points on edge v3-v4 +// bestdist best distance so far +// Returns: - +// Changes Globals: - +//=========================================================================== +/* +float AAS_ClosestEdgePoints(vec3_t v1, vec3_t v2, vec3_t v3, vec3_t v4, + aas_plane_t *plane1, aas_plane_t *plane2, + vec3_t beststart, vec3_t bestend, float bestdist) +{ + vec3_t dir1, dir2, p1, p2, p3, p4; + float a1, a2, b1, b2, dist; + int founddist; + + //edge vectors + VectorSubtract(v2, v1, dir1); + VectorSubtract(v4, v3, dir2); + //get the horizontal directions + dir1[2] = 0; + dir2[2] = 0; + // + // p1 = point on an edge vector of area2 closest to v1 + // p2 = point on an edge vector of area2 closest to v2 + // p3 = point on an edge vector of area1 closest to v3 + // p4 = point on an edge vector of area1 closest to v4 + // + if (dir2[0]) + { + a2 = dir2[1] / dir2[0]; + b2 = v3[1] - a2 * v3[0]; + //point on the edge vector of area2 closest to v1 + p1[0] = (DotProduct(v1, dir2) - (a2 * dir2[0] + b2 * dir2[1])) / dir2[0]; + p1[1] = a2 * p1[0] + b2; + //point on the edge vector of area2 closest to v2 + p2[0] = (DotProduct(v2, dir2) - (a2 * dir2[0] + b2 * dir2[1])) / dir2[0]; + p2[1] = a2 * p2[0] + b2; + } //end if + else + { + //point on the edge vector of area2 closest to v1 + p1[0] = v3[0]; + p1[1] = v1[1]; + //point on the edge vector of area2 closest to v2 + p2[0] = v3[0]; + p2[1] = v2[1]; + } //end else + // + if (dir1[0]) + { + // + a1 = dir1[1] / dir1[0]; + b1 = v1[1] - a1 * v1[0]; + //point on the edge vector of area1 closest to v3 + p3[0] = (DotProduct(v3, dir1) - (a1 * dir1[0] + b1 * dir1[1])) / dir1[0]; + p3[1] = a1 * p3[0] + b1; + //point on the edge vector of area1 closest to v4 + p4[0] = (DotProduct(v4, dir1) - (a1 * dir1[0] + b1 * dir1[1])) / dir1[0]; + p4[1] = a1 * p4[0] + b1; + } //end if + else + { + //point on the edge vector of area1 closest to v3 + p3[0] = v1[0]; + p3[1] = v3[1]; + //point on the edge vector of area1 closest to v4 + p4[0] = v1[0]; + p4[1] = v4[1]; + } //end else + //start with zero z-coordinates + p1[2] = 0; + p2[2] = 0; + p3[2] = 0; + p4[2] = 0; + //calculate the z-coordinates from the ground planes + p1[2] = (plane2->dist - DotProduct(plane2->normal, p1)) / plane2->normal[2]; + p2[2] = (plane2->dist - DotProduct(plane2->normal, p2)) / plane2->normal[2]; + p3[2] = (plane1->dist - DotProduct(plane1->normal, p3)) / plane1->normal[2]; + p4[2] = (plane1->dist - DotProduct(plane1->normal, p4)) / plane1->normal[2]; + // + founddist = qfalse; + // + if (VectorBetweenVectors(p1, v3, v4)) + { + dist = VectorDistance(v1, p1); + if (dist > bestdist - 0.5 && dist < bestdist + 0.5) + { + VectorMiddle(beststart, v1, beststart); + VectorMiddle(bestend, p1, bestend); + } //end if + else if (dist < bestdist) + { + bestdist = dist; + VectorCopy(v1, beststart); + VectorCopy(p1, bestend); + } //end if + founddist = qtrue; + } //end if + if (VectorBetweenVectors(p2, v3, v4)) + { + dist = VectorDistance(v2, p2); + if (dist > bestdist - 0.5 && dist < bestdist + 0.5) + { + VectorMiddle(beststart, v2, beststart); + VectorMiddle(bestend, p2, bestend); + } //end if + else if (dist < bestdist) + { + bestdist = dist; + VectorCopy(v2, beststart); + VectorCopy(p2, bestend); + } //end if + founddist = qtrue; + } //end else if + if (VectorBetweenVectors(p3, v1, v2)) + { + dist = VectorDistance(v3, p3); + if (dist > bestdist - 0.5 && dist < bestdist + 0.5) + { + VectorMiddle(beststart, p3, beststart); + VectorMiddle(bestend, v3, bestend); + } //end if + else if (dist < bestdist) + { + bestdist = dist; + VectorCopy(p3, beststart); + VectorCopy(v3, bestend); + } //end if + founddist = qtrue; + } //end else if + if (VectorBetweenVectors(p4, v1, v2)) + { + dist = VectorDistance(v4, p4); + if (dist > bestdist - 0.5 && dist < bestdist + 0.5) + { + VectorMiddle(beststart, p4, beststart); + VectorMiddle(bestend, v4, bestend); + } //end if + else if (dist < bestdist) + { + bestdist = dist; + VectorCopy(p4, beststart); + VectorCopy(v4, bestend); + } //end if + founddist = qtrue; + } //end else if + //if no shortest distance was found the shortest distance + //is between one of the vertexes of edge1 and one of edge2 + if (!founddist) + { + dist = VectorDistance(v1, v3); + if (dist < bestdist) + { + bestdist = dist; + VectorCopy(v1, beststart); + VectorCopy(v3, bestend); + } //end if + dist = VectorDistance(v1, v4); + if (dist < bestdist) + { + bestdist = dist; + VectorCopy(v1, beststart); + VectorCopy(v4, bestend); + } //end if + dist = VectorDistance(v2, v3); + if (dist < bestdist) + { + bestdist = dist; + VectorCopy(v2, beststart); + VectorCopy(v3, bestend); + } //end if + dist = VectorDistance(v2, v4); + if (dist < bestdist) + { + bestdist = dist; + VectorCopy(v2, beststart); + VectorCopy(v4, bestend); + } //end if + } //end if + return bestdist; +} //end of the function AAS_ClosestEdgePoints*/ + +float AAS_ClosestEdgePoints( vec3_t v1, vec3_t v2, vec3_t v3, vec3_t v4, + aas_plane_t *plane1, aas_plane_t *plane2, + vec3_t beststart1, vec3_t bestend1, + vec3_t beststart2, vec3_t bestend2, float bestdist ) { + vec3_t dir1, dir2, p1, p2, p3, p4; + float a1, a2, b1, b2, dist, dist1, dist2; + int founddist; + + //edge vectors + VectorSubtract( v2, v1, dir1 ); + VectorSubtract( v4, v3, dir2 ); + //get the horizontal directions + dir1[2] = 0; + dir2[2] = 0; + // + // p1 = point on an edge vector of area2 closest to v1 + // p2 = point on an edge vector of area2 closest to v2 + // p3 = point on an edge vector of area1 closest to v3 + // p4 = point on an edge vector of area1 closest to v4 + // + if ( dir2[0] ) { + a2 = dir2[1] / dir2[0]; + b2 = v3[1] - a2 * v3[0]; + //point on the edge vector of area2 closest to v1 + p1[0] = ( DotProduct( v1, dir2 ) - ( a2 * dir2[0] + b2 * dir2[1] ) ) / dir2[0]; + p1[1] = a2 * p1[0] + b2; + //point on the edge vector of area2 closest to v2 + p2[0] = ( DotProduct( v2, dir2 ) - ( a2 * dir2[0] + b2 * dir2[1] ) ) / dir2[0]; + p2[1] = a2 * p2[0] + b2; + } //end if + else + { + //point on the edge vector of area2 closest to v1 + p1[0] = v3[0]; + p1[1] = v1[1]; + //point on the edge vector of area2 closest to v2 + p2[0] = v3[0]; + p2[1] = v2[1]; + } //end else + // + if ( dir1[0] ) { + // + a1 = dir1[1] / dir1[0]; + b1 = v1[1] - a1 * v1[0]; + //point on the edge vector of area1 closest to v3 + p3[0] = ( DotProduct( v3, dir1 ) - ( a1 * dir1[0] + b1 * dir1[1] ) ) / dir1[0]; + p3[1] = a1 * p3[0] + b1; + //point on the edge vector of area1 closest to v4 + p4[0] = ( DotProduct( v4, dir1 ) - ( a1 * dir1[0] + b1 * dir1[1] ) ) / dir1[0]; + p4[1] = a1 * p4[0] + b1; + } //end if + else + { + //point on the edge vector of area1 closest to v3 + p3[0] = v1[0]; + p3[1] = v3[1]; + //point on the edge vector of area1 closest to v4 + p4[0] = v1[0]; + p4[1] = v4[1]; + } //end else + //start with zero z-coordinates + p1[2] = 0; + p2[2] = 0; + p3[2] = 0; + p4[2] = 0; + //calculate the z-coordinates from the ground planes + p1[2] = ( plane2->dist - DotProduct( plane2->normal, p1 ) ) / plane2->normal[2]; + p2[2] = ( plane2->dist - DotProduct( plane2->normal, p2 ) ) / plane2->normal[2]; + p3[2] = ( plane1->dist - DotProduct( plane1->normal, p3 ) ) / plane1->normal[2]; + p4[2] = ( plane1->dist - DotProduct( plane1->normal, p4 ) ) / plane1->normal[2]; + // + founddist = qfalse; + // + if ( VectorBetweenVectors( p1, v3, v4 ) ) { + dist = VectorDistance( v1, p1 ); + if ( dist > bestdist - 0.5 && dist < bestdist + 0.5 ) { + dist1 = VectorDistance( beststart1, v1 ); + dist2 = VectorDistance( beststart2, v1 ); + if ( dist1 > dist2 ) { + if ( dist1 > VectorDistance( beststart1, beststart2 ) ) { + VectorCopy( v1, beststart2 ); + } + } //end if + else + { + if ( dist2 > VectorDistance( beststart1, beststart2 ) ) { + VectorCopy( v1, beststart1 ); + } + } //end else + dist1 = VectorDistance( bestend1, p1 ); + dist2 = VectorDistance( bestend2, p1 ); + if ( dist1 > dist2 ) { + if ( dist1 > VectorDistance( bestend1, bestend2 ) ) { + VectorCopy( p1, bestend2 ); + } + } //end if + else + { + if ( dist2 > VectorDistance( bestend1, bestend2 ) ) { + VectorCopy( p1, bestend1 ); + } + } //end else + } //end if + else if ( dist < bestdist ) { + bestdist = dist; + VectorCopy( v1, beststart1 ); + VectorCopy( v1, beststart2 ); + VectorCopy( p1, bestend1 ); + VectorCopy( p1, bestend2 ); + } //end if + founddist = qtrue; + } //end if + if ( VectorBetweenVectors( p2, v3, v4 ) ) { + dist = VectorDistance( v2, p2 ); + if ( dist > bestdist - 0.5 && dist < bestdist + 0.5 ) { + dist1 = VectorDistance( beststart1, v2 ); + dist2 = VectorDistance( beststart2, v2 ); + if ( dist1 > dist2 ) { + if ( dist1 > VectorDistance( beststart1, beststart2 ) ) { + VectorCopy( v2, beststart2 ); + } + } //end if + else + { + if ( dist2 > VectorDistance( beststart1, beststart2 ) ) { + VectorCopy( v2, beststart1 ); + } + } //end else + dist1 = VectorDistance( bestend1, p2 ); + dist2 = VectorDistance( bestend2, p2 ); + if ( dist1 > dist2 ) { + if ( dist1 > VectorDistance( bestend1, bestend2 ) ) { + VectorCopy( p2, bestend2 ); + } + } //end if + else + { + if ( dist2 > VectorDistance( bestend1, bestend2 ) ) { + VectorCopy( p2, bestend1 ); + } + } //end else + } //end if + else if ( dist < bestdist ) { + bestdist = dist; + VectorCopy( v2, beststart1 ); + VectorCopy( v2, beststart2 ); + VectorCopy( p2, bestend1 ); + VectorCopy( p2, bestend2 ); + } //end if + founddist = qtrue; + } //end else if + if ( VectorBetweenVectors( p3, v1, v2 ) ) { + dist = VectorDistance( v3, p3 ); + if ( dist > bestdist - 0.5 && dist < bestdist + 0.5 ) { + dist1 = VectorDistance( beststart1, p3 ); + dist2 = VectorDistance( beststart2, p3 ); + if ( dist1 > dist2 ) { + if ( dist1 > VectorDistance( beststart1, beststart2 ) ) { + VectorCopy( p3, beststart2 ); + } + } //end if + else + { + if ( dist2 > VectorDistance( beststart1, beststart2 ) ) { + VectorCopy( p3, beststart1 ); + } + } //end else + dist1 = VectorDistance( bestend1, v3 ); + dist2 = VectorDistance( bestend2, v3 ); + if ( dist1 > dist2 ) { + if ( dist1 > VectorDistance( bestend1, bestend2 ) ) { + VectorCopy( v3, bestend2 ); + } + } //end if + else + { + if ( dist2 > VectorDistance( bestend1, bestend2 ) ) { + VectorCopy( v3, bestend1 ); + } + } //end else + } //end if + else if ( dist < bestdist ) { + bestdist = dist; + VectorCopy( p3, beststart1 ); + VectorCopy( p3, beststart2 ); + VectorCopy( v3, bestend1 ); + VectorCopy( v3, bestend2 ); + } //end if + founddist = qtrue; + } //end else if + if ( VectorBetweenVectors( p4, v1, v2 ) ) { + dist = VectorDistance( v4, p4 ); + if ( dist > bestdist - 0.5 && dist < bestdist + 0.5 ) { + dist1 = VectorDistance( beststart1, p4 ); + dist2 = VectorDistance( beststart2, p4 ); + if ( dist1 > dist2 ) { + if ( dist1 > VectorDistance( beststart1, beststart2 ) ) { + VectorCopy( p4, beststart2 ); + } + } //end if + else + { + if ( dist2 > VectorDistance( beststart1, beststart2 ) ) { + VectorCopy( p4, beststart1 ); + } + } //end else + dist1 = VectorDistance( bestend1, v4 ); + dist2 = VectorDistance( bestend2, v4 ); + if ( dist1 > dist2 ) { + if ( dist1 > VectorDistance( bestend1, bestend2 ) ) { + VectorCopy( v4, bestend2 ); + } + } //end if + else + { + if ( dist2 > VectorDistance( bestend1, bestend2 ) ) { + VectorCopy( v4, bestend1 ); + } + } //end else + } //end if + else if ( dist < bestdist ) { + bestdist = dist; + VectorCopy( p4, beststart1 ); + VectorCopy( p4, beststart2 ); + VectorCopy( v4, bestend1 ); + VectorCopy( v4, bestend2 ); + } //end if + founddist = qtrue; + } //end else if + //if no shortest distance was found the shortest distance + //is between one of the vertexes of edge1 and one of edge2 + if ( !founddist ) { + dist = VectorDistance( v1, v3 ); + if ( dist < bestdist ) { + bestdist = dist; + VectorCopy( v1, beststart1 ); + VectorCopy( v1, beststart2 ); + VectorCopy( v3, bestend1 ); + VectorCopy( v3, bestend2 ); + } //end if + dist = VectorDistance( v1, v4 ); + if ( dist < bestdist ) { + bestdist = dist; + VectorCopy( v1, beststart1 ); + VectorCopy( v1, beststart2 ); + VectorCopy( v4, bestend1 ); + VectorCopy( v4, bestend2 ); + } //end if + dist = VectorDistance( v2, v3 ); + if ( dist < bestdist ) { + bestdist = dist; + VectorCopy( v2, beststart1 ); + VectorCopy( v2, beststart2 ); + VectorCopy( v3, bestend1 ); + VectorCopy( v3, bestend2 ); + } //end if + dist = VectorDistance( v2, v4 ); + if ( dist < bestdist ) { + bestdist = dist; + VectorCopy( v2, beststart1 ); + VectorCopy( v2, beststart2 ); + VectorCopy( v4, bestend1 ); + VectorCopy( v4, bestend2 ); + } //end if + } //end if + return bestdist; +} //end of the function AAS_ClosestEdgePoints +//=========================================================================== +// creates possible jump reachabilities between the areas +// +// The two closest points on the ground of the areas are calculated +// One of the points will be on an edge of a ground face of area1 and +// one on an edge of a ground face of area2. +// If there is a range of closest points the point in the middle of this range +// is selected. +// Between these two points there must be one or more gaps. +// If the gaps exist a potential jump is predicted. +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_Reachability_Jump( int area1num, int area2num ) { + int i, j, k, l, face1num, face2num, edge1num, edge2num, traveltype; + float sv_jumpvel, maxjumpdistance, maxjumpheight, height, bestdist, speed; + vec_t *v1, *v2, *v3, *v4; + vec3_t beststart, beststart2, bestend, bestend2; + vec3_t teststart, testend, dir, velocity, cmdmove, up = {0, 0, 1}; + aas_area_t *area1, *area2; + aas_face_t *face1, *face2; + aas_edge_t *edge1, *edge2; + aas_plane_t *plane1, *plane2, *plane; + aas_trace_t trace; + aas_clientmove_t move; + aas_lreachability_t *lreach; + + if ( !AAS_AreaGrounded( area1num ) || !AAS_AreaGrounded( area2num ) ) { + return qfalse; + } + //cannot jump from or to a crouch area + if ( AAS_AreaCrouch( area1num ) || AAS_AreaCrouch( area2num ) ) { + return qfalse; + } + // + area1 = &( *aasworld ).areas[area1num]; + area2 = &( *aasworld ).areas[area2num]; + // + sv_jumpvel = aassettings.sv_jumpvel; + //maximum distance a player can jump + maxjumpdistance = 2 * AAS_MaxJumpDistance( sv_jumpvel ); + //maximum height a player can jump with the given initial z velocity + maxjumpheight = AAS_MaxJumpHeight( sv_jumpvel ); + + //if the areas are not near anough in the x-y direction + for ( i = 0; i < 2; i++ ) + { + if ( area1->mins[i] > area2->maxs[i] + maxjumpdistance ) { + return qfalse; + } + if ( area1->maxs[i] < area2->mins[i] - maxjumpdistance ) { + return qfalse; + } + } //end for + //if area2 is way to high to jump up to + if ( area2->mins[2] > area1->maxs[2] + maxjumpheight ) { + return qfalse; + } + // + bestdist = 999999; + // + for ( i = 0; i < area1->numfaces; i++ ) + { + face1num = ( *aasworld ).faceindex[area1->firstface + i]; + face1 = &( *aasworld ).faces[abs( face1num )]; + //if not a ground face + if ( !( face1->faceflags & FACE_GROUND ) ) { + continue; + } + // + for ( j = 0; j < area2->numfaces; j++ ) + { + face2num = ( *aasworld ).faceindex[area2->firstface + j]; + face2 = &( *aasworld ).faces[abs( face2num )]; + //if not a ground face + if ( !( face2->faceflags & FACE_GROUND ) ) { + continue; + } + // + for ( k = 0; k < face1->numedges; k++ ) + { + edge1num = abs( ( *aasworld ).edgeindex[face1->firstedge + k] ); + edge1 = &( *aasworld ).edges[edge1num]; + for ( l = 0; l < face2->numedges; l++ ) + { + edge2num = abs( ( *aasworld ).edgeindex[face2->firstedge + l] ); + edge2 = &( *aasworld ).edges[edge2num]; + //calculate the minimum distance between the two edges + v1 = ( *aasworld ).vertexes[edge1->v[0]]; + v2 = ( *aasworld ).vertexes[edge1->v[1]]; + v3 = ( *aasworld ).vertexes[edge2->v[0]]; + v4 = ( *aasworld ).vertexes[edge2->v[1]]; + //get the ground planes + plane1 = &( *aasworld ).planes[face1->planenum]; + plane2 = &( *aasworld ).planes[face2->planenum]; + // + bestdist = AAS_ClosestEdgePoints( v1, v2, v3, v4, plane1, plane2, + beststart, bestend, + beststart2, bestend2, bestdist ); + } //end for + } //end for + } //end for + } //end for + VectorMiddle( beststart, beststart2, beststart ); + VectorMiddle( bestend, bestend2, bestend ); + if ( bestdist > 4 && bestdist < maxjumpdistance ) { +// Log_Write("shortest distance between %d and %d is %f\r\n", area1num, area2num, bestdist); + //if the fall would damage the bot + // + if ( AAS_HorizontalVelocityForJump( 0, beststart, bestend, &speed ) ) { + //FIXME: why multiply with 1.2??? + speed *= 1.2; + traveltype = TRAVEL_WALKOFFLEDGE; + } //end if + else if ( bestdist <= 48 && fabs( beststart[2] - bestend[2] ) < 8 ) { + speed = 400; + traveltype = TRAVEL_WALKOFFLEDGE; + } //end else if + else + { + //get the horizontal speed for the jump, if it isn't possible to calculate this + //speed (the jump is not possible) then there's no jump reachability created + if ( !AAS_HorizontalVelocityForJump( sv_jumpvel, beststart, bestend, &speed ) ) { + return qfalse; + } + traveltype = TRAVEL_JUMP; + // + //NOTE: test if the horizontal distance isn't too small + VectorSubtract( bestend, beststart, dir ); + dir[2] = 0; + if ( VectorLength( dir ) < 10 ) { + return qfalse; + } + } //end if + // + VectorSubtract( bestend, beststart, dir ); + VectorNormalize( dir ); + VectorMA( beststart, 1, dir, teststart ); + // + VectorCopy( teststart, testend ); + testend[2] -= 100; + trace = AAS_TraceClientBBox( teststart, testend, PRESENCE_NORMAL, -1 ); + // + if ( trace.startsolid ) { + return qfalse; + } + if ( trace.fraction < 1 ) { + plane = &( *aasworld ).planes[trace.planenum]; + if ( DotProduct( plane->normal, up ) >= 0.7 ) { + if ( !( AAS_PointContents( trace.endpos ) & CONTENTS_LAVA ) ) { //----(SA) modified since slime is no longer deadly +// if (!(AAS_PointContents(trace.endpos) & (CONTENTS_LAVA|CONTENTS_SLIME))) + if ( teststart[2] - trace.endpos[2] <= aassettings.sv_maxbarrier ) { + return qfalse; + } + } //end if + } //end if + } //end if + // + VectorMA( bestend, -1, dir, teststart ); + // + VectorCopy( teststart, testend ); + testend[2] -= 100; + trace = AAS_TraceClientBBox( teststart, testend, PRESENCE_NORMAL, -1 ); + // + if ( trace.startsolid ) { + return qfalse; + } + if ( trace.fraction < 1 ) { + plane = &( *aasworld ).planes[trace.planenum]; + if ( DotProduct( plane->normal, up ) >= 0.7 ) { + if ( !( AAS_PointContents( trace.endpos ) & ( CONTENTS_LAVA | CONTENTS_SLIME ) ) ) { + if ( teststart[2] - trace.endpos[2] <= aassettings.sv_maxbarrier ) { + return qfalse; + } + } //end if + } //end if + } //end if + // + VectorSubtract( bestend, beststart, dir ); + dir[2] = 0; + VectorNormalize( dir ); + // + VectorScale( dir, speed, velocity ); + //get command movement + VectorClear( cmdmove ); + if ( traveltype == TRAVEL_JUMP ) { + cmdmove[2] = aassettings.sv_jumpvel; + } else { cmdmove[2] = 0;} + // + AAS_PredictClientMovement( &move, -1, beststart, PRESENCE_NORMAL, qtrue, + velocity, cmdmove, 3, 30, 0.1, + SE_HITGROUND | SE_ENTERWATER | SE_ENTERSLIME | + SE_ENTERLAVA | SE_HITGROUNDDAMAGE, 0, qfalse ); + //if prediction time wasn't enough to fully predict the movement + if ( move.frames >= 30 ) { + return qfalse; + } + //don't enter slime or lava and don't fall from too high + if ( move.stopevent & SE_ENTERLAVA ) { + return qfalse; //----(SA) modified since slime is no longer deadly + } +// if (move.stopevent & (SE_ENTERSLIME|SE_ENTERLAVA)) return qfalse; + //the end position should be in area2, also test a little bit back + //because the predicted jump could have rushed through the area + for ( i = 0; i <= 32; i += 8 ) + { + VectorMA( move.endpos, -i, dir, teststart ); + teststart[2] += 0.125; + if ( AAS_PointAreaNum( teststart ) == area2num ) { + break; + } + } //end for + if ( i > 32 ) { + return qfalse; + } + // +#ifdef REACHDEBUG + //create the reachability + Log_Write( "jump reachability between %d and %d\r\n", area1num, area2num ); +#endif //REACHDEBUG + //create a new reachability link + lreach = AAS_AllocReachability(); + if ( !lreach ) { + return qfalse; + } + lreach->areanum = area2num; + lreach->facenum = 0; + lreach->edgenum = 0; + VectorCopy( beststart, lreach->start ); + VectorCopy( bestend, lreach->end ); + lreach->traveltype = traveltype; + + VectorSubtract( bestend, beststart, dir ); + height = dir[2]; + dir[2] = 0; + if ( traveltype == TRAVEL_WALKOFFLEDGE && height > VectorLength( dir ) ) { + lreach->traveltime = STARTWALKOFFLEDGE_TIME + height * 50 / aassettings.sv_gravity; + } else + { + lreach->traveltime = STARTJUMP_TIME + VectorDistance( bestend, beststart ) * 240 / aassettings.sv_maxwalkvelocity; + } //end if + // + if ( !AAS_AreaJumpPad( area2num ) ) { + if ( AAS_FallDelta( beststart[2] - bestend[2] ) > FALLDELTA_5DAMAGE ) { + lreach->traveltime += FALLDAMAGE_5_TIME; + } //end if + else if ( AAS_FallDelta( beststart[2] - bestend[2] ) > FALLDELTA_10DAMAGE ) { + lreach->traveltime += FALLDAMAGE_10_TIME; + } //end if + } //end if + lreach->next = areareachability[area1num]; + areareachability[area1num] = lreach; + // + if ( traveltype == TRAVEL_JUMP ) { + reach_jump++; + } else { reach_walkoffledge++;} + } //end if + return qfalse; +} //end of the function AAS_Reachability_Jump +//=========================================================================== +// create a possible ladder reachability from area1 to area2 +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_Reachability_Ladder( int area1num, int area2num ) { + int i, j, k, l, edge1num, edge2num, sharededgenum, lowestedgenum; + int face1num, face2num, ladderface1num, ladderface2num; + int ladderface1vertical, ladderface2vertical, firstv; + float face1area, face2area, bestface1area, bestface2area; + float sv_jumpvel, maxjumpheight; + vec3_t area1point, area2point, v1, v2, up = {0, 0, 1}; + vec3_t mid, lowestpoint, start, end, sharededgevec, dir; + aas_area_t *area1, *area2; + aas_face_t *face1, *face2, *ladderface1, *ladderface2; + aas_plane_t *plane1, *plane2; + aas_edge_t *sharededge, *edge1; + aas_lreachability_t *lreach; + aas_trace_t trace; + + if ( !AAS_AreaLadder( area1num ) || !AAS_AreaLadder( area2num ) ) { + return qfalse; + } + // + sv_jumpvel = aassettings.sv_jumpvel; + //maximum height a player can jump with the given initial z velocity + maxjumpheight = AAS_MaxJumpHeight( sv_jumpvel ); + + area1 = &( *aasworld ).areas[area1num]; + area2 = &( *aasworld ).areas[area2num]; + // + ladderface1 = NULL; + ladderface2 = NULL; + ladderface1num = 0; //make compiler happy + ladderface2num = 0; //make compiler happy + bestface1area = -9999; + bestface2area = -9999; + sharededgenum = 0; //make compiler happy + lowestedgenum = 0; //make compiler happy + // + for ( i = 0; i < area1->numfaces; i++ ) + { + face1num = ( *aasworld ).faceindex[area1->firstface + i]; + face1 = &( *aasworld ).faces[abs( face1num )]; + //if not a ladder face + if ( !( face1->faceflags & FACE_LADDER ) ) { + continue; + } + // + for ( j = 0; j < area2->numfaces; j++ ) + { + face2num = ( *aasworld ).faceindex[area2->firstface + j]; + face2 = &( *aasworld ).faces[abs( face2num )]; + //if not a ladder face + if ( !( face2->faceflags & FACE_LADDER ) ) { + continue; + } + //check if the faces share an edge + for ( k = 0; k < face1->numedges; k++ ) + { + edge1num = ( *aasworld ).edgeindex[face1->firstedge + k]; + for ( l = 0; l < face2->numedges; l++ ) + { + edge2num = ( *aasworld ).edgeindex[face2->firstedge + l]; + if ( abs( edge1num ) == abs( edge2num ) ) { + //get the face with the largest area + face1area = AAS_FaceArea( face1 ); + face2area = AAS_FaceArea( face2 ); + if ( face1area > bestface1area && face2area > bestface2area ) { + bestface1area = face1area; + bestface2area = face2area; + ladderface1 = face1; + ladderface2 = face2; + ladderface1num = face1num; + ladderface2num = face2num; + sharededgenum = edge1num; + } //end if + break; + } //end if + } //end for + if ( l != face2->numedges ) { + break; + } + } //end for + } //end for + } //end for + // + if ( ladderface1 && ladderface2 ) { + //get the middle of the shared edge + sharededge = &( *aasworld ).edges[abs( sharededgenum )]; + firstv = sharededgenum < 0; + // + VectorCopy( ( *aasworld ).vertexes[sharededge->v[firstv]], v1 ); + VectorCopy( ( *aasworld ).vertexes[sharededge->v[!firstv]], v2 ); + VectorAdd( v1, v2, area1point ); + VectorScale( area1point, 0.5, area1point ); + VectorCopy( area1point, area2point ); + // + //if the face plane in area 1 is pretty much vertical + plane1 = &( *aasworld ).planes[ladderface1->planenum ^ ( ladderface1num < 0 )]; + plane2 = &( *aasworld ).planes[ladderface2->planenum ^ ( ladderface2num < 0 )]; + // + //get the points really into the areas + VectorSubtract( v2, v1, sharededgevec ); + CrossProduct( plane1->normal, sharededgevec, dir ); + VectorNormalize( dir ); + //NOTE: 32 because that's larger than 16 (bot bbox x,y) + VectorMA( area1point, -32, dir, area1point ); + VectorMA( area2point, 32, dir, area2point ); + // + ladderface1vertical = abs( DotProduct( plane1->normal, up ) ) < 0.1; + ladderface2vertical = abs( DotProduct( plane2->normal, up ) ) < 0.1; + //there's only reachability between vertical ladder faces + if ( !ladderface1vertical && !ladderface2vertical ) { + return qfalse; + } + //if both vertical ladder faces + if ( ladderface1vertical && ladderface2vertical + //and the ladder faces do not make a sharp corner + && DotProduct( plane1->normal, plane2->normal ) > 0.7 + //and the shared edge is not too vertical + && abs( DotProduct( sharededgevec, up ) ) < 0.7 ) { + //create a new reachability link + lreach = AAS_AllocReachability(); + if ( !lreach ) { + return qfalse; + } + lreach->areanum = area2num; + lreach->facenum = ladderface1num; + lreach->edgenum = abs( sharededgenum ); + VectorCopy( area1point, lreach->start ); + //VectorCopy(area2point, lreach->end); + VectorMA( area2point, -3, plane1->normal, lreach->end ); + lreach->traveltype = TRAVEL_LADDER; + lreach->traveltime = 10; + lreach->next = areareachability[area1num]; + areareachability[area1num] = lreach; + // + reach_ladder++; + //create a new reachability link + lreach = AAS_AllocReachability(); + if ( !lreach ) { + return qfalse; + } + lreach->areanum = area1num; + lreach->facenum = ladderface2num; + lreach->edgenum = abs( sharededgenum ); + VectorCopy( area2point, lreach->start ); + //VectorCopy(area1point, lreach->end); + VectorMA( area1point, -3, plane2->normal, lreach->end ); + lreach->traveltype = TRAVEL_LADDER; + lreach->traveltime = 10; + lreach->next = areareachability[area2num]; + areareachability[area2num] = lreach; + // + reach_ladder++; + // + return qtrue; + } //end if + //if the second ladder face is also a ground face + //create ladder end (just ladder) reachability and + //walk off a ladder (ledge) reachability + if ( ladderface1vertical && ( ladderface2->faceflags & FACE_GROUND ) ) { + //create a new reachability link + lreach = AAS_AllocReachability(); + if ( !lreach ) { + return qfalse; + } + lreach->areanum = area2num; + lreach->facenum = ladderface1num; + lreach->edgenum = abs( sharededgenum ); + VectorCopy( area1point, lreach->start ); + VectorCopy( area2point, lreach->end ); + lreach->end[2] += 16; + VectorMA( lreach->end, -15, plane1->normal, lreach->end ); + lreach->traveltype = TRAVEL_LADDER; + lreach->traveltime = 10; + lreach->next = areareachability[area1num]; + areareachability[area1num] = lreach; + // + reach_ladder++; + //create a new reachability link + lreach = AAS_AllocReachability(); + if ( !lreach ) { + return qfalse; + } + lreach->areanum = area1num; + lreach->facenum = ladderface2num; + lreach->edgenum = abs( sharededgenum ); + VectorCopy( area2point, lreach->start ); + VectorCopy( area1point, lreach->end ); + lreach->traveltype = TRAVEL_WALKOFFLEDGE; + lreach->traveltime = 10; + lreach->next = areareachability[area2num]; + areareachability[area2num] = lreach; + // + reach_walkoffledge++; + // + return qtrue; + } //end if + // + if ( ladderface1vertical ) { + //find lowest edge of the ladder face + lowestpoint[2] = 99999; + for ( i = 0; i < ladderface1->numedges; i++ ) + { + edge1num = abs( ( *aasworld ).edgeindex[ladderface1->firstedge + i] ); + edge1 = &( *aasworld ).edges[edge1num]; + // + VectorCopy( ( *aasworld ).vertexes[edge1->v[0]], v1 ); + VectorCopy( ( *aasworld ).vertexes[edge1->v[1]], v2 ); + // + VectorAdd( v1, v2, mid ); + VectorScale( mid, 0.5, mid ); + // + if ( mid[2] < lowestpoint[2] ) { + VectorCopy( mid, lowestpoint ); + lowestedgenum = edge1num; + } //end if + } //end for + // + plane1 = &( *aasworld ).planes[ladderface1->planenum]; + //trace down in the middle of this edge + VectorMA( lowestpoint, 5, plane1->normal, start ); + VectorCopy( start, end ); + start[2] += 5; + end[2] -= 100; + //trace without entity collision + trace = AAS_TraceClientBBox( start, end, PRESENCE_NORMAL, -1 ); + // + // +#ifdef REACHDEBUG + if ( trace.startsolid ) { + Log_Write( "trace from area %d started in solid\r\n", area1num ); + } //end if +#endif //REACHDEBUG + // + trace.endpos[2] += 1; + area2num = AAS_PointAreaNum( trace.endpos ); + // + area2 = &( *aasworld ).areas[area2num]; + for ( i = 0; i < area2->numfaces; i++ ) + { + face2num = ( *aasworld ).faceindex[area2->firstface + i]; + face2 = &( *aasworld ).faces[abs( face2num )]; + // + if ( face2->faceflags & FACE_LADDER ) { + plane2 = &( *aasworld ).planes[face2->planenum]; + if ( abs( DotProduct( plane2->normal, up ) ) < 0.1 ) { + break; + } + } //end if + } //end for + //if from another area without vertical ladder faces + if ( i >= area2->numfaces && area2num != area1num && + //the reachabilities shouldn't exist already + !AAS_ReachabilityExists( area1num, area2num ) && + !AAS_ReachabilityExists( area2num, area1num ) ) { + //if the height is jumpable + if ( start[2] - trace.endpos[2] < maxjumpheight ) { + //create a new reachability link + lreach = AAS_AllocReachability(); + if ( !lreach ) { + return qfalse; + } + lreach->areanum = area2num; + lreach->facenum = ladderface1num; + lreach->edgenum = lowestedgenum; + VectorCopy( lowestpoint, lreach->start ); + VectorCopy( trace.endpos, lreach->end ); + lreach->traveltype = TRAVEL_LADDER; + lreach->traveltime = 10; + lreach->next = areareachability[area1num]; + areareachability[area1num] = lreach; + // + reach_ladder++; + //create a new reachability link + lreach = AAS_AllocReachability(); + if ( !lreach ) { + return qfalse; + } + lreach->areanum = area1num; + lreach->facenum = ladderface1num; + lreach->edgenum = lowestedgenum; + VectorCopy( trace.endpos, lreach->start ); + //get the end point a little bit into the ladder + VectorMA( lowestpoint, -5, plane1->normal, lreach->end ); + //get the end point a little higher + lreach->end[2] += 10; + lreach->traveltype = TRAVEL_JUMP; + lreach->traveltime = 10; + lreach->next = areareachability[area2num]; + areareachability[area2num] = lreach; + // + reach_jump++; + // + return qtrue; +#ifdef REACHDEBUG + Log_Write( "jump up to ladder reach between %d and %d\r\n", area2num, area1num ); +#endif //REACHDEBUG + } //end if +#ifdef REACHDEBUG + else {Log_Write( "jump too high between area %d and %d\r\n", area2num, area1num );} +#endif //REACHDEBUG + } //end if + /*//if slime or lava below the ladder + //try jump reachability from far towards the ladder + if ((*aasworld).areasettings[area2num].contents & (AREACONTENTS_SLIME + | AREACONTENTS_LAVA)) + { + for (i = 20; i <= 120; i += 20) + { + //trace down in the middle of this edge + VectorMA(lowestpoint, i, plane1->normal, start); + VectorCopy(start, end); + start[2] += 5; + end[2] -= 100; + //trace without entity collision + trace = AAS_TraceClientBBox(start, end, PRESENCE_NORMAL, -1); + // + if (trace.startsolid) break; + trace.endpos[2] += 1; + area2num = AAS_PointAreaNum(trace.endpos); + if (area2num == area1num) continue; + // + if (start[2] - trace.endpos[2] > maxjumpheight) continue; + if ((*aasworld).areasettings[area2num].contents & (AREACONTENTS_SLIME + | AREACONTENTS_LAVA)) continue; + // + //create a new reachability link + lreach = AAS_AllocReachability(); + if (!lreach) return qfalse; + lreach->areanum = area1num; + lreach->facenum = ladderface1num; + lreach->edgenum = lowestedgenum; + VectorCopy(trace.endpos, lreach->start); + VectorCopy(lowestpoint, lreach->end); + lreach->end[2] += 5; + lreach->traveltype = TRAVEL_JUMP; + lreach->traveltime = 10; + lreach->next = areareachability[area2num]; + areareachability[area2num] = lreach; + // + reach_jump++; + // + Log_Write("jump far to ladder reach between %d and %d\r\n", area2num, area1num); + // + break; + } //end for + } //end if*/ + } //end if + } //end if + return qfalse; +} //end of the function AAS_Reachability_Ladder +//=========================================================================== +// create possible teleporter reachabilities +// this is very game dependent.... :( +// +// classname = trigger_multiple or trigger_teleport +// target = "t1" +// +// classname = target_teleporter +// targetname = "t1" +// target = "t2" +// +// classname = misc_teleporter_dest +// targetname = "t2" +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_Reachability_Teleport( void ) { + int area1num, area2num; + char target[MAX_EPAIRKEY], targetname[MAX_EPAIRKEY]; + char classname[MAX_EPAIRKEY], model[MAX_EPAIRKEY]; + int ent, dest; + vec3_t origin, destorigin, mins, maxs, end, angles = {0, 0, 0}; + vec3_t mid; + aas_lreachability_t *lreach; + aas_trace_t trace; + aas_link_t *areas, *link; + + for ( ent = AAS_NextBSPEntity( 0 ); ent; ent = AAS_NextBSPEntity( ent ) ) + { + if ( !AAS_ValueForBSPEpairKey( ent, "classname", classname, MAX_EPAIRKEY ) ) { + continue; + } + if ( !strcmp( classname, "trigger_multiple" ) ) { + AAS_ValueForBSPEpairKey( ent, "model", model, MAX_EPAIRKEY ); +//#ifdef REACHDEBUG + botimport.Print( PRT_MESSAGE, "trigger_multiple model = \"%s\"\n", model ); +//#endif REACHDEBUG + AAS_BSPModelMinsMaxsOrigin( atoi( model + 1 ), angles, mins, maxs, origin ); + // + if ( !AAS_ValueForBSPEpairKey( ent, "target", target, MAX_EPAIRKEY ) ) { + botimport.Print( PRT_ERROR, "trigger_multiple at %1.0f %1.0f %1.0f without target\n", + origin[0], origin[1], origin[2] ); + continue; + } //end if + for ( dest = AAS_NextBSPEntity( 0 ); dest; dest = AAS_NextBSPEntity( dest ) ) + { + if ( !AAS_ValueForBSPEpairKey( dest, "classname", classname, MAX_EPAIRKEY ) ) { + continue; + } + if ( !strcmp( classname, "target_teleporter" ) ) { + if ( !AAS_ValueForBSPEpairKey( dest, "targetname", targetname, MAX_EPAIRKEY ) ) { + continue; + } + if ( !strcmp( targetname, target ) ) { + break; + } //end if + } //end if + } //end for + if ( !dest ) { + continue; + } //end if + if ( !AAS_ValueForBSPEpairKey( dest, "target", target, MAX_EPAIRKEY ) ) { + botimport.Print( PRT_ERROR, "target_teleporter without target\n" ); + continue; + } //end if + } //end else + else if ( !strcmp( classname, "trigger_teleport" ) ) { + AAS_ValueForBSPEpairKey( ent, "model", model, MAX_EPAIRKEY ); +//#ifdef REACHDEBUG + botimport.Print( PRT_MESSAGE, "trigger_teleport model = \"%s\"\n", model ); +//#endif REACHDEBUG + AAS_BSPModelMinsMaxsOrigin( atoi( model + 1 ), angles, mins, maxs, origin ); + // + if ( !AAS_ValueForBSPEpairKey( ent, "target", target, MAX_EPAIRKEY ) ) { + botimport.Print( PRT_ERROR, "trigger_teleport at %1.0f %1.0f %1.0f without target\n", + origin[0], origin[1], origin[2] ); + continue; + } //end if + } //end if + else + { + continue; + } //end else + // + for ( dest = AAS_NextBSPEntity( 0 ); dest; dest = AAS_NextBSPEntity( dest ) ) + { + //classname should be misc_teleporter_dest + //but I've also seen target_position and actually any + //entity could be used... burp + if ( AAS_ValueForBSPEpairKey( dest, "targetname", targetname, MAX_EPAIRKEY ) ) { + if ( !strcmp( targetname, target ) ) { + break; + } //end if + } //end if + } //end for + if ( !dest ) { + botimport.Print( PRT_ERROR, "teleporter without misc_teleporter_dest (%s)\n", target ); + continue; + } //end if + if ( !AAS_VectorForBSPEpairKey( dest, "origin", destorigin ) ) { + botimport.Print( PRT_ERROR, "teleporter destination (%s) without origin\n", target ); + continue; + } //end if + // + area2num = AAS_PointAreaNum( destorigin ); + //if not teleported into a teleporter or into a jumppad + if ( !AAS_AreaTeleporter( area2num ) && !AAS_AreaJumpPad( area2num ) ) { + destorigin[2] += 24; //just for q2e1m2, the dork has put the telepads in the ground + VectorCopy( destorigin, end ); + end[2] -= 100; + trace = AAS_TraceClientBBox( destorigin, end, PRESENCE_CROUCH, -1 ); + if ( trace.startsolid ) { + botimport.Print( PRT_ERROR, "teleporter destination (%s) in solid\n", target ); + continue; + } //end if + VectorCopy( trace.endpos, destorigin ); + area2num = AAS_PointAreaNum( destorigin ); + } //end if + // + //botimport.Print(PRT_MESSAGE, "teleporter brush origin at %f %f %f\n", origin[0], origin[1], origin[2]); + //botimport.Print(PRT_MESSAGE, "teleporter brush mins = %f %f %f\n", mins[0], mins[1], mins[2]); + //botimport.Print(PRT_MESSAGE, "teleporter brush maxs = %f %f %f\n", maxs[0], maxs[1], maxs[2]); + VectorAdd( origin, mins, mins ); + VectorAdd( origin, maxs, maxs ); + // + VectorAdd( mins, maxs, mid ); + VectorScale( mid, 0.5, mid ); + //link an invalid (-1) entity + areas = AAS_LinkEntityClientBBox( mins, maxs, -1, PRESENCE_CROUCH ); + if ( !areas ) { + botimport.Print( PRT_MESSAGE, "trigger_multiple not in any area\n" ); + } + // + for ( link = areas; link; link = link->next_area ) + { + //if (!AAS_AreaGrounded(link->areanum)) continue; + if ( !AAS_AreaTeleporter( link->areanum ) ) { + continue; + } + // + area1num = link->areanum; + //create a new reachability link + lreach = AAS_AllocReachability(); + if ( !lreach ) { + break; + } + lreach->areanum = area2num; + lreach->facenum = 0; + lreach->edgenum = 0; + VectorCopy( mid, lreach->start ); + VectorCopy( destorigin, lreach->end ); + lreach->traveltype = TRAVEL_TELEPORT; + lreach->traveltime = TELEPORT_TIME; + lreach->next = areareachability[area1num]; + areareachability[area1num] = lreach; + // + reach_teleport++; + } //end for + //unlink the invalid entity + AAS_UnlinkFromAreas( areas ); + } //end for +} //end of the function AAS_Reachability_Teleport +//=========================================================================== +// create possible elevator (func_plat) reachabilities +// this is very game dependent.... :( +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +#define REACHDEBUG +void AAS_Reachability_Elevator( void ) { + int area1num, area2num, modelnum, i, j, k, l, n, p; + float lip, height, speed; + char model[MAX_EPAIRKEY], classname[MAX_EPAIRKEY]; + int ent; + vec3_t mins, maxs, origin, angles = {0, 0, 0}; + vec3_t pos1, pos2, mids, platbottom, plattop; + vec3_t bottomorg, toporg, start, end, dir; + vec_t xvals[8], yvals[8], xvals_top[8], yvals_top[8]; + aas_lreachability_t *lreach; + aas_trace_t trace; + +#ifdef REACHDEBUG + Log_Write( "AAS_Reachability_Elevator\r\n" ); +#endif //REACHDEBUG + for ( ent = AAS_NextBSPEntity( 0 ); ent; ent = AAS_NextBSPEntity( ent ) ) + { + if ( !AAS_ValueForBSPEpairKey( ent, "classname", classname, MAX_EPAIRKEY ) ) { + continue; + } + if ( !strcmp( classname, "func_plat" ) ) { +#ifdef REACHDEBUG + Log_Write( "found func plat\r\n" ); +#endif //REACHDEBUG + if ( !AAS_ValueForBSPEpairKey( ent, "model", model, MAX_EPAIRKEY ) ) { + botimport.Print( PRT_ERROR, "func_plat without model\n" ); + continue; + } //end if + //get the model number, and skip the leading * + modelnum = atoi( model + 1 ); + if ( modelnum <= 0 ) { + botimport.Print( PRT_ERROR, "func_plat with invalid model number\n" ); + continue; + } //end if + //get the mins, maxs and origin of the model + //NOTE: the origin is usually (0,0,0) and the mins and maxs + // are the absolute mins and maxs + AAS_BSPModelMinsMaxsOrigin( modelnum, angles, mins, maxs, origin ); + // + AAS_VectorForBSPEpairKey( ent, "origin", origin ); + //pos1 is the top position, pos2 is the bottom + VectorCopy( origin, pos1 ); + VectorCopy( origin, pos2 ); + //get the lip of the plat + AAS_FloatForBSPEpairKey( ent, "lip", &lip ); + if ( !lip ) { + lip = 8; + } + //get the movement height of the plat + AAS_FloatForBSPEpairKey( ent, "height", &height ); + if ( !height ) { + height = ( maxs[2] - mins[2] ) - lip; + } + //get the speed of the plat + AAS_FloatForBSPEpairKey( ent, "speed", &speed ); + if ( !speed ) { + speed = 200; + } + //get bottom position below pos1 + pos2[2] -= height; + // + botimport.Print( PRT_MESSAGE, "pos2[2] = %1.1f pos1[2] = %1.1f\n", pos2[2], pos1[2] ); + //get a point just above the plat in the bottom position + VectorAdd( mins, maxs, mids ); + VectorMA( pos2, 0.5, mids, platbottom ); + platbottom[2] = maxs[2] - ( pos1[2] - pos2[2] ) + 2; + //get a point just above the plat in the top position + VectorAdd( mins, maxs, mids ); + VectorMA( pos2, 0.5, mids, plattop ); + plattop[2] = maxs[2] + 2; + // + /*if (!area1num) + { + Log_Write("no grounded area near plat bottom\r\n"); + continue; + } //end if*/ + //get the mins and maxs a little larger + for ( i = 0; i < 3; i++ ) + { + mins[i] -= 1; + maxs[i] += 1; + } //end for + // + botimport.Print( PRT_MESSAGE, "platbottom[2] = %1.1f plattop[2] = %1.1f\n", platbottom[2], plattop[2] ); + // + VectorAdd( mins, maxs, mids ); + VectorScale( mids, 0.5, mids ); + // + xvals[0] = mins[0]; xvals[1] = mids[0]; xvals[2] = maxs[0]; xvals[3] = mids[0]; + yvals[0] = mids[1]; yvals[1] = maxs[1]; yvals[2] = mids[1]; yvals[3] = mins[1]; + // + xvals[4] = mins[0]; xvals[5] = maxs[0]; xvals[6] = maxs[0]; xvals[7] = mins[0]; + yvals[4] = maxs[1]; yvals[5] = maxs[1]; yvals[6] = mins[1]; yvals[7] = mins[1]; + //find adjacent areas around the bottom of the plat + for ( i = 0; i < 9; i++ ) + { + if ( i < 8 ) { //check at the sides of the plat + bottomorg[0] = origin[0] + xvals[i]; + bottomorg[1] = origin[1] + yvals[i]; + bottomorg[2] = platbottom[2] + 16; + //get a grounded or swim area near the plat in the bottom position + area1num = AAS_PointAreaNum( bottomorg ); + for ( k = 0; k < 16; k++ ) + { + if ( area1num ) { + if ( AAS_AreaGrounded( area1num ) || AAS_AreaSwim( area1num ) ) { + break; + } + } //end if + bottomorg[2] += 4; + area1num = AAS_PointAreaNum( bottomorg ); + } //end if + //if in solid + if ( k >= 16 ) { + continue; + } //end if + } //end if + else //at the middle of the plat + { + VectorCopy( plattop, bottomorg ); + bottomorg[2] += 24; + area1num = AAS_PointAreaNum( bottomorg ); + if ( !area1num ) { + continue; + } + VectorCopy( platbottom, bottomorg ); + bottomorg[2] += 24; + } //end else + //look at adjacent areas around the top of the plat + //make larger steps to outside the plat everytime + for ( n = 0; n < 3; n++ ) + { + for ( k = 0; k < 3; k++ ) + { + mins[k] -= 4; + maxs[k] += 4; + } //end for + xvals_top[0] = mins[0]; xvals_top[1] = mids[0]; xvals_top[2] = maxs[0]; xvals_top[3] = mids[0]; + yvals_top[0] = mids[1]; yvals_top[1] = maxs[1]; yvals_top[2] = mids[1]; yvals_top[3] = mins[1]; + // + xvals_top[4] = mins[0]; xvals_top[5] = maxs[0]; xvals_top[6] = maxs[0]; xvals_top[7] = mins[0]; + yvals_top[4] = maxs[1]; yvals_top[5] = maxs[1]; yvals_top[6] = mins[1]; yvals_top[7] = mins[1]; + // + for ( j = 0; j < 8; j++ ) + { + toporg[0] = origin[0] + xvals_top[j]; + toporg[1] = origin[1] + yvals_top[j]; + toporg[2] = plattop[2] + 16; + //get a grounded or swim area near the plat in the top position + area2num = AAS_PointAreaNum( toporg ); + for ( l = 0; l < 16; l++ ) + { + if ( area2num ) { + if ( AAS_AreaGrounded( area2num ) || AAS_AreaSwim( area2num ) ) { + VectorCopy( plattop, start ); + start[2] += 32; + VectorCopy( toporg, end ); + end[2] += 1; + trace = AAS_TraceClientBBox( start, end, PRESENCE_CROUCH, -1 ); + if ( trace.fraction >= 1 ) { + break; + } + } //end if + } //end if + toporg[2] += 4; + area2num = AAS_PointAreaNum( toporg ); + } //end if + //if in solid + if ( l >= 16 ) { + continue; + } + //never create a reachability in the same area + if ( area2num == area1num ) { + continue; + } + //if the area isn't grounded + if ( !AAS_AreaGrounded( area2num ) ) { + continue; + } + //if there already exists reachability between the areas + if ( AAS_ReachabilityExists( area1num, area2num ) ) { + continue; + } + //if the reachability start is within the elevator bounding box + VectorSubtract( bottomorg, platbottom, dir ); + VectorNormalize( dir ); + dir[0] = bottomorg[0] + 24 * dir[0]; + dir[1] = bottomorg[1] + 24 * dir[1]; + dir[2] = bottomorg[2]; + // + for ( p = 0; p < 3; p++ ) + if ( dir[p] < origin[p] + mins[p] || dir[p] > origin[p] + maxs[p] ) { + break; + } + if ( p >= 3 ) { + continue; + } + //create a new reachability link + lreach = AAS_AllocReachability(); + if ( !lreach ) { + continue; + } + lreach->areanum = area2num; + //the facenum is the model number + lreach->facenum = modelnum; + //the edgenum is the height + lreach->edgenum = (int) height; + // + VectorCopy( dir, lreach->start ); + VectorCopy( toporg, lreach->end ); + lreach->traveltype = TRAVEL_ELEVATOR; + lreach->traveltime = height * 100 / speed; + if ( !lreach->traveltime ) { + lreach->traveltime = 50; + } + lreach->next = areareachability[area1num]; + areareachability[area1num] = lreach; + //don't go any further to the outside + n = 9999; + // +#ifdef REACHDEBUG + Log_Write( "elevator reach from %d to %d\r\n", area1num, area2num ); +#endif //REACHDEBUG + // + reach_elevator++; + } //end for + } //end for + } //end for + } //end if + } //end for +} //end of the function AAS_Reachability_Elevator +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +aas_lreachability_t *AAS_FindFaceReachabilities( vec3_t *facepoints, int numpoints, aas_plane_t *plane, int towardsface ) { + int i, j, k, l; + int facenum, edgenum, bestfacenum; + float *v1, *v2, *v3, *v4; + float bestdist, speed, hordist, dist; + vec3_t beststart, beststart2, bestend, bestend2, tmp, hordir, testpoint; + aas_lreachability_t *lreach, *lreachabilities; + aas_area_t *area; + aas_face_t *face; + aas_edge_t *edge; + aas_plane_t *faceplane, *bestfaceplane; + + // + lreachabilities = NULL; + bestfacenum = 0; + bestfaceplane = NULL; + // + for ( i = 1; i < ( *aasworld ).numareas; i++ ) + { + area = &( *aasworld ).areas[i]; + // get the shortest distance between one of the func_bob start edges and + // one of the face edges of area1 + bestdist = 999999; + for ( j = 0; j < area->numfaces; j++ ) + { + facenum = ( *aasworld ).faceindex[area->firstface + j]; + face = &( *aasworld ).faces[abs( facenum )]; + //if not a ground face + if ( !( face->faceflags & FACE_GROUND ) ) { + continue; + } + //get the ground planes + faceplane = &( *aasworld ).planes[face->planenum]; + // + for ( k = 0; k < face->numedges; k++ ) + { + edgenum = abs( ( *aasworld ).edgeindex[face->firstedge + k] ); + edge = &( *aasworld ).edges[edgenum]; + //calculate the minimum distance between the two edges + v1 = ( *aasworld ).vertexes[edge->v[0]]; + v2 = ( *aasworld ).vertexes[edge->v[1]]; + // + for ( l = 0; l < numpoints; l++ ) + { + v3 = facepoints[l]; + v4 = facepoints[( l + 1 ) % numpoints]; + dist = AAS_ClosestEdgePoints( v1, v2, v3, v4, faceplane, plane, + beststart, bestend, + beststart2, bestend2, bestdist ); + if ( dist < bestdist ) { + bestfacenum = facenum; + bestfaceplane = faceplane; + bestdist = dist; + } //end if + } //end for + } //end for + } //end for + // + if ( bestdist > 192 ) { + continue; + } + // + VectorMiddle( beststart, beststart2, beststart ); + VectorMiddle( bestend, bestend2, bestend ); + // + if ( !towardsface ) { + VectorCopy( beststart, tmp ); + VectorCopy( bestend, beststart ); + VectorCopy( tmp, bestend ); + } //end if + // + VectorSubtract( bestend, beststart, hordir ); + hordir[2] = 0; + hordist = VectorLength( hordir ); + // + if ( hordist > 2 * AAS_MaxJumpDistance( aassettings.sv_jumpvel ) ) { + continue; + } + //the end point should not be significantly higher than the start point + if ( bestend[2] - 32 > beststart[2] ) { + continue; + } + //don't fall down too far + if ( bestend[2] < beststart[2] - 128 ) { + continue; + } + //the distance should not be too far + if ( hordist > 32 ) { + //check for walk off ledge + if ( !AAS_HorizontalVelocityForJump( 0, beststart, bestend, &speed ) ) { + continue; + } + } //end if + // + beststart[2] += 1; + bestend[2] += 1; + // + if ( towardsface ) { + VectorCopy( bestend, testpoint ); + } else { VectorCopy( beststart, testpoint );} + testpoint[2] = 0; + testpoint[2] = ( bestfaceplane->dist - DotProduct( bestfaceplane->normal, testpoint ) ) / bestfaceplane->normal[2]; + // + if ( !AAS_PointInsideFace( bestfacenum, testpoint, 0.1 ) ) { + //if the faces are not overlapping then only go down + if ( bestend[2] - 16 > beststart[2] ) { + continue; + } + } //end if + lreach = AAS_AllocReachability(); + if ( !lreach ) { + return lreachabilities; + } + lreach->areanum = i; + lreach->facenum = 0; + lreach->edgenum = 0; + VectorCopy( beststart, lreach->start ); + VectorCopy( bestend, lreach->end ); + lreach->traveltype = 0; + lreach->traveltime = 0; + lreach->next = lreachabilities; + lreachabilities = lreach; +#ifndef BSPC + if ( towardsface ) { + AAS_PermanentLine( lreach->start, lreach->end, 1 ); + } else { AAS_PermanentLine( lreach->start, lreach->end, 2 );} +#endif + } //end for + return lreachabilities; +} //end of the function AAS_FindFaceReachabilities +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_Reachability_FuncBobbing( void ) { + int ent, spawnflags, modelnum, axis; + int i, numareas, areas[10]; + char classname[MAX_EPAIRKEY], model[MAX_EPAIRKEY]; + vec3_t origin, move_end, move_start, move_start_top, move_end_top; + vec3_t mins, maxs, angles = {0, 0, 0}; + vec3_t start_edgeverts[4], end_edgeverts[4], mid; + vec3_t org, start, end, dir, points[10]; + float height; + aas_plane_t start_plane, end_plane; + aas_lreachability_t *startreach, *endreach, *nextstartreach, *nextendreach, *lreach; + aas_lreachability_t *firststartreach, *firstendreach; + + for ( ent = AAS_NextBSPEntity( 0 ); ent; ent = AAS_NextBSPEntity( ent ) ) + { + if ( !AAS_ValueForBSPEpairKey( ent, "classname", classname, MAX_EPAIRKEY ) ) { + continue; + } + if ( strcmp( classname, "func_bobbing" ) ) { + continue; + } + AAS_FloatForBSPEpairKey( ent, "height", &height ); + if ( !height ) { + height = 32; + } + // + if ( !AAS_ValueForBSPEpairKey( ent, "model", model, MAX_EPAIRKEY ) ) { + botimport.Print( PRT_ERROR, "func_bobbing without model\n" ); + continue; + } //end if + //get the model number, and skip the leading * + modelnum = atoi( model + 1 ); + if ( modelnum <= 0 ) { + botimport.Print( PRT_ERROR, "func_bobbing with invalid model number\n" ); + continue; + } //end if + // + AAS_BSPModelMinsMaxsOrigin( modelnum, angles, mins, maxs, NULL ); + // + VectorAdd( mins, maxs, mid ); + VectorScale( mid, 0.5, mid ); + //VectorAdd(mid, origin, mid); + VectorCopy( mid, origin ); + // + VectorCopy( origin, move_end ); + VectorCopy( origin, move_start ); + // + AAS_IntForBSPEpairKey( ent, "spawnflags", &spawnflags ); + // set the axis of bobbing + if ( spawnflags & 1 ) { + axis = 0; + } else if ( spawnflags & 2 ) { + axis = 1; + } else { axis = 2;} + // + move_start[axis] -= height; + move_end[axis] += height; + // + Log_Write( "funcbob model %d, start = {%1.1f, %1.1f, %1.1f} end = {%1.1f, %1.1f, %1.1f}\n", + modelnum, move_start[0], move_start[1], move_start[2], move_end[0], move_end[1], move_end[2] ); + // +#ifndef BSPC + /* + AAS_DrawPermanentCross(move_start, 4, 1); + AAS_DrawPermanentCross(move_end, 4, 2); + */ +#endif + // + for ( i = 0; i < 4; i++ ) + { + VectorCopy( move_start, start_edgeverts[i] ); + start_edgeverts[i][2] += maxs[2] - mid[2]; //+ bbox maxs z + start_edgeverts[i][2] += 24; //+ player origin to ground dist + } //end for + start_edgeverts[0][0] += maxs[0] - mid[0]; + start_edgeverts[0][1] += maxs[1] - mid[1]; + start_edgeverts[1][0] += maxs[0] - mid[0]; + start_edgeverts[1][1] += mins[1] - mid[1]; + start_edgeverts[2][0] += mins[0] - mid[0]; + start_edgeverts[2][1] += mins[1] - mid[1]; + start_edgeverts[3][0] += mins[0] - mid[0]; + start_edgeverts[3][1] += maxs[1] - mid[1]; + // + start_plane.dist = start_edgeverts[0][2]; + VectorSet( start_plane.normal, 0, 0, 1 ); + // + for ( i = 0; i < 4; i++ ) + { + VectorCopy( move_end, end_edgeverts[i] ); + end_edgeverts[i][2] += maxs[2] - mid[2]; //+ bbox maxs z + end_edgeverts[i][2] += 24; //+ player origin to ground dist + } //end for + end_edgeverts[0][0] += maxs[0] - mid[0]; + end_edgeverts[0][1] += maxs[1] - mid[1]; + end_edgeverts[1][0] += maxs[0] - mid[0]; + end_edgeverts[1][1] += mins[1] - mid[1]; + end_edgeverts[2][0] += mins[0] - mid[0]; + end_edgeverts[2][1] += mins[1] - mid[1]; + end_edgeverts[3][0] += mins[0] - mid[0]; + end_edgeverts[3][1] += maxs[1] - mid[1]; + // + end_plane.dist = end_edgeverts[0][2]; + VectorSet( end_plane.normal, 0, 0, 1 ); + // +#ifndef BSPC + /* + for (i = 0; i < 4; i++) + { + AAS_PermanentLine(start_edgeverts[i], start_edgeverts[(i+1)%4], 1); + AAS_PermanentLine(end_edgeverts[i], end_edgeverts[(i+1)%4], 1); + } //end for + */ +#endif + VectorCopy( move_start, move_start_top ); + move_start_top[2] += maxs[2] - mid[2] + 24; //+ bbox maxs z + VectorCopy( move_end, move_end_top ); + move_end_top[2] += maxs[2] - mid[2] + 24; //+ bbox maxs z + // + if ( !AAS_PointAreaNum( move_start_top ) ) { + continue; + } + if ( !AAS_PointAreaNum( move_end_top ) ) { + continue; + } + // + for ( i = 0; i < 2; i++ ) + { + firststartreach = firstendreach = NULL; + // + if ( i == 0 ) { + firststartreach = AAS_FindFaceReachabilities( start_edgeverts, 4, &start_plane, qtrue ); + firstendreach = AAS_FindFaceReachabilities( end_edgeverts, 4, &end_plane, qfalse ); + } //end if + else + { + firststartreach = AAS_FindFaceReachabilities( end_edgeverts, 4, &end_plane, qtrue ); + firstendreach = AAS_FindFaceReachabilities( start_edgeverts, 4, &start_plane, qfalse ); + } //end else + // + //create reachabilities from start to end + for ( startreach = firststartreach; startreach; startreach = nextstartreach ) + { + nextstartreach = startreach->next; + // + //trace = AAS_TraceClientBBox(startreach->start, move_start_top, PRESENCE_NORMAL, -1); + //if (trace.fraction < 1) continue; + // + for ( endreach = firstendreach; endreach; endreach = nextendreach ) + { + nextendreach = endreach->next; + // + //trace = AAS_TraceClientBBox(endreach->end, move_end_top, PRESENCE_NORMAL, -1); + //if (trace.fraction < 1) continue; + // + Log_Write( "funcbob reach from area %d to %d\n", startreach->areanum, endreach->areanum ); + // + // + if ( i == 0 ) { + VectorCopy( move_start_top, org ); + } else { VectorCopy( move_end_top, org );} + VectorSubtract( startreach->start, org, dir ); + dir[2] = 0; + VectorNormalize( dir ); + VectorCopy( startreach->start, start ); + VectorMA( startreach->start, 1, dir, start ); + start[2] += 1; + VectorMA( startreach->start, 16, dir, end ); + end[2] += 1; + // + numareas = AAS_TraceAreas( start, end, areas, points, 10 ); + if ( numareas <= 0 ) { + continue; + } + if ( numareas > 1 ) { + VectorCopy( points[1], startreach->start ); + } else { VectorCopy( end, startreach->start );} + // + if ( !AAS_PointAreaNum( startreach->start ) ) { + continue; + } + if ( !AAS_PointAreaNum( endreach->end ) ) { + continue; + } + // + lreach = AAS_AllocReachability(); + lreach->areanum = endreach->areanum; + if ( i == 0 ) { + lreach->edgenum = ( (int)move_start[axis] << 16 ) | ( (int) move_end[axis] & 0x0000ffff ); + } else { lreach->edgenum = ( (int)move_end[axis] << 16 ) | ( (int) move_start[axis] & 0x0000ffff );} + lreach->facenum = ( spawnflags << 16 ) | modelnum; + VectorCopy( startreach->start, lreach->start ); + VectorCopy( endreach->end, lreach->end ); +#ifndef BSPC +// AAS_DrawArrow(lreach->start, lreach->end, LINECOLOR_BLUE, LINECOLOR_YELLOW); +// AAS_PermanentLine(lreach->start, lreach->end, 1); +#endif + lreach->traveltype = TRAVEL_FUNCBOB; + lreach->traveltime = 300; + reach_funcbob++; + lreach->next = areareachability[startreach->areanum]; + areareachability[startreach->areanum] = lreach; + // + } //end for + } //end for + for ( startreach = firststartreach; startreach; startreach = nextstartreach ) + { + nextstartreach = startreach->next; + AAS_FreeReachability( startreach ); + } //end for + for ( endreach = firstendreach; endreach; endreach = nextendreach ) + { + nextendreach = endreach->next; + AAS_FreeReachability( endreach ); + } //end for + //only go up with func_bobbing entities that go up and down + if ( !( spawnflags & 1 ) && !( spawnflags & 2 ) ) { + break; + } + } //end for + } //end for +} //end of the function AAS_Reachability_FuncBobbing +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_Reachability_JumpPad( void ) { + int face2num, i, ret, modelnum, area2num, visualize; + float speed, zvel, hordist, dist, time, height, gravity, forward; + aas_face_t *face2; + aas_area_t *area2; + aas_lreachability_t *lreach; + vec3_t areastart, facecenter, dir, cmdmove, teststart; + vec3_t velocity, origin, ent2origin, angles, absmins, absmaxs; + aas_clientmove_t move; + aas_trace_t trace; + int ent, ent2; + aas_link_t *areas, *link; + char target[MAX_EPAIRKEY], targetname[MAX_EPAIRKEY]; + char classname[MAX_EPAIRKEY], model[MAX_EPAIRKEY]; + + for ( ent = AAS_NextBSPEntity( 0 ); ent; ent = AAS_NextBSPEntity( ent ) ) + { + if ( !AAS_ValueForBSPEpairKey( ent, "classname", classname, MAX_EPAIRKEY ) ) { + continue; + } + if ( strcmp( classname, "trigger_push" ) ) { + continue; + } + // + AAS_FloatForBSPEpairKey( ent, "speed", &speed ); + if ( !speed ) { + speed = 1000; + } +// AAS_VectorForBSPEpairKey(ent, "angles", angles); +// AAS_SetMovedir(angles, velocity); +// VectorScale(velocity, speed, velocity); + VectorClear( angles ); + //get the mins, maxs and origin of the model + AAS_ValueForBSPEpairKey( ent, "model", model, MAX_EPAIRKEY ); + if ( model[0] ) { + modelnum = atoi( model + 1 ); + } else { modelnum = 0;} + AAS_BSPModelMinsMaxsOrigin( modelnum, angles, absmins, absmaxs, origin ); + VectorAdd( origin, absmins, absmins ); + VectorAdd( origin, absmaxs, absmaxs ); + // +#ifdef REACHDEBUG + botimport.Print( PRT_MESSAGE, "absmins = %f %f %f\n", absmins[0], absmins[1], absmins[2] ); + botimport.Print( PRT_MESSAGE, "absmaxs = %f %f %f\n", absmaxs[0], absmaxs[1], absmaxs[2] ); +#endif //REACHDEBUG + VectorAdd( absmins, absmaxs, origin ); + VectorScale( origin, 0.5, origin ); + + //get the start areas + VectorCopy( origin, teststart ); + teststart[2] += 64; + trace = AAS_TraceClientBBox( teststart, origin, PRESENCE_CROUCH, -1 ); + if ( trace.startsolid ) { + botimport.Print( PRT_MESSAGE, "trigger_push start solid\n" ); + VectorCopy( origin, areastart ); + } //end if + else + { + VectorCopy( trace.endpos, areastart ); + } //end else + areastart[2] += 0.125; + // + //AAS_DrawPermanentCross(origin, 4, 4); + //get the target entity + AAS_ValueForBSPEpairKey( ent, "target", target, MAX_EPAIRKEY ); + for ( ent2 = AAS_NextBSPEntity( 0 ); ent2; ent2 = AAS_NextBSPEntity( ent2 ) ) + { + if ( !AAS_ValueForBSPEpairKey( ent2, "targetname", targetname, MAX_EPAIRKEY ) ) { + continue; + } + if ( !strcmp( targetname, target ) ) { + break; + } + } //end for + if ( !ent2 ) { + botimport.Print( PRT_MESSAGE, "trigger_push without target entity %s\n", target ); + continue; + } //end if + AAS_VectorForBSPEpairKey( ent2, "origin", ent2origin ); + // + height = ent2origin[2] - origin[2]; + gravity = aassettings.sv_gravity; + time = sqrt( height / ( 0.5 * gravity ) ); + if ( !time ) { + botimport.Print( PRT_MESSAGE, "trigger_push without time\n" ); + continue; + } //end if + // set s.origin2 to the push velocity + VectorSubtract( ent2origin, origin, velocity ); + dist = VectorNormalize( velocity ); + forward = dist / time; + //FIXME: why multiply by 1.1 + forward *= 1.1; + VectorScale( velocity, forward, velocity ); + velocity[2] = time * gravity; + //get the areas the jump pad brush is in + areas = AAS_LinkEntityClientBBox( absmins, absmaxs, -1, PRESENCE_CROUCH ); + //* + for ( link = areas; link; link = link->next_area ) + { + if ( link->areanum == 5772 ) { + ret = qfalse; + } + } //*/ + for ( link = areas; link; link = link->next_area ) + { + if ( AAS_AreaJumpPad( link->areanum ) ) { + break; + } + } //end for + if ( !link ) { + botimport.Print( PRT_MESSAGE, "trigger_multiple not in any jump pad area\n" ); + AAS_UnlinkFromAreas( areas ); + continue; + } //end if + // + botimport.Print( PRT_MESSAGE, "found a trigger_push with velocity %f %f %f\n", velocity[0], velocity[1], velocity[2] ); + //if there is a horizontal velocity check for a reachability without air control + if ( velocity[0] || velocity[1] ) { + VectorSet( cmdmove, 0, 0, 0 ); + //VectorCopy(velocity, cmdmove); + //cmdmove[2] = 0; + memset( &move, 0, sizeof( aas_clientmove_t ) ); + area2num = 0; + for ( i = 0; i < 20; i++ ) + { + AAS_PredictClientMovement( &move, -1, areastart, PRESENCE_NORMAL, qfalse, + velocity, cmdmove, 0, 30, 0.1, + SE_HITGROUND | SE_ENTERWATER | SE_ENTERSLIME | + SE_ENTERLAVA | SE_HITGROUNDDAMAGE | SE_TOUCHJUMPPAD | SE_TOUCHTELEPORTER, 0, qfalse ); //qtrue); + area2num = AAS_PointAreaNum( move.endpos ); + for ( link = areas; link; link = link->next_area ) + { + if ( !AAS_AreaJumpPad( link->areanum ) ) { + continue; + } + if ( link->areanum == area2num ) { + break; + } + } //end if + if ( !link ) { + break; + } + VectorCopy( move.endpos, areastart ); + VectorCopy( move.velocity, velocity ); + } //end for + if ( area2num && i < 20 ) { + for ( link = areas; link; link = link->next_area ) + { + if ( !AAS_AreaJumpPad( link->areanum ) ) { + continue; + } + if ( AAS_ReachabilityExists( link->areanum, area2num ) ) { + continue; + } + //create a rocket or bfg jump reachability from area1 to area2 + lreach = AAS_AllocReachability(); + if ( !lreach ) { + AAS_UnlinkFromAreas( areas ); + return; + } //end if + lreach->areanum = area2num; + //NOTE: the facenum is the Z velocity + lreach->facenum = velocity[2]; + //NOTE: the edgenum is the horizontal velocity + lreach->edgenum = sqrt( velocity[0] * velocity[0] + velocity[1] * velocity[1] ); + VectorCopy( areastart, lreach->start ); + VectorCopy( move.endpos, lreach->end ); + lreach->traveltype = TRAVEL_JUMPPAD; + lreach->traveltime = 200; + lreach->next = areareachability[link->areanum]; + areareachability[link->areanum] = lreach; + // + reach_jumppad++; + } //end for + } //end if + } //end if + // + if ( fabs( velocity[0] ) > 100 || fabs( velocity[1] ) > 100 ) { + continue; + } + //check for areas we can reach with air control + for ( area2num = 1; area2num < ( *aasworld ).numareas; area2num++ ) + { + visualize = qfalse; + /* + if (area2num == 3568) + { + for (link = areas; link; link = link->next_area) + { + if (link->areanum == 3380) + { + visualize = qtrue; + botimport.Print(PRT_MESSAGE, "bah\n"); + } //end if + } //end for + } //end if*/ + //never try to go back to one of the original jumppad areas + //and don't create reachabilities if they already exist + for ( link = areas; link; link = link->next_area ) + { + if ( AAS_ReachabilityExists( link->areanum, area2num ) ) { + break; + } + if ( AAS_AreaJumpPad( link->areanum ) ) { + if ( link->areanum == area2num ) { + break; + } + } //end if + } //end if + if ( link ) { + continue; + } + // + area2 = &( *aasworld ).areas[area2num]; + for ( i = 0; i < area2->numfaces; i++ ) + { + face2num = ( *aasworld ).faceindex[area2->firstface + i]; + face2 = &( *aasworld ).faces[abs( face2num )]; + //if it is not a ground face + if ( !( face2->faceflags & FACE_GROUND ) ) { + continue; + } + //get the center of the face + AAS_FaceCenter( face2num, facecenter ); + //only go higher up + if ( facecenter[2] < areastart[2] ) { + continue; + } + //get the jumppad jump z velocity + zvel = velocity[2]; + //get the horizontal speed for the jump, if it isn't possible to calculate this + //speed (the jump is not possible) then there's no jump reachability created + ret = AAS_HorizontalVelocityForJump( zvel, areastart, facecenter, &speed ); + if ( ret && speed < 150 ) { + //direction towards the face center + VectorSubtract( facecenter, areastart, dir ); + dir[2] = 0; + hordist = VectorNormalize( dir ); + //if (hordist < 1.6 * facecenter[2] - areastart[2]) + { + //get command movement + VectorScale( dir, speed, cmdmove ); + // + AAS_PredictClientMovement( &move, -1, areastart, PRESENCE_NORMAL, qfalse, + velocity, cmdmove, 30, 30, 0.1, + SE_ENTERWATER | SE_ENTERSLIME | + SE_ENTERLAVA | SE_HITGROUNDDAMAGE | + SE_TOUCHJUMPPAD | SE_TOUCHTELEPORTER | SE_HITGROUNDAREA, area2num, visualize ); + //if prediction time wasn't enough to fully predict the movement + //don't enter slime or lava and don't fall from too high + if ( move.frames < 30 && + !( move.stopevent & ( SE_ENTERSLIME | SE_ENTERLAVA | SE_HITGROUNDDAMAGE ) ) + && ( move.stopevent & ( SE_HITGROUNDAREA | SE_TOUCHJUMPPAD | SE_TOUCHTELEPORTER ) ) ) { + for ( link = areas; link; link = link->next_area ) + { + if ( !AAS_AreaJumpPad( link->areanum ) ) { + continue; + } + if ( AAS_ReachabilityExists( link->areanum, area2num ) ) { + continue; + } + //create a jumppad reachability from area1 to area2 + lreach = AAS_AllocReachability(); + if ( !lreach ) { + AAS_UnlinkFromAreas( areas ); + return; + } //end if + lreach->areanum = area2num; + //NOTE: the facenum is the Z velocity + lreach->facenum = velocity[2]; + //NOTE: the edgenum is the horizontal velocity + lreach->edgenum = sqrt( cmdmove[0] * cmdmove[0] + cmdmove[1] * cmdmove[1] ); + VectorCopy( areastart, lreach->start ); + VectorCopy( facecenter, lreach->end ); + lreach->traveltype = TRAVEL_JUMPPAD; + lreach->traveltime = 250; + lreach->next = areareachability[link->areanum]; + areareachability[link->areanum] = lreach; + // + reach_jumppad++; + } //end for + } //end if + } //end if + } //end for + } //end for + } //end for + AAS_UnlinkFromAreas( areas ); + } //end for +} //end of the function AAS_Reachability_JumpPad +//=========================================================================== +// never point at ground faces +// always a higher and pretty far area +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_Reachability_Grapple( int area1num, int area2num ) { + int face2num, i, j, areanum, numareas, areas[20]; + float mingrappleangle, z, hordist; + bsp_trace_t bsptrace; + aas_trace_t trace; + aas_face_t *face2; + aas_area_t *area1, *area2; + aas_lreachability_t *lreach; + vec3_t areastart, facecenter, start, end, dir, down = {0, 0, -1}; + vec_t *v; + + //only grapple when on the ground or swimming + if ( !AAS_AreaGrounded( area1num ) && !AAS_AreaSwim( area1num ) ) { + return qfalse; + } + //don't grapple from a crouch area + if ( !( AAS_AreaPresenceType( area1num ) & PRESENCE_NORMAL ) ) { + return qfalse; + } + //NOTE: disabled area swim it doesn't work right + if ( AAS_AreaSwim( area1num ) ) { + return qfalse; + } + // + area1 = &( *aasworld ).areas[area1num]; + area2 = &( *aasworld ).areas[area2num]; + //don't grapple towards way lower areas + if ( area2->maxs[2] < area1->mins[2] ) { + return qfalse; + } + // + VectorCopy( ( *aasworld ).areas[area1num].center, start ); + //if not a swim area + if ( !AAS_AreaSwim( area1num ) ) { + if ( !AAS_PointAreaNum( start ) ) { + Log_Write( "area %d center %f %f %f in solid?\r\n", area1num, + start[0], start[1], start[2] ); + } + VectorCopy( start, end ); + end[2] -= 1000; + trace = AAS_TraceClientBBox( start, end, PRESENCE_CROUCH, -1 ); + if ( trace.startsolid ) { + return qfalse; + } + VectorCopy( trace.endpos, areastart ); + } //end if + else + { + if ( !( AAS_PointContents( start ) & ( CONTENTS_LAVA | CONTENTS_SLIME | CONTENTS_WATER ) ) ) { + return qfalse; + } + } //end else + // + //start is now the start point + // + for ( i = 0; i < area2->numfaces; i++ ) + { + face2num = ( *aasworld ).faceindex[area2->firstface + i]; + face2 = &( *aasworld ).faces[abs( face2num )]; + //if it is not a solid face + if ( !( face2->faceflags & FACE_SOLID ) ) { + continue; + } + //direction towards the first vertex of the face + v = ( *aasworld ).vertexes[( *aasworld ).edges[abs( ( *aasworld ).edgeindex[face2->firstedge] )].v[0]]; + VectorSubtract( v, areastart, dir ); + //if the face plane is facing away + if ( DotProduct( ( *aasworld ).planes[face2->planenum].normal, dir ) > 0 ) { + continue; + } + //get the center of the face + AAS_FaceCenter( face2num, facecenter ); + //only go higher up with the grapple + if ( facecenter[2] < areastart[2] + 64 ) { + continue; + } + //only use vertical faces or downward facing faces + if ( DotProduct( ( *aasworld ).planes[face2->planenum].normal, down ) < 0 ) { + continue; + } + //direction towards the face center + VectorSubtract( facecenter, areastart, dir ); + // + z = dir[2]; + dir[2] = 0; + hordist = VectorLength( dir ); + if ( !hordist ) { + continue; + } + //if too far + if ( hordist > 2000 ) { + continue; + } + //check the minimal angle of the movement + mingrappleangle = 15; //15 degrees + if ( z / hordist < tan( 2 * M_PI * mingrappleangle / 360 ) ) { + continue; + } + // + VectorCopy( facecenter, start ); + VectorMA( facecenter, -500, ( *aasworld ).planes[face2->planenum].normal, end ); + // + bsptrace = AAS_Trace( start, NULL, NULL, end, 0, CONTENTS_SOLID ); + //the grapple won't stick to the sky and the grapple point should be near the AAS wall + if ( ( bsptrace.surface.flags & SURF_SKY ) || ( bsptrace.fraction * 500 > 32 ) ) { + continue; + } + //trace a full bounding box from the area center on the ground to + //the center of the face + VectorSubtract( facecenter, areastart, dir ); + VectorNormalize( dir ); + VectorMA( areastart, 4, dir, start ); + VectorCopy( bsptrace.endpos, end ); + trace = AAS_TraceClientBBox( start, end, PRESENCE_NORMAL, -1 ); + VectorSubtract( trace.endpos, facecenter, dir ); + if ( VectorLength( dir ) > 24 ) { + continue; + } + // + VectorCopy( trace.endpos, start ); + VectorCopy( trace.endpos, end ); + end[2] -= AAS_FallDamageDistance(); + trace = AAS_TraceClientBBox( start, end, PRESENCE_NORMAL, -1 ); + if ( trace.fraction >= 1 ) { + continue; + } + //area to end in + areanum = AAS_PointAreaNum( trace.endpos ); + //if not in lava or slime + if ( ( *aasworld ).areasettings[areanum].contents & AREACONTENTS_LAVA ) { //----(SA) modified since slime is no longer deadly +// if ((*aasworld).areasettings[areanum].contents & (AREACONTENTS_SLIME|AREACONTENTS_LAVA)) + continue; + } //end if + //do not go the the source area + if ( areanum == area1num ) { + continue; + } + //don't create reachabilities if they already exist + if ( AAS_ReachabilityExists( area1num, areanum ) ) { + continue; + } + //only end in areas we can stand + if ( !AAS_AreaGrounded( areanum ) ) { + continue; + } + //never go through cluster portals!! + numareas = AAS_TraceAreas( areastart, bsptrace.endpos, areas, NULL, 20 ); + if ( numareas >= 20 ) { + continue; + } + for ( j = 0; j < numareas; j++ ) + { + if ( ( *aasworld ).areasettings[areas[j]].contents & AREACONTENTS_CLUSTERPORTAL ) { + break; + } + } //end for + if ( j < numareas ) { + continue; + } + //create a new reachability link + lreach = AAS_AllocReachability(); + if ( !lreach ) { + return qfalse; + } + lreach->areanum = areanum; + lreach->facenum = face2num; + lreach->edgenum = 0; + VectorCopy( areastart, lreach->start ); + //VectorCopy(facecenter, lreach->end); + VectorCopy( bsptrace.endpos, lreach->end ); + lreach->traveltype = TRAVEL_GRAPPLEHOOK; + VectorSubtract( lreach->end, lreach->start, dir ); + lreach->traveltime = STARTGRAPPLE_TIME + VectorLength( dir ) * 0.25; + lreach->next = areareachability[area1num]; + areareachability[area1num] = lreach; + // + reach_grapple++; + } //end for + // + return qfalse; +} //end of the function AAS_Reachability_Grapple +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_SetWeaponJumpAreaFlags( void ) { + int ent, i; + vec3_t mins = {-15, -15, -15}, maxs = {15, 15, 15}; + vec3_t origin; + int areanum, weaponjumpareas, spawnflags; + char classname[MAX_EPAIRKEY]; + + weaponjumpareas = 0; + for ( ent = AAS_NextBSPEntity( 0 ); ent; ent = AAS_NextBSPEntity( ent ) ) + { + if ( !AAS_ValueForBSPEpairKey( ent, "classname", classname, MAX_EPAIRKEY ) ) { + continue; + } + if ( + !strcmp( classname, "item_armor_body" ) || + !strcmp( classname, "item_armor_combat" ) || + !strcmp( classname, "item_health_mega" ) || + !strcmp( classname, "weapon_grenadelauncher" ) || + !strcmp( classname, "weapon_rocketlauncher" ) || + !strcmp( classname, "weapon_lightning" ) || + !strcmp( classname, "weapon_sp5" ) || + !strcmp( classname, "weapon_railgun" ) || + !strcmp( classname, "weapon_bfg" ) || + !strcmp( classname, "item_quad" ) || + !strcmp( classname, "item_regen" ) || + !strcmp( classname, "item_invulnerability" ) ) { + if ( AAS_VectorForBSPEpairKey( ent, "origin", origin ) ) { + spawnflags = 0; + AAS_IntForBSPEpairKey( ent, "spawnflags", &spawnflags ); + //if not a stationary item + if ( !( spawnflags & 1 ) ) { + if ( !AAS_DropToFloor( origin, mins, maxs ) ) { + botimport.Print( PRT_MESSAGE, "%s in solid at (%1.1f %1.1f %1.1f)\n", + classname, origin[0], origin[1], origin[2] ); + } //end if + } //end if + //areanum = AAS_PointAreaNum(origin); + areanum = AAS_BestReachableArea( origin, mins, maxs, origin ); + //the bot may rocket jump towards this area + ( *aasworld ).areasettings[areanum].areaflags |= AREA_WEAPONJUMP; + // + if ( !AAS_AreaGrounded( areanum ) ) { + botimport.Print( PRT_MESSAGE, "area not grounded\n" ); + } + // + weaponjumpareas++; + } //end if + } //end if + } //end for + for ( i = 1; i < ( *aasworld ).numareas; i++ ) + { + if ( ( *aasworld ).areasettings[i].contents & AREACONTENTS_JUMPPAD ) { + ( *aasworld ).areasettings[i].areaflags |= AREA_WEAPONJUMP; + weaponjumpareas++; + } //end if + } //end for + botimport.Print( PRT_MESSAGE, "%d weapon jump areas\n", weaponjumpareas ); +} //end of the function AAS_SetWeaponJumpAreaFlags +//=========================================================================== +// create a possible weapon jump reachability from area1 to area2 +// +// check if there's a cool item in the second area +// check if area1 is lower than area2 +// check if the bot can rocketjump from area1 to area2 +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_Reachability_WeaponJump( int area1num, int area2num ) { + int face2num, i, n, ret; + float speed, zvel, hordist; + aas_face_t *face2; + aas_area_t *area1, *area2; + aas_lreachability_t *lreach; + vec3_t areastart, facecenter, start, end, dir, cmdmove; // teststart; + vec3_t velocity; + aas_clientmove_t move; + aas_trace_t trace; + + if ( !AAS_AreaGrounded( area1num ) || AAS_AreaSwim( area1num ) ) { + return qfalse; + } + if ( !AAS_AreaGrounded( area2num ) ) { + return qfalse; + } + //NOTE: only weapon jump towards areas with an interesting item in it?? + if ( !( ( *aasworld ).areasettings[area2num].areaflags & AREA_WEAPONJUMP ) ) { + return qfalse; + } + // + area1 = &( *aasworld ).areas[area1num]; + area2 = &( *aasworld ).areas[area2num]; + //don't weapon jump towards way lower areas + if ( area2->maxs[2] < area1->mins[2] ) { + return qfalse; + } + // + VectorCopy( ( *aasworld ).areas[area1num].center, start ); + //if not a swim area + if ( !AAS_PointAreaNum( start ) ) { + Log_Write( "area %d center %f %f %f in solid?\r\n", area1num, + start[0], start[1], start[2] ); + } + VectorCopy( start, end ); + end[2] -= 1000; + trace = AAS_TraceClientBBox( start, end, PRESENCE_CROUCH, -1 ); + if ( trace.startsolid ) { + return qfalse; + } + VectorCopy( trace.endpos, areastart ); + // + //areastart is now the start point + // + for ( i = 0; i < area2->numfaces; i++ ) + { + face2num = ( *aasworld ).faceindex[area2->firstface + i]; + face2 = &( *aasworld ).faces[abs( face2num )]; + //if it is not a solid face + if ( !( face2->faceflags & FACE_GROUND ) ) { + continue; + } + //get the center of the face + AAS_FaceCenter( face2num, facecenter ); + //only go higher up with weapon jumps + if ( facecenter[2] < areastart[2] + 64 ) { + continue; + } + //NOTE: set to 2 to allow bfg jump reachabilities + for ( n = 0; n < 1 /*2*/; n++ ) + { + //get the rocket jump z velocity + if ( n ) { + zvel = AAS_BFGJumpZVelocity( areastart ); + } else { zvel = AAS_RocketJumpZVelocity( areastart );} + //get the horizontal speed for the jump, if it isn't possible to calculate this + //speed (the jump is not possible) then there's no jump reachability created + ret = AAS_HorizontalVelocityForJump( zvel, areastart, facecenter, &speed ); + if ( ret && speed < 270 ) { + //direction towards the face center + VectorSubtract( facecenter, areastart, dir ); + dir[2] = 0; + hordist = VectorNormalize( dir ); + //if (hordist < 1.6 * (facecenter[2] - areastart[2])) + { + //get command movement + VectorScale( dir, speed, cmdmove ); + VectorSet( velocity, 0, 0, zvel ); + /* + //get command movement + VectorScale(dir, speed, velocity); + velocity[2] = zvel; + VectorSet(cmdmove, 0, 0, 0); + */ + // + AAS_PredictClientMovement( &move, -1, areastart, PRESENCE_NORMAL, qtrue, + velocity, cmdmove, 30, 30, 0.1, + SE_ENTERWATER | SE_ENTERSLIME | + SE_ENTERLAVA | SE_HITGROUNDDAMAGE | + SE_TOUCHJUMPPAD | SE_HITGROUNDAREA, area2num, qfalse ); + //if prediction time wasn't enough to fully predict the movement + //don't enter slime or lava and don't fall from too high + if ( move.frames < 30 && + !( move.stopevent & ( SE_ENTERSLIME | SE_ENTERLAVA | SE_HITGROUNDDAMAGE ) ) + && ( move.stopevent & ( SE_HITGROUNDAREA | SE_TOUCHJUMPPAD ) ) ) { + //create a rocket or bfg jump reachability from area1 to area2 + lreach = AAS_AllocReachability(); + if ( !lreach ) { + return qfalse; + } + lreach->areanum = area2num; + lreach->facenum = 0; + lreach->edgenum = 0; + VectorCopy( areastart, lreach->start ); + VectorCopy( facecenter, lreach->end ); + if ( n ) { + lreach->traveltype = TRAVEL_BFGJUMP; + } else { lreach->traveltype = TRAVEL_ROCKETJUMP;} + lreach->traveltime = 300; + lreach->next = areareachability[area1num]; + areareachability[area1num] = lreach; + // + reach_rocketjump++; + return qtrue; + } //end if + } //end if + } //end if + } //end for + } //end for + // + return qfalse; +} //end of the function AAS_Reachability_WeaponJump +//=========================================================================== +// calculates additional walk off ledge reachabilities for the given area +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_Reachability_WalkOffLedge( int areanum ) { + int i, j, k, l, m, n; + int face1num, face2num, face3num, edge1num, edge2num, edge3num; + int otherareanum, gap, reachareanum, side; + aas_area_t *area, *area2; + aas_face_t *face1, *face2, *face3; + aas_edge_t *edge; + aas_plane_t *plane; + vec_t *v1, *v2; + vec3_t sharededgevec, mid, dir, testend; + aas_lreachability_t *lreach; + aas_trace_t trace; + + if ( !AAS_AreaGrounded( areanum ) || AAS_AreaSwim( areanum ) ) { + return; + } + // + area = &( *aasworld ).areas[areanum]; + // + for ( i = 0; i < area->numfaces; i++ ) + { + face1num = ( *aasworld ).faceindex[area->firstface + i]; + face1 = &( *aasworld ).faces[abs( face1num )]; + //face 1 must be a ground face + if ( !( face1->faceflags & FACE_GROUND ) ) { + continue; + } + //go through all the edges of this ground face + for ( k = 0; k < face1->numedges; k++ ) + { + edge1num = ( *aasworld ).edgeindex[face1->firstedge + k]; + //find another not ground face using this same edge + for ( j = 0; j < area->numfaces; j++ ) + { + face2num = ( *aasworld ).faceindex[area->firstface + j]; + face2 = &( *aasworld ).faces[abs( face2num )]; + //face 2 may not be a ground face + if ( face2->faceflags & FACE_GROUND ) { + continue; + } + //compare all the edges + for ( l = 0; l < face2->numedges; l++ ) + { + edge2num = ( *aasworld ).edgeindex[face2->firstedge + l]; + if ( abs( edge1num ) == abs( edge2num ) ) { + //get the area at the other side of the face + if ( face2->frontarea == areanum ) { + otherareanum = face2->backarea; + } else { otherareanum = face2->frontarea;} + // + area2 = &( *aasworld ).areas[otherareanum]; + //if the other area is grounded! + if ( ( *aasworld ).areasettings[otherareanum].areaflags & AREA_GROUNDED ) { + //check for a possible gap + gap = qfalse; + for ( n = 0; n < area2->numfaces; n++ ) + { + face3num = ( *aasworld ).faceindex[area2->firstface + n]; + //may not be the shared face of the two areas + if ( abs( face3num ) == abs( face2num ) ) { + continue; + } + // + face3 = &( *aasworld ).faces[abs( face3num )]; + //find an edge shared by all three faces + for ( m = 0; m < face3->numedges; m++ ) + { + edge3num = ( *aasworld ).edgeindex[face3->firstedge + m]; + //but the edge should be shared by all three faces + if ( abs( edge3num ) == abs( edge1num ) ) { + if ( !( face3->faceflags & FACE_SOLID ) ) { + gap = qtrue; + break; + } //end if + // + if ( face3->faceflags & FACE_GROUND ) { + gap = qfalse; + break; + } //end if + //FIXME: there are more situations to be handled + gap = qtrue; + break; + } //end if + } //end for + if ( m < face3->numedges ) { + break; + } + } //end for + if ( !gap ) { + break; + } + } //end if + //check for a walk off ledge reachability + edge = &( *aasworld ).edges[abs( edge1num )]; + side = edge1num < 0; + // + v1 = ( *aasworld ).vertexes[edge->v[side]]; + v2 = ( *aasworld ).vertexes[edge->v[!side]]; + // + plane = &( *aasworld ).planes[face1->planenum]; + //get the points really into the areas + VectorSubtract( v2, v1, sharededgevec ); + CrossProduct( plane->normal, sharededgevec, dir ); + VectorNormalize( dir ); + // + VectorAdd( v1, v2, mid ); + VectorScale( mid, 0.5, mid ); + VectorMA( mid, 8, dir, mid ); + // + VectorCopy( mid, testend ); + testend[2] -= 1000; + trace = AAS_TraceClientBBox( mid, testend, PRESENCE_CROUCH, -1 ); + // + if ( trace.startsolid ) { + //Log_Write("area %d: trace.startsolid\r\n", areanum); + break; + } //end if + reachareanum = AAS_PointAreaNum( trace.endpos ); + if ( reachareanum == areanum ) { + //Log_Write("area %d: same area\r\n", areanum); + break; + } //end if + if ( AAS_ReachabilityExists( areanum, reachareanum ) ) { + //Log_Write("area %d: reachability already exists\r\n", areanum); + break; + } //end if + if ( !AAS_AreaGrounded( reachareanum ) && !AAS_AreaSwim( reachareanum ) ) { + //Log_Write("area %d, reach area %d: not grounded and not swim\r\n", areanum, reachareanum); + break; + } //end if + // + if ( ( *aasworld ).areasettings[reachareanum].contents & AREACONTENTS_LAVA ) { //----(SA) modified since slime is no longer deadly +// if ((*aasworld).areasettings[reachareanum].contents & (AREACONTENTS_SLIME | AREACONTENTS_LAVA)) + //Log_Write("area %d, reach area %d: lava or slime\r\n", areanum, reachareanum); + break; + } //end if + lreach = AAS_AllocReachability(); + if ( !lreach ) { + break; + } + lreach->areanum = reachareanum; + lreach->facenum = 0; + lreach->edgenum = edge1num; + VectorCopy( mid, lreach->start ); + VectorCopy( trace.endpos, lreach->end ); + lreach->traveltype = TRAVEL_WALKOFFLEDGE; + lreach->traveltime = STARTWALKOFFLEDGE_TIME + fabs( mid[2] - trace.endpos[2] ) * 50 / aassettings.sv_gravity; + if ( !AAS_AreaSwim( reachareanum ) && !AAS_AreaJumpPad( reachareanum ) ) { + if ( AAS_FallDelta( mid[2] - trace.endpos[2] ) > FALLDELTA_5DAMAGE ) { + lreach->traveltime += FALLDAMAGE_5_TIME; + } //end if + else if ( AAS_FallDelta( mid[2] - trace.endpos[2] ) > FALLDELTA_10DAMAGE ) { + lreach->traveltime += FALLDAMAGE_10_TIME; + } //end if + } //end if + lreach->next = areareachability[areanum]; + areareachability[areanum] = lreach; + //we've got another walk off ledge reachability + reach_walkoffledge++; + } //end if + } //end for + } //end for + } //end for + } //end for +} //end of the function AAS_Reachability_WalkOffLedge +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_StoreReachability( void ) { + int i; + aas_areasettings_t *areasettings; + aas_lreachability_t *lreach; + aas_reachability_t *reach; + + if ( ( *aasworld ).reachability ) { + FreeMemory( ( *aasworld ).reachability ); + } + ( *aasworld ).reachability = (aas_reachability_t *) GetClearedMemory( ( numlreachabilities + 10 ) * sizeof( aas_reachability_t ) ); + ( *aasworld ).reachabilitysize = 1; + for ( i = 0; i < ( *aasworld ).numareas; i++ ) + { + areasettings = &( *aasworld ).areasettings[i]; + areasettings->firstreachablearea = ( *aasworld ).reachabilitysize; + areasettings->numreachableareas = 0; + for ( lreach = areareachability[i]; lreach; lreach = lreach->next ) + { + reach = &( *aasworld ).reachability[areasettings->firstreachablearea + + areasettings->numreachableareas]; + reach->areanum = lreach->areanum; + reach->facenum = lreach->facenum; + reach->edgenum = lreach->edgenum; + VectorCopy( lreach->start, reach->start ); + VectorCopy( lreach->end, reach->end ); + reach->traveltype = lreach->traveltype; + reach->traveltime = lreach->traveltime; + // RF, enforce the min reach time + if ( reach->traveltime < REACH_MIN_TIME ) { + reach->traveltime = REACH_MIN_TIME; + } + // + areasettings->numreachableareas++; + } //end for + ( *aasworld ).reachabilitysize += areasettings->numreachableareas; + } //end for +} //end of the function AAS_StoreReachability +//=========================================================================== +// +// TRAVEL_WALK 100% equal floor height + steps +// TRAVEL_CROUCH 100% +// TRAVEL_BARRIERJUMP 100% +// TRAVEL_JUMP 80% +// TRAVEL_LADDER 100% + fall down from ladder + jump up to ladder +// TRAVEL_WALKOFFLEDGE 90% walk off very steep walls? +// TRAVEL_SWIM 100% +// TRAVEL_WATERJUMP 100% +// TRAVEL_TELEPORT 100% +// TRAVEL_ELEVATOR 100% +// TRAVEL_GRAPPLEHOOK 100% +// TRAVEL_DOUBLEJUMP 0% +// TRAVEL_RAMPJUMP 0% +// TRAVEL_STRAFEJUMP 0% +// TRAVEL_ROCKETJUMP 100% (currently limited towards areas with items) +// TRAVEL_BFGJUMP 0% (currently disabled) +// TRAVEL_JUMPPAD 100% +// TRAVEL_FUNCBOB 100% +// +// Parameter: - +// Returns: true if NOT finished +// Changes Globals: - +//=========================================================================== +int AAS_ContinueInitReachability( float time ) { + int i, j, todo, start_time; + static float framereachability, reachability_delay; + static int lastpercentage; + + if ( !( *aasworld ).loaded ) { + return qfalse; + } + //if reachability is calculated for all areas + if ( ( *aasworld ).reachabilityareas >= ( *aasworld ).numareas + 2 ) { + return qfalse; + } + //if starting with area 1 (area 0 is a dummy) + if ( ( *aasworld ).reachabilityareas == 1 ) { + botimport.Print( PRT_MESSAGE, "calculating reachability...\n" ); + lastpercentage = 0; + framereachability = 2000; + reachability_delay = 1000; + } //end if + //number of areas to calculate reachability for this cycle + todo = ( *aasworld ).reachabilityareas + (int) framereachability; + start_time = Sys_MilliSeconds(); + //loop over the areas + for ( i = ( *aasworld ).reachabilityareas; i < ( *aasworld ).numareas && i < todo; i++ ) + { + ( *aasworld ).reachabilityareas++; + //only create jumppad reachabilities from jumppad areas + if ( ( *aasworld ).areasettings[i].contents & AREACONTENTS_JUMPPAD ) { + continue; + } //end if + //loop over the areas + for ( j = 1; j < ( *aasworld ).numareas; j++ ) + { + if ( i == j ) { + continue; + } + //never create reachabilities from teleporter or jumppad areas to regular areas + if ( ( *aasworld ).areasettings[i].contents & ( AREACONTENTS_TELEPORTER | AREACONTENTS_JUMPPAD ) ) { + if ( !( ( *aasworld ).areasettings[j].contents & ( AREACONTENTS_TELEPORTER | AREACONTENTS_JUMPPAD ) ) ) { + continue; + } //end if + } //end if + //if there already is a reachability link from area i to j + if ( AAS_ReachabilityExists( i, j ) ) { + continue; + } + //check for a swim reachability + if ( AAS_Reachability_Swim( i, j ) ) { + continue; + } + //check for a simple walk on equal floor height reachability + if ( AAS_Reachability_EqualFloorHeight( i, j ) ) { + continue; + } + //check for step, barrier, waterjump and walk off ledge reachabilities + if ( AAS_Reachability_Step_Barrier_WaterJump_WalkOffLedge( i, j ) ) { + continue; + } + //check for ladder reachabilities + if ( AAS_Reachability_Ladder( i, j ) ) { + continue; + } + //check for a jump reachability + if ( AAS_Reachability_Jump( i, j ) ) { + continue; + } + } //end for + //never create these reachabilities from teleporter or jumppad areas + if ( ( *aasworld ).areasettings[i].contents & ( AREACONTENTS_TELEPORTER | AREACONTENTS_JUMPPAD ) ) { + continue; + } //end if + //loop over the areas + for ( j = 1; j < ( *aasworld ).numareas; j++ ) + { + if ( i == j ) { + continue; + } + // + if ( AAS_ReachabilityExists( i, j ) ) { + continue; + } + //check for a grapple hook reachability +// Ridah, no grapple +// AAS_Reachability_Grapple(i, j); + //check for a weapon jump reachability +// Ridah, no weapon jumping +// AAS_Reachability_WeaponJump(i, j); + } //end for + //if the calculation took more time than the max reachability delay + if ( Sys_MilliSeconds() - start_time > (int) reachability_delay ) { + break; + } + // + if ( ( *aasworld ).reachabilityareas * 1000 / ( *aasworld ).numareas > lastpercentage ) { + break; + } + } //end for + // + if ( ( *aasworld ).reachabilityareas == ( *aasworld ).numareas ) { + botimport.Print( PRT_MESSAGE, "\r%6.1f%%", (float) 100.0 ); + botimport.Print( PRT_MESSAGE, "\nplease wait while storing reachability...\n" ); + ( *aasworld ).reachabilityareas++; + } //end if + //if this is the last step in the reachability calculations + else if ( ( *aasworld ).reachabilityareas == ( *aasworld ).numareas + 1 ) { + //create additional walk off ledge reachabilities for every area + for ( i = 1; i < ( *aasworld ).numareas; i++ ) + { + //only create jumppad reachabilities from jumppad areas + if ( ( *aasworld ).areasettings[i].contents & AREACONTENTS_JUMPPAD ) { + continue; + } //end if + AAS_Reachability_WalkOffLedge( i ); + } //end for + //create jump pad reachabilities + AAS_Reachability_JumpPad(); + //create teleporter reachabilities + AAS_Reachability_Teleport(); + //create elevator (func_plat) reachabilities + AAS_Reachability_Elevator(); + //create func_bobbing reachabilities + AAS_Reachability_FuncBobbing(); + // +//#ifdef DEBUG + botimport.Print( PRT_MESSAGE, "%6d reach swim\n", reach_swim ); + botimport.Print( PRT_MESSAGE, "%6d reach equal floor\n", reach_equalfloor ); + botimport.Print( PRT_MESSAGE, "%6d reach step\n", reach_step ); + botimport.Print( PRT_MESSAGE, "%6d reach barrier\n", reach_barrier ); + botimport.Print( PRT_MESSAGE, "%6d reach waterjump\n", reach_waterjump ); + botimport.Print( PRT_MESSAGE, "%6d reach walkoffledge\n", reach_walkoffledge ); + botimport.Print( PRT_MESSAGE, "%6d reach jump\n", reach_jump ); + botimport.Print( PRT_MESSAGE, "%6d reach ladder\n", reach_ladder ); + botimport.Print( PRT_MESSAGE, "%6d reach walk\n", reach_walk ); + botimport.Print( PRT_MESSAGE, "%6d reach teleport\n", reach_teleport ); + botimport.Print( PRT_MESSAGE, "%6d reach funcbob\n", reach_funcbob ); + botimport.Print( PRT_MESSAGE, "%6d reach elevator\n", reach_elevator ); + botimport.Print( PRT_MESSAGE, "%6d reach grapple\n", reach_grapple ); + botimport.Print( PRT_MESSAGE, "%6d reach rocketjump\n", reach_rocketjump ); + botimport.Print( PRT_MESSAGE, "%6d reach jumppad\n", reach_jumppad ); +//#endif + //*/ + //store all the reachabilities + AAS_StoreReachability(); + //free the reachability link heap + AAS_ShutDownReachabilityHeap(); + // + FreeMemory( areareachability ); + // + ( *aasworld ).reachabilityareas++; + // + botimport.Print( PRT_MESSAGE, "calculating clusters...\n" ); + } //end if + else + { + lastpercentage = ( *aasworld ).reachabilityareas * 1000 / ( *aasworld ).numareas; + botimport.Print( PRT_MESSAGE, "\r%6.1f%%", (float) lastpercentage / 10 ); + } //end else + //not yet finished + return qtrue; +} //end of the function AAS_ContinueInitReachability +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_InitReachability( void ) { + if ( !( *aasworld ).loaded ) { + return; + } + + if ( ( *aasworld ).reachabilitysize ) { +#ifndef BSPC + if ( !( (int)LibVarGetValue( "forcereachability" ) ) ) { + ( *aasworld ).reachabilityareas = ( *aasworld ).numareas + 2; + return; + } //end if +#else + ( *aasworld ).reachabilityareas = ( *aasworld ).numareas + 2; + return; +#endif //BSPC + } //end if + ( *aasworld ).savefile = qtrue; + //start with area 1 because area zero is a dummy + ( *aasworld ).reachabilityareas = 1; + //setup the heap with reachability links + AAS_SetupReachabilityHeap(); + //allocate area reachability link array + areareachability = (aas_lreachability_t **) GetClearedMemory( + ( *aasworld ).numareas * sizeof( aas_lreachability_t * ) ); + // + AAS_SetWeaponJumpAreaFlags(); +} //end of the function AAS_InitReachable diff --git a/Projects/Android/jni/rtcw/src/botlib/be_aas_reach.h b/Projects/Android/jni/rtcw/src/botlib/be_aas_reach.h new file mode 100644 index 0000000..8c5f615 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/botlib/be_aas_reach.h @@ -0,0 +1,74 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +/***************************************************************************** + * name: be_aas_reach.h + * + * desc: AAS + * + * + *****************************************************************************/ + +#ifdef AASINTERN +//initialize calculating the reachabilities +void AAS_InitReachability( void ); +//continue calculating the reachabilities +int AAS_ContinueInitReachability( float time ); +// +int AAS_BestReachableLinkArea( aas_link_t *areas ); +#endif //AASINTERN + +//returns true if the are has reachabilities to other areas +int AAS_AreaReachability( int areanum ); +//returns the best reachable area and goal origin for a bounding box at the given origin +int AAS_BestReachableArea( vec3_t origin, vec3_t mins, vec3_t maxs, vec3_t goalorigin ); +//returns the next reachability using the given model +int AAS_NextModelReachability( int num, int modelnum ); +//returns the total area of the ground faces of the given area +float AAS_AreaGroundFaceArea( int areanum ); +//returns true if the area is crouch only +int AAS_AreaCrouch( int areanum ); +//returns true if a player can swim in this area +int AAS_AreaSwim( int areanum ); +//returns true if the area is filled with a liquid +int AAS_AreaLiquid( int areanum ); +//returns true if the area contains lava +int AAS_AreaLava( int areanum ); +//returns true if the area contains slime +int AAS_AreaSlime( int areanum ); +//returns true if the area has one or more ground faces +int AAS_AreaGrounded( int areanum ); +//returns true if the area has one or more ladder faces +int AAS_AreaLadder( int areanum ); +//returns true if the area is a jump pad +int AAS_AreaJumpPad( int areanum ); +//returns true if the area is donotenter +int AAS_AreaDoNotEnter( int areanum ); +//returns true if the area is donotenterlarge +int AAS_AreaDoNotEnterLarge( int areanum ); diff --git a/Projects/Android/jni/rtcw/src/botlib/be_aas_route.c b/Projects/Android/jni/rtcw/src/botlib/be_aas_route.c new file mode 100644 index 0000000..7cec1f3 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/botlib/be_aas_route.c @@ -0,0 +1,2640 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +/***************************************************************************** + * name: be_aas_route.c + * + * desc: AAS + * + * + *****************************************************************************/ + +#include "../game/q_shared.h" +#include "l_utils.h" +#include "l_memory.h" +#include "l_log.h" +#include "l_crc.h" +#include "l_libvar.h" +#include "l_script.h" +#include "l_precomp.h" +#include "l_struct.h" +#include "aasfile.h" +#include "../game/botlib.h" +#include "../game/be_aas.h" +#include "be_aas_funcs.h" +#include "be_interface.h" +#include "be_aas_def.h" + +#define ROUTING_DEBUG + +//travel time in hundreths of a second = distance * 100 / speed +#define DISTANCEFACTOR_CROUCH 1.3 //crouch speed = 100 +#define DISTANCEFACTOR_SWIM 1 //should be 0.66, swim speed = 150 +#define DISTANCEFACTOR_WALK 0.33 //walk speed = 300 + +// Ridah, scale traveltimes with ground steepness of area +#define GROUNDSTEEPNESS_TIMESCALE 20 // this is the maximum scale, 1 being the usual for a flat ground + +//cache refresh time +#define CACHE_REFRESHTIME 15.0 //15 seconds refresh time + +//maximum number of routing updates each frame +#define MAX_FRAMEROUTINGUPDATES 100 + +extern aas_t aasworlds[MAX_AAS_WORLDS]; + + +/* + + area routing cache: + stores the distances within one cluster to a specific goal area + this goal area is in this same cluster and could be a cluster portal + for every cluster there's a list with routing cache for every area + in that cluster (including the portals of that cluster) + area cache stores (*aasworld).clusters[?].numreachabilityareas travel times + + portal routing cache: + stores the distances of all portals to a specific goal area + this goal area could be in any cluster and could also be a cluster portal + for every area ((*aasworld).numareas) the portal cache stores + (*aasworld).numportals travel times + +*/ + +#ifdef ROUTING_DEBUG +int numareacacheupdates; +int numportalcacheupdates; +#endif //ROUTING_DEBUG + +int routingcachesize; +int max_routingcachesize; + +// Ridah, routing memory calls go here, so we can change between Hunk/Zone easily +void *AAS_RoutingGetMemory( int size ) { + return GetClearedMemory( size ); +} + +void AAS_RoutingFreeMemory( void *ptr ) { + FreeMemory( ptr ); +} +// done. + +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +#ifdef ROUTING_DEBUG +void AAS_RoutingInfo( void ) { + botimport.Print( PRT_MESSAGE, "%d area cache updates\n", numareacacheupdates ); + botimport.Print( PRT_MESSAGE, "%d portal cache updates\n", numportalcacheupdates ); + botimport.Print( PRT_MESSAGE, "%d bytes routing cache\n", routingcachesize ); +} //end of the function AAS_RoutingInfo +#endif //ROUTING_DEBUG +//=========================================================================== +// returns the number of the area in the cluster +// assumes the given area is in the given cluster or a portal of the cluster +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +__inline int AAS_ClusterAreaNum( int cluster, int areanum ) { + int side, areacluster; + + areacluster = ( *aasworld ).areasettings[areanum].cluster; + if ( areacluster > 0 ) { + return ( *aasworld ).areasettings[areanum].clusterareanum; + } else + { +/*#ifdef ROUTING_DEBUG + if ((*aasworld).portals[-areacluster].frontcluster != cluster && + (*aasworld).portals[-areacluster].backcluster != cluster) + { + botimport.Print(PRT_ERROR, "portal %d: does not belong to cluster %d\n" + , -areacluster, cluster); + } //end if +#endif //ROUTING_DEBUG*/ + side = ( *aasworld ).portals[-areacluster].frontcluster != cluster; + return ( *aasworld ).portals[-areacluster].clusterareanum[side]; + } //end else +} //end of the function AAS_ClusterAreaNum +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_InitTravelFlagFromType( void ) { + int i; + + for ( i = 0; i < MAX_TRAVELTYPES; i++ ) + { + ( *aasworld ).travelflagfortype[i] = TFL_INVALID; + } //end for + ( *aasworld ).travelflagfortype[TRAVEL_INVALID] = TFL_INVALID; + ( *aasworld ).travelflagfortype[TRAVEL_WALK] = TFL_WALK; + ( *aasworld ).travelflagfortype[TRAVEL_CROUCH] = TFL_CROUCH; + ( *aasworld ).travelflagfortype[TRAVEL_BARRIERJUMP] = TFL_BARRIERJUMP; + ( *aasworld ).travelflagfortype[TRAVEL_JUMP] = TFL_JUMP; + ( *aasworld ).travelflagfortype[TRAVEL_LADDER] = TFL_LADDER; + ( *aasworld ).travelflagfortype[TRAVEL_WALKOFFLEDGE] = TFL_WALKOFFLEDGE; + ( *aasworld ).travelflagfortype[TRAVEL_SWIM] = TFL_SWIM; + ( *aasworld ).travelflagfortype[TRAVEL_WATERJUMP] = TFL_WATERJUMP; + ( *aasworld ).travelflagfortype[TRAVEL_TELEPORT] = TFL_TELEPORT; + ( *aasworld ).travelflagfortype[TRAVEL_ELEVATOR] = TFL_ELEVATOR; + ( *aasworld ).travelflagfortype[TRAVEL_ROCKETJUMP] = TFL_ROCKETJUMP; + ( *aasworld ).travelflagfortype[TRAVEL_BFGJUMP] = TFL_BFGJUMP; + ( *aasworld ).travelflagfortype[TRAVEL_GRAPPLEHOOK] = TFL_GRAPPLEHOOK; + ( *aasworld ).travelflagfortype[TRAVEL_DOUBLEJUMP] = TFL_DOUBLEJUMP; + ( *aasworld ).travelflagfortype[TRAVEL_RAMPJUMP] = TFL_RAMPJUMP; + ( *aasworld ).travelflagfortype[TRAVEL_STRAFEJUMP] = TFL_STRAFEJUMP; + ( *aasworld ).travelflagfortype[TRAVEL_JUMPPAD] = TFL_JUMPPAD; + ( *aasworld ).travelflagfortype[TRAVEL_FUNCBOB] = TFL_FUNCBOB; +} //end of the function AAS_InitTravelFlagFromType +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_TravelFlagForType( int traveltype ) { + if ( traveltype < 0 || traveltype >= MAX_TRAVELTYPES ) { + return TFL_INVALID; + } + return ( *aasworld ).travelflagfortype[traveltype]; +} //end of the function AAS_TravelFlagForType +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +__inline float AAS_RoutingTime( void ) { + return AAS_Time(); +} //end of the function AAS_RoutingTime +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_FreeRoutingCache( aas_routingcache_t *cache ) { + routingcachesize -= cache->size; + AAS_RoutingFreeMemory( cache ); +} //end of the function AAS_FreeRoutingCache +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_RemoveRoutingCacheInCluster( int clusternum ) { + int i; + aas_routingcache_t *cache, *nextcache; + aas_cluster_t *cluster; + + if ( !( *aasworld ).clusterareacache ) { + return; + } + cluster = &( *aasworld ).clusters[clusternum]; + for ( i = 0; i < cluster->numareas; i++ ) + { + for ( cache = ( *aasworld ).clusterareacache[clusternum][i]; cache; cache = nextcache ) + { + nextcache = cache->next; + AAS_FreeRoutingCache( cache ); + } //end for + ( *aasworld ).clusterareacache[clusternum][i] = NULL; + } //end for +} //end of the function AAS_RemoveRoutingCacheInCluster +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_RemoveRoutingCacheUsingArea( int areanum ) { + int i, clusternum; + aas_routingcache_t *cache, *nextcache; + + clusternum = ( *aasworld ).areasettings[areanum].cluster; + if ( clusternum > 0 ) { + //remove all the cache in the cluster the area is in + AAS_RemoveRoutingCacheInCluster( clusternum ); + } //end if + else + { + // if this is a portal remove all cache in both the front and back cluster + AAS_RemoveRoutingCacheInCluster( ( *aasworld ).portals[-clusternum].frontcluster ); + AAS_RemoveRoutingCacheInCluster( ( *aasworld ).portals[-clusternum].backcluster ); + } //end else + // remove all portal cache + if ( ( *aasworld ).portalcache ) { + for ( i = 0; i < ( *aasworld ).numareas; i++ ) + { + //refresh portal cache + for ( cache = ( *aasworld ).portalcache[i]; cache; cache = nextcache ) + { + nextcache = cache->next; + AAS_FreeRoutingCache( cache ); + } //end for + ( *aasworld ).portalcache[i] = NULL; + } //end for + } +} //end of the function AAS_RemoveRoutingCacheUsingArea +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_EnableRoutingArea( int areanum, int enable ) { + int flags; + + if ( areanum <= 0 || areanum >= ( *aasworld ).numareas ) { + if ( bot_developer ) { + botimport.Print( PRT_ERROR, "AAS_EnableRoutingArea: areanum %d out of range\n", areanum ); + } //end if + return 0; + } //end if + flags = ( *aasworld ).areasettings[areanum].areaflags & AREA_DISABLED; + if ( enable < 0 ) { + return !flags; + } + + if ( enable ) { + ( *aasworld ).areasettings[areanum].areaflags &= ~AREA_DISABLED; + } else { + ( *aasworld ).areasettings[areanum].areaflags |= AREA_DISABLED; + } + // if the status of the area changed + if ( ( flags & AREA_DISABLED ) != ( ( *aasworld ).areasettings[areanum].areaflags & AREA_DISABLED ) ) { + //remove all routing cache involving this area + AAS_RemoveRoutingCacheUsingArea( areanum ); + } //end if + return !flags; +} //end of the function AAS_EnableRoutingArea +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_CreateReversedReachability( void ) { + int i, n; + aas_reversedlink_t *revlink; + aas_reachability_t *reach; + aas_areasettings_t *settings; + char *ptr; +#ifdef DEBUG + int starttime; + + starttime = Sys_MilliSeconds(); +#endif + //free reversed links that have already been created + if ( ( *aasworld ).reversedreachability ) { + AAS_RoutingFreeMemory( ( *aasworld ).reversedreachability ); + } + //allocate memory for the reversed reachability links + ptr = (char *) AAS_RoutingGetMemory( ( *aasworld ).numareas * sizeof( aas_reversedreachability_t ) + + ( *aasworld ).reachabilitysize * sizeof( aas_reversedlink_t ) ); + // + ( *aasworld ).reversedreachability = (aas_reversedreachability_t *) ptr; + //pointer to the memory for the reversed links + ptr += ( *aasworld ).numareas * sizeof( aas_reversedreachability_t ); + //check all other areas for reachability links to the area + for ( i = 1; i < ( *aasworld ).numareas; i++ ) + { + //settings of the area + settings = &( *aasworld ).areasettings[i]; + //check the reachability links + for ( n = 0; n < settings->numreachableareas; n++ ) + { + //reachability link + reach = &( *aasworld ).reachability[settings->firstreachablearea + n]; + // + revlink = (aas_reversedlink_t *) ptr; + ptr += sizeof( aas_reversedlink_t ); + // + revlink->areanum = i; + revlink->linknum = settings->firstreachablearea + n; + revlink->next = ( *aasworld ).reversedreachability[reach->areanum].first; + ( *aasworld ).reversedreachability[reach->areanum].first = revlink; + ( *aasworld ).reversedreachability[reach->areanum].numlinks++; + } //end for + } //end for +#ifdef DEBUG + botimport.Print( PRT_MESSAGE, "reversed reachability %d msec\n", Sys_MilliSeconds() - starttime ); +#endif //DEBUG +} //end of the function AAS_CreateReversedReachability +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +float AAS_AreaGroundSteepnessScale( int areanum ) { + return ( 1.0 + ( *aasworld ).areasettings[areanum].groundsteepness * (float)( GROUNDSTEEPNESS_TIMESCALE - 1 ) ); +} +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +unsigned short int AAS_AreaTravelTime( int areanum, vec3_t start, vec3_t end ) { + int intdist; + float dist; + vec3_t dir; + + VectorSubtract( start, end, dir ); + dist = VectorLength( dir ); + // Ridah, factor in the groundsteepness now + dist *= AAS_AreaGroundSteepnessScale( areanum ); + + //if crouch only area + if ( AAS_AreaCrouch( areanum ) ) { + dist *= DISTANCEFACTOR_CROUCH; + } + //if swim area + else if ( AAS_AreaSwim( areanum ) ) { + dist *= DISTANCEFACTOR_SWIM; + } + //normal walk area + else {dist *= DISTANCEFACTOR_WALK;} + // + intdist = (int) ceil( dist ); + //make sure the distance isn't zero + if ( intdist <= 0 ) { + intdist = 1; + } + return intdist; +} //end of the function AAS_AreaTravelTime +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_CalculateAreaTravelTimes( void ) { + int i, l, n, size; + char *ptr; + vec3_t end; + aas_reversedreachability_t *revreach; + aas_reversedlink_t *revlink; + aas_reachability_t *reach; + aas_areasettings_t *settings; + int starttime; + + starttime = Sys_MilliSeconds(); + //if there are still area travel times, free the memory + if ( ( *aasworld ).areatraveltimes ) { + AAS_RoutingFreeMemory( ( *aasworld ).areatraveltimes ); + } + //get the total size of all the area travel times + size = ( *aasworld ).numareas * sizeof( unsigned short ** ); + for ( i = 0; i < ( *aasworld ).numareas; i++ ) + { + revreach = &( *aasworld ).reversedreachability[i]; + //settings of the area + settings = &( *aasworld ).areasettings[i]; + // + size += settings->numreachableareas * sizeof( unsigned short * ); + // + size += settings->numreachableareas * revreach->numlinks * sizeof( unsigned short ); + } //end for + //allocate memory for the area travel times + ptr = (char *) AAS_RoutingGetMemory( size ); + ( *aasworld ).areatraveltimes = (unsigned short ***) ptr; + ptr += ( *aasworld ).numareas * sizeof( unsigned short ** ); + //calcluate the travel times for all the areas + for ( i = 0; i < ( *aasworld ).numareas; i++ ) + { + //reversed reachabilities of this area + revreach = &( *aasworld ).reversedreachability[i]; + //settings of the area + settings = &( *aasworld ).areasettings[i]; + // + ( *aasworld ).areatraveltimes[i] = (unsigned short **) ptr; + ptr += settings->numreachableareas * sizeof( unsigned short * ); + // + reach = &( *aasworld ).reachability[settings->firstreachablearea]; + for ( l = 0; l < settings->numreachableareas; l++, reach++ ) + { + ( *aasworld ).areatraveltimes[i][l] = (unsigned short *) ptr; + ptr += revreach->numlinks * sizeof( unsigned short ); + //reachability link + // + for ( n = 0, revlink = revreach->first; revlink; revlink = revlink->next, n++ ) + { + VectorCopy( ( *aasworld ).reachability[revlink->linknum].end, end ); + // + ( *aasworld ).areatraveltimes[i][l][n] = AAS_AreaTravelTime( i, end, reach->start ); + } //end for + } //end for + } //end for +#ifdef DEBUG + botimport.Print( PRT_MESSAGE, "area travel times %d msec\n", Sys_MilliSeconds() - starttime ); +#endif //DEBUG +} //end of the function AAS_CalculateAreaTravelTimes +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_PortalMaxTravelTime( int portalnum ) { + int l, n, t, maxt; + aas_portal_t *portal; + aas_reversedreachability_t *revreach; + aas_reversedlink_t *revlink; + aas_areasettings_t *settings; + + portal = &( *aasworld ).portals[portalnum]; + //reversed reachabilities of this portal area + revreach = &( *aasworld ).reversedreachability[portal->areanum]; + //settings of the portal area + settings = &( *aasworld ).areasettings[portal->areanum]; + // + maxt = 0; + for ( l = 0; l < settings->numreachableareas; l++ ) + { + for ( n = 0, revlink = revreach->first; revlink; revlink = revlink->next, n++ ) + { + t = ( *aasworld ).areatraveltimes[portal->areanum][l][n]; + if ( t > maxt ) { + maxt = t; + } //end if + } //end for + } //end for + return maxt; +} //end of the function AAS_PortalMaxTravelTime +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_InitPortalMaxTravelTimes( void ) { + int i; + + if ( ( *aasworld ).portalmaxtraveltimes ) { + AAS_RoutingFreeMemory( ( *aasworld ).portalmaxtraveltimes ); + } + + ( *aasworld ).portalmaxtraveltimes = (int *) AAS_RoutingGetMemory( ( *aasworld ).numportals * sizeof( int ) ); + + for ( i = 0; i < ( *aasworld ).numportals; i++ ) + { + ( *aasworld ).portalmaxtraveltimes[i] = AAS_PortalMaxTravelTime( i ); + //botimport.Print(PRT_MESSAGE, "portal %d max tt = %d\n", i, (*aasworld).portalmaxtraveltimes[i]); + } //end for +} //end of the function AAS_InitPortalMaxTravelTimes +/* +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_UnlinkCache(aas_routingcache_t *cache) +{ + if (cache->time_next) cache->time_next->time_prev = cache->time_prev; + else newestcache = cache->time_prev; + if (cache->time_prev) cache->time_prev->time_next = cache->time_next; + else oldestcache = cache->time_next; + cache->time_next = NULL; + cache->time_prev = NULL; +} //end of the function AAS_UnlinkCache +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_LinkCache(aas_routingcache_t *cache) +{ + if (newestcache) + { + newestcache->time_next = cache; + cache->time_prev = cache; + } //end if + else + { + oldestcache = cache; + cache->time_prev = NULL; + } //end else + cache->time_next = NULL; + newestcache = cache; +} //end of the function AAS_LinkCache*/ +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_FreeOldestCache( void ) { + int i, j, bestcluster, bestarea, freed; + float besttime; + aas_routingcache_t *cache, *bestcache; + + freed = qfalse; + besttime = 999999999; + bestcache = NULL; + bestcluster = 0; + bestarea = 0; + //refresh cluster cache + for ( i = 0; i < ( *aasworld ).numclusters; i++ ) + { + for ( j = 0; j < ( *aasworld ).clusters[i].numareas; j++ ) + { + for ( cache = ( *aasworld ).clusterareacache[i][j]; cache; cache = cache->next ) + { + //never remove cache leading towards a portal + if ( ( *aasworld ).areasettings[cache->areanum].cluster < 0 ) { + continue; + } + //if this cache is older than the cache we found so far + if ( cache->time < besttime ) { + bestcache = cache; + bestcluster = i; + bestarea = j; + besttime = cache->time; + } //end if + } //end for + } //end for + } //end for + if ( bestcache ) { + cache = bestcache; + if ( cache->prev ) { + cache->prev->next = cache->next; + } else { ( *aasworld ).clusterareacache[bestcluster][bestarea] = cache->next;} + if ( cache->next ) { + cache->next->prev = cache->prev; + } + AAS_FreeRoutingCache( cache ); + freed = qtrue; + } //end if + besttime = 999999999; + bestcache = NULL; + bestarea = 0; + for ( i = 0; i < ( *aasworld ).numareas; i++ ) + { + //refresh portal cache + for ( cache = ( *aasworld ).portalcache[i]; cache; cache = cache->next ) + { + if ( cache->time < besttime ) { + bestcache = cache; + bestarea = i; + besttime = cache->time; + } //end if + } //end for + } //end for + if ( bestcache ) { + cache = bestcache; + if ( cache->prev ) { + cache->prev->next = cache->next; + } else { ( *aasworld ).portalcache[bestarea] = cache->next;} + if ( cache->next ) { + cache->next->prev = cache->prev; + } + AAS_FreeRoutingCache( cache ); + freed = qtrue; + } //end if + return freed; +} //end of the function AAS_FreeOldestCache +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +aas_routingcache_t *AAS_AllocRoutingCache( int numtraveltimes ) { + aas_routingcache_t *cache; + int size; + + // + size = sizeof( aas_routingcache_t ) + + numtraveltimes * sizeof( unsigned short int ) + + numtraveltimes * sizeof( unsigned char ); + // + routingcachesize += size; + // + cache = (aas_routingcache_t *) AAS_RoutingGetMemory( size ); + cache->reachabilities = (unsigned char *) cache + sizeof( aas_routingcache_t ) + + numtraveltimes * sizeof( unsigned short int ); + cache->size = size; + return cache; +} //end of the function AAS_AllocRoutingCache +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_FreeAllClusterAreaCache( void ) { + int i, j; + aas_routingcache_t *cache, *nextcache; + aas_cluster_t *cluster; + + //free all cluster cache if existing + if ( !( *aasworld ).clusterareacache ) { + return; + } + //free caches + for ( i = 0; i < ( *aasworld ).numclusters; i++ ) + { + cluster = &( *aasworld ).clusters[i]; + for ( j = 0; j < cluster->numareas; j++ ) + { + for ( cache = ( *aasworld ).clusterareacache[i][j]; cache; cache = nextcache ) + { + nextcache = cache->next; + AAS_FreeRoutingCache( cache ); + } //end for + ( *aasworld ).clusterareacache[i][j] = NULL; + } //end for + } //end for + //free the cluster cache array + AAS_RoutingFreeMemory( ( *aasworld ).clusterareacache ); + ( *aasworld ).clusterareacache = NULL; +} //end of the function AAS_FreeAllClusterAreaCache +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_InitClusterAreaCache( void ) { + int i, size; + char *ptr; + + // + for ( size = 0, i = 0; i < ( *aasworld ).numclusters; i++ ) + { + size += ( *aasworld ).clusters[i].numareas; + } //end for + //two dimensional array with pointers for every cluster to routing cache + //for every area in that cluster + ptr = (char *) AAS_RoutingGetMemory( + ( *aasworld ).numclusters * sizeof( aas_routingcache_t * * ) + + size * sizeof( aas_routingcache_t * ) ); + ( *aasworld ).clusterareacache = (aas_routingcache_t ***) ptr; + ptr += ( *aasworld ).numclusters * sizeof( aas_routingcache_t * * ); + for ( i = 0; i < ( *aasworld ).numclusters; i++ ) + { + ( *aasworld ).clusterareacache[i] = (aas_routingcache_t **) ptr; + ptr += ( *aasworld ).clusters[i].numareas * sizeof( aas_routingcache_t * ); + } //end for +} //end of the function AAS_InitClusterAreaCache +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_FreeAllPortalCache( void ) { + int i; + aas_routingcache_t *cache, *nextcache; + + //free all portal cache if existing + if ( !( *aasworld ).portalcache ) { + return; + } + //free portal caches + for ( i = 0; i < ( *aasworld ).numareas; i++ ) + { + for ( cache = ( *aasworld ).portalcache[i]; cache; cache = nextcache ) + { + nextcache = cache->next; + AAS_FreeRoutingCache( cache ); + } //end for + ( *aasworld ).portalcache[i] = NULL; + } //end for + AAS_RoutingFreeMemory( ( *aasworld ).portalcache ); + ( *aasworld ).portalcache = NULL; +} //end of the function AAS_FreeAllPortalCache +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_InitPortalCache( void ) { + // + ( *aasworld ).portalcache = (aas_routingcache_t **) AAS_RoutingGetMemory( + ( *aasworld ).numareas * sizeof( aas_routingcache_t * ) ); +} //end of the function AAS_InitPortalCache +// +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_FreeAreaVisibility( void ) { + int i; + + if ( ( *aasworld ).areavisibility ) { + for ( i = 0; i < ( *aasworld ).numareas; i++ ) + { + if ( ( *aasworld ).areavisibility[i] ) { + FreeMemory( ( *aasworld ).areavisibility[i] ); + } + } + } + if ( ( *aasworld ).areavisibility ) { + FreeMemory( ( *aasworld ).areavisibility ); + } + ( *aasworld ).areavisibility = NULL; + if ( ( *aasworld ).decompressedvis ) { + FreeMemory( ( *aasworld ).decompressedvis ); + } + ( *aasworld ).decompressedvis = NULL; +} +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_InitRoutingUpdate( void ) { +// int i, maxreachabilityareas; + + //free routing update fields if already existing + if ( ( *aasworld ).areaupdate ) { + AAS_RoutingFreeMemory( ( *aasworld ).areaupdate ); + } + // +// Ridah, had to change it to numareas for hidepos checking +/* + maxreachabilityareas = 0; + for (i = 0; i < (*aasworld).numclusters; i++) + { + if ((*aasworld).clusters[i].numreachabilityareas > maxreachabilityareas) + { + maxreachabilityareas = (*aasworld).clusters[i].numreachabilityareas; + } //end if + } //end for + //allocate memory for the routing update fields + (*aasworld).areaupdate = (aas_routingupdate_t *) AAS_RoutingGetMemory( + maxreachabilityareas * sizeof(aas_routingupdate_t)); +*/ + ( *aasworld ).areaupdate = (aas_routingupdate_t *) AAS_RoutingGetMemory( + ( *aasworld ).numareas * sizeof( aas_routingupdate_t ) ); + // + if ( ( *aasworld ).portalupdate ) { + AAS_RoutingFreeMemory( ( *aasworld ).portalupdate ); + } + //allocate memory for the portal update fields + ( *aasworld ).portalupdate = (aas_routingupdate_t *) AAS_RoutingGetMemory( + ( ( *aasworld ).numportals + 1 ) * sizeof( aas_routingupdate_t ) ); +} //end of the function AAS_InitRoutingUpdate +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== + +void AAS_CreateAllRoutingCache( void ) { + int i, j, k, t, tfl, numroutingareas; + aas_areasettings_t *areasettings; + aas_reachability_t *reach; + + numroutingareas = 0; + tfl = TFL_DEFAULT & ~( TFL_JUMPPAD | TFL_ROCKETJUMP | TFL_BFGJUMP | TFL_GRAPPLEHOOK | TFL_DOUBLEJUMP | TFL_RAMPJUMP | TFL_STRAFEJUMP | TFL_LAVA ); //----(SA) modified since slime is no longer deadly +// tfl = TFL_DEFAULT & ~(TFL_JUMPPAD|TFL_ROCKETJUMP|TFL_BFGJUMP|TFL_GRAPPLEHOOK|TFL_DOUBLEJUMP|TFL_RAMPJUMP|TFL_STRAFEJUMP|TFL_SLIME|TFL_LAVA); + botimport.Print( PRT_MESSAGE, "AAS_CreateAllRoutingCache\n" ); + // + for ( i = 1; i < ( *aasworld ).numareas; i++ ) + { + if ( !AAS_AreaReachability( i ) ) { + continue; + } + areasettings = &( *aasworld ).areasettings[i]; + for ( k = 0; k < areasettings->numreachableareas; k++ ) + { + reach = &( *aasworld ).reachability[areasettings->firstreachablearea + k]; + if ( ( *aasworld ).travelflagfortype[reach->traveltype] & tfl ) { + break; + } + } + if ( k >= areasettings->numreachableareas ) { + continue; + } + ( *aasworld ).areasettings[i].areaflags |= AREA_USEFORROUTING; + numroutingareas++; + } + for ( i = 1; i < ( *aasworld ).numareas; i++ ) + { + if ( !( ( *aasworld ).areasettings[i].areaflags & AREA_USEFORROUTING ) ) { + continue; + } + for ( j = 1; j < ( *aasworld ).numareas; j++ ) + { + if ( i == j ) { + continue; + } + if ( !( ( *aasworld ).areasettings[j].areaflags & AREA_USEFORROUTING ) ) { + continue; + } + t = AAS_AreaTravelTimeToGoalArea( j, ( *aasworld ).areawaypoints[j], i, tfl ); + ( *aasworld ).frameroutingupdates = 0; + //if (t) break; + //Log_Write("traveltime from %d to %d is %d", i, j, t); + } //end for + } //end for +} //end of the function AAS_CreateAllRoutingCache +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +unsigned short CRC_ProcessString( unsigned char *data, int length ); + +//the route cache header +//this header is followed by numportalcache + numareacache aas_routingcache_t +//structures that store routing cache +typedef struct routecacheheader_s +{ + int ident; + int version; + int numareas; + int numclusters; + int areacrc; + int clustercrc; + int reachcrc; + int numportalcache; + int numareacache; +} routecacheheader_t; + +#define RCID ( ( 'C' << 24 ) + ( 'R' << 16 ) + ( 'E' << 8 ) + 'M' ) +#define RCVERSION 15 + +void AAS_DecompressVis( byte *in, int numareas, byte *decompressed ); +int AAS_CompressVis( byte *vis, int numareas, byte *dest ); + +void AAS_WriteRouteCache( void ) { + int i, j, numportalcache, numareacache, size; + aas_routingcache_t *cache; + aas_cluster_t *cluster; + fileHandle_t fp; + char filename[MAX_QPATH]; + routecacheheader_t routecacheheader; + byte *buf; + + buf = (byte *) GetClearedMemory( ( *aasworld ).numareas * 2 * sizeof( byte ) ); // in case it ends up bigger than the decompressedvis, which is rare but possible + + numportalcache = 0; + for ( i = 0; i < ( *aasworld ).numareas; i++ ) + { + for ( cache = ( *aasworld ).portalcache[i]; cache; cache = cache->next ) + { + numportalcache++; + } //end for + } //end for + numareacache = 0; + for ( i = 0; i < ( *aasworld ).numclusters; i++ ) + { + cluster = &( *aasworld ).clusters[i]; + for ( j = 0; j < cluster->numareas; j++ ) + { + for ( cache = ( *aasworld ).clusterareacache[i][j]; cache; cache = cache->next ) + { + numareacache++; + } //end for + } //end for + } //end for + // open the file for writing + Com_sprintf( filename, MAX_QPATH, "maps/%s.rcd", ( *aasworld ).mapname ); + botimport.FS_FOpenFile( filename, &fp, FS_WRITE ); + if ( !fp ) { + AAS_Error( "Unable to open file: %s\n", filename ); + return; + } //end if + //create the header + routecacheheader.ident = RCID; + routecacheheader.version = RCVERSION; + routecacheheader.numareas = ( *aasworld ).numareas; + routecacheheader.numclusters = ( *aasworld ).numclusters; + routecacheheader.areacrc = CRC_ProcessString( (unsigned char *)( *aasworld ).areas, sizeof( aas_area_t ) * ( *aasworld ).numareas ); + routecacheheader.clustercrc = CRC_ProcessString( (unsigned char *)( *aasworld ).clusters, sizeof( aas_cluster_t ) * ( *aasworld ).numclusters ); + routecacheheader.reachcrc = CRC_ProcessString( (unsigned char *)( *aasworld ).reachability, sizeof( aas_reachability_t ) * ( *aasworld ).reachabilitysize ); + routecacheheader.numportalcache = numportalcache; + routecacheheader.numareacache = numareacache; + //write the header + botimport.FS_Write( &routecacheheader, sizeof( routecacheheader_t ), fp ); + //write all the cache + for ( i = 0; i < ( *aasworld ).numareas; i++ ) + { + for ( cache = ( *aasworld ).portalcache[i]; cache; cache = cache->next ) + { + botimport.FS_Write( cache, cache->size, fp ); + } //end for + } //end for + for ( i = 0; i < ( *aasworld ).numclusters; i++ ) + { + cluster = &( *aasworld ).clusters[i]; + for ( j = 0; j < cluster->numareas; j++ ) + { + for ( cache = ( *aasworld ).clusterareacache[i][j]; cache; cache = cache->next ) + { + botimport.FS_Write( cache, cache->size, fp ); + } //end for + } //end for + } //end for + // write the visareas + for ( i = 0; i < ( *aasworld ).numareas; i++ ) + { + if ( !( *aasworld ).areavisibility[i] ) { + size = 0; + botimport.FS_Write( &size, sizeof( int ), fp ); + continue; + } + AAS_DecompressVis( ( *aasworld ).areavisibility[i], ( *aasworld ).numareas, ( *aasworld ).decompressedvis ); + size = AAS_CompressVis( ( *aasworld ).decompressedvis, ( *aasworld ).numareas, buf ); + botimport.FS_Write( &size, sizeof( int ), fp ); + botimport.FS_Write( buf, size, fp ); + } + // write the waypoints + botimport.FS_Write( ( *aasworld ).areawaypoints, sizeof( vec3_t ) * ( *aasworld ).numareas, fp ); + // + botimport.FS_FCloseFile( fp ); + botimport.Print( PRT_MESSAGE, "\nroute cache written to %s\n", filename ); +} //end of the function AAS_WriteRouteCache +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +aas_routingcache_t *AAS_ReadCache( fileHandle_t fp ) { + int i, size; + aas_routingcache_t *cache; + + botimport.FS_Read( &size, sizeof( size ), fp ); + size = LittleLong( size ); + cache = (aas_routingcache_t *) AAS_RoutingGetMemory( size ); + cache->size = size; + botimport.FS_Read( (unsigned char *)cache + sizeof( size ), size - sizeof( size ), fp ); + + if ( 1 != LittleLong( 1 ) ) { + cache->time = LittleFloat( cache->time ); + cache->cluster = LittleLong( cache->cluster ); + cache->areanum = LittleLong( cache->areanum ); + cache->origin[0] = LittleFloat( cache->origin[0] ); + cache->origin[1] = LittleFloat( cache->origin[1] ); + cache->origin[2] = LittleFloat( cache->origin[2] ); + cache->starttraveltime = LittleFloat( cache->starttraveltime ); + cache->travelflags = LittleLong( cache->travelflags ); + } + +// cache->reachabilities = (unsigned char *) cache + sizeof(aas_routingcache_t) - sizeof(unsigned short) + +// (size - sizeof(aas_routingcache_t) + sizeof(unsigned short)) / 3 * 2; + cache->reachabilities = (unsigned char *) cache + sizeof( aas_routingcache_t ) + + ( ( size - sizeof( aas_routingcache_t ) ) / 3 ) * 2; + + //DAJ BUGFIX for missing byteswaps for traveltimes + size = ( size - sizeof( aas_routingcache_t ) ) / 3 + 1; + for ( i = 0; i < size; i++ ) { + cache->traveltimes[i] = LittleShort( cache->traveltimes[i] ); + } + return cache; +} //end of the function AAS_ReadCache +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_ReadRouteCache( void ) { + int i, clusterareanum, size; + fileHandle_t fp = 0; + char filename[MAX_QPATH]; + routecacheheader_t routecacheheader; + aas_routingcache_t *cache; + + Com_sprintf( filename, MAX_QPATH, "maps/%s.rcd", ( *aasworld ).mapname ); + botimport.FS_FOpenFile( filename, &fp, FS_READ ); + if ( !fp ) { + return qfalse; + } //end if + botimport.FS_Read( &routecacheheader, sizeof( routecacheheader_t ), fp ); + + // GJD: route cache data MUST be written on a PC because I've not altered the writing code. + + routecacheheader.areacrc = LittleLong( routecacheheader.areacrc ); + routecacheheader.clustercrc = LittleLong( routecacheheader.clustercrc ); + routecacheheader.ident = LittleLong( routecacheheader.ident ); + routecacheheader.numareacache = LittleLong( routecacheheader.numareacache ); + routecacheheader.numareas = LittleLong( routecacheheader.numareas ); + routecacheheader.numclusters = LittleLong( routecacheheader.numclusters ); + routecacheheader.numportalcache = LittleLong( routecacheheader.numportalcache ); + routecacheheader.reachcrc = LittleLong( routecacheheader.reachcrc ); + routecacheheader.version = LittleLong( routecacheheader.version ); + + if ( routecacheheader.ident != RCID ) { + botimport.FS_FCloseFile( fp ); + Com_Printf( "%s is not a route cache dump\n", filename ); // not an aas_error because we want to continue + return qfalse; // and remake them by returning false here + } //end if + + if ( routecacheheader.version != RCVERSION ) { + botimport.FS_FCloseFile( fp ); + Com_Printf( "route cache dump has wrong version %d, should be %d", routecacheheader.version, RCVERSION ); + return qfalse; + } //end if + if ( routecacheheader.numareas != ( *aasworld ).numareas ) { + botimport.FS_FCloseFile( fp ); + //AAS_Error("route cache dump has wrong number of areas\n"); + return qfalse; + } //end if + if ( routecacheheader.numclusters != ( *aasworld ).numclusters ) { + botimport.FS_FCloseFile( fp ); + //AAS_Error("route cache dump has wrong number of clusters\n"); + return qfalse; + } //end if +#ifdef _WIN32 // crc code is only good on intel machines + if ( routecacheheader.areacrc != + CRC_ProcessString( (unsigned char *)( *aasworld ).areas, sizeof( aas_area_t ) * ( *aasworld ).numareas ) ) { + botimport.FS_FCloseFile( fp ); + //AAS_Error("route cache dump area CRC incorrect\n"); + return qfalse; + } //end if + if ( routecacheheader.clustercrc != + CRC_ProcessString( (unsigned char *)( *aasworld ).clusters, sizeof( aas_cluster_t ) * ( *aasworld ).numclusters ) ) { + botimport.FS_FCloseFile( fp ); + //AAS_Error("route cache dump cluster CRC incorrect\n"); + return qfalse; + } //end if + if ( routecacheheader.reachcrc != + CRC_ProcessString( (unsigned char *)( *aasworld ).reachability, sizeof( aas_reachability_t ) * ( *aasworld ).reachabilitysize ) ) { + botimport.FS_FCloseFile( fp ); + //AAS_Error("route cache dump reachability CRC incorrect\n"); + return qfalse; + } //end if +#endif + //read all the portal cache + for ( i = 0; i < routecacheheader.numportalcache; i++ ) + { + cache = AAS_ReadCache( fp ); + cache->next = ( *aasworld ).portalcache[cache->areanum]; + cache->prev = NULL; + if ( ( *aasworld ).portalcache[cache->areanum] ) { + ( *aasworld ).portalcache[cache->areanum]->prev = cache; + } + ( *aasworld ).portalcache[cache->areanum] = cache; + } //end for + //read all the cluster area cache + for ( i = 0; i < routecacheheader.numareacache; i++ ) + { + cache = AAS_ReadCache( fp ); + clusterareanum = AAS_ClusterAreaNum( cache->cluster, cache->areanum ); + cache->next = ( *aasworld ).clusterareacache[cache->cluster][clusterareanum]; + cache->prev = NULL; + if ( ( *aasworld ).clusterareacache[cache->cluster][clusterareanum] ) { + ( *aasworld ).clusterareacache[cache->cluster][clusterareanum]->prev = cache; + } + ( *aasworld ).clusterareacache[cache->cluster][clusterareanum] = cache; + } //end for + // read the visareas + ( *aasworld ).areavisibility = (byte **) GetClearedMemory( ( *aasworld ).numareas * sizeof( byte * ) ); + ( *aasworld ).decompressedvis = (byte *) GetClearedMemory( ( *aasworld ).numareas * sizeof( byte ) ); + for ( i = 0; i < ( *aasworld ).numareas; i++ ) + { + botimport.FS_Read( &size, sizeof( size ), fp ); + size = LittleLong( size ); + if ( size ) { + ( *aasworld ).areavisibility[i] = (byte *) GetMemory( size ); + botimport.FS_Read( ( *aasworld ).areavisibility[i], size, fp ); + } + } + // read the area waypoints + ( *aasworld ).areawaypoints = (vec3_t *) GetClearedMemory( ( *aasworld ).numareas * sizeof( vec3_t ) ); + botimport.FS_Read( ( *aasworld ).areawaypoints, ( *aasworld ).numareas * sizeof( vec3_t ), fp ); + if ( 1 != LittleLong( 1 ) ) { + for ( i = 0; i < ( *aasworld ).numareas; i++ ) { + ( *aasworld ).areawaypoints[i][0] = LittleFloat( ( *aasworld ).areawaypoints[i][0] ); + ( *aasworld ).areawaypoints[i][1] = LittleFloat( ( *aasworld ).areawaypoints[i][1] ); + ( *aasworld ).areawaypoints[i][2] = LittleFloat( ( *aasworld ).areawaypoints[i][2] ); + } + } + // + botimport.FS_FCloseFile( fp ); + return qtrue; +} //end of the function AAS_ReadRouteCache +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_CreateVisibility( void ); +void AAS_InitRouting( void ) { + AAS_InitTravelFlagFromType(); + //initialize the routing update fields + AAS_InitRoutingUpdate(); + //create reversed reachability links used by the routing update algorithm + AAS_CreateReversedReachability(); + //initialize the cluster cache + AAS_InitClusterAreaCache(); + //initialize portal cache + AAS_InitPortalCache(); + //initialize the area travel times + AAS_CalculateAreaTravelTimes(); + //calculate the maximum travel times through portals + AAS_InitPortalMaxTravelTimes(); + // +#ifdef ROUTING_DEBUG + numareacacheupdates = 0; + numportalcacheupdates = 0; +#endif //ROUTING_DEBUG + // + routingcachesize = 0; + max_routingcachesize = 1024 * (int) LibVarValue( "max_routingcache", "4096" ); + // + // Ridah, load or create the routing cache + if ( !AAS_ReadRouteCache() ) { + ( *aasworld ).initialized = qtrue; // Hack, so routing can compute traveltimes + AAS_CreateVisibility(); + AAS_CreateAllRoutingCache(); + ( *aasworld ).initialized = qfalse; + + AAS_WriteRouteCache(); // save it so we don't have to create it again + } + // done. +} //end of the function AAS_InitRouting +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_FreeRoutingCaches( void ) { + // free all the existing cluster area cache + AAS_FreeAllClusterAreaCache(); + // free all the existing portal cache + AAS_FreeAllPortalCache(); + // free all the existing area visibility data + AAS_FreeAreaVisibility(); + // free cached travel times within areas + if ( ( *aasworld ).areatraveltimes ) { + AAS_RoutingFreeMemory( ( *aasworld ).areatraveltimes ); + } + ( *aasworld ).areatraveltimes = NULL; + // free cached maximum travel time through cluster portals + if ( ( *aasworld ).portalmaxtraveltimes ) { + AAS_RoutingFreeMemory( ( *aasworld ).portalmaxtraveltimes ); + } + ( *aasworld ).portalmaxtraveltimes = NULL; + // free reversed reachability links + if ( ( *aasworld ).reversedreachability ) { + AAS_RoutingFreeMemory( ( *aasworld ).reversedreachability ); + } + ( *aasworld ).reversedreachability = NULL; + // free routing algorithm memory + if ( ( *aasworld ).areaupdate ) { + AAS_RoutingFreeMemory( ( *aasworld ).areaupdate ); + } + ( *aasworld ).areaupdate = NULL; + if ( ( *aasworld ).portalupdate ) { + AAS_RoutingFreeMemory( ( *aasworld ).portalupdate ); + } + ( *aasworld ).portalupdate = NULL; + // free area waypoints + if ( ( *aasworld ).areawaypoints ) { + FreeMemory( ( *aasworld ).areawaypoints ); + } + ( *aasworld ).areawaypoints = NULL; +} //end of the function AAS_FreeRoutingCaches +//=========================================================================== +// this function could be replaced by a bubble sort or for even faster +// routing by a B+ tree +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +__inline void AAS_AddUpdateToList( aas_routingupdate_t **updateliststart, + aas_routingupdate_t **updatelistend, + aas_routingupdate_t *update ) { + if ( !update->inlist ) { + if ( *updatelistend ) { + ( *updatelistend )->next = update; + } else { *updateliststart = update;} + update->prev = *updatelistend; + update->next = NULL; + *updatelistend = update; + update->inlist = qtrue; + } //end if +} //end of the function AAS_AddUpdateToList +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_AreaContentsTravelFlag( int areanum ) { + int contents, tfl; + + contents = ( *aasworld ).areasettings[areanum].contents; + tfl = 0; + if ( contents & AREACONTENTS_WATER ) { + return tfl |= TFL_WATER; + } else if ( contents & AREACONTENTS_SLIME ) { + return tfl |= TFL_SLIME; + } else if ( contents & AREACONTENTS_LAVA ) { + return tfl |= TFL_LAVA; + } else { tfl |= TFL_AIR;} + if ( contents & AREACONTENTS_DONOTENTER_LARGE ) { + tfl |= TFL_DONOTENTER_LARGE; + } + if ( contents & AREACONTENTS_DONOTENTER ) { + return tfl |= TFL_DONOTENTER; + } + return tfl; +} //end of the function AAS_AreaContentsTravelFlag +//=========================================================================== +// update the given routing cache +// +// Parameter: areacache : routing cache to update +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_UpdateAreaRoutingCache( aas_routingcache_t *areacache ) { + int i, nextareanum, cluster, badtravelflags, clusterareanum, linknum; + int numreachabilityareas; + unsigned short int t, startareatraveltimes[128]; + aas_routingupdate_t *updateliststart, *updatelistend, *curupdate, *nextupdate; + aas_reachability_t *reach; + aas_reversedreachability_t *revreach; + aas_reversedlink_t *revlink; + +#ifdef ROUTING_DEBUG + numareacacheupdates++; +#endif //ROUTING_DEBUG + //number of reachability areas within this cluster + numreachabilityareas = ( *aasworld ).clusters[areacache->cluster].numreachabilityareas; + // + //clear the routing update fields +// memset((*aasworld).areaupdate, 0, (*aasworld).numareas * sizeof(aas_routingupdate_t)); + // + badtravelflags = ~areacache->travelflags; + // + clusterareanum = AAS_ClusterAreaNum( areacache->cluster, areacache->areanum ); + if ( clusterareanum >= numreachabilityareas ) { + return; + } + // + memset( startareatraveltimes, 0, sizeof( startareatraveltimes ) ); + // + curupdate = &( *aasworld ).areaupdate[clusterareanum]; + curupdate->areanum = areacache->areanum; + //VectorCopy(areacache->origin, curupdate->start); + curupdate->areatraveltimes = ( *aasworld ).areatraveltimes[areacache->areanum][0]; + curupdate->tmptraveltime = areacache->starttraveltime; + // + areacache->traveltimes[clusterareanum] = areacache->starttraveltime; + //put the area to start with in the current read list + curupdate->next = NULL; + curupdate->prev = NULL; + updateliststart = curupdate; + updatelistend = curupdate; + //while there are updates in the current list, flip the lists + while ( updateliststart ) + { + curupdate = updateliststart; + // + if ( curupdate->next ) { + curupdate->next->prev = NULL; + } else { updatelistend = NULL;} + updateliststart = curupdate->next; + // + curupdate->inlist = qfalse; + //check all reversed reachability links + revreach = &( *aasworld ).reversedreachability[curupdate->areanum]; + // + for ( i = 0, revlink = revreach->first; revlink; revlink = revlink->next, i++ ) + { + linknum = revlink->linknum; + reach = &( *aasworld ).reachability[linknum]; + //if there is used an undesired travel type + if ( ( *aasworld ).travelflagfortype[reach->traveltype] & badtravelflags ) { + continue; + } + //if not allowed to enter the next area + if ( ( *aasworld ).areasettings[reach->areanum].areaflags & AREA_DISABLED ) { + continue; + } + //if the next area has a not allowed travel flag + if ( AAS_AreaContentsTravelFlag( reach->areanum ) & badtravelflags ) { + continue; + } + //number of the area the reversed reachability leads to + nextareanum = revlink->areanum; + //get the cluster number of the area + cluster = ( *aasworld ).areasettings[nextareanum].cluster; + //don't leave the cluster + if ( cluster > 0 && cluster != areacache->cluster ) { + continue; + } + //get the number of the area in the cluster + clusterareanum = AAS_ClusterAreaNum( areacache->cluster, nextareanum ); + if ( clusterareanum >= numreachabilityareas ) { + continue; + } + //time already travelled plus the traveltime through + //the current area plus the travel time from the reachability + t = curupdate->tmptraveltime + + //AAS_AreaTravelTime(curupdate->areanum, curupdate->start, reach->end) + + curupdate->areatraveltimes[i] + + reach->traveltime; + // + ( *aasworld ).frameroutingupdates++; + // + if ( !areacache->traveltimes[clusterareanum] || + areacache->traveltimes[clusterareanum] > t ) { + areacache->traveltimes[clusterareanum] = t; + areacache->reachabilities[clusterareanum] = linknum - ( *aasworld ).areasettings[nextareanum].firstreachablearea; + nextupdate = &( *aasworld ).areaupdate[clusterareanum]; + nextupdate->areanum = nextareanum; + nextupdate->tmptraveltime = t; + //VectorCopy(reach->start, nextupdate->start); + nextupdate->areatraveltimes = ( *aasworld ).areatraveltimes[nextareanum][linknum - + ( *aasworld ).areasettings[nextareanum].firstreachablearea]; + if ( !nextupdate->inlist ) { + nextupdate->next = NULL; + nextupdate->prev = updatelistend; + if ( updatelistend ) { + updatelistend->next = nextupdate; + } else { updateliststart = nextupdate;} + updatelistend = nextupdate; + nextupdate->inlist = qtrue; + } //end if + } //end if + } //end for + } //end while +} //end of the function AAS_UpdateAreaRoutingCache +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +aas_routingcache_t *AAS_GetAreaRoutingCache( int clusternum, int areanum, int travelflags, qboolean forceUpdate ) { + int clusterareanum; + aas_routingcache_t *cache, *clustercache; + + //number of the area in the cluster + clusterareanum = AAS_ClusterAreaNum( clusternum, areanum ); + //pointer to the cache for the area in the cluster + clustercache = ( *aasworld ).clusterareacache[clusternum][clusterareanum]; + //find the cache without undesired travel flags + for ( cache = clustercache; cache; cache = cache->next ) + { + //if there aren't used any undesired travel types for the cache + if ( cache->travelflags == travelflags ) { + break; + } + } //end for + //if there was no cache + if ( !cache ) { + //NOTE: the number of routing updates is limited per frame + if ( !forceUpdate && ( ( *aasworld ).frameroutingupdates > MAX_FRAMEROUTINGUPDATES ) ) { + return NULL; + } //end if + + cache = AAS_AllocRoutingCache( ( *aasworld ).clusters[clusternum].numreachabilityareas ); + cache->cluster = clusternum; + cache->areanum = areanum; + VectorCopy( ( *aasworld ).areas[areanum].center, cache->origin ); + cache->starttraveltime = 1; + cache->travelflags = travelflags; + cache->prev = NULL; + cache->next = clustercache; + if ( clustercache ) { + clustercache->prev = cache; + } + ( *aasworld ).clusterareacache[clusternum][clusterareanum] = cache; + AAS_UpdateAreaRoutingCache( cache ); + } //end if + //the cache has been accessed + cache->time = AAS_RoutingTime(); + return cache; +} //end of the function AAS_GetAreaRoutingCache +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_UpdatePortalRoutingCache( aas_routingcache_t *portalcache ) { + int i, portalnum, clusterareanum, clusternum; + unsigned short int t; + aas_portal_t *portal; + aas_cluster_t *cluster; + aas_routingcache_t *cache; + aas_routingupdate_t *updateliststart, *updatelistend, *curupdate, *nextupdate; + +#ifdef ROUTING_DEBUG + numportalcacheupdates++; +#endif //ROUTING_DEBUG + //clear the routing update fields +// memset((*aasworld).portalupdate, 0, ((*aasworld).numportals+1) * sizeof(aas_routingupdate_t)); + // + curupdate = &( *aasworld ).portalupdate[( *aasworld ).numportals]; + curupdate->cluster = portalcache->cluster; + curupdate->areanum = portalcache->areanum; + curupdate->tmptraveltime = portalcache->starttraveltime; + //if the start area is a cluster portal, store the travel time for that portal + clusternum = ( *aasworld ).areasettings[portalcache->areanum].cluster; + if ( clusternum < 0 ) { + portalcache->traveltimes[-clusternum] = portalcache->starttraveltime; + } //end if + //put the area to start with in the current read list + curupdate->next = NULL; + curupdate->prev = NULL; + updateliststart = curupdate; + updatelistend = curupdate; + //while there are updates in the current list, flip the lists + while ( updateliststart ) + { + curupdate = updateliststart; + //remove the current update from the list + if ( curupdate->next ) { + curupdate->next->prev = NULL; + } else { updatelistend = NULL;} + updateliststart = curupdate->next; + //current update is removed from the list + curupdate->inlist = qfalse; + // + cluster = &( *aasworld ).clusters[curupdate->cluster]; + // + cache = AAS_GetAreaRoutingCache( curupdate->cluster, + curupdate->areanum, portalcache->travelflags, qtrue ); + //take all portals of the cluster + for ( i = 0; i < cluster->numportals; i++ ) + { + portalnum = ( *aasworld ).portalindex[cluster->firstportal + i]; + portal = &( *aasworld ).portals[portalnum]; + //if this is the portal of the current update continue + if ( portal->areanum == curupdate->areanum ) { + continue; + } + // + clusterareanum = AAS_ClusterAreaNum( curupdate->cluster, portal->areanum ); + if ( clusterareanum >= cluster->numreachabilityareas ) { + continue; + } + // + t = cache->traveltimes[clusterareanum]; + if ( !t ) { + continue; + } + t += curupdate->tmptraveltime; + // + if ( !portalcache->traveltimes[portalnum] || + portalcache->traveltimes[portalnum] > t ) { + portalcache->traveltimes[portalnum] = t; + portalcache->reachabilities[portalnum] = cache->reachabilities[clusterareanum]; + nextupdate = &( *aasworld ).portalupdate[portalnum]; + if ( portal->frontcluster == curupdate->cluster ) { + nextupdate->cluster = portal->backcluster; + } //end if + else + { + nextupdate->cluster = portal->frontcluster; + } //end else + nextupdate->areanum = portal->areanum; + //add travel time through actual portal area for the next update + nextupdate->tmptraveltime = t + ( *aasworld ).portalmaxtraveltimes[portalnum]; + if ( !nextupdate->inlist ) { + nextupdate->next = NULL; + nextupdate->prev = updatelistend; + if ( updatelistend ) { + updatelistend->next = nextupdate; + } else { updateliststart = nextupdate;} + updatelistend = nextupdate; + nextupdate->inlist = qtrue; + } //end if + } //end if + } //end for + } //end while +} //end of the function AAS_UpdatePortalRoutingCache +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +aas_routingcache_t *AAS_GetPortalRoutingCache( int clusternum, int areanum, int travelflags ) { + aas_routingcache_t *cache; + + //find the cached portal routing if existing + for ( cache = ( *aasworld ).portalcache[areanum]; cache; cache = cache->next ) + { + if ( cache->travelflags == travelflags ) { + break; + } + } //end for + //if the portal routing isn't cached + if ( !cache ) { + cache = AAS_AllocRoutingCache( ( *aasworld ).numportals ); + cache->cluster = clusternum; + cache->areanum = areanum; + VectorCopy( ( *aasworld ).areas[areanum].center, cache->origin ); + cache->starttraveltime = 1; + cache->travelflags = travelflags; + //add the cache to the cache list + cache->prev = NULL; + cache->next = ( *aasworld ).portalcache[areanum]; + if ( ( *aasworld ).portalcache[areanum] ) { + ( *aasworld ).portalcache[areanum]->prev = cache; + } + ( *aasworld ).portalcache[areanum] = cache; + //update the cache + AAS_UpdatePortalRoutingCache( cache ); + } //end if + //the cache has been accessed + cache->time = AAS_RoutingTime(); + return cache; +} //end of the function AAS_GetPortalRoutingCache +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_AreaRouteToGoalArea( int areanum, vec3_t origin, int goalareanum, int travelflags, int *traveltime, int *reachnum ) { + int clusternum, goalclusternum, portalnum, i, clusterareanum, bestreachnum; + unsigned short int t, besttime; + aas_portal_t *portal; + aas_cluster_t *cluster; + aas_routingcache_t *areacache, *portalcache; + aas_reachability_t *reach; + aas_portalindex_t *pPortalnum; + + if ( !( *aasworld ).initialized ) { + return qfalse; + } + + if ( areanum == goalareanum ) { + *traveltime = 1; + *reachnum = 0; + return qtrue; + } //end if + // + if ( areanum <= 0 || areanum >= ( *aasworld ).numareas ) { + if ( bot_developer ) { + botimport.Print( PRT_ERROR, "AAS_AreaTravelTimeToGoalArea: areanum %d out of range\n", areanum ); + } //end if + return qfalse; + } //end if + if ( goalareanum <= 0 || goalareanum >= ( *aasworld ).numareas ) { + if ( bot_developer ) { + botimport.Print( PRT_ERROR, "AAS_AreaTravelTimeToGoalArea: goalareanum %d out of range\n", goalareanum ); + } //end if + return qfalse; + } //end if + + //make sure the routing cache doesn't grow to large + while ( routingcachesize > max_routingcachesize ) { + if ( !AAS_FreeOldestCache() ) { + break; + } + } + // + if ( AAS_AreaDoNotEnter( areanum ) || AAS_AreaDoNotEnter( goalareanum ) ) { + travelflags |= TFL_DONOTENTER; + } //end if + if ( AAS_AreaDoNotEnterLarge( areanum ) || AAS_AreaDoNotEnterLarge( goalareanum ) ) { + travelflags |= TFL_DONOTENTER_LARGE; + } //end if + //NOTE: the number of routing updates is limited per frame + /* + if ((*aasworld).frameroutingupdates > MAX_FRAMEROUTINGUPDATES) + { + #ifdef DEBUG + //Log_Write("WARNING: AAS_AreaTravelTimeToGoalArea: frame routing updates overflowed"); + #endif + return 0; + } //end if + */ + // + clusternum = ( *aasworld ).areasettings[areanum].cluster; + goalclusternum = ( *aasworld ).areasettings[goalareanum].cluster; + //check if the area is a portal of the goal area cluster + if ( clusternum < 0 && goalclusternum > 0 ) { + portal = &( *aasworld ).portals[-clusternum]; + if ( portal->frontcluster == goalclusternum || + portal->backcluster == goalclusternum ) { + clusternum = goalclusternum; + } //end if + } //end if + //check if the goalarea is a portal of the area cluster + else if ( clusternum > 0 && goalclusternum < 0 ) { + portal = &( *aasworld ).portals[-goalclusternum]; + if ( portal->frontcluster == clusternum || + portal->backcluster == clusternum ) { + goalclusternum = clusternum; + } //end if + } //end if + //if both areas are in the same cluster + //NOTE: there might be a shorter route via another cluster!!! but we don't care + if ( clusternum > 0 && goalclusternum > 0 && clusternum == goalclusternum ) { + // + areacache = AAS_GetAreaRoutingCache( clusternum, goalareanum, travelflags, qfalse ); + // RF, note that the routing cache might be NULL now since we are restricting + // the updates per frame, hopefully rejected cache's will be requested again + // when things have settled down + if ( !areacache ) { + return qfalse; + } + //the number of the area in the cluster + clusterareanum = AAS_ClusterAreaNum( clusternum, areanum ); + //the cluster the area is in + cluster = &( *aasworld ).clusters[clusternum]; + //if the area is NOT a reachability area + if ( clusterareanum >= cluster->numreachabilityareas ) { + return qfalse; + } + //if it is possible to travel to the goal area through this cluster + if ( areacache->traveltimes[clusterareanum] != 0 ) { + *reachnum = ( *aasworld ).areasettings[areanum].firstreachablearea + + areacache->reachabilities[clusterareanum]; + // + if ( !origin ) { + *traveltime = areacache->traveltimes[clusterareanum]; + return qtrue; + } + // + reach = &( *aasworld ).reachability[*reachnum]; + *traveltime = areacache->traveltimes[clusterareanum] + + AAS_AreaTravelTime( areanum, origin, reach->start ); + return qtrue; + } //end if + } //end if + // + clusternum = ( *aasworld ).areasettings[areanum].cluster; + goalclusternum = ( *aasworld ).areasettings[goalareanum].cluster; + //if the goal area is a portal + if ( goalclusternum < 0 ) { + //just assume the goal area is part of the front cluster + portal = &( *aasworld ).portals[-goalclusternum]; + goalclusternum = portal->frontcluster; + } //end if + //get the portal routing cache + portalcache = AAS_GetPortalRoutingCache( goalclusternum, goalareanum, travelflags ); + //if the area is a cluster portal, read directly from the portal cache + if ( clusternum < 0 ) { + *traveltime = portalcache->traveltimes[-clusternum]; + *reachnum = ( *aasworld ).areasettings[areanum].firstreachablearea + + portalcache->reachabilities[-clusternum]; + return qtrue; + } + // + besttime = 0; + bestreachnum = -1; + //the cluster the area is in + cluster = &( *aasworld ).clusters[clusternum]; + //current area inside the current cluster + clusterareanum = AAS_ClusterAreaNum( clusternum, areanum ); + //if the area is NOT a reachability area + if ( clusterareanum >= cluster->numreachabilityareas ) { + return qfalse; + } + // + pPortalnum = ( *aasworld ).portalindex + cluster->firstportal; + //find the portal of the area cluster leading towards the goal area + for ( i = 0; i < cluster->numportals; i++, pPortalnum++ ) + { + portalnum = *pPortalnum; + //if the goal area isn't reachable from the portal + if ( !portalcache->traveltimes[portalnum] ) { + continue; + } + // + portal = ( *aasworld ).portals + portalnum; + // if the area in disabled + if ( ( *aasworld ).areasettings[portal->areanum].areaflags & AREA_DISABLED ) { + continue; + } + //get the cache of the portal area + areacache = AAS_GetAreaRoutingCache( clusternum, portal->areanum, travelflags, qfalse ); + // RF, this may be NULL if we were unable to calculate the cache this frame + if ( !areacache ) { + return qfalse; + } + //if the portal is NOT reachable from this area + if ( !areacache->traveltimes[clusterareanum] ) { + continue; + } + //total travel time is the travel time the portal area is from + //the goal area plus the travel time towards the portal area + t = portalcache->traveltimes[portalnum] + areacache->traveltimes[clusterareanum]; + //FIXME: add the exact travel time through the actual portal area + //NOTE: for now we just add the largest travel time through the area portal + // because we can't directly calculate the exact travel time + // to be more specific we don't know which reachability is used to travel + // into the portal area when coming from the current area + t += ( *aasworld ).portalmaxtraveltimes[portalnum]; + // + // Ridah, needs to be up here + *reachnum = ( *aasworld ).areasettings[areanum].firstreachablearea + + areacache->reachabilities[clusterareanum]; + +//botimport.Print(PRT_MESSAGE, "portal reachability: %i\n", (int)areacache->reachabilities[clusterareanum] ); + + if ( origin ) { + reach = ( *aasworld ).reachability + *reachnum; + t += AAS_AreaTravelTime( areanum, origin, reach->start ); + } //end if + //if the time is better than the one already found + if ( !besttime || t < besttime ) { + bestreachnum = *reachnum; + besttime = t; + } //end if + } //end for + // Ridah, check a route was found + if ( bestreachnum < 0 ) { + return qfalse; + } + *reachnum = bestreachnum; + *traveltime = besttime; + return qtrue; +} //end of the function AAS_AreaRouteToGoalArea +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_AreaTravelTimeToGoalArea( int areanum, vec3_t origin, int goalareanum, int travelflags ) { + int traveltime, reachnum; + + if ( AAS_AreaRouteToGoalArea( areanum, origin, goalareanum, travelflags, &traveltime, &reachnum ) ) { + return traveltime; + } + return 0; +} //end of the function AAS_AreaTravelTimeToGoalArea +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_AreaTravelTimeToGoalAreaCheckLoop( int areanum, vec3_t origin, int goalareanum, int travelflags, int loopareanum ) { + int traveltime, reachnum; + aas_reachability_t *reach; + + if ( AAS_AreaRouteToGoalArea( areanum, origin, goalareanum, travelflags, &traveltime, &reachnum ) ) { + reach = &( *aasworld ).reachability[reachnum]; + if ( loopareanum && reach->areanum == loopareanum ) { + return 0; // going here will cause a looped route + } + return traveltime; + } + return 0; +} //end of the function AAS_AreaTravelTimeToGoalArea +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_AreaReachabilityToGoalArea( int areanum, vec3_t origin, int goalareanum, int travelflags ) { + int traveltime, reachnum; + + if ( AAS_AreaRouteToGoalArea( areanum, origin, goalareanum, travelflags, &traveltime, &reachnum ) ) { + return reachnum; + } + return 0; +} //end of the function AAS_AreaReachabilityToGoalArea +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_ReachabilityFromNum( int num, struct aas_reachability_s *reach ) { + if ( !( *aasworld ).initialized ) { + memset( reach, 0, sizeof( aas_reachability_t ) ); + return; + } //end if + if ( num < 0 || num >= ( *aasworld ).reachabilitysize ) { + memset( reach, 0, sizeof( aas_reachability_t ) ); + return; + } //end if + memcpy( reach, &( *aasworld ).reachability[num], sizeof( aas_reachability_t ) );; +} //end of the function AAS_ReachabilityFromNum +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_NextAreaReachability( int areanum, int reachnum ) { + aas_areasettings_t *settings; + + if ( !( *aasworld ).initialized ) { + return 0; + } + + if ( areanum <= 0 || areanum >= ( *aasworld ).numareas ) { + botimport.Print( PRT_ERROR, "AAS_NextAreaReachability: areanum %d out of range\n", areanum ); + return 0; + } //end if + + settings = &( *aasworld ).areasettings[areanum]; + if ( !reachnum ) { + return settings->firstreachablearea; + } //end if + if ( reachnum < settings->firstreachablearea ) { + botimport.Print( PRT_FATAL, "AAS_NextAreaReachability: reachnum < settings->firstreachableara" ); + return 0; + } //end if + reachnum++; + if ( reachnum >= settings->firstreachablearea + settings->numreachableareas ) { + return 0; + } //end if + return reachnum; +} //end of the function AAS_NextAreaReachability +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_NextModelReachability( int num, int modelnum ) { + int i; + + if ( num <= 0 ) { + num = 1; + } else if ( num >= ( *aasworld ).reachabilitysize ) { + return 0; + } else { num++;} + // + for ( i = num; i < ( *aasworld ).reachabilitysize; i++ ) + { + if ( ( *aasworld ).reachability[i].traveltype == TRAVEL_ELEVATOR ) { + if ( ( *aasworld ).reachability[i].facenum == modelnum ) { + return i; + } + } //end if + else if ( ( *aasworld ).reachability[i].traveltype == TRAVEL_FUNCBOB ) { + if ( ( ( *aasworld ).reachability[i].facenum & 0x0000FFFF ) == modelnum ) { + return i; + } + } //end if + } //end for + return 0; +} //end of the function AAS_NextModelReachability +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_RandomGoalArea( int areanum, int travelflags, int *goalareanum, vec3_t goalorigin ) { + int i, n, t; + vec3_t start, end; + aas_trace_t trace; + + //if the area has no reachabilities + if ( !AAS_AreaReachability( areanum ) ) { + return qfalse; + } + // + n = ( *aasworld ).numareas * random(); + for ( i = 0; i < ( *aasworld ).numareas; i++ ) + { + if ( n <= 0 ) { + n = 1; + } + if ( n >= ( *aasworld ).numareas ) { + n = 1; + } + if ( AAS_AreaReachability( n ) ) { + t = AAS_AreaTravelTimeToGoalArea( areanum, ( *aasworld ).areas[areanum].center, n, travelflags ); + //if the goal is reachable + if ( t > 0 ) { + if ( AAS_AreaSwim( n ) ) { + *goalareanum = n; + VectorCopy( ( *aasworld ).areas[n].center, goalorigin ); + //botimport.Print(PRT_MESSAGE, "found random goal area %d\n", *goalareanum); + return qtrue; + } //end if + VectorCopy( ( *aasworld ).areas[n].center, start ); + if ( !AAS_PointAreaNum( start ) ) { + Log_Write( "area %d center %f %f %f in solid?", n, + start[0], start[1], start[2] ); + } + VectorCopy( start, end ); + end[2] -= 300; + trace = AAS_TraceClientBBox( start, end, PRESENCE_CROUCH, -1 ); + if ( !trace.startsolid && AAS_PointAreaNum( trace.endpos ) == n ) { + if ( AAS_AreaGroundFaceArea( n ) > 300 ) { + *goalareanum = n; + VectorCopy( trace.endpos, goalorigin ); + //botimport.Print(PRT_MESSAGE, "found random goal area %d\n", *goalareanum); + return qtrue; + } //end if + } //end if + } //end if + } //end if + n++; + } //end for + return qfalse; +} //end of the function AAS_RandomGoalArea +//=========================================================================== +// run-length compression on zeros +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_CompressVis( byte *vis, int numareas, byte *dest ) { + int j; + int rep; + //int visrow; + byte *dest_p; + byte check; + + // + dest_p = dest; + //visrow = (numareas + 7)>>3; + + for ( j = 0 ; j < numareas /*visrow*/ ; j++ ) + { + *dest_p++ = vis[j]; + check = vis[j]; + //if (vis[j]) + // continue; + + rep = 1; + for ( j++; j < numareas /*visrow*/ ; j++ ) + if ( vis[j] != check || rep == 255 ) { + break; + } else { + rep++; + } + *dest_p++ = rep; + j--; + } + return dest_p - dest; +} //end of the function AAS_CompressVis +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_DecompressVis( byte *in, int numareas, byte *decompressed ) { + byte c; + byte *out; + //int row; + byte *end; + + // initialize the vis data, only set those that are visible + memset( decompressed, 0, numareas ); + + //row = (numareas+7)>>3; + out = decompressed; + end = ( byte * )( (int)decompressed + numareas ); + + do + { + /* + if (*in) + { + *out++ = *in++; + continue; + } + */ + + c = in[1]; + if ( !c ) { + AAS_Error( "DecompressVis: 0 repeat" ); + } + if ( *in ) { // we need to set these bits + memset( out, 1, c ); + } + in += 2; + /* + while (c) + { + *out++ = 0; + c--; + } + */ + out += c; + } while ( out < end ); +} //end of the function AAS_DecompressVis +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_AreaVisible( int srcarea, int destarea ) { + if ( srcarea != ( *aasworld ).decompressedvisarea ) { + if ( !( *aasworld ).areavisibility[srcarea] ) { + return qfalse; + } + AAS_DecompressVis( ( *aasworld ).areavisibility[srcarea], + ( *aasworld ).numareas, ( *aasworld ).decompressedvis ); + ( *aasworld ).decompressedvisarea = srcarea; + } + return ( *aasworld ).decompressedvis[destarea]; +} //end of the function AAS_AreaVisible +//=========================================================================== +// just center to center visibility checking... +// FIXME: implement a correct full vis +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_CreateVisibility( void ) { + int i, j, size, totalsize; + vec3_t endpos, mins, maxs; + bsp_trace_t trace; + byte *buf; + byte *validareas; + int numvalid = 0; + byte *areaTable = NULL; + int numAreas, numAreaBits; + + numAreas = ( *aasworld ).numareas; + numAreaBits = ( ( numAreas + 8 ) >> 3 ); + areaTable = (byte *) GetClearedMemory( numAreas * numAreaBits * sizeof( byte ) ); + + buf = (byte *) GetClearedMemory( numAreas * 2 * sizeof( byte ) ); // in case it ends up bigger than the decompressedvis, which is rare but possible + validareas = (byte *) GetClearedMemory( numAreas * sizeof( byte ) ); + + ( *aasworld ).areavisibility = (byte **) GetClearedMemory( numAreas * sizeof( byte * ) ); + ( *aasworld ).decompressedvis = (byte *) GetClearedMemory( numAreas * sizeof( byte ) ); + ( *aasworld ).areawaypoints = (vec3_t *) GetClearedMemory( numAreas * sizeof( vec3_t ) ); + totalsize = numAreas * sizeof( byte * ); + for ( i = 1; i < numAreas; i++ ) + { + if ( !AAS_AreaReachability( i ) ) { + continue; + } + + // find the waypoint + VectorCopy( ( *aasworld ).areas[i].center, endpos ); + endpos[2] -= 256; + AAS_PresenceTypeBoundingBox( PRESENCE_NORMAL, mins, maxs ); +// maxs[2] = 0; + trace = AAS_Trace( ( *aasworld ).areas[i].center, mins, maxs, endpos, -1, CONTENTS_SOLID | CONTENTS_PLAYERCLIP | CONTENTS_MONSTERCLIP ); + if ( !trace.startsolid && trace.fraction < 1 && AAS_PointAreaNum( trace.endpos ) == i ) { + VectorCopy( trace.endpos, ( *aasworld ).areawaypoints[i] ); + validareas[i] = 1; + numvalid++; + } else { + continue; + } + } + + for ( i = 1; i < numAreas; i++ ) + { + if ( !validareas[i] ) { + continue; + } + + for ( j = 1; j < numAreas; j++ ) + { + ( *aasworld ).decompressedvis[j] = 0; + if ( i == j ) { + ( *aasworld ).decompressedvis[j] = 1; + if ( areaTable ) { + areaTable[ ( i * numAreaBits ) + ( j >> 3 ) ] |= ( 1 << ( j & 7 ) ); + } + continue; + } + if ( !validareas[j] ) { + continue; + } //end if + // if we have already checked this combination, copy the result + if ( areaTable && ( i > j ) ) { + // use the reverse result stored in the table + if ( areaTable[ ( j * numAreaBits ) + ( i >> 3 ) ] & ( 1 << ( i & 7 ) ) ) { + ( *aasworld ).decompressedvis[j] = 1; + } + // done, move to the next area + continue; + } + + // RF, check PVS first, since it's much faster + if ( !AAS_inPVS( ( *aasworld ).areawaypoints[i], ( *aasworld ).areawaypoints[j] ) ) { + continue; + } + trace = AAS_Trace( ( *aasworld ).areawaypoints[i], NULL, NULL, ( *aasworld ).areawaypoints[j], -1, CONTENTS_SOLID ); + if ( trace.fraction >= 1 ) { + ( *aasworld ).decompressedvis[j] = 1; + } //end if + } //end for + size = AAS_CompressVis( ( *aasworld ).decompressedvis, numAreas, buf ); + ( *aasworld ).areavisibility[i] = (byte *) GetMemory( size ); + memcpy( ( *aasworld ).areavisibility[i], buf, size ); + totalsize += size; + } //end for + if ( areaTable ) { + FreeMemory( areaTable ); + } + botimport.Print( PRT_MESSAGE, "AAS_CreateVisibility: compressed vis size = %i\n", totalsize ); +} //end of the function AAS_CreateVisibility +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +float VectorDistance( vec3_t v1, vec3_t v2 ); +extern void ProjectPointOntoVector( vec3_t point, vec3_t vStart, vec3_t vEnd, vec3_t vProj ) ; +int AAS_NearestHideArea( int srcnum, vec3_t origin, int areanum, int enemynum, vec3_t enemyorigin, int enemyareanum, int travelflags ) { + int i, j, nextareanum, badtravelflags, numreach, bestarea; + unsigned short int t, besttraveltime, enemytraveltime; + aas_routingupdate_t *updateliststart, *updatelistend, *curupdate, *nextupdate; + aas_reachability_t *reach; + float dist1, dist2; + float enemytraveldist; + vec3_t enemyVec; + qboolean startVisible; + vec3_t v1, v2, p; + #define MAX_HIDEAREA_LOOPS 3000 + static float lastTime; + static int loopCount; + // + if ( srcnum < 0 ) { // hack to force run this call + srcnum = -srcnum - 1; + lastTime = 0; + } + // don't run this more than once per frame + if ( lastTime == AAS_Time() && loopCount >= MAX_HIDEAREA_LOOPS ) { + return 0; + } + lastTime = AAS_Time(); + loopCount = 0; + // + if ( !( *aasworld ).hidetraveltimes ) { + ( *aasworld ).hidetraveltimes = (unsigned short int *) GetClearedMemory( ( *aasworld ).numareas * sizeof( unsigned short int ) ); + } else { + memset( ( *aasworld ).hidetraveltimes, 0, ( *aasworld ).numareas * sizeof( unsigned short int ) ); + } //end else + // + if ( !( *aasworld ).visCache ) { + ( *aasworld ).visCache = (byte *) GetClearedMemory( ( *aasworld ).numareas * sizeof( byte ) ); + } else { + memset( ( *aasworld ).visCache, 0, ( *aasworld ).numareas * sizeof( byte ) ); + } //end else + besttraveltime = 0; + bestarea = 0; + if ( enemyareanum ) { + enemytraveltime = AAS_AreaTravelTimeToGoalArea( areanum, origin, enemyareanum, travelflags ); + } + VectorSubtract( enemyorigin, origin, enemyVec ); + enemytraveldist = VectorNormalize( enemyVec ); + startVisible = botimport.AICast_VisibleFromPos( enemyorigin, enemynum, origin, srcnum, qfalse ); + // + badtravelflags = ~travelflags; + // + curupdate = &( *aasworld ).areaupdate[areanum]; + curupdate->areanum = areanum; + VectorCopy( origin, curupdate->start ); + curupdate->areatraveltimes = ( *aasworld ).areatraveltimes[areanum][0]; + curupdate->tmptraveltime = 0; + //put the area to start with in the current read list + curupdate->next = NULL; + curupdate->prev = NULL; + updateliststart = curupdate; + updatelistend = curupdate; + //while there are updates in the current list, flip the lists + while ( updateliststart ) + { + curupdate = updateliststart; + // + if ( curupdate->next ) { + curupdate->next->prev = NULL; + } else { updatelistend = NULL;} + updateliststart = curupdate->next; + // + curupdate->inlist = qfalse; + //check all reversed reachability links + numreach = ( *aasworld ).areasettings[curupdate->areanum].numreachableareas; + reach = &( *aasworld ).reachability[( *aasworld ).areasettings[curupdate->areanum].firstreachablearea]; + // + for ( i = 0; i < numreach; i++, reach++ ) + { + //if an undesired travel type is used + if ( ( *aasworld ).travelflagfortype[reach->traveltype] & badtravelflags ) { + continue; + } + // + if ( AAS_AreaContentsTravelFlag( reach->areanum ) & badtravelflags ) { + continue; + } + // dont pass through ladder areas + if ( ( *aasworld ).areasettings[reach->areanum].areaflags & AREA_LADDER ) { + continue; + } + // + if ( ( *aasworld ).areasettings[reach->areanum].areaflags & AREA_DISABLED ) { + continue; + } + //number of the area the reachability leads to + nextareanum = reach->areanum; + // if this moves us into the enemies area, skip it + if ( nextareanum == enemyareanum ) { + continue; + } + //time already travelled plus the traveltime through + //the current area plus the travel time from the reachability + t = curupdate->tmptraveltime + + AAS_AreaTravelTime( curupdate->areanum, curupdate->start, reach->start ) + + reach->traveltime; + // inc the loopCount, we are starting to use a bit of cpu time + loopCount++; + // if this isn't the fastest route to this area, ignore + if ( ( *aasworld ).hidetraveltimes[nextareanum] && ( *aasworld ).hidetraveltimes[nextareanum] < t ) { + continue; + } + ( *aasworld ).hidetraveltimes[nextareanum] = t; + // if the bestarea is this area, then it must be a longer route, so ignore it + if ( bestarea == nextareanum ) { + bestarea = 0; + besttraveltime = 0; + } + // do this test now, so we can reject the route if it starts out too long + if ( besttraveltime && t >= besttraveltime ) { + continue; + } + // + //avoid going near the enemy + ProjectPointOntoVector( enemyorigin, curupdate->start, reach->end, p ); + for ( j = 0; j < 3; j++ ) { + if ( ( p[j] > curupdate->start[j] + 0.1 && p[j] > reach->end[j] + 0.1 ) || + ( p[j] < curupdate->start[j] - 0.1 && p[j] < reach->end[j] - 0.1 ) ) { + break; + } + } + if ( j < 3 ) { + VectorSubtract( enemyorigin, reach->end, v2 ); + } //end if + else + { + VectorSubtract( enemyorigin, p, v2 ); + } //end else + dist2 = VectorLength( v2 ); + //never go through the enemy + if ( enemytraveldist > 32 && dist2 < enemytraveldist && dist2 < 256 ) { + continue; + } + // + VectorSubtract( reach->end, origin, v2 ); + if ( enemytraveldist > 32 && DotProduct( v2, enemyVec ) > enemytraveldist / 2 ) { + continue; + } + // + VectorSubtract( enemyorigin, curupdate->start, v1 ); + dist1 = VectorLength( v1 ); + // + if ( enemytraveldist > 32 && dist2 < dist1 ) { + t += ( dist1 - dist2 ) * 10; + // test it again after modifying it + if ( besttraveltime && t >= besttraveltime ) { + continue; + } + } + // make sure the hide area doesn't have anyone else in it + if ( AAS_IsEntityInArea( srcnum, -1, nextareanum ) ) { + t += 1000; // avoid this path/area + //continue; + } + // + // if we weren't visible when starting, make sure we don't move into their view + if ( enemyareanum && !startVisible && AAS_AreaVisible( enemyareanum, nextareanum ) ) { + continue; + //t += 1000; + } + // + if ( !besttraveltime || besttraveltime > t ) { + // + // if this area doesn't have a vis list, ignore it + if ( ( *aasworld ).areavisibility[nextareanum] ) { + //if the nextarea is not visible from the enemy area + if ( !AAS_AreaVisible( enemyareanum, nextareanum ) ) { // now last of all, check that this area is a safe hiding spot + if ( ( ( *aasworld ).visCache[nextareanum] == 2 ) || + ( !( *aasworld ).visCache[nextareanum] && !botimport.AICast_VisibleFromPos( enemyorigin, enemynum, ( *aasworld ).areawaypoints[nextareanum], srcnum, qfalse ) ) ) { + ( *aasworld ).visCache[nextareanum] = 2; + besttraveltime = t; + bestarea = nextareanum; + } else { + ( *aasworld ).visCache[nextareanum] = 1; + } + } //end if + } + // + // getting down to here is bad for cpu usage + if ( loopCount++ > MAX_HIDEAREA_LOOPS ) { + //botimport.Print(PRT_MESSAGE, "AAS_NearestHideArea: exceeded max loops, aborting\n" ); + continue; + } + // + // otherwise, add this to the list so we check is reachables + // disabled, this should only store the raw traveltime, not the adjusted time + //(*aasworld).hidetraveltimes[nextareanum] = t; + nextupdate = &( *aasworld ).areaupdate[nextareanum]; + nextupdate->areanum = nextareanum; + nextupdate->tmptraveltime = t; + //remember where we entered this area + VectorCopy( reach->end, nextupdate->start ); + //if this update is not in the list yet + if ( !nextupdate->inlist ) { + //add the new update to the end of the list + nextupdate->next = NULL; + nextupdate->prev = updatelistend; + if ( updatelistend ) { + updatelistend->next = nextupdate; + } else { updateliststart = nextupdate;} + updatelistend = nextupdate; + nextupdate->inlist = qtrue; + } //end if + } //end if + } //end for + } //end while + //botimport.Print(PRT_MESSAGE, "AAS_NearestHideArea: hidearea: %i, %i loops\n", bestarea, count ); + return bestarea; +} //end of the function AAS_NearestHideArea + +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_FindAttackSpotWithinRange( int srcnum, int rangenum, int enemynum, float rangedist, int travelflags, float *outpos ) { + int i, nextareanum, badtravelflags, numreach, bestarea; + unsigned short int t, besttraveltime, enemytraveltime; + aas_routingupdate_t *updateliststart, *updatelistend, *curupdate, *nextupdate; + aas_reachability_t *reach; + vec3_t srcorg, rangeorg, enemyorg; + int srcarea, rangearea, enemyarea; + unsigned short int srctraveltime; + int count = 0; + #define MAX_ATTACKAREA_LOOPS 200 + static float lastTime; + // + // RF, currently doesn't work with multiple AAS worlds, so only enable for the default world + //if (aasworld != aasworlds) return 0; + // + // don't run this more than once per frame + if ( lastTime == AAS_Time() ) { + return 0; + } + lastTime = AAS_Time(); + // + if ( !( *aasworld ).hidetraveltimes ) { + ( *aasworld ).hidetraveltimes = (unsigned short int *) GetClearedMemory( ( *aasworld ).numareas * sizeof( unsigned short int ) ); + } else { + memset( ( *aasworld ).hidetraveltimes, 0, ( *aasworld ).numareas * sizeof( unsigned short int ) ); + } //end else + // + if ( !( *aasworld ).visCache ) { + ( *aasworld ).visCache = (byte *) GetClearedMemory( ( *aasworld ).numareas * sizeof( byte ) ); + } else { + memset( ( *aasworld ).visCache, 0, ( *aasworld ).numareas * sizeof( byte ) ); + } //end else + // + AAS_EntityOrigin( srcnum, srcorg ); + AAS_EntityOrigin( rangenum, rangeorg ); + AAS_EntityOrigin( enemynum, enemyorg ); + // + srcarea = BotFuzzyPointReachabilityArea( srcorg ); + rangearea = BotFuzzyPointReachabilityArea( rangeorg ); + enemyarea = BotFuzzyPointReachabilityArea( enemyorg ); + // + besttraveltime = 0; + bestarea = 0; + enemytraveltime = AAS_AreaTravelTimeToGoalArea( srcarea, srcorg, enemyarea, travelflags ); + // + badtravelflags = ~travelflags; + // + curupdate = &( *aasworld ).areaupdate[rangearea]; + curupdate->areanum = rangearea; + VectorCopy( rangeorg, curupdate->start ); + curupdate->areatraveltimes = ( *aasworld ).areatraveltimes[srcarea][0]; + curupdate->tmptraveltime = 0; + //put the area to start with in the current read list + curupdate->next = NULL; + curupdate->prev = NULL; + updateliststart = curupdate; + updatelistend = curupdate; + //while there are updates in the current list, flip the lists + while ( updateliststart ) + { + curupdate = updateliststart; + // + if ( curupdate->next ) { + curupdate->next->prev = NULL; + } else { updatelistend = NULL;} + updateliststart = curupdate->next; + // + curupdate->inlist = qfalse; + //check all reversed reachability links + numreach = ( *aasworld ).areasettings[curupdate->areanum].numreachableareas; + reach = &( *aasworld ).reachability[( *aasworld ).areasettings[curupdate->areanum].firstreachablearea]; + // + for ( i = 0; i < numreach; i++, reach++ ) + { + //if an undesired travel type is used + if ( ( *aasworld ).travelflagfortype[reach->traveltype] & badtravelflags ) { + continue; + } + // + if ( AAS_AreaContentsTravelFlag( reach->areanum ) & badtravelflags ) { + continue; + } + // dont pass through ladder areas + if ( ( *aasworld ).areasettings[reach->areanum].areaflags & AREA_LADDER ) { + continue; + } + // + if ( ( *aasworld ).areasettings[reach->areanum].areaflags & AREA_DISABLED ) { + continue; + } + //number of the area the reachability leads to + nextareanum = reach->areanum; + // if this moves us into the enemies area, skip it + if ( nextareanum == enemyarea ) { + continue; + } + // if we've already been to this area + if ( ( *aasworld ).hidetraveltimes[nextareanum] ) { + continue; + } + //time already travelled plus the traveltime through + //the current area plus the travel time from the reachability + if ( count++ > MAX_ATTACKAREA_LOOPS ) { + //botimport.Print(PRT_MESSAGE, "AAS_FindAttackSpotWithinRange: exceeded max loops, aborting\n" ); + if ( bestarea ) { + VectorCopy( ( *aasworld ).areawaypoints[bestarea], outpos ); + } + return bestarea; + } + t = curupdate->tmptraveltime + + AAS_AreaTravelTime( curupdate->areanum, curupdate->start, reach->start ) + + reach->traveltime; + // + // if it's too far from rangenum, ignore + if ( Distance( rangeorg, ( *aasworld ).areawaypoints[nextareanum] ) > rangedist ) { + continue; + } + // + // find the traveltime from srcnum + srctraveltime = AAS_AreaTravelTimeToGoalArea( srcarea, srcorg, nextareanum, travelflags ); + // do this test now, so we can reject the route if it starts out too long + if ( besttraveltime && srctraveltime >= besttraveltime ) { + continue; + } + // + // if this area doesn't have a vis list, ignore it + if ( ( *aasworld ).areavisibility[nextareanum] ) { + //if the nextarea can see the enemy area + if ( AAS_AreaVisible( enemyarea, nextareanum ) ) { // now last of all, check that this area is a good attacking spot + if ( ( ( *aasworld ).visCache[nextareanum] == 2 ) || + ( !( *aasworld ).visCache[nextareanum] && + ( count += 10 ) && // we are about to use lots of CPU time + botimport.AICast_CheckAttackAtPos( srcnum, enemynum, ( *aasworld ).areawaypoints[nextareanum], qfalse, qfalse ) ) ) { + ( *aasworld ).visCache[nextareanum] = 2; + besttraveltime = srctraveltime; + bestarea = nextareanum; + } else { + ( *aasworld ).visCache[nextareanum] = 1; + } + } //end if + } + ( *aasworld ).hidetraveltimes[nextareanum] = t; + nextupdate = &( *aasworld ).areaupdate[nextareanum]; + nextupdate->areanum = nextareanum; + nextupdate->tmptraveltime = t; + //remember where we entered this area + VectorCopy( reach->end, nextupdate->start ); + //if this update is not in the list yet + if ( !nextupdate->inlist ) { + //add the new update to the end of the list + nextupdate->next = NULL; + nextupdate->prev = updatelistend; + if ( updatelistend ) { + updatelistend->next = nextupdate; + } else { updateliststart = nextupdate;} + updatelistend = nextupdate; + nextupdate->inlist = qtrue; + } //end if + } //end for + } //end while +//botimport.Print(PRT_MESSAGE, "AAS_NearestHideArea: hidearea: %i, %i loops\n", bestarea, count ); + if ( bestarea ) { + VectorCopy( ( *aasworld ).areawaypoints[bestarea], outpos ); + } + return bestarea; +} //end of the function AAS_NearestHideArea + +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +qboolean AAS_GetRouteFirstVisPos( vec3_t srcpos, vec3_t destpos, int travelflags, vec3_t retpos ) { + int srcarea, destarea, travarea; + vec3_t travpos; + int ftraveltime, freachnum, lasttraveltime; + aas_reachability_t reach; + int loops = 0; +#define MAX_GETROUTE_VISPOS_LOOPS 200 + // + // SRCPOS: enemy + // DESTPOS: self + // RETPOS: first area that is visible from destpos, in route from srcpos to destpos + srcarea = BotFuzzyPointReachabilityArea( srcpos ); + if ( !srcarea ) { + return qfalse; + } + destarea = BotFuzzyPointReachabilityArea( destpos ); + if ( !destarea ) { + return qfalse; + } + if ( destarea == srcarea ) { + VectorCopy( srcpos, retpos ); + return qtrue; + } + // + //if the srcarea can see the destarea + if ( AAS_AreaVisible( srcarea, destarea ) ) { + VectorCopy( srcpos, retpos ); + return qtrue; + } + // if this area doesn't have a vis list, ignore it + if ( !( *aasworld ).areavisibility[destarea] ) { + return qfalse; + } + // + travarea = srcarea; + VectorCopy( srcpos, travpos ); + lasttraveltime = -1; + while ( ( loops++ < MAX_GETROUTE_VISPOS_LOOPS ) && AAS_AreaRouteToGoalArea( travarea, travpos, destarea, travelflags, &ftraveltime, &freachnum ) ) { + if ( lasttraveltime >= 0 && ftraveltime >= lasttraveltime ) { + return qfalse; // we may be in a loop + } + lasttraveltime = ftraveltime; + // + AAS_ReachabilityFromNum( freachnum, &reach ); + if ( reach.areanum == destarea ) { + VectorCopy( travpos, retpos ); + return qtrue; + } + //if the reach area can see the destarea + if ( AAS_AreaVisible( reach.areanum, destarea ) ) { + VectorCopy( reach.end, retpos ); + return qtrue; + } + // + travarea = reach.areanum; + VectorCopy( reach.end, travpos ); + } + // + // unsuccessful + return qfalse; +} \ No newline at end of file diff --git a/Projects/Android/jni/rtcw/src/botlib/be_aas_route.h b/Projects/Android/jni/rtcw/src/botlib/be_aas_route.h new file mode 100644 index 0000000..bc2e134 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/botlib/be_aas_route.h @@ -0,0 +1,68 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +/***************************************************************************** + * name: be_aas_route.h + * + * desc: AAS + * + * + *****************************************************************************/ + +#ifdef AASINTERN +//initialize the AAS routing +void AAS_InitRouting( void ); +//free the AAS routing caches +void AAS_FreeRoutingCaches( void ); +//returns the travel time from start to end in the given area +unsigned short int AAS_AreaTravelTime( int areanum, vec3_t start, vec3_t end ); +// +void AAS_CreateAllRoutingCache( void ); +// +void AAS_RoutingInfo( void ); +#endif //AASINTERN + +//returns the travel flag for the given travel type +int AAS_TravelFlagForType( int traveltype ); +// +int AAS_AreaContentsTravelFlag( int areanum ); +//returns the index of the next reachability for the given area +int AAS_NextAreaReachability( int areanum, int reachnum ); +//returns the reachability with the given index +void AAS_ReachabilityFromNum( int num, struct aas_reachability_s *reach ); +//returns a random goal area and goal origin +int AAS_RandomGoalArea( int areanum, int travelflags, int *goalareanum, vec3_t goalorigin ); +//returns the travel time within the given area from start to end +unsigned short int AAS_AreaTravelTime( int areanum, vec3_t start, vec3_t end ); +//returns the travel time from the area to the goal area using the given travel flags +int AAS_AreaTravelTimeToGoalArea( int areanum, vec3_t origin, int goalareanum, int travelflags ); +//returns the travel time from the area to the goal area using the given travel flags +int AAS_AreaTravelTimeToGoalAreaCheckLoop( int areanum, vec3_t origin, int goalareanum, int travelflags, int loopareanum ); + +extern int BotFuzzyPointReachabilityArea( vec3_t origin ); diff --git a/Projects/Android/jni/rtcw/src/botlib/be_aas_routealt.c b/Projects/Android/jni/rtcw/src/botlib/be_aas_routealt.c new file mode 100644 index 0000000..ee6828e --- /dev/null +++ b/Projects/Android/jni/rtcw/src/botlib/be_aas_routealt.c @@ -0,0 +1,271 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +/***************************************************************************** + * name: be_aas_routealt.c + * + * desc: AAS + * + * + *****************************************************************************/ + +#include "../game/q_shared.h" +#include "l_utils.h" +#include "l_memory.h" +#include "l_log.h" +#include "l_script.h" +#include "l_precomp.h" +#include "l_struct.h" +#include "aasfile.h" +#include "../game/botlib.h" +#include "../game/be_aas.h" +#include "be_aas_funcs.h" +#include "be_interface.h" +#include "be_aas_def.h" + +//#define ENABLE_ALTROUTING + +typedef struct midrangearea_s +{ + int valid; + unsigned short starttime; + unsigned short goaltime; +} midrangearea_t; + +midrangearea_t *midrangeareas; +int *clusterareas; +int numclusterareas; + +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_AltRoutingFloodCluster_r( int areanum ) { + int i, otherareanum; + aas_area_t *area; + aas_face_t *face; + + //add the current area to the areas of the current cluster + clusterareas[numclusterareas] = areanum; + numclusterareas++; + //remove the area from the mid range areas + midrangeareas[areanum].valid = qfalse; + //flood to other areas through the faces of this area + area = &( *aasworld ).areas[areanum]; + for ( i = 0; i < area->numfaces; i++ ) + { + face = &( *aasworld ).faces[abs( ( *aasworld ).faceindex[area->firstface + i] )]; + //get the area at the other side of the face + if ( face->frontarea == areanum ) { + otherareanum = face->backarea; + } else { otherareanum = face->frontarea;} + //if there is an area at the other side of this face + if ( !otherareanum ) { + continue; + } + //if the other area is not a midrange area + if ( !midrangeareas[otherareanum].valid ) { + continue; + } + // + AAS_AltRoutingFloodCluster_r( otherareanum ); + } //end for +} //end of the function AAS_AltRoutingFloodCluster_r +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_AlternativeRouteGoals( vec3_t start, vec3_t goal, int travelflags, + aas_altroutegoal_t *altroutegoals, int maxaltroutegoals, + int color ) { +#ifndef ENABLE_ALTROUTING + return 0; +#else + int i, j, startareanum, goalareanum, bestareanum; + int numaltroutegoals, nummidrangeareas; + int starttime, goaltime, goaltraveltime; + float dist, bestdist; + vec3_t mid, dir; +#ifdef DEBUG + int startmillisecs; + + startmillisecs = Sys_MilliSeconds(); +#endif + + startareanum = AAS_PointAreaNum( start ); + if ( !startareanum ) { + return 0; + } + goalareanum = AAS_PointAreaNum( goal ); + if ( !goalareanum ) { + return 0; + } + //travel time towards the goal area + goaltraveltime = AAS_AreaTravelTimeToGoalArea( startareanum, start, goalareanum, travelflags ); + //clear the midrange areas + memset( midrangeareas, 0, ( *aasworld ).numareas * sizeof( midrangearea_t ) ); + numaltroutegoals = 0; + // + nummidrangeareas = 0; + // + for ( i = 1; i < ( *aasworld ).numareas; i++ ) + { + // + if ( !( ( *aasworld ).areasettings[i].contents & AREACONTENTS_ROUTEPORTAL ) ) { + continue; + } + //if the area has no reachabilities + if ( !AAS_AreaReachability( i ) ) { + continue; + } + //tavel time from the area to the start area + starttime = AAS_AreaTravelTimeToGoalArea( startareanum, start, i, travelflags ); + if ( !starttime ) { + continue; + } + //if the travel time from the start to the area is greater than the shortest goal travel time + if ( starttime > 1.5 * goaltraveltime ) { + continue; + } + //travel time from the area to the goal area + goaltime = AAS_AreaTravelTimeToGoalArea( i, NULL, goalareanum, travelflags ); + if ( !goaltime ) { + continue; + } + //if the travel time from the area to the goal is greater than the shortest goal travel time + if ( goaltime > 1.5 * goaltraveltime ) { + continue; + } + //this is a mid range area + midrangeareas[i].valid = qtrue; + midrangeareas[i].starttime = starttime; + midrangeareas[i].goaltime = goaltime; + Log_Write( "%d midrange area %d", nummidrangeareas, i ); + nummidrangeareas++; + } //end for + // + for ( i = 1; i < ( *aasworld ).numareas; i++ ) + { + if ( !midrangeareas[i].valid ) { + continue; + } + //get the areas in one cluster + numclusterareas = 0; + AAS_AltRoutingFloodCluster_r( i ); + //now we've got a cluster with areas through which an alternative route could go + //get the 'center' of the cluster + VectorClear( mid ); + for ( j = 0; j < numclusterareas; j++ ) + { + VectorAdd( mid, ( *aasworld ).areas[clusterareas[j]].center, mid ); + } //end for + VectorScale( mid, 1.0 / numclusterareas, mid ); + //get the area closest to the center of the cluster + bestdist = 999999; + bestareanum = 0; + for ( j = 0; j < numclusterareas; j++ ) + { + VectorSubtract( mid, ( *aasworld ).areas[clusterareas[j]].center, dir ); + dist = VectorLength( dir ); + if ( dist < bestdist ) { + bestdist = dist; + bestareanum = clusterareas[j]; + } //end if + } //end for + //now we've got an area for an alternative route + //FIXME: add alternative goal origin + VectorCopy( ( *aasworld ).areas[bestareanum].center, altroutegoals[numaltroutegoals].origin ); + altroutegoals[numaltroutegoals].areanum = bestareanum; + altroutegoals[numaltroutegoals].starttraveltime = midrangeareas[bestareanum].starttime; + altroutegoals[numaltroutegoals].goaltraveltime = midrangeareas[bestareanum].goaltime; + altroutegoals[numaltroutegoals].extratraveltime = + ( midrangeareas[bestareanum].starttime + midrangeareas[bestareanum].goaltime ) - + goaltraveltime; + numaltroutegoals++; + // +#ifdef DEBUG + botimport.Print( PRT_MESSAGE, "alternative route goal area %d, numclusterareas = %d\n", bestareanum, numclusterareas ); + if ( color ) { + AAS_DrawPermanentCross( ( *aasworld ).areas[bestareanum].center, 10, color ); + } //end if + //AAS_ShowArea(bestarea, qtrue); +#endif + //don't return more than the maximum alternative route goals + if ( numaltroutegoals >= maxaltroutegoals ) { + break; + } + } //end for + botimport.Print( PRT_MESSAGE, "%d alternative route goals\n", numaltroutegoals ); +#ifdef DEBUG + botimport.Print( PRT_MESSAGE, "alternative route goals in %d msec\n", Sys_MilliSeconds() - startmillisecs ); +#endif + return numaltroutegoals; +#endif +} //end of the function AAS_AlternativeRouteGoals +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_InitAlternativeRouting( void ) { +#ifdef ENABLE_ALTROUTING + if ( midrangeareas ) { + FreeMemory( midrangeareas ); + } + midrangeareas = (midrangearea_t *) GetMemory( ( *aasworld ).numareas * sizeof( midrangearea_t ) ); + if ( clusterareas ) { + FreeMemory( clusterareas ); + } + clusterareas = (int *) GetMemory( aasworld.numareas * sizeof( int ) ); +#endif +} //end of the function AAS_InitAlternativeRouting +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_ShutdownAlternativeRouting( void ) { +#ifdef ENABLE_ALTROUTING + if ( midrangeareas ) { + FreeMemory( midrangeareas ); + } + midrangeareas = NULL; + if ( clusterareas ) { + FreeMemory( clusterareas ); + } + clusterareas = NULL; + numclusterareas = 0; +#endif +} diff --git a/Projects/Android/jni/rtcw/src/botlib/be_aas_routealt.h b/Projects/Android/jni/rtcw/src/botlib/be_aas_routealt.h new file mode 100644 index 0000000..be40784 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/botlib/be_aas_routealt.h @@ -0,0 +1,46 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +/***************************************************************************** + * name: be_aas_routealt.h + * + * desc: AAS + * + * + *****************************************************************************/ + +#ifdef AASINTERN +void AAS_InitAlternativeRouting( void ); +void AAS_ShutdownAlternativeRouting( void ); +#endif //AASINTERN + + +int AAS_AlternativeRouteGoals( vec3_t start, vec3_t goal, int travelflags, + aas_altroutegoal_t *altroutegoals, int maxaltroutegoals, + int color ); diff --git a/Projects/Android/jni/rtcw/src/botlib/be_aas_routetable.c b/Projects/Android/jni/rtcw/src/botlib/be_aas_routetable.c new file mode 100644 index 0000000..70dbb63 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/botlib/be_aas_routetable.c @@ -0,0 +1,1449 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +//=========================================================================== +// +// Name: be_aas_routetable.c +// Function: Area Awareness System, Route-table defines +// Programmer: Ridah +// Tab Size: 3 +//=========================================================================== + +#include "../game/q_shared.h" +#include "l_memory.h" +#include "l_script.h" +#include "l_precomp.h" +#include "l_struct.h" +#include "l_libvar.h" +#include "l_utils.h" +#include "aasfile.h" +#include "../game/botlib.h" +#include "../game/be_aas.h" +#include "be_interface.h" +#include "be_aas_def.h" + +// ugly hack to turn off route-tables, can't find a way to check cvar's +int disable_routetable = 0; + +// this must be enabled for the route-tables to work, but it's not fully operational yet +#define CHECK_TRAVEL_TIMES +//#define DEBUG_ROUTETABLE +#define FILTERAREAS + +// enable this to use the built-in route-cache system to find the routes +#define USE_ROUTECACHE + +// enable this to disable Rocket/BFG Jumping, Grapple Hook +#define FILTER_TRAVEL + +// hmm, is there a cleaner way of finding out memory usage? +extern int totalmemorysize; +static int memorycount, cachememory; + +// globals to reduce function parameters +static unsigned short int *filtered_areas, childcount, num_parents; +static unsigned short int *rev_filtered_areas; + +// misc defines +unsigned short CRC_ProcessString( unsigned char *data, int length ); + + +//=========================================================================== +// Memory debugging/optimization + +void *AAS_RT_GetClearedMemory( unsigned long size ) { + void *ptr; + + memorycount += size; + + // ptr = GetClearedMemory(size); + //ptr = GetClearedHunkMemory(size); + // Ryan - 01102k, need to use this, since the routetable calculations use up a lot of memory + // this will be a non-issue once we transfer the remnants of the routetable over to the aasworld + ptr = malloc( size ); + memset( ptr, 0, size ); + + return ptr; +} + +void AAS_RT_FreeMemory( void *ptr ) { + int before; + + before = totalmemorysize; + + // FreeMemory( ptr ); + // Ryan - 01102k + free( ptr ); + + memorycount -= before - totalmemorysize; +} + +void AAS_RT_PrintMemoryUsage() { +#ifdef AAS_RT_MEMORY_USAGE + + botimport.Print( PRT_MESSAGE, "\n" ); + + // TODO: print the usage from each of the aas_rt_t lumps + +#endif +} +//=========================================================================== + + +//=========================================================================== +// return the number of unassigned areas that are in the given area's visible list +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_RT_GetValidVisibleAreasCount( aas_area_buildlocalinfo_t *localinfo, aas_area_childlocaldata_t **childlocaldata ) { + int i, cnt; + + cnt = 1; // assume it can reach itself + + for ( i = 0; i < localinfo->numvisible; i++ ) + { + if ( childlocaldata[localinfo->visible[i]] ) { + continue; + } + + cnt++; + } + + return cnt; +} +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +static aas_rt_route_t **routetable; + +int AAS_AreaRouteToGoalArea( int areanum, vec3_t origin, int goalareanum, int travelflags, int *traveltime, int *reachnum ); + +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== + +void AAS_RT_CalcTravelTimesToGoalArea( int goalarea ) { + int i; + // TTimo: unused +// static int tfl = TFL_DEFAULT & ~(TFL_JUMPPAD|TFL_ROCKETJUMP|TFL_BFGJUMP|TFL_GRAPPLEHOOK|TFL_DOUBLEJUMP|TFL_RAMPJUMP|TFL_STRAFEJUMP|TFL_LAVA); //----(SA) modified since slime is no longer deadly +// static int tfl = TFL_DEFAULT & ~(TFL_JUMPPAD|TFL_ROCKETJUMP|TFL_BFGJUMP|TFL_GRAPPLEHOOK|TFL_DOUBLEJUMP|TFL_RAMPJUMP|TFL_STRAFEJUMP|TFL_SLIME|TFL_LAVA); + aas_rt_route_t *rt; + int reach, travel; + + for ( i = 0; i < childcount; i++ ) { + rt = &routetable[i][-1 + rev_filtered_areas[goalarea]]; + if ( AAS_AreaRouteToGoalArea( filtered_areas[i], ( *aasworld ).areas[filtered_areas[i]].center, goalarea, ~RTB_BADTRAVELFLAGS, &travel, &reach ) ) { + rt->reachable_index = reach; + rt->travel_time = travel; + } else { + rt->reachable_index = -1; + rt->travel_time = 0; + } + } +} +//=========================================================================== +// calculate the initial route-table for each filtered area to all other areas +// +// FIXME: this isn't fully operational yet, for some reason not all routes are found +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_RT_CalculateRouteTable( aas_rt_route_t **parmroutetable ) { + int i; + + routetable = parmroutetable; + + for ( i = 0; i < childcount; i++ ) + { + AAS_RT_CalcTravelTimesToGoalArea( filtered_areas[i] ); + } +} + +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_RT_AddParentLink( aas_area_childlocaldata_t *child, int parentindex, int childindex ) { + aas_parent_link_t *oldparentlink; + + oldparentlink = child->parentlink; + + child->parentlink = (aas_parent_link_t *) AAS_RT_GetClearedMemory( sizeof( aas_parent_link_t ) ); + + child->parentlink->childindex = (unsigned short int)childindex; + child->parentlink->parent = (unsigned short int)parentindex; + child->parentlink->next = oldparentlink; +} + +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_RT_WriteShort( unsigned short int si, fileHandle_t fp ) { + unsigned short int lsi; + + lsi = LittleShort( si ); + botimport.FS_Write( &lsi, sizeof( lsi ), fp ); +} + +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_RT_WriteByte( int si, fileHandle_t fp ) { + unsigned char uc; + + uc = si; + botimport.FS_Write( &uc, sizeof( uc ), fp ); +} + +//=========================================================================== +// writes the current route-table data to a .rtb file in tne maps folder +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_RT_WriteRouteTable() { + int ident, version; + unsigned short crc_aas; + fileHandle_t fp; + char filename[MAX_QPATH]; + + // open the file for writing + Com_sprintf( filename, MAX_QPATH, "maps/%s.rtb", ( *aasworld ).mapname ); + botimport.Print( PRT_MESSAGE, "\nsaving route-table to %s\n", filename ); + botimport.FS_FOpenFile( filename, &fp, FS_WRITE ); + if ( !fp ) { + AAS_Error( "Unable to open file: %s\n", filename ); + return; + } + + // ident + ident = LittleLong( RTBID ); + botimport.FS_Write( &ident, sizeof( ident ), fp ); + + // version + version = LittleLong( RTBVERSION ); + botimport.FS_Write( &version, sizeof( version ), fp ); + + // crc + crc_aas = CRC_ProcessString( (unsigned char *)( *aasworld ).areas, sizeof( aas_area_t ) * ( *aasworld ).numareas ); + botimport.FS_Write( &crc_aas, sizeof( crc_aas ), fp ); + + // save the table data + + // children + botimport.FS_Write( &( *aasworld ).routetable->numChildren, sizeof( int ), fp ); + botimport.FS_Write( ( *aasworld ).routetable->children, ( *aasworld ).routetable->numChildren * sizeof( aas_rt_child_t ), fp ); + + // parents + botimport.FS_Write( &( *aasworld ).routetable->numParents, sizeof( int ), fp ); + botimport.FS_Write( ( *aasworld ).routetable->parents, ( *aasworld ).routetable->numParents * sizeof( aas_rt_parent_t ), fp ); + + // parentChildren + botimport.FS_Write( &( *aasworld ).routetable->numParentChildren, sizeof( int ), fp ); + botimport.FS_Write( ( *aasworld ).routetable->parentChildren, ( *aasworld ).routetable->numParentChildren * sizeof( unsigned short int ), fp ); + + // visibleParents + botimport.FS_Write( &( *aasworld ).routetable->numVisibleParents, sizeof( int ), fp ); + botimport.FS_Write( ( *aasworld ).routetable->visibleParents, ( *aasworld ).routetable->numVisibleParents * sizeof( unsigned short int ), fp ); + + // parentLinks + botimport.FS_Write( &( *aasworld ).routetable->numParentLinks, sizeof( int ), fp ); + botimport.FS_Write( ( *aasworld ).routetable->parentLinks, ( *aasworld ).routetable->numParentLinks * sizeof( aas_rt_parent_link_t ), fp ); + + botimport.FS_FCloseFile( fp ); + return; +} + +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_RT_DBG_Read( void *buf, int size, int fp ) { + botimport.FS_Read( buf, size, fp ); +} + +//=========================================================================== +// reads the given file, and creates the structures required for the route-table system +// +// Parameter: - +// Returns: qtrue if succesful, qfalse if not +// Changes Globals: - +//=========================================================================== +#define DEBUG_READING_TIME +qboolean AAS_RT_ReadRouteTable( fileHandle_t fp ) { + int ident, version, i; + unsigned short int crc, crc_aas; + aas_rt_t *routetable; + aas_rt_child_t *child; + aas_rt_parent_t *parent; + aas_rt_parent_link_t *plink; + unsigned short int *psi; + + qboolean doswap; + +#ifdef DEBUG_READING_TIME + int pretime; + + pretime = Sys_MilliSeconds(); +#endif + + routetable = ( *aasworld ).routetable; + + doswap = ( LittleLong( 1 ) != 1 ); + + // check ident + AAS_RT_DBG_Read( &ident, sizeof( ident ), fp ); + ident = LittleLong( ident ); + + if ( ident != RTBID ) { + AAS_Error( "File is not an RTB file\n" ); + botimport.FS_FCloseFile( fp ); + return qfalse; + } + + // check version + AAS_RT_DBG_Read( &version, sizeof( version ), fp ); + version = LittleLong( version ); + + if ( version != RTBVERSION ) { + AAS_Error( "File is version %i not %i\n", version, RTBVERSION ); + botimport.FS_FCloseFile( fp ); + return qfalse; + } + + // read the CRC check on the AAS data + AAS_RT_DBG_Read( &crc, sizeof( crc ), fp ); + crc = LittleShort( crc ); + + // calculate a CRC on the AAS areas + crc_aas = CRC_ProcessString( (unsigned char *)( *aasworld ).areas, sizeof( aas_area_t ) * ( *aasworld ).numareas ); + + if ( crc != crc_aas ) { + AAS_Error( "Route-table is from different AAS file, ignoring.\n" ); + botimport.FS_FCloseFile( fp ); + return qfalse; + } + + // read the route-table + + // children + botimport.FS_Read( &routetable->numChildren, sizeof( int ), fp ); + routetable->numChildren = LittleLong( routetable->numChildren ); + routetable->children = (aas_rt_child_t *) AAS_RT_GetClearedMemory( routetable->numChildren * sizeof( aas_rt_child_t ) ); + botimport.FS_Read( routetable->children, routetable->numChildren * sizeof( aas_rt_child_t ), fp ); + child = &routetable->children[0]; + if ( doswap ) { + for ( i = 0; i < routetable->numChildren; i++, child++ ) { + child->areanum = LittleShort( child->areanum ); + child->numParentLinks = LittleLong( child->numParentLinks ); + child->startParentLinks = LittleLong( child->startParentLinks ); + } + } + + // parents + botimport.FS_Read( &routetable->numParents, sizeof( int ), fp ); + routetable->numParents = LittleLong( routetable->numParents ); + routetable->parents = (aas_rt_parent_t *) AAS_RT_GetClearedMemory( routetable->numParents * sizeof( aas_rt_parent_t ) ); + botimport.FS_Read( routetable->parents, routetable->numParents * sizeof( aas_rt_parent_t ), fp ); + parent = &routetable->parents[0]; + if ( doswap ) { + for ( i = 0; i < routetable->numParents; i++, parent++ ) { + parent->areanum = LittleShort( parent->areanum ); + parent->numParentChildren = LittleLong( parent->numParentChildren ); + parent->startParentChildren = LittleLong( parent->startParentChildren ); + parent->numVisibleParents = LittleLong( parent->numVisibleParents ); + parent->startVisibleParents = LittleLong( parent->startVisibleParents ); + } + } + + // parentChildren + botimport.FS_Read( &routetable->numParentChildren, sizeof( int ), fp ); + routetable->numParentChildren = LittleLong( routetable->numParentChildren ); + routetable->parentChildren = (unsigned short int *) AAS_RT_GetClearedMemory( routetable->numParentChildren * sizeof( unsigned short int ) ); + botimport.FS_Read( routetable->parentChildren, routetable->numParentChildren * sizeof( unsigned short int ), fp ); + psi = &routetable->parentChildren[0]; + if ( doswap ) { + for ( i = 0; i < routetable->numParentChildren; i++, psi++ ) { + *psi = LittleShort( *psi ); + } + } + + // visibleParents + botimport.FS_Read( &routetable->numVisibleParents, sizeof( int ), fp ); + routetable->numVisibleParents = LittleLong( routetable->numVisibleParents ); + routetable->visibleParents = (unsigned short int *) AAS_RT_GetClearedMemory( routetable->numVisibleParents * sizeof( unsigned short int ) ); + botimport.FS_Read( routetable->visibleParents, routetable->numVisibleParents * sizeof( unsigned short int ), fp ); + psi = &routetable->visibleParents[0]; + if ( doswap ) { + for ( i = 0; i < routetable->numVisibleParents; i++, psi++ ) { + *psi = LittleShort( *psi ); + } + } + + // parentLinks + botimport.FS_Read( &routetable->numParentLinks, sizeof( int ), fp ); + routetable->numParentLinks = LittleLong( routetable->numParentLinks ); + routetable->parentLinks = (aas_rt_parent_link_t *) AAS_RT_GetClearedMemory( routetable->numParentLinks * sizeof( aas_rt_parent_link_t ) ); + botimport.FS_Read( routetable->parentLinks, routetable->numParentLinks * sizeof( aas_parent_link_t ), fp ); + plink = &routetable->parentLinks[0]; + if ( doswap ) { + for ( i = 0; i < routetable->numParentLinks; i++, plink++ ) { + plink->childIndex = LittleShort( plink->childIndex ); + plink->parent = LittleShort( plink->parent ); + } + } + + // build the areaChildIndexes + routetable->areaChildIndexes = (unsigned short int *) AAS_RT_GetClearedMemory( ( *aasworld ).numareas * sizeof( unsigned short int ) ); + child = routetable->children; + for ( i = 0; i < routetable->numChildren; i++, child++ ) { + routetable->areaChildIndexes[child->areanum] = i + 1; + } + + botimport.Print( PRT_MESSAGE, "Total Parents: %d\n", routetable->numParents ); + botimport.Print( PRT_MESSAGE, "Total Children: %d\n", routetable->numChildren ); + botimport.Print( PRT_MESSAGE, "Total Memory Used: %d\n", memorycount ); + +#ifdef DEBUG_READING_TIME + botimport.Print( PRT_MESSAGE, "Route-Table read time: %i\n", Sys_MilliSeconds() - pretime ); +#endif + + botimport.FS_FCloseFile( fp ); + return qtrue; +} + +int AAS_RT_NumParentLinks( aas_area_childlocaldata_t *child ) { + aas_parent_link_t *plink; + int i; + + i = 0; + plink = child->parentlink; + while ( plink ) + { + i++; + plink = plink->next; + } + + return i; +} + +//=========================================================================== +// main routine to build the route-table +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_CreateAllRoutingCache( void ); + +void AAS_RT_BuildRouteTable( void ) { + int i,j,k; + aas_area_t *srcarea; + aas_areasettings_t *srcsettings; +// vec3_t vec; + unsigned int totalcount; + unsigned int noroutecount; + + aas_area_buildlocalinfo_t **area_localinfos; + aas_area_buildlocalinfo_t *localinfo; + + aas_area_childlocaldata_t **area_childlocaldata; + aas_area_childlocaldata_t *child; + + aas_area_parent_t *area_parents[MAX_PARENTS]; + aas_area_parent_t *thisparent; + + int bestchild, bestcount, bestparent, cnt; + + int memoryend; + + unsigned short int *visibleParents; + +#ifdef CHECK_TRAVEL_TIMES + aas_rt_route_t **filteredroutetable; + unsigned short int traveltime; +#endif + + fileHandle_t fp; + char filename[MAX_QPATH]; + +// not used anymore + return; + + // create the routetable in this aasworld + aasworld->routetable = (aas_rt_t *) AAS_RT_GetClearedMemory( sizeof( aas_rt_t ) ); + + // Try to load in a prepared route-table + Com_sprintf( filename, MAX_QPATH, "maps/%s.rtb", ( *aasworld ).mapname ); + botimport.Print( PRT_MESSAGE, "\n---------------------------------\n" ); + botimport.Print( PRT_MESSAGE, "\ntrying to load %s\n", filename ); + botimport.FS_FOpenFile( filename, &fp, FS_READ ); + if ( fp ) { + // read in the table.. + if ( AAS_RT_ReadRouteTable( fp ) ) { + AAS_RT_PrintMemoryUsage(); + + botimport.Print( PRT_MESSAGE, "\nAAS Route-Table loaded.\n" ); + botimport.Print( PRT_MESSAGE, "---------------------------------\n\n" ); + return; + } else + { + botimport.Print( PRT_MESSAGE, "\nUnable to load %s, building route-table..\n", filename ); + } + } else + { + botimport.Print( PRT_MESSAGE, "file not found, building route-table\n\n" ); + } + + + botimport.Print( PRT_MESSAGE, "\n-------------------------------------\nRoute-table memory usage figures..\n\n" ); + + totalcount = 0; + childcount = 0; + noroutecount = 0; + childcount = 0; + num_parents = 0; + + memorycount = 0; + cachememory = 0; + + filtered_areas = (unsigned short int *) AAS_RT_GetClearedMemory( ( *aasworld ).numareas * sizeof( unsigned short int ) ); + rev_filtered_areas = (unsigned short int *) AAS_RT_GetClearedMemory( ( *aasworld ).numareas * sizeof( unsigned short int ) ); + + // to speed things up, build a list of FILTERED areas first + // do this so we can check for filtered areas + AAS_CreateAllRoutingCache(); + for ( i = 0; i < ( *aasworld ).numareas; i++ ) + { + srcarea = &( *aasworld ).areas[i]; + srcsettings = &( *aasworld ).areasettings[i]; + +#ifdef FILTERAREAS + if ( !( srcsettings->areaflags & ( AREA_USEFORROUTING ) ) ) { + continue; + } + if ( !( srcsettings->areaflags & ( AREA_GROUNDED | AREA_LIQUID | AREA_LADDER ) ) ) { + continue; + } +#endif + + rev_filtered_areas[i] = childcount + 1; + filtered_areas[childcount++] = (unsigned short int)i; + } + +#ifdef CHECK_TRAVEL_TIMES + // allocate and calculate the travel times + filteredroutetable = (aas_rt_route_t **) AAS_RT_GetClearedMemory( childcount * sizeof( aas_rt_route_t * ) ); + for ( i = 0; i < childcount; i++ ) + filteredroutetable[i] = (aas_rt_route_t *) AAS_RT_GetClearedMemory( childcount * sizeof( aas_rt_route_t ) ); + + AAS_RT_CalculateRouteTable( filteredroutetable ); + +#endif // CHECK_TRAVEL_TIMES + + // allocate for the temporary build local data + area_localinfos = (aas_area_buildlocalinfo_t **) AAS_RT_GetClearedMemory( childcount * sizeof( aas_area_buildlocalinfo_t * ) ); + + for ( i = 0; i < childcount; i++ ) + { + srcarea = &( *aasworld ).areas[filtered_areas[i]]; + srcsettings = &( *aasworld ).areasettings[filtered_areas[i]]; + + // allocate memory for this area + area_localinfos[i] = (aas_area_buildlocalinfo_t *) AAS_RT_GetClearedMemory( sizeof( aas_area_buildlocalinfo_t ) ); + localinfo = area_localinfos[i]; + + for ( j = 0; j < childcount; j++ ) + { + if ( i == j ) { + continue; + } + +#ifdef CHECK_TRAVEL_TIMES + + // make sure travel time is reasonable + // Get the travel time from i to j + traveltime = (int)filteredroutetable[i][j].travel_time; + + if ( !traveltime ) { + noroutecount++; + continue; + } + if ( traveltime > MAX_LOCALTRAVELTIME ) { + continue; + } + +#endif // CHECK_TRAVEL_TIMES + + // Add it to the list + localinfo->visible[localinfo->numvisible++] = j; + totalcount++; + + if ( localinfo->numvisible >= MAX_VISIBLE_AREAS ) { + botimport.Print( PRT_MESSAGE, "MAX_VISIBLE_AREAS exceeded, lower MAX_VISIBLE_RANGE\n" ); + break; + } + } + } + + // now calculate the best list of locale's + + // allocate for the long-term child data + area_childlocaldata = (aas_area_childlocaldata_t **) AAS_RT_GetClearedMemory( childcount * sizeof( aas_area_childlocaldata_t * ) ); + + for ( i = 0; i < childcount; i++ ) + { + area_childlocaldata[i] = (aas_area_childlocaldata_t *) AAS_RT_GetClearedMemory( sizeof( aas_area_childlocaldata_t ) ); + area_childlocaldata[i]->areanum = filtered_areas[i]; + } + + while ( 1 ) + { + bestchild = -1; + bestcount = 99999; + + // find the area with the least number of visible areas + for ( i = 0; i < childcount; i++ ) + { + if ( area_childlocaldata[i]->parentlink ) { + continue; // already has been allocated to a parent + + } + cnt = AAS_RT_GetValidVisibleAreasCount( area_localinfos[i], area_childlocaldata ); + + if ( cnt < bestcount ) { + bestcount = area_localinfos[i]->numvisible; + bestchild = i; + } + } + + if ( bestchild < 0 ) { + break; // our job is done + + + } + localinfo = area_localinfos[bestchild]; + + + // look through this area's list of visible areas, and pick the one with the most VALID visible areas + bestparent = bestchild; + + for ( i = 0; i < localinfo->numvisible; i++ ) + { + if ( area_childlocaldata[localinfo->visible[i]]->parentlink ) { + continue; // already has been allocated to a parent + + } + // calculate how many of children are valid + cnt = AAS_RT_GetValidVisibleAreasCount( area_localinfos[localinfo->visible[i]], area_childlocaldata ); + + if ( cnt > bestcount ) { + bestcount = cnt; + bestparent = localinfo->visible[i]; + } + } + + // now setup this parent, and assign all it's children + localinfo = area_localinfos[bestparent]; + + // we use all children now, not just valid ones + bestcount = localinfo->numvisible; + + area_parents[num_parents] = (aas_area_parent_t *) AAS_RT_GetClearedMemory( sizeof( aas_area_parent_t ) ); + thisparent = area_parents[num_parents]; + + thisparent->areanum = filtered_areas[bestparent]; + thisparent->children = (unsigned short int *) AAS_RT_GetClearedMemory( ( localinfo->numvisible + 1 ) * sizeof( unsigned short int ) ); + + // first, add itself to the list (yes, a parent is a child of itself) + child = area_childlocaldata[bestparent]; + AAS_RT_AddParentLink( child, num_parents, thisparent->numchildren ); + thisparent->children[thisparent->numchildren++] = filtered_areas[bestparent]; + + // loop around all the parent's visible list, and make them children if they're aren't already assigned to a parent + for ( i = 0; i < localinfo->numvisible; i++ ) + { + // create the childlocaldata + child = area_childlocaldata[localinfo->visible[i]]; + + // Ridah, only one parent per child in the new system + if ( child->parentlink ) { + continue; // already has been allocated to a parent + + } + if ( child->areanum != thisparent->areanum ) { + AAS_RT_AddParentLink( child, num_parents, thisparent->numchildren ); + thisparent->children[thisparent->numchildren++] = filtered_areas[localinfo->visible[i]]; + } + } + + // now setup the list of children and the route-tables + for ( i = 0; i < thisparent->numchildren; i++ ) + { + child = area_childlocaldata[-1 + rev_filtered_areas[thisparent->children[i]]]; + localinfo = area_localinfos[-1 + rev_filtered_areas[thisparent->children[i]]]; + + child->parentlink->routeindexes = (unsigned short int *) AAS_RT_GetClearedMemory( thisparent->numchildren * sizeof( unsigned short int ) ); + + // now setup the indexes + for ( j = 0; j < thisparent->numchildren; j++ ) + { + // find this child in our list of visibles + if ( j == child->parentlink->childindex ) { + continue; + } + + for ( k = 0; k < localinfo->numvisible; k++ ) + { + if ( thisparent->children[j] == filtered_areas[localinfo->visible[k]] ) { // found a match + child->parentlink->routeindexes[j] = (unsigned short int)k; + break; + } + } + + if ( k == localinfo->numvisible ) { // didn't find it, so add it to our list + if ( localinfo->numvisible >= MAX_VISIBLE_AREAS ) { + botimport.Print( PRT_MESSAGE, "MAX_VISIBLE_AREAS exceeded, lower MAX_VISIBLE_RANGE\n" ); + } else + { + localinfo->visible[localinfo->numvisible] = -1 + rev_filtered_areas[thisparent->children[j]]; + child->parentlink->routeindexes[j] = (unsigned short int)localinfo->numvisible; + localinfo->numvisible++; + } + } + } + } + + num_parents++; + } + + // place all the visible areas from each child, into their childlocaldata route-table + for ( i = 0; i < childcount; i++ ) + { + localinfo = area_localinfos[i]; + child = area_childlocaldata[i]; + + child->numlocal = localinfo->numvisible; + child->localroutes = (aas_rt_route_t *) AAS_RT_GetClearedMemory( localinfo->numvisible * sizeof( aas_rt_route_t ) ); + + for ( j = 0; j < localinfo->numvisible; j++ ) + { + child->localroutes[j] = filteredroutetable[i][localinfo->visible[j]]; + } + + child->parentroutes = (aas_rt_route_t *) AAS_RT_GetClearedMemory( num_parents * sizeof( aas_rt_route_t ) ); + + for ( j = 0; j < num_parents; j++ ) + { + child->parentroutes[j] = filteredroutetable[i][-1 + rev_filtered_areas[area_parents[j]->areanum]]; + } + } + + // build the visibleParents lists + visibleParents = (unsigned short int *) AAS_RT_GetClearedMemory( num_parents * sizeof( unsigned short int ) ); + for ( i = 0; i < num_parents; i++ ) + { + area_parents[i]->numVisibleParents = 0; + + for ( j = 0; j < num_parents; j++ ) + { + if ( i == j ) { + continue; + } + + if ( !AAS_inPVS( ( *aasworld ).areas[area_parents[i]->areanum].center, ( *aasworld ).areas[area_parents[j]->areanum].center ) ) { + continue; + } + + visibleParents[area_parents[i]->numVisibleParents] = j; + area_parents[i]->numVisibleParents++; + } + + // now copy the list over to the current src area + area_parents[i]->visibleParents = (unsigned short int *) AAS_RT_GetClearedMemory( area_parents[i]->numVisibleParents * sizeof( unsigned short int ) ); + memcpy( area_parents[i]->visibleParents, visibleParents, area_parents[i]->numVisibleParents * sizeof( unsigned short int ) ); + + } + AAS_RT_FreeMemory( visibleParents ); + + // before we free the main childlocaldata, go through and assign the aas_area's to their appropriate childlocaldata + // this would require modification of the aas_area_t structure, so for now, we'll just place them in a global array, for external reference + +// aasworld->routetable->area_childlocaldata_list = (aas_area_childlocaldata_t **) AAS_RT_GetClearedMemory( (*aasworld).numareas * sizeof(aas_area_childlocaldata_t *) ); +// for (i=0; iroutetable->area_childlocaldata_list[filtered_areas[i]] = area_childlocaldata[i]; +// } + + // copy the list of parents to a global structure for now (should eventually go into the (*aasworld) structure +// aasworld->routetable->area_parents_global = (aas_area_parent_t **) AAS_RT_GetClearedMemory( num_parents * sizeof(aas_area_parent_t *) ); +// memcpy( aasworld->routetable->area_parents_global, area_parents, num_parents * sizeof(aas_area_parent_t *) ); + + // ................................................ + // Convert the data into the correct format + { + aas_rt_t *rt; + aas_rt_child_t *child; + aas_rt_parent_t *parent; + aas_rt_parent_link_t *plink; + unsigned short int *psi; + + aas_area_childlocaldata_t *chloc; + aas_area_parent_t *apar; + aas_parent_link_t *oplink; + + int localRoutesCount, parentRoutesCount, parentChildrenCount, visibleParentsCount, parentLinkCount, routeIndexesCount; + + rt = ( *aasworld ).routetable; + localRoutesCount = 0; + parentRoutesCount = 0; + parentChildrenCount = 0; + visibleParentsCount = 0; + parentLinkCount = 0; + routeIndexesCount = 0; + + // areaChildIndexes + rt->areaChildIndexes = (unsigned short int *) AAS_RT_GetClearedMemory( ( *aasworld ).numareas * sizeof( unsigned short int ) ); + for ( i = 0; i < childcount; i++ ) + { + rt->areaChildIndexes[filtered_areas[i]] = i + 1; + } + + // children + rt->numChildren = childcount; + rt->children = (aas_rt_child_t *) AAS_RT_GetClearedMemory( rt->numChildren * sizeof( aas_rt_child_t ) ); + child = rt->children; + for ( i = 0; i < childcount; i++, child++ ) + { + chloc = area_childlocaldata[i]; + + child->areanum = chloc->areanum; + child->numParentLinks = AAS_RT_NumParentLinks( chloc ); + + child->startParentLinks = parentLinkCount; + + parentLinkCount += child->numParentLinks; + } + + // parents + rt->numParents = num_parents; + rt->parents = (aas_rt_parent_t *) AAS_RT_GetClearedMemory( rt->numParents * sizeof( aas_rt_parent_t ) ); + parent = rt->parents; + for ( i = 0; i < num_parents; i++, parent++ ) + { + apar = area_parents[i]; + + parent->areanum = apar->areanum; + parent->numParentChildren = apar->numchildren; + parent->numVisibleParents = apar->numVisibleParents; + + parent->startParentChildren = parentChildrenCount; + parent->startVisibleParents = visibleParentsCount; + + parentChildrenCount += parent->numParentChildren; + visibleParentsCount += parent->numVisibleParents; + } + + // parentChildren + rt->numParentChildren = parentChildrenCount; + rt->parentChildren = (unsigned short int *) AAS_RT_GetClearedMemory( parentChildrenCount * sizeof( unsigned short int ) ); + psi = rt->parentChildren; + for ( i = 0; i < num_parents; i++ ) + { + apar = area_parents[i]; + for ( j = 0; j < apar->numchildren; j++, psi++ ) + { + *psi = apar->children[j]; + } + } + + // visibleParents + rt->numVisibleParents = visibleParentsCount; + rt->visibleParents = (unsigned short int *) AAS_RT_GetClearedMemory( rt->numVisibleParents * sizeof( unsigned short int ) ); + psi = rt->visibleParents; + for ( i = 0; i < num_parents; i++ ) + { + apar = area_parents[i]; + for ( j = 0; j < apar->numVisibleParents; j++, psi++ ) + { + *psi = apar->visibleParents[j]; + } + } + + // parentLinks + rt->numParentLinks = parentLinkCount; + rt->parentLinks = (aas_rt_parent_link_t *) AAS_RT_GetClearedMemory( parentLinkCount * sizeof( aas_rt_parent_link_t ) ); + plink = rt->parentLinks; + for ( i = 0; i < childcount; i++ ) + { + chloc = area_childlocaldata[i]; + for ( oplink = chloc->parentlink; oplink; plink++, oplink = oplink->next ) + { + plink->childIndex = oplink->childindex; + plink->parent = oplink->parent; + } + } + + } + // ................................................ + + // write the newly created table + AAS_RT_WriteRouteTable(); + + + botimport.Print( PRT_MESSAGE, "Child Areas: %i\nTotal Parents: %i\nAverage VisAreas: %i\n", (int)childcount, num_parents, (int)( childcount / num_parents ) ); + botimport.Print( PRT_MESSAGE, "NoRoute Ratio: %i%%\n", (int)( ( 100.0 * noroutecount ) / ( 1.0 * childcount * childcount ) ) ); + + memoryend = memorycount; + + // clear allocated memory + +// causes crashes in route-caching +//#ifdef USE_ROUTECACHE +// AAS_FreeRoutingCaches(); +//#endif + + for ( i = 0; i < childcount; i++ ) + { + AAS_RT_FreeMemory( area_localinfos[i] ); +#ifdef CHECK_TRAVEL_TIMES + AAS_RT_FreeMemory( filteredroutetable[i] ); +#endif + } + + { + aas_parent_link_t *next, *trav; + + // kill the client areas + for ( i = 0; i < childcount; i++ ) + { + // kill the parent links + next = area_childlocaldata[i]->parentlink; + // TTimo: suggest () around assignment used as truth value + while ( ( trav = next ) ) + { + next = next->next; + + AAS_RT_FreeMemory( trav->routeindexes ); + AAS_RT_FreeMemory( trav ); + } + + AAS_RT_FreeMemory( area_childlocaldata[i]->localroutes ); + AAS_RT_FreeMemory( area_childlocaldata[i]->parentroutes ); + AAS_RT_FreeMemory( area_childlocaldata[i] ); + } + + // kill the parents + for ( i = 0; i < num_parents; i++ ) + { + AAS_RT_FreeMemory( area_parents[i]->children ); + AAS_RT_FreeMemory( area_parents[i]->visibleParents ); + AAS_RT_FreeMemory( area_parents[i] ); + } + } + + AAS_RT_FreeMemory( area_localinfos ); + AAS_RT_FreeMemory( area_childlocaldata ); + AAS_RT_FreeMemory( filtered_areas ); + AAS_RT_FreeMemory( rev_filtered_areas ); +#ifdef CHECK_TRAVEL_TIMES + AAS_RT_FreeMemory( filteredroutetable ); +#endif + + // check how much memory we've used, and intend to keep + AAS_RT_PrintMemoryUsage(); + + botimport.Print( PRT_MESSAGE, "Route-Table Permanent Memory Usage: %i\n", memorycount ); + botimport.Print( PRT_MESSAGE, "Route-Table Calculation Usage: %i\n", memoryend + cachememory ); + botimport.Print( PRT_MESSAGE, "---------------------------------\n" ); +} + +//=========================================================================== +// free permanent memory used by route-table system +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_RT_ShutdownRouteTable( void ) { + if ( !aasworld->routetable ) { + return; + } + + // free the dynamic lists + AAS_RT_FreeMemory( aasworld->routetable->areaChildIndexes ); + AAS_RT_FreeMemory( aasworld->routetable->children ); + AAS_RT_FreeMemory( aasworld->routetable->parents ); + AAS_RT_FreeMemory( aasworld->routetable->parentChildren ); + AAS_RT_FreeMemory( aasworld->routetable->visibleParents ); +// AAS_RT_FreeMemory( aasworld->routetable->localRoutes ); +// AAS_RT_FreeMemory( aasworld->routetable->parentRoutes ); + AAS_RT_FreeMemory( aasworld->routetable->parentLinks ); +// AAS_RT_FreeMemory( aasworld->routetable->routeIndexes ); +// AAS_RT_FreeMemory( aasworld->routetable->parentTravelTimes ); + + // kill the table + AAS_RT_FreeMemory( aasworld->routetable ); + aasworld->routetable = NULL; +} + +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +aas_rt_parent_link_t *AAS_RT_GetFirstParentLink( aas_rt_child_t *child ) { + return &aasworld->routetable->parentLinks[child->startParentLinks]; +} + +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +aas_rt_child_t *AAS_RT_GetChild( int areanum ) { + int i; + + i = (int)aasworld->routetable->areaChildIndexes[areanum] - 1; + + if ( i >= 0 ) { + return &aasworld->routetable->children[i]; + } else { + return NULL; + } +} + +//=========================================================================== +// returns a route between the areas +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_AreaRouteToGoalArea( int areanum, vec3_t origin, int goalareanum, int travelflags, int *traveltime, int *reachnum ); +aas_rt_route_t *AAS_RT_GetRoute( int srcnum, vec3_t origin, int destnum ) { + #define GETROUTE_NUMROUTES 64 + static aas_rt_route_t routes[GETROUTE_NUMROUTES]; // cycle through these, so we don't overlap + static int routeIndex = 0; + aas_rt_route_t *thisroute; + int reach, traveltime; + aas_rt_t *rt; + static int tfl = TFL_DEFAULT & ~( TFL_JUMPPAD | TFL_ROCKETJUMP | TFL_BFGJUMP | TFL_GRAPPLEHOOK | TFL_DOUBLEJUMP | TFL_RAMPJUMP | TFL_STRAFEJUMP | TFL_LAVA ); //----(SA) modified since slime is no longer deadly +// static int tfl = TFL_DEFAULT & ~(TFL_JUMPPAD|TFL_ROCKETJUMP|TFL_BFGJUMP|TFL_GRAPPLEHOOK|TFL_DOUBLEJUMP|TFL_RAMPJUMP|TFL_STRAFEJUMP|TFL_SLIME|TFL_LAVA); + + if ( !( rt = aasworld->routetable ) ) { // no route table present + return NULL; + } + + if ( disable_routetable ) { + return NULL; + } + + if ( ++routeIndex >= GETROUTE_NUMROUTES ) { + routeIndex = 0; + } + + thisroute = &routes[routeIndex]; + + if ( AAS_AreaRouteToGoalArea( srcnum, origin, destnum, tfl, &traveltime, &reach ) ) { + thisroute->reachable_index = reach; + thisroute->travel_time = traveltime; + return thisroute; + } else { + return NULL; + } +} + +//=========================================================================== +// draws the route-table from src to dest +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +#include "../game/be_ai_goal.h" +int BotGetReachabilityToGoal( vec3_t origin, int areanum, int entnum, + int lastgoalareanum, int lastareanum, + int *avoidreach, float *avoidreachtimes, int *avoidreachtries, + bot_goal_t *goal, int travelflags, int movetravelflags ); + +void AAS_RT_ShowRoute( vec3_t srcpos, int srcnum, int destnum ) { +#ifdef DEBUG +#define MAX_RT_AVOID_REACH 1 + AAS_ClearShownPolygons(); + AAS_ClearShownDebugLines(); + AAS_ShowAreaPolygons( srcnum, 1, qtrue ); + AAS_ShowAreaPolygons( destnum, 4, qtrue ); + { + static int lastgoalareanum, lastareanum; + static int avoidreach[MAX_RT_AVOID_REACH]; + static float avoidreachtimes[MAX_RT_AVOID_REACH]; + static int avoidreachtries[MAX_RT_AVOID_REACH]; + int reachnum; + bot_goal_t goal; + aas_reachability_t reach; + + goal.areanum = destnum; + VectorCopy( botlibglobals.goalorigin, goal.origin ); + reachnum = BotGetReachabilityToGoal( srcpos, srcnum, -1, + lastgoalareanum, lastareanum, + avoidreach, avoidreachtimes, avoidreachtries, + &goal, TFL_DEFAULT | TFL_FUNCBOB, TFL_DEFAULT | TFL_FUNCBOB ); + AAS_ReachabilityFromNum( reachnum, &reach ); + AAS_ShowReachability( &reach ); + } +#endif +} + +/* +================= +AAS_RT_GetHidePos + + "src" is hiding ent, "dest" is the enemy +================= +*/ +int AAS_NearestHideArea( int srcnum, vec3_t origin, int areanum, int enemynum, vec3_t enemyorigin, int enemyareanum, int travelflags ); +qboolean AAS_RT_GetHidePos( vec3_t srcpos, int srcnum, int srcarea, vec3_t destpos, int destnum, int destarea, vec3_t returnPos ) { + static int tfl = TFL_DEFAULT & ~( TFL_JUMPPAD | TFL_ROCKETJUMP | TFL_BFGJUMP | TFL_GRAPPLEHOOK | TFL_DOUBLEJUMP | TFL_RAMPJUMP | TFL_STRAFEJUMP | TFL_LAVA ); //----(SA) modified since slime is no longer deadly +// static int tfl = TFL_DEFAULT & ~(TFL_JUMPPAD|TFL_ROCKETJUMP|TFL_BFGJUMP|TFL_GRAPPLEHOOK|TFL_DOUBLEJUMP|TFL_RAMPJUMP|TFL_STRAFEJUMP|TFL_SLIME|TFL_LAVA); + +#if 1 + // use MrE's breadth first method + int hideareanum; +// int pretime; + + // disabled this so grenade hiding works + //if (!srcarea || !destarea) + // return qfalse; + +// pretime = -Sys_MilliSeconds(); + + hideareanum = AAS_NearestHideArea( srcnum, srcpos, srcarea, destnum, destpos, destarea, tfl ); + if ( !hideareanum ) { +// botimport.Print(PRT_MESSAGE, "Breadth First HidePos FAILED: %i ms\n", pretime + Sys_MilliSeconds()); + return qfalse; + } + // we found a valid hiding area + VectorCopy( ( *aasworld ).areawaypoints[hideareanum], returnPos ); + +// botimport.Print(PRT_MESSAGE, "Breadth First HidePos: %i ms\n", pretime + Sys_MilliSeconds()); + + return qtrue; + +#else + // look around at random parent areas, if any of them have a center point + // that isn't visible from "destpos", then return it's position in returnPos + + int i, j, pathArea, dir; + unsigned short int destTravelTime; + aas_rt_parent_t *srcParent, *travParent, *destParent; + aas_rt_child_t *srcChild, *destChild, *travChild; + aas_rt_route_t *route; + vec3_t destVec; + float destTravelDist; + static float lastTime; + static int frameCount, maxPerFrame = 2; + int firstreach; + aas_reachability_t *reachability, *reach; + qboolean startVisible; + unsigned short int bestTravelTime, thisTravelTime, elapsedTravelTime; + #define MAX_HIDE_TRAVELTIME 1000 // 10 seconds is a very long way away + unsigned char destVisLookup[MAX_PARENTS]; + unsigned short int *destVisTrav; + + aas_rt_t *rt; + + const int MAX_CHECK_VISPARENTS = 100; + int visparents_count, total_parents_checked; + int thisParentIndex; + int pretime; + + if ( !( rt = aasworld->routetable ) ) { // no route table present + return qfalse; + } +/* + if (lastTime > (AAS_Time() - 0.1)) { + if (frameCount++ > maxPerFrame) { + return qfalse; + } + } else { + frameCount = 0; + lastTime = AAS_Time(); + } +*/ + pretime = -Sys_MilliSeconds(); + + // is the src area grounded? + if ( !( srcChild = AAS_RT_GetChild( srcarea ) ) ) { + return qfalse; + } + // does it have a parent? +// all valid areas have a parent +// if (!srcChild->numParentLinks) { +// return qfalse; +// } + // get the dest (enemy) area + if ( !( destChild = AAS_RT_GetChild( destarea ) ) ) { + return qfalse; + } + destParent = &rt->parents[ rt->parentLinks[destChild->startParentLinks].parent ]; + // + // populate the destVisAreas + memset( destVisLookup, 0, sizeof( destVisLookup ) ); + destVisTrav = rt->visibleParents + destParent->startVisibleParents; + for ( i = 0; i < destParent->numVisibleParents; i++, destVisTrav++ ) { + destVisLookup[*destVisTrav] = 1; + } + // + // use the first parent to source the vis areas from + srcParent = &rt->parents[ rt->parentLinks[srcChild->startParentLinks].parent ]; + // + // set the destTravelTime + if ( route = AAS_RT_GetRoute( srcarea, srcpos, destarea ) ) { + destTravelTime = route->travel_time; + } else { + destTravelTime = 0; + } + bestTravelTime = MAX_HIDE_TRAVELTIME; // ignore any routes longer than 10 seconds away + // set the destVec + VectorSubtract( destpos, srcpos, destVec ); + destTravelDist = VectorNormalize( destVec ); + // + // randomize the direction we traverse the list, so the hiding spot isn't always the same + if ( rand() % 2 ) { + dir = 1; // forward + } else { + dir = -1; // reverse + } + // randomize the starting area + if ( srcParent->numVisibleParents ) { + i = rand() % srcParent->numVisibleParents; + } else { // prevent divide by zero + i = 0; + } + // + // setup misc stuff + reachability = ( *aasworld ).reachability; + startVisible = botimport.AICast_VisibleFromPos( destpos, destnum, srcpos, srcnum, qfalse ); + // + // set the firstreach to prevent having to do an array and pointer lookup for each destination + firstreach = ( *aasworld ).areasettings[srcarea].firstreachablearea; + // + // just check random parent areas, traversing the route until we find an area that can't be seen from the dest area + for ( visparents_count = 0, total_parents_checked = 0; visparents_count < MAX_CHECK_VISPARENTS && total_parents_checked < rt->numParents; total_parents_checked++ ) { + thisParentIndex = rand() % rt->numParents; + travParent = &rt->parents[ thisParentIndex ]; + // + // never go to the enemy's areas + if ( travParent->areanum == destarea ) { + continue; + } + // + // if it's visible from dest, ignore it + if ( destVisLookup[thisParentIndex] ) { + continue; + } + // + visparents_count++; + // they might be visible, check to see if the path to the area, takes us towards the + // enemy we are trying to hide from + { + qboolean invalidRoute; + vec3_t curPos, lastVec; + #define GETHIDE_MAX_CHECK_PATHS 15 + // + invalidRoute = qfalse; + // initialize the pathArea + pathArea = srcarea; + VectorCopy( srcpos, curPos ); + // now evaluate the path + for ( j = 0; j < GETHIDE_MAX_CHECK_PATHS; j++ ) { + // get the reachability to the travParent + if ( !( route = AAS_RT_GetRoute( pathArea, curPos, travParent->areanum ) ) ) { + // we can't get to the travParent, so don't bother checking it + invalidRoute = qtrue; + break; + } + // set the pathArea + reach = &reachability[route->reachable_index]; + // how far have we travelled so far? + elapsedTravelTime = AAS_AreaTravelTimeToGoalArea( pathArea, curPos, reach->areanum, tfl ); + // add the travel to the center of the area + elapsedTravelTime += AAS_AreaTravelTime( reach->areanum, reach->end, ( *aasworld ).areas[reach->areanum].center ); + // have we gone too far already? + if ( elapsedTravelTime > bestTravelTime ) { + invalidRoute = qtrue; + break; + } else { + thisTravelTime = route->travel_time; + } + // + // if this travel would have us do something wierd + if ( ( reach->traveltype == TRAVEL_WALKOFFLEDGE ) && ( reach->traveltime > 500 ) ) { + invalidRoute = qtrue; + break; + } + // + pathArea = reach->areanum; + VectorCopy( reach->end, curPos ); + // + // if this moves us into the enemies area, skip it + if ( pathArea == destarea ) { + invalidRoute = qtrue; + break; + } + // if we are very close, don't get any closer under any circumstances + { + vec3_t vec; + float dist; + // + VectorSubtract( destpos, reachability[firstreach + route->reachable_index].end, vec ); + dist = VectorNormalize( vec ); + // + if ( destTravelTime < 400 ) { + if ( dist < destTravelDist ) { + invalidRoute = qtrue; + break; + } + if ( DotProduct( destVec, vec ) < 0.2 ) { + invalidRoute = qtrue; + break; + } + } else { + if ( dist < destTravelDist * 0.7 ) { + invalidRoute = qtrue; + break; + } + } + // + // check the directions to make sure we're not trying to run through them + if ( j > 0 ) { + if ( DotProduct( vec, lastVec ) < 0.2 ) { + invalidRoute = qtrue; + break; + } + } else if ( DotProduct( destVec, vec ) < 0.2 ) { + invalidRoute = qtrue; + break; + } + // + VectorCopy( vec, lastVec ); + } + // + // if this area isn't in the visible list for the enemy's area, it's a good hiding spot + if ( !( travChild = AAS_RT_GetChild( pathArea ) ) ) { + invalidRoute = qtrue; + break; + } + if ( !destVisLookup[rt->parentLinks[travChild->startParentLinks].parent] ) { + // success ? + if ( !botimport.AICast_VisibleFromPos( destpos, destnum, ( *aasworld ).areas[pathArea].center, srcnum, qfalse ) ) { + // SUCESS !! + travParent = &rt->parents[rt->parentLinks[travChild->startParentLinks].parent]; + break; + } + } else { + // if we weren't visible when starting, make sure we don't move into their view + if ( !startVisible ) { //botimport.AICast_VisibleFromPos( destpos, destnum, reachability[firstreach + route->reachable_index].end, srcnum, qfalse )) { + invalidRoute = qtrue; + break; + } + } + // + // if this is the travParent, then stop checking + if ( pathArea == travParent->areanum ) { + invalidRoute = qtrue; // we didn't find a hiding spot + break; + } + } // end for areas in route + // + // if the route is invalid, skip this travParent + if ( invalidRoute ) { + continue; + } + } + // + // now last of all, check that this area is a safe hiding spot +// if (botimport.AICast_VisibleFromPos( destpos, destnum, (*aasworld).areas[travParent->areanum].center, srcnum, qfalse )) { +// continue; +// } + // + // we've found a good hiding spot, so use it + VectorCopy( ( *aasworld ).areas[travParent->areanum].center, returnPos ); + bestTravelTime = elapsedTravelTime; + // + if ( thisTravelTime < 300 ) { + botimport.Print( PRT_MESSAGE, "Fuzzy RT HidePos: %i ms\n", pretime + Sys_MilliSeconds() ); + return qtrue; + } + } + // + // did we find something? + if ( bestTravelTime < MAX_HIDE_TRAVELTIME ) { + botimport.Print( PRT_MESSAGE, "Fuzzy RT HidePos: %i ms\n", pretime + Sys_MilliSeconds() ); + return qtrue; + } + // + // couldn't find anything + botimport.Print( PRT_MESSAGE, "Fuzzy RT HidePos FAILED: %i ms\n", pretime + Sys_MilliSeconds() ); + return qfalse; +#endif +} + +/* +================= +AAS_RT_GetReachabilityIndex +================= +*/ +int AAS_RT_GetReachabilityIndex( int areanum, int reachIndex ) { +// return (*aasworld).areasettings[areanum].firstreachablearea + reachIndex; + return reachIndex; +} diff --git a/Projects/Android/jni/rtcw/src/botlib/be_aas_routetable.h b/Projects/Android/jni/rtcw/src/botlib/be_aas_routetable.h new file mode 100644 index 0000000..dd69ac1 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/botlib/be_aas_routetable.h @@ -0,0 +1,171 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +//=========================================================================== +// +// Name: be_aas_routetable.h +// Function: Area Awareness System, Route-table defines +// Programmer: Ridah +// Tab Size: 3 +//=========================================================================== + +#ifndef RT_DEFINED + +#define RT_DEFINED + +#define RTBID ( ( 'B' << 24 ) + ( 'T' << 16 ) + ( 'R' << 8 ) + 'X' ) +#define RTBVERSION 17 + +#define RTB_BADTRAVELFLAGS ( TFL_JUMPPAD | TFL_ROCKETJUMP | TFL_BFGJUMP | TFL_GRAPPLEHOOK | TFL_DOUBLEJUMP | TFL_RAMPJUMP | TFL_STRAFEJUMP | TFL_LAVA ) //----(SA) modified since slime is no longer deadly +//#define RTB_BADTRAVELFLAGS (TFL_JUMPPAD|TFL_ROCKETJUMP|TFL_BFGJUMP|TFL_GRAPPLEHOOK|TFL_DOUBLEJUMP|TFL_RAMPJUMP|TFL_STRAFEJUMP|TFL_SLIME|TFL_LAVA) + +#define MAX_VISIBLE_AREAS 1024 // going over this limit will result in excessive memory usage, try and keep RANGE low enough so this limit won't be reached +#define MAX_LOCALTRAVELTIME 60 // use this to tweak memory usage (reduces parent count, increases local count (and cpu usage) - find a balance) +#define MAX_PARENTS 8192 + +extern int disable_routetable; + +//.................................................................... +// Permanent structures (in order of highest to lowest count) +typedef struct +{ + unsigned short int reachable_index; // reachability index (from this area's first reachability link in the world) to head for to get to the destination + unsigned short int travel_time; // travel time (!) +} aas_rt_route_t; + +typedef struct +{ + unsigned short int parent; // parent we belong to + unsigned short int childIndex; // our index in the parent's list of children +// unsigned short int numRouteIndexes; +// int startRouteIndexes; +} aas_rt_parent_link_t; + +typedef struct +{ + unsigned short int areanum; +// int numLocalRoutes; +// int startLocalRoutes; +// int numParentRoutes; +// int startParentRoutes; + int numParentLinks; + int startParentLinks; +} aas_rt_child_t; + +typedef struct +{ + unsigned short int areanum; // out area number in the global list + int numParentChildren; + int startParentChildren; + int numVisibleParents; + int startVisibleParents; // list of other parents that we can see (used for fast hide/retreat checks) +// int startParentTravelTimes; +} aas_rt_parent_t; + +// this is what each aasworld attaches itself to +typedef struct +{ + unsigned short int *areaChildIndexes; // each aas area that is part of the Route-Table has a pointer here to their position in the list of children + + int numChildren; + aas_rt_child_t *children; + + int numParents; + aas_rt_parent_t *parents; + + int numParentChildren; + unsigned short int *parentChildren; + + int numVisibleParents; + unsigned short int *visibleParents; + +// int numLocalRoutes; +// aas_rt_route_t *localRoutes; // the list of routes to all other local areas + +// int numParentRoutes; +// unsigned char *parentRoutes; // reachability to each other parent, as an offset from our first reachability + + int numParentLinks; + aas_rt_parent_link_t *parentLinks; // links from each child to the parent's it belongs to + +// int numParentTravelTimes; +// unsigned short int *parentTravelTimes; // travel times between all parent areas + +// int numRouteIndexes; +// unsigned short int *routeIndexes; // each parentLink has a list within here, which + // contains the local indexes of each child that + // belongs to the parent, within the source child's + // localroutes +} aas_rt_t; + +//.................................................................... +// Temp structures used only during route-table contruction +typedef struct +{ + unsigned short int numvisible; // number of areas that are visible and within range + unsigned short int + visible[MAX_VISIBLE_AREAS]; // list of area indexes of visible and within range areas +} aas_area_buildlocalinfo_t; + +typedef struct aas_parent_link_s +{ + unsigned short int parent; // parent we belong to + unsigned short int childindex; // our index in the parent's list of children + unsigned short int *routeindexes; // for this parent link, list the children that fall under that parent, and their associated indexes in our localroutes table + struct aas_parent_link_s *next; +} aas_parent_link_t; + +typedef struct +{ + unsigned short int areanum; + unsigned short int numlocal; + aas_parent_link_t *parentlink; // linked list of parents that we belong to + aas_rt_route_t *localroutes; // the list of routes to all other local areas + aas_rt_route_t *parentroutes; // the list of routes to all other parent areas +} aas_area_childlocaldata_t; + +typedef struct +{ + unsigned short int areanum; // out area number in the global list + unsigned short int numchildren; + unsigned short int *children; + unsigned short int numVisibleParents; + unsigned short int *visibleParents; // list of other parents that we can see (used for fast hide/retreat checks) +} aas_area_parent_t; + +#endif // RT_DEFINED + +//.................................................................... + +void AAS_RT_BuildRouteTable( void ); +void AAS_RT_ShowRoute( vec3_t srcpos, int srcnum, int destnum ); +aas_rt_route_t *AAS_RT_GetRoute( int srcnum, vec3_t origin, int destnum ); +void AAS_RT_ShutdownRouteTable( void ); +qboolean AAS_RT_GetHidePos( vec3_t srcpos, int srcnum, int srcarea, vec3_t destpos, int destnum, int destarea, vec3_t returnPos ); +int AAS_RT_GetReachabilityIndex( int areanum, int reachIndex ); + diff --git a/Projects/Android/jni/rtcw/src/botlib/be_aas_sample.c b/Projects/Android/jni/rtcw/src/botlib/be_aas_sample.c new file mode 100644 index 0000000..faa3b4b --- /dev/null +++ b/Projects/Android/jni/rtcw/src/botlib/be_aas_sample.c @@ -0,0 +1,1274 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +/***************************************************************************** + * name: be_aas_sample.c + * + * desc: AAS environment sampling + * + * + *****************************************************************************/ + +#include "../game/q_shared.h" +#include "l_memory.h" +#include "l_script.h" +#include "l_precomp.h" +#include "l_struct.h" +#include "aasfile.h" +#include "../game/botlib.h" +#include "../game/be_aas.h" +#include "be_aas_funcs.h" +#include "be_aas_def.h" + +extern botlib_import_t botimport; + +//#define AAS_SAMPLE_DEBUG + +#define BBOX_NORMAL_EPSILON 0.001 + +#define ON_EPSILON 0 //0.0005 + +#define TRACEPLANE_EPSILON 0.125 + +typedef struct aas_tracestack_s +{ + vec3_t start; //start point of the piece of line to trace + vec3_t end; //end point of the piece of line to trace + int planenum; //last plane used as splitter + int nodenum; //node found after splitting with planenum +} aas_tracestack_t; + +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_PresenceTypeBoundingBox( int presencetype, vec3_t mins, vec3_t maxs ) { + int index; + //bounding box size for each presence type + vec3_t boxmins[3] = {{0, 0, 0}, {-15, -15, -24}, {-15, -15, -24}}; + vec3_t boxmaxs[3] = {{0, 0, 0}, { 15, 15, 32}, { 15, 15, 8}}; + + if ( presencetype == PRESENCE_NORMAL ) { + index = 1; + } else if ( presencetype == PRESENCE_CROUCH ) { + index = 2; + } else + { + botimport.Print( PRT_FATAL, "AAS_PresenceTypeBoundingBox: unknown presence type\n" ); + index = 2; + } //end if + VectorCopy( boxmins[index], mins ); + VectorCopy( boxmaxs[index], maxs ); +} //end of the function AAS_PresenceTypeBoundingBox +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_InitAASLinkHeap( void ) { + int i, max_aaslinks; + + max_aaslinks = ( *aasworld ).linkheapsize; + //if there's no link heap present + if ( !( *aasworld ).linkheap ) { + max_aaslinks = (int) 4096; //LibVarValue("max_aaslinks", "4096"); + if ( max_aaslinks < 0 ) { + max_aaslinks = 0; + } + ( *aasworld ).linkheapsize = max_aaslinks; + ( *aasworld ).linkheap = (aas_link_t *) GetHunkMemory( max_aaslinks * sizeof( aas_link_t ) ); + } //end if + //link the links on the heap + ( *aasworld ).linkheap[0].prev_ent = NULL; + ( *aasworld ).linkheap[0].next_ent = &( *aasworld ).linkheap[1]; + for ( i = 1; i < max_aaslinks - 1; i++ ) + { + ( *aasworld ).linkheap[i].prev_ent = &( *aasworld ).linkheap[i - 1]; + ( *aasworld ).linkheap[i].next_ent = &( *aasworld ).linkheap[i + 1]; + } //end for + ( *aasworld ).linkheap[max_aaslinks - 1].prev_ent = &( *aasworld ).linkheap[max_aaslinks - 2]; + ( *aasworld ).linkheap[max_aaslinks - 1].next_ent = NULL; + //pointer to the first free link + ( *aasworld ).freelinks = &( *aasworld ).linkheap[0]; +} //end of the function AAS_InitAASLinkHeap +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_FreeAASLinkHeap( void ) { + if ( ( *aasworld ).linkheap ) { + FreeMemory( ( *aasworld ).linkheap ); + } + ( *aasworld ).linkheap = NULL; + ( *aasworld ).linkheapsize = 0; +} //end of the function AAS_FreeAASLinkHeap +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +aas_link_t *AAS_AllocAASLink( void ) { + aas_link_t *link; + + link = ( *aasworld ).freelinks; + if ( !link ) { + botimport.Print( PRT_FATAL, "empty aas link heap\n" ); + return NULL; + } //end if + if ( ( *aasworld ).freelinks ) { + ( *aasworld ).freelinks = ( *aasworld ).freelinks->next_ent; + } + if ( ( *aasworld ).freelinks ) { + ( *aasworld ).freelinks->prev_ent = NULL; + } + return link; +} //end of the function AAS_AllocAASLink +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_DeAllocAASLink( aas_link_t *link ) { + if ( ( *aasworld ).freelinks ) { + ( *aasworld ).freelinks->prev_ent = link; + } + link->prev_ent = NULL; + link->next_ent = ( *aasworld ).freelinks; + link->prev_area = NULL; + link->next_area = NULL; + ( *aasworld ).freelinks = link; +} //end of the function AAS_DeAllocAASLink +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_InitAASLinkedEntities( void ) { + if ( !( *aasworld ).loaded ) { + return; + } + if ( ( *aasworld ).arealinkedentities ) { + FreeMemory( ( *aasworld ).arealinkedentities ); + } + ( *aasworld ).arealinkedentities = (aas_link_t **) GetClearedHunkMemory( + ( *aasworld ).numareas * sizeof( aas_link_t * ) ); +} //end of the function AAS_InitAASLinkedEntities +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_FreeAASLinkedEntities( void ) { + if ( ( *aasworld ).arealinkedentities ) { + FreeMemory( ( *aasworld ).arealinkedentities ); + } + ( *aasworld ).arealinkedentities = NULL; +} //end of the function AAS_InitAASLinkedEntities +//=========================================================================== +// returns the AAS area the point is in +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_PointAreaNum( vec3_t point ) { + int nodenum; + vec_t dist; + aas_node_t *node; + aas_plane_t *plane; + + if ( !( *aasworld ).loaded ) { + botimport.Print( PRT_ERROR, "AAS_PointAreaNum: aas not loaded\n" ); + return 0; + } //end if + + //start with node 1 because node zero is a dummy used for solid leafs + nodenum = 1; + while ( nodenum > 0 ) + { +// botimport.Print(PRT_MESSAGE, "[%d]", nodenum); +#ifdef AAS_SAMPLE_DEBUG + if ( nodenum >= ( *aasworld ).numnodes ) { + botimport.Print( PRT_ERROR, "nodenum = %d >= (*aasworld).numnodes = %d\n", nodenum, ( *aasworld ).numnodes ); + return 0; + } //end if +#endif //AAS_SAMPLE_DEBUG + node = &( *aasworld ).nodes[nodenum]; +#ifdef AAS_SAMPLE_DEBUG + if ( node->planenum < 0 || node->planenum >= ( *aasworld ).numplanes ) { + botimport.Print( PRT_ERROR, "node->planenum = %d >= (*aasworld).numplanes = %d\n", node->planenum, ( *aasworld ).numplanes ); + return 0; + } //end if +#endif //AAS_SAMPLE_DEBUG + plane = &( *aasworld ).planes[node->planenum]; + dist = DotProduct( point, plane->normal ) - plane->dist; + if ( dist > 0 ) { + nodenum = node->children[0]; + } else { nodenum = node->children[1];} + } //end while + if ( !nodenum ) { +#ifdef AAS_SAMPLE_DEBUG + botimport.Print( PRT_MESSAGE, "in solid\n" ); +#endif //AAS_SAMPLE_DEBUG + return 0; + } //end if + return -nodenum; +} //end of the function AAS_PointAreaNum +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_AreaCluster( int areanum ) { + if ( areanum <= 0 || areanum >= ( *aasworld ).numareas ) { + botimport.Print( PRT_ERROR, "AAS_AreaCluster: invalid area number\n" ); + return 0; + } //end if + return ( *aasworld ).areasettings[areanum].cluster; +} //end of the function AAS_AreaCluster +//=========================================================================== +// returns the presence types of the given area +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_AreaPresenceType( int areanum ) { + if ( !( *aasworld ).loaded ) { + return 0; + } + if ( areanum <= 0 || areanum >= ( *aasworld ).numareas ) { + botimport.Print( PRT_ERROR, "AAS_AreaPresenceType: invalid area number\n" ); + return 0; + } //end if + return ( *aasworld ).areasettings[areanum].presencetype; +} //end of the function AAS_AreaPresenceType +//=========================================================================== +// returns the presence type at the given point +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_PointPresenceType( vec3_t point ) { + int areanum; + + if ( !( *aasworld ).loaded ) { + return 0; + } + + areanum = AAS_PointAreaNum( point ); + if ( !areanum ) { + return PRESENCE_NONE; + } + return ( *aasworld ).areasettings[areanum].presencetype; +} //end of the function AAS_PointPresenceType +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +qboolean AAS_AreaEntityCollision( int areanum, vec3_t start, vec3_t end, + int presencetype, int passent, aas_trace_t *trace ) { + int collision; + vec3_t boxmins, boxmaxs; + aas_link_t *link; + bsp_trace_t bsptrace; + + AAS_PresenceTypeBoundingBox( presencetype, boxmins, boxmaxs ); + + memset( &bsptrace, 0, sizeof( bsp_trace_t ) ); //make compiler happy + //assume no collision + bsptrace.fraction = 1; + collision = qfalse; + for ( link = ( *aasworld ).arealinkedentities[areanum]; link; link = link->next_ent ) + { + //ignore the pass entity + if ( link->entnum == passent ) { + continue; + } + // + if ( AAS_EntityCollision( link->entnum, start, boxmins, boxmaxs, end, + CONTENTS_SOLID | CONTENTS_PLAYERCLIP, &bsptrace ) ) { + collision = qtrue; + } //end if + } //end for + if ( collision ) { + trace->startsolid = bsptrace.startsolid; + trace->ent = bsptrace.ent; + VectorCopy( bsptrace.endpos, trace->endpos ); + trace->area = 0; + trace->planenum = 0; + return qtrue; + } //end if + return qfalse; +} //end of the function AAS_AreaEntityCollision +//=========================================================================== +// recursive subdivision of the line by the BSP tree. +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +aas_trace_t AAS_TraceClientBBox( vec3_t start, vec3_t end, int presencetype, + int passent ) { + int side, nodenum, tmpplanenum; + float front, back, frac; + vec3_t cur_start, cur_end, cur_mid, v1, v2; + aas_tracestack_t tracestack[127]; + aas_tracestack_t *tstack_p; + aas_node_t *aasnode; + aas_plane_t *plane; + aas_trace_t trace; + + //clear the trace structure + memset( &trace, 0, sizeof( aas_trace_t ) ); + + if ( !( *aasworld ).loaded ) { + return trace; + } + + tstack_p = tracestack; + //we start with the whole line on the stack + VectorCopy( start, tstack_p->start ); + VectorCopy( end, tstack_p->end ); + tstack_p->planenum = 0; + //start with node 1 because node zero is a dummy for a solid leaf + tstack_p->nodenum = 1; //starting at the root of the tree + tstack_p++; + + while ( 1 ) + { + //pop up the stack + tstack_p--; + //if the trace stack is empty (ended up with a piece of the + //line to be traced in an area) + if ( tstack_p < tracestack ) { + tstack_p++; + //nothing was hit + trace.startsolid = qfalse; + trace.fraction = 1.0; + //endpos is the end of the line + VectorCopy( end, trace.endpos ); + //nothing hit + trace.ent = 0; + trace.area = 0; + trace.planenum = 0; + return trace; + } //end if + //number of the current node to test the line against + nodenum = tstack_p->nodenum; + //if it is an area + if ( nodenum < 0 ) { +#ifdef AAS_SAMPLE_DEBUG + if ( -nodenum > ( *aasworld ).numareasettings ) { + botimport.Print( PRT_ERROR, "AAS_TraceBoundingBox: -nodenum out of range\n" ); + return trace; + } //end if +#endif //AAS_SAMPLE_DEBUG + //botimport.Print(PRT_MESSAGE, "areanum = %d, must be %d\n", -nodenum, AAS_PointAreaNum(start)); + //if can't enter the area because it hasn't got the right presence type + if ( !( ( *aasworld ).areasettings[-nodenum].presencetype & presencetype ) ) { + //if the start point is still the initial start point + //NOTE: no need for epsilons because the points will be + //exactly the same when they're both the start point + if ( tstack_p->start[0] == start[0] && + tstack_p->start[1] == start[1] && + tstack_p->start[2] == start[2] ) { + trace.startsolid = qtrue; + trace.fraction = 0.0; + } //end if + else + { + trace.startsolid = qfalse; + VectorSubtract( end, start, v1 ); + VectorSubtract( tstack_p->start, start, v2 ); + trace.fraction = VectorLength( v2 ) / VectorNormalize( v1 ); + VectorMA( tstack_p->start, -0.125, v1, tstack_p->start ); + } //end else + VectorCopy( tstack_p->start, trace.endpos ); + trace.ent = 0; + trace.area = -nodenum; +// VectorSubtract(end, start, v1); + trace.planenum = tstack_p->planenum; + //always take the plane with normal facing towards the trace start + plane = &( *aasworld ).planes[trace.planenum]; + if ( DotProduct( v1, plane->normal ) > 0 ) { + trace.planenum ^= 1; + } + return trace; + } //end if + else + { + if ( passent >= 0 ) { + if ( AAS_AreaEntityCollision( -nodenum, tstack_p->start, + tstack_p->end, presencetype, passent, + &trace ) ) { + if ( !trace.startsolid ) { + VectorSubtract( end, start, v1 ); + VectorSubtract( trace.endpos, start, v2 ); + trace.fraction = VectorLength( v2 ) / VectorLength( v1 ); + } //end if + return trace; + } //end if + } //end if + } //end else + trace.lastarea = -nodenum; + continue; + } //end if + //if it is a solid leaf + if ( !nodenum ) { + //if the start point is still the initial start point + //NOTE: no need for epsilons because the points will be + //exactly the same when they're both the start point + if ( tstack_p->start[0] == start[0] && + tstack_p->start[1] == start[1] && + tstack_p->start[2] == start[2] ) { + trace.startsolid = qtrue; + trace.fraction = 0.0; + } //end if + else + { + trace.startsolid = qfalse; + VectorSubtract( end, start, v1 ); + VectorSubtract( tstack_p->start, start, v2 ); + trace.fraction = VectorLength( v2 ) / VectorNormalize( v1 ); + VectorMA( tstack_p->start, -0.125, v1, tstack_p->start ); + } //end else + VectorCopy( tstack_p->start, trace.endpos ); + trace.ent = 0; + trace.area = 0; //hit solid leaf +// VectorSubtract(end, start, v1); + trace.planenum = tstack_p->planenum; + //always take the plane with normal facing towards the trace start + plane = &( *aasworld ).planes[trace.planenum]; + if ( DotProduct( v1, plane->normal ) > 0 ) { + trace.planenum ^= 1; + } + return trace; + } //end if +#ifdef AAS_SAMPLE_DEBUG + if ( nodenum > ( *aasworld ).numnodes ) { + botimport.Print( PRT_ERROR, "AAS_TraceBoundingBox: nodenum out of range\n" ); + return trace; + } //end if +#endif //AAS_SAMPLE_DEBUG + //the node to test against + aasnode = &( *aasworld ).nodes[nodenum]; + //start point of current line to test against node + VectorCopy( tstack_p->start, cur_start ); + //end point of the current line to test against node + VectorCopy( tstack_p->end, cur_end ); + //the current node plane + plane = &( *aasworld ).planes[aasnode->planenum]; + + switch ( plane->type ) + {/*FIXME: wtf doesn't this work? obviously the axial node planes aren't always facing positive!!! + //check for axial planes + case PLANE_X: + { + front = cur_start[0] - plane->dist; + back = cur_end[0] - plane->dist; + break; + } //end case + case PLANE_Y: + { + front = cur_start[1] - plane->dist; + back = cur_end[1] - plane->dist; + break; + } //end case + case PLANE_Z: + { + front = cur_start[2] - plane->dist; + back = cur_end[2] - plane->dist; + break; + } //end case*/ + default: //gee it's not an axial plane + { + front = DotProduct( cur_start, plane->normal ) - plane->dist; + back = DotProduct( cur_end, plane->normal ) - plane->dist; + break; + } //end default + } //end switch + + //calculate the hitpoint with the node (split point of the line) + //put the crosspoint TRACEPLANE_EPSILON pixels on the near side + if ( front < 0 ) { + frac = ( front + TRACEPLANE_EPSILON ) / ( front - back ); + } else { frac = ( front - TRACEPLANE_EPSILON ) / ( front - back );} + //if the whole to be traced line is totally at the front of this node + //only go down the tree with the front child + if ( ( front >= -ON_EPSILON && back >= -ON_EPSILON ) ) { + //keep the current start and end point on the stack + //and go down the tree with the front child + tstack_p->nodenum = aasnode->children[0]; + tstack_p++; + if ( tstack_p >= &tracestack[127] ) { + botimport.Print( PRT_ERROR, "AAS_TraceBoundingBox: stack overflow\n" ); + return trace; + } //end if + } //end if + //if the whole to be traced line is totally at the back of this node + //only go down the tree with the back child + else if ( ( front < ON_EPSILON && back < ON_EPSILON ) ) { + //keep the current start and end point on the stack + //and go down the tree with the back child + tstack_p->nodenum = aasnode->children[1]; + tstack_p++; + if ( tstack_p >= &tracestack[127] ) { + botimport.Print( PRT_ERROR, "AAS_TraceBoundingBox: stack overflow\n" ); + return trace; + } //end if + } //end if + //go down the tree both at the front and back of the node + else + { + tmpplanenum = tstack_p->planenum; + // + if ( frac < 0 ) { + frac = 0.001; //0 + } else if ( frac > 1 ) { + frac = 0.999; //1 + } + //frac = front / (front-back); + // + cur_mid[0] = cur_start[0] + ( cur_end[0] - cur_start[0] ) * frac; + cur_mid[1] = cur_start[1] + ( cur_end[1] - cur_start[1] ) * frac; + cur_mid[2] = cur_start[2] + ( cur_end[2] - cur_start[2] ) * frac; + +// AAS_DrawPlaneCross(cur_mid, plane->normal, plane->dist, plane->type, LINECOLOR_RED); + //side the front part of the line is on + side = front < 0; + //first put the end part of the line on the stack (back side) + VectorCopy( cur_mid, tstack_p->start ); + //not necesary to store because still on stack + //VectorCopy(cur_end, tstack_p->end); + tstack_p->planenum = aasnode->planenum; + tstack_p->nodenum = aasnode->children[!side]; + tstack_p++; + if ( tstack_p >= &tracestack[127] ) { + botimport.Print( PRT_ERROR, "AAS_TraceBoundingBox: stack overflow\n" ); + return trace; + } //end if + //now put the part near the start of the line on the stack so we will + //continue with thats part first. This way we'll find the first + //hit of the bbox + VectorCopy( cur_start, tstack_p->start ); + VectorCopy( cur_mid, tstack_p->end ); + tstack_p->planenum = tmpplanenum; + tstack_p->nodenum = aasnode->children[side]; + tstack_p++; + if ( tstack_p >= &tracestack[127] ) { + botimport.Print( PRT_ERROR, "AAS_TraceBoundingBox: stack overflow\n" ); + return trace; + } //end if + } //end else + } //end while +// return trace; +} //end of the function AAS_TraceClientBBox +//=========================================================================== +// recursive subdivision of the line by the BSP tree. +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_TraceAreas( vec3_t start, vec3_t end, int *areas, vec3_t *points, int maxareas ) { + int side, nodenum, tmpplanenum; + int numareas; + float front, back, frac; + vec3_t cur_start, cur_end, cur_mid; + aas_tracestack_t tracestack[127]; + aas_tracestack_t *tstack_p; + aas_node_t *aasnode; + aas_plane_t *plane; + + numareas = 0; + areas[0] = 0; + if ( !( *aasworld ).loaded ) { + return numareas; + } + + tstack_p = tracestack; + //we start with the whole line on the stack + VectorCopy( start, tstack_p->start ); + VectorCopy( end, tstack_p->end ); + tstack_p->planenum = 0; + //start with node 1 because node zero is a dummy for a solid leaf + tstack_p->nodenum = 1; //starting at the root of the tree + tstack_p++; + + while ( 1 ) + { + //pop up the stack + tstack_p--; + //if the trace stack is empty (ended up with a piece of the + //line to be traced in an area) + if ( tstack_p < tracestack ) { + return numareas; + } //end if + //number of the current node to test the line against + nodenum = tstack_p->nodenum; + //if it is an area + if ( nodenum < 0 ) { +#ifdef AAS_SAMPLE_DEBUG + if ( -nodenum > ( *aasworld ).numareasettings ) { + botimport.Print( PRT_ERROR, "AAS_TraceAreas: -nodenum = %d out of range\n", -nodenum ); + return numareas; + } //end if +#endif //AAS_SAMPLE_DEBUG + //botimport.Print(PRT_MESSAGE, "areanum = %d, must be %d\n", -nodenum, AAS_PointAreaNum(start)); + areas[numareas] = -nodenum; + if ( points ) { + VectorCopy( tstack_p->start, points[numareas] ); + } + numareas++; + if ( numareas >= maxareas ) { + return numareas; + } + continue; + } //end if + //if it is a solid leaf + if ( !nodenum ) { + continue; + } //end if +#ifdef AAS_SAMPLE_DEBUG + if ( nodenum > ( *aasworld ).numnodes ) { + botimport.Print( PRT_ERROR, "AAS_TraceAreas: nodenum out of range\n" ); + return numareas; + } //end if +#endif //AAS_SAMPLE_DEBUG + //the node to test against + aasnode = &( *aasworld ).nodes[nodenum]; + //start point of current line to test against node + VectorCopy( tstack_p->start, cur_start ); + //end point of the current line to test against node + VectorCopy( tstack_p->end, cur_end ); + //the current node plane + plane = &( *aasworld ).planes[aasnode->planenum]; + + switch ( plane->type ) + {/*FIXME: wtf doesn't this work? obviously the node planes aren't always facing positive!!! + //check for axial planes + case PLANE_X: + { + front = cur_start[0] - plane->dist; + back = cur_end[0] - plane->dist; + break; + } //end case + case PLANE_Y: + { + front = cur_start[1] - plane->dist; + back = cur_end[1] - plane->dist; + break; + } //end case + case PLANE_Z: + { + front = cur_start[2] - plane->dist; + back = cur_end[2] - plane->dist; + break; + } //end case*/ + default: //gee it's not an axial plane + { + front = DotProduct( cur_start, plane->normal ) - plane->dist; + back = DotProduct( cur_end, plane->normal ) - plane->dist; + break; + } //end default + } //end switch + + //if the whole to be traced line is totally at the front of this node + //only go down the tree with the front child + if ( front > 0 && back > 0 ) { + //keep the current start and end point on the stack + //and go down the tree with the front child + tstack_p->nodenum = aasnode->children[0]; + tstack_p++; + if ( tstack_p >= &tracestack[127] ) { + botimport.Print( PRT_ERROR, "AAS_TraceAreas: stack overflow\n" ); + return numareas; + } //end if + } //end if + //if the whole to be traced line is totally at the back of this node + //only go down the tree with the back child + else if ( front <= 0 && back <= 0 ) { + //keep the current start and end point on the stack + //and go down the tree with the back child + tstack_p->nodenum = aasnode->children[1]; + tstack_p++; + if ( tstack_p >= &tracestack[127] ) { + botimport.Print( PRT_ERROR, "AAS_TraceAreas: stack overflow\n" ); + return numareas; + } //end if + } //end if + //go down the tree both at the front and back of the node + else + { + tmpplanenum = tstack_p->planenum; + //calculate the hitpoint with the node (split point of the line) + //put the crosspoint TRACEPLANE_EPSILON pixels on the near side + if ( front < 0 ) { + frac = ( front ) / ( front - back ); + } else { frac = ( front ) / ( front - back );} + if ( frac < 0 ) { + frac = 0; + } else if ( frac > 1 ) { + frac = 1; + } + //frac = front / (front-back); + // + cur_mid[0] = cur_start[0] + ( cur_end[0] - cur_start[0] ) * frac; + cur_mid[1] = cur_start[1] + ( cur_end[1] - cur_start[1] ) * frac; + cur_mid[2] = cur_start[2] + ( cur_end[2] - cur_start[2] ) * frac; + +// AAS_DrawPlaneCross(cur_mid, plane->normal, plane->dist, plane->type, LINECOLOR_RED); + //side the front part of the line is on + side = front < 0; + //first put the end part of the line on the stack (back side) + VectorCopy( cur_mid, tstack_p->start ); + //not necesary to store because still on stack + //VectorCopy(cur_end, tstack_p->end); + tstack_p->planenum = aasnode->planenum; + tstack_p->nodenum = aasnode->children[!side]; + tstack_p++; + if ( tstack_p >= &tracestack[127] ) { + botimport.Print( PRT_ERROR, "AAS_TraceAreas: stack overflow\n" ); + return numareas; + } //end if + //now put the part near the start of the line on the stack so we will + //continue with thats part first. This way we'll find the first + //hit of the bbox + VectorCopy( cur_start, tstack_p->start ); + VectorCopy( cur_mid, tstack_p->end ); + tstack_p->planenum = tmpplanenum; + tstack_p->nodenum = aasnode->children[side]; + tstack_p++; + if ( tstack_p >= &tracestack[127] ) { + botimport.Print( PRT_ERROR, "AAS_TraceAreas: stack overflow\n" ); + return numareas; + } //end if + } //end else + } //end while +// return numareas; +} //end of the function AAS_TraceAreas +//=========================================================================== +// a simple cross product +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +// void AAS_OrthogonalToVectors(vec3_t v1, vec3_t v2, vec3_t res) +#define AAS_OrthogonalToVectors( v1, v2, res ) \ + ( res )[0] = ( ( v1 )[1] * ( v2 )[2] ) - ( ( v1 )[2] * ( v2 )[1] ); \ + ( res )[1] = ( ( v1 )[2] * ( v2 )[0] ) - ( ( v1 )[0] * ( v2 )[2] ); \ + ( res )[2] = ( ( v1 )[0] * ( v2 )[1] ) - ( ( v1 )[1] * ( v2 )[0] ); +//=========================================================================== +// tests if the given point is within the face boundaries +// +// Parameter: face : face to test if the point is in it +// pnormal : normal of the plane to use for the face +// point : point to test if inside face boundaries +// Returns: qtrue if the point is within the face boundaries +// Changes Globals: - +//=========================================================================== +qboolean AAS_InsideFace( aas_face_t *face, vec3_t pnormal, vec3_t point, float epsilon ) { + int i, firstvertex, edgenum; + vec3_t v0; + vec3_t edgevec, pointvec, sepnormal; + aas_edge_t *edge; +#ifdef AAS_SAMPLE_DEBUG + int lastvertex = 0; +#endif //AAS_SAMPLE_DEBUG + + if ( !( *aasworld ).loaded ) { + return qfalse; + } + + for ( i = 0; i < face->numedges; i++ ) + { + edgenum = ( *aasworld ).edgeindex[face->firstedge + i]; + edge = &( *aasworld ).edges[abs( edgenum )]; + //get the first vertex of the edge + firstvertex = edgenum < 0; + VectorCopy( ( *aasworld ).vertexes[edge->v[firstvertex]], v0 ); + //edge vector + VectorSubtract( ( *aasworld ).vertexes[edge->v[!firstvertex]], v0, edgevec ); + // +#ifdef AAS_SAMPLE_DEBUG + if ( lastvertex && lastvertex != edge->v[firstvertex] ) { + botimport.Print( PRT_MESSAGE, "winding not counter clockwise\n" ); + } //end if + lastvertex = edge->v[!firstvertex]; +#endif //AAS_SAMPLE_DEBUG + //vector from first edge point to point possible in face + VectorSubtract( point, v0, pointvec ); + //get a vector pointing inside the face orthogonal to both the + //edge vector and the normal vector of the plane the face is in + //this vector defines a plane through the origin (first vertex of + //edge) and through both the edge vector and the normal vector + //of the plane + AAS_OrthogonalToVectors( edgevec, pnormal, sepnormal ); + //check on wich side of the above plane the point is + //this is done by checking the sign of the dot product of the + //vector orthogonal vector from above and the vector from the + //origin (first vertex of edge) to the point + //if the dotproduct is smaller than zero the point is outside the face + if ( DotProduct( pointvec, sepnormal ) < -epsilon ) { + return qfalse; + } + } //end for + return qtrue; +} //end of the function AAS_InsideFace +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +qboolean AAS_PointInsideFace( int facenum, vec3_t point, float epsilon ) { + int i, firstvertex, edgenum; + vec_t *v1, *v2; + vec3_t edgevec, pointvec, sepnormal; + aas_edge_t *edge; + aas_plane_t *plane; + aas_face_t *face; + + if ( !( *aasworld ).loaded ) { + return qfalse; + } + + face = &( *aasworld ).faces[facenum]; + plane = &( *aasworld ).planes[face->planenum]; + // + for ( i = 0; i < face->numedges; i++ ) + { + edgenum = ( *aasworld ).edgeindex[face->firstedge + i]; + edge = &( *aasworld ).edges[abs( edgenum )]; + //get the first vertex of the edge + firstvertex = edgenum < 0; + v1 = ( *aasworld ).vertexes[edge->v[firstvertex]]; + v2 = ( *aasworld ).vertexes[edge->v[!firstvertex]]; + //edge vector + VectorSubtract( v2, v1, edgevec ); + //vector from first edge point to point possible in face + VectorSubtract( point, v1, pointvec ); + // + CrossProduct( edgevec, plane->normal, sepnormal ); + // + if ( DotProduct( pointvec, sepnormal ) < -epsilon ) { + return qfalse; + } + } //end for + return qtrue; +} //end of the function AAS_PointInsideFace +//=========================================================================== +// returns the ground face the given point is above in the given area +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +aas_face_t *AAS_AreaGroundFace( int areanum, vec3_t point ) { + int i, facenum; + vec3_t up = {0, 0, 1}; + vec3_t normal; + aas_area_t *area; + aas_face_t *face; + + if ( !( *aasworld ).loaded ) { + return NULL; + } + + area = &( *aasworld ).areas[areanum]; + for ( i = 0; i < area->numfaces; i++ ) + { + facenum = ( *aasworld ).faceindex[area->firstface + i]; + face = &( *aasworld ).faces[abs( facenum )]; + //if this is a ground face + if ( face->faceflags & FACE_GROUND ) { + //get the up or down normal + if ( ( *aasworld ).planes[face->planenum].normal[2] < 0 ) { + VectorNegate( up, normal ); + } else { VectorCopy( up, normal );} + //check if the point is in the face + if ( AAS_InsideFace( face, normal, point, 0.01 ) ) { + return face; + } + } //end if + } //end for + return NULL; +} //end of the function AAS_AreaGroundFace +//=========================================================================== +// returns the face the trace end position is situated in +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_FacePlane( int facenum, vec3_t normal, float *dist ) { + aas_plane_t *plane; + + plane = &( *aasworld ).planes[( *aasworld ).faces[facenum].planenum]; + VectorCopy( plane->normal, normal ); + *dist = plane->dist; +} //end of the function AAS_FacePlane +//=========================================================================== +// returns the face the trace end position is situated in +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +aas_face_t *AAS_TraceEndFace( aas_trace_t *trace ) { + int i, facenum; + aas_area_t *area; + aas_face_t *face, *firstface = NULL; + + if ( !( *aasworld ).loaded ) { + return NULL; + } + + //if started in solid no face was hit + if ( trace->startsolid ) { + return NULL; + } + //trace->lastarea is the last area the trace was in + area = &( *aasworld ).areas[trace->lastarea]; + //check which face the trace.endpos was in + for ( i = 0; i < area->numfaces; i++ ) + { + facenum = ( *aasworld ).faceindex[area->firstface + i]; + face = &( *aasworld ).faces[abs( facenum )]; + //if the face is in the same plane as the trace end point + if ( ( face->planenum & ~1 ) == ( trace->planenum & ~1 ) ) { + //firstface is used for optimization, if theres only one + //face in the plane then it has to be the good one + //if there are more faces in the same plane then always + //check the one with the fewest edges first +/* if (firstface) + { + if (firstface->numedges < face->numedges) + { + if (AAS_InsideFace(firstface, + (*aasworld).planes[face->planenum].normal, trace->endpos)) + { + return firstface; + } //end if + firstface = face; + } //end if + else + { + if (AAS_InsideFace(face, + (*aasworld).planes[face->planenum].normal, trace->endpos)) + { + return face; + } //end if + } //end else + } //end if + else + { + firstface = face; + } //end else*/ + if ( AAS_InsideFace( face, + ( *aasworld ).planes[face->planenum].normal, trace->endpos, 0.01 ) ) { + return face; + } + } //end if + } //end for + return firstface; +} //end of the function AAS_TraceEndFace +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_BoxOnPlaneSide2( vec3_t absmins, vec3_t absmaxs, aas_plane_t *p ) { + int i, sides; + float dist1, dist2; + vec3_t corners[2]; + + for ( i = 0; i < 3; i++ ) + { + if ( p->normal[i] < 0 ) { + corners[0][i] = absmins[i]; + corners[1][i] = absmaxs[i]; + } //end if + else + { + corners[1][i] = absmins[i]; + corners[0][i] = absmaxs[i]; + } //end else + } //end for + dist1 = DotProduct( p->normal, corners[0] ) - p->dist; + dist2 = DotProduct( p->normal, corners[1] ) - p->dist; + sides = 0; + if ( dist1 >= 0 ) { + sides = 1; + } + if ( dist2 < 0 ) { + sides |= 2; + } + + return sides; +} //end of the function AAS_BoxOnPlaneSide2 +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +//int AAS_BoxOnPlaneSide(vec3_t absmins, vec3_t absmaxs, aas_plane_t *p) +#define AAS_BoxOnPlaneSide( absmins, absmaxs, p ) ( \ + ( ( p )->type < 3 ) ? \ + ( \ + ( ( p )->dist <= ( absmins )[( p )->type] ) ? \ + ( \ + 1 \ + ) \ + : \ + ( \ + ( ( p )->dist >= ( absmaxs )[( p )->type] ) ? \ + ( \ + 2 \ + ) \ + : \ + ( \ + 3 \ + ) \ + ) \ + ) \ + : \ + ( \ + AAS_BoxOnPlaneSide2( ( absmins ), ( absmaxs ), ( p ) ) \ + ) \ + ) //end of the function AAS_BoxOnPlaneSide +//=========================================================================== +// remove the links to this entity from all areas +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_UnlinkFromAreas( aas_link_t *areas ) { + aas_link_t *link, *nextlink; + + for ( link = areas; link; link = nextlink ) + { + //next area the entity is linked in + nextlink = link->next_area; + //remove the entity from the linked list of this area + if ( link->prev_ent ) { + link->prev_ent->next_ent = link->next_ent; + } else { ( *aasworld ).arealinkedentities[link->areanum] = link->next_ent;} + if ( link->next_ent ) { + link->next_ent->prev_ent = link->prev_ent; + } + //deallocate the link structure + AAS_DeAllocAASLink( link ); + } //end for +} //end of the function AAS_UnlinkFromAreas +//=========================================================================== +// link the entity to the areas the bounding box is totally or partly +// situated in. This is done with recursion down the tree using the +// bounding box to test for plane sides +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== + +typedef struct +{ + int nodenum; //node found after splitting +} aas_linkstack_t; + +aas_link_t *AAS_AASLinkEntity( vec3_t absmins, vec3_t absmaxs, int entnum ) { + int side, nodenum; + aas_linkstack_t linkstack[128]; + aas_linkstack_t *lstack_p; + aas_node_t *aasnode; + aas_plane_t *plane; + aas_link_t *link, *areas; + + if ( !( *aasworld ).loaded ) { + botimport.Print( PRT_ERROR, "AAS_LinkEntity: aas not loaded\n" ); + return NULL; + } //end if + + areas = NULL; + // + lstack_p = linkstack; + //we start with the whole line on the stack + //start with node 1 because node zero is a dummy used for solid leafs + lstack_p->nodenum = 1; //starting at the root of the tree + lstack_p++; + + while ( 1 ) + { + //pop up the stack + lstack_p--; + //if the trace stack is empty (ended up with a piece of the + //line to be traced in an area) + if ( lstack_p < linkstack ) { + break; + } + //number of the current node to test the line against + nodenum = lstack_p->nodenum; + //if it is an area + if ( nodenum < 0 ) { + //NOTE: the entity might have already been linked into this area + // because several node children can point to the same area + for ( link = ( *aasworld ).arealinkedentities[-nodenum]; link; link = link->next_ent ) + { + if ( link->entnum == entnum ) { + break; + } + } //end for + if ( link ) { + continue; + } + // + link = AAS_AllocAASLink(); + if ( !link ) { + return areas; + } + link->entnum = entnum; + link->areanum = -nodenum; + //put the link into the double linked area list of the entity + link->prev_area = NULL; + link->next_area = areas; + if ( areas ) { + areas->prev_area = link; + } + areas = link; + //put the link into the double linked entity list of the area + link->prev_ent = NULL; + link->next_ent = ( *aasworld ).arealinkedentities[-nodenum]; + if ( ( *aasworld ).arealinkedentities[-nodenum] ) { + ( *aasworld ).arealinkedentities[-nodenum]->prev_ent = link; + } + ( *aasworld ).arealinkedentities[-nodenum] = link; + // + continue; + } //end if + //if solid leaf + if ( !nodenum ) { + continue; + } + //the node to test against + aasnode = &( *aasworld ).nodes[nodenum]; + //the current node plane + plane = &( *aasworld ).planes[aasnode->planenum]; + //get the side(s) the box is situated relative to the plane + side = AAS_BoxOnPlaneSide2( absmins, absmaxs, plane ); + //if on the front side of the node + if ( side & 1 ) { + lstack_p->nodenum = aasnode->children[0]; + lstack_p++; + } //end if + if ( lstack_p >= &linkstack[127] ) { + botimport.Print( PRT_ERROR, "AAS_LinkEntity: stack overflow\n" ); + break; + } //end if + //if on the back side of the node + if ( side & 2 ) { + lstack_p->nodenum = aasnode->children[1]; + lstack_p++; + } //end if + if ( lstack_p >= &linkstack[127] ) { + botimport.Print( PRT_ERROR, "AAS_LinkEntity: stack overflow\n" ); + break; + } //end if + } //end while + return areas; +} //end of the function AAS_AASLinkEntity +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +aas_link_t *AAS_LinkEntityClientBBox( vec3_t absmins, vec3_t absmaxs, int entnum, int presencetype ) { + vec3_t mins, maxs; + vec3_t newabsmins, newabsmaxs; + + AAS_PresenceTypeBoundingBox( presencetype, mins, maxs ); + VectorSubtract( absmins, maxs, newabsmins ); + VectorSubtract( absmaxs, mins, newabsmaxs ); + //relink the entity + return AAS_AASLinkEntity( newabsmins, newabsmaxs, entnum ); +} //end of the function AAS_LinkEntityClientBBox +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +aas_plane_t *AAS_PlaneFromNum( int planenum ) { + if ( !( *aasworld ).loaded ) { + return 0; + } + + return &( *aasworld ).planes[planenum]; +} //end of the function AAS_PlaneFromNum + +/* +============= +AAS_BBoxAreas +============= +*/ +int AAS_BBoxAreas( vec3_t absmins, vec3_t absmaxs, int *areas, int maxareas ) { + aas_link_t *linkedareas, *link; + int num; + + linkedareas = AAS_AASLinkEntity( absmins, absmaxs, -1 ); + num = 0; + for ( link = linkedareas; link; link = link->next_area ) + { + areas[num] = link->areanum; + num++; + if ( num >= maxareas ) { + break; + } + } //end for + AAS_UnlinkFromAreas( linkedareas ); + return num; +} //end of the function AAS_BBoxAreas diff --git a/Projects/Android/jni/rtcw/src/botlib/be_aas_sample.h b/Projects/Android/jni/rtcw/src/botlib/be_aas_sample.h new file mode 100644 index 0000000..2a3b764 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/botlib/be_aas_sample.h @@ -0,0 +1,70 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +/***************************************************************************** + * name: be_aas_sample.h + * + * desc: AAS + * + * + *****************************************************************************/ + +#ifdef AASINTERN +void AAS_InitAASLinkHeap( void ); +void AAS_InitAASLinkedEntities( void ); +void AAS_FreeAASLinkHeap( void ); +void AAS_FreeAASLinkedEntities( void ); +aas_face_t *AAS_AreaGroundFace( int areanum, vec3_t point ); +aas_face_t *AAS_TraceEndFace( aas_trace_t *trace ); +aas_plane_t *AAS_PlaneFromNum( int planenum ); +aas_link_t *AAS_AASLinkEntity( vec3_t absmins, vec3_t absmaxs, int entnum ); +aas_link_t *AAS_LinkEntityClientBBox( vec3_t absmins, vec3_t absmaxs, int entnum, int presencetype ); +qboolean AAS_PointInsideFace( int facenum, vec3_t point, float epsilon ); +qboolean AAS_InsideFace( aas_face_t *face, vec3_t pnormal, vec3_t point, float epsilon ); +void AAS_UnlinkFromAreas( aas_link_t *areas ); +#endif //AASINTERN + +//returns the mins and maxs of the bounding box for the given presence type +void AAS_PresenceTypeBoundingBox( int presencetype, vec3_t mins, vec3_t maxs ); +//returns the cluster the area is in (negative portal number if the area is a portal) +int AAS_AreaCluster( int areanum ); +//returns the presence type(s) of the area +int AAS_AreaPresenceType( int areanum ); +//returns the presence type(s) at the given point +int AAS_PointPresenceType( vec3_t point ); +//returns the result of the trace of a client bbox +aas_trace_t AAS_TraceClientBBox( vec3_t start, vec3_t end, int presencetype, int passent ); +//stores the areas the trace went through and returns the number of passed areas +int AAS_TraceAreas( vec3_t start, vec3_t end, int *areas, vec3_t *points, int maxareas ); +//returns the area the point is in +int AAS_PointAreaNum( vec3_t point ); +//returns the plane the given face is in +void AAS_FacePlane( int facenum, vec3_t normal, float *dist ); + +int AAS_BBoxAreas( vec3_t absmins, vec3_t absmaxs, int *areas, int maxareas ); diff --git a/Projects/Android/jni/rtcw/src/botlib/be_ai_char.c b/Projects/Android/jni/rtcw/src/botlib/be_ai_char.c new file mode 100644 index 0000000..6fcf53b --- /dev/null +++ b/Projects/Android/jni/rtcw/src/botlib/be_ai_char.c @@ -0,0 +1,765 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +/***************************************************************************** + * name: be_ai_char.c + * + * desc: bot characters + * + * + *****************************************************************************/ + +#include "../game/q_shared.h" +#include "l_log.h" +#include "l_memory.h" +#include "l_utils.h" +#include "l_script.h" +#include "l_precomp.h" +#include "l_struct.h" +#include "l_libvar.h" +#include "aasfile.h" +#include "../game/botlib.h" +#include "../game/be_aas.h" +#include "be_aas_funcs.h" +#include "be_interface.h" +#include "../game/be_ai_char.h" + +#define MAX_CHARACTERISTICS 80 + +#define CT_INTEGER 1 +#define CT_FLOAT 2 +#define CT_STRING 3 + +#define DEFAULT_CHARACTER "bots/default_c.c" + +//characteristic value +union cvalue +{ + int integer; + float _float; + char *string; +}; +//a characteristic +typedef struct bot_characteristic_s +{ + char type; //characteristic type + union cvalue value; //characteristic value +} bot_characteristic_t; + +//a bot character +typedef struct bot_character_s +{ + char filename[MAX_QPATH]; + int skill; + bot_characteristic_t c[1]; //variable sized +} bot_character_t; + +bot_character_t *botcharacters[MAX_CLIENTS + 1]; + +//======================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//======================================================================== +bot_character_t *BotCharacterFromHandle( int handle ) { + if ( handle <= 0 || handle > MAX_CLIENTS ) { + botimport.Print( PRT_FATAL, "character handle %d out of range\n", handle ); + return NULL; + } //end if + if ( !botcharacters[handle] ) { + botimport.Print( PRT_FATAL, "invalid character %d\n", handle ); + return NULL; + } //end if + return botcharacters[handle]; +} //end of the function BotCharacterFromHandle +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void BotDumpCharacter( bot_character_t *ch ) { + int i; + + Log_Write( "%s", ch->filename ); + Log_Write( "skill %d\n", ch->skill ); + Log_Write( "{\n" ); + for ( i = 0; i < MAX_CHARACTERISTICS; i++ ) + { + switch ( ch->c[i].type ) + { + case CT_INTEGER: Log_Write( " %4d %d\n", i, ch->c[i].value.integer ); break; + case CT_FLOAT: Log_Write( " %4d %f\n", i, ch->c[i].value._float ); break; + case CT_STRING: Log_Write( " %4d %s\n", i, ch->c[i].value.string ); break; + } //end case + } //end for + Log_Write( "}\n" ); +} //end of the function BotDumpCharacter +//======================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//======================================================================== +void BotFreeCharacterStrings( bot_character_t *ch ) { + int i; + + for ( i = 0; i < MAX_CHARACTERISTICS; i++ ) + { + if ( ch->c[i].type == CT_STRING ) { + FreeMemory( ch->c[i].value.string ); + } //end if + } //end for +} //end of the function BotFreeCharacterStrings +//======================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//======================================================================== +void BotFreeCharacter2( int handle ) { + if ( handle <= 0 || handle > MAX_CLIENTS ) { + botimport.Print( PRT_FATAL, "character handle %d out of range\n", handle ); + return; + } //end if + if ( !botcharacters[handle] ) { + botimport.Print( PRT_FATAL, "invalid character %d\n", handle ); + return; + } //end if + BotFreeCharacterStrings( botcharacters[handle] ); + FreeMemory( botcharacters[handle] ); + botcharacters[handle] = NULL; +} //end of the function BotFreeCharacter2 +//======================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//======================================================================== +void BotFreeCharacter( int handle ) { + if ( !LibVarGetValue( "bot_reloadcharacters" ) ) { + return; + } + BotFreeCharacter2( handle ); +} //end of the function BotFreeCharacter +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void BotDefaultCharacteristics( bot_character_t *ch, bot_character_t *defaultch ) { + int i; + + for ( i = 0; i < MAX_CHARACTERISTICS; i++ ) + { + if ( ch->c[i].type ) { + continue; + } + // + if ( defaultch->c[i].type == CT_FLOAT ) { + ch->c[i].type = CT_FLOAT; + ch->c[i].value._float = defaultch->c[i].value._float; + } //end if + else if ( defaultch->c[i].type == CT_INTEGER ) { + ch->c[i].type = CT_INTEGER; + ch->c[i].value.integer = defaultch->c[i].value.integer; + } //end else if + else if ( defaultch->c[i].type == CT_STRING ) { + ch->c[i].type = CT_STRING; + ch->c[i].value.string = (char *) GetMemory( strlen( defaultch->c[i].value.string ) + 1 ); + strcpy( ch->c[i].value.string, defaultch->c[i].value.string ); + } //end else if + } //end for +} //end of the function BotDefaultCharacteristics +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +bot_character_t *BotLoadCharacterFromFile( char *charfile, int skill ) { + int indent, index, foundcharacter; + bot_character_t *ch; + source_t *source; + token_t token; + + foundcharacter = qfalse; + //a bot character is parsed in two phases + source = LoadSourceFile( charfile ); + if ( !source ) { + botimport.Print( PRT_ERROR, "counldn't load %s\n", charfile ); + return NULL; + } //end if + ch = (bot_character_t *) GetClearedMemory( sizeof( bot_character_t ) + + MAX_CHARACTERISTICS * sizeof( bot_characteristic_t ) ); + strcpy( ch->filename, charfile ); + while ( PC_ReadToken( source, &token ) ) + { + if ( !strcmp( token.string, "skill" ) ) { + if ( !PC_ExpectTokenType( source, TT_NUMBER, 0, &token ) ) { + FreeSource( source ); + BotFreeCharacterStrings( ch ); + FreeMemory( ch ); + return NULL; + } //end if + if ( !PC_ExpectTokenString( source, "{" ) ) { + FreeSource( source ); + BotFreeCharacterStrings( ch ); + FreeMemory( ch ); + return NULL; + } //end if + //if it's the correct skill + if ( skill < 0 || token.intvalue == skill ) { + foundcharacter = qtrue; + ch->skill = token.intvalue; + while ( PC_ExpectAnyToken( source, &token ) ) + { + if ( !strcmp( token.string, "}" ) ) { + break; + } + if ( token.type != TT_NUMBER || !( token.subtype & TT_INTEGER ) ) { + SourceError( source, "expected integer index, found %s\n", token.string ); + FreeSource( source ); + BotFreeCharacterStrings( ch ); + FreeMemory( ch ); + return NULL; + } //end if + index = token.intvalue; + if ( index < 0 || index > MAX_CHARACTERISTICS ) { + SourceError( source, "characteristic index out of range [0, %d]\n", MAX_CHARACTERISTICS ); + FreeSource( source ); + BotFreeCharacterStrings( ch ); + FreeMemory( ch ); + return NULL; + } //end if + if ( ch->c[index].type ) { + SourceError( source, "characteristic %d already initialized\n", index ); + FreeSource( source ); + BotFreeCharacterStrings( ch ); + FreeMemory( ch ); + return NULL; + } //end if + if ( !PC_ExpectAnyToken( source, &token ) ) { + FreeSource( source ); + BotFreeCharacterStrings( ch ); + FreeMemory( ch ); + return NULL; + } //end if + if ( token.type == TT_NUMBER ) { + if ( token.subtype & TT_FLOAT ) { + ch->c[index].value._float = token.floatvalue; + ch->c[index].type = CT_FLOAT; + } //end if + else + { + ch->c[index].value.integer = token.intvalue; + ch->c[index].type = CT_INTEGER; + } //end else + } //end if + else if ( token.type == TT_STRING ) { + StripDoubleQuotes( token.string ); + ch->c[index].value.string = GetMemory( strlen( token.string ) + 1 ); + strcpy( ch->c[index].value.string, token.string ); + ch->c[index].type = CT_STRING; + } //end else if + else + { + SourceError( source, "expected integer, float or string, found %s\n", token.string ); + FreeSource( source ); + BotFreeCharacterStrings( ch ); + FreeMemory( ch ); + return NULL; + } //end else + } //end if + break; + } //end if + else + { + indent = 1; + while ( indent ) + { + if ( !PC_ExpectAnyToken( source, &token ) ) { + FreeSource( source ); + BotFreeCharacterStrings( ch ); + FreeMemory( ch ); + return NULL; + } //end if + if ( !strcmp( token.string, "{" ) ) { + indent++; + } else if ( !strcmp( token.string, "}" ) ) { + indent--; + } + } //end while + } //end else + } //end if + else + { + SourceError( source, "unknown definition %s\n", token.string ); + FreeSource( source ); + BotFreeCharacterStrings( ch ); + FreeMemory( ch ); + return NULL; + } //end else + } //end while + FreeSource( source ); + // + if ( !foundcharacter ) { + BotFreeCharacterStrings( ch ); + FreeMemory( ch ); + return NULL; + } //end if + return ch; +} //end of the function BotLoadCharacterFromFile +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int BotFindCachedCharacter( char *charfile, int skill ) { + int handle; + + for ( handle = 1; handle <= MAX_CLIENTS; handle++ ) + { + if ( !botcharacters[handle] ) { + continue; + } + if ( strcmp( botcharacters[handle]->filename, charfile ) == 0 && + ( skill < 0 || botcharacters[handle]->skill == skill ) ) { + return handle; + } //end if + } //end for + return 0; +} //end of the function BotFindCachedCharacter +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int BotLoadCachedCharacter( char *charfile, int skill, int reload ) { + int handle, cachedhandle; + bot_character_t *ch = NULL; +#ifdef DEBUG + int starttime; + + starttime = Sys_MilliSeconds(); +#endif //DEBUG + + //find a free spot for a character + for ( handle = 1; handle <= MAX_CLIENTS; handle++ ) + { + if ( !botcharacters[handle] ) { + break; + } + } //end for + if ( handle > MAX_CLIENTS ) { + return 0; + } + //try to load a cached character with the given skill + if ( !reload ) { + cachedhandle = BotFindCachedCharacter( charfile, skill ); + if ( cachedhandle ) { + botimport.Print( PRT_MESSAGE, "loaded cached skill %d from %s\n", skill, charfile ); + return cachedhandle; + } //end if + } //end else + //try to load the character with the given skill + ch = BotLoadCharacterFromFile( charfile, skill ); + if ( ch ) { + botcharacters[handle] = ch; + // + botimport.Print( PRT_MESSAGE, "loaded skill %d from %s\n", skill, charfile ); +#ifdef DEBUG + if ( bot_developer ) { + botimport.Print( PRT_MESSAGE, "skill %d loaded in %d msec from %s\n", skill, Sys_MilliSeconds() - starttime, charfile ); + } //end if +#endif //DEBUG + return handle; + } //end if + // + botimport.Print( PRT_WARNING, "couldn't find skill %d in %s\n", skill, charfile ); + // + if ( !reload ) { + //try to load a cached default character with the given skill + cachedhandle = BotFindCachedCharacter( "bots/default_c.c", skill ); + if ( cachedhandle ) { + botimport.Print( PRT_MESSAGE, "loaded cached default skill %d from %s\n", skill, charfile ); + return cachedhandle; + } //end if + } //end if + //try to load the default character with the given skill + ch = BotLoadCharacterFromFile( DEFAULT_CHARACTER, skill ); + if ( ch ) { + botcharacters[handle] = ch; + botimport.Print( PRT_MESSAGE, "loaded default skill %d from %s\n", skill, charfile ); + return handle; + } //end if + // + if ( !reload ) { + //try to load a cached character with any skill + cachedhandle = BotFindCachedCharacter( charfile, -1 ); + if ( cachedhandle ) { + botimport.Print( PRT_MESSAGE, "loaded cached skill %d from %s\n", botcharacters[cachedhandle]->skill, charfile ); + return cachedhandle; + } //end if + } //end if + //try to load a character with any skill + ch = BotLoadCharacterFromFile( charfile, -1 ); + if ( ch ) { + botcharacters[handle] = ch; + botimport.Print( PRT_MESSAGE, "loaded skill %d from %s\n", ch->skill, charfile ); + return handle; + } //end if + // + if ( !reload ) { + //try to load a cached character with any skill + cachedhandle = BotFindCachedCharacter( DEFAULT_CHARACTER, -1 ); + if ( cachedhandle ) { + botimport.Print( PRT_MESSAGE, "loaded cached default skill %d from %s\n", botcharacters[cachedhandle]->skill, charfile ); + return cachedhandle; + } //end if + } //end if + //try to load a character with any skill + ch = BotLoadCharacterFromFile( DEFAULT_CHARACTER, -1 ); + if ( ch ) { + botcharacters[handle] = ch; + botimport.Print( PRT_MESSAGE, "loaded default skill %d from %s\n", ch->skill, charfile ); + return handle; + } //end if + // + botimport.Print( PRT_WARNING, "couldn't load any skill from %s\n", charfile ); + //couldn't load any character + return 0; +} //end of the function BotLoadCachedCharacter +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int BotLoadCharacterSkill( char *charfile, int skill ) { + int ch, defaultch; + + defaultch = BotLoadCachedCharacter( DEFAULT_CHARACTER, skill, qfalse ); + ch = BotLoadCachedCharacter( charfile, skill, LibVarGetValue( "bot_reloadcharacters" ) ); + + if ( defaultch && ch ) { + BotDefaultCharacteristics( botcharacters[ch], botcharacters[defaultch] ); + } //end if + + return ch; +} //end of the function BotLoadCharacterSkill +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int BotInterpolateCharacters( int handle1, int handle2, int desiredskill ) { + bot_character_t *ch1, *ch2, *out; + int i, handle; + float scale; + + ch1 = BotCharacterFromHandle( handle1 ); + ch2 = BotCharacterFromHandle( handle2 ); + if ( !ch1 || !ch2 ) { + return 0; + } + //find a free spot for a character + for ( handle = 1; handle <= MAX_CLIENTS; handle++ ) + { + if ( !botcharacters[handle] ) { + break; + } + } //end for + if ( handle > MAX_CLIENTS ) { + return 0; + } + out = (bot_character_t *) GetClearedMemory( sizeof( bot_character_t ) + + MAX_CHARACTERISTICS * sizeof( bot_characteristic_t ) ); + out->skill = desiredskill; + strcpy( out->filename, ch1->filename ); + botcharacters[handle] = out; + + scale = (float) ( desiredskill - 1 ) / ( ch2->skill - ch1->skill ); + for ( i = 0; i < MAX_CHARACTERISTICS; i++ ) + { + // + if ( ch1->c[i].type == CT_FLOAT && ch2->c[i].type == CT_FLOAT ) { + out->c[i].type = CT_FLOAT; + out->c[i].value._float = ch1->c[i].value._float + + ( ch2->c[i].value._float - ch1->c[i].value._float ) * scale; + } //end if + else if ( ch1->c[i].type == CT_INTEGER ) { + out->c[i].type = CT_INTEGER; + out->c[i].value.integer = ch1->c[i].value.integer; + } //end else if + else if ( ch1->c[i].type == CT_STRING ) { + out->c[i].type = CT_STRING; + out->c[i].value.string = (char *) GetMemory( strlen( ch1->c[i].value.string ) + 1 ); + strcpy( out->c[i].value.string, ch1->c[i].value.string ); + } //end else if + } //end for + return handle; +} //end of the function BotInterpolateCharacters +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int BotLoadCharacter( char *charfile, int skill ) { + int skill1, skill4, handle; + + //make sure the skill is in the valid range + if ( skill < 1 ) { + skill = 1; + } else if ( skill > 5 ) { + skill = 5; + } + //skill 1, 4 and 5 should be available in the character files + if ( skill == 1 || skill == 4 || skill == 5 ) { + return BotLoadCharacterSkill( charfile, skill ); + } //end if + //check if there's a cached skill 2 or 3 + handle = BotFindCachedCharacter( charfile, skill ); + if ( handle ) { + botimport.Print( PRT_MESSAGE, "loaded cached skill %d from %s\n", skill, charfile ); + return handle; + } //end if + //load skill 1 and 4 + skill1 = BotLoadCharacterSkill( charfile, 1 ); + if ( !skill1 ) { + return 0; + } + skill4 = BotLoadCharacterSkill( charfile, 4 ); + if ( !skill4 ) { + return skill1; + } + //interpolate between 1 and 4 to create skill 2 or 3 + handle = BotInterpolateCharacters( skill1, skill4, skill ); + if ( !handle ) { + return 0; + } + //write the character to the log file + BotDumpCharacter( botcharacters[handle] ); + // + return handle; +} //end of the function BotLoadCharacter +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int CheckCharacteristicIndex( int character, int index ) { + bot_character_t *ch; + + ch = BotCharacterFromHandle( character ); + if ( !ch ) { + return qfalse; + } + if ( index < 0 || index >= MAX_CHARACTERISTICS ) { + botimport.Print( PRT_ERROR, "characteristic %d does not exist\n", index ); + return qfalse; + } //end if + if ( !ch->c[index].type ) { + botimport.Print( PRT_ERROR, "characteristic %d is not initialized\n", index ); + return qfalse; + } //end if + return qtrue; +} //end of the function CheckCharacteristicIndex +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +float Characteristic_Float( int character, int index ) { + bot_character_t *ch; + + ch = BotCharacterFromHandle( character ); + if ( !ch ) { + return 0; + } + //check if the index is in range + if ( !CheckCharacteristicIndex( character, index ) ) { + return 0; + } + //an integer will be converted to a float + if ( ch->c[index].type == CT_INTEGER ) { + return (float) ch->c[index].value.integer; + } //end if + //floats are just returned + else if ( ch->c[index].type == CT_FLOAT ) { + return ch->c[index].value._float; + } //end else if + //cannot convert a string pointer to a float + else + { + botimport.Print( PRT_ERROR, "characteristic %d is not a float\n", index ); + return 0; + } //end else if +// return 0; +} //end of the function Characteristic_Float +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +float Characteristic_BFloat( int character, int index, float min, float max ) { + float value; + bot_character_t *ch; + + ch = BotCharacterFromHandle( character ); + if ( !ch ) { + return 0; + } + if ( min > max ) { + botimport.Print( PRT_ERROR, "cannot bound characteristic %d between %f and %f\n", index, min, max ); + return 0; + } //end if + value = Characteristic_Float( character, index ); + if ( value < min ) { + return min; + } + if ( value > max ) { + return max; + } + return value; +} //end of the function Characteristic_BFloat +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int Characteristic_Integer( int character, int index ) { + bot_character_t *ch; + + ch = BotCharacterFromHandle( character ); + if ( !ch ) { + return 0; + } + //check if the index is in range + if ( !CheckCharacteristicIndex( character, index ) ) { + return 0; + } + //an integer will just be returned + if ( ch->c[index].type == CT_INTEGER ) { + return ch->c[index].value.integer; + } //end if + //floats are casted to integers + else if ( ch->c[index].type == CT_FLOAT ) { + return (int) ch->c[index].value._float; + } //end else if + else + { + botimport.Print( PRT_ERROR, "characteristic %d is not a integer\n", index ); + return 0; + } //end else if +// return 0; +} //end of the function Characteristic_Integer +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int Characteristic_BInteger( int character, int index, int min, int max ) { + int value; + bot_character_t *ch; + + ch = BotCharacterFromHandle( character ); + if ( !ch ) { + return 0; + } + if ( min > max ) { + botimport.Print( PRT_ERROR, "cannot bound characteristic %d between %d and %d\n", index, min, max ); + return 0; + } //end if + value = Characteristic_Integer( character, index ); + if ( value < min ) { + return min; + } + if ( value > max ) { + return max; + } + return value; +} //end of the function Characteristic_BInteger +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void Characteristic_String( int character, int index, char *buf, int size ) { + bot_character_t *ch; + + ch = BotCharacterFromHandle( character ); + if ( !ch ) { + return; + } + //check if the index is in range + if ( !CheckCharacteristicIndex( character, index ) ) { + return; + } + //an integer will be converted to a float + if ( ch->c[index].type == CT_STRING ) { + strncpy( buf, ch->c[index].value.string, size - 1 ); + buf[size - 1] = '\0'; + return; + } //end if + else + { + botimport.Print( PRT_ERROR, "characteristic %d is not a string\n", index ); + return; + } //end else if + return; +} //end of the function Characteristic_String +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void BotShutdownCharacters( void ) { + int handle; + + for ( handle = 1; handle <= MAX_CLIENTS; handle++ ) + { + if ( botcharacters[handle] ) { + BotFreeCharacter2( handle ); + } //end if + } //end for +} //end of the function BotShutdownCharacters diff --git a/Projects/Android/jni/rtcw/src/botlib/be_ai_chat.c b/Projects/Android/jni/rtcw/src/botlib/be_ai_chat.c new file mode 100644 index 0000000..73c5900 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/botlib/be_ai_chat.c @@ -0,0 +1,2883 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +/***************************************************************************** + * name: be_ai_chat.c + * + * desc: bot chat AI + * + * + *****************************************************************************/ + +#include "../game/q_shared.h" +//#include "../server/server.h" +#include "l_memory.h" +#include "l_libvar.h" +#include "l_script.h" +#include "l_precomp.h" +#include "l_struct.h" +#include "l_utils.h" +#include "l_log.h" +#include "aasfile.h" +#include "../game/botlib.h" +#include "../game/be_aas.h" +#include "be_aas_funcs.h" +#include "be_interface.h" +#include "../game/be_ea.h" +#include "../game/be_ai_chat.h" + + +//escape character +#define ESCAPE_CHAR 0x01 //'_' +// +// "hi ", people, " ", 0, " entered the game" +//becomes: +// "hi _rpeople_ _v0_ entered the game" +// + +//match piece types +#define MT_VARIABLE 1 //variable match piece +#define MT_STRING 2 //string match piece +//reply chat key flags +#define RCKFL_AND 1 //key must be present +#define RCKFL_NOT 2 //key must be absent +#define RCKFL_NAME 4 //name of bot must be present +#define RCKFL_STRING 8 //key is a string +#define RCKFL_VARIABLES 16 //key is a match template +#define RCKFL_BOTNAMES 32 //key is a series of botnames +#define RCKFL_GENDERFEMALE 64 //bot must be female +#define RCKFL_GENDERMALE 128 //bot must be male +#define RCKFL_GENDERLESS 256 //bot must be genderless +//time to ignore a chat message after using it +#define CHATMESSAGE_RECENTTIME 20 + +//the actuall chat messages +typedef struct bot_chatmessage_s +{ + char *chatmessage; //chat message string + float time; //last time used + struct bot_chatmessage_s *next; //next chat message in a list +} bot_chatmessage_t; +//bot chat type with chat lines +typedef struct bot_chattype_s +{ + char name[MAX_CHATTYPE_NAME]; + int numchatmessages; + bot_chatmessage_t *firstchatmessage; + struct bot_chattype_s *next; +} bot_chattype_t; +//bot chat lines +typedef struct bot_chat_s +{ + bot_chattype_t *types; +} bot_chat_t; + +//random string +typedef struct bot_randomstring_s +{ + char *string; + struct bot_randomstring_s *next; +} bot_randomstring_t; +//list with random strings +typedef struct bot_randomlist_s +{ + char *string; + int numstrings; + bot_randomstring_t *firstrandomstring; + struct bot_randomlist_s *next; +} bot_randomlist_t; + +//synonym +typedef struct bot_synonym_s +{ + char *string; + float weight; + struct bot_synonym_s *next; +} bot_synonym_t; +//list with synonyms +typedef struct bot_synonymlist_s +{ + unsigned long int context; + float totalweight; + bot_synonym_t *firstsynonym; + struct bot_synonymlist_s *next; +} bot_synonymlist_t; + +//fixed match string +typedef struct bot_matchstring_s +{ + char *string; + struct bot_matchstring_s *next; +} bot_matchstring_t; + +//piece of a match template +typedef struct bot_matchpiece_s +{ + int type; + bot_matchstring_t *firststring; + int variable; + struct bot_matchpiece_s *next; +} bot_matchpiece_t; +//match template +typedef struct bot_matchtemplate_s +{ + unsigned long int context; + int type; + int subtype; + bot_matchpiece_t *first; + struct bot_matchtemplate_s *next; +} bot_matchtemplate_t; + +//reply chat key +typedef struct bot_replychatkey_s +{ + int flags; + char *string; + bot_matchpiece_t *match; + struct bot_replychatkey_s *next; +} bot_replychatkey_t; +//reply chat +typedef struct bot_replychat_s +{ + bot_replychatkey_t *keys; + float priority; + int numchatmessages; + bot_chatmessage_t *firstchatmessage; + struct bot_replychat_s *next; +} bot_replychat_t; + +//string list +typedef struct bot_stringlist_s +{ + char *string; + struct bot_stringlist_s *next; +} bot_stringlist_t; + +//chat state of a bot +typedef struct bot_chatstate_s +{ + int gender; //0=it, 1=female, 2=male + char name[32]; //name of the bot + char chatmessage[MAX_MESSAGE_SIZE]; + int handle; + //the console messages visible to the bot + bot_consolemessage_t *firstmessage; //first message is the first typed message + bot_consolemessage_t *lastmessage; //last message is the last typed message, bottom of console + //number of console messages stored in the state + int numconsolemessages; + //the bot chat lines + bot_chat_t *chat; +} bot_chatstate_t; + +typedef struct { + bot_chat_t *chat; + int inuse; + char filename[MAX_QPATH]; + char chatname[MAX_QPATH]; +} bot_ichatdata_t; + +bot_ichatdata_t ichatdata[MAX_CLIENTS]; + +bot_chatstate_t *botchatstates[MAX_CLIENTS + 1]; +//console message heap +bot_consolemessage_t *consolemessageheap = NULL; +bot_consolemessage_t *freeconsolemessages = NULL; +//list with match strings +bot_matchtemplate_t *matchtemplates = NULL; +//list with synonyms +bot_synonymlist_t *synonyms = NULL; +//list with random strings +bot_randomlist_t *randomstrings = NULL; +//reply chats +bot_replychat_t *replychats = NULL; + +//======================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//======================================================================== +bot_chatstate_t *BotChatStateFromHandle( int handle ) { + if ( handle <= 0 || handle > MAX_CLIENTS ) { + botimport.Print( PRT_FATAL, "chat state handle %d out of range\n", handle ); + return NULL; + } //end if + if ( !botchatstates[handle] ) { + botimport.Print( PRT_FATAL, "invalid chat state %d\n", handle ); + return NULL; + } //end if + return botchatstates[handle]; +} //end of the function BotChatStateFromHandle +//=========================================================================== +// initialize the heap with unused console messages +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void InitConsoleMessageHeap( void ) { + int i, max_messages; + + if ( consolemessageheap ) { + FreeMemory( consolemessageheap ); + } + // + max_messages = (int) LibVarValue( "max_messages", "1024" ); + consolemessageheap = (bot_consolemessage_t *) GetClearedHunkMemory( max_messages * + sizeof( bot_consolemessage_t ) ); + consolemessageheap[0].prev = NULL; + consolemessageheap[0].next = &consolemessageheap[1]; + for ( i = 1; i < max_messages - 1; i++ ) + { + consolemessageheap[i].prev = &consolemessageheap[i - 1]; + consolemessageheap[i].next = &consolemessageheap[i + 1]; + } //end for + consolemessageheap[max_messages - 1].prev = &consolemessageheap[max_messages - 2]; + consolemessageheap[max_messages - 1].next = NULL; + //pointer to the free console messages + freeconsolemessages = consolemessageheap; +} //end of the function InitConsoleMessageHeap +//=========================================================================== +// allocate one console message from the heap +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +bot_consolemessage_t *AllocConsoleMessage( void ) { + bot_consolemessage_t *message; + message = freeconsolemessages; + if ( freeconsolemessages ) { + freeconsolemessages = freeconsolemessages->next; + } + if ( freeconsolemessages ) { + freeconsolemessages->prev = NULL; + } + return message; +} //end of the function AllocConsoleMessage +//=========================================================================== +// deallocate one console message from the heap +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void FreeConsoleMessage( bot_consolemessage_t *message ) { + if ( freeconsolemessages ) { + freeconsolemessages->prev = message; + } + message->prev = NULL; + message->next = freeconsolemessages; + freeconsolemessages = message; +} //end of the function FreeConsoleMessage +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void BotRemoveConsoleMessage( int chatstate, int handle ) { + bot_consolemessage_t *m, *nextm; + bot_chatstate_t *cs; + + cs = BotChatStateFromHandle( chatstate ); + if ( !cs ) { + return; + } + + for ( m = cs->firstmessage; m; m = nextm ) + { + nextm = m->next; + if ( m->handle == handle ) { + if ( m->next ) { + m->next->prev = m->prev; + } else { cs->lastmessage = m->prev;} + if ( m->prev ) { + m->prev->next = m->next; + } else { cs->firstmessage = m->next;} + + FreeConsoleMessage( m ); + cs->numconsolemessages--; + break; + } //end if + } //end for +} //end of the function BotRemoveConsoleMessage +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void BotQueueConsoleMessage( int chatstate, int type, char *message ) { + bot_consolemessage_t *m; + bot_chatstate_t *cs; + + cs = BotChatStateFromHandle( chatstate ); + if ( !cs ) { + return; + } + + m = AllocConsoleMessage(); + if ( !m ) { + botimport.Print( PRT_ERROR, "empty console message heap\n" ); + return; + } //end if + cs->handle++; + if ( cs->handle <= 0 || cs->handle > 8192 ) { + cs->handle = 1; + } + m->handle = cs->handle; + m->time = AAS_Time(); + m->type = type; + strncpy( m->message, message, MAX_MESSAGE_SIZE ); + m->next = NULL; + if ( cs->lastmessage ) { + cs->lastmessage->next = m; + m->prev = cs->lastmessage; + cs->lastmessage = m; + } //end if + else + { + cs->lastmessage = m; + cs->firstmessage = m; + m->prev = NULL; + } //end if + cs->numconsolemessages++; +} //end of the function BotQueueConsoleMessage +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int BotNextConsoleMessage( int chatstate, bot_consolemessage_t *cm ) { + bot_chatstate_t *cs; + + cs = BotChatStateFromHandle( chatstate ); + if ( !cs ) { + return 0; + } + if ( cs->firstmessage ) { + memcpy( cm, cs->firstmessage, sizeof( bot_consolemessage_t ) ); + cm->next = cm->prev = NULL; + return cm->handle; + } //end if + return 0; +} //end of the function BotConsoleMessage +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int BotNumConsoleMessages( int chatstate ) { + bot_chatstate_t *cs; + + cs = BotChatStateFromHandle( chatstate ); + if ( !cs ) { + return 0; + } + return cs->numconsolemessages; +} //end of the function BotNumConsoleMessages +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int IsWhiteSpace( char c ) { + if ( ( c >= 'a' && c <= 'z' ) + || ( c >= 'A' && c <= 'Z' ) + || ( c >= '0' && c <= '9' ) + || c == '(' || c == ')' + || c == '?' || c == '\'' + || c == ':' || c == ',' + || c == '[' || c == ']' + || c == '-' || c == '_' + || c == '+' || c == '=' ) { + return qfalse; + } + return qtrue; +} //end of the function IsWhiteSpace +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void BotRemoveTildes( char *message ) { + int i; + + //remove all tildes from the chat message + for ( i = 0; message[i]; i++ ) + { + if ( message[i] == '~' ) { + memmove( &message[i], &message[i + 1], strlen( &message[i + 1] ) + 1 ); + } //end if + } //end for +} //end of the function BotRemoveTildes +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void UnifyWhiteSpaces( char *string ) { + char *ptr, *oldptr; + + for ( ptr = oldptr = string; *ptr; oldptr = ptr ) + { + while ( *ptr && IsWhiteSpace( *ptr ) ) ptr++; + if ( ptr > oldptr ) { + //if not at the start and not at the end of the string + //write only one space + if ( oldptr > string && *ptr ) { + *oldptr++ = ' '; + } + //remove all other white spaces + if ( ptr > oldptr ) { + memmove( oldptr, ptr, strlen( ptr ) + 1 ); + } + } //end if + while ( *ptr && !IsWhiteSpace( *ptr ) ) ptr++; + } //end while +} //end of the function UnifyWhiteSpaces +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int StringContains( char *str1, char *str2, int casesensitive ) { + int len, i, j, index; + + if ( str1 == NULL || str2 == NULL ) { + return -1; + } + + len = strlen( str1 ) - strlen( str2 ); + index = 0; + for ( i = 0; i <= len; i++, str1++, index++ ) + { + for ( j = 0; str2[j]; j++ ) + { + if ( casesensitive ) { + if ( str1[j] != str2[j] ) { + break; + } + } //end if + else + { + if ( toupper( str1[j] ) != toupper( str2[j] ) ) { + break; + } + } //end else + } //end for + if ( !str2[j] ) { + return index; + } + } //end for + return -1; +} //end of the function StringContains +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +char *StringContainsWord( char *str1, char *str2, int casesensitive ) { + int len, i, j; + + len = strlen( str1 ) - strlen( str2 ); + for ( i = 0; i <= len; i++, str1++ ) + { + //if not at the start of the string + if ( i ) { + //skip to the start of the next word + while ( *str1 && *str1 != ' ' ) str1++; + if ( !*str1 ) { + break; + } + str1++; + } //end for + //compare the word + for ( j = 0; str2[j]; j++ ) + { + if ( casesensitive ) { + if ( str1[j] != str2[j] ) { + break; + } + } //end if + else + { + if ( toupper( str1[j] ) != toupper( str2[j] ) ) { + break; + } + } //end else + } //end for + //if there was a word match + if ( !str2[j] ) { + //if the first string has an end of word + if ( !str1[j] || str1[j] == ' ' ) { + return str1; + } + } //end if + } //end for + return NULL; +} //end of the function StringContainsWord +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void StringReplaceWords( char *string, char *synonym, char *replacement ) { + char *str, *str2; + + //find the synonym in the string + str = StringContainsWord( string, synonym, qfalse ); + //if the synonym occured in the string + while ( str ) + { + //if the synonym isn't part of the replacement which is already in the string + //usefull for abreviations + str2 = StringContainsWord( string, replacement, qfalse ); + while ( str2 ) + { + if ( str2 <= str && str < str2 + strlen( replacement ) ) { + break; + } + str2 = StringContainsWord( str2 + 1, replacement, qfalse ); + } //end while + if ( !str2 ) { + memmove( str + strlen( replacement ), str + strlen( synonym ), strlen( str + strlen( synonym ) ) + 1 ); + //append the synonum replacement + memcpy( str, replacement, strlen( replacement ) ); + } //end if + //find the next synonym in the string + str = StringContainsWord( str + strlen( replacement ), synonym, qfalse ); + } //end if +} //end of the function StringReplaceWords +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void BotDumpSynonymList( bot_synonymlist_t *synlist ) { + FILE *fp; + bot_synonymlist_t *syn; + bot_synonym_t *synonym; + + fp = Log_FilePointer(); + if ( !fp ) { + return; + } + for ( syn = synlist; syn; syn = syn->next ) + { + fprintf( fp, "%d : [", (int)syn->context ); + for ( synonym = syn->firstsynonym; synonym; synonym = synonym->next ) + { + fprintf( fp, "(\"%s\", %1.2f)", synonym->string, synonym->weight ); + if ( synonym->next ) { + fprintf( fp, ", " ); + } + } //end for + fprintf( fp, "]\n" ); + } //end for +} //end of the function BotDumpSynonymList +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +bot_synonymlist_t *BotLoadSynonyms( char *filename ) { + int pass, size, contextlevel, numsynonyms; + unsigned long int context, contextstack[32]; + char *ptr = NULL; + source_t *source; + token_t token; + bot_synonymlist_t *synlist, *lastsyn, *syn; + bot_synonym_t *synonym, *lastsynonym; + + size = 0; + synlist = NULL; //make compiler happy + syn = NULL; //make compiler happy + synonym = NULL; //make compiler happy + //the synonyms are parsed in two phases + for ( pass = 0; pass < 2; pass++ ) + { + // + if ( pass && size ) { + ptr = (char *) GetClearedHunkMemory( size ); + } + // + source = LoadSourceFile( filename ); + if ( !source ) { + botimport.Print( PRT_ERROR, "counldn't load %s\n", filename ); + return NULL; + } //end if + // + context = 0; + contextlevel = 0; + synlist = NULL; //list synonyms + lastsyn = NULL; //last synonym in the list + // + while ( PC_ReadToken( source, &token ) ) + { + if ( token.type == TT_NUMBER ) { + context |= token.intvalue; + contextstack[contextlevel] = token.intvalue; + contextlevel++; + if ( contextlevel >= 32 ) { + SourceError( source, "more than 32 context levels" ); + FreeSource( source ); + return NULL; + } //end if + if ( !PC_ExpectTokenString( source, "{" ) ) { + FreeSource( source ); + return NULL; + } //end if + } //end if + else if ( token.type == TT_PUNCTUATION ) { + if ( !strcmp( token.string, "}" ) ) { + contextlevel--; + if ( contextlevel < 0 ) { + SourceError( source, "too many }" ); + FreeSource( source ); + return NULL; + } //end if + context &= ~contextstack[contextlevel]; + } //end if + else if ( !strcmp( token.string, "[" ) ) { + size += sizeof( bot_synonymlist_t ); + if ( pass ) { + syn = (bot_synonymlist_t *) ptr; + ptr += sizeof( bot_synonymlist_t ); + syn->context = context; + syn->firstsynonym = NULL; + syn->next = NULL; + if ( lastsyn ) { + lastsyn->next = syn; + } else { synlist = syn;} + lastsyn = syn; + } //end if + numsynonyms = 0; + lastsynonym = NULL; + while ( 1 ) + { + if ( !PC_ExpectTokenString( source, "(" ) || + !PC_ExpectTokenType( source, TT_STRING, 0, &token ) ) { + FreeSource( source ); + return NULL; + } //end if + StripDoubleQuotes( token.string ); + if ( strlen( token.string ) <= 0 ) { + SourceError( source, "empty string", token.string ); + FreeSource( source ); + return NULL; + } //end if + size += sizeof( bot_synonym_t ) + strlen( token.string ) + 1; + if ( pass ) { + synonym = (bot_synonym_t *) ptr; + ptr += sizeof( bot_synonym_t ); + synonym->string = ptr; + ptr += strlen( token.string ) + 1; + strcpy( synonym->string, token.string ); + // + if ( lastsynonym ) { + lastsynonym->next = synonym; + } else { syn->firstsynonym = synonym;} + lastsynonym = synonym; + } //end if + numsynonyms++; + if ( !PC_ExpectTokenString( source, "," ) || + !PC_ExpectTokenType( source, TT_NUMBER, 0, &token ) || + !PC_ExpectTokenString( source, ")" ) ) { + FreeSource( source ); + return NULL; + } //end if + if ( pass ) { + synonym->weight = token.floatvalue; + syn->totalweight += synonym->weight; + } //end if + if ( PC_CheckTokenString( source, "]" ) ) { + break; + } + if ( !PC_ExpectTokenString( source, "," ) ) { + FreeSource( source ); + return NULL; + } //end if + } //end while + if ( numsynonyms < 2 ) { + SourceError( source, "synonym must have at least two entries\n" ); + FreeSource( source ); + return NULL; + } //end if + } //end else + else + { + SourceError( source, "unexpected %s", token.string ); + FreeSource( source ); + return NULL; + } //end if + } //end else if + } //end while + // + FreeSource( source ); + // + if ( contextlevel > 0 ) { + SourceError( source, "missing }" ); + return NULL; + } //end if + } //end for + botimport.Print( PRT_MESSAGE, "loaded %s\n", filename ); + // + //BotDumpSynonymList(synlist); + // + return synlist; +} //end of the function BotLoadSynonyms +//=========================================================================== +// replace all the synonyms in the string +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void BotReplaceSynonyms( char *string, unsigned long int context ) { + bot_synonymlist_t *syn; + bot_synonym_t *synonym; + + for ( syn = synonyms; syn; syn = syn->next ) + { + if ( !( syn->context & context ) ) { + continue; + } + for ( synonym = syn->firstsynonym->next; synonym; synonym = synonym->next ) + { + StringReplaceWords( string, synonym->string, syn->firstsynonym->string ); + } //end for + } //end for +} //end of the function BotReplaceSynonyms +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void BotReplaceWeightedSynonyms( char *string, unsigned long int context ) { + bot_synonymlist_t *syn; + bot_synonym_t *synonym, *replacement; + float weight, curweight; + + for ( syn = synonyms; syn; syn = syn->next ) + { + if ( !( syn->context & context ) ) { + continue; + } + //choose a weighted random replacement synonym + weight = random() * syn->totalweight; + if ( !weight ) { + continue; + } + curweight = 0; + for ( replacement = syn->firstsynonym; replacement; replacement = replacement->next ) + { + curweight += replacement->weight; + if ( weight < curweight ) { + break; + } + } //end for + if ( !replacement ) { + continue; + } + //replace all synonyms with the replacement + for ( synonym = syn->firstsynonym; synonym; synonym = synonym->next ) + { + if ( synonym == replacement ) { + continue; + } + StringReplaceWords( string, synonym->string, replacement->string ); + } //end for + } //end for +} //end of the function BotReplaceWeightedSynonyms +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void BotReplaceReplySynonyms( char *string, unsigned long int context ) { + char *str1, *str2, *replacement; + bot_synonymlist_t *syn; + bot_synonym_t *synonym; + + for ( str1 = string; *str1; ) + { + //go to the start of the next word + while ( *str1 && *str1 <= ' ' ) str1++; + if ( !*str1 ) { + break; + } + // + for ( syn = synonyms; syn; syn = syn->next ) + { + if ( !( syn->context & context ) ) { + continue; + } + for ( synonym = syn->firstsynonym->next; synonym; synonym = synonym->next ) + { + str2 = synonym->string; + //if the synonym is not at the front of the string continue + str2 = StringContainsWord( str1, synonym->string, qfalse ); + if ( !str2 || str2 != str1 ) { + continue; + } + // + replacement = syn->firstsynonym->string; + //if the replacement IS in front of the string continue + str2 = StringContainsWord( str1, replacement, qfalse ); + if ( str2 && str2 == str1 ) { + continue; + } + // + memmove( str1 + strlen( replacement ), str1 + strlen( synonym->string ), + strlen( str1 + strlen( synonym->string ) ) + 1 ); + //append the synonum replacement + memcpy( str1, replacement, strlen( replacement ) ); + // + break; + } //end for + //if a synonym has been replaced + if ( synonym ) { + break; + } + } //end for + //skip over this word + while ( *str1 && *str1 > ' ' ) str1++; + if ( !*str1 ) { + break; + } + } //end while +} //end of the function BotReplaceReplySynonyms +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int BotLoadChatMessage( source_t *source, char *chatmessagestring ) { + char *ptr; + token_t token; + + ptr = chatmessagestring; + *ptr = 0; + // + while ( 1 ) + { + if ( !PC_ExpectAnyToken( source, &token ) ) { + return qfalse; + } + //fixed string + if ( token.type == TT_STRING ) { + StripDoubleQuotes( token.string ); + if ( strlen( ptr ) + strlen( token.string ) + 1 > MAX_MESSAGE_SIZE ) { + SourceError( source, "chat message too long\n" ); + return qfalse; + } //end if + strcat( ptr, token.string ); + } //end else if + //variable string + else if ( token.type == TT_NUMBER && ( token.subtype & TT_INTEGER ) ) { + if ( strlen( ptr ) + 7 > MAX_MESSAGE_SIZE ) { + SourceError( source, "chat message too long\n" ); + return qfalse; + } //end if + sprintf( &ptr[strlen( ptr )], "%cv%d%c", ESCAPE_CHAR, (int)token.intvalue, ESCAPE_CHAR ); + } //end if + //random string + else if ( token.type == TT_NAME ) { + if ( strlen( ptr ) + 7 > MAX_MESSAGE_SIZE ) { + SourceError( source, "chat message too long\n" ); + return qfalse; + } //end if + sprintf( &ptr[strlen( ptr )], "%cr%s%c", ESCAPE_CHAR, token.string, ESCAPE_CHAR ); + } //end else if + else + { + SourceError( source, "unknown message component %s\n", token.string ); + return qfalse; + } //end else + if ( PC_CheckTokenString( source, ";" ) ) { + break; + } + if ( !PC_ExpectTokenString( source, "," ) ) { + return qfalse; + } + } //end while + // + return qtrue; +} //end of the function BotLoadChatMessage +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void BotDumpRandomStringList( bot_randomlist_t *randomlist ) { + FILE *fp; + bot_randomlist_t *random; + bot_randomstring_t *rs; + + fp = Log_FilePointer(); + if ( !fp ) { + return; + } + for ( random = randomlist; random; random = random->next ) + { + fprintf( fp, "%s = {", random->string ); + for ( rs = random->firstrandomstring; rs; rs = rs->next ) + { + fprintf( fp, "\"%s\"", rs->string ); + if ( rs->next ) { + fprintf( fp, ", " ); + } else { fprintf( fp, "}\n" );} + } //end for + } //end for +} //end of the function BotDumpRandomStringList +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +bot_randomlist_t *BotLoadRandomStrings( char *filename ) { + int pass, size; + char *ptr = NULL, chatmessagestring[MAX_MESSAGE_SIZE]; + source_t *source; + token_t token; + bot_randomlist_t *randomlist, *lastrandom, *random; + bot_randomstring_t *randomstring; + +#ifdef DEBUG + int starttime = Sys_MilliSeconds(); +#endif //DEBUG + + size = 0; + randomlist = NULL; + random = NULL; + //the synonyms are parsed in two phases + for ( pass = 0; pass < 2; pass++ ) + { + // + if ( pass && size ) { + ptr = (char *) GetClearedHunkMemory( size ); + } + // + source = LoadSourceFile( filename ); + if ( !source ) { + botimport.Print( PRT_ERROR, "counldn't load %s\n", filename ); + return NULL; + } //end if + // + randomlist = NULL; //list + lastrandom = NULL; //last + // + while ( PC_ReadToken( source, &token ) ) + { + if ( token.type != TT_NAME ) { + SourceError( source, "unknown random %s", token.string ); + FreeSource( source ); + return NULL; + } //end if + size += sizeof( bot_randomlist_t ) + strlen( token.string ) + 1; + if ( pass ) { + random = (bot_randomlist_t *) ptr; + ptr += sizeof( bot_randomlist_t ); + random->string = ptr; + ptr += strlen( token.string ) + 1; + strcpy( random->string, token.string ); + random->firstrandomstring = NULL; + random->numstrings = 0; + // + if ( lastrandom ) { + lastrandom->next = random; + } else { randomlist = random;} + lastrandom = random; + } //end if + if ( !PC_ExpectTokenString( source, "=" ) || + !PC_ExpectTokenString( source, "{" ) ) { + FreeSource( source ); + return NULL; + } //end if + while ( !PC_CheckTokenString( source, "}" ) ) + { + if ( !BotLoadChatMessage( source, chatmessagestring ) ) { + FreeSource( source ); + return NULL; + } //end if + size += sizeof( bot_randomstring_t ) + strlen( chatmessagestring ) + 1; + if ( pass ) { + randomstring = (bot_randomstring_t *) ptr; + ptr += sizeof( bot_randomstring_t ); + randomstring->string = ptr; + ptr += strlen( chatmessagestring ) + 1; + strcpy( randomstring->string, chatmessagestring ); + // + random->numstrings++; + randomstring->next = random->firstrandomstring; + random->firstrandomstring = randomstring; + } //end if + } //end while + } //end while + //free the source after one pass + FreeSource( source ); + } //end for + botimport.Print( PRT_MESSAGE, "loaded %s\n", filename ); + // +#ifdef DEBUG + botimport.Print( PRT_MESSAGE, "random strings %d msec\n", Sys_MilliSeconds() - starttime ); + //BotDumpRandomStringList(randomlist); +#endif //DEBUG + // + return randomlist; +} //end of the function BotLoadRandomStrings +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +char *RandomString( char *name ) { + bot_randomlist_t *random; + bot_randomstring_t *rs; + int i; + + for ( random = randomstrings; random; random = random->next ) + { + if ( !strcmp( random->string, name ) ) { + i = random() * random->numstrings; + for ( rs = random->firstrandomstring; rs; rs = rs->next ) + { + if ( --i < 0 ) { + break; + } + } //end for + if ( rs ) { + return rs->string; + } //end if + } //end for + } //end for + return NULL; +} //end of the function RandomString +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void BotDumpMatchTemplates( bot_matchtemplate_t *matches ) { + FILE *fp; + bot_matchtemplate_t *mt; + bot_matchpiece_t *mp; + bot_matchstring_t *ms; + + fp = Log_FilePointer(); + if ( !fp ) { + return; + } + for ( mt = matches; mt; mt = mt->next ) + { + //fprintf(fp, "%8d { "); + for ( mp = mt->first; mp; mp = mp->next ) + { + if ( mp->type == MT_STRING ) { + for ( ms = mp->firststring; ms; ms = ms->next ) + { + fprintf( fp, "\"%s\"", ms->string ); + if ( ms->next ) { + fprintf( fp, "|" ); + } + } //end for + } //end if + else if ( mp->type == MT_VARIABLE ) { + fprintf( fp, "%d", mp->variable ); + } //end else if + if ( mp->next ) { + fprintf( fp, ", " ); + } + } //end for + fprintf( fp, " = (%d, %d);}\n", mt->type, mt->subtype ); + } //end for +} //end of the function BotDumpMatchTemplates +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void BotFreeMatchPieces( bot_matchpiece_t *matchpieces ) { + bot_matchpiece_t *mp, *nextmp; + bot_matchstring_t *ms, *nextms; + + for ( mp = matchpieces; mp; mp = nextmp ) + { + nextmp = mp->next; + if ( mp->type == MT_STRING ) { + for ( ms = mp->firststring; ms; ms = nextms ) + { + nextms = ms->next; + FreeMemory( ms ); + } //end for + } //end if + FreeMemory( mp ); + } //end for +} //end of the function BotFreeMatchPieces +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +bot_matchpiece_t *BotLoadMatchPieces( source_t *source, char *endtoken ) { + int lastwasvariable, emptystring; + token_t token; + bot_matchpiece_t *matchpiece, *firstpiece, *lastpiece; + bot_matchstring_t *matchstring, *lastmatchstring; + + firstpiece = NULL; + lastpiece = NULL; + // + lastwasvariable = qfalse; + // + while ( PC_ReadToken( source, &token ) ) + { + if ( token.type == TT_NUMBER && ( token.subtype & TT_INTEGER ) ) { + if ( token.intvalue < 0 || token.intvalue >= MAX_MATCHVARIABLES ) { + SourceError( source, "can't have more than %d match variables\n", MAX_MATCHVARIABLES ); + FreeSource( source ); + BotFreeMatchPieces( firstpiece ); + return NULL; + } //end if + if ( lastwasvariable ) { + SourceError( source, "not allowed to have adjacent variables\n" ); + FreeSource( source ); + BotFreeMatchPieces( firstpiece ); + return NULL; + } //end if + lastwasvariable = qtrue; + // + matchpiece = (bot_matchpiece_t *) GetClearedHunkMemory( sizeof( bot_matchpiece_t ) ); + matchpiece->type = MT_VARIABLE; + matchpiece->variable = token.intvalue; + matchpiece->next = NULL; + if ( lastpiece ) { + lastpiece->next = matchpiece; + } else { firstpiece = matchpiece;} + lastpiece = matchpiece; + } //end if + else if ( token.type == TT_STRING ) { + // + matchpiece = (bot_matchpiece_t *) GetClearedHunkMemory( sizeof( bot_matchpiece_t ) ); + matchpiece->firststring = NULL; + matchpiece->type = MT_STRING; + matchpiece->variable = 0; + matchpiece->next = NULL; + if ( lastpiece ) { + lastpiece->next = matchpiece; + } else { firstpiece = matchpiece;} + lastpiece = matchpiece; + // + lastmatchstring = NULL; + emptystring = qfalse; + // + do + { + if ( matchpiece->firststring ) { + if ( !PC_ExpectTokenType( source, TT_STRING, 0, &token ) ) { + FreeSource( source ); + BotFreeMatchPieces( firstpiece ); + return NULL; + } //end if + } //end if + StripDoubleQuotes( token.string ); + matchstring = (bot_matchstring_t *) GetClearedHunkMemory( sizeof( bot_matchstring_t ) + strlen( token.string ) + 1 ); + matchstring->string = (char *) matchstring + sizeof( bot_matchstring_t ); + strcpy( matchstring->string, token.string ); + if ( !strlen( token.string ) ) { + emptystring = qtrue; + } + matchstring->next = NULL; + if ( lastmatchstring ) { + lastmatchstring->next = matchstring; + } else { matchpiece->firststring = matchstring;} + lastmatchstring = matchstring; + } while ( PC_CheckTokenString( source, "|" ) ); + //if there was no empty string found + if ( !emptystring ) { + lastwasvariable = qfalse; + } + } //end if + else + { + SourceError( source, "invalid token %s\n", token.string ); + FreeSource( source ); + BotFreeMatchPieces( firstpiece ); + return NULL; + } //end else + if ( PC_CheckTokenString( source, endtoken ) ) { + break; + } + if ( !PC_ExpectTokenString( source, "," ) ) { + FreeSource( source ); + BotFreeMatchPieces( firstpiece ); + return NULL; + } //end if + } //end while + return firstpiece; +} //end of the function BotLoadMatchPieces +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void BotFreeMatchTemplates( bot_matchtemplate_t *mt ) { + bot_matchtemplate_t *nextmt; + + for (; mt; mt = nextmt ) + { + nextmt = mt->next; + BotFreeMatchPieces( mt->first ); + FreeMemory( mt ); + } //end for +} //end of the function BotFreeMatchTemplates +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +bot_matchtemplate_t *BotLoadMatchTemplates( char *matchfile ) { + source_t *source; + token_t token; + bot_matchtemplate_t *matchtemplate, *matches, *lastmatch; + unsigned long int context; + + source = LoadSourceFile( matchfile ); + if ( !source ) { + botimport.Print( PRT_ERROR, "counldn't load %s\n", matchfile ); + return NULL; + } //end if + // + matches = NULL; //list with matches + lastmatch = NULL; //last match in the list + + while ( PC_ReadToken( source, &token ) ) + { + if ( token.type != TT_NUMBER || !( token.subtype & TT_INTEGER ) ) { + SourceError( source, "expected integer, found %s\n", token.string ); + BotFreeMatchTemplates( matches ); + FreeSource( source ); + return NULL; + } //end if + //the context + context = token.intvalue; + // + if ( !PC_ExpectTokenString( source, "{" ) ) { + BotFreeMatchTemplates( matches ); + FreeSource( source ); + return NULL; + } //end if + // + while ( PC_ReadToken( source, &token ) ) + { + if ( !strcmp( token.string, "}" ) ) { + break; + } + // + PC_UnreadLastToken( source ); + // + matchtemplate = (bot_matchtemplate_t *) GetClearedHunkMemory( sizeof( bot_matchtemplate_t ) ); + matchtemplate->context = context; + matchtemplate->next = NULL; + //add the match template to the list + if ( lastmatch ) { + lastmatch->next = matchtemplate; + } else { matches = matchtemplate;} + lastmatch = matchtemplate; + //load the match template + matchtemplate->first = BotLoadMatchPieces( source, "=" ); + if ( !matchtemplate->first ) { + BotFreeMatchTemplates( matches ); + return NULL; + } //end if + //read the match type + if ( !PC_ExpectTokenString( source, "(" ) || + !PC_ExpectTokenType( source, TT_NUMBER, TT_INTEGER, &token ) ) { + BotFreeMatchTemplates( matches ); + FreeSource( source ); + return NULL; + } //end if + matchtemplate->type = token.intvalue; + //read the match subtype + if ( !PC_ExpectTokenString( source, "," ) || + !PC_ExpectTokenType( source, TT_NUMBER, TT_INTEGER, &token ) ) { + BotFreeMatchTemplates( matches ); + FreeSource( source ); + return NULL; + } //end if + matchtemplate->subtype = token.intvalue; + //read trailing punctuations + if ( !PC_ExpectTokenString( source, ")" ) || + !PC_ExpectTokenString( source, ";" ) ) { + BotFreeMatchTemplates( matches ); + FreeSource( source ); + return NULL; + } //end if + } //end while + } //end while + //free the source + FreeSource( source ); + botimport.Print( PRT_MESSAGE, "loaded %s\n", matchfile ); + // + //BotDumpMatchTemplates(matches); + // + return matches; +} //end of the function BotLoadMatchTemplates +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int StringsMatch( bot_matchpiece_t *pieces, bot_match_t *match ) { + int lastvariable, index; + char *strptr, *newstrptr; + bot_matchpiece_t *mp; + bot_matchstring_t *ms; + + //no last variable + lastvariable = -1; + //pointer to the string to compare the match string with + strptr = match->string; + //Log_Write("match: %s", strptr); + //compare the string with the current match string + for ( mp = pieces; mp; mp = mp->next ) + { + //if it is a piece of string + if ( mp->type == MT_STRING ) { + newstrptr = NULL; + for ( ms = mp->firststring; ms; ms = ms->next ) + { + if ( !strlen( ms->string ) ) { + newstrptr = strptr; + break; + } //end if + //Log_Write("MT_STRING: %s", mp->string); + index = StringContains( strptr, ms->string, qfalse ); + if ( index >= 0 ) { + newstrptr = strptr + index; + if ( lastvariable >= 0 ) { + match->variables[lastvariable].length = + newstrptr - match->variables[lastvariable].ptr; + lastvariable = -1; + break; + } //end if + else if ( index == 0 ) { + break; + } //end else + newstrptr = NULL; + } //end if + } //end for + if ( !newstrptr ) { + return qfalse; + } + strptr = newstrptr + strlen( ms->string ); + } //end if + //if it is a variable piece of string + else if ( mp->type == MT_VARIABLE ) { + //Log_Write("MT_VARIABLE"); + match->variables[mp->variable].ptr = strptr; + lastvariable = mp->variable; + } //end else if + } //end for + //if a match was found + if ( !mp && ( lastvariable >= 0 || !strlen( strptr ) ) ) { + //if the last piece was a variable string + if ( lastvariable >= 0 ) { + match->variables[lastvariable].length = strlen( match->variables[lastvariable].ptr ); + } //end if + return qtrue; + } //end if + return qfalse; +} //end of the function StringsMatch +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int BotFindMatch( char *str, bot_match_t *match, unsigned long int context ) { + int i; + bot_matchtemplate_t *ms; + + strncpy( match->string, str, MAX_MESSAGE_SIZE ); + //remove any trailing enters + while ( strlen( match->string ) && + match->string[strlen( match->string ) - 1] == '\n' ) + { + match->string[strlen( match->string ) - 1] = '\0'; + } //end while + //compare the string with all the match strings + for ( ms = matchtemplates; ms; ms = ms->next ) + { + if ( !( ms->context & context ) ) { + continue; + } + //reset the match variable pointers + for ( i = 0; i < MAX_MATCHVARIABLES; i++ ) match->variables[i].ptr = NULL; + // + if ( StringsMatch( ms->first, match ) ) { + match->type = ms->type; + match->subtype = ms->subtype; + return qtrue; + } //end if + } //end for + return qfalse; +} //end of the function BotFindMatch +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void BotMatchVariable( bot_match_t *match, int variable, char *buf, int size ) { + if ( variable < 0 || variable >= MAX_MATCHVARIABLES ) { + botimport.Print( PRT_FATAL, "BotMatchVariable: variable out of range\n" ); + strcpy( buf, "" ); + return; + } //end if + + if ( match->variables[variable].ptr ) { + if ( match->variables[variable].length < size ) { + size = match->variables[variable].length + 1; + } + strncpy( buf, match->variables[variable].ptr, size - 1 ); + buf[size - 1] = '\0'; + } //end if + else + { + strcpy( buf, "" ); + } //end else + return; +} //end of the function BotMatchVariable +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +bot_stringlist_t *BotFindStringInList( bot_stringlist_t *list, char *string ) { + bot_stringlist_t *s; + + for ( s = list; s; s = s->next ) + { + if ( !strcmp( s->string, string ) ) { + return s; + } + } //end for + return NULL; +} //end of the function BotFindStringInList +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +bot_stringlist_t *BotCheckChatMessageIntegrety( char *message, bot_stringlist_t *stringlist ) { + int i; + char *msgptr; + char temp[MAX_MESSAGE_SIZE]; + bot_stringlist_t *s; + + msgptr = message; + // + while ( *msgptr ) + { + if ( *msgptr == ESCAPE_CHAR ) { + msgptr++; + switch ( *msgptr ) + { + case 'v': //variable + { + //step over the 'v' + msgptr++; + while ( *msgptr && *msgptr != ESCAPE_CHAR ) msgptr++; + //step over the trailing escape char + if ( *msgptr ) { + msgptr++; + } + break; + } //end case + case 'r': //random + { + //step over the 'r' + msgptr++; + for ( i = 0; ( *msgptr && *msgptr != ESCAPE_CHAR ); i++ ) + { + temp[i] = *msgptr++; + } //end while + temp[i] = '\0'; + //step over the trailing escape char + if ( *msgptr ) { + msgptr++; + } + //find the random keyword + if ( !RandomString( temp ) ) { + if ( !BotFindStringInList( stringlist, temp ) ) { + Log_Write( "%s = {\"%s\"} //MISSING RANDOM\r\n", temp, temp ); + s = GetClearedMemory( sizeof( bot_stringlist_t ) + strlen( temp ) + 1 ); + s->string = (char *) s + sizeof( bot_stringlist_t ); + strcpy( s->string, temp ); + s->next = stringlist; + stringlist = s; + } //end if + } //end if + break; + } //end case + default: + { + botimport.Print( PRT_FATAL, "BotCheckChatMessageIntegrety: message \"%s\" invalid escape char\n", message ); + break; + } //end default + } //end switch + } //end if + else + { + msgptr++; + } //end else + } //end while + return stringlist; +} //end of the function BotCheckChatMessageIntegrety +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void BotCheckReplyChatIntegrety( bot_replychat_t *replychat ) { + bot_replychat_t *rp; + bot_chatmessage_t *cm; + bot_stringlist_t *stringlist, *s, *nexts; + + stringlist = NULL; + for ( rp = replychat; rp; rp = rp->next ) + { + for ( cm = rp->firstchatmessage; cm; cm = cm->next ) + { + stringlist = BotCheckChatMessageIntegrety( cm->chatmessage, stringlist ); + } //end for + } //end for + for ( s = stringlist; s; s = nexts ) + { + nexts = s->next; + FreeMemory( s ); + } //end for +} //end of the function BotCheckReplyChatIntegrety +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void BotCheckInitialChatIntegrety( bot_chat_t *chat ) { + bot_chattype_t *t; + bot_chatmessage_t *cm; + bot_stringlist_t *stringlist, *s, *nexts; + + stringlist = NULL; + for ( t = chat->types; t; t = t->next ) + { + for ( cm = t->firstchatmessage; cm; cm = cm->next ) + { + stringlist = BotCheckChatMessageIntegrety( cm->chatmessage, stringlist ); + } //end for + } //end for + for ( s = stringlist; s; s = nexts ) + { + nexts = s->next; + FreeMemory( s ); + } //end for +} //end of the function BotCheckInitialChatIntegrety +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void BotDumpReplyChat( bot_replychat_t *replychat ) { + FILE *fp; + bot_replychat_t *rp; + bot_replychatkey_t *key; + bot_chatmessage_t *cm; + bot_matchpiece_t *mp; + + fp = Log_FilePointer(); + if ( !fp ) { + return; + } + fprintf( fp, "BotDumpReplyChat:\n" ); + for ( rp = replychat; rp; rp = rp->next ) + { + fprintf( fp, "[" ); + for ( key = rp->keys; key; key = key->next ) + { + if ( key->flags & RCKFL_AND ) { + fprintf( fp, "&" ); + } else if ( key->flags & RCKFL_NOT ) { + fprintf( fp, "!" ); + } + // + if ( key->flags & RCKFL_NAME ) { + fprintf( fp, "name" ); + } else if ( key->flags & RCKFL_GENDERFEMALE ) { + fprintf( fp, "female" ); + } else if ( key->flags & RCKFL_GENDERMALE ) { + fprintf( fp, "male" ); + } else if ( key->flags & RCKFL_GENDERLESS ) { + fprintf( fp, "it" ); + } else if ( key->flags & RCKFL_VARIABLES ) { + fprintf( fp, "(" ); + for ( mp = key->match; mp; mp = mp->next ) + { + if ( mp->type == MT_STRING ) { + fprintf( fp, "\"%s\"", mp->firststring->string ); + } else { fprintf( fp, "%d", mp->variable );} + if ( mp->next ) { + fprintf( fp, ", " ); + } + } //end for + fprintf( fp, ")" ); + } //end if + else if ( key->flags & RCKFL_STRING ) { + fprintf( fp, "\"%s\"", key->string ); + } //end if + if ( key->next ) { + fprintf( fp, ", " ); + } else { fprintf( fp, "] = %1.0f\n", rp->priority );} + } //end for + fprintf( fp, "{\n" ); + for ( cm = rp->firstchatmessage; cm; cm = cm->next ) + { + fprintf( fp, "\t\"%s\";\n", cm->chatmessage ); + } //end for + fprintf( fp, "}\n" ); + } //end for +} //end of the function BotDumpReplyChat +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void BotFreeReplyChat( bot_replychat_t *replychat ) { + bot_replychat_t *rp, *nextrp; + bot_replychatkey_t *key, *nextkey; + bot_chatmessage_t *cm, *nextcm; + + for ( rp = replychat; rp; rp = nextrp ) + { + nextrp = rp->next; + for ( key = rp->keys; key; key = nextkey ) + { + nextkey = key->next; + if ( key->match ) { + BotFreeMatchPieces( key->match ); + } + if ( key->string ) { + FreeMemory( key->string ); + } + FreeMemory( key ); + } //end for + for ( cm = rp->firstchatmessage; cm; cm = nextcm ) + { + nextcm = cm->next; + FreeMemory( cm ); + } //end for + FreeMemory( rp ); + } //end for +} //end of the function BotFreeReplyChat +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +bot_replychat_t *BotLoadReplyChat( char *filename ) { + char chatmessagestring[MAX_MESSAGE_SIZE]; + char namebuffer[MAX_MESSAGE_SIZE]; + source_t *source; + token_t token; + bot_chatmessage_t *chatmessage = NULL; + bot_replychat_t *replychat, *replychatlist; + bot_replychatkey_t *key; + + source = LoadSourceFile( filename ); + if ( !source ) { + botimport.Print( PRT_ERROR, "counldn't load %s\n", filename ); + return NULL; + } //end if + // + replychatlist = NULL; + // + while ( PC_ReadToken( source, &token ) ) + { + if ( strcmp( token.string, "[" ) ) { + SourceError( source, "expected [, found %s", token.string ); + BotFreeReplyChat( replychatlist ); + FreeSource( source ); + return NULL; + } //end if + // + replychat = GetClearedHunkMemory( sizeof( bot_replychat_t ) ); + replychat->keys = NULL; + replychat->next = replychatlist; + replychatlist = replychat; + //read the keys, there must be at least one key + do + { + //allocate a key + key = (bot_replychatkey_t *) GetClearedHunkMemory( sizeof( bot_replychatkey_t ) ); + key->flags = 0; + key->string = NULL; + key->match = NULL; + key->next = replychat->keys; + replychat->keys = key; + //check for MUST BE PRESENT and MUST BE ABSENT keys + if ( PC_CheckTokenString( source, "&" ) ) { + key->flags |= RCKFL_AND; + } else if ( PC_CheckTokenString( source, "!" ) ) { + key->flags |= RCKFL_NOT; + } + //special keys + if ( PC_CheckTokenString( source, "name" ) ) { + key->flags |= RCKFL_NAME; + } else if ( PC_CheckTokenString( source, "female" ) ) { + key->flags |= RCKFL_GENDERFEMALE; + } else if ( PC_CheckTokenString( source, "male" ) ) { + key->flags |= RCKFL_GENDERMALE; + } else if ( PC_CheckTokenString( source, "it" ) ) { + key->flags |= RCKFL_GENDERLESS; + } else if ( PC_CheckTokenString( source, "(" ) ) { //match key + key->flags |= RCKFL_VARIABLES; + key->match = BotLoadMatchPieces( source, ")" ); + if ( !key->match ) { + BotFreeReplyChat( replychatlist ); + return NULL; + } //end if + } //end else if + else if ( PC_CheckTokenString( source, "<" ) ) { //bot names + key->flags |= RCKFL_BOTNAMES; + strcpy( namebuffer, "" ); + do + { + if ( !PC_ExpectTokenType( source, TT_STRING, 0, &token ) ) { + BotFreeReplyChat( replychatlist ); + FreeSource( source ); + return NULL; + } //end if + StripDoubleQuotes( token.string ); + if ( strlen( namebuffer ) ) { + strcat( namebuffer, "\\" ); + } + strcat( namebuffer, token.string ); + } while ( PC_CheckTokenString( source, "," ) ); + if ( !PC_ExpectTokenString( source, ">" ) ) { + BotFreeReplyChat( replychatlist ); + FreeSource( source ); + return NULL; + } //end if + key->string = (char *) GetClearedHunkMemory( strlen( namebuffer ) + 1 ); + strcpy( key->string, namebuffer ); + } //end else if + else //normal string key + { + key->flags |= RCKFL_STRING; + if ( !PC_ExpectTokenType( source, TT_STRING, 0, &token ) ) { + BotFreeReplyChat( replychatlist ); + FreeSource( source ); + return NULL; + } //end if + StripDoubleQuotes( token.string ); + key->string = (char *) GetClearedHunkMemory( strlen( token.string ) + 1 ); + strcpy( key->string, token.string ); + } //end else + // + PC_CheckTokenString( source, "," ); + } while ( !PC_CheckTokenString( source, "]" ) ); + //read the = sign and the priority + if ( !PC_ExpectTokenString( source, "=" ) || + !PC_ExpectTokenType( source, TT_NUMBER, 0, &token ) ) { + BotFreeReplyChat( replychatlist ); + FreeSource( source ); + return NULL; + } //end if + replychat->priority = token.floatvalue; + //read the leading { + if ( !PC_ExpectTokenString( source, "{" ) ) { + BotFreeReplyChat( replychatlist ); + FreeSource( source ); + return NULL; + } //end if + replychat->numchatmessages = 0; + //while the trailing } is not found + while ( !PC_CheckTokenString( source, "}" ) ) + { + if ( !BotLoadChatMessage( source, chatmessagestring ) ) { + BotFreeReplyChat( replychatlist ); + FreeSource( source ); + return NULL; + } //end if + chatmessage = (bot_chatmessage_t *) GetClearedHunkMemory( sizeof( bot_chatmessage_t ) + strlen( chatmessagestring ) + 1 ); + chatmessage->chatmessage = (char *) chatmessage + sizeof( bot_chatmessage_t ); + strcpy( chatmessage->chatmessage, chatmessagestring ); + chatmessage->time = -2 * CHATMESSAGE_RECENTTIME; + chatmessage->next = replychat->firstchatmessage; + //add the chat message to the reply chat + replychat->firstchatmessage = chatmessage; + replychat->numchatmessages++; + } //end while + } //end while + FreeSource( source ); + botimport.Print( PRT_MESSAGE, "loaded %s\n", filename ); + // + //BotDumpReplyChat(replychatlist); + if ( bot_developer ) { + BotCheckReplyChatIntegrety( replychatlist ); + } //end if + // + if ( !replychatlist ) { + botimport.Print( PRT_MESSAGE, "no rchats\n" ); + } + // + return replychatlist; +} //end of the function BotLoadReplyChat +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void BotDumpInitialChat( bot_chat_t *chat ) { + bot_chattype_t *t; + bot_chatmessage_t *m; + + Log_Write( "{" ); + for ( t = chat->types; t; t = t->next ) + { + Log_Write( " type \"%s\"", t->name ); + Log_Write( " {" ); + Log_Write( " numchatmessages = %d", t->numchatmessages ); + for ( m = t->firstchatmessage; m; m = m->next ) + { + Log_Write( " \"%s\"", m->chatmessage ); + } //end for + Log_Write( " }" ); + } //end for + Log_Write( "}" ); +} //end of the function BotDumpInitialChat +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +bot_chat_t *BotLoadInitialChat( char *chatfile, char *chatname ) { + int pass, foundchat, indent, size; + char *ptr = NULL; + char chatmessagestring[MAX_MESSAGE_SIZE]; + source_t *source; + token_t token; + bot_chat_t *chat = NULL; + bot_chattype_t *chattype = NULL; + bot_chatmessage_t *chatmessage = NULL; +#ifdef DEBUG + int starttime; + + starttime = Sys_MilliSeconds(); +#endif //DEBUG + // + size = 0; + foundchat = qfalse; + //a bot chat is parsed in two phases + for ( pass = 0; pass < 2; pass++ ) + { + //allocate memory + if ( pass && size ) { + ptr = (char *) GetClearedMemory( size ); + } + //load the source file + source = LoadSourceFile( chatfile ); + if ( !source ) { + botimport.Print( PRT_ERROR, "counldn't load %s\n", chatfile ); + return NULL; + } //end if + //chat structure + if ( pass ) { + chat = (bot_chat_t *) ptr; + ptr += sizeof( bot_chat_t ); + } //end if + size = sizeof( bot_chat_t ); + // + while ( PC_ReadToken( source, &token ) ) + { + if ( !strcmp( token.string, "chat" ) ) { + if ( !PC_ExpectTokenType( source, TT_STRING, 0, &token ) ) { + FreeSource( source ); + return NULL; + } //end if + StripDoubleQuotes( token.string ); + //after the chat name we expect a opening brace + if ( !PC_ExpectTokenString( source, "{" ) ) { + FreeSource( source ); + return NULL; + } //end if + //if the chat name is found + if ( !Q_stricmp( token.string, chatname ) ) { + foundchat = qtrue; + //read the chat types + while ( 1 ) + { + if ( !PC_ExpectAnyToken( source, &token ) ) { + FreeSource( source ); + return NULL; + } //end if + if ( !strcmp( token.string, "}" ) ) { + break; + } + if ( strcmp( token.string, "type" ) ) { + SourceError( source, "expected type found %s\n", token.string ); + FreeSource( source ); + return NULL; + } //end if + //expect the chat type name + if ( !PC_ExpectTokenType( source, TT_STRING, 0, &token ) || + !PC_ExpectTokenString( source, "{" ) ) { + FreeSource( source ); + return NULL; + } //end if + StripDoubleQuotes( token.string ); + if ( pass ) { + chattype = (bot_chattype_t *) ptr; + strncpy( chattype->name, token.string, MAX_CHATTYPE_NAME ); + chattype->firstchatmessage = NULL; + //add the chat type to the chat + chattype->next = chat->types; + chat->types = chattype; + // + ptr += sizeof( bot_chattype_t ); + } //end if + size += sizeof( bot_chattype_t ); + //read the chat messages + while ( !PC_CheckTokenString( source, "}" ) ) + { + if ( !BotLoadChatMessage( source, chatmessagestring ) ) { + FreeSource( source ); + return NULL; + } //end if + if ( pass ) { + chatmessage = (bot_chatmessage_t *) ptr; + chatmessage->time = -2 * CHATMESSAGE_RECENTTIME; + //put the chat message in the list + chatmessage->next = chattype->firstchatmessage; + chattype->firstchatmessage = chatmessage; + //store the chat message + ptr += sizeof( bot_chatmessage_t ); + chatmessage->chatmessage = ptr; + strcpy( chatmessage->chatmessage, chatmessagestring ); + ptr += strlen( chatmessagestring ) + 1; + //the number of chat messages increased + chattype->numchatmessages++; + } //end if + size += sizeof( bot_chatmessage_t ) + strlen( chatmessagestring ) + 1; + } //end if + } //end while + } //end if + else //skip the bot chat + { + indent = 1; + while ( indent ) + { + if ( !PC_ExpectAnyToken( source, &token ) ) { + FreeSource( source ); + return NULL; + } //end if + if ( !strcmp( token.string, "{" ) ) { + indent++; + } else if ( !strcmp( token.string, "}" ) ) { + indent--; + } + } //end while + } //end else + } //end if + else + { + SourceError( source, "unknown definition %s\n", token.string ); + FreeSource( source ); + return NULL; + } //end else + } //end while + //free the source + FreeSource( source ); + //if the requested character is not found + if ( !foundchat ) { + botimport.Print( PRT_ERROR, "couldn't find chat %s in %s\n", chatname, chatfile ); + return NULL; + } //end if + } //end for + // + botimport.Print( PRT_MESSAGE, "loaded %s from %s\n", chatname, chatfile ); + // + //BotDumpInitialChat(chat); + if ( bot_developer ) { + BotCheckInitialChatIntegrety( chat ); + } //end if +#ifdef DEBUG + botimport.Print( PRT_MESSAGE, "initial chats loaded in %d msec\n", Sys_MilliSeconds() - starttime ); +#endif //DEBUG + //character was read succesfully + return chat; +} //end of the function BotLoadInitialChat +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void BotFreeChatFile( int chatstate ) { + bot_chatstate_t *cs; + + cs = BotChatStateFromHandle( chatstate ); + if ( !cs ) { + return; + } + if ( cs->chat ) { + FreeMemory( cs->chat ); + } + cs->chat = NULL; +} //end of the function BotFreeChatFile +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int BotLoadChatFile( int chatstate, char *chatfile, char *chatname ) { + bot_chatstate_t *cs; + int n, avail = 0; + + cs = BotChatStateFromHandle( chatstate ); + if ( !cs ) { + return BLERR_CANNOTLOADICHAT; + } + BotFreeChatFile( chatstate ); + + if ( !LibVarGetValue( "bot_reloadcharacters" ) ) { + avail = -1; + for ( n = 0; n < MAX_CLIENTS; n++ ) { + if ( !ichatdata[n].inuse ) { + if ( avail == -1 ) { + avail = n; + } + continue; + } + if ( strcmp( chatfile, ichatdata[n].filename ) != 0 ) { + continue; + } + if ( strcmp( chatname, ichatdata[n].chatname ) != 0 ) { + continue; + } + cs->chat = ichatdata[n].chat; + // botimport.Print( PRT_MESSAGE, "retained %s from %s\n", chatname, chatfile ); + return BLERR_NOERROR; + } + + if ( avail == -1 ) { + botimport.Print( PRT_FATAL, "ichatdata table full; couldn't load chat %s from %s\n", chatname, chatfile ); + return BLERR_CANNOTLOADICHAT; + } + } + + cs->chat = BotLoadInitialChat( chatfile, chatname ); + if ( !cs->chat ) { + botimport.Print( PRT_FATAL, "couldn't load chat %s from %s\n", chatname, chatfile ); + return BLERR_CANNOTLOADICHAT; + } //end if + if ( !LibVarGetValue( "bot_reloadcharacters" ) ) { + ichatdata[avail].chat = cs->chat; + Q_strncpyz( ichatdata[avail].chatname, chatname, sizeof( ichatdata[avail].chatname ) ); + Q_strncpyz( ichatdata[avail].filename, chatfile, sizeof( ichatdata[avail].filename ) ); + ichatdata[avail].inuse = qtrue; + } //end if + + return BLERR_NOERROR; +} //end of the function BotLoadChatFile +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int BotExpandChatMessage( char *outmessage, char *message, unsigned long mcontext, + bot_matchvariable_t *variables, unsigned long vcontext, int reply ) { + int num, len, i, expansion; + char *outputbuf, *ptr, *msgptr; + char temp[MAX_MESSAGE_SIZE]; + + expansion = qfalse; + msgptr = message; + outputbuf = outmessage; + len = 0; + // + while ( *msgptr ) + { + if ( *msgptr == ESCAPE_CHAR ) { + msgptr++; + switch ( *msgptr ) + { + case 'v': //variable + { + msgptr++; + num = 0; + while ( *msgptr && *msgptr != ESCAPE_CHAR ) + { + num = num * 10 + ( *msgptr++ ) - '0'; + } //end while + //step over the trailing escape char + if ( *msgptr ) { + msgptr++; + } + if ( num > MAX_MATCHVARIABLES ) { + botimport.Print( PRT_ERROR, "BotConstructChat: message %s variable %d out of range\n", message, num ); + return qfalse; + } //end if + ptr = variables[num].ptr; + if ( ptr ) { + for ( i = 0; i < variables[num].length; i++ ) + { + temp[i] = ptr[i]; + } //end for + temp[i] = 0; + //if it's a reply message + if ( reply ) { + //replace the reply synonyms in the variables + BotReplaceReplySynonyms( temp, vcontext ); + } //end if + else + { + //replace synonyms in the variable context + BotReplaceSynonyms( temp, vcontext ); + } //end else + // + if ( len + strlen( temp ) >= MAX_MESSAGE_SIZE ) { + botimport.Print( PRT_ERROR, "BotConstructChat: message %s too long\n", message ); + return qfalse; + } //end if + strcpy( &outputbuf[len], temp ); + len += strlen( temp ); + } //end if + break; + } //end case + case 'r': //random + { + msgptr++; + for ( i = 0; ( *msgptr && *msgptr != ESCAPE_CHAR ); i++ ) + { + temp[i] = *msgptr++; + } //end while + temp[i] = '\0'; + //step over the trailing escape char + if ( *msgptr ) { + msgptr++; + } + //find the random keyword + ptr = RandomString( temp ); + if ( !ptr ) { + botimport.Print( PRT_ERROR, "BotConstructChat: unknown random string %s\n", temp ); + return qfalse; + } //end if + if ( len + strlen( ptr ) >= MAX_MESSAGE_SIZE ) { + botimport.Print( PRT_ERROR, "BotConstructChat: message \"%s\" too long\n", message ); + return qfalse; + } //end if + strcpy( &outputbuf[len], ptr ); + len += strlen( ptr ); + expansion = qtrue; + break; + } //end case + default: + { + botimport.Print( PRT_FATAL, "BotConstructChat: message \"%s\" invalid escape char\n", message ); + break; + } //end default + } //end switch + } //end if + else + { + outputbuf[len++] = *msgptr++; + if ( len >= MAX_MESSAGE_SIZE ) { + botimport.Print( PRT_ERROR, "BotConstructChat: message \"%s\" too long\n", message ); + break; + } //end if + } //end else + } //end while + outputbuf[len] = '\0'; + //replace synonyms weighted in the message context + BotReplaceWeightedSynonyms( outputbuf, mcontext ); + //return true if a random was expanded + return expansion; +} //end of the function BotExpandChatMessage +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void BotConstructChatMessage( bot_chatstate_t *chatstate, char *message, unsigned long mcontext, + bot_matchvariable_t *variables, unsigned long vcontext, int reply ) { + int i; + char srcmessage[MAX_MESSAGE_SIZE]; + + strcpy( srcmessage, message ); + for ( i = 0; i < 10; i++ ) + { + if ( !BotExpandChatMessage( chatstate->chatmessage, srcmessage, mcontext, variables, vcontext, reply ) ) { + break; + } //end if + strcpy( srcmessage, chatstate->chatmessage ); + } //end for + if ( i >= 10 ) { + botimport.Print( PRT_WARNING, "too many expansions in chat message\n" ); + botimport.Print( PRT_WARNING, "%s\n", chatstate->chatmessage ); + } //end if +} //end of the function BotConstructChatMessage +//=========================================================================== +// randomly chooses one of the chat message of the given type +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +char *BotChooseInitialChatMessage( bot_chatstate_t *cs, char *type ) { + int n, numchatmessages; + float besttime; + bot_chattype_t *t; + bot_chatmessage_t *m, *bestchatmessage; + bot_chat_t *chat; + + chat = cs->chat; + for ( t = chat->types; t; t = t->next ) + { + if ( !Q_stricmp( t->name, type ) ) { + numchatmessages = 0; + for ( m = t->firstchatmessage; m; m = m->next ) + { + if ( m->time > AAS_Time() ) { + continue; + } + numchatmessages++; + } //end if + //if all chat messages have been used recently + if ( numchatmessages <= 0 ) { + besttime = 0; + bestchatmessage = NULL; + for ( m = t->firstchatmessage; m; m = m->next ) + { + if ( !besttime || m->time < besttime ) { + bestchatmessage = m; + besttime = m->time; + } //end if + } //end for + if ( bestchatmessage ) { + return bestchatmessage->chatmessage; + } + } //end if + else //choose a chat message randomly + { + n = random() * numchatmessages; + for ( m = t->firstchatmessage; m; m = m->next ) + { + if ( m->time > AAS_Time() ) { + continue; + } + if ( --n < 0 ) { + m->time = AAS_Time() + CHATMESSAGE_RECENTTIME; + return m->chatmessage; + } //end if + } //end for + } //end else + return NULL; + } //end if + } //end for + return NULL; +} //end of the function BotChooseInitialChatMessage +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int BotNumInitialChats( int chatstate, char *type ) { + bot_chatstate_t *cs; + bot_chattype_t *t; + + cs = BotChatStateFromHandle( chatstate ); + if ( !cs ) { + return 0; + } + + for ( t = cs->chat->types; t; t = t->next ) + { + if ( !Q_stricmp( t->name, type ) ) { + if ( LibVarGetValue( "bot_testichat" ) ) { + botimport.Print( PRT_MESSAGE, "%s has %d chat lines\n", type, t->numchatmessages ); + botimport.Print( PRT_MESSAGE, "-------------------\n" ); + } + return t->numchatmessages; + } //end if + } //end for + return 0; +} //end of the function BotNumInitialChats +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void BotInitialChat( int chatstate, char *type, int mcontext, char *var0, char *var1, char *var2, char *var3, char *var4, char *var5, char *var6, char *var7 ) { + char *message; + bot_matchvariable_t variables[MAX_MATCHVARIABLES]; + bot_chatstate_t *cs; + + cs = BotChatStateFromHandle( chatstate ); + if ( !cs ) { + return; + } + //if no chat file is loaded + if ( !cs->chat ) { + return; + } + //choose a chat message randomly of the given type + message = BotChooseInitialChatMessage( cs, type ); + //if there's no message of the given type + if ( !message ) { +#ifdef DEBUG + botimport.Print( PRT_MESSAGE, "no chat messages of type %s\n", type ); +#endif //DEBUG + return; + } //end if + // + memset( variables, 0, sizeof( variables ) ); + if ( var0 ) { + variables[0].ptr = var0; + variables[0].length = strlen( var0 ); + } + if ( var1 ) { + variables[1].ptr = var1; + variables[1].length = strlen( var1 ); + } + if ( var2 ) { + variables[2].ptr = var2; + variables[2].length = strlen( var2 ); + } + if ( var3 ) { + variables[3].ptr = var3; + variables[3].length = strlen( var3 ); + } + if ( var4 ) { + variables[4].ptr = var4; + variables[4].length = strlen( var4 ); + } + if ( var5 ) { + variables[5].ptr = var5; + variables[5].length = strlen( var5 ); + } + if ( var6 ) { + variables[6].ptr = var6; + variables[6].length = strlen( var6 ); + } + if ( var7 ) { + variables[7].ptr = var7; + variables[7].length = strlen( var7 ); + } + // + BotConstructChatMessage( cs, message, mcontext, variables, 0, qfalse ); +} //end of the function BotInitialChat +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void BotPrintReplyChatKeys( bot_replychat_t *replychat ) { + bot_replychatkey_t *key; + bot_matchpiece_t *mp; + + botimport.Print( PRT_MESSAGE, "[" ); + for ( key = replychat->keys; key; key = key->next ) + { + if ( key->flags & RCKFL_AND ) { + botimport.Print( PRT_MESSAGE, "&" ); + } else if ( key->flags & RCKFL_NOT ) { + botimport.Print( PRT_MESSAGE, "!" ); + } + // + if ( key->flags & RCKFL_NAME ) { + botimport.Print( PRT_MESSAGE, "name" ); + } else if ( key->flags & RCKFL_GENDERFEMALE ) { + botimport.Print( PRT_MESSAGE, "female" ); + } else if ( key->flags & RCKFL_GENDERMALE ) { + botimport.Print( PRT_MESSAGE, "male" ); + } else if ( key->flags & RCKFL_GENDERLESS ) { + botimport.Print( PRT_MESSAGE, "it" ); + } else if ( key->flags & RCKFL_VARIABLES ) { + botimport.Print( PRT_MESSAGE, "(" ); + for ( mp = key->match; mp; mp = mp->next ) + { + if ( mp->type == MT_STRING ) { + botimport.Print( PRT_MESSAGE, "\"%s\"", mp->firststring->string ); + } else { botimport.Print( PRT_MESSAGE, "%d", mp->variable );} + if ( mp->next ) { + botimport.Print( PRT_MESSAGE, ", " ); + } + } //end for + botimport.Print( PRT_MESSAGE, ")" ); + } //end if + else if ( key->flags & RCKFL_STRING ) { + botimport.Print( PRT_MESSAGE, "\"%s\"", key->string ); + } //end if + if ( key->next ) { + botimport.Print( PRT_MESSAGE, ", " ); + } else { botimport.Print( PRT_MESSAGE, "] = %1.0f\n", replychat->priority );} + } //end for + botimport.Print( PRT_MESSAGE, "{\n" ); +} //end of the function BotPrintReplyChatKeys +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int BotReplyChat( int chatstate, char *message, int mcontext, int vcontext, char *var0, char *var1, char *var2, char *var3, char *var4, char *var5, char *var6, char *var7 ) { + bot_replychat_t *rchat, *bestrchat; + bot_replychatkey_t *key; + bot_chatmessage_t *m, *bestchatmessage; + bot_match_t match, bestmatch; + int bestpriority, num, found, res, numchatmessages; + bot_chatstate_t *cs; + + cs = BotChatStateFromHandle( chatstate ); + if ( !cs ) { + return qfalse; + } + memset( &match, 0, sizeof( bot_match_t ) ); + strcpy( match.string, message ); + bestpriority = -1; + bestchatmessage = NULL; + bestrchat = NULL; + //go through all the reply chats + for ( rchat = replychats; rchat; rchat = rchat->next ) + { + found = qfalse; + for ( key = rchat->keys; key; key = key->next ) + { + res = qfalse; + //get the match result + if ( key->flags & RCKFL_NAME ) { + res = ( StringContains( message, cs->name, qfalse ) != -1 ); + } else if ( key->flags & RCKFL_BOTNAMES ) { + res = ( StringContains( key->string, cs->name, qfalse ) != -1 ); + } else if ( key->flags & RCKFL_GENDERFEMALE ) { + res = ( cs->gender == CHAT_GENDERFEMALE ); + } else if ( key->flags & RCKFL_GENDERMALE ) { + res = ( cs->gender == CHAT_GENDERMALE ); + } else if ( key->flags & RCKFL_GENDERLESS ) { + res = ( cs->gender == CHAT_GENDERLESS ); + } else if ( key->flags & RCKFL_VARIABLES ) { + res = StringsMatch( key->match, &match ); + } else if ( key->flags & RCKFL_STRING ) { + res = ( StringContainsWord( message, key->string, qfalse ) != NULL ); + } + //if the key must be present + if ( key->flags & RCKFL_AND ) { + if ( !res ) { + found = qfalse; + break; + } //end if + //botnames is an exception + //if (!(key->flags & RCKFL_BOTNAMES)) found = qtrue; + } //end else if + //if the key must be absent + else if ( key->flags & RCKFL_NOT ) { + if ( res ) { + found = qfalse; + break; + } //end if + } //end if + else if ( res ) { + found = qtrue; + } //end else + } //end for + // + if ( found ) { + if ( rchat->priority > bestpriority ) { + numchatmessages = 0; + for ( m = rchat->firstchatmessage; m; m = m->next ) + { + if ( m->time > AAS_Time() ) { + continue; + } + numchatmessages++; + } //end if + num = random() * numchatmessages; + for ( m = rchat->firstchatmessage; m; m = m->next ) + { + if ( --num < 0 ) { + break; + } + if ( m->time > AAS_Time() ) { + continue; + } + } //end for + //if the reply chat has a message + if ( m ) { + memcpy( &bestmatch, &match, sizeof( bot_match_t ) ); + bestchatmessage = m; + bestrchat = rchat; + bestpriority = rchat->priority; + } //end if + } //end if + } //end if + } //end for + if ( bestchatmessage ) { + if ( var0 ) { + bestmatch.variables[0].ptr = var0; + bestmatch.variables[0].length = strlen( var0 ); + } + if ( var1 ) { + bestmatch.variables[1].ptr = var1; + bestmatch.variables[1].length = strlen( var1 ); + } + if ( var2 ) { + bestmatch.variables[2].ptr = var2; + bestmatch.variables[2].length = strlen( var2 ); + } + if ( var3 ) { + bestmatch.variables[3].ptr = var3; + bestmatch.variables[3].length = strlen( var3 ); + } + if ( var4 ) { + bestmatch.variables[4].ptr = var4; + bestmatch.variables[4].length = strlen( var4 ); + } + if ( var5 ) { + bestmatch.variables[5].ptr = var5; + bestmatch.variables[5].length = strlen( var5 ); + } + if ( var6 ) { + bestmatch.variables[6].ptr = var6; + bestmatch.variables[6].length = strlen( var6 ); + } + if ( var7 ) { + bestmatch.variables[7].ptr = var7; + bestmatch.variables[7].length = strlen( var7 ); + } + if ( LibVarGetValue( "bot_testrchat" ) ) { + for ( m = bestrchat->firstchatmessage; m; m = m->next ) + { + BotConstructChatMessage( cs, m->chatmessage, mcontext, bestmatch.variables, vcontext, qtrue ); + BotRemoveTildes( cs->chatmessage ); + botimport.Print( PRT_MESSAGE, "%s\n", cs->chatmessage ); + } //end if + } //end if + else + { + bestchatmessage->time = AAS_Time() + CHATMESSAGE_RECENTTIME; + BotConstructChatMessage( cs, bestchatmessage->chatmessage, mcontext, bestmatch.variables, vcontext, qtrue ); + } //end else + return qtrue; + } //end if + return qfalse; +} //end of the function BotReplyChat +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int BotChatLength( int chatstate ) { + bot_chatstate_t *cs; + + cs = BotChatStateFromHandle( chatstate ); + if ( !cs ) { + return 0; + } + return strlen( cs->chatmessage ); +} //end of the function BotChatLength +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void BotEnterChat( int chatstate, int client, int sendto ) { + bot_chatstate_t *cs; + + cs = BotChatStateFromHandle( chatstate ); + if ( !cs ) { + return; + } + + if ( strlen( cs->chatmessage ) ) { + BotRemoveTildes( cs->chatmessage ); + if ( LibVarGetValue( "bot_testichat" ) ) { + botimport.Print( PRT_MESSAGE, "%s\n", cs->chatmessage ); + } else { + if ( sendto == CHAT_TEAM ) { + EA_SayTeam( client, cs->chatmessage ); + } else { EA_Say( client, cs->chatmessage );} + } + //clear the chat message from the state + strcpy( cs->chatmessage, "" ); + } //end if +} //end of the function BotEnterChat +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void BotGetChatMessage( int chatstate, char *buf, int size ) { + bot_chatstate_t *cs; + + cs = BotChatStateFromHandle( chatstate ); + if ( !cs ) { + return; + } + + BotRemoveTildes( cs->chatmessage ); + strncpy( buf, cs->chatmessage, size - 1 ); + buf[size - 1] = '\0'; + //clear the chat message from the state + strcpy( cs->chatmessage, "" ); +} //end of the function BotGetChatMessage +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void BotSetChatGender( int chatstate, int gender ) { + bot_chatstate_t *cs; + + cs = BotChatStateFromHandle( chatstate ); + if ( !cs ) { + return; + } + switch ( gender ) + { + case CHAT_GENDERFEMALE: cs->gender = CHAT_GENDERFEMALE; break; + case CHAT_GENDERMALE: cs->gender = CHAT_GENDERMALE; break; + default: cs->gender = CHAT_GENDERLESS; break; + } //end switch +} //end of the function BotSetChatGender +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void BotSetChatName( int chatstate, char *name ) { + bot_chatstate_t *cs; + + cs = BotChatStateFromHandle( chatstate ); + if ( !cs ) { + return; + } + memset( cs->name, 0, sizeof( cs->name ) ); + strncpy( cs->name, name, sizeof( cs->name ) ); + cs->name[sizeof( cs->name ) - 1] = '\0'; +} //end of the function BotSetChatName +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void BotResetChatAI( void ) { + bot_replychat_t *rchat; + bot_chatmessage_t *m; + + for ( rchat = replychats; rchat; rchat = rchat->next ) + { + for ( m = rchat->firstchatmessage; m; m = m->next ) + { + m->time = 0; + } //end for + } //end for +} //end of the function BotResetChatAI +//======================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//======================================================================== +int BotAllocChatState( void ) { + int i; + + for ( i = 1; i <= MAX_CLIENTS; i++ ) + { + if ( !botchatstates[i] ) { + botchatstates[i] = GetClearedMemory( sizeof( bot_chatstate_t ) ); + return i; + } //end if + } //end for + return 0; +} //end of the function BotAllocChatState +//======================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//======================================================================== +void BotFreeChatState( int handle ) { + bot_chatstate_t *cs; + bot_consolemessage_t m; + int h; + + if ( handle <= 0 || handle > MAX_CLIENTS ) { + botimport.Print( PRT_FATAL, "chat state handle %d out of range\n", handle ); + return; + } //end if + if ( !botchatstates[handle] ) { + botimport.Print( PRT_FATAL, "invalid chat state %d\n", handle ); + return; + } //end if + cs = botchatstates[handle]; + if ( LibVarGetValue( "bot_reloadcharacters" ) ) { + BotFreeChatFile( handle ); + } //end if + //free all the console messages left in the chat state + for ( h = BotNextConsoleMessage( handle, &m ); h; h = BotNextConsoleMessage( handle, &m ) ) + { + //remove the console message + BotRemoveConsoleMessage( handle, h ); + } //end for + FreeMemory( botchatstates[handle] ); + botchatstates[handle] = NULL; +} //end of the function BotFreeChatState +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int BotSetupChatAI( void ) { + char *file; + +#ifdef DEBUG + int starttime = Sys_MilliSeconds(); +#endif //DEBUG + + file = LibVarString( "synfile", "syn.c" ); + synonyms = BotLoadSynonyms( file ); + file = LibVarString( "rndfile", "rnd.c" ); + randomstrings = BotLoadRandomStrings( file ); + file = LibVarString( "matchfile", "match.c" ); + matchtemplates = BotLoadMatchTemplates( file ); + // + if ( !LibVarValue( "nochat", "0" ) ) { + file = LibVarString( "rchatfile", "rchat.c" ); + replychats = BotLoadReplyChat( file ); + } //end if + + InitConsoleMessageHeap(); + +#ifdef DEBUG + botimport.Print( PRT_MESSAGE, "setup chat AI %d msec\n", Sys_MilliSeconds() - starttime ); +#endif //DEBUG + return BLERR_NOERROR; +} //end of the function BotSetupChatAI +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void BotShutdownChatAI( void ) { + int i; + + //free all remaining chat states + for ( i = 0; i < MAX_CLIENTS; i++ ) + { + if ( botchatstates[i] ) { + BotFreeChatState( i ); + } //end if + } //end for + //free all cached chats + for ( i = 0; i < MAX_CLIENTS; i++ ) + { + if ( ichatdata[i].inuse ) { + FreeMemory( ichatdata[i].chat ); + ichatdata[i].inuse = qfalse; + } //end if + } //end for + if ( consolemessageheap ) { + FreeMemory( consolemessageheap ); + } + consolemessageheap = NULL; + if ( matchtemplates ) { + BotFreeMatchTemplates( matchtemplates ); + } + matchtemplates = NULL; + if ( randomstrings ) { + FreeMemory( randomstrings ); + } + randomstrings = NULL; + if ( synonyms ) { + FreeMemory( synonyms ); + } + synonyms = NULL; + if ( replychats ) { + BotFreeReplyChat( replychats ); + } + replychats = NULL; +} //end of the function BotShutdownChatAI diff --git a/Projects/Android/jni/rtcw/src/botlib/be_ai_gen.c b/Projects/Android/jni/rtcw/src/botlib/be_ai_gen.c new file mode 100644 index 0000000..697f030 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/botlib/be_ai_gen.c @@ -0,0 +1,151 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +/***************************************************************************** + * name: be_ai_gen.c + * + * desc: genetic selection + * + * + *****************************************************************************/ + +#include "../game/q_shared.h" +#include "l_memory.h" +#include "l_log.h" +#include "l_utils.h" +#include "l_script.h" +#include "l_precomp.h" +#include "l_struct.h" +#include "aasfile.h" +#include "../game/botlib.h" +#include "../game/be_aas.h" +#include "be_aas_funcs.h" +#include "be_interface.h" +#include "../game/be_ai_gen.h" + +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int GeneticSelection( int numranks, float *rankings ) { + float sum, select; + int i, index; + + sum = 0; + for ( i = 0; i < numranks; i++ ) + { + if ( rankings[i] < 0 ) { + continue; + } + sum += rankings[i]; + } //end for + if ( sum > 0 ) { + //select a bot where the ones with the higest rankings have + //the highest chance of being selected + select = random() * sum; + for ( i = 0; i < numranks; i++ ) + { + if ( rankings[i] < 0 ) { + continue; + } + sum -= rankings[i]; + if ( sum <= 0 ) { + return i; + } + } //end for + } //end if + //select a bot randomly + index = random() * numranks; + for ( i = 0; i < numranks; i++ ) + { + if ( rankings[index] >= 0 ) { + return index; + } + index = ( index + 1 ) % numranks; + } //end for + return 0; +} //end of the function GeneticSelection +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int GeneticParentsAndChildSelection( int numranks, float *ranks, int *parent1, int *parent2, int *child ) { + float rankings[256], max; + int i; + + if ( numranks > 256 ) { + botimport.Print( PRT_WARNING, "GeneticParentsAndChildSelection: too many bots\n" ); + *parent1 = *parent2 = *child = 0; + return qfalse; + } //end if + for ( max = 0, i = 0; i < numranks; i++ ) + { + if ( ranks[i] < 0 ) { + continue; + } + max++; + } //end for + if ( max < 3 ) { + botimport.Print( PRT_WARNING, "GeneticParentsAndChildSelection: too few valid bots\n" ); + *parent1 = *parent2 = *child = 0; + return qfalse; + } //end if + memcpy( rankings, ranks, sizeof( float ) * numranks ); + //select first parent + *parent1 = GeneticSelection( numranks, rankings ); + rankings[*parent1] = -1; + //select second parent + *parent2 = GeneticSelection( numranks, rankings ); + rankings[*parent2] = -1; + //reverse the rankings + max = 0; + for ( i = 0; i < numranks; i++ ) + { + if ( rankings[i] < 0 ) { + continue; + } + if ( rankings[i] > max ) { + max = rankings[i]; + } + } //end for + for ( i = 0; i < numranks; i++ ) + { + if ( rankings[i] < 0 ) { + continue; + } + rankings[i] = max - rankings[i]; + } //end for + //select child + *child = GeneticSelection( numranks, rankings ); + return qtrue; +} //end of the function GeneticParentsAndChildSelection diff --git a/Projects/Android/jni/rtcw/src/botlib/be_ai_goal.c b/Projects/Android/jni/rtcw/src/botlib/be_ai_goal.c new file mode 100644 index 0000000..6b24cd1 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/botlib/be_ai_goal.c @@ -0,0 +1,1630 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +/***************************************************************************** + * name: be_ai_goal.c + * + * desc: goal AI + * + * + *****************************************************************************/ + +#include "../game/q_shared.h" +#include "l_utils.h" +#include "l_libvar.h" +#include "l_memory.h" +#include "l_log.h" +#include "l_script.h" +#include "l_precomp.h" +#include "l_struct.h" +#include "aasfile.h" +#include "../game/botlib.h" +#include "../game/be_aas.h" +#include "be_aas_funcs.h" +#include "be_interface.h" +#include "be_ai_weight.h" +#include "../game/be_ai_goal.h" +#include "../game/be_ai_move.h" + +//#define DEBUG_AI_GOAL +#ifdef RANDOMIZE +#define UNDECIDEDFUZZY +#endif //RANDOMIZE +#define DROPPEDWEIGHT +//avoid goal time +#define AVOID_TIME 30 +//avoid dropped goal time +#define AVOIDDROPPED_TIME 5 +// +#define TRAVELTIME_SCALE 0.01 + +//location in the map "target_location" +typedef struct maplocation_s +{ + vec3_t origin; + int areanum; + char name[MAX_EPAIRKEY]; + struct maplocation_s *next; +} maplocation_t; + +//camp spots "info_camp" +typedef struct campspot_s +{ + vec3_t origin; + int areanum; + char name[MAX_EPAIRKEY]; + float range; + float weight; + float wait; + float random; + struct campspot_s *next; +} campspot_t; + +//FIXME: these are game specific +typedef enum { + GT_FFA, // free for all + GT_TOURNAMENT, // one on one tournament + GT_SINGLE_PLAYER, // single player tournament + + //-- team games go after this -- + + GT_TEAM, // team deathmatch + GT_CTF, // capture the flag + + GT_MAX_GAME_TYPE +} gametype_t; + +// Rafael gameskill +typedef enum { + GSKILL_EASY, + GSKILL_MEDIUM, + GSKILL_HARD, // normal default level + GSKILL_MAX +} gameskill_t; + +typedef struct levelitem_s +{ + int number; //number of the level item + int iteminfo; //index into the item info + int notteam; //true if not in teamplay + int notfree; //true if not in ffa + int notsingle; //true if not in single + vec3_t origin; //origin of the item + int goalareanum; //area the item is in + vec3_t goalorigin; //goal origin within the area + int entitynum; //entity number + float timeout; //item is removed after this time + struct levelitem_s *prev, *next; +} levelitem_t; + +typedef struct iteminfo_s +{ + char classname[32]; //classname of the item + char name[MAX_STRINGFIELD]; //name of the item + char model[MAX_STRINGFIELD]; //model of the item + int modelindex; //model index + int type; //item type + int index; //index in the inventory + float respawntime; //respawn time + vec3_t mins; //mins of the item + vec3_t maxs; //maxs of the item + int number; //number of the item info +} iteminfo_t; + +#define ITEMINFO_OFS( x ) (int)&( ( (iteminfo_t *)0 )->x ) + +fielddef_t iteminfo_fields[] = +{ + {"name", ITEMINFO_OFS( name ), FT_STRING}, + {"model", ITEMINFO_OFS( model ), FT_STRING}, + {"modelindex", ITEMINFO_OFS( modelindex ), FT_INT}, + {"type", ITEMINFO_OFS( type ), FT_INT}, + {"index", ITEMINFO_OFS( index ), FT_INT}, + {"respawntime", ITEMINFO_OFS( respawntime ), FT_FLOAT}, + {"mins", ITEMINFO_OFS( mins ), FT_FLOAT | FT_ARRAY, 3}, + {"maxs", ITEMINFO_OFS( maxs ), FT_FLOAT | FT_ARRAY, 3}, + {0, 0, 0} +}; + +structdef_t iteminfo_struct = +{ + sizeof( iteminfo_t ), iteminfo_fields +}; + +typedef struct itemconfig_s +{ + int numiteminfo; + iteminfo_t *iteminfo; +} itemconfig_t; + +//goal state +typedef struct bot_goalstate_s +{ + struct weightconfig_s *itemweightconfig; //weight config + int *itemweightindex; //index from item to weight + // + int client; //client using this goal state + int lastreachabilityarea; //last area with reachabilities the bot was in + // + bot_goal_t goalstack[MAX_GOALSTACK]; //goal stack + int goalstacktop; //the top of the goal stack + // + int avoidgoals[MAX_AVOIDGOALS]; //goals to avoid + float avoidgoaltimes[MAX_AVOIDGOALS]; //times to avoid the goals +} bot_goalstate_t; + +bot_goalstate_t *botgoalstates[MAX_CLIENTS + 1]; +//item configuration +itemconfig_t *itemconfig = NULL; +//level items +levelitem_t *levelitemheap = NULL; +levelitem_t *freelevelitems = NULL; +levelitem_t *levelitems = NULL; +int numlevelitems = 0; +//map locations +maplocation_t *maplocations = NULL; +//camp spots +campspot_t *campspots = NULL; +//the game type +int g_gametype; + +// Rafael gameskill +int g_gameskill; +// done + +//======================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//======================================================================== +bot_goalstate_t *BotGoalStateFromHandle( int handle ) { + if ( handle <= 0 || handle > MAX_CLIENTS ) { + botimport.Print( PRT_FATAL, "goal state handle %d out of range\n", handle ); + return NULL; + } //end if + if ( !botgoalstates[handle] ) { + botimport.Print( PRT_FATAL, "invalid goal state %d\n", handle ); + return NULL; + } //end if + return botgoalstates[handle]; +} //end of the function BotGoalStateFromHandle +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void BotInterbreedGoalFuzzyLogic( int parent1, int parent2, int child ) { + bot_goalstate_t *p1, *p2, *c; + + p1 = BotGoalStateFromHandle( parent1 ); + p2 = BotGoalStateFromHandle( parent2 ); + c = BotGoalStateFromHandle( child ); + + InterbreedWeightConfigs( p1->itemweightconfig, p2->itemweightconfig, + c->itemweightconfig ); +} //end of the function BotInterbreedingGoalFuzzyLogic +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void BotSaveGoalFuzzyLogic( int goalstate, char *filename ) { + bot_goalstate_t *gs; + + gs = BotGoalStateFromHandle( goalstate ); + + //WriteWeightConfig(filename, gs->itemweightconfig); +} //end of the function BotSaveGoalFuzzyLogic +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void BotMutateGoalFuzzyLogic( int goalstate, float range ) { + bot_goalstate_t *gs; + + gs = BotGoalStateFromHandle( goalstate ); + + EvolveWeightConfig( gs->itemweightconfig ); +} //end of the function BotMutateGoalFuzzyLogic +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +itemconfig_t *LoadItemConfig( char *filename ) { + int max_iteminfo; + token_t token; + char path[MAX_PATH]; + source_t *source; + itemconfig_t *ic; + iteminfo_t *ii; + + max_iteminfo = (int) LibVarValue( "max_iteminfo", "256" ); + if ( max_iteminfo < 0 ) { + botimport.Print( PRT_ERROR, "max_iteminfo = %d\n", max_iteminfo ); + max_iteminfo = 128; + LibVarSet( "max_iteminfo", "128" ); + } + + strncpy( path, filename, MAX_PATH ); + source = LoadSourceFile( path ); + if ( !source ) { + botimport.Print( PRT_ERROR, "counldn't load %s\n", path ); + return NULL; + } //end if + //initialize item config + ic = (itemconfig_t *) GetClearedHunkMemory( sizeof( itemconfig_t ) + + max_iteminfo * sizeof( iteminfo_t ) ); + ic->iteminfo = ( iteminfo_t * )( (char *) ic + sizeof( itemconfig_t ) ); + ic->numiteminfo = 0; + //parse the item config file + while ( PC_ReadToken( source, &token ) ) + { + if ( !strcmp( token.string, "iteminfo" ) ) { + if ( ic->numiteminfo >= max_iteminfo ) { + SourceError( source, "more than %d item info defined\n", max_iteminfo ); + FreeMemory( ic ); + FreeSource( source ); + return NULL; + } //end if + ii = &ic->iteminfo[ic->numiteminfo]; + memset( ii, 0, sizeof( iteminfo_t ) ); + if ( !PC_ExpectTokenType( source, TT_STRING, 0, &token ) ) { + FreeMemory( ic ); + FreeMemory( source ); + return NULL; + } //end if + StripDoubleQuotes( token.string ); + strncpy( ii->classname, token.string, sizeof( ii->classname ) - 1 ); + if ( !ReadStructure( source, &iteminfo_struct, (char *) ii ) ) { + FreeMemory( ic ); + FreeSource( source ); + return NULL; + } //end if + ii->number = ic->numiteminfo; + ic->numiteminfo++; + } //end if + else + { + SourceError( source, "unknown definition %s\n", token.string ); + FreeMemory( ic ); + FreeSource( source ); + return NULL; + } //end else + } //end while + FreeSource( source ); + // + if ( !ic->numiteminfo ) { + botimport.Print( PRT_WARNING, "no item info loaded\n" ); + } + botimport.Print( PRT_MESSAGE, "loaded %s\n", path ); + return ic; +} //end of the function LoadItemConfig +//=========================================================================== +// index to find the weight function of an iteminfo +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int *ItemWeightIndex( weightconfig_t *iwc, itemconfig_t *ic ) { + int *index, i; + + //initialize item weight index + index = (int *) GetClearedMemory( sizeof( int ) * ic->numiteminfo ); + + for ( i = 0; i < ic->numiteminfo; i++ ) + { + index[i] = FindFuzzyWeight( iwc, ic->iteminfo[i].classname ); + if ( index[i] < 0 ) { + Log_Write( "item info %d \"%s\" has no fuzzy weight\r\n", i, ic->iteminfo[i].classname ); + } //end if + } //end for + return index; +} //end of the function ItemWeightIndex +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void InitLevelItemHeap( void ) { + int i, max_levelitems; + + if ( levelitemheap ) { + FreeMemory( levelitemheap ); + } + + max_levelitems = (int) LibVarValue( "max_levelitems", "256" ); + levelitemheap = (levelitem_t *) GetMemory( max_levelitems * sizeof( levelitem_t ) ); + + for ( i = 0; i < max_levelitems - 2; i++ ) + { + levelitemheap[i].next = &levelitemheap[i + 1]; + } //end for + levelitemheap[max_levelitems - 1].next = NULL; + // + freelevelitems = levelitemheap; +} //end of the function InitLevelItemHeap +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +levelitem_t *AllocLevelItem( void ) { + levelitem_t *li; + + li = freelevelitems; + if ( !li ) { + botimport.Print( PRT_FATAL, "out of level items\n" ); + return NULL; + } //end if + // + freelevelitems = freelevelitems->next; + memset( li, 0, sizeof( levelitem_t ) ); + return li; +} //end of the function AllocLevelItem +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void FreeLevelItem( levelitem_t *li ) { + li->next = freelevelitems; + freelevelitems = li; +} //end of the function FreeLevelItem +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AddLevelItemToList( levelitem_t *li ) { + if ( levelitems ) { + levelitems->prev = li; + } + li->prev = NULL; + li->next = levelitems; + levelitems = li; +} //end of the function AddLevelItemToList +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void RemoveLevelItemFromList( levelitem_t *li ) { + if ( li->prev ) { + li->prev->next = li->next; + } else { levelitems = li->next;} + if ( li->next ) { + li->next->prev = li->prev; + } +} //end of the function RemoveLevelItemFromList +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void BotFreeInfoEntities( void ) { + maplocation_t *ml, *nextml; + campspot_t *cs, *nextcs; + + for ( ml = maplocations; ml; ml = nextml ) + { + nextml = ml->next; + FreeMemory( ml ); + } //end for + maplocations = NULL; + for ( cs = campspots; cs; cs = nextcs ) + { + nextcs = cs->next; + FreeMemory( cs ); + } //end for + campspots = NULL; +} //end of the function BotFreeInfoEntities +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void BotInitInfoEntities( void ) { + char classname[MAX_EPAIRKEY]; + maplocation_t *ml; + campspot_t *cs; + int ent, numlocations, numcampspots; + + BotFreeInfoEntities(); + // + numlocations = 0; + numcampspots = 0; + for ( ent = AAS_NextBSPEntity( 0 ); ent; ent = AAS_NextBSPEntity( ent ) ) + { + if ( !AAS_ValueForBSPEpairKey( ent, "classname", classname, MAX_EPAIRKEY ) ) { + continue; + } + + //map locations + if ( !strcmp( classname, "target_location" ) ) { + ml = (maplocation_t *) GetClearedMemory( sizeof( maplocation_t ) ); + AAS_VectorForBSPEpairKey( ent, "origin", ml->origin ); + AAS_ValueForBSPEpairKey( ent, "message", ml->name, sizeof( ml->name ) ); + ml->areanum = AAS_PointAreaNum( ml->origin ); + ml->next = maplocations; + maplocations = ml; + numlocations++; + } //end if + //camp spots + else if ( !strcmp( classname, "info_camp" ) ) { + cs = (campspot_t *) GetClearedMemory( sizeof( campspot_t ) ); + AAS_VectorForBSPEpairKey( ent, "origin", cs->origin ); + //cs->origin[2] += 16; + AAS_ValueForBSPEpairKey( ent, "message", cs->name, sizeof( cs->name ) ); + AAS_FloatForBSPEpairKey( ent, "range", &cs->range ); + AAS_FloatForBSPEpairKey( ent, "weight", &cs->weight ); + AAS_FloatForBSPEpairKey( ent, "wait", &cs->wait ); + AAS_FloatForBSPEpairKey( ent, "random", &cs->random ); + cs->areanum = AAS_PointAreaNum( cs->origin ); + if ( !cs->areanum ) { + botimport.Print( PRT_MESSAGE, "camp spot at %1.1f %1.1f %1.1f in solid\n", cs->origin[0], cs->origin[1], cs->origin[2] ); + FreeMemory( cs ); + continue; + } //end if + cs->next = campspots; + campspots = cs; + //AAS_DrawPermanentCross(cs->origin, 4, LINECOLOR_YELLOW); + numcampspots++; + } //end else if + } //end for + if ( bot_developer ) { + botimport.Print( PRT_MESSAGE, "%d map locations\n", numlocations ); + botimport.Print( PRT_MESSAGE, "%d camp spots\n", numcampspots ); + } //end if +} //end of the function BotInitInfoEntities +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void BotInitLevelItems( void ) { + int i, spawnflags; + char classname[MAX_EPAIRKEY]; + vec3_t origin; + int ent; + itemconfig_t *ic; + levelitem_t *li; + + //initialize the map locations and camp spots + BotInitInfoEntities(); + + //initialize the level item heap + InitLevelItemHeap(); + levelitems = NULL; + numlevelitems = 0; + // + ic = itemconfig; + if ( !ic ) { + return; + } + + //if there's no AAS file loaded + if ( !AAS_Loaded() ) { + return; + } + + //update the modelindexes of the item info + for ( i = 0; i < ic->numiteminfo; i++ ) + { + //ic->iteminfo[i].modelindex = AAS_IndexFromModel(ic->iteminfo[i].model); + if ( !ic->iteminfo[i].modelindex ) { + Log_Write( "item %s has modelindex 0", ic->iteminfo[i].classname ); + } //end if + } //end for + + for ( ent = AAS_NextBSPEntity( 0 ); ent; ent = AAS_NextBSPEntity( ent ) ) + { + if ( !AAS_ValueForBSPEpairKey( ent, "classname", classname, MAX_EPAIRKEY ) ) { + continue; + } + // + spawnflags = 0; + AAS_IntForBSPEpairKey( ent, "spawnflags", &spawnflags ); + //FIXME: don't do this + // for now skip all floating entities + if ( spawnflags & 1 ) { + continue; + } + // + for ( i = 0; i < ic->numiteminfo; i++ ) + { + if ( !strcmp( classname, ic->iteminfo[i].classname ) ) { + //get the origin of the item + if ( AAS_VectorForBSPEpairKey( ent, "origin", origin ) ) { + li = AllocLevelItem(); + if ( !li ) { + return; + } + // + li->number = ++numlevelitems; + li->timeout = 0; + li->entitynum = 0; + // + AAS_IntForBSPEpairKey( ent, "notfree", &li->notfree ); + AAS_IntForBSPEpairKey( ent, "notteam", &li->notteam ); + AAS_IntForBSPEpairKey( ent, "notsingle", &li->notsingle ); + //if not a stationary item + if ( !( spawnflags & 1 ) ) { + if ( !AAS_DropToFloor( origin, ic->iteminfo[i].mins, ic->iteminfo[i].maxs ) ) { + botimport.Print( PRT_MESSAGE, "%s in solid at (%1.1f %1.1f %1.1f)\n", + classname, origin[0], origin[1], origin[2] ); + } //end if + } //end if + //item info of the level item + li->iteminfo = i; + //origin of the item + VectorCopy( origin, li->origin ); + //get the item goal area and goal origin + li->goalareanum = AAS_BestReachableArea( origin, + ic->iteminfo[i].mins, ic->iteminfo[i].maxs, + li->goalorigin ); + // + AddLevelItemToList( li ); + } //end if + else + { + botimport.Print( PRT_ERROR, "item %s without origin\n", classname ); + } //end else + break; + } //end if + } //end for + if ( i >= ic->numiteminfo ) { + Log_Write( "entity %s unknown item\r\n", classname ); + } //end if + } //end for + botimport.Print( PRT_MESSAGE, "found %d level items\n", numlevelitems ); +} //end of the function BotInitLevelItems +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void BotGoalName( int number, char *name, int size ) { + levelitem_t *li; + + if ( !itemconfig ) { + return; + } + // + for ( li = levelitems; li; li = li->next ) + { + if ( li->number == number ) { + strncpy( name, itemconfig->iteminfo[li->iteminfo].name, size - 1 ); + name[size - 1] = '\0'; + return; + } //end for + } //end for + strcpy( name, "" ); + return; +} //end of the function BotGoalName +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void BotResetAvoidGoals( int goalstate ) { + bot_goalstate_t *gs; + + gs = BotGoalStateFromHandle( goalstate ); + if ( !gs ) { + return; + } + memset( gs->avoidgoals, 0, MAX_AVOIDGOALS * sizeof( int ) ); + memset( gs->avoidgoaltimes, 0, MAX_AVOIDGOALS * sizeof( float ) ); +} //end of the function BotResetAvoidGoals +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void BotDumpAvoidGoals( int goalstate ) { + int i; + bot_goalstate_t *gs; + char name[32]; + + gs = BotGoalStateFromHandle( goalstate ); + if ( !gs ) { + return; + } + for ( i = 0; i < MAX_AVOIDGOALS; i++ ) + { + if ( gs->avoidgoaltimes[i] >= AAS_Time() ) { + BotGoalName( gs->avoidgoals[i], name, 32 ); + Log_Write( "avoid goal %s, number %d for %f seconds", name, + gs->avoidgoals[i], gs->avoidgoaltimes[i] - AAS_Time() ); + } //end if + } //end for +} //end of the function BotDumpAvoidGoals +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void BotAddToAvoidGoals( bot_goalstate_t *gs, int number, float avoidtime ) { + int i; + + for ( i = 0; i < MAX_AVOIDGOALS; i++ ) + { + //if this avoid goal has expired + if ( gs->avoidgoaltimes[i] < AAS_Time() ) { + gs->avoidgoals[i] = number; + gs->avoidgoaltimes[i] = AAS_Time() + avoidtime; + return; + } //end if + } //end for +} //end of the function BotAddToAvoidGoals +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void BotRemoveFromAvoidGoals( int goalstate, int number ) { + int i; + bot_goalstate_t *gs; + + gs = BotGoalStateFromHandle( goalstate ); + if ( !gs ) { + return; + } + //don't use the goals the bot wants to avoid + for ( i = 0; i < MAX_AVOIDGOALS; i++ ) + { + if ( gs->avoidgoals[i] == number && gs->avoidgoaltimes[i] >= AAS_Time() ) { + gs->avoidgoaltimes[i] = 0; + return; + } //end if + } //end for +} //end of the function BotRemoveFromAvoidGoals +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +float BotAvoidGoalTime( int goalstate, int number ) { + int i; + bot_goalstate_t *gs; + + gs = BotGoalStateFromHandle( goalstate ); + if ( !gs ) { + return 0; + } + //don't use the goals the bot wants to avoid + for ( i = 0; i < MAX_AVOIDGOALS; i++ ) + { + if ( gs->avoidgoals[i] == number && gs->avoidgoaltimes[i] >= AAS_Time() ) { + return gs->avoidgoaltimes[i] - AAS_Time(); + } //end if + } //end for + return 0; +} //end of the function BotAvoidGoalTime +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int BotGetLevelItemGoal( int index, char *name, bot_goal_t *goal ) { + levelitem_t *li; + + if ( !itemconfig ) { + return -1; + } + for ( li = levelitems; li; li = li->next ) + { + if ( li->number <= index ) { + continue; + } + // + if ( g_gametype == GT_SINGLE_PLAYER ) { + if ( li->notsingle ) { + continue; + } + } else if ( g_gametype >= GT_TEAM ) { + if ( li->notteam ) { + continue; + } + } else { + if ( li->notfree ) { + continue; + } + } + // + if ( !Q_stricmp( name, itemconfig->iteminfo[li->iteminfo].name ) ) { + goal->areanum = li->goalareanum; + VectorCopy( li->goalorigin, goal->origin ); + goal->entitynum = li->entitynum; + VectorCopy( itemconfig->iteminfo[li->iteminfo].mins, goal->mins ); + VectorCopy( itemconfig->iteminfo[li->iteminfo].maxs, goal->maxs ); + goal->number = li->number; + //botimport.Print(PRT_MESSAGE, "found li %s\n", itemconfig->iteminfo[li->iteminfo].name); + return li->number; + } //end if + } //end for + return -1; +} //end of the function BotGetLevelItemGoal +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int BotGetMapLocationGoal( char *name, bot_goal_t *goal ) { + maplocation_t *ml; + vec3_t mins = {-8, -8, -8}, maxs = {8, 8, 8}; + + for ( ml = maplocations; ml; ml = ml->next ) + { + if ( !Q_stricmp( ml->name, name ) ) { + goal->areanum = ml->areanum; + VectorCopy( ml->origin, goal->origin ); + goal->entitynum = 0; + VectorCopy( mins, goal->mins ); + VectorCopy( maxs, goal->maxs ); + return qtrue; + } //end if + } //end for + return qfalse; +} //end of the function BotGetMapLocationGoal +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int BotGetNextCampSpotGoal( int num, bot_goal_t *goal ) { + int i; + campspot_t *cs; + vec3_t mins = {-8, -8, -8}, maxs = {8, 8, 8}; + + if ( num < 0 ) { + num = 0; + } + i = num; + for ( cs = campspots; cs; cs = cs->next ) + { + if ( --i < 0 ) { + goal->areanum = cs->areanum; + VectorCopy( cs->origin, goal->origin ); + goal->entitynum = 0; + VectorCopy( mins, goal->mins ); + VectorCopy( maxs, goal->maxs ); + return num + 1; + } //end if + } //end for + return 0; +} //end of the function BotGetNextCampSpotGoal +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== + +//NOTE: enum entityType_t in bg_public.h +#define ET_ITEM 2 + +void BotUpdateEntityItems( void ) { + int ent, i, modelindex; + vec3_t dir; + levelitem_t *li, *nextli; + aas_entityinfo_t entinfo; + itemconfig_t *ic; + + //timeout current entity items if necessary + for ( li = levelitems; li; li = nextli ) + { + nextli = li->next; + //if it is a item that will time out + if ( li->timeout ) { + //timeout the item + if ( li->timeout < AAS_Time() ) { + RemoveLevelItemFromList( li ); + FreeLevelItem( li ); + } //end if + } //end if + } //end for + //find new entity items + ic = itemconfig; + if ( !itemconfig ) { + return; + } + // + for ( ent = AAS_NextEntity( 0 ); ent; ent = AAS_NextEntity( ent ) ) + { + if ( AAS_EntityType( ent ) != ET_ITEM ) { + continue; + } + //get the model index of the entity + modelindex = AAS_EntityModelindex( ent ); + // + if ( !modelindex ) { + continue; + } + //get info about the entity + AAS_EntityInfo( ent, &entinfo ); + //FIXME: don't do this + //skip all floating items for now + if ( entinfo.groundent != ENTITYNUM_WORLD ) { + continue; + } + //if the entity is still moving + if ( entinfo.origin[0] != entinfo.lastvisorigin[0] || + entinfo.origin[1] != entinfo.lastvisorigin[1] || + entinfo.origin[2] != entinfo.lastvisorigin[2] ) { + continue; + } + //check if the level item isn't already stored + for ( li = levelitems; li; li = li->next ) + { + //if the model of the level item and the entity are different + if ( ic->iteminfo[li->iteminfo].modelindex != modelindex ) { + continue; + } + //if the level item is linked to an entity + if ( li->entitynum ) { + if ( li->entitynum == ent ) { + VectorCopy( entinfo.origin, li->origin ); + break; + } //end if + } //end if + else + { + //check if the entity is very close + VectorSubtract( li->origin, entinfo.origin, dir ); + if ( VectorLength( dir ) < 30 ) { + //found an entity for this level item + li->entitynum = ent; + //keep updating the entity origin + VectorCopy( entinfo.origin, li->origin ); + //also update the goal area number + li->goalareanum = AAS_BestReachableArea( li->origin, + ic->iteminfo[li->iteminfo].mins, ic->iteminfo[li->iteminfo].maxs, + li->goalorigin ); + //Log_Write("found item %s entity", ic->iteminfo[li->iteminfo].classname); + break; + } //end if + //else botimport.Print(PRT_MESSAGE, "item %s has no attached entity\n", + // ic->iteminfo[li->iteminfo].name); + } //end else + } //end for + if ( li ) { + continue; + } + //check if the model is from a known item + for ( i = 0; i < ic->numiteminfo; i++ ) + { + if ( ic->iteminfo[i].modelindex == modelindex ) { + break; + } //end if + } //end for + //if the model is not from a known item + if ( i >= ic->numiteminfo ) { + continue; + } + //allocate a new level item + li = AllocLevelItem(); + // + if ( !li ) { + continue; + } + //entity number of the level item + li->entitynum = ent; + //number for the level item + li->number = numlevelitems + ent; + //set the item info index for the level item + li->iteminfo = i; + //origin of the item + VectorCopy( entinfo.origin, li->origin ); + //get the item goal area and goal origin + li->goalareanum = AAS_BestReachableArea( li->origin, + ic->iteminfo[i].mins, ic->iteminfo[i].maxs, + li->goalorigin ); + // + if ( AAS_AreaJumpPad( li->goalareanum ) ) { + FreeLevelItem( li ); + continue; + } //end if + //time this item out after 30 seconds + //dropped items disappear after 30 seconds + li->timeout = AAS_Time() + 30; + //add the level item to the list + AddLevelItemToList( li ); + //botimport.Print(PRT_MESSAGE, "found new level item %s\n", ic->iteminfo[i].classname); + } //end for +} //end of the function BotUpdateEntityItems +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void BotDumpGoalStack( int goalstate ) { + int i; + bot_goalstate_t *gs; + char name[32]; + + gs = BotGoalStateFromHandle( goalstate ); + if ( !gs ) { + return; + } + for ( i = 1; i <= gs->goalstacktop; i++ ) + { + BotGoalName( gs->goalstack[i].number, name, 32 ); + Log_Write( "%d: %s", i, name ); + } //end for +} //end of the function BotDumpGoalStack +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void BotPushGoal( int goalstate, bot_goal_t *goal ) { + bot_goalstate_t *gs; + + gs = BotGoalStateFromHandle( goalstate ); + if ( !gs ) { + return; + } + if ( gs->goalstacktop >= MAX_GOALSTACK - 1 ) { + botimport.Print( PRT_ERROR, "goal heap overflow\n" ); + BotDumpGoalStack( goalstate ); + return; + } //end if + gs->goalstacktop++; + memcpy( &gs->goalstack[gs->goalstacktop], goal, sizeof( bot_goal_t ) ); +} //end of the function BotPushGoal +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void BotPopGoal( int goalstate ) { + bot_goalstate_t *gs; + + gs = BotGoalStateFromHandle( goalstate ); + if ( !gs ) { + return; + } + if ( gs->goalstacktop > 0 ) { + gs->goalstacktop--; + } +} //end of the function BotPopGoal +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void BotEmptyGoalStack( int goalstate ) { + bot_goalstate_t *gs; + + gs = BotGoalStateFromHandle( goalstate ); + if ( !gs ) { + return; + } + gs->goalstacktop = 0; +} //end of the function BotEmptyGoalStack +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int BotGetTopGoal( int goalstate, bot_goal_t *goal ) { + bot_goalstate_t *gs; + + gs = BotGoalStateFromHandle( goalstate ); + if ( !gs ) { + return qfalse; + } + if ( !gs->goalstacktop ) { + return qfalse; + } + memcpy( goal, &gs->goalstack[gs->goalstacktop], sizeof( bot_goal_t ) ); + return qtrue; +} //end of the function BotGetTopGoal +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int BotGetSecondGoal( int goalstate, bot_goal_t *goal ) { + bot_goalstate_t *gs; + + gs = BotGoalStateFromHandle( goalstate ); + if ( !gs ) { + return qfalse; + } + if ( gs->goalstacktop <= 1 ) { + return qfalse; + } + memcpy( goal, &gs->goalstack[gs->goalstacktop - 1], sizeof( bot_goal_t ) ); + return qtrue; +} //end of the function BotGetSecondGoal +//=========================================================================== +// pops a new long term goal on the goal stack in the goalstate +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int BotChooseLTGItem( int goalstate, vec3_t origin, int *inventory, int travelflags ) { + int areanum, t, weightnum; + float weight, bestweight, avoidtime; + iteminfo_t *iteminfo; + itemconfig_t *ic; + levelitem_t *li, *bestitem; + bot_goal_t goal; + bot_goalstate_t *gs; + + gs = BotGoalStateFromHandle( goalstate ); + if ( !gs ) { + return qfalse; + } + if ( !gs->itemweightconfig ) { + return qfalse; + } + //get the area the bot is in + areanum = BotReachabilityArea( origin, gs->client ); + //if the bot is in solid or if the area the bot is in has no reachability links + if ( !areanum || !AAS_AreaReachability( areanum ) ) { + //use the last valid area the bot was in + areanum = gs->lastreachabilityarea; + } //end if + //remember the last area with reachabilities the bot was in + gs->lastreachabilityarea = areanum; + //if still in solid + if ( !areanum ) { + return qfalse; + } + //the item configuration + ic = itemconfig; + if ( !itemconfig ) { + return qfalse; + } + //best weight and item so far + bestweight = 0; + bestitem = NULL; + memset( &goal, 0, sizeof( bot_goal_t ) ); + //go through the items in the level + for ( li = levelitems; li; li = li->next ) + { + if ( g_gametype == GT_SINGLE_PLAYER ) { + if ( li->notsingle ) { + continue; + } + } else if ( g_gametype >= GT_TEAM ) { + if ( li->notteam ) { + continue; + } + } else { + if ( li->notfree ) { + continue; + } + } + //if the item is not in a possible goal area + if ( !li->goalareanum ) { + continue; + } + //get the fuzzy weight function for this item + iteminfo = &ic->iteminfo[li->iteminfo]; + weightnum = gs->itemweightindex[iteminfo->number]; + if ( weightnum < 0 ) { + continue; + } + //if this goal is in the avoid goals + if ( BotAvoidGoalTime( goalstate, li->number ) > 0 ) { + continue; + } + +#ifdef UNDECIDEDFUZZY + weight = FuzzyWeightUndecided( inventory, gs->itemweightconfig, weightnum ); +#else + weight = FuzzyWeight( inventory, gs->itemweightconfig, weightnum ); +#endif //UNDECIDEDFUZZY +#ifdef DROPPEDWEIGHT + //HACK: to make dropped items more attractive + if ( li->timeout ) { + weight += 1000; + } +#endif //DROPPEDWEIGHT + if ( weight > 0 ) { + //get the travel time towards the goal area + t = AAS_AreaTravelTimeToGoalArea( areanum, origin, li->goalareanum, travelflags ); + //if the goal is reachable + if ( t > 0 ) { + weight /= (float) t * TRAVELTIME_SCALE; + // + if ( weight > bestweight ) { + bestweight = weight; + bestitem = li; + } //end if + } //end if + } //end if + } //end for + //if no goal item found + if ( !bestitem ) { + /* + //if not in lava or slime + if (!AAS_AreaLava(areanum) && !AAS_AreaSlime(areanum)) + { + if (AAS_RandomGoalArea(areanum, travelflags, &goal.areanum, goal.origin)) + { + VectorSet(goal.mins, -15, -15, -15); + VectorSet(goal.maxs, 15, 15, 15); + goal.entitynum = 0; + goal.number = 0; + goal.flags = GFL_ROAM; + goal.iteminfo = 0; + //push the goal on the stack + BotPushGoal(goalstate, &goal); + // +#ifdef DEBUG + botimport.Print(PRT_MESSAGE, "chosen roam goal area %d\n", goal.areanum); +#endif //DEBUG + return qtrue; + } //end if + } //end if + */ + return qfalse; + } //end if + //create a bot goal for this item + iteminfo = &ic->iteminfo[bestitem->iteminfo]; + VectorCopy( bestitem->goalorigin, goal.origin ); + VectorCopy( iteminfo->mins, goal.mins ); + VectorCopy( iteminfo->maxs, goal.maxs ); + goal.areanum = bestitem->goalareanum; + goal.entitynum = bestitem->entitynum; + goal.number = bestitem->number; + goal.flags = GFL_ITEM; + goal.iteminfo = bestitem->iteminfo; + //add the chosen goal to the goals to avoid for a while + avoidtime = iteminfo->respawntime * 0.5; + if ( avoidtime < 10 ) { + avoidtime = AVOID_TIME; + } + //if it's a dropped item + if ( bestitem->timeout ) { + avoidtime = AVOIDDROPPED_TIME; + } + BotAddToAvoidGoals( gs, bestitem->number, avoidtime ); + //push the goal on the stack + BotPushGoal( goalstate, &goal ); + // +#ifdef DEBUG_AI_GOAL + if ( bestitem->timeout ) { + botimport.Print( PRT_MESSAGE, "new ltg dropped item %s\n", ic->iteminfo[bestitem->iteminfo].classname ); + } //end if + iteminfo = &ic->iteminfo[bestitem->iteminfo]; + botimport.Print( PRT_MESSAGE, "new ltg \"%s\"\n", iteminfo->classname ); +#endif //DEBUG_AI_GOAL + return qtrue; +} //end of the function BotChooseLTGItem +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int BotChooseNBGItem( int goalstate, vec3_t origin, int *inventory, int travelflags, + bot_goal_t *ltg, float maxtime ) { + int areanum, t, weightnum, ltg_time; + float weight, bestweight, avoidtime; + iteminfo_t *iteminfo; + itemconfig_t *ic; + levelitem_t *li, *bestitem; + bot_goal_t goal; + bot_goalstate_t *gs; + + gs = BotGoalStateFromHandle( goalstate ); + if ( !gs ) { + return qfalse; + } + if ( !gs->itemweightconfig ) { + return qfalse; + } + //get the area the bot is in + areanum = BotReachabilityArea( origin, gs->client ); + //if the bot is in solid or if the area the bot is in has no reachability links + if ( !areanum || !AAS_AreaReachability( areanum ) ) { + //use the last valid area the bot was in + areanum = gs->lastreachabilityarea; + } //end if + //remember the last area with reachabilities the bot was in + gs->lastreachabilityarea = areanum; + //if still in solid + if ( !areanum ) { + return qfalse; + } + // + if ( ltg ) { + ltg_time = AAS_AreaTravelTimeToGoalArea( areanum, origin, ltg->areanum, travelflags ); + } else { ltg_time = 99999;} + //the item configuration + ic = itemconfig; + if ( !itemconfig ) { + return qfalse; + } + //best weight and item so far + bestweight = 0; + bestitem = NULL; + memset( &goal, 0, sizeof( bot_goal_t ) ); + //go through the items in the level + for ( li = levelitems; li; li = li->next ) + { + if ( g_gametype == GT_SINGLE_PLAYER ) { + if ( li->notsingle ) { + continue; + } + } else if ( g_gametype >= GT_TEAM ) { + if ( li->notteam ) { + continue; + } + } else { + if ( li->notfree ) { + continue; + } + } + //if the item is in a possible goal area + if ( !li->goalareanum ) { + continue; + } + //get the fuzzy weight function for this item + iteminfo = &ic->iteminfo[li->iteminfo]; + weightnum = gs->itemweightindex[iteminfo->number]; + if ( weightnum < 0 ) { + continue; + } + //if this goal is in the avoid goals + if ( BotAvoidGoalTime( goalstate, li->number ) > 0 ) { + continue; + } + // +#ifdef UNDECIDEDFUZZY + weight = FuzzyWeightUndecided( inventory, gs->itemweightconfig, weightnum ); +#else + weight = FuzzyWeight( inventory, gs->itemweightconfig, weightnum ); +#endif //UNDECIDEDFUZZY +#ifdef DROPPEDWEIGHT + //HACK: to make dropped items more attractive + if ( li->timeout ) { + weight += 1000; + } +#endif //DROPPEDWEIGHT + if ( weight > 0 ) { + //get the travel time towards the goal area + t = AAS_AreaTravelTimeToGoalArea( areanum, origin, li->goalareanum, travelflags ); + //if the goal is reachable + if ( t > 0 && t < maxtime ) { + weight /= (float) t * TRAVELTIME_SCALE; + // + if ( weight > bestweight ) { + t = 0; + if ( ltg && !li->timeout ) { + //get the travel time from the goal to the long term goal + t = AAS_AreaTravelTimeToGoalArea( li->goalareanum, li->goalorigin, ltg->areanum, travelflags ); + } //end if + //if the travel back is possible and doesn't take too long + if ( t <= ltg_time ) { + bestweight = weight; + bestitem = li; + } //end if + } //end if + } //end if + } //end if + } //end for + //if no goal item found + if ( !bestitem ) { + return qfalse; + } + //create a bot goal for this item + iteminfo = &ic->iteminfo[bestitem->iteminfo]; + VectorCopy( bestitem->goalorigin, goal.origin ); + VectorCopy( iteminfo->mins, goal.mins ); + VectorCopy( iteminfo->maxs, goal.maxs ); + goal.areanum = bestitem->goalareanum; + goal.entitynum = bestitem->entitynum; + goal.number = bestitem->number; + goal.flags = GFL_ITEM; + goal.iteminfo = bestitem->iteminfo; + //add the chosen goal to the goals to avoid for a while + avoidtime = iteminfo->respawntime * 0.5; + if ( avoidtime < 10 ) { + avoidtime = AVOID_TIME; + } + //if it's a dropped item + if ( bestitem->timeout ) { + avoidtime = AVOIDDROPPED_TIME; + } + BotAddToAvoidGoals( gs, bestitem->number, avoidtime ); + //push the goal on the stack + BotPushGoal( goalstate, &goal ); + // +#ifdef DEBUG_AI_GOAL + if ( bestitem->timeout ) { + botimport.Print( PRT_MESSAGE, "new nbg dropped item %s\n", ic->iteminfo[bestitem->iteminfo].classname ); + } //end if + iteminfo = &ic->iteminfo[bestitem->iteminfo]; + botimport.Print( PRT_MESSAGE, "new nbg \"%s\"\n", iteminfo->classname ); +#endif //DEBUG_AI_GOAL + return qtrue; +} //end of the function BotChooseNBGItem +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int BotTouchingGoal( vec3_t origin, bot_goal_t *goal ) { + int i; + vec3_t boxmins, boxmaxs; + vec3_t absmins, absmaxs; + vec3_t safety_maxs = {0, 0, 0}; //{4, 4, 10}; + vec3_t safety_mins = {0, 0, 0}; //{-4, -4, 0}; + + AAS_PresenceTypeBoundingBox( PRESENCE_NORMAL, boxmins, boxmaxs ); + VectorSubtract( goal->mins, boxmaxs, absmins ); + VectorSubtract( goal->maxs, boxmins, absmaxs ); + VectorAdd( absmins, goal->origin, absmins ); + VectorAdd( absmaxs, goal->origin, absmaxs ); + //make the box a little smaller for safety + VectorSubtract( absmaxs, safety_maxs, absmaxs ); + VectorSubtract( absmins, safety_mins, absmins ); + + for ( i = 0; i < 3; i++ ) + { + if ( origin[i] < absmins[i] || origin[i] > absmaxs[i] ) { + return qfalse; + } + } //end for + return qtrue; +} //end of the function BotTouchingGoal +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int BotItemGoalInVisButNotVisible( int viewer, vec3_t eye, vec3_t viewangles, bot_goal_t *goal ) { + aas_entityinfo_t entinfo; + bsp_trace_t trace; + vec3_t middle; + + if ( !( goal->flags & GFL_ITEM ) ) { + return qfalse; + } + // + VectorAdd( goal->mins, goal->mins, middle ); + VectorScale( middle, 0.5, middle ); + VectorAdd( goal->origin, middle, middle ); + // + trace = AAS_Trace( eye, NULL, NULL, middle, viewer, CONTENTS_SOLID ); + //if the goal middle point is visible + if ( trace.fraction >= 1 ) { + //the goal entity number doesn't have to be valid + //just assume it's valid + if ( goal->entitynum <= 0 ) { + return qfalse; + } + // + //if the entity data isn't valid + AAS_EntityInfo( goal->entitynum, &entinfo ); + //NOTE: for some wacko reason entities are sometimes + // not updated + //if (!entinfo.valid) return qtrue; + if ( entinfo.ltime < AAS_Time() - 0.5 ) { + return qtrue; + } + } //end if + return qfalse; +} //end of the function BotItemGoalInVisButNotVisible +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void BotResetGoalState( int goalstate ) { + bot_goalstate_t *gs; + + gs = BotGoalStateFromHandle( goalstate ); + if ( !gs ) { + return; + } + memset( gs->goalstack, 0, MAX_GOALSTACK * sizeof( bot_goal_t ) ); + gs->goalstacktop = 0; + BotResetAvoidGoals( goalstate ); +} //end of the function BotResetGoalState +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int BotLoadItemWeights( int goalstate, char *filename ) { + bot_goalstate_t *gs; + + gs = BotGoalStateFromHandle( goalstate ); + if ( !gs ) { + return BLERR_CANNOTLOADITEMWEIGHTS; + } + //load the weight configuration + gs->itemweightconfig = ReadWeightConfig( filename ); + if ( !gs->itemweightconfig ) { + botimport.Print( PRT_FATAL, "couldn't load weights\n" ); + return BLERR_CANNOTLOADITEMWEIGHTS; + } //end if + //if there's no item configuration + if ( !itemconfig ) { + return BLERR_CANNOTLOADITEMWEIGHTS; + } + //create the item weight index + gs->itemweightindex = ItemWeightIndex( gs->itemweightconfig, itemconfig ); + //everything went ok + return BLERR_NOERROR; +} //end of the function BotLoadItemWeights +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void BotFreeItemWeights( int goalstate ) { + bot_goalstate_t *gs; + + gs = BotGoalStateFromHandle( goalstate ); + if ( !gs ) { + return; + } + if ( gs->itemweightconfig ) { + FreeWeightConfig( gs->itemweightconfig ); + } + if ( gs->itemweightindex ) { + FreeMemory( gs->itemweightindex ); + } +} //end of the function BotFreeItemWeights +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int BotAllocGoalState( int client ) { + int i; + + for ( i = 1; i <= MAX_CLIENTS; i++ ) + { + if ( !botgoalstates[i] ) { + botgoalstates[i] = GetClearedMemory( sizeof( bot_goalstate_t ) ); + botgoalstates[i]->client = client; + return i; + } //end if + } //end for + return 0; +} //end of the function BotAllocGoalState +//======================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//======================================================================== +void BotFreeGoalState( int handle ) { + if ( handle <= 0 || handle > MAX_CLIENTS ) { + botimport.Print( PRT_FATAL, "goal state handle %d out of range\n", handle ); + return; + } //end if + if ( !botgoalstates[handle] ) { + botimport.Print( PRT_FATAL, "invalid goal state handle %d\n", handle ); + return; + } //end if + BotFreeItemWeights( handle ); + FreeMemory( botgoalstates[handle] ); + botgoalstates[handle] = NULL; +} //end of the function BotFreeGoalState +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int BotSetupGoalAI( void ) { + char *filename; + + //check if teamplay is on + g_gametype = LibVarValue( "g_gametype", "0" ); + //item configuration file + filename = LibVarString( "itemconfig", "items.c" ); + //load the item configuration + itemconfig = LoadItemConfig( filename ); + if ( !itemconfig ) { + botimport.Print( PRT_FATAL, "couldn't load item config\n" ); + return BLERR_CANNOTLOADITEMCONFIG; + } //end if + //everything went ok + return BLERR_NOERROR; +} //end of the function BotSetupGoalAI +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void BotShutdownGoalAI( void ) { + int i; + + if ( itemconfig ) { + FreeMemory( itemconfig ); + } + itemconfig = NULL; + if ( levelitemheap ) { + FreeMemory( levelitemheap ); + } + levelitemheap = NULL; + freelevelitems = NULL; + levelitems = NULL; + numlevelitems = 0; + + BotFreeInfoEntities(); + + for ( i = 1; i <= MAX_CLIENTS; i++ ) + { + if ( botgoalstates[i] ) { + BotFreeGoalState( i ); + } //end if + } //end for +} //end of the function BotShutdownGoalAI diff --git a/Projects/Android/jni/rtcw/src/botlib/be_ai_move.c b/Projects/Android/jni/rtcw/src/botlib/be_ai_move.c new file mode 100644 index 0000000..0795ed6 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/botlib/be_ai_move.c @@ -0,0 +1,3697 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +/***************************************************************************** + * name: be_ai_move.c + * + * desc: bot movement AI + * + * + *****************************************************************************/ + +#include "../game/q_shared.h" +#include "l_memory.h" +#include "l_libvar.h" +#include "l_utils.h" +#include "l_script.h" +#include "l_precomp.h" +#include "l_struct.h" +#include "aasfile.h" +#include "../game/botlib.h" +#include "../game/be_aas.h" +#include "be_aas_funcs.h" +#include "be_interface.h" + +#include "../game/be_ea.h" +#include "../game/be_ai_goal.h" +#include "../game/be_ai_move.h" + + +//#define DEBUG_AI_MOVE +//#define DEBUG_ELEVATOR +//#define DEBUG_GRAPPLE +//movement state + +//NOTE: the moveflags MFL_ONGROUND, MFL_TELEPORTED and MFL_WATERJUMP must be set outside the movement code +typedef struct bot_movestate_s +{ + //input vars (all set outside the movement code) + vec3_t origin; //origin of the bot + vec3_t velocity; //velocity of the bot + vec3_t viewoffset; //view offset + int entitynum; //entity number of the bot + int client; //client number of the bot + float thinktime; //time the bot thinks + int presencetype; //presencetype of the bot + vec3_t viewangles; //view angles of the bot + //state vars + int areanum; //area the bot is in + int lastareanum; //last area the bot was in + int lastgoalareanum; //last goal area number + int lastreachnum; //last reachability number + vec3_t lastorigin; //origin previous cycle + float lasttime; + int reachareanum; //area number of the reachabilty + int moveflags; //movement flags + int jumpreach; //set when jumped + float grapplevisible_time; //last time the grapple was visible + float lastgrappledist; //last distance to the grapple end + float reachability_time; //time to use current reachability + int avoidreach[MAX_AVOIDREACH]; //reachabilities to avoid + float avoidreachtimes[MAX_AVOIDREACH]; //times to avoid the reachabilities + int avoidreachtries[MAX_AVOIDREACH]; //number of tries before avoiding +} bot_movestate_t; + +//used to avoid reachability links for some time after being used +// Ridah, disabled this to prevent wierd navigational behaviour (mostly by Zombie, since it's so slow) +//#define AVOIDREACH +#define AVOIDREACH_TIME 6 //avoid links for 6 seconds after use +#define AVOIDREACH_TRIES 4 +//prediction times +#define PREDICTIONTIME_JUMP 3 //in seconds +#define PREDICTIONTIME_MOVE 2 //in seconds +//hook commands +#define CMD_HOOKOFF "hookoff" +#define CMD_HOOKON "hookon" +//weapon indexes for weapon jumping +#define WEAPONINDEX_ROCKET_LAUNCHER 5 +#define WEAPONINDEX_BFG 9 + +#define MODELTYPE_FUNC_PLAT 1 +#define MODELTYPE_FUNC_BOB 2 + +float sv_maxstep; +float sv_maxbarrier; +float sv_gravity; +//type of model, func_plat or func_bobbing +int modeltypes[MAX_MODELS]; + +bot_movestate_t *botmovestates[MAX_CLIENTS + 1]; + +//======================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//======================================================================== +int BotAllocMoveState( void ) { + int i; + + for ( i = 1; i <= MAX_CLIENTS; i++ ) + { + if ( !botmovestates[i] ) { + botmovestates[i] = GetClearedMemory( sizeof( bot_movestate_t ) ); + return i; + } //end if + } //end for + return 0; +} //end of the function BotAllocMoveState +//======================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//======================================================================== +void BotFreeMoveState( int handle ) { + if ( handle <= 0 || handle > MAX_CLIENTS ) { + botimport.Print( PRT_FATAL, "move state handle %d out of range\n", handle ); + return; + } //end if + if ( !botmovestates[handle] ) { + botimport.Print( PRT_FATAL, "invalid move state %d\n", handle ); + return; + } //end if + FreeMemory( botmovestates[handle] ); + botmovestates[handle] = NULL; +} //end of the function BotFreeMoveState +//======================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//======================================================================== +bot_movestate_t *BotMoveStateFromHandle( int handle ) { + if ( handle <= 0 || handle > MAX_CLIENTS ) { + botimport.Print( PRT_FATAL, "move state handle %d out of range\n", handle ); + return NULL; + } //end if + if ( !botmovestates[handle] ) { + botimport.Print( PRT_FATAL, "invalid move state %d\n", handle ); + return NULL; + } //end if + return botmovestates[handle]; +} //end of the function BotMoveStateFromHandle + +// Ridah, provide a means of resetting the avoidreach, so if a bot stops moving, they don't avoid the area they were heading for +//======================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//======================================================================== +void BotInitAvoidReach( int handle ) { + bot_movestate_t *ms; + + ms = BotMoveStateFromHandle( handle ); + if ( !ms ) { + return; + } + + memset( ms->avoidreach, 0, sizeof( ms->avoidreach ) ); + memset( ms->avoidreachtries, 0, sizeof( ms->avoidreachtries ) ); + memset( ms->avoidreachtimes, 0, sizeof( ms->avoidreachtimes ) ); +} +// done. + +//======================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//======================================================================== +void BotInitMoveState( int handle, bot_initmove_t *initmove ) { + bot_movestate_t *ms; + + ms = BotMoveStateFromHandle( handle ); + if ( !ms ) { + return; + } + VectorCopy( initmove->origin, ms->origin ); + VectorCopy( initmove->velocity, ms->velocity ); + VectorCopy( initmove->viewoffset, ms->viewoffset ); + ms->entitynum = initmove->entitynum; + ms->client = initmove->client; + ms->thinktime = initmove->thinktime; + ms->presencetype = initmove->presencetype; + VectorCopy( initmove->viewangles, ms->viewangles ); + // + ms->moveflags &= ~MFL_ONGROUND; + if ( initmove->or_moveflags & MFL_ONGROUND ) { + ms->moveflags |= MFL_ONGROUND; + } + ms->moveflags &= ~MFL_TELEPORTED; + if ( initmove->or_moveflags & MFL_TELEPORTED ) { + ms->moveflags |= MFL_TELEPORTED; + } + ms->moveflags &= ~MFL_WATERJUMP; + if ( initmove->or_moveflags & MFL_WATERJUMP ) { + ms->moveflags |= MFL_WATERJUMP; + } + ms->moveflags &= ~MFL_WALK; + if ( initmove->or_moveflags & MFL_WALK ) { + ms->moveflags |= MFL_WALK; + } +} //end of the function BotInitMoveState +//======================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//======================================================================== +float AngleDiff( float ang1, float ang2 ) { + float diff; + + diff = ang1 - ang2; + if ( ang1 > ang2 ) { + if ( diff > 180.0 ) { + diff -= 360.0; + } + } //end if + else + { + if ( diff < -180.0 ) { + diff += 360.0; + } + } //end else + return diff; +} //end of the function AngleDiff +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int BotFuzzyPointReachabilityArea( vec3_t origin ) { + int firstareanum, j, x, y, z; + int areas[10], numareas, areanum, bestareanum; + float dist, bestdist; + vec3_t points[10], v, end; + + firstareanum = 0; + areanum = AAS_PointAreaNum( origin ); + if ( areanum ) { + firstareanum = areanum; + if ( AAS_AreaReachability( areanum ) ) { + return areanum; + } + } //end if + VectorCopy( origin, end ); + end[2] += 4; + numareas = AAS_TraceAreas( origin, end, areas, points, 10 ); + for ( j = 0; j < numareas; j++ ) + { + if ( AAS_AreaReachability( areas[j] ) ) { + return areas[j]; + } + } //end for + bestdist = 999999; + bestareanum = 0; + //z = 0; + for ( z = 1; z >= -1; z -= 1 ) + { + for ( x = 1; x >= -1; x -= 2 ) + { + for ( y = 1; y >= -1; y -= 2 ) + { + VectorCopy( origin, end ); + // Ridah, increased this for Wolf larger bounding boxes + end[0] += x * 256; //8; + end[1] += y * 256; //8; + end[2] += z * 200; //12; + numareas = AAS_TraceAreas( origin, end, areas, points, 10 ); + for ( j = 0; j < numareas; j++ ) + { + if ( AAS_AreaReachability( areas[j] ) ) { + VectorSubtract( points[j], origin, v ); + dist = VectorLength( v ); + if ( dist < bestdist ) { + bestareanum = areas[j]; + bestdist = dist; + } //end if + } //end if + if ( !firstareanum ) { + firstareanum = areas[j]; + } + } //end for + } //end for + } //end for + if ( bestareanum ) { + return bestareanum; + } + } //end for + return firstareanum; +} //end of the function BotFuzzyPointReachabilityArea +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int BotReachabilityArea( vec3_t origin, int client ) { + int modelnum, modeltype, reachnum, areanum; + aas_reachability_t reach; + vec3_t org, end, mins, maxs, up = {0, 0, 1}; + bsp_trace_t bsptrace; + aas_trace_t trace; + + //check if the bot is standing on something + AAS_PresenceTypeBoundingBox( PRESENCE_CROUCH, mins, maxs ); + VectorMA( origin, -3, up, end ); + bsptrace = AAS_Trace( origin, mins, maxs, end, client, CONTENTS_SOLID | CONTENTS_PLAYERCLIP ); + if ( !bsptrace.startsolid && bsptrace.fraction < 1 && bsptrace.ent != ENTITYNUM_NONE ) { + //if standing on the world the bot should be in a valid area + if ( bsptrace.ent == ENTITYNUM_WORLD ) { + return BotFuzzyPointReachabilityArea( origin ); + } //end if + + modelnum = AAS_EntityModelindex( bsptrace.ent ); + modeltype = modeltypes[modelnum]; + + //if standing on a func_plat or func_bobbing then the bot is assumed to be + //in the area the reachability points to + if ( modeltype == MODELTYPE_FUNC_PLAT || modeltype == MODELTYPE_FUNC_BOB ) { + reachnum = AAS_NextModelReachability( 0, modelnum ); + if ( reachnum ) { + AAS_ReachabilityFromNum( reachnum, &reach ); + return reach.areanum; + } //end if + } //end else if + + //if the bot is swimming the bot should be in a valid area + if ( AAS_Swimming( origin ) ) { + return BotFuzzyPointReachabilityArea( origin ); + } //end if + // + areanum = BotFuzzyPointReachabilityArea( origin ); + //if the bot is in an area with reachabilities + if ( areanum && AAS_AreaReachability( areanum ) ) { + return areanum; + } + //trace down till the ground is hit because the bot is standing on some other entity + VectorCopy( origin, org ); + VectorCopy( org, end ); + end[2] -= 800; + trace = AAS_TraceClientBBox( org, end, PRESENCE_CROUCH, -1 ); + if ( !trace.startsolid ) { + VectorCopy( trace.endpos, org ); + } //end if + // + return BotFuzzyPointReachabilityArea( org ); + } //end if + // + return BotFuzzyPointReachabilityArea( origin ); +} //end of the function BotReachabilityArea +//=========================================================================== +// returns the reachability area the bot is in +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +/* +int BotReachabilityArea(vec3_t origin, int testground) +{ + int firstareanum, i, j, x, y, z; + int areas[10], numareas, areanum, bestareanum; + float dist, bestdist; + vec3_t org, end, points[10], v; + aas_trace_t trace; + + firstareanum = 0; + for (i = 0; i < 2; i++) + { + VectorCopy(origin, org); + //if test at the ground (used when bot is standing on an entity) + if (i > 0) + { + VectorCopy(origin, end); + end[2] -= 800; + trace = AAS_TraceClientBBox(origin, end, PRESENCE_CROUCH, -1); + if (!trace.startsolid) + { + VectorCopy(trace.endpos, org); + } //end if + } //end if + + firstareanum = 0; + areanum = AAS_PointAreaNum(org); + if (areanum) + { + firstareanum = areanum; + if (AAS_AreaReachability(areanum)) return areanum; + } //end if + bestdist = 999999; + bestareanum = 0; + for (z = 1; z >= -1; z -= 1) + { + for (x = 1; x >= -1; x -= 1) + { + for (y = 1; y >= -1; y -= 1) + { + VectorCopy(org, end); + end[0] += x * 8; + end[1] += y * 8; + end[2] += z * 12; + numareas = AAS_TraceAreas(org, end, areas, points, 10); + for (j = 0; j < numareas; j++) + { + if (AAS_AreaReachability(areas[j])) + { + VectorSubtract(points[j], org, v); + dist = VectorLength(v); + if (dist < bestdist) + { + bestareanum = areas[j]; + bestdist = dist; + } //end if + } //end if + } //end for + } //end for + } //end for + if (bestareanum) return bestareanum; + } //end for + if (!testground) break; + } //end for +//#ifdef DEBUG + //botimport.Print(PRT_MESSAGE, "no reachability area\n"); +//#endif //DEBUG + return firstareanum; +} //end of the function BotReachabilityArea*/ +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int BotOnMover( vec3_t origin, int entnum, aas_reachability_t *reach ) { + int i, modelnum; + vec3_t mins, maxs, modelorigin, org, end; + vec3_t angles = {0, 0, 0}; + vec3_t boxmins = {-16, -16, -8}, boxmaxs = {16, 16, 8}; + bsp_trace_t trace; + + modelnum = reach->facenum & 0x0000FFFF; + //get some bsp model info + AAS_BSPModelMinsMaxsOrigin( modelnum, angles, mins, maxs, NULL ); + // + if ( !AAS_OriginOfEntityWithModelNum( modelnum, modelorigin ) ) { + botimport.Print( PRT_MESSAGE, "no entity with model %d\n", modelnum ); + return qfalse; + } //end if + // + for ( i = 0; i < 2; i++ ) + { + if ( origin[i] > modelorigin[i] + maxs[i] + 16 ) { + return qfalse; + } + if ( origin[i] < modelorigin[i] + mins[i] - 16 ) { + return qfalse; + } + } //end for + // + VectorCopy( origin, org ); + org[2] += 24; + VectorCopy( origin, end ); + end[2] -= 48; + // + trace = AAS_Trace( org, boxmins, boxmaxs, end, entnum, CONTENTS_SOLID | CONTENTS_PLAYERCLIP ); + if ( !trace.startsolid && !trace.allsolid ) { + //NOTE: the reachability face number is the model number of the elevator + if ( trace.ent != ENTITYNUM_NONE && AAS_EntityModelNum( trace.ent ) == modelnum ) { + return qtrue; + } //end if + } //end if + return qfalse; +} //end of the function BotOnMover +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int MoverDown( aas_reachability_t *reach ) { + int modelnum; + vec3_t mins, maxs, origin; + vec3_t angles = {0, 0, 0}; + + modelnum = reach->facenum & 0x0000FFFF; + //get some bsp model info + AAS_BSPModelMinsMaxsOrigin( modelnum, angles, mins, maxs, origin ); + // + if ( !AAS_OriginOfEntityWithModelNum( modelnum, origin ) ) { + botimport.Print( PRT_MESSAGE, "no entity with model %d\n", modelnum ); + return qfalse; + } //end if + //if the top of the plat is below the reachability start point + if ( origin[2] + maxs[2] < reach->start[2] ) { + return qtrue; + } + return qfalse; +} //end of the function MoverDown +//======================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//======================================================================== +void BotSetBrushModelTypes( void ) { + int ent, modelnum; + char classname[MAX_EPAIRKEY], model[MAX_EPAIRKEY]; + + memset( modeltypes, 0, MAX_MODELS * sizeof( int ) ); + // + for ( ent = AAS_NextBSPEntity( 0 ); ent; ent = AAS_NextBSPEntity( ent ) ) + { + if ( !AAS_ValueForBSPEpairKey( ent, "classname", classname, MAX_EPAIRKEY ) ) { + continue; + } + if ( !AAS_ValueForBSPEpairKey( ent, "model", model, MAX_EPAIRKEY ) ) { + continue; + } + if ( model[0] ) { + modelnum = atoi( model + 1 ); + } else { modelnum = 0;} + + if ( modelnum < 0 || modelnum > MAX_MODELS ) { + botimport.Print( PRT_MESSAGE, "entity %s model number out of range\n", classname ); + continue; + } //end if + + if ( !strcmp( classname, "func_bobbing" ) ) { + modeltypes[modelnum] = MODELTYPE_FUNC_BOB; + } else if ( !strcmp( classname, "func_plat" ) ) { + modeltypes[modelnum] = MODELTYPE_FUNC_PLAT; + } + } //end for +} //end of the function BotSetBrushModelTypes +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int BotOnTopOfEntity( bot_movestate_t *ms ) { + vec3_t mins, maxs, end, up = {0, 0, 1}; + bsp_trace_t trace; + + AAS_PresenceTypeBoundingBox( ms->presencetype, mins, maxs ); + VectorMA( ms->origin, -3, up, end ); + trace = AAS_Trace( ms->origin, mins, maxs, end, ms->entitynum, CONTENTS_SOLID | CONTENTS_PLAYERCLIP ); + if ( !trace.startsolid && ( trace.ent != ENTITYNUM_WORLD && trace.ent != ENTITYNUM_NONE ) ) { + return trace.ent; + } //end if + return -1; +} //end of the function BotOnTopOfEntity +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int BotValidTravel( vec3_t origin, aas_reachability_t *reach, int travelflags ) { + //if the reachability uses an unwanted travel type + if ( AAS_TravelFlagForType( reach->traveltype ) & ~travelflags ) { + return qfalse; + } + //don't go into areas with bad travel types + if ( AAS_AreaContentsTravelFlag( reach->areanum ) & ~travelflags ) { + return qfalse; + } + return qtrue; +} //end of the function BotValidTravel +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void BotAddToAvoidReach( bot_movestate_t *ms, int number, float avoidtime ) { + int i; + + for ( i = 0; i < MAX_AVOIDREACH; i++ ) + { + if ( ms->avoidreach[i] == number ) { + if ( ms->avoidreachtimes[i] > AAS_Time() ) { + ms->avoidreachtries[i]++; + } else { ms->avoidreachtries[i] = 1;} + ms->avoidreachtimes[i] = AAS_Time() + avoidtime; + return; + } //end if + } //end for + //add the reachability to the reachabilities to avoid for a while + for ( i = 0; i < MAX_AVOIDREACH; i++ ) + { + if ( ms->avoidreachtimes[i] < AAS_Time() ) { + ms->avoidreach[i] = number; + ms->avoidreachtimes[i] = AAS_Time() + avoidtime; + ms->avoidreachtries[i] = 1; + return; + } //end if + } //end for +} //end of the function BotAddToAvoidReach +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +//__inline int AAS_AreaContentsTravelFlag(int areanum); + +int BotGetReachabilityToGoal( vec3_t origin, int areanum, int entnum, + int lastgoalareanum, int lastareanum, + int *avoidreach, float *avoidreachtimes, int *avoidreachtries, + bot_goal_t *goal, int travelflags, int movetravelflags ) { + int t, besttime, bestreachnum, reachnum; + aas_reachability_t reach; + + //if not in a valid area + if ( !areanum ) { + return 0; + } + // + if ( AAS_AreaDoNotEnter( areanum ) || AAS_AreaDoNotEnter( goal->areanum ) ) { + travelflags |= TFL_DONOTENTER; + movetravelflags |= TFL_DONOTENTER; + } //end if + if ( AAS_AreaDoNotEnterLarge( areanum ) || AAS_AreaDoNotEnterLarge( goal->areanum ) ) { + travelflags |= TFL_DONOTENTER_LARGE; + movetravelflags |= TFL_DONOTENTER_LARGE; + } //end if + //use the routing to find the next area to go to + besttime = 0; + bestreachnum = 0; + // + for ( reachnum = AAS_NextAreaReachability( areanum, 0 ); reachnum; + reachnum = AAS_NextAreaReachability( areanum, reachnum ) ) + { +#ifdef AVOIDREACH + int i; + //check if it isn't an reachability to avoid + for ( i = 0; i < MAX_AVOIDREACH; i++ ) + { + if ( avoidreach[i] == reachnum && avoidreachtimes[i] >= AAS_Time() ) { + break; + } + } //end for + if ( i != MAX_AVOIDREACH && avoidreachtries[i] > AVOIDREACH_TRIES ) { +#ifdef DEBUG + if ( bot_developer ) { + botimport.Print( PRT_MESSAGE, "avoiding reachability %d\n", avoidreach[i] ); + } //end if +#endif //DEBUG + continue; + } //end if +#endif //AVOIDREACH + //get the reachability from the number + AAS_ReachabilityFromNum( reachnum, &reach ); + //NOTE: do not go back to the previous area if the goal didn't change + //NOTE: is this actually avoidance of local routing minima between two areas??? + if ( lastgoalareanum == goal->areanum && reach.areanum == lastareanum ) { + continue; + } + //if (AAS_AreaContentsTravelFlag(reach.areanum) & ~travelflags) continue; + //if the travel isn't valid + if ( !BotValidTravel( origin, &reach, movetravelflags ) ) { + continue; + } + //RF, ignore disabled areas + if ( !AAS_AreaReachability( reach.areanum ) ) { + continue; + } + //get the travel time (ignore routes that leads us back our current area) + t = AAS_AreaTravelTimeToGoalAreaCheckLoop( reach.areanum, reach.end, goal->areanum, travelflags, areanum ); + //if the goal area isn't reachable from the reachable area + if ( !t ) { + continue; + } + + // Ridah, if this sends us to a looped route, ignore it + //if (AAS_AreaTravelTimeToGoalArea(areanum, reach.start, goal->areanum, travelflags) + reach.traveltime < t) + // continue; + + //add the travel time towards the area + // Ridah, not sure why this was disabled, but it causes looped links in the route-cache + // RF, update.. seems to work better like this.... + t += reach.traveltime; // + AAS_AreaTravelTime(areanum, origin, reach.start); + //t += reach.traveltime + AAS_AreaTravelTime(areanum, origin, reach.start); + + // Ridah, if there exists other entities in this area, avoid it +// if (reach.areanum != goal->areanum && AAS_IsEntityInArea( entnum, goal->entitynum, reach.areanum )) { +// t += 50; +// } + + //if the travel time is better than the ones already found + if ( !besttime || t < besttime ) { + besttime = t; + bestreachnum = reachnum; + } //end if + } //end for + // + return bestreachnum; +} //end of the function BotGetReachabilityToGoal +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int BotAddToTarget( vec3_t start, vec3_t end, float maxdist, float *dist, vec3_t target ) { + vec3_t dir; + float curdist; + + VectorSubtract( end, start, dir ); + curdist = VectorNormalize( dir ); + if ( *dist + curdist < maxdist ) { + VectorCopy( end, target ); + *dist += curdist; + return qfalse; + } //end if + else + { + VectorMA( start, maxdist - *dist, dir, target ); + *dist = maxdist; + return qtrue; + } //end else +} //end of the function BotAddToTarget + +int BotMovementViewTarget( int movestate, bot_goal_t *goal, int travelflags, float lookahead, vec3_t target ) { + aas_reachability_t reach; + int reachnum, lastareanum; + bot_movestate_t *ms; + vec3_t end; + float dist; + + ms = BotMoveStateFromHandle( movestate ); + if ( !ms ) { + return qfalse; + } + reachnum = 0; + //if the bot has no goal or no last reachability + if ( !ms->lastreachnum || !goal ) { + return qfalse; + } + + reachnum = ms->lastreachnum; + VectorCopy( ms->origin, end ); + lastareanum = ms->lastareanum; + dist = 0; + while ( reachnum && dist < lookahead ) + { + AAS_ReachabilityFromNum( reachnum, &reach ); + if ( BotAddToTarget( end, reach.start, lookahead, &dist, target ) ) { + return qtrue; + } + //never look beyond teleporters + if ( reach.traveltype == TRAVEL_TELEPORT ) { + return qtrue; + } + //don't add jump pad distances + if ( reach.traveltype != TRAVEL_JUMPPAD && + reach.traveltype != TRAVEL_ELEVATOR && + reach.traveltype != TRAVEL_FUNCBOB ) { + if ( BotAddToTarget( reach.start, reach.end, lookahead, &dist, target ) ) { + return qtrue; + } + } //end if + reachnum = BotGetReachabilityToGoal( reach.end, reach.areanum, -1, + ms->lastgoalareanum, lastareanum, + ms->avoidreach, ms->avoidreachtimes, ms->avoidreachtries, + goal, travelflags, travelflags ); + VectorCopy( reach.end, end ); + lastareanum = reach.areanum; + if ( lastareanum == goal->areanum ) { + BotAddToTarget( reach.end, goal->origin, lookahead, &dist, target ); + return qtrue; + } //end if + } //end while + // + return qfalse; +} //end of the function BotMovementViewTarget +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int BotVisible( int ent, vec3_t eye, vec3_t target ) { + bsp_trace_t trace; + + trace = AAS_Trace( eye, NULL, NULL, target, ent, CONTENTS_SOLID | CONTENTS_PLAYERCLIP ); + if ( trace.fraction >= 1 ) { + return qtrue; + } + return qfalse; +} //end of the function BotVisible +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int BotPredictVisiblePosition( vec3_t origin, int areanum, bot_goal_t *goal, int travelflags, vec3_t target ) { + aas_reachability_t reach; + int reachnum, lastgoalareanum, lastareanum, i; + int avoidreach[MAX_AVOIDREACH]; + float avoidreachtimes[MAX_AVOIDREACH]; + int avoidreachtries[MAX_AVOIDREACH]; + vec3_t end; + + //if the bot has no goal or no last reachability + if ( !goal ) { + return qfalse; + } + //if the areanum is not valid + if ( !areanum ) { + return qfalse; + } + //if the goal areanum is not valid + if ( !goal->areanum ) { + return qfalse; + } + + memset( avoidreach, 0, MAX_AVOIDREACH * sizeof( int ) ); + lastgoalareanum = goal->areanum; + lastareanum = areanum; + VectorCopy( origin, end ); + //only do 20 hops + for ( i = 0; i < 20 && ( areanum != goal->areanum ); i++ ) + { + // + reachnum = BotGetReachabilityToGoal( end, areanum, -1, + lastgoalareanum, lastareanum, + avoidreach, avoidreachtimes, avoidreachtries, + goal, travelflags, travelflags ); + if ( !reachnum ) { + return qfalse; + } + AAS_ReachabilityFromNum( reachnum, &reach ); + // + if ( BotVisible( goal->entitynum, goal->origin, reach.start ) ) { + VectorCopy( reach.start, target ); + return qtrue; + } //end if + // + if ( BotVisible( goal->entitynum, goal->origin, reach.end ) ) { + VectorCopy( reach.end, target ); + return qtrue; + } //end if + // + if ( reach.areanum == goal->areanum ) { + VectorCopy( reach.end, target ); + return qtrue; + } //end if + // + lastareanum = areanum; + areanum = reach.areanum; + VectorCopy( reach.end, end ); + // + } //end while + // + return qfalse; +} //end of the function BotPredictVisiblePosition +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void MoverBottomCenter( aas_reachability_t *reach, vec3_t bottomcenter ) { + int modelnum; + vec3_t mins, maxs, origin, mids; + vec3_t angles = {0, 0, 0}; + + modelnum = reach->facenum & 0x0000FFFF; + //get some bsp model info + AAS_BSPModelMinsMaxsOrigin( modelnum, angles, mins, maxs, origin ); + // + if ( !AAS_OriginOfEntityWithModelNum( modelnum, origin ) ) { + botimport.Print( PRT_MESSAGE, "no entity with model %d\n", modelnum ); + } //end if + //get a point just above the plat in the bottom position + VectorAdd( mins, maxs, mids ); + VectorMA( origin, 0.5, mids, bottomcenter ); + bottomcenter[2] = reach->start[2]; +} //end of the function MoverBottomCenter +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +float BotGapDistance( vec3_t origin, vec3_t hordir, int entnum ) { + float dist, startz; + vec3_t start, end; + aas_trace_t trace; + + //do gap checking + startz = origin[2]; + //this enables walking down stairs more fluidly + { + VectorCopy( origin, start ); + VectorCopy( origin, end ); + end[2] -= 60; + trace = AAS_TraceClientBBox( start, end, PRESENCE_CROUCH, entnum ); + if ( trace.fraction >= 1 ) { + return 1; + } + startz = trace.endpos[2] + 1; + } + // + for ( dist = 8; dist <= 100; dist += 8 ) + { + VectorMA( origin, dist, hordir, start ); + start[2] = startz + 24; + VectorCopy( start, end ); + end[2] -= 48 + sv_maxbarrier; + trace = AAS_TraceClientBBox( start, end, PRESENCE_CROUCH, entnum ); + //if solid is found the bot can't walk any further and fall into a gap + if ( !trace.startsolid ) { + //if it is a gap + if ( trace.endpos[2] < startz - sv_maxstep - 8 ) { + VectorCopy( trace.endpos, end ); + end[2] -= 20; + if ( AAS_PointContents( end ) & ( CONTENTS_WATER | CONTENTS_SLIME ) ) { + break; //----(SA) modified since slime is no longer deadly + } +// if (AAS_PointContents(end) & CONTENTS_WATER) break; + //if a gap is found slow down + //botimport.Print(PRT_MESSAGE, "gap at %f\n", dist); + return dist; + } //end if + startz = trace.endpos[2]; + } //end if + } //end for + return 0; +} //end of the function BotGapDistance +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int BotCheckBarrierJump( bot_movestate_t *ms, vec3_t dir, float speed ) { + vec3_t start, hordir, end; + aas_trace_t trace; + + VectorCopy( ms->origin, end ); + end[2] += sv_maxbarrier; + //trace right up + trace = AAS_TraceClientBBox( ms->origin, end, PRESENCE_NORMAL, ms->entitynum ); + //this shouldn't happen... but we check anyway + if ( trace.startsolid ) { + return qfalse; + } + //if very low ceiling it isn't possible to jump up to a barrier + if ( trace.endpos[2] - ms->origin[2] < sv_maxstep ) { + return qfalse; + } + // + hordir[0] = dir[0]; + hordir[1] = dir[1]; + hordir[2] = 0; + VectorNormalize( hordir ); + VectorMA( ms->origin, ms->thinktime * speed * 0.5, hordir, end ); + VectorCopy( trace.endpos, start ); + end[2] = trace.endpos[2]; + //trace from previous trace end pos horizontally in the move direction + trace = AAS_TraceClientBBox( start, end, PRESENCE_NORMAL, ms->entitynum ); + //again this shouldn't happen + if ( trace.startsolid ) { + return qfalse; + } + // + VectorCopy( trace.endpos, start ); + VectorCopy( trace.endpos, end ); + end[2] = ms->origin[2]; + //trace down from the previous trace end pos + trace = AAS_TraceClientBBox( start, end, PRESENCE_NORMAL, ms->entitynum ); + //if solid + if ( trace.startsolid ) { + return qfalse; + } + //if no obstacle at all + if ( trace.fraction >= 1.0 ) { + return qfalse; + } + //if less than the maximum step height + if ( trace.endpos[2] - ms->origin[2] < sv_maxstep ) { + return qfalse; + } + // + EA_Jump( ms->client ); + EA_Move( ms->client, hordir, speed ); + ms->moveflags |= MFL_BARRIERJUMP; + //there is a barrier + return qtrue; +} //end of the function BotCheckBarrierJump +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int BotSwimInDirection( bot_movestate_t *ms, vec3_t dir, float speed, int type ) { + vec3_t normdir; + + VectorCopy( dir, normdir ); + VectorNormalize( normdir ); + EA_Move( ms->client, normdir, speed ); + return qtrue; +} //end of the function BotSwimInDirection +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int BotWalkInDirection( bot_movestate_t *ms, vec3_t dir, float speed, int type ) { + vec3_t hordir, cmdmove, velocity, tmpdir, origin; + int presencetype, maxframes, cmdframes, stopevent; + aas_clientmove_t move; + float dist; + + //if the bot is on the ground + if ( ms->moveflags & MFL_ONGROUND ) { + //if there is a barrier the bot can jump on + if ( BotCheckBarrierJump( ms, dir, speed ) ) { + return qtrue; + } + //remove barrier jump flag + ms->moveflags &= ~MFL_BARRIERJUMP; + //get the presence type for the movement + if ( ( type & MOVE_CROUCH ) && !( type & MOVE_JUMP ) ) { + presencetype = PRESENCE_CROUCH; + } else { presencetype = PRESENCE_NORMAL;} + //horizontal direction + hordir[0] = dir[0]; + hordir[1] = dir[1]; + hordir[2] = 0; + VectorNormalize( hordir ); + //if the bot is not supposed to jump + if ( !( type & MOVE_JUMP ) ) { + //if there is a gap, try to jump over it + if ( BotGapDistance( ms->origin, hordir, ms->entitynum ) > 0 ) { + type |= MOVE_JUMP; + } + } //end if + //get command movement + VectorScale( hordir, speed, cmdmove ); + VectorCopy( ms->velocity, velocity ); + // + if ( type & MOVE_JUMP ) { + //botimport.Print(PRT_MESSAGE, "trying jump\n"); + cmdmove[2] = 400; + maxframes = PREDICTIONTIME_JUMP / 0.1; + cmdframes = 1; + stopevent = SE_HITGROUND | SE_HITGROUNDDAMAGE | + SE_ENTERWATER | SE_ENTERSLIME | SE_ENTERLAVA; + } //end if + else + { + maxframes = 2; + cmdframes = 2; + stopevent = SE_HITGROUNDDAMAGE | + SE_ENTERWATER | SE_ENTERSLIME | SE_ENTERLAVA; + } //end else + //AAS_ClearShownDebugLines(); + // + VectorCopy( ms->origin, origin ); + origin[2] += 0.5; + AAS_PredictClientMovement( &move, ms->entitynum, origin, presencetype, qtrue, + velocity, cmdmove, cmdframes, maxframes, 0.1, + stopevent, 0, qfalse ); //qtrue); + //if prediction time wasn't enough to fully predict the movement + if ( move.frames >= maxframes && ( type & MOVE_JUMP ) ) { + //botimport.Print(PRT_MESSAGE, "client %d: max prediction frames\n", ms->client); + return qfalse; + } //end if + //don't enter slime or lava and don't fall from too high + if ( move.stopevent & ( SE_ENTERLAVA | SE_HITGROUNDDAMAGE ) ) { //----(SA) modified since slime is no longer deadly +// if (move.stopevent & (SE_ENTERSLIME|SE_ENTERLAVA|SE_HITGROUNDDAMAGE)) + //botimport.Print(PRT_MESSAGE, "client %d: would be hurt ", ms->client); + //if (move.stopevent & SE_ENTERSLIME) botimport.Print(PRT_MESSAGE, "slime\n"); + //if (move.stopevent & SE_ENTERLAVA) botimport.Print(PRT_MESSAGE, "lava\n"); + //if (move.stopevent & SE_HITGROUNDDAMAGE) botimport.Print(PRT_MESSAGE, "hitground\n"); + return qfalse; + } //end if + //if ground was hit + if ( move.stopevent & SE_HITGROUND ) { + //check for nearby gap + VectorNormalize2( move.velocity, tmpdir ); + dist = BotGapDistance( move.endpos, tmpdir, ms->entitynum ); + if ( dist > 0 ) { + return qfalse; + } + // + dist = BotGapDistance( move.endpos, hordir, ms->entitynum ); + if ( dist > 0 ) { + return qfalse; + } + } //end if + //get horizontal movement + tmpdir[0] = move.endpos[0] - ms->origin[0]; + tmpdir[1] = move.endpos[1] - ms->origin[1]; + tmpdir[2] = 0; + // + //AAS_DrawCross(move.endpos, 4, LINECOLOR_BLUE); + //the bot is blocked by something + if ( VectorLength( tmpdir ) < speed * ms->thinktime * 0.5 ) { + return qfalse; + } + //perform the movement + if ( type & MOVE_JUMP ) { + EA_Jump( ms->client ); + } + if ( type & MOVE_CROUCH ) { + EA_Crouch( ms->client ); + } + EA_Move( ms->client, hordir, speed ); + //movement was succesfull + return qtrue; + } //end if + else + { + if ( ms->moveflags & MFL_BARRIERJUMP ) { + //if near the top or going down + if ( ms->velocity[2] < 50 ) { + EA_Move( ms->client, dir, speed ); + } //end if + } //end if + //FIXME: do air control to avoid hazards + return qtrue; + } //end else +} //end of the function BotWalkInDirection +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int BotMoveInDirection( int movestate, vec3_t dir, float speed, int type ) { + bot_movestate_t *ms; + + ms = BotMoveStateFromHandle( movestate ); + if ( !ms ) { + return qfalse; + } + //if swimming + if ( AAS_Swimming( ms->origin ) ) { + return BotSwimInDirection( ms, dir, speed, type ); + } //end if + else + { + return BotWalkInDirection( ms, dir, speed, type ); + } //end else +} //end of the function BotMoveInDirection +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int Intersection( vec2_t p1, vec2_t p2, vec2_t p3, vec2_t p4, vec2_t out ) { + float x1, dx1, dy1, x2, dx2, dy2, d; + + dx1 = p2[0] - p1[0]; + dy1 = p2[1] - p1[1]; + dx2 = p4[0] - p3[0]; + dy2 = p4[1] - p3[1]; + + d = dy1 * dx2 - dx1 * dy2; + if ( d != 0 ) { + x1 = p1[1] * dx1 - p1[0] * dy1; + x2 = p3[1] * dx2 - p3[0] * dy2; + out[0] = (int) ( ( dx1 * x2 - dx2 * x1 ) / d ); + out[1] = (int) ( ( dy1 * x2 - dy2 * x1 ) / d ); + return qtrue; + } //end if + else + { + return qfalse; + } //end else +} //end of the function Intersection +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void BotCheckBlocked( bot_movestate_t *ms, vec3_t dir, int checkbottom, bot_moveresult_t *result ) { + vec3_t mins, maxs, end, up = {0, 0, 1}; + bsp_trace_t trace; + + // RF, not required for Wolf AI + return; + + //test for entities obstructing the bot's path + AAS_PresenceTypeBoundingBox( ms->presencetype, mins, maxs ); + // + if ( fabs( DotProduct( dir, up ) ) < 0.7 ) { + mins[2] += sv_maxstep; //if the bot can step on + maxs[2] -= 10; //a little lower to avoid low ceiling + } //end if + VectorMA( ms->origin, 3, dir, end ); + trace = AAS_Trace( ms->origin, mins, maxs, end, ms->entitynum, CONTENTS_SOLID | CONTENTS_PLAYERCLIP | CONTENTS_BODY ); + //if not started in solid and not hitting the world entity + if ( !trace.startsolid && ( trace.ent != ENTITYNUM_WORLD && trace.ent != ENTITYNUM_NONE ) ) { + result->blocked = qtrue; + result->blockentity = trace.ent; +#ifdef DEBUG + //botimport.Print(PRT_MESSAGE, "%d: BotCheckBlocked: I'm blocked\n", ms->client); +#endif //DEBUG + } //end if + //if not in an area with reachability + else if ( checkbottom && !AAS_AreaReachability( ms->areanum ) ) { + //check if the bot is standing on something + AAS_PresenceTypeBoundingBox( ms->presencetype, mins, maxs ); + VectorMA( ms->origin, -3, up, end ); + trace = AAS_Trace( ms->origin, mins, maxs, end, ms->entitynum, CONTENTS_SOLID | CONTENTS_PLAYERCLIP ); + if ( !trace.startsolid && ( trace.ent != ENTITYNUM_WORLD && trace.ent != ENTITYNUM_NONE ) ) { + result->blocked = qtrue; + result->blockentity = trace.ent; + result->flags |= MOVERESULT_ONTOPOFOBSTACLE; +#ifdef DEBUG + //botimport.Print(PRT_MESSAGE, "%d: BotCheckBlocked: I'm blocked\n", ms->client); +#endif //DEBUG + } //end if + } //end else +} //end of the function BotCheckBlocked +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void BotClearMoveResult( bot_moveresult_t *moveresult ) { + moveresult->failure = qfalse; + moveresult->type = 0; + moveresult->blocked = qfalse; + moveresult->blockentity = 0; + moveresult->traveltype = 0; + moveresult->flags = 0; +} //end of the function BotClearMoveResult +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +bot_moveresult_t BotTravel_Walk( bot_movestate_t *ms, aas_reachability_t *reach ) { + float dist, speed; + vec3_t hordir; + bot_moveresult_t result; + + BotClearMoveResult( &result ); + //first walk straight to the reachability start + hordir[0] = reach->start[0] - ms->origin[0]; + hordir[1] = reach->start[1] - ms->origin[1]; + hordir[2] = 0; + dist = VectorNormalize( hordir ); + // + BotCheckBlocked( ms, hordir, qtrue, &result ); + // + // Ridah, tweaked this +// if (dist < 10) + if ( dist < 32 ) { + //walk straight to the reachability end + hordir[0] = reach->end[0] - ms->origin[0]; + hordir[1] = reach->end[1] - ms->origin[1]; + hordir[2] = 0; + dist = VectorNormalize( hordir ); + } //end if + //if going towards a crouch area + + // Ridah, some areas have a 0 presence (!?!) +// if (!(AAS_AreaPresenceType(reach->areanum) & PRESENCE_NORMAL)) + if ( ( AAS_AreaPresenceType( reach->areanum ) & PRESENCE_CROUCH ) && + !( AAS_AreaPresenceType( reach->areanum ) & PRESENCE_NORMAL ) ) { + //if pretty close to the reachable area + if ( dist < 20 ) { + EA_Crouch( ms->client ); + } + } //end if + // + dist = BotGapDistance( ms->origin, hordir, ms->entitynum ); + // + if ( ms->moveflags & MFL_WALK ) { + if ( dist > 0 ) { + speed = 200 - ( 180 - 1 * dist ); + } else { speed = 200;} + EA_Walk( ms->client ); + } //end if + else + { + if ( dist > 0 ) { + speed = 400 - ( 360 - 2 * dist ); + } else { speed = 400;} + } //end else + //elemantary action move in direction + EA_Move( ms->client, hordir, speed ); + VectorCopy( hordir, result.movedir ); + // + return result; +} //end of the function BotTravel_Walk +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +bot_moveresult_t BotFinishTravel_Walk( bot_movestate_t *ms, aas_reachability_t *reach ) { + vec3_t hordir; + float dist, speed; + bot_moveresult_t result; + + BotClearMoveResult( &result ); + //if not on the ground and changed areas... don't walk back!! + //(doesn't seem to help) + /* + ms->areanum = BotFuzzyPointReachabilityArea(ms->origin); + if (ms->areanum == reach->areanum) + { +#ifdef DEBUG + botimport.Print(PRT_MESSAGE, "BotFinishTravel_Walk: already in reach area\n"); +#endif //DEBUG + return result; + } //end if*/ + //go straight to the reachability end + hordir[0] = reach->end[0] - ms->origin[0]; + hordir[1] = reach->end[1] - ms->origin[1]; + hordir[2] = 0; + dist = VectorNormalize( hordir ); + // + if ( dist > 100 ) { + dist = 100; + } + speed = 400 - ( 400 - 3 * dist ); + // + EA_Move( ms->client, hordir, speed ); + VectorCopy( hordir, result.movedir ); + // + return result; +} //end of the function BotFinishTravel_Walk +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +bot_moveresult_t BotTravel_Crouch( bot_movestate_t *ms, aas_reachability_t *reach ) { + float speed; + vec3_t hordir; + bot_moveresult_t result; + + BotClearMoveResult( &result ); + // + speed = 400; + //walk straight to reachability end + hordir[0] = reach->end[0] - ms->origin[0]; + hordir[1] = reach->end[1] - ms->origin[1]; + hordir[2] = 0; + VectorNormalize( hordir ); + // + BotCheckBlocked( ms, hordir, qtrue, &result ); + //elemantary actions + EA_Crouch( ms->client ); + EA_Move( ms->client, hordir, speed ); + // + VectorCopy( hordir, result.movedir ); + // + return result; +} //end of the function BotTravel_Crouch +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +bot_moveresult_t BotTravel_BarrierJump( bot_movestate_t *ms, aas_reachability_t *reach ) { + float dist, speed; + vec3_t hordir; + bot_moveresult_t result; + + BotClearMoveResult( &result ); + //walk straight to reachability start + hordir[0] = reach->start[0] - ms->origin[0]; + hordir[1] = reach->start[1] - ms->origin[1]; + hordir[2] = 0; + dist = VectorNormalize( hordir ); + // + BotCheckBlocked( ms, hordir, qtrue, &result ); + //if pretty close to the barrier + if ( dist < 9 ) { + EA_Jump( ms->client ); + + // Ridah, do the movement also, so we have momentum to get onto the barrier + hordir[0] = reach->end[0] - reach->start[0]; + hordir[1] = reach->end[1] - reach->start[1]; + hordir[2] = 0; + VectorNormalize( hordir ); + + dist = 60; + speed = 360 - ( 360 - 6 * dist ); + EA_Move( ms->client, hordir, speed ); + // done. + } //end if + else + { + if ( dist > 60 ) { + dist = 60; + } + speed = 360 - ( 360 - 6 * dist ); + EA_Move( ms->client, hordir, speed ); + } //end else + VectorCopy( hordir, result.movedir ); + // + return result; +} //end of the function BotTravel_BarrierJump +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +bot_moveresult_t BotFinishTravel_BarrierJump( bot_movestate_t *ms, aas_reachability_t *reach ) { + float dist, speed; + vec3_t hordir; + bot_moveresult_t result; + + BotClearMoveResult( &result ); + //if near the top or going down + if ( ms->velocity[2] < 250 ) { + // Ridah, extend the end point a bit, so we strive to get over the ledge more + vec3_t end; + + VectorSubtract( reach->end, reach->start, end ); + end[2] = 0; + VectorNormalize( end ); + VectorMA( reach->end, 32, end, end ); + hordir[0] = end[0] - ms->origin[0]; + hordir[1] = end[1] - ms->origin[1]; +// hordir[0] = reach->end[0] - ms->origin[0]; +// hordir[1] = reach->end[1] - ms->origin[1]; + // done. + hordir[2] = 0; + dist = VectorNormalize( hordir ); + // + BotCheckBlocked( ms, hordir, qtrue, &result ); + // + if ( dist > 60 ) { + dist = 60; + } + speed = 400 - ( 400 - 6 * dist ); + EA_Move( ms->client, hordir, speed ); + VectorCopy( hordir, result.movedir ); + } //end if + // + return result; +} //end of the function BotFinishTravel_BarrierJump +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +bot_moveresult_t BotTravel_Swim( bot_movestate_t *ms, aas_reachability_t *reach ) { + vec3_t dir; + bot_moveresult_t result; + + BotClearMoveResult( &result ); + //swim straight to reachability end + VectorSubtract( reach->start, ms->origin, dir ); + VectorNormalize( dir ); + // + BotCheckBlocked( ms, dir, qtrue, &result ); + //elemantary actions + EA_Move( ms->client, dir, 400 ); + // + VectorCopy( dir, result.movedir ); + Vector2Angles( dir, result.ideal_viewangles ); + result.flags |= MOVERESULT_SWIMVIEW; + // + return result; +} //end of the function BotTravel_Swim +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +bot_moveresult_t BotTravel_WaterJump( bot_movestate_t *ms, aas_reachability_t *reach ) { + vec3_t dir, hordir; + float dist; + bot_moveresult_t result; + + BotClearMoveResult( &result ); + //swim straight to reachability end + VectorSubtract( reach->end, ms->origin, dir ); + VectorCopy( dir, hordir ); + hordir[2] = 0; + dir[2] += 15 + crandom() * 40; + //botimport.Print(PRT_MESSAGE, "BotTravel_WaterJump: dir[2] = %f\n", dir[2]); + VectorNormalize( dir ); + dist = VectorNormalize( hordir ); + //elemantary actions + //EA_Move(ms->client, dir, 400); + EA_MoveForward( ms->client ); + //move up if close to the actual out of water jump spot + if ( dist < 40 ) { + EA_MoveUp( ms->client ); + } + //set the ideal view angles + Vector2Angles( dir, result.ideal_viewangles ); + result.flags |= MOVERESULT_MOVEMENTVIEW; + // + VectorCopy( dir, result.movedir ); + // + return result; +} //end of the function BotTravel_WaterJump +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +bot_moveresult_t BotFinishTravel_WaterJump( bot_movestate_t *ms, aas_reachability_t *reach ) { + vec3_t dir, pnt; + float dist; + bot_moveresult_t result; + + //botimport.Print(PRT_MESSAGE, "BotFinishTravel_WaterJump\n"); + BotClearMoveResult( &result ); + //if waterjumping there's nothing to do + if ( ms->moveflags & MFL_WATERJUMP ) { + return result; + } + //if not touching any water anymore don't do anything + //otherwise the bot sometimes keeps jumping? + VectorCopy( ms->origin, pnt ); + pnt[2] -= 32; //extra for q2dm4 near red armor/mega health + if ( !( AAS_PointContents( pnt ) & ( CONTENTS_LAVA | CONTENTS_SLIME | CONTENTS_WATER ) ) ) { + return result; + } + //swim straight to reachability end + VectorSubtract( reach->end, ms->origin, dir ); + dir[0] += crandom() * 10; + dir[1] += crandom() * 10; + dir[2] += 70 + crandom() * 10; + dist = VectorNormalize( dir ); + //elemantary actions + EA_Move( ms->client, dir, 400 ); + //set the ideal view angles + Vector2Angles( dir, result.ideal_viewangles ); + result.flags |= MOVERESULT_MOVEMENTVIEW; + // + VectorCopy( dir, result.movedir ); + // + return result; +} //end of the function BotFinishTravel_WaterJump +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +bot_moveresult_t BotTravel_WalkOffLedge( bot_movestate_t *ms, aas_reachability_t *reach ) { + vec3_t hordir, dir; + float dist, speed, reachhordist; + bot_moveresult_t result; + + BotClearMoveResult( &result ); + //check if the bot is blocked by anything + VectorSubtract( reach->start, ms->origin, dir ); + VectorNormalize( dir ); + BotCheckBlocked( ms, dir, qtrue, &result ); + //if the reachability start and end are practially above each other + VectorSubtract( reach->end, reach->start, dir ); + dir[2] = 0; + reachhordist = VectorLength( dir ); + //walk straight to the reachability start + hordir[0] = reach->start[0] - ms->origin[0]; + hordir[1] = reach->start[1] - ms->origin[1]; + hordir[2] = 0; + dist = VectorNormalize( hordir ); + //if pretty close to the start focus on the reachability end + + // Ridah, tweaked this +#if 0 + if ( dist < 48 ) { + hordir[0] = reach->end[0] - ms->origin[0]; + hordir[1] = reach->end[1] - ms->origin[1]; + hordir[2] = 0; +#else + if ( ( dist < 72 ) && ( DotProduct( dir, hordir ) < 0 ) ) { // walk in the direction of start -> end + //hordir[0] = reach->end[0] - ms->origin[0]; + //hordir[1] = reach->end[1] - ms->origin[1]; + //VectorNormalize( dir ); + //VectorMA( hordir, 48, dir, hordir ); + //hordir[2] = 0; + + VectorCopy( dir, hordir ); +#endif + VectorNormalize( hordir ); + // + if ( reachhordist < 20 ) { + //speed = 100; + speed = 200; // RF, increased this to speed up travel speed down steps + } //end if + else if ( !AAS_HorizontalVelocityForJump( 0, reach->start, reach->end, &speed ) ) { + speed = 400; + } //end if + // looks better crouching off a ledge + EA_Crouch( ms->client ); + } //end if + else + { + if ( reachhordist < 20 ) { + if ( dist > 64 ) { + dist = 64; + } + //speed = 400 - (256 - 4 * dist); + speed = 400 - ( 256 - 4 * dist ) * 0.5; // RF changed this for steps + } //end if + else + { + speed = 400; + // Ridah, tweaked this + if ( dist < 128 ) { + speed *= 0.5 + 0.5 * ( dist / 128 ); + } + } //end else + } //end else + // + BotCheckBlocked( ms, hordir, qtrue, &result ); + //elemantary action + EA_Move( ms->client, hordir, speed ); + VectorCopy( hordir, result.movedir ); + // + return result; +} //end of the function BotTravel_WalkOffLedge +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int BotAirControl( vec3_t origin, vec3_t velocity, vec3_t goal, vec3_t dir, float *speed ) { + vec3_t org, vel; + float dist; + int i; + + VectorCopy( origin, org ); + VectorScale( velocity, 0.1, vel ); + for ( i = 0; i < 50; i++ ) + { + vel[2] -= sv_gravity * 0.01; + //if going down and next position would be below the goal + if ( vel[2] < 0 && org[2] + vel[2] < goal[2] ) { + VectorScale( vel, ( goal[2] - org[2] ) / vel[2], vel ); + VectorAdd( org, vel, org ); + VectorSubtract( goal, org, dir ); + dist = VectorNormalize( dir ); + if ( dist > 32 ) { + dist = 32; + } + *speed = 400 - ( 400 - 13 * dist ); + return qtrue; + } //end if + else + { + VectorAdd( org, vel, org ); + } //end else + } //end for + VectorSet( dir, 0, 0, 0 ); + *speed = 400; + return qfalse; +} //end of the function BotAirControl +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +bot_moveresult_t BotFinishTravel_WalkOffLedge( bot_movestate_t *ms, aas_reachability_t *reach ) { + vec3_t dir, hordir, end, v; + float dist, speed; + bot_moveresult_t result; + + BotClearMoveResult( &result ); + // + VectorSubtract( reach->end, ms->origin, dir ); + BotCheckBlocked( ms, dir, qtrue, &result ); + // + VectorSubtract( reach->end, ms->origin, v ); + v[2] = 0; + dist = VectorNormalize( v ); + if ( dist > 16 ) { + VectorMA( reach->end, 16, v, end ); + } else { VectorCopy( reach->end, end );} + // + if ( !BotAirControl( ms->origin, ms->velocity, end, hordir, &speed ) ) { + //go straight to the reachability end + VectorCopy( dir, hordir ); + hordir[2] = 0; + // + dist = VectorNormalize( hordir ); + speed = 400; + } //end if + // + // looks better crouching off a ledge + EA_Crouch( ms->client ); + EA_Move( ms->client, hordir, speed ); + VectorCopy( hordir, result.movedir ); + // + return result; +} //end of the function BotFinishTravel_WalkOffLedge +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +/* +bot_moveresult_t BotTravel_Jump(bot_movestate_t *ms, aas_reachability_t *reach) +{ + vec3_t hordir; + float dist, gapdist, speed, horspeed, sv_jumpvel; + bot_moveresult_t result; + + BotClearMoveResult(&result); + // + sv_jumpvel = botlibglobals.sv_jumpvel->value; + //walk straight to the reachability start + hordir[0] = reach->start[0] - ms->origin[0]; + hordir[1] = reach->start[1] - ms->origin[1]; + hordir[2] = 0; + dist = VectorNormalize(hordir); + // + speed = 350; + // + gapdist = BotGapDistance(ms, hordir, ms->entitynum); + //if pretty close to the start focus on the reachability end + if (dist < 50 || (gapdist && gapdist < 50)) + { + //NOTE: using max speed (400) works best + //if (AAS_HorizontalVelocityForJump(sv_jumpvel, ms->origin, reach->end, &horspeed)) + //{ + // speed = horspeed * 400 / botlibglobals.sv_maxwalkvelocity->value; + //} //end if + hordir[0] = reach->end[0] - ms->origin[0]; + hordir[1] = reach->end[1] - ms->origin[1]; + VectorNormalize(hordir); + //elemantary action jump + EA_Jump(ms->client); + // + ms->jumpreach = ms->lastreachnum; + speed = 600; + } //end if + else + { + if (AAS_HorizontalVelocityForJump(sv_jumpvel, reach->start, reach->end, &horspeed)) + { + speed = horspeed * 400 / botlibglobals.sv_maxwalkvelocity->value; + } //end if + } //end else + //elemantary action + EA_Move(ms->client, hordir, speed); + VectorCopy(hordir, result.movedir); + // + return result; +} //end of the function BotTravel_Jump*/ +/* +bot_moveresult_t BotTravel_Jump(bot_movestate_t *ms, aas_reachability_t *reach) +{ + vec3_t hordir, dir1, dir2, mins, maxs, start, end; + float dist1, dist2, speed; + bot_moveresult_t result; + bsp_trace_t trace; + + BotClearMoveResult(&result); + // + hordir[0] = reach->start[0] - reach->end[0]; + hordir[1] = reach->start[1] - reach->end[1]; + hordir[2] = 0; + VectorNormalize(hordir); + // + VectorCopy(reach->start, start); + start[2] += 1; + //minus back the bouding box size plus 16 + VectorMA(reach->start, 80, hordir, end); + // + AAS_PresenceTypeBoundingBox(PRESENCE_NORMAL, mins, maxs); + //check for solids + trace = AAS_Trace(start, mins, maxs, end, ms->entitynum, MASK_PLAYERSOLID); + if (trace.startsolid) VectorCopy(start, trace.endpos); + //check for a gap + for (dist1 = 0; dist1 < 80; dist1 += 10) + { + VectorMA(start, dist1+10, hordir, end); + end[2] += 1; + if (AAS_PointAreaNum(end) != ms->reachareanum) break; + } //end for + if (dist1 < 80) VectorMA(reach->start, dist1, hordir, trace.endpos); +// dist1 = BotGapDistance(start, hordir, ms->entitynum); +// if (dist1 && dist1 <= trace.fraction * 80) VectorMA(reach->start, dist1-20, hordir, trace.endpos); + // + VectorSubtract(ms->origin, reach->start, dir1); + dir1[2] = 0; + dist1 = VectorNormalize(dir1); + VectorSubtract(ms->origin, trace.endpos, dir2); + dir2[2] = 0; + dist2 = VectorNormalize(dir2); + //if just before the reachability start + if (DotProduct(dir1, dir2) < -0.8 || dist2 < 5) + { + //botimport.Print(PRT_MESSAGE, "between jump start and run to point\n"); + hordir[0] = reach->end[0] - ms->origin[0]; + hordir[1] = reach->end[1] - ms->origin[1]; + hordir[2] = 0; + VectorNormalize(hordir); + //elemantary action jump + if (dist1 < 24) EA_Jump(ms->client); + else if (dist1 < 32) EA_DelayedJump(ms->client); + EA_Move(ms->client, hordir, 600); + // + ms->jumpreach = ms->lastreachnum; + } //end if + else + { + //botimport.Print(PRT_MESSAGE, "going towards run to point\n"); + hordir[0] = trace.endpos[0] - ms->origin[0]; + hordir[1] = trace.endpos[1] - ms->origin[1]; + hordir[2] = 0; + VectorNormalize(hordir); + // + if (dist2 > 80) dist2 = 80; + speed = 400 - (400 - 5 * dist2); + EA_Move(ms->client, hordir, speed); + } //end else + VectorCopy(hordir, result.movedir); + // + return result; +} //end of the function BotTravel_Jump*/ +//* +bot_moveresult_t BotTravel_Jump( bot_movestate_t *ms, aas_reachability_t *reach ) { + vec3_t hordir, dir1, dir2, start, end, runstart; +// vec3_t runstart, dir1, dir2, hordir; + float dist1, dist2, speed; + bot_moveresult_t result; + + BotClearMoveResult( &result ); + // + AAS_JumpReachRunStart( reach, runstart ); + //* + hordir[0] = runstart[0] - reach->start[0]; + hordir[1] = runstart[1] - reach->start[1]; + hordir[2] = 0; + VectorNormalize( hordir ); + // + VectorCopy( reach->start, start ); + start[2] += 1; + VectorMA( reach->start, 80, hordir, runstart ); + //check for a gap + for ( dist1 = 0; dist1 < 80; dist1 += 10 ) + { + VectorMA( start, dist1 + 10, hordir, end ); + end[2] += 1; + if ( AAS_PointAreaNum( end ) != ms->reachareanum ) { + break; + } + } //end for + if ( dist1 < 80 ) { + VectorMA( reach->start, dist1, hordir, runstart ); + } + // + VectorSubtract( ms->origin, reach->start, dir1 ); + dir1[2] = 0; + dist1 = VectorNormalize( dir1 ); + VectorSubtract( ms->origin, runstart, dir2 ); + dir2[2] = 0; + dist2 = VectorNormalize( dir2 ); + //if just before the reachability start + if ( DotProduct( dir1, dir2 ) < -0.8 || dist2 < 5 ) { +// botimport.Print(PRT_MESSAGE, "between jump start and run start point\n"); + hordir[0] = reach->end[0] - ms->origin[0]; + hordir[1] = reach->end[1] - ms->origin[1]; + hordir[2] = 0; + VectorNormalize( hordir ); + //elemantary action jump + if ( dist1 < 24 ) { + EA_Jump( ms->client ); + } else if ( dist1 < 32 ) { + EA_DelayedJump( ms->client ); + } + EA_Move( ms->client, hordir, 600 ); + // + ms->jumpreach = ms->lastreachnum; + } //end if + else + { +// botimport.Print(PRT_MESSAGE, "going towards run start point\n"); + hordir[0] = runstart[0] - ms->origin[0]; + hordir[1] = runstart[1] - ms->origin[1]; + hordir[2] = 0; + VectorNormalize( hordir ); + // + if ( dist2 > 80 ) { + dist2 = 80; + } + speed = 400 - ( 400 - 5 * dist2 ); + EA_Move( ms->client, hordir, speed ); + } //end else + VectorCopy( hordir, result.movedir ); + // + return result; +} //end of the function BotTravel_Jump*/ +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +bot_moveresult_t BotFinishTravel_Jump( bot_movestate_t *ms, aas_reachability_t *reach ) { + vec3_t hordir, hordir2; + float speed, dist; + bot_moveresult_t result; + + BotClearMoveResult( &result ); + //if not jumped yet + if ( !ms->jumpreach ) { + return result; + } + //go straight to the reachability end + hordir[0] = reach->end[0] - ms->origin[0]; + hordir[1] = reach->end[1] - ms->origin[1]; + hordir[2] = 0; + dist = VectorNormalize( hordir ); + // + hordir2[0] = reach->end[0] - reach->start[0]; + hordir2[1] = reach->end[1] - reach->start[1]; + hordir2[2] = 0; + VectorNormalize( hordir2 ); + // + if ( DotProduct( hordir, hordir2 ) < -0.5 && dist < 24 ) { + return result; + } + //always use max speed when traveling through the air + speed = 800; + // + EA_Move( ms->client, hordir, speed ); + VectorCopy( hordir, result.movedir ); + // + return result; +} //end of the function BotFinishTravel_Jump +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +bot_moveresult_t BotTravel_Ladder( bot_movestate_t *ms, aas_reachability_t *reach ) { + //float dist, speed; + vec3_t dir, viewdir, hordir, pos, p, v1, v2, vec, right; + vec3_t origin = {0, 0, 0}; +// vec3_t up = {0, 0, 1}; + bot_moveresult_t result; + float dist, speed; + + // RF, heavily modified, wolf has different ladder movement + + BotClearMoveResult( &result ); + // + if ( ( ms->moveflags & MFL_AGAINSTLADDER ) + //NOTE: not a good idea for ladders starting in water + || !( ms->moveflags & MFL_ONGROUND ) ) { + //botimport.Print(PRT_MESSAGE, "against ladder or not on ground\n"); + // RF, wolf has different ladder movement + VectorSubtract( reach->end, reach->start, dir ); + VectorNormalize( dir ); + //set the ideal view angles, facing the ladder up or down + viewdir[0] = dir[0]; + viewdir[1] = dir[1]; + viewdir[2] = dir[2]; + if ( dir[2] < 0 ) { // going down, so face the other way (towards ladder) + VectorInverse( viewdir ); + } + viewdir[2] = 0; // straight forward goes up + VectorNormalize( viewdir ); + Vector2Angles( viewdir, result.ideal_viewangles ); + //elemantary action + EA_Move( ms->client, origin, 0 ); + if ( dir[2] < 0 ) { // going down, so face the other way + EA_MoveBack( ms->client ); + } else { + EA_MoveForward( ms->client ); + } + // check for sideways adjustments to stay on the center of the ladder + VectorMA( ms->origin, 18, viewdir, p ); + VectorCopy( reach->start, v1 ); + v1[2] = ms->origin[2]; + VectorCopy( reach->end, v2 ); + v2[2] = ms->origin[2]; + VectorSubtract( v2, v1, vec ); + VectorNormalize( vec ); + VectorMA( v1, -32, vec, v1 ); + VectorMA( v2, 32, vec, v2 ); + ProjectPointOntoVector( p, v1, v2, pos ); + VectorSubtract( pos, p, vec ); + if ( VectorLength( vec ) > 2 ) { + AngleVectors( result.ideal_viewangles, NULL, right, NULL ); + if ( DotProduct( vec, right ) > 0 ) { + EA_MoveRight( ms->client ); + } else { + EA_MoveLeft( ms->client ); + } + } + //set movement view flag so the AI can see the view is focussed + result.flags |= MOVERESULT_MOVEMENTVIEW; + } //end if + else + { + //botimport.Print(PRT_MESSAGE, "moving towards ladder base\n"); + // find a postion back away from the base of the ladder + VectorSubtract( reach->end, reach->start, hordir ); + hordir[2] = 0; + VectorNormalize( hordir ); + VectorMA( reach->start, -24, hordir, pos ); + // project our position onto the vector + ProjectPointOntoVector( ms->origin, pos, reach->start, p ); + VectorSubtract( p, ms->origin, dir ); + //make sure the horizontal movement is large anough + VectorCopy( dir, hordir ); + hordir[2] = 0; + dist = VectorNormalize( hordir ); + if ( dist < 8 ) { // within range, go for the end + //botimport.Print(PRT_MESSAGE, "found base, moving towards ladder top\n"); + VectorSubtract( reach->end, ms->origin, dir ); + //make sure the horizontal movement is large anough + VectorCopy( dir, hordir ); + hordir[2] = 0; + dist = VectorNormalize( hordir ); + //set the ideal view angles, facing the ladder up or down + viewdir[0] = dir[0]; + viewdir[1] = dir[1]; + viewdir[2] = dir[2]; + if ( dir[2] < 0 ) { // going down, so face the other way + VectorInverse( viewdir ); + } + viewdir[2] = 0; + VectorNormalize( viewdir ); + Vector2Angles( viewdir, result.ideal_viewangles ); + result.flags |= MOVERESULT_MOVEMENTVIEW; + } + // + dir[0] = hordir[0]; + dir[1] = hordir[1]; +// if (dist < 48) { +// if (dir[2] > 0) dir[2] = 1; +// else dir[2] = -1; +// } else { + dir[2] = 0; +// } + if ( dist > 50 ) { + dist = 50; + } + speed = 400 - ( 300 - 6 * dist ); + EA_Move( ms->client, dir, speed ); + } //end else + //save the movement direction + VectorCopy( dir, result.movedir ); + // + return result; +} //end of the function BotTravel_Ladder +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +bot_moveresult_t BotTravel_Teleport( bot_movestate_t *ms, aas_reachability_t *reach ) { + vec3_t hordir; + float dist; + bot_moveresult_t result; + + BotClearMoveResult( &result ); + //if the bot is being teleported + if ( ms->moveflags & MFL_TELEPORTED ) { + return result; + } + + //walk straight to center of the teleporter + VectorSubtract( reach->start, ms->origin, hordir ); + if ( !( ms->moveflags & MFL_SWIMMING ) ) { + hordir[2] = 0; + } + dist = VectorNormalize( hordir ); + // + BotCheckBlocked( ms, hordir, qtrue, &result ); + + if ( dist < 30 ) { + EA_Move( ms->client, hordir, 200 ); + } else { EA_Move( ms->client, hordir, 400 );} + + if ( ms->moveflags & MFL_SWIMMING ) { + result.flags |= MOVERESULT_SWIMVIEW; + } + + VectorCopy( hordir, result.movedir ); + return result; +} //end of the function BotTravel_Teleport +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +bot_moveresult_t BotTravel_Elevator( bot_movestate_t *ms, aas_reachability_t *reach ) { + vec3_t dir, dir1, dir2, hordir, bottomcenter; + float dist, dist1, dist2, speed; + bot_moveresult_t result; + + BotClearMoveResult( &result ); + //if standing on the plat + if ( BotOnMover( ms->origin, ms->entitynum, reach ) ) { +#ifdef DEBUG_ELEVATOR + botimport.Print( PRT_MESSAGE, "bot on elevator\n" ); +#endif //DEBUG_ELEVATOR + //if vertically not too far from the end point + if ( abs( ms->origin[2] - reach->end[2] ) < sv_maxbarrier ) { +#ifdef DEBUG_ELEVATOR + botimport.Print( PRT_MESSAGE, "bot moving to end\n" ); +#endif //DEBUG_ELEVATOR + //move to the end point + VectorSubtract( reach->end, ms->origin, hordir ); + hordir[2] = 0; + VectorNormalize( hordir ); + if ( !BotCheckBarrierJump( ms, hordir, 100 ) ) { + EA_Move( ms->client, hordir, 400 ); + } //end if + VectorCopy( hordir, result.movedir ); + } //end else + //if not really close to the center of the elevator + else + { + MoverBottomCenter( reach, bottomcenter ); + VectorSubtract( bottomcenter, ms->origin, hordir ); + hordir[2] = 0; + dist = VectorNormalize( hordir ); + // + if ( dist > 10 ) { +#ifdef DEBUG_ELEVATOR + botimport.Print( PRT_MESSAGE, "bot moving to center\n" ); +#endif //DEBUG_ELEVATOR + //move to the center of the plat + if ( dist > 100 ) { + dist = 100; + } + speed = 400 - ( 400 - 4 * dist ); + // + EA_Move( ms->client, hordir, speed ); + VectorCopy( hordir, result.movedir ); + } //end if + } //end else + } //end if + else + { +#ifdef DEBUG_ELEVATOR + botimport.Print( PRT_MESSAGE, "bot not on elevator\n" ); +#endif //DEBUG_ELEVATOR + //if very near the reachability end + VectorSubtract( reach->end, ms->origin, dir ); + dist = VectorLength( dir ); + if ( dist < 64 ) { + if ( dist > 60 ) { + dist = 60; + } + speed = 360 - ( 360 - 6 * dist ); + // + if ( ( ms->moveflags & MFL_SWIMMING ) || !BotCheckBarrierJump( ms, dir, 50 ) ) { + if ( speed > 5 ) { + EA_Move( ms->client, dir, speed ); + } + } //end if + VectorCopy( dir, result.movedir ); + // + if ( ms->moveflags & MFL_SWIMMING ) { + result.flags |= MOVERESULT_SWIMVIEW; + } + //stop using this reachability + ms->reachability_time = 0; + return result; + } //end if + //get direction and distance to reachability start + VectorSubtract( reach->start, ms->origin, dir1 ); + if ( !( ms->moveflags & MFL_SWIMMING ) ) { + dir1[2] = 0; + } + dist1 = VectorNormalize( dir1 ); + //if the elevator isn't down + if ( !MoverDown( reach ) ) { +#ifdef DEBUG_ELEVATOR + botimport.Print( PRT_MESSAGE, "elevator not down\n" ); +#endif //DEBUG_ELEVATOR + dist = dist1; + VectorCopy( dir1, dir ); + // + BotCheckBlocked( ms, dir, qfalse, &result ); + // + if ( dist > 60 ) { + dist = 60; + } + speed = 360 - ( 360 - 6 * dist ); + // + if ( !( ms->moveflags & MFL_SWIMMING ) && !BotCheckBarrierJump( ms, dir, 50 ) ) { + if ( speed > 5 ) { + EA_Move( ms->client, dir, speed ); + } + } //end if + VectorCopy( dir, result.movedir ); + // + if ( ms->moveflags & MFL_SWIMMING ) { + result.flags |= MOVERESULT_SWIMVIEW; + } + //this isn't a failure... just wait till the elevator comes down + //result.failure = qtrue; + result.type = RESULTTYPE_ELEVATORUP; + result.flags |= MOVERESULT_WAITING; + return result; + } //end if + //get direction and distance to elevator bottom center + MoverBottomCenter( reach, bottomcenter ); + VectorSubtract( bottomcenter, ms->origin, dir2 ); + if ( !( ms->moveflags & MFL_SWIMMING ) ) { + dir2[2] = 0; + } + dist2 = VectorNormalize( dir2 ); + //if very close to the reachability start or + //closer to the elevator center or + //between reachability start and elevator center + if ( dist1 < 20 || dist2 < dist1 || DotProduct( dir1, dir2 ) < 0 ) { +#ifdef DEBUG_ELEVATOR + botimport.Print( PRT_MESSAGE, "bot moving to center\n" ); +#endif //DEBUG_ELEVATOR + dist = dist2; + VectorCopy( dir2, dir ); + } //end if + else //closer to the reachability start + { +#ifdef DEBUG_ELEVATOR + botimport.Print( PRT_MESSAGE, "bot moving to start\n" ); +#endif //DEBUG_ELEVATOR + dist = dist1; + VectorCopy( dir1, dir ); + } //end else + // + BotCheckBlocked( ms, dir, qfalse, &result ); + // + if ( dist > 60 ) { + dist = 60; + } + speed = 400 - ( 400 - 6 * dist ); + // + if ( !( ms->moveflags & MFL_SWIMMING ) && !BotCheckBarrierJump( ms, dir, 50 ) ) { + EA_Move( ms->client, dir, speed ); + } //end if + VectorCopy( dir, result.movedir ); + // + if ( ms->moveflags & MFL_SWIMMING ) { + result.flags |= MOVERESULT_SWIMVIEW; + } + } //end else + return result; +} //end of the function BotTravel_Elevator +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +bot_moveresult_t BotFinishTravel_Elevator( bot_movestate_t *ms, aas_reachability_t *reach ) { + vec3_t bottomcenter, bottomdir, topdir; + bot_moveresult_t result; + + BotClearMoveResult( &result ); + // + MoverBottomCenter( reach, bottomcenter ); + VectorSubtract( bottomcenter, ms->origin, bottomdir ); + // + VectorSubtract( reach->end, ms->origin, topdir ); + // + if ( fabs( bottomdir[2] ) < fabs( topdir[2] ) ) { + VectorNormalize( bottomdir ); + EA_Move( ms->client, bottomdir, 300 ); + } //end if + else + { + VectorNormalize( topdir ); + EA_Move( ms->client, topdir, 300 ); + } //end else + return result; +} //end of the function BotFinishTravel_Elevator +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void BotFuncBobStartEnd( aas_reachability_t *reach, vec3_t start, vec3_t end, vec3_t origin ) { + int spawnflags, modelnum; + vec3_t mins, maxs, mid, angles = {0, 0, 0}; + int num0, num1; + + modelnum = reach->facenum & 0x0000FFFF; + if ( !AAS_OriginOfEntityWithModelNum( modelnum, origin ) ) { + botimport.Print( PRT_MESSAGE, "BotFuncBobStartEnd: no entity with model %d\n", modelnum ); + VectorSet( start, 0, 0, 0 ); + VectorSet( end, 0, 0, 0 ); + return; + } //end if + AAS_BSPModelMinsMaxsOrigin( modelnum, angles, mins, maxs, NULL ); + VectorAdd( mins, maxs, mid ); + VectorScale( mid, 0.5, mid ); + VectorCopy( mid, start ); + VectorCopy( mid, end ); + spawnflags = reach->facenum >> 16; + num0 = reach->edgenum >> 16; + if ( num0 > 0x00007FFF ) { + num0 |= 0xFFFF0000; + } + num1 = reach->edgenum & 0x0000FFFF; + if ( num1 > 0x00007FFF ) { + num1 |= 0xFFFF0000; + } + if ( spawnflags & 1 ) { + start[0] = num0; + end[0] = num1; + // + origin[0] += mid[0]; + origin[1] = mid[1]; + origin[2] = mid[2]; + } //end if + else if ( spawnflags & 2 ) { + start[1] = num0; + end[1] = num1; + // + origin[0] = mid[0]; + origin[1] += mid[1]; + origin[2] = mid[2]; + } //end else if + else + { + start[2] = num0; + end[2] = num1; + // + origin[0] = mid[0]; + origin[1] = mid[1]; + origin[2] += mid[2]; + } //end else +} //end of the function BotFuncBobStartEnd +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +bot_moveresult_t BotTravel_FuncBobbing( bot_movestate_t *ms, aas_reachability_t *reach ) { + vec3_t dir, dir1, dir2, hordir, bottomcenter, bob_start, bob_end, bob_origin; + float dist, dist1, dist2, speed; + bot_moveresult_t result; + + BotClearMoveResult( &result ); + // + BotFuncBobStartEnd( reach, bob_start, bob_end, bob_origin ); + //if standing ontop of the func_bobbing + if ( BotOnMover( ms->origin, ms->entitynum, reach ) ) { +#ifdef DEBUG_FUNCBOB + botimport.Print( PRT_MESSAGE, "bot on func_bobbing\n" ); +#endif + //if near end point of reachability + VectorSubtract( bob_origin, bob_end, dir ); + if ( VectorLength( dir ) < 24 ) { +#ifdef DEBUG_FUNCBOB + botimport.Print( PRT_MESSAGE, "bot moving to reachability end\n" ); +#endif + //move to the end point + VectorSubtract( reach->end, ms->origin, hordir ); + hordir[2] = 0; + VectorNormalize( hordir ); + if ( !BotCheckBarrierJump( ms, hordir, 100 ) ) { + EA_Move( ms->client, hordir, 400 ); + } //end if + VectorCopy( hordir, result.movedir ); + } //end else + //if not really close to the center of the elevator + else + { + MoverBottomCenter( reach, bottomcenter ); + VectorSubtract( bottomcenter, ms->origin, hordir ); + hordir[2] = 0; + dist = VectorNormalize( hordir ); + // + if ( dist > 10 ) { +#ifdef DEBUG_FUNCBOB + botimport.Print( PRT_MESSAGE, "bot moving to func_bobbing center\n" ); +#endif + //move to the center of the plat + if ( dist > 100 ) { + dist = 100; + } + speed = 400 - ( 400 - 4 * dist ); + // + EA_Move( ms->client, hordir, speed ); + VectorCopy( hordir, result.movedir ); + } //end if + } //end else + } //end if + else + { +#ifdef DEBUG_FUNCBOB + botimport.Print( PRT_MESSAGE, "bot not ontop of func_bobbing\n" ); +#endif + //if very near the reachability end + VectorSubtract( reach->end, ms->origin, dir ); + dist = VectorLength( dir ); + if ( dist < 64 ) { +#ifdef DEBUG_FUNCBOB + botimport.Print( PRT_MESSAGE, "bot moving to end\n" ); +#endif + if ( dist > 60 ) { + dist = 60; + } + speed = 360 - ( 360 - 6 * dist ); + //if swimming or no barrier jump + if ( ( ms->moveflags & MFL_SWIMMING ) || !BotCheckBarrierJump( ms, dir, 50 ) ) { + if ( speed > 5 ) { + EA_Move( ms->client, dir, speed ); + } + } //end if + VectorCopy( dir, result.movedir ); + // + if ( ms->moveflags & MFL_SWIMMING ) { + result.flags |= MOVERESULT_SWIMVIEW; + } + //stop using this reachability + ms->reachability_time = 0; + return result; + } //end if + //get direction and distance to reachability start + VectorSubtract( reach->start, ms->origin, dir1 ); + if ( !( ms->moveflags & MFL_SWIMMING ) ) { + dir1[2] = 0; + } + dist1 = VectorNormalize( dir1 ); + //if func_bobbing is Not it's start position + VectorSubtract( bob_origin, bob_start, dir ); + if ( VectorLength( dir ) > 16 ) { +#ifdef DEBUG_FUNCBOB + botimport.Print( PRT_MESSAGE, "func_bobbing not at start\n" ); +#endif + dist = dist1; + VectorCopy( dir1, dir ); + // + BotCheckBlocked( ms, dir, qfalse, &result ); + // + if ( dist > 60 ) { + dist = 60; + } + speed = 360 - ( 360 - 6 * dist ); + // + if ( !( ms->moveflags & MFL_SWIMMING ) && !BotCheckBarrierJump( ms, dir, 50 ) ) { + if ( speed > 5 ) { + EA_Move( ms->client, dir, speed ); + } + } //end if + VectorCopy( dir, result.movedir ); + // + if ( ms->moveflags & MFL_SWIMMING ) { + result.flags |= MOVERESULT_SWIMVIEW; + } + //this isn't a failure... just wait till the func_bobbing arrives + result.type = RESULTTYPE_ELEVATORUP; + result.flags |= MOVERESULT_WAITING; + return result; + } //end if + //get direction and distance to func_bob bottom center + MoverBottomCenter( reach, bottomcenter ); + VectorSubtract( bottomcenter, ms->origin, dir2 ); + if ( !( ms->moveflags & MFL_SWIMMING ) ) { + dir2[2] = 0; + } + dist2 = VectorNormalize( dir2 ); + //if very close to the reachability start or + //closer to the elevator center or + //between reachability start and func_bobbing center + if ( dist1 < 20 || dist2 < dist1 || DotProduct( dir1, dir2 ) < 0 ) { +#ifdef DEBUG_FUNCBOB + botimport.Print( PRT_MESSAGE, "bot moving to func_bobbing center\n" ); +#endif + dist = dist2; + VectorCopy( dir2, dir ); + } //end if + else //closer to the reachability start + { +#ifdef DEBUG_FUNCBOB + botimport.Print( PRT_MESSAGE, "bot moving to reachability start\n" ); +#endif + dist = dist1; + VectorCopy( dir1, dir ); + } //end else + // + BotCheckBlocked( ms, dir, qfalse, &result ); + // + if ( dist > 60 ) { + dist = 60; + } + speed = 400 - ( 400 - 6 * dist ); + // + if ( !( ms->moveflags & MFL_SWIMMING ) && !BotCheckBarrierJump( ms, dir, 50 ) ) { + EA_Move( ms->client, dir, speed ); + } //end if + VectorCopy( dir, result.movedir ); + // + if ( ms->moveflags & MFL_SWIMMING ) { + result.flags |= MOVERESULT_SWIMVIEW; + } + } //end else + return result; +} //end of the function BotTravel_FuncBobbing +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +bot_moveresult_t BotFinishTravel_FuncBobbing( bot_movestate_t *ms, aas_reachability_t *reach ) { + vec3_t bob_origin, bob_start, bob_end, dir, hordir, bottomcenter; + bot_moveresult_t result; + float dist, speed; + + BotClearMoveResult( &result ); + // + BotFuncBobStartEnd( reach, bob_start, bob_end, bob_origin ); + // + VectorSubtract( bob_origin, bob_end, dir ); + dist = VectorLength( dir ); + //if the func_bobbing is near the end + if ( dist < 16 ) { + VectorSubtract( reach->end, ms->origin, hordir ); + if ( !( ms->moveflags & MFL_SWIMMING ) ) { + hordir[2] = 0; + } + dist = VectorNormalize( hordir ); + // + if ( dist > 60 ) { + dist = 60; + } + speed = 360 - ( 360 - 6 * dist ); + // + if ( speed > 5 ) { + EA_Move( ms->client, dir, speed ); + } + VectorCopy( dir, result.movedir ); + // + if ( ms->moveflags & MFL_SWIMMING ) { + result.flags |= MOVERESULT_SWIMVIEW; + } + } //end if + else + { + MoverBottomCenter( reach, bottomcenter ); + VectorSubtract( bottomcenter, ms->origin, hordir ); + if ( !( ms->moveflags & MFL_SWIMMING ) ) { + hordir[2] = 0; + } + dist = VectorNormalize( hordir ); + // + if ( dist > 5 ) { + //move to the center of the plat + if ( dist > 100 ) { + dist = 100; + } + speed = 400 - ( 400 - 4 * dist ); + // + EA_Move( ms->client, hordir, speed ); + VectorCopy( hordir, result.movedir ); + } //end if + } //end else + return result; +} //end of the function BotFinishTravel_FuncBobbing +//=========================================================================== +// 0 no valid grapple hook visible +// 1 the grapple hook is still flying +// 2 the grapple hooked into a wall +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +/* +int GrappleState(bot_movestate_t *ms, aas_reachability_t *reach) +{ + static int grapplemodelindex; + int i; + vec3_t dir; + aas_entityinfo_t entinfo; + + if (!grapplemodelindex) + { + grapplemodelindex = AAS_IndexFromModel("models/weapons/grapple/hook/tris.md2"); + } //end if + for (i = AAS_NextEntity(0); i; i = AAS_NextEntity(i)) + { + if (AAS_EntityModelindex(i) == grapplemodelindex) + { + AAS_EntityInfo(i, &entinfo); + if (VectorCompare(entinfo.origin, entinfo.old_origin)) + { + VectorSubtract(entinfo.origin, reach->end, dir); + //if hooked near the reachability end + if (VectorLength(dir) < 32) return 2; + } //end if + else + { + //still shooting hook + return 1; + } //end else + } //end if + } //end if + //no valid grapple at all + return 0; +} //end of the function GrappleState*/ +//=========================================================================== +// 0 no valid grapple hook visible +// 1 the grapple hook is still flying +// 2 the grapple hooked into a wall +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int GrappleState( bot_movestate_t *ms, aas_reachability_t *reach ) { + static int grapplemodelindex; + static libvar_t *laserhook; + int i; + vec3_t dir; + aas_entityinfo_t entinfo; + + if ( !laserhook ) { + laserhook = LibVar( "laserhook", "0" ); + } + if ( !laserhook->value && !grapplemodelindex ) { + grapplemodelindex = AAS_IndexFromModel( "models/weapons/grapple/hook/tris.md2" ); + } //end if + for ( i = AAS_NextEntity( 0 ); i; i = AAS_NextEntity( i ) ) + { + if ( ( !laserhook->value && AAS_EntityModelindex( i ) == grapplemodelindex ) +// || (laserhook->value && (AAS_EntityRenderFX(i) & RF_BEAM)) + ) { + AAS_EntityInfo( i, &entinfo ); + //if the origin is equal to the last visible origin + if ( VectorCompare( entinfo.origin, entinfo.lastvisorigin ) ) { + VectorSubtract( entinfo.origin, reach->end, dir ); + //if hooked near the reachability end + if ( VectorLength( dir ) < 32 ) { + return 2; + } + } //end if + else + { + //still shooting hook + return 1; + } //end else + } //end if + } //end for + //no valid grapple at all + return 0; +} //end of the function GrappleState +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void BotResetGrapple( bot_movestate_t *ms ) { + aas_reachability_t reach; + + AAS_ReachabilityFromNum( ms->lastreachnum, &reach ); + //if not using the grapple hook reachability anymore + if ( reach.traveltype != TRAVEL_GRAPPLEHOOK ) { + if ( ( ms->moveflags & MFL_ACTIVEGRAPPLE ) || ms->grapplevisible_time ) { + EA_Command( ms->client, CMD_HOOKOFF ); + ms->moveflags &= ~MFL_ACTIVEGRAPPLE; + ms->grapplevisible_time = 0; +#ifdef DEBUG_GRAPPLE + botimport.Print( PRT_MESSAGE, "reset grapple\n" ); +#endif //DEBUG_GRAPPLE + } //end if + } //end if +} //end of the function BotResetGrapple +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +bot_moveresult_t BotTravel_Grapple( bot_movestate_t *ms, aas_reachability_t *reach ) { + bot_moveresult_t result; + float dist, speed; + vec3_t dir, viewdir, org; + int state, areanum; + +#ifdef DEBUG_GRAPPLE + static int debugline; + if ( !debugline ) { + debugline = botimport.DebugLineCreate(); + } + botimport.DebugLineShow( debugline, reach->start, reach->end, LINECOLOR_BLUE ); +#endif //DEBUG_GRAPPLE + + BotClearMoveResult( &result ); + // + if ( ms->moveflags & MFL_GRAPPLERESET ) { + EA_Command( ms->client, CMD_HOOKOFF ); + ms->moveflags &= ~MFL_ACTIVEGRAPPLE; + return result; + } //end if + // + if ( ms->moveflags & MFL_ACTIVEGRAPPLE ) { +#ifdef DEBUG_GRAPPLE + botimport.Print( PRT_MESSAGE, "BotTravel_Grapple: active grapple\n" ); +#endif //DEBUG_GRAPPLE + // + state = GrappleState( ms, reach ); + // + VectorSubtract( reach->end, ms->origin, dir ); + dir[2] = 0; + dist = VectorLength( dir ); + //if very close to the grapple end or + //the grappled is hooked and the bot doesn't get any closer + if ( state && dist < 48 ) { + if ( ms->lastgrappledist - dist < 1 ) { + EA_Command( ms->client, CMD_HOOKOFF ); + ms->moveflags &= ~MFL_ACTIVEGRAPPLE; + ms->moveflags |= MFL_GRAPPLERESET; + ms->reachability_time = 0; //end the reachability +#ifdef DEBUG_GRAPPLE + botimport.Print( PRT_ERROR, "grapple normal end\n" ); +#endif //DEBUG_GRAPPLE + } //end if + } //end if + //if no valid grapple at all, or the grapple hooked and the bot + //isn't moving anymore + else if ( !state || ( state == 2 && dist > ms->lastgrappledist - 2 ) ) { + if ( ms->grapplevisible_time < AAS_Time() - 0.4 ) { +#ifdef DEBUG_GRAPPLE + botimport.Print( PRT_ERROR, "grapple not visible\n" ); +#endif //DEBUG_GRAPPLE + EA_Command( ms->client, CMD_HOOKOFF ); + ms->moveflags &= ~MFL_ACTIVEGRAPPLE; + ms->moveflags |= MFL_GRAPPLERESET; + ms->reachability_time = 0; //end the reachability + //result.failure = qtrue; + //result.type = RESULTTYPE_INVISIBLEGRAPPLE; + return result; + } //end if + } //end if + else + { + ms->grapplevisible_time = AAS_Time(); + } //end else + //remember the current grapple distance + ms->lastgrappledist = dist; + } //end if + else + { +#ifdef DEBUG_GRAPPLE + botimport.Print( PRT_MESSAGE, "BotTravel_Grapple: inactive grapple\n" ); +#endif //DEBUG_GRAPPLE + // + ms->grapplevisible_time = AAS_Time(); + // + VectorSubtract( reach->start, ms->origin, dir ); + if ( !( ms->moveflags & MFL_SWIMMING ) ) { + dir[2] = 0; + } + VectorAdd( ms->origin, ms->viewoffset, org ); + VectorSubtract( reach->end, org, viewdir ); + // + dist = VectorNormalize( dir ); + Vector2Angles( viewdir, result.ideal_viewangles ); + result.flags |= MOVERESULT_MOVEMENTVIEW; + // + if ( dist < 5 && + fabs( AngleDiff( result.ideal_viewangles[0], ms->viewangles[0] ) ) < 2 && + fabs( AngleDiff( result.ideal_viewangles[1], ms->viewangles[1] ) ) < 2 ) { +#ifdef DEBUG_GRAPPLE + botimport.Print( PRT_MESSAGE, "BotTravel_Grapple: activating grapple\n" ); +#endif //DEBUG_GRAPPLE + EA_Command( ms->client, CMD_HOOKON ); + ms->moveflags |= MFL_ACTIVEGRAPPLE; + ms->lastgrappledist = 999999; + } //end if + else + { + if ( dist < 70 ) { + speed = 300 - ( 300 - 4 * dist ); + } else { speed = 400;} + // + BotCheckBlocked( ms, dir, qtrue, &result ); + //elemantary action move in direction + EA_Move( ms->client, dir, speed ); + VectorCopy( dir, result.movedir ); + } //end else + //if in another area before actually grappling + areanum = AAS_PointAreaNum( ms->origin ); + if ( areanum && areanum != ms->reachareanum ) { + ms->reachability_time = 0; + } + } //end else + return result; +} //end of the function BotTravel_Grapple +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +bot_moveresult_t BotTravel_RocketJump( bot_movestate_t *ms, aas_reachability_t *reach ) { + vec3_t hordir; + float dist, speed; + bot_moveresult_t result; + + //botimport.Print(PRT_MESSAGE, "BotTravel_RocketJump: bah\n"); + BotClearMoveResult( &result ); + // + hordir[0] = reach->start[0] - ms->origin[0]; + hordir[1] = reach->start[1] - ms->origin[1]; + hordir[2] = 0; + // + dist = VectorNormalize( hordir ); + // + if ( dist < 5 ) { +// botimport.Print(PRT_MESSAGE, "between jump start and run start point\n"); + hordir[0] = reach->end[0] - ms->origin[0]; + hordir[1] = reach->end[1] - ms->origin[1]; + hordir[2] = 0; + VectorNormalize( hordir ); + //elemantary action jump + EA_Jump( ms->client ); + EA_Attack( ms->client ); + EA_Move( ms->client, hordir, 800 ); + // + ms->jumpreach = ms->lastreachnum; + } //end if + else + { + if ( dist > 80 ) { + dist = 80; + } + speed = 400 - ( 400 - 5 * dist ); + EA_Move( ms->client, hordir, speed ); + } //end else + // +/* + vec3_t hordir, dir1, dir2, start, end, runstart; + float dist1, dist2, speed; + bot_moveresult_t result; + + botimport.Print(PRT_MESSAGE, "BotTravel_RocketJump: bah\n"); + BotClearMoveResult(&result); + AAS_JumpReachRunStart(reach, runstart); + // + hordir[0] = runstart[0] - reach->start[0]; + hordir[1] = runstart[1] - reach->start[1]; + hordir[2] = 0; + VectorNormalize(hordir); + // + VectorCopy(reach->start, start); + start[2] += 1; + VectorMA(reach->start, 80, hordir, runstart); + //check for a gap + for (dist1 = 0; dist1 < 80; dist1 += 10) + { + VectorMA(start, dist1+10, hordir, end); + end[2] += 1; + if (AAS_PointAreaNum(end) != ms->reachareanum) break; + } //end for + if (dist1 < 80) VectorMA(reach->start, dist1, hordir, runstart); + // + VectorSubtract(ms->origin, reach->start, dir1); + dir1[2] = 0; + dist1 = VectorNormalize(dir1); + VectorSubtract(ms->origin, runstart, dir2); + dir2[2] = 0; + dist2 = VectorNormalize(dir2); + //if just before the reachability start + if (DotProduct(dir1, dir2) < -0.8 || dist2 < 5) + { +// botimport.Print(PRT_MESSAGE, "between jump start and run start point\n"); + hordir[0] = reach->end[0] - ms->origin[0]; + hordir[1] = reach->end[1] - ms->origin[1]; + hordir[2] = 0; + VectorNormalize(hordir); + //elemantary action jump + if (dist1 < 24) EA_Jump(ms->client); + else if (dist1 < 32) EA_DelayedJump(ms->client); + EA_Attack(ms->client); + EA_Move(ms->client, hordir, 800); + // + ms->jumpreach = ms->lastreachnum; + } //end if + else + { +// botimport.Print(PRT_MESSAGE, "going towards run start point\n"); + hordir[0] = runstart[0] - ms->origin[0]; + hordir[1] = runstart[1] - ms->origin[1]; + hordir[2] = 0; + VectorNormalize(hordir); + // + if (dist2 > 80) dist2 = 80; + speed = 400 - (400 - 5 * dist2); + EA_Move(ms->client, hordir, speed); + } //end else*/ + //look in the movement direction + Vector2Angles( hordir, result.ideal_viewangles ); + //look straight down + result.ideal_viewangles[PITCH] = 90; + //set the view angles directly + EA_View( ms->client, result.ideal_viewangles ); + //view is important for the movment + result.flags |= MOVERESULT_MOVEMENTVIEWSET; + //select the rocket launcher + EA_SelectWeapon( ms->client, WEAPONINDEX_ROCKET_LAUNCHER ); + //weapon is used for movement + result.weapon = WEAPONINDEX_ROCKET_LAUNCHER; + result.flags |= MOVERESULT_MOVEMENTWEAPON; + // + VectorCopy( hordir, result.movedir ); + // + return result; +} //end of the function BotTravel_RocketJump +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +bot_moveresult_t BotTravel_BFGJump( bot_movestate_t *ms, aas_reachability_t *reach ) { + bot_moveresult_t result; + + BotClearMoveResult( &result ); + // + return result; +} //end of the function BotTravel_BFGJump +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +bot_moveresult_t BotFinishTravel_WeaponJump( bot_movestate_t *ms, aas_reachability_t *reach ) { + vec3_t hordir; + bot_moveresult_t result; + + BotClearMoveResult( &result ); + //if not jumped yet + if ( !ms->jumpreach ) { + return result; + } + //go straight to the reachability end + hordir[0] = reach->end[0] - ms->origin[0]; + hordir[1] = reach->end[1] - ms->origin[1]; + hordir[2] = 0; + VectorNormalize( hordir ); + //always use max speed when traveling through the air + EA_Move( ms->client, hordir, 800 ); + VectorCopy( hordir, result.movedir ); + // + return result; +} //end of the function BotFinishTravel_WeaponJump +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +bot_moveresult_t BotTravel_JumpPad( bot_movestate_t *ms, aas_reachability_t *reach ) { + float dist, speed; + vec3_t hordir; + bot_moveresult_t result; + + BotClearMoveResult( &result ); + //first walk straight to the reachability start + hordir[0] = reach->start[0] - ms->origin[0]; + hordir[1] = reach->start[1] - ms->origin[1]; + hordir[2] = 0; + dist = VectorNormalize( hordir ); + // + BotCheckBlocked( ms, hordir, qtrue, &result ); + speed = 400; + //elemantary action move in direction + EA_Move( ms->client, hordir, speed ); + VectorCopy( hordir, result.movedir ); + // + return result; +} //end of the function BotTravel_JumpPad +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +bot_moveresult_t BotFinishTravel_JumpPad( bot_movestate_t *ms, aas_reachability_t *reach ) { + float speed; + vec3_t hordir; + bot_moveresult_t result; + + BotClearMoveResult( &result ); + if ( !BotAirControl( ms->origin, ms->velocity, reach->end, hordir, &speed ) ) { + hordir[0] = reach->end[0] - ms->origin[0]; + hordir[1] = reach->end[1] - ms->origin[1]; + hordir[2] = 0; + VectorNormalize( hordir ); + speed = 400; + } //end if + BotCheckBlocked( ms, hordir, qtrue, &result ); + //elemantary action move in direction + EA_Move( ms->client, hordir, speed ); + VectorCopy( hordir, result.movedir ); + // + return result; +} //end of the function BotFinishTravel_JumpPad +//=========================================================================== +// time before the reachability times out +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int BotReachabilityTime( aas_reachability_t *reach ) { + switch ( reach->traveltype ) + { + case TRAVEL_WALK: return 5; + case TRAVEL_CROUCH: return 5; + case TRAVEL_BARRIERJUMP: return 5; + case TRAVEL_LADDER: return 6; + case TRAVEL_WALKOFFLEDGE: return 5; + case TRAVEL_JUMP: return 5; + case TRAVEL_SWIM: return 5; + case TRAVEL_WATERJUMP: return 5; + case TRAVEL_TELEPORT: return 5; + case TRAVEL_ELEVATOR: return 10; + case TRAVEL_GRAPPLEHOOK: return 8; + case TRAVEL_ROCKETJUMP: return 6; + //case TRAVEL_BFGJUMP: return 6; + case TRAVEL_JUMPPAD: return 10; + case TRAVEL_FUNCBOB: return 10; + default: + { + botimport.Print( PRT_ERROR, "travel type %d not implemented yet\n", reach->traveltype ); + return 8; + } //end case + } //end switch +} //end of the function BotReachabilityTime +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +bot_moveresult_t BotMoveInGoalArea( bot_movestate_t *ms, bot_goal_t *goal ) { + bot_moveresult_t result; + vec3_t dir; + float dist, speed; + +#ifdef DEBUG + //botimport.Print(PRT_MESSAGE, "%s: moving straight to goal\n", ClientName(ms->entitynum-1)); + //AAS_ClearShownDebugLines(); + //AAS_DebugLine(ms->origin, goal->origin, LINECOLOR_RED); +#endif //DEBUG + BotClearMoveResult( &result ); + //walk straight to the goal origin + dir[0] = goal->origin[0] - ms->origin[0]; + dir[1] = goal->origin[1] - ms->origin[1]; + if ( ms->moveflags & MFL_SWIMMING ) { + dir[2] = goal->origin[2] - ms->origin[2]; + result.traveltype = TRAVEL_SWIM; + } //end if + else + { + dir[2] = 0; + result.traveltype = TRAVEL_WALK; + } //endif + // + dist = VectorNormalize( dir ); + if ( dist > 100 || ( goal->flags & GFL_NOSLOWAPPROACH ) ) { + dist = 100; + } + speed = 400 - ( 400 - 4 * dist ); + if ( speed < 10 ) { + speed = 0; + } + // + BotCheckBlocked( ms, dir, qtrue, &result ); + //elemantary action move in direction + EA_Move( ms->client, dir, speed ); + VectorCopy( dir, result.movedir ); + // + if ( ms->moveflags & MFL_SWIMMING ) { + Vector2Angles( dir, result.ideal_viewangles ); + result.flags |= MOVERESULT_SWIMVIEW; + } //end if + //if (!debugline) debugline = botimport.DebugLineCreate(); + //botimport.DebugLineShow(debugline, ms->origin, goal->origin, LINECOLOR_BLUE); + // + ms->lastreachnum = 0; + ms->lastareanum = 0; + ms->lastgoalareanum = goal->areanum; + VectorCopy( ms->origin, ms->lastorigin ); + ms->lasttime = AAS_Time(); + // + return result; +} //end of the function BotMoveInGoalArea +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_AreaRouteToGoalArea( int areanum, vec3_t origin, int goalareanum, int travelflags, int *traveltime, int *reachnum ); +extern float VectorDistance( vec3_t v1, vec3_t v2 ); +void BotMoveToGoal( bot_moveresult_t *result, int movestate, bot_goal_t *goal, int travelflags ) { + int reachnum = 0, lastreachnum, foundjumppad, ent; // TTimo: init + aas_reachability_t reach, lastreach; + bot_movestate_t *ms; + //vec3_t mins, maxs, up = {0, 0, 1}; + //bsp_trace_t trace; + //static int debugline; + + BotClearMoveResult( result ); + // + ms = BotMoveStateFromHandle( movestate ); + if ( !ms ) { + return; + } + //reset the grapple before testing if the bot has a valid goal + //because the bot could loose all it's goals when stuck to a wall + BotResetGrapple( ms ); + // + if ( !goal ) { +#ifdef DEBUG + botimport.Print( PRT_MESSAGE, "client %d: movetogoal -> no goal\n", ms->client ); +#endif //DEBUG + result->failure = qtrue; + return; + } //end if + //botimport.Print(PRT_MESSAGE, "numavoidreach = %d\n", ms->numavoidreach); + //remove some of the move flags + ms->moveflags &= ~( MFL_SWIMMING | MFL_AGAINSTLADDER ); + //set some of the move flags + //NOTE: the MFL_ONGROUND flag is also set in the higher AI + if ( AAS_OnGround( ms->origin, ms->presencetype, ms->entitynum ) ) { + ms->moveflags |= MFL_ONGROUND; + } + // + + if ( ms->moveflags & MFL_ONGROUND ) { + int modeltype, modelnum; + + ent = BotOnTopOfEntity( ms ); + + if ( ent != -1 ) { + modelnum = AAS_EntityModelindex( ent ); + if ( modelnum >= 0 && modelnum < MAX_MODELS ) { + modeltype = modeltypes[modelnum]; + + if ( modeltype == MODELTYPE_FUNC_PLAT ) { + AAS_ReachabilityFromNum( ms->lastreachnum, &reach ); + //if the bot is Not using the elevator + if ( reach.traveltype != TRAVEL_ELEVATOR || + //NOTE: the face number is the plat model number + ( reach.facenum & 0x0000FFFF ) != modelnum ) { + reachnum = AAS_NextModelReachability( 0, modelnum ); + if ( reachnum ) { + //botimport.Print(PRT_MESSAGE, "client %d: accidentally ended up on func_plat\n", ms->client); + AAS_ReachabilityFromNum( reachnum, &reach ); + ms->lastreachnum = reachnum; + ms->reachability_time = AAS_Time() + BotReachabilityTime( &reach ); + } //end if + else + { + if ( bot_developer ) { + botimport.Print( PRT_MESSAGE, "client %d: on func_plat without reachability\n", ms->client ); + } //end if + result->blocked = qtrue; + result->blockentity = ent; + result->flags |= MOVERESULT_ONTOPOFOBSTACLE; + return; + } //end else + } //end if + result->flags |= MOVERESULT_ONTOPOF_ELEVATOR; + } //end if + else if ( modeltype == MODELTYPE_FUNC_BOB ) { + AAS_ReachabilityFromNum( ms->lastreachnum, &reach ); + //if the bot is Not using the func bobbing + if ( reach.traveltype != TRAVEL_FUNCBOB || + //NOTE: the face number is the func_bobbing model number + ( reach.facenum & 0x0000FFFF ) != modelnum ) { + reachnum = AAS_NextModelReachability( 0, modelnum ); + if ( reachnum ) { + //botimport.Print(PRT_MESSAGE, "client %d: accidentally ended up on func_bobbing\n", ms->client); + AAS_ReachabilityFromNum( reachnum, &reach ); + ms->lastreachnum = reachnum; + ms->reachability_time = AAS_Time() + BotReachabilityTime( &reach ); + } //end if + else + { + if ( bot_developer ) { + botimport.Print( PRT_MESSAGE, "client %d: on func_bobbing without reachability\n", ms->client ); + } //end if + result->blocked = qtrue; + result->blockentity = ent; + result->flags |= MOVERESULT_ONTOPOFOBSTACLE; + return; + } //end else + } //end if + result->flags |= MOVERESULT_ONTOPOF_FUNCBOB; + } //end if + /* Ridah, disabled this, or standing on little fragments causes problems + else + { + result->blocked = qtrue; + result->blockentity = ent; + result->flags |= MOVERESULT_ONTOPOFOBSTACLE; + return; + } //end else + */ + } //end if + } //end if + } //end if + //if swimming + if ( AAS_Swimming( ms->origin ) ) { + ms->moveflags |= MFL_SWIMMING; + } + //if against a ladder + if ( AAS_AgainstLadder( ms->origin, ms->areanum ) ) { + ms->moveflags |= MFL_AGAINSTLADDER; + } + //if the bot is on the ground, swimming or against a ladder + if ( ms->moveflags & ( MFL_ONGROUND | MFL_SWIMMING | MFL_AGAINSTLADDER ) ) { + //botimport.Print(PRT_MESSAGE, "%s: onground, swimming or against ladder\n", ClientName(ms->entitynum-1)); + // + AAS_ReachabilityFromNum( ms->lastreachnum, &lastreach ); + //reachability area the bot is in + //ms->areanum = BotReachabilityArea(ms->origin, (lastreach.traveltype != TRAVEL_ELEVATOR)); + ms->areanum = BotFuzzyPointReachabilityArea( ms->origin ); + //if the bot is in the goal area + if ( ms->areanum == goal->areanum ) { + *result = BotMoveInGoalArea( ms, goal ); + return; + } //end if + //assume we can use the reachability from the last frame + reachnum = ms->lastreachnum; + //if there is a last reachability + +// Ridah, best calc it each frame, especially for Zombie, which moves so slow that we can't afford to take a long route +// reachnum = 0; +// done. + if ( reachnum ) { + AAS_ReachabilityFromNum( reachnum, &reach ); + //check if the reachability is still valid + if ( !( AAS_TravelFlagForType( reach.traveltype ) & travelflags ) ) { + reachnum = 0; + } //end if + //special grapple hook case + else if ( reach.traveltype == TRAVEL_GRAPPLEHOOK ) { + if ( ms->reachability_time < AAS_Time() || + ( ms->moveflags & MFL_GRAPPLERESET ) ) { + reachnum = 0; + } //end if + } //end if + //special elevator case + else if ( reach.traveltype == TRAVEL_ELEVATOR || reach.traveltype == TRAVEL_FUNCBOB ) { + if ( ( result->flags & MOVERESULT_ONTOPOF_FUNCBOB ) || + ( result->flags & MOVERESULT_ONTOPOF_FUNCBOB ) ) { + ms->reachability_time = AAS_Time() + 5; + } //end if + //if the bot was going for an elevator and reached the reachability area + if ( ms->areanum == reach.areanum || + ms->reachability_time < AAS_Time() ) { + reachnum = 0; + } //end if + } //end if + else + { +#ifdef DEBUG + if ( bot_developer ) { + if ( ms->reachability_time < AAS_Time() ) { + botimport.Print( PRT_MESSAGE, "client %d: reachability timeout in ", ms->client ); + AAS_PrintTravelType( reach.traveltype ); + botimport.Print( PRT_MESSAGE, "\n" ); + } //end if + /* + if (ms->lastareanum != ms->areanum) + { + botimport.Print(PRT_MESSAGE, "changed from area %d to %d\n", ms->lastareanum, ms->areanum); + } //end if*/ + } //end if +#endif //DEBUG + //if the goal area changed or the reachability timed out + //or the area changed + if ( ms->lastgoalareanum != goal->areanum || + ms->reachability_time < AAS_Time() || + ms->lastareanum != ms->areanum || + ( ( ms->lasttime > ( AAS_Time() - 0.5 ) ) && ( VectorDistance( ms->origin, ms->lastorigin ) < 20 * ( AAS_Time() - ms->lasttime ) ) ) ) { + reachnum = 0; + //botimport.Print(PRT_MESSAGE, "area change or timeout\n"); + } //end else if + } //end else + } //end if + //if the bot needs a new reachability + if ( !reachnum ) { + //if the area has no reachability links + if ( !AAS_AreaReachability( ms->areanum ) ) { +#ifdef DEBUG + if ( bot_developer ) { + botimport.Print( PRT_MESSAGE, "area %d no reachability\n", ms->areanum ); + } //end if +#endif //DEBUG + } //end if + //get a new reachability leading towards the goal + reachnum = BotGetReachabilityToGoal( ms->origin, ms->areanum, ms->entitynum, + ms->lastgoalareanum, ms->lastareanum, + ms->avoidreach, ms->avoidreachtimes, ms->avoidreachtries, + goal, travelflags, travelflags ); + //the area number the reachability starts in + ms->reachareanum = ms->areanum; + //reset some state variables + ms->jumpreach = 0; //for TRAVEL_JUMP + ms->moveflags &= ~MFL_GRAPPLERESET; //for TRAVEL_GRAPPLEHOOK + //if there is a reachability to the goal + if ( reachnum ) { + AAS_ReachabilityFromNum( reachnum, &reach ); + //set a timeout for this reachability + ms->reachability_time = AAS_Time() + BotReachabilityTime( &reach ); + // +#ifdef AVOIDREACH + //add the reachability to the reachabilities to avoid for a while + BotAddToAvoidReach( ms, reachnum, AVOIDREACH_TIME ); +#endif //AVOIDREACH + } //end if +#ifdef DEBUG + + else if ( bot_developer ) { + botimport.Print( PRT_MESSAGE, "goal not reachable\n" ); + memset( &reach, 0, sizeof( aas_reachability_t ) ); //make compiler happy + } //end else + if ( bot_developer ) { + //if still going for the same goal + if ( ms->lastgoalareanum == goal->areanum ) { + if ( ms->lastareanum == reach.areanum ) { + botimport.Print( PRT_MESSAGE, "same goal, going back to previous area\n" ); + } //end if + } //end if + } //end if +#endif //DEBUG + } //end else + // + ms->lastreachnum = reachnum; + ms->lastgoalareanum = goal->areanum; + ms->lastareanum = ms->areanum; + //if the bot has a reachability + if ( reachnum ) { + //get the reachability from the number + AAS_ReachabilityFromNum( reachnum, &reach ); + result->traveltype = reach.traveltype; + // +#ifdef DEBUG_AI_MOVE + AAS_ClearShownDebugLines(); + AAS_PrintTravelType( reach.traveltype ); + AAS_ShowReachability( &reach ); +#endif //DEBUG_AI_MOVE + // +#ifdef DEBUG + //botimport.Print(PRT_MESSAGE, "client %d: ", ms->client); + //AAS_PrintTravelType(reach.traveltype); + //botimport.Print(PRT_MESSAGE, "\n"); +#endif //DEBUG + switch ( reach.traveltype ) + { + case TRAVEL_WALK: *result = BotTravel_Walk( ms, &reach ); break; + case TRAVEL_CROUCH: *result = BotTravel_Crouch( ms, &reach ); break; + case TRAVEL_BARRIERJUMP: *result = BotTravel_BarrierJump( ms, &reach ); break; + case TRAVEL_LADDER: *result = BotTravel_Ladder( ms, &reach ); break; + case TRAVEL_WALKOFFLEDGE: *result = BotTravel_WalkOffLedge( ms, &reach ); break; + case TRAVEL_JUMP: *result = BotTravel_Jump( ms, &reach ); break; + case TRAVEL_SWIM: *result = BotTravel_Swim( ms, &reach ); break; + case TRAVEL_WATERJUMP: *result = BotTravel_WaterJump( ms, &reach ); break; + case TRAVEL_TELEPORT: *result = BotTravel_Teleport( ms, &reach ); break; + case TRAVEL_ELEVATOR: *result = BotTravel_Elevator( ms, &reach ); break; + case TRAVEL_GRAPPLEHOOK: *result = BotTravel_Grapple( ms, &reach ); break; + case TRAVEL_ROCKETJUMP: *result = BotTravel_RocketJump( ms, &reach ); break; + //case TRAVEL_BFGJUMP: + case TRAVEL_JUMPPAD: *result = BotTravel_JumpPad( ms, &reach ); break; + case TRAVEL_FUNCBOB: *result = BotTravel_FuncBobbing( ms, &reach ); break; + default: + { + botimport.Print( PRT_FATAL, "travel type %d not implemented yet\n", reach.traveltype ); + break; + } //end case + } //end switch + } //end if + else + { + result->failure = qtrue; + memset( &reach, 0, sizeof( aas_reachability_t ) ); + } //end else +#ifdef DEBUG + if ( bot_developer ) { + if ( result->failure ) { + botimport.Print( PRT_MESSAGE, "client %d: movement failure in ", ms->client ); + AAS_PrintTravelType( reach.traveltype ); + botimport.Print( PRT_MESSAGE, "\n" ); + } //end if + } //end if +#endif //DEBUG + } //end if + else + { + int i, numareas, areas[16]; + vec3_t end; + + //special handling of jump pads when the bot uses a jump pad without knowing it + foundjumppad = qfalse; + VectorMA( ms->origin, -2 * ms->thinktime, ms->velocity, end ); + numareas = AAS_TraceAreas( ms->origin, end, areas, NULL, 16 ); + for ( i = numareas - 1; i >= 0; i-- ) + { + if ( AAS_AreaJumpPad( areas[i] ) ) { + //botimport.Print(PRT_MESSAGE, "client %d used a jumppad without knowing, area %d\n", ms->client, areas[i]); + foundjumppad = qtrue; + lastreachnum = BotGetReachabilityToGoal( end, areas[i], ms->entitynum, + ms->lastgoalareanum, ms->lastareanum, + ms->avoidreach, ms->avoidreachtimes, ms->avoidreachtries, + goal, travelflags, TFL_JUMPPAD ); + if ( lastreachnum ) { + ms->lastreachnum = lastreachnum; + ms->lastareanum = areas[i]; + //botimport.Print(PRT_MESSAGE, "found jumppad reachability\n"); + break; + } //end if + else + { + for ( lastreachnum = AAS_NextAreaReachability( areas[i], 0 ); lastreachnum; + lastreachnum = AAS_NextAreaReachability( areas[i], lastreachnum ) ) + { + //get the reachability from the number + AAS_ReachabilityFromNum( lastreachnum, &reach ); + if ( reach.traveltype == TRAVEL_JUMPPAD ) { + ms->lastreachnum = lastreachnum; + ms->lastareanum = areas[i]; + //botimport.Print(PRT_MESSAGE, "found jumppad reachability hard!!\n"); + break; + } //end if + } //end for + if ( lastreachnum ) { + break; + } + } //end else + } //end if + } //end for + if ( bot_developer ) { + //if a jumppad is found with the trace but no reachability is found + if ( foundjumppad && !ms->lastreachnum ) { + botimport.Print( PRT_MESSAGE, "client %d didn't find jumppad reachability\n", ms->client ); + } //end if + } //end if + // + if ( ms->lastreachnum ) { + //botimport.Print(PRT_MESSAGE, "%s: NOT onground, swimming or against ladder\n", ClientName(ms->entitynum-1)); + AAS_ReachabilityFromNum( ms->lastreachnum, &reach ); + result->traveltype = reach.traveltype; +#ifdef DEBUG + //botimport.Print(PRT_MESSAGE, "client %d finish: ", ms->client); + //AAS_PrintTravelType(reach.traveltype); + //botimport.Print(PRT_MESSAGE, "\n"); +#endif //DEBUG + // + switch ( reach.traveltype ) + { + case TRAVEL_WALK: *result = BotTravel_Walk( ms, &reach ); break; //BotFinishTravel_Walk(ms, &reach); break; + case TRAVEL_CROUCH: /*do nothing*/ break; + case TRAVEL_BARRIERJUMP: *result = BotFinishTravel_BarrierJump( ms, &reach ); break; + case TRAVEL_LADDER: *result = BotTravel_Ladder( ms, &reach ); break; + case TRAVEL_WALKOFFLEDGE: *result = BotFinishTravel_WalkOffLedge( ms, &reach ); break; + case TRAVEL_JUMP: *result = BotFinishTravel_Jump( ms, &reach ); break; + case TRAVEL_SWIM: *result = BotTravel_Swim( ms, &reach ); break; + case TRAVEL_WATERJUMP: *result = BotFinishTravel_WaterJump( ms, &reach ); break; + case TRAVEL_TELEPORT: /*do nothing*/ break; + case TRAVEL_ELEVATOR: *result = BotFinishTravel_Elevator( ms, &reach ); break; + case TRAVEL_GRAPPLEHOOK: *result = BotTravel_Grapple( ms, &reach ); break; + case TRAVEL_ROCKETJUMP: *result = BotFinishTravel_WeaponJump( ms, &reach ); break; + //case TRAVEL_BFGJUMP: + case TRAVEL_JUMPPAD: *result = BotFinishTravel_JumpPad( ms, &reach ); break; + case TRAVEL_FUNCBOB: *result = BotFinishTravel_FuncBobbing( ms, &reach ); break; + default: + { + botimport.Print( PRT_FATAL, "(last) travel type %d not implemented yet\n", reach.traveltype ); + break; + } //end case + } //end switch +#ifdef DEBUG + if ( bot_developer ) { + if ( result->failure ) { + botimport.Print( PRT_MESSAGE, "client %d: movement failure in finish ", ms->client ); + AAS_PrintTravelType( reach.traveltype ); + botimport.Print( PRT_MESSAGE, "\n" ); + } //end if + } //end if +#endif //DEBUG + } //end if + } //end else + //FIXME: is it right to do this here? + if ( result->blocked ) { + ms->reachability_time -= 10 * ms->thinktime; + } + //copy the last origin + VectorCopy( ms->origin, ms->lastorigin ); + ms->lasttime = AAS_Time(); + + // RF, try to look in the direction we will be moving ahead of time + if ( reachnum > 0 && !( result->flags & ( MOVERESULT_MOVEMENTVIEW | MOVERESULT_SWIMVIEW ) ) ) { + vec3_t dir; + int ftraveltime, freachnum, straveltime, ltraveltime; + + AAS_ReachabilityFromNum( reachnum, &reach ); + if ( reach.areanum != goal->areanum ) { + if ( AAS_AreaRouteToGoalArea( reach.areanum, reach.end, goal->areanum, travelflags, &straveltime, &freachnum ) ) { + ltraveltime = 999999; + while ( AAS_AreaRouteToGoalArea( reach.areanum, reach.end, goal->areanum, travelflags, &ftraveltime, &freachnum ) ) { + // make sure we are not in a loop + if ( ftraveltime > ltraveltime ) { + break; + } + ltraveltime = ftraveltime; + // + AAS_ReachabilityFromNum( freachnum, &reach ); + if ( reach.areanum == goal->areanum ) { + VectorSubtract( goal->origin, ms->origin, dir ); + VectorNormalize( dir ); + vectoangles( dir, result->ideal_viewangles ); + result->flags |= MOVERESULT_FUTUREVIEW; + break; + } + if ( straveltime - ftraveltime > 120 ) { + VectorSubtract( reach.end, ms->origin, dir ); + VectorNormalize( dir ); + vectoangles( dir, result->ideal_viewangles ); + result->flags |= MOVERESULT_FUTUREVIEW; + break; + } + } + } + } else { + VectorSubtract( goal->origin, ms->origin, dir ); + VectorNormalize( dir ); + vectoangles( dir, result->ideal_viewangles ); + result->flags |= MOVERESULT_FUTUREVIEW; + } + } + + //return the movement result + return; +} //end of the function BotMoveToGoal +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void BotResetAvoidReach( int movestate ) { + bot_movestate_t *ms; + + ms = BotMoveStateFromHandle( movestate ); + if ( !ms ) { + return; + } + memset( ms->avoidreach, 0, MAX_AVOIDREACH * sizeof( int ) ); + memset( ms->avoidreachtimes, 0, MAX_AVOIDREACH * sizeof( float ) ); + memset( ms->avoidreachtries, 0, MAX_AVOIDREACH * sizeof( int ) ); + + // RF, also clear movestate stuff + ms->lastareanum = 0; + ms->lastgoalareanum = 0; + ms->lastreachnum = 0; +} //end of the function BotResetAvoidReach +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void BotResetLastAvoidReach( int movestate ) { + int i, latest; + float latesttime; + bot_movestate_t *ms; + + ms = BotMoveStateFromHandle( movestate ); + if ( !ms ) { + return; + } + latesttime = 0; + latest = 0; + for ( i = 0; i < MAX_AVOIDREACH; i++ ) + { + if ( ms->avoidreachtimes[i] > latesttime ) { + latesttime = ms->avoidreachtimes[i]; + latest = i; + } //end if + } //end for + if ( latesttime ) { + ms->avoidreachtimes[latest] = 0; + if ( ms->avoidreachtries[i] > 0 ) { + ms->avoidreachtries[latest]--; + } + } //end if +} //end of the function BotResetLastAvoidReach +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void BotResetMoveState( int movestate ) { + bot_movestate_t *ms; + + ms = BotMoveStateFromHandle( movestate ); + if ( !ms ) { + return; + } + memset( ms, 0, sizeof( bot_movestate_t ) ); +} //end of the function BotResetMoveState +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int BotSetupMoveAI( void ) { + BotSetBrushModelTypes(); + sv_maxstep = LibVarValue( "sv_step", "18" ); + sv_maxbarrier = LibVarValue( "sv_maxbarrier", "32" ); + sv_gravity = LibVarValue( "sv_gravity", "800" ); + return BLERR_NOERROR; +} //end of the function BotSetupMoveAI +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void BotShutdownMoveAI( void ) { + int i; + + for ( i = 1; i <= MAX_CLIENTS; i++ ) + { + if ( botmovestates[i] ) { + FreeMemory( botmovestates[i] ); + botmovestates[i] = NULL; + } //end if + } //end for +} //end of the function BotShutdownMoveAI diff --git a/Projects/Android/jni/rtcw/src/botlib/be_ai_weap.c b/Projects/Android/jni/rtcw/src/botlib/be_ai_weap.c new file mode 100644 index 0000000..72f84e6 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/botlib/be_ai_weap.c @@ -0,0 +1,547 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +/***************************************************************************** + * name: be_ai_weap.c + * + * desc: weapon AI + * + * + *****************************************************************************/ + +#include "../game/q_shared.h" +#include "l_libvar.h" +#include "l_log.h" +#include "l_memory.h" +#include "l_utils.h" +#include "l_script.h" +#include "l_precomp.h" +#include "l_struct.h" +#include "aasfile.h" +#include "../game/botlib.h" +#include "../game/be_aas.h" +#include "be_aas_funcs.h" +#include "be_interface.h" +#include "be_ai_weight.h" //fuzzy weights +#include "../game/be_ai_weap.h" + +//#define DEBUG_AI_WEAP + +//structure field offsets +#define WEAPON_OFS( x ) (int)&( ( (weaponinfo_t *)0 )->x ) +#define PROJECTILE_OFS( x ) (int)&( ( (projectileinfo_t *)0 )->x ) + +//weapon definition +fielddef_t weaponinfo_fields[] = +{ + {"number", WEAPON_OFS( number ), FT_INT}, //weapon number + {"name", WEAPON_OFS( name ), FT_STRING}, //name of the weapon + {"level", WEAPON_OFS( level ), FT_INT}, + {"model", WEAPON_OFS( model ), FT_STRING}, //model of the weapon + {"weaponindex", WEAPON_OFS( weaponindex ), FT_INT}, //index of weapon in inventory + {"flags", WEAPON_OFS( flags ), FT_INT}, //special flags + {"projectile", WEAPON_OFS( projectile ), FT_STRING}, //projectile used by the weapon + {"numprojectiles", WEAPON_OFS( numprojectiles ), FT_INT}, //number of projectiles + {"hspread", WEAPON_OFS( hspread ), FT_FLOAT}, //horizontal spread of projectiles (degrees from middle) + {"vspread", WEAPON_OFS( vspread ), FT_FLOAT}, //vertical spread of projectiles (degrees from middle) + {"speed", WEAPON_OFS( speed ), FT_FLOAT}, //speed of the projectile (0 = instant hit) + {"acceleration", WEAPON_OFS( acceleration ), FT_FLOAT}, //"acceleration" * time (in seconds) + "speed" = projectile speed + {"recoil", WEAPON_OFS( recoil ), FT_FLOAT | FT_ARRAY, 3}, //amount of recoil the player gets from the weapon + {"offset", WEAPON_OFS( offset ), FT_FLOAT | FT_ARRAY, 3}, //projectile start offset relative to eye and view angles + {"angleoffset", WEAPON_OFS( angleoffset ), FT_FLOAT | FT_ARRAY, 3}, //offset of the shoot angles relative to the view angles + {"extrazvelocity", WEAPON_OFS( extrazvelocity ), FT_FLOAT}, //extra z velocity the projectile gets + {"ammoamount", WEAPON_OFS( ammoamount ), FT_INT}, //ammo amount used per shot + {"ammoindex", WEAPON_OFS( ammoindex ), FT_INT}, //index of ammo in inventory + {"activate", WEAPON_OFS( activate ), FT_FLOAT}, //time it takes to select the weapon + {"reload", WEAPON_OFS( reload ), FT_FLOAT}, //time it takes to reload the weapon + {"spinup", WEAPON_OFS( spinup ), FT_FLOAT}, //time it takes before first shot + {"spindown", WEAPON_OFS( spindown ), FT_FLOAT}, //time it takes before weapon stops firing + {NULL, 0, 0, 0} +}; + +//projectile definition +fielddef_t projectileinfo_fields[] = +{ + {"name", PROJECTILE_OFS( name ), FT_STRING}, //name of the projectile + {"model", WEAPON_OFS( model ), FT_STRING}, //model of the projectile + {"flags", PROJECTILE_OFS( flags ), FT_INT}, //special flags + {"gravity", PROJECTILE_OFS( gravity ), FT_FLOAT}, //amount of gravity applied to the projectile [0,1] + {"damage", PROJECTILE_OFS( damage ), FT_INT}, //damage of the projectile + {"radius", PROJECTILE_OFS( radius ), FT_FLOAT}, //radius of damage + {"visdamage", PROJECTILE_OFS( visdamage ), FT_INT}, //damage of the projectile to visible entities + {"damagetype", PROJECTILE_OFS( damagetype ), FT_INT}, //type of damage (combination of the DAMAGETYPE_? flags) + {"healthinc", PROJECTILE_OFS( healthinc ), FT_INT}, //health increase the owner gets + {"push", PROJECTILE_OFS( push ), FT_FLOAT}, //amount a player is pushed away from the projectile impact + {"detonation", PROJECTILE_OFS( detonation ), FT_FLOAT}, //time before projectile explodes after fire pressed + {"bounce", PROJECTILE_OFS( bounce ), FT_FLOAT}, //amount the projectile bounces + {"bouncefric", PROJECTILE_OFS( bouncefric ), FT_FLOAT}, //amount the bounce decreases per bounce + {"bouncestop", PROJECTILE_OFS( bouncestop ), FT_FLOAT}, //minimum bounce value before bouncing stops +//recurive projectile definition?? + {NULL, 0, 0, 0} +}; + +structdef_t weaponinfo_struct = +{ + sizeof( weaponinfo_t ), weaponinfo_fields +}; +structdef_t projectileinfo_struct = +{ + sizeof( projectileinfo_t ), projectileinfo_fields +}; + +//weapon configuration: set of weapons with projectiles +typedef struct weaponconfig_s +{ + int numweapons; + int numprojectiles; + projectileinfo_t *projectileinfo; + weaponinfo_t *weaponinfo; +} weaponconfig_t; + +//the bot weapon state +typedef struct bot_weaponstate_s +{ + struct weightconfig_s *weaponweightconfig; //weapon weight configuration + int *weaponweightindex; //weapon weight index +} bot_weaponstate_t; + +bot_weaponstate_t *botweaponstates[MAX_CLIENTS + 1]; +weaponconfig_t *weaponconfig; + +//======================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//======================================================================== +int BotValidWeaponNumber( int weaponnum ) { + if ( weaponnum <= 0 || weaponnum > weaponconfig->numweapons ) { + botimport.Print( PRT_ERROR, "weapon number out of range\n" ); + return qfalse; + } //end if + return qtrue; +} //end of the function BotValidWeaponNumber +//======================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//======================================================================== +bot_weaponstate_t *BotWeaponStateFromHandle( int handle ) { + if ( handle <= 0 || handle > MAX_CLIENTS ) { + botimport.Print( PRT_FATAL, "move state handle %d out of range\n", handle ); + return NULL; + } //end if + if ( !botweaponstates[handle] ) { + botimport.Print( PRT_FATAL, "invalid move state %d\n", handle ); + return NULL; + } //end if + return botweaponstates[handle]; +} //end of the function BotWeaponStateFromHandle +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +#ifdef DEBUG_AI_WEAP +void DumpWeaponConfig( weaponconfig_t *wc ) { + FILE *fp; + int i; + + fp = Log_FileStruct(); + if ( !fp ) { + return; + } + for ( i = 0; i < wc->numprojectiles; i++ ) + { + WriteStructure( fp, &projectileinfo_struct, (char *) &wc->projectileinfo[i] ); + Log_Flush(); + } //end for + for ( i = 0; i < wc->numweapons; i++ ) + { + WriteStructure( fp, &weaponinfo_struct, (char *) &wc->weaponinfo[i] ); + Log_Flush(); + } //end for +} //end of the function DumpWeaponConfig +#endif //DEBUG_AI_WEAP +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +weaponconfig_t *LoadWeaponConfig( char *filename ) { + int max_weaponinfo, max_projectileinfo; + token_t token; + char path[MAX_PATH]; + int i, j; + source_t *source; + weaponconfig_t *wc; + weaponinfo_t weaponinfo; + + max_weaponinfo = (int) LibVarValue( "max_weaponinfo", "32" ); + if ( max_weaponinfo < 0 ) { + botimport.Print( PRT_ERROR, "max_weaponinfo = %d\n", max_weaponinfo ); + max_weaponinfo = 32; + LibVarSet( "max_weaponinfo", "32" ); + } //end if + max_projectileinfo = (int) LibVarValue( "max_projectileinfo", "32" ); + if ( max_projectileinfo < 0 ) { + botimport.Print( PRT_ERROR, "max_projectileinfo = %d\n", max_projectileinfo ); + max_projectileinfo = 32; + LibVarSet( "max_projectileinfo", "32" ); + } //end if + strncpy( path, filename, MAX_PATH ); + source = LoadSourceFile( path ); + if ( !source ) { + botimport.Print( PRT_ERROR, "counldn't load %s\n", path ); + return NULL; + } //end if + //initialize weapon config + wc = (weaponconfig_t *) GetClearedHunkMemory( sizeof( weaponconfig_t ) + + max_weaponinfo * sizeof( weaponinfo_t ) + + max_projectileinfo * sizeof( projectileinfo_t ) ); + wc->weaponinfo = ( weaponinfo_t * )( (char *) wc + sizeof( weaponconfig_t ) ); + wc->projectileinfo = ( projectileinfo_t * )( (char *) wc->weaponinfo + + max_weaponinfo * sizeof( weaponinfo_t ) ); + wc->numweapons = max_weaponinfo; + wc->numprojectiles = 0; + //parse the source file + while ( PC_ReadToken( source, &token ) ) + { + if ( !strcmp( token.string, "weaponinfo" ) ) { + memset( &weaponinfo, 0, sizeof( weaponinfo_t ) ); + if ( !ReadStructure( source, &weaponinfo_struct, (char *) &weaponinfo ) ) { + FreeMemory( wc ); + FreeSource( source ); + return NULL; + } //end if + if ( weaponinfo.number < 0 || weaponinfo.number >= max_weaponinfo ) { + botimport.Print( PRT_ERROR, "weapon info number %d out of range in %s\n", weaponinfo.number, path ); + FreeMemory( wc ); + FreeSource( source ); + return NULL; + } //end if + memcpy( &wc->weaponinfo[weaponinfo.number], &weaponinfo, sizeof( weaponinfo_t ) ); + wc->weaponinfo[weaponinfo.number].valid = qtrue; + } //end if + else if ( !strcmp( token.string, "projectileinfo" ) ) { + if ( wc->numprojectiles >= max_projectileinfo ) { + botimport.Print( PRT_ERROR, "more than %d projectiles defined in %s\n", max_projectileinfo, path ); + FreeMemory( wc ); + FreeSource( source ); + return NULL; + } //end if + memset( &wc->projectileinfo[wc->numprojectiles], 0, sizeof( projectileinfo_t ) ); + if ( !ReadStructure( source, &projectileinfo_struct, (char *) &wc->projectileinfo[wc->numprojectiles] ) ) { + FreeMemory( wc ); + FreeSource( source ); + return NULL; + } //end if + wc->numprojectiles++; + } //end if + else + { + botimport.Print( PRT_ERROR, "unknown definition %s in %s\n", token.string, path ); + FreeMemory( wc ); + FreeSource( source ); + return NULL; + } //end else + } //end while + FreeSource( source ); + //fix up weapons + for ( i = 0; i < wc->numweapons; i++ ) + { + if ( !wc->weaponinfo[i].valid ) { + continue; + } + if ( !wc->weaponinfo[i].name[0] ) { + botimport.Print( PRT_ERROR, "weapon %d has no name in %s\n", i, path ); + FreeMemory( wc ); + return NULL; + } //end if + if ( !wc->weaponinfo[i].projectile[0] ) { + botimport.Print( PRT_ERROR, "weapon %s has no projectile in %s\n", wc->weaponinfo[i].name, path ); + FreeMemory( wc ); + return NULL; + } //end if + //find the projectile info and copy it to the weapon info + for ( j = 0; j < wc->numprojectiles; j++ ) + { + if ( !strcmp( wc->projectileinfo[j].name, wc->weaponinfo[i].projectile ) ) { + memcpy( &wc->weaponinfo[i].proj, &wc->projectileinfo[j], sizeof( projectileinfo_t ) ); + break; + } //end if + } //end for + if ( j == wc->numprojectiles ) { + botimport.Print( PRT_ERROR, "weapon %s uses undefined projectile in %s\n", wc->weaponinfo[i].name, path ); + FreeMemory( wc ); + return NULL; + } //end if + } //end for + if ( !wc->numweapons ) { + botimport.Print( PRT_WARNING, "no weapon info loaded\n" ); + } + botimport.Print( PRT_MESSAGE, "loaded %s\n", path ); + return wc; +} //end of the function LoadWeaponConfig +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int *WeaponWeightIndex( weightconfig_t *wwc, weaponconfig_t *wc ) { + int *index, i; + + //initialize item weight index + index = (int *) GetClearedMemory( sizeof( int ) * wc->numweapons ); + + for ( i = 0; i < wc->numweapons; i++ ) + { + index[i] = FindFuzzyWeight( wwc, wc->weaponinfo[i].name ); + } //end for + return index; +} //end of the function WeaponWeightIndex +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void BotFreeWeaponWeights( int weaponstate ) { + bot_weaponstate_t *ws; + + ws = BotWeaponStateFromHandle( weaponstate ); + if ( !ws ) { + return; + } + if ( ws->weaponweightconfig ) { + FreeWeightConfig( ws->weaponweightconfig ); + } + if ( ws->weaponweightindex ) { + FreeMemory( ws->weaponweightindex ); + } +} //end of the function BotFreeWeaponWeights +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int BotLoadWeaponWeights( int weaponstate, char *filename ) { + bot_weaponstate_t *ws; + + ws = BotWeaponStateFromHandle( weaponstate ); + if ( !ws ) { + return BLERR_CANNOTLOADWEAPONWEIGHTS; + } + BotFreeWeaponWeights( weaponstate ); + // + ws->weaponweightconfig = ReadWeightConfig( filename ); + if ( !ws->weaponweightconfig ) { + botimport.Print( PRT_FATAL, "couldn't load weapon config %s\n", filename ); + return BLERR_CANNOTLOADWEAPONWEIGHTS; + } //end if + if ( !weaponconfig ) { + return BLERR_CANNOTLOADWEAPONCONFIG; + } + ws->weaponweightindex = WeaponWeightIndex( ws->weaponweightconfig, weaponconfig ); + return BLERR_NOERROR; +} //end of the function BotLoadWeaponWeights +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void BotGetWeaponInfo( int weaponstate, int weapon, weaponinfo_t *weaponinfo ) { + bot_weaponstate_t *ws; + + if ( !BotValidWeaponNumber( weapon ) ) { + return; + } + ws = BotWeaponStateFromHandle( weaponstate ); + if ( !ws ) { + return; + } + if ( !weaponconfig ) { + return; + } + memcpy( weaponinfo, &weaponconfig->weaponinfo[weapon], sizeof( weaponinfo_t ) ); +} //end of the function BotGetWeaponInfo +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int BotChooseBestFightWeapon( int weaponstate, int *inventory ) { + int i, index, bestweapon; + float weight, bestweight; + weaponconfig_t *wc; + bot_weaponstate_t *ws; + + ws = BotWeaponStateFromHandle( weaponstate ); + if ( !ws ) { + return 0; + } + wc = weaponconfig; + if ( !weaponconfig ) { + return 0; + } + + //if the bot has no weapon weight configuration + if ( !ws->weaponweightconfig ) { + return 0; + } + + bestweight = 0; + bestweapon = 0; + for ( i = 0; i < wc->numweapons; i++ ) + { + if ( !wc->weaponinfo[i].valid ) { + continue; + } + index = ws->weaponweightindex[i]; + if ( index < 0 ) { + continue; + } + weight = FuzzyWeight( inventory, ws->weaponweightconfig, index ); + if ( weight > bestweight ) { + bestweight = weight; + bestweapon = i; + } //end if + } //end for + return bestweapon; +} //end of the function BotChooseBestFightWeapon +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void BotResetWeaponState( int weaponstate ) { + struct weightconfig_s *weaponweightconfig; + int *weaponweightindex; + bot_weaponstate_t *ws; + + ws = BotWeaponStateFromHandle( weaponstate ); + if ( !ws ) { + return; + } + weaponweightconfig = ws->weaponweightconfig; + weaponweightindex = ws->weaponweightindex; + + //memset(ws, 0, sizeof(bot_weaponstate_t)); + ws->weaponweightconfig = weaponweightconfig; + ws->weaponweightindex = weaponweightindex; +} //end of the function BotResetWeaponState +//======================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//======================================================================== +int BotAllocWeaponState( void ) { + int i; + + for ( i = 1; i <= MAX_CLIENTS; i++ ) + { + if ( !botweaponstates[i] ) { + botweaponstates[i] = GetClearedMemory( sizeof( bot_weaponstate_t ) ); + return i; + } //end if + } //end for + return 0; +} //end of the function BotAllocWeaponState +//======================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//======================================================================== +void BotFreeWeaponState( int handle ) { + if ( handle <= 0 || handle > MAX_CLIENTS ) { + botimport.Print( PRT_FATAL, "move state handle %d out of range\n", handle ); + return; + } //end if + if ( !botweaponstates[handle] ) { + botimport.Print( PRT_FATAL, "invalid move state %d\n", handle ); + return; + } //end if + BotFreeWeaponWeights( handle ); + FreeMemory( botweaponstates[handle] ); + botweaponstates[handle] = NULL; +} //end of the function BotFreeWeaponState +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int BotSetupWeaponAI( void ) { + char *file; + + file = LibVarString( "weaponconfig", "weapons.c" ); + weaponconfig = LoadWeaponConfig( file ); + if ( !weaponconfig ) { + botimport.Print( PRT_FATAL, "couldn't load the weapon config\n" ); + return BLERR_CANNOTLOADWEAPONCONFIG; + } //end if + +#ifdef DEBUG_AI_WEAP + DumpWeaponConfig( weaponconfig ); +#endif //DEBUG_AI_WEAP + // + return BLERR_NOERROR; +} //end of the function BotSetupWeaponAI +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void BotShutdownWeaponAI( void ) { + int i; + + if ( weaponconfig ) { + FreeMemory( weaponconfig ); + } + weaponconfig = NULL; + + for ( i = 1; i <= MAX_CLIENTS; i++ ) + { + if ( botweaponstates[i] ) { + BotFreeWeaponState( i ); + } //end if + } //end for +} //end of the function BotShutdownWeaponAI + diff --git a/Projects/Android/jni/rtcw/src/botlib/be_ai_weight.c b/Projects/Android/jni/rtcw/src/botlib/be_ai_weight.c new file mode 100644 index 0000000..f99c29e --- /dev/null +++ b/Projects/Android/jni/rtcw/src/botlib/be_ai_weight.c @@ -0,0 +1,972 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +/***************************************************************************** + * name: be_ai_weight.c + * + * desc: fuzzy logic + * + * + *****************************************************************************/ + +#include "../game/q_shared.h" +#include "l_memory.h" +#include "l_log.h" +#include "l_utils.h" +#include "l_script.h" +#include "l_precomp.h" +#include "l_struct.h" +#include "l_libvar.h" +#include "aasfile.h" +#include "../game/botlib.h" +#include "../game/be_aas.h" +#include "be_aas_funcs.h" +#include "be_interface.h" +#include "be_ai_weight.h" + +#define MAX_INVENTORYVALUE 999999 +#define EVALUATERECURSIVELY + +#define MAX_WEIGHT_FILES 128 +weightconfig_t *weightFileList[MAX_WEIGHT_FILES]; + +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int ReadValue( source_t *source, float *value ) { + token_t token; + + if ( !PC_ExpectAnyToken( source, &token ) ) { + return qfalse; + } + if ( !strcmp( token.string, "-" ) ) { + SourceWarning( source, "negative value set to zero\n" ); + if ( !PC_ExpectTokenType( source, TT_NUMBER, 0, &token ) ) { + return qfalse; + } + } //end if + if ( token.type != TT_NUMBER ) { + SourceError( source, "invalid return value %s\n", token.string ); + return qfalse; + } //end if + *value = token.floatvalue; + return qtrue; +} //end of the function ReadValue +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int ReadFuzzyWeight( source_t *source, fuzzyseperator_t *fs ) { + if ( PC_CheckTokenString( source, "balance" ) ) { + fs->type = WT_BALANCE; + if ( !PC_ExpectTokenString( source, "(" ) ) { + return qfalse; + } + if ( !ReadValue( source, &fs->weight ) ) { + return qfalse; + } + if ( !PC_ExpectTokenString( source, "," ) ) { + return qfalse; + } + if ( !ReadValue( source, &fs->minweight ) ) { + return qfalse; + } + if ( !PC_ExpectTokenString( source, "," ) ) { + return qfalse; + } + if ( !ReadValue( source, &fs->maxweight ) ) { + return qfalse; + } + if ( !PC_ExpectTokenString( source, ")" ) ) { + return qfalse; + } + } //end if + else + { + fs->type = 0; + if ( !ReadValue( source, &fs->weight ) ) { + return qfalse; + } + fs->minweight = fs->weight; + fs->maxweight = fs->weight; + } //end if + if ( !PC_ExpectTokenString( source, ";" ) ) { + return qfalse; + } + return qtrue; +} //end of the function ReadFuzzyWeight +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void FreeFuzzySeperators_r( fuzzyseperator_t *fs ) { + if ( !fs ) { + return; + } + if ( fs->child ) { + FreeFuzzySeperators_r( fs->child ); + } + if ( fs->next ) { + FreeFuzzySeperators_r( fs->next ); + } + FreeMemory( fs ); +} //end of the function FreeFuzzySeperators +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void FreeWeightConfig2( weightconfig_t *config ) { + int i; + + for ( i = 0; i < config->numweights; i++ ) + { + FreeFuzzySeperators_r( config->weights[i].firstseperator ); + if ( config->weights[i].name ) { + FreeMemory( config->weights[i].name ); + } + } //end for + FreeMemory( config ); +} //end of the function FreeWeightConfig2 +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void FreeWeightConfig( weightconfig_t *config ) { + if ( !LibVarGetValue( "bot_reloadcharacters" ) ) { + return; + } + FreeWeightConfig2( config ); +} //end of the function FreeWeightConfig +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +fuzzyseperator_t *ReadFuzzySeperators_r( source_t *source ) { + int newindent, index, def, founddefault; + token_t token; + fuzzyseperator_t *fs, *lastfs, *firstfs; + + founddefault = qfalse; + firstfs = NULL; + lastfs = NULL; + if ( !PC_ExpectTokenString( source, "(" ) ) { + return NULL; + } + if ( !PC_ExpectTokenType( source, TT_NUMBER, TT_INTEGER, &token ) ) { + return NULL; + } + index = token.intvalue; + if ( !PC_ExpectTokenString( source, ")" ) ) { + return NULL; + } + if ( !PC_ExpectTokenString( source, "{" ) ) { + return NULL; + } + if ( !PC_ExpectAnyToken( source, &token ) ) { + return NULL; + } + do + { + def = !strcmp( token.string, "default" ); + if ( def || !strcmp( token.string, "case" ) ) { + fs = (fuzzyseperator_t *) GetClearedMemory( sizeof( fuzzyseperator_t ) ); + fs->index = index; + if ( lastfs ) { + lastfs->next = fs; + } else { firstfs = fs;} + lastfs = fs; + if ( def ) { + if ( founddefault ) { + SourceError( source, "switch already has a default\n" ); + FreeFuzzySeperators_r( firstfs ); + return NULL; + } //end if + fs->value = MAX_INVENTORYVALUE; + founddefault = qtrue; + } //end if + else + { + if ( !PC_ExpectTokenType( source, TT_NUMBER, TT_INTEGER, &token ) ) { + FreeFuzzySeperators_r( firstfs ); + return NULL; + } //end if + fs->value = token.intvalue; + } //end else + if ( !PC_ExpectTokenString( source, ":" ) || !PC_ExpectAnyToken( source, &token ) ) { + FreeFuzzySeperators_r( firstfs ); + return NULL; + } //end if + newindent = qfalse; + if ( !strcmp( token.string, "{" ) ) { + newindent = qtrue; + if ( !PC_ExpectAnyToken( source, &token ) ) { + FreeFuzzySeperators_r( firstfs ); + return NULL; + } //end if + } //end if + if ( !strcmp( token.string, "return" ) ) { + if ( !ReadFuzzyWeight( source, fs ) ) { + FreeFuzzySeperators_r( firstfs ); + return NULL; + } //end if + } //end if + else if ( !strcmp( token.string, "switch" ) ) { + fs->child = ReadFuzzySeperators_r( source ); + if ( !fs->child ) { + FreeFuzzySeperators_r( firstfs ); + return NULL; + } //end if + } //end else if + else + { + SourceError( source, "invalid name %s\n", token.string ); + return NULL; + } //end else + if ( newindent ) { + if ( !PC_ExpectTokenString( source, "}" ) ) { + FreeFuzzySeperators_r( firstfs ); + return NULL; + } //end if + } //end if + } //end if + else + { + FreeFuzzySeperators_r( firstfs ); + SourceError( source, "invalid name %s\n", token.string ); + return NULL; + } //end else + if ( !PC_ExpectAnyToken( source, &token ) ) { + FreeFuzzySeperators_r( firstfs ); + return NULL; + } //end if + } while ( strcmp( token.string, "}" ) ); + // + if ( !founddefault ) { + SourceWarning( source, "switch without default\n" ); + fs = (fuzzyseperator_t *) GetClearedMemory( sizeof( fuzzyseperator_t ) ); + fs->index = index; + fs->value = MAX_INVENTORYVALUE; + fs->weight = 0; + fs->next = NULL; + fs->child = NULL; + if ( lastfs ) { + lastfs->next = fs; + } else { firstfs = fs;} + lastfs = fs; + } //end if + // + return firstfs; +} //end of the function ReadFuzzySeperators_r +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +weightconfig_t *ReadWeightConfig( char *filename ) { + int newindent, avail = 0, n; + token_t token; + source_t *source; + fuzzyseperator_t *fs; + weightconfig_t *config = NULL; +#ifdef DEBUG + int starttime; + + starttime = Sys_MilliSeconds(); +#endif //DEBUG + + if ( !LibVarGetValue( "bot_reloadcharacters" ) ) { + avail = -1; + for ( n = 0; n < MAX_WEIGHT_FILES; n++ ) + { + config = weightFileList[n]; + if ( !config ) { + if ( avail == -1 ) { + avail = n; + } //end if + continue; + } //end if + if ( strcmp( filename, config->filename ) == 0 ) { + //botimport.Print( PRT_MESSAGE, "retained %s\n", filename ); + return config; + } //end if + } //end for + + if ( avail == -1 ) { + botimport.Print( PRT_ERROR, "weightFileList was full trying to load %s\n", filename ); + return NULL; + } //end if + } //end if + + source = LoadSourceFile( filename ); + if ( !source ) { + botimport.Print( PRT_ERROR, "counldn't load %s\n", filename ); + return NULL; + } //end if + // + config = (weightconfig_t *) GetClearedMemory( sizeof( weightconfig_t ) ); + config->numweights = 0; + Q_strncpyz( config->filename, filename, sizeof( config->filename ) ); + //parse the item config file + while ( PC_ReadToken( source, &token ) ) + { + if ( !strcmp( token.string, "weight" ) ) { + if ( config->numweights >= MAX_WEIGHTS ) { + SourceWarning( source, "too many fuzzy weights\n" ); + break; + } //end if + if ( !PC_ExpectTokenType( source, TT_STRING, 0, &token ) ) { + FreeWeightConfig( config ); + FreeSource( source ); + return NULL; + } //end if + StripDoubleQuotes( token.string ); + config->weights[config->numweights].name = (char *) GetClearedMemory( strlen( token.string ) + 1 ); + strcpy( config->weights[config->numweights].name, token.string ); + if ( !PC_ExpectAnyToken( source, &token ) ) { + FreeWeightConfig( config ); + FreeSource( source ); + return NULL; + } //end if + newindent = qfalse; + if ( !strcmp( token.string, "{" ) ) { + newindent = qtrue; + if ( !PC_ExpectAnyToken( source, &token ) ) { + FreeWeightConfig( config ); + FreeSource( source ); + return NULL; + } //end if + } //end if + if ( !strcmp( token.string, "switch" ) ) { + fs = ReadFuzzySeperators_r( source ); + if ( !fs ) { + FreeWeightConfig( config ); + FreeSource( source ); + return NULL; + } //end if + config->weights[config->numweights].firstseperator = fs; + } //end if + else if ( !strcmp( token.string, "return" ) ) { + fs = (fuzzyseperator_t *) GetClearedMemory( sizeof( fuzzyseperator_t ) ); + fs->index = 0; + fs->value = MAX_INVENTORYVALUE; + fs->next = NULL; + fs->child = NULL; + if ( !ReadFuzzyWeight( source, fs ) ) { + FreeMemory( fs ); + FreeWeightConfig( config ); + FreeSource( source ); + return NULL; + } //end if + config->weights[config->numweights].firstseperator = fs; + } //end else if + else + { + SourceError( source, "invalid name %s\n", token.string ); + FreeWeightConfig( config ); + FreeSource( source ); + return NULL; + } //end else + if ( newindent ) { + if ( !PC_ExpectTokenString( source, "}" ) ) { + FreeWeightConfig( config ); + FreeSource( source ); + return NULL; + } //end if + } //end if + config->numweights++; + } //end if + else + { + SourceError( source, "invalid name %s\n", token.string ); + FreeWeightConfig( config ); + FreeSource( source ); + return NULL; + } //end else + } //end while + //free the source at the end of a pass + FreeSource( source ); + //if the file was located in a pak file + botimport.Print( PRT_MESSAGE, "loaded %s\n", filename ); +#ifdef DEBUG + if ( bot_developer ) { + botimport.Print( PRT_MESSAGE, "weights loaded in %d msec\n", Sys_MilliSeconds() - starttime ); + } //end if +#endif //DEBUG + // + if ( !LibVarGetValue( "bot_reloadcharacters" ) ) { + weightFileList[avail] = config; + } //end if + // + return config; +} //end of the function ReadWeightConfig +#if 0 +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +qboolean WriteFuzzyWeight( FILE *fp, fuzzyseperator_t *fs ) { + if ( fs->type == WT_BALANCE ) { + if ( fprintf( fp, " return balance(" ) < 0 ) { + return qfalse; + } + if ( !WriteFloat( fp, fs->weight ) ) { + return qfalse; + } + if ( fprintf( fp, "," ) < 0 ) { + return qfalse; + } + if ( !WriteFloat( fp, fs->minweight ) ) { + return qfalse; + } + if ( fprintf( fp, "," ) < 0 ) { + return qfalse; + } + if ( !WriteFloat( fp, fs->maxweight ) ) { + return qfalse; + } + if ( fprintf( fp, ");\n" ) < 0 ) { + return qfalse; + } + } //end if + else + { + if ( fprintf( fp, " return " ) < 0 ) { + return qfalse; + } + if ( !WriteFloat( fp, fs->weight ) ) { + return qfalse; + } + if ( fprintf( fp, ";\n" ) < 0 ) { + return qfalse; + } + } //end else + return qtrue; +} //end of the function WriteFuzzyWeight +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +qboolean WriteFuzzySeperators_r( FILE *fp, fuzzyseperator_t *fs, int indent ) { + if ( !WriteIndent( fp, indent ) ) { + return qfalse; + } + if ( fprintf( fp, "switch(%d)\n", fs->index ) < 0 ) { + return qfalse; + } + if ( !WriteIndent( fp, indent ) ) { + return qfalse; + } + if ( fprintf( fp, "{\n" ) < 0 ) { + return qfalse; + } + indent++; + do + { + if ( !WriteIndent( fp, indent ) ) { + return qfalse; + } + if ( fs->next ) { + if ( fprintf( fp, "case %d:", fs->value ) < 0 ) { + return qfalse; + } + } //end if + else + { + if ( fprintf( fp, "default:" ) < 0 ) { + return qfalse; + } + } //end else + if ( fs->child ) { + if ( fprintf( fp, "\n" ) < 0 ) { + return qfalse; + } + if ( !WriteIndent( fp, indent ) ) { + return qfalse; + } + if ( fprintf( fp, "{\n" ) < 0 ) { + return qfalse; + } + if ( !WriteFuzzySeperators_r( fp, fs->child, indent + 1 ) ) { + return qfalse; + } + if ( !WriteIndent( fp, indent ) ) { + return qfalse; + } + if ( fs->next ) { + if ( fprintf( fp, "} //end case\n" ) < 0 ) { + return qfalse; + } + } //end if + else + { + if ( fprintf( fp, "} //end default\n" ) < 0 ) { + return qfalse; + } + } //end else + } //end if + else + { + if ( !WriteFuzzyWeight( fp, fs ) ) { + return qfalse; + } + } //end else + fs = fs->next; + } while ( fs ); + indent--; + if ( !WriteIndent( fp, indent ) ) { + return qfalse; + } + if ( fprintf( fp, "} //end switch\n" ) < 0 ) { + return qfalse; + } + return qtrue; +} //end of the function WriteItemFuzzyWeights_r +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +qboolean WriteWeightConfig( char *filename, weightconfig_t *config ) { + int i; + FILE *fp; + weight_t *ifw; + + fp = fopen( filename, "wb" ); + if ( !fp ) { + return qfalse; + } + + for ( i = 0; i < config->numweights; i++ ) + { + ifw = &config->weights[i]; + if ( fprintf( fp, "\nweight \"%s\"\n", ifw->name ) < 0 ) { + return qfalse; + } + if ( fprintf( fp, "{\n" ) < 0 ) { + return qfalse; + } + if ( ifw->firstseperator->index > 0 ) { + if ( !WriteFuzzySeperators_r( fp, ifw->firstseperator, 1 ) ) { + return qfalse; + } + } //end if + else + { + if ( !WriteIndent( fp, 1 ) ) { + return qfalse; + } + if ( !WriteFuzzyWeight( fp, ifw->firstseperator ) ) { + return qfalse; + } + } //end else + if ( fprintf( fp, "} //end weight\n" ) < 0 ) { + return qfalse; + } + } //end for + fclose( fp ); + return qtrue; +} //end of the function WriteWeightConfig +#endif +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int FindFuzzyWeight( weightconfig_t *wc, char *name ) { + int i; + + for ( i = 0; i < wc->numweights; i++ ) + { + if ( !strcmp( wc->weights[i].name, name ) ) { + return i; + } //end if + } //end if + return -1; +} //end of the function FindFuzzyWeight +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +float FuzzyWeight_r( int *inventory, fuzzyseperator_t *fs ) { + float scale, w1, w2; + + if ( inventory[fs->index] < fs->value ) { + if ( fs->child ) { + return FuzzyWeight_r( inventory, fs->child ); + } else { return fs->weight;} + } //end if + else if ( fs->next ) { + if ( inventory[fs->index] < fs->next->value ) { + //first weight + if ( fs->child ) { + w1 = FuzzyWeight_r( inventory, fs->child ); + } else { w1 = fs->weight;} + //second weight + if ( fs->next->child ) { + w2 = FuzzyWeight_r( inventory, fs->next->child ); + } else { w2 = fs->next->weight;} + //the scale factor + scale = ( inventory[fs->index] - fs->value ) / ( fs->next->value - fs->value ); + //scale between the two weights + return scale * w1 + ( 1 - scale ) * w2; + } //end if + return FuzzyWeight_r( inventory, fs->next ); + } //end else if + return fs->weight; +} //end of the function FuzzyWeight_r +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +float FuzzyWeightUndecided_r( int *inventory, fuzzyseperator_t *fs ) { + float scale, w1, w2; + + if ( inventory[fs->index] < fs->value ) { + if ( fs->child ) { + return FuzzyWeightUndecided_r( inventory, fs->child ); + } else { return fs->minweight + random() * ( fs->maxweight - fs->minweight );} + } //end if + else if ( fs->next ) { + if ( inventory[fs->index] < fs->next->value ) { + //first weight + if ( fs->child ) { + w1 = FuzzyWeightUndecided_r( inventory, fs->child ); + } else { w1 = fs->minweight + random() * ( fs->maxweight - fs->minweight );} + //second weight + if ( fs->next->child ) { + w2 = FuzzyWeight_r( inventory, fs->next->child ); + } else { w2 = fs->next->minweight + random() * ( fs->next->maxweight - fs->next->minweight );} + //the scale factor + scale = ( inventory[fs->index] - fs->value ) / ( fs->next->value - fs->value ); + //scale between the two weights + return scale * w1 + ( 1 - scale ) * w2; + } //end if + return FuzzyWeightUndecided_r( inventory, fs->next ); + } //end else if + return fs->weight; +} //end of the function FuzzyWeightUndecided_r +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +float FuzzyWeight( int *inventory, weightconfig_t *wc, int weightnum ) { +#ifdef EVALUATERECURSIVELY + return FuzzyWeight_r( inventory, wc->weights[weightnum].firstseperator ); +#else + fuzzyseperator_t *s; + + s = wc->weights[weightnum].firstseperator; + if ( !s ) { + return 0; + } + while ( 1 ) + { + if ( inventory[s->index] < s->value ) { + if ( s->child ) { + s = s->child; + } else { return s->weight;} + } //end if + else + { + if ( s->next ) { + s = s->next; + } else { return s->weight;} + } //end else + } //end if + return 0; +#endif +} //end of the function FuzzyWeight +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +float FuzzyWeightUndecided( int *inventory, weightconfig_t *wc, int weightnum ) { +#ifdef EVALUATERECURSIVELY + return FuzzyWeightUndecided_r( inventory, wc->weights[weightnum].firstseperator ); +#else + fuzzyseperator_t *s; + + s = wc->weights[weightnum].firstseperator; + if ( !s ) { + return 0; + } + while ( 1 ) + { + if ( inventory[s->index] < s->value ) { + if ( s->child ) { + s = s->child; + } else { return s->minweight + random() * ( s->maxweight - s->minweight );} + } //end if + else + { + if ( s->next ) { + s = s->next; + } else { return s->minweight + random() * ( s->maxweight - s->minweight );} + } //end else + } //end if + return 0; +#endif +} //end of the function FuzzyWeightUndecided +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void EvolveFuzzySeperator_r( fuzzyseperator_t *fs ) { + if ( fs->child ) { + EvolveFuzzySeperator_r( fs->child ); + } //end if + else if ( fs->type == WT_BALANCE ) { + //every once in a while an evolution leap occurs, mutation + if ( random() < 0.01 ) { + fs->weight += crandom() * ( fs->maxweight - fs->minweight ); + } else { fs->weight += crandom() * ( fs->maxweight - fs->minweight ) * 0.5;} + //modify bounds if necesary because of mutation + if ( fs->weight < fs->minweight ) { + fs->minweight = fs->weight; + } else if ( fs->weight > fs->maxweight ) { + fs->maxweight = fs->weight; + } + } //end else if + if ( fs->next ) { + EvolveFuzzySeperator_r( fs->next ); + } +} //end of the function EvolveFuzzySeperator_r +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void EvolveWeightConfig( weightconfig_t *config ) { + int i; + + for ( i = 0; i < config->numweights; i++ ) + { + EvolveFuzzySeperator_r( config->weights[i].firstseperator ); + } //end for +} //end of the function EvolveWeightConfig +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void ScaleFuzzySeperator_r( fuzzyseperator_t *fs, float scale ) { + if ( fs->child ) { + ScaleFuzzySeperator_r( fs->child, scale ); + } //end if + else if ( fs->type == WT_BALANCE ) { + // + fs->weight = ( fs->maxweight + fs->minweight ) * scale; + //get the weight between bounds + if ( fs->weight < fs->minweight ) { + fs->weight = fs->minweight; + } else if ( fs->weight > fs->maxweight ) { + fs->weight = fs->maxweight; + } + } //end else if + if ( fs->next ) { + ScaleFuzzySeperator_r( fs->next, scale ); + } +} //end of the function ScaleFuzzySeperator_r +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void ScaleWeight( weightconfig_t *config, char *name, float scale ) { + int i; + + if ( scale < 0 ) { + scale = 0; + } else if ( scale > 1 ) { + scale = 1; + } + for ( i = 0; i < config->numweights; i++ ) + { + if ( !strcmp( name, config->weights[i].name ) ) { + ScaleFuzzySeperator_r( config->weights[i].firstseperator, scale ); + break; + } //end if + } //end for +} //end of the function ScaleWeight +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void ScaleFuzzySeperatorBalanceRange_r( fuzzyseperator_t *fs, float scale ) { + if ( fs->child ) { + ScaleFuzzySeperatorBalanceRange_r( fs->child, scale ); + } //end if + else if ( fs->type == WT_BALANCE ) { + float mid = ( fs->minweight + fs->maxweight ) * 0.5; + //get the weight between bounds + fs->maxweight = mid + ( fs->maxweight - mid ) * scale; + fs->minweight = mid + ( fs->minweight - mid ) * scale; + if ( fs->maxweight < fs->minweight ) { + fs->maxweight = fs->minweight; + } //end if + } //end else if + if ( fs->next ) { + ScaleFuzzySeperatorBalanceRange_r( fs->next, scale ); + } +} //end of the function ScaleFuzzySeperatorBalanceRange_r +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void ScaleFuzzyBalanceRange( weightconfig_t *config, float scale ) { + int i; + + if ( scale < 0 ) { + scale = 0; + } else if ( scale > 100 ) { + scale = 100; + } + for ( i = 0; i < config->numweights; i++ ) + { + ScaleFuzzySeperatorBalanceRange_r( config->weights[i].firstseperator, scale ); + } //end for +} //end of the function ScaleFuzzyBalanceRange +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int InterbreedFuzzySeperator_r( fuzzyseperator_t *fs1, fuzzyseperator_t *fs2, + fuzzyseperator_t *fsout ) { + if ( fs1->child ) { + if ( !fs2->child || !fsout->child ) { + botimport.Print( PRT_ERROR, "cannot interbreed weight configs, unequal child\n" ); + return qfalse; + } //end if + if ( !InterbreedFuzzySeperator_r( fs2->child, fs2->child, fsout->child ) ) { + return qfalse; + } //end if + } //end if + else if ( fs1->type == WT_BALANCE ) { + if ( fs2->type != WT_BALANCE || fsout->type != WT_BALANCE ) { + botimport.Print( PRT_ERROR, "cannot interbreed weight configs, unequal balance\n" ); + return qfalse; + } //end if + fsout->weight = ( fs1->weight + fs2->weight ) / 2; + if ( fsout->weight > fsout->maxweight ) { + fsout->maxweight = fsout->weight; + } + if ( fsout->weight > fsout->minweight ) { + fsout->minweight = fsout->weight; + } + } //end else if + if ( fs1->next ) { + if ( !fs2->next || !fsout->next ) { + botimport.Print( PRT_ERROR, "cannot interbreed weight configs, unequal next\n" ); + return qfalse; + } //end if + if ( !InterbreedFuzzySeperator_r( fs1->next, fs2->next, fsout->next ) ) { + return qfalse; + } //end if + } //end if + return qtrue; +} //end of the function InterbreedFuzzySeperator_r +//=========================================================================== +// config1 and config2 are interbreeded and stored in configout +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void InterbreedWeightConfigs( weightconfig_t *config1, weightconfig_t *config2, + weightconfig_t *configout ) { + int i; + + if ( config1->numweights != config2->numweights || + config1->numweights != configout->numweights ) { + botimport.Print( PRT_ERROR, "cannot interbreed weight configs, unequal numweights\n" ); + return; + } //end if + for ( i = 0; i < config1->numweights; i++ ) + { + InterbreedFuzzySeperator_r( config1->weights[i].firstseperator, + config2->weights[i].firstseperator, + configout->weights[i].firstseperator ); + } //end for +} //end of the function InterbreedWeightConfigs +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void BotShutdownWeights( void ) { + int i; + + for ( i = 0; i < MAX_WEIGHT_FILES; i++ ) + { + if ( weightFileList[i] ) { + FreeWeightConfig2( weightFileList[i] ); + weightFileList[i] = NULL; + } //end if + } //end for +} //end of the function BotShutdownWeights diff --git a/Projects/Android/jni/rtcw/src/botlib/be_ai_weight.h b/Projects/Android/jni/rtcw/src/botlib/be_ai_weight.h new file mode 100644 index 0000000..b26e83b --- /dev/null +++ b/Projects/Android/jni/rtcw/src/botlib/be_ai_weight.h @@ -0,0 +1,89 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +/***************************************************************************** + * name: be_ai_weight.h + * + * desc: fuzzy weights + * + * + *****************************************************************************/ + +#define WT_BALANCE 1 +#define MAX_WEIGHTS 128 + +//fuzzy seperator +typedef struct fuzzyseperator_s +{ + int index; + int value; + int type; + float weight; + float minweight; + float maxweight; + struct fuzzyseperator_s *child; + struct fuzzyseperator_s *next; +} fuzzyseperator_t; + +//fuzzy weight +typedef struct weight_s +{ + char *name; + struct fuzzyseperator_s *firstseperator; +} weight_t; + +//weight configuration +typedef struct weightconfig_s +{ + int numweights; + weight_t weights[MAX_WEIGHTS]; + char filename[MAX_QPATH]; +} weightconfig_t; + +//reads a weight configuration +weightconfig_t *ReadWeightConfig( char *filename ); +//free a weight configuration +void FreeWeightConfig( weightconfig_t *config ); +//writes a weight configuration, returns true if successfull +qboolean WriteWeightConfig( char *filename, weightconfig_t *config ); +//find the fuzzy weight with the given name +int FindFuzzyWeight( weightconfig_t *wc, char *name ); +//returns the fuzzy weight for the given inventory and weight +float FuzzyWeight( int *inventory, weightconfig_t *wc, int weightnum ); +float FuzzyWeightUndecided( int *inventory, weightconfig_t *wc, int weightnum ); +//scales the weight with the given name +void ScaleWeight( weightconfig_t *config, char *name, float scale ); +//scale the balance range +void ScaleBalanceRange( weightconfig_t *config, float scale ); +//evolves the weight configuration +void EvolveWeightConfig( weightconfig_t *config ); +//interbreed the weight configurations and stores the interbreeded one in configout +void InterbreedWeightConfigs( weightconfig_t *config1, weightconfig_t *config2, weightconfig_t *configout ); +//frees cached weight configurations +void BotShutdownWeights( void ); diff --git a/Projects/Android/jni/rtcw/src/botlib/be_ea.c b/Projects/Android/jni/rtcw/src/botlib/be_ea.c new file mode 100644 index 0000000..9648e5b --- /dev/null +++ b/Projects/Android/jni/rtcw/src/botlib/be_ea.c @@ -0,0 +1,480 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +/***************************************************************************** + * name: be_ea.c + * + * desc: elementary actions + * + * + *****************************************************************************/ + +#include "../game/q_shared.h" +#include "l_memory.h" +#include "l_script.h" +#include "l_precomp.h" +#include "l_struct.h" +#include "../game/botlib.h" +#include "be_interface.h" + +#define MAX_USERMOVE 400 +#define MAX_COMMANDARGUMENTS 10 +#define ACTION_JUMPEDLASTFRAME 128 + +bot_input_t *botinputs; + +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void EA_Say( int client, char *str ) { + botimport.BotClientCommand( client, va( "say %s", str ) ); +} //end of the function EA_Say +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void EA_SayTeam( int client, char *str ) { + botimport.BotClientCommand( client, va( "say_team %s", str ) ); +} //end of the function EA_SayTeam +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void EA_UseItem( int client, char *it ) { + botimport.BotClientCommand( client, va( "use %s", it ) ); +} //end of the function EA_UseItem +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void EA_DropItem( int client, char *it ) { + botimport.BotClientCommand( client, va( "drop %s", it ) ); +} //end of the function EA_DropItem +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void EA_UseInv( int client, char *inv ) { + botimport.BotClientCommand( client, va( "invuse %s", inv ) ); +} //end of the function EA_UseInv +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void EA_DropInv( int client, char *inv ) { + botimport.BotClientCommand( client, va( "invdrop %s", inv ) ); +} //end of the function EA_DropInv +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void EA_Gesture( int client ) { + bot_input_t *bi; + + bi = &botinputs[client]; + + bi->actionflags |= ACTION_GESTURE; +} //end of the function EA_Gesture +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void EA_Command( int client, char *command ) { + botimport.BotClientCommand( client, command ); +} //end of the function EA_Command +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void EA_SelectWeapon( int client, int weapon ) { + bot_input_t *bi; + + bi = &botinputs[client]; + + bi->weapon = weapon; +} //end of the function EA_SelectWeapon +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void EA_Attack( int client ) { + bot_input_t *bi; + + bi = &botinputs[client]; + + bi->actionflags |= ACTION_ATTACK; +} //end of the function EA_Attack +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void EA_Reload( int client ) { + bot_input_t *bi; + + bi = &botinputs[client]; + + bi->actionflags |= ACTION_RELOAD; +} //end of the function EA_Attack +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void EA_Talk( int client ) { + bot_input_t *bi; + + bi = &botinputs[client]; + + bi->actionflags |= ACTION_TALK; +} //end of the function EA_Talk +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void EA_Use( int client ) { + bot_input_t *bi; + + bi = &botinputs[client]; + + bi->actionflags |= ACTION_USE; +} //end of the function EA_Use +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void EA_Respawn( int client ) { + bot_input_t *bi; + + bi = &botinputs[client]; + + bi->actionflags |= ACTION_RESPAWN; +} //end of the function EA_Respawn +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void EA_Jump( int client ) { + bot_input_t *bi; + + bi = &botinputs[client]; + + if ( bi->actionflags & ACTION_JUMPEDLASTFRAME ) { + bi->actionflags &= ~ACTION_JUMP; + } //end if + else + { + bi->actionflags |= ACTION_JUMP; + } //end if +} //end of the function EA_Jump +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void EA_DelayedJump( int client ) { + bot_input_t *bi; + + bi = &botinputs[client]; + + if ( bi->actionflags & ACTION_JUMPEDLASTFRAME ) { + bi->actionflags &= ~ACTION_DELAYEDJUMP; + } //end if + else + { + bi->actionflags |= ACTION_DELAYEDJUMP; + } //end if +} //end of the function EA_DelayedJump +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void EA_Crouch( int client ) { + bot_input_t *bi; + + bi = &botinputs[client]; + + bi->actionflags |= ACTION_CROUCH; +} //end of the function EA_Crouch +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void EA_Walk( int client ) { + bot_input_t *bi; + + bi = &botinputs[client]; + + bi->actionflags |= ACTION_WALK; +} //end of the function EA_Walk +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void EA_MoveUp( int client ) { + bot_input_t *bi; + + bi = &botinputs[client]; + + bi->actionflags |= ACTION_MOVEUP; +} //end of the function EA_MoveUp +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void EA_MoveDown( int client ) { + bot_input_t *bi; + + bi = &botinputs[client]; + + bi->actionflags |= ACTION_MOVEDOWN; +} //end of the function EA_MoveDown +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void EA_MoveForward( int client ) { + bot_input_t *bi; + + bi = &botinputs[client]; + + bi->actionflags |= ACTION_MOVEFORWARD; +} //end of the function EA_MoveForward +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void EA_MoveBack( int client ) { + bot_input_t *bi; + + bi = &botinputs[client]; + + bi->actionflags |= ACTION_MOVEBACK; +} //end of the function EA_MoveBack +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void EA_MoveLeft( int client ) { + bot_input_t *bi; + + bi = &botinputs[client]; + + bi->actionflags |= ACTION_MOVELEFT; +} //end of the function EA_MoveLeft +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void EA_MoveRight( int client ) { + bot_input_t *bi; + + bi = &botinputs[client]; + + bi->actionflags |= ACTION_MOVERIGHT; +} //end of the function EA_MoveRight +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void EA_Move( int client, vec3_t dir, float speed ) { + bot_input_t *bi; + + bi = &botinputs[client]; + + VectorCopy( dir, bi->dir ); + //cap speed + if ( speed > MAX_USERMOVE ) { + speed = MAX_USERMOVE; + } else if ( speed < -MAX_USERMOVE ) { + speed = -MAX_USERMOVE; + } + bi->speed = speed; +} //end of the function EA_Move +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void EA_View( int client, vec3_t viewangles ) { + bot_input_t *bi; + + bi = &botinputs[client]; + + VectorCopy( viewangles, bi->viewangles ); +} //end of the function EA_View +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void EA_EndRegular( int client, float thinktime ) { +/* + bot_input_t *bi; + int jumped = qfalse; + + bi = &botinputs[client]; + + bi->actionflags &= ~ACTION_JUMPEDLASTFRAME; + + bi->thinktime = thinktime; + botimport.BotInput(client, bi); + + bi->thinktime = 0; + VectorClear(bi->dir); + bi->speed = 0; + jumped = bi->actionflags & ACTION_JUMP; + bi->actionflags = 0; + if (jumped) bi->actionflags |= ACTION_JUMPEDLASTFRAME; +*/ +} //end of the function EA_EndRegular +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void EA_GetInput( int client, float thinktime, bot_input_t *input ) { + bot_input_t *bi; +// int jumped = qfalse; + + bi = &botinputs[client]; + +// bi->actionflags &= ~ACTION_JUMPEDLASTFRAME; + + bi->thinktime = thinktime; + memcpy( input, bi, sizeof( bot_input_t ) ); + + /* + bi->thinktime = 0; + VectorClear(bi->dir); + bi->speed = 0; + jumped = bi->actionflags & ACTION_JUMP; + bi->actionflags = 0; + if (jumped) bi->actionflags |= ACTION_JUMPEDLASTFRAME; + */ +} //end of the function EA_GetInput +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void EA_ResetInput( int client, bot_input_t *init ) { + bot_input_t *bi; + int jumped = qfalse; + + bi = &botinputs[client]; + bi->actionflags &= ~ACTION_JUMPEDLASTFRAME; + + bi->thinktime = 0; + VectorClear( bi->dir ); + bi->speed = 0; + jumped = bi->actionflags & ACTION_JUMP; + bi->actionflags = 0; + if ( jumped ) { + bi->actionflags |= ACTION_JUMPEDLASTFRAME; + } + + if ( init ) { + memcpy( bi, init, sizeof( bot_input_t ) ); + } +} //end of the function EA_ResetInput +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int EA_Setup( void ) { + //initialize the bot inputs + botinputs = (bot_input_t *) GetClearedHunkMemory( + botlibglobals.maxclients * sizeof( bot_input_t ) ); + return BLERR_NOERROR; +} //end of the function EA_Setup +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void EA_Shutdown( void ) { + FreeMemory( botinputs ); + botinputs = NULL; +} //end of the function EA_Shutdown diff --git a/Projects/Android/jni/rtcw/src/botlib/be_interface.c b/Projects/Android/jni/rtcw/src/botlib/be_interface.c new file mode 100644 index 0000000..1bee884 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/botlib/be_interface.c @@ -0,0 +1,936 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +/***************************************************************************** + * name: be_interface.c + * + * desc: bot library interface + * + * + *****************************************************************************/ + +#include "../game/q_shared.h" +#include "l_memory.h" +#include "l_log.h" +#include "l_libvar.h" +#include "l_script.h" +#include "l_precomp.h" +#include "l_struct.h" +#include "aasfile.h" +#include "../game/botlib.h" +#include "../game/be_aas.h" +#include "be_aas_funcs.h" +#include "be_aas_def.h" +#include "be_interface.h" + +#include "../game/be_ea.h" +#include "be_ai_weight.h" +#include "../game/be_ai_goal.h" +#include "../game/be_ai_move.h" +#include "../game/be_ai_weap.h" +#include "../game/be_ai_chat.h" +#include "../game/be_ai_char.h" +#include "../game/be_ai_gen.h" + +//library globals in a structure +botlib_globals_t botlibglobals; + +botlib_export_t be_botlib_export; +botlib_import_t botimport; +// +int bot_developer; +//qtrue if the library is setup +int botlibsetup = qfalse; + +//=========================================================================== +// +// several functions used by the exported functions +// +//=========================================================================== + +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +// Ridah, faster Win32 code +#ifdef _WIN32 +#undef MAX_PATH // this is an ugly hack, to temporarily ignore the current definition, since it's also defined in windows.h +#include +#undef MAX_PATH +#define MAX_PATH MAX_QPATH +#endif + +int Sys_MilliSeconds( void ) { +// Ridah, faster Win32 code +#ifdef _WIN32 + int sys_curtime; + static qboolean initialized = qfalse; + static int sys_timeBase; + + if ( !initialized ) { + sys_timeBase = timeGetTime(); + initialized = qtrue; + } + sys_curtime = timeGetTime() - sys_timeBase; + + return sys_curtime; +#else + return clock() * 1000 / CLOCKS_PER_SEC; +#endif +} //end of the function Sys_MilliSeconds +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +qboolean ValidClientNumber( int num, char *str ) { + if ( num < 0 || num > botlibglobals.maxclients ) { + //weird: the disabled stuff results in a crash + botimport.Print( PRT_ERROR, "%s: invalid client number %d, [0, %d]\n", + str, num, botlibglobals.maxclients ); + return qfalse; + } //end if + return qtrue; +} //end of the function BotValidateClientNumber +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +qboolean ValidEntityNumber( int num, char *str ) { + if ( num < 0 || num > botlibglobals.maxentities ) { + botimport.Print( PRT_ERROR, "%s: invalid entity number %d, [0, %d]\n", + str, num, botlibglobals.maxentities ); + return qfalse; + } //end if + return qtrue; +} //end of the function BotValidateClientNumber +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +qboolean BotLibSetup( char *str ) { +// return qtrue; + + if ( !botlibglobals.botlibsetup ) { + botimport.Print( PRT_ERROR, "%s: bot library used before being setup\n", str ); + return qfalse; + } //end if + return qtrue; +} //end of the function BotLibSetup +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int Export_BotLibSetup( void ) { + int errnum; + + bot_developer = LibVarGetValue( "bot_developer" ); + //initialize byte swapping (litte endian etc.) + Swap_Init(); + Log_Open( "botlib.log" ); + // + botimport.Print( PRT_MESSAGE, "------- BotLib Initialization -------\n" ); + // + botlibglobals.maxclients = (int) LibVarValue( "maxclients", "128" ); + botlibglobals.maxentities = (int) LibVarValue( "maxentities", "2048" ); + + errnum = AAS_Setup(); //be_aas_main.c + if ( errnum != BLERR_NOERROR ) { + return errnum; + } + errnum = EA_Setup(); //be_ea.c + if ( errnum != BLERR_NOERROR ) { + return errnum; + } +// errnum = BotSetupWeaponAI(); //be_ai_weap.c +// if (errnum != BLERR_NOERROR)return errnum; +// errnum = BotSetupGoalAI(); //be_ai_goal.c +// if (errnum != BLERR_NOERROR) return errnum; +// errnum = BotSetupChatAI(); //be_ai_chat.c +// if (errnum != BLERR_NOERROR) return errnum; + errnum = BotSetupMoveAI(); //be_ai_move.c + if ( errnum != BLERR_NOERROR ) { + return errnum; + } + + botlibsetup = qtrue; + botlibglobals.botlibsetup = qtrue; + + return BLERR_NOERROR; +} //end of the function Export_BotLibSetup +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int Export_BotLibShutdown( void ) { + static int recursive = 0; + + if ( !BotLibSetup( "BotLibShutdown" ) ) { + return BLERR_LIBRARYNOTSETUP; + } + // + if ( recursive ) { + return BLERR_NOERROR; + } + recursive = 1; + // shutdown all AI subsystems + BotShutdownChatAI(); //be_ai_chat.c + BotShutdownMoveAI(); //be_ai_move.c + BotShutdownGoalAI(); //be_ai_goal.c + BotShutdownWeaponAI(); //be_ai_weap.c + BotShutdownWeights(); //be_ai_weight.c + BotShutdownCharacters(); //be_ai_char.c + // shutdown AAS + AAS_Shutdown(); + // shutdown bot elemantary actions + EA_Shutdown(); + // free all libvars + LibVarDeAllocAll(); + // remove all global defines from the pre compiler + PC_RemoveAllGlobalDefines(); + // shut down library log file + Log_Shutdown(); + // + botlibsetup = qfalse; + botlibglobals.botlibsetup = qfalse; + recursive = 0; + // print any files still open + PC_CheckOpenSourceHandles(); + // +#ifdef _DEBUG + Log_AlwaysOpen( "memory.log" ); + PrintMemoryLabels(); + Log_Shutdown(); +#endif + return BLERR_NOERROR; +} //end of the function Export_BotLibShutdown +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int Export_BotLibVarSet( char *var_name, char *value ) { + LibVarSet( var_name, value ); + return BLERR_NOERROR; +} //end of the function Export_BotLibVarSet +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int Export_BotLibVarGet( char *var_name, char *value, int size ) { + char *varvalue; + + varvalue = LibVarGetString( var_name ); + strncpy( value, varvalue, size - 1 ); + value[size - 1] = '\0'; + return BLERR_NOERROR; +} //end of the function Export_BotLibVarGet +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int Export_BotLibStartFrame( float time ) { + if ( !BotLibSetup( "BotStartFrame" ) ) { + return BLERR_LIBRARYNOTSETUP; + } + return AAS_StartFrame( time ); +} //end of the function Export_BotLibStartFrame +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int Export_BotLibLoadMap( const char *mapname ) { +#ifdef DEBUG + int starttime = Sys_MilliSeconds(); +#endif + int errnum; + + if ( !BotLibSetup( "BotLoadMap" ) ) { + return BLERR_LIBRARYNOTSETUP; + } + // + botimport.Print( PRT_MESSAGE, "------------ Map Loading ------------\n" ); + //startup AAS for the current map, model and sound index + errnum = AAS_LoadMap( mapname ); + if ( errnum != BLERR_NOERROR ) { + return errnum; + } + //initialize the items in the level + BotInitLevelItems(); //be_ai_goal.h + BotSetBrushModelTypes(); //be_ai_move.h + // + botimport.Print( PRT_MESSAGE, "-------------------------------------\n" ); +#ifdef DEBUG + botimport.Print( PRT_MESSAGE, "map loaded in %d msec\n", Sys_MilliSeconds() - starttime ); +#endif + // + return BLERR_NOERROR; +} //end of the function Export_BotLibLoadMap +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int Export_BotLibUpdateEntity( int ent, bot_entitystate_t *state ) { + if ( !BotLibSetup( "BotUpdateEntity" ) ) { + return BLERR_LIBRARYNOTSETUP; + } + if ( !ValidEntityNumber( ent, "BotUpdateEntity" ) ) { + return BLERR_INVALIDENTITYNUMBER; + } + + return AAS_UpdateEntity( ent, state ); +} //end of the function Export_BotLibUpdateEntity +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_TestMovementPrediction( int entnum, vec3_t origin, vec3_t dir ); +void ElevatorBottomCenter( aas_reachability_t *reach, vec3_t bottomcenter ); +int BotGetReachabilityToGoal( vec3_t origin, int areanum, int entnum, + int lastgoalareanum, int lastareanum, + int *avoidreach, float *avoidreachtimes, int *avoidreachtries, + bot_goal_t *goal, int travelflags, int movetravelflags ); + +int AAS_PointLight( vec3_t origin, int *red, int *green, int *blue ); + +int AAS_TraceAreas( vec3_t start, vec3_t end, int *areas, vec3_t *points, int maxareas ); + +int AAS_Reachability_WeaponJump( int area1num, int area2num ); + +int BotFuzzyPointReachabilityArea( vec3_t origin ); + +float BotGapDistance( vec3_t origin, vec3_t hordir, int entnum ); + +int AAS_NearestHideArea( int srcnum, vec3_t origin, int areanum, int enemynum, vec3_t enemyorigin, int enemyareanum, int travelflags ); + +int AAS_FindAttackSpotWithinRange( int srcnum, int rangenum, int enemynum, float rangedist, int travelflags, float *outpos ); + +qboolean AAS_GetRouteFirstVisPos( vec3_t srcpos, vec3_t destpos, int travelflags, vec3_t retpos ); + +void AAS_SetAASBlockingEntity( vec3_t absmin, vec3_t absmax, qboolean blocking ); + +int BotExportTest( int parm0, char *parm1, vec3_t parm2, vec3_t parm3 ) { + +// return AAS_PointLight(parm2, NULL, NULL, NULL); + +#ifdef DEBUG + static int area = -1; + static int line[2]; + int newarea, i, highlightarea, bot_testhidepos, hideposarea, bot_testroutevispos; +// int reachnum; + vec3_t eye, forward, right, end, origin; +// vec3_t bottomcenter; +// aas_trace_t trace; +// aas_face_t *face; +// aas_entity_t *ent; +// bsp_trace_t bsptrace; +// aas_reachability_t reach; +// bot_goal_t goal; + +// clock_t start_time, end_time; + vec3_t mins = {-16, -16, -24}; + vec3_t maxs = {16, 16, 32}; +// int areas[10], numareas; + + + //return 0; + + if ( !( *aasworld ).loaded ) { + return 0; + } + AAS_SetCurrentWorld( 0 ); + + for ( i = 0; i < 2; i++ ) if ( !line[i] ) { + line[i] = botimport.DebugLineCreate(); + } + +// AAS_ClearShownDebugLines(); + bot_testhidepos = LibVarGetValue( "bot_testhidepos" ); + if ( bot_testhidepos ) { + VectorCopy( parm2, origin ); + newarea = BotFuzzyPointReachabilityArea( origin ); + if ( parm0 & 1 ) { + botlibglobals.goalareanum = newarea; + VectorCopy( origin, botlibglobals.goalorigin ); + botimport.Print( PRT_MESSAGE, "new enemy position %2.1f %2.1f %2.1f area %d\n", + origin[0], origin[1], origin[2], newarea ); + } //end if + AAS_ClearShownPolygons(); + AAS_ClearShownDebugLines(); + hideposarea = AAS_NearestHideArea( -1, origin, AAS_PointAreaNum( origin ), 0, + botlibglobals.goalorigin, botlibglobals.goalareanum, TFL_DEFAULT ); + + if ( bot_testhidepos > 1 ) { + if ( hideposarea ) { + botimport.Print( PRT_MESSAGE, "hidepos (%i) %2.1f %2.1f %2.1f\n", + hideposarea, + ( *aasworld ).areawaypoints[hideposarea][0], + ( *aasworld ).areawaypoints[hideposarea][1], + ( *aasworld ).areawaypoints[hideposarea][2] ); + } else { + botimport.Print( PRT_MESSAGE, "no hidepos found\n" ); + } + } + + //area we are currently in + AAS_ShowAreaPolygons( newarea, 1, qtrue ); + //enemy position + AAS_ShowAreaPolygons( botlibglobals.goalareanum, 2, qtrue ); + //area we should go hide + AAS_ShowAreaPolygons( hideposarea, 4, qtrue ); + return 0; + } + + bot_testroutevispos = LibVarGetValue( "bot_testroutevispos" ); + if ( bot_testroutevispos ) { + VectorCopy( parm2, origin ); + newarea = BotFuzzyPointReachabilityArea( origin ); + if ( parm0 & 1 ) { + botlibglobals.goalareanum = newarea; + VectorCopy( origin, botlibglobals.goalorigin ); + botimport.Print( PRT_MESSAGE, "new enemy position %2.1f %2.1f %2.1f area %d\n", + origin[0], origin[1], origin[2], newarea ); + } //end if + AAS_ClearShownPolygons(); + AAS_ClearShownDebugLines(); + AAS_GetRouteFirstVisPos( botlibglobals.goalorigin, origin, TFL_DEFAULT, eye ); + //area we are currently in + AAS_ShowAreaPolygons( newarea, 1, qtrue ); + //enemy position + AAS_ShowAreaPolygons( botlibglobals.goalareanum, 2, qtrue ); + //area that is visible in path from enemy pos + hideposarea = BotFuzzyPointReachabilityArea( eye ); + AAS_ShowAreaPolygons( hideposarea, 4, qtrue ); + return 0; + } + + //if (AAS_AgainstLadder(parm2)) botimport.Print(PRT_MESSAGE, "against ladder\n"); + //BotOnGround(parm2, PRESENCE_NORMAL, 1, &newarea, &newarea); + //botimport.Print(PRT_MESSAGE, "%f %f %f\n", parm2[0], parm2[1], parm2[2]); + //* + highlightarea = LibVarGetValue( "bot_highlightarea" ); + if ( highlightarea > 0 ) { + newarea = highlightarea; + } //end if + else + { + VectorCopy( parm2, origin ); + origin[2] += 0.5; + //newarea = AAS_PointAreaNum(origin); + newarea = BotFuzzyPointReachabilityArea( origin ); + } //end else + + botimport.Print( PRT_MESSAGE, "\rtravel time to goal (%d) = %d ", botlibglobals.goalareanum, + AAS_AreaTravelTimeToGoalArea( newarea, origin, botlibglobals.goalareanum, TFL_DEFAULT ) ); + //newarea = BotReachabilityArea(origin, qtrue); + if ( newarea != area ) { + botimport.Print( PRT_MESSAGE, "origin = %f, %f, %f\n", origin[0], origin[1], origin[2] ); + area = newarea; + botimport.Print( PRT_MESSAGE, "new area %d, cluster %d, presence type %d\n", + area, AAS_AreaCluster( area ), AAS_PointPresenceType( origin ) ); + if ( ( *aasworld ).areasettings[area].areaflags & AREA_LIQUID ) { + botimport.Print( PRT_MESSAGE, "liquid area\n" ); + } //end if + botimport.Print( PRT_MESSAGE, "area contents: " ); + if ( ( *aasworld ).areasettings[area].contents & AREACONTENTS_WATER ) { + botimport.Print( PRT_MESSAGE, "water " ); + } //end if + if ( ( *aasworld ).areasettings[area].contents & AREACONTENTS_LAVA ) { + botimport.Print( PRT_MESSAGE, "lava " ); + } //end if + if ( ( *aasworld ).areasettings[area].contents & AREACONTENTS_SLIME ) { +// botimport.Print(PRT_MESSAGE, "slime "); + botimport.Print( PRT_MESSAGE, "slag " ); + } //end if + if ( ( *aasworld ).areasettings[area].contents & AREACONTENTS_JUMPPAD ) { + botimport.Print( PRT_MESSAGE, "jump pad " ); + } //end if + if ( ( *aasworld ).areasettings[area].contents & AREACONTENTS_CLUSTERPORTAL ) { + botimport.Print( PRT_MESSAGE, "cluster portal " ); + } //end if + if ( ( *aasworld ).areasettings[area].contents & AREACONTENTS_DONOTENTER ) { + botimport.Print( PRT_MESSAGE, "do not enter " ); + } //end if + if ( ( *aasworld ).areasettings[area].contents & AREACONTENTS_DONOTENTER_LARGE ) { + botimport.Print( PRT_MESSAGE, "do not enter large " ); + } //end if + if ( !( *aasworld ).areasettings[area].contents ) { + botimport.Print( PRT_MESSAGE, "empty " ); + } //end if + if ( ( *aasworld ).areasettings[area].areaflags & AREA_DISABLED ) { + botimport.Print( PRT_MESSAGE, "DISABLED" ); + } //end if + botimport.Print( PRT_MESSAGE, "\n" ); + botimport.Print( PRT_MESSAGE, "travel time to goal (%d) = %d\n", botlibglobals.goalareanum, + AAS_AreaTravelTimeToGoalArea( newarea, origin, botlibglobals.goalareanum, TFL_DEFAULT | TFL_ROCKETJUMP ) ); + /* + VectorCopy(origin, end); + end[2] += 5; + numareas = AAS_TraceAreas(origin, end, areas, NULL, 10); + AAS_TraceClientBBox(origin, end, PRESENCE_CROUCH, -1); + botimport.Print(PRT_MESSAGE, "num areas = %d, area = %d\n", numareas, areas[0]); + */ + /* + botlibglobals.goalareanum = newarea; + VectorCopy(parm2, botlibglobals.goalorigin); + botimport.Print(PRT_MESSAGE, "new goal %2.1f %2.1f %2.1f area %d\n", + origin[0], origin[1], origin[2], newarea); + */ + } //end if + //* + if ( parm0 & 1 ) { + botlibglobals.goalareanum = newarea; + VectorCopy( parm2, botlibglobals.goalorigin ); + botimport.Print( PRT_MESSAGE, "new goal %2.1f %2.1f %2.1f area %d\n", + origin[0], origin[1], origin[2], newarea ); + } //end if*/ +// if (parm0 & BUTTON_USE) +// { +// botlibglobals.runai = !botlibglobals.runai; +// if (botlibglobals.runai) botimport.Print(PRT_MESSAGE, "started AI\n"); +// else botimport.Print(PRT_MESSAGE, "stopped AI\n"); + //* / + /* + goal.areanum = botlibglobals.goalareanum; + reachnum = BotGetReachabilityToGoal(parm2, newarea, 1, + ms.avoidreach, ms.avoidreachtimes, + &goal, TFL_DEFAULT); + if (!reachnum) + { + botimport.Print(PRT_MESSAGE, "goal not reachable\n"); + } //end if + else + { + AAS_ReachabilityFromNum(reachnum, &reach); + AAS_ClearShownDebugLines(); + AAS_ShowArea(area, qtrue); + AAS_ShowArea(reach.areanum, qtrue); + AAS_DrawCross(reach.start, 6, LINECOLOR_BLUE); + AAS_DrawCross(reach.end, 6, LINECOLOR_RED); + // + if (reach.traveltype == TRAVEL_ELEVATOR) + { + ElevatorBottomCenter(&reach, bottomcenter); + AAS_DrawCross(bottomcenter, 10, LINECOLOR_GREEN); + } //end if + } //end else*/ +// botimport.Print(PRT_MESSAGE, "travel time to goal = %d\n", +// AAS_AreaTravelTimeToGoalArea(area, origin, botlibglobals.goalareanum, TFL_DEFAULT)); +// botimport.Print(PRT_MESSAGE, "test rj from 703 to 716\n"); +// AAS_Reachability_WeaponJump(703, 716); +// } //end if*/ + +/* face = AAS_AreaGroundFace(newarea, parm2); + if (face) + { + AAS_ShowFace(face - (*aasworld).faces); + } //end if*/ + /* + AAS_ClearShownDebugLines(); + AAS_ShowArea(newarea, parm0 & BUTTON_USE); + AAS_ShowReachableAreas(area); + */ + AAS_ClearShownPolygons(); + AAS_ClearShownDebugLines(); + AAS_ShowAreaPolygons( newarea, 1, parm0 & 4 ); + if ( parm0 & 2 ) { + AAS_ShowReachableAreas( area ); + } else + { + static int lastgoalareanum, lastareanum; + static int avoidreach[MAX_AVOIDREACH]; + static float avoidreachtimes[MAX_AVOIDREACH]; + static int avoidreachtries[MAX_AVOIDREACH]; + int reachnum; + bot_goal_t goal; + aas_reachability_t reach; + + goal.areanum = botlibglobals.goalareanum; + VectorCopy( botlibglobals.goalorigin, goal.origin ); + reachnum = BotGetReachabilityToGoal( origin, newarea, -1, + lastgoalareanum, lastareanum, + avoidreach, avoidreachtimes, avoidreachtries, + &goal, TFL_DEFAULT | TFL_FUNCBOB, TFL_DEFAULT | TFL_FUNCBOB ); + AAS_ReachabilityFromNum( reachnum, &reach ); + AAS_ShowReachability( &reach ); + } //end else + VectorClear( forward ); + //BotGapDistance(origin, forward, 0); + /* + if (parm0 & BUTTON_USE) + { + botimport.Print(PRT_MESSAGE, "test rj from 703 to 716\n"); + AAS_Reachability_WeaponJump(703, 716); + } //end if*/ + + AngleVectors( parm3, forward, right, NULL ); + //get the eye 16 units to the right of the origin + VectorMA( parm2, 8, right, eye ); + //get the eye 24 units up + eye[2] += 24; + //get the end point for the line to be traced + VectorMA( eye, 800, forward, end ); + +// AAS_TestMovementPrediction(1, parm2, forward); +/* //trace the line to find the hit point + trace = AAS_TraceClientBBox(eye, end, PRESENCE_NORMAL, 1); + if (!line[0]) line[0] = botimport.DebugLineCreate(); + botimport.DebugLineShow(line[0], eye, trace.endpos, LINECOLOR_BLUE); + // + AAS_ClearShownDebugLines(); + if (trace.ent) + { + ent = &(*aasworld).entities[trace.ent]; + AAS_ShowBoundingBox(ent->origin, ent->mins, ent->maxs); + } //end if*/ + +/* + start_time = clock(); + for (i = 0; i < 2000; i++) + { + AAS_Trace2(eye, mins, maxs, end, 1, MASK_PLAYERSOLID); +// AAS_TraceClientBBox(eye, end, PRESENCE_NORMAL, 1); + } //end for + end_time = clock(); + botimport.Print(PRT_MESSAGE, "me %lu clocks, %lu CLOCKS_PER_SEC\n", end_time - start_time, CLOCKS_PER_SEC); + start_time = clock(); + for (i = 0; i < 2000; i++) + { + AAS_Trace(eye, mins, maxs, end, 1, MASK_PLAYERSOLID); + } //end for + end_time = clock(); + botimport.Print(PRT_MESSAGE, "id %lu clocks, %lu CLOCKS_PER_SEC\n", end_time - start_time, CLOCKS_PER_SEC); +*/ + + /* + AAS_ClearShownDebugLines(); + //bsptrace = AAS_Trace(eye, NULL, NULL, end, 1, MASK_PLAYERSOLID); + bsptrace = AAS_Trace(eye, mins, maxs, end, 1, MASK_PLAYERSOLID); + if (!line[0]) line[0] = botimport.DebugLineCreate(); + botimport.DebugLineShow(line[0], eye, bsptrace.endpos, LINECOLOR_YELLOW); + if (bsptrace.fraction < 1.0) + { + face = AAS_TraceEndFace(&trace); + if (face) + { + AAS_ShowFace(face - (*aasworld).faces); + } //end if + AAS_DrawPlaneCross(bsptrace.endpos, + bsptrace.plane.normal, + bsptrace.plane.dist + bsptrace.exp_dist, + bsptrace.plane.type, LINECOLOR_GREEN); + if (trace.ent) + { + ent = &(*aasworld).entities[trace.ent]; + AAS_ShowBoundingBox(ent->origin, ent->mins, ent->maxs); + } //end if + } //end if*/ + /*/ + //bsptrace = AAS_Trace2(eye, NULL, NULL, end, 1, MASK_PLAYERSOLID); + bsptrace = AAS_Trace2(eye, mins, maxs, end, 1, MASK_PLAYERSOLID); + botimport.DebugLineShow(line[1], eye, bsptrace.endpos, LINECOLOR_BLUE); + if (bsptrace.fraction < 1.0) + { + AAS_DrawPlaneCross(bsptrace.endpos, + bsptrace.plane.normal, + bsptrace.plane.dist,// + bsptrace.exp_dist, + bsptrace.plane.type, LINECOLOR_RED); + if (bsptrace.ent) + { + ent = &(*aasworld).entities[bsptrace.ent]; + AAS_ShowBoundingBox(ent->origin, ent->mins, ent->maxs); + } //end if + } //end if + */ +#endif + return 0; +} //end of the function BotExportTest + + +/* +============ +Init_AAS_Export +============ +*/ +static void Init_AAS_Export( aas_export_t *aas ) { + //-------------------------------------------- + // be_aas_entity.c + //-------------------------------------------- + aas->AAS_EntityInfo = AAS_EntityInfo; + //-------------------------------------------- + // be_aas_main.c + //-------------------------------------------- + aas->AAS_Initialized = AAS_Initialized; + aas->AAS_PresenceTypeBoundingBox = AAS_PresenceTypeBoundingBox; + aas->AAS_Time = AAS_Time; + //-------------------------------------------- + // be_aas_sample.c + //-------------------------------------------- + aas->AAS_PointAreaNum = AAS_PointAreaNum; + aas->AAS_TraceAreas = AAS_TraceAreas; + //-------------------------------------------- + // be_aas_bspq3.c + //-------------------------------------------- + aas->AAS_PointContents = AAS_PointContents; + aas->AAS_NextBSPEntity = AAS_NextBSPEntity; + aas->AAS_ValueForBSPEpairKey = AAS_ValueForBSPEpairKey; + aas->AAS_VectorForBSPEpairKey = AAS_VectorForBSPEpairKey; + aas->AAS_FloatForBSPEpairKey = AAS_FloatForBSPEpairKey; + aas->AAS_IntForBSPEpairKey = AAS_IntForBSPEpairKey; + //-------------------------------------------- + // be_aas_reach.c + //-------------------------------------------- + aas->AAS_AreaReachability = AAS_AreaReachability; + //-------------------------------------------- + // be_aas_route.c + //-------------------------------------------- + aas->AAS_AreaTravelTimeToGoalArea = AAS_AreaTravelTimeToGoalArea; + //-------------------------------------------- + // be_aas_move.c + //-------------------------------------------- + aas->AAS_Swimming = AAS_Swimming; + aas->AAS_PredictClientMovement = AAS_PredictClientMovement; + + // Ridah, route-tables + //-------------------------------------------- + // be_aas_routetable.c + //-------------------------------------------- + aas->AAS_RT_ShowRoute = AAS_RT_ShowRoute; + aas->AAS_RT_GetHidePos = AAS_RT_GetHidePos; + aas->AAS_FindAttackSpotWithinRange = AAS_FindAttackSpotWithinRange; + aas->AAS_GetRouteFirstVisPos = AAS_GetRouteFirstVisPos; + aas->AAS_SetAASBlockingEntity = AAS_SetAASBlockingEntity; + // done. + + // Ridah, multiple AAS files + aas->AAS_SetCurrentWorld = AAS_SetCurrentWorld; + // done. + +} + + +/* +============ +Init_EA_Export +============ +*/ +static void Init_EA_Export( ea_export_t *ea ) { + //ClientCommand elementary actions + ea->EA_Say = EA_Say; + ea->EA_SayTeam = EA_SayTeam; + ea->EA_UseItem = EA_UseItem; + ea->EA_DropItem = EA_DropItem; + ea->EA_UseInv = EA_UseInv; + ea->EA_DropInv = EA_DropInv; + ea->EA_Gesture = EA_Gesture; + ea->EA_Command = EA_Command; + ea->EA_SelectWeapon = EA_SelectWeapon; + ea->EA_Talk = EA_Talk; + ea->EA_Attack = EA_Attack; + ea->EA_Reload = EA_Reload; + ea->EA_Use = EA_Use; + ea->EA_Respawn = EA_Respawn; + ea->EA_Jump = EA_Jump; + ea->EA_DelayedJump = EA_DelayedJump; + ea->EA_Crouch = EA_Crouch; + ea->EA_MoveUp = EA_MoveUp; + ea->EA_MoveDown = EA_MoveDown; + ea->EA_MoveForward = EA_MoveForward; + ea->EA_MoveBack = EA_MoveBack; + ea->EA_MoveLeft = EA_MoveLeft; + ea->EA_MoveRight = EA_MoveRight; + ea->EA_Move = EA_Move; + ea->EA_View = EA_View; + ea->EA_GetInput = EA_GetInput; + ea->EA_EndRegular = EA_EndRegular; + ea->EA_ResetInput = EA_ResetInput; +} + + +/* +============ +Init_AI_Export +============ +*/ +static void Init_AI_Export( ai_export_t *ai ) { + //----------------------------------- + // be_ai_char.h + //----------------------------------- + ai->BotLoadCharacter = BotLoadCharacter; + ai->BotFreeCharacter = BotFreeCharacter; + ai->Characteristic_Float = Characteristic_Float; + ai->Characteristic_BFloat = Characteristic_BFloat; + ai->Characteristic_Integer = Characteristic_Integer; + ai->Characteristic_BInteger = Characteristic_BInteger; + ai->Characteristic_String = Characteristic_String; + //----------------------------------- + // be_ai_chat.h + //----------------------------------- + ai->BotAllocChatState = BotAllocChatState; + ai->BotFreeChatState = BotFreeChatState; + ai->BotQueueConsoleMessage = BotQueueConsoleMessage; + ai->BotRemoveConsoleMessage = BotRemoveConsoleMessage; + ai->BotNextConsoleMessage = BotNextConsoleMessage; + ai->BotNumConsoleMessages = BotNumConsoleMessages; + ai->BotInitialChat = BotInitialChat; + ai->BotNumInitialChats = BotNumInitialChats; + ai->BotReplyChat = BotReplyChat; + ai->BotChatLength = BotChatLength; + ai->BotEnterChat = BotEnterChat; + ai->BotGetChatMessage = BotGetChatMessage; + ai->StringContains = StringContains; + ai->BotFindMatch = BotFindMatch; + ai->BotMatchVariable = BotMatchVariable; + ai->UnifyWhiteSpaces = UnifyWhiteSpaces; + ai->BotReplaceSynonyms = BotReplaceSynonyms; + ai->BotLoadChatFile = BotLoadChatFile; + ai->BotSetChatGender = BotSetChatGender; + ai->BotSetChatName = BotSetChatName; + //----------------------------------- + // be_ai_goal.h + //----------------------------------- + ai->BotResetGoalState = BotResetGoalState; + ai->BotResetAvoidGoals = BotResetAvoidGoals; + ai->BotRemoveFromAvoidGoals = BotRemoveFromAvoidGoals; + ai->BotPushGoal = BotPushGoal; + ai->BotPopGoal = BotPopGoal; + ai->BotEmptyGoalStack = BotEmptyGoalStack; + ai->BotDumpAvoidGoals = BotDumpAvoidGoals; + ai->BotDumpGoalStack = BotDumpGoalStack; + ai->BotGoalName = BotGoalName; + ai->BotGetTopGoal = BotGetTopGoal; + ai->BotGetSecondGoal = BotGetSecondGoal; + ai->BotChooseLTGItem = BotChooseLTGItem; + ai->BotChooseNBGItem = BotChooseNBGItem; + ai->BotTouchingGoal = BotTouchingGoal; + ai->BotItemGoalInVisButNotVisible = BotItemGoalInVisButNotVisible; + ai->BotGetLevelItemGoal = BotGetLevelItemGoal; + ai->BotGetNextCampSpotGoal = BotGetNextCampSpotGoal; + ai->BotGetMapLocationGoal = BotGetMapLocationGoal; + ai->BotAvoidGoalTime = BotAvoidGoalTime; + ai->BotInitLevelItems = BotInitLevelItems; + ai->BotUpdateEntityItems = BotUpdateEntityItems; + ai->BotLoadItemWeights = BotLoadItemWeights; + ai->BotFreeItemWeights = BotFreeItemWeights; + ai->BotInterbreedGoalFuzzyLogic = BotInterbreedGoalFuzzyLogic; + ai->BotSaveGoalFuzzyLogic = BotSaveGoalFuzzyLogic; + ai->BotMutateGoalFuzzyLogic = BotMutateGoalFuzzyLogic; + ai->BotAllocGoalState = BotAllocGoalState; + ai->BotFreeGoalState = BotFreeGoalState; + //----------------------------------- + // be_ai_move.h + //----------------------------------- + ai->BotResetMoveState = BotResetMoveState; + ai->BotMoveToGoal = BotMoveToGoal; + ai->BotMoveInDirection = BotMoveInDirection; + ai->BotResetAvoidReach = BotResetAvoidReach; + ai->BotResetLastAvoidReach = BotResetLastAvoidReach; + ai->BotReachabilityArea = BotReachabilityArea; + ai->BotMovementViewTarget = BotMovementViewTarget; + ai->BotPredictVisiblePosition = BotPredictVisiblePosition; + ai->BotAllocMoveState = BotAllocMoveState; + ai->BotFreeMoveState = BotFreeMoveState; + ai->BotInitMoveState = BotInitMoveState; + // Ridah + ai->BotInitAvoidReach = BotInitAvoidReach; + // done. + //----------------------------------- + // be_ai_weap.h + //----------------------------------- + ai->BotChooseBestFightWeapon = BotChooseBestFightWeapon; + ai->BotGetWeaponInfo = BotGetWeaponInfo; + ai->BotLoadWeaponWeights = BotLoadWeaponWeights; + ai->BotAllocWeaponState = BotAllocWeaponState; + ai->BotFreeWeaponState = BotFreeWeaponState; + ai->BotResetWeaponState = BotResetWeaponState; + //----------------------------------- + // be_ai_gen.h + //----------------------------------- + ai->GeneticParentsAndChildSelection = GeneticParentsAndChildSelection; +} + + +/* +============ +GetBotLibAPI +============ +*/ +botlib_export_t *GetBotLibAPI( int apiVersion, botlib_import_t *import ) { + botimport = *import; + + memset( &be_botlib_export, 0, sizeof( be_botlib_export ) ); + + if ( apiVersion != BOTLIB_API_VERSION ) { + botimport.Print( PRT_ERROR, "Mismatched BOTLIB_API_VERSION: expected %i, got %i\n", BOTLIB_API_VERSION, apiVersion ); + return NULL; + } + + Init_AAS_Export( &be_botlib_export.aas ); + Init_EA_Export( &be_botlib_export.ea ); + Init_AI_Export( &be_botlib_export.ai ); + + be_botlib_export.BotLibSetup = Export_BotLibSetup; + be_botlib_export.BotLibShutdown = Export_BotLibShutdown; + be_botlib_export.BotLibVarSet = Export_BotLibVarSet; + be_botlib_export.BotLibVarGet = Export_BotLibVarGet; + be_botlib_export.PC_AddGlobalDefine = PC_AddGlobalDefine; + be_botlib_export.PC_LoadSourceHandle = PC_LoadSourceHandle; + be_botlib_export.PC_FreeSourceHandle = PC_FreeSourceHandle; + be_botlib_export.PC_ReadTokenHandle = PC_ReadTokenHandle; + be_botlib_export.PC_SourceFileAndLine = PC_SourceFileAndLine; + + be_botlib_export.BotLibStartFrame = Export_BotLibStartFrame; + be_botlib_export.BotLibLoadMap = Export_BotLibLoadMap; + be_botlib_export.BotLibUpdateEntity = Export_BotLibUpdateEntity; + be_botlib_export.Test = BotExportTest; + + return &be_botlib_export; +} diff --git a/Projects/Android/jni/rtcw/src/botlib/be_interface.h b/Projects/Android/jni/rtcw/src/botlib/be_interface.h new file mode 100644 index 0000000..e2355ce --- /dev/null +++ b/Projects/Android/jni/rtcw/src/botlib/be_interface.h @@ -0,0 +1,93 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +/***************************************************************************** + * name: be_interface.h + * + * desc: botlib interface + * + * + *****************************************************************************/ + +/* +"Do not go where the path leads, rather go where there's no track and leave a trail." + +"AAS (Area Awareness System)" + +"Part of the Gladiator is BoGuS (Bot Guidance System)" + +"ANSI (Advanced Navigational System Interface)" + +"to make things work the only thing you really have to do is think things work." + +"a madman is just someone living in another reality which isn't shared among many people" +*/ + +//#define DEBUG //debug code +#define RANDOMIZE //randomize bot behaviour +#if defined( WIN32 ) || defined( _WIN32 ) +#define AASZIP //allow reading directly from aasX.zip files +#endif +#define QUAKE2 //bot for Quake2 +//#define HALFLIFE //bot for Half-Life + +//========================================================== +// +// global variable structures +// +//========================================================== + +//FIXME: get rid of this global structure +typedef struct botlib_globals_s +{ + int botlibsetup; //true when the bot library has been setup + int maxentities; //maximum number of entities + int maxclients; //maximum number of clients + float time; //the global time +#ifdef DEBUG + qboolean debug; //true if debug is on + int goalareanum; + vec3_t goalorigin; + int runai; +#endif +} botlib_globals_t; + +//========================================================== +// +// global variables +// +//========================================================== + +extern botlib_globals_t botlibglobals; +extern botlib_import_t botimport; +extern int bot_developer; //true if developer is on + +// +int Sys_MilliSeconds( void ); + diff --git a/Projects/Android/jni/rtcw/src/botlib/botlib.h b/Projects/Android/jni/rtcw/src/botlib/botlib.h new file mode 100644 index 0000000..ea802a5 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/botlib/botlib.h @@ -0,0 +1,512 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +//=========================================================================== +// +// Name: botlib.h +// Function: bot AI Library +// Programmer: Mr Elusive (MrElusive@idsoftware.com) +// Last update: 1999-08-18 +// Tab Size: 3 +//=========================================================================== + +#define BOTLIB_API_VERSION 2 + +struct aas_clientmove_s; +struct aas_entityinfo_s; +struct bot_consolemessage_s; +struct bot_match_s; +struct bot_goal_s; +struct bot_moveresult_s; +struct bot_initmove_s; +struct weaponinfo_s; + + +//debug line colors +#define LINECOLOR_NONE -1 +#define LINECOLOR_RED 1 //0xf2f2f0f0L +#define LINECOLOR_GREEN 2 //0xd0d1d2d3L +#define LINECOLOR_BLUE 3 //0xf3f3f1f1L +#define LINECOLOR_YELLOW 4 //0xdcdddedfL +#define LINECOLOR_ORANGE 5 //0xe0e1e2e3L + +//Print types +#define PRT_MESSAGE 1 +#define PRT_WARNING 2 +#define PRT_ERROR 3 +#define PRT_FATAL 4 +#define PRT_EXIT 5 + +//console message types +#define CMS_NORMAL 0 +#define CMS_CHAT 1 + +//botlib error codes +#define BLERR_NOERROR 0 //no error +#define BLERR_LIBRARYNOTSETUP 1 //library not setup +#define BLERR_LIBRARYALREADYSETUP 2 //BotSetupLibrary: library already setup +#define BLERR_INVALIDCLIENTNUMBER 3 //invalid client number +#define BLERR_INVALIDENTITYNUMBER 4 //invalid entity number +#define BLERR_NOAASFILE 5 //BotLoadMap: no AAS file available +#define BLERR_CANNOTOPENAASFILE 6 //BotLoadMap: cannot open AAS file +#define BLERR_CANNOTSEEKTOAASFILE 7 //BotLoadMap: cannot seek to AAS file +#define BLERR_CANNOTREADAASHEADER 8 //BotLoadMap: cannot read AAS header +#define BLERR_WRONGAASFILEID 9 //BotLoadMap: incorrect AAS file id +#define BLERR_WRONGAASFILEVERSION 10 //BotLoadMap: incorrect AAS file version +#define BLERR_CANNOTREADAASLUMP 11 //BotLoadMap: cannot read AAS file lump +#define BLERR_NOBSPFILE 12 //BotLoadMap: no BSP file available +#define BLERR_CANNOTOPENBSPFILE 13 //BotLoadMap: cannot open BSP file +#define BLERR_CANNOTSEEKTOBSPFILE 14 //BotLoadMap: cannot seek to BSP file +#define BLERR_CANNOTREADBSPHEADER 15 //BotLoadMap: cannot read BSP header +#define BLERR_WRONGBSPFILEID 16 //BotLoadMap: incorrect BSP file id +#define BLERR_WRONGBSPFILEVERSION 17 //BotLoadMap: incorrect BSP file version +#define BLERR_CANNOTREADBSPLUMP 18 //BotLoadMap: cannot read BSP file lump +#define BLERR_AICLIENTNOTSETUP 19 //BotAI: client not setup +#define BLERR_AICLIENTALREADYSETUP 20 //BotSetupClient: client already setup +#define BLERR_AIMOVEINACTIVECLIENT 21 //BotMoveClient: cannot move inactive client +#define BLERR_AIMOVETOACTIVECLIENT 22 //BotMoveClient: cannot move to active client +#define BLERR_AICLIENTALREADYSHUTDOWN 23 //BotShutdownClient: client not setup +#define BLERR_AIUPDATEINACTIVECLIENT 24 //BotUpdateClient: called for inactive client +#define BLERR_AICMFORINACTIVECLIENT 25 //BotConsoleMessage: called for inactive client +#define BLERR_SETTINGSINACTIVECLIENT 26 //BotClientSettings: called for inactive client +#define BLERR_CANNOTLOADICHAT 27 //BotSetupClient: cannot load initial chats +#define BLERR_CANNOTLOADITEMWEIGHTS 28 //BotSetupClient: cannot load item weights +#define BLERR_CANNOTLOADITEMCONFIG 29 //BotSetupLibrary: cannot load item config +#define BLERR_CANNOTLOADWEAPONWEIGHTS 30 //BotSetupClient: cannot load weapon weights +#define BLERR_CANNOTLOADWEAPONCONFIG 31 //BotSetupLibrary: cannot load weapon config +#define BLERR_INVALIDSOUNDINDEX 32 //BotAddSound: invalid sound index value + +//action flags +#define ACTION_ATTACK 1 +#define ACTION_USE 2 +#define ACTION_RESPAWN 4 +#define ACTION_JUMP 8 +#define ACTION_MOVEUP 8 +#define ACTION_CROUCH 16 +#define ACTION_MOVEDOWN 16 +#define ACTION_MOVEFORWARD 32 +#define ACTION_MOVEBACK 64 +#define ACTION_MOVELEFT 128 +#define ACTION_MOVERIGHT 256 +#define ACTION_DELAYEDJUMP 512 +#define ACTION_TALK 1024 +#define ACTION_GESTURE 2048 +#define ACTION_WALK 4096 + +//the bot input, will be converted to an usercmd_t +typedef struct bot_input_s +{ + float thinktime; //time since last output (in seconds) + vec3_t dir; //movement direction + float speed; //speed in the range [0, 400] + vec3_t viewangles; //the view angles + int actionflags; //one of the ACTION_? flags + int weapon; //weapon to use +} bot_input_t; + +#ifndef BSPTRACE + +//bsp_trace_t hit surface +typedef struct bsp_surface_s +{ + char name[16]; + int flags; + int value; +} bsp_surface_t; + +//remove the bsp_trace_s structure definition l8r on +//a trace is returned when a box is swept through the world +typedef struct bsp_trace_s +{ + qboolean allsolid; // if true, plane is not valid + qboolean startsolid; // if true, the initial point was in a solid area + float fraction; // time completed, 1.0 = didn't hit anything + vec3_t endpos; // final position + cplane_t plane; // surface normal at impact + float exp_dist; // expanded plane distance + int sidenum; // number of the brush side hit + bsp_surface_t surface; // the hit point surface + int contents; // contents on other side of surface hit + int ent; // number of entity hit +} bsp_trace_t; + +#define BSPTRACE +#endif // BSPTRACE + +//entity state +typedef struct bot_entitystate_s +{ + int type; // entity type + int flags; // entity flags + vec3_t origin; // origin of the entity + vec3_t angles; // angles of the model + vec3_t old_origin; // for lerping + vec3_t mins; // bounding box minimums + vec3_t maxs; // bounding box maximums + int groundent; // ground entity + int solid; // solid type + int modelindex; // model used + int modelindex2; // weapons, CTF flags, etc + int frame; // model frame number + int event; // impulse events -- muzzle flashes, footsteps, etc + int eventParm; // even parameter + int powerups; // bit flags + int weapon; // determines weapon and flash model, etc + int legsAnim; // mask off ANIM_TOGGLEBIT + int torsoAnim; // mask off ANIM_TOGGLEBIT +// int weapAnim; // mask off ANIM_TOGGLEBIT //----(SA) added +//----(SA) didn't want to comment in as I wasn't sure of any implications of changing this structure. +} bot_entitystate_t; + +//bot AI library exported functions +typedef struct botlib_import_s +{ + //print messages from the bot library + void ( QDECL * Print )( int type, char *fmt, ... ); + //trace a bbox through the world + void ( *Trace )( bsp_trace_t *trace, vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end, int passent, int contentmask ); + //trace a bbox against a specific entity + void ( *EntityTrace )( bsp_trace_t *trace, vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end, int entnum, int contentmask ); + //retrieve the contents at the given point + int ( *PointContents )( vec3_t point ); + //check if the point is in potential visible sight + int ( *inPVS )( vec3_t p1, vec3_t p2 ); + //retrieve the BSP entity data lump + char *( *BSPEntityData )( void ); + // + void ( *BSPModelMinsMaxsOrigin )( int modelnum, vec3_t angles, vec3_t mins, vec3_t maxs, vec3_t origin ); + //send a bot client command + void ( *BotClientCommand )( int client, char *command ); + //memory allocation + void *( *GetMemory )( int size ); + void ( *FreeMemory )( void *ptr ); + void ( *FreeZoneMemory )( void ); + void *( *HunkAlloc )( int size ); + //file system access + int ( *FS_FOpenFile )( const char *qpath, fileHandle_t *file, fsMode_t mode ); + int ( *FS_Read )( void *buffer, int len, fileHandle_t f ); + int ( *FS_Write )( const void *buffer, int len, fileHandle_t f ); + void ( *FS_FCloseFile )( fileHandle_t f ); + int ( *FS_Seek )( fileHandle_t f, long offset, int origin ); + //debug visualisation stuff + int ( *DebugLineCreate )( void ); + void ( *DebugLineDelete )( int line ); + void ( *DebugLineShow )( int line, vec3_t start, vec3_t end, int color ); + // + int ( *DebugPolygonCreate )( int color, int numPoints, vec3_t *points ); + void ( *DebugPolygonDelete )( int id ); + // + // Ridah, Cast AI stuff + qboolean ( *AICast_VisibleFromPos )( vec3_t srcpos, int srcnum, + vec3_t destpos, int destnum, qboolean updateVisPos ); + qboolean ( *AICast_CheckAttackAtPos )( int entnum, int enemy, vec3_t pos, qboolean ducking, qboolean allowHitWorld ); + // done. +} botlib_import_t; + +typedef struct aas_export_s +{ + //----------------------------------- + // be_aas_entity.h + //----------------------------------- + void ( *AAS_EntityInfo )( int entnum, struct aas_entityinfo_s *info ); + //----------------------------------- + // be_aas_main.h + //----------------------------------- + int ( *AAS_Initialized )( void ); + void ( *AAS_PresenceTypeBoundingBox )( int presencetype, vec3_t mins, vec3_t maxs ); + float ( *AAS_Time )( void ); + //-------------------------------------------- + // be_aas_sample.c + //-------------------------------------------- + int ( *AAS_PointAreaNum )( vec3_t point ); + int ( *AAS_TraceAreas )( vec3_t start, vec3_t end, int *areas, vec3_t *points, int maxareas ); + //-------------------------------------------- + // be_aas_bspq3.c + //-------------------------------------------- + int ( *AAS_PointContents )( vec3_t point ); + int ( *AAS_NextBSPEntity )( int ent ); + int ( *AAS_ValueForBSPEpairKey )( int ent, char *key, char *value, int size ); + int ( *AAS_VectorForBSPEpairKey )( int ent, char *key, vec3_t v ); + int ( *AAS_FloatForBSPEpairKey )( int ent, char *key, float *value ); + int ( *AAS_IntForBSPEpairKey )( int ent, char *key, int *value ); + //-------------------------------------------- + // be_aas_reach.c + //-------------------------------------------- + int ( *AAS_AreaReachability )( int areanum ); + //-------------------------------------------- + // be_aas_route.c + //-------------------------------------------- + int ( *AAS_AreaTravelTimeToGoalArea )( int areanum, vec3_t origin, int goalareanum, int travelflags ); + //-------------------------------------------- + // be_aas_move.c + //-------------------------------------------- + int ( *AAS_Swimming )( vec3_t origin ); + int ( *AAS_PredictClientMovement )( struct aas_clientmove_s *move, + int entnum, vec3_t origin, + int presencetype, int onground, + vec3_t velocity, vec3_t cmdmove, + int cmdframes, + int maxframes, float frametime, + int stopevent, int stopareanum, int visualize ); + + // Ridah, route-tables + //-------------------------------------------- + // be_aas_routetable.c + //-------------------------------------------- + void ( *AAS_RT_ShowRoute )( vec3_t srcpos, int srcnum, int destnum ); + qboolean ( *AAS_RT_GetHidePos )( vec3_t srcpos, int srcnum, int srcarea, vec3_t destpos, int destnum, int destarea, vec3_t returnPos ); + int ( *AAS_FindAttackSpotWithinRange )( int srcnum, int rangenum, int enemynum, float rangedist, int travelflags, float *outpos ); + void ( *AAS_SetAASBlockingEntity )( vec3_t absmin, vec3_t absmax, qboolean blocking ); + // done. + + // Ridah + void ( *AAS_SetCurrentWorld )( int index ); + // done. + +} aas_export_t; + +typedef struct ea_export_s +{ + //ClientCommand elementary actions + void ( *EA_Say )( int client, char *str ); + void ( *EA_SayTeam )( int client, char *str ); + void ( *EA_UseItem )( int client, char *it ); + void ( *EA_DropItem )( int client, char *it ); + void ( *EA_UseInv )( int client, char *inv ); + void ( *EA_DropInv )( int client, char *inv ); + void ( *EA_Gesture )( int client ); + void ( *EA_Command )( int client, char *command ); + //regular elementary actions + void ( *EA_SelectWeapon )( int client, int weapon ); + void ( *EA_Talk )( int client ); + void ( *EA_Attack )( int client ); + void ( *EA_Use )( int client ); + void ( *EA_Respawn )( int client ); + void ( *EA_Jump )( int client ); + void ( *EA_DelayedJump )( int client ); + void ( *EA_Crouch )( int client ); + void ( *EA_MoveUp )( int client ); + void ( *EA_MoveDown )( int client ); + void ( *EA_MoveForward )( int client ); + void ( *EA_MoveBack )( int client ); + void ( *EA_MoveLeft )( int client ); + void ( *EA_MoveRight )( int client ); + void ( *EA_Move )( int client, vec3_t dir, float speed ); + void ( *EA_View )( int client, vec3_t viewangles ); + //send regular input to the server + void ( *EA_EndRegular )( int client, float thinktime ); + void ( *EA_GetInput )( int client, float thinktime, bot_input_t *input ); + void ( *EA_ResetInput )( int client, bot_input_t *init ); +} ea_export_t; + +typedef struct ai_export_s +{ + //----------------------------------- + // be_ai_char.h + //----------------------------------- + int ( *BotLoadCharacter )( char *charfile, int skill ); + void ( *BotFreeCharacter )( int character ); + float ( *Characteristic_Float )( int character, int index ); + float ( *Characteristic_BFloat )( int character, int index, float min, float max ); + int ( *Characteristic_Integer )( int character, int index ); + int ( *Characteristic_BInteger )( int character, int index, int min, int max ); + void ( *Characteristic_String )( int character, int index, char *buf, int size ); + //----------------------------------- + // be_ai_chat.h + //----------------------------------- + int ( *BotAllocChatState )( void ); + void ( *BotFreeChatState )( int handle ); + void ( *BotQueueConsoleMessage )( int chatstate, int type, char *message ); + void ( *BotRemoveConsoleMessage )( int chatstate, int handle ); + int ( *BotNextConsoleMessage )( int chatstate, struct bot_consolemessage_s *cm ); + int ( *BotNumConsoleMessages )( int chatstate ); + void ( *BotInitialChat )( int chatstate, char *type, int mcontext, char *var0, char *var1, char *var2, char *var3, char *var4, char *var5, char *var6, char *var7 ); + int ( *BotNumInitialChats )( int chatstate, char *type ); + int ( *BotReplyChat )( int chatstate, char *message, int mcontext, int vcontext, char *var0, char *var1, char *var2, char *var3, char *var4, char *var5, char *var6, char *var7 ); + int ( *BotChatLength )( int chatstate ); + void ( *BotEnterChat )( int chatstate, int client, int sendto ); + void ( *BotGetChatMessage )( int chatstate, char *buf, int size ); + int ( *StringContains )( char *str1, char *str2, int casesensitive ); + int ( *BotFindMatch )( char *str, struct bot_match_s *match, unsigned long int context ); + void ( *BotMatchVariable )( struct bot_match_s *match, int variable, char *buf, int size ); + void ( *UnifyWhiteSpaces )( char *string ); + void ( *BotReplaceSynonyms )( char *string, unsigned long int context ); + int ( *BotLoadChatFile )( int chatstate, char *chatfile, char *chatname ); + void ( *BotSetChatGender )( int chatstate, int gender ); + void ( *BotSetChatName )( int chatstate, char *name ); + //----------------------------------- + // be_ai_goal.h + //----------------------------------- + void ( *BotResetGoalState )( int goalstate ); + void ( *BotResetAvoidGoals )( int goalstate ); + void ( *BotRemoveFromAvoidGoals )( int goalstate, int number ); + void ( *BotPushGoal )( int goalstate, struct bot_goal_s *goal ); + void ( *BotPopGoal )( int goalstate ); + void ( *BotEmptyGoalStack )( int goalstate ); + void ( *BotDumpAvoidGoals )( int goalstate ); + void ( *BotDumpGoalStack )( int goalstate ); + void ( *BotGoalName )( int number, char *name, int size ); + int ( *BotGetTopGoal )( int goalstate, struct bot_goal_s *goal ); + int ( *BotGetSecondGoal )( int goalstate, struct bot_goal_s *goal ); + int ( *BotChooseLTGItem )( int goalstate, vec3_t origin, int *inventory, int travelflags ); + int ( *BotChooseNBGItem )( int goalstate, vec3_t origin, int *inventory, int travelflags, + struct bot_goal_s *ltg, float maxtime ); + int ( *BotTouchingGoal )( vec3_t origin, struct bot_goal_s *goal ); + int ( *BotItemGoalInVisButNotVisible )( int viewer, vec3_t eye, vec3_t viewangles, struct bot_goal_s *goal ); + int ( *BotGetLevelItemGoal )( int index, char *classname, struct bot_goal_s *goal ); + int ( *BotGetNextCampSpotGoal )( int num, struct bot_goal_s *goal ); + int ( *BotGetMapLocationGoal )( char *name, struct bot_goal_s *goal ); + float ( *BotAvoidGoalTime )( int goalstate, int number ); + void ( *BotInitLevelItems )( void ); + void ( *BotUpdateEntityItems )( void ); + int ( *BotLoadItemWeights )( int goalstate, char *filename ); + void ( *BotFreeItemWeights )( int goalstate ); + void ( *BotInterbreedGoalFuzzyLogic )( int parent1, int parent2, int child ); + void ( *BotSaveGoalFuzzyLogic )( int goalstate, char *filename ); + void ( *BotMutateGoalFuzzyLogic )( int goalstate, float range ); + int ( *BotAllocGoalState )( int client ); + void ( *BotFreeGoalState )( int handle ); + //----------------------------------- + // be_ai_move.h + //----------------------------------- + void ( *BotResetMoveState )( int movestate ); + void ( *BotMoveToGoal )( struct bot_moveresult_s *result, int movestate, struct bot_goal_s *goal, int travelflags ); + int ( *BotMoveInDirection )( int movestate, vec3_t dir, float speed, int type ); + void ( *BotResetAvoidReach )( int movestate ); + void ( *BotResetLastAvoidReach )( int movestate ); + int ( *BotReachabilityArea )( vec3_t origin, int testground ); + int ( *BotMovementViewTarget )( int movestate, struct bot_goal_s *goal, int travelflags, float lookahead, vec3_t target ); + int ( *BotPredictVisiblePosition )( vec3_t origin, int areanum, struct bot_goal_s *goal, int travelflags, vec3_t target ); + int ( *BotAllocMoveState )( void ); + void ( *BotFreeMoveState )( int handle ); + void ( *BotInitMoveState )( int handle, struct bot_initmove_s *initmove ); + // Ridah + void ( *BotInitAvoidReach )( int handle ); + // done. + //----------------------------------- + // be_ai_weap.h + //----------------------------------- + int ( *BotChooseBestFightWeapon )( int weaponstate, int *inventory ); + void ( *BotGetWeaponInfo )( int weaponstate, int weapon, struct weaponinfo_s *weaponinfo ); + int ( *BotLoadWeaponWeights )( int weaponstate, char *filename ); + int ( *BotAllocWeaponState )( void ); + void ( *BotFreeWeaponState )( int weaponstate ); + void ( *BotResetWeaponState )( int weaponstate ); + //----------------------------------- + // be_ai_gen.h + //----------------------------------- + int ( *GeneticParentsAndChildSelection )( int numranks, float *ranks, int *parent1, int *parent2, int *child ); +} ai_export_t; + +//bot AI library imported functions +typedef struct botlib_export_s +{ + //Area Awareness System functions + aas_export_t aas; + //Elementary Action functions + ea_export_t ea; + //AI functions + ai_export_t ai; + //setup the bot library, returns BLERR_ + int ( *BotLibSetup )( void ); + //shutdown the bot library, returns BLERR_ + int ( *BotLibShutdown )( void ); + //sets a library variable returns BLERR_ + int ( *BotLibVarSet )( char *var_name, char *value ); + //gets a library variable returns BLERR_ + int ( *BotLibVarGet )( char *var_name, char *value, int size ); + //sets a C-like define returns BLERR_ + int ( *BotLibDefine )( char *string ); + //start a frame in the bot library + int ( *BotLibStartFrame )( float time ); + //load a new map in the bot library + int ( *BotLibLoadMap )( const char *mapname ); + //entity updates + int ( *BotLibUpdateEntity )( int ent, bot_entitystate_t *state ); + //just for testing + int ( *Test )( int parm0, char *parm1, vec3_t parm2, vec3_t parm3 ); +} botlib_export_t; + +//linking of bot library +botlib_export_t *GetBotLibAPI( int apiVersion, botlib_import_t *import ); + +/* Library variables: + +name: default: module(s): description: + +"basedir" "" l_utils.c Quake2 base directory +"gamedir" "" l_utils.c Quake2 game directory +"cddir" "" l_utils.c Quake2 CD directory + +"autolaunchbspc" "0" be_aas_load.c automatically launch (Win)BSPC +"log" "0" l_log.c enable/disable creating a log file +"maxclients" "4" be_interface.c maximum number of clients +"maxentities" "1024" be_interface.c maximum number of entities + +"sv_friction" "6" be_aas_move.c ground friction +"sv_stopspeed" "100" be_aas_move.c stop speed +"sv_gravity" "800" be_aas_move.c gravity value +"sv_waterfriction" "1" be_aas_move.c water friction +"sv_watergravity" "400" be_aas_move.c gravity in water +"sv_maxvelocity" "300" be_aas_move.c maximum velocity +"sv_maxwalkvelocity" "300" be_aas_move.c maximum walk velocity +"sv_maxcrouchvelocity" "100" be_aas_move.c maximum crouch velocity +"sv_maxswimvelocity" "150" be_aas_move.c maximum swim velocity +"sv_walkaccelerate" "10" be_aas_move.c walk acceleration +"sv_airaccelerate" "1" be_aas_move.c air acceleration +"sv_swimaccelerate" "4" be_aas_move.c swim acceleration +"sv_maxstep" "18" be_aas_move.c maximum step height +"sv_maxbarrier" "32" be_aas_move.c maximum barrier height +"sv_maxsteepness" "0.7" be_aas_move.c maximum floor steepness +"sv_jumpvel" "270" be_aas_move.c jump z velocity +"sv_maxwaterjump" "20" be_aas_move.c maximum waterjump height + +"max_aaslinks" "4096" be_aas_sample.c maximum links in the AAS +"max_bsplinks" "4096" be_aas_bsp.c maximum links in the BSP + +"notspawnflags" "2048" be_ai_goal.c entities with these spawnflags will be removed +"itemconfig" "items.c" be_ai_goal.c item configuration file +"weaponconfig" "weapons.c" be_ai_weap.c weapon configuration file +"synfile" "syn.c" be_ai_chat.c file with synonyms +"rndfile" "rnd.c" be_ai_chat.c file with random strings +"matchfile" "match.c" be_ai_chat.c file with match strings +"max_messages" "1024" be_ai_chat.c console message heap size +"max_weaponinfo" "32" be_ai_weap.c maximum number of weapon info +"max_projectileinfo" "32" be_ai_weap.c maximum number of projectile info +"max_iteminfo" "256" be_ai_goal.c maximum number of item info +"max_levelitems" "256" be_ai_goal.c maximum number of level items +"framereachability" "" be_aas_reach.c number of reachabilities to calucate per frame +"forceclustering" "0" be_aas_main.c force recalculation of clusters +"forcereachability" "0" be_aas_main.c force recalculation of reachabilities +"forcewrite" "0" be_aas_main.c force writing of aas file +"nooptimize" "0" be_aas_main.c no aas optimization + +"laserhook" "0" be_ai_move.c 0 = CTF hook, 1 = laser hook + +*/ + diff --git a/Projects/Android/jni/rtcw/src/botlib/botlib.vcproj b/Projects/Android/jni/rtcw/src/botlib/botlib.vcproj new file mode 100644 index 0000000..86c25c5 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/botlib/botlib.vcproj @@ -0,0 +1,911 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Projects/Android/jni/rtcw/src/botlib/botlib.vcxproj b/Projects/Android/jni/rtcw/src/botlib/botlib.vcxproj new file mode 100644 index 0000000..77061e8 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/botlib/botlib.vcxproj @@ -0,0 +1,182 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {86691FDD-E0C6-4D71-9FFD-E0F30F19AA3E} + + + + StaticLibrary + v110 + false + MultiByte + + + StaticLibrary + v110 + false + MultiByte + + + + + + + + + + + + + + + <_ProjectFileVersion>11.0.50727.1 + + + .\Release\ + .\Release\ + + + .\Debug\ + .\Debug\ + + + + MaxSpeed + OnlyExplicitInline + WIN32;NDEBUG;_LIB;BOTLIB;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + true + MultiThreaded + true + .\Release/botlib.pch + .\Release/ + .\Release/ + .\Release/ + Level4 + true + + + NDEBUG;%(PreprocessorDefinitions) + 0x0409 + + + .\Release\botlib.lib + true + + + true + .\Release/botlib.bsc + + + + + Disabled + WIN32;_DEBUG;_LIB;BOTLIB;DEBUG;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + true + EnableFastChecks + MultiThreadedDebug + .\Debug/botlib.pch + .\Debug/ + .\Debug/ + .\Debug/ + true + Level3 + true + EditAndContinue + + + _DEBUG;%(PreprocessorDefinitions) + 0x0409 + + + .\Debug\botlib.lib + true + + + true + .\Debug/botlib.bsc + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Projects/Android/jni/rtcw/src/botlib/botlib.vcxproj.filters b/Projects/Android/jni/rtcw/src/botlib/botlib.vcxproj.filters new file mode 100644 index 0000000..cae5693 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/botlib/botlib.vcxproj.filters @@ -0,0 +1,215 @@ + + + + + {24c141db-c4a4-4901-8516-8d8cfc8fa793} + cpp;c;cxx;rc;def;r;odl;idl;hpj;bat + + + {22df568f-e0ff-497f-a95c-218be479c431} + h;hpp;hxx;hm;inl + + + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + \ No newline at end of file diff --git a/Projects/Android/jni/rtcw/src/botlib/l_crc.c b/Projects/Android/jni/rtcw/src/botlib/l_crc.c new file mode 100644 index 0000000..d76f461 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/botlib/l_crc.c @@ -0,0 +1,155 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +/***************************************************************************** + * name: l_crc.c + * + * desc: CRC calculation + * + * + *****************************************************************************/ + +#include +#include +#include + +#include "../game/q_shared.h" +#include "../game/botlib.h" +#include "be_interface.h" //for botimport.Print + + +// FIXME: byte swap? + +// this is a 16 bit, non-reflected CRC using the polynomial 0x1021 +// and the initial and final xor values shown below... in other words, the +// CCITT standard CRC used by XMODEM + +#define CRC_INIT_VALUE 0xffff +#define CRC_XOR_VALUE 0x0000 + +unsigned short crctable[257] = +{ + 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7, + 0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef, + 0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6, + 0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de, + 0x2462, 0x3443, 0x0420, 0x1401, 0x64e6, 0x74c7, 0x44a4, 0x5485, + 0xa56a, 0xb54b, 0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d, + 0x3653, 0x2672, 0x1611, 0x0630, 0x76d7, 0x66f6, 0x5695, 0x46b4, + 0xb75b, 0xa77a, 0x9719, 0x8738, 0xf7df, 0xe7fe, 0xd79d, 0xc7bc, + 0x48c4, 0x58e5, 0x6886, 0x78a7, 0x0840, 0x1861, 0x2802, 0x3823, + 0xc9cc, 0xd9ed, 0xe98e, 0xf9af, 0x8948, 0x9969, 0xa90a, 0xb92b, + 0x5af5, 0x4ad4, 0x7ab7, 0x6a96, 0x1a71, 0x0a50, 0x3a33, 0x2a12, + 0xdbfd, 0xcbdc, 0xfbbf, 0xeb9e, 0x9b79, 0x8b58, 0xbb3b, 0xab1a, + 0x6ca6, 0x7c87, 0x4ce4, 0x5cc5, 0x2c22, 0x3c03, 0x0c60, 0x1c41, + 0xedae, 0xfd8f, 0xcdec, 0xddcd, 0xad2a, 0xbd0b, 0x8d68, 0x9d49, + 0x7e97, 0x6eb6, 0x5ed5, 0x4ef4, 0x3e13, 0x2e32, 0x1e51, 0x0e70, + 0xff9f, 0xefbe, 0xdfdd, 0xcffc, 0xbf1b, 0xaf3a, 0x9f59, 0x8f78, + 0x9188, 0x81a9, 0xb1ca, 0xa1eb, 0xd10c, 0xc12d, 0xf14e, 0xe16f, + 0x1080, 0x00a1, 0x30c2, 0x20e3, 0x5004, 0x4025, 0x7046, 0x6067, + 0x83b9, 0x9398, 0xa3fb, 0xb3da, 0xc33d, 0xd31c, 0xe37f, 0xf35e, + 0x02b1, 0x1290, 0x22f3, 0x32d2, 0x4235, 0x5214, 0x6277, 0x7256, + 0xb5ea, 0xa5cb, 0x95a8, 0x8589, 0xf56e, 0xe54f, 0xd52c, 0xc50d, + 0x34e2, 0x24c3, 0x14a0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405, + 0xa7db, 0xb7fa, 0x8799, 0x97b8, 0xe75f, 0xf77e, 0xc71d, 0xd73c, + 0x26d3, 0x36f2, 0x0691, 0x16b0, 0x6657, 0x7676, 0x4615, 0x5634, + 0xd94c, 0xc96d, 0xf90e, 0xe92f, 0x99c8, 0x89e9, 0xb98a, 0xa9ab, + 0x5844, 0x4865, 0x7806, 0x6827, 0x18c0, 0x08e1, 0x3882, 0x28a3, + 0xcb7d, 0xdb5c, 0xeb3f, 0xfb1e, 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a, + 0x4a75, 0x5a54, 0x6a37, 0x7a16, 0x0af1, 0x1ad0, 0x2ab3, 0x3a92, + 0xfd2e, 0xed0f, 0xdd6c, 0xcd4d, 0xbdaa, 0xad8b, 0x9de8, 0x8dc9, + 0x7c26, 0x6c07, 0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0x0cc1, + 0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8, + 0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0, + 0x0000 // because process string allows value 256 through and it was undefined +}; + +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void CRC_Init( unsigned short *crcvalue ) { + *crcvalue = CRC_INIT_VALUE; +} //end of the function CRC_Init +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void CRC_ProcessByte( unsigned short *crcvalue, byte data ) { + *crcvalue = ( *crcvalue << 8 ) ^ crctable[( *crcvalue >> 8 ) ^ data]; +} //end of the function CRC_ProcessByte +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +unsigned short CRC_Value( unsigned short crcvalue ) { + return crcvalue ^ CRC_XOR_VALUE; +} //end of the function CRC_Value +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +unsigned short CRC_ProcessString( unsigned char *data, int length ) { + unsigned short crcvalue; + int i, ind; + + CRC_Init( &crcvalue ); + + for ( i = 0; i < length; i++ ) + { + ind = ( crcvalue >> 8 ) ^ data[i]; + if ( ind < 0 || ind > 256 ) { + ind = 0; + } + crcvalue = ( crcvalue << 8 ) ^ crctable[ind]; + } //end for + return CRC_Value( crcvalue ); +} //end of the function CRC_ProcessString +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void CRC_ContinueProcessString( unsigned short *crc, char *data, int length ) { + int i; + + for ( i = 0; i < length; i++ ) + { + *crc = ( *crc << 8 ) ^ crctable[( *crc >> 8 ) ^ data[i]]; + } //end for +} //end of the function CRC_ProcessString diff --git a/Projects/Android/jni/rtcw/src/botlib/l_crc.h b/Projects/Android/jni/rtcw/src/botlib/l_crc.h new file mode 100644 index 0000000..287289a --- /dev/null +++ b/Projects/Android/jni/rtcw/src/botlib/l_crc.h @@ -0,0 +1,44 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +//=========================================================================== +// +// Name: l_crc.h +// Function: for CRC checks +// Programmer: Mr Elusive (MrElusive@demigod.demon.nl) +// Last update: 1997-12-31 +// Tab Size: 3 +//=========================================================================== + +typedef unsigned short crc_t; + +void CRC_Init( unsigned short *crcvalue ); +void CRC_ProcessByte( unsigned short *crcvalue, byte data ); +unsigned short CRC_Value( unsigned short crcvalue ); +unsigned short CRC_ProcessString( unsigned char *data, int length ); +void CRC_ContinueProcessString( unsigned short *crc, char *data, int length ); diff --git a/Projects/Android/jni/rtcw/src/botlib/l_libvar.c b/Projects/Android/jni/rtcw/src/botlib/l_libvar.c new file mode 100644 index 0000000..99c0fe7 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/botlib/l_libvar.c @@ -0,0 +1,282 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +/***************************************************************************** + * name: l_libvar.c + * + * desc: bot library variables + * + * + *****************************************************************************/ + +#include "../game/q_shared.h" +#include "l_memory.h" +#include "l_libvar.h" + +//list with library variables +libvar_t *libvarlist; + +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +float LibVarStringValue( char *string ) { + int dotfound = 0; + float value = 0; + + while ( *string ) + { + if ( *string < '0' || *string > '9' ) { + if ( dotfound || *string != '.' ) { + return 0; + } //end if + else + { + dotfound = 10; + string++; + } //end if + } //end if + if ( dotfound ) { + value = value + (float) ( *string - '0' ) / (float) dotfound; + dotfound *= 10; + } //end if + else + { + value = value * 10.0 + (float) ( *string - '0' ); + } //end else + string++; + } //end while + return value; +} //end of the function LibVarStringValue +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +libvar_t *LibVarAlloc( char *var_name ) { + libvar_t *v; + + v = (libvar_t *) GetMemory( sizeof( libvar_t ) + strlen( var_name ) + 1 ); + memset( v, 0, sizeof( libvar_t ) ); + v->name = (char *) v + sizeof( libvar_t ); + strcpy( v->name, var_name ); + //add the variable in the list + v->next = libvarlist; + libvarlist = v; + return v; +} //end of the function LibVarAlloc +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void LibVarDeAlloc( libvar_t *v ) { + if ( v->string ) { + FreeMemory( v->string ); + } + FreeMemory( v ); +} //end of the function LibVarDeAlloc +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void LibVarDeAllocAll( void ) { + libvar_t *v; + + for ( v = libvarlist; v; v = libvarlist ) + { + libvarlist = libvarlist->next; + LibVarDeAlloc( v ); + } //end for + libvarlist = NULL; +} //end of the function LibVarDeAllocAll +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +libvar_t *LibVarGet( char *var_name ) { + libvar_t *v; + + for ( v = libvarlist; v; v = v->next ) + { + if ( !Q_stricmp( v->name, var_name ) ) { + return v; + } //end if + } //end for + return NULL; +} //end of the function LibVarGet +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +char *LibVarGetString( char *var_name ) { + libvar_t *v; + + v = LibVarGet( var_name ); + if ( v ) { + return v->string; + } //end if + else + { + return ""; + } //end else +} //end of the function LibVarGetString +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +float LibVarGetValue( char *var_name ) { + libvar_t *v; + + v = LibVarGet( var_name ); + if ( v ) { + return v->value; + } //end if + else + { + return 0; + } //end else +} //end of the function LibVarGetValue +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +libvar_t *LibVar( char *var_name, char *value ) { + libvar_t *v; + v = LibVarGet( var_name ); + if ( v ) { + return v; + } + //create new variable + v = LibVarAlloc( var_name ); + //variable string + v->string = (char *) GetMemory( strlen( value ) + 1 ); + strcpy( v->string, value ); + //the value + v->value = LibVarStringValue( v->string ); + //variable is modified + v->modified = qtrue; + // + return v; +} //end of the function LibVar +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +char *LibVarString( char *var_name, char *value ) { + libvar_t *v; + + v = LibVar( var_name, value ); + return v->string; +} //end of the function LibVarString +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +float LibVarValue( char *var_name, char *value ) { + libvar_t *v; + + v = LibVar( var_name, value ); + return v->value; +} //end of the function LibVarValue +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void LibVarSet( char *var_name, char *value ) { + libvar_t *v; + + v = LibVarGet( var_name ); + if ( v ) { + FreeMemory( v->string ); + } //end if + else + { + v = LibVarAlloc( var_name ); + } //end else + //variable string + v->string = (char *) GetMemory( strlen( value ) + 1 ); + strcpy( v->string, value ); + //the value + v->value = LibVarStringValue( v->string ); + //variable is modified + v->modified = qtrue; +} //end of the function LibVarSet +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +qboolean LibVarChanged( char *var_name ) { + libvar_t *v; + + v = LibVarGet( var_name ); + if ( v ) { + return v->modified; + } //end if + else + { + return qfalse; + } //end else +} //end of the function LibVarChanged +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void LibVarSetNotModified( char *var_name ) { + libvar_t *v; + + v = LibVarGet( var_name ); + if ( v ) { + v->modified = qfalse; + } //end if +} //end of the function LibVarSetNotModified diff --git a/Projects/Android/jni/rtcw/src/botlib/l_libvar.h b/Projects/Android/jni/rtcw/src/botlib/l_libvar.h new file mode 100644 index 0000000..cd04894 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/botlib/l_libvar.h @@ -0,0 +1,69 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +/***************************************************************************** + * name: l_libvar.h + * + * desc: botlib vars + * + * + *****************************************************************************/ + +//library variable +typedef struct libvar_s +{ + char *name; + char *string; + int flags; + qboolean modified; // set each time the cvar is changed + float value; + struct libvar_s *next; +} libvar_t; + +//removes all library variables +void LibVarDeAllocAll( void ); +//gets the library variable with the given name +libvar_t *LibVarGet( char *var_name ); +//gets the string of the library variable with the given name +char *LibVarGetString( char *var_name ); +//gets the value of the library variable with the given name +float LibVarGetValue( char *var_name ); +//creates the library variable if not existing already and returns it +libvar_t *LibVar( char *var_name, char *value ); +//creates the library variable if not existing already and returns the value +float LibVarValue( char *var_name, char *value ); +//creates the library variable if not existing already and returns the value string +char *LibVarString( char *var_name, char *value ); +//sets the library variable +void LibVarSet( char *var_name, char *value ); +//returns true if the library variable has been modified +qboolean LibVarChanged( char *var_name ); +//sets the library variable to unmodified +void LibVarSetNotModified( char *var_name ); + diff --git a/Projects/Android/jni/rtcw/src/botlib/l_log.c b/Projects/Android/jni/rtcw/src/botlib/l_log.c new file mode 100644 index 0000000..3ad98ad --- /dev/null +++ b/Projects/Android/jni/rtcw/src/botlib/l_log.c @@ -0,0 +1,186 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +/***************************************************************************** + * name: l_log.c + * + * desc: log file + * + * + *****************************************************************************/ + +#include +#include +#include + +#include "../game/q_shared.h" +#include "../game/botlib.h" +#include "be_interface.h" //for botimport.Print +#include "l_libvar.h" + +#define MAX_LOGFILENAMESIZE 1024 + +typedef struct logfile_s +{ + char filename[MAX_LOGFILENAMESIZE]; + FILE *fp; + int numwrites; +} logfile_t; + +static logfile_t logfile; + +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void Log_AlwaysOpen( char *filename ) { + if ( !filename || !strlen( filename ) ) { + botimport.Print( PRT_MESSAGE, "openlog \n" ); + return; + } //end if + if ( logfile.fp ) { + botimport.Print( PRT_ERROR, "log file %s is already opened\n", logfile.filename ); + return; + } //end if + logfile.fp = fopen( filename, "wb" ); + if ( !logfile.fp ) { + botimport.Print( PRT_ERROR, "can't open the log file %s\n", filename ); + return; + } //end if + strncpy( logfile.filename, filename, MAX_LOGFILENAMESIZE ); + botimport.Print( PRT_MESSAGE, "Opened log %s\n", logfile.filename ); +} //end of the function Log_Create +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void Log_Open( char *filename ) { + if ( !LibVarValue( "log", "0" ) ) { + return; + } + Log_AlwaysOpen( filename ); + +} +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void Log_Close( void ) { + if ( !logfile.fp ) { + return; + } + if ( fclose( logfile.fp ) ) { + botimport.Print( PRT_ERROR, "can't close log file %s\n", logfile.filename ); + return; + } //end if + logfile.fp = NULL; + botimport.Print( PRT_MESSAGE, "Closed log %s\n", logfile.filename ); +} //end of the function Log_Close +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void Log_Shutdown( void ) { + if ( logfile.fp ) { + Log_Close(); + } +} //end of the function Log_Shutdown +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void QDECL Log_Write( char *fmt, ... ) { + va_list ap; + + if ( !logfile.fp ) { + return; + } + va_start( ap, fmt ); + vfprintf( logfile.fp, fmt, ap ); + va_end( ap ); + //fprintf(logfile.fp, "\r\n"); + fflush( logfile.fp ); +} //end of the function Log_Write +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void QDECL Log_WriteTimeStamped( char *fmt, ... ) { + va_list ap; + + if ( !logfile.fp ) { + return; + } + fprintf( logfile.fp, "%d %02d:%02d:%02d:%02d ", + logfile.numwrites, + (int) ( botlibglobals.time / 60 / 60 ), + (int) ( botlibglobals.time / 60 ), + (int) ( botlibglobals.time ), + (int) ( (int) ( botlibglobals.time * 100 ) ) - + ( (int) botlibglobals.time ) * 100 ); + va_start( ap, fmt ); + vfprintf( logfile.fp, fmt, ap ); + va_end( ap ); + fprintf( logfile.fp, "\r\n" ); + logfile.numwrites++; + fflush( logfile.fp ); +} //end of the function Log_Write +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +FILE *Log_FilePointer( void ) { + return logfile.fp; +} //end of the function Log_FilePointer +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void Log_Flush( void ) { + if ( logfile.fp ) { + fflush( logfile.fp ); + } +} //end of the function Log_Flush + diff --git a/Projects/Android/jni/rtcw/src/botlib/l_log.h b/Projects/Android/jni/rtcw/src/botlib/l_log.h new file mode 100644 index 0000000..fa32c9f --- /dev/null +++ b/Projects/Android/jni/rtcw/src/botlib/l_log.h @@ -0,0 +1,54 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +/***************************************************************************** + * name: l_log.h + * + * desc: log file + * + * + *****************************************************************************/ + +//open a log file +void Log_Open( char *filename ); +// +void Log_AlwaysOpen( char *filename ); +//close the current log file +void Log_Close( void ); +//close log file if present +void Log_Shutdown( void ); +//write to the current opened log file +void QDECL Log_Write( char *fmt, ... ); +//write to the current opened log file with a time stamp +void QDECL Log_WriteTimeStamped( char *fmt, ... ); +//returns a pointer to the log file +FILE *Log_FilePointer( void ); +//flush log file +void Log_Flush( void ); + diff --git a/Projects/Android/jni/rtcw/src/botlib/l_memory.c b/Projects/Android/jni/rtcw/src/botlib/l_memory.c new file mode 100644 index 0000000..6905afc --- /dev/null +++ b/Projects/Android/jni/rtcw/src/botlib/l_memory.c @@ -0,0 +1,446 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +/***************************************************************************** + * name: l_memory.c + * + * desc: memory allocation + * + * + *****************************************************************************/ + +#include "../game/q_shared.h" +#include "../game/botlib.h" +#include "l_log.h" +#include "be_interface.h" + +#ifdef _DEBUG + #define MEMDEBUG + #define MEMORYMANEGER +#endif + +#define MEM_ID 0x12345678l +#define HUNK_ID 0x87654321l + +int allocatedmemory; +int totalmemorysize; +int numblocks; + +#ifdef MEMORYMANEGER + +typedef struct memoryblock_s +{ + unsigned long int id; + void *ptr; + int size; +#ifdef MEMDEBUG + char *label; + char *file; + int line; +#endif //MEMDEBUG + struct memoryblock_s *prev, *next; +} memoryblock_t; + +memoryblock_t *memory; + +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void LinkMemoryBlock( memoryblock_t *block ) { + block->prev = NULL; + block->next = memory; + if ( memory ) { + memory->prev = block; + } + memory = block; +} //end of the function LinkMemoryBlock +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void UnlinkMemoryBlock( memoryblock_t *block ) { + if ( block->prev ) { + block->prev->next = block->next; + } else { memory = block->next;} + if ( block->next ) { + block->next->prev = block->prev; + } +} //end of the function UnlinkMemoryBlock +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +#ifdef MEMDEBUG +void *GetMemoryDebug( unsigned long size, char *label, char *file, int line ) +#else +void *GetMemory( unsigned long size ) +#endif //MEMDEBUG +{ + void *ptr; + memoryblock_t *block; + + ptr = botimport.GetMemory( size + sizeof( memoryblock_t ) ); + block = (memoryblock_t *) ptr; + block->id = MEM_ID; + block->ptr = (char *) ptr + sizeof( memoryblock_t ); + block->size = size + sizeof( memoryblock_t ); +#ifdef MEMDEBUG + block->label = label; + block->file = file; + block->line = line; +#endif //MEMDEBUG + LinkMemoryBlock( block ); + allocatedmemory += block->size; + totalmemorysize += block->size + sizeof( memoryblock_t ); + numblocks++; + return block->ptr; +} //end of the function GetMemoryDebug +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +#ifdef MEMDEBUG +void *GetClearedMemoryDebug( unsigned long size, char *label, char *file, int line ) +#else +void *GetClearedMemory( unsigned long size ) +#endif //MEMDEBUG +{ + void *ptr; +#ifdef MEMDEBUG + ptr = GetMemoryDebug( size, label, file, line ); +#else + ptr = GetMemory( size ); +#endif //MEMDEBUG + memset( ptr, 0, size ); + return ptr; +} //end of the function GetClearedMemory +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +#ifdef MEMDEBUG +void *GetHunkMemoryDebug( unsigned long size, char *label, char *file, int line ) +#else +void *GetHunkMemory( unsigned long size ) +#endif //MEMDEBUG +{ + void *ptr; + memoryblock_t *block; + + ptr = botimport.HunkAlloc( size + sizeof( memoryblock_t ) ); + block = (memoryblock_t *) ptr; + block->id = HUNK_ID; + block->ptr = (char *) ptr + sizeof( memoryblock_t ); + block->size = size + sizeof( memoryblock_t ); +#ifdef MEMDEBUG + block->label = label; + block->file = file; + block->line = line; +#endif //MEMDEBUG + LinkMemoryBlock( block ); + allocatedmemory += block->size; + totalmemorysize += block->size + sizeof( memoryblock_t ); + numblocks++; + return block->ptr; +} //end of the function GetHunkMemoryDebug +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +#ifdef MEMDEBUG +void *GetClearedHunkMemoryDebug( unsigned long size, char *label, char *file, int line ) +#else +void *GetClearedHunkMemory( unsigned long size ) +#endif //MEMDEBUG +{ + void *ptr; +#ifdef MEMDEBUG + ptr = GetHunkMemoryDebug( size, label, file, line ); +#else + ptr = GetHunkMemory( size ); +#endif //MEMDEBUG + memset( ptr, 0, size ); + return ptr; +} //end of the function GetClearedHunkMemory +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +memoryblock_t *BlockFromPointer( void *ptr, char *str ) { + memoryblock_t *block; + + if ( !ptr ) { +#ifdef MEMDEBUG + //char *crash = (char *) NULL; + //crash[0] = 1; + botimport.Print( PRT_FATAL, "%s: NULL pointer\n", str ); +#endif //MEMDEBUG + return NULL; + } //end if + block = ( memoryblock_t * )( (char *) ptr - sizeof( memoryblock_t ) ); + if ( block->id != MEM_ID && block->id != HUNK_ID ) { + botimport.Print( PRT_FATAL, "%s: invalid memory block\n", str ); + return NULL; + } //end if + if ( block->ptr != ptr ) { + botimport.Print( PRT_FATAL, "%s: memory block pointer invalid\n", str ); + return NULL; + } //end if + return block; +} //end of the function BlockFromPointer +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void FreeMemory( void *ptr ) { + memoryblock_t *block; + + block = BlockFromPointer( ptr, "FreeMemory" ); + if ( !block ) { + return; + } + UnlinkMemoryBlock( block ); + allocatedmemory -= block->size; + totalmemorysize -= block->size + sizeof( memoryblock_t ); + numblocks--; + // + if ( block->id == MEM_ID ) { + botimport.FreeMemory( block ); + } //end if +} //end of the function FreeMemory +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int MemoryByteSize( void *ptr ) { + memoryblock_t *block; + + block = BlockFromPointer( ptr, "MemoryByteSize" ); + if ( !block ) { + return 0; + } + return block->size; +} //end of the function MemoryByteSize +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void PrintUsedMemorySize( void ) { + botimport.Print( PRT_MESSAGE, "total allocated memory: %d KB\n", allocatedmemory >> 10 ); + botimport.Print( PRT_MESSAGE, "total botlib memory: %d KB\n", totalmemorysize >> 10 ); + botimport.Print( PRT_MESSAGE, "total memory blocks: %d\n", numblocks ); +} //end of the function PrintUsedMemorySize +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void PrintMemoryLabels( void ) { + memoryblock_t *block; + int i; + + PrintUsedMemorySize(); + i = 0; + Log_Write( "\r\n" ); + for ( block = memory; block; block = block->next ) + { +#ifdef MEMDEBUG + if ( block->id == HUNK_ID ) { + Log_Write( "%6d, hunk %p, %8d: %24s line %6d: %s\r\n", i, block->ptr, block->size, block->file, block->line, block->label ); + } //end if + else + { + Log_Write( "%6d, %p, %8d: %24s line %6d: %s\r\n", i, block->ptr, block->size, block->file, block->line, block->label ); + } //end else +#endif //MEMDEBUG + i++; + } //end for +} //end of the function PrintMemoryLabels +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void DumpMemory( void ) { + memoryblock_t *block; + + for ( block = memory; block; block = memory ) + { + FreeMemory( block->ptr ); + } //end for + totalmemorysize = 0; + allocatedmemory = 0; +} //end of the function DumpMemory + +#else + +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +#ifdef MEMDEBUG +void *GetMemoryDebug( unsigned long size, char *label, char *file, int line ) +#else +void *GetMemory( unsigned long size ) +#endif //MEMDEBUG +{ + void *ptr; + unsigned long int *memid; + + ptr = botimport.GetMemory( size + sizeof( unsigned long int ) ); + if ( !ptr ) { + return NULL; + } + memid = (unsigned long int *) ptr; + *memid = MEM_ID; + return (unsigned long int *) ( (char *) ptr + sizeof( unsigned long int ) ); +} //end of the function GetMemory +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +#ifdef MEMDEBUG +void *GetClearedMemoryDebug( unsigned long size, char *label, char *file, int line ) +#else +void *GetClearedMemory( unsigned long size ) +#endif //MEMDEBUG +{ + void *ptr; +#ifdef MEMDEBUG + ptr = GetMemoryDebug( size, label, file, line ); +#else +ptr = GetMemory( size ); +#endif //MEMDEBUG +memset( ptr, 0, size ); +return ptr; +} //end of the function GetClearedMemory +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +#ifdef MEMDEBUG +void *GetHunkMemoryDebug( unsigned long size, char *label, char *file, int line ) +#else +void *GetHunkMemory( unsigned long size ) +#endif //MEMDEBUG +{ + void *ptr; + unsigned long int *memid; + + ptr = botimport.HunkAlloc( size + sizeof( unsigned long int ) ); + if ( !ptr ) { + return NULL; + } + memid = (unsigned long int *) ptr; + *memid = HUNK_ID; + return (unsigned long int *) ( (char *) ptr + sizeof( unsigned long int ) ); +} //end of the function GetHunkMemory +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +#ifdef MEMDEBUG +void *GetClearedHunkMemoryDebug( unsigned long size, char *label, char *file, int line ) +#else +void *GetClearedHunkMemory( unsigned long size ) +#endif //MEMDEBUG +{ + void *ptr; +#ifdef MEMDEBUG + ptr = GetHunkMemoryDebug( size, label, file, line ); +#else +ptr = GetHunkMemory( size ); +#endif //MEMDEBUG +memset( ptr, 0, size ); +return ptr; +} //end of the function GetClearedHunkMemory +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void FreeMemory( void *ptr ) { + unsigned long int *memid; + + memid = (unsigned long int *) ( (char *) ptr - sizeof( unsigned long int ) ); + + if ( *memid == MEM_ID ) { + botimport.FreeMemory( memid ); + } //end if +} //end of the function FreeMemory +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void PrintUsedMemorySize( void ) { +} //end of the function PrintUsedMemorySize +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void PrintMemoryLabels( void ) { +} //end of the function PrintMemoryLabels + +#endif diff --git a/Projects/Android/jni/rtcw/src/botlib/l_memory.h b/Projects/Android/jni/rtcw/src/botlib/l_memory.h new file mode 100644 index 0000000..e730c1b --- /dev/null +++ b/Projects/Android/jni/rtcw/src/botlib/l_memory.h @@ -0,0 +1,84 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +/***************************************************************************** + * name: l_memory.h + * + * desc: memory management + * + * + *****************************************************************************/ + +#ifdef _DEBUG +#ifndef BSPC + #define MEMDEBUG +#endif +#endif + +#ifdef MEMDEBUG +#define GetMemory( size ) GetMemoryDebug( size, # size, __FILE__, __LINE__ ); +#define GetClearedMemory( size ) GetClearedMemoryDebug( size, # size, __FILE__, __LINE__ ); +//allocate a memory block of the given size +void *GetMemoryDebug( unsigned long size, char *label, char *file, int line ); +//allocate a memory block of the given size and clear it +void *GetClearedMemoryDebug( unsigned long size, char *label, char *file, int line ); +// +#define GetHunkMemory( size ) GetHunkMemoryDebug( size, # size, __FILE__, __LINE__ ); +#define GetClearedHunkMemory( size ) GetClearedHunkMemoryDebug( size, # size, __FILE__, __LINE__ ); +//allocate a memory block of the given size +void *GetHunkMemoryDebug( unsigned long size, char *label, char *file, int line ); +//allocate a memory block of the given size and clear it +void *GetClearedHunkMemoryDebug( unsigned long size, char *label, char *file, int line ); +#else +//allocate a memory block of the given size +void *GetMemory( unsigned long size ); +//allocate a memory block of the given size and clear it +void *GetClearedMemory( unsigned long size ); +// +#ifdef BSPC +#define GetHunkMemory GetMemory +#define GetClearedHunkMemory GetClearedMemory +#else +//allocate a memory block of the given size +void *GetHunkMemory( unsigned long size ); +//allocate a memory block of the given size and clear it +void *GetClearedHunkMemory( unsigned long size ); +#endif +#endif + +//free the given memory block +void FreeMemory( void *ptr ); +//prints the total used memory size +void PrintUsedMemorySize( void ); +//print all memory blocks with label +void PrintMemoryLabels( void ); +//returns the size of the memory block in bytes +int MemoryByteSize( void *ptr ); +//free all allocated memory +void DumpMemory( void ); diff --git a/Projects/Android/jni/rtcw/src/botlib/l_precomp.c b/Projects/Android/jni/rtcw/src/botlib/l_precomp.c new file mode 100644 index 0000000..2a77426 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/botlib/l_precomp.c @@ -0,0 +1,3229 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +// Copyright (C) 1999-2000 Id Software, Inc. +// + +/***************************************************************************** + * name: l_precomp.c + * + * desc: pre compiler + * + * + *****************************************************************************/ + +//Notes: fix: PC_StringizeTokens + +//#define SCREWUP +//#define BOTLIB +//#define QUAKE +//#define QUAKEC +//#define MEQCC + +#ifdef SCREWUP +#include +#include +#include +#include +#include +#include +#include "l_memory.h" +#include "l_script.h" +#include "l_precomp.h" + +typedef enum {qfalse, qtrue} qboolean; +#endif //SCREWUP + +#ifdef BOTLIB +#include "../game/q_shared.h" +#include "../game/botlib.h" +#include "be_interface.h" +#include "l_memory.h" +#include "l_script.h" +#include "l_precomp.h" +#include "l_log.h" +#endif //BOTLIB + +#ifdef MEQCC +#include "qcc.h" +#include "time.h" //time & ctime +#include "math.h" //fabs +#include "l_memory.h" +#include "l_script.h" +#include "l_precomp.h" +#include "l_log.h" + +#define qtrue true +#define qfalse false +#endif //MEQCC + +#ifdef BSPC +//include files for usage in the BSP Converter +#include "../bspc/qbsp.h" +#include "../bspc/l_log.h" +#include "../bspc/l_mem.h" +#include "l_precomp.h" + +#define qtrue true +#define qfalse false +#define Q_stricmp strcasecmp + +#define MAX_TOKENLENGTH 1024 + +#endif //BSPC + +#if defined( QUAKE ) && !defined( BSPC ) +#include "l_utils.h" +#endif //QUAKE + +//#define DEBUG_EVAL + +#define MAX_DEFINEPARMS 128 + +#define DEFINEHASHING 1 + +//directive name with parse function +typedef struct directive_s +{ + char *name; + int ( *func )( source_t *source ); +} directive_t; + +#define DEFINEHASHSIZE 1024 + +#define TOKEN_HEAP_SIZE 4096 + +int numtokens; +/* +int tokenheapinitialized; //true when the token heap is initialized +token_t token_heap[TOKEN_HEAP_SIZE]; //heap with tokens +token_t *freetokens; //free tokens from the heap +*/ + +//list with global defines added to every source loaded +define_t *globaldefines; + +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void QDECL SourceError( source_t *source, char *str, ... ) { + char text[1024]; + va_list ap; + + va_start( ap, str ); + vsprintf( text, str, ap ); + va_end( ap ); +#ifdef BOTLIB + botimport.Print( PRT_ERROR, "file %s, line %d: %s\n", source->scriptstack->filename, source->scriptstack->line, text ); +#endif //BOTLIB +#ifdef MEQCC + printf( "error: file %s, line %d: %s\n", source->scriptstack->filename, source->scriptstack->line, text ); +#endif //MEQCC +#ifdef BSPC + Log_Print( "error: file %s, line %d: %s\n", source->scriptstack->filename, source->scriptstack->line, text ); +#endif //BSPC +} //end of the function SourceError +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void QDECL SourceWarning( source_t *source, char *str, ... ) { + char text[1024]; + va_list ap; + + va_start( ap, str ); + vsprintf( text, str, ap ); + va_end( ap ); +#ifdef BOTLIB + botimport.Print( PRT_WARNING, "file %s, line %d: %s\n", source->scriptstack->filename, source->scriptstack->line, text ); +#endif //BOTLIB +#ifdef MEQCC + printf( "warning: file %s, line %d: %s\n", source->scriptstack->filename, source->scriptstack->line, text ); +#endif //MEQCC +#ifdef BSPC + Log_Print( "warning: file %s, line %d: %s\n", source->scriptstack->filename, source->scriptstack->line, text ); +#endif //BSPC +} //end of the function ScriptWarning +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void PC_PushIndent( source_t *source, int type, int skip ) { + indent_t *indent; + + indent = (indent_t *) GetMemory( sizeof( indent_t ) ); + indent->type = type; + indent->script = source->scriptstack; + indent->skip = ( skip != 0 ); + source->skip += indent->skip; + indent->next = source->indentstack; + source->indentstack = indent; +} //end of the function PC_PushIndent +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void PC_PopIndent( source_t *source, int *type, int *skip ) { + indent_t *indent; + + *type = 0; + *skip = 0; + + indent = source->indentstack; + if ( !indent ) { + return; + } + + //must be an indent from the current script + if ( source->indentstack->script != source->scriptstack ) { + return; + } + + *type = indent->type; + *skip = indent->skip; + source->indentstack = source->indentstack->next; + source->skip -= indent->skip; + FreeMemory( indent ); +} //end of the function PC_PopIndent +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void PC_PushScript( source_t *source, script_t *script ) { + script_t *s; + + for ( s = source->scriptstack; s; s = s->next ) + { + if ( !Q_stricmp( s->filename, script->filename ) ) { + SourceError( source, "%s recursively included", script->filename ); + return; + } //end if + } //end for + //push the script on the script stack + script->next = source->scriptstack; + source->scriptstack = script; +} //end of the function PC_PushScript +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void PC_InitTokenHeap( void ) { + /* + int i; + + if (tokenheapinitialized) return; + freetokens = NULL; + for (i = 0; i < TOKEN_HEAP_SIZE; i++) + { + token_heap[i].next = freetokens; + freetokens = &token_heap[i]; + } //end for + tokenheapinitialized = qtrue; + */ +} //end of the function PC_InitTokenHeap +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +token_t *PC_CopyToken( token_t *token ) { + token_t *t; + +// t = (token_t *) malloc(sizeof(token_t)); + t = (token_t *) GetMemory( sizeof( token_t ) ); +// t = freetokens; + if ( !t ) { +#ifdef BSPC + Error( "out of token space\n" ); +#else + Com_Error( ERR_FATAL, "out of token space\n" ); +#endif + return NULL; + } //end if +// freetokens = freetokens->next; + memcpy( t, token, sizeof( token_t ) ); + t->next = NULL; + numtokens++; + return t; +} //end of the function PC_CopyToken +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void PC_FreeToken( token_t *token ) { + //free(token); + FreeMemory( token ); +// token->next = freetokens; +// freetokens = token; + numtokens--; +} //end of the function PC_FreeToken +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_ReadSourceToken( source_t *source, token_t *token ) { + token_t *t; + script_t *script; + int type, skip; + + //if there's no token already available + while ( !source->tokens ) + { + //if there's a token to read from the script + if ( PS_ReadToken( source->scriptstack, token ) ) { + return qtrue; + } + //if at the end of the script + if ( EndOfScript( source->scriptstack ) ) { + //remove all indents of the script + while ( source->indentstack && + source->indentstack->script == source->scriptstack ) + { + SourceWarning( source, "missing #endif" ); + PC_PopIndent( source, &type, &skip ); + } //end if + } //end if + //if this was the initial script + if ( !source->scriptstack->next ) { + return qfalse; + } + //remove the script and return to the last one + script = source->scriptstack; + source->scriptstack = source->scriptstack->next; + FreeScript( script ); + } //end while + //copy the already available token + memcpy( token, source->tokens, sizeof( token_t ) ); + //free the read token + t = source->tokens; + source->tokens = source->tokens->next; + PC_FreeToken( t ); + return qtrue; +} //end of the function PC_ReadSourceToken +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_UnreadSourceToken( source_t *source, token_t *token ) { + token_t *t; + + t = PC_CopyToken( token ); + t->next = source->tokens; + source->tokens = t; + return qtrue; +} //end of the function PC_UnreadSourceToken +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_ReadDefineParms( source_t *source, define_t *define, token_t **parms, int maxparms ) { + token_t token, *t, *last; + int i, done, lastcomma, numparms, indent; + + if ( !PC_ReadSourceToken( source, &token ) ) { + SourceError( source, "define %s missing parms", define->name ); + return qfalse; + } //end if + // + if ( define->numparms > maxparms ) { + SourceError( source, "define with more than %d parameters", maxparms ); + return qfalse; + } //end if + // + for ( i = 0; i < define->numparms; i++ ) parms[i] = NULL; + //if no leading "(" + if ( strcmp( token.string, "(" ) ) { + PC_UnreadSourceToken( source, &token ); + SourceError( source, "define %s missing parms", define->name ); + return qfalse; + } //end if + //read the define parameters + for ( done = 0, numparms = 0, indent = 0; !done; ) + { + if ( numparms >= maxparms ) { + SourceError( source, "define %s with too many parms", define->name ); + return qfalse; + } //end if + if ( numparms >= define->numparms ) { + SourceWarning( source, "define %s has too many parms", define->name ); + return qfalse; + } //end if + parms[numparms] = NULL; + lastcomma = 1; + last = NULL; + while ( !done ) + { + // + if ( !PC_ReadSourceToken( source, &token ) ) { + SourceError( source, "define %s incomplete", define->name ); + return qfalse; + } //end if + // + if ( !strcmp( token.string, "," ) ) { + if ( indent <= 0 ) { + if ( lastcomma ) { + SourceWarning( source, "too many comma's" ); + } + lastcomma = 1; + break; + } //end if + } //end if + lastcomma = 0; + // + if ( !strcmp( token.string, "(" ) ) { + indent++; + continue; + } //end if + else if ( !strcmp( token.string, ")" ) ) { + if ( --indent <= 0 ) { + if ( !parms[define->numparms - 1] ) { + SourceWarning( source, "too few define parms" ); + } //end if + done = 1; + break; + } //end if + } //end if + // + if ( numparms < define->numparms ) { + // + t = PC_CopyToken( &token ); + t->next = NULL; + if ( last ) { + last->next = t; + } else { parms[numparms] = t;} + last = t; + } //end if + } //end while + numparms++; + } //end for + return qtrue; +} //end of the function PC_ReadDefineParms +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_StringizeTokens( token_t *tokens, token_t *token ) { + token_t *t; + + token->type = TT_STRING; + token->whitespace_p = NULL; + token->endwhitespace_p = NULL; + token->string[0] = '\0'; + strcat( token->string, "\"" ); + for ( t = tokens; t; t = t->next ) + { + strncat( token->string, t->string, MAX_TOKEN - strlen( token->string ) ); + } //end for + strncat( token->string, "\"", MAX_TOKEN - strlen( token->string ) ); + return qtrue; +} //end of the function PC_StringizeTokens +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_MergeTokens( token_t *t1, token_t *t2 ) { + //merging of a name with a name or number + if ( t1->type == TT_NAME && ( t2->type == TT_NAME || t2->type == TT_NUMBER ) ) { + strcat( t1->string, t2->string ); + return qtrue; + } //end if + //merging of two strings + if ( t1->type == TT_STRING && t2->type == TT_STRING ) { + //remove trailing double quote + t1->string[strlen( t1->string ) - 1] = '\0'; + //concat without leading double quote + strcat( t1->string, &t2->string[1] ); + return qtrue; + } //end if + //FIXME: merging of two number of the same sub type + return qfalse; +} //end of the function PC_MergeTokens +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +/* +void PC_PrintDefine(define_t *define) +{ + printf("define->name = %s\n", define->name); + printf("define->flags = %d\n", define->flags); + printf("define->builtin = %d\n", define->builtin); + printf("define->numparms = %d\n", define->numparms); +// token_t *parms; //define parameters +// token_t *tokens; //macro tokens (possibly containing parm tokens) +// struct define_s *next; //next defined macro in a list +} //end of the function PC_PrintDefine*/ +#if DEFINEHASHING +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void PC_PrintDefineHashTable( define_t **definehash ) { + int i; + define_t *d; + + for ( i = 0; i < DEFINEHASHSIZE; i++ ) + { + Log_Write( "%4d:", i ); + for ( d = definehash[i]; d; d = d->hashnext ) + { + Log_Write( " %s", d->name ); + } //end for + Log_Write( "\n" ); + } //end for +} //end of the function PC_PrintDefineHashTable +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +//char primes[16] = {1, 3, 5, 7, 11, 13, 17, 19, 23, 27, 29, 31, 37, 41, 43, 47}; + +int PC_NameHash( char *name ) { + int register hash, i; + + hash = 0; + for ( i = 0; name[i] != '\0'; i++ ) + { + hash += name[i] * ( 119 + i ); + //hash += (name[i] << 7) + i; + //hash += (name[i] << (i&15)); + } //end while + hash = ( hash ^ ( hash >> 10 ) ^ ( hash >> 20 ) ) & ( DEFINEHASHSIZE - 1 ); + return hash; +} //end of the function PC_NameHash +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void PC_AddDefineToHash( define_t *define, define_t **definehash ) { + int hash; + + hash = PC_NameHash( define->name ); + define->hashnext = definehash[hash]; + definehash[hash] = define; +} //end of the function PC_AddDefineToHash +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +define_t *PC_FindHashedDefine( define_t **definehash, char *name ) { + define_t *d; + int hash; + + hash = PC_NameHash( name ); + for ( d = definehash[hash]; d; d = d->hashnext ) + { + if ( !strcmp( d->name, name ) ) { + return d; + } + } //end for + return NULL; +} //end of the function PC_FindHashedDefine +#endif //DEFINEHASHING +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +define_t *PC_FindDefine( define_t *defines, char *name ) { + define_t *d; + + for ( d = defines; d; d = d->next ) + { + if ( !strcmp( d->name, name ) ) { + return d; + } + } //end for + return NULL; +} //end of the function PC_FindDefine +//============================================================================ +// +// Parameter: - +// Returns: number of the parm +// if no parm found with the given name -1 is returned +// Changes Globals: - +//============================================================================ +int PC_FindDefineParm( define_t *define, char *name ) { + token_t *p; + int i; + + i = 0; + for ( p = define->parms; p; p = p->next ) + { + if ( !strcmp( p->string, name ) ) { + return i; + } + i++; + } //end for + return -1; +} //end of the function PC_FindDefineParm +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void PC_FreeDefine( define_t *define ) { + token_t *t, *next; + + //free the define parameters + for ( t = define->parms; t; t = next ) + { + next = t->next; + PC_FreeToken( t ); + } //end for + //free the define tokens + for ( t = define->tokens; t; t = next ) + { + next = t->next; + PC_FreeToken( t ); + } //end for + //free the define + FreeMemory( define ); +} //end of the function PC_FreeDefine +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void PC_AddBuiltinDefines( source_t *source ) { + int i; + define_t *define; + struct builtin + { + char *string; + int builtin; + } builtin[] = { + { "__LINE__", BUILTIN_LINE }, + { "__FILE__", BUILTIN_FILE }, + { "__DATE__", BUILTIN_DATE }, + { "__TIME__", BUILTIN_TIME }, +// "__STDC__", BUILTIN_STDC, + { NULL, 0 } + }; + + for ( i = 0; builtin[i].string; i++ ) + { + define = (define_t *) GetMemory( sizeof( define_t ) + strlen( builtin[i].string ) + 1 ); + memset( define, 0, sizeof( define_t ) ); + define->name = (char *) define + sizeof( define_t ); + strcpy( define->name, builtin[i].string ); + define->flags |= DEFINE_FIXED; + define->builtin = builtin[i].builtin; + //add the define to the source +#if DEFINEHASHING + PC_AddDefineToHash( define, source->definehash ); +#else + define->next = source->defines; + source->defines = define; +#endif //DEFINEHASHING + } //end for +} //end of the function PC_AddBuiltinDefines +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_ExpandBuiltinDefine( source_t *source, token_t *deftoken, define_t *define, + token_t **firsttoken, token_t **lasttoken ) { + token_t *token; + unsigned long t; // time_t t; //to prevent LCC warning + char *curtime; + + token = PC_CopyToken( deftoken ); + switch ( define->builtin ) + { + case BUILTIN_LINE: + { + sprintf( token->string, "%d", deftoken->line ); +#ifdef NUMBERVALUE + token->intvalue = deftoken->line; + token->floatvalue = deftoken->line; +#endif //NUMBERVALUE + token->type = TT_NUMBER; + token->subtype = TT_DECIMAL | TT_INTEGER; + *firsttoken = token; + *lasttoken = token; + break; + } //end case + case BUILTIN_FILE: + { + strcpy( token->string, source->scriptstack->filename ); + token->type = TT_NAME; + token->subtype = strlen( token->string ); + *firsttoken = token; + *lasttoken = token; + break; + } //end case + case BUILTIN_DATE: + { + t = time( NULL ); + curtime = ctime( &t ); + strcpy( token->string, "\"" ); + strncat( token->string, curtime + 4, 7 ); + strncat( token->string + 7, curtime + 20, 4 ); + strcat( token->string, "\"" ); + free( curtime ); + token->type = TT_NAME; + token->subtype = strlen( token->string ); + *firsttoken = token; + *lasttoken = token; + break; + } //end case + case BUILTIN_TIME: + { + t = time( NULL ); + curtime = ctime( &t ); + strcpy( token->string, "\"" ); + strncat( token->string, curtime + 11, 8 ); + strcat( token->string, "\"" ); + free( curtime ); + token->type = TT_NAME; + token->subtype = strlen( token->string ); + *firsttoken = token; + *lasttoken = token; + break; + } //end case + case BUILTIN_STDC: + default: + { + *firsttoken = NULL; + *lasttoken = NULL; + break; + } //end case + } //end switch + return qtrue; +} //end of the function PC_ExpandBuiltinDefine +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_ExpandDefine( source_t *source, token_t *deftoken, define_t *define, + token_t **firsttoken, token_t **lasttoken ) { + token_t *parms[MAX_DEFINEPARMS], *dt, *pt, *t; + token_t *t1, *t2, *first, *last, *nextpt, token; + int parmnum, i; + + //if it is a builtin define + if ( define->builtin ) { + return PC_ExpandBuiltinDefine( source, deftoken, define, firsttoken, lasttoken ); + } //end if + //if the define has parameters + if ( define->numparms ) { + if ( !PC_ReadDefineParms( source, define, parms, MAX_DEFINEPARMS ) ) { + return qfalse; + } +#ifdef DEBUG_EVAL + for ( i = 0; i < define->numparms; i++ ) + { + Log_Write( "define parms %d:", i ); + for ( pt = parms[i]; pt; pt = pt->next ) + { + Log_Write( "%s", pt->string ); + } //end for + } //end for +#endif //DEBUG_EVAL + } //end if + //empty list at first + first = NULL; + last = NULL; + //create a list with tokens of the expanded define + for ( dt = define->tokens; dt; dt = dt->next ) + { + parmnum = -1; + //if the token is a name, it could be a define parameter + if ( dt->type == TT_NAME ) { + parmnum = PC_FindDefineParm( define, dt->string ); + } //end if + //if it is a define parameter + if ( parmnum >= 0 ) { + for ( pt = parms[parmnum]; pt; pt = pt->next ) + { + t = PC_CopyToken( pt ); + //add the token to the list + t->next = NULL; + if ( last ) { + last->next = t; + } else { first = t;} + last = t; + } //end for + } //end if + else + { + //if stringizing operator + if ( dt->string[0] == '#' && dt->string[1] == '\0' ) { + //the stringizing operator must be followed by a define parameter + if ( dt->next ) { + parmnum = PC_FindDefineParm( define, dt->next->string ); + } else { parmnum = -1;} + // + if ( parmnum >= 0 ) { + //step over the stringizing operator + dt = dt->next; + //stringize the define parameter tokens + if ( !PC_StringizeTokens( parms[parmnum], &token ) ) { + SourceError( source, "can't stringize tokens" ); + return qfalse; + } //end if + t = PC_CopyToken( &token ); + } //end if + else + { + SourceWarning( source, "stringizing operator without define parameter" ); + continue; + } //end if + } //end if + else + { + t = PC_CopyToken( dt ); + } //end else + //add the token to the list + t->next = NULL; + if ( last ) { + last->next = t; + } else { first = t;} + last = t; + } //end else + } //end for + //check for the merging operator + for ( t = first; t; ) + { + if ( t->next ) { + //if the merging operator + if ( t->next->string[0] == '#' && t->next->string[1] == '#' ) { + t1 = t; + t2 = t->next->next; + if ( t2 ) { + if ( !PC_MergeTokens( t1, t2 ) ) { + SourceError( source, "can't merge %s with %s", t1->string, t2->string ); + return qfalse; + } //end if + PC_FreeToken( t1->next ); + t1->next = t2->next; + if ( t2 == last ) { + last = t1; + } + PC_FreeToken( t2 ); + continue; + } //end if + } //end if + } //end if + t = t->next; + } //end for + //store the first and last token of the list + *firsttoken = first; + *lasttoken = last; + //free all the parameter tokens + for ( i = 0; i < define->numparms; i++ ) + { + for ( pt = parms[i]; pt; pt = nextpt ) + { + nextpt = pt->next; + PC_FreeToken( pt ); + } //end for + } //end for + // + return qtrue; +} //end of the function PC_ExpandDefine +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_ExpandDefineIntoSource( source_t *source, token_t *deftoken, define_t *define ) { + token_t *firsttoken, *lasttoken; + + if ( !PC_ExpandDefine( source, deftoken, define, &firsttoken, &lasttoken ) ) { + return qfalse; + } + + if ( firsttoken && lasttoken ) { + lasttoken->next = source->tokens; + source->tokens = firsttoken; + return qtrue; + } //end if + return qfalse; +} //end of the function PC_ExpandDefineIntoSource +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void PC_ConvertPath( char *path ) { + char *ptr; + + //remove double path seperators + for ( ptr = path; *ptr; ) + { + if ( ( *ptr == '\\' || *ptr == '/' ) && + ( *( ptr + 1 ) == '\\' || *( ptr + 1 ) == '/' ) ) { + strcpy( ptr, ptr + 1 ); + } //end if + else + { + ptr++; + } //end else + } //end while + //set OS dependent path seperators + for ( ptr = path; *ptr; ) + { + if ( *ptr == '/' || *ptr == '\\' ) { + *ptr = PATHSEPERATOR_CHAR; + } + ptr++; + } //end while +} //end of the function PC_ConvertPath +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_Directive_include( source_t *source ) { + script_t *script; + token_t token; + char path[_MAX_PATH]; +#ifdef QUAKE + foundfile_t file; +#endif //QUAKE + + if ( source->skip > 0 ) { + return qtrue; + } + // + if ( !PC_ReadSourceToken( source, &token ) ) { + SourceError( source, "#include without file name" ); + return qfalse; + } //end if + if ( token.linescrossed > 0 ) { + SourceError( source, "#include without file name" ); + return qfalse; + } //end if + if ( token.type == TT_STRING ) { + StripDoubleQuotes( token.string ); + PC_ConvertPath( token.string ); + script = LoadScriptFile( token.string ); + if ( !script ) { + strcpy( path, source->includepath ); + strcat( path, token.string ); + script = LoadScriptFile( path ); + } //end if + } //end if + else if ( token.type == TT_PUNCTUATION && *token.string == '<' ) { + strcpy( path, source->includepath ); + while ( PC_ReadSourceToken( source, &token ) ) + { + if ( token.linescrossed > 0 ) { + PC_UnreadSourceToken( source, &token ); + break; + } //end if + if ( token.type == TT_PUNCTUATION && *token.string == '>' ) { + break; + } + strncat( path, token.string, _MAX_PATH ); + } //end while + if ( *token.string != '>' ) { + SourceWarning( source, "#include missing trailing >" ); + } //end if + if ( !strlen( path ) ) { + SourceError( source, "#include without file name between < >" ); + return qfalse; + } //end if + PC_ConvertPath( path ); + script = LoadScriptFile( path ); + } //end if + else + { + SourceError( source, "#include without file name" ); + return qfalse; + } //end else +#ifdef QUAKE + if ( !script ) { + memset( &file, 0, sizeof( foundfile_t ) ); + script = LoadScriptFile( path ); + if ( script ) { + strncpy( script->filename, path, _MAX_PATH ); + } + } //end if +#endif //QUAKE + if ( !script ) { +#ifdef SCREWUP + SourceWarning( source, "file %s not found", path ); + return qtrue; +#else + SourceError( source, "file %s not found", path ); + return qfalse; +#endif //SCREWUP + } //end if + PC_PushScript( source, script ); + return qtrue; +} //end of the function PC_Directive_include +//============================================================================ +// reads a token from the current line, continues reading on the next +// line only if a backslash '\' is encountered. +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_ReadLine( source_t *source, token_t *token ) { + int crossline; + + crossline = 0; + do + { + if ( !PC_ReadSourceToken( source, token ) ) { + return qfalse; + } + + if ( token->linescrossed > crossline ) { + PC_UnreadSourceToken( source, token ); + return qfalse; + } //end if + crossline = 1; + } while ( !strcmp( token->string, "\\" ) ); + return qtrue; +} //end of the function PC_ReadLine +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_WhiteSpaceBeforeToken( token_t *token ) { + return token->endwhitespace_p - token->whitespace_p > 0; +} //end of the function PC_WhiteSpaceBeforeToken +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void PC_ClearTokenWhiteSpace( token_t *token ) { + token->whitespace_p = NULL; + token->endwhitespace_p = NULL; + token->linescrossed = 0; +} //end of the function PC_ClearTokenWhiteSpace +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_Directive_undef( source_t *source ) { + token_t token; + define_t *define, *lastdefine; + int hash; + + if ( source->skip > 0 ) { + return qtrue; + } + // + if ( !PC_ReadLine( source, &token ) ) { + SourceError( source, "undef without name" ); + return qfalse; + } //end if + if ( token.type != TT_NAME ) { + PC_UnreadSourceToken( source, &token ); + SourceError( source, "expected name, found %s", token.string ); + return qfalse; + } //end if +#if DEFINEHASHING + + hash = PC_NameHash( token.string ); + for ( lastdefine = NULL, define = source->definehash[hash]; define; define = define->hashnext ) + { + if ( !strcmp( define->name, token.string ) ) { + if ( define->flags & DEFINE_FIXED ) { + SourceWarning( source, "can't undef %s", token.string ); + } //end if + else + { + if ( lastdefine ) { + lastdefine->hashnext = define->hashnext; + } else { source->definehash[hash] = define->hashnext;} + PC_FreeDefine( define ); + } //end else + break; + } //end if + lastdefine = define; + } //end for +#else //DEFINEHASHING + for ( lastdefine = NULL, define = source->defines; define; define = define->next ) + { + if ( !strcmp( define->name, token.string ) ) { + if ( define->flags & DEFINE_FIXED ) { + SourceWarning( source, "can't undef %s", token.string ); + } //end if + else + { + if ( lastdefine ) { + lastdefine->next = define->next; + } else { source->defines = define->next;} + PC_FreeDefine( define ); + } //end else + break; + } //end if + lastdefine = define; + } //end for +#endif //DEFINEHASHING + return qtrue; +} //end of the function PC_Directive_undef +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_Directive_define( source_t *source ) { + token_t token, *t, *last; + define_t *define; + + if ( source->skip > 0 ) { + return qtrue; + } + // + if ( !PC_ReadLine( source, &token ) ) { + SourceError( source, "#define without name" ); + return qfalse; + } //end if + if ( token.type != TT_NAME ) { + PC_UnreadSourceToken( source, &token ); + SourceError( source, "expected name after #define, found %s", token.string ); + return qfalse; + } //end if + //check if the define already exists +#if DEFINEHASHING + define = PC_FindHashedDefine( source->definehash, token.string ); +#else + define = PC_FindDefine( source->defines, token.string ); +#endif //DEFINEHASHING + if ( define ) { + if ( define->flags & DEFINE_FIXED ) { + SourceError( source, "can't redefine %s", token.string ); + return qfalse; + } //end if + SourceWarning( source, "redefinition of %s", token.string ); + //unread the define name before executing the #undef directive + PC_UnreadSourceToken( source, &token ); + if ( !PC_Directive_undef( source ) ) { + return qfalse; + } + //if the define was not removed (define->flags & DEFINE_FIXED) +#if DEFINEHASHING + define = PC_FindHashedDefine( source->definehash, token.string ); +#else + define = PC_FindDefine( source->defines, token.string ); +#endif //DEFINEHASHING + } //end if + //allocate define + define = (define_t *) GetMemory( sizeof( define_t ) + strlen( token.string ) + 1 ); + memset( define, 0, sizeof( define_t ) ); + define->name = (char *) define + sizeof( define_t ); + strcpy( define->name, token.string ); + //add the define to the source +#if DEFINEHASHING + PC_AddDefineToHash( define, source->definehash ); +#else //DEFINEHASHING + define->next = source->defines; + source->defines = define; +#endif //DEFINEHASHING + //if nothing is defined, just return + if ( !PC_ReadLine( source, &token ) ) { + return qtrue; + } + //if it is a define with parameters + if ( !PC_WhiteSpaceBeforeToken( &token ) && !strcmp( token.string, "(" ) ) { + //read the define parameters + last = NULL; + if ( !PC_CheckTokenString( source, ")" ) ) { + while ( 1 ) + { + if ( !PC_ReadLine( source, &token ) ) { + SourceError( source, "expected define parameter" ); + return qfalse; + } //end if + //if it isn't a name + if ( token.type != TT_NAME ) { + SourceError( source, "invalid define parameter" ); + return qfalse; + } //end if + // + if ( PC_FindDefineParm( define, token.string ) >= 0 ) { + SourceError( source, "two the same define parameters" ); + return qfalse; + } //end if + //add the define parm + t = PC_CopyToken( &token ); + PC_ClearTokenWhiteSpace( t ); + t->next = NULL; + if ( last ) { + last->next = t; + } else { define->parms = t;} + last = t; + define->numparms++; + //read next token + if ( !PC_ReadLine( source, &token ) ) { + SourceError( source, "define parameters not terminated" ); + return qfalse; + } //end if + // + if ( !strcmp( token.string, ")" ) ) { + break; + } + //then it must be a comma + if ( strcmp( token.string, "," ) ) { + SourceError( source, "define not terminated" ); + return qfalse; + } //end if + } //end while + } //end if + if ( !PC_ReadLine( source, &token ) ) { + return qtrue; + } + } //end if + //read the defined stuff + last = NULL; + do + { + t = PC_CopyToken( &token ); + if ( t->type == TT_NAME && !strcmp( t->string, define->name ) ) { + SourceError( source, "recursive define (removed recursion)" ); + continue; + } //end if + PC_ClearTokenWhiteSpace( t ); + t->next = NULL; + if ( last ) { + last->next = t; + } else { define->tokens = t;} + last = t; + } while ( PC_ReadLine( source, &token ) ); + // + if ( last ) { + //check for merge operators at the beginning or end + if ( !strcmp( define->tokens->string, "##" ) || + !strcmp( last->string, "##" ) ) { + SourceError( source, "define with misplaced ##" ); + return qfalse; + } //end if + } //end if + return qtrue; +} //end of the function PC_Directive_define +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +define_t *PC_DefineFromString( char *string ) { + script_t *script; + source_t src; + token_t *t; + int res, i; + define_t *def; + + PC_InitTokenHeap(); + + script = LoadScriptMemory( string, strlen( string ), "*extern" ); + //create a new source + memset( &src, 0, sizeof( source_t ) ); + strncpy( src.filename, "*extern", _MAX_PATH ); + src.scriptstack = script; +#if DEFINEHASHING + src.definehash = GetClearedMemory( DEFINEHASHSIZE * sizeof( define_t * ) ); +#endif //DEFINEHASHING + //create a define from the source + res = PC_Directive_define( &src ); + //free any tokens if left + for ( t = src.tokens; t; t = src.tokens ) + { + src.tokens = src.tokens->next; + PC_FreeToken( t ); + } //end for +#ifdef DEFINEHASHING + def = NULL; + for ( i = 0; i < DEFINEHASHSIZE; i++ ) + { + if ( src.definehash[i] ) { + def = src.definehash[i]; + break; + } //end if + } //end for +#else + def = src.defines; +#endif //DEFINEHASHING + // +#if DEFINEHASHING + FreeMemory( src.definehash ); +#endif //DEFINEHASHING + // + FreeScript( script ); + //if the define was created succesfully + if ( res > 0 ) { + return def; + } + //free the define if created + if ( src.defines ) { + PC_FreeDefine( def ); + } + // + return NULL; +} //end of the function PC_DefineFromString +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_AddDefine( source_t *source, char *string ) { + define_t *define; + + define = PC_DefineFromString( string ); + if ( !define ) { + return qfalse; + } +#if DEFINEHASHING + PC_AddDefineToHash( define, source->definehash ); +#else //DEFINEHASHING + define->next = source->defines; + source->defines = define; +#endif //DEFINEHASHING + return qtrue; +} //end of the function PC_AddDefine +//============================================================================ +// add a globals define that will be added to all opened sources +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_AddGlobalDefine( char *string ) { + define_t *define; + + define = PC_DefineFromString( string ); + if ( !define ) { + return qfalse; + } + define->next = globaldefines; + globaldefines = define; + return qtrue; +} //end of the function PC_AddGlobalDefine +//============================================================================ +// remove the given global define +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_RemoveGlobalDefine( char *name ) { + define_t *define; + + define = PC_FindDefine( globaldefines, name ); + if ( define ) { + PC_FreeDefine( define ); + return qtrue; + } //end if + return qfalse; +} //end of the function PC_RemoveGlobalDefine +//============================================================================ +// remove all globals defines +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void PC_RemoveAllGlobalDefines( void ) { + define_t *define; + + for ( define = globaldefines; define; define = globaldefines ) + { + globaldefines = globaldefines->next; + PC_FreeDefine( define ); + } //end for +} //end of the function PC_RemoveAllGlobalDefines +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +define_t *PC_CopyDefine( source_t *source, define_t *define ) { + define_t *newdefine; + token_t *token, *newtoken, *lasttoken; + + newdefine = (define_t *) GetMemory( sizeof( define_t ) + strlen( define->name ) + 1 ); + //copy the define name + newdefine->name = (char *) newdefine + sizeof( define_t ); + strcpy( newdefine->name, define->name ); + newdefine->flags = define->flags; + newdefine->builtin = define->builtin; + newdefine->numparms = define->numparms; + //the define is not linked + newdefine->next = NULL; + newdefine->hashnext = NULL; + //copy the define tokens + newdefine->tokens = NULL; + for ( lasttoken = NULL, token = define->tokens; token; token = token->next ) + { + newtoken = PC_CopyToken( token ); + newtoken->next = NULL; + if ( lasttoken ) { + lasttoken->next = newtoken; + } else { newdefine->tokens = newtoken;} + lasttoken = newtoken; + } //end for + //copy the define parameters + newdefine->parms = NULL; + for ( lasttoken = NULL, token = define->parms; token; token = token->next ) + { + newtoken = PC_CopyToken( token ); + newtoken->next = NULL; + if ( lasttoken ) { + lasttoken->next = newtoken; + } else { newdefine->parms = newtoken;} + lasttoken = newtoken; + } //end for + return newdefine; +} //end of the function PC_CopyDefine +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void PC_AddGlobalDefinesToSource( source_t *source ) { + define_t *define, *newdefine; + + for ( define = globaldefines; define; define = define->next ) + { + newdefine = PC_CopyDefine( source, define ); +#if DEFINEHASHING + PC_AddDefineToHash( newdefine, source->definehash ); +#else //DEFINEHASHING + newdefine->next = source->defines; + source->defines = newdefine; +#endif //DEFINEHASHING + } //end for +} //end of the function PC_AddGlobalDefinesToSource +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_Directive_if_def( source_t *source, int type ) { + token_t token; + define_t *d; + int skip; + + if ( !PC_ReadLine( source, &token ) ) { + SourceError( source, "#ifdef without name" ); + return qfalse; + } //end if + if ( token.type != TT_NAME ) { + PC_UnreadSourceToken( source, &token ); + SourceError( source, "expected name after #ifdef, found %s", token.string ); + return qfalse; + } //end if +#if DEFINEHASHING + d = PC_FindHashedDefine( source->definehash, token.string ); +#else + d = PC_FindDefine( source->defines, token.string ); +#endif //DEFINEHASHING + skip = ( type == INDENT_IFDEF ) == ( d == NULL ); + PC_PushIndent( source, type, skip ); + return qtrue; +} //end of the function PC_Directiveif_def +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_Directive_ifdef( source_t *source ) { + return PC_Directive_if_def( source, INDENT_IFDEF ); +} //end of the function PC_Directive_ifdef +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_Directive_ifndef( source_t *source ) { + return PC_Directive_if_def( source, INDENT_IFNDEF ); +} //end of the function PC_Directive_ifndef +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_Directive_else( source_t *source ) { + int type, skip; + + PC_PopIndent( source, &type, &skip ); + if ( !type ) { + SourceError( source, "misplaced #else" ); + return qfalse; + } //end if + if ( type == INDENT_ELSE ) { + SourceError( source, "#else after #else" ); + return qfalse; + } //end if + PC_PushIndent( source, INDENT_ELSE, !skip ); + return qtrue; +} //end of the function PC_Directive_else +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_Directive_endif( source_t *source ) { + int type, skip; + + PC_PopIndent( source, &type, &skip ); + if ( !type ) { + SourceError( source, "misplaced #endif" ); + return qfalse; + } //end if + return qtrue; +} //end of the function PC_Directive_endif +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +typedef struct operator_s +{ + int operator; + int priority; + int parentheses; + struct operator_s *prev, *next; +} operator_t; + +typedef struct value_s +{ + signed long int intvalue; + double floatvalue; + int parentheses; + struct value_s *prev, *next; +} value_t; + +int PC_OperatorPriority( int op ) { + switch ( op ) + { + case P_MUL: return 15; + case P_DIV: return 15; + case P_MOD: return 15; + case P_ADD: return 14; + case P_SUB: return 14; + + case P_LOGIC_AND: return 7; + case P_LOGIC_OR: return 6; + case P_LOGIC_GEQ: return 12; + case P_LOGIC_LEQ: return 12; + case P_LOGIC_EQ: return 11; + case P_LOGIC_UNEQ: return 11; + + case P_LOGIC_NOT: return 16; + case P_LOGIC_GREATER: return 12; + case P_LOGIC_LESS: return 12; + + case P_RSHIFT: return 13; + case P_LSHIFT: return 13; + + case P_BIN_AND: return 10; + case P_BIN_OR: return 8; + case P_BIN_XOR: return 9; + case P_BIN_NOT: return 16; + + case P_COLON: return 5; + case P_QUESTIONMARK: return 5; + } //end switch + return qfalse; +} //end of the function PC_OperatorPriority + +//#define AllocValue() GetClearedMemory(sizeof(value_t)); +//#define FreeValue(val) FreeMemory(val) +//#define AllocOperator(op) op = (operator_t *) GetClearedMemory(sizeof(operator_t)); +//#define FreeOperator(op) FreeMemory(op); + +#define MAX_VALUES 64 +#define MAX_OPERATORS 64 +#define AllocValue( val ) \ + if ( numvalues >= MAX_VALUES ) { \ + SourceError( source, "out of value space\n" ); \ + error = 1; \ + break; \ + } \ + else { \ + val = &value_heap[numvalues++];} +#define FreeValue( val ) +// +#define AllocOperator( op ) \ + if ( numoperators >= MAX_OPERATORS ) { \ + SourceError( source, "out of operator space\n" ); \ + error = 1; \ + break; \ + } \ + else { \ + op = &operator_heap[numoperators++];} +#define FreeOperator( op ) + +int PC_EvaluateTokens( source_t *source, token_t *tokens, signed long int *intvalue, + double *floatvalue, int integer ) { + operator_t *o, *firstoperator, *lastoperator; + value_t *v, *firstvalue, *lastvalue, *v1, *v2; + token_t *t; + int brace = 0; + int parentheses = 0; + int error = 0; + int lastwasvalue = 0; + int negativevalue = 0; + int questmarkintvalue = 0; + double questmarkfloatvalue = 0; + int gotquestmarkvalue = qfalse; + int lastoperatortype = 0; + // + operator_t operator_heap[MAX_OPERATORS]; + int numoperators = 0; + value_t value_heap[MAX_VALUES]; + int numvalues = 0; + + firstoperator = lastoperator = NULL; + firstvalue = lastvalue = NULL; + if ( intvalue ) { + *intvalue = 0; + } + if ( floatvalue ) { + *floatvalue = 0; + } + for ( t = tokens; t; t = t->next ) + { + switch ( t->type ) + { + case TT_NAME: + { + if ( lastwasvalue || negativevalue ) { + SourceError( source, "syntax error in #if/#elif" ); + error = 1; + break; + } //end if + if ( strcmp( t->string, "defined" ) ) { + SourceError( source, "undefined name %s in #if/#elif", t->string ); + error = 1; + break; + } //end if + t = t->next; + if ( !strcmp( t->string, "(" ) ) { + brace = qtrue; + t = t->next; + } //end if + if ( !t || t->type != TT_NAME ) { + SourceError( source, "defined without name in #if/#elif" ); + error = 1; + break; + } //end if + //v = (value_t *) GetClearedMemory(sizeof(value_t)); + AllocValue( v ); +#if DEFINEHASHING + if ( PC_FindHashedDefine( source->definehash, t->string ) ) +#else + if ( PC_FindDefine( source->defines, t->string ) ) +#endif //DEFINEHASHING + { + v->intvalue = 1; + v->floatvalue = 1; + } //end if + else + { + v->intvalue = 0; + v->floatvalue = 0; + } //end else + v->parentheses = parentheses; + v->next = NULL; + v->prev = lastvalue; + if ( lastvalue ) { + lastvalue->next = v; + } else { firstvalue = v;} + lastvalue = v; + if ( brace ) { + t = t->next; + if ( !t || strcmp( t->string, ")" ) ) { + SourceError( source, "defined without ) in #if/#elif" ); + error = 1; + break; + } //end if + } //end if + brace = qfalse; + // defined() creates a value + lastwasvalue = 1; + break; + } //end case + case TT_NUMBER: + { + if ( lastwasvalue ) { + SourceError( source, "syntax error in #if/#elif" ); + error = 1; + break; + } //end if + //v = (value_t *) GetClearedMemory(sizeof(value_t)); + AllocValue( v ); + if ( negativevalue ) { + v->intvalue = -(signed int) t->intvalue; + v->floatvalue = -t->floatvalue; + } //end if + else + { + v->intvalue = t->intvalue; + v->floatvalue = t->floatvalue; + } //end else + v->parentheses = parentheses; + v->next = NULL; + v->prev = lastvalue; + if ( lastvalue ) { + lastvalue->next = v; + } else { firstvalue = v;} + lastvalue = v; + //last token was a value + lastwasvalue = 1; + // + negativevalue = 0; + break; + } //end case + case TT_PUNCTUATION: + { + if ( negativevalue ) { + SourceError( source, "misplaced minus sign in #if/#elif" ); + error = 1; + break; + } //end if + if ( t->subtype == P_PARENTHESESOPEN ) { + parentheses++; + break; + } //end if + else if ( t->subtype == P_PARENTHESESCLOSE ) { + parentheses--; + if ( parentheses < 0 ) { + SourceError( source, "too many ) in #if/#elsif" ); + error = 1; + } //end if + break; + } //end else if + //check for invalid operators on floating point values + if ( !integer ) { + if ( t->subtype == P_BIN_NOT || t->subtype == P_MOD || + t->subtype == P_RSHIFT || t->subtype == P_LSHIFT || + t->subtype == P_BIN_AND || t->subtype == P_BIN_OR || + t->subtype == P_BIN_XOR ) { + SourceError( source, "illigal operator %s on floating point operands\n", t->string ); + error = 1; + break; + } //end if + } //end if + switch ( t->subtype ) + { + case P_LOGIC_NOT: + case P_BIN_NOT: + { + if ( lastwasvalue ) { + SourceError( source, "! or ~ after value in #if/#elif" ); + error = 1; + break; + } //end if + break; + } //end case + case P_INC: + case P_DEC: + { + SourceError( source, "++ or -- used in #if/#elif" ); + break; + } //end case + case P_SUB: + { + if ( !lastwasvalue ) { + negativevalue = 1; + break; + } //end if + } //end case + + case P_MUL: + case P_DIV: + case P_MOD: + case P_ADD: + + case P_LOGIC_AND: + case P_LOGIC_OR: + case P_LOGIC_GEQ: + case P_LOGIC_LEQ: + case P_LOGIC_EQ: + case P_LOGIC_UNEQ: + + case P_LOGIC_GREATER: + case P_LOGIC_LESS: + + case P_RSHIFT: + case P_LSHIFT: + + case P_BIN_AND: + case P_BIN_OR: + case P_BIN_XOR: + + case P_COLON: + case P_QUESTIONMARK: + { + if ( !lastwasvalue ) { + SourceError( source, "operator %s after operator in #if/#elif", t->string ); + error = 1; + break; + } //end if + break; + } //end case + default: + { + SourceError( source, "invalid operator %s in #if/#elif", t->string ); + error = 1; + break; + } //end default + } //end switch + if ( !error && !negativevalue ) { + //o = (operator_t *) GetClearedMemory(sizeof(operator_t)); + AllocOperator( o ); + o->operator = t->subtype; + o->priority = PC_OperatorPriority( t->subtype ); + o->parentheses = parentheses; + o->next = NULL; + o->prev = lastoperator; + if ( lastoperator ) { + lastoperator->next = o; + } else { firstoperator = o;} + lastoperator = o; + lastwasvalue = 0; + } //end if + break; + } //end case + default: + { + SourceError( source, "unknown %s in #if/#elif", t->string ); + error = 1; + break; + } //end default + } //end switch + if ( error ) { + break; + } + } //end for + if ( !error ) { + if ( !lastwasvalue ) { + SourceError( source, "trailing operator in #if/#elif" ); + error = 1; + } //end if + else if ( parentheses ) { + SourceError( source, "too many ( in #if/#elif" ); + error = 1; + } //end else if + } //end if + // + gotquestmarkvalue = qfalse; + questmarkintvalue = 0; + questmarkfloatvalue = 0; + //while there are operators + while ( !error && firstoperator ) + { + v = firstvalue; + for ( o = firstoperator; o->next; o = o->next ) + { + //if the current operator is nested deeper in parentheses + //than the next operator + if ( o->parentheses > o->next->parentheses ) { + break; + } + //if the current and next operator are nested equally deep in parentheses + if ( o->parentheses == o->next->parentheses ) { + //if the priority of the current operator is equal or higher + //than the priority of the next operator + if ( o->priority >= o->next->priority ) { + break; + } + } //end if + //if the arity of the operator isn't equal to 1 + if ( o->operator != P_LOGIC_NOT + && o->operator != P_BIN_NOT ) { + v = v->next; + } + //if there's no value or no next value + if ( !v ) { + SourceError( source, "mising values in #if/#elif" ); + error = 1; + break; + } //end if + } //end for + if ( error ) { + break; + } + v1 = v; + v2 = v->next; +#ifdef DEBUG_EVAL + if ( integer ) { + Log_Write( "operator %s, value1 = %d", PunctuationFromNum( source->scriptstack, o->operator ), v1->intvalue ); + if ( v2 ) { + Log_Write( "value2 = %d", v2->intvalue ); + } + } //end if + else + { + Log_Write( "operator %s, value1 = %f", PunctuationFromNum( source->scriptstack, o->operator ), v1->floatvalue ); + if ( v2 ) { + Log_Write( "value2 = %f", v2->floatvalue ); + } + } //end else +#endif //DEBUG_EVAL + switch ( o->operator ) + { + case P_LOGIC_NOT: v1->intvalue = !v1->intvalue; + v1->floatvalue = !v1->floatvalue; break; + case P_BIN_NOT: v1->intvalue = ~v1->intvalue; + break; + case P_MUL: v1->intvalue *= v2->intvalue; + v1->floatvalue *= v2->floatvalue; break; + case P_DIV: if ( !v2->intvalue || !v2->floatvalue ) { + SourceError( source, "divide by zero in #if/#elif\n" ); + error = 1; + break; + } + v1->intvalue /= v2->intvalue; + v1->floatvalue /= v2->floatvalue; break; + case P_MOD: if ( !v2->intvalue ) { + SourceError( source, "divide by zero in #if/#elif\n" ); + error = 1; + break; + } + v1->intvalue %= v2->intvalue; break; + case P_ADD: v1->intvalue += v2->intvalue; + v1->floatvalue += v2->floatvalue; break; + case P_SUB: v1->intvalue -= v2->intvalue; + v1->floatvalue -= v2->floatvalue; break; + case P_LOGIC_AND: v1->intvalue = v1->intvalue && v2->intvalue; + v1->floatvalue = v1->floatvalue && v2->floatvalue; break; + case P_LOGIC_OR: v1->intvalue = v1->intvalue || v2->intvalue; + v1->floatvalue = v1->floatvalue || v2->floatvalue; break; + case P_LOGIC_GEQ: v1->intvalue = v1->intvalue >= v2->intvalue; + v1->floatvalue = v1->floatvalue >= v2->floatvalue; break; + case P_LOGIC_LEQ: v1->intvalue = v1->intvalue <= v2->intvalue; + v1->floatvalue = v1->floatvalue <= v2->floatvalue; break; + case P_LOGIC_EQ: v1->intvalue = v1->intvalue == v2->intvalue; + v1->floatvalue = v1->floatvalue == v2->floatvalue; break; + case P_LOGIC_UNEQ: v1->intvalue = v1->intvalue != v2->intvalue; + v1->floatvalue = v1->floatvalue != v2->floatvalue; break; + case P_LOGIC_GREATER: v1->intvalue = v1->intvalue > v2->intvalue; + v1->floatvalue = v1->floatvalue > v2->floatvalue; break; + case P_LOGIC_LESS: v1->intvalue = v1->intvalue < v2->intvalue; + v1->floatvalue = v1->floatvalue < v2->floatvalue; break; + case P_RSHIFT: v1->intvalue >>= v2->intvalue; + break; + case P_LSHIFT: v1->intvalue <<= v2->intvalue; + break; + case P_BIN_AND: v1->intvalue &= v2->intvalue; + break; + case P_BIN_OR: v1->intvalue |= v2->intvalue; + break; + case P_BIN_XOR: v1->intvalue ^= v2->intvalue; + break; + case P_COLON: + { + if ( !gotquestmarkvalue ) { + SourceError( source, ": without ? in #if/#elif" ); + error = 1; + break; + } //end if + if ( integer ) { + if ( !questmarkintvalue ) { + v1->intvalue = v2->intvalue; + } + } //end if + else + { + if ( !questmarkfloatvalue ) { + v1->floatvalue = v2->floatvalue; + } + } //end else + gotquestmarkvalue = qfalse; + break; + } //end case + case P_QUESTIONMARK: + { + if ( gotquestmarkvalue ) { + SourceError( source, "? after ? in #if/#elif" ); + error = 1; + break; + } //end if + questmarkintvalue = v1->intvalue; + questmarkfloatvalue = v1->floatvalue; + gotquestmarkvalue = qtrue; + break; + } //end if + } //end switch +#ifdef DEBUG_EVAL + if ( integer ) { + Log_Write( "result value = %d", v1->intvalue ); + } else { Log_Write( "result value = %f", v1->floatvalue );} +#endif //DEBUG_EVAL + if ( error ) { + break; + } + lastoperatortype = o->operator; + //if not an operator with arity 1 + if ( o->operator != P_LOGIC_NOT + && o->operator != P_BIN_NOT ) { + //remove the second value if not question mark operator + if ( o->operator != P_QUESTIONMARK ) { + v = v->next; + } + // + if ( v->prev ) { + v->prev->next = v->next; + } else { firstvalue = v->next;} + if ( v->next ) { + v->next->prev = v->prev; + } else { lastvalue = v->prev;} + //FreeMemory(v); + FreeValue( v ); + } //end if + //remove the operator + if ( o->prev ) { + o->prev->next = o->next; + } else { firstoperator = o->next;} + if ( o->next ) { + o->next->prev = o->prev; + } else { lastoperator = o->prev;} + //FreeMemory(o); + FreeOperator( o ); + } //end while + if ( firstvalue ) { + if ( intvalue ) { + *intvalue = firstvalue->intvalue; + } + if ( floatvalue ) { + *floatvalue = firstvalue->floatvalue; + } + } //end if + for ( o = firstoperator; o; o = lastoperator ) + { + lastoperator = o->next; + //FreeMemory(o); + FreeOperator( o ); + } //end for + for ( v = firstvalue; v; v = lastvalue ) + { + lastvalue = v->next; + //FreeMemory(v); + FreeValue( v ); + } //end for + if ( !error ) { + return qtrue; + } + if ( intvalue ) { + *intvalue = 0; + } + if ( floatvalue ) { + *floatvalue = 0; + } + return qfalse; +} //end of the function PC_EvaluateTokens +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_Evaluate( source_t *source, signed long int *intvalue, + double *floatvalue, int integer ) { + token_t token, *firsttoken, *lasttoken; + token_t *t, *nexttoken; + define_t *define; + int defined = qfalse; + + if ( intvalue ) { + *intvalue = 0; + } + if ( floatvalue ) { + *floatvalue = 0; + } + // + if ( !PC_ReadLine( source, &token ) ) { + SourceError( source, "no value after #if/#elif" ); + return qfalse; + } //end if + firsttoken = NULL; + lasttoken = NULL; + do + { + //if the token is a name + if ( token.type == TT_NAME ) { + if ( defined ) { + defined = qfalse; + t = PC_CopyToken( &token ); + t->next = NULL; + if ( lasttoken ) { + lasttoken->next = t; + } else { firsttoken = t;} + lasttoken = t; + } //end if + else if ( !strcmp( token.string, "defined" ) ) { + defined = qtrue; + t = PC_CopyToken( &token ); + t->next = NULL; + if ( lasttoken ) { + lasttoken->next = t; + } else { firsttoken = t;} + lasttoken = t; + } //end if + else + { + //then it must be a define +#if DEFINEHASHING + define = PC_FindHashedDefine( source->definehash, token.string ); +#else + define = PC_FindDefine( source->defines, token.string ); +#endif //DEFINEHASHING + if ( !define ) { + SourceError( source, "can't evaluate %s, not defined", token.string ); + return qfalse; + } //end if + if ( !PC_ExpandDefineIntoSource( source, &token, define ) ) { + return qfalse; + } + } //end else + } //end if + //if the token is a number or a punctuation + else if ( token.type == TT_NUMBER || token.type == TT_PUNCTUATION ) { + t = PC_CopyToken( &token ); + t->next = NULL; + if ( lasttoken ) { + lasttoken->next = t; + } else { firsttoken = t;} + lasttoken = t; + } //end else + else //can't evaluate the token + { + SourceError( source, "can't evaluate %s", token.string ); + return qfalse; + } //end else + } while ( PC_ReadLine( source, &token ) ); + // + if ( !PC_EvaluateTokens( source, firsttoken, intvalue, floatvalue, integer ) ) { + return qfalse; + } + // +#ifdef DEBUG_EVAL + Log_Write( "eval:" ); +#endif //DEBUG_EVAL + for ( t = firsttoken; t; t = nexttoken ) + { +#ifdef DEBUG_EVAL + Log_Write( " %s", t->string ); +#endif //DEBUG_EVAL + nexttoken = t->next; + PC_FreeToken( t ); + } //end for +#ifdef DEBUG_EVAL + if ( integer ) { + Log_Write( "eval result: %d", *intvalue ); + } else { Log_Write( "eval result: %f", *floatvalue );} +#endif //DEBUG_EVAL + // + return qtrue; +} //end of the function PC_Evaluate +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_DollarEvaluate( source_t *source, signed long int *intvalue, + double *floatvalue, int integer ) { + int indent, defined = qfalse; + token_t token, *firsttoken, *lasttoken; + token_t *t, *nexttoken; + define_t *define; + + if ( intvalue ) { + *intvalue = 0; + } + if ( floatvalue ) { + *floatvalue = 0; + } + // + if ( !PC_ReadSourceToken( source, &token ) ) { + SourceError( source, "no leading ( after $evalint/$evalfloat" ); + return qfalse; + } //end if + if ( !PC_ReadSourceToken( source, &token ) ) { + SourceError( source, "nothing to evaluate" ); + return qfalse; + } //end if + indent = 1; + firsttoken = NULL; + lasttoken = NULL; + do + { + //if the token is a name + if ( token.type == TT_NAME ) { + if ( defined ) { + defined = qfalse; + t = PC_CopyToken( &token ); + t->next = NULL; + if ( lasttoken ) { + lasttoken->next = t; + } else { firsttoken = t;} + lasttoken = t; + } //end if + else if ( !strcmp( token.string, "defined" ) ) { + defined = qtrue; + t = PC_CopyToken( &token ); + t->next = NULL; + if ( lasttoken ) { + lasttoken->next = t; + } else { firsttoken = t;} + lasttoken = t; + } //end if + else + { + //then it must be a define +#if DEFINEHASHING + define = PC_FindHashedDefine( source->definehash, token.string ); +#else + define = PC_FindDefine( source->defines, token.string ); +#endif //DEFINEHASHING + if ( !define ) { + SourceError( source, "can't evaluate %s, not defined", token.string ); + return qfalse; + } //end if + if ( !PC_ExpandDefineIntoSource( source, &token, define ) ) { + return qfalse; + } + } //end else + } //end if + //if the token is a number or a punctuation + else if ( token.type == TT_NUMBER || token.type == TT_PUNCTUATION ) { + if ( *token.string == '(' ) { + indent++; + } else if ( *token.string == ')' ) { + indent--; + } + if ( indent <= 0 ) { + break; + } + t = PC_CopyToken( &token ); + t->next = NULL; + if ( lasttoken ) { + lasttoken->next = t; + } else { firsttoken = t;} + lasttoken = t; + } //end else + else //can't evaluate the token + { + SourceError( source, "can't evaluate %s", token.string ); + return qfalse; + } //end else + } while ( PC_ReadSourceToken( source, &token ) ); + // + if ( !PC_EvaluateTokens( source, firsttoken, intvalue, floatvalue, integer ) ) { + return qfalse; + } + // +#ifdef DEBUG_EVAL + Log_Write( "$eval:" ); +#endif //DEBUG_EVAL + for ( t = firsttoken; t; t = nexttoken ) + { +#ifdef DEBUG_EVAL + Log_Write( " %s", t->string ); +#endif //DEBUG_EVAL + nexttoken = t->next; + PC_FreeToken( t ); + } //end for +#ifdef DEBUG_EVAL + if ( integer ) { + Log_Write( "$eval result: %d", *intvalue ); + } else { Log_Write( "$eval result: %f", *floatvalue );} +#endif //DEBUG_EVAL + // + return qtrue; +} //end of the function PC_DollarEvaluate +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_Directive_elif( source_t *source ) { + signed long int value; + int type, skip; + + PC_PopIndent( source, &type, &skip ); + if ( !type || type == INDENT_ELSE ) { + SourceError( source, "misplaced #elif" ); + return qfalse; + } //end if + if ( !PC_Evaluate( source, &value, NULL, qtrue ) ) { + return qfalse; + } + skip = ( value == 0 ); + PC_PushIndent( source, INDENT_ELIF, skip ); + return qtrue; +} //end of the function PC_Directive_elif +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_Directive_if( source_t *source ) { + signed long int value; + int skip; + + if ( !PC_Evaluate( source, &value, NULL, qtrue ) ) { + return qfalse; + } + skip = ( value == 0 ); + PC_PushIndent( source, INDENT_IF, skip ); + return qtrue; +} //end of the function PC_Directive +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_Directive_line( source_t *source ) { + SourceError( source, "#line directive not supported" ); + return qfalse; +} //end of the function PC_Directive_line +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_Directive_error( source_t *source ) { + token_t token; + + strcpy( token.string, "" ); + PC_ReadSourceToken( source, &token ); + SourceError( source, "#error directive: %s", token.string ); + return qfalse; +} //end of the function PC_Directive_error +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_Directive_pragma( source_t *source ) { + token_t token; + + SourceWarning( source, "#pragma directive not supported" ); + while ( PC_ReadLine( source, &token ) ) ; + return qtrue; +} //end of the function PC_Directive_pragma +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void UnreadSignToken( source_t *source ) { + token_t token; + + token.line = source->scriptstack->line; + token.whitespace_p = source->scriptstack->script_p; + token.endwhitespace_p = source->scriptstack->script_p; + token.linescrossed = 0; + strcpy( token.string, "-" ); + token.type = TT_PUNCTUATION; + token.subtype = P_SUB; + PC_UnreadSourceToken( source, &token ); +} //end of the function UnreadSignToken +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_Directive_eval( source_t *source ) { + signed long int value; + token_t token; + + if ( !PC_Evaluate( source, &value, NULL, qtrue ) ) { + return qfalse; + } + // + token.line = source->scriptstack->line; + token.whitespace_p = source->scriptstack->script_p; + token.endwhitespace_p = source->scriptstack->script_p; + token.linescrossed = 0; + sprintf( token.string, "%d", abs( value ) ); + token.type = TT_NUMBER; + token.subtype = TT_INTEGER | TT_LONG | TT_DECIMAL; + PC_UnreadSourceToken( source, &token ); + if ( value < 0 ) { + UnreadSignToken( source ); + } + return qtrue; +} //end of the function PC_Directive_eval +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_Directive_evalfloat( source_t *source ) { + double value; + token_t token; + + if ( !PC_Evaluate( source, NULL, &value, qfalse ) ) { + return qfalse; + } + token.line = source->scriptstack->line; + token.whitespace_p = source->scriptstack->script_p; + token.endwhitespace_p = source->scriptstack->script_p; + token.linescrossed = 0; + sprintf( token.string, "%1.2f", fabs( value ) ); + token.type = TT_NUMBER; + token.subtype = TT_FLOAT | TT_LONG | TT_DECIMAL; + PC_UnreadSourceToken( source, &token ); + if ( value < 0 ) { + UnreadSignToken( source ); + } + return qtrue; +} //end of the function PC_Directive_evalfloat +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +directive_t directives[20] = +{ + {"if", PC_Directive_if}, + {"ifdef", PC_Directive_ifdef}, + {"ifndef", PC_Directive_ifndef}, + {"elif", PC_Directive_elif}, + {"else", PC_Directive_else}, + {"endif", PC_Directive_endif}, + {"include", PC_Directive_include}, + {"define", PC_Directive_define}, + {"undef", PC_Directive_undef}, + {"line", PC_Directive_line}, + {"error", PC_Directive_error}, + {"pragma", PC_Directive_pragma}, + {"eval", PC_Directive_eval}, + {"evalfloat", PC_Directive_evalfloat}, + {NULL, NULL} +}; + +int PC_ReadDirective( source_t *source ) { + token_t token; + int i; + + //read the directive name + if ( !PC_ReadSourceToken( source, &token ) ) { + SourceError( source, "found # without name" ); + return qfalse; + } //end if + //directive name must be on the same line + if ( token.linescrossed > 0 ) { + PC_UnreadSourceToken( source, &token ); + SourceError( source, "found # at end of line" ); + return qfalse; + } //end if + //if if is a name + if ( token.type == TT_NAME ) { + //find the precompiler directive + for ( i = 0; directives[i].name; i++ ) + { + if ( !strcmp( directives[i].name, token.string ) ) { + return directives[i].func( source ); + } //end if + } //end for + } //end if + SourceError( source, "unknown precompiler directive %s", token.string ); + return qfalse; +} //end of the function PC_ReadDirective +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_DollarDirective_evalint( source_t *source ) { + signed long int value; + token_t token; + + if ( !PC_DollarEvaluate( source, &value, NULL, qtrue ) ) { + return qfalse; + } + // + token.line = source->scriptstack->line; + token.whitespace_p = source->scriptstack->script_p; + token.endwhitespace_p = source->scriptstack->script_p; + token.linescrossed = 0; + sprintf( token.string, "%d", abs( value ) ); + token.type = TT_NUMBER; + token.subtype = TT_INTEGER | TT_LONG | TT_DECIMAL; +#ifdef NUMBERVALUE + token.intvalue = value; + token.floatvalue = value; +#endif //NUMBERVALUE + PC_UnreadSourceToken( source, &token ); + if ( value < 0 ) { + UnreadSignToken( source ); + } + return qtrue; +} //end of the function PC_DollarDirective_evalint +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_DollarDirective_evalfloat( source_t *source ) { + double value; + token_t token; + + if ( !PC_DollarEvaluate( source, NULL, &value, qfalse ) ) { + return qfalse; + } + token.line = source->scriptstack->line; + token.whitespace_p = source->scriptstack->script_p; + token.endwhitespace_p = source->scriptstack->script_p; + token.linescrossed = 0; + sprintf( token.string, "%1.2f", fabs( value ) ); + token.type = TT_NUMBER; + token.subtype = TT_FLOAT | TT_LONG | TT_DECIMAL; +#ifdef NUMBERVALUE + token.intvalue = (unsigned long) value; + token.floatvalue = value; +#endif //NUMBERVALUE + PC_UnreadSourceToken( source, &token ); + if ( value < 0 ) { + UnreadSignToken( source ); + } + return qtrue; +} //end of the function PC_DollarDirective_evalfloat +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +directive_t dollardirectives[20] = +{ + {"evalint", PC_DollarDirective_evalint}, + {"evalfloat", PC_DollarDirective_evalfloat}, + {NULL, NULL} +}; + +int PC_ReadDollarDirective( source_t *source ) { + token_t token; + int i; + + //read the directive name + if ( !PC_ReadSourceToken( source, &token ) ) { + SourceError( source, "found $ without name" ); + return qfalse; + } //end if + //directive name must be on the same line + if ( token.linescrossed > 0 ) { + PC_UnreadSourceToken( source, &token ); + SourceError( source, "found $ at end of line" ); + return qfalse; + } //end if + //if if is a name + if ( token.type == TT_NAME ) { + //find the precompiler directive + for ( i = 0; dollardirectives[i].name; i++ ) + { + if ( !strcmp( dollardirectives[i].name, token.string ) ) { + return dollardirectives[i].func( source ); + } //end if + } //end for + } //end if + PC_UnreadSourceToken( source, &token ); + SourceError( source, "unknown precompiler directive %s", token.string ); + return qfalse; +} //end of the function PC_ReadDirective + +#ifdef QUAKEC +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int BuiltinFunction( source_t *source ) { + token_t token; + + if ( !PC_ReadSourceToken( source, &token ) ) { + return qfalse; + } + if ( token.type == TT_NUMBER ) { + PC_UnreadSourceToken( source, &token ); + return qtrue; + } //end if + else + { + PC_UnreadSourceToken( source, &token ); + return qfalse; + } //end else +} //end of the function BuiltinFunction +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int QuakeCMacro( source_t *source ) { + int i; + token_t token; + + if ( !PC_ReadSourceToken( source, &token ) ) { + return qtrue; + } + if ( token.type != TT_NAME ) { + PC_UnreadSourceToken( source, &token ); + return qtrue; + } //end if + //find the precompiler directive + for ( i = 0; dollardirectives[i].name; i++ ) + { + if ( !strcmp( dollardirectives[i].name, token.string ) ) { + PC_UnreadSourceToken( source, &token ); + return qfalse; + } //end if + } //end for + PC_UnreadSourceToken( source, &token ); + return qtrue; +} //end of the function QuakeCMacro +#endif //QUAKEC +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_ReadToken( source_t *source, token_t *token ) { + define_t *define; + + while ( 1 ) + { + if ( !PC_ReadSourceToken( source, token ) ) { + return qfalse; + } + //check for precompiler directives + if ( token->type == TT_PUNCTUATION && *token->string == '#' ) { +#ifdef QUAKEC + if ( !BuiltinFunction( source ) ) +#endif //QUAKC + { + //read the precompiler directive + if ( !PC_ReadDirective( source ) ) { + return qfalse; + } + continue; + } //end if + } //end if + if ( token->type == TT_PUNCTUATION && *token->string == '$' ) { +#ifdef QUAKEC + if ( !QuakeCMacro( source ) ) +#endif //QUAKEC + { + //read the precompiler directive + if ( !PC_ReadDollarDirective( source ) ) { + return qfalse; + } + continue; + } //end if + } //end if + // recursively concatenate strings that are behind each other still resolving defines + if ( token->type == TT_STRING ) { + token_t newtoken; + if ( PC_ReadToken( source, &newtoken ) ) { + if ( newtoken.type == TT_STRING ) { + token->string[strlen( token->string ) - 1] = '\0'; + if ( strlen( token->string ) + strlen( newtoken.string + 1 ) + 1 >= MAX_TOKEN ) { + SourceError( source, "string longer than MAX_TOKEN %d\n", MAX_TOKEN ); + return qfalse; + } + strcat( token->string, newtoken.string + 1 ); + } else + { + PC_UnreadToken( source, &newtoken ); + } + } + } //end if + //if skipping source because of conditional compilation + if ( source->skip ) { + continue; + } + //if the token is a name + if ( token->type == TT_NAME ) { + //check if the name is a define macro +#if DEFINEHASHING + define = PC_FindHashedDefine( source->definehash, token->string ); +#else + define = PC_FindDefine( source->defines, token->string ); +#endif //DEFINEHASHING + //if it is a define macro + if ( define ) { + //expand the defined macro + if ( !PC_ExpandDefineIntoSource( source, token, define ) ) { + return qfalse; + } + continue; + } //end if + } //end if + //copy token for unreading + memcpy( &source->token, token, sizeof( token_t ) ); + //found a token + return qtrue; + } //end while +} //end of the function PC_ReadToken +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_ExpectTokenString( source_t *source, char *string ) { + token_t token; + + if ( !PC_ReadToken( source, &token ) ) { + SourceError( source, "couldn't find expected %s", string ); + return qfalse; + } //end if + + if ( strcmp( token.string, string ) ) { + SourceError( source, "expected %s, found %s", string, token.string ); + return qfalse; + } //end if + return qtrue; +} //end of the function PC_ExpectTokenString +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_ExpectTokenType( source_t *source, int type, int subtype, token_t *token ) { + char str[MAX_TOKEN]; + + if ( !PC_ReadToken( source, token ) ) { + SourceError( source, "couldn't read expected token" ); + return qfalse; + } //end if + + if ( token->type != type ) { + strcpy( str, "" ); + if ( type == TT_STRING ) { + strcpy( str, "string" ); + } + if ( type == TT_LITERAL ) { + strcpy( str, "literal" ); + } + if ( type == TT_NUMBER ) { + strcpy( str, "number" ); + } + if ( type == TT_NAME ) { + strcpy( str, "name" ); + } + if ( type == TT_PUNCTUATION ) { + strcpy( str, "punctuation" ); + } + SourceError( source, "expected a %s, found %s", str, token->string ); + return qfalse; + } //end if + if ( token->type == TT_NUMBER ) { + if ( ( token->subtype & subtype ) != subtype ) { + if ( subtype & TT_DECIMAL ) { + strcpy( str, "decimal" ); + } + if ( subtype & TT_HEX ) { + strcpy( str, "hex" ); + } + if ( subtype & TT_OCTAL ) { + strcpy( str, "octal" ); + } + if ( subtype & TT_BINARY ) { + strcpy( str, "binary" ); + } + if ( subtype & TT_LONG ) { + strcat( str, " long" ); + } + if ( subtype & TT_UNSIGNED ) { + strcat( str, " unsigned" ); + } + if ( subtype & TT_FLOAT ) { + strcat( str, " float" ); + } + if ( subtype & TT_INTEGER ) { + strcat( str, " integer" ); + } + SourceError( source, "expected %s, found %s", str, token->string ); + return qfalse; + } //end if + } //end if + else if ( token->type == TT_PUNCTUATION ) { + if ( token->subtype != subtype ) { + SourceError( source, "found %s", token->string ); + return qfalse; + } //end if + } //end else if + return qtrue; +} //end of the function PC_ExpectTokenType +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_ExpectAnyToken( source_t *source, token_t *token ) { + if ( !PC_ReadToken( source, token ) ) { + SourceError( source, "couldn't read expected token" ); + return qfalse; + } //end if + else + { + return qtrue; + } //end else +} //end of the function PC_ExpectAnyToken +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_CheckTokenString( source_t *source, char *string ) { + token_t tok; + + if ( !PC_ReadToken( source, &tok ) ) { + return qfalse; + } + //if the token is available + if ( !strcmp( tok.string, string ) ) { + return qtrue; + } + // + PC_UnreadSourceToken( source, &tok ); + return qfalse; +} //end of the function PC_CheckTokenString +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_CheckTokenType( source_t *source, int type, int subtype, token_t *token ) { + token_t tok; + + if ( !PC_ReadToken( source, &tok ) ) { + return qfalse; + } + //if the type matches + if ( tok.type == type && + ( tok.subtype & subtype ) == subtype ) { + memcpy( token, &tok, sizeof( token_t ) ); + return qtrue; + } //end if + // + PC_UnreadSourceToken( source, &tok ); + return qfalse; +} //end of the function PC_CheckTokenType +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_SkipUntilString( source_t *source, char *string ) { + token_t token; + + while ( PC_ReadToken( source, &token ) ) + { + if ( !strcmp( token.string, string ) ) { + return qtrue; + } + } //end while + return qfalse; +} //end of the function PC_SkipUntilString +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void PC_UnreadLastToken( source_t *source ) { + PC_UnreadSourceToken( source, &source->token ); +} //end of the function PC_UnreadLastToken +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void PC_UnreadToken( source_t *source, token_t *token ) { + PC_UnreadSourceToken( source, token ); +} //end of the function PC_UnreadToken +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void PC_SetIncludePath( source_t *source, char *path ) { + strncpy( source->includepath, path, _MAX_PATH ); + //add trailing path seperator + if ( source->includepath[strlen( source->includepath ) - 1] != '\\' && + source->includepath[strlen( source->includepath ) - 1] != '/' ) { + strcat( source->includepath, PATHSEPERATOR_STR ); + } //end if +} //end of the function PC_SetIncludePath +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void PC_SetPunctuations( source_t *source, punctuation_t *p ) { + source->punctuations = p; +} //end of the function PC_SetPunctuations +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +source_t *LoadSourceFile( const char *filename ) { + source_t *source; + script_t *script; + + PC_InitTokenHeap(); + + script = LoadScriptFile( filename ); + if ( !script ) { + return NULL; + } + + script->next = NULL; + + source = (source_t *) GetMemory( sizeof( source_t ) ); + memset( source, 0, sizeof( source_t ) ); + + strncpy( source->filename, filename, _MAX_PATH ); + source->scriptstack = script; + source->tokens = NULL; + source->defines = NULL; + source->indentstack = NULL; + source->skip = 0; + +#if DEFINEHASHING + source->definehash = GetClearedMemory( DEFINEHASHSIZE * sizeof( define_t * ) ); +#endif //DEFINEHASHING + PC_AddGlobalDefinesToSource( source ); + return source; +} //end of the function LoadSourceFile +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +source_t *LoadSourceMemory( char *ptr, int length, char *name ) { + source_t *source; + script_t *script; + + PC_InitTokenHeap(); + + script = LoadScriptMemory( ptr, length, name ); + if ( !script ) { + return NULL; + } + script->next = NULL; + + source = (source_t *) GetMemory( sizeof( source_t ) ); + memset( source, 0, sizeof( source_t ) ); + + strncpy( source->filename, name, _MAX_PATH ); + source->scriptstack = script; + source->tokens = NULL; + source->defines = NULL; + source->indentstack = NULL; + source->skip = 0; + +#if DEFINEHASHING + source->definehash = GetClearedMemory( DEFINEHASHSIZE * sizeof( define_t * ) ); +#endif //DEFINEHASHING + PC_AddGlobalDefinesToSource( source ); + return source; +} //end of the function LoadSourceMemory +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void FreeSource( source_t *source ) { + script_t *script; + token_t *token; + define_t *define; + indent_t *indent; + int i; + + //PC_PrintDefineHashTable(source->definehash); + //free all the scripts + while ( source->scriptstack ) + { + script = source->scriptstack; + source->scriptstack = source->scriptstack->next; + FreeScript( script ); + } //end for + //free all the tokens + while ( source->tokens ) + { + token = source->tokens; + source->tokens = source->tokens->next; + PC_FreeToken( token ); + } //end for +#if DEFINEHASHING + for ( i = 0; i < DEFINEHASHSIZE; i++ ) + { + while ( source->definehash[i] ) + { + define = source->definehash[i]; + source->definehash[i] = source->definehash[i]->hashnext; + PC_FreeDefine( define ); + } //end while + } //end for +#else //DEFINEHASHING + //free all defines + while ( source->defines ) + { + define = source->defines; + source->defines = source->defines->next; + PC_FreeDefine( define ); + } //end for +#endif //DEFINEHASHING + //free all indents + while ( source->indentstack ) + { + indent = source->indentstack; + source->indentstack = source->indentstack->next; + FreeMemory( indent ); + } //end for +#if DEFINEHASHING + // + if ( source->definehash ) { + FreeMemory( source->definehash ); + } +#endif //DEFINEHASHING + //free the source itself + FreeMemory( source ); +} //end of the function FreeSource +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ + +#define MAX_SOURCEFILES 64 + +source_t *sourceFiles[MAX_SOURCEFILES]; + +int PC_LoadSourceHandle( const char *filename ) { + source_t *source; + int i; + + for ( i = 1; i < MAX_SOURCEFILES; i++ ) + { + if ( !sourceFiles[i] ) { + break; + } + } //end for + if ( i >= MAX_SOURCEFILES ) { + return 0; + } + PS_SetBaseFolder( "" ); + source = LoadSourceFile( filename ); + if ( !source ) { + return 0; + } + sourceFiles[i] = source; + return i; +} //end of the function PC_LoadSourceHandle +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_FreeSourceHandle( int handle ) { + if ( handle < 1 || handle >= MAX_SOURCEFILES ) { + return qfalse; + } + if ( !sourceFiles[handle] ) { + return qfalse; + } + + FreeSource( sourceFiles[handle] ); + sourceFiles[handle] = NULL; + return qtrue; +} //end of the function PC_FreeSourceHandle +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_ReadTokenHandle( int handle, pc_token_t *pc_token ) { + token_t token; + int ret; + + if ( handle < 1 || handle >= MAX_SOURCEFILES ) { + return 0; + } + if ( !sourceFiles[handle] ) { + return 0; + } + + ret = PC_ReadToken( sourceFiles[handle], &token ); + strcpy( pc_token->string, token.string ); + pc_token->type = token.type; + pc_token->subtype = token.subtype; + pc_token->intvalue = token.intvalue; + pc_token->floatvalue = token.floatvalue; + if ( pc_token->type == TT_STRING ) { + StripDoubleQuotes( pc_token->string ); + } + return ret; +} //end of the function PC_ReadTokenHandle +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_SourceFileAndLine( int handle, char *filename, int *line ) { + if ( handle < 1 || handle >= MAX_SOURCEFILES ) { + return qfalse; + } + if ( !sourceFiles[handle] ) { + return qfalse; + } + + strcpy( filename, sourceFiles[handle]->filename ); + if ( sourceFiles[handle]->scriptstack ) { + *line = sourceFiles[handle]->scriptstack->line; + } else { + *line = 0; + } + return qtrue; +} //end of the function PC_SourceFileAndLine +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void PC_SetBaseFolder( char *path ) { + PS_SetBaseFolder( path ); +} //end of the function PC_SetBaseFolder +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void PC_CheckOpenSourceHandles( void ) { + int i; + + for ( i = 1; i < MAX_SOURCEFILES; i++ ) + { + if ( sourceFiles[i] ) { +#ifdef BOTLIB + botimport.Print( PRT_ERROR, "file %s still open in precompiler\n", sourceFiles[i]->scriptstack->filename ); +#endif //BOTLIB + } //end if + } //end for +} //end of the function PC_CheckOpenSourceHandles diff --git a/Projects/Android/jni/rtcw/src/botlib/l_precomp.h b/Projects/Android/jni/rtcw/src/botlib/l_precomp.h new file mode 100644 index 0000000..e1e504f --- /dev/null +++ b/Projects/Android/jni/rtcw/src/botlib/l_precomp.h @@ -0,0 +1,182 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +/***************************************************************************** + * name: l_precomp.h + * + * desc: pre compiler + * + * + *****************************************************************************/ + +#ifndef _MAX_PATH + #define MAX_PATH MAX_QPATH +#endif + +#ifndef PATH_SEPERATORSTR + #if defined( WIN32 ) | defined( _WIN32 ) | defined( __NT__ ) | defined( __WINDOWS__ ) | defined( __WINDOWS_386__ ) + #define PATHSEPERATOR_STR "\\" + #else + #define PATHSEPERATOR_STR "/" + #endif +#endif +#ifndef PATH_SEPERATORCHAR + #if defined( WIN32 ) | defined( _WIN32 ) | defined( __NT__ ) | defined( __WINDOWS__ ) | defined( __WINDOWS_386__ ) + #define PATHSEPERATOR_CHAR '\\' + #else + #define PATHSEPERATOR_CHAR '/' + #endif +#endif + + +#define DEFINE_FIXED 0x0001 + +#define BUILTIN_LINE 1 +#define BUILTIN_FILE 2 +#define BUILTIN_DATE 3 +#define BUILTIN_TIME 4 +#define BUILTIN_STDC 5 + +#define INDENT_IF 0x0001 +#define INDENT_ELSE 0x0002 +#define INDENT_ELIF 0x0004 +#define INDENT_IFDEF 0x0008 +#define INDENT_IFNDEF 0x0010 + +//macro definitions +typedef struct define_s +{ + char *name; //define name + int flags; //define flags + int builtin; // > 0 if builtin define + int numparms; //number of define parameters + token_t *parms; //define parameters + token_t *tokens; //macro tokens (possibly containing parm tokens) + struct define_s *next; //next defined macro in a list + struct define_s *hashnext; //next define in the hash chain +} define_t; + +//indents +//used for conditional compilation directives: +//#if, #else, #elif, #ifdef, #ifndef +typedef struct indent_s +{ + int type; //indent type + int skip; //true if skipping current indent + script_t *script; //script the indent was in + struct indent_s *next; //next indent on the indent stack +} indent_t; + +//source file +typedef struct source_s +{ + char filename[_MAX_PATH]; //file name of the script + char includepath[_MAX_PATH]; //path to include files + punctuation_t *punctuations; //punctuations to use + script_t *scriptstack; //stack with scripts of the source + token_t *tokens; //tokens to read first + define_t *defines; //list with macro definitions + define_t **definehash; //hash chain with defines + indent_t *indentstack; //stack with indents + int skip; // > 0 if skipping conditional code + token_t token; //last read token +} source_t; + + +//read a token from the source +int PC_ReadToken( source_t *source, token_t *token ); +//expect a certain token +int PC_ExpectTokenString( source_t *source, char *string ); +//expect a certain token type +int PC_ExpectTokenType( source_t *source, int type, int subtype, token_t *token ); +//expect a token +int PC_ExpectAnyToken( source_t *source, token_t *token ); +//returns true when the token is available +int PC_CheckTokenString( source_t *source, char *string ); +//returns true an reads the token when a token with the given type is available +int PC_CheckTokenType( source_t *source, int type, int subtype, token_t *token ); +//skip tokens until the given token string is read +int PC_SkipUntilString( source_t *source, char *string ); +//unread the last token read from the script +void PC_UnreadLastToken( source_t *source ); +//unread the given token +void PC_UnreadToken( source_t *source, token_t *token ); +//read a token only if on the same line, lines are concatenated with a slash +int PC_ReadLine( source_t *source, token_t *token ); +//returns true if there was a white space in front of the token +int PC_WhiteSpaceBeforeToken( token_t *token ); +//add a define to the source +int PC_AddDefine( source_t *source, char *string ); +//add a globals define that will be added to all opened sources +int PC_AddGlobalDefine( char *string ); +//remove the given global define +int PC_RemoveGlobalDefine( char *name ); +//remove all globals defines +void PC_RemoveAllGlobalDefines( void ); +//add builtin defines +void PC_AddBuiltinDefines( source_t *source ); +//set the source include path +void PC_SetIncludePath( source_t *source, char *path ); +//set the punction set +void PC_SetPunctuations( source_t *source, punctuation_t *p ); +//set the base folder to load files from +void PC_SetBaseFolder( char *path ); +//load a source file +source_t *LoadSourceFile( const char *filename ); +//load a source from memory +source_t *LoadSourceMemory( char *ptr, int length, char *name ); +//free the given source +void FreeSource( source_t *source ); +//print a source error +void QDECL SourceError( source_t *source, char *str, ... ); +//print a source warning +void QDECL SourceWarning( source_t *source, char *str, ... ); + +#ifdef BSPC +// some of BSPC source does include game/q_shared.h and some does not +// we define pc_token_s pc_token_t if needed (yes, it's ugly) +#ifndef __Q_SHARED_H +#define MAX_TOKENLENGTH 1024 +typedef struct pc_token_s +{ + int type; + int subtype; + int intvalue; + float floatvalue; + char string[MAX_TOKENLENGTH]; +} pc_token_t; +#endif //!_Q_SHARED_H +#endif //BSPC + +// +int PC_LoadSourceHandle( const char *filename ); +int PC_FreeSourceHandle( int handle ); +int PC_ReadTokenHandle( int handle, struct pc_token_s *pc_token ); +int PC_SourceFileAndLine( int handle, char *filename, int *line ); +void PC_CheckOpenSourceHandles( void ); diff --git a/Projects/Android/jni/rtcw/src/botlib/l_script.c b/Projects/Android/jni/rtcw/src/botlib/l_script.c new file mode 100644 index 0000000..68d305c --- /dev/null +++ b/Projects/Android/jni/rtcw/src/botlib/l_script.c @@ -0,0 +1,1452 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +/***************************************************************************** + * name: l_script.c + * + * desc: lexicographical parser + * + * + *****************************************************************************/ + +//#define SCREWUP +//#define BOTLIB +//#define MEQCC +//#define BSPC + +#ifdef SCREWUP +#include +#include +#include +#include +#include +#include "../botlib/l_memory.h" +#include "../botlib/l_script.h" + +typedef enum {qfalse, qtrue} qboolean; + +#endif //SCREWUP + +#ifdef BOTLIB +//include files for usage in the bot library +#include "../game/q_shared.h" +#include "../game/botlib.h" +#include "be_interface.h" +#include "l_script.h" +#include "l_memory.h" +#include "l_log.h" +#include "l_libvar.h" +#endif //BOTLIB + +#ifdef MEQCC +//include files for usage in MrElusive's QuakeC Compiler +#include "qcc.h" +#include "l_script.h" +#include "l_memory.h" +#include "l_log.h" + +#define qtrue true +#define qfalse false +#endif //MEQCC + +#ifdef BSPC +//include files for usage in the BSP Converter +#include "../bspc/qbsp.h" +#include "../bspc/l_log.h" +#include "../bspc/l_mem.h" +int COM_Compress( char *data_p ); + +#define qtrue true +#define qfalse false +#endif //BSPC + + +#define PUNCTABLE + +//longer punctuations first +punctuation_t default_punctuations[] = +{ + //binary operators + {">>=",P_RSHIFT_ASSIGN, NULL}, + {"<<=",P_LSHIFT_ASSIGN, NULL}, + // + {"...",P_PARMS, NULL}, + //define merge operator + {"##",P_PRECOMPMERGE, NULL}, + //logic operators + {"&&",P_LOGIC_AND, NULL}, + {"||",P_LOGIC_OR, NULL}, + {">=",P_LOGIC_GEQ, NULL}, + {"<=",P_LOGIC_LEQ, NULL}, + {"==",P_LOGIC_EQ, NULL}, + {"!=",P_LOGIC_UNEQ, NULL}, + //arithmatic operators + {"*=",P_MUL_ASSIGN, NULL}, + {"/=",P_DIV_ASSIGN, NULL}, + {"%=",P_MOD_ASSIGN, NULL}, + {"+=",P_ADD_ASSIGN, NULL}, + {"-=",P_SUB_ASSIGN, NULL}, + {"++",P_INC, NULL}, + {"--",P_DEC, NULL}, + //binary operators + {"&=",P_BIN_AND_ASSIGN, NULL}, + {"|=",P_BIN_OR_ASSIGN, NULL}, + {"^=",P_BIN_XOR_ASSIGN, NULL}, + {">>",P_RSHIFT, NULL}, + {"<<",P_LSHIFT, NULL}, + //reference operators + {"->",P_POINTERREF, NULL}, + //C++ + {"::",P_CPP1, NULL}, + {".*",P_CPP2, NULL}, + //arithmatic operators + {"*",P_MUL, NULL}, + {"/",P_DIV, NULL}, + {"%",P_MOD, NULL}, + {"+",P_ADD, NULL}, + {"-",P_SUB, NULL}, + {"=",P_ASSIGN, NULL}, + //binary operators + {"&",P_BIN_AND, NULL}, + {"|",P_BIN_OR, NULL}, + {"^",P_BIN_XOR, NULL}, + {"~",P_BIN_NOT, NULL}, + //logic operators + {"!",P_LOGIC_NOT, NULL}, + {">",P_LOGIC_GREATER, NULL}, + {"<",P_LOGIC_LESS, NULL}, + //reference operator + {".",P_REF, NULL}, + //seperators + {",",P_COMMA, NULL}, + {";",P_SEMICOLON, NULL}, + //label indication + {":",P_COLON, NULL}, + //if statement + {"?",P_QUESTIONMARK, NULL}, + //embracements + {"(",P_PARENTHESESOPEN, NULL}, + {")",P_PARENTHESESCLOSE, NULL}, + {"{",P_BRACEOPEN, NULL}, + {"}",P_BRACECLOSE, NULL}, + {"[",P_SQBRACKETOPEN, NULL}, + {"]",P_SQBRACKETCLOSE, NULL}, + // + {"\\",P_BACKSLASH, NULL}, + //precompiler operator + {"#",P_PRECOMP, NULL}, +#ifdef DOLLAR + {"$",P_DOLLAR, NULL}, +#endif //DOLLAR + {NULL, 0} +}; + +#ifdef BSPC +char basefolder[MAX_PATH]; +#else +char basefolder[MAX_QPATH]; +#endif + +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void PS_CreatePunctuationTable( script_t *script, punctuation_t *punctuations ) { + int i; + punctuation_t *p, *lastp, *newp; + + //get memory for the table + if ( !script->punctuationtable ) { + script->punctuationtable = (punctuation_t **) + GetMemory( 256 * sizeof( punctuation_t * ) ); + } + memset( script->punctuationtable, 0, 256 * sizeof( punctuation_t * ) ); + //add the punctuations in the list to the punctuation table + for ( i = 0; punctuations[i].p; i++ ) + { + newp = &punctuations[i]; + lastp = NULL; + //sort the punctuations in this table entry on length (longer punctuations first) + for ( p = script->punctuationtable[(unsigned int) newp->p[0]]; p; p = p->next ) + { + if ( strlen( p->p ) < strlen( newp->p ) ) { + newp->next = p; + if ( lastp ) { + lastp->next = newp; + } else { script->punctuationtable[(unsigned int) newp->p[0]] = newp;} + break; + } //end if + lastp = p; + } //end for + if ( !p ) { + newp->next = NULL; + if ( lastp ) { + lastp->next = newp; + } else { script->punctuationtable[(unsigned int) newp->p[0]] = newp;} + } //end if + } //end for +} //end of the function PS_CreatePunctuationTable +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +char *PunctuationFromNum( script_t *script, int num ) { + int i; + + for ( i = 0; script->punctuations[i].p; i++ ) + { + if ( script->punctuations[i].n == num ) { + return script->punctuations[i].p; + } + } //end for + return "unkown punctuation"; +} //end of the function PunctuationFromNum +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void QDECL ScriptError( script_t *script, char *str, ... ) { + char text[1024]; + va_list ap; + + if ( script->flags & SCFL_NOERRORS ) { + return; + } + + va_start( ap, str ); + vsprintf( text, str, ap ); + va_end( ap ); +#ifdef BOTLIB + botimport.Print( PRT_ERROR, "file %s, line %d: %s\n", script->filename, script->line, text ); +#endif //BOTLIB +#ifdef MEQCC + printf( "error: file %s, line %d: %s\n", script->filename, script->line, text ); +#endif //MEQCC +#ifdef BSPC + Log_Print( "error: file %s, line %d: %s\n", script->filename, script->line, text ); +#endif //BSPC +} //end of the function ScriptError +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void QDECL ScriptWarning( script_t *script, char *str, ... ) { + char text[1024]; + va_list ap; + + if ( script->flags & SCFL_NOWARNINGS ) { + return; + } + + va_start( ap, str ); + vsprintf( text, str, ap ); + va_end( ap ); +#ifdef BOTLIB + botimport.Print( PRT_WARNING, "file %s, line %d: %s\n", script->filename, script->line, text ); +#endif //BOTLIB +#ifdef MEQCC + printf( "warning: file %s, line %d: %s\n", script->filename, script->line, text ); +#endif //MEQCC +#ifdef BSPC + Log_Print( "warning: file %s, line %d: %s\n", script->filename, script->line, text ); +#endif //BSPC +} //end of the function ScriptWarning +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void SetScriptPunctuations( script_t *script, punctuation_t *p ) { +#ifdef PUNCTABLE + if ( p ) { + PS_CreatePunctuationTable( script, p ); + } else { PS_CreatePunctuationTable( script, default_punctuations );} +#endif //PUNCTABLE + if ( p ) { + script->punctuations = p; + } else { script->punctuations = default_punctuations;} +} //end of the function SetScriptPunctuations +//============================================================================ +// Reads spaces, tabs, C-like comments etc. +// When a newline character is found the scripts line counter is increased. +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PS_ReadWhiteSpace( script_t *script ) { + while ( 1 ) + { + //skip white space + while ( *script->script_p <= ' ' ) + { + if ( !*script->script_p ) { + return 0; + } + if ( *script->script_p == '\n' ) { + script->line++; + } + script->script_p++; + } //end while + //skip comments + if ( *script->script_p == '/' ) { + //comments // + if ( *( script->script_p + 1 ) == '/' ) { + script->script_p++; + do + { + script->script_p++; + if ( !*script->script_p ) { + return 0; + } + } //end do + while ( *script->script_p != '\n' ); + script->line++; + script->script_p++; + if ( !*script->script_p ) { + return 0; + } + continue; + } //end if + //comments /* */ + else if ( *( script->script_p + 1 ) == '*' ) { + script->script_p++; + do + { + script->script_p++; + if ( !*script->script_p ) { + return 0; + } + if ( *script->script_p == '\n' ) { + script->line++; + } + } //end do + while ( !( *script->script_p == '*' && *( script->script_p + 1 ) == '/' ) ); + script->script_p++; + if ( !*script->script_p ) { + return 0; + } + script->script_p++; + if ( !*script->script_p ) { + return 0; + } + continue; + } //end if + } //end if + break; + } //end while + return 1; +} //end of the function PS_ReadWhiteSpace +//============================================================================ +// Reads an escape character. +// +// Parameter: script : script to read from +// ch : place to store the read escape character +// Returns: - +// Changes Globals: - +//============================================================================ +int PS_ReadEscapeCharacter( script_t *script, char *ch ) { + int c, val, i; + + //step over the leading '\\' + script->script_p++; + //determine the escape character + switch ( *script->script_p ) + { + case '\\': c = '\\'; break; + case 'n': c = '\n'; break; + case 'r': c = '\r'; break; + case 't': c = '\t'; break; + case 'v': c = '\v'; break; + case 'b': c = '\b'; break; + case 'f': c = '\f'; break; + case 'a': c = '\a'; break; + case '\'': c = '\''; break; + case '\"': c = '\"'; break; + case '\?': c = '\?'; break; + case 'x': + { + script->script_p++; + for ( i = 0, val = 0; ; i++, script->script_p++ ) + { + c = *script->script_p; + if ( c >= '0' && c <= '9' ) { + c = c - '0'; + } else if ( c >= 'A' && c <= 'Z' ) { + c = c - 'A' + 10; + } else if ( c >= 'a' && c <= 'z' ) { + c = c - 'a' + 10; + } else { break;} + val = ( val << 4 ) + c; + } //end for + script->script_p--; + if ( val > 0xFF ) { + ScriptWarning( script, "too large value in escape character" ); + val = 0xFF; + } //end if + c = val; + break; + } //end case + default: //NOTE: decimal ASCII code, NOT octal + { + if ( *script->script_p < '0' || *script->script_p > '9' ) { + ScriptError( script, "unknown escape char" ); + } + for ( i = 0, val = 0; ; i++, script->script_p++ ) + { + c = *script->script_p; + if ( c >= '0' && c <= '9' ) { + c = c - '0'; + } else { break;} + val = val * 10 + c; + } //end for + script->script_p--; + if ( val > 0xFF ) { + ScriptWarning( script, "too large value in escape character" ); + val = 0xFF; + } //end if + c = val; + break; + } //end default + } //end switch + //step over the escape character or the last digit of the number + script->script_p++; + //store the escape character + *ch = c; + //succesfully read escape character + return 1; +} //end of the function PS_ReadEscapeCharacter +//============================================================================ +// Reads C-like string. Escape characters are interpretted. +// Quotes are included with the string. +// Reads two strings with a white space between them as one string. +// +// Parameter: script : script to read from +// token : buffer to store the string +// Returns: qtrue when a string was read succesfully +// Changes Globals: - +//============================================================================ +int PS_ReadString( script_t *script, token_t *token, int quote ) { + int len, tmpline; + char *tmpscript_p; + + if ( quote == '\"' ) { + token->type = TT_STRING; + } else { token->type = TT_LITERAL;} + + len = 0; + //leading quote + token->string[len++] = *script->script_p++; + // + while ( 1 ) + { + //minus 2 because trailing double quote and zero have to be appended + if ( len >= MAX_TOKEN - 2 ) { + ScriptError( script, "string longer than MAX_TOKEN = %d", MAX_TOKEN ); + return 0; + } //end if + //if there is an escape character and + //if escape characters inside a string are allowed + if ( *script->script_p == '\\' && !( script->flags & SCFL_NOSTRINGESCAPECHARS ) ) { + if ( !PS_ReadEscapeCharacter( script, &token->string[len] ) ) { + token->string[len] = 0; + return 0; + } //end if + len++; + } //end if + //if a trailing quote + else if ( *script->script_p == quote ) { + //step over the double quote + script->script_p++; + //if white spaces in a string are not allowed + if ( script->flags & SCFL_NOSTRINGWHITESPACES ) { + break; + } + // + tmpscript_p = script->script_p; + tmpline = script->line; + //read unusefull stuff between possible two following strings + if ( !PS_ReadWhiteSpace( script ) ) { + script->script_p = tmpscript_p; + script->line = tmpline; + break; + } //end if + //if there's no leading double qoute + if ( *script->script_p != quote ) { + script->script_p = tmpscript_p; + script->line = tmpline; + break; + } //end if + //step over the new leading double quote + script->script_p++; + } //end if + else + { + if ( *script->script_p == '\0' ) { + token->string[len] = 0; + ScriptError( script, "missing trailing quote" ); + return 0; + } //end if + if ( *script->script_p == '\n' ) { + token->string[len] = 0; + ScriptError( script, "newline inside string %s", token->string ); + return 0; + } //end if + token->string[len++] = *script->script_p++; + } //end else + } //end while + //trailing quote + token->string[len++] = quote; + //end string with a zero + token->string[len] = '\0'; + //the sub type is the length of the string + token->subtype = len; + return 1; +} //end of the function PS_ReadString +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PS_ReadName( script_t *script, token_t *token ) { + int len = 0; + char c; + + token->type = TT_NAME; + do + { + token->string[len++] = *script->script_p++; + if ( len >= MAX_TOKEN ) { + ScriptError( script, "name longer than MAX_TOKEN = %d", MAX_TOKEN ); + return 0; + } //end if + c = *script->script_p; + } while ( ( c >= 'a' && c <= 'z' ) || + ( c >= 'A' && c <= 'Z' ) || + ( c >= '0' && c <= '9' ) || + c == '_' ); + token->string[len] = '\0'; + //the sub type is the length of the name + token->subtype = len; + return 1; +} //end of the function PS_ReadName +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void NumberValue( char *string, int subtype, unsigned long int *intvalue, + long double *floatvalue ) { + unsigned long int dotfound = 0; + + *intvalue = 0; + *floatvalue = 0; + //floating point number + if ( subtype & TT_FLOAT ) { + while ( *string ) + { + if ( *string == '.' ) { + if ( dotfound ) { + return; + } + dotfound = 10; + string++; + } //end if + if ( dotfound ) { + *floatvalue = *floatvalue + ( long double )( *string - '0' ) / + (long double) dotfound; + dotfound *= 10; + } //end if + else + { + *floatvalue = *floatvalue * 10.0 + ( long double )( *string - '0' ); + } //end else + string++; + } //end while + *intvalue = (unsigned long) *floatvalue; + } //end if + else if ( subtype & TT_DECIMAL ) { + while ( *string ) *intvalue = *intvalue * 10 + ( *string++ - '0' ); + *floatvalue = *intvalue; + } //end else if + else if ( subtype & TT_HEX ) { + //step over the leading 0x or 0X + string += 2; + while ( *string ) + { + *intvalue <<= 4; + if ( *string >= 'a' && *string <= 'f' ) { + *intvalue += *string - 'a' + 10; + } else if ( *string >= 'A' && *string <= 'F' ) { + *intvalue += *string - 'A' + 10; + } else { *intvalue += *string - '0';} + string++; + } //end while + *floatvalue = *intvalue; + } //end else if + else if ( subtype & TT_OCTAL ) { + //step over the first zero + string += 1; + while ( *string ) *intvalue = ( *intvalue << 3 ) + ( *string++ - '0' ); + *floatvalue = *intvalue; + } //end else if + else if ( subtype & TT_BINARY ) { + //step over the leading 0b or 0B + string += 2; + while ( *string ) *intvalue = ( *intvalue << 1 ) + ( *string++ - '0' ); + *floatvalue = *intvalue; + } //end else if +} //end of the function NumberValue +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PS_ReadNumber( script_t *script, token_t *token ) { + int len = 0, i; + int octal, dot; + char c; +// unsigned long int intvalue = 0; +// long double floatvalue = 0; + + token->type = TT_NUMBER; + //check for a hexadecimal number + if ( *script->script_p == '0' && + ( *( script->script_p + 1 ) == 'x' || + *( script->script_p + 1 ) == 'X' ) ) { + token->string[len++] = *script->script_p++; + token->string[len++] = *script->script_p++; + c = *script->script_p; + //hexadecimal + while ( ( c >= '0' && c <= '9' ) || + ( c >= 'a' && c <= 'f' ) || + ( c >= 'A' && c <= 'A' ) ) + { + token->string[len++] = *script->script_p++; + if ( len >= MAX_TOKEN ) { + ScriptError( script, "hexadecimal number longer than MAX_TOKEN = %d", MAX_TOKEN ); + return 0; + } //end if + c = *script->script_p; + } //end while + token->subtype |= TT_HEX; + } //end if +#ifdef BINARYNUMBERS + //check for a binary number + else if ( *script->script_p == '0' && + ( *( script->script_p + 1 ) == 'b' || + *( script->script_p + 1 ) == 'B' ) ) { + token->string[len++] = *script->script_p++; + token->string[len++] = *script->script_p++; + c = *script->script_p; + //hexadecimal + while ( c == '0' || c == '1' ) + { + token->string[len++] = *script->script_p++; + if ( len >= MAX_TOKEN ) { + ScriptError( script, "binary number longer than MAX_TOKEN = %d", MAX_TOKEN ); + return 0; + } //end if + c = *script->script_p; + } //end while + token->subtype |= TT_BINARY; + } //end if +#endif //BINARYNUMBERS + else //decimal or octal integer or floating point number + { + octal = qfalse; + dot = qfalse; + if ( *script->script_p == '0' ) { + octal = qtrue; + } + while ( 1 ) + { + c = *script->script_p; + if ( c == '.' ) { + dot = qtrue; + } else if ( c == '8' || c == '9' ) { + octal = qfalse; + } else if ( c < '0' || c > '9' ) { + break; + } + token->string[len++] = *script->script_p++; + if ( len >= MAX_TOKEN - 1 ) { + ScriptError( script, "number longer than MAX_TOKEN = %d", MAX_TOKEN ); + return 0; + } //end if + } //end while + if ( octal ) { + token->subtype |= TT_OCTAL; + } else { token->subtype |= TT_DECIMAL;} + if ( dot ) { + token->subtype |= TT_FLOAT; + } + } //end else + for ( i = 0; i < 2; i++ ) + { + c = *script->script_p; + //check for a LONG number + // TTimo: gcc: suggest parentheses around && within || + // initial line: + // if (c == 'l' || c == 'L' && !(token->subtype & TT_LONG)) + // changed behaviour + if ( ( c == 'l' || c == 'L' ) && + !( token->subtype & TT_LONG ) ) { + script->script_p++; + token->subtype |= TT_LONG; + } //end if + //check for an UNSIGNED number + // TTimo: gcc: suggest parentheses around && within || + // initial line: + // else if (c == 'u' || c == 'U' && !(token->subtype & (TT_UNSIGNED | TT_FLOAT))) + // changed behaviour + else if ( ( c == 'u' || c == 'U' ) && + !( token->subtype & ( TT_UNSIGNED | TT_FLOAT ) ) ) { + script->script_p++; + token->subtype |= TT_UNSIGNED; + } //end if + } //end for + token->string[len] = '\0'; +#ifdef NUMBERVALUE + NumberValue( token->string, token->subtype, &token->intvalue, &token->floatvalue ); +#endif //NUMBERVALUE + if ( !( token->subtype & TT_FLOAT ) ) { + token->subtype |= TT_INTEGER; + } + return 1; +} //end of the function PS_ReadNumber +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PS_ReadLiteral( script_t *script, token_t *token ) { + token->type = TT_LITERAL; + //first quote + token->string[0] = *script->script_p++; + //check for end of file + if ( !*script->script_p ) { + ScriptError( script, "end of file before trailing \'" ); + return 0; + } //end if + //if it is an escape character + if ( *script->script_p == '\\' ) { + if ( !PS_ReadEscapeCharacter( script, &token->string[1] ) ) { + return 0; + } + } //end if + else + { + token->string[1] = *script->script_p++; + } //end else + //check for trailing quote + if ( *script->script_p != '\'' ) { + ScriptWarning( script, "too many characters in literal, ignored" ); + while ( *script->script_p && + *script->script_p != '\'' && + *script->script_p != '\n' ) + { + script->script_p++; + } //end while + if ( *script->script_p == '\'' ) { + script->script_p++; + } + } //end if + //store the trailing quote + token->string[2] = *script->script_p++; + //store trailing zero to end the string + token->string[3] = '\0'; + //the sub type is the integer literal value + token->subtype = token->string[1]; + // + return 1; +} //end of the function PS_ReadLiteral +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PS_ReadPunctuation( script_t *script, token_t *token ) { + int len; + char *p; + punctuation_t *punc; + +#ifdef PUNCTABLE + for ( punc = script->punctuationtable[(unsigned int)*script->script_p]; punc; punc = punc->next ) + { +#else + int i; + + for ( i = 0; script->punctuations[i].p; i++ ) + { + punc = &script->punctuations[i]; +#endif //PUNCTABLE + p = punc->p; + len = strlen( p ); + //if the script contains at least as much characters as the punctuation + if ( script->script_p + len <= script->end_p ) { + //if the script contains the punctuation + if ( !strncmp( script->script_p, p, len ) ) { + strncpy( token->string, p, MAX_TOKEN ); + script->script_p += len; + token->type = TT_PUNCTUATION; + //sub type is the number of the punctuation + token->subtype = punc->n; + return 1; + } //end if + } //end if + } //end for + return 0; +} //end of the function PS_ReadPunctuation +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PS_ReadPrimitive( script_t *script, token_t *token ) { + int len; + + len = 0; + while ( *script->script_p > ' ' && *script->script_p != ';' ) + { + if ( len >= MAX_TOKEN ) { + ScriptError( script, "primitive token longer than MAX_TOKEN = %d", MAX_TOKEN ); + return 0; + } //end if + token->string[len++] = *script->script_p++; + } //end while + token->string[len] = 0; + //copy the token into the script structure + memcpy( &script->token, token, sizeof( token_t ) ); + //primitive reading successfull + return 1; +} //end of the function PS_ReadPrimitive +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PS_ReadToken( script_t *script, token_t *token ) { + //if there is a token available (from UnreadToken) + if ( script->tokenavailable ) { + script->tokenavailable = 0; + memcpy( token, &script->token, sizeof( token_t ) ); + return 1; + } //end if + //save script pointer + script->lastscript_p = script->script_p; + //save line counter + script->lastline = script->line; + //clear the token stuff + memset( token, 0, sizeof( token_t ) ); + //start of the white space + script->whitespace_p = script->script_p; + token->whitespace_p = script->script_p; + //read unusefull stuff + if ( !PS_ReadWhiteSpace( script ) ) { + return 0; + } + //end of the white space + script->endwhitespace_p = script->script_p; + token->endwhitespace_p = script->script_p; + //line the token is on + token->line = script->line; + //number of lines crossed before token + token->linescrossed = script->line - script->lastline; + //if there is a leading double quote + if ( *script->script_p == '\"' ) { + if ( !PS_ReadString( script, token, '\"' ) ) { + return 0; + } + } //end if + //if an literal + else if ( *script->script_p == '\'' ) { + //if (!PS_ReadLiteral(script, token)) return 0; + if ( !PS_ReadString( script, token, '\'' ) ) { + return 0; + } + } //end if + //if there is a number + else if ( ( *script->script_p >= '0' && *script->script_p <= '9' ) || + ( *script->script_p == '.' && + ( *( script->script_p + 1 ) >= '0' && *( script->script_p + 1 ) <= '9' ) ) ) { + if ( !PS_ReadNumber( script, token ) ) { + return 0; + } + } //end if + //if this is a primitive script + else if ( script->flags & SCFL_PRIMITIVE ) { + return PS_ReadPrimitive( script, token ); + } //end else if + //if there is a name + else if ( ( *script->script_p >= 'a' && *script->script_p <= 'z' ) || + ( *script->script_p >= 'A' && *script->script_p <= 'Z' ) || + *script->script_p == '_' ) { + if ( !PS_ReadName( script, token ) ) { + return 0; + } + } //end if + //check for punctuations + else if ( !PS_ReadPunctuation( script, token ) ) { + ScriptError( script, "can't read token" ); + return 0; + } //end if + //copy the token into the script structure + memcpy( &script->token, token, sizeof( token_t ) ); + //succesfully read a token + return 1; +} //end of the function PS_ReadToken +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PS_ExpectTokenString( script_t *script, char *string ) { + token_t token; + + if ( !PS_ReadToken( script, &token ) ) { + ScriptError( script, "couldn't find expected %s", string ); + return 0; + } //end if + + if ( strcmp( token.string, string ) ) { + ScriptError( script, "expected %s, found %s", string, token.string ); + return 0; + } //end if + return 1; +} //end of the function PS_ExpectToken +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PS_ExpectTokenType( script_t *script, int type, int subtype, token_t *token ) { + char str[MAX_TOKEN]; + + if ( !PS_ReadToken( script, token ) ) { + ScriptError( script, "couldn't read expected token" ); + return 0; + } //end if + + if ( token->type != type ) { + if ( type == TT_STRING ) { + strcpy( str, "string" ); + } + if ( type == TT_LITERAL ) { + strcpy( str, "literal" ); + } + if ( type == TT_NUMBER ) { + strcpy( str, "number" ); + } + if ( type == TT_NAME ) { + strcpy( str, "name" ); + } + if ( type == TT_PUNCTUATION ) { + strcpy( str, "punctuation" ); + } + ScriptError( script, "expected a %s, found %s", str, token->string ); + return 0; + } //end if + if ( token->type == TT_NUMBER ) { + if ( ( token->subtype & subtype ) != subtype ) { + if ( subtype & TT_DECIMAL ) { + strcpy( str, "decimal" ); + } + if ( subtype & TT_HEX ) { + strcpy( str, "hex" ); + } + if ( subtype & TT_OCTAL ) { + strcpy( str, "octal" ); + } + if ( subtype & TT_BINARY ) { + strcpy( str, "binary" ); + } + if ( subtype & TT_LONG ) { + strcat( str, " long" ); + } + if ( subtype & TT_UNSIGNED ) { + strcat( str, " unsigned" ); + } + if ( subtype & TT_FLOAT ) { + strcat( str, " float" ); + } + if ( subtype & TT_INTEGER ) { + strcat( str, " integer" ); + } + ScriptError( script, "expected %s, found %s", str, token->string ); + return 0; + } //end if + } //end if + else if ( token->type == TT_PUNCTUATION ) { + if ( subtype < 0 ) { + ScriptError( script, "BUG: wrong punctuation subtype" ); + return 0; + } //end if + if ( token->subtype != subtype ) { + ScriptError( script, "expected %s, found %s", + script->punctuations[subtype], token->string ); + return 0; + } //end if + } //end else if + return 1; +} //end of the function PS_ExpectTokenType +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PS_ExpectAnyToken( script_t *script, token_t *token ) { + if ( !PS_ReadToken( script, token ) ) { + ScriptError( script, "couldn't read expected token" ); + return 0; + } //end if + else + { + return 1; + } //end else +} //end of the function PS_ExpectAnyToken +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PS_CheckTokenString( script_t *script, char *string ) { + token_t tok; + + if ( !PS_ReadToken( script, &tok ) ) { + return 0; + } + //if the token is available + if ( !strcmp( tok.string, string ) ) { + return 1; + } + //token not available + script->script_p = script->lastscript_p; + return 0; +} //end of the function PS_CheckTokenString +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PS_CheckTokenType( script_t *script, int type, int subtype, token_t *token ) { + token_t tok; + + if ( !PS_ReadToken( script, &tok ) ) { + return 0; + } + //if the type matches + if ( tok.type == type && + ( tok.subtype & subtype ) == subtype ) { + memcpy( token, &tok, sizeof( token_t ) ); + return 1; + } //end if + //token is not available + script->script_p = script->lastscript_p; + return 0; +} //end of the function PS_CheckTokenType +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PS_SkipUntilString( script_t *script, char *string ) { + token_t token; + + while ( PS_ReadToken( script, &token ) ) + { + if ( !strcmp( token.string, string ) ) { + return 1; + } + } //end while + return 0; +} //end of the function PS_SkipUntilString +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void PS_UnreadLastToken( script_t *script ) { + script->tokenavailable = 1; +} //end of the function UnreadLastToken +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void PS_UnreadToken( script_t *script, token_t *token ) { + memcpy( &script->token, token, sizeof( token_t ) ); + script->tokenavailable = 1; +} //end of the function UnreadToken +//============================================================================ +// returns the next character of the read white space, returns NULL if none +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +char PS_NextWhiteSpaceChar( script_t *script ) { + if ( script->whitespace_p != script->endwhitespace_p ) { + return *script->whitespace_p++; + } //end if + else + { + return 0; + } //end else +} //end of the function PS_NextWhiteSpaceChar +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void StripDoubleQuotes( char *string ) { + if ( *string == '\"' ) { + strcpy( string, string + 1 ); + } //end if + if ( string[strlen( string ) - 1] == '\"' ) { + string[strlen( string ) - 1] = '\0'; + } //end if +} //end of the function StripDoubleQuotes +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void StripSingleQuotes( char *string ) { + if ( *string == '\'' ) { + strcpy( string, string + 1 ); + } //end if + if ( string[strlen( string ) - 1] == '\'' ) { + string[strlen( string ) - 1] = '\0'; + } //end if +} //end of the function StripSingleQuotes +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +long double ReadSignedFloat( script_t *script ) { + token_t token; + long double sign = 1; + + PS_ExpectAnyToken( script, &token ); + if ( !strcmp( token.string, "-" ) ) { + sign = -1; + PS_ExpectTokenType( script, TT_NUMBER, 0, &token ); + } //end if + else if ( token.type != TT_NUMBER ) { + ScriptError( script, "expected float value, found %s\n", token.string ); + } //end else if + return sign * token.floatvalue; +} //end of the function ReadSignedFloat +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +signed long int ReadSignedInt( script_t *script ) { + token_t token; + signed long int sign = 1; + + PS_ExpectAnyToken( script, &token ); + if ( !strcmp( token.string, "-" ) ) { + sign = -1; + PS_ExpectTokenType( script, TT_NUMBER, TT_INTEGER, &token ); + } //end if + else if ( token.type != TT_NUMBER || token.subtype == TT_FLOAT ) { + ScriptError( script, "expected integer value, found %s\n", token.string ); + } //end else if + return sign * token.intvalue; +} //end of the function ReadSignedInt +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void SetScriptFlags( script_t *script, int flags ) { + script->flags = flags; +} //end of the function SetScriptFlags +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int GetScriptFlags( script_t *script ) { + return script->flags; +} //end of the function GetScriptFlags +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void ResetScript( script_t *script ) { + //pointer in script buffer + script->script_p = script->buffer; + //pointer in script buffer before reading token + script->lastscript_p = script->buffer; + //begin of white space + script->whitespace_p = NULL; + //end of white space + script->endwhitespace_p = NULL; + //set if there's a token available in script->token + script->tokenavailable = 0; + // + script->line = 1; + script->lastline = 1; + //clear the saved token + memset( &script->token, 0, sizeof( token_t ) ); +} //end of the function ResetScript +//============================================================================ +// returns true if at the end of the script +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int EndOfScript( script_t *script ) { + return script->script_p >= script->end_p; +} //end of the function EndOfScript +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int NumLinesCrossed( script_t *script ) { + return script->line - script->lastline; +} //end of the function NumLinesCrossed +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int ScriptSkipTo( script_t *script, char *value ) { + int len; + char firstchar; + + firstchar = *value; + len = strlen( value ); + do + { + if ( !PS_ReadWhiteSpace( script ) ) { + return 0; + } + if ( *script->script_p == firstchar ) { + if ( !strncmp( script->script_p, value, len ) ) { + return 1; + } //end if + } //end if + script->script_p++; + } while ( 1 ); +} //end of the function ScriptSkipTo +#ifndef BOTLIB +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int FileLength( FILE *fp ) { + int pos; + int end; + + pos = ftell( fp ); + fseek( fp, 0, SEEK_END ); + end = ftell( fp ); + fseek( fp, pos, SEEK_SET ); + + return end; +} //end of the function FileLength +#endif +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +script_t *LoadScriptFile( const char *filename ) { +#ifdef BOTLIB + fileHandle_t fp; + char pathname[MAX_QPATH]; +#else + FILE *fp; +#endif + int length; + void *buffer; + script_t *script; + +#ifdef BOTLIB + if ( strlen( basefolder ) ) { + Com_sprintf( pathname, sizeof( pathname ), "%s/%s", basefolder, filename ); + } else { + Com_sprintf( pathname, sizeof( pathname ), "%s", filename ); + } + length = botimport.FS_FOpenFile( pathname, &fp, FS_READ ); + if ( !fp ) { + return NULL; + } +#else + fp = fopen( filename, "rb" ); + if ( !fp ) { + return NULL; + } + + length = FileLength( fp ); +#endif + + buffer = GetClearedMemory( sizeof( script_t ) + length + 1 ); + script = (script_t *) buffer; + memset( script, 0, sizeof( script_t ) ); + strcpy( script->filename, filename ); + script->buffer = (char *) buffer + sizeof( script_t ); + script->buffer[length] = 0; + script->length = length; + //pointer in script buffer + script->script_p = script->buffer; + //pointer in script buffer before reading token + script->lastscript_p = script->buffer; + //pointer to end of script buffer + script->end_p = &script->buffer[length]; + //set if there's a token available in script->token + script->tokenavailable = 0; + // + script->line = 1; + script->lastline = 1; + // + SetScriptPunctuations( script, NULL ); + // +#ifdef BOTLIB + botimport.FS_Read( script->buffer, length, fp ); + botimport.FS_FCloseFile( fp ); +#else + if ( fread( script->buffer, length, 1, fp ) != 1 ) { + FreeMemory( buffer ); + script = NULL; + } //end if + fclose( fp ); +#endif + // + script->length = COM_Compress( script->buffer ); + + return script; +} //end of the function LoadScriptFile +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +script_t *LoadScriptMemory( char *ptr, int length, char *name ) { + void *buffer; + script_t *script; + + buffer = GetClearedMemory( sizeof( script_t ) + length + 1 ); + script = (script_t *) buffer; + memset( script, 0, sizeof( script_t ) ); + strcpy( script->filename, name ); + script->buffer = (char *) buffer + sizeof( script_t ); + script->buffer[length] = 0; + script->length = length; + //pointer in script buffer + script->script_p = script->buffer; + //pointer in script buffer before reading token + script->lastscript_p = script->buffer; + //pointer to end of script buffer + script->end_p = &script->buffer[length]; + //set if there's a token available in script->token + script->tokenavailable = 0; + // + script->line = 1; + script->lastline = 1; + // + SetScriptPunctuations( script, NULL ); + // + memcpy( script->buffer, ptr, length ); + // + return script; +} //end of the function LoadScriptMemory +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void FreeScript( script_t *script ) { +#ifdef PUNCTABLE + if ( script->punctuationtable ) { + FreeMemory( script->punctuationtable ); + } +#endif //PUNCTABLE + FreeMemory( script ); +} //end of the function FreeScript +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void PS_SetBaseFolder( char *path ) { +#ifdef BSPC + sprintf( basefolder, path ); +#else + Com_sprintf( basefolder, sizeof( basefolder ), path ); +#endif +} //end of the function PS_SetBaseFolder diff --git a/Projects/Android/jni/rtcw/src/botlib/l_script.h b/Projects/Android/jni/rtcw/src/botlib/l_script.h new file mode 100644 index 0000000..461276e --- /dev/null +++ b/Projects/Android/jni/rtcw/src/botlib/l_script.h @@ -0,0 +1,268 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +/***************************************************************************** + * name: l_script.h + * + * desc: lexicographical parser + * + * + *****************************************************************************/ + +// Ridah, can't get it to compile without this +#ifndef QDECL + +// for windows fastcall option +#define QDECL +//======================= WIN32 DEFINES ================================= +#ifdef WIN32 +#undef QDECL +#define QDECL __cdecl +#endif +#endif +// done. + +//undef if binary numbers of the form 0b... or 0B... are not allowed +#define BINARYNUMBERS +//undef if not using the token.intvalue and token.floatvalue +#define NUMBERVALUE +//use dollar sign also as punctuation +#define DOLLAR + +//maximum token length +#define MAX_TOKEN 1024 +//maximum path length +#ifndef _MAX_PATH +// TTimo: used to be MAX_QPATH, which is the game filesystem max len, and not the OS max len + #define _MAX_PATH 1024 +#endif + + +//script flags +#define SCFL_NOERRORS 0x0001 +#define SCFL_NOWARNINGS 0x0002 +#define SCFL_NOSTRINGWHITESPACES 0x0004 +#define SCFL_NOSTRINGESCAPECHARS 0x0008 +#define SCFL_PRIMITIVE 0x0010 +#define SCFL_NOBINARYNUMBERS 0x0020 +#define SCFL_NONUMBERVALUES 0x0040 + +//token types +#define TT_STRING 1 // string +#define TT_LITERAL 2 // literal +#define TT_NUMBER 3 // number +#define TT_NAME 4 // name +#define TT_PUNCTUATION 5 // punctuation + +//string sub type +//--------------- +// the length of the string +//literal sub type +//---------------- +// the ASCII code of the literal +//number sub type +//--------------- +#define TT_DECIMAL 0x0008 // decimal number +#define TT_HEX 0x0100 // hexadecimal number +#define TT_OCTAL 0x0200 // octal number +#ifdef BINARYNUMBERS +#define TT_BINARY 0x0400 // binary number +#endif //BINARYNUMBERS +#define TT_FLOAT 0x0800 // floating point number +#define TT_INTEGER 0x1000 // integer number +#define TT_LONG 0x2000 // long number +#define TT_UNSIGNED 0x4000 // unsigned number +//punctuation sub type +//-------------------- +#define P_RSHIFT_ASSIGN 1 +#define P_LSHIFT_ASSIGN 2 +#define P_PARMS 3 +#define P_PRECOMPMERGE 4 + +#define P_LOGIC_AND 5 +#define P_LOGIC_OR 6 +#define P_LOGIC_GEQ 7 +#define P_LOGIC_LEQ 8 +#define P_LOGIC_EQ 9 +#define P_LOGIC_UNEQ 10 + +#define P_MUL_ASSIGN 11 +#define P_DIV_ASSIGN 12 +#define P_MOD_ASSIGN 13 +#define P_ADD_ASSIGN 14 +#define P_SUB_ASSIGN 15 +#define P_INC 16 +#define P_DEC 17 + +#define P_BIN_AND_ASSIGN 18 +#define P_BIN_OR_ASSIGN 19 +#define P_BIN_XOR_ASSIGN 20 +#define P_RSHIFT 21 +#define P_LSHIFT 22 + +#define P_POINTERREF 23 +#define P_CPP1 24 +#define P_CPP2 25 +#define P_MUL 26 +#define P_DIV 27 +#define P_MOD 28 +#define P_ADD 29 +#define P_SUB 30 +#define P_ASSIGN 31 + +#define P_BIN_AND 32 +#define P_BIN_OR 33 +#define P_BIN_XOR 34 +#define P_BIN_NOT 35 + +#define P_LOGIC_NOT 36 +#define P_LOGIC_GREATER 37 +#define P_LOGIC_LESS 38 + +#define P_REF 39 +#define P_COMMA 40 +#define P_SEMICOLON 41 +#define P_COLON 42 +#define P_QUESTIONMARK 43 + +#define P_PARENTHESESOPEN 44 +#define P_PARENTHESESCLOSE 45 +#define P_BRACEOPEN 46 +#define P_BRACECLOSE 47 +#define P_SQBRACKETOPEN 48 +#define P_SQBRACKETCLOSE 49 +#define P_BACKSLASH 50 + +#define P_PRECOMP 51 +#define P_DOLLAR 52 +//name sub type +//------------- +// the length of the name + +//punctuation +typedef struct punctuation_s +{ + char *p; //punctuation character(s) + int n; //punctuation indication + struct punctuation_s *next; //next punctuation +} punctuation_t; + +//token +typedef struct token_s +{ + char string[MAX_TOKEN]; //available token + int type; //last read token type + int subtype; //last read token sub type +#ifdef NUMBERVALUE + unsigned long int intvalue; //integer value + long double floatvalue; //floating point value +#endif //NUMBERVALUE + char *whitespace_p; //start of white space before token + char *endwhitespace_p; //start of white space before token + int line; //line the token was on + int linescrossed; //lines crossed in white space + struct token_s *next; //next token in chain +} token_t; + +//script file +typedef struct script_s +{ + char filename[_MAX_PATH]; //file name of the script + char *buffer; //buffer containing the script + char *script_p; //current pointer in the script + char *end_p; //pointer to the end of the script + char *lastscript_p; //script pointer before reading token + char *whitespace_p; //begin of the white space + char *endwhitespace_p; //end of the white space + int length; //length of the script in bytes + int line; //current line in script + int lastline; //line before reading token + int tokenavailable; //set by UnreadLastToken + int flags; //several script flags + punctuation_t *punctuations; //the punctuations used in the script + punctuation_t **punctuationtable; + token_t token; //available token + struct script_s *next; //next script in a chain +} script_t; + +//read a token from the script +int PS_ReadToken( script_t *script, token_t *token ); +//expect a certain token +int PS_ExpectTokenString( script_t *script, char *string ); +//expect a certain token type +int PS_ExpectTokenType( script_t *script, int type, int subtype, token_t *token ); +//expect a token +int PS_ExpectAnyToken( script_t *script, token_t *token ); +//returns true when the token is available +int PS_CheckTokenString( script_t *script, char *string ); +//returns true an reads the token when a token with the given type is available +int PS_CheckTokenType( script_t *script, int type, int subtype, token_t *token ); +//skip tokens until the given token string is read +int PS_SkipUntilString( script_t *script, char *string ); +//unread the last token read from the script +void PS_UnreadLastToken( script_t *script ); +//unread the given token +void PS_UnreadToken( script_t *script, token_t *token ); +//returns the next character of the read white space, returns NULL if none +char PS_NextWhiteSpaceChar( script_t *script ); +//remove any leading and trailing double quotes from the token +void StripDoubleQuotes( char *string ); +//remove any leading and trailing single quotes from the token +void StripSingleQuotes( char *string ); +//read a possible signed integer +signed long int ReadSignedInt( script_t *script ); +//read a possible signed floating point number +long double ReadSignedFloat( script_t *script ); +//set an array with punctuations, NULL restores default C/C++ set +void SetScriptPunctuations( script_t *script, punctuation_t *p ); +//set script flags +void SetScriptFlags( script_t *script, int flags ); +//get script flags +int GetScriptFlags( script_t *script ); +//reset a script +void ResetScript( script_t *script ); +//returns true if at the end of the script +int EndOfScript( script_t *script ); +//returns a pointer to the punctuation with the given number +char *PunctuationFromNum( script_t *script, int num ); +//load a script from the given file at the given offset with the given length +script_t *LoadScriptFile( const char *filename ); +//load a script from the given memory with the given length +script_t *LoadScriptMemory( char *ptr, int length, char *name ); +//free a script +void FreeScript( script_t *script ); +//set the base folder to load files from +void PS_SetBaseFolder( char *path ); +//print a script error with filename and line number +void QDECL ScriptError( script_t *script, char *str, ... ); +//print a script warning with filename and line number +void QDECL ScriptWarning( script_t *script, char *str, ... ); + + + diff --git a/Projects/Android/jni/rtcw/src/botlib/l_struct.c b/Projects/Android/jni/rtcw/src/botlib/l_struct.c new file mode 100644 index 0000000..a698f36 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/botlib/l_struct.c @@ -0,0 +1,507 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +/***************************************************************************** + * name: l_struct.c + * + * desc: structure reading / writing + * + * + *****************************************************************************/ + +#ifdef BOTLIB +#include "../game/q_shared.h" +#include "../game/botlib.h" //for the include of be_interface.h +#include "l_script.h" +#include "l_precomp.h" +#include "l_struct.h" +#include "l_utils.h" +#include "be_interface.h" +#endif //BOTLIB + +#ifdef BSPC +//include files for usage in the BSP Converter +#include "../bspc/qbsp.h" +#include "../bspc/l_log.h" +#include "../bspc/l_mem.h" +#include "l_precomp.h" +#include "l_struct.h" + +#define qtrue true +#define qfalse false +#endif //BSPC + +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +fielddef_t *FindField( fielddef_t *defs, char *name ) { + int i; + + for ( i = 0; defs[i].name; i++ ) + { + if ( !strcmp( defs[i].name, name ) ) { + return &defs[i]; + } + } //end for + return NULL; +} //end of the function FindField +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +qboolean ReadNumber( source_t *source, fielddef_t *fd, void *p ) { + token_t token; + int negative = qfalse; + long int intval, intmin = 0, intmax = 0; + double floatval; + + if ( !PC_ExpectAnyToken( source, &token ) ) { + return 0; + } + + //check for minus sign + if ( token.type == TT_PUNCTUATION ) { + if ( fd->type & FT_UNSIGNED ) { + SourceError( source, "expected unsigned value, found %s", token.string ); + return 0; + } //end if + //if not a minus sign + if ( strcmp( token.string, "-" ) ) { + SourceError( source, "unexpected punctuation %s", token.string ); + return 0; + } //end if + negative = qtrue; + //read the number + if ( !PC_ExpectAnyToken( source, &token ) ) { + return 0; + } + } //end if + //check if it is a number + if ( token.type != TT_NUMBER ) { + SourceError( source, "expected number, found %s", token.string ); + return 0; + } //end if + //check for a float value + if ( token.subtype & TT_FLOAT ) { + if ( ( fd->type & FT_TYPE ) != FT_FLOAT ) { + SourceError( source, "unexpected float" ); + return 0; + } //end if + floatval = token.floatvalue; + if ( negative ) { + floatval = -floatval; + } + if ( fd->type & FT_BOUNDED ) { + if ( floatval < fd->floatmin || floatval > fd->floatmax ) { + SourceError( source, "float out of range [%f, %f]", fd->floatmin, fd->floatmax ); + return 0; + } //end if + } //end if + *(float *) p = (float) floatval; + return 1; + } //end if + // + intval = token.intvalue; + if ( negative ) { + intval = -intval; + } + //check bounds + if ( ( fd->type & FT_TYPE ) == FT_CHAR ) { + if ( fd->type & FT_UNSIGNED ) { + intmin = 0; intmax = 255; + } else {intmin = -128; intmax = 127;} + } //end if + if ( ( fd->type & FT_TYPE ) == FT_INT ) { + if ( fd->type & FT_UNSIGNED ) { + intmin = 0; intmax = 65535; + } else {intmin = -32768; intmax = 32767;} + } //end else if + if ( ( fd->type & FT_TYPE ) == FT_CHAR || ( fd->type & FT_TYPE ) == FT_INT ) { + if ( fd->type & FT_BOUNDED ) { + intmin = Maximum( intmin, fd->floatmin ); + intmax = Minimum( intmax, fd->floatmax ); + } //end if + if ( intval < intmin || intval > intmax ) { + SourceError( source, "value %d out of range [%d, %d]", intval, intmin, intmax ); + return 0; + } //end if + } //end if + else if ( ( fd->type & FT_TYPE ) == FT_FLOAT ) { + if ( fd->type & FT_BOUNDED ) { + if ( intval < fd->floatmin || intval > fd->floatmax ) { + SourceError( source, "value %d out of range [%f, %f]", intval, fd->floatmin, fd->floatmax ); + return 0; + } //end if + } //end if + } //end else if + //store the value + if ( ( fd->type & FT_TYPE ) == FT_CHAR ) { + if ( fd->type & FT_UNSIGNED ) { + *(unsigned char *) p = (unsigned char) intval; + } else { *(char *) p = (char) intval;} + } //end if + else if ( ( fd->type & FT_TYPE ) == FT_INT ) { + if ( fd->type & FT_UNSIGNED ) { + *(unsigned int *) p = (unsigned int) intval; + } else { *(int *) p = (int) intval;} + } //end else + else if ( ( fd->type & FT_TYPE ) == FT_FLOAT ) { + *(float *) p = (float) intval; + } //end else + return 1; +} //end of the function ReadNumber +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +qboolean ReadChar( source_t *source, fielddef_t *fd, void *p ) { + token_t token; + + if ( !PC_ExpectAnyToken( source, &token ) ) { + return 0; + } + + //take literals into account + if ( token.type == TT_LITERAL ) { + StripSingleQuotes( token.string ); + *(char *) p = token.string[0]; + } //end if + else + { + PC_UnreadLastToken( source ); + if ( !ReadNumber( source, fd, p ) ) { + return 0; + } + } //end if + return 1; +} //end of the function ReadChar +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int ReadString( source_t *source, fielddef_t *fd, void *p ) { + token_t token; + + if ( !PC_ExpectTokenType( source, TT_STRING, 0, &token ) ) { + return 0; + } + //remove the double quotes + StripDoubleQuotes( token.string ); + //copy the string + strncpy( (char *) p, token.string, MAX_STRINGFIELD ); + //make sure the string is closed with a zero + ( (char *)p )[MAX_STRINGFIELD - 1] = '\0'; + // + return 1; +} //end of the function ReadString +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int ReadStructure( source_t *source, structdef_t *def, char *structure ) { + token_t token; + fielddef_t *fd; + void *p; + int num; + + if ( !PC_ExpectTokenString( source, "{" ) ) { + return 0; + } + while ( 1 ) + { + if ( !PC_ExpectAnyToken( source, &token ) ) { + return qfalse; + } + //if end of structure + if ( !strcmp( token.string, "}" ) ) { + break; + } + //find the field with the name + fd = FindField( def->fields, token.string ); + if ( !fd ) { + SourceError( source, "unknown structure field %s", token.string ); + return qfalse; + } //end if + if ( fd->type & FT_ARRAY ) { + num = fd->maxarray; + if ( !PC_ExpectTokenString( source, "{" ) ) { + return qfalse; + } + } //end if + else + { + num = 1; + } //end else + p = ( void * )( structure + fd->offset ); + while ( num-- > 0 ) + { + if ( fd->type & FT_ARRAY ) { + if ( PC_CheckTokenString( source, "}" ) ) { + break; + } + } //end if + switch ( fd->type & FT_TYPE ) + { + case FT_CHAR: + { + if ( !ReadChar( source, fd, p ) ) { + return qfalse; + } + p = (char *) p + sizeof( char ); + break; + } //end case + case FT_INT: + { + if ( !ReadNumber( source, fd, p ) ) { + return qfalse; + } + p = (char *) p + sizeof( int ); + break; + } //end case + case FT_FLOAT: + { + if ( !ReadNumber( source, fd, p ) ) { + return qfalse; + } + p = (char *) p + sizeof( float ); + break; + } //end case + case FT_STRING: + { + if ( !ReadString( source, fd, p ) ) { + return qfalse; + } + p = (char *) p + MAX_STRINGFIELD; + break; + } //end case + case FT_STRUCT: + { + if ( !fd->substruct ) { + SourceError( source, "BUG: no sub structure defined" ); + return qfalse; + } //end if + ReadStructure( source, fd->substruct, (char *) p ); + p = (char *) p + fd->substruct->size; + break; + } //end case + } //end switch + if ( fd->type & FT_ARRAY ) { + if ( !PC_ExpectAnyToken( source, &token ) ) { + return qfalse; + } + if ( !strcmp( token.string, "}" ) ) { + break; + } + if ( strcmp( token.string, "," ) ) { + SourceError( source, "expected a comma, found %s", token.string ); + return qfalse; + } //end if + } //end if + } //end while + } //end while + return qtrue; +} //end of the function ReadStructure +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int WriteIndent( FILE *fp, int indent ) { + while ( indent-- > 0 ) + { + if ( fprintf( fp, "\t" ) < 0 ) { + return qfalse; + } + } //end while + return qtrue; +} //end of the function WriteIndent +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int WriteFloat( FILE *fp, float value ) { + char buf[128]; + int l; + + sprintf( buf, "%f", value ); + l = strlen( buf ); + //strip any trailing zeros + while ( l-- > 1 ) + { + if ( buf[l] != '0' && buf[l] != '.' ) { + break; + } + if ( buf[l] == '.' ) { + buf[l] = 0; + break; + } //end if + buf[l] = 0; + } //end while + //write the float to file + if ( fprintf( fp, "%s", buf ) < 0 ) { + return 0; + } + return 1; +} //end of the function WriteFloat +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int WriteStructWithIndent( FILE *fp, structdef_t *def, char *structure, int indent ) { + int i, num; + void *p; + fielddef_t *fd; + + if ( !WriteIndent( fp, indent ) ) { + return qfalse; + } + if ( fprintf( fp, "{\r\n" ) < 0 ) { + return qfalse; + } + + indent++; + for ( i = 0; def->fields[i].name; i++ ) + { + fd = &def->fields[i]; + if ( !WriteIndent( fp, indent ) ) { + return qfalse; + } + if ( fprintf( fp, "%s\t", fd->name ) < 0 ) { + return qfalse; + } + p = ( void * )( structure + fd->offset ); + if ( fd->type & FT_ARRAY ) { + num = fd->maxarray; + if ( fprintf( fp, "{" ) < 0 ) { + return qfalse; + } + } //end if + else + { + num = 1; + } //end else + while ( num-- > 0 ) + { + switch ( fd->type & FT_TYPE ) + { + case FT_CHAR: + { + if ( fprintf( fp, "%d", *(char *) p ) < 0 ) { + return qfalse; + } + p = (char *) p + sizeof( char ); + break; + } //end case + case FT_INT: + { + if ( fprintf( fp, "%d", *(int *) p ) < 0 ) { + return qfalse; + } + p = (char *) p + sizeof( int ); + break; + } //end case + case FT_FLOAT: + { + if ( !WriteFloat( fp, *(float *)p ) ) { + return qfalse; + } + p = (char *) p + sizeof( float ); + break; + } //end case + case FT_STRING: + { + if ( fprintf( fp, "\"%s\"", (char *) p ) < 0 ) { + return qfalse; + } + p = (char *) p + MAX_STRINGFIELD; + break; + } //end case + case FT_STRUCT: + { + if ( !WriteStructWithIndent( fp, fd->substruct, structure, indent ) ) { + return qfalse; + } + p = (char *) p + fd->substruct->size; + break; + } //end case + } //end switch + if ( fd->type & FT_ARRAY ) { + if ( num > 0 ) { + if ( fprintf( fp, "," ) < 0 ) { + return qfalse; + } + } //end if + else + { + if ( fprintf( fp, "}" ) < 0 ) { + return qfalse; + } + } //end else + } //end if + } //end while + if ( fprintf( fp, "\r\n" ) < 0 ) { + return qfalse; + } + } //end for + indent--; + + if ( !WriteIndent( fp, indent ) ) { + return qfalse; + } + if ( fprintf( fp, "}\r\n" ) < 0 ) { + return qfalse; + } + return qtrue; +} //end of the function WriteStructWithIndent +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int WriteStructure( FILE *fp, structdef_t *def, char *structure ) { + return WriteStructWithIndent( fp, def, structure, 0 ); +} //end of the function WriteStructure + diff --git a/Projects/Android/jni/rtcw/src/botlib/l_struct.h b/Projects/Android/jni/rtcw/src/botlib/l_struct.h new file mode 100644 index 0000000..7b7f441 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/botlib/l_struct.h @@ -0,0 +1,81 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +/***************************************************************************** + * name: l_struct.h + * + * desc: structure reading/writing + * + * + *****************************************************************************/ + + +#define MAX_STRINGFIELD 80 +//field types +#define FT_CHAR 1 // char +#define FT_INT 2 // int +#define FT_FLOAT 3 // float +#define FT_STRING 4 // char [MAX_STRINGFIELD] +#define FT_STRUCT 6 // struct (sub structure) +//type only mask +#define FT_TYPE 0x00FF // only type, clear subtype +//sub types +#define FT_ARRAY 0x0100 // array of type +#define FT_BOUNDED 0x0200 // bounded value +#define FT_UNSIGNED 0x0400 + +//structure field definition +typedef struct fielddef_s +{ + char *name; //name of the field + int offset; //offset in the structure + int type; //type of the field + //type specific fields + int maxarray; //maximum array size + float floatmin, floatmax; //float min and max + struct structdef_s *substruct; //sub structure +} fielddef_t; + +//structure definition +typedef struct structdef_s +{ + int size; + fielddef_t *fields; +} structdef_t; + +//read a structure from a script +int ReadStructure( source_t *source, structdef_t *def, char *structure ); +//write a structure to a file +int WriteStructure( FILE *fp, structdef_t *def, char *structure ); +//writes indents +int WriteIndent( FILE *fp, int indent ); +//writes a float without traling zeros +int WriteFloat( FILE *fp, float value ); + + diff --git a/Projects/Android/jni/rtcw/src/botlib/l_utils.h b/Projects/Android/jni/rtcw/src/botlib/l_utils.h new file mode 100644 index 0000000..c419299 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/botlib/l_utils.h @@ -0,0 +1,41 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +/***************************************************************************** + * name: l_util.h + * + * desc: utils + * + * + *****************************************************************************/ + +#define Vector2Angles( v,a ) vectoangles( v,a ) +#define MAX_PATH MAX_QPATH +#define Maximum( x,y ) ( x > y ? x : y ) +#define Minimum( x,y ) ( x < y ? x : y ) diff --git a/Projects/Android/jni/rtcw/src/bspc/_files.c b/Projects/Android/jni/rtcw/src/bspc/_files.c new file mode 100644 index 0000000..d34525a --- /dev/null +++ b/Projects/Android/jni/rtcw/src/bspc/_files.c @@ -0,0 +1,91 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +//=========================================================================== +// +// Name: _files.c +// Function: +// Programmer: Mr Elusive +// Last update: 1999-12-02 +// Tab Size: 4 +//=========================================================================== + +/* + +aas_areamerging.c //AAS area merging +aas_cfg.c //AAS configuration for different games +aas_create.c //AAS creating +aas_edgemelting.c //AAS edge melting +aas_facemerging.c //AAS face merging +aas_file.c //AAS file writing +aas_gsubdiv.c //AAS gravitational and ladder subdivision +aas_map.c //AAS map brush creation +aas_prunenodes.c //AAS node pruning +aas_store.c //AAS file storing + +map.c //map file loading and writing +map_hl.c //Half-Life map loading +map_q1.c //Quake1 map loading +map_q2.c //Quake2 map loading +map_q3.c //Quake3 map loading +map_sin.c //Sin map loading +tree.c //BSP tree management + node pruning (*) +brushbsp.c //brush bsp creation (*) +portals.c //BSP portal creation and leaf filling (*) +csg.c //Constructive Solid Geometry brush chopping (*) +leakfile.c //leak file writing (*) +textures.c //Quake2 BSP textures (*) + +l_bsp_ent.c //BSP entity parsing +l_bsp_hl.c //Half-Life BSP loading and writing +l_bsp_q1.c //Quake1 BSP loading and writing +l_bsp_q2.c //Quake2 BSP loading and writing +l_bsp_q3.c //Quake2 BSP loading and writing +l_bsp_sin.c //Sin BSP loading and writing +l_cmd.c //cmd library +l_log.c //log file library +l_math.c //math library +l_mem.c //memory management library +l_poly.c //polygon (winding) library +l_script.c //script file parsing library +l_threads.c //multi-threading library +l_utils.c //utility library +l_qfiles.c //loading of quake files + +gldraw.c //GL drawing (*) +glfile.c //GL file writing (*) +nodraw.c //no draw module (*) + +bspc.c //BSPC Win32 console version +winbspc.c //WinBSPC Win32 GUI version +win32_terminal.c //Win32 terminal output +win32_qfiles.c //Win32 game file management (also .pak .sin) +win32_font.c //Win32 fonts +win32_folder.c //Win32 folder dialogs + +*/ diff --git a/Projects/Android/jni/rtcw/src/bspc/aas_areamerging.c b/Projects/Android/jni/rtcw/src/bspc/aas_areamerging.c new file mode 100644 index 0000000..f3e3c9f --- /dev/null +++ b/Projects/Android/jni/rtcw/src/bspc/aas_areamerging.c @@ -0,0 +1,424 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +//=========================================================================== +// +// Name: aas_areamerging.c +// Function: Merging of Areas +// Programmer: Mr Elusive (MrElusive@demigod.demon.nl) +// Last update: 1997-12-04 +// Tab Size: 3 +//=========================================================================== + +#include "qbsp.h" +#include "../botlib/aasfile.h" +#include "aas_create.h" +#include "aas_store.h" + +#define CONVEX_EPSILON 0.3 + +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +tmp_node_t *AAS_RefreshMergedTree_r( tmp_node_t *tmpnode ) { + tmp_area_t *tmparea; + + //if this is a solid leaf + if ( !tmpnode ) { + return NULL; + } + //if this is an area leaf + if ( tmpnode->tmparea ) { + tmparea = tmpnode->tmparea; + while ( tmparea->mergedarea ) tmparea = tmparea->mergedarea; + tmpnode->tmparea = tmparea; + return tmpnode; + } //end if + //do the children recursively + tmpnode->children[0] = AAS_RefreshMergedTree_r( tmpnode->children[0] ); + tmpnode->children[1] = AAS_RefreshMergedTree_r( tmpnode->children[1] ); + return tmpnode; +} //end of the function AAS_RefreshMergedTree_r +//=========================================================================== +// returns true if the two given faces would create a non-convex area at +// the given sides, otherwise false is returned +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int NonConvex( tmp_face_t *face1, tmp_face_t *face2, int side1, int side2 ) { + int i; + winding_t *w1, *w2; + plane_t *plane1, *plane2; + + w1 = face1->winding; + w2 = face2->winding; + + plane1 = &mapplanes[face1->planenum ^ side1]; + plane2 = &mapplanes[face2->planenum ^ side2]; + + //check if one of the points of face1 is at the back of the plane of face2 + for ( i = 0; i < w1->numpoints; i++ ) + { + if ( DotProduct( plane2->normal, w1->p[i] ) - plane2->dist < -CONVEX_EPSILON ) { + return true; + } + } //end for + //check if one of the points of face2 is at the back of the plane of face1 + for ( i = 0; i < w2->numpoints; i++ ) + { + if ( DotProduct( plane1->normal, w2->p[i] ) - plane1->dist < -CONVEX_EPSILON ) { + return true; + } + } //end for + + return false; +} //end of the function NonConvex +//=========================================================================== +// try to merge the areas at both sides of the given face +// +// Parameter: seperatingface : face that seperates two areas +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_TryMergeFaceAreas( tmp_face_t *seperatingface ) { + int side1, side2, area1faceflags, area2faceflags; + tmp_area_t *tmparea1, *tmparea2, *newarea; + tmp_face_t *face1, *face2, *nextface1, *nextface2; + + tmparea1 = seperatingface->frontarea; + tmparea2 = seperatingface->backarea; + + //areas must have the same presence type + if ( tmparea1->presencetype != tmparea2->presencetype ) { + return false; + } + //areas must have the same area contents + if ( tmparea1->contents != tmparea2->contents ) { + return false; + } + //areas must have the same bsp model inside (or both none) + if ( tmparea1->modelnum != tmparea2->modelnum ) { + return false; + } + + area1faceflags = 0; + area2faceflags = 0; + for ( face1 = tmparea1->tmpfaces; face1; face1 = face1->next[side1] ) + { + side1 = ( face1->frontarea != tmparea1 ); + //debug: check if the area belongs to the area + if ( face1->frontarea != tmparea1 && + face1->backarea != tmparea1 ) { + Error( "face does not belong to area1" ); + } + //just continue if the face is seperating the two areas + //NOTE: a result of this is that ground and gap areas can + // be merged if the seperating face is the gap + if ( ( face1->frontarea == tmparea1 && + face1->backarea == tmparea2 ) || + ( face1->frontarea == tmparea2 && + face1->backarea == tmparea1 ) ) { + continue; + } + //get area1 face flags + area1faceflags |= face1->faceflags; + if ( AAS_GapFace( face1, side1 ) ) { + area1faceflags |= FACE_GAP; + } + // + for ( face2 = tmparea2->tmpfaces; face2; face2 = face2->next[side2] ) + { + side2 = ( face2->frontarea != tmparea2 ); + //debug: check if the area belongs to the area + if ( face2->frontarea != tmparea2 && + face2->backarea != tmparea2 ) { + Error( "face does not belong to area2" ); + } + //just continue if the face is seperating the two areas + //NOTE: a result of this is that ground and gap areas can + // be merged if the seperating face is the gap + if ( ( face2->frontarea == tmparea1 && + face2->backarea == tmparea2 ) || + ( face2->frontarea == tmparea2 && + face2->backarea == tmparea1 ) ) { + continue; + } + //get area2 face flags + area2faceflags |= face2->faceflags; + if ( AAS_GapFace( face2, side2 ) ) { + area2faceflags |= FACE_GAP; + } + //if the two faces would create a non-convex area + if ( NonConvex( face1, face2, side1, side2 ) ) { + return false; + } + } //end for + } //end for + //if one area has gap faces (that aren't seperating the two areas) + //and the other has ground faces (that aren't seperating the two areas), + //the areas can't be merged + if ( ( ( area1faceflags & FACE_GROUND ) && ( area2faceflags & FACE_GAP ) ) || + ( ( area2faceflags & FACE_GROUND ) && ( area1faceflags & FACE_GAP ) ) ) { +// Log_Print(" can't merge: ground/gap\n"); + return false; + } //end if + +// Log_Print("merged area %d & %d to %d with %d faces\n", tmparea1->areanum, tmparea2->areanum, newarea->areanum, numfaces); +// return false; + // + //AAS_CheckArea(tmparea1); + //AAS_CheckArea(tmparea2); + //create the new area + newarea = AAS_AllocTmpArea(); + newarea->presencetype = tmparea1->presencetype; + newarea->contents = tmparea1->contents; + newarea->modelnum = tmparea1->modelnum; + newarea->tmpfaces = NULL; + + //add all the faces (except the seperating ones) from the first area + //to the new area + for ( face1 = tmparea1->tmpfaces; face1; face1 = nextface1 ) + { + side1 = ( face1->frontarea != tmparea1 ); + nextface1 = face1->next[side1]; + //don't add seperating faces + if ( ( face1->frontarea == tmparea1 && + face1->backarea == tmparea2 ) || + ( face1->frontarea == tmparea2 && + face1->backarea == tmparea1 ) ) { + continue; + } //end if + // + AAS_RemoveFaceFromArea( face1, tmparea1 ); + AAS_AddFaceSideToArea( face1, side1, newarea ); + } //end for + //add all the faces (except the seperating ones) from the second area + //to the new area + for ( face2 = tmparea2->tmpfaces; face2; face2 = nextface2 ) + { + side2 = ( face2->frontarea != tmparea2 ); + nextface2 = face2->next[side2]; + //don't add seperating faces + if ( ( face2->frontarea == tmparea1 && + face2->backarea == tmparea2 ) || + ( face2->frontarea == tmparea2 && + face2->backarea == tmparea1 ) ) { + continue; + } //end if + // + AAS_RemoveFaceFromArea( face2, tmparea2 ); + AAS_AddFaceSideToArea( face2, side2, newarea ); + } //end for + //free all shared faces + for ( face1 = tmparea1->tmpfaces; face1; face1 = nextface1 ) + { + side1 = ( face1->frontarea != tmparea1 ); + nextface1 = face1->next[side1]; + // + AAS_RemoveFaceFromArea( face1, face1->frontarea ); + AAS_RemoveFaceFromArea( face1, face1->backarea ); + AAS_FreeTmpFace( face1 ); + } //end for + // + tmparea1->mergedarea = newarea; + tmparea1->invalid = true; + tmparea2->mergedarea = newarea; + tmparea2->invalid = true; + // + AAS_CheckArea( newarea ); + AAS_FlipAreaFaces( newarea ); +// Log_Print("merged area %d & %d to %d with %d faces\n", tmparea1->areanum, tmparea2->areanum, newarea->areanum); + return true; +} //end of the function AAS_TryMergeFaceAreas +//=========================================================================== +// try to merge areas +// merged areas are added to the end of the convex area list so merging +// will be tried for those areas as well +// +// Parameter: - +// Returns: - +// Changes Globals: tmpaasworld +//=========================================================================== +/* +void AAS_MergeAreas(void) +{ + int side, nummerges; + tmp_area_t *tmparea, *othertmparea; + tmp_face_t *face; + + nummerges = 0; + Log_Write("AAS_MergeAreas\r\n"); + qprintf("%6d areas merged", 1); + //first merge grounded areas only + //NOTE: this is useless because the area settings aren't available yet + for (tmparea = tmpaasworld.areas; tmparea; tmparea = tmparea->l_next) + { +// Log_Print("checking area %d\n", i); + //if the area is invalid + if (tmparea->invalid) + { +// Log_Print(" area invalid\n"); + continue; + } //end if + // +// if (!(tmparea->settings->areaflags & AREA_GROUNDED)) continue; + // + for (face = tmparea->tmpfaces; face; face = face->next[side]) + { + side = (face->frontarea != tmparea); + //if the face has both a front and back area + if (face->frontarea && face->backarea) + { + // + if (face->frontarea == tmparea) othertmparea = face->backarea; + else othertmparea = face->frontarea; +// if (!(othertmparea->settings->areaflags & AREA_GROUNDED)) continue; +// Log_Print(" checking area %d with %d\n", face->frontarea, face->backarea); + if (AAS_TryMergeFaceAreas(face)) + { + qprintf("\r%6d", ++nummerges); + break; + } //end if + } //end if + } //end for + } //end for + //merge all areas + for (tmparea = tmpaasworld.areas; tmparea; tmparea = tmparea->l_next) + { +// Log_Print("checking area %d\n", i); + //if the area is invalid + if (tmparea->invalid) + { +// Log_Print(" area invalid\n"); + continue; + } //end if + // + for (face = tmparea->tmpfaces; face; face = face->next[side]) + { + side = (face->frontarea != tmparea); + //if the face has both a front and back area + if (face->frontarea && face->backarea) + { +// Log_Print(" checking area %d with %d\n", face->frontarea, face->backarea); + if (AAS_TryMergeFaceAreas(face)) + { + qprintf("\r%6d", ++nummerges); + break; + } //end if + } //end if + } //end for + } //end for + Log_Print("\r%6d areas merged\n", nummerges); + //refresh the merged tree + AAS_RefreshMergedTree_r(tmpaasworld.nodes); +} //end of the function AAS_MergeAreas*/ + +int AAS_GroundArea( tmp_area_t *tmparea ) { + tmp_face_t *face; + int side; + + for ( face = tmparea->tmpfaces; face; face = face->next[side] ) + { + side = ( face->frontarea != tmparea ); + if ( face->faceflags & FACE_GROUND ) { + return true; + } + } //end for + return false; +} //end of the function AAS_GroundArea + +void AAS_MergeAreas( void ) { + int side, nummerges, merges, groundfirst; + tmp_area_t *tmparea, *othertmparea; + tmp_face_t *face; + + nummerges = 0; + Log_Write( "AAS_MergeAreas\r\n" ); + qprintf( "%6d areas merged", 1 ); + // + groundfirst = true; + //for (i = 0; i < 4 || merges; i++) + while ( 1 ) + { + //if (i < 2) groundfirst = true; + //else groundfirst = false; + // + merges = 0; + //first merge grounded areas only + for ( tmparea = tmpaasworld.areas; tmparea; tmparea = tmparea->l_next ) + { + //if the area is invalid + if ( tmparea->invalid ) { + continue; + } //end if + // + if ( groundfirst ) { + if ( !AAS_GroundArea( tmparea ) ) { + continue; + } + } //end if + // + for ( face = tmparea->tmpfaces; face; face = face->next[side] ) + { + side = ( face->frontarea != tmparea ); + //if the face has both a front and back area + if ( face->frontarea && face->backarea ) { + // + if ( face->frontarea == tmparea ) { + othertmparea = face->backarea; + } else { othertmparea = face->frontarea;} + // + if ( groundfirst ) { + if ( !AAS_GroundArea( othertmparea ) ) { + continue; + } + } //end if + if ( AAS_TryMergeFaceAreas( face ) ) { + qprintf( "\r%6d", ++nummerges ); + merges++; + break; + } //end if + } //end if + } //end for + } //end for + if ( !merges ) { + if ( groundfirst ) { + groundfirst = false; + } else { break;} + } //end if + } //end for + qprintf( "\n" ); + Log_Write( "%6d areas merged\r\n", nummerges ); + //refresh the merged tree + AAS_RefreshMergedTree_r( tmpaasworld.nodes ); +} //end of the function AAS_MergeAreas diff --git a/Projects/Android/jni/rtcw/src/bspc/aas_areamerging.h b/Projects/Android/jni/rtcw/src/bspc/aas_areamerging.h new file mode 100644 index 0000000..4221942 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/bspc/aas_areamerging.h @@ -0,0 +1,40 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +//=========================================================================== +// +// Name: aas_areamerging.h +// Function: Merging of Areas +// Programmer: Mr Elusive (MrElusive@demigod.demon.nl) +// Last update: 1997-12-04 +// Tab Size: 3 +//=========================================================================== + + +void AAS_MergeAreas( void ); + diff --git a/Projects/Android/jni/rtcw/src/bspc/aas_cfg.c b/Projects/Android/jni/rtcw/src/bspc/aas_cfg.c new file mode 100644 index 0000000..2388787 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/bspc/aas_cfg.c @@ -0,0 +1,317 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +//=========================================================================== +// +// Name: cfg.c +// Function: +// Programmer: Mr Elusive (MrElusive@demigod.demon.nl) +// Last update: 1997-12-04 +// Tab Size: 3 +//=========================================================================== + +#include "qbsp.h" +#include "float.h" +#include "../botlib/aasfile.h" +#include "aas_store.h" +#include "aas_cfg.h" +#include "../botlib/l_precomp.h" +#include "../botlib/l_struct.h" +#include "../botlib/l_libvar.h" + +// TTimo: this is a f*g mess +// I got rid of all occurences except for bspc it seems +// all code *should* be using Q_stricmp +#ifdef BSPC +#define stricmp strcasecmp +#endif + +/////////////////////////////////// +extern void LibVarSet( char *var_name, char *value ); +/////////////////////////////////// + +//structure field offsets +#define BBOX_OFS( x ) (int)&( ( (aas_bbox_t *)0 )->x ) +#define CFG_OFS( x ) (int)&( ( (cfg_t *)0 )->x ) + +//bounding box definition +fielddef_t bbox_fields[] = +{ + {"presencetype", BBOX_OFS( presencetype ), FT_INT}, + {"flags", BBOX_OFS( flags ), FT_INT}, + {"mins", BBOX_OFS( mins ), FT_FLOAT | FT_ARRAY, 3}, + {"maxs", BBOX_OFS( maxs ), FT_FLOAT | FT_ARRAY, 3}, + {NULL, 0, 0, 0} +}; + +fielddef_t cfg_fields[] = +{ + {"phys_gravitydirection", CFG_OFS( phys_gravitydirection ), FT_FLOAT | FT_ARRAY, 3}, + {"phys_friction", CFG_OFS( phys_friction ), FT_FLOAT}, + {"phys_stopspeed", CFG_OFS( phys_stopspeed ), FT_FLOAT}, + {"phys_gravity", CFG_OFS( phys_gravity ), FT_FLOAT}, + {"phys_waterfriction", CFG_OFS( phys_waterfriction ), FT_FLOAT}, + {"phys_watergravity", CFG_OFS( phys_watergravity ), FT_FLOAT}, + {"phys_maxvelocity", CFG_OFS( phys_maxvelocity ), FT_FLOAT}, + {"phys_maxwalkvelocity", CFG_OFS( phys_maxwalkvelocity ), FT_FLOAT}, + {"phys_maxcrouchvelocity", CFG_OFS( phys_maxcrouchvelocity ), FT_FLOAT}, + {"phys_maxswimvelocity", CFG_OFS( phys_maxswimvelocity ), FT_FLOAT}, + {"phys_walkaccelerate", CFG_OFS( phys_walkaccelerate ), FT_FLOAT}, + {"phys_airaccelerate", CFG_OFS( phys_airaccelerate ), FT_FLOAT}, + {"phys_swimaccelerate", CFG_OFS( phys_swimaccelerate ), FT_FLOAT}, + {"phys_maxstep", CFG_OFS( phys_maxstep ), FT_FLOAT}, + {"phys_maxsteepness", CFG_OFS( phys_maxsteepness ), FT_FLOAT}, + {"phys_maxwaterjump", CFG_OFS( phys_maxwaterjump ), FT_FLOAT}, + {"phys_maxbarrier", CFG_OFS( phys_maxbarrier ), FT_FLOAT}, + {"phys_jumpvel", CFG_OFS( phys_jumpvel ), FT_FLOAT}, + {"phys_falldelta5", CFG_OFS( phys_falldelta5 ), FT_FLOAT}, + {"phys_falldelta10", CFG_OFS( phys_falldelta10 ), FT_FLOAT}, + {"rs_waterjump", CFG_OFS( rs_waterjump ), FT_FLOAT}, + {"rs_teleport", CFG_OFS( rs_teleport ), FT_FLOAT}, + {"rs_barrierjump", CFG_OFS( rs_barrierjump ), FT_FLOAT}, + {"rs_startcrouch", CFG_OFS( rs_startcrouch ), FT_FLOAT}, + {"rs_startgrapple", CFG_OFS( rs_startgrapple ), FT_FLOAT}, + {"rs_startwalkoffledge", CFG_OFS( rs_startwalkoffledge ), FT_FLOAT}, + {"rs_startjump", CFG_OFS( rs_startjump ), FT_FLOAT}, + {"rs_rocketjump", CFG_OFS( rs_rocketjump ), FT_FLOAT}, + {"rs_bfgjump", CFG_OFS( rs_bfgjump ), FT_FLOAT}, + {"rs_jumppad", CFG_OFS( rs_jumppad ), FT_FLOAT}, + {"rs_aircontrolledjumppad", CFG_OFS( rs_aircontrolledjumppad ), FT_FLOAT}, + {"rs_funcbob", CFG_OFS( rs_funcbob ), FT_FLOAT}, + {"rs_startelevator", CFG_OFS( rs_startelevator ), FT_FLOAT}, + {"rs_falldamage5", CFG_OFS( rs_falldamage5 ), FT_FLOAT}, + {"rs_falldamage10", CFG_OFS( rs_falldamage10 ), FT_FLOAT}, + {"rs_maxjumpfallheight", CFG_OFS( rs_maxjumpfallheight ), FT_FLOAT}, + {"rs_allowladders", CFG_OFS( rs_allowladders ), FT_INT}, + {NULL, 0, 0, 0} +}; + +structdef_t bbox_struct = +{ + sizeof( aas_bbox_t ), bbox_fields +}; +structdef_t cfg_struct = +{ + sizeof( cfg_t ), cfg_fields +}; + +//global cfg +cfg_t cfg; + +#if 0 +//=========================================================================== +// the default Q3A configuration +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void DefaultCfg( void ) { + int i; + + // default all float values to infinite + for ( i = 0; cfg_fields[i].name; i++ ) + { + if ( ( cfg_fields[i].type & FT_TYPE ) == FT_FLOAT ) { + *( float * )( ( (char*)&cfg ) + cfg_fields[i].offset ) = FLT_MAX; + } + } //end for + // + cfg.numbboxes = 2; + //bbox 0 + cfg.bboxes[0].presencetype = PRESENCE_NORMAL; + cfg.bboxes[0].flags = 0; + cfg.bboxes[0].mins[0] = -18; + cfg.bboxes[0].mins[1] = -18; + cfg.bboxes[0].mins[2] = -24; + cfg.bboxes[0].maxs[0] = 18; + cfg.bboxes[0].maxs[1] = 18; + cfg.bboxes[0].maxs[2] = 48; + //bbox 1 + cfg.bboxes[1].presencetype = PRESENCE_CROUCH; + cfg.bboxes[1].flags = 1; + cfg.bboxes[1].mins[0] = -18; + cfg.bboxes[1].mins[1] = -18; + cfg.bboxes[1].mins[2] = -24; + cfg.bboxes[1].maxs[0] = 18; + cfg.bboxes[1].maxs[1] = 18; + cfg.bboxes[1].maxs[2] = 24; + // + cfg.allpresencetypes = PRESENCE_NORMAL | PRESENCE_CROUCH; + cfg.phys_gravitydirection[0] = 0; + cfg.phys_gravitydirection[1] = 0; + cfg.phys_gravitydirection[2] = -1; + cfg.phys_maxsteepness = 0.7; + +// cfg.phys_maxbarrier = -999;//32; // RIDAH: this is calculated at run-time now, from the gravity and jump velocity settings +} //end of the function DefaultCfg +#else +//=========================================================================== +// the default Q3A configuration +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void DefaultCfg( void ) { + int i; + + // default all float values to infinite + for ( i = 0; cfg_fields[i].name; i++ ) + { + if ( ( cfg_fields[i].type & FT_TYPE ) == FT_FLOAT ) { + *( float * )( ( (char*)&cfg ) + cfg_fields[i].offset ) = FLT_MAX; + } + } //end for + // + cfg.numbboxes = 2; + //bbox 0 + cfg.bboxes[0].presencetype = PRESENCE_NORMAL; + cfg.bboxes[0].flags = 0; + cfg.bboxes[0].mins[0] = -15; + cfg.bboxes[0].mins[1] = -15; + cfg.bboxes[0].mins[2] = -24; + cfg.bboxes[0].maxs[0] = 15; + cfg.bboxes[0].maxs[1] = 15; + cfg.bboxes[0].maxs[2] = 32; + //bbox 1 + cfg.bboxes[1].presencetype = PRESENCE_CROUCH; + cfg.bboxes[1].flags = 1; + cfg.bboxes[1].mins[0] = -15; + cfg.bboxes[1].mins[1] = -15; + cfg.bboxes[1].mins[2] = -24; + cfg.bboxes[1].maxs[0] = 15; + cfg.bboxes[1].maxs[1] = 15; + cfg.bboxes[1].maxs[2] = 16; + // + cfg.allpresencetypes = PRESENCE_NORMAL | PRESENCE_CROUCH; + cfg.phys_gravitydirection[0] = 0; + cfg.phys_gravitydirection[1] = 0; + cfg.phys_gravitydirection[2] = -1; + cfg.phys_maxsteepness = 0.7; + +// cfg.phys_maxbarrier = -999;//32; // RIDAH: this is calculated at run-time now, from the gravity and jump velocity settings +} //end of the function DefaultCfg +#endif + +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +char * QDECL va( char *format, ... ) { + va_list argptr; + static char string[2][32000]; // in case va is called by nested functions + static int index = 0; + char *buf; + + buf = string[index & 1]; + index++; + + va_start( argptr, format ); + vsprintf( buf, format,argptr ); + va_end( argptr ); + + return buf; +} //end of the function va +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void SetCfgLibVars( void ) { + int i; + float value; + + for ( i = 0; cfg_fields[i].name; i++ ) + { + if ( ( cfg_fields[i].type & FT_TYPE ) == FT_FLOAT ) { + value = *( float * )( ( (char*)&cfg ) + cfg_fields[i].offset ); + if ( value != FLT_MAX ) { + LibVarSet( cfg_fields[i].name, va( "%f", value ) ); + } //end if + } //end if + } //end for +} //end of the function SetCfgLibVars +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int LoadCfgFile( char *filename ) { + source_t *source; + token_t token; + int settingsdefined; + + source = LoadSourceFile( filename ); + if ( !source ) { + Log_Print( "couldn't open cfg file %s\n", filename ); + return false; + } //end if + + settingsdefined = false; + memset( &cfg, 0, sizeof( cfg_t ) ); + + while ( PC_ReadToken( source, &token ) ) + { + if ( !stricmp( token.string, "bbox" ) ) { + if ( cfg.numbboxes >= AAS_MAX_BBOXES ) { + SourceError( source, "too many bounding box volumes defined" ); + } //end if + if ( !ReadStructure( source, &bbox_struct, (char *) &cfg.bboxes[cfg.numbboxes] ) ) { + FreeSource( source ); + return false; + } //end if + cfg.allpresencetypes |= cfg.bboxes[cfg.numbboxes].presencetype; + cfg.numbboxes++; + } //end if + else if ( !stricmp( token.string, "settings" ) ) { + if ( settingsdefined ) { + SourceWarning( source, "settings already defined\n" ); + } //end if + settingsdefined = true; + if ( !ReadStructure( source, &cfg_struct, (char *) &cfg ) ) { + FreeSource( source ); + return false; + } //end if + } //end else if + } //end while + if ( VectorLength( cfg.phys_gravitydirection ) < 0.9 || VectorLength( cfg.phys_gravitydirection ) > 1.1 ) { + SourceError( source, "invalid gravity direction specified" ); + } //end if + if ( cfg.numbboxes <= 0 ) { + SourceError( source, "no bounding volumes specified" ); + } //end if + FreeSource( source ); + SetCfgLibVars(); + Log_Print( "using cfg file %s\n", filename ); + return true; +} //end of the function LoadCfgFile diff --git a/Projects/Android/jni/rtcw/src/bspc/aas_cfg.h b/Projects/Android/jni/rtcw/src/bspc/aas_cfg.h new file mode 100644 index 0000000..e14c419 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/bspc/aas_cfg.h @@ -0,0 +1,89 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +//=========================================================================== +// +// Name: cfg.h +// Function: +// Programmer: Mr Elusive (MrElusive@demigod.demon.nl) +// Last update: 1997-12-04 +// Tab Size: 3 +//=========================================================================== + +#define BBOXFL_GROUNDED 1 //bounding box only valid when on ground +#define BBOXFL_NOTGROUNDED 2 //bounding box only valid when NOT on ground + +typedef struct cfg_s +{ + int numbboxes; //number of bounding boxes + aas_bbox_t bboxes[AAS_MAX_BBOXES]; //all the bounding boxes + int allpresencetypes; //or of all presence types + // aas settings + vec3_t phys_gravitydirection; + float phys_friction; + float phys_stopspeed; + float phys_gravity; + float phys_waterfriction; + float phys_watergravity; + float phys_maxvelocity; + float phys_maxwalkvelocity; + float phys_maxcrouchvelocity; + float phys_maxswimvelocity; + float phys_walkaccelerate; + float phys_airaccelerate; + float phys_swimaccelerate; + float phys_maxstep; + float phys_maxsteepness; + float phys_maxwaterjump; + float phys_maxbarrier; + float phys_jumpvel; + float phys_falldelta5; + float phys_falldelta10; + float rs_waterjump; + float rs_teleport; + float rs_barrierjump; + float rs_startcrouch; + float rs_startgrapple; + float rs_startwalkoffledge; + float rs_startjump; + float rs_rocketjump; + float rs_bfgjump; + float rs_jumppad; + float rs_aircontrolledjumppad; + float rs_funcbob; + float rs_startelevator; + float rs_falldamage5; + float rs_falldamage10; + float rs_maxjumpfallheight; + qboolean rs_allowladders; +} cfg_t; + +extern cfg_t cfg; + +void DefaultCfg( void ); +int LoadCfgFile( char *filename ); diff --git a/Projects/Android/jni/rtcw/src/bspc/aas_create.c b/Projects/Android/jni/rtcw/src/bspc/aas_create.c new file mode 100644 index 0000000..bdf6bd0 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/bspc/aas_create.c @@ -0,0 +1,1180 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +//=========================================================================== +// +// Name: aas_create.c +// Function: Creation of AAS +// Programmer: Mr Elusive (MrElusive@demigod.demon.nl) +// Last update: 1997-12-04 +// Tab Size: 3 +//=========================================================================== + +#include "qbsp.h" +#include "../botlib/aasfile.h" +#include "aas_create.h" +#include "aas_store.h" +#include "aas_gsubdiv.h" +#include "aas_facemerging.h" +#include "aas_areamerging.h" +#include "aas_edgemelting.h" +#include "aas_prunenodes.h" +#include "aas_cfg.h" +#include "../game/surfaceflags.h" + +#define AREAONFACESIDE( face, area ) ( face->frontarea != area ) + +tmp_aas_t tmpaasworld; + +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_InitTmpAAS( void ) { + //tmp faces + tmpaasworld.numfaces = 0; + tmpaasworld.facenum = 0; + tmpaasworld.faces = NULL; + //tmp convex areas + tmpaasworld.numareas = 0; + tmpaasworld.areanum = 0; + tmpaasworld.areas = NULL; + //tmp nodes + tmpaasworld.numnodes = 0; + tmpaasworld.nodes = NULL; + // + tmpaasworld.nodebuffer = NULL; +} //end of the function AAS_InitTmpAAS +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_FreeTmpAAS( void ) { + tmp_face_t *f, *nextf; + tmp_area_t *a, *nexta; + tmp_nodebuf_t *nb, *nextnb; + + //free all the faces + for ( f = tmpaasworld.faces; f; f = nextf ) + { + nextf = f->l_next; + if ( f->winding ) { + FreeWinding( f->winding ); + } + FreeMemory( f ); + } //end if + //free all tmp areas + for ( a = tmpaasworld.areas; a; a = nexta ) + { + nexta = a->l_next; + if ( a->settings ) { + FreeMemory( a->settings ); + } + FreeMemory( a ); + } //end for + //free all the tmp nodes + for ( nb = tmpaasworld.nodebuffer; nb; nb = nextnb ) + { + nextnb = nb->next; + FreeMemory( nb ); + } //end for +} //end of the function AAS_FreeTmpAAS +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +tmp_face_t *AAS_AllocTmpFace( void ) { + tmp_face_t *tmpface; + + tmpface = (tmp_face_t *) GetClearedMemory( sizeof( tmp_face_t ) ); + tmpface->num = tmpaasworld.facenum++; + tmpface->l_prev = NULL; + tmpface->l_next = tmpaasworld.faces; + if ( tmpaasworld.faces ) { + tmpaasworld.faces->l_prev = tmpface; + } + tmpaasworld.faces = tmpface; + tmpaasworld.numfaces++; + return tmpface; +} //end of the function AAS_AllocTmpFace +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_FreeTmpFace( tmp_face_t *tmpface ) { + if ( tmpface->l_next ) { + tmpface->l_next->l_prev = tmpface->l_prev; + } + if ( tmpface->l_prev ) { + tmpface->l_prev->l_next = tmpface->l_next; + } else { tmpaasworld.faces = tmpface->l_next;} + //free the winding + if ( tmpface->winding ) { + FreeWinding( tmpface->winding ); + } + //free the face + FreeMemory( tmpface ); + tmpaasworld.numfaces--; +} //end of the function AAS_FreeTmpFace +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +tmp_area_t *AAS_AllocTmpArea( void ) { + tmp_area_t *tmparea; + + tmparea = (tmp_area_t *) GetClearedMemory( sizeof( tmp_area_t ) ); + tmparea->areanum = tmpaasworld.areanum++; + tmparea->l_prev = NULL; + tmparea->l_next = tmpaasworld.areas; + if ( tmpaasworld.areas ) { + tmpaasworld.areas->l_prev = tmparea; + } + tmpaasworld.areas = tmparea; + tmpaasworld.numareas++; + return tmparea; +} //end of the function AAS_AllocTmpArea +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_FreeTmpArea( tmp_area_t *tmparea ) { + if ( tmparea->l_next ) { + tmparea->l_next->l_prev = tmparea->l_prev; + } + if ( tmparea->l_prev ) { + tmparea->l_prev->l_next = tmparea->l_next; + } else { tmpaasworld.areas = tmparea->l_next;} + if ( tmparea->settings ) { + FreeMemory( tmparea->settings ); + } + FreeMemory( tmparea ); + tmpaasworld.numareas--; +} //end of the function AAS_FreeTmpArea +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +tmp_node_t *AAS_AllocTmpNode( void ) { + tmp_nodebuf_t *nodebuf; + + if ( !tmpaasworld.nodebuffer || + tmpaasworld.nodebuffer->numnodes >= NODEBUF_SIZE ) { + nodebuf = (tmp_nodebuf_t *) GetClearedMemory( sizeof( tmp_nodebuf_t ) ); + nodebuf->next = tmpaasworld.nodebuffer; + nodebuf->numnodes = 0; + tmpaasworld.nodebuffer = nodebuf; + } //end if + tmpaasworld.numnodes++; + return &tmpaasworld.nodebuffer->nodes[tmpaasworld.nodebuffer->numnodes++]; +} //end of the function AAS_AllocTmpNode +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_FreeTmpNode( tmp_node_t *tmpnode ) { + tmpaasworld.numnodes--; +} //end of the function AAS_FreeTmpNode +//=========================================================================== +// returns true if the face is a gap from the given side +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_GapFace( tmp_face_t *tmpface, int side ) { + vec3_t invgravity; + + //if the face is a solid or ground face it can't be a gap + if ( tmpface->faceflags & ( FACE_GROUND | FACE_SOLID ) ) { + return 0; + } + + VectorCopy( cfg.phys_gravitydirection, invgravity ); + VectorInverse( invgravity ); + + return ( DotProduct( invgravity, mapplanes[tmpface->planenum ^ side].normal ) > cfg.phys_maxsteepness ); +} //end of the function AAS_GapFace +//=========================================================================== +// returns true if the face is a ground face +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_GroundFace( tmp_face_t *tmpface ) { + vec3_t invgravity; + + //must be a solid face + if ( !( tmpface->faceflags & FACE_SOLID ) ) { + return 0; + } + + VectorCopy( cfg.phys_gravitydirection, invgravity ); + VectorInverse( invgravity ); + + return ( DotProduct( invgravity, mapplanes[tmpface->planenum].normal ) > cfg.phys_maxsteepness ); +} //end of the function AAS_GroundFace +//=========================================================================== +// adds the side of a face to an area +// +// side : 0 = front side +// 1 = back side +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_AddFaceSideToArea( tmp_face_t *tmpface, int side, tmp_area_t *tmparea ) { + int tmpfaceside; + + if ( side ) { + if ( tmpface->backarea ) { + Error( "AAS_AddFaceSideToArea: already a back area\n" ); + } + } //end if + else + { + if ( tmpface->frontarea ) { + Error( "AAS_AddFaceSideToArea: already a front area\n" ); + } + } //end else + + if ( side ) { + tmpface->backarea = tmparea; + } else { tmpface->frontarea = tmparea;} + + if ( tmparea->tmpfaces ) { + tmpfaceside = tmparea->tmpfaces->frontarea != tmparea; + tmparea->tmpfaces->prev[tmpfaceside] = tmpface; + } //end if + tmpface->next[side] = tmparea->tmpfaces; + tmpface->prev[side] = NULL; + tmparea->tmpfaces = tmpface; +} //end of the function AAS_AddFaceSideToArea +//=========================================================================== +// remove (a side of) a face from an area +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_RemoveFaceFromArea( tmp_face_t *tmpface, tmp_area_t *tmparea ) { + int side, prevside, nextside; + + if ( tmpface->frontarea != tmparea && + tmpface->backarea != tmparea ) { + Error( "AAS_RemoveFaceFromArea: face not part of the area" ); + } //end if + side = tmpface->frontarea != tmparea; + if ( tmpface->prev[side] ) { + prevside = tmpface->prev[side]->frontarea != tmparea; + tmpface->prev[side]->next[prevside] = tmpface->next[side]; + } //end if + else + { + tmparea->tmpfaces = tmpface->next[side]; + } //end else + if ( tmpface->next[side] ) { + nextside = tmpface->next[side]->frontarea != tmparea; + tmpface->next[side]->prev[nextside] = tmpface->prev[side]; + } //end if + //remove the area number from the face depending on the side + if ( side ) { + tmpface->backarea = NULL; + } else { tmpface->frontarea = NULL;} + tmpface->prev[side] = NULL; + tmpface->next[side] = NULL; +} //end of the function AAS_RemoveFaceFromArea +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_CheckArea( tmp_area_t *tmparea ) { + int side; + tmp_face_t *face; + plane_t *plane; + vec3_t wcenter, acenter = {0, 0, 0}; + vec3_t normal; + float n, dist; + + if ( tmparea->invalid ) { + Log_Print( "AAS_CheckArea: invalid area\n" ); + } + for ( n = 0, face = tmparea->tmpfaces; face; face = face->next[side] ) + { + //side of the face the area is on + side = face->frontarea != tmparea; + WindingCenter( face->winding, wcenter ); + VectorAdd( acenter, wcenter, acenter ); + n++; + } //end for + n = 1 / n; + VectorScale( acenter, n, acenter ); + for ( face = tmparea->tmpfaces; face; face = face->next[side] ) + { + //side of the face the area is on + side = face->frontarea != tmparea; + +#ifdef L_DEBUG + if ( WindingError( face->winding ) ) { + Log_Write( "AAS_CheckArea: area %d face %d: %s\r\n", tmparea->areanum, + face->num, WindingErrorString() ); + } //end if +#endif L_DEBUG + + plane = &mapplanes[face->planenum ^ side]; + + if ( DotProduct( plane->normal, acenter ) - plane->dist < 0 ) { + Log_Print( "AAS_CheckArea: area %d face %d is flipped\n", tmparea->areanum, face->num ); + Log_Print( "AAS_CheckArea: area %d center is %f %f %f\n", tmparea->areanum, acenter[0], acenter[1], acenter[2] ); + } //end if + //check if the winding plane is the same as the face plane + WindingPlane( face->winding, normal, &dist ); + plane = &mapplanes[face->planenum]; +#ifdef L_DEBUG + if ( fabs( dist - plane->dist ) > 0.4 || + fabs( normal[0] - plane->normal[0] ) > 0.0001 || + fabs( normal[1] - plane->normal[1] ) > 0.0001 || + fabs( normal[2] - plane->normal[2] ) > 0.0001 ) { + Log_Write( "AAS_CheckArea: area %d face %d winding plane unequal to face plane\r\n", + tmparea->areanum, face->num ); + } //end if +#endif L_DEBUG + } //end for +} //end of the function AAS_CheckArea +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_CheckFaceWindingPlane( tmp_face_t *face ) { + float dist, sign1, sign2; + vec3_t normal; + plane_t *plane; + winding_t *w; + + //check if the winding plane is the same as the face plane + WindingPlane( face->winding, normal, &dist ); + plane = &mapplanes[face->planenum]; + // + sign1 = DotProduct( plane->normal, normal ); + // + if ( fabs( dist - plane->dist ) > 0.4 || + fabs( normal[0] - plane->normal[0] ) > 0.0001 || + fabs( normal[1] - plane->normal[1] ) > 0.0001 || + fabs( normal[2] - plane->normal[2] ) > 0.0001 ) { + VectorInverse( normal ); + dist = -dist; + if ( fabs( dist - plane->dist ) > 0.4 || + fabs( normal[0] - plane->normal[0] ) > 0.0001 || + fabs( normal[1] - plane->normal[1] ) > 0.0001 || + fabs( normal[2] - plane->normal[2] ) > 0.0001 ) { + Log_Write( "AAS_CheckFaceWindingPlane: face %d winding plane unequal to face plane\r\n", + face->num ); + // + sign2 = DotProduct( plane->normal, normal ); + if ( ( sign1 < 0 && sign2 > 0 ) || + ( sign1 > 0 && sign2 < 0 ) ) { + Log_Write( "AAS_CheckFaceWindingPlane: face %d winding reversed\r\n", + face->num ); + w = face->winding; + face->winding = ReverseWinding( w ); + FreeWinding( w ); + } //end if + } //end if + else + { + Log_Write( "AAS_CheckFaceWindingPlane: face %d winding reversed\r\n", + face->num ); + w = face->winding; + face->winding = ReverseWinding( w ); + FreeWinding( w ); + } //end else + } //end if +} //end of the function AAS_CheckFaceWindingPlane +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_CheckAreaWindingPlanes( void ) { + int side; + tmp_area_t *tmparea; + tmp_face_t *face; + + Log_Write( "AAS_CheckAreaWindingPlanes:\r\n" ); + for ( tmparea = tmpaasworld.areas; tmparea; tmparea = tmparea->l_next ) + { + if ( tmparea->invalid ) { + continue; + } + for ( face = tmparea->tmpfaces; face; face = face->next[side] ) + { + side = face->frontarea != tmparea; + AAS_CheckFaceWindingPlane( face ); + } //end for + } //end for +} //end of the function AAS_CheckAreaWindingPlanes +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_FlipAreaFaces( tmp_area_t *tmparea ) { + int side; + tmp_face_t *face; + plane_t *plane; + vec3_t wcenter, acenter = {0, 0, 0}; + //winding_t *w; + float n; + + for ( n = 0, face = tmparea->tmpfaces; face; face = face->next[side] ) + { + if ( !face->frontarea ) { + Error( "face %d has no front area\n", face->num ); + } + //side of the face the area is on + side = face->frontarea != tmparea; + WindingCenter( face->winding, wcenter ); + VectorAdd( acenter, wcenter, acenter ); + n++; + } //end for + n = 1 / n; + VectorScale( acenter, n, acenter ); + for ( face = tmparea->tmpfaces; face; face = face->next[side] ) + { + //side of the face the area is on + side = face->frontarea != tmparea; + + plane = &mapplanes[face->planenum ^ side]; + + if ( DotProduct( plane->normal, acenter ) - plane->dist < 0 ) { + Log_Print( "area %d face %d flipped: front area %d, back area %d\n", tmparea->areanum, face->num, + face->frontarea ? face->frontarea->areanum : 0, + face->backarea ? face->backarea->areanum : 0 ); + /* + face->planenum = face->planenum ^ 1; + w = face->winding; + face->winding = ReverseWinding(w); + FreeWinding(w); + */ + } //end if +#ifdef L_DEBUG + { + float dist; + vec3_t normal; + + //check if the winding plane is the same as the face plane + WindingPlane( face->winding, normal, &dist ); + plane = &mapplanes[face->planenum]; + if ( fabs( dist - plane->dist ) > 0.4 || + fabs( normal[0] - plane->normal[0] ) > 0.0001 || + fabs( normal[1] - plane->normal[1] ) > 0.0001 || + fabs( normal[2] - plane->normal[2] ) > 0.0001 ) { + Log_Write( "area %d face %d winding plane unequal to face plane\r\n", + tmparea->areanum, face->num ); + } //end if + } +#endif + } //end for +} //end of the function AAS_FlipAreaFaces +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_RemoveAreaFaceColinearPoints( void ) { + int side; + tmp_face_t *face; + tmp_area_t *tmparea; + + //FIXME: loop over the faces instead of area->faces + for ( tmparea = tmpaasworld.areas; tmparea; tmparea = tmparea->l_next ) + { + for ( face = tmparea->tmpfaces; face; face = face->next[side] ) + { + side = face->frontarea != tmparea; + RemoveColinearPoints( face->winding ); +// RemoveEqualPoints(face->winding, 0.1); + } //end for + } //end for +} //end of the function AAS_RemoveAreaFaceColinearPoints +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_RemoveTinyFaces( void ) { + int side, num; + tmp_face_t *face, *nextface; + tmp_area_t *tmparea; + + //FIXME: loop over the faces instead of area->faces + Log_Write( "AAS_RemoveTinyFaces\r\n" ); + num = 0; + for ( tmparea = tmpaasworld.areas; tmparea; tmparea = tmparea->l_next ) + { + for ( face = tmparea->tmpfaces; face; face = nextface ) + { + side = face->frontarea != tmparea; + nextface = face->next[side]; + // + if ( WindingArea( face->winding ) < 1 ) { + if ( face->frontarea ) { + AAS_RemoveFaceFromArea( face, face->frontarea ); + } + if ( face->backarea ) { + AAS_RemoveFaceFromArea( face, face->backarea ); + } + AAS_FreeTmpFace( face ); + //Log_Write("area %d face %d is tiny\r\n", tmparea->areanum, face->num); + num++; + } //end if + } //end for + } //end for + Log_Write( "%d tiny faces removed\r\n", num ); +} //end of the function AAS_RemoveTinyFaces +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_CreateAreaSettings( void ) { + int i, flags, side, numgrounded, numladderareas, numliquidareas; + tmp_face_t *face; + tmp_area_t *tmparea; + int count; + + numgrounded = 0; + numladderareas = 0; + numliquidareas = 0; + Log_Write( "AAS_CreateAreaSettings\r\n" ); + i = 0; + qprintf( "%6d areas provided with settings", i ); + for ( tmparea = tmpaasworld.areas; tmparea; tmparea = tmparea->l_next ) + { + //if the area is invalid there no need to create settings for it + if ( tmparea->invalid ) { + continue; + } + + tmparea->settings = (tmp_areasettings_t *) GetClearedMemory( sizeof( tmp_areasettings_t ) ); + tmparea->settings->contents = tmparea->contents; + tmparea->settings->modelnum = tmparea->modelnum; + flags = 0; + count = 0; + tmparea->settings->groundsteepness = 0.0; + for ( face = tmparea->tmpfaces; face; face = face->next[side] ) + { + side = face->frontarea != tmparea; + flags |= face->faceflags; + // Ridah, add this face's steepness + if ( face->faceflags & FACE_GROUND ) { + tmparea->settings->groundsteepness += ( 1.0 - mapplanes[face->planenum ^ side].normal[2] ); + count++; + } + } //end for + tmparea->settings->groundsteepness /= (float)count; + if ( tmparea->settings->groundsteepness > 1.0 ) { + tmparea->settings->groundsteepness = 1.0; + } + if ( tmparea->settings->groundsteepness < 0.0 ) { + tmparea->settings->groundsteepness = 0.0; + } + tmparea->settings->areaflags = 0; + if ( flags & FACE_GROUND ) { + tmparea->settings->areaflags |= AREA_GROUNDED; + numgrounded++; + } //end if + if ( flags & FACE_LADDER ) { + tmparea->settings->areaflags |= AREA_LADDER; + numladderareas++; + } //end if + if ( tmparea->contents & ( AREACONTENTS_WATER | + AREACONTENTS_SLIME | + AREACONTENTS_LAVA ) ) { + tmparea->settings->areaflags |= AREA_LIQUID; + numliquidareas++; + } //end if + //presence type of the area + tmparea->settings->presencetype = tmparea->presencetype; + // + qprintf( "\r%6d", ++i ); + } //end for + qprintf( "\n" ); +#ifdef AASINFO + Log_Print( "%6d grounded areas\n", numgrounded ); + Log_Print( "%6d ladder areas\n", numladderareas ); + Log_Print( "%6d liquid areas\n", numliquidareas ); +#endif //AASINFO +} //end of the function AAS_CreateAreaSettings +//=========================================================================== +// create a tmp AAS area from a leaf node +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +//portal_t *globalPortalDebug; +tmp_node_t *AAS_CreateArea( node_t *node ) { + int pside; + int areafaceflags; + portal_t *p; + tmp_face_t *tmpface; + tmp_area_t *tmparea; + tmp_node_t *tmpnode; + //vec3_t up = {0, 0, 1}; // TTimo: unused + + //create an area from this leaf + tmparea = AAS_AllocTmpArea(); + tmparea->tmpfaces = NULL; + //clear the area face flags + areafaceflags = 0; + //make aas faces from the portals + for ( p = node->portals; p; p = p->next[pside] ) + { + pside = ( p->nodes[1] == node ); + //don't create faces from very small portals +// if (WindingArea(p->winding) < 1) continue; + //if there's already a face created for this portal + if ( p->tmpface ) { + //add the back side of the face to the area + AAS_AddFaceSideToArea( p->tmpface, 1, tmparea ); + } //end if + else + { + tmpface = AAS_AllocTmpFace(); + //set the face pointer at the portal so we can see from + //the portal there's a face created for it + p->tmpface = tmpface; + //FIXME: test this change + //tmpface->planenum = (p->planenum & ~1) | pside; + tmpface->planenum = p->planenum ^ pside; + if ( pside ) { + tmpface->winding = ReverseWinding( p->winding ); + } else { tmpface->winding = CopyWinding( p->winding );} +#ifdef L_DEBUG + // + AAS_CheckFaceWindingPlane( tmpface ); +#endif //L_DEBUG + //if there's solid at the other side of the portal + if ( p->nodes[!pside]->contents & ( CONTENTS_SOLID | CONTENTS_PLAYERCLIP ) ) { + tmpface->faceflags |= FACE_SOLID; + } //end if + //else there is no solid at the other side and if there + //is a liquid at this side + else if ( node->contents & ( CONTENTS_WATER | CONTENTS_SLIME | CONTENTS_LAVA ) ) { + tmpface->faceflags |= FACE_LIQUID; + //if there's no liquid at the other side + if ( !( p->nodes[!pside]->contents & ( CONTENTS_WATER | CONTENTS_SLIME | CONTENTS_LAVA ) ) ) { + tmpface->faceflags |= FACE_LIQUIDSURFACE; + } //end if + } //end else + //if there's ladder contents at other side of the portal + if ( ( p->nodes[pside]->contents & CONTENTS_LADDER ) || + ( p->nodes[!pside]->contents & CONTENTS_LADDER ) ) { + + //NOTE: doesn't have to be solid at the other side because + // when standing one can use a crouch area (which is not solid) + // as a ladder + // imagine a ladder one can walk underthrough, + // under the ladder against the ladder is a crouch area + // the (vertical) sides of this crouch area area also used as + // ladder sides when standing (not crouched) + tmpface->faceflags |= FACE_LADDER; + } //end if + //if it is possible to stand on the face + if ( AAS_GroundFace( tmpface ) ) { + tmpface->faceflags |= FACE_GROUND; + } //end if + // + areafaceflags |= tmpface->faceflags; + //no aas face number yet (zero is a dummy in the aasworld faces) + tmpface->aasfacenum = 0; + //add the front side of the face to the area + AAS_AddFaceSideToArea( tmpface, 0, tmparea ); + } //end else + } //end for + qprintf( "\r%6d", tmparea->areanum ); + //presence type in the area + tmparea->presencetype = ~node->expansionbboxes & cfg.allpresencetypes; + // + tmparea->contents = 0; + if ( node->contents & CONTENTS_CLUSTERPORTAL ) { + tmparea->contents |= AREACONTENTS_CLUSTERPORTAL; + } + if ( node->contents & CONTENTS_MOVER ) { + tmparea->contents |= AREACONTENTS_MOVER; + } + if ( node->contents & CONTENTS_TELEPORTER ) { + tmparea->contents |= AREACONTENTS_TELEPORTER; + } + if ( node->contents & CONTENTS_JUMPPAD ) { + tmparea->contents |= AREACONTENTS_JUMPPAD; + } + if ( node->contents & CONTENTS_DONOTENTER ) { + tmparea->contents |= AREACONTENTS_DONOTENTER; + } + if ( node->contents & CONTENTS_DONOTENTER_LARGE ) { + tmparea->contents |= AREACONTENTS_DONOTENTER_LARGE; + } + if ( node->contents & CONTENTS_WATER ) { + tmparea->contents |= AREACONTENTS_WATER; + } + if ( node->contents & CONTENTS_LAVA ) { + tmparea->contents |= AREACONTENTS_LAVA; + } + if ( node->contents & CONTENTS_SLIME ) { + tmparea->contents |= AREACONTENTS_SLIME; + } + + //store the bsp model that's inside this node + tmparea->modelnum = node->modelnum; + //sorta check for flipped area faces (remove??) + AAS_FlipAreaFaces( tmparea ); + //check if the area is ok (remove??) + AAS_CheckArea( tmparea ); + // + tmpnode = AAS_AllocTmpNode(); + tmpnode->planenum = 0; + tmpnode->children[0] = 0; + tmpnode->children[1] = 0; + tmpnode->tmparea = tmparea; + // + return tmpnode; +} //end of the function AAS_CreateArea +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +tmp_node_t *AAS_CreateAreas_r( node_t *node ) { + tmp_node_t *tmpnode; + + //recurse down to leafs + if ( node->planenum != PLANENUM_LEAF ) { + //the first tmp node is a dummy + tmpnode = AAS_AllocTmpNode(); + tmpnode->planenum = node->planenum; + tmpnode->children[0] = AAS_CreateAreas_r( node->children[0] ); + tmpnode->children[1] = AAS_CreateAreas_r( node->children[1] ); + return tmpnode; + } //end if + //areas won't be created for solid leafs + if ( node->contents & CONTENTS_SOLID ) { + //just return zero for a solid leaf (in tmp AAS NULL is a solid leaf) + return NULL; + } //end if + + return AAS_CreateArea( node ); +} //end of the function AAS_CreateAreas_r +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_CreateAreas( node_t *node ) { + Log_Write( "AAS_CreateAreas\r\n" ); + qprintf( "%6d areas created", 0 ); + tmpaasworld.nodes = AAS_CreateAreas_r( node ); + qprintf( "\n" ); + Log_Write( "%6d areas created\r\n", tmpaasworld.numareas ); +} //end of the function AAS_CreateAreas +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_PrintNumGroundFaces( void ) { + tmp_face_t *tmpface; + int numgroundfaces = 0; + + for ( tmpface = tmpaasworld.faces; tmpface; tmpface = tmpface->l_next ) + { + if ( tmpface->faceflags & FACE_GROUND ) { + numgroundfaces++; + } //end if + } //end for + qprintf( "%6d ground faces\n", numgroundfaces ); +} //end of the function AAS_PrintNumGroundFaces +//=========================================================================== +// checks the number of shared faces between the given two areas +// since areas are convex they should only have ONE shared face +// however due to crappy face merging there are sometimes several +// shared faces +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_CheckAreaSharedFaces( tmp_area_t *tmparea1, tmp_area_t *tmparea2 ) { + int numsharedfaces, side; + tmp_face_t *face1, *sharedface; + + if ( tmparea1->invalid || tmparea2->invalid ) { + return; + } + + sharedface = NULL; + numsharedfaces = 0; + for ( face1 = tmparea1->tmpfaces; face1; face1 = face1->next[side] ) + { + side = face1->frontarea != tmparea1; + if ( face1->backarea == tmparea2 || face1->frontarea == tmparea2 ) { + sharedface = face1; + numsharedfaces++; + } //end if + } //end if + if ( !sharedface ) { + return; + } + //the areas should only have one shared face + if ( numsharedfaces > 1 ) { + Log_Write( "---- tmp area %d and %d have %d shared faces\r\n", + tmparea1->areanum, tmparea2->areanum, numsharedfaces ); + for ( face1 = tmparea1->tmpfaces; face1; face1 = face1->next[side] ) + { + side = face1->frontarea != tmparea1; + if ( face1->backarea == tmparea2 || face1->frontarea == tmparea2 ) { + Log_Write( "face %d, planenum = %d, face->frontarea = %d face->backarea = %d\r\n", + face1->num, face1->planenum, face1->frontarea->areanum, face1->backarea->areanum ); + } //end if + } //end if + } //end if +} //end of the function AAS_CheckAreaSharedFaces +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_CheckSharedFaces( void ) { + tmp_area_t *tmparea1, *tmparea2; + + for ( tmparea1 = tmpaasworld.areas; tmparea1; tmparea1 = tmparea1->l_next ) + { + for ( tmparea2 = tmpaasworld.areas; tmparea2; tmparea2 = tmparea2->l_next ) + { + if ( tmparea1 == tmparea2 ) { + continue; + } + AAS_CheckAreaSharedFaces( tmparea1, tmparea2 ); + } //end for + } //end for +} //end of the function AAS_CheckSharedFaces +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_FlipFace( tmp_face_t *face ) { + tmp_area_t *frontarea, *backarea; + winding_t *w; + + frontarea = face->frontarea; + backarea = face->backarea; + //must have an area at both sides before flipping is allowed + if ( !frontarea || !backarea ) { + return; + } + //flip the face winding + w = face->winding; + face->winding = ReverseWinding( w ); + FreeWinding( w ); + //flip the face plane + face->planenum ^= 1; + //flip the face areas + AAS_RemoveFaceFromArea( face, frontarea ); + AAS_RemoveFaceFromArea( face, backarea ); + AAS_AddFaceSideToArea( face, 1, frontarea ); + AAS_AddFaceSideToArea( face, 0, backarea ); +} //end of the function AAS_FlipFace +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +/* +void AAS_FlipAreaSharedFaces(tmp_area_t *tmparea1, tmp_area_t *tmparea2) +{ + int numsharedfaces, side, area1facing, area2facing; + tmp_face_t *face1, *sharedface; + + if (tmparea1->invalid || tmparea2->invalid) return; + + sharedface = NULL; + numsharedfaces = 0; + area1facing = 0; //number of shared faces facing towards area 1 + area2facing = 0; //number of shared faces facing towards area 2 + for (face1 = tmparea1->tmpfaces; face1; face1 = face1->next[side]) + { + side = face1->frontarea != tmparea1; + if (face1->backarea == tmparea2 || face1->frontarea == tmparea2) + { + sharedface = face1; + numsharedfaces++; + if (face1->frontarea == tmparea1) area1facing++; + else area2facing++; + } //end if + } //end if + if (!sharedface) return; + //if there's only one shared face + if (numsharedfaces <= 1) return; + //if all the shared faces are facing to the same area + if (numsharedfaces == area1facing || numsharedfaces == area2facing) return; + // + do + { + for (face1 = tmparea1->tmpfaces; face1; face1 = face1->next[side]) + { + side = face1->frontarea != tmparea1; + if (face1->backarea == tmparea2 || face1->frontarea == tmparea2) + { + if (face1->frontarea != tmparea1) + { + AAS_FlipFace(face1); + break; + } //end if + } //end if + } //end for + } while(face1); +} //end of the function AAS_FlipAreaSharedFaces +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_FlipSharedFaces(void) +{ + int i; + tmp_area_t *tmparea1, *tmparea2; + + i = 0; + qprintf("%6d areas checked for shared face flipping", i); + for (tmparea1 = tmpaasworld.areas; tmparea1; tmparea1 = tmparea1->l_next) + { + if (tmparea1->invalid) continue; + for (tmparea2 = tmpaasworld.areas; tmparea2; tmparea2 = tmparea2->l_next) + { + if (tmparea2->invalid) continue; + if (tmparea1 == tmparea2) continue; + AAS_FlipAreaSharedFaces(tmparea1, tmparea2); + } //end for + qprintf("\r%6d", ++i); + } //end for + Log_Print("\r%6d areas checked for shared face flipping\n", i); +} //end of the function AAS_FlipSharedFaces +*/ +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_FlipSharedFaces( void ) { + int i, side1, side2; + tmp_area_t *tmparea1; + tmp_face_t *face1, *face2; + + i = 0; + qprintf( "%6d areas checked for shared face flipping", i ); + for ( tmparea1 = tmpaasworld.areas; tmparea1; tmparea1 = tmparea1->l_next ) + { + if ( tmparea1->invalid ) { + continue; + } + for ( face1 = tmparea1->tmpfaces; face1; face1 = face1->next[side1] ) + { + side1 = face1->frontarea != tmparea1; + if ( !face1->frontarea || !face1->backarea ) { + continue; + } + // + for ( face2 = face1->next[side1]; face2; face2 = face2->next[side2] ) + { + side2 = face2->frontarea != tmparea1; + if ( !face2->frontarea || !face2->backarea ) { + continue; + } + // + if ( face1->frontarea == face2->backarea && + face1->backarea == face2->frontarea ) { + AAS_FlipFace( face2 ); + } //end if + //recheck side + side2 = face2->frontarea != tmparea1; + } //end for + } //end for + qprintf( "\r%6d", ++i ); + } //end for + qprintf( "\n" ); + Log_Print( "%6d areas checked for shared face flipping\r\n", i ); +} //end of the function AAS_FlipSharedFaces +//=========================================================================== +// creates an .AAS file with the given name +// a MAP should be loaded before calling this +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_Create( char *aasfile ) { + entity_t *e; + tree_t *tree; + double start_time; + + //for a possible leak file + strcpy( source, aasfile ); + StripExtension( source ); + //the time started + start_time = I_FloatTime(); + //set the default number of threads (depends on number of processors) + ThreadSetDefault(); + //set the global entity number to the world model + entity_num = 0; + //the world entity + e = &entities[entity_num]; + //process the whole world + tree = ProcessWorldBrushes( e->firstbrush, e->firstbrush + e->numbrushes ); + //if the conversion is cancelled + if ( cancelconversion ) { + Tree_Free( tree ); + return; + } //end if + //display BSP tree creation time + Log_Print( "BSP tree created in %5.0f seconds\n", I_FloatTime() - start_time ); + //prune the bsp tree + Tree_PruneNodes( tree->headnode ); + //if the conversion is cancelled + if ( cancelconversion ) { + Tree_Free( tree ); + return; + } //end if + //create the tree portals + MakeTreePortals( tree ); + //if the conversion is cancelled + if ( cancelconversion ) { + Tree_Free( tree ); + return; + } //end if + //Marks all nodes that can be reached by entites + if ( FloodEntities( tree ) ) { + //fill out nodes that can't be reached + FillOutside( tree->headnode ); + } //end if + else + { + LeakFile( tree ); + Error( "**** leaked ****\n" ); + return; + } //end else + //create AAS from the BSP tree + //========================================== + //initialize tmp aas + AAS_InitTmpAAS(); + //create the convex areas from the leaves + AAS_CreateAreas( tree->headnode ); + //free the BSP tree because it isn't used anymore + if ( freetree ) { + Tree_Free( tree ); + } + //try to merge area faces + AAS_MergeAreaFaces(); + //do gravitational subdivision + AAS_GravitationalSubdivision(); + //merge faces if possible + AAS_MergeAreaFaces(); + AAS_RemoveAreaFaceColinearPoints(); + //merge areas if possible + AAS_MergeAreas(); + //NOTE: prune nodes directly after area merging + AAS_PruneNodes(); + //flip shared faces so they are all facing to the same area + AAS_FlipSharedFaces(); + AAS_RemoveAreaFaceColinearPoints(); + //merge faces if possible + AAS_MergeAreaFaces(); + //merge area faces in the same plane + AAS_MergeAreaPlaneFaces(); + //do ladder subdivision + AAS_LadderSubdivision(); + //FIXME: melting is buggy + AAS_MeltAreaFaceWindings(); + //remove tiny faces + AAS_RemoveTinyFaces(); + //create area settings + AAS_CreateAreaSettings(); + //check if the winding plane is equal to the face plane + //AAS_CheckAreaWindingPlanes(); + // + //AAS_CheckSharedFaces(); + //========================================== + //if the conversion is cancelled + if ( cancelconversion ) { + Tree_Free( tree ); + AAS_FreeTmpAAS(); + return; + } //end if + //store the created AAS stuff in the AAS file format and write the file + AAS_StoreFile( aasfile ); + //free the temporary AAS memory + AAS_FreeTmpAAS(); + //display creation time + Log_Print( "\nAAS created in %5.0f seconds\n", I_FloatTime() - start_time ); +} //end of the function AAS_Create diff --git a/Projects/Android/jni/rtcw/src/bspc/aas_create.h b/Projects/Android/jni/rtcw/src/bspc/aas_create.h new file mode 100644 index 0000000..596fe33 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/bspc/aas_create.h @@ -0,0 +1,153 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +//=========================================================================== +// +// Name: aas_create.h +// Function: +// Programmer: Mr Elusive (MrElusive@demigod.demon.nl) +// Last update: 1997-12-04 +// Tab Size: 3 +//=========================================================================== + +#define AREA_PORTAL 1 + +//temporary AAS face +typedef struct tmp_face_s +{ + int num; //face number + int planenum; //number of the plane the face is in + winding_t *winding; //winding of the face + struct tmp_area_s *frontarea; //area at the front of the face + struct tmp_area_s *backarea; //area at the back of the face + int faceflags; //flags of this face + int aasfacenum; //the number of the aas face used for this face + //double link list pointers for front and back area + struct tmp_face_s *prev[2], *next[2]; + //links in the list with faces + struct tmp_face_s *l_prev, *l_next; +} tmp_face_t; + +//temporary AAS area settings +typedef struct tmp_areasettings_s +{ + //could also add all kind of statistic fields + int contents; //contents of the area + int modelnum; //bsp model inside this area + int areaflags; //area flags + int presencetype; //how a bot can be present in this area + int numreachableareas; //number of reachable areas from this one + int firstreachablearea; //first reachable area in the reachable area index + // Ridah, steepness + float groundsteepness; +} tmp_areasettings_t; + +//temporary AAS area +typedef struct tmp_area_s +{ + int areanum; //number of the area + struct tmp_face_s *tmpfaces; //the faces of the area + int presencetype; //presence type of the area + int contents; //area contents + int modelnum; //bsp model inside this area + int invalid; //true if the area is invalid + tmp_areasettings_t *settings; //area settings + struct tmp_area_s *mergedarea; //points to the new area after merging + //when mergedarea != 0 the area has only the + //seperating face of the merged areas + int aasareanum; //number of the aas area created for this tmp area + //links in the list with areas + struct tmp_area_s *l_prev, *l_next; +} tmp_area_t; + +//temporary AAS node +typedef struct tmp_node_s +{ + int planenum; //node plane number + struct tmp_area_s *tmparea; //points to an area if this node is an area + struct tmp_node_s *children[2]; //child nodes of this node +} tmp_node_t; + +#define NODEBUF_SIZE 128 +//node buffer +typedef struct tmp_nodebuf_s +{ + int numnodes; + struct tmp_nodebuf_s *next; + tmp_node_t nodes[NODEBUF_SIZE]; +} tmp_nodebuf_t; + +//the whole temorary AAS +typedef struct tmp_aas_s +{ + //faces + int numfaces; + int facenum; + tmp_face_t *faces; + //areas + int numareas; + int areanum; + tmp_area_t *areas; + //area settings + int numareasettings; + tmp_areasettings_t *areasettings; + //nodes + int numnodes; + tmp_node_t *nodes; + //node buffer + tmp_nodebuf_t *nodebuffer; +} tmp_aas_t; + +extern tmp_aas_t tmpaasworld; + +//creates a .AAS file with the given name from an already loaded map +void AAS_Create( char *aasfile ); +//adds a face side to an area +void AAS_AddFaceSideToArea( tmp_face_t *tmpface, int side, tmp_area_t *tmparea ); +//remvoes a face from an area +void AAS_RemoveFaceFromArea( tmp_face_t *tmpface, tmp_area_t *tmparea ); +//allocate a tmp face +tmp_face_t *AAS_AllocTmpFace( void ); +//free the tmp face +void AAS_FreeTmpFace( tmp_face_t *tmpface ); +//allocate a tmp area +tmp_area_t *AAS_AllocTmpArea( void ); +//free a tmp area +void AAS_FreeTmpArea( tmp_area_t *tmparea ); +//allocate a tmp node +tmp_node_t *AAS_AllocTmpNode( void ); +//free a tmp node +void AAS_FreeTmpNode( tmp_node_t *node ); +//checks if an area is ok +void AAS_CheckArea( tmp_area_t *tmparea ); +//flips the area faces where needed +void AAS_FlipAreaFaces( tmp_area_t *tmparea ); +//returns true if the face is a gap seen from the given side +int AAS_GapFace( tmp_face_t *tmpface, int side ); +//returns true if the face is a ground face +int AAS_GroundFace( tmp_face_t *tmpface ); diff --git a/Projects/Android/jni/rtcw/src/bspc/aas_edgemelting.c b/Projects/Android/jni/rtcw/src/bspc/aas_edgemelting.c new file mode 100644 index 0000000..803937a --- /dev/null +++ b/Projects/Android/jni/rtcw/src/bspc/aas_edgemelting.c @@ -0,0 +1,125 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +//=========================================================================== +// +// Name: aas_edgemelting.c +// Function: Melting of Edges +// Programmer: Mr Elusive (MrElusive@demigod.demon.nl) +// Last update: 1997-12-04 +// Tab Size: 3 +//=========================================================================== + +#include "qbsp.h" +#include "../botlib/aasfile.h" +#include "aas_create.h" + +//=========================================================================== +// try to melt the windings of the two faces +// FIXME: this is buggy +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_MeltFaceWinding( tmp_face_t *face1, tmp_face_t *face2 ) { + int i, n; + int splits = 0; + winding_t *w2, *neww; + plane_t *plane1; + +#ifdef DEBUG + if ( !face1->winding ) { + Error( "face1 %d without winding", face1->num ); + } + if ( !face2->winding ) { + Error( "face2 %d without winding", face2->num ); + } +#endif //DEBUG + w2 = face2->winding; + plane1 = &mapplanes[face1->planenum]; + for ( i = 0; i < w2->numpoints; i++ ) + { + if ( PointOnWinding( face1->winding, plane1->normal, plane1->dist, w2->p[i], &n ) ) { + neww = AddWindingPoint( face1->winding, w2->p[i], n ); + FreeWinding( face1->winding ); + face1->winding = neww; + + splits++; + } //end if + } //end for + return splits; +} //end of the function AAS_MeltFaceWinding +//=========================================================================== +// melt the windings of the area faces +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_MeltFaceWindingsOfArea( tmp_area_t *tmparea ) { + int side1, side2, num_windingsplits = 0; + tmp_face_t *face1, *face2; + + for ( face1 = tmparea->tmpfaces; face1; face1 = face1->next[side1] ) + { + side1 = face1->frontarea != tmparea; + for ( face2 = tmparea->tmpfaces; face2; face2 = face2->next[side2] ) + { + side2 = face2->frontarea != tmparea; + if ( face1 == face2 ) { + continue; + } + num_windingsplits += AAS_MeltFaceWinding( face1, face2 ); + } //end for + } //end for + return num_windingsplits; +} //end of the function AAS_MeltFaceWindingsOfArea +//=========================================================================== +// melt the windings of the faces of all areas +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_MeltAreaFaceWindings( void ) { + tmp_area_t *tmparea; + int num_windingsplits = 0; + + Log_Write( "AAS_MeltAreaFaceWindings\r\n" ); + qprintf( "%6d edges melted", num_windingsplits ); + //NOTE: first convex area (zero) is a dummy + for ( tmparea = tmpaasworld.areas; tmparea; tmparea = tmparea->l_next ) + { + num_windingsplits += AAS_MeltFaceWindingsOfArea( tmparea ); + qprintf( "\r%6d", num_windingsplits ); + } //end for + qprintf( "\n" ); + Log_Write( "%6d edges melted\r\n", num_windingsplits ); +} //end of the function AAS_MeltAreaFaceWindings + diff --git a/Projects/Android/jni/rtcw/src/bspc/aas_edgemelting.h b/Projects/Android/jni/rtcw/src/bspc/aas_edgemelting.h new file mode 100644 index 0000000..20dbf86 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/bspc/aas_edgemelting.h @@ -0,0 +1,40 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +//=========================================================================== +// +// Name: aas_edgemelting.h +// Function: Melting of Edges +// Programmer: Mr Elusive (MrElusive@demigod.demon.nl) +// Last update: 1997-12-04 +// Tab Size: 3 +//=========================================================================== + + +void AAS_MeltAreaFaceWindings( void ); + diff --git a/Projects/Android/jni/rtcw/src/bspc/aas_facemerging.c b/Projects/Android/jni/rtcw/src/bspc/aas_facemerging.c new file mode 100644 index 0000000..2f89ddf --- /dev/null +++ b/Projects/Android/jni/rtcw/src/bspc/aas_facemerging.c @@ -0,0 +1,312 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +//=========================================================================== +// +// Name: aas_facemerging.c +// Function: Merging of Faces +// Programmer: Mr Elusive (MrElusive@demigod.demon.nl) +// Last update: 1997-12-04 +// Tab Size: 3 +//=========================================================================== + +#include "qbsp.h" +#include "../botlib/aasfile.h" +#include "aas_create.h" + +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_TryMergeFaces( tmp_face_t *face1, tmp_face_t *face2 ) { + winding_t *neww; + +#ifdef DEBUG + if ( !face1->winding ) { + Error( "face1 %d without winding", face1->num ); + } + if ( !face2->winding ) { + Error( "face2 %d without winding", face2->num ); + } +#endif //DEBUG + // + if ( face1->faceflags != face2->faceflags ) { + return false; + } + //NOTE: if the front or back area is zero this doesn't mean there's + //a real area. It means there's solid at that side of the face + //if both faces have the same front area + if ( face1->frontarea == face2->frontarea ) { + //if both faces have the same back area + if ( face1->backarea == face2->backarea ) { + //if the faces are in the same plane + if ( face1->planenum == face2->planenum ) { + //if they have both a front and a back area (no solid on either side) + if ( face1->frontarea && face1->backarea ) { + neww = MergeWindings( face1->winding, face2->winding, + mapplanes[face1->planenum].normal ); + } //end if + else + { + //this function is to be found in l_poly.c + neww = TryMergeWinding( face1->winding, face2->winding, + mapplanes[face1->planenum].normal ); + } //end else + if ( neww ) { + FreeWinding( face1->winding ); + face1->winding = neww; + if ( face2->frontarea ) { + AAS_RemoveFaceFromArea( face2, face2->frontarea ); + } + if ( face2->backarea ) { + AAS_RemoveFaceFromArea( face2, face2->backarea ); + } + AAS_FreeTmpFace( face2 ); + return true; + } //end if + } //end if + else if ( ( face1->planenum & ~1 ) == ( face2->planenum & ~1 ) ) { + Log_Write( "face %d and %d, same front and back area but flipped planes\r\n", + face1->num, face2->num ); + } //end if + } //end if + } //end if + return false; +} //end of the function AAS_TryMergeFaces +/* +int AAS_TryMergeFaces(tmp_face_t *face1, tmp_face_t *face2) +{ + winding_t *neww; + +#ifdef DEBUG + if (!face1->winding) Error("face1 %d without winding", face1->num); + if (!face2->winding) Error("face2 %d without winding", face2->num); +#endif //DEBUG + //if the faces are in the same plane + if ((face1->planenum & ~1) != (face2->planenum & ~1)) return false; +// if (face1->planenum != face2->planenum) return false; + //NOTE: if the front or back area is zero this doesn't mean there's + //a real area. It means there's solid at that side of the face + //if both faces have the same front area + if (face1->frontarea != face2->frontarea || + face1->backarea != face2->backarea) + { + if (!face1->frontarea || !face1->backarea || + !face2->frontarea || !face2->backarea) return false; + else if (face1->frontarea != face2->backarea || + face1->backarea != face2->frontarea) return false; +// return false; + } //end if + //this function is to be found in l_poly.c + neww = TryMergeWinding(face1->winding, face2->winding, + mapplanes[face1->planenum].normal); + if (!neww) return false; + // + FreeWinding(face1->winding); + face1->winding = neww; + //remove face2 + if (face2->frontarea) + AAS_RemoveFaceFromArea(face2, &tmpaasworld.areas[face2->frontarea]); + if (face2->backarea) + AAS_RemoveFaceFromArea(face2, &tmpaasworld.areas[face2->backarea]); + return true; +} //end of the function AAS_TryMergeFaces*/ +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_MergeAreaFaces( void ) { + int num_facemerges = 0; + int side1, side2, restart; + tmp_area_t *tmparea, *lasttmparea; + tmp_face_t *face1, *face2; + + Log_Write( "AAS_MergeAreaFaces\r\n" ); + qprintf( "%6d face merges", num_facemerges ); + //NOTE: first convex area is a dummy + lasttmparea = tmpaasworld.areas; + for ( tmparea = tmpaasworld.areas; tmparea; tmparea = tmparea->l_next ) + { + restart = false; + // + if ( tmparea->invalid ) { + continue; + } + // + for ( face1 = tmparea->tmpfaces; face1; face1 = face1->next[side1] ) + { + side1 = face1->frontarea != tmparea; + for ( face2 = face1->next[side1]; face2; face2 = face2->next[side2] ) + { + side2 = face2->frontarea != tmparea; + //if succesfully merged + if ( AAS_TryMergeFaces( face1, face2 ) ) { + //start over again after merging two faces + restart = true; + num_facemerges++; + qprintf( "\r%6d", num_facemerges ); + AAS_CheckArea( tmparea ); + break; + } //end if + } //end for + if ( restart ) { + tmparea = lasttmparea; + break; + } //end if + } //end for + lasttmparea = tmparea; + } //end for + qprintf( "\n" ); + Log_Write( "%6d face merges\r\n", num_facemerges ); +} //end of the function AAS_MergeAreaFaces +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_MergePlaneFaces( tmp_area_t *tmparea, int planenum ) { + tmp_face_t *face1, *face2, *nextface2; + winding_t *neww; + int side1, side2; + + for ( face1 = tmparea->tmpfaces; face1; face1 = face1->next[side1] ) + { + side1 = face1->frontarea != tmparea; + if ( face1->planenum != planenum ) { + continue; + } + // + for ( face2 = face1->next[side1]; face2; face2 = nextface2 ) + { + side2 = face2->frontarea != tmparea; + nextface2 = face2->next[side2]; + // + if ( ( face2->planenum & ~1 ) != ( planenum & ~1 ) ) { + continue; + } + // + neww = MergeWindings( face1->winding, face2->winding, + mapplanes[face1->planenum].normal ); + FreeWinding( face1->winding ); + face1->winding = neww; + if ( face2->frontarea ) { + AAS_RemoveFaceFromArea( face2, face2->frontarea ); + } + if ( face2->backarea ) { + AAS_RemoveFaceFromArea( face2, face2->backarea ); + } + AAS_FreeTmpFace( face2 ); + // + nextface2 = face1->next[side1]; + } //end for + } //end for +} //end of the function AAS_MergePlaneFaces +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_CanMergePlaneFaces( tmp_area_t *tmparea, int planenum ) { + tmp_area_t *frontarea, *backarea; + tmp_face_t *face1; + int side1, merge, faceflags = 0; // TTimo: init + + frontarea = backarea = NULL; + merge = false; + for ( face1 = tmparea->tmpfaces; face1; face1 = face1->next[side1] ) + { + side1 = face1->frontarea != tmparea; + if ( ( face1->planenum & ~1 ) != ( planenum & ~1 ) ) { + continue; + } + if ( !frontarea && !backarea ) { + frontarea = face1->frontarea; + backarea = face1->backarea; + faceflags = face1->faceflags; + } //end if + else + { + if ( frontarea != face1->frontarea ) { + return false; + } + if ( backarea != face1->backarea ) { + return false; + } + if ( faceflags != face1->faceflags ) { + return false; + } + merge = true; + } //end else + } //end for + return merge; +} //end of the function AAS_CanMergePlaneFaces +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_MergeAreaPlaneFaces( void ) { + int num_facemerges = 0; + int side1; + tmp_area_t *tmparea, *nexttmparea; + tmp_face_t *face1; + + Log_Write( "AAS_MergePlaneFaces\r\n" ); + qprintf( "%6d plane face merges", num_facemerges ); + //NOTE: first convex area is a dummy + for ( tmparea = tmpaasworld.areas; tmparea; tmparea = nexttmparea ) + { + nexttmparea = tmparea->l_next; + // + if ( tmparea->invalid ) { + continue; + } + // + for ( face1 = tmparea->tmpfaces; face1; face1 = face1->next[side1] ) + { + side1 = face1->frontarea != tmparea; + // + if ( AAS_CanMergePlaneFaces( tmparea, face1->planenum ) ) { + AAS_MergePlaneFaces( tmparea, face1->planenum ); + nexttmparea = tmparea; + num_facemerges++; + qprintf( "\r%6d", num_facemerges ); + break; + } //end if + } //end for + } //end for + qprintf( "\n" ); + Log_Write( "%6d plane face merges\r\n", num_facemerges ); +} //end of the function AAS_MergeAreaPlaneFaces diff --git a/Projects/Android/jni/rtcw/src/bspc/aas_facemerging.h b/Projects/Android/jni/rtcw/src/bspc/aas_facemerging.h new file mode 100644 index 0000000..79e1c12 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/bspc/aas_facemerging.h @@ -0,0 +1,39 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +//=========================================================================== +// +// Name: aas_facemerging.h +// Function: Merging of Faces +// Programmer: Mr Elusive (MrElusive@demigod.demon.nl) +// Last update: 1997-12-04 +// Tab Size: 3 +//=========================================================================== + +void AAS_MergeAreaFaces( void ); +void AAS_MergeAreaPlaneFaces( void ); diff --git a/Projects/Android/jni/rtcw/src/bspc/aas_file.c b/Projects/Android/jni/rtcw/src/bspc/aas_file.c new file mode 100644 index 0000000..29b5c5b --- /dev/null +++ b/Projects/Android/jni/rtcw/src/bspc/aas_file.c @@ -0,0 +1,603 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +//=========================================================================== +// +// Name: aas_file.c +// Function: AAS file loading and writing +// Programmer: Mr Elusive (MrElusive@demigod.demon.nl) +// Last update: 1997-12-04 +// Tab Size: 3 +//=========================================================================== + +#include "qbsp.h" +#include "../botlib/aasfile.h" +#include "aas_file.h" +#include "aas_store.h" +#include "aas_create.h" + +#define AAS_Error Error + +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_SwapAASData( void ) { + int i, j; + //bounding boxes + for ( i = 0; i < ( *aasworld ).numbboxes; i++ ) + { + ( *aasworld ).bboxes[i].presencetype = LittleLong( ( *aasworld ).bboxes[i].presencetype ); + ( *aasworld ).bboxes[i].flags = LittleLong( ( *aasworld ).bboxes[i].flags ); + for ( j = 0; j < 3; j++ ) + { + ( *aasworld ).bboxes[i].mins[j] = LittleLong( ( *aasworld ).bboxes[i].mins[j] ); + ( *aasworld ).bboxes[i].maxs[j] = LittleLong( ( *aasworld ).bboxes[i].maxs[j] ); + } //end for + } //end for + //vertexes + for ( i = 0; i < ( *aasworld ).numvertexes; i++ ) + { + for ( j = 0; j < 3; j++ ) + ( *aasworld ).vertexes[i][j] = LittleFloat( ( *aasworld ).vertexes[i][j] ); + } //end for + //planes + for ( i = 0; i < ( *aasworld ).numplanes; i++ ) + { + for ( j = 0; j < 3; j++ ) + ( *aasworld ).planes[i].normal[j] = LittleFloat( ( *aasworld ).planes[i].normal[j] ); + ( *aasworld ).planes[i].dist = LittleFloat( ( *aasworld ).planes[i].dist ); + ( *aasworld ).planes[i].type = LittleLong( ( *aasworld ).planes[i].type ); + } //end for + //edges + for ( i = 0; i < ( *aasworld ).numedges; i++ ) + { + ( *aasworld ).edges[i].v[0] = LittleLong( ( *aasworld ).edges[i].v[0] ); + ( *aasworld ).edges[i].v[1] = LittleLong( ( *aasworld ).edges[i].v[1] ); + } //end for + //edgeindex + for ( i = 0; i < ( *aasworld ).edgeindexsize; i++ ) + { + ( *aasworld ).edgeindex[i] = LittleLong( ( *aasworld ).edgeindex[i] ); + } //end for + //faces + for ( i = 0; i < ( *aasworld ).numfaces; i++ ) + { + ( *aasworld ).faces[i].planenum = LittleLong( ( *aasworld ).faces[i].planenum ); + ( *aasworld ).faces[i].faceflags = LittleLong( ( *aasworld ).faces[i].faceflags ); + ( *aasworld ).faces[i].numedges = LittleLong( ( *aasworld ).faces[i].numedges ); + ( *aasworld ).faces[i].firstedge = LittleLong( ( *aasworld ).faces[i].firstedge ); + ( *aasworld ).faces[i].frontarea = LittleLong( ( *aasworld ).faces[i].frontarea ); + ( *aasworld ).faces[i].backarea = LittleLong( ( *aasworld ).faces[i].backarea ); + } //end for + //face index + for ( i = 0; i < ( *aasworld ).faceindexsize; i++ ) + { + ( *aasworld ).faceindex[i] = LittleLong( ( *aasworld ).faceindex[i] ); + } //end for + //convex areas + for ( i = 0; i < ( *aasworld ).numareas; i++ ) + { + ( *aasworld ).areas[i].areanum = LittleLong( ( *aasworld ).areas[i].areanum ); + ( *aasworld ).areas[i].numfaces = LittleLong( ( *aasworld ).areas[i].numfaces ); + ( *aasworld ).areas[i].firstface = LittleLong( ( *aasworld ).areas[i].firstface ); + for ( j = 0; j < 3; j++ ) + { + ( *aasworld ).areas[i].mins[j] = LittleFloat( ( *aasworld ).areas[i].mins[j] ); + ( *aasworld ).areas[i].maxs[j] = LittleFloat( ( *aasworld ).areas[i].maxs[j] ); + ( *aasworld ).areas[i].center[j] = LittleFloat( ( *aasworld ).areas[i].center[j] ); + } //end for + } //end for + //area settings + for ( i = 0; i < ( *aasworld ).numareasettings; i++ ) + { + ( *aasworld ).areasettings[i].contents = LittleLong( ( *aasworld ).areasettings[i].contents ); + ( *aasworld ).areasettings[i].areaflags = LittleLong( ( *aasworld ).areasettings[i].areaflags ); + ( *aasworld ).areasettings[i].presencetype = LittleLong( ( *aasworld ).areasettings[i].presencetype ); + ( *aasworld ).areasettings[i].cluster = LittleLong( ( *aasworld ).areasettings[i].cluster ); + ( *aasworld ).areasettings[i].clusterareanum = LittleLong( ( *aasworld ).areasettings[i].clusterareanum ); + ( *aasworld ).areasettings[i].numreachableareas = LittleLong( ( *aasworld ).areasettings[i].numreachableareas ); + ( *aasworld ).areasettings[i].firstreachablearea = LittleLong( ( *aasworld ).areasettings[i].firstreachablearea ); + // Ridah + ( *aasworld ).areasettings[i].groundsteepness = LittleFloat( ( *aasworld ).areasettings[i].groundsteepness ); + } //end for + //area reachability + for ( i = 0; i < ( *aasworld ).reachabilitysize; i++ ) + { + ( *aasworld ).reachability[i].areanum = LittleLong( ( *aasworld ).reachability[i].areanum ); + ( *aasworld ).reachability[i].facenum = LittleLong( ( *aasworld ).reachability[i].facenum ); + ( *aasworld ).reachability[i].edgenum = LittleLong( ( *aasworld ).reachability[i].edgenum ); + for ( j = 0; j < 3; j++ ) + { + ( *aasworld ).reachability[i].start[j] = LittleFloat( ( *aasworld ).reachability[i].start[j] ); + ( *aasworld ).reachability[i].end[j] = LittleFloat( ( *aasworld ).reachability[i].end[j] ); + } //end for + ( *aasworld ).reachability[i].traveltype = LittleLong( ( *aasworld ).reachability[i].traveltype ); + ( *aasworld ).reachability[i].traveltime = LittleShort( ( *aasworld ).reachability[i].traveltime ); + } //end for + //nodes + for ( i = 0; i < ( *aasworld ).numnodes; i++ ) + { + ( *aasworld ).nodes[i].planenum = LittleLong( ( *aasworld ).nodes[i].planenum ); + ( *aasworld ).nodes[i].children[0] = LittleLong( ( *aasworld ).nodes[i].children[0] ); + ( *aasworld ).nodes[i].children[1] = LittleLong( ( *aasworld ).nodes[i].children[1] ); + } //end for + //cluster portals + for ( i = 0; i < ( *aasworld ).numportals; i++ ) + { + ( *aasworld ).portals[i].areanum = LittleLong( ( *aasworld ).portals[i].areanum ); + ( *aasworld ).portals[i].frontcluster = LittleLong( ( *aasworld ).portals[i].frontcluster ); + ( *aasworld ).portals[i].backcluster = LittleLong( ( *aasworld ).portals[i].backcluster ); + ( *aasworld ).portals[i].clusterareanum[0] = LittleLong( ( *aasworld ).portals[i].clusterareanum[0] ); + ( *aasworld ).portals[i].clusterareanum[1] = LittleLong( ( *aasworld ).portals[i].clusterareanum[1] ); + } //end for + //cluster portal index + for ( i = 0; i < ( *aasworld ).portalindexsize; i++ ) + { + ( *aasworld ).portalindex[i] = LittleLong( ( *aasworld ).portalindex[i] ); + } //end for + //cluster + for ( i = 0; i < ( *aasworld ).numclusters; i++ ) + { + ( *aasworld ).clusters[i].numareas = LittleLong( ( *aasworld ).clusters[i].numareas ); + ( *aasworld ).clusters[i].numportals = LittleLong( ( *aasworld ).clusters[i].numportals ); + ( *aasworld ).clusters[i].firstportal = LittleLong( ( *aasworld ).clusters[i].firstportal ); + } //end for +} //end of the function AAS_SwapAASData +//=========================================================================== +// dump the current loaded aas file +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_DumpAASData( void ) { + /* + if ((*aasworld).vertexes) FreeMemory((*aasworld).vertexes); + (*aasworld).vertexes = NULL; + if ((*aasworld).planes) FreeMemory((*aasworld).planes); + (*aasworld).planes = NULL; + if ((*aasworld).edges) FreeMemory((*aasworld).edges); + (*aasworld).edges = NULL; + if ((*aasworld).edgeindex) FreeMemory((*aasworld).edgeindex); + (*aasworld).edgeindex = NULL; + if ((*aasworld).faces) FreeMemory((*aasworld).faces); + (*aasworld).faces = NULL; + if ((*aasworld).faceindex) FreeMemory((*aasworld).faceindex); + (*aasworld).faceindex = NULL; + if ((*aasworld).areas) FreeMemory((*aasworld).areas); + (*aasworld).areas = NULL; + if ((*aasworld).areasettings) FreeMemory((*aasworld).areasettings); + (*aasworld).areasettings = NULL; + if ((*aasworld).reachability) FreeMemory((*aasworld).reachability); + (*aasworld).reachability = NULL; + */ + ( *aasworld ).loaded = false; +} //end of the function AAS_DumpAASData +//=========================================================================== +// allocate memory and read a lump of a AAS file +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +char *AAS_LoadAASLump( FILE *fp, int offset, int length, void *buf ) { + if ( !length ) { + printf( "lump size 0\n" ); + return buf; + } //end if + //seek to the data + if ( fseek( fp, offset, SEEK_SET ) ) { + AAS_Error( "can't seek to lump\n" ); + AAS_DumpAASData(); + fclose( fp ); + return 0; + } //end if + //allocate memory + if ( !buf ) { + buf = (void *) GetClearedMemory( length ); + } + //read the data + if ( fread( (char *) buf, 1, length, fp ) != length ) { + AAS_Error( "can't read lump\n" ); + FreeMemory( buf ); + AAS_DumpAASData(); + fclose( fp ); + return NULL; + } //end if + return buf; +} //end of the function AAS_LoadAASLump +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_DData( unsigned char *data, int size ) { + int i; + + for ( i = 0; i < size; i++ ) + { + data[i] ^= (unsigned char) i * 119; + } //end for +} //end of the function AAS_DData +//=========================================================================== +// load an aas file +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +qboolean AAS_LoadAASFile( char *filename, int fpoffset, int fplength ) { + FILE *fp; + aas_header_t header; + int offset, length; + + //dump current loaded aas file + AAS_DumpAASData(); + //open the file + fp = fopen( filename, "rb" ); + if ( !fp ) { + AAS_Error( "can't open %s\n", filename ); + return false; + } //end if + //seek to the correct position (in the pak file) + if ( fseek( fp, fpoffset, SEEK_SET ) ) { + AAS_Error( "can't seek to file %s\n" ); + fclose( fp ); + return false; + } //end if + //read the header + if ( fread( &header, sizeof( aas_header_t ), 1, fp ) != 1 ) { + AAS_Error( "can't read header of file %s\n", filename ); + fclose( fp ); + return false; + } //end if + //check header identification + header.ident = LittleLong( header.ident ); + if ( header.ident != AASID ) { + AAS_Error( "%s is not an AAS file\n", filename ); + fclose( fp ); + return false; + } //end if + //check the version + header.version = LittleLong( header.version ); + if ( header.version != AASVERSION ) { + AAS_Error( "%s is version %i, not %i\n", filename, header.version, AASVERSION ); + fclose( fp ); + return false; + } //end if + // + if ( header.version == AASVERSION ) { + AAS_DData( (unsigned char *) &header + 8, sizeof( aas_header_t ) - 8 ); + } //end if + ( *aasworld ).bspchecksum = LittleLong( header.bspchecksum ); + //load the lumps: + //bounding boxes + offset = fpoffset + LittleLong( header.lumps[AASLUMP_BBOXES].fileofs ); + length = LittleLong( header.lumps[AASLUMP_BBOXES].filelen ); + ( *aasworld ).bboxes = (aas_bbox_t *) AAS_LoadAASLump( fp, offset, length, ( *aasworld ).bboxes ); + if ( !( *aasworld ).bboxes ) { + return false; + } + ( *aasworld ).numbboxes = length / sizeof( aas_bbox_t ); + //vertexes + offset = fpoffset + LittleLong( header.lumps[AASLUMP_VERTEXES].fileofs ); + length = LittleLong( header.lumps[AASLUMP_VERTEXES].filelen ); + ( *aasworld ).vertexes = (aas_vertex_t *) AAS_LoadAASLump( fp, offset, length, ( *aasworld ).vertexes ); + if ( !( *aasworld ).vertexes ) { + return false; + } + ( *aasworld ).numvertexes = length / sizeof( aas_vertex_t ); + //planes + offset = fpoffset + LittleLong( header.lumps[AASLUMP_PLANES].fileofs ); + length = LittleLong( header.lumps[AASLUMP_PLANES].filelen ); + ( *aasworld ).planes = (aas_plane_t *) AAS_LoadAASLump( fp, offset, length, ( *aasworld ).planes ); + if ( !( *aasworld ).planes ) { + return false; + } + ( *aasworld ).numplanes = length / sizeof( aas_plane_t ); + //edges + offset = fpoffset + LittleLong( header.lumps[AASLUMP_EDGES].fileofs ); + length = LittleLong( header.lumps[AASLUMP_EDGES].filelen ); + ( *aasworld ).edges = (aas_edge_t *) AAS_LoadAASLump( fp, offset, length, ( *aasworld ).edges ); + if ( !( *aasworld ).edges ) { + return false; + } + ( *aasworld ).numedges = length / sizeof( aas_edge_t ); + //edgeindex + offset = fpoffset + LittleLong( header.lumps[AASLUMP_EDGEINDEX].fileofs ); + length = LittleLong( header.lumps[AASLUMP_EDGEINDEX].filelen ); + ( *aasworld ).edgeindex = (aas_edgeindex_t *) AAS_LoadAASLump( fp, offset, length, ( *aasworld ).edgeindex ); + if ( !( *aasworld ).edgeindex ) { + return false; + } + ( *aasworld ).edgeindexsize = length / sizeof( aas_edgeindex_t ); + //faces + offset = fpoffset + LittleLong( header.lumps[AASLUMP_FACES].fileofs ); + length = LittleLong( header.lumps[AASLUMP_FACES].filelen ); + ( *aasworld ).faces = (aas_face_t *) AAS_LoadAASLump( fp, offset, length, ( *aasworld ).faces ); + if ( !( *aasworld ).faces ) { + return false; + } + ( *aasworld ).numfaces = length / sizeof( aas_face_t ); + //faceindex + offset = fpoffset + LittleLong( header.lumps[AASLUMP_FACEINDEX].fileofs ); + length = LittleLong( header.lumps[AASLUMP_FACEINDEX].filelen ); + ( *aasworld ).faceindex = (aas_faceindex_t *) AAS_LoadAASLump( fp, offset, length, ( *aasworld ).faceindex ); + if ( !( *aasworld ).faceindex ) { + return false; + } + ( *aasworld ).faceindexsize = length / sizeof( int ); + //convex areas + offset = fpoffset + LittleLong( header.lumps[AASLUMP_AREAS].fileofs ); + length = LittleLong( header.lumps[AASLUMP_AREAS].filelen ); + ( *aasworld ).areas = (aas_area_t *) AAS_LoadAASLump( fp, offset, length, ( *aasworld ).areas ); + if ( !( *aasworld ).areas ) { + return false; + } + ( *aasworld ).numareas = length / sizeof( aas_area_t ); + //area settings + offset = fpoffset + LittleLong( header.lumps[AASLUMP_AREASETTINGS].fileofs ); + length = LittleLong( header.lumps[AASLUMP_AREASETTINGS].filelen ); + ( *aasworld ).areasettings = (aas_areasettings_t *) AAS_LoadAASLump( fp, offset, length, ( *aasworld ).areasettings ); + if ( !( *aasworld ).areasettings ) { + return false; + } + ( *aasworld ).numareasettings = length / sizeof( aas_areasettings_t ); + //reachability list + offset = fpoffset + LittleLong( header.lumps[AASLUMP_REACHABILITY].fileofs ); + length = LittleLong( header.lumps[AASLUMP_REACHABILITY].filelen ); + ( *aasworld ).reachability = (aas_reachability_t *) AAS_LoadAASLump( fp, offset, length, ( *aasworld ).reachability ); + if ( length && !( *aasworld ).reachability ) { + return false; + } + ( *aasworld ).reachabilitysize = length / sizeof( aas_reachability_t ); + //nodes + offset = fpoffset + LittleLong( header.lumps[AASLUMP_NODES].fileofs ); + length = LittleLong( header.lumps[AASLUMP_NODES].filelen ); + ( *aasworld ).nodes = (aas_node_t *) AAS_LoadAASLump( fp, offset, length, ( *aasworld ).nodes ); + if ( !( *aasworld ).nodes ) { + return false; + } + ( *aasworld ).numnodes = length / sizeof( aas_node_t ); + //cluster portals + offset = fpoffset + LittleLong( header.lumps[AASLUMP_PORTALS].fileofs ); + length = LittleLong( header.lumps[AASLUMP_PORTALS].filelen ); + ( *aasworld ).portals = (aas_portal_t *) AAS_LoadAASLump( fp, offset, length, ( *aasworld ).portals ); + if ( length && !( *aasworld ).portals ) { + return false; + } + ( *aasworld ).numportals = length / sizeof( aas_portal_t ); + //cluster portal index + offset = fpoffset + LittleLong( header.lumps[AASLUMP_PORTALINDEX].fileofs ); + length = LittleLong( header.lumps[AASLUMP_PORTALINDEX].filelen ); + ( *aasworld ).portalindex = (aas_portalindex_t *) AAS_LoadAASLump( fp, offset, length, ( *aasworld ).portalindex ); + if ( length && !( *aasworld ).portalindex ) { + return false; + } + ( *aasworld ).portalindexsize = length / sizeof( aas_portalindex_t ); + //clusters + offset = fpoffset + LittleLong( header.lumps[AASLUMP_CLUSTERS].fileofs ); + length = LittleLong( header.lumps[AASLUMP_CLUSTERS].filelen ); + ( *aasworld ).clusters = (aas_cluster_t *) AAS_LoadAASLump( fp, offset, length, ( *aasworld ).clusters ); + if ( length && !( *aasworld ).clusters ) { + return false; + } + ( *aasworld ).numclusters = length / sizeof( aas_cluster_t ); + //swap everything + AAS_SwapAASData(); + //aas file is loaded + ( *aasworld ).loaded = true; + //close the file + fclose( fp ); + return true; +} //end of the function AAS_LoadAASFile +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_WriteAASLump( FILE *fp, aas_header_t *h, int lumpnum, void *data, int length ) { + aas_lump_t *lump; + + lump = &h->lumps[lumpnum]; + + lump->fileofs = LittleLong( ftell( fp ) ); + lump->filelen = LittleLong( length ); + + if ( length > 0 ) { + if ( fwrite( data, length, 1, fp ) < 1 ) { + Log_Print( "error writing lump %s\n", lumpnum ); + fclose( fp ); + return false; + } //end if + } //end if + return true; +} //end of the function AAS_WriteAASLump +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_ShowNumReachabilities( int tt, char *name ) { + int i, num; + + num = 0; + for ( i = 0; i < ( *aasworld ).reachabilitysize; i++ ) + { + if ( ( ( *aasworld ).reachability[i].traveltype & TRAVELTYPE_MASK ) == tt ) { + num++; + } + } //end for + Log_Print( "%6d %s\n", num, name ); +} //end of the function AAS_ShowNumReachabilities +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_ShowTotals( void ) { + Log_Print( "numvertexes = %d\r\n", ( *aasworld ).numvertexes ); + Log_Print( "numplanes = %d\r\n", ( *aasworld ).numplanes ); + Log_Print( "numedges = %d\r\n", ( *aasworld ).numedges ); + Log_Print( "edgeindexsize = %d\r\n", ( *aasworld ).edgeindexsize ); + Log_Print( "numfaces = %d\r\n", ( *aasworld ).numfaces ); + Log_Print( "faceindexsize = %d\r\n", ( *aasworld ).faceindexsize ); + Log_Print( "numareas = %d\r\n", ( *aasworld ).numareas ); + Log_Print( "numareasettings = %d\r\n", ( *aasworld ).numareasettings ); + Log_Print( "reachabilitysize = %d\r\n", ( *aasworld ).reachabilitysize ); + Log_Print( "numnodes = %d\r\n", ( *aasworld ).numnodes ); + Log_Print( "numportals = %d\r\n", ( *aasworld ).numportals ); + Log_Print( "portalindexsize = %d\r\n", ( *aasworld ).portalindexsize ); + Log_Print( "numclusters = %d\r\n", ( *aasworld ).numclusters ); + AAS_ShowNumReachabilities( TRAVEL_WALK, "walk" ); + AAS_ShowNumReachabilities( TRAVEL_CROUCH, "crouch" ); + AAS_ShowNumReachabilities( TRAVEL_BARRIERJUMP, "barrier jump" ); + AAS_ShowNumReachabilities( TRAVEL_JUMP, "jump" ); + AAS_ShowNumReachabilities( TRAVEL_LADDER, "ladder" ); + AAS_ShowNumReachabilities( TRAVEL_WALKOFFLEDGE, "walk off ledge" ); + AAS_ShowNumReachabilities( TRAVEL_SWIM, "swim" ); + AAS_ShowNumReachabilities( TRAVEL_WATERJUMP, "water jump" ); + AAS_ShowNumReachabilities( TRAVEL_TELEPORT, "teleport" ); + AAS_ShowNumReachabilities( TRAVEL_ELEVATOR, "elevator" ); + AAS_ShowNumReachabilities( TRAVEL_ROCKETJUMP, "rocket jump" ); + AAS_ShowNumReachabilities( TRAVEL_BFGJUMP, "bfg jump" ); + AAS_ShowNumReachabilities( TRAVEL_GRAPPLEHOOK, "grapple hook" ); + AAS_ShowNumReachabilities( TRAVEL_DOUBLEJUMP, "double jump" ); + AAS_ShowNumReachabilities( TRAVEL_RAMPJUMP, "ramp jump" ); + AAS_ShowNumReachabilities( TRAVEL_STRAFEJUMP, "strafe jump" ); + AAS_ShowNumReachabilities( TRAVEL_JUMPPAD, "jump pad" ); + AAS_ShowNumReachabilities( TRAVEL_FUNCBOB, "func bob" ); + +} //end of the function AAS_ShowTotals +//=========================================================================== +// aas data is useless after writing to file because it is byte swapped +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +qboolean AAS_WriteAASFile( char *filename ) { + aas_header_t header; + FILE *fp; + + Log_Print( "writing %s\n", filename ); + AAS_ShowTotals(); + //swap the aas data + AAS_SwapAASData(); + //initialize the file header + memset( &header, 0, sizeof( aas_header_t ) ); + header.ident = LittleLong( AASID ); + header.version = LittleLong( AASVERSION ); + header.bspchecksum = LittleLong( ( *aasworld ).bspchecksum ); + //open a new file + fp = fopen( filename, "wb" ); + if ( !fp ) { + Log_Print( "error opening %s\n", filename ); + return false; + } //end if + //write the header + if ( fwrite( &header, sizeof( aas_header_t ), 1, fp ) < 1 ) { + fclose( fp ); + return false; + } //end if + //add the data lumps to the file + if ( !AAS_WriteAASLump( fp, &header, AASLUMP_BBOXES, ( *aasworld ).bboxes, + ( *aasworld ).numbboxes * sizeof( aas_bbox_t ) ) ) { + return false; + } + if ( !AAS_WriteAASLump( fp, &header, AASLUMP_VERTEXES, ( *aasworld ).vertexes, + ( *aasworld ).numvertexes * sizeof( aas_vertex_t ) ) ) { + return false; + } + if ( !AAS_WriteAASLump( fp, &header, AASLUMP_PLANES, ( *aasworld ).planes, + ( *aasworld ).numplanes * sizeof( aas_plane_t ) ) ) { + return false; + } + if ( !AAS_WriteAASLump( fp, &header, AASLUMP_EDGES, ( *aasworld ).edges, + ( *aasworld ).numedges * sizeof( aas_edge_t ) ) ) { + return false; + } + if ( !AAS_WriteAASLump( fp, &header, AASLUMP_EDGEINDEX, ( *aasworld ).edgeindex, + ( *aasworld ).edgeindexsize * sizeof( aas_edgeindex_t ) ) ) { + return false; + } + if ( !AAS_WriteAASLump( fp, &header, AASLUMP_FACES, ( *aasworld ).faces, + ( *aasworld ).numfaces * sizeof( aas_face_t ) ) ) { + return false; + } + if ( !AAS_WriteAASLump( fp, &header, AASLUMP_FACEINDEX, ( *aasworld ).faceindex, + ( *aasworld ).faceindexsize * sizeof( aas_faceindex_t ) ) ) { + return false; + } + if ( !AAS_WriteAASLump( fp, &header, AASLUMP_AREAS, ( *aasworld ).areas, + ( *aasworld ).numareas * sizeof( aas_area_t ) ) ) { + return false; + } + if ( !AAS_WriteAASLump( fp, &header, AASLUMP_AREASETTINGS, ( *aasworld ).areasettings, + ( *aasworld ).numareasettings * sizeof( aas_areasettings_t ) ) ) { + return false; + } + if ( !AAS_WriteAASLump( fp, &header, AASLUMP_REACHABILITY, ( *aasworld ).reachability, + ( *aasworld ).reachabilitysize * sizeof( aas_reachability_t ) ) ) { + return false; + } + if ( !AAS_WriteAASLump( fp, &header, AASLUMP_NODES, ( *aasworld ).nodes, + ( *aasworld ).numnodes * sizeof( aas_node_t ) ) ) { + return false; + } + if ( !AAS_WriteAASLump( fp, &header, AASLUMP_PORTALS, ( *aasworld ).portals, + ( *aasworld ).numportals * sizeof( aas_portal_t ) ) ) { + return false; + } + if ( !AAS_WriteAASLump( fp, &header, AASLUMP_PORTALINDEX, ( *aasworld ).portalindex, + ( *aasworld ).portalindexsize * sizeof( aas_portalindex_t ) ) ) { + return false; + } + if ( !AAS_WriteAASLump( fp, &header, AASLUMP_CLUSTERS, ( *aasworld ).clusters, + ( *aasworld ).numclusters * sizeof( aas_cluster_t ) ) ) { + return false; + } + //rewrite the header with the added lumps + fseek( fp, 0, SEEK_SET ); + AAS_DData( (unsigned char *) &header + 8, sizeof( aas_header_t ) - 8 ); + if ( fwrite( &header, sizeof( aas_header_t ), 1, fp ) < 1 ) { + fclose( fp ); + return false; + } //end if + //close the file + fclose( fp ); + return true; +} //end of the function AAS_WriteAASFile + diff --git a/Projects/Android/jni/rtcw/src/bspc/aas_file.h b/Projects/Android/jni/rtcw/src/bspc/aas_file.h new file mode 100644 index 0000000..dbe6032 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/bspc/aas_file.h @@ -0,0 +1,40 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +//=========================================================================== +// +// Name: aas_write.h +// Function: +// Programmer: Mr Elusive (MrElusive@demigod.demon.nl) +// Last update: 1997-12-04 +// Tab Size: 3 +//=========================================================================== + +qboolean AAS_WriteAASFile( char *filename ); +qboolean AAS_LoadAASFile( char *filename, int fpoffset, int fplength ); + diff --git a/Projects/Android/jni/rtcw/src/bspc/aas_gsubdiv.c b/Projects/Android/jni/rtcw/src/bspc/aas_gsubdiv.c new file mode 100644 index 0000000..184f569 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/bspc/aas_gsubdiv.c @@ -0,0 +1,688 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +//=========================================================================== +// +// Name: aas_gsubdiv.c +// Function: Gravitational Subdivision +// Programmer: Mr Elusive (MrElusive@demigod.demon.nl) +// Last update: 1997-12-04 +// Tab Size: 3 +//=========================================================================== + +#include "qbsp.h" +#include "../botlib/aasfile.h" +#include "aas_create.h" +#include "aas_store.h" +#include "aas_cfg.h" + +#define FACECLIP_EPSILON 0.2 +#define FACE_EPSILON 1.0 + +int numgravitationalsubdivisions = 0; +int numladdersubdivisions = 0; + +//NOTE: only do gravitational subdivision BEFORE area merging!!!!!!! +// because the bsp tree isn't refreshes like with ladder subdivision + +//=========================================================================== +// NOTE: the original face is invalid after splitting +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_SplitFace( tmp_face_t *face, vec3_t normal, float dist, + tmp_face_t **frontface, tmp_face_t **backface ) { + winding_t *frontw, *backw; + + // + *frontface = *backface = NULL; + + ClipWindingEpsilon( face->winding, normal, dist, FACECLIP_EPSILON, &frontw, &backw ); + +#ifdef DEBUG + // + if ( frontw ) { + if ( WindingIsTiny( frontw ) ) { + Log_Write( "AAS_SplitFace: tiny back face\r\n" ); + FreeWinding( frontw ); + frontw = NULL; + } //end if + } //end if + if ( backw ) { + if ( WindingIsTiny( backw ) ) { + Log_Write( "AAS_SplitFace: tiny back face\r\n" ); + FreeWinding( backw ); + backw = NULL; + } //end if + } //end if +#endif //DEBUG + //if the winding was split + if ( frontw ) { + //check bounds + ( *frontface ) = AAS_AllocTmpFace(); + ( *frontface )->planenum = face->planenum; + ( *frontface )->winding = frontw; + ( *frontface )->faceflags = face->faceflags; + } //end if + if ( backw ) { + //check bounds + ( *backface ) = AAS_AllocTmpFace(); + ( *backface )->planenum = face->planenum; + ( *backface )->winding = backw; + ( *backface )->faceflags = face->faceflags; + } //end if +} //end of the function AAS_SplitFace +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +winding_t *AAS_SplitWinding( tmp_area_t *tmparea, int planenum ) { + tmp_face_t *face; + plane_t *plane; + int side; + winding_t *splitwinding; + + // + plane = &mapplanes[planenum]; + //create a split winding, first base winding for plane + splitwinding = BaseWindingForPlane( plane->normal, plane->dist ); + //chop with all the faces of the area + for ( face = tmparea->tmpfaces; face && splitwinding; face = face->next[side] ) + { + //side of the face the original area was on + side = face->frontarea != tmparea; + plane = &mapplanes[face->planenum ^ side]; + ChopWindingInPlace( &splitwinding, plane->normal, plane->dist, 0 ); // PLANESIDE_EPSILON); + } //end for + return splitwinding; +} //end of the function AAS_SplitWinding +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_TestSplitPlane( tmp_area_t *tmparea, vec3_t normal, float dist, + int *facesplits, int *groundsplits, int *epsilonfaces ) { + int j, side, front, back, planenum; + float d, d_front, d_back; + tmp_face_t *face; + winding_t *w; + + *facesplits = *groundsplits = *epsilonfaces = 0; + + planenum = FindFloatPlane( normal, dist ); + + w = AAS_SplitWinding( tmparea, planenum ); + if ( !w ) { + return false; + } + FreeWinding( w ); + // + for ( face = tmparea->tmpfaces; face; face = face->next[side] ) + { + //side of the face the area is on + side = face->frontarea != tmparea; + + if ( ( face->planenum & ~1 ) == ( planenum & ~1 ) ) { + Log_Print( "AAS_TestSplitPlane: tried face plane as splitter\n" ); + return false; + } //end if + w = face->winding; + //reset distance at front and back side of plane + d_front = d_back = 0; + //reset front and back flags + front = back = 0; + for ( j = 0; j < w->numpoints; j++ ) + { + d = DotProduct( w->p[j], normal ) - dist; + if ( d > d_front ) { + d_front = d; + } + if ( d < d_back ) { + d_back = d; + } + + if ( d > 0.4 ) { // PLANESIDE_EPSILON) + front = 1; + } + if ( d < -0.4 ) { // PLANESIDE_EPSILON) + back = 1; + } + } //end for + //check for an epsilon face + if ( ( d_front > FACECLIP_EPSILON && d_front < FACE_EPSILON ) + || ( d_back < -FACECLIP_EPSILON && d_back > -FACE_EPSILON ) ) { + ( *epsilonfaces )++; + } //end if + //if the face has points at both sides of the plane + if ( front && back ) { + ( *facesplits )++; + if ( face->faceflags & FACE_GROUND ) { + ( *groundsplits )++; + } //end if + } //end if + } //end for + return true; +} //end of the function AAS_TestSplitPlane +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_SplitArea( tmp_area_t *tmparea, int planenum, tmp_area_t **frontarea, tmp_area_t **backarea ) { + int side; + tmp_area_t *facefrontarea, *facebackarea, *faceotherarea; + tmp_face_t *face, *frontface, *backface, *splitface, *nextface; + winding_t *splitwinding; + plane_t *splitplane; + +/* +#ifdef AW_DEBUG + int facesplits, groundsplits, epsilonface; + Log_Print("\n----------------------\n"); + Log_Print("splitting area %d\n", areanum); + Log_Print("with normal = \'%f %f %f\', dist = %f\n", normal[0], normal[1], normal[2], dist); + AAS_TestSplitPlane(areanum, normal, dist, + &facesplits, &groundsplits, &epsilonface); + Log_Print("face splits = %d\nground splits = %d\n", facesplits, groundsplits); + if (epsilonface) Log_Print("aaahh epsilon face\n"); +#endif //AW_DEBUG*/ + //the original area + + AAS_FlipAreaFaces( tmparea ); + AAS_CheckArea( tmparea ); + // + splitplane = &mapplanes[planenum]; +/* //create a split winding, first base winding for plane + splitwinding = BaseWindingForPlane(splitplane->normal, splitplane->dist); + //chop with all the faces of the area + for (face = tmparea->tmpfaces; face && splitwinding; face = face->next[side]) + { + //side of the face the original area was on + side = face->frontarea != tmparea->areanum; + plane = &mapplanes[face->planenum ^ side]; + ChopWindingInPlace(&splitwinding, plane->normal, plane->dist, 0); // PLANESIDE_EPSILON); + } //end for*/ + splitwinding = AAS_SplitWinding( tmparea, planenum ); + if ( !splitwinding ) { +/* +#ifdef DEBUG + AAS_TestSplitPlane(areanum, normal, dist, + &facesplits, &groundsplits, &epsilonface); + Log_Print("\nface splits = %d\nground splits = %d\n", facesplits, groundsplits); + if (epsilonface) Log_Print("aaahh epsilon face\n"); +#endif //DEBUG*/ + Error( "AAS_SplitArea: no split winding when splitting area %d\n", tmparea->areanum ); + } //end if + //create a split face + splitface = AAS_AllocTmpFace(); + //get the map plane + splitface->planenum = planenum; + //store the split winding + splitface->winding = splitwinding; + //the new front area + ( *frontarea ) = AAS_AllocTmpArea(); + ( *frontarea )->presencetype = tmparea->presencetype; + ( *frontarea )->contents = tmparea->contents; + ( *frontarea )->modelnum = tmparea->modelnum; + ( *frontarea )->tmpfaces = NULL; + //the new back area + ( *backarea ) = AAS_AllocTmpArea(); + ( *backarea )->presencetype = tmparea->presencetype; + ( *backarea )->contents = tmparea->contents; + ( *backarea )->modelnum = tmparea->modelnum; + ( *backarea )->tmpfaces = NULL; + //add the split face to the new areas + AAS_AddFaceSideToArea( splitface, 0, ( *frontarea ) ); + AAS_AddFaceSideToArea( splitface, 1, ( *backarea ) ); + + //split all the faces of the original area + for ( face = tmparea->tmpfaces; face; face = nextface ) + { + //side of the face the original area was on + side = face->frontarea != tmparea; + //next face of the original area + nextface = face->next[side]; + //front area of the face + facefrontarea = face->frontarea; + //back area of the face + facebackarea = face->backarea; + //remove the face from both the front and back areas + if ( facefrontarea ) { + AAS_RemoveFaceFromArea( face, facefrontarea ); + } + if ( facebackarea ) { + AAS_RemoveFaceFromArea( face, facebackarea ); + } + //split the face + AAS_SplitFace( face, splitplane->normal, splitplane->dist, &frontface, &backface ); + //free the original face + AAS_FreeTmpFace( face ); + //get the number of the area at the other side of the face + if ( side ) { + faceotherarea = facefrontarea; + } else { faceotherarea = facebackarea;} + //if there is an area at the other side of the original face + if ( faceotherarea ) { + if ( frontface ) { + AAS_AddFaceSideToArea( frontface, !side, faceotherarea ); + } + if ( backface ) { + AAS_AddFaceSideToArea( backface, !side, faceotherarea ); + } + } //end if + //add the front and back part left after splitting the original face to the new areas + if ( frontface ) { + AAS_AddFaceSideToArea( frontface, side, ( *frontarea ) ); + } + if ( backface ) { + AAS_AddFaceSideToArea( backface, side, ( *backarea ) ); + } + } //end for + + if ( !( *frontarea )->tmpfaces ) { + Log_Print( "AAS_SplitArea: front area without faces\n" ); + } + if ( !( *backarea )->tmpfaces ) { + Log_Print( "AAS_SplitArea: back area without faces\n" ); + } + + tmparea->invalid = true; +/* +#ifdef AW_DEBUG + for (i = 0, face = frontarea->tmpfaces; face; face = face->next[side]) + { + side = face->frontarea != frontarea->areanum; + i++; + } //end for + Log_Print("created front area %d with %d faces\n", frontarea->areanum, i); + + for (i = 0, face = backarea->tmpfaces; face; face = face->next[side]) + { + side = face->frontarea != backarea->areanum; + i++; + } //end for + Log_Print("created back area %d with %d faces\n", backarea->areanum, i); +#endif //AW_DEBUG*/ + + AAS_FlipAreaFaces( ( *frontarea ) ); + AAS_FlipAreaFaces( ( *backarea ) ); + // + AAS_CheckArea( ( *frontarea ) ); + AAS_CheckArea( ( *backarea ) ); +} //end of the function AAS_SplitArea +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_FindBestAreaSplitPlane( tmp_area_t *tmparea, vec3_t normal, float *dist ) { + int side1, side2; + int foundsplitter, facesplits, groundsplits, epsilonfaces, bestepsilonfaces; + float bestvalue, value; + tmp_face_t *face1, *face2; + vec3_t tmpnormal, invgravity; + float tmpdist; + + //get inverse of gravity direction + VectorCopy( cfg.phys_gravitydirection, invgravity ); + VectorInverse( invgravity ); + + foundsplitter = false; + bestvalue = -999999; + bestepsilonfaces = 0; + // +#ifdef AW_DEBUG + Log_Print( "finding split plane for area %d\n", tmparea->areanum ); +#endif //AW_DEBUG + for ( face1 = tmparea->tmpfaces; face1; face1 = face1->next[side1] ) + { + //side of the face the area is on + side1 = face1->frontarea != tmparea; + // + if ( WindingIsTiny( face1->winding ) ) { + Log_Write( "gsubdiv: area %d has a tiny winding\r\n", tmparea->areanum ); + continue; + } //end if + //if the face isn't a gap or ground there's no split edge + if ( !( face1->faceflags & FACE_GROUND ) && !AAS_GapFace( face1, side1 ) ) { + continue; + } + // + for ( face2 = face1->next[side1]; face2; face2 = face2->next[side2] ) + { + //side of the face the area is on + side2 = face2->frontarea != tmparea; + // + if ( WindingIsTiny( face1->winding ) ) { + Log_Write( "gsubdiv: area %d has a tiny winding\r\n", tmparea->areanum ); + continue; + } //end if + //if the face isn't a gap or ground there's no split edge + if ( !( face2->faceflags & FACE_GROUND ) && !AAS_GapFace( face2, side2 ) ) { + continue; + } + //only split between gaps and ground + if ( !( ( ( face1->faceflags & FACE_GROUND ) && AAS_GapFace( face2, side2 ) ) || + ( ( face2->faceflags & FACE_GROUND ) && AAS_GapFace( face1, side1 ) ) ) ) { + continue; + } + //find a plane seperating the windings of the faces + if ( !FindPlaneSeperatingWindings( face1->winding, face2->winding, invgravity, + tmpnormal, &tmpdist ) ) { + continue; + } +#ifdef AW_DEBUG + Log_Print( "normal = \'%f %f %f\', dist = %f\n", + tmpnormal[0], tmpnormal[1], tmpnormal[2], tmpdist ); +#endif //AW_DEBUG + //get metrics for this vertical plane + if ( !AAS_TestSplitPlane( tmparea, tmpnormal, tmpdist, + &facesplits, &groundsplits, &epsilonfaces ) ) { + continue; + } //end if +#ifdef AW_DEBUG + Log_Print( "face splits = %d\nground splits = %d\n", + facesplits, groundsplits ); +#endif //AW_DEBUG + value = 100 - facesplits - 2 * groundsplits; + //avoid epsilon faces + value += epsilonfaces * -1000; + if ( value > bestvalue ) { + VectorCopy( tmpnormal, normal ); + *dist = tmpdist; + bestvalue = value; + bestepsilonfaces = epsilonfaces; + foundsplitter = true; + } //end if + } //end for + } //end for + if ( bestepsilonfaces ) { + Log_Write( "found %d epsilon faces trying to split area %d\r\n", + epsilonfaces, tmparea->areanum ); + } //end else + return foundsplitter; +} //end of the function AAS_FindBestAreaSplitPlane +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +tmp_node_t *AAS_SubdivideArea_r( tmp_node_t *tmpnode ) { + int planenum; + tmp_area_t *frontarea, *backarea; + tmp_node_t *tmpnode1, *tmpnode2; + vec3_t normal; + float dist; + + if ( AAS_FindBestAreaSplitPlane( tmpnode->tmparea, normal, &dist ) ) { + qprintf( "\r%6d", ++numgravitationalsubdivisions ); + // + planenum = FindFloatPlane( normal, dist ); + //split the area + AAS_SplitArea( tmpnode->tmparea, planenum, &frontarea, &backarea ); + // + tmpnode->tmparea = NULL; + tmpnode->planenum = FindFloatPlane( normal, dist ); + // + tmpnode1 = AAS_AllocTmpNode(); + tmpnode1->planenum = 0; + tmpnode1->tmparea = frontarea; + // + tmpnode2 = AAS_AllocTmpNode(); + tmpnode2->planenum = 0; + tmpnode2->tmparea = backarea; + //subdivide the areas created by splitting recursively + tmpnode->children[0] = AAS_SubdivideArea_r( tmpnode1 ); + tmpnode->children[1] = AAS_SubdivideArea_r( tmpnode2 ); + } //end if + return tmpnode; +} //end of the function AAS_SubdivideArea_r +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +tmp_node_t *AAS_GravitationalSubdivision_r( tmp_node_t *tmpnode ) { + //if this is a solid leaf + if ( !tmpnode ) { + return NULL; + } + //negative so it's an area + if ( tmpnode->tmparea ) { + return AAS_SubdivideArea_r( tmpnode ); + } + //do the children recursively + tmpnode->children[0] = AAS_GravitationalSubdivision_r( tmpnode->children[0] ); + tmpnode->children[1] = AAS_GravitationalSubdivision_r( tmpnode->children[1] ); + return tmpnode; +} //end of the function AAS_GravitationalSubdivision_r +//=========================================================================== +// NOTE: merge faces and melt edges first +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_GravitationalSubdivision( void ) { + Log_Write( "AAS_GravitationalSubdivision\r\n" ); + numgravitationalsubdivisions = 0; + qprintf( "%6i gravitational subdivisions", numgravitationalsubdivisions ); + //start with the head node + AAS_GravitationalSubdivision_r( tmpaasworld.nodes ); + qprintf( "\n" ); + Log_Write( "%6i gravitational subdivisions\r\n", numgravitationalsubdivisions ); +} //end of the function AAS_GravitationalSubdivision +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +tmp_node_t *AAS_RefreshLadderSubdividedTree_r( tmp_node_t *tmpnode, tmp_area_t *tmparea, + tmp_node_t *tmpnode1, tmp_node_t *tmpnode2, int planenum ) { + //if this is a solid leaf + if ( !tmpnode ) { + return NULL; + } + //negative so it's an area + if ( tmpnode->tmparea ) { + if ( tmpnode->tmparea == tmparea ) { + tmpnode->tmparea = NULL; + tmpnode->planenum = planenum; + tmpnode->children[0] = tmpnode1; + tmpnode->children[1] = tmpnode2; + } //end if + return tmpnode; + } //end if + //do the children recursively + tmpnode->children[0] = AAS_RefreshLadderSubdividedTree_r( tmpnode->children[0], + tmparea, tmpnode1, tmpnode2, planenum ); + tmpnode->children[1] = AAS_RefreshLadderSubdividedTree_r( tmpnode->children[1], + tmparea, tmpnode1, tmpnode2, planenum ); + return tmpnode; +} //end of the function AAS_RefreshLadderSubdividedTree_r +//=========================================================================== +// find an area with ladder faces and ground faces that are not connected +// split the area with a horizontal plane at the lowest vertex of all +// ladder faces in the area +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +tmp_node_t *AAS_LadderSubdivideArea_r( tmp_node_t *tmpnode ) { + int side1, i, planenum; + int foundladderface, foundgroundface; + float dist; + tmp_area_t *tmparea, *frontarea, *backarea; + tmp_face_t *face1; + tmp_node_t *tmpnode1, *tmpnode2; + vec3_t lowestpoint, normal = {0, 0, 1}; + plane_t *plane; + winding_t *w; + + tmparea = tmpnode->tmparea; + //skip areas with a liquid + if ( tmparea->contents & ( AREACONTENTS_WATER + | AREACONTENTS_LAVA + | AREACONTENTS_SLIME ) ) { + return tmpnode; + } + //must be possible to stand in the area + if ( !( tmparea->presencetype & PRESENCE_NORMAL ) ) { + return tmpnode; + } + // + foundladderface = false; + foundgroundface = false; + lowestpoint[2] = 99999; + // + for ( face1 = tmparea->tmpfaces; face1; face1 = face1->next[side1] ) + { + //side of the face the area is on + side1 = face1->frontarea != tmparea; + //if the face is a ladder face + if ( face1->faceflags & FACE_LADDER ) { + plane = &mapplanes[face1->planenum]; + //the ladder face plane should be pretty much vertical + if ( DotProduct( plane->normal, normal ) > -0.1 ) { + foundladderface = true; + //find lowest point + for ( i = 0; i < face1->winding->numpoints; i++ ) + { + if ( face1->winding->p[i][2] < lowestpoint[2] ) { + VectorCopy( face1->winding->p[i], lowestpoint ); + } //end if + } //end for + } //end if + } //end if + else if ( face1->faceflags & FACE_GROUND ) { + foundgroundface = true; + } //end else if + } //end for + // + if ( ( !foundladderface ) || ( !foundgroundface ) ) { + return tmpnode; + } + // + for ( face1 = tmparea->tmpfaces; face1; face1 = face1->next[side1] ) + { + //side of the face the area is on + side1 = face1->frontarea != tmparea; + //if the face isn't a ground face + if ( !( face1->faceflags & FACE_GROUND ) ) { + continue; + } + //the ground plane + plane = &mapplanes[face1->planenum]; + //get the difference between the ground plane and the lowest point + dist = DotProduct( plane->normal, lowestpoint ) - plane->dist; + //if the lowest point is very near one of the ground planes + if ( dist > -1 && dist < 1 ) { + return tmpnode; + } //end if + } //end for + // + dist = DotProduct( normal, lowestpoint ); + planenum = FindFloatPlane( normal, dist ); + // + w = AAS_SplitWinding( tmparea, planenum ); + if ( !w ) { + return tmpnode; + } + FreeWinding( w ); + //split the area with a horizontal plane through the lowest point + qprintf( "\r%6d", ++numladdersubdivisions ); + // + AAS_SplitArea( tmparea, planenum, &frontarea, &backarea ); + // + tmpnode->tmparea = NULL; + tmpnode->planenum = planenum; + // + tmpnode1 = AAS_AllocTmpNode(); + tmpnode1->planenum = 0; + tmpnode1->tmparea = frontarea; + // + tmpnode2 = AAS_AllocTmpNode(); + tmpnode2->planenum = 0; + tmpnode2->tmparea = backarea; + //subdivide the areas created by splitting recursively + tmpnode->children[0] = AAS_LadderSubdivideArea_r( tmpnode1 ); + tmpnode->children[1] = AAS_LadderSubdivideArea_r( tmpnode2 ); + //refresh the tree + AAS_RefreshLadderSubdividedTree_r( tmpaasworld.nodes, tmparea, tmpnode1, tmpnode2, planenum ); + // + return tmpnode; +} //end of the function AAS_LadderSubdivideArea_r +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +tmp_node_t *AAS_LadderSubdivision_r( tmp_node_t *tmpnode ) { + //if this is a solid leaf + if ( !tmpnode ) { + return 0; + } + //negative so it's an area + if ( tmpnode->tmparea ) { + return AAS_LadderSubdivideArea_r( tmpnode ); + } + //do the children recursively + tmpnode->children[0] = AAS_LadderSubdivision_r( tmpnode->children[0] ); + tmpnode->children[1] = AAS_LadderSubdivision_r( tmpnode->children[1] ); + return tmpnode; +} //end of the function AAS_LadderSubdivision_r +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_LadderSubdivision( void ) { + Log_Write( "AAS_LadderSubdivision\r\n" ); + numladdersubdivisions = 0; + qprintf( "%6i ladder subdivisions", numladdersubdivisions ); + //start with the head node + AAS_LadderSubdivision_r( tmpaasworld.nodes ); + // + qprintf( "\n" ); + Log_Write( "%6i ladder subdivisions\r\n", numladdersubdivisions ); +} //end of the function AAS_LadderSubdivision + diff --git a/Projects/Android/jni/rtcw/src/bspc/aas_gsubdiv.h b/Projects/Android/jni/rtcw/src/bspc/aas_gsubdiv.h new file mode 100644 index 0000000..4964a40 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/bspc/aas_gsubdiv.h @@ -0,0 +1,40 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +//=========================================================================== +// +// Name: aas_gsubdiv.h +// Function: Gravitational subdivision +// Programmer: Mr Elusive (MrElusive@demigod.demon.nl) +// Last update: 1997-12-04 +// Tab Size: 3 +//=========================================================================== + +//works with the global tmpaasworld +void AAS_GravitationalSubdivision( void ); +void AAS_LadderSubdivision( void ); diff --git a/Projects/Android/jni/rtcw/src/bspc/aas_map.c b/Projects/Android/jni/rtcw/src/bspc/aas_map.c new file mode 100644 index 0000000..3256d27 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/bspc/aas_map.c @@ -0,0 +1,840 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +//=========================================================================== +// +// Name: aas_map.c +// Function: +// Programmer: Mr Elusive (MrElusive@demigod.demon.nl) +// Last update: 1997-12-03 +// Tab Size: 3 +//=========================================================================== + +#include "qbsp.h" +#include "l_mem.h" +#include "../botlib/aasfile.h" //aas_bbox_t +#include "aas_store.h" //AAS_MAX_BBOXES +#include "aas_cfg.h" +#include "../game/surfaceflags.h" + +#define SPAWNFLAG_NOT_EASY 0x00000100 +#define SPAWNFLAG_NOT_MEDIUM 0x00000200 +#define SPAWNFLAG_NOT_HARD 0x00000400 +#define SPAWNFLAG_NOT_DEATHMATCH 0x00000800 +#define SPAWNFLAG_NOT_COOP 0x00001000 + +#define STATE_TOP 0 +#define STATE_BOTTOM 1 +#define STATE_UP 2 +#define STATE_DOWN 3 + +#define DOOR_START_OPEN 1 +#define DOOR_REVERSE 2 +#define DOOR_CRUSHER 4 +#define DOOR_NOMONSTER 8 +#define DOOR_TOGGLE 32 +#define DOOR_X_AXIS 64 +#define DOOR_Y_AXIS 128 + +#define BBOX_NORMAL_EPSILON 0.00001 + +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +vec_t BoxOriginDistanceFromPlane( vec3_t normal, vec3_t mins, vec3_t maxs, int side ) { + vec3_t v1, v2; + int i; + + if ( side ) { + for ( i = 0; i < 3; i++ ) + { + if ( normal[i] > BBOX_NORMAL_EPSILON ) { + v1[i] = maxs[i]; + } else if ( normal[i] < -BBOX_NORMAL_EPSILON ) { + v1[i] = mins[i]; + } else { v1[i] = 0;} + } //end for + } //end if + else + { + for ( i = 0; i < 3; i++ ) + { + if ( normal[i] > BBOX_NORMAL_EPSILON ) { + v1[i] = mins[i]; + } else if ( normal[i] < -BBOX_NORMAL_EPSILON ) { + v1[i] = maxs[i]; + } else { v1[i] = 0;} + } //end for + } //end else + VectorCopy( normal, v2 ); + VectorInverse( v2 ); + return DotProduct( v1, v2 ); +} //end of the function BoxOriginDistanceFromPlane +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +vec_t CapsuleOriginDistanceFromPlane( vec3_t normal, vec3_t mins, vec3_t maxs ) { + float offset_up, offset_down, width, radius; + + width = maxs[0] - mins[0]; + // if the box is less high then it is wide + if ( maxs[2] - mins[2] < width ) { + width = maxs[2] - mins[2]; + } + radius = width * 0.5; + // offset to upper and lower sphere + offset_up = maxs[2] - radius; + offset_down = -mins[2] - radius; + + // if normal points upward + if ( normal[2] > 0 ) { + // touches lower sphere first + return normal[2] * offset_down + radius; + } else { + // touched upper sphere first + return -normal[2] * offset_up + radius; + } +} +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_ExpandMapBrush( mapbrush_t *brush, vec3_t mins, vec3_t maxs ) { + int sn; + float dist; + side_t *s; + plane_t *plane; + + for ( sn = 0; sn < brush->numsides; sn++ ) + { + s = brush->original_sides + sn; + plane = &mapplanes[s->planenum]; + dist = plane->dist; + if ( capsule_collision ) { + dist += CapsuleOriginDistanceFromPlane( plane->normal, mins, maxs ); + } else { + dist += BoxOriginDistanceFromPlane( plane->normal, mins, maxs, 0 ); + } + s->planenum = FindFloatPlane( plane->normal, dist ); + //the side isn't a bevel after expanding + s->flags &= ~SFL_BEVEL; + //don't skip the surface + s->surf &= ~SURF_SKIP; + //make sure the texinfo is not TEXINFO_NODE + //when player clip contents brushes are read from the bsp tree + //they have the texinfo field set to TEXINFO_NODE + //s->texinfo = 0; + } //end for +} //end of the function AAS_ExpandMapBrush +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_SetTexinfo( mapbrush_t *brush ) { + int n; + side_t *side; + + if ( brush->contents & ( CONTENTS_LADDER + | CONTENTS_AREAPORTAL + | CONTENTS_CLUSTERPORTAL + | CONTENTS_TELEPORTER + | CONTENTS_JUMPPAD + | CONTENTS_DONOTENTER + | CONTENTS_DONOTENTER_LARGE + | CONTENTS_WATER + | CONTENTS_LAVA + | CONTENTS_SLIME + | CONTENTS_WINDOW + | CONTENTS_PLAYERCLIP ) ) { + //we just set texinfo to 0 because these brush sides MUST be used as + //bsp splitters textured or not textured + for ( n = 0; n < brush->numsides; n++ ) + { + side = brush->original_sides + n; + //side->flags |= SFL_TEXTURED|SFL_VISIBLE; + side->texinfo = 0; + } //end for + } //end if + else + { + //only use brush sides as splitters if they are textured + //texinfo of non-textured sides will be set to TEXINFO_NODE + for ( n = 0; n < brush->numsides; n++ ) + { + side = brush->original_sides + n; + //don't use side as splitter (set texinfo to TEXINFO_NODE) if not textured + if ( side->flags & ( SFL_TEXTURED | SFL_BEVEL ) ) { + side->texinfo = 0; + } else { side->texinfo = TEXINFO_NODE;} + } //end for + } //end else +} //end of the function AAS_SetTexinfo +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void FreeBrushWindings( mapbrush_t *brush ) { + int n; + side_t *side; + // + for ( n = 0; n < brush->numsides; n++ ) + { + side = brush->original_sides + n; + // + if ( side->winding ) { + FreeWinding( side->winding ); + } + } //end for +} //end of the function FreeBrushWindings +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_AddMapBrushSide( mapbrush_t *brush, int planenum ) { + side_t *side; + // + if ( nummapbrushsides >= MAX_MAPFILE_BRUSHSIDES ) { + Error( "MAX_MAPFILE_BRUSHSIDES" ); + } + // + side = brush->original_sides + brush->numsides; + side->original = NULL; + side->winding = NULL; + side->contents = brush->contents; + side->flags &= ~( SFL_BEVEL | SFL_VISIBLE ); + side->surf = 0; + side->planenum = planenum; + side->texinfo = 0; + // + nummapbrushsides++; + brush->numsides++; +} //end of the function AAS_AddMapBrushSide +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_FixMapBrush( mapbrush_t *brush ) { + int i, j, planenum; + float dist; + winding_t *w; + plane_t *plane, *plane1, *plane2; + side_t *side; + vec3_t normal; + + //calculate the brush bounds + ClearBounds( brush->mins, brush->maxs ); + for ( i = 0; i < brush->numsides; i++ ) + { + plane = &mapplanes[brush->original_sides[i].planenum]; + w = BaseWindingForPlane( plane->normal, plane->dist ); + for ( j = 0; j < brush->numsides && w; j++ ) + { + if ( i == j ) { + continue; + } + //there are no brush bevels marked but who cares :) + if ( brush->original_sides[j].flags & SFL_BEVEL ) { + continue; + } + plane = &mapplanes[brush->original_sides[j].planenum ^ 1]; + ChopWindingInPlace( &w, plane->normal, plane->dist, 0 ); //CLIP_EPSILON); + } //end for + + side = &brush->original_sides[i]; + side->winding = w; + if ( w ) { + for ( j = 0; j < w->numpoints; j++ ) + { + AddPointToBounds( w->p[j], brush->mins, brush->maxs ); + } //end for + } //end if + } //end for + // + for ( i = 0; i < brush->numsides; i++ ) + { + for ( j = 0; j < brush->numsides; j++ ) + { + if ( i == j ) { + continue; + } + plane1 = &mapplanes[brush->original_sides[i].planenum]; + plane2 = &mapplanes[brush->original_sides[j].planenum]; + if ( WindingsNonConvex( brush->original_sides[i].winding, + brush->original_sides[j].winding, + plane1->normal, plane2->normal, + plane1->dist, plane2->dist ) ) { + Log_Print( "non convex brush" ); + } //end if + } //end for + } //end for + + //NOW close the fucking brush!! + for ( i = 0; i < 3; i++ ) + { + if ( brush->mins[i] < -MAX_MAP_BOUNDS ) { + VectorClear( normal ); + normal[i] = -1; + dist = MAX_MAP_BOUNDS - 10; + planenum = FindFloatPlane( normal, dist ); + // + Log_Print( "mins out of range: added extra brush side\n" ); + AAS_AddMapBrushSide( brush, planenum ); + } //end if + if ( brush->maxs[i] > MAX_MAP_BOUNDS ) { + VectorClear( normal ); + normal[i] = 1; + dist = MAX_MAP_BOUNDS - 10; + planenum = FindFloatPlane( normal, dist ); + // + Log_Print( "maxs out of range: added extra brush side\n" ); + AAS_AddMapBrushSide( brush, planenum ); + } //end if + if ( brush->mins[i] > MAX_MAP_BOUNDS || brush->maxs[i] < -MAX_MAP_BOUNDS ) { + Log_Print( "entity %i, brush %i: no visible sides on brush\n", brush->entitynum, brush->brushnum ); + } //end if + } //end for + //free all the windings + FreeBrushWindings( brush ); +} //end of the function AAS_FixMapBrush +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +qboolean AAS_MakeBrushWindings( mapbrush_t *ob ) { + int i, j; + winding_t *w; + side_t *side; + plane_t *plane, *plane1, *plane2; + + ClearBounds( ob->mins, ob->maxs ); + + for ( i = 0; i < ob->numsides; i++ ) + { + plane = &mapplanes[ob->original_sides[i].planenum]; + w = BaseWindingForPlane( plane->normal, plane->dist ); + for ( j = 0; j < ob->numsides && w; j++ ) + { + if ( i == j ) { + continue; + } + if ( ob->original_sides[j].flags & SFL_BEVEL ) { + continue; + } + plane = &mapplanes[ob->original_sides[j].planenum ^ 1]; + ChopWindingInPlace( &w, plane->normal, plane->dist, 0 ); //CLIP_EPSILON); + } + + side = &ob->original_sides[i]; + side->winding = w; + if ( w ) { + side->flags |= SFL_VISIBLE; + for ( j = 0; j < w->numpoints; j++ ) + AddPointToBounds( w->p[j], ob->mins, ob->maxs ); + } + } + //check if the brush is convex + for ( i = 0; i < ob->numsides; i++ ) + { + for ( j = 0; j < ob->numsides; j++ ) + { + if ( i == j ) { + continue; + } + plane1 = &mapplanes[ob->original_sides[i].planenum]; + plane2 = &mapplanes[ob->original_sides[j].planenum]; + if ( WindingsNonConvex( ob->original_sides[i].winding, + ob->original_sides[j].winding, + plane1->normal, plane2->normal, + plane1->dist, plane2->dist ) ) { + Log_Print( "non convex brush" ); + } //end if + } //end for + } //end for + //check for out of bound brushes + for ( i = 0; i < 3; i++ ) + { + //IDBUG: all the indexes into the mins and maxs were zero (not using i) + if ( ob->mins[i] < -MAX_MAP_BOUNDS || ob->maxs[i] > MAX_MAP_BOUNDS ) { + Log_Print( "entity %i, brush %i: bounds out of range\n", ob->entitynum, ob->brushnum ); + Log_Print( "ob->mins[%d] = %f, ob->maxs[%d] = %f\n", i, ob->mins[i], i, ob->maxs[i] ); + ob->numsides = 0; //remove the brush + break; + } //end if + if ( ob->mins[i] > MAX_MAP_BOUNDS || ob->maxs[i] < -MAX_MAP_BOUNDS ) { + Log_Print( "entity %i, brush %i: no visible sides on brush\n", ob->entitynum, ob->brushnum ); + Log_Print( "ob->mins[%d] = %f, ob->maxs[%d] = %f\n", i, ob->mins[i], i, ob->maxs[i] ); + ob->numsides = 0; //remove the brush + break; + } //end if + } //end for + return true; +} //end of the function AAS_MakeBrushWindings +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +mapbrush_t *AAS_CopyMapBrush( mapbrush_t *brush, entity_t *mapent ) { + int n; + mapbrush_t *newbrush; + side_t *side, *newside; + + if ( nummapbrushes >= MAX_MAPFILE_BRUSHES ) { + Error( "MAX_MAPFILE_BRUSHES" ); + } + + newbrush = &mapbrushes[nummapbrushes]; + newbrush->original_sides = &brushsides[nummapbrushsides]; + newbrush->entitynum = brush->entitynum; + newbrush->brushnum = nummapbrushes - mapent->firstbrush; + newbrush->numsides = brush->numsides; + newbrush->contents = brush->contents; + + //copy the sides + for ( n = 0; n < brush->numsides; n++ ) + { + if ( nummapbrushsides >= MAX_MAPFILE_BRUSHSIDES ) { + Error( "MAX_MAPFILE_BRUSHSIDES" ); + } + side = brush->original_sides + n; + + newside = newbrush->original_sides + n; + newside->original = NULL; + newside->winding = NULL; + newside->contents = side->contents; + newside->flags = side->flags; + newside->surf = side->surf; + newside->planenum = side->planenum; + newside->texinfo = side->texinfo; + nummapbrushsides++; + } //end for + // + nummapbrushes++; + mapent->numbrushes++; + return newbrush; +} //end of the function AAS_CopyMapBrush +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_AlwaysTriggered( char *targetname ) { + int i; + + if ( !strlen( targetname ) ) { + return false; + } + // + for ( i = 0; i < num_entities; i++ ) + { + //if the entity will activate the given targetname + if ( !strcmp( targetname, ValueForKey( &entities[i], "target" ) ) ) { + //if this activator is present in deathmatch + if ( !( atoi( ValueForKey( &entities[i], "spawnflags" ) ) & SPAWNFLAG_NOT_DEATHMATCH ) ) { + //if it is a trigger_always entity + if ( !strcmp( "trigger_always", ValueForKey( &entities[i], "classname" ) ) ) { + return true; + } //end if + //check for possible trigger_always entities activating this entity + if ( AAS_AlwaysTriggered( ValueForKey( &entities[i], "targetname" ) ) ) { + return true; + } //end if + } //end if + } //end if + } //end for + return false; +} //end of the function AAS_AlwaysTriggered +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_ValidEntity( entity_t *mapent ) { + int i; + char target[1024]; + + //all world brushes are used for AAS + if ( mapent == &entities[0] ) { + return true; + } //end if + //some of the func_wall brushes are also used for AAS + else if ( !strcmp( "func_wall", ValueForKey( mapent, "classname" ) ) ) { + //Log_Print("found func_wall entity %d\n", mapent - entities); + //if the func wall is used in deathmatch + //if (!(atoi(ValueForKey(mapent, "spawnflags")) & SPAWNFLAG_NOT_DEATHMATCH)) + { + //Log_Print("func_wall USED in deathmatch mode %d\n", atoi(ValueForKey(mapent, "spawnflags"))); + return true; + } //end if + } //end else if + else if ( !strcmp( "func_door_rotating", ValueForKey( mapent, "classname" ) ) || + !strcmp( "func_door", ValueForKey( mapent, "classname" ) ) || + !strcmp( "func_invisible_user", ValueForKey( mapent, "classname" ) ) ) { + //if the func_door_rotating is present in deathmatch + //if (!(atoi(ValueForKey(mapent, "spawnflags")) & SPAWNFLAG_NOT_DEATHMATCH)) + { + //if the func_door_rotating is always activated in deathmatch + if ( AAS_AlwaysTriggered( ValueForKey( mapent, "targetname" ) ) ) { + //Log_Print("found func_door_rotating in deathmatch\ntargetname %s\n", ValueForKey(mapent, "targetname")); + return true; + } //end if + } //end if + } //end else if + else if ( !strcmp( "trigger_hurt", ValueForKey( mapent, "classname" ) ) ) { + // RF, spawnflag & 1 is for delayed spawn, so ignore it + if ( atoi( ValueForKey( mapent, "spawnflags" ) ) & 1 ) { + return false; + } + + //"dmg" is the damage, for instance: "dmg" "666" + return true; + } //end else if + else if ( !strcmp( "trigger_push", ValueForKey( mapent, "classname" ) ) ) { + return true; + } //end else if + else if ( !strcmp( "trigger_multiple", ValueForKey( mapent, "classname" ) ) ) { + //find out if the trigger_multiple is pointing to a target_teleporter + strcpy( target, ValueForKey( mapent, "target" ) ); + for ( i = 0; i < num_entities; i++ ) + { + //if the entity will activate the given targetname + if ( !strcmp( target, ValueForKey( &entities[i], "targetname" ) ) ) { + if ( !strcmp( "target_teleporter", ValueForKey( &entities[i], "classname" ) ) ) { + return true; + } //end if + } //end if + } //end for + } //end else if + else if ( !strcmp( "trigger_teleport", ValueForKey( mapent, "classname" ) ) ) { + return true; + } //end else if + else if ( !strcmp( "func_tramcar", ValueForKey( mapent, "classname" ) ) ) { + return true; + } //end else if + else if ( !strcmp( "func_invisible_user", ValueForKey( mapent, "classname" ) ) ) { + return true; + } + /* + else if (!strcmp("func_static", ValueForKey(mapent, "classname"))) + { + //FIXME: easy/medium/hard/deathmatch specific? + return true; + } //end else if + */ + return false; +} //end of the function AAS_ValidEntity +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_TransformPlane( int planenum, vec3_t origin, vec3_t angles ) { + float newdist, matrix[3][3]; + vec3_t normal; + + //rotate the node plane + VectorCopy( mapplanes[planenum].normal, normal ); + CreateRotationMatrix( angles, matrix ); + RotatePoint( normal, matrix ); + newdist = mapplanes[planenum].dist + DotProduct( normal, origin ); + return FindFloatPlane( normal, newdist ); +} //end of the function AAS_TransformPlane +//=========================================================================== +// this function sets the func_rotating_door in it's final position +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_PositionFuncRotatingBrush( entity_t *mapent, mapbrush_t *brush ) { + int spawnflags, i; + float distance; + vec3_t movedir, angles, pos1, pos2; + side_t *s; + + spawnflags = FloatForKey( mapent, "spawnflags" ); + VectorClear( movedir ); + if ( spawnflags & DOOR_X_AXIS ) { + movedir[2] = 1.0; //roll + } else if ( spawnflags & DOOR_Y_AXIS ) { + movedir[0] = 1.0; //pitch + } else { // Z_AXIS + movedir[1] = 1.0; //yaw + + } + // check for reverse rotation + if ( spawnflags & DOOR_REVERSE ) { + VectorInverse( movedir ); + } + + distance = FloatForKey( mapent, "distance" ); + if ( !distance ) { + distance = 90; + } + + GetVectorForKey( mapent, "angles", angles ); + VectorCopy( angles, pos1 ); + VectorMA( angles, -distance, movedir, pos2 ); + // if it starts open, switch the positions + if ( spawnflags & DOOR_START_OPEN ) { + VectorCopy( pos2, angles ); + VectorCopy( pos1, pos2 ); + VectorCopy( angles, pos1 ); + VectorInverse( movedir ); + } //end if + // + for ( i = 0; i < brush->numsides; i++ ) + { + s = &brush->original_sides[i]; + s->planenum = AAS_TransformPlane( s->planenum, mapent->origin, pos2 ); + } //end for + // + FreeBrushWindings( brush ); + AAS_MakeBrushWindings( brush ); + AddBrushBevels( brush ); + FreeBrushWindings( brush ); +} //end of the function AAS_PositionFuncRotatingBrush +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_PositionBrush( entity_t *mapent, mapbrush_t *brush ) { + side_t *s; + float newdist; + int i; + char *model; + + if ( !strcmp( ValueForKey( mapent, "classname" ), "func_door_rotating" ) ) { + AAS_PositionFuncRotatingBrush( mapent, brush ); + } //end if + else + { + if ( mapent->origin[0] || mapent->origin[1] || mapent->origin[2] ) { + for ( i = 0; i < brush->numsides; i++ ) + { + s = &brush->original_sides[i]; + newdist = mapplanes[s->planenum].dist + + DotProduct( mapplanes[s->planenum].normal, mapent->origin ); + s->planenum = FindFloatPlane( mapplanes[s->planenum].normal, newdist ); + } //end for + } //end if + // RF, disabled for Wolf, we dont use trigger_hurt for lava + //if it's a trigger hurt + //if (!strcmp("trigger_hurt", ValueForKey(mapent, "classname"))) + //{ + // //set the lava contents + // brush->contents |= CONTENTS_LAVA; + // //Log_Print("found trigger_hurt brush\n"); + //} //end if + // + else if ( !strcmp( "trigger_push", ValueForKey( mapent, "classname" ) ) ) { + //set the jumppad contents + brush->contents = CONTENTS_JUMPPAD; + //Log_Print("found trigger_push brush\n"); + } //end if + // + else if ( !strcmp( "trigger_multiple", ValueForKey( mapent, "classname" ) ) ) { + //set teleporter contents + brush->contents = CONTENTS_TELEPORTER; + //Log_Print("found trigger_multiple teleporter brush\n"); + } //end if + // + else if ( !strcmp( "trigger_teleport", ValueForKey( mapent, "classname" ) ) ) { + //set teleporter contents + brush->contents = CONTENTS_TELEPORTER; + //Log_Print("found trigger_teleport teleporter brush\n"); + } //end if + else if ( !strcmp( "func_door", ValueForKey( mapent, "classname" ) ) ) { + //set mover contents + brush->contents = CONTENTS_MOVER; + //get the model number + model = ValueForKey( mapent, "model" ); + brush->modelnum = atoi( model + 1 ); + } //end if + else if ( !strcmp( "func_invisible_user", ValueForKey( mapent, "classname" ) ) ) { + //set mover contents + brush->contents = CONTENTS_TRIGGER; + } //end if + + } //end else +} //end of the function AAS_PositionBrush +//=========================================================================== +// uses the global cfg_t cfg +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_CreateMapBrushes( mapbrush_t *brush, entity_t *mapent, int addbevels ) { + int i; + //side_t *s; + mapbrush_t *bboxbrushes[16]; + + //if the brushes are not from an entity used for AAS + if ( !AAS_ValidEntity( mapent ) ) { + nummapbrushsides -= brush->numsides; + brush->numsides = 0; + return; + } //end if + // + AAS_PositionBrush( mapent, brush ); + //from all normal solid brushes only the textured brush sides will + //be used as bsp splitters, so set the right texinfo reference here + AAS_SetTexinfo( brush ); + //remove contents detail flag, otherwise player clip contents won't be + //bsped correctly for AAS! + brush->contents &= ~CONTENTS_DETAIL; + //if the brush has contents area portal it should be the only contents + if ( brush->contents & ( CONTENTS_AREAPORTAL | CONTENTS_CLUSTERPORTAL ) ) { + brush->contents = CONTENTS_CLUSTERPORTAL; + brush->leafnum = -1; + } //end if + //window and playerclip are used for player clipping, make them solid + if ( brush->contents & ( CONTENTS_WINDOW | CONTENTS_PLAYERCLIP ) ) { + // + brush->contents &= ~( CONTENTS_WINDOW | CONTENTS_PLAYERCLIP ); + brush->contents |= CONTENTS_SOLID; + brush->leafnum = -1; + } //end if + // +// Rafael TBD: no flag to support CONTENTS_BOTCLIP +/* + if (brush->contents & CONTENTS_BOTCLIP) + { + brush->contents = CONTENTS_SOLID; + brush->leafnum = -1; + } // end if +*/ + // + //Log_Write("brush %d contents = ", brush->brushnum); + //PrintContents(brush->contents); + //Log_Write("\r\n"); + //if not one of the following brushes then the brush is NOT used for AAS + if ( !( brush->contents & ( CONTENTS_SOLID + | CONTENTS_LADDER + | CONTENTS_CLUSTERPORTAL + | CONTENTS_DONOTENTER + | CONTENTS_DONOTENTER_LARGE + | CONTENTS_TELEPORTER + | CONTENTS_JUMPPAD + | CONTENTS_WATER + | CONTENTS_LAVA + | CONTENTS_SLIME + | CONTENTS_MOVER + ) ) ) { + nummapbrushsides -= brush->numsides; + brush->numsides = 0; + return; + } //end if + //fix the map brush + //AAS_FixMapBrush(brush); + //if brush bevels should be added (for real map brushes, not bsp map brushes) + if ( addbevels ) { + //NOTE: we first have to get the mins and maxs of the brush before + // creating the brush bevels... the mins and maxs are used to + // create them. so we call MakeBrushWindings to get the mins + // and maxs and then after creating the bevels we free the + // windings because they are created for all sides (including + // bevels) a little later + AAS_MakeBrushWindings( brush ); + AddBrushBevels( brush ); + FreeBrushWindings( brush ); + } //end if + //NOTE: add the brush to the WORLD entity!!! + mapent = &entities[0]; + //there's at least one new brush for now + nummapbrushes++; + mapent->numbrushes++; + //liquid brushes are expanded for the maximum possible bounding box + if ( brush->contents & ( CONTENTS_WATER + | CONTENTS_LAVA + | CONTENTS_SLIME + | CONTENTS_TELEPORTER + | CONTENTS_JUMPPAD + | CONTENTS_DONOTENTER + | CONTENTS_DONOTENTER_LARGE + | CONTENTS_MOVER + ) ) { + brush->expansionbbox = 0; + //NOTE: the first bounding box is the max + //FIXME: use max bounding box created from all bboxes + AAS_ExpandMapBrush( brush, cfg.bboxes[0].mins, cfg.bboxes[0].maxs ); + AAS_MakeBrushWindings( brush ); + } //end if + //area portal brushes are NOT expanded + else if ( brush->contents & CONTENTS_CLUSTERPORTAL ) { + brush->expansionbbox = 0; + //NOTE: the first bounding box is the max + //FIXME: use max bounding box created from all bboxes + AAS_ExpandMapBrush( brush, cfg.bboxes[0].mins, cfg.bboxes[0].maxs ); + AAS_MakeBrushWindings( brush ); + } //end if + //all solid brushes are expanded for all bounding boxes + else if ( brush->contents & ( CONTENTS_SOLID + | CONTENTS_LADDER + ) ) { + //brush for the first bounding box + bboxbrushes[0] = brush; + //make a copy for the other bounding boxes + for ( i = 1; i < cfg.numbboxes; i++ ) + { + bboxbrushes[i] = AAS_CopyMapBrush( brush, mapent ); + } //end for + //expand every brush for it's bounding box and create windings + for ( i = 0; i < cfg.numbboxes; i++ ) + { + AAS_ExpandMapBrush( bboxbrushes[i], cfg.bboxes[i].mins, cfg.bboxes[i].maxs ); + bboxbrushes[i]->expansionbbox = cfg.bboxes[i].presencetype; + AAS_MakeBrushWindings( bboxbrushes[i] ); + } //end for + } //end else +} //end of the function AAS_CreateMapBrushes diff --git a/Projects/Android/jni/rtcw/src/bspc/aas_map.h b/Projects/Android/jni/rtcw/src/bspc/aas_map.h new file mode 100644 index 0000000..d41611e --- /dev/null +++ b/Projects/Android/jni/rtcw/src/bspc/aas_map.h @@ -0,0 +1,38 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +//=========================================================================== +// +// Name: aas_map.h +// Function: +// Programmer: Mr Elusive (MrElusive@demigod.demon.nl) +// Last update: 1997-12-04 +// Tab Size: 3 +//=========================================================================== + +void AAS_CreateMapBrushes( mapbrush_t *brush, entity_t *mapent, int addbevels ); diff --git a/Projects/Android/jni/rtcw/src/bspc/aas_prunenodes.c b/Projects/Android/jni/rtcw/src/bspc/aas_prunenodes.c new file mode 100644 index 0000000..1dc6e38 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/bspc/aas_prunenodes.c @@ -0,0 +1,103 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +//=========================================================================== +// +// Name: aas_prunenodes.c +// Function: Prune Nodes +// Programmer: Mr Elusive (MrElusive@demigod.demon.nl) +// Last update: 1997-12-04 +// Tab Size: 3 +//=========================================================================== + +#include "qbsp.h" +#include "../botlib/aasfile.h" +#include "aas_create.h" + +int c_numprunes; + +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +tmp_node_t *AAS_PruneNodes_r( tmp_node_t *tmpnode ) { + tmp_area_t *tmparea1, *tmparea2; + + //if it is a solid leaf + if ( !tmpnode ) { + return NULL; + } + // + if ( tmpnode->tmparea ) { + return tmpnode; + } + //process the children first + tmpnode->children[0] = AAS_PruneNodes_r( tmpnode->children[0] ); + tmpnode->children[1] = AAS_PruneNodes_r( tmpnode->children[1] ); + //if both children are areas + if ( tmpnode->children[0] && tmpnode->children[1] && + tmpnode->children[0]->tmparea && tmpnode->children[1]->tmparea ) { + tmparea1 = tmpnode->children[0]->tmparea; + while ( tmparea1->mergedarea ) tmparea1 = tmparea1->mergedarea; + + tmparea2 = tmpnode->children[1]->tmparea; + while ( tmparea2->mergedarea ) tmparea2 = tmparea2->mergedarea; + + if ( tmparea1 == tmparea2 ) { + c_numprunes++; + tmpnode->tmparea = tmparea1; + tmpnode->planenum = 0; + AAS_FreeTmpNode( tmpnode->children[0] ); + AAS_FreeTmpNode( tmpnode->children[1] ); + tmpnode->children[0] = NULL; + tmpnode->children[1] = NULL; + return tmpnode; + } //end if + } //end if + //if both solid leafs + if ( !tmpnode->children[0] && !tmpnode->children[1] ) { + c_numprunes++; + AAS_FreeTmpNode( tmpnode ); + return NULL; + } //end if + // + return tmpnode; +} //end of the function AAS_PruneNodes_r +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_PruneNodes( void ) { + Log_Write( "AAS_PruneNodes\r\n" ); + AAS_PruneNodes_r( tmpaasworld.nodes ); + Log_Print( "%6d nodes pruned\r\n", c_numprunes ); +} //end of the function AAS_PruneNodes diff --git a/Projects/Android/jni/rtcw/src/bspc/aas_prunenodes.h b/Projects/Android/jni/rtcw/src/bspc/aas_prunenodes.h new file mode 100644 index 0000000..cacc59c --- /dev/null +++ b/Projects/Android/jni/rtcw/src/bspc/aas_prunenodes.h @@ -0,0 +1,39 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +//=========================================================================== +// +// Name: aas_prunenodes.h +// Function: Prune Nodes +// Programmer: Mr Elusive (MrElusive@demigod.demon.nl) +// Last update: 1997-12-04 +// Tab Size: 3 +//=========================================================================== + +void AAS_PruneNodes( void ); + diff --git a/Projects/Android/jni/rtcw/src/bspc/aas_store.c b/Projects/Android/jni/rtcw/src/bspc/aas_store.c new file mode 100644 index 0000000..70ffc4f --- /dev/null +++ b/Projects/Android/jni/rtcw/src/bspc/aas_store.c @@ -0,0 +1,1124 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +//=========================================================================== +// +// Name: aas_store.c +// Function: +// Programmer: Mr Elusive (MrElusive@demigod.demon.nl) +// Last update: 1997-12-04 +// Tab Size: 3 +//=========================================================================== + +#include "qbsp.h" +#include "../botlib/aasfile.h" +#include "aas_file.h" +#include "aas_store.h" +#include "aas_create.h" +#include "aas_cfg.h" + + +//#define NOTHREEVERTEXFACES + +#define STOREPLANESDOUBLE + +#define VERTEX_EPSILON 0.1 //NOTE: changed from 0.5 + +// MrE: use same epsilons as q3map! + +//NOTE: changed from 0.0001 +#define NORMAL_EPSILON 0.00001 +//NOTE: changed from 0.05 +#define DIST_EPSILON 0.01 + +#define INTEGRAL_EPSILON 0.01 +#define VEREX_EPSILON 0.1 //NOTE: changed from 0.5 +#define VERTEX_HASHING +#define VERTEX_HASH_SHIFT 7 +#define VERTEX_HASH_SIZE ( ( MAX_MAP_BOUNDS >> ( VERTEX_HASH_SHIFT - 1 ) ) + 1 ) //was 64 +// +#define PLANE_HASHING +#define PLANE_HASH_SIZE 1024 //must be power of 2 +// +#define EDGE_HASHING +#define EDGE_HASH_SIZE 1024 //must be power of 2 + +// Ridah +aas_t aasworlds[1]; +aas_t( *aasworld ); +// done. + +//vertex hash +int *aas_vertexchain; // the next vertex in a hash chain +int aas_hashverts[VERTEX_HASH_SIZE * VERTEX_HASH_SIZE]; // a vertex number, or 0 for no verts +//plane hash +int *aas_planechain; +int aas_hashplanes[PLANE_HASH_SIZE]; +//edge hash +int *aas_edgechain; +int aas_hashedges[EDGE_HASH_SIZE]; + +int allocatedaasmem = 0; + +int groundfacesonly = false; //true; +// +typedef struct max_aas_s +{ + int max_bboxes; + int max_vertexes; + int max_planes; + int max_edges; + int max_edgeindexsize; + int max_faces; + int max_faceindexsize; + int max_areas; + int max_areasettings; + int max_reachabilitysize; + int max_nodes; + int max_portals; + int max_portalindexsize; + int max_clusters; +} max_aas_t; +//maximums of everything +max_aas_t max_aas; + +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_CountTmpNodes( tmp_node_t *tmpnode ) { + if ( !tmpnode ) { + return 0; + } + return AAS_CountTmpNodes( tmpnode->children[0] ) + + AAS_CountTmpNodes( tmpnode->children[1] ) + 1; +} //end of the function AAS_CountTmpNodes +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_InitMaxAAS( void ) { + int numfaces, numpoints, numareas; + tmp_face_t *f; + tmp_area_t *a; + + numpoints = 0; + numfaces = 0; + for ( f = tmpaasworld.faces; f; f = f->l_next ) + { + numfaces++; + if ( f->winding ) { + numpoints += f->winding->numpoints; + } + } //end for + // + numareas = 0; + for ( a = tmpaasworld.areas; a; a = a->l_next ) + { + numareas++; + } //end for + max_aas.max_bboxes = AAS_MAX_BBOXES; + max_aas.max_vertexes = numpoints + 1; + max_aas.max_planes = nummapplanes; + max_aas.max_edges = numpoints + 1; + max_aas.max_edgeindexsize = ( numpoints + 1 ) * 3; + max_aas.max_faces = numfaces + 10; + max_aas.max_faceindexsize = ( numfaces + 10 ) * 2; + max_aas.max_areas = numareas + 10; + max_aas.max_areasettings = numareas + 10; + max_aas.max_reachabilitysize = 0; + max_aas.max_nodes = AAS_CountTmpNodes( tmpaasworld.nodes ) + 10; + max_aas.max_portals = 0; + max_aas.max_portalindexsize = 0; + max_aas.max_clusters = 0; +} //end of the function AAS_InitMaxAAS +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_AllocMaxAAS( void ) { + int i; + + AAS_InitMaxAAS(); + //bounding boxes + ( *aasworld ).numbboxes = 0; + ( *aasworld ).bboxes = (aas_bbox_t *) GetClearedMemory( max_aas.max_bboxes * sizeof( aas_bbox_t ) ); + allocatedaasmem += max_aas.max_bboxes * sizeof( aas_bbox_t ); + //vertexes + ( *aasworld ).numvertexes = 0; + ( *aasworld ).vertexes = (aas_vertex_t *) GetClearedMemory( max_aas.max_vertexes * sizeof( aas_vertex_t ) ); + allocatedaasmem += max_aas.max_vertexes * sizeof( aas_vertex_t ); + //planes + ( *aasworld ).numplanes = 0; + ( *aasworld ).planes = (aas_plane_t *) GetClearedMemory( max_aas.max_planes * sizeof( aas_plane_t ) ); + allocatedaasmem += max_aas.max_planes * sizeof( aas_plane_t ); + //edges + ( *aasworld ).numedges = 0; + ( *aasworld ).edges = (aas_edge_t *) GetClearedMemory( max_aas.max_edges * sizeof( aas_edge_t ) ); + allocatedaasmem += max_aas.max_edges * sizeof( aas_edge_t ); + //edge index + ( *aasworld ).edgeindexsize = 0; + ( *aasworld ).edgeindex = (aas_edgeindex_t *) GetClearedMemory( max_aas.max_edgeindexsize * sizeof( aas_edgeindex_t ) ); + allocatedaasmem += max_aas.max_edgeindexsize * sizeof( aas_edgeindex_t ); + //faces + ( *aasworld ).numfaces = 0; + ( *aasworld ).faces = (aas_face_t *) GetClearedMemory( max_aas.max_faces * sizeof( aas_face_t ) ); + allocatedaasmem += max_aas.max_faces * sizeof( aas_face_t ); + //face index + ( *aasworld ).faceindexsize = 0; + ( *aasworld ).faceindex = (aas_faceindex_t *) GetClearedMemory( max_aas.max_faceindexsize * sizeof( aas_faceindex_t ) ); + allocatedaasmem += max_aas.max_faceindexsize * sizeof( aas_faceindex_t ); + //convex areas + ( *aasworld ).numareas = 0; + ( *aasworld ).areas = (aas_area_t *) GetClearedMemory( max_aas.max_areas * sizeof( aas_area_t ) ); + allocatedaasmem += max_aas.max_areas * sizeof( aas_area_t ); + //convex area settings + ( *aasworld ).numareasettings = 0; + ( *aasworld ).areasettings = (aas_areasettings_t *) GetClearedMemory( max_aas.max_areasettings * sizeof( aas_areasettings_t ) ); + allocatedaasmem += max_aas.max_areasettings * sizeof( aas_areasettings_t ); + //reachablity list + ( *aasworld ).reachabilitysize = 0; + ( *aasworld ).reachability = (aas_reachability_t *) GetClearedMemory( max_aas.max_reachabilitysize * sizeof( aas_reachability_t ) ); + allocatedaasmem += max_aas.max_reachabilitysize * sizeof( aas_reachability_t ); + //nodes of the bsp tree + ( *aasworld ).numnodes = 0; + ( *aasworld ).nodes = (aas_node_t *) GetClearedMemory( max_aas.max_nodes * sizeof( aas_node_t ) ); + allocatedaasmem += max_aas.max_nodes * sizeof( aas_node_t ); + //cluster portals + ( *aasworld ).numportals = 0; + ( *aasworld ).portals = (aas_portal_t *) GetClearedMemory( max_aas.max_portals * sizeof( aas_portal_t ) ); + allocatedaasmem += max_aas.max_portals * sizeof( aas_portal_t ); + //cluster portal index + ( *aasworld ).portalindexsize = 0; + ( *aasworld ).portalindex = (aas_portalindex_t *) GetClearedMemory( max_aas.max_portalindexsize * sizeof( aas_portalindex_t ) ); + allocatedaasmem += max_aas.max_portalindexsize * sizeof( aas_portalindex_t ); + //cluster + ( *aasworld ).numclusters = 0; + ( *aasworld ).clusters = (aas_cluster_t *) GetClearedMemory( max_aas.max_clusters * sizeof( aas_cluster_t ) ); + allocatedaasmem += max_aas.max_clusters * sizeof( aas_cluster_t ); + // + Log_Print( "allocated " ); + PrintMemorySize( allocatedaasmem ); + Log_Print( " of AAS memory\n" ); + //reset the has stuff + aas_vertexchain = (int *) GetClearedMemory( max_aas.max_vertexes * sizeof( int ) ); + aas_planechain = (int *) GetClearedMemory( max_aas.max_planes * sizeof( int ) ); + aas_edgechain = (int *) GetClearedMemory( max_aas.max_edges * sizeof( int ) ); + // + for ( i = 0; i < max_aas.max_vertexes; i++ ) aas_vertexchain[i] = -1; + for ( i = 0; i < VERTEX_HASH_SIZE * VERTEX_HASH_SIZE; i++ ) aas_hashverts[i] = -1; + // + for ( i = 0; i < max_aas.max_planes; i++ ) aas_planechain[i] = -1; + for ( i = 0; i < PLANE_HASH_SIZE; i++ ) aas_hashplanes[i] = -1; + // + for ( i = 0; i < max_aas.max_edges; i++ ) aas_edgechain[i] = -1; + for ( i = 0; i < EDGE_HASH_SIZE; i++ ) aas_hashedges[i] = -1; +} //end of the function AAS_AllocMaxAAS +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_FreeMaxAAS( void ) { + //bounding boxes + if ( ( *aasworld ).bboxes ) { + FreeMemory( ( *aasworld ).bboxes ); + } + ( *aasworld ).bboxes = NULL; + ( *aasworld ).numbboxes = 0; + //vertexes + if ( ( *aasworld ).vertexes ) { + FreeMemory( ( *aasworld ).vertexes ); + } + ( *aasworld ).vertexes = NULL; + ( *aasworld ).numvertexes = 0; + //planes + if ( ( *aasworld ).planes ) { + FreeMemory( ( *aasworld ).planes ); + } + ( *aasworld ).planes = NULL; + ( *aasworld ).numplanes = 0; + //edges + if ( ( *aasworld ).edges ) { + FreeMemory( ( *aasworld ).edges ); + } + ( *aasworld ).edges = NULL; + ( *aasworld ).numedges = 0; + //edge index + if ( ( *aasworld ).edgeindex ) { + FreeMemory( ( *aasworld ).edgeindex ); + } + ( *aasworld ).edgeindex = NULL; + ( *aasworld ).edgeindexsize = 0; + //faces + if ( ( *aasworld ).faces ) { + FreeMemory( ( *aasworld ).faces ); + } + ( *aasworld ).faces = NULL; + ( *aasworld ).numfaces = 0; + //face index + if ( ( *aasworld ).faceindex ) { + FreeMemory( ( *aasworld ).faceindex ); + } + ( *aasworld ).faceindex = NULL; + ( *aasworld ).faceindexsize = 0; + //convex areas + if ( ( *aasworld ).areas ) { + FreeMemory( ( *aasworld ).areas ); + } + ( *aasworld ).areas = NULL; + ( *aasworld ).numareas = 0; + //convex area settings + if ( ( *aasworld ).areasettings ) { + FreeMemory( ( *aasworld ).areasettings ); + } + ( *aasworld ).areasettings = NULL; + ( *aasworld ).numareasettings = 0; + //reachablity list + if ( ( *aasworld ).reachability ) { + FreeMemory( ( *aasworld ).reachability ); + } + ( *aasworld ).reachability = NULL; + ( *aasworld ).reachabilitysize = 0; + //nodes of the bsp tree + if ( ( *aasworld ).nodes ) { + FreeMemory( ( *aasworld ).nodes ); + } + ( *aasworld ).nodes = NULL; + ( *aasworld ).numnodes = 0; + //cluster portals + if ( ( *aasworld ).portals ) { + FreeMemory( ( *aasworld ).portals ); + } + ( *aasworld ).portals = NULL; + ( *aasworld ).numportals = 0; + //cluster portal index + if ( ( *aasworld ).portalindex ) { + FreeMemory( ( *aasworld ).portalindex ); + } + ( *aasworld ).portalindex = NULL; + ( *aasworld ).portalindexsize = 0; + //clusters + if ( ( *aasworld ).clusters ) { + FreeMemory( ( *aasworld ).clusters ); + } + ( *aasworld ).clusters = NULL; + ( *aasworld ).numclusters = 0; + + Log_Print( "freed " ); + PrintMemorySize( allocatedaasmem ); + Log_Print( " of AAS memory\n" ); + allocatedaasmem = 0; + // + if ( aas_vertexchain ) { + FreeMemory( aas_vertexchain ); + } + aas_vertexchain = NULL; + if ( aas_planechain ) { + FreeMemory( aas_planechain ); + } + aas_planechain = NULL; + if ( aas_edgechain ) { + FreeMemory( aas_edgechain ); + } + aas_edgechain = NULL; +} //end of the function AAS_FreeMaxAAS +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +unsigned AAS_HashVec( vec3_t vec ) { + int x, y; + + x = ( MAX_MAP_BOUNDS + (int)( vec[0] + 0.5 ) ) >> VERTEX_HASH_SHIFT; + y = ( MAX_MAP_BOUNDS + (int)( vec[1] + 0.5 ) ) >> VERTEX_HASH_SHIFT; + + if ( x < 0 || x >= VERTEX_HASH_SIZE || y < 0 || y >= VERTEX_HASH_SIZE ) { + Log_Print( "WARNING! HashVec: point %f %f %f outside valid range\n", vec[0], vec[1], vec[2] ); + Log_Print( "This should never happen!\n" ); + return -1; + } //end if + + return y * VERTEX_HASH_SIZE + x; +} //end of the function AAS_HashVec +//=========================================================================== +// returns true if the vertex was found in the list +// stores the vertex number in *vnum +// stores a new vertex if not stored already +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +qboolean AAS_GetVertex( vec3_t v, int *vnum ) { + int i; +#ifndef VERTEX_HASHING + float diff; +#endif //VERTEX_HASHING + +#ifdef VERTEX_HASHING + int h, vn; + vec3_t vert; + + for ( i = 0; i < 3; i++ ) + { + if ( fabs( v[i] - Q_rint( v[i] ) ) < INTEGRAL_EPSILON ) { + vert[i] = Q_rint( v[i] ); + } else { + vert[i] = v[i]; + } + } //end for + + h = AAS_HashVec( vert ); + //if the vertex was outside the valid range + if ( h == -1 ) { + *vnum = -1; + return true; + } //end if + + for ( vn = aas_hashverts[h]; vn >= 0; vn = aas_vertexchain[vn] ) + { + if ( fabs( ( *aasworld ).vertexes[vn][0] - vert[0] ) < VEREX_EPSILON + && fabs( ( *aasworld ).vertexes[vn][1] - vert[1] ) < VEREX_EPSILON + && fabs( ( *aasworld ).vertexes[vn][2] - vert[2] ) < VEREX_EPSILON ) { + *vnum = vn; + return true; + } //end if + } //end for +#else //VERTEX_HASHING + //check if the vertex is already stored + //stupid linear search + for ( i = 0; i < ( *aasworld ).numvertexes; i++ ) + { + diff = vert[0] - ( *aasworld ).vertexes[i][0]; + if ( diff < VERTEX_EPSILON && diff > -VERTEX_EPSILON ) { + diff = vert[1] - ( *aasworld ).vertexes[i][1]; + if ( diff < VERTEX_EPSILON && diff > -VERTEX_EPSILON ) { + diff = vert[2] - ( *aasworld ).vertexes[i][2]; + if ( diff < VERTEX_EPSILON && diff > -VERTEX_EPSILON ) { + *vnum = i; + return true; + } //end if + } //end if + } //end if + } //end for +#endif //VERTEX_HASHING + + if ( ( *aasworld ).numvertexes >= max_aas.max_vertexes ) { + Error( "AAS_MAX_VERTEXES = %d", max_aas.max_vertexes ); + } //end if + VectorCopy( vert, ( *aasworld ).vertexes[( *aasworld ).numvertexes] ); + *vnum = ( *aasworld ).numvertexes; + +#ifdef VERTEX_HASHING + aas_vertexchain[( *aasworld ).numvertexes] = aas_hashverts[h]; + aas_hashverts[h] = ( *aasworld ).numvertexes; +#endif //VERTEX_HASHING + + ( *aasworld ).numvertexes++; + return false; +} //end of the function AAS_GetVertex +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +unsigned AAS_HashEdge( int v1, int v2 ) { + int vnum1, vnum2; + // + if ( v1 < v2 ) { + vnum1 = v1; + vnum2 = v2; + } //end if + else + { + vnum1 = v2; + vnum2 = v1; + } //end else + return ( vnum1 + vnum2 ) & ( EDGE_HASH_SIZE - 1 ); +} //end of the function AAS_HashVec +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_AddEdgeToHash( int edgenum ) { + int hash; + aas_edge_t *edge; + + edge = &( *aasworld ).edges[edgenum]; + + hash = AAS_HashEdge( edge->v[0], edge->v[1] ); + + aas_edgechain[edgenum] = aas_hashedges[hash]; + aas_hashedges[hash] = edgenum; +} //end of the function AAS_AddEdgeToHash +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +qboolean AAS_FindHashedEdge( int v1num, int v2num, int *edgenum ) { + int e, hash; + aas_edge_t *edge; + + hash = AAS_HashEdge( v1num, v2num ); + for ( e = aas_hashedges[hash]; e >= 0; e = aas_edgechain[e] ) + { + edge = &( *aasworld ).edges[e]; + if ( edge->v[0] == v1num ) { + if ( edge->v[1] == v2num ) { + *edgenum = e; + return true; + } //end if + } //end if + else if ( edge->v[1] == v1num ) { + if ( edge->v[0] == v2num ) { + //negative for a reversed edge + *edgenum = -e; + return true; + } //end if + } //end else + } //end for + return false; +} //end of the function AAS_FindHashedPlane +//=========================================================================== +// returns true if the edge was found +// stores the edge number in *edgenum (negative if reversed edge) +// stores new edge if not stored already +// returns zero when the edge is degenerate +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +qboolean AAS_GetEdge( vec3_t v1, vec3_t v2, int *edgenum ) { + int v1num, v2num; + qboolean found; + + //the first edge is a dummy + if ( ( *aasworld ).numedges == 0 ) { + ( *aasworld ).numedges = 1; + } + + found = AAS_GetVertex( v1, &v1num ); + found &= AAS_GetVertex( v2, &v2num ); + //if one of the vertexes was outside the valid range + if ( v1num == -1 || v2num == -1 ) { + *edgenum = 0; + return true; + } //end if + //if both vertexes are the same or snapped onto each other + if ( v1num == v2num ) { + *edgenum = 0; + return true; + } //end if + //if both vertexes where already stored + if ( found ) { +#ifdef EDGE_HASHING + if ( AAS_FindHashedEdge( v1num, v2num, edgenum ) ) { + return true; + } +#else + int i; + for ( i = 1; i < ( *aasworld ).numedges; i++ ) + { + if ( ( *aasworld ).edges[i].v[0] == v1num ) { + if ( ( *aasworld ).edges[i].v[1] == v2num ) { + *edgenum = i; + return true; + } //end if + } //end if + else if ( ( *aasworld ).edges[i].v[1] == v1num ) { + if ( ( *aasworld ).edges[i].v[0] == v2num ) { + //negative for a reversed edge + *edgenum = -i; + return true; + } //end if + } //end else + } //end for +#endif //EDGE_HASHING + } //end if + if ( ( *aasworld ).numedges >= max_aas.max_edges ) { + Error( "AAS_MAX_EDGES = %d", max_aas.max_edges ); + } //end if + ( *aasworld ).edges[( *aasworld ).numedges].v[0] = v1num; + ( *aasworld ).edges[( *aasworld ).numedges].v[1] = v2num; + *edgenum = ( *aasworld ).numedges; +#ifdef EDGE_HASHING + AAS_AddEdgeToHash( *edgenum ); +#endif //EDGE_HASHING + ( *aasworld ).numedges++; + return false; +} //end of the function AAS_GetEdge +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_PlaneTypeForNormal( vec3_t normal ) { + vec_t ax, ay, az; + + //NOTE: epsilon used + if ( ( normal[0] >= 1.0 - NORMAL_EPSILON ) || + ( normal[0] <= -1.0 + NORMAL_EPSILON ) ) { + return PLANE_X; + } + if ( ( normal[1] >= 1.0 - NORMAL_EPSILON ) || + ( normal[1] <= -1.0 + NORMAL_EPSILON ) ) { + return PLANE_Y; + } + if ( ( normal[2] >= 1.0 - NORMAL_EPSILON ) || + ( normal[2] <= -1.0 + NORMAL_EPSILON ) ) { + return PLANE_Z; + } + + ax = fabs( normal[0] ); + ay = fabs( normal[1] ); + az = fabs( normal[2] ); + + if ( ax >= ay && ax >= az ) { + return PLANE_ANYX; + } + if ( ay >= ax && ay >= az ) { + return PLANE_ANYY; + } + return PLANE_ANYZ; +} //end of the function AAS_PlaneTypeForNormal +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_AddPlaneToHash( int planenum ) { + int hash; + aas_plane_t *plane; + + plane = &( *aasworld ).planes[planenum]; + + hash = (int)fabs( plane->dist ) / 8; + hash &= ( PLANE_HASH_SIZE - 1 ); + + aas_planechain[planenum] = aas_hashplanes[hash]; + aas_hashplanes[hash] = planenum; +} //end of the function AAS_AddPlaneToHash +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_PlaneEqual( vec3_t normal, float dist, int planenum ) { + float diff; + + diff = dist - ( *aasworld ).planes[planenum].dist; + if ( diff > -DIST_EPSILON && diff < DIST_EPSILON ) { + diff = normal[0] - ( *aasworld ).planes[planenum].normal[0]; + if ( diff > -NORMAL_EPSILON && diff < NORMAL_EPSILON ) { + diff = normal[1] - ( *aasworld ).planes[planenum].normal[1]; + if ( diff > -NORMAL_EPSILON && diff < NORMAL_EPSILON ) { + diff = normal[2] - ( *aasworld ).planes[planenum].normal[2]; + if ( diff > -NORMAL_EPSILON && diff < NORMAL_EPSILON ) { + return true; + } //end if + } //end if + } //end if + } //end if + return false; +} //end of the function AAS_PlaneEqual +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +qboolean AAS_FindPlane( vec3_t normal, float dist, int *planenum ) { + int i; + + for ( i = 0; i < ( *aasworld ).numplanes; i++ ) + { + if ( AAS_PlaneEqual( normal, dist, i ) ) { + *planenum = i; + return true; + } //end if + } //end for + return false; +} //end of the function AAS_FindPlane +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +qboolean AAS_FindHashedPlane( vec3_t normal, float dist, int *planenum ) { + int i, p; + aas_plane_t *plane; + int hash, h; + + hash = (int)fabs( dist ) / 8; + hash &= ( PLANE_HASH_SIZE - 1 ); + + //search the border bins as well + for ( i = -1; i <= 1; i++ ) + { + h = ( hash + i ) & ( PLANE_HASH_SIZE - 1 ); + for ( p = aas_hashplanes[h]; p >= 0; p = aas_planechain[p] ) + { + plane = &( *aasworld ).planes[p]; + if ( AAS_PlaneEqual( normal, dist, p ) ) { + *planenum = p; + return true; + } //end if + } //end for + } //end for + return false; +} //end of the function AAS_FindHashedPlane +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +qboolean AAS_GetPlane( vec3_t normal, vec_t dist, int *planenum ) { + aas_plane_t *plane, temp; + + //if (AAS_FindPlane(normal, dist, planenum)) return true; + if ( AAS_FindHashedPlane( normal, dist, planenum ) ) { + return true; + } + + if ( ( *aasworld ).numplanes >= max_aas.max_planes - 1 ) { + Error( "AAS_MAX_PLANES = %d", max_aas.max_planes ); + } //end if + +#ifdef STOREPLANESDOUBLE + plane = &( *aasworld ).planes[( *aasworld ).numplanes]; + VectorCopy( normal, plane->normal ); + plane->dist = dist; + plane->type = ( plane + 1 )->type = PlaneTypeForNormal( plane->normal ); + + VectorCopy( normal, ( plane + 1 )->normal ); + VectorNegate( ( plane + 1 )->normal, ( plane + 1 )->normal ); + ( plane + 1 )->dist = -dist; + + ( *aasworld ).numplanes += 2; + + //allways put axial planes facing positive first + if ( plane->type < 3 ) { + if ( plane->normal[0] < 0 || plane->normal[1] < 0 || plane->normal[2] < 0 ) { + // flip order + temp = *plane; + *plane = *( plane + 1 ); + *( plane + 1 ) = temp; + *planenum = ( *aasworld ).numplanes - 1; + return false; + } //end if + } //end if + *planenum = ( *aasworld ).numplanes - 2; + //add the planes to the hash + AAS_AddPlaneToHash( ( *aasworld ).numplanes - 1 ); + AAS_AddPlaneToHash( ( *aasworld ).numplanes - 2 ); + return false; +#else + plane = &( *aasworld ).planes[( *aasworld ).numplanes]; + VectorCopy( normal, plane->normal ); + plane->dist = dist; + plane->type = AAS_PlaneTypeForNormal( normal ); + + *planenum = ( *aasworld ).numplanes; + ( *aasworld ).numplanes++; + //add the plane to the hash + AAS_AddPlaneToHash( ( *aasworld ).numplanes - 1 ); + return false; +#endif //STOREPLANESDOUBLE +} //end of the function AAS_GetPlane +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +qboolean AAS_GetFace( winding_t *w, plane_t *p, int side, int *facenum ) { + int edgenum, i, j; + aas_face_t *face; + + //face zero is a dummy, because of the face index with negative numbers + if ( ( *aasworld ).numfaces == 0 ) { + ( *aasworld ).numfaces = 1; + } + + if ( ( *aasworld ).numfaces >= max_aas.max_faces ) { + Error( "AAS_MAX_FACES = %d", max_aas.max_faces ); + } //end if + face = &( *aasworld ).faces[( *aasworld ).numfaces]; + AAS_GetPlane( p->normal, p->dist, &face->planenum ); + face->faceflags = 0; + face->firstedge = ( *aasworld ).edgeindexsize; + face->frontarea = 0; + face->backarea = 0; + face->numedges = 0; + for ( i = 0; i < w->numpoints; i++ ) + { + if ( ( *aasworld ).edgeindexsize >= max_aas.max_edgeindexsize ) { + Error( "AAS_MAX_EDGEINDEXSIZE = %d", max_aas.max_edgeindexsize ); + } //end if + j = ( i + 1 ) % w->numpoints; + AAS_GetEdge( w->p[i], w->p[j], &edgenum ); + //if the edge wasn't degenerate + if ( edgenum ) { + ( *aasworld ).edgeindex[( *aasworld ).edgeindexsize++] = edgenum; + face->numedges++; + } //end if + else if ( verbose ) { + Log_Write( "AAS_GetFace: face %d had degenerate edge %d-%d\r\n", + ( *aasworld ).numfaces, i, j ); + } //end else + } //end for + if ( face->numedges < 1 +#ifdef NOTHREEVERTEXFACES + || face->numedges < 3 +#endif //NOTHREEVERTEXFACES + ) { + memset( &( *aasworld ).faces[( *aasworld ).numfaces], 0, sizeof( aas_face_t ) ); + Log_Write( "AAS_GetFace: face %d was tiny\r\n", ( *aasworld ).numfaces ); + return false; + } //end if + *facenum = ( *aasworld ).numfaces; + ( *aasworld ).numfaces++; + return true; +} //end of the function AAS_GetFace +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +/* +qboolean AAS_GetFace(winding_t *w, plane_t *p, int side, int *facenum) +{ + aas_edgeindex_t edges[1024]; + int planenum, numedges, i; + int j, edgenum; + qboolean foundplane, foundedges; + aas_face_t *face; + + //face zero is a dummy, because of the face index with negative numbers + if ((*aasworld).numfaces == 0) (*aasworld).numfaces = 1; + + foundplane = AAS_GetPlane(p->normal, p->dist, &planenum); + + foundedges = true; + numedges = w->numpoints; + for (i = 0; i < w->numpoints; i++) + { + if (i >= 1024) Error("AAS_GetFace: more than %d edges\n", 1024); + foundedges &= AAS_GetEdge(w->p[i], w->p[(i+1 >= w->numpoints ? 0 : i+1)], &edges[i]); + } //end for + + //FIXME: use portal number instead of a search + //if the plane and all edges already existed + if (foundplane && foundedges) + { + for (i = 0; i < (*aasworld).numfaces; i++) + { + face = &(*aasworld).faces[i]; + if (planenum == face->planenum) + { + if (numedges == face->numedges) + { + for (j = 0; j < numedges; j++) + { + edgenum = abs((*aasworld).edgeindex[face->firstedge + j]); + if (abs(edges[i]) != edgenum) break; + } //end for + if (j == numedges) + { + //jippy found the face + *facenum = -i; + return true; + } //end if + } //end if + } //end if + } //end for + } //end if + if ((*aasworld).numfaces >= max_aas.max_faces) + { + Error("AAS_MAX_FACES = %d", max_aas.max_faces); + } //end if + face = &(*aasworld).faces[(*aasworld).numfaces]; + face->planenum = planenum; + face->faceflags = 0; + face->numedges = numedges; + face->firstedge = (*aasworld).edgeindexsize; + face->frontarea = 0; + face->backarea = 0; + for (i = 0; i < numedges; i++) + { + if ((*aasworld).edgeindexsize >= max_aas.max_edgeindexsize) + { + Error("AAS_MAX_EDGEINDEXSIZE = %d", max_aas.max_edgeindexsize); + } //end if + (*aasworld).edgeindex[(*aasworld).edgeindexsize++] = edges[i]; + } //end for + *facenum = (*aasworld).numfaces; + (*aasworld).numfaces++; + return false; +} //end of the function AAS_GetFace*/ +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_StoreAreaSettings( tmp_areasettings_t *tmpareasettings ) { + aas_areasettings_t *areasettings; + + if ( ( *aasworld ).numareasettings == 0 ) { + ( *aasworld ).numareasettings = 1; + } + areasettings = &( *aasworld ).areasettings[( *aasworld ).numareasettings++]; + areasettings->areaflags = tmpareasettings->areaflags; + areasettings->presencetype = tmpareasettings->presencetype; + areasettings->contents = tmpareasettings->contents; + areasettings->groundsteepness = tmpareasettings->groundsteepness; // Ridah + if ( tmpareasettings->modelnum > AREACONTENTS_MAXMODELNUM ) { + Log_Print( "WARNING: more than %d mover models\n", AREACONTENTS_MAXMODELNUM ); + } + areasettings->contents |= ( tmpareasettings->modelnum & AREACONTENTS_MAXMODELNUM ) << AREACONTENTS_MODELNUMSHIFT; +} //end of the function AAS_StoreAreaSettings +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_StoreArea( tmp_area_t *tmparea ) { + int side, edgenum, i; + plane_t *plane; + tmp_face_t *tmpface; + aas_area_t *aasarea; + aas_edge_t *edge; + aas_face_t *aasface; + aas_faceindex_t aasfacenum; + vec3_t facecenter; + winding_t *w = NULL; // TTimo: init + + //when the area is merged go to the merged area + //FIXME: this isn't necessary anymore because the tree + // is refreshed after area merging + while ( tmparea->mergedarea ) tmparea = tmparea->mergedarea; + // + if ( tmparea->invalid ) { + Error( "AAS_StoreArea: tried to store invalid area" ); + } + //if there is an aas area already stored for this tmp area + if ( tmparea->aasareanum ) { + return -tmparea->aasareanum; + } + // + if ( ( *aasworld ).numareas >= max_aas.max_areas ) { + Error( "AAS_MAX_AREAS = %d", max_aas.max_areas ); + } //end if + //area zero is a dummy + if ( ( *aasworld ).numareas == 0 ) { + ( *aasworld ).numareas = 1; + } + //create an area from this leaf + aasarea = &( *aasworld ).areas[( *aasworld ).numareas]; + aasarea->areanum = ( *aasworld ).numareas; + aasarea->numfaces = 0; + aasarea->firstface = ( *aasworld ).faceindexsize; + ClearBounds( aasarea->mins, aasarea->maxs ); + VectorClear( aasarea->center ); + // +// Log_Write("tmparea %d became aasarea %d\r\n", tmparea->areanum, aasarea->areanum); + //store the aas area number at the tmp area + tmparea->aasareanum = aasarea->areanum; + // + for ( tmpface = tmparea->tmpfaces; tmpface; tmpface = tmpface->next[side] ) + { + side = tmpface->frontarea != tmparea; + //if there's an aas face created for the tmp face already + if ( tmpface->aasfacenum ) { + //we're at the back of the face so use a negative index + aasfacenum = -tmpface->aasfacenum; +#ifdef DEBUG + if ( tmpface->aasfacenum < 0 || tmpface->aasfacenum > max_aas.max_faces ) { + Error( "AAS_CreateTree_r: face number out of range" ); + } //end if +#endif //DEBUG + aasface = &( *aasworld ).faces[tmpface->aasfacenum]; + aasface->backarea = aasarea->areanum; + } //end if + else + { + plane = &mapplanes[tmpface->planenum ^ side]; + if ( side ) { + w = tmpface->winding; + tmpface->winding = ReverseWinding( tmpface->winding ); + } //end if + if ( !AAS_GetFace( tmpface->winding, plane, 0, &aasfacenum ) ) { + continue; + } + if ( side ) { + FreeWinding( tmpface->winding ); + tmpface->winding = w; + } //end if + aasface = &( *aasworld ).faces[aasfacenum]; + aasface->frontarea = aasarea->areanum; + aasface->backarea = 0; + aasface->faceflags = tmpface->faceflags; + //set the face number at the tmp face + tmpface->aasfacenum = aasfacenum; + } //end else + //add face points to the area bounds and + //calculate the face 'center' + VectorClear( facecenter ); + for ( edgenum = 0; edgenum < aasface->numedges; edgenum++ ) + { + edge = &( *aasworld ).edges[abs( ( *aasworld ).edgeindex[aasface->firstedge + edgenum] )]; + for ( i = 0; i < 2; i++ ) + { + AddPointToBounds( ( *aasworld ).vertexes[edge->v[i]], aasarea->mins, aasarea->maxs ); + VectorAdd( ( *aasworld ).vertexes[edge->v[i]], facecenter, facecenter ); + } //end for + } //end for + VectorScale( facecenter, 1.0 / ( aasface->numedges * 2.0 ), facecenter ); + //add the face 'center' to the area 'center' + VectorAdd( aasarea->center, facecenter, aasarea->center ); + // + if ( ( *aasworld ).faceindexsize >= max_aas.max_faceindexsize ) { + Error( "AAS_MAX_FACEINDEXSIZE = %d", max_aas.max_faceindexsize ); + } //end if + ( *aasworld ).faceindex[( *aasworld ).faceindexsize++] = aasfacenum; + aasarea->numfaces++; + } //end for + //if the area has no faces at all (return 0, = solid leaf) + if ( !aasarea->numfaces ) { + return 0; + } + // + VectorScale( aasarea->center, 1.0 / aasarea->numfaces, aasarea->center ); + //Log_Write("area %d center %f %f %f\r\n", (*aasworld).numareas, + // aasarea->center[0], aasarea->center[1], aasarea->center[2]); + //store the area settings + AAS_StoreAreaSettings( tmparea->settings ); + // + //Log_Write("tmp area %d became aas area %d\r\n", tmpareanum, aasarea->areanum); + qprintf( "\r%6d", aasarea->areanum ); + // + if ( ( *aasworld ).areasettings[aasarea->areanum].contents & AREACONTENTS_CLUSTERPORTAL ) { + static int num; + Log_Write( "***** area %d is a cluster portal %d\n", aasarea->areanum, num++ ); + } //end if + // + ( *aasworld ).numareas++; + return -( ( *aasworld ).numareas - 1 ); +} //end of the function AAS_StoreArea +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int AAS_StoreTree_r( tmp_node_t *tmpnode ) { + int aasnodenum; + plane_t *plane; + aas_node_t *aasnode; + + //if it is a solid leaf + if ( !tmpnode ) { + return 0; + } + //negative so it's an area + if ( tmpnode->tmparea ) { + return AAS_StoreArea( tmpnode->tmparea ); + } + //it's another node + //the first node is a dummy + if ( ( *aasworld ).numnodes == 0 ) { + ( *aasworld ).numnodes = 1; + } + if ( ( *aasworld ).numnodes >= max_aas.max_nodes ) { + Error( "AAS_MAX_NODES = %d", max_aas.max_nodes ); + } //end if + aasnodenum = ( *aasworld ).numnodes; + aasnode = &( *aasworld ).nodes[( *aasworld ).numnodes++]; + plane = &mapplanes[tmpnode->planenum]; + AAS_GetPlane( plane->normal, plane->dist, &aasnode->planenum ); + aasnode->children[0] = AAS_StoreTree_r( tmpnode->children[0] ); + aasnode->children[1] = AAS_StoreTree_r( tmpnode->children[1] ); + return aasnodenum; +} //end of the function AAS_StoreTree_r +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_StoreBoundingBoxes( void ) { + if ( cfg.numbboxes > max_aas.max_bboxes ) { + Error( "more than %d bounding boxes", max_aas.max_bboxes ); + } //end if + ( *aasworld ).numbboxes = cfg.numbboxes; + memcpy( ( *aasworld ).bboxes, cfg.bboxes, cfg.numbboxes * sizeof( aas_bbox_t ) ); +} //end of the function AAS_StoreBoundingBoxes +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_StoreFile( char *filename ) { + AAS_AllocMaxAAS(); + + Log_Write( "AAS_StoreFile\r\n" ); + // + AAS_StoreBoundingBoxes(); + // + qprintf( "%6d areas stored", 0 ); + //start with node 1 because node zero is a dummy + AAS_StoreTree_r( tmpaasworld.nodes ); + qprintf( "\n" ); + Log_Write( "%6d areas stored\r\n", ( *aasworld ).numareas ); + ( *aasworld ).loaded = true; +} //end of the function AAS_StoreFile diff --git a/Projects/Android/jni/rtcw/src/bspc/aas_store.h b/Projects/Android/jni/rtcw/src/bspc/aas_store.h new file mode 100644 index 0000000..5e0cae4 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/bspc/aas_store.h @@ -0,0 +1,126 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +//=========================================================================== +// +// Name: aas_store.h +// Function: +// Programmer: Mr Elusive (MrElusive@demigod.demon.nl) +// Last update: 1997-12-04 +// Tab Size: 3 +//=========================================================================== + +#define AAS_MAX_BBOXES 5 +#define AAS_MAX_VERTEXES 512000 +#define AAS_MAX_PLANES 65536 +#define AAS_MAX_EDGES 512000 +#define AAS_MAX_EDGEINDEXSIZE 512000 +#define AAS_MAX_FACES 512000 +#define AAS_MAX_FACEINDEXSIZE 512000 +#define AAS_MAX_AREAS 65536 +#define AAS_MAX_AREASETTINGS 65536 +#define AAS_MAX_REACHABILITYSIZE 65536 +#define AAS_MAX_NODES 256000 +#define AAS_MAX_PORTALS 65536 +#define AAS_MAX_PORTALINDEXSIZE 65536 +#define AAS_MAX_CLUSTERS 65536 + +#define BSPCINCLUDE +#include "../botlib/be_aas.h" +#include "../botlib/be_aas_def.h" + +/* +typedef struct bspc_aas_s +{ + int loaded; + int initialized; //true when AAS has been initialized + int savefile; //set true when file should be saved + //bounding boxes + int numbboxes; + aas_bbox_t *bboxes; + //vertexes + int numvertexes; + aas_vertex_t *vertexes; + //planes + int numplanes; + aas_plane_t *planes; + //edges + int numedges; + aas_edge_t *edges; + //edge index + int edgeindexsize; + aas_edgeindex_t *edgeindex; + //faces + int numfaces; + aas_face_t *faces; + //face index + int faceindexsize; + aas_faceindex_t *faceindex; + //convex areas + int numareas; + aas_area_t *areas; + //convex area settings + int numareasettings; + aas_areasettings_t *areasettings; + //reachablity list + int reachabilitysize; + aas_reachability_t *reachability; + //nodes of the bsp tree + int numnodes; + aas_node_t *nodes; + //cluster portals + int numportals; + aas_portal_t *portals; + //cluster portal index + int portalindexsize; + aas_portalindex_t *portalindex; + //clusters + int numclusters; + aas_cluster_t *clusters; + // + int numreachabilityareas; + float reachabilitytime; +} bspc_aas_t; + +extern bspc_aas_t aasworld; +// +*/ + +// Ridah +extern aas_t aasworlds[1]; +extern aas_t *aasworld; +// done. + +//stores the AAS file from the temporary AAS +void AAS_StoreFile( char *filename ); +//returns a number of the given plane +qboolean AAS_FindPlane( vec3_t normal, float dist, int *planenum ); +//allocates the maximum AAS memory for storage +void AAS_AllocMaxAAS( void ); +//frees the maximum AAS memory for storage +void AAS_FreeMaxAAS( void ); diff --git a/Projects/Android/jni/rtcw/src/bspc/be_aas_bspc.c b/Projects/Android/jni/rtcw/src/bspc/be_aas_bspc.c new file mode 100644 index 0000000..01567f5 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/bspc/be_aas_bspc.c @@ -0,0 +1,314 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +//=========================================================================== +// +// Name: b_aas_bspc.c +// Function: Area Awareness System +// Programmer: Mr Elusive (MrElusive@idsoftware.com) +// Last update: 1999-09-14 +// Tab Size: 3 +//=========================================================================== + +#include "../game/q_shared.h" +#include "../bspc/l_log.h" +#include "../bspc/l_qfiles.h" +#include "../botlib/l_memory.h" +#include "../botlib/l_script.h" +#include "../botlib/l_precomp.h" +#include "../botlib/l_struct.h" +#include "../botlib/aasfile.h" +#include "../botlib/botlib.h" +#include "../botlib/be_aas.h" +#include "../botlib/be_aas_def.h" +#include "../qcommon/cm_public.h" + +//#define BSPC + +extern botlib_import_t botimport; +extern qboolean capsule_collision; + +//#define AAS_MOVE_DEBUG + +botlib_import_t botimport; +clipHandle_t worldmodel; + +void Error( char *error, ... ); + +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_Error( char *fmt, ... ) { + va_list argptr; + char text[1024]; + + va_start( argptr, fmt ); + vsprintf( text, fmt, argptr ); + va_end( argptr ); + + Error( text ); +} //end of the function AAS_Error +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int Sys_MilliSeconds( void ) { + return clock() * 1000 / CLOCKS_PER_SEC; +} //end of the function Sys_MilliSeconds +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_DebugLine( vec3_t start, vec3_t end, int color ) { +} //end of the function AAS_DebugLine +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_ClearShownDebugLines( void ) { +} //end of the function AAS_ClearShownDebugLines +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +char *BotImport_BSPEntityData( void ) { + return CM_EntityString(); +} //end of the function AAS_GetEntityData +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void BotImport_Trace( bsp_trace_t *bsptrace, vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end, int passent, int contentmask ) { + trace_t result; + + CM_BoxTrace( &result, start, end, mins, maxs, worldmodel, contentmask, capsule_collision ); + + bsptrace->allsolid = result.allsolid; + bsptrace->contents = result.contents; + VectorCopy( result.endpos, bsptrace->endpos ); + bsptrace->ent = result.entityNum; + bsptrace->fraction = result.fraction; + bsptrace->exp_dist = 0; + bsptrace->plane.dist = result.plane.dist; + VectorCopy( result.plane.normal, bsptrace->plane.normal ); + bsptrace->plane.signbits = result.plane.signbits; + bsptrace->plane.type = result.plane.type; + bsptrace->sidenum = 0; + bsptrace->startsolid = result.startsolid; + bsptrace->surface.flags = result.surfaceFlags; +} //end of the function BotImport_Trace +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int BotImport_PointContents( vec3_t p ) { + return CM_PointContents( p, worldmodel ); +} //end of the function BotImport_PointContents +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void *BotImport_GetMemory( int size ) { + return GetMemory( size ); +} //end of the function BotImport_GetMemory +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void BotImport_Print( int type, char *fmt, ... ) { + va_list argptr; + char buf[1024]; + + va_start( argptr, fmt ); + vsprintf( buf, fmt, argptr ); + printf( buf ); + if ( buf[0] != '\r' ) { + Log_Write( buf ); + } + va_end( argptr ); +} //end of the function BotImport_Print +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void BotImport_BSPModelMinsMaxsOrigin( int modelnum, vec3_t angles, vec3_t outmins, vec3_t outmaxs, vec3_t origin ) { + clipHandle_t h; + vec3_t mins, maxs; + float max; + int i; + + h = CM_InlineModel( modelnum ); + CM_ModelBounds( h, mins, maxs ); + //if the model is rotated + if ( ( angles[0] || angles[1] || angles[2] ) ) { // expand for rotation + + max = RadiusFromBounds( mins, maxs ); + for ( i = 0; i < 3; i++ ) + { + mins[i] = ( mins[i] + maxs[i] ) * 0.5 - max; + maxs[i] = ( mins[i] + maxs[i] ) * 0.5 + max; + } //end for + } //end if + if ( outmins ) { + VectorCopy( mins, outmins ); + } + if ( outmaxs ) { + VectorCopy( maxs, outmaxs ); + } + if ( origin ) { + VectorClear( origin ); + } +} //end of the function BotImport_BSPModelMinsMaxsOrigin +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void Com_DPrintf( char *fmt, ... ) { + va_list argptr; + char buf[1024]; + + va_start( argptr, fmt ); + vsprintf( buf, fmt, argptr ); + printf( buf ); + if ( buf[0] != '\r' ) { + Log_Write( buf ); + } + va_end( argptr ); +} //end of the function Com_DPrintf +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int COM_Compress( char *data_p ) { + return strlen( data_p ); +} +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void Com_Memset( void* dest, const int val, const size_t count ) { + memset( dest, val, count ); +} +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void Com_Memcpy( void* dest, const void* src, const size_t count ) { + memcpy( dest, src, count ); +} +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_InitBotImport( void ) { + botimport.BSPEntityData = BotImport_BSPEntityData; + botimport.GetMemory = BotImport_GetMemory; + botimport.FreeMemory = FreeMemory; + botimport.Trace = BotImport_Trace; + botimport.PointContents = BotImport_PointContents; + botimport.Print = BotImport_Print; + botimport.BSPModelMinsMaxsOrigin = BotImport_BSPModelMinsMaxsOrigin; +} //end of the function AAS_InitBotImport +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== + +void AAS_CalcReachAndClusters( struct quakefile_s *qf ) { + float time; + + Log_Print( "loading collision map...\n" ); + // + if ( !qf->pakfile[0] ) { + strcpy( qf->pakfile, qf->filename ); + } + //load the map + CM_LoadMap( (char *) qf, qfalse, &( *aasworld ).bspchecksum ); + //get a handle to the world model + worldmodel = CM_InlineModel( 0 ); // 0 = world, 1 + are bmodels + //initialize bot import structure + AAS_InitBotImport(); + //load the BSP entity string + AAS_LoadBSPFile(); + //init physics settings + AAS_InitSettings(); + //initialize AAS link heap + AAS_InitAASLinkHeap(); + //initialize the AAS linked entities for the new map + AAS_InitAASLinkedEntities(); + //reset all reachabilities and clusters + ( *aasworld ).reachabilitysize = 0; + ( *aasworld ).numclusters = 0; + //set all view portals as cluster portals in case we re-calculate the reachabilities and clusters (with -reach) + AAS_SetViewPortalsAsClusterPortals(); + //calculate reachabilities + AAS_InitReachability(); + time = 0; + while ( AAS_ContinueInitReachability( time ) ) time++; + //calculate clusters + AAS_InitClustering(); +} //end of the function AAS_CalcReachAndClusters + +// Ridah +void AAS_SetWorldPointer( aas_t *newaasworld ) { + aasworld = newaasworld; +} +// done. diff --git a/Projects/Android/jni/rtcw/src/bspc/be_aas_bspc.h b/Projects/Android/jni/rtcw/src/bspc/be_aas_bspc.h new file mode 100644 index 0000000..a950474 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/bspc/be_aas_bspc.h @@ -0,0 +1,44 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +//=========================================================================== +// +// Name: b_aas_bspc.h +// Function: Area Awareness System +// Programmer: Mr Elusive (MrElusive@demigod.demon.nl) +// Last update: 1999-02-28 +// Tab Size: 3 +//=========================================================================== + +void AAS_CalcReachAndClusters( struct quakefile_s *qf ); + +// Ridah +void AAS_SetWorldPointer( aas_t *newaasworld ); +// done. + + diff --git a/Projects/Android/jni/rtcw/src/bspc/brushbsp.c b/Projects/Android/jni/rtcw/src/bspc/brushbsp.c new file mode 100644 index 0000000..b88bbe5 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/bspc/brushbsp.c @@ -0,0 +1,1924 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +//=========================================================================== +// +// Name: BrushBSP +// Function: Build a BSP tree from a set of brushes +// Programmer: id Software & Mr Elusive (MrElusive@demigod.demon.nl) +// Last update: 1997-12-04 +// Tab Size: 3 +//=========================================================================== + +#include "qbsp.h" +#include "l_mem.h" +#include "../botlib/aasfile.h" +#include "aas_store.h" +#include "aas_cfg.h" + +#include + +/* +each side has a count of the other sides it splits + +the best split will be the one that minimizes the total split counts +of all remaining sides + +precalc side on plane table + +evaluate split side +{ +cost = 0 +for all sides + for all sides + get + if side splits side and splitside is on same child + cost++; +} +*/ + +int c_nodes; +int c_nonvis; +int c_active_brushes; +int c_solidleafnodes; +int c_totalsides; +int c_brushmemory; +int c_peak_brushmemory; +int c_nodememory; +int c_peak_totalbspmemory; + +// if a brush just barely pokes onto the other side, +// let it slide by without chopping +#define PLANESIDE_EPSILON 0.001 +//0.1 + +//#ifdef DEBUG +typedef struct cname_s +{ + int value; + char *name; +} cname_t; + +cname_t contentnames[] = +{ + {CONTENTS_SOLID,"CONTENTS_SOLID"}, + {CONTENTS_WINDOW,"CONTENTS_WINDOW"}, + {CONTENTS_AUX,"CONTENTS_AUX"}, + {CONTENTS_LAVA,"CONTENTS_LAVA"}, + {CONTENTS_SLIME,"CONTENTS_SLIME"}, + {CONTENTS_WATER,"CONTENTS_WATER"}, + {CONTENTS_MIST,"CONTENTS_MIST"}, + {LAST_VISIBLE_CONTENTS,"LAST_VISIBLE_CONTENTS"}, + + {CONTENTS_AREAPORTAL,"CONTENTS_AREAPORTAL"}, + {CONTENTS_PLAYERCLIP,"CONTENTS_PLAYERCLIP"}, + {CONTENTS_MONSTERCLIP,"CONTENTS_MONSTERCLIP"}, + {CONTENTS_CURRENT_0,"CONTENTS_CURRENT_0"}, + {CONTENTS_CURRENT_90,"CONTENTS_CURRENT_90"}, + {CONTENTS_CURRENT_180,"CONTENTS_CURRENT_180"}, + {CONTENTS_CURRENT_270,"CONTENTS_CURRENT_270"}, + {CONTENTS_CURRENT_UP,"CONTENTS_CURRENT_UP"}, + {CONTENTS_CURRENT_DOWN,"CONTENTS_CURRENT_DOWN"}, + {CONTENTS_ORIGIN,"CONTENTS_ORIGIN"}, + {CONTENTS_MONSTER,"CONTENTS_MONSTER"}, + {CONTENTS_DEADMONSTER,"CONTENTS_DEADMONSTER"}, + {CONTENTS_DETAIL,"CONTENTS_DETAIL"}, + {CONTENTS_Q2TRANSLUCENT,"CONTENTS_TRANSLUCENT"}, + {CONTENTS_LADDER,"CONTENTS_LADDER"}, + {0, 0} +}; + +void PrintContents( int contents ) { + int i; + + for ( i = 0; contentnames[i].value; i++ ) + { + if ( contents & contentnames[i].value ) { + Log_Write( "%s,", contentnames[i].name ); + } //end if + } //end for +} //end of the function PrintContents + +//#endif DEBUG + +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void ResetBrushBSP( void ) { + c_nodes = 0; + c_nonvis = 0; + c_active_brushes = 0; + c_solidleafnodes = 0; + c_totalsides = 0; + c_brushmemory = 0; + c_peak_brushmemory = 0; + c_nodememory = 0; + c_peak_totalbspmemory = 0; +} //end of the function ResetBrushBSP +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void FindBrushInTree( node_t *node, int brushnum ) { + bspbrush_t *b; + + if ( node->planenum == PLANENUM_LEAF ) { + for ( b = node->brushlist ; b ; b = b->next ) + if ( b->original->brushnum == brushnum ) { + Log_Print( "here\n" ); + } + return; + } + FindBrushInTree( node->children[0], brushnum ); + FindBrushInTree( node->children[1], brushnum ); +} //end of the function FindBrushInTree +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void DrawBrushList( bspbrush_t *brush, node_t *node ) { + int i; + side_t *s; + + GLS_BeginScene(); + for ( ; brush ; brush = brush->next ) + { + for ( i = 0 ; i < brush->numsides ; i++ ) + { + s = &brush->sides[i]; + if ( !s->winding ) { + continue; + } + if ( s->texinfo == TEXINFO_NODE ) { + GLS_Winding( s->winding, 1 ); + } else if ( !( s->flags & SFL_VISIBLE ) ) { + GLS_Winding( s->winding, 2 ); + } else { + GLS_Winding( s->winding, 0 ); + } + } + } + GLS_EndScene(); +} //end of the function DrawBrushList +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void WriteBrushList( char *name, bspbrush_t *brush, qboolean onlyvis ) { + int i; + side_t *s; + FILE *f; + + qprintf( "writing %s\n", name ); + f = SafeOpenWrite( name ); + + for ( ; brush ; brush = brush->next ) + { + for ( i = 0 ; i < brush->numsides ; i++ ) + { + s = &brush->sides[i]; + if ( !s->winding ) { + continue; + } + if ( onlyvis && !( s->flags & SFL_VISIBLE ) ) { + continue; + } + OutputWinding( brush->sides[i].winding, f ); + } + } + + fclose( f ); +} //end of the function WriteBrushList +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void PrintBrush( bspbrush_t *brush ) { + int i; + + printf( "brush: %p\n", brush ); + for ( i = 0; i < brush->numsides ; i++ ) + { + pw( brush->sides[i].winding ); + printf( "\n" ); + } //end for +} //end of the function PrintBrush +//=========================================================================== +// Sets the mins/maxs based on the windings +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void BoundBrush( bspbrush_t *brush ) { + int i, j; + winding_t *w; + + ClearBounds( brush->mins, brush->maxs ); + for ( i = 0 ; i < brush->numsides ; i++ ) + { + w = brush->sides[i].winding; + if ( !w ) { + continue; + } + for ( j = 0 ; j < w->numpoints ; j++ ) + AddPointToBounds( w->p[j], brush->mins, brush->maxs ); + } +} //end of the function BoundBrush +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void CreateBrushWindings( bspbrush_t *brush ) { + int i, j; + winding_t *w; + side_t *side; + plane_t *plane; + + for ( i = 0 ; i < brush->numsides ; i++ ) + { + side = &brush->sides[i]; + plane = &mapplanes[side->planenum]; + w = BaseWindingForPlane( plane->normal, plane->dist ); + for ( j = 0 ; j < brush->numsides && w; j++ ) + { + if ( i == j ) { + continue; + } + if ( brush->sides[j].flags & SFL_BEVEL ) { + continue; + } + plane = &mapplanes[brush->sides[j].planenum ^ 1]; + ChopWindingInPlace( &w, plane->normal, plane->dist, 0 ); //CLIP_EPSILON); + } + + side->winding = w; + } + + BoundBrush( brush ); +} //end of the function CreateBrushWindings +//=========================================================================== +// Creates a new axial brush +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +bspbrush_t *BrushFromBounds( vec3_t mins, vec3_t maxs ) { + bspbrush_t *b; + int i; + vec3_t normal; + vec_t dist; + + b = AllocBrush( 6 ); + b->numsides = 6; + for ( i = 0 ; i < 3 ; i++ ) + { + VectorClear( normal ); + normal[i] = 1; + dist = maxs[i]; + b->sides[i].planenum = FindFloatPlane( normal, dist ); + + normal[i] = -1; + dist = -mins[i]; + b->sides[3 + i].planenum = FindFloatPlane( normal, dist ); + } + + CreateBrushWindings( b ); + + return b; +} //end of the function BrushFromBounds +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int BrushOutOfBounds( bspbrush_t *brush, vec3_t mins, vec3_t maxs, float epsilon ) { + int i, j, n; + winding_t *w; + side_t *side; + + for ( i = 0; i < brush->numsides; i++ ) + { + side = &brush->sides[i]; + w = side->winding; + for ( j = 0; j < w->numpoints; j++ ) + { + for ( n = 0; n < 3; n++ ) + { + if ( w->p[j][n] < ( mins[n] + epsilon ) || w->p[j][n] > ( maxs[n] - epsilon ) ) { + return true; + } + } //end for + } //end for + } //end for + return false; +} //end of the function BrushOutOfBounds +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +vec_t BrushVolume( bspbrush_t *brush ) { + int i; + winding_t *w; + vec3_t corner; + vec_t d, area, volume; + plane_t *plane; + + if ( !brush ) { + return 0; + } + + // grab the first valid point as the corner + w = NULL; + for ( i = 0; i < brush->numsides; i++ ) + { + w = brush->sides[i].winding; + if ( w ) { + break; + } + } //end for + if ( !w ) { + return 0; + } + VectorCopy( w->p[0], corner ); + + // make tetrahedrons to all other faces + volume = 0; + for ( ; i < brush->numsides; i++ ) + { + w = brush->sides[i].winding; + if ( !w ) { + continue; + } + plane = &mapplanes[brush->sides[i].planenum]; + d = -( DotProduct( corner, plane->normal ) - plane->dist ); + area = WindingArea( w ); + volume += d * area; + } //end for + + volume /= 3; + return volume; +} //end of the function BrushVolume +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int CountBrushList( bspbrush_t *brushes ) { + int c; + + c = 0; + for ( ; brushes; brushes = brushes->next ) c++; + return c; +} //end of the function CountBrushList +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +node_t *AllocNode( void ) { + node_t *node; + + node = GetMemory( sizeof( *node ) ); + memset( node, 0, sizeof( *node ) ); + if ( numthreads == 1 ) { + c_nodememory += MemorySize( node ); + } //end if + return node; +} //end of the function AllocNode +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +bspbrush_t *AllocBrush( int numsides ) { + bspbrush_t *bb; + int c; + + c = (int)&( ( (bspbrush_t *)0 )->sides[numsides] ); + bb = GetMemory( c ); + memset( bb, 0, c ); + if ( numthreads == 1 ) { + c_active_brushes++; + c_brushmemory += MemorySize( bb ); + if ( c_brushmemory > c_peak_brushmemory ) { + c_peak_brushmemory = c_brushmemory; + } + } //end if + return bb; +} //end of the function AllocBrush +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void FreeBrush( bspbrush_t *brushes ) { + int i; + + for ( i = 0 ; i < brushes->numsides ; i++ ) + if ( brushes->sides[i].winding ) { + FreeWinding( brushes->sides[i].winding ); + } + if ( numthreads == 1 ) { + c_active_brushes--; + c_brushmemory -= MemorySize( brushes ); + if ( c_brushmemory < 0 ) { + c_brushmemory = 0; + } + } //end if + FreeMemory( brushes ); +} //end of the function FreeBrush +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void FreeBrushList( bspbrush_t *brushes ) { + bspbrush_t *next; + + for ( ; brushes; brushes = next ) + { + next = brushes->next; + + FreeBrush( brushes ); + } //end for +} //end of the function FreeBrushList +//=========================================================================== +// Duplicates the brush, the sides, and the windings +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +bspbrush_t *CopyBrush( bspbrush_t *brush ) { + bspbrush_t *newbrush; + int size; + int i; + + size = (int)&( ( (bspbrush_t *)0 )->sides[brush->numsides] ); + + newbrush = AllocBrush( brush->numsides ); + memcpy( newbrush, brush, size ); + + for ( i = 0 ; i < brush->numsides ; i++ ) + { + if ( brush->sides[i].winding ) { + newbrush->sides[i].winding = CopyWinding( brush->sides[i].winding ); + } + } + + return newbrush; +} //end of the function CopyBrush +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +node_t *PointInLeaf( node_t *node, vec3_t point ) { + vec_t d; + plane_t *plane; + + while ( node->planenum != PLANENUM_LEAF ) + { + plane = &mapplanes[node->planenum]; + d = DotProduct( point, plane->normal ) - plane->dist; + if ( d > 0 ) { + node = node->children[0]; + } else { + node = node->children[1]; + } + } + + return node; +} //end of the function PointInLeaf +//=========================================================================== +// Returns PSIDE_FRONT, PSIDE_BACK, or PSIDE_BOTH +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +#if 0 +int BoxOnPlaneSide( vec3_t mins, vec3_t maxs, plane_t *plane ) { + int side; + int i; + vec3_t corners[2]; + vec_t dist1, dist2; + + // axial planes are easy + if ( plane->type < 3 ) { + side = 0; + if ( maxs[plane->type] > plane->dist + PLANESIDE_EPSILON ) { + side |= PSIDE_FRONT; + } + if ( mins[plane->type] < plane->dist - PLANESIDE_EPSILON ) { + side |= PSIDE_BACK; + } + return side; + } + + // create the proper leading and trailing verts for the box + + for ( i = 0 ; i < 3 ; i++ ) + { + if ( plane->normal[i] < 0 ) { + corners[0][i] = mins[i]; + corners[1][i] = maxs[i]; + } else + { + corners[1][i] = mins[i]; + corners[0][i] = maxs[i]; + } + } + + dist1 = DotProduct( plane->normal, corners[0] ) - plane->dist; + dist2 = DotProduct( plane->normal, corners[1] ) - plane->dist; + side = 0; + if ( dist1 >= PLANESIDE_EPSILON ) { + side = PSIDE_FRONT; + } + if ( dist2 < PLANESIDE_EPSILON ) { + side |= PSIDE_BACK; + } + + return side; +} +#else +int BoxOnPlaneSide( vec3_t emins, vec3_t emaxs, plane_t *p ) { + float dist1, dist2; + int sides; + + // axial planes are easy + if ( p->type < 3 ) { + sides = 0; + if ( emaxs[p->type] > p->dist + PLANESIDE_EPSILON ) { + sides |= PSIDE_FRONT; + } + if ( emins[p->type] < p->dist - PLANESIDE_EPSILON ) { + sides |= PSIDE_BACK; + } + return sides; + } //end if + +// general case + switch ( p->signbits ) + { + case 0: + dist1 = p->normal[0] * emaxs[0] + p->normal[1] * emaxs[1] + p->normal[2] * emaxs[2]; + dist2 = p->normal[0] * emins[0] + p->normal[1] * emins[1] + p->normal[2] * emins[2]; + break; + case 1: + dist1 = p->normal[0] * emins[0] + p->normal[1] * emaxs[1] + p->normal[2] * emaxs[2]; + dist2 = p->normal[0] * emaxs[0] + p->normal[1] * emins[1] + p->normal[2] * emins[2]; + break; + case 2: + dist1 = p->normal[0] * emaxs[0] + p->normal[1] * emins[1] + p->normal[2] * emaxs[2]; + dist2 = p->normal[0] * emins[0] + p->normal[1] * emaxs[1] + p->normal[2] * emins[2]; + break; + case 3: + dist1 = p->normal[0] * emins[0] + p->normal[1] * emins[1] + p->normal[2] * emaxs[2]; + dist2 = p->normal[0] * emaxs[0] + p->normal[1] * emaxs[1] + p->normal[2] * emins[2]; + break; + case 4: + dist1 = p->normal[0] * emaxs[0] + p->normal[1] * emaxs[1] + p->normal[2] * emins[2]; + dist2 = p->normal[0] * emins[0] + p->normal[1] * emins[1] + p->normal[2] * emaxs[2]; + break; + case 5: + dist1 = p->normal[0] * emins[0] + p->normal[1] * emaxs[1] + p->normal[2] * emins[2]; + dist2 = p->normal[0] * emaxs[0] + p->normal[1] * emins[1] + p->normal[2] * emaxs[2]; + break; + case 6: + dist1 = p->normal[0] * emaxs[0] + p->normal[1] * emins[1] + p->normal[2] * emins[2]; + dist2 = p->normal[0] * emins[0] + p->normal[1] * emaxs[1] + p->normal[2] * emaxs[2]; + break; + case 7: + dist1 = p->normal[0] * emins[0] + p->normal[1] * emins[1] + p->normal[2] * emins[2]; + dist2 = p->normal[0] * emaxs[0] + p->normal[1] * emaxs[1] + p->normal[2] * emaxs[2]; + break; + default: + dist1 = dist2 = 0; // shut up compiler +// assert( 0 ); + break; + } + + sides = 0; + if ( dist1 - p->dist >= PLANESIDE_EPSILON ) { + sides = PSIDE_FRONT; + } + if ( dist2 - p->dist < PLANESIDE_EPSILON ) { + sides |= PSIDE_BACK; + } + +// assert(sides != 0); + + return sides; +} +#endif +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int QuickTestBrushToPlanenum( bspbrush_t *brush, int planenum, int *numsplits ) { + int i, num; + plane_t *plane; + int s; + + *numsplits = 0; + + plane = &mapplanes[planenum]; + +#ifdef ME + //fast axial cases + if ( plane->type < 3 ) { + if ( plane->dist + PLANESIDE_EPSILON < brush->mins[plane->type] ) { + return PSIDE_FRONT; + } + if ( plane->dist - PLANESIDE_EPSILON > brush->maxs[plane->type] ) { + return PSIDE_BACK; + } + } //end if +#endif //ME*/ + + // if the brush actually uses the planenum, + // we can tell the side for sure + for ( i = 0; i < brush->numsides; i++ ) + { + num = brush->sides[i].planenum; + if ( num >= MAX_MAPFILE_PLANES ) { + Error( "bad planenum" ); + } + if ( num == planenum ) { + return PSIDE_BACK | PSIDE_FACING; + } + if ( num == ( planenum ^ 1 ) ) { + return PSIDE_FRONT | PSIDE_FACING; + } + + } + + // box on plane side + s = BoxOnPlaneSide( brush->mins, brush->maxs, plane ); + + // if both sides, count the visible faces split + if ( s == PSIDE_BOTH ) { + *numsplits += 3; + } + + return s; +} //end of the function QuickTestBrushToPlanenum +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int TestBrushToPlanenum( bspbrush_t *brush, int planenum, + int *numsplits, qboolean *hintsplit, int *epsilonbrush ) { + int i, j, num; + plane_t *plane; + int s = 0; + winding_t *w; + vec_t d, d_front, d_back; + int front, back; + int type; + float dist; + + *numsplits = 0; + *hintsplit = false; + + plane = &mapplanes[planenum]; + +#ifdef ME +// fast axial cases + type = plane->type; + if ( type < 3 ) { + dist = plane->dist; + if ( dist + PLANESIDE_EPSILON < brush->mins[type] ) { + return PSIDE_FRONT; + } + if ( dist - PLANESIDE_EPSILON > brush->maxs[type] ) { + return PSIDE_BACK; + } + if ( brush->mins[type] < dist - PLANESIDE_EPSILON && + brush->maxs[type] > dist + PLANESIDE_EPSILON ) { + s = PSIDE_BOTH; + } + } //end if + + if ( s != PSIDE_BOTH ) +#endif //ME + { + // if the brush actually uses the planenum, + // we can tell the side for sure + for ( i = 0; i < brush->numsides; i++ ) + { + num = brush->sides[i].planenum; + if ( num >= MAX_MAPFILE_PLANES ) { + Error( "bad planenum" ); + } + if ( num == planenum ) { + //we don't need to test this side plane again + brush->sides[i].flags |= SFL_TESTED; + return PSIDE_BACK | PSIDE_FACING; + } //end if + if ( num == ( planenum ^ 1 ) ) { + //we don't need to test this side plane again + brush->sides[i].flags |= SFL_TESTED; + return PSIDE_FRONT | PSIDE_FACING; + } //end if + } //end for + + // box on plane side + s = BoxOnPlaneSide( brush->mins, brush->maxs, plane ); + + if ( s != PSIDE_BOTH ) { + return s; + } + } //end if + +// if both sides, count the visible faces split + d_front = d_back = 0; + + for ( i = 0; i < brush->numsides; i++ ) + { + if ( brush->sides[i].texinfo == TEXINFO_NODE ) { + continue; // on node, don't worry about splits + } + if ( !( brush->sides[i].flags & SFL_VISIBLE ) ) { + continue; // we don't care about non-visible + } + w = brush->sides[i].winding; + if ( !w ) { + continue; + } + front = back = 0; + for ( j = 0; j < w->numpoints; j++ ) + { + d = DotProduct( w->p[j], plane->normal ) - plane->dist; + if ( d > d_front ) { + d_front = d; + } + if ( d < d_back ) { + d_back = d; + } + if ( d > 0.1 ) { // PLANESIDE_EPSILON) + front = 1; + } + if ( d < -0.1 ) { // PLANESIDE_EPSILON) + back = 1; + } + } //end for + if ( front && back ) { + if ( !( brush->sides[i].surf & SURF_SKIP ) ) { + ( *numsplits )++; + if ( brush->sides[i].surf & SURF_HINT ) { + *hintsplit = true; + } //end if + } //end if + } //end if + } //end for + + if ( ( d_front > 0.0 && d_front < 1.0 ) + || ( d_back < 0.0 && d_back > -1.0 ) ) { + ( *epsilonbrush )++; + } + +#if 0 + if ( *numsplits == 0 ) { // didn't really need to be split + if ( front ) { + s = PSIDE_FRONT; + } else if ( back ) { + s = PSIDE_BACK; + } else { s = 0;} + } +#endif + + return s; +} //end of the function TestBrushToPlanenum +//=========================================================================== +// Returns true if the winding would be crunched out of +// existance by the vertex snapping. +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +#define EDGE_LENGTH 0.2 +qboolean WindingIsTiny( winding_t *w ) { +#if 0 + if ( WindingArea( w ) < 1 ) { + return true; + } + return false; +#else + int i, j; + vec_t len; + vec3_t delta; + int edges; + + edges = 0; + for ( i = 0 ; i < w->numpoints ; i++ ) + { + j = i == w->numpoints - 1 ? 0 : i + 1; + VectorSubtract( w->p[j], w->p[i], delta ); + len = VectorLength( delta ); + if ( len > EDGE_LENGTH ) { + if ( ++edges == 3 ) { + return false; + } + } + } + return true; +#endif +} +//=========================================================================== +// Returns true if the winding still has one of the points +// from basewinding for plane +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +qboolean WindingIsHuge( winding_t *w ) { + int i, j; + + for ( i = 0 ; i < w->numpoints ; i++ ) + { + for ( j = 0 ; j < 3 ; j++ ) + if ( w->p[i][j] < -BOGUS_RANGE + 1 || w->p[i][j] > BOGUS_RANGE - 1 ) { + return true; + } + } + return false; +} //end of the function WindingIsHuge +//=========================================================================== +// creates a leaf out of the given nodes with the given brushes +// +// FIXME: use the origin->expansionbbox to find areas with different +// presence types +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void LeafNode( node_t *node, bspbrush_t *brushes ) { + bspbrush_t *b; + int i; + + node->side = NULL; + node->planenum = PLANENUM_LEAF; + node->contents = 0; + + for ( b = brushes; b; b = b->next ) + { + // if the brush is solid and all of its sides are on nodes, + // it eats everything + if ( b->original->contents & CONTENTS_SOLID ) { + for ( i = 0 ; i < b->numsides ; i++ ) + if ( b->sides[i].texinfo != TEXINFO_NODE ) { + break; + } + if ( i == b->numsides ) { + node->contents = CONTENTS_SOLID; + break; + } //end if + } //end if + node->contents |= b->original->contents; + } //end for + + if ( create_aas ) { + node->expansionbboxes = 0; + node->contents = 0; + for ( b = brushes; b; b = b->next ) + { + node->expansionbboxes |= b->original->expansionbbox; + node->contents |= b->original->contents; + if ( b->original->modelnum ) { + node->modelnum = b->original->modelnum; + } + } //end for + if ( node->contents & CONTENTS_SOLID ) { + if ( node->expansionbboxes != cfg.allpresencetypes ) { + node->contents &= ~CONTENTS_SOLID; + } //end if + } //end if + } //end if + + node->brushlist = brushes; +} //end of the function LeafNode +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void CheckPlaneAgainstParents( int pnum, node_t *node ) { + node_t *p; + + for ( p = node->parent; p; p = p->parent ) + { + if ( p->planenum == pnum ) { + Error( "Tried parent" ); + } + } //end for +} //end of the function CheckPlaneAgainstParants +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +qboolean CheckPlaneAgainstVolume( int pnum, node_t *node ) { + bspbrush_t *front, *back; + qboolean good; + + SplitBrush( node->volume, pnum, &front, &back ); + + good = ( front && back ); + + if ( front ) { + FreeBrush( front ); + } + if ( back ) { + FreeBrush( back ); + } + + return good; +} //end of the function CheckPlaneAgaintsVolume +//=========================================================================== +// Using a hueristic, choses one of the sides out of the brushlist +// to partition the brushes with. +// Returns NULL if there are no valid planes to split with.. +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== + +/* + + //perfect for fact2: + + value = 5*facing - 7*splits - abs(front-back); + if (mapplanes[pnum].type < 3) + value+=3; // axial is better +*/ + +side_t *SelectSplitSide( bspbrush_t *brushes, node_t *node ) { + int value, bestvalue; + bspbrush_t *brush, *test; + side_t *side, *bestside; + int i, pass, numpasses; + //int j; + int pnum; + int s; + int front, back, both, facing, splits; + int bsplits; + int bestsplits; + int epsilonbrush; + qboolean hintsplit = false; + + bestside = NULL; + bestvalue = -99999; + bestsplits = 0; + + // the search order goes: visible-structural, visible-detail, + // nonvisible-structural, nonvisible-detail. + // If any valid plane is available in a pass, no further + // passes will be tried. + numpasses = 2; + for ( pass = 0; pass < numpasses; pass++ ) + { + for ( brush = brushes; brush; brush = brush->next ) + { + // only check detail the second pass +// if ( (pass & 1) && !(brush->original->contents & CONTENTS_DETAIL) ) +// continue; +// if ( !(pass & 1) && (brush->original->contents & CONTENTS_DETAIL) ) +// continue; + for ( i = 0; i < brush->numsides; i++ ) + { + side = brush->sides + i; +// if (side->flags & SFL_BEVEL) +// continue; // never use a bevel as a spliter + if ( !side->winding ) { + continue; // nothing visible, so it can't split + } + if ( side->texinfo == TEXINFO_NODE ) { + continue; // allready a node splitter + } + if ( side->flags & SFL_TESTED ) { + continue; // we allready have metrics for this plane + } +// if (side->surf & SURF_SKIP) +// continue; // skip surfaces are never chosen +// if (!(side->flags & SFL_VISIBLE) && (pass < 2)) +// continue; // only check visible faces on first pass + if ( ( side->flags & SFL_CURVE ) && ( pass < 1 ) ) { + continue; // only check curves on the second pass + + } + pnum = side->planenum; + pnum &= ~1; // allways use positive facing plane + + CheckPlaneAgainstParents( pnum, node ); + + if ( !CheckPlaneAgainstVolume( pnum, node ) ) { + continue; // would produce a tiny volume + + } + front = 0; + back = 0; + both = 0; + facing = 0; + splits = 0; + epsilonbrush = 0; + + //inner loop: optimize + for ( test = brushes; test; test = test->next ) + { + s = TestBrushToPlanenum( test, pnum, &bsplits, &hintsplit, &epsilonbrush ); + + splits += bsplits; +// if (bsplits && (s&PSIDE_FACING) ) +// Error ("PSIDE_FACING with splits"); + + test->testside = s; + // + if ( s & PSIDE_FACING ) { + facing++; + } + if ( s & PSIDE_FRONT ) { + front++; + } + if ( s & PSIDE_BACK ) { + back++; + } + if ( s == PSIDE_BOTH ) { + both++; + } + } //end for + + // give a value estimate for using this plane + value = 5 * facing - 5 * splits - abs( front - back ); +// value = -5*splits; +// value = 5*facing - 5*splits; + if ( mapplanes[pnum].type < 3 ) { + value += 5; // axial is better + + } + value -= epsilonbrush * 1000; // avoid! + + // never split a hint side except with another hint + if ( hintsplit && !( side->surf & SURF_HINT ) ) { + value = -9999999; + } + + // save off the side test so we don't need + // to recalculate it when we actually seperate + // the brushes + if ( value > bestvalue ) { + bestvalue = value; + bestside = side; + bestsplits = splits; + for ( test = brushes; test ; test = test->next ) + test->side = test->testside; + } //end if + } //end for + } //end for (brush = brushes; + + // if we found a good plane, don't bother trying any + // other passes + if ( bestside ) { + if ( pass > 1 ) { + if ( numthreads == 1 ) { + c_nonvis++; + } + } + if ( pass > 0 ) { + node->detail_seperator = true; // not needed for vis + } + break; + } //end if + } //end for (pass = 0; + + // + // clear all the tested flags we set + // + for ( brush = brushes ; brush ; brush = brush->next ) + { + for ( i = 0; i < brush->numsides; i++ ) + { + brush->sides[i].flags &= ~SFL_TESTED; + } //end for + } //end for + + return bestside; +} //end of the function SelectSplitSide +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int BrushMostlyOnSide( bspbrush_t *brush, plane_t *plane ) { + int i, j; + winding_t *w; + vec_t d, max; + int side; + + max = 0; + side = PSIDE_FRONT; + for ( i = 0 ; i < brush->numsides ; i++ ) + { + w = brush->sides[i].winding; + if ( !w ) { + continue; + } + for ( j = 0 ; j < w->numpoints ; j++ ) + { + d = DotProduct( w->p[j], plane->normal ) - plane->dist; + if ( d > max ) { + max = d; + side = PSIDE_FRONT; + } + if ( -d > max ) { + max = -d; + side = PSIDE_BACK; + } + } + } + return side; +} //end of the function BrushMostlyOnSide +//=========================================================================== +// Generates two new brushes, leaving the original +// unchanged +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void SplitBrush( bspbrush_t *brush, int planenum, + bspbrush_t **front, bspbrush_t **back ) { + bspbrush_t *b[2]; + int i, j; + winding_t *w, *cw[2], *midwinding; + plane_t *plane, *plane2; + side_t *s, *cs; + float d, d_front, d_back; + + *front = *back = NULL; + plane = &mapplanes[planenum]; + + // check all points + d_front = d_back = 0; + for ( i = 0 ; i < brush->numsides ; i++ ) + { + w = brush->sides[i].winding; + if ( !w ) { + continue; + } + for ( j = 0 ; j < w->numpoints ; j++ ) + { + d = DotProduct( w->p[j], plane->normal ) - plane->dist; + if ( d > 0 && d > d_front ) { + d_front = d; + } + if ( d < 0 && d < d_back ) { + d_back = d; + } + } + } + + if ( d_front < 0.2 ) { // PLANESIDE_EPSILON) + // only on back + *back = CopyBrush( brush ); + return; + } + if ( d_back > -0.2 ) { // PLANESIDE_EPSILON) + // only on front + *front = CopyBrush( brush ); + return; + } + + // create a new winding from the split plane + + w = BaseWindingForPlane( plane->normal, plane->dist ); + for ( i = 0 ; i < brush->numsides && w ; i++ ) + { + plane2 = &mapplanes[brush->sides[i].planenum ^ 1]; + ChopWindingInPlace( &w, plane2->normal, plane2->dist, 0 ); // PLANESIDE_EPSILON); + } + + if ( !w || WindingIsTiny( w ) ) { // the brush isn't really split + int side; + + side = BrushMostlyOnSide( brush, plane ); + if ( side == PSIDE_FRONT ) { + *front = CopyBrush( brush ); + } + if ( side == PSIDE_BACK ) { + *back = CopyBrush( brush ); + } + //free a possible winding + if ( w ) { + FreeWinding( w ); + } + return; + } + + if ( WindingIsHuge( w ) ) { + Log_Write( "WARNING: huge winding\n" ); + } + + midwinding = w; + + // split it for real + + for ( i = 0 ; i < 2 ; i++ ) + { + b[i] = AllocBrush( brush->numsides + 1 ); + b[i]->original = brush->original; + } + + // split all the current windings + + for ( i = 0 ; i < brush->numsides ; i++ ) + { + s = &brush->sides[i]; + w = s->winding; + if ( !w ) { + continue; + } + ClipWindingEpsilon( w, plane->normal, plane->dist, + 0 /*PLANESIDE_EPSILON*/, &cw[0], &cw[1] ); + for ( j = 0 ; j < 2 ; j++ ) + { + if ( !cw[j] ) { + continue; + } +#if 0 + if ( WindingIsTiny( cw[j] ) ) { + FreeWinding( cw[j] ); + continue; + } +#endif + cs = &b[j]->sides[b[j]->numsides]; + b[j]->numsides++; + *cs = *s; +// cs->planenum = s->planenum; +// cs->texinfo = s->texinfo; +// cs->original = s->original; + cs->winding = cw[j]; + cs->flags &= ~SFL_TESTED; + } + } + + + // see if we have valid polygons on both sides + + for ( i = 0 ; i < 2 ; i++ ) + { + BoundBrush( b[i] ); + for ( j = 0 ; j < 3 ; j++ ) + { + if ( b[i]->mins[j] < -MAX_MAP_BOUNDS || b[i]->maxs[j] > MAX_MAP_BOUNDS ) { + Log_Write( "bogus brush after clip" ); + break; + } + } + + if ( b[i]->numsides < 3 || j < 3 ) { + FreeBrush( b[i] ); + b[i] = NULL; + } + } + + if ( !( b[0] && b[1] ) ) { + if ( !b[0] && !b[1] ) { + Log_Write( "split removed brush\r\n" ); + } else { + Log_Write( "split not on both sides\r\n" ); + } + if ( b[0] ) { + FreeBrush( b[0] ); + *front = CopyBrush( brush ); + } + if ( b[1] ) { + FreeBrush( b[1] ); + *back = CopyBrush( brush ); + } + return; + } + + // add the midwinding to both sides + for ( i = 0 ; i < 2 ; i++ ) + { + cs = &b[i]->sides[b[i]->numsides]; + b[i]->numsides++; + + cs->planenum = planenum ^ i ^ 1; + cs->texinfo = TEXINFO_NODE; //never use these sides as splitters + cs->flags &= ~SFL_VISIBLE; + cs->flags &= ~SFL_TESTED; + if ( i == 0 ) { + cs->winding = CopyWinding( midwinding ); + } else { + cs->winding = midwinding; + } + } + + { + vec_t v1; + int i; + + for ( i = 0; i < 2; i++ ) + { + v1 = BrushVolume( b[i] ); + if ( v1 < 1.0 ) { + FreeBrush( b[i] ); + b[i] = NULL; + //Log_Write("tiny volume after clip"); + } + } + if ( !b[0] && !b[1] ) { + Log_Write( "two tiny brushes\r\n" ); + } //end if + } + + *front = b[0]; + *back = b[1]; +} //end of the function SplitBrush +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void SplitBrushList( bspbrush_t *brushes, + node_t *node, bspbrush_t **front, bspbrush_t **back ) { + bspbrush_t *brush, *newbrush, *newbrush2; + side_t *side; + int sides; + int i; + + *front = *back = NULL; + + for ( brush = brushes ; brush ; brush = brush->next ) + { + sides = brush->side; + + if ( sides == PSIDE_BOTH ) { // split into two brushes + SplitBrush( brush, node->planenum, &newbrush, &newbrush2 ); + if ( newbrush ) { + newbrush->next = *front; + *front = newbrush; + } //end if + if ( newbrush2 ) { + newbrush2->next = *back; + *back = newbrush2; + } //end if + continue; + } //end if + + newbrush = CopyBrush( brush ); + + // if the planenum is actualy a part of the brush + // find the plane and flag it as used so it won't be tried + // as a splitter again + if ( sides & PSIDE_FACING ) { + for ( i = 0 ; i < newbrush->numsides ; i++ ) + { + side = newbrush->sides + i; + if ( ( side->planenum & ~1 ) == node->planenum ) { + side->texinfo = TEXINFO_NODE; + } + } //end for + } //end if + + if ( sides & PSIDE_FRONT ) { + newbrush->next = *front; + *front = newbrush; + continue; + } //end if + if ( sides & PSIDE_BACK ) { + newbrush->next = *back; + *back = newbrush; + continue; + } //end if + } //end for +} //end of the function SplitBrushList +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void CheckBrushLists( bspbrush_t *brushlist1, bspbrush_t *brushlist2 ) { + bspbrush_t *brush1, *brush2; + + for ( brush1 = brushlist1; brush1; brush1 = brush1->next ) + { + for ( brush2 = brushlist2; brush2; brush2 = brush2->next ) + { + assert( brush1 != brush2 ); + } //end for + } //end for +} //end of the function CheckBrushLists +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int numrecurse = 0; + +node_t *BuildTree_r( node_t *node, bspbrush_t *brushes ) { + node_t *newnode; + side_t *bestside; + int i, totalmem; + bspbrush_t *children[2]; + + qprintf( "\r%6d", numrecurse ); + numrecurse++; + + if ( numthreads == 1 ) { + totalmem = WindingMemory() + c_nodememory + c_brushmemory; + if ( totalmem > c_peak_totalbspmemory ) { + c_peak_totalbspmemory = totalmem; + } + c_nodes++; + } //endif + + if ( drawflag ) { + DrawBrushList( brushes, node ); + } + + // find the best plane to use as a splitter + bestside = SelectSplitSide( brushes, node ); + if ( !bestside ) { + // leaf node + node->side = NULL; + node->planenum = -1; + LeafNode( node, brushes ); + if ( node->contents & CONTENTS_SOLID ) { + c_solidleafnodes++; + } + if ( create_aas ) { + //free up memory!!! + FreeBrushList( node->brushlist ); + node->brushlist = NULL; + //free the node volume brush + if ( node->volume ) { + FreeBrush( node->volume ); + node->volume = NULL; + } //end if + } //end if + return node; + } //end if + + // this is a splitplane node + node->side = bestside; + node->planenum = bestside->planenum & ~1; // always use front facing + + //split the brush list in two for both children + SplitBrushList( brushes, node, &children[0], &children[1] ); + //free the old brush list + FreeBrushList( brushes ); + + // allocate children before recursing + for ( i = 0; i < 2; i++ ) + { + newnode = AllocNode(); + newnode->parent = node; + node->children[i] = newnode; + } //end for + + //split the volume brush of the node for the children + SplitBrush( node->volume, node->planenum, &node->children[0]->volume, + &node->children[1]->volume ); + + if ( create_aas ) { + //free the volume brush + if ( node->volume ) { + FreeBrush( node->volume ); + node->volume = NULL; + } //end if + } //end if + // recursively process children + for ( i = 0; i < 2; i++ ) + { + node->children[i] = BuildTree_r( node->children[i], children[i] ); + } //end for + + return node; +} //end of the function BuildTree_r +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +node_t *firstnode; //first node in the list +node_t *lastnode; //last node in the list +int nodelistsize; //number of nodes in the list +int use_nodequeue = 0; //use nodequeue, otherwise a node stack is used +int numwaiting = 0; + +void ( *AddNodeToList )( node_t *node ); + +//add the node to the front of the node list +//(effectively using a node stack) +void AddNodeToStack( node_t *node ) { + ThreadLock(); + + node->next = firstnode; + firstnode = node; + if ( !lastnode ) { + lastnode = node; + } + nodelistsize++; + + ThreadUnlock(); + // + ThreadSemaphoreIncrease( 1 ); +} //end of the function AddNodeToStack +//add the node to the end of the node list +//(effectively using a node queue) +void AddNodeToQueue( node_t *node ) { + ThreadLock(); + + node->next = NULL; + if ( lastnode ) { + lastnode->next = node; + } else { firstnode = node;} + lastnode = node; + nodelistsize++; + + ThreadUnlock(); + // + ThreadSemaphoreIncrease( 1 ); +} //end of the function AddNodeToQueue +//get the first node from the front of the node list +node_t *NextNodeFromList( void ) { + node_t *node; + + ThreadLock(); + numwaiting++; + if ( !firstnode ) { + if ( numwaiting >= GetNumThreads() ) { + ThreadSemaphoreIncrease( GetNumThreads() ); + } + } //end if + ThreadUnlock(); + + ThreadSemaphoreWait(); + + ThreadLock(); + + numwaiting--; + + node = firstnode; + if ( firstnode ) { + firstnode = firstnode->next; + nodelistsize--; + } //end if + if ( !firstnode ) { + lastnode = NULL; + } + + ThreadUnlock(); + + return node; +} //end of the function NextNodeFromList +//returns the size of the node list +int NodeListSize( void ) { + int size; + + ThreadLock(); + size = nodelistsize; + ThreadUnlock(); + + return size; +} //end of the function NodeListSize +// +void IncreaseNodeCounter( void ) { + ThreadLock(); + //if (verbose) printf("\r%6d", numrecurse++); + qprintf( "\r%6d", numrecurse++ ); + //qprintf("\r%6d %d, %5d ", numrecurse++, GetNumThreads(), nodelistsize); + ThreadUnlock(); +} //end of the function IncreaseNodeCounter +//thread function, gets nodes from the nodelist and processes them +void BuildTreeThread( int threadid ) { + node_t *newnode, *node; + side_t *bestside; + int i, totalmem; + bspbrush_t *brushes; + + for ( node = NextNodeFromList(); node; ) + { + //if the nodelist isn't empty try to add another thread + //if (NodeListSize() > 10) AddThread(BuildTreeThread); + //display the number of nodes processed so far + if ( numthreads == 1 ) { + IncreaseNodeCounter(); + } + + brushes = node->brushlist; + + if ( numthreads == 1 ) { + totalmem = WindingMemory() + c_nodememory + c_brushmemory; + if ( totalmem > c_peak_totalbspmemory ) { + c_peak_totalbspmemory = totalmem; + } //end if + c_nodes++; + } //endif + + if ( drawflag ) { + DrawBrushList( brushes, node ); + } //end if + + if ( cancelconversion ) { + bestside = NULL; + } //end if + else + { + // find the best plane to use as a splitter + bestside = SelectSplitSide( brushes, node ); + } //end else + //if there's no split side left + if ( !bestside ) { + //create a leaf out of the node + LeafNode( node, brushes ); + if ( node->contents & CONTENTS_SOLID ) { + c_solidleafnodes++; + } + + if ( create_aas ) { + //free up memory!!! + FreeBrushList( node->brushlist ); + node->brushlist = NULL; + } //end if + //free the node volume brush (it is not used anymore) + if ( node->volume ) { + FreeBrush( node->volume ); + node->volume = NULL; + } //end if + node = NextNodeFromList(); + continue; + } //end if + + // this is a splitplane node + node->side = bestside; + node->planenum = bestside->planenum & ~1; //always use front facing + + //allocate children + for ( i = 0; i < 2; i++ ) + { + newnode = AllocNode(); + newnode->parent = node; + node->children[i] = newnode; + } //end for + + //split the brush list in two for both children + SplitBrushList( brushes, node, &node->children[0]->brushlist, &node->children[1]->brushlist ); + + CheckBrushLists( node->children[0]->brushlist, node->children[1]->brushlist ); + //free the old brush list + FreeBrushList( brushes ); + node->brushlist = NULL; + + //split the volume brush of the node for the children + SplitBrush( node->volume, node->planenum, &node->children[0]->volume, + &node->children[1]->volume ); + + if ( !node->children[0]->volume || !node->children[1]->volume ) { + Error( "child without volume brush" ); + } //end if + + //free the volume brush + if ( node->volume ) { + FreeBrush( node->volume ); + node->volume = NULL; + } //end if + + //add both children to the node list + //AddNodeToList(node->children[0]); + AddNodeToList( node->children[1] ); + node = node->children[0]; + } //end while + RemoveThread( threadid ); +} //end of the function BuildTreeThread +//=========================================================================== +// build the bsp tree using a node list +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void BuildTree( tree_t *tree ) { + int i; + + firstnode = NULL; + lastnode = NULL; + //use a node queue or node stack + if ( use_nodequeue ) { + AddNodeToList = AddNodeToQueue; + } else { AddNodeToList = AddNodeToStack;} + //setup thread locking + ThreadSetupLock(); + ThreadSetupSemaphore(); + numwaiting = 0; + // + Log_Print( "%6d threads max\n", numthreads ); + if ( use_nodequeue ) { + Log_Print( "breadth first bsp building\n" ); + } else { Log_Print( "depth first bsp building\n" );} + qprintf( "%6d splits", 0 ); + //add the first node to the list + AddNodeToList( tree->headnode ); + //start the threads + for ( i = 0; i < numthreads; i++ ) + AddThread( BuildTreeThread ); + //wait for all added threads to be finished + WaitForAllThreadsFinished(); + //shutdown the thread locking + ThreadShutdownLock(); + ThreadShutdownSemaphore(); +} //end of the function BuildTree +//=========================================================================== +// The incoming brush list will be freed before exiting +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +tree_t *BrushBSP( bspbrush_t *brushlist, vec3_t mins, vec3_t maxs ) { + int i, c_faces, c_nonvisfaces, c_brushes; + bspbrush_t *b; + node_t *node; + tree_t *tree; + vec_t volume; +// vec3_t point; + + Log_Print( "-------- Brush BSP ---------\n" ); + + tree = Tree_Alloc(); + + c_faces = 0; + c_nonvisfaces = 0; + c_brushes = 0; + c_totalsides = 0; + for ( b = brushlist; b; b = b->next ) + { + c_brushes++; + + volume = BrushVolume( b ); + if ( volume < microvolume ) { + Log_Print( "WARNING: entity %i, brush %i: microbrush\n", + b->original->entitynum, b->original->brushnum ); + } //end if + + for ( i = 0 ; i < b->numsides ; i++ ) + { + if ( b->sides[i].flags & SFL_BEVEL ) { + continue; + } + if ( !b->sides[i].winding ) { + continue; + } + if ( b->sides[i].texinfo == TEXINFO_NODE ) { + continue; + } + if ( b->sides[i].flags & SFL_VISIBLE ) { + c_faces++; + } //end if + else + { + c_nonvisfaces++; + //if (create_aas) b->sides[i].texinfo = TEXINFO_NODE; + } //end if + } //end for + c_totalsides += b->numsides; + + AddPointToBounds( b->mins, tree->mins, tree->maxs ); + AddPointToBounds( b->maxs, tree->mins, tree->maxs ); + } //end for + + Log_Print( "%6i brushes\n", c_brushes ); + Log_Print( "%6i visible faces\n", c_faces ); + Log_Print( "%6i nonvisible faces\n", c_nonvisfaces ); + Log_Print( "%6i total sides\n", c_totalsides ); + + c_active_brushes = c_brushes; + c_nodememory = 0; + c_brushmemory = 0; + c_peak_brushmemory = 0; + + c_nodes = 0; + c_nonvis = 0; + node = AllocNode(); + + //volume of first node (head node) + node->volume = BrushFromBounds( mins, maxs ); + // + tree->headnode = node; + //just get some statistics and the mins/maxs of the node + numrecurse = 0; +// qprintf("%6d splits", numrecurse); + + tree->headnode->brushlist = brushlist; + BuildTree( tree ); + + //build the bsp tree with the start node from the brushlist +// node = BuildTree_r(node, brushlist); + + //if the conversion is cancelled + if ( cancelconversion ) { + return tree; + } + + qprintf( "\n" ); + Log_Write( "%6d splits\r\n", numrecurse ); +// Log_Print("%6i visible nodes\n", c_nodes/2 - c_nonvis); +// Log_Print("%6i nonvis nodes\n", c_nonvis); +// Log_Print("%6i leaves\n", (c_nodes+1)/2); +// Log_Print("%6i solid leaf nodes\n", c_solidleafnodes); +// Log_Print("%6i active brushes\n", c_active_brushes); + if ( numthreads == 1 ) { +// Log_Print("%6i KB of node memory\n", c_nodememory >> 10); +// Log_Print("%6i KB of brush memory\n", c_brushmemory >> 10); +// Log_Print("%6i KB of peak brush memory\n", c_peak_brushmemory >> 10); +// Log_Print("%6i KB of winding memory\n", WindingMemory() >> 10); +// Log_Print("%6i KB of peak winding memory\n", WindingPeakMemory() >> 10); + Log_Print( "%6i KB of peak total bsp memory\n", c_peak_totalbspmemory >> 10 ); + } //end if + + /* + point[0] = 1485; + point[1] = 956.125; + point[2] = 352.125; + node = PointInLeaf(tree->headnode, point); + if (node->planenum != PLANENUM_LEAF) + { + Log_Print("node not a leaf\n"); + } //end if + Log_Print("at %f %f %f:\n", point[0], point[1], point[2]); + PrintContents(node->contents); + Log_Print("node->expansionbboxes = %d\n", node->expansionbboxes); + // + */ + return tree; +} //end of the function BrushBSP + diff --git a/Projects/Android/jni/rtcw/src/bspc/bspc.c b/Projects/Android/jni/rtcw/src/bspc/bspc.c new file mode 100644 index 0000000..59f97bf --- /dev/null +++ b/Projects/Android/jni/rtcw/src/bspc/bspc.c @@ -0,0 +1,1129 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +//=========================================================================== +// +// Name: BSP tool +// Function: +// Programmer: id Software & Mr Elusive (MrElusive@demigod.demon.nl) +// Last update: 1997-12-04 +// Tab Size: 3 +// Notes: Microsoft Visual C++ optimizations: +// "global optimization" or "full optimization" results +// in micro brushes?? +//=========================================================================== + +#if defined( WIN32 ) || defined( _WIN32 ) +#include +#include +#include +#include +#else +#include +#include +#include +#include +#endif +#include "qbsp.h" +#include "l_mem.h" +//#include "l_qfiles.h" +#include "../botlib/aasfile.h" +#include "../botlib/be_aas_cluster.h" +#include "../botlib/be_aas_optimize.h" +#include "aas_create.h" +#include "aas_store.h" +#include "aas_file.h" +#include "aas_cfg.h" +#include "be_aas_bspc.h" + +#define BSPC_VERSION "2.1c-wolf" + +// TTimo: some messy config things +#ifndef BSPC + #define BSPC // RF +#endif +#define stricmp strcasecmp + +void AAS_InitBotImport(); +void AAS_InitClustering(); +void AAS_ShowTotals(); + + +extern int use_nodequeue; //brushbsp.c +extern int calcgrapplereach; //be_aas_reach.c + +float subdivide_size = 240; +char source[1024]; +char name[1024]; +vec_t microvolume = 1.0; +char outbase[32]; +int entity_num; +aas_settings_t aassettings; + +qboolean noprune; //don't prune nodes (bspc.c) +qboolean glview; //create a gl view +qboolean nodetail; //don't use detail brushes (map.c) +qboolean fulldetail; //use but don't mark detail brushes (map.c) +qboolean onlyents; //only process the entities (bspc.c) +qboolean nomerge; //don't merge bsp node faces (faces.c) +qboolean nowater; //don't use the water brushes (map.c) +qboolean nocsg; //don't carve intersecting brushes (bspc.c) +qboolean noweld; //use unique face vertexes (faces.c) +qboolean noshare; //don't share bsp edges (faces.c) +qboolean nosubdiv; //don't subdivide bsp node faces (faces.c) +qboolean notjunc; //don't create tjunctions (edge melting) (faces.c) +qboolean optimize; //enable optimisation +qboolean leaktest; //perform a leak test +qboolean verboseentities; +qboolean freetree; //free the bsp tree when not needed anymore +qboolean create_aas; //create an .AAS file +qboolean nobrushmerge; //don't merge brushes +qboolean lessbrushes; //create less brushes instead of correct texture placement +qboolean cancelconversion; //true if the conversion is being cancelled +qboolean noliquids; //no liquids when writing map file +qboolean forcesidesvisible; //force all brush sides to be visible when loaded from bsp +qboolean writeaasmap; // +// qboolean capsule_collision = true; //use capsule collision +qboolean capsule_collision = false; // capsule collision// Ridah, allow to specify an extension for multiple AAS files per map + +char aas_extension[64]; +// done. + +float VectorDistance( vec3_t v1, vec3_t v2 ) { + vec3_t dir; + + VectorSubtract( v2, v1, dir ); + return VectorLength( dir ); +} + +/* +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void ProcessWorldModel (void) +{ + entity_t *e; + tree_t *tree; + qboolean leaked; + int brush_start, brush_end; + + e = &entities[entity_num]; + + brush_start = e->firstbrush; + brush_end = brush_start + e->numbrushes; + leaked = false; + + //process the whole world in one time + tree = ProcessWorldBrushes(brush_start, brush_end); + //create the bsp tree portals + MakeTreePortals(tree); + //mark all leafs that can be reached by entities + if (FloodEntities(tree)) + { + FillOutside(tree->headnode); + } //end if + else + { + Log_Print("**** leaked ****\n"); + leaked = true; + LeakFile(tree); + if (leaktest) + { + Log_Print("--- MAP LEAKED ---\n"); + exit(0); + } //end if + } //end else + + MarkVisibleSides (tree, brush_start, brush_end); + + FloodAreas (tree); + +#ifndef ME + if (glview) WriteGLView(tree, source); +#endif + MakeFaces(tree->headnode); + FixTjuncs(tree->headnode); + + //NOTE: Never prune the nodes because the portals + // are screwed when prunning is done and as + // a result portal writing will crash + //if (!noprune) PruneNodes(tree->headnode); + + WriteBSP(tree->headnode); + + if (!leaked) WritePortalFile(tree); + + Tree_Free(tree); +} //end of the function ProcessWorldModel +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void ProcessSubModel (void) +{ + entity_t *e; + int start, end; + tree_t *tree; + bspbrush_t *list; + vec3_t mins, maxs; + + e = &entities[entity_num]; + + start = e->firstbrush; + end = start + e->numbrushes; + + mins[0] = mins[1] = mins[2] = -4096; + maxs[0] = maxs[1] = maxs[2] = 4096; + list = MakeBspBrushList(start, end, mins, maxs); + if (!nocsg) list = ChopBrushes (list); + tree = BrushBSP (list, mins, maxs); + MakeTreePortals (tree); + MarkVisibleSides (tree, start, end); + MakeFaces (tree->headnode); + FixTjuncs (tree->headnode); + WriteBSP (tree->headnode); + Tree_Free (tree); +} //end of the function ProcessSubModel +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void ProcessModels (void) +{ + BeginBSPFile(); + + for (entity_num = 0; entity_num < num_entities; entity_num++) + { + if (!entities[entity_num].numbrushes) + continue; + + Log_Print("############### model %i ###############\n", nummodels); + BeginModel(); + if (entity_num == 0) ProcessWorldModel(); + else ProcessSubModel(); + EndModel(); + + if (!verboseentities) + verbose = false; // don't bother printing submodels + } //end for + EndBSPFile(); +} //end of the function ProcessModels +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void Win_Map2Bsp(char *bspfilename) +{ + double start, end; + char path[1024]; + + start = I_FloatTime(); + + ThreadSetDefault(); + //yeah sure Carmack + //numthreads = 1; // multiple threads aren't helping... + + strcpy(source, ExpandArg(bspfilename)); + StripExtension(source); + + //delete portal and line files + sprintf(path, "%s.prt", source); + remove(path); + sprintf(path, "%s.lin", source); + remove(path); + + strcpy(name, ExpandArg(bspfilename)); + DefaultExtension(name, ".map"); // might be .reg + + Q2_AllocMaxBSP(); + // + SetModelNumbers(); + SetLightStyles(); + ProcessModels(); + //write the BSP + Q2_WriteBSPFile(bspfilename); + + Q2_FreeMaxBSP(); + + end = I_FloatTime(); + Log_Print("%5.0f seconds elapsed\n", end-start); +} //end of the function Win_Map2Bsp +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void Map2Bsp(char *mapfilename, char *outputfilename) +{ + double start, end; + char path[1024]; + + start = I_FloatTime (); + + ThreadSetDefault (); + //yeah sure Carmack + //numthreads = 1; //multiple threads aren't helping... + //SetQdirFromPath(bspfilename); + + strcpy(source, ExpandArg(mapfilename)); + StripExtension(source); + + // delete portal and line files + sprintf(path, "%s.prt", source); + remove(path); + sprintf(path, "%s.lin", source); + remove(path); + + strcpy(name, ExpandArg(mapfilename)); + DefaultExtension(name, ".map"); // might be .reg + + // + // if onlyents, just grab the entites and resave + // + if (onlyents) + { + char out[1024]; + + Q2_AllocMaxBSP(); + sprintf (out, "%s.bsp", source); + Q2_LoadBSPFile(out, 0, 0); + num_entities = 0; + + Q2_LoadMapFile(name); + SetModelNumbers(); + SetLightStyles(); + + Q2_UnparseEntities(); + + Q2_WriteBSPFile(out); + // + Q2_FreeMaxBSP(); + } //end if + else + { + // + // start from scratch + // + Q2_AllocMaxBSP(); + //load the map + Q2_LoadMapFile(name); + //create the .bsp file + SetModelNumbers(); + SetLightStyles(); + ProcessModels(); + //write the BSP + Q2_WriteBSPFile(outputfilename); + // + Q2_FreeMaxBSP(); + } //end else + + end = I_FloatTime(); + Log_Print("%5.0f seconds elapsed\n", end-start); +} //end of the function Map2Bsp +*/ +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AASOuputFile( quakefile_t *qf, char *outputpath, char *filename ) { + char ext[MAX_PATH]; + + // + if ( strlen( outputpath ) ) { + strcpy( filename, outputpath ); + //append the bsp file base + AppendPathSeperator( filename, MAX_PATH ); + ExtractFileBase( qf->origname, &filename[strlen( filename )] ); + + // Ridah, add extension + strcat( filename, aas_extension ); + // done. + + //append .aas + strcat( filename, ".aas" ); + return; + } //end if + // + ExtractFileExtension( qf->filename, ext ); + if ( !stricmp( ext, "pk3" ) || !stricmp( ext, "pak" ) || !stricmp( ext, "sin" ) ) { + strcpy( filename, qf->filename ); + while ( strlen( filename ) && + filename[strlen( filename ) - 1] != '\\' && + filename[strlen( filename ) - 1] != '/' ) + { + filename[strlen( filename ) - 1] = '\0'; + } //end while + strcat( filename, "maps" ); + if ( access( filename, 0x04 ) ) { + CreatePath( filename ); + } + //append the bsp file base + AppendPathSeperator( filename, MAX_PATH ); + ExtractFileBase( qf->origname, &filename[strlen( filename )] ); + + // Ridah, add extension + strcat( filename, aas_extension ); + // done. + + //append .aas + strcat( filename, ".aas" ); + } //end if + else + { + strcpy( filename, qf->filename ); + while ( strlen( filename ) && + filename[strlen( filename ) - 1] != '.' ) + { + filename[strlen( filename ) - 1] = '\0'; + } //end while + + // Ridah, add extension + strcat( filename, aas_extension ); + // done. + + strcat( filename, "aas" ); + } //end else +} //end of the function AASOutputFile +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void CreateAASFilesForAllBSPFiles( char *quakepath ) { +#if defined( WIN32 ) | defined( _WIN32 ) + WIN32_FIND_DATA filedata; + HWND handle; + struct _stat statbuf; +#else + glob_t globbuf; + struct stat statbuf; + int j; +#endif + //int done; // TTimo: unused + char filter[_MAX_PATH], bspfilter[_MAX_PATH], aasfilter[_MAX_PATH]; + char aasfile[_MAX_PATH], buf[_MAX_PATH], foldername[_MAX_PATH]; + quakefile_t *qf, *qf2, *files, *bspfiles, *aasfiles; + + strcpy( filter, quakepath ); + AppendPathSeperator( filter, sizeof( filter ) ); + strcat( filter, "*" ); + +#if defined( WIN32 ) | defined( _WIN32 ) + handle = FindFirstFile( filter, &filedata ); + done = ( handle == INVALID_HANDLE_VALUE ); + while ( !done ) + { + _splitpath( filter, foldername, NULL, NULL, NULL ); + _splitpath( filter, NULL, &foldername[strlen( foldername )], NULL, NULL ); + AppendPathSeperator( foldername, _MAX_PATH ); + strcat( foldername, filedata.cFileName ); + _stat( foldername, &statbuf ); +#else + glob( filter, 0, NULL, &globbuf ); + for ( j = 0; j < globbuf.gl_pathc; j++ ) + { + strcpy( foldername, globbuf.gl_pathv[j] ); + stat( foldername, &statbuf ); +#endif + //if it is a folder + if ( statbuf.st_mode & S_IFDIR ) { + // + AppendPathSeperator( foldername, sizeof( foldername ) ); + //get all the bsp files + strcpy( bspfilter, foldername ); + strcat( bspfilter, "maps/*.bsp" ); + files = FindQuakeFiles( bspfilter ); + strcpy( bspfilter, foldername ); + strcat( bspfilter, "*.pk3/maps/*.bsp" ); + bspfiles = FindQuakeFiles( bspfilter ); + for ( qf = bspfiles; qf; qf = qf->next ) if ( !qf->next ) { + break; + } + if ( qf ) { + qf->next = files; + } else { bspfiles = files;} + //get all the aas files + strcpy( aasfilter, foldername ); + strcat( aasfilter, "maps/*.aas" ); + files = FindQuakeFiles( aasfilter ); + strcpy( aasfilter, foldername ); + strcat( aasfilter, "*.pk3/maps/*.aas" ); + aasfiles = FindQuakeFiles( aasfilter ); + for ( qf = aasfiles; qf; qf = qf->next ) if ( !qf->next ) { + break; + } + if ( qf ) { + qf->next = files; + } else { aasfiles = files;} + // + for ( qf = bspfiles; qf; qf = qf->next ) + { + sprintf( aasfile, "%s/%s", qf->pakfile, qf->origname ); + Log_Print( "found %s\n", aasfile ); + strcpy( &aasfile[strlen( aasfile ) - strlen( ".bsp" )], ".aas" ); + for ( qf2 = aasfiles; qf2; qf2 = qf2->next ) + { + sprintf( buf, "%s/%s", qf2->pakfile, qf2->origname ); + if ( !stricmp( aasfile, buf ) ) { + Log_Print( "found %s\n", buf ); + break; + } //end if + } //end for + } //end for + } //end if +#if defined( WIN32 ) | defined( _WIN32 ) + //find the next file + done = !FindNextFile( handle, &filedata ); + } //end while +#else + } //end for + globfree( &globbuf ); +#endif +} //end of the function CreateAASFilesForAllBSPFiles +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +quakefile_t *GetArgumentFiles( int argc, char *argv[], int *i, char *ext ) { + quakefile_t *qfiles, *lastqf, *qf; + int j; + char buf[1024]; + + qfiles = NULL; + lastqf = NULL; + for (; ( *i ) + 1 < argc && argv[( *i ) + 1][0] != '-'; ( *i )++ ) + { + strcpy( buf, argv[( *i ) + 1] ); + for ( j = strlen( buf ) - 1; j >= strlen( buf ) - 4; j-- ) + if ( buf[j] == '.' ) { + break; + } + if ( j >= strlen( buf ) - 4 ) { + strcpy( &buf[j + 1], ext ); + } + qf = FindQuakeFiles( buf ); + if ( !qf ) { + continue; + } + if ( lastqf ) { + lastqf->next = qf; + } else { qfiles = qf;} + lastqf = qf; + while ( lastqf->next ) lastqf = lastqf->next; + } //end for + return qfiles; +} //end of the function GetArgumentFiles +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== + +#define COMP_BSP2MAP 1 +#define COMP_BSP2AAS 2 +#define COMP_REACH 3 +#define COMP_CLUSTER 4 +#define COMP_AASOPTIMIZE 5 +#define COMP_AASINFO 6 +#define COMP_TETRA 7 + +//#define GTKRADIANT + +#ifdef GTKRADIANT +// TTimo: comment this out and use a bogus RADIANT_VERSION if necessary +#include "include/version.h" +#endif + +int main( int argc, char **argv ) { + int i, comp = 0; + char outputpath[MAX_PATH] = ""; + char filename[MAX_PATH] = "unknown"; + quakefile_t *qfiles = NULL, *qf; // TTimo: init + + // Ridah, allow to specify an extension for multiple AAS files per map + int has_ext = 0; + // done. + + // Ridah, set the world pointer up for reachabilities + aasworld = aasworlds; + AAS_SetWorldPointer( &( *aasworld ) ); + // done. + + myargc = argc; + myargv = argv; + + Log_Open( "bspc.log" ); //open a log file + #ifdef GTKRADIANT + Log_Print( "BSPC version " BSPC_VERSION " by Mr Elusive\n" ); + Log_Print( "GtkRadiant " RADIANT_VERSION " %s\n", __DATE__ ); + #else + Log_Print( "BSPC version " BSPC_VERSION ", %s %s by Mr Elusive\n", __DATE__, __TIME__ ); + #endif + + DefaultCfg(); + for ( i = 1; i < argc; i++ ) + { + if ( !stricmp( argv[i],"-threads" ) ) { + if ( i + 1 >= argc ) { + i = 0; break; + } + numthreads = atoi( argv[++i] ); + Log_Print( "threads = %d\n", numthreads ); + } //end if + else if ( !stricmp( argv[i], "-noverbose" ) ) { + Log_Print( "verbose = false\n" ); + verbose = false; + } //end else if + else if ( !stricmp( argv[i], "-nocsg" ) ) { + Log_Print( "nocsg = true\n" ); + nocsg = true; + } //end else if + else if ( !stricmp( argv[i], "-optimize" ) ) { + Log_Print( "optimize = true\n" ); + optimize = true; + } //end else if + /* + else if (!stricmp(argv[i],"-glview")) + { + glview = true; + } //end else if + else if (!stricmp(argv[i], "-draw")) + { + Log_Print("drawflag = true\n"); + drawflag = true; + } //end else if + else if (!stricmp(argv[i], "-noweld")) + { + Log_Print("noweld = true\n"); + noweld = true; + } //end else if + else if (!stricmp(argv[i], "-noshare")) + { + Log_Print("noshare = true\n"); + noshare = true; + } //end else if + else if (!stricmp(argv[i], "-notjunc")) + { + Log_Print("notjunc = true\n"); + notjunc = true; + } //end else if + else if (!stricmp(argv[i], "-nowater")) + { + Log_Print("nowater = true\n"); + nowater = true; + } //end else if + else if (!stricmp(argv[i], "-noprune")) + { + Log_Print("noprune = true\n"); + noprune = true; + } //end else if + else if (!stricmp(argv[i], "-nomerge")) + { + Log_Print("nomerge = true\n"); + nomerge = true; + } //end else if + else if (!stricmp(argv[i], "-nosubdiv")) + { + Log_Print("nosubdiv = true\n"); + nosubdiv = true; + } //end else if + else if (!stricmp(argv[i], "-nodetail")) + { + Log_Print("nodetail = true\n"); + nodetail = true; + } //end else if + else if (!stricmp(argv[i], "-fulldetail")) + { + Log_Print("fulldetail = true\n"); + fulldetail = true; + } //end else if + else if (!stricmp(argv[i], "-onlyents")) + { + Log_Print("onlyents = true\n"); + onlyents = true; + } //end else if + else if (!stricmp(argv[i], "-micro")) + { + if (i + 1 >= argc) {i = 0; break;} + microvolume = atof(argv[++i]); + Log_Print("microvolume = %f\n", microvolume); + } //end else if + else if (!stricmp(argv[i], "-leaktest")) + { + Log_Print("leaktest = true\n"); + leaktest = true; + } //end else if + else if (!stricmp(argv[i], "-verboseentities")) + { + Log_Print("verboseentities = true\n"); + verboseentities = true; + } //end else if + else if (!stricmp(argv[i], "-chop")) + { + if (i + 1 >= argc) {i = 0; break;} + subdivide_size = atof(argv[++i]); + Log_Print("subdivide_size = %f\n", subdivide_size); + } //end else if + else if (!stricmp (argv[i], "-tmpout")) + { + strcpy (outbase, "/tmp"); + Log_Print("temp output\n"); + } //end else if + */ +#ifdef ME + else if ( !stricmp( argv[i], "-freetree" ) ) { + freetree = true; + Log_Print( "freetree = true\n" ); + } //end else if + else if ( !stricmp( argv[i], "-grapplereach" ) ) { + calcgrapplereach = true; + Log_Print( "grapplereach = true\n" ); + } //end else if + else if ( !stricmp( argv[i], "-nobrushmerge" ) ) { + nobrushmerge = true; + Log_Print( "nobrushmerge = true\n" ); + } //end else if + else if ( !stricmp( argv[i], "-noliquids" ) ) { + noliquids = true; + Log_Print( "noliquids = true\n" ); + } //end else if + else if ( !stricmp( argv[i], "-forcesidesvisible" ) ) { + forcesidesvisible = true; + Log_Print( "forcesidesvisible = true\n" ); + } //end else if + else if ( !stricmp( argv[i], "-output" ) ) { + if ( i + 1 >= argc ) { + i = 0; break; + } + if ( access( argv[i + 1], 0x04 ) ) { + Warning( "the folder %s does not exist", argv[i + 1] ); + } + strcpy( outputpath, argv[++i] ); + } //end else if + else if ( !stricmp( argv[i], "-breadthfirst" ) ) { + use_nodequeue = true; + Log_Print( "breadthfirst = true\n" ); + } //end else if + else if ( !stricmp( argv[i], "-cfg" ) ) { + if ( i + 1 >= argc ) { + i = 0; break; + } + if ( !LoadCfgFile( argv[++i] ) ) { + exit( 0 ); + } + } //end else if + else if ( !stricmp( argv[i], "-bsp2map" ) ) { + if ( i + 1 >= argc ) { + i = 0; break; + } + comp = COMP_BSP2MAP; + qfiles = GetArgumentFiles( argc, argv, &i, "bsp" ); + } //end else if + else if ( !stricmp( argv[i], "-bsp2aas" ) ) { + if ( i + 1 >= argc ) { + i = 0; break; + } + comp = COMP_BSP2AAS; + qfiles = GetArgumentFiles( argc, argv, &i, "bsp" ); + } //end else if + else if ( !stricmp( argv[i], "-aasall" ) ) { + if ( i + 1 >= argc ) { + i = 0; break; + } + CreateAASFilesForAllBSPFiles( argv[++i] ); + } //end else if + else if ( !stricmp( argv[i], "-reach" ) ) { + if ( i + 1 >= argc ) { + i = 0; break; + } + comp = COMP_REACH; + qfiles = GetArgumentFiles( argc, argv, &i, "bsp" ); + } //end else if + else if ( !stricmp( argv[i], "-cluster" ) ) { + if ( i + 1 >= argc ) { + i = 0; break; + } + comp = COMP_CLUSTER; + qfiles = GetArgumentFiles( argc, argv, &i, "bsp" ); + } //end else if + else if ( !stricmp( argv[i], "-aasinfo" ) ) { + if ( i + 1 >= argc ) { + i = 0; break; + } + comp = COMP_AASINFO; + qfiles = GetArgumentFiles( argc, argv, &i, "aas" ); + } //end else if + else if ( !stricmp( argv[i], "-aasopt" ) ) { + if ( i + 1 >= argc ) { + i = 0; break; + } + comp = COMP_AASOPTIMIZE; + qfiles = GetArgumentFiles( argc, argv, &i, "aas" ); + } //end else if + else if ( !stricmp( argv[i], "-tetra" ) ) { + if ( i + 1 >= argc ) { + i = 0; break; + } + comp = COMP_TETRA; + qfiles = GetArgumentFiles( argc, argv, &i, "aas" ); + } //end else if + else if ( !stricmp( argv[i], "-writeaasmap" ) ) { + writeaasmap = true; + Log_Print( "writeaasmap = true\n" ); + } + // Ridah, allow to specify an extension for multiple AAS files per map + else if ( !stricmp( argv[i], "-ext" ) ) { + if ( i + 1 >= argc ) { + i = 0; break; + } + strcpy( aas_extension, argv[++i] ); + has_ext = 1; + + } //end else if + // done. + +#endif //ME + else + { + Log_Print( "unknown parameter %s\n", argv[i] ); + break; + } //end else + } //end for + + //if there are parameters and there's no mismatch in one of the parameters + if ( argc > 1 && i == argc ) { + switch ( comp ) + { + case COMP_BSP2MAP: + { + if ( !qfiles ) { + Log_Print( "no files found\n" ); + } + for ( qf = qfiles; qf; qf = qf->next ) + { + //copy the output path + strcpy( filename, outputpath ); + //append the bsp file base + AppendPathSeperator( filename, MAX_PATH ); + ExtractFileBase( qf->origname, &filename[strlen( filename )] ); + //append .map + strcat( filename, ".map" ); + // + Log_Print( "bsp2map: %s to %s\n", qf->origname, filename ); + if ( qf->type != QFILETYPE_BSP ) { + Warning( "%s is probably not a BSP file\n", qf->origname ); + } + // + LoadMapFromBSP( qf ); + //write the map file + WriteMapFile( filename ); + } //end for + break; + } //end case + case COMP_BSP2AAS: + { + if ( !qfiles ) { + Log_Print( "no files found\n" ); + } + for ( qf = qfiles; qf; qf = qf->next ) + { + AASOuputFile( qf, outputpath, filename ); + // + Log_Print( "bsp2aas: %s to %s\n", qf->origname, filename ); + if ( qf->type != QFILETYPE_BSP ) { + Warning( "%s is probably not a BSP file\n", qf->origname ); + } + //set before map loading + create_aas = 1; + LoadMapFromBSP( qf ); + //create the AAS file + AAS_Create( filename ); + //if it's a Quake3 map calculate the reachabilities and clusters + if ( loadedmaptype == MAPTYPE_QUAKE3 ) { + AAS_CalcReachAndClusters( qf ); + } + // + if ( optimize ) { + AAS_Optimize(); + } + // + //write out the stored AAS file + if ( !AAS_WriteAASFile( filename ) ) { + Error( "error writing %s\n", filename ); + } //end if + //deallocate memory + AAS_FreeMaxAAS(); + } //end for + break; + } //end case + case COMP_REACH: + { + if ( !qfiles ) { + Log_Print( "no files found\n" ); + } + for ( qf = qfiles; qf; qf = qf->next ) + { + AASOuputFile( qf, outputpath, filename ); + // + Log_Print( "reach: %s to %s\n", qf->origname, filename ); + if ( qf->type != QFILETYPE_BSP ) { + Warning( "%s is probably not a BSP file\n", qf->origname ); + } + //if the AAS file exists in the output directory + if ( !access( filename, 0x04 ) ) { + if ( !AAS_LoadAASFile( filename, 0, 0 ) ) { + Error( "error loading aas file %s\n", filename ); + } //end if + //assume it's a Quake3 BSP file + loadedmaptype = MAPTYPE_QUAKE3; + } //end if + else + { + Warning( "AAS file %s not found in output folder\n", filename ); + Log_Print( "creating %s...\n", filename ); + //set before map loading + create_aas = 1; + LoadMapFromBSP( qf ); + //create the AAS file + AAS_Create( filename ); + } //end else + //if it's a Quake3 map calculate the reachabilities and clusters + if ( loadedmaptype == MAPTYPE_QUAKE3 ) { + AAS_CalcReachAndClusters( qf ); + } //end if + // + if ( optimize ) { + AAS_Optimize(); + } + //write out the stored AAS file + if ( !AAS_WriteAASFile( filename ) ) { + Error( "error writing %s\n", filename ); + } //end if + //deallocate memory + AAS_FreeMaxAAS(); + } //end for + break; + } //end case + case COMP_CLUSTER: + { + if ( !qfiles ) { + Log_Print( "no files found\n" ); + } + for ( qf = qfiles; qf; qf = qf->next ) + { + AASOuputFile( qf, outputpath, filename ); + // + Log_Print( "cluster: %s to %s\n", qf->origname, filename ); + if ( qf->type != QFILETYPE_BSP ) { + Warning( "%s is probably not a BSP file\n", qf->origname ); + } + //if the AAS file exists in the output directory + if ( !access( filename, 0x04 ) ) { + if ( !AAS_LoadAASFile( filename, 0, 0 ) ) { + Error( "error loading aas file %s\n", filename ); + } //end if + //assume it's a Quake3 BSP file + loadedmaptype = MAPTYPE_QUAKE3; + //if it's a Quake3 map calculate the clusters + if ( loadedmaptype == MAPTYPE_QUAKE3 ) { + ( *aasworld ).numclusters = 0; + AAS_InitBotImport(); + AAS_InitClustering(); + } //end if + } //end if + else + { + Warning( "AAS file %s not found in output folder\n", filename ); + Log_Print( "creating %s...\n", filename ); + //set before map loading + create_aas = 1; + LoadMapFromBSP( qf ); + //create the AAS file + AAS_Create( filename ); + //if it's a Quake3 map calculate the reachabilities and clusters + if ( loadedmaptype == MAPTYPE_QUAKE3 ) { + AAS_CalcReachAndClusters( qf ); + } + } //end else + // + if ( optimize ) { + AAS_Optimize(); + } + //write out the stored AAS file + if ( !AAS_WriteAASFile( filename ) ) { + Error( "error writing %s\n", filename ); + } //end if + //deallocate memory + AAS_FreeMaxAAS(); + } //end for + break; + } //end case + case COMP_AASOPTIMIZE: + { + if ( !qfiles ) { + Log_Print( "no files found\n" ); + } + for ( qf = qfiles; qf; qf = qf->next ) + { + AASOuputFile( qf, outputpath, filename ); + // + Log_Print( "optimizing: %s to %s\n", qf->origname, filename ); + if ( qf->type != QFILETYPE_AAS ) { + Warning( "%s is probably not a AAS file\n", qf->origname ); + } + // + AAS_InitBotImport(); + // + if ( !AAS_LoadAASFile( qf->filename, qf->offset, qf->length ) ) { + Error( "error loading aas file %s\n", qf->filename ); + } //end if + AAS_Optimize(); + //write out the stored AAS file + if ( !AAS_WriteAASFile( filename ) ) { + Error( "error writing %s\n", filename ); + } //end if + //deallocate memory + AAS_FreeMaxAAS(); + } //end for + break; + } //end case + case COMP_AASINFO: + { + if ( !qfiles ) { + Log_Print( "no files found\n" ); + } + for ( qf = qfiles; qf; qf = qf->next ) + { + AASOuputFile( qf, outputpath, filename ); + // + Log_Print( "aas info for: %s\n", filename ); + if ( qf->type != QFILETYPE_AAS ) { + Warning( "%s is probably not a AAS file\n", qf->origname ); + } + // + AAS_InitBotImport(); + // + if ( !AAS_LoadAASFile( qf->filename, qf->offset, qf->length ) ) { + Error( "error loading aas file %s\n", qf->filename ); + } //end if + AAS_ShowTotals(); + } //end for + } //end case + case COMP_TETRA: + { + if ( !qfiles ) { + Log_Print( "no files found\n" ); + } + for ( qf = qfiles; qf; qf = qf->next ) + { + //TH_AASToTetrahedrons(qf->filename); + } //end for + break; + } //end case + default: + { + Log_Print( "don't know what to do\n" ); + break; + } //end default + } //end switch + } //end if + else + { + Log_Print( "Usage: bspc [- [- ...]]\n" +#if defined( WIN32 ) || defined( _WIN32 ) + "Example 1: bspc -bsp2aas d:\\quake3\\baseq3\\maps\\mymap?.bsp\n" + "Example 2: bspc -bsp2aas d:\\quake3\\baseq3\\pak0.pk3\\maps/q3dm*.bsp\n" +#else + "Example 1: bspc -bsp2aas /quake3/baseq3/maps/mymap?.bsp\n" + "Example 2: bspc -bsp2aas /quake3/baseq3/pak0.pk3/maps/q3dm*.bsp\n" +#endif + "\n" + "Switches:\n" + //" bsp2map <[pakfilter/]filter.bsp> = convert BSP to MAP\n" + " bsp2aas <[pakfilter/]filter.bsp> = convert BSP to AAS\n" + //" aasall = create AAS files for all BSPs\n" + " reach = compute reachability & clusters\n" + " cluster = compute clusters\n" + " aasopt = optimize aas file\n" + //" tetra = tetrahedral decomposition\n" + " output = set output path\n" + " threads = set number of threads to X\n" + " cfg = use this cfg file\n" + " optimize = enable optimization\n" + " noverbose = disable verbose output\n" + " breadthfirst = breadth first bsp building\n" + " nobrushmerge = don't merge brushes\n" + " noliquids = don't write liquids to map\n" + " freetree = free the bsp tree\n" + " nocsg = disables brush chopping\n" + " forcesidesvisible = force all sides to be visible\n" + " grapplereach = calculate grapple reachabilities\n" + " writeaasmap = write the map the AI sees\n" + +/* " glview = output a GL view\n" + " draw = enables drawing\n" + " noweld = disables weld\n" + " noshare = disables sharing\n" + " notjunc = disables juncs\n" + " nowater = disables water brushes\n" + " noprune = disables node prunes\n" + " nomerge = disables face merging\n" + " nosubdiv = disables subdeviding\n" + " nodetail = disables detail brushes\n" + " fulldetail = enables full detail\n" + " onlyents = only compile entities with bsp\n" + " micro \n" + " = sets the micro volume to the given float\n" + " leaktest = perform a leak test\n" + " verboseentities\n" + " = enable entity verbose mode\n" + " chop \n" + " = sets the subdivide size to the given float\n"*/ + "\n" ); + } //end else + Log_Close(); //close the log file + return 0; +} //end of the function main + + diff --git a/Projects/Android/jni/rtcw/src/bspc/csg.c b/Projects/Android/jni/rtcw/src/bspc/csg.c new file mode 100644 index 0000000..c3256cc --- /dev/null +++ b/Projects/Android/jni/rtcw/src/bspc/csg.c @@ -0,0 +1,1053 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +//=========================================================================== +// +// Name: Brush CSG +// Function: +// Programmer(s): id Software & Mr Elusive (MrElusive@demigod.demon.nl) +// Last update: 1997-12-04 +// Tab Size: 3 +// Notes: Microsoft Visual C++ optimizations: +// "global optimization" or "full optimization" results +// in micro brushes?? +//=========================================================================== + +#include "qbsp.h" + +/* + +tag all brushes with original contents +brushes may contain multiple contents +there will be no brush overlap after csg phase + +*/ + +int minplanenums[3]; +int maxplanenums[3]; + +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void CheckBSPBrush( bspbrush_t *brush ) { + int i, j; + plane_t *plane1, *plane2; + + //check if the brush is convex... flipped planes make a brush non-convex + for ( i = 0; i < brush->numsides; i++ ) + { + for ( j = 0; j < brush->numsides; j++ ) + { + if ( i == j ) { + continue; + } + plane1 = &mapplanes[brush->sides[i].planenum]; + plane2 = &mapplanes[brush->sides[j].planenum]; + // + if ( WindingsNonConvex( brush->sides[i].winding, + brush->sides[j].winding, + plane1->normal, plane2->normal, + plane1->dist, plane2->dist ) ) { + Log_Print( "non convex brush" ); + break; + } //end if + } //end for + } //end for + BoundBrush( brush ); + //check for out of bound brushes + for ( i = 0; i < 3; i++ ) + { + if ( brush->mins[i] < -MAX_MAP_BOUNDS || brush->maxs[i] > MAX_MAP_BOUNDS ) { + Log_Print( "brush: bounds out of range\n" ); + Log_Print( "ob->mins[%d] = %f, ob->maxs[%d] = %f\n", i, brush->mins[i], i, brush->maxs[i] ); + break; + } //end if + if ( brush->mins[i] > MAX_MAP_BOUNDS || brush->maxs[i] < -MAX_MAP_BOUNDS ) { + Log_Print( "brush: no visible sides on brush\n" ); + Log_Print( "ob->mins[%d] = %f, ob->maxs[%d] = %f\n", i, brush->mins[i], i, brush->maxs[i] ); + break; + } //end if + } //end for +} //end of the function CheckBSPBrush +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void BSPBrushWindings( bspbrush_t *brush ) { + int i, j; + winding_t *w; + plane_t *plane; + + for ( i = 0; i < brush->numsides; i++ ) + { + plane = &mapplanes[brush->sides[i].planenum]; + w = BaseWindingForPlane( plane->normal, plane->dist ); + for ( j = 0; j < brush->numsides && w; j++ ) + { + if ( i == j ) { + continue; + } + plane = &mapplanes[brush->sides[j].planenum ^ 1]; + ChopWindingInPlace( &w, plane->normal, plane->dist, 0 ); //CLIP_EPSILON); + } //end for + brush->sides[i].winding = w; + } //end for +} //end of the function BSPBrushWindings +//=========================================================================== +// NOTE: can't keep brush->original intact +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +bspbrush_t *TryMergeBrushes( bspbrush_t *brush1, bspbrush_t *brush2 ) { + int i, j, k, n, shared; + side_t *side1, *side2, *cs; + plane_t *plane1, *plane2; + bspbrush_t *newbrush; + + //check for bounding box overlapp + for ( i = 0; i < 3; i++ ) + { + if ( brush1->mins[i] > brush2->maxs[i] + 2 + || brush1->maxs[i] < brush2->mins[i] - 2 ) { + return NULL; + } //end if + } //end for + // + shared = 0; + //check if the brush is convex... flipped planes make a brush non-convex + for ( i = 0; i < brush1->numsides; i++ ) + { + side1 = &brush1->sides[i]; + //don't check the "shared" sides + for ( k = 0; k < brush2->numsides; k++ ) + { + side2 = &brush2->sides[k]; + if ( side1->planenum == ( side2->planenum ^ 1 ) ) { + shared++; + //there may only be ONE shared side + if ( shared > 1 ) { + return NULL; + } + break; + } //end if + } //end for + if ( k < brush2->numsides ) { + continue; + } + // + for ( j = 0; j < brush2->numsides; j++ ) + { + side2 = &brush2->sides[j]; + //don't check the "shared" sides + for ( n = 0; n < brush1->numsides; n++ ) + { + side1 = &brush1->sides[n]; + if ( side1->planenum == ( side2->planenum ^ 1 ) ) { + break; + } + } //end for + if ( n < brush1->numsides ) { + continue; + } + // + side1 = &brush1->sides[i]; + //if the side is in the same plane + //* + if ( side1->planenum == side2->planenum ) { + if ( side1->texinfo != TEXINFO_NODE && + side2->texinfo != TEXINFO_NODE && + side1->texinfo != side2->texinfo ) { + return NULL; + } + continue; + } //end if + // + plane1 = &mapplanes[side1->planenum]; + plane2 = &mapplanes[side2->planenum]; + // + if ( WindingsNonConvex( side1->winding, side2->winding, + plane1->normal, plane2->normal, + plane1->dist, plane2->dist ) ) { + return NULL; + } //end if + } //end for + } //end for + newbrush = AllocBrush( brush1->numsides + brush2->numsides ); + newbrush->original = brush1->original; + newbrush->numsides = 0; + //newbrush->side = brush1->side; //brush contents + //fix texinfos for sides lying in the same plane + for ( i = 0; i < brush1->numsides; i++ ) + { + side1 = &brush1->sides[i]; + // + for ( n = 0; n < brush2->numsides; n++ ) + { + side2 = &brush2->sides[n]; + //if both sides are in the same plane get the texinfo right + if ( side1->planenum == side2->planenum ) { + if ( side1->texinfo == TEXINFO_NODE ) { + side1->texinfo = side2->texinfo; + } + if ( side2->texinfo == TEXINFO_NODE ) { + side2->texinfo = side1->texinfo; + } + } //end if + } //end for + } //end for + // + for ( i = 0; i < brush1->numsides; i++ ) + { + side1 = &brush1->sides[i]; + //don't add the "shared" sides + for ( n = 0; n < brush2->numsides; n++ ) + { + side2 = &brush2->sides[n]; + if ( side1->planenum == ( side2->planenum ^ 1 ) ) { + break; + } + } //end for + if ( n < brush2->numsides ) { + continue; + } + // + for ( n = 0; n < newbrush->numsides; n++ ) + { + cs = &newbrush->sides[n]; + if ( cs->planenum == side1->planenum ) { + Log_Print( "brush duplicate plane\n" ); + break; + } //end if + } //end if + if ( n < newbrush->numsides ) { + continue; + } + //add this side + cs = &newbrush->sides[newbrush->numsides]; + newbrush->numsides++; + *cs = *side1; + } //end for + for ( j = 0; j < brush2->numsides; j++ ) + { + side2 = &brush2->sides[j]; + for ( n = 0; n < brush1->numsides; n++ ) + { + side1 = &brush1->sides[n]; + //if the side is in the same plane + if ( side2->planenum == side1->planenum ) { + break; + } + //don't add the "shared" sides + if ( side2->planenum == ( side1->planenum ^ 1 ) ) { + break; + } + } //end for + if ( n < brush1->numsides ) { + continue; + } + // + for ( n = 0; n < newbrush->numsides; n++ ) + { + cs = &newbrush->sides[n]; + if ( cs->planenum == side2->planenum ) { + Log_Print( "brush duplicate plane\n" ); + break; + } //end if + } //end if + if ( n < newbrush->numsides ) { + continue; + } + //add this side + cs = &newbrush->sides[newbrush->numsides]; + newbrush->numsides++; + *cs = *side2; + } //end for + BSPBrushWindings( newbrush ); + BoundBrush( newbrush ); + CheckBSPBrush( newbrush ); + return newbrush; +} //end of the function TryMergeBrushes +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +bspbrush_t *MergeBrushes( bspbrush_t *brushlist ) { + int nummerges, merged; + bspbrush_t *b1, *b2, *tail, *newbrush, *newbrushlist; + bspbrush_t *lastb2; + + if ( !brushlist ) { + return NULL; + } + + qprintf( "%5d brushes merged", nummerges = 0 ); + do + { + for ( tail = brushlist; tail; tail = tail->next ) + { + if ( !tail->next ) { + break; + } + } //end for + merged = 0; + newbrushlist = NULL; + for ( b1 = brushlist; b1; b1 = brushlist ) + { + lastb2 = b1; + for ( b2 = b1->next; b2; b2 = b2->next ) + { + //if the brushes don't have the same contents + if ( b1->original->contents != b2->original->contents || + b1->original->expansionbbox != b2->original->expansionbbox ) { + newbrush = NULL; + } else { newbrush = TryMergeBrushes( b1, b2 );} + if ( newbrush ) { + tail->next = newbrush; + lastb2->next = b2->next; + brushlist = brushlist->next; + FreeBrush( b1 ); + FreeBrush( b2 ); + for ( tail = brushlist; tail; tail = tail->next ) + { + if ( !tail->next ) { + break; + } + } //end for + merged++; + qprintf( "\r%5d", nummerges++ ); + break; + } //end if + lastb2 = b2; + } //end for + //if b1 can't be merged with any of the other brushes + if ( !b2 ) { + brushlist = brushlist->next; + //keep b1 + b1->next = newbrushlist; + newbrushlist = b1; + } //end else + } //end for + brushlist = newbrushlist; + } while ( merged ); + qprintf( "\n" ); + return newbrushlist; +} //end of the function MergeBrushes +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void SplitBrush2( bspbrush_t *brush, int planenum, + bspbrush_t **front, bspbrush_t **back ) { + SplitBrush( brush, planenum, front, back ); +#if 0 + if ( *front && ( *front )->sides[( *front )->numsides - 1].texinfo == -1 ) { + ( *front )->sides[( *front )->numsides - 1].texinfo = ( *front )->sides[0].texinfo; // not -1 + } + if ( *back && ( *back )->sides[( *back )->numsides - 1].texinfo == -1 ) { + ( *back )->sides[( *back )->numsides - 1].texinfo = ( *back )->sides[0].texinfo; // not -1 + } +#endif +} //end of the function SplitBrush2 +//=========================================================================== +// Returns a list of brushes that remain after B is subtracted from A. +// May by empty if A is contained inside B. +// The originals are undisturbed. +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +bspbrush_t *SubtractBrush( bspbrush_t *a, bspbrush_t *b ) { // a - b = out (list) + int i; + bspbrush_t *front, *back; + bspbrush_t *out, *in; + + in = a; + out = NULL; + for ( i = 0; i < b->numsides && in; i++ ) + { + SplitBrush2( in, b->sides[i].planenum, &front, &back ); + if ( in != a ) { + FreeBrush( in ); + } + if ( front ) { // add to list + front->next = out; + out = front; + } //end if + in = back; + } //end for + if ( in ) { + FreeBrush( in ); + } //end if + else + { // didn't really intersect + FreeBrushList( out ); + return a; + } //end else + return out; +} //end of the function SubtractBrush +//=========================================================================== +// Returns a single brush made up by the intersection of the +// two provided brushes, or NULL if they are disjoint. +// +// The originals are undisturbed. +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +bspbrush_t *IntersectBrush( bspbrush_t *a, bspbrush_t *b ) { + int i; + bspbrush_t *front, *back; + bspbrush_t *in; + + in = a; + for ( i = 0 ; i < b->numsides && in ; i++ ) + { + SplitBrush2( in, b->sides[i].planenum, &front, &back ); + if ( in != a ) { + FreeBrush( in ); + } + if ( front ) { + FreeBrush( front ); + } + in = back; + } //end for + + if ( in == a ) { + return NULL; + } + + in->next = NULL; + return in; +} //end of the function IntersectBrush +//=========================================================================== +// Returns true if the two brushes definately do not intersect. +// There will be false negatives for some non-axial combinations. +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +qboolean BrushesDisjoint( bspbrush_t *a, bspbrush_t *b ) { + int i, j; + + // check bounding boxes + for ( i = 0 ; i < 3 ; i++ ) + if ( a->mins[i] >= b->maxs[i] + || a->maxs[i] <= b->mins[i] ) { + return true; + } // bounding boxes don't overlap + + // check for opposing planes + for ( i = 0 ; i < a->numsides ; i++ ) + { + for ( j = 0 ; j < b->numsides ; j++ ) + { + if ( a->sides[i].planenum == + ( b->sides[j].planenum ^ 1 ) ) { + return true; // opposite planes, so not touching + } + } + } + + return false; // might intersect +} //end of the function BrushesDisjoint +//=========================================================================== +// Returns a content word for the intersection of two brushes. +// Some combinations will generate a combination (water + clip), +// but most will be the stronger of the two contents. +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int IntersectionContents( int c1, int c2 ) { + int out; + + out = c1 | c2; + + if ( out & CONTENTS_SOLID ) { + out = CONTENTS_SOLID; + } + + return out; +} //end of the function IntersectionContents +//=========================================================================== +// Any planes shared with the box edge will be set to no texinfo +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +bspbrush_t *ClipBrushToBox( bspbrush_t *brush, vec3_t clipmins, vec3_t clipmaxs ) { + int i, j; + bspbrush_t *front, *back; + int p; + + for ( j = 0 ; j < 2 ; j++ ) + { + if ( brush->maxs[j] > clipmaxs[j] ) { + SplitBrush( brush, maxplanenums[j], &front, &back ); + if ( front ) { + FreeBrush( front ); + } + brush = back; + if ( !brush ) { + return NULL; + } + } + if ( brush->mins[j] < clipmins[j] ) { + SplitBrush( brush, minplanenums[j], &front, &back ); + if ( back ) { + FreeBrush( back ); + } + brush = front; + if ( !brush ) { + return NULL; + } + } + } + + // remove any colinear faces + + for ( i = 0 ; i < brush->numsides ; i++ ) + { + p = brush->sides[i].planenum & ~1; + if ( p == maxplanenums[0] || p == maxplanenums[1] + || p == minplanenums[0] || p == minplanenums[1] ) { + brush->sides[i].texinfo = TEXINFO_NODE; + brush->sides[i].flags &= ~SFL_VISIBLE; + } + } + return brush; +} //end of the function ClipBrushToBox +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +bspbrush_t *MakeBspBrushList( int startbrush, int endbrush, + vec3_t clipmins, vec3_t clipmaxs ) { + mapbrush_t *mb; + bspbrush_t *brushlist, *newbrush; + int i, j; + int c_faces; + int c_brushes; + int numsides; + int vis; + vec3_t normal; + float dist; + + for ( i = 0 ; i < 2 ; i++ ) + { + VectorClear( normal ); + normal[i] = 1; + dist = clipmaxs[i]; + maxplanenums[i] = FindFloatPlane( normal, dist ); + dist = clipmins[i]; + minplanenums[i] = FindFloatPlane( normal, dist ); + } + + brushlist = NULL; + c_faces = 0; + c_brushes = 0; + + for ( i = startbrush ; i < endbrush ; i++ ) + { + mb = &mapbrushes[i]; + + numsides = mb->numsides; + if ( !numsides ) { + continue; + } + + // make sure the brush has at least one face showing + vis = 0; + for ( j = 0 ; j < numsides ; j++ ) + if ( ( mb->original_sides[j].flags & SFL_VISIBLE ) && mb->original_sides[j].winding ) { + vis++; + } +#if 0 + if ( !vis ) { + continue; // no faces at all + } +#endif + // if the brush is outside the clip area, skip it + for ( j = 0 ; j < 3 ; j++ ) + if ( mb->mins[j] >= clipmaxs[j] + || mb->maxs[j] <= clipmins[j] ) { + break; + } + if ( j != 3 ) { + continue; + } + + // + // make a copy of the brush + // + newbrush = AllocBrush( mb->numsides ); + newbrush->original = mb; + newbrush->numsides = mb->numsides; + memcpy( newbrush->sides, mb->original_sides, numsides * sizeof( side_t ) ); + for ( j = 0 ; j < numsides ; j++ ) + { + if ( newbrush->sides[j].winding ) { + newbrush->sides[j].winding = CopyWinding( newbrush->sides[j].winding ); + } + if ( newbrush->sides[j].surf & SURF_HINT ) { + newbrush->sides[j].flags |= SFL_VISIBLE; // hints are always visible + } + } + VectorCopy( mb->mins, newbrush->mins ); + VectorCopy( mb->maxs, newbrush->maxs ); + + // + // carve off anything outside the clip box + // + newbrush = ClipBrushToBox( newbrush, clipmins, clipmaxs ); + if ( !newbrush ) { + continue; + } + + c_faces += vis; + c_brushes++; + + newbrush->next = brushlist; + brushlist = newbrush; + } + + return brushlist; +} //end of the function MakeBspBrushList +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +bspbrush_t *AddBrushListToTail( bspbrush_t *list, bspbrush_t *tail ) { + bspbrush_t *walk, *next; + + for ( walk = list ; walk ; walk = next ) + { // add to end of list + next = walk->next; + walk->next = NULL; + tail->next = walk; + tail = walk; + } //end for + return tail; +} //end of the function AddBrushListToTail +//=========================================================================== +// Builds a new list that doesn't hold the given brush +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +bspbrush_t *CullList( bspbrush_t *list, bspbrush_t *skip1 ) { + bspbrush_t *newlist; + bspbrush_t *next; + + newlist = NULL; + + for ( ; list ; list = next ) + { + next = list->next; + if ( list == skip1 ) { + FreeBrush( list ); + continue; + } + list->next = newlist; + newlist = list; + } + return newlist; +} //end of the function CullList +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +/* +void WriteBrushMap(char *name, bspbrush_t *list) +{ + FILE *f; + side_t *s; + int i; + winding_t *w; + + Log_Print("writing %s\n", name); + f = fopen (name, "wb"); + if (!f) + Error ("Can't write %s\b", name); + + fprintf (f, "{\n\"classname\" \"worldspawn\"\n"); + + for ( ; list ; list=list->next ) + { + fprintf (f, "{\n"); + for (i=0,s=list->sides ; inumsides ; i++,s++) + { + w = BaseWindingForPlane (mapplanes[s->planenum].normal, mapplanes[s->planenum].dist); + + fprintf (f,"( %i %i %i ) ", (int)w->p[0][0], (int)w->p[0][1], (int)w->p[0][2]); + fprintf (f,"( %i %i %i ) ", (int)w->p[1][0], (int)w->p[1][1], (int)w->p[1][2]); + fprintf (f,"( %i %i %i ) ", (int)w->p[2][0], (int)w->p[2][1], (int)w->p[2][2]); + + fprintf (f, "%s 0 0 0 1 1\n", texinfo[s->texinfo].texture); + FreeWinding (w); + } + fprintf (f, "}\n"); + } + fprintf (f, "}\n"); + + fclose (f); +} //end of the function WriteBrushMap +*/ +//=========================================================================== +// Returns true if b1 is allowed to bite b2 +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +qboolean BrushGE( bspbrush_t *b1, bspbrush_t *b2 ) { +#ifdef ME + if ( create_aas ) { + if ( b1->original->expansionbbox != b2->original->expansionbbox ) { + return false; + } //end if + //never have something else bite a ladder brush + //never have a ladder brush bite something else + if ( ( b1->original->contents & CONTENTS_LADDER ) + && !( b2->original->contents & CONTENTS_LADDER ) ) { + return false; + } //end if + } //end if +#endif //ME + // detail brushes never bite structural brushes + if ( ( b1->original->contents & CONTENTS_DETAIL ) + && !( b2->original->contents & CONTENTS_DETAIL ) ) { + return false; + } //end if + if ( b1->original->contents & CONTENTS_SOLID ) { + return true; + } //end if + return false; +} //end of the function BrushGE +//=========================================================================== +// Carves any intersecting solid brushes into the minimum number +// of non-intersecting brushes. +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +bspbrush_t *ChopBrushes( bspbrush_t *head ) { + bspbrush_t *b1, *b2, *next; + bspbrush_t *tail; + bspbrush_t *keep; + bspbrush_t *sub, *sub2; + int c1, c2; + int num_csg_iterations; + + Log_Print( "-------- Brush CSG ---------\n" ); + Log_Print( "%6d original brushes\n", CountBrushList( head ) ); + + num_csg_iterations = 0; + qprintf( "%6d output brushes", num_csg_iterations ); + +#if 0 + if ( startbrush == 0 ) { + WriteBrushList( "before.gl", head, false ); + } +#endif + keep = NULL; + +newlist: + // find tail + if ( !head ) { + return NULL; + } + + for ( tail = head; tail->next; tail = tail->next ) + ; + + for ( b1 = head ; b1 ; b1 = next ) + { + next = b1->next; + + //if the conversion is cancelled + if ( cancelconversion ) { + b1->next = keep; + keep = b1; + continue; + } //end if + + for ( b2 = b1->next; b2; b2 = b2->next ) + { + if ( BrushesDisjoint( b1, b2 ) ) { + continue; + } + + sub = NULL; + sub2 = NULL; + c1 = 999999; + c2 = 999999; + + if ( BrushGE( b2, b1 ) ) { + sub = SubtractBrush( b1, b2 ); + if ( sub == b1 ) { + continue; // didn't really intersect + } //end if + if ( !sub ) { // b1 is swallowed by b2 + head = CullList( b1, b1 ); + goto newlist; + } + c1 = CountBrushList( sub ); + } + + if ( BrushGE( b1, b2 ) ) { + sub2 = SubtractBrush( b2, b1 ); + if ( sub2 == b2 ) { + continue; // didn't really intersect + } + if ( !sub2 ) { // b2 is swallowed by b1 + FreeBrushList( sub ); + head = CullList( b1, b2 ); + goto newlist; + } + c2 = CountBrushList( sub2 ); + } + + if ( !sub && !sub2 ) { + continue; // neither one can bite + + } + // only accept if it didn't fragment + // (commenting this out allows full fragmentation) + if ( c1 > 1 && c2 > 1 ) { + if ( sub2 ) { + FreeBrushList( sub2 ); + } + if ( sub ) { + FreeBrushList( sub ); + } + continue; + } + + if ( c1 < c2 ) { + if ( sub2 ) { + FreeBrushList( sub2 ); + } + tail = AddBrushListToTail( sub, tail ); + head = CullList( b1, b1 ); + goto newlist; + } //end if + else + { + if ( sub ) { + FreeBrushList( sub ); + } + tail = AddBrushListToTail( sub2, tail ); + head = CullList( b1, b2 ); + goto newlist; + } //end else + } //end for + + if ( !b2 ) { // b1 is no longer intersecting anything, so keep it + b1->next = keep; + keep = b1; + } //end if + num_csg_iterations++; + qprintf( "\r%6d", num_csg_iterations ); + } //end for + + if ( cancelconversion ) { + return keep; + } + // + qprintf( "\n" ); + Log_Write( "%6d output brushes\r\n", num_csg_iterations ); + +#if 0 + { + WriteBrushList( "after.gl", keep, false ); + WriteBrushMap( "after.map", keep ); + } +#endif + + return keep; +} //end of the function ChopBrushes +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +bspbrush_t *InitialBrushList( bspbrush_t *list ) { + bspbrush_t *b; + bspbrush_t *out, *newb; + int i; + + // only return brushes that have visible faces + out = NULL; + for ( b = list ; b ; b = b->next ) + { +#if 0 + for ( i = 0 ; i < b->numsides ; i++ ) + if ( b->sides[i].flags & SFL_VISIBLE ) { + break; + } + if ( i == b->numsides ) { + continue; + } +#endif + newb = CopyBrush( b ); + newb->next = out; + out = newb; + + // clear visible, so it must be set by MarkVisibleFaces_r + // to be used in the optimized list + for ( i = 0 ; i < b->numsides ; i++ ) + { + newb->sides[i].original = &b->sides[i]; +// newb->sides[i].visible = true; + b->sides[i].flags &= ~SFL_VISIBLE; + } + } + + return out; +} //end of the function InitialBrushList +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +bspbrush_t *OptimizedBrushList( bspbrush_t *list ) { + bspbrush_t *b; + bspbrush_t *out, *newb; + int i; + + // only return brushes that have visible faces + out = NULL; + for ( b = list ; b ; b = b->next ) + { + for ( i = 0 ; i < b->numsides ; i++ ) + if ( b->sides[i].flags & SFL_VISIBLE ) { + break; + } + if ( i == b->numsides ) { + continue; + } + newb = CopyBrush( b ); + newb->next = out; + out = newb; + } //end for + +// WriteBrushList ("vis.gl", out, true); + return out; +} //end of the function OptimizeBrushList +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +tree_t *ProcessWorldBrushes( int brush_start, int brush_end ) { + bspbrush_t *brushes; + tree_t *tree; + node_t *node; + vec3_t mins, maxs; + + //take the whole world + mins[0] = map_mins[0] - 8; + mins[1] = map_mins[1] - 8; + mins[2] = map_mins[2] - 8; + + maxs[0] = map_maxs[0] + 8; + maxs[1] = map_maxs[1] + 8; + maxs[2] = map_maxs[2] + 8; + + //reset the brush bsp + ResetBrushBSP(); + + // the makelist and chopbrushes could be cached between the passes... + + //create a list with brushes that are within the given mins/maxs + //some brushes will be cut and only the part that falls within the + //mins/maxs will be in the bush list + brushes = MakeBspBrushList( brush_start, brush_end, mins, maxs ); + // + + if ( !brushes ) { + node = AllocNode(); + node->planenum = PLANENUM_LEAF; + node->contents = CONTENTS_SOLID; + + tree = Tree_Alloc(); + tree->headnode = node; + VectorCopy( mins, tree->mins ); + VectorCopy( maxs, tree->maxs ); + } //end if + else + { + //Carves any intersecting solid brushes into the minimum number + //of non-intersecting brushes. + if ( !nocsg ) { + brushes = ChopBrushes( brushes ); + /* + if (create_aas) + { + brushes = MergeBrushes(brushes); + } //end if*/ + } //end if + //if the conversion is cancelled + if ( cancelconversion ) { + FreeBrushList( brushes ); + return NULL; + } //end if + //create the actual bsp tree + tree = BrushBSP( brushes, mins, maxs ); + } //end else + //return the tree + return tree; +} //end of the function ProcessWorldBrushes diff --git a/Projects/Android/jni/rtcw/src/bspc/faces.c b/Projects/Android/jni/rtcw/src/bspc/faces.c new file mode 100644 index 0000000..279e10f --- /dev/null +++ b/Projects/Android/jni/rtcw/src/bspc/faces.c @@ -0,0 +1,1002 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +// NO LONGER USED +// faces.c +#if 0 +#include "qbsp.h" +#include "l_mem.h" + + +extern dvertex_t *dvertexes; +extern int numvertexes; +extern int numedges; +extern dedge_t *dedges; +extern texinfo_t texinfo[MAX_MAP_TEXINFO]; + +/* + + some faces will be removed before saving, but still form nodes: + + the insides of sky volumes + meeting planes of different water current volumes + +*/ + +// undefine for dumb linear searches +#define USE_HASHING + +#define INTEGRAL_EPSILON 0.01 +#define POINT_EPSILON 0.5 +#define OFF_EPSILON 0.5 + +int c_merge; +int c_subdivide; + +int c_totalverts; +int c_uniqueverts; +int c_degenerate; +int c_tjunctions; +int c_faceoverflows; +int c_facecollapse; +int c_badstartverts; + +#define MAX_SUPERVERTS 512 +int superverts[MAX_SUPERVERTS]; +int numsuperverts; + +face_t *edgefaces[MAX_MAP_EDGES][2]; +int firstmodeledge = 1; +int firstmodelface; + +int c_tryedges; + +vec3_t edge_dir; +vec3_t edge_start; +vec_t edge_len; + +int num_edge_verts; +int edge_verts[MAX_MAP_VERTS]; + + +face_t *NewFaceFromFace( face_t *f ); + +//=========================================================================== + +typedef struct hashvert_s +{ + struct hashvert_s *next; + int num; +} hashvert_t; + + +#define HASH_SIZE 64 + + +int vertexchain[MAX_MAP_VERTS]; // the next vertex in a hash chain +int hashverts[HASH_SIZE * HASH_SIZE]; // a vertex number, or 0 for no verts + +face_t *edgefaces[MAX_MAP_EDGES][2]; + +//============================================================================ + + +unsigned HashVec( vec3_t vec ) { + int x, y; + + x = ( 4096 + (int)( vec[0] + 0.5 ) ) >> 7; + y = ( 4096 + (int)( vec[1] + 0.5 ) ) >> 7; + + if ( x < 0 || x >= HASH_SIZE || y < 0 || y >= HASH_SIZE ) { + Error( "HashVec: point outside valid range" ); + } + + return y * HASH_SIZE + x; +} + +#ifdef USE_HASHING +/* +============= +GetVertex + +Uses hashing +============= +*/ +int GetVertexnum( vec3_t in ) { + int h; + int i; + float *p; + vec3_t vert; + int vnum; + + c_totalverts++; + + for ( i = 0 ; i < 3 ; i++ ) + { + if ( fabs( in[i] - Q_rint( in[i] ) ) < INTEGRAL_EPSILON ) { + vert[i] = Q_rint( in[i] ); + } else { + vert[i] = in[i]; + } + } + + h = HashVec( vert ); + + for ( vnum = hashverts[h] ; vnum ; vnum = vertexchain[vnum] ) + { + p = dvertexes[vnum].point; + if ( fabs( p[0] - vert[0] ) < POINT_EPSILON + && fabs( p[1] - vert[1] ) < POINT_EPSILON + && fabs( p[2] - vert[2] ) < POINT_EPSILON ) { + return vnum; + } + } + +// emit a vertex + if ( numvertexes == MAX_MAP_VERTS ) { + Error( "numvertexes == MAX_MAP_VERTS" ); + } + + dvertexes[numvertexes].point[0] = vert[0]; + dvertexes[numvertexes].point[1] = vert[1]; + dvertexes[numvertexes].point[2] = vert[2]; + + vertexchain[numvertexes] = hashverts[h]; + hashverts[h] = numvertexes; + + c_uniqueverts++; + + numvertexes++; + + return numvertexes - 1; +} +#else +/* +================== +GetVertexnum + +Dumb linear search +================== +*/ +int GetVertexnum( vec3_t v ) { + int i, j; + dvertex_t *dv; + vec_t d; + + c_totalverts++; + + // make really close values exactly integral + for ( i = 0 ; i < 3 ; i++ ) + { + if ( fabs( v[i] - (int)( v[i] + 0.5 ) ) < INTEGRAL_EPSILON ) { + v[i] = (int)( v[i] + 0.5 ); + } + if ( v[i] < -4096 || v[i] > 4096 ) { + Error( "GetVertexnum: outside +/- 4096" ); + } + } + + // search for an existing vertex match + for ( i = 0, dv = dvertexes ; i < numvertexes ; i++, dv++ ) + { + for ( j = 0 ; j < 3 ; j++ ) + { + d = v[j] - dv->point[j]; + if ( d > POINT_EPSILON || d < -POINT_EPSILON ) { + break; + } + } + if ( j == 3 ) { + return i; // a match + } + } + + // new point + if ( numvertexes == MAX_MAP_VERTS ) { + Error( "MAX_MAP_VERTS" ); + } + VectorCopy( v, dv->point ); + numvertexes++; + c_uniqueverts++; + + return numvertexes - 1; +} +#endif + + +/* +================== +FaceFromSuperverts + +The faces vertexes have been added to the superverts[] array, +and there may be more there than can be held in a face (MAXEDGES). + +If less, the faces vertexnums[] will be filled in, otherwise +face will reference a tree of split[] faces until all of the +vertexnums can be added. + +superverts[base] will become face->vertexnums[0], and the others +will be circularly filled in. +================== +*/ +void FaceFromSuperverts( node_t *node, face_t *f, int base ) { + face_t *newf; + int remaining; + int i; + + remaining = numsuperverts; + while ( remaining > MAXEDGES ) + { // must split into two faces, because of vertex overload + c_faceoverflows++; + + newf = f->split[0] = NewFaceFromFace( f ); + newf = f->split[0]; + newf->next = node->faces; + node->faces = newf; + + newf->numpoints = MAXEDGES; + for ( i = 0 ; i < MAXEDGES ; i++ ) + newf->vertexnums[i] = superverts[( i + base ) % numsuperverts]; + + f->split[1] = NewFaceFromFace( f ); + f = f->split[1]; + f->next = node->faces; + node->faces = f; + + remaining -= ( MAXEDGES - 2 ); + base = ( base + MAXEDGES - 1 ) % numsuperverts; + } + + // copy the vertexes back to the face + f->numpoints = remaining; + for ( i = 0 ; i < remaining ; i++ ) + f->vertexnums[i] = superverts[( i + base ) % numsuperverts]; +} + + +/* +================== +EmitFaceVertexes +================== +*/ +void EmitFaceVertexes( node_t *node, face_t *f ) { + winding_t *w; + int i; + + if ( f->merged || f->split[0] || f->split[1] ) { + return; + } + + w = f->w; + for ( i = 0 ; i < w->numpoints ; i++ ) + { + if ( noweld ) { // make every point unique + if ( numvertexes == MAX_MAP_VERTS ) { + Error( "MAX_MAP_VERTS" ); + } + superverts[i] = numvertexes; + VectorCopy( w->p[i], dvertexes[numvertexes].point ); + numvertexes++; + c_uniqueverts++; + c_totalverts++; + } else { + superverts[i] = GetVertexnum( w->p[i] ); + } + } + numsuperverts = w->numpoints; + + // this may fragment the face if > MAXEDGES + FaceFromSuperverts( node, f, 0 ); +} + +/* +================== +EmitVertexes_r +================== +*/ +void EmitVertexes_r( node_t *node ) { + int i; + face_t *f; + + if ( node->planenum == PLANENUM_LEAF ) { + return; + } + + for ( f = node->faces ; f ; f = f->next ) + { + EmitFaceVertexes( node, f ); + } + + for ( i = 0 ; i < 2 ; i++ ) + EmitVertexes_r( node->children[i] ); +} + + +#ifdef USE_HASHING +/* +========== +FindEdgeVerts + +Uses the hash tables to cut down to a small number +========== +*/ +void FindEdgeVerts( vec3_t v1, vec3_t v2 ) { + int x1, x2, y1, y2, t; + int x, y; + int vnum; + +#if 0 + { + int i; + num_edge_verts = numvertexes - 1; + for ( i = 0 ; i < numvertexes - 1 ; i++ ) + edge_verts[i] = i + 1; + } +#endif + + x1 = ( 4096 + (int)( v1[0] + 0.5 ) ) >> 7; + y1 = ( 4096 + (int)( v1[1] + 0.5 ) ) >> 7; + x2 = ( 4096 + (int)( v2[0] + 0.5 ) ) >> 7; + y2 = ( 4096 + (int)( v2[1] + 0.5 ) ) >> 7; + + if ( x1 > x2 ) { + t = x1; + x1 = x2; + x2 = t; + } + if ( y1 > y2 ) { + t = y1; + y1 = y2; + y2 = t; + } +#if 0 + x1--; + x2++; + y1--; + y2++; + if ( x1 < 0 ) { + x1 = 0; + } + if ( x2 >= HASH_SIZE ) { + x2 = HASH_SIZE; + } + if ( y1 < 0 ) { + y1 = 0; + } + if ( y2 >= HASH_SIZE ) { + y2 = HASH_SIZE; + } +#endif + num_edge_verts = 0; + for ( x = x1 ; x <= x2 ; x++ ) + { + for ( y = y1 ; y <= y2 ; y++ ) + { + for ( vnum = hashverts[y * HASH_SIZE + x] ; vnum ; vnum = vertexchain[vnum] ) + { + edge_verts[num_edge_verts++] = vnum; + } + } + } +} + +#else +/* +========== +FindEdgeVerts + +Forced a dumb check of everything +========== +*/ +void FindEdgeVerts( vec3_t v1, vec3_t v2 ) { + int i; + + num_edge_verts = numvertexes - 1; + for ( i = 0 ; i < num_edge_verts ; i++ ) + edge_verts[i] = i + 1; +} +#endif + +/* +========== +TestEdge + +Can be recursively reentered +========== +*/ +void TestEdge( vec_t start, vec_t end, int p1, int p2, int startvert ) { + int j, k; + vec_t dist; + vec3_t delta; + vec3_t exact; + vec3_t off; + vec_t error; + vec3_t p; + + if ( p1 == p2 ) { + c_degenerate++; + return; // degenerate edge + } + + for ( k = startvert ; k < num_edge_verts ; k++ ) + { + j = edge_verts[k]; + if ( j == p1 || j == p2 ) { + continue; + } + + VectorCopy( dvertexes[j].point, p ); + + VectorSubtract( p, edge_start, delta ); + dist = DotProduct( delta, edge_dir ); + if ( dist <= start || dist >= end ) { + continue; // off an end + } + VectorMA( edge_start, dist, edge_dir, exact ); + VectorSubtract( p, exact, off ); + error = VectorLength( off ); + + if ( fabs( error ) > OFF_EPSILON ) { + continue; // not on the edge + + } + // break the edge + c_tjunctions++; + TestEdge( start, dist, p1, j, k + 1 ); + TestEdge( dist, end, j, p2, k + 1 ); + return; + } + + // the edge p1 to p2 is now free of tjunctions + if ( numsuperverts >= MAX_SUPERVERTS ) { + Error( "MAX_SUPERVERTS" ); + } + superverts[numsuperverts] = p1; + numsuperverts++; +} + +/* +================== +FixFaceEdges + +================== +*/ +void FixFaceEdges( node_t *node, face_t *f ) { + int p1, p2; + int i; + vec3_t e2; + vec_t len; + int count[MAX_SUPERVERTS], start[MAX_SUPERVERTS]; + int base; + + if ( f->merged || f->split[0] || f->split[1] ) { + return; + } + + numsuperverts = 0; + + for ( i = 0 ; i < f->numpoints ; i++ ) + { + p1 = f->vertexnums[i]; + p2 = f->vertexnums[( i + 1 ) % f->numpoints]; + + VectorCopy( dvertexes[p1].point, edge_start ); + VectorCopy( dvertexes[p2].point, e2 ); + + FindEdgeVerts( edge_start, e2 ); + + VectorSubtract( e2, edge_start, edge_dir ); + len = VectorNormalize( edge_dir ); + + start[i] = numsuperverts; + TestEdge( 0, len, p1, p2, 0 ); + + count[i] = numsuperverts - start[i]; + } + + if ( numsuperverts < 3 ) { // entire face collapsed + f->numpoints = 0; + c_facecollapse++; + return; + } + + // we want to pick a vertex that doesn't have tjunctions + // on either side, which can cause artifacts on trifans, + // especially underwater + for ( i = 0 ; i < f->numpoints ; i++ ) + { + if ( count[i] == 1 && count[( i + f->numpoints - 1 ) % f->numpoints] == 1 ) { + break; + } + } + if ( i == f->numpoints ) { + f->badstartvert = true; + c_badstartverts++; + base = 0; + } else + { // rotate the vertex order + base = start[i]; + } + + // this may fragment the face if > MAXEDGES + FaceFromSuperverts( node, f, base ); +} + +/* +================== +FixEdges_r +================== +*/ +void FixEdges_r( node_t *node ) { + int i; + face_t *f; + + if ( node->planenum == PLANENUM_LEAF ) { + return; + } + + for ( f = node->faces ; f ; f = f->next ) + FixFaceEdges( node, f ); + + for ( i = 0 ; i < 2 ; i++ ) + FixEdges_r( node->children[i] ); +} + +/* +=========== +FixTjuncs + +=========== +*/ +void FixTjuncs( node_t *headnode ) { + // snap and merge all vertexes + qprintf( "---- snap verts ----\n" ); + memset( hashverts, 0, sizeof( hashverts ) ); + c_totalverts = 0; + c_uniqueverts = 0; + c_faceoverflows = 0; + EmitVertexes_r( headnode ); + qprintf( "%i unique from %i\n", c_uniqueverts, c_totalverts ); + + // break edges on tjunctions + qprintf( "---- tjunc ----\n" ); + c_tryedges = 0; + c_degenerate = 0; + c_facecollapse = 0; + c_tjunctions = 0; + if ( !notjunc ) { + FixEdges_r( headnode ); + } + qprintf( "%5i edges degenerated\n", c_degenerate ); + qprintf( "%5i faces degenerated\n", c_facecollapse ); + qprintf( "%5i edges added by tjunctions\n", c_tjunctions ); + qprintf( "%5i faces added by tjunctions\n", c_faceoverflows ); + qprintf( "%5i bad start verts\n", c_badstartverts ); +} + + +//======================================================== + +int c_faces; + +face_t *AllocFace( void ) { + face_t *f; + + f = GetMemory( sizeof( *f ) ); + memset( f, 0, sizeof( *f ) ); + c_faces++; + + return f; +} + +face_t *NewFaceFromFace( face_t *f ) { + face_t *newf; + + newf = AllocFace(); + *newf = *f; + newf->merged = NULL; + newf->split[0] = newf->split[1] = NULL; + newf->w = NULL; + return newf; +} + +void FreeFace( face_t *f ) { + if ( f->w ) { + FreeWinding( f->w ); + } + FreeMemory( f ); + c_faces--; +} + +//======================================================== + +/* +================== +GetEdge + +Called by writebsp. +Don't allow four way edges +================== +*/ +int GetEdge2( int v1, int v2, face_t *f ) { + dedge_t *edge; + int i; + + c_tryedges++; + + if ( !noshare ) { + for ( i = firstmodeledge ; i < numedges ; i++ ) + { + edge = &dedges[i]; + if ( v1 == edge->v[1] && v2 == edge->v[0] + && edgefaces[i][0]->contents == f->contents ) { + if ( edgefaces[i][1] ) { + // printf ("WARNING: multiple backward edge\n"); + continue; + } + edgefaces[i][1] = f; + return -i; + } + #if 0 + if ( v1 == edge->v[0] && v2 == edge->v[1] ) { + printf( "WARNING: multiple forward edge\n" ); + return i; + } + #endif + } + } + +// emit an edge + if ( numedges >= MAX_MAP_EDGES ) { + Error( "numedges == MAX_MAP_EDGES" ); + } + edge = &dedges[numedges]; + numedges++; + edge->v[0] = v1; + edge->v[1] = v2; + edgefaces[numedges - 1][0] = f; + + return numedges - 1; +} + +/* +=========================================================================== + +FACE MERGING + +=========================================================================== +*/ + +/* +============= +TryMerge + +If two polygons share a common edge and the edges that meet at the +common points are both inside the other polygons, merge them + +Returns NULL if the faces couldn't be merged, or the new face. +The originals will NOT be freed. +============= +*/ +face_t *TryMerge( face_t *f1, face_t *f2, vec3_t planenormal ) { + face_t *newf; + winding_t *nw; + + if ( !f1->w || !f2->w ) { + return NULL; + } + if ( f1->texinfo != f2->texinfo ) { + return NULL; + } + if ( f1->planenum != f2->planenum ) { // on front and back sides + return NULL; + } + if ( f1->contents != f2->contents ) { + return NULL; + } + + + nw = TryMergeWinding( f1->w, f2->w, planenormal ); + if ( !nw ) { + return NULL; + } + + c_merge++; + newf = NewFaceFromFace( f1 ); + newf->w = nw; + + f1->merged = newf; + f2->merged = newf; + + return newf; +} + +/* +=============== +MergeNodeFaces +=============== +*/ +void MergeNodeFaces( node_t *node ) { + face_t *f1, *f2, *end; + face_t *merged; + plane_t *plane; + + plane = &mapplanes[node->planenum]; + merged = NULL; + + for ( f1 = node->faces ; f1 ; f1 = f1->next ) + { + if ( f1->merged || f1->split[0] || f1->split[1] ) { + continue; + } + + for ( f2 = node->faces ; f2 != f1 ; f2 = f2->next ) + { + if ( f2->merged || f2->split[0] || f2->split[1] ) { + continue; + } + + //IDBUG: always passes the face's node's normal to TryMerge() + //regardless of which side the face is on. Approximately 50% of + //the time the face will be on the other side of node, and thus + //the result of the convex/concave test in TryMergeWinding(), + //which depends on the normal, is flipped. This causes faces + //that shouldn't be merged to be merged and faces that + //should be merged to not be merged. + //the following added line fixes this bug + //thanks to: Alexander Malmberg + plane = &mapplanes[f1->planenum]; + // + merged = TryMerge( f1, f2, plane->normal ); + if ( !merged ) { + continue; + } + + // add merged to the end of the node face list + // so it will be checked against all the faces again + for ( end = node->faces ; end->next ; end = end->next ) + ; + merged->next = NULL; + end->next = merged; + break; + } + } +} + +//===================================================================== + +/* +=============== +SubdivideFace + +Chop up faces that are larger than we want in the surface cache +=============== +*/ +void SubdivideFace( node_t *node, face_t *f ) { + float mins, maxs; + vec_t v; + int axis, i; + texinfo_t *tex; + vec3_t temp; + vec_t dist; + winding_t *w, *frontw, *backw; + + if ( f->merged ) { + return; + } + +// special (non-surface cached) faces don't need subdivision + tex = &texinfo[f->texinfo]; + + if ( tex->flags & ( SURF_WARP | SURF_SKY ) ) { + return; + } + + for ( axis = 0 ; axis < 2 ; axis++ ) + { + while ( 1 ) + { + mins = 999999; + maxs = -999999; + + VectorCopy( tex->vecs[axis], temp ); + w = f->w; + for ( i = 0 ; i < w->numpoints ; i++ ) + { + v = DotProduct( w->p[i], temp ); + if ( v < mins ) { + mins = v; + } + if ( v > maxs ) { + maxs = v; + } + } +#if 0 + if ( maxs - mins <= 0 ) { + Error( "zero extents" ); + } +#endif + if ( axis == 2 ) { // allow double high walls + if ( maxs - mins <= subdivide_size /* *2 */ ) { + break; + } + } else if ( maxs - mins <= subdivide_size ) { + break; + } + + // split it + c_subdivide++; + + v = VectorNormalize( temp ); + + dist = ( mins + subdivide_size - 16 ) / v; + + ClipWindingEpsilon( w, temp, dist, ON_EPSILON, &frontw, &backw ); + if ( !frontw || !backw ) { + Error( "SubdivideFace: didn't split the polygon" ); + } + + f->split[0] = NewFaceFromFace( f ); + f->split[0]->w = frontw; + f->split[0]->next = node->faces; + node->faces = f->split[0]; + + f->split[1] = NewFaceFromFace( f ); + f->split[1]->w = backw; + f->split[1]->next = node->faces; + node->faces = f->split[1]; + + SubdivideFace( node, f->split[0] ); + SubdivideFace( node, f->split[1] ); + return; + } + } +} + +void SubdivideNodeFaces( node_t *node ) { + face_t *f; + + for ( f = node->faces ; f ; f = f->next ) + { + SubdivideFace( node, f ); + } +} + +//=========================================================================== + +int c_nodefaces; + + +/* +============ +FaceFromPortal + +============ +*/ +face_t *FaceFromPortal( portal_t *p, int pside ) { + face_t *f; + side_t *side; + + side = p->side; + if ( !side ) { + return NULL; // portal does not bridge different visible contents + + } + f = AllocFace(); + + f->texinfo = side->texinfo; + f->planenum = ( side->planenum & ~1 ) | pside; + f->portal = p; + + if ( ( p->nodes[pside]->contents & CONTENTS_WINDOW ) + && VisibleContents( p->nodes[!pside]->contents ^ p->nodes[pside]->contents ) == CONTENTS_WINDOW ) { + return NULL; // don't show insides of windows + + } + if ( pside ) { + f->w = ReverseWinding( p->winding ); + f->contents = p->nodes[1]->contents; + } else + { + f->w = CopyWinding( p->winding ); + f->contents = p->nodes[0]->contents; + } + return f; +} + + +/* +=============== +MakeFaces_r + +If a portal will make a visible face, +mark the side that originally created it + + solid / empty : solid + solid / water : solid + water / empty : water + water / water : none +=============== +*/ +void MakeFaces_r( node_t *node ) { + portal_t *p; + int s; + + // recurse down to leafs + if ( node->planenum != PLANENUM_LEAF ) { + MakeFaces_r( node->children[0] ); + MakeFaces_r( node->children[1] ); + + // merge together all visible faces on the node + if ( !nomerge ) { + MergeNodeFaces( node ); + } + if ( !nosubdiv ) { + SubdivideNodeFaces( node ); + } + + return; + } + + // solid leafs never have visible faces + if ( node->contents & CONTENTS_SOLID ) { + return; + } + + // see which portals are valid + for ( p = node->portals ; p ; p = p->next[s] ) + { + s = ( p->nodes[1] == node ); + + p->face[s] = FaceFromPortal( p, s ); + if ( p->face[s] ) { + c_nodefaces++; + p->face[s]->next = p->onnode->faces; + p->onnode->faces = p->face[s]; + } + } +} + +/* +============ +MakeFaces +============ +*/ +void MakeFaces( node_t *node ) { + qprintf( "--- MakeFaces ---\n" ); + c_merge = 0; + c_subdivide = 0; + c_nodefaces = 0; + + MakeFaces_r( node ); + + qprintf( "%5i makefaces\n", c_nodefaces ); + qprintf( "%5i merged\n", c_merge ); + qprintf( "%5i subdivided\n", c_subdivide ); +} +#endif \ No newline at end of file diff --git a/Projects/Android/jni/rtcw/src/bspc/glfile.c b/Projects/Android/jni/rtcw/src/bspc/glfile.c new file mode 100644 index 0000000..faf4717 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/bspc/glfile.c @@ -0,0 +1,157 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +#include "qbsp.h" + +int c_glfaces; + +int PortalVisibleSides( portal_t *p ) { + int fcon, bcon; + + if ( !p->onnode ) { + return 0; // outside + + } + fcon = p->nodes[0]->contents; + bcon = p->nodes[1]->contents; + + // same contents never create a face + if ( fcon == bcon ) { + return 0; + } + + // FIXME: is this correct now? + if ( !fcon ) { + return 1; + } + if ( !bcon ) { + return 2; + } + return 0; +} + +void OutputWinding( winding_t *w, FILE *glview ) { + static int level = 128; + vec_t light; + int i; + + fprintf( glview, "%i\n", w->numpoints ); + level += 28; + light = ( level & 255 ) / 255.0; + for ( i = 0 ; i < w->numpoints ; i++ ) + { + fprintf( glview, "%6.3f %6.3f %6.3f %6.3f %6.3f %6.3f\n", + w->p[i][0], + w->p[i][1], + w->p[i][2], + light, + light, + light ); + } + fprintf( glview, "\n" ); +} + +/* +============= +OutputPortal +============= +*/ +void OutputPortal( portal_t *p, FILE *glview ) { + winding_t *w; + int sides; + + sides = PortalVisibleSides( p ); + if ( !sides ) { + return; + } + + c_glfaces++; + + w = p->winding; + + if ( sides == 2 ) { // back side + w = ReverseWinding( w ); + } + + OutputWinding( w, glview ); + + if ( sides == 2 ) { + FreeWinding( w ); + } +} + +/* +============= +WriteGLView_r +============= +*/ +void WriteGLView_r( node_t *node, FILE *glview ) { + portal_t *p, *nextp; + + if ( node->planenum != PLANENUM_LEAF ) { + WriteGLView_r( node->children[0], glview ); + WriteGLView_r( node->children[1], glview ); + return; + } + + // write all the portals + for ( p = node->portals ; p ; p = nextp ) + { + if ( p->nodes[0] == node ) { + OutputPortal( p, glview ); + nextp = p->next[0]; + } else { + nextp = p->next[1]; + } + } +} + +/* +============= +WriteGLView +============= +*/ +void WriteGLView( tree_t *tree, char *source ) { + char name[1024]; + FILE *glview; + + c_glfaces = 0; + sprintf( name, "%s%s.gl",outbase, source ); + printf( "Writing %s\n", name ); + + glview = fopen( name, "w" ); + if ( !glview ) { + Error( "Couldn't open %s", name ); + } + WriteGLView_r( tree->headnode, glview ); + fclose( glview ); + + printf( "%5i c_glfaces\n", c_glfaces ); +} + diff --git a/Projects/Android/jni/rtcw/src/bspc/l_bsp_ent.c b/Projects/Android/jni/rtcw/src/bspc/l_bsp_ent.c new file mode 100644 index 0000000..2671cf5 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/bspc/l_bsp_ent.c @@ -0,0 +1,195 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +//=========================================================================== +// +// Name: l_bsp_ent.c +// Function: bsp entity parsing +// Programmer: Mr Elusive (MrElusive@demigod.demon.nl) +// Last update: 1999-04-05 +// Tab Size: 3 +// Notes: - +//=========================================================================== + +#include "l_cmd.h" +#include "l_math.h" +#include "l_mem.h" +#include "l_log.h" +#include "../botlib/l_script.h" +#include "l_bsp_ent.h" + +#define MAX_KEY 32 +#define MAX_VALUE 1024 + +int num_entities; +entity_t entities[MAX_MAP_ENTITIES]; + +void StripTrailing( char *e ) { + char *s; + + s = e + strlen( e ) - 1; + while ( s >= e && *s <= 32 ) + { + *s = 0; + s--; + } +} + +/* +================= +ParseEpair +================= +*/ +epair_t *ParseEpair( script_t *script ) { + epair_t *e; + token_t token; + + e = GetMemory( sizeof( epair_t ) ); + memset( e, 0, sizeof( epair_t ) ); + + PS_ExpectAnyToken( script, &token ); + StripDoubleQuotes( token.string ); + if ( strlen( token.string ) >= MAX_KEY - 1 ) { + Error( "ParseEpair: token %s too long", token.string ); + } + e->key = copystring( token.string ); + PS_ExpectAnyToken( script, &token ); + StripDoubleQuotes( token.string ); + if ( strlen( token.string ) >= MAX_VALUE - 1 ) { + Error( "ParseEpair: token %s too long", token.string ); + } + e->value = copystring( token.string ); + + // strip trailing spaces + StripTrailing( e->key ); + StripTrailing( e->value ); + + return e; +} //end of the function ParseEpair + + +/* +================ +ParseEntity +================ +*/ +qboolean ParseEntity( script_t *script ) { + epair_t *e; + entity_t *mapent; + token_t token; + + if ( !PS_ReadToken( script, &token ) ) { + return false; + } + + if ( strcmp( token.string, "{" ) ) { + Error( "ParseEntity: { not found" ); + } + + if ( num_entities == MAX_MAP_ENTITIES ) { + Error( "num_entities == MAX_MAP_ENTITIES" ); + } + + mapent = &entities[num_entities]; + num_entities++; + + do + { + if ( !PS_ReadToken( script, &token ) ) { + Error( "ParseEntity: EOF without closing brace" ); + } + if ( !strcmp( token.string, "}" ) ) { + break; + } + PS_UnreadLastToken( script ); + e = ParseEpair( script ); + e->next = mapent->epairs; + mapent->epairs = e; + } while ( 1 ); + + return true; +} //end of the function ParseEntity + +void PrintEntity( entity_t *ent ) { + epair_t *ep; + + printf( "------- entity %p -------\n", ent ); + for ( ep = ent->epairs ; ep ; ep = ep->next ) + { + printf( "%s = %s\n", ep->key, ep->value ); + } + +} + +void SetKeyValue( entity_t *ent, char *key, char *value ) { + epair_t *ep; + + for ( ep = ent->epairs ; ep ; ep = ep->next ) + if ( !strcmp( ep->key, key ) ) { + FreeMemory( ep->value ); + ep->value = copystring( value ); + return; + } + ep = GetMemory( sizeof( *ep ) ); + ep->next = ent->epairs; + ent->epairs = ep; + ep->key = copystring( key ); + ep->value = copystring( value ); +} + +char *ValueForKey( entity_t *ent, char *key ) { + epair_t *ep; + + for ( ep = ent->epairs ; ep ; ep = ep->next ) + if ( !strcmp( ep->key, key ) ) { + return ep->value; + } + return ""; +} + +vec_t FloatForKey( entity_t *ent, char *key ) { + char *k; + + k = ValueForKey( ent, key ); + return atof( k ); +} + +void GetVectorForKey( entity_t *ent, char *key, vec3_t vec ) { + char *k; + double v1, v2, v3; + + k = ValueForKey( ent, key ); +// scanf into doubles, then assign, so it is vec_t size independent + v1 = v2 = v3 = 0; + sscanf( k, "%lf %lf %lf", &v1, &v2, &v3 ); + vec[0] = v1; + vec[1] = v2; + vec[2] = v3; +} + + diff --git a/Projects/Android/jni/rtcw/src/bspc/l_bsp_ent.h b/Projects/Android/jni/rtcw/src/bspc/l_bsp_ent.h new file mode 100644 index 0000000..42257a4 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/bspc/l_bsp_ent.h @@ -0,0 +1,65 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +#ifndef MAX_MAP_ENTITIES +#define MAX_MAP_ENTITIES 2048 +#endif + +typedef struct epair_s +{ + struct epair_s *next; + char *key; + char *value; +} epair_t; + +typedef struct +{ + vec3_t origin; + int firstbrush; + int numbrushes; + epair_t *epairs; + // only valid for func_areaportals + int areaportalnum; + int portalareas[2]; + int modelnum; //for bsp 2 map conversion + qboolean wasdetail; //for SIN +} entity_t; + +extern int num_entities; +extern entity_t entities[MAX_MAP_ENTITIES]; + +void StripTrailing( char *e ); +void SetKeyValue( entity_t *ent, char *key, char *value ); +char *ValueForKey( entity_t *ent, char *key ); // will return "" if not present +vec_t FloatForKey( entity_t *ent, char *key ); +void GetVectorForKey( entity_t *ent, char *key, vec3_t vec ); +qboolean ParseEntity( script_t *script ); +epair_t *ParseEpair( script_t *script ); +void PrintEntity( entity_t *ent ); + diff --git a/Projects/Android/jni/rtcw/src/bspc/l_bsp_hl.c b/Projects/Android/jni/rtcw/src/bspc/l_bsp_hl.c new file mode 100644 index 0000000..87eb171 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/bspc/l_bsp_hl.c @@ -0,0 +1,886 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +/*** +* +* Copyright (c) 1998, Valve LLC. All rights reserved. +* +* This product contains software technology licensed from Id +* Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc. +* All Rights Reserved. +* +****/ + +#include "l_cmd.h" +#include "l_math.h" +#include "l_mem.h" +#include "l_log.h" +#include "../botlib/l_script.h" +#include "l_bsp_hl.h" +#include "l_bsp_ent.h" + +//============================================================================= + +int hl_nummodels; +hl_dmodel_t *hl_dmodels; //[HL_MAX_MAP_MODELS]; +int hl_dmodels_checksum; + +int hl_visdatasize; +byte *hl_dvisdata; //[HL_MAX_MAP_VISIBILITY]; +int hl_dvisdata_checksum; + +int hl_lightdatasize; +byte *hl_dlightdata; //[HL_MAX_MAP_LIGHTING]; +int hl_dlightdata_checksum; + +int hl_texdatasize; +byte *hl_dtexdata; //[HL_MAX_MAP_MIPTEX]; // (dmiptexlump_t) +int hl_dtexdata_checksum; + +int hl_entdatasize; +char *hl_dentdata; //[HL_MAX_MAP_ENTSTRING]; +int hl_dentdata_checksum; + +int hl_numleafs; +hl_dleaf_t *hl_dleafs; //[HL_MAX_MAP_LEAFS]; +int hl_dleafs_checksum; + +int hl_numplanes; +hl_dplane_t *hl_dplanes; //[HL_MAX_MAP_PLANES]; +int hl_dplanes_checksum; + +int hl_numvertexes; +hl_dvertex_t *hl_dvertexes; //[HL_MAX_MAP_VERTS]; +int hl_dvertexes_checksum; + +int hl_numnodes; +hl_dnode_t *hl_dnodes; //[HL_MAX_MAP_NODES]; +int hl_dnodes_checksum; + +int hl_numtexinfo; +hl_texinfo_t *hl_texinfo; //[HL_MAX_MAP_TEXINFO]; +int hl_texinfo_checksum; + +int hl_numfaces; +hl_dface_t *hl_dfaces; //[HL_MAX_MAP_FACES]; +int hl_dfaces_checksum; + +int hl_numclipnodes; +hl_dclipnode_t *hl_dclipnodes; //[HL_MAX_MAP_CLIPNODES]; +int hl_dclipnodes_checksum; + +int hl_numedges; +hl_dedge_t *hl_dedges; //[HL_MAX_MAP_EDGES]; +int hl_dedges_checksum; + +int hl_nummarksurfaces; +unsigned short *hl_dmarksurfaces; //[HL_MAX_MAP_MARKSURFACES]; +int hl_dmarksurfaces_checksum; + +int hl_numsurfedges; +int *hl_dsurfedges; //[HL_MAX_MAP_SURFEDGES]; +int hl_dsurfedges_checksum; + +//int num_entities; +//entity_t entities[HL_MAX_MAP_ENTITIES]; + + +//#ifdef //ME + +int hl_bspallocated = false; +int hl_allocatedbspmem = 0; + +void HL_AllocMaxBSP( void ) { + //models + hl_nummodels = 0; + hl_dmodels = (hl_dmodel_t *) GetMemory( HL_MAX_MAP_MODELS * sizeof( hl_dmodel_t ) ); + hl_allocatedbspmem = HL_MAX_MAP_MODELS * sizeof( hl_dmodel_t ); + //visibility + hl_visdatasize = 0; + hl_dvisdata = (byte *) GetMemory( HL_MAX_MAP_VISIBILITY * sizeof( byte ) ); + hl_allocatedbspmem += HL_MAX_MAP_VISIBILITY * sizeof( byte ); + //light data + hl_lightdatasize = 0; + hl_dlightdata = (byte *) GetMemory( HL_MAX_MAP_LIGHTING * sizeof( byte ) ); + hl_allocatedbspmem += HL_MAX_MAP_LIGHTING * sizeof( byte ); + //texture data + hl_texdatasize = 0; + hl_dtexdata = (byte *) GetMemory( HL_MAX_MAP_MIPTEX * sizeof( byte ) ); // (dmiptexlump_t) + hl_allocatedbspmem += HL_MAX_MAP_MIPTEX * sizeof( byte ); + //entities + hl_entdatasize = 0; + hl_dentdata = (char *) GetMemory( HL_MAX_MAP_ENTSTRING * sizeof( char ) ); + hl_allocatedbspmem += HL_MAX_MAP_ENTSTRING * sizeof( char ); + //leaves + hl_numleafs = 0; + hl_dleafs = (hl_dleaf_t *) GetMemory( HL_MAX_MAP_LEAFS * sizeof( hl_dleaf_t ) ); + hl_allocatedbspmem += HL_MAX_MAP_LEAFS * sizeof( hl_dleaf_t ); + //planes + hl_numplanes = 0; + hl_dplanes = (hl_dplane_t *) GetMemory( HL_MAX_MAP_PLANES * sizeof( hl_dplane_t ) ); + hl_allocatedbspmem += HL_MAX_MAP_PLANES * sizeof( hl_dplane_t ); + //vertexes + hl_numvertexes = 0; + hl_dvertexes = (hl_dvertex_t *) GetMemory( HL_MAX_MAP_VERTS * sizeof( hl_dvertex_t ) ); + hl_allocatedbspmem += HL_MAX_MAP_VERTS * sizeof( hl_dvertex_t ); + //nodes + hl_numnodes = 0; + hl_dnodes = (hl_dnode_t *) GetMemory( HL_MAX_MAP_NODES * sizeof( hl_dnode_t ) ); + hl_allocatedbspmem += HL_MAX_MAP_NODES * sizeof( hl_dnode_t ); + //texture info + hl_numtexinfo = 0; + hl_texinfo = (hl_texinfo_t *) GetMemory( HL_MAX_MAP_TEXINFO * sizeof( hl_texinfo_t ) ); + hl_allocatedbspmem += HL_MAX_MAP_TEXINFO * sizeof( hl_texinfo_t ); + //faces + hl_numfaces = 0; + hl_dfaces = (hl_dface_t *) GetMemory( HL_MAX_MAP_FACES * sizeof( hl_dface_t ) ); + hl_allocatedbspmem += HL_MAX_MAP_FACES * sizeof( hl_dface_t ); + //clip nodes + hl_numclipnodes = 0; + hl_dclipnodes = (hl_dclipnode_t *) GetMemory( HL_MAX_MAP_CLIPNODES * sizeof( hl_dclipnode_t ) ); + hl_allocatedbspmem += HL_MAX_MAP_CLIPNODES * sizeof( hl_dclipnode_t ); + //edges + hl_numedges = 0; + hl_dedges = (hl_dedge_t *) GetMemory( HL_MAX_MAP_EDGES * sizeof( hl_dedge_t ) ); + hl_allocatedbspmem += HL_MAX_MAP_EDGES, sizeof( hl_dedge_t ); + //mark surfaces + hl_nummarksurfaces = 0; + hl_dmarksurfaces = (unsigned short *) GetMemory( HL_MAX_MAP_MARKSURFACES * sizeof( unsigned short ) ); + hl_allocatedbspmem += HL_MAX_MAP_MARKSURFACES * sizeof( unsigned short ); + //surface edges + hl_numsurfedges = 0; + hl_dsurfedges = (int *) GetMemory( HL_MAX_MAP_SURFEDGES * sizeof( int ) ); + hl_allocatedbspmem += HL_MAX_MAP_SURFEDGES * sizeof( int ); + //print allocated memory + Log_Print( "allocated " ); + PrintMemorySize( hl_allocatedbspmem ); + Log_Print( " of BSP memory\n" ); +} //end of the function HL_AllocMaxBSP + +void HL_FreeMaxBSP( void ) { + //models + hl_nummodels = 0; + FreeMemory( hl_dmodels ); + hl_dmodels = NULL; + //visibility + hl_visdatasize = 0; + FreeMemory( hl_dvisdata ); + hl_dvisdata = NULL; + //light data + hl_lightdatasize = 0; + FreeMemory( hl_dlightdata ); + hl_dlightdata = NULL; + //texture data + hl_texdatasize = 0; + FreeMemory( hl_dtexdata ); + hl_dtexdata = NULL; + //entities + hl_entdatasize = 0; + FreeMemory( hl_dentdata ); + hl_dentdata = NULL; + //leaves + hl_numleafs = 0; + FreeMemory( hl_dleafs ); + hl_dleafs = NULL; + //planes + hl_numplanes = 0; + FreeMemory( hl_dplanes ); + hl_dplanes = NULL; + //vertexes + hl_numvertexes = 0; + FreeMemory( hl_dvertexes ); + hl_dvertexes = NULL; + //nodes + hl_numnodes = 0; + FreeMemory( hl_dnodes ); + hl_dnodes = NULL; + //texture info + hl_numtexinfo = 0; + FreeMemory( hl_texinfo ); + hl_texinfo = NULL; + //faces + hl_numfaces = 0; + FreeMemory( hl_dfaces ); + hl_dfaces = NULL; + //clip nodes + hl_numclipnodes = 0; + FreeMemory( hl_dclipnodes ); + hl_dclipnodes = NULL; + //edges + hl_numedges = 0; + FreeMemory( hl_dedges ); + hl_dedges = NULL; + //mark surfaces + hl_nummarksurfaces = 0; + FreeMemory( hl_dmarksurfaces ); + hl_dmarksurfaces = NULL; + //surface edges + hl_numsurfedges = 0; + FreeMemory( hl_dsurfedges ); + hl_dsurfedges = NULL; + // + Log_Print( "freed " ); + PrintMemorySize( hl_allocatedbspmem ); + Log_Print( " of BSP memory\n" ); + hl_allocatedbspmem = 0; +} //end of the function HL_FreeMaxBSP +//#endif //ME + +/* +=============== +FastChecksum +=============== +*/ + +int FastChecksum( void *buffer, int bytes ) { + int checksum = 0; + + while ( bytes-- ) + checksum = ( checksum << 4 ) ^ *( (char *)buffer )++; + + return checksum; +} + +/* +=============== +HL_CompressVis +=============== +*/ +int HL_CompressVis( byte *vis, byte *dest ) { + int j; + int rep; + int visrow; + byte *dest_p; + + dest_p = dest; + visrow = ( hl_numleafs + 7 ) >> 3; + + for ( j = 0 ; j < visrow ; j++ ) + { + *dest_p++ = vis[j]; + if ( vis[j] ) { + continue; + } + + rep = 1; + for ( j++; j < visrow ; j++ ) + if ( vis[j] || rep == 255 ) { + break; + } else { + rep++; + } + *dest_p++ = rep; + j--; + } + + return dest_p - dest; +} + + +/* +=================== +HL_DecompressVis +=================== +*/ +void HL_DecompressVis( byte *in, byte *decompressed ) { + int c; + byte *out; + int row; + + row = ( hl_numleafs + 7 ) >> 3; + out = decompressed; + + do + { + if ( *in ) { + *out++ = *in++; + continue; + } + + c = in[1]; + in += 2; + while ( c ) + { + *out++ = 0; + c--; + } + } while ( out - decompressed < row ); +} + +//============================================================================= + +/* +============= +HL_SwapBSPFile + +Byte swaps all data in a bsp file. +============= +*/ +void HL_SwapBSPFile( qboolean todisk ) { + int i, j, c; + hl_dmodel_t *d; + hl_dmiptexlump_t *mtl; + + +// models + for ( i = 0; i < hl_nummodels; i++ ) + { + d = &hl_dmodels[i]; + + for ( j = 0; j < HL_MAX_MAP_HULLS; j++ ) + d->headnode[j] = LittleLong( d->headnode[j] ); + + d->visleafs = LittleLong( d->visleafs ); + d->firstface = LittleLong( d->firstface ); + d->numfaces = LittleLong( d->numfaces ); + + for ( j = 0; j < 3; j++ ) + { + d->mins[j] = LittleFloat( d->mins[j] ); + d->maxs[j] = LittleFloat( d->maxs[j] ); + d->origin[j] = LittleFloat( d->origin[j] ); + } + } + +// +// vertexes +// + for ( i = 0; i < hl_numvertexes; i++ ) + { + for ( j = 0; j < 3; j++ ) + hl_dvertexes[i].point[j] = LittleFloat( hl_dvertexes[i].point[j] ); + } + +// +// planes +// + for ( i = 0 ; i < hl_numplanes ; i++ ) + { + for ( j = 0 ; j < 3 ; j++ ) + hl_dplanes[i].normal[j] = LittleFloat( hl_dplanes[i].normal[j] ); + hl_dplanes[i].dist = LittleFloat( hl_dplanes[i].dist ); + hl_dplanes[i].type = LittleLong( hl_dplanes[i].type ); + } + +// +// texinfos +// + for ( i = 0 ; i < hl_numtexinfo ; i++ ) + { + for ( j = 0 ; j < 8 ; j++ ) + hl_texinfo[i].vecs[0][j] = LittleFloat( hl_texinfo[i].vecs[0][j] ); + hl_texinfo[i].miptex = LittleLong( hl_texinfo[i].miptex ); + hl_texinfo[i].flags = LittleLong( hl_texinfo[i].flags ); + } + +// +// faces +// + for ( i = 0 ; i < hl_numfaces ; i++ ) + { + hl_dfaces[i].texinfo = LittleShort( hl_dfaces[i].texinfo ); + hl_dfaces[i].planenum = LittleShort( hl_dfaces[i].planenum ); + hl_dfaces[i].side = LittleShort( hl_dfaces[i].side ); + hl_dfaces[i].lightofs = LittleLong( hl_dfaces[i].lightofs ); + hl_dfaces[i].firstedge = LittleLong( hl_dfaces[i].firstedge ); + hl_dfaces[i].numedges = LittleShort( hl_dfaces[i].numedges ); + } + +// +// nodes +// + for ( i = 0 ; i < hl_numnodes ; i++ ) + { + hl_dnodes[i].planenum = LittleLong( hl_dnodes[i].planenum ); + for ( j = 0 ; j < 3 ; j++ ) + { + hl_dnodes[i].mins[j] = LittleShort( hl_dnodes[i].mins[j] ); + hl_dnodes[i].maxs[j] = LittleShort( hl_dnodes[i].maxs[j] ); + } + hl_dnodes[i].children[0] = LittleShort( hl_dnodes[i].children[0] ); + hl_dnodes[i].children[1] = LittleShort( hl_dnodes[i].children[1] ); + hl_dnodes[i].firstface = LittleShort( hl_dnodes[i].firstface ); + hl_dnodes[i].numfaces = LittleShort( hl_dnodes[i].numfaces ); + } + +// +// leafs +// + for ( i = 0 ; i < hl_numleafs ; i++ ) + { + hl_dleafs[i].contents = LittleLong( hl_dleafs[i].contents ); + for ( j = 0 ; j < 3 ; j++ ) + { + hl_dleafs[i].mins[j] = LittleShort( hl_dleafs[i].mins[j] ); + hl_dleafs[i].maxs[j] = LittleShort( hl_dleafs[i].maxs[j] ); + } + + hl_dleafs[i].firstmarksurface = LittleShort( hl_dleafs[i].firstmarksurface ); + hl_dleafs[i].nummarksurfaces = LittleShort( hl_dleafs[i].nummarksurfaces ); + hl_dleafs[i].visofs = LittleLong( hl_dleafs[i].visofs ); + } + +// +// clipnodes +// + for ( i = 0 ; i < hl_numclipnodes ; i++ ) + { + hl_dclipnodes[i].planenum = LittleLong( hl_dclipnodes[i].planenum ); + hl_dclipnodes[i].children[0] = LittleShort( hl_dclipnodes[i].children[0] ); + hl_dclipnodes[i].children[1] = LittleShort( hl_dclipnodes[i].children[1] ); + } + +// +// miptex +// + if ( hl_texdatasize ) { + mtl = (hl_dmiptexlump_t *)hl_dtexdata; + if ( todisk ) { + c = mtl->nummiptex; + } else { + c = LittleLong( mtl->nummiptex ); + } + mtl->nummiptex = LittleLong( mtl->nummiptex ); + for ( i = 0 ; i < c ; i++ ) + mtl->dataofs[i] = LittleLong( mtl->dataofs[i] ); + } + +// +// marksurfaces +// + for ( i = 0 ; i < hl_nummarksurfaces ; i++ ) + hl_dmarksurfaces[i] = LittleShort( hl_dmarksurfaces[i] ); + +// +// surfedges +// + for ( i = 0 ; i < hl_numsurfedges ; i++ ) + hl_dsurfedges[i] = LittleLong( hl_dsurfedges[i] ); + +// +// edges +// + for ( i = 0 ; i < hl_numedges ; i++ ) + { + hl_dedges[i].v[0] = LittleShort( hl_dedges[i].v[0] ); + hl_dedges[i].v[1] = LittleShort( hl_dedges[i].v[1] ); + } +} //end of the function HL_SwapBSPFile + + +hl_dheader_t *hl_header; + +int HL_CopyLump( int lump, void *dest, int size ) { + int length, ofs; + + length = hl_header->lumps[lump].filelen; + ofs = hl_header->lumps[lump].fileofs; + + if ( length % size ) { + Error( "HL_LoadBSPFile: odd lump size" ); + } + + memcpy( dest, (byte *)hl_header + ofs, length ); + + return length / size; +} + +/* +============= +HL_LoadBSPFile +============= +*/ +void HL_LoadBSPFile( char *filename, int offset, int length ) { + int i; + +// +// load the file header +// + LoadFile( filename, (void **)&hl_header, offset, length ); + +// swap the header + for ( i = 0 ; i < sizeof( hl_dheader_t ) / 4 ; i++ ) + ( (int *)hl_header )[i] = LittleLong( ( (int *)hl_header )[i] ); + + if ( hl_header->version != HL_BSPVERSION ) { + Error( "%s is version %i, not %i", filename, hl_header->version, HL_BSPVERSION ); + } + + hl_nummodels = HL_CopyLump( HL_LUMP_MODELS, hl_dmodels, sizeof( hl_dmodel_t ) ); + hl_numvertexes = HL_CopyLump( HL_LUMP_VERTEXES, hl_dvertexes, sizeof( hl_dvertex_t ) ); + hl_numplanes = HL_CopyLump( HL_LUMP_PLANES, hl_dplanes, sizeof( hl_dplane_t ) ); + hl_numleafs = HL_CopyLump( HL_LUMP_LEAFS, hl_dleafs, sizeof( hl_dleaf_t ) ); + hl_numnodes = HL_CopyLump( HL_LUMP_NODES, hl_dnodes, sizeof( hl_dnode_t ) ); + hl_numtexinfo = HL_CopyLump( HL_LUMP_TEXINFO, hl_texinfo, sizeof( hl_texinfo_t ) ); + hl_numclipnodes = HL_CopyLump( HL_LUMP_CLIPNODES, hl_dclipnodes, sizeof( hl_dclipnode_t ) ); + hl_numfaces = HL_CopyLump( HL_LUMP_FACES, hl_dfaces, sizeof( hl_dface_t ) ); + hl_nummarksurfaces = HL_CopyLump( HL_LUMP_MARKSURFACES, hl_dmarksurfaces, sizeof( hl_dmarksurfaces[0] ) ); + hl_numsurfedges = HL_CopyLump( HL_LUMP_SURFEDGES, hl_dsurfedges, sizeof( hl_dsurfedges[0] ) ); + hl_numedges = HL_CopyLump( HL_LUMP_EDGES, hl_dedges, sizeof( hl_dedge_t ) ); + + hl_texdatasize = HL_CopyLump( HL_LUMP_TEXTURES, hl_dtexdata, 1 ); + hl_visdatasize = HL_CopyLump( HL_LUMP_VISIBILITY, hl_dvisdata, 1 ); + hl_lightdatasize = HL_CopyLump( HL_LUMP_LIGHTING, hl_dlightdata, 1 ); + hl_entdatasize = HL_CopyLump( HL_LUMP_ENTITIES, hl_dentdata, 1 ); + + FreeMemory( hl_header ); // everything has been copied out + +// +// swap everything +// + HL_SwapBSPFile( false ); + + hl_dmodels_checksum = FastChecksum( hl_dmodels, hl_nummodels * sizeof( hl_dmodels[0] ) ); + hl_dvertexes_checksum = FastChecksum( hl_dvertexes, hl_numvertexes * sizeof( hl_dvertexes[0] ) ); + hl_dplanes_checksum = FastChecksum( hl_dplanes, hl_numplanes * sizeof( hl_dplanes[0] ) ); + hl_dleafs_checksum = FastChecksum( hl_dleafs, hl_numleafs * sizeof( hl_dleafs[0] ) ); + hl_dnodes_checksum = FastChecksum( hl_dnodes, hl_numnodes * sizeof( hl_dnodes[0] ) ); + hl_texinfo_checksum = FastChecksum( hl_texinfo, hl_numtexinfo * sizeof( hl_texinfo[0] ) ); + hl_dclipnodes_checksum = FastChecksum( hl_dclipnodes, hl_numclipnodes * sizeof( hl_dclipnodes[0] ) ); + hl_dfaces_checksum = FastChecksum( hl_dfaces, hl_numfaces * sizeof( hl_dfaces[0] ) ); + hl_dmarksurfaces_checksum = FastChecksum( hl_dmarksurfaces, hl_nummarksurfaces * sizeof( hl_dmarksurfaces[0] ) ); + hl_dsurfedges_checksum = FastChecksum( hl_dsurfedges, hl_numsurfedges * sizeof( hl_dsurfedges[0] ) ); + hl_dedges_checksum = FastChecksum( hl_dedges, hl_numedges * sizeof( hl_dedges[0] ) ); + hl_dtexdata_checksum = FastChecksum( hl_dtexdata, hl_numedges * sizeof( hl_dtexdata[0] ) ); + hl_dvisdata_checksum = FastChecksum( hl_dvisdata, hl_visdatasize * sizeof( hl_dvisdata[0] ) ); + hl_dlightdata_checksum = FastChecksum( hl_dlightdata, hl_lightdatasize * sizeof( hl_dlightdata[0] ) ); + hl_dentdata_checksum = FastChecksum( hl_dentdata, hl_entdatasize * sizeof( hl_dentdata[0] ) ); + +} + +//============================================================================ + +FILE *wadfile; +hl_dheader_t outheader; + +void HL_AddLump( int lumpnum, void *data, int len ) { + hl_lump_t *lump; + + lump = &hl_header->lumps[lumpnum]; + + lump->fileofs = LittleLong( ftell( wadfile ) ); + lump->filelen = LittleLong( len ); + SafeWrite( wadfile, data, ( len + 3 ) & ~3 ); +} + +/* +============= +HL_WriteBSPFile + +Swaps the bsp file in place, so it should not be referenced again +============= +*/ +void HL_WriteBSPFile( char *filename ) { + hl_header = &outheader; + memset( hl_header, 0, sizeof( hl_dheader_t ) ); + + HL_SwapBSPFile( true ); + + hl_header->version = LittleLong( HL_BSPVERSION ); + + wadfile = SafeOpenWrite( filename ); + SafeWrite( wadfile, hl_header, sizeof( hl_dheader_t ) ); // overwritten later + + HL_AddLump( HL_LUMP_PLANES, hl_dplanes, hl_numplanes * sizeof( hl_dplane_t ) ); + HL_AddLump( HL_LUMP_LEAFS, hl_dleafs, hl_numleafs * sizeof( hl_dleaf_t ) ); + HL_AddLump( HL_LUMP_VERTEXES, hl_dvertexes, hl_numvertexes * sizeof( hl_dvertex_t ) ); + HL_AddLump( HL_LUMP_NODES, hl_dnodes, hl_numnodes * sizeof( hl_dnode_t ) ); + HL_AddLump( HL_LUMP_TEXINFO, hl_texinfo, hl_numtexinfo * sizeof( hl_texinfo_t ) ); + HL_AddLump( HL_LUMP_FACES, hl_dfaces, hl_numfaces * sizeof( hl_dface_t ) ); + HL_AddLump( HL_LUMP_CLIPNODES, hl_dclipnodes, hl_numclipnodes * sizeof( hl_dclipnode_t ) ); + HL_AddLump( HL_LUMP_MARKSURFACES, hl_dmarksurfaces, hl_nummarksurfaces * sizeof( hl_dmarksurfaces[0] ) ); + HL_AddLump( HL_LUMP_SURFEDGES, hl_dsurfedges, hl_numsurfedges * sizeof( hl_dsurfedges[0] ) ); + HL_AddLump( HL_LUMP_EDGES, hl_dedges, hl_numedges * sizeof( hl_dedge_t ) ); + HL_AddLump( HL_LUMP_MODELS, hl_dmodels, hl_nummodels * sizeof( hl_dmodel_t ) ); + + HL_AddLump( HL_LUMP_LIGHTING, hl_dlightdata, hl_lightdatasize ); + HL_AddLump( HL_LUMP_VISIBILITY, hl_dvisdata, hl_visdatasize ); + HL_AddLump( HL_LUMP_ENTITIES, hl_dentdata, hl_entdatasize ); + HL_AddLump( HL_LUMP_TEXTURES, hl_dtexdata, hl_texdatasize ); + + fseek( wadfile, 0, SEEK_SET ); + SafeWrite( wadfile, hl_header, sizeof( hl_dheader_t ) ); + fclose( wadfile ); +} + +//============================================================================ + +#define ENTRIES( a ) ( sizeof( a ) / sizeof( *( a ) ) ) +#define ENTRYSIZE( a ) ( sizeof( *( a ) ) ) + +int ArrayUsage( char *szItem, int items, int maxitems, int itemsize ) { + float percentage = maxitems ? items * 100.0 / maxitems : 0.0; + + qprintf( "%-12s %7i/%-7i %7i/%-7i (%4.1f%%)", + szItem, items, maxitems, items * itemsize, maxitems * itemsize, percentage ); + if ( percentage > 80.0 ) { + qprintf( "VERY FULL!\n" ); + } else if ( percentage > 95.0 ) { + qprintf( "SIZE DANGER!\n" ); + } else if ( percentage > 99.9 ) { + qprintf( "SIZE OVERFLOW!!!\n" ); + } else { + qprintf( "\n" ); + } + return items * itemsize; +} + +int GlobUsage( char *szItem, int itemstorage, int maxstorage ) { + float percentage = maxstorage ? itemstorage * 100.0 / maxstorage : 0.0; + + qprintf( "%-12s [variable] %7i/%-7i (%4.1f%%)", + szItem, itemstorage, maxstorage, percentage ); + if ( percentage > 80.0 ) { + qprintf( "VERY FULL!\n" ); + } else if ( percentage > 95.0 ) { + qprintf( "SIZE DANGER!\n" ); + } else if ( percentage > 99.9 ) { + qprintf( "SIZE OVERFLOW!!!\n" ); + } else { + qprintf( "\n" ); + } + return itemstorage; +} + +/* +============= +HL_PrintBSPFileSizes + +Dumps info about current file +============= +*/ +void HL_PrintBSPFileSizes( void ) { + //int numtextures = hl_texdatasize ? ((hl_dmiptexlump_t*)hl_dtexdata)->nummiptex : 0; // TTimo: unused + int totalmemory = 0; + + qprintf( "\n" ); + qprintf( "Object names Objects/Maxobjs Memory / Maxmem Fullness\n" ); + qprintf( "------------ --------------- --------------- --------\n" ); + + totalmemory += ArrayUsage( "models", hl_nummodels, ENTRIES( hl_dmodels ), ENTRYSIZE( hl_dmodels ) ); + totalmemory += ArrayUsage( "planes", hl_numplanes, ENTRIES( hl_dplanes ), ENTRYSIZE( hl_dplanes ) ); + totalmemory += ArrayUsage( "vertexes", hl_numvertexes, ENTRIES( hl_dvertexes ), ENTRYSIZE( hl_dvertexes ) ); + totalmemory += ArrayUsage( "nodes", hl_numnodes, ENTRIES( hl_dnodes ), ENTRYSIZE( hl_dnodes ) ); + totalmemory += ArrayUsage( "texinfos", hl_numtexinfo, ENTRIES( hl_texinfo ), ENTRYSIZE( hl_texinfo ) ); + totalmemory += ArrayUsage( "faces", hl_numfaces, ENTRIES( hl_dfaces ), ENTRYSIZE( hl_dfaces ) ); + totalmemory += ArrayUsage( "clipnodes", hl_numclipnodes, ENTRIES( hl_dclipnodes ), ENTRYSIZE( hl_dclipnodes ) ); + totalmemory += ArrayUsage( "leaves", hl_numleafs, ENTRIES( hl_dleafs ), ENTRYSIZE( hl_dleafs ) ); + totalmemory += ArrayUsage( "marksurfaces",hl_nummarksurfaces,ENTRIES( hl_dmarksurfaces ),ENTRYSIZE( hl_dmarksurfaces ) ); + totalmemory += ArrayUsage( "surfedges", hl_numsurfedges, ENTRIES( hl_dsurfedges ), ENTRYSIZE( hl_dsurfedges ) ); + totalmemory += ArrayUsage( "edges", hl_numedges, ENTRIES( hl_dedges ), ENTRYSIZE( hl_dedges ) ); + + totalmemory += GlobUsage( "texdata", hl_texdatasize, sizeof( hl_dtexdata ) ); + totalmemory += GlobUsage( "lightdata", hl_lightdatasize, sizeof( hl_dlightdata ) ); + totalmemory += GlobUsage( "visdata", hl_visdatasize, sizeof( hl_dvisdata ) ); + totalmemory += GlobUsage( "entdata", hl_entdatasize, sizeof( hl_dentdata ) ); + + qprintf( "=== Total BSP file data space used: %d bytes ===\n\n", totalmemory ); +} + + + +/* +================= +ParseEpair +================= +* / +epair_t *ParseEpair (void) +{ + epair_t *e; + + e = malloc (sizeof(epair_t)); + memset (e, 0, sizeof(epair_t)); + + if (strlen(token) >= MAX_KEY-1) + Error ("ParseEpar: token too long"); + e->key = copystring(token); + GetToken (false); + if (strlen(token) >= MAX_VALUE-1) + Error ("ParseEpar: token too long"); + e->value = copystring(token); + + return e; +} // +*/ + + +/* +================ +ParseEntity +================ +* / +qboolean ParseEntity (void) +{ + epair_t *e; + entity_t *mapent; + + if (!GetToken (true)) + return false; + + if (strcmp (token, "{") ) + Error ("ParseEntity: { not found"); + + if (num_entities == HL_MAX_MAP_ENTITIES) + Error ("num_entities == HL_MAX_MAP_ENTITIES"); + + mapent = &entities[num_entities]; + num_entities++; + + do + { + if (!GetToken (true)) + Error ("ParseEntity: EOF without closing brace"); + if (!strcmp (token, "}") ) + break; + e = ParseEpair (); + e->next = mapent->epairs; + mapent->epairs = e; + } while (1); + + return true; +} // +*/ + +/* +================ +ParseEntities + +Parses the dentdata string into entities +================ +*/ +void HL_ParseEntities( void ) { + script_t *script; + + num_entities = 0; + script = LoadScriptMemory( hl_dentdata, hl_entdatasize, "*Half-Life bsp file" ); + SetScriptFlags( script, SCFL_NOSTRINGWHITESPACES | + SCFL_NOSTRINGESCAPECHARS ); + + while ( ParseEntity( script ) ) + { + } //end while + + FreeScript( script ); +} //end of the function HL_ParseEntities + + +/* +================ +UnparseEntities + +Generates the dentdata string from all the entities +================ +*/ +void HL_UnparseEntities( void ) { + char *buf, *end; + epair_t *ep; + char line[2048]; + int i; + + buf = hl_dentdata; + end = buf; + *end = 0; + + for ( i = 0 ; i < num_entities ; i++ ) + { + ep = entities[i].epairs; + if ( !ep ) { + continue; // ent got removed + + } + strcat( end,"{\n" ); + end += 2; + + for ( ep = entities[i].epairs ; ep ; ep = ep->next ) + { + sprintf( line, "\"%s\" \"%s\"\n", ep->key, ep->value ); + strcat( end, line ); + end += strlen( line ); + } + strcat( end,"}\n" ); + end += 2; + + if ( end > buf + HL_MAX_MAP_ENTSTRING ) { + Error( "Entity text too long" ); + } + } + hl_entdatasize = end - buf + 1; +} //end of the function HL_UnparseEntities + + +/* +void SetKeyValue (entity_t *ent, char *key, char *value) +{ + epair_t *ep; + + for (ep=ent->epairs ; ep ; ep=ep->next) + if (!strcmp (ep->key, key) ) + { + free (ep->value); + ep->value = copystring(value); + return; + } + ep = malloc (sizeof(*ep)); + ep->next = ent->epairs; + ent->epairs = ep; + ep->key = copystring(key); + ep->value = copystring(value); +} + +char *ValueForKey (entity_t *ent, char *key) +{ + epair_t *ep; + + for (ep=ent->epairs ; ep ; ep=ep->next) + if (!strcmp (ep->key, key) ) + return ep->value; + return ""; +} + +vec_t FloatForKey (entity_t *ent, char *key) +{ + char *k; + + k = ValueForKey (ent, key); + return atof(k); +} + +void GetVectorForKey (entity_t *ent, char *key, vec3_t vec) +{ + char *k; + double v1, v2, v3; + + k = ValueForKey (ent, key); +// scanf into doubles, then assign, so it is vec_t size independent + v1 = v2 = v3 = 0; + sscanf (k, "%lf %lf %lf", &v1, &v2, &v3); + vec[0] = v1; + vec[1] = v2; + vec[2] = v3; +} // +*/ diff --git a/Projects/Android/jni/rtcw/src/bspc/l_bsp_hl.h b/Projects/Android/jni/rtcw/src/bspc/l_bsp_hl.h new file mode 100644 index 0000000..c1131cf --- /dev/null +++ b/Projects/Android/jni/rtcw/src/bspc/l_bsp_hl.h @@ -0,0 +1,332 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +/*** +* +* Copyright (c) 1998, Valve LLC. All rights reserved. +* +* This product contains software technology licensed from Id +* Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc. +* All Rights Reserved. +* +****/ + + +// upper design bounds + +#define HL_MAX_MAP_HULLS 4 + +#define HL_MAX_MAP_MODELS 400 +#define HL_MAX_MAP_BRUSHES 4096 +#define HL_MAX_MAP_ENTITIES 1024 +#define HL_MAX_MAP_ENTSTRING ( 128 * 1024 ) + +#define HL_MAX_MAP_PLANES 32767 +#define HL_MAX_MAP_NODES 32767 // because negative shorts are contents +#define HL_MAX_MAP_CLIPNODES 32767 // +#define HL_MAX_MAP_LEAFS 8192 +#define HL_MAX_MAP_VERTS 65535 +#define HL_MAX_MAP_FACES 65535 +#define HL_MAX_MAP_MARKSURFACES 65535 +#define HL_MAX_MAP_TEXINFO 8192 +#define HL_MAX_MAP_EDGES 256000 +#define HL_MAX_MAP_SURFEDGES 512000 +#define HL_MAX_MAP_TEXTURES 512 +#define HL_MAX_MAP_MIPTEX 0x200000 +#define HL_MAX_MAP_LIGHTING 0x200000 +#define HL_MAX_MAP_VISIBILITY 0x200000 + +#define HL_MAX_MAP_PORTALS 65536 + +// key / value pair sizes + +#define MAX_KEY 32 +#define MAX_VALUE 1024 + +//============================================================================= + + +#define HL_BSPVERSION 30 +#define HL_TOOLVERSION 2 + + +typedef struct +{ + int fileofs, filelen; +} hl_lump_t; + +#define HL_LUMP_ENTITIES 0 +#define HL_LUMP_PLANES 1 +#define HL_LUMP_TEXTURES 2 +#define HL_LUMP_VERTEXES 3 +#define HL_LUMP_VISIBILITY 4 +#define HL_LUMP_NODES 5 +#define HL_LUMP_TEXINFO 6 +#define HL_LUMP_FACES 7 +#define HL_LUMP_LIGHTING 8 +#define HL_LUMP_CLIPNODES 9 +#define HL_LUMP_LEAFS 10 +#define HL_LUMP_MARKSURFACES 11 +#define HL_LUMP_EDGES 12 +#define HL_LUMP_SURFEDGES 13 +#define HL_LUMP_MODELS 14 + +#define HL_HEADER_LUMPS 15 + +typedef struct +{ + float mins[3], maxs[3]; + float origin[3]; + int headnode[HL_MAX_MAP_HULLS]; + int visleafs; // not including the solid leaf 0 + int firstface, numfaces; +} hl_dmodel_t; + +typedef struct +{ + int version; + hl_lump_t lumps[HL_HEADER_LUMPS]; +} hl_dheader_t; + +typedef struct +{ + int nummiptex; + int dataofs[4]; // [nummiptex] +} hl_dmiptexlump_t; + +#define MIPLEVELS 4 +typedef struct hl_miptex_s +{ + char name[16]; + unsigned width, height; + unsigned offsets[MIPLEVELS]; // four mip maps stored +} hl_miptex_t; + + +typedef struct +{ + float point[3]; +} hl_dvertex_t; + + +// 0-2 are axial planes +#define PLANE_X 0 +#define PLANE_Y 1 +#define PLANE_Z 2 + +// 3-5 are non-axial planes snapped to the nearest +#define PLANE_ANYX 3 +#define PLANE_ANYY 4 +#define PLANE_ANYZ 5 + +typedef struct +{ + float normal[3]; + float dist; + int type; // PLANE_X - PLANE_ANYZ ?remove? trivial to regenerate +} hl_dplane_t; + + + +#define HL_CONTENTS_EMPTY -1 +#define HL_CONTENTS_SOLID -2 +#define HL_CONTENTS_WATER -3 +#define HL_CONTENTS_SLIME -4 +#define HL_CONTENTS_LAVA -5 +#define HL_CONTENTS_SKY -6 +#define HL_CONTENTS_ORIGIN -7 // removed at csg time +#define HL_CONTENTS_CLIP -8 // changed to contents_solid + +#define HL_CONTENTS_CURRENT_0 -9 +#define HL_CONTENTS_CURRENT_90 -10 +#define HL_CONTENTS_CURRENT_180 -11 +#define HL_CONTENTS_CURRENT_270 -12 +#define HL_CONTENTS_CURRENT_UP -13 +#define HL_CONTENTS_CURRENT_DOWN -14 + +#define HL_CONTENTS_TRANSLUCENT -15 + +// !!! if this is changed, it must be changed in asm_i386.h too !!! +typedef struct +{ + int planenum; + short children[2]; // negative numbers are -(leafs+1), not nodes + short mins[3]; // for sphere culling + short maxs[3]; + unsigned short firstface; + unsigned short numfaces; // counting both sides +} hl_dnode_t; + +typedef struct +{ + int planenum; + short children[2]; // negative numbers are contents +} hl_dclipnode_t; + + +typedef struct hl_texinfo_s +{ + float vecs[2][4]; // [s/t][xyz offset] + int miptex; + int flags; +} hl_texinfo_t; +#define TEX_SPECIAL 1 // sky or slime, no lightmap or 256 subdivision + +// note that edge 0 is never used, because negative edge nums are used for +// counterclockwise use of the edge in a face +typedef struct +{ + unsigned short v[2]; // vertex numbers +} hl_dedge_t; + +#define MAXLIGHTMAPS 4 +typedef struct +{ + short planenum; + short side; + + int firstedge; // we must support > 64k edges + short numedges; + short texinfo; + +// lighting info + byte styles[MAXLIGHTMAPS]; + int lightofs; // start of [numstyles*surfsize] samples +} hl_dface_t; + + +#define AMBIENT_WATER 0 +#define AMBIENT_SKY 1 +#define AMBIENT_SLIME 2 +#define AMBIENT_LAVA 3 + +#define NUM_AMBIENTS 4 // automatic ambient sounds + +// leaf 0 is the generic HL_CONTENTS_SOLID leaf, used for all solid areas +// all other leafs need visibility info +typedef struct +{ + int contents; + int visofs; // -1 = no visibility info + + short mins[3]; // for frustum culling + short maxs[3]; + + unsigned short firstmarksurface; + unsigned short nummarksurfaces; + + byte ambient_level[NUM_AMBIENTS]; +} hl_dleaf_t; + + +//============================================================================ + +#ifndef QUAKE_GAME + +#define ANGLE_UP -1 +#define ANGLE_DOWN -2 + + +// the utilities get to be lazy and just use large static arrays + +extern int hl_nummodels; +extern hl_dmodel_t *hl_dmodels; //[MAX_MAP_MODELS]; +extern int hl_dmodels_checksum; + +extern int hl_visdatasize; +extern byte *hl_dvisdata; //[MAX_MAP_VISIBILITY]; +extern int hl_dvisdata_checksum; + +extern int hl_lightdatasize; +extern byte *hl_dlightdata; //[MAX_MAP_LIGHTING]; +extern int hl_dlightdata_checksum; + +extern int hl_texdatasize; +extern byte *hl_dtexdata; //[MAX_MAP_MIPTEX]; // (dmiptexlump_t) +extern int hl_dtexdata_checksum; + +extern int hl_entdatasize; +extern char *hl_dentdata; //[MAX_MAP_ENTSTRING]; +extern int hl_dentdata_checksum; + +extern int hl_numleafs; +extern hl_dleaf_t *hl_dleafs; //[MAX_MAP_LEAFS]; +extern int hl_dleafs_checksum; + +extern int hl_numplanes; +extern hl_dplane_t *hl_dplanes; //[MAX_MAP_PLANES]; +extern int hl_dplanes_checksum; + +extern int hl_numvertexes; +extern hl_dvertex_t *hl_dvertexes; //[MAX_MAP_VERTS]; +extern int hl_dvertexes_checksum; + +extern int hl_numnodes; +extern hl_dnode_t *hl_dnodes; //[MAX_MAP_NODES]; +extern int hl_dnodes_checksum; + +extern int hl_numtexinfo; +extern hl_texinfo_t *hl_texinfo; //[MAX_MAP_TEXINFO]; +extern int hl_texinfo_checksum; + +extern int hl_numfaces; +extern hl_dface_t *hl_dfaces; //[MAX_MAP_FACES]; +extern int hl_dfaces_checksum; + +extern int hl_numclipnodes; +extern hl_dclipnode_t *hl_dclipnodes; //[MAX_MAP_CLIPNODES]; +extern int hl_dclipnodes_checksum; + +extern int hl_numedges; +extern hl_dedge_t *hl_dedges; //[MAX_MAP_EDGES]; +extern int hl_dedges_checksum; + +extern int hl_nummarksurfaces; +extern unsigned short *hl_dmarksurfaces; //[MAX_MAP_MARKSURFACES]; +extern int hl_dmarksurfaces_checksum; + +extern int hl_numsurfedges; +extern int *hl_dsurfedges; //[MAX_MAP_SURFEDGES]; +extern int hl_dsurfedges_checksum; + +int FastChecksum( void *buffer, int bytes ); + +void HL_AllocMaxBSP( void ); +void HL_FreeMaxBSP( void ); + +void HL_DecompressVis( byte *in, byte *decompressed ); +int HL_CompressVis( byte *vis, byte *dest ); + +void HL_LoadBSPFile( char *filename, int offset, int length ); +void HL_WriteBSPFile( char *filename ); +void HL_PrintBSPFileSizes( void ); +void HL_PrintBSPFileSizes( void ); +void HL_ParseEntities( void ); +void HL_UnparseEntities( void ); + +#endif diff --git a/Projects/Android/jni/rtcw/src/bspc/l_bsp_q1.c b/Projects/Android/jni/rtcw/src/bspc/l_bsp_q1.c new file mode 100644 index 0000000..c9c966e --- /dev/null +++ b/Projects/Android/jni/rtcw/src/bspc/l_bsp_q1.c @@ -0,0 +1,608 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +#include "l_cmd.h" +#include "l_math.h" +#include "l_mem.h" +#include "l_log.h" +#include "../botlib/l_script.h" +#include "l_bsp_q1.h" +#include "l_bsp_ent.h" + +//============================================================================= + +int q1_nummodels; +q1_dmodel_t *q1_dmodels; //[MAX_MAP_MODELS]; + +int q1_visdatasize; +byte *q1_dvisdata; //[MAX_MAP_VISIBILITY]; + +int q1_lightdatasize; +byte *q1_dlightdata; //[MAX_MAP_LIGHTING]; + +int q1_texdatasize; +byte *q1_dtexdata; //[MAX_MAP_MIPTEX]; // (dmiptexlump_t) + +int q1_entdatasize; +char *q1_dentdata; //[MAX_MAP_ENTSTRING]; + +int q1_numleafs; +q1_dleaf_t *q1_dleafs; //[MAX_MAP_LEAFS]; + +int q1_numplanes; +q1_dplane_t *q1_dplanes; //[MAX_MAP_PLANES]; + +int q1_numvertexes; +q1_dvertex_t *q1_dvertexes; //[MAX_MAP_VERTS]; + +int q1_numnodes; +q1_dnode_t *q1_dnodes; //[MAX_MAP_NODES]; + +int q1_numtexinfo; +q1_texinfo_t *q1_texinfo; //[MAX_MAP_TEXINFO]; + +int q1_numfaces; +q1_dface_t *q1_dfaces; //[MAX_MAP_FACES]; + +int q1_numclipnodes; +q1_dclipnode_t *q1_dclipnodes; //[MAX_MAP_CLIPNODES]; + +int q1_numedges; +q1_dedge_t *q1_dedges; //[MAX_MAP_EDGES]; + +int q1_nummarksurfaces; +unsigned short *q1_dmarksurfaces; //[MAX_MAP_MARKSURFACES]; + +int q1_numsurfedges; +int *q1_dsurfedges; //[MAX_MAP_SURFEDGES]; + +//============================================================================= + +int q1_bspallocated = false; +int q1_allocatedbspmem = 0; + +void Q1_AllocMaxBSP( void ) { + //models + q1_nummodels = 0; + q1_dmodels = (q1_dmodel_t *) GetMemory( Q1_MAX_MAP_MODELS * sizeof( q1_dmodel_t ) ); + q1_allocatedbspmem = Q1_MAX_MAP_MODELS * sizeof( q1_dmodel_t ); + //visibility + q1_visdatasize = 0; + q1_dvisdata = (byte *) GetMemory( Q1_MAX_MAP_VISIBILITY * sizeof( byte ) ); + q1_allocatedbspmem += Q1_MAX_MAP_VISIBILITY * sizeof( byte ); + //light data + q1_lightdatasize = 0; + q1_dlightdata = (byte *) GetMemory( Q1_MAX_MAP_LIGHTING * sizeof( byte ) ); + q1_allocatedbspmem += Q1_MAX_MAP_LIGHTING * sizeof( byte ); + //texture data + q1_texdatasize = 0; + q1_dtexdata = (byte *) GetMemory( Q1_MAX_MAP_MIPTEX * sizeof( byte ) ); // (dmiptexlump_t) + q1_allocatedbspmem += Q1_MAX_MAP_MIPTEX * sizeof( byte ); + //entities + q1_entdatasize = 0; + q1_dentdata = (char *) GetMemory( Q1_MAX_MAP_ENTSTRING * sizeof( char ) ); + q1_allocatedbspmem += Q1_MAX_MAP_ENTSTRING * sizeof( char ); + //leaves + q1_numleafs = 0; + q1_dleafs = (q1_dleaf_t *) GetMemory( Q1_MAX_MAP_LEAFS * sizeof( q1_dleaf_t ) ); + q1_allocatedbspmem += Q1_MAX_MAP_LEAFS * sizeof( q1_dleaf_t ); + //planes + q1_numplanes = 0; + q1_dplanes = (q1_dplane_t *) GetMemory( Q1_MAX_MAP_PLANES * sizeof( q1_dplane_t ) ); + q1_allocatedbspmem += Q1_MAX_MAP_PLANES * sizeof( q1_dplane_t ); + //vertexes + q1_numvertexes = 0; + q1_dvertexes = (q1_dvertex_t *) GetMemory( Q1_MAX_MAP_VERTS * sizeof( q1_dvertex_t ) ); + q1_allocatedbspmem += Q1_MAX_MAP_VERTS * sizeof( q1_dvertex_t ); + //nodes + q1_numnodes = 0; + q1_dnodes = (q1_dnode_t *) GetMemory( Q1_MAX_MAP_NODES * sizeof( q1_dnode_t ) ); + q1_allocatedbspmem += Q1_MAX_MAP_NODES * sizeof( q1_dnode_t ); + //texture info + q1_numtexinfo = 0; + q1_texinfo = (q1_texinfo_t *) GetMemory( Q1_MAX_MAP_TEXINFO * sizeof( q1_texinfo_t ) ); + q1_allocatedbspmem += Q1_MAX_MAP_TEXINFO * sizeof( q1_texinfo_t ); + //faces + q1_numfaces = 0; + q1_dfaces = (q1_dface_t *) GetMemory( Q1_MAX_MAP_FACES * sizeof( q1_dface_t ) ); + q1_allocatedbspmem += Q1_MAX_MAP_FACES * sizeof( q1_dface_t ); + //clip nodes + q1_numclipnodes = 0; + q1_dclipnodes = (q1_dclipnode_t *) GetMemory( Q1_MAX_MAP_CLIPNODES * sizeof( q1_dclipnode_t ) ); + q1_allocatedbspmem += Q1_MAX_MAP_CLIPNODES * sizeof( q1_dclipnode_t ); + //edges + q1_numedges = 0; + q1_dedges = (q1_dedge_t *) GetMemory( Q1_MAX_MAP_EDGES * sizeof( q1_dedge_t ) ); + q1_allocatedbspmem += Q1_MAX_MAP_EDGES, sizeof( q1_dedge_t ); + //mark surfaces + q1_nummarksurfaces = 0; + q1_dmarksurfaces = (unsigned short *) GetMemory( Q1_MAX_MAP_MARKSURFACES * sizeof( unsigned short ) ); + q1_allocatedbspmem += Q1_MAX_MAP_MARKSURFACES * sizeof( unsigned short ); + //surface edges + q1_numsurfedges = 0; + q1_dsurfedges = (int *) GetMemory( Q1_MAX_MAP_SURFEDGES * sizeof( int ) ); + q1_allocatedbspmem += Q1_MAX_MAP_SURFEDGES * sizeof( int ); + //print allocated memory + Log_Print( "allocated " ); + PrintMemorySize( q1_allocatedbspmem ); + Log_Print( " of BSP memory\n" ); +} //end of the function Q1_AllocMaxBSP + +void Q1_FreeMaxBSP( void ) { + //models + q1_nummodels = 0; + FreeMemory( q1_dmodels ); + q1_dmodels = NULL; + //visibility + q1_visdatasize = 0; + FreeMemory( q1_dvisdata ); + q1_dvisdata = NULL; + //light data + q1_lightdatasize = 0; + FreeMemory( q1_dlightdata ); + q1_dlightdata = NULL; + //texture data + q1_texdatasize = 0; + FreeMemory( q1_dtexdata ); + q1_dtexdata = NULL; + //entities + q1_entdatasize = 0; + FreeMemory( q1_dentdata ); + q1_dentdata = NULL; + //leaves + q1_numleafs = 0; + FreeMemory( q1_dleafs ); + q1_dleafs = NULL; + //planes + q1_numplanes = 0; + FreeMemory( q1_dplanes ); + q1_dplanes = NULL; + //vertexes + q1_numvertexes = 0; + FreeMemory( q1_dvertexes ); + q1_dvertexes = NULL; + //nodes + q1_numnodes = 0; + FreeMemory( q1_dnodes ); + q1_dnodes = NULL; + //texture info + q1_numtexinfo = 0; + FreeMemory( q1_texinfo ); + q1_texinfo = NULL; + //faces + q1_numfaces = 0; + FreeMemory( q1_dfaces ); + q1_dfaces = NULL; + //clip nodes + q1_numclipnodes = 0; + FreeMemory( q1_dclipnodes ); + q1_dclipnodes = NULL; + //edges + q1_numedges = 0; + FreeMemory( q1_dedges ); + q1_dedges = NULL; + //mark surfaces + q1_nummarksurfaces = 0; + FreeMemory( q1_dmarksurfaces ); + q1_dmarksurfaces = NULL; + //surface edges + q1_numsurfedges = 0; + FreeMemory( q1_dsurfedges ); + q1_dsurfedges = NULL; + // + Log_Print( "freed " ); + PrintMemorySize( q1_allocatedbspmem ); + Log_Print( " of BSP memory\n" ); + q1_allocatedbspmem = 0; +} //end of the function Q1_FreeMaxBSP +//#endif //ME + +/* +============= +Q1_SwapBSPFile + +Byte swaps all data in a bsp file. +============= +*/ +void Q1_SwapBSPFile( qboolean todisk ) { + int i, j, c; + q1_dmodel_t *d; + q1_dmiptexlump_t *mtl; + + +// models + for ( i = 0 ; i < q1_nummodels ; i++ ) + { + d = &q1_dmodels[i]; + + for ( j = 0 ; j < Q1_MAX_MAP_HULLS ; j++ ) + d->headnode[j] = LittleLong( d->headnode[j] ); + + d->visleafs = LittleLong( d->visleafs ); + d->firstface = LittleLong( d->firstface ); + d->numfaces = LittleLong( d->numfaces ); + + for ( j = 0 ; j < 3 ; j++ ) + { + d->mins[j] = LittleFloat( d->mins[j] ); + d->maxs[j] = LittleFloat( d->maxs[j] ); + d->origin[j] = LittleFloat( d->origin[j] ); + } + } + +// +// vertexes +// + for ( i = 0 ; i < q1_numvertexes ; i++ ) + { + for ( j = 0 ; j < 3 ; j++ ) + q1_dvertexes[i].point[j] = LittleFloat( q1_dvertexes[i].point[j] ); + } + +// +// planes +// + for ( i = 0 ; i < q1_numplanes ; i++ ) + { + for ( j = 0 ; j < 3 ; j++ ) + q1_dplanes[i].normal[j] = LittleFloat( q1_dplanes[i].normal[j] ); + q1_dplanes[i].dist = LittleFloat( q1_dplanes[i].dist ); + q1_dplanes[i].type = LittleLong( q1_dplanes[i].type ); + } + +// +// texinfos +// + for ( i = 0 ; i < q1_numtexinfo ; i++ ) + { + for ( j = 0 ; j < 8 ; j++ ) + q1_texinfo[i].vecs[0][j] = LittleFloat( q1_texinfo[i].vecs[0][j] ); + q1_texinfo[i].miptex = LittleLong( q1_texinfo[i].miptex ); + q1_texinfo[i].flags = LittleLong( q1_texinfo[i].flags ); + } + +// +// faces +// + for ( i = 0 ; i < q1_numfaces ; i++ ) + { + q1_dfaces[i].texinfo = LittleShort( q1_dfaces[i].texinfo ); + q1_dfaces[i].planenum = LittleShort( q1_dfaces[i].planenum ); + q1_dfaces[i].side = LittleShort( q1_dfaces[i].side ); + q1_dfaces[i].lightofs = LittleLong( q1_dfaces[i].lightofs ); + q1_dfaces[i].firstedge = LittleLong( q1_dfaces[i].firstedge ); + q1_dfaces[i].numedges = LittleShort( q1_dfaces[i].numedges ); + } + +// +// nodes +// + for ( i = 0 ; i < q1_numnodes ; i++ ) + { + q1_dnodes[i].planenum = LittleLong( q1_dnodes[i].planenum ); + for ( j = 0 ; j < 3 ; j++ ) + { + q1_dnodes[i].mins[j] = LittleShort( q1_dnodes[i].mins[j] ); + q1_dnodes[i].maxs[j] = LittleShort( q1_dnodes[i].maxs[j] ); + } + q1_dnodes[i].children[0] = LittleShort( q1_dnodes[i].children[0] ); + q1_dnodes[i].children[1] = LittleShort( q1_dnodes[i].children[1] ); + q1_dnodes[i].firstface = LittleShort( q1_dnodes[i].firstface ); + q1_dnodes[i].numfaces = LittleShort( q1_dnodes[i].numfaces ); + } + +// +// leafs +// + for ( i = 0 ; i < q1_numleafs ; i++ ) + { + q1_dleafs[i].contents = LittleLong( q1_dleafs[i].contents ); + for ( j = 0 ; j < 3 ; j++ ) + { + q1_dleafs[i].mins[j] = LittleShort( q1_dleafs[i].mins[j] ); + q1_dleafs[i].maxs[j] = LittleShort( q1_dleafs[i].maxs[j] ); + } + + q1_dleafs[i].firstmarksurface = LittleShort( q1_dleafs[i].firstmarksurface ); + q1_dleafs[i].nummarksurfaces = LittleShort( q1_dleafs[i].nummarksurfaces ); + q1_dleafs[i].visofs = LittleLong( q1_dleafs[i].visofs ); + } + +// +// clipnodes +// + for ( i = 0 ; i < q1_numclipnodes ; i++ ) + { + q1_dclipnodes[i].planenum = LittleLong( q1_dclipnodes[i].planenum ); + q1_dclipnodes[i].children[0] = LittleShort( q1_dclipnodes[i].children[0] ); + q1_dclipnodes[i].children[1] = LittleShort( q1_dclipnodes[i].children[1] ); + } + +// +// miptex +// + if ( q1_texdatasize ) { + mtl = (q1_dmiptexlump_t *)q1_dtexdata; + if ( todisk ) { + c = mtl->nummiptex; + } else { + c = LittleLong( mtl->nummiptex ); + } + mtl->nummiptex = LittleLong( mtl->nummiptex ); + for ( i = 0 ; i < c ; i++ ) + mtl->dataofs[i] = LittleLong( mtl->dataofs[i] ); + } + +// +// marksurfaces +// + for ( i = 0 ; i < q1_nummarksurfaces ; i++ ) + q1_dmarksurfaces[i] = LittleShort( q1_dmarksurfaces[i] ); + +// +// surfedges +// + for ( i = 0 ; i < q1_numsurfedges ; i++ ) + q1_dsurfedges[i] = LittleLong( q1_dsurfedges[i] ); + +// +// edges +// + for ( i = 0 ; i < q1_numedges ; i++ ) + { + q1_dedges[i].v[0] = LittleShort( q1_dedges[i].v[0] ); + q1_dedges[i].v[1] = LittleShort( q1_dedges[i].v[1] ); + } +} + + +q1_dheader_t *q1_header; + +int Q1_CopyLump( int lump, void *dest, int size ) { + int length, ofs; + + length = q1_header->lumps[lump].filelen; + ofs = q1_header->lumps[lump].fileofs; + + if ( length % size ) { + Error( "Q1_LoadBSPFile: odd lump size" ); + } + + memcpy( dest, (byte *)q1_header + ofs, length ); + + return length / size; +} + +/* +============= +Q1_LoadBSPFile +============= +*/ +void Q1_LoadBSPFile( char *filename, int offset, int length ) { + int i; + +// +// load the file header +// + LoadFile( filename, (void **)&q1_header, offset, length ); + +// swap the header + for ( i = 0 ; i < sizeof( q1_dheader_t ) / 4 ; i++ ) + ( (int *)q1_header )[i] = LittleLong( ( (int *)q1_header )[i] ); + + if ( q1_header->version != Q1_BSPVERSION ) { + Error( "%s is version %i, not %i", filename, i, Q1_BSPVERSION ); + } + + q1_nummodels = Q1_CopyLump( Q1_LUMP_MODELS, q1_dmodels, sizeof( q1_dmodel_t ) ); + q1_numvertexes = Q1_CopyLump( Q1_LUMP_VERTEXES, q1_dvertexes, sizeof( q1_dvertex_t ) ); + q1_numplanes = Q1_CopyLump( Q1_LUMP_PLANES, q1_dplanes, sizeof( q1_dplane_t ) ); + q1_numleafs = Q1_CopyLump( Q1_LUMP_LEAFS, q1_dleafs, sizeof( q1_dleaf_t ) ); + q1_numnodes = Q1_CopyLump( Q1_LUMP_NODES, q1_dnodes, sizeof( q1_dnode_t ) ); + q1_numtexinfo = Q1_CopyLump( Q1_LUMP_TEXINFO, q1_texinfo, sizeof( q1_texinfo_t ) ); + q1_numclipnodes = Q1_CopyLump( Q1_LUMP_CLIPNODES, q1_dclipnodes, sizeof( q1_dclipnode_t ) ); + q1_numfaces = Q1_CopyLump( Q1_LUMP_FACES, q1_dfaces, sizeof( q1_dface_t ) ); + q1_nummarksurfaces = Q1_CopyLump( Q1_LUMP_MARKSURFACES, q1_dmarksurfaces, sizeof( q1_dmarksurfaces[0] ) ); + q1_numsurfedges = Q1_CopyLump( Q1_LUMP_SURFEDGES, q1_dsurfedges, sizeof( q1_dsurfedges[0] ) ); + q1_numedges = Q1_CopyLump( Q1_LUMP_EDGES, q1_dedges, sizeof( q1_dedge_t ) ); + + q1_texdatasize = Q1_CopyLump( Q1_LUMP_TEXTURES, q1_dtexdata, 1 ); + q1_visdatasize = Q1_CopyLump( Q1_LUMP_VISIBILITY, q1_dvisdata, 1 ); + q1_lightdatasize = Q1_CopyLump( Q1_LUMP_LIGHTING, q1_dlightdata, 1 ); + q1_entdatasize = Q1_CopyLump( Q1_LUMP_ENTITIES, q1_dentdata, 1 ); + + FreeMemory( q1_header ); // everything has been copied out + +// +// swap everything +// + Q1_SwapBSPFile( false ); +} + +//============================================================================ + +FILE *q1_wadfile; +q1_dheader_t q1_outheader; + +void Q1_AddLump( int lumpnum, void *data, int len ) { + q1_lump_t *lump; + + lump = &q1_header->lumps[lumpnum]; + + lump->fileofs = LittleLong( ftell( q1_wadfile ) ); + lump->filelen = LittleLong( len ); + SafeWrite( q1_wadfile, data, ( len + 3 ) & ~3 ); +} + +/* +============= +Q1_WriteBSPFile + +Swaps the bsp file in place, so it should not be referenced again +============= +*/ +void Q1_WriteBSPFile( char *filename ) { + q1_header = &q1_outheader; + memset( q1_header, 0, sizeof( q1_dheader_t ) ); + + Q1_SwapBSPFile( true ); + + q1_header->version = LittleLong( Q1_BSPVERSION ); + + q1_wadfile = SafeOpenWrite( filename ); + SafeWrite( q1_wadfile, q1_header, sizeof( q1_dheader_t ) ); // overwritten later + + Q1_AddLump( Q1_LUMP_PLANES, q1_dplanes, q1_numplanes * sizeof( q1_dplane_t ) ); + Q1_AddLump( Q1_LUMP_LEAFS, q1_dleafs, q1_numleafs * sizeof( q1_dleaf_t ) ); + Q1_AddLump( Q1_LUMP_VERTEXES, q1_dvertexes, q1_numvertexes * sizeof( q1_dvertex_t ) ); + Q1_AddLump( Q1_LUMP_NODES, q1_dnodes, q1_numnodes * sizeof( q1_dnode_t ) ); + Q1_AddLump( Q1_LUMP_TEXINFO, q1_texinfo, q1_numtexinfo * sizeof( q1_texinfo_t ) ); + Q1_AddLump( Q1_LUMP_FACES, q1_dfaces, q1_numfaces * sizeof( q1_dface_t ) ); + Q1_AddLump( Q1_LUMP_CLIPNODES, q1_dclipnodes, q1_numclipnodes * sizeof( q1_dclipnode_t ) ); + Q1_AddLump( Q1_LUMP_MARKSURFACES, q1_dmarksurfaces, q1_nummarksurfaces * sizeof( q1_dmarksurfaces[0] ) ); + Q1_AddLump( Q1_LUMP_SURFEDGES, q1_dsurfedges, q1_numsurfedges * sizeof( q1_dsurfedges[0] ) ); + Q1_AddLump( Q1_LUMP_EDGES, q1_dedges, q1_numedges * sizeof( q1_dedge_t ) ); + Q1_AddLump( Q1_LUMP_MODELS, q1_dmodels, q1_nummodels * sizeof( q1_dmodel_t ) ); + + Q1_AddLump( Q1_LUMP_LIGHTING, q1_dlightdata, q1_lightdatasize ); + Q1_AddLump( Q1_LUMP_VISIBILITY, q1_dvisdata, q1_visdatasize ); + Q1_AddLump( Q1_LUMP_ENTITIES, q1_dentdata, q1_entdatasize ); + Q1_AddLump( Q1_LUMP_TEXTURES, q1_dtexdata, q1_texdatasize ); + + fseek( q1_wadfile, 0, SEEK_SET ); + SafeWrite( q1_wadfile, q1_header, sizeof( q1_dheader_t ) ); + fclose( q1_wadfile ); +} + +//============================================================================ + +/* +============= +Q1_PrintBSPFileSizes + +Dumps info about current file +============= +*/ +void Q1_PrintBSPFileSizes( void ) { + printf( "%5i planes %6i\n" + ,q1_numplanes, (int)( q1_numplanes * sizeof( q1_dplane_t ) ) ); + printf( "%5i vertexes %6i\n" + ,q1_numvertexes, (int)( q1_numvertexes * sizeof( q1_dvertex_t ) ) ); + printf( "%5i nodes %6i\n" + ,q1_numnodes, (int)( q1_numnodes * sizeof( q1_dnode_t ) ) ); + printf( "%5i texinfo %6i\n" + ,q1_numtexinfo, (int)( q1_numtexinfo * sizeof( q1_texinfo_t ) ) ); + printf( "%5i faces %6i\n" + ,q1_numfaces, (int)( q1_numfaces * sizeof( q1_dface_t ) ) ); + printf( "%5i clipnodes %6i\n" + ,q1_numclipnodes, (int)( q1_numclipnodes * sizeof( q1_dclipnode_t ) ) ); + printf( "%5i leafs %6i\n" + ,q1_numleafs, (int)( q1_numleafs * sizeof( q1_dleaf_t ) ) ); + printf( "%5i marksurfaces %6i\n" + ,q1_nummarksurfaces, (int)( q1_nummarksurfaces * sizeof( q1_dmarksurfaces[0] ) ) ); + printf( "%5i surfedges %6i\n" + ,q1_numsurfedges, (int)( q1_numsurfedges * sizeof( q1_dmarksurfaces[0] ) ) ); + printf( "%5i edges %6i\n" + ,q1_numedges, (int)( q1_numedges * sizeof( q1_dedge_t ) ) ); + if ( !q1_texdatasize ) { + printf( " 0 textures 0\n" ); + } else { + printf( "%5i textures %6i\n",( (q1_dmiptexlump_t*)q1_dtexdata )->nummiptex, q1_texdatasize ); + } + printf( " lightdata %6i\n", q1_lightdatasize ); + printf( " visdata %6i\n", q1_visdatasize ); + printf( " entdata %6i\n", q1_entdatasize ); +} //end of the function Q1_PrintBSPFileSizes + + +/* +================ +Q1_ParseEntities + +Parses the dentdata string into entities +================ +*/ +void Q1_ParseEntities( void ) { + script_t *script; + + num_entities = 0; + script = LoadScriptMemory( q1_dentdata, q1_entdatasize, "*Quake1 bsp file" ); + SetScriptFlags( script, SCFL_NOSTRINGWHITESPACES | + SCFL_NOSTRINGESCAPECHARS ); + + while ( ParseEntity( script ) ) + { + } //end while + + FreeScript( script ); +} //end of the function Q1_ParseEntities + + +/* +================ +Q1_UnparseEntities + +Generates the dentdata string from all the entities +================ +*/ +void Q1_UnparseEntities( void ) { + char *buf, *end; + epair_t *ep; + char line[2048]; + int i; + + buf = q1_dentdata; + end = buf; + *end = 0; + + for ( i = 0 ; i < num_entities ; i++ ) + { + ep = entities[i].epairs; + if ( !ep ) { + continue; // ent got removed + + } + strcat( end,"{\n" ); + end += 2; + + for ( ep = entities[i].epairs ; ep ; ep = ep->next ) + { + sprintf( line, "\"%s\" \"%s\"\n", ep->key, ep->value ); + strcat( end, line ); + end += strlen( line ); + } + strcat( end,"}\n" ); + end += 2; + + if ( end > buf + Q1_MAX_MAP_ENTSTRING ) { + Error( "Entity text too long" ); + } + } + q1_entdatasize = end - buf + 1; +} //end of the function Q1_UnparseEntities diff --git a/Projects/Android/jni/rtcw/src/bspc/l_bsp_q1.h b/Projects/Android/jni/rtcw/src/bspc/l_bsp_q1.h new file mode 100644 index 0000000..dcd8b8e --- /dev/null +++ b/Projects/Android/jni/rtcw/src/bspc/l_bsp_q1.h @@ -0,0 +1,282 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + + +// upper design bounds + +#define Q1_MAX_MAP_HULLS 4 + +#define Q1_MAX_MAP_MODELS 256 +#define Q1_MAX_MAP_BRUSHES 4096 +#define Q1_MAX_MAP_ENTITIES 1024 +#define Q1_MAX_MAP_ENTSTRING 65536 + +#define Q1_MAX_MAP_PLANES 8192 +#define Q1_MAX_MAP_NODES 32767 // because negative shorts are contents +#define Q1_MAX_MAP_CLIPNODES 32767 // +#define Q1_MAX_MAP_LEAFS 32767 // +#define Q1_MAX_MAP_VERTS 65535 +#define Q1_MAX_MAP_FACES 65535 +#define Q1_MAX_MAP_MARKSURFACES 65535 +#define Q1_MAX_MAP_TEXINFO 4096 +#define Q1_MAX_MAP_EDGES 256000 +#define Q1_MAX_MAP_SURFEDGES 512000 +#define Q1_MAX_MAP_MIPTEX 0x200000 +#define Q1_MAX_MAP_LIGHTING 0x100000 +#define Q1_MAX_MAP_VISIBILITY 0x100000 + +// key / value pair sizes + +#define MAX_KEY 32 +#define MAX_VALUE 1024 + +//============================================================================= + + +#define Q1_BSPVERSION 29 + +typedef struct +{ + int fileofs, filelen; +} q1_lump_t; + +#define Q1_LUMP_ENTITIES 0 +#define Q1_LUMP_PLANES 1 +#define Q1_LUMP_TEXTURES 2 +#define Q1_LUMP_VERTEXES 3 +#define Q1_LUMP_VISIBILITY 4 +#define Q1_LUMP_NODES 5 +#define Q1_LUMP_TEXINFO 6 +#define Q1_LUMP_FACES 7 +#define Q1_LUMP_LIGHTING 8 +#define Q1_LUMP_CLIPNODES 9 +#define Q1_LUMP_LEAFS 10 +#define Q1_LUMP_MARKSURFACES 11 +#define Q1_LUMP_EDGES 12 +#define Q1_LUMP_SURFEDGES 13 +#define Q1_LUMP_MODELS 14 + +#define Q1_HEADER_LUMPS 15 + +typedef struct +{ + float mins[3], maxs[3]; + float origin[3]; + int headnode[Q1_MAX_MAP_HULLS]; + int visleafs; // not including the solid leaf 0 + int firstface, numfaces; +} q1_dmodel_t; + +typedef struct +{ + int version; + q1_lump_t lumps[Q1_HEADER_LUMPS]; +} q1_dheader_t; + +typedef struct +{ + int nummiptex; + int dataofs[4]; // [nummiptex] +} q1_dmiptexlump_t; + +#define MIPLEVELS 4 +typedef struct q1_miptex_s +{ + char name[16]; + unsigned width, height; + unsigned offsets[MIPLEVELS]; // four mip maps stored +} q1_miptex_t; + + +typedef struct +{ + float point[3]; +} q1_dvertex_t; + + +// 0-2 are axial planes +#define PLANE_X 0 +#define PLANE_Y 1 +#define PLANE_Z 2 + +// 3-5 are non-axial planes snapped to the nearest +#define PLANE_ANYX 3 +#define PLANE_ANYY 4 +#define PLANE_ANYZ 5 + +typedef struct +{ + float normal[3]; + float dist; + int type; // PLANE_X - PLANE_ANYZ ?remove? trivial to regenerate +} q1_dplane_t; + + + +#define Q1_CONTENTS_EMPTY -1 +#define Q1_CONTENTS_SOLID -2 +#define Q1_CONTENTS_WATER -3 +#define Q1_CONTENTS_SLIME -4 +#define Q1_CONTENTS_LAVA -5 +#define Q1_CONTENTS_SKY -6 + +// !!! if this is changed, it must be changed in asm_i386.h too !!! +typedef struct +{ + int planenum; + short children[2]; // negative numbers are -(leafs+1), not nodes + short mins[3]; // for sphere culling + short maxs[3]; + unsigned short firstface; + unsigned short numfaces; // counting both sides +} q1_dnode_t; + +typedef struct +{ + int planenum; + short children[2]; // negative numbers are contents +} q1_dclipnode_t; + + +typedef struct q1_texinfo_s +{ + float vecs[2][4]; // [s/t][xyz offset] + int miptex; + int flags; +} q1_texinfo_t; +#define TEX_SPECIAL 1 // sky or slime, no lightmap or 256 subdivision + +// note that edge 0 is never used, because negative edge nums are used for +// counterclockwise use of the edge in a face +typedef struct +{ + unsigned short v[2]; // vertex numbers +} q1_dedge_t; + +#define MAXLIGHTMAPS 4 +typedef struct +{ + short planenum; + short side; + + int firstedge; // we must support > 64k edges + short numedges; + short texinfo; + +// lighting info + byte styles[MAXLIGHTMAPS]; + int lightofs; // start of [numstyles*surfsize] samples +} q1_dface_t; + + + +#define AMBIENT_WATER 0 +#define AMBIENT_SKY 1 +#define AMBIENT_SLIME 2 +#define AMBIENT_LAVA 3 + +#define NUM_AMBIENTS 4 // automatic ambient sounds + +// leaf 0 is the generic Q1_CONTENTS_SOLID leaf, used for all solid areas +// all other leafs need visibility info +typedef struct +{ + int contents; + int visofs; // -1 = no visibility info + + short mins[3]; // for frustum culling + short maxs[3]; + + unsigned short firstmarksurface; + unsigned short nummarksurfaces; + + byte ambient_level[NUM_AMBIENTS]; +} q1_dleaf_t; + +//============================================================================ + +#ifndef QUAKE_GAME + +// the utilities get to be lazy and just use large static arrays + +extern int q1_nummodels; +extern q1_dmodel_t *q1_dmodels; //[MAX_MAP_MODELS]; + +extern int q1_visdatasize; +extern byte *q1_dvisdata; //[MAX_MAP_VISIBILITY]; + +extern int q1_lightdatasize; +extern byte *q1_dlightdata; //[MAX_MAP_LIGHTING]; + +extern int q1_texdatasize; +extern byte *q1_dtexdata; //[MAX_MAP_MIPTEX]; // (dmiptexlump_t) + +extern int q1_entdatasize; +extern char *q1_dentdata; //[MAX_MAP_ENTSTRING]; + +extern int q1_numleafs; +extern q1_dleaf_t *q1_dleafs; //[MAX_MAP_LEAFS]; + +extern int q1_numplanes; +extern q1_dplane_t *q1_dplanes; //[MAX_MAP_PLANES]; + +extern int q1_numvertexes; +extern q1_dvertex_t *q1_dvertexes; //[MAX_MAP_VERTS]; + +extern int q1_numnodes; +extern q1_dnode_t *q1_dnodes; //[MAX_MAP_NODES]; + +extern int q1_numtexinfo; +extern q1_texinfo_t *q1_texinfo; //[MAX_MAP_TEXINFO]; + +extern int q1_numfaces; +extern q1_dface_t *q1_dfaces; //[MAX_MAP_FACES]; + +extern int q1_numclipnodes; +extern q1_dclipnode_t *q1_dclipnodes; //[MAX_MAP_CLIPNODES]; + +extern int q1_numedges; +extern q1_dedge_t *q1_dedges; //[MAX_MAP_EDGES]; + +extern int q1_nummarksurfaces; +extern unsigned short *q1_dmarksurfaces; //[MAX_MAP_MARKSURFACES]; + +extern int q1_numsurfedges; +extern int *q1_dsurfedges; //[MAX_MAP_SURFEDGES]; + + +void Q1_AllocMaxBSP( void ); +void Q1_FreeMaxBSP( void ); +void Q1_LoadBSPFile( char *filename, int offset, int length ); +void Q1_WriteBSPFile( char *filename ); +void Q1_PrintBSPFileSizes( void ); +void Q1_ParseEntities( void ); +void Q1_UnparseEntities( void ); + +#endif diff --git a/Projects/Android/jni/rtcw/src/bspc/l_bsp_q2.c b/Projects/Android/jni/rtcw/src/bspc/l_bsp_q2.c new file mode 100644 index 0000000..f3c0d20 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/bspc/l_bsp_q2.c @@ -0,0 +1,1139 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +#include "l_cmd.h" +#include "l_math.h" +#include "l_mem.h" +#include "l_log.h" +#include "l_poly.h" +#include "../botlib/l_script.h" +#include "q2files.h" +#include "l_bsp_q2.h" +#include "l_bsp_ent.h" + +#define q2_dmodel_t dmodel_t +#define q2_lump_t lump_t +#define q2_dheader_t dheader_t +#define q2_dmodel_t dmodel_t +#define q2_dvertex_t dvertex_t +#define q2_dplane_t dplane_t +#define q2_dnode_t dnode_t +#define q2_texinfo_t texinfo_t +#define q2_dedge_t dedge_t +#define q2_dface_t dface_t +#define q2_dleaf_t dleaf_t +#define q2_dbrushside_t dbrushside_t +#define q2_dbrush_t dbrush_t +#define q2_dvis_t dvis_t +#define q2_dareaportal_t dareaportal_t +#define q2_darea_t darea_t + +#define q2_nummodels nummodels +#define q2_dmodels dmodels +#define q2_numleafs numleafs +#define q2_dleafs dleafs +#define q2_numplanes numplanes +#define q2_dplanes dplanes +#define q2_numvertexes numvertexes +#define q2_dvertexes dvertexes +#define q2_numnodes numnodes +#define q2_dnodes dnodes +#define q2_numtexinfo numtexinfo +#define q2_texinfo texinfo +#define q2_numfaces numfaces +#define q2_dfaces dfaces +#define q2_numedges numedges +#define q2_dedges dedges +#define q2_numleaffaces numleaffaces +#define q2_dleaffaces dleaffaces +#define q2_numleafbrushes numleafbrushes +#define q2_dleafbrushes dleafbrushes +#define q2_dsurfedges dsurfedges +#define q2_numbrushes numbrushes +#define q2_dbrushes dbrushes +#define q2_numbrushsides numbrushsides +#define q2_dbrushsides dbrushsides +#define q2_numareas numareas +#define q2_dareas dareas +#define q2_numareaportals numareaportals +#define q2_dareaportals dareaportals + +void GetLeafNums( void ); + +//============================================================================= + +int nummodels; +dmodel_t *dmodels; //[MAX_MAP_MODELS]; + +int visdatasize; +byte *dvisdata; //[MAX_MAP_VISIBILITY]; +dvis_t *dvis; // = (dvis_t *)dvisdata; + +int lightdatasize; +byte *dlightdata; //[MAX_MAP_LIGHTING]; + +int entdatasize; +char *dentdata; //[MAX_MAP_ENTSTRING]; + +int numleafs; +dleaf_t *dleafs; //[MAX_MAP_LEAFS]; + +int numplanes; +dplane_t *dplanes; //[MAX_MAP_PLANES]; + +int numvertexes; +dvertex_t *dvertexes; //[MAX_MAP_VERTS]; + +int numnodes; +dnode_t *dnodes; //[MAX_MAP_NODES]; + +//NOTE: must be static for q2 .map to q2 .bsp +int numtexinfo; +texinfo_t texinfo[MAX_MAP_TEXINFO]; + +int numfaces; +dface_t *dfaces; //[MAX_MAP_FACES]; + +int numedges; +dedge_t *dedges; //[MAX_MAP_EDGES]; + +int numleaffaces; +unsigned short *dleaffaces; //[MAX_MAP_LEAFFACES]; + +int numleafbrushes; +unsigned short *dleafbrushes; //[MAX_MAP_LEAFBRUSHES]; + +int numsurfedges; +int *dsurfedges; //[MAX_MAP_SURFEDGES]; + +int numbrushes; +dbrush_t *dbrushes; //[MAX_MAP_BRUSHES]; + +int numbrushsides; +dbrushside_t *dbrushsides; //[MAX_MAP_BRUSHSIDES]; + +int numareas; +darea_t *dareas; //[MAX_MAP_AREAS]; + +int numareaportals; +dareaportal_t *dareaportals; //[MAX_MAP_AREAPORTALS]; + +#define MAX_MAP_DPOP 256 +byte dpop[MAX_MAP_DPOP]; + +// +char brushsidetextured[MAX_MAP_BRUSHSIDES]; + +//#ifdef ME + +int bspallocated = false; +int allocatedbspmem = 0; + +void Q2_AllocMaxBSP( void ) { + //models + nummodels = 0; + dmodels = (dmodel_t *) GetClearedMemory( MAX_MAP_MODELS * sizeof( dmodel_t ) ); + allocatedbspmem += MAX_MAP_MODELS * sizeof( dmodel_t ); + //vis data + visdatasize = 0; + dvisdata = (byte *) GetClearedMemory( MAX_MAP_VISIBILITY * sizeof( byte ) ); + dvis = (dvis_t *) dvisdata; + allocatedbspmem += MAX_MAP_VISIBILITY * sizeof( byte ); + //light data + lightdatasize = 0; + dlightdata = (byte *) GetClearedMemory( MAX_MAP_LIGHTING * sizeof( byte ) ); + allocatedbspmem += MAX_MAP_LIGHTING * sizeof( byte ); + //entity data + entdatasize = 0; + dentdata = (char *) GetClearedMemory( MAX_MAP_ENTSTRING * sizeof( char ) ); + allocatedbspmem += MAX_MAP_ENTSTRING * sizeof( char ); + //leafs + numleafs = 0; + dleafs = (dleaf_t *) GetClearedMemory( MAX_MAP_LEAFS * sizeof( dleaf_t ) ); + allocatedbspmem += MAX_MAP_LEAFS * sizeof( dleaf_t ); + //planes + numplanes = 0; + dplanes = (dplane_t *) GetClearedMemory( MAX_MAP_PLANES * sizeof( dplane_t ) ); + allocatedbspmem += MAX_MAP_PLANES * sizeof( dplane_t ); + //vertexes + numvertexes = 0; + dvertexes = (dvertex_t *) GetClearedMemory( MAX_MAP_VERTS * sizeof( dvertex_t ) ); + allocatedbspmem += MAX_MAP_VERTS * sizeof( dvertex_t ); + //nodes + numnodes = 0; + dnodes = (dnode_t *) GetClearedMemory( MAX_MAP_NODES * sizeof( dnode_t ) ); + allocatedbspmem += MAX_MAP_NODES * sizeof( dnode_t ); + /* + //texture info + numtexinfo = 0; + texinfo = (texinfo_t *) GetClearedMemory(MAX_MAP_TEXINFO * sizeof(texinfo_t)); + allocatedbspmem += MAX_MAP_TEXINFO * sizeof(texinfo_t); + // + */ + //faces + numfaces = 0; + dfaces = (dface_t *) GetClearedMemory( MAX_MAP_FACES * sizeof( dface_t ) ); + allocatedbspmem += MAX_MAP_FACES * sizeof( dface_t ); + //edges + numedges = 0; + dedges = (dedge_t *) GetClearedMemory( MAX_MAP_EDGES * sizeof( dedge_t ) ); + allocatedbspmem += MAX_MAP_EDGES * sizeof( dedge_t ); + //leaf faces + numleaffaces = 0; + dleaffaces = (unsigned short *) GetClearedMemory( MAX_MAP_LEAFFACES * sizeof( unsigned short ) ); + allocatedbspmem += MAX_MAP_LEAFFACES * sizeof( unsigned short ); + //leaf brushes + numleafbrushes = 0; + dleafbrushes = (unsigned short *) GetClearedMemory( MAX_MAP_LEAFBRUSHES * sizeof( unsigned short ) ); + allocatedbspmem += MAX_MAP_LEAFBRUSHES * sizeof( unsigned short ); + //surface edges + numsurfedges = 0; + dsurfedges = (int *) GetClearedMemory( MAX_MAP_SURFEDGES * sizeof( int ) ); + allocatedbspmem += MAX_MAP_SURFEDGES * sizeof( int ); + //brushes + numbrushes = 0; + dbrushes = (dbrush_t *) GetClearedMemory( MAX_MAP_BRUSHES * sizeof( dbrush_t ) ); + allocatedbspmem += MAX_MAP_BRUSHES * sizeof( dbrush_t ); + //brushsides + numbrushsides = 0; + dbrushsides = (dbrushside_t *) GetClearedMemory( MAX_MAP_BRUSHSIDES * sizeof( dbrushside_t ) ); + allocatedbspmem += MAX_MAP_BRUSHSIDES * sizeof( dbrushside_t ); + //areas + numareas = 0; + dareas = (darea_t *) GetClearedMemory( MAX_MAP_AREAS * sizeof( darea_t ) ); + allocatedbspmem += MAX_MAP_AREAS * sizeof( darea_t ); + //area portals + numareaportals = 0; + dareaportals = (dareaportal_t *) GetClearedMemory( MAX_MAP_AREAPORTALS * sizeof( dareaportal_t ) ); + allocatedbspmem += MAX_MAP_AREAPORTALS * sizeof( dareaportal_t ); + //print allocated memory + Log_Print( "allocated " ); + PrintMemorySize( allocatedbspmem ); + Log_Print( " of BSP memory\n" ); +} //end of the function Q2_AllocMaxBSP + +void Q2_FreeMaxBSP( void ) { + //models + nummodels = 0; + FreeMemory( dmodels ); + dmodels = NULL; + //vis data + visdatasize = 0; + FreeMemory( dvisdata ); + dvisdata = NULL; + dvis = NULL; + //light data + lightdatasize = 0; + FreeMemory( dlightdata ); + dlightdata = NULL; + //entity data + entdatasize = 0; + FreeMemory( dentdata ); + dentdata = NULL; + //leafs + numleafs = 0; + FreeMemory( dleafs ); + dleafs = NULL; + //planes + numplanes = 0; + FreeMemory( dplanes ); + dplanes = NULL; + //vertexes + numvertexes = 0; + FreeMemory( dvertexes ); + dvertexes = NULL; + //nodes + numnodes = 0; + FreeMemory( dnodes ); + dnodes = NULL; + /* + //texture info + numtexinfo = 0; + FreeMemory(texinfo); + texinfo = NULL; + // + */ + //faces + numfaces = 0; + FreeMemory( dfaces ); + dfaces = NULL; + //edges + numedges = 0; + FreeMemory( dedges ); + dedges = NULL; + //leaf faces + numleaffaces = 0; + FreeMemory( dleaffaces ); + dleaffaces = NULL; + //leaf brushes + numleafbrushes = 0; + FreeMemory( dleafbrushes ); + dleafbrushes = NULL; + //surface edges + numsurfedges = 0; + FreeMemory( dsurfedges ); + dsurfedges = NULL; + //brushes + numbrushes = 0; + FreeMemory( dbrushes ); + dbrushes = NULL; + //brushsides + numbrushsides = 0; + FreeMemory( dbrushsides ); + dbrushsides = NULL; + //areas + numareas = 0; + FreeMemory( dareas ); + dareas = NULL; + //area portals + numareaportals = 0; + FreeMemory( dareaportals ); + dareaportals = NULL; + // + Log_Print( "freed " ); + PrintMemorySize( allocatedbspmem ); + Log_Print( " of BSP memory\n" ); + allocatedbspmem = 0; +} //end of the function Q2_FreeMaxBSP + +#define WCONVEX_EPSILON 0.5 + +int InsideWinding( winding_t *w, vec3_t point, int planenum ) { + int i; + float dist; + vec_t *v1, *v2; + vec3_t normal, edgevec; + dplane_t *plane; + + for ( i = 1; i <= w->numpoints; i++ ) + { + v1 = w->p[i % w->numpoints]; + v2 = w->p[( i + 1 ) % w->numpoints]; + + VectorSubtract( v2, v1, edgevec ); + plane = &dplanes[planenum]; + CrossProduct( plane->normal, edgevec, normal ); + VectorNormalize( normal ); + dist = DotProduct( normal, v1 ); + // + if ( DotProduct( normal, point ) - dist > WCONVEX_EPSILON ) { + return false; + } + } //end for + return true; +} //end of the function InsideWinding + +int InsideFace( dface_t *face, vec3_t point ) { + int i, edgenum, side; + float dist; + vec_t *v1, *v2; + vec3_t normal, edgevec; + dplane_t *plane; + + for ( i = 0; i < face->numedges; i++ ) + { + //get the first and second vertex of the edge + edgenum = dsurfedges[face->firstedge + i]; + side = edgenum < 0; + v1 = dvertexes[dedges[abs( edgenum )].v[side]].point; + v2 = dvertexes[dedges[abs( edgenum )].v[!side]].point; + //create a plane through the edge vector, orthogonal to the face plane + //and with the normal vector pointing out of the face + VectorSubtract( v1, v2, edgevec ); + plane = &dplanes[face->planenum]; + CrossProduct( plane->normal, edgevec, normal ); + VectorNormalize( normal ); + dist = DotProduct( normal, v1 ); + // + if ( DotProduct( normal, point ) - dist > WCONVEX_EPSILON ) { + return false; + } + } //end for + return true; +} //end of the function InsideFace +//=========================================================================== +// returns the amount the face and the winding overlap +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +float Q2_FaceOnWinding( q2_dface_t *face, winding_t *winding ) { + int i, edgenum, side; + float dist, area; + q2_dplane_t plane; + vec_t *v1, *v2; + vec3_t normal, edgevec; + winding_t *w; + + // + w = CopyWinding( winding ); + memcpy( &plane, &q2_dplanes[face->planenum], sizeof( q2_dplane_t ) ); + //check on which side of the plane the face is + if ( face->side ) { + VectorNegate( plane.normal, plane.normal ); + plane.dist = -plane.dist; + } //end if + for ( i = 0; i < face->numedges && w; i++ ) + { + //get the first and second vertex of the edge + edgenum = q2_dsurfedges[face->firstedge + i]; + side = edgenum > 0; + //if the face plane is flipped + v1 = q2_dvertexes[q2_dedges[abs( edgenum )].v[side]].point; + v2 = q2_dvertexes[q2_dedges[abs( edgenum )].v[!side]].point; + //create a plane through the edge vector, orthogonal to the face plane + //and with the normal vector pointing inward + VectorSubtract( v1, v2, edgevec ); + CrossProduct( edgevec, plane.normal, normal ); + VectorNormalize( normal ); + dist = DotProduct( normal, v1 ); + // + ChopWindingInPlace( &w, normal, dist, -0.1 ); //CLIP_EPSILON + } //end for + if ( w ) { + area = WindingArea( w ); + FreeWinding( w ); + return area; + } //end if + return 0; +} //end of the function Q2_FaceOnWinding +//=========================================================================== +// creates a winding for the given brush side on the given brush +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +winding_t *Q2_BrushSideWinding( dbrush_t *brush, dbrushside_t *baseside ) { + int i; + dplane_t *baseplane, *plane; + winding_t *w; + dbrushside_t *side; + + //create a winding for the brush side with the given planenumber + baseplane = &dplanes[baseside->planenum]; + w = BaseWindingForPlane( baseplane->normal, baseplane->dist ); + for ( i = 0; i < brush->numsides && w; i++ ) + { + side = &dbrushsides[brush->firstside + i]; + //don't chop with the base plane + if ( side->planenum == baseside->planenum ) { + continue; + } + //also don't use planes that are almost equal + plane = &dplanes[side->planenum]; + if ( DotProduct( baseplane->normal, plane->normal ) > 0.999 + && fabs( baseplane->dist - plane->dist ) < 0.01 ) { + continue; + } + // + plane = &dplanes[side->planenum ^ 1]; + ChopWindingInPlace( &w, plane->normal, plane->dist, -0.1 ); //CLIP_EPSILON); + } //end for + return w; +} //end of the function Q2_BrushSideWinding +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int Q2_HintSkipBrush( dbrush_t *brush ) { + int j; + dbrushside_t *brushside; + + for ( j = 0; j < brush->numsides; j++ ) + { + brushside = &dbrushsides[brush->firstside + j]; + if ( brushside->texinfo > 0 ) { + if ( texinfo[brushside->texinfo].flags & ( SURF_SKIP | SURF_HINT ) ) { + return true; + } //end if + } //end if + } //end for + return false; +} //end of the function Q2_HintSkipBrush +//=========================================================================== +// fix screwed brush texture references +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +qboolean WindingIsTiny( winding_t *w ); + +void Q2_FixTextureReferences( void ) { + int i, j, k, we; + dbrushside_t *brushside; + dbrush_t *brush; + dface_t *face; + winding_t *w; + + memset( brushsidetextured, false, MAX_MAP_BRUSHSIDES ); + //go over all the brushes + for ( i = 0; i < numbrushes; i++ ) + { + brush = &dbrushes[i]; + //hint brushes are not textured + if ( Q2_HintSkipBrush( brush ) ) { + continue; + } + //go over all the sides of the brush + for ( j = 0; j < brush->numsides; j++ ) + { + brushside = &dbrushsides[brush->firstside + j]; + // + w = Q2_BrushSideWinding( brush, brushside ); + if ( !w ) { + brushsidetextured[brush->firstside + j] = true; + continue; + } //end if + else + { + //RemoveEqualPoints(w, 0.2); + if ( WindingIsTiny( w ) ) { + FreeWinding( w ); + brushsidetextured[brush->firstside + j] = true; + continue; + } //end if + else + { + we = WindingError( w ); + if ( we == WE_NOTENOUGHPOINTS + || we == WE_SMALLAREA + || we == WE_POINTBOGUSRANGE +// || we == WE_NONCONVEX + ) { + FreeWinding( w ); + brushsidetextured[brush->firstside + j] = true; + continue; + } //end if + } //end else + } //end else + if ( WindingArea( w ) < 20 ) { + brushsidetextured[brush->firstside + j] = true; + } //end if + //find a face for texturing this brush + for ( k = 0; k < numfaces; k++ ) + { + face = &dfaces[k]; + //if the face is in the same plane as the brush side + if ( ( face->planenum & ~1 ) != ( brushside->planenum & ~1 ) ) { + continue; + } + //if the face is partly or totally on the brush side + if ( Q2_FaceOnWinding( face, w ) ) { + brushside->texinfo = face->texinfo; + brushsidetextured[brush->firstside + j] = true; + break; + } //end if + } //end for + FreeWinding( w ); + } //end for + } //end for +} //end of the function Q2_FixTextureReferences*/ + +//#endif //ME + + +/* +=============== +CompressVis + +=============== +*/ +int Q2_CompressVis( byte *vis, byte *dest ) { + int j; + int rep; + int visrow; + byte *dest_p; + + dest_p = dest; +// visrow = (r_numvisleafs + 7)>>3; + visrow = ( dvis->numclusters + 7 ) >> 3; + + for ( j = 0 ; j < visrow ; j++ ) + { + *dest_p++ = vis[j]; + if ( vis[j] ) { + continue; + } + + rep = 1; + for ( j++; j < visrow ; j++ ) + if ( vis[j] || rep == 255 ) { + break; + } else { + rep++; + } + *dest_p++ = rep; + j--; + } + + return dest_p - dest; +} + + +/* +=================== +DecompressVis +=================== +*/ +void Q2_DecompressVis( byte *in, byte *decompressed ) { + int c; + byte *out; + int row; + +// row = (r_numvisleafs+7)>>3; + row = ( dvis->numclusters + 7 ) >> 3; + out = decompressed; + + do + { + if ( *in ) { + *out++ = *in++; + continue; + } + + c = in[1]; + if ( !c ) { + Error( "DecompressVis: 0 repeat" ); + } + in += 2; + while ( c ) + { + *out++ = 0; + c--; + } + } while ( out - decompressed < row ); +} + +//============================================================================= + +/* +============= +SwapBSPFile + +Byte swaps all data in a bsp file. +============= +*/ +void Q2_SwapBSPFile( qboolean todisk ) { + int i, j; + dmodel_t *d; + + +// models + for ( i = 0 ; i < nummodels ; i++ ) + { + d = &dmodels[i]; + + d->firstface = LittleLong( d->firstface ); + d->numfaces = LittleLong( d->numfaces ); + d->headnode = LittleLong( d->headnode ); + + for ( j = 0 ; j < 3 ; j++ ) + { + d->mins[j] = LittleFloat( d->mins[j] ); + d->maxs[j] = LittleFloat( d->maxs[j] ); + d->origin[j] = LittleFloat( d->origin[j] ); + } + } + +// +// vertexes +// + for ( i = 0 ; i < numvertexes ; i++ ) + { + for ( j = 0 ; j < 3 ; j++ ) + dvertexes[i].point[j] = LittleFloat( dvertexes[i].point[j] ); + } + +// +// planes +// + for ( i = 0 ; i < numplanes ; i++ ) + { + for ( j = 0 ; j < 3 ; j++ ) + dplanes[i].normal[j] = LittleFloat( dplanes[i].normal[j] ); + dplanes[i].dist = LittleFloat( dplanes[i].dist ); + dplanes[i].type = LittleLong( dplanes[i].type ); + } + +// +// texinfos +// + for ( i = 0 ; i < numtexinfo ; i++ ) + { + for ( j = 0 ; j < 8 ; j++ ) + texinfo[i].vecs[0][j] = LittleFloat( texinfo[i].vecs[0][j] ); + texinfo[i].flags = LittleLong( texinfo[i].flags ); + texinfo[i].value = LittleLong( texinfo[i].value ); + texinfo[i].nexttexinfo = LittleLong( texinfo[i].nexttexinfo ); + } + +// +// faces +// + for ( i = 0 ; i < numfaces ; i++ ) + { + dfaces[i].texinfo = LittleShort( dfaces[i].texinfo ); + dfaces[i].planenum = LittleShort( dfaces[i].planenum ); + dfaces[i].side = LittleShort( dfaces[i].side ); + dfaces[i].lightofs = LittleLong( dfaces[i].lightofs ); + dfaces[i].firstedge = LittleLong( dfaces[i].firstedge ); + dfaces[i].numedges = LittleShort( dfaces[i].numedges ); + } + +// +// nodes +// + for ( i = 0 ; i < numnodes ; i++ ) + { + dnodes[i].planenum = LittleLong( dnodes[i].planenum ); + for ( j = 0 ; j < 3 ; j++ ) + { + dnodes[i].mins[j] = LittleShort( dnodes[i].mins[j] ); + dnodes[i].maxs[j] = LittleShort( dnodes[i].maxs[j] ); + } + dnodes[i].children[0] = LittleLong( dnodes[i].children[0] ); + dnodes[i].children[1] = LittleLong( dnodes[i].children[1] ); + dnodes[i].firstface = LittleShort( dnodes[i].firstface ); + dnodes[i].numfaces = LittleShort( dnodes[i].numfaces ); + } + +// +// leafs +// + for ( i = 0 ; i < numleafs ; i++ ) + { + dleafs[i].contents = LittleLong( dleafs[i].contents ); + dleafs[i].cluster = LittleShort( dleafs[i].cluster ); + dleafs[i].area = LittleShort( dleafs[i].area ); + for ( j = 0 ; j < 3 ; j++ ) + { + dleafs[i].mins[j] = LittleShort( dleafs[i].mins[j] ); + dleafs[i].maxs[j] = LittleShort( dleafs[i].maxs[j] ); + } + + dleafs[i].firstleafface = LittleShort( dleafs[i].firstleafface ); + dleafs[i].numleaffaces = LittleShort( dleafs[i].numleaffaces ); + dleafs[i].firstleafbrush = LittleShort( dleafs[i].firstleafbrush ); + dleafs[i].numleafbrushes = LittleShort( dleafs[i].numleafbrushes ); + } + +// +// leaffaces +// + for ( i = 0 ; i < numleaffaces ; i++ ) + dleaffaces[i] = LittleShort( dleaffaces[i] ); + +// +// leafbrushes +// + for ( i = 0 ; i < numleafbrushes ; i++ ) + dleafbrushes[i] = LittleShort( dleafbrushes[i] ); + +// +// surfedges +// + for ( i = 0 ; i < numsurfedges ; i++ ) + dsurfedges[i] = LittleLong( dsurfedges[i] ); + +// +// edges +// + for ( i = 0 ; i < numedges ; i++ ) + { + dedges[i].v[0] = LittleShort( dedges[i].v[0] ); + dedges[i].v[1] = LittleShort( dedges[i].v[1] ); + } + +// +// brushes +// + for ( i = 0 ; i < numbrushes ; i++ ) + { + dbrushes[i].firstside = LittleLong( dbrushes[i].firstside ); + dbrushes[i].numsides = LittleLong( dbrushes[i].numsides ); + dbrushes[i].contents = LittleLong( dbrushes[i].contents ); + } + +// +// areas +// + for ( i = 0 ; i < numareas ; i++ ) + { + dareas[i].numareaportals = LittleLong( dareas[i].numareaportals ); + dareas[i].firstareaportal = LittleLong( dareas[i].firstareaportal ); + } + +// +// areasportals +// + for ( i = 0 ; i < numareaportals ; i++ ) + { + dareaportals[i].portalnum = LittleLong( dareaportals[i].portalnum ); + dareaportals[i].otherarea = LittleLong( dareaportals[i].otherarea ); + } + +// +// brushsides +// + for ( i = 0 ; i < numbrushsides ; i++ ) + { + dbrushsides[i].planenum = LittleShort( dbrushsides[i].planenum ); + dbrushsides[i].texinfo = LittleShort( dbrushsides[i].texinfo ); + } + +// +// visibility +// + if ( todisk ) { + j = dvis->numclusters; + } else { + j = LittleLong( dvis->numclusters ); + } + dvis->numclusters = LittleLong( dvis->numclusters ); + for ( i = 0 ; i < j ; i++ ) + { + dvis->bitofs[i][0] = LittleLong( dvis->bitofs[i][0] ); + dvis->bitofs[i][1] = LittleLong( dvis->bitofs[i][1] ); + } +} //end of the function Q2_SwapBSPFile + + +dheader_t *header; + +int Q2_CopyLump( int lump, void *dest, int size, int maxsize ) { + int length, ofs; + + length = header->lumps[lump].filelen; + ofs = header->lumps[lump].fileofs; + + if ( length % size ) { + Error( "LoadBSPFile: odd lump size" ); + } + + if ( ( length / size ) > maxsize ) { + Error( "Q2_LoadBSPFile: exceeded max size for lump %d size %d > maxsize %d\n", lump, ( length / size ), maxsize ); + } + + memcpy( dest, (byte *)header + ofs, length ); + + return length / size; +} //end of the function Q2_CopyLump + +/* +============= +LoadBSPFile +============= +*/ +void Q2_LoadBSPFile( char *filename, int offset, int length ) { + int i; + +// +// load the file header +// + LoadFile( filename, (void **)&header, offset, length ); + +// swap the header + for ( i = 0 ; i < sizeof( dheader_t ) / 4 ; i++ ) + ( (int *)header )[i] = LittleLong( ( (int *)header )[i] ); + + if ( header->ident != IDBSPHEADER ) { + Error( "%s is not a IBSP file", filename ); + } + if ( header->version != BSPVERSION ) { + Error( "%s is version %i, not %i", filename, header->version, BSPVERSION ); + } + + nummodels = Q2_CopyLump( LUMP_MODELS, dmodels, sizeof( dmodel_t ), MAX_MAP_MODELS ); + numvertexes = Q2_CopyLump( LUMP_VERTEXES, dvertexes, sizeof( dvertex_t ), MAX_MAP_VERTS ); + numplanes = Q2_CopyLump( LUMP_PLANES, dplanes, sizeof( dplane_t ), MAX_MAP_PLANES ); + numleafs = Q2_CopyLump( LUMP_LEAFS, dleafs, sizeof( dleaf_t ), MAX_MAP_LEAFS ); + numnodes = Q2_CopyLump( LUMP_NODES, dnodes, sizeof( dnode_t ), MAX_MAP_NODES ); + numtexinfo = Q2_CopyLump( LUMP_TEXINFO, texinfo, sizeof( texinfo_t ), MAX_MAP_TEXINFO ); + numfaces = Q2_CopyLump( LUMP_FACES, dfaces, sizeof( dface_t ), MAX_MAP_FACES ); + numleaffaces = Q2_CopyLump( LUMP_LEAFFACES, dleaffaces, sizeof( dleaffaces[0] ), MAX_MAP_LEAFFACES ); + numleafbrushes = Q2_CopyLump( LUMP_LEAFBRUSHES, dleafbrushes, sizeof( dleafbrushes[0] ), MAX_MAP_LEAFBRUSHES ); + numsurfedges = Q2_CopyLump( LUMP_SURFEDGES, dsurfedges, sizeof( dsurfedges[0] ), MAX_MAP_SURFEDGES ); + numedges = Q2_CopyLump( LUMP_EDGES, dedges, sizeof( dedge_t ), MAX_MAP_EDGES ); + numbrushes = Q2_CopyLump( LUMP_BRUSHES, dbrushes, sizeof( dbrush_t ), MAX_MAP_BRUSHES ); + numbrushsides = Q2_CopyLump( LUMP_BRUSHSIDES, dbrushsides, sizeof( dbrushside_t ), MAX_MAP_BRUSHSIDES ); + numareas = Q2_CopyLump( LUMP_AREAS, dareas, sizeof( darea_t ), MAX_MAP_AREAS ); + numareaportals = Q2_CopyLump( LUMP_AREAPORTALS, dareaportals, sizeof( dareaportal_t ), MAX_MAP_AREAPORTALS ); + + visdatasize = Q2_CopyLump( LUMP_VISIBILITY, dvisdata, 1, MAX_MAP_VISIBILITY ); + lightdatasize = Q2_CopyLump( LUMP_LIGHTING, dlightdata, 1, MAX_MAP_LIGHTING ); + entdatasize = Q2_CopyLump( LUMP_ENTITIES, dentdata, 1, MAX_MAP_ENTSTRING ); + + Q2_CopyLump( LUMP_POP, dpop, 1, MAX_MAP_DPOP ); + + FreeMemory( header ); // everything has been copied out + +// +// swap everything +// + Q2_SwapBSPFile( false ); + + Q2_FixTextureReferences(); +} //end of the function Q2_LoadBSPFile + + +/* +============= +LoadBSPFileTexinfo + +Only loads the texinfo lump, so qdata can scan for textures +============= +*/ +void Q2_LoadBSPFileTexinfo( char *filename ) { + int i; + FILE *f; + int length, ofs; + + header = GetMemory( sizeof( dheader_t ) ); + + f = fopen( filename, "rb" ); + fread( header, sizeof( dheader_t ), 1, f ); + +// swap the header + for ( i = 0 ; i < sizeof( dheader_t ) / 4 ; i++ ) + ( (int *)header )[i] = LittleLong( ( (int *)header )[i] ); + + if ( header->ident != IDBSPHEADER ) { + Error( "%s is not a IBSP file", filename ); + } + if ( header->version != BSPVERSION ) { + Error( "%s is version %i, not %i", filename, header->version, BSPVERSION ); + } + + + length = header->lumps[LUMP_TEXINFO].filelen; + ofs = header->lumps[LUMP_TEXINFO].fileofs; + + fseek( f, ofs, SEEK_SET ); + fread( texinfo, length, 1, f ); + fclose( f ); + + numtexinfo = length / sizeof( texinfo_t ); + + FreeMemory( header ); // everything has been copied out + + Q2_SwapBSPFile( false ); +} //end of the function Q2_LoadBSPFileTexinfo + + +//============================================================================ + +FILE *wadfile; +dheader_t outheader; + +void Q2_AddLump( int lumpnum, void *data, int len ) { + lump_t *lump; + + lump = &header->lumps[lumpnum]; + + lump->fileofs = LittleLong( ftell( wadfile ) ); + lump->filelen = LittleLong( len ); + SafeWrite( wadfile, data, ( len + 3 ) & ~3 ); +} //end of the function Q2_AddLump + +/* +============= +WriteBSPFile + +Swaps the bsp file in place, so it should not be referenced again +============= +*/ +void Q2_WriteBSPFile( char *filename ) { + header = &outheader; + memset( header, 0, sizeof( dheader_t ) ); + + Q2_SwapBSPFile( true ); + + header->ident = LittleLong( IDBSPHEADER ); + header->version = LittleLong( BSPVERSION ); + + wadfile = SafeOpenWrite( filename ); + SafeWrite( wadfile, header, sizeof( dheader_t ) ); // overwritten later + + Q2_AddLump( LUMP_PLANES, dplanes, numplanes * sizeof( dplane_t ) ); + Q2_AddLump( LUMP_LEAFS, dleafs, numleafs * sizeof( dleaf_t ) ); + Q2_AddLump( LUMP_VERTEXES, dvertexes, numvertexes * sizeof( dvertex_t ) ); + Q2_AddLump( LUMP_NODES, dnodes, numnodes * sizeof( dnode_t ) ); + Q2_AddLump( LUMP_TEXINFO, texinfo, numtexinfo * sizeof( texinfo_t ) ); + Q2_AddLump( LUMP_FACES, dfaces, numfaces * sizeof( dface_t ) ); + Q2_AddLump( LUMP_BRUSHES, dbrushes, numbrushes * sizeof( dbrush_t ) ); + Q2_AddLump( LUMP_BRUSHSIDES, dbrushsides, numbrushsides * sizeof( dbrushside_t ) ); + Q2_AddLump( LUMP_LEAFFACES, dleaffaces, numleaffaces * sizeof( dleaffaces[0] ) ); + Q2_AddLump( LUMP_LEAFBRUSHES, dleafbrushes, numleafbrushes * sizeof( dleafbrushes[0] ) ); + Q2_AddLump( LUMP_SURFEDGES, dsurfedges, numsurfedges * sizeof( dsurfedges[0] ) ); + Q2_AddLump( LUMP_EDGES, dedges, numedges * sizeof( dedge_t ) ); + Q2_AddLump( LUMP_MODELS, dmodels, nummodels * sizeof( dmodel_t ) ); + Q2_AddLump( LUMP_AREAS, dareas, numareas * sizeof( darea_t ) ); + Q2_AddLump( LUMP_AREAPORTALS, dareaportals, numareaportals * sizeof( dareaportal_t ) ); + + Q2_AddLump( LUMP_LIGHTING, dlightdata, lightdatasize ); + Q2_AddLump( LUMP_VISIBILITY, dvisdata, visdatasize ); + Q2_AddLump( LUMP_ENTITIES, dentdata, entdatasize ); + Q2_AddLump( LUMP_POP, dpop, sizeof( dpop ) ); + + fseek( wadfile, 0, SEEK_SET ); + SafeWrite( wadfile, header, sizeof( dheader_t ) ); + fclose( wadfile ); +} //end of the function Q2_WriteBSPFile + +//============================================================================ + +/* +============= +PrintBSPFileSizes + +Dumps info about current file +============= +*/ +void Q2_PrintBSPFileSizes( void ) { + if ( !num_entities ) { + Q2_ParseEntities(); + } + + printf( "%6i models %7i\n" + ,nummodels, (int)( nummodels * sizeof( dmodel_t ) ) ); + printf( "%6i brushes %7i\n" + ,numbrushes, (int)( numbrushes * sizeof( dbrush_t ) ) ); + printf( "%6i brushsides %7i\n" + ,numbrushsides, (int)( numbrushsides * sizeof( dbrushside_t ) ) ); + printf( "%6i planes %7i\n" + ,numplanes, (int)( numplanes * sizeof( dplane_t ) ) ); + printf( "%6i texinfo %7i\n" + ,numtexinfo, (int)( numtexinfo * sizeof( texinfo_t ) ) ); + printf( "%6i entdata %7i\n", num_entities, entdatasize ); + + printf( "\n" ); + + printf( "%6i vertexes %7i\n" + ,numvertexes, (int)( numvertexes * sizeof( dvertex_t ) ) ); + printf( "%6i nodes %7i\n" + ,numnodes, (int)( numnodes * sizeof( dnode_t ) ) ); + printf( "%6i faces %7i\n" + ,numfaces, (int)( numfaces * sizeof( dface_t ) ) ); + printf( "%6i leafs %7i\n" + ,numleafs, (int)( numleafs * sizeof( dleaf_t ) ) ); + printf( "%6i leaffaces %7i\n" + ,numleaffaces, (int)( numleaffaces * sizeof( dleaffaces[0] ) ) ); + printf( "%6i leafbrushes %7i\n" + ,numleafbrushes, (int)( numleafbrushes * sizeof( dleafbrushes[0] ) ) ); + printf( "%6i surfedges %7i\n" + ,numsurfedges, (int)( numsurfedges * sizeof( dsurfedges[0] ) ) ); + printf( "%6i edges %7i\n" + ,numedges, (int)( numedges * sizeof( dedge_t ) ) ); +//NEW + printf( "%6i areas %7i\n" + ,numareas, (int)( numareas * sizeof( darea_t ) ) ); + printf( "%6i areaportals %7i\n" + ,numareaportals, (int)( numareaportals * sizeof( dareaportal_t ) ) ); +//ENDNEW + printf( " lightdata %7i\n", lightdatasize ); + printf( " visdata %7i\n", visdatasize ); +} //end of the function Q2_PrintBSPFileSizes + +/* +================ +ParseEntities + +Parses the dentdata string into entities +================ +*/ +void Q2_ParseEntities( void ) { + script_t *script; + + num_entities = 0; + script = LoadScriptMemory( dentdata, entdatasize, "*Quake2 bsp file" ); + SetScriptFlags( script, SCFL_NOSTRINGWHITESPACES | + SCFL_NOSTRINGESCAPECHARS ); + + while ( ParseEntity( script ) ) + { + } //end while + + FreeScript( script ); +} //end of the function Q2_ParseEntities + + +/* +================ +UnparseEntities + +Generates the dentdata string from all the entities +================ +*/ +void Q2_UnparseEntities( void ) { + char *buf, *end; + epair_t *ep; + char line[2048]; + int i; + char key[1024], value[1024]; + + buf = dentdata; + end = buf; + *end = 0; + + for ( i = 0 ; i < num_entities ; i++ ) + { + ep = entities[i].epairs; + if ( !ep ) { + continue; // ent got removed + + } + strcat( end,"{\n" ); + end += 2; + + for ( ep = entities[i].epairs ; ep ; ep = ep->next ) + { + strcpy( key, ep->key ); + StripTrailing( key ); + strcpy( value, ep->value ); + StripTrailing( value ); + + sprintf( line, "\"%s\" \"%s\"\n", key, value ); + strcat( end, line ); + end += strlen( line ); + } + strcat( end,"}\n" ); + end += 2; + + if ( end > buf + MAX_MAP_ENTSTRING ) { + Error( "Entity text too long" ); + } + } + entdatasize = end - buf + 1; +} //end of the function Q2_UnparseEntities + diff --git a/Projects/Android/jni/rtcw/src/bspc/l_bsp_q2.h b/Projects/Android/jni/rtcw/src/bspc/l_bsp_q2.h new file mode 100644 index 0000000..9267949 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/bspc/l_bsp_q2.h @@ -0,0 +1,104 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +#ifndef ME +#define ME +#endif //ME + +extern int nummodels; +extern dmodel_t *dmodels; //[MAX_MAP_MODELS]; + +extern int visdatasize; +extern byte *dvisdata; //[MAX_MAP_VISIBILITY]; +extern dvis_t *dvis; + +extern int lightdatasize; +extern byte *dlightdata; //[MAX_MAP_LIGHTING]; + +extern int entdatasize; +extern char *dentdata; //[MAX_MAP_ENTSTRING]; + +extern int numleafs; +extern dleaf_t *dleafs; //[MAX_MAP_LEAFS]; + +extern int numplanes; +extern dplane_t *dplanes; //[MAX_MAP_PLANES]; + +extern int numvertexes; +extern dvertex_t *dvertexes; //[MAX_MAP_VERTS]; + +extern int numnodes; +extern dnode_t *dnodes; //[MAX_MAP_NODES]; + +extern int numtexinfo; +extern texinfo_t texinfo[MAX_MAP_TEXINFO]; + +extern int numfaces; +extern dface_t *dfaces; //[MAX_MAP_FACES]; + +extern int numedges; +extern dedge_t *dedges; //[MAX_MAP_EDGES]; + +extern int numleaffaces; +extern unsigned short *dleaffaces; //[MAX_MAP_LEAFFACES]; + +extern int numleafbrushes; +extern unsigned short *dleafbrushes; //[MAX_MAP_LEAFBRUSHES]; + +extern int numsurfedges; +extern int *dsurfedges; //[MAX_MAP_SURFEDGES]; + +extern int numareas; +extern darea_t *dareas; //[MAX_MAP_AREAS]; + +extern int numareaportals; +extern dareaportal_t *dareaportals; //[MAX_MAP_AREAPORTALS]; + +extern int numbrushes; +extern dbrush_t *dbrushes; //[MAX_MAP_BRUSHES]; + +extern int numbrushsides; +extern dbrushside_t *dbrushsides; //[MAX_MAP_BRUSHSIDES]; + +extern byte dpop[256]; + +extern char brushsidetextured[MAX_MAP_BRUSHSIDES]; + +void Q2_AllocMaxBSP( void ); +void Q2_FreeMaxBSP( void ); + +void Q2_DecompressVis( byte *in, byte *decompressed ); +int Q2_CompressVis( byte *vis, byte *dest ); + +void Q2_LoadBSPFile( char *filename, int offset, int length ); +void Q2_LoadBSPFileTexinfo( char *filename ); // just for qdata +void Q2_WriteBSPFile( char *filename ); +void Q2_PrintBSPFileSizes( void ); +void Q2_ParseEntities( void ); +void Q2_UnparseEntities( void ); + diff --git a/Projects/Android/jni/rtcw/src/bspc/l_bsp_q3.c b/Projects/Android/jni/rtcw/src/bspc/l_bsp_q3.c new file mode 100644 index 0000000..71743b2 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/bspc/l_bsp_q3.c @@ -0,0 +1,857 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +#include "l_cmd.h" +#include "l_math.h" +#include "l_mem.h" +#include "l_log.h" +#include "l_poly.h" +#include "../botlib/l_script.h" +#include "l_qfiles.h" +#include "l_bsp_q3.h" +#include "l_bsp_ent.h" +//#include "qfiles.h" +#include "q2files.h" + +void Q3_ParseEntities( void ); +void Q3_PrintBSPFileSizes( void ); + +void GetLeafNums( void ); + +//============================================================================= + +#define WCONVEX_EPSILON 0.5 + +int q3_nummodels; +q3_dmodel_t *q3_dmodels; //[MAX_MAP_MODELS]; + +int q3_numShaders; +q3_dshader_t *q3_dshaders; //[Q3_MAX_MAP_SHADERS]; + +int q3_entdatasize; +char *q3_dentdata; //[Q3_MAX_MAP_ENTSTRING]; + +int q3_numleafs; +q3_dleaf_t *q3_dleafs; //[Q3_MAX_MAP_LEAFS]; + +int q3_numplanes; +q3_dplane_t *q3_dplanes; //[Q3_MAX_MAP_PLANES]; + +int q3_numnodes; +q3_dnode_t *q3_dnodes; //[Q3_MAX_MAP_NODES]; + +int q3_numleafsurfaces; +int *q3_dleafsurfaces; //[Q3_MAX_MAP_LEAFFACES]; + +int q3_numleafbrushes; +int *q3_dleafbrushes; //[Q3_MAX_MAP_LEAFBRUSHES]; + +int q3_numbrushes; +q3_dbrush_t *q3_dbrushes; //[Q3_MAX_MAP_BRUSHES]; + +int q3_numbrushsides; +q3_dbrushside_t *q3_dbrushsides; //[Q3_MAX_MAP_BRUSHSIDES]; + +int q3_numLightBytes; +byte *q3_lightBytes; //[Q3_MAX_MAP_LIGHTING]; + +int q3_numGridPoints; +byte *q3_gridData; //[Q3_MAX_MAP_LIGHTGRID]; + +int q3_numVisBytes; +byte *q3_visBytes; //[Q3_MAX_MAP_VISIBILITY]; + +int q3_numDrawVerts; +q3_drawVert_t *q3_drawVerts; //[Q3_MAX_MAP_DRAW_VERTS]; + +int q3_numDrawIndexes; +int *q3_drawIndexes; //[Q3_MAX_MAP_DRAW_INDEXES]; + +int q3_numDrawSurfaces; +q3_dsurface_t *q3_drawSurfaces; //[Q3_MAX_MAP_DRAW_SURFS]; + +int q3_numFogs; +q3_dfog_t *q3_dfogs; //[Q3_MAX_MAP_FOGS]; + +char q3_dbrushsidetextured[Q3_MAX_MAP_BRUSHSIDES]; + +extern qboolean forcesidesvisible; + + +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void Q3_FreeMaxBSP( void ) { + if ( q3_dmodels ) { + FreeMemory( q3_dmodels ); + } + q3_dmodels = NULL; + q3_nummodels = 0; + if ( q3_dshaders ) { + FreeMemory( q3_dshaders ); + } + q3_dshaders = NULL; + q3_numShaders = 0; + if ( q3_dentdata ) { + FreeMemory( q3_dentdata ); + } + q3_dentdata = NULL; + q3_entdatasize = 0; + if ( q3_dleafs ) { + FreeMemory( q3_dleafs ); + } + q3_dleafs = NULL; + q3_numleafs = 0; + if ( q3_dplanes ) { + FreeMemory( q3_dplanes ); + } + q3_dplanes = NULL; + q3_numplanes = 0; + if ( q3_dnodes ) { + FreeMemory( q3_dnodes ); + } + q3_dnodes = NULL; + q3_numnodes = 0; + if ( q3_dleafsurfaces ) { + FreeMemory( q3_dleafsurfaces ); + } + q3_dleafsurfaces = NULL; + q3_numleafsurfaces = 0; + if ( q3_dleafbrushes ) { + FreeMemory( q3_dleafbrushes ); + } + q3_dleafbrushes = NULL; + q3_numleafbrushes = 0; + if ( q3_dbrushes ) { + FreeMemory( q3_dbrushes ); + } + q3_dbrushes = NULL; + q3_numbrushes = 0; + if ( q3_dbrushsides ) { + FreeMemory( q3_dbrushsides ); + } + q3_dbrushsides = NULL; + q3_numbrushsides = 0; + if ( q3_lightBytes ) { + FreeMemory( q3_lightBytes ); + } + q3_lightBytes = NULL; + q3_numLightBytes = 0; + if ( q3_gridData ) { + FreeMemory( q3_gridData ); + } + q3_gridData = NULL; + q3_numGridPoints = 0; + if ( q3_visBytes ) { + FreeMemory( q3_visBytes ); + } + q3_visBytes = NULL; + q3_numVisBytes = 0; + if ( q3_drawVerts ) { + FreeMemory( q3_drawVerts ); + } + q3_drawVerts = NULL; + q3_numDrawVerts = 0; + if ( q3_drawIndexes ) { + FreeMemory( q3_drawIndexes ); + } + q3_drawIndexes = NULL; + q3_numDrawIndexes = 0; + if ( q3_drawSurfaces ) { + FreeMemory( q3_drawSurfaces ); + } + q3_drawSurfaces = NULL; + q3_numDrawSurfaces = 0; + if ( q3_dfogs ) { + FreeMemory( q3_dfogs ); + } + q3_dfogs = NULL; + q3_numFogs = 0; +} //end of the function Q3_FreeMaxBSP + +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void Q3_PlaneFromPoints( vec3_t p0, vec3_t p1, vec3_t p2, vec3_t normal, float *dist ) { + vec3_t t1, t2; + + VectorSubtract( p0, p1, t1 ); + VectorSubtract( p2, p1, t2 ); + CrossProduct( t1, t2, normal ); + VectorNormalize( normal ); + + *dist = DotProduct( p0, normal ); +} //end of the function PlaneFromPoints +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void Q3_SurfacePlane( q3_dsurface_t *surface, vec3_t normal, float *dist ) { + int i; + float *p0, *p1, *p2; + vec3_t t1, t2; + + p0 = q3_drawVerts[surface->firstVert].xyz; + for ( i = 1; i < surface->numVerts - 1; i++ ) + { + p1 = q3_drawVerts[surface->firstVert + ( ( i ) % surface->numVerts )].xyz; + p2 = q3_drawVerts[surface->firstVert + ( ( i + 1 ) % surface->numVerts )].xyz; + VectorSubtract( p0, p1, t1 ); + VectorSubtract( p2, p1, t2 ); + CrossProduct( t1, t2, normal ); + VectorNormalize( normal ); + if ( VectorLength( normal ) ) { + break; + } + } //end for*/ +/* + float dot; + for (i = 0; i < surface->numVerts; i++) + { + p0 = q3_drawVerts[surface->firstVert + ((i) % surface->numVerts)].xyz; + p1 = q3_drawVerts[surface->firstVert + ((i+1) % surface->numVerts)].xyz; + p2 = q3_drawVerts[surface->firstVert + ((i+2) % surface->numVerts)].xyz; + VectorSubtract(p0, p1, t1); + VectorSubtract(p2, p1, t2); + VectorNormalize(t1); + VectorNormalize(t2); + dot = DotProduct(t1, t2); + if (dot > -0.9 && dot < 0.9 && + VectorLength(t1) > 0.1 && VectorLength(t2) > 0.1) break; + } //end for + CrossProduct(t1, t2, normal); + VectorNormalize(normal); +*/ + if ( VectorLength( normal ) < 0.9 ) { + printf( "surface %d bogus normal vector %f %f %f\n", surface - q3_drawSurfaces, normal[0], normal[1], normal[2] ); + printf( "t1 = %f %f %f, t2 = %f %f %f\n", t1[0], t1[1], t1[2], t2[0], t2[1], t2[2] ); + for ( i = 0; i < surface->numVerts; i++ ) + { + p1 = q3_drawVerts[surface->firstVert + ( ( i ) % surface->numVerts )].xyz; + Log_Print( "p%d = %f %f %f\n", i, p1[0], p1[1], p1[2] ); + } //end for + } //end if + *dist = DotProduct( p0, normal ); +} //end of the function Q3_SurfacePlane +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +q3_dplane_t *q3_surfaceplanes; + +void Q3_CreatePlanarSurfacePlanes( void ) { + int i; + q3_dsurface_t *surface; + + Log_Print( "creating planar surface planes...\n" ); + q3_surfaceplanes = (q3_dplane_t *) GetClearedMemory( q3_numDrawSurfaces * sizeof( q3_dplane_t ) ); + + for ( i = 0; i < q3_numDrawSurfaces; i++ ) + { + surface = &q3_drawSurfaces[i]; + if ( surface->surfaceType != MST_PLANAR ) { + continue; + } + Q3_SurfacePlane( surface, q3_surfaceplanes[i].normal, &q3_surfaceplanes[i].dist ); + //Log_Print("normal = %f %f %f, dist = %f\n", q3_surfaceplanes[i].normal[0], + // q3_surfaceplanes[i].normal[1], + // q3_surfaceplanes[i].normal[2], q3_surfaceplanes[i].dist); + } //end for +} //end of the function Q3_CreatePlanarSurfacePlanes +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +/* +void Q3_SurfacePlane(q3_dsurface_t *surface, vec3_t normal, float *dist) +{ + //take the plane information from the lightmap vector + //VectorCopy(surface->lightmapVecs[2], normal); + //calculate plane dist with first surface vertex + // *dist = DotProduct(q3_drawVerts[surface->firstVert].xyz, normal); + Q3_PlaneFromPoints(q3_drawVerts[surface->firstVert].xyz, + q3_drawVerts[surface->firstVert+1].xyz, + q3_drawVerts[surface->firstVert+2].xyz, normal, dist); +} //end of the function Q3_SurfacePlane*/ +//=========================================================================== +// returns the amount the face and the winding overlap +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +float Q3_FaceOnWinding( q3_dsurface_t *surface, winding_t *winding ) { + int i; + float dist, area; + q3_dplane_t plane; + vec_t *v1, *v2; + vec3_t normal, edgevec; + winding_t *w; + + //copy the winding before chopping + w = CopyWinding( winding ); + //retrieve the surface plane + Q3_SurfacePlane( surface, plane.normal, &plane.dist ); + //chop the winding with the surface edge planes + for ( i = 0; i < surface->numVerts && w; i++ ) + { + v1 = q3_drawVerts[surface->firstVert + ( ( i ) % surface->numVerts )].xyz; + v2 = q3_drawVerts[surface->firstVert + ( ( i + 1 ) % surface->numVerts )].xyz; + //create a plane through the edge from v1 to v2, orthogonal to the + //surface plane and with the normal vector pointing inward + VectorSubtract( v2, v1, edgevec ); + CrossProduct( edgevec, plane.normal, normal ); + VectorNormalize( normal ); + dist = DotProduct( normal, v1 ); + // + ChopWindingInPlace( &w, normal, dist, -0.1 ); //CLIP_EPSILON + } //end for + if ( w ) { + area = WindingArea( w ); + FreeWinding( w ); + return area; + } //end if + return 0; +} //end of the function Q3_FaceOnWinding +//=========================================================================== +// creates a winding for the given brush side on the given brush +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +winding_t *Q3_BrushSideWinding( q3_dbrush_t *brush, q3_dbrushside_t *baseside ) { + int i; + q3_dplane_t *baseplane, *plane; + winding_t *w; + q3_dbrushside_t *side; + + //create a winding for the brush side with the given planenumber + baseplane = &q3_dplanes[baseside->planeNum]; + w = BaseWindingForPlane( baseplane->normal, baseplane->dist ); + for ( i = 0; i < brush->numSides && w; i++ ) + { + side = &q3_dbrushsides[brush->firstSide + i]; + //don't chop with the base plane + if ( side->planeNum == baseside->planeNum ) { + continue; + } + //also don't use planes that are almost equal + plane = &q3_dplanes[side->planeNum]; + if ( DotProduct( baseplane->normal, plane->normal ) > 0.999 + && fabs( baseplane->dist - plane->dist ) < 0.01 ) { + continue; + } + // + plane = &q3_dplanes[side->planeNum ^ 1]; + ChopWindingInPlace( &w, plane->normal, plane->dist, -0.1 ); //CLIP_EPSILON); + } //end for + return w; +} //end of the function Q3_BrushSideWinding +//=========================================================================== +// fix screwed brush texture references +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +qboolean WindingIsTiny( winding_t *w ); + +void Q3_FindVisibleBrushSides( void ) { + int i, j, k, we, numtextured, numsides; + float dot; + q3_dplane_t *plane; + q3_dbrushside_t *brushside; + q3_dbrush_t *brush; + q3_dsurface_t *surface; + winding_t *w; + + memset( q3_dbrushsidetextured, false, Q3_MAX_MAP_BRUSHSIDES ); + // + numsides = 0; + //create planes for the planar surfaces + Q3_CreatePlanarSurfacePlanes(); + Log_Print( "searching visible brush sides...\n" ); + Log_Print( "%6d brush sides", numsides ); + //go over all the brushes + for ( i = 0; i < q3_numbrushes; i++ ) + { + brush = &q3_dbrushes[i]; + // if one of the brush sides uses the terrain shader mark all sides as visible + for ( j = 0; j < brush->numSides; j++ ) { + brushside = &q3_dbrushsides[brush->firstSide + j]; + // NOTE: using "terrain" just like in q3map/terrain.c + if ( strstr( q3_dshaders[brushside->shaderNum].shader, "terrain" ) ) { + for ( j = 0; j < brush->numSides; j++ ) { + q3_dbrushsidetextured[brush->firstSide + j] = true; + } + break; + } + } + if ( j < brush->numSides ) { + continue; + } + //go over all the sides of the brush + for ( j = 0; j < brush->numSides; j++ ) + { + qprintf( "\r%6d", numsides++ ); + brushside = &q3_dbrushsides[brush->firstSide + j]; + // + w = Q3_BrushSideWinding( brush, brushside ); + if ( !w ) { + q3_dbrushsidetextured[brush->firstSide + j] = true; + continue; + } //end if + else + { + //RemoveEqualPoints(w, 0.2); + if ( WindingIsTiny( w ) ) { + FreeWinding( w ); + q3_dbrushsidetextured[brush->firstSide + j] = true; + continue; + } //end if + else + { + we = WindingError( w ); + if ( we == WE_NOTENOUGHPOINTS + || we == WE_SMALLAREA + || we == WE_POINTBOGUSRANGE +// || we == WE_NONCONVEX + ) { + FreeWinding( w ); + q3_dbrushsidetextured[brush->firstSide + j] = true; + continue; + } //end if + } //end else + } //end else + if ( WindingArea( w ) < 20 ) { + q3_dbrushsidetextured[brush->firstSide + j] = true; + continue; + } //end if + //find a face for texturing this brush + for ( k = 0; k < q3_numDrawSurfaces; k++ ) + { + surface = &q3_drawSurfaces[k]; + if ( surface->surfaceType != MST_PLANAR ) { + continue; + } + // + //Q3_SurfacePlane(surface, plane.normal, &plane.dist); + plane = &q3_surfaceplanes[k]; + //the surface plane and the brush side plane should be pretty much the same + if ( fabs( fabs( plane->dist ) - fabs( q3_dplanes[brushside->planeNum].dist ) ) > 5 ) { + continue; + } + dot = DotProduct( plane->normal, q3_dplanes[brushside->planeNum].normal ); + if ( dot > -0.9 && dot < 0.9 ) { + continue; + } + //if the face is partly or totally on the brush side + if ( Q3_FaceOnWinding( surface, w ) ) { + q3_dbrushsidetextured[brush->firstSide + j] = true; + //Log_Write("Q3_FaceOnWinding"); + break; + } //end if + } //end for + FreeWinding( w ); + } //end for + } //end for + qprintf( "\r%6d brush sides\n", numsides ); + numtextured = 0; + for ( i = 0; i < q3_numbrushsides; i++ ) + { + if ( forcesidesvisible ) { + q3_dbrushsidetextured[i] = true; + } + if ( q3_dbrushsidetextured[i] ) { + numtextured++; + } + } //end for + Log_Print( "%d brush sides textured out of %d\n", numtextured, q3_numbrushsides ); +} //end of the function Q3_FindVisibleBrushSides + +/* +============= +Q3_SwapBlock + +If all values are 32 bits, this can be used to swap everything +============= +*/ +void Q3_SwapBlock( int *block, int sizeOfBlock ) { + int i; + + sizeOfBlock >>= 2; + for ( i = 0 ; i < sizeOfBlock ; i++ ) { + block[i] = LittleLong( block[i] ); + } +} //end of the function Q3_SwapBlock + +/* +============= +Q3_SwapBSPFile + +Byte swaps all data in a bsp file. +============= +*/ +void Q3_SwapBSPFile( void ) { + int i; + + // models + Q3_SwapBlock( (int *)q3_dmodels, q3_nummodels * sizeof( q3_dmodels[0] ) ); + + // shaders (don't swap the name) + for ( i = 0 ; i < q3_numShaders ; i++ ) { + q3_dshaders[i].contentFlags = LittleLong( q3_dshaders[i].contentFlags ); + q3_dshaders[i].surfaceFlags = LittleLong( q3_dshaders[i].surfaceFlags ); + // + // RF, only keep content flags that are consistent with q3map + q3_dshaders[i].contentFlags &= ( CONTENTS_SOLID | CONTENTS_WINDOW | CONTENTS_LAVA | CONTENTS_SLIME | CONTENTS_WATER | CONTENTS_MIST | CONTENTS_AREAPORTAL | CONTENTS_PLAYERCLIP | CONTENTS_MONSTERCLIP | CONTENTS_ORIGIN | CONTENTS_DETAIL ); + } + + // planes + Q3_SwapBlock( (int *)q3_dplanes, q3_numplanes * sizeof( q3_dplanes[0] ) ); + + // nodes + Q3_SwapBlock( (int *)q3_dnodes, q3_numnodes * sizeof( q3_dnodes[0] ) ); + + // leafs + Q3_SwapBlock( (int *)q3_dleafs, q3_numleafs * sizeof( q3_dleafs[0] ) ); + + // leaffaces + Q3_SwapBlock( (int *)q3_dleafsurfaces, q3_numleafsurfaces * sizeof( q3_dleafsurfaces[0] ) ); + + // leafbrushes + Q3_SwapBlock( (int *)q3_dleafbrushes, q3_numleafbrushes * sizeof( q3_dleafbrushes[0] ) ); + + // brushes + Q3_SwapBlock( (int *)q3_dbrushes, q3_numbrushes * sizeof( q3_dbrushes[0] ) ); + + // brushsides + Q3_SwapBlock( (int *)q3_dbrushsides, q3_numbrushsides * sizeof( q3_dbrushsides[0] ) ); + + // vis + ( (int *)&q3_visBytes )[0] = LittleLong( ( (int *)&q3_visBytes )[0] ); + ( (int *)&q3_visBytes )[1] = LittleLong( ( (int *)&q3_visBytes )[1] ); + + // drawverts (don't swap colors ) + for ( i = 0 ; i < q3_numDrawVerts ; i++ ) { + q3_drawVerts[i].lightmap[0] = LittleFloat( q3_drawVerts[i].lightmap[0] ); + q3_drawVerts[i].lightmap[1] = LittleFloat( q3_drawVerts[i].lightmap[1] ); + q3_drawVerts[i].st[0] = LittleFloat( q3_drawVerts[i].st[0] ); + q3_drawVerts[i].st[1] = LittleFloat( q3_drawVerts[i].st[1] ); + q3_drawVerts[i].xyz[0] = LittleFloat( q3_drawVerts[i].xyz[0] ); + q3_drawVerts[i].xyz[1] = LittleFloat( q3_drawVerts[i].xyz[1] ); + q3_drawVerts[i].xyz[2] = LittleFloat( q3_drawVerts[i].xyz[2] ); + q3_drawVerts[i].normal[0] = LittleFloat( q3_drawVerts[i].normal[0] ); + q3_drawVerts[i].normal[1] = LittleFloat( q3_drawVerts[i].normal[1] ); + q3_drawVerts[i].normal[2] = LittleFloat( q3_drawVerts[i].normal[2] ); + } + + // drawindexes + Q3_SwapBlock( (int *)q3_drawIndexes, q3_numDrawIndexes * sizeof( q3_drawIndexes[0] ) ); + + // drawsurfs + Q3_SwapBlock( (int *)q3_drawSurfaces, q3_numDrawSurfaces * sizeof( q3_drawSurfaces[0] ) ); + + // fogs + for ( i = 0 ; i < q3_numFogs ; i++ ) { + q3_dfogs[i].brushNum = LittleLong( q3_dfogs[i].brushNum ); + } +} + + + +/* +============= +Q3_CopyLump +============= +*/ +int Q3_CopyLump( q3_dheader_t *header, int lump, void **dest, int size ) { + int length, ofs; + + length = header->lumps[lump].filelen; + ofs = header->lumps[lump].fileofs; + + if ( length % size ) { + Error( "Q3_LoadBSPFile: odd lump size" ); + } + + *dest = GetMemory( length ); + + memcpy( *dest, (byte *)header + ofs, length ); + + return length / size; +} + +/* +============= +Q3_LoadBSPFile +============= +*/ +void Q3_LoadBSPFile( struct quakefile_s *qf ) { + q3_dheader_t *header; + + // load the file header + //LoadFile(filename, (void **)&header, offset, length); + // + LoadQuakeFile( qf, (void **)&header ); + + // swap the header + Q3_SwapBlock( (int *)header, sizeof( *header ) ); + + if ( header->ident != Q3_BSP_IDENT ) { + Error( "%s is not a IBSP file", qf->filename ); + } + if ( header->version != Q3_BSP_VERSION ) { + Error( "%s is version %i, not %i", qf->filename, header->version, Q3_BSP_VERSION ); + } + + q3_numShaders = Q3_CopyLump( header, Q3_LUMP_SHADERS, (void *) &q3_dshaders, sizeof( q3_dshader_t ) ); + q3_nummodels = Q3_CopyLump( header, Q3_LUMP_MODELS, (void *) &q3_dmodels, sizeof( q3_dmodel_t ) ); + q3_numplanes = Q3_CopyLump( header, Q3_LUMP_PLANES, (void *) &q3_dplanes, sizeof( q3_dplane_t ) ); + q3_numleafs = Q3_CopyLump( header, Q3_LUMP_LEAFS, (void *) &q3_dleafs, sizeof( q3_dleaf_t ) ); + q3_numnodes = Q3_CopyLump( header, Q3_LUMP_NODES, (void *) &q3_dnodes, sizeof( q3_dnode_t ) ); + q3_numleafsurfaces = Q3_CopyLump( header, Q3_LUMP_LEAFSURFACES, (void *) &q3_dleafsurfaces, sizeof( q3_dleafsurfaces[0] ) ); + q3_numleafbrushes = Q3_CopyLump( header, Q3_LUMP_LEAFBRUSHES, (void *) &q3_dleafbrushes, sizeof( q3_dleafbrushes[0] ) ); + q3_numbrushes = Q3_CopyLump( header, Q3_LUMP_BRUSHES, (void *) &q3_dbrushes, sizeof( q3_dbrush_t ) ); + q3_numbrushsides = Q3_CopyLump( header, Q3_LUMP_BRUSHSIDES, (void *) &q3_dbrushsides, sizeof( q3_dbrushside_t ) ); + q3_numDrawVerts = Q3_CopyLump( header, Q3_LUMP_DRAWVERTS, (void *) &q3_drawVerts, sizeof( q3_drawVert_t ) ); + q3_numDrawSurfaces = Q3_CopyLump( header, Q3_LUMP_SURFACES, (void *) &q3_drawSurfaces, sizeof( q3_dsurface_t ) ); + q3_numFogs = Q3_CopyLump( header, Q3_LUMP_FOGS, (void *) &q3_dfogs, sizeof( q3_dfog_t ) ); + q3_numDrawIndexes = Q3_CopyLump( header, Q3_LUMP_DRAWINDEXES, (void *) &q3_drawIndexes, sizeof( q3_drawIndexes[0] ) ); + + q3_numVisBytes = Q3_CopyLump( header, Q3_LUMP_VISIBILITY, (void *) &q3_visBytes, 1 ); + q3_numLightBytes = Q3_CopyLump( header, Q3_LUMP_LIGHTMAPS, (void *) &q3_lightBytes, 1 ); + q3_entdatasize = Q3_CopyLump( header, Q3_LUMP_ENTITIES, (void *) &q3_dentdata, 1 ); + + q3_numGridPoints = Q3_CopyLump( header, Q3_LUMP_LIGHTGRID, (void *) &q3_gridData, 8 ); + + + FreeMemory( header ); // everything has been copied out + + // swap everything + Q3_SwapBSPFile(); + + Q3_FindVisibleBrushSides(); + + //Q3_PrintBSPFileSizes(); +} + + +//============================================================================ + +/* +============= +Q3_AddLump +============= +*/ +void Q3_AddLump( FILE *bspfile, q3_dheader_t *header, int lumpnum, void *data, int len ) { + q3_lump_t *lump; + + lump = &header->lumps[lumpnum]; + + lump->fileofs = LittleLong( ftell( bspfile ) ); + lump->filelen = LittleLong( len ); + SafeWrite( bspfile, data, ( len + 3 ) & ~3 ); +} + +/* +============= +Q3_WriteBSPFile + +Swaps the bsp file in place, so it should not be referenced again +============= +*/ +void Q3_WriteBSPFile( char *filename ) { + q3_dheader_t outheader, *header; + FILE *bspfile; + + header = &outheader; + memset( header, 0, sizeof( q3_dheader_t ) ); + + Q3_SwapBSPFile(); + + header->ident = LittleLong( Q3_BSP_IDENT ); + header->version = LittleLong( Q3_BSP_VERSION ); + + bspfile = SafeOpenWrite( filename ); + SafeWrite( bspfile, header, sizeof( q3_dheader_t ) ); // overwritten later + + Q3_AddLump( bspfile, header, Q3_LUMP_SHADERS, q3_dshaders, q3_numShaders * sizeof( q3_dshader_t ) ); + Q3_AddLump( bspfile, header, Q3_LUMP_PLANES, q3_dplanes, q3_numplanes * sizeof( q3_dplane_t ) ); + Q3_AddLump( bspfile, header, Q3_LUMP_LEAFS, q3_dleafs, q3_numleafs * sizeof( q3_dleaf_t ) ); + Q3_AddLump( bspfile, header, Q3_LUMP_NODES, q3_dnodes, q3_numnodes * sizeof( q3_dnode_t ) ); + Q3_AddLump( bspfile, header, Q3_LUMP_BRUSHES, q3_dbrushes, q3_numbrushes * sizeof( q3_dbrush_t ) ); + Q3_AddLump( bspfile, header, Q3_LUMP_BRUSHSIDES, q3_dbrushsides, q3_numbrushsides * sizeof( q3_dbrushside_t ) ); + Q3_AddLump( bspfile, header, Q3_LUMP_LEAFSURFACES, q3_dleafsurfaces, q3_numleafsurfaces * sizeof( q3_dleafsurfaces[0] ) ); + Q3_AddLump( bspfile, header, Q3_LUMP_LEAFBRUSHES, q3_dleafbrushes, q3_numleafbrushes * sizeof( q3_dleafbrushes[0] ) ); + Q3_AddLump( bspfile, header, Q3_LUMP_MODELS, q3_dmodels, q3_nummodels * sizeof( q3_dmodel_t ) ); + Q3_AddLump( bspfile, header, Q3_LUMP_DRAWVERTS, q3_drawVerts, q3_numDrawVerts * sizeof( q3_drawVert_t ) ); + Q3_AddLump( bspfile, header, Q3_LUMP_SURFACES, q3_drawSurfaces, q3_numDrawSurfaces * sizeof( q3_dsurface_t ) ); + Q3_AddLump( bspfile, header, Q3_LUMP_VISIBILITY, q3_visBytes, q3_numVisBytes ); + Q3_AddLump( bspfile, header, Q3_LUMP_LIGHTMAPS, q3_lightBytes, q3_numLightBytes ); + Q3_AddLump( bspfile, header, Q3_LUMP_LIGHTGRID, q3_gridData, 8 * q3_numGridPoints ); + Q3_AddLump( bspfile, header, Q3_LUMP_ENTITIES, q3_dentdata, q3_entdatasize ); + Q3_AddLump( bspfile, header, Q3_LUMP_FOGS, q3_dfogs, q3_numFogs * sizeof( q3_dfog_t ) ); + Q3_AddLump( bspfile, header, Q3_LUMP_DRAWINDEXES, q3_drawIndexes, q3_numDrawIndexes * sizeof( q3_drawIndexes[0] ) ); + + fseek( bspfile, 0, SEEK_SET ); + SafeWrite( bspfile, header, sizeof( q3_dheader_t ) ); + fclose( bspfile ); +} + +//============================================================================ + +/* +============= +Q3_PrintBSPFileSizes + +Dumps info about current file +============= +*/ +void Q3_PrintBSPFileSizes( void ) { + if ( !num_entities ) { + Q3_ParseEntities(); + } + + Log_Print( "%6i models %7i\n" + ,q3_nummodels, (int)( q3_nummodels * sizeof( q3_dmodel_t ) ) ); + Log_Print( "%6i shaders %7i\n" + ,q3_numShaders, (int)( q3_numShaders * sizeof( q3_dshader_t ) ) ); + Log_Print( "%6i brushes %7i\n" + ,q3_numbrushes, (int)( q3_numbrushes * sizeof( q3_dbrush_t ) ) ); + Log_Print( "%6i brushsides %7i\n" + ,q3_numbrushsides, (int)( q3_numbrushsides * sizeof( q3_dbrushside_t ) ) ); + Log_Print( "%6i fogs %7i\n" + ,q3_numFogs, (int)( q3_numFogs * sizeof( q3_dfog_t ) ) ); + Log_Print( "%6i planes %7i\n" + ,q3_numplanes, (int)( q3_numplanes * sizeof( q3_dplane_t ) ) ); + Log_Print( "%6i entdata %7i\n", num_entities, q3_entdatasize ); + + Log_Print( "\n" ); + + Log_Print( "%6i nodes %7i\n" + ,q3_numnodes, (int)( q3_numnodes * sizeof( q3_dnode_t ) ) ); + Log_Print( "%6i leafs %7i\n" + ,q3_numleafs, (int)( q3_numleafs * sizeof( q3_dleaf_t ) ) ); + Log_Print( "%6i leafsurfaces %7i\n" + ,q3_numleafsurfaces, (int)( q3_numleafsurfaces * sizeof( q3_dleafsurfaces[0] ) ) ); + Log_Print( "%6i leafbrushes %7i\n" + ,q3_numleafbrushes, (int)( q3_numleafbrushes * sizeof( q3_dleafbrushes[0] ) ) ); + Log_Print( "%6i drawverts %7i\n" + ,q3_numDrawVerts, (int)( q3_numDrawVerts * sizeof( q3_drawVerts[0] ) ) ); + Log_Print( "%6i drawindexes %7i\n" + ,q3_numDrawIndexes, (int)( q3_numDrawIndexes * sizeof( q3_drawIndexes[0] ) ) ); + Log_Print( "%6i drawsurfaces %7i\n" + ,q3_numDrawSurfaces, (int)( q3_numDrawSurfaces * sizeof( q3_drawSurfaces[0] ) ) ); + + Log_Print( "%6i lightmaps %7i\n" + ,q3_numLightBytes / ( LIGHTMAP_WIDTH * LIGHTMAP_HEIGHT * 3 ), q3_numLightBytes ); + Log_Print( " visibility %7i\n" + , q3_numVisBytes ); +} + +/* +================ +Q3_ParseEntities + +Parses the q3_dentdata string into entities +================ +*/ +void Q3_ParseEntities( void ) { + script_t *script; + + num_entities = 0; + script = LoadScriptMemory( q3_dentdata, q3_entdatasize, "*Quake3 bsp file" ); + SetScriptFlags( script, SCFL_NOSTRINGWHITESPACES | + SCFL_NOSTRINGESCAPECHARS ); + + while ( ParseEntity( script ) ) + { + } //end while + + FreeScript( script ); +} //end of the function Q3_ParseEntities + + +/* +================ +Q3_UnparseEntities + +Generates the q3_dentdata string from all the entities +================ +*/ +void Q3_UnparseEntities( void ) { + char *buf, *end; + epair_t *ep; + char line[2048]; + int i; + + buf = q3_dentdata; + end = buf; + *end = 0; + + for ( i = 0 ; i < num_entities ; i++ ) + { + ep = entities[i].epairs; + if ( !ep ) { + continue; // ent got removed + + } + strcat( end,"{\n" ); + end += 2; + + for ( ep = entities[i].epairs ; ep ; ep = ep->next ) + { + sprintf( line, "\"%s\" \"%s\"\n", ep->key, ep->value ); + strcat( end, line ); + end += strlen( line ); + } + strcat( end,"}\n" ); + end += 2; + + if ( end > buf + Q3_MAX_MAP_ENTSTRING ) { + Error( "Entity text too long" ); + } + } + q3_entdatasize = end - buf + 1; +} //end of the function Q3_UnparseEntities + diff --git a/Projects/Android/jni/rtcw/src/bspc/l_bsp_q3.h b/Projects/Android/jni/rtcw/src/bspc/l_bsp_q3.h new file mode 100644 index 0000000..30a545d --- /dev/null +++ b/Projects/Android/jni/rtcw/src/bspc/l_bsp_q3.h @@ -0,0 +1,88 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +#include "q3files.h" +//#include "surfaceflags.h" + +extern int q3_nummodels; +extern q3_dmodel_t *q3_dmodels; //[MAX_MAP_MODELS]; + +extern int q3_numShaders; +extern q3_dshader_t *q3_dshaders; //[Q3_MAX_MAP_SHADERS]; + +extern int q3_entdatasize; +extern char *q3_dentdata; //[Q3_MAX_MAP_ENTSTRING]; + +extern int q3_numleafs; +extern q3_dleaf_t *q3_dleafs; //[Q3_MAX_MAP_LEAFS]; + +extern int q3_numplanes; +extern q3_dplane_t *q3_dplanes; //[Q3_MAX_MAP_PLANES]; + +extern int q3_numnodes; +extern q3_dnode_t *q3_dnodes; //[Q3_MAX_MAP_NODES]; + +extern int q3_numleafsurfaces; +extern int *q3_dleafsurfaces; //[Q3_MAX_MAP_LEAFFACES]; + +extern int q3_numleafbrushes; +extern int *q3_dleafbrushes; //[Q3_MAX_MAP_LEAFBRUSHES]; + +extern int q3_numbrushes; +extern q3_dbrush_t *q3_dbrushes; //[Q3_MAX_MAP_BRUSHES]; + +extern int q3_numbrushsides; +extern q3_dbrushside_t *q3_dbrushsides; //[Q3_MAX_MAP_BRUSHSIDES]; + +extern int q3_numLightBytes; +extern byte *q3_lightBytes; //[Q3_MAX_MAP_LIGHTING]; + +extern int q3_numGridPoints; +extern byte *q3_gridData; //[Q3_MAX_MAP_LIGHTGRID]; + +extern int q3_numVisBytes; +extern byte *q3_visBytes; //[Q3_MAX_MAP_VISIBILITY]; + +extern int q3_numDrawVerts; +extern q3_drawVert_t *q3_drawVerts; //[Q3_MAX_MAP_DRAW_VERTS]; + +extern int q3_numDrawIndexes; +extern int *q3_drawIndexes; //[Q3_MAX_MAP_DRAW_INDEXES]; + +extern int q3_numDrawSurfaces; +extern q3_dsurface_t *q3_drawSurfaces; //[Q3_MAX_MAP_DRAW_SURFS]; + +extern int q3_numFogs; +extern q3_dfog_t *q3_dfogs; //[Q3_MAX_MAP_FOGS]; + +extern char q3_dbrushsidetextured[Q3_MAX_MAP_BRUSHSIDES]; + +void Q3_LoadBSPFile( struct quakefile_s *qf ); +void Q3_FreeMaxBSP( void ); +void Q3_ParseEntities( void ); diff --git a/Projects/Android/jni/rtcw/src/bspc/l_bsp_sin.c b/Projects/Android/jni/rtcw/src/bspc/l_bsp_sin.c new file mode 100644 index 0000000..745f1da --- /dev/null +++ b/Projects/Android/jni/rtcw/src/bspc/l_bsp_sin.c @@ -0,0 +1,1186 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +#include "l_cmd.h" +#include "l_math.h" +#include "l_mem.h" +#include "l_log.h" +#include "l_poly.h" +#include "../botlib/l_script.h" +#include "l_bsp_ent.h" +#include "l_bsp_sin.h" + +void GetLeafNums( void ); + +//============================================================================= + +int sin_nummodels; +sin_dmodel_t *sin_dmodels; //[SIN_MAX_MAP_MODELS]; + +int sin_visdatasize; +byte *sin_dvisdata; //[SIN_MAX_MAP_VISIBILITY]; +sin_dvis_t *sin_dvis; // = (sin_dvis_t *)sin_sin_dvisdata; + +int sin_lightdatasize; +byte *sin_dlightdata; //[SIN_MAX_MAP_LIGHTING]; + +int sin_entdatasize; +char *sin_dentdata; //[SIN_MAX_MAP_ENTSTRING]; + +int sin_numleafs; +sin_dleaf_t *sin_dleafs; //[SIN_MAX_MAP_LEAFS]; + +int sin_numplanes; +sin_dplane_t *sin_dplanes; //[SIN_MAX_MAP_PLANES]; + +int sin_numvertexes; +sin_dvertex_t *sin_dvertexes; //[SIN_MAX_MAP_VERTS]; + +int sin_numnodes; +sin_dnode_t *sin_dnodes; //[SIN_MAX_MAP_NODES]; + +int sin_numtexinfo; +sin_texinfo_t *sin_texinfo; //[SIN_MAX_MAP_sin_texinfo]; + +int sin_numfaces; +sin_dface_t *sin_dfaces; //[SIN_MAX_MAP_FACES]; + +int sin_numedges; +sin_dedge_t *sin_dedges; //[SIN_MAX_MAP_EDGES]; + +int sin_numleaffaces; +unsigned short *sin_dleaffaces; //[SIN_MAX_MAP_LEAFFACES]; + +int sin_numleafbrushes; +unsigned short *sin_dleafbrushes; //[SIN_MAX_MAP_LEAFBRUSHES]; + +int sin_numsurfedges; +int *sin_dsurfedges; //[SIN_MAX_MAP_SURFEDGES]; + +int sin_numbrushes; +sin_dbrush_t *sin_dbrushes; //[SIN_MAX_MAP_BRUSHES]; + +int sin_numbrushsides; +sin_dbrushside_t *sin_dbrushsides; //[SIN_MAX_MAP_BRUSHSIDES]; + +int sin_numareas; +sin_darea_t *sin_dareas; //[SIN_MAX_MAP_AREAS]; + +int sin_numareaportals; +sin_dareaportal_t *sin_dareaportals; //[SIN_MAX_MAP_AREAPORTALS]; + +int sin_numlightinfo; +sin_lightvalue_t *sin_lightinfo; //[SIN_MAX_MAP_LIGHTINFO]; + +byte sin_dpop[256]; + +char sin_dbrushsidetextured[SIN_MAX_MAP_BRUSHSIDES]; + +int sin_bspallocated = false; +int sin_allocatedbspmem = 0; + +void Sin_AllocMaxBSP( void ) { + //models + sin_nummodels = 0; + sin_dmodels = (sin_dmodel_t *) GetClearedMemory( SIN_MAX_MAP_MODELS * sizeof( sin_dmodel_t ) ); + sin_allocatedbspmem += SIN_MAX_MAP_MODELS * sizeof( sin_dmodel_t ); + //vis data + sin_visdatasize = 0; + sin_dvisdata = (byte *) GetClearedMemory( SIN_MAX_MAP_VISIBILITY * sizeof( byte ) ); + sin_dvis = (sin_dvis_t *) sin_dvisdata; + sin_allocatedbspmem += SIN_MAX_MAP_VISIBILITY * sizeof( byte ); + //light data + sin_lightdatasize = 0; + sin_dlightdata = (byte *) GetClearedMemory( SIN_MAX_MAP_LIGHTING * sizeof( byte ) ); + sin_allocatedbspmem += SIN_MAX_MAP_LIGHTING * sizeof( byte ); + //entity data + sin_entdatasize = 0; + sin_dentdata = (char *) GetClearedMemory( SIN_MAX_MAP_ENTSTRING * sizeof( char ) ); + sin_allocatedbspmem += SIN_MAX_MAP_ENTSTRING * sizeof( char ); + //leafs + sin_numleafs = 0; + sin_dleafs = (sin_dleaf_t *) GetClearedMemory( SIN_MAX_MAP_LEAFS * sizeof( sin_dleaf_t ) ); + sin_allocatedbspmem += SIN_MAX_MAP_LEAFS * sizeof( sin_dleaf_t ); + //planes + sin_numplanes = 0; + sin_dplanes = (sin_dplane_t *) GetClearedMemory( SIN_MAX_MAP_PLANES * sizeof( sin_dplane_t ) ); + sin_allocatedbspmem += SIN_MAX_MAP_PLANES * sizeof( sin_dplane_t ); + //vertexes + sin_numvertexes = 0; + sin_dvertexes = (sin_dvertex_t *) GetClearedMemory( SIN_MAX_MAP_VERTS * sizeof( sin_dvertex_t ) ); + sin_allocatedbspmem += SIN_MAX_MAP_VERTS * sizeof( sin_dvertex_t ); + //nodes + sin_numnodes = 0; + sin_dnodes = (sin_dnode_t *) GetClearedMemory( SIN_MAX_MAP_NODES * sizeof( sin_dnode_t ) ); + sin_allocatedbspmem += SIN_MAX_MAP_NODES * sizeof( sin_dnode_t ); + //texture info + sin_numtexinfo = 0; + sin_texinfo = (sin_texinfo_t *) GetClearedMemory( SIN_MAX_MAP_TEXINFO * sizeof( sin_texinfo_t ) ); + sin_allocatedbspmem += SIN_MAX_MAP_TEXINFO * sizeof( sin_texinfo_t ); + //faces + sin_numfaces = 0; + sin_dfaces = (sin_dface_t *) GetClearedMemory( SIN_MAX_MAP_FACES * sizeof( sin_dface_t ) ); + sin_allocatedbspmem += SIN_MAX_MAP_FACES * sizeof( sin_dface_t ); + //edges + sin_numedges = 0; + sin_dedges = (sin_dedge_t *) GetClearedMemory( SIN_MAX_MAP_EDGES * sizeof( sin_dedge_t ) ); + sin_allocatedbspmem += SIN_MAX_MAP_EDGES * sizeof( sin_dedge_t ); + //leaf faces + sin_numleaffaces = 0; + sin_dleaffaces = (unsigned short *) GetClearedMemory( SIN_MAX_MAP_LEAFFACES * sizeof( unsigned short ) ); + sin_allocatedbspmem += SIN_MAX_MAP_LEAFFACES * sizeof( unsigned short ); + //leaf brushes + sin_numleafbrushes = 0; + sin_dleafbrushes = (unsigned short *) GetClearedMemory( SIN_MAX_MAP_LEAFBRUSHES * sizeof( unsigned short ) ); + sin_allocatedbspmem += SIN_MAX_MAP_LEAFBRUSHES * sizeof( unsigned short ); + //surface edges + sin_numsurfedges = 0; + sin_dsurfedges = (int *) GetClearedMemory( SIN_MAX_MAP_SURFEDGES * sizeof( int ) ); + sin_allocatedbspmem += SIN_MAX_MAP_SURFEDGES * sizeof( int ); + //brushes + sin_numbrushes = 0; + sin_dbrushes = (sin_dbrush_t *) GetClearedMemory( SIN_MAX_MAP_BRUSHES * sizeof( sin_dbrush_t ) ); + sin_allocatedbspmem += SIN_MAX_MAP_BRUSHES * sizeof( sin_dbrush_t ); + //brushsides + sin_numbrushsides = 0; + sin_dbrushsides = (sin_dbrushside_t *) GetClearedMemory( SIN_MAX_MAP_BRUSHSIDES * sizeof( sin_dbrushside_t ) ); + sin_allocatedbspmem += SIN_MAX_MAP_BRUSHSIDES * sizeof( sin_dbrushside_t ); + //areas + sin_numareas = 0; + sin_dareas = (sin_darea_t *) GetClearedMemory( SIN_MAX_MAP_AREAS * sizeof( sin_darea_t ) ); + sin_allocatedbspmem += SIN_MAX_MAP_AREAS * sizeof( sin_darea_t ); + //area portals + sin_numareaportals = 0; + sin_dareaportals = (sin_dareaportal_t *) GetClearedMemory( SIN_MAX_MAP_AREAPORTALS * sizeof( sin_dareaportal_t ) ); + sin_allocatedbspmem += SIN_MAX_MAP_AREAPORTALS * sizeof( sin_dareaportal_t ); + //light info + sin_numlightinfo = 0; + sin_lightinfo = (sin_lightvalue_t *) GetClearedMemory( SIN_MAX_MAP_LIGHTINFO * sizeof( sin_lightvalue_t ) ); + sin_allocatedbspmem += SIN_MAX_MAP_LIGHTINFO * sizeof( sin_lightvalue_t ); + //print allocated memory + Log_Print( "allocated " ); + PrintMemorySize( sin_allocatedbspmem ); + Log_Print( " of BSP memory\n" ); +} //end of the function Sin_AllocMaxBSP + +void Sin_FreeMaxBSP( void ) { + //models + sin_nummodels = 0; + FreeMemory( sin_dmodels ); + sin_dmodels = NULL; + //vis data + sin_visdatasize = 0; + FreeMemory( sin_dvisdata ); + sin_dvisdata = NULL; + sin_dvis = NULL; + //light data + sin_lightdatasize = 0; + FreeMemory( sin_dlightdata ); + sin_dlightdata = NULL; + //entity data + sin_entdatasize = 0; + FreeMemory( sin_dentdata ); + sin_dentdata = NULL; + //leafs + sin_numleafs = 0; + FreeMemory( sin_dleafs ); + sin_dleafs = NULL; + //planes + sin_numplanes = 0; + FreeMemory( sin_dplanes ); + sin_dplanes = NULL; + //vertexes + sin_numvertexes = 0; + FreeMemory( sin_dvertexes ); + sin_dvertexes = NULL; + //nodes + sin_numnodes = 0; + FreeMemory( sin_dnodes ); + sin_dnodes = NULL; + //texture info + sin_numtexinfo = 0; + FreeMemory( sin_texinfo ); + sin_texinfo = NULL; + //faces + sin_numfaces = 0; + FreeMemory( sin_dfaces ); + sin_dfaces = NULL; + //edges + sin_numedges = 0; + FreeMemory( sin_dedges ); + sin_dedges = NULL; + //leaf faces + sin_numleaffaces = 0; + FreeMemory( sin_dleaffaces ); + sin_dleaffaces = NULL; + //leaf brushes + sin_numleafbrushes = 0; + FreeMemory( sin_dleafbrushes ); + sin_dleafbrushes = NULL; + //surface edges + sin_numsurfedges = 0; + FreeMemory( sin_dsurfedges ); + sin_dsurfedges = NULL; + //brushes + sin_numbrushes = 0; + FreeMemory( sin_dbrushes ); + sin_dbrushes = NULL; + //brushsides + sin_numbrushsides = 0; + FreeMemory( sin_dbrushsides ); + sin_dbrushsides = NULL; + //areas + sin_numareas = 0; + FreeMemory( sin_dareas ); + sin_dareas = NULL; + //area portals + sin_numareaportals = 0; + FreeMemory( sin_dareaportals ); + sin_dareaportals = NULL; + //light info + sin_numlightinfo = 0; + FreeMemory( sin_lightinfo ); + sin_lightinfo = NULL; + // + Log_Print( "freed " ); + PrintMemorySize( sin_allocatedbspmem ); + Log_Print( " of BSP memory\n" ); + sin_allocatedbspmem = 0; +} //end of the function Sin_FreeMaxBSP + +#define WCONVEX_EPSILON 0.5 + +//=========================================================================== +// returns the amount the face and the winding overlap +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +float Sin_FaceOnWinding( sin_dface_t *face, winding_t *winding ) { + int i, edgenum, side; + float dist, area; + sin_dplane_t plane; + vec_t *v1, *v2; + vec3_t normal, edgevec; + winding_t *w; + + // + w = CopyWinding( winding ); + memcpy( &plane, &sin_dplanes[face->planenum], sizeof( sin_dplane_t ) ); + //check on which side of the plane the face is + if ( face->side ) { + VectorNegate( plane.normal, plane.normal ); + plane.dist = -plane.dist; + } //end if + for ( i = 0; i < face->numedges && w; i++ ) + { + //get the first and second vertex of the edge + edgenum = sin_dsurfedges[face->firstedge + i]; + side = edgenum > 0; + //if the face plane is flipped + v1 = sin_dvertexes[sin_dedges[abs( edgenum )].v[side]].point; + v2 = sin_dvertexes[sin_dedges[abs( edgenum )].v[!side]].point; + //create a plane through the edge vector, orthogonal to the face plane + //and with the normal vector pointing out of the face + VectorSubtract( v1, v2, edgevec ); + CrossProduct( edgevec, plane.normal, normal ); + VectorNormalize( normal ); + dist = DotProduct( normal, v1 ); + // + ChopWindingInPlace( &w, normal, dist, 0.9 ); //CLIP_EPSILON + } //end for + if ( w ) { + area = WindingArea( w ); + FreeWinding( w ); + return area; + } //end if + return 0; +} //end of the function Sin_FaceOnWinding +//=========================================================================== +// creates a winding for the given brush side on the given brush +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +winding_t *Sin_BrushSideWinding( sin_dbrush_t *brush, sin_dbrushside_t *baseside ) { + int i; + sin_dplane_t *baseplane, *plane; + sin_dbrushside_t *side; + winding_t *w; + + //create a winding for the brush side with the given planenumber + baseplane = &sin_dplanes[baseside->planenum]; + w = BaseWindingForPlane( baseplane->normal, baseplane->dist ); + for ( i = 0; i < brush->numsides && w; i++ ) + { + side = &sin_dbrushsides[brush->firstside + i]; + //don't chop with the base plane + if ( side->planenum == baseside->planenum ) { + continue; + } + //also don't use planes that are almost equal + plane = &sin_dplanes[side->planenum]; + if ( DotProduct( baseplane->normal, plane->normal ) > 0.999 + && fabs( baseplane->dist - plane->dist ) < 0.01 ) { + continue; + } + // + plane = &sin_dplanes[side->planenum ^ 1]; + ChopWindingInPlace( &w, plane->normal, plane->dist, 0 ); //CLIP_EPSILON); + } //end for + return w; +} //end of the function Sin_BrushSideWinding +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int Sin_HintSkipBrush( sin_dbrush_t *brush ) { + int j; + sin_dbrushside_t *brushside; + + for ( j = 0; j < brush->numsides; j++ ) + { + brushside = &sin_dbrushsides[brush->firstside + j]; + if ( brushside->texinfo > 0 ) { + if ( sin_texinfo[brushside->texinfo].flags & ( SURF_SKIP | SURF_HINT ) ) { + return true; + } //end if + } //end if + } //end for + return false; +} //end of the function Sin_HintSkipBrush +//=========================================================================== +// fix screwed brush texture references +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +qboolean WindingIsTiny( winding_t *w ); + +void Sin_FixTextureReferences( void ) { + int i, j, k, we; + sin_dbrushside_t *brushside; + sin_dbrush_t *brush; + sin_dface_t *face; + winding_t *w; + + memset( sin_dbrushsidetextured, false, SIN_MAX_MAP_BRUSHSIDES ); + //go over all the brushes + for ( i = 0; i < sin_numbrushes; i++ ) + { + brush = &sin_dbrushes[i]; + //hint brushes are not textured + if ( Sin_HintSkipBrush( brush ) ) { + continue; + } + //go over all the sides of the brush + for ( j = 0; j < brush->numsides; j++ ) + { + brushside = &sin_dbrushsides[brush->firstside + j]; + // + w = Sin_BrushSideWinding( brush, brushside ); + if ( !w ) { + sin_dbrushsidetextured[brush->firstside + j] = true; + continue; + } //end if + else + { + //RemoveEqualPoints(w, 0.2); + if ( WindingIsTiny( w ) ) { + FreeWinding( w ); + sin_dbrushsidetextured[brush->firstside + j] = true; + continue; + } //end if + else + { + we = WindingError( w ); + if ( we == WE_NOTENOUGHPOINTS + || we == WE_SMALLAREA + || we == WE_POINTBOGUSRANGE +// || we == WE_NONCONVEX + ) { + FreeWinding( w ); + sin_dbrushsidetextured[brush->firstside + j] = true; + continue; + } //end if + } //end else + } //end else + if ( WindingArea( w ) < 20 ) { + sin_dbrushsidetextured[brush->firstside + j] = true; + } //end if + //find a face for texturing this brush + for ( k = 0; k < sin_numfaces; k++ ) + { + face = &sin_dfaces[k]; + //if the face is in the same plane as the brush side + if ( ( face->planenum & ~1 ) != ( brushside->planenum & ~1 ) ) { + continue; + } + //if the face is partly or totally on the brush side + if ( Sin_FaceOnWinding( face, w ) ) { + brushside->texinfo = face->texinfo; + sin_dbrushsidetextured[brush->firstside + j] = true; + break; + } //end if + } //end for + FreeWinding( w ); + } //end for + } //end for +} //end of the function Sin_FixTextureReferences*/ + +/* +=============== +CompressVis + +=============== +*/ +int Sin_CompressVis( byte *vis, byte *dest ) { + int j; + int rep; + int visrow; + byte *dest_p; + + dest_p = dest; +// visrow = (r_numvisleafs + 7)>>3; + visrow = ( sin_dvis->numclusters + 7 ) >> 3; + + for ( j = 0 ; j < visrow ; j++ ) + { + *dest_p++ = vis[j]; + if ( vis[j] ) { + continue; + } + + rep = 1; + for ( j++; j < visrow ; j++ ) + if ( vis[j] || rep == 255 ) { + break; + } else { + rep++; + } + *dest_p++ = rep; + j--; + } + + return dest_p - dest; +} //end of the function Sin_CompressVis + + +/* +=================== +DecompressVis +=================== +*/ +void Sin_DecompressVis( byte *in, byte *decompressed ) { + int c; + byte *out; + int row; + +// row = (r_numvisleafs+7)>>3; + row = ( sin_dvis->numclusters + 7 ) >> 3; + out = decompressed; + + do + { + if ( *in ) { + *out++ = *in++; + continue; + } + + c = in[1]; + if ( !c ) { + Error( "DecompressVis: 0 repeat" ); + } + in += 2; + while ( c ) + { + *out++ = 0; + c--; + } + } while ( out - decompressed < row ); +} //end of the function Sin_DecompressVis + +//============================================================================= + +/* +============= +Sin_SwapBSPFile + +Byte swaps all data in a bsp file. +============= +*/ +void Sin_SwapBSPFile( qboolean todisk ) { + int i, j; + sin_dmodel_t *d; + + +// models + for ( i = 0 ; i < sin_nummodels ; i++ ) + { + d = &sin_dmodels[i]; + + d->firstface = LittleLong( d->firstface ); + d->numfaces = LittleLong( d->numfaces ); + d->headnode = LittleLong( d->headnode ); + + for ( j = 0 ; j < 3 ; j++ ) + { + d->mins[j] = LittleFloat( d->mins[j] ); + d->maxs[j] = LittleFloat( d->maxs[j] ); + d->origin[j] = LittleFloat( d->origin[j] ); + } + } + +// +// vertexes +// + for ( i = 0 ; i < sin_numvertexes ; i++ ) + { + for ( j = 0 ; j < 3 ; j++ ) + sin_dvertexes[i].point[j] = LittleFloat( sin_dvertexes[i].point[j] ); + } + +// +// planes +// + for ( i = 0 ; i < sin_numplanes ; i++ ) + { + for ( j = 0 ; j < 3 ; j++ ) + sin_dplanes[i].normal[j] = LittleFloat( sin_dplanes[i].normal[j] ); + sin_dplanes[i].dist = LittleFloat( sin_dplanes[i].dist ); + sin_dplanes[i].type = LittleLong( sin_dplanes[i].type ); + } + +// +// sin_texinfos +// + for ( i = 0; i < sin_numtexinfo; i++ ) + { + for ( j = 0 ; j < 8 ; j++ ) + sin_texinfo[i].vecs[0][j] = LittleFloat( sin_texinfo[i].vecs[0][j] ); +#ifdef SIN + sin_texinfo[i].trans_mag = LittleFloat( sin_texinfo[i].trans_mag ); + sin_texinfo[i].trans_angle = LittleLong( sin_texinfo[i].trans_angle ); + sin_texinfo[i].animtime = LittleFloat( sin_texinfo[i].animtime ); + sin_texinfo[i].nonlit = LittleFloat( sin_texinfo[i].nonlit ); + sin_texinfo[i].translucence = LittleFloat( sin_texinfo[i].translucence ); + sin_texinfo[i].friction = LittleFloat( sin_texinfo[i].friction ); + sin_texinfo[i].restitution = LittleFloat( sin_texinfo[i].restitution ); + sin_texinfo[i].flags = LittleUnsigned( sin_texinfo[i].flags ); +#else + sin_texinfo[i].value = LittleLong( sin_texinfo[i].value ); + sin_texinfo[i].flags = LittleLong( sin_texinfo[i].flags ); +#endif + sin_texinfo[i].nexttexinfo = LittleLong( sin_texinfo[i].nexttexinfo ); + } + +#ifdef SIN +// +// lightinfos +// + for ( i = 0; i < sin_numlightinfo; i++ ) + { + for ( j = 0 ; j < 3 ; j++ ) + { + sin_lightinfo[i].color[j] = LittleFloat( sin_lightinfo[i].color[j] ); + } + sin_lightinfo[i].value = LittleLong( sin_lightinfo[i].value ); + sin_lightinfo[i].direct = LittleFloat( sin_lightinfo[i].direct ); + sin_lightinfo[i].directangle = LittleFloat( sin_lightinfo[i].directangle ); + sin_lightinfo[i].directstyle = LittleFloat( sin_lightinfo[i].directstyle ); + } +#endif + +// +// faces +// + for ( i = 0 ; i < sin_numfaces ; i++ ) + { + sin_dfaces[i].texinfo = LittleShort( sin_dfaces[i].texinfo ); +#ifdef SIN + sin_dfaces[i].lightinfo = LittleLong( sin_dfaces[i].lightinfo ); + sin_dfaces[i].planenum = LittleUnsignedShort( sin_dfaces[i].planenum ); +#else + sin_dfaces[i].planenum = LittleShort( sin_dfaces[i].planenum ); +#endif + sin_dfaces[i].side = LittleShort( sin_dfaces[i].side ); + sin_dfaces[i].lightofs = LittleLong( sin_dfaces[i].lightofs ); + sin_dfaces[i].firstedge = LittleLong( sin_dfaces[i].firstedge ); + sin_dfaces[i].numedges = LittleShort( sin_dfaces[i].numedges ); + } + +// +// nodes +// + for ( i = 0 ; i < sin_numnodes ; i++ ) + { + sin_dnodes[i].planenum = LittleLong( sin_dnodes[i].planenum ); + for ( j = 0 ; j < 3 ; j++ ) + { + sin_dnodes[i].mins[j] = LittleShort( sin_dnodes[i].mins[j] ); + sin_dnodes[i].maxs[j] = LittleShort( sin_dnodes[i].maxs[j] ); + } + sin_dnodes[i].children[0] = LittleLong( sin_dnodes[i].children[0] ); + sin_dnodes[i].children[1] = LittleLong( sin_dnodes[i].children[1] ); +#ifdef SIN + sin_dnodes[i].firstface = LittleUnsignedShort( sin_dnodes[i].firstface ); + sin_dnodes[i].numfaces = LittleUnsignedShort( sin_dnodes[i].numfaces ); +#else + sin_dnodes[i].firstface = LittleShort( sin_dnodes[i].firstface ); + sin_dnodes[i].numfaces = LittleShort( sin_dnodes[i].numfaces ); +#endif + } + +// +// leafs +// + for ( i = 0 ; i < sin_numleafs ; i++ ) + { + sin_dleafs[i].contents = LittleLong( sin_dleafs[i].contents ); + sin_dleafs[i].cluster = LittleShort( sin_dleafs[i].cluster ); + sin_dleafs[i].area = LittleShort( sin_dleafs[i].area ); + for ( j = 0 ; j < 3 ; j++ ) + { + sin_dleafs[i].mins[j] = LittleShort( sin_dleafs[i].mins[j] ); + sin_dleafs[i].maxs[j] = LittleShort( sin_dleafs[i].maxs[j] ); + } +#ifdef SIN + sin_dleafs[i].firstleafface = LittleUnsignedShort( sin_dleafs[i].firstleafface ); + sin_dleafs[i].numleaffaces = LittleUnsignedShort( sin_dleafs[i].numleaffaces ); + sin_dleafs[i].firstleafbrush = LittleUnsignedShort( sin_dleafs[i].firstleafbrush ); + sin_dleafs[i].numleafbrushes = LittleUnsignedShort( sin_dleafs[i].numleafbrushes ); +#else + sin_dleafs[i].firstleafface = LittleShort( sin_dleafs[i].firstleafface ); + sin_dleafs[i].numleaffaces = LittleShort( sin_dleafs[i].numleaffaces ); + sin_dleafs[i].firstleafbrush = LittleShort( sin_dleafs[i].firstleafbrush ); + sin_dleafs[i].numleafbrushes = LittleShort( sin_dleafs[i].numleafbrushes ); +#endif + } + +// +// leaffaces +// + for ( i = 0 ; i < sin_numleaffaces ; i++ ) + sin_dleaffaces[i] = LittleShort( sin_dleaffaces[i] ); + +// +// leafbrushes +// + for ( i = 0 ; i < sin_numleafbrushes ; i++ ) + sin_dleafbrushes[i] = LittleShort( sin_dleafbrushes[i] ); + +// +// surfedges +// + for ( i = 0 ; i < sin_numsurfedges ; i++ ) + sin_dsurfedges[i] = LittleLong( sin_dsurfedges[i] ); + +// +// edges +// + for ( i = 0 ; i < sin_numedges ; i++ ) + { +#ifdef SIN + sin_dedges[i].v[0] = LittleUnsignedShort( sin_dedges[i].v[0] ); + sin_dedges[i].v[1] = LittleUnsignedShort( sin_dedges[i].v[1] ); +#else + sin_dedges[i].v[0] = LittleShort( sin_dedges[i].v[0] ); + sin_dedges[i].v[1] = LittleShort( sin_dedges[i].v[1] ); +#endif + } + +// +// brushes +// + for ( i = 0 ; i < sin_numbrushes ; i++ ) + { + sin_dbrushes[i].firstside = LittleLong( sin_dbrushes[i].firstside ); + sin_dbrushes[i].numsides = LittleLong( sin_dbrushes[i].numsides ); + sin_dbrushes[i].contents = LittleLong( sin_dbrushes[i].contents ); + } + +// +// areas +// + for ( i = 0 ; i < sin_numareas ; i++ ) + { + sin_dareas[i].numareaportals = LittleLong( sin_dareas[i].numareaportals ); + sin_dareas[i].firstareaportal = LittleLong( sin_dareas[i].firstareaportal ); + } + +// +// areasportals +// + for ( i = 0 ; i < sin_numareaportals ; i++ ) + { + sin_dareaportals[i].portalnum = LittleLong( sin_dareaportals[i].portalnum ); + sin_dareaportals[i].otherarea = LittleLong( sin_dareaportals[i].otherarea ); + } + +// +// brushsides +// + for ( i = 0 ; i < sin_numbrushsides ; i++ ) + { +#ifdef SIN + sin_dbrushsides[i].planenum = LittleUnsignedShort( sin_dbrushsides[i].planenum ); +#else + sin_dbrushsides[i].planenum = LittleShort( sin_dbrushsides[i].planenum ); +#endif + sin_dbrushsides[i].texinfo = LittleShort( sin_dbrushsides[i].texinfo ); +#ifdef SIN + sin_dbrushsides[i].lightinfo = LittleLong( sin_dbrushsides[i].lightinfo ); +#endif + } + +// +// visibility +// + if ( todisk ) { + j = sin_dvis->numclusters; + } else { + j = LittleLong( sin_dvis->numclusters ); + } + sin_dvis->numclusters = LittleLong( sin_dvis->numclusters ); + for ( i = 0 ; i < j ; i++ ) + { + sin_dvis->bitofs[i][0] = LittleLong( sin_dvis->bitofs[i][0] ); + sin_dvis->bitofs[i][1] = LittleLong( sin_dvis->bitofs[i][1] ); + } +} //end of the function Sin_SwapBSPFile + + +sin_dheader_t *header; +#ifdef SIN +int Sin_CopyLump( int lump, void *dest, int size, int maxsize ) { + int length, ofs; + + length = header->lumps[lump].filelen; + ofs = header->lumps[lump].fileofs; + + if ( length % size ) { + Error( "Sin_LoadBSPFile: odd lump size" ); + } + + if ( ( length / size ) > maxsize ) { + Error( "Sin_LoadBSPFile: exceeded max size for lump %d size %d > maxsize %d\n", lump, ( length / size ), maxsize ); + } + + memcpy( dest, (byte *)header + ofs, length ); + + return length / size; +} +#else +int Sin_CopyLump( int lump, void *dest, int size ) { + int length, ofs; + + length = header->lumps[lump].filelen; + ofs = header->lumps[lump].fileofs; + + if ( length % size ) { + Error( "Sin_LoadBSPFile: odd lump size" ); + } + + memcpy( dest, (byte *)header + ofs, length ); + + return length / size; +} +#endif + +/* +============= +Sin_LoadBSPFile +============= +*/ +void Sin_LoadBSPFile( char *filename, int offset, int length ) { + int i; + +// +// load the file header +// + LoadFile( filename, (void **)&header, offset, length ); + +// swap the header + for ( i = 0 ; i < sizeof( sin_dheader_t ) / 4 ; i++ ) + ( (int *)header )[i] = LittleLong( ( (int *)header )[i] ); + + if ( header->ident != SIN_BSPHEADER && header->ident != SINGAME_BSPHEADER ) { + Error( "%s is not a IBSP file", filename ); + } + if ( header->version != SIN_BSPVERSION && header->version != SINGAME_BSPVERSION ) { + Error( "%s is version %i, not %i", filename, header->version, SIN_BSPVERSION ); + } + +#ifdef SIN + sin_nummodels = Sin_CopyLump( SIN_LUMP_MODELS, sin_dmodels, sizeof( sin_dmodel_t ), SIN_MAX_MAP_MODELS ); + sin_numvertexes = Sin_CopyLump( SIN_LUMP_VERTEXES, sin_dvertexes, sizeof( sin_dvertex_t ), SIN_MAX_MAP_VERTS ); + sin_numplanes = Sin_CopyLump( SIN_LUMP_PLANES, sin_dplanes, sizeof( sin_dplane_t ), SIN_MAX_MAP_PLANES ); + sin_numleafs = Sin_CopyLump( SIN_LUMP_LEAFS, sin_dleafs, sizeof( sin_dleaf_t ), SIN_MAX_MAP_LEAFS ); + sin_numnodes = Sin_CopyLump( SIN_LUMP_NODES, sin_dnodes, sizeof( sin_dnode_t ), SIN_MAX_MAP_NODES ); + sin_numtexinfo = Sin_CopyLump( SIN_LUMP_TEXINFO, sin_texinfo, sizeof( sin_texinfo_t ), SIN_MAX_MAP_TEXINFO ); + sin_numfaces = Sin_CopyLump( SIN_LUMP_FACES, sin_dfaces, sizeof( sin_dface_t ), SIN_MAX_MAP_FACES ); + sin_numleaffaces = Sin_CopyLump( SIN_LUMP_LEAFFACES, sin_dleaffaces, sizeof( sin_dleaffaces[0] ), SIN_MAX_MAP_LEAFFACES ); + sin_numleafbrushes = Sin_CopyLump( SIN_LUMP_LEAFBRUSHES, sin_dleafbrushes, sizeof( sin_dleafbrushes[0] ), SIN_MAX_MAP_LEAFBRUSHES ); + sin_numsurfedges = Sin_CopyLump( SIN_LUMP_SURFEDGES, sin_dsurfedges, sizeof( sin_dsurfedges[0] ), SIN_MAX_MAP_SURFEDGES ); + sin_numedges = Sin_CopyLump( SIN_LUMP_EDGES, sin_dedges, sizeof( sin_dedge_t ), SIN_MAX_MAP_EDGES ); + sin_numbrushes = Sin_CopyLump( SIN_LUMP_BRUSHES, sin_dbrushes, sizeof( sin_dbrush_t ), SIN_MAX_MAP_BRUSHES ); + sin_numbrushsides = Sin_CopyLump( SIN_LUMP_BRUSHSIDES, sin_dbrushsides, sizeof( sin_dbrushside_t ), SIN_MAX_MAP_BRUSHSIDES ); + sin_numareas = Sin_CopyLump( SIN_LUMP_AREAS, sin_dareas, sizeof( sin_darea_t ), SIN_MAX_MAP_AREAS ); + sin_numareaportals = Sin_CopyLump( SIN_LUMP_AREAPORTALS, sin_dareaportals, sizeof( sin_dareaportal_t ), SIN_MAX_MAP_AREAPORTALS ); + sin_numlightinfo = Sin_CopyLump( SIN_LUMP_LIGHTINFO, sin_lightinfo, sizeof( sin_lightvalue_t ), SIN_MAX_MAP_LIGHTINFO ); + + sin_visdatasize = Sin_CopyLump( SIN_LUMP_VISIBILITY, sin_dvisdata, 1, SIN_MAX_MAP_VISIBILITY ); + sin_lightdatasize = Sin_CopyLump( SIN_LUMP_LIGHTING, sin_dlightdata, 1, SIN_MAX_MAP_LIGHTING ); + sin_entdatasize = Sin_CopyLump( SIN_LUMP_ENTITIES, sin_dentdata, 1, SIN_MAX_MAP_ENTSTRING ); + + Sin_CopyLump( SIN_LUMP_POP, sin_dpop, 1, sizeof( sin_dpop ) ); +#else + sin_nummodels = Sin_CopyLump( SIN_LUMP_MODELS, sin_dmodels, sizeof( sin_dmodel_t ) ); + sin_numvertexes = Sin_CopyLump( SIN_LUMP_VERTEXES, sin_dvertexes, sizeof( sin_dvertex_t ) ); + sin_numplanes = Sin_CopyLump( SIN_LUMP_PLANES, sin_dplanes, sizeof( sin_dplane_t ) ); + sin_numleafs = Sin_CopyLump( SIN_LUMP_LEAFS, sin_dleafs, sizeof( sin_dleaf_t ) ); + sin_numnodes = Sin_CopyLump( SIN_LUMP_NODES, sin_dnodes, sizeof( sin_dnode_t ) ); + sin_numtexinfo = Sin_CopyLump( SIN_LUMP_TEXINFO, sin_texinfo, sizeof( sin_texinfo_t ) ); + sin_numfaces = Sin_CopyLump( SIN_LUMP_FACES, sin_dfaces, sizeof( sin_dface_t ) ); + sin_numleaffaces = Sin_CopyLump( SIN_LUMP_LEAFFACES, sin_dleaffaces, sizeof( sin_dleaffaces[0] ) ); + sin_numleafbrushes = Sin_CopyLump( SIN_LUMP_LEAFBRUSHES, sin_dleafbrushes, sizeof( sin_dleafbrushes[0] ) ); + sin_numsurfedges = Sin_CopyLump( SIN_LUMP_SURFEDGES, sin_dsurfedges, sizeof( sin_dsurfedges[0] ) ); + sin_numedges = Sin_CopyLump( SIN_LUMP_EDGES, sin_dedges, sizeof( sin_dedge_t ) ); + sin_numbrushes = Sin_CopyLump( SIN_LUMP_BRUSHES, sin_dbrushes, sizeof( sin_dbrush_t ) ); + sin_numbrushsides = Sin_CopyLump( SIN_LUMP_BRUSHSIDES, sin_dbrushsides, sizeof( sin_dbrushside_t ) ); + sin_numareas = Sin_CopyLump( SIN_LUMP_AREAS, sin_dareas, sizeof( sin_darea_t ) ); + sin_numareaportals = Sin_CopyLump( SIN_LUMP_AREAPORTALS, sin_dareaportals, sizeof( sin_dareaportal_t ) ); + + sin_visdatasize = Sin_CopyLump( SIN_LUMP_VISIBILITY, sin_dvisdata, 1 ); + sin_lightdatasize = Sin_CopyLump( SIN_LUMP_LIGHTING, sin_dlightdata, 1 ); + sin_entdatasize = Sin_CopyLump( SIN_LUMP_ENTITIES, sin_dentdata, 1 ); + + Sin_CopyLump( SIN_LUMP_POP, sin_dpop, 1 ); +#endif + + FreeMemory( header ); // everything has been copied out + +// +// swap everything +// + Sin_SwapBSPFile( false ); +} //end of the function Sin_LoadBSPFile + +/* +============= +Sin_LoadBSPFilesTexinfo + +Only loads the sin_texinfo lump, so qdata can scan for textures +============= +*/ +void Sin_LoadBSPFileTexinfo( char *filename ) { + int i; + FILE *f; + int length, ofs; + + header = GetMemory( sizeof( sin_dheader_t ) ); + + f = fopen( filename, "rb" ); + fread( header, sizeof( sin_dheader_t ), 1, f ); + +// swap the header + for ( i = 0 ; i < sizeof( sin_dheader_t ) / 4 ; i++ ) + ( (int *)header )[i] = LittleLong( ( (int *)header )[i] ); + + if ( header->ident != SIN_BSPHEADER && header->ident != SINGAME_BSPHEADER ) { + Error( "%s is not a IBSP file", filename ); + } + if ( header->version != SIN_BSPVERSION && header->version != SINGAME_BSPVERSION ) { + Error( "%s is version %i, not %i", filename, header->version, SIN_BSPVERSION ); + } + + + length = header->lumps[SIN_LUMP_TEXINFO].filelen; + ofs = header->lumps[SIN_LUMP_TEXINFO].fileofs; + + fseek( f, ofs, SEEK_SET ); + fread( sin_texinfo, length, 1, f ); + fclose( f ); + + sin_numtexinfo = length / sizeof( sin_texinfo_t ); + + FreeMemory( header ); // everything has been copied out + + Sin_SwapBSPFile( false ); +} //end of the function Sin_LoadBSPFilesTexinfo + + +//============================================================================ + +FILE *wadfile; +sin_dheader_t outheader; + +#ifdef SIN +void Sin_AddLump( int lumpnum, void *data, int len, int size, int maxsize ) { + sin_lump_t *lump; + int totallength; + + totallength = len * size; + + if ( len > maxsize ) { + Error( "Sin_WriteBSPFile: exceeded max size for lump %d size %d > maxsize %d\n", lumpnum, len, maxsize ); + } + + lump = &header->lumps[lumpnum]; + + lump->fileofs = LittleLong( ftell( wadfile ) ); + lump->filelen = LittleLong( totallength ); + SafeWrite( wadfile, data, ( totallength + 3 ) & ~3 ); +} +#else +void Sin_AddLump( int lumpnum, void *data, int len ) { + sin_lump_t *lump; + + lump = &header->lumps[lumpnum]; + + lump->fileofs = LittleLong( ftell( wadfile ) ); + lump->filelen = LittleLong( len ); + SafeWrite( wadfile, data, ( len + 3 ) & ~3 ); +} +#endif +/* +============= +Sin_WriteBSPFile + +Swaps the bsp file in place, so it should not be referenced again +============= +*/ +void Sin_WriteBSPFile( char *filename ) { + header = &outheader; + memset( header, 0, sizeof( sin_dheader_t ) ); + + Sin_SwapBSPFile( true ); + + header->ident = LittleLong( SIN_BSPHEADER ); + header->version = LittleLong( SIN_BSPVERSION ); + + wadfile = SafeOpenWrite( filename ); + SafeWrite( wadfile, header, sizeof( sin_dheader_t ) ); // overwritten later + +#ifdef SIN + Sin_AddLump( SIN_LUMP_PLANES, sin_dplanes, sin_numplanes, sizeof( sin_dplane_t ), SIN_MAX_MAP_PLANES ); + Sin_AddLump( SIN_LUMP_LEAFS, sin_dleafs, sin_numleafs, sizeof( sin_dleaf_t ), SIN_MAX_MAP_LEAFS ); + Sin_AddLump( SIN_LUMP_VERTEXES, sin_dvertexes, sin_numvertexes, sizeof( sin_dvertex_t ), SIN_MAX_MAP_VERTS ); + Sin_AddLump( SIN_LUMP_NODES, sin_dnodes, sin_numnodes, sizeof( sin_dnode_t ), SIN_MAX_MAP_NODES ); + Sin_AddLump( SIN_LUMP_TEXINFO, sin_texinfo, sin_numtexinfo, sizeof( sin_texinfo_t ), SIN_MAX_MAP_TEXINFO ); + Sin_AddLump( SIN_LUMP_FACES, sin_dfaces, sin_numfaces, sizeof( sin_dface_t ), SIN_MAX_MAP_FACES ); + Sin_AddLump( SIN_LUMP_BRUSHES, sin_dbrushes, sin_numbrushes, sizeof( sin_dbrush_t ), SIN_MAX_MAP_BRUSHES ); + Sin_AddLump( SIN_LUMP_BRUSHSIDES, sin_dbrushsides, sin_numbrushsides, sizeof( sin_dbrushside_t ), SIN_MAX_MAP_BRUSHSIDES ); + Sin_AddLump( SIN_LUMP_LEAFFACES, sin_dleaffaces, sin_numleaffaces, sizeof( sin_dleaffaces[0] ), SIN_MAX_MAP_LEAFFACES ); + Sin_AddLump( SIN_LUMP_LEAFBRUSHES, sin_dleafbrushes, sin_numleafbrushes, sizeof( sin_dleafbrushes[0] ), SIN_MAX_MAP_LEAFBRUSHES ); + Sin_AddLump( SIN_LUMP_SURFEDGES, sin_dsurfedges, sin_numsurfedges, sizeof( sin_dsurfedges[0] ), SIN_MAX_MAP_SURFEDGES ); + Sin_AddLump( SIN_LUMP_EDGES, sin_dedges, sin_numedges, sizeof( sin_dedge_t ), SIN_MAX_MAP_EDGES ); + Sin_AddLump( SIN_LUMP_MODELS, sin_dmodels, sin_nummodels, sizeof( sin_dmodel_t ), SIN_MAX_MAP_MODELS ); + Sin_AddLump( SIN_LUMP_AREAS, sin_dareas, sin_numareas, sizeof( sin_darea_t ), SIN_MAX_MAP_AREAS ); + Sin_AddLump( SIN_LUMP_AREAPORTALS, sin_dareaportals, sin_numareaportals, sizeof( sin_dareaportal_t ), SIN_MAX_MAP_AREAPORTALS ); + Sin_AddLump( SIN_LUMP_LIGHTINFO, sin_lightinfo, sin_numlightinfo, sizeof( sin_lightvalue_t ), SIN_MAX_MAP_LIGHTINFO ); + + Sin_AddLump( SIN_LUMP_LIGHTING, sin_dlightdata, sin_lightdatasize, 1, SIN_MAX_MAP_LIGHTING ); + Sin_AddLump( SIN_LUMP_VISIBILITY, sin_dvisdata, sin_visdatasize, 1, SIN_MAX_MAP_VISIBILITY ); + Sin_AddLump( SIN_LUMP_ENTITIES, sin_dentdata, sin_entdatasize, 1, SIN_MAX_MAP_ENTSTRING ); + Sin_AddLump( SIN_LUMP_POP, sin_dpop, sizeof( sin_dpop ), 1, sizeof( sin_dpop ) ); +#else + Sin_AddLump( SIN_LUMP_PLANES, sin_dplanes, sin_numplanes * sizeof( sin_dplane_t ) ); + Sin_AddLump( SIN_LUMP_LEAFS, sin_dleafs, sin_numleafs * sizeof( sin_dleaf_t ) ); + Sin_AddLump( SIN_LUMP_VERTEXES, sin_dvertexes, sin_numvertexes * sizeof( sin_dvertex_t ) ); + Sin_AddLump( SIN_LUMP_NODES, sin_dnodes, sin_numnodes * sizeof( sin_dnode_t ) ); + Sin_AddLump( SIN_LUMP_TEXINFO, sin_texinfo, sin_numtexinfo * sizeof( sin_texinfo_t ) ); + Sin_AddLump( SIN_LUMP_FACES, sin_dfaces, sin_numfaces * sizeof( sin_dface_t ) ); + Sin_AddLump( SIN_LUMP_BRUSHES, sin_dbrushes, sin_numbrushes * sizeof( sin_dbrush_t ) ); + Sin_AddLump( SIN_LUMP_BRUSHSIDES, sin_dbrushsides, sin_numbrushsides * sizeof( sin_dbrushside_t ) ); + Sin_AddLump( SIN_LUMP_LEAFFACES, sin_dleaffaces, sin_numleaffaces * sizeof( sin_dleaffaces[0] ) ); + Sin_AddLump( SIN_LUMP_LEAFBRUSHES, sin_dleafbrushes, sin_numleafbrushes * sizeof( sin_dleafbrushes[0] ) ); + Sin_AddLump( SIN_LUMP_SURFEDGES, sin_dsurfedges, sin_numsurfedges * sizeof( sin_dsurfedges[0] ) ); + Sin_AddLump( SIN_LUMP_EDGES, sin_dedges, sin_numedges * sizeof( sin_dedge_t ) ); + Sin_AddLump( SIN_LUMP_MODELS, sin_dmodels, sin_nummodels * sizeof( sin_dmodel_t ) ); + Sin_AddLump( SIN_LUMP_AREAS, sin_dareas, sin_numareas * sizeof( sin_darea_t ) ); + Sin_AddLump( SIN_LUMP_AREAPORTALS, sin_dareaportals, sin_numareaportals * sizeof( sin_dareaportal_t ) ); + + Sin_AddLump( SIN_LUMP_LIGHTING, sin_dlightdata, sin_lightdatasize ); + Sin_AddLump( SIN_LUMP_VISIBILITY, sin_dvisdata, sin_visdatasize ); + Sin_AddLump( SIN_LUMP_ENTITIES, sin_dentdata, sin_entdatasize ); + Sin_AddLump( SIN_LUMP_POP, sin_dpop, sizeof( sin_dpop ) ); +#endif + + fseek( wadfile, 0, SEEK_SET ); + SafeWrite( wadfile, header, sizeof( sin_dheader_t ) ); + fclose( wadfile ); +} + +//============================================================================ + + +//============================================ + +/* +================ +ParseEntities + +Parses the sin_dentdata string into entities +================ +*/ +void Sin_ParseEntities( void ) { + script_t *script; + + num_entities = 0; + script = LoadScriptMemory( sin_dentdata, sin_entdatasize, "*sin bsp file" ); + SetScriptFlags( script, SCFL_NOSTRINGWHITESPACES | + SCFL_NOSTRINGESCAPECHARS ); + + while ( ParseEntity( script ) ) + { + } //end while + + FreeScript( script ); +} //end of the function Sin_ParseEntities + + +/* +================ +UnparseEntities + +Generates the sin_dentdata string from all the entities +================ +*/ +void Sin_UnparseEntities( void ) { + char *buf, *end; + epair_t *ep; + char line[2048]; + int i; + char key[1024], value[1024]; + + buf = sin_dentdata; + end = buf; + *end = 0; + + for ( i = 0 ; i < num_entities ; i++ ) + { + ep = entities[i].epairs; + if ( !ep ) { + continue; // ent got removed + + } + strcat( end,"{\n" ); + end += 2; + + for ( ep = entities[i].epairs ; ep ; ep = ep->next ) + { + strcpy( key, ep->key ); + StripTrailing( key ); + strcpy( value, ep->value ); + StripTrailing( value ); + + sprintf( line, "\"%s\" \"%s\"\n", key, value ); + strcat( end, line ); + end += strlen( line ); + } + strcat( end,"}\n" ); + end += 2; + + if ( end > buf + SIN_MAX_MAP_ENTSTRING ) { + Error( "Entity text too long" ); + } + } + sin_entdatasize = end - buf + 1; +} //end of the function Sin_UnparseEntities + +#ifdef SIN +void FreeValueKeys( entity_t *ent ) { + epair_t *ep,*next; + + for ( ep = ent->epairs ; ep ; ep = next ) + { + next = ep->next; + FreeMemory( ep->value ); + FreeMemory( ep->key ); + FreeMemory( ep ); + } + ent->epairs = NULL; +} +#endif + +/* +============= +Sin_PrintBSPFileSizes + +Dumps info about current file +============= +*/ +void Sin_PrintBSPFileSizes( void ) { + if ( !num_entities ) { + Sin_ParseEntities(); + } + + Log_Print( "%6i models %7i\n" + ,sin_nummodels, (int)( sin_nummodels * sizeof( sin_dmodel_t ) ) ); + Log_Print( "%6i brushes %7i\n" + ,sin_numbrushes, (int)( sin_numbrushes * sizeof( sin_dbrush_t ) ) ); + Log_Print( "%6i brushsides %7i\n" + ,sin_numbrushsides, (int)( sin_numbrushsides * sizeof( sin_dbrushside_t ) ) ); + Log_Print( "%6i planes %7i\n" + ,sin_numplanes, (int)( sin_numplanes * sizeof( sin_dplane_t ) ) ); + Log_Print( "%6i texinfo %7i\n" + ,sin_numtexinfo, (int)( sin_numtexinfo * sizeof( sin_texinfo_t ) ) ); +#ifdef SIN + Log_Print( "%6i lightinfo %7i\n" + ,sin_numlightinfo, (int)( sin_numlightinfo * sizeof( sin_lightvalue_t ) ) ); +#endif + Log_Print( "%6i entdata %7i\n", num_entities, sin_entdatasize ); + + Log_Print( "\n" ); + + Log_Print( "%6i vertexes %7i\n" + ,sin_numvertexes, (int)( sin_numvertexes * sizeof( sin_dvertex_t ) ) ); + Log_Print( "%6i nodes %7i\n" + ,sin_numnodes, (int)( sin_numnodes * sizeof( sin_dnode_t ) ) ); + Log_Print( "%6i faces %7i\n" + ,sin_numfaces, (int)( sin_numfaces * sizeof( sin_dface_t ) ) ); + Log_Print( "%6i leafs %7i\n" + ,sin_numleafs, (int)( sin_numleafs * sizeof( sin_dleaf_t ) ) ); + Log_Print( "%6i leaffaces %7i\n" + ,sin_numleaffaces, (int)( sin_numleaffaces * sizeof( sin_dleaffaces[0] ) ) ); + Log_Print( "%6i leafbrushes %7i\n" + ,sin_numleafbrushes, (int)( sin_numleafbrushes * sizeof( sin_dleafbrushes[0] ) ) ); + Log_Print( "%6i surfedges %7i\n" + ,sin_numsurfedges, (int)( sin_numsurfedges * sizeof( sin_dsurfedges[0] ) ) ); + Log_Print( "%6i edges %7i\n" + ,sin_numedges, (int)( sin_numedges * sizeof( sin_dedge_t ) ) ); + Log_Print( " lightdata %7i\n", sin_lightdatasize ); + Log_Print( " visdata %7i\n", sin_visdatasize ); +} diff --git a/Projects/Android/jni/rtcw/src/bspc/l_bsp_sin.h b/Projects/Android/jni/rtcw/src/bspc/l_bsp_sin.h new file mode 100644 index 0000000..2ba1843 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/bspc/l_bsp_sin.h @@ -0,0 +1,113 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +#include "sinfiles.h" + +#define SINGAME_BSPHEADER ( ( 'P' << 24 ) + ( 'S' << 16 ) + ( 'B' << 8 ) + 'R' ) //RBSP +#define SINGAME_BSPVERSION 1 + +#define SIN_BSPHEADER ( ( 'P' << 24 ) + ( 'S' << 16 ) + ( 'B' << 8 ) + 'I' ) //IBSP +#define SIN_BSPVERSION 41 + + +extern int sin_nummodels; +extern sin_dmodel_t *sin_dmodels; //[MAX_MAP_MODELS]; + +extern int sin_visdatasize; +extern byte *sin_dvisdata; //[MAX_MAP_VISIBILITY]; +extern sin_dvis_t *sin_dvis; // = (dvis_t *)sin_sin_dvisdata; + +extern int sin_lightdatasize; +extern byte *sin_dlightdata; //[MAX_MAP_LIGHTING]; + +extern int sin_entdatasize; +extern char *sin_dentdata; //[MAX_MAP_ENTSTRING]; + +extern int sin_numleafs; +extern sin_dleaf_t *sin_dleafs; //[MAX_MAP_LEAFS]; + +extern int sin_numplanes; +extern sin_dplane_t *sin_dplanes; //[MAX_MAP_PLANES]; + +extern int sin_numvertexes; +extern sin_dvertex_t *sin_dvertexes; //[MAX_MAP_VERTS]; + +extern int sin_numnodes; +extern sin_dnode_t *sin_dnodes; //[MAX_MAP_NODES]; + +extern int sin_numtexinfo; +extern sin_texinfo_t *sin_texinfo; //[MAX_MAP_sin_texinfo]; + +extern int sin_numfaces; +extern sin_dface_t *sin_dfaces; //[MAX_MAP_FACES]; + +extern int sin_numedges; +extern sin_dedge_t *sin_dedges; //[MAX_MAP_EDGES]; + +extern int sin_numleaffaces; +extern unsigned short *sin_dleaffaces; //[MAX_MAP_LEAFFACES]; + +extern int sin_numleafbrushes; +extern unsigned short *sin_dleafbrushes; //[MAX_MAP_LEAFBRUSHES]; + +extern int sin_numsurfedges; +extern int *sin_dsurfedges; //[MAX_MAP_SURFEDGES]; + +extern int sin_numbrushes; +extern sin_dbrush_t *sin_dbrushes; //[MAX_MAP_BRUSHES]; + +extern int sin_numbrushsides; +extern sin_dbrushside_t *sin_dbrushsides; //[MAX_MAP_BRUSHSIDES]; + +extern int sin_numareas; +extern sin_darea_t *sin_dareas; //[MAX_MAP_AREAS]; + +extern int sin_numareaportals; +extern sin_dareaportal_t *sin_dareaportals; //[MAX_MAP_AREAPORTALS]; + +extern int sin_numlightinfo; +extern sin_lightvalue_t *sin_lightinfo; //[MAX_MAP_LIGHTINFO]; + +extern byte sin_dpop[256]; + +extern char sin_dbrushsidetextured[SIN_MAX_MAP_BRUSHSIDES]; + +void Sin_AllocMaxBSP( void ); +void Sin_FreeMaxBSP( void ); + +void Sin_DecompressVis( byte *in, byte *decompressed ); +int Sin_CompressVis( byte *vis, byte *dest ); + +void Sin_LoadBSPFile( char *filename, int offset, int length ); +void Sin_LoadBSPFileTexinfo( char *filename ); // just for qdata +void Sin_WriteBSPFile( char *filename ); +void Sin_PrintBSPFileSizes( void ); +void Sin_ParseEntities( void ); +void Sin_UnparseEntities( void ); + diff --git a/Projects/Android/jni/rtcw/src/bspc/l_cmd.c b/Projects/Android/jni/rtcw/src/bspc/l_cmd.c new file mode 100644 index 0000000..6ca23f1 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/bspc/l_cmd.c @@ -0,0 +1,1181 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +// cmdlib.c + +#include "l_cmd.h" +#include "l_log.h" +#include "l_mem.h" +#include +#include + +#ifndef SIN +#define SIN +#endif //SIN + +#if defined( WIN32 ) || defined( _WIN32 ) +#include +#else +#include +#endif + +#ifdef NeXT +#include +#endif + +#define BASEDIRNAME "wolf" +#define PATHSEPERATOR '/' + +// set these before calling CheckParm +int myargc; +char **myargv; + +char com_token[1024]; +qboolean com_eof; + +qboolean archive; +char archivedir[1024]; + + +/* +=================== +ExpandWildcards + +Mimic unix command line expansion +=================== +*/ +#define MAX_EX_ARGC 1024 +int ex_argc; +char *ex_argv[MAX_EX_ARGC]; +#ifdef _WIN32 +#include "io.h" +void ExpandWildcards( int *argc, char ***argv ) { + struct _finddata_t fileinfo; + int handle; + int i; + char filename[1024]; + char filebase[1024]; + char *path; + + ex_argc = 0; + for ( i = 0 ; i < *argc ; i++ ) + { + path = ( *argv )[i]; + if ( path[0] == '-' + || ( !strstr( path, "*" ) && !strstr( path, "?" ) ) ) { + ex_argv[ex_argc++] = path; + continue; + } + + handle = _findfirst( path, &fileinfo ); + if ( handle == -1 ) { + return; + } + + ExtractFilePath( path, filebase ); + + do + { + sprintf( filename, "%s%s", filebase, fileinfo.name ); + ex_argv[ex_argc++] = copystring( filename ); + } while ( _findnext( handle, &fileinfo ) != -1 ); + + _findclose( handle ); + } + + *argc = ex_argc; + *argv = ex_argv; +} +#else +void ExpandWildcards( int *argc, char ***argv ) { +} +#endif + +#ifdef WINBSPC + +#include + +HWND program_hwnd; + +void SetProgramHandle( HWND hwnd ) { + program_hwnd = hwnd; +} //end of the function SetProgramHandle + +/* +================= +Error + +For abnormal program terminations in windowed apps +================= +*/ +void Error( char *error, ... ) { + va_list argptr; + char text[1024]; + char text2[1024]; + int err; + + err = GetLastError(); + + va_start( argptr, error ); + vsprintf( text, error, argptr ); + va_end( argptr ); + + sprintf( text2, "%s\nGetLastError() = %i", text, err ); + MessageBox( program_hwnd, text2, "Error", 0 /* MB_OK */ ); + + Log_Write( text ); + Log_Close(); + + exit( 1 ); +} //end of the function Error + +void Warning( char *szFormat, ... ) { + char szBuffer[256]; + va_list argptr; + + va_start( argptr, szFormat ); + vsprintf( szBuffer, szFormat, argptr ); + va_end( argptr ); + + MessageBox( program_hwnd, szBuffer, "Warning", MB_OK ); + + Log_Write( szBuffer ); +} //end of the function Warning + + +#else +/* +================= +Error + +For abnormal program terminations in console apps +================= +*/ +void Error( char *error, ... ) { + va_list argptr; + char text[1024]; + + va_start( argptr, error ); + vsprintf( text, error, argptr ); + va_end( argptr ); + printf( "ERROR: %s\n", text ); + + Log_Write( text ); + Log_Close(); + + exit( 1 ); +} //end of the function Error + +void Warning( char *warning, ... ) { + va_list argptr; + char text[1024]; + + va_start( argptr, warning ); + vsprintf( text, warning, argptr ); + va_end( argptr ); + printf( "WARNING: %s\n", text ); + + Log_Write( text ); +} //end of the function Warning + +#endif + +//only printf if in verbose mode +qboolean verbose = true; + +void qprintf( char *format, ... ) { + va_list argptr; +#ifdef WINBSPC + char buf[2048]; +#endif //WINBSPC + + if ( !verbose ) { + return; + } + + va_start( argptr,format ); +#ifdef WINBSPC + vsprintf( buf, format, argptr ); + WinBSPCPrint( buf ); +#else + vprintf( format, argptr ); +#endif //WINBSPC + va_end( argptr ); +} //end of the function qprintf + +void Com_Error( int level, char *error, ... ) { + va_list argptr; + char text[1024]; + + va_start( argptr, error ); + vsprintf( text, error, argptr ); + va_end( argptr ); + Error( text ); +} //end of the funcion Com_Error + +void Com_Printf( const char *fmt, ... ) { + va_list argptr; + char text[1024]; + + va_start( argptr, fmt ); + vsprintf( text, fmt, argptr ); + va_end( argptr ); + Log_Print( text ); +} //end of the funcion Com_Printf + +/* + +qdir will hold the path up to the quake directory, including the slash + + f:\quake \ + /raid/quake/ + +gamedir will hold qdir + the game directory (id1, id2, etc) + + */ + +char qdir[1024]; +char gamedir[1024]; + +void SetQdirFromPath( char *path ) { + char temp[1024]; + char *c; + int len; + + if ( !( path[0] == '/' || path[0] == '\\' || path[1] == ':' ) ) { // path is partial + Q_getwd( temp ); + strcat( temp, path ); + path = temp; + } + + // search for "quake2" in path + + len = strlen( BASEDIRNAME ); + for ( c = path + strlen( path ) - 1 ; c != path ; c-- ) + if ( !Q_strncasecmp( c, BASEDIRNAME, len ) ) { + strncpy( qdir, path, c + len + 1 - path ); + qprintf( "qdir: %s\n", qdir ); + c += len + 1; + while ( *c ) + { + if ( *c == '/' || *c == '\\' ) { + strncpy( gamedir, path, c + 1 - path ); + qprintf( "gamedir: %s\n", gamedir ); + return; + } + c++; + } + Error( "No gamedir in %s", path ); + return; + } + Error( "SetQdirFromPath: no '%s' in %s", BASEDIRNAME, path ); +} + +char *ExpandArg( char *path ) { + static char full[1024]; + + if ( path[0] != '/' && path[0] != '\\' && path[1] != ':' ) { + Q_getwd( full ); + strcat( full, path ); + } else { + strcpy( full, path ); + } + return full; +} + +char *ExpandPath( char *path ) { + static char full[1024]; + if ( !qdir ) { + Error( "ExpandPath called without qdir set" ); + } + if ( path[0] == '/' || path[0] == '\\' || path[1] == ':' ) { + return path; + } + sprintf( full, "%s%s", qdir, path ); + return full; +} + +char *ExpandPathAndArchive( char *path ) { + char *expanded; + char archivename[1024]; + + expanded = ExpandPath( path ); + + if ( archive ) { + sprintf( archivename, "%s/%s", archivedir, path ); + QCopyFile( expanded, archivename ); + } + return expanded; +} + + +char *copystring( char *s ) { + char *b; + b = GetMemory( strlen( s ) + 1 ); + strcpy( b, s ); + return b; +} + + + +/* +================ +I_FloatTime +================ +*/ +double I_FloatTime( void ) { + time_t t; + + time( &t ); + + return t; +#if 0 +// more precise, less portable + struct timeval tp; + struct timezone tzp; + static int secbase; + + gettimeofday( &tp, &tzp ); + + if ( !secbase ) { + secbase = tp.tv_sec; + return tp.tv_usec / 1000000.0; + } + + return ( tp.tv_sec - secbase ) + tp.tv_usec / 1000000.0; +#endif +} + +void Q_getwd( char *out ) { +#if defined( WIN32 ) || defined( _WIN32 ) + getcwd( out, 256 ); + strcat( out, "\\" ); +#else + getwd( out ); + strcat( out, "/" ); +#endif +} + + +void Q_mkdir( char *path ) { +#ifdef WIN32 + if ( _mkdir( path ) != -1 ) { + return; + } +#else + if ( mkdir( path, 0777 ) != -1 ) { + return; + } +#endif + if ( errno != EEXIST ) { + Error( "mkdir %s: %s",path, strerror( errno ) ); + } +} + +/* +============ +FileTime + +returns -1 if not present +============ +*/ +int FileTime( char *path ) { + struct stat buf; + + if ( stat( path,&buf ) == -1 ) { + return -1; + } + + return buf.st_mtime; +} + + + +/* +============== +COM_Parse + +Parse a token out of a string +============== +*/ +char *COM_Parse( char *data ) { + int c; + int len; + + len = 0; + com_token[0] = 0; + + if ( !data ) { + return NULL; + } + +// skip whitespace +skipwhite: + while ( ( c = *data ) <= ' ' ) + { + if ( c == 0 ) { + com_eof = true; + return NULL; // end of file; + } + data++; + } + +// skip // comments + if ( c == '/' && data[1] == '/' ) { + while ( *data && *data != '\n' ) + data++; + goto skipwhite; + } + + +// handle quoted strings specially + if ( c == '\"' ) { + data++; + do + { + c = *data++; + if ( c == '\"' ) { + com_token[len] = 0; + return data; + } + com_token[len] = c; + len++; + } while ( 1 ); + } + +// parse single characters + if ( c == '{' || c == '}' || c == ')' || c == '(' || c == '\'' || c == ':' ) { + com_token[len] = c; + len++; + com_token[len] = 0; + return data + 1; + } + +// parse a regular word + do + { + com_token[len] = c; + data++; + len++; + c = *data; + if ( c == '{' || c == '}' || c == ')' || c == '(' || c == '\'' || c == ':' ) { + break; + } + } while ( c > 32 ); + + com_token[len] = 0; + return data; +} + + +int Q_strncasecmp( char *s1, char *s2, int n ) { + int c1, c2; + + do + { + c1 = *s1++; + c2 = *s2++; + + if ( !n-- ) { + return 0; // strings are equal until end point + + } + if ( c1 != c2 ) { + if ( c1 >= 'a' && c1 <= 'z' ) { + c1 -= ( 'a' - 'A' ); + } + if ( c2 >= 'a' && c2 <= 'z' ) { + c2 -= ( 'a' - 'A' ); + } + if ( c1 != c2 ) { + return -1; // strings not equal + } + } + } while ( c1 ); + + return 0; // strings are equal +} + +int Q_strcasecmp( char *s1, char *s2 ) { + return Q_strncasecmp( s1, s2, 99999 ); +} + +int Q_stricmp( char *s1, char *s2 ) { + return Q_strncasecmp( s1, s2, 99999 ); +} + +void Q_strncpyz( char *dest, const char *src, int destsize ) { + strncpy( dest, src, destsize - 1 ); + dest[destsize - 1] = 0; +} + +char *strupr( char *start ) { + char *in; + in = start; + while ( *in ) + { + *in = toupper( *in ); + in++; + } + return start; +} + +char *strlower( char *start ) { + char *in; + in = start; + while ( *in ) + { + *in = tolower( *in ); + in++; + } + return start; +} + + +/* +============================================================================= + + MISC FUNCTIONS + +============================================================================= +*/ + + +/* +================= +CheckParm + +Checks for the given parameter in the program's command line arguments +Returns the argument number (1 to argc-1) or 0 if not present +================= +*/ +int CheckParm( char *check ) { + int i; + + for ( i = 1; i < myargc; i++ ) + { + if ( !Q_strcasecmp( check, myargv[i] ) ) { + return i; + } + } + + return 0; +} + + + +/* +================ +Q_filelength +================ +*/ +int Q_filelength( FILE *f ) { + int pos; + int end; + + pos = ftell( f ); + fseek( f, 0, SEEK_END ); + end = ftell( f ); + fseek( f, pos, SEEK_SET ); + + return end; +} + + +FILE *SafeOpenWrite( char *filename ) { + FILE *f; + + f = fopen( filename, "wb" ); + + if ( !f ) { + Error( "Error opening %s: %s",filename,strerror( errno ) ); + } + + return f; +} + +FILE *SafeOpenRead( char *filename ) { + FILE *f; + + f = fopen( filename, "rb" ); + + if ( !f ) { + Error( "Error opening %s: %s",filename,strerror( errno ) ); + } + + return f; +} + + +void SafeRead( FILE *f, void *buffer, int count ) { + if ( fread( buffer, 1, count, f ) != (size_t)count ) { + Error( "File read failure" ); + } +} + + +void SafeWrite( FILE *f, void *buffer, int count ) { + if ( fwrite( buffer, 1, count, f ) != (size_t)count ) { + Error( "File write failure" ); + } +} + + +/* +============== +FileExists +============== +*/ +qboolean FileExists( char *filename ) { + FILE *f; + + f = fopen( filename, "r" ); + if ( !f ) { + return false; + } + fclose( f ); + return true; +} + +/* +============== +LoadFile +============== +*/ +int LoadFile( char *filename, void **bufferptr, int offset, int length ) { + FILE *f; + void *buffer; + + f = SafeOpenRead( filename ); + fseek( f, offset, SEEK_SET ); + if ( !length ) { + length = Q_filelength( f ); + } + buffer = GetMemory( length + 1 ); + ( (char *)buffer )[length] = 0; + SafeRead( f, buffer, length ); + fclose( f ); + + *bufferptr = buffer; + return length; +} + + +/* +============== +TryLoadFile + +Allows failure +============== +*/ +int TryLoadFile( char *filename, void **bufferptr ) { + FILE *f; + int length; + void *buffer; + + *bufferptr = NULL; + + f = fopen( filename, "rb" ); + if ( !f ) { + return -1; + } + length = Q_filelength( f ); + buffer = GetMemory( length + 1 ); + ( (char *)buffer )[length] = 0; + SafeRead( f, buffer, length ); + fclose( f ); + + *bufferptr = buffer; + return length; +} + + +/* +============== +SaveFile +============== +*/ +void SaveFile( char *filename, void *buffer, int count ) { + FILE *f; + + f = SafeOpenWrite( filename ); + SafeWrite( f, buffer, count ); + fclose( f ); +} + + + +void DefaultExtension( char *path, char *extension ) { + char *src; +// +// if path doesnt have a .EXT, append extension +// (extension should include the .) +// + src = path + strlen( path ) - 1; + + while ( *src != PATHSEPERATOR && src != path ) + { + if ( *src == '.' ) { + return; // it has an extension + } + src--; + } + + strcat( path, extension ); +} + + +void DefaultPath( char *path, char *basepath ) { + char temp[128]; + + if ( path[0] == PATHSEPERATOR ) { + return; // absolute path location + } + strcpy( temp,path ); + strcpy( path,basepath ); + strcat( path,temp ); +} + + +void StripFilename( char *path ) { + int length; + + length = strlen( path ) - 1; + while ( length > 0 && path[length] != PATHSEPERATOR ) + length--; + path[length] = 0; +} + +void StripExtension( char *path ) { + int length; + + length = strlen( path ) - 1; + while ( length > 0 && path[length] != '.' ) + { + length--; + if ( path[length] == '/' ) { + return; // no extension + } + } + if ( length ) { + path[length] = 0; + } +} + + +/* +==================== +Extract file parts +==================== +*/ +// FIXME: should include the slash, otherwise +// backing to an empty path will be wrong when appending a slash +void ExtractFilePath( char *path, char *dest ) { + char *src; + + src = path + strlen( path ) - 1; + +// +// back up until a \ or the start +// + while ( src != path && *( src - 1 ) != '\\' && *( src - 1 ) != '/' ) + src--; + + memcpy( dest, path, src - path ); + dest[src - path] = 0; +} + +void ExtractFileBase( char *path, char *dest ) { + char *src; + + src = path + strlen( path ) - 1; + +// +// back up until a \ or the start +// + while ( src != path && *( src - 1 ) != '\\' && *( src - 1 ) != '/' ) + src--; + + while ( *src && *src != '.' ) + { + *dest++ = *src++; + } + *dest = 0; +} + +void ExtractFileExtension( char *path, char *dest ) { + char *src; + + src = path + strlen( path ) - 1; + +// +// back up until a . or the start +// + while ( src != path && *( src - 1 ) != '.' ) + src--; + if ( src == path ) { + *dest = 0; // no extension + return; + } + + strcpy( dest,src ); +} + + +/* +============== +ParseNum / ParseHex +============== +*/ +int ParseHex( char *hex ) { + char *str; + int num; + + num = 0; + str = hex; + + while ( *str ) + { + num <<= 4; + if ( *str >= '0' && *str <= '9' ) { + num += *str - '0'; + } else if ( *str >= 'a' && *str <= 'f' ) { + num += 10 + *str - 'a'; + } else if ( *str >= 'A' && *str <= 'F' ) { + num += 10 + *str - 'A'; + } else { + Error( "Bad hex number: %s",hex ); + } + str++; + } + + return num; +} + + +int ParseNum( char *str ) { + if ( str[0] == '$' ) { + return ParseHex( str + 1 ); + } + if ( str[0] == '0' && str[1] == 'x' ) { + return ParseHex( str + 2 ); + } + return atol( str ); +} + + + +/* +============================================================================ + + BYTE ORDER FUNCTIONS + +============================================================================ +*/ + +#ifdef _SGI_SOURCE +#define __BIG_ENDIAN__ +#endif + +#ifdef __BIG_ENDIAN__ + +short LittleShort( short l ) { + byte b1,b2; + + b1 = l & 255; + b2 = ( l >> 8 ) & 255; + + return ( b1 << 8 ) + b2; +} + +short BigShort( short l ) { + return l; +} + + +int LittleLong( int l ) { + byte b1,b2,b3,b4; + + b1 = l & 255; + b2 = ( l >> 8 ) & 255; + b3 = ( l >> 16 ) & 255; + b4 = ( l >> 24 ) & 255; + + return ( (int)b1 << 24 ) + ( (int)b2 << 16 ) + ( (int)b3 << 8 ) + b4; +} + +int BigLong( int l ) { + return l; +} + + +float LittleFloat( float l ) { + union {byte b[4]; float f;} in, out; + + in.f = l; + out.b[0] = in.b[3]; + out.b[1] = in.b[2]; + out.b[2] = in.b[1]; + out.b[3] = in.b[0]; + + return out.f; +} + +float BigFloat( float l ) { + return l; +} + +#ifdef SIN +unsigned short LittleUnsignedShort( unsigned short l ) { + byte b1,b2; + + b1 = l & 255; + b2 = ( l >> 8 ) & 255; + + return ( b1 << 8 ) + b2; +} + +unsigned short BigUnsignedShort( unsigned short l ) { + return l; +} + +unsigned LittleUnsigned( unsigned l ) { + byte b1,b2,b3,b4; + + b1 = l & 255; + b2 = ( l >> 8 ) & 255; + b3 = ( l >> 16 ) & 255; + b4 = ( l >> 24 ) & 255; + + return ( (unsigned)b1 << 24 ) + ( (unsigned)b2 << 16 ) + ( (unsigned)b3 << 8 ) + b4; +} + +unsigned BigUnsigned( unsigned l ) { + return l; +} +#endif + + +#else + + +short BigShort( short l ) { + byte b1,b2; + + b1 = l & 255; + b2 = ( l >> 8 ) & 255; + + return ( b1 << 8 ) + b2; +} + +short LittleShort( short l ) { + return l; +} + + +int BigLong( int l ) { + byte b1,b2,b3,b4; + + b1 = l & 255; + b2 = ( l >> 8 ) & 255; + b3 = ( l >> 16 ) & 255; + b4 = ( l >> 24 ) & 255; + + return ( (int)b1 << 24 ) + ( (int)b2 << 16 ) + ( (int)b3 << 8 ) + b4; +} + +int LittleLong( int l ) { + return l; +} + +float BigFloat( float l ) { + union {byte b[4]; float f;} in, out; + + in.f = l; + out.b[0] = in.b[3]; + out.b[1] = in.b[2]; + out.b[2] = in.b[1]; + out.b[3] = in.b[0]; + + return out.f; +} + +float LittleFloat( float l ) { + return l; +} + +#ifdef SIN +unsigned short BigUnsignedShort( unsigned short l ) { + byte b1,b2; + + b1 = l & 255; + b2 = ( l >> 8 ) & 255; + + return ( b1 << 8 ) + b2; +} + +unsigned short LittleUnsignedShort( unsigned short l ) { + return l; +} + + +unsigned BigUnsigned( unsigned l ) { + byte b1,b2,b3,b4; + + b1 = l & 255; + b2 = ( l >> 8 ) & 255; + b3 = ( l >> 16 ) & 255; + b4 = ( l >> 24 ) & 255; + + return ( (unsigned)b1 << 24 ) + ( (unsigned)b2 << 16 ) + ( (unsigned)b3 << 8 ) + b4; +} + +unsigned LittleUnsigned( unsigned l ) { + return l; +} +#endif + + +#endif + + +//======================================================= + + +// FIXME: byte swap? + +// this is a 16 bit, non-reflected CRC using the polynomial 0x1021 +// and the initial and final xor values shown below... in other words, the +// CCITT standard CRC used by XMODEM + +#define CRC_INIT_VALUE 0xffff +#define CRC_XOR_VALUE 0x0000 + +static unsigned short crctable[256] = +{ + 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7, + 0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef, + 0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6, + 0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de, + 0x2462, 0x3443, 0x0420, 0x1401, 0x64e6, 0x74c7, 0x44a4, 0x5485, + 0xa56a, 0xb54b, 0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d, + 0x3653, 0x2672, 0x1611, 0x0630, 0x76d7, 0x66f6, 0x5695, 0x46b4, + 0xb75b, 0xa77a, 0x9719, 0x8738, 0xf7df, 0xe7fe, 0xd79d, 0xc7bc, + 0x48c4, 0x58e5, 0x6886, 0x78a7, 0x0840, 0x1861, 0x2802, 0x3823, + 0xc9cc, 0xd9ed, 0xe98e, 0xf9af, 0x8948, 0x9969, 0xa90a, 0xb92b, + 0x5af5, 0x4ad4, 0x7ab7, 0x6a96, 0x1a71, 0x0a50, 0x3a33, 0x2a12, + 0xdbfd, 0xcbdc, 0xfbbf, 0xeb9e, 0x9b79, 0x8b58, 0xbb3b, 0xab1a, + 0x6ca6, 0x7c87, 0x4ce4, 0x5cc5, 0x2c22, 0x3c03, 0x0c60, 0x1c41, + 0xedae, 0xfd8f, 0xcdec, 0xddcd, 0xad2a, 0xbd0b, 0x8d68, 0x9d49, + 0x7e97, 0x6eb6, 0x5ed5, 0x4ef4, 0x3e13, 0x2e32, 0x1e51, 0x0e70, + 0xff9f, 0xefbe, 0xdfdd, 0xcffc, 0xbf1b, 0xaf3a, 0x9f59, 0x8f78, + 0x9188, 0x81a9, 0xb1ca, 0xa1eb, 0xd10c, 0xc12d, 0xf14e, 0xe16f, + 0x1080, 0x00a1, 0x30c2, 0x20e3, 0x5004, 0x4025, 0x7046, 0x6067, + 0x83b9, 0x9398, 0xa3fb, 0xb3da, 0xc33d, 0xd31c, 0xe37f, 0xf35e, + 0x02b1, 0x1290, 0x22f3, 0x32d2, 0x4235, 0x5214, 0x6277, 0x7256, + 0xb5ea, 0xa5cb, 0x95a8, 0x8589, 0xf56e, 0xe54f, 0xd52c, 0xc50d, + 0x34e2, 0x24c3, 0x14a0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405, + 0xa7db, 0xb7fa, 0x8799, 0x97b8, 0xe75f, 0xf77e, 0xc71d, 0xd73c, + 0x26d3, 0x36f2, 0x0691, 0x16b0, 0x6657, 0x7676, 0x4615, 0x5634, + 0xd94c, 0xc96d, 0xf90e, 0xe92f, 0x99c8, 0x89e9, 0xb98a, 0xa9ab, + 0x5844, 0x4865, 0x7806, 0x6827, 0x18c0, 0x08e1, 0x3882, 0x28a3, + 0xcb7d, 0xdb5c, 0xeb3f, 0xfb1e, 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a, + 0x4a75, 0x5a54, 0x6a37, 0x7a16, 0x0af1, 0x1ad0, 0x2ab3, 0x3a92, + 0xfd2e, 0xed0f, 0xdd6c, 0xcd4d, 0xbdaa, 0xad8b, 0x9de8, 0x8dc9, + 0x7c26, 0x6c07, 0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0x0cc1, + 0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8, + 0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0 +}; + +void CRC_Init( unsigned short *crcvalue ) { + *crcvalue = CRC_INIT_VALUE; +} + +void CRC_ProcessByte( unsigned short *crcvalue, byte data ) { + *crcvalue = ( *crcvalue << 8 ) ^ crctable[( *crcvalue >> 8 ) ^ data]; +} + +unsigned short CRC_Value( unsigned short crcvalue ) { + return crcvalue ^ CRC_XOR_VALUE; +} +//============================================================================= + +/* +============ +CreatePath +============ +*/ +void CreatePath( char *path ) { + char *ofs, c; + + if ( path[1] == ':' ) { + path += 2; + } + + for ( ofs = path + 1 ; *ofs ; ofs++ ) + { + c = *ofs; + if ( c == '/' || c == '\\' ) { // create the directory + *ofs = 0; + Q_mkdir( path ); + *ofs = c; + } + } +} + + +/* +============ +QCopyFile + + Used to archive source files +============ +*/ +void QCopyFile( char *from, char *to ) { + void *buffer; + int length; + + length = LoadFile( from, &buffer, 0, 0 ); + CreatePath( to ); + SaveFile( to, buffer, length ); + FreeMemory( buffer ); +} + +void FS_FreeFile( void *buf ) { + FreeMemory( buf ); +} //end of the function FS_FreeFile + +int FS_ReadFileAndCache( const char *qpath, void **buffer ) { + return LoadFile( (char *) qpath, buffer, 0, 0 ); +} //end of the function FS_ReadFileAndCache + +int FS_FOpenFileRead( const char *filename, FILE **file, qboolean uniqueFILE ) { + *file = fopen( filename, "rb" ); + return ( *file != NULL ); +} //end of the function FS_FOpenFileRead diff --git a/Projects/Android/jni/rtcw/src/bspc/l_cmd.h b/Projects/Android/jni/rtcw/src/bspc/l_cmd.h new file mode 100644 index 0000000..6d0e1fe --- /dev/null +++ b/Projects/Android/jni/rtcw/src/bspc/l_cmd.h @@ -0,0 +1,164 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +// cmdlib.h + +#ifndef SIN +#define SIN +#endif //SIN + +#ifndef __CMDLIB__ +#define __CMDLIB__ + +#ifdef _WIN32 +#pragma warning(disable : 4244) // MIPS +#pragma warning(disable : 4136) // X86 +#pragma warning(disable : 4051) // ALPHA + +#pragma warning(disable : 4018) // signed/unsigned mismatch +#pragma warning(disable : 4305) // truncate from double to float +#endif + +#include +#include +#include +#include +#include +#include +#include + +#ifndef __BYTEBOOL__ +#define __BYTEBOOL__ +typedef enum {false, true} qboolean; +typedef unsigned char byte; +#endif + +// the dec offsetof macro doesnt work very well... +#define myoffsetof( type,identifier ) ( (size_t)&( (type *)0 )->identifier ) + + +// set these before calling CheckParm +extern int myargc; +extern char **myargv; + +char *strupr( char *in ); +char *strlower( char *in ); +int Q_strncasecmp( char *s1, char *s2, int n ); +int Q_strcasecmp( char *s1, char *s2 ); +void Q_getwd( char *out ); + +int Q_filelength( FILE *f ); +int FileTime( char *path ); + +void Q_mkdir( char *path ); + +extern char qdir[1024]; +extern char gamedir[1024]; +void SetQdirFromPath( char *path ); +char *ExpandArg( char *path ); // from cmd line +char *ExpandPath( char *path ); // from scripts +char *ExpandPathAndArchive( char *path ); + + +double I_FloatTime( void ); + +void Error( char *error, ... ); +void Warning( char *warning, ... ); + +int CheckParm( char *check ); + +FILE *SafeOpenWrite( char *filename ); +FILE *SafeOpenRead( char *filename ); +void SafeRead( FILE *f, void *buffer, int count ); +void SafeWrite( FILE *f, void *buffer, int count ); + +int LoadFile( char *filename, void **bufferptr, int offset, int length ); +int TryLoadFile( char *filename, void **bufferptr ); +void SaveFile( char *filename, void *buffer, int count ); +qboolean FileExists( char *filename ); + +void DefaultExtension( char *path, char *extension ); +void DefaultPath( char *path, char *basepath ); +void StripFilename( char *path ); +void StripExtension( char *path ); + +void ExtractFilePath( char *path, char *dest ); +void ExtractFileBase( char *path, char *dest ); +void ExtractFileExtension( char *path, char *dest ); + +int ParseNum( char *str ); + +short BigShort( short l ); +short LittleShort( short l ); +int BigLong( int l ); +int LittleLong( int l ); +float BigFloat( float l ); +float LittleFloat( float l ); + +#ifdef SIN +unsigned short BigUnsignedShort( unsigned short l ); +unsigned short LittleUnsignedShort( unsigned short l ); +unsigned BigUnsigned( unsigned l ); +unsigned LittleUnsigned( unsigned l ); +#endif + + +char *COM_Parse( char *data ); + +extern char com_token[1024]; +extern qboolean com_eof; + +char *copystring( char *s ); + + +void CRC_Init( unsigned short *crcvalue ); +void CRC_ProcessByte( unsigned short *crcvalue, byte data ); +unsigned short CRC_Value( unsigned short crcvalue ); + +void CreatePath( char *path ); +void QCopyFile( char *from, char *to ); + +extern qboolean archive; +extern char archivedir[1024]; + + +extern qboolean verbose; +void qprintf( char *format, ... ); + +void ExpandWildcards( int *argc, char ***argv ); + + +// for compression routines +typedef struct +{ + byte *data; + int count; +} cblock_t; + +#endif + diff --git a/Projects/Android/jni/rtcw/src/bspc/l_log.c b/Projects/Android/jni/rtcw/src/bspc/l_log.c new file mode 100644 index 0000000..49ac74b --- /dev/null +++ b/Projects/Android/jni/rtcw/src/bspc/l_log.c @@ -0,0 +1,220 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +//=========================================================================== +// +// Name: l_log.c +// Function: log file stuff +// Programmer: Mr Elusive (MrElusive@demigod.demon.nl) +// Last update: 1997-12-31 +// Tab Size: 3 +//=========================================================================== + +#include +#include +#include + +#include "qbsp.h" + +#define MAX_LOGFILENAMESIZE 1024 + +typedef struct logfile_s +{ + char filename[MAX_LOGFILENAMESIZE]; + FILE *fp; + int numwrites; +} logfile_t; + +logfile_t logfile; + +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void Log_Open( char *filename ) { + if ( !filename || !strlen( filename ) ) { + printf( "openlog \n" ); + return; + } //end if + if ( logfile.fp ) { + printf( "log file %s is already opened\n", logfile.filename ); + return; + } //end if + logfile.fp = fopen( filename, "wb" ); + if ( !logfile.fp ) { + printf( "can't open the log file %s\n", filename ); + return; + } //end if + strncpy( logfile.filename, filename, MAX_LOGFILENAMESIZE ); + printf( "Opened log %s\n", logfile.filename ); +} //end of the function Log_Create +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void Log_Close( void ) { + if ( !logfile.fp ) { + printf( "no log file to close\n" ); + return; + } //end if + if ( fclose( logfile.fp ) ) { + printf( "can't close log file %s\n", logfile.filename ); + return; + } //end if + logfile.fp = NULL; + printf( "Closed log %s\n", logfile.filename ); +} //end of the function Log_Close +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void Log_Shutdown( void ) { + if ( logfile.fp ) { + Log_Close(); + } +} //end of the function Log_Shutdown +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void Log_UnifyEndOfLine( char *buf ) { + int i; + + for ( i = 0; buf[i]; i++ ) + { + if ( buf[i] == '\n' ) { + if ( i <= 0 || buf[i - 1] != '\r' ) { + memmove( &buf[i + 1], &buf[i], strlen( &buf[i] ) + 1 ); + buf[i] = '\r'; + i++; + } //end if + } //end if + } //end for +} //end of the function Log_UnifyEndOfLine +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void Log_Print( char *fmt, ... ) { + va_list ap; + char buf[2048]; + + va_start( ap, fmt ); + vsprintf( buf, fmt, ap ); + va_end( ap ); + + if ( verbose ) { +#ifdef WINBSPC + WinBSPCPrint( buf ); +#else + printf( "%s", buf ); +#endif //WINBSPS + } //end if + + if ( logfile.fp ) { + Log_UnifyEndOfLine( buf ); + fprintf( logfile.fp, "%s", buf ); + fflush( logfile.fp ); + } //end if +} //end of the function Log_Print +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void Log_Write( char *fmt, ... ) { + va_list ap; + char buf[2048]; + + if ( !logfile.fp ) { + return; + } + va_start( ap, fmt ); + vsprintf( buf, fmt, ap ); + va_end( ap ); + Log_UnifyEndOfLine( buf ); + fprintf( logfile.fp, "%s", buf ); + fflush( logfile.fp ); +} //end of the function Log_Write +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void Log_WriteTimeStamped( char *fmt, ... ) { + va_list ap; + + if ( !logfile.fp ) { + return; + } +/* fprintf(logfile.fp, "%d %02d:%02d:%02d:%02d ", + logfile.numwrites, + (int) (botlibglobals.time / 60 / 60), + (int) (botlibglobals.time / 60), + (int) (botlibglobals.time), + (int) ((int) (botlibglobals.time * 100)) - + ((int) botlibglobals.time) * 100);*/ + va_start( ap, fmt ); + vfprintf( logfile.fp, fmt, ap ); + va_end( ap ); + logfile.numwrites++; + fflush( logfile.fp ); +} //end of the function Log_Write +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +FILE *Log_FileStruct( void ) { + return logfile.fp; +} //end of the function Log_FileStruct +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void Log_Flush( void ) { + if ( logfile.fp ) { + fflush( logfile.fp ); + } +} //end of the function Log_Flush + diff --git a/Projects/Android/jni/rtcw/src/bspc/l_log.h b/Projects/Android/jni/rtcw/src/bspc/l_log.h new file mode 100644 index 0000000..978b19d --- /dev/null +++ b/Projects/Android/jni/rtcw/src/bspc/l_log.h @@ -0,0 +1,57 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +//=========================================================================== +// +// Name: l_log.h +// Function: log file stuff +// Programmer: Mr Elusive (MrElusive@demigod.demon.nl) +// Last update: 1997-12-31 +// Tab Size: 3 +//=========================================================================== + +//open a log file +void Log_Open( char *filename ); +//close the current log file +void Log_Close( void ); +//close log file if present +void Log_Shutdown( void ); +//print on stdout and write to the current opened log file +void Log_Print( char *fmt, ... ); +//write to the current opened log file +void Log_Write( char *fmt, ... ); +//write to the current opened log file with a time stamp +void Log_WriteTimeStamped( char *fmt, ... ); +//returns the log file structure +FILE *Log_FileStruct( void ); +//flush log file +void Log_Flush( void ); + +#ifdef WINBSPC +void WinBSPCPrint( char *str ); +#endif //WINBSPC diff --git a/Projects/Android/jni/rtcw/src/bspc/l_math.c b/Projects/Android/jni/rtcw/src/bspc/l_math.c new file mode 100644 index 0000000..52f15fc --- /dev/null +++ b/Projects/Android/jni/rtcw/src/bspc/l_math.c @@ -0,0 +1,279 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +// mathlib.c -- math primitives + +#include "l_cmd.h" +#include "l_math.h" + +vec3_t vec3_origin = {0,0,0}; + +void AngleVectors( const vec3_t angles, vec3_t forward, vec3_t right, vec3_t up ) { + float angle; + static float sr, sp, sy, cr, cp, cy; + // static to help MS compiler fp bugs + + angle = angles[YAW] * ( M_PI * 2 / 360 ); + sy = sin( angle ); + cy = cos( angle ); + angle = angles[PITCH] * ( M_PI * 2 / 360 ); + sp = sin( angle ); + cp = cos( angle ); + angle = angles[ROLL] * ( M_PI * 2 / 360 ); + sr = sin( angle ); + cr = cos( angle ); + + if ( forward ) { + forward[0] = cp * cy; + forward[1] = cp * sy; + forward[2] = -sp; + } + if ( right ) { + right[0] = ( -1 * sr * sp * cy + - 1 * cr * -sy ); + right[1] = ( -1 * sr * sp * sy + - 1 * cr * cy ); + right[2] = -1 * sr * cp; + } + if ( up ) { + up[0] = ( cr * sp * cy + - sr * -sy ); + up[1] = ( cr * sp * sy + - sr * cy ); + up[2] = cr * cp; + } +} + +/* +================= +RadiusFromBounds +================= +*/ +float RadiusFromBounds( const vec3_t mins, const vec3_t maxs ) { + int i; + vec3_t corner; + float a, b; + + for ( i = 0 ; i < 3 ; i++ ) { + a = fabs( mins[i] ); + b = fabs( maxs[i] ); + corner[i] = a > b ? a : b; + } + + return VectorLength( corner ); +} + +/* +================ +R_ConcatRotations +================ +*/ +void R_ConcatRotations( float in1[3][3], float in2[3][3], float out[3][3] ) { + out[0][0] = in1[0][0] * in2[0][0] + in1[0][1] * in2[1][0] + + in1[0][2] * in2[2][0]; + out[0][1] = in1[0][0] * in2[0][1] + in1[0][1] * in2[1][1] + + in1[0][2] * in2[2][1]; + out[0][2] = in1[0][0] * in2[0][2] + in1[0][1] * in2[1][2] + + in1[0][2] * in2[2][2]; + out[1][0] = in1[1][0] * in2[0][0] + in1[1][1] * in2[1][0] + + in1[1][2] * in2[2][0]; + out[1][1] = in1[1][0] * in2[0][1] + in1[1][1] * in2[1][1] + + in1[1][2] * in2[2][1]; + out[1][2] = in1[1][0] * in2[0][2] + in1[1][1] * in2[1][2] + + in1[1][2] * in2[2][2]; + out[2][0] = in1[2][0] * in2[0][0] + in1[2][1] * in2[1][0] + + in1[2][2] * in2[2][0]; + out[2][1] = in1[2][0] * in2[0][1] + in1[2][1] * in2[1][1] + + in1[2][2] * in2[2][1]; + out[2][2] = in1[2][0] * in2[0][2] + in1[2][1] * in2[1][2] + + in1[2][2] * in2[2][2]; +} + +void AxisClear( vec3_t axis[3] ) { + axis[0][0] = 1; + axis[0][1] = 0; + axis[0][2] = 0; + axis[1][0] = 0; + axis[1][1] = 1; + axis[1][2] = 0; + axis[2][0] = 0; + axis[2][1] = 0; + axis[2][2] = 1; +} + +double VectorLength( vec3_t v ) { + int i; + double length; + + length = 0; + for ( i = 0 ; i < 3 ; i++ ) + length += v[i] * v[i]; + length = sqrt( length ); // FIXME + + return length; +} + +float VectorLengthSquared( vec3_t v ) { + return DotProduct( v, v ); +} + +qboolean VectorCompare( vec3_t v1, vec3_t v2 ) { + int i; + + for ( i = 0 ; i < 3 ; i++ ) + if ( fabs( v1[i] - v2[i] ) > EQUAL_EPSILON ) { + return false; + } + + return true; +} + +vec_t Q_rint( vec_t in ) { + return floor( in + 0.5 ); +} + +void CrossProduct( const vec3_t v1, const vec3_t v2, vec3_t cross ) { + cross[0] = v1[1] * v2[2] - v1[2] * v2[1]; + cross[1] = v1[2] * v2[0] - v1[0] * v2[2]; + cross[2] = v1[0] * v2[1] - v1[1] * v2[0]; +} + +void _VectorMA( vec3_t va, double scale, vec3_t vb, vec3_t vc ) { + vc[0] = va[0] + scale * vb[0]; + vc[1] = va[1] + scale * vb[1]; + vc[2] = va[2] + scale * vb[2]; +} + +vec_t _DotProduct( vec3_t v1, vec3_t v2 ) { + return v1[0] * v2[0] + v1[1] * v2[1] + v1[2] * v2[2]; +} + +void _VectorSubtract( vec3_t va, vec3_t vb, vec3_t out ) { + out[0] = va[0] - vb[0]; + out[1] = va[1] - vb[1]; + out[2] = va[2] - vb[2]; +} + +void _VectorAdd( vec3_t va, vec3_t vb, vec3_t out ) { + out[0] = va[0] + vb[0]; + out[1] = va[1] + vb[1]; + out[2] = va[2] + vb[2]; +} + +void _VectorCopy( vec3_t in, vec3_t out ) { + out[0] = in[0]; + out[1] = in[1]; + out[2] = in[2]; +} + +void _VectorScale( vec3_t v, vec_t scale, vec3_t out ) { + out[0] = v[0] * scale; + out[1] = v[1] * scale; + out[2] = v[2] * scale; +} + +vec_t VectorNormalize( vec3_t inout ) { + vec_t length, ilength; + + length = sqrt( inout[0] * inout[0] + inout[1] * inout[1] + inout[2] * inout[2] ); + if ( length == 0 ) { + VectorClear( inout ); + return 0; + } + + ilength = 1.0 / length; + inout[0] = inout[0] * ilength; + inout[1] = inout[1] * ilength; + inout[2] = inout[2] * ilength; + + return length; +} + +vec_t VectorNormalize2( const vec3_t in, vec3_t out ) { + vec_t length, ilength; + + length = sqrt( in[0] * in[0] + in[1] * in[1] + in[2] * in[2] ); + if ( length == 0 ) { + VectorClear( out ); + return 0; + } + + ilength = 1.0 / length; + out[0] = in[0] * ilength; + out[1] = in[1] * ilength; + out[2] = in[2] * ilength; + + return length; +} + +vec_t ColorNormalize( vec3_t in, vec3_t out ) { + float max, scale; + + max = in[0]; + if ( in[1] > max ) { + max = in[1]; + } + if ( in[2] > max ) { + max = in[2]; + } + + if ( max == 0 ) { + return 0; + } + + scale = 1.0 / max; + + VectorScale( in, scale, out ); + + return max; +} + + + +void VectorInverse( vec3_t v ) { + v[0] = -v[0]; + v[1] = -v[1]; + v[2] = -v[2]; +} + +void ClearBounds( vec3_t mins, vec3_t maxs ) { + mins[0] = mins[1] = mins[2] = 99999; + maxs[0] = maxs[1] = maxs[2] = -99999; +} + +void AddPointToBounds( const vec3_t v, vec3_t mins, vec3_t maxs ) { + int i; + vec_t val; + + for ( i = 0 ; i < 3 ; i++ ) + { + val = v[i]; + if ( val < mins[i] ) { + mins[i] = val; + } + if ( val > maxs[i] ) { + maxs[i] = val; + } + } +} diff --git a/Projects/Android/jni/rtcw/src/bspc/l_math.h b/Projects/Android/jni/rtcw/src/bspc/l_math.h new file mode 100644 index 0000000..872c4c5 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/bspc/l_math.h @@ -0,0 +1,100 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +#ifndef __MATHLIB__ +#define __MATHLIB__ + +// mathlib.h + +#include + +#ifdef DOUBLEVEC_T +typedef double vec_t; +#else +typedef float vec_t; +#endif +typedef vec_t vec3_t[3]; +typedef vec_t vec4_t[4]; + +#define SIDE_FRONT 0 +#define SIDE_ON 2 +#define SIDE_BACK 1 +#define SIDE_CROSS -2 + +#define PITCH 0 +#define YAW 1 +#define ROLL 2 + +#define Q_PI 3.14159265358979323846 + +#define DEG2RAD( a ) ( a * M_PI ) / 180.0F + +#ifndef M_PI +#define M_PI 3.14159265358979323846 // matches value in gcc v2 math.h +#endif + +extern vec3_t vec3_origin; + +#define EQUAL_EPSILON 0.001 + +qboolean VectorCompare( vec3_t v1, vec3_t v2 ); + +#define DotProduct( x,y ) ( x[0] * y[0] + x[1] * y[1] + x[2] * y[2] ) +#define VectorSubtract( a,b,c ) {c[0] = a[0] - b[0]; c[1] = a[1] - b[1]; c[2] = a[2] - b[2];} +#define VectorAdd( a,b,c ) {c[0] = a[0] + b[0]; c[1] = a[1] + b[1]; c[2] = a[2] + b[2];} +#define VectorCopy( a,b ) {b[0] = a[0]; b[1] = a[1]; b[2] = a[2];} +#define Vector4Copy( a,b ) {b[0] = a[0]; b[1] = a[1]; b[2] = a[2]; b[3] = a[3];} +#define VectorScale( v, s, o ) ( ( o )[0] = ( v )[0] * ( s ),( o )[1] = ( v )[1] * ( s ),( o )[2] = ( v )[2] * ( s ) ) +#define VectorClear( x ) {x[0] = x[1] = x[2] = 0;} +#define VectorNegate( x, y ) {y[0] = -x[0]; y[1] = -x[1]; y[2] = -x[2];} +#define VectorMA( v, s, b, o ) ( ( o )[0] = ( v )[0] + ( b )[0] * ( s ),( o )[1] = ( v )[1] + ( b )[1] * ( s ),( o )[2] = ( v )[2] + ( b )[2] * ( s ) ) + +vec_t Q_rint( vec_t in ); +vec_t _DotProduct( vec3_t v1, vec3_t v2 ); +void _VectorSubtract( vec3_t va, vec3_t vb, vec3_t out ); +void _VectorAdd( vec3_t va, vec3_t vb, vec3_t out ); +void _VectorCopy( vec3_t in, vec3_t out ); +void _VectorScale( vec3_t v, vec_t scale, vec3_t out ); +void _VectorMA( vec3_t va, double scale, vec3_t vb, vec3_t vc ); + +double VectorLength( vec3_t v ); +void CrossProduct( const vec3_t v1, const vec3_t v2, vec3_t cross ); +vec_t VectorNormalize( vec3_t inout ); +vec_t ColorNormalize( vec3_t in, vec3_t out ); +vec_t VectorNormalize2( const vec3_t v, vec3_t out ); +void VectorInverse( vec3_t v ); + +void ClearBounds( vec3_t mins, vec3_t maxs ); +void AddPointToBounds( const vec3_t v, vec3_t mins, vec3_t maxs ); + +void AngleVectors( const vec3_t angles, vec3_t forward, vec3_t right, vec3_t up ); +void R_ConcatRotations( float in1[3][3], float in2[3][3], float out[3][3] ); +void RotatePoint( vec3_t point, float matrix[3][3] ); +void CreateRotationMatrix( vec3_t angles, float matrix[3][3] ); + +#endif diff --git a/Projects/Android/jni/rtcw/src/bspc/l_mem.c b/Projects/Android/jni/rtcw/src/bspc/l_mem.c new file mode 100644 index 0000000..c81375a --- /dev/null +++ b/Projects/Android/jni/rtcw/src/bspc/l_mem.c @@ -0,0 +1,468 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +//=========================================================================== +// +// Name: l_mem.c +// Function: +// Programmer: Mr Elusive (MrElusive@demigod.demon.nl) +// Last update: 1999-06-02 +// Tab Size: 3 +//=========================================================================== + +#include "qbsp.h" +#include "l_log.h" + +int allocedmemory; + +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void PrintMemorySize( unsigned long size ) { + unsigned long number1, number2, number3; + number1 = size >> 20; + number2 = ( size & 0xFFFFF ) >> 10; + number3 = ( size & 0x3FF ); + if ( number1 ) { + Log_Print( "%ld MB", number1 ); + } + if ( number1 && number2 ) { + Log_Print( " and " ); + } + if ( number2 ) { + Log_Print( "%ld KB", number2 ); + } + if ( number2 && number3 ) { + Log_Print( " and " ); + } + if ( number3 ) { + Log_Print( "%ld bytes", number3 ); + } +} //end of the function PrintFileSize + +#ifndef MEMDEBUG +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int MemorySize( void *ptr ) { +#if defined( WIN32 ) || defined( _WIN32 ) + #ifdef __WATCOMC__ + //Intel 32 bits memory addressing, 16 bytes aligned + return ( _msize( ptr ) + 15 ) >> 4 << 4; + #else + return _msize( ptr ); + #endif +#else + return 0; +#endif +} //end of the function MemorySize +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void *GetClearedMemory( int size ) { + void *ptr; + + ptr = (void *) malloc( size ); + if ( !ptr ) { + Error( "out of memory" ); + } + memset( ptr, 0, size ); + allocedmemory += MemorySize( ptr ); + return ptr; +} //end of the function GetClearedMemory +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void *GetMemory( unsigned long size ) { + void *ptr; + ptr = malloc( size ); + if ( !ptr ) { + Error( "out of memory" ); + } + allocedmemory += MemorySize( ptr ); + return ptr; +} //end of the function GetMemory +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int fmemsize; +void FreeMemory( void *ptr ) { + // RF, modified this for better memory trash testing + fmemsize = MemorySize( ptr ); + allocedmemory -= fmemsize; + + // RF, somehow this crashes windows if size is less than or equal 8 + if ( fmemsize <= 8 ) { + return; + } + + // RF, set this memory to something that will cause problems if accessed again + memset( ptr, 0xAA, fmemsize ); + + free( ptr ); +} //end of the function FreeMemory +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int TotalAllocatedMemory( void ) { + return allocedmemory; +} //end of the function TotalAllocatedMemory + +#else + +#define MEM_ID 0x12345678l + +int totalmemorysize; +int numblocks; + +typedef struct memoryblock_s +{ + unsigned long int id; + void *ptr; + int size; +#ifdef MEMDEBUG + char *label; + char *file; + int line; +#endif //MEMDEBUG + struct memoryblock_s *prev, *next; +} memoryblock_t; + +memoryblock_t *memory; + +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void LinkMemoryBlock( memoryblock_t *block ) { + block->prev = NULL; + block->next = memory; + if ( memory ) { + memory->prev = block; + } + memory = block; +} //end of the function LinkMemoryBlock +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void UnlinkMemoryBlock( memoryblock_t *block ) { + if ( block->prev ) { + block->prev->next = block->next; + } else { memory = block->next;} + if ( block->next ) { + block->next->prev = block->prev; + } +} //end of the function UnlinkMemoryBlock +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +#ifdef MEMDEBUG +void *GetMemoryDebug( unsigned long size, char *label, char *file, int line ) +#else +void *GetMemory( unsigned long size ) +#endif //MEMDEBUG +{ + void *ptr; + memoryblock_t *block; + + ptr = malloc( size + sizeof( memoryblock_t ) ); + block = (memoryblock_t *) ptr; + block->id = MEM_ID; + block->ptr = (char *) ptr + sizeof( memoryblock_t ); + block->size = size + sizeof( memoryblock_t ); +#ifdef MEMDEBUG + block->label = label; + block->file = file; + block->line = line; +#endif //MEMDEBUG + LinkMemoryBlock( block ); + totalmemorysize += block->size; + numblocks++; + return block->ptr; +} //end of the function GetMemoryDebug +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +#ifdef MEMDEBUG +void *GetClearedMemoryDebug( unsigned long size, char *label, char *file, int line ) +#else +void *GetClearedMemory( unsigned long size ) +#endif //MEMDEBUG +{ + void *ptr; +#ifdef MEMDEBUG + ptr = GetMemoryDebug( size, label, file, line ); +#else + ptr = GetMemory( size ); +#endif //MEMDEBUG + memset( ptr, 0, size ); + return ptr; +} //end of the function GetClearedMemoryLabelled +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void *GetClearedHunkMemory( unsigned long size ) { + return GetClearedMemory( size ); +} //end of the function GetClearedHunkMemory +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void *GetHunkMemory( unsigned long size ) { + return GetMemory( size ); +} //end of the function GetHunkMemory +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +memoryblock_t *BlockFromPointer( void *ptr, char *str ) { + memoryblock_t *block; + + if ( !ptr ) { +#ifdef MEMDEBUG + //char *crash = (char *) NULL; + //crash[0] = 1; + Error( "%s: NULL pointer\n", str ); +#endif MEMDEBUG + return NULL; + } //end if + block = ( memoryblock_t * )( (char *) ptr - sizeof( memoryblock_t ) ); + if ( block->id != MEM_ID ) { + Error( "%s: invalid memory block\n", str ); + } //end if + if ( block->ptr != ptr ) { + + Error( "%s: memory block pointer invalid\n", str ); + } //end if + return block; +} //end of the function BlockFromPointer +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void FreeMemory( void *ptr ) { + memoryblock_t *block; + + block = BlockFromPointer( ptr, "FreeMemory" ); + if ( !block ) { + return; + } + UnlinkMemoryBlock( block ); + totalmemorysize -= block->size; + numblocks--; + // + free( block ); +} //end of the function FreeMemory +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int MemoryByteSize( void *ptr ) { + memoryblock_t *block; + + block = BlockFromPointer( ptr, "MemoryByteSize" ); + if ( !block ) { + return 0; + } + return block->size; +} //end of the function MemoryByteSize +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int MemorySize( void *ptr ) { + return MemoryByteSize( ptr ); +} //end of the function MemorySize +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void PrintUsedMemorySize( void ) { + printf( "total botlib memory: %d KB\n", totalmemorysize >> 10 ); + printf( "total memory blocks: %d\n", numblocks ); +} //end of the function PrintUsedMemorySize +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void PrintMemoryLabels( void ) { + memoryblock_t *block; + int i; + + PrintUsedMemorySize(); + i = 0; + for ( block = memory; block; block = block->next ) + { +#ifdef MEMDEBUG + Log_Write( "%6d, %p, %8d: %24s line %6d: %s", i, block->ptr, block->size, block->file, block->line, block->label ); +#endif //MEMDEBUG + i++; + } //end for +} //end of the function PrintMemoryLabels +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void DumpMemory( void ) { + memoryblock_t *block; + + for ( block = memory; block; block = memory ) + { + FreeMemory( block->ptr ); + } //end for + totalmemorysize = 0; +} //end of the function DumpMemory +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int TotalAllocatedMemory( void ) { + return totalmemorysize; +} //end of the function TotalAllocatedMemory +#endif + +//=========================================================================== +// Q3 Hunk and Z_ memory management +//=========================================================================== + +typedef struct memhunk_s +{ + void *ptr; + struct memhunk_s *next; +} memhunk_t; + +memhunk_t *memhunk_high; +memhunk_t *memhunk_low; +int memhunk_high_size = 16 * 1024 * 1024; +int memhunk_low_size = 0; + +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void Hunk_ClearHigh( void ) { + memhunk_t *h, *nexth; + + for ( h = memhunk_high; h; h = nexth ) + { + nexth = h->next; + FreeMemory( h ); + } //end for + memhunk_high = NULL; + memhunk_high_size = 16 * 1024 * 1024; +} //end of the function Hunk_ClearHigh +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void *Hunk_Alloc( int size ) { + memhunk_t *h; + + if ( !size ) { + return (void *) memhunk_high_size; + } + // + h = GetClearedMemory( size + sizeof( memhunk_t ) ); + h->ptr = (char *) h + sizeof( memhunk_t ); + h->next = memhunk_high; + memhunk_high = h; + memhunk_high_size -= size; + return h->ptr; +} //end of the function Hunk_Alloc +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void *Z_Malloc( int size ) { + return GetClearedMemory( size ); +} //end of the function Z_Malloc +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void Z_Free( void *ptr ) { + FreeMemory( ptr ); +} //end of the function Z_Free diff --git a/Projects/Android/jni/rtcw/src/bspc/l_mem.h b/Projects/Android/jni/rtcw/src/bspc/l_mem.h new file mode 100644 index 0000000..5b29f81 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/bspc/l_mem.h @@ -0,0 +1,58 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + + +//============================================================================= + +// memory.h +//#define MEMDEBUG +#undef MEMDEBUG + +#ifndef MEMDEBUG + +void *GetClearedMemory( int size ); +void *GetMemory( unsigned long size ); + +#else + +#define GetMemory( size ) GetMemoryDebug( size, # size, __FILE__, __LINE__ ); +#define GetClearedMemory( size ) GetClearedMemoryDebug( size, # size, __FILE__, __LINE__ ); +//allocate a memory block of the given size +void *GetMemoryDebug( unsigned long size, char *label, char *file, int line ); +//allocate a memory block of the given size and clear it +void *GetClearedMemoryDebug( unsigned long size, char *label, char *file, int line ); +// +void PrintMemoryLabels( void ); +#endif //MEMDEBUG + +void FreeMemory( void *ptr ); +int MemorySize( void *ptr ); +void PrintMemorySize( unsigned long size ); +int TotalAllocatedMemory( void ); + diff --git a/Projects/Android/jni/rtcw/src/bspc/l_poly.c b/Projects/Android/jni/rtcw/src/bspc/l_poly.c new file mode 100644 index 0000000..761cd9c --- /dev/null +++ b/Projects/Android/jni/rtcw/src/bspc/l_poly.c @@ -0,0 +1,1434 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +//=========================================================================== +// +// Name: l_poly.c +// Function: +// Programmer: id Sofware +// Mr Elusive (MrElusive@demigod.demon.nl) +// Last update: 1997-12-04 +// Tab Size: 3 +//=========================================================================== + +#include +#include "l_cmd.h" +#include "l_math.h" +#include "l_poly.h" +#include "l_log.h" +#include "l_mem.h" + +//#define BOGUS_RANGE 8192 +#define BOGUS_RANGE ( 128 * 1024 ) + +extern int numthreads; + +// counters are only bumped when running single threaded, +// because they are an awefull coherence problem +int c_active_windings; +int c_peak_windings; +int c_winding_allocs; +int c_winding_points; +int c_windingmemory; +int c_peak_windingmemory; + +char windingerror[1024]; + +void pw( winding_t *w ) { + int i; + for ( i = 0 ; i < w->numpoints ; i++ ) + printf( "(%5.3f, %5.3f, %5.3f)\n",w->p[i][0], w->p[i][1],w->p[i][2] ); +} + + +void ResetWindings( void ) { + c_active_windings = 0; + c_peak_windings = 0; + c_winding_allocs = 0; + c_winding_points = 0; + c_windingmemory = 0; + c_peak_windingmemory = 0; + + strcpy( windingerror, "" ); +} //end of the function ResetWindings +/* +============= +AllocWinding +============= +*/ +winding_t *AllocWinding( int points ) { + winding_t *w; + int s; + + s = sizeof( vec_t ) * 3 * points + sizeof( int ); + w = GetMemory( s ); + memset( w, 0, s ); + + if ( numthreads == 1 ) { + c_winding_allocs++; + c_winding_points += points; + c_active_windings++; + if ( c_active_windings > c_peak_windings ) { + c_peak_windings = c_active_windings; + } + c_windingmemory += MemorySize( w ); + if ( c_windingmemory > c_peak_windingmemory ) { + c_peak_windingmemory = c_windingmemory; + } + } //end if + return w; +} //end of the function AllocWinding + +void FreeWinding( winding_t *w ) { + if ( *(unsigned *)w == 0xdeaddead ) { + Error( "FreeWinding: freed a freed winding" ); + } + + if ( numthreads == 1 ) { + c_active_windings--; + c_windingmemory -= MemorySize( w ); + } //end if + + *(unsigned *)w = 0xdeaddead; + + FreeMemory( w ); +} //end of the function FreeWinding + +int WindingMemory( void ) { + return c_windingmemory; +} //end of the function WindingMemory + +int WindingPeakMemory( void ) { + return c_peak_windingmemory; +} //end of the function WindingPeakMemory + +int ActiveWindings( void ) { + return c_active_windings; +} //end of the function ActiveWindings +/* +============ +RemoveColinearPoints +============ +*/ +int c_removed; + +void RemoveColinearPoints( winding_t *w ) { + int i, j, k; + vec3_t v1, v2; + int nump; + vec3_t p[MAX_POINTS_ON_WINDING]; + + nump = 0; + for ( i = 0 ; i < w->numpoints ; i++ ) + { + j = ( i + 1 ) % w->numpoints; + k = ( i + w->numpoints - 1 ) % w->numpoints; + VectorSubtract( w->p[j], w->p[i], v1 ); + VectorSubtract( w->p[i], w->p[k], v2 ); + VectorNormalize( v1 ); + VectorNormalize( v2 ); + if ( DotProduct( v1, v2 ) < 0.999 ) { + if ( nump >= MAX_POINTS_ON_WINDING ) { + Error( "RemoveColinearPoints: MAX_POINTS_ON_WINDING" ); + } + VectorCopy( w->p[i], p[nump] ); + nump++; + } + } + + if ( nump == w->numpoints ) { + return; + } + + if ( numthreads == 1 ) { + c_removed += w->numpoints - nump; + } + w->numpoints = nump; + memcpy( w->p, p, nump * sizeof( p[0] ) ); +} + +/* +============ +WindingPlane +============ +*/ +void WindingPlane( winding_t *w, vec3_t normal, vec_t *dist ) { + vec3_t v1, v2; + int i; + + //find two vectors each longer than 0.5 units + for ( i = 0; i < w->numpoints; i++ ) + { + VectorSubtract( w->p[( i + 1 ) % w->numpoints], w->p[i], v1 ); + VectorSubtract( w->p[( i + 2 ) % w->numpoints], w->p[i], v2 ); + if ( VectorLength( v1 ) > 0.5 && VectorLength( v2 ) > 0.5 ) { + break; + } + } //end for + CrossProduct( v2, v1, normal ); + VectorNormalize( normal ); + *dist = DotProduct( w->p[0], normal ); +} //end of the function WindingPlane + +/* +============= +WindingArea +============= +*/ +vec_t WindingArea( winding_t *w ) { + int i; + vec3_t d1, d2, cross; + vec_t total; + + total = 0; + for ( i = 2 ; i < w->numpoints ; i++ ) + { + VectorSubtract( w->p[i - 1], w->p[0], d1 ); + VectorSubtract( w->p[i], w->p[0], d2 ); + CrossProduct( d1, d2, cross ); + total += 0.5 * VectorLength( cross ); + } + return total; +} + +void WindingBounds( winding_t *w, vec3_t mins, vec3_t maxs ) { + vec_t v; + int i,j; + + mins[0] = mins[1] = mins[2] = 99999; + maxs[0] = maxs[1] = maxs[2] = -99999; + + for ( i = 0 ; i < w->numpoints ; i++ ) + { + for ( j = 0 ; j < 3 ; j++ ) + { + v = w->p[i][j]; + if ( v < mins[j] ) { + mins[j] = v; + } + if ( v > maxs[j] ) { + maxs[j] = v; + } + } + } +} + +/* +============= +WindingCenter +============= +*/ +void WindingCenter( winding_t *w, vec3_t center ) { + int i; + float scale; + + VectorCopy( vec3_origin, center ); + for ( i = 0 ; i < w->numpoints ; i++ ) + VectorAdd( w->p[i], center, center ); + + scale = 1.0 / w->numpoints; + VectorScale( center, scale, center ); +} + +/* +================= +BaseWindingForPlane +================= +*/ +winding_t *BaseWindingForPlane( vec3_t normal, vec_t dist ) { + int i, x; + vec_t max, v; + vec3_t org, vright, vup; + winding_t *w; + +// find the major axis + + max = -BOGUS_RANGE; + x = -1; + for ( i = 0 ; i < 3; i++ ) + { + v = fabs( normal[i] ); + if ( v > max ) { + x = i; + max = v; + } + } + if ( x == -1 ) { + Error( "BaseWindingForPlane: no axis found" ); + } + + VectorCopy( vec3_origin, vup ); + switch ( x ) + { + case 0: + case 1: + vup[2] = 1; + break; + case 2: + vup[0] = 1; + break; + } + + v = DotProduct( vup, normal ); + VectorMA( vup, -v, normal, vup ); + VectorNormalize( vup ); + + VectorScale( normal, dist, org ); + + CrossProduct( vup, normal, vright ); + + VectorScale( vup, BOGUS_RANGE, vup ); + VectorScale( vright, BOGUS_RANGE, vright ); + +// project a really big axis aligned box onto the plane + w = AllocWinding( 4 ); + + VectorSubtract( org, vright, w->p[0] ); + VectorAdd( w->p[0], vup, w->p[0] ); + + VectorAdd( org, vright, w->p[1] ); + VectorAdd( w->p[1], vup, w->p[1] ); + + VectorAdd( org, vright, w->p[2] ); + VectorSubtract( w->p[2], vup, w->p[2] ); + + VectorSubtract( org, vright, w->p[3] ); + VectorSubtract( w->p[3], vup, w->p[3] ); + + w->numpoints = 4; + + return w; +} + +/* +================== +CopyWinding +================== +*/ +winding_t *CopyWinding( winding_t *w ) { + int size; + winding_t *c; + + c = AllocWinding( w->numpoints ); + size = (int)( (winding_t *)0 )->p[w->numpoints]; + memcpy( c, w, size ); + return c; +} + +/* +================== +ReverseWinding +================== +*/ +winding_t *ReverseWinding( winding_t *w ) { + int i; + winding_t *c; + + c = AllocWinding( w->numpoints ); + for ( i = 0 ; i < w->numpoints ; i++ ) + { + VectorCopy( w->p[w->numpoints - 1 - i], c->p[i] ); + } + c->numpoints = w->numpoints; + return c; +} + + +/* +============= +ClipWindingEpsilon +============= +*/ +void ClipWindingEpsilon( winding_t *in, vec3_t normal, vec_t dist, + vec_t epsilon, winding_t **front, winding_t **back ) { + vec_t dists[MAX_POINTS_ON_WINDING + 4]; + int sides[MAX_POINTS_ON_WINDING + 4]; + int counts[3]; + //MrElusive: DOH can't use statics when unsing multithreading!!! + vec_t dot; // VC 4.2 optimizer bug if not static + int i, j; + vec_t *p1, *p2; + vec3_t mid; + winding_t *f, *b; + int maxpts; + + counts[0] = counts[1] = counts[2] = 0; + +// determine sides for each point + for ( i = 0 ; i < in->numpoints ; i++ ) + { + dot = DotProduct( in->p[i], normal ); + dot -= dist; + dists[i] = dot; + if ( dot > epsilon ) { + sides[i] = SIDE_FRONT; + } else if ( dot < -epsilon ) { + sides[i] = SIDE_BACK; + } else + { + sides[i] = SIDE_ON; + } + counts[sides[i]]++; + } + sides[i] = sides[0]; + dists[i] = dists[0]; + + *front = *back = NULL; + + if ( !counts[0] ) { + *back = CopyWinding( in ); + return; + } + if ( !counts[1] ) { + *front = CopyWinding( in ); + return; + } + + maxpts = in->numpoints + 4; // cant use counts[0]+2 because + // of fp grouping errors + + *front = f = AllocWinding( maxpts ); + *back = b = AllocWinding( maxpts ); + + for ( i = 0 ; i < in->numpoints ; i++ ) + { + p1 = in->p[i]; + + if ( sides[i] == SIDE_ON ) { + VectorCopy( p1, f->p[f->numpoints] ); + f->numpoints++; + VectorCopy( p1, b->p[b->numpoints] ); + b->numpoints++; + continue; + } + + if ( sides[i] == SIDE_FRONT ) { + VectorCopy( p1, f->p[f->numpoints] ); + f->numpoints++; + } + if ( sides[i] == SIDE_BACK ) { + VectorCopy( p1, b->p[b->numpoints] ); + b->numpoints++; + } + + if ( sides[i + 1] == SIDE_ON || sides[i + 1] == sides[i] ) { + continue; + } + + // generate a split point + p2 = in->p[( i + 1 ) % in->numpoints]; + + dot = dists[i] / ( dists[i] - dists[i + 1] ); + for ( j = 0 ; j < 3 ; j++ ) + { // avoid round off error when possible + if ( normal[j] == 1 ) { + mid[j] = dist; + } else if ( normal[j] == -1 ) { + mid[j] = -dist; + } else { + mid[j] = p1[j] + dot * ( p2[j] - p1[j] ); + } + } + + VectorCopy( mid, f->p[f->numpoints] ); + f->numpoints++; + VectorCopy( mid, b->p[b->numpoints] ); + b->numpoints++; + } + + if ( f->numpoints > maxpts || b->numpoints > maxpts ) { + Error( "ClipWinding: points exceeded estimate" ); + } + if ( f->numpoints > MAX_POINTS_ON_WINDING || b->numpoints > MAX_POINTS_ON_WINDING ) { + Error( "ClipWinding: MAX_POINTS_ON_WINDING" ); + } +} + + +/* +============= +ChopWindingInPlace +============= +*/ +void ChopWindingInPlace( winding_t **inout, vec3_t normal, vec_t dist, vec_t epsilon ) { + winding_t *in; + vec_t dists[MAX_POINTS_ON_WINDING + 4]; + int sides[MAX_POINTS_ON_WINDING + 4]; + int counts[3]; + //MrElusive: DOH can't use statics when unsing multithreading!!! + vec_t dot; // VC 4.2 optimizer bug if not static + int i, j; + vec_t *p1, *p2; + vec3_t mid; + winding_t *f; + int maxpts; + + in = *inout; + counts[0] = counts[1] = counts[2] = 0; + +// determine sides for each point + for ( i = 0 ; i < in->numpoints ; i++ ) + { + dot = DotProduct( in->p[i], normal ); + dot -= dist; + dists[i] = dot; + if ( dot > epsilon ) { + sides[i] = SIDE_FRONT; + } else if ( dot < -epsilon ) { + sides[i] = SIDE_BACK; + } else + { + sides[i] = SIDE_ON; + } + counts[sides[i]]++; + } + sides[i] = sides[0]; + dists[i] = dists[0]; + + if ( !counts[0] ) { + FreeWinding( in ); + *inout = NULL; + return; + } + if ( !counts[1] ) { + return; // inout stays the same + + } + maxpts = in->numpoints + 4; // cant use counts[0]+2 because + // of fp grouping errors + + f = AllocWinding( maxpts ); + + for ( i = 0 ; i < in->numpoints ; i++ ) + { + p1 = in->p[i]; + + if ( sides[i] == SIDE_ON ) { + VectorCopy( p1, f->p[f->numpoints] ); + f->numpoints++; + continue; + } + + if ( sides[i] == SIDE_FRONT ) { + VectorCopy( p1, f->p[f->numpoints] ); + f->numpoints++; + } + + if ( sides[i + 1] == SIDE_ON || sides[i + 1] == sides[i] ) { + continue; + } + + // generate a split point + p2 = in->p[( i + 1 ) % in->numpoints]; + + dot = dists[i] / ( dists[i] - dists[i + 1] ); + for ( j = 0 ; j < 3 ; j++ ) + { // avoid round off error when possible + if ( normal[j] == 1 ) { + mid[j] = dist; + } else if ( normal[j] == -1 ) { + mid[j] = -dist; + } else { + mid[j] = p1[j] + dot * ( p2[j] - p1[j] ); + } + } + + VectorCopy( mid, f->p[f->numpoints] ); + f->numpoints++; + } + + if ( f->numpoints > maxpts ) { + Error( "ClipWinding: points exceeded estimate" ); + } + if ( f->numpoints > MAX_POINTS_ON_WINDING ) { + Error( "ClipWinding: MAX_POINTS_ON_WINDING" ); + } + + FreeWinding( in ); + *inout = f; +} + + +/* +================= +ChopWinding + +Returns the fragment of in that is on the front side +of the cliping plane. The original is freed. +================= +*/ +winding_t *ChopWinding( winding_t *in, vec3_t normal, vec_t dist ) { + winding_t *f, *b; + + ClipWindingEpsilon( in, normal, dist, ON_EPSILON, &f, &b ); + FreeWinding( in ); + if ( b ) { + FreeWinding( b ); + } + return f; +} + + +/* +================= +CheckWinding + +================= +*/ +void CheckWinding( winding_t *w ) { + int i, j; + vec_t *p1, *p2; + vec_t d, edgedist; + vec3_t dir, edgenormal, facenormal; + vec_t area; + vec_t facedist; + + if ( w->numpoints < 3 ) { + Error( "CheckWinding: %i points",w->numpoints ); + } + + area = WindingArea( w ); + if ( area < 1 ) { + Error( "CheckWinding: %f area", area ); + } + + WindingPlane( w, facenormal, &facedist ); + + for ( i = 0 ; i < w->numpoints ; i++ ) + { + p1 = w->p[i]; + + for ( j = 0 ; j < 3 ; j++ ) + if ( p1[j] > BOGUS_RANGE || p1[j] < -BOGUS_RANGE ) { + Error( "CheckWinding: BUGUS_RANGE: %f",p1[j] ); + } + + j = i + 1 == w->numpoints ? 0 : i + 1; + + // check the point is on the face plane + d = DotProduct( p1, facenormal ) - facedist; + if ( d < -ON_EPSILON || d > ON_EPSILON ) { + Error( "CheckWinding: point off plane" ); + } + + // check the edge isnt degenerate + p2 = w->p[j]; + VectorSubtract( p2, p1, dir ); + + if ( VectorLength( dir ) < ON_EPSILON ) { + Error( "CheckWinding: degenerate edge" ); + } + + CrossProduct( facenormal, dir, edgenormal ); + VectorNormalize( edgenormal ); + edgedist = DotProduct( p1, edgenormal ); + edgedist += ON_EPSILON; + + // all other points must be on front side + for ( j = 0 ; j < w->numpoints ; j++ ) + { + if ( j == i ) { + continue; + } + d = DotProduct( w->p[j], edgenormal ); + if ( d > edgedist ) { + Error( "CheckWinding: non-convex" ); + } + } + } +} + + +/* +============ +WindingOnPlaneSide +============ +*/ +int WindingOnPlaneSide( winding_t *w, vec3_t normal, vec_t dist ) { + qboolean front, back; + int i; + vec_t d; + + front = false; + back = false; + for ( i = 0 ; i < w->numpoints ; i++ ) + { + d = DotProduct( w->p[i], normal ) - dist; + if ( d < -ON_EPSILON ) { + if ( front ) { + return SIDE_CROSS; + } + back = true; + continue; + } + if ( d > ON_EPSILON ) { + if ( back ) { + return SIDE_CROSS; + } + front = true; + continue; + } + } + + if ( back ) { + return SIDE_BACK; + } + if ( front ) { + return SIDE_FRONT; + } + return SIDE_ON; +} + +//#ifdef ME + #define CONTINUOUS_EPSILON 0.005 +//#else +// #define CONTINUOUS_EPSILON 0.001 +//#endif + +/* +============= +TryMergeWinding + +If two polygons share a common edge and the edges that meet at the +common points are both inside the other polygons, merge them + +Returns NULL if the faces couldn't be merged, or the new face. +The originals will NOT be freed. +============= +*/ + +winding_t *TryMergeWinding( winding_t *f1, winding_t *f2, vec3_t planenormal ) { + vec_t *p1, *p2, *p3, *p4, *back; + winding_t *newf; + int i, j, k, l; + vec3_t normal, delta; + vec_t dot; + qboolean keep1, keep2; + + + // + // find a common edge + // + p1 = p2 = NULL; // stop compiler warning + j = 0; // + + for ( i = 0; i < f1->numpoints; i++ ) + { + p1 = f1->p[i]; + p2 = f1->p[( i + 1 ) % f1->numpoints]; + for ( j = 0; j < f2->numpoints; j++ ) + { + p3 = f2->p[j]; + p4 = f2->p[( j + 1 ) % f2->numpoints]; + for ( k = 0; k < 3; k++ ) + { + if ( fabs( p1[k] - p4[k] ) > 0.1 ) { //EQUAL_EPSILON) //ME + break; + } + if ( fabs( p2[k] - p3[k] ) > 0.1 ) { //EQUAL_EPSILON) //ME + break; + } + } //end for + if ( k == 3 ) { + break; + } + } //end for + if ( j < f2->numpoints ) { + break; + } + } //end for + + if ( i == f1->numpoints ) { + return NULL; // no matching edges + + } + // + // check slope of connected lines + // if the slopes are colinear, the point can be removed + // + back = f1->p[( i + f1->numpoints - 1 ) % f1->numpoints]; + VectorSubtract( p1, back, delta ); + CrossProduct( planenormal, delta, normal ); + VectorNormalize( normal ); + + back = f2->p[( j + 2 ) % f2->numpoints]; + VectorSubtract( back, p1, delta ); + dot = DotProduct( delta, normal ); + if ( dot > CONTINUOUS_EPSILON ) { + return NULL; // not a convex polygon + } + keep1 = (qboolean)( dot < -CONTINUOUS_EPSILON ); + + back = f1->p[( i + 2 ) % f1->numpoints]; + VectorSubtract( back, p2, delta ); + CrossProduct( planenormal, delta, normal ); + VectorNormalize( normal ); + + back = f2->p[( j + f2->numpoints - 1 ) % f2->numpoints]; + VectorSubtract( back, p2, delta ); + dot = DotProduct( delta, normal ); + if ( dot > CONTINUOUS_EPSILON ) { + return NULL; // not a convex polygon + } + keep2 = (qboolean)( dot < -CONTINUOUS_EPSILON ); + + // + // build the new polygon + // + newf = AllocWinding( f1->numpoints + f2->numpoints ); + + // copy first polygon + for ( k = ( i + 1 ) % f1->numpoints ; k != i ; k = ( k + 1 ) % f1->numpoints ) + { + if ( k == ( i + 1 ) % f1->numpoints && !keep2 ) { + continue; + } + + VectorCopy( f1->p[k], newf->p[newf->numpoints] ); + newf->numpoints++; + } + + // copy second polygon + for ( l = ( j + 1 ) % f2->numpoints ; l != j ; l = ( l + 1 ) % f2->numpoints ) + { + if ( l == ( j + 1 ) % f2->numpoints && !keep1 ) { + continue; + } + VectorCopy( f2->p[l], newf->p[newf->numpoints] ); + newf->numpoints++; + } + + return newf; +} + +//#ifdef ME +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +winding_t *MergeWindings( winding_t *w1, winding_t *w2, vec3_t planenormal ) { + winding_t *neww; + float dist; + int i, j, n, found, insertafter; + int sides[MAX_POINTS_ON_WINDING + 4]; + vec3_t newp[MAX_POINTS_ON_WINDING + 4]; + int numpoints; + vec3_t edgevec, sepnormal, v; + + RemoveEqualPoints( w1, 0.2 ); + numpoints = w1->numpoints; + memcpy( newp, w1->p, w1->numpoints * sizeof( vec3_t ) ); + // + for ( i = 0; i < w2->numpoints; i++ ) + { + VectorCopy( w2->p[i], v ); + for ( j = 0; j < numpoints; j++ ) + { + VectorSubtract( newp[( j + 1 ) % numpoints], + newp[( j ) % numpoints], edgevec ); + CrossProduct( edgevec, planenormal, sepnormal ); + VectorNormalize( sepnormal ); + if ( VectorLength( sepnormal ) < 0.9 ) { + //remove the point from the new winding + for ( n = j; n < numpoints - 1; n++ ) + { + VectorCopy( newp[n + 1], newp[n] ); + sides[n] = sides[n + 1]; + } //end for + numpoints--; + j--; + Log_Print( "MergeWindings: degenerate edge on winding %f %f %f\n", sepnormal[0], + sepnormal[1], + sepnormal[2] ); + continue; + } //end if + dist = DotProduct( newp[( j ) % numpoints], sepnormal ); + if ( DotProduct( v, sepnormal ) - dist < -0.1 ) { + sides[j] = SIDE_BACK; + } else { sides[j] = SIDE_FRONT;} + } //end for + //remove all unnecesary points + for ( j = 0; j < numpoints; ) + { + if ( sides[j] == SIDE_BACK + && sides[( j + 1 ) % numpoints] == SIDE_BACK ) { + //remove the point from the new winding + for ( n = ( j + 1 ) % numpoints; n < numpoints - 1; n++ ) + { + VectorCopy( newp[n + 1], newp[n] ); + sides[n] = sides[n + 1]; + } //end for + numpoints--; + } //end if + else + { + j++; + } //end else + } //end for + // + found = false; + for ( j = 0; j < numpoints; j++ ) + { + if ( sides[j] == SIDE_FRONT + && sides[( j + 1 ) % numpoints] == SIDE_BACK ) { + if ( found ) { + Log_Print( "Warning: MergeWindings: front to back found twice\n" ); + } + found = true; + } //end if + } //end for + // + for ( j = 0; j < numpoints; j++ ) + { + if ( sides[j] == SIDE_FRONT + && sides[( j + 1 ) % numpoints] == SIDE_BACK ) { + insertafter = ( j + 1 ) % numpoints; + //insert the new point after j+1 + for ( n = numpoints - 1; n > insertafter; n-- ) + { + VectorCopy( newp[n], newp[n + 1] ); + } //end for + numpoints++; + VectorCopy( v, newp[( insertafter + 1 ) % numpoints] ); + break; + } //end if + } //end for + } //end for + neww = AllocWinding( numpoints ); + neww->numpoints = numpoints; + memcpy( neww->p, newp, numpoints * sizeof( vec3_t ) ); + RemoveColinearPoints( neww ); + return neww; +} //end of the function MergeWindings +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +char *WindingErrorString( void ) { + return windingerror; +} //end of the function WindingErrorString +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int WindingError( winding_t *w ) { + int i, j; + vec_t *p1, *p2; + vec_t d, edgedist; + vec3_t dir, edgenormal, facenormal; + vec_t area; + vec_t facedist; + + if ( w->numpoints < 3 ) { + sprintf( windingerror, "winding %i points", w->numpoints ); + return WE_NOTENOUGHPOINTS; + } //end if + + area = WindingArea( w ); + if ( area < 1 ) { + sprintf( windingerror, "winding %f area", area ); + return WE_SMALLAREA; + } //end if + + WindingPlane( w, facenormal, &facedist ); + + for ( i = 0 ; i < w->numpoints ; i++ ) + { + p1 = w->p[i]; + + for ( j = 0 ; j < 3 ; j++ ) + { + if ( p1[j] > BOGUS_RANGE || p1[j] < -BOGUS_RANGE ) { + sprintf( windingerror, "winding point %d BUGUS_RANGE \'%f %f %f\'", j, p1[0], p1[1], p1[2] ); + return WE_POINTBOGUSRANGE; + } //end if + } //end for + + j = i + 1 == w->numpoints ? 0 : i + 1; + + // check the point is on the face plane + d = DotProduct( p1, facenormal ) - facedist; + if ( d < -ON_EPSILON || d > ON_EPSILON ) { + sprintf( windingerror, "winding point %d off plane", i ); + return WE_POINTOFFPLANE; + } //end if + + // check the edge isnt degenerate + p2 = w->p[j]; + VectorSubtract( p2, p1, dir ); + + if ( VectorLength( dir ) < ON_EPSILON ) { + sprintf( windingerror, "winding degenerate edge %d-%d", i, j ); + return WE_DEGENERATEEDGE; + } //end if + + CrossProduct( facenormal, dir, edgenormal ); + VectorNormalize( edgenormal ); + edgedist = DotProduct( p1, edgenormal ); + edgedist += ON_EPSILON; + + // all other points must be on front side + for ( j = 0 ; j < w->numpoints ; j++ ) + { + if ( j == i ) { + continue; + } + d = DotProduct( w->p[j], edgenormal ); + if ( d > edgedist ) { + sprintf( windingerror, "winding non-convex" ); + return WE_NONCONVEX; + } //end if + } //end for + } //end for + return WE_NONE; +} //end of the function WindingError +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void RemoveEqualPoints( winding_t *w, float epsilon ) { + int i, nump; + vec3_t v; + vec3_t p[MAX_POINTS_ON_WINDING]; + + VectorCopy( w->p[0], p[0] ); + nump = 1; + for ( i = 1; i < w->numpoints; i++ ) + { + VectorSubtract( w->p[i], p[nump - 1], v ); + if ( VectorLength( v ) > epsilon ) { + if ( nump >= MAX_POINTS_ON_WINDING ) { + Error( "RemoveColinearPoints: MAX_POINTS_ON_WINDING" ); + } + VectorCopy( w->p[i], p[nump] ); + nump++; + } //end if + } //end for + + if ( nump == w->numpoints ) { + return; + } + + w->numpoints = nump; + memcpy( w->p, p, nump * sizeof( p[0] ) ); +} //end of the function RemoveEqualPoints +//=========================================================================== +// adds the given point to a winding at the given spot +// (for instance when spot is zero then the point is added at position zero) +// the original winding is NOT freed +// +// Parameter: - +// Returns: the new winding with the added point +// Changes Globals: - +//=========================================================================== +winding_t *AddWindingPoint( winding_t *w, vec3_t point, int spot ) { + int i, j; + winding_t *neww; + + if ( spot > w->numpoints ) { + Error( "AddWindingPoint: num > w->numpoints" ); + } //end if + if ( spot < 0 ) { + Error( "AddWindingPoint: num < 0" ); + } //end if + neww = AllocWinding( w->numpoints + 1 ); + neww->numpoints = w->numpoints + 1; + for ( i = 0, j = 0; i < neww->numpoints; i++ ) + { + if ( i == spot ) { + VectorCopy( point, neww->p[i] ); + } //end if + else + { + VectorCopy( w->p[j], neww->p[i] ); + j++; + } //end else + } //end for + return neww; +} //end of the function AddWindingPoint +//=========================================================================== +// the position where the new point should be added in the winding is +// stored in *spot +// +// Parameter: - +// Returns: true if the point is on the winding +// Changes Globals: - +//=========================================================================== +#define MELT_ON_EPSILON 0.2 + +int PointOnWinding( winding_t *w, vec3_t normal, float dist, vec3_t point, int *spot ) { + int i, j; + vec3_t v1, v2; + vec3_t edgenormal, edgevec; + float edgedist, dot; + + *spot = 0; + //the point must be on the winding plane + dot = DotProduct( point, normal ) - dist; + if ( dot < -MELT_ON_EPSILON || dot > MELT_ON_EPSILON ) { + return false; + } + // + for ( i = 0; i < w->numpoints; i++ ) + { + j = ( i + 1 ) % w->numpoints; + //get a plane orthogonal to the winding plane through the edge + VectorSubtract( w->p[j], w->p[i], edgevec ); + CrossProduct( normal, edgevec, edgenormal ); + VectorNormalize( edgenormal ); + edgedist = DotProduct( edgenormal, w->p[i] ); + //point must be not too far from the plane + dot = DotProduct( point, edgenormal ) - edgedist; + if ( dot < -MELT_ON_EPSILON || dot > MELT_ON_EPSILON ) { + continue; + } + //vector from first point of winding to the point to test + VectorSubtract( point, w->p[i], v1 ); + //vector from second point of winding to the point to test + VectorSubtract( point, w->p[j], v2 ); + //if the length of the vector is not larger than 0.5 units then + //the point is assumend to be the same as one of the winding points + if ( VectorNormalize( v1 ) < 0.5 ) { + return false; + } + if ( VectorNormalize( v2 ) < 0.5 ) { + return false; + } + //point must be between the two winding points + //(the two vectors must be directed towards each other, and on the + //same straight line) + if ( DotProduct( v1, v2 ) < -0.99 ) { + *spot = i + 1; + return true; + } //end if + } //end for + return false; +} //end of the function PointOnWinding +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int FindPlaneSeperatingWindings( winding_t *w1, winding_t *w2, vec3_t dir, + vec3_t normal, float *dist ) { + int i, i2, j, j2, n; + int sides1[3], sides2[3]; + float dist1, dist2, dot, diff; + vec3_t normal1, normal2; + vec3_t v1, v2; + + for ( i = 0; i < w1->numpoints; i++ ) + { + i2 = ( i + 1 ) % w1->numpoints; + // + VectorSubtract( w1->p[i2], w1->p[i], v1 ); + if ( VectorLength( v1 ) < 0.1 ) { + //Log_Write("FindPlaneSeperatingWindings: winding1 with degenerate edge\r\n"); + continue; + } //end if + CrossProduct( v1, dir, normal1 ); + VectorNormalize( normal1 ); + dist1 = DotProduct( normal1, w1->p[i] ); + // + for ( j = 0; j < w2->numpoints; j++ ) + { + j2 = ( j + 1 ) % w2->numpoints; + // + VectorSubtract( w2->p[j2], w2->p[j], v2 ); + if ( VectorLength( v2 ) < 0.1 ) { + //Log_Write("FindPlaneSeperatingWindings: winding2 with degenerate edge\r\n"); + continue; + } //end if + CrossProduct( v2, dir, normal2 ); + VectorNormalize( normal2 ); + dist2 = DotProduct( normal2, w2->p[j] ); + // + diff = dist1 - dist2; + if ( diff < -0.1 || diff > 0.1 ) { + dist2 = -dist2; + VectorNegate( normal2, normal2 ); + diff = dist1 - dist2; + if ( diff < -0.1 || diff > 0.1 ) { + continue; + } + } //end if + //check if the normal vectors are equal + for ( n = 0; n < 3; n++ ) + { + diff = normal1[n] - normal2[n]; + if ( diff < -0.0001 || diff > 0.0001 ) { + break; + } + } //end for + if ( n != 3 ) { + continue; + } + //check on which side of the seperating plane the points of + //the first winding are + sides1[0] = sides1[1] = sides1[2] = 0; + for ( n = 0; n < w1->numpoints; n++ ) + { + dot = DotProduct( w1->p[n], normal1 ) - dist1; + if ( dot > 0.1 ) { + sides1[0]++; + } else if ( dot < -0.1 ) { + sides1[1]++; + } else { sides1[2]++;} + } //end for + //check on which side of the seperating plane the points of + //the second winding are + sides2[0] = sides2[1] = sides2[2] = 0; + for ( n = 0; n < w2->numpoints; n++ ) + { + //used normal1 and dist1 (they are equal to normal2 and dist2) + dot = DotProduct( w2->p[n], normal1 ) - dist1; + if ( dot > 0.1 ) { + sides2[0]++; + } else if ( dot < -0.1 ) { + sides2[1]++; + } else { sides2[2]++;} + } //end for + //if the first winding has points at both sides + if ( sides1[0] && sides1[1] ) { + Log_Write( "FindPlaneSeperatingWindings: winding1 non-convex\r\n" ); + continue; + } //end if + //if the second winding has points at both sides + if ( sides2[0] && sides2[1] ) { + Log_Write( "FindPlaneSeperatingWindings: winding2 non-convex\r\n" ); + continue; + } //end if + // + if ( ( !sides1[0] && !sides1[1] ) || ( !sides2[0] && !sides2[1] ) ) { + //don't use one of the winding planes as the seperating plane + continue; + } //end if + //the windings must be at different sides of the seperating plane + if ( ( !sides1[0] && !sides2[1] ) || ( !sides1[1] && !sides2[0] ) ) { + VectorCopy( normal1, normal ); + *dist = dist1; + return true; + } //end if + } //end for + } //end for + return false; +} //end of the function FindPlaneSeperatingWindings +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +#define WCONVEX_EPSILON 0.2 + +int WindingsNonConvex( winding_t *w1, winding_t *w2, + vec3_t normal1, vec3_t normal2, + float dist1, float dist2 ) { + int i; + + if ( !w1 || !w2 ) { + return false; + } + + //check if one of the points of face1 is at the back of the plane of face2 + for ( i = 0; i < w1->numpoints; i++ ) + { + if ( DotProduct( normal2, w1->p[i] ) - dist2 > WCONVEX_EPSILON ) { + return true; + } + } //end for + //check if one of the points of face2 is at the back of the plane of face1 + for ( i = 0; i < w2->numpoints; i++ ) + { + if ( DotProduct( normal1, w2->p[i] ) - dist1 > WCONVEX_EPSILON ) { + return true; + } + } //end for + + return false; +} //end of the function WindingsNonConvex +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +/* +#define VERTEX_EPSILON 0.5 + +qboolean EqualVertexes(vec3_t v1, vec3_t v2) +{ + float diff; + + diff = v1[0] - v2[0]; + if (diff > -VERTEX_EPSILON && diff < VERTEX_EPSILON) + { + diff = v1[1] - v2[1]; + if (diff > -VERTEX_EPSILON && diff < VERTEX_EPSILON) + { + diff = v1[2] - v2[2]; + if (diff > -VERTEX_EPSILON && diff < VERTEX_EPSILON) + { + return true; + } //end if + } //end if + } //end if + return false; +} //end of the function EqualVertexes + +#define CONTINUOUS_EPSILON 0.001 + +winding_t *AAS_MergeWindings(winding_t *w1, winding_t *w2, vec3_t windingnormal) +{ + int n, i, k; + vec3_t normal, delta; + winding_t *winding, *neww; + float dist, dot; + int p1, p2; + int points[2][64]; + int numpoints[2] = {0, 0}; + int newnumpoints; + int keep[2]; + + if (!FindPlaneSeperatingWindings(w1, w2, windingnormal, normal, &dist)) return NULL; + + //for both windings + for (n = 0; n < 2; n++) + { + if (n == 0) winding = w1; + else winding = w2; + //get the points of the winding which are on the seperating plane + for (i = 0; i < winding->numpoints; i++) + { + dot = DotProduct(winding->p[i], normal) - dist; + if (dot > -ON_EPSILON && dot < ON_EPSILON) + { + //don't allow more than 64 points on the seperating plane + if (numpoints[n] >= 64) Error("AAS_MergeWindings: more than 64 points on seperating plane\n"); + points[n][numpoints[n]++] = i; + } //end if + } //end for + //there must be at least two points of each winding on the seperating plane + if (numpoints[n] < 2) return NULL; + } //end for + + //if the first point of winding1 (which is on the seperating plane) is unequal + //to the last point of winding2 (which is on the seperating plane) + if (!EqualVertexes(w1->p[points[0][0]], w2->p[points[1][numpoints[1]-1]])) + { + return NULL; + } //end if + //if the last point of winding1 (which is on the seperating plane) is unequal + //to the first point of winding2 (which is on the seperating plane) + if (!EqualVertexes(w1->p[points[0][numpoints[0]-1]], w2->p[points[1][0]])) + { + return NULL; + } //end if + // + // check slope of connected lines + // if the slopes are colinear, the point can be removed + // + //first point of winding1 which is on the seperating plane + p1 = points[0][0]; + //point before p1 + p2 = (p1 + w1->numpoints - 1) % w1->numpoints; + VectorSubtract(w1->p[p1], w1->p[p2], delta); + CrossProduct(windingnormal, delta, normal); + VectorNormalize(normal, normal); + + //last point of winding2 which is on the seperating plane + p1 = points[1][numpoints[1]-1]; + //point after p1 + p2 = (p1 + 1) % w2->numpoints; + VectorSubtract(w2->p[p2], w2->p[p1], delta); + dot = DotProduct(delta, normal); + if (dot > CONTINUOUS_EPSILON) return NULL; //merging would create a non-convex polygon + keep[0] = (qboolean)(dot < -CONTINUOUS_EPSILON); + + //first point of winding2 which is on the seperating plane + p1 = points[1][0]; + //point before p1 + p2 = (p1 + w2->numpoints - 1) % w2->numpoints; + VectorSubtract(w2->p[p1], w2->p[p2], delta); + CrossProduct(windingnormal, delta, normal); + VectorNormalize(normal, normal); + + //last point of winding1 which is on the seperating plane + p1 = points[0][numpoints[0]-1]; + //point after p1 + p2 = (p1 + 1) % w1->numpoints; + VectorSubtract(w1->p[p2], w1->p[p1], delta); + dot = DotProduct(delta, normal); + if (dot > CONTINUOUS_EPSILON) return NULL; //merging would create a non-convex polygon + keep[1] = (qboolean)(dot < -CONTINUOUS_EPSILON); + + //number of points on the new winding + newnumpoints = w1->numpoints - numpoints[0] + w2->numpoints - numpoints[1] + 2; + //allocate the winding + neww = AllocWinding(newnumpoints); + neww->numpoints = newnumpoints; + //copy all the points + k = 0; + //for both windings + for (n = 0; n < 2; n++) + { + if (n == 0) winding = w1; + else winding = w2; + //copy the points of the winding starting with the last point on the + //seperating plane and ending before the first point on the seperating plane + for (i = points[n][numpoints[n]-1]; i != points[n][0]; i = (i+1)%winding->numpoints) + { + if (k >= newnumpoints) + { + Log_Print("numpoints[0] = %d\n", numpoints[0]); + Log_Print("numpoints[1] = %d\n", numpoints[1]); + Error("AAS_MergeWindings: k = %d >= newnumpoints = %d\n", k, newnumpoints); + } //end if + VectorCopy(winding->p[i], neww->p[k]); + k++; + } //end for + } //end for + RemoveEqualPoints(neww); + if (!WindingIsOk(neww, 1)) + { + Log_Print("AAS_MergeWindings: winding not ok after merging\n"); + FreeWinding(neww); + return NULL; + } //end if + return neww; +} //end of the function AAS_MergeWindings*/ +//#endif //ME diff --git a/Projects/Android/jni/rtcw/src/bspc/l_poly.h b/Projects/Android/jni/rtcw/src/bspc/l_poly.h new file mode 100644 index 0000000..028fc22 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/bspc/l_poly.h @@ -0,0 +1,136 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +//=========================================================================== +// +// Name: l_poly.h +// Function: +// Programmer: id Sofware +// Mr Elusive (MrElusive@demigod.demon.nl) +// Last update: 1997-12-04 +// Tab Size: 3 +//=========================================================================== + +//a winding gives the bounding points of a convex polygon +typedef struct +{ + int numpoints; + vec3_t p[4]; //variable sized +} winding_t; + +#define MAX_POINTS_ON_WINDING 96 + +//you can define on_epsilon in the makefile as tighter +#ifndef ON_EPSILON +#define ON_EPSILON 0.1 +#endif +//winding errors +#define WE_NONE 0 +#define WE_NOTENOUGHPOINTS 1 +#define WE_SMALLAREA 2 +#define WE_POINTBOGUSRANGE 3 +#define WE_POINTOFFPLANE 4 +#define WE_DEGENERATEEDGE 5 +#define WE_NONCONVEX 6 + +//allocates a winding +winding_t *AllocWinding( int points ); +//returns the area of the winding +vec_t WindingArea( winding_t *w ); +//gives the center of the winding +void WindingCenter( winding_t *w, vec3_t center ); +//clips the given winding to the given plane and gives the front +//and back part of the clipped winding +void ClipWindingEpsilon( winding_t *in, vec3_t normal, vec_t dist, + vec_t epsilon, winding_t **front, winding_t **back ); +//returns the fragment of the given winding that is on the front +//side of the cliping plane. The original is freed. +winding_t *ChopWinding( winding_t *in, vec3_t normal, vec_t dist ); +//returns a copy of the given winding +winding_t *CopyWinding( winding_t *w ); +//returns the reversed winding of the given one +winding_t *ReverseWinding( winding_t *w ); +//returns a base winding for the given plane +winding_t *BaseWindingForPlane( vec3_t normal, vec_t dist ); +//checks the winding for errors +void CheckWinding( winding_t *w ); +//returns the plane normal and dist the winding is in +void WindingPlane( winding_t *w, vec3_t normal, vec_t *dist ); +//removes colinear points from the winding +void RemoveColinearPoints( winding_t *w ); +//returns on which side of the plane the winding is situated +int WindingOnPlaneSide( winding_t *w, vec3_t normal, vec_t dist ); +//frees the winding +void FreeWinding( winding_t *w ); +//gets the bounds of the winding +void WindingBounds( winding_t *w, vec3_t mins, vec3_t maxs ); +//chops the winding with the given plane, the original winding is freed if clipped +void ChopWindingInPlace( winding_t **w, vec3_t normal, vec_t dist, vec_t epsilon ); +//prints the winding points on STDOUT +void pw( winding_t *w ); +//try to merge the two windings which are in the given plane +//the original windings are undisturbed +//the merged winding is returned when merging was possible +//NULL is returned otherwise +winding_t *TryMergeWinding( winding_t *f1, winding_t *f2, vec3_t planenormal ); +//brute force winding merging... creates a convex winding out of +//the two whatsoever +winding_t *MergeWindings( winding_t *w1, winding_t *w2, vec3_t planenormal ); + +//#ifdef ME +void ResetWindings( void ); +//returns the amount of winding memory +int WindingMemory( void ); +int WindingPeakMemory( void ); +int ActiveWindings( void ); +//returns the winding error string +char *WindingErrorString( void ); +//returns one of the WE_ flags when the winding has errors +int WindingError( winding_t *w ); +//removes equal points from the winding +void RemoveEqualPoints( winding_t *w, float epsilon ); +//returns a winding with a point added at the given spot to the +//given winding, original winding is NOT freed +winding_t *AddWindingPoint( winding_t *w, vec3_t point, int spot ); +//returns true if the point is on one of the winding 'edges' +//when the point is on one of the edged the number of the first +//point of the edge is stored in 'spot' +int PointOnWinding( winding_t *w, vec3_t normal, float dist, vec3_t point, int *spot ); +//find a plane seperating the two windings +//true is returned when the windings area adjacent +//the seperating plane normal and distance area stored in 'normal' and 'dist' +//this plane will contain both the piece of common edge of the two windings +//and the vector 'dir' +int FindPlaneSeperatingWindings( winding_t *w1, winding_t *w2, vec3_t dir, + vec3_t normal, float *dist ); +// +int WindingsNonConvex( winding_t *w1, winding_t *w2, + vec3_t normal1, vec3_t normal2, + float dist1, float dist2 ); +//#endif //ME + diff --git a/Projects/Android/jni/rtcw/src/bspc/l_qfiles.c b/Projects/Android/jni/rtcw/src/bspc/l_qfiles.c new file mode 100644 index 0000000..6d75e40 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/bspc/l_qfiles.c @@ -0,0 +1,702 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +//=========================================================================== +// +// Name: l_qfiles.h +// Function: - +// Programmer: Mr Elusive +// Last update: 1999-11-29 +// Tab Size: 3 +//=========================================================================== + +#if defined( WIN32 ) | defined( _WIN32 ) +#include +#include +#include +#else +#include +#include +#include +#endif + +#include "qbsp.h" +#define stricmp strcasecmp + +//file extensions with their type +typedef struct qfile_exttype_s +{ + char *extension; + int type; +} qfile_exttyp_t; + +qfile_exttyp_t quakefiletypes[] = +{ + {QFILEEXT_UNKNOWN, QFILETYPE_UNKNOWN}, + {QFILEEXT_PAK, QFILETYPE_PAK}, + {QFILEEXT_PK3, QFILETYPE_PK3}, + {QFILEEXT_SIN, QFILETYPE_PAK}, + {QFILEEXT_BSP, QFILETYPE_BSP}, + {QFILEEXT_MAP, QFILETYPE_MAP}, + {QFILEEXT_MDL, QFILETYPE_MDL}, + {QFILEEXT_MD2, QFILETYPE_MD2}, + {QFILEEXT_MD3, QFILETYPE_MD3}, + {QFILEEXT_WAL, QFILETYPE_WAL}, + {QFILEEXT_WAV, QFILETYPE_WAV}, + {QFILEEXT_AAS, QFILETYPE_AAS}, + {NULL, 0} +}; + +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int QuakeFileExtensionType( char *extension ) { + int i; + + for ( i = 0; quakefiletypes[i].extension; i++ ) + { + if ( !stricmp( extension, quakefiletypes[i].extension ) ) { + return quakefiletypes[i].type; + } //end if + } //end for + return QFILETYPE_UNKNOWN; +} //end of the function QuakeFileExtensionType +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +char *QuakeFileTypeExtension( int type ) { + int i; + + for ( i = 0; quakefiletypes[i].extension; i++ ) + { + if ( quakefiletypes[i].type == type ) { + return quakefiletypes[i].extension; + } //end if + } //end for + return QFILEEXT_UNKNOWN; +} //end of the function QuakeFileExtension +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int QuakeFileType( char *filename ) { + char ext[_MAX_PATH] = "."; + + ExtractFileExtension( filename, ext + 1 ); + return QuakeFileExtensionType( ext ); +} //end of the function QuakeFileTypeFromFileName +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +char *StringContains( char *str1, char *str2, int casesensitive ) { + int len, i, j; + + len = strlen( str1 ) - strlen( str2 ); + for ( i = 0; i <= len; i++, str1++ ) + { + for ( j = 0; str2[j]; j++ ) + { + if ( casesensitive ) { + if ( str1[j] != str2[j] ) { + break; + } + } //end if + else + { + if ( toupper( str1[j] ) != toupper( str2[j] ) ) { + break; + } + } //end else + } //end for + if ( !str2[j] ) { + return str1; + } + } //end for + return NULL; +} //end of the function StringContains +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int FileFilter( char *filter, char *filename, int casesensitive ) { + char buf[1024]; + char *ptr; + int i, found; + + while ( *filter ) + { + if ( *filter == '*' ) { + filter++; + for ( i = 0; *filter; i++ ) + { + if ( *filter == '*' || *filter == '?' ) { + break; + } + buf[i] = *filter; + filter++; + } //end for + buf[i] = '\0'; + if ( strlen( buf ) ) { + ptr = StringContains( filename, buf, casesensitive ); + if ( !ptr ) { + return false; + } + filename = ptr + strlen( buf ); + } //end if + } //end if + else if ( *filter == '?' ) { + filter++; + filename++; + } //end else if + else if ( *filter == '[' && *( filter + 1 ) == '[' ) { + filter++; + } //end if + else if ( *filter == '[' ) { + filter++; + found = false; + while ( *filter && !found ) + { + if ( *filter == ']' && *( filter + 1 ) != ']' ) { + break; + } + if ( *( filter + 1 ) == '-' && *( filter + 2 ) && ( *( filter + 2 ) != ']' || *( filter + 3 ) == ']' ) ) { + if ( casesensitive ) { + if ( *filename >= *filter && *filename <= *( filter + 2 ) ) { + found = true; + } + } //end if + else + { + if ( toupper( *filename ) >= toupper( *filter ) && + toupper( *filename ) <= toupper( *( filter + 2 ) ) ) { + found = true; + } + } //end else + filter += 3; + } //end if + else + { + if ( casesensitive ) { + if ( *filter == *filename ) { + found = true; + } + } //end if + else + { + if ( toupper( *filter ) == toupper( *filename ) ) { + found = true; + } + } //end else + filter++; + } //end else + } //end while + if ( !found ) { + return false; + } + while ( *filter ) + { + if ( *filter == ']' && *( filter + 1 ) != ']' ) { + break; + } + filter++; + } //end while + filter++; + filename++; + } //end else if + else + { + if ( casesensitive ) { + if ( *filter != *filename ) { + return false; + } + } //end if + else + { + if ( toupper( *filter ) != toupper( *filename ) ) { + return false; + } + } //end else + filter++; + filename++; + } //end else + } //end while + return true; +} //end of the function FileFilter +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +quakefile_t *FindQuakeFilesInZip( char *zipfile, char *filter ) { + unzFile uf; + int err; + unz_global_info gi; + char filename_inzip[MAX_PATH]; + unz_file_info file_info; + int i; + quakefile_t *qfiles, *lastqf, *qf; + + uf = unzOpen( zipfile ); + err = unzGetGlobalInfo( uf, &gi ); + + if ( err != UNZ_OK ) { + return NULL; + } + + unzGoToFirstFile( uf ); + + qfiles = NULL; + lastqf = NULL; + for ( i = 0; i < gi.number_entry; i++ ) + { + err = unzGetCurrentFileInfo( uf, &file_info, filename_inzip, sizeof( filename_inzip ), NULL,0,NULL,0 ); + if ( err != UNZ_OK ) { + break; + } + + ConvertPath( filename_inzip ); + if ( FileFilter( filter, filename_inzip, false ) ) { + qf = malloc( sizeof( quakefile_t ) ); + if ( !qf ) { + Error( "out of memory" ); + } + memset( qf, 0, sizeof( quakefile_t ) ); + strcpy( qf->pakfile, zipfile ); + strcpy( qf->filename, zipfile ); + strcpy( qf->origname, filename_inzip ); + qf->zipfile = true; + //memcpy( &buildBuffer[i].zipfileinfo, (unz_s*)uf, sizeof(unz_s)); + memcpy( &qf->zipinfo, (unz_s*)uf, sizeof( unz_s ) ); + qf->offset = 0; + qf->length = file_info.uncompressed_size; + qf->type = QuakeFileType( filename_inzip ); + //add the file ot the list + qf->next = NULL; + if ( lastqf ) { + lastqf->next = qf; + } else { qfiles = qf;} + lastqf = qf; + } //end if + unzGoToNextFile( uf ); + } //end for + + unzClose( uf ); + + return qfiles; +} //end of the function FindQuakeFilesInZip +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +quakefile_t *FindQuakeFilesInPak( char *pakfile, char *filter ) { + FILE *fp; + dpackheader_t packheader; + dsinpackfile_t *packfiles; + dpackfile_t *idpackfiles; + quakefile_t *qfiles, *lastqf, *qf; + int numpackdirs, i; + + qfiles = NULL; + lastqf = NULL; + //open the pak file + fp = fopen( pakfile, "rb" ); + if ( !fp ) { + Warning( "can't open pak file %s", pakfile ); + return NULL; + } //end if + //read pak header, check for valid pak id and seek to the dir entries + if ( ( fread( &packheader, 1, sizeof( dpackheader_t ), fp ) != sizeof( dpackheader_t ) ) + || ( packheader.ident != IDPAKHEADER && packheader.ident != SINPAKHEADER ) + || ( fseek( fp, LittleLong( packheader.dirofs ), SEEK_SET ) ) + ) { + fclose( fp ); + Warning( "invalid pak file %s", pakfile ); + return NULL; + } //end if + //if it is a pak file from id software + if ( packheader.ident == IDPAKHEADER ) { + //number of dir entries in the pak file + numpackdirs = LittleLong( packheader.dirlen ) / sizeof( dpackfile_t ); + idpackfiles = (dpackfile_t *) malloc( numpackdirs * sizeof( dpackfile_t ) ); + if ( !idpackfiles ) { + Error( "out of memory" ); + } + //read the dir entry + if ( fread( idpackfiles, sizeof( dpackfile_t ), numpackdirs, fp ) != numpackdirs ) { + fclose( fp ); + free( idpackfiles ); + Warning( "can't read the Quake pak file dir entries from %s", pakfile ); + return NULL; + } //end if + fclose( fp ); + //convert to sin pack files + packfiles = (dsinpackfile_t *) malloc( numpackdirs * sizeof( dsinpackfile_t ) ); + if ( !packfiles ) { + Error( "out of memory" ); + } + for ( i = 0; i < numpackdirs; i++ ) + { + strcpy( packfiles[i].name, idpackfiles[i].name ); + packfiles[i].filepos = LittleLong( idpackfiles[i].filepos ); + packfiles[i].filelen = LittleLong( idpackfiles[i].filelen ); + } //end for + free( idpackfiles ); + } //end if + else //its a Sin pack file + { + //number of dir entries in the pak file + numpackdirs = LittleLong( packheader.dirlen ) / sizeof( dsinpackfile_t ); + packfiles = (dsinpackfile_t *) malloc( numpackdirs * sizeof( dsinpackfile_t ) ); + if ( !packfiles ) { + Error( "out of memory" ); + } + //read the dir entry + if ( fread( packfiles, sizeof( dsinpackfile_t ), numpackdirs, fp ) != numpackdirs ) { + fclose( fp ); + free( packfiles ); + Warning( "can't read the Sin pak file dir entries from %s", pakfile ); + return NULL; + } //end if + fclose( fp ); + for ( i = 0; i < numpackdirs; i++ ) + { + packfiles[i].filepos = LittleLong( packfiles[i].filepos ); + packfiles[i].filelen = LittleLong( packfiles[i].filelen ); + } //end for + } //end else + // + for ( i = 0; i < numpackdirs; i++ ) + { + ConvertPath( packfiles[i].name ); + if ( FileFilter( filter, packfiles[i].name, false ) ) { + qf = malloc( sizeof( quakefile_t ) ); + if ( !qf ) { + Error( "out of memory" ); + } + memset( qf, 0, sizeof( quakefile_t ) ); + strcpy( qf->pakfile, pakfile ); + strcpy( qf->filename, pakfile ); + strcpy( qf->origname, packfiles[i].name ); + qf->zipfile = false; + qf->offset = packfiles[i].filepos; + qf->length = packfiles[i].filelen; + qf->type = QuakeFileType( packfiles[i].name ); + //add the file ot the list + qf->next = NULL; + if ( lastqf ) { + lastqf->next = qf; + } else { qfiles = qf;} + lastqf = qf; + } //end if + } //end for + free( packfiles ); + return qfiles; +} //end of the function FindQuakeFilesInPak +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +quakefile_t *FindQuakeFilesWithPakFilter( char *pakfilter, char *filter ) { +#if defined( WIN32 ) | defined( _WIN32 ) + WIN32_FIND_DATA filedata; + HWND handle; + struct _stat statbuf; +#else + glob_t globbuf; + struct stat statbuf; + int j; +#endif + quakefile_t *qfiles, *lastqf, *qf; + char pakfile[_MAX_PATH], filename[_MAX_PATH], *str; + //int done; //TTimo: unused + + qfiles = NULL; + lastqf = NULL; + if ( pakfilter && strlen( pakfilter ) ) { +#if defined( WIN32 ) | defined( _WIN32 ) + handle = FindFirstFile( pakfilter, &filedata ); + done = ( handle == INVALID_HANDLE_VALUE ); + while ( !done ) + { + _splitpath( pakfilter, pakfile, NULL, NULL, NULL ); + _splitpath( pakfilter, NULL, &pakfile[strlen( pakfile )], NULL, NULL ); + AppendPathSeperator( pakfile, _MAX_PATH ); + strcat( pakfile, filedata.cFileName ); + _stat( pakfile, &statbuf ); +#else + glob( pakfilter, 0, NULL, &globbuf ); + for ( j = 0; j < globbuf.gl_pathc; j++ ) + { + strcpy( pakfile, globbuf.gl_pathv[j] ); + stat( pakfile, &statbuf ); +#endif + //if the file with .pak or .pk3 is a folder + if ( statbuf.st_mode & S_IFDIR ) { + strcpy( filename, pakfilter ); + AppendPathSeperator( filename, _MAX_PATH ); + strcat( filename, filter ); + qf = FindQuakeFilesWithPakFilter( NULL, filename ); + if ( lastqf ) { + lastqf->next = qf; + } else { qfiles = qf;} + lastqf = qf; + while ( lastqf->next ) lastqf = lastqf->next; + } //end if + else + { +#if defined( WIN32 ) | defined( _WIN32 ) + str = StringContains( pakfile, ".pk3", false ); +#else + str = StringContains( pakfile, ".pk3", true ); +#endif + if ( str && str == pakfile + strlen( pakfile ) - strlen( ".pk3" ) ) { + qf = FindQuakeFilesInZip( pakfile, filter ); + } //end if + else + { + qf = FindQuakeFilesInPak( pakfile, filter ); + } //end else + // + if ( qf ) { + if ( lastqf ) { + lastqf->next = qf; + } else { qfiles = qf;} + lastqf = qf; + while ( lastqf->next ) lastqf = lastqf->next; + } //end if + } //end else + // +#if defined( WIN32 ) | defined( _WIN32 ) + //find the next file + done = !FindNextFile( handle, &filedata ); + } //end while +#else + } //end for + globfree( &globbuf ); +#endif + } //end if + else + { +#if defined( WIN32 ) | defined( _WIN32 ) + handle = FindFirstFile( filter, &filedata ); + done = ( handle == INVALID_HANDLE_VALUE ); + while ( !done ) + { + _splitpath( filter, filename, NULL, NULL, NULL ); + _splitpath( filter, NULL, &filename[strlen( filename )], NULL, NULL ); + AppendPathSeperator( filename, _MAX_PATH ); + strcat( filename, filedata.cFileName ); +#else + glob( filter, 0, NULL, &globbuf ); + for ( j = 0; j < globbuf.gl_pathc; j++ ) + { + strcpy( filename, globbuf.gl_pathv[j] ); +#endif + // + qf = malloc( sizeof( quakefile_t ) ); + if ( !qf ) { + Error( "out of memory" ); + } + memset( qf, 0, sizeof( quakefile_t ) ); + strcpy( qf->pakfile, "" ); + strcpy( qf->filename, filename ); + strcpy( qf->origname, filename ); + qf->offset = 0; + qf->length = 0; + qf->type = QuakeFileType( filename ); + //add the file ot the list + qf->next = NULL; + if ( lastqf ) { + lastqf->next = qf; + } else { qfiles = qf;} + lastqf = qf; +#if defined( WIN32 ) | defined( _WIN32 ) + //find the next file + done = !FindNextFile( handle, &filedata ); + } //end while +#else + } //end for + globfree( &globbuf ); +#endif + } //end else + return qfiles; +} //end of the function FindQuakeFilesWithPakFilter +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +quakefile_t *FindQuakeFiles( char *filter ) { + char *str; + char newfilter[_MAX_PATH]; + char pakfilter[_MAX_PATH]; + char filefilter[_MAX_PATH]; + + strcpy( newfilter, filter ); + ConvertPath( newfilter ); + strcpy( pakfilter, newfilter ); + + str = StringContains( pakfilter, ".pak", false ); + if ( !str ) { + str = StringContains( pakfilter, ".pk3", false ); + } + + if ( str ) { + str += strlen( ".pak" ); + if ( *str ) { + *str++ = '\0'; + while ( *str == '\\' || *str == '/' ) str++; + strcpy( filefilter, str ); + return FindQuakeFilesWithPakFilter( pakfilter, filefilter ); + } //end if + } //end else + return FindQuakeFilesWithPakFilter( NULL, newfilter ); +} //end of the function FindQuakeFiles +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int LoadQuakeFile( quakefile_t *qf, void **bufferptr ) { + FILE *fp; + void *buffer; + int length; + unzFile zf; + + if ( qf->zipfile ) { + //open the zip file + zf = unzOpen( qf->pakfile ); + //set the file pointer + qf->zipinfo.file = ( (unz_s *) zf )->file; + //open the Quake file in the zip file + unzOpenCurrentFile( &qf->zipinfo ); + //allocate memory for the buffer + length = qf->length; + buffer = GetMemory( length + 1 ); + //read the Quake file from the zip file + length = unzReadCurrentFile( &qf->zipinfo, buffer, length ); + //close the Quake file in the zip file + unzCloseCurrentFile( &qf->zipinfo ); + //close the zip file + unzClose( zf ); + + *bufferptr = buffer; + return length; + } //end if + else + { + fp = SafeOpenRead( qf->filename ); + if ( qf->offset ) { + fseek( fp, qf->offset, SEEK_SET ); + } + length = qf->length; + if ( !length ) { + length = Q_filelength( fp ); + } + buffer = GetMemory( length + 1 ); + ( (char *)buffer )[length] = 0; + SafeRead( fp, buffer, length ); + fclose( fp ); + + *bufferptr = buffer; + return length; + } //end else +} //end of the function LoadQuakeFile +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int ReadQuakeFile( quakefile_t *qf, void *buffer, int offset, int length ) { + FILE *fp; + int read; + unzFile zf; + char tmpbuf[1024]; + + if ( qf->zipfile ) { + //open the zip file + zf = unzOpen( qf->pakfile ); + //set the file pointer + qf->zipinfo.file = ( (unz_s *) zf )->file; + //open the Quake file in the zip file + unzOpenCurrentFile( &qf->zipinfo ); + // + while ( offset > 0 ) + { + read = offset; + if ( read > sizeof( tmpbuf ) ) { + read = sizeof( tmpbuf ); + } + unzReadCurrentFile( &qf->zipinfo, tmpbuf, read ); + offset -= read; + } //end while + //read the Quake file from the zip file + length = unzReadCurrentFile( &qf->zipinfo, buffer, length ); + //close the Quake file in the zip file + unzCloseCurrentFile( &qf->zipinfo ); + //close the zip file + unzClose( zf ); + + return length; + } //end if + else + { + fp = SafeOpenRead( qf->filename ); + if ( qf->offset ) { + fseek( fp, qf->offset, SEEK_SET ); + } + if ( offset ) { + fseek( fp, offset, SEEK_CUR ); + } + SafeRead( fp, buffer, length ); + fclose( fp ); + + return length; + } //end else +} //end of the function ReadQuakeFile diff --git a/Projects/Android/jni/rtcw/src/bspc/l_qfiles.h b/Projects/Android/jni/rtcw/src/bspc/l_qfiles.h new file mode 100644 index 0000000..7b331ad --- /dev/null +++ b/Projects/Android/jni/rtcw/src/bspc/l_qfiles.h @@ -0,0 +1,106 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +//=========================================================================== +// +// Name: l_qfiles.h +// Function: - +// Programmer: Mr Elusive +// Last update: 1999-12-01 +// Tab Size: 3 +//=========================================================================== + +#include "../qcommon/unzip.h" + +#define QFILETYPE_UNKNOWN 0x8000 +#define QFILETYPE_PAK 0x0001 +#define QFILETYPE_PK3 0x0002 +#define QFILETYPE_BSP 0x0004 +#define QFILETYPE_MAP 0x0008 +#define QFILETYPE_MDL 0x0010 +#define QFILETYPE_MD2 0x0020 +#define QFILETYPE_MD3 0x0040 +#define QFILETYPE_WAL 0x0080 +#define QFILETYPE_WAV 0x0100 +#define QFILETYPE_AAS 0x4000 + +#define QFILEEXT_UNKNOWN "" +#define QFILEEXT_PAK ".PAK" +#define QFILEEXT_PK3 ".PK3" +#define QFILEEXT_SIN ".SIN" +#define QFILEEXT_BSP ".BSP" +#define QFILEEXT_MAP ".MAP" +#define QFILEEXT_MDL ".MDL" +#define QFILEEXT_MD2 ".MD2" +#define QFILEEXT_MD3 ".MD3" +#define QFILEEXT_WAL ".WAL" +#define QFILEEXT_WAV ".WAV" +#define QFILEEXT_AAS ".AAS" + +//maximum path length +#ifndef _MAX_PATH + #define _MAX_PATH 1024 +#endif + +//for Sin packs +#define MAX_PAK_FILENAME_LENGTH 120 +#define SINPAKHEADER ( ( 'K' << 24 ) + ( 'A' << 16 ) + ( 'P' << 8 ) + 'S' ) + +typedef struct +{ + char name[MAX_PAK_FILENAME_LENGTH]; + int filepos, filelen; +} dsinpackfile_t; + +typedef struct quakefile_s +{ + char pakfile[_MAX_PATH]; + char filename[_MAX_PATH]; + char origname[_MAX_PATH]; + int zipfile; + int type; + int offset; + int length; + unz_s zipinfo; + struct quakefile_s *next; +} quakefile_t; + +//returns the file extension for the given type +char *QuakeFileTypeExtension( int type ); +//returns the file type for the given extension +int QuakeFileExtensionType( char *extension ); +//return the Quake file type for the given file +int QuakeFileType( char *filename ); +//returns true if the filename complies to the filter +int FileFilter( char *filter, char *filename, int casesensitive ); +//find Quake files using the given filter +quakefile_t *FindQuakeFiles( char *filter ); +//load the given Quake file, returns the length of the file +int LoadQuakeFile( quakefile_t *qf, void **bufferptr ); +//read part of a Quake file into the buffer +int ReadQuakeFile( quakefile_t *qf, void *buffer, int offset, int length ); diff --git a/Projects/Android/jni/rtcw/src/bspc/l_threads.c b/Projects/Android/jni/rtcw/src/bspc/l_threads.c new file mode 100644 index 0000000..f36b5cc --- /dev/null +++ b/Projects/Android/jni/rtcw/src/bspc/l_threads.c @@ -0,0 +1,1528 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +//=========================================================================== +// +// Name: l_threads.c +// Function: multi-threading +// Programmer: Mr Elusive (MrElusive@demigod.demon.nl) +// Last update: 1999-05-14 +// Tab Size: 3 +//=========================================================================== + +#include "l_cmd.h" +#include "l_threads.h" +#include "l_log.h" +#include "l_mem.h" + +#define MAX_THREADS 64 + +//#define THREAD_DEBUG + +int dispatch; +int workcount; +int oldf; +qboolean pacifier; +qboolean threaded; +void ( *workfunction )( int ); + +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int GetThreadWork( void ) { + int r; + int f; + + ThreadLock(); + + if ( dispatch == workcount ) { + ThreadUnlock(); + return -1; + } + + f = 10 * dispatch / workcount; + if ( f != oldf ) { + oldf = f; + if ( pacifier ) { + printf( "%i...", f ); + } + } //end if + + r = dispatch; + dispatch++; + ThreadUnlock(); + + return r; +} //end of the function GetThreadWork +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void ThreadWorkerFunction( int threadnum ) { + int work; + + while ( 1 ) + { + work = GetThreadWork(); + if ( work == -1 ) { + break; + } +//printf ("thread %i, work %i\n", threadnum, work); + workfunction( work ); + } //end while +} //end of the function ThreadWorkerFunction +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void RunThreadsOnIndividual( int workcnt, qboolean showpacifier, void ( *func )(int) ) { + if ( numthreads == -1 ) { + ThreadSetDefault(); + } + workfunction = func; + RunThreadsOn( workcnt, showpacifier, ThreadWorkerFunction ); +} //end of the function RunThreadsOnIndividual + + +//=================================================================== +// +// WIN32 +// +//=================================================================== + +#if defined( WIN32 ) || defined( _WIN32 ) + +#define USED + +#include + +typedef struct thread_s +{ + HANDLE handle; + int threadid; + int id; + struct thread_s *next; +} thread_t; + +thread_t *firstthread; +thread_t *lastthread; +int currentnumthreads; +int currentthreadid; + +int numthreads = 1; +CRITICAL_SECTION crit; +HANDLE semaphore; +static int enter; +static int numwaitingthreads = 0; + +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void ThreadSetDefault( void ) { + SYSTEM_INFO info; + + if ( numthreads == -1 ) { // not set manually + GetSystemInfo( &info ); + numthreads = info.dwNumberOfProcessors; + if ( numthreads < 1 || numthreads > 32 ) { + numthreads = 1; + } + } //end if + qprintf( "%i threads\n", numthreads ); +} //end of the function ThreadSetDefault +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void ThreadLock( void ) { + if ( !threaded ) { + Error( "ThreadLock: !threaded" ); + return; + } //end if + EnterCriticalSection( &crit ); + if ( enter ) { + Error( "Recursive ThreadLock\n" ); + } + enter = 1; +} //end of the function ThreadLock +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void ThreadUnlock( void ) { + if ( !threaded ) { + Error( "ThreadUnlock: !threaded" ); + return; + } //end if + if ( !enter ) { + Error( "ThreadUnlock without lock\n" ); + } + enter = 0; + LeaveCriticalSection( &crit ); +} //end of the function ThreadUnlock +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void ThreadSetupLock( void ) { + Log_Print( "Win32 multi-threading\n" ); + InitializeCriticalSection( &crit ); + threaded = true; //Stupid me... forgot this!!! + currentnumthreads = 0; + currentthreadid = 0; +} //end of the function ThreadInitLock +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void ThreadShutdownLock( void ) { + DeleteCriticalSection( &crit ); + threaded = false; //Stupid me... forgot this!!! +} //end of the function ThreadShutdownLock +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void ThreadSetupSemaphore( void ) { + semaphore = CreateSemaphore( NULL, 0, 99999999, "bspc" ); +} //end of the function ThreadSetupSemaphore +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void ThreadShutdownSemaphore( void ) { +} //end of the function ThreadShutdownSemaphore +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void ThreadSemaphoreWait( void ) { + WaitForSingleObject( semaphore, INFINITE ); +} //end of the function ThreadSemaphoreWait +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void ThreadSemaphoreIncrease( int count ) { + ReleaseSemaphore( semaphore, count, NULL ); +} //end of the function ThreadSemaphoreIncrease +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void RunThreadsOn( int workcnt, qboolean showpacifier, void ( *func )(int) ) { + int threadid[MAX_THREADS]; + HANDLE threadhandle[MAX_THREADS]; + int i; + int start, end; + + Log_Print( "Win32 multi-threading\n" ); + start = I_FloatTime(); + dispatch = 0; + workcount = workcnt; + oldf = -1; + pacifier = showpacifier; + threaded = true; + + if ( numthreads == -1 ) { + ThreadSetDefault(); + } + + if ( numthreads < 1 || numthreads > MAX_THREADS ) { + numthreads = 1; + } + // + // run threads in parallel + // + InitializeCriticalSection( &crit ); + + numwaitingthreads = 0; + + if ( numthreads == 1 ) { // use same thread + func( 0 ); + } //end if + else + { +// printf("starting %d threads\n", numthreads); + for ( i = 0; i < numthreads; i++ ) + { + threadhandle[i] = CreateThread( + NULL, // LPSECURITY_ATTRIBUTES lpsa, + 0, // DWORD cbStack, + (LPTHREAD_START_ROUTINE)func, // LPTHREAD_START_ROUTINE lpStartAddr, + (LPVOID)i, // LPVOID lpvThreadParm, + 0, // DWORD fdwCreate, + &threadid[i] ); +// printf("started thread %d\n", i); + } //end for + + for ( i = 0; i < numthreads; i++ ) + WaitForSingleObject( threadhandle[i], INFINITE ); + } //end else + DeleteCriticalSection( &crit ); + + threaded = false; + end = I_FloatTime(); + if ( pacifier ) { + printf( " (%i)\n", end - start ); + } +} //end of the function RunThreadsOn +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AddThread( void ( *func )(int) ) { + thread_t *thread; + + if ( numthreads == 1 ) { + if ( currentnumthreads >= numthreads ) { + return; + } + currentnumthreads++; + func( -1 ); + currentnumthreads--; + } //end if + else + { + ThreadLock(); + if ( currentnumthreads >= numthreads ) { + ThreadUnlock(); + return; + } //end if + //allocate new thread + thread = GetMemory( sizeof( thread_t ) ); + if ( !thread ) { + Error( "can't allocate memory for thread\n" ); + } + + // + thread->threadid = currentthreadid; + thread->handle = CreateThread( + NULL, // LPSECURITY_ATTRIBUTES lpsa, + 0, // DWORD cbStack, + (LPTHREAD_START_ROUTINE)func, // LPTHREAD_START_ROUTINE lpStartAddr, + (LPVOID) thread->threadid, // LPVOID lpvThreadParm, + 0, // DWORD fdwCreate, + &thread->id ); + + //add the thread to the end of the list + thread->next = NULL; + if ( lastthread ) { + lastthread->next = thread; + } else { firstthread = thread;} + lastthread = thread; + // +#ifdef THREAD_DEBUG + qprintf( "added thread with id %d\n", thread->threadid ); +#endif //THREAD_DEBUG + // + currentnumthreads++; + currentthreadid++; + // + ThreadUnlock(); + } //end else +} //end of the function AddThread +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void RemoveThread( int threadid ) { + thread_t *thread, *last; + + //if a single thread + if ( threadid == -1 ) { + return; + } + // + ThreadLock(); + last = NULL; + for ( thread = firstthread; thread; thread = thread->next ) + { + if ( thread->threadid == threadid ) { + if ( last ) { + last->next = thread->next; + } else { firstthread = thread->next;} + if ( !thread->next ) { + lastthread = last; + } + // + FreeMemory( thread ); + currentnumthreads--; +#ifdef THREAD_DEBUG + qprintf( "removed thread with id %d\n", threadid ); +#endif //THREAD_DEBUG + break; + } //end if + last = thread; + } //end if + if ( !thread ) { + Error( "couldn't find thread with id %d", threadid ); + } + ThreadUnlock(); +} //end of the function RemoveThread +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void WaitForAllThreadsFinished( void ) { + HANDLE handle; + + ThreadLock(); + while ( firstthread ) + { + handle = firstthread->handle; + ThreadUnlock(); + + WaitForSingleObject( handle, INFINITE ); + + ThreadLock(); + } //end while + ThreadUnlock(); +} //end of the function WaitForAllThreadsFinished +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int GetNumThreads( void ) { + return currentnumthreads; +} //end of the function GetNumThreads + +#endif + + +//=================================================================== +// +// OSF1 +// +//=================================================================== + +#if defined( __osf__ ) + +#define USED + +#include + +typedef struct thread_s +{ + pthread_t thread; + int threadid; + int id; + struct thread_s *next; +} thread_t; + +thread_t *firstthread; +thread_t *lastthread; +int currentnumthreads; +int currentthreadid; + +int numthreads = 1; +pthread_mutex_t my_mutex; +pthread_attr_t attrib; +static int enter; +static int numwaitingthreads = 0; + + +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void ThreadSetDefault( void ) { + if ( numthreads == -1 ) { // not set manually + numthreads = 1; + } //end if + qprintf( "%i threads\n", numthreads ); +} //end of the function ThreadSetDefault +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void ThreadLock( void ) { + if ( !threaded ) { + Error( "ThreadLock: !threaded" ); + return; + } //end if + if ( my_mutex ) { + pthread_mutex_lock( my_mutex ); + } //end if + if ( enter ) { + Error( "Recursive ThreadLock\n" ); + } + enter = 1; +} //end of the function ThreadLock +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void ThreadUnlock( void ) { + if ( !threaded ) { + Error( "ThreadUnlock: !threaded" ); + return; + } //end if + if ( !enter ) { + Error( "ThreadUnlock without lock\n" ); + } + enter = 0; + if ( my_mutex ) { + pthread_mutex_unlock( my_mutex ); + } //end if +} //end of the function ThreadUnlock +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void ThreadSetupLock( void ) { + pthread_mutexattr_t mattrib; + + Log_Print( "pthread multi-threading\n" ); + + if ( !my_mutex ) { + my_mutex = GetMemory( sizeof( *my_mutex ) ); + if ( pthread_mutexattr_create( &mattrib ) == -1 ) { + Error( "pthread_mutex_attr_create failed" ); + } + if ( pthread_mutexattr_setkind_np( &mattrib, MUTEX_FAST_NP ) == -1 ) { + Error( "pthread_mutexattr_setkind_np failed" ); + } + if ( pthread_mutex_init( my_mutex, mattrib ) == -1 ) { + Error( "pthread_mutex_init failed" ); + } + } + + if ( pthread_attr_create( &attrib ) == -1 ) { + Error( "pthread_attr_create failed" ); + } + if ( pthread_attr_setstacksize( &attrib, 0x100000 ) == -1 ) { + Error( "pthread_attr_setstacksize failed" ); + } + + threaded = true; + currentnumthreads = 0; + currentthreadid = 0; +} //end of the function ThreadInitLock +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void ThreadShutdownLock( void ) { + threaded = false; +} //end of the function ThreadShutdownLock +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void RunThreadsOn( int workcnt, qboolean showpacifier, void ( *func )(int) ) { + int i; + pthread_t work_threads[MAX_THREADS]; + pthread_addr_t status; + pthread_attr_t attrib; + pthread_mutexattr_t mattrib; + int start, end; + + Log_Print( "pthread multi-threading\n" ); + + start = I_FloatTime(); + dispatch = 0; + workcount = workcnt; + oldf = -1; + pacifier = showpacifier; + threaded = true; + + if ( numthreads < 1 || numthreads > MAX_THREADS ) { + numthreads = 1; + } + + if ( pacifier ) { + setbuf( stdout, NULL ); + } + + if ( !my_mutex ) { + my_mutex = GetMemory( sizeof( *my_mutex ) ); + if ( pthread_mutexattr_create( &mattrib ) == -1 ) { + Error( "pthread_mutex_attr_create failed" ); + } + if ( pthread_mutexattr_setkind_np( &mattrib, MUTEX_FAST_NP ) == -1 ) { + Error( "pthread_mutexattr_setkind_np failed" ); + } + if ( pthread_mutex_init( my_mutex, mattrib ) == -1 ) { + Error( "pthread_mutex_init failed" ); + } + } + + if ( pthread_attr_create( &attrib ) == -1 ) { + Error( "pthread_attr_create failed" ); + } + if ( pthread_attr_setstacksize( &attrib, 0x100000 ) == -1 ) { + Error( "pthread_attr_setstacksize failed" ); + } + + for ( i = 0 ; i < numthreads ; i++ ) + { + if ( pthread_create( &work_threads[i], attrib + , (pthread_startroutine_t)func, (pthread_addr_t)i ) == -1 ) { + Error( "pthread_create failed" ); + } + } + + for ( i = 0 ; i < numthreads ; i++ ) + { + if ( pthread_join( work_threads[i], &status ) == -1 ) { + Error( "pthread_join failed" ); + } + } + + threaded = false; + + end = I_FloatTime(); + if ( pacifier ) { + printf( " (%i)\n", end - start ); + } +} //end of the function RunThreadsOn +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AddThread( void ( *func )(int) ) { + thread_t *thread; + + if ( numthreads == 1 ) { + if ( currentnumthreads >= numthreads ) { + return; + } + currentnumthreads++; + func( -1 ); + currentnumthreads--; + } //end if + else + { + ThreadLock(); + if ( currentnumthreads >= numthreads ) { + ThreadUnlock(); + return; + } //end if + //allocate new thread + thread = GetMemory( sizeof( thread_t ) ); + if ( !thread ) { + Error( "can't allocate memory for thread\n" ); + } + // + thread->threadid = currentthreadid; + + if ( pthread_create( &thread->thread, attrib, (pthread_startroutine_t)func, (pthread_addr_t)thread->threadid ) == -1 ) { + Error( "pthread_create failed" ); + } + + //add the thread to the end of the list + thread->next = NULL; + if ( lastthread ) { + lastthread->next = thread; + } else { firstthread = thread;} + lastthread = thread; + // +#ifdef THREAD_DEBUG + qprintf( "added thread with id %d\n", thread->threadid ); +#endif //THREAD_DEBUG + // + currentnumthreads++; + currentthreadid++; + // + ThreadUnlock(); + } //end else +} //end of the function AddThread +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void RemoveThread( int threadid ) { + thread_t *thread, *last; + + //if a single thread + if ( threadid == -1 ) { + return; + } + // + ThreadLock(); + last = NULL; + for ( thread = firstthread; thread; thread = thread->next ) + { + if ( thread->threadid == threadid ) { + if ( last ) { + last->next = thread->next; + } else { firstthread = thread->next;} + if ( !thread->next ) { + lastthread = last; + } + // + FreeMemory( thread ); + currentnumthreads--; +#ifdef THREAD_DEBUG + qprintf( "removed thread with id %d\n", threadid ); +#endif //THREAD_DEBUG + break; + } //end if + last = thread; + } //end if + if ( !thread ) { + Error( "couldn't find thread with id %d", threadid ); + } + ThreadUnlock(); +} //end of the function RemoveThread +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void WaitForAllThreadsFinished( void ) { + pthread_t *thread; + pthread_addr_t status; + + ThreadLock(); + while ( firstthread ) + { + thread = &firstthread->thread; + ThreadUnlock(); + + if ( pthread_join( *thread, &status ) == -1 ) { + Error( "pthread_join failed" ); + } + + ThreadLock(); + } //end while + ThreadUnlock(); +} //end of the function WaitForAllThreadsFinished +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int GetNumThreads( void ) { + return currentnumthreads; +} //end of the function GetNumThreads + +#endif + +//=================================================================== +// +// LINUX +// +//=================================================================== + +#if defined( LINUX ) + +#define USED + +#include +#include + +typedef struct thread_s +{ + pthread_t thread; + int threadid; + int id; + struct thread_s *next; +} thread_t; + +thread_t *firstthread; +thread_t *lastthread; +int currentnumthreads; +int currentthreadid; + +int numthreads = 1; +pthread_mutex_t my_mutex = PTHREAD_MUTEX_INITIALIZER; +pthread_attr_t attrib; +sem_t semaphore; +static int enter; +static int numwaitingthreads = 0; + + +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void ThreadSetDefault( void ) { + if ( numthreads == -1 ) { // not set manually + numthreads = 1; + } //end if + qprintf( "%i threads\n", numthreads ); +} //end of the function ThreadSetDefault +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void ThreadLock( void ) { + if ( !threaded ) { + Error( "ThreadLock: !threaded" ); + return; + } //end if + pthread_mutex_lock( &my_mutex ); + if ( enter ) { + Error( "Recursive ThreadLock\n" ); + } + enter = 1; +} //end of the function ThreadLock +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void ThreadUnlock( void ) { + if ( !threaded ) { + Error( "ThreadUnlock: !threaded" ); + return; + } //end if + if ( !enter ) { + Error( "ThreadUnlock without lock\n" ); + } + enter = 0; + pthread_mutex_unlock( &my_mutex ); +} //end of the function ThreadUnlock +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void ThreadSetupLock( void ) { + pthread_mutexattr_t mattrib; + + Log_Print( "pthread multi-threading\n" ); + + threaded = true; + currentnumthreads = 0; + currentthreadid = 0; +} //end of the function ThreadInitLock +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void ThreadShutdownLock( void ) { + threaded = false; +} //end of the function ThreadShutdownLock +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void ThreadSetupSemaphore( void ) { + sem_init( &semaphore, 0, 0 ); +} //end of the function ThreadSetupSemaphore +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void ThreadShutdownSemaphore( void ) { + sem_destroy( &semaphore ); +} //end of the function ThreadShutdownSemaphore +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void ThreadSemaphoreWait( void ) { + sem_wait( &semaphore ); +} //end of the function ThreadSemaphoreWait +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void ThreadSemaphoreIncrease( int count ) { + int i; + + for ( i = 0; i < count; i++ ) + { + sem_post( &semaphore ); + } //end for +} //end of the function ThreadSemaphoreIncrease +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void RunThreadsOn( int workcnt, qboolean showpacifier, void ( *func )(int) ) { + int i; + pthread_t work_threads[MAX_THREADS]; + void *pthread_return; + pthread_attr_t attrib; + pthread_mutexattr_t mattrib; + int start, end; + + Log_Print( "pthread multi-threading\n" ); + + start = I_FloatTime(); + dispatch = 0; + workcount = workcnt; + oldf = -1; + pacifier = showpacifier; + threaded = true; + + if ( numthreads < 1 || numthreads > MAX_THREADS ) { + numthreads = 1; + } + + if ( pacifier ) { + setbuf( stdout, NULL ); + } + + for ( i = 0 ; i < numthreads ; i++ ) + { + if ( pthread_create( &work_threads[i], NULL, (void *)func, (void *)i ) == -1 ) { + Error( "pthread_create failed" ); + } + } + + for ( i = 0 ; i < numthreads ; i++ ) + { + if ( pthread_join( work_threads[i], &pthread_return ) == -1 ) { + Error( "pthread_join failed" ); + } + } + + threaded = false; + + end = I_FloatTime(); + if ( pacifier ) { + printf( " (%i)\n", end - start ); + } +} //end of the function RunThreadsOn +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AddThread( void ( *func )(int) ) { + thread_t *thread; + + if ( numthreads == 1 ) { + if ( currentnumthreads >= numthreads ) { + return; + } + currentnumthreads++; + func( -1 ); + currentnumthreads--; + } //end if + else + { + ThreadLock(); + if ( currentnumthreads >= numthreads ) { + ThreadUnlock(); + return; + } //end if + //allocate new thread + thread = GetMemory( sizeof( thread_t ) ); + if ( !thread ) { + Error( "can't allocate memory for thread\n" ); + } + // + thread->threadid = currentthreadid; + + if ( pthread_create( &thread->thread, NULL, (void *)func, (void *)thread->threadid ) == -1 ) { + Error( "pthread_create failed" ); + } + + //add the thread to the end of the list + thread->next = NULL; + if ( lastthread ) { + lastthread->next = thread; + } else { firstthread = thread;} + lastthread = thread; + // +#ifdef THREAD_DEBUG + qprintf( "added thread with id %d\n", thread->threadid ); +#endif //THREAD_DEBUG + // + currentnumthreads++; + currentthreadid++; + // + ThreadUnlock(); + } //end else +} //end of the function AddThread +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void RemoveThread( int threadid ) { + thread_t *thread, *last; + + //if a single thread + if ( threadid == -1 ) { + return; + } + // + ThreadLock(); + last = NULL; + for ( thread = firstthread; thread; thread = thread->next ) + { + if ( thread->threadid == threadid ) { + if ( last ) { + last->next = thread->next; + } else { firstthread = thread->next;} + if ( !thread->next ) { + lastthread = last; + } + // + FreeMemory( thread ); + currentnumthreads--; +#ifdef THREAD_DEBUG + qprintf( "removed thread with id %d\n", threadid ); +#endif //THREAD_DEBUG + break; + } //end if + last = thread; + } //end if + if ( !thread ) { + Error( "couldn't find thread with id %d", threadid ); + } + ThreadUnlock(); +} //end of the function RemoveThread +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void WaitForAllThreadsFinished( void ) { + pthread_t *thread; + void *pthread_return; + + ThreadLock(); + while ( firstthread ) + { + thread = &firstthread->thread; + ThreadUnlock(); + + if ( pthread_join( *thread, &pthread_return ) == -1 ) { + Error( "pthread_join failed" ); + } + + ThreadLock(); + } //end while + ThreadUnlock(); +} //end of the function WaitForAllThreadsFinished +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int GetNumThreads( void ) { + return currentnumthreads; +} //end of the function GetNumThreads + +#endif //LINUX + + +//=================================================================== +// +// IRIX +// +//=================================================================== + +#ifdef _MIPS_ISA + +#define USED + +#include +#include +#include +#include + +typedef struct thread_s +{ + int threadid; + int id; + struct thread_s *next; +} thread_t; + +thread_t *firstthread; +thread_t *lastthread; +int currentnumthreads; +int currentthreadid; + +int numthreads = 1; +static int enter; +static int numwaitingthreads = 0; + +abilock_t lck; + +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void ThreadSetDefault( void ) { + if ( numthreads == -1 ) { + numthreads = prctl( PR_MAXPPROCS ); + } + printf( "%i threads\n", numthreads ); +//@@ + usconfig( CONF_INITUSERS, numthreads ); +} //end of the function ThreadSetDefault +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void ThreadLock( void ) { + spin_lock( &lck ); +} //end of the function ThreadLock +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void ThreadUnlock( void ) { + release_lock( &lck ); +} //end of the function ThreadUnlock +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void ThreadSetupLock( void ) { + init_lock( &lck ); + + Log_Print( "IRIX multi-threading\n" ); + + threaded = true; + currentnumthreads = 0; + currentthreadid = 0; +} //end of the function ThreadInitLock +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void ThreadShutdownLock( void ) { + threaded = false; +} //end of the function ThreadShutdownLock +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void RunThreadsOn( int workcnt, qboolean showpacifier, void ( *func )(int) ) { + int i; + int pid[MAX_THREADS]; + int start, end; + + start = I_FloatTime(); + dispatch = 0; + workcount = workcnt; + oldf = -1; + pacifier = showpacifier; + threaded = true; + + if ( numthreads < 1 || numthreads > MAX_THREADS ) { + numthreads = 1; + } + + if ( pacifier ) { + setbuf( stdout, NULL ); + } + + init_lock( &lck ); + + for ( i = 0 ; i < numthreads - 1 ; i++ ) + { + pid[i] = sprocsp( ( void( * ) ( void *, size_t ) )func, PR_SALL, (void *)i + , NULL, 0x100000 ); +// pid[i] = sprocsp ( (void (*)(void *, size_t))func, PR_SALL, (void *)i +// , NULL, 0x80000); + if ( pid[i] == -1 ) { + perror( "sproc" ); + Error( "sproc failed" ); + } + } + + func( i ); + + for ( i = 0 ; i < numthreads - 1 ; i++ ) + wait( NULL ); + + threaded = false; + + end = I_FloatTime(); + if ( pacifier ) { + printf( " (%i)\n", end - start ); + } +} //end of the function RunThreadsOn +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AddThread( void ( *func )(int) ) { + thread_t *thread; + + if ( numthreads == 1 ) { + if ( currentnumthreads >= numthreads ) { + return; + } + currentnumthreads++; + func( -1 ); + currentnumthreads--; + } //end if + else + { + ThreadLock(); + if ( currentnumthreads >= numthreads ) { + ThreadUnlock(); + return; + } //end if + //allocate new thread + thread = GetMemory( sizeof( thread_t ) ); + if ( !thread ) { + Error( "can't allocate memory for thread\n" ); + } + // + thread->threadid = currentthreadid; + + thread->id = sprocsp( ( void( * ) ( void *, size_t ) )func, PR_SALL, (void *)thread->threadid, NULL, 0x100000 ); + if ( thread->id == -1 ) { + perror( "sproc" ); + Error( "sproc failed" ); + } + + //add the thread to the end of the list + thread->next = NULL; + if ( lastthread ) { + lastthread->next = thread; + } else { firstthread = thread;} + lastthread = thread; + // +#ifdef THREAD_DEBUG + qprintf( "added thread with id %d\n", thread->threadid ); +#endif //THREAD_DEBUG + // + currentnumthreads++; + currentthreadid++; + // + ThreadUnlock(); + } //end else +} //end of the function AddThread +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void RemoveThread( int threadid ) { + thread_t *thread, *last; + + //if a single thread + if ( threadid == -1 ) { + return; + } + // + ThreadLock(); + last = NULL; + for ( thread = firstthread; thread; thread = thread->next ) + { + if ( thread->threadid == threadid ) { + if ( last ) { + last->next = thread->next; + } else { firstthread = thread->next;} + if ( !thread->next ) { + lastthread = last; + } + // + FreeMemory( thread ); + currentnumthreads--; +#ifdef THREAD_DEBUG + qprintf( "removed thread with id %d\n", threadid ); +#endif //THREAD_DEBUG + break; + } //end if + last = thread; + } //end if + if ( !thread ) { + Error( "couldn't find thread with id %d", threadid ); + } + ThreadUnlock(); +} //end of the function RemoveThread +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void WaitForAllThreadsFinished( void ) { + ThreadLock(); + while ( firstthread ) + { + ThreadUnlock(); + + //wait (NULL); + + ThreadLock(); + } //end while + ThreadUnlock(); +} //end of the function WaitForAllThreadsFinished +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int GetNumThreads( void ) { + return currentnumthreads; +} //end of the function GetNumThreads + +#endif //_MIPS_ISA + + +//======================================================================= +// +// SINGLE THREAD +// +//======================================================================= + +#ifndef USED + +int numthreads = 1; +int currentnumthreads = 0; + +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void ThreadSetDefault( void ) { + numthreads = 1; +} //end of the function ThreadSetDefault +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void ThreadLock( void ) { +} //end of the function ThreadLock +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void ThreadUnlock( void ) { +} //end of the function ThreadUnlock +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void ThreadSetupLock( void ) { + Log_Print( "no multi-threading\n" ); +} //end of the function ThreadInitLock +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void ThreadShutdownLock( void ) { +} //end of the function ThreadShutdownLock +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void ThreadSetupSemaphore( void ) { +} //end of the function ThreadSetupSemaphore +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void ThreadShutdownSemaphore( void ) { +} //end of the function ThreadShutdownSemaphore +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void ThreadSemaphoreWait( void ) { +} //end of the function ThreadSemaphoreWait +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void ThreadSemaphoreIncrease( int count ) { +} //end of the function ThreadSemaphoreIncrease +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void RunThreadsOn( int workcnt, qboolean showpacifier, void ( *func )(int) ) { + int start, end; + + Log_Print( "no multi-threading\n" ); + dispatch = 0; + workcount = workcnt; + oldf = -1; + pacifier = showpacifier; + start = I_FloatTime(); +#ifdef NeXT + if ( pacifier ) { + setbuf( stdout, NULL ); + } +#endif + func( 0 ); + + end = I_FloatTime(); + if ( pacifier ) { + printf( " (%i)\n", end - start ); + } +} //end of the function RunThreadsOn +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AddThread( void ( *func )(int) ) { + if ( currentnumthreads >= numthreads ) { + return; + } + currentnumthreads++; + func( -1 ); + currentnumthreads--; +} //end of the function AddThread +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void RemoveThread( int threadid ) { +} //end of the function RemoveThread +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void WaitForAllThreadsFinished( void ) { +} //end of the function WaitForAllThreadsFinished +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int GetNumThreads( void ) { + return currentnumthreads; +} //end of the function GetNumThreads + +#endif //USED diff --git a/Projects/Android/jni/rtcw/src/bspc/l_threads.h b/Projects/Android/jni/rtcw/src/bspc/l_threads.h new file mode 100644 index 0000000..70ad0fa --- /dev/null +++ b/Projects/Android/jni/rtcw/src/bspc/l_threads.h @@ -0,0 +1,52 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +extern int numthreads; + +void ThreadSetDefault( void ); +int GetThreadWork( void ); +void RunThreadsOnIndividual( int workcnt, qboolean showpacifier, void ( *func )( int ) ); +void RunThreadsOn( int workcnt, qboolean showpacifier, void ( *func )( int ) ); + +//mutex +void ThreadSetupLock( void ); +void ThreadShutdownLock( void ); +void ThreadLock( void ); +void ThreadUnlock( void ); +//semaphore +void ThreadSetupSemaphore( void ); +void ThreadShutdownSemaphore( void ); +void ThreadSemaphoreWait( void ); +void ThreadSemaphoreIncrease( int count ); +//add/remove threads +void AddThread( void ( *func )( int ) ); +void RemoveThread( int threadid ); +void WaitForAllThreadsFinished( void ); +int GetNumThreads( void ); + diff --git a/Projects/Android/jni/rtcw/src/bspc/l_utils.c b/Projects/Android/jni/rtcw/src/bspc/l_utils.c new file mode 100644 index 0000000..596529d --- /dev/null +++ b/Projects/Android/jni/rtcw/src/bspc/l_utils.c @@ -0,0 +1,267 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +//=========================================================================== +// +// Name: l_utils.c +// Function: several utils +// Programmer: Mr Elusive (MrElusive@demigod.demon.nl) +// Last update: 1997-12-31 +// Tab Size: 3 +//=========================================================================== + +#include +//#ifndef BOTLIB +//#define BOTLIB +//#endif //BOTLIB + +#ifdef BOTLIB +#include "q_shared.h" +#include "qfiles.h" +#include "botlib.h" +#include "l_log.h" +#include "l_libvar.h" +#include "l_memory.h" +//#include "l_utils.h" +#include "be_interface.h" +#else //BOTLIB +#include "qbsp.h" +#include "l_mem.h" +#endif //BOTLIB + +#ifdef BOTLIB +//======================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//======================================================================== +void Vector2Angles( vec3_t value1, vec3_t angles ) { + float forward; + float yaw, pitch; + + if ( value1[1] == 0 && value1[0] == 0 ) { + yaw = 0; + if ( value1[2] > 0 ) { + pitch = 90; + } else { pitch = 270;} + } //end if + else + { + yaw = (int) ( atan2( value1[1], value1[0] ) * 180 / M_PI ); + if ( yaw < 0 ) { + yaw += 360; + } + + forward = sqrt( value1[0] * value1[0] + value1[1] * value1[1] ); + pitch = (int) ( atan2( value1[2], forward ) * 180 / M_PI ); + if ( pitch < 0 ) { + pitch += 360; + } + } //end else + + angles[PITCH] = -pitch; + angles[YAW] = yaw; + angles[ROLL] = 0; +} //end of the function Vector2Angles +#endif //BOTLIB +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void ConvertPath( char *path ) { + while ( *path ) + { + if ( *path == '/' || *path == '\\' ) { + *path = PATHSEPERATOR_CHAR; + } + path++; + } //end while +} //end of the function ConvertPath +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AppendPathSeperator( char *path, int length ) { + int pathlen = strlen( path ); + + if ( strlen( path ) && length - pathlen > 1 && path[pathlen - 1] != '/' && path[pathlen - 1] != '\\' ) { + path[pathlen] = PATHSEPERATOR_CHAR; + path[pathlen + 1] = '\0'; + } //end if +} //end of the function AppenPathSeperator +//=========================================================================== +// returns pointer to file handle +// sets offset to and length of 'filename' in the pak file +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +qboolean FindFileInPak( char *pakfile, char *filename, foundfile_t *file ) { + FILE *fp; + dpackheader_t packheader; + dpackfile_t *packfiles; + int numdirs, i; + char path[MAX_PATH]; + + //open the pak file + fp = fopen( pakfile, "rb" ); + if ( !fp ) { + return false; + } //end if + //read pak header, check for valid pak id and seek to the dir entries + if ( ( fread( &packheader, 1, sizeof( dpackheader_t ), fp ) != sizeof( dpackheader_t ) ) + || ( packheader.ident != IDPAKHEADER ) + || ( fseek( fp, LittleLong( packheader.dirofs ), SEEK_SET ) ) + ) { + fclose( fp ); + return false; + } //end if + //number of dir entries in the pak file + numdirs = LittleLong( packheader.dirlen ) / sizeof( dpackfile_t ); + packfiles = (dpackfile_t *) GetMemory( numdirs * sizeof( dpackfile_t ) ); + //read the dir entry + if ( fread( packfiles, sizeof( dpackfile_t ), numdirs, fp ) != numdirs ) { + fclose( fp ); + FreeMemory( packfiles ); + return false; + } //end if + fclose( fp ); + // + strcpy( path, filename ); + ConvertPath( path ); + //find the dir entry in the pak file + for ( i = 0; i < numdirs; i++ ) + { + //convert the dir entry name + ConvertPath( packfiles[i].name ); + //compare the dir entry name with the filename + if ( Q_strcasecmp( packfiles[i].name, path ) == 0 ) { + strcpy( file->filename, pakfile ); + file->offset = LittleLong( packfiles[i].filepos ); + file->length = LittleLong( packfiles[i].filelen ); + FreeMemory( packfiles ); + return true; + } //end if + } //end for + FreeMemory( packfiles ); + return false; +} //end of the function FindFileInPak +//=========================================================================== +// find a Quake2 file +// returns full path in 'filename' +// sets offset and length of the file +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +qboolean FindQuakeFile2( char *basedir, char *gamedir, char *filename, foundfile_t *file ) { + int dir, i; + //NOTE: 3 is necessary (LCC bug???) + char gamedirs[3][MAX_PATH] = {"","",""}; + char filedir[MAX_PATH] = ""; + + // + if ( gamedir ) { + strncpy( gamedirs[0], gamedir, MAX_PATH ); + } + strncpy( gamedirs[1], "baseq2", MAX_PATH ); + // + //find the file in the two game directories + for ( dir = 0; dir < 2; dir++ ) + { + //check if the file is in a directory + filedir[0] = 0; + if ( basedir && strlen( basedir ) ) { + strncpy( filedir, basedir, MAX_PATH ); + AppendPathSeperator( filedir, MAX_PATH ); + } //end if + if ( strlen( gamedirs[dir] ) ) { + strncat( filedir, gamedirs[dir], MAX_PATH - strlen( filedir ) ); + AppendPathSeperator( filedir, MAX_PATH ); + } //end if + strncat( filedir, filename, MAX_PATH - strlen( filedir ) ); + ConvertPath( filedir ); + Log_Write( "accessing %s", filedir ); + if ( !access( filedir, 0x04 ) ) { + strcpy( file->filename, filedir ); + file->length = 0; + file->offset = 0; + return true; + } //end if + //check if the file is in a pak?.pak + for ( i = 0; i < 10; i++ ) + { + filedir[0] = 0; + if ( basedir && strlen( basedir ) ) { + strncpy( filedir, basedir, MAX_PATH ); + AppendPathSeperator( filedir, MAX_PATH ); + } //end if + if ( strlen( gamedirs[dir] ) ) { + strncat( filedir, gamedirs[dir], MAX_PATH - strlen( filedir ) ); + AppendPathSeperator( filedir, MAX_PATH ); + } //end if + // TTimo: huuuuh .. I suppose this means there needs to be two \0\0 at the end? + //sprintf(&filedir[strlen(filedir)], "pak%d.pak\0", i); + // doing it more 'clean' + sprintf( &filedir[strlen( filedir )], "pak%d.pak ", i ); + filedir[strlen( filedir ) - 1] = '\0'; + if ( !access( filedir, 0x04 ) ) { + Log_Write( "searching %s in %s", filename, filedir ); + if ( FindFileInPak( filedir, filename, file ) ) { + return true; + } + } //end if + } //end for + } //end for + file->offset = 0; + file->length = 0; + return false; +} //end of the function FindQuakeFile2 +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +#ifdef BOTLIB +qboolean FindQuakeFile( char *filename, foundfile_t *file ) { + return FindQuakeFile2( LibVarGetString( "basedir" ), + LibVarGetString( "gamedir" ), filename, file ); +} //end of the function FindQuakeFile +#else //BOTLIB +qboolean FindQuakeFile( char *basedir, char *gamedir, char *filename, foundfile_t *file ) { + return FindQuakeFile2( basedir, gamedir, filename, file ); +} //end of the function FindQuakeFile +#endif //BOTLIB diff --git a/Projects/Android/jni/rtcw/src/bspc/l_utils.h b/Projects/Android/jni/rtcw/src/bspc/l_utils.h new file mode 100644 index 0000000..4b9949e --- /dev/null +++ b/Projects/Android/jni/rtcw/src/bspc/l_utils.h @@ -0,0 +1,94 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +//=========================================================================== +// +// Name: l_utils.h +// Function: several utils +// Programmer: Mr Elusive (MrElusive@demigod.demon.nl) +// Last update: 1997-12-31 +// Tab Size: 3 +//=========================================================================== + +#ifndef MAX_PATH + #define MAX_PATH 64 +#endif + +#ifndef PATH_SEPERATORSTR + #if defined( WIN32 ) | defined( _WIN32 ) | defined( __NT__ ) | defined( __WINDOWS__ ) | defined( __WINDOWS_386__ ) + #define PATHSEPERATOR_STR "\\" + #else + #define PATHSEPERATOR_STR "/" + #endif +#endif +#ifndef PATH_SEPERATORCHAR + #if defined( WIN32 ) | defined( _WIN32 ) | defined( __NT__ ) | defined( __WINDOWS__ ) | defined( __WINDOWS_386__ ) + #define PATHSEPERATOR_CHAR '\\' + #else + #define PATHSEPERATOR_CHAR '/' + #endif +#endif + +//random in the range [0, 1] +#define random() ( ( rand() & 0x7fff ) / ( (float)0x7fff ) ) +//random in the range [-1, 1] +#define crandom() ( 2.0 * ( random() - 0.5 ) ) +//min and max +#define Maximum( x,y ) ( x > y ? x : y ) +#define Minimum( x,y ) ( x < y ? x : y ) +//absolute value +#define FloatAbs( x ) ( *(float *) &( ( *(int *) &( x ) ) & 0x7FFFFFFF ) ) +#define IntAbs( x ) ( ~( x ) ) +//coordinates +#define _X 0 +#define _Y 1 +#define _Z 2 + +typedef struct foundfile_s +{ + int offset; + int length; + char filename[MAX_PATH]; //screw LCC, array must be at end of struct +} foundfile_t; + +void Vector2Angles( vec3_t value1, vec3_t angles ); +//set the correct path seperators +void ConvertPath( char *path ); +//append a path seperator to the given path not exceeding the length +void AppendPathSeperator( char *path, int length ); +//find a file in a pak file +qboolean FindFileInPak( char *pakfile, char *filename, foundfile_t *file ); +//find a quake file +#ifdef BOTLIB +qboolean FindQuakeFile( char *filename, foundfile_t *file ); +#else //BOTLIB +qboolean FindQuakeFile( char *basedir, char *gamedir, char *filename, foundfile_t *file ); +#endif //BOTLIB + + + diff --git a/Projects/Android/jni/rtcw/src/bspc/leakfile.c b/Projects/Android/jni/rtcw/src/bspc/leakfile.c new file mode 100644 index 0000000..4d500ba --- /dev/null +++ b/Projects/Android/jni/rtcw/src/bspc/leakfile.c @@ -0,0 +1,108 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +#include "qbsp.h" + +/* +============================================================================== + +LEAF FILE GENERATION + +Save out name.line for qe3 to read +============================================================================== +*/ + + +/* +============= +LeakFile + +Finds the shortest possible chain of portals +that leads from the outside leaf to a specifically +occupied leaf +============= +*/ +void LeakFile( tree_t *tree ) { + vec3_t mid; + FILE *linefile; + char filename[1024]; + node_t *node; + int count; + + if ( !tree->outside_node.occupied ) { + return; + } + + qprintf( "--- LeakFile ---\n" ); + + // + // write the points to the file + // + sprintf( filename, "%s.lin", source ); + qprintf( "%s\n", filename ); + linefile = fopen( filename, "w" ); + if ( !linefile ) { + Error( "Couldn't open %s\n", filename ); + } + + count = 0; + node = &tree->outside_node; + while ( node->occupied > 1 ) + { + int next; + portal_t *p, *nextportal = NULL; // TTimo: init + node_t *nextnode = NULL; // TTimo: init + int s; + + // find the best portal exit + next = node->occupied; + for ( p = node->portals ; p ; p = p->next[!s] ) + { + s = ( p->nodes[0] == node ); + if ( p->nodes[s]->occupied + && p->nodes[s]->occupied < next ) { + nextportal = p; + nextnode = p->nodes[s]; + next = nextnode->occupied; + } + } + node = nextnode; + WindingCenter( nextportal->winding, mid ); + fprintf( linefile, "%f %f %f\n", mid[0], mid[1], mid[2] ); + count++; + } + // add the occupant center + GetVectorForKey( node->occupant, "origin", mid ); + + fprintf( linefile, "%f %f %f\n", mid[0], mid[1], mid[2] ); + qprintf( "%5i point linefile\n", count + 1 ); + + fclose( linefile ); +} + diff --git a/Projects/Android/jni/rtcw/src/bspc/map.c b/Projects/Android/jni/rtcw/src/bspc/map.c new file mode 100644 index 0000000..8e11d31 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/bspc/map.c @@ -0,0 +1,1360 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +//=========================================================================== +// +// Name: map.c +// Function: map loading and writing +// Programmer: Mr Elusive (MrElusive@demigod.demon.nl) +// Last update: 1997-12-03 +// Tab Size: 3 +//=========================================================================== + +#include "qbsp.h" +#include "l_bsp_hl.h" +#include "l_bsp_q1.h" +#include "l_bsp_q2.h" +#include "l_bsp_q3.h" +#include "l_bsp_sin.h" +#include "l_mem.h" +#include "../botlib/aasfile.h" //aas_bbox_t +#include "aas_store.h" //AAS_MAX_BBOXES +#include "aas_cfg.h" + +// TTimo: messy... +#define stricmp strcasecmp + +#define Sign( x ) ( x < 0 ? 1 : 0 ) + +int nummapbrushes; +mapbrush_t mapbrushes[MAX_MAPFILE_BRUSHES]; + +int nummapbrushsides; +side_t brushsides[MAX_MAPFILE_BRUSHSIDES]; +brush_texture_t side_brushtextures[MAX_MAPFILE_BRUSHSIDES]; + +int nummapplanes; +plane_t mapplanes[MAX_MAPFILE_PLANES]; +int mapplaneusers[MAX_MAPFILE_PLANES]; + +#define PLANE_HASHES 1024 +plane_t *planehash[PLANE_HASHES]; +vec3_t map_mins, map_maxs; + +#ifdef SIN +textureref_t side_newrefs[MAX_MAPFILE_BRUSHSIDES]; +#endif + +map_texinfo_t map_texinfo[MAX_MAPFILE_TEXINFO]; +int map_numtexinfo; +int loadedmaptype; //loaded map type + +// undefine to make plane finding use linear sort +#define USE_HASHING + +int c_boxbevels; +int c_edgebevels; +int c_areaportals; +int c_clipbrushes; +int c_squattbrushes; +int c_writtenbrushes; + +/* +============================================================================= + +PLANE FINDING + +============================================================================= +*/ + + +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int PlaneSignBits( vec3_t normal ) { + int i, signbits; + + signbits = 0; + for ( i = 2; i >= 0; i-- ) + { + signbits = ( signbits << 1 ) + Sign( normal[i] ); + } //end for + return signbits; +} //end of the function PlaneSignBits +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int PlaneTypeForNormal( vec3_t normal ) { + vec_t ax, ay, az; + +// NOTE: should these have an epsilon around 1.0? + if ( normal[0] == 1.0 || normal[0] == -1.0 ) { + return PLANE_X; + } + if ( normal[1] == 1.0 || normal[1] == -1.0 ) { + return PLANE_Y; + } + if ( normal[2] == 1.0 || normal[2] == -1.0 ) { + return PLANE_Z; + } + + ax = fabs( normal[0] ); + ay = fabs( normal[1] ); + az = fabs( normal[2] ); + + if ( ax >= ay && ax >= az ) { + return PLANE_ANYX; + } + if ( ay >= ax && ay >= az ) { + return PLANE_ANYY; + } + return PLANE_ANYZ; +} //end of the function PlaneTypeForNormal +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== + +// MrE: use the same epsilons as q3map! + +//ME NOTE: changed from 0.00001 +#define NORMAL_EPSILON 0.00001 +//ME NOTE: changed from 0.01 +#define DIST_EPSILON 0.01 + +qboolean PlaneEqual( plane_t *p, vec3_t normal, vec_t dist ) { +#if 1 + if ( + fabs( p->normal[0] - normal[0] ) < NORMAL_EPSILON + && fabs( p->normal[1] - normal[1] ) < NORMAL_EPSILON + && fabs( p->normal[2] - normal[2] ) < NORMAL_EPSILON + && fabs( p->dist - dist ) < DIST_EPSILON ) { + return true; + } +#else + if ( p->normal[0] == normal[0] + && p->normal[1] == normal[1] + && p->normal[2] == normal[2] + && p->dist == dist ) { + return true; + } +#endif + return false; +} //end of the function PlaneEqual +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AddPlaneToHash( plane_t *p ) { + int hash; + + hash = (int)fabs( p->dist ) / 8; + hash &= ( PLANE_HASHES - 1 ); + + p->hash_chain = planehash[hash]; + planehash[hash] = p; +} //end of the function AddPlaneToHash +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int CreateNewFloatPlane( vec3_t normal, vec_t dist ) { + plane_t *p, temp; + + if ( VectorLength( normal ) < 0.5 ) { + Error( "FloatPlane: bad normal" ); + } + // create a new plane + if ( nummapplanes + 2 > MAX_MAPFILE_PLANES ) { + Error( "MAX_MAPFILE_PLANES" ); + } + + p = &mapplanes[nummapplanes]; + VectorCopy( normal, p->normal ); + p->dist = dist; + p->type = ( p + 1 )->type = PlaneTypeForNormal( p->normal ); + p->signbits = PlaneSignBits( p->normal ); + + VectorSubtract( vec3_origin, normal, ( p + 1 )->normal ); + ( p + 1 )->dist = -dist; + ( p + 1 )->signbits = PlaneSignBits( ( p + 1 )->normal ); + + nummapplanes += 2; + + // allways put axial planes facing positive first + if ( p->type < 3 ) { + if ( p->normal[0] < 0 || p->normal[1] < 0 || p->normal[2] < 0 ) { + // flip order + temp = *p; + *p = *( p + 1 ); + *( p + 1 ) = temp; + + AddPlaneToHash( p ); + AddPlaneToHash( p + 1 ); + return nummapplanes - 1; + } + } + + AddPlaneToHash( p ); + AddPlaneToHash( p + 1 ); + return nummapplanes - 2; +} //end of the function CreateNewFloatPlane +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void SnapVector( vec3_t normal ) { + int i; + + for ( i = 0 ; i < 3 ; i++ ) + { + if ( fabs( normal[i] - 1 ) < NORMAL_EPSILON ) { + VectorClear( normal ); + normal[i] = 1; + break; + } + if ( fabs( normal[i] - -1 ) < NORMAL_EPSILON ) { + VectorClear( normal ); + normal[i] = -1; + break; + } + } +} //end of the function SnapVector +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void SnapPlane( vec3_t normal, vec_t *dist ) { + SnapVector( normal ); + + if ( fabs( *dist - Q_rint( *dist ) ) < DIST_EPSILON ) { + *dist = Q_rint( *dist ); + } +} //end of the function SnapPlane +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +#ifndef USE_HASHING +int FindFloatPlane( vec3_t normal, vec_t dist ) { + int i; + plane_t *p; + + SnapPlane( normal, &dist ); + for ( i = 0, p = mapplanes; i < nummapplanes; i++, p++ ) + { + if ( PlaneEqual( p, normal, dist ) ) { + mapplaneusers[i]++; + return i; + } //end if + } //end for + i = CreateNewFloatPlane( normal, dist ); + mapplaneusers[i]++; + return i; +} //end of the function FindFloatPlane +#else +int FindFloatPlane( vec3_t normal, vec_t dist ) { + int i; + plane_t *p; + int hash, h; + + SnapPlane( normal, &dist ); + hash = (int)fabs( dist ) / 8; + hash &= ( PLANE_HASHES - 1 ); + + // search the border bins as well + for ( i = -1; i <= 1; i++ ) + { + h = ( hash + i ) & ( PLANE_HASHES - 1 ); + for ( p = planehash[h]; p; p = p->hash_chain ) + { + if ( PlaneEqual( p, normal, dist ) ) { + mapplaneusers[p - mapplanes]++; + return p - mapplanes; + } //end if + } //end for + } //end for + i = CreateNewFloatPlane( normal, dist ); + mapplaneusers[i]++; + return i; +} //end of the function FindFloatPlane +#endif +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int PlaneFromPoints( int *p0, int *p1, int *p2 ) { + vec3_t t1, t2, normal; + vec_t dist; + + VectorSubtract( p0, p1, t1 ); + VectorSubtract( p2, p1, t2 ); + CrossProduct( t1, t2, normal ); + VectorNormalize( normal ); + + dist = DotProduct( p0, normal ); + + return FindFloatPlane( normal, dist ); +} //end of the function PlaneFromPoints +//=========================================================================== +// Adds any additional planes necessary to allow the brush to be expanded +// against axial bounding boxes +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AddBrushBevels( mapbrush_t *b ) { + int axis, dir; + int i, j, k, l, order; + side_t sidetemp; + brush_texture_t tdtemp; +#ifdef SIN + textureref_t trtemp; +#endif + side_t *s, *s2; + vec3_t normal; + float dist; + winding_t *w, *w2; + vec3_t vec, vec2; + float d; + + // + // add the axial planes + // + order = 0; + for ( axis = 0 ; axis < 3 ; axis++ ) + { + for ( dir = -1 ; dir <= 1 ; dir += 2, order++ ) + { + // see if the plane is allready present + for ( i = 0, s = b->original_sides ; i < b->numsides ; i++,s++ ) + { + if ( mapplanes[s->planenum].normal[axis] == dir ) { + break; + } + } + + if ( i == b->numsides ) { // add a new side + if ( nummapbrushsides == MAX_MAP_BRUSHSIDES ) { + Error( "MAX_MAP_BRUSHSIDES" ); + } + nummapbrushsides++; + b->numsides++; + VectorClear( normal ); + normal[axis] = dir; + if ( dir == 1 ) { + dist = b->maxs[axis]; + } else { + dist = -b->mins[axis]; + } + s->planenum = FindFloatPlane( normal, dist ); + s->texinfo = b->original_sides[0].texinfo; +#ifdef SIN + s->lightinfo = b->original_sides[0].lightinfo; +#endif + s->contents = b->original_sides[0].contents; + s->flags |= SFL_BEVEL; + c_boxbevels++; + } + + // if the plane is not in it canonical order, swap it + if ( i != order ) { + sidetemp = b->original_sides[order]; + b->original_sides[order] = b->original_sides[i]; + b->original_sides[i] = sidetemp; + + j = b->original_sides - brushsides; + tdtemp = side_brushtextures[j + order]; + side_brushtextures[j + order] = side_brushtextures[j + i]; + side_brushtextures[j + i] = tdtemp; + +#ifdef SIN + trtemp = side_newrefs[j + order]; + side_newrefs[j + order] = side_newrefs[j + i]; + side_newrefs[j + i] = trtemp; +#endif + } + } + } + + // + // add the edge bevels + // + if ( b->numsides == 6 ) { + return; // pure axial + + } + // test the non-axial plane edges + for ( i = 6 ; i < b->numsides ; i++ ) + { + s = b->original_sides + i; + w = s->winding; + if ( !w ) { + continue; + } + for ( j = 0 ; j < w->numpoints ; j++ ) + { + k = ( j + 1 ) % w->numpoints; + VectorSubtract( w->p[j], w->p[k], vec ); + if ( VectorNormalize( vec ) < 0.5 ) { + continue; + } + SnapVector( vec ); + for ( k = 0 ; k < 3 ; k++ ) + if ( vec[k] == -1 || vec[k] == 1 ) { + break; + } // axial + if ( k != 3 ) { + continue; // only test non-axial edges + + } + // try the six possible slanted axials from this edge + for ( axis = 0 ; axis < 3 ; axis++ ) + { + for ( dir = -1 ; dir <= 1 ; dir += 2 ) + { + // construct a plane + VectorClear( vec2 ); + vec2[axis] = dir; + CrossProduct( vec, vec2, normal ); + if ( VectorNormalize( normal ) < 0.5 ) { + continue; + } + dist = DotProduct( w->p[j], normal ); + + // if all the points on all the sides are + // behind this plane, it is a proper edge bevel + for ( k = 0 ; k < b->numsides ; k++ ) + { + // if this plane has allready been used, skip it + if ( PlaneEqual( &mapplanes[b->original_sides[k].planenum] + , normal, dist ) ) { + break; + } + + w2 = b->original_sides[k].winding; + if ( !w2 ) { + continue; + } + for ( l = 0 ; l < w2->numpoints ; l++ ) + { + d = DotProduct( w2->p[l], normal ) - dist; + if ( d > 0.1 ) { + break; // point in front + } + } + if ( l != w2->numpoints ) { + break; + } + } + + if ( k != b->numsides ) { + continue; // wasn't part of the outer hull + } + // add this plane + if ( nummapbrushsides == MAX_MAP_BRUSHSIDES ) { + Error( "MAX_MAP_BRUSHSIDES" ); + } + nummapbrushsides++; + s2 = &b->original_sides[b->numsides]; + s2->planenum = FindFloatPlane( normal, dist ); + s2->texinfo = b->original_sides[0].texinfo; +#ifdef SIN + s2->lightinfo = b->original_sides[0].lightinfo; +#endif + s2->contents = b->original_sides[0].contents; + s2->flags |= SFL_BEVEL; + c_edgebevels++; + b->numsides++; + } + } + } + } +} //end of the function AddBrushBevels +//=========================================================================== +// creates windigs for sides and mins / maxs for the brush +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +qboolean MakeBrushWindings( mapbrush_t *ob ) { + int i, j; + winding_t *w; + side_t *side; + plane_t *plane; + + ClearBounds( ob->mins, ob->maxs ); + + for ( i = 0; i < ob->numsides; i++ ) + { + plane = &mapplanes[ob->original_sides[i].planenum]; + w = BaseWindingForPlane( plane->normal, plane->dist ); + for ( j = 0; j < ob->numsides && w; j++ ) + { + if ( i == j ) { + continue; + } + if ( ob->original_sides[j].flags & SFL_BEVEL ) { + continue; + } + plane = &mapplanes[ob->original_sides[j].planenum ^ 1]; + ChopWindingInPlace( &w, plane->normal, plane->dist, 0 ); //CLIP_EPSILON); + } + + side = &ob->original_sides[i]; + side->winding = w; + if ( w ) { + side->flags |= SFL_VISIBLE; + for ( j = 0; j < w->numpoints; j++ ) + AddPointToBounds( w->p[j], ob->mins, ob->maxs ); + } + } + + for ( i = 0; i < 3; i++ ) + { + //IDBUG: all the indexes into the mins and maxs were zero (not using i) + if ( ob->mins[i] < -MAX_MAP_BOUNDS || ob->maxs[i] > MAX_MAP_BOUNDS ) { + Log_Print( "entity %i, brush %i: bounds out of range\n", ob->entitynum, ob->brushnum ); + ob->numsides = 0; //remove the brush + break; + } //end if + if ( ob->mins[i] > MAX_MAP_BOUNDS || ob->maxs[i] < -MAX_MAP_BOUNDS ) { + Log_Print( "entity %i, brush %i: no visible sides on brush\n", ob->entitynum, ob->brushnum ); + ob->numsides = 0; //remove the brush + break; + } //end if + } //end for + return true; +} //end of the function MakeBrushWindings +//=========================================================================== +// FIXME: currently doesn't mark all bevels +// NOTE: when one brush bevel is found the remaining sides of the brush +// are bevels as well (when the brush isn't expanded for AAS :)) +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void MarkBrushBevels( mapbrush_t *brush ) { + int i; + int we; + side_t *s; + + //check all the sides of the brush + for ( i = 0; i < brush->numsides; i++ ) + { + s = brush->original_sides + i; + //if the side has no winding + if ( !s->winding ) { + Log_Write( "MarkBrushBevels: brush %d no winding", brush->brushnum ); + s->flags |= SFL_BEVEL; + } //end if + //if the winding is tiny + else if ( WindingIsTiny( s->winding ) ) { + s->flags |= SFL_BEVEL; + Log_Write( "MarkBrushBevels: brush %d tiny winding", brush->brushnum ); + } //end else if + //if the winding has errors + else + { + we = WindingError( s->winding ); + if ( we == WE_NOTENOUGHPOINTS + || we == WE_SMALLAREA + || we == WE_POINTBOGUSRANGE +// || we == WE_NONCONVEX + ) { + Log_Write( "MarkBrushBevels: brush %d %s", brush->brushnum, WindingErrorString() ); + s->flags |= SFL_BEVEL; + } //end else if + } //end else + if ( s->flags & SFL_BEVEL ) { + s->flags &= ~SFL_VISIBLE; + //if the side has a valid plane + if ( s->planenum > 0 && s->planenum < nummapplanes ) { + //if it is an axial plane + if ( mapplanes[s->planenum].type < 3 ) { + c_boxbevels++; + } else { c_edgebevels++;} + } //end if + } //end if + } //end for +} //end of the function MarkBrushBevels +//=========================================================================== +// returns true if the map brush already exists +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int BrushExists( mapbrush_t *brush ) { + int i, s1, s2; + side_t *side1, *side2; + mapbrush_t *brush1, *brush2; + + for ( i = 0; i < nummapbrushes; i++ ) + { + brush1 = brush; + brush2 = &mapbrushes[i]; + //compare the brushes + if ( brush1->entitynum != brush2->entitynum ) { + continue; + } + //if (brush1->contents != brush2->contents) continue; + if ( brush1->numsides != brush2->numsides ) { + continue; + } + for ( s1 = 0; s1 < brush1->numsides; s1++ ) + { + side1 = brush1->original_sides + s1; + // + for ( s2 = 0; s2 < brush2->numsides; s2++ ) + { + side2 = brush2->original_sides + s2; + // + if ( ( side1->planenum & ~1 ) == ( side2->planenum & ~1 ) +// && side1->texinfo == side2->texinfo +// && side1->contents == side2->contents +// && side1->surf == side2->surf + ) { + break; + } + } //end if + if ( s2 >= brush2->numsides ) { + break; + } + } //end for + if ( s1 >= brush1->numsides ) { + return true; + } + } //end for + return false; +} //end of the function BrushExists +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +qboolean WriteMapBrush( FILE *fp, mapbrush_t *brush, vec3_t origin ) { + int sn, rotate, shift[2], sv, tv, planenum, p1, i, j; + float scale[2], originshift[2], ang1, ang2, newdist; + vec3_t vecs[2], axis[2]; + map_texinfo_t *ti; + winding_t *w; + side_t *s; + plane_t *plane; + + if ( noliquids ) { + if ( brush->contents & ( CONTENTS_WATER | CONTENTS_SLIME | CONTENTS_LAVA ) ) { + return true; + } //end if + } //end if + //if the brush has no contents + if ( !brush->contents ) { + return true; + } + //print the leading { + if ( fprintf( fp, " { //brush %d\n", brush->brushnum ) < 0 ) { + return false; + } + //write brush sides + for ( sn = 0; sn < brush->numsides; sn++ ) + { + s = brush->original_sides + sn; + //don't write out bevels + if ( !( s->flags & SFL_BEVEL ) ) { + //if the entity has an origin set + if ( origin[0] || origin[1] || origin[2] ) { + newdist = mapplanes[s->planenum].dist + + DotProduct( mapplanes[s->planenum].normal, origin ); + planenum = FindFloatPlane( mapplanes[s->planenum].normal, newdist ); + } //end if + else + { + planenum = s->planenum; + } //end else + //always take the first plane, then flip the points if necesary + plane = &mapplanes[planenum & ~1]; + w = BaseWindingForPlane( plane->normal, plane->dist ); + // + for ( i = 0; i < 3; i++ ) + { + for ( j = 0; j < 3; j++ ) + { + if ( fabs( w->p[i][j] ) < 0.2 ) { + w->p[i][j] = 0; + } else if ( fabs( (int)w->p[i][j] - w->p[i][j] ) < 0.3 ) { + w->p[i][j] = (int) w->p[i][j]; + } + //w->p[i][j] = (int) (w->p[i][j] + 0.2); + } //end for + } //end for + //three non-colinear points to define the plane + if ( planenum & 1 ) { + p1 = 1; + } else { p1 = 0;} + if ( fprintf( fp," ( %5i %5i %5i ) ", (int)w->p[p1][0], (int)w->p[p1][1], (int)w->p[p1][2] ) < 0 ) { + return false; + } + if ( fprintf( fp,"( %5i %5i %5i ) ", (int)w->p[!p1][0], (int)w->p[!p1][1], (int)w->p[!p1][2] ) < 0 ) { + return false; + } + if ( fprintf( fp,"( %5i %5i %5i ) ", (int)w->p[2][0], (int)w->p[2][1], (int)w->p[2][2] ) < 0 ) { + return false; + } + //free the winding + FreeWinding( w ); + // + if ( s->texinfo == TEXINFO_NODE ) { + if ( brush->contents & CONTENTS_PLAYERCLIP ) { + //player clip + if ( loadedmaptype == MAPTYPE_SIN ) { + if ( fprintf( fp, "generic/misc/clip 0 0 0 1 1" ) < 0 ) { + return false; + } + } //end if + else if ( loadedmaptype == MAPTYPE_QUAKE2 ) { //FIXME: don't always use e1u1 + if ( fprintf( fp, "e1u1/clip 0 0 0 1 1" ) < 0 ) { + return false; + } + } //end else + else if ( loadedmaptype == MAPTYPE_QUAKE3 ) { + if ( fprintf( fp, "e1u1/clip 0 0 0 1 1" ) < 0 ) { + return false; + } + } //end else if + else + { + if ( fprintf( fp, "clip 0 0 0 1 1" ) < 0 ) { + return false; + } + } //end else + } //end if + else if ( brush->contents == CONTENTS_MONSTERCLIP ) { + //monster clip + if ( loadedmaptype == MAPTYPE_SIN ) { + if ( fprintf( fp, "generic/misc/monster 0 0 0 1 1" ) < 0 ) { + return false; + } + } //end if + else if ( loadedmaptype == MAPTYPE_QUAKE2 ) { + if ( fprintf( fp, "e1u1/clip_mon 0 0 0 1 1" ) < 0 ) { + return false; + } + } //end else + else + { + if ( fprintf( fp, "clip 0 0 0 1 1" ) < 0 ) { + return false; + } + } //end else + } //end else + else + { + if ( fprintf( fp, "clip 0 0 0 1 1" ) < 0 ) { + return false; + } + Log_Write( "brush->contents = %d\n", brush->contents ); + } //end else + } //end if + else if ( loadedmaptype == MAPTYPE_SIN && s->texinfo == 0 ) { + if ( brush->contents & CONTENTS_DUMMYFENCE ) { + if ( fprintf( fp, "generic/misc/fence 0 0 0 1 1" ) < 0 ) { + return false; + } + } //end if + else if ( brush->contents & CONTENTS_MIST ) { + if ( fprintf( fp, "generic/misc/volumetric_base 0 0 0 1 1" ) < 0 ) { + return false; + } + } //end if + else //unknown so far + { + if ( fprintf( fp, "generic/misc/red 0 0 0 1 1" ) < 0 ) { + return false; + } + } //end else + } //end if + else if ( loadedmaptype == MAPTYPE_QUAKE3 ) { + //always use the same texture + if ( fprintf( fp, "e2u3/floor1_2 0 0 0 1 1 1 0 0" ) < 0 ) { + return false; + } + } //end else if + else + { + //* + ti = &map_texinfo[s->texinfo]; + //the scaling of the texture + scale[0] = 1 / VectorNormalize2( ti->vecs[0], vecs[0] ); + scale[1] = 1 / VectorNormalize2( ti->vecs[1], vecs[1] ); + // + TextureAxisFromPlane( plane, axis[0], axis[1] ); + //calculate texture shift done by entity origin + originshift[0] = DotProduct( origin, axis[0] ); + originshift[1] = DotProduct( origin, axis[1] ); + //the texture shift without origin shift + shift[0] = ti->vecs[0][3] - originshift[0]; + shift[1] = ti->vecs[1][3] - originshift[1]; + // + if ( axis[0][0] ) { + sv = 0; + } else if ( axis[0][1] ) { + sv = 1; + } else { sv = 2;} + if ( axis[1][0] ) { + tv = 0; + } else if ( axis[1][1] ) { + tv = 1; + } else { tv = 2;} + //calculate rotation of texture + if ( vecs[0][tv] == 0 ) { + ang1 = vecs[0][sv] > 0 ? 90.0 : -90.0; + } else { ang1 = atan2( vecs[0][sv], vecs[0][tv] ) * 180 / Q_PI;} + if ( ang1 < 0 ) { + ang1 += 360; + } + if ( ang1 >= 360 ) { + ang1 -= 360; + } + if ( axis[0][tv] == 0 ) { + ang2 = axis[0][sv] > 0 ? 90.0 : -90.0; + } else { ang2 = atan2( axis[0][sv], axis[0][tv] ) * 180 / Q_PI;} + if ( ang2 < 0 ) { + ang2 += 360; + } + if ( ang2 >= 360 ) { + ang2 -= 360; + } + rotate = ang2 - ang1; + if ( rotate < 0 ) { + rotate += 360; + } + if ( rotate >= 360 ) { + rotate -= 360; + } + //write the texture info + if ( fprintf( fp, "%s %d %d %d", ti->texture, shift[0], shift[1], rotate ) < 0 ) { + return false; + } + if ( fabs( scale[0] - ( (int) scale[0] ) ) < 0.001 ) { + if ( fprintf( fp, " %d", (int) scale[0] ) < 0 ) { + return false; + } + } //end if + else + { + if ( fprintf( fp, " %4f", scale[0] ) < 0 ) { + return false; + } + } //end if + if ( fabs( scale[1] - ( (int) scale[1] ) ) < 0.001 ) { + if ( fprintf( fp, " %d", (int) scale[1] ) < 0 ) { + return false; + } + } //end if + else + { + if ( fprintf( fp, " %4f", scale[1] ) < 0 ) { + return false; + } + } //end else + //write the extra brush side info + if ( loadedmaptype == MAPTYPE_QUAKE2 ) { + if ( fprintf( fp, " %d %d %d", s->contents, ti->flags, ti->value ) < 0 ) { + return false; + } + } //end if + //*/ + } //end else + if ( fprintf( fp, "\n" ) < 0 ) { + return false; + } + } //end if + } //end if + if ( fprintf( fp, " }\n" ) < 0 ) { + return false; + } + c_writtenbrushes++; + return true; +} //end of the function WriteMapBrush +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +qboolean WriteOriginBrush( FILE *fp, vec3_t origin ) { + vec3_t normal; + float dist; + int i, s; + winding_t *w; + + if ( fprintf( fp, " {\n" ) < 0 ) { + return false; + } + // + for ( i = 0; i < 3; i++ ) + { + for ( s = -1; s <= 1; s += 2 ) + { + // + VectorClear( normal ); + normal[i] = s; + dist = origin[i] * s + 16; + // + w = BaseWindingForPlane( normal, dist ); + //three non-colinear points to define the plane + if ( fprintf( fp," ( %5i %5i %5i ) ", (int)w->p[0][0], (int)w->p[0][1], (int)w->p[0][2] ) < 0 ) { + return false; + } + if ( fprintf( fp,"( %5i %5i %5i ) ", (int)w->p[1][0], (int)w->p[1][1], (int)w->p[1][2] ) < 0 ) { + return false; + } + if ( fprintf( fp,"( %5i %5i %5i ) ", (int)w->p[2][0], (int)w->p[2][1], (int)w->p[2][2] ) < 0 ) { + return false; + } + //free the winding + FreeWinding( w ); + //write origin texture: + // CONTENTS_ORIGIN = 16777216 + // SURF_NODRAW = 128 + if ( loadedmaptype == MAPTYPE_SIN ) { + if ( fprintf( fp, "generic/misc/origin 0 0 0 1 1" ) < 0 ) { + return false; + } + } //end if + else if ( loadedmaptype == MAPTYPE_HALFLIFE ) { + if ( fprintf( fp, "origin 0 0 0 1 1" ) < 0 ) { + return false; + } + } //end if + else + { + if ( fprintf( fp, "e1u1/origin 0 0 0 1 1" ) < 0 ) { + return false; + } + } //end else + //Quake2 extra brush side info + if ( loadedmaptype == MAPTYPE_QUAKE2 ) { + //if (fprintf(fp, " 16777216 128 0") < 0) return false; + } //end if + if ( fprintf( fp, "\n" ) < 0 ) { + return false; + } + } //end for + } //end for + if ( fprintf( fp, " }\n" ) < 0 ) { + return false; + } + c_writtenbrushes++; + return true; +} //end of the function WriteOriginBrush +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +mapbrush_t *GetAreaPortalBrush( entity_t *mapent ) { + int portalnum, bn; + mapbrush_t *brush = NULL; // TTimo: init + + //the area portal number + portalnum = mapent->areaportalnum; + //find the area portal brush in the world brushes + for ( bn = 0; bn < nummapbrushes && portalnum; bn++ ) + { + brush = &mapbrushes[bn]; + //must be in world entity + if ( brush->entitynum == 0 ) { + if ( brush->contents & CONTENTS_AREAPORTAL ) { + portalnum--; + } //end if + } //end if + } //end for + if ( bn < nummapbrushes ) { + return brush; + } //end if + else + { + Log_Print( "area portal %d brush not found\n", mapent->areaportalnum ); + return NULL; + } //end else +} //end of the function GetAreaPortalBrush +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +qboolean WriteMapFileSafe( FILE *fp ) { + char key[1024], value[1024]; + int i, bn, entitybrushes; + epair_t *ep; + mapbrush_t *brush; + entity_t *mapent; + //vec3_t vec_origin = {0, 0, 0}; + + // + if ( fprintf( fp,"//=====================================================\n" + "//\n" + "// map file created with BSPC v1.6\n" + "//\n" + "// BSPC is created by Mr Elusive\n" + "//\n" ) < 0 ) { + return false; + } + if ( loadedmaptype == MAPTYPE_SIN ) { + if ( fprintf( fp, + "// generic/misc/red is used for unknown textures\n" ) < 0 ) { + return false; + } + } //end if + if ( fprintf( fp,"//\n" + "//=====================================================\n" ) < 0 ) { + return false; + } + //write out all the entities + for ( i = 0; i < num_entities; i++ ) + { + mapent = &entities[i]; + if ( !mapent->epairs ) { + continue; + } //end if + if ( fprintf( fp, "{\n" ) < 0 ) { + return false; + } + // + if ( loadedmaptype == MAPTYPE_QUAKE3 ) { + if ( !stricmp( ValueForKey( mapent, "classname" ), "light" ) ) { + SetKeyValue( mapent, "light", "10000" ); + } //end if + } //end if + //write epairs + for ( ep = mapent->epairs; ep; ep = ep->next ) + { + strcpy( key, ep->key ); + StripTrailing( key ); + strcpy( value, ep->value ); + StripTrailing( value ); + // + if ( loadedmaptype == MAPTYPE_QUAKE2 || + loadedmaptype == MAPTYPE_SIN ) { + //don't write an origin for BSP models + if ( mapent->modelnum >= 0 && !strcmp( key, "origin" ) ) { + continue; + } + } //end if + //don't write BSP model numbers + if ( mapent->modelnum >= 0 && !strcmp( key, "model" ) && value[0] == '*' ) { + continue; + } + // + if ( fprintf( fp, " \"%s\" \"%s\"\n", key, value ) < 0 ) { + return false; + } + } //end for + // + if ( ValueForKey( mapent, "origin" ) ) { + GetVectorForKey( mapent, "origin", mapent->origin ); + } else { mapent->origin[0] = mapent->origin[1] = mapent->origin[2] = 0;} + //if this is an area portal entity + if ( !strcmp( "func_areaportal", ValueForKey( mapent, "classname" ) ) ) { + brush = GetAreaPortalBrush( mapent ); + if ( !brush ) { + return false; + } + if ( !WriteMapBrush( fp, brush, mapent->origin ) ) { + return false; + } + } //end if + else + { + entitybrushes = false; + //write brushes + for ( bn = 0; bn < nummapbrushes; bn++ ) + { + brush = &mapbrushes[bn]; + //if the brush is part of this entity + if ( brush->entitynum == i ) { + //don't write out area portal brushes in the world + if ( !( ( brush->contents & CONTENTS_AREAPORTAL ) && brush->entitynum == 0 ) ) { + /* + if (!strcmp("func_door_rotating", ValueForKey(mapent, "classname"))) + { + AAS_PositionFuncRotatingBrush(mapent, brush); + if (!WriteMapBrush(fp, brush, vec_origin)) return false; + } //end if + else // + */ + { + if ( !WriteMapBrush( fp, brush, mapent->origin ) ) { + return false; + } + } //end else + entitybrushes = true; + } //end if + } //end if + } //end for + //if the entity had brushes + if ( entitybrushes ) { + //if the entity has an origin set + if ( mapent->origin[0] || mapent->origin[1] || mapent->origin[2] ) { + if ( !WriteOriginBrush( fp, mapent->origin ) ) { + return false; + } + } //end if + } //end if + } //end else + if ( fprintf( fp, "}\n" ) < 0 ) { + return false; + } + } //end for + if ( fprintf( fp, "//total of %d brushes\n", c_writtenbrushes ) < 0 ) { + return false; + } + return true; +} //end of the function WriteMapFileSafe +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void WriteMapFile( char *filename ) { + FILE *fp; + double start_time; + + c_writtenbrushes = 0; + //the time started + start_time = I_FloatTime(); + // + Log_Print( "writing %s\n", filename ); + fp = fopen( filename, "wb" ); + if ( !fp ) { + Log_Print( "can't open %s\n", filename ); + return; + } //end if + if ( !WriteMapFileSafe( fp ) ) { + fclose( fp ); + Log_Print( "error writing map file %s\n", filename ); + return; + } //end if + fclose( fp ); + //display creation time + Log_Print( "written %d brushes\n", c_writtenbrushes ); + Log_Print( "map file written in %5.0f seconds\n", I_FloatTime() - start_time ); +} //end of the function WriteMapFile +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void PrintMapInfo( void ) { + Log_Print( "\n" ); + Log_Print( "%6i brushes\n", nummapbrushes ); + Log_Print( "%6i brush sides\n", nummapbrushsides ); +// Log_Print("%6i clipbrushes\n", c_clipbrushes); +// Log_Print("%6i total sides\n", nummapbrushsides); +// Log_Print("%6i boxbevels\n", c_boxbevels); +// Log_Print("%6i edgebevels\n", c_edgebevels); +// Log_Print("%6i entities\n", num_entities); +// Log_Print("%6i planes\n", nummapplanes); +// Log_Print("%6i areaportals\n", c_areaportals); +// Log_Print("%6i squatt brushes\n", c_squattbrushes); +// Log_Print("size: %5.0f,%5.0f,%5.0f to %5.0f,%5.0f,%5.0f\n", map_mins[0],map_mins[1],map_mins[2], +// map_maxs[0],map_maxs[1],map_maxs[2]); +} //end of the function PrintMapInfo +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void ResetMapLoading( void ) { + int i; + epair_t *ep, *nextep; + + Q2_ResetMapLoading(); + Sin_ResetMapLoading(); + + //free all map brush side windings + for ( i = 0; i < nummapbrushsides; i++ ) + { + if ( brushsides[i].winding ) { + FreeWinding( brushsides[i].winding ); + } //end for + } //end for + + //reset regular stuff + nummapbrushes = 0; + memset( mapbrushes, 0, MAX_MAPFILE_BRUSHES * sizeof( mapbrush_t ) ); + // + nummapbrushsides = 0; + memset( brushsides, 0, MAX_MAPFILE_BRUSHSIDES * sizeof( side_t ) ); + memset( side_brushtextures, 0, MAX_MAPFILE_BRUSHSIDES * sizeof( brush_texture_t ) ); + // + nummapplanes = 0; + memset( mapplanes, 0, MAX_MAPFILE_PLANES * sizeof( plane_t ) ); + // + memset( planehash, 0, PLANE_HASHES * sizeof( plane_t * ) ); + // + memset( map_texinfo, 0, MAX_MAPFILE_TEXINFO * sizeof( map_texinfo_t ) ); + map_numtexinfo = 0; + // + VectorClear( map_mins ); + VectorClear( map_maxs ); + // + c_boxbevels = 0; + c_edgebevels = 0; + c_areaportals = 0; + c_clipbrushes = 0; + c_writtenbrushes = 0; + //clear the entities + for ( i = 0; i < num_entities; i++ ) + { + for ( ep = entities[i].epairs; ep; ep = nextep ) + { + nextep = ep->next; + FreeMemory( ep->key ); + FreeMemory( ep->value ); + FreeMemory( ep ); + } //end for + } //end for + num_entities = 0; + memset( entities, 0, MAX_MAP_ENTITIES * sizeof( entity_t ) ); +} //end of the function ResetMapLoading +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +#ifndef Q1_BSPVERSION +#define Q1_BSPVERSION 29 +#endif +#ifndef HL_BSPVERSION +#define HL_BSPVERSION 30 +#endif + +#define Q2_BSPHEADER ( ( 'P' << 24 ) + ( 'S' << 16 ) + ( 'B' << 8 ) + 'I' ) //IBSP +#define Q2_BSPVERSION 38 + +#define SINGAME_BSPHEADER ( ( 'P' << 24 ) + ( 'S' << 16 ) + ( 'B' << 8 ) + 'R' ) //RBSP +#define SINGAME_BSPVERSION 1 + +#define SIN_BSPHEADER ( ( 'P' << 24 ) + ( 'S' << 16 ) + ( 'B' << 8 ) + 'I' ) //IBSP +#define SIN_BSPVERSION 41 + +typedef struct +{ + int ident; + int version; +} idheader_t; + +int LoadMapFromBSP( struct quakefile_s *qf ) { + idheader_t idheader; + + if ( ReadQuakeFile( qf, &idheader, 0, sizeof( idheader_t ) ) != sizeof( idheader_t ) ) { + return false; + } //end if + + idheader.ident = LittleLong( idheader.ident ); + idheader.version = LittleLong( idheader.version ); + //Quake3 BSP file + if ( idheader.ident == Q3_BSP_IDENT && idheader.version == Q3_BSP_VERSION ) { + ResetMapLoading(); + Q3_LoadMapFromBSP( qf ); + Q3_FreeMaxBSP(); + } //end if + //Quake2 BSP file + else if ( idheader.ident == Q2_BSPHEADER && idheader.version == Q2_BSPVERSION ) { + ResetMapLoading(); + Q2_AllocMaxBSP(); + Q2_LoadMapFromBSP( qf->filename, qf->offset, qf->length ); + Q2_FreeMaxBSP(); + } //endif + //Sin BSP file + else if ( ( idheader.ident == SIN_BSPHEADER && idheader.version == SIN_BSPVERSION ) || + //the dorks gave the same format another ident and verions + ( idheader.ident == SINGAME_BSPHEADER && idheader.version == SINGAME_BSPVERSION ) ) { + ResetMapLoading(); + Sin_AllocMaxBSP(); + Sin_LoadMapFromBSP( qf->filename, qf->offset, qf->length ); + Sin_FreeMaxBSP(); + } //end if + //the Quake1 bsp files don't have a ident only a version + else if ( idheader.ident == Q1_BSPVERSION ) { + ResetMapLoading(); + Q1_AllocMaxBSP(); + Q1_LoadMapFromBSP( qf->filename, qf->offset, qf->length ); + Q1_FreeMaxBSP(); + } //end if + //Half-Life also only uses a version number + else if ( idheader.ident == HL_BSPVERSION ) { + ResetMapLoading(); + HL_AllocMaxBSP(); + HL_LoadMapFromBSP( qf->filename, qf->offset, qf->length ); + HL_FreeMaxBSP(); + } //end if + else + { + Error( "unknown BSP format %c%c%c%c, version %d\n", + ( idheader.ident & 0xFF ), + ( ( idheader.ident >> 8 ) & 0xFF ), + ( ( idheader.ident >> 16 ) & 0xFF ), + ( ( idheader.ident >> 24 ) & 0xFF ), idheader.version ); + return false; + } //end if + // + return true; +} //end of the function LoadMapFromBSP diff --git a/Projects/Android/jni/rtcw/src/bspc/map_hl.c b/Projects/Android/jni/rtcw/src/bspc/map_hl.c new file mode 100644 index 0000000..ad7906a --- /dev/null +++ b/Projects/Android/jni/rtcw/src/bspc/map_hl.c @@ -0,0 +1,1147 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +//=========================================================================== +// +// Name: map_hl.c +// Function: map loading and writing +// Programmer: Mr Elusive (MrElusive@demigod.demon.nl) +// Last update: 1997-12-03 +// Tab Size: 3 +//=========================================================================== + +#include "qbsp.h" +#include "l_bsp_hl.h" +#include "aas_map.h" //AAS_CreateMapBrushes + +int hl_numbrushes; +int hl_numclipbrushes; + +//#define HL_PRINT +#define HLCONTENTS + +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int HL_TextureContents( char *name ) { + if ( !Q_strncasecmp( name, "sky",3 ) ) { + return CONTENTS_SOLID; + } + + if ( !Q_strncasecmp( name + 1,"!lava",5 ) ) { + return CONTENTS_LAVA; + } + + if ( !Q_strncasecmp( name + 1,"!slime",6 ) ) { + return CONTENTS_SLIME; + } + + /* + if (!Q_strncasecmp (name, "!cur_90",7)) + return CONTENTS_CURRENT_90; + if (!Q_strncasecmp (name, "!cur_0",6)) + return CONTENTS_CURRENT_0; + if (!Q_strncasecmp (name, "!cur_270",8)) + return CONTENTS_CURRENT_270; + if (!Q_strncasecmp (name, "!cur_180",8)) + return CONTENTS_CURRENT_180; + if (!Q_strncasecmp (name, "!cur_up",7)) + return CONTENTS_CURRENT_UP; + if (!Q_strncasecmp (name, "!cur_dwn",8)) + return CONTENTS_CURRENT_DOWN; + // + */ + if ( name[0] == '!' ) { + return CONTENTS_WATER; + } + /* + if (!Q_strncasecmp (name, "origin",6)) + return CONTENTS_ORIGIN; + if (!Q_strncasecmp (name, "clip",4)) + return CONTENTS_CLIP; + if( !Q_strncasecmp( name, "translucent", 11 ) ) + return CONTENTS_TRANSLUCENT; + if( name[0] == '@' ) + return CONTENTS_TRANSLUCENT; + // + */ + + return CONTENTS_SOLID; +} //end of the function HL_TextureContents +//=========================================================================== +// Generates two new brushes, leaving the original +// unchanged +// +// modified for Half-Life because there are quite a lot of tiny node leaves +// in the Half-Life bsps +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void HL_SplitBrush( bspbrush_t *brush, int planenum, int nodenum, + bspbrush_t **front, bspbrush_t **back ) { + bspbrush_t *b[2]; + int i, j; + winding_t *w, *cw[2], *midwinding; + plane_t *plane, *plane2; + side_t *s, *cs; + float d, d_front, d_back; + + *front = *back = NULL; + plane = &mapplanes[planenum]; + + // check all points + d_front = d_back = 0; + for ( i = 0 ; i < brush->numsides ; i++ ) + { + w = brush->sides[i].winding; + if ( !w ) { + continue; + } + for ( j = 0 ; j < w->numpoints ; j++ ) + { + d = DotProduct( w->p[j], plane->normal ) - plane->dist; + if ( d > 0 && d > d_front ) { + d_front = d; + } + if ( d < 0 && d < d_back ) { + d_back = d; + } + } //end for + } //end for + + if ( d_front < 0.1 ) { // PLANESIDE_EPSILON) + // only on back + *back = CopyBrush( brush ); + Log_Print( "HL_SplitBrush: only on back\n" ); + return; + } //end if + if ( d_back > -0.1 ) { // PLANESIDE_EPSILON) + // only on front + *front = CopyBrush( brush ); + Log_Print( "HL_SplitBrush: only on front\n" ); + return; + } //end if + + // create a new winding from the split plane + + w = BaseWindingForPlane( plane->normal, plane->dist ); + for ( i = 0; i < brush->numsides && w; i++ ) + { + plane2 = &mapplanes[brush->sides[i].planenum ^ 1]; + ChopWindingInPlace( &w, plane2->normal, plane2->dist, 0 ); // PLANESIDE_EPSILON); + } //end for + + if ( !w || WindingIsTiny( w ) ) { // the brush isn't really split + int side; + + Log_Print( "HL_SplitBrush: no split winding\n" ); + side = BrushMostlyOnSide( brush, plane ); + if ( side == PSIDE_FRONT ) { + *front = CopyBrush( brush ); + } + if ( side == PSIDE_BACK ) { + *back = CopyBrush( brush ); + } + return; + } + + if ( WindingIsHuge( w ) ) { + Log_Print( "HL_SplitBrush: WARNING huge split winding\n" ); + } //end of + + midwinding = w; + + // split it for real + + for ( i = 0; i < 2; i++ ) + { + b[i] = AllocBrush( brush->numsides + 1 ); + b[i]->original = brush->original; + } //end for + + // split all the current windings + + for ( i = 0 ; i < brush->numsides ; i++ ) + { + s = &brush->sides[i]; + w = s->winding; + if ( !w ) { + continue; + } + ClipWindingEpsilon( w, plane->normal, plane->dist, + 0 /*PLANESIDE_EPSILON*/, &cw[0], &cw[1] ); + for ( j = 0 ; j < 2 ; j++ ) + { + if ( !cw[j] ) { + continue; + } +#if 0 + if ( WindingIsTiny( cw[j] ) ) { + FreeWinding( cw[j] ); + continue; + } +#endif + cs = &b[j]->sides[b[j]->numsides]; + b[j]->numsides++; + *cs = *s; +// cs->planenum = s->planenum; +// cs->texinfo = s->texinfo; +// cs->visible = s->visible; +// cs->original = s->original; + cs->winding = cw[j]; + cs->flags &= ~SFL_TESTED; + } //end for + } //end for + + + // see if we have valid polygons on both sides + + for ( i = 0 ; i < 2 ; i++ ) + { + BoundBrush( b[i] ); + for ( j = 0 ; j < 3 ; j++ ) + { + if ( b[i]->mins[j] < -4096 || b[i]->maxs[j] > 4096 ) { + Log_Print( "HL_SplitBrush: bogus brush after clip\n" ); + break; + } //end if + } //end for + + if ( b[i]->numsides < 3 || j < 3 ) { + FreeBrush( b[i] ); + b[i] = NULL; + Log_Print( "HL_SplitBrush: numsides < 3\n" ); + } //end if + } //end for + + if ( !( b[0] && b[1] ) ) { + if ( !b[0] && !b[1] ) { + Log_Print( "HL_SplitBrush: split removed brush\n" ); + } else { + Log_Print( "HL_SplitBrush: split not on both sides\n" ); + } + if ( b[0] ) { + FreeBrush( b[0] ); + *front = CopyBrush( brush ); + } //end if + if ( b[1] ) { + FreeBrush( b[1] ); + *back = CopyBrush( brush ); + } //end if + return; + } //end if + + // add the midwinding to both sides + for ( i = 0; i < 2; i++ ) + { + cs = &b[i]->sides[b[i]->numsides]; + b[i]->numsides++; + + cs->planenum = planenum ^ i ^ 1; + cs->texinfo = 0; + //store the node number in the surf to find the texinfo later on + cs->surf = nodenum; + // + cs->flags &= ~SFL_VISIBLE; + cs->flags &= ~SFL_TESTED; + if ( i == 0 ) { + cs->winding = CopyWinding( midwinding ); + } else { + cs->winding = midwinding; + } + } //end for + + + { + vec_t v1; + int i; + + for ( i = 0 ; i < 2 ; i++ ) + { + v1 = BrushVolume( b[i] ); + if ( v1 < 1 ) { + FreeBrush( b[i] ); + b[i] = NULL; + Log_Print( "HL_SplitBrush: tiny volume after clip\n" ); + } //end if + } //end for + } //*/ + + *front = b[0]; + *back = b[1]; +} //end of the function HL_SplitBrush +//=========================================================================== +// returns true if the tree starting at nodenum has only solid leaves +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int HL_SolidTree_r( int nodenum ) { + if ( nodenum < 0 ) { + switch ( hl_dleafs[( -nodenum ) - 1].contents ) + { + case HL_CONTENTS_EMPTY: + { + return false; + } //end case + case HL_CONTENTS_SOLID: +#ifdef HLCONTENTS + case HL_CONTENTS_CLIP: +#endif //HLCONTENTS + case HL_CONTENTS_SKY: +#ifdef HLCONTENTS + case HL_CONTENTS_TRANSLUCENT: +#endif //HLCONTENTS + { + return true; + } //end case + case HL_CONTENTS_WATER: + case HL_CONTENTS_SLIME: + case HL_CONTENTS_LAVA: +#ifdef HLCONTENTS + //these contents should not be found in the BSP + case HL_CONTENTS_ORIGIN: + case HL_CONTENTS_CURRENT_0: + case HL_CONTENTS_CURRENT_90: + case HL_CONTENTS_CURRENT_180: + case HL_CONTENTS_CURRENT_270: + case HL_CONTENTS_CURRENT_UP: + case HL_CONTENTS_CURRENT_DOWN: +#endif //HLCONTENTS + default: + { + return false; + } //end default + } //end switch + return false; + } //end if + if ( !HL_SolidTree_r( hl_dnodes[nodenum].children[0] ) ) { + return false; + } + if ( !HL_SolidTree_r( hl_dnodes[nodenum].children[1] ) ) { + return false; + } + return true; +} //end of the function HL_SolidTree_r +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +bspbrush_t *HL_CreateBrushes_r( bspbrush_t *brush, int nodenum ) { + int planenum; + bspbrush_t *front, *back; + hl_dleaf_t *leaf; + + //if it is a leaf + if ( nodenum < 0 ) { + leaf = &hl_dleafs[( -nodenum ) - 1]; + if ( leaf->contents != HL_CONTENTS_EMPTY ) { +#ifdef HL_PRINT + qprintf( "\r%5i", ++hl_numbrushes ); +#endif //HL_PRINT + } //end if + switch ( leaf->contents ) + { + case HL_CONTENTS_EMPTY: + { + FreeBrush( brush ); + return NULL; + } //end case + case HL_CONTENTS_SOLID: +#ifdef HLCONTENTS + case HL_CONTENTS_CLIP: +#endif //HLCONTENTS + case HL_CONTENTS_SKY: +#ifdef HLCONTENTS + case HL_CONTENTS_TRANSLUCENT: +#endif //HLCONTENTS + { + brush->side = CONTENTS_SOLID; + return brush; + } //end case + case HL_CONTENTS_WATER: + { + brush->side = CONTENTS_WATER; + return brush; + } //end case + case HL_CONTENTS_SLIME: + { + brush->side = CONTENTS_SLIME; + return brush; + } //end case + case HL_CONTENTS_LAVA: + { + brush->side = CONTENTS_LAVA; + return brush; + } //end case +#ifdef HLCONTENTS + //these contents should not be found in the BSP + case HL_CONTENTS_ORIGIN: + case HL_CONTENTS_CURRENT_0: + case HL_CONTENTS_CURRENT_90: + case HL_CONTENTS_CURRENT_180: + case HL_CONTENTS_CURRENT_270: + case HL_CONTENTS_CURRENT_UP: + case HL_CONTENTS_CURRENT_DOWN: + { + Error( "HL_CreateBrushes_r: found contents %d in Half-Life BSP", leaf->contents ); + return NULL; + } //end case +#endif //HLCONTENTS + default: + { + Error( "HL_CreateBrushes_r: unknown contents %d in Half-Life BSP", leaf->contents ); + return NULL; + } //end default + } //end switch + return NULL; + } //end if + //if the rest of the tree is solid + /*if (HL_SolidTree_r(nodenum)) + { + brush->side = CONTENTS_SOLID; + return brush; + } //end if*/ + // + planenum = hl_dnodes[nodenum].planenum; + planenum = FindFloatPlane( hl_dplanes[planenum].normal, hl_dplanes[planenum].dist ); + //split the brush with the node plane + HL_SplitBrush( brush, planenum, nodenum, &front, &back ); + //free the original brush + FreeBrush( brush ); + //every node must split the brush in two + if ( !front || !back ) { + Log_Print( "HL_CreateBrushes_r: WARNING node not splitting brush\n" ); + //return NULL; + } //end if + //create brushes recursively + if ( front ) { + front = HL_CreateBrushes_r( front, hl_dnodes[nodenum].children[0] ); + } + if ( back ) { + back = HL_CreateBrushes_r( back, hl_dnodes[nodenum].children[1] ); + } + //link the brushes if possible and return them + if ( front ) { + for ( brush = front; brush->next; brush = brush->next ) ; + brush->next = back; + return front; + } //end if + else + { + return back; + } //end else +} //end of the function HL_CreateBrushes_r +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +bspbrush_t *HL_CreateBrushesFromBSP( int modelnum ) { + bspbrush_t *brushlist; + bspbrush_t *brush; + hl_dnode_t *headnode; + vec3_t mins, maxs; + int i; + + // + headnode = &hl_dnodes[hl_dmodels[modelnum].headnode[0]]; + //get the mins and maxs of the world + VectorCopy( headnode->mins, mins ); + VectorCopy( headnode->maxs, maxs ); + //enlarge these mins and maxs + for ( i = 0; i < 3; i++ ) + { + mins[i] -= 8; + maxs[i] += 8; + } //end for + //NOTE: have to add the BSP tree mins and maxs to the MAP mins and maxs + AddPointToBounds( mins, map_mins, map_maxs ); + AddPointToBounds( maxs, map_mins, map_maxs ); + // + if ( !modelnum ) { + Log_Print( "brush size: %5.0f,%5.0f,%5.0f to %5.0f,%5.0f,%5.0f\n", + map_mins[0], map_mins[1], map_mins[2], + map_maxs[0], map_maxs[1], map_maxs[2] ); + } //end if + //create one huge brush containing the whole world + brush = BrushFromBounds( mins, maxs ); + VectorCopy( mins, brush->mins ); + VectorCopy( maxs, brush->maxs ); + // +#ifdef HL_PRINT + qprintf( "creating Half-Life brushes\n" ); + qprintf( "%5d brushes", hl_numbrushes = 0 ); +#endif //HL_PRINT + //create the brushes + brushlist = HL_CreateBrushes_r( brush, hl_dmodels[modelnum].headnode[0] ); + // +#ifdef HL_PRINT + qprintf( "\n" ); +#endif //HL_PRINT + //now we've got a list with brushes! + return brushlist; +} //end of the function HL_CreateBrushesFromBSP +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +bspbrush_t *HL_MergeBrushes( bspbrush_t *brushlist, int modelnum ) { + int nummerges = 0, merged; // TTimo: init + bspbrush_t *b1, *b2, *tail, *newbrush, *newbrushlist; + bspbrush_t *lastb2; + + if ( !brushlist ) { + return NULL; + } + + if ( !modelnum ) { + qprintf( "%5d brushes merged", nummerges = 0 ); + } + do + { + for ( tail = brushlist; tail; tail = tail->next ) + { + if ( !tail->next ) { + break; + } + } //end for + merged = 0; + newbrushlist = NULL; + for ( b1 = brushlist; b1; b1 = brushlist ) + { + lastb2 = b1; + for ( b2 = b1->next; b2; b2 = b2->next ) + { + //can't merge brushes with different contents + if ( b1->side != b2->side ) { + newbrush = NULL; + } else { newbrush = TryMergeBrushes( b1, b2 );} + //if a merged brush is created + if ( newbrush ) { + //copy the brush contents + newbrush->side = b1->side; + //add the new brush to the end of the list + tail->next = newbrush; + //remove the second brush from the list + lastb2->next = b2->next; + //remove the first brush from the list + brushlist = brushlist->next; + //free the merged brushes + FreeBrush( b1 ); + FreeBrush( b2 ); + //get a new tail brush + for ( tail = brushlist; tail; tail = tail->next ) + { + if ( !tail->next ) { + break; + } + } //end for + merged++; + if ( !modelnum ) { + qprintf( "\r%5d", nummerges++ ); + } + break; + } //end if + lastb2 = b2; + } //end for + //if b1 can't be merged with any of the other brushes + if ( !b2 ) { + brushlist = brushlist->next; + //keep b1 + b1->next = newbrushlist; + newbrushlist = b1; + } //end else + } //end for + brushlist = newbrushlist; + } while ( merged ); + if ( !modelnum ) { + qprintf( "\n" ); + } + return newbrushlist; +} //end of the function HL_MergeBrushes +//=========================================================================== +// returns the amount the face and the winding have overlap +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +float HL_FaceOnWinding( hl_dface_t *face, winding_t *winding ) { + int i, edgenum, side; + float dist, area; + hl_dplane_t plane; + vec_t *v1, *v2; + vec3_t normal, edgevec; + winding_t *w; + + // + w = CopyWinding( winding ); + memcpy( &plane, &hl_dplanes[face->planenum], sizeof( hl_dplane_t ) ); + //check on which side of the plane the face is + if ( face->side ) { + VectorNegate( plane.normal, plane.normal ); + plane.dist = -plane.dist; + } //end if + for ( i = 0; i < face->numedges && w; i++ ) + { + //get the first and second vertex of the edge + edgenum = hl_dsurfedges[face->firstedge + i]; + side = edgenum > 0; + //if the face plane is flipped + v1 = hl_dvertexes[hl_dedges[abs( edgenum )].v[side]].point; + v2 = hl_dvertexes[hl_dedges[abs( edgenum )].v[!side]].point; + //create a plane through the edge vector, orthogonal to the face plane + //and with the normal vector pointing out of the face + VectorSubtract( v1, v2, edgevec ); + CrossProduct( edgevec, plane.normal, normal ); + VectorNormalize( normal ); + dist = DotProduct( normal, v1 ); + // + ChopWindingInPlace( &w, normal, dist, 0.9 ); //CLIP_EPSILON + } //end for + if ( w ) { + area = WindingArea( w ); + FreeWinding( w ); + return area; + } //end if + return 0; +} //end of the function HL_FaceOnWinding +//=========================================================================== +// returns a list with brushes created by splitting the given brush with +// planes that go through the face edges and are orthogonal to the face plane +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +bspbrush_t *HL_SplitBrushWithFace( bspbrush_t *brush, hl_dface_t *face ) { + int i, edgenum, side, planenum, splits; + float dist; + hl_dplane_t plane; + vec_t *v1, *v2; + vec3_t normal, edgevec; + bspbrush_t *front, *back, *brushlist; + + memcpy( &plane, &hl_dplanes[face->planenum], sizeof( hl_dplane_t ) ); + //check on which side of the plane the face is + if ( face->side ) { + VectorNegate( plane.normal, plane.normal ); + plane.dist = -plane.dist; + } //end if + splits = 0; + brushlist = NULL; + for ( i = 0; i < face->numedges; i++ ) + { + //get the first and second vertex of the edge + edgenum = hl_dsurfedges[face->firstedge + i]; + side = edgenum > 0; + //if the face plane is flipped + v1 = hl_dvertexes[hl_dedges[abs( edgenum )].v[side]].point; + v2 = hl_dvertexes[hl_dedges[abs( edgenum )].v[!side]].point; + //create a plane through the edge vector, orthogonal to the face plane + //and with the normal vector pointing out of the face + VectorSubtract( v1, v2, edgevec ); + CrossProduct( edgevec, plane.normal, normal ); + VectorNormalize( normal ); + dist = DotProduct( normal, v1 ); + // + planenum = FindFloatPlane( normal, dist ); + //split the current brush + SplitBrush( brush, planenum, &front, &back ); + //if there is a back brush just put it in the list + if ( back ) { + //copy the brush contents + back->side = brush->side; + // + back->next = brushlist; + brushlist = back; + splits++; + } //end if + if ( !front ) { + Log_Print( "HL_SplitBrushWithFace: no new brush\n" ); + FreeBrushList( brushlist ); + return NULL; + } //end if + //copy the brush contents + front->side = brush->side; + //continue splitting the front brush + brush = front; + } //end for + if ( !splits ) { + FreeBrush( front ); + return NULL; + } //end if + front->next = brushlist; + brushlist = front; + return brushlist; +} //end of the function HL_SplitBrushWithFace +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +bspbrush_t *HL_TextureBrushes( bspbrush_t *brushlist, int modelnum ) { + float area, largestarea; + int i, n, texinfonum, sn, numbrushes = 0; // TTimo: init + int bestfacenum, sidenodenum; + side_t *side; + hl_dmiptexlump_t *miptexlump; + hl_miptex_t *miptex; + bspbrush_t *brush, *nextbrush, *prevbrush, *newbrushes, *brushlistend; + vec_t defaultvec[4] = {1, 0, 0, 0}; + + if ( !modelnum ) { + qprintf( "texturing brushes\n" ); + } + if ( !modelnum ) { + qprintf( "%5d brushes", numbrushes = 0 ); + } + //get a pointer to the last brush in the list + for ( brushlistend = brushlist; brushlistend; brushlistend = brushlistend->next ) + { + if ( !brushlistend->next ) { + break; + } + } //end for + //there's no previous brush when at the start of the list + prevbrush = NULL; + //go over the brush list + for ( brush = brushlist; brush; brush = nextbrush ) + { + nextbrush = brush->next; + //find a texinfo for every brush side + for ( sn = 0; sn < brush->numsides; sn++ ) + { + side = &brush->sides[sn]; + // + if ( side->flags & SFL_TEXTURED ) { + continue; + } + //number of the node that created this brush side + sidenodenum = side->surf; //see midwinding in HL_SplitBrush + //no face found yet + bestfacenum = -1; + //minimum face size + largestarea = 1; + //if optimizing the texture placement and not going for the + //least number of brushes + if ( !lessbrushes ) { + for ( i = 0; i < hl_numfaces; i++ ) + { + //the face must be in the same plane as the node plane that created + //this brush side + if ( hl_dfaces[i].planenum == hl_dnodes[sidenodenum].planenum ) { + //get the area the face and the brush side overlap + area = HL_FaceOnWinding( &hl_dfaces[i], side->winding ); + //if this face overlaps the brush side winding more than previous faces + if ( area > largestarea ) { + //if there already was a face for texturing this brush side with + //a different texture + if ( bestfacenum >= 0 && + ( hl_dfaces[bestfacenum].texinfo != hl_dfaces[i].texinfo ) ) { + //split the brush to fit the texture + newbrushes = HL_SplitBrushWithFace( brush, &hl_dfaces[i] ); + //if new brushes where created + if ( newbrushes ) { + //remove the current brush from the list + if ( prevbrush ) { + prevbrush->next = brush->next; + } else { brushlist = brush->next;} + if ( brushlistend == brush ) { + brushlistend = prevbrush; + nextbrush = newbrushes; + } //end if + //add the new brushes to the end of the list + if ( brushlistend ) { + brushlistend->next = newbrushes; + } else { brushlist = newbrushes;} + //free the current brush + FreeBrush( brush ); + //don't forget about the prevbrush pointer at the bottom of + //the outer loop + brush = prevbrush; + //find the end of the list + for ( brushlistend = brushlist; brushlistend; brushlistend = brushlistend->next ) + { + if ( !brushlistend->next ) { + break; + } + } //end for + break; + } //end if + else + { + Log_Write( "brush %d: no real texture split", numbrushes ); + } //end else + } //end if + else + { + //best face for texturing this brush side + bestfacenum = i; + } //end else + } //end if + } //end if + } //end for + //if the brush was split the original brush is removed + //and we just continue with the next one in the list + if ( i < hl_numfaces ) { + break; + } + } //end if + else + { + //find the face with the largest overlap with this brush side + //for texturing the brush side + for ( i = 0; i < hl_numfaces; i++ ) + { + //the face must be in the same plane as the node plane that created + //this brush side + if ( hl_dfaces[i].planenum == hl_dnodes[sidenodenum].planenum ) { + //get the area the face and the brush side overlap + area = HL_FaceOnWinding( &hl_dfaces[i], side->winding ); + //if this face overlaps the brush side winding more than previous faces + if ( area > largestarea ) { + largestarea = area; + bestfacenum = i; + } //end if + } //end if + } //end for + } //end else + //if a face was found for texturing this brush side + if ( bestfacenum >= 0 ) { + //set the MAP texinfo values + texinfonum = hl_dfaces[bestfacenum].texinfo; + for ( n = 0; n < 4; n++ ) + { + map_texinfo[texinfonum].vecs[0][n] = hl_texinfo[texinfonum].vecs[0][n]; + map_texinfo[texinfonum].vecs[1][n] = hl_texinfo[texinfonum].vecs[1][n]; + } //end for + //make sure the two vectors aren't of zero length otherwise use the default + //vector to prevent a divide by zero in the map writing + if ( VectorLength( map_texinfo[texinfonum].vecs[0] ) < 0.01 ) { + memcpy( map_texinfo[texinfonum].vecs[0], defaultvec, sizeof( defaultvec ) ); + } + if ( VectorLength( map_texinfo[texinfonum].vecs[1] ) < 0.01 ) { + memcpy( map_texinfo[texinfonum].vecs[1], defaultvec, sizeof( defaultvec ) ); + } + // + map_texinfo[texinfonum].flags = hl_texinfo[texinfonum].flags; + map_texinfo[texinfonum].value = 0; //HL_ and HL texinfos don't have a value + //the mip texture + miptexlump = (hl_dmiptexlump_t *) hl_dtexdata; + miptex = ( hl_miptex_t * )( (byte *)miptexlump + miptexlump->dataofs[hl_texinfo[texinfonum].miptex] ); + //get the mip texture name + strcpy( map_texinfo[texinfonum].texture, miptex->name ); + //no animations in Quake1 and Half-Life mip textures + map_texinfo[texinfonum].nexttexinfo = -1; + //store the texinfo number + side->texinfo = texinfonum; + // + if ( texinfonum > map_numtexinfo ) { + map_numtexinfo = texinfonum; + } + //this side is textured + side->flags |= SFL_TEXTURED; + } //end if + else + { + //no texture for this side + side->texinfo = TEXINFO_NODE; + //this side is textured + side->flags |= SFL_TEXTURED; + } //end if + } //end for + // + if ( !modelnum && prevbrush != brush ) { + qprintf( "\r%5d", ++numbrushes ); + } + //previous brush in the list + prevbrush = brush; + } //end for + if ( !modelnum ) { + qprintf( "\n" ); + } + //return the new list with brushes + return brushlist; +} //end of the function HL_TextureBrushes +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void HL_FixContentsTextures( bspbrush_t *brushlist ) { + int i, texinfonum; + bspbrush_t *brush; + + for ( brush = brushlist; brush; brush = brush->next ) + { + //only fix the textures of water, slime and lava brushes + if ( brush->side != CONTENTS_WATER && + brush->side != CONTENTS_SLIME && + brush->side != CONTENTS_LAVA ) { + continue; + } + // + for ( i = 0; i < brush->numsides; i++ ) + { + texinfonum = brush->sides[i].texinfo; + if ( HL_TextureContents( map_texinfo[texinfonum].texture ) == brush->side ) { + break; + } + } //end for + //if no specific contents texture was found + if ( i >= brush->numsides ) { + texinfonum = -1; + for ( i = 0; i < map_numtexinfo; i++ ) + { + if ( HL_TextureContents( map_texinfo[i].texture ) == brush->side ) { + texinfonum = i; + break; + } //end if + } //end for + } //end if + // + if ( texinfonum >= 0 ) { + //give all the brush sides this contents texture + for ( i = 0; i < brush->numsides; i++ ) + { + brush->sides[i].texinfo = texinfonum; + } //end for + } //end if + else {Log_Print( "brush contents %d with wrong textures\n", brush->side );} + // + } //end for + /* + for (brush = brushlist; brush; brush = brush->next) + { + //give all the brush sides this contents texture + for (i = 0; i < brush->numsides; i++) + { + if (HL_TextureContents(map_texinfo[texinfonum].texture) != brush->side) + { + Error("brush contents %d with wrong contents textures %s\n", brush->side, + HL_TextureContents(map_texinfo[texinfonum].texture)); + } //end if + } //end for + } //end for*/ +} //end of the function HL_FixContentsTextures +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void HL_BSPBrushToMapBrush( bspbrush_t *bspbrush, entity_t *mapent ) { + mapbrush_t *mapbrush; + side_t *side; + int i, besttexinfo; + + if ( nummapbrushes >= MAX_MAPFILE_BRUSHES ) { + Error( "nummapbrushes == MAX_MAPFILE_BRUSHES" ); + } + + mapbrush = &mapbrushes[nummapbrushes]; + mapbrush->original_sides = &brushsides[nummapbrushsides]; + mapbrush->entitynum = mapent - entities; + mapbrush->brushnum = nummapbrushes - mapent->firstbrush; + mapbrush->leafnum = -1; + mapbrush->numsides = 0; + + besttexinfo = TEXINFO_NODE; + for ( i = 0; i < bspbrush->numsides; i++ ) + { + if ( !bspbrush->sides[i].winding ) { + continue; + } + // + if ( nummapbrushsides >= MAX_MAPFILE_BRUSHSIDES ) { + Error( "MAX_MAPFILE_BRUSHSIDES" ); + } + side = &brushsides[nummapbrushsides]; + //the contents of the bsp brush is stored in the side variable + side->contents = bspbrush->side; + side->surf = 0; + side->planenum = bspbrush->sides[i].planenum; + side->texinfo = bspbrush->sides[i].texinfo; + if ( side->texinfo != TEXINFO_NODE ) { + //this brush side is textured + side->flags |= SFL_TEXTURED; + besttexinfo = side->texinfo; + } //end if + // + nummapbrushsides++; + mapbrush->numsides++; + } //end for + // + if ( besttexinfo == TEXINFO_NODE ) { + mapbrush->numsides = 0; + hl_numclipbrushes++; + return; + } //end if + //set the texinfo for all the brush sides without texture + for ( i = 0; i < mapbrush->numsides; i++ ) + { + if ( mapbrush->original_sides[i].texinfo == TEXINFO_NODE ) { + mapbrush->original_sides[i].texinfo = besttexinfo; + } //end if + } //end for + //contents of the brush + mapbrush->contents = bspbrush->side; + // + if ( create_aas ) { + //create the AAS brushes from this brush, add brush bevels + AAS_CreateMapBrushes( mapbrush, mapent, true ); + return; + } //end if + //create windings for sides and bounds for brush + MakeBrushWindings( mapbrush ); + //add brush bevels + AddBrushBevels( mapbrush ); + //a new brush has been created + nummapbrushes++; + mapent->numbrushes++; +} //end of the function HL_BSPBrushToMapBrush +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void HL_CreateMapBrushes( entity_t *mapent, int modelnum ) { + bspbrush_t *brushlist, *brush, *nextbrush; + int i = 0; //TTimo: init + + //create brushes from the model BSP tree + brushlist = HL_CreateBrushesFromBSP( modelnum ); + //texture the brushes and split them when necesary + brushlist = HL_TextureBrushes( brushlist, modelnum ); + //fix the contents textures of all brushes + HL_FixContentsTextures( brushlist ); + // + if ( !nobrushmerge ) { + brushlist = HL_MergeBrushes( brushlist, modelnum ); + //brushlist = HL_MergeBrushes(brushlist, modelnum); + } //end if + // + if ( !modelnum ) { + qprintf( "converting brushes to map brushes\n" ); + } + if ( !modelnum ) { + qprintf( "%5d brushes", i = 0 ); + } + for ( brush = brushlist; brush; brush = nextbrush ) + { + nextbrush = brush->next; + HL_BSPBrushToMapBrush( brush, mapent ); + brush->next = NULL; + FreeBrush( brush ); + if ( !modelnum ) { + qprintf( "\r%5d", ++i ); + } + } //end for + if ( !modelnum ) { + qprintf( "\n" ); + } +} //end of the function HL_CreateMapBrushes +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void HL_ResetMapLoading( void ) { +} //end of the function HL_ResetMapLoading +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void HL_LoadMapFromBSP( char *filename, int offset, int length ) { + int i, modelnum; + char *model, *classname; + + Log_Print( "-- HL_LoadMapFromBSP --\n" ); + //loaded map type + loadedmaptype = MAPTYPE_HALFLIFE; + // + qprintf( "loading map from %s at %d\n", filename, offset ); + //load the Half-Life BSP file + HL_LoadBSPFile( filename, offset, length ); + // + hl_numclipbrushes = 0; + //parse the entities from the BSP + HL_ParseEntities(); + //clear the map mins and maxs + ClearBounds( map_mins, map_maxs ); + // + qprintf( "creating Half-Life brushes\n" ); + if ( lessbrushes ) { + qprintf( "creating minimum number of brushes\n" ); + } else { qprintf( "placing textures correctly\n" );} + // + for ( i = 0; i < num_entities; i++ ) + { + entities[i].firstbrush = nummapbrushes; + entities[i].numbrushes = 0; + // + classname = ValueForKey( &entities[i], "classname" ); + if ( classname && !strcmp( classname, "worldspawn" ) ) { + modelnum = 0; + } //end if + else + { + // + model = ValueForKey( &entities[i], "model" ); + if ( !model || *model != '*' ) { + continue; + } + model++; + modelnum = atoi( model ); + } //end else + //create map brushes for the entity + HL_CreateMapBrushes( &entities[i], modelnum ); + } //end for + // + qprintf( "%5d map brushes\n", nummapbrushes ); + qprintf( "%5d clip brushes\n", hl_numclipbrushes ); +} //end of the function HL_LoadMapFromBSP diff --git a/Projects/Android/jni/rtcw/src/bspc/map_q1.c b/Projects/Android/jni/rtcw/src/bspc/map_q1.c new file mode 100644 index 0000000..4756915 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/bspc/map_q1.c @@ -0,0 +1,1205 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +//=========================================================================== +// +// Name: map_q1.c +// Function: map loading and writing +// Programmer: Mr Elusive (MrElusive@demigod.demon.nl) +// Last update: 1997-12-03 +// Tab Size: 3 +// NOTES: the recursive splitting of the huge brush sometimes still +// creates bad brushes +//=========================================================================== + +#include "qbsp.h" +#include "l_bsp_q1.h" +#include "aas_map.h" //AAS_CreateMapBrushes + +int q1_numbrushes; +int q1_numclipbrushes; + +//#define Q1_PRINT + +//=========================================================================== +// water, slime and lava brush textures names always start with a * +// followed by the type: "slime", "lava" or otherwise water +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int Q1_TextureContents( char *name ) { + if ( !Q_strcasecmp( name, "clip" ) ) { + return CONTENTS_SOLID; + } + if ( name[0] == '*' ) { + if ( !Q_strncasecmp( name + 1,"lava",4 ) ) { + return CONTENTS_LAVA; + } else if ( !Q_strncasecmp( name + 1,"slime",5 ) ) { + return CONTENTS_SLIME; + } else { return CONTENTS_WATER;} + } //end if + else if ( !Q_strncasecmp( name, "sky", 3 ) ) { + return CONTENTS_SOLID; + } else { return CONTENTS_SOLID;} +} //end of the function Q1_TextureContents +//=========================================================================== +// Generates two new brushes, leaving the original +// unchanged +// +// modified for Half-Life because there are quite a lot of tiny node leaves +// in the Half-Life bsps +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void Q1_SplitBrush( bspbrush_t *brush, int planenum, int nodenum, + bspbrush_t **front, bspbrush_t **back ) { + bspbrush_t *b[2]; + int i, j; + winding_t *w, *cw[2], *midwinding; + plane_t *plane, *plane2; + side_t *s, *cs; + float d, d_front, d_back; + + *front = *back = NULL; + plane = &mapplanes[planenum]; + + // check all points + d_front = d_back = 0; + for ( i = 0 ; i < brush->numsides ; i++ ) + { + w = brush->sides[i].winding; + if ( !w ) { + continue; + } + for ( j = 0 ; j < w->numpoints ; j++ ) + { + d = DotProduct( w->p[j], plane->normal ) - plane->dist; + if ( d > 0 && d > d_front ) { + d_front = d; + } + if ( d < 0 && d < d_back ) { + d_back = d; + } + } //end for + } //end for + + if ( d_front < 0.1 ) { // PLANESIDE_EPSILON) + // only on back + *back = CopyBrush( brush ); + Log_Print( "Q1_SplitBrush: only on back\n" ); + return; + } //end if + if ( d_back > -0.1 ) { // PLANESIDE_EPSILON) + // only on front + *front = CopyBrush( brush ); + Log_Print( "Q1_SplitBrush: only on front\n" ); + return; + } //end if + + // create a new winding from the split plane + + w = BaseWindingForPlane( plane->normal, plane->dist ); + for ( i = 0; i < brush->numsides && w; i++ ) + { + plane2 = &mapplanes[brush->sides[i].planenum ^ 1]; + ChopWindingInPlace( &w, plane2->normal, plane2->dist, 0 ); // PLANESIDE_EPSILON); + } //end for + + if ( !w || WindingIsTiny( w ) ) { // the brush isn't really split + int side; + + Log_Print( "Q1_SplitBrush: no split winding\n" ); + side = BrushMostlyOnSide( brush, plane ); + if ( side == PSIDE_FRONT ) { + *front = CopyBrush( brush ); + } + if ( side == PSIDE_BACK ) { + *back = CopyBrush( brush ); + } + return; + } + + if ( WindingIsHuge( w ) ) { + Log_Print( "Q1_SplitBrush: WARNING huge split winding\n" ); + } //end of + + midwinding = w; + + // split it for real + + for ( i = 0; i < 2; i++ ) + { + b[i] = AllocBrush( brush->numsides + 1 ); + b[i]->original = brush->original; + } //end for + + // split all the current windings + + for ( i = 0 ; i < brush->numsides ; i++ ) + { + s = &brush->sides[i]; + w = s->winding; + if ( !w ) { + continue; + } + ClipWindingEpsilon( w, plane->normal, plane->dist, + 0 /*PLANESIDE_EPSILON*/, &cw[0], &cw[1] ); + for ( j = 0 ; j < 2 ; j++ ) + { + if ( !cw[j] ) { + continue; + } +#if 0 + if ( WindingIsTiny( cw[j] ) ) { + FreeWinding( cw[j] ); + continue; + } +#endif + cs = &b[j]->sides[b[j]->numsides]; + b[j]->numsides++; + *cs = *s; +// cs->planenum = s->planenum; +// cs->texinfo = s->texinfo; +// cs->visible = s->visible; +// cs->original = s->original; + cs->winding = cw[j]; + cs->flags &= ~SFL_TESTED; + } //end for + } //end for + + + // see if we have valid polygons on both sides + + for ( i = 0 ; i < 2 ; i++ ) + { + BoundBrush( b[i] ); + for ( j = 0 ; j < 3 ; j++ ) + { + if ( b[i]->mins[j] < -4096 || b[i]->maxs[j] > 4096 ) { + Log_Print( "Q1_SplitBrush: bogus brush after clip\n" ); + break; + } //end if + } //end for + + if ( b[i]->numsides < 3 || j < 3 ) { + FreeBrush( b[i] ); + b[i] = NULL; + Log_Print( "Q1_SplitBrush: numsides < 3\n" ); + } //end if + } //end for + + if ( !( b[0] && b[1] ) ) { + if ( !b[0] && !b[1] ) { + Log_Print( "Q1_SplitBrush: split removed brush\n" ); + } else { + Log_Print( "Q1_SplitBrush: split not on both sides\n" ); + } + if ( b[0] ) { + FreeBrush( b[0] ); + *front = CopyBrush( brush ); + } //end if + if ( b[1] ) { + FreeBrush( b[1] ); + *back = CopyBrush( brush ); + } //end if + return; + } //end if + + // add the midwinding to both sides + for ( i = 0; i < 2; i++ ) + { + cs = &b[i]->sides[b[i]->numsides]; + b[i]->numsides++; + + cs->planenum = planenum ^ i ^ 1; + cs->texinfo = 0; + //store the node number in the surf to find the texinfo later on + cs->surf = nodenum; + // + cs->flags &= ~SFL_VISIBLE; + cs->flags &= ~SFL_TESTED; + cs->flags &= ~SFL_TEXTURED; + if ( i == 0 ) { + cs->winding = CopyWinding( midwinding ); + } else { + cs->winding = midwinding; + } + } //end for + + + { + vec_t v1; + int i; + + for ( i = 0 ; i < 2 ; i++ ) + { + v1 = BrushVolume( b[i] ); + if ( v1 < 1 ) { + FreeBrush( b[i] ); + b[i] = NULL; + Log_Print( "Q1_SplitBrush: tiny volume after clip\n" ); + } //end if + } //end for + } //*/ + + *front = b[0]; + *back = b[1]; +} //end of the function Q1_SplitBrush +//=========================================================================== +// returns true if the tree starting at nodenum has only solid leaves +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int Q1_SolidTree_r( int nodenum ) { + if ( nodenum < 0 ) { + switch ( q1_dleafs[( -nodenum ) - 1].contents ) + { + case Q1_CONTENTS_EMPTY: + { + return false; + } //end case + case Q1_CONTENTS_SOLID: +#ifdef HLCONTENTS + case Q1_CONTENTS_CLIP: +#endif HLCONTENTS + case Q1_CONTENTS_SKY: +#ifdef HLCONTENTS + case Q1_CONTENTS_TRANSLUCENT: +#endif HLCONTENTS + { + return true; + } //end case + case Q1_CONTENTS_WATER: + case Q1_CONTENTS_SLIME: + case Q1_CONTENTS_LAVA: +#ifdef HLCONTENTS + //these contents should not be found in the BSP + case Q1_CONTENTS_ORIGIN: + case Q1_CONTENTS_CURRENT_0: + case Q1_CONTENTS_CURRENT_90: + case Q1_CONTENTS_CURRENT_180: + case Q1_CONTENTS_CURRENT_270: + case Q1_CONTENTS_CURRENT_UP: + case Q1_CONTENTS_CURRENT_DOWN: +#endif HLCONTENTS + default: + { + return false; + } //end default + } //end switch + return false; + } //end if + if ( !Q1_SolidTree_r( q1_dnodes[nodenum].children[0] ) ) { + return false; + } + if ( !Q1_SolidTree_r( q1_dnodes[nodenum].children[1] ) ) { + return false; + } + return true; +} //end of the function Q1_SolidTree_r +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +bspbrush_t *Q1_CreateBrushes_r( bspbrush_t *brush, int nodenum ) { + int planenum; + bspbrush_t *front, *back; + q1_dleaf_t *leaf; + + //if it is a leaf + if ( nodenum < 0 ) { + leaf = &q1_dleafs[( -nodenum ) - 1]; + if ( leaf->contents != Q1_CONTENTS_EMPTY ) { +#ifdef Q1_PRINT + qprintf( "\r%5i", ++q1_numbrushes ); +#endif //Q1_PRINT + } //end if + switch ( leaf->contents ) + { + case Q1_CONTENTS_EMPTY: + { + FreeBrush( brush ); + return NULL; + } //end case + case Q1_CONTENTS_SOLID: +#ifdef HLCONTENTS + case Q1_CONTENTS_CLIP: +#endif HLCONTENTS + case Q1_CONTENTS_SKY: +#ifdef HLCONTENTS + case Q1_CONTENTS_TRANSLUCENT: +#endif HLCONTENTS + { + brush->side = CONTENTS_SOLID; + return brush; + } //end case + case Q1_CONTENTS_WATER: + { + brush->side = CONTENTS_WATER; + return brush; + } //end case + case Q1_CONTENTS_SLIME: + { + brush->side = CONTENTS_SLIME; + return brush; + } //end case + case Q1_CONTENTS_LAVA: + { + brush->side = CONTENTS_LAVA; + return brush; + } //end case +#ifdef HLCONTENTS + //these contents should not be found in the BSP + case Q1_CONTENTS_ORIGIN: + case Q1_CONTENTS_CURRENT_0: + case Q1_CONTENTS_CURRENT_90: + case Q1_CONTENTS_CURRENT_180: + case Q1_CONTENTS_CURRENT_270: + case Q1_CONTENTS_CURRENT_UP: + case Q1_CONTENTS_CURRENT_DOWN: + { + Error( "Q1_CreateBrushes_r: found contents %d in Half-Life BSP", leaf->contents ); + return NULL; + } //end case +#endif HLCONTENTS + default: + { + Error( "Q1_CreateBrushes_r: unknown contents %d in Half-Life BSP", leaf->contents ); + return NULL; + } //end default + } //end switch + return NULL; + } //end if + //if the rest of the tree is solid + /*if (Q1_SolidTree_r(nodenum)) + { + brush->side = CONTENTS_SOLID; + return brush; + } //end if*/ + // + planenum = q1_dnodes[nodenum].planenum; + planenum = FindFloatPlane( q1_dplanes[planenum].normal, q1_dplanes[planenum].dist ); + //split the brush with the node plane + Q1_SplitBrush( brush, planenum, nodenum, &front, &back ); + //free the original brush + FreeBrush( brush ); + //every node must split the brush in two + if ( !front || !back ) { + Log_Print( "Q1_CreateBrushes_r: WARNING node not splitting brush\n" ); + //return NULL; + } //end if + //create brushes recursively + if ( front ) { + front = Q1_CreateBrushes_r( front, q1_dnodes[nodenum].children[0] ); + } + if ( back ) { + back = Q1_CreateBrushes_r( back, q1_dnodes[nodenum].children[1] ); + } + //link the brushes if possible and return them + if ( front ) { + for ( brush = front; brush->next; brush = brush->next ) ; + brush->next = back; + return front; + } //end if + else + { + return back; + } //end else +} //end of the function Q1_CreateBrushes_r +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +bspbrush_t *Q1_CreateBrushesFromBSP( int modelnum ) { + bspbrush_t *brushlist; + bspbrush_t *brush; + q1_dnode_t *headnode; + vec3_t mins, maxs; + int i; + + // + headnode = &q1_dnodes[q1_dmodels[modelnum].headnode[0]]; + //get the mins and maxs of the world + VectorCopy( headnode->mins, mins ); + VectorCopy( headnode->maxs, maxs ); + //enlarge these mins and maxs + for ( i = 0; i < 3; i++ ) + { + mins[i] -= 8; + maxs[i] += 8; + } //end for + //NOTE: have to add the BSP tree mins and maxs to the MAP mins and maxs + AddPointToBounds( mins, map_mins, map_maxs ); + AddPointToBounds( maxs, map_mins, map_maxs ); + // + if ( !modelnum ) { + Log_Print( "brush size: %5.0f,%5.0f,%5.0f to %5.0f,%5.0f,%5.0f\n", + map_mins[0], map_mins[1], map_mins[2], + map_maxs[0], map_maxs[1], map_maxs[2] ); + } //end if + //create one huge brush containing the whole world + brush = BrushFromBounds( mins, maxs ); + VectorCopy( mins, brush->mins ); + VectorCopy( maxs, brush->maxs ); + // +#ifdef Q1_PRINT + qprintf( "creating Quake brushes\n" ); + qprintf( "%5d brushes", q1_numbrushes = 0 ); +#endif //Q1_PRINT + //create the brushes + brushlist = Q1_CreateBrushes_r( brush, q1_dmodels[modelnum].headnode[0] ); + // +#ifdef Q1_PRINT + qprintf( "\n" ); +#endif //Q1_PRINT + //now we've got a list with brushes! + return brushlist; +} //end of the function Q1_CreateBrushesFromBSP +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +q1_dleaf_t *Q1_PointInLeaf( int startnode, vec3_t point ) { + int nodenum; + vec_t dist; + q1_dnode_t *node; + q1_dplane_t *plane; + + nodenum = startnode; + while ( nodenum >= 0 ) + { + node = &q1_dnodes[nodenum]; + plane = &q1_dplanes[node->planenum]; + dist = DotProduct( point, plane->normal ) - plane->dist; + if ( dist > 0 ) { + nodenum = node->children[0]; + } else { + nodenum = node->children[1]; + } + } //end while + + return &q1_dleafs[-nodenum - 1]; +} //end of the function Q1_PointInLeaf +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +float Q1_FaceArea( q1_dface_t *face ) { + int i; + float total; + vec_t *v; + vec3_t d1, d2, cross; + q1_dedge_t *edge; + + edge = &q1_dedges[face->firstedge]; + v = q1_dvertexes[edge->v[0]].point; + + total = 0; + for ( i = 1; i < face->numedges - 1; i++ ) + { + edge = &q1_dedges[face->firstedge + i]; + VectorSubtract( q1_dvertexes[edge->v[0]].point, v, d1 ); + VectorSubtract( q1_dvertexes[edge->v[1]].point, v, d2 ); + CrossProduct( d1, d2, cross ); + total += 0.5 * VectorLength( cross ); + } //end for + return total; +} //end of the function AAS_FaceArea +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void Q1_FacePlane( q1_dface_t *face, vec3_t normal, float *dist ) { + vec_t *v1, *v2, *v3; + vec3_t vec1, vec2; + int side, edgenum; + + edgenum = q1_dsurfedges[face->firstedge]; + side = edgenum < 0; + v1 = q1_dvertexes[q1_dedges[abs( edgenum )].v[side]].point; + v2 = q1_dvertexes[q1_dedges[abs( edgenum )].v[!side]].point; + edgenum = q1_dsurfedges[face->firstedge + 1]; + side = edgenum < 0; + v3 = q1_dvertexes[q1_dedges[abs( edgenum )].v[!side]].point; + // + VectorSubtract( v2, v1, vec1 ); + VectorSubtract( v3, v1, vec2 ); + + CrossProduct( vec1, vec2, normal ); + VectorNormalize( normal ); + *dist = DotProduct( v1, normal ); +} //end of the function Q1_FacePlane +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +bspbrush_t *Q1_MergeBrushes( bspbrush_t *brushlist, int modelnum ) { + int nummerges = 0, merged; // TTimo: init + bspbrush_t *b1, *b2, *tail, *newbrush, *newbrushlist; + bspbrush_t *lastb2; + + if ( !brushlist ) { + return NULL; + } + + if ( !modelnum ) { + qprintf( "%5d brushes merged", nummerges = 0 ); + } + do + { + for ( tail = brushlist; tail; tail = tail->next ) + { + if ( !tail->next ) { + break; + } + } //end for + merged = 0; + newbrushlist = NULL; + for ( b1 = brushlist; b1; b1 = brushlist ) + { + lastb2 = b1; + for ( b2 = b1->next; b2; b2 = b2->next ) + { + //can't merge brushes with different contents + if ( b1->side != b2->side ) { + newbrush = NULL; + } else { newbrush = TryMergeBrushes( b1, b2 );} + //if a merged brush is created + if ( newbrush ) { + //copy the brush contents + newbrush->side = b1->side; + //add the new brush to the end of the list + tail->next = newbrush; + //remove the second brush from the list + lastb2->next = b2->next; + //remove the first brush from the list + brushlist = brushlist->next; + //free the merged brushes + FreeBrush( b1 ); + FreeBrush( b2 ); + //get a new tail brush + for ( tail = brushlist; tail; tail = tail->next ) + { + if ( !tail->next ) { + break; + } + } //end for + merged++; + if ( !modelnum ) { + qprintf( "\r%5d", nummerges++ ); + } + break; + } //end if + lastb2 = b2; + } //end for + //if b1 can't be merged with any of the other brushes + if ( !b2 ) { + brushlist = brushlist->next; + //keep b1 + b1->next = newbrushlist; + newbrushlist = b1; + } //end else + } //end for + brushlist = newbrushlist; + } while ( merged ); + if ( !modelnum ) { + qprintf( "\n" ); + } + return newbrushlist; +} //end of the function Q1_MergeBrushes +//=========================================================================== +// returns the amount the face and the winding overlap +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +float Q1_FaceOnWinding( q1_dface_t *face, winding_t *winding ) { + int i, edgenum, side; + float dist, area; + q1_dplane_t plane; + vec_t *v1, *v2; + vec3_t normal, edgevec; + winding_t *w; + + // + w = CopyWinding( winding ); + memcpy( &plane, &q1_dplanes[face->planenum], sizeof( q1_dplane_t ) ); + //check on which side of the plane the face is + if ( face->side ) { + VectorNegate( plane.normal, plane.normal ); + plane.dist = -plane.dist; + } //end if + for ( i = 0; i < face->numedges && w; i++ ) + { + //get the first and second vertex of the edge + edgenum = q1_dsurfedges[face->firstedge + i]; + side = edgenum > 0; + //if the face plane is flipped + v1 = q1_dvertexes[q1_dedges[abs( edgenum )].v[side]].point; + v2 = q1_dvertexes[q1_dedges[abs( edgenum )].v[!side]].point; + //create a plane through the edge vector, orthogonal to the face plane + //and with the normal vector pointing out of the face + VectorSubtract( v1, v2, edgevec ); + CrossProduct( edgevec, plane.normal, normal ); + VectorNormalize( normal ); + dist = DotProduct( normal, v1 ); + // + ChopWindingInPlace( &w, normal, dist, 0.9 ); //CLIP_EPSILON + } //end for + if ( w ) { + area = WindingArea( w ); + FreeWinding( w ); + return area; + } //end if + return 0; +} //end of the function Q1_FaceOnWinding +//=========================================================================== +// returns a list with brushes created by splitting the given brush with +// planes that go through the face edges and are orthogonal to the face plane +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +bspbrush_t *Q1_SplitBrushWithFace( bspbrush_t *brush, q1_dface_t *face ) { + int i, edgenum, side, planenum, splits; + float dist; + q1_dplane_t plane; + vec_t *v1, *v2; + vec3_t normal, edgevec; + bspbrush_t *front, *back, *brushlist; + + memcpy( &plane, &q1_dplanes[face->planenum], sizeof( q1_dplane_t ) ); + //check on which side of the plane the face is + if ( face->side ) { + VectorNegate( plane.normal, plane.normal ); + plane.dist = -plane.dist; + } //end if + splits = 0; + brushlist = NULL; + for ( i = 0; i < face->numedges; i++ ) + { + //get the first and second vertex of the edge + edgenum = q1_dsurfedges[face->firstedge + i]; + side = edgenum > 0; + //if the face plane is flipped + v1 = q1_dvertexes[q1_dedges[abs( edgenum )].v[side]].point; + v2 = q1_dvertexes[q1_dedges[abs( edgenum )].v[!side]].point; + //create a plane through the edge vector, orthogonal to the face plane + //and with the normal vector pointing out of the face + VectorSubtract( v1, v2, edgevec ); + CrossProduct( edgevec, plane.normal, normal ); + VectorNormalize( normal ); + dist = DotProduct( normal, v1 ); + // + planenum = FindFloatPlane( normal, dist ); + //split the current brush + SplitBrush( brush, planenum, &front, &back ); + //if there is a back brush just put it in the list + if ( back ) { + //copy the brush contents + back->side = brush->side; + // + back->next = brushlist; + brushlist = back; + splits++; + } //end if + if ( !front ) { + Log_Print( "Q1_SplitBrushWithFace: no new brush\n" ); + FreeBrushList( brushlist ); + return NULL; + } //end if + //copy the brush contents + front->side = brush->side; + //continue splitting the front brush + brush = front; + } //end for + if ( !splits ) { + FreeBrush( front ); + return NULL; + } //end if + front->next = brushlist; + brushlist = front; + return brushlist; +} //end of the function Q1_SplitBrushWithFace +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +bspbrush_t *Q1_TextureBrushes( bspbrush_t *brushlist, int modelnum ) { + float area, largestarea; + int i, n, texinfonum, sn, numbrushes = 0; // TTimo: init + int bestfacenum, sidenodenum; + side_t *side; + q1_dmiptexlump_t *miptexlump; + q1_miptex_t *miptex; + bspbrush_t *brush, *nextbrush, *prevbrush, *newbrushes, *brushlistend; + vec_t defaultvec[4] = {1, 0, 0, 0}; + + if ( !modelnum ) { + qprintf( "texturing brushes\n" ); + } + if ( !modelnum ) { + qprintf( "%5d brushes", numbrushes = 0 ); + } + //get a pointer to the last brush in the list + for ( brushlistend = brushlist; brushlistend; brushlistend = brushlistend->next ) + { + if ( !brushlistend->next ) { + break; + } + } //end for + //there's no previous brush when at the start of the list + prevbrush = NULL; + //go over the brush list + for ( brush = brushlist; brush; brush = nextbrush ) + { + nextbrush = brush->next; + //find a texinfo for every brush side + for ( sn = 0; sn < brush->numsides; sn++ ) + { + side = &brush->sides[sn]; + // + if ( side->flags & SFL_TEXTURED ) { + continue; + } + //number of the node that created this brush side + sidenodenum = side->surf; //see midwinding in Q1_SplitBrush + //no face found yet + bestfacenum = -1; + //minimum face size + largestarea = 1; + //if optimizing the texture placement and not going for the + //least number of brushes + if ( !lessbrushes ) { + for ( i = 0; i < q1_numfaces; i++ ) + { + //the face must be in the same plane as the node plane that created + //this brush side + if ( q1_dfaces[i].planenum == q1_dnodes[sidenodenum].planenum ) { + //get the area the face and the brush side overlap + area = Q1_FaceOnWinding( &q1_dfaces[i], side->winding ); + //if this face overlaps the brush side winding more than previous faces + if ( area > largestarea ) { + //if there already was a face for texturing this brush side with + //a different texture + if ( bestfacenum >= 0 && + ( q1_dfaces[bestfacenum].texinfo != q1_dfaces[i].texinfo ) ) { + //split the brush to fit the texture + newbrushes = Q1_SplitBrushWithFace( brush, &q1_dfaces[i] ); + //if new brushes where created + if ( newbrushes ) { + //remove the current brush from the list + if ( prevbrush ) { + prevbrush->next = brush->next; + } else { brushlist = brush->next;} + if ( brushlistend == brush ) { + brushlistend = prevbrush; + nextbrush = newbrushes; + } //end if + //add the new brushes to the end of the list + if ( brushlistend ) { + brushlistend->next = newbrushes; + } else { brushlist = newbrushes;} + //free the current brush + FreeBrush( brush ); + //don't forget about the prevbrush pointer at the bottom of + //the outer loop + brush = prevbrush; + //find the end of the list + for ( brushlistend = brushlist; brushlistend; brushlistend = brushlistend->next ) + { + if ( !brushlistend->next ) { + break; + } + } //end for + break; + } //end if + else + { + Log_Write( "brush %d: no real texture split", numbrushes ); + } //end else + } //end if + else + { + //best face for texturing this brush side + bestfacenum = i; + } //end else + } //end if + } //end if + } //end for + //if the brush was split the original brush is removed + //and we just continue with the next one in the list + if ( i < q1_numfaces ) { + break; + } + } //end if + else + { + //find the face with the largest overlap with this brush side + //for texturing the brush side + for ( i = 0; i < q1_numfaces; i++ ) + { + //the face must be in the same plane as the node plane that created + //this brush side + if ( q1_dfaces[i].planenum == q1_dnodes[sidenodenum].planenum ) { + //get the area the face and the brush side overlap + area = Q1_FaceOnWinding( &q1_dfaces[i], side->winding ); + //if this face overlaps the brush side winding more than previous faces + if ( area > largestarea ) { + largestarea = area; + bestfacenum = i; + } //end if + } //end if + } //end for + } //end else + //if a face was found for texturing this brush side + if ( bestfacenum >= 0 ) { + //set the MAP texinfo values + texinfonum = q1_dfaces[bestfacenum].texinfo; + for ( n = 0; n < 4; n++ ) + { + map_texinfo[texinfonum].vecs[0][n] = q1_texinfo[texinfonum].vecs[0][n]; + map_texinfo[texinfonum].vecs[1][n] = q1_texinfo[texinfonum].vecs[1][n]; + } //end for + //make sure the two vectors aren't of zero length otherwise use the default + //vector to prevent a divide by zero in the map writing + if ( VectorLength( map_texinfo[texinfonum].vecs[0] ) < 0.01 ) { + memcpy( map_texinfo[texinfonum].vecs[0], defaultvec, sizeof( defaultvec ) ); + } + if ( VectorLength( map_texinfo[texinfonum].vecs[1] ) < 0.01 ) { + memcpy( map_texinfo[texinfonum].vecs[1], defaultvec, sizeof( defaultvec ) ); + } + // + map_texinfo[texinfonum].flags = q1_texinfo[texinfonum].flags; + map_texinfo[texinfonum].value = 0; //Q1 and HL texinfos don't have a value + //the mip texture + miptexlump = (q1_dmiptexlump_t *) q1_dtexdata; + miptex = ( q1_miptex_t * )( (byte *)miptexlump + miptexlump->dataofs[q1_texinfo[texinfonum].miptex] ); + //get the mip texture name + strcpy( map_texinfo[texinfonum].texture, miptex->name ); + //no animations in Quake1 and Half-Life mip textures + map_texinfo[texinfonum].nexttexinfo = -1; + //store the texinfo number + side->texinfo = texinfonum; + // + if ( texinfonum > map_numtexinfo ) { + map_numtexinfo = texinfonum; + } + //this side is textured + side->flags |= SFL_TEXTURED; + } //end if + else + { + //no texture for this side + side->texinfo = TEXINFO_NODE; + //this side is textured + side->flags |= SFL_TEXTURED; + } //end if + } //end for + // + if ( !modelnum && prevbrush != brush ) { + qprintf( "\r%5d", ++numbrushes ); + } + //previous brush in the list + prevbrush = brush; + } //end for + if ( !modelnum ) { + qprintf( "\n" ); + } + //return the new list with brushes + return brushlist; +} //end of the function Q1_TextureBrushes +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void Q1_FixContentsTextures( bspbrush_t *brushlist ) { + int i, texinfonum; + bspbrush_t *brush; + + for ( brush = brushlist; brush; brush = brush->next ) + { + //only fix the textures of water, slime and lava brushes + if ( brush->side != CONTENTS_WATER && + brush->side != CONTENTS_SLIME && + brush->side != CONTENTS_LAVA ) { + continue; + } + // + for ( i = 0; i < brush->numsides; i++ ) + { + texinfonum = brush->sides[i].texinfo; + if ( Q1_TextureContents( map_texinfo[texinfonum].texture ) == brush->side ) { + break; + } + } //end for + //if no specific contents texture was found + if ( i >= brush->numsides ) { + texinfonum = -1; + for ( i = 0; i < map_numtexinfo; i++ ) + { + if ( Q1_TextureContents( map_texinfo[i].texture ) == brush->side ) { + texinfonum = i; + break; + } //end if + } //end for + } //end if + // + if ( texinfonum >= 0 ) { + //give all the brush sides this contents texture + for ( i = 0; i < brush->numsides; i++ ) + { + brush->sides[i].texinfo = texinfonum; + } //end for + } //end if + else {Log_Print( "brush contents %d with wrong textures\n", brush->side );} + // + } //end for + /* + for (brush = brushlist; brush; brush = brush->next) + { + //give all the brush sides this contents texture + for (i = 0; i < brush->numsides; i++) + { + if (Q1_TextureContents(map_texinfo[texinfonum].texture) != brush->side) + { + Error("brush contents %d with wrong contents textures %s\n", brush->side, + Q1_TextureContents(map_texinfo[texinfonum].texture)); + } //end if + } //end for + } //end for*/ +} //end of the function Q1_FixContentsTextures +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void Q1_BSPBrushToMapBrush( bspbrush_t *bspbrush, entity_t *mapent ) { + mapbrush_t *mapbrush; + side_t *side; + int i, besttexinfo; + + CheckBSPBrush( bspbrush ); + + if ( nummapbrushes >= MAX_MAPFILE_BRUSHES ) { + Error( "nummapbrushes == MAX_MAPFILE_BRUSHES" ); + } + + mapbrush = &mapbrushes[nummapbrushes]; + mapbrush->original_sides = &brushsides[nummapbrushsides]; + mapbrush->entitynum = mapent - entities; + mapbrush->brushnum = nummapbrushes - mapent->firstbrush; + mapbrush->leafnum = -1; + mapbrush->numsides = 0; + + besttexinfo = TEXINFO_NODE; + for ( i = 0; i < bspbrush->numsides; i++ ) + { + if ( !bspbrush->sides[i].winding ) { + continue; + } + // + if ( nummapbrushsides >= MAX_MAPFILE_BRUSHSIDES ) { + Error( "MAX_MAPFILE_BRUSHSIDES" ); + } + side = &brushsides[nummapbrushsides]; + //the contents of the bsp brush is stored in the side variable + side->contents = bspbrush->side; + side->surf = 0; + side->planenum = bspbrush->sides[i].planenum; + side->texinfo = bspbrush->sides[i].texinfo; + if ( side->texinfo != TEXINFO_NODE ) { + //this brush side is textured + side->flags |= SFL_TEXTURED; + besttexinfo = side->texinfo; + } //end if + // + nummapbrushsides++; + mapbrush->numsides++; + } //end for + // + if ( besttexinfo == TEXINFO_NODE ) { + mapbrush->numsides = 0; + q1_numclipbrushes++; + return; + } //end if + //set the texinfo for all the brush sides without texture + for ( i = 0; i < mapbrush->numsides; i++ ) + { + if ( mapbrush->original_sides[i].texinfo == TEXINFO_NODE ) { + mapbrush->original_sides[i].texinfo = besttexinfo; + } //end if + } //end for + //contents of the brush + mapbrush->contents = bspbrush->side; + // + if ( create_aas ) { + //create the AAS brushes from this brush, add brush bevels + AAS_CreateMapBrushes( mapbrush, mapent, true ); + return; + } //end if + //create windings for sides and bounds for brush + MakeBrushWindings( mapbrush ); + //add brush bevels + AddBrushBevels( mapbrush ); + //a new brush has been created + nummapbrushes++; + mapent->numbrushes++; +} //end of the function Q1_BSPBrushToMapBrush +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void Q1_CreateMapBrushes( entity_t *mapent, int modelnum ) { + bspbrush_t *brushlist, *brush, *nextbrush; + int i = 0; // TTimo: init + + //create brushes from the model BSP tree + brushlist = Q1_CreateBrushesFromBSP( modelnum ); + //texture the brushes and split them when necesary + brushlist = Q1_TextureBrushes( brushlist, modelnum ); + //fix the contents textures of all brushes + Q1_FixContentsTextures( brushlist ); + // + if ( !nobrushmerge ) { + brushlist = Q1_MergeBrushes( brushlist, modelnum ); + //brushlist = Q1_MergeBrushes(brushlist, modelnum); + } //end if + // + if ( !modelnum ) { + qprintf( "converting brushes to map brushes\n" ); + } + if ( !modelnum ) { + qprintf( "%5d brushes", i = 0 ); + } + for ( brush = brushlist; brush; brush = nextbrush ) + { + nextbrush = brush->next; + Q1_BSPBrushToMapBrush( brush, mapent ); + brush->next = NULL; + FreeBrush( brush ); + if ( !modelnum ) { + qprintf( "\r%5d", ++i ); + } + } //end for + if ( !modelnum ) { + qprintf( "\n" ); + } +} //end of the function Q1_CreateMapBrushes +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void Q1_ResetMapLoading( void ) { +} //end of the function Q1_ResetMapLoading +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void Q1_LoadMapFromBSP( char *filename, int offset, int length ) { + int i, modelnum; + char *model, *classname; + + Log_Print( "-- Q1_LoadMapFromBSP --\n" ); + //the loaded map type + loadedmaptype = MAPTYPE_QUAKE1; + // + qprintf( "loading map from %s at %d\n", filename, offset ); + //load the Half-Life BSP file + Q1_LoadBSPFile( filename, offset, length ); + // + q1_numclipbrushes = 0; + //CreatePath(path); + //Q1_CreateQ2WALFiles(path); + //parse the entities from the BSP + Q1_ParseEntities(); + //clear the map mins and maxs + ClearBounds( map_mins, map_maxs ); + // + qprintf( "creating Quake1 brushes\n" ); + if ( lessbrushes ) { + qprintf( "creating minimum number of brushes\n" ); + } else { qprintf( "placing textures correctly\n" );} + // + for ( i = 0; i < num_entities; i++ ) + { + entities[i].firstbrush = nummapbrushes; + entities[i].numbrushes = 0; + // + classname = ValueForKey( &entities[i], "classname" ); + if ( classname && !strcmp( classname, "worldspawn" ) ) { + modelnum = 0; + } //end if + else + { + // + model = ValueForKey( &entities[i], "model" ); + if ( !model || *model != '*' ) { + continue; + } + model++; + modelnum = atoi( model ); + } //end else + //create map brushes for the entity + Q1_CreateMapBrushes( &entities[i], modelnum ); + } //end for + // + qprintf( "%5d map brushes\n", nummapbrushes ); + qprintf( "%5d clip brushes\n", q1_numclipbrushes ); +} //end of the function Q1_LoadMapFromBSP diff --git a/Projects/Android/jni/rtcw/src/bspc/map_q2.c b/Projects/Android/jni/rtcw/src/bspc/map_q2.c new file mode 100644 index 0000000..1603579 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/bspc/map_q2.c @@ -0,0 +1,1147 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +//=========================================================================== +// +// Name: map_q2.c +// Function: map loading and writing +// Programmer: Mr Elusive (MrElusive@demigod.demon.nl) +// Last update: 1997-12-03 +// Tab Size: 3 +//=========================================================================== + +//=========================================================================== +// ANSI, Area Navigational System Interface +// AAS, Area Awareness System +//=========================================================================== + +#include "qbsp.h" +#include "l_mem.h" +#include "../botlib/aasfile.h" //aas_bbox_t +#include "aas_store.h" //AAS_MAX_BBOXES +#include "aas_cfg.h" +#include "aas_map.h" //AAS_CreateMapBrushes +#include "l_bsp_q2.h" + +#ifdef ME + +#define NODESTACKSIZE 1024 + +int nodestack[NODESTACKSIZE]; +int *nodestackptr; +int nodestacksize = 0; +int brushmodelnumbers[MAX_MAPFILE_BRUSHES]; +int dbrushleafnums[MAX_MAPFILE_BRUSHES]; +int dplanes2mapplanes[MAX_MAPFILE_PLANES]; + +#endif //ME + +//==================================================================== + +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void Q2_CreateMapTexinfo( void ) { + int i; + + for ( i = 0; i < numtexinfo; i++ ) + { + memcpy( map_texinfo[i].vecs, texinfo[i].vecs, sizeof( float ) * 2 * 4 ); + map_texinfo[i].flags = texinfo[i].flags; + map_texinfo[i].value = texinfo[i].value; + strcpy( map_texinfo[i].texture, texinfo[i].texture ); + map_texinfo[i].nexttexinfo = 0; + } //end for +} //end of the function Q2_CreateMapTexinfo + +/* +=========== +Q2_BrushContents +=========== +*/ +int Q2_BrushContents( mapbrush_t *b ) { + int contents; + side_t *s; + int i; + int trans; + + s = &b->original_sides[0]; + contents = s->contents; + trans = texinfo[s->texinfo].flags; + for ( i = 1; i < b->numsides; i++, s++ ) + { + s = &b->original_sides[i]; + trans |= texinfo[s->texinfo].flags; + if ( s->contents != contents ) { + Log_Print( "Entity %i, Brush %i: mixed face contents\n" + , b->entitynum, b->brushnum ); + Log_Print( "texture name = %s\n", texinfo[s->texinfo].texture ); + break; + } + } + + // if any side is translucent, mark the contents + // and change solid to window + if ( trans & ( SURF_TRANS33 | SURF_TRANS66 ) ) { + contents |= CONTENTS_Q2TRANSLUCENT; + if ( contents & CONTENTS_SOLID ) { + contents &= ~CONTENTS_SOLID; + contents |= CONTENTS_WINDOW; + } + } + + return contents; +} + +#ifdef ME + +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void MakeAreaPortalBrush( mapbrush_t *brush ) { + int sn; + side_t *s; + + brush->contents = CONTENTS_AREAPORTAL; + + for ( sn = 0; sn < brush->numsides; sn++ ) + { + s = brush->original_sides + sn; + //make sure the surfaces are not hint or skip + s->surf &= ~( SURF_HINT | SURF_SKIP ); + // + s->texinfo = 0; + s->contents = CONTENTS_AREAPORTAL; + } //end for +} //end of the function MakeAreaPortalBrush +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void DPlanes2MapPlanes( void ) { + int i; + + for ( i = 0; i < numplanes; i++ ) + { + dplanes2mapplanes[i] = FindFloatPlane( dplanes[i].normal, dplanes[i].dist ); + } //end for +} //end of the function DPlanes2MapPlanes +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void MarkVisibleBrushSides( mapbrush_t *brush ) { + int n, i, planenum; + side_t *side; + dface_t *face; + // + for ( n = 0; n < brush->numsides; n++ ) + { + side = brush->original_sides + n; + //if this side is a bevel or the leaf number of the brush is unknown + if ( ( side->flags & SFL_BEVEL ) || brush->leafnum < 0 ) { + //this side is a valid splitter + side->flags |= SFL_VISIBLE; + continue; + } //end if + //assum this side will not be used as a splitter + side->flags &= ~SFL_VISIBLE; + //check if the side plane is used by a visible face + for ( i = 0; i < numfaces; i++ ) + { + face = &dfaces[i]; + planenum = dplanes2mapplanes[face->planenum]; + if ( ( planenum & ~1 ) == ( side->planenum & ~1 ) ) { + //this side is a valid splitter + side->flags |= SFL_VISIBLE; + } //end if + } //end for + } //end for +} //end of the function MarkVisibleBrushSides + +#endif //ME + +/* +================= +Q2_ParseBrush +================= +*/ +void Q2_ParseBrush( script_t *script, entity_t *mapent ) { + mapbrush_t *b; + int i, j, k; + int mt; + side_t *side, *s2; + int planenum; + brush_texture_t td; + int planepts[3][3]; + token_t token; + + if ( nummapbrushes >= MAX_MAPFILE_BRUSHES ) { + Error( "nummapbrushes == MAX_MAPFILE_BRUSHES" ); + } + + b = &mapbrushes[nummapbrushes]; + b->original_sides = &brushsides[nummapbrushsides]; + b->entitynum = num_entities - 1; + b->brushnum = nummapbrushes - mapent->firstbrush; + b->leafnum = -1; + + do + { + if ( !PS_ReadToken( script, &token ) ) { + break; + } + if ( !strcmp( token.string, "}" ) ) { + break; + } + + //IDBUG: mixed use of MAX_MAPFILE_? and MAX_MAP_? this could + // lead to out of bound indexing of the arrays + if ( nummapbrushsides >= MAX_MAPFILE_BRUSHSIDES ) { + Error( "MAX_MAPFILE_BRUSHSIDES" ); + } + side = &brushsides[nummapbrushsides]; + + //read the three point plane definition + for ( i = 0; i < 3; i++ ) + { + if ( i != 0 ) { + PS_ExpectTokenString( script, "(" ); + } + for ( j = 0; j < 3; j++ ) + { + PS_ExpectAnyToken( script, &token ); + planepts[i][j] = atof( token.string ); + } //end for + PS_ExpectTokenString( script, ")" ); + } //end for + + // + //read the texturedef + // + PS_ExpectAnyToken( script, &token ); + strcpy( td.name, token.string ); + + PS_ExpectAnyToken( script, &token ); + td.shift[0] = atol( token.string ); + PS_ExpectAnyToken( script, &token ); + td.shift[1] = atol( token.string ); + PS_ExpectAnyToken( script, &token ); + td.rotate = atol( token.string ); + PS_ExpectAnyToken( script, &token ); + td.scale[0] = atof( token.string ); + PS_ExpectAnyToken( script, &token ); + td.scale[1] = atof( token.string ); + + //find default flags and values + mt = FindMiptex( td.name ); + td.flags = textureref[mt].flags; + td.value = textureref[mt].value; + side->contents = textureref[mt].contents; + side->surf = td.flags = textureref[mt].flags; + + //check if there's a number available + if ( PS_CheckTokenType( script, TT_NUMBER, 0, &token ) ) { + side->contents = token.intvalue; + PS_ExpectTokenType( script, TT_NUMBER, 0, &token ); + side->surf = td.flags = token.intvalue; + PS_ExpectTokenType( script, TT_NUMBER, 0, &token ); + td.value = token.intvalue; + } + + // translucent objects are automatically classified as detail + if ( side->surf & ( SURF_TRANS33 | SURF_TRANS66 ) ) { + side->contents |= CONTENTS_DETAIL; + } + if ( side->contents & ( CONTENTS_PLAYERCLIP | CONTENTS_MONSTERCLIP ) ) { + side->contents |= CONTENTS_DETAIL; + } + if ( fulldetail ) { + side->contents &= ~CONTENTS_DETAIL; + } + if ( !( side->contents & ( ( LAST_VISIBLE_CONTENTS - 1 ) + | CONTENTS_PLAYERCLIP | CONTENTS_MONSTERCLIP | CONTENTS_MIST ) ) ) { + side->contents |= CONTENTS_SOLID; + } + + // hints and skips are never detail, and have no content + if ( side->surf & ( SURF_HINT | SURF_SKIP ) ) { + side->contents = 0; + side->surf &= ~CONTENTS_DETAIL; + } + +#ifdef ME + //for creating AAS... this side is textured + side->flags |= SFL_TEXTURED; +#endif //ME + // + // find the plane number + // + planenum = PlaneFromPoints( planepts[0], planepts[1], planepts[2] ); + if ( planenum == -1 ) { + Log_Print( "Entity %i, Brush %i: plane with no normal\n" + , b->entitynum, b->brushnum ); + continue; + } + + // + // see if the plane has been used already + // + for ( k = 0 ; k < b->numsides ; k++ ) + { + s2 = b->original_sides + k; + if ( s2->planenum == planenum ) { + Log_Print( "Entity %i, Brush %i: duplicate plane\n" + , b->entitynum, b->brushnum ); + break; + } + if ( s2->planenum == ( planenum ^ 1 ) ) { + Log_Print( "Entity %i, Brush %i: mirrored plane\n" + , b->entitynum, b->brushnum ); + break; + } + } + if ( k != b->numsides ) { + continue; // duplicated + + } + // + // keep this side + // + + side = b->original_sides + b->numsides; + side->planenum = planenum; + side->texinfo = TexinfoForBrushTexture( &mapplanes[planenum], + &td, vec3_origin ); + + // save the td off in case there is an origin brush and we + // have to recalculate the texinfo + side_brushtextures[nummapbrushsides] = td; + + nummapbrushsides++; + b->numsides++; + } while ( 1 ); + + // get the content for the entire brush + b->contents = Q2_BrushContents( b ); + +#ifdef ME + if ( BrushExists( b ) ) { + c_squattbrushes++; + b->numsides = 0; + return; + } //end if + + if ( create_aas ) { + //create AAS brushes, and add brush bevels + AAS_CreateMapBrushes( b, mapent, true ); + //NOTE: if we return here then duplicate plane errors occur for the non world entities + return; + } //end if +#endif //ME + + // allow detail brushes to be removed + if ( nodetail && ( b->contents & CONTENTS_DETAIL ) ) { + b->numsides = 0; + return; + } + + // allow water brushes to be removed + if ( nowater && ( b->contents & ( CONTENTS_LAVA | CONTENTS_SLIME | CONTENTS_WATER ) ) ) { + b->numsides = 0; + return; + } + + // create windings for sides and bounds for brush + MakeBrushWindings( b ); + + // brushes that will not be visible at all will never be + // used as bsp splitters + if ( b->contents & ( CONTENTS_PLAYERCLIP | CONTENTS_MONSTERCLIP ) ) { + c_clipbrushes++; + for ( i = 0 ; i < b->numsides ; i++ ) + b->original_sides[i].texinfo = TEXINFO_NODE; + } + + // + // origin brushes are removed, but they set + // the rotation origin for the rest of the brushes + // in the entity. After the entire entity is parsed, + // the planenums and texinfos will be adjusted for + // the origin brush + // + if ( b->contents & CONTENTS_ORIGIN ) { + char string[32]; + vec3_t origin; + + if ( num_entities == 1 ) { + Error( "Entity %i, Brush %i: origin brushes not allowed in world" + , b->entitynum, b->brushnum ); + return; + } + + VectorAdd( b->mins, b->maxs, origin ); + VectorScale( origin, 0.5, origin ); + + sprintf( string, "%i %i %i", (int)origin[0], (int)origin[1], (int)origin[2] ); + SetKeyValue( &entities[b->entitynum], "origin", string ); + + VectorCopy( origin, entities[b->entitynum].origin ); + + // don't keep this brush + b->numsides = 0; + + return; + } + + AddBrushBevels( b ); + + nummapbrushes++; + mapent->numbrushes++; +} + +/* +================ +Q2_MoveBrushesToWorld + +Takes all of the brushes from the current entity and +adds them to the world's brush list. + +Used by func_group and func_areaportal +================ +*/ +void Q2_MoveBrushesToWorld( entity_t *mapent ) { + int newbrushes; + int worldbrushes; + mapbrush_t *temp; + int i; + + // this is pretty gross, because the brushes are expected to be + // in linear order for each entity + + newbrushes = mapent->numbrushes; + worldbrushes = entities[0].numbrushes; + + temp = GetMemory( newbrushes * sizeof( mapbrush_t ) ); + memcpy( temp, mapbrushes + mapent->firstbrush, newbrushes * sizeof( mapbrush_t ) ); + +#if 0 // let them keep their original brush numbers + for ( i = 0 ; i < newbrushes ; i++ ) + temp[i].entitynum = 0; +#endif + + // make space to move the brushes (overlapped copy) + memmove( mapbrushes + worldbrushes + newbrushes, + mapbrushes + worldbrushes, + sizeof( mapbrush_t ) * ( nummapbrushes - worldbrushes - newbrushes ) ); + + // copy the new brushes down + memcpy( mapbrushes + worldbrushes, temp, sizeof( mapbrush_t ) * newbrushes ); + + // fix up indexes + entities[0].numbrushes += newbrushes; + for ( i = 1 ; i < num_entities ; i++ ) + entities[i].firstbrush += newbrushes; + FreeMemory( temp ); + + mapent->numbrushes = 0; +} + +/* +================ +Q2_ParseMapEntity +================ +*/ +qboolean Q2_ParseMapEntity( script_t *script ) { + entity_t *mapent; + epair_t *e; + side_t *s; + int i, j; + int startbrush, startsides; + vec_t newdist; + mapbrush_t *b; + token_t token; + + if ( !PS_ReadToken( script, &token ) ) { + return false; + } + + if ( strcmp( token.string, "{" ) ) { + Error( "ParseEntity: { not found" ); + } + + if ( num_entities == MAX_MAP_ENTITIES ) { + Error( "num_entities == MAX_MAP_ENTITIES" ); + } + + startbrush = nummapbrushes; + startsides = nummapbrushsides; + + mapent = &entities[num_entities]; + num_entities++; + memset( mapent, 0, sizeof( *mapent ) ); + mapent->firstbrush = nummapbrushes; + mapent->numbrushes = 0; +// mapent->portalareas[0] = -1; +// mapent->portalareas[1] = -1; + + do + { + if ( !PS_ReadToken( script, &token ) ) { + Error( "ParseEntity: EOF without closing brace" ); + } //end if + if ( !strcmp( token.string, "}" ) ) { + break; + } + if ( !strcmp( token.string, "{" ) ) { + Q2_ParseBrush( script, mapent ); + } //end if + else + { + PS_UnreadLastToken( script ); + e = ParseEpair( script ); + e->next = mapent->epairs; + mapent->epairs = e; + } //end else + } while ( 1 ); + + GetVectorForKey( mapent, "origin", mapent->origin ); + + // + // if there was an origin brush, offset all of the planes and texinfo + // + if ( mapent->origin[0] || mapent->origin[1] || mapent->origin[2] ) { + for ( i = 0 ; i < mapent->numbrushes ; i++ ) + { + b = &mapbrushes[mapent->firstbrush + i]; + for ( j = 0 ; j < b->numsides ; j++ ) + { + s = &b->original_sides[j]; + newdist = mapplanes[s->planenum].dist - + DotProduct( mapplanes[s->planenum].normal, mapent->origin ); + s->planenum = FindFloatPlane( mapplanes[s->planenum].normal, newdist ); + s->texinfo = TexinfoForBrushTexture( &mapplanes[s->planenum], + &side_brushtextures[s - brushsides], mapent->origin ); + } + MakeBrushWindings( b ); + } + } + + // group entities are just for editor convenience + // toss all brushes into the world entity + if ( !strcmp( "func_group", ValueForKey( mapent, "classname" ) ) ) { + Q2_MoveBrushesToWorld( mapent ); + mapent->numbrushes = 0; + return true; + } + + // areaportal entities move their brushes, but don't eliminate + // the entity + if ( !strcmp( "func_areaportal", ValueForKey( mapent, "classname" ) ) ) { + char str[128]; + + if ( mapent->numbrushes != 1 ) { + Error( "Entity %i: func_areaportal can only be a single brush", num_entities - 1 ); + } + + b = &mapbrushes[nummapbrushes - 1]; + b->contents = CONTENTS_AREAPORTAL; + c_areaportals++; + mapent->areaportalnum = c_areaportals; + // set the portal number as "style" + sprintf( str, "%i", c_areaportals ); + SetKeyValue( mapent, "style", str ); + Q2_MoveBrushesToWorld( mapent ); + return true; + } + + return true; +} + +//=================================================================== + +/* +================ +LoadMapFile +================ +*/ +void Q2_LoadMapFile( char *filename ) { + int i; + script_t *script; + + Log_Print( "-- Q2_LoadMapFile --\n" ); +#ifdef ME + //loaded map type + loadedmaptype = MAPTYPE_QUAKE2; + //reset the map loading + ResetMapLoading(); +#endif //ME + + script = LoadScriptFile( filename ); + if ( !script ) { + Log_Print( "couldn't open %s\n", filename ); + return; + } //end if + //white spaces and escape characters inside a string are not allowed + SetScriptFlags( script, SCFL_NOSTRINGWHITESPACES | + SCFL_NOSTRINGESCAPECHARS | + SCFL_PRIMITIVE ); + + nummapbrushsides = 0; + num_entities = 0; + + while ( Q2_ParseMapEntity( script ) ) + { + } + + ClearBounds( map_mins, map_maxs ); + for ( i = 0 ; i < entities[0].numbrushes ; i++ ) + { + if ( mapbrushes[i].mins[0] > 4096 ) { + continue; // no valid points + } + AddPointToBounds( mapbrushes[i].mins, map_mins, map_maxs ); + AddPointToBounds( mapbrushes[i].maxs, map_mins, map_maxs ); + } //end for + + PrintMapInfo(); + + //free the script + FreeScript( script ); +// TestExpandBrushes (); + // + Q2_CreateMapTexinfo(); +} //end of the function Q2_LoadMapFile + +#ifdef ME //Begin MAP loading from BSP file +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void Q2_SetLeafBrushesModelNumbers( int leafnum, int modelnum ) { + int i, brushnum; + dleaf_t *leaf; + + leaf = &dleafs[leafnum]; + for ( i = 0; i < leaf->numleafbrushes; i++ ) + { + brushnum = dleafbrushes[leaf->firstleafbrush + i]; + brushmodelnumbers[brushnum] = modelnum; + dbrushleafnums[brushnum] = leafnum; + } //end for +} //end of the function Q2_SetLeafBrushesModelNumbers +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void Q2_InitNodeStack( void ) { + nodestackptr = nodestack; + nodestacksize = 0; +} //end of the function Q2_InitNodeStack +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void Q2_PushNodeStack( int num ) { + *nodestackptr = num; + nodestackptr++; + nodestacksize++; + // + if ( nodestackptr >= &nodestack[NODESTACKSIZE] ) { + Error( "Q2_PushNodeStack: stack overflow\n" ); + } //end if +} //end of the function Q2_PushNodeStack +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int Q2_PopNodeStack( void ) { + //if the stack is empty + if ( nodestackptr <= nodestack ) { + return -1; + } + //decrease stack pointer + nodestackptr--; + nodestacksize--; + //return the top value from the stack + return *nodestackptr; +} //end of the function Q2_PopNodeStack +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void Q2_SetBrushModelNumbers( entity_t *mapent ) { + int n, pn; + int leafnum; + + // + Q2_InitNodeStack(); + //head node (root) of the bsp tree + n = dmodels[mapent->modelnum].headnode; + pn = 0; + + do + { + //if we are in a leaf (negative node number) + if ( n < 0 ) { + //number of the leaf + leafnum = ( -n ) - 1; + //set the brush numbers + Q2_SetLeafBrushesModelNumbers( leafnum, mapent->modelnum ); + //walk back into the tree to find a second child to continue with + for ( pn = Q2_PopNodeStack(); pn >= 0; n = pn, pn = Q2_PopNodeStack() ) + { + //if we took the first child at the parent node + if ( dnodes[pn].children[0] == n ) { + break; + } + } //end for + //if the stack wasn't empty (if not processed whole tree) + if ( pn >= 0 ) { + //push the parent node again + Q2_PushNodeStack( pn ); + //we proceed with the second child of the parent node + n = dnodes[pn].children[1]; + } //end if + } //end if + else + { + //push the current node onto the stack + Q2_PushNodeStack( n ); + //walk forward into the tree to the first child + n = dnodes[n].children[0]; + } //end else + } while ( pn >= 0 ); +} //end of the function Q2_SetBrushModelNumbers +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void Q2_BSPBrushToMapBrush( dbrush_t *bspbrush, entity_t *mapent ) { + mapbrush_t *b; + int i, k, n; + side_t *side, *s2; + int planenum; + dbrushside_t *bspbrushside; + dplane_t *bspplane; + + if ( nummapbrushes >= MAX_MAPFILE_BRUSHES ) { + Error( "nummapbrushes >= MAX_MAPFILE_BRUSHES" ); + } + + b = &mapbrushes[nummapbrushes]; + b->original_sides = &brushsides[nummapbrushsides]; + b->entitynum = mapent - entities; + b->brushnum = nummapbrushes - mapent->firstbrush; + b->leafnum = dbrushleafnums[bspbrush - dbrushes]; + + for ( n = 0; n < bspbrush->numsides; n++ ) + { + //pointer to the bsp brush side + bspbrushside = &dbrushsides[bspbrush->firstside + n]; + + if ( nummapbrushsides >= MAX_MAPFILE_BRUSHSIDES ) { + Error( "MAX_MAPFILE_BRUSHSIDES" ); + } //end if + //pointer to the map brush side + side = &brushsides[nummapbrushsides]; + //if the BSP brush side is textured + if ( brushsidetextured[bspbrush->firstside + n] ) { + side->flags |= SFL_TEXTURED; + } else { side->flags &= ~SFL_TEXTURED;} + //ME: can get side contents and surf directly from BSP file + side->contents = bspbrush->contents; + //if the texinfo is TEXINFO_NODE + if ( bspbrushside->texinfo < 0 ) { + side->surf = 0; + } else { side->surf = texinfo[bspbrushside->texinfo].flags;} + + // translucent objects are automatically classified as detail + if ( side->surf & ( SURF_TRANS33 | SURF_TRANS66 ) ) { + side->contents |= CONTENTS_DETAIL; + } + if ( side->contents & ( CONTENTS_PLAYERCLIP | CONTENTS_MONSTERCLIP ) ) { + side->contents |= CONTENTS_DETAIL; + } + if ( fulldetail ) { + side->contents &= ~CONTENTS_DETAIL; + } + if ( !( side->contents & ( ( LAST_VISIBLE_CONTENTS - 1 ) + | CONTENTS_PLAYERCLIP | CONTENTS_MONSTERCLIP | CONTENTS_MIST ) ) ) { + side->contents |= CONTENTS_SOLID; + } + + // hints and skips are never detail, and have no content + if ( side->surf & ( SURF_HINT | SURF_SKIP ) ) { + side->contents = 0; + side->surf &= ~CONTENTS_DETAIL; + } + + //ME: get a plane for this side + bspplane = &dplanes[bspbrushside->planenum]; + planenum = FindFloatPlane( bspplane->normal, bspplane->dist ); + // + // see if the plane has been used already + // + //ME: this really shouldn't happen!!! + //ME: otherwise the bsp file is corrupted?? + //ME: still it seems to happen, maybe Johny Boy's + //ME: brush bevel adding is crappy ? + for ( k = 0; k < b->numsides; k++ ) + { + s2 = b->original_sides + k; +// if (DotProduct (mapplanes[s2->planenum].normal, mapplanes[planenum].normal) > 0.999 +// && fabs(mapplanes[s2->planenum].dist - mapplanes[planenum].dist) < 0.01 ) + + if ( s2->planenum == planenum ) { + Log_Print( "Entity %i, Brush %i: duplicate plane\n" + , b->entitynum, b->brushnum ); + break; + } + if ( s2->planenum == ( planenum ^ 1 ) ) { + Log_Print( "Entity %i, Brush %i: mirrored plane\n" + , b->entitynum, b->brushnum ); + break; + } + } + if ( k != b->numsides ) { + continue; // duplicated + + } + // + // keep this side + // + //ME: reset pointer to side, why? hell I dunno (pointer is set above already) + side = b->original_sides + b->numsides; + //ME: store the plane number + side->planenum = planenum; + //ME: texinfo is already stored when bsp is loaded + //NOTE: check for TEXINFO_NODE, otherwise crash in Q2_BrushContents + if ( bspbrushside->texinfo < 0 ) { + side->texinfo = 0; + } else { side->texinfo = bspbrushside->texinfo;} + + // save the td off in case there is an origin brush and we + // have to recalculate the texinfo + // ME: don't need to recalculate because it's already done + // (for non-world entities) in the BSP file +// side_brushtextures[nummapbrushsides] = td; + + nummapbrushsides++; + b->numsides++; + } //end for + + // get the content for the entire brush + b->contents = bspbrush->contents; + Q2_BrushContents( b ); + + if ( BrushExists( b ) ) { + c_squattbrushes++; + b->numsides = 0; + return; + } //end if + + //if we're creating AAS + if ( create_aas ) { + //create the AAS brushes from this brush, don't add brush bevels + AAS_CreateMapBrushes( b, mapent, false ); + return; + } //end if + + // allow detail brushes to be removed + if ( nodetail && ( b->contents & CONTENTS_DETAIL ) ) { + b->numsides = 0; + return; + } //end if + + // allow water brushes to be removed + if ( nowater && ( b->contents & ( CONTENTS_LAVA | CONTENTS_SLIME | CONTENTS_WATER ) ) ) { + b->numsides = 0; + return; + } //end if + + // create windings for sides and bounds for brush + MakeBrushWindings( b ); + + //mark brushes without winding or with a tiny window as bevels + MarkBrushBevels( b ); + + // brushes that will not be visible at all will never be + // used as bsp splitters + if ( b->contents & ( CONTENTS_PLAYERCLIP | CONTENTS_MONSTERCLIP ) ) { + c_clipbrushes++; + for ( i = 0; i < b->numsides; i++ ) + b->original_sides[i].texinfo = TEXINFO_NODE; + } //end for + + // + // origin brushes are removed, but they set + // the rotation origin for the rest of the brushes + // in the entity. After the entire entity is parsed, + // the planenums and texinfos will be adjusted for + // the origin brush + // + //ME: not needed because the entities in the BSP file already + // have an origin set +// if (b->contents & CONTENTS_ORIGIN) +// { +// char string[32]; +// vec3_t origin; +// +// if (num_entities == 1) +// { +// Error ("Entity %i, Brush %i: origin brushes not allowed in world" +// , b->entitynum, b->brushnum); +// return; +// } +// +// VectorAdd (b->mins, b->maxs, origin); +// VectorScale (origin, 0.5, origin); +// +// sprintf (string, "%i %i %i", (int)origin[0], (int)origin[1], (int)origin[2]); +// SetKeyValue (&entities[b->entitynum], "origin", string); +// +// VectorCopy (origin, entities[b->entitynum].origin); +// +// // don't keep this brush +// b->numsides = 0; +// +// return; +// } + + //ME: the bsp brushes already have bevels, so we won't try to + // add them again (especially since Johny Boy's bevel adding might + // be crappy) +// AddBrushBevels(b); + + nummapbrushes++; + mapent->numbrushes++; +} //end of the function Q2_BSPBrushToMapBrush +//=========================================================================== +//=========================================================================== +void Q2_ParseBSPBrushes( entity_t *mapent ) { + int i; + + //give all the brushes that belong to this entity the number of the + //BSP model used by this entity + Q2_SetBrushModelNumbers( mapent ); + //now parse all the brushes with the correct mapent->modelnum + for ( i = 0; i < numbrushes; i++ ) + { + if ( brushmodelnumbers[i] == mapent->modelnum ) { + Q2_BSPBrushToMapBrush( &dbrushes[i], mapent ); + } //end if + } //end for +} //end of the function Q2_ParseBSPBrushes +//=========================================================================== +//=========================================================================== +qboolean Q2_ParseBSPEntity( int entnum ) { + entity_t *mapent; + char *model; + int startbrush, startsides; + + startbrush = nummapbrushes; + startsides = nummapbrushsides; + + mapent = &entities[entnum]; //num_entities]; + mapent->firstbrush = nummapbrushes; + mapent->numbrushes = 0; + mapent->modelnum = -1; //-1 = no model + + model = ValueForKey( mapent, "model" ); + if ( model && strlen( model ) ) { + if ( *model != '*' ) { + Error( "Q2_ParseBSPEntity: model number without leading *" ); + } //end if + //get the model number of this entity (skip the leading *) + mapent->modelnum = atoi( &model[1] ); + } //end if + + GetVectorForKey( mapent, "origin", mapent->origin ); + + //if this is the world entity it has model number zero + //the world entity has no model key + if ( !strcmp( "worldspawn", ValueForKey( mapent, "classname" ) ) ) { + mapent->modelnum = 0; + } //end if + //if the map entity has a BSP model (a modelnum of -1 is used for + //entities that aren't using a BSP model) + if ( mapent->modelnum >= 0 ) { + //parse the bsp brushes + Q2_ParseBSPBrushes( mapent ); + } //end if + // + //the origin of the entity is already taken into account + // + //func_group entities can't be in the bsp file + // + //check out the func_areaportal entities + if ( !strcmp( "func_areaportal", ValueForKey( mapent, "classname" ) ) ) { + c_areaportals++; + mapent->areaportalnum = c_areaportals; + return true; + } //end if + return true; +} //end of the function Q2_ParseBSPEntity +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void Q2_LoadMapFromBSP( char *filename, int offset, int length ) { + int i; + + Log_Print( "-- Q2_LoadMapFromBSP --\n" ); + //loaded map type + loadedmaptype = MAPTYPE_QUAKE2; + + Log_Print( "Loading map from %s...\n", filename ); + //load the bsp file + Q2_LoadBSPFile( filename, offset, length ); + + //create an index from bsp planes to map planes + //DPlanes2MapPlanes(); + //clear brush model numbers + for ( i = 0; i < MAX_MAPFILE_BRUSHES; i++ ) + brushmodelnumbers[i] = -1; + + nummapbrushsides = 0; + num_entities = 0; + + Q2_ParseEntities(); + // + for ( i = 0; i < num_entities; i++ ) + { + Q2_ParseBSPEntity( i ); + } //end for + + //get the map mins and maxs from the world model + ClearBounds( map_mins, map_maxs ); + for ( i = 0; i < entities[0].numbrushes; i++ ) + { + if ( mapbrushes[i].mins[0] > 4096 ) { + continue; //no valid points + } + AddPointToBounds( mapbrushes[i].mins, map_mins, map_maxs ); + AddPointToBounds( mapbrushes[i].maxs, map_mins, map_maxs ); + } //end for + + PrintMapInfo(); + // + Q2_CreateMapTexinfo(); +} //end of the function Q2_LoadMapFromBSP + +void Q2_ResetMapLoading( void ) { + //reset for map loading from bsp + memset( nodestack, 0, NODESTACKSIZE * sizeof( int ) ); + nodestackptr = NULL; + nodestacksize = 0; + memset( brushmodelnumbers, 0, MAX_MAPFILE_BRUSHES * sizeof( int ) ); +} //end of the function Q2_ResetMapLoading + +//End MAP loading from BSP file +#endif //ME + +//==================================================================== + +/* +================ +TestExpandBrushes + +Expands all the brush planes and saves a new map out +================ +*/ +void TestExpandBrushes( void ) { + FILE *f; + side_t *s; + int i, j, bn; + winding_t *w; + char *name = "expanded.map"; + mapbrush_t *brush; + vec_t dist; + + Log_Print( "writing %s\n", name ); + f = fopen( name, "wb" ); + if ( !f ) { + Error( "Can't write %s\n", name ); + } + + fprintf( f, "{\n\"classname\" \"worldspawn\"\n" ); + + for ( bn = 0 ; bn < nummapbrushes ; bn++ ) + { + brush = &mapbrushes[bn]; + fprintf( f, "{\n" ); + for ( i = 0 ; i < brush->numsides ; i++ ) + { + s = brush->original_sides + i; + dist = mapplanes[s->planenum].dist; + for ( j = 0 ; j < 3 ; j++ ) + dist += fabs( 16 * mapplanes[s->planenum].normal[j] ); + + w = BaseWindingForPlane( mapplanes[s->planenum].normal, dist ); + + fprintf( f,"( %i %i %i ) ", (int)w->p[0][0], (int)w->p[0][1], (int)w->p[0][2] ); + fprintf( f,"( %i %i %i ) ", (int)w->p[1][0], (int)w->p[1][1], (int)w->p[1][2] ); + fprintf( f,"( %i %i %i ) ", (int)w->p[2][0], (int)w->p[2][1], (int)w->p[2][2] ); + + fprintf( f, "%s 0 0 0 1 1\n", texinfo[s->texinfo].texture ); + FreeWinding( w ); + } + fprintf( f, "}\n" ); + } + fprintf( f, "}\n" ); + + fclose( f ); + + Error( "can't proceed after expanding brushes" ); +} //end of the function TestExpandBrushes + diff --git a/Projects/Android/jni/rtcw/src/bspc/map_q3.c b/Projects/Android/jni/rtcw/src/bspc/map_q3.c new file mode 100644 index 0000000..5cc64a6 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/bspc/map_q3.c @@ -0,0 +1,729 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +//=========================================================================== +// +// Name: map_q3.c +// Function: map loading +// Programmer: Mr Elusive (MrElusive@demigod.demon.nl) +// Last update: 1999-07-02 +// Tab Size: 3 +//=========================================================================== + +#include "qbsp.h" +#include "l_mem.h" +#include "../botlib/aasfile.h" //aas_bbox_t +#include "aas_store.h" //AAS_MAX_BBOXES +#include "aas_cfg.h" +#include "aas_map.h" //AAS_CreateMapBrushes +#include "l_bsp_q3.h" +#include "../qcommon/cm_patch.h" +#include "../game/surfaceflags.h" + +#define NODESTACKSIZE 1024 +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void PrintContents( int contents ); + +int Q3_BrushContents( mapbrush_t *b ) { + int contents, i, mixed, hint; + side_t *s; + + s = &b->original_sides[0]; + contents = s->contents; + // + mixed = false; + hint = false; + for ( i = 1; i < b->numsides; i++ ) + { + s = &b->original_sides[i]; + if ( s->contents != contents ) { + mixed = true; + } + if ( s->surf & ( SURF_HINT | SURF_SKIP ) ) { + hint = true; + } + contents |= s->contents; + } //end for + // + if ( hint ) { + if ( contents ) { + Log_Write( "WARNING: hint brush with contents: " ); + PrintContents( contents ); + Log_Write( "\r\n" ); + // + Log_Write( "brush contents is: " ); + PrintContents( b->contents ); + Log_Write( "\r\n" ); + } //end if + return 0; + } //end if + //Log_Write("brush %d contents ", nummapbrushes); + //PrintContents(contents); + //Log_Write("\r\n"); + //remove ladder and fog contents + contents &= ~( CONTENTS_LADDER | CONTENTS_FOG ); + // + if ( mixed ) { + Log_Write( "Entity %i, Brush %i: mixed face contents " + , b->entitynum, b->brushnum ); + PrintContents( contents ); + Log_Write( "\r\n" ); + // + Log_Write( "brush contents is: " ); + PrintContents( b->contents ); + Log_Write( "\r\n" ); + // + if ( contents & CONTENTS_DONOTENTER ) { + return CONTENTS_DONOTENTER; //Log_Print("mixed contents with donotenter\n"); + } + /* + Log_Print("contents:"); PrintContents(contents); + Log_Print("\ncontents:"); PrintContents(s->contents); + Log_Print("\n"); + Log_Print("texture name = %s\n", texinfo[s->texinfo].texture); + */ + //if liquid brush + if ( contents & ( CONTENTS_LAVA | CONTENTS_SLIME | CONTENTS_WATER ) ) { + return ( contents & ( CONTENTS_LAVA | CONTENTS_SLIME | CONTENTS_WATER ) ); + } //end if + if ( contents & CONTENTS_PLAYERCLIP ) { + return ( contents & CONTENTS_PLAYERCLIP ); + } + return ( contents & CONTENTS_SOLID ); + } //end if + /* + if (contents & CONTENTS_AREAPORTAL) + { + static int num; + Log_Write("Entity %i, Brush %i: area portal %d\r\n", b->entitynum, b->brushnum, num++); + } //end if*/ + if ( contents == ( contents & CONTENTS_STRUCTURAL ) ) { + //Log_Print("brush %i is only structural\n", b->brushnum); + contents = 0; + } //end if + if ( contents & CONTENTS_DONOTENTER ) { + Log_Print( "brush %i is a donotenter brush, c = %X\n", b->brushnum, contents ); + } //end if + return contents; +} //end of the function Q3_BrushContents +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void Q3_DPlanes2MapPlanes( void ) { + int i; + + for ( i = 0; i < q3_numplanes; i++ ) + { + dplanes2mapplanes[i] = FindFloatPlane( q3_dplanes[i].normal, q3_dplanes[i].dist ); + } //end for +} //end of the function Q3_DPlanes2MapPlanes +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void Q3_BSPBrushToMapBrush( q3_dbrush_t *bspbrush, entity_t *mapent ) { + mapbrush_t *b; + int i, k, n; + side_t *side, *s2; + int planenum; + q3_dbrushside_t *bspbrushside; + q3_dplane_t *bspplane; + int contentFlags = 0; + + if ( nummapbrushes >= MAX_MAPFILE_BRUSHES ) { + Error( "nummapbrushes >= MAX_MAPFILE_BRUSHES" ); + } + + b = &mapbrushes[nummapbrushes]; + b->original_sides = &brushsides[nummapbrushsides]; + b->entitynum = mapent - entities; + b->brushnum = nummapbrushes - mapent->firstbrush; + b->leafnum = dbrushleafnums[bspbrush - q3_dbrushes]; + + for ( n = 0; n < bspbrush->numSides; n++ ) + { + //pointer to the bsp brush side + bspbrushside = &q3_dbrushsides[bspbrush->firstSide + n]; + + if ( nummapbrushsides >= MAX_MAPFILE_BRUSHSIDES ) { + Error( "MAX_MAPFILE_BRUSHSIDES" ); + } //end if + //pointer to the map brush side + side = &brushsides[nummapbrushsides]; + //if the BSP brush side is textured + if ( q3_dbrushsidetextured[bspbrush->firstSide + n] ) { + side->flags |= SFL_TEXTURED | SFL_VISIBLE; + } else { side->flags &= ~SFL_TEXTURED;} + //NOTE: all Quake3 sides are assumed textured + //side->flags |= SFL_TEXTURED|SFL_VISIBLE; + // + if ( bspbrushside->shaderNum < 0 ) { + side->contents = 0; + side->surf = 0; + } //end if + else + { + side->contents = q3_dshaders[bspbrushside->shaderNum].contentFlags; + side->surf = q3_dshaders[bspbrushside->shaderNum].surfaceFlags; + + if ( strstr( q3_dshaders[bspbrushside->shaderNum].shader, "common/hint" ) ) { + //Log_Print("found hint side\n"); + side->surf |= SURF_HINT; + } //end if + + // Ridah, mark ladder brushes + if ( cfg.rs_allowladders && strstr( q3_dshaders[bspbrushside->shaderNum].shader, "common/ladder" ) ) { + //Log_Print("found ladder side\n"); + side->contents |= CONTENTS_LADDER; + contentFlags |= CONTENTS_LADDER; + } //end if + // done. + + } //end else + // + + if ( !( strstr( q3_dshaders[bspbrushside->shaderNum].shader, "common/slip" ) ) ) { + side->flags |= SFL_VISIBLE; + } else if ( side->surf & SURF_NODRAW ) { + side->flags |= SFL_TEXTURED | SFL_VISIBLE; + } //end if + /* + if (side->contents & (CONTENTS_TRANSLUCENT|CONTENTS_STRUCTURAL)) + { + side->flags |= SFL_TEXTURED|SFL_VISIBLE; + } //end if*/ + + // hints and skips are never detail, and have no content + if ( side->surf & ( SURF_HINT | SURF_SKIP ) ) { + side->contents = 0; + //Log_Print("found hint brush side\n"); + } + /* + if ((side->surf & SURF_NODRAW) && (side->surf & SURF_NOIMPACT)) + { + side->contents = 0; + side->surf &= ~CONTENTS_DETAIL; + Log_Print("probably found hint brush in a BSP without hints being used\n"); + } //end if*/ + +/* + // RF, ignore slick brushes (causes ladder issues) + if (strstr(q3_dshaders[bspbrushside->shaderNum].shader, "common/slick")) + { + //Log_Print("found hint side\n"); + b->numsides = 0; + b->contents = 0; + return; // get out of here + } //end if +*/ + + //ME: get a plane for this side + bspplane = &q3_dplanes[bspbrushside->planeNum]; + planenum = FindFloatPlane( bspplane->normal, bspplane->dist ); + // + // see if the plane has been used already + // + //ME: this really shouldn't happen!!! + //ME: otherwise the bsp file is corrupted?? + //ME: still it seems to happen, maybe Johny Boy's + //ME: brush bevel adding is crappy ? + for ( k = 0; k < b->numsides; k++ ) + { + s2 = b->original_sides + k; +// if (DotProduct (mapplanes[s2->planenum].normal, mapplanes[planenum].normal) > 0.999 +// && fabs(mapplanes[s2->planenum].dist - mapplanes[planenum].dist) < 0.01 ) + + if ( s2->planenum == planenum ) { + Log_Print( "Entity %i, Brush %i: duplicate plane\n" + , b->entitynum, b->brushnum ); + break; + } + if ( s2->planenum == ( planenum ^ 1 ) ) { + Log_Print( "Entity %i, Brush %i: mirrored plane\n" + , b->entitynum, b->brushnum ); + break; + } + } + if ( k != b->numsides ) { + continue; // duplicated + + } + // + // keep this side + // + //ME: reset pointer to side, why? hell I dunno (pointer is set above already) + side = b->original_sides + b->numsides; + //ME: store the plane number + side->planenum = planenum; + //ME: texinfo is already stored when bsp is loaded + //NOTE: check for TEXINFO_NODE, otherwise crash in Q3_BrushContents + //if (bspbrushside->texinfo < 0) side->texinfo = 0; + //else side->texinfo = bspbrushside->texinfo; + + // save the td off in case there is an origin brush and we + // have to recalculate the texinfo + // ME: don't need to recalculate because it's already done + // (for non-world entities) in the BSP file +// side_brushtextures[nummapbrushsides] = td; + + nummapbrushsides++; + b->numsides++; + } //end for + + // get the content for the entire brush + //Quake3 bsp brushes don't have a contents + b->contents = q3_dshaders[bspbrush->shaderNum].contentFlags | contentFlags; + // Ridah, Wolf has ladders (if we call Q3_BrushContents(), we'll get the solid area bug + b->contents &= ~( /*CONTENTS_LADDER|*/ CONTENTS_FOG | CONTENTS_STRUCTURAL ); + //b->contents = Q3_BrushContents(b); + // + // Ridah, CONTENTS_MOSTERCLIP should prevent AAS from being created, but not clip players/AI in the game + if ( b->contents & CONTENTS_MONSTERCLIP ) { + b->contents |= CONTENTS_PLAYERCLIP; + } + + // func_explosive's not solid + if ( !strcmp( "func_explosive", ValueForKey( &entities[b->entitynum], "classname" ) ) || + !strcmp( "func_invisible_user", ValueForKey( &entities[b->entitynum], "classname" ) ) || + !strcmp( "script_mover", ValueForKey( &entities[b->entitynum], "classname" ) ) || + !strcmp( "func_static", ValueForKey( &entities[b->entitynum], "classname" ) ) ) { + Log_Print( "Ignoring %s brush..\n", ValueForKey( &entities[b->entitynum], "classname" ) ); + b->numsides = 0; + b->contents = 0; + return; + } + + if ( BrushExists( b ) ) { + c_squattbrushes++; + b->numsides = 0; + return; + } //end if + + //if we're creating AAS + if ( create_aas ) { + //create the AAS brushes from this brush, don't add brush bevels + AAS_CreateMapBrushes( b, mapent, false ); + return; + } //end if + + // allow detail brushes to be removed + if ( nodetail && ( b->contents & CONTENTS_DETAIL ) ) { + b->numsides = 0; + return; + } //end if + + // allow water brushes to be removed + if ( nowater && ( b->contents & ( CONTENTS_LAVA | CONTENTS_SLIME | CONTENTS_WATER ) ) ) { + b->numsides = 0; + return; + } //end if + + + // create windings for sides and bounds for brush + MakeBrushWindings( b ); + + //mark brushes without winding or with a tiny window as bevels + MarkBrushBevels( b ); + + // brushes that will not be visible at all will never be + // used as bsp splitters + if ( b->contents & ( CONTENTS_PLAYERCLIP | CONTENTS_MONSTERCLIP ) ) { + c_clipbrushes++; + for ( i = 0; i < b->numsides; i++ ) + b->original_sides[i].texinfo = TEXINFO_NODE; + } //end for + + // + // origin brushes are removed, but they set + // the rotation origin for the rest of the brushes + // in the entity. After the entire entity is parsed, + // the planenums and texinfos will be adjusted for + // the origin brush + // + //ME: not needed because the entities in the BSP file already + // have an origin set +// if (b->contents & CONTENTS_ORIGIN) +// { +// char string[32]; +// vec3_t origin; +// +// if (num_entities == 1) +// { +// Error ("Entity %i, Brush %i: origin brushes not allowed in world" +// , b->entitynum, b->brushnum); +// return; +// } +// +// VectorAdd (b->mins, b->maxs, origin); +// VectorScale (origin, 0.5, origin); +// +// sprintf (string, "%i %i %i", (int)origin[0], (int)origin[1], (int)origin[2]); +// SetKeyValue (&entities[b->entitynum], "origin", string); +// +// VectorCopy (origin, entities[b->entitynum].origin); +// +// // don't keep this brush +// b->numsides = 0; +// +// return; +// } + + //ME: the bsp brushes already have bevels, so we won't try to + // add them again (especially since Johny Boy's bevel adding might + // be crappy) +// AddBrushBevels(b); + + nummapbrushes++; + mapent->numbrushes++; +} //end of the function Q3_BSPBrushToMapBrush +//=========================================================================== +//=========================================================================== +void Q3_ParseBSPBrushes( entity_t *mapent ) { + int i; + + /* + //give all the brushes that belong to this entity the number of the + //BSP model used by this entity + Q3_SetBrushModelNumbers(mapent); + //now parse all the brushes with the correct mapent->modelnum + for (i = 0; i < q3_numbrushes; i++) + { + if (brushmodelnumbers[i] == mapent->modelnum) + { + Q3_BSPBrushToMapBrush(&q3_dbrushes[i], mapent); + } //end if + } //end for + */ + for ( i = 0; i < q3_dmodels[mapent->modelnum].numBrushes; i++ ) + { + Q3_BSPBrushToMapBrush( &q3_dbrushes[q3_dmodels[mapent->modelnum].firstBrush + i], mapent ); + } //end for +} //end of the function Q3_ParseBSPBrushes +//=========================================================================== +//=========================================================================== +qboolean Q3_ParseBSPEntity( int entnum ) { + entity_t *mapent; + char *model; + int startbrush, startsides; + + startbrush = nummapbrushes; + startsides = nummapbrushsides; + + mapent = &entities[entnum]; //num_entities]; + mapent->firstbrush = nummapbrushes; + mapent->numbrushes = 0; + mapent->modelnum = -1; //-1 = no BSP model + + model = ValueForKey( mapent, "model" ); + if ( model && strlen( model ) ) { + if ( *model == '*' ) { + //get the model number of this entity (skip the leading *) + mapent->modelnum = atoi( &model[1] ); + } //end if + } //end if + + GetVectorForKey( mapent, "origin", mapent->origin ); + + //if this is the world entity it has model number zero + //the world entity has no model key + if ( !strcmp( "worldspawn", ValueForKey( mapent, "classname" ) ) ) { + mapent->modelnum = 0; + } //end if + //if the map entity has a BSP model (a modelnum of -1 is used for + //entities that aren't using a BSP model) + if ( mapent->modelnum >= 0 ) { + //parse the bsp brushes + Q3_ParseBSPBrushes( mapent ); + } //end if + // + //the origin of the entity is already taken into account + // + //func_group entities can't be in the bsp file + // + //check out the func_areaportal entities + if ( !strcmp( "func_areaportal", ValueForKey( mapent, "classname" ) ) ) { + c_areaportals++; + mapent->areaportalnum = c_areaportals; + return true; + } //end if + return true; +} //end of the function Q3_ParseBSPEntity +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +#define MAX_PATCH_VERTS 1024 + +void AAS_CreateCurveBrushes( void ) { + int i, j, n, planenum, numcurvebrushes = 0; + q3_dsurface_t *surface; + q3_drawVert_t *dv_p; + vec3_t points[MAX_PATCH_VERTS]; + int width, height, c; + patchCollide_t *pc; + facet_t *facet; + mapbrush_t *brush; + side_t *side; + entity_t *mapent; + winding_t *winding; + + qprintf( "nummapbrushsides = %d\n", nummapbrushsides ); + mapent = &entities[0]; + for ( i = 0; i < q3_numDrawSurfaces; i++ ) + { + surface = &q3_drawSurfaces[i]; + if ( !surface->patchWidth ) { + continue; + } + //if the curve is not solid + if ( !( q3_dshaders[surface->shaderNum].contentFlags & ( CONTENTS_SOLID | CONTENTS_PLAYERCLIP ) ) ) { + //Log_Print("skipped non-solid curve\n"); + continue; + } //end if + // + width = surface->patchWidth; + height = surface->patchHeight; + c = width * height; + if ( c > MAX_PATCH_VERTS ) { + Error( "ParseMesh: MAX_PATCH_VERTS" ); + } //end if + + dv_p = q3_drawVerts + surface->firstVert; + for ( j = 0 ; j < c ; j++, dv_p++ ) + { + points[j][0] = dv_p->xyz[0]; + points[j][1] = dv_p->xyz[1]; + points[j][2] = dv_p->xyz[2]; + } //end for + // create the internal facet structure + pc = CM_GeneratePatchCollide( width, height, points ); + // + for ( j = 0; j < pc->numFacets; j++ ) + { + facet = &pc->facets[j]; + // + brush = &mapbrushes[nummapbrushes]; + brush->original_sides = &brushsides[nummapbrushsides]; + brush->entitynum = 0; + brush->brushnum = nummapbrushes - mapent->firstbrush; + // + brush->numsides = facet->numBorders + 2; + nummapbrushsides += brush->numsides; + brush->contents = CONTENTS_SOLID; + // + //qprintf("\r%6d curve brushes", nummapbrushsides);//++numcurvebrushes); + qprintf( "\r%6d curve brushes", ++numcurvebrushes ); + // + planenum = FindFloatPlane( pc->planes[facet->surfacePlane].plane, pc->planes[facet->surfacePlane].plane[3] ); + // + side = &brush->original_sides[0]; + side->planenum = planenum; + side->contents = CONTENTS_SOLID; + side->flags |= SFL_TEXTURED | SFL_VISIBLE | SFL_CURVE; + side->surf = 0; + // + side = &brush->original_sides[1]; + if ( create_aas ) { + //the plane is expanded later so it's not a problem that + //these first two opposite sides are coplanar + side->planenum = planenum ^ 1; + } //end if + else + { + side->planenum = FindFloatPlane( mapplanes[planenum ^ 1].normal, mapplanes[planenum ^ 1].dist + 1 ); + side->flags |= SFL_TEXTURED | SFL_VISIBLE; + } //end else + side->contents = CONTENTS_SOLID; + side->flags |= SFL_CURVE; + side->surf = 0; + // + winding = BaseWindingForPlane( mapplanes[side->planenum].normal, mapplanes[side->planenum].dist ); + for ( n = 0; n < facet->numBorders; n++ ) + { + //never use the surface plane as a border + if ( facet->borderPlanes[n] == facet->surfacePlane ) { + continue; + } + // + side = &brush->original_sides[2 + n]; + side->planenum = FindFloatPlane( pc->planes[facet->borderPlanes[n]].plane, pc->planes[facet->borderPlanes[n]].plane[3] ); + if ( facet->borderInward[n] ) { + side->planenum ^= 1; + } + side->contents = CONTENTS_SOLID; + side->flags |= SFL_TEXTURED | SFL_CURVE; + side->surf = 0; + //chop the winding in place + if ( winding ) { + ChopWindingInPlace( &winding, mapplanes[side->planenum ^ 1].normal, mapplanes[side->planenum ^ 1].dist, 0.1 ); //CLIP_EPSILON); + } + } //end for + //VectorCopy(pc->bounds[0], brush->mins); + //VectorCopy(pc->bounds[1], brush->maxs); + if ( !winding ) { + Log_Print( "WARNING: AAS_CreateCurveBrushes: no winding\n" ); + brush->numsides = 0; + continue; + } //end if + brush->original_sides[0].winding = winding; + WindingBounds( winding, brush->mins, brush->maxs ); + for ( n = 0; n < 3; n++ ) + { + //IDBUG: all the indexes into the mins and maxs were zero (not using i) + if ( brush->mins[n] < -MAX_MAP_BOUNDS || brush->maxs[n] > MAX_MAP_BOUNDS ) { + Log_Print( "entity %i, brush %i: bounds out of range\n", brush->entitynum, brush->brushnum ); + Log_Print( "brush->mins[%d] = %f, brush->maxs[%d] = %f\n", n, brush->mins[n], n, brush->maxs[n] ); + brush->numsides = 0; //remove the brush + break; + } //end if + if ( brush->mins[n] > MAX_MAP_BOUNDS || brush->maxs[n] < -MAX_MAP_BOUNDS ) { + Log_Print( "entity %i, brush %i: no visible sides on brush\n", brush->entitynum, brush->brushnum ); + Log_Print( "brush->mins[%d] = %f, brush->maxs[%d] = %f\n", n, brush->mins[n], n, brush->maxs[n] ); + brush->numsides = 0; //remove the brush + break; + } //end if + } //end for + if ( create_aas ) { + //NOTE: brush bevels now already added + //AddBrushBevels(brush); + AAS_CreateMapBrushes( brush, mapent, false ); + } //end if + else + { + // create windings for sides and bounds for brush + MakeBrushWindings( brush ); + AddBrushBevels( brush ); + nummapbrushes++; + mapent->numbrushes++; + } //end else + } //end for + } //end for + //qprintf("\r%6d curve brushes", nummapbrushsides);//++numcurvebrushes); + qprintf( "\r%6d curve brushes\n", numcurvebrushes ); +} //end of the function AAS_CreateCurveBrushes +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AAS_ExpandMapBrush( mapbrush_t *brush, vec3_t mins, vec3_t maxs ); + +void Q3_LoadMapFromBSP( struct quakefile_s *qf ) { + int i; + //vec3_t mins = {-1,-1,-1}, maxs = {1, 1, 1}; // TTimo: unused + + Log_Print( "-- Q3_LoadMapFromBSP --\n" ); + //loaded map type + loadedmaptype = MAPTYPE_QUAKE3; + + Log_Print( "Loading map from %s...\n", qf->filename ); + //load the bsp file + Q3_LoadBSPFile( qf ); + + //create an index from bsp planes to map planes + //DPlanes2MapPlanes(); + //clear brush model numbers + for ( i = 0; i < MAX_MAPFILE_BRUSHES; i++ ) + brushmodelnumbers[i] = -1; + + nummapbrushsides = 0; + num_entities = 0; + + Q3_ParseEntities(); + // + for ( i = 0; i < num_entities; i++ ) + { + Q3_ParseBSPEntity( i ); + } //end for + + AAS_CreateCurveBrushes(); + //get the map mins and maxs from the world model + ClearBounds( map_mins, map_maxs ); + for ( i = 0; i < entities[0].numbrushes; i++ ) + { + if ( mapbrushes[i].numsides <= 0 ) { + continue; + } + //if (mapbrushes[i].mins[0] > 4096) + // continue; //no valid points + AddPointToBounds( mapbrushes[i].mins, map_mins, map_maxs ); + AddPointToBounds( mapbrushes[i].maxs, map_mins, map_maxs ); + } //end for + /*/ + for (i = 0; i < nummapbrushes; i++) + { + //if (!mapbrushes[i].original_sides) continue; + //AddBrushBevels(&mapbrushes[i]); + //AAS_ExpandMapBrush(&mapbrushes[i], mins, maxs); + } //end for*/ + /* + for (i = 0; i < nummapbrushsides; i++) + { + Log_Write("side %d flags = %d", i, brushsides[i].flags); + } //end for + for (i = 0; i < nummapbrushes; i++) + { + Log_Write("brush contents: "); + PrintContents(mapbrushes[i].contents); + Log_Print("\n"); + } //end for*/ + if ( writeaasmap ) { + char name[MAX_QPATH]; + strncpy( name, qf->filename, sizeof( name ) ); + StripExtension( name ); + strcat( name, "_aas.map" ); + WriteMapFile( name ); + } +} //end of the function Q3_LoadMapFromBSP +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void Q3_ResetMapLoading( void ) { + //reset for map loading from bsp + memset( nodestack, 0, NODESTACKSIZE * sizeof( int ) ); + nodestackptr = NULL; + nodestacksize = 0; + memset( brushmodelnumbers, 0, MAX_MAPFILE_BRUSHES * sizeof( int ) ); +} //end of the function Q3_ResetMapLoading + diff --git a/Projects/Android/jni/rtcw/src/bspc/map_sin.c b/Projects/Android/jni/rtcw/src/bspc/map_sin.c new file mode 100644 index 0000000..17145ac --- /dev/null +++ b/Projects/Android/jni/rtcw/src/bspc/map_sin.c @@ -0,0 +1,1201 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +//----------------------------------------------------------------------------- +// +// $Logfile:: /Wolf4/src/bspc/map_sin.c $ + +#include "qbsp.h" +#include "l_bsp_sin.h" +#include "aas_map.h" //AAS_CreateMapBrushes + + +//==================================================================== + + +/* +=========== +Sin_BrushContents +=========== +*/ + +int Sin_BrushContents( mapbrush_t *b ) { + int contents; + side_t *s; + int i; +#ifdef SIN + float trans = 0; +#else + int trans; +#endif + + s = &b->original_sides[0]; + contents = s->contents; + +#ifdef SIN + trans = sin_texinfo[s->texinfo].translucence; +#else + trans = texinfo[s->texinfo].flags; +#endif + for ( i = 1 ; i < b->numsides ; i++, s++ ) + { + s = &b->original_sides[i]; +#ifdef SIN + trans += sin_texinfo[s->texinfo].translucence; +#else + trans |= texinfo[s->texinfo].flags; +#endif + if ( s->contents != contents ) { +#ifdef SIN + if ( + ( s->contents & CONTENTS_DETAIL && !( contents & CONTENTS_DETAIL ) ) || + ( !( s->contents & CONTENTS_DETAIL ) && contents & CONTENTS_DETAIL ) + ) { + s->contents |= CONTENTS_DETAIL; + contents |= CONTENTS_DETAIL; + continue; + } +#endif + printf( "Entity %i, Brush %i: mixed face contents\n" + , b->entitynum, b->brushnum ); + break; + } + } + + +#ifdef SIN + if ( contents & CONTENTS_FENCE ) { +// contents |= CONTENTS_TRANSLUCENT; + contents |= CONTENTS_DETAIL; + contents |= CONTENTS_DUMMYFENCE; + contents &= ~CONTENTS_SOLID; + contents &= ~CONTENTS_FENCE; + contents |= CONTENTS_WINDOW; + } +#endif + + // if any side is translucent, mark the contents + // and change solid to window +#ifdef SIN + if ( trans > 0 ) +#else + if ( trans & ( SURF_TRANS33 | SURF_TRANS66 ) ) +#endif + { + contents |= CONTENTS_Q2TRANSLUCENT; + if ( contents & CONTENTS_SOLID ) { + contents &= ~CONTENTS_SOLID; + contents |= CONTENTS_WINDOW; + } + } + + return contents; +} //*/ + + +//============================================================================ + + + +/* +================= +ParseBrush +================= +* / +void ParseBrush (entity_t *mapent) +{ + mapbrush_t *b; + int i,j, k; + int mt; + side_t *side, *s2; + int planenum; + brush_texture_t td; +#ifdef SIN + textureref_t newref; +#endif + int planepts[3][3]; + + if (nummapbrushes == MAX_MAP_BRUSHES) + Error ("nummapbrushes == MAX_MAP_BRUSHES"); + + b = &mapbrushes[nummapbrushes]; + b->original_sides = &brushsides[nummapbrushsides]; + b->entitynum = num_entities-1; + b->brushnum = nummapbrushes - mapent->firstbrush; + + do + { + if (!GetToken (true)) + break; + if (!strcmp (token, "}") ) + break; + + if (nummapbrushsides == MAX_MAP_BRUSHSIDES) + Error ("MAX_MAP_BRUSHSIDES"); + side = &brushsides[nummapbrushsides]; + + // read the three point plane definition + for (i=0 ; i<3 ; i++) + { + if (i != 0) + GetToken (true); + if (strcmp (token, "(") ) + Error ("parsing brush"); + + for (j=0 ; j<3 ; j++) + { + GetToken (false); + planepts[i][j] = atoi(token); + } + + GetToken (false); + if (strcmp (token, ")") ) + Error ("parsing brush"); + + } + + + // + // read the texturedef + // + GetToken (false); + strcpy (td.name, token); + + GetToken (false); + td.shift[0] = atoi(token); + GetToken (false); + td.shift[1] = atoi(token); + GetToken (false); +#ifdef SIN + td.rotate = atof(token); +#else + td.rotate = atoi(token); +#endif + GetToken (false); + td.scale[0] = atof(token); + GetToken (false); + td.scale[1] = atof(token); + + // find default flags and values + mt = FindMiptex (td.name); +#ifdef SIN + // clear out the masks on newref + memset(&newref,0,sizeof(newref)); + // copy over the name + strcpy( newref.name, td.name ); + + ParseSurfaceInfo( &newref ); + MergeRefs( &bsp_textureref[mt], &newref, &td.tref ); + side->contents = td.tref.contents; + side->surf = td.tref.flags; +#else + td.flags = textureref[mt].flags; + td.value = textureref[mt].value; + side->contents = textureref[mt].contents; + side->surf = td.flags = textureref[mt].flags; + + if (TokenAvailable()) + { + GetToken (false); + side->contents = atoi(token); + GetToken (false); + side->surf = td.flags = atoi(token); + GetToken (false); + td.value = atoi(token); + } +#endif + + // translucent objects are automatically classified as detail +#ifdef SIN + if ( td.tref.translucence > 0 ) +#else + if (side->surf & (SURF_TRANS33|SURF_TRANS66) ) +#endif + side->contents |= CONTENTS_DETAIL; + if (side->contents & (CONTENTS_PLAYERCLIP|CONTENTS_MONSTERCLIP) ) + side->contents |= CONTENTS_DETAIL; + if (fulldetail) + side->contents &= ~CONTENTS_DETAIL; + if (!(side->contents & ((LAST_VISIBLE_CONTENTS-1) + | CONTENTS_PLAYERCLIP|CONTENTS_MONSTERCLIP|CONTENTS_MIST) ) ) + side->contents |= CONTENTS_SOLID; + + // hints and skips are never detail, and have no content + if (side->surf & (SURF_HINT|SURF_SKIP) ) + { + side->contents = 0; +#ifndef SIN // I think this is a bug of some kind + side->surf &= ~CONTENTS_DETAIL; +#endif + } + + // + // find the plane number + // + planenum = PlaneFromPoints (planepts[0], planepts[1], planepts[2]); + if (planenum == -1) + { + printf ("Entity %i, Brush %i: plane with no normal\n" + , b->entitynum, b->brushnum); + continue; + } + + // + // see if the plane has been used already + // + for (k=0 ; knumsides ; k++) + { + s2 = b->original_sides + k; + if (s2->planenum == planenum) + { + printf ("Entity %i, Brush %i: duplicate plane\n" + , b->entitynum, b->brushnum); + break; + } + if ( s2->planenum == (planenum^1) ) + { + printf ("Entity %i, Brush %i: mirrored plane\n" + , b->entitynum, b->brushnum); + break; + } + } + if (k != b->numsides) + continue; // duplicated + + // + // keep this side + // + + side = b->original_sides + b->numsides; + side->planenum = planenum; +#ifdef SIN + side->texinfo = TexinfoForBrushTexture (&mapplanes[planenum], + &td, vec3_origin, &newref); + // + // save off lightinfo + // + side->lightinfo = LightinfoForBrushTexture ( &td ); +#else + side->texinfo = TexinfoForBrushTexture (&mapplanes[planenum], + &td, vec3_origin); + +#endif + + // save the td off in case there is an origin brush and we + // have to recalculate the texinfo + side_brushtextures[nummapbrushsides] = td; +#ifdef SIN + // save off the merged tref for animating textures + side_newrefs[nummapbrushsides] = newref; +#endif + + nummapbrushsides++; + b->numsides++; + } while (1); + + // get the content for the entire brush + b->contents = Sin_BrushContents (b); + + // allow detail brushes to be removed + if (nodetail && (b->contents & CONTENTS_DETAIL) ) + { + b->numsides = 0; + return; + } + + // allow water brushes to be removed + if (nowater && (b->contents & (CONTENTS_LAVA | CONTENTS_SLIME | CONTENTS_WATER)) ) + { + b->numsides = 0; + return; + } + + // create windings for sides and bounds for brush + MakeBrushWindings (b); + + // brushes that will not be visible at all will never be + // used as bsp splitters + if (b->contents & (CONTENTS_PLAYERCLIP|CONTENTS_MONSTERCLIP) ) + { + c_clipbrushes++; + for (i=0 ; inumsides ; i++) + b->original_sides[i].texinfo = TEXINFO_NODE; + } + + // + // origin brushes are removed, but they set + // the rotation origin for the rest of the brushes + // in the entity. After the entire entity is parsed, + // the planenums and texinfos will be adjusted for + // the origin brush + // + if (b->contents & CONTENTS_ORIGIN) + { + char string[32]; + vec3_t origin; + + if (num_entities == 1) + { + Error ("Entity %i, Brush %i: origin brushes not allowed in world" + , b->entitynum, b->brushnum); + return; + } + + VectorAdd (b->mins, b->maxs, origin); + VectorScale (origin, 0.5, origin); + + sprintf (string, "%i %i %i", (int)origin[0], (int)origin[1], (int)origin[2]); + SetKeyValue (&entities[b->entitynum], "origin", string); + + VectorCopy (origin, entities[b->entitynum].origin); + + // don't keep this brush + b->numsides = 0; + + return; + } + + AddBrushBevels (b); + + nummapbrushes++; + mapent->numbrushes++; +} // +*/ + +/* +================ +MoveBrushesToWorld + +Takes all of the brushes from the current entity and +adds them to the world's brush list. + +Used by func_group and func_areaportal +================ +* / +void MoveBrushesToWorld (entity_t *mapent) +{ + int newbrushes; + int worldbrushes; + mapbrush_t *temp; + int i; + + // this is pretty gross, because the brushes are expected to be + // in linear order for each entity + + newbrushes = mapent->numbrushes; + worldbrushes = entities[0].numbrushes; + + temp = malloc(newbrushes*sizeof(mapbrush_t)); + memcpy (temp, mapbrushes + mapent->firstbrush, newbrushes*sizeof(mapbrush_t)); + +#if 0 // let them keep their original brush numbers + for (i=0 ; inumbrushes = 0; +} // +*/ + +/* +================ +ParseMapEntity +================ +* / +qboolean Sin_ParseMapEntity (void) +{ + entity_t *mapent; + epair_t *e; + side_t *s; + int i, j; + int startbrush, startsides; + vec_t newdist; + mapbrush_t *b; + + if (!GetToken (true)) + return false; + + if (strcmp (token, "{") ) + Error ("ParseEntity: { not found"); + + if (num_entities == MAX_MAP_ENTITIES) + Error ("num_entities == MAX_MAP_ENTITIES"); + + startbrush = nummapbrushes; + startsides = nummapbrushsides; + + mapent = &entities[num_entities]; + num_entities++; + memset (mapent, 0, sizeof(*mapent)); + mapent->firstbrush = nummapbrushes; + mapent->numbrushes = 0; +// mapent->portalareas[0] = -1; +// mapent->portalareas[1] = -1; + + do + { + if (!GetToken (true)) + Error ("ParseEntity: EOF without closing brace"); + if (!strcmp (token, "}") ) + break; + if (!strcmp (token, "{") ) + ParseBrush (mapent); + else + { + e = ParseEpair (); +#ifdef SIN + //HACK HACK HACK + // MED Gotta do this here + if ( !stricmp(e->key, "surfacefile") ) + { + if (!surfacefile[0]) + { + strcpy( surfacefile, e->value ); + } + printf ("--- ParseSurfaceFile ---\n"); + printf ("Surface script: %s\n", surfacefile); + if (!ParseSurfaceFile(surfacefile)) + { + Error ("Script file not found: %s\n", surfacefile); + } + } +#endif + e->next = mapent->epairs; + mapent->epairs = e; + } + } while (1); + +#ifdef SIN + if (!(strlen(ValueForKey(mapent, "origin"))) && ((num_entities-1) != 0)) + { + mapbrush_t *brush; + vec3_t origin; + char string[32]; + vec3_t mins, maxs; + int start, end; + // Calculate bounds + + start = mapent->firstbrush; + end = start + mapent->numbrushes; + ClearBounds (mins, maxs); + + for (j=start ; jnumsides) + continue; // not a real brush (origin brush) - shouldn't happen + AddPointToBounds (brush->mins, mins, maxs); + AddPointToBounds (brush->maxs, mins, maxs); + } + + // Set the origin to be the centroid of the entity. + VectorAdd ( mins, maxs, origin); + VectorScale( origin, 0.5f, origin ); + + sprintf (string, "%i %i %i", (int)origin[0], (int)origin[1], (int)origin[2]); + SetKeyValue ( mapent, "origin", string); +// qprintf("Setting origin to %s\n",string); + } +#endif + + GetVectorForKey (mapent, "origin", mapent->origin); + +#ifdef SIN + if ( + (!strcmp ("func_areaportal", ValueForKey (mapent, "classname"))) || + (!strcmp ("func_group", ValueForKey (mapent, "classname"))) || + (!strcmp ("detail", ValueForKey (mapent, "classname")) && !entitydetails) + ) + { + VectorClear( mapent->origin ); + } +#endif + + // + // if there was an origin brush, offset all of the planes and texinfo + // + if (mapent->origin[0] || mapent->origin[1] || mapent->origin[2]) + { + for (i=0 ; inumbrushes ; i++) + { + b = &mapbrushes[mapent->firstbrush + i]; + for (j=0 ; jnumsides ; j++) + { + s = &b->original_sides[j]; + newdist = mapplanes[s->planenum].dist - + DotProduct (mapplanes[s->planenum].normal, mapent->origin); + s->planenum = FindFloatPlane (mapplanes[s->planenum].normal, newdist); +#ifdef SIN + s->texinfo = TexinfoForBrushTexture (&mapplanes[s->planenum], + &side_brushtextures[s-brushsides], mapent->origin, &side_newrefs[s-brushsides]); + // + // save off lightinfo + // + s->lightinfo = LightinfoForBrushTexture ( &side_brushtextures[s-brushsides] ); +#else + s->texinfo = TexinfoForBrushTexture (&mapplanes[s->planenum], + &side_brushtextures[s-brushsides], mapent->origin); +#endif + } + MakeBrushWindings (b); + } + } + + // group entities are just for editor convenience + // toss all brushes into the world entity + if (!strcmp ("func_group", ValueForKey (mapent, "classname"))) + { + MoveBrushesToWorld (mapent); + mapent->numbrushes = 0; + mapent->wasdetail = true; + FreeValueKeys( mapent ); + return true; + } +#ifdef SIN + // detail entities are just for editor convenience + // toss all brushes into the world entity as detail brushes + if (!strcmp ("detail", ValueForKey (mapent, "classname")) && !entitydetails) + { + for (i=0 ; inumbrushes ; i++) + { + int j; + side_t * s; + b = &mapbrushes[mapent->firstbrush + i]; + if (nodetail) + { + b->numsides = 0; + continue; + } + if (!fulldetail) + { + // set the contents for the entire brush + b->contents |= CONTENTS_DETAIL; + // set the contents in the sides as well + for (j=0, s=b->original_sides ; jnumsides ; j++,s++) + { + s->contents |= CONTENTS_DETAIL; + } + } + else + { + // set the contents for the entire brush + b->contents |= CONTENTS_SOLID; + // set the contents in the sides as well + for (j=0, s=b->original_sides ; jnumsides ; j++,s++) + { + s->contents |= CONTENTS_SOLID; + } + } + } + MoveBrushesToWorld (mapent); + mapent->wasdetail = true; + FreeValueKeys( mapent ); + // kill off the entity + // num_entities--; + return true; + } +#endif + + // areaportal entities move their brushes, but don't eliminate + // the entity + if (!strcmp ("func_areaportal", ValueForKey (mapent, "classname"))) + { + char str[128]; + + if (mapent->numbrushes != 1) + Error ("Entity %i: func_areaportal can only be a single brush", num_entities-1); + + b = &mapbrushes[nummapbrushes-1]; + b->contents = CONTENTS_AREAPORTAL; + c_areaportals++; + mapent->areaportalnum = c_areaportals; + // set the portal number as "style" + sprintf (str, "%i", c_areaportals); + SetKeyValue (mapent, "style", str); + MoveBrushesToWorld (mapent); + return true; + } + + return true; +} //end of the function Sin_ParseMapEntity */ + +//=================================================================== + +/* +================ +LoadMapFile +================ +* / +void Sin_LoadMapFile (char *filename) +{ + int i; +#ifdef SIN + int num_detailsides=0; + int num_detailbrushes=0; + int num_worldsides=0; + int num_worldbrushes=0; + int j,k; +#endif + + qprintf ("--- LoadMapFile ---\n"); + + LoadScriptFile (filename); + + nummapbrushsides = 0; + num_entities = 0; + + while (ParseMapEntity ()) + { + } + + ClearBounds (map_mins, map_maxs); + for (i=0 ; i 4096) + continue; // no valid points + AddPointToBounds (mapbrushes[i].mins, map_mins, map_maxs); + AddPointToBounds (mapbrushes[i].maxs, map_mins, map_maxs); + } +#ifdef SIN + for (j=0; jnumsides && b->contents & CONTENTS_DETAIL) + num_detailbrushes++; + else if (b->numsides) + num_worldbrushes++; + for (k=0, s=b->original_sides ; knumsides ; k++,s++) + { + if (s->contents & CONTENTS_DETAIL) + num_detailsides++; + else + num_worldsides++; + } + } + } +#endif + + qprintf ("%5i brushes\n", nummapbrushes); + qprintf ("%5i clipbrushes\n", c_clipbrushes); + qprintf ("%5i total sides\n", nummapbrushsides); + qprintf ("%5i boxbevels\n", c_boxbevels); + qprintf ("%5i edgebevels\n", c_edgebevels); + qprintf ("%5i entities\n", num_entities); + qprintf ("%5i planes\n", nummapplanes); + qprintf ("%5i areaportals\n", c_areaportals); + qprintf ("size: %5.0f,%5.0f,%5.0f to %5.0f,%5.0f,%5.0f\n", map_mins[0],map_mins[1],map_mins[2], + map_maxs[0],map_maxs[1],map_maxs[2]); +#ifdef SIN + qprintf ("%5i detailbrushes\n", num_detailbrushes); + qprintf ("%5i worldbrushes\n", num_worldbrushes); + qprintf ("%5i detailsides\n", num_detailsides); + qprintf ("%5i worldsides\n", num_worldsides); +#endif + +} //end of the function Sin_LoadMap */ + + +#ifdef ME //Begin MAP loading from BSP file +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void Sin_CreateMapTexinfo( void ) { + int i; + vec_t defaultvec[4] = {1, 0, 0, 0}; + + memcpy( map_texinfo[0].vecs[0], defaultvec, sizeof( defaultvec ) ); + memcpy( map_texinfo[0].vecs[1], defaultvec, sizeof( defaultvec ) ); + map_texinfo[0].flags = 0; + map_texinfo[0].value = 0; + strcpy( map_texinfo[0].texture, "generic/misc/red" ); //no texture + map_texinfo[0].nexttexinfo = -1; + for ( i = 1; i < sin_numtexinfo; i++ ) + { + memcpy( map_texinfo[i].vecs, sin_texinfo[i].vecs, sizeof( float ) * 2 * 4 ); + map_texinfo[i].flags = sin_texinfo[i].flags; + map_texinfo[i].value = 0; + strcpy( map_texinfo[i].texture, sin_texinfo[i].texture ); + map_texinfo[i].nexttexinfo = -1; + } //end for +} //end of the function Sin_CreateMapTexinfo +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void Sin_SetLeafBrushesModelNumbers( int leafnum, int modelnum ) { + int i, brushnum; + sin_dleaf_t *leaf; + + leaf = &sin_dleafs[leafnum]; + for ( i = 0; i < leaf->numleafbrushes; i++ ) + { + brushnum = sin_dleafbrushes[leaf->firstleafbrush + i]; + brushmodelnumbers[brushnum] = modelnum; + dbrushleafnums[brushnum] = leafnum; + } //end for +} //end of the function Sin_SetLeafBrushesModelNumbers +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void Sin_InitNodeStack( void ) { + nodestackptr = nodestack; + nodestacksize = 0; +} //end of the function Sin_InitNodeStack +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void Sin_PushNodeStack( int num ) { + *nodestackptr = num; + nodestackptr++; + nodestacksize++; + // + if ( nodestackptr >= &nodestack[NODESTACKSIZE] ) { + Error( "Sin_PushNodeStack: stack overflow\n" ); + } //end if +} //end of the function Sin_PushNodeStack +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int Sin_PopNodeStack( void ) { + //if the stack is empty + if ( nodestackptr <= nodestack ) { + return -1; + } + //decrease stack pointer + nodestackptr--; + nodestacksize--; + //return the top value from the stack + return *nodestackptr; +} //end of the function Sin_PopNodeStack +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void Sin_SetBrushModelNumbers( entity_t *mapent ) { + int n, pn; + int leafnum; + + // + Sin_InitNodeStack(); + //head node (root) of the bsp tree + n = sin_dmodels[mapent->modelnum].headnode; + pn = 0; + + do + { + //if we are in a leaf (negative node number) + if ( n < 0 ) { + //number of the leaf + leafnum = ( -n ) - 1; + //set the brush numbers + Sin_SetLeafBrushesModelNumbers( leafnum, mapent->modelnum ); + //walk back into the tree to find a second child to continue with + for ( pn = Sin_PopNodeStack(); pn >= 0; n = pn, pn = Sin_PopNodeStack() ) + { + //if we took the first child at the parent node + if ( sin_dnodes[pn].children[0] == n ) { + break; + } + } //end for + //if the stack wasn't empty (if not processed whole tree) + if ( pn >= 0 ) { + //push the parent node again + Sin_PushNodeStack( pn ); + //we proceed with the second child of the parent node + n = sin_dnodes[pn].children[1]; + } //end if + } //end if + else + { + //push the current node onto the stack + Sin_PushNodeStack( n ); + //walk forward into the tree to the first child + n = sin_dnodes[n].children[0]; + } //end else + } while ( pn >= 0 ); +} //end of the function Sin_SetBrushModelNumbers +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void Sin_BSPBrushToMapBrush( sin_dbrush_t *bspbrush, entity_t *mapent ) { + mapbrush_t *b; + int i, k, n; + side_t *side, *s2; + int planenum; + sin_dbrushside_t *bspbrushside; + sin_dplane_t *bspplane; + + if ( nummapbrushes >= MAX_MAPFILE_BRUSHES ) { + Error( "nummapbrushes >= MAX_MAPFILE_BRUSHES" ); + } + + b = &mapbrushes[nummapbrushes]; + b->original_sides = &brushsides[nummapbrushsides]; + b->entitynum = mapent - entities; + b->brushnum = nummapbrushes - mapent->firstbrush; + b->leafnum = dbrushleafnums[bspbrush - sin_dbrushes]; + + for ( n = 0; n < bspbrush->numsides; n++ ) + { + //pointer to the bsp brush side + bspbrushside = &sin_dbrushsides[bspbrush->firstside + n]; + + if ( nummapbrushsides >= MAX_MAPFILE_BRUSHSIDES ) { + Error( "MAX_MAPFILE_BRUSHSIDES" ); + } //end if + //pointer to the map brush side + side = &brushsides[nummapbrushsides]; + //if the BSP brush side is textured + if ( sin_dbrushsidetextured[bspbrush->firstside + n] ) { + side->flags |= SFL_TEXTURED; + } else { side->flags &= ~SFL_TEXTURED;} + //ME: can get side contents and surf directly from BSP file + side->contents = bspbrush->contents; + //if the texinfo is TEXINFO_NODE + if ( bspbrushside->texinfo < 0 ) { + side->surf = 0; + } else { side->surf = sin_texinfo[bspbrushside->texinfo].flags;} + + // translucent objects are automatically classified as detail + if ( side->surf & ( SURF_TRANS33 | SURF_TRANS66 ) ) { + side->contents |= CONTENTS_DETAIL; + } + if ( side->contents & ( CONTENTS_PLAYERCLIP | CONTENTS_MONSTERCLIP ) ) { + side->contents |= CONTENTS_DETAIL; + } + if ( fulldetail ) { + side->contents &= ~CONTENTS_DETAIL; + } + if ( !( side->contents & ( ( LAST_VISIBLE_CONTENTS - 1 ) + | CONTENTS_PLAYERCLIP | CONTENTS_MONSTERCLIP | CONTENTS_MIST ) ) ) { + side->contents |= CONTENTS_SOLID; + } + + // hints and skips are never detail, and have no content + if ( side->surf & ( SURF_HINT | SURF_SKIP ) ) { + side->contents = 0; + side->surf &= ~CONTENTS_DETAIL; + } + + //ME: get a plane for this side + bspplane = &sin_dplanes[bspbrushside->planenum]; + planenum = FindFloatPlane( bspplane->normal, bspplane->dist ); + // + // see if the plane has been used already + // + //ME: this really shouldn't happen!!! + //ME: otherwise the bsp file is corrupted?? + //ME: still it seems to happen, maybe Johny Boy's + //ME: brush bevel adding is crappy ? + for ( k = 0; k < b->numsides; k++ ) + { + s2 = b->original_sides + k; + if ( s2->planenum == planenum ) { + Log_Print( "Entity %i, Brush %i: duplicate plane\n" + , b->entitynum, b->brushnum ); + break; + } + if ( s2->planenum == ( planenum ^ 1 ) ) { + Log_Print( "Entity %i, Brush %i: mirrored plane\n" + , b->entitynum, b->brushnum ); + break; + } + } + if ( k != b->numsides ) { + continue; // duplicated + + } + // + // keep this side + // + //ME: reset pointer to side, why? hell I dunno (pointer is set above already) + side = b->original_sides + b->numsides; + //ME: store the plane number + side->planenum = planenum; + //ME: texinfo is already stored when bsp is loaded + //NOTE: check for TEXINFO_NODE, otherwise crash in Sin_BrushContents + if ( bspbrushside->texinfo < 0 ) { + side->texinfo = 0; + } else { side->texinfo = bspbrushside->texinfo;} + + // save the td off in case there is an origin brush and we + // have to recalculate the texinfo + // ME: don't need to recalculate because it's already done + // (for non-world entities) in the BSP file +// side_brushtextures[nummapbrushsides] = td; + + nummapbrushsides++; + b->numsides++; + } //end for + + // get the content for the entire brush + b->contents = bspbrush->contents; + Sin_BrushContents( b ); + + if ( BrushExists( b ) ) { + c_squattbrushes++; + b->numsides = 0; + return; + } //end if + + //if we're creating AAS + if ( create_aas ) { + //create the AAS brushes from this brush, don't add brush bevels + AAS_CreateMapBrushes( b, mapent, false ); + return; + } //end if + + // allow detail brushes to be removed + if ( nodetail && ( b->contents & CONTENTS_DETAIL ) ) { + b->numsides = 0; + return; + } //end if + + // allow water brushes to be removed + if ( nowater && ( b->contents & ( CONTENTS_LAVA | CONTENTS_SLIME | CONTENTS_WATER ) ) ) { + b->numsides = 0; + return; + } //end if + + // create windings for sides and bounds for brush + MakeBrushWindings( b ); + + //mark brushes without winding or with a tiny window as bevels + MarkBrushBevels( b ); + + // brushes that will not be visible at all will never be + // used as bsp splitters + if ( b->contents & ( CONTENTS_PLAYERCLIP | CONTENTS_MONSTERCLIP ) ) { + c_clipbrushes++; + for ( i = 0; i < b->numsides; i++ ) + b->original_sides[i].texinfo = TEXINFO_NODE; + } //end for + + // + // origin brushes are removed, but they set + // the rotation origin for the rest of the brushes + // in the entity. After the entire entity is parsed, + // the planenums and texinfos will be adjusted for + // the origin brush + // + //ME: not needed because the entities in the BSP file already + // have an origin set +// if (b->contents & CONTENTS_ORIGIN) +// { +// char string[32]; +// vec3_t origin; +// +// if (num_entities == 1) +// { +// Error ("Entity %i, Brush %i: origin brushes not allowed in world" +// , b->entitynum, b->brushnum); +// return; +// } +// +// VectorAdd (b->mins, b->maxs, origin); +// VectorScale (origin, 0.5, origin); +// +// sprintf (string, "%i %i %i", (int)origin[0], (int)origin[1], (int)origin[2]); +// SetKeyValue (&entities[b->entitynum], "origin", string); +// +// VectorCopy (origin, entities[b->entitynum].origin); +// +// // don't keep this brush +// b->numsides = 0; +// +// return; +// } + + //ME: the bsp brushes already have bevels, so we won't try to + // add them again (especially since Johny Boy's bevel adding might + // be crappy) +// AddBrushBevels(b); + + nummapbrushes++; + mapent->numbrushes++; +} //end of the function Sin_BSPBrushToMapBrush +//=========================================================================== +//=========================================================================== +void Sin_ParseBSPBrushes( entity_t *mapent ) { + int i, testnum = 0; + + //give all the brushes that belong to this entity the number of the + //BSP model used by this entity + Sin_SetBrushModelNumbers( mapent ); + //now parse all the brushes with the correct mapent->modelnum + for ( i = 0; i < sin_numbrushes; i++ ) + { + if ( brushmodelnumbers[i] == mapent->modelnum ) { + testnum++; + Sin_BSPBrushToMapBrush( &sin_dbrushes[i], mapent ); + } //end if + } //end for +} //end of the function Sin_ParseBSPBrushes +//=========================================================================== +//=========================================================================== +qboolean Sin_ParseBSPEntity( int entnum ) { + entity_t *mapent; + char *model; + int startbrush, startsides; + + startbrush = nummapbrushes; + startsides = nummapbrushsides; + + mapent = &entities[entnum]; //num_entities]; + mapent->firstbrush = nummapbrushes; + mapent->numbrushes = 0; + mapent->modelnum = -1; //-1 = no model + + model = ValueForKey( mapent, "model" ); + if ( model && *model == '*' ) { + mapent->modelnum = atoi( &model[1] ); + //Log_Print("model = %s\n", model); + //Log_Print("mapent->modelnum = %d\n", mapent->modelnum); + } //end if + + GetVectorForKey( mapent, "origin", mapent->origin ); + + //if this is the world entity it has model number zero + //the world entity has no model key + if ( !strcmp( "worldspawn", ValueForKey( mapent, "classname" ) ) ) { + mapent->modelnum = 0; + } //end if + //if the map entity has a BSP model (a modelnum of -1 is used for + //entities that aren't using a BSP model) + if ( mapent->modelnum >= 0 ) { + //parse the bsp brushes + Sin_ParseBSPBrushes( mapent ); + } //end if + // + //the origin of the entity is already taken into account + // + //func_group entities can't be in the bsp file + // + //check out the func_areaportal entities + if ( !strcmp( "func_areaportal", ValueForKey( mapent, "classname" ) ) ) { + c_areaportals++; + mapent->areaportalnum = c_areaportals; + return true; + } //end if + return true; +} //end of the function Sin_ParseBSPEntity +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void Sin_LoadMapFromBSP( char *filename, int offset, int length ) { + int i; + + Log_Print( "-- Sin_LoadMapFromBSP --\n" ); + //loaded map type + loadedmaptype = MAPTYPE_SIN; + + Log_Print( "Loading map from %s...\n", filename ); + //load the bsp file + Sin_LoadBSPFile( filename, offset, length ); + + //create an index from bsp planes to map planes + //DPlanes2MapPlanes(); + //clear brush model numbers + for ( i = 0; i < MAX_MAPFILE_BRUSHES; i++ ) + brushmodelnumbers[i] = -1; + + nummapbrushsides = 0; + num_entities = 0; + + Sin_ParseEntities(); + // + for ( i = 0; i < num_entities; i++ ) + { + Sin_ParseBSPEntity( i ); + } //end for + + //get the map mins and maxs from the world model + ClearBounds( map_mins, map_maxs ); + for ( i = 0; i < entities[0].numbrushes; i++ ) + { + if ( mapbrushes[i].mins[0] > 4096 ) { + continue; //no valid points + } + AddPointToBounds( mapbrushes[i].mins, map_mins, map_maxs ); + AddPointToBounds( mapbrushes[i].maxs, map_mins, map_maxs ); + } //end for + // + Sin_CreateMapTexinfo(); +} //end of the function Sin_LoadMapFromBSP + +void Sin_ResetMapLoading( void ) { + //reset for map loading from bsp + memset( nodestack, 0, NODESTACKSIZE * sizeof( int ) ); + nodestackptr = NULL; + nodestacksize = 0; + memset( brushmodelnumbers, 0, MAX_MAPFILE_BRUSHES * sizeof( int ) ); +} //end of the function Sin_ResetMapLoading + +//End MAP loading from BSP file + +#endif //ME diff --git a/Projects/Android/jni/rtcw/src/bspc/nodraw.c b/Projects/Android/jni/rtcw/src/bspc/nodraw.c new file mode 100644 index 0000000..b4846b0 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/bspc/nodraw.c @@ -0,0 +1,50 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +#include "qbsp.h" + +vec3_t draw_mins, draw_maxs; +qboolean drawflag; + +void Draw_ClearWindow( void ) { +} + +//============================================================ + +#define GLSERV_PORT 25001 + + +void GLS_BeginScene( void ) { +} + +void GLS_Winding( winding_t *w, int code ) { +} + +void GLS_EndScene( void ) { +} diff --git a/Projects/Android/jni/rtcw/src/bspc/portals.c b/Projects/Android/jni/rtcw/src/bspc/portals.c new file mode 100644 index 0000000..6b0bf5d --- /dev/null +++ b/Projects/Android/jni/rtcw/src/bspc/portals.c @@ -0,0 +1,1308 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +//=========================================================================== +// +// Name: Portals +// Function: partalizing a bsp tree, flooding through portals +// Programmer: id Software & Mr Elusive (MrElusive@worldentity.com) +// Last update: 1999-08-10 +// Tab Size: 3 +//=========================================================================== + +#include "qbsp.h" +#include "l_mem.h" + +int c_active_portals; +int c_peak_portals; +int c_boundary; +int c_boundary_sides; +int c_portalmemory; + +//portal_t *portallist = NULL; +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +portal_t *AllocPortal( void ) { + portal_t *p; + + p = GetMemory( sizeof( portal_t ) ); + memset( p, 0, sizeof( portal_t ) ); + + if ( numthreads == 1 ) { + c_active_portals++; + if ( c_active_portals > c_peak_portals ) { + c_peak_portals = c_active_portals; + } //end if + c_portalmemory += MemorySize( p ); + } //end if + +// p->nextportal = portallist; +// portallist = p; + + return p; +} //end of the function AllocPortal +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void FreePortal( portal_t *p ) { + if ( p->winding ) { + FreeWinding( p->winding ); + } + if ( numthreads == 1 ) { + c_active_portals--; + c_portalmemory -= MemorySize( p ); + } //end if + FreeMemory( p ); +} //end of the function FreePortal +//=========================================================================== +// Returns the single content bit of the +// strongest visible content present +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int VisibleContents( int contents ) { + int i; + + for ( i = 1 ; i <= LAST_VISIBLE_CONTENTS ; i <<= 1 ) + if ( contents & i ) { + return i; + } + + return 0; +} //end of the function VisibleContents +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int ClusterContents( node_t *node ) { + int c1, c2, c; + + if ( node->planenum == PLANENUM_LEAF ) { + return node->contents; + } + + c1 = ClusterContents( node->children[0] ); + c2 = ClusterContents( node->children[1] ); + c = c1 | c2; + + // a cluster may include some solid detail areas, but + // still be seen into + if ( !( c1 & CONTENTS_SOLID ) || !( c2 & CONTENTS_SOLID ) ) { + c &= ~CONTENTS_SOLID; + } + return c; +} //end of the function ClusterContents + +//=========================================================================== +// Returns true if the portal is empty or translucent, allowing +// the PVS calculation to see through it. +// The nodes on either side of the portal may actually be clusters, +// not leaves, so all contents should be ored together +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +qboolean Portal_VisFlood( portal_t *p ) { + int c1, c2; + + if ( !p->onnode ) { + return false; // to global outsideleaf + + } + c1 = ClusterContents( p->nodes[0] ); + c2 = ClusterContents( p->nodes[1] ); + + if ( !VisibleContents( c1 ^ c2 ) ) { + return true; + } + + if ( c1 & ( CONTENTS_Q2TRANSLUCENT | CONTENTS_DETAIL ) ) { + c1 = 0; + } + if ( c2 & ( CONTENTS_Q2TRANSLUCENT | CONTENTS_DETAIL ) ) { + c2 = 0; + } + + if ( ( c1 | c2 ) & CONTENTS_SOLID ) { + return false; // can't see through solid + + } + if ( !( c1 ^ c2 ) ) { + return true; // identical on both sides + + } + if ( !VisibleContents( c1 ^ c2 ) ) { + return true; + } + return false; +} //end of the function Portal_VisFlood +//=========================================================================== +// The entity flood determines which areas are +// "outside" on the map, which are then filled in. +// Flowing from side s to side !s +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +qboolean Portal_EntityFlood( portal_t *p, int s ) { + if ( p->nodes[0]->planenum != PLANENUM_LEAF + || p->nodes[1]->planenum != PLANENUM_LEAF ) { + Error( "Portal_EntityFlood: not a leaf" ); + } + + // can never cross to a solid + if ( ( p->nodes[0]->contents & CONTENTS_SOLID ) + || ( p->nodes[1]->contents & CONTENTS_SOLID ) ) { + return false; + } + + // can flood through everything else + return true; +} + + +//============================================================================= + +int c_tinyportals; + +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void AddPortalToNodes( portal_t *p, node_t *front, node_t *back ) { + if ( p->nodes[0] || p->nodes[1] ) { + Error( "AddPortalToNode: allready included" ); + } + + p->nodes[0] = front; + p->next[0] = front->portals; + front->portals = p; + + p->nodes[1] = back; + p->next[1] = back->portals; + back->portals = p; +} //end of the function AddPortalToNodes +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void RemovePortalFromNode( portal_t *portal, node_t *l ) { + portal_t **pp, *t; + + int s, i, n; + portal_t *p; + portal_t *portals[4096]; + +// remove reference to the current portal + pp = &l->portals; + while ( 1 ) + { + t = *pp; + if ( !t ) { + Error( "RemovePortalFromNode: portal not in leaf" ); + } + + if ( t == portal ) { + break; + } + + if ( t->nodes[0] == l ) { + pp = &t->next[0]; + } else if ( t->nodes[1] == l ) { + pp = &t->next[1]; + } else { + Error( "RemovePortalFromNode: portal not bounding leaf" ); + } + } + + if ( portal->nodes[0] == l ) { + *pp = portal->next[0]; + portal->nodes[0] = NULL; + } //end if + else if ( portal->nodes[1] == l ) { + *pp = portal->next[1]; + portal->nodes[1] = NULL; + } //end else if + else + { + Error( "RemovePortalFromNode: mislinked portal" ); + } //end else +//#ifdef ME + n = 0; + for ( p = l->portals; p; p = p->next[s] ) + { + for ( i = 0; i < n; i++ ) + { + if ( p == portals[i] ) { + Error( "RemovePortalFromNode: circular linked\n" ); + } + } //end for + if ( p->nodes[0] != l && p->nodes[1] != l ) { + Error( "RemovePortalFromNodes: portal does not belong to node\n" ); + } //end if + portals[n] = p; + s = ( p->nodes[1] == l ); +// if (++n >= 4096) Error("RemovePortalFromNode: more than 4096 portals\n"); + } //end for +//#endif +} //end of the function RemovePortalFromNode +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void PrintPortal( portal_t *p ) { + int i; + winding_t *w; + + w = p->winding; + for ( i = 0 ; i < w->numpoints ; i++ ) + printf( "(%5.0f,%5.0f,%5.0f)\n",w->p[i][0] + , w->p[i][1], w->p[i][2] ); +} //end of the function PrintPortal +//=========================================================================== +// The created portals will face the global outside_node +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +#define SIDESPACE 8 + +void MakeHeadnodePortals( tree_t *tree ) { + vec3_t bounds[2]; + int i, j, n; + portal_t *p, *portals[6]; + plane_t bplanes[6], *pl; + node_t *node; + + node = tree->headnode; + +// pad with some space so there will never be null volume leaves + for ( i = 0 ; i < 3 ; i++ ) + { + bounds[0][i] = tree->mins[i] - SIDESPACE; + bounds[1][i] = tree->maxs[i] + SIDESPACE; + } + + tree->outside_node.planenum = PLANENUM_LEAF; + tree->outside_node.brushlist = NULL; + tree->outside_node.portals = NULL; + tree->outside_node.contents = 0; + + for ( i = 0 ; i < 3 ; i++ ) + for ( j = 0 ; j < 2 ; j++ ) + { + n = j * 3 + i; + + p = AllocPortal(); + portals[n] = p; + + pl = &bplanes[n]; + memset( pl, 0, sizeof( *pl ) ); + if ( j ) { + pl->normal[i] = -1; + pl->dist = -bounds[j][i]; + } else + { + pl->normal[i] = 1; + pl->dist = bounds[j][i]; + } + p->plane = *pl; + p->winding = BaseWindingForPlane( pl->normal, pl->dist ); + AddPortalToNodes( p, node, &tree->outside_node ); + } + +// clip the basewindings by all the other planes + for ( i = 0 ; i < 6 ; i++ ) + { + for ( j = 0 ; j < 6 ; j++ ) + { + if ( j == i ) { + continue; + } + ChopWindingInPlace( &portals[i]->winding, bplanes[j].normal, bplanes[j].dist, ON_EPSILON ); + } //end for + } //end for +} //end of the function MakeHeadNodePortals +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +#define BASE_WINDING_EPSILON 0.001 +#define SPLIT_WINDING_EPSILON 0.001 + +winding_t *BaseWindingForNode( node_t *node ) { + winding_t *w; + node_t *n; + plane_t *plane; + vec3_t normal; + vec_t dist; + + w = BaseWindingForPlane( mapplanes[node->planenum].normal + , mapplanes[node->planenum].dist ); + + // clip by all the parents + for ( n = node->parent ; n && w ; ) + { + plane = &mapplanes[n->planenum]; + + if ( n->children[0] == node ) { // take front + ChopWindingInPlace( &w, plane->normal, plane->dist, BASE_WINDING_EPSILON ); + } else + { // take back + VectorSubtract( vec3_origin, plane->normal, normal ); + dist = -plane->dist; + ChopWindingInPlace( &w, normal, dist, BASE_WINDING_EPSILON ); + } + node = n; + n = n->parent; + } + + return w; +} //end of the function BaseWindingForNode +//=========================================================================== +// create the new portal by taking the full plane winding for the cutting +// plane and clipping it by all of parents of this node +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +qboolean WindingIsTiny( winding_t *w ); + +void MakeNodePortal( node_t *node ) { + portal_t *new_portal, *p; + winding_t *w; + vec3_t normal; + float dist = 0; // TTimo: init + int side = 0; + + w = BaseWindingForNode( node ); + + // clip the portal by all the other portals in the node + for ( p = node->portals; p && w; p = p->next[side] ) + { + if ( p->nodes[0] == node ) { + side = 0; + VectorCopy( p->plane.normal, normal ); + dist = p->plane.dist; + } //end if + else if ( p->nodes[1] == node ) { + side = 1; + VectorSubtract( vec3_origin, p->plane.normal, normal ); + dist = -p->plane.dist; + } //end else if + else + { + Error( "MakeNodePortal: mislinked portal" ); + } //end else + ChopWindingInPlace( &w, normal, dist, 0.1 ); + } //end for + + if ( !w ) { + return; + } //end if + + if ( WindingIsTiny( w ) ) { + c_tinyportals++; + FreeWinding( w ); + return; + } //end if + +#ifdef DEBUG +/* //NOTE: don't use this winding ok check + // all the invalid windings only have a degenerate edge + if (WindingError(w)) + { + Log_Print("MakeNodePortal: %s\n", WindingErrorString()); + FreeWinding(w); + return; + } //end if*/ +#endif //DEBUG + + + new_portal = AllocPortal(); + new_portal->plane = mapplanes[node->planenum]; + +#ifdef ME + new_portal->planenum = node->planenum; +#endif //ME + + new_portal->onnode = node; + new_portal->winding = w; + AddPortalToNodes( new_portal, node->children[0], node->children[1] ); +} //end of the function MakeNodePortal +//=========================================================================== +// Move or split the portals that bound node so that the node's +// children have portals instead of node. +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void SplitNodePortals( node_t *node ) { + portal_t *p, *next_portal, *new_portal; + node_t *f, *b, *other_node; + int side = 0; // TTimo: init + plane_t *plane; + winding_t *frontwinding, *backwinding; + + plane = &mapplanes[node->planenum]; + f = node->children[0]; + b = node->children[1]; + + for ( p = node->portals ; p ; p = next_portal ) + { + if ( p->nodes[0] == node ) { + side = 0; + } else if ( p->nodes[1] == node ) { + side = 1; + } else { Error( "SplitNodePortals: mislinked portal" );} + next_portal = p->next[side]; + + other_node = p->nodes[!side]; + RemovePortalFromNode( p, p->nodes[0] ); + RemovePortalFromNode( p, p->nodes[1] ); + +// +// cut the portal into two portals, one on each side of the cut plane +// + ClipWindingEpsilon( p->winding, plane->normal, plane->dist, + SPLIT_WINDING_EPSILON, &frontwinding, &backwinding ); + + if ( frontwinding && WindingIsTiny( frontwinding ) ) { + FreeWinding( frontwinding ); + frontwinding = NULL; + c_tinyportals++; + } //end if + + if ( backwinding && WindingIsTiny( backwinding ) ) { + FreeWinding( backwinding ); + backwinding = NULL; + c_tinyportals++; + } //end if + +#ifdef DEBUG +/* //NOTE: don't use this winding ok check + // all the invalid windings only have a degenerate edge + if (frontwinding && WindingError(frontwinding)) + { + Log_Print("SplitNodePortals: front %s\n", WindingErrorString()); + FreeWinding(frontwinding); + frontwinding = NULL; + } //end if + if (backwinding && WindingError(backwinding)) + { + Log_Print("SplitNodePortals: back %s\n", WindingErrorString()); + FreeWinding(backwinding); + backwinding = NULL; + } //end if*/ +#endif //DEBUG + + if ( !frontwinding && !backwinding ) { // tiny windings on both sides + continue; + } + + if ( !frontwinding ) { + FreeWinding( backwinding ); + if ( side == 0 ) { + AddPortalToNodes( p, b, other_node ); + } else { AddPortalToNodes( p, other_node, b );} + continue; + } + if ( !backwinding ) { + FreeWinding( frontwinding ); + if ( side == 0 ) { + AddPortalToNodes( p, f, other_node ); + } else { AddPortalToNodes( p, other_node, f );} + continue; + } + + // the winding is split + new_portal = AllocPortal(); + *new_portal = *p; + new_portal->winding = backwinding; + FreeWinding( p->winding ); + p->winding = frontwinding; + + if ( side == 0 ) { + AddPortalToNodes( p, f, other_node ); + AddPortalToNodes( new_portal, b, other_node ); + } //end if + else + { + AddPortalToNodes( p, other_node, f ); + AddPortalToNodes( new_portal, other_node, b ); + } //end else + } + + node->portals = NULL; +} //end of the function SplitNodePortals +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void CalcNodeBounds( node_t *node ) { + portal_t *p; + int s; + int i; + + // calc mins/maxs for both leaves and nodes + ClearBounds( node->mins, node->maxs ); + for ( p = node->portals ; p ; p = p->next[s] ) + { + s = ( p->nodes[1] == node ); + for ( i = 0 ; i < p->winding->numpoints ; i++ ) + AddPointToBounds( p->winding->p[i], node->mins, node->maxs ); + } +} //end of the function CalcNodeBounds +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int c_numportalizednodes; + +void MakeTreePortals_r( node_t *node ) { + int i; + +#ifdef ME + qprintf( "\r%6d", ++c_numportalizednodes ); + if ( cancelconversion ) { + return; + } +#endif //ME + + CalcNodeBounds( node ); + if ( node->mins[0] >= node->maxs[0] ) { + Log_Print( "WARNING: node without a volume\n" ); + } + + for ( i = 0 ; i < 3 ; i++ ) + { + if ( node->mins[i] < -MAX_MAP_BOUNDS || node->maxs[i] > MAX_MAP_BOUNDS ) { + Log_Print( "WARNING: node with unbounded volume\n" ); + break; + } + } + if ( node->planenum == PLANENUM_LEAF ) { + return; + } + + MakeNodePortal( node ); + SplitNodePortals( node ); + + MakeTreePortals_r( node->children[0] ); + MakeTreePortals_r( node->children[1] ); +} //end of the function MakeTreePortals_r +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void MakeTreePortals( tree_t *tree ) { + +#ifdef ME + Log_Print( "---- Node Portalization ----\n" ); + c_numportalizednodes = 0; + c_portalmemory = 0; + qprintf( "%6d nodes portalized", c_numportalizednodes ); +#endif //ME + + MakeHeadnodePortals( tree ); + MakeTreePortals_r( tree->headnode ); + +#ifdef ME + qprintf( "\n" ); + Log_Write( "\r%6d nodes portalized\r\n", c_numportalizednodes ); + Log_Print( "%6d tiny portals\r\n", c_tinyportals ); + Log_Print( "%6d KB of portal memory\r\n", c_portalmemory >> 10 ); + Log_Print( "%6i KB of winding memory\r\n", WindingMemory() >> 10 ); +#endif //ME +} //end of the function MakeTreePortals + +/* +========================================================= + +FLOOD ENTITIES + +========================================================= +*/ +//#define P_NODESTACK + +node_t *p_firstnode; +node_t *p_lastnode; + +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +#ifdef P_NODESTACK +void P_AddNodeToList( node_t *node ) { + node->next = p_firstnode; + p_firstnode = node; + if ( !p_lastnode ) { + p_lastnode = node; + } +} //end of the function P_AddNodeToList +#else //it's a node queue +//add the node to the end of the node list +void P_AddNodeToList( node_t *node ) { + node->next = NULL; + if ( p_lastnode ) { + p_lastnode->next = node; + } else { p_firstnode = node;} + p_lastnode = node; +} //end of the function P_AddNodeToList +#endif //P_NODESTACK +//=========================================================================== +// get the first node from the front of the node list +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +node_t *P_NextNodeFromList( void ) { + node_t *node; + + node = p_firstnode; + if ( p_firstnode ) { + p_firstnode = p_firstnode->next; + } + if ( !p_firstnode ) { + p_lastnode = NULL; + } + return node; +} //end of the function P_NextNodeFromList +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void FloodPortals( node_t *firstnode ) { + node_t *node; + portal_t *p; + int s; + + firstnode->occupied = 1; + P_AddNodeToList( firstnode ); + + for ( node = P_NextNodeFromList(); node; node = P_NextNodeFromList() ) + { + for ( p = node->portals; p; p = p->next[s] ) + { + s = ( p->nodes[1] == node ); + //if the node at the other side of the portal is occupied already + if ( p->nodes[!s]->occupied ) { + continue; + } + //if it isn't possible to flood through this portal + if ( !Portal_EntityFlood( p, s ) ) { + continue; + } + // + p->nodes[!s]->occupied = node->occupied + 1; + // + P_AddNodeToList( p->nodes[!s] ); + } //end for + } //end for +} //end of the function FloodPortals +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int numrec; + +void FloodPortals_r( node_t *node, int dist ) { + portal_t *p; + int s; +// int i; + + Log_Print( "\r%6d", ++numrec ); + + if ( node->occupied ) { + Error( "FloodPortals_r: node already occupied\n" ); + } + if ( !node ) { + Error( "FloodPortals_r: NULL node\n" ); + } //end if*/ + node->occupied = dist; + + for ( p = node->portals; p; p = p->next[s] ) + { + s = ( p->nodes[1] == node ); + //if the node at the other side of the portal is occupied already + if ( p->nodes[!s]->occupied ) { + continue; + } + //if it isn't possible to flood through this portal + if ( !Portal_EntityFlood( p, s ) ) { + continue; + } + //flood recursively through the current portal + FloodPortals_r( p->nodes[!s], dist + 1 ); + } //end for + Log_Print( "\r%6d", --numrec ); +} //end of the function FloodPortals_r +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +qboolean PlaceOccupant( node_t *headnode, vec3_t origin, entity_t *occupant ) { + node_t *node; + vec_t d; + plane_t *plane; + + //find the leaf to start in + node = headnode; + while ( node->planenum != PLANENUM_LEAF ) + { + if ( node->planenum < 0 || node->planenum > nummapplanes ) { + Error( "PlaceOccupant: invalid node->planenum\n" ); + } //end if + plane = &mapplanes[node->planenum]; + d = DotProduct( origin, plane->normal ) - plane->dist; + if ( d >= 0 ) { + node = node->children[0]; + } else { node = node->children[1];} + if ( !node ) { + Error( "PlaceOccupant: invalid child %d\n", d < 0 ); + } //end if + } //end while + //don't start in solid +// if (node->contents == CONTENTS_SOLID) + //ME: replaced because in LeafNode in brushbsp.c + // some nodes have contents solid with other contents + if ( node->contents & CONTENTS_SOLID ) { + return false; + } + //if the node is already occupied + if ( node->occupied ) { + return false; + } + + //place the occupant in the first leaf + node->occupant = occupant; + + numrec = 0; +// Log_Print("%6d recurses", numrec); +// FloodPortals_r(node, 1); +// Log_Print("\n"); + FloodPortals( node ); + + return true; +} //end of the function PlaceOccupant +//=========================================================================== +// Marks all nodes that can be reached by entites +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +qboolean FloodEntities( tree_t *tree ) { + int i; + int x, y; + vec3_t origin; + char *cl; + qboolean inside; + node_t *headnode; + + headnode = tree->headnode; + Log_Print( "------ FloodEntities -------\n" ); + inside = false; + tree->outside_node.occupied = 0; + + //start at entity 1 not the world ( = 0) + for ( i = 1; i < num_entities; i++ ) + { + GetVectorForKey( &entities[i], "origin", origin ); + if ( VectorCompare( origin, vec3_origin ) ) { + continue; + } + + cl = ValueForKey( &entities[i], "classname" ); + origin[2] += 1; //so objects on floor are ok + +// Log_Print("flooding from entity %d: %s\n", i, cl); + //nudge playerstart around if needed so clipping hulls allways + //have a valid point + if ( !strcmp( cl, "info_player_start" ) ) { + for ( x = -16; x <= 16; x += 16 ) + { + for ( y = -16; y <= 16; y += 16 ) + { + origin[0] += x; + origin[1] += y; + if ( PlaceOccupant( headnode, origin, &entities[i] ) ) { + inside = true; + x = 999; //stop for this info_player_start + break; + } //end if + origin[0] -= x; + origin[1] -= y; + } //end for + } //end for + } //end if + else + { + if ( PlaceOccupant( headnode, origin, &entities[i] ) ) { + inside = true; + } //end if + } //end else + } //end for + + if ( !inside ) { + Log_Print( "WARNING: no entities inside\n" ); + } //end if + else if ( tree->outside_node.occupied ) { + Log_Print( "WARNING: entity reached from outside\n" ); + } //end else if + + return (qboolean)( inside && !tree->outside_node.occupied ); +} //end of the function FloodEntities + +/* +========================================================= + +FILL OUTSIDE + +========================================================= +*/ + +int c_outside; +int c_inside; +int c_solid; + +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void FillOutside_r( node_t *node ) { + if ( node->planenum != PLANENUM_LEAF ) { + FillOutside_r( node->children[0] ); + FillOutside_r( node->children[1] ); + return; + } //end if + // anything not reachable by an entity + // can be filled away (by setting solid contents) + if ( !node->occupied ) { + if ( !( node->contents & CONTENTS_SOLID ) ) { + c_outside++; + node->contents |= CONTENTS_SOLID; + } //end if + else + { + c_solid++; + } //end else + } //end if + else + { + c_inside++; + } //end else +} //end of the function FillOutside_r +//=========================================================================== +// Fill all nodes that can't be reached by entities +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void FillOutside( node_t *headnode ) { + c_outside = 0; + c_inside = 0; + c_solid = 0; + Log_Print( "------- FillOutside --------\n" ); + FillOutside_r( headnode ); + Log_Print( "%5i solid leaves\n", c_solid ); + Log_Print( "%5i leaves filled\n", c_outside ); + Log_Print( "%5i inside leaves\n", c_inside ); +} //end of the function FillOutside + +/* +========================================================= + +FLOOD AREAS + +========================================================= +*/ + +int c_areas; + +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void FloodAreas_r( node_t *node ) { + portal_t *p; + int s; + bspbrush_t *b; + entity_t *e; + + if ( node->contents == CONTENTS_AREAPORTAL ) { + // this node is part of an area portal + b = node->brushlist; + e = &entities[b->original->entitynum]; + + // if the current area has allready touched this + // portal, we are done + if ( e->portalareas[0] == c_areas || e->portalareas[1] == c_areas ) { + return; + } + + // note the current area as bounding the portal + if ( e->portalareas[1] ) { + Log_Print( "WARNING: areaportal entity %i touches > 2 areas\n", b->original->entitynum ); + return; + } + if ( e->portalareas[0] ) { + e->portalareas[1] = c_areas; + } else { + e->portalareas[0] = c_areas; + } + + return; + } //end if + + if ( node->area ) { + return; // allready got it + } + node->area = c_areas; + + for ( p = node->portals ; p ; p = p->next[s] ) + { + s = ( p->nodes[1] == node ); +#if 0 + if ( p->nodes[!s]->occupied ) { + continue; + } +#endif + if ( !Portal_EntityFlood( p, s ) ) { + continue; + } + + FloodAreas_r( p->nodes[!s] ); + } //end for +} //end of the function FloodAreas_r +//=========================================================================== +// Just decend the tree, and for each node that hasn't had an +// area set, flood fill out from there +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void FindAreas_r( node_t *node ) { + if ( node->planenum != PLANENUM_LEAF ) { + FindAreas_r( node->children[0] ); + FindAreas_r( node->children[1] ); + return; + } + + if ( node->area ) { + return; // allready got it + + } + if ( node->contents & CONTENTS_SOLID ) { + return; + } + + if ( !node->occupied ) { + return; // not reachable by entities + + } + // area portals are allways only flooded into, never + // out of + if ( node->contents == CONTENTS_AREAPORTAL ) { + return; + } + + c_areas++; + FloodAreas_r( node ); +} //end of the function FindAreas_r +//=========================================================================== +// Just decend the tree, and for each node that hasn't had an +// area set, flood fill out from there +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void SetAreaPortalAreas_r( node_t *node ) { + bspbrush_t *b; + entity_t *e; + + if ( node->planenum != PLANENUM_LEAF ) { + SetAreaPortalAreas_r( node->children[0] ); + SetAreaPortalAreas_r( node->children[1] ); + return; + } //end if + + if ( node->contents == CONTENTS_AREAPORTAL ) { + if ( node->area ) { + return; // allready set + + } + b = node->brushlist; + e = &entities[b->original->entitynum]; + node->area = e->portalareas[0]; + if ( !e->portalareas[1] ) { + Log_Print( "WARNING: areaportal entity %i doesn't touch two areas\n", b->original->entitynum ); + return; + } //end if + } //end if +} //end of the function SetAreaPortalAreas_r +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +/* +void EmitAreaPortals(node_t *headnode) +{ + int i, j; + entity_t *e; + dareaportal_t *dp; + + if (c_areas > MAX_MAP_AREAS) + Error ("MAX_MAP_AREAS"); + numareas = c_areas+1; + numareaportals = 1; // leave 0 as an error + + for (i=1 ; i<=c_areas ; i++) + { + dareas[i].firstareaportal = numareaportals; + for (j=0 ; jareaportalnum) + continue; + dp = &dareaportals[numareaportals]; + if (e->portalareas[0] == i) + { + dp->portalnum = e->areaportalnum; + dp->otherarea = e->portalareas[1]; + numareaportals++; + } //end if + else if (e->portalareas[1] == i) + { + dp->portalnum = e->areaportalnum; + dp->otherarea = e->portalareas[0]; + numareaportals++; + } //end else if + } //end for + dareas[i].numareaportals = numareaportals - dareas[i].firstareaportal; + } //end for + + Log_Print("%5i numareas\n", numareas); + Log_Print("%5i numareaportals\n", numareaportals); +} //end of the function EmitAreaPortals +*/ +//=========================================================================== +// Mark each leaf with an area, bounded by CONTENTS_AREAPORTAL +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void FloodAreas( tree_t *tree ) { + Log_Print( "--- FloodAreas ---\n" ); + FindAreas_r( tree->headnode ); + SetAreaPortalAreas_r( tree->headnode ); + Log_Print( "%5i areas\n", c_areas ); +} //end of the function FloodAreas +//=========================================================================== +// Finds a brush side to use for texturing the given portal +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void FindPortalSide( portal_t *p ) { + int viscontents; + bspbrush_t *bb; + mapbrush_t *brush; + node_t *n; + int i,j; + int planenum; + side_t *side, *bestside; + float dot, bestdot; + plane_t *p1, *p2; + + // decide which content change is strongest + // solid > lava > water, etc + viscontents = VisibleContents( p->nodes[0]->contents ^ p->nodes[1]->contents ); + if ( !viscontents ) { + return; + } + + planenum = p->onnode->planenum; + bestside = NULL; + bestdot = 0; + + for ( j = 0 ; j < 2 ; j++ ) + { + n = p->nodes[j]; + p1 = &mapplanes[p->onnode->planenum]; + for ( bb = n->brushlist ; bb ; bb = bb->next ) + { + brush = bb->original; + if ( !( brush->contents & viscontents ) ) { + continue; + } + for ( i = 0 ; i < brush->numsides ; i++ ) + { + side = &brush->original_sides[i]; + if ( side->flags & SFL_BEVEL ) { + continue; + } + if ( side->texinfo == TEXINFO_NODE ) { + continue; // non-visible + } + if ( ( side->planenum & ~1 ) == planenum ) { // exact match + bestside = &brush->original_sides[i]; + goto gotit; + } //end if + // see how close the match is + p2 = &mapplanes[side->planenum & ~1]; + dot = DotProduct( p1->normal, p2->normal ); + if ( dot > bestdot ) { + bestdot = dot; + bestside = side; + } //end if + } //end for + } //end for + } //end for + +gotit: + if ( !bestside ) { + Log_Print( "WARNING: side not found for portal\n" ); + } + + p->sidefound = true; + p->side = bestside; +} //end of the function FindPortalSide +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void MarkVisibleSides_r( node_t *node ) { + portal_t *p; + int s; + + if ( node->planenum != PLANENUM_LEAF ) { + MarkVisibleSides_r( node->children[0] ); + MarkVisibleSides_r( node->children[1] ); + return; + } //end if + + // empty leaves are never boundary leaves + if ( !node->contents ) { + return; + } + + // see if there is a visible face + for ( p = node->portals ; p ; p = p->next[!s] ) + { + s = ( p->nodes[0] == node ); + if ( !p->onnode ) { + continue; // edge of world + } + if ( !p->sidefound ) { + FindPortalSide( p ); + } + if ( p->side ) { + p->side->flags |= SFL_VISIBLE; + } + } //end for +} //end of the function MarkVisibleSides_r +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void MarkVisibleSides( tree_t *tree, int startbrush, int endbrush ) { + int i, j; + mapbrush_t *mb; + int numsides; + + Log_Print( "--- MarkVisibleSides ---\n" ); + + // clear all the visible flags + for ( i = startbrush ; i < endbrush ; i++ ) + { + mb = &mapbrushes[i]; + + numsides = mb->numsides; + for ( j = 0 ; j < numsides ; j++ ) + mb->original_sides[j].flags &= ~SFL_VISIBLE; + } + + // set visible flags on the sides that are used by portals + MarkVisibleSides_r( tree->headnode ); +} //end of the function MarkVisibleSides + diff --git a/Projects/Android/jni/rtcw/src/bspc/prtfile.c b/Projects/Android/jni/rtcw/src/bspc/prtfile.c new file mode 100644 index 0000000..f412d5a --- /dev/null +++ b/Projects/Android/jni/rtcw/src/bspc/prtfile.c @@ -0,0 +1,287 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +// NO LONGER USED +#if 0 +#include "qbsp.h" + +extern dleaf_t dleafs[MAX_MAP_LEAFS]; +/* +============================================================================== + +PORTAL FILE GENERATION + +Save out name.prt for qvis to read +============================================================================== +*/ + + +#define PORTALFILE "PRT1" + +FILE *pf; +int num_visclusters; // clusters the player can be in +int num_visportals; + +void WriteFloat2( FILE *f, vec_t v ) { + if ( fabs( v - Q_rint( v ) ) < 0.001 ) { + fprintf( f,"%i ",(int)Q_rint( v ) ); + } else { + fprintf( f,"%f ",v ); + } +} + +/* +================= +WritePortalFile_r +================= +*/ +void WritePortalFile_r( node_t *node ) { + int i, s; + portal_t *p; + winding_t *w; + vec3_t normal; + vec_t dist; + + // decision node + if ( node->planenum != PLANENUM_LEAF && !node->detail_seperator ) { + WritePortalFile_r( node->children[0] ); + WritePortalFile_r( node->children[1] ); + return; + } + + if ( node->contents & CONTENTS_SOLID ) { + return; + } + + for ( p = node->portals ; p ; p = p->next[s] ) + { + w = p->winding; + s = ( p->nodes[1] == node ); + if ( w && p->nodes[0] == node ) { + if ( !Portal_VisFlood( p ) ) { + continue; + } + // write out to the file + + // sometimes planes get turned around when they are very near + // the changeover point between different axis. interpret the + // plane the same way vis will, and flip the side orders if needed + // FIXME: is this still relevent? + WindingPlane( w, normal, &dist ); + if ( DotProduct( p->plane.normal, normal ) < 0.99 ) { // backwards... + fprintf( pf,"%i %i %i ",w->numpoints, p->nodes[1]->cluster, p->nodes[0]->cluster ); + } else { + fprintf( pf,"%i %i %i ",w->numpoints, p->nodes[0]->cluster, p->nodes[1]->cluster ); + } + for ( i = 0 ; i < w->numpoints ; i++ ) + { + fprintf( pf,"(" ); + WriteFloat2( pf, w->p[i][0] ); + WriteFloat2( pf, w->p[i][1] ); + WriteFloat2( pf, w->p[i][2] ); + fprintf( pf,") " ); + } + fprintf( pf,"\n" ); + } + } + +} + +/* +================ +FillLeafNumbers_r + +All of the leafs under node will have the same cluster +================ +*/ +void FillLeafNumbers_r( node_t *node, int num ) { + if ( node->planenum == PLANENUM_LEAF ) { + if ( node->contents & CONTENTS_SOLID ) { + node->cluster = -1; + } else { + node->cluster = num; + } + return; + } + node->cluster = num; + FillLeafNumbers_r( node->children[0], num ); + FillLeafNumbers_r( node->children[1], num ); +} + +/* +================ +NumberLeafs_r +================ +*/ +void NumberLeafs_r( node_t *node ) { + portal_t *p; + + if ( node->planenum != PLANENUM_LEAF && !node->detail_seperator ) { // decision node + node->cluster = -99; + NumberLeafs_r( node->children[0] ); + NumberLeafs_r( node->children[1] ); + return; + } + + // either a leaf or a detail cluster + + if ( node->contents & CONTENTS_SOLID ) { // solid block, viewpoint never inside + node->cluster = -1; + return; + } + + FillLeafNumbers_r( node, num_visclusters ); + num_visclusters++; + + // count the portals + for ( p = node->portals ; p ; ) + { + if ( p->nodes[0] == node ) { // only write out from first leaf + if ( Portal_VisFlood( p ) ) { + num_visportals++; + } + p = p->next[0]; + } else { + p = p->next[1]; + } + } + +} + + +/* +================ +CreateVisPortals_r +================ +*/ +void CreateVisPortals_r( node_t *node ) { + // stop as soon as we get to a detail_seperator, which + // means that everything below is in a single cluster + if ( node->planenum == PLANENUM_LEAF || node->detail_seperator ) { + return; + } + + MakeNodePortal( node ); + SplitNodePortals( node ); + + CreateVisPortals_r( node->children[0] ); + CreateVisPortals_r( node->children[1] ); +} + +/* +================ +FinishVisPortals_r +================ +*/ +void FinishVisPortals2_r( node_t *node ) { + if ( node->planenum == PLANENUM_LEAF ) { + return; + } + + MakeNodePortal( node ); + SplitNodePortals( node ); + + FinishVisPortals2_r( node->children[0] ); + FinishVisPortals2_r( node->children[1] ); +} + +void FinishVisPortals_r( node_t *node ) { + if ( node->planenum == PLANENUM_LEAF ) { + return; + } + + if ( node->detail_seperator ) { + FinishVisPortals2_r( node ); + return; + } + + FinishVisPortals_r( node->children[0] ); + FinishVisPortals_r( node->children[1] ); +} + + +int clusterleaf; +void SaveClusters_r( node_t *node ) { + if ( node->planenum == PLANENUM_LEAF ) { + dleafs[clusterleaf++].cluster = node->cluster; + return; + } + SaveClusters_r( node->children[0] ); + SaveClusters_r( node->children[1] ); +} + +/* +================ +WritePortalFile +================ +*/ +void WritePortalFile( tree_t *tree ) { + char filename[1024]; + node_t *headnode; + + qprintf( "--- WritePortalFile ---\n" ); + + headnode = tree->headnode; + num_visclusters = 0; + num_visportals = 0; + + Tree_FreePortals_r( headnode ); + + MakeHeadnodePortals( tree ); + + CreateVisPortals_r( headnode ); + +// set the cluster field in every leaf and count the total number of portals + + NumberLeafs_r( headnode ); + +// write the file + sprintf( filename, "%s.prt", source ); + printf( "writing %s\n", filename ); + pf = fopen( filename, "w" ); + if ( !pf ) { + Error( "Error opening %s", filename ); + } + + fprintf( pf, "%s\n", PORTALFILE ); + fprintf( pf, "%i\n", num_visclusters ); + fprintf( pf, "%i\n", num_visportals ); + + qprintf( "%5i visclusters\n", num_visclusters ); + qprintf( "%5i visportals\n", num_visportals ); + + WritePortalFile_r( headnode ); + + fclose( pf ); + + // we need to store the clusters out now because ordering + // issues made us do this after writebsp... + clusterleaf = 1; + SaveClusters_r( headnode ); +} +#endif diff --git a/Projects/Android/jni/rtcw/src/bspc/q2files.h b/Projects/Android/jni/rtcw/src/bspc/q2files.h new file mode 100644 index 0000000..9c33e06 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/bspc/q2files.h @@ -0,0 +1,494 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +// +// qfiles.h: quake file formats +// This file must be identical in the quake and utils directories +// + +/* +======================================================================== + +The .pak files are just a linear collapse of a directory tree + +======================================================================== +*/ + +#define IDPAKHEADER ( ( 'K' << 24 ) + ( 'C' << 16 ) + ( 'A' << 8 ) + 'P' ) + +typedef struct +{ + char name[56]; + int filepos, filelen; +} dpackfile_t; + +typedef struct +{ + int ident; // == IDPAKHEADER + int dirofs; + int dirlen; +} dpackheader_t; + +#define MAX_FILES_IN_PACK 4096 + + +/* +======================================================================== + +PCX files are used for as many images as possible + +======================================================================== +*/ + +typedef struct +{ + char manufacturer; + char version; + char encoding; + char bits_per_pixel; + unsigned short xmin,ymin,xmax,ymax; + unsigned short hres,vres; + unsigned char palette[48]; + char reserved; + char color_planes; + unsigned short bytes_per_line; + unsigned short palette_type; + char filler[58]; + unsigned char data; // unbounded +} pcx_t; + + +/* +======================================================================== + +.MD2 triangle model file format + +======================================================================== +*/ + +#define IDALIASHEADER ( ( '2' << 24 ) + ( 'P' << 16 ) + ( 'D' << 8 ) + 'I' ) +#define ALIAS_VERSION 8 + +#define MAX_TRIANGLES 4096 +#define MAX_VERTS 2048 +#define MAX_FRAMES 512 +#define MAX_MD2SKINS 32 +#define MAX_SKINNAME 64 + +typedef struct +{ + short s; + short t; +} dstvert_t; + +typedef struct +{ + short index_xyz[3]; + short index_st[3]; +} dtriangle_t; + +typedef struct +{ + byte v[3]; // scaled byte to fit in frame mins/maxs + byte lightnormalindex; +} dtrivertx_t; + +#define DTRIVERTX_V0 0 +#define DTRIVERTX_V1 1 +#define DTRIVERTX_V2 2 +#define DTRIVERTX_LNI 3 +#define DTRIVERTX_SIZE 4 + +typedef struct +{ + float scale[3]; // multiply byte verts by this + float translate[3]; // then add this + char name[16]; // frame name from grabbing + dtrivertx_t verts[1]; // variable sized +} daliasframe_t; + + +// the glcmd format: +// a positive integer starts a tristrip command, followed by that many +// vertex structures. +// a negative integer starts a trifan command, followed by -x vertexes +// a zero indicates the end of the command list. +// a vertex consists of a floating point s, a floating point t, +// and an integer vertex index. + + +typedef struct +{ + int ident; + int version; + + int skinwidth; + int skinheight; + int framesize; // byte size of each frame + + int num_skins; + int num_xyz; + int num_st; // greater than num_xyz for seams + int num_tris; + int num_glcmds; // dwords in strip/fan command list + int num_frames; + + int ofs_skins; // each skin is a MAX_SKINNAME string + int ofs_st; // byte offset from start for stverts + int ofs_tris; // offset for dtriangles + int ofs_frames; // offset for first frame + int ofs_glcmds; + int ofs_end; // end of file + +} dmdl_t; + +/* +======================================================================== + +.SP2 sprite file format + +======================================================================== +*/ + +#define IDSPRITEHEADER ( ( '2' << 24 ) + ( 'S' << 16 ) + ( 'D' << 8 ) + 'I' ) +// little-endian "IDS2" +#define SPRITE_VERSION 2 + +typedef struct +{ + int width, height; + int origin_x, origin_y; // raster coordinates inside pic + char name[MAX_SKINNAME]; // name of pcx file +} dsprframe_t; + +typedef struct { + int ident; + int version; + int numframes; + dsprframe_t frames[1]; // variable sized +} dsprite_t; + +/* +============================================================================== + + .WAL texture file format + +============================================================================== +*/ + + +#define MIPLEVELS 4 +typedef struct miptex_s +{ + char name[32]; + unsigned width, height; + unsigned offsets[MIPLEVELS]; // four mip maps stored + char animname[32]; // next frame in animation chain + int flags; + int contents; + int value; +} miptex_t; + + + +/* +============================================================================== + + .BSP file format + +============================================================================== +*/ + +#define IDBSPHEADER ( ( 'P' << 24 ) + ( 'S' << 16 ) + ( 'B' << 8 ) + 'I' ) +// little-endian "IBSP" + +#define BSPVERSION 38 + + +// upper design bounds +// leaffaces, leafbrushes, planes, and verts are still bounded by +// 16 bit short limits +#define MAX_MAP_MODELS 1024 +#define MAX_MAP_BRUSHES 8192 +#define MAX_MAP_ENTITIES 2048 +#define MAX_MAP_ENTSTRING 0x40000 +#define MAX_MAP_TEXINFO 8192 + +#define MAX_MAP_AREAS 256 +#define MAX_MAP_AREAPORTALS 1024 +#define MAX_MAP_PLANES 65536 +#define MAX_MAP_NODES 65536 +#define MAX_MAP_BRUSHSIDES 65536 +#define MAX_MAP_LEAFS 65536 +#define MAX_MAP_VERTS 65536 +#define MAX_MAP_FACES 65536 +#define MAX_MAP_LEAFFACES 65536 +#define MAX_MAP_LEAFBRUSHES 65536 +#define MAX_MAP_PORTALS 65536 +#define MAX_MAP_EDGES 128000 +#define MAX_MAP_SURFEDGES 256000 +#define MAX_MAP_LIGHTING 0x320000 +#define MAX_MAP_VISIBILITY 0x280000 + +// key / value pair sizes + +#define MAX_KEY 32 +#define MAX_VALUE 1024 + +//============================================================================= + +typedef struct +{ + int fileofs, filelen; +} lump_t; + +#define LUMP_ENTITIES 0 +#define LUMP_PLANES 1 +#define LUMP_VERTEXES 2 +#define LUMP_VISIBILITY 3 +#define LUMP_NODES 4 +#define LUMP_TEXINFO 5 +#define LUMP_FACES 6 +#define LUMP_LIGHTING 7 +#define LUMP_LEAFS 8 +#define LUMP_LEAFFACES 9 +#define LUMP_LEAFBRUSHES 10 +#define LUMP_EDGES 11 +#define LUMP_SURFEDGES 12 +#define LUMP_MODELS 13 +#define LUMP_BRUSHES 14 +#define LUMP_BRUSHSIDES 15 +#define LUMP_POP 16 +#define LUMP_AREAS 17 +#define LUMP_AREAPORTALS 18 +#define HEADER_LUMPS 19 + +typedef struct +{ + int ident; + int version; + lump_t lumps[HEADER_LUMPS]; +} dheader_t; + +typedef struct +{ + float mins[3], maxs[3]; + float origin[3]; // for sounds or lights + int headnode; + int firstface, numfaces; // submodels just draw faces + // without walking the bsp tree +} dmodel_t; + + +typedef struct +{ + float point[3]; +} dvertex_t; + + +// 0-2 are axial planes +#define PLANE_X 0 +#define PLANE_Y 1 +#define PLANE_Z 2 + +// 3-5 are non-axial planes snapped to the nearest +#define PLANE_ANYX 3 +#define PLANE_ANYY 4 +#define PLANE_ANYZ 5 + +// planes (x&~1) and (x&~1)+1 are allways opposites + +typedef struct +{ + float normal[3]; + float dist; + int type; // PLANE_X - PLANE_ANYZ ?remove? trivial to regenerate +} dplane_t; + + +// contents flags are seperate bits +// a given brush can contribute multiple content bits +// multiple brushes can be in a single leaf + +// these definitions also need to be in q_shared.h! + +// lower bits are stronger, and will eat weaker brushes completely +#define CONTENTS_SOLID 1 // an eye is never valid in a solid +#define CONTENTS_WINDOW 2 // translucent, but not watery +#define CONTENTS_AUX 4 +#define CONTENTS_LAVA 8 +#define CONTENTS_SLIME 16 +#define CONTENTS_WATER 32 +#define CONTENTS_MIST 64 +#define LAST_VISIBLE_CONTENTS 64 + +// remaining contents are non-visible, and don't eat brushes + +#define CONTENTS_AREAPORTAL 0x8000 + +#define CONTENTS_PLAYERCLIP 0x10000 +#define CONTENTS_MONSTERCLIP 0x20000 + +// currents can be added to any other contents, and may be mixed +#define CONTENTS_CURRENT_0 0x40000 +#define CONTENTS_CURRENT_90 0x80000 +#define CONTENTS_CURRENT_180 0x100000 +#define CONTENTS_CURRENT_270 0x200000 +#define CONTENTS_CURRENT_UP 0x400000 +#define CONTENTS_CURRENT_DOWN 0x800000 + +#define CONTENTS_ORIGIN 0x1000000 // removed before bsping an entity + +#define CONTENTS_MONSTER 0x2000000 // should never be on a brush, only in game +#define CONTENTS_DEADMONSTER 0x4000000 +#define CONTENTS_DETAIL 0x8000000 // brushes to be added after vis leafs +//renamed because it's in conflict with the Q3A translucent contents +#define CONTENTS_Q2TRANSLUCENT 0x10000000 // auto set if any surface has trans +#define CONTENTS_LADDER 0x20000000 + + + +#define SURF_LIGHT 0x1 // value will hold the light strength + +#define SURF_SLICK 0x2 // effects game physics + +#define SURF_SKY 0x4 // don't draw, but add to skybox +#define SURF_WARP 0x8 // turbulent water warp +#define SURF_TRANS33 0x10 +#define SURF_TRANS66 0x20 +#define SURF_FLOWING 0x40 // scroll towards angle +#define SURF_NODRAW 0x80 // don't bother referencing the texture + +#define SURF_HINT 0x100 // make a primary bsp splitter +#define SURF_SKIP 0x200 // completely ignore, allowing non-closed brushes + + + +typedef struct +{ + int planenum; + int children[2]; // negative numbers are -(leafs+1), not nodes + short mins[3]; // for frustom culling + short maxs[3]; + unsigned short firstface; + unsigned short numfaces; // counting both sides +} dnode_t; + + +typedef struct texinfo_s +{ + float vecs[2][4]; // [s/t][xyz offset] + int flags; // miptex flags + overrides + int value; // light emission, etc + char texture[32]; // texture name (textures/*.wal) + int nexttexinfo; // for animations, -1 = end of chain +} texinfo_t; + + +// note that edge 0 is never used, because negative edge nums are used for +// counterclockwise use of the edge in a face +typedef struct +{ + unsigned short v[2]; // vertex numbers +} dedge_t; + +#define MAXLIGHTMAPS 4 +typedef struct +{ + unsigned short planenum; + short side; + + int firstedge; // we must support > 64k edges + short numedges; + short texinfo; + +// lighting info + byte styles[MAXLIGHTMAPS]; + int lightofs; // start of [numstyles*surfsize] samples +} dface_t; + +typedef struct +{ + int contents; // OR of all brushes (not needed?) + + short cluster; + short area; + + short mins[3]; // for frustum culling + short maxs[3]; + + unsigned short firstleafface; + unsigned short numleaffaces; + + unsigned short firstleafbrush; + unsigned short numleafbrushes; +} dleaf_t; + +typedef struct +{ + unsigned short planenum; // facing out of the leaf + short texinfo; +} dbrushside_t; + +typedef struct +{ + int firstside; + int numsides; + int contents; +} dbrush_t; + +#define ANGLE_UP -1 +#define ANGLE_DOWN -2 + + +// the visibility lump consists of a header with a count, then +// byte offsets for the PVS and PHS of each cluster, then the raw +// compressed bit vectors +#define DVIS_PVS 0 +#define DVIS_PHS 1 +typedef struct +{ + int numclusters; + int bitofs[8][2]; // bitofs[numclusters][2] +} dvis_t; + +// each area has a list of portals that lead into other areas +// when portals are closed, other areas may not be visible or +// hearable even if the vis info says that it should be +typedef struct +{ + int portalnum; + int otherarea; +} dareaportal_t; + +typedef struct +{ + int numareaportals; + int firstareaportal; +} darea_t; diff --git a/Projects/Android/jni/rtcw/src/bspc/q3files.h b/Projects/Android/jni/rtcw/src/bspc/q3files.h new file mode 100644 index 0000000..78d3f79 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/bspc/q3files.h @@ -0,0 +1,379 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +#ifndef __QFILES_H__ +#define __QFILES_H__ + +// +// qfiles.h: quake file formats +// This file must be identical in the quake and utils directories +// + +// surface geometry should not exceed these limits +#define SHADER_MAX_VERTEXES 1000 +#define SHADER_MAX_INDEXES ( 6 * SHADER_MAX_VERTEXES ) + + +// the maximum size of game reletive pathnames +#define MAX_QPATH 64 + + +/* +======================================================================== + +PCX files are used for 8 bit images + +======================================================================== +*/ +/* +typedef struct { + char manufacturer; + char version; + char encoding; + char bits_per_pixel; + unsigned short xmin,ymin,xmax,ymax; + unsigned short hres,vres; + unsigned char palette[48]; + char reserved; + char color_planes; + unsigned short bytes_per_line; + unsigned short palette_type; + char filler[58]; + unsigned char data; // unbounded +} pcx_t; +*/ + +/* +======================================================================== + +TGA files are used for 24/32 bit images + +======================================================================== +*/ +/* +typedef struct _TargaHeader { + unsigned char id_length, colormap_type, image_type; + unsigned short colormap_index, colormap_length; + unsigned char colormap_size; + unsigned short x_origin, y_origin, width, height; + unsigned char pixel_size, attributes; +} TargaHeader; +*/ + +/* +======================================================================== + +.MD3 triangle model file format + +======================================================================== +*/ + +#define MD3_IDENT ( ( '3' << 24 ) + ( 'P' << 16 ) + ( 'D' << 8 ) + 'I' ) +#define MD3_VERSION 15 + +// limits +#define MD3_MAX_LODS 4 +#define MD3_MAX_TRIANGLES 8192 // per surface +#define MD3_MAX_VERTS 4096 // per surface +#define MD3_MAX_SHADERS 256 // per surface +#define MD3_MAX_FRAMES 1024 // per model +#define MD3_MAX_SURFACES 32 // per model +#define MD3_MAX_TAGS 16 // per frame + +// vertex scales +#define MD3_XYZ_SCALE ( 1.0 / 64 ) + +typedef struct md3Frame_s { + vec3_t bounds[2]; + vec3_t localOrigin; + float radius; + char name[16]; +} md3Frame_t; + +typedef struct md3Tag_s { + char name[MAX_QPATH]; // tag name + vec3_t origin; + vec3_t axis[3]; +} md3Tag_t; + +/* +** md3Surface_t +** +** CHUNK SIZE +** header sizeof( md3Surface_t ) +** shaders sizeof( md3Shader_t ) * numShaders +** triangles[0] sizeof( md3Triangle_t ) * numTriangles +** st sizeof( md3St_t ) * numVerts +** XyzNormals sizeof( md3XyzNormal_t ) * numVerts * numFrames +*/ + +typedef struct { + int ident; // + + char name[MAX_QPATH]; // polyset name + + int flags; + int numFrames; // all surfaces in a model should have the same + + int numShaders; // all surfaces in a model should have the same + int numVerts; + + int numTriangles; + int ofsTriangles; + + int ofsShaders; // offset from start of md3Surface_t + int ofsSt; // texture coords are common for all frames + int ofsXyzNormals; // numVerts * numFrames + + int ofsEnd; // next surface follows +} md3Surface_t; + +typedef struct { + char name[MAX_QPATH]; + int shaderIndex; // for in-game use +} md3Shader_t; + +typedef struct { + int indexes[3]; +} md3Triangle_t; + +typedef struct { + float st[2]; +} md3St_t; + +typedef struct { + short xyz[3]; + short normal; +} md3XyzNormal_t; + +typedef struct { + int ident; + int version; + + char name[MAX_QPATH]; // model name + + int flags; + + int numFrames; + int numTags; + int numSurfaces; + + int numSkins; + + int ofsFrames; // offset for first frame + int ofsTags; // numFrames * numTags + int ofsSurfaces; // first surface, others follow + + int ofsEnd; // end of file +} md3Header_t; + + + +/* +============================================================================== + + .BSP file format + +============================================================================== +*/ + + +#define Q3_BSP_IDENT ( ( 'P' << 24 ) + ( 'S' << 16 ) + ( 'B' << 8 ) + 'I' ) +// little-endian "IBSP" + +#define Q3_BSP_VERSION 47 + + +// there shouldn't be any problem with increasing these values at the +// expense of more memory allocation in the utilities +#define Q3_MAX_MAP_MODELS 0x400 +#define Q3_MAX_MAP_BRUSHES 0x8000 +#define Q3_MAX_MAP_ENTITIES 0x800 +#define Q3_MAX_MAP_ENTSTRING 0x10000 +#define Q3_MAX_MAP_SHADERS 0x400 + +#define Q3_MAX_MAP_AREAS 0x100 // MAX_MAP_AREA_BYTES in q_shared must match! +#define Q3_MAX_MAP_FOGS 0x100 +#define Q3_MAX_MAP_PLANES 0x10000 +#define Q3_MAX_MAP_NODES 0x10000 +#define Q3_MAX_MAP_BRUSHSIDES 0x10000 +#define Q3_MAX_MAP_LEAFS 0x10000 +#define Q3_MAX_MAP_LEAFFACES 0x10000 +#define Q3_MAX_MAP_LEAFBRUSHES 0x10000 +#define Q3_MAX_MAP_PORTALS 0x10000 +#define Q3_MAX_MAP_LIGHTING 0x400000 +#define Q3_MAX_MAP_LIGHTGRID 0x400000 +#define Q3_MAX_MAP_VISIBILITY 0x200000 + +#define Q3_MAX_MAP_DRAW_SURFS 0x20000 +#define Q3_MAX_MAP_DRAW_VERTS 0x80000 +#define Q3_MAX_MAP_DRAW_INDEXES 0x80000 + + +// key / value pair sizes in the entities lump +#define Q3_MAX_KEY 32 +#define Q3_MAX_VALUE 1024 + +// the editor uses these predefined yaw angles to orient entities up or down +#define ANGLE_UP -1 +#define ANGLE_DOWN -2 + +#define LIGHTMAP_WIDTH 128 +#define LIGHTMAP_HEIGHT 128 + + +//============================================================================= + + +typedef struct { + int fileofs, filelen; +} q3_lump_t; + +#define Q3_LUMP_ENTITIES 0 +#define Q3_LUMP_SHADERS 1 +#define Q3_LUMP_PLANES 2 +#define Q3_LUMP_NODES 3 +#define Q3_LUMP_LEAFS 4 +#define Q3_LUMP_LEAFSURFACES 5 +#define Q3_LUMP_LEAFBRUSHES 6 +#define Q3_LUMP_MODELS 7 +#define Q3_LUMP_BRUSHES 8 +#define Q3_LUMP_BRUSHSIDES 9 +#define Q3_LUMP_DRAWVERTS 10 +#define Q3_LUMP_DRAWINDEXES 11 +#define Q3_LUMP_FOGS 12 +#define Q3_LUMP_SURFACES 13 +#define Q3_LUMP_LIGHTMAPS 14 +#define Q3_LUMP_LIGHTGRID 15 +#define Q3_LUMP_VISIBILITY 16 +#define Q3_HEADER_LUMPS 17 + +typedef struct { + int ident; + int version; + + q3_lump_t lumps[Q3_HEADER_LUMPS]; +} q3_dheader_t; + +typedef struct { + float mins[3], maxs[3]; + int firstSurface, numSurfaces; + int firstBrush, numBrushes; +} q3_dmodel_t; + +typedef struct { + char shader[MAX_QPATH]; + int surfaceFlags; + int contentFlags; +} q3_dshader_t; + +// planes (x&~1) and (x&~1)+1 are allways opposites + +typedef struct { + float normal[3]; + float dist; +} q3_dplane_t; + +typedef struct { + int planeNum; + int children[2]; // negative numbers are -(leafs+1), not nodes + int mins[3]; // for frustom culling + int maxs[3]; +} q3_dnode_t; + +typedef struct { + int cluster; // -1 = opaque cluster (do I still store these?) + int area; + + int mins[3]; // for frustum culling + int maxs[3]; + + int firstLeafSurface; + int numLeafSurfaces; + + int firstLeafBrush; + int numLeafBrushes; +} q3_dleaf_t; + +typedef struct { + int planeNum; // positive plane side faces out of the leaf + int shaderNum; +} q3_dbrushside_t; + +typedef struct { + int firstSide; + int numSides; + int shaderNum; // the shader that determines the contents flags +} q3_dbrush_t; + +typedef struct { + char shader[MAX_QPATH]; + int brushNum; + int visibleSide; // the brush side that ray tests need to clip against (-1 == none) +} q3_dfog_t; + +typedef struct { + vec3_t xyz; + float st[2]; + float lightmap[2]; + vec3_t normal; + byte color[4]; +} q3_drawVert_t; + +typedef enum { + MST_BAD, + MST_PLANAR, + MST_PATCH, + MST_TRIANGLE_SOUP, + MST_FLARE +} q3_mapSurfaceType_t; + +typedef struct { + int shaderNum; + int fogNum; + int surfaceType; + + int firstVert; + int numVerts; + + int firstIndex; + int numIndexes; + + int lightmapNum; + int lightmapX, lightmapY; + int lightmapWidth, lightmapHeight; + + vec3_t lightmapOrigin; + vec3_t lightmapVecs[3]; // for patches, [0] and [1] are lodbounds + + int patchWidth; + int patchHeight; +} q3_dsurface_t; + + +#endif diff --git a/Projects/Android/jni/rtcw/src/bspc/qbsp.h b/Projects/Android/jni/rtcw/src/bspc/qbsp.h new file mode 100644 index 0000000..ceb257d --- /dev/null +++ b/Projects/Android/jni/rtcw/src/bspc/qbsp.h @@ -0,0 +1,498 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + + +#if defined( WIN32 ) || defined( _WIN32 ) +#include +#endif +#include +#include "l_cmd.h" +#include "l_math.h" +#include "l_poly.h" +#include "l_threads.h" +#include "../botlib/l_script.h" +#include "l_bsp_ent.h" +#include "q2files.h" +#include "l_mem.h" +#include "l_utils.h" +#include "l_log.h" +#include "l_qfiles.h" + +//Mr Elusive shit +#define ME +#define DEBUG +#define NODELIST +#define SIN + +#define MAX_BRUSH_SIDES 128 //maximum number of sides per brush +#define CLIP_EPSILON 0.1 +//#define MAX_MAP_BOUNDS 65535 +#define MAX_MAP_BOUNDS ( 128 * 1024 ) // (SA) (9/17/01) new map dimensions (from Q3TA) +#define BOGUS_RANGE ( MAX_MAP_BOUNDS + 128 ) //somewhere outside the map + +#define TEXINFO_NODE -1 //side is allready on a node +#define PLANENUM_LEAF -1 //used for leaf nodes +#define MAXEDGES 20 //maximum number of face edges +#define MAX_NODE_BRUSHES 8 //maximum brushes in a node +//side flags +#define SFL_TESTED 1 +#define SFL_VISIBLE 2 +#define SFL_BEVEL 4 +#define SFL_TEXTURED 8 +#define SFL_CURVE 16 + +//map plane +typedef struct plane_s +{ + vec3_t normal; + vec_t dist; + int type; + int signbits; + struct plane_s *hash_chain; +} plane_t; +//brush texture +typedef struct +{ + vec_t shift[2]; + vec_t rotate; + vec_t scale[2]; + char name[32]; + int flags; + int value; +} brush_texture_t; +//brush side +typedef struct side_s +{ + int planenum; // map plane this side is in + int texinfo; // texture reference + winding_t *winding; // winding of this side + struct side_s *original; // bspbrush_t sides will reference the mapbrush_t sides + int lightinfo; // for SIN only + int contents; // from miptex + int surf; // from miptex + unsigned short flags; // side flags +} side_t; //sizeof(side_t) = 36 +//map brush +typedef struct mapbrush_s +{ + int entitynum; + int brushnum; + + int contents; +#ifdef ME + int expansionbbox; //bbox used for expansion of the brush + int leafnum; + int modelnum; +#endif + + vec3_t mins, maxs; + + int numsides; + side_t *original_sides; +} mapbrush_t; +//bsp face +typedef struct face_s +{ + struct face_s *next; // on node + + // the chain of faces off of a node can be merged or split, + // but each face_t along the way will remain in the chain + // until the entire tree is freed + struct face_s *merged; // if set, this face isn't valid anymore + struct face_s *split[2]; // if set, this face isn't valid anymore + + struct portal_s *portal; + int texinfo; +#ifdef SIN + int lightinfo; +#endif + int planenum; + int contents; // faces in different contents can't merge + int outputnumber; + winding_t *w; + int numpoints; + qboolean badstartvert; // tjunctions cannot be fixed without a midpoint vertex + int vertexnums[MAXEDGES]; +} face_t; +//bsp brush +typedef struct bspbrush_s +{ + struct bspbrush_s *next; + vec3_t mins, maxs; + int side, testside; // side of node during construction + mapbrush_t *original; + int numsides; + side_t sides[6]; // variably sized +} bspbrush_t; //sizeof(bspbrush_t) = 44 + numsides * sizeof(side_t) +//bsp node +typedef struct node_s +{ + //both leafs and nodes + int planenum; // -1 = leaf node + struct node_s *parent; + vec3_t mins, maxs; // valid after portalization + bspbrush_t *volume; // one for each leaf/node + + // nodes only + qboolean detail_seperator; // a detail brush caused the split + side_t *side; // the side that created the node + struct node_s *children[2]; + face_t *faces; + + // leafs only + bspbrush_t *brushlist; // fragments of all brushes in this leaf + int contents; // OR of all brush contents + int occupied; // 1 or greater can reach entity + entity_t *occupant; // for leak file testing + int cluster; // for portalfile writing + int area; // for areaportals + struct portal_s *portals; // also on nodes during construction +#ifdef NODELIST + struct node_s *next; //next node in the nodelist +#endif +#ifdef ME + int expansionbboxes; //OR of all bboxes used for expansion of the brushes + int modelnum; +#endif +} node_t; //sizeof(node_t) = 80 bytes +//bsp portal +typedef struct portal_s +{ + plane_t plane; + node_t *onnode; // NULL = outside box + node_t *nodes[2]; // [0] = front side of plane + struct portal_s *next[2]; + winding_t *winding; + + qboolean sidefound; // false if ->side hasn't been checked + side_t *side; // NULL = non-visible + face_t *face[2]; // output face in bsp file +#ifdef ME + struct tmp_face_s *tmpface; //pointer to the tmpface created for this portal + int planenum; //number of the map plane used by the portal +#endif +} portal_t; +//bsp tree +typedef struct +{ + node_t *headnode; + node_t outside_node; + vec3_t mins, maxs; +} tree_t; + +//============================================================================= +// bspc.c +//============================================================================= + +extern qboolean noprune; +extern qboolean nodetail; +extern qboolean fulldetail; +extern qboolean nomerge; +extern qboolean nosubdiv; +extern qboolean nowater; +extern qboolean noweld; +extern qboolean noshare; +extern qboolean notjunc; +extern qboolean onlyents; +#ifdef ME +extern qboolean nocsg; +extern qboolean create_aas; +extern qboolean freetree; +extern qboolean lessbrushes; +extern qboolean nobrushmerge; +extern qboolean cancelconversion; +extern qboolean noliquids; +extern qboolean capsule_collision; +extern qboolean writeaasmap; +#endif //ME + +extern float subdivide_size; +extern vec_t microvolume; + +extern char outbase[32]; +extern char source[1024]; + +//============================================================================= +// map.c +//============================================================================= + +#define MAX_MAPFILE_PLANES 128000 +#define MAX_MAPFILE_BRUSHES 65535 //16384 +#define MAX_MAPFILE_BRUSHSIDES ( MAX_MAPFILE_BRUSHES * 8 ) +#define MAX_MAPFILE_TEXINFO 8192 + +extern int entity_num; + +extern plane_t mapplanes[MAX_MAPFILE_PLANES]; +extern int nummapplanes; +extern int mapplaneusers[MAX_MAPFILE_PLANES]; + +extern int nummapbrushes; +extern mapbrush_t mapbrushes[MAX_MAPFILE_BRUSHES]; + +extern vec3_t map_mins, map_maxs; + +extern int nummapbrushsides; +extern side_t brushsides[MAX_MAPFILE_BRUSHSIDES]; +extern brush_texture_t side_brushtextures[MAX_MAPFILE_BRUSHSIDES]; + +#ifdef ME + +typedef struct +{ + float vecs[2][4]; // [s/t][xyz offset] + int flags; // miptex flags + overrides + int value; + char texture[64]; // texture name (textures/*.wal) + int nexttexinfo; // for animations, -1 = end of chain +} map_texinfo_t; + +extern map_texinfo_t map_texinfo[MAX_MAPFILE_TEXINFO]; +extern int map_numtexinfo; +#define NODESTACKSIZE 1024 + +#define MAPTYPE_QUAKE1 1 +#define MAPTYPE_QUAKE2 2 +#define MAPTYPE_QUAKE3 3 +#define MAPTYPE_HALFLIFE 4 +#define MAPTYPE_SIN 5 + +extern int nodestack[NODESTACKSIZE]; +extern int *nodestackptr; +extern int nodestacksize; +extern int brushmodelnumbers[MAX_MAPFILE_BRUSHES]; +extern int dbrushleafnums[MAX_MAPFILE_BRUSHES]; +extern int dplanes2mapplanes[MAX_MAPFILE_PLANES]; + +extern int loadedmaptype; +#endif //ME + +extern int c_boxbevels; +extern int c_edgebevels; +extern int c_areaportals; +extern int c_clipbrushes; +extern int c_squattbrushes; + +//finds a float plane for the given normal and distance +int FindFloatPlane( vec3_t normal, vec_t dist ); +//returns the plane type for the given normal +int PlaneTypeForNormal( vec3_t normal ); +//returns the plane defined by the three given points +int PlaneFromPoints( int *p0, int *p1, int *p2 ); +//add bevels to the map brush +void AddBrushBevels( mapbrush_t *b ); +//makes brush side windings for the brush +qboolean MakeBrushWindings( mapbrush_t *ob ); +//marks brush bevels of the brush as bevel +void MarkBrushBevels( mapbrush_t *brush ); +//returns true if the map brush already exists +int BrushExists( mapbrush_t *brush ); +//loads a map from a bsp file +int LoadMapFromBSP( struct quakefile_s *qf ); +//resets map loading +void ResetMapLoading( void ); +//print some map info +void PrintMapInfo( void ); +//writes a map file (type depending on loaded map type) +void WriteMapFile( char *filename ); + +//============================================================================= +// map_q2.c +//============================================================================= + +void Q2_ResetMapLoading( void ); +//loads a Quake2 map file +void Q2_LoadMapFile( char *filename ); +//loads a map from a Quake2 bsp file +void Q2_LoadMapFromBSP( char *filename, int offset, int length ); + +//============================================================================= +// map_q1.c +//============================================================================= + +void Q1_ResetMapLoading( void ); +//loads a Quake2 map file +void Q1_LoadMapFile( char *filename ); +//loads a map from a Quake1 bsp file +void Q1_LoadMapFromBSP( char *filename, int offset, int length ); + +//============================================================================= +// map_q3.c +//============================================================================= +void Q3_ResetMapLoading( void ); +//loads a map from a Quake3 bsp file +void Q3_LoadMapFromBSP( struct quakefile_s *qf ); + +//============================================================================= +// map_sin.c +//============================================================================= + +void Sin_ResetMapLoading( void ); +//loads a Sin map file +void Sin_LoadMapFile( char *filename ); +//loads a map from a Sin bsp file +void Sin_LoadMapFromBSP( char *filename, int offset, int length ); + +//============================================================================= +// map_hl.c +//============================================================================= + +void HL_ResetMapLoading( void ); +//loads a Half-Life map file +void HL_LoadMapFile( char *filename ); +//loads a map from a Half-Life bsp file +void HL_LoadMapFromBSP( char *filename, int offset, int length ); + +//============================================================================= +// textures.c +//============================================================================= + +typedef struct +{ + char name[64]; + int flags; + int value; + int contents; + char animname[64]; +} textureref_t; + +#define MAX_MAP_TEXTURES 1024 + +extern textureref_t textureref[MAX_MAP_TEXTURES]; + +int FindMiptex( char *name ); +int TexinfoForBrushTexture( plane_t *plane, brush_texture_t *bt, vec3_t origin ); +void TextureAxisFromPlane( plane_t *pln, vec3_t xv, vec3_t yv ); + +//============================================================================= +// csg +//============================================================================= + +bspbrush_t *MakeBspBrushList( int startbrush, int endbrush, vec3_t clipmins, vec3_t clipmaxs ); +bspbrush_t *ChopBrushes( bspbrush_t *head ); +bspbrush_t *InitialBrushList( bspbrush_t *list ); +bspbrush_t *OptimizedBrushList( bspbrush_t *list ); +void WriteBrushMap( char *name, bspbrush_t *list ); +void CheckBSPBrush( bspbrush_t *brush ); +void BSPBrushWindings( bspbrush_t *brush ); +bspbrush_t *TryMergeBrushes( bspbrush_t *brush1, bspbrush_t *brush2 ); +tree_t *ProcessWorldBrushes( int brush_start, int brush_end ); + +//============================================================================= +// brushbsp +//============================================================================= + +#define PSIDE_FRONT 1 +#define PSIDE_BACK 2 +#define PSIDE_BOTH ( PSIDE_FRONT | PSIDE_BACK ) +#define PSIDE_FACING 4 + +void WriteBrushList( char *name, bspbrush_t *brush, qboolean onlyvis ); +bspbrush_t *CopyBrush( bspbrush_t *brush ); +void SplitBrush( bspbrush_t *brush, int planenum, bspbrush_t **front, bspbrush_t **back ); +node_t *AllocNode( void ); +bspbrush_t *AllocBrush( int numsides ); +int CountBrushList( bspbrush_t *brushes ); +void FreeBrush( bspbrush_t *brushes ); +vec_t BrushVolume( bspbrush_t *brush ); +void BoundBrush( bspbrush_t *brush ); +void FreeBrushList( bspbrush_t *brushes ); +tree_t *BrushBSP( bspbrush_t *brushlist, vec3_t mins, vec3_t maxs ); + +bspbrush_t *BrushFromBounds( vec3_t mins, vec3_t maxs ); +int BrushMostlyOnSide( bspbrush_t *brush, plane_t *plane ); +qboolean WindingIsHuge( winding_t *w ); +qboolean WindingIsTiny( winding_t *w ); +void ResetBrushBSP( void ); + +//============================================================================= +// portals.c +//============================================================================= + +int VisibleContents( int contents ); +void MakeHeadnodePortals( tree_t *tree ); +void MakeNodePortal( node_t *node ); +void SplitNodePortals( node_t *node ); +qboolean Portal_VisFlood( portal_t *p ); +qboolean FloodEntities( tree_t *tree ); +void FillOutside( node_t *headnode ); +void FloodAreas( tree_t *tree ); +void MarkVisibleSides( tree_t *tree, int start, int end ); +void FreePortal( portal_t *p ); +void EmitAreaPortals( node_t *headnode ); +void MakeTreePortals( tree_t *tree ); + +//============================================================================= +// glfile.c +//============================================================================= + +void OutputWinding( winding_t *w, FILE *glview ); +void WriteGLView( tree_t *tree, char *source ); + +//============================================================================= +// gldraw.c +//============================================================================= + +extern vec3_t draw_mins, draw_maxs; +extern qboolean drawflag; + +void Draw_ClearWindow( void ); +void DrawWinding( winding_t *w ); +void GLS_BeginScene( void ); +void GLS_Winding( winding_t *w, int code ); +void GLS_EndScene( void ); + +//============================================================================= +// leakfile.c +//============================================================================= + +void LeakFile( tree_t *tree ); + +//============================================================================= +// tree.c +//============================================================================= + +tree_t *Tree_Alloc( void ); +void Tree_Free( tree_t *tree ); +void Tree_Free_r( node_t *node ); +void Tree_Print_r( node_t *node, int depth ); +void Tree_FreePortals_r( node_t *node ); +void Tree_PruneNodes_r( node_t *node ); +void Tree_PruneNodes( node_t *node ); + +//============================================================================= +// faces.c +//============================================================================= + +face_t *AllocFace( void ); +void FreeFace( face_t *f ); +void MakeFaces( node_t *headnode ); +void FixTjuncs( node_t *headnode ); +int GetEdge2( int v1, int v2, face_t *f ); +void MergeNodeFaces( node_t *node ); diff --git a/Projects/Android/jni/rtcw/src/bspc/qfiles.h b/Projects/Android/jni/rtcw/src/bspc/qfiles.h new file mode 100644 index 0000000..1a29769 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/bspc/qfiles.h @@ -0,0 +1,495 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +// +// qfiles.h: quake file formats +// This file must be identical in the quake and utils directories +// + +/* +======================================================================== + +The .pak files are just a linear collapse of a directory tree + +======================================================================== +*/ + +#define IDPAKHEADER ( ( 'K' << 24 ) + ( 'C' << 16 ) + ( 'A' << 8 ) + 'P' ) + +typedef struct +{ + char name[56]; + int filepos, filelen; +} dpackfile_t; + +typedef struct +{ + int ident; // == IDPAKHEADER + int dirofs; + int dirlen; +} dpackheader_t; + +#define MAX_FILES_IN_PACK 4096 + + +/* +======================================================================== + +PCX files are used for as many images as possible + +======================================================================== +*/ + +typedef struct +{ + char manufacturer; + char version; + char encoding; + char bits_per_pixel; + unsigned short xmin,ymin,xmax,ymax; + unsigned short hres,vres; + unsigned char palette[48]; + char reserved; + char color_planes; + unsigned short bytes_per_line; + unsigned short palette_type; + char filler[58]; + unsigned char data; // unbounded +} pcx_t; + + +/* +======================================================================== + +.MD2 triangle model file format + +======================================================================== +*/ + +#define IDALIASHEADER ( ( '2' << 24 ) + ( 'P' << 16 ) + ( 'D' << 8 ) + 'I' ) +#define ALIAS_VERSION 8 + +#define MAX_TRIANGLES 4096 +#define MAX_VERTS 2048 +#define MAX_FRAMES 512 +#define MAX_MD2SKINS 32 +#define MAX_SKINNAME 64 + +typedef struct +{ + short s; + short t; +} dstvert_t; + +typedef struct +{ + short index_xyz[3]; + short index_st[3]; +} dtriangle_t; + +typedef struct +{ + byte v[3]; // scaled byte to fit in frame mins/maxs + byte lightnormalindex; +} dtrivertx_t; + +#define DTRIVERTX_V0 0 +#define DTRIVERTX_V1 1 +#define DTRIVERTX_V2 2 +#define DTRIVERTX_LNI 3 +#define DTRIVERTX_SIZE 4 + +typedef struct +{ + float scale[3]; // multiply byte verts by this + float translate[3]; // then add this + char name[16]; // frame name from grabbing + dtrivertx_t verts[1]; // variable sized +} daliasframe_t; + + +// the glcmd format: +// a positive integer starts a tristrip command, followed by that many +// vertex structures. +// a negative integer starts a trifan command, followed by -x vertexes +// a zero indicates the end of the command list. +// a vertex consists of a floating point s, a floating point t, +// and an integer vertex index. + + +typedef struct +{ + int ident; + int version; + + int skinwidth; + int skinheight; + int framesize; // byte size of each frame + + int num_skins; + int num_xyz; + int num_st; // greater than num_xyz for seams + int num_tris; + int num_glcmds; // dwords in strip/fan command list + int num_frames; + + int ofs_skins; // each skin is a MAX_SKINNAME string + int ofs_st; // byte offset from start for stverts + int ofs_tris; // offset for dtriangles + int ofs_frames; // offset for first frame + int ofs_glcmds; + int ofs_end; // end of file + +} dmdl_t; + +/* +======================================================================== + +.SP2 sprite file format + +======================================================================== +*/ + +#define IDSPRITEHEADER ( ( '2' << 24 ) + ( 'S' << 16 ) + ( 'D' << 8 ) + 'I' ) +// little-endian "IDS2" +#define SPRITE_VERSION 2 + +typedef struct +{ + int width, height; + int origin_x, origin_y; // raster coordinates inside pic + char name[MAX_SKINNAME]; // name of pcx file +} dsprframe_t; + +typedef struct { + int ident; + int version; + int numframes; + dsprframe_t frames[1]; // variable sized +} dsprite_t; + +/* +============================================================================== + + .WAL texture file format + +============================================================================== +*/ + + +#define MIPLEVELS 4 +typedef struct miptex_s +{ + char name[32]; + unsigned width, height; + unsigned offsets[MIPLEVELS]; // four mip maps stored + char animname[32]; // next frame in animation chain + int flags; + int contents; + int value; +} miptex_t; + + + +/* +============================================================================== + + .BSP file format + +============================================================================== +*/ + +#define IDBSPHEADER ( ( 'P' << 24 ) + ( 'S' << 16 ) + ( 'B' << 8 ) + 'I' ) +// little-endian "IBSP" + +#define BSPVERSION 38 + + +// upper design bounds +// leaffaces, leafbrushes, planes, and verts are still bounded by +// 16 bit short limits +#define MAX_MAP_MODELS 1024 +#define MAX_MAP_BRUSHES 8192 +#define MAX_MAP_ENTITIES 2048 +#define MAX_MAP_ENTSTRING 0x40000 +#define MAX_MAP_TEXINFO 8192 + +#define MAX_MAP_AREAS 256 +#define MAX_MAP_AREAPORTALS 1024 +#define MAX_MAP_PLANES 65536 +#define MAX_MAP_NODES 65536 +#define MAX_MAP_BRUSHSIDES 65536 +#define MAX_MAP_LEAFS 65536 +#define MAX_MAP_VERTS 65536 +#define MAX_MAP_FACES 65536 +#define MAX_MAP_LEAFFACES 65536 +#define MAX_MAP_LEAFBRUSHES 65536 +#define MAX_MAP_PORTALS 65536 +#define MAX_MAP_EDGES 128000 +#define MAX_MAP_SURFEDGES 256000 +#define MAX_MAP_LIGHTING 0x320000 +#define MAX_MAP_VISIBILITY 0x280000 + +// key / value pair sizes + +#define MAX_KEY 32 +#define MAX_VALUE 1024 + +//============================================================================= + +typedef struct +{ + int fileofs, filelen; +} lump_t; + +#define LUMP_ENTITIES 0 +#define LUMP_PLANES 1 +#define LUMP_VERTEXES 2 +#define LUMP_VISIBILITY 3 +#define LUMP_NODES 4 +#define LUMP_TEXINFO 5 +#define LUMP_FACES 6 +#define LUMP_LIGHTING 7 +#define LUMP_LEAFS 8 +#define LUMP_LEAFFACES 9 +#define LUMP_LEAFBRUSHES 10 +#define LUMP_EDGES 11 +#define LUMP_SURFEDGES 12 +#define LUMP_MODELS 13 +#define LUMP_BRUSHES 14 +#define LUMP_BRUSHSIDES 15 +#define LUMP_POP 16 +#define LUMP_AREAS 17 +#define LUMP_AREAPORTALS 18 +#define HEADER_LUMPS 19 + +typedef struct +{ + int ident; + int version; + lump_t lumps[HEADER_LUMPS]; +} dheader_t; + +typedef struct +{ + float mins[3], maxs[3]; + float origin[3]; // for sounds or lights + int headnode; + int firstface, numfaces; // submodels just draw faces + // without walking the bsp tree +} dmodel_t; + + +typedef struct +{ + float point[3]; +} dvertex_t; + + +// 0-2 are axial planes +#define PLANE_X 0 +#define PLANE_Y 1 +#define PLANE_Z 2 + +// 3-5 are non-axial planes snapped to the nearest +#define PLANE_ANYX 3 +#define PLANE_ANYY 4 +#define PLANE_ANYZ 5 + +// planes (x&~1) and (x&~1)+1 are allways opposites + +typedef struct +{ + float normal[3]; + float dist; + int type; // PLANE_X - PLANE_ANYZ ?remove? trivial to regenerate +} dplane_t; + + +// contents flags are seperate bits +// a given brush can contribute multiple content bits +// multiple brushes can be in a single leaf + +// these definitions also need to be in q_shared.h! + +// lower bits are stronger, and will eat weaker brushes completely +#define CONTENTS_SOLID 1 // an eye is never valid in a solid +#define CONTENTS_WINDOW 2 // translucent, but not watery +#define CONTENTS_AUX 4 +#define CONTENTS_LAVA 8 +#define CONTENTS_SLIME 16 +#define CONTENTS_WATER 32 +#define CONTENTS_MIST 64 +#define LAST_VISIBLE_CONTENTS 64 + +// remaining contents are non-visible, and don't eat brushes + +#define CONTENTS_AREAPORTAL 0x8000 + +#define CONTENTS_PLAYERCLIP 0x10000 +#define CONTENTS_MONSTERCLIP 0x20000 + +// currents can be added to any other contents, and may be mixed +#define CONTENTS_CURRENT_0 0x40000 +#define CONTENTS_CURRENT_90 0x80000 +#define CONTENTS_CURRENT_180 0x100000 +#define CONTENTS_CURRENT_270 0x200000 +#define CONTENTS_CURRENT_UP 0x400000 +#define CONTENTS_CURRENT_DOWN 0x800000 + +#define CONTENTS_ORIGIN 0x1000000 // removed before bsping an entity + +#define CONTENTS_MONSTER 0x2000000 // should never be on a brush, only in game +#define CONTENTS_DEADMONSTER 0x4000000 +#define CONTENTS_DETAIL 0x8000000 // brushes to be added after vis leafs +//renamed because it's in conflict with the Q3A translucent contents +#define CONTENTS_Q2TRANSLUCENT 0x10000000 // auto set if any surface has trans +#define CONTENTS_LADDER 0x20000000 + + + +#define SURF_LIGHT 0x1 // value will hold the light strength + +#define SURF_SLICK 0x2 // effects game physics + +#define SURF_SKY 0x4 // don't draw, but add to skybox +#define SURF_WARP 0x8 // turbulent water warp +#define SURF_TRANS33 0x10 +#define SURF_TRANS66 0x20 +#define SURF_FLOWING 0x40 // scroll towards angle +#define SURF_NODRAW 0x80 // don't bother referencing the texture + +#define SURF_HINT 0x100 // make a primary bsp splitter +#define SURF_SKIP 0x200 // completely ignore, allowing non-closed brushes + +#define SURF_MONSTERSLICK 0x4000000 // slick surf that only affects ai's + + +typedef struct +{ + int planenum; + int children[2]; // negative numbers are -(leafs+1), not nodes + short mins[3]; // for frustom culling + short maxs[3]; + unsigned short firstface; + unsigned short numfaces; // counting both sides +} dnode_t; + + +typedef struct texinfo_s +{ + float vecs[2][4]; // [s/t][xyz offset] + int flags; // miptex flags + overrides + int value; // light emission, etc + char texture[32]; // texture name (textures/*.wal) + int nexttexinfo; // for animations, -1 = end of chain +} texinfo_t; + + +// note that edge 0 is never used, because negative edge nums are used for +// counterclockwise use of the edge in a face +typedef struct +{ + unsigned short v[2]; // vertex numbers +} dedge_t; + +#define MAXLIGHTMAPS 4 +typedef struct +{ + unsigned short planenum; + short side; + + int firstedge; // we must support > 64k edges + short numedges; + short texinfo; + +// lighting info + byte styles[MAXLIGHTMAPS]; + int lightofs; // start of [numstyles*surfsize] samples +} dface_t; + +typedef struct +{ + int contents; // OR of all brushes (not needed?) + + short cluster; + short area; + + short mins[3]; // for frustum culling + short maxs[3]; + + unsigned short firstleafface; + unsigned short numleaffaces; + + unsigned short firstleafbrush; + unsigned short numleafbrushes; +} dleaf_t; + +typedef struct +{ + unsigned short planenum; // facing out of the leaf + short texinfo; +} dbrushside_t; + +typedef struct +{ + int firstside; + int numsides; + int contents; +} dbrush_t; + +#define ANGLE_UP -1 +#define ANGLE_DOWN -2 + + +// the visibility lump consists of a header with a count, then +// byte offsets for the PVS and PHS of each cluster, then the raw +// compressed bit vectors +#define DVIS_PVS 0 +#define DVIS_PHS 1 +typedef struct +{ + int numclusters; + int bitofs[8][2]; // bitofs[numclusters][2] +} dvis_t; + +// each area has a list of portals that lead into other areas +// when portals are closed, other areas may not be visible or +// hearable even if the vis info says that it should be +typedef struct +{ + int portalnum; + int otherarea; +} dareaportal_t; + +typedef struct +{ + int numareaportals; + int firstareaportal; +} darea_t; diff --git a/Projects/Android/jni/rtcw/src/bspc/sinfiles.h b/Projects/Android/jni/rtcw/src/bspc/sinfiles.h new file mode 100644 index 0000000..ea5f79a --- /dev/null +++ b/Projects/Android/jni/rtcw/src/bspc/sinfiles.h @@ -0,0 +1,372 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +/* +============================================================================== + + .BSP file format + +============================================================================== +*/ + +#define SIN + +#define SINBSPVERSION 41 + +// upper design bounds +// leaffaces, leafbrushes, planes, and verts are still bounded by +// 16 bit short limits +#define SIN_MAX_MAP_MODELS 1024 +#define SIN_MAX_MAP_BRUSHES 8192 +#define SIN_MAX_MAP_ENTITIES 2048 +#define SIN_MAX_MAP_ENTSTRING 0x40000 +#define SIN_MAX_MAP_TEXINFO 8192 + +#define SIN_MAX_MAP_AREAS 256 +#define SIN_MAX_MAP_AREAPORTALS 1024 +#define SIN_MAX_MAP_PLANES 65536 +#define SIN_MAX_MAP_NODES 65536 +#define SIN_MAX_MAP_BRUSHSIDES 65536 +#define SIN_MAX_MAP_LEAFS 65536 +#define SIN_MAX_MAP_VERTS 65536 +#define SIN_MAX_MAP_FACES 65536 +#define SIN_MAX_MAP_LEAFFACES 65536 +#define SIN_MAX_MAP_LEAFBRUSHES 65536 +#define SIN_MAX_MAP_PORTALS 65536 +#define SIN_MAX_MAP_EDGES 128000 +#define SIN_MAX_MAP_SURFEDGES 256000 +#define SIN_MAX_MAP_LIGHTING 0x320000 +#define SIN_MAX_MAP_VISIBILITY 0x280000 + +#ifdef SIN +#define SIN_MAX_MAP_LIGHTINFO 8192 +#endif + +#ifdef SIN +#undef SIN_MAX_MAP_LIGHTING //undef the Quake2 bsp version +#define SIN_MAX_MAP_LIGHTING 0x300000 +#endif + +#ifdef SIN +#undef SIN_MAX_MAP_VISIBILITY //undef the Quake2 bsp version +#define SIN_MAX_MAP_VISIBILITY 0x280000 +#endif + +//============================================================================= + +typedef struct +{ + int fileofs, filelen; +} sin_lump_t; + +#define SIN_LUMP_ENTITIES 0 +#define SIN_LUMP_PLANES 1 +#define SIN_LUMP_VERTEXES 2 +#define SIN_LUMP_VISIBILITY 3 +#define SIN_LUMP_NODES 4 +#define SIN_LUMP_TEXINFO 5 +#define SIN_LUMP_FACES 6 +#define SIN_LUMP_LIGHTING 7 +#define SIN_LUMP_LEAFS 8 +#define SIN_LUMP_LEAFFACES 9 +#define SIN_LUMP_LEAFBRUSHES 10 +#define SIN_LUMP_EDGES 11 +#define SIN_LUMP_SURFEDGES 12 +#define SIN_LUMP_MODELS 13 +#define SIN_LUMP_BRUSHES 14 +#define SIN_LUMP_BRUSHSIDES 15 +#define SIN_LUMP_POP 16 +#define SIN_LUMP_AREAS 17 +#define SIN_LUMP_AREAPORTALS 18 + +#ifdef SIN +#define SIN_LUMP_LIGHTINFO 19 +#define SINHEADER_LUMPS 20 +#endif + +typedef struct +{ + int ident; + int version; + sin_lump_t lumps[SINHEADER_LUMPS]; +} sin_dheader_t; + +typedef struct +{ + float mins[3], maxs[3]; + float origin[3]; // for sounds or lights + int headnode; + int firstface, numfaces; // submodels just draw faces + // without walking the bsp tree +} sin_dmodel_t; + +typedef struct +{ + float point[3]; +} sin_dvertex_t; + + +// 0-2 are axial planes +#define PLANE_X 0 +#define PLANE_Y 1 +#define PLANE_Z 2 + +// 3-5 are non-axial planes snapped to the nearest +#define PLANE_ANYX 3 +#define PLANE_ANYY 4 +#define PLANE_ANYZ 5 + +// planes (x&~1) and (x&~1)+1 are allways opposites + +typedef struct +{ + float normal[3]; + float dist; + int type; // PLANE_X - PLANE_ANYZ ?remove? trivial to regenerate +} sin_dplane_t; + + +// contents flags are seperate bits +// a given brush can contribute multiple content bits +// multiple brushes can be in a single leaf + +// these definitions also need to be in q_shared.h! + +// lower bits are stronger, and will eat weaker brushes completely +#ifdef SIN +#define CONTENTS_FENCE 4 +#endif +// remaining contents are non-visible, and don't eat brushes + +#ifdef SIN +#define CONTENTS_DUMMYFENCE 0x1000 +#endif + +#ifdef SIN +#define SURF_MASKED 0x2 // surface texture is masked +#endif + +#define SURF_SKY 0x4 // don't draw, but add to skybox +#define SURF_WARP 0x8 // turbulent water warp + +#ifdef SIN +#define SURF_NONLIT 0x10 // surface is not lit +#define SURF_NOFILTER 0x20 // surface is not bi-linear filtered +#endif + +#define SURF_FLOWING 0x40 // scroll towards angle +#define SURF_NODRAW 0x80 // don't bother referencing the texture + +#define SURF_HINT 0x100 // make a primary bsp splitter +#define SURF_SKIP 0x200 // completely ignore, allowing non-closed brushes + +#ifdef SIN +#define SURF_CONVEYOR 0x40 // surface is not lit +#endif + +#ifdef SIN +#define SURF_WAVY 0x400 // surface has waves +#define SURF_RICOCHET 0x800 // projectiles bounce literally bounce off this surface +#define SURF_PRELIT 0x1000 // surface has intensity information for pre-lighting +#define SURF_MIRROR 0x2000 // surface is a mirror +#define SURF_CONSOLE 0x4000 // surface is a console +#define SURF_USECOLOR 0x8000 // surface is lit with non-lit * color +#define SURF_HARDWAREONLY 0x10000 // surface has been damaged +#define SURF_DAMAGE 0x20000 // surface can be damaged +#define SURF_WEAK 0x40000 // surface has weak hit points +#define SURF_NORMAL 0x80000 // surface has normal hit points +#define SURF_ADD 0x100000 // surface will be additive +#define SURF_ENVMAPPED 0x200000 // surface is envmapped +#define SURF_RANDOMANIMATE 0x400000 // surface start animating on a random frame +#define SURF_ANIMATE 0x800000 // surface animates +#define SURF_RNDTIME 0x1000000 // time between animations is random +#define SURF_TRANSLATE 0x2000000 // surface translates +#define SURF_NOMERGE 0x4000000 // surface is not merged in csg phase +#define SURF_TYPE_BIT0 0x8000000 // 0 bit of surface type +#define SURF_TYPE_BIT1 0x10000000 // 1 bit of surface type +#define SURF_TYPE_BIT2 0x20000000 // 2 bit of surface type +#define SURF_TYPE_BIT3 0x40000000 // 3 bit of surface type + +#define SURF_START_BIT 27 +#define SURFACETYPE_FROM_FLAGS( x ) ( ( x >> ( SURF_START_BIT ) ) & 0xf ) + + +#define SURF_TYPE_SHIFT( x ) ( ( x ) << ( SURF_START_BIT ) ) // macro for getting proper bit mask + +#define SURF_TYPE_NONE SURF_TYPE_SHIFT( 0 ) +#define SURF_TYPE_WOOD SURF_TYPE_SHIFT( 1 ) +#define SURF_TYPE_METAL SURF_TYPE_SHIFT( 2 ) +#define SURF_TYPE_STONE SURF_TYPE_SHIFT( 3 ) +#define SURF_TYPE_CONCRETE SURF_TYPE_SHIFT( 4 ) +#define SURF_TYPE_DIRT SURF_TYPE_SHIFT( 5 ) +#define SURF_TYPE_FLESH SURF_TYPE_SHIFT( 6 ) +#define SURF_TYPE_GRILL SURF_TYPE_SHIFT( 7 ) +#define SURF_TYPE_GLASS SURF_TYPE_SHIFT( 8 ) +#define SURF_TYPE_FABRIC SURF_TYPE_SHIFT( 9 ) +#define SURF_TYPE_MONITOR SURF_TYPE_SHIFT( 10 ) +#define SURF_TYPE_GRAVEL SURF_TYPE_SHIFT( 11 ) +#define SURF_TYPE_VEGETATION SURF_TYPE_SHIFT( 12 ) +#define SURF_TYPE_PAPER SURF_TYPE_SHIFT( 13 ) +#define SURF_TYPE_DUCT SURF_TYPE_SHIFT( 14 ) +#define SURF_TYPE_WATER SURF_TYPE_SHIFT( 15 ) +#endif + + +typedef struct +{ + int planenum; + int children[2]; // negative numbers are -(leafs+1), not nodes + short mins[3]; // for frustom culling + short maxs[3]; + unsigned short firstface; + unsigned short numfaces; // counting both sides +} sin_dnode_t; + +#ifdef SIN + +typedef struct sin_lightvalue_s +{ + int value; // light emission, etc + vec3_t color; + float direct; + float directangle; + float directstyle; + char directstylename[32]; +} sin_lightvalue_t; + +typedef struct sin_texinfo_s +{ + float vecs[2][4]; // [s/t][xyz offset] + int flags; // miptex flags + overrides + char texture[64]; // texture name (textures/*.wal) + int nexttexinfo; // for animations, -1 = end of chain + float trans_mag; + int trans_angle; + int base_angle; + float animtime; + float nonlit; + float translucence; + float friction; + float restitution; + vec3_t color; + char groupname[32]; +} sin_texinfo_t; + +#endif //SIN + +// note that edge 0 is never used, because negative edge nums are used for +// counterclockwise use of the edge in a face +typedef struct +{ + unsigned short v[2]; // vertex numbers +} sin_dedge_t; + +#ifdef MAXLIGHTMAPS +#undef MAXLIGHTMAPS +#endif +#define MAXLIGHTMAPS 16 +typedef struct +{ + unsigned short planenum; + short side; + + int firstedge; // we must support > 64k edges + short numedges; + short texinfo; + +// lighting info + byte styles[MAXLIGHTMAPS]; + int lightofs; // start of [numstyles*surfsize] samples +#ifdef SIN + int lightinfo; +#endif +} sin_dface_t; + +typedef struct +{ + int contents; // OR of all brushes (not needed?) + + short cluster; + short area; + + short mins[3]; // for frustum culling + short maxs[3]; + + unsigned short firstleafface; + unsigned short numleaffaces; + + unsigned short firstleafbrush; + unsigned short numleafbrushes; +} sin_dleaf_t; + +typedef struct +{ + unsigned short planenum; // facing out of the leaf + short texinfo; +#ifdef SIN + int lightinfo; +#endif +} sin_dbrushside_t; + +typedef struct +{ + int firstside; + int numsides; + int contents; +} sin_dbrush_t; + +#define ANGLE_UP -1 +#define ANGLE_DOWN -2 + + +// the visibility lump consists of a header with a count, then +// byte offsets for the PVS and PHS of each cluster, then the raw +// compressed bit vectors +#define DVIS_PVS 0 +#define DVIS_PHS 1 +typedef struct +{ + int numclusters; + int bitofs[8][2]; // bitofs[numclusters][2] +} sin_dvis_t; + +// each area has a list of portals that lead into other areas +// when portals are closed, other areas may not be visible or +// hearable even if the vis info says that it should be +typedef struct +{ + int portalnum; + int otherarea; +} sin_dareaportal_t; + +typedef struct +{ + int numareaportals; + int firstareaportal; +} sin_darea_t; diff --git a/Projects/Android/jni/rtcw/src/bspc/textures.c b/Projects/Android/jni/rtcw/src/bspc/textures.c new file mode 100644 index 0000000..9822b86 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/bspc/textures.c @@ -0,0 +1,249 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +//=========================================================================== +// +// Name: textures.c +// Function: textures +// Programmer: Mr Elusive (MrElusive@worldentity.com) +// Last update: 1999-08-10 +// Tab Size: 3 +//=========================================================================== + +#include "qbsp.h" +#include "l_bsp_q2.h" + + +int nummiptex; +textureref_t textureref[MAX_MAP_TEXTURES]; + +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int FindMiptex( char *name ) { + int i; + char path[1024]; + miptex_t *mt; + + for ( i = 0; i < nummiptex; i++ ) + { + if ( !strcmp( name, textureref[i].name ) ) { + return i; + } //end if + } //end for + if ( nummiptex == MAX_MAP_TEXTURES ) { + Error( "MAX_MAP_TEXTURES" ); + } + strcpy( textureref[i].name, name ); + + // load the miptex to get the flags and values + sprintf( path, "%stextures/%s.wal", gamedir, name ); + if ( TryLoadFile( path, (void **)&mt ) != -1 ) { + textureref[i].value = LittleLong( mt->value ); + textureref[i].flags = LittleLong( mt->flags ); + textureref[i].contents = LittleLong( mt->contents ); + strcpy( textureref[i].animname, mt->animname ); + FreeMemory( mt ); + } //end if + nummiptex++; + + if ( textureref[i].animname[0] ) { + FindMiptex( textureref[i].animname ); + } + + return i; +} //end of the function FindMipTex +//=========================================================================== +//textureAxisFromPlane +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +vec3_t baseaxis[18] = +{ + {0,0,1}, {1,0,0}, {0,-1,0}, // floor + {0,0,-1}, {1,0,0}, {0,-1,0}, // ceiling + {1,0,0}, {0,1,0}, {0,0,-1}, // west wall + {-1,0,0}, {0,1,0}, {0,0,-1}, // east wall + {0,1,0}, {1,0,0}, {0,0,-1}, // south wall + {0,-1,0}, {1,0,0}, {0,0,-1} // north wall +}; + +void TextureAxisFromPlane( plane_t *pln, vec3_t xv, vec3_t yv ) { + int bestaxis; + vec_t dot,best; + int i; + + best = 0; + bestaxis = 0; + + for ( i = 0 ; i < 6 ; i++ ) + { + dot = DotProduct( pln->normal, baseaxis[i * 3] ); + if ( dot > best ) { + best = dot; + bestaxis = i; + } + } + + VectorCopy( baseaxis[bestaxis * 3 + 1], xv ); + VectorCopy( baseaxis[bestaxis * 3 + 2], yv ); +} //end of the function TextureAxisFromPlane +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int TexinfoForBrushTexture( plane_t *plane, brush_texture_t *bt, vec3_t origin ) { + vec3_t vecs[2]; + int sv, tv; + vec_t ang, sinv, cosv; + vec_t ns, nt; + texinfo_t tx, *tc; + int i, j, k; + float shift[2]; + brush_texture_t anim; + int mt; + + if ( !bt->name[0] ) { + return 0; + } + + memset( &tx, 0, sizeof( tx ) ); + strcpy( tx.texture, bt->name ); + + TextureAxisFromPlane( plane, vecs[0], vecs[1] ); + + shift[0] = DotProduct( origin, vecs[0] ); + shift[1] = DotProduct( origin, vecs[1] ); + + if ( !bt->scale[0] ) { + bt->scale[0] = 1; + } + if ( !bt->scale[1] ) { + bt->scale[1] = 1; + } + + +// rotate axis + if ( bt->rotate == 0 ) { + sinv = 0 ; cosv = 1; + } else if ( bt->rotate == 90 ) { + sinv = 1 ; cosv = 0; + } else if ( bt->rotate == 180 ) { + sinv = 0 ; cosv = -1; + } else if ( bt->rotate == 270 ) { + sinv = -1 ; cosv = 0; + } else + { + ang = bt->rotate / 180 * Q_PI; + sinv = sin( ang ); + cosv = cos( ang ); + } + + if ( vecs[0][0] ) { + sv = 0; + } else if ( vecs[0][1] ) { + sv = 1; + } else { + sv = 2; + } + + if ( vecs[1][0] ) { + tv = 0; + } else if ( vecs[1][1] ) { + tv = 1; + } else { + tv = 2; + } + + for ( i = 0 ; i < 2 ; i++ ) + { + ns = cosv * vecs[i][sv] - sinv * vecs[i][tv]; + nt = sinv * vecs[i][sv] + cosv * vecs[i][tv]; + vecs[i][sv] = ns; + vecs[i][tv] = nt; + } + + for ( i = 0 ; i < 2 ; i++ ) + for ( j = 0 ; j < 3 ; j++ ) + tx.vecs[i][j] = vecs[i][j] / bt->scale[i]; + + tx.vecs[0][3] = bt->shift[0] + shift[0]; + tx.vecs[1][3] = bt->shift[1] + shift[1]; + tx.flags = bt->flags; + tx.value = bt->value; + + // + // find the texinfo + // + tc = texinfo; + for ( i = 0 ; i < numtexinfo ; i++, tc++ ) + { + if ( tc->flags != tx.flags ) { + continue; + } + if ( tc->value != tx.value ) { + continue; + } + for ( j = 0 ; j < 2 ; j++ ) + { + if ( strcmp( tc->texture, tx.texture ) ) { + goto skip; + } + for ( k = 0 ; k < 4 ; k++ ) + { + if ( tc->vecs[j][k] != tx.vecs[j][k] ) { + goto skip; + } + } + } + return i; +skip:; + } + *tc = tx; + numtexinfo++; + + // load the next animation + mt = FindMiptex( bt->name ); + if ( textureref[mt].animname[0] ) { + anim = *bt; + strcpy( anim.name, textureref[mt].animname ); + tc->nexttexinfo = TexinfoForBrushTexture( plane, &anim, origin ); + } else { + tc->nexttexinfo = -1; + } + + + return i; +} //end of the function TexinfoForBrushTexture diff --git a/Projects/Android/jni/rtcw/src/bspc/tree.c b/Projects/Android/jni/rtcw/src/bspc/tree.c new file mode 100644 index 0000000..706ce24 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/bspc/tree.c @@ -0,0 +1,298 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +//=========================================================================== +// +// Name: textures.c +// Function: textures +// Programmer: Mr Elusive (MrElusive@worldentity.com) +// Last update: 1999-08-10 +// Tab Size: 3 +//=========================================================================== + +#include "qbsp.h" + +extern int c_nodes; +int c_pruned; +int freedtreemem = 0; + +void RemovePortalFromNode( portal_t *portal, node_t *l ); + +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +node_t *NodeForPoint( node_t *node, vec3_t origin ) { + plane_t *plane; + vec_t d; + + while ( node->planenum != PLANENUM_LEAF ) + { + plane = &mapplanes[node->planenum]; + d = DotProduct( origin, plane->normal ) - plane->dist; + if ( d >= 0 ) { + node = node->children[0]; + } else { + node = node->children[1]; + } + } + return node; +} //end of the function NodeForPoint +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void Tree_FreePortals_r( node_t *node ) { + portal_t *p, *nextp; + int s; + + // free children + if ( node->planenum != PLANENUM_LEAF ) { + Tree_FreePortals_r( node->children[0] ); + Tree_FreePortals_r( node->children[1] ); + } + + // free portals + for ( p = node->portals; p; p = nextp ) + { + s = ( p->nodes[1] == node ); + nextp = p->next[s]; + + RemovePortalFromNode( p, p->nodes[!s] ); +#ifdef ME + if ( p->winding ) { + freedtreemem += MemorySize( p->winding ); + } + freedtreemem += MemorySize( p ); +#endif //ME + FreePortal( p ); + } + node->portals = NULL; +} //end of the function Tree_FreePortals_r +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void Tree_Free_r( node_t *node ) { +// face_t *f, *nextf; + bspbrush_t *brush, *nextbrush; + + //free children + if ( node->planenum != PLANENUM_LEAF ) { + Tree_Free_r( node->children[0] ); + Tree_Free_r( node->children[1] ); + } //end if + //free bspbrushes +// FreeBrushList (node->brushlist); + for ( brush = node->brushlist; brush; brush = nextbrush ) + { + nextbrush = brush->next; +#ifdef ME + freedtreemem += MemorySize( brush ); +#endif //ME + FreeBrush( brush ); + } //end for + node->brushlist = NULL; + + /* + NOTE: only used when creating Q2 bsp + // free faces + for (f = node->faces; f; f = nextf) + { + nextf = f->next; +#ifdef ME + if (f->w) freedtreemem += MemorySize(f->w); + freedtreemem += sizeof(face_t); +#endif //ME + FreeFace(f); + } //end for + */ + + // free the node + if ( node->volume ) { +#ifdef ME + freedtreemem += MemorySize( node->volume ); +#endif //ME + FreeBrush( node->volume ); + } //end if + + if ( numthreads == 1 ) { + c_nodes--; + } +#ifdef ME + freedtreemem += MemorySize( node ); +#endif //ME + FreeMemory( node ); +} //end of the function Tree_Free_r +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void Tree_Free( tree_t *tree ) { + //if no tree just return + if ( !tree ) { + return; + } + // + freedtreemem = 0; + // + Tree_FreePortals_r( tree->headnode ); + Tree_Free_r( tree->headnode ); +#ifdef ME + freedtreemem += MemorySize( tree ); +#endif //ME + FreeMemory( tree ); +#ifdef ME + Log_Print( "freed " ); + PrintMemorySize( freedtreemem ); + Log_Print( " of tree memory\n" ); +#endif //ME +} //end of the function Tree_Free +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +tree_t *Tree_Alloc( void ) { + tree_t *tree; + + tree = GetMemory( sizeof( *tree ) ); + memset( tree, 0, sizeof( *tree ) ); + ClearBounds( tree->mins, tree->maxs ); + + return tree; +} //end of the function Tree_Alloc +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void Tree_Print_r( node_t *node, int depth ) { + int i; + plane_t *plane; + bspbrush_t *bb; + + for ( i = 0 ; i < depth ; i++ ) + printf( " " ); + if ( node->planenum == PLANENUM_LEAF ) { + if ( !node->brushlist ) { + printf( "NULL\n" ); + } else + { + for ( bb = node->brushlist ; bb ; bb = bb->next ) + printf( "%i ", bb->original->brushnum ); + printf( "\n" ); + } + return; + } + + plane = &mapplanes[node->planenum]; + printf( "#%i (%5.2f %5.2f %5.2f):%5.2f\n", node->planenum, + plane->normal[0], plane->normal[1], plane->normal[2], + plane->dist ); + Tree_Print_r( node->children[0], depth + 1 ); + Tree_Print_r( node->children[1], depth + 1 ); +} //end of the function Tree_Print_r +//=========================================================================== +// NODES THAT DON'T SEPERATE DIFFERENT CONTENTS CAN BE PRUNED +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void Tree_PruneNodes_r( node_t *node ) { + bspbrush_t *b, *next; + + if ( node->planenum == PLANENUM_LEAF ) { + return; + } + + Tree_PruneNodes_r( node->children[0] ); + Tree_PruneNodes_r( node->children[1] ); + + if ( create_aas ) { + if ( ( node->children[0]->contents & CONTENTS_LADDER ) || + ( node->children[1]->contents & CONTENTS_LADDER ) ) { + return; + } + } + + if ( ( node->children[0]->contents & CONTENTS_SOLID ) + && ( node->children[1]->contents & CONTENTS_SOLID ) ) { + if ( node->faces ) { + Error( "node->faces seperating CONTENTS_SOLID" ); + } + if ( node->children[0]->faces || node->children[1]->faces ) { + Error( "!node->faces with children" ); + } + // FIXME: free stuff + node->planenum = PLANENUM_LEAF; + node->contents = CONTENTS_SOLID; + node->detail_seperator = false; + + if ( node->brushlist ) { + Error( "PruneNodes: node->brushlist" ); + } + // combine brush lists + node->brushlist = node->children[1]->brushlist; + + for ( b = node->children[0]->brushlist; b; b = next ) + { + next = b->next; + b->next = node->brushlist; + node->brushlist = b; + } //end for + //free the child nodes + FreeMemory( node->children[0] ); + FreeMemory( node->children[1] ); + //two nodes are cut away + c_pruned += 2; + } //end if +} //end of the function Tree_PruneNodes_r +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void Tree_PruneNodes( node_t *node ) { + Log_Print( "------- Prune Nodes --------\n" ); + c_pruned = 0; + Tree_PruneNodes_r( node ); + Log_Print( "%5i pruned nodes\n", c_pruned ); +} //end of the function Tree_PruneNodes diff --git a/Projects/Android/jni/rtcw/src/bspc/writebsp.c b/Projects/Android/jni/rtcw/src/bspc/writebsp.c new file mode 100644 index 0000000..10bb718 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/bspc/writebsp.c @@ -0,0 +1,632 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +// NO LONGER IN PROJECT +#if 0 +#include "qbsp.h" + +int c_nofaces; +int c_facenodes; + + +extern int numplanes; +extern int numfaces; +extern int numleaffaces; +extern int numleafs; +extern int numleafbrushes; +extern int numsurfedges; +extern int numnodes; + +extern int nummodels; +extern int numbrushsides; +extern int numbrushes; +extern int numvertexes; +extern int numedges; + +extern dplane_t dplanes[MAX_MAP_PLANES]; +extern dleaf_t dleafs[MAX_MAP_LEAFS]; +extern dleaf_t dleafs[MAX_MAP_LEAFS]; +extern dface_t dfaces[MAX_MAP_FACES]; +extern unsigned short dleafbrushes[MAX_MAP_LEAFBRUSHES]; +extern unsigned short dleaffaces[MAX_MAP_LEAFFACES]; +extern int dsurfedges[MAX_MAP_SURFEDGES]; +extern dnode_t dnodes[MAX_MAP_NODES]; +extern dmodel_t dmodels[MAX_MAP_MODELS]; +extern dbrush_t dbrushes[MAX_MAP_BRUSHES]; +extern dbrushside_t dbrushsides[MAX_MAP_BRUSHSIDES]; + +/* +========================================================= + +ONLY SAVE OUT PLANES THAT ARE ACTUALLY USED AS NODES + +========================================================= +*/ + +int planeused[MAX_MAP_PLANES]; + +/* +============ +EmitPlanes + +There is no oportunity to discard planes, because all of the original +brushes will be saved in the map. +============ +*/ +void EmitPlanes( void ) { + int i; + dplane_t *dp; + plane_t *mp; + //ME: this causes a crash?? +// int planetranslate[MAX_MAP_PLANES]; + + mp = mapplanes; + for ( i = 0 ; i < nummapplanes ; i++, mp++ ) + { + dp = &dplanes[numplanes]; +// planetranslate[i] = numplanes; + VectorCopy( mp->normal, dp->normal ); + dp->dist = mp->dist; + dp->type = mp->type; + numplanes++; + if ( numplanes >= MAX_MAP_PLANES ) { + Error( "MAX_MAP_PLANES" ); + } + } +} + + +//======================================================== + +void EmitMarkFace( dleaf_t *leaf_p, face_t *f ) { + int i; + int facenum; + + while ( f->merged ) + f = f->merged; + + if ( f->split[0] ) { + EmitMarkFace( leaf_p, f->split[0] ); + EmitMarkFace( leaf_p, f->split[1] ); + return; + } + + facenum = f->outputnumber; + if ( facenum == -1 ) { + return; // degenerate face + + } + if ( facenum < 0 || facenum >= numfaces ) { + Error( "Bad leafface" ); + } + for ( i = leaf_p->firstleafface ; i < numleaffaces ; i++ ) + if ( dleaffaces[i] == facenum ) { + break; + } // merged out face + if ( i == numleaffaces ) { + if ( numleaffaces >= MAX_MAP_LEAFFACES ) { + Error( "MAX_MAP_LEAFFACES" ); + } + + dleaffaces[numleaffaces] = facenum; + numleaffaces++; + } + +} + + +/* +================== +EmitLeaf +================== +*/ +void EmitLeaf( node_t *node ) { + dleaf_t *leaf_p; + portal_t *p; + int s; + face_t *f; + bspbrush_t *b; + int i; + int brushnum; + + // emit a leaf + if ( numleafs >= MAX_MAP_LEAFS ) { + Error( "MAX_MAP_LEAFS" ); + } + + leaf_p = &dleafs[numleafs]; + numleafs++; + + leaf_p->contents = node->contents; + leaf_p->cluster = node->cluster; + leaf_p->area = node->area; + + // + // write bounding box info + // + VectorCopy( node->mins, leaf_p->mins ); + VectorCopy( node->maxs, leaf_p->maxs ); + + // + // write the leafbrushes + // + leaf_p->firstleafbrush = numleafbrushes; + for ( b = node->brushlist ; b ; b = b->next ) + { + if ( numleafbrushes >= MAX_MAP_LEAFBRUSHES ) { + Error( "MAX_MAP_LEAFBRUSHES" ); + } + + brushnum = b->original - mapbrushes; + for ( i = leaf_p->firstleafbrush ; i < numleafbrushes ; i++ ) + if ( dleafbrushes[i] == brushnum ) { + break; + } + if ( i == numleafbrushes ) { + dleafbrushes[numleafbrushes] = brushnum; + numleafbrushes++; + } + } + leaf_p->numleafbrushes = numleafbrushes - leaf_p->firstleafbrush; + + // + // write the leaffaces + // + if ( leaf_p->contents & CONTENTS_SOLID ) { + return; // no leaffaces in solids + + } + leaf_p->firstleafface = numleaffaces; + + for ( p = node->portals ; p ; p = p->next[s] ) + { + s = ( p->nodes[1] == node ); + f = p->face[s]; + if ( !f ) { + continue; // not a visible portal + + } + EmitMarkFace( leaf_p, f ); + } + + leaf_p->numleaffaces = numleaffaces - leaf_p->firstleafface; +} + + +/* +================== +EmitFace +================== +*/ +void EmitFace( face_t *f ) { + dface_t *df; + int i; + int e; + + f->outputnumber = -1; + + if ( f->numpoints < 3 ) { + return; // degenerated + } + if ( f->merged || f->split[0] || f->split[1] ) { + return; // not a final face + } + + // save output number so leaffaces can use + f->outputnumber = numfaces; + + if ( numfaces >= MAX_MAP_FACES ) { + Error( "numfaces == MAX_MAP_FACES" ); + } + df = &dfaces[numfaces]; + numfaces++; + + // planenum is used by qlight, but not quake + df->planenum = f->planenum & ( ~1 ); + df->side = f->planenum & 1; + + df->firstedge = numsurfedges; + df->numedges = f->numpoints; + df->texinfo = f->texinfo; + for ( i = 0 ; i < f->numpoints ; i++ ) + { +// e = GetEdge (f->pts[i], f->pts[(i+1)%f->numpoints], f); + e = GetEdge2( f->vertexnums[i], f->vertexnums[( i + 1 ) % f->numpoints], f ); + if ( numsurfedges >= MAX_MAP_SURFEDGES ) { + Error( "numsurfedges == MAX_MAP_SURFEDGES" ); + } + dsurfedges[numsurfedges] = e; + numsurfedges++; + } +} + +/* +============ +EmitDrawingNode_r +============ +*/ +int EmitDrawNode_r( node_t *node ) { + dnode_t *n; + face_t *f; + int i; + + if ( node->planenum == PLANENUM_LEAF ) { + EmitLeaf( node ); + return -numleafs; + } + + // emit a node + if ( numnodes == MAX_MAP_NODES ) { + Error( "MAX_MAP_NODES" ); + } + n = &dnodes[numnodes]; + numnodes++; + + VectorCopy( node->mins, n->mins ); + VectorCopy( node->maxs, n->maxs ); + + planeused[node->planenum]++; + planeused[node->planenum ^ 1]++; + + if ( node->planenum & 1 ) { + Error( "WriteDrawNodes_r: odd planenum" ); + } + n->planenum = node->planenum; + n->firstface = numfaces; + + if ( !node->faces ) { + c_nofaces++; + } else { + c_facenodes++; + } + + for ( f = node->faces ; f ; f = f->next ) + EmitFace( f ); + + n->numfaces = numfaces - n->firstface; + + + // + // recursively output the other nodes + // + for ( i = 0 ; i < 2 ; i++ ) + { + if ( node->children[i]->planenum == PLANENUM_LEAF ) { + n->children[i] = -( numleafs + 1 ); + EmitLeaf( node->children[i] ); + } else + { + n->children[i] = numnodes; + EmitDrawNode_r( node->children[i] ); + } + } + + return n - dnodes; +} + +//========================================================= + + +/* +============ +WriteBSP +============ +*/ +void WriteBSP( node_t *headnode ) { + int oldfaces; + + c_nofaces = 0; + c_facenodes = 0; + + qprintf( "--- WriteBSP ---\n" ); + + oldfaces = numfaces; + dmodels[nummodels].headnode = EmitDrawNode_r( headnode ); +// EmitAreaPortals (headnode); + + qprintf( "%5i nodes with faces\n", c_facenodes ); + qprintf( "%5i nodes without faces\n", c_nofaces ); + qprintf( "%5i faces\n", numfaces - oldfaces ); +} + +//=========================================================== + +/* +============ +SetModelNumbers +============ +*/ +void SetModelNumbers( void ) { + int i; + int models; + char value[10]; + + models = 1; + for ( i = 1 ; i < num_entities ; i++ ) + { + if ( entities[i].numbrushes ) { + sprintf( value, "*%i", models ); + models++; + SetKeyValue( &entities[i], "model", value ); + } + } + +} + +/* +============ +SetLightStyles +============ +*/ +#define MAX_SWITCHED_LIGHTS 32 +void SetLightStyles( void ) { + int stylenum; + char *t; + entity_t *e; + int i, j; + char value[10]; + char lighttargets[MAX_SWITCHED_LIGHTS][64]; + + + // any light that is controlled (has a targetname) + // must have a unique style number generated for it + + stylenum = 0; + for ( i = 1 ; i < num_entities ; i++ ) + { + e = &entities[i]; + + t = ValueForKey( e, "classname" ); + if ( Q_strncasecmp( t, "light", 5 ) ) { + continue; + } + t = ValueForKey( e, "targetname" ); + if ( !t[0] ) { + continue; + } + + // find this targetname + for ( j = 0 ; j < stylenum ; j++ ) + if ( !strcmp( lighttargets[j], t ) ) { + break; + } + if ( j == stylenum ) { + if ( stylenum == MAX_SWITCHED_LIGHTS ) { + Error( "stylenum == MAX_SWITCHED_LIGHTS" ); + } + strcpy( lighttargets[j], t ); + stylenum++; + } + sprintf( value, "%i", 32 + j ); + SetKeyValue( e, "style", value ); + } + +} + +//=========================================================== + +/* +============ +EmitBrushes +============ +*/ +void EmitBrushes( void ) { + int i, j, bnum, s, x; + dbrush_t *db; + mapbrush_t *b; + dbrushside_t *cp; + vec3_t normal; + vec_t dist; + int planenum; + + numbrushsides = 0; + numbrushes = nummapbrushes; + + for ( bnum = 0 ; bnum < nummapbrushes ; bnum++ ) + { + b = &mapbrushes[bnum]; + db = &dbrushes[bnum]; + + db->contents = b->contents; + db->firstside = numbrushsides; + db->numsides = b->numsides; + for ( j = 0 ; j < b->numsides ; j++ ) + { + if ( numbrushsides == MAX_MAP_BRUSHSIDES ) { + Error( "MAX_MAP_BRUSHSIDES" ); + } + cp = &dbrushsides[numbrushsides]; + numbrushsides++; + cp->planenum = b->original_sides[j].planenum; + cp->texinfo = b->original_sides[j].texinfo; + } + +#ifdef ME + //for collision detection, bounding boxes are axial :) + //brushes are convex so just add dot or line touching planes on the sides of + //the brush parallell to the axis planes +#endif + // add any axis planes not contained in the brush to bevel off corners + for ( x = 0 ; x < 3 ; x++ ) + for ( s = -1 ; s <= 1 ; s += 2 ) + { + // add the plane + VectorCopy( vec3_origin, normal ); + normal[x] = s; + if ( s == -1 ) { + dist = -b->mins[x]; + } else { + dist = b->maxs[x]; + } + planenum = FindFloatPlane( normal, dist ); + for ( i = 0 ; i < b->numsides ; i++ ) + if ( b->original_sides[i].planenum == planenum ) { + break; + } + if ( i == b->numsides ) { + if ( numbrushsides >= MAX_MAP_BRUSHSIDES ) { + Error( "MAX_MAP_BRUSHSIDES" ); + } + + dbrushsides[numbrushsides].planenum = planenum; + dbrushsides[numbrushsides].texinfo = + dbrushsides[numbrushsides - 1].texinfo; + numbrushsides++; + db->numsides++; + } + } + + } + +} + +//=========================================================== + +/* +================== +BeginBSPFile +================== +*/ +void BeginBSPFile( void ) { + // these values may actually be initialized + // if the file existed when loaded, so clear them explicitly + nummodels = 0; + numfaces = 0; + numnodes = 0; + numbrushsides = 0; + numvertexes = 0; + numleaffaces = 0; + numleafbrushes = 0; + numsurfedges = 0; + + // edge 0 is not used, because 0 can't be negated + numedges = 1; + + // leave vertex 0 as an error + numvertexes = 1; + + // leave leaf 0 as an error + numleafs = 1; + dleafs[0].contents = CONTENTS_SOLID; +} + + +/* +============ +EndBSPFile +============ +*/ +void EndBSPFile( void ) { +#if 0 + char path[1024]; + int len; + byte *buf; +#endif + + + EmitBrushes(); + EmitPlanes(); + Q2_UnparseEntities(); + + // load the pop +#if 0 + sprintf( path, "%s/pics/pop.lmp", gamedir ); + len = LoadFile( path, &buf ); + memcpy( dpop, buf, sizeof( dpop ) ); + FreeMemory( buf ); +#endif +} + + +/* +================== +BeginModel +================== +*/ +int firstmodleaf; +extern int firstmodeledge; +extern int firstmodelface; +void BeginModel( void ) { + dmodel_t *mod; + int start, end; + mapbrush_t *b; + int j; + entity_t *e; + vec3_t mins, maxs; + + if ( nummodels == MAX_MAP_MODELS ) { + Error( "MAX_MAP_MODELS" ); + } + mod = &dmodels[nummodels]; + + mod->firstface = numfaces; + + firstmodleaf = numleafs; + firstmodeledge = numedges; + firstmodelface = numfaces; + + // + // bound the brushes + // + e = &entities[entity_num]; + + start = e->firstbrush; + end = start + e->numbrushes; + ClearBounds( mins, maxs ); + + for ( j = start ; j < end ; j++ ) + { + b = &mapbrushes[j]; + if ( !b->numsides ) { + continue; // not a real brush (origin brush) + } + AddPointToBounds( b->mins, mins, maxs ); + AddPointToBounds( b->maxs, mins, maxs ); + } + + VectorCopy( mins, mod->mins ); + VectorCopy( maxs, mod->maxs ); +} + + +/* +================== +EndModel +================== +*/ +void EndModel( void ) { + dmodel_t *mod; + + mod = &dmodels[nummodels]; + + mod->numfaces = numfaces - mod->firstface; + + nummodels++; +} + +#endif \ No newline at end of file diff --git a/Projects/Android/jni/rtcw/src/cgame/cg_consolecmds.c b/Projects/Android/jni/rtcw/src/cgame/cg_consolecmds.c new file mode 100644 index 0000000..284d5fd --- /dev/null +++ b/Projects/Android/jni/rtcw/src/cgame/cg_consolecmds.c @@ -0,0 +1,546 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +/* + * name: cg_consolecmds.c + * + * desc: text commands typed in at the local console, or executed by a key binding + * +*/ + + +#include "cg_local.h" +#include "../ui/ui_shared.h" + + + +void CG_TargetCommand_f( void ) { + int targetNum; + char test[4]; + + targetNum = CG_CrosshairPlayer(); + if ( !targetNum ) { + return; + } + + trap_Argv( 1, test, 4 ); + trap_SendConsoleCommand( va( "gc %i %i", targetNum, atoi( test ) ) ); +} + + + +/* +================= +CG_SizeUp_f + +Keybinding command +================= +*/ +static void CG_SizeUp_f( void ) { + trap_Cvar_Set( "cg_viewsize", va( "%i",(int)( cg_viewsize.integer + 10 ) ) ); +} + + +/* +================= +CG_SizeDown_f + +Keybinding command +================= +*/ +static void CG_SizeDown_f( void ) { + trap_Cvar_Set( "cg_viewsize", va( "%i",(int)( cg_viewsize.integer - 10 ) ) ); +} + + +/* +============= +CG_Viewpos_f + +Debugging command to print the current position +============= +*/ +static void CG_Viewpos_f( void ) { + CG_Printf( "(%i %i %i) : %i\n", (int)cg.refdef.vieworg[0], + (int)cg.refdef.vieworg[1], (int)cg.refdef.vieworg[2], + (int)cg.refdefViewAngles[YAW] ); +} + + +static void CG_ScoresDown_f( void ) { + if ( cg.scoresRequestTime + 2000 < cg.time ) { + // the scores are more than two seconds out of data, + // so request new ones + cg.scoresRequestTime = cg.time; + trap_SendClientCommand( "score" ); + + // leave the current scores up if they were already + // displayed, but if this is the first hit, clear them out + if ( !cg.showScores ) { + cg.showScores = qtrue; + cg.numScores = 0; + } + } else { + // show the cached contents even if they just pressed if it + // is within two seconds + cg.showScores = qtrue; + } +} + +static void CG_ScoresUp_f( void ) { + if ( cg.showScores ) { + cg.showScores = qfalse; + cg.scoreFadeTime = cg.time; + } +} + + +extern menuDef_t *menuScoreboard; +void Menu_Reset(); // FIXME: add to right include file + +static void CG_LoadHud_f( void ) { + char buff[1024]; + const char *hudSet; + memset( buff, 0, sizeof( buff ) ); + + String_Init(); + Menu_Reset(); + + trap_Cvar_VariableStringBuffer( "cg_hudFiles", buff, sizeof( buff ) ); + hudSet = buff; + if ( hudSet[0] == '\0' ) { + hudSet = "ui/hud.txt"; + } + + CG_LoadMenus( hudSet ); + menuScoreboard = NULL; +} + +// TTimo: defined but not used +/* +static void CG_scrollScoresDown_f( void) { + if (menuScoreboard && cg.scoreBoardShowing) { + Menu_ScrollFeeder(menuScoreboard, FEEDER_SCOREBOARD, qtrue); + Menu_ScrollFeeder(menuScoreboard, FEEDER_REDTEAM_LIST, qtrue); + Menu_ScrollFeeder(menuScoreboard, FEEDER_BLUETEAM_LIST, qtrue); + } +} + + +static void CG_scrollScoresUp_f( void) { + if (menuScoreboard && cg.scoreBoardShowing) { + Menu_ScrollFeeder(menuScoreboard, FEEDER_SCOREBOARD, qfalse); + Menu_ScrollFeeder(menuScoreboard, FEEDER_REDTEAM_LIST, qfalse); + Menu_ScrollFeeder(menuScoreboard, FEEDER_BLUETEAM_LIST, qfalse); + } +} + + +static void CG_spWin_f( void) { + trap_Cvar_Set("cg_cameraOrbit", "2"); + trap_Cvar_Set("cg_cameraOrbitDelay", "35"); + trap_Cvar_Set("cg_thirdPerson", "1"); + trap_Cvar_Set("cg_thirdPersonAngle", "0"); + trap_Cvar_Set("cg_thirdPersonRange", "100"); +// CG_AddBufferedSound(cgs.media.winnerSound); + //trap_S_StartLocalSound(cgs.media.winnerSound, CHAN_ANNOUNCER); + CG_CenterPrint("YOU WIN!", SCREEN_HEIGHT * .30, 0); +} + +static void CG_spLose_f( void) { + trap_Cvar_Set("cg_cameraOrbit", "2"); + trap_Cvar_Set("cg_cameraOrbitDelay", "35"); + trap_Cvar_Set("cg_thirdPerson", "1"); + trap_Cvar_Set("cg_thirdPersonAngle", "0"); + trap_Cvar_Set("cg_thirdPersonRange", "100"); +// CG_AddBufferedSound(cgs.media.loserSound); + //trap_S_StartLocalSound(cgs.media.loserSound, CHAN_ANNOUNCER); + CG_CenterPrint("YOU LOSE...", SCREEN_HEIGHT * .30, 0); +} +*/ + +//----(SA) item (key/pickup) drawing +static void CG_InventoryDown_f( void ) { + cg.showItems = qtrue; +} + +static void CG_InventoryUp_f( void ) { + cg.showItems = qfalse; + cg.itemFadeTime = cg.time; +} + +//----(SA) end + +static void CG_TellTarget_f( void ) { + int clientNum; + char command[128]; + char message[128]; + + clientNum = CG_CrosshairPlayer(); + if ( clientNum == -1 ) { + return; + } + + trap_Args( message, 128 ); + Com_sprintf( command, 128, "tell %i %s", clientNum, message ); + trap_SendClientCommand( command ); +} + +static void CG_TellAttacker_f( void ) { + int clientNum; + char command[128]; + char message[128]; + + clientNum = CG_LastAttacker(); + if ( clientNum == -1 ) { + return; + } + + trap_Args( message, 128 ); + Com_sprintf( command, 128, "tell %i %s", clientNum, message ); + trap_SendClientCommand( command ); +} + +// TTimo: unused +/* +static void CG_NextTeamMember_f( void ) { + CG_SelectNextPlayer(); +} + +static void CG_PrevTeamMember_f( void ) { + CG_SelectPrevPlayer(); +} +*/ + +/////////// cameras + +#define MAX_CAMERAS 64 // matches define in splines.cpp +qboolean cameraInuse[MAX_CAMERAS]; + +int CG_LoadCamera( const char *name ) { + int i; + for ( i = 1; i < MAX_CAMERAS; i++ ) { // start at '1' since '0' is always taken by the cutscene camera + if ( !cameraInuse[i] ) { + if ( trap_loadCamera( i, name ) ) { + cameraInuse[i] = qtrue; + return i; + } + } + } + return -1; +} + +void CG_FreeCamera( int camNum ) { + cameraInuse[camNum] = qfalse; +} + +/* +============== +CG_StartCamera +============== +*/ +void CG_StartCamera( const char *name, qboolean startBlack ) { + char lname[MAX_QPATH]; + + //if ( cg.predictedPlayerState.stats[STAT_HEALTH] <= 0 ) // don't allow camera to start if you're dead + // return; + + COM_StripExtension( name, lname ); //----(SA) added + strcat( lname, ".camera" ); + + if ( trap_loadCamera( CAM_PRIMARY, va( "cameras/%s", lname ) ) ) { + cg.cameraMode = qtrue; // camera on in cgame + if ( startBlack ) { + CG_Fade( 0, 0, 0, 255, cg.time, 0 ); // go black + } + trap_Cvar_Set( "cg_letterbox", "1" ); // go letterbox + trap_SendClientCommand( "startCamera" ); // camera on in game + trap_startCamera( CAM_PRIMARY, cg.time ); // camera on in client + } else { +//----(SA) removed check for cams in main dir + cg.cameraMode = qfalse; // camera off in cgame + trap_SendClientCommand( "stopCamera" ); // camera off in game + trap_stopCamera( CAM_PRIMARY ); // camera off in client + CG_Fade( 0, 0, 0, 0, cg.time, 0 ); // ensure fadeup + trap_Cvar_Set( "cg_letterbox", "0" ); + } +} + +/* +============== +CG_SopCamera +============== +*/ +void CG_StopCamera( void ) { + cg.cameraMode = qfalse; // camera off in cgame + trap_SendClientCommand( "stopCamera" ); // camera off in game + trap_stopCamera( CAM_PRIMARY ); // camera off in client + trap_Cvar_Set( "cg_letterbox", "0" ); + + // fade back into world + CG_Fade( 0, 0, 0, 255, 0, 0 ); + CG_Fade( 0, 0, 0, 0, cg.time + 500, 2000 ); + +} + +static void CG_Camera_f( void ) { + char name[MAX_QPATH]; + trap_Argv( 1, name, sizeof( name ) ); + CG_StartCamera( name, qfalse ); +} + +static void CG_Fade_f( void ) { + int r, g, b, a; + float duration; + + if ( trap_Argc() < 6 ) { + return; + } + + r = atof( CG_Argv( 1 ) ); + g = atof( CG_Argv( 2 ) ); + b = atof( CG_Argv( 3 ) ); + a = atof( CG_Argv( 4 ) ); + + duration = atof( CG_Argv( 5 ) ) * 1000; + + CG_Fade( r, g, b, a, cg.time, duration ); +} + +// TTimo unused +/* +// NERVE - SMF +static void CG_PickTeam_f( void ) { + const char *s; + char buf[144]; + + if(cgs.gametype != GT_WOLF) + return; + + // set map title + trap_Cvar_VariableStringBuffer( "sv_mapname", buf, sizeof( buf ) ); + trap_Cvar_Set( "mp_mapTitle", "MAP" ); //buf ); + + // set map description + s = CG_ConfigString( CS_MULTI_MAPDESC ); + if ( s ) + trap_Cvar_Set( "mp_mapDesc", s ); + + trap_UI_Popup( "UIMENU_WM_PICKTEAM" ); +} + +static void CG_PickPlayer_f( void ) { + const char *s; + char buf[144]; + + if(cgs.gametype != GT_WOLF) + return; + + // set map title + trap_Cvar_VariableStringBuffer( "sv_mapname", buf, sizeof( buf ) ); + trap_Cvar_Set( "mp_mapTitle", "MAP" ); //buf ); + + // set map description + s = CG_ConfigString( CS_MULTI_MAPDESC ); + if ( s ) + trap_Cvar_Set( "mp_mapDesc", s ); + + trap_UI_Popup( "UIMENU_WM_PICKPLAYER" ); +} +*/ + +static void CG_QuickMessage_f( void ) { + if ( cgs.gametype != GT_WOLF ) { + return; + } + trap_UI_Popup( "UIMENU_WM_QUICKMESSAGE" ); +} + +static void CG_OpenLimbo_f( void ) { + if ( cgs.gametype != GT_WOLF ) { + return; + } + trap_UI_Popup( "UIMENU_WM_LIMBO" ); +} + +static void CG_CloseLimbo_f( void ) { + if ( cgs.gametype != GT_WOLF ) { + return; + } + trap_UI_ClosePopup( "UIMENU_WM_LIMBO" ); +} + +static void CG_LimboMessage_f( void ) { + char teamStr[80], classStr[80], weapStr[80]; + + if ( cgs.gametype != GT_WOLF ) { + return; + } + + Q_strncpyz( teamStr, CG_Argv( 1 ), 80 ); + Q_strncpyz( classStr, CG_Argv( 2 ), 80 ); + Q_strncpyz( weapStr, CG_Argv( 3 ), 80 ); + + CG_CenterPrint( va( "You will spawn as a %s \n%s with a %s.", teamStr, classStr, weapStr ), + SCREEN_HEIGHT - ( SCREEN_HEIGHT * 0.25 ), SMALLCHAR_WIDTH ); +} +// -NERVE - SMF + +typedef struct { + char *cmd; + void ( *function )( void ); +} consoleCommand_t; + +static consoleCommand_t commands[] = { + { "testgun", CG_TestGun_f }, + { "testmodel", CG_TestModel_f }, + { "nextframe", CG_TestModelNextFrame_f }, + { "prevframe", CG_TestModelPrevFrame_f }, + { "nextskin", CG_TestModelNextSkin_f }, + { "prevskin", CG_TestModelPrevSkin_f }, + { "viewpos", CG_Viewpos_f }, + { "+scores", CG_ScoresDown_f }, + { "-scores", CG_ScoresUp_f }, + { "+inventory", CG_InventoryDown_f }, + { "-inventory", CG_InventoryUp_f }, +// { "+zoom", CG_ZoomDown_f }, // (SA) zoom moved to a wbutton so server can determine weapon firing based on zoom status +// { "-zoom", CG_ZoomUp_f }, + { "zoomin", CG_ZoomIn_f }, + { "zoomout", CG_ZoomOut_f }, + { "sizeup", CG_SizeUp_f }, + { "sizedown", CG_SizeDown_f }, + { "weaplastused", CG_LastWeaponUsed_f }, + { "weapnextinbank", CG_NextWeaponInBank_f }, + { "weapprevinbank", CG_PrevWeaponInBank_f }, + { "weapnext", CG_NextWeapon_f }, + { "weapprev", CG_PrevWeapon_f }, + { "weapalt", CG_AltWeapon_f }, + { "weapon", CG_Weapon_f }, + { "weaponbank", CG_WeaponBank_f }, + { "itemnext", CG_NextItem_f }, + { "itemprev", CG_PrevItem_f }, + { "item", CG_Item_f }, + { "tell_target", CG_TellTarget_f }, + { "tell_attacker", CG_TellAttacker_f }, + { "tcmd", CG_TargetCommand_f }, + { "loadhud", CG_LoadHud_f }, + { "loaddeferred", CG_LoadDeferredPlayers }, // spelling fixed (SA) + { "camera", CG_Camera_f }, // duffy + { "fade", CG_Fade_f }, // duffy + + // NERVE - SMF + { "mp_QuickMessage", CG_QuickMessage_f }, + { "OpenLimboMenu", CG_OpenLimbo_f }, + { "CloseLimboMenu", CG_CloseLimbo_f }, + { "LimboMessage", CG_LimboMessage_f } + // -NERVE - SMF +}; + + +/* +================= +CG_ConsoleCommand + +The string has been tokenized and can be retrieved with +Cmd_Argc() / Cmd_Argv() +================= +*/ +qboolean CG_ConsoleCommand( void ) { + const char *cmd; + int i; + + cmd = CG_Argv( 0 ); + + for ( i = 0 ; i < sizeof( commands ) / sizeof( commands[0] ) ; i++ ) { + if ( !Q_stricmp( cmd, commands[i].cmd ) ) { + commands[i].function(); + return qtrue; + } + } + + return qfalse; +} + + +/* +================= +CG_InitConsoleCommands + +Let the client system know about all of our commands +so it can perform tab completion +================= +*/ +void CG_InitConsoleCommands( void ) { + int i; + + for ( i = 0 ; i < sizeof( commands ) / sizeof( commands[0] ) ; i++ ) { + trap_AddCommand( commands[i].cmd ); + } + + // + // the game server will interpret these commands, which will be automatically + // forwarded to the server after they are not recognized locally + // + trap_AddCommand( "kill" ); + trap_AddCommand( "say" ); + trap_AddCommand( "say_team" ); + trap_AddCommand( "say_limbo" ); // NERVE - SMF + trap_AddCommand( "tell" ); +// trap_AddCommand ("vsay"); +// trap_AddCommand ("vsay_team"); +// trap_AddCommand ("vtell"); +// trap_AddCommand ("vtaunt"); +// trap_AddCommand ("vosay"); +// trap_AddCommand ("vosay_team"); +// trap_AddCommand ("votell"); + trap_AddCommand( "give" ); + trap_AddCommand( "god" ); + trap_AddCommand( "notarget" ); + trap_AddCommand( "noclip" ); + trap_AddCommand( "team" ); + trap_AddCommand( "follow" ); + trap_AddCommand( "levelshot" ); + trap_AddCommand( "addbot" ); + trap_AddCommand( "setviewpos" ); + trap_AddCommand( "callvote" ); + trap_AddCommand( "vote" ); +// trap_AddCommand ("callteamvote"); +// trap_AddCommand ("teamvote"); + trap_AddCommand( "stats" ); +// trap_AddCommand ("teamtask"); + trap_AddCommand( "loaddeferred" ); // spelling fixed (SA) + + trap_AddCommand( "startCamera" ); + trap_AddCommand( "stopCamera" ); + trap_AddCommand( "setCameraOrigin" ); + + // Rafael + trap_AddCommand( "nofatigue" ); + + trap_AddCommand( "setspawnpt" ); // NERVE - SMF +} diff --git a/Projects/Android/jni/rtcw/src/cgame/cg_draw.c b/Projects/Android/jni/rtcw/src/cgame/cg_draw.c new file mode 100644 index 0000000..3ec0da8 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/cgame/cg_draw.c @@ -0,0 +1,3630 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +// cg_draw.c -- draw all of the graphical elements during +// active (after loading) gameplay + +#include "cg_local.h" +#include "../ui/ui_shared.h" + +//----(SA) added to make it easier to raise/lower our statsubar by only changing one thing +#define STATUSBARHEIGHT 452 +//----(SA) end + +extern displayContextDef_t cgDC; +menuDef_t *menuScoreboard = NULL; + +int sortedTeamPlayers[TEAM_MAXOVERLAY]; +int numSortedTeamPlayers; + +char systemChat[256]; +char teamChat1[256]; +char teamChat2[256]; + +//////////////////////// +//////////////////////// +////// new hud stuff +/////////////////////// +/////////////////////// + +int CG_Text_Width( const char *text, int font, float scale, int limit ) { + int count,len; + float out; + glyphInfo_t *glyph; + float useScale; + const char *s = text; + + fontInfo_t *fnt = &cgDC.Assets.textFont; + + if ( font == UI_FONT_DEFAULT ) { + if ( scale <= cg_smallFont.value ) { + fnt = &cgDC.Assets.smallFont; + } else if ( scale > cg_bigFont.value ) { + fnt = &cgDC.Assets.bigFont; + } + } else if ( font == UI_FONT_BIG ) { + fnt = &cgDC.Assets.bigFont; + } else if ( font == UI_FONT_SMALL ) { + fnt = &cgDC.Assets.smallFont; + } else if ( font == UI_FONT_HANDWRITING ) { + fnt = &cgDC.Assets.handwritingFont; + } + + useScale = scale * fnt->glyphScale; + out = 0; + if ( text ) { + len = strlen( text ); + if ( limit > 0 && len > limit ) { + len = limit; + } + count = 0; + while ( s && *s && count < len ) { + if ( Q_IsColorString( s ) ) { + s += 2; + continue; + } else { + glyph = &fnt->glyphs[(int)*s]; + out += glyph->xSkip; + s++; + count++; + } + } + } + return out * useScale; +} + +int CG_Text_Height( const char *text, int font, float scale, int limit ) { + int len, count; + float max; + glyphInfo_t *glyph; + float useScale; + const char *s = text; + + fontInfo_t *fnt = &cgDC.Assets.textFont; + if ( font == UI_FONT_DEFAULT ) { + if ( scale <= cg_smallFont.value ) { + fnt = &cgDC.Assets.smallFont; + } else if ( scale > cg_bigFont.value ) { + fnt = &cgDC.Assets.bigFont; + } + } else if ( font == UI_FONT_BIG ) { + fnt = &cgDC.Assets.bigFont; + } else if ( font == UI_FONT_SMALL ) { + fnt = &cgDC.Assets.smallFont; + } else if ( font == UI_FONT_HANDWRITING ) { + fnt = &cgDC.Assets.handwritingFont; + } + + useScale = scale * fnt->glyphScale; + max = 0; + if ( text ) { + len = strlen( text ); + if ( limit > 0 && len > limit ) { + len = limit; + } + count = 0; + while ( s && *s && count < len ) { + if ( Q_IsColorString( s ) ) { + s += 2; + continue; + } else { + glyph = &fnt->glyphs[(int)*s]; + if ( max < glyph->height ) { + max = glyph->height; + } + s++; + count++; + } + } + } + return max * useScale; +} + +void CG_Text_PaintChar( float x, float y, float width, float height, float scale, float s, float t, float s2, float t2, qhandle_t hShader ) { + float w, h; + w = width * scale; + h = height * scale; + CG_AdjustFrom640( &x, &y, &w, &h ); + trap_R_DrawStretchPic( x, y, w, h, s, t, s2, t2, hShader ); +} + +void CG_Text_Paint( float x, float y, int font, float scale, vec4_t color, const char *text, float adjust, int limit, int style ) { + int len, count; + vec4_t newColor; + glyphInfo_t *glyph; + float useScale; + fontInfo_t *fnt = &cgDC.Assets.textFont; + + if ( font == UI_FONT_DEFAULT ) { + if ( scale <= cg_smallFont.value ) { + fnt = &cgDC.Assets.smallFont; + } else if ( scale > cg_bigFont.value ) { + fnt = &cgDC.Assets.bigFont; + } + } else if ( font == UI_FONT_BIG ) { + fnt = &cgDC.Assets.bigFont; + } else if ( font == UI_FONT_SMALL ) { + fnt = &cgDC.Assets.smallFont; + } else if ( font == UI_FONT_HANDWRITING ) { + fnt = &cgDC.Assets.handwritingFont; + } + + useScale = scale * fnt->glyphScale; + + color[3] *= cg_hudAlpha.value; // (SA) adjust for cg_hudalpha + + if ( text ) { + const char *s = text; + trap_R_SetColor( color ); + memcpy( &newColor[0], &color[0], sizeof( vec4_t ) ); + len = strlen( text ); + if ( limit > 0 && len > limit ) { + len = limit; + } + count = 0; + while ( s && *s && count < len ) { + glyph = &fnt->glyphs[(int)*s]; + //int yadj = Assets.textFont.glyphs[text[i]].bottom + Assets.textFont.glyphs[text[i]].top; + //float yadj = scale * (Assets.textFont.glyphs[text[i]].imageHeight - Assets.textFont.glyphs[text[i]].height); + if ( Q_IsColorString( s ) ) { + memcpy( newColor, g_color_table[ColorIndex( *( s + 1 ) )], sizeof( newColor ) ); + newColor[3] = color[3]; + trap_R_SetColor( newColor ); + s += 2; + continue; + } else { + float yadj = useScale * glyph->top; + if ( style == ITEM_TEXTSTYLE_SHADOWED || style == ITEM_TEXTSTYLE_SHADOWEDMORE ) { + int ofs = style == ITEM_TEXTSTYLE_SHADOWED ? 1 : 2; + colorBlack[3] = newColor[3]; + trap_R_SetColor( colorBlack ); + CG_Text_PaintChar( x + ofs, y - yadj + ofs, + glyph->imageWidth, + glyph->imageHeight, + useScale, + glyph->s, + glyph->t, + glyph->s2, + glyph->t2, + glyph->glyph ); + colorBlack[3] = 1.0; + trap_R_SetColor( newColor ); + } + CG_Text_PaintChar( x, y - yadj, + glyph->imageWidth, + glyph->imageHeight, + useScale, + glyph->s, + glyph->t, + glyph->s2, + glyph->t2, + glyph->glyph ); + // CG_DrawPic(x, y - yadj, scale * cgDC.Assets.textFont.glyphs[text[i]].imageWidth, scale * cgDC.Assets.textFont.glyphs[text[i]].imageHeight, cgDC.Assets.textFont.glyphs[text[i]].glyph); + x += ( glyph->xSkip * useScale ) + adjust; + s++; + count++; + } + } + trap_R_SetColor( NULL ); + } +} + + + + + + + + + + + +#ifdef OLDWOLFUI +static void CG_DrawField( int x, int y, int width, int value ) { + char num[16], *ptr; + int l; + int frame; + + if ( width < 1 ) { + return; + } + + // draw number string + if ( width > 5 ) { + width = 5; + } + + switch ( width ) { + case 1: + value = value > 9 ? 9 : value; + value = value < 0 ? 0 : value; + break; + case 2: + value = value > 99 ? 99 : value; + value = value < -9 ? -9 : value; + break; + case 3: + value = value > 999 ? 999 : value; + value = value < -99 ? -99 : value; + break; + case 4: + value = value > 9999 ? 9999 : value; + value = value < -999 ? -999 : value; + break; + } + + Com_sprintf( num, sizeof( num ), "%i", value ); + l = strlen( num ); + if ( l > width ) { + l = width; + } + x += 2 + CHAR_WIDTH * ( width - l ); + + ptr = num; + while ( *ptr && l ) + { + if ( *ptr == '-' ) { + frame = STAT_MINUS; + } else { + frame = *ptr - '0'; + } + + CG_DrawPic( x,y, CHAR_WIDTH, CHAR_HEIGHT, cgs.media.numberShaders[frame] ); + x += CHAR_WIDTH; + ptr++; + l--; + } +} +#endif // #ifdef OLDWOLFUI + +/* +================ +CG_Draw3DModel + +================ +*/ +void CG_Draw3DModel( float x, float y, float w, float h, qhandle_t model, qhandle_t skin, vec3_t origin, vec3_t angles ) { + refdef_t refdef; + refEntity_t ent; + + if ( !cg_draw3dIcons.integer || !cg_drawIcons.integer ) { + return; + } + + CG_AdjustFrom640( &x, &y, &w, &h ); + + memset( &refdef, 0, sizeof( refdef ) ); + + memset( &ent, 0, sizeof( ent ) ); + AnglesToAxis( angles, ent.axis ); + VectorCopy( origin, ent.origin ); + ent.hModel = model; + ent.customSkin = skin; + ent.renderfx = RF_NOSHADOW; // no stencil shadows + + refdef.rdflags = RDF_NOWORLDMODEL; + + AxisClear( refdef.viewaxis ); + + refdef.fov_x = 30; + refdef.fov_y = 30; + + refdef.x = x; + refdef.y = y; + refdef.width = w; + refdef.height = h; + + refdef.time = cg.time; + + refdef.rdflags |= RDF_DRAWSKYBOX; + if ( !cg_skybox.integer ) { + refdef.rdflags &= ~RDF_DRAWSKYBOX; + } + + trap_R_ClearScene(); + trap_R_AddRefEntityToScene( &ent ); + trap_R_RenderScene( &refdef ); +} + +/* +================ +CG_DrawHead + +Used for both the status bar and the scoreboard +================ +*/ +void CG_DrawHead( float x, float y, float w, float h, int clientNum, vec3_t headAngles ) { + clipHandle_t cm; + clientInfo_t *ci; + float len; + vec3_t origin; + vec3_t mins, maxs; + + ci = &cgs.clientinfo[ clientNum ]; + + if ( cg_draw3dIcons.integer ) { + cm = ci->headModel; + if ( !cm ) { + return; + } + + // offset the origin y and z to center the head + trap_R_ModelBounds( cm, mins, maxs ); + + origin[2] = -0.5 * ( mins[2] + maxs[2] ); + origin[1] = 0.5 * ( mins[1] + maxs[1] ); + + // calculate distance so the head nearly fills the box + // assume heads are taller than wide + len = 0.7 * ( maxs[2] - mins[2] ); + origin[0] = len / 0.268; // len / tan( fov/2 ) + + // allow per-model tweaking + VectorAdd( origin, ci->modelInfo->headOffset, origin ); + + CG_Draw3DModel( x, y, w, h, ci->headModel, ci->headSkin, origin, headAngles ); +// } else if ( cg_drawIcons.integer ) { +// CG_DrawPic( x, y, w, h, ci->modelIcon ); + } + + // if they are deferred, draw a cross out + if ( ci->deferred ) { + CG_DrawPic( x, y, w, h, cgs.media.deferShader ); + } +} + +/* +================ +CG_DrawFlagModel + +Used for both the status bar and the scoreboard +================ +*/ +void CG_DrawFlagModel( float x, float y, float w, float h, int team ) { + qhandle_t cm; + float len; + vec3_t origin, angles; + vec3_t mins, maxs; + + VectorClear( angles ); + + cm = cgs.media.redFlagModel; + + // offset the origin y and z to center the flag + trap_R_ModelBounds( cm, mins, maxs ); + + origin[2] = -0.5 * ( mins[2] + maxs[2] ); + origin[1] = 0.5 * ( mins[1] + maxs[1] ); + + // calculate distance so the flag nearly fills the box + // assume heads are taller than wide + len = 0.5 * ( maxs[2] - mins[2] ); + origin[0] = len / 0.268; // len / tan( fov/2 ) + + angles[YAW] = 60 * sin( cg.time / 2000.0 );; + + CG_Draw3DModel( x, y, w, h, + team == TEAM_RED ? cgs.media.redFlagModel : cgs.media.blueFlagModel, + 0, origin, angles ); +} + + +/* +============== +CG_DrawKeyModel +============== +*/ +void CG_DrawKeyModel( int keynum, float x, float y, float w, float h, int fadetime ) { + qhandle_t cm; + float len; + vec3_t origin, angles; + vec3_t mins, maxs; + + VectorClear( angles ); + + cm = cg_items[keynum].models[0]; + + // offset the origin y and z to center the model + trap_R_ModelBounds( cm, mins, maxs ); + + origin[2] = -0.5 * ( mins[2] + maxs[2] ); + origin[1] = 0.5 * ( mins[1] + maxs[1] ); + +// len = 0.5 * ( maxs[2] - mins[2] ); + len = 0.75 * ( maxs[2] - mins[2] ); + origin[0] = len / 0.268; // len / tan( fov/2 ) + + angles[YAW] = 30 * sin( cg.time / 2000.0 );; + + CG_Draw3DModel( x, y, w, h, cg_items[keynum].models[0], 0, origin, angles ); +} + +/* +================ +CG_DrawStatusBarHead + +================ +*/ +#ifdef OLDWOLFUI +static void CG_DrawStatusBarHead( float x ) { + vec3_t angles; + float size, stretch; + float frac; + + VectorClear( angles ); + + if ( cg.damageTime && cg.time - cg.damageTime < DAMAGE_TIME ) { + frac = (float)( cg.time - cg.damageTime ) / DAMAGE_TIME; + size = ICON_SIZE * 1.25 * ( 1.5 - frac * 0.5 ); + + stretch = size - ICON_SIZE * 1.25; + // kick in the direction of damage + x -= stretch * 0.5 + cg.viewDamage[cg.damageIndex].damageX * stretch * 0.5; + + cg.headStartYaw = 180 + cg.viewDamage[cg.damageIndex].damageX * 45; + + cg.headEndYaw = 180 + 20 * cos( crandom() * M_PI ); + cg.headEndPitch = 5 * cos( crandom() * M_PI ); + + cg.headStartTime = cg.time; + cg.headEndTime = cg.time + 100 + random() * 2000; + } else { + if ( cg.time >= cg.headEndTime ) { + // select a new head angle + cg.headStartYaw = cg.headEndYaw; + cg.headStartPitch = cg.headEndPitch; + cg.headStartTime = cg.headEndTime; + cg.headEndTime = cg.time + 100 + random() * 2000; + + cg.headEndYaw = 180 + 20 * cos( crandom() * M_PI ); + cg.headEndPitch = 5 * cos( crandom() * M_PI ); + } + + size = ICON_SIZE * 1.25; + } + + // if the server was frozen for a while we may have a bad head start time + if ( cg.headStartTime > cg.time ) { + cg.headStartTime = cg.time; + } + + frac = ( cg.time - cg.headStartTime ) / (float)( cg.headEndTime - cg.headStartTime ); + frac = frac * frac * ( 3 - 2 * frac ); + angles[YAW] = cg.headStartYaw + ( cg.headEndYaw - cg.headStartYaw ) * frac; + angles[PITCH] = cg.headStartPitch + ( cg.headEndPitch - cg.headStartPitch ) * frac; + + CG_DrawHead( x, 480 - size, size, size, + cg.snap->ps.clientNum, angles ); +} +#endif // #ifdef OLDWOLFUI + +/* +============== +CG_DrawStatusBarKeys +IT_KEY (this makes this routine easier to find in files...) (SA) +============== +*/ +#ifdef OLDWOLFUI +static void CG_DrawStatusBarKeys() { + int i; + float y = 0; // start height is + gitem_t *gi; + int itemnum; +// int fadetime = 0; + float *fadeColor; + + +//----(SA) added + if ( cg.showItems ) { + fadeColor = colorWhite; + } else { + fadeColor = CG_FadeColor( cg.itemFadeTime, 1000 ); + } + + if ( !fadeColor ) { + return; + } + + + // (SA) just don't draw this stuff for now. It's got fog issues I need to clean up + + return; + + + + for ( i = 1; i < KEY_NUM_KEYS; i++ ) + { + gi = BG_FindItemForKey( i, &itemnum ); + // if i've got the key... + + if ( cg.snap->ps.stats[STAT_KEYS] & ( 1 << gi->giTag ) ) { + y += ICON_SIZE + 5; + CG_DrawKeyModel( itemnum, 640 - ( 1.5 * ICON_SIZE ), y, ICON_SIZE, ICON_SIZE, cg.time + fadeColor[0] * 1000 ); + } + } +} +#endif // #ifdef OLDWOLFUI + +/* +================ +CG_DrawStatusBarFlag + +================ +*/ +#ifdef OLDWOLFUI +static void CG_DrawStatusBarFlag( float x, int team ) { + CG_DrawFlagModel( x, 480 - ICON_SIZE, ICON_SIZE, ICON_SIZE, team ); +} +#endif // #ifdef OLDWOFLUI + +/* +================ +CG_DrawTeamBackground + +================ +*/ +void CG_DrawTeamBackground( int x, int y, int w, int h, float alpha, int team ) { + vec4_t hcolor; + + hcolor[3] = alpha; + if ( team == TEAM_RED ) { + hcolor[0] = 1; + hcolor[1] = 0; + hcolor[2] = 0; + } else if ( team == TEAM_BLUE ) { + hcolor[0] = 0; + hcolor[1] = 0; + hcolor[2] = 1; + } else { + return; + } + trap_R_SetColor( hcolor ); + CG_DrawPic( x, y, w, h, cgs.media.teamStatusBar ); + trap_R_SetColor( NULL ); +} + +////////////////////// +////// end new hud stuff +////////////////////// + + + + + +// JOSEPH 4-25-00 +/* +================ +CG_DrawStatusBar + +================ +*/ +#ifdef OLDWOLFUI +static void CG_DrawStatusBar( void ) { + int color; + centity_t *cent; + playerState_t *ps; + int value, inclip; + vec4_t hcolor; + vec3_t angles; +// vec3_t origin; + static float colors[4][4] = { +// { 0.2, 1.0, 0.2, 1.0 } , { 1.0, 0.2, 0.2, 1.0 }, {0.5, 0.5, 0.5, 1} }; + { 1, 0.69, 0, 1.0 }, // normal + { 1.0, 0.2, 0.2, 1.0 }, // low health + {0.5, 0.5, 0.5, 1}, // weapon firing + { 1, 1, 1, 1 } + }; // health > 100 + + if ( cg_drawStatus.integer == 0 ) { + return; + } + + // draw the team background + if ( cg.snap->ps.persistant[PERS_TEAM] == TEAM_RED ) { + hcolor[0] = 1; + hcolor[1] = 0; + hcolor[2] = 0; + hcolor[3] = 0.33; + trap_R_SetColor( hcolor ); + CG_DrawPic( 0, 420, 640, 60, cgs.media.teamStatusBar ); + trap_R_SetColor( NULL ); + } else if ( cg.snap->ps.persistant[PERS_TEAM] == TEAM_BLUE ) { + hcolor[0] = 0; + hcolor[1] = 0; + hcolor[2] = 1; + hcolor[3] = 0.33; + trap_R_SetColor( hcolor ); + CG_DrawPic( 0, 420, 640, 60, cgs.media.teamStatusBar ); + trap_R_SetColor( NULL ); + } + + cent = &cg_entities[cg.snap->ps.clientNum]; + ps = &cg.snap->ps; + + VectorClear( angles ); + + // draw any 3D icons first, so the changes back to 2D are minimized + + //----(SA) further change... we don't need to draw the ammo 3d model do we? +/* + if ( cent->currentState.weapon && cg_weapons[ cent->currentState.weapon ].ammoModel ) { + origin[0] = 70; + origin[1] = 0; + origin[2] = 0; + angles[YAW] = 90 + 20 * sin( cg.time / 1000.0 );; +//----(SA) Wolf statusbar change + CG_Draw3DModel( CHAR_WIDTH*3 + TEXT_ICON_SPACE, STATUSBARHEIGHT -20, ICON_SIZE, ICON_SIZE, + cg_weapons[ cent->currentState.weapon ].ammoModel, 0, origin, angles ); +//----(SA) end + } +*/ + //CG_DrawStatusBarHead( 185 + CHAR_WIDTH*3 + TEXT_ICON_SPACE ); + + CG_DrawStatusBarKeys(); + + if ( cg.predictedPlayerState.powerups[PW_REDFLAG] ) { + CG_DrawStatusBarFlag( 185 + CHAR_WIDTH * 3 + TEXT_ICON_SPACE + ICON_SIZE, TEAM_RED ); + } else if ( cg.predictedPlayerState.powerups[PW_BLUEFLAG] ) { + CG_DrawStatusBarFlag( 185 + CHAR_WIDTH * 3 + TEXT_ICON_SPACE + ICON_SIZE, TEAM_BLUE ); + } + + //----(SA) further change... we don't need to draw the armor do we? +/* + if ( ps->stats[ STAT_ARMOR ] ) { + origin[0] = 90; + origin[1] = 0; + origin[2] = -10; + angles[YAW] = ( cg.time & 2047 ) * 360 / 2048.0; +//----(SA) Wolf statusbar change +// CG_Draw3DModel( 370 + CHAR_WIDTH*3 + TEXT_ICON_SPACE, STATUSBARHEIGHT -20, ICON_SIZE, ICON_SIZE, +// cgs.media.armorModel, 0, origin, angles ); +//----(SA) end + } +*/ + // + // ammo + // + if ( cent->currentState.weapon ) { + qhandle_t icon; + float scale,halfScale; + float wideOffset; + + value = ps->ammo[BG_FindAmmoForWeapon( cent->currentState.weapon )]; + inclip = ps->ammoclip[BG_FindClipForWeapon( cent->currentState.weapon )]; + + if ( value > -1 ) { + if ( ( cg.predictedPlayerState.weaponstate == WEAPON_FIRING || cg.predictedPlayerState.weaponstate == WEAPON_FIRINGALT ) + && cg.predictedPlayerState.weaponTime > 100 ) { + // draw as dark grey when reloading + color = 2; // dark grey + } else { + if ( value >= 0 ) { + color = 0; // green + } else { + color = 1; // red + } + } + trap_R_SetColor( colors[color] ); + + // pulsing grenade icon to help the player 'count' in their head + if ( ps->grenadeTimeLeft ) { + if ( ps->weapon == WP_DYNAMITE ) { + + } else { + if ( ( ( cg.grenLastTime ) % 1000 ) < ( ( ps->grenadeTimeLeft ) % 1000 ) ) { + switch ( ps->grenadeTimeLeft / 1000 ) { + case 3: + trap_S_StartLocalSound( cgs.media.grenadePulseSound4, CHAN_LOCAL_SOUND ); + break; + case 2: + trap_S_StartLocalSound( cgs.media.grenadePulseSound3, CHAN_LOCAL_SOUND ); + break; + case 1: + trap_S_StartLocalSound( cgs.media.grenadePulseSound2, CHAN_LOCAL_SOUND ); + break; + case 0: + trap_S_StartLocalSound( cgs.media.grenadePulseSound1, CHAN_LOCAL_SOUND ); + break; + } + } + } + + scale = (float)( ( ps->grenadeTimeLeft ) % 1000 ) / 100.0f; + halfScale = scale * 0.5f; + + cg.grenLastTime = ps->grenadeTimeLeft; + } else { + scale = halfScale = 0; + } + + + switch ( cg.predictedPlayerState.weapon ) { + case WP_THOMPSON: + case WP_MP40: + case WP_STEN: + case WP_MAUSER: + case WP_GARAND: + case WP_VENOM: + case WP_TESLA: + case WP_PANZERFAUST: + case WP_FLAMETHROWER: + wideOffset = -38; + break; + default: + wideOffset = 0; + break; + } + + // don't draw ammo value for knife + if ( cg.predictedPlayerState.weapon != WP_KNIFE ) { + if ( cgs.dmflags & DF_NO_WEAPRELOAD ) { + CG_DrawBigString2( ( 580 - 23 + 35 ) + wideOffset, STATUSBARHEIGHT, va( "%d.", value ), cg_hudAlpha.value ); + } else if ( value ) { + CG_DrawBigString2( ( 580 - 23 + 35 ) + wideOffset, STATUSBARHEIGHT, va( "%d/%d", inclip, value ), cg_hudAlpha.value ); + } else { + CG_DrawBigString2( ( 580 - 23 + 35 ) + wideOffset, STATUSBARHEIGHT, va( "%d", inclip ), cg_hudAlpha.value ); + } + } + + icon = cg_weapons[ cg.predictedPlayerState.weapon ].weaponIcon[0]; + if ( icon ) { + CG_DrawPic( ( ( 530 + 68 ) - halfScale ) + wideOffset, ( 446 - 10 ) - halfScale, ( 38 + scale ) - wideOffset, 38 + scale, icon ); + } + + trap_R_SetColor( NULL ); + + // if we didn't draw a 3D icon, draw a 2D icon for ammo + if ( !cg_draw3dIcons.integer ) { + qhandle_t icon; + + icon = cg_weapons[ cg.predictedPlayerState.weapon ].ammoIcon; + if ( icon ) { + CG_DrawPic( CHAR_WIDTH * 3 + TEXT_ICON_SPACE, STATUSBARHEIGHT, ICON_SIZE, ICON_SIZE, icon ); + } + } + } + } + + // + // health + // + value = ps->stats[STAT_HEALTH]; + if ( value > 100 ) { + trap_R_SetColor( colors[3] ); // white + } else if ( value > 25 ) { + trap_R_SetColor( colors[0] ); // green + } else if ( value > 0 ) { + color = ( cg.time >> 8 ) & 1; // flash + trap_R_SetColor( colors[color] ); + } else { + trap_R_SetColor( colors[1] ); // red + } + + // stretch the health up when taking damage +//----(SA) Wolf statusbar change +// CG_DrawField ( 185, STATUSBARHEIGHT, 3, value); + { + char printme[16]; + sprintf( printme, "%d", value ); + //CG_DrawBigString( 185, STATUSBARHEIGHT, printme, cg_hudAlpha.value ); + CG_DrawBigString2( 16 + 23 + 43, STATUSBARHEIGHT, printme, cg_hudAlpha.value ); + } +//----(SA) end + CG_ColorForHealth( hcolor ); + trap_R_SetColor( hcolor ); + + + // + // armor + // + value = ps->stats[STAT_ARMOR]; + if ( value > 0 ) { + trap_R_SetColor( colors[0] ); +//----(SA) Wolf statusbar change +// CG_DrawField (370, STATUSBARHEIGHT, 3, value); + { + char printme[16]; + sprintf( printme, "%d", value ); + //CG_DrawBigString( 370, STATUSBARHEIGHT, printme, cg_hudAlpha.value ); + CG_DrawBigString2( 200, STATUSBARHEIGHT, printme, cg_hudAlpha.value ); + } +//----(SA) end + trap_R_SetColor( NULL ); +//----(SA) Wolf statusbar change +// CG_DrawPic( 370 + CHAR_WIDTH*3 + TEXT_ICON_SPACE, STATUSBARHEIGHT, ICON_SIZE, ICON_SIZE, cgs.media.armorIcon ); +//----(SA) end + } +} +// END JOSEPH +#endif // #ifdef OLDWOLFUI +/* +=========================================================================================== + + UPPER RIGHT CORNER + +=========================================================================================== +*/ + +/* +================ +CG_DrawAttacker + +================ +*/ +#ifdef OLDWOLFUI +static float CG_DrawAttacker( float y ) { + int t; + float size; + vec3_t angles; + const char *info; + const char *name; + int clientNum; + + if ( cg.predictedPlayerState.stats[STAT_HEALTH] <= 0 ) { + return y; + } + + if ( !cg.attackerTime ) { + return y; + } + + clientNum = cg.predictedPlayerState.persistant[PERS_ATTACKER]; + if ( clientNum < 0 || clientNum >= MAX_CLIENTS || clientNum == cg.snap->ps.clientNum ) { + return y; + } + + t = cg.time - cg.attackerTime; + if ( t > ATTACKER_HEAD_TIME ) { + cg.attackerTime = 0; + return y; + } + + size = ICON_SIZE * 1.25; + + angles[PITCH] = 0; + angles[YAW] = 180; + angles[ROLL] = 0; + CG_DrawHead( 640 - size, y, size, size, clientNum, angles ); + + info = CG_ConfigString( CS_PLAYERS + clientNum ); + name = Info_ValueForKey( info, "n" ); + y += size; + CG_DrawBigString( 640 - ( Q_PrintStrlen( name ) * BIGCHAR_WIDTH ), y, name, 0.5 ); + + return y + BIGCHAR_HEIGHT + 2; +} +#endif // #ifdef OLDWOLFUI + +#define UPPERRIGHT_X 500 +/* +================== +CG_DrawSnapshot +================== +*/ +static float CG_DrawSnapshot( float y ) { + char *s; + int w; + + s = va( "time:%i snap:%i cmd:%i", cg.snap->serverTime, + cg.latestSnapshotNum, cgs.serverCommandSequence ); + w = CG_DrawStrlen( s ) * BIGCHAR_WIDTH; + + CG_DrawBigString( UPPERRIGHT_X - w, y + 2, s, 1.0F ); + + return y + BIGCHAR_HEIGHT + 4; +} + +/* +================== +CG_DrawFPS +================== +*/ +#define FPS_FRAMES 4 +static float CG_DrawFPS( float y ) { + char *s; + int w; + static int previousTimes[FPS_FRAMES]; + static int index; + int i, total; + int fps; + static int previous; + int t, frameTime; + + // don't use serverTime, because that will be drifting to + // correct for internet lag changes, timescales, timedemos, etc + t = trap_Milliseconds(); + frameTime = t - previous; + previous = t; + + previousTimes[index % FPS_FRAMES] = frameTime; + index++; + if ( index > FPS_FRAMES ) { + // average multiple frames together to smooth changes out a bit + total = 0; + for ( i = 0 ; i < FPS_FRAMES ; i++ ) { + total += previousTimes[i]; + } + if ( !total ) { + total = 1; + } + fps = 1000 * FPS_FRAMES / total; + + s = va( "%ifps", fps ); + w = CG_DrawStrlen( s ) * BIGCHAR_WIDTH; + + CG_DrawBigString( UPPERRIGHT_X - w, y + 2, s, 1.0F ); + } + + return y + BIGCHAR_HEIGHT + 4; +} + +/* +================= +CG_DrawTimer +================= +*/ +static float CG_DrawTimer( float y ) { + char *s; + int w; + int mins, seconds, tens; + int msec; + + // NERVE - SMF - draw time remaining in multiplayer + if ( cgs.gametype == GT_WOLF ) { + msec = ( cgs.timelimit * 60.f * 1000.f ) - ( cg.time - cgs.levelStartTime ); + } else { + msec = cg.time - cgs.levelStartTime; + } + // -NERVE - SMF + + seconds = msec / 1000; + mins = seconds / 60; + seconds -= mins * 60; + tens = seconds / 10; + seconds -= tens * 10; + + s = va( "%i:%i%i", mins, tens, seconds ); + w = CG_DrawStrlen( s ) * BIGCHAR_WIDTH; + + CG_DrawBigString( UPPERRIGHT_X - w, y + 2, s, 1.0F ); + + return y + BIGCHAR_HEIGHT + 4; +} + + +/* +================= +CG_DrawTeamOverlay +================= +*/ + +// set in CG_ParseTeamInfo +int sortedTeamPlayers[TEAM_MAXOVERLAY]; +int numSortedTeamPlayers; + +#define TEAM_OVERLAY_MAXNAME_WIDTH 16 +#define TEAM_OVERLAY_MAXLOCATION_WIDTH 20 + +static float CG_DrawTeamOverlay( float y ) { + int x, w, h, xx; + int i, j, len; + const char *p; + vec4_t hcolor; + int pwidth, lwidth; + int plyrs; + char st[16]; + clientInfo_t *ci; + + if ( !cg_drawTeamOverlay.integer ) { + return y; + } + + if ( cg.snap->ps.persistant[PERS_TEAM] != TEAM_RED && + cg.snap->ps.persistant[PERS_TEAM] != TEAM_BLUE ) { + return y; // Not on any team + + } + plyrs = 0; + + // max player name width + pwidth = 0; + for ( i = 0; i < numSortedTeamPlayers; i++ ) { + ci = cgs.clientinfo + sortedTeamPlayers[i]; + if ( ci->infoValid && ci->team == cg.snap->ps.persistant[PERS_TEAM] ) { + plyrs++; + len = CG_DrawStrlen( cgs.clientinfo[i].name ); + if ( len > pwidth ) { + pwidth = len; + } + } + } + + if ( !plyrs ) { + return y; + } + + if ( pwidth > TEAM_OVERLAY_MAXNAME_WIDTH ) { + pwidth = TEAM_OVERLAY_MAXNAME_WIDTH; + } + +#if 0 + // max location name width + lwidth = 0; + for ( i = 0; i < numSortedTeamPlayers; i++ ) { + ci = cgs.clientinfo + sortedTeamPlayers[i]; + if ( ci->infoValid && + ci->team == cg.snap->ps.persistant[PERS_TEAM] && + CG_ConfigString( CS_LOCATIONS + ci->location ) ) { + len = CG_DrawStrlen( CG_ConfigString( CS_LOCATIONS + ci->location ) ); + if ( len > lwidth ) { + lwidth = len; + } + } + } +#else + // max location name width + lwidth = 0; + for ( i = 1; i < MAX_LOCATIONS; i++ ) { + p = CG_ConfigString( CS_LOCATIONS + i ); + if ( p && *p ) { + len = CG_DrawStrlen( p ); + if ( len > lwidth ) { + lwidth = len; + } + } + } +#endif + + if ( lwidth > TEAM_OVERLAY_MAXLOCATION_WIDTH ) { + lwidth = TEAM_OVERLAY_MAXLOCATION_WIDTH; + } + + w = ( pwidth + lwidth + 4 + 7 ) * TINYCHAR_WIDTH; + x = 640 - w - 32; + h = plyrs * TINYCHAR_HEIGHT; + + if ( cg.snap->ps.persistant[PERS_TEAM] == TEAM_RED ) { + hcolor[0] = 1; + hcolor[1] = 0; + hcolor[2] = 0; + hcolor[3] = 0.33; + } else { // if ( cg.snap->ps.persistant[PERS_TEAM] == TEAM_BLUE ) + hcolor[0] = 0; + hcolor[1] = 0; + hcolor[2] = 1; + hcolor[3] = 0.33; + } + trap_R_SetColor( hcolor ); + CG_DrawPic( x, y, w, h, cgs.media.teamStatusBar ); + trap_R_SetColor( NULL ); + + + for ( i = 0; i < numSortedTeamPlayers; i++ ) { + ci = cgs.clientinfo + sortedTeamPlayers[i]; + if ( ci->infoValid && ci->team == cg.snap->ps.persistant[PERS_TEAM] ) { + + hcolor[0] = hcolor[1] = hcolor[2] = hcolor[3] = 1.0; + + xx = x + TINYCHAR_WIDTH; + + CG_DrawStringExt( xx, y, + ci->name, hcolor, qfalse, qfalse, + TINYCHAR_WIDTH, TINYCHAR_HEIGHT, TEAM_OVERLAY_MAXNAME_WIDTH ); + + if ( lwidth ) { + p = CG_ConfigString( CS_LOCATIONS + ci->location ); + if ( !p || !*p ) { + p = "unknown"; + } + len = CG_DrawStrlen( p ); + if ( len > lwidth ) { + len = lwidth; + } + + xx = x + TINYCHAR_WIDTH * 2 + TINYCHAR_WIDTH * pwidth + + ( ( lwidth / 2 - len / 2 ) * TINYCHAR_WIDTH ); + CG_DrawStringExt( xx, y, + p, hcolor, qfalse, qfalse, TINYCHAR_WIDTH, TINYCHAR_HEIGHT, + TEAM_OVERLAY_MAXLOCATION_WIDTH ); + } + + CG_ColorForHealth( hcolor ); + + Com_sprintf( st, sizeof( st ), "%3i %3i", ci->health, ci->armor ); + + xx = x + TINYCHAR_WIDTH * 3 + + TINYCHAR_WIDTH * pwidth + TINYCHAR_WIDTH * lwidth; + + CG_DrawStringExt( xx, y, + st, hcolor, qfalse, qfalse, + TINYCHAR_WIDTH, TINYCHAR_HEIGHT, 0 ); + + // draw weapon icon + xx += TINYCHAR_WIDTH * 3; + + CG_DrawPic( xx, y, TINYCHAR_WIDTH, TINYCHAR_HEIGHT, + cg_weapons[ci->curWeapon].weaponIcon[0] ); + + // Draw powerup icons + xx = x; + for ( j = 0; j < PW_NUM_POWERUPS; j++ ) { + if ( ci->powerups & ( 1 << j ) ) { + gitem_t *item; + + item = BG_FindItemForPowerup( j ); + + if ( item != NULL ) { // JPW NERVE added for invulnerability powerup at beginning of map + CG_DrawPic( xx, y, TINYCHAR_WIDTH, TINYCHAR_HEIGHT, + trap_R_RegisterShader( item->icon ) ); + xx -= TINYCHAR_WIDTH; + } // jpw + } + } + + y += TINYCHAR_HEIGHT; + } + } + + return y; +} + + +/* +===================== +CG_DrawUpperRight + +===================== +*/ +static void CG_DrawUpperRight( void ) { + float y; + + y = 0; + + if ( cgs.gametype >= GT_TEAM ) { + y = CG_DrawTeamOverlay( y ); + } + if ( cg_drawSnapshot.integer ) { + y = CG_DrawSnapshot( y ); + } + if ( cg_drawFPS.integer ) { + y = CG_DrawFPS( y ); + } + if ( cg_drawTimer.integer ) { + y = CG_DrawTimer( y ); + } +// (SA) disabling drawattacker for the time being +// if ( cg_drawAttacker.integer ) { +// y = CG_DrawAttacker( y ); +// } +//----(SA) end +} + +/* +=========================================================================================== + + LOWER RIGHT CORNER + +=========================================================================================== +*/ + +/* +================= +CG_DrawScores + +Draw the small two score display +================= +*/ +#ifdef OLDWOLFUI +static float CG_DrawScores( float y ) { + const char *s; + int s1, s2, score; + int x, w; + int v; + vec4_t color; + + s = CG_ConfigString( CS_SCORES1 ); + s1 = cgs.scores1; + s = CG_ConfigString( CS_SCORES2 ); + s2 = cgs.scores2; + + y -= BIGCHAR_HEIGHT + 8; + + // draw from the right side to left + if ( cgs.gametype >= GT_TEAM ) { + x = 640; + + color[0] = 0; + color[1] = 0; + color[2] = 1; + color[3] = 0.33; + s = va( "%2i", s2 ); + w = CG_DrawStrlen( s ) * BIGCHAR_WIDTH + 8; + x -= w; + CG_FillRect( x, y - 4, w, BIGCHAR_HEIGHT + 8, color ); + if ( cg.snap->ps.persistant[PERS_TEAM] == TEAM_BLUE ) { + CG_DrawPic( x, y - 4, w, BIGCHAR_HEIGHT + 8, cgs.media.selectShader ); + } + CG_DrawBigString( x + 4, y, s, 1.0F ); + + + color[0] = 1; + color[1] = 0; + color[2] = 0; + color[3] = 0.33; + s = va( "%2i", s1 ); + w = CG_DrawStrlen( s ) * BIGCHAR_WIDTH + 8; + x -= w; + CG_FillRect( x, y - 4, w, BIGCHAR_HEIGHT + 8, color ); + if ( cg.snap->ps.persistant[PERS_TEAM] == TEAM_RED ) { + CG_DrawPic( x, y - 4, w, BIGCHAR_HEIGHT + 8, cgs.media.selectShader ); + } + CG_DrawBigString( x + 4, y, s, 1.0F ); + + if ( cgs.gametype == GT_CTF ) { + v = cgs.capturelimit; + } else { + v = cgs.fraglimit; + } + if ( v ) { + s = va( "%2i", v ); + w = CG_DrawStrlen( s ) * BIGCHAR_WIDTH + 8; + x -= w; + CG_DrawBigString( x + 4, y, s, 1.0F ); + } + +//----(SA) don't show frag count/limit in sp + } else if ( cgs.gametype != GT_SINGLE_PLAYER && cg_drawFrags.integer ) { +//----(SA) end + qboolean spectator; + + x = 640; + score = cg.snap->ps.persistant[PERS_SCORE]; + spectator = ( cg.snap->ps.persistant[PERS_TEAM] == TEAM_SPECTATOR ); + + // always show your score in the second box if not in first place + if ( s1 != score ) { + s2 = score; + } + if ( s2 != SCORE_NOT_PRESENT ) { + s = va( "%2i", s2 ); + w = CG_DrawStrlen( s ) * BIGCHAR_WIDTH + 8; + x -= w; + if ( !spectator && score == s2 && score != s1 ) { + color[0] = 1; + color[1] = 0; + color[2] = 0; + color[3] = 0.33; + CG_FillRect( x, y - 4, w, BIGCHAR_HEIGHT + 8, color ); + CG_DrawPic( x, y - 4, w, BIGCHAR_HEIGHT + 8, cgs.media.selectShader ); + } else { + color[0] = 0.5; + color[1] = 0.5; + color[2] = 0.5; + color[3] = 0.33; + CG_FillRect( x, y - 4, w, BIGCHAR_HEIGHT + 8, color ); + } + CG_DrawBigString( x + 4, y, s, 1.0F ); + } + + // first place + if ( s1 != SCORE_NOT_PRESENT ) { + s = va( "%2i", s1 ); + w = CG_DrawStrlen( s ) * BIGCHAR_WIDTH + 8; + x -= w; + if ( !spectator && score == s1 ) { + color[0] = 0; + color[1] = 0; + color[2] = 1; + color[3] = 0.33; + CG_FillRect( x, y - 4, w, BIGCHAR_HEIGHT + 8, color ); + CG_DrawPic( x, y - 4, w, BIGCHAR_HEIGHT + 8, cgs.media.selectShader ); + } else { + color[0] = 0.5; + color[1] = 0.5; + color[2] = 0.5; + color[3] = 0.33; + CG_FillRect( x, y - 4, w, BIGCHAR_HEIGHT + 8, color ); + } + CG_DrawBigString( x + 4, y, s, 1.0F ); + } + + if ( cgs.fraglimit ) { + s = va( "%2i", cgs.fraglimit ); + w = CG_DrawStrlen( s ) * BIGCHAR_WIDTH + 8; + x -= w; + CG_DrawBigString( x + 4, y, s, 1.0F ); + } + + } + + return y - 8; +} +#endif // #ifdef OLDWOLFUI + +/* +================ +CG_DrawPowerups +================ +*/ +#ifdef OLDWOLFUI +static float CG_DrawPowerups( float y ) { + int sorted[MAX_POWERUPS]; + int sortedTime[MAX_POWERUPS]; + int i, j, k; + int active; + playerState_t *ps; + int t; + gitem_t *item; + int x; + int color; + float size; + float f; + static float colors[2][4] = { + { 0.2, 1.0, 0.2, 1.0 }, { 1.0, 0.2, 0.2, 1.0 } + }; + + ps = &cg.snap->ps; + + if ( ps->stats[STAT_HEALTH] <= 0 ) { + return y; + } + + // sort the list by time remaining + active = 0; + for ( i = 0 ; i < MAX_POWERUPS ; i++ ) { + if ( !ps->powerups[ i ] ) { + continue; + } + t = ps->powerups[ i ] - cg.time; + // ZOID--don't draw if the power up has unlimited time (999 seconds) + // This is true of the CTF flags + if ( t < 0 || t > 999000 ) { + continue; + } + + // insert into the list + for ( j = 0 ; j < active ; j++ ) { + if ( sortedTime[j] >= t ) { + for ( k = active - 1 ; k >= j ; k-- ) { + sorted[k + 1] = sorted[k]; + sortedTime[k + 1] = sortedTime[k]; + } + break; + } + } + sorted[j] = i; + sortedTime[j] = t; + active++; + } + + // draw the icons and timers + x = 640 - ICON_SIZE - CHAR_WIDTH * 2; + for ( i = 0 ; i < active ; i++ ) { + + continue; // (SA) FIXME: TEMP: as I'm getting powerup business going + + item = BG_FindItemForPowerup( sorted[i] ); + + color = 1; + + y -= ICON_SIZE; + + trap_R_SetColor( colors[color] ); + CG_DrawField( x, y, 2, sortedTime[ i ] / 1000 ); + + t = ps->powerups[ sorted[i] ]; + if ( t - cg.time >= POWERUP_BLINKS * POWERUP_BLINK_TIME ) { + trap_R_SetColor( NULL ); + } else { + vec4_t modulate; + + f = (float)( t - cg.time ) / POWERUP_BLINK_TIME; + f -= (int)f; + modulate[0] = modulate[1] = modulate[2] = modulate[3] = f; + trap_R_SetColor( modulate ); + } + + if ( cg.powerupActive == sorted[i] && + cg.time - cg.powerupTime < PULSE_TIME ) { + f = 1.0 - ( ( (float)cg.time - cg.powerupTime ) / PULSE_TIME ); + size = ICON_SIZE * ( 1.0 + ( PULSE_SCALE - 1.0 ) * f ); + } else { + size = ICON_SIZE; + } + + CG_DrawPic( 640 - size, y + ICON_SIZE / 2 - size / 2, + size, size, trap_R_RegisterShader( item->icon ) ); + } + trap_R_SetColor( NULL ); + + return y; +} +#endif // #ifdef OLDWOLFUI + + +/* +===================== +CG_DrawLowerRight + +===================== +*/ +#ifdef OLDWOLFUI +static void CG_DrawLowerRight( void ) { + float y; + + y = 480 - ICON_SIZE; + + y = CG_DrawScores( y ); + y = CG_DrawPowerups( y ); +} +#endif // #ifdef OLDWOLFUI + +//=========================================================================================== + +/* +================= +CG_DrawTeamInfo +================= +*/ +static void CG_DrawTeamInfo( void ) { + int w, h; + int i, len; + vec4_t hcolor; + int chatHeight; + +#define CHATLOC_Y 420 // bottom end +#define CHATLOC_X 0 + + if ( cg_teamChatHeight.integer < TEAMCHAT_HEIGHT ) { + chatHeight = cg_teamChatHeight.integer; + } else { + chatHeight = TEAMCHAT_HEIGHT; + } + if ( chatHeight <= 0 ) { + return; // disabled + + } + if ( cgs.teamLastChatPos != cgs.teamChatPos ) { + if ( cg.time - cgs.teamChatMsgTimes[cgs.teamLastChatPos % chatHeight] > cg_teamChatTime.integer ) { + cgs.teamLastChatPos++; + } + + h = ( cgs.teamChatPos - cgs.teamLastChatPos ) * TINYCHAR_HEIGHT; + + w = 0; + + for ( i = cgs.teamLastChatPos; i < cgs.teamChatPos; i++ ) { + len = CG_DrawStrlen( cgs.teamChatMsgs[i % chatHeight] ); + if ( len > w ) { + w = len; + } + } + w *= TINYCHAR_WIDTH; + w += TINYCHAR_WIDTH * 2; + + if ( cg.snap->ps.persistant[PERS_TEAM] == TEAM_RED ) { + hcolor[0] = 1; + hcolor[1] = 0; + hcolor[2] = 0; + hcolor[3] = 0.33; + } else if ( cg.snap->ps.persistant[PERS_TEAM] == TEAM_BLUE ) { + hcolor[0] = 0; + hcolor[1] = 0; + hcolor[2] = 1; + hcolor[3] = 0.33; + } else { + hcolor[0] = 0; + hcolor[1] = 1; + hcolor[2] = 0; + hcolor[3] = 0.33; + } + + trap_R_SetColor( hcolor ); + CG_DrawPic( CHATLOC_X, CHATLOC_Y - h, 640, h, cgs.media.teamStatusBar ); + trap_R_SetColor( NULL ); + + hcolor[0] = hcolor[1] = hcolor[2] = 1.0; + hcolor[3] = 1.0; + + for ( i = cgs.teamChatPos - 1; i >= cgs.teamLastChatPos; i-- ) { + CG_DrawStringExt( CHATLOC_X + TINYCHAR_WIDTH, + CHATLOC_Y - ( cgs.teamChatPos - i ) * TINYCHAR_HEIGHT, + cgs.teamChatMsgs[i % chatHeight], hcolor, qfalse, qfalse, + TINYCHAR_WIDTH, TINYCHAR_HEIGHT, 0 ); +// CG_DrawSmallString( CHATLOC_X + SMALLCHAR_WIDTH, +// CHATLOC_Y - (cgs.teamChatPos - i)*SMALLCHAR_HEIGHT, +// cgs.teamChatMsgs[i % TEAMCHAT_HEIGHT], 1.0F ); + } + } +} + +//----(SA) modified +/* +=================== +CG_DrawPickupItem +=================== +*/ +static void CG_DrawPickupItem( void ) { + int value; + float *fadeColor; + char pickupText[256]; + float color[4]; + + value = cg.itemPickup; + if ( value ) { + fadeColor = CG_FadeColor( cg.itemPickupTime, 3000 ); + if ( fadeColor ) { + CG_RegisterItemVisuals( value ); + +//----(SA) commented out +// trap_R_SetColor( fadeColor ); +// CG_DrawPic( 8, 380, ICON_SIZE, ICON_SIZE, cg_items[ value ].icon ); +//----(SA) end + + //----(SA) so we don't pick up all sorts of items and have it print "0 " + if ( bg_itemlist[ value ].giType == IT_AMMO || bg_itemlist[ value ].giType == IT_HEALTH || bg_itemlist[value].giType == IT_POWERUP ) { + if ( bg_itemlist[ value ].world_model[2] ) { // this is a multi-stage item + // FIXME: print the correct amount for multi-stage + Com_sprintf( pickupText, sizeof( pickupText ), "%s", cgs.itemPrintNames[ value ] ); + } else { + if ( bg_itemlist[ value ].gameskillnumber[cg_gameSkill.integer] > 1 ) { + Com_sprintf( pickupText, sizeof( pickupText ), "%i %s", bg_itemlist[ value ].gameskillnumber[cg_gameSkill.integer], cgs.itemPrintNames[ value ] ); + } else { + Com_sprintf( pickupText, sizeof( pickupText ), "%s", cgs.itemPrintNames[value] ); + } + } + } else { + Com_sprintf( pickupText, sizeof( pickupText ), "%s", cgs.itemPrintNames[value] ); + } + + //----(SA) trying smaller text + color[0] = color[1] = color[2] = 1.0; + color[3] = fadeColor[0]; + CG_DrawStringExt2( ICON_SIZE + 16, 398, pickupText, color, qfalse, qtrue, 10, 10, 0 ); +// CG_Text_Paint(ICON_SIZE + 16, 398, 2, 0.3f, color, pickupText, 0, 0, ITEM_TEXTSTYLE_SHADOWEDMORE); + + + trap_R_SetColor( NULL ); + } + } +} +//----(SA) end + + +/* +=================== +CG_DrawHoldableItem +=================== +*/ +void CG_DrawHoldableItem_old( void ) { + int value; + gitem_t *item; + + if ( !cg.holdableSelect ) { + return; + } + + item = BG_FindItemForHoldable( cg.holdableSelect ); + + if ( !item ) { + return; + } + + value = cg.predictedPlayerState.holdable[cg.holdableSelect]; + + if ( value ) { + + trap_R_SetColor( NULL ); + + CG_RegisterItemVisuals( item - bg_itemlist ); + + if ( cg.holdableSelect == HI_WINE ) { + if ( value > 3 ) { + value = 3; // 3 stages to icon, just draw full if beyond 'full' + + } + //----(SA) trying smaller text + //----(SA) and off to the right side of the HUD +// CG_DrawPic( 100, (SCREEN_HEIGHT-ICON_SIZE)-8, ICON_SIZE/2, ICON_SIZE, cg_items[item - bg_itemlist].icons[2-(value-1)] ); + CG_DrawPic( 606, 366, 24, 48, cg_items[item - bg_itemlist].icons[2 - ( value - 1 )] ); + + } else { +// CG_DrawPic( 100, (SCREEN_HEIGHT-ICON_SIZE)-8, ICON_SIZE/2, ICON_SIZE, cg_items[item - bg_itemlist].icons[0] ); + CG_DrawPic( 606, 366, 24, 48, cg_items[item - bg_itemlist].icons[0] ); + + } + + // draw the selection box so it's not just floating in space + CG_DrawPic( 606 - 4, 366 - 4, 32, 56, cgs.media.selectShader ); + } +} +/* + if(cg.holdableSelect == HI_WINE) { + if(value > 3) + value = 3; // 3 stages to icon, just draw full if beyond 'full' + + CG_DrawPic( 598 + 16, 366, 16, 32, cg_items[item - bg_itemlist].icons[2-(value-1)] ); + CG_DrawPic( (598 + 16)-4, 366-4, 24, 40, cgs.media.selectShader ); + + } else { + CG_DrawPic( 598, 366, 32, 32, cg_items[item - bg_itemlist].icons[0] ); + CG_DrawPic( 598-4, 366-4, 40, 40, cgs.media.selectShader ); + } +*/ + +/* +=================== +CG_DrawReward +=================== +*/ +static void CG_DrawReward( void ) { + float *color; + int i; + float x, y; + + if ( !cg_drawRewards.integer ) { + return; + } + color = CG_FadeColor( cg.rewardTime, REWARD_TIME ); + if ( !color ) { + return; + } + + trap_R_SetColor( color ); + y = 56; + x = 320 - cg.rewardCount * ICON_SIZE / 2; + for ( i = 0 ; i < cg.rewardCount ; i++ ) { + CG_DrawPic( x, y, ICON_SIZE - 4, ICON_SIZE - 4, cg.rewardShader ); + x += ICON_SIZE; + } + trap_R_SetColor( NULL ); +} + + +/* +=============================================================================== + +LAGOMETER + +=============================================================================== +*/ + +#define LAG_SAMPLES 128 + + +typedef struct { + int frameSamples[LAG_SAMPLES]; + int frameCount; + int snapshotFlags[LAG_SAMPLES]; + int snapshotSamples[LAG_SAMPLES]; + int snapshotCount; +} lagometer_t; + +lagometer_t lagometer; + +/* +============== +CG_AddLagometerFrameInfo + +Adds the current interpolate / extrapolate bar for this frame +============== +*/ +void CG_AddLagometerFrameInfo( void ) { + int offset; + + offset = cg.time - cg.latestSnapshotTime; + lagometer.frameSamples[ lagometer.frameCount & ( LAG_SAMPLES - 1 ) ] = offset; + lagometer.frameCount++; +} + +/* +============== +CG_AddLagometerSnapshotInfo + +Each time a snapshot is received, log its ping time and +the number of snapshots that were dropped before it. + +Pass NULL for a dropped packet. +============== +*/ +void CG_AddLagometerSnapshotInfo( snapshot_t *snap ) { + // dropped packet + if ( !snap ) { + lagometer.snapshotSamples[ lagometer.snapshotCount & ( LAG_SAMPLES - 1 ) ] = -1; + lagometer.snapshotCount++; + return; + } + + // add this snapshot's info + lagometer.snapshotSamples[ lagometer.snapshotCount & ( LAG_SAMPLES - 1 ) ] = snap->ping; + lagometer.snapshotFlags[ lagometer.snapshotCount & ( LAG_SAMPLES - 1 ) ] = snap->snapFlags; + lagometer.snapshotCount++; +} + +/* +============== +CG_DrawDisconnect + +Should we draw something differnet for long lag vs no packets? +============== +*/ +static void CG_DrawDisconnect( void ) { + float x, y; + int cmdNum; + usercmd_t cmd; + const char *s; + int w; // bk010215 - FIXME char message[1024]; + + // draw the phone jack if we are completely past our buffers + cmdNum = trap_GetCurrentCmdNumber() - CMD_BACKUP + 1; + trap_GetUserCmd( cmdNum, &cmd ); + if ( cmd.serverTime <= cg.snap->ps.commandTime + || cmd.serverTime > cg.time ) { // special check for map_restart // bk 0102165 - FIXME + return; + } + + // also add text in center of screen + s = "Connection Interrupted"; // bk 010215 - FIXME + w = CG_DrawStrlen( s ) * BIGCHAR_WIDTH; + CG_DrawBigString( 320 - w / 2, 100, s, 1.0F ); + + // blink the icon + if ( ( cg.time >> 9 ) & 1 ) { + return; + } + + x = 640 - 48; + y = 480 - 48; + + CG_DrawPic( x, y, 48, 48, trap_R_RegisterShader( "gfx/2d/net.tga" ) ); +} + + +#define MAX_LAGOMETER_PING 900 +#define MAX_LAGOMETER_RANGE 300 + +/* +============== +CG_DrawLagometer +============== +*/ +static void CG_DrawLagometer( void ) { + int a, x, y, i; + float v; + float ax, ay, aw, ah, mid, range; + int color; + float vscale; + + if ( !cg_lagometer.integer || cgs.localServer ) { +// if(0) { + CG_DrawDisconnect(); + return; + } + + // + // draw the graph + // + x = 640 - 48; + y = 480 - 48; + + trap_R_SetColor( NULL ); + CG_DrawPic( x, y, 48, 48, cgs.media.lagometerShader ); + + ax = x; + ay = y; + aw = 48; + ah = 48; + CG_AdjustFrom640( &ax, &ay, &aw, &ah ); + + color = -1; + range = ah / 3; + mid = ay + range; + + vscale = range / MAX_LAGOMETER_RANGE; + + // draw the frame interpoalte / extrapolate graph + for ( a = 0 ; a < aw ; a++ ) { + i = ( lagometer.frameCount - 1 - a ) & ( LAG_SAMPLES - 1 ); + v = lagometer.frameSamples[i]; + v *= vscale; + if ( v > 0 ) { + if ( color != 1 ) { + color = 1; + trap_R_SetColor( g_color_table[ColorIndex( COLOR_YELLOW )] ); + } + if ( v > range ) { + v = range; + } + trap_R_DrawStretchPic( ax + aw - a, mid - v, 1, v, 0, 0, 0, 0, cgs.media.whiteShader ); + } else if ( v < 0 ) { + if ( color != 2 ) { + color = 2; + trap_R_SetColor( g_color_table[ColorIndex( COLOR_BLUE )] ); + } + v = -v; + if ( v > range ) { + v = range; + } + trap_R_DrawStretchPic( ax + aw - a, mid, 1, v, 0, 0, 0, 0, cgs.media.whiteShader ); + } + } + + // draw the snapshot latency / drop graph + range = ah / 2; + vscale = range / MAX_LAGOMETER_PING; + + for ( a = 0 ; a < aw ; a++ ) { + i = ( lagometer.snapshotCount - 1 - a ) & ( LAG_SAMPLES - 1 ); + v = lagometer.snapshotSamples[i]; + if ( v > 0 ) { + if ( lagometer.snapshotFlags[i] & SNAPFLAG_RATE_DELAYED ) { + if ( color != 5 ) { + color = 5; // YELLOW for rate delay + trap_R_SetColor( g_color_table[ColorIndex( COLOR_YELLOW )] ); + } + } else { + if ( color != 3 ) { + color = 3; + trap_R_SetColor( g_color_table[ColorIndex( COLOR_GREEN )] ); + } + } + v = v * vscale; + if ( v > range ) { + v = range; + } + trap_R_DrawStretchPic( ax + aw - a, ay + ah - v, 1, v, 0, 0, 0, 0, cgs.media.whiteShader ); + } else if ( v < 0 ) { + if ( color != 4 ) { + color = 4; // RED for dropped snapshots + trap_R_SetColor( g_color_table[ColorIndex( COLOR_RED )] ); + } + trap_R_DrawStretchPic( ax + aw - a, ay + ah - range, 1, range, 0, 0, 0, 0, cgs.media.whiteShader ); + } + } + + trap_R_SetColor( NULL ); + + if ( cg_nopredict.integer || cg_synchronousClients.integer ) { + CG_DrawBigString( ax, ay, "snc", 1.0 ); + } + + CG_DrawDisconnect(); +} + + +/* +=============================================================================== + +CENTER PRINTING + +=============================================================================== +*/ + +/* +============== +CG_CenterPrint + +Called for important messages that should stay in the center of the screen +for a few moments +============== +*/ +void CG_CenterPrint( const char *str, int y, int charWidth ) { + /*unsigned*/ char *s;/*SEB*/ + +//----(SA) added translation lookup + Q_strncpyz( cg.centerPrint, CG_translateString( (char*)str ), sizeof( cg.centerPrint ) ); +//----(SA) end + + + cg.centerPrintTime = cg.time; + cg.centerPrintY = y; + cg.centerPrintCharWidth = charWidth; + + // count the number of lines for centering + cg.centerPrintLines = 1; + s = cg.centerPrint; + while ( *s ) { + if ( *s == '\n' ) { + cg.centerPrintLines++; + } + if ( !Q_strncmp( s, "\\n", 1 ) ) { + cg.centerPrintLines++; + s++; + } + s++; + } +} + + +/* +=================== +CG_DrawCenterString +=================== +*/ +static void CG_DrawCenterString( void ) { + char *start; + int l; + int x, y, w; + float *color; + + if ( !cg.centerPrintTime ) { + return; + } + + color = CG_FadeColor( cg.centerPrintTime, 1000 * cg_centertime.value ); + if ( !color ) { + return; + } + + trap_R_SetColor( color ); + + start = cg.centerPrint; + + y = cg.centerPrintY - cg.centerPrintLines * BIGCHAR_HEIGHT / 2; + + while ( 1 ) { + char linebuffer[1024]; + + for ( l = 0; l < 40; l++ ) { + if ( !start[l] || start[l] == '\n' || !Q_strncmp( &start[l], "\\n", 1 ) ) { + break; + } + linebuffer[l] = start[l]; + } + linebuffer[l] = 0; + + w = cg.centerPrintCharWidth * CG_DrawStrlen( linebuffer ); + + x = ( SCREEN_WIDTH - w ) / 2; + + CG_DrawStringExt( x, y, linebuffer, color, qfalse, qtrue, cg.centerPrintCharWidth, (int)( cg.centerPrintCharWidth * 1.5 ), 0 ); +// CG_Text_Paint(x, y, 2, 0.3f, color, linebuffer, 0, 0, ITEM_TEXTSTYLE_SHADOWEDMORE); + +// y += cg.centerPrintCharWidth * 1.5; + y += cg.centerPrintCharWidth * 2; + +// while ( *start && ( *start != '\n' ) && !Q_strncmp(start, "\\n", 1) ) { + while ( *start && ( *start != '\n' ) ) { + if ( !Q_strncmp( start, "\\n", 1 ) ) { + start++; + break; + } + start++; + } + if ( !*start ) { + break; + } + start++; + } + + trap_R_SetColor( NULL ); +} + + + +/* +================================================================================ + +CROSSHAIRS + +================================================================================ +*/ + + +/* +============== +CG_DrawWeapReticle +============== +*/ +static void CG_DrawWeapReticle( void ) { + int weap; + vec4_t color = {0, 0, 0, 1}; + //vec4_t snoopercolor = {0.7, .8, 0.7, 0}; // greenish + vec4_t snoopercolor = {0.7, .8, 0.7, 1}; // greenish + + float snooperBrightness; + float x = 80, y, w = 240, h = 240; + + CG_AdjustFrom640( &x, &y, &w, &h ); + + weap = cg.weaponSelect; + + // DHM - Nerve :: So that we will draw reticle + if ( cgs.gametype == GT_WOLF && cg.snap->ps.pm_flags & PMF_FOLLOW ) { + weap = cg.snap->ps.weapon; + } + + + if ( weap == WP_SNIPERRIFLE ) { + + + // sides + CG_FillRect( 0, 0, 80, 480, color ); + CG_FillRect( 560, 0, 80, 480, color ); + + // center + if ( cgs.media.reticleShaderSimpleQ ) { + trap_R_DrawStretchPic( x, 0, w, h, 0, 0, 1, 1, cgs.media.reticleShaderSimpleQ ); // tl + trap_R_DrawStretchPic( x + w, 0, w, h, 1, 0, 0, 1, cgs.media.reticleShaderSimpleQ ); // tr + trap_R_DrawStretchPic( x, h, w, h, 0, 1, 1, 0, cgs.media.reticleShaderSimpleQ ); // bl + trap_R_DrawStretchPic( x + w, h, w, h, 1, 1, 0, 0, cgs.media.reticleShaderSimpleQ ); // br + } + + // hairs + CG_FillRect( 84, 239, 177, 2, color ); // left + CG_FillRect( 320, 242, 1, 58, color ); // center top + CG_FillRect( 319, 300, 2, 178, color ); // center bot + CG_FillRect( 380, 239, 177, 2, color ); // right + } else if ( weap == WP_SNOOPERSCOPE ) { + // sides + CG_FillRect( 0, 0, 80, 480, color ); + CG_FillRect( 560, 0, 80, 480, color ); + + // center + +//----(SA) added + // DM didn't like how bright it gets + snooperBrightness = Com_Clamp( 0.0f, 1.0f, cg_reticleBrightness.value ); + snoopercolor[0] *= snooperBrightness; + snoopercolor[1] *= snooperBrightness; + snoopercolor[2] *= snooperBrightness; + trap_R_SetColor( snoopercolor ); +//----(SA) end + + if ( cgs.media.snooperShaderSimple ) { + CG_DrawPic( 80, 0, 480, 480, cgs.media.snooperShaderSimple ); + } + + // hairs + + CG_FillRect( 310, 120, 20, 1, color ); // ----- + CG_FillRect( 300, 160, 40, 1, color ); // ------------- + CG_FillRect( 310, 200, 20, 1, color ); // ----- + + CG_FillRect( 140, 239, 360, 1, color ); // horiz --------------------------- + + CG_FillRect( 310, 280, 20, 1, color ); // ----- + CG_FillRect( 300, 320, 40, 1, color ); // ------------- + CG_FillRect( 310, 360, 20, 1, color ); // ----- + + + + CG_FillRect( 400, 220, 1, 40, color ); // l + + CG_FillRect( 319, 60, 1, 360, color ); // vert + + CG_FillRect( 240, 220, 1, 40, color ); // r + } else if ( weap == WP_FG42SCOPE ) { + // sides + CG_FillRect( 0, 0, 80, 480, color ); + CG_FillRect( 560, 0, 80, 480, color ); + + // center + if ( cgs.media.reticleShaderSimpleQ ) { + trap_R_DrawStretchPic( x, 0, w, h, 0, 0, 1, 1, cgs.media.reticleShaderSimpleQ ); // tl + trap_R_DrawStretchPic( x + w, 0, w, h, 1, 0, 0, 1, cgs.media.reticleShaderSimpleQ ); // tr + trap_R_DrawStretchPic( x, h, w, h, 0, 1, 1, 0, cgs.media.reticleShaderSimpleQ ); // bl + trap_R_DrawStretchPic( x + w, h, w, h, 1, 1, 0, 0, cgs.media.reticleShaderSimpleQ ); // br + } + + // hairs + CG_FillRect( 84, 239, 150, 3, color ); // left + CG_FillRect( 234, 240, 173, 1, color ); // horiz center + CG_FillRect( 407, 239, 150, 3, color ); // right + + + CG_FillRect( 319, 2, 3, 151, color ); // top center top + CG_FillRect( 320, 153, 1, 114, color ); // top center bot + + CG_FillRect( 320, 241, 1, 87, color ); // bot center top + CG_FillRect( 319, 327, 3, 151, color ); // bot center bot + } +} + + +//----(SA) removed (9/8/2001) + +/* +============== +CG_DrawBinocReticle +============== +*/ +static void CG_DrawBinocReticle( void ) { + // an alternative. This gives nice sharp lines at the expense of a few extra polys + vec4_t color = {0, 0, 0, 1}; + float x, y, w = 320, h = 240; + + if ( cgs.media.binocShaderSimpleQ ) { + CG_AdjustFrom640( &x, &y, &w, &h ); + trap_R_DrawStretchPic( 0, 0, w, h, 0, 0, 1, 1, cgs.media.binocShaderSimpleQ ); // tl + trap_R_DrawStretchPic( w, 0, w, h, 1, 0, 0, 1, cgs.media.binocShaderSimpleQ ); // tr + trap_R_DrawStretchPic( 0, h, w, h, 0, 1, 1, 0, cgs.media.binocShaderSimpleQ ); // bl + trap_R_DrawStretchPic( w, h, w, h, 1, 1, 0, 0, cgs.media.binocShaderSimpleQ ); // br + } + + CG_FillRect( 146, 239, 348, 1, color ); + + CG_FillRect( 188, 234, 1, 13, color ); // ll + CG_FillRect( 234, 226, 1, 29, color ); // l + CG_FillRect( 274, 234, 1, 13, color ); // lr + CG_FillRect( 320, 213, 1, 55, color ); // center + CG_FillRect( 360, 234, 1, 13, color ); // rl + CG_FillRect( 406, 226, 1, 29, color ); // r + CG_FillRect( 452, 234, 1, 13, color ); // rr +} + +void CG_FinishWeaponChange( int lastweap, int newweap ); // JPW NERVE + + +/* +================= +CG_DrawCrosshair +================= +*/ +static void CG_DrawCrosshair( void ) { + float w, h; + qhandle_t hShader; + float f; + float x, y; + int weapnum; // DHM - Nerve + vec4_t hcolor = {1, 1, 1, 0}; + qboolean friendInSights = qfalse; + + #ifdef AUTOAIM + cg.crossHairStatus = 0; + if (cg.snap->ps.serverCursorHint == HINT_PLYR_ENEMY ) + cg.crossHairStatus=1; //----(*SEB*) added + if (cg.snap->ps.serverCursorHint == HINT_PLYR_UNKNOWN ) + cg.crossHairStatus=1; + #endif + + if ( cg.renderingThirdPerson ) { + return; + } + + if ( cg_crosshairHealth.integer ) { + CG_ColorForHealth( hcolor ); + } + + hcolor[3] = cg_crosshairAlpha.value; //----(SA) added + + + // on mg42 + if ( cg.snap->ps.eFlags & EF_MG42_ACTIVE ) { + hcolor[0] = hcolor[1] = hcolor[2] = 0.0f; + hcolor[3] = 0.6f; + // option 1 +// CG_FillRect (300, 240, 40, 2, hcolor); // horizontal +// CG_FillRect (319, 242, 2, 16, hcolor); // vertical + + // option 2 + CG_FillRect( 305, 240, 30, 2, hcolor ); // horizontal + CG_FillRect( 314, 256, 12, 2, hcolor ); // horizontal2 + CG_FillRect( 319, 242, 2, 32, hcolor ); // vertical + + return; + } + + friendInSights = (qboolean)( cg.snap->ps.serverCursorHint == HINT_PLYR_FRIEND ); //----(SA) added + + // DHM - Nerve :: show reticle in limbo and spectator + if ( cgs.gametype == GT_WOLF && cg.snap->ps.pm_flags & PMF_FOLLOW ) { + weapnum = cg.snap->ps.weapon; + } else { + weapnum = cg.weaponSelect; + } + + switch ( weapnum ) { + + // weapons that get no reticle + case WP_NONE: // no weapon, no crosshair + case WP_GARAND: + if ( cg.zoomedBinoc ) { + CG_DrawBinocReticle(); + } + return; + break; + + // special reticle for weapon + case WP_KNIFE: + if ( cg.zoomedBinoc ) { + CG_DrawBinocReticle(); + return; + } + + // no crosshair when looking at exits + if ( cg.snap->ps.serverCursorHint >= HINT_EXIT && cg.snap->ps.serverCursorHint <= HINT_NOEXIT_FAR ) { + return; + } + + if ( !friendInSights ) { + if ( !cg.snap->ps.leanf ) { // no crosshair while leaning + CG_FillRect( 319, 239, 2, 2, hcolor ); // dot + } + return; + } + + break; + + case WP_SNIPERRIFLE: + case WP_SNOOPERSCOPE: + case WP_FG42SCOPE: + +// JPW NERVE -- don't let players run with rifles -- speed 80 == crouch, 128 == walk, 256 == run + if ( cg_gameType.integer != GT_SINGLE_PLAYER ) { + if ( VectorLength( cg.snap->ps.velocity ) > 127.0f ) { + if ( cg.snap->ps.weapon == WP_SNIPERRIFLE ) { + CG_FinishWeaponChange( WP_SNIPERRIFLE, WP_MAUSER ); + } + if ( cg.snap->ps.weapon == WP_SNOOPERSCOPE ) { + CG_FinishWeaponChange( WP_SNOOPERSCOPE, WP_GARAND ); + } + } + } +// jpw + + CG_DrawWeapReticle(); + return; + + default: + break; + } + + // using binoculars + if ( cg.zoomedBinoc ) { + CG_DrawBinocReticle(); + return; + } + + + // mauser only gets crosshair if you don't have the scope (I don't like this, but it's a test) + if ( cg.weaponSelect == WP_MAUSER ) { + if ( COM_BitCheck( cg.predictedPlayerState.weapons, WP_SNIPERRIFLE ) ) { + return; + } + } + + + if ( !cg_drawCrosshair.integer ) { //----(SA) moved down so it doesn't keep the scoped weaps from drawing reticles + return; + } + + // no crosshair while leaning + if ( cg.snap->ps.leanf ) { + return; + } + + // no crosshair when looking at exits + if ( cg.snap->ps.serverCursorHint >= HINT_EXIT && cg.snap->ps.serverCursorHint <= HINT_NOEXIT_FAR ) { + return; + } + + if ( cg_paused.integer ) { + // no draw if any menu's are up (or otherwise paused) + return; + } + + // set color based on health + if ( cg_crosshairHealth.integer ) { + trap_R_SetColor( hcolor ); + } else { + trap_R_SetColor( NULL ); + } + + w = h = cg_crosshairSize.value; +/* + // pulse the size of the crosshair when picking up items + f = cg.time - cg.itemPickupBlendTime; + if ( f > 0 && f < ITEM_BLOB_TIME ) { + f /= ITEM_BLOB_TIME; + w *= ( 1 + f ); + h *= ( 1 + f ); + } +*/ + // RF, crosshair size represents aim spread + f = (float)cg.snap->ps.aimSpreadScale / 255.0; + w *= ( 1 + f * 2.0 ); + h *= ( 1 + f * 2.0 ); + + x = cg_crosshairX.integer; + y = cg_crosshairY.integer; + CG_AdjustFrom640( &x, &y, &w, &h ); + +//----(SA) modified + if ( friendInSights ) { + hShader = cgs.media.crosshairFriendly; + } else { + hShader = cgs.media.crosshairShader[ cg_drawCrosshair.integer % NUM_CROSSHAIRS ]; + } +//----(SA) end + + // NERVE - SMF - modified, fixes crosshair offset in shifted/scaled 3d views + // (SA) also breaks scaled view... + trap_R_DrawStretchPic( x + cg.refdef.x + 0.5 * ( cg.refdef.width - w ), + y + cg.refdef.y + 0.5 * ( cg.refdef.height - h ), + w, h, 0, 0, 1, 1, hShader ); +} + + + +/* +================= +CG_ScanForCrosshairEntity +================= +*/ +static void CG_ScanForCrosshairEntity( void ) { + trace_t trace; +// gentity_t *traceEnt; + vec3_t start, end; + int content; + + // DHM - Nerve :: We want this in multiplayer + if ( cgs.gametype == GT_SINGLE_PLAYER ) { + return; //----(SA) don't use any scanning at the moment. + + } + VectorCopy( cg.refdef.vieworg, start ); + VectorMA( start, 4096, cg.refdef.viewaxis[0], end ); //----(SA) changed from 8192 + + CG_Trace( &trace, start, vec3_origin, vec3_origin, end, + cg.snap->ps.clientNum, CONTENTS_SOLID | CONTENTS_BODY | CONTENTS_ITEM ); + +//----(SA) allow targets that aren't clients +// if ( trace.entityNum >= MAX_CLIENTS ) { +// return; +// } + +// traceEnt = &g_entities[trace.entityNum]; + + + // if the player is in fog, don't show it + content = trap_CM_PointContents( trace.endpos, 0 ); + if ( content & CONTENTS_FOG ) { + return; + } + + // if the player is invisible, don't show it + if ( cg_entities[ trace.entityNum ].currentState.powerups & ( 1 << PW_INVIS ) ) { + return; + } + + // update the fade timer + cg.crosshairClientNum = trace.entityNum; + cg.crosshairClientTime = cg.time; +} + + + +/* +============== +CG_DrawDynamiteStatus +============== +*/ +static void CG_DrawDynamiteStatus( void ) { + float color[4]; + char *name; + int timeleft; + float w; + + if ( cg.snap->ps.weapon != WP_DYNAMITE ) { + return; + } + + if ( cg.snap->ps.grenadeTimeLeft <= 0 ) { + return; + } + + timeleft = cg.snap->ps.grenadeTimeLeft; + +// color = g_color_table[ColorIndex(COLOR_RED)]; + color[0] = color[3] = 1.0f; + + // fade red as it pulses past seconds + color[1] = color[2] = 1.0f - ( (float)( timeleft % 1000 ) * 0.001f ); + + if ( timeleft < 300 ) { // fade up the text + color[3] = (float)timeleft / 300.0f; + } + + trap_R_SetColor( color ); + + timeleft *= 5; + timeleft -= ( timeleft % 5000 ); + timeleft += 5000; + timeleft /= 1000; + + name = va( "Timer: %d", timeleft ); + w = CG_DrawStrlen( name ) * BIGCHAR_WIDTH; + + color[3] *= cg_hudAlpha.value; + CG_DrawBigStringColor( 320 - w / 2, 170, name, color ); + + trap_R_SetColor( NULL ); +} + + + +/* +============== +CG_CheckForCursorHints +============== +*/ +void CG_CheckForCursorHints( void ) { + + if ( cg.renderingThirdPerson ) { + return; + } + + if ( cg.snap->ps.serverCursorHint != HINT_NONE ) { // let the client remember what was last looked at (for fading out) + cg.cursorHintTime = cg.time; + cg.cursorHintFade = cg_hintFadeTime.integer; // fade out time + cg.cursorHintIcon = cg.snap->ps.serverCursorHint; + cg.cursorHintValue = cg.snap->ps.serverCursorHintVal; + } + + // (SA) (8/14/01) removed all the client-side stuff. don't think it's really necessary anymore +} + + +/* +===================== +CG_DrawCrosshairNames +===================== +*/ +static void CG_DrawCrosshairNames( void ) { + float *color; + vec4_t teamColor; // NERVE - SMF + char *name; + float w; + + if ( !cg_drawCrosshair.integer ) { + return; + } + if ( !cg_drawCrosshairNames.integer ) { + return; + } + if ( cg.renderingThirdPerson ) { + return; + } + + // Ridah + if ( cg_gameType.integer == GT_SINGLE_PLAYER ) { + return; + } + // done. + + // scan the known entities to see if the crosshair is sighted on one + CG_ScanForCrosshairEntity(); + + // draw the name of the player being looked at + color = CG_FadeColor( cg.crosshairClientTime, 1000 ); + + if ( !color ) { + trap_R_SetColor( NULL ); + return; + } + + // NERVE - SMF - use fade alpha but color text according to teams + teamColor[3] = color[3]; + + // NERVE - SMF - no longer identify opposing side, so just use green now +// if ( cgs.clientinfo[ cg.crosshairClientNum ].team != cgs.clientinfo[ cg.clientNum ].team ) +// VectorSet( teamColor, 0.7608, 0.1250, 0.0859 ); // LIGHT-RED +// else + VectorSet( teamColor, 0.1250, 0.7608, 0.0859 ); // LIGHT-GREEN + + trap_R_SetColor( teamColor ); + // -NERVE - SMF + + name = cgs.clientinfo[ cg.crosshairClientNum ].name; + w = CG_DrawStrlen( va( "Axis: %s", name ) ) * BIGCHAR_WIDTH; +// CG_DrawBigString( 320 - w / 2, 170, name, color[3] * 0.5 ); + + // NERVE - SMF + if ( strlen( name ) ) { + if ( ( cgs.clientinfo[ cg.crosshairClientNum ].team == TEAM_RED ) && + ( cgs.clientinfo[cg.snap->ps.clientNum].team == TEAM_RED ) ) { // JPW NERVE -- only show same team info so people can't pan-search + CG_DrawBigStringColor( 320 - w / 2, 170, va( "Axis: %s", name ), teamColor ); + } else if ( ( cgs.clientinfo[ cg.crosshairClientNum ].team == TEAM_BLUE ) && + ( cgs.clientinfo[cg.snap->ps.clientNum].team == TEAM_BLUE ) ) { // JPW NERVE -- so's we can't find snipers for free + CG_DrawBigStringColor( 320 - w / 2, 170, va( "Ally: %s", name ), teamColor ); + } + } + // -NERVE - SMF + + trap_R_SetColor( NULL ); +} + + + +//============================================================================== + +/* +================= +CG_DrawSpectator +================= +*/ +static void CG_DrawSpectator( void ) { + CG_DrawBigString( 320 - 9 * 8, 440, "SPECTATOR", 1.0F ); + if ( cgs.gametype == GT_TOURNAMENT ) { + CG_DrawBigString( 320 - 15 * 8, 460, "waiting to play", 1.0F ); + } + if ( cgs.gametype == GT_TEAM || cgs.gametype == GT_CTF ) { + CG_DrawBigString( 320 - 25 * 8, 460, "use the TEAM menu to play", 1.0F ); + } +} + +/* +================= +CG_DrawVote +================= +*/ +static void CG_DrawVote( void ) { + char *s; + int sec; + + if ( !cgs.voteTime ) { + return; + } + + // play a talk beep whenever it is modified + if ( cgs.voteModified ) { + cgs.voteModified = qfalse; + trap_S_StartLocalSound( cgs.media.talkSound, CHAN_LOCAL_SOUND ); + } + + sec = ( VOTE_TIME - ( cg.time - cgs.voteTime ) ) / 1000; + if ( sec < 0 ) { + sec = 0; + } + s = va( "VOTE(%i):%s yes(F1):%i no(F2):%i", sec, cgs.voteString, cgs.voteYes, cgs.voteNo ); + CG_DrawSmallString( 0, 58, s, 1.0F ); +} + +/* +================= +CG_DrawIntermission +================= +*/ +static void CG_DrawIntermission( void ) { + if ( cgs.gametype == GT_SINGLE_PLAYER ) { + CG_DrawCenterString(); + return; + } + + cg.scoreFadeTime = cg.time; + CG_DrawScoreboard(); +} + +// NERVE - SMF +/* +================= +CG_ActivateLimboMenu +================= +*/ +// TTimo: unused +/* +static void CG_ActivateLimboMenu( void ) { + static qboolean latch = qfalse; + qboolean test; + char buf[32]; + + if ( cgs.gametype != GT_WOLF ) + return; + + // should we open the limbo menu + test = cg.snap->ps.pm_flags & PMF_LIMBO || cg.snap->ps.persistant[PERS_TEAM] == TEAM_SPECTATOR; + + if ( test && !latch ) { + trap_SendConsoleCommand( "startLimboMode\n" ); + trap_SendConsoleCommand( "OpenLimboMenu\n" ); + latch = qtrue; + } + else if ( !test && latch ) { + trap_SendConsoleCommand( "stopLimboMode\n" ); + trap_SendConsoleCommand( "CloseLimboMenu\n" ); + latch = qfalse; + } + + // set the limbo state + trap_Cvar_VariableStringBuffer( "ui_limboMode", buf, sizeof( buf ) ); + + if ( atoi( buf ) ) + cg.limboMenu = qtrue; + else + cg.limboMenu = qfalse; +} +*/ +// -NERVE - SMF + +/* +================= +CG_DrawFollow +================= +*/ +static qboolean CG_DrawFollow( void ) { + float x; + vec4_t color; + const char *name; + char deploytime[128]; // JPW NERVE + + if ( !( cg.snap->ps.pm_flags & PMF_FOLLOW ) ) { + return qfalse; + } + color[0] = 1; + color[1] = 1; + color[2] = 1; + color[3] = 1; + +// JPW NERVE -- if in limbo, show different follow message + if ( cg.snap->ps.pm_flags & PMF_LIMBO ) { +// CG_Printf("following %s\n",cgs.clientinfo[ cg.snap->ps.clientNum ].name); + color[1] = 0; + color[2] = 0; + if ( cgs.clientinfo[cg.snap->ps.clientNum].team == TEAM_RED ) { + sprintf( deploytime,"Deploying in %d seconds", (int)( (float)( cg_redlimbotime.integer - ( cg.time % cg_redlimbotime.integer ) ) * 0.001f ) ); + } else { + sprintf( deploytime,"Deploying in %d seconds", (int)( (float)( cg_bluelimbotime.integer - ( cg.time % cg_bluelimbotime.integer ) ) * 0.001f ) ); + } + + x = 0.5 * ( 640 - BIGCHAR_WIDTH * strlen( deploytime ) ); //CG_DrawStrlen( deploytime ) ); + CG_DrawStringExt( x, 24, deploytime, color, qtrue, qtrue, BIGCHAR_WIDTH, BIGCHAR_HEIGHT, 0 ); + sprintf( deploytime,"(Following %s)",cgs.clientinfo[ cg.snap->ps.clientNum ].name ); + x = 0.5 * ( 640 - BIGCHAR_WIDTH * strlen( deploytime ) ); //CG_DrawStrlen( deploytime ) ); + CG_DrawStringExt( x, 48, deploytime, color, qtrue, qtrue, BIGCHAR_WIDTH, BIGCHAR_HEIGHT, 0 ); + + } else { +// jpw + CG_DrawBigString( 320 - 9 * 8, 24, "following", 1.0F ); + + name = cgs.clientinfo[ cg.snap->ps.clientNum ].name; + + x = 0.5 * ( 640 - GIANT_WIDTH * CG_DrawStrlen( name ) ); + + CG_DrawStringExt( x, 40, name, color, qtrue, qtrue, GIANT_WIDTH, GIANT_HEIGHT, 0 ); + } // JPW NERVE + return qtrue; +} + + + +/* +================= +CG_DrawAmmoWarning +================= +*/ +static void CG_DrawAmmoWarning( void ) { + const char *s; + int w; + +//----(SA) forcing return for now +// if we have messages to show here, comment back in + return; + + + if ( cg_drawAmmoWarning.integer == 0 ) { + return; + } + + if ( !cg.lowAmmoWarning ) { + return; + } + + if ( cg.lowAmmoWarning == 2 ) { + s = "OUT OF AMMO"; + } else { + s = "LOW AMMO WARNING"; + } + w = CG_DrawStrlen( s ) * BIGCHAR_WIDTH; + CG_DrawBigString( 320 - w / 2, 64, s, 1.0F ); +} + +/* +================= +CG_DrawWarmup +================= +*/ +static void CG_DrawWarmup( void ) { + int w; + int sec; + int i; + clientInfo_t *ci1, *ci2; + int cw; + const char *s; + + if ( cgs.gametype == GT_SINGLE_PLAYER ) { + return; // (SA) don't bother with this stuff in sp + } + + sec = cg.warmup; + if ( !sec ) { + return; + } + + if ( sec < 0 ) { + s = "Waiting for players"; + w = CG_DrawStrlen( s ) * BIGCHAR_WIDTH; + CG_DrawBigString( 320 - w / 2, 40, s, 1.0F ); + cg.warmupCount = 0; + return; + } + + + // find the two active players + ci1 = NULL; + ci2 = NULL; + for ( i = 0 ; i < cgs.maxclients ; i++ ) { + if ( cgs.clientinfo[i].infoValid && cgs.clientinfo[i].team == TEAM_FREE ) { + if ( !ci1 ) { + ci1 = &cgs.clientinfo[i]; + } else { + ci2 = &cgs.clientinfo[i]; + } + } + } + + if ( ci1 && ci2 ) { + s = va( "%s vs %s", ci1->name, ci2->name ); + w = CG_DrawStrlen( s ); + if ( w > 640 / GIANT_WIDTH ) { + cw = 640 / w; + } else { + cw = GIANT_WIDTH; + } + CG_DrawStringExt( 320 - w * cw / 2, 20,s, colorWhite, + qfalse, qtrue, cw, (int)( cw * 1.5 ), 0 ); + } + + + sec = ( sec - cg.time ) / 1000; + if ( sec < 0 ) { + sec = 0; + } + s = va( "Starts in: %i", sec + 1 ); + if ( sec != cg.warmupCount ) { + cg.warmupCount = sec; + switch ( sec ) { + case 0: + trap_S_StartLocalSound( cgs.media.count1Sound, CHAN_ANNOUNCER ); + break; + case 1: + trap_S_StartLocalSound( cgs.media.count2Sound, CHAN_ANNOUNCER ); + break; + case 2: + trap_S_StartLocalSound( cgs.media.count3Sound, CHAN_ANNOUNCER ); + break; + default: + break; + } + } + switch ( cg.warmupCount ) { + case 0: + cw = 28; + break; + case 1: + cw = 24; + break; + case 2: + cw = 20; + break; + default: + cw = 16; + break; + } + + w = CG_DrawStrlen( s ); + CG_DrawStringExt( 320 - w * cw / 2, 70, s, colorWhite, + qfalse, qtrue, cw, (int)( cw * 1.5 ), 0 ); +} + +//================================================================================== + +/* +================= +CG_DrawFlashFade +================= +*/ +static void CG_DrawFlashFade( void ) { + static int lastTime; + int elapsed, time; + vec4_t col; + + if ( cgs.scrFadeStartTime + cgs.scrFadeDuration < cg.time ) { + cgs.scrFadeAlphaCurrent = cgs.scrFadeAlpha; + } else if ( cgs.scrFadeAlphaCurrent != cgs.scrFadeAlpha ) { + elapsed = ( time = trap_Milliseconds() ) - lastTime; // we need to use trap_Milliseconds() here since the cg.time gets modified upon reloading + lastTime = time; + if ( elapsed < 500 && elapsed > 0 ) { + if ( cgs.scrFadeAlphaCurrent > cgs.scrFadeAlpha ) { + cgs.scrFadeAlphaCurrent -= ( (float)elapsed / (float)cgs.scrFadeDuration ); + if ( cgs.scrFadeAlphaCurrent < cgs.scrFadeAlpha ) { + cgs.scrFadeAlphaCurrent = cgs.scrFadeAlpha; + } + } else { + cgs.scrFadeAlphaCurrent += ( (float)elapsed / (float)cgs.scrFadeDuration ); + if ( cgs.scrFadeAlphaCurrent > cgs.scrFadeAlpha ) { + cgs.scrFadeAlphaCurrent = cgs.scrFadeAlpha; + } + } + } + } + // now draw the fade + if ( cgs.scrFadeAlphaCurrent > 0.0 ) { +// CG_Printf("fade: %f\n", cgs.scrFadeAlphaCurrent); + VectorClear( col ); + col[3] = cgs.scrFadeAlphaCurrent; +// CG_FillRect( -10, -10, 650, 490, col ); + CG_FillRect( 0, 0, 640, 480, col ); // why do a bunch of these extend outside 640x480? + } +} + + + +/* +============== +CG_DrawFlashZoomTransition + hide the snap transition from regular view to/from zoomed + + FIXME: TODO: use cg_fade? +============== +*/ +static void CG_DrawFlashZoomTransition( void ) { + vec4_t color; + float frac; + int fadeTime; + + if ( !cg.snap ) { + return; + } + + if ( cg.snap->ps.eFlags & EF_MG42_ACTIVE ) { // don't draw when on mg_42 + // keep the timer fresh so when you remove yourself from the mg42, it'll fade + cg.zoomTime = cg.time; + return; + } + + if ( cgs.gametype != GT_SINGLE_PLAYER ) { // JPW NERVE + fadeTime = 400; + } else { + if ( cg.zoomedScope ) { + fadeTime = cg.zoomedScope; //----(SA) + } else { + fadeTime = 300; + } + } + // jpw + + frac = cg.time - cg.zoomTime; + + if ( frac < fadeTime ) { + frac = frac / (float)fadeTime; + + if ( cg.weaponSelect == WP_SNOOPERSCOPE ) { +// Vector4Set( color, 0.7f, 0.3f, 0.7f, 1.0f - frac ); +// Vector4Set( color, 1, 0.5, 1, 1.0f - frac ); +// Vector4Set( color, 0.5f, 0.3f, 0.5f, 1.0f - frac ); + Vector4Set( color, 0.7f, 0.6f, 0.7f, 1.0f - frac ); + } else { + Vector4Set( color, 0, 0, 0, 1.0f - frac ); + } + + CG_FillRect( -10, -10, 650, 490, color ); + } +} + + + +/* +================= +CG_DrawFlashDamage +================= +*/ +static void CG_DrawFlashDamage( void ) { + vec4_t col; + float redFlash; + + if ( !cg.snap ) { + return; + } + + if ( cg.v_dmg_time > cg.time ) { + redFlash = fabs( cg.v_dmg_pitch * ( ( cg.v_dmg_time - cg.time ) / DAMAGE_TIME ) ); + + // blend the entire screen red + if ( redFlash > 5 ) { + redFlash = 5; + } + + VectorSet( col, 0.2, 0, 0 ); + col[3] = 0.7 * ( redFlash / 5.0 ); + + CG_FillRect( -10, -10, 650, 490, col ); + } +} + + +/* +================= +CG_DrawFlashFire +================= +*/ +static void CG_DrawFlashFire( void ) { + vec4_t col = {1,1,1,1}; + float alpha, max, f; + + if ( !cg.snap ) { + return; + } + + if ( cg_thirdPerson.integer ) { + return; + } + + if ( cg.cameraMode ) { // don't draw flames on camera screen. will still do damage though, so not a potential cheat + return; + } + + if ( !cg.snap->ps.onFireStart ) { + cg.v_noFireTime = cg.time; + return; + } + + alpha = (float)( ( FIRE_FLASH_TIME - 1000 ) - ( cg.time - cg.snap->ps.onFireStart ) ) / ( FIRE_FLASH_TIME - 1000 ); + if ( alpha > 0 ) { + if ( alpha >= 1.0 ) { + alpha = 1.0; + } + + // fade in? + f = (float)( cg.time - cg.v_noFireTime ) / FIRE_FLASH_FADEIN_TIME; + if ( f >= 0.0 && f < 1.0 ) { + alpha = f; + } + + max = 0.5 + 0.5 * sin( (float)( ( cg.time / 10 ) % 1000 ) / 1000.0 ); + if ( alpha > max ) { + alpha = max; + } + col[0] = alpha; + col[1] = alpha; + col[2] = alpha; + col[3] = alpha; + trap_R_SetColor( col ); + CG_DrawPic( -10, -10, 650, 490, cgs.media.viewFlashFire[( cg.time / 50 ) % 16] ); + trap_R_SetColor( NULL ); + + trap_S_AddLoopingSound( cg.snap->ps.clientNum, cg.snap->ps.origin, vec3_origin, cgs.media.flameSound, (int)( 255.0 * alpha ) ); + trap_S_AddLoopingSound( cg.snap->ps.clientNum, cg.snap->ps.origin, vec3_origin, cgs.media.flameCrackSound, (int)( 255.0 * alpha ) ); + } else { + cg.v_noFireTime = cg.time; + } +} + +/* +================= +CG_DrawFlashLightning +================= +*/ +static void CG_DrawFlashLightning( void ) { + //vec4_t col={1,1,1,1}; // TTimo: unused + float alpha; + centity_t *cent; + qhandle_t shader; + + if ( !cg.snap ) { + return; + } + + if ( cg_thirdPerson.integer ) { + return; + } + + cent = &cg_entities[cg.snap->ps.clientNum]; + + if ( !cent->pe.teslaDamagedTime || ( cent->pe.teslaDamagedTime > cg.time ) ) { + return; + } + + alpha = 1.0 - (float)( cg.time - cent->pe.teslaDamagedTime ) / LIGHTNING_FLASH_TIME; + if ( alpha > 0 ) { + if ( alpha >= 1.0 ) { + alpha = 1.0; + } + + if ( ( cg.time / 50 ) % ( 2 + ( cg.time % 2 ) ) == 0 ) { + shader = cgs.media.viewTeslaAltDamageEffectShader; + } else { + shader = cgs.media.viewTeslaDamageEffectShader; + } + + CG_DrawPic( -10, -10, 650, 490, shader ); + } +} + + + +/* +============== +CG_DrawFlashBlendBehindHUD + screen flash stuff drawn first (on top of world, behind HUD) +============== +*/ +static void CG_DrawFlashBlendBehindHUD( void ) { + CG_DrawFlashZoomTransition(); +} + + +/* +================= +CG_DrawFlashBlend + screen flash stuff drawn last (on top of everything) +================= +*/ +static void CG_DrawFlashBlend( void ) { + CG_DrawFlashLightning(); + CG_DrawFlashFire(); + CG_DrawFlashDamage(); + CG_DrawFlashFade(); +} + +// NERVE - SMF +/* +================= +CG_DrawObjectiveInfo +================= +*/ +#define OID_LEFT 10 +#define OID_TOP 65 + +void CG_ObjectivePrint( const char *str, int charWidth, int team ) { + char *s; + + Q_strncpyz( cg.oidPrint, str, sizeof( cg.oidPrint ) ); + + cg.oidPrintTime = cg.time; + cg.oidPrintY = OID_TOP; + cg.oidPrintCharWidth = charWidth; + + // count the number of lines for oiding + cg.oidPrintLines = 1; + s = cg.oidPrint; + while ( *s ) { + if ( *s == '\n' ) { + cg.oidPrintLines++; + } + s++; + } +} + +static void CG_DrawObjectiveInfo( void ) { + char *start; + int l; + int x, y, w; + int x1, y1, x2, y2; + float *color; + vec4_t backColor = { 0.2f, 0.2f, 0.2f, 1.f }; + + if ( !cg.oidPrintTime ) { + return; + } + + color = CG_FadeColor( cg.oidPrintTime, 1000 * 5 ); + if ( !color ) { + return; + } + + trap_R_SetColor( color ); + + start = cg.oidPrint; + + y = cg.oidPrintY - cg.oidPrintLines * BIGCHAR_HEIGHT / 2; + + x1 = OID_LEFT - 2; + y1 = y - 2; + x2 = 0; + + // first just find the bounding rect + while ( 1 ) { + char linebuffer[1024]; + + for ( l = 0; l < 40; l++ ) { + if ( !start[l] || start[l] == '\n' ) { + break; + } + linebuffer[l] = start[l]; + } + linebuffer[l] = 0; + + w = cg.oidPrintCharWidth * CG_DrawStrlen( linebuffer ); + if ( x1 + w > x2 ) { + x2 = x1 + w; + } + + x = OID_LEFT; + + y += cg.oidPrintCharWidth * 1.5; + + while ( *start && ( *start != '\n' ) ) { + start++; + } + if ( !*start ) { + break; + } + start++; + } + + x2 = x2 + 4; + y2 = y - cg.oidPrintCharWidth * 1.5 + 4; + + backColor[3] = color[3]; + CG_FillRect( x1, y1, x2 - x1, y2 - y1, backColor ); + + VectorSet( backColor, 0, 0, 0 ); + CG_DrawRect( x1, y1, x2 - x1, y2 - y1, 1, backColor ); + + // do the actual drawing + start = cg.oidPrint; + y = cg.oidPrintY - cg.oidPrintLines * BIGCHAR_HEIGHT / 2; + + while ( 1 ) { + char linebuffer[1024]; + + for ( l = 0; l < 40; l++ ) { + if ( !start[l] || start[l] == '\n' ) { + break; + } + linebuffer[l] = start[l]; + } + linebuffer[l] = 0; + + w = cg.oidPrintCharWidth * CG_DrawStrlen( linebuffer ); + if ( x1 + w > x2 ) { + x2 = x1 + w; + } + + x = OID_LEFT; + + CG_DrawStringExt( x, y, linebuffer, color, qfalse, qtrue, + cg.oidPrintCharWidth, (int)( cg.oidPrintCharWidth * 1.5 ), 0 ); + + y += cg.oidPrintCharWidth * 1.5; + + while ( *start && ( *start != '\n' ) ) { + start++; + } + if ( !*start ) { + break; + } + start++; + } + + trap_R_SetColor( NULL ); +} +// -NERVE - SMF + +//================================================================================== + + +void CG_DrawTimedMenus() { + if ( cg.voiceTime ) { + int t = cg.time - cg.voiceTime; + if ( t > 2500 ) { + Menus_CloseByName( "voiceMenu" ); + trap_Cvar_Set( "cl_conXOffset", "0" ); + cg.voiceTime = 0; + } + } +} + + +/* +================= +CG_Fade +================= +*/ +void CG_Fade( int r, int g, int b, int a, int time, int duration ) { + + // incorporate this into the current fade scheme + + cgs.scrFadeAlpha = (float)a / 255.0f; + cgs.scrFadeStartTime = time; + cgs.scrFadeDuration = duration; + + if ( cgs.scrFadeStartTime + cgs.scrFadeDuration <= cg.time ) { + cgs.scrFadeAlphaCurrent = cgs.scrFadeAlpha; + } + + + return; + + + if ( time <= 0 ) { // do instantly + cg.fadeRate = 1; + cg.fadeTime = cg.time - 1; // set cg.fadeTime behind cg.time so it will start out 'done' + } else { + cg.fadeRate = 1.0f / time; + cg.fadeTime = cg.time + time; + } + + cg.fadeColor2[ 0 ] = ( float )r / 255.0f; + cg.fadeColor2[ 1 ] = ( float )g / 255.0f; + cg.fadeColor2[ 2 ] = ( float )b / 255.0f; + cg.fadeColor2[ 3 ] = ( float )a / 255.0f; +} + + +/* +=============== +CG_DrawGameScreenFade +=============== +*/ +static void CG_DrawGameScreenFade( void ) { + vec4_t col; + + if ( cg.viewFade <= 0.0 ) { + return; + } + + if ( !cg.snap ) { + return; + } + + VectorClear( col ); + col[3] = cg.viewFade; + CG_FillRect( 0, 0, 640, 480, col ); +} + +/* +================= +CG_ScreenFade +================= +*/ +static void CG_ScreenFade( void ) { + int msec; + int i; + float t, invt; + vec4_t color; + + // Ridah, fade the screen (in-game) + CG_DrawGameScreenFade(); + + if ( !cg.fadeRate ) { + return; + } + + msec = cg.fadeTime - cg.time; + if ( msec <= 0 ) { + cg.fadeColor1[ 0 ] = cg.fadeColor2[ 0 ]; + cg.fadeColor1[ 1 ] = cg.fadeColor2[ 1 ]; + cg.fadeColor1[ 2 ] = cg.fadeColor2[ 2 ]; + cg.fadeColor1[ 3 ] = cg.fadeColor2[ 3 ]; + + if ( !cg.fadeColor1[ 3 ] ) { + cg.fadeRate = 0; + return; + } + + CG_FillRect( 0, 0, 640, 480, cg.fadeColor1 ); + + } else { + t = ( float )msec * cg.fadeRate; + invt = 1.0f - t; + + for ( i = 0; i < 4; i++ ) { + color[ i ] = cg.fadeColor1[ i ] * t + cg.fadeColor2[ i ] * invt; + } + + if ( color[ 3 ] ) { + CG_FillRect( 0, 0, 640, 480, color ); + } + } +} + + + +/* +================= +CG_Draw2D +================= +*/ +static void CG_Draw2D( void ) { + + // if we are taking a levelshot for the menu, don't draw anything + if ( cg.levelShot ) { + return; + } + + if ( cg.cameraMode ) { //----(SA) no 2d when in camera view + CG_DrawFlashBlend(); // (for fades) + return; + } + + if ( cg_draw2D.integer == 0 ) { + return; + } + + CG_ScreenFade(); + + + if ( cg.snap->ps.pm_type == PM_INTERMISSION ) { + CG_DrawIntermission(); + return; + } + + CG_DrawFlashBlendBehindHUD(); + + if ( cg.snap->ps.persistant[PERS_TEAM] == TEAM_SPECTATOR ) { + CG_DrawSpectator(); + CG_DrawCrosshair(); + CG_DrawCrosshairNames(); + } else { + // don't draw any status if dead + if ( cg.snap->ps.stats[STAT_HEALTH] > 0 ) { + + CG_DrawCrosshair(); + + if ( cg_drawStatus.integer ) { + Menu_PaintAll(); + CG_DrawTimedMenus(); + } + +// CG_DrawStatusBar(); + CG_DrawAmmoWarning(); + CG_DrawDynamiteStatus(); + CG_DrawCrosshairNames(); + CG_DrawWeaponSelect(); + CG_DrawHoldableSelect(); + CG_DrawPickupItem(); + CG_DrawReward(); + } + if ( cgs.gametype >= GT_TEAM ) { + CG_DrawTeamInfo(); + } + } + + CG_DrawVote(); + + CG_DrawLagometer(); + + if ( !cg_paused.integer ) { + CG_DrawUpperRight(); + } + +// CG_DrawLowerRight(); + if ( !CG_DrawFollow() ) { + CG_DrawWarmup(); + } + + // don't draw center string if scoreboard is up + if ( !CG_DrawScoreboard() ) { + CG_DrawCenterString(); + + CG_DrawObjectiveInfo(); // NERVE - SMF + } + + // Ridah, draw flash blends now + CG_DrawFlashBlend(); +} + +/* +==================== +CG_StartShakeCamera +==================== +*/ +void CG_StartShakeCamera( float p, int duration, vec3_t src, float radius ) { + int i; + + // find a free shake slot + for ( i = 0; i < MAX_CAMERA_SHAKE; i++ ) { + if ( cg.cameraShake[i].time > cg.time || cg.cameraShake[i].time + cg.cameraShake[i].length <= cg.time ) { + break; + } + } + + if ( i == MAX_CAMERA_SHAKE ) { + return; // no free slots + + } + cg.cameraShake[i].scale = p; + + cg.cameraShake[i].length = duration; + cg.cameraShake[i].time = cg.time; + VectorCopy( src, cg.cameraShake[i].src ); + cg.cameraShake[i].radius = radius; +} + +/* +==================== +CG_CalcShakeCamera +==================== +*/ +void CG_CalcShakeCamera() { + float val, scale, dist, x, sx; + float bx = 0.0f; // TTimo: init + int i; + + // build the scale + scale = 0.0f; + sx = (float)cg.time / 600.0; // x * (float)(cg.cameraShake[i].length) / 600.0; + for ( i = 0; i < MAX_CAMERA_SHAKE; i++ ) { + if ( cg.cameraShake[i].time <= cg.time && cg.cameraShake[i].time + cg.cameraShake[i].length > cg.time ) { + dist = Distance( cg.cameraShake[i].src, cg.refdef.vieworg ); + // fade with distance + val = cg.cameraShake[i].scale * ( 1.0f - ( dist / cg.cameraShake[i].radius ) ); + // fade with time + x = 1.0f - ( ( cg.time - cg.cameraShake[i].time ) / cg.cameraShake[i].length ); + val *= x; + // overwrite global scale if larger + if ( val > scale ) { + scale = val; + bx = x; + } + } + } + + // check the current rumble status + if ( cg.rumbleScale > scale ) { + scale = cg.rumbleScale; + bx = cg.rumbleScale; + } + + if ( scale <= 0.0f ) { + cg.cameraShakePhase = crandom() * M_PI; // randomize the phase + return; + } + + if ( scale > 1.0f ) { + scale = 1.0f; + } + + // up/down + val = sin( M_PI * 8 * sx + cg.cameraShakePhase ) * bx * 18.0f * scale; + cg.cameraShakeAngles[0] = val; + //cg.refdefViewAngles[0] += val; + + // left/right + val = sin( M_PI * 15 * sx + cg.cameraShakePhase ) * bx * 16.0f * scale; + cg.cameraShakeAngles[1] = val; + //cg.refdefViewAngles[1] += val; + + // roll + val = sin( M_PI * 12 * sx + cg.cameraShakePhase ) * bx * 10.0f * scale; + cg.cameraShakeAngles[2] = val; + //cg.refdefViewAngles[2] += val; +} + +/* +==================== +CG_ApplyShakeCamera +==================== +*/ +void CG_ApplyShakeCamera() { + VectorAdd( cg.refdefViewAngles, cg.cameraShakeAngles, cg.refdefViewAngles ); + AnglesToAxis( cg.refdefViewAngles, cg.refdef.viewaxis ); +} + +/* +===================== +CG_DrawActive + +Perform all drawing needed to completely fill the screen +===================== +*/ +void CG_DrawActive( stereoFrame_t stereoView ) { + float separation; + vec3_t baseOrg; + + // optionally draw the info screen instead + if ( !cg.snap ) { + CG_DrawInformation(); + return; + } + + // if they are waiting at the mission stats screen, show the stats + if ( cg_gameType.integer == GT_SINGLE_PLAYER ) { + if ( strlen( cg_missionStats.string ) > 1 ) { + trap_Cvar_Set( "com_expectedhunkusage", "-2" ); + CG_DrawInformation(); + return; + } + } + + // optionally draw the tournement scoreboard instead + if ( cg.snap->ps.persistant[PERS_TEAM] == TEAM_SPECTATOR && + ( cg.snap->ps.pm_flags & PMF_SCOREBOARD ) ) { + CG_DrawTourneyScoreboard(); + return; + } + + switch ( stereoView ) { + case STEREO_CENTER: + separation = 0; + break; + case STEREO_LEFT: + separation = -cg_stereoSeparation.value / 2; + break; + case STEREO_RIGHT: + separation = cg_stereoSeparation.value / 2; + break; + default: + separation = 0; + CG_Error( "CG_DrawActive: Undefined stereoView" ); + } + + + // clear around the rendered view if sized down +// CG_TileClear(); // (SA) moved down + + // offset vieworg appropriately if we're doing stereo separation + VectorCopy( cg.refdef.vieworg, baseOrg ); + if ( separation != 0 ) { + VectorMA( cg.refdef.vieworg, -separation, cg.refdef.viewaxis[1], cg.refdef.vieworg ); + } + + cg.refdef.glfog.registered = 0; // make sure it doesn't use fog from another scene +/* + // NERVE - SMF - activate limbo menu and draw small 3d window + CG_ActivateLimboMenu(); + + if ( cg.limboMenu ) { + float x, y, w, h; + x = LIMBO_3D_X; + y = LIMBO_3D_Y; + w = LIMBO_3D_W; + h = LIMBO_3D_H; + + cg.refdef.width = 0; + CG_AdjustFrom640( &x, &y, &w, &h ); + + cg.refdef.x = x; + cg.refdef.y = y; + cg.refdef.width = w; + cg.refdef.height = h; + } + // -NERVE - SMF +*/ + cg.refdef.rdflags |= RDF_DRAWSKYBOX; + if ( !cg_skybox.integer ) { + cg.refdef.rdflags &= ~RDF_DRAWSKYBOX; + } + + trap_R_RenderScene( &cg.refdef ); + + // restore original viewpoint if running stereo + if ( separation != 0 ) { + VectorCopy( baseOrg, cg.refdef.vieworg ); + } + + // clear around the rendered view if sized down + CG_TileClear(); //----(SA) moved to 2d section to avoid 2d/3d fog-state problems + + // draw status bar and other floating elements + CG_Draw2D(); +} + + diff --git a/Projects/Android/jni/rtcw/src/cgame/cg_drawtools.c b/Projects/Android/jni/rtcw/src/cgame/cg_drawtools.c new file mode 100644 index 0000000..42fab20 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/cgame/cg_drawtools.c @@ -0,0 +1,1297 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +// cg_drawtools.c -- helper functions called by cg_draw, cg_scoreboard, cg_info, etc +#include "cg_local.h" + +/* +================ +CG_AdjustFrom640 + +Adjusted for resolution and screen aspect ratio +================ +*/ +void CG_AdjustFrom640( float *x, float *y, float *w, float *h ) { +#if 0 + // adjust for wide screens + if ( cgs.glconfig.vidWidth * 480 > cgs.glconfig.vidHeight * 640 ) { + *x += 0.5 * ( cgs.glconfig.vidWidth - ( cgs.glconfig.vidHeight * 640 / 480 ) ); + } +#endif + + // NERVE - SMF - hack to make images display properly in small view / limbo mode + if ( cg.limboMenu && cg.refdef.width ) { + float xscale = ( ( cg.refdef.width / cgs.screenXScale ) / 640.f ); + float yscale = ( ( cg.refdef.height / cgs.screenYScale ) / 480.f ); + + ( *x ) = ( *x ) * xscale + ( cg.refdef.x / cgs.screenXScale ); + ( *y ) = ( *y ) * yscale + ( cg.refdef.y / cgs.screenYScale ); + ( *w ) *= xscale; + ( *h ) *= yscale; + } + // -NERVE - SMF + + // scale for screen sizes + *x *= cgs.screenXScale; + *y *= cgs.screenYScale; + *w *= cgs.screenXScale; + *h *= cgs.screenYScale; +} + +/* +================ +CG_FillRect + +Coordinates are 640*480 virtual values +================= +*/ +void CG_FillRect( float x, float y, float width, float height, const float *color ) { + trap_R_SetColor( color ); + + CG_AdjustFrom640( &x, &y, &width, &height ); + trap_R_DrawStretchPic( x, y, width, height, 0, 0, 0, 1, cgs.media.whiteShader ); + + trap_R_SetColor( NULL ); +} + +/* +============== +CG_FillRectGradient +============== +*/ +void CG_FillRectGradient( float x, float y, float width, float height, const float *color, const float *gradcolor, int gradientType ) { + trap_R_SetColor( color ); + + CG_AdjustFrom640( &x, &y, &width, &height ); + trap_R_DrawStretchPicGradient( x, y, width, height, 0, 0, 0, 0, cgs.media.whiteShader, gradcolor, gradientType ); + + trap_R_SetColor( NULL ); +} + + +/* +============== +CG_HorizontalPercentBar + Generic routine for pretty much all status indicators that show a fractional + value to the palyer by virtue of how full a drawn box is. + +flags: + left - 1 + center - 2 // direction is 'right' by default and orientation is 'horizontal' + vert - 4 + nohudalpha - 8 // don't adjust bar's alpha value by the cg_hudalpha value + bg - 16 // background contrast box (bg set with bgColor of 'NULL' means use default bg color (1,1,1,0.25) + spacing - 32 // some bars use different sorts of spacing when drawing both an inner and outer box + + lerp color - 256 // use an average of the start and end colors to set the fill color +============== +*/ + + +// TODO: these flags will be shared, but it was easier to work on stuff if I wasn't changing header files a lot +#define BAR_LEFT 0x0001 +#define BAR_CENTER 0x0002 +#define BAR_VERT 0x0004 +#define BAR_NOHUDALPHA 0x0008 +#define BAR_BG 0x0010 +// different spacing modes for use w/ BAR_BG +#define BAR_BGSPACING_X0Y5 0x0020 +#define BAR_BGSPACING_X0Y0 0x0040 + +#define BAR_LERP_COLOR 0x0100 + +#define BAR_BORDERSIZE 2 + +void CG_FilledBar( float x, float y, float w, float h, const float *startColorIn, float *endColor, const float *bgColor, float frac, int flags ) { + vec4_t backgroundcolor = {1, 1, 1, 0.25f}, colorAtPos; // colorAtPos is the lerped color if necessary + vec4_t startColor; + + int indent = BAR_BORDERSIZE; + + VectorCopy4( startColorIn, startColor ); + + if ( ( flags & BAR_BG ) && bgColor ) { // BAR_BG set, and color specified, use specified bg color + Vector4Copy( bgColor, backgroundcolor ); + } + + // hud alpha + if ( !( flags & BAR_NOHUDALPHA ) ) { + startColor[3] *= cg_hudAlpha.value; + if ( endColor ) { + endColor[3] *= cg_hudAlpha.value; + } + if ( backgroundcolor ) { + backgroundcolor[3] *= cg_hudAlpha.value; + } + } + + if ( flags & BAR_LERP_COLOR ) { + Vector4Average( startColor, endColor, frac, colorAtPos ); + } + + // background + if ( ( flags & BAR_BG ) ) { + // draw background at full size and shrink the remaining box to fit inside with a border. (alternate border may be specified by a BAR_BGSPACING_xx) + CG_FillRect( x, + y, + w, + h, + backgroundcolor ); + + if ( flags & BAR_BGSPACING_X0Y0 ) { // fill the whole box (no border) + + } else if ( flags & BAR_BGSPACING_X0Y5 ) { // spacing created for weapon heat + indent *= 3; + y += indent; + h -= ( 2 * indent ); + + } else { // default spacing of 2 units on each side + x += indent; + y += indent; + w -= ( 2 * indent ); + h -= ( 2 * indent ); + } + } + + + // adjust for horiz/vertical and draw the fractional box + if ( flags & BAR_VERT ) { + if ( flags & BAR_LEFT ) { // TODO: remember to swap colors on the ends here + y += ( h * ( 1 - frac ) ); + } else if ( flags & BAR_CENTER ) { + y += ( h * ( 1 - frac ) / 2 ); + } + + if ( flags & BAR_LERP_COLOR ) { + CG_FillRect( x, y, w, h * frac, colorAtPos ); + } else { +// CG_FillRectGradient ( x, y, w, h * frac, startColor, endColor, 0 ); + CG_FillRect( x, y, w, h * frac, startColor ); + } + + } else { + + if ( flags & BAR_LEFT ) { // TODO: remember to swap colors on the ends here + x += ( w * ( 1 - frac ) ); + } else if ( flags & BAR_CENTER ) { + x += ( w * ( 1 - frac ) / 2 ); + } + + if ( flags & BAR_LERP_COLOR ) { + CG_FillRect( x, y, w * frac, h, colorAtPos ); + } else { +// CG_FillRectGradient ( x, y, w * frac, h, startColor, endColor, 0 ); + CG_FillRect( x, y, w * frac, h, startColor ); + } + } + +} + + +/* +================= +CG_HorizontalPercentBar +================= +*/ +void CG_HorizontalPercentBar( float x, float y, float width, float height, float percent ) { + vec4_t bgcolor = {0.5f, 0.5f, 0.5f, 0.3f}, + color = {1.0f, 1.0f, 1.0f, 0.3f}; + CG_FilledBar( x, y, width, height, color, NULL, bgcolor, percent, BAR_BG | BAR_NOHUDALPHA ); +} + + +/* +================ +CG_DrawSides + +Coords are virtual 640x480 +================ +*/ +void CG_DrawSides( float x, float y, float w, float h, float size ) { + CG_AdjustFrom640( &x, &y, &w, &h ); + size *= cgs.screenXScale; + trap_R_DrawStretchPic( x, y, size, h, 0, 0, 0, 0, cgs.media.whiteShader ); + trap_R_DrawStretchPic( x + w - size, y, size, h, 0, 0, 0, 0, cgs.media.whiteShader ); +} + +void CG_DrawTopBottom( float x, float y, float w, float h, float size ) { + CG_AdjustFrom640( &x, &y, &w, &h ); + size *= cgs.screenYScale; + trap_R_DrawStretchPic( x, y, w, size, 0, 0, 0, 0, cgs.media.whiteShader ); + trap_R_DrawStretchPic( x, y + h - size, w, size, 0, 0, 0, 0, cgs.media.whiteShader ); +} + +/* +================ +UI_DrawRect + +Coordinates are 640*480 virtual values +================= +*/ +void CG_DrawRect( float x, float y, float width, float height, float size, const float *color ) { + vec4_t hudAlphaColor; + + Vector4Copy( color, hudAlphaColor ); + hudAlphaColor[3] *= cg_hudAlpha.value; + + trap_R_SetColor( hudAlphaColor ); + + CG_DrawTopBottom( x, y, width, height, size ); + CG_DrawSides( x, y, width, height, size ); + + trap_R_SetColor( NULL ); +} + + + +/* +================ +CG_DrawPic + +Coordinates are 640*480 virtual values +================= +*/ +void CG_DrawPic( float x, float y, float width, float height, qhandle_t hShader ) { + CG_AdjustFrom640( &x, &y, &width, &height ); + trap_R_DrawStretchPic( x, y, width, height, 0, 0, 1, 1, hShader ); +} + + + +/* +=============== +CG_DrawChar + +Coordinates and size in 640*480 virtual screen size +=============== +*/ +void CG_DrawChar( int x, int y, int width, int height, int ch ) { + int row, col; + float frow, fcol; + float size; + float ax, ay, aw, ah; + + ch &= 255; + + if ( ch == ' ' ) { + return; + } + + ax = x; + ay = y; + aw = width; + ah = height; + CG_AdjustFrom640( &ax, &ay, &aw, &ah ); + + row = ch >> 4; + col = ch & 15; + + frow = row * 0.0625; + fcol = col * 0.0625; + size = 0.0625; + + trap_R_DrawStretchPic( ax, ay, aw, ah, + fcol, frow, + fcol + size, frow + size, + cgs.media.charsetShader ); +} + +/* +=============== +CG_DrawChar2 + +Coordinates and size in 640*480 virtual screen size +=============== +*/ +void CG_DrawChar2( int x, int y, int width, int height, int ch ) { + int row, col; + float frow, fcol; + float size; + float ax, ay, aw, ah; + + ch &= 255; + + if ( ch == ' ' ) { + return; + } + + ax = x; + ay = y; + aw = width; + ah = height; + CG_AdjustFrom640( &ax, &ay, &aw, &ah ); + + row = ch >> 4; + col = ch & 15; + + frow = row * 0.0625; + fcol = col * 0.0625; + size = 0.0625; + + trap_R_DrawStretchPic( ax, ay, aw, ah, + fcol, frow, + fcol + size, frow + size, + cgs.media.menucharsetShader ); +} + +// JOSEPH 4-25-00 +/* +================== +CG_DrawStringExt + +Draws a multi-colored string with a drop shadow, optionally forcing +to a fixed color. + +Coordinates are at 640 by 480 virtual resolution +================== +*/ +void CG_DrawStringExt( int x, int y, const char *string, const float *setColor, + qboolean forceColor, qboolean shadow, int charWidth, int charHeight, int maxChars ) { + vec4_t color; + const /*unsigned*/ char *s; /*SEB*/ + int xx; + int cnt; + + if ( maxChars <= 0 ) { + maxChars = 32767; // do them all! + + } + // draw the drop shadow + if ( shadow ) { + color[0] = color[1] = color[2] = 0; + color[3] = setColor[3]; + trap_R_SetColor( color ); + s = string; + xx = x; + cnt = 0; + while ( *s && cnt < maxChars ) { + if ( Q_IsColorString( s ) ) { + s += 2; + continue; + } + CG_DrawChar( xx + 2, y + 2, charWidth, charHeight, *s ); + cnt++; + xx += charWidth; + s++; + } + } + + // draw the colored text + s = string; + xx = x; + cnt = 0; + trap_R_SetColor( setColor ); + while ( *s && cnt < maxChars ) { + if ( Q_IsColorString( s ) ) { + if ( !forceColor ) { + memcpy( color, g_color_table[ColorIndex( *( s + 1 ) )], sizeof( color ) ); + color[3] = setColor[3]; + trap_R_SetColor( color ); + } + s += 2; + continue; + } + CG_DrawChar( xx, y, charWidth, charHeight, *s ); + xx += charWidth; + cnt++; + s++; + } + trap_R_SetColor( NULL ); +} + +/*================== +CG_DrawStringExt2 + +Draws a multi-colored string with a drop shadow, optionally forcing +to a fixed color. + +Coordinates are at 640 by 480 virtual resolution +================== +*/ +void CG_DrawStringExt2( int x, int y, const char *string, const float *setColor, + qboolean forceColor, qboolean shadow, int charWidth, int charHeight, int maxChars ) { + vec4_t color; + const /*unsigned*/ char *s;/*SEB*/ + int xx; + int cnt; + + if ( maxChars <= 0 ) { + maxChars = 32767; // do them all! + + } + // draw the drop shadow + if ( shadow ) { + color[0] = color[1] = color[2] = 0; + color[3] = setColor[3]; + trap_R_SetColor( color ); + s = string; + xx = x; + cnt = 0; + while ( *s && cnt < maxChars ) { + if ( Q_IsColorString( s ) ) { + s += 2; + continue; + } + CG_DrawChar2( xx + 2, y + 2, charWidth, charHeight, *s ); + cnt++; + xx += charWidth; + s++; + } + } + + // draw the colored text + s = string; + xx = x; + cnt = 0; + trap_R_SetColor( setColor ); + while ( *s && cnt < maxChars ) { + if ( Q_IsColorString( s ) ) { + if ( !forceColor ) { + memcpy( color, g_color_table[ColorIndex( *( s + 1 ) )], sizeof( color ) ); + color[3] = setColor[3]; + trap_R_SetColor( color ); + } + s += 2; + continue; + } + CG_DrawChar2( xx, y, charWidth, charHeight, *s ); + xx += charWidth; + cnt++; + s++; + } + trap_R_SetColor( NULL ); +} + +/*================== +CG_DrawStringExt3 + +Draws a multi-colored string with a drop shadow, optionally forcing +to a fixed color. + +Coordinates are at 640 by 480 virtual resolution +================== +*/ +void CG_DrawStringExt3( int x, int y, const char *string, const float *setColor, + qboolean forceColor, qboolean shadow, int charWidth, int charHeight, int maxChars ) { + vec4_t color; + const /*unsigned*/ char *s;/*SEB*/ + int xx; + int cnt; + + if ( maxChars <= 0 ) { + maxChars = 32767; // do them all! + + } + s = string; + xx = 0; + + while ( *s ) { + xx += charWidth; + s++; + } + + x -= xx; + + s = string; + xx = x; + + // draw the drop shadow + if ( shadow ) { + color[0] = color[1] = color[2] = 0; + color[3] = setColor[3]; + trap_R_SetColor( color ); + s = string; + xx = x; + cnt = 0; + while ( *s && cnt < maxChars ) { + if ( Q_IsColorString( s ) ) { + s += 2; + continue; + } + CG_DrawChar2( xx + 2, y + 2, charWidth, charHeight, *s ); + cnt++; + xx += charWidth; + s++; + } + } + + // draw the colored text + s = string; + xx = x; + cnt = 0; + trap_R_SetColor( setColor ); + while ( *s && cnt < maxChars ) { + if ( Q_IsColorString( s ) ) { + if ( !forceColor ) { + memcpy( color, g_color_table[ColorIndex( *( s + 1 ) )], sizeof( color ) ); + color[3] = setColor[3]; + trap_R_SetColor( color ); + } + s += 2; + continue; + } + CG_DrawChar2( xx, y, charWidth, charHeight, *s ); + xx += charWidth; + cnt++; + s++; + } + trap_R_SetColor( NULL ); +} + +/* +================== +CG_DrawStringExt2 + +Draws a multi-colored string with a drop shadow, optionally forcing +to a fixed color. + +Coordinates are at 640 by 480 virtual resolution +================== +*/ +/*void CG_DrawStringExt2( int x, int y, const char *string, const float *setColor, + qboolean forceColor, qboolean shadow, int charWidth, int charHeight, int maxChars ) { + vec4_t color; + const char *s; + int xx; + int cnt; + + if (maxChars <= 0) + maxChars = 32767; // do them all! + + // draw the drop shadow + if (shadow) { + color[0] = color[1] = color[2] = 0; + color[3] = setColor[3]; + trap_R_SetColor( color ); + s = string; + xx = x; + cnt = 0; + while ( *s && cnt < maxChars) { + if ( Q_IsColorString( s ) ) { + s += 2; + continue; + } + CG_DrawChar2( xx + 2, y + 2, charWidth, charHeight, *s ); + cnt++; + xx += charWidth; + s++; + } + } + + // draw the colored text + s = string; + xx = x; + cnt = 0; + trap_R_SetColor( setColor ); + while ( *s && cnt < maxChars) { + if ( Q_IsColorString( s ) ) { + if ( !forceColor ) { + memcpy( color, g_color_table[ColorIndex(*(s+1))], sizeof( color ) ); + color[3] = setColor[3]; + trap_R_SetColor( color ); + } + s += 2; + continue; + } + CG_DrawChar2( xx, y, charWidth, charHeight, *s ); + xx += charWidth; + cnt++; + s++; + } + trap_R_SetColor( NULL ); +}*/ + +void CG_DrawBigString( int x, int y, const char *s, float alpha ) { + float color[4]; + + color[0] = color[1] = color[2] = 1.0; + color[3] = alpha; + //CG_DrawStringExt( x, y, s, color, qfalse, qtrue, BIGCHAR_WIDTH, BIGCHAR_HEIGHT, 0 ); + CG_DrawStringExt2( x, y, s, color, qfalse, qtrue, BIGCHAR_WIDTH, BIGCHAR_HEIGHT, 0 ); +} + +void CG_DrawBigStringColor( int x, int y, const char *s, vec4_t color ) { + //CG_DrawStringExt( x, y, s, color, qtrue, qtrue, BIGCHAR_WIDTH, BIGCHAR_HEIGHT, 0 ); + CG_DrawStringExt2( x, y, s, color, qfalse, qtrue, BIGCHAR_WIDTH, BIGCHAR_HEIGHT, 0 ); +} +// END JOSEPH + +// JOSEPH 4-25-00 +void CG_DrawBigString2( int x, int y, const char *s, float alpha ) { + float color[4]; + + color[0] = color[1] = color[2] = 1.0; + color[3] = alpha; + CG_DrawStringExt3( x, y, s, color, qfalse, qtrue, BIGCHAR_WIDTH, BIGCHAR_HEIGHT, 0 ); +} + +void CG_DrawBigStringColor2( int x, int y, const char *s, vec4_t color ) { + CG_DrawStringExt3( x, y, s, color, qfalse, qtrue, BIGCHAR_WIDTH, BIGCHAR_HEIGHT, 0 ); +} +// END JOSEPH + +void CG_DrawSmallString( int x, int y, const char *s, float alpha ) { + float color[4]; + + color[0] = color[1] = color[2] = 1.0; + color[3] = alpha; + CG_DrawStringExt( x, y, s, color, qfalse, qfalse, SMALLCHAR_WIDTH, SMALLCHAR_HEIGHT, 0 ); +} + +void CG_DrawSmallStringColor( int x, int y, const char *s, vec4_t color ) { + CG_DrawStringExt( x, y, s, color, qtrue, qfalse, SMALLCHAR_WIDTH, SMALLCHAR_HEIGHT, 0 ); +} + +/* +================= +CG_DrawStrlen + +Returns character count, skiping color escape codes +================= +*/ +int CG_DrawStrlen( const char *str ) { + const char *s = str; + int count = 0; + + while ( *s ) { + if ( Q_IsColorString( s ) ) { + s += 2; + } else { + count++; + s++; + } + } + + return count; +} + +/* +============= +CG_TileClearBox + +This repeats a 64*64 tile graphic to fill the screen around a sized down +refresh window. +============= +*/ +static void CG_TileClearBox( int x, int y, int w, int h, qhandle_t hShader ) { + float s1, t1, s2, t2; + s1 = x / 64.0; + t1 = y / 64.0; + s2 = ( x + w ) / 64.0; + t2 = ( y + h ) / 64.0; + trap_R_DrawStretchPic( x, y, w, h, s1, t1, s2, t2, hShader ); +} + + + +/* +============== +CG_TileClear + +Clear around a sized down screen +============== +*/ +void CG_TileClear( void ) { + int top, bottom, left, right; + int w, h; + + w = cgs.glconfig.vidWidth; + h = cgs.glconfig.vidHeight; + + if ( cg.refdef.x == 0 && cg.refdef.y == 0 && + cg.refdef.width == w && cg.refdef.height == h ) { + return; // full screen rendering + } + + top = cg.refdef.y; + bottom = top + cg.refdef.height - 1; + left = cg.refdef.x; + right = left + cg.refdef.width - 1; + + // clear above view screen + CG_TileClearBox( 0, 0, w, top, cgs.media.backTileShader ); + + // clear below view screen + CG_TileClearBox( 0, bottom, w, h - bottom, cgs.media.backTileShader ); + + // clear left of view screen + CG_TileClearBox( 0, top, left, bottom - top + 1, cgs.media.backTileShader ); + + // clear right of view screen + CG_TileClearBox( right, top, w - right, bottom - top + 1, cgs.media.backTileShader ); +} + + + +/* +================ +CG_FadeColor +================ +*/ +float *CG_FadeColor( int startMsec, int totalMsec ) { + static vec4_t color; + int t; + + if ( startMsec == 0 ) { + return NULL; + } + + t = cg.time - startMsec; + + if ( t >= totalMsec ) { + return NULL; + } + + // fade out + if ( totalMsec - t < FADE_TIME ) { + color[3] = ( totalMsec - t ) * 1.0 / FADE_TIME; + } else { + color[3] = 1.0; + } + color[0] = color[1] = color[2] = 1; + + return color; +} + + +/* +================ +CG_TeamColor +================ +*/ +float *CG_TeamColor( int team ) { + static vec4_t red = {1, 0.2, 0.2, 1}; + static vec4_t blue = {0.2, 0.2, 1, 1}; + static vec4_t other = {1, 1, 1, 1}; + static vec4_t spectator = {0.7, 0.7, 0.7, 1}; + + switch ( team ) { + case TEAM_RED: + return red; + case TEAM_BLUE: + return blue; + case TEAM_SPECTATOR: + return spectator; + default: + return other; + } +} + + +/* +================= +CG_GetColorForHealth +================= +*/ +void CG_GetColorForHealth( int health, int armor, vec4_t hcolor ) { + int count; + int max; + + // calculate the total points of damage that can + // be sustained at the current health / armor level + if ( health <= 0 ) { + VectorClear( hcolor ); // black + hcolor[3] = 1; + return; + } + count = armor; + max = health * ARMOR_PROTECTION / ( 1.0 - ARMOR_PROTECTION ); + if ( max < count ) { + count = max; + } + health += count; + + // set the color based on health + hcolor[0] = 1.0; + hcolor[3] = 1.0; + if ( health >= 100 ) { + hcolor[2] = 1.0; + } else if ( health < 66 ) { + hcolor[2] = 0; + } else { + hcolor[2] = ( health - 66 ) / 33.0; + } + + if ( health > 60 ) { + hcolor[1] = 1.0; + } else if ( health < 30 ) { + hcolor[1] = 0; + } else { + hcolor[1] = ( health - 30 ) / 30.0; + } +} + +/* +================= +CG_ColorForHealth +================= +*/ +void CG_ColorForHealth( vec4_t hcolor ) { + int health; + int count; + int max; + + // calculate the total points of damage that can + // be sustained at the current health / armor level + health = cg.snap->ps.stats[STAT_HEALTH]; + if ( health <= 0 ) { + VectorClear( hcolor ); // black + hcolor[3] = 1; + return; + } + count = cg.snap->ps.stats[STAT_ARMOR]; + max = health * ARMOR_PROTECTION / ( 1.0 - ARMOR_PROTECTION ); + if ( max < count ) { + count = max; + } + health += count; + + + // set the color based on health + hcolor[0] = 1.0; + hcolor[3] = 1.0; + if ( health >= 100 ) { + hcolor[2] = 1.0; + } else if ( health < 66 ) { + hcolor[2] = 0; + } else { + hcolor[2] = ( health - 66 ) / 33.0; + } + + if ( health > 60 ) { + hcolor[1] = 1.0; + } else if ( health < 30 ) { + hcolor[1] = 0; + } else { + hcolor[1] = ( health - 30 ) / 30.0; + } +} + + + + +/* +================= +UI_DrawProportionalString2 +================= +*/ +static int propMap[128][3] = { + {0, 0, -1}, {0, 0, -1}, {0, 0, -1}, {0, 0, -1}, {0, 0, -1}, {0, 0, -1}, {0, 0, -1}, {0, 0, -1}, + {0, 0, -1}, {0, 0, -1}, {0, 0, -1}, {0, 0, -1}, {0, 0, -1}, {0, 0, -1}, {0, 0, -1}, {0, 0, -1}, + + {0, 0, -1}, {0, 0, -1}, {0, 0, -1}, {0, 0, -1}, {0, 0, -1}, {0, 0, -1}, {0, 0, -1}, {0, 0, -1}, + {0, 0, -1}, {0, 0, -1}, {0, 0, -1}, {0, 0, -1}, {0, 0, -1}, {0, 0, -1}, {0, 0, -1}, {0, 0, -1}, + + {0, 0, PROP_SPACE_WIDTH}, // SPACE + {11, 122, 7}, // ! + {154, 181, 14}, // " + {55, 122, 17}, // # + {79, 122, 18}, // $ + {101, 122, 23}, // % + {153, 122, 18}, // & + {9, 93, 7}, // ' + {207, 122, 8}, // ( + {230, 122, 9}, // ) + {177, 122, 18}, // * + {30, 152, 18}, // + + {85, 181, 7}, // , + {34, 93, 11}, // - + {110, 181, 6}, // . + {130, 152, 14}, // / + + {22, 64, 17}, // 0 + {41, 64, 12}, // 1 + {58, 64, 17}, // 2 + {78, 64, 18}, // 3 + {98, 64, 19}, // 4 + {120, 64, 18}, // 5 + {141, 64, 18}, // 6 + {204, 64, 16}, // 7 + {162, 64, 17}, // 8 + {182, 64, 18}, // 9 + {59, 181, 7}, // : + {35,181, 7}, // ; + {203, 152, 14}, // < + {56, 93, 14}, // = + {228, 152, 14}, // > + {177, 181, 18}, // ? + + {28, 122, 22}, // @ + {5, 4, 18}, // A + {27, 4, 18}, // B + {48, 4, 18}, // C + {69, 4, 17}, // D + {90, 4, 13}, // E + {106, 4, 13}, // F + {121, 4, 18}, // G + {143, 4, 17}, // H + {164, 4, 8}, // I + {175, 4, 16}, // J + {195, 4, 18}, // K + {216, 4, 12}, // L + {230, 4, 23}, // M + {6, 34, 18}, // N + {27, 34, 18}, // O + + {48, 34, 18}, // P + {68, 34, 18}, // Q + {90, 34, 17}, // R + {110, 34, 18}, // S + {130, 34, 14}, // T + {146, 34, 18}, // U + {166, 34, 19}, // V + {185, 34, 29}, // W + {215, 34, 18}, // X + {234, 34, 18}, // Y + {5, 64, 14}, // Z + {60, 152, 7}, // [ + {106, 151, 13}, // '\' + {83, 152, 7}, // ] + {128, 122, 17}, // ^ + {4, 152, 21}, // _ + + {134, 181, 5}, // ' + {5, 4, 18}, // A + {27, 4, 18}, // B + {48, 4, 18}, // C + {69, 4, 17}, // D + {90, 4, 13}, // E + {106, 4, 13}, // F + {121, 4, 18}, // G + {143, 4, 17}, // H + {164, 4, 8}, // I + {175, 4, 16}, // J + {195, 4, 18}, // K + {216, 4, 12}, // L + {230, 4, 23}, // M + {6, 34, 18}, // N + {27, 34, 18}, // O + + {48, 34, 18}, // P + {68, 34, 18}, // Q + {90, 34, 17}, // R + {110, 34, 18}, // S + {130, 34, 14}, // T + {146, 34, 18}, // U + {166, 34, 19}, // V + {185, 34, 29}, // W + {215, 34, 18}, // X + {234, 34, 18}, // Y + {5, 64, 14}, // Z + {153, 152, 13}, // { + {11, 181, 5}, // | + {180, 152, 13}, // } + {79, 93, 17}, // ~ + {0, 0, -1} // DEL +}; + +static int propMapB[26][3] = { + {11, 12, 33}, + {49, 12, 31}, + {85, 12, 31}, + {120, 12, 30}, + {156, 12, 21}, + {183, 12, 21}, + {207, 12, 32}, + + {13, 55, 30}, + {49, 55, 13}, + {66, 55, 29}, + {101, 55, 31}, + {135, 55, 21}, + {158, 55, 40}, + {204, 55, 32}, + + {12, 97, 31}, + {48, 97, 31}, + {82, 97, 30}, + {118, 97, 30}, + {153, 97, 30}, + {185, 97, 25}, + {213, 97, 30}, + + {11, 139, 32}, + {42, 139, 51}, + {93, 139, 32}, + {126, 139, 31}, + {158, 139, 25}, +}; + +#define PROPB_GAP_WIDTH 4 +#define PROPB_SPACE_WIDTH 12 +#define PROPB_HEIGHT 36 + +/* +================= +UI_DrawBannerString +================= +*/ +static void UI_DrawBannerString2( int x, int y, const char* str, vec4_t color ) { + const char* s; + unsigned char ch; + float ax; + float ay; + float aw; + float ah; + float frow; + float fcol; + float fwidth; + float fheight; + + // draw the colored text + trap_R_SetColor( color ); + + ax = x * cgs.screenXScale + cgs.screenXBias; + ay = y * cgs.screenXScale; + + s = str; + while ( *s ) + { + ch = *s & 127; + if ( ch == ' ' ) { + ax += ( (float)PROPB_SPACE_WIDTH + (float)PROPB_GAP_WIDTH ) * cgs.screenXScale; + } else if ( Q_isupper( ch ) ) { + ch -= 'A'; + fcol = (float)propMapB[ch][0] / 256.0f; + frow = (float)propMapB[ch][1] / 256.0f; + fwidth = (float)propMapB[ch][2] / 256.0f; + fheight = (float)PROPB_HEIGHT / 256.0f; + aw = (float)propMapB[ch][2] * cgs.screenXScale; + ah = (float)PROPB_HEIGHT * cgs.screenXScale; + trap_R_DrawStretchPic( ax, ay, aw, ah, fcol, frow, fcol + fwidth, frow + fheight, cgs.media.charsetPropB ); + ax += ( aw + (float)PROPB_GAP_WIDTH * cgs.screenXScale ); + } + s++; + } + + trap_R_SetColor( NULL ); +} + +void UI_DrawBannerString( int x, int y, const char* str, int style, vec4_t color ) { + const char * s; + int ch; + int width; + vec4_t drawcolor; + + // find the width of the drawn text + s = str; + width = 0; + while ( *s ) { + ch = *s; + if ( ch == ' ' ) { + width += PROPB_SPACE_WIDTH; + } else if ( ch >= 'A' && ch <= 'Z' ) { + width += propMapB[ch - 'A'][2] + PROPB_GAP_WIDTH; + } + s++; + } + width -= PROPB_GAP_WIDTH; + + switch ( style & UI_FORMATMASK ) { + case UI_CENTER: + x -= width / 2; + break; + + case UI_RIGHT: + x -= width; + break; + + case UI_LEFT: + default: + break; + } + + if ( style & UI_DROPSHADOW ) { + drawcolor[0] = drawcolor[1] = drawcolor[2] = 0; + drawcolor[3] = color[3]; + UI_DrawBannerString2( x + 2, y + 2, str, drawcolor ); + } + + UI_DrawBannerString2( x, y, str, color ); +} + + +int UI_ProportionalStringWidth( const char* str ) { + const char * s; + int ch; + int charWidth; + int width; + + s = str; + width = 0; + while ( *s ) { + ch = *s & 127; + charWidth = propMap[ch][2]; + if ( charWidth != -1 ) { + width += charWidth; + width += PROP_GAP_WIDTH; + } + s++; + } + + width -= PROP_GAP_WIDTH; + return width; +} + +static void UI_DrawProportionalString2( int x, int y, const char* str, vec4_t color, float sizeScale, qhandle_t charset ) { + const char* s; + unsigned char ch; + float ax; + float ay; + float aw; + float ah; + float frow; + float fcol; + float fwidth; + float fheight; + + // draw the colored text + trap_R_SetColor( color ); + + ax = x * cgs.screenXScale + cgs.screenXBias; + ay = y * cgs.screenXScale; + + s = str; + while ( *s ) + { + ch = *s & 127; + if ( ch == ' ' ) { + aw = (float)PROP_SPACE_WIDTH * cgs.screenXScale * sizeScale; + } else if ( propMap[ch][2] != -1 ) { + fcol = (float)propMap[ch][0] / 256.0f; + frow = (float)propMap[ch][1] / 256.0f; + fwidth = (float)propMap[ch][2] / 256.0f; + fheight = (float)PROP_HEIGHT / 256.0f; + aw = (float)propMap[ch][2] * cgs.screenXScale * sizeScale; + ah = (float)PROP_HEIGHT * cgs.screenXScale * sizeScale; + trap_R_DrawStretchPic( ax, ay, aw, ah, fcol, frow, fcol + fwidth, frow + fheight, charset ); + } else { + aw = 0; + } + + ax += ( aw + (float)PROP_GAP_WIDTH * cgs.screenXScale * sizeScale ); + s++; + } + + trap_R_SetColor( NULL ); +} + +/* +================= +UI_ProportionalSizeScale +================= +*/ +float UI_ProportionalSizeScale( int style ) { + if ( style & UI_SMALLFONT ) { + return 0.75; + } + if ( style & UI_EXSMALLFONT ) { + return 0.4; + } + + return 1.00; +} + + +/* +================= +UI_DrawProportionalString +================= +*/ +void UI_DrawProportionalString( int x, int y, const char* str, int style, vec4_t color ) { + vec4_t drawcolor; + int width; + float sizeScale; + + sizeScale = UI_ProportionalSizeScale( style ); + + switch ( style & UI_FORMATMASK ) { + case UI_CENTER: + width = UI_ProportionalStringWidth( str ) * sizeScale; + x -= width / 2; + break; + + case UI_RIGHT: + width = UI_ProportionalStringWidth( str ) * sizeScale; + x -= width; + break; + + case UI_LEFT: + default: + break; + } + + if ( style & UI_DROPSHADOW ) { + drawcolor[0] = drawcolor[1] = drawcolor[2] = 0; + drawcolor[3] = color[3]; + UI_DrawProportionalString2( x + 2, y + 2, str, drawcolor, sizeScale, cgs.media.charsetProp ); + } + + if ( style & UI_INVERSE ) { + drawcolor[0] = color[0] * 0.8; + drawcolor[1] = color[1] * 0.8; + drawcolor[2] = color[2] * 0.8; + drawcolor[3] = color[3]; + UI_DrawProportionalString2( x, y, str, drawcolor, sizeScale, cgs.media.charsetProp ); + return; + } + + // JOSEPH 12-29-99 + if ( style & UI_PULSE ) { + //drawcolor[0] = color[0] * 0.8; + //drawcolor[1] = color[1] * 0.8; + //drawcolor[2] = color[2] * 0.8; + drawcolor[3] = color[3]; + UI_DrawProportionalString2( x, y, str, color, sizeScale, cgs.media.charsetProp ); + + drawcolor[0] = color[0]; + drawcolor[1] = color[1]; + drawcolor[2] = color[2]; + drawcolor[3] = 0.5 + 0.5 * sin( cg.time / PULSE_DIVISOR ); + UI_DrawProportionalString2( x, y, str, drawcolor, sizeScale, cgs.media.charsetPropGlow ); + return; + } + // END JOSEPH + + UI_DrawProportionalString2( x, y, str, color, sizeScale, cgs.media.charsetProp ); +} + + + + + + + + + + + + + + + diff --git a/Projects/Android/jni/rtcw/src/cgame/cg_effects.c b/Projects/Android/jni/rtcw/src/cgame/cg_effects.c new file mode 100644 index 0000000..65edb62 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/cgame/cg_effects.c @@ -0,0 +1,1708 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +// cg_effects.c -- these functions generate localentities, usually as a result +// of event processing + +#include "cg_local.h" + + +/* +================== +CG_BubbleTrail + +Bullets shot underwater +================== +*/ +void CG_BubbleTrail( vec3_t start, vec3_t end, float size, float spacing ) { + vec3_t move; + vec3_t vec; + float len; + int i; + + return; + + VectorCopy( start, move ); + VectorSubtract( end, start, vec ); + len = VectorNormalize( vec ); + + // advance a random amount first + i = rand() % (int)spacing; + VectorMA( move, i, vec, move ); + + VectorScale( vec, spacing, vec ); + + for ( ; i < len; i += spacing ) { + localEntity_t *le; + refEntity_t *re; + + le = CG_AllocLocalEntity(); + le->leFlags = LEF_PUFF_DONT_SCALE; + le->leType = LE_MOVE_SCALE_FADE; + le->startTime = cg.time; + le->endTime = cg.time + 1000 + random() * 250; + le->lifeRate = 1.0 / ( le->endTime - le->startTime ); + + re = &le->refEntity; + re->shaderTime = cg.time / 1000.0f; + + re->reType = RT_SPRITE; + re->rotation = 0; +// re->radius = 3; + re->radius = size; // (SA) + re->customShader = cgs.media.waterBubbleShader; + re->shaderRGBA[0] = 0xff; + re->shaderRGBA[1] = 0xff; + re->shaderRGBA[2] = 0xff; + re->shaderRGBA[3] = 0xff; + + le->color[3] = 1.0; + + le->pos.trType = TR_LINEAR; + le->pos.trTime = cg.time; + VectorCopy( move, le->pos.trBase ); + le->pos.trDelta[0] = crandom() * 3; + le->pos.trDelta[1] = crandom() * 3; +// le->pos.trDelta[2] = crandom()*5 + 6; + le->pos.trDelta[2] = crandom() * 5 + 20; // (SA) + + VectorAdd( move, vec, move ); + } +} + +/* +===================== +CG_SmokePuff + +Adds a smoke puff or blood trail localEntity. + +(SA) boy, it would be nice to have an acceleration vector for this as well. + big velocity vector with a negative acceleration for deceleration, etc. + (breath could then come out of a guys mouth at the rate he's walking/running and it + would slow down once it's created) +===================== +*/ + +//----(SA) modified +localEntity_t *CG_SmokePuff( const vec3_t p, const vec3_t vel, + float radius, + float r, float g, float b, float a, + float duration, + int startTime, + int fadeInTime, + int leFlags, + qhandle_t hShader ) { + static int seed = 0x92; + localEntity_t *le; + refEntity_t *re; + + le = CG_AllocLocalEntity(); + le->leFlags = leFlags; + le->radius = radius; + + re = &le->refEntity; + re->rotation = Q_random( &seed ) * 360; + re->radius = radius; + re->shaderTime = startTime / 1000.0f; + + le->leType = LE_MOVE_SCALE_FADE; + le->startTime = startTime; + le->endTime = startTime + duration; + le->fadeInTime = fadeInTime; + if ( fadeInTime > startTime ) { + le->lifeRate = 1.0 / ( le->endTime - le->fadeInTime ); + } else { + le->lifeRate = 1.0 / ( le->endTime - le->startTime ); + } + le->color[0] = r; + le->color[1] = g; + le->color[2] = b; + le->color[3] = a; + + + le->pos.trType = TR_LINEAR; + le->pos.trTime = startTime; + VectorCopy( vel, le->pos.trDelta ); + VectorCopy( p, le->pos.trBase ); + + VectorCopy( p, re->origin ); + re->customShader = hShader; + + // rage pro can't alpha fade, so use a different shader + if ( cgs.glconfig.hardwareType == GLHW_RAGEPRO ) { + re->customShader = cgs.media.smokePuffRageProShader; + re->shaderRGBA[0] = 0xff; + re->shaderRGBA[1] = 0xff; + re->shaderRGBA[2] = 0xff; + re->shaderRGBA[3] = 0xff; + } else { + re->shaderRGBA[0] = le->color[0] * 0xff; + re->shaderRGBA[1] = le->color[1] * 0xff; + re->shaderRGBA[2] = le->color[2] * 0xff; + re->shaderRGBA[3] = 0xff; + } + + re->reType = RT_SPRITE; + re->radius = le->radius; + + return le; +} + +/* +================== +CG_SpawnEffect + +Player teleporting in or out +================== +*/ +void CG_SpawnEffect( vec3_t org ) { + localEntity_t *le; + refEntity_t *re; + + return; // (SA) don't play spawn in effect right now + + le = CG_AllocLocalEntity(); + le->leFlags = 0; + le->leType = LE_FADE_RGB; + le->startTime = cg.time; + le->endTime = cg.time + 500; + le->lifeRate = 1.0 / ( le->endTime - le->startTime ); + + le->color[0] = le->color[1] = le->color[2] = le->color[3] = 1.0; + + re = &le->refEntity; + + re->reType = RT_MODEL; + re->shaderTime = cg.time / 1000.0f; + + re->customShader = cgs.media.teleportEffectShader; + re->hModel = cgs.media.teleportEffectModel; + AxisClear( re->axis ); + + VectorCopy( org, re->origin ); + re->origin[2] -= 24; +} + + + + +/* +==================== +CG_MakeExplosion +==================== +*/ +localEntity_t *CG_MakeExplosion( vec3_t origin, vec3_t dir, + qhandle_t hModel, qhandle_t shader, + int msec, qboolean isSprite ) { + float ang; + localEntity_t *ex; + int offset; + vec3_t tmpVec, newOrigin; + + if ( msec <= 0 ) { + CG_Error( "CG_MakeExplosion: msec = %i", msec ); + } + + // skew the time a bit so they aren't all in sync + offset = rand() & 63; + + ex = CG_AllocLocalEntity(); + if ( isSprite ) { + ex->leType = LE_SPRITE_EXPLOSION; + + // randomly rotate sprite orientation + ex->refEntity.rotation = rand() % 360; + VectorScale( dir, 16, tmpVec ); + VectorAdd( tmpVec, origin, newOrigin ); + } else { + ex->leType = LE_EXPLOSION; + VectorCopy( origin, newOrigin ); + + // set axis with random rotate + if ( !dir ) { + AxisClear( ex->refEntity.axis ); + } else { + ang = rand() % 360; + VectorCopy( dir, ex->refEntity.axis[0] ); + RotateAroundDirection( ex->refEntity.axis, ang ); + } + } + + ex->startTime = cg.time - offset; + ex->endTime = ex->startTime + msec; + + // bias the time so all shader effects start correctly + ex->refEntity.shaderTime = ex->startTime / 1000.0f; + + ex->refEntity.hModel = hModel; + ex->refEntity.customShader = shader; + + // set origin + VectorCopy( newOrigin, ex->refEntity.origin ); + VectorCopy( newOrigin, ex->refEntity.oldorigin ); + + // Ridah, move away from the wall as the sprite expands + ex->pos.trType = TR_LINEAR; + ex->pos.trTime = cg.time; + VectorCopy( newOrigin, ex->pos.trBase ); + VectorScale( dir, 48, ex->pos.trDelta ); + // done. + + ex->color[0] = ex->color[1] = ex->color[2] = 1.0; + + return ex; +} + +/* +================= +CG_AddBloodTrails +================= +*/ +void CG_AddBloodTrails( vec3_t origin, vec3_t dir, int speed, int duration, int count, float randScale ) { + localEntity_t *le; + refEntity_t *re; + vec3_t velocity; + int i; + + for ( i = 0; i < count; i++ ) { + le = CG_AllocLocalEntity(); + re = &le->refEntity; + + VectorSet( velocity, dir[0] + crandom() * randScale, dir[1] + crandom() * randScale, dir[2] + crandom() * randScale ); + VectorScale( velocity, (float)speed, velocity ); + + le->leType = LE_BLOOD; + le->startTime = cg.time; + le->endTime = le->startTime + duration - (int)( 0.5 * random() * duration ); + le->lastTrailTime = cg.time; + + VectorCopy( origin, re->origin ); + AxisCopy( axisDefault, re->axis ); + + le->pos.trType = TR_GRAVITY_LOW; + VectorCopy( origin, le->pos.trBase ); + VectorMA( le->pos.trBase, 2 + random() * 4, dir, le->pos.trBase ); + VectorCopy( velocity, le->pos.trDelta ); + le->pos.trTime = cg.time; + + le->bounceFactor = 0.9; + } +} + +/* +================= +CG_Bleed + +This is the spurt of blood when a character gets hit +================= +*/ +void CG_Bleed( vec3_t origin, int entityNum ) { +#define BLOOD_SPURT_COUNT 4 + int i,j; +// localEntity_t *ex; + centity_t *cent; +// vec3_t dir; + + if ( !cg_blood.integer ) { + return; + } + + if ( cg_reloading.integer ) { + return; // to dangerous, since we call playerangles() in here, which calls the animation system, which might not be setup yet + } + + cent = &cg_entities[entityNum]; + + if ( cent->currentState.aiChar == AICHAR_ZOMBIE ) { + CG_ParticleBloodCloudZombie( cent, origin, vec3_origin ); + return; + } + +/* + ex = CG_AllocLocalEntity(); + ex->leType = LE_EXPLOSION; + + ex->startTime = cg.time; + ex->endTime = ex->startTime + 500; + + VectorCopy ( origin, ex->refEntity.origin); + ex->refEntity.reType = RT_SPRITE; + ex->refEntity.rotation = rand() % 360; + ex->refEntity.radius = 3; + + ex->refEntity.customShader = cgs.media.bloodExplosionShader; + + // don't show player's own blood in view + if ( entityNum == cg.snap->ps.clientNum ) { + ex->refEntity.renderfx |= RF_THIRD_PERSON; + } +*/ + // Ridah, blood spurts + if ( entityNum != cg.snap->ps.clientNum ) { + vec3_t vhead, vlegs, vtorso, bOrigin, dir, vec, pvec, ndir; + + CG_GetBleedOrigin( vhead, vtorso, vlegs, entityNum ); + + // project the impact point onto the vector defined by torso -> head + ProjectPointOntoVector( origin, vtorso, vhead, bOrigin ); + + // if it's below the waste, or above the head, clamp + VectorSubtract( vhead, vtorso, vec ); + VectorSubtract( bOrigin, vtorso, pvec ); + if ( DotProduct( pvec, vec ) < 0 ) { + VectorCopy( vtorso, bOrigin ); + } else { + VectorSubtract( bOrigin, vhead, pvec ); + if ( DotProduct( pvec, vec ) > 0 ) { + VectorCopy( vhead, bOrigin ); + } + } + + // spawn some blood trails, heading out towards the impact point + VectorSubtract( origin, bOrigin, dir ); + VectorNormalize( dir ); + + { + float len; + vec3_t vec; + + VectorSubtract( bOrigin, vhead, vec ); + len = VectorLength( vec ); + + if ( len > 8 ) { + VectorMA( bOrigin, 8, dir, bOrigin ); + } + } + + + for ( i = 0; i < BLOOD_SPURT_COUNT; i++ ) { + VectorCopy( dir, ndir ); + for ( j = 0; j < 3; j++ ) ndir[j] += crandom() * 0.3; + VectorNormalize( ndir ); + CG_AddBloodTrails( bOrigin, ndir, + 100, // speed + 250 + (int)( crandom() * 50 ), // duration + 3 + rand() % 2, // count + 0.1 ); // rand scale + } + + } + // done. +} + + + +/* +================== +CG_LaunchGib +================== +*/ +void CG_LaunchGib( centity_t *cent, vec3_t origin, vec3_t angles, vec3_t velocity, qhandle_t hModel, float sizeScale, int breakCount ) { + localEntity_t *le; + refEntity_t *re; + int i; + + le = CG_AllocLocalEntity(); + re = &le->refEntity; + + le->leType = LE_FRAGMENT; + le->startTime = cg.time; + // le->endTime = le->startTime + 60000 + random() * 60000; + le->endTime = le->startTime + 20000 + ( crandom() * 5000 ); + le->breakCount = breakCount; + le->sizeScale = sizeScale; + + VectorCopy( angles, le->angles.trBase ); + VectorCopy( origin, re->origin ); + AnglesToAxis( angles, re->axis ); + if ( sizeScale != 1.0 ) { + for ( i = 0; i < 3; i++ ) VectorScale( re->axis[i], sizeScale, re->axis[i] ); + } + re->hModel = hModel; + + switch ( cent->currentState.aiChar ) { + case AICHAR_ZOMBIE: + le->pos.trType = TR_GRAVITY_LOW; + le->angles.trDelta[0] = 400 * crandom(); + le->angles.trDelta[1] = 400 * crandom(); + le->angles.trDelta[2] = 400 * crandom(); + + le->leBounceSoundType = LEBS_BONE; + + le->bounceFactor = 0.5; + break; + case AICHAR_HEINRICH: + case AICHAR_HELGA: + le->endTime = le->startTime + 999000; // stay around for long enough to see the player off + default: + le->leBounceSoundType = LEBS_BLOOD; + le->leMarkType = LEMT_BLOOD; + le->pos.trType = TR_GRAVITY; + + le->angles.trDelta[0] = ( 10 + ( rand() & 50 ) ) - 30; + // le->angles.trDelta[0] = (100 + (rand()&500)) - 300; // pitch + le->angles.trDelta[1] = ( 100 + ( rand() & 500 ) ) - 300; // (SA) this is the safe one right now (yaw) turn the others up when I have tumbling things landing properly + le->angles.trDelta[2] = ( 10 + ( rand() & 50 ) ) - 30; + // le->angles.trDelta[2] = (100 + (rand()&500)) - 300; // roll + + le->bounceFactor = 0.3; + break; + } + + if ( cent->currentState.aiChar == AICHAR_HELGA || cent->currentState.aiChar == AICHAR_HEINRICH ) { + // bit bouncier + //le->pos.trType = TR_GRAVITY_LOW; + le->bounceFactor = 0.4; + //if (VectorLength( velocity ) < 300) { + // VectorScale( velocity, 300.0 / VectorLength( velocity ), velocity ); + //} + } + + VectorCopy( origin, le->pos.trBase ); + VectorCopy( velocity, le->pos.trDelta ); + le->pos.trTime = cg.time; + + re->fadeStartTime = le->endTime - 1000; + re->fadeEndTime = le->endTime; + + le->angles.trType = TR_LINEAR; + + le->angles.trTime = cg.time; + + le->ownerNum = cent->currentState.number; + + // Ridah, if the player is on fire, then spawn some flaming gibs + if ( cent && CG_EntOnFire( cent ) ) { + le->onFireStart = cent->currentState.onFireStart; + le->onFireEnd = re->fadeEndTime + 1000; + } else if ( ( cent->currentState.aiChar == AICHAR_ZOMBIE ) && IS_FLAMING_ZOMBIE( cent->currentState ) ) { + le->onFireStart = cg.time - 1000; + le->onFireEnd = re->fadeEndTime + 1000; + } +} + +//#define GIB_VELOCITY 250 +//#define GIB_JUMP 250 + +#define GIB_VELOCITY 75 +#define GIB_JUMP 250 + + +/* +============== +CG_LoseHat +============== +*/ +void CG_LoseHat( centity_t *cent, vec3_t dir ) { + clientInfo_t *ci; + int clientNum; +// int i, count, tagIndex, gibIndex; + int tagIndex; + vec3_t origin, velocity; + + clientNum = cent->currentState.clientNum; + if ( clientNum < 0 || clientNum >= MAX_CLIENTS ) { + CG_Error( "Bad clientNum on player entity" ); + } + ci = &cgs.clientinfo[ clientNum ]; + + if ( !ci->accModels[ACC_HAT] ) { // don't launch anything if they don't have one + return; + } + + tagIndex = CG_GetOriginForTag( cent, ¢->pe.headRefEnt, "tag_mouth", 0, origin, NULL ); + + velocity[0] = dir[0] * ( 0.75 + random() ) * GIB_VELOCITY; + velocity[1] = dir[1] * ( 0.75 + random() ) * GIB_VELOCITY; + velocity[2] = GIB_JUMP - 50 + dir[2] * ( 0.5 + random() ) * GIB_VELOCITY; + + { + localEntity_t *le; + refEntity_t *re; + + le = CG_AllocLocalEntity(); + re = &le->refEntity; + + le->leType = LE_FRAGMENT; + le->startTime = cg.time; + le->endTime = le->startTime + 20000 + ( crandom() * 5000 ); + + VectorCopy( origin, re->origin ); + AxisCopy( axisDefault, re->axis ); + re->hModel = ci->accModels[ACC_HAT]; + + re->fadeStartTime = le->endTime - 1000; + re->fadeEndTime = le->endTime; + + // (SA) FIXME: origin of hat md3 is offset from center. need to center the origin when you toss it + le->pos.trType = TR_GRAVITY; + VectorCopy( origin, le->pos.trBase ); + VectorCopy( velocity, le->pos.trDelta ); + le->pos.trTime = cg.time; + + // spin it a bit + le->angles.trType = TR_LINEAR; + VectorCopy( tv( 0, 0, 0 ), le->angles.trBase ); + le->angles.trDelta[0] = 0; + le->angles.trDelta[1] = ( 100 + ( rand() & 500 ) ) - 300; +// le->angles.trDelta[2] = 0; + le->angles.trDelta[2] = 400; // (SA) this is set with a very particular value to try to get it + // to flip exactly once before landing (based on player alive + // (standing) and on level ground) and will be unnecessary when + // I have things landing properly on their own + + le->angles.trTime = cg.time; + + le->bounceFactor = 0.2; + + // Ridah, if the player is on fire, then make the hat on fire + if ( cent && CG_EntOnFire( cent ) ) { + le->onFireStart = cent->currentState.onFireStart; + le->onFireEnd = cent->currentState.onFireEnd + 4000; + } + } +} +/* +============== +CG_GibHead + + FIXME: accept the cent as parameter, and use it to grab the head position + from the model TAG's +============== +*/ +void CG_GibHead( vec3_t headOrigin ) { + vec3_t origin, velocity; + + VectorCopy( headOrigin, origin ); + velocity[0] = crandom() * GIB_VELOCITY; + velocity[1] = crandom() * GIB_VELOCITY; + velocity[2] = GIB_JUMP + crandom() * GIB_VELOCITY; + CG_LaunchGib( NULL, origin, vec3_origin, velocity, cgs.media.gibSkull, 1.0, 0 ); + + VectorCopy( headOrigin, origin ); + velocity[0] = crandom() * GIB_VELOCITY; + velocity[1] = crandom() * GIB_VELOCITY; + velocity[2] = GIB_JUMP + crandom() * GIB_VELOCITY; + CG_LaunchGib( NULL, origin, vec3_origin, velocity, cgs.media.gibBrain, 1.0, 0 ); + +} + +/* +====================== +CG_GetOriginForTag + + places the position of the tag into "org" + + returns the index of the tag it used, so we can cycle through tag's with the same name +====================== +*/ +int CG_GetOriginForTag( centity_t *cent, refEntity_t *parent, char *tagName, int startIndex, vec3_t org, vec3_t axis[3] ) { + int i; + orientation_t lerped; + int retval; + + // lerp the tag + retval = trap_R_LerpTag( &lerped, parent, tagName, startIndex ); + + if ( retval < 0 ) { + return retval; + } + + VectorCopy( parent->origin, org ); + + for ( i = 0 ; i < 3 ; i++ ) { + VectorMA( org, lerped.origin[i], parent->axis[i], org ); + } + + if ( axis ) { + // had to cast away the const to avoid compiler problems... + MatrixMultiply( lerped.axis, ( (refEntity_t *)parent )->axis, axis ); + } + + return retval; +} + +/* +=================== +CG_GibPlayer + +Generated a bunch of gibs launching out from the bodies location +=================== +*/ +#define MAXJUNCTIONS 8 + +void CG_GibPlayer( centity_t *cent, vec3_t playerOrigin, vec3_t gdir ) { + vec3_t origin, velocity, dir; + int i, count, tagIndex, gibIndex; + trace_t trace; + qboolean foundtag; + + clientInfo_t *ci; + int clientNum; + + // Rafael + // BloodCloud + qboolean newjunction[MAXJUNCTIONS]; + vec3_t junctionOrigin[MAXJUNCTIONS]; + int junction; + int j; + float size; + vec3_t axis[3], angles; + + char *JunctiongibTags[] = { + // leg tag + "tag_footright", + "tag_footleft", + "tag_legright", + "tag_legleft", + + // torsotags + "tag_armright", + "tag_armleft", + + "tag_torso", + "tag_chest" + }; + + char *ConnectTags[] = { + // legs tags + "tag_legright", + "tag_legleft", + "tag_torso", + "tag_torso", + + // torso tags + "tag_chest", + "tag_chest", + + "tag_chest", + "tag_torso", + }; + + // FIXME: let them specify tag & model in the cfg file? + + // (SA) and perhaps which body part that tag is attached to? + + char *gibTags[] = { + // tags in the legs + "tag_footright", + "tag_footleft", + "tag_legright", + "tag_legleft", + "tag_torso", + + // tags in the torso + "tag_chest", + "tag_armright", + "tag_armleft", + "tag_head", + NULL + }; + +#define TORSOTAGSSTART 5 // where the 'split' happens in the above table + + + // Rafael + for ( i = 0; i < MAXJUNCTIONS; i++ ) + newjunction[i] = qfalse; + + clientNum = cent->currentState.clientNum; + if ( clientNum < 0 || clientNum >= MAX_CLIENTS ) { + CG_Error( "Bad clientNum on player entity" ); + } + ci = &cgs.clientinfo[ clientNum ]; + + // Ridah, fetch the various positions of the tag_gib*'s + // and spawn the gibs from the correct places (especially the head) + for ( gibIndex = 0, count = 0, foundtag = qtrue; foundtag && gibIndex < MAX_GIB_MODELS && gibTags[gibIndex]; gibIndex++ ) { + + refEntity_t *re = 0; + + foundtag = qfalse; + + if ( !ci->gibModels[gibIndex] ) { + continue; + } + + // (SA) split this into torso and legs, since the tags are only attached to the appropriate part +// if(gibIndex >= TORSOTAGSSTART) + re = ¢->pe.torsoRefEnt; +// else +// re = ¢->pe.legsRefEnt; + + for ( tagIndex = 0; ( tagIndex = CG_GetOriginForTag( cent, re, gibTags[gibIndex], tagIndex, origin, axis ) ) >= 0; count++, tagIndex++ ) { + + foundtag = qtrue; + + VectorSubtract( origin, re->origin, dir ); + VectorNormalize( dir ); + + // spawn a gib + velocity[0] = dir[0] * ( 0.5 + random() ) * GIB_VELOCITY * 0.3; + velocity[1] = dir[1] * ( 0.5 + random() ) * GIB_VELOCITY * 0.3; + velocity[2] = GIB_JUMP + dir[2] * ( 0.5 + random() ) * GIB_VELOCITY * 0.5; + + VectorMA( velocity, GIB_VELOCITY, gdir, velocity ); + + AxisToAngles( axis, angles ); + + // RF, Zombies dying by particle effect dont spawn gibs + if ( ( cent->currentState.aiChar == AICHAR_ZOMBIE ) || + ( cent->currentState.aiChar == AICHAR_HELGA ) || + ( cent->currentState.aiChar == AICHAR_HEINRICH ) ) { + //VectorScale( velocity, 4, velocity ); + size = 0.6 + 0.4 * random(); + if ( ( cent->currentState.aiChar == AICHAR_HELGA ) || ( cent->currentState.aiChar == AICHAR_HEINRICH ) ) { + //size *= 3.0; + velocity[0] = crandom() * GIB_VELOCITY * 1.0; + velocity[1] = crandom() * GIB_VELOCITY * 1.0; + velocity[2] = GIB_JUMP + crandom() * GIB_VELOCITY; + // additional gibs + CG_LaunchGib( cent, origin, angles, velocity, ci->gibModels[gibIndex], size, 1 ); + CG_LaunchGib( cent, origin, angles, velocity, ci->gibModels[gibIndex], size, 1 ); + } else { + CG_LaunchGib( cent, origin, angles, velocity, ci->gibModels[gibIndex], size, 1 + (int)( 2.0 * ( size - 0.4 ) ) ); + } + } else { + CG_LaunchGib( cent, origin, angles, velocity, ci->gibModels[gibIndex], 1.0, 0 ); + } + + for ( junction = 0; junction < MAXJUNCTIONS; junction++ ) + { + if ( !Q_stricmp( gibTags[gibIndex], JunctiongibTags[junction] ) ) { + VectorCopy( origin, junctionOrigin[junction] ); + newjunction[junction] = qtrue; + } + } + } + } + + + for ( i = 0; i < MAXJUNCTIONS; i++ ) + { + if ( newjunction[i] == qtrue ) { + for ( j = 0; j < MAXJUNCTIONS; j++ ) + { + if ( !Q_stricmp( JunctiongibTags[j], ConnectTags[i] ) ) { + if ( newjunction[j] == qtrue ) { + // spawn a blood cloud somewhere on the vec from + VectorSubtract( junctionOrigin[i], junctionOrigin[j], dir ); + + // ok now lets spawn a little blood + if ( cent->currentState.aiChar == AICHAR_ZOMBIE ) { + CG_ParticleBloodCloudZombie( cent, junctionOrigin[i], dir ); + } else { + CG_ParticleBloodCloud( cent, junctionOrigin[i], dir ); + } + + // RF, also spawn some blood in this direction + VectorMA( junctionOrigin[i], 2.0, dir, origin ); + if ( cent->currentState.aiChar == AICHAR_ZOMBIE ) { + CG_ParticleBloodCloudZombie( cent, origin, dir ); + } else { + CG_ParticleBloodCloud( cent, origin, dir ); + } + + // Zombies spawn more bones + if ( ( cent->currentState.aiChar == AICHAR_ZOMBIE ) || + ( cent->currentState.aiChar == AICHAR_HEINRICH ) || + ( cent->currentState.aiChar == AICHAR_HELGA ) ) { + // spawn a gib + VectorCopy( junctionOrigin[i], origin ); + + if ( ( cent->currentState.aiChar == AICHAR_HELGA ) || ( cent->currentState.aiChar == AICHAR_HEINRICH ) ) { + size *= 3.0; + velocity[0] = crandom() * GIB_VELOCITY * 2.0; + velocity[1] = crandom() * GIB_VELOCITY * 2.0; + velocity[2] = GIB_JUMP + random() * GIB_VELOCITY; + } else { + velocity[0] = dir[0] * ( 0.5 + random() ) * GIB_VELOCITY * 0.3; + velocity[1] = dir[1] * ( 0.5 + random() ) * GIB_VELOCITY * 0.3; + velocity[2] = GIB_JUMP + dir[2] * ( 0.5 + random() ) * GIB_VELOCITY * 0.5; + VectorMA( velocity, GIB_VELOCITY, gdir, velocity ); + } + + vectoangles( dir, angles ); + + VectorScale( velocity, 3, velocity ); + size = 0.6 + 0.4 * random(); + if ( ( cent->currentState.aiChar == AICHAR_HELGA ) || ( cent->currentState.aiChar == AICHAR_HEINRICH ) ) { + CG_LaunchGib( cent, origin, angles, velocity, ci->gibModels[rand() % 4], size, 1 ); + } else { + CG_LaunchGib( cent, origin, angles, velocity, ci->gibModels[rand() % 4], size, 1 + (int)( 2.0 * ( size - 0.4 ) ) ); + } + } + } + } + } + } + } + + if ( !count ) { + + // CG_Printf("falling back to old-style gibs\n"); + + // old style gibs + + VectorCopy( playerOrigin, origin ); + velocity[0] = crandom() * GIB_VELOCITY; + velocity[1] = crandom() * GIB_VELOCITY; + velocity[2] = GIB_JUMP + crandom() * GIB_VELOCITY; + if ( rand() & 1 ) { + CG_LaunchGib( cent, origin, vec3_origin, velocity, cgs.media.gibSkull, 1.0, 0 ); + } else { + CG_LaunchGib( cent, origin, vec3_origin, velocity, cgs.media.gibBrain, 1.0, 0 ); + } + + // allow gibs to be turned off for speed + if ( !cg_gibs.integer ) { + return; + } + + VectorCopy( playerOrigin, origin ); + velocity[0] = crandom() * GIB_VELOCITY; + velocity[1] = crandom() * GIB_VELOCITY; + velocity[2] = GIB_JUMP + crandom() * GIB_VELOCITY; + CG_LaunchGib( cent, origin, vec3_origin, velocity, cgs.media.gibAbdomen, 1.0, 0 ); + + VectorCopy( playerOrigin, origin ); + velocity[0] = crandom() * GIB_VELOCITY; + velocity[1] = crandom() * GIB_VELOCITY; + velocity[2] = GIB_JUMP + crandom() * GIB_VELOCITY; + CG_LaunchGib( cent, origin, vec3_origin, velocity, cgs.media.gibArm, 1.0, 0 ); + + VectorCopy( playerOrigin, origin ); + velocity[0] = crandom() * GIB_VELOCITY; + velocity[1] = crandom() * GIB_VELOCITY; + velocity[2] = GIB_JUMP + crandom() * GIB_VELOCITY; + CG_LaunchGib( cent, origin, vec3_origin, velocity, cgs.media.gibChest, 1.0, 0 ); + + VectorCopy( playerOrigin, origin ); + velocity[0] = crandom() * GIB_VELOCITY; + velocity[1] = crandom() * GIB_VELOCITY; + velocity[2] = GIB_JUMP + crandom() * GIB_VELOCITY; + CG_LaunchGib( cent, origin, vec3_origin, velocity, cgs.media.gibFist, 1.0, 0 ); + + VectorCopy( playerOrigin, origin ); + velocity[0] = crandom() * GIB_VELOCITY; + velocity[1] = crandom() * GIB_VELOCITY; + velocity[2] = GIB_JUMP + crandom() * GIB_VELOCITY; + CG_LaunchGib( cent, origin, vec3_origin, velocity, cgs.media.gibFoot, 1.0, 0 ); + + VectorCopy( playerOrigin, origin ); + velocity[0] = crandom() * GIB_VELOCITY; + velocity[1] = crandom() * GIB_VELOCITY; + velocity[2] = GIB_JUMP + crandom() * GIB_VELOCITY; + CG_LaunchGib( cent, origin, vec3_origin, velocity, cgs.media.gibForearm, 1.0, 0 ); + + VectorCopy( playerOrigin, origin ); + velocity[0] = crandom() * GIB_VELOCITY; + velocity[1] = crandom() * GIB_VELOCITY; + velocity[2] = GIB_JUMP + crandom() * GIB_VELOCITY; + CG_LaunchGib( cent, origin, vec3_origin, velocity, cgs.media.gibIntestine, 1.0, 0 ); + + VectorCopy( playerOrigin, origin ); + velocity[0] = crandom() * GIB_VELOCITY; + velocity[1] = crandom() * GIB_VELOCITY; + velocity[2] = GIB_JUMP + crandom() * GIB_VELOCITY; + CG_LaunchGib( cent, origin, vec3_origin, velocity, cgs.media.gibLeg, 1.0, 0 ); + } + + +//----(SA) toss the hat + if ( !( cent->currentState.eFlags & EF_HEADSHOT ) ) { // (SA) already lost hat while living + CG_LoseHat( cent, tv( 0, 0, 1 ) ); + } +//----(SA) end + + // Ridah, spawn a bunch of blood dots around the place + #define GIB_BLOOD_DOTS 4 + for ( i = 0, count = 0; i < GIB_BLOOD_DOTS * 2; i++ ) { + //static vec3_t mins = {-10,-10,-10}; // TTimo: unused + //static vec3_t maxs = { 10, 10, 10}; // TTimo: unused + + if ( i > 0 ) { + velocity[0] = ( ( i % 2 ) * 2 - 1 ) * ( 40 + 40 * random() ); + velocity[1] = ( ( ( i / 2 ) % 2 ) * 2 - 1 ) * ( 40 + 40 * random() ); + velocity[2] = ( ( ( i < GIB_BLOOD_DOTS ) * 2 ) - 1 ) * 40; + } else { + VectorClear( velocity ); + velocity[2] = -64; + } + + VectorAdd( playerOrigin, velocity, origin ); + + CG_Trace( &trace, playerOrigin, NULL, NULL, origin, -1, CONTENTS_SOLID ); + if ( trace.fraction < 1.0 ) { + BG_GetMarkDir( velocity, trace.plane.normal, velocity ); + CG_ImpactMark( cgs.media.bloodDotShaders[rand() % 5], trace.endpos, velocity, random() * 360, + 1,1,1,1, qtrue, 30, qfalse, cg_bloodTime.integer * 1000 ); + if ( count++ > GIB_BLOOD_DOTS ) { + break; + } + } + } + +} + + +/* +============== +CG_SparklerSparks +============== +*/ +void CG_SparklerSparks( vec3_t origin, int count ) { +// these effect the look of the, umm, effect + int FUSE_SPARK_LIFE = 100; + int FUSE_SPARK_LENGTH = 30; +// these are calculated from the above + int FUSE_SPARK_SPEED = ( FUSE_SPARK_LENGTH * 1000 / FUSE_SPARK_LIFE ); + + int i; + localEntity_t *le; + refEntity_t *re; + + for ( i = 0; i < count; i++ ) { + + // spawn the spark + le = CG_AllocLocalEntity(); + re = &le->refEntity; + + le->leType = LE_FUSE_SPARK; + le->startTime = cg.time; + le->endTime = cg.time + FUSE_SPARK_LIFE; + le->lastTrailTime = cg.time; + + VectorCopy( origin, re->origin ); + + le->pos.trType = TR_GRAVITY; + VectorCopy( origin, le->pos.trBase ); + VectorSet( le->pos.trDelta, crandom(), crandom(), crandom() ); + VectorNormalize( le->pos.trDelta ); + VectorScale( le->pos.trDelta, FUSE_SPARK_SPEED, le->pos.trDelta ); + le->pos.trTime = cg.time; + + } +} + +// just a bunch of numbers we can use for pseudo-randomizing based on time +#define NUMRANDTABLE 257 +unsigned short randtable[NUMRANDTABLE] = +{ + 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7, + 0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef, + 0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6, + 0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de, + 0x2462, 0x3443, 0x0420, 0x1401, 0x64e6, 0x74c7, 0x44a4, 0x5485, + 0xa56a, 0xb54b, 0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d, + 0x3653, 0x2672, 0x1611, 0x0630, 0x76d7, 0x66f6, 0x5695, 0x46b4, + 0xb75b, 0xa77a, 0x9719, 0x8738, 0xf7df, 0xe7fe, 0xd79d, 0xc7bc, + 0x48c4, 0x58e5, 0x6886, 0x78a7, 0x0840, 0x1861, 0x2802, 0x3823, + 0xc9cc, 0xd9ed, 0xe98e, 0xf9af, 0x8948, 0x9969, 0xa90a, 0xb92b, + 0x5af5, 0x4ad4, 0x7ab7, 0x6a96, 0x1a71, 0x0a50, 0x3a33, 0x2a12, + 0xdbfd, 0xcbdc, 0xfbbf, 0xeb9e, 0x9b79, 0x8b58, 0xbb3b, 0xab1a, + 0x6ca6, 0x7c87, 0x4ce4, 0x5cc5, 0x2c22, 0x3c03, 0x0c60, 0x1c41, + 0xedae, 0xfd8f, 0xcdec, 0xddcd, 0xad2a, 0xbd0b, 0x8d68, 0x9d49, + 0x7e97, 0x6eb6, 0x5ed5, 0x4ef4, 0x3e13, 0x2e32, 0x1e51, 0x0e70, + 0xff9f, 0xefbe, 0xdfdd, 0xcffc, 0xbf1b, 0xaf3a, 0x9f59, 0x8f78, + 0x9188, 0x81a9, 0xb1ca, 0xa1eb, 0xd10c, 0xc12d, 0xf14e, 0xe16f, + 0x1080, 0x00a1, 0x30c2, 0x20e3, 0x5004, 0x4025, 0x7046, 0x6067, + 0x83b9, 0x9398, 0xa3fb, 0xb3da, 0xc33d, 0xd31c, 0xe37f, 0xf35e, + 0x02b1, 0x1290, 0x22f3, 0x32d2, 0x4235, 0x5214, 0x6277, 0x7256, + 0xb5ea, 0xa5cb, 0x95a8, 0x8589, 0xf56e, 0xe54f, 0xd52c, 0xc50d, + 0x34e2, 0x24c3, 0x14a0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405, + 0xa7db, 0xb7fa, 0x8799, 0x97b8, 0xe75f, 0xf77e, 0xc71d, 0xd73c, + 0x26d3, 0x36f2, 0x0691, 0x16b0, 0x6657, 0x7676, 0x4615, 0x5634, + 0xd94c, 0xc96d, 0xf90e, 0xe92f, 0x99c8, 0x89e9, 0xb98a, 0xa9ab, + 0x5844, 0x4865, 0x7806, 0x6827, 0x18c0, 0x08e1, 0x3882, 0x28a3, + 0xcb7d, 0xdb5c, 0xeb3f, 0xfb1e, 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a, + 0x4a75, 0x5a54, 0x6a37, 0x7a16, 0x0af1, 0x1ad0, 0x2ab3, 0x3a92, + 0xfd2e, 0xed0f, 0xdd6c, 0xcd4d, 0xbdaa, 0xad8b, 0x9de8, 0x8dc9, + 0x7c26, 0x6c07, 0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0x0cc1, + 0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8, + 0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0 +}; + +#define LT_MS 100 // random number will change every LT_MS millseconds +#define LT_RANDMAX ( (unsigned short)0xffff ) + +float lt_random( int thisrandseed, int t ) { + return (float)randtable[abs( ( thisrandseed + t + ( cg.time / LT_MS ) * ( cg.time / LT_MS ) ) ) % NUMRANDTABLE] / (float)LT_RANDMAX; +} + +float lt_crandom( int thisrandseed, int t ) { + return ( ( 2.0 * ( (float)randtable[abs( ( thisrandseed + t + ( cg.time / LT_MS ) * ( cg.time / LT_MS ) ) ) % NUMRANDTABLE] / (float)LT_RANDMAX ) ) - 1.0 ); +} + +/* +=============== +CG_DynamicLightningBolt +=============== +*/ +void CG_DynamicLightningBolt( qhandle_t shader, vec3_t start, vec3_t pend, int numBolts, float maxWidth, qboolean fade, float startAlpha, int recursion, int randseed ) { + int i,j; + float segMin, segMax, length; + float thisSeg, distLeft, thisWidth; + vec3_t pos, vec, end; + int curJunc; + vec3_t c, bc = {0.8,0.9,1}; + const float rndSize = 12.0; + const float maxSTscale = 30.0; + float stScale; + float alpha, viewDist; + const int trailLife = 1; + int forks = 0; + #define STYPE_LIGHTNING STYPE_REPEAT // ST mapping for trail + #define FORK_CHANCE 0.5 + #define VIEW_SCALE_DIST 128 + + VectorCopy( pend, end ); // need this so recursive calls don't override stacked endpoints + + // HACK, updated sprite, so downscale all widths + maxWidth *= 0.6; + + length = Distance( start, end ); + //if (length > 128) { + segMin = length / 10.0; + if ( segMin < 8 ) { + segMin = 8; + } + segMax = segMin * 1.2; + //segMax = length / 30.0; + //} else { + // segMin = length / 3.0; + // segMax = length / 1.5; + //} + + if ( startAlpha > 1.0 ) { + startAlpha = 1.0; + } + alpha = startAlpha; // change only if fading + + for ( i = 0; i < numBolts; i++ ) + { + distLeft = length; + VectorCopy( start, pos ); + // drop a start junction + stScale = maxSTscale * ( 0.5 + lt_random( randseed,i + 1 ) * 0.5 ); + if ( fade ) { + if ( startAlpha == 1.0 ) { + alpha = startAlpha * ( distLeft / length ); + } else { + alpha = 1.0 - 1.0 * fabs( ( 1.0 - ( distLeft / length ) ) - startAlpha ); + if ( alpha < 0 ) { + alpha = 0; + } + if ( alpha > 1 ) { + alpha = 1; + } + } + } + thisWidth = maxWidth * ( 0.5 + 0.5 * alpha ); + if ( ( viewDist = VectorDistance( pos, cg.refdef.vieworg ) ) < VIEW_SCALE_DIST ) { + thisWidth *= 0.5 + ( 0.5 * ( viewDist / VIEW_SCALE_DIST ) ); + if ( thisWidth < 4.0 && thisWidth < maxWidth ) { + thisWidth = 4.0; + } + } else { // scale it wider with distance so it remains visible + thisWidth *= 0.5 + ( 0.5 * ( viewDist / VIEW_SCALE_DIST ) ); + if ( thisWidth > maxWidth * 2 ) { + // thisWidth > maxWidth*2; + thisWidth = maxWidth * 2; + } + } + // + VectorScale( bc, alpha, c ); + c[2] *= 1.0 + ( 1.0 - alpha ); + if ( c[2] > 1.0 ) { + c[2] = 1.0; + } + // + curJunc = CG_AddTrailJunc( 0, shader, cg.time, STYPE_LIGHTNING, pos, trailLife, 1, 1, thisWidth, thisWidth, TJFL_NOCULL, c, c, stScale, 20.0 ); + while ( distLeft > 0 ) + { // create this bolt + thisSeg = segMin + ( segMax - segMin ) * lt_random( randseed,2 ); + thisWidth = maxWidth * ( 0.5 + 0.5 * alpha ); + if ( thisSeg >= distLeft - rndSize ) { // go directly to the end point + VectorCopy( end, pos ); + thisWidth *= 0.6; + } else if ( (float)distLeft / length < 0.3 ) { + VectorSubtract( end, pos, vec ); + VectorNormalize( vec ); + VectorMA( pos, thisSeg, vec, pos ); + // randomize the position a bit + thisSeg *= 0.05; + if ( thisSeg > rndSize ) { + thisSeg = rndSize; + } + for ( j = 0; j < 3; j++ ) { + viewDist = lt_crandom( randseed * randseed,j * j + i * i + 3 ); + if ( fabs( viewDist ) < 0.5 ) { + if ( viewDist > 0 ) { + viewDist = 0.5; + } else { viewDist = -0.5;} + } + pos[j] += viewDist * thisSeg; + } + } else { + VectorSubtract( end, pos, vec ); + VectorNormalize( vec ); + VectorMA( pos, thisSeg, vec, pos ); + // randomize the position a bit + thisSeg *= 0.25; + if ( thisSeg > rndSize ) { + thisSeg = rndSize; + } + for ( j = 0; j < 3; j++ ) { + viewDist = lt_crandom( randseed,j * j + i * i + 3 ); + if ( fabs( viewDist ) < 0.5 ) { + if ( viewDist > 0 ) { + viewDist = 0.5; + } else { viewDist = -0.5;} + } + pos[j] += viewDist * thisSeg; + } + } + + distLeft = Distance( pos, end ); + if ( fade ) { + if ( startAlpha == 1.0 ) { + alpha = startAlpha * ( distLeft / length ); + } else { + alpha = 1.0 - 1.0 * fabs( ( 1.0 - ( distLeft / length ) ) - startAlpha ); + if ( alpha < 0 ) { + alpha = 0; + } + if ( alpha > 1 ) { + alpha = 1; + } + } + } + //thisWidth *= alpha; + if ( ( viewDist = VectorDistance( pos, cg.refdef.vieworg ) ) < VIEW_SCALE_DIST ) { + thisWidth *= 0.5 + ( 0.5 * ( viewDist / VIEW_SCALE_DIST ) ); + if ( thisWidth < 4.0 && thisWidth < maxWidth ) { + thisWidth = 4.0; + } + } else { // scale it wider with distance so it remains visible + thisWidth *= 0.5 + ( 0.5 * ( viewDist / VIEW_SCALE_DIST ) ); + if ( thisWidth > maxWidth * 2 ) { + // thisWidth > maxWidth*2; + thisWidth = maxWidth * 2; + } + + } + // + VectorScale( bc, alpha, c ); + c[2] *= 1.0 + ( 1.0 - alpha ); + if ( c[2] > 1.0 ) { + c[2] = 1.0; + } + // + //stScale = maxSTscale * (0.4 + lt_random(randseed,1)*0.6); + curJunc = CG_AddTrailJunc( curJunc, shader, cg.time, STYPE_LIGHTNING, pos, trailLife, 1, 1, thisWidth, thisWidth, TJFL_NOCULL, c, c, stScale, 20.0 ); + + // fork from here? + if ( thisWidth < 4 && distLeft > 10 && recursion < 3 && forks < 3 && lt_random( randseed,383 + i + forks ) < FORK_CHANCE ) { + vec3_t fend; + forks++; + VectorSet( fend, + distLeft * 0.3 * lt_crandom( randseed,56 + i + forks ), + distLeft * 0.3 * lt_crandom( randseed,160 + i + forks ), + distLeft * 0.3 * lt_crandom( randseed,190 + i + forks ) ); + VectorAdd( fend, end, fend ); + VectorSubtract( fend, pos, fend ); + VectorMA( pos, 0.2 + 0.7 * lt_random( randseed,6 + i + forks ), fend, fend ); + + //if (recursion > 0 && recursion < 2) { + // CG_DynamicLightningBolt( cgs.media.lightningBoltShader, pos, fend, 1, maxWidth, qtrue, alpha, recursion, randseed ); + // return; // divert bolt rather than split + //} else { + CG_DynamicLightningBolt( shader, pos, fend, 1, maxWidth, qtrue, alpha, recursion + 1, randseed + 765 ); + //} + } + + randseed++; + + } + } +} + + + +/* +================ +CG_ProjectedSpotLight +================ +*/ +void CG_ProjectedSpotLight( vec3_t start, vec3_t dir ) { + vec3_t end, proj; + trace_t tr; + float alpha, radius; + + VectorMA( start, 1000, dir, end ); + CG_Trace( &tr, start, NULL, NULL, end, -1, CONTENTS_SOLID ); + if ( tr.fraction == 1.0 ) { + return; + } + // + alpha = ( 1.0 - tr.fraction ); + if ( alpha > 1.0 ) { + alpha = 1.0; + } + // + radius = 32 + 64 * tr.fraction; + VectorNegate( dir, proj ); + CG_ImpactMark( cgs.media.spotLightShader, tr.endpos, proj, 0, alpha, alpha, alpha, 1.0, qfalse, radius, qtrue, -2 ); +} + + +#define MAX_SPOT_SEGS 20 +#define MAX_SPOT_RANGE 2000 +/* +============== +CG_Spotlight + segs: number of sides on tube. - 999 is a valid value and just means, 'cap to max' (MAX_SPOT_SEGS) or use lod scheme + range: effective range of beam + startWidth: will be optimized for '0' as a value (true cone) to not use quads and not cap the start circle + + -- flags -- + SL_NOTRACE - don't do a trace check for shortening the beam, always draw at full 'range' length + SL_TRACEWORLDONLY - go through everything but the world + SL_NODLIGHT - don't put a dlight at the end + SL_NOSTARTCAP - dont' cap the start circle + SL_LOCKTRACETORANGE - only trace out as far as the specified range (rather than to max spot range) + SL_NOFLARE - don't draw a flare when the light is pointing at the camera + SL_NOIMPACT - don't draw the impact mark on hit surfaces + SL_LOCKUV - lock the texture coordinates at the 'true' length of the requested beam. + SL_NOCORE - don't draw the center 'core' beam + + + + + + + I know, this is a bit kooky right now. It evolved big, but now that I know what it should do, it'll get + crunched down to a bunch of table driven stuff. once it works, I'll make it work well... + +============== +*/ + +void CG_Spotlight( centity_t *cent, float *color, vec3_t realstart, vec3_t lightDir, int segs, float range, int startWidth, float coneAngle, int flags ) { + int i, j; + vec3_t start, traceEnd, proj; + vec3_t right, up; + vec3_t v1, v2; + vec3_t startvec, endvec; // the vectors to rotate around lightDir to create the circles + vec3_t conevec; + vec3_t start_points[MAX_SPOT_SEGS], end_points[MAX_SPOT_SEGS]; + vec3_t coreright; + polyVert_t verts[MAX_SPOT_SEGS * 4]; // x4 for 4 verts per poly + polyVert_t plugVerts[MAX_SPOT_SEGS]; + vec3_t endCenter; + polyVert_t coreverts[4]; + trace_t tr; + float /*alpha,*/ radius = 0.0f; // TTimo: init + float coreEndRadius; + qboolean capStart = qtrue; + float hitDist; // the actual distance of the trace impact (0 is no hit) + float beamLen; // actual distance of the drawn beam + float startAlpha, endAlpha; + vec4_t colorNorm; // normalized color vector + refEntity_t ent; + vec3_t angles; + float deadFrac = 0; + + VectorCopy( realstart, start ); + + // normalize color + colorNorm[3] = 0; // store normalize multiplier in alpha index + for ( i = 0; i < 3; i++ ) { + if ( color[i] > colorNorm[3] ) { + colorNorm[3] = color[i]; // find largest color value in RGB + } + } + + if ( colorNorm[3] != 1 ) { // it needs to be boosted + VectorMA( color, 1.0 / colorNorm[3], color, colorNorm ); // FIXME: div by 0 + } else { + VectorCopy( color, colorNorm ); + } + colorNorm[3] = color[3]; + + + if ( flags & SL_NOSTARTCAP ) { + capStart = qfalse; + } + + if ( startWidth == 0 ) { // cone, not cylinder + capStart = qfalse; + } + + + if ( flags & SL_LOCKTRACETORANGE ) { + VectorMA( start, range, lightDir, traceEnd ); // trace out to 'range' + } else { + VectorMA( start, MAX_SPOT_RANGE, lightDir, traceEnd ); // trace all the way out to max dist + } + + // first trace to see if anything is hit + if ( flags & SL_NOTRACE ) { + tr.fraction = 1.0; // force no hit + } else { + if ( flags & SL_TRACEWORLDONLY ) { + CG_Trace( &tr, start, NULL, NULL, traceEnd, -1, CONTENTS_SOLID ); + } else { +// CG_Trace( &tr, start, NULL, NULL, traceEnd, -1, MASK_SHOT); + CG_Trace( &tr, start, NULL, NULL, traceEnd, -1, MASK_SHOT & ~CONTENTS_BODY ); + } +// CG_Trace( &tr, start, NULL, NULL, traceEnd, -1, MASK_ALL &~(CONTENTS_MONSTERCLIP|CONTENTS_AREAPORTAL|CONTENTS_CLUSTERPORTAL)); + } + + + if ( tr.fraction < 1.0 ) { + hitDist = beamLen = MAX_SPOT_RANGE * tr.fraction; + if ( beamLen > range ) { + beamLen = range; + } + } else { + hitDist = 0; + beamLen = range; + } + + + startAlpha = color[3] * 255.0f; + endAlpha = 0.0f; + + + + if ( flags & SL_LOCKUV ) { + if ( beamLen < range ) { + endAlpha = 255.0f * ( color[3] - ( color[3] * beamLen / range ) ); + } + } + + + if ( segs >= MAX_SPOT_SEGS ) { + segs = MAX_SPOT_SEGS - 1; + } + + // TODO: adjust segs based on r_lodbias + // TODO: move much of this to renderer + + +// model at base +// if(cgs.media.spotLightLightModel) { + memset( &ent, 0, sizeof( ent ) ); + ent.frame = 0; + ent.oldframe = 0; + ent.backlerp = 0; + VectorCopy( cent->lerpOrigin, ent.origin ); + VectorCopy( cent->lerpOrigin, ent.oldorigin ); +// ent.hModel = cgs.gameModels[cent->currentState.modelindex]; + if ( cent->currentState.frame == 1 ) { + ent.hModel = cgs.media.spotLightLightModelBroke; + } else { + ent.hModel = cgs.media.spotLightLightModel; + } + + vectoangles( lightDir, angles ); + angles[ROLL] = 0.0f; // clear out roll so it doesn't interfere + AnglesToAxis( angles, ent.axis ); + trap_R_AddRefEntityToScene( &ent ); + + ent.hModel = cgs.media.spotLightBaseModel; + angles[PITCH] = 0.0f; // flatten out pitch so it only yaws + AnglesToAxis( angles, ent.axis ); + trap_R_AddRefEntityToScene( &ent ); + + // push start out a bit so the beam fits to the front of the base model + VectorMA( start, 14, lightDir, start ); +// } + + + + if ( cent->currentState.frame == 1 ) { // dead + deadFrac = (float)( cg.time - cent->currentState.time2 ) / 5000.0f; + + // no fade out, just off +// if(deadFrac > 1) + return; + + startAlpha *= ( 1.0f - deadFrac ); + endAlpha *= ( 1.0f - deadFrac ); + } + + +//// BEAM + + PerpendicularVector( up, lightDir ); + CrossProduct( lightDir, up, right ); + + // find first vert of the start + VectorScale( right, startWidth, startvec ); + // find the first vert of the end + RotatePointAroundVector( conevec, up, lightDir, -coneAngle ); + VectorMA( startvec, beamLen, conevec, endvec ); // this applies the offset of the start diameter before finding the end points + + VectorScale( lightDir, beamLen, endCenter ); + VectorSubtract( endCenter, endvec, coreverts[3].xyz ); // get a vector of the radius out at the end for the core to use + coreEndRadius = VectorLength( coreverts[3].xyz ); +#define CORESCALE 0.6f + +// +// generate the flat beam 'core' +// + if ( !( flags & SL_NOCORE ) ) { + VectorSubtract( start, cg.refdef.vieworg, v1 ); + VectorNormalize( v1 ); + VectorSubtract( traceEnd, cg.refdef.vieworg, v2 ); + VectorNormalize( v2 ); + CrossProduct( v1, v2, coreright ); + VectorNormalize( coreright ); + + memset( &coreverts[0], 0, 4 * sizeof( polyVert_t ) ); + VectorMA( start, startWidth * 0.8f, coreright, coreverts[0].xyz ); + VectorMA( start, -startWidth * 0.8f, coreright, coreverts[1].xyz ); + VectorMA( endCenter, -coreEndRadius * CORESCALE, coreright, coreverts[2].xyz ); + VectorAdd( start, coreverts[2].xyz, coreverts[2].xyz ); + VectorMA( endCenter, coreEndRadius * CORESCALE, coreright, coreverts[3].xyz ); + VectorAdd( start, coreverts[3].xyz, coreverts[3].xyz ); + + for ( i = 0; i < 4; i++ ) { + coreverts[i].modulate[0] = color[0] * 200.0f; + coreverts[i].modulate[1] = color[1] * 200.0f; + coreverts[i].modulate[2] = color[2] * 200.0f; + coreverts[i].modulate[3] = startAlpha; + if ( i > 1 ) { + coreverts[i].modulate[3] = endAlpha; + } + } + + trap_R_AddPolyToScene( cgs.media.spotLightBeamShader, 4, &coreverts[0] ); + } + + +// +// generate the beam cylinder +// + + + + for ( i = 0; i <= segs; i++ ) { + RotatePointAroundVector( start_points[i], lightDir, startvec, ( 360.0f / (float)segs ) * i ); + VectorAdd( start_points[i], start, start_points[i] ); + + RotatePointAroundVector( end_points[i], lightDir, endvec, ( 360.0f / (float)segs ) * i ); + VectorAdd( end_points[i], start, end_points[i] ); + } + + for ( i = 0; i < segs; i++ ) { + + j = ( i * 4 ); + + VectorCopy( start_points[i], verts[( i * 4 )].xyz ); + verts[j].st[0] = 0; + verts[j].st[1] = 1; + verts[j].modulate[0] = color[0] * 255.0f; + verts[j].modulate[1] = color[1] * 255.0f; + verts[j].modulate[2] = color[2] * 255.0f; + verts[j].modulate[3] = startAlpha; + j++; + + VectorCopy( end_points[i], verts[j].xyz ); + verts[j].st[0] = 0; + verts[j].st[1] = 0; + verts[j].modulate[0] = color[0] * 255.0f; + verts[j].modulate[1] = color[1] * 255.0f; + verts[j].modulate[2] = color[2] * 255.0f; + verts[j].modulate[3] = endAlpha; + j++; + + VectorCopy( end_points[i + 1], verts[j].xyz ); + verts[j].st[0] = 1; + verts[j].st[1] = 0; + verts[j].modulate[0] = color[0] * 255.0f; + verts[j].modulate[1] = color[1] * 255.0f; + verts[j].modulate[2] = color[2] * 255.0f; + verts[j].modulate[3] = endAlpha; + j++; + + VectorCopy( start_points[i + 1], verts[j].xyz ); + verts[j].st[0] = 1; + verts[j].st[1] = 1; + verts[j].modulate[0] = color[0] * 255.0f; + verts[j].modulate[1] = color[1] * 255.0f; + verts[j].modulate[2] = color[2] * 255.0f; + verts[j].modulate[3] = startAlpha; + + if ( capStart ) { + VectorCopy( start_points[i], plugVerts[i].xyz ); + plugVerts[i].st[0] = 0; + plugVerts[i].st[1] = 0; + plugVerts[i].modulate[0] = color[0] * 255.0f; + plugVerts[i].modulate[1] = color[1] * 255.0f; + plugVerts[i].modulate[2] = color[2] * 255.0f; + plugVerts[i].modulate[3] = startAlpha; + } + } + + trap_R_AddPolysToScene( cgs.media.spotLightBeamShader, 4, &verts[0], segs ); + + + // plug up the start circle + if ( capStart ) { + trap_R_AddPolyToScene( cgs.media.spotLightBeamShader, segs, &plugVerts[0] ); + } + + + // show the endpoint + + if ( !( flags & SL_NOIMPACT ) ) { + if ( hitDist ) { + vec3_t impactPos; + VectorMA( startvec, hitDist, conevec, endvec ); + + radius = 1.5f * coreEndRadius * ( hitDist / beamLen ); + + VectorNegate( lightDir, proj ); + + VectorMA( tr.endpos, -0.5f * radius, lightDir, impactPos ); // back away a little from the hit + + CG_ImpactMark( cgs.media.spotLightShader, impactPos, proj, 0, colorNorm[0], colorNorm[1], colorNorm[2], 0.3f, qfalse, radius, qtrue, -1 ); +// CG_ImpactMark( cgs.media.spotLightShader, tr.endpos, proj, 0, colorNorm[0], colorNorm[1], colorNorm[2], 1.0f, qfalse, radius, qtrue, -1 ); + } + } + + + + // add d light at end + if ( !( flags & SL_NODLIGHT ) ) { + vec3_t dlightLoc; +// VectorMA(tr.endpos, -60, lightDir, dlightLoc); // back away from the hit + VectorMA( tr.endpos, 0, lightDir, dlightLoc ); // back away from the hit +// trap_R_AddLightToScene(dlightLoc, 200, colorNorm[0], colorNorm[1], colorNorm[2], 0); // ,REF_JUNIOR_DLIGHT); +// trap_R_AddLightToScene(dlightLoc, radius*2, colorNorm[0], colorNorm[1], colorNorm[2], 0); // ,REF_JUNIOR_DLIGHT); + trap_R_AddLightToScene( dlightLoc, radius * 2, 0.3, 0.3, 0.3, 0 ); // ,REF_JUNIOR_DLIGHT); + } + + +#define FLAREANGLE 35 + + // draw flare at source + if ( !( flags & SL_NOFLARE ) ) { + qboolean lightInEyes = qfalse; + vec3_t camloc, dirtolight; + float dot, deg, dist; + float flarescale = 0.0f; // TTimo: init + + // get camera position and direction to lightsource + VectorCopy( cg.snap->ps.origin, camloc ); + camloc[2] += cg.snap->ps.viewheight; + VectorSubtract( start, camloc, dirtolight ); + dist = VectorNormalize( dirtolight ); + + // first use dot to determine if it's facing the camera + dot = DotProduct( lightDir, dirtolight ); + + // it's facing the camera, find out how closely and trace to see if the source can be seen + + deg = RAD2DEG( M_PI - acos( dot ) ); + if ( deg <= FLAREANGLE ) { // start flare a bit before the camera gets inside the cylinder + lightInEyes = qtrue; + flarescale = 1 - ( deg / FLAREANGLE ); + } + + if ( lightInEyes ) { // the dot check succeeded, now do a trace +// CG_Trace( &tr, start, NULL, NULL, camloc, -1, MASK_ALL &~(CONTENTS_MONSTERCLIP|CONTENTS_AREAPORTAL|CONTENTS_CLUSTERPORTAL)); + CG_Trace( &tr, start, NULL, NULL, camloc, -1, MASK_SOLID ); + if ( tr.fraction != 1 ) { + lightInEyes = qfalse; + } + + } + + if ( lightInEyes ) { + float coronasize = flarescale; + if ( dist < 512 ) { // make even bigger if you're close enough + coronasize *= ( 512.0f / dist ); + } + + trap_R_AddCoronaToScene( start, colorNorm[0], colorNorm[1], colorNorm[2], coronasize, cent->currentState.number, 3 ); // 1&2 ('visible' & 'spotlightflare') + } else { + // even though it's off, still need to add it, but turned off so it can fade in/out properly + trap_R_AddCoronaToScene( start, colorNorm[0], colorNorm[1], colorNorm[2], 0, cent->currentState.number, 2 ); // 0&2 ('not visible' & 'spotlightflare') + } + } + +} + + + +/* +============== +CG_RumbleEfx +============== +*/ +void CG_RumbleEfx( float pitch, float yaw ) { + float pitchRecoilAdd, pitchAdd; + float yawRandom; + vec3_t recoil; + + // + pitchRecoilAdd = 0; + pitchAdd = 0; + yawRandom = 0; + // + + if ( pitch < 1 ) { + pitch = 1; + } + + pitchRecoilAdd = pow( random(),8 ) * ( 10 + VectorLength( cg.snap->ps.velocity ) / 5 ); + pitchAdd = ( rand() % (int)pitch ) - ( pitch * 0.5 ); //5 + yawRandom = yaw; //2 + + pitchRecoilAdd *= 0.5; + pitchAdd *= 0.5; + yawRandom *= 0.5; + + // calc the recoil + recoil[YAW] = crandom() * yawRandom; + recoil[ROLL] = -recoil[YAW]; // why not + recoil[PITCH] = -pitchAdd; + // scale it up a bit (easier to modify this while tweaking) + VectorScale( recoil, 30, recoil ); + // set the recoil + VectorCopy( recoil, cg.kickAVel ); + // set the recoil + cg.recoilPitch -= pitchRecoilAdd; +} + + + diff --git a/Projects/Android/jni/rtcw/src/cgame/cg_ents.c b/Projects/Android/jni/rtcw/src/cgame/cg_ents.c new file mode 100644 index 0000000..791e852 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/cgame/cg_ents.c @@ -0,0 +1,2680 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +/* + * name: cg_ents.c + * + * desc: present snapshot entities, happens every single frame + * +*/ + + +#include "cg_local.h" + +/////////////////////// +extern int propellerModel; +/////////////////////// + + + +/* +====================== +CG_PositionEntityOnTag + +Modifies the entities position and axis by the given +tag location +====================== +*/ +void CG_PositionEntityOnTag( refEntity_t *entity, const refEntity_t *parent, + char *tagName, int startIndex, vec3_t *offset ) { + int i; + orientation_t lerped; + + // lerp the tag + trap_R_LerpTag( &lerped, parent, tagName, startIndex ); + + // FIXME: allow origin offsets along tag? //----(SA) Yes! Adding. + + VectorCopy( parent->origin, entity->origin ); + + if ( offset ) { + VectorAdd( lerped.origin, *offset, lerped.origin ); + } +//----(SA) end + + for ( i = 0 ; i < 3 ; i++ ) { + VectorMA( entity->origin, lerped.origin[i], parent->axis[i], entity->origin ); + } + + // had to cast away the const to avoid compiler problems... + MatrixMultiply( lerped.axis, ( (refEntity_t *)parent )->axis, entity->axis ); + // Ridah, not sure why this was here.. causes jittery torso animation, since the torso might have + // different frame/oldFrame + //entity->backlerp = parent->backlerp; +} + + +/* +====================== +CG_PositionRotatedEntityOnTag + +Modifies the entities position and axis by the given +tag location +====================== +*/ +void CG_PositionRotatedEntityOnTag( refEntity_t *entity, const refEntity_t *parent, + char *tagName ) { + int i; + orientation_t lerped; + vec3_t tempAxis[3]; + +//AxisClear( entity->axis ); + // lerp the tag + trap_R_LerpTag( &lerped, parent, tagName, 0 ); + + // FIXME: allow origin offsets along tag? + VectorCopy( parent->origin, entity->origin ); + for ( i = 0 ; i < 3 ; i++ ) { + VectorMA( entity->origin, lerped.origin[i], parent->axis[i], entity->origin ); + } + + // had to cast away the const to avoid compiler problems... + MatrixMultiply( entity->axis, lerped.axis, tempAxis ); + MatrixMultiply( tempAxis, ( (refEntity_t *)parent )->axis, entity->axis ); +} + + +//----(SA) added +/* +============== +CG_LoseArmor + maybe better in cg_localents.c +============== +*/ +void CG_LoseArmor( centity_t *cent, int index ) { + char *protoTags[] = { "tag_chest", + "tag_calfleft", + "tag_armleft", + "tag_back", + "tag_legleft", + "tag_calfright", + "tag_armright", + "tag_back", + "tag_legright"}; + + char *ssTags[] = { "tag_chest", + "tag_calfleft", + "tag_armleft", + "tag_back", + "tag_legleft", + "tag_calfright", + "tag_armright", + "tag_back", + "tag_legright", + + "tag_footleft", + "tag_footright", + "tag_sholeft", + "tag_shoright", + "tag_torso", + "tag_calfleft", + "tag_calfright"}; + + char *heinrichTags[] = {"tag_chest", + "tag_calfleft", + "tag_armleft", + "tag_back", + "tag_legleft", + "tag_calfright", + "tag_armright", + "tag_back", + "tag_legright", + + "tag_footleft", + "tag_footright", + "tag_sholeft", + "tag_shoright", + "tag_torso", + "tag_legleft", + "tag_legright", + + "tag_sholeft", + "tag_shoright", + "tag_legleft", + "tag_legright", + "tag_calfleft", + "tag_calfright"}; + + clientInfo_t *ci; + // TTimo: bunch of inits + int totalparts = 0, dynamicparts = 0, protoParts = 9, superParts = 16, heinrichParts = 22; + char **tags = NULL; + qhandle_t *models = NULL; + qhandle_t sound = 0; //----(SA) added + int dmgbits = 16; // 32/2; + int clientNum; + int tagIndex; + vec3_t origin, velocity, dir; + + + if ( cent->currentState.aiChar == AICHAR_PROTOSOLDIER ) { + tags = &protoTags[0]; + models = &cgs.media.protoArmor[0]; + dynamicparts = totalparts = protoParts; + sound = cgs.media.protoArmorBreak; + } else if ( cent->currentState.aiChar == AICHAR_SUPERSOLDIER ) { + tags = &ssTags[0]; + models = &cgs.media.superArmor[0]; + dynamicparts = 14; // the other two stay permanent + totalparts = superParts; + sound = cgs.media.superArmorBreak; + } else if ( cent->currentState.aiChar == AICHAR_HEINRICH ) { + tags = &heinrichTags[0]; + models = &cgs.media.heinrichArmor[0]; + dynamicparts = 20; // will get kicked down to 16 + totalparts = heinrichParts; + sound = cgs.media.heinrichArmorBreak; + } else { + return; //----(SA) added + } + + if ( dynamicparts > dmgbits ) { + dynamicparts = dmgbits; + } + + if ( index > dynamicparts ) { // shouldn't happen + return; + } + + clientNum = cent->currentState.clientNum; + if ( clientNum < 0 || clientNum >= MAX_CLIENTS ) { + CG_Error( "Bad clientNum on player entity" ); + } + ci = &cgs.clientinfo[ clientNum ]; + + // check if the model for the damaged part to fling is there + if ( cent->currentState.dmgFlags & ( 1 << ( index + dynamicparts ) ) ) { + if ( !models[index + ( 2 * totalparts )] ) { + return; + } + } else if ( !models[index + totalparts] ) { + return; + } + + tagIndex = CG_GetOriginForTag( cent, ¢->pe.torsoRefEnt, tags[index], 0, origin, NULL ); + + // calculate direction vector based on player center->tag position + VectorSubtract( origin, cent->currentState.origin, dir ); + VectorNormalize( dir ); + +//----(SA) added + if ( sound ) { + CG_SoundPlayIndexedScript( sound, NULL, cent->currentState.number ); + } +//----(SA) end + +//#define FLY_VELOCITY 75 +//#define FLY_JUMP 200 +#define FLY_VELOCITY 200 +#define FLY_JUMP 300 + +// velocity[0] = dir[0]*(0.75+random())*FLY_VELOCITY; +// velocity[1] = dir[1]*(0.75+random())*FLY_VELOCITY; + velocity[0] = dir[0] * FLY_VELOCITY; + velocity[1] = dir[1] * FLY_VELOCITY; + velocity[2] = FLY_JUMP - 50 + dir[2] * ( 0.5 + random() ) * FLY_VELOCITY; + + { + localEntity_t *le; + refEntity_t *re; + + le = CG_AllocLocalEntity(); + re = &le->refEntity; + + le->leType = LE_FRAGMENT; + le->startTime = cg.time; + le->endTime = le->startTime + 20000 + ( crandom() * 5000 ); + + VectorCopy( origin, re->origin ); + AxisCopy( axisDefault, re->axis ); + + if ( cent->currentState.dmgFlags & ( 1 << ( index + dynamicparts ) ) ) { + re->hModel = models[index + ( 2 * dynamicparts )]; + } else { + re->hModel = models[index + dynamicparts]; + } + + + re->fadeStartTime = le->endTime - 1000; + re->fadeEndTime = le->endTime; + + // (SA) FIXME: origin of md3 is offset from center. need to center the origin when you toss it + le->pos.trType = TR_GRAVITY; + VectorCopy( origin, le->pos.trBase ); + VectorCopy( velocity, le->pos.trDelta ); + le->pos.trTime = cg.time; + + // spin it a bit + le->angles.trType = TR_LINEAR; + VectorCopy( tv( 0, 0, 0 ), le->angles.trBase ); + le->angles.trDelta[0] = 0; + le->angles.trDelta[1] = ( 100 + ( rand() & 500 ) ) - 300; + le->angles.trDelta[2] = 400; + le->angles.trTime = cg.time; + le->bounceFactor = 0.4; + +// time = le->lastTrailTime+step; + + // want to add a trail, but I need to find out what all these parameters are first + + le->headJuncIndex = CG_AddTrailJunc( le->headJuncIndex, + cgs.media.zombieSpiritTrailShader, +// time, + le->lastTrailTime + 50, + STYPE_STRETCH, + le->refEntity.origin, +// (int)le->effectWidth, // trail life + 1000, + 0.3, + 0.0, +// le->radius, + 50, + 0, + 0, //TJFL_FIXDISTORT, + colorWhite, + colorWhite, + 1.0, 1 ); + + + // Ridah, if the player is on fire, then make the part on fire + if ( cent && CG_EntOnFire( cent ) ) { + le->onFireStart = cent->currentState.onFireStart; + le->onFireEnd = cent->currentState.onFireEnd + 4000; + } + } +} + + +/* +============== +CG_AttachedPartChange +============== +*/ +void CG_AttachedPartChange( centity_t *cent ) { + unsigned int diff, i; + int aiCharNum, numParts = 0; + + aiCharNum = cent->currentState.aiChar; + + diff = (unsigned int)cent->nextState.dmgFlags ^ (unsigned int)cent->currentState.dmgFlags; + + if ( aiCharNum == AICHAR_PROTOSOLDIER || + aiCharNum == AICHAR_SUPERSOLDIER || + aiCharNum == AICHAR_HEINRICH ) { + // TODO: get these from a bloody #define (or something) + if ( aiCharNum == AICHAR_PROTOSOLDIER ) { + numParts = 9; + } else if ( aiCharNum == AICHAR_SUPERSOLDIER ) { + numParts = 14; + } else if ( aiCharNum == AICHAR_HEINRICH ) { + numParts = 20; + } + + for ( i = 0; i < numParts; i++ ) { // FIXME: 7 is how many parts he currently has, this should probably share a define with the server, or be stored in the cent (cent->currentState.dmgParts) + if ( diff & ( 1 << i ) ) { + CG_LoseArmor( cent, i ); + } + } + } +} + +//----(SA) end + + + + +/* +========================================================================== + +FUNCTIONS CALLED EACH FRAME + +========================================================================== +*/ + +/* +====================== +CG_SetEntitySoundPosition + +Also called by event processing code +====================== +*/ +void CG_SetEntitySoundPosition( centity_t *cent ) { + if ( cent->currentState.solid == SOLID_BMODEL ) { + vec3_t origin; + float *v; + + v = cgs.inlineModelMidpoints[ cent->currentState.modelindex ]; + VectorAdd( cent->lerpOrigin, v, origin ); + trap_S_UpdateEntityPosition( cent->currentState.number, origin ); + } else { + trap_S_UpdateEntityPosition( cent->currentState.number, cent->lerpOrigin ); + } +} + + + + +#define LS_FRAMETIME 100 // (ms) cycle through lightstyle characters at 10fps + + +/* +============== +CG_SetDlightIntensity + +============== +*/ +void CG_AddLightstyle( centity_t *cent ) { + float lightval; + int cl; + int r, g, b; + int stringlength; + float offset; + int offsetwhole; + int otime; + int lastch, nextch; + + if ( !cent->dl_stylestring ) { + return; + } + + otime = cg.time - cent->dl_time; + stringlength = strlen( cent->dl_stylestring ); + + // it's been a long time since you were updated, lets assume a reset + if ( otime > 2 * LS_FRAMETIME ) { + otime = 0; + cent->dl_frame = cent->dl_oldframe = 0; + cent->dl_backlerp = 0; + } + + cent->dl_time = cg.time; + + offset = ( (float)otime ) / LS_FRAMETIME; + offsetwhole = (int)offset; + + cent->dl_backlerp += offset; + + + if ( cent->dl_backlerp > 1 ) { // we're moving on to the next frame + cent->dl_oldframe = cent->dl_oldframe + (int)cent->dl_backlerp; + cent->dl_frame = cent->dl_oldframe + 1; + if ( cent->dl_oldframe >= stringlength ) { + cent->dl_oldframe = ( cent->dl_oldframe ) % stringlength; + if ( cent->dl_oldframe < 3 && cent->dl_sound ) { // < 3 so if an alarm comes back into the pvs it will only start a sound if it's going to be closely synced with the light, otherwise wait till the next cycle + trap_S_StartSound( NULL, cent->currentState.number, CHAN_AUTO, cgs.gameSounds[cent->dl_sound] ); + } + } + + if ( cent->dl_frame >= stringlength ) { + cent->dl_frame = ( cent->dl_frame ) % stringlength; + } + + cent->dl_backlerp = cent->dl_backlerp - (int)cent->dl_backlerp; + } + + + lastch = cent->dl_stylestring[cent->dl_oldframe] - 'a'; + nextch = cent->dl_stylestring[cent->dl_frame] - 'a'; + + lightval = ( lastch * ( 1.0 - cent->dl_backlerp ) ) + ( nextch * cent->dl_backlerp ); + + lightval = ( lightval * ( 1000.0f / 24.0f ) ) - 200.0f; // they want 'm' as the "middle" value as 300 + + lightval = max( 0.0f, lightval ); + lightval = min( 1000.0f, lightval ); + + cl = cent->currentState.constantLight; + r = cl & 255; + g = ( cl >> 8 ) & 255; + b = ( cl >> 16 ) & 255; + + trap_R_AddLightToScene( cent->lerpOrigin, lightval, (float)r / 255.0f, (float)g / 255.0f, (float)b / 255.0f, 0 ); // overdraw forced to 0 for now +} + + + +/* +================== +CG_EntityEffects + +Add continuous entity effects, like local entity emission and lighting +================== +*/ +static void CG_EntityEffects( centity_t *cent ) { + + // update sound origins + CG_SetEntitySoundPosition( cent ); + + // add loop sound + if ( cent->currentState.loopSound ) { + //----(SA) hmm, the above (CG_SetEntitySoundPosition()) sets s_entityPosition[entityNum] with a valid + // location, but the looping sound for a bmodel will never get it since that sound is + // started with the lerpOriging right here. \/ \/ How do looping sounds ever work for bmodels? + // Or have they always been broken and we just never used them? + + if ( cent->currentState.eType == ET_SPEAKER ) { + /*if(cent->currentState.density == 1) { // NO_PVS + trap_S_AddRealLoopingSound( cent->currentState.number, cent->lerpOrigin, vec3_origin, cgs.gameSounds[ cent->currentState.loopSound ] ); + } + else*/if ( cent->currentState.dmgFlags ) { // range is set + trap_S_AddRangedLoopingSound( cent->currentState.number, cent->lerpOrigin, vec3_origin, cgs.gameSounds[ cent->currentState.loopSound ], cent->currentState.dmgFlags ); + } else { + trap_S_AddLoopingSound( cent->currentState.number, cent->lerpOrigin, vec3_origin, cgs.gameSounds[ cent->currentState.loopSound ], 255 ); + } + } else if ( cent->currentState.solid == SOLID_BMODEL ) { + vec3_t origin; + float *v; + + v = cgs.inlineModelMidpoints[ cent->currentState.modelindex ]; + VectorAdd( cent->lerpOrigin, v, origin ); + + if ( cgs.gameSoundTypes[ cent->currentState.loopSound ] == 1 ) { // old style + trap_S_AddLoopingSound( cent->currentState.number, origin, vec3_origin, cgs.gameSounds[ cent->currentState.loopSound ], 255 ); + } else { // from script + int soundIndex; + soundIndex = soundScripts[cgs.gameSounds[ cent->currentState.loopSound ] - 1 ].soundList->sfxHandle; + trap_S_AddLoopingSound( cent->currentState.number, origin, vec3_origin, soundIndex, 255 ); + } + } else { + trap_S_AddLoopingSound( cent->currentState.number, cent->lerpOrigin, vec3_origin, cgs.gameSounds[ cent->currentState.loopSound ], 255 ); + } + } /*else { + // stop NO_PVS speakers if they've been turned off + if(cent->currentState.eType == ET_SPEAKER) { + if(cent->currentState.density == 1) { + trap_S_StopLoopingSound(cent->currentState.number); + } + } + }*/ + + + // constant light glow + if ( cent->currentState.constantLight ) { + int cl; + int i, r, g, b; + + + if ( cent->dl_stylestring[0] != 0 ) { // it's probably a dlight + CG_AddLightstyle( cent ); + } else + { + cl = cent->currentState.constantLight; + r = cl & 255; + g = ( cl >> 8 ) & 255; + b = ( cl >> 16 ) & 255; + i = ( ( cl >> 24 ) & 255 ) * 4; + + trap_R_AddLightToScene( cent->lerpOrigin, i, (float)r / 255.0f, (float)g / 255.0f, (float)b / 255.0f, 0 ); + } + } + + // Ridah, flaming sounds + if ( CG_EntOnFire( cent ) ) { + // play a flame blow sound when moving + trap_S_AddLoopingSound( cent->currentState.number, cent->lerpOrigin, vec3_origin, cgs.media.flameBlowSound, (int)( 255.0 * ( 1.0 - fabs( cent->fireRiseDir[2] ) ) ) ); + // play a burning sound when not moving + trap_S_AddLoopingSound( cent->currentState.number, cent->lerpOrigin, vec3_origin, cgs.media.flameSound, (int)( 0.3 * 255.0 * ( pow( cent->fireRiseDir[2],2 ) ) ) ); + } + +} + +/* +================== +CG_General +================== +*/ +static void CG_General( centity_t *cent ) { + refEntity_t ent; + entityState_t *s1; + + s1 = ¢->currentState; + + // if set to invisible, skip + if ( !s1->modelindex ) { + return; + } + + memset( &ent, 0, sizeof( ent ) ); + + // set frame + + ent.frame = s1->frame; + ent.oldframe = ent.frame; + ent.backlerp = 0; + + if ( ent.frame ) { + + ent.oldframe -= 1; + ent.backlerp = 1 - cg.frameInterpolation; + + if ( cent->currentState.time ) { + ent.fadeStartTime = cent->currentState.time; + ent.fadeEndTime = cent->currentState.time2; + } + + } + + VectorCopy( cent->lerpOrigin, ent.origin ); + VectorCopy( cent->lerpOrigin, ent.oldorigin ); + + ent.hModel = cgs.gameModels[s1->modelindex]; + + // player model + if ( s1->number == cg.snap->ps.clientNum ) { + ent.renderfx |= RF_THIRD_PERSON; // only draw from mirrors + } + + // convert angles to axis + AnglesToAxis( cent->lerpAngles, ent.axis ); + + // scale gamemodels + if ( cent->currentState.eType == ET_GAMEMODEL ) { + VectorScale( ent.axis[0], cent->currentState.angles2[0], ent.axis[0] ); + VectorScale( ent.axis[1], cent->currentState.angles2[1], ent.axis[1] ); + VectorScale( ent.axis[2], cent->currentState.angles2[2], ent.axis[2] ); + ent.nonNormalizedAxes = qtrue; + +// if( (cent->currentState.angles2[0] * cent->currentState.angles2[1] * cent->currentState.angles2[2]) != 1) { +// ent.reFlags |= REFLAG_SCALEDSPHERECULL; +// +// // find greatest scaled axis +// ent.radius = cent->currentState.angles2[0]; +// if(cent->currentState.angles2[1] > ent.radius) +// ent.radius = cent->currentState.angles2[1]; +// if(cent->currentState.angles2[2] > ent.radius) +// ent.radius = cent->currentState.angles2[2]; +// } + +//----(SA) testing +// if(cent->currentState.apos.trType) { +// ent.reFlags |= REFLAG_ORIENT_LOD; +// } +//----(SA) end + } + + // add to refresh list + trap_R_AddRefEntityToScene( &ent ); + + memcpy( ¢->refEnt, &ent, sizeof( refEntity_t ) ); +} + +/* +================== +CG_Speaker + +Speaker entities can automatically play sounds +================== +*/ +static void CG_Speaker( centity_t *cent ) { + if ( !cent->currentState.clientNum ) { // FIXME: use something other than clientNum... + return; // not auto triggering + } + + if ( cg.time < cent->miscTime ) { + return; + } + + trap_S_StartSound( NULL, cent->currentState.number, CHAN_ITEM, cgs.gameSounds[cent->currentState.eventParm] ); + + // ent->s.frame = ent->wait * 10; + // ent->s.clientNum = ent->random * 10; + cent->miscTime = cg.time + cent->currentState.frame * 100 + cent->currentState.clientNum * 100 * crandom(); +} + + + +/* +============== +CG_DrawHoldableSelect + + This, of course, will all change when we've got a hud, but for now it makes the holdable items usable and not bad looking +============== +*/ +void CG_DrawHoldableSelect( void ) { + int bits; + int count; + int amount; + int i, x, y, w; + float *color; + char *name; + gitem_t *item; + + // don't display if dead + if ( cg.predictedPlayerState.stats[STAT_HEALTH] <= 0 ) { + return; + } + + color = CG_FadeColor( cg.holdableSelectTime, HOLDABLE_SELECT_TIME ); + if ( !color ) { + return; + } + trap_R_SetColor( color ); + + // showing select clears pickup item display, but not the blend blob + cg.itemPickupTime = 0; + + // count the number of holdables owned + bits = cg.snap->ps.stats[ STAT_HOLDABLE_ITEM ]; + count = 0; + + for ( i = 1 ; i <= HI_BOOK3; i++ ) { + if ( bits & ( 1 << i ) ) { + if ( cg.predictedPlayerState.holdable[i] ) { // don't show ones we're out of + count++; + } + } + } + + + if ( !count ) { + return; + } + + x = 320 - count * 20; + y = 370; + + + for ( i = 1 ; i <= HI_BOOK3 ; i++ ) { + if ( !( bits & ( 1 << i ) ) ) { + continue; + } + + amount = cg.predictedPlayerState.holdable[i]; + + if ( !amount ) { + continue; + } + + item = BG_FindItemForHoldable( i ); + if ( !item ) { + continue; + } + + CG_RegisterItemVisuals( item - bg_itemlist ); + + // draw icon + if ( i == HI_WINE ) { + // wine icons have three stages since each bottle has three uses (as opposed to others so far where there's only 1 use) + int wine = amount; + if ( wine > 3 ) { + wine = 3; + } + CG_DrawPic( x, y, 32, 32, cg_items[item - bg_itemlist].icons[ 2 - ( wine - 1 ) ] ) ; + } else { + CG_DrawPic( x, y, 32, 32, cg_items[item - bg_itemlist].icons[0] ); + } + + // draw remaining uses if there's more than one + if ( amount > 1 ) { + CG_DrawBigStringColor( x + 6, y + 40, va( "%d", amount ), color ); + } + + // draw selection marker + if ( i == cg.holdableSelect ) { + CG_DrawPic( x - 4, y - 4, 40, 40, cgs.media.selectShader ); + } + + x += 40; + } + + // draw the selected name + if ( cg.holdableSelect ) { + item = BG_FindItemForHoldable( cg.holdableSelect ); + if ( item ) { + name = cgs.itemPrintNames[ item - bg_itemlist ]; + if ( name ) { + //----(SA) trying smaller text +// w = CG_DrawStrlen( name ) * BIGCHAR_WIDTH; + w = CG_DrawStrlen( name ) * 10; + x = ( SCREEN_WIDTH - w ) / 2; +// CG_DrawBigStringColor(x, y - 22, name, color); + CG_DrawStringExt2( x, y + 74, name, color, qfalse, qtrue, 10, 10, 0 ); +// CG_Text_Paint(x, y + 74, 2, 0.3f, color, name, 0, 0, 6); // ITEM_TEXTSTYLE_SHADOWEDMORE + } + } + } + + trap_R_SetColor( NULL ); +} + + +/* +============== +CG_NextItem_f +============== +*/ + +void CG_NextItem_f( void ) { + int i; + int original, next; + + if ( !cg.snap ) { + return; + } + + if ( cg.snap->ps.pm_flags & PMF_FOLLOW ) { + return; + } + + cg.holdableSelectTime = cg.time; + cg.weaponSelectTime = 0; // (SA) clear weapon selection drawing + + next = original = cg.holdableSelect; + + for ( i = 0 ; i < HI_NUM_HOLDABLE ; i++ ) { + next++; + + if ( next == HI_NUM_HOLDABLE ) { + next = 0; + } + + if ( cg.predictedPlayerState.holdable[next] ) { //----(SA) + break; + } + } + + if ( i == HI_NUM_HOLDABLE ) { + next = original; + } + + cg.holdableSelect = next; +} + +/* +============== +CG_PrevItem_f +============== +*/ +void CG_PrevItem_f( void ) { + int i; + int original, next; + + if ( !cg.snap ) { + return; + } + + if ( cg.snap->ps.pm_flags & PMF_FOLLOW ) { + return; + } + + cg.weaponSelectTime = 0; // (SA) clear weapon selection drawing + cg.holdableSelectTime = cg.time; + + next = original = cg.holdableSelect; + + for ( i = 0 ; i < HI_NUM_HOLDABLE ; i++ ) { + next--; + + if ( next == -1 ) { + next = HI_NUM_HOLDABLE - 1; + } + + if ( cg.predictedPlayerState.holdable[next] ) { //----(SA) + break; + } + } + + if ( i == HI_NUM_HOLDABLE ) { + next = original; + } + + cg.holdableSelect = next; +} + +/* +============== +CG_Item_f +============== +*/ +void CG_Item_f( void ) { + int num; + num = atoi( CG_Argv( 1 ) ); + + cg.holdableSelectTime = cg.time; + + CG_Printf( "Item set to: d\n", num ); +} + + + +//----(SA) added +/* +============== +CG_HoldableUsedupChange +============== +*/ +void CG_HoldableUsedupChange( void ) { + int holding; + + holding = cg.holdableSelect; + + CG_NextItem_f(); + + if ( cg.holdableSelect == holding ) { // nothing else to go to + cg.holdableSelect = 0; + cg.weaponSelectTime = 0; + return; + } +} +//----(SA) end + + + +qboolean CG_PlayerSeesItem( playerState_t *ps, entityState_t *item, int atTime, int itemType ) { + vec3_t vorigin, eorigin, viewa, dir; + float dot, dist, foo; + trace_t tr; + + BG_EvaluateTrajectory( &item->pos, atTime, eorigin ); + + VectorCopy( ps->origin, vorigin ); + vorigin[2] += ps->viewheight; // get the view loc up to the viewheight +// eorigin[2] += 8; // and subtract the item's offset (that is used to place it on the ground) + + + VectorSubtract( vorigin, eorigin, dir ); + + dist = VectorNormalize( dir ); // dir is now the direction from the item to the player + + if ( dist > 255 ) { + return qfalse; // only run the remaining stuff on items that are close enough + + } + // (SA) FIXME: do this without AngleVectors. + // It'd be nice if the angle vectors for the player + // have already been figured at this point and I can + // just pick them up. (if anybody is storing this somewhere, + // for the current frame please let me know so I don't + // have to do redundant calcs) + AngleVectors( ps->viewangles, viewa, 0, 0 ); + dot = DotProduct( viewa, dir ); + + // give more range based on distance (the hit area is wider when closer) + +// foo = -0.94f - (dist/255.0f) * 0.057f; // (ranging from -0.94 to -0.997) (it happened to be a pretty good range) + foo = -0.94f - ( dist * ( 1.0f / 255.0f ) ) * 0.057f; // (ranging from -0.94 to -0.997) (it happened to be a pretty good range) + +/// Com_Printf("test: if(%f > %f) return qfalse (dot > foo)\n", dot, foo); + if ( dot > foo ) { + return qfalse; + } + + // (SA) okay, everything else is okay, so do a bloody trace. (so coronas on treasure doesn't show through walls) + if ( itemType == IT_TREASURE ) { + CG_Trace( &tr, vorigin, NULL, NULL, eorigin, -1, MASK_SOLID ); + + if ( tr.fraction != 1 ) { + return qfalse; + } + } + + return qtrue; + +} + + +/* +================== +CG_Item +================== +*/ +static void CG_Item( centity_t *cent ) { + refEntity_t ent; + entityState_t *es; + gitem_t *item; + float scale; + qboolean hasStand, highlight; + float highlightFadeScale = 1.0f; + + es = ¢->currentState; + + hasStand = qfalse; + highlight = qfalse; + + // (item index is stored in es->modelindex for item) + + if ( es->modelindex >= bg_numItems ) { + CG_Error( "Bad item index %i on entity", es->modelindex ); + } + + // if set to invisible, skip + if ( !es->modelindex || ( es->eFlags & EF_NODRAW ) ) { + return; + } + + item = &bg_itemlist[ es->modelindex ]; + + if ( cg_simpleItems.integer && item->giType != IT_TEAM ) { + memset( &ent, 0, sizeof( ent ) ); + ent.reType = RT_SPRITE; + VectorCopy( cent->lerpOrigin, ent.origin ); + ent.radius = 14; + ent.customShader = cg_items[es->modelindex].icons[0]; + ent.shaderRGBA[0] = 255; + ent.shaderRGBA[1] = 255; + ent.shaderRGBA[2] = 255; + ent.shaderRGBA[3] = 255; + trap_R_AddRefEntityToScene( &ent ); + return; + } + + scale = 0.005 + cent->currentState.number * 0.00001; + + memset( &ent, 0, sizeof( ent ) ); + + ent.nonNormalizedAxes = qfalse; + + if ( item->giType == IT_WEAPON ) { + weaponInfo_t *weaponInfo = &cg_weapons[item->giTag]; + + if ( weaponInfo->standModel ) { + hasStand = qtrue; + } + + if ( hasStand ) { // first try to put the weapon on it's 'stand' + refEntity_t stand; + + memset( &stand, 0, sizeof( stand ) ); + stand.hModel = weaponInfo->standModel; + + if ( es->eFlags & EF_SPINNING ) { + if ( es->groundEntityNum == -1 || !es->groundEntityNum ) { // (SA) spinning with a stand will spin the stand and the attached weap (only when in the air) + VectorCopy( cg.autoAnglesSlow, cent->lerpAngles ); + VectorCopy( cg.autoAnglesSlow, cent->lastLerpAngles ); + } else { + VectorCopy( cent->lastLerpAngles, cent->lerpAngles ); // make a tossed weapon sit on the ground in a position that matches how it was yawed + } + } + + AnglesToAxis( cent->lerpAngles, stand.axis ); + VectorCopy( cent->lerpOrigin, stand.origin ); + + // scale the stand to match the weapon scale ( the weapon will also be scaled inside CG_PositionEntityOnTag() ) + VectorScale( stand.axis[0], 1.5, stand.axis[0] ); + VectorScale( stand.axis[1], 1.5, stand.axis[1] ); + VectorScale( stand.axis[2], 1.5, stand.axis[2] ); + +//----(SA) modified + if ( cent->currentState.frame ) { + CG_PositionEntityOnTag( &ent, &stand, va( "tag_stand%d", cent->currentState.frame ), 0, NULL ); + } else { + CG_PositionEntityOnTag( &ent, &stand, "tag_stand", 0, NULL ); + } +//----(SA) end + + VectorCopy( ent.origin, ent.oldorigin ); + ent.nonNormalizedAxes = qtrue; + + } else { // then default to laying it on it's side + if ( !cg_items[es->modelindex].models[2] ) { + cent->lerpAngles[2] += 90; + } + + AnglesToAxis( cent->lerpAngles, ent.axis ); + + // increase the size of the weapons when they are presented as items + VectorScale( ent.axis[0], 1.5, ent.axis[0] ); + VectorScale( ent.axis[1], 1.5, ent.axis[1] ); + VectorScale( ent.axis[2], 1.5, ent.axis[2] ); + ent.nonNormalizedAxes = qtrue; + + VectorCopy( cent->lerpOrigin, ent.origin ); + VectorCopy( cent->lerpOrigin, ent.oldorigin ); + + if ( es->eFlags & EF_SPINNING ) { // spinning will override the angles set by a stand + if ( es->groundEntityNum == -1 || !es->groundEntityNum ) { // (SA) spinning with a stand will spin the stand and the attached weap (only when in the air) + VectorCopy( cg.autoAnglesSlow, cent->lerpAngles ); + VectorCopy( cg.autoAnglesSlow, cent->lastLerpAngles ); + } else { + VectorCopy( cent->lastLerpAngles, cent->lerpAngles ); // make a tossed weapon sit on the ground in a position that matches how it was yawed + } + } + } + + } else { + AnglesToAxis( cent->lerpAngles, ent.axis ); + VectorCopy( cent->lerpOrigin, ent.origin ); + VectorCopy( cent->lerpOrigin, ent.oldorigin ); + + if ( es->eFlags & EF_SPINNING ) { // spinning will override the angles set by a stand + VectorCopy( cg.autoAnglesSlow, cent->lerpAngles ); + AxisCopy( cg.autoAxisSlow, ent.axis ); + } + } + + + if ( es->modelindex2 ) { // modelindex2 was specified for the ent, meaning it probably has an alternate model (as opposed to the one in the itemlist) + // try to load it first, and if it fails, default to the itemlist model + ent.hModel = cgs.gameModels[ es->modelindex2 ]; + } else { + if ( item->giType == IT_WEAPON && cg_items[es->modelindex].models[2] ) { // check if there's a specific model for weapon pickup placement + ent.hModel = cg_items[es->modelindex].models[2]; + } else if ( item->giType == IT_HEALTH || item->giType == IT_AMMO || item->giType == IT_POWERUP ) { + if ( es->density < ( 1 << 9 ) ) { // (10 bits of data transmission for density) + ent.hModel = cg_items[es->modelindex].models[es->density]; // multi-state powerups store their state in 'density' + + // add steam to 'hot' meals + if ( !Q_stricmp( item->classname, "item_health_turkey" ) ) { + if ( !cg_paused.integer ) { // don't add while paused + if ( !( rand() % 7 ) ) { + CG_ParticleImpactSmokePuffExtended( cgs.media.smokeParticleShader, cent->lerpOrigin, tv( 0,0,1 ), 6, 2000, 4, 10, 16, 0.2f ); + } + } + } + } else { + ent.hModel = cg_items[es->modelindex].models[0]; + } + } else { + ent.hModel = cg_items[es->modelindex].models[0]; + } + } + + //----(SA) find midpoint for highlight corona. + // Can't do it when item is registered since it wouldn't know about replacement model + if ( !( cent->usehighlightOrigin ) ) { + vec3_t mins, maxs, offset; + int i; + + trap_R_ModelBounds( ent.hModel, mins, maxs ); // get bounds + + for ( i = 0 ; i < 3 ; i++ ) { + offset[i] = mins[i] + 0.5 * ( maxs[i] - mins[i] ); // find object-space center + } + + VectorCopy( cent->lerpOrigin, cent->highlightOrigin ); // set 'midpoint' to origin + + for ( i = 0 ; i < 3 ; i++ ) { // adjust midpoint by offset and orientation + cent->highlightOrigin[i] += offset[0] * ent.axis[0][i] + + offset[1] * ent.axis[1][i] + + offset[2] * ent.axis[2][i]; + } + + cent->usehighlightOrigin = qtrue; + } + + // items without glow textures need to keep a minimum light value so they are always visible +// if ( ( item->giType == IT_WEAPON ) || ( item->giType == IT_ARMOR ) ) { + ent.renderfx |= RF_MINLIGHT; +// } + + // highlighting items the player looks at + if ( cg_drawCrosshairPickups.integer ) { + + + if ( cg_drawCrosshairPickups.integer == 2 ) { // '2' is 'force highlights' + highlight = qtrue; + } + + if ( CG_PlayerSeesItem( &cg.predictedPlayerState, es, cg.time, item->giType ) ) { + highlight = qtrue; + + if ( item->giType == IT_TREASURE ) { + trap_R_AddCoronaToScene( cent->highlightOrigin, 1, 0.85, 0.5, 2, cent->currentState.number, 1 ); //----(SA) add corona to treasure + } + } else { + if ( item->giType == IT_TREASURE ) { + trap_R_AddCoronaToScene( cent->highlightOrigin, 1, 0.85, 0.5, 2, cent->currentState.number, 0 ); //----(SA) "empty corona" for proper fades + } + } + +//----(SA) added fixed item highlight fading + + if ( highlight ) { + if ( !cent->highlighted ) { + cent->highlighted = qtrue; + cent->highlightTime = cg.time; + } + ent.hilightIntensity = ( ( cg.time - cent->highlightTime ) / 250.0f ) * highlightFadeScale; // .25 sec to brighten up + } else { + if ( cent->highlighted ) { + cent->highlighted = qfalse; + cent->highlightTime = cg.time; + } + ent.hilightIntensity = 1.0f - ( ( cg.time - cent->highlightTime ) / 1000.0f ) * highlightFadeScale; // 1 sec to dim down (diff in time causes problems if you quickly flip to/away from looking at the item) + } + + if ( ent.hilightIntensity < 0.25f ) { // leave a minlight + ent.hilightIntensity = 0.25f; + } + if ( ent.hilightIntensity > 1 ) { + ent.hilightIntensity = 1.0; + } + } +//----(SA) end + + + // add to refresh list + trap_R_AddRefEntityToScene( &ent ); +} + +//============================================================================ + +/* +=============== +CG_Missile +=============== +*/ + +extern void CG_RocketTrail( centity_t *ent, const weaponInfo_t *wi ); + +static void CG_Missile( centity_t *cent ) { + refEntity_t ent; + entityState_t *s1; + const weaponInfo_t *weapon; + + s1 = ¢->currentState; + if ( s1->weapon > WP_NUM_WEAPONS ) { + s1->weapon = 0; + } + weapon = &cg_weapons[s1->weapon]; + + // calculate the axis + VectorCopy( s1->angles, cent->lerpAngles ); + + // add trails + if ( cent->currentState.eType == ET_FP_PARTS + || cent->currentState.eType == ET_FIRE_COLUMN + || cent->currentState.eType == ET_FIRE_COLUMN_SMOKE + || cent->currentState.eType == ET_RAMJET ) { + CG_RocketTrail( cent, NULL ); + } else if ( weapon->missileTrailFunc ) { + weapon->missileTrailFunc( cent, weapon ); + } + + // add dynamic light + if ( weapon->missileDlight ) { + trap_R_AddLightToScene( cent->lerpOrigin, weapon->missileDlight, + weapon->missileDlightColor[0], weapon->missileDlightColor[1], weapon->missileDlightColor[2], 0 ); + } + +//----(SA) whoops, didn't mean to check it in with the missile flare + + // add missile sound + if ( weapon->missileSound ) { + vec3_t velocity; + + BG_EvaluateTrajectoryDelta( ¢->currentState.pos, cg.time, velocity ); + trap_S_AddLoopingSound( cent->currentState.number, cent->lerpOrigin, velocity, weapon->missileSound, 255 ); + } + + // create the render entity + memset( &ent, 0, sizeof( ent ) ); + VectorCopy( cent->lerpOrigin, ent.origin ); + VectorCopy( cent->lerpOrigin, ent.oldorigin ); + +//----(SA) removed plasma gun code as sp5 is taking that spot + + // flicker between two skins + ent.skinNum = cg.clientFrame & 1; + + if ( cent->currentState.eType == ET_FP_PARTS ) { + ent.hModel = cgs.gameModels[cent->currentState.modelindex]; + } else if ( cent->currentState.eType == ET_EXPLO_PART ) { + ent.hModel = cgs.gameModels[cent->currentState.modelindex]; + } else if ( cent->currentState.eType == ET_FLAMEBARREL ) { + ent.hModel = cgs.media.flamebarrel; + } else if ( cent->currentState.eType == ET_FIRE_COLUMN || cent->currentState.eType == ET_FIRE_COLUMN_SMOKE ) { + // it may have a model sometime in the future + ent.hModel = 0; + } else if ( cent->currentState.eType == ET_RAMJET ) { + ent.hModel = 0; + } + // ent.hModel = cgs.gameModels[cent->currentState.modelindex]; + else { + ent.hModel = weapon->missileModel; + } + ent.renderfx = weapon->missileRenderfx | RF_NOSHADOW; + + // convert direction of travel into axis + if ( VectorNormalize2( s1->pos.trDelta, ent.axis[0] ) == 0 ) { + ent.axis[0][2] = 1; + } + + // spin as it moves + if ( s1->pos.trType != TR_STATIONARY ) { + RotateAroundDirection( ent.axis, cg.time / 4 ); + } else { + RotateAroundDirection( ent.axis, s1->time ); + } + + // Rafael + // Added this since it may be a propExlosion + if ( ent.hModel ) { + // add to refresh list, possibly with quad glow + CG_AddRefEntityWithPowerups( &ent, s1->powerups, TEAM_FREE, s1, vec3_origin ); + } + +} + +/* +=============== +CG_ZombieSpit +=============== +*/ +static void CG_ZombieSpit( centity_t *cent ) { + refEntity_t ent; + entityState_t *s1; + const weaponInfo_t *weapon; + + s1 = ¢->currentState; + if ( s1->weapon > WP_NUM_WEAPONS ) { + s1->weapon = 0; + } + weapon = &cg_weapons[s1->weapon]; + + // calculate the axis + VectorCopy( s1->angles, cent->lerpAngles ); + + // create the render entity + memset( &ent, 0, sizeof( ent ) ); + VectorCopy( cent->lerpOrigin, ent.origin ); + VectorCopy( cent->lerpOrigin, ent.oldorigin ); + + // flicker between two skins + ent.skinNum = cg.clientFrame & 1; + + ent.hModel = cgs.media.zombieLoogie; + + ent.renderfx = weapon->missileRenderfx | RF_NOSHADOW; + + // convert direction of travel into axis + if ( VectorNormalize2( s1->pos.trDelta, ent.axis[0] ) == 0 ) { + ent.axis[0][2] = 1; + } + + // spin as it moves + if ( s1->pos.trType != TR_STATIONARY ) { + RotateAroundDirection( ent.axis, cg.time / 4 ); + } else { + RotateAroundDirection( ent.axis, s1->time ); + } + + // add to refresh list, possibly with quad glow + CG_AddRefEntityWithPowerups( &ent, s1->powerups, TEAM_FREE, s1, vec3_origin ); + + // smoke trail effect + CG_Particle_Bleed( cgs.media.smokePuffShader, ent.origin, vec3_origin, 1, 180 ); +} + +/* +=============== +CG_Bat + + RF, a bat now is actually a spirit +=============== +*/ +static void CG_Bat( centity_t *cent ) { + refEntity_t refent; + + memset( &refent, 0, sizeof( refent ) ); + +//CG_Printf("remove me!!"); +//cgs.media.zombieSpiritLoopSound = trap_S_RegisterSound( "sound/zombie/attack/spirit_loop.wav" ); +//cgs.media.ssSpiritSkullModel = trap_R_RegisterModel( "models/players/supersoldier/ssghost.md3" ); + + // add the visible entity and trail + memset( &refent, 0, sizeof( refent ) ); + refent.hModel = cgs.media.ssSpiritSkullModel; + refent.backlerp = 0; + refent.renderfx = RF_NOSHADOW | RF_MINLIGHT; //----(SA) + refent.reType = RT_MODEL; + refent.shaderRGBA[3] = 255; + VectorCopy( cent->lerpOrigin, refent.origin ); + AnglesToAxis( cent->currentState.angles, refent.axis ); + // draw it + trap_R_AddRefEntityToScene( &refent ); + // emit a sound + trap_S_AddLoopingSound( 0, refent.origin, vec3_origin, cgs.media.zombieSpiritLoopSound, 255 ); +} + +/* +=============== +CG_Crowbar +=============== +*/ +static void CG_Crowbar( centity_t *cent ) { + refEntity_t ent; + entityState_t *s1; + const weaponInfo_t *weapon; + + s1 = ¢->currentState; + if ( s1->weapon > WP_NUM_WEAPONS ) { + s1->weapon = 0; + } + weapon = &cg_weapons[s1->weapon]; + + // calculate the axis + VectorCopy( s1->angles, cent->lerpAngles ); + + // create the render entity + memset( &ent, 0, sizeof( ent ) ); + VectorCopy( cent->lerpOrigin, ent.origin ); + VectorCopy( cent->lerpOrigin, ent.oldorigin ); + + // flicker between two skins + ent.skinNum = cg.clientFrame & 1; + + ent.hModel = cgs.media.crowbar; + + ent.renderfx = weapon->missileRenderfx | RF_NOSHADOW; + + // convert direction of travel into axis + if ( VectorNormalize2( s1->pos.trDelta, ent.axis[0] ) == 0 ) { + ent.axis[0][2] = 1; + } + + // spin as it moves + if ( s1->pos.trType != TR_STATIONARY ) { + RotateAroundDirection( ent.axis, cg.time / 4 ); + } else { + RotateAroundDirection( ent.axis, s1->time ); + } + + // add to refresh list, possibly with quad glow + CG_AddRefEntityWithPowerups( &ent, s1->powerups, TEAM_FREE, s1, vec3_origin ); + +} + + +//----(SA) animation_t struct changed, so changes are to keep this working +static animation_t grabberAnims[] = { + {"", 0, 6, 6, 1000 / 5, 1000 / 5 }, // (main idle) + {"", 5, 21, 21, 1000 / 7, 1000 / 7 }, // (random idle) + {"", 25, 11, 0, 1000 / 15, 1000 / 15 }, // (attack big swipe) + {"", 35, 16, 0, 1000 / 15, 1000 / 15 }, // (attack small swipe) + {"", 50, 16, 0, 1000 / 15, 1000 / 15 }, // (attack grab) + {"", 66, 1, 0, 1000 / 15, 1000 / 15 } // (starting position) +}; + +//----(SA) added +// TTimo: unused +/* +static animation_t footlockerAnims[] = { + {"", 0, 1, 1, 1000/5, 1000/5 }, // (main idle) + {"", 0, 5, 5, 1000/5, 1000/5 }, // (lock rattle) + {"", 5, 6, 0, 1000/5, 1000/5 } // (break open) +}; +*/ +//----(SA) end + +// DHM - Nerve :: capture and hold flag + +static animation_t multi_flagpoleAnims[] = { + {"", 0, 1, 0, 1000 / 15, 1000 / 15 }, // (no flags, idle) + {"", 0, 15, 0, 1000 / 15, 1000 / 15 }, // (nazi flag rising) + {"", 490, 15, 0, 1000 / 15, 1000 / 15 }, // (american flag rising) + {"", 20, 211, 211, 1000 / 15, 1000 / 15 }, // (nazi flag raised) + {"", 255, 211, 211, 1000 / 15, 1000 / 15 }, // (american flag raised) + {"", 235, 15, 0, 1000 / 15, 1000 / 15 }, // (nazi switching to american) + {"", 470, 15, 0, 1000 / 15, 1000 / 15 } // (american switching to nazi) +}; + +// dhm - end + +extern void CG_RunLerpFrame( clientInfo_t *ci, lerpFrame_t *lf, int newAnimation, float speedScale ); + +///// +//////----(SA) okay, a whole bunch of changes in here. LMK if this breaks anything. I will fix. +///// I'm trying to test any potential breaks, but stuff could slip by. +///// + +/* +============== +CG_SetAnim +============== +*/ +static void CG_SetAnim( centity_t *cent, lerpFrame_t *lf, int newSequence ) { + + // transition animation + lf->animationNumber = newSequence; + lf->animation = &lf->cgAnim[newSequence]; + lf->animationTime = lf->frameTime + lf->animation->initialLerp; + +} + +//----(SA) added +/* +============== +CG_NewAnim +============== +*/ +static int CG_NewAnim( centity_t *cent, lerpFrame_t *lf, animation_t *anim, int initialSequence ) { + + lf->frameTime = + lf->oldFrameTime = cg.time; + + lf->cgAnim = anim; // set the pointer to the base of the animation array for this ent + // TODO: handle out of range? + lf->animation = &anim[initialSequence]; + + CG_SetAnim( cent, lf, initialSequence ); + + lf->frame = + lf->oldFrame = lf->animation->firstFrame; + + return 0; +} +//----(SA) end + +/* +============== +CG_RunAnim +============== +*/ +static void CG_RunAnim( centity_t *cent, int *frame, int *oldframe, float *backlerp ) { + + // transition to new anim if requested (rather than letting it get done in cg_runlerpframe() since that expects a player ent) + if ( ( cent->lerpFrame.animationNumber != cent->currentState.frame ) || !cent->lerpFrame.animation ) { + CG_SetAnim( cent, ¢->lerpFrame, cent->currentState.frame ); + } + + // run it + CG_RunLerpFrame( NULL, ¢->lerpFrame, 0, 1 ); + + *frame = cent->lerpFrame.frame; + *oldframe = cent->lerpFrame.oldFrame; + *backlerp = cent->lerpFrame.backlerp; +} + + +/* +============== +CG_Trap + // TODO: change from 'trap' to something else. 'trap' is a misnomer. it's actually used for other stuff too +============== +*/ +static void CG_Trap( centity_t *cent ) { + refEntity_t ent; + entityState_t *cs; + animation_t *trapAnim; + + trapAnim = &grabberAnims[0]; + + memset( &ent, 0, sizeof( ent ) ); + + cs = ¢->currentState; + + // initial setup. set pointer to animation table and setup anim + if ( !cent->lerpFrame.oldFrameTime ) { + + // DHM - Nerve :: teamNum specifies which set of animations to use (only 1 exists right now) + if ( cgs.gametype == GT_WOLF ) { + switch ( cent->currentState.teamNum ) { + + case 1: + trapAnim = &multi_flagpoleAnims[0]; +// lf->animation = &multi_flagpoleAnims[ cent->currentState.frame ]; + break; + default: + // Keep what was set above + break; + } + } + // dhm - end + + CG_NewAnim( cent, ¢->lerpFrame, trapAnim, cs->frame ); + } + + CG_RunAnim( cent, &ent.frame, &ent.oldframe, &ent.backlerp ); + + VectorCopy( cent->lerpOrigin, ent.origin ); + VectorCopy( cent->lerpOrigin, ent.oldorigin ); + + ent.hModel = cgs.gameModels[cs->modelindex]; + + AnglesToAxis( cent->lerpAngles, ent.axis ); + + trap_R_AddRefEntityToScene( &ent ); + + memcpy( ¢->refEnt, &ent, sizeof( refEntity_t ) ); +} +//----(SA) end + + +/* +============== +CG_Corona +============== +*/ +static void CG_Corona( centity_t *cent ) { + trace_t tr; + int r, g, b; + int dli; + int flags = 0; + qboolean behind = qfalse, + toofar = qfalse; + + float dot, dist; + vec3_t dir; + + if ( cg_coronas.integer == 0 ) { // if set to '0' no coronas + return; + } + + dli = cent->currentState.dl_intensity; + r = dli & 255; + g = ( dli >> 8 ) & 255; + b = ( dli >> 16 ) & 255; + + // only coronas that are in your PVS are being added + + VectorSubtract( cg.refdef.vieworg, cent->lerpOrigin, dir ); + + dist = VectorNormalize2( dir, dir ); + if ( dist > cg_coronafardist.integer ) { // performance variable cg_coronafardist will keep down super long traces + toofar = qtrue; + } + + dot = DotProduct( dir, cg.refdef.viewaxis[0] ); + if ( dot >= -0.6 ) { // assumes ~90 deg fov (SA) changed value to 0.6 (screen corner at 90 fov) + behind = qtrue; // use the dot to at least do trivial removal of those behind you. + } + // yeah, I could calc side planes to clip against, but would that be worth it? (much better than dumb dot>= thing?) + +// CG_Printf("dot: %f\n", dot); + + if ( cg_coronas.integer == 2 ) { // if set to '2' trace everything + behind = qfalse; + toofar = qfalse; + } + + + if ( !behind && !toofar ) { + CG_Trace( &tr, cg.refdef.vieworg, NULL, NULL, cent->lerpOrigin, -1, MASK_SOLID | CONTENTS_BODY ); // added blockage by players. not sure how this is going to be since this is their bb, not their model (too much blockage) + + if ( tr.fraction == 1 ) { + flags = 1; + } + + trap_R_AddCoronaToScene( cent->lerpOrigin, (float)r / 255.0f, (float)g / 255.0f, (float)b / 255.0f, (float)cent->currentState.density / 255.0f, cent->currentState.number, flags ); + } +} + + +/* +============== +CG_Efx +============== +*/ +extern void CG_Explodef( vec3_t origin, vec3_t dir, int mass, int type, qhandle_t sound, int forceLowGrav, qhandle_t shader, int parent, qboolean damage ); + +static void CG_Efx( centity_t *cent ) { + int i; + float rnd; + trace_t trace; + vec3_t perpvec; + vec3_t stickPoint; + float movePerUpdate; + + if ( cent->currentState.eType == ET_TESLA_EF ) { + rnd = cent->currentState.angles2[0]; + + for ( i = 0; i < MAX_TESLA_BOLTS; i++ ) { + if ( cent->boltTimes[i] < cg.time ) { + VectorSet( cent->boltLocs[i], crandom(), crandom(), crandom() ); + VectorNormalize2( cent->boltLocs[i], cent->boltLocs[i] ); + VectorMA( cent->currentState.origin2, rnd, cent->boltLocs[i], cent->boltLocs[i] ); + + cent->boltTimes[i] = cg.time + rand() % cent->currentState.time2; // hold this position for ~1 second ('stickytime' value is stored in .time2) + + // cut the bolt short if it collides w/ something + CG_Trace( &trace, cent->currentState.origin, NULL, NULL, cent->boltLocs[i], -1, MASK_SOLID | CONTENTS_BODY ); + + if ( trace.fraction < 1 ) { + // take damage + if ( trace.entityNum != ENTITYNUM_WORLD ) { +// CG_ClientDamage(trace.entityNum, cent->currentState.number, CLDMG_TESLA); +// cg_entities[trace.entityNum].pe.teslaDamagedTime = cg.time; + } + + VectorCopy( trace.endpos, cent->boltLocs[i] ); + + // store perpendicular vector so end can 'crawl' + PerpendicularVector( perpvec, trace.plane.normal ); + + RotatePointAroundVector( stickPoint, trace.plane.normal, perpvec, crandom() * 360 ); + + // scale it so it won't move too far with bolts that have long boltTimer's + movePerUpdate = 1.0f / (float)( cent->boltTimes[i] - cg.time ); + + // move a max of 64 away from the 'original' target location + VectorScale( stickPoint, movePerUpdate * trace.fraction * 64.0f, cent->boltCrawlDirs[i] ); + + } else { + VectorSet( cent->boltCrawlDirs[i], 0, 0, 0 ); + } + + } + } + + for ( i = 0; i < MAX_TESLA_BOLTS; i++ ) { + + if ( cent->boltCrawlDirs[0] || cent->boltCrawlDirs[1] || cent->boltCrawlDirs[2] ) { + VectorMA( cent->boltLocs[i], cent->boltTimes[i] - cg.time, cent->boltCrawlDirs[i], perpvec ); + } else { + VectorCopy( cent->boltLocs[i], perpvec ); + } + + CG_DynamicLightningBolt( cgs.media.lightningBoltShader, // shader + cent->currentState.origin, // start + perpvec, // end + cent->currentState.density, // numBolts + cent->currentState.frame, // maxWidth + qtrue, // fade + 1.0, // startAlpha + 0, // recursion + i * i * 2 ); // randseed + } + + // add dlight + if ( cent->currentState.dl_intensity ) { + int r, g, b; + int dli; + int randomness = cent->currentState.time2; + + if ( ( cg.time / 50 ) % ( randomness + ( cg.time % randomness ) ) == 0 ) { + dli = cent->currentState.dl_intensity; + r = dli & 255; + g = ( dli >> 8 ) & 255; + b = ( dli >> 16 ) & 255; + trap_R_AddLightToScene( cent->currentState.origin, cent->currentState.time, (float)r / 255.0f, (float)g / 255.0f, (float)b / 255.0f, 0 ); + } + } + } else if ( cent->currentState.eType == ET_SPOTLIGHT_EF ) { + + vec3_t targetpos, normalized_direction, direction; + float dist, fov = 90; + vec4_t color = {1, 1, 1, .1}; + int splinetarget = 0; + char *cs; + int time = 0; + + VectorCopy( cent->currentState.origin2, targetpos ); + + splinetarget = cent->overheatTime; + + time = cg.time; + if ( cent->currentState.frame == 1 ) { // dead, don't move + time = cent->currentState.time2; // 'time2' set when it died, so you have a good position + + + if ( rand() % 50 == 1 ) { + vec3_t angNorm; // normalized angles + VectorNormalize2( cent->lerpAngles, angNorm ); + // (origin, dir, speed, duration, count, 'randscale') + CG_AddBulletParticles( cent->lerpOrigin, angNorm, 2, 800, 4, 16.0f ); + trap_S_StartSound( NULL, cent->currentState.number, CHAN_AUTO, cgs.media.sparkSounds[0] ); + } + + // smoking dead light + if ( !cg_paused.integer ) { // don't add while paused + if ( !( rand() % 3 ) ) { + CG_ParticleImpactSmokePuffExtended( cgs.media.smokeParticleShader, cent->currentState.origin, tv( 0,0,1 ), 8, 1000, 8, 20, 20, 0.25f ); + } + } + } + + if ( !splinetarget ) { + cs = (char *)CG_ConfigString( CS_SPLINES + cent->currentState.density ); + cent->overheatTime = splinetarget = CG_LoadCamera( va( "cameras/%s.camera", cs ) ); + if ( splinetarget != -1 ) { + trap_startCamera( splinetarget, cg.time ); + } + } else { + vec3_t angles; + if ( splinetarget != -1 ) { + if ( trap_getCameraInfo( splinetarget, time, &targetpos, &angles, &fov ) ) { + } else { // loop + trap_startCamera( splinetarget, cg.time ); + trap_getCameraInfo( splinetarget, cg.time, &targetpos, &angles, &fov ); + } + } + } + + + normalized_direction[0] = direction[0] = targetpos[0] - cent->currentState.origin[0]; + normalized_direction[1] = direction[1] = targetpos[1] - cent->currentState.origin[1]; + normalized_direction[2] = direction[2] = targetpos[2] - cent->currentState.origin[2]; + + dist = VectorNormalize( normalized_direction ); + + if ( dist == 0 ) { + return; + } + + if ( cent->currentState.frame == 1 ) { // dead + if ( ( cg.time - cent->currentState.time2 ) < 100 ) { // it just died, throw some glass + CG_Explodef( cent->lerpOrigin, normalized_direction, 50, 1, cgs.media.sfx_bullet_glasshit[0], 1, 0, cent->currentState.number, qfalse ); + } + } + + CG_Spotlight( cent, color, cent->currentState.origin, normalized_direction, 999, 4096, 10, fov, 0 ); + + } else if ( cent->currentState.eType == ET_EFFECT3 ) { + vec3_t forward; + // tag attached emitter + + // messed up tag attachment rotation (forward for a tag is not forward in the world) + forward[0] = cent->lerpAngles[1]; + forward[1] = cent->lerpAngles[0]; + forward[2] = cent->lerpAngles[2]; + +// CG_FireFlameChunks( cent, cent->lerpOrigin, forward, 1.0, qtrue, 1 ); + CG_FireFlameChunks( cent, cent->currentState.pos.trBase, forward, 1.0, qtrue, 1 ); + } +} + + +//----(SA) adding func_explosive + +/* +=============== +CG_Explosive + This is currently almost exactly the same as CG_Mover + It's split out so that any changes or experiments are + unattached to anything else. +=============== +*/ +static void CG_Explosive( centity_t *cent ) { + lerpFrame_t *traplf; + refEntity_t ent; + entityState_t *s1; + + s1 = ¢->currentState; + + + // create the render entity + memset( &ent, 0, sizeof( ent ) ); + + traplf = ¢->lerpFrame; + +//----(SA) added animation stuff + if ( cent->currentState.modelindex2 ) { // there's a 'model2' + +// if(cent->currentState.effect3Time) { // if there's at least 1 frame specified, this is animated + + // first time initialize + if ( !cent->lerpFrame.oldFrameTime ) { + // note: effect3Time and density will be invalidated when this explodes. + // they get re-used for explosion parameters. seems like this + // could be re-arranged a bit better in the future. + // (this is why the above check for currentstate.effect3Time is commented out) + cent->centAnim[0].name[0] = 0; + cent->centAnim[0].firstFrame = 0; + cent->centAnim[0].numFrames = cent->currentState.effect3Time; + cent->centAnim[0].loopFrames = cent->currentState.effect3Time; + cent->centAnim[0].frameLerp = 1000.0f / 15.0f; + cent->centAnim[0].initialLerp = 1000.0f / 15.0f; + + cent->centAnim[1].name[0] = 0; + cent->centAnim[1].firstFrame = cent->currentState.effect3Time; + cent->centAnim[1].numFrames = cent->currentState.density; + cent->centAnim[1].loopFrames = 0; + cent->centAnim[1].frameLerp = 1000.0f / 15.0f; + cent->centAnim[1].initialLerp = 1000.0f / 15.0f; + + CG_NewAnim( cent, ¢->lerpFrame, ¢->centAnim[0], s1->frame ); + } + + CG_RunAnim( cent, &ent.frame, &ent.oldframe, &ent.backlerp ); +// } + } +//----(SA) end + + VectorCopy( cent->lerpOrigin, ent.origin ); + VectorCopy( cent->lerpOrigin, ent.oldorigin ); + + // fade out + if ( cent->currentState.time ) { + ent.fadeStartTime = cent->currentState.time; + ent.fadeEndTime = cent->currentState.time2; + } + + // TODO: need to set lightingOrigin? + +// AnglesToAxis( cent->lerpAngles, ent.axis ); + AnglesToAxis( cent->currentState.angles, ent.axis ); + + ent.renderfx = RF_NOSHADOW; + + // get the model, either as a bmodel or a modelindex + if ( s1->solid == SOLID_BMODEL ) { + ent.hModel = cgs.inlineDrawModel[s1->modelindex]; + } else { + ent.hModel = cgs.gameModels[s1->modelindex]; + } + + // add to refresh list + // trap_R_AddRefEntityToScene(&ent); + + // add the secondary model + if ( s1->modelindex2 ) { + ent.skinNum = 0; + ent.hModel = cgs.gameModels[s1->modelindex2]; + trap_R_AddRefEntityToScene( &ent ); + } else { + trap_R_AddRefEntityToScene( &ent ); + } + +} + +//----(SA) done + +/* +=============== +CG_Mover +=============== +*/ +static void CG_Mover( centity_t *cent ) { + refEntity_t ent; + entityState_t *s1; + + s1 = ¢->currentState; + + // create the render entity + memset( &ent, 0, sizeof( ent ) ); + + VectorCopy( cent->lerpOrigin, ent.origin ); + VectorCopy( cent->lerpOrigin, ent.oldorigin ); + + AnglesToAxis( cent->lerpAngles, ent.axis ); + + ent.renderfx = RF_NOSHADOW; + + // flicker between two skins (FIXME?) + ent.skinNum = 0; +// ent.skinNum = ( cg.time >> 6 ) & 1; + + // get the model, either as a bmodel or a modelindex + if ( s1->solid == SOLID_BMODEL ) { + ent.hModel = cgs.inlineDrawModel[s1->modelindex]; + } else { + ent.hModel = cgs.gameModels[s1->modelindex]; + } + + // add to refresh list + //trap_R_AddRefEntityToScene(&ent); + + + // Rafael + // testing for mike to get movers to scale + if ( cent->currentState.density == ET_MOVERSCALED ) { + VectorScale( ent.axis[0], cent->currentState.angles2[0], ent.axis[0] ); + VectorScale( ent.axis[1], cent->currentState.angles2[1], ent.axis[1] ); + VectorScale( ent.axis[2], cent->currentState.angles2[2], ent.axis[2] ); + ent.nonNormalizedAxes = qtrue; + } + + +//----(SA) added + if ( cent->currentState.eType == ET_ALARMBOX ) { + ent.renderfx |= RF_MINLIGHT; + } +//----(SA) end + + + // add the secondary model + if ( s1->modelindex2 ) { + ent.skinNum = 0; + ent.hModel = cgs.gameModels[s1->modelindex2]; + // set frame + ent.frame = s1->frame; + ent.oldframe = ent.frame; + ent.backlerp = 0; + // RF, add interpolation + if ( ent.frame && ( cent->currentState.eFlags & EF_MOVER_ANIMATE ) ) { + ent.oldframe -= 1; + ent.backlerp = 1 - cg.frameInterpolation; + } + trap_R_AddRefEntityToScene( &ent ); + memcpy( ¢->refEnt, &ent, sizeof( refEntity_t ) ); + } else { + trap_R_AddRefEntityToScene( &ent ); + } + + // add propeller and sfx to me109 + if ( cent->currentState.density == 7 || cent->currentState.density == 8 ) { + refEntity_t propeller; + vec3_t angles; + + memset( &propeller, 0, sizeof( propeller ) ); + VectorCopy( ent.lightingOrigin, propeller.lightingOrigin ); + propeller.shadowPlane = ent.shadowPlane; + propeller.renderfx = ent.renderfx; + + propeller.hModel = propellerModel; + + angles[PITCH] = cg.time % 16; + + AnglesToAxis( angles, propeller.axis ); + + CG_PositionRotatedEntityOnTag( &propeller, &ent, "tag_prop" ); + + trap_R_AddRefEntityToScene( &propeller ); + + if ( cent->currentState.density == 8 ) { + refEntity_t flash; + vec3_t angles; + + angles[YAW] = 90; + angles[ROLL] = random() * 90; + + memset( &flash, 0, sizeof( flash ) ); + flash.renderfx = ent.shadowPlane; + //flash.hModel = cgs.media.mg42muzzleflash; + flash.hModel = cgs.media.planemuzzleflash; + + AnglesToAxis( angles, flash.axis ); + CG_PositionRotatedEntityOnTag( &flash, &ent, "tag_gun1" ); + + trap_R_AddRefEntityToScene( &flash ); + trap_R_AddLightToScene( flash.origin, 200 + ( rand() & 31 ),1.0, 0.6, 0.23, 0 ); + + memset( &flash, 0, sizeof( flash ) ); + flash.renderfx = ent.shadowPlane; + //flash.hModel = cgs.media.mg42muzzleflash; + flash.hModel = cgs.media.planemuzzleflash; + + AnglesToAxis( angles, flash.axis ); + CG_PositionRotatedEntityOnTag( &flash, &ent, "tag_gun02" ); + + trap_R_AddRefEntityToScene( &flash ); + trap_R_AddLightToScene( flash.origin, 200 + ( rand() & 31 ),1.0, 0.6, 0.23, 0 ); + } + } + + // alarm box spark effects + + // (SA) I'd like to do this as an entity flag (EF_SPARKING or something) and have it randomly + // pick a vert on the model and have a few sparks at that point, jumping away from the core (geometric center or lerporigin) + // of the model. Then we could use it generally for sparking ents/characters/character gibs/etc + // (since we've got lots of electric based characters) + + if ( cent->currentState.eType == ET_ALARMBOX ) { + if ( cent->currentState.frame == 2 ) { // i'm dead + if ( rand() % 50 == 1 ) { + vec3_t angNorm; // normalized angles + VectorNormalize2( cent->lerpAngles, angNorm ); + // (origin, dir, speed, duration, count, 'randscale') + CG_AddBulletParticles( cent->lerpOrigin, angNorm, 2, 800, 4, 16.0f ); + trap_S_StartSound( NULL, cent->currentState.number, CHAN_AUTO, cgs.media.sparkSounds[0] ); + } + } + } +} + +/* +=============== +CG_Beam + +Also called as an event +=============== +*/ +void CG_Beam( centity_t *cent ) { + refEntity_t ent; + entityState_t *s1; + + s1 = ¢->currentState; + + // create the render entity + memset( &ent, 0, sizeof( ent ) ); + VectorCopy( s1->pos.trBase, ent.origin ); + VectorCopy( s1->origin2, ent.oldorigin ); + + AxisClear( ent.axis ); + ent.reType = RT_BEAM; + + ent.renderfx = RF_NOSHADOW; + + // add to refresh list + trap_R_AddRefEntityToScene( &ent ); +} + + +/* +=============== +CG_Portal +=============== +*/ +static void CG_Portal( centity_t *cent ) { + refEntity_t ent; + entityState_t *s1; + + s1 = ¢->currentState; + + // create the render entity + memset( &ent, 0, sizeof( ent ) ); + VectorCopy( cent->lerpOrigin, ent.origin ); + VectorCopy( s1->origin2, ent.oldorigin ); + ByteToDir( s1->eventParm, ent.axis[0] ); + PerpendicularVector( ent.axis[1], ent.axis[0] ); + + // negating this tends to get the directions like they want + // we really should have a camera roll value + VectorSubtract( vec3_origin, ent.axis[1], ent.axis[1] ); + + CrossProduct( ent.axis[0], ent.axis[1], ent.axis[2] ); + ent.reType = RT_PORTALSURFACE; + ent.frame = s1->frame; // rotation speed + ent.skinNum = s1->clientNum / 256.0 * 360; // roll offset + + // add to refresh list + trap_R_AddRefEntityToScene( &ent ); +} + +/* +=============== +CG_Prop +=============== +*/ +static void CG_Prop( centity_t *cent ) { + refEntity_t ent; + entityState_t *s1; + vec3_t angles; + float scale; + + s1 = ¢->currentState; + + if ( cg.cameraMode ) { // don't render chair in hands when in cinematic + return; + } + + // create the render entity + memset( &ent, 0, sizeof( ent ) ); + + if ( cg.renderingThirdPerson ) { + VectorCopy( cent->lerpOrigin, ent.origin ); + VectorCopy( cent->lerpOrigin, ent.oldorigin ); + + ent.frame = s1->frame; + ent.oldframe = ent.frame; + ent.backlerp = 0; + } else + { + VectorCopy( cg.refdef.vieworg, ent.origin ); + VectorCopy( cg.refdefViewAngles, angles ); + + if ( cg.bobcycle & 1 ) { + scale = -cg.xyspeed; + } else { + scale = cg.xyspeed; + } + + // modify angles from bobbing + angles[ROLL] += scale * cg.bobfracsin * 0.005; + angles[YAW] += scale * cg.bobfracsin * 0.01; + angles[PITCH] += cg.xyspeed * cg.bobfracsin * 0.005; + + VectorCopy( angles, cent->lerpAngles ); + + ent.frame = s1->frame; + ent.oldframe = ent.frame; + ent.backlerp = 0; + + if ( cent->currentState.density ) { + ent.frame = s1->frame + cent->currentState.density; + ent.oldframe = ent.frame - 1; + ent.backlerp = 1 - cg.frameInterpolation; + ent.renderfx = RF_DEPTHHACK | RF_FIRST_PERSON; + + //CG_Printf ("frame %d oldframe %d\n", ent.frame, ent.oldframe); + } else if ( ent.frame ) { + ent.oldframe -= 1; + ent.backlerp = 1 - cg.frameInterpolation; + } else + { + ent.renderfx = RF_DEPTHHACK | RF_FIRST_PERSON; + } + } + + AnglesToAxis( cent->lerpAngles, ent.axis ); + + ent.renderfx |= RF_NOSHADOW; + + // flicker between two skins (FIXME?) + ent.skinNum = ( cg.time >> 6 ) & 1; + + // get the model, either as a bmodel or a modelindex + if ( s1->solid == SOLID_BMODEL ) { + ent.hModel = cgs.inlineDrawModel[s1->modelindex]; + } else { + ent.hModel = cgs.gameModels[s1->modelindex]; + } + + // add to refresh list + //trap_R_AddRefEntityToScene(&ent); + + // add the secondary model + if ( s1->modelindex2 ) { + ent.skinNum = 0; + ent.hModel = cgs.gameModels[s1->modelindex2]; + ent.frame = s1->frame; + trap_R_AddRefEntityToScene( &ent ); + memcpy( ¢->refEnt, &ent, sizeof( refEntity_t ) ); + } else { + trap_R_AddRefEntityToScene( &ent ); + } + +} + +/* +============== +CG_FlamethrowerProp +============== +*/ +void CG_FlamethrowerProp( centity_t *cent ) { + int old; + int flags; + + old = cent->currentState.aiChar; + cent->currentState.aiChar = AICHAR_ZOMBIE; + + if ( !( cent->currentState.eFlags & EF_FIRING ) ) { + return; + } + + flags = 1; // use angles + + if ( cent->currentState.density ) { + flags |= 2; // silent + + } + // shoot this only in bursts + +// (SA) this first one doesn't seem to do anything. ? + +// if ((cg.time+cent->currentState.number*100)%1000 > 200) { +// CG_FireFlameChunks( cent, cent->currentState.origin, cent->lerpAngles, 0.1, qfalse, flags ); +// CG_FireFlameChunks( cent, cent->currentState.origin, cent->currentState.apos.trBase, 0.1, qfalse, flags ); +// } +// else +// CG_FireFlameChunks( cent, cent->currentState.origin, cent->lerpAngles, 0.6, 2, flags ); + + CG_FireFlameChunks( cent, cent->currentState.origin, cent->currentState.apos.trBase, 0.6, 2, flags ); + + cent->currentState.aiChar = old; + +} + +/* +================ +CG_ProcessRumble +================ +*/ +void CG_ProcessRumble( centity_t *cent ) { + + if ( cent->currentState.angles[2] > cg.rumbleScale ) { + cg.rumbleScale = cent->currentState.angles[2]; + } + +} + +/* +========================= +CG_AdjustPositionForMover + +Also called by client movement prediction code +========================= +*/ +void CG_AdjustPositionForMover( const vec3_t in, int moverNum, int fromTime, int toTime, vec3_t out, vec3_t outDeltaAngles ) { + centity_t *cent; + vec3_t oldOrigin, origin, deltaOrigin; + vec3_t oldAngles, angles, deltaAngles; + + if ( outDeltaAngles ) { + VectorClear( outDeltaAngles ); + } + + if ( moverNum <= 0 || moverNum >= ENTITYNUM_MAX_NORMAL ) { + VectorCopy( in, out ); + return; + } + + cent = &cg_entities[ moverNum ]; + + if ( cent->currentState.eType != ET_MOVER ) { + VectorCopy( in, out ); + return; + } + + BG_EvaluateTrajectory( ¢->currentState.pos, fromTime, oldOrigin ); + BG_EvaluateTrajectory( ¢->currentState.apos, fromTime, oldAngles ); + + BG_EvaluateTrajectory( ¢->currentState.pos, toTime, origin ); + BG_EvaluateTrajectory( ¢->currentState.apos, toTime, angles ); + + VectorSubtract( origin, oldOrigin, deltaOrigin ); + VectorSubtract( angles, oldAngles, deltaAngles ); + + VectorAdd( in, deltaOrigin, out ); + if ( outDeltaAngles ) { + VectorCopy( deltaAngles, outDeltaAngles ); + } + + // FIXME: origin change when on a rotating object +} + + +/* +============================= +CG_InterpolateEntityPosition +============================= +*/ +static void CG_InterpolateEntityPosition( centity_t *cent ) { + vec3_t current, next; + float f; + + // it would be an internal error to find an entity that interpolates without + // a snapshot ahead of the current one + if ( cg.nextSnap == NULL ) { + CG_Error( "CG_InterpoateEntityPosition: cg.nextSnap == NULL" ); + } + + f = cg.frameInterpolation; + + // this will linearize a sine or parabolic curve, but it is important + // to not extrapolate player positions if more recent data is available + BG_EvaluateTrajectory( ¢->currentState.pos, cg.snap->serverTime, current ); + BG_EvaluateTrajectory( ¢->nextState.pos, cg.nextSnap->serverTime, next ); + + cent->lerpOrigin[0] = current[0] + f * ( next[0] - current[0] ); + cent->lerpOrigin[1] = current[1] + f * ( next[1] - current[1] ); + cent->lerpOrigin[2] = current[2] + f * ( next[2] - current[2] ); + + BG_EvaluateTrajectory( ¢->currentState.apos, cg.snap->serverTime, current ); + BG_EvaluateTrajectory( ¢->nextState.apos, cg.nextSnap->serverTime, next ); + + cent->lerpAngles[0] = LerpAngle( current[0], next[0], f ); + cent->lerpAngles[1] = LerpAngle( current[1], next[1], f ); + cent->lerpAngles[2] = LerpAngle( current[2], next[2], f ); + +} + +/* +=============== +CG_CalcEntityLerpPositions + +=============== +*/ +static void CG_CalcEntityLerpPositions( centity_t *cent ) { + if ( cent->interpolate && cent->currentState.pos.trType == TR_INTERPOLATE ) { + CG_InterpolateEntityPosition( cent ); + return; + } + + // just use the current frame and evaluate as best we can + BG_EvaluateTrajectory( ¢->currentState.pos, cg.time, cent->lerpOrigin ); + BG_EvaluateTrajectory( ¢->currentState.apos, cg.time, cent->lerpAngles ); + + // adjust for riding a mover if it wasn't rolled into the predicted + // player state + if ( cent != &cg.predictedPlayerEntity ) { + CG_AdjustPositionForMover( cent->lerpOrigin, cent->currentState.groundEntityNum, + cg.snap->serverTime, cg.time, cent->lerpOrigin, NULL ); + } +} + +/* +=============== +CG_ProcessEntity +=============== +*/ +static void CG_ProcessEntity( centity_t *cent ) { + switch ( cent->currentState.eType ) { + default: + CG_Error( "Bad entity type: %i\n", cent->currentState.eType ); + break; + case ET_CAMERA: + case ET_INVISIBLE: + case ET_PUSH_TRIGGER: + case ET_TELEPORT_TRIGGER: + case ET_AI_EFFECT: + case ET_LEAKY: //----(SA) added + case ET_SPIRIT_SPAWNER: + break; + case ET_RUMBLE: + CG_ProcessRumble( cent ); + break; + case ET_GAMEMODEL: + if ( !cg_drawGamemodels.integer ) { + break; + } + case ET_MG42: + if ( cent->currentState.frame == 2 ) { // dead + if ( !cg_paused.integer ) { // don't add while paused + if ( !( rand() % 7 ) ) { + CG_ParticleImpactSmokePuffExtended( cgs.media.smokeParticleShader, cent->lerpOrigin, tv( 0,0,1 ), 6, 2000, 4, 10, 16, 0.2f ); + } + } + } + + case ET_FOOTLOCKER: + case ET_GENERAL: + CG_General( cent ); + break; + case ET_PLAYER: + CG_Player( cent ); + break; + case ET_ITEM: + CG_Item( cent ); + break; + case ET_MISSILE: + case ET_FLAMEBARREL: + case ET_FP_PARTS: + case ET_FIRE_COLUMN: + case ET_FIRE_COLUMN_SMOKE: + case ET_EXPLO_PART: + case ET_RAMJET: + CG_Missile( cent ); + break; + case ET_CROWBAR: + CG_Crowbar( cent ); + break; + case ET_ZOMBIESPIT: + CG_ZombieSpit( cent ); + break; + case ET_TESLA_EF: + case ET_SPOTLIGHT_EF: + case ET_EFFECT3: + CG_Efx( cent ); + break; + case ET_EXPLOSIVE: + CG_Explosive( cent ); + break; + case ET_TRAP: + CG_Trap( cent ); + break; + case ET_ALARMBOX: + case ET_MOVER: + CG_Mover( cent ); + break; + case ET_PROP: + CG_Prop( cent ); + break; + case ET_BEAM: + CG_Beam( cent ); + break; + case ET_PORTAL: + CG_Portal( cent ); + break; + case ET_SPEAKER: + CG_Speaker( cent ); + break; + case ET_CORONA: + CG_Corona( cent ); + break; + case ET_BAT: + CG_Bat( cent ); + break; + case ET_FLAMETHROWER_PROP: + CG_FlamethrowerProp( cent ); + break; + } +} + +/* +=============== +CG_AddCEntity + +=============== +*/ +static void CG_AddCEntity( centity_t *cent ) { + // event-only entities will have been dealt with already + if ( cent->currentState.eType >= ET_EVENTS ) { + return; + } + + cent->processedFrame = cg.clientFrame; + + // calculate the current origin + CG_CalcEntityLerpPositions( cent ); + + // add automatic effects + CG_EntityEffects( cent ); + + // call the appropriate function which will add this entity to the view accordingly + CG_ProcessEntity( cent ); +} + +/* +================== +CG_AddEntityToTag +================== +*/ +static void CG_AddEntityToTag( centity_t *cent ) { + entityState_t *s1; + centity_t *centParent; + entityState_t *sParent; + refEntity_t ent; + char *cs, *token = NULL; + int i, pi; + vec3_t ang; + + memset( &ent, 0, sizeof( ent ) ); + + // event-only entities will have been dealt with already + if ( cent->currentState.eType >= ET_EVENTS ) { + return; + } + + if ( cent->processedFrame == cg.clientFrame ) { + // already processed this frame + return; + } + + // calculate the current origin + CG_CalcEntityLerpPositions( cent ); + + s1 = ¢->currentState; + + // if set to invisible, skip + //if (!s1->modelindex) { + // return; + //} + + // find us in the list of tagged entities + sParent = NULL; + centParent = NULL; + for ( i = CS_TAGCONNECTS + 1; i < CS_TAGCONNECTS + MAX_TAGCONNECTS; i++ ) { // NOTE: +1 since G_FindConfigStringIndex() starts at index 1 rather than 0 (not sure why) + cs = (char *)CG_ConfigString( i ); + token = COM_Parse( &cs ); + if ( !token[0] ) { + break; + } + if ( atoi( token ) == s1->number ) { + token = COM_Parse( &cs ); + if ( !token[0] ) { + CG_Error( "CG_EntityTagConnected: missing parameter in configstring" ); + } + pi = atoi( token ); + if ( pi < 0 || pi >= MAX_GENTITIES ) { + CG_Error( "CG_EntityTagConnected: parent out of range" ); + } + centParent = &cg_entities[pi]; + sParent = &( cg_entities[pi].currentState ); + token = COM_Parse( &cs ); + if ( !token[0] ) { + CG_Error( "CG_EntityTagConnected: missing parameter in configstring" ); + } + + // NOTE: token is now the tag name to attach to + + break; + } + } + + if ( !sParent ) { + //return; // assume the configstring hasn't arrived yet? + CG_Error( "CG_EntityTagConnected: unable to find configstring to perform connection" ); + } + + // if parent isn't visible, then don't draw us + if ( !centParent->currentValid ) { + return; + } + + // make sure all parents are added first + if ( centParent->processedFrame != cg.clientFrame ) { + if ( sParent->eFlags & EF_TAGCONNECT ) { + CG_AddEntityToTag( centParent ); + } + } + + // if there was a higher ranking parent not added to the scene, then don't add us + if ( centParent->processedFrame != cg.clientFrame ) { + return; + } + + cent->processedFrame = cg.clientFrame; + + // start with default axis + AnglesToAxis( vec3_origin, ent.axis ); + //AnglesToAxis( cent->lerpAngles, ent.axis ); + + // get the tag position from parent + CG_PositionEntityOnTag( &ent, ¢Parent->refEnt, token, 0, NULL ); +// CG_PositionRotatedEntityOnTag( &ent, ¢Parent->refEnt, centParent->refEnt.hModel, token ); + + VectorCopy( ent.origin, cent->lerpOrigin ); + // we need to add the child's angles to the tag angles + //if (!cent->currentState.density) { // this entity should rotate with it's parent, but can turn around using it's own angles + AxisToAngles( ent.axis, ang ); + VectorAdd( cent->lerpAngles, ang, cent->lerpAngles ); + //} else { // face our angles exactly + // BG_EvaluateTrajectory( ¢->currentState.apos, cg.time, cent->lerpAngles ); + //} + + // add automatic effects + CG_EntityEffects( cent ); + + // call the appropriate function which will add this entity to the view accordingly + CG_ProcessEntity( cent ); +} + +/* +=============== +CG_AddPacketEntities + +=============== +*/ +void CG_AddPacketEntities( void ) { + int num; + centity_t *cent; + playerState_t *ps; + int clcount; + + // set cg.frameInterpolation + if ( cg.nextSnap ) { + int delta; + + delta = ( cg.nextSnap->serverTime - cg.snap->serverTime ); + if ( delta == 0 ) { + cg.frameInterpolation = 0; + } else { + cg.frameInterpolation = (float)( cg.time - cg.snap->serverTime ) / delta; + } + } else { + cg.frameInterpolation = 0; // actually, it should never be used, because + // no entities should be marked as interpolating + } + + cg.rumbleScale = 0.0; // RF, default to 0 each frame + + // the auto-rotating items will all have the same axis + cg.autoAnglesSlow[0] = 0; + cg.autoAnglesSlow[1] = ( cg.time & 4095 ) * 360 / 4095.0; + cg.autoAnglesSlow[2] = 0; + + cg.autoAngles[0] = 0; + cg.autoAngles[1] = ( cg.time & 2047 ) * 360 / 2048.0; + cg.autoAngles[2] = 0; + + cg.autoAnglesFast[0] = 0; + cg.autoAnglesFast[1] = ( cg.time & 1023 ) * 360 / 1024.0f; + cg.autoAnglesFast[2] = 0; + + AnglesToAxis( cg.autoAnglesSlow, cg.autoAxisSlow ); + AnglesToAxis( cg.autoAngles, cg.autoAxis ); + AnglesToAxis( cg.autoAnglesFast, cg.autoAxisFast ); + + // generate and add the entity from the playerstate + ps = &cg.predictedPlayerState; + BG_PlayerStateToEntityState( ps, &cg.predictedPlayerEntity.currentState, qfalse ); + CG_AddCEntity( &cg.predictedPlayerEntity ); + + // lerp the non-predicted value for lightning gun origins + CG_CalcEntityLerpPositions( &cg_entities[ cg.snap->ps.clientNum ] ); + + // add each entity sent over by the server + + + // RF, count the number of players in the scene, so we can force low LOD's for dead bodies + for ( num = 0, clcount = 0 ; num < cg.snap->numEntities ; num++ ) { + cent = &cg_entities[ cg.snap->entities[ num ].number ]; + cent->pe.forceLOD = qfalse; + if ( cent->currentState.number < MAX_CLIENTS ) { + clcount++; + } + } + + // NON TAG-CONNECTED ENTITIES + for ( num = 0 ; num < cg.snap->numEntities ; num++ ) { + cent = &cg_entities[ cg.snap->entities[ num ].number ]; + if ( !( cent->currentState.eFlags & EF_TAGCONNECT ) ) { +//----(SA) commented this out for DM and Dom +// if (cent->currentState.number < MAX_CLIENTS) { +// if ((clcount > 2) && (cent->currentState.eFlags & EF_DEAD)) { +// cent->pe.forceLOD = qtrue; +// } +// } +//----(SA) end + CG_AddCEntity( cent ); + } + } + + // TAG-CONNECTED ENTITIES (connected to NON TAG-CONNECTED ENTITIES) + for ( num = 0 ; num < cg.snap->numEntities ; num++ ) { + cent = &cg_entities[ cg.snap->entities[ num ].number ]; + if ( cent->currentState.eFlags & EF_TAGCONNECT ) { + CG_AddEntityToTag( cent ); + } + } + + // Ridah, add the flamethrower sounds + CG_UpdateFlamethrowerSounds(); +} diff --git a/Projects/Android/jni/rtcw/src/cgame/cg_event.c b/Projects/Android/jni/rtcw/src/cgame/cg_event.c new file mode 100644 index 0000000..a26961e --- /dev/null +++ b/Projects/Android/jni/rtcw/src/cgame/cg_event.c @@ -0,0 +1,2882 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + + +// cg_event.c -- handle entity events at snapshot or playerstate transitions + +#include "cg_local.h" +#include "../ui/ui_shared.h" // for Menus_CloseAll() + +extern int hWeaponSnd; + +extern void CG_Tracer( vec3_t source, vec3_t dest, int sparks ); +//========================================================================== + +/* +=================== +CG_PlaceString + +Also called by scoreboard drawing +=================== +*/ +const char *CG_PlaceString( int rank ) { + static char str[64]; + char *s, *t; + + if ( rank & RANK_TIED_FLAG ) { + rank &= ~RANK_TIED_FLAG; + t = "Tied for "; + } else { + t = ""; + } + + if ( rank == 1 ) { + s = S_COLOR_BLUE "1st" S_COLOR_WHITE; // draw in blue + } else if ( rank == 2 ) { + s = S_COLOR_RED "2nd" S_COLOR_WHITE; // draw in red + } else if ( rank == 3 ) { + s = S_COLOR_YELLOW "3rd" S_COLOR_WHITE; // draw in yellow + } else if ( rank == 11 ) { + s = "11th"; + } else if ( rank == 12 ) { + s = "12th"; + } else if ( rank == 13 ) { + s = "13th"; + } else if ( rank % 10 == 1 ) { + s = va( "%ist", rank ); + } else if ( rank % 10 == 2 ) { + s = va( "%ind", rank ); + } else if ( rank % 10 == 3 ) { + s = va( "%ird", rank ); + } else { + s = va( "%ith", rank ); + } + + Com_sprintf( str, sizeof( str ), "%s%s", t, s ); + return str; +} + +/* +============= +CG_Obituary +============= +*/ +static void CG_Obituary( entityState_t *ent ) { + int mod; + int target, attacker; + char *message; + char *message2; + const char *targetInfo; + const char *attackerInfo; + char targetName[32]; + char attackerName[32]; + gender_t gender; + clientInfo_t *ci; + + // Ridah, no obituaries in single player + if ( cgs.gametype == GT_SINGLE_PLAYER ) { + return; + } + + target = ent->otherEntityNum; + attacker = ent->otherEntityNum2; + mod = ent->eventParm; + + if ( target < 0 || target >= MAX_CLIENTS ) { + CG_Error( "CG_Obituary: target out of range" ); + } + ci = &cgs.clientinfo[target]; + + if ( attacker < 0 || attacker >= MAX_CLIENTS ) { + attacker = ENTITYNUM_WORLD; + attackerInfo = NULL; + } else { + attackerInfo = CG_ConfigString( CS_PLAYERS + attacker ); + } + + targetInfo = CG_ConfigString( CS_PLAYERS + target ); + if ( !targetInfo ) { + return; + } + Q_strncpyz( targetName, Info_ValueForKey( targetInfo, "n" ), sizeof( targetName ) - 2 ); + strcat( targetName, S_COLOR_WHITE ); + + message2 = ""; + + // check for single client messages + + switch ( mod ) { + case MOD_SUICIDE: + message = "suicides"; + break; + case MOD_FALLING: + message = "cratered"; + break; + case MOD_CRUSH: + message = "was squished"; + break; + case MOD_WATER: + message = "sank like a rock"; + break; + case MOD_SLIME: + message = "melted"; + break; + case MOD_LAVA: + message = "does a back flip into the lava"; + break; + case MOD_TARGET_LASER: + message = "saw the light"; + break; + case MOD_TRIGGER_HURT: + message = "was in the wrong place"; + break; + default: + message = NULL; + break; + } + + if ( attacker == target ) { + gender = ci->modelInfo->gender; + switch ( mod ) { + case MOD_GRENADE_SPLASH: + if ( gender == GENDER_FEMALE ) { + message = "tripped on her own grenade"; + } else if ( gender == GENDER_NEUTER ) { + message = "tripped on its own grenade"; + } else { + message = "tripped on his own grenade"; + } + break; + case MOD_ROCKET_SPLASH: + if ( gender == GENDER_FEMALE ) { + message = "blew herself up"; + } else if ( gender == GENDER_NEUTER ) { + message = "blew itself up"; + } else { + message = "blew himself up"; + } + break; + case MOD_BFG_SPLASH: + message = "should have used a smaller gun"; + break; + case MOD_EXPLOSIVE: + message = "died in an explosion"; + break; + default: + if ( gender == GENDER_FEMALE ) { + message = "killed herself"; + } else if ( gender == GENDER_NEUTER ) { + message = "killed itself"; + } else { + message = "killed himself"; + } + break; + } + } + + if ( message ) { + CG_Printf( "%s %s.\n", targetName, message ); + return; + } + + // check for kill messages from the current clientNum + if ( attacker == cg.snap->ps.clientNum ) { + char *s; + + if ( cgs.gametype < GT_TEAM ) { + s = va( "You fragged %s\n%s place with %i", targetName, + CG_PlaceString( cg.snap->ps.persistant[PERS_RANK] + 1 ), + cg.snap->ps.persistant[PERS_SCORE] ); + } else { + s = va( "You fragged %s", targetName ); + } + CG_CenterPrint( s, SCREEN_HEIGHT * 0.25, BIGCHAR_WIDTH ); + + // print the text message as well + } + + // check for double client messages + if ( !attackerInfo ) { + attacker = ENTITYNUM_WORLD; + strcpy( attackerName, "noname" ); + } else { + Q_strncpyz( attackerName, Info_ValueForKey( attackerInfo, "n" ), sizeof( attackerName ) - 2 ); + strcat( attackerName, S_COLOR_WHITE ); + // check for kill messages about the current clientNum + if ( target == cg.snap->ps.clientNum ) { + Q_strncpyz( cg.killerName, attackerName, sizeof( cg.killerName ) ); + } + } + + if ( attacker != ENTITYNUM_WORLD ) { + switch ( mod ) { + + // TODO: put real text here. these are just placeholders + + case MOD_KNIFE_STEALTH: + case MOD_KNIFE: + case MOD_KNIFE2: + message = "was knifed by"; + break; + case MOD_LUGER: + message = "was killed (luger) by"; + break; + case MOD_COLT: + message = "was killed (colt) by"; + break; + case MOD_MP40: + message = "was killed (mp40) by"; + break; + case MOD_THOMPSON: + message = "was killed (thompson) by"; + break; + case MOD_STEN: + message = "was killed (sten) by"; + break; + case MOD_MAUSER: + message = "was killed (mauser) by"; + break; + case MOD_SNIPERRIFLE: + message = "was killed (sniper) by"; + break; + case MOD_GARAND: + message = "was killed (garand) by"; + break; + case MOD_SNOOPERSCOPE: + message = "was killed (snooper) by"; + break; + case MOD_AKIMBO: + message = "was killed (dual colts) by"; + break; + case MOD_ROCKET_LAUNCHER: + message = "was killed (rl) by"; + break; + case MOD_GRENADE_LAUNCHER: + message = "was killed (gren - gm) by"; + break; + case MOD_VENOM: + message = "was killed (venom) by"; + break; + case MOD_VENOM_FULL: + message = "was killed (venom shot) by"; + break; + case MOD_FLAMETHROWER: + message = "was killed (flamethrower) by"; + break; + case MOD_TESLA: + message = "was killed (tesla) by"; + break; + case MOD_SPEARGUN: + message = "was killed (spear) by"; + break; + case MOD_SPEARGUN_CO2: + message = "was killed (co2 spear) by"; + break; + case MOD_GRENADE_PINEAPPLE: + message = "was killed (gren - am) by"; + break; + case MOD_CROSS: + message = "was killed (cross) by"; + break; +// JPW NERVE + case MOD_AIRSTRIKE: + message = "stood under"; + message2 = "'s air strike"; + break; +// jpw +// (SA) leaving a sample of two part obit's +// case MOD_ROCKET: +// message = "ate"; +// message2 = "'s rocket"; +// break; +// case MOD_ROCKET_SPLASH: +// message = "almost dodged"; +// message2 = "'s rocket"; +// break; + default: + message = "was killed by"; + break; + } + + if ( message ) { + CG_Printf( "%s %s %s%s\n", + targetName, message, attackerName, message2 ); + return; + } + } + + // we don't know what it was +// JPW NERVE added mod check for machinegun (prolly mortar here too) + switch ( mod ) { + case MOD_MACHINEGUN: + CG_Printf( "%s was riddled by machinegun fire\n",targetName ); + break; + default: + CG_Printf( "%s died.\n", targetName ); + break; + } +// jpw +} + +//========================================================================== + +/* +=============== +CG_UseItem +=============== +*/ +static void CG_UseItem( centity_t *cent ) { + int itemNum; + gitem_t *item; + entityState_t *es; + + es = ¢->currentState; + + // itemNum = es->event - EV_USE_ITEM0; + // JCash bluesnews reported fix + itemNum = ( es->event & ~EV_EVENT_BITS ) - EV_USE_ITEM0; + + if ( itemNum < 0 || itemNum > HI_NUM_HOLDABLE ) { + itemNum = 0; + } + + // print a message if the local player + if ( es->number == cg.snap->ps.clientNum ) { + if ( !itemNum ) { + CG_CenterPrint( "noitem", SCREEN_HEIGHT - ( SCREEN_HEIGHT * 0.25 ), SMALLCHAR_WIDTH ); //----(SA) modified + } else { + item = BG_FindItemForHoldable( itemNum ); + + if ( item ) { + cg.holdableSelectTime = cg.time; // show remaining items + + switch ( itemNum ) { + case HI_BOOK1: + case HI_BOOK2: + case HI_BOOK3: + break; + case HI_WINE: + CG_CenterPrint( "drankwine", SCREEN_HEIGHT - ( SCREEN_HEIGHT * 0.25 ), SMALLCHAR_WIDTH ); + break; + default: + CG_CenterPrint( va( "Use %s", cgs.itemPrintNames[item - bg_itemlist] ), SCREEN_HEIGHT - ( SCREEN_HEIGHT * 0.25 ), SMALLCHAR_WIDTH ); + break; + } + } + } + } + + switch ( itemNum ) { + default: + case HI_NONE: + trap_S_StartSound( NULL, es->number, CHAN_BODY, cgs.media.useNothingSound ); + break; + + case HI_BOOK1: + case HI_BOOK2: + case HI_BOOK3: + trap_S_StartSound( NULL, es->number, CHAN_BODY, cgs.media.bookSound ); + break; + + case HI_WINE: + trap_S_StartSound( NULL, es->number, CHAN_BODY, cgs.media.wineSound ); + break; + + case HI_STAMINA: + trap_S_StartSound( NULL, es->number, CHAN_BODY, cgs.media.staminaSound ); + break; + } + +} + +// from cg_weapons.c +extern int CG_WeaponIndex( int weapnum, int *bank, int *cycle ); + + +/* +================ +CG_ItemPickup + +A new item was picked up this frame +================ +*/ +static void CG_ItemPickup( int itemNum ) { + int itemid; + int wpbank_cur, wpbank_pickup; + qboolean selectIt; + + itemid = bg_itemlist[itemNum].giTag; + + cg.itemPickup = itemNum; + cg.itemPickupTime = cg.time; + cg.itemPickupBlendTime = cg.time; + + // see if it should be the grabbed weapon + if ( bg_itemlist[itemNum].giType == IT_WEAPON ) { + int weapon; + + selectIt = qfalse; + + weapon = itemid; + + if ( weapon == WP_COLT ) { + if ( COM_BitCheck( cg.snap->ps.weapons, weapon ) ) { + weapon = WP_AKIMBO; // you have colt, now get akimbo (second) + } + } + + if ( cg_autoswitch.integer && cg.predictedPlayerState.weaponstate != WEAPON_RELOADING ) { + + // 0 - "Off" + // 1 - "Always Switch" + // 2 - "If New" + // 3 - "If Better" + // 4 - "New or Better" + // 5 - "New and Better" + + // don't ever autoswitch to secondary fire weapons + if ( weapon != WP_SNIPERRIFLE && weapon != WP_SNOOPERSCOPE && weapon != WP_FG42SCOPE ) { //----(SA) modified + + // no weap currently selected, always just select the new one + if ( !cg.weaponSelect ) { + selectIt = qtrue; + } + // 1 - "Always Switch" - always switch to new weap (Q3A default) + else if ( cg_autoswitch.integer == 1 ) { + selectIt = qtrue; + } else { + + // 2 - "If New" - switch to weap if it's not already in the player's inventory (Wolf default) + // 4 - either 2 or 3 + // 5 - both 2 and 3 + + // FIXME: this works fine for predicted pickups (when you walk over the weapon), but not for + // manual pickups (activate item) + if ( cg_autoswitch.integer == 2 || cg_autoswitch.integer == 4 || cg_autoswitch.integer == 5 ) { + if ( !COM_BitCheck( cg.snap->ps.weapons, weapon ) ) { + selectIt = qtrue; + } + } // end 2/4/5 + + // 3 - "If Better" - switch to weap if it's in a bank greater than the current weap + // 4 - either 2 or 3 + // 5 - both 2 and 3 + if ( cg_autoswitch.integer == 3 || cg_autoswitch.integer == 4 || cg_autoswitch.integer == 5 ) { + // switch away only if a primary weapon is selected (read: don't switch away if current weap is a secondary mode) + if ( CG_WeaponIndex( cg.weaponSelect, &wpbank_cur, NULL ) ) { + if ( CG_WeaponIndex( weapon, &wpbank_pickup, NULL ) ) { + if ( wpbank_pickup > wpbank_cur ) { + if ( cg_autoswitch.integer == 5 ) { // 'new /and/ better' + if ( !selectIt ) { + selectIt = qfalse; // if it isn't selected because it's new, then this isn't "both" new /and/ better + } + } else { + selectIt = qtrue; + } + } else { // not better + if ( cg_autoswitch.integer == 5 ) { + selectIt = qfalse; + } + } + } + } + } // end 3/4/5 + + } // end cg_autoswitch.integer != 1 + + } // end weapon != WP_SNIPERRIFLE && ... + + } // end cg_autoswitch.integer + + // only select one-handed weaps if you've got a chair + if ( cg.snap->ps.eFlags & EF_MELEE_ACTIVE ) { + if ( !( ( 1 << weapon ) & WEAPS_ONE_HANDED ) ) { + selectIt = qfalse; + } + } + + if ( selectIt ) { + cg.weaponSelectTime = cg.time; + cg.weaponSelect = weapon; + } + + } // end bg_itemlist[itemNum].giType == IT_WEAPON + + + if ( bg_itemlist[itemNum].giType == IT_HOLDABLE ) { + cg.holdableSelectTime = cg.time; // show holdables when a new one is picked up + cg.holdableSelect = itemid; // and select the new one + } + +} + + +/* +================ +CG_PainEvent + +Also called by playerstate transition +================ +*/ +typedef struct { + char *tag; + int refEntOfs; + int anim; +} painAnimForTag_t; + +#define PEFOFS( x ) ( (int)&( ( (playerEntity_t *)0 )->x ) ) + +void CG_PainEvent( centity_t *cent, int health, qboolean crouching ) { + char *snd; + + #define STUNNED_ANIM BOTH_PAIN8 + painAnimForTag_t tagAnims[] = { + {"tag_head", PEFOFS( torsoRefEnt ), BOTH_PAIN1}, + {"tag_chest", PEFOFS( torsoRefEnt ), BOTH_PAIN2}, + {"tag_groin", PEFOFS( legsRefEnt ), BOTH_PAIN3}, + {"tag_armright",PEFOFS( torsoRefEnt ), BOTH_PAIN4}, + {"tag_armleft", PEFOFS( torsoRefEnt ), BOTH_PAIN5}, + {"tag_legright",PEFOFS( legsRefEnt ), BOTH_PAIN6}, + {"tag_legleft", PEFOFS( legsRefEnt ), BOTH_PAIN7}, + {NULL,0,0}, + }; + vec3_t tagOrg; + int tagIndex, bestTag, oldPainAnim; + float bestDist, dist; + + // Rafael + if ( cent->currentState.aiChar && cgs.gametype == GT_SINGLE_PLAYER ) { + + if ( cent->pe.painTime > cg.time - 1000 ) { + oldPainAnim = cent->pe.painAnimTorso; + } else { + oldPainAnim = -1; + } + + // Ridah, health is actually time to spend playing the animation + cent->pe.painTime = cg.time; + cent->pe.painDuration = health << 4; + cent->pe.painDirection ^= 1; + cent->pe.painAnimLegs = -1; + cent->pe.painAnimTorso = -1; + + if ( VectorLength( cent->currentState.origin2 ) > 1 ) { + // find a correct animation to play, based on the body orientation at previous frame + for ( tagIndex = 0, bestDist = 0, bestTag = -1; tagAnims[tagIndex].tag; tagIndex++ ) { + if ( oldPainAnim >= 0 && tagAnims[tagIndex].anim == oldPainAnim ) { + continue; + } + // grab the tag with this name + if ( CG_GetOriginForTag( cent, ( refEntity_t * )( ( (byte *)¢->pe ) + tagAnims[tagIndex].refEntOfs ), tagAnims[tagIndex].tag, 0, tagOrg, NULL ) >= 0 ) { + dist = VectorDistance( tagOrg, cent->currentState.origin2 ); + if ( !bestDist || dist < bestDist ) { + bestTag = tagIndex; + bestDist = dist; + } + } + } + + if ( bestTag >= 0 ) { + if ( !crouching ) { + cent->pe.painAnimLegs = tagAnims[bestTag].anim; + } + cent->pe.painAnimTorso = tagAnims[bestTag].anim; + } + } + + if ( cent->pe.painAnimTorso < 0 && cent->pe.painDuration > 1000 ) { // stunned + if ( !crouching ) { + cent->pe.painAnimLegs = STUNNED_ANIM; + } + cent->pe.painAnimTorso = STUNNED_ANIM; + } + + if ( cent->pe.painAnimTorso < 0 ) { + // pick a random anim + for ( tagIndex = 0; tagAnims[tagIndex].tag; tagIndex++ ) {}; + bestTag = rand() % tagIndex; + if ( !crouching ) { + cent->pe.painAnimLegs = tagAnims[bestTag].anim; + } + cent->pe.painAnimTorso = tagAnims[bestTag].anim; + } + + // adjust the animation speed + { + animation_t *anim; + clientInfo_t *ci; + + ci = &cgs.clientinfo[ cent->currentState.number ]; + anim = &ci->modelInfo->animations[ cent->pe.painAnimTorso ]; + + cent->pe.animSpeed = ( anim->frameLerp * anim->numFrames ) / (float)cent->pe.painDuration; + } + + return; + } + + // don't do more than two pain sounds a second + if ( cg.time - cent->pe.painTime < 500 ) { + return; + } + + if ( health < 25 ) { + snd = "*pain25_1.wav"; + } else if ( health < 50 ) { + snd = "*pain50_1.wav"; + } else if ( health < 75 ) { + snd = "*pain75_1.wav"; + } else { + snd = "*pain100_1.wav"; + } + trap_S_StartSound( NULL, cent->currentState.number, CHAN_VOICE, + CG_CustomSound( cent->currentState.number, snd ) ); + + // save pain time for programitic twitch animation + cent->pe.painTime = cg.time; + cent->pe.painDirection ^= 1; +} + + + + + +/* +============== +CG_Explode + + + if (cent->currentState.angles2[0] || cent->currentState.angles2[1] || cent->currentState.angles2[2]) + +============== +*/ + +#define POSSIBLE_PIECES 6 + + + + +void CG_Explodef( vec3_t origin, vec3_t dir, int mass, int type, qhandle_t sound, int forceLowGrav, qhandle_t shader, int parent, qboolean damage ); + +/* +============== +CG_Explode + the old cent-based explode calls will still work with this pass-through +============== +*/ +void CG_Explode( centity_t *cent, vec3_t origin, vec3_t dir, qhandle_t shader ) { + vec3_t pos; + qhandle_t inheritmodel = 0; + + +// VectorCopy(origin, pos); + VectorCopy( cent->currentState.origin2, pos ); + + // inherit shader + // (SA) FIXME: do this at spawn time rather than explode time so any new necessary shaders are created earlier + if ( cent->currentState.eFlags & EF_INHERITSHADER ) { + if ( !shader ) { +// inheritmodel = cent->currentState.modelindex; + inheritmodel = cgs.inlineDrawModel[cent->currentState.modelindex]; // okay, this should be better. + if ( inheritmodel ) { + shader = trap_R_GetShaderFromModel( inheritmodel, 0, 0 ); + } + } + } + + CG_Explodef( pos, + dir, + cent->currentState.density, // mass +// cent->currentState.time2, // type + cent->currentState.effect3Time, //----(SA) needed .time + cent->currentState.dl_intensity, // sound + cent->currentState.weapon, // forceLowGrav + shader, + cent->currentState.number, + cent->currentState.teamNum + ); + +} + + +/* +============== +CG_Explodef + made this more generic for spawning hits and breaks without needing a *cent +============== +*/ +void CG_Explodef( vec3_t origin, vec3_t dir, int mass, int type, qhandle_t sound, int forceLowGrav, qhandle_t shader, int parent, qboolean damage ) { + int i; + localEntity_t *le; + refEntity_t *re; + int howmany, total; + int pieces[6]; // how many of each piece + qhandle_t modelshader = 0; + float materialmul = 1; // multiplier for different types + + memset( &pieces, 0, sizeof( pieces ) ); + + if ( type == 5 && damage ) { + vec3_t vec, org; + centity_t *boss; + // set the default pos to the viewpos + VectorCopy( cg.refdef.vieworg, org ); + // find the boss + for ( boss = cg_entities; boss < &cg_entities[MAX_CLIENTS]; boss++ ) { + if ( !boss->currentValid ) { + continue; + } + if ( boss->currentState.aiChar == AICHAR_HEINRICH ) { + VectorCopy( boss->lerpOrigin, org ); + break; + } + } + // optimization, ignore if too far away + VectorSubtract( origin, org, vec ); // whoops, that way wouldn't work for cameras... + vec[2] = 0; + if ( VectorLength( vec ) > 800 ) { + return; + } + mass = (int)( 2.0 * mass * ( 1.0 - ( 0.6 + 0.4 * ( VectorLength( vec ) / 800.0 ) ) ) ); + } + + pieces[5] = (int)( mass / 250.0f ); + pieces[4] = (int)( mass / 76.0f ); + pieces[3] = (int)( mass / 37.0f ); // so 2 per 75 + pieces[2] = (int)( mass / 15.0f ); + pieces[1] = (int)( mass / 10.0f ); + pieces[0] = (int)( mass / 5.0f ); + + if ( pieces[0] > 20 ) { + pieces[0] = 20; // cap some of the smaller bits so they don't get out of control + } + if ( pieces[1] > 15 ) { + pieces[1] = 15; + } + if ( pieces[2] > 10 ) { + pieces[2] = 10; + } + + if ( type == 0 ) { // cap wood even more since it's often grouped, and the small splinters can add up + if ( pieces[0] > 10 ) { + pieces[0] = 10; + } + if ( pieces[1] > 10 ) { + pieces[1] = 10; + } + if ( pieces[2] > 10 ) { + pieces[2] = 10; + } + } + + // cap end map debris (optimization) + if ( type == 5 && damage ) { + pieces[0] = 5; + pieces[1] = 5; + pieces[2] = 4; + pieces[3] = 4; + pieces[4] = 4; + } + + total = pieces[5] + pieces[4] + pieces[3] + pieces[2] + pieces[1] + pieces[0]; + + if ( sound ) { + trap_S_StartSound( origin, ENTITYNUM_WORLD, CHAN_AUTO, cgs.gameSounds[sound] ); + } + + if ( shader ) { // shader passed in to use + modelshader = shader; + } + + for ( i = 0; i < POSSIBLE_PIECES; i++ ) { + leBounceSoundType_t snd = LEBS_NONE; + int hmodel = 0; + float scale; + int endtime; + for ( howmany = 0; howmany < pieces[i]; howmany++ ) { + + scale = 1.0f; + endtime = 0; // set endtime offset for faster/slower fadeouts + + switch ( type ) { + case 0: // "wood" + snd = LEBS_WOOD; + hmodel = cgs.media.debWood[i]; + + if ( i == 0 ) { + scale = 0.5f; + } else if ( i == 1 ) { + scale = 0.6f; + } else if ( i == 2 ) { + scale = 0.7f; + } else if ( i == 3 ) { + scale = 0.5f; + } + // else + // scale = cg_forceModel.value; + // else goto pass; + + if ( i < 3 ) { + endtime = -3000; // small bits live 3 sec shorter than normal + } + break; + + case 1: // "glass" + snd = LEBS_NONE; + if ( i == 5 ) { + hmodel = cgs.media.shardGlass1; + } else if ( i == 4 ) { + hmodel = cgs.media.shardGlass2; + } else if ( i == 2 ) { + hmodel = cgs.media.shardGlass2; + } else if ( i == 1 ) { + hmodel = cgs.media.shardGlass2; + scale = 0.5f; + } else {goto pass;} + break; + + case 2: // "metal" + snd = LEBS_BRASS; + if ( i == 5 ) { + hmodel = cgs.media.shardMetal1; + } else if ( i == 4 ) { + hmodel = cgs.media.shardMetal2; + } else if ( i == 2 ) { + hmodel = cgs.media.shardMetal2; + } else if ( i == 1 ) { + hmodel = cgs.media.shardMetal2; + scale = 0.5f; + } else {goto pass;} + break; + + case 3: // "gibs" + snd = LEBS_BLOOD; + if ( i == 5 ) { + hmodel = cgs.media.gibIntestine; + } else if ( i == 4 ) { + hmodel = cgs.media.gibLeg; + } else if ( i == 2 ) { + hmodel = cgs.media.gibChest; + } else { goto pass;} + break; + + case 4: // "brick" + snd = LEBS_ROCK; + hmodel = cgs.media.debBlock[i]; + break; + + case 5: // "rock" + snd = LEBS_ROCK; + if ( i == 5 ) { + hmodel = cgs.media.debRock[2]; // temporarily use the next smallest rock piece + } else if ( i == 4 ) { + hmodel = cgs.media.debRock[2]; + } else if ( i == 3 ) { + hmodel = cgs.media.debRock[1]; + } else if ( i == 2 ) { + hmodel = cgs.media.debRock[0]; + } else if ( i == 1 ) { + hmodel = cgs.media.debBlock[1]; // temporarily use the small block pieces + } else { hmodel = cgs.media.debBlock[0]; // temporarily use the small block pieces + } + if ( i <= 2 ) { + endtime = -2000; // small bits live 2 sec shorter than normal + } + break; + + case 6: // "fabric" + if ( i == 5 ) { + hmodel = cgs.media.debFabric[0]; + } else if ( i == 4 ) { + hmodel = cgs.media.debFabric[1]; + } else if ( i == 2 ) { + hmodel = cgs.media.debFabric[2]; + } else if ( i == 1 ) { + hmodel = cgs.media.debFabric[2]; + scale = 0.5; + } else {goto pass; // (only do 5, 4, 2 and 1) + } + break; + } + + le = CG_AllocLocalEntity(); + re = &le->refEntity; + + le->leType = LE_FRAGMENT; + le->startTime = cg.time; + + le->endTime = ( le->startTime + 5000 + random() * 5000 ) + endtime; + + // RF, debris rocks last longer in the boss map (is thee a better way of doing this at this late stage?) + if ( snd == LEBS_ROCK && damage ) { + snd = 0; + if ( damage ) { + le->leFlags |= LEF_PLAYER_DAMAGE; + } + le->endTime = le->startTime + 7000 + random() * 5000; + } + + if ( parent ) { + le->leFlags |= LEF_NOTOUCHPARENT; //----(SA) added + le->ownerNum = parent; + } + + // as it turns out, i'm not sure if setting the re->axis here will actually do anything + // AxisClear(re->axis); + // re->axis[0][0] = + // re->axis[1][1] = + // re->axis[2][2] = scale; + // + // if(scale != 1.0) + // re->nonNormalizedAxes = qtrue; + + le->sizeScale = scale; + + if ( type == 1 ) { // glass + // Rafael added this because glass looks funky when it fades out + // TBD: need to look into this so that they fade out correctly + re->fadeStartTime = le->endTime; + re->fadeEndTime = le->endTime; + } else { + re->fadeStartTime = le->endTime - 4000; + re->fadeEndTime = le->endTime; + } + + + le->lifeRate = 1.0 / ( le->endTime - le->startTime ); + le->leFlags |= LEF_TUMBLE; + le->leMarkType = 0; + + VectorCopy( origin, re->origin ); + AxisCopy( axisDefault, re->axis ); + + le->leBounceSoundType = snd; + re->hModel = hmodel; + + // inherit shader + if ( modelshader ) { + re->customShader = modelshader; + } + + re->radius = 1000; + + switch ( type ) { + case 6: // fabric + le->pos.trType = TR_GRAVITY_FLOAT; // the fabric stuff will change to use something that looks better + le->bounceFactor = 0.0f; + materialmul = 0.3f; // rotation speed + break; + default: + if ( !forceLowGrav && rand() & 1 ) { // if low gravity is not forced and die roll goes our way use regular grav + le->pos.trType = TR_GRAVITY; + } else { + le->pos.trType = TR_GRAVITY_LOW; + } + le->bounceFactor = 0.2f; // RF, rubble in end is like rubber, also ID requestsed this + break; + } + + + // rotation + le->angles.trType = TR_LINEAR; + le->angles.trTime = cg.time; + le->angles.trBase[0] = rand() & 31; + le->angles.trBase[1] = rand() & 31; + le->angles.trBase[2] = rand() & 31; + le->angles.trDelta[0] = ( ( 100 + ( rand() & 500 ) ) - 300 ) * materialmul; + le->angles.trDelta[1] = ( ( 100 + ( rand() & 500 ) ) - 300 ) * materialmul; + le->angles.trDelta[2] = ( ( 100 + ( rand() & 500 ) ) - 300 ) * materialmul; + + + // if(type == 6) // fabric + // materialmul = 1; // translation speed + + + VectorCopy( origin, le->pos.trBase ); + VectorNormalize( dir ); + le->pos.trTime = cg.time; + + // (SA) hoping that was just intended to represent randomness + // if (cent->currentState.angles2[0] || cent->currentState.angles2[1] || cent->currentState.angles2[2]) + if ( ( le->angles.trBase[0] == 1 || le->angles.trBase[1] == 1 || le->angles.trBase[2] == 1 ) && type != 6 ) { // not for fabric + le->pos.trType = TR_GRAVITY; + VectorScale( dir, 10 * 8, le->pos.trDelta ); + le->pos.trDelta[0] += ( ( random() * 100 ) - 50 ); + le->pos.trDelta[1] += ( ( random() * 100 ) - 50 ); + le->pos.trDelta[2] = ( random() * 200 ) + 200; + + } else { + // location + VectorScale( dir, 200 + mass, le->pos.trDelta ); + le->pos.trDelta[0] += ( ( random() * 100 ) - 50 ); + le->pos.trDelta[1] += ( ( random() * 100 ) - 50 ); + + if ( dir[2] ) { + le->pos.trDelta[2] = random() * 200 * materialmul; // randomize sort of a lot so they don't all land together + } else { + le->pos.trDelta[2] = random() * 20; + } + + if ( type == 5 && damage ) { + VectorScale( le->pos.trDelta, 4.0, le->pos.trDelta ); + // dont let them fly out too fast + while ( VectorLength( le->pos.trDelta ) > 800 ) { + VectorScale( le->pos.trDelta, 0.5, le->pos.trDelta ); + } + } + } + } +pass: + continue; + } + +} + + +/* +============== +CG_Effect + Quake ed -> target_effect (0 .5 .8) (-6 -6 -6) (6 6 6) TNT explode smoke debris gore lowgrav +============== +*/ +void CG_Effect( centity_t *cent, vec3_t origin, vec3_t dir ) { + localEntity_t *le; + refEntity_t *re; +// int howmany; + int mass; +// int large, small; + + VectorSet( dir, 0, 0, 1 ); // straight up. + + mass = cent->currentState.density; + +// 1 large per 100, 1 small per 24 +// large = (int)(mass / 100); +// small = (int)(mass / 24) + 1; + + if ( cent->currentState.eventParm & 1 ) { // fire + vec3_t sprVel, sprOrg; + int i,j; + + // RF, sprVel is used without being set, so to be sure, I'm going to clear out the vector + VectorClear( sprVel ); + + for ( i = 0; i < 5; i++ ) { + for ( j = 0; j < 3; j++ ) + sprOrg[j] = origin[j] + 64 * dir[j] + 24 * crandom(); + sprVel[2] += rand() % 50; + CG_ParticleExplosion( "blacksmokeanimb", sprOrg, sprVel, + 3500 + rand() % 250, // duration + 10, // startsize + 250 + rand() % 60 ); // endsize + } + + VectorMA( origin, 16, dir, sprOrg ); + VectorScale( dir, 100, sprVel ); + + // trying this one just for now just for variety + CG_ParticleExplosion( "explode1", sprOrg, sprVel, + 1200, // duration + 9, // startsize + 300 ); // endsize + + CG_AddDebris( origin, dir, + 280, // speed + 1400, // duration + 7 + rand() % 2 ); // count + + trap_S_StartSound( origin, ENTITYNUM_WORLD, CHAN_AUTO, cgs.media.sfx_dynamiteexp ); + trap_S_StartLocalSound( cgs.media.sfx_dynamiteexpDist, CHAN_AUTO ); + CG_ImpactMark( cgs.media.burnMarkShader, origin, dir, random() * 360, 1,1,1,1, qfalse, 64, qfalse, -1 ); + } + + // (SA) right now force smoke on any explosions +// if(cent->currentState.eventParm & 4) // smoke + if ( cent->currentState.eventParm & 6 ) { + int i, j; + vec3_t sprVel, sprOrg; + // explosion sprite animation + VectorScale( dir, 16, sprVel ); + for ( i = 0; i < 5; i++ ) { + for ( j = 0; j < 3; j++ ) + sprOrg[j] = origin[j] + 64 * dir[j] + 24 * crandom(); + sprVel[2] += rand() % 50; +// CG_ParticleExplosion( 2, sprOrg, sprVel, 1000+rand()%250, 20, 40+rand()%60 ); + CG_ParticleExplosion( "blacksmokeanimb", sprOrg, sprVel, 3500 + rand() % 250, 10, 250 + rand() % 60 ); + } + } + + + if ( cent->currentState.eventParm & 2 ) { // explode + vec3_t sprVel, sprOrg; + trap_S_StartSound( origin, ENTITYNUM_WORLD, CHAN_AUTO, cgs.media.sfx_rockexp ); + + // new explode (from rl) + VectorMA( origin, 16, dir, sprOrg ); + VectorScale( dir, 100, sprVel ); + CG_ParticleExplosion( "expblue", sprOrg, sprVel, 500, 20, 160 ); + //CG_ParticleExplosion( "blueexp", sprOrg, sprVel, 1200, 9, 300 ); + + // (SA) this is done only if the level designer has it marked in the entity. + // (see "cent->currentState.eventParm & 64" below) + + // RF, throw some debris +// CG_AddDebris( origin, dir, +// 280, // speed +// 1400, // duration +// // 15 + rand()%5 ); // count +// 7 + rand()%2 ); // count + + CG_ImpactMark( cgs.media.burnMarkShader, origin, dir, random() * 360, 1,1,1,1, qfalse, 64, qfalse, 0xffffffff ); + } + + + if ( cent->currentState.eventParm & 8 ) { // rubble + // share the cg_explode code with func_explosives + const char *s; + qhandle_t sh = 0; // shader handle + + vec3_t newdir = {0, 0, 0}; + + if ( cent->currentState.angles2[0] || cent->currentState.angles2[1] || cent->currentState.angles2[2] ) { + VectorCopy( cent->currentState.angles2, newdir ); + } + + s = CG_ConfigString( CS_TARGETEFFECT ); // see if ent has a shader specified + if ( s && strlen( s ) > 0 ) { + sh = trap_R_RegisterShader( va( "textures/%s", s ) ); // FIXME: don't do this here. only for testing + + } + cent->currentState.eFlags &= ~EF_INHERITSHADER; // don't try to inherit shader + cent->currentState.dl_intensity = 0; // no sound + CG_Explode( cent, origin, newdir, sh ); + } + + + if ( cent->currentState.eventParm & 16 ) { // gore + le = CG_AllocLocalEntity(); + re = &le->refEntity; + + le->leType = LE_FRAGMENT; + le->startTime = cg.time; + le->endTime = le->startTime + 5000 + random() * 3000; +//----(SA) fading out + re->fadeStartTime = le->endTime - 4000; + re->fadeEndTime = le->endTime; +//----(SA) end + + VectorCopy( origin, re->origin ); + AxisCopy( axisDefault, re->axis ); + // re->hModel = hModel; + re->hModel = cgs.media.gibIntestine; + le->pos.trType = TR_GRAVITY; + VectorCopy( origin, le->pos.trBase ); + + // VectorCopy( velocity, le->pos.trDelta ); + VectorNormalize( dir ); + VectorMA( dir, 200, dir, le->pos.trDelta ); + + le->pos.trTime = cg.time; + + le->bounceFactor = 0.3; + + le->leBounceSoundType = LEBS_BLOOD; + le->leMarkType = LEMT_BLOOD; + } + + + if ( cent->currentState.eventParm & 64 ) { // debris trails (the black strip that Ryan did) + CG_AddDebris( origin, dir, + 280, // speed + 1400, // duration + // 15 + rand()%5 ); // count + 7 + rand() % 2 ); // count + } +} + + + + + + +/* +CG_Shard + + We should keep this separate since there will be considerable differences + in the physical properties of shard vrs debris. not to mention the fact + there is no way we can quantify what type of effects the designers will + potentially desire. If it is still possible to merge the functionality of + cg_shard into cg_explode at a latter time I would have no problem with that + but for now I want to keep it separate +*/ +void CG_Shard( centity_t *cent, vec3_t origin, vec3_t dir ) { + localEntity_t *le; + refEntity_t *re; + int type; + int howmany; + int i; + int rval; + + qboolean isflyingdebris = qfalse; + + type = cent->currentState.density; + howmany = cent->currentState.frame; + + for ( i = 0; i < howmany; i++ ) + { + le = CG_AllocLocalEntity(); + re = &le->refEntity; + + le->leType = LE_FRAGMENT; + le->startTime = cg.time; + le->endTime = le->startTime + 5000 + random() * 5000; + +//----(SA) fading out + re->fadeStartTime = le->endTime - 1000; + re->fadeEndTime = le->endTime; +//----(SA) end + + if ( type == 999 ) { + le->startTime = cg.time; + le->endTime = le->startTime + 100; + re->fadeStartTime = le->endTime - 100; + re->fadeEndTime = le->endTime; + type = 1; + + isflyingdebris = qtrue; + } + + + le->lifeRate = 1.0 / ( le->endTime - le->startTime ); + le->leFlags |= LEF_TUMBLE; + le->bounceFactor = 0.4; + // le->leBounceSoundType = LEBS_WOOD; + le->leMarkType = 0; + + VectorCopy( origin, re->origin ); + AxisCopy( axisDefault, re->axis ); + + rval = rand() % 2; + + if ( type == 0 ) { // glass + if ( rval ) { + re->hModel = cgs.media.shardGlass1; + } else { + re->hModel = cgs.media.shardGlass2; + } + } else if ( type == 1 ) { // wood + if ( rval ) { + re->hModel = cgs.media.shardWood1; + } else { + re->hModel = cgs.media.shardWood2; + } + } else if ( type == 2 ) { // metal + if ( rval ) { + re->hModel = cgs.media.shardMetal1; + } else { + re->hModel = cgs.media.shardMetal2; + } + } else if ( type == 3 ) { // ceramic + if ( rval ) { + re->hModel = cgs.media.shardCeramic1; + } else { + re->hModel = cgs.media.shardCeramic2; + } + } else if ( type == 4 ) { // rubble + rval = rand() % 3; + + if ( rval == 1 ) { + re->hModel = cgs.media.shardRubble1; + } else if ( rval == 2 ) { + re->hModel = cgs.media.shardRubble2; + } else { + re->hModel = cgs.media.shardRubble3; + } + + } else { + CG_Printf( "CG_Debris has an unknown type\n" ); + } + + // location + if ( isflyingdebris ) { + le->pos.trType = TR_GRAVITY_LOW; + } else { + le->pos.trType = TR_GRAVITY; + } + + VectorCopy( origin, le->pos.trBase ); + VectorNormalize( dir ); + VectorScale( dir, 10 * howmany, le->pos.trDelta ); + le->pos.trTime = cg.time; + le->pos.trDelta[0] += ( ( random() * 100 ) - 50 ); + le->pos.trDelta[1] += ( ( random() * 100 ) - 50 ); + if ( type ) { + le->pos.trDelta[2] = ( random() * 200 ) + 100; // randomize sort of a lot so they don't all land together + } else { // glass + le->pos.trDelta[2] = ( random() * 100 ) + 50; // randomize sort of a lot so they don't all land together + + } + // rotation + le->angles.trType = TR_LINEAR; + le->angles.trTime = cg.time; + le->angles.trBase[0] = rand() & 31; + le->angles.trBase[1] = rand() & 31; + le->angles.trBase[2] = rand() & 31; + le->angles.trDelta[0] = ( 100 + ( rand() & 500 ) ) - 300; + le->angles.trDelta[1] = ( 100 + ( rand() & 500 ) ) - 300; + le->angles.trDelta[2] = ( 100 + ( rand() & 500 ) ) - 300; + + } + +} + + +void CG_ShardJunk( centity_t *cent, vec3_t origin, vec3_t dir ) { + localEntity_t *le; + refEntity_t *re; + int type; + + type = cent->currentState.density; + + le = CG_AllocLocalEntity(); + re = &le->refEntity; + + le->leType = LE_FRAGMENT; + le->startTime = cg.time; + le->endTime = le->startTime + 5000 + random() * 5000; + + re->fadeStartTime = le->endTime - 1000; + re->fadeEndTime = le->endTime; + + le->lifeRate = 1.0 / ( le->endTime - le->startTime ); + le->leFlags |= LEF_TUMBLE; + le->bounceFactor = 0.4; + le->leMarkType = 0; + + VectorCopy( origin, re->origin ); + AxisCopy( axisDefault, re->axis ); + + re->hModel = cgs.media.shardJunk[rand() % MAX_LOCKER_DEBRIS]; + + le->pos.trType = TR_GRAVITY; + + VectorCopy( origin, le->pos.trBase ); + VectorNormalize( dir ); + VectorScale( dir, 10 * 8, le->pos.trDelta ); + le->pos.trTime = cg.time; + le->pos.trDelta[0] += ( ( random() * 100 ) - 50 ); + le->pos.trDelta[1] += ( ( random() * 100 ) - 50 ); + + le->pos.trDelta[2] = ( random() * 100 ) + 50; // randomize sort of a lot so they don't all land together + + // rotation + le->angles.trType = TR_LINEAR; + le->angles.trTime = cg.time; + //le->angles.trBase[0] = rand()&31; + //le->angles.trBase[1] = rand()&31; + le->angles.trBase[2] = rand() & 31; + + //le->angles.trDelta[0] = (100 + (rand()&500)) - 300; + //le->angles.trDelta[1] = (100 + (rand()&500)) - 300; + le->angles.trDelta[2] = ( 100 + ( rand() & 500 ) ) - 300; + +} + +void CG_BatDeath( centity_t *cent ) { + CG_ParticleExplosion( "blood", cent->lerpOrigin, vec3_origin, 400, 20, 30 ); +} + +void CG_SpawnSpirit( centity_t *cent ) { + localEntity_t *le; + refEntity_t *re; + vec3_t enemyPos, v, ang; + + le = CG_AllocLocalEntity(); + re = &le->refEntity; + + re->hModel = cgs.media.ssSpiritSkullModel; + re->backlerp = 0; + re->renderfx = RF_NOSHADOW | RF_MINLIGHT; //----(SA) + //re->customShader = cgs.media.ssSpiritSkullModel; + re->reType = RT_MODEL; + + le->leType = LE_HELGA_SPIRIT; + le->startTime = cg.time; + le->endTime = cg.time + 6000; //cent->currentState.time; + + le->pos.trType = TR_LINEAR; + le->pos.trTime = cg.time; + VectorCopy( cent->currentState.origin, le->pos.trBase ); + VectorClear( le->pos.trDelta ); + + le->effectWidth = 600; + le->radius = 30.0; + le->lastTrailTime = cg.time; + le->headJuncIndex = -1; + le->loopingSound = cgs.media.zombieSpiritLoopSound; + + le->ownerNum = cent->currentState.number; + + re->fadeStartTime = le->endTime - 2000; + re->fadeEndTime = le->endTime; + re->shaderTime = cg.time; + + // get direction to enemy + if ( cg_entities[le->ownerNum].currentState.otherEntityNum2 == cg.snap->ps.clientNum ) { + VectorCopy( cg.snap->ps.origin, enemyPos ); + enemyPos[2] += cg.snap->ps.viewheight; + } else { + VectorCopy( cg_entities[le->ownerNum].currentState.origin2, enemyPos ); + } + + // set angles + VectorSubtract( enemyPos, le->pos.trBase, v ); + VectorNormalize( v ); + vectoangles( v, ang ); + AnglesToAxis( ang, re->axis ); + VectorScale( v, 350, le->pos.trDelta ); + +} + +/* +============== +CG_EntityEvent + +An entity has an event value +also called by CG_CheckPlayerstateEvents +============== +*/ +#define DEBUGNAME( x ) if ( cg_debugEvents.integer ) {CG_Printf( x "\n" );} +void CG_EntityEvent( centity_t *cent, vec3_t position ) { + entityState_t *es; + int event; + vec3_t dir; + const char *s; + int clientNum; + clientInfo_t *ci; + //char tempStr[MAX_QPATH]; + + static int footstepcnt = 0; + static int splashfootstepcnt = 0; + + es = ¢->currentState; + event = es->event & ~EV_EVENT_BITS; + + if ( cg_debugEvents.integer ) { + CG_Printf( "ent:%3i event:%3i ", es->number, event ); + } + + if ( !event ) { + DEBUGNAME( "ZEROEVENT" ); + return; + } + + clientNum = es->clientNum; + if ( clientNum < 0 || clientNum >= MAX_CLIENTS ) { + clientNum = 0; + } + ci = &cgs.clientinfo[ clientNum ]; + + if ( !ci->modelInfo ) { // not ready yet? + return; + } + + switch ( event ) { + // + // movement generated events + // + + // TODO: change all this to sound scripts + + case EV_FOOTSTEP: + DEBUGNAME( "EV_FOOTSTEP" ); + if ( cg_footsteps.integer ) { + if ( cent->currentState.aiChar == AICHAR_ELITEGUARD ) { + trap_S_StartSound( NULL, es->number, CHAN_BODY, cgs.media.footsteps[ FOOTSTEP_ELITE_STEP ][footstepcnt] ); + } else if ( cent->currentState.aiChar == AICHAR_ZOMBIE ) { + trap_S_StartSound( NULL, es->number, CHAN_BODY, cgs.media.footsteps[ FOOTSTEP_ZOMBIE_STEP ][footstepcnt] ); + } else if ( cent->currentState.aiChar == AICHAR_LOPER ) { + trap_S_StartSound( NULL, es->number, CHAN_BODY, cgs.media.footsteps[ FOOTSTEP_LOPER_STEP ][footstepcnt] ); + } else if ( cent->currentState.aiChar == AICHAR_PROTOSOLDIER ) { + trap_S_StartSound( NULL, es->number, CHAN_BODY, cgs.media.footsteps[ FOOTSTEP_PROTOSOLDIER_STEP ][footstepcnt] ); + CG_StartShakeCamera( 0.05, 400, es->pos.trBase, 512 ); + } else if ( cent->currentState.aiChar == AICHAR_SUPERSOLDIER ) { + trap_S_StartSound( NULL, es->number, CHAN_BODY, cgs.media.footsteps[ FOOTSTEP_SUPERSOLDIER_STEP ][footstepcnt] ); + CG_StartShakeCamera( 0.08, 500, es->pos.trBase, 800 ); + } else if ( cent->currentState.aiChar == AICHAR_HEINRICH ) { + trap_S_StartSound( NULL, es->number, CHAN_BODY, cgs.media.footsteps[ FOOTSTEP_HEINRICH ][footstepcnt] ); + CG_StartShakeCamera( 0.08, 500, es->pos.trBase, 800 ); + } else if ( cent->currentState.aiChar == AICHAR_HELGA ) { + CG_SoundPlayIndexedScript( cgs.media.footsteps[FOOTSTEP_BEAST][0], NULL, es->number ); + } else { + trap_S_StartSound( NULL, es->number, CHAN_BODY, cgs.media.footsteps[ ci->modelInfo->footsteps ][footstepcnt] ); + } + } + break; + case EV_FOOTSTEP_METAL: + DEBUGNAME( "EV_FOOTSTEP_METAL" ); + if ( cg_footsteps.integer ) { + if ( cent->currentState.aiChar == AICHAR_ELITEGUARD ) { + trap_S_StartSound( NULL, es->number, CHAN_BODY, cgs.media.footsteps[ FOOTSTEP_ELITE_METAL ][footstepcnt] ); + } else if ( cent->currentState.aiChar == AICHAR_LOPER ) { + trap_S_StartSound( NULL, es->number, CHAN_BODY, cgs.media.footsteps[ FOOTSTEP_LOPER_METAL ][footstepcnt] ); + } else if ( cent->currentState.aiChar == AICHAR_PROTOSOLDIER ) { + trap_S_StartSound( NULL, es->number, CHAN_BODY, cgs.media.footsteps[ FOOTSTEP_PROTOSOLDIER_METAL ][footstepcnt] ); + CG_StartShakeCamera( 0.05, 400, es->pos.trBase, 512 ); + } else if ( cent->currentState.aiChar == AICHAR_SUPERSOLDIER || cent->currentState.aiChar == AICHAR_HEINRICH ) { + trap_S_StartSound( NULL, es->number, CHAN_BODY, cgs.media.footsteps[ FOOTSTEP_SUPERSOLDIER_METAL ][0] ); + CG_StartShakeCamera( 0.08, 500, es->pos.trBase, 800 ); + } else if ( cent->currentState.aiChar == AICHAR_HELGA ) { + CG_SoundPlayIndexedScript( cgs.media.footsteps[FOOTSTEP_BEAST][0], NULL, es->number ); + } else { + trap_S_StartSound( NULL, es->number, CHAN_BODY, cgs.media.footsteps[ FOOTSTEP_METAL ][footstepcnt] ); + } + } + break; + case EV_FOOTSTEP_WOOD: + DEBUGNAME( "EV_FOOTSTEP_WOOD" ); + if ( cg_footsteps.integer ) { + if ( cent->currentState.aiChar == AICHAR_ELITEGUARD ) { + trap_S_StartSound( NULL, es->number, CHAN_BODY, cgs.media.footsteps[ FOOTSTEP_ELITE_WOOD ][footstepcnt] ); + } else if ( cent->currentState.aiChar == AICHAR_ZOMBIE ) { + trap_S_StartSound( NULL, es->number, CHAN_BODY, cgs.media.footsteps[ FOOTSTEP_ZOMBIE_WOOD ][footstepcnt] ); + } else if ( cent->currentState.aiChar == AICHAR_LOPER ) { + trap_S_StartSound( NULL, es->number, CHAN_BODY, cgs.media.footsteps[ FOOTSTEP_LOPER_WOOD ][footstepcnt] ); + } else if ( cent->currentState.aiChar == AICHAR_PROTOSOLDIER ) { + trap_S_StartSound( NULL, es->number, CHAN_BODY, cgs.media.footsteps[ FOOTSTEP_PROTOSOLDIER_WOOD ][footstepcnt] ); + CG_StartShakeCamera( 0.05, 400, es->pos.trBase, 512 ); + } else if ( cent->currentState.aiChar == AICHAR_SUPERSOLDIER || cent->currentState.aiChar == AICHAR_HEINRICH ) { + trap_S_StartSound( NULL, es->number, CHAN_BODY, cgs.media.footsteps[ FOOTSTEP_SUPERSOLDIER_WOOD ][footstepcnt] ); + CG_StartShakeCamera( 0.08, 500, es->pos.trBase, 800 ); + } else if ( cent->currentState.aiChar == AICHAR_HELGA ) { + CG_SoundPlayIndexedScript( cgs.media.footsteps[FOOTSTEP_BEAST][0], NULL, es->number ); + } else { + trap_S_StartSound( NULL, es->number, CHAN_BODY, cgs.media.footsteps[ FOOTSTEP_WOOD ][footstepcnt] ); + } + + } + break; + case EV_FOOTSTEP_GRASS: + DEBUGNAME( "EV_FOOTSTEP_GRASS" ); + if ( cg_footsteps.integer ) { + //if (cent->currentState.aiChar == AICHAR_ELITEGUARD) + // trap_S_StartSound (NULL, es->number, CHAN_BODY, + // cgs.media.footsteps[ FOOTSTEP_ELITE_STEP ][footstepcnt] ); + //else + if ( cent->currentState.aiChar == AICHAR_PROTOSOLDIER ) { + trap_S_StartSound( NULL, es->number, CHAN_BODY, cgs.media.footsteps[ FOOTSTEP_PROTOSOLDIER_GRASS ][footstepcnt] ); + } else if ( cent->currentState.aiChar == AICHAR_SUPERSOLDIER || cent->currentState.aiChar == AICHAR_HEINRICH ) { + trap_S_StartSound( NULL, es->number, CHAN_BODY, cgs.media.footsteps[ FOOTSTEP_SUPERSOLDIER_GRASS ][footstepcnt] ); + } else if ( cent->currentState.aiChar == AICHAR_HELGA ) { + CG_SoundPlayIndexedScript( cgs.media.footsteps[FOOTSTEP_BEAST][0], NULL, es->number ); + } else { + trap_S_StartSound( NULL, es->number, CHAN_BODY, cgs.media.footsteps[ FOOTSTEP_GRASS ][footstepcnt] ); + } + } + break; + case EV_FOOTSTEP_GRAVEL: + DEBUGNAME( "EV_FOOTSTEP_GRAVEL" ); + if ( cg_footsteps.integer ) { + if ( cent->currentState.aiChar == AICHAR_ELITEGUARD ) { + trap_S_StartSound( NULL, es->number, CHAN_BODY, cgs.media.footsteps[ FOOTSTEP_ELITE_GRAVEL ][footstepcnt] ); + } else if ( cent->currentState.aiChar == AICHAR_ZOMBIE ) { + trap_S_StartSound( NULL, es->number, CHAN_BODY, cgs.media.footsteps[ FOOTSTEP_ZOMBIE_GRAVEL ][footstepcnt] ); + } else if ( cent->currentState.aiChar == AICHAR_PROTOSOLDIER ) { + trap_S_StartSound( NULL, es->number, CHAN_BODY, cgs.media.footsteps[ FOOTSTEP_PROTOSOLDIER_GRAVEL][footstepcnt] ); + } else if ( cent->currentState.aiChar == AICHAR_SUPERSOLDIER || cent->currentState.aiChar == AICHAR_HEINRICH ) { + trap_S_StartSound( NULL, es->number, CHAN_BODY, cgs.media.footsteps[ FOOTSTEP_SUPERSOLDIER_GRAVEL][footstepcnt] ); + } else if ( cent->currentState.aiChar == AICHAR_HELGA ) { + CG_SoundPlayIndexedScript( cgs.media.footsteps[FOOTSTEP_BEAST][0], NULL, es->number ); + } else { + trap_S_StartSound( NULL, es->number, CHAN_BODY, cgs.media.footsteps[ FOOTSTEP_GRAVEL ][footstepcnt] ); + } + } + break; + + case EV_FOOTSTEP_ROOF: // tile sound + DEBUGNAME( "EV_FOOTSTEP_ROOF" ); + if ( cg_footsteps.integer ) { + //if (cent->currentState.aiChar == AICHAR_ELITEGUARD) + // trap_S_StartSound (NULL, es->number, CHAN_BODY, + // cgs.media.footsteps[ FOOTSTEP_ELITE_ROOF ][footstepcnt] ); + //else + trap_S_StartSound( NULL, es->number, CHAN_BODY, + cgs.media.footsteps[ FOOTSTEP_ROOF ][footstepcnt] ); + } + break; + case EV_FOOTSTEP_SNOW: + DEBUGNAME( "EV_FOOTSTEP_SNOW" ); + if ( cg_footsteps.integer ) { + //if (cent->currentState.aiChar == AICHAR_ELITEGUARD) + // trap_S_StartSound (NULL, es->number, CHAN_BODY, + // cgs.media.footsteps[ FOOTSTEP_ELITE_STEP ][footstepcnt] ); + //else + trap_S_StartSound( NULL, es->number, CHAN_BODY, + cgs.media.footsteps[ FOOTSTEP_SNOW ][footstepcnt] ); + } + break; + +//----(SA) added + case EV_FOOTSTEP_CARPET: + DEBUGNAME( "EV_FOOTSTEP_CARPET" ); + if ( cg_footsteps.integer ) { + trap_S_StartSound( NULL, es->number, CHAN_BODY, cgs.media.footsteps[ FOOTSTEP_CARPET ][footstepcnt] ); + } + break; + + +//----(SA) end + + case EV_FOOTSPLASH: + DEBUGNAME( "EV_FOOTSPLASH" ); + if ( cg_footsteps.integer ) { + trap_S_StartSound( NULL, es->number, CHAN_BODY, + cgs.media.footsteps[ FOOTSTEP_SPLASH ][splashfootstepcnt] ); + } + break; + case EV_FOOTWADE: + DEBUGNAME( "EV_FOOTWADE" ); + if ( cg_footsteps.integer ) { + trap_S_StartSound( NULL, es->number, CHAN_BODY, + cgs.media.footsteps[ FOOTSTEP_SPLASH ][splashfootstepcnt] ); + } + break; + case EV_SWIM: + DEBUGNAME( "EV_SWIM" ); + if ( cg_footsteps.integer ) { + trap_S_StartSound( NULL, es->number, CHAN_BODY, + cgs.media.footsteps[ FOOTSTEP_SPLASH ][footstepcnt] ); + } + break; + + + case EV_FALL_SHORT: + DEBUGNAME( "EV_FALL_SHORT" ); + trap_S_StartSound( NULL, es->number, CHAN_AUTO, cgs.media.landSound ); + if ( clientNum == cg.predictedPlayerState.clientNum ) { + // smooth landing z changes + cg.landChange = -8; + cg.landTime = cg.time; + } + break; + + case EV_FALL_DMG_10: + DEBUGNAME( "EV_FALL_DMG_10" ); + trap_S_StartSound( NULL, es->number, CHAN_AUTO, CG_CustomSound( es->number, "*fall1.wav" ) ); + // use normal pain sound trap_S_StartSound( NULL, es->number, CHAN_VOICE, CG_CustomSound( es->number, "*pain100_1.wav" ) ); + if ( clientNum == cg.predictedPlayerState.clientNum ) { + // smooth landing z changes + cg.landChange = -16; + cg.landTime = cg.time; + CG_StartShakeCamera( 0.03, 200, cg.predictedPlayerState.origin, 200 ); + } + break; + + case EV_FALL_DMG_15: + DEBUGNAME( "EV_FALL_DMG_15" ); + trap_S_StartSound( NULL, es->number, CHAN_AUTO, CG_CustomSound( es->number, "*fall1.wav" ) ); + // use normal pain sound trap_S_StartSound( NULL, es->number, CHAN_VOICE, CG_CustomSound( es->number, "*pain100_1.wav" ) ); + if ( clientNum == cg.predictedPlayerState.clientNum ) { + // smooth landing z changes + cg.landChange = -16; + cg.landTime = cg.time; + CG_StartShakeCamera( 0.04, 200, cg.predictedPlayerState.origin, 200 ); + } + break; + + case EV_FALL_DMG_25: + DEBUGNAME( "EV_FALL_DMG_25" ); + trap_S_StartSound( NULL, es->number, CHAN_AUTO, CG_CustomSound( es->number, "*fall2.wav" ) ); + cent->pe.painTime = cg.time; // don't play a pain sound right after this + if ( clientNum == cg.predictedPlayerState.clientNum ) { + // smooth landing z changes + cg.landChange = -24; + cg.landTime = cg.time; + CG_StartShakeCamera( 0.05, 200, cg.predictedPlayerState.origin, 200 ); + } + break; + + case EV_FALL_DMG_50: + DEBUGNAME( "EV_FALL_DMG_50" ); + trap_S_StartSound( NULL, es->number, CHAN_AUTO, CG_CustomSound( es->number, "*fall2.wav" ) ); + cent->pe.painTime = cg.time; // don't play a pain sound right after this + if ( clientNum == cg.predictedPlayerState.clientNum ) { + // smooth landing z changes + cg.landChange = -24; + cg.landTime = cg.time; + CG_StartShakeCamera( 0.08, 200, cg.predictedPlayerState.origin, 200 ); + } + break; + + case EV_FALL_NDIE: + DEBUGNAME( "EV_FALL_NDIE" ); + // splat + break; + + case EV_EXERT1: + DEBUGNAME( "EV_EXERT1" ); + trap_S_StartSound( NULL, es->number, CHAN_VOICE, CG_CustomSound( es->number, "*exert1.wav" ) ); + break; + case EV_EXERT2: + DEBUGNAME( "EV_EXERT2" ); + trap_S_StartSound( NULL, es->number, CHAN_VOICE, CG_CustomSound( es->number, "*exert2.wav" ) ); + break; + case EV_EXERT3: + DEBUGNAME( "EV_EXERT3" ); + trap_S_StartSound( NULL, es->number, CHAN_VOICE, CG_CustomSound( es->number, "*exert3.wav" ) ); + break; + + case EV_STEP_4: + case EV_STEP_8: + case EV_STEP_12: + case EV_STEP_16: // smooth out step up transitions + DEBUGNAME( "EV_STEP" ); + { + float oldStep; + int delta; + int step; + + if ( clientNum != cg.predictedPlayerState.clientNum ) { + break; + } + // if we are interpolating, we don't need to smooth steps + if ( cg.demoPlayback || ( cg.snap->ps.pm_flags & PMF_FOLLOW ) || + cg_nopredict.integer || cg_synchronousClients.integer ) { + break; + } + // check for stepping up before a previous step is completed + delta = cg.time - cg.stepTime; + if ( delta < STEP_TIME ) { + oldStep = cg.stepChange * ( STEP_TIME - delta ) / STEP_TIME; + } else { + oldStep = 0; + } + + // add this amount + step = 4 * ( event - EV_STEP_4 + 1 ); + cg.stepChange = oldStep + step; + if ( cg.stepChange > MAX_STEP_CHANGE ) { + cg.stepChange = MAX_STEP_CHANGE; + } + cg.stepTime = cg.time; + break; + } + + case EV_JUMP_PAD: + DEBUGNAME( "EV_JUMP_PAD" ); + // boing sound at origin, jump sound on player + trap_S_StartSound( cent->lerpOrigin, -1, CHAN_VOICE, cgs.media.jumpPadSound ); + trap_S_StartSound( NULL, es->number, CHAN_VOICE, CG_CustomSound( es->number, "*jump1.wav" ) ); + break; + + case EV_JUMP: + DEBUGNAME( "EV_JUMP" ); + trap_S_StartSound( NULL, es->number, CHAN_VOICE, CG_CustomSound( es->number, "*jump1.wav" ) ); + break; + case EV_TAUNT: + DEBUGNAME( "EV_TAUNT" ); + trap_S_StartSound( NULL, es->number, CHAN_VOICE, CG_CustomSound( es->number, "*taunt.wav" ) ); + break; + case EV_WATER_TOUCH: + DEBUGNAME( "EV_WATER_TOUCH" ); + trap_S_StartSound( NULL, es->number, CHAN_AUTO, cgs.media.watrInSound ); + break; + case EV_WATER_LEAVE: + DEBUGNAME( "EV_WATER_LEAVE" ); + trap_S_StartSound( NULL, es->number, CHAN_AUTO, cgs.media.watrOutSound ); + break; + case EV_WATER_UNDER: + DEBUGNAME( "EV_WATER_UNDER" ); + trap_S_StartSound( NULL, es->number, CHAN_AUTO, cgs.media.watrUnSound ); +//----(SA) this fog stuff for underwater is really just a test for feasibility of creating the under-water effect that way. +//----(SA) the related issues of load/savegames, death underwater, etc. are not handled at all. +//----(SA) the actual problem, of course, is doing underwater stuff when the water is very turbulant and you can't simply +//----(SA) do things based on the players head being above/below the water brushes top surface. (since the waves can potentially be /way/ above/below that) + + // DHM - Nerve :: causes problems in multiplayer... + if ( cgs.gametype == GT_SINGLE_PLAYER && clientNum == cg.predictedPlayerState.clientNum ) { +// trap_R_SetFog(FOG_WATER, 0, 400, .1, .1, .1, 111); +// trap_R_SetFog(FOG_CMD_SWITCHFOG, FOG_WATER, 200, 0, 0, 0, 0); + char buff[64]; + trap_Cvar_VariableStringBuffer( "r_waterFogColor", buff, sizeof( buff ) ); + trap_SendClientCommand( va( "fogswitch %s", buff ) ); + } + break; + case EV_WATER_CLEAR: + DEBUGNAME( "EV_WATER_CLEAR" ); + trap_S_StartSound( NULL, es->number, CHAN_AUTO, CG_CustomSound( es->number, "*gasp.wav" ) ); + + // DHM - Nerve :: causes problems in multiplayer... + if ( cgs.gametype == GT_SINGLE_PLAYER && clientNum == cg.predictedPlayerState.clientNum ) { +// trap_R_SetFog(FOG_CMD_SWITCHFOG, FOG_MAP, 400,0,0,0,0); + char buff[64]; + trap_Cvar_VariableStringBuffer( "r_mapFogColor", buff, sizeof( buff ) ); + trap_SendClientCommand( va( "fogswitch %s", buff ) ); + } + break; + + case EV_ITEM_PICKUP: + case EV_ITEM_PICKUP_QUIET: + DEBUGNAME( "EV_ITEM_PICKUP" ); + { + gitem_t *item; + int index; + + index = es->eventParm; // player predicted + + if ( index < 1 || index >= bg_numItems ) { + break; + } + item = &bg_itemlist[ index ]; + + if ( event == EV_ITEM_PICKUP ) { // not quiet + // powerups and team items will have a separate global sound, this one + // will be played at prediction time + if ( item->giType == IT_POWERUP || item->giType == IT_TEAM ) { + trap_S_StartSound( NULL, es->number, CHAN_AUTO, trap_S_RegisterSound( "sound/items/n_health.wav" ) ); + } else { + trap_S_StartSound( NULL, es->number, CHAN_AUTO, trap_S_RegisterSound( item->pickup_sound ) ); + } + } + + // show icon and name on status bar + if ( es->number == cg.snap->ps.clientNum ) { + CG_ItemPickup( index ); + } + +//----(SA) draw the HUD items for a sec since this is a special item + if ( item->giType == IT_KEY ) { + cg.itemFadeTime = cg.time + 1000; + } + + } + break; + + case EV_GLOBAL_ITEM_PICKUP: + DEBUGNAME( "EV_GLOBAL_ITEM_PICKUP" ); + { + gitem_t *item; + int index; + + index = es->eventParm; // player predicted + + if ( index < 1 || index >= bg_numItems ) { + break; + } + item = &bg_itemlist[ index ]; + // powerup pickups are global + trap_S_StartSound( NULL, cg.snap->ps.clientNum, CHAN_AUTO, trap_S_RegisterSound( item->pickup_sound ) ); + + // show icon and name on status bar + if ( es->number == cg.snap->ps.clientNum ) { + CG_ItemPickup( index ); + } + } + break; + + // + // weapon events + // + case EV_VENOM: + DEBUGNAME( "EV_VENOM" ); + CG_VenomFire( es, qfalse ); + break; + case EV_VENOMFULL: + DEBUGNAME( "EV_VENOMFULL" ); + CG_VenomFire( es, qtrue ); + break; + + case EV_NOITEM: + DEBUGNAME( "EV_NOITEM" ); + if ( es->number == cg.snap->ps.clientNum ) { + CG_HoldableUsedupChange(); + } + break; + + case EV_WEAP_OVERHEAT: + DEBUGNAME( "EV_WEAP_OVERHEAT" ); + + // start weapon idle animation + if ( es->number == cg.snap->ps.clientNum ) { + if ( ( cg.predictedPlayerState.weapAnim & ~ANIM_TOGGLEBIT ) == WEAP_ATTACK1 ) { // if attacking, go idle while overheating + cg.predictedPlayerState.weapAnim = ( ( cg.predictedPlayerState.weapAnim & ANIM_TOGGLEBIT ) ^ ANIM_TOGGLEBIT ) | WEAP_IDLE1; + } + cent->overheatTime = cg.time; // used to make the barrels smoke when overheated + } + + if ( cg_weapons[es->weapon].overheatSound ) { + trap_S_StartSound( NULL, es->number, CHAN_AUTO, cg_weapons[es->weapon].overheatSound ); + } + break; + +// JPW NERVE + case EV_SPINUP: + DEBUGNAME( "EV_SPINUP" ); + if ( cg_gameType.integer != GT_SINGLE_PLAYER ) { + trap_S_StartSound( NULL, es->number, CHAN_AUTO, cg_weapons[es->weapon].spinupSound ); + } + break; +// jpw + + case EV_EMPTYCLIP: + DEBUGNAME( "EV_EMPTYCLIP" ); + break; + + case EV_FILL_CLIP: + DEBUGNAME( "EV_FILL_CLIP" ); + if ( cg_weapons[es->weapon].reloadSound ) { + + // hope this does not cause trouble. changed it to chan_weapon so i could kill the sound if the guy dies while reloading + // can re-work if this causes trouble +// trap_S_StartSound (NULL, es->number, CHAN_AUTO, cg_weapons[es->weapon].reloadSound ); + trap_S_StartSound( NULL, es->number, CHAN_WEAPON, cg_weapons[es->weapon].reloadSound ); + } + break; + + + case EV_NOAMMO: + DEBUGNAME( "EV_NOAMMO" ); + if ( ( es->weapon != WP_GRENADE_LAUNCHER ) && ( es->weapon != WP_GRENADE_PINEAPPLE ) && ( es->weapon != WP_DYNAMITE ) ) { + trap_S_StartSound( NULL, es->number, CHAN_AUTO, cgs.media.noAmmoSound ); + } + if ( es->number == cg.snap->ps.clientNum ) { + CG_OutOfAmmoChange(); + } + break; + case EV_CHANGE_WEAPON: + { + + int newweap = 0; + + DEBUGNAME( "EV_CHANGE_WEAPON" ); + + // client will get this message if reloading while using an alternate weapon + // client should voluntarily switch back to primary at that point + switch ( es->weapon ) { + case WP_SNOOPERSCOPE: + newweap = WP_GARAND; + break; + case WP_SNIPERRIFLE: + newweap = WP_MAUSER; + break; + case WP_FG42SCOPE: + newweap = WP_FG42; + break; + default: + break; + } + + // TTimo + // show_bug.cgi?id=417 + if ( ( newweap ) && ( cgs.gametype != GT_WOLF ) ) { + CG_FinishWeaponChange( es->weapon, newweap ); + } + + } + break; + +//----(SA) added + case EV_SUGGESTWEAP: + CG_WeaponSuggest( es->eventParm ); + break; +//----(SA) end + + case EV_FIRE_WEAPON_MG42: + // shake the camera a bit + CG_StartShakeCamera( 0.05, 100, cent->lerpOrigin, 100 ); + trap_S_StartSound( NULL, cent->currentState.number, CHAN_WEAPON, hWeaponSnd ); + DEBUGNAME( "EV_FIRE_WEAPON" ); + CG_FireWeapon( cent ); + break; + case EV_FIRE_WEAPON: + case EV_FIRE_WEAPONB: + DEBUGNAME( "EV_FIRE_WEAPON" ); + CG_FireWeapon( cent ); + if ( event == EV_FIRE_WEAPONB ) { // akimbo firing colt + cent->akimboFire = qtrue; + } else { + cent->akimboFire = qfalse; + } + break; + case EV_FIRE_WEAPON_LASTSHOT: + DEBUGNAME( "EV_FIRE_WEAPON_LASTSHOT" ); + CG_FireWeapon( cent ); + break; + +//----(SA) added + case EV_GRENADE_SUICIDE: + DEBUGNAME( "EV_GRENADE_SUICIDE" ); + CG_MissileHitWall( WP_GRENADE_LAUNCHER, 0, position, dir, 0 ); // (SA) modified to send missilehitwall surface parameters + break; +//----(SA) end + +//----(SA) added + case EV_FIRE_QUICKGREN: + // testing. no client side effect yet + break; +//----(SA) end +//----(SA) added + case EV_NOFIRE_UNDERWATER: + DEBUGNAME( "EV_NOFIRE_UNDERWATER" ); + if ( es->number == cg.snap->ps.clientNum ) { // reset client-side weapon animation + cg.predictedPlayerState.weapAnim = ( ( cg.predictedPlayerState.weapAnim & ANIM_TOGGLEBIT ) ^ ANIM_TOGGLEBIT ) | WEAP_IDLE1; + } + if ( cgs.media.noFireUnderwater ) { + trap_S_StartSound( NULL, es->number, CHAN_WEAPON, cgs.media.noFireUnderwater ); + } + break; +//----(SA) end + case EV_USE_ITEM0: + DEBUGNAME( "EV_USE_ITEM0" ); + CG_UseItem( cent ); + break; + case EV_USE_ITEM1: + DEBUGNAME( "EV_USE_ITEM1" ); + CG_UseItem( cent ); + break; + case EV_USE_ITEM2: + DEBUGNAME( "EV_USE_ITEM2" ); + CG_UseItem( cent ); + break; + case EV_USE_ITEM3: + DEBUGNAME( "EV_USE_ITEM3" ); + CG_UseItem( cent ); + break; + case EV_USE_ITEM4: + DEBUGNAME( "EV_USE_ITEM4" ); + CG_UseItem( cent ); + break; + case EV_USE_ITEM5: + DEBUGNAME( "EV_USE_ITEM5" ); + CG_UseItem( cent ); + break; + case EV_USE_ITEM6: + DEBUGNAME( "EV_USE_ITEM6" ); + CG_UseItem( cent ); + break; + case EV_USE_ITEM7: + DEBUGNAME( "EV_USE_ITEM7" ); + CG_UseItem( cent ); + break; + case EV_USE_ITEM8: + DEBUGNAME( "EV_USE_ITEM8" ); + CG_UseItem( cent ); + break; + case EV_USE_ITEM9: + DEBUGNAME( "EV_USE_ITEM9" ); + CG_UseItem( cent ); + break; + case EV_USE_ITEM10: + DEBUGNAME( "EV_USE_ITEM10" ); + CG_UseItem( cent ); + break; + case EV_USE_ITEM11: + DEBUGNAME( "EV_USE_ITEM11" ); + CG_UseItem( cent ); + break; + case EV_USE_ITEM12: + DEBUGNAME( "EV_USE_ITEM12" ); + CG_UseItem( cent ); + break; + case EV_USE_ITEM13: + DEBUGNAME( "EV_USE_ITEM13" ); + CG_UseItem( cent ); + break; + case EV_USE_ITEM14: + DEBUGNAME( "EV_USE_ITEM14" ); + CG_UseItem( cent ); + break; + + //================================================================= + + // + // other events + // + case EV_PLAYER_TELEPORT_IN: + DEBUGNAME( "EV_PLAYER_TELEPORT_IN" ); + trap_S_StartSound( NULL, es->number, CHAN_AUTO, cgs.media.teleInSound ); + CG_SpawnEffect( position ); + break; + + case EV_PLAYER_TELEPORT_OUT: + DEBUGNAME( "EV_PLAYER_TELEPORT_OUT" ); + trap_S_StartSound( NULL, es->number, CHAN_AUTO, cgs.media.teleOutSound ); + CG_SpawnEffect( position ); + break; + + case EV_ITEM_POP: + DEBUGNAME( "EV_ITEM_POP" ); + trap_S_StartSound( NULL, es->number, CHAN_AUTO, cgs.media.respawnSound ); + break; + case EV_ITEM_RESPAWN: + DEBUGNAME( "EV_ITEM_RESPAWN" ); + cent->miscTime = cg.time; // scale up from this + trap_S_StartSound( NULL, es->number, CHAN_AUTO, cgs.media.respawnSound ); + break; + + case EV_GRENADE_BOUNCE: + DEBUGNAME( "EV_GRENADE_BOUNCE" ); + +// CG_Printf("bounce on: %d\n", es->eventParm); + + // DYNAMITE + if ( es->weapon == WP_DYNAMITE ) { + trap_S_StartSound( NULL, es->number, CHAN_AUTO, cgs.media.dynamitebounce1 ); + } else { + int flags; + // GRENADES + // es->eventParm - surfaceparms +//#define SURF_METAL 0x1000 // clanking footsteps + + flags = es->eventParm; + flags = ( flags << 12 ); + if ( flags & SURF_WOOD ) { // SURF_WOOD + if ( rand() & 1 ) { + trap_S_StartSound( NULL, es->number, CHAN_AUTO, cgs.media.grenadebounce[GRENBOUNCE_WOOD][0] ); + } else { trap_S_StartSound( NULL, es->number, CHAN_AUTO, cgs.media.grenadebounce[GRENBOUNCE_WOOD][1] );} + } else if ( flags & ( SURF_METAL | SURF_ROOF | SURF_GLASS ) ) { // SURF_METAL | SURF_ROOF | SURF_GLASS + if ( rand() & 1 ) { + trap_S_StartSound( NULL, es->number, CHAN_AUTO, cgs.media.grenadebounce[GRENBOUNCE_METAL][0] ); + } else { trap_S_StartSound( NULL, es->number, CHAN_AUTO, cgs.media.grenadebounce[GRENBOUNCE_METAL][1] );} + } else if ( flags & ( SURF_GRASS | SURF_GRAVEL | SURF_SNOW | SURF_CARPET ) ) { //SURF_GRASS | SURF_GRAVEL | SURF_SNOW | SURF_CARPET + if ( rand() & 1 ) { + trap_S_StartSound( NULL, es->number, CHAN_AUTO, cgs.media.grenadebounce[GRENBOUNCE_DIRT][0] ); + } else { trap_S_StartSound( NULL, es->number, CHAN_AUTO, cgs.media.grenadebounce[GRENBOUNCE_DIRT][1] );} + } else { + if ( rand() & 1 ) { + trap_S_StartSound( NULL, es->number, CHAN_AUTO, cgs.media.grenadebounce[GRENBOUNCE_DEFAULT][0] ); + } else { trap_S_StartSound( NULL, es->number, CHAN_AUTO, cgs.media.grenadebounce[GRENBOUNCE_DEFAULT][1] );} + } + } + break; + + case EV_FLAMEBARREL_BOUNCE: + DEBUGNAME( "EV_FLAMEBARREL_BOUNCE" ); + if ( rand() & 1 ) { + trap_S_StartSound( NULL, es->number, CHAN_AUTO, cgs.media.fbarrelexp1 ); + } else { + trap_S_StartSound( NULL, es->number, CHAN_AUTO, cgs.media.fbarrelexp2 ); + } + break; + + case EV_RAILTRAIL: + // ev_railtrail is now sent standalone rather than by a player entity + CG_RailTrail( &cgs.clientinfo[ es->otherEntityNum2 ], es->origin2, es->pos.trBase, es->dmgFlags ); //----(SA) added 'type' field + break; + // + // missile impacts + // + case EV_MISSILE_HIT: + DEBUGNAME( "EV_MISSILE_HIT" ); + ByteToDir( es->eventParm, dir ); + CG_MissileHitPlayer( cent, es->weapon, position, dir, es->otherEntityNum ); + break; + + case EV_MISSILE_MISS_SMALL: + DEBUGNAME( "EV_MISSILE_MISS" ); + ByteToDir( es->eventParm, dir ); + CG_MissileHitWallSmall( es->weapon, 0, position, dir ); + break; + + case EV_MISSILE_MISS: + DEBUGNAME( "EV_MISSILE_MISS" ); + ByteToDir( es->eventParm, dir ); + CG_MissileHitWall( es->weapon, 0, position, dir, 0 ); // (SA) modified to send missilehitwall surface parameters + break; + + case EV_MISSILE_MISS_LARGE: + DEBUGNAME( "EV_MISSILE_MISS_LARGE" ); + ByteToDir( es->eventParm, dir ); + CG_MissileHitWall( VERYBIGEXPLOSION, 0, position, dir, 0 ); // (SA) modified to send missilehitwall surface parameters + break; + + case EV_SPIT_MISS: + case EV_SPIT_HIT: + DEBUGNAME( "EV_SPIT_MISS" ); + ByteToDir( es->eventParm, dir ); + CG_MissileHitWall( es->weapon, 0, position, dir, 0 ); // (SA) modified to send missilehitwall surface parameters + break; + + case EV_BULLET_HIT_WALL: + DEBUGNAME( "EV_BULLET_HIT_WALL" ); + ByteToDir( es->eventParm, dir ); + CG_Bullet( es->pos.trBase, es->otherEntityNum, dir, qfalse, ENTITYNUM_WORLD, qfalse, es->otherEntityNum2 ); + break; + + case EV_BULLET_HIT_FLESH: + DEBUGNAME( "EV_BULLET_HIT_FLESH" ); + CG_Bullet( es->pos.trBase, es->otherEntityNum, dir, qtrue, es->eventParm, qfalse, es->otherEntityNum2 ); + break; + + case EV_WOLFKICK_HIT_WALL: + DEBUGNAME( "EV_WOLFKICK_HIT_WALL" ); + ByteToDir( es->eventParm, dir ); + CG_Bullet( es->pos.trBase, es->otherEntityNum, dir, qfalse, ENTITYNUM_WORLD, qtrue, es->otherEntityNum2 ); + trap_S_StartSound( NULL, es->number, CHAN_AUTO, cgs.media.fkickwall ); + break; + + case EV_WOLFKICK_HIT_FLESH: + DEBUGNAME( "EV_WOLFKICK_HIT_FLESH" ); + CG_Bullet( es->pos.trBase, es->otherEntityNum, dir, qtrue, es->eventParm, qtrue, es->otherEntityNum2 ); + trap_S_StartSound( NULL, es->number, CHAN_AUTO, cgs.media.fkickflesh ); + break; + + case EV_WOLFKICK_MISS: + DEBUGNAME( "EV_WOLFKICK_MISS" ); + trap_S_StartSound( NULL, es->number, CHAN_AUTO, cgs.media.fkickmiss ); + break; + + case EV_POPUPBOOK: + trap_UI_Popup( va( "hbook%d", es->eventParm ) ); + break; + + case EV_POPUP: + s = CG_ConfigString( CS_CLIPBOARDS + es->eventParm ); + // 's' is now the name of the menu script to run + trap_Cvar_Set( "cg_clipboardName", s ); // store new current page name for the ui to pick up + trap_UI_Popup( s ); + break; + + case EV_CLOSEMENU: + Menus_CloseAll(); + break; + + case EV_GIVEPAGE: + { + int havepages = cg_notebookpages.integer; + havepages |= es->eventParm; + trap_Cvar_Set( "cg_notebookpages", va( "%d", havepages ) ); // store new current page name for the ui to pick up + trap_Cvar_Set( "cg_youGotMail", "1" ); //----(SA) added + } + break; + + case EV_GENERAL_SOUND: + DEBUGNAME( "EV_GENERAL_SOUND" ); + // Ridah, check for a sound script + s = CG_ConfigString( CS_SOUNDS + es->eventParm ); + if ( !strstr( s, ".wav" ) ) { + if ( CG_SoundPlaySoundScript( s, NULL, es->number ) ) { + break; + } + // try with .wav + break; // RF, all sounds should have extension + //Q_strncpyz( tempStr, s, sizeof(tempStr) ); + //Q_strcat( tempStr, sizeof(tempStr), ".wav" ); + //s = tempStr; + } + // done. + if ( cgs.gameSounds[ es->eventParm ] ) { + trap_S_StartSound( NULL, es->number, CHAN_VOICE, cgs.gameSounds[ es->eventParm ] ); + } else { + s = CG_ConfigString( CS_SOUNDS + es->eventParm ); + trap_S_StartSound( NULL, es->number, CHAN_VOICE, CG_CustomSound( es->number, s ) ); + } + break; + + case EV_GLOBAL_SOUND: // play from the player's head so it never diminishes + DEBUGNAME( "EV_GLOBAL_SOUND" ); + // Ridah, check for a sound script + s = CG_ConfigString( CS_SOUNDS + es->eventParm ); + if ( !strstr( s, ".wav" ) ) { + if ( CG_SoundPlaySoundScript( s, NULL, es->number ) ) { + break; + } + // try with .wav + break; // RF, all sounds should have extension + //Q_strncpyz( tempStr, s, sizeof(tempStr) ); + //Q_strcat( tempStr, sizeof(tempStr), ".wav" ); + //s = tempStr; + } + // done. + if ( cgs.gameSounds[ es->eventParm ] ) { + trap_S_StartSound( NULL, cg.snap->ps.clientNum, CHAN_AUTO, cgs.gameSounds[ es->eventParm ] ); + } else { + s = CG_ConfigString( CS_SOUNDS + es->eventParm ); + trap_S_StartSound( NULL, cg.snap->ps.clientNum, CHAN_AUTO, CG_CustomSound( es->number, s ) ); + } + break; + + + case EV_PAIN: + // local player sounds are triggered in CG_CheckLocalSounds, + // so ignore events on the player + DEBUGNAME( "EV_PAIN" ); + if ( cent->currentState.number != cg.snap->ps.clientNum ) { + CG_PainEvent( cent, es->eventParm, qfalse ); + } + break; + + case EV_CROUCH_PAIN: + // local player sounds are triggered in CG_CheckLocalSounds, + // so ignore events on the player + DEBUGNAME( "EV_PAIN" ); + if ( cent->currentState.number != cg.snap->ps.clientNum ) { + CG_PainEvent( cent, es->eventParm, qtrue ); + } + break; + + case EV_DEATH1: + case EV_DEATH2: + case EV_DEATH3: + DEBUGNAME( "EV_DEATHx" ); + +// trap_S_StartSoundEx(NULL, cent->currentState.number, CHAN_WEAPON, 0, SND_CUTOFF_ALL); // kill weapon sound (could be reloading) +// trap_S_StopStreamingSound( es->number ); // kill speech + + trap_S_StartSound( NULL, es->number, CHAN_VOICE, + CG_CustomSound( es->number, va( "*death%i.wav", event - EV_DEATH1 + 1 ) ) ); + break; + + case EV_ENTDEATH: + DEBUGNAME( "EV_ENTDEATH" ); + switch ( es->eventParm ) { +// case ET_SPOTLIGHT: +// CG_Explodef(cent->lerpOrigin, normalized_direction, 50, 1, cgs.media.sfx_bullet_glasshit[0], 1, 0, cent->currentState.number, qfalse); +// break; + + case ET_ALARMBOX: + // all this crap shouldn't be in here, but we don't have a generic entry_point into + // explosions that's reasonable. This will be an early thing to get fixed in future work + { + int i, j; + vec3_t sprVel, sprOrg; + + VectorCopy( cent->lerpAngles, dir ); + VectorNormalize( dir ); + + // explosion sprite animation +// VectorScale( dir, 16, sprVel ); + VectorScale( dir, 6, sprVel ); + + for ( i = 0; i < 5; i++ ) { + for ( j = 0; j < 3; j++ ) + sprOrg[j] = cent->lerpOrigin[j] + 2 * dir[j] + 4 * crandom(); + sprVel[2] += rand() % 10; + CG_ParticleExplosion( "blacksmokeanimb", sprOrg, sprVel, 3500 + rand() % 250, 4, 50 + rand() % 20 ); + } + + CG_AddDebris( cent->lerpOrigin, + dir, + 80, // speed + 1000, // duration + 3 + rand() % 2 ); // count + } + break; + } + + break; + + case EV_OBITUARY: + DEBUGNAME( "EV_OBITUARY" ); + CG_Obituary( es ); + break; + + // + // powerup events + // + case EV_POWERUP_QUAD: + DEBUGNAME( "EV_POWERUP_QUAD" ); + if ( es->number == cg.snap->ps.clientNum ) { + cg.powerupActive = PW_QUAD; + cg.powerupTime = cg.time; + } + trap_S_StartSound( NULL, es->number, CHAN_ITEM, cgs.media.quadSound ); + break; + case EV_POWERUP_BATTLESUIT: + DEBUGNAME( "EV_POWERUP_BATTLESUIT" ); + if ( es->number == cg.snap->ps.clientNum ) { + cg.powerupActive = PW_BATTLESUIT; + cg.powerupTime = cg.time; + } + trap_S_StartSound( NULL, es->number, CHAN_ITEM, trap_S_RegisterSound( "sound/items/protect3.wav" ) ); + break; + case EV_POWERUP_REGEN: + DEBUGNAME( "EV_POWERUP_REGEN" ); + if ( es->number == cg.snap->ps.clientNum ) { + cg.powerupActive = PW_REGEN; + cg.powerupTime = cg.time; + } + trap_S_StartSound( NULL, es->number, CHAN_ITEM, trap_S_RegisterSound( "sound/items/regen.wav" ) ); + break; + + case EV_LOSE_HAT: + DEBUGNAME( "EV_LOSE_HAT" ); + ByteToDir( es->eventParm, dir ); + // (SA) okay, some events not getting through, so I'm still testing. Works except for that tho. +// CG_Printf("lose had dir: %2.4f %2.4f %2.4f\n", dir[0], dir[1], dir[2]); + CG_LoseHat( cent, dir ); + break; + + case EV_GIB_HEAD: + DEBUGNAME( "EV_GIB_HEAD" ); + trap_S_StartSound( NULL, es->number, CHAN_BODY, cgs.media.gibSound ); + { + vec3_t vhead, vtorso, vlegs; + CG_GetBleedOrigin( vhead, vtorso, vlegs, cent->currentState.clientNum ); + CG_GibHead( vhead ); + } + break; + + case EV_GIB_PLAYER: + DEBUGNAME( "EV_GIB_PLAYER" ); + if ( es->aiChar == AICHAR_ZOMBIE ) { + trap_S_StartSound( es->pos.trBase, es->number, CHAN_VOICE, cgs.media.zombieDeathSound ); + } else { + trap_S_StartSound( es->pos.trBase, es->number, CHAN_VOICE, cgs.media.gibSound ); + } + ByteToDir( es->eventParm, dir ); + CG_GibPlayer( cent, cent->lerpOrigin, dir ); + break; + +//----(SA) added + case EV_STOPSTREAMINGSOUND: + DEBUGNAME( "EV_STOPLOOPINGSOUND" ); + trap_S_StopStreamingSound( es->number ); + + // hope this does not cause trouble. + // can re-work if this causes trouble + // this is only called on death now, so stop the weapon sound now too + trap_S_StartSoundEx( NULL, es->number, CHAN_WEAPON, 0, SND_CUTOFF_ALL ); // kill weapon sound (could be reloading) + + break; +//----(SA) end + + case EV_STOPLOOPINGSOUND: + DEBUGNAME( "EV_STOPLOOPINGSOUND" ); + trap_S_StopLoopingSound( es->number ); + es->loopSound = 0; + break; + + case EV_DEBUG_LINE: + DEBUGNAME( "EV_DEBUG_LINE" ); + CG_Beam( cent ); + break; + + // Rafael particles + case EV_SMOKE: + DEBUGNAME( "EV_SMOKE" ); + if ( cent->currentState.density == 3 ) { // cannon + CG_ParticleSmoke( cgs.media.smokePuffShaderdirty, cent ); + } else if ( cent->currentState.density == 7 ) { // steam + // steam from panzerfaust casing + CG_ParticleImpactSmokePuffExtended( cgs.media.smokeParticleShader, cent->currentState.origin, tv( 0,0,1 ), 8, 1000, 8, 20, 20, 0.25f ); + } else if ( !( cent->currentState.density ) ) { + CG_ParticleSmoke( cgs.media.smokePuffShader, cent ); + } else { + CG_ParticleSmoke( cgs.media.smokePuffShader, cent ); + } + break; + // done. + + case EV_FLAMETHROWER_EFFECT: + { + int old; + old = cent->currentState.aiChar; + cent->currentState.aiChar = AICHAR_ZOMBIE; + + // shoot this only in bursts + + // (SA) this first one doesn't seem to do anything. ? + +// if ((cg.time+cent->currentState.number*100)%1000 > 200) { +// CG_FireFlameChunks( cent, cent->currentState.origin, cent->lerpAngles, 0.1, qfalse, 1 ); +// CG_FireFlameChunks( cent, cent->currentState.origin, cent->currentState.apos.trBase, 0.1, qfalse, 1 ); +// } +// else +// CG_FireFlameChunks( cent, cent->currentState.origin, cent->lerpAngles, 0.6, 2, 1 ); + CG_FireFlameChunks( cent, cent->currentState.origin, cent->currentState.apos.trBase, 0.6, 2, 1 ); + + cent->currentState.aiChar = old; + } + break; + + case EV_DUST: + CG_ParticleDust( cent, cent->currentState.origin, cent->currentState.angles ); + break; + + case EV_RUMBLE_EFX: + { + float pitch, yaw; + pitch = cent->currentState.angles[0]; + yaw = cent->currentState.angles[1]; + CG_RumbleEfx( pitch, yaw ); + } + break; + + case EV_CONCUSSIVE: + CG_Concussive( cent ); + break; + +// generic particle emitter that uses client-side particle scripts + case EV_EMITTER: + { + localEntity_t *le; + le = CG_AllocLocalEntity(); + le->leType = LE_EMITTER; + le->startTime = cg.time; + le->endTime = le->startTime + cent->currentState.time; // 'time' stores lifetime + le->pos.trType = TR_STATIONARY; + VectorCopy( cent->currentState.origin, le->pos.trBase ); + VectorCopy( cent->currentState.origin2, le->angles.trBase ); + le->ownerNum = 0; + le->radius = cent->currentState.density; // 'density' stores pressure + le->headJuncIndex = cent->currentState.teamNum; // 'type' + } + break; + + case EV_OILPARTICLES: + CG_Particle_OilParticle( cgs.media.oilParticle, cent->currentState.origin, cent->currentState.origin2, cent->currentState.time, cent->currentState.density ); + break; + case EV_OILSLICK: + CG_Particle_OilSlick( cgs.media.oilSlick, cent ); + break; + case EV_OILSLICKREMOVE: + CG_OilSlickRemove( cent ); + break; + + case EV_MG42EFX: + CG_MG42EFX( cent ); + break; + + case EV_FLAKGUN1: + CG_FLAKEFX( cent, 1 ); + break; + case EV_FLAKGUN2: + CG_FLAKEFX( cent, 2 ); + break; + case EV_FLAKGUN3: + CG_FLAKEFX( cent, 3 ); + break; + case EV_FLAKGUN4: + CG_FLAKEFX( cent, 4 ); + break; + + case EV_SPARKS_ELECTRIC: + case EV_SPARKS: + { + int numsparks; + int i; + int duration; + float x,y; + float speed; + vec3_t source, dest; + + if ( !( cent->currentState.density ) ) { + cent->currentState.density = 1; + } + numsparks = rand() % cent->currentState.density; + duration = cent->currentState.frame; + x = cent->currentState.angles2[0]; + y = cent->currentState.angles2[1]; + speed = cent->currentState.angles2[2]; + + if ( !numsparks ) { + numsparks = 1; + } + for ( i = 0; i < numsparks; i++ ) + { + + if ( event == EV_SPARKS_ELECTRIC ) { + VectorCopy( cent->currentState.origin, source ); + + VectorCopy( source, dest ); + dest[0] += ( ( rand() & 31 ) - 16 ); + dest[1] += ( ( rand() & 31 ) - 16 ); + dest[2] += ( ( rand() & 31 ) - 16 ); + + CG_Tracer( source, dest, 1 ); + } else { + CG_ParticleSparks( cent->currentState.origin, cent->currentState.angles, duration, x, y, speed ); + } + + } + + } + break; + + case EV_GUNSPARKS: + { + int numsparks; + int speed; + //int count; + + numsparks = cent->currentState.density; + speed = cent->currentState.angles2[2]; + + CG_AddBulletParticles( cent->currentState.origin, cent->currentState.angles, speed, 800, numsparks, 1.0f ); + + } + break; + + // Rafael bats + case EV_BATS: + { + int i; + for ( i = 0; i < cent->currentState.density; i++ ) + CG_ParticleBats( cgs.media.bats[0], cent ); + } + break; + + case EV_BATS_UPDATEPOSITION: + CG_BatsUpdatePosition( cent ); + break; + + case EV_BATS_DEATH: + CG_BatDeath( cent ); + break; + + // Rafael snow pvs check + case EV_SNOW_ON: + CG_SnowLink( cent, qtrue ); + break; + + case EV_SNOW_OFF: + CG_SnowLink( cent, qfalse ); + break; + + + case EV_SNOWFLURRY: + CG_ParticleSnowFlurry( cgs.media.snowShader, cent ); + break; + + //----(SA) + + // for func_exploding + case EV_EXPLODE: + DEBUGNAME( "EV_EXPLODE" ); + ByteToDir( es->eventParm, dir ); + CG_Explode( cent, position, dir, 0 ); + break; + + // for target_effect + case EV_EFFECT: + DEBUGNAME( "EV_EFFECT" ); +// ByteToDir( es->eventParm, dir ); + CG_Effect( cent, position, dir ); + break; + + //----(SA) done + + case EV_MORTAREFX: // mortar firing + DEBUGNAME( "EV_MORTAREFX" ); + CG_MortarEFX( cent ); + break; + + case EV_SHARD: + ByteToDir( es->eventParm, dir ); + CG_Shard( cent, position, dir ); + break; + + case EV_JUNK: + ByteToDir( es->eventParm, dir ); + { + int i; + int rval; + + rval = rand() % 3 + 3; + + for ( i = 0; i < rval; i++ ) + CG_ShardJunk( cent, position, dir ); + } + break; + + case EV_SNIPER_SOUND: + // trap_S_StartSound( es->pos.trBase, -1, CHAN_AUTO, cgs.media.snipersound ); + // trap_S_StartSound (NULL, es->number, CHAN_AUTO, cgs.media.snipersound ); + trap_S_StartSound( NULL, cent->currentState.number, CHAN_WEAPON, cgs.media.snipersound ); + break; + + case EV_SPAWN_SPIRIT: + CG_SpawnSpirit( cent ); + break; + + default: + DEBUGNAME( "UNKNOWN" ); + CG_Error( "Unknown event: %i", event ); + break; + } + + + { + int rval; + + rval = rand() & 3; + + if ( splashfootstepcnt != rval ) { + splashfootstepcnt = rval; + } else { + splashfootstepcnt++; + } + + if ( splashfootstepcnt > 3 ) { + splashfootstepcnt = 0; + } + + + if ( footstepcnt != rval ) { + footstepcnt = rval; + } else { + footstepcnt++; + } + + if ( footstepcnt > 3 ) { + footstepcnt = 0; + } + } +} + + +/* +============== +CG_CheckEvents + +============== +*/ +void CG_CheckEvents( centity_t *cent ) { + int i, event; + + // calculate the position at exactly the frame time + BG_EvaluateTrajectory( ¢->currentState.pos, cg.snap->serverTime, cent->lerpOrigin ); + CG_SetEntitySoundPosition( cent ); + + // check for event-only entities + if ( cent->currentState.eType > ET_EVENTS ) { + if ( cent->previousEvent ) { + goto skipEvent; + //return; // already fired + } + // if this is a player event set the entity number of the client entity number +//(SA) note: EF_PLAYER_EVENT never set +// if ( cent->currentState.eFlags & EF_PLAYER_EVENT ) { +// cent->currentState.number = cent->currentState.otherEntityNum; +// } + + cent->previousEvent = 1; + + cent->currentState.event = cent->currentState.eType - ET_EVENTS; + } else { + + // DHM - Nerve :: Entities that make it here are Not TempEntities. + // As far as we could tell, for all non-TempEntities, the + // circular 'events' list contains the valid events. So we + // skip processing the single 'event' field and go straight + // to the circular list. + + goto skipEvent; + /* + // check for events riding with another entity + if ( cent->currentState.event == cent->previousEvent ) { + goto skipEvent; + //return; + } + cent->previousEvent = cent->currentState.event; + if ( ( cent->currentState.event & ~EV_EVENT_BITS ) == 0 ) { + goto skipEvent; + //return; + } + */ + // dhm - end + } + + CG_EntityEvent( cent, cent->lerpOrigin ); + +skipEvent: + + // check the sequencial list + // if the eventSequence is zero, then there are no events + if ( !cent->currentState.eventSequence ) { + cent->previousEventSequence = 0; + } + // if we've added more events than can fit into the list, make sure we only add them once + if ( cent->currentState.eventSequence < cent->previousEventSequence ) { + cent->previousEventSequence -= ( 1 << 8 ); // eventSequence is sent as an 8-bit through network stream + } + if ( cent->currentState.eventSequence - cent->previousEventSequence > MAX_EVENTS ) { + cent->previousEventSequence = cent->currentState.eventSequence - MAX_EVENTS; + } + for ( i = cent->previousEventSequence ; i != cent->currentState.eventSequence; i++ ) { + event = cent->currentState.events[ i & ( MAX_EVENTS - 1 ) ]; + + cent->currentState.event = event; + cent->currentState.eventParm = cent->currentState.eventParms[ i & ( MAX_EVENTS - 1 ) ]; + CG_EntityEvent( cent, cent->lerpOrigin ); + } + cent->previousEventSequence = cent->currentState.eventSequence; + + // set the event back so we don't think it's changed next frame (unless it really has) + cent->currentState.event = cent->previousEvent; +} + + +/* +void CG_CheckEvents( centity_t *cent ) { + int i, event; + + // calculate the position at exactly the frame time + BG_EvaluateTrajectory( ¢->currentState.pos, cg.snap->serverTime, cent->lerpOrigin ); + CG_SetEntitySoundPosition( cent ); + + // check for event-only entities + if ( cent->currentState.eType > ET_EVENTS ) { + if ( !cent->previousEvent ) { + cent->previousEvent = 1; + cent->currentState.event = cent->currentState.eType - ET_EVENTS; + CG_EntityEvent( cent, cent->lerpOrigin ); + } + } else { + // check for events riding with another entity + if ( cent->currentState.event != cent->previousEvent ) { + cent->previousEvent = cent->currentState.event; + if ( cent->currentState.event & ~EV_EVENT_BITS ) { + CG_EntityEvent( cent, cent->lerpOrigin ); + } + } + } + + // check the sequencial list + // if we've added more events than can fit into the list, make sure we only add them once + if (cent->currentState.eventSequence < cent->previousEventSequence) { + cent->previousEventSequence -= (1 << 8); // eventSequence is sent as an 8-bit through network stream + } + if (cent->currentState.eventSequence - cent->previousEventSequence > MAX_EVENTS) { + cent->previousEventSequence = cent->currentState.eventSequence - MAX_EVENTS; + } + for ( i = cent->previousEventSequence ; i != cent->currentState.eventSequence; i++ ) { + event = cent->currentState.events[ i & (MAX_EVENTS-1) ]; + + cent->currentState.event = event; + cent->currentState.eventParm = cent->currentState.eventParms[ i & (MAX_EVENTS-1) ]; + CG_EntityEvent( cent, cent->lerpOrigin ); + } + cent->previousEventSequence = cent->currentState.eventSequence; + + // set the event back so we don't think it's changed next frame (unless it really has) + cent->currentState.event = cent->previousEvent; +} +*/ diff --git a/Projects/Android/jni/rtcw/src/cgame/cg_flamethrower.c b/Projects/Android/jni/rtcw/src/cgame/cg_flamethrower.c new file mode 100644 index 0000000..17a39d6 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/cgame/cg_flamethrower.c @@ -0,0 +1,1696 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +// cg_flamethrower.c - special code for the flamethrower effects +// +// the flameChunks behave similarly to the trailJunc's, except they are rendered differently, and +// also interact with the environment +// +// NOTE: some AI's are treated different, mostly for aesthetical reasons. + +#include "cg_local.h" + +// a flameChunk is a ball or section of fuel which goes from fuel->blue ignition->flame ball +// optimization is necessary, since lots of these will be spawned, but as they grow, they can be +// merged so that less overdraw occurs +typedef struct flameChunk_s +{ + struct flameChunk_s *nextGlobal, *prevGlobal; // next junction in the global list it is in (free or used) + struct flameChunk_s *nextFlameChunk; // next junction in the trail + struct flameChunk_s *nextHead, *prevHead; // next head junc in the world + + qboolean inuse; + qboolean dead; // set when a chunk is effectively inactive, but waiting to be freed + int ownerCent; // cent that spawned us + + int timeStart, timeEnd; + float sizeStart, sizeMax; // start small, increase if we slow down + float sizeRand; + float sizeRate; // rate per ms, variable according to speed (larger if moving slower) + int sizeTime; + vec3_t baseOrg; + int baseOrgTime; + vec3_t velDir; + float velSpeed; // flame chunks should start with a fast velocity, then slow down if there is nothing behind them pushing them along + float rollAngle; + qboolean ignitionOnly; + int blueLife; + float gravity; + vec3_t startVelDir; + float speedScale; + + // current variables + vec3_t org; + float size; + float lifeFrac; // 0.0 (baby) -> 1.0 (aged) + + int lastFriction, lastFrictionTake; + vec3_t parentFwd; +} flameChunk_t; + +#define MAX_FLAME_CHUNKS 2048 +static flameChunk_t flameChunks[MAX_FLAME_CHUNKS]; +static flameChunk_t *freeFlameChunks, *activeFlameChunks, *headFlameChunks; + +static qboolean initFlameChunks = qfalse; + +static int numFlameChunksInuse; + +// this structure stores information relevant to each cent in the game, this way we keep +// the flamethrower data seperate to the rest of the code, which helps if we decide against +// using this weapon in the game +typedef struct centFlameInfo_s +{ + int lastClientFrame; // client frame that we last fired the flamethrower + vec3_t lastAngles; // angles at last firing + vec3_t lastOrigin; // origin at last firing + flameChunk_t + *lastFlameChunk; // flame chunk we last spawned + int lastSoundUpdate; + + qboolean lastFiring; + + qboolean silent; //----(SA) added + + int lastDmgUpdate; // time we last told server about this ent's flame damage + int lastDmgCheck; // only check once per 100ms + int lastDmgEnemy; // entity that inflicted the damage +} centFlameInfo_t; + +static centFlameInfo_t centFlameInfo[MAX_GENTITIES]; + +typedef struct +{ +// float fireVolume; // not needed, since we add individual loop sources for the flame, so it gets spacialized + float blowVolume; + float streamVolume; +} flameSoundStatus_t; + +static flameSoundStatus_t centFlameStatus[MAX_GENTITIES]; + +// procedure defs +flameChunk_t *CG_SpawnFlameChunk( flameChunk_t *headFlameChunk ); +void CG_FlameCalcOrg( flameChunk_t *f, int time, vec3_t outOrg ); +void CG_FlameGetMuzzlePoint( vec3_t org, vec3_t fwd, vec3_t right, vec3_t up, vec3_t outPos ); + +// these must be globals, since they cannot expand or contract, since that might result in them getting +// stuck in geometry. therefore when a chunk hits a surface, we should deflect it away from the surface +// slightly, rather than running along it, so that as the chink grows, the sprites don't sink into the +// wall too much. +static vec3_t flameChunkMins = {-4, -4, -4}; +static vec3_t flameChunkMaxs = { 4, 4, 4}; + +// these define how the flame looks +#define FLAME_START_SIZE 1.0 +#define FLAME_START_MAX_SIZE 140.0 // when the flame is spawned, it should endevour to reach this size +#define FLAME_START_MAX_SIZE_RAND 60.0 +#define FLAME_MAX_SIZE 200.0 // flame sprites cannot be larger than this +#define FLAME_MIN_MAXSIZE 40.0 // don't ever let the sizeMax go less than this +#define FLAME_START_SPEED 950.0 // speed of flame as it leaves the nozzle +#define FLAME_MIN_SPEED 60.0 //200.0 +#define FLAME_CHUNK_DIST 4.0 // space in between chunks when fired + +#define FLAME_BLUE_LENGTH 230.0 +#define FLAME_BLUE_MAX_ALPHA 1.0 + +#define FLAME_FUEL_LENGTH 48.0 +#define FLAME_FUEL_MAX_ALPHA 0.35 +#define FLAME_FUEL_MIN_WIDTH 1.0 + +// these are calculated (don't change) +#define FLAME_LENGTH ( FLAMETHROWER_RANGE + 50.0 ) // NOTE: only modify the range, since this should always reflect that range + +#define FLAME_LIFETIME (int)( ( FLAME_LENGTH / FLAME_START_SPEED ) * 1000 ) // life duration in milliseconds +#define FLAME_FRICTION_PER_SEC ( 1.0 * FLAME_START_SPEED ) +#define FLAME_BLUE_LIFE (int)( ( FLAME_BLUE_LENGTH / FLAME_START_SPEED ) * 1000 ) +#define FLAME_FUEL_LIFE (int)( ( FLAME_FUEL_LENGTH / FLAME_START_SPEED ) * 1000 ) +#define FLAME_FUEL_FADEIN_TIME ( 0.2 * FLAME_FUEL_LIFE ) + +#define FLAME_BLUE_FADEIN_TIME( x ) ( 0.2 * x ) +#define FLAME_BLUE_FADEOUT_TIME( x ) ( 0.05 * x ) +#define GET_FLAME_BLUE_SIZE_SPEED( x ) ( ( (float)x / FLAME_LIFETIME ) / 1.0 ) // x is the current sizeMax +#define GET_FLAME_SIZE_SPEED( x ) ( ( (float)x / FLAME_LIFETIME ) / 0.6 ) // x is the current sizeMax + +//#define FLAME_MIN_DRAWSIZE 20 + +// enable this for the fuel stream +//#define FLAME_ENABLE_FUEL_STREAM + +// enable this for dynamic lighting around flames +//#define FLAMETHROW_LIGHTS + +// disable this to stop rotating flames (this is variable so we can change it at run-time) +int rotatingFlames = qtrue; + +/* +=============== +CG_FlameLerpVec +=============== +*/ +void CG_FlameLerpVec( const vec3_t oldV, const vec3_t newV, float backLerp, vec3_t outV ) { + VectorScale( newV, ( 1.0 - backLerp ), outV ); + VectorMA( outV, backLerp, oldV, outV ); +} + +/* +=============== +CG_FlameAdjustSpeed +=============== +*/ +void CG_FlameAdjustSpeed( flameChunk_t *f, float change ) { + if ( !f->velSpeed && !change ) { + return; + } + + f->velSpeed += change; + if ( f->velSpeed < FLAME_MIN_SPEED ) { + f->velSpeed = FLAME_MIN_SPEED; + } +/* + f->sizeMax = FLAME_START_MAX_SIZE + ((1.0 - (f->velSpeed / FLAME_START_SPEED)) * (FLAME_MAX_SIZE - FLAME_START_MAX_SIZE)); + + if (!f->ignitionOnly) { + if ((cg.time - f->timeStart) < f->blueLife) { + f->sizeRate = GET_FLAME_BLUE_SIZE_SPEED(f->sizeMax); + } else { + f->sizeMax += f->sizeRand; + if (f->sizeMax < FLAME_MIN_MAXSIZE) + f->sizeMax = FLAME_MIN_MAXSIZE; + f->sizeRate = GET_FLAME_SIZE_SPEED(f->sizeMax); + } + } +*/ +} + +/* +=============== +CG_FireFlameChunks + + The given entity is firing a flamethrower + + flags: + 1 - use 'angles' + 2 - silent +=============== +*/ +void CG_FireFlameChunks( centity_t *cent, vec3_t origin, vec3_t angles, float speedScale, qboolean firing, int flags ) { + centFlameInfo_t *centInfo; + flameChunk_t *f, *of; + vec3_t lastFwd, thisFwd, fwd; + vec3_t lastUp, thisUp, up; + vec3_t lastRight, thisRight, right; + vec3_t thisOrg, lastOrg, org; + double timeInc, backLerp, fracInc; + int t; + double ft; + trace_t trace; + vec3_t parentFwd; + int flameLife; +#define MAX_CHUNKS_PER_CALL 30 + + + centInfo = ¢FlameInfo[cent->currentState.number]; + +//----(SA) added + if ( flags & 2 ) { // silent + centInfo->silent = qtrue; + } +//----(SA) end + + // only do one ignition flame for zombie + if ( cent->currentState.aiChar == AICHAR_ZOMBIE && !firing ) { + if ( !centInfo->lastFiring ) { + return; + } + } + + // if this point is in water, no flames + if ( CG_PointContents( origin, cent->currentState.number ) & ( CONTENTS_WATER | CONTENTS_SLIME | CONTENTS_LAVA ) ) { + return; + } + + // for any other character or in 3rd person view, use entity angles for friction + if ( cent->currentState.number != cg.snap->ps.clientNum || cg_thirdPerson.integer ) { + if ( flags & 1 ) { // use 'angles' + AngleVectors( angles, parentFwd, NULL, NULL ); + } else { + AngleVectors( cent->currentState.angles, parentFwd, NULL, NULL ); + } + } else { + AngleVectors( angles, parentFwd, NULL, NULL ); + } + + // tweak the speed of the flame + //if (cent->currentState.aiChar) + // speedScale *= 0.8; + //else + // speedScale *= 1.0; + + AngleVectors( angles, thisFwd, thisRight, thisUp ); + VectorCopy( origin, thisOrg ); + + // if this entity was firing last frame, interpolate the angles as we spawn the chunks that + // fired over the last frame + if ( ( centInfo->lastClientFrame == cent->currentState.frame ) && + ( centInfo->lastFlameChunk && centInfo->lastFiring == firing ) ) { + AngleVectors( centInfo->lastAngles, lastFwd, lastRight, lastUp ); + VectorCopy( centInfo->lastOrigin, lastOrg ); + centInfo->lastFiring = firing; + + flameLife = FLAME_LIFETIME * ( 1.0 / ( 0.5 + 0.5 * speedScale ) ); + of = centInfo->lastFlameChunk; + timeInc = 1000.0 * ( firing ? 1.0 : 0.5 ) * ( FLAME_CHUNK_DIST /**(1.0+crandom()*0.1)*/ / ( FLAME_START_SPEED * speedScale ) ); + ft = ( (double)of->timeStart ); + // never spawn too many chunk in one call (framerate preservation) + if ( ( ( (double)cg.time - ft ) / timeInc ) > MAX_CHUNKS_PER_CALL ) { + timeInc = ( (double)cg.time - ft ) / MAX_CHUNKS_PER_CALL; + } + ft += timeInc; + t = (int)ft; + fracInc = timeInc / (double)( cg.time - of->timeStart ); + backLerp = 1.0 - fracInc; + while ( t <= cg.time ) { + // spawn a new chunk + CG_FlameLerpVec( lastOrg, thisOrg, backLerp, org ); + + CG_Trace( &trace, org, flameChunkMins, flameChunkMaxs, org, cent->currentState.number, MASK_SHOT ); + if ( trace.startsolid && trace.entityNum >= cgs.maxclients ) { + centInfo->lastFlameChunk = NULL; + return; // don't spawn inside a wall + } + + f = CG_SpawnFlameChunk( of ); + + if ( !f ) { + CG_Printf( "Out of flame chunks\n" ); + return; + } + + CG_FlameLerpVec( lastFwd, thisFwd, backLerp, fwd ); + VectorNormalize( fwd ); + CG_FlameLerpVec( lastRight, thisRight, backLerp, right ); + VectorNormalize( right ); + CG_FlameLerpVec( lastUp, thisUp, backLerp, up ); + VectorNormalize( up ); + + f->timeStart = t; + f->timeEnd = t + flameLife; // * (firing ? 1.0 : 0.2); + f->sizeStart = f->size = FLAME_START_SIZE * speedScale; // * (firing ? 1.0 : 0.2); + f->sizeMax = ( 0.3 + 0.7 * speedScale ) * ( FLAME_START_MAX_SIZE + f->sizeRand * ( firing ? 1.0 : 0.0 ) ); + //if (cent->currentState.aiChar == AICHAR_ZOMBIE) { + // f->sizeRand = crandom() * FLAME_START_MAX_SIZE_RAND; + // f->sizeMax = 20; + //} else { + f->sizeRand = 0; + //} + if ( f->sizeMax > FLAME_MAX_SIZE ) { + f->sizeMax = FLAME_MAX_SIZE; + } + f->sizeRate = GET_FLAME_BLUE_SIZE_SPEED( f->sizeMax * speedScale * ( 1.0 + ( 0.5 * (float)!firing ) ) ); + f->sizeTime = t; + VectorCopy( org, f->baseOrg ); + f->baseOrgTime = t; + VectorCopy( fwd, f->velDir ); + VectorCopy( fwd, f->startVelDir ); + f->speedScale = speedScale; + // randomize the direction slightly + /* + if (!firing) { + f->velDir[0] += 0.03*sin((float)cg.time/134); + f->velDir[1] += 0.03*sin((float)cg.time/567); + f->velDir[2] += 0.03*cos((float)cg.time/3435); + } + */ + VectorNormalize( f->velDir ); + f->velSpeed = FLAME_START_SPEED * ( 0.3 + 0.7 * speedScale ); + f->ownerCent = cent->currentState.number; + f->rollAngle = crandom() * 179; + f->ignitionOnly = !firing; + if ( !firing ) { + f->gravity = -150; + f->blueLife = FLAME_BLUE_LIFE * 0.5; +// f->blueLife = (int)(0.3*(1.0/speedScale)*(float)FLAME_BLUE_LIFE); + } else { + f->gravity = 0; + f->blueLife = FLAME_BLUE_LIFE; + } + f->lastFriction = cg.time; + f->lastFrictionTake = cg.time; + VectorCopy( parentFwd, f->parentFwd ); + + ft += timeInc; + // always spawn a chunk right on the current time + if ( (int)ft > cg.time && t < cg.time ) { + ft = (double)cg.time; + t = cg.time; + backLerp = 0; + } else { + t = (int)floor( ft ); + backLerp -= fracInc; + } + centInfo->lastFlameChunk = of = f; + } + } else { + + centInfo->lastFiring = firing; + t = cg.time; + + VectorCopy( thisOrg, org ); + + // if igniting, play start sound + //if (firing) { + // trap_S_StartSound( org, cent->currentState.number, CHAN_AUTO, cgs.media.flameStartSound ); + //} + + CG_Trace( &trace, org, flameChunkMins, flameChunkMaxs, org, cent->currentState.number, MASK_SHOT ); + if ( trace.startsolid && trace.entityNum >= cgs.maxclients ) { + centInfo->lastFlameChunk = NULL; + return; // don't spawn inside a wall + } + + // just fire a single chunk to get us started + f = CG_SpawnFlameChunk( NULL ); + + if ( !f ) { + CG_Printf( "Out of flame chunks\n" ); + return; + } + + VectorCopy( thisFwd, fwd ); + VectorCopy( thisUp, up ); + VectorCopy( thisRight, right ); + + f->timeStart = cg.time; + f->timeEnd = cg.time + FLAME_LIFETIME * ( 1.0 / ( 0.5 + 0.5 * speedScale ) ); // * (firing ? 1.0 : 0.2); + //f->timeEnd = cg.time + FLAME_LIFETIME * (1.0/speedScale); + f->sizeStart = f->size = FLAME_START_SIZE * speedScale; + f->sizeMax = FLAME_START_MAX_SIZE * ( 0.3 + 0.7 * speedScale ); + if ( f->sizeMax > FLAME_MAX_SIZE ) { + f->sizeMax = FLAME_MAX_SIZE; + } + //if (cent->currentState.aiChar == AICHAR_ZOMBIE) { + // f->sizeRand = crandom() * FLAME_START_MAX_SIZE_RAND; + // f->sizeMax = 20; + //} else { + f->sizeRand = 0; + //} + f->sizeRate = GET_FLAME_BLUE_SIZE_SPEED( f->sizeMax * speedScale ); + f->sizeTime = cg.time; + VectorCopy( org, f->baseOrg ); + f->baseOrgTime = cg.time; + VectorCopy( fwd, f->velDir ); + VectorCopy( fwd, f->startVelDir ); + f->velSpeed = FLAME_START_SPEED * ( 0.3 + 0.7 * speedScale ); + f->ownerCent = cent->currentState.number; + f->rollAngle = crandom() * 179; + f->ignitionOnly = !firing; + f->speedScale = speedScale; + if ( !firing ) { + f->gravity = -100; + f->blueLife = (int)( 0.3 * ( 1.0 / speedScale ) * (float)FLAME_BLUE_LIFE ); + } else { + f->gravity = 0; + f->blueLife = FLAME_BLUE_LIFE; + } + f->lastFriction = cg.time; + f->lastFrictionTake = cg.time; + VectorCopy( parentFwd, f->parentFwd ); + + centInfo->lastFlameChunk = f; + } + + /*if (centInfo->lastFlameChunk && !cent->currentState.aiChar)*/ { + // push them along + float frametime, dot; + + f = centInfo->lastFlameChunk; + while ( f ) { + + if ( f->lastFriction < cg.time - 50 ) { + frametime = (float)( cg.time - f->lastFriction ) / 1000.0; + f->lastFriction = cg.time; + dot = DotProduct( parentFwd, f->parentFwd ); + if ( dot >= 0.99 ) { + dot -= 0.99; + dot *= ( 1.0 / ( 1.0 - 0.99 ) ); + CG_FlameAdjustSpeed( f, /*(0.3+0.7*f->speedScale) **/ 0.5 * frametime * FLAME_FRICTION_PER_SEC * pow( dot,4 ) ); + } + } + + f = f->nextFlameChunk; + } + } + + VectorCopy( angles, centInfo->lastAngles ); + VectorCopy( origin, centInfo->lastOrigin ); + centInfo->lastClientFrame = cent->currentState.frame; +} + +/* +=============== +CG_ClearFlameChunks +=============== +*/ +void CG_ClearFlameChunks( void ) { + int i; + + memset( flameChunks, 0, sizeof( flameChunks ) ); + memset( centFlameInfo, 0, sizeof( centFlameInfo ) ); + + freeFlameChunks = flameChunks; + activeFlameChunks = NULL; + headFlameChunks = NULL; + + for ( i = 0 ; i < MAX_FLAME_CHUNKS ; i++ ) + { + flameChunks[i].nextGlobal = &flameChunks[i + 1]; + + if ( i > 0 ) { + flameChunks[i].prevGlobal = &flameChunks[i - 1]; + } else { + flameChunks[i].prevGlobal = NULL; + } + + flameChunks[i].inuse = qfalse; + } + flameChunks[MAX_FLAME_CHUNKS - 1].nextGlobal = NULL; + + initFlameChunks = qtrue; + numFlameChunksInuse = 0; +} + +/* +=============== +CG_SpawnFlameChunk +=============== +*/ +flameChunk_t *CG_SpawnFlameChunk( flameChunk_t *headFlameChunk ) { + flameChunk_t *f; + + if ( !freeFlameChunks ) { + //CG_ClearFlameChunks(); + return NULL; + } + + if ( headFlameChunks && headFlameChunks->dead ) { + headFlameChunks = NULL; + } + + // select the first free trail, and remove it from the list + f = freeFlameChunks; + freeFlameChunks = f->nextGlobal; + if ( freeFlameChunks ) { + freeFlameChunks->prevGlobal = NULL; + } + + f->nextGlobal = activeFlameChunks; + if ( activeFlameChunks ) { + activeFlameChunks->prevGlobal = f; + } + activeFlameChunks = f; + f->prevGlobal = NULL; + f->inuse = qtrue; + f->dead = qfalse; + + // if this owner has a headJunc, add us to the start + if ( headFlameChunk ) { + // remove the headJunc from the list of heads + if ( headFlameChunk == headFlameChunks ) { + headFlameChunks = headFlameChunks->nextHead; + if ( headFlameChunks ) { + headFlameChunks->prevHead = NULL; + } + } else { + if ( headFlameChunk->nextHead ) { + headFlameChunk->nextHead->prevHead = headFlameChunk->prevHead; + } + if ( headFlameChunk->prevHead ) { + headFlameChunk->prevHead->nextHead = headFlameChunk->nextHead; + } + } + headFlameChunk->prevHead = NULL; + headFlameChunk->nextHead = NULL; + } + // make us the headTrail + if ( headFlameChunks ) { + headFlameChunks->prevHead = f; + } + f->nextHead = headFlameChunks; + f->prevHead = NULL; + headFlameChunks = f; + + f->nextFlameChunk = headFlameChunk; // if headJunc is NULL, then we'll just be the end of the list + + numFlameChunksInuse++; + + // debugging + if ( cg_drawRewards.integer > 1 && numFlameChunksInuse > cg_drawRewards.integer ) { + CG_Printf( "NumFlameChunks: %i\n", numFlameChunksInuse ); + } + + return f; +} + +/* +=========== +CG_FreeFlameChunk +=========== +*/ +void CG_FreeFlameChunk( flameChunk_t *f ) { +// if (!f->inuse) +// return; + + // kill any juncs after us, so they aren't left hanging + if ( f->nextFlameChunk ) { + CG_FreeFlameChunk( f->nextFlameChunk ); + f->nextFlameChunk = NULL; + } + + // make it non-active + f->inuse = qfalse; + f->dead = qfalse; + if ( f->nextGlobal ) { + f->nextGlobal->prevGlobal = f->prevGlobal; + } + if ( f->prevGlobal ) { + f->prevGlobal->nextGlobal = f->nextGlobal; + } + if ( f == activeFlameChunks ) { + activeFlameChunks = f->nextGlobal; + } + + // if it's a head, remove it + if ( f == headFlameChunks ) { + headFlameChunks = f->nextHead; + } + if ( f->nextHead ) { + f->nextHead->prevHead = f->prevHead; + } + if ( f->prevHead ) { + f->prevHead->nextHead = f->nextHead; + } + f->nextHead = NULL; + f->prevHead = NULL; + + // stick it in the free list + f->prevGlobal = NULL; + f->nextGlobal = freeFlameChunks; + if ( freeFlameChunks ) { + freeFlameChunks->prevGlobal = f; + } + freeFlameChunks = f; + + numFlameChunksInuse--; +} + +/* +=============== +CG_MergeFlameChunks + + Assumes f1 comes before f2 +=============== +*/ +void CG_MergeFlameChunks( flameChunk_t *f1, flameChunk_t *f2 ) { + if ( f1->nextFlameChunk != f2 ) { + CG_Error( "CG_MergeFlameChunks: f2 doesn't follow f1, cannot merge\n" ); + } + + f1->nextFlameChunk = f2->nextFlameChunk; + f2->nextFlameChunk = NULL; + + //VectorAdd( f1->velDir, f2->velDir, f1->velDir ); + //VectorScale( f1->velDir, 0.5, f1->velDir ); + VectorCopy( f2->velDir, f1->velDir ); + + //VectorAdd( f1->baseOrg, f2->baseOrg, f1->baseOrg ); + //VectorScale( f1->baseOrg, 0.5, f1->baseOrg ); + VectorCopy( f2->baseOrg, f1->baseOrg ); + f1->baseOrgTime = f2->baseOrgTime; + + f1->velSpeed = f2->velSpeed; //(f1->velSpeed + f2->velSpeed) / 2.0; + f1->sizeMax = f2->sizeMax; //(f1->sizeMax + f2->sizeMax) / 2.0; + f1->size = f2->size; //(f1->size + f2->size) / 2.0; + f1->timeStart = f2->timeStart; + f1->timeEnd = f2->timeEnd; + + CG_FreeFlameChunk( f2 ); +} + +/* +=============== +CG_FlameCalcOrg +=============== +*/ +void CG_FlameCalcOrg( flameChunk_t *f, int time, vec3_t outOrg ) { + VectorMA( f->baseOrg, f->velSpeed * ( (float)( time - f->baseOrgTime ) / 1000 ), f->velDir, outOrg ); + outOrg[2] -= f->gravity * ( (float)( time - f->timeStart ) / 1000.0 ) * ( (float)( time - f->timeStart ) / 1000.0 ); +} + +void CG_AdjustFlameSize( flameChunk_t *f, int t ) { + // adjust size + if ( f->size < f->sizeMax ) { + //f->sizeMax = FLAME_START_MAX_SIZE + ((1.0 - (f->velSpeed / FLAME_START_SPEED)) * (FLAME_MAX_SIZE - FLAME_START_MAX_SIZE)); + if ( ( t - f->timeStart ) < f->blueLife ) { + f->sizeRate = GET_FLAME_BLUE_SIZE_SPEED( FLAME_START_MAX_SIZE ); // use a constant so the blue flame doesn't distort + } else { + f->sizeRate = GET_FLAME_SIZE_SPEED( f->sizeMax ); + } + + f->size += f->sizeRate * (float)( t - f->sizeTime ); + if ( f->size > f->sizeMax ) { + f->size = f->sizeMax; + } + } + f->sizeTime = t; +} + +/* +=============== +CG_MoveFlameChunk +=============== +*/ +void CG_MoveFlameChunk( flameChunk_t *f, int t ) { + vec3_t newOrigin, sOrg; + trace_t trace; + int jiggleCount; + float dot; + //static vec3_t umins = {-1,-1,-1}; // TTimo: unused + //static vec3_t umaxs = { 1, 1, 1}; // TTimo: unused + + // subtract friction from speed + if ( f->velSpeed > 1 && f->lastFrictionTake < t - 50 ) { + CG_FlameAdjustSpeed( f, /*(0.3+0.7*f->speedScale) **/ -( (float)( t - f->lastFrictionTake ) / 1000.0 ) * FLAME_FRICTION_PER_SEC ); + f->lastFrictionTake = t; + } +/* + // adjust size + if (f->size < f->sizeMax) { + //f->sizeMax = FLAME_START_MAX_SIZE + ((1.0 - (f->velSpeed / FLAME_START_SPEED)) * (FLAME_MAX_SIZE - FLAME_START_MAX_SIZE)); + if ((t - f->timeStart) < f->blueLife) + f->sizeRate = GET_FLAME_BLUE_SIZE_SPEED(FLAME_START_MAX_SIZE); // use a constant so the blue flame doesn't distort + else + f->sizeRate = GET_FLAME_SIZE_SPEED(f->sizeMax); + + f->size += f->sizeRate * (float)(t - f->baseOrgTime); + if (f->size > f->sizeMax) { + f->size = f->sizeMax; + } + } +*/ + + jiggleCount = 0; + VectorCopy( f->baseOrg, sOrg ); + while ( f->velSpeed > 1 && ( ( t - f->baseOrgTime ) > 20 ) ) { + CG_FlameCalcOrg( f, t, newOrigin ); + + //if (cg_entities[f->ownerCent].currentState.aiChar != AICHAR_ZOMBIE) { + // trace a line from previous position to new position + CG_Trace( &trace, sOrg, flameChunkMins, flameChunkMaxs, newOrigin, f->ownerCent, MASK_SHOT ); + //} else { + // trace.startsolid = 0; + // trace.surfaceFlags = 0; + // trace.fraction = 1.0; + // VectorCopy( newOrigin, trace.endpos ); + //} + + if ( trace.startsolid ) { + // if it's young, let it go through solids briefly + if ( f->lifeFrac < 0.4 ) { + trace.fraction = 1.0; + } else { + f->velSpeed = 0; + break; + } + } + + if ( trace.surfaceFlags & SURF_NOIMPACT ) { + break; + } + + // moved some distance + VectorCopy( trace.endpos, f->baseOrg ); + f->baseOrgTime += (int)( (float)( t - f->baseOrgTime ) * trace.fraction ); + + if ( trace.fraction == 1.0 ) { + // check for hitting client + if ( ( f->ownerCent != cg.snap->ps.clientNum ) && !( cg.snap->ps.eFlags & EF_DEAD ) && VectorDistance( newOrigin, cg.snap->ps.origin ) < 32 ) { + VectorNegate( f->velDir, trace.plane.normal ); + } else { + break; + } + } + + // reflect off surface + dot = DotProduct( f->velDir, trace.plane.normal ); + VectorMA( f->velDir, -1.3 * dot, trace.plane.normal, f->velDir ); + VectorNormalize( f->velDir ); + // subtract some speed + f->velSpeed *= 0.5 * ( 0.25 + 0.75 * ( ( dot + 1.0 ) * 0.5 ) ); + if ( f->velSpeed > 20 ) { + f->velSpeed = 20; + } + // adjust size + //f->sizeMax = FLAME_START_MAX_SIZE + ((/*1.0 -*/ (f->velSpeed / FLAME_START_SPEED)) * (FLAME_MAX_SIZE - FLAME_START_MAX_SIZE)); + //f->sizeRate = GET_FLAME_SIZE_SPEED(f->sizeMax); + VectorCopy( f->velDir, f->parentFwd ); + + VectorCopy( f->baseOrg, sOrg ); + } + + CG_FlameCalcOrg( f, t, f->org ); + //f->baseOrgTime = t; // incase we skipped the movement +} + +/* +=============== +CG_AddFlameSpriteToScene +=============== +*/ +static vec3_t vright, vup; +static vec3_t rright, rup; + +#ifdef _DEBUG // just in case we forget about it, but it should be disabled at all times (only enabled to generate updated shaders) +#ifdef ALLOW_GEN_SHADERS // secondary security measure + +//#define GEN_FLAME_SHADER + +#endif // ALLOW_GEN_SHADERS +#endif // _DEBUG + +#define FLAME_BLEND_SRC "GL_ONE" +#define FLAME_BLEND_DST "GL_ONE_MINUS_SRC_COLOR" + +#define NUM_FLAME_SPRITES 45 +#define FLAME_SPRITE_DIR "twiltb2" + +#define NUM_NOZZLE_SPRITES 8 + +static qhandle_t flameShaders[NUM_FLAME_SPRITES]; +static qhandle_t nozzleShaders[NUM_NOZZLE_SPRITES]; +static qboolean initFlameShaders = qtrue; + +#define MAX_CLIPPED_FLAMES 2 // dont draw more than this many per frame +static int numClippedFlames; + +void CG_FlameDamage( int owner, vec3_t org, float radius ) { + centity_t *cent; + int i; + trace_t tr; + static vec3_t lastPos; + static int lastTime; + + if ( cg.time == lastTime ) { + if ( VectorDistance( org, lastPos ) < radius ) { + return; + } + } + lastTime = cg.time; + VectorCopy( org, lastPos ); + + // check for damage this flame is inflicting on something + if ( radius < 24 ) { + radius = 24; + } + + // check the local playing client + if ( ( centFlameInfo[cg.snap->ps.clientNum].lastDmgCheck < cg.time - 100 ) && + ( Distance( org, cg.snap->ps.origin ) < radius * ( cg.snap->ps.clientNum == owner ? 0.1 : 1.0 ) ) ) { + // trace to make sure it's not going through geometry + CG_Trace( &tr, org, NULL, NULL, cg.snap->ps.origin, -1, MASK_SHOT ); + // + if ( tr.fraction == 1.0 || tr.entityNum == cg.snap->ps.clientNum ) { + centFlameInfo[cg.snap->ps.clientNum].lastDmgCheck = cg.time; + centFlameInfo[cg.snap->ps.clientNum].lastDmgEnemy = owner; + } + } + + if ( cgs.localServer && cgs.gametype == GT_SINGLE_PLAYER ) { + + // flaming zombie's only hurt the player + //if (cg_entities[owner].currentState.aiChar == AICHAR_ZOMBIE) + // return; + + // check for AI's getting hurt (TODO: bot support?) + for ( cent = cg_entities, i = 0; i < cgs.maxclients; cent++, i++ ) { + if ( cent->currentState.aiChar && + cent->currentState.aiChar != AICHAR_VENOM && // Venom has no flame damage + centFlameInfo[i].lastDmgCheck < ( cg.time - 100 ) && + cent->currentValid && // is in the visible frame + ( Distance( org, cent->lerpOrigin ) < radius ) ) { + // trace to make sure it's not going through geometry + CG_Trace( &tr, org, NULL, NULL, cent->lerpOrigin, -1, MASK_SHOT ); + // + if ( tr.fraction == 1.0 || tr.entityNum == cent->currentState.number ) { + centFlameInfo[i].lastDmgCheck = cg.time; + centFlameInfo[i].lastDmgEnemy = owner; + } + } + } + } +} + +void CG_AddFlameSpriteToScene( flameChunk_t *f, float lifeFrac, float alpha ) { + vec3_t point, p2, projVec, sProj; + polyVert_t verts[4]; + float radius, sdist, x; + int frameNum; + vec3_t vec, rotate_ang; + unsigned char alphaChar; + vec2_t fovRadius; + vec2_t rdist, rST; + int rollAngleClamped; + static vec3_t lastPos; + + CG_FlameDamage( f->ownerCent, f->org, f->size ); + + if ( alpha < 0 ) { + return; // we dont want to see this + + } + radius = ( f->size / 2.0 ); + if ( radius < 6 ) { + radius = 6; + } + rST[0] = radius * 1.0; + rST[1] = radius * 1.0 / 1.481; + alphaChar = ( unsigned char )( 255.0 * alpha ); + + verts[0].modulate[0] = alphaChar; + verts[0].modulate[1] = alphaChar; + verts[0].modulate[2] = alphaChar; + verts[0].modulate[3] = alphaChar; + verts[1] = verts[0]; + verts[2] = verts[0]; + verts[3] = verts[0]; + + // find the projected distance from the eye to the projection of the flame origin + // onto the view direction vector + VectorMA( cg.refdef.vieworg, 1024, cg.refdef.viewaxis[0], p2 ); + ProjectPointOntoVector( f->org, cg.refdef.vieworg, p2, sProj ); + + // make sure its infront of us + VectorSubtract( sProj, cg.refdef.vieworg, vec ); + sdist = VectorNormalize( vec ); + if ( !sdist || DotProduct( vec, cg.refdef.viewaxis[0] ) < 0 ) { + return; + } + + // if we are "inside" this sprite, clip it to our view frustum + if ( sdist < f->size * 0.6 ) { + // clip the sprite to the viewport, avoiding rendering off-screen pixels which + // is the main cause of slow-downs + + // if it's close to the previous sprite, ignore + //if (VectorDistance(lastPos, f->org) < 6) + // return; + + if ( ( sdist < f->size * 0.6 ) && ( numClippedFlames++ > MAX_CLIPPED_FLAMES ) ) { + return; + } + + // OPTIMIZATION: clamp to 90 degree rotations + rollAngleClamped = 0; + if ( rotatingFlames ) { + vectoangles( cg.refdef.viewaxis[0], rotate_ang ); + rotate_ang[ROLL] += ( rollAngleClamped = ( (int)( f->rollAngle ) / 90 ) * 90 ); + AngleVectors( rotate_ang, NULL, rright, rup ); + } else { + VectorCopy( vright, rright ); + VectorCopy( vup, rup ); + } + + VectorSubtract( sProj, f->org, projVec ); + + // find the distances from the sprite origin to the projection along the refdef axis + rdist[0] = -1.0 * DotProduct( rright, projVec ); + rdist[1] = -1.0 * DotProduct( rup, projVec ); + + if ( fabs( rdist[0] ) > radius || fabs( rdist[1] ) > radius ) { + return; // completely off-screen + + } + // now set the bounds for clipping + fovRadius[0] = tan( DEG2RAD( ( rollAngleClamped % 2 == 0 ? cg.refdef.fov_x : cg.refdef.fov_x ) * 0.52 ) ) * sdist; + fovRadius[1] = tan( DEG2RAD( ( rollAngleClamped % 2 == 0 ? cg.refdef.fov_x : cg.refdef.fov_x ) * 0.52 ) ) * sdist; + + // BOTTOM LEFT + x = ( -radius + rdist[0] ); + if ( x < -fovRadius[0] ) { // clip + VectorMA( f->org, -radius + ( -fovRadius[0] - x ), rright, point ); + verts[0].st[0] = 0.0 + ( -fovRadius[0] - x ) / ( radius * 2 ); + } else { + VectorMA( f->org, -radius, rright, point ); + verts[0].st[0] = 0.0; + } + x = ( -radius + rdist[1] ); + if ( x < -fovRadius[1] ) { + VectorMA( point, -radius + ( -fovRadius[1] - x ), rup, point ); + verts[0].st[1] = 0.0 + ( -fovRadius[1] - x ) / ( radius * 2 ); + } else { + VectorMA( point, -radius, rup, point ); + verts[0].st[1] = 0.0; + } + VectorCopy( point, verts[0].xyz ); + + // TOP LEFT + x = ( -radius + rdist[0] ); + if ( x < -fovRadius[0] ) { // clip + VectorMA( f->org, -radius + ( -fovRadius[0] - x ), rright, point ); + verts[1].st[0] = 0.0 + ( -fovRadius[0] - x ) / ( radius * 2 ); + } else { + VectorMA( f->org, -radius, rright, point ); + verts[1].st[0] = 0.0; + } + x = ( radius + rdist[1] ); + if ( x > fovRadius[1] ) { + VectorMA( point, radius + ( fovRadius[1] - x ), rup, point ); + verts[1].st[1] = 1.0 + ( fovRadius[1] - x ) / ( radius * 2 ); + } else { + VectorMA( point, radius, rup, point ); + verts[1].st[1] = 1.0; + } + VectorCopy( point, verts[1].xyz ); + + // TOP RIGHT + x = ( radius + rdist[0] ); + if ( x > fovRadius[0] ) { + VectorMA( f->org, radius + ( fovRadius[0] - x ), rright, point ); + verts[2].st[0] = 1.0 + ( fovRadius[0] - x ) / ( radius * 2 ); + } else { + VectorMA( f->org, radius, rright, point ); + verts[2].st[0] = 1.0; + } + x = ( radius + rdist[1] ); + if ( x > fovRadius[1] ) { + VectorMA( point, radius + ( fovRadius[1] - x ), rup, point ); + verts[2].st[1] = 1.0 + ( fovRadius[1] - x ) / ( radius * 2 ); + } else { + VectorMA( point, radius, rup, point ); + verts[2].st[1] = 1.0; + } + VectorCopy( point, verts[2].xyz ); + + // BOTTOM RIGHT + x = ( radius + rdist[0] ); + if ( x > fovRadius[0] ) { + VectorMA( f->org, radius + ( fovRadius[0] - x ), rright, point ); + verts[3].st[0] = 1.0 + ( fovRadius[0] - x ) / ( radius * 2 ); + } else { + VectorMA( f->org, radius, rright, point ); + verts[3].st[0] = 1.0; + } + x = ( -radius + rdist[1] ); + if ( x < -fovRadius[1] ) { + VectorMA( point, -radius + ( -fovRadius[1] - x ), rup, point ); + verts[3].st[1] = 0.0 + ( -fovRadius[1] - x ) / ( radius * 2 ); + } else { + VectorMA( point, -radius, rup, point ); + verts[3].st[1] = 0.0; + } + VectorCopy( point, verts[3].xyz ); + + } else { // set default values for no clipping + + if ( rotatingFlames ) { + vectoangles( cg.refdef.viewaxis[0], rotate_ang ); + rotate_ang[ROLL] += f->rollAngle; + AngleVectors( rotate_ang, NULL, rright, rup ); + } else { + VectorCopy( vright, rright ); + VectorCopy( vup, rup ); + } + + VectorMA( f->org, -rST[1], rup, point ); + VectorMA( point, -rST[0], rright, point ); + VectorCopy( point, verts[0].xyz ); + verts[0].st[0] = 0; + verts[0].st[1] = 0; + + VectorMA( point, rST[1] * 2, rup, point ); + VectorCopy( point, verts[1].xyz ); + verts[1].st[0] = 0; + verts[1].st[1] = 1; + + VectorMA( point, rST[0] * 2, rright, point ); + VectorCopy( point, verts[2].xyz ); + verts[2].st[0] = 1; + verts[2].st[1] = 1; + + VectorMA( point, -rST[1] * 2, rup, point ); + VectorCopy( point, verts[3].xyz ); + verts[3].st[0] = 1; + verts[3].st[1] = 0; + } + + frameNum = (int)floor( lifeFrac * NUM_FLAME_SPRITES ); + if ( frameNum < 0 ) { + frameNum = 0; + } else if ( frameNum > NUM_FLAME_SPRITES - 1 ) { + frameNum = NUM_FLAME_SPRITES - 1; + } + + trap_R_AddPolyToScene( flameShaders[frameNum], 4, verts ); + VectorCopy( f->org, lastPos ); +} + +/* +=============== +CG_AddFlameToScene +=============== +*/ +void CG_AddFlameToScene( flameChunk_t *fHead ) { + flameChunk_t *f, *fNext; + int blueTrailHead = 0, fuelTrailHead = 0; + static vec3_t whiteColor = {1,1,1}; + vec3_t c; + float alpha; + float lived; + int headTimeStart; + //qboolean firstFuel = qtrue; // TTimo + float vdist, bdot; +#define FLAME_SOUND_RANGE 1024.0 + + //flameChunk_t *lastSoundFlameChunk=NULL; // TTimo: unused + flameChunk_t *lastBlowChunk = NULL; + qboolean isClientFlame, firing; + int shader; + + flameChunk_t *lastBlueChunk = NULL; + qboolean skip = qfalse, droppedTrail; + vec3_t v, lastDrawPos; + +#ifdef FLAMETHROW_LIGHTS + vec3_t lastLightPos; + flameChunk_t *lastLightFlameChunk; + float lightSize, lastLightSize, lightAlpha; +#endif + + vec3_t lightOrg; // origin to place light at + float lightSize; + float lightFlameCount; + + float lastFuelAlpha; + + + //if (fHead->ownerCent == cg.snap->ps.clientNum) + isClientFlame = ( fHead == centFlameInfo[fHead->ownerCent].lastFlameChunk ); + //else + // isClientFlame = qfalse; // always optimize enemy flames + + if ( ( cg_entities[fHead->ownerCent].currentState.eFlags & EF_FIRING ) /*(centFlameInfo[fHead->ownerCent].lastClientFrame == cg_entities[fHead->ownerCent].lastWeaponClientFrame)*/ && ( centFlameInfo[fHead->ownerCent].lastFlameChunk == fHead ) ) { + headTimeStart = fHead->timeStart; + firing = qtrue; + } else { + //isClientFlame = qfalse; + headTimeStart = cg.time; + firing = qfalse; + } + + // Zombie ignition is just to make on/off transitions look better + //if (cg_entities[fHead->ownerCent].currentState.aiChar == AICHAR_ZOMBIE && !centFlameInfo[fHead->ownerCent].lastFiring) { + // return; + //} + + VectorClear( lightOrg ); + lightSize = 0; + lightFlameCount = 0; + + lastFuelAlpha = 1.0; + VectorClear( lastDrawPos ); + + f = fHead; + while ( f ) { + + if ( f->nextFlameChunk && f->nextFlameChunk->dead ) { + // kill it + CG_FreeFlameChunk( f->nextFlameChunk ); + f->nextFlameChunk = NULL; + } + + // draw this chunk + + fNext = f->nextFlameChunk; + lived = (float)( headTimeStart - f->timeStart ); + + // update the "blow" sound volume (louder as we sway it) + vdist = Distance( cg.refdef.vieworg, f->org ); // NOTE: this needs to be here or the flameSound code further below won't work + if ( lastBlowChunk && ( centFlameStatus[f->ownerCent].blowVolume < 1.0 ) && + ( ( bdot = DotProduct( lastBlowChunk->startVelDir, f->startVelDir ) ) < 1.0 ) ) { + if ( vdist < FLAME_SOUND_RANGE ) { + centFlameStatus[f->ownerCent].blowVolume += 500.0 * ( 1.0 - bdot ) * ( 1.0 - ( vdist / FLAME_SOUND_RANGE ) ); + if ( centFlameStatus[f->ownerCent].blowVolume > 1.0 ) { + centFlameStatus[f->ownerCent].blowVolume = 1.0; + } + } + } + lastBlowChunk = f; + + VectorMA( lightOrg, f->size / 20.0, f->org, lightOrg ); + lightSize += f->size; + lightFlameCount += f->size / 20.0; + + droppedTrail = qfalse; + + // is it a stream chunk? (no special handling) + if ( !f->ignitionOnly && f->velSpeed < 1 ) { + + CG_AddFlameSpriteToScene( f, f->lifeFrac, 1.0 ); +/* + } else if (cg_entities[f->ownerCent].currentState.aiChar == AICHAR_ZOMBIE) { + + if (isClientFlame && !fHead->ignitionOnly) { + + if (f->lifeFrac < 0.3) { + skip = qfalse; + + // if this is backwards from the last chunk, then skip it + if (!f->ignitionOnly && fNext && f != fHead && lastBlueChunk) { + VectorSubtract( f->org, lastBlueChunk->org, v ); + if (VectorNormalize( v ) < f->size/4 ) + skip = qtrue; + else if (DotProduct( v, f->velDir ) < 0.7) + skip = qtrue; + } + + if (!skip) { + lastBlueChunk = f; + alpha = 1.0; // new nozzle sprite + VectorScale( whiteColor, alpha, c ); + shader = cgs.media.funnelFireShader[(cg.time/10)%NUM_FUNNEL_SPRITES]; + blueTrailHead = CG_AddTrailJunc( blueTrailHead, + shader, + cg.time, + STYPE_STRETCH, + f->org, + 1, + alpha, alpha, + f->size*4.0*f->speedScale, + FLAME_MAX_SIZE, + TJFL_NOCULL|TJFL_FIXDISTORT, + c, c, 1.0, 5.0 ); + } + } + + } else { + lightSize = 0; + } +*/ + // is it in the blue ignition section of the flame? + } else if ( isClientFlame && f->blueLife > ( lived / 2.0 ) ) { + + skip = qfalse; + + // if this is backwards from the last chunk, then skip it + if ( /*!f->ignitionOnly &&*/ fNext && f != fHead && lastBlueChunk ) { + VectorSubtract( f->org, lastBlueChunk->org, v ); + if ( VectorNormalize( v ) < f->size / 2 ) { + skip = qtrue; + } else if ( DotProduct( v, f->velDir ) < 0 ) { + skip = qtrue; + } + } + + // stream sound + if ( !f->ignitionOnly && ( cg_entities[f->ownerCent].currentState.number >= MAX_CLIENTS || cg_entities[f->ownerCent].currentState.weapon == WP_FLAMETHROWER ) ) { + centFlameStatus[f->ownerCent].streamVolume += 0.05; + if ( centFlameStatus[f->ownerCent].streamVolume > 1.0 ) { + centFlameStatus[f->ownerCent].streamVolume = 1.0; + } + } + + + if ( !skip ) { + + // just call this for damage checking + if ( !f->ignitionOnly ) { + CG_AddFlameSpriteToScene( f, f->lifeFrac, -1 ); + } + + lastBlueChunk = f; + + alpha = 1.0; // new nozzle sprite + VectorScale( whiteColor, alpha, c ); + + if ( f->blueLife > lived * ( f->ignitionOnly ? 3.0 : 3.0 ) ) { + + //if (cg_entities[f->ownerCent].currentState.aiChar == AICHAR_ZOMBIE) + // shader = cgs.media.funnelFireShader[(cg.time/50 + (cg.time/50 >> 1))%NUM_FUNNEL_SPRITES]; + //else + shader = nozzleShaders[( cg.time / 50 + ( cg.time / 50 >> 1 ) ) % NUM_NOZZLE_SPRITES]; + + blueTrailHead = CG_AddTrailJunc( blueTrailHead, + shader, + cg.time, + STYPE_STRETCH, + f->org, + 1, + alpha, alpha, + f->size * ( f->ignitionOnly /*&& (cg.snap->ps.clientNum != f->ownerCent || cg_thirdPerson.integer)*/ ? 2.0 : 1.0 ), + FLAME_MAX_SIZE, + TJFL_NOCULL | TJFL_FIXDISTORT, + c, c, 1.0, 5.0 ); + } + + // fire stream +//if (qfalse) + if ( !f->ignitionOnly ) { // && isClientFlame) { + float bscale; + qboolean fskip = qfalse; + + bscale = 1.0; + + if ( !f->nextFlameChunk ) { + alpha = 0; + } else if ( lived / 1.3 < bscale * FLAME_BLUE_FADEIN_TIME( f->blueLife ) ) { + alpha = FLAME_BLUE_MAX_ALPHA * ( ( lived / 1.3 ) / ( bscale * FLAME_BLUE_FADEIN_TIME( f->blueLife ) ) ); + } else if ( lived / 1.3 < ( f->blueLife - FLAME_BLUE_FADEOUT_TIME( f->blueLife ) ) ) { + alpha = FLAME_BLUE_MAX_ALPHA; + } else { + alpha = FLAME_BLUE_MAX_ALPHA * ( 1.0 - ( ( lived / 1.3 - ( f->blueLife - FLAME_BLUE_FADEOUT_TIME( f->blueLife ) ) ) / ( FLAME_BLUE_FADEOUT_TIME( f->blueLife ) ) ) ); + } + if ( alpha <= 0.0 ) { + alpha = 0.0; + if ( lastFuelAlpha <= 0.0 ) { + fskip = qtrue; + } + } + + if ( !fskip ) { + lastFuelAlpha = alpha; + + VectorScale( whiteColor, alpha, c ); + + droppedTrail = qtrue; + + fuelTrailHead = CG_AddTrailJunc( fuelTrailHead, + cgs.media.flamethrowerFireStream, + cg.time, + ( f->ignitionOnly ? STYPE_STRETCH : STYPE_REPEAT ), + f->org, + 1, + alpha, alpha, + ( f->size / 2 < f->sizeMax / 4 ? f->size / 2 : f->sizeMax / 4 ), + FLAME_MAX_SIZE, + TJFL_NOCULL | TJFL_FIXDISTORT | TJFL_CROSSOVER, + c, c, 0.5, 1.5 ); + } + } + + } + + } + +#define FLAME_SPRITE_START_BLUE_SCALE 0.2 + + if ( !f->ignitionOnly && + //!(cg_entities[f->ownerCent].currentState.aiChar == AICHAR_ZOMBIE) && + ( (float)( FLAME_SPRITE_START_BLUE_SCALE * f->blueLife ) < (float)lived ) ) { + + float alpha, lifeFrac; + qboolean skip = qfalse; + vec3_t v1, v2; + float fDist, vDist; + + // should we merge it with the next sprite? + while ( fNext && !droppedTrail ) { + if ( ( Distance( f->org, fNext->org ) < ( ( 0.2 + 0.8 * f->lifeFrac ) * f->size * ( isClientFlame ? 0.2 : 0.1 ) ) ) + && ( fabs( f->size - fNext->size ) < ( 40.0 ) ) + && ( fabs( f->timeStart - fNext->timeStart ) < 50 ) + && ( DotProduct( f->velDir, fNext->velDir ) > 0.999 ) + ) { + if ( !droppedTrail ) { + CG_MergeFlameChunks( f, fNext ); + fNext = f->nextFlameChunk; // it may have changed + } else { + skip = qtrue; + break; + } + } else { + break; + } + } + + lifeFrac = ( lived - FLAME_SPRITE_START_BLUE_SCALE * f->blueLife ) / ( FLAME_LIFETIME - FLAME_SPRITE_START_BLUE_SCALE * f->blueLife ); + + alpha = ( 1.0 - lifeFrac ) * 1.4; + if ( alpha > 1.0 ) { + alpha = 1.0; + } + + // should we draw this sprite? + if ( !skip && VectorLengthSquared( lastDrawPos ) ) { + VectorSubtract( cg.refdef.vieworg, lastDrawPos, v1 ); + VectorSubtract( f->org, lastDrawPos, v2 ); + fDist = VectorNormalize( v2 ); + vDist = VectorNormalize( v1 ); + if ( ( vDist / f->size ) * fDist * ( 0.1 + 0.9 * ( 1.0 - fabs( DotProduct( v1, v2 ) ) ) ) < ( 2.0 * ( f->size / 30.0 < 1.0 ? f->size / 30.0 : 1.0 ) ) ) { + skip = qtrue; + } + } + + if ( !skip ) { + // draw the sprite + CG_AddFlameSpriteToScene( f, lifeFrac, alpha ); + VectorCopy( f->org, lastDrawPos ); + } + // update the sizeRate + f->sizeRate = GET_FLAME_SIZE_SPEED( f->sizeMax ); + +#ifdef FLAMETHROW_LIGHTS + // drop a light? + if ( /*f->size > FLAME_START_MAX_SIZE/1.5 &&*/ ( !lastLightFlameChunk || Distance( lastLightPos, f->org ) > lastLightSize * 0.4 ) ) { + lightSize = f->size * 10; + if ( lightSize > 250 ) { + lightSize = 250; + } + lightAlpha = 1.0; //lightSize / 600; + if ( lightSize < 200 ) { + lightSize = 200; + } + trap_R_AddLightToScene( f->org, lightSize, 1.0 * lightAlpha, 0.7 * lightAlpha, 0.3 * lightAlpha, 0 ); + VectorCopy( f->org, lastLightPos ); + lastLightFlameChunk = f; + lastLightSize = lightSize; + } +#endif + + } + + f = fNext; + } + + if ( lightSize < 80 ) { + lightSize = 80; + } + + if ( lightSize > 500 ) { + lightSize = 500; + } + lightSize *= 1.0 + 0.2 * ( sin( 1.0 * cg.time / 50.0 ) * cos( 1.0 * cg.time / 43.0 ) ); + // set the alpha + alpha = lightSize / 500.0; + if ( alpha > 1.0 ) { + alpha = 1.0; + } + VectorScale( lightOrg, 1.0 / lightFlameCount, lightOrg ); + // if it's only a nozzle, make it blue + if ( fHead->ignitionOnly ) { + if ( lightSize > 80 ) { + lightSize = 80; + } + trap_R_AddLightToScene( lightOrg, 90 + lightSize, 0, 0, alpha * 0.5, 0 ); + } else if ( isClientFlame || ( fHead->ownerCent == cg.snap->ps.clientNum ) ) { + //trap_R_AddLightToScene( lightOrg, 90 + lightSize, 1.000000*alpha, 0.603922*alpha, 0.207843*alpha, 2/*isClientFlame * (fHead->ownerCent == cg.snap->ps.clientNum)*/ ); + } +} + +/* +============= +CG_GenerateShaders + + A util to create a bunch of shaders in a unique shader file, which represent an animation +============= +*/ +void CG_GenerateShaders( char *filename, char *shaderName, char *dir, int numFrames, char *srcBlend, char *dstBlend, char *extras, qboolean compressedVersionAvailable, qboolean nomipmap ) { + fileHandle_t f; + int b, c, d, lastNumber; + char str[512]; + int i; + + trap_FS_FOpenFile( filename, &f, FS_WRITE ); + for ( i = 0; i < numFrames; i++ ) { + lastNumber = i; + b = lastNumber / 100; + lastNumber -= b * 100; + c = lastNumber / 10; + lastNumber -= c * 10; + d = lastNumber; + + if ( compressedVersionAvailable ) { + Com_sprintf( str, sizeof( str ), "%s%i\n{\n\tnofog%s\n\tallowCompress\n\tcull none\n\t{\n\t\tmapcomp sprites/%s_lg/spr%i%i%i.tga\n\t\tmapnocomp sprites/%s/spr%i%i%i.tga\n\t\tblendFunc %s %s\n%s\t}\n}\n", shaderName, i + 1, nomipmap ? "\n\tnomipmaps" : "", dir, b, c, d, dir, b, c, d, srcBlend, dstBlend, extras ); + } else { + Com_sprintf( str, sizeof( str ), "%s%i\n{\n\tnofog%s\n\tallowCompress\n\tcull none\n\t{\n\t\tmap sprites/%s/spr%i%i%i.tga\n\t\tblendFunc %s %s\n%s\t}\n}\n", shaderName, i + 1, nomipmap ? "\n\tnomipmap" : "", dir, b, c, d, srcBlend, dstBlend, extras ); + } + trap_FS_Write( str, strlen( str ), f ); + } + trap_FS_FCloseFile( f ); +} + +/* +=============== +CG_InitFlameChunks +=============== +*/ +void CG_InitFlameChunks( void ) { + int i; + char filename[MAX_QPATH]; + + CG_ClearFlameChunks(); + +#ifdef GEN_FLAME_SHADER + CG_GenerateShaders( "scripts/flamethrower.shader", + "flamethrowerFire", + FLAME_SPRITE_DIR, + NUM_FLAME_SPRITES, + FLAME_BLEND_SRC, + FLAME_BLEND_DST, + "", + qtrue, qtrue ); + + CG_GenerateShaders( "scripts/blacksmokeanim.shader", + "blacksmokeanim", + "explode1", + 23, + "GL_ZERO", + "GL_ONE_MINUS_SRC_ALPHA", + "\t\talphaGen const 0.2\n", + qfalse, qfalse ); + + CG_GenerateShaders( "scripts/viewflames.shader", + "viewFlashFire", + "clnfire", + 16, + "GL_ONE", + "GL_ONE", + "\t\talphaGen vertex\n\t\trgbGen vertex\n", + qtrue, qtrue ); + + CG_GenerateShaders( "scripts/twiltb.shader", + "twiltb", + "twiltb", + 42, + "GL_SRC_ALPHA", + "GL_ONE_MINUS_SRC_COLOR", + "", + qtrue, qfalse ); + + CG_GenerateShaders( "scripts/twiltb2.shader", + "twiltb2", + "twiltb2", + 45, + "GL_ONE", + "GL_ONE_MINUS_SRC_COLOR", + "", + qtrue, qfalse ); + + CG_GenerateShaders( "scripts/expblue.shader", + "expblue", + "expblue", + 25, + "GL_ONE", + "GL_ONE_MINUS_SRC_COLOR", + "", + qfalse, qfalse ); + + CG_GenerateShaders( "scripts/firest.shader", + "firest", + "firest", + 36, + "GL_ONE", + "GL_ONE_MINUS_SRC_COLOR", + "", + qtrue, qfalse ); + + CG_GenerateShaders( "scripts/explode1.shader", + "explode1", + "explode1", + 23, + "GL_ONE", + "GL_ONE_MINUS_SRC_COLOR", + "", + qtrue, qfalse ); + + CG_GenerateShaders( "scripts/funnel.shader", + "funnel", + "funnel", + 21, + "GL_ONE", + "GL_ONE_MINUS_SRC_COLOR", + "", + qfalse, qfalse ); +#endif + + for ( i = 0; i < NUM_FLAME_SPRITES; i++ ) { + Com_sprintf( filename, MAX_QPATH, "flamethrowerFire%i", i + 1 ); + flameShaders[i] = trap_R_RegisterShader( filename ); + } + for ( i = 0; i < NUM_NOZZLE_SPRITES; i++ ) { + Com_sprintf( filename, MAX_QPATH, "nozzleFlame%i", i + 1 ); + nozzleShaders[i] = trap_R_RegisterShader( filename ); + } + initFlameShaders = qfalse; +} + +/* +=============== +CG_AddFlameChunks +=============== +*/ +void CG_AddFlameChunks( void ) { + flameChunk_t *f, *fNext; + //int moveStep = 100; // TTimo: unused + + //AngleVectors( cg.refdef.viewangles, NULL, vright, vup ); + VectorCopy( cg.refdef.viewaxis[1], vright ); + VectorCopy( cg.refdef.viewaxis[2], vup ); + + // clear out the volumes so we can rebuild them + memset( centFlameStatus, 0, sizeof( centFlameStatus ) ); + + numClippedFlames = 0; + + // age them + f = activeFlameChunks; + while ( f ) { + if ( !f->dead ) { + if ( cg.time > f->timeEnd ) { + f->dead = qtrue; + } else if ( f->ignitionOnly && ( f->blueLife < ( cg.time - f->timeStart ) ) ) { + f->dead = qtrue; + } else { + // adjust by a fraction if crossing the blueLife threshold + if ( ( f->sizeTime - f->timeStart < f->blueLife ) != ( cg.time - f->timeStart < f->blueLife ) ) { + CG_AdjustFlameSize( f, f->timeStart + f->blueLife ); + } + // + CG_AdjustFlameSize( f, cg.time ); + //if (cg.time - f->baseOrgTime >= moveStep) + CG_MoveFlameChunk( f, cg.time ); + // + f->lifeFrac = (float)( f->baseOrgTime - f->timeStart ) / (float)( f->timeEnd - f->timeStart ); + } + } + f = f->nextGlobal; + } + + // draw each of the headFlameChunk's + f = headFlameChunks; + while ( f ) { + fNext = f->nextHead; // in case it gets removed + if ( f->dead ) { + if ( centFlameInfo[f->ownerCent].lastFlameChunk == f ) { + centFlameInfo[f->ownerCent].lastFlameChunk = NULL; + centFlameInfo[f->ownerCent].lastClientFrame = 0; + } + CG_FreeFlameChunk( f ); + } else if ( !f->ignitionOnly || ( centFlameInfo[f->ownerCent].lastFlameChunk == f ) ) { // don't draw the ignition flame after we start firing + CG_AddFlameToScene( f ); + } + f = fNext; + } +} + +/* +=============== +CG_UpdateFlamethrowerSounds +=============== +*/ +void CG_UpdateFlamethrowerSounds( void ) { + flameChunk_t *f, *trav; + //flameChunk_t *lastSoundFlameChunk=NULL; // TTimo: unused + int i; + centity_t *cent; + #define MIN_BLOW_VOLUME 30 + + // draw each of the headFlameChunk's + f = headFlameChunks; + while ( f ) { + + if ( centFlameInfo[f->ownerCent].silent ) { + f = f->nextHead; + continue; + } + + // update this entity? + if ( centFlameInfo[f->ownerCent].lastSoundUpdate != cg.time ) { + // blow/ignition sound + if ( centFlameStatus[f->ownerCent].blowVolume * 255.0 > MIN_BLOW_VOLUME ) { + trap_S_AddLoopingSound( f->ownerCent, f->org, vec3_origin, cgs.media.flameBlowSound, (int)( 255.0 * centFlameStatus[f->ownerCent].blowVolume ) ); + } else { + trap_S_AddLoopingSound( f->ownerCent, f->org, vec3_origin, cgs.media.flameBlowSound, MIN_BLOW_VOLUME ); + } + + if ( centFlameStatus[f->ownerCent].streamVolume ) { + if ( cg_entities[f->ownerCent].currentState.aiChar != AICHAR_ZOMBIE ) { + trap_S_AddLoopingSound( f->ownerCent, f->org, vec3_origin, cgs.media.flameStreamSound, (int)( 255.0 /**centFlameStatus[f->ownerCent].streamVolume*/ ) ); + } else { + trap_S_AddLoopingSound( f->ownerCent, f->org, vec3_origin, cgs.media.flameCrackSound, (int)( 255.0 * centFlameStatus[f->ownerCent].streamVolume ) ); + } + } + + centFlameInfo[f->ownerCent].lastSoundUpdate = cg.time; + } + + // traverse the chunks, spawning flame sound sources as we go + for ( trav = f; trav; trav = trav->nextFlameChunk ) { + // update the sound volume + if ( trav->blueLife + 100 < ( cg.time - trav->timeStart ) ) { + //if (!lastSoundFlameChunk || Distance( lastSoundFlameChunk->org, trav->org ) > lastSoundFlameChunk->size) { + trap_S_AddLoopingSound( trav->ownerCent, trav->org, vec3_origin, cgs.media.flameSound, (int)( 255.0 * ( 0.2 * ( trav->size / FLAME_MAX_SIZE ) ) ) ); + // lastSoundFlameChunk = trav; + //} + } + } + + f = f->nextHead; + } + + // send client damage updates if required + for ( cent = cg_entities, i = 0; i < cgs.maxclients; cent++, i++ ) { + if ( centFlameInfo[i].lastDmgCheck > centFlameInfo[i].lastDmgUpdate && + centFlameInfo[i].lastDmgUpdate < cg.time - 50 ) { // JPW NERVE (cgs.gametype == GT_SINGLE_PLAYER ? 50 : 50)) -- sean changed clientdamage so this isn't a saturation issue any longer + if ( ( cg.snap->ps.pm_flags & PMF_LIMBO ) || ( cg.snap->ps.persistant[PERS_TEAM] == TEAM_SPECTATOR ) ) { // JPW NERVE + return; // JPW NERVE don't do flame damage to guys in limbo or spectator, they drop out of the game + + } + CG_ClientDamage( i, centFlameInfo[i].lastDmgEnemy, CLDMG_FLAMETHROWER ); + centFlameInfo[i].lastDmgUpdate = cg.time; + } + } +} diff --git a/Projects/Android/jni/rtcw/src/cgame/cg_info.c b/Projects/Android/jni/rtcw/src/cgame/cg_info.c new file mode 100644 index 0000000..5f45326 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/cgame/cg_info.c @@ -0,0 +1,667 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +// cg_info.c -- display information while data is being loading + +#include "cg_local.h" +#include "../ui/ui_shared.h" + +#define MAX_LOADING_PLAYER_ICONS 16 +#define MAX_LOADING_ITEM_ICONS 26 + +static int loadingPlayerIconCount; +static int loadingItemIconCount; +static qhandle_t loadingPlayerIcons[MAX_LOADING_PLAYER_ICONS]; +static qhandle_t loadingItemIcons[MAX_LOADING_ITEM_ICONS]; + + +/* +=================== +CG_DrawLoadingIcons +=================== +*/ +static void CG_DrawLoadingIcons( void ) { + int n; + int x, y; + + // JOSEPH 5-2-00 Per MAXX + return; + + for ( n = 0; n < loadingPlayerIconCount; n++ ) { + x = 16 + n * 78; + y = 324; + CG_DrawPic( x, y, 64, 64, loadingPlayerIcons[n] ); + } + + for ( n = 0; n < loadingItemIconCount; n++ ) { + y = 400; + if ( n >= 13 ) { + y += 40; + } + x = 16 + n % 13 * 48; + CG_DrawPic( x, y, 32, 32, loadingItemIcons[n] ); + } +} + + +/* +====================== +CG_LoadingString + +====================== +*/ +void CG_LoadingString( const char *s ) { + Q_strncpyz( cg.infoScreenText, s, sizeof( cg.infoScreenText ) ); + + if ( s && s[0] != 0 ) { + CG_Printf( va( "LOADING... %s\n",s ) ); //----(SA) added so you can see from the console what's going on + + } + trap_UpdateScreen(); +} + +/* +=================== +CG_LoadingItem +=================== +*/ +void CG_LoadingItem( int itemNum ) { + gitem_t *item; + + item = &bg_itemlist[itemNum]; + + if ( item->giType == IT_KEY ) { // do not show keys at level startup //----(SA) + return; + } + +//----(SA) Max Kaufman request that we don't show any pacifier stuff for items + return; +//----(SA) end + + + if ( item->icon && loadingItemIconCount < MAX_LOADING_ITEM_ICONS ) { + loadingItemIcons[loadingItemIconCount++] = trap_R_RegisterShaderNoMip( item->icon ); + } + + CG_LoadingString( cgs.itemPrintNames[item - bg_itemlist] ); +} + +/* +=================== +CG_LoadingClient +=================== +*/ +void CG_LoadingClient( int clientNum ) { + const char *info; + char *skin; + char personality[MAX_QPATH]; + char model[MAX_QPATH]; + char iconName[MAX_QPATH]; + + if ( cgs.gametype == GT_SINGLE_PLAYER && clientNum > 0 ) { // for now only show the player's icon in SP games + return; + } + + info = CG_ConfigString( CS_PLAYERS + clientNum ); + + Q_strncpyz( model, Info_ValueForKey( info, "model" ), sizeof( model ) ); + skin = Q_strrchr( model, '/' ); + if ( skin ) { + *skin++ = '\0'; + } else { + skin = "default"; + } + + Com_sprintf( iconName, MAX_QPATH, "models/players/%s/icon_%s.tga", model, skin ); + +// (SA) ignore player icons for the moment + if ( !( cg_entities[clientNum].currentState.aiChar ) ) { +// if ( loadingPlayerIconCount < MAX_LOADING_PLAYER_ICONS ) { +// loadingPlayerIcons[loadingPlayerIconCount++] = trap_R_RegisterShaderNoMip( iconName ); +// } + } + + Q_strncpyz( personality, Info_ValueForKey( info, "n" ), sizeof( personality ) ); + Q_CleanStr( personality ); + + if ( cgs.gametype == GT_SINGLE_PLAYER ) { + trap_S_RegisterSound( va( "sound/player/announce/%s.wav", personality ) ); + } + + CG_LoadingString( personality ); +} + +/* +==================== +CG_DrawStats +==================== +*/ + +typedef struct { + char *label; + int YOfs; + int labelX; + int labelFlags; + vec4_t labelColor; + + char *format; + int formatX; + int formatFlags; + vec4_t formatColor; + + int numVars; +} statsItem_t; + +// this defines the layout of the mission stats +// NOTE: these must match the stats sent in AICast_ScriptAction_ChangeLevel() +static statsItem_t statsItems[] = { + { "end_time", 168, 214, ITEM_TEXTSTYLE_SHADOWEDMORE, {1.0f, 1.0f, 1.0f, 1.0f}, "%02i:%02i:%02i", 348, ITEM_TEXTSTYLE_SHADOWEDMORE, {1.0f, 1.0f, 1.0f, 1.0f}, 3 }, + { "end_objectives", 28, 214, ITEM_TEXTSTYLE_SHADOWEDMORE, {1.0f, 1.0f, 1.0f, 1.0f}, "%i/%i", 348, ITEM_TEXTSTYLE_SHADOWEDMORE, {1.0f, 1.0f, 1.0f, 1.0f}, 2 }, + { "end_secrets", 28, 214, ITEM_TEXTSTYLE_SHADOWEDMORE, {1.0f, 1.0f, 1.0f, 1.0f}, "%i/%i", 348, ITEM_TEXTSTYLE_SHADOWEDMORE, {1.0f, 1.0f, 1.0f, 1.0f}, 2 }, + { "end_treasure", 28, 214, ITEM_TEXTSTYLE_SHADOWEDMORE, {0.62f, 0.56f, 0.0f, 1.0f}, "%i/%i", 348, ITEM_TEXTSTYLE_SHADOWEDMORE, {1.0f, 1.0f, 1.0f, 1.0f}, 2 }, + { "end_attempts", 28, 214, ITEM_TEXTSTYLE_SHADOWEDMORE, {1.0f, 1.0f, 1.0f, 1.0f}, "%i", 348, ITEM_TEXTSTYLE_SHADOWEDMORE, {1.0f, 1.0f, 1.0f, 1.0f}, 1 }, + + { NULL } +}; + +// int numSecrets; +// int numTreasure; +// int numTreasureFound; +// int numArtifacts; +// int numObjectives; + + + +/* +============== +CG_DrawStats +============== +*/ +void CG_DrawStats( char *stats ) { + int i, y, v, j; + #define MAX_STATS_VARS 64 + int vars[MAX_STATS_VARS]; + char *str, *token; + char *formatStr; + int varIndex; + char string[MAX_QPATH]; + + UI_DrawProportionalString( 320, 120, "MISSION STATS", + UI_CENTER | UI_SMALLFONT | UI_DROPSHADOW, colorWhite ); + + Q_strncpyz( string, stats, sizeof( string ) ); + str = string; + // convert commas to spaces + for ( i = 0; str[i]; i++ ) { + if ( str[i] == ',' ) { + str[i] = ' '; + } + } + + for ( i = 0, y = 0, v = 0; statsItems[i].label; i++ ) { + y += statsItems[i].YOfs; + +// UI_DrawProportionalString( statsItems[i].labelX, y, statsItems[i].label, +// statsItems[i].labelFlags, *statsItems[i].labelColor ); + + if ( statsItems[i].numVars ) { + varIndex = v; + for ( j = 0; j < statsItems[i].numVars; j++ ) { + token = COM_Parse( &str ); + if ( !token || !token[0] ) { + CG_Error( "error parsing mission stats\n" ); + return; + } + + vars[v++] = atoi( token ); + } + + // build the formatStr + switch ( statsItems[i].numVars ) { + case 1: + formatStr = va( statsItems[i].format, vars[varIndex] ); + break; + case 2: + formatStr = va( statsItems[i].format, vars[varIndex], vars[varIndex + 1] ); + break; + case 3: + formatStr = va( statsItems[i].format, vars[varIndex], vars[varIndex + 1], vars[varIndex + 2] ); + break; + case 4: + formatStr = va( statsItems[i].format, vars[varIndex], vars[varIndex + 1], vars[varIndex + 2], vars[varIndex + 3] ); + break; + } + +// UI_DrawProportionalString( statsItems[i].formatX, y, formatStr, +// statsItems[i].formatFlags, *statsItems[i].formatColor ); + } + } +} + +/* +============== +CG_DrawExitStats + pretty much what the game should draw when you're at the exit + This is not the final deal, but represents the kind of thing + that will be there +============== +*/ + +void CG_DrawExitStats( void ) { + int i, y, v, j; + float *color; // faded color based on cursor hint drawing + float color2[4] = {0, 0, 0, 1}; + const char *str; + char *mstats, *token; + + #define MAX_STATS_VARS 64 + int vars[MAX_STATS_VARS]; + char *formatStr = NULL; // TTimo: init + int varIndex = 0; // TTimo: init + + if ( cg_paused.integer ) { + // no draw if any menu's are up (or otherwise paused) + return; + } + + color = CG_FadeColor( cg.cursorHintTime, cg.cursorHintFade ); + + if ( !color ) { // currently faded out, don't draw + return; + } + + // check for fade up + if ( cg.time < ( cg.exitStatsTime + cg.exitStatsFade ) ) { + color[3] = (float)( cg.time - cg.exitStatsTime ) / (float)cg.exitStatsFade; + } + + color2[3] = color[3]; + + +// parse it + str = CG_ConfigString( CS_MISSIONSTATS ); + + if ( !str || !str[0] ) { + return; + } + + // background + color2[3] *= 0.6f; + CG_FilledBar( 150, 104, 340, 230, color2, NULL, NULL, 1.0f, 0 ); + + color2[0] = color2[1] = color2[2] = 0.3f; + color2[3] *= 0.6f; + + // border + CG_FilledBar( 148, 104, 2, 230, color2, NULL, NULL, 1.0f, 0 ); // left + CG_FilledBar( 490, 104, 2, 230, color2, NULL, NULL, 1.0f, 0 ); // right + CG_FilledBar( 148, 102, 344, 2, color2, NULL, NULL, 1.0f, 0 ); // top + CG_FilledBar( 148, 334, 344, 2, color2, NULL, NULL, 1.0f, 0 ); // bot + + + // text boxes + color2[0] = color2[1] = color2[2] = 0.4f; + for ( i = 0; i < 5; i++ ) { + CG_FilledBar( 170, 154 + ( 28 * i ), 300, 20, color2, NULL, NULL, 1.0f, 0 ); + } + + + // green title + color2[0] = color2[2] = 0; + color2[1] = 0.3f; + CG_FilledBar( 150, 104, 340, 20, color2, NULL, NULL, 1.0f, 0 ); + + color2[0] = color2[1] = color2[2] = 0.2f; + + // title + color2[0] = color2[1] = color2[2] = 1; + color2[3] = color[3]; +// CG_Text_Paint(280, 120, 2, 0.25f, color2, va("%s", CG_translateString("end_title")), 0, 0, ITEM_TEXTSTYLE_SHADOWEDMORE); + //----(SA) scale change per MK + CG_Text_Paint( 270, 120, 2, 0.313f, color2, va( "%s", CG_translateString( "end_title" ) ), 0, 0, ITEM_TEXTSTYLE_SHADOWEDMORE ); + + color2[0] = color2[1] = color2[2] = 1; + if ( cg.cursorHintIcon == HINT_NOEXIT ) { + // "exit not available" +// CG_Text_Paint(250, 320, 2, 0.3f, color2, va("%s", CG_translateString("end_noexit")), 0, 0, ITEM_TEXTSTYLE_SHADOWEDMORE); + //----(SA) scale change per MK + CG_Text_Paint( 260, 320, 2, 0.225f, color2, va( "%s", CG_translateString( "end_noexit" ) ), 0, 0, ITEM_TEXTSTYLE_SHADOWEDMORE ); + } else { + // "forward to proceed" +// CG_Text_Paint(230, 320, 2, 0.3f, color2, va("%s", CG_translateString("end_exit")), 0, 0, ITEM_TEXTSTYLE_SHADOWEDMORE); + //----(SA) scale change per MK + CG_Text_Paint( 250, 320, 2, 0.225f, color2, va( "%s", CG_translateString( "end_exit" ) ), 0, 0, ITEM_TEXTSTYLE_SHADOWEDMORE ); + } + + mstats = (char*)str + 2; // add offset for 's=' + for ( i = 0; mstats[i]; i++ ) { + if ( mstats[i] == ',' ) { + mstats[i] = ' '; + } + } + for ( i = 0, y = 0, v = 0; statsItems[i].label; i++ ) { + y += statsItems[i].YOfs; + + VectorCopy4( statsItems[i].labelColor, color2 ); +// statsItems[i].labelColor[3] = statsItems[i].formatColor[3] = color[3]; // set proper alpha + color2[3] = statsItems[i].formatColor[3] = color[3]; // set proper alpha + + + if ( statsItems[i].numVars ) { + varIndex = v; + for ( j = 0; j < statsItems[i].numVars; j++ ) { + token = COM_Parse( &mstats ); + if ( !token || !token[0] ) { + CG_Error( "error parsing mission stats\n" ); + return; + } + + vars[v++] = atoi( token ); + } + + // build the formatStr + switch ( statsItems[i].numVars ) { + case 1: + formatStr = va( statsItems[i].format, vars[varIndex] ); + break; + case 2: + formatStr = va( statsItems[i].format, vars[varIndex], vars[varIndex + 1] ); + break; + case 3: + formatStr = va( statsItems[i].format, vars[varIndex], vars[varIndex + 1], vars[varIndex + 2] ); + break; + case 4: + formatStr = va( statsItems[i].format, vars[varIndex], vars[varIndex + 1], vars[varIndex + 2], vars[varIndex + 3] ); + break; + } + + CG_Text_Paint( statsItems[i].formatX, y, 2, 0.3, statsItems[i].formatColor, formatStr, 0, 0, statsItems[i].formatFlags ); +// UI_DrawProportionalString( statsItems[i].formatX, y, formatStr, statsItems[i].formatFlags, *statsItems[i].formatColor ); + } + + if ( i == 1 ) { // 'objectives' + if ( vars[varIndex] < vars[varIndex + 1] ) { // missing objectives, draw in red + color2[0] = 1; + color2[1] = color2[2] = 0; + } + } + + if ( i == 3 ) { // 'treasure' + if ( vars[varIndex] < vars[varIndex + 1] || !vars[varIndex + 1] ) { // missing treasure, only draw in white (gold when you got em all) (unless there's no gold available, then 0/0 shows white) + color2[0] = color2[1] = color2[2] = 1; // white + } + } + +// UI_DrawProportionalString( statsItems[i].labelX, y, statsItems[i].label, statsItems[i].labelFlags, *statsItems[i].labelColor ); + +// CG_Text_Paint(statsItems[i].labelX, y, 2, 0.3, statsItems[i].labelColor, va("%s:", CG_translateString(statsItems[i].label)), 0, 0, statsItems[i].labelFlags); + CG_Text_Paint( statsItems[i].labelX, y, 2, 0.3, color2, va( "%s:", CG_translateString( statsItems[i].label ) ), 0, 0, statsItems[i].labelFlags ); + + } + token = COM_Parse( &mstats ); + +// end (parse it) +} + + +/* +==================== +CG_DrawInformation + +Draw all the status / pacifier stuff during level loading +==================== +*/ +void CG_DrawInformation( void ) { + const char *s; + const char *info; + const char *sysInfo; + int y; + int value; + qhandle_t levelshot = 0; // TTimo: init +// qhandle_t detail; + char buf[1024]; + static int lastDraw = 0; // Ridah, so we don't draw the screen more often than we need to + int ms; + static int callCount = 0; + float percentDone; + + int expectedHunk; + char hunkBuf[MAX_QPATH]; + + vec4_t color; + + if ( cg.snap && ( strlen( cg_missionStats.string ) <= 1 ) ) { + return; // we are in the world, no need to draw information + } + + if ( callCount ) { // reject recursive calls + return; + } + + ms = trap_Milliseconds(); + if ( ( lastDraw <= ms ) && ( lastDraw > ms - 100 ) ) { + return; + } + lastDraw = ms; + + callCount++; + + info = CG_ConfigString( CS_SERVERINFO ); + sysInfo = CG_ConfigString( CS_SYSTEMINFO ); + + trap_Cvar_VariableStringBuffer( "com_expectedhunkusage", hunkBuf, MAX_QPATH ); + expectedHunk = atoi( hunkBuf ); + + + s = Info_ValueForKey( info, "mapname" ); + + //----(SA) just the briefing now + + if ( s && s[0] != 0 ) { // there is often no 's' + levelshot = trap_R_RegisterShaderNoMip( va( "levelshots/%s.tga", s ) ); + } + + if ( !levelshot ) { + levelshot = trap_R_RegisterShaderNoMip( "menu/art/unknownmap" ); + } + + trap_R_SetColor( NULL ); +// CG_DrawPic( 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, levelshot ); + + // blend a detail texture over it + //detail = trap_R_RegisterShader( "levelShotDetail" ); + //trap_R_DrawStretchPic( 0, 0, cgs.glconfig.vidWidth, cgs.glconfig.vidHeight, 0, 0, 2.5, 2, detail ); + + +// (SA) commented out for Drew +// UI_DrawProportionalString( 320, 16, va( "Loading %s", Info_ValueForKey( info, "mapname" ) ), UI_SMALLFONT|UI_CENTER|UI_DROPSHADOW, colorWhite ); + + // show the loading progress + VectorSet( color, 0.8, 0.8, 0.8 ); + color[3] = 0.8; + + if ( strlen( cg_missionStats.string ) > 1 && cg_missionStats.string[0] == 's' ) { + vec2_t xy = { 190, 470 }; + vec2_t wh = { 260, 10 }; + + // draw the mission stats while loading + + if ( expectedHunk > 0 ) { + percentDone = (float)( cg_hunkUsed.integer + cg_soundAdjust.integer ) / (float)( expectedHunk ); + if ( percentDone > 0.97 ) { // never actually show 100%, since we are not in the game yet + percentDone = 0.97; + } + CG_HorizontalPercentBar( xy[0] + 10, xy[1] + wh[1] - 10, wh[0] - 20, 10, percentDone ); + } else { + UI_DrawProportionalString( 320, xy[1] + wh[1] - 10, "please wait", + UI_CENTER | UI_EXSMALLFONT | UI_DROPSHADOW, color ); + } + + trap_UpdateScreen(); + callCount--; + return; + } + + // Ridah, in single player, cheats disabled, don't show unnecessary information + if ( cgs.gametype == GT_SINGLE_PLAYER ) { + + if ( 0 ) { // bar drawn in menu now + vec2_t xy = { 200, 468 }; + vec2_t wh = { 240, 10 }; + + // show the percent complete bar + if ( expectedHunk > 0 ) { + percentDone = (float)( cg_hunkUsed.integer + cg_soundAdjust.integer ) / (float)( expectedHunk ); + if ( percentDone > 0.97 ) { + percentDone = 0.97; + } + + CG_HorizontalPercentBar( xy[0], xy[1], wh[0], wh[1], percentDone ); + } + } + + trap_UI_Popup( "briefing" ); + + trap_UpdateScreen(); + callCount--; + return; + } + // done. + + + // draw the icons of thiings as they are loaded + CG_DrawLoadingIcons(); + + // the first 150 rows are reserved for the client connection + // screen to write into + if ( cg.infoScreenText[0] ) { + UI_DrawProportionalString( 320, 128, va( "Loading... %s", cg.infoScreenText ), + UI_CENTER | UI_SMALLFONT | UI_DROPSHADOW, colorWhite ); + } else { + UI_DrawProportionalString( 320, 128, "Awaiting snapshot...", + UI_CENTER | UI_SMALLFONT | UI_DROPSHADOW, colorWhite ); + } + + // draw info string information + + y = 180; + + // don't print server lines if playing a local game + trap_Cvar_VariableStringBuffer( "sv_running", buf, sizeof( buf ) ); + if ( !atoi( buf ) ) { + // server hostname + s = Info_ValueForKey( info, "sv_hostname" ); + UI_DrawProportionalString( 320, y, s, + UI_CENTER | UI_SMALLFONT | UI_DROPSHADOW, colorWhite ); + y += PROP_HEIGHT; + + // server-specific message of the day + s = CG_ConfigString( CS_MOTD ); + if ( s[0] ) { + UI_DrawProportionalString( 320, y, s, + UI_CENTER | UI_SMALLFONT | UI_DROPSHADOW, colorWhite ); + y += PROP_HEIGHT; + } + + // some extra space after hostname and motd + y += 10; + } + + // map-specific message (long map name) + s = CG_ConfigString( CS_MESSAGE ); + if ( s[0] ) { + UI_DrawProportionalString( 320, y, s, + UI_CENTER | UI_SMALLFONT | UI_DROPSHADOW, colorWhite ); + y += PROP_HEIGHT; + } + + // cheats warning + s = Info_ValueForKey( sysInfo, "sv_cheats" ); + if ( s[0] == '1' ) { + UI_DrawProportionalString( 320, y, "CHEATS ARE ENABLED", + UI_CENTER | UI_SMALLFONT | UI_DROPSHADOW, colorWhite ); + y += PROP_HEIGHT; + } + + // game type + switch ( cgs.gametype ) { + case GT_FFA: + s = "Free For All"; + break; + case GT_SINGLE_PLAYER: + s = "Single Player"; + break; + case GT_TOURNAMENT: + s = "Tournament"; + break; + case GT_TEAM: + s = "Team Deathmatch"; + break; + case GT_CTF: + s = "Capture The Flag"; + break; +// JPW NERVE + case GT_WOLF: + s = "Wolfenstein Multiplayer"; + break; +// jpw + default: + s = "Unknown Gametype"; + break; + } + UI_DrawProportionalString( 320, y, s, + UI_CENTER | UI_SMALLFONT | UI_DROPSHADOW, colorWhite ); + y += PROP_HEIGHT; + + value = atoi( Info_ValueForKey( info, "timelimit" ) ); + if ( value ) { + UI_DrawProportionalString( 320, y, va( "timelimit %i", value ), + UI_CENTER | UI_SMALLFONT | UI_DROPSHADOW, colorWhite ); + y += PROP_HEIGHT; + } + + if ( cgs.gametype != GT_CTF && cgs.gametype != GT_SINGLE_PLAYER ) { + value = atoi( Info_ValueForKey( info, "fraglimit" ) ); + if ( value ) { + UI_DrawProportionalString( 320, y, va( "fraglimit %i", value ), + UI_CENTER | UI_SMALLFONT | UI_DROPSHADOW, colorWhite ); + y += PROP_HEIGHT; + } + } + + if ( cgs.gametype == GT_CTF ) { + value = atoi( Info_ValueForKey( info, "capturelimit" ) ); + if ( value ) { + UI_DrawProportionalString( 320, y, va( "capturelimit %i", value ), + UI_CENTER | UI_SMALLFONT | UI_DROPSHADOW, colorWhite ); + y += PROP_HEIGHT; + } + } + + callCount--; +} diff --git a/Projects/Android/jni/rtcw/src/cgame/cg_local.h b/Projects/Android/jni/rtcw/src/cgame/cg_local.h new file mode 100644 index 0000000..db5084f --- /dev/null +++ b/Projects/Android/jni/rtcw/src/cgame/cg_local.h @@ -0,0 +1,2469 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +/* + * name: cg_local.h + * + * desc: The entire cgame module is unloaded and reloaded on each level change, + * so there is NO persistant data between levels on the client side. + * If you absolutely need something stored, it can either be kept + * by the server in the server stored userinfos, or stashed in a cvar. + + * +*/ + +#include "../game/q_shared.h" +#include "tr_types.h" +#include "../game/bg_public.h" +#include "cg_public.h" + + +#define POWERUP_BLINKS 5 + +#define POWERUP_BLINK_TIME 1000 +#define FADE_TIME 200 +#define PULSE_TIME 200 +#define DAMAGE_DEFLECT_TIME 100 +#define DAMAGE_RETURN_TIME 400 +#define DAMAGE_TIME 500 +#define LAND_DEFLECT_TIME 150 +#define LAND_RETURN_TIME 300 +#define STEP_TIME 200 +#define DUCK_TIME 100 +#define PAIN_TWITCH_TIME 200 +#define WEAPON_SELECT_TIME 1400 +#define HOLDABLE_SELECT_TIME 1400 //----(SA) for drawing holdable icons +#define ITEM_SCALEUP_TIME 1000 +#define ZOOM_TIME 150 +#define ITEM_BLOB_TIME 200 +#define MUZZLE_FLASH_TIME 30 //----(SA) +#define SINK_TIME 1000 // time for fragments to sink into ground before going away +#define ATTACKER_HEAD_TIME 10000 +#define REWARD_TIME 3000 + +#define PULSE_SCALE 1.5 // amount to scale up the icons when activating + +#define MAX_STEP_CHANGE 32 + +#define MAX_VERTS_ON_POLY 10 +#define MAX_MARK_POLYS 1024 + +#define STAT_MINUS 10 // num frame for '-' stats digit + +#define ICON_SIZE 48 +#define CHAR_WIDTH 32 +#define CHAR_HEIGHT 48 +#define TEXT_ICON_SPACE 4 + +#define TEAMCHAT_WIDTH 80 +#define TEAMCHAT_HEIGHT 8 + +// very large characters +#define GIANT_WIDTH 32 +#define GIANT_HEIGHT 48 + +#define NUM_CROSSHAIRS 10 + +// Ridah, trails +#define STYPE_STRETCH 0 +#define STYPE_REPEAT 1 + +#define TJFL_FADEIN ( 1 << 0 ) +#define TJFL_CROSSOVER ( 1 << 1 ) +#define TJFL_NOCULL ( 1 << 2 ) +#define TJFL_FIXDISTORT ( 1 << 3 ) +#define TJFL_SPARKHEADFLARE ( 1 << 4 ) +#define TJFL_NOPOLYMERGE ( 1 << 5 ) +// done. + +// NERVE - SMF - limbo mode 3d view position +#define LIMBO_3D_X 10 +#define LIMBO_3D_Y 120 +#define LIMBO_3D_W 420 +#define LIMBO_3D_H 330 +// -NERVE - SMF + +//================================================= + +// player entities need to track more information +// than any other type of entity. + +// note that not every player entity is a client entity, +// because corpses after respawn are outside the normal +// client numbering range + +// when changing animation, set animationTime to frameTime + lerping time +// The current lerp will finish out, then it will lerp to the new animation +typedef struct { + int oldFrame; + int oldFrameTime; // time when ->oldFrame was exactly on + + int frame; + int frameTime; // time when ->frame will be exactly on + + float backlerp; + + float yawAngle; + qboolean yawing; + float pitchAngle; + qboolean pitching; + + int animationNumber; // may include ANIM_TOGGLEBIT + int oldAnimationNumber; // may include ANIM_TOGGLEBIT + animation_t *animation; + int animationTime; // time when the first frame of the animation will be exact + + // Ridah, variable speed anims + vec3_t oldFramePos; + float animSpeedScale; + int oldFrameSnapshotTime; + headAnimation_t *headAnim; + // done. + + animation_t *cgAnim; // pointer to the root of the animation array to use (*animation above points at the current sequence) //----(SA) added +} lerpFrame_t; + +// Ridah, effect defines +#define MAX_ZOMBIE_SPIRITS 4 +#define MAX_ZOMBIE_DEATH_TRAILS 16 + +#define MAX_LOPER_LIGHTNING_POINTS 24 + +#define MAX_TESLA_BOLTS 4 + +#define MAX_EFFECT_ENTS 20 + +typedef struct { + lerpFrame_t legs, torso; + + // Ridah, talking animations + lerpFrame_t head; + // done. + + lerpFrame_t weap; //----(SA) autonomous weapon animations + + int lastTime; // last time we were processed/ If the time goes backwards, reset. + + int painTime; + int painDuration; + int painDirection; // flip from 0 to 1 + int painAnimTorso; + int painAnimLegs; + int lightningFiring; + + // railgun trail spawning + vec3_t railgunImpact; + qboolean railgunFlash; + + // machinegun spinning + float barrelAngle; + int barrelTime; + qboolean barrelSpinning; + + //----(SA) machinegun bolt sliding + float boltPosition; + int boltTime; + int boltSliding; + //----(SA) end + + //----(SA) 'spinner' spinning (body part) + float spinnerAngle; + int spinnerTime; + qboolean spinnerSpinning; + //----(SA) end + + // Ridah, so we can do fast tag grabbing + refEntity_t legsRefEnt, torsoRefEnt, headRefEnt, gunRefEnt; + int gunRefEntFrame; + + float animSpeed; // for manual adjustment + + // Zombie spirit effect + // !!FIXME: these effects will be restarted by a *_restart command, can we save this data somehow? + qboolean cueZombieSpirit; // if this is qfalse, and the zombie effect flag is set, then we need to start a new attack + int zombieSpiritStartTime; // time the effect was started, so we can fade things in + int zombieSpiritTrailHead[MAX_ZOMBIE_SPIRITS]; + int zombieSpiritRotationTimes[MAX_ZOMBIE_SPIRITS]; + int zombieSpiritRadiusCycleTimes[MAX_ZOMBIE_SPIRITS]; + int lastZombieSpirit; + int nextZombieSpiritSound; + int zombieSpiritEndTime; // time the effect was disabled + vec3_t zombieSpiritPos[MAX_ZOMBIE_SPIRITS]; + vec3_t zombieSpiritDir[MAX_ZOMBIE_SPIRITS]; + float zombieSpiritSpeed[MAX_ZOMBIE_SPIRITS]; + int zombieSpiritStartTimes[MAX_ZOMBIE_SPIRITS]; + + // Zombie death effect + // !!FIXME: these effects will be restarted by a *_restart command, can we save this data somehow? + qboolean cueZombieDeath; // if this is qfalse, and the zombie effect flag is set, then we need to start a new attack + int zombieDeathStartTime; // time the effect was started, so we can fade things in + int zombieDeathEndTime; // time the effect was disabled + int lastZombieDeath; + int zombieDeathFadeStart; + int zombieDeathFadeEnd; + int zombieDeathTrailHead[MAX_ZOMBIE_DEATH_TRAILS]; + int zombieDeathRotationTimes[MAX_ZOMBIE_DEATH_TRAILS]; + int zombieDeathRadiusCycleTimes[MAX_ZOMBIE_DEATH_TRAILS]; + + // loper effects + int loperLastGroundChargeTime; + byte loperGroundChargeToggle; + int loperGroundValidTime; + + vec3_t headLookIdeal; + vec3_t headLookOffset; + float headLookSpeed; + int headLookStopTime; + float headLookSpeedMax; + + // tesla coil effects + vec3_t teslaEndPoints[MAX_TESLA_BOLTS]; + int teslaEndPointTimes[MAX_TESLA_BOLTS]; // time the bolt stays valid + vec3_t teslaOffsetDirs[MAX_TESLA_BOLTS]; // bending direction from center or direct beam + float teslaOffsets[MAX_TESLA_BOLTS]; // amount to offset from center + int teslaOffsetTimes[MAX_TESLA_BOLTS]; // time the offset stays valid + int teslaEnemy[MAX_TESLA_BOLTS]; + int teslaDamageApplyTime; + + int teslaDamagedTime; // time we were last hit by a tesla bolt + + // misc effects + int effectEnts[MAX_EFFECT_ENTS]; + int numEffectEnts; + int effect1EndTime; + vec3_t lightningPoints[MAX_LOPER_LIGHTNING_POINTS]; + int lightningTimes[MAX_LOPER_LIGHTNING_POINTS]; + int lightningSoundTime; + + qboolean forceLOD; + +} playerEntity_t; + +//----(SA) +typedef struct { + char type[MAX_QPATH]; // md3_lower, md3_lbelt, md3_rbelt, etc. + char model[MAX_QPATH]; // lower.md3, belt1.md3, etc. +} skinModel_t; +//----(SA) end + + +//================================================= + + + +// centity_t have a direct corespondence with gentity_t in the game, but +// only the entityState_t is directly communicated to the cgame +typedef struct centity_s { + entityState_t currentState; // from cg.frame + entityState_t nextState; // from cg.nextFrame, if available + qboolean interpolate; // true if next is valid to interpolate to + qboolean currentValid; // true if cg.frame holds this entity + + int muzzleFlashTime; // move to playerEntity? + int overheatTime; + int previousEvent; + int previousEventSequence; // Ridah + int teleportFlag; + + int trailTime; // so missile trails can handle dropped initial packets + int miscTime; + + playerEntity_t pe; + + int errorTime; // decay the error from this time + vec3_t errorOrigin; + vec3_t errorAngles; + + qboolean extrapolated; // false if origin / angles is an interpolation + vec3_t rawOrigin; + vec3_t rawAngles; + + vec3_t beamEnd; + + // exact interpolated position of entity on this frame + vec3_t lerpOrigin; + vec3_t lerpAngles; + + vec3_t lastLerpAngles; // (SA) for remembering the last position when a state changes + + // Ridah, trail effects + int headJuncIndex, headJuncIndex2; + int lastTrailTime; + // done. + + // Ridah + float loopSoundVolume; + vec3_t fireRiseDir; // if standing still this will be up, otherwise it'll point away from movement dir + int lastWeaponClientFrame; + int lastFuseSparkTime; + vec3_t lastFuseSparkOrg; + + // client side dlights + int dl_frame; + int dl_oldframe; + float dl_backlerp; + int dl_time; + char dl_stylestring[64]; + int dl_sound; + int dl_atten; + + lerpFrame_t lerpFrame; //----(SA) added + vec3_t highlightOrigin; // center of the geometry. for things like corona placement on treasure + qboolean usehighlightOrigin; + + refEntity_t refEnt; + int processedFrame; // frame we were last added to the scene + + // client-side lightning + int boltTimes[MAX_TESLA_BOLTS]; + vec3_t boltLocs[MAX_TESLA_BOLTS]; + vec3_t boltCrawlDirs[MAX_TESLA_BOLTS]; + + // item highlighting + + int highlightTime; + qboolean highlighted; + + animation_t centAnim[2]; + + // (SA) added to help akimbo effects attach to the correct model + qboolean akimboFire; +} centity_t; + + +//====================================================================== + +// local entities are created as a result of events or predicted actions, +// and live independantly from all server transmitted entities + +typedef struct markPoly_s { + struct markPoly_s *prevMark, *nextMark; + int time; + qhandle_t markShader; + qboolean alphaFade; // fade alpha instead of rgb + float color[4]; + poly_t poly; + polyVert_t verts[MAX_VERTS_ON_POLY]; + + int duration; // Ridah +} markPoly_t; + +//----(SA) moved in from cg_view.c +typedef enum { + ZOOM_NONE, + ZOOM_BINOC, + ZOOM_SNIPER, + ZOOM_SNOOPER, + ZOOM_FG42SCOPE, + ZOOM_MG42, + ZOOM_MAX_ZOOMS +} EZoom_t; + +typedef enum { + ZOOM_OUT, // widest angle + ZOOM_IN // tightest angle (approaching 0) +} EZoomInOut_t; + +extern float zoomTable[ZOOM_MAX_ZOOMS][2]; + +//----(SA) end + +typedef enum { + LE_MARK, + LE_EXPLOSION, + LE_SPRITE_EXPLOSION, + LE_FRAGMENT, + LE_MOVE_SCALE_FADE, + LE_FALL_SCALE_FADE, + LE_FADE_RGB, + LE_SCALE_FADE, + LE_SPARK, + LE_DEBRIS, + LE_BLOOD, + LE_FUSE_SPARK, + LE_ZOMBIE_SPIRIT, + LE_HELGA_SPIRIT, + LE_ZOMBIE_BAT, + LE_MOVING_TRACER, + LE_EMITTER, + LE_SPIRIT_VIEWFLASH +} leType_t; + +typedef enum { + LEF_PUFF_DONT_SCALE = 0x0001 // do not scale size over time + ,LEF_TUMBLE = 0x0002 // tumble over time, used for ejecting shells + ,LEF_NOFADEALPHA = 0x0004 // Ridah, sparks + ,LEF_SMOKING = 0x0008 // (SA) smoking + ,LEF_NOTOUCHPARENT = 0x0010 // (SA) when tracing to eval trajectory, ignore parent cent + ,LEF_PLAYER_DAMAGE = 0x0020 // hurt the player on impact +} leFlag_t; + +typedef enum { + LEMT_NONE, + LEMT_BLOOD +} leMarkType_t; // fragment local entities can leave marks on walls + +typedef enum { + LEBS_NONE, + LEBS_BLOOD, + LEBS_ROCK, + LEBS_WOOD, + LEBS_BRASS, + LEBS_BONE +} leBounceSoundType_t; // fragment local entities can make sounds on impacts + +#define MAX_OLD_POS 3 + +typedef struct localEntity_s { + struct localEntity_s *prev, *next; + leType_t leType; + int leFlags; + + int startTime; + int endTime; + int fadeInTime; + + float lifeRate; // 1.0 / (endTime - startTime) + + trajectory_t pos; + trajectory_t angles; + + float bounceFactor; // 0.0 = no bounce, 1.0 = perfect + + float color[4]; + + float radius; + + float light; + vec3_t lightColor; + + leMarkType_t leMarkType; // mark to leave on fragment impact + leBounceSoundType_t leBounceSoundType; + + refEntity_t refEntity; + + // Ridah + int lightOverdraw; + int lastTrailTime; + int headJuncIndex, headJuncIndex2; + float effectWidth; + int effectFlags; + struct localEntity_s *chain; // used for grouping entities (like for flamethrower junctions) + int onFireStart, onFireEnd; + int ownerNum; + int lastSpiritDmgTime; + + int loopingSound; + + int breakCount; // break-up this many times before we can break no more + float sizeScale; + + char validOldPos[MAX_OLD_POS]; + vec3_t oldPos[MAX_OLD_POS]; + int oldPosHead; + // done. + +} localEntity_t; + +//====================================================================== + + +typedef struct { + int client; + int score; + int ping; + int time; + int scoreFlags; + int powerUps; + int accuracy; + int impressiveCount; + int excellentCount; + int guantletCount; + int defendCount; + int assistCount; + int captures; + qboolean perfect; + int team; +} score_t; + + +typedef enum { + ACC_BELT_LEFT, // belt left (lower) + ACC_BELT_RIGHT, // belt right (lower) + ACC_BELT, // belt (upper) + ACC_BACK, // back (upper) + ACC_WEAPON, // weapon (upper) + ACC_WEAPON2, // weapon2 (upper) + ACC_HAT, // hat (head) + ACC_MOUTH2, // + ACC_MOUTH3, // + // + ACC_MAX // this is bound by network limits, must change network stream to increase this + // (SA) No, really? that's not true is it? isn't this client-side only? +} accType_t; + +#define ACC_NUM_MOUTH 3 // matches the above count (hat/mouth2/mouth3) + + + + +// each client has an associated clientInfo_t +// that contains media references necessary to present the +// client model and other color coded effects +// this is regenerated each time a client's configstring changes, +// usually as a result of a userinfo (name, model, etc) change +#define MAX_CUSTOM_SOUNDS 32 +#define MAX_GIB_MODELS 16 +typedef struct { + qboolean infoValid; + + int clientNum; + + char name[MAX_QPATH]; + team_t team; + + int botSkill; // 0 = not bot, 1-5 = bot + + vec3_t color; + + int score; // updated by score servercmds + int location; // location index for team mode + int health; // you only get this info about your teammates + int armor; + int curWeapon; + + int handicap; + int wins, losses; // in tourney mode + + int powerups; // so can display quad/flag status + + int breathPuffTime; + + // when clientinfo is changed, the loading of models/skins/sounds + // can be deferred until you are dead, to prevent hitches in + // gameplay + char modelName[MAX_QPATH]; + char skinName[MAX_QPATH]; + char hSkinName[MAX_QPATH]; + qboolean deferred; + + qhandle_t legsModel; + qhandle_t legsSkin; + + qhandle_t torsoModel; + qhandle_t torsoSkin; + + qboolean isSkeletal; + + //----(SA) added accessory models/skins for belts/backpacks/etc. + qhandle_t accModels[ACC_MAX]; // see def of ACC_MAX for index descriptions + qhandle_t accSkins[ACC_MAX]; // FIXME: put the #define for number of accessory models somewhere. (SA) + + //----(SA) additional parts for specialized characters (the loper's spinning trunk for example) + qhandle_t partModels[9]; // [0-7] are optionally called in scripts, [8] is reserved for internal use + qhandle_t partSkins[9]; + //----(SA) end + + qhandle_t headModel; + qhandle_t headSkin; + + qhandle_t modelIcon; + + // RF, may be shared by multiple clients/characters + animModelInfo_t *modelInfo; + + sfxHandle_t sounds[MAX_CUSTOM_SOUNDS]; + + qhandle_t gibModels[MAX_GIB_MODELS]; + + vec3_t playermodelScale; //----(SA) set in the skin. client-side only + + int blinkTime; //----(SA) +} clientInfo_t; + + + +typedef enum { + W_PART_1, + W_PART_2, + W_PART_3, + W_PART_4, + W_PART_5, + W_PART_6, + W_PART_7, + W_MAX_PARTS +} barrelType_t; + +typedef enum { + W_TP_MODEL, // third person model + W_FP_MODEL, // first person model + W_PU_MODEL, // pickup model + W_FP_MODEL_SWAP, // swap out model + W_SKTP_MODEL, // SKELETAL version third person model + W_NUM_TYPES +} modelViewType_t; + +// each WP_* weapon enum has an associated weaponInfo_t +// that contains media references necessary to present the +// weapon and its effects +typedef struct weaponInfo_s { + qboolean registered; + gitem_t *item; + +//----(SA) weapon animation sequences loaded from the weapon.cfg + animation_t weapAnimations[MAX_WP_ANIMATIONS]; +//----(SA) end + + qhandle_t handsModel; // the hands don't actually draw, they just position the weapon + + qhandle_t standModel; // not drawn. tags used for positioning weapons for pickup + +//----(SA) mod for 1st/3rd person weap views + qhandle_t weaponModel[W_NUM_TYPES]; + qhandle_t wpPartModels[W_NUM_TYPES][W_MAX_PARTS]; + qhandle_t flashModel[W_NUM_TYPES]; + qhandle_t modModel[W_NUM_TYPES]; // like the scope for the rifles +//----(SA) end + + pose_t position; // wolf locations (high, low, knife, pistol, shoulder, throw) defines are WPOS_HIGH, WPOS_LOW, WPOS_KNIFE, WPOS_PISTOL, WPOS_SHOULDER, WPOS_THROW + + vec3_t weaponMidpoint; // so it will rotate centered instead of by tag + + float flashDlight; + vec3_t flashDlightColor; + sfxHandle_t flashSound[4]; // fast firing weapons randomly choose + sfxHandle_t flashEchoSound[4]; //----(SA) added - distant gun firing sound + sfxHandle_t lastShotSound[4]; // sound of the last shot can be different (mauser doesn't have bolt action on last shot for example) + + sfxHandle_t switchSound[4]; //----(SA) added + + qhandle_t weaponIcon[2]; //----(SA) [0] is weap icon, [1] is highlight icon + qhandle_t ammoIcon; + + qhandle_t ammoModel; + + qhandle_t missileModel; + sfxHandle_t missileSound; + void ( *missileTrailFunc )( centity_t *, const struct weaponInfo_s *wi ); + float missileDlight; + vec3_t missileDlightColor; + int missileRenderfx; + + void ( *ejectBrassFunc )( centity_t * ); + + float trailRadius; + float wiTrailTime; + + sfxHandle_t readySound; // an amibient sound the weapon makes when it's /not/ firing + sfxHandle_t firingSound; + sfxHandle_t overheatSound; + sfxHandle_t reloadSound; + + sfxHandle_t spinupSound; //----(SA) added // sound started when fire button goes down, and stepped on when the first fire event happens + sfxHandle_t spindownSound; //----(SA) added // sound called if the above is running but player doesn't follow through and fire +} weaponInfo_t; + + +// each IT_* item has an associated itemInfo_t +// that constains media references necessary to present the +// item and its effects +typedef struct { + qboolean registered; + qhandle_t models[MAX_ITEM_MODELS]; + qhandle_t icons[MAX_ITEM_ICONS]; +} itemInfo_t; + + +typedef struct { + int itemNum; +} powerupInfo_t; + +#define MAX_VIEWDAMAGE 8 +typedef struct { + int damageTime, damageDuration; + float damageX, damageY, damageValue; +} viewDamage_t; + +#define MAX_CAMERA_SHAKE 4 +typedef struct { + int time; + float scale; + float length; + float radius; + vec3_t src; +} cameraShake_t; + +//====================================================================== + +// all cg.stepTime, cg.duckTime, cg.landTime, etc are set to cg.time when the action +// occurs, and they will have visible effects for #define STEP_TIME or whatever msec after + +#define MAX_PREDICTED_EVENTS 16 + +typedef struct { + int clientFrame; // incremented each frame + + int clientNum; + + qboolean demoPlayback; + qboolean levelShot; // taking a level menu screenshot + int deferredPlayerLoading; + qboolean loading; // don't defer players at initial startup + qboolean intermissionStarted; // don't play voice rewards, because game will end shortly + + // there are only one or two snapshot_t that are relevent at a time + int latestSnapshotNum; // the number of snapshots the client system has received + int latestSnapshotTime; // the time from latestSnapshotNum, so we don't need to read the snapshot yet + + snapshot_t *snap; // cg.snap->serverTime <= cg.time + snapshot_t *nextSnap; // cg.nextSnap->serverTime > cg.time, or NULL + snapshot_t activeSnapshots[2]; + + float frameInterpolation; // (float)( cg.time - cg.frame->serverTime ) / (cg.nextFrame->serverTime - cg.frame->serverTime) + + qboolean thisFrameTeleport; + qboolean nextFrameTeleport; + + int frametime; // cg.time - cg.oldTime + + int time; // this is the time value that the client + // is rendering at. + int oldTime; // time at last frame, used for missile trails and prediction checking + + int physicsTime; // either cg.snap->time or cg.nextSnap->time + + int timelimitWarnings; // 5 min, 1 min, overtime + int fraglimitWarnings; + + qboolean mapRestart; // set on a map restart to set back the weapon + + qboolean renderingThirdPerson; // during deaths, chasecams, etc + + // prediction state + qboolean hyperspace; // true if prediction has hit a trigger_teleport + playerState_t predictedPlayerState; + centity_t predictedPlayerEntity; + qboolean validPPS; // clear until the first call to CG_PredictPlayerState + int predictedErrorTime; + vec3_t predictedError; + + int eventSequence; + int predictableEvents[MAX_PREDICTED_EVENTS]; + + float stepChange; // for stair up smoothing + int stepTime; + + float duckChange; // for duck viewheight smoothing + int duckTime; + + float landChange; // for landing hard + int landTime; + + // input state sent to server + int weaponSelect; + int holdableSelect; // (SA) which holdable item is currently held ("selected"). When the client is ready to use it, send "use item " + + // auto rotating items + vec3_t autoAnglesSlow; + vec3_t autoAxisSlow[3]; + vec3_t autoAngles; + vec3_t autoAxis[3]; + vec3_t autoAnglesFast; + vec3_t autoAxisFast[3]; + + // view rendering + refdef_t refdef; + vec3_t refdefViewAngles; // will be converted to refdef.viewaxis + + // zoom key + qboolean zoomed; + qboolean zoomedBinoc; + int zoomedScope; //----(SA) changed to int + int zoomTime; + float zoomSensitivity; + float zoomval; + + + // information screen text during loading + /*unsigned*/ char infoScreenText[MAX_STRING_CHARS]; /*SEB*/ + + // scoreboard + int scoresRequestTime; + int numScores; + int selectedScore; + int teamScores[2]; + score_t scores[MAX_CLIENTS]; + qboolean showScores; + qboolean scoreBoardShowing; + int scoreFadeTime; + char killerName[MAX_NAME_LENGTH]; + char spectatorList[MAX_STRING_CHARS]; // list of names + int spectatorLen; // length of list + float spectatorWidth; // width in device units + int spectatorTime; // next time to offset + int spectatorPaintX; // current paint x + int spectatorPaintX2; // current paint x + int spectatorOffset; // current offset from start + int spectatorPaintLen; // current offset from start + + qboolean showItems; + int itemFadeTime; + + qboolean lightstylesInited; + + // centerprinting + int centerPrintTime; + int centerPrintCharWidth; + int centerPrintY; + /*unsigned*/ char centerPrint[1024]; /*SEB*/ + int centerPrintLines; + + // fade in/out + int fadeTime; + float fadeRate; + vec4_t fadeColor1; + vec4_t fadeColor2; + +//----(SA) added + // game stats + int exitStatsTime; + int exitStatsFade; + // just a copy of what's on the server, updated by configstring. better way to communicate/store this I'm sure + int playTimeH; + int playTimeM; + int playTimeS; + int attempts; + int numObjectives; + int numObjectivesFound; + int numSecrets; + int numSecretsFound; + int numTreasure; + int numTreasureFound; + int numArtifacts; + int numArtifactsFound; +//----(SA) end + + + // low ammo warning state + int lowAmmoWarning; // 1 = low, 2 = empty + + // kill timers for carnage reward + int lastKillTime; + + // crosshair client ID + int crosshairClientNum; + int crosshairClientTime; + + int crosshairPowerupNum; + int crosshairPowerupTime; + +//----(SA) added + // cursorhints + int cursorHintIcon; + int cursorHintTime; + int cursorHintFade; + int cursorHintValue; + +//----(SA) end + + // powerup active flashing + int powerupActive; + int powerupTime; + + // attacking player + int attackerTime; + int voiceTime; + + // reward medals + int rewardTime; + int rewardCount; + qhandle_t rewardShader; + + // warmup countdown + int warmup; + int warmupCount; + + // message icon popup time //----(SA) added + int yougotmailTime; + + //========================== + + int itemPickup; + int itemPickupTime; + int itemPickupBlendTime; // the pulse around the crosshair is timed seperately + + int holdableSelectTime; //----(SA) for holdable item icon drawing + + int weaponSelectTime; + int weaponAnimation; + int weaponAnimationTime; + + // blend blobs + viewDamage_t viewDamage[MAX_VIEWDAMAGE]; + float damageTime; // last time any kind of damage was recieved + int damageIndex; // slot that was filled in + float damageX, damageY, damageValue; + float viewFade; + + int grenLastTime; + + int switchbackWeapon; + int lastFiredWeapon; + int lastWeapSelInBank[MAX_WEAP_BANKS]; // remember which weapon was last selected in a bank for 'weaponbank' commands //----(SA) added +// JPW FIXME NOTE: max_weap_banks > max_weap_banks_mp so this should be OK, but if that changes, change this too + + // status bar head + float headYaw; + float headEndPitch; + float headEndYaw; + int headEndTime; + float headStartPitch; + float headStartYaw; + int headStartTime; + + // view movement + float v_dmg_time; + float v_dmg_pitch; + float v_dmg_roll; + + vec3_t kick_angles; // weapon kicks + vec3_t kick_origin; + + // RF, view flames when getting burnt + int v_fireTime, v_noFireTime; + vec3_t v_fireRiseDir; + + // temp working variables for player view + float bobfracsin; + int bobcycle; + float xyspeed; + int nextOrbitTime; + + // development tool + refEntity_t testModelEntity; + char testModelName[MAX_QPATH]; + qboolean testGun; + + // RF, new kick angles + vec3_t kickAVel; // for damage feedback, weapon recoil, etc + // This is the angular velocity, to give a smooth + // rotational feedback, rather than sudden jerks + vec3_t kickAngles; // for damage feedback, weapon recoil, etc + // NOTE: this is not transmitted through MSG.C stream + // since weapon kicks are client-side, and damage feedback + // is rare enough that we can transmit that as an event + float recoilPitch, recoilPitchAngle; + + // Duffy + qboolean cameraMode; // if rendering from a camera + // Duffy end + + unsigned int cld; // NERVE - SMF + qboolean limboMenu; // NERVE - SMF + + // NERVE - SMF - Objective info display + int oidTeam; + int oidPrintTime; + int oidPrintCharWidth; + int oidPrintY; + char oidPrint[1024]; + int oidPrintLines; + // -NERVE - SMF + + cameraShake_t cameraShake[MAX_CAMERA_SHAKE]; + float cameraShakePhase; + vec3_t cameraShakeAngles; + + float rumbleScale; //RUMBLE FX using new shakeCamera code + + #ifdef AUTOAIM + int lastFireTime; + int crossHairStatus; + #endif + +} cg_t; + +#define NUM_FUNNEL_SPRITES 21 +#define MAX_LOCKER_DEBRIS 5 + +// all of the model, shader, and sound references that are +// loaded at gamestate time are stored in cgMedia_t +// Other media that can be tied to clients, weapons, or items are +// stored in the clientInfo_t, itemInfo_t, weaponInfo_t, and powerupInfo_t +typedef struct { + qhandle_t charsetShader; + // JOSEPH 4-17-00 + qhandle_t menucharsetShader; + // END JOSEPH + qhandle_t charsetProp; + qhandle_t charsetPropGlow; + qhandle_t charsetPropB; + qhandle_t whiteShader; + + qhandle_t redFlagModel; + qhandle_t blueFlagModel; + + qhandle_t armorModel; + + qhandle_t teamStatusBar; + + qhandle_t deferShader; + + // gib explosions + qhandle_t gibAbdomen; + qhandle_t gibArm; + qhandle_t gibChest; + qhandle_t gibFist; + qhandle_t gibFoot; + qhandle_t gibForearm; + qhandle_t gibIntestine; + qhandle_t gibLeg; + qhandle_t gibSkull; + qhandle_t gibBrain; + + // debris + qhandle_t debBlock[6]; + qhandle_t debRock[3]; + qhandle_t debFabric[3]; + qhandle_t debWood[6]; + + qhandle_t targetEffectExplosionShader; + + qhandle_t machinegunBrassModel; + qhandle_t panzerfaustBrassModel; //----(SA) added + + // Rafael + qhandle_t smallgunBrassModel; + + qhandle_t shotgunBrassModel; + + qhandle_t railRingsShader; + qhandle_t railCoreShader; + + qhandle_t lightningShader; + + qhandle_t friendShader; + +// qhandle_t medicReviveShader; //----(SA) commented out from MP + qhandle_t balloonShader; + qhandle_t connectionShader; + + qhandle_t aiStateShaders[MAX_AISTATES]; + + qhandle_t selectShader; + qhandle_t viewBloodShader; + qhandle_t tracerShader; + qhandle_t crosshairShader[NUM_CROSSHAIRS]; + qhandle_t crosshairFriendly; //----(SA) added + qhandle_t lagometerShader; + qhandle_t backTileShader; + qhandle_t noammoShader; + + qhandle_t reticleShader; +// qhandle_t reticleShaderSimple; + qhandle_t reticleShaderSimpleQ; +// qhandle_t snooperShader; + qhandle_t snooperShaderSimple; +// qhandle_t binocShaderSimple; + qhandle_t binocShaderSimpleQ; // same as above, but quartered. (trying to save texture space) + + qhandle_t smokePuffShader; + qhandle_t smokePuffRageProShader; + qhandle_t shotgunSmokePuffShader; + qhandle_t waterBubbleShader; + qhandle_t bloodTrailShader; + + qhandle_t nailPuffShader; + +//----(SA) modified + + // cursor hints + // would be nice to specify these in the menu scripts instead of permanent handles... + qhandle_t hintShaders[HINT_NUM_HINTS]; + + qhandle_t youGotMailShader; // '!' - new entry in notebook + qhandle_t youGotObjectiveShader; // ' - you completed objective +//----(SA) end + + // Rafael + qhandle_t snowShader; + qhandle_t oilParticle; + qhandle_t oilSlick; + // done. + + // Rafael - cannon + qhandle_t smokePuffShaderdirty; + qhandle_t smokePuffShaderb1; + qhandle_t smokePuffShaderb2; + qhandle_t smokePuffShaderb3; + qhandle_t smokePuffShaderb4; + qhandle_t smokePuffShaderb5; + // done + + // Rafael - blood pool + qhandle_t bloodPool; + + // Ridah, viewscreen blood animation + qhandle_t viewBloodAni[5]; + qhandle_t viewFlashBlood; + qhandle_t viewFlashFire[16]; + // done + + // Rafael bats + qhandle_t bats[10]; + // done + + // Rafael shards + qhandle_t shardGlass1; + qhandle_t shardGlass2; + qhandle_t shardWood1; + qhandle_t shardWood2; + qhandle_t shardMetal1; + qhandle_t shardMetal2; + qhandle_t shardCeramic1; + qhandle_t shardCeramic2; + // done + + qhandle_t shardRubble1; + qhandle_t shardRubble2; + qhandle_t shardRubble3; + + + qhandle_t shardJunk[MAX_LOCKER_DEBRIS]; + + qhandle_t numberShaders[11]; + + qhandle_t shadowMarkShader; + qhandle_t shadowFootShader; + qhandle_t shadowTorsoShader; + + qhandle_t botSkillShaders[5]; + + // wall mark shaders + qhandle_t wakeMarkShader; + qhandle_t wakeMarkShaderAnim; + qhandle_t bloodMarkShaders[5]; + qhandle_t bloodDotShaders[5]; + qhandle_t bulletMarkShader; + qhandle_t bulletMarkShaderMetal; + qhandle_t bulletMarkShaderWood; + qhandle_t bulletMarkShaderCeramic; + qhandle_t bulletMarkShaderGlass; + qhandle_t burnMarkShader; + qhandle_t holeMarkShader; + qhandle_t energyMarkShader; + + // powerup shaders + qhandle_t quadShader; + qhandle_t redQuadShader; + qhandle_t quadWeaponShader; + qhandle_t invisShader; + qhandle_t regenShader; + qhandle_t battleSuitShader; + qhandle_t battleWeaponShader; + qhandle_t hastePuffShader; + + // weapon effect models + qhandle_t spearModel; //----(SA) + + qhandle_t bulletFlashModel; + qhandle_t ringFlashModel; + qhandle_t dishFlashModel; + qhandle_t lightningExplosionModel; + + qhandle_t zombieLoogie; + qhandle_t flamebarrel; + qhandle_t mg42muzzleflash; + //qhandle_t mg42muzzleflashgg; + qhandle_t planemuzzleflash; + + // Rafael + qhandle_t crowbar; + + qhandle_t waterSplashModel; + qhandle_t waterSplashShader; + + qhandle_t thirdPersonBinocModel; //----(SA) added + qhandle_t cigModel; //----(SA) added + + qhandle_t batModel; + qhandle_t spiritSkullModel; + qhandle_t helgaGhostModel; + + // weapon effect shaders + qhandle_t railExplosionShader; + qhandle_t bulletExplosionShader; + qhandle_t rocketExplosionShader; + qhandle_t grenadeExplosionShader; + qhandle_t bfgExplosionShader; + qhandle_t bloodExplosionShader; + + qhandle_t flameThrowerhitShader; + + // special effects models + qhandle_t teleportEffectModel; + qhandle_t teleportEffectShader; + + // scoreboard headers + qhandle_t scoreboardName; + qhandle_t scoreboardPing; + qhandle_t scoreboardScore; + qhandle_t scoreboardTime; + // Ridah + qhandle_t bloodCloudShader; + qhandle_t sparkParticleShader; + qhandle_t smokeTrailShader; + qhandle_t fireTrailShader; + qhandle_t lightningBoltShader; + qhandle_t lightningBoltShaderGreen; + qhandle_t flamethrowerFireStream; + qhandle_t flamethrowerBlueStream; + qhandle_t flamethrowerFuelStream; + qhandle_t flamethrowerFuelShader; + qhandle_t onFireShader, onFireShader2; + //qhandle_t dripWetShader, dripWetShader2; + qhandle_t viewFadeBlack; + qhandle_t sparkFlareShader; + qhandle_t funnelFireShader[NUM_FUNNEL_SPRITES]; + + qhandle_t spotLightShader; + qhandle_t spotLightBeamShader; + qhandle_t spotLightBaseModel; //----(SA) added + qhandle_t spotLightLightModel; //----(SA) added + qhandle_t spotLightLightModelBroke; //----(SA) added + + qhandle_t lightningHitWallShader; + qhandle_t lightningWaveShader; + qhandle_t bulletParticleTrailShader; + qhandle_t smokeParticleShader; + + // DHM - Nerve :: bullet hitting dirt + qhandle_t dirtParticle1Shader; + qhandle_t dirtParticle2Shader; + qhandle_t dirtParticle3Shader; + + qhandle_t zombieSpiritWallShader; + qhandle_t zombieSpiritTrailShader; + qhandle_t zombieSpiritSkullShader; + qhandle_t zombieDeathDustShader; + qhandle_t zombieBodyFadeShader; + qhandle_t zombieHeadFadeShader; + + qhandle_t helgaSpiritSkullShader; + qhandle_t helgaSpiritTrailShader; + + qhandle_t ssSpiritSkullModel; + + qhandle_t skeletonSkinShader; + qhandle_t skeletonLegsModel; + qhandle_t skeletonTorsoModel; + qhandle_t skeletonHeadModel; + qhandle_t skeletonLegsSkin; + qhandle_t skeletonTorsoSkin; + qhandle_t skeletonHeadSkin; + + qhandle_t loperGroundChargeShader; + + qhandle_t teslaDamageEffectShader; + qhandle_t teslaAltDamageEffectShader; + qhandle_t viewTeslaDamageEffectShader; + qhandle_t viewTeslaAltDamageEffectShader; + // done. + +//----(SA) + // proto/super/heini armor parts + qhandle_t protoArmor[9 * 3]; // 9 parts, 3 sections each (nodam, dam1, dam2) + qhandle_t superArmor[16 * 3]; // 14 parts, 3 sections each + qhandle_t heinrichArmor[22 * 3]; // 20 parts, 3 sections each +//----(SA) end + + // medals shown during gameplay + qhandle_t medalImpressive; + qhandle_t medalExcellent; + qhandle_t medalGauntlet; + + // sounds + sfxHandle_t n_health; + sfxHandle_t noFireUnderwater; + sfxHandle_t snipersound; + sfxHandle_t quadSound; + sfxHandle_t tracerSound; + sfxHandle_t selectSound; + sfxHandle_t useNothingSound; + sfxHandle_t wearOffSound; + sfxHandle_t footsteps[FOOTSTEP_TOTAL][4]; + sfxHandle_t sfx_lghit1; + sfxHandle_t sfx_lghit2; + sfxHandle_t sfx_lghit3; + sfxHandle_t sfx_ric1; + sfxHandle_t sfx_ric2; + sfxHandle_t sfx_ric3; + sfxHandle_t sfx_railg; + sfxHandle_t sfx_rockexp; + sfxHandle_t sfx_dynamiteexp; + sfxHandle_t sfx_dynamiteexpDist; //----(SA) added + sfxHandle_t sfx_spearhit; + sfxHandle_t sfx_knifehit[5]; + sfxHandle_t sfx_bullet_metalhit[3]; + sfxHandle_t sfx_bullet_woodhit[3]; + sfxHandle_t sfx_bullet_roofhit[3]; + sfxHandle_t sfx_bullet_ceramichit[3]; + sfxHandle_t sfx_bullet_glasshit[3]; + sfxHandle_t gibSound; + sfxHandle_t gibBounce1Sound; + sfxHandle_t gibBounce2Sound; + sfxHandle_t gibBounce3Sound; + sfxHandle_t teleInSound; + sfxHandle_t teleOutSound; + sfxHandle_t noAmmoSound; + sfxHandle_t respawnSound; + sfxHandle_t talkSound; + sfxHandle_t landSound; + sfxHandle_t fallSound; + sfxHandle_t jumpPadSound; + + sfxHandle_t oneMinuteSound; + sfxHandle_t fiveMinuteSound; + sfxHandle_t suddenDeathSound; + + sfxHandle_t threeFragSound; + sfxHandle_t twoFragSound; + sfxHandle_t oneFragSound; + + sfxHandle_t hitSound; + sfxHandle_t hitTeamSound; + sfxHandle_t impressiveSound; + sfxHandle_t excellentSound; + sfxHandle_t deniedSound; + sfxHandle_t humiliationSound; + + sfxHandle_t takenLeadSound; + sfxHandle_t tiedLeadSound; + sfxHandle_t lostLeadSound; + + sfxHandle_t watrInSound; + sfxHandle_t watrOutSound; + sfxHandle_t watrUnSound; + +// sfxHandle_t flightSound; + sfxHandle_t underWaterSound; + sfxHandle_t medkitSound; + sfxHandle_t wineSound; + sfxHandle_t bookSound; //----(SA) added + sfxHandle_t staminaSound; //----(SA) added + sfxHandle_t elecSound; + sfxHandle_t fireSound; + sfxHandle_t waterSound; + + // teamplay sounds + sfxHandle_t redLeadsSound; + sfxHandle_t blueLeadsSound; + sfxHandle_t teamsTiedSound; + + // tournament sounds + sfxHandle_t count3Sound; + sfxHandle_t count2Sound; + sfxHandle_t count1Sound; + sfxHandle_t countFightSound; + sfxHandle_t countPrepareSound; + + //----(SA) added + sfxHandle_t debBounce1Sound; + sfxHandle_t debBounce2Sound; + sfxHandle_t debBounce3Sound; + //----(SA) end + + //----(SA) added + sfxHandle_t grenadePulseSound4; + sfxHandle_t grenadePulseSound3; + sfxHandle_t grenadePulseSound2; + sfxHandle_t grenadePulseSound1; + //----(SA) + +//----(SA) added + sfxHandle_t sparkSounds[2]; +//----(SA) + + // Ridah + sfxHandle_t flameSound; + sfxHandle_t flameBlowSound; + sfxHandle_t flameStartSound; + sfxHandle_t flameStreamSound; + sfxHandle_t lightningSounds[3]; + sfxHandle_t lightningZap; + sfxHandle_t flameCrackSound; + sfxHandle_t boneBounceSound; + + sfxHandle_t zombieSpiritSound; + sfxHandle_t zombieSpiritLoopSound; + sfxHandle_t zombieDeathSound; + + sfxHandle_t helgaSpiritLoopSound; + sfxHandle_t helgaSpiritSound; + sfxHandle_t helgaGaspSound; + + sfxHandle_t heinrichArmorBreak; //----(SA) + sfxHandle_t protoArmorBreak; //----(SA) + sfxHandle_t superArmorBreak; //----(SA) + + + sfxHandle_t debrisHitSound; + + sfxHandle_t loperLightningSounds[3]; + sfxHandle_t loperLightningZap; + + sfxHandle_t lightningClap[5]; + + sfxHandle_t batsFlyingLoopSound; + +// sfxHandle_t grenadebounce1; +// sfxHandle_t grenadebounce2; + sfxHandle_t grenadebounce[GRENBOUNCE_TOTAL][2]; //----(SA) modified + + sfxHandle_t dynamitebounce1; //----(SA) added + + sfxHandle_t fbarrelexp1; + sfxHandle_t fbarrelexp2; + + sfxHandle_t fkickwall; + sfxHandle_t fkickflesh; + sfxHandle_t fkickmiss; + + int bulletHitFleshScript; + int bulletHitFleshMetalScript; + + int teslaZapScript; + sfxHandle_t teslaLoopSound; + // done. + + qhandle_t cursor; + qhandle_t selectCursor; + qhandle_t sizeCursor; + +} cgMedia_t; + + +// +// SOUND SCRIPTING +// + +typedef struct soundScriptSound_s +{ + char filename[MAX_QPATH]; + sfxHandle_t sfxHandle; + int lastPlayed; + + struct soundScriptSound_s *next; +} soundScriptSound_t; + + +#define MAX_SOUND_SCRIPT_SOUNDS 8192 +extern soundScriptSound_t soundScriptSounds[MAX_SOUND_SCRIPT_SOUNDS]; +//DAJ defined in cg_sound.c int numSoundScriptSounds; + + +typedef struct soundScript_s +{ + int index; + char name[MAX_QPATH]; + int channel; + int attenuation; + qboolean streaming; + qboolean looping; + float shakeScale; + float shakeRadius; + int shakeDuration; + qboolean random; // TODO + int numSounds; + soundScriptSound_t *soundList; // pointer into the global list of soundScriptSounds (defined below) + + struct soundScript_s *nextHash; // next soundScript in our hashTable list position +} soundScript_t; + +// we have to define these static lists, since we can't alloc memory within the cgame + +#define FILE_HASH_SIZE 1024 +extern soundScript_t* hashTable[FILE_HASH_SIZE]; + +#define MAX_SOUND_SCRIPTS 4096 +extern soundScript_t soundScripts[MAX_SOUND_SCRIPTS]; +//DAJ defined in cg_sound.c int numSoundScripts; + +extern soundScript_t soundScripts[MAX_SOUND_SCRIPTS]; + + + + + +// The client game static (cgs) structure hold everything +// loaded or calculated from the gamestate. It will NOT +// be cleared when a tournement restart is done, allowing +// all clients to begin playing instantly +typedef struct { + gameState_t gameState; // gamestate from server + glconfig_t glconfig; // rendering configuration + float screenXScale; // derived from glconfig + float screenYScale; + float screenXBias; + + int serverCommandSequence; // reliable command stream counter + int processedSnapshotNum; // the number of snapshots cgame has requested + + qboolean localServer; // detected on startup by checking sv_running + + // parsed from serverinfo + gametype_t gametype; + + // Rafael gameskill + gameskill_t gameskill; + // done + + int dmflags; + int teamflags; + int fraglimit; + int capturelimit; + int timelimit; + int maxclients; + char mapname[MAX_QPATH]; + char redTeam[MAX_QPATH]; // A team + char blueTeam[MAX_QPATH]; // B team + + int voteTime; + int voteYes; + int voteNo; + qboolean voteModified; // beep whenever changed + char voteString[MAX_STRING_TOKENS]; + + int teamVoteTime[2]; + int teamVoteYes[2]; + int teamVoteNo[2]; + qboolean teamVoteModified[2]; // beep whenever changed + char teamVoteString[2][MAX_STRING_TOKENS]; + + int levelStartTime; + + int scores1, scores2; // from configstrings + + // + // locally derived information from gamestate + // + qhandle_t gameModels[MAX_MODELS]; + + sfxHandle_t gameSounds[MAX_SOUNDS]; + int gameSoundTypes[MAX_SOUNDS]; //----(SA) added + + int numInlineModels; + qhandle_t inlineDrawModel[MAX_MODELS]; + vec3_t inlineModelMidpoints[MAX_MODELS]; + + clientInfo_t clientinfo[MAX_CLIENTS]; + + // teamchat width is *3 because of embedded color codes + char teamChatMsgs[TEAMCHAT_HEIGHT][TEAMCHAT_WIDTH * 3 + 1]; + int teamChatMsgTimes[TEAMCHAT_HEIGHT]; + int teamChatPos; + int teamLastChatPos; + + char itemPrintNames[MAX_ITEMS][32]; //----(SA) added + + int cursorX; + int cursorY; + qboolean eventHandling; + qboolean mouseCaptured; + qboolean sizingHud; + void *capturedItem; + qhandle_t activeCursor; + + // screen fading + //----(SA) modified just in name so global searching is easier to narrow down (added 'scrF') + float scrFadeAlpha, scrFadeAlphaCurrent; + int scrFadeStartTime; + int scrFadeDuration; + + // media + cgMedia_t media; + + // player/AI model scripting (client repository) + animScriptData_t animScriptData; + +} cgs_t; + +//============================================================================== + +extern cgs_t cgs; +extern cg_t cg; +extern centity_t cg_entities[MAX_GENTITIES]; +extern weaponInfo_t cg_weapons[MAX_WEAPONS]; +extern itemInfo_t cg_items[MAX_ITEMS]; +extern markPoly_t cg_markPolys[MAX_MARK_POLYS]; + +extern vmCvar_t cg_centertime; +extern vmCvar_t cg_runpitch; +extern vmCvar_t cg_runroll; +extern vmCvar_t cg_bobup; +extern vmCvar_t cg_bobpitch; +extern vmCvar_t cg_bobroll; +extern vmCvar_t cg_swingSpeed; +extern vmCvar_t cg_shadows; +extern vmCvar_t cg_gibs; +extern vmCvar_t cg_drawTimer; +extern vmCvar_t cg_drawFPS; +extern vmCvar_t cg_drawSnapshot; +extern vmCvar_t cg_draw3dIcons; +extern vmCvar_t cg_drawIcons; +extern vmCvar_t cg_youGotMail; //----(SA) added +extern vmCvar_t cg_drawAmmoWarning; +extern vmCvar_t cg_drawCrosshair; +extern vmCvar_t cg_drawCrosshairNames; +extern vmCvar_t cg_drawCrosshairPickups; +extern vmCvar_t cg_hudAlpha; +extern vmCvar_t cg_useWeapsForZoom; +extern vmCvar_t cg_weaponCycleDelay; //----(SA) added +extern vmCvar_t cg_cycleAllWeaps; +extern vmCvar_t cg_drawAllWeaps; +extern vmCvar_t cg_drawRewards; +extern vmCvar_t cg_drawTeamOverlay; +extern vmCvar_t cg_crosshairX; +extern vmCvar_t cg_crosshairY; +extern vmCvar_t cg_crosshairSize; +extern vmCvar_t cg_crosshairAlpha; //----(SA) added +extern vmCvar_t cg_crosshairHealth; +extern vmCvar_t cg_drawStatus; +extern vmCvar_t cg_draw2D; +extern vmCvar_t cg_drawFrags; +extern vmCvar_t cg_animSpeed; +extern vmCvar_t cg_debugAnim; +extern vmCvar_t cg_debugPosition; +extern vmCvar_t cg_debugEvents; +extern vmCvar_t cg_drawSpreadScale; +extern vmCvar_t cg_railTrailTime; +extern vmCvar_t cg_errorDecay; +extern vmCvar_t cg_nopredict; +extern vmCvar_t cg_noPlayerAnims; +extern vmCvar_t cg_showmiss; +extern vmCvar_t cg_footsteps; +extern vmCvar_t cg_markTime; +extern vmCvar_t cg_brassTime; +extern vmCvar_t cg_gun_frame; +extern vmCvar_t cg_gun_x; +extern vmCvar_t cg_gun_y; +extern vmCvar_t cg_gun_z; +extern vmCvar_t cg_drawGun; +extern vmCvar_t cg_drawFPGun; +extern vmCvar_t cg_drawGamemodels; +extern vmCvar_t cg_cursorHints; +extern vmCvar_t cg_hintFadeTime; //----(SA) added +extern vmCvar_t cg_viewsize; +extern vmCvar_t cg_letterbox; //----(SA) added +extern vmCvar_t cg_tracerChance; +extern vmCvar_t cg_tracerWidth; +extern vmCvar_t cg_tracerLength; +extern vmCvar_t cg_tracerSpeed; +extern vmCvar_t cg_autoswitch; +extern vmCvar_t cg_ignore; +extern vmCvar_t cg_simpleItems; +extern vmCvar_t cg_fov; +extern vmCvar_t cg_zoomFov; +extern vmCvar_t cg_zoomDefaultBinoc; +extern vmCvar_t cg_zoomDefaultSniper; +extern vmCvar_t cg_zoomDefaultFG; +extern vmCvar_t cg_zoomDefaultSnooper; +extern vmCvar_t cg_zoomStepBinoc; +extern vmCvar_t cg_zoomStepSniper; +extern vmCvar_t cg_zoomStepSnooper; +extern vmCvar_t cg_zoomStepFG; +extern vmCvar_t cg_reticles; +extern vmCvar_t cg_reticleBrightness; +extern vmCvar_t cg_thirdPersonRange; +extern vmCvar_t cg_thirdPersonAngle; +extern vmCvar_t cg_thirdPerson; +extern vmCvar_t cg_stereoSeparation; +extern vmCvar_t cg_lagometer; +extern vmCvar_t cg_drawAttacker; +extern vmCvar_t cg_synchronousClients; +extern vmCvar_t cg_teamChatTime; +extern vmCvar_t cg_teamChatHeight; +extern vmCvar_t cg_stats; +extern vmCvar_t cg_forceModel; +extern vmCvar_t cg_coronafardist; +extern vmCvar_t cg_coronas; +extern vmCvar_t cg_buildScript; +extern vmCvar_t cg_paused; +extern vmCvar_t cg_blood; +extern vmCvar_t cg_predictItems; +extern vmCvar_t cg_deferPlayers; +extern vmCvar_t cg_teamChatsOnly; +extern vmCvar_t cg_enableBreath; +extern vmCvar_t cg_autoactivate; +extern vmCvar_t cg_emptyswitch; +extern vmCvar_t cg_useSuggestedWeapons; //----(SA) added +extern vmCvar_t cg_particleDist; +extern vmCvar_t cg_particleLOD; +extern vmCvar_t cg_smoothClients; +extern vmCvar_t pmove_fixed; +extern vmCvar_t pmove_msec; + +extern vmCvar_t cg_cameraOrbit; +extern vmCvar_t cg_cameraOrbitDelay; +extern vmCvar_t cg_timescaleFadeEnd; +extern vmCvar_t cg_timescaleFadeSpeed; +extern vmCvar_t cg_timescale; +extern vmCvar_t cg_cameraMode; +extern vmCvar_t cg_smallFont; +extern vmCvar_t cg_bigFont; + +extern vmCvar_t cg_blinktime; //----(SA) added + +extern vmCvar_t cg_currentSelectedPlayer; +extern vmCvar_t cg_currentSelectedPlayerName; + +// Rafael - particle switch +extern vmCvar_t cg_wolfparticles; +// done + +// Ridah +extern vmCvar_t cg_gameType; +extern vmCvar_t cg_bloodTime; +extern vmCvar_t cg_norender; +extern vmCvar_t cg_skybox; + +// Rafael gameskill +extern vmCvar_t cg_gameSkill; +// done + +extern vmCvar_t cg_reloading; //----(SA) added + +// JPW NERVE +extern vmCvar_t cg_medicChargeTime; +extern vmCvar_t cg_engineerChargeTime; +extern vmCvar_t cg_LTChargeTime; +extern vmCvar_t cg_soldierChargeTime; +extern vmCvar_t cg_redlimbotime; +extern vmCvar_t cg_bluelimbotime; +// jpw + +extern vmCvar_t cg_hunkUsed; +extern vmCvar_t cg_soundAdjust; +extern vmCvar_t cg_expectedhunkusage; + +extern vmCvar_t cg_showAIState; + +extern vmCvar_t cg_notebook; +extern vmCvar_t cg_notebookpages; // bitflags for the currently accessable pages. if they wanna cheat, let 'em. Most won't, or will wait 'til they actually play it. + +extern vmCvar_t cg_animState; +extern vmCvar_t cg_missionStats; +extern vmCvar_t cg_waitForFire; + +extern vmCvar_t cg_loadWeaponSelect; + +// NERVE - SMF - Wolf multiplayer configuration cvars +extern vmCvar_t mp_playerType; +extern vmCvar_t mp_weapon; +extern vmCvar_t mp_item1; +extern vmCvar_t mp_item2; +extern vmCvar_t mp_mapDesc; +extern vmCvar_t mp_mapTitle; +// -NERVE - SMF + +// +// cg_main.c +// +const char *CG_ConfigString( int index ); +const char *CG_Argv( int arg ); + +void QDECL CG_Printf( const char *msg, ... ); +void QDECL CG_Error( const char *msg, ... ); + +void CG_StartMusic( void ); +void CG_QueueMusic( void ); //----(SA) added + +void CG_UpdateCvars( void ); + +int CG_CrosshairPlayer( void ); +int CG_LastAttacker( void ); +void CG_LoadMenus( const char *menuFile ); +void CG_KeyEvent( int key, qboolean down ); +void CG_MouseEvent( int x, int y ); +void CG_EventHandling( int type ); + +qboolean CG_GetTag( int clientNum, char *tagname, orientation_t * or ); +qboolean CG_GetWeaponTag( int clientNum, char *tagname, orientation_t * or ); + +// +// cg_view.c +// +void CG_TestModel_f( void ); +void CG_TestGun_f( void ); +void CG_TestModelNextFrame_f( void ); +void CG_TestModelPrevFrame_f( void ); +void CG_TestModelNextSkin_f( void ); +void CG_TestModelPrevSkin_f( void ); +void CG_ZoomDown_f( void ); +void CG_ZoomIn_f( void ); +void CG_ZoomOut_f( void ); +void CG_ZoomUp_f( void ); + +void CG_DrawActiveFrame( int serverTime, stereoFrame_t stereoView, qboolean demoPlayback ); + +void CG_Concussive( centity_t *cent ); +// +// cg_drawtools.c +// +void CG_AdjustFrom640( float *x, float *y, float *w, float *h ); +void CG_FillRect( float x, float y, float width, float height, const float *color ); +void CG_HorizontalPercentBar( float x, float y, float width, float height, float percent ); +void CG_DrawPic( float x, float y, float width, float height, qhandle_t hShader ); +void CG_FilledBar( float x, float y, float w, float h, const float *startColorIn, float *endColor, const float *bgColor, float frac, int flags ); +// JOSEPH 10-26-99 +void CG_DrawStretchPic( float x, float y, float width, float height, qhandle_t hShader ); +// END JOSEPH +void CG_DrawString( float x, float y, const char *string, + float charWidth, float charHeight, const float *modulate ); + + +void CG_DrawStringExt( int x, int y, const char *string, const float *setColor, + qboolean forceColor, qboolean shadow, int charWidth, int charHeight, int maxChars ); +// JOSEPH 4-17-00 +void CG_DrawStringExt2( int x, int y, const char *string, const float *setColor, + qboolean forceColor, qboolean shadow, int charWidth, int charHeight, int maxChars ); +// END JOSEPH +void CG_DrawBigString( int x, int y, const char *s, float alpha ); +void CG_DrawBigStringColor( int x, int y, const char *s, vec4_t color ); +void CG_DrawSmallString( int x, int y, const char *s, float alpha ); +void CG_DrawSmallStringColor( int x, int y, const char *s, vec4_t color ); +// JOSEPH 4-25-00 +void CG_DrawBigString2( int x, int y, const char *s, float alpha ); +void CG_DrawBigStringColor2( int x, int y, const char *s, vec4_t color ); +// END JOSEPH +int CG_DrawStrlen( const char *str ); + +float *CG_FadeColor( int startMsec, int totalMsec ); +float *CG_TeamColor( int team ); +void CG_TileClear( void ); +void CG_ColorForHealth( vec4_t hcolor ); +void CG_GetColorForHealth( int health, int armor, vec4_t hcolor ); + +void UI_DrawProportionalString( int x, int y, const char* str, int style, vec4_t color ); + +// new hud stuff +void CG_DrawRect( float x, float y, float width, float height, float size, const float *color ); +void CG_DrawSides( float x, float y, float w, float h, float size ); +void CG_DrawTopBottom( float x, float y, float w, float h, float size ); + + + +// +// cg_draw.c, cg_newDraw.c +// +extern int sortedTeamPlayers[TEAM_MAXOVERLAY]; +extern int numSortedTeamPlayers; +extern int drawTeamOverlayModificationCount; +extern char systemChat[256]; +extern char teamChat1[256]; +extern char teamChat2[256]; + +void CG_AddLagometerFrameInfo( void ); +void CG_AddLagometerSnapshotInfo( snapshot_t *snap ); +void CG_CenterPrint( const char *str, int y, int charWidth ); +void CG_ObjectivePrint( const char *str, int charWidth, int team ); // NERVE - SMF +void CG_DrawHead( float x, float y, float w, float h, int clientNum, vec3_t headAngles ); +void CG_DrawActive( stereoFrame_t stereoView ); +void CG_DrawFlagModel( float x, float y, float w, float h, int team ); + +void CG_DrawTeamBackground( int x, int y, int w, int h, float alpha, int team ); +void CG_OwnerDraw( float x, float y, float w, float h, float text_x, float text_y, int ownerDraw, int ownerDrawFlags, int align, float special, int font, float scale, vec4_t color, qhandle_t shader, int textStyle ); +void CG_Text_Paint( float x, float y, int font, float scale, vec4_t color, const char *text, float adjust, int limit, int style ); //----(SA) modified +int CG_Text_Width( const char *text, int font, float scale, int limit ); +int CG_Text_Height( const char *text, int font, float scale, int limit ); +void CG_SelectPrevPlayer(); +void CG_SelectNextPlayer(); +float CG_GetValue( int ownerDraw, int type ); // 'type' is relative or absolute (fractional-'0.5' or absolute- '50' health) +qboolean CG_OwnerDrawVisible( int flags ); +void CG_RunMenuScript( char **args ); +void CG_ShowResponseHead(); +void CG_SetPrintString( int type, const char *p ); +void CG_InitTeamChat(); +void CG_GetTeamColor( vec4_t *color ); +const char *CG_GetGameStatusText(); +const char *CG_GetKillerText(); +void CG_Draw3DModel( float x, float y, float w, float h, qhandle_t model, qhandle_t skin, vec3_t origin, vec3_t angles ); +void CG_Text_PaintChar( float x, float y, float width, float height, float scale, float s, float t, float s2, float t2, qhandle_t hShader ); +void CG_CheckOrderPending(); +const char *CG_GameTypeString(); +qboolean CG_YourTeamHasFlag(); +qboolean CG_OtherTeamHasFlag(); +qhandle_t CG_StatusHandle( int task ); +void CG_Fade( int r, int g, int b, int a, int time, int duration ); //----(SA) modified + +void CG_CalcShakeCamera(); +void CG_ApplyShakeCamera(); + + + +// +// cg_player.c +// +qboolean CG_EntOnFire( centity_t *cent ); // Ridah +void CG_Player( centity_t *cent ); +void CG_ResetPlayerEntity( centity_t *cent ); +void CG_AddRefEntityWithPowerups( refEntity_t *ent, int powerups, int team, entityState_t *es, const vec3_t fireRiseDir ); +void CG_NewClientInfo( int clientNum ); +sfxHandle_t CG_CustomSound( int clientNum, const char *soundName ); + +// Rafael particles +extern qboolean initparticles; +int CG_NewParticleArea( int num ); + +// +// cg_predict.c +// +void CG_BuildSolidList( void ); +int CG_PointContents( const vec3_t point, int passEntityNum ); +void CG_Trace( trace_t *result, const vec3_t start, const vec3_t mins, const vec3_t maxs, const vec3_t end, + int skipNumber, int mask ); +void CG_PredictPlayerState( void ); +void CG_LoadDeferredPlayers( void ); + + +// +// cg_events.c +// +void CG_CheckEvents( centity_t *cent ); +const char *CG_PlaceString( int rank ); +void CG_EntityEvent( centity_t *cent, vec3_t position ); +void CG_PainEvent( centity_t *cent, int health, qboolean crouching ); + + +// +// cg_ents.c +// +void CG_SetEntitySoundPosition( centity_t *cent ); +void CG_AddPacketEntities( void ); +void CG_Beam( centity_t *cent ); +void CG_AdjustPositionForMover( const vec3_t in, int moverNum, int fromTime, int toTime, vec3_t out, vec3_t outDeltaAngles ); + +void CG_PositionEntityOnTag( refEntity_t *entity, const refEntity_t *parent, + char *tagName, int startIndex, vec3_t *offset ); +void CG_PositionRotatedEntityOnTag( refEntity_t *entity, const refEntity_t *parent, char *tagName ); + + +//----(SA) +void CG_AttachedPartChange( centity_t *cent ); +void CG_NextItem_f( void ); +void CG_PrevItem_f( void ); +void CG_Item_f( void ); +//----(SA) end + + +// +// cg_weapons.c +// +void CG_LastWeaponUsed_f( void ); //----(SA) added +void CG_NextWeaponInBank_f( void ); //----(SA) added +void CG_PrevWeaponInBank_f( void ); //----(SA) added +void CG_AltWeapon_f( void ); +void CG_NextWeapon_f( void ); +void CG_PrevWeapon_f( void ); +void CG_Weapon_f( void ); +void CG_WeaponBank_f( void ); +void CG_WeaponSuggest( int weap ); + +void CG_FinishWeaponChange( int lastweap, int newweap ); + +void CG_RegisterWeapon( int weaponNum ); +void CG_RegisterItemVisuals( int itemNum ); + +void CG_FireWeapon( centity_t *cent ); //----(SA) modified. +//void CG_EndFireWeapon( centity_t *cent, int firemode ); //----(SA) added +void CG_MissileHitWall( int weapon, int clientNum, vec3_t origin, vec3_t dir, int surfaceFlags ); // (SA) modified to send missilehitwall surface parameters + +void CG_MissileHitWallSmall( int weapon, int clientNum, vec3_t origin, vec3_t dir ); +void CG_DrawTracer( vec3_t start, vec3_t finish ); + +// Rafael +void CG_MG42EFX( centity_t *cent ); + +void CG_FLAKEFX( centity_t *cent, int whichgun ); + +void CG_MortarEFX( centity_t *cent ); + +// Ridah +qboolean CG_MonsterUsingWeapon( centity_t *cent, int aiChar, int weaponNum ); + +// Rafael +void CG_MissileHitWall2( int weapon, int clientNum, vec3_t origin, vec3_t dir ); +// done + +void CG_MissileHitPlayer( centity_t *cent, int weapon, vec3_t origin, vec3_t dir, int entityNum ); +//----(SA) +void CG_VenomFire( entityState_t *es, qboolean fullmode ); +//----(SA) +void CG_Bullet( vec3_t origin, int sourceEntityNum, vec3_t normal, qboolean flesh, int fleshEntityNum, qboolean wolfkick, int otherEntNum2 ); + +void CG_RailTrail( clientInfo_t *ci, vec3_t start, vec3_t end, int type ); //----(SA) added 'type' +void CG_GrappleTrail( centity_t *ent, const weaponInfo_t *wi ); +void CG_AddViewWeapon( playerState_t *ps ); +void CG_AddPlayerWeapon( refEntity_t *parent, playerState_t *ps, centity_t *cent ); +void CG_DrawWeaponSelect( void ); +void CG_DrawHoldableSelect( void ); + +void CG_OutOfAmmoChange( void ); +void CG_HoldableUsedupChange( void ); //----(SA) added + +//----(SA) added to header to access from outside cg_weapons.c +void CG_AddDebris( vec3_t origin, vec3_t dir, int speed, int duration, int count ); +//----(SA) done + +void CG_ClientDamage( int entnum, int enemynum, int id ); + +void CG_AddBulletParticles( vec3_t origin, vec3_t dir, int speed, int duration, int count, float randScale ); + +// +// cg_marks.c +// +void CG_InitMarkPolys( void ); +void CG_AddMarks( void ); +void CG_ImpactMark( qhandle_t markShader, + const vec3_t origin, const vec3_t dir, + float orientation, + float r, float g, float b, float a, + qboolean alphaFade, + float radius, qboolean temporary, int duration ); + +// Rafael particles +// +// cg_particles.c +// +void CG_ClearParticles( void ); +void CG_AddParticles( void ); +void CG_ParticleSnow( qhandle_t pshader, vec3_t origin, vec3_t origin2, int turb, float range, int snum ); +void CG_ParticleSmoke( qhandle_t pshader, centity_t *cent ); +void CG_AddParticleShrapnel( localEntity_t *le ); +void CG_ParticleSnowFlurry( qhandle_t pshader, centity_t *cent ); +void CG_ParticleBulletDebris( vec3_t org, vec3_t vel, int duration ); +void CG_ParticleDirtBulletDebris( vec3_t org, vec3_t vel, int duration ); // DHM - Nerve +void CG_ParticleDirtBulletDebris_Core( vec3_t org, vec3_t vel, int duration, float width, float height, float alpha, char *shadername ); // NERVE - SMF // JPW addtnl params +void CG_ParticleSparks( vec3_t org, vec3_t vel, int duration, float x, float y, float speed ); +void CG_ParticleDust( centity_t *cent, vec3_t origin, vec3_t dir ); +void CG_ParticleMisc( qhandle_t pshader, vec3_t origin, int size, int duration, float alpha ); + +// Ridah +void CG_ParticleExplosion( char *animStr, vec3_t origin, vec3_t vel, int duration, int sizeStart, int sizeEnd ); + +// Rafael snow pvs check +void CG_SnowLink( centity_t *cent, qboolean particleOn ); +// done. + +// Rafael bats +void CG_ParticleBat( centity_t *cent ); +void CG_ParticleBats( qhandle_t pshader, centity_t *cent ); +void CG_BatsUpdatePosition( centity_t *cent ); +void CG_ParticleImpactSmokePuff( qhandle_t pshader, vec3_t origin ); +void CG_ParticleImpactSmokePuffExtended( qhandle_t pshader, vec3_t origin, vec3_t dir, int radius, int lifetime, int vel, int acc, int maxroll, float alpha ); // (SA) so I can add more parameters without screwing up the one that's there +void CG_Particle_Bleed( qhandle_t pshader, vec3_t start, vec3_t dir, int fleshEntityNum, int duration ); +void CG_GetBleedOrigin( vec3_t head_origin, vec3_t torso_origin, vec3_t legs_origin, int fleshEntityNum ); +void CG_Particle_OilParticle( qhandle_t pshader, vec3_t origin, vec3_t origin2, int ptime, int snum ); +void CG_Particle_OilSlick( qhandle_t pshader, centity_t *cent ); +void CG_OilSlickRemove( centity_t *cent ); +void CG_BloodPool( localEntity_t *le, qhandle_t pshader, trace_t *tr ); +void CG_ParticleBloodCloudZombie( centity_t *cent, vec3_t origin, vec3_t dir ); +void CG_ParticleBloodCloud( centity_t *cent, vec3_t origin, vec3_t dir ); +// done + +// Ridah, trails +// +// cg_trails.c +// +int CG_AddTrailJunc( int headJuncIndex, qhandle_t shader, int spawnTime, int sType, vec3_t pos, int trailLife, float alphaStart, float alphaEnd, float startWidth, float endWidth, int flags, vec3_t colorStart, vec3_t colorEnd, float sRatio, float animSpeed ); +int CG_AddSparkJunc( int headJuncIndex, qhandle_t shader, vec3_t pos, int trailLife, float alphaStart, float alphaEnd, float startWidth, float endWidth ); +int CG_AddSmokeJunc( int headJuncIndex, qhandle_t shader, vec3_t pos, int trailLife, float alpha, float startWidth, float endWidth ); +int CG_AddFireJunc( int headJuncIndex, qhandle_t shader, vec3_t pos, int trailLife, float alpha, float startWidth, float endWidth ); +void CG_AddTrails( void ); +void CG_ClearTrails( void ); +// done. + +// Ridah, sound scripting +int CG_SoundScriptPrecache( const char *name ); +qboolean CG_SoundPlaySoundScript( const char *name, vec3_t org, int entnum ); +void CG_SoundPlayIndexedScript( int index, vec3_t org, int entnum ); +void CG_SoundInit( void ); +// done. + +// Ridah, flamethrower +void CG_FireFlameChunks( centity_t *cent, vec3_t origin, vec3_t angles, float speedScale, qboolean firing, int flags ); //----(SA) added 'flags' +void CG_InitFlameChunks( void ); +void CG_AddFlameChunks( void ); +void CG_UpdateFlamethrowerSounds( void ); +void CG_FlameDamage( int owner, vec3_t org, float radius ); +// done. + +// +// cg_localents.c +// +void CG_InitLocalEntities( void ); +localEntity_t *CG_AllocLocalEntity( void ); +void CG_AddLocalEntities( void ); + +// +// cg_effects.c +// +int CG_GetOriginForTag( centity_t * cent, refEntity_t * parent, char *tagName, int startIndex, vec3_t org, vec3_t axis[3] ); +localEntity_t *CG_SmokePuff( const vec3_t p, + const vec3_t vel, + float radius, + float r, float g, float b, float a, + float duration, + int startTime, + int fadeInTime, + int leFlags, + qhandle_t hShader ); + +void CG_BubbleTrail( vec3_t start, vec3_t end, float size, float spacing ); +void CG_SpawnEffect( vec3_t org ); +void CG_GibPlayer( centity_t *cent, vec3_t playerOrigin, vec3_t gdir ); +void CG_LoseHat( centity_t *cent, vec3_t dir ); //----(SA) added +void CG_GibHead( vec3_t headOrigin ); + +void CG_Bleed( vec3_t origin, int entityNum ); + +localEntity_t *CG_MakeExplosion( vec3_t origin, vec3_t dir, + qhandle_t hModel, qhandle_t shader, int msec, + qboolean isSprite ); +// Ridah +void CG_DynamicLightningBolt( qhandle_t shader, vec3_t start, vec3_t pend, int numBolts, float maxWidth, qboolean fade, float startAlpha, int recursion, int randseed ); +void CG_SparklerSparks( vec3_t origin, int count ); +void CG_ClearFlameChunks( void ); +void CG_ProjectedSpotLight( vec3_t start, vec3_t dir ); +// done. + +//----(SA) +void CG_Spotlight( centity_t *cent, float *color, vec3_t start, vec3_t dir, int segs, float range, int startWidth, float coneAngle, int flags ); +#define SL_NOTRACE 0x001 // don't do a trace check for shortening the beam, always draw at full 'range' length +#define SL_NODLIGHT 0x002 // don't put a dlight at the end +#define SL_NOSTARTCAP 0x004 // dont' cap the start circle +#define SL_LOCKTRACETORANGE 0x010 // only trace out as far as the specified range (rather than to max spot range) +#define SL_NOFLARE 0x020 // don't draw a flare when the light is pointing at the camera +#define SL_NOIMPACT 0x040 // don't draw the impact mark +#define SL_LOCKUV 0x080 // lock the texture coordinates at the 'true' length of the requested beam. +#define SL_NOCORE 0x100 // don't draw the center 'core' beam +#define SL_TRACEWORLDONLY 0x200 +//----(SA) done + +void CG_RumbleEfx( float pitch, float yaw ); + +// +// cg_snapshot.c +// +void CG_ProcessSnapshots( void ); + +// +// cg_info.c +// +void CG_LoadingString( const char *s ); +void CG_LoadingItem( int itemNum ); +void CG_LoadingClient( int clientNum ); +void CG_DrawInformation( void ); +const char *CG_translateString( const char *str ); + +// +// cg_scoreboard.c +// +qboolean CG_DrawScoreboard( void ); +void CG_DrawTourneyScoreboard( void ); + +// +// cg_consolecmds.c +// +qboolean CG_ConsoleCommand( void ); +void CG_InitConsoleCommands( void ); + +// +// cg_servercmds.c +// +void CG_ExecuteNewServerCommands( int latestSequence ); +void CG_ParseServerinfo( void ); +void CG_SetConfigValues( void ); +void CG_ShaderStateChanged( void ); +void CG_SendMoveSpeed( animation_t *animList, int numAnims, char *modelName ); + +// +// cg_playerstate.c +// +void CG_Respawn( void ); +void CG_TransitionPlayerState( playerState_t *ps, playerState_t *ops ); +void CG_LoadClientInfo( clientInfo_t *ci ); + + +//=============================================== + +// +// system traps +// These functions are how the cgame communicates with the main game system +// + +// print message on the local console +void trap_Print( const char *fmt ); + +// abort the game +void trap_Error( const char *fmt ); + +// exit game to main menu (credits/etc) +void trap_Endgame( void ); //----(SA) added + +// milliseconds should only be used for performance tuning, never +// for anything game related. Get time from the CG_DrawActiveFrame parameter +int trap_Milliseconds( void ); + +// console variable interaction +void trap_Cvar_Register( vmCvar_t *vmCvar, const char *varName, const char *defaultValue, int flags ); +void trap_Cvar_Update( vmCvar_t *vmCvar ); +void trap_Cvar_Set( const char *var_name, const char *value ); +void trap_Cvar_VariableStringBuffer( const char *var_name, char *buffer, int bufsize ); + +// ServerCommand and ConsoleCommand parameter access +int trap_Argc( void ); +void trap_Argv( int n, char *buffer, int bufferLength ); +void trap_Args( char *buffer, int bufferLength ); + +// filesystem access +// returns length of file +int trap_FS_FOpenFile( const char *qpath, fileHandle_t *f, fsMode_t mode ); +void trap_FS_Read( void *buffer, int len, fileHandle_t f ); +void trap_FS_Write( const void *buffer, int len, fileHandle_t f ); +void trap_FS_FCloseFile( fileHandle_t f ); +void trap_FS_CopyFile( char *from, char *to ); //DAJ + +// add commands to the local console as if they were typed in +// for map changing, etc. The command is not executed immediately, +// but will be executed in order the next time console commands +// are processed +void trap_SendConsoleCommand( const char *text ); + +// register a command name so the console can perform command completion. +// FIXME: replace this with a normal console command "defineCommand"? +void trap_AddCommand( const char *cmdName ); + +// send a string to the server over the network +void trap_SendClientCommand( const char *s ); + +// force a screen update, only used during gamestate load +void trap_UpdateScreen( void ); + +// model collision +void trap_CM_LoadMap( const char *mapname ); +int trap_CM_NumInlineModels( void ); +clipHandle_t trap_CM_InlineModel( int index ); // 0 = world, 1+ = bmodels +clipHandle_t trap_CM_TempBoxModel( const vec3_t mins, const vec3_t maxs ); +clipHandle_t trap_CM_TempCapsuleModel( const vec3_t mins, const vec3_t maxs ); +int trap_CM_PointContents( const vec3_t p, clipHandle_t model ); +int trap_CM_TransformedPointContents( const vec3_t p, clipHandle_t model, const vec3_t origin, const vec3_t angles ); +void trap_CM_BoxTrace( trace_t *results, const vec3_t start, const vec3_t end, + const vec3_t mins, const vec3_t maxs, + clipHandle_t model, int brushmask ); +void trap_CM_TransformedBoxTrace( trace_t *results, const vec3_t start, const vec3_t end, + const vec3_t mins, const vec3_t maxs, + clipHandle_t model, int brushmask, + const vec3_t origin, const vec3_t angles ); + +void trap_CM_CapsuleTrace( trace_t *results, const vec3_t start, const vec3_t end, + const vec3_t mins, const vec3_t maxs, + clipHandle_t model, int brushmask ); +void trap_CM_TransformedCapsuleTrace( trace_t *results, const vec3_t start, const vec3_t end, + const vec3_t mins, const vec3_t maxs, + clipHandle_t model, int brushmask, + const vec3_t origin, const vec3_t angles ); + +// Returns the projection of a polygon onto the solid brushes in the world +int trap_CM_MarkFragments( int numPoints, const vec3_t *points, + const vec3_t projection, + int maxPoints, vec3_t pointBuffer, + int maxFragments, markFragment_t *fragmentBuffer ); + +// normal sounds will have their volume dynamically changed as their entity +// moves and the listener moves +void trap_S_StartSound( vec3_t origin, int entityNum, int entchannel, sfxHandle_t sfx ); +void trap_S_StartSoundEx( vec3_t origin, int entityNum, int entchannel, sfxHandle_t sfx, int flags ); +void trap_S_StopLoopingSound( int entnum ); + +void trap_S_StopStreamingSound( int entnum ); // usually AI. character is talking and needs to be shut up /now/ + +// a local sound is always played full volume +void trap_S_StartLocalSound( sfxHandle_t sfx, int channelNum ); +void trap_S_ClearLoopingSounds( qboolean killall ); +void trap_S_AddLoopingSound( int entityNum, const vec3_t origin, const vec3_t velocity, sfxHandle_t sfx, int volume ); +void trap_S_AddRangedLoopingSound( int entityNum, const vec3_t origin, const vec3_t velocity, sfxHandle_t sfx, int range ); +void trap_S_AddRealLoopingSound( int entityNum, const vec3_t origin, const vec3_t velocity, sfxHandle_t sfx ); +void trap_S_UpdateEntityPosition( int entityNum, const vec3_t origin ); + +// Ridah, talking animations +int trap_S_GetVoiceAmplitude( int entityNum ); +// done. + +// repatialize recalculates the volumes of sound as they should be heard by the +// given entityNum and position +void trap_S_Respatialize( int entityNum, const vec3_t origin, vec3_t axis[3], int inwater ); +sfxHandle_t trap_S_RegisterSound( const char *sample ); // returns buzz if not found +void trap_S_StartBackgroundTrack( const char *intro, const char *loop, int fadeupTime ); // empty name stops music +void trap_S_StopBackgroundTrack( void ); +void trap_S_FadeBackgroundTrack( float targetvol, int time, int sound ); //----(SA) added +void trap_S_StartStreamingSound( const char *intro, const char *loop, int entnum, int channel, int attenuation ); +void trap_S_FadeAllSound( float targetvol, int time ); //----(SA) added + +void trap_R_LoadWorldMap( const char *mapname ); + +// all media should be registered during level startup to prevent +// hitches during gameplay +qhandle_t trap_R_RegisterModel( const char *name ); // returns rgb axis if not found +qhandle_t trap_R_RegisterSkin( const char *name ); // returns all white if not found +qhandle_t trap_R_RegisterShader( const char *name ); // returns all white if not found +qhandle_t trap_R_RegisterShaderNoMip( const char *name ); // returns all white if not found + +qboolean trap_R_GetSkinModel( qhandle_t skinid, const char *type, char *name ); //----(SA) added +qhandle_t trap_R_GetShaderFromModel( qhandle_t modelid, int surfnum, int withlightmap ); //----(SA) added + +// a scene is built up by calls to R_ClearScene and the various R_Add functions. +// Nothing is drawn until R_RenderScene is called. +void trap_R_ClearScene( void ); +void trap_R_AddRefEntityToScene( const refEntity_t *re ); + +// polys are intended for simple wall marks, not really for doing +// significant construction +void trap_R_AddPolyToScene( qhandle_t hShader, int numVerts, const polyVert_t *verts ); +// Ridah +void trap_R_AddPolysToScene( qhandle_t hShader, int numVerts, const polyVert_t *verts, int numPolys ); +void trap_RB_ZombieFXAddNewHit( int entityNum, const vec3_t hitPos, const vec3_t hitDir ); +// done. +void trap_R_AddLightToScene( const vec3_t org, float intensity, float r, float g, float b, int overdraw ); +void trap_R_AddCoronaToScene( const vec3_t org, float r, float g, float b, float scale, int id, int flags ); //----(SA) modified +void trap_R_RenderScene( const refdef_t *fd ); +void trap_R_SetColor( const float *rgba ); // NULL = 1,1,1,1 +void trap_R_DrawStretchPic( float x, float y, float w, float h, + float s1, float t1, float s2, float t2, qhandle_t hShader ); +void trap_R_DrawStretchPicGradient( float x, float y, float w, float h, + float s1, float t1, float s2, float t2, qhandle_t hShader, const float *gradientColor, int gradientType ); + +void trap_R_ModelBounds( clipHandle_t model, vec3_t mins, vec3_t maxs ); +int trap_R_LerpTag( orientation_t *tag, const refEntity_t *refent, const char *tagName, int startIndex ); +void trap_R_RemapShader( const char *oldShader, const char *newShader, const char *timeOffset ); + +//----(SA) +void trap_R_SetFog( int fogvar, int var1, int var2, float r, float g, float b, float density ); + +//----(SA) + +// The glconfig_t will not change during the life of a cgame. +// If it needs to change, the entire cgame will be restarted, because +// all the qhandle_t are then invalid. +void trap_GetGlconfig( glconfig_t *glconfig ); + +// the gamestate should be grabbed at startup, and whenever a +// configstring changes +void trap_GetGameState( gameState_t *gamestate ); + +// cgame will poll each frame to see if a newer snapshot has arrived +// that it is interested in. The time is returned seperately so that +// snapshot latency can be calculated. +void trap_GetCurrentSnapshotNumber( int *snapshotNumber, int *serverTime ); + +// a snapshot get can fail if the snapshot (or the entties it holds) is so +// old that it has fallen out of the client system queue +qboolean trap_GetSnapshot( int snapshotNumber, snapshot_t *snapshot ); + +// retrieve a text command from the server stream +// the current snapshot will hold the number of the most recent command +// qfalse can be returned if the client system handled the command +// argc() / argv() can be used to examine the parameters of the command +qboolean trap_GetServerCommand( int serverCommandNumber ); + +// returns the most recent command number that can be passed to GetUserCmd +// this will always be at least one higher than the number in the current +// snapshot, and it may be quite a few higher if it is a fast computer on +// a lagged connection +int trap_GetCurrentCmdNumber( void ); + +qboolean trap_GetUserCmd( int cmdNumber, usercmd_t *ucmd ); + +// used for the weapon/holdable select and zoom +#ifdef AUTOAIM +void trap_SetUserCmdValue( int stateValue, int holdableValue, float sensitivityScale, int cld, int lastFire, int crossHairStatus ); +#else +void trap_SetUserCmdValue( int stateValue, int holdValue, float sensitivityScale, int cld ); // NERVE - SMF - added cld +#endif + +// aids for VM testing +void testPrintInt( char *string, int i ); +void testPrintFloat( char *string, float f ); + +int trap_MemoryRemaining( void ); +void trap_R_RegisterFont( const char *fontName, int pointSize, fontInfo_t *font ); +qboolean trap_Key_IsDown( int keynum ); +int trap_Key_GetCatcher( void ); +void trap_Key_SetCatcher( int catcher ); +int trap_Key_GetKey( const char *binding ); + +// RF +void trap_SendMoveSpeedsToGame( int entnum, char *movespeeds ); + +typedef enum { + SYSTEM_PRINT, + CHAT_PRINT, + TEAMCHAT_PRINT +} q3print_t; // bk001201 - warning: useless keyword or type name in empty declaration + +void trap_UI_Popup( const char *arg0 ); //----(SA) added +void trap_UI_ClosePopup( const char *arg0 ); // NERVE - SMF +void trap_UI_LimboChat( const char *arg0 ); // NERVE - SMF + +int trap_CIN_PlayCinematic( const char *arg0, int xpos, int ypos, int width, int height, int bits ); +e_status trap_CIN_StopCinematic( int handle ); +e_status trap_CIN_RunCinematic( int handle ); +void trap_CIN_DrawCinematic( int handle ); +void trap_CIN_SetExtents( int handle, int x, int y, int w, int h ); + +void trap_SnapVector( float *v ); + +qboolean trap_GetEntityToken( char *buffer, int bufferSize ); + +// Duffy, camera stuff +#define CAM_PRIMARY 0 // the main camera for cutscenes, etc. +qboolean trap_loadCamera( int camNum, const char *name ); +void trap_startCamera( int camNum, int time ); +void trap_stopCamera( int camNum ); //----(SA) added +qboolean trap_getCameraInfo( int camNum, int time, vec3_t *origin, vec3_t *angles, float *fov ); +void CG_StartCamera( const char *name, qboolean startBlack ); +void CG_StopCamera( void ); + +//----(SA) added +int CG_LoadCamera( const char *name ); +void CG_FreeCamera( int camNum ); +//----(SA) end + +void CG_StartShakeCamera( float p, int duration, vec3_t src, float radius ); + +qboolean trap_GetModelInfo( int clientNum, char *modelName, animModelInfo_t **modelInfo ); diff --git a/Projects/Android/jni/rtcw/src/cgame/cg_localents.c b/Projects/Android/jni/rtcw/src/cgame/cg_localents.c new file mode 100644 index 0000000..77ff886 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/cgame/cg_localents.c @@ -0,0 +1,1775 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +// cg_localents.c -- every frame, generate renderer commands for locally +// processed entities, like smoke puffs, gibs, shells, etc. + +#include "cg_local.h" + +// Ridah, increased this +//#define MAX_LOCAL_ENTITIES 512 +#define MAX_LOCAL_ENTITIES 768 // renderer can only handle 1024 entities max, so we should avoid + // overwriting game entities +// done. + +localEntity_t cg_localEntities[MAX_LOCAL_ENTITIES]; +localEntity_t cg_activeLocalEntities; // double linked list +localEntity_t *cg_freeLocalEntities; // single linked list + +// Ridah, debugging +int localEntCount = 0; + +/* +=================== +CG_InitLocalEntities + +This is called at startup and for tournement restarts +=================== +*/ +void CG_InitLocalEntities( void ) { + int i; + + memset( cg_localEntities, 0, sizeof( cg_localEntities ) ); + cg_activeLocalEntities.next = &cg_activeLocalEntities; + cg_activeLocalEntities.prev = &cg_activeLocalEntities; + cg_freeLocalEntities = cg_localEntities; + for ( i = 0 ; i < MAX_LOCAL_ENTITIES - 1 ; i++ ) { + cg_localEntities[i].next = &cg_localEntities[i + 1]; + } + + // Ridah, debugging + localEntCount = 0; +} + + +/* +================== +CG_FreeLocalEntity +================== +*/ +void CG_FreeLocalEntity( localEntity_t *le ) { + if ( !le->prev ) { + CG_Error( "CG_FreeLocalEntity: not active" ); + } + + // Ridah, debugging + localEntCount--; +// trap_Print( va("FreeLocalEntity: locelEntCount = %d\n", localEntCount) ); + // done. + + // remove from the doubly linked active list + le->prev->next = le->next; + le->next->prev = le->prev; + + // the free list is only singly linked + le->next = cg_freeLocalEntities; + cg_freeLocalEntities = le; +} + +/* +=================== +CG_AllocLocalEntity + +Will allways succeed, even if it requires freeing an old active entity +=================== +*/ +localEntity_t *CG_AllocLocalEntity( void ) { + localEntity_t *le; + + if ( !cg_freeLocalEntities ) { + // no free entities, so free the one at the end of the chain + // remove the oldest active entity + CG_FreeLocalEntity( cg_activeLocalEntities.prev ); + } + + // Ridah, debugging + localEntCount++; +// trap_Print( va("AllocLocalEntity: locelEntCount = %d\n", localEntCount) ); + // done. + + le = cg_freeLocalEntities; + cg_freeLocalEntities = cg_freeLocalEntities->next; + + memset( le, 0, sizeof( *le ) ); + + // link into the active list + le->next = cg_activeLocalEntities.next; + le->prev = &cg_activeLocalEntities; + cg_activeLocalEntities.next->prev = le; + cg_activeLocalEntities.next = le; + return le; +} + + +/* +==================================================================================== + +FRAGMENT PROCESSING + +A fragment localentity interacts with the environment in some way (hitting walls), +or generates more localentities along a trail. + +==================================================================================== +*/ + +/* +================ +CG_BloodTrail + +Leave expanding blood puffs behind gibs +================ +*/ +// use this to change between particle and trail code +//#define BLOOD_PARTICLE_TRAIL +void CG_BloodTrail( localEntity_t *le ) { + int t; + int t2; + int step; + vec3_t newOrigin; + +#ifndef BLOOD_PARTICLE_TRAIL + static vec3_t col = {1,1,1}; +#endif + + centity_t *cent; + cent = &cg_entities[le->ownerNum]; + + if ( !cg_blood.integer ) { + return; + } + + // step = 150; +#ifdef BLOOD_PARTICLE_TRAIL + step = 10; +#else + // time it takes to move 3 units + step = ( 1000 * 3 ) / VectorLength( le->pos.trDelta ); +#endif + + if ( cent && cent->currentState.aiChar == AICHAR_ZOMBIE ) { + step = 30; + } + + t = step * ( ( cg.time - cg.frametime + step ) / step ); + t2 = step * ( cg.time / step ); + + for ( ; t <= t2; t += step ) { + BG_EvaluateTrajectory( &le->pos, t, newOrigin ); + +#ifdef BLOOD_PARTICLE_TRAIL + CG_Particle_Bleed( cgs.media.smokePuffShader, newOrigin, vec3_origin, 0, 500 + rand() % 200 ); +#else + + + if ( cent && cent->currentState.aiChar == AICHAR_ZOMBIE ) { + CG_Particle_Bleed( cgs.media.smokePuffShader, newOrigin, vec3_origin, 1, 500 + rand() % 200 ); + } else { + // Ridah, blood trail using trail code (should be faster since we don't have to spawn as many) + le->headJuncIndex = CG_AddTrailJunc( le->headJuncIndex, + cgs.media.bloodTrailShader, + t, + STYPE_STRETCH, + newOrigin, + 180, + 1.0, // start alpha + 0.0, // end alpha + 12.0, + 12.0, + TJFL_NOCULL, + col, col, + 0, 0 ); + } +#endif + + } +} + + +/* +================ +CG_FragmentBounceMark +================ +*/ +void CG_FragmentBounceMark( localEntity_t *le, trace_t *trace ) { + int radius; + + if ( le->leMarkType == LEMT_BLOOD ) { + static int lastBloodMark; + + // don't drop too many blood marks + if ( !( lastBloodMark > cg.time || lastBloodMark > cg.time - 100 ) ) { + radius = 16 + ( rand() & 31 ); + CG_ImpactMark( cgs.media.bloodDotShaders[rand() % 5], trace->endpos, trace->plane.normal, random() * 360, + 1,1,1,1, qtrue, radius, qfalse, cg_bloodTime.integer * 1000 ); + + lastBloodMark = cg.time; + } + } + + // don't allow a fragment to make multiple marks, or they + // pile up while settling + le->leMarkType = LEMT_NONE; +} + +/* +================ +CG_FragmentBounceSound +================ +*/ +void CG_FragmentBounceSound( localEntity_t *le, trace_t *trace ) { + if ( le->leBounceSoundType == LEBS_BLOOD ) { + // half the gibs will make splat sounds + if ( rand() & 1 ) { + int r = rand() & 3; + sfxHandle_t s; + + if ( r < 2 ) { + s = cgs.media.gibBounce1Sound; + } else if ( r == 2 ) { + s = cgs.media.gibBounce2Sound; + } else { + s = cgs.media.gibBounce3Sound; + } + trap_S_StartSound( trace->endpos, ENTITYNUM_WORLD, CHAN_AUTO, s ); + } + } else if ( le->leBounceSoundType == LEBS_BRASS ) { + +//----(SA) added + } else if ( le->leBounceSoundType == LEBS_ROCK ) { + // half the hits will make thunk sounds (this is just to start since we don't even have the sound yet... (SA)) + if ( rand() & 1 ) { + int r = rand() & 3; + sfxHandle_t s; + + if ( r < 2 ) { + s = cgs.media.debBounce1Sound; + } else if ( r == 2 ) { + s = cgs.media.debBounce2Sound; + } else { + s = cgs.media.debBounce3Sound; + } + trap_S_StartSound( trace->endpos, ENTITYNUM_WORLD, CHAN_AUTO, s ); + } +//----(SA) end + + } else if ( le->leBounceSoundType == LEBS_BONE ) { + + trap_S_StartSound( trace->endpos, ENTITYNUM_WORLD, CHAN_AUTO, cgs.media.boneBounceSound ); + + } + + // don't allow a fragment to make multiple bounce sounds, + // or it gets too noisy as they settle + le->leBounceSoundType = LEBS_NONE; +} + + +/* +================ +CG_ReflectVelocity +================ +*/ +void CG_ReflectVelocity( localEntity_t *le, trace_t *trace ) { + vec3_t velocity; + float dot; + int hitTime; + + // reflect the velocity on the trace plane + hitTime = cg.time - cg.frametime + cg.frametime * trace->fraction; + BG_EvaluateTrajectoryDelta( &le->pos, hitTime, velocity ); + dot = DotProduct( velocity, trace->plane.normal ); + VectorMA( velocity, -2 * dot, trace->plane.normal, le->pos.trDelta ); + + VectorScale( le->pos.trDelta, le->bounceFactor, le->pos.trDelta ); + + VectorCopy( trace->endpos, le->pos.trBase ); + le->pos.trTime = cg.time; + + + // check for stop, making sure that even on low FPS systems it doesn't bobble + + if ( le->leMarkType == LEMT_BLOOD && trace->startsolid ) { + //centity_t *cent; + //cent = &cg_entities[trace->entityNum]; + //if (cent && cent->currentState.apos.trType != TR_STATIONARY) + // le->pos.trType = TR_STATIONARY; + } else if ( trace->allsolid || + ( trace->plane.normal[2] > 0 && + ( le->pos.trDelta[2] < 40 || le->pos.trDelta[2] < -cg.frametime * le->pos.trDelta[2] ) ) ) { + +//----(SA) if it's a fragment and it's not resting on the world... +// if(le->leType == LE_DEBRIS && trace->entityNum < (MAX_ENTITIES - 1)) + if ( le->leType == LE_FRAGMENT && trace->entityNum < ( MAX_ENTITIES - 1 ) ) { + le->pos.trType = TR_GRAVITY_PAUSED; + } else + { + le->pos.trType = TR_STATIONARY; + } + } else { + + } +} + + +//----(SA) added + +/* +============== +CG_AddEmitter +============== +*/ +void CG_AddEmitter( localEntity_t *le ) { + vec3_t dir; + int nextTime = 50; + + if ( le->breakCount > cg.time ) { // using 'breakCount' for 'wait' + return; + } + + if ( cg_paused.integer ) { // don't add while paused + return; + } + + // TODO: look up particle script and use proper effect rather than this check + //if(water){} + //else if(oil) {} + //else if(steam) {} + //else if(wine) {} + + switch ( le->headJuncIndex ) { +// CG_ParticleImpactSmokePuff (cgs.media.oilParticle, le->pos.trBase); +// CG_Particle_Bleed(cgs.media.smokePuffShader, le->pos.trBase, dir, 0, 200); + + case 1: // oil + VectorScale( le->angles.trBase, le->radius, dir ); + CG_Particle_OilParticle( cgs.media.oilParticle, le->pos.trBase, dir, 10000, le->ownerNum ); + break; + case 2: // water + VectorScale( le->angles.trBase, le->radius, dir ); + CG_Particle_OilParticle( cgs.media.oilParticle, le->pos.trBase, dir, 10000, le->ownerNum ); + break; + case 3: // steam + nextTime = 100; +// CG_ParticleImpactSmokePuffExtended(cgs.media.smokeParticleShader, le->pos.trBase, 8, 1000, 8, 20, 20, 0.25f); + CG_ParticleImpactSmokePuffExtended( cgs.media.smokeParticleShader, le->pos.trBase, le->angles.trBase, 8, 1000, 8, le->radius, 20, 0.25f ); + break; + case 4: // wine + VectorScale( le->angles.trBase, le->radius, dir ); + CG_Particle_OilParticle( cgs.media.oilParticle, le->pos.trBase, dir, 10000, le->ownerNum ); + break; + case 5: // smoke + nextTime = 100; + CG_ParticleImpactSmokePuffExtended( cgs.media.smokeParticleShader, le->pos.trBase, dir, 8, 1000, 8, 20, 20, 0.25f ); + break; + case 6: // electrical + nextTime = 100; + CG_AddBulletParticles( le->pos.trBase, dir, 2, 800, 4, 16.0f ); +// CG_AddBulletParticles( le->pos.trBase, dir, 1, 800, 4, 0 ); + break; + + case 0: + default: + nextTime = 100; + CG_ParticleImpactSmokePuffExtended( cgs.media.smokeParticleShader, le->pos.trBase, dir, 8, 1000, 8, 20, 20, 0.25f ); + break; + } + + le->breakCount = cg.time + nextTime; +} + +//----(SA) end + + +/* +================ +CG_AddFragment +================ +*/ +void CG_AddFragment( localEntity_t *le ) { + vec3_t newOrigin; + trace_t trace; + refEntity_t *re; + float flameAlpha = 0.0f; // TTimo: init + vec3_t flameDir; + qboolean hasFlame = qfalse; + int i; + int contents; + + // Ridah + re = &le->refEntity; + if ( !re->fadeStartTime || re->fadeEndTime < le->endTime ) { + if ( le->endTime - cg.time > 5000 ) { + re->fadeStartTime = le->endTime - 5000; + } else { + re->fadeStartTime = le->endTime - 1000; + } + re->fadeEndTime = le->endTime; + } + + // Ridah, flaming gibs + if ( le->onFireStart && ( le->onFireStart < cg.time && le->onFireEnd > cg.time ) ) { + hasFlame = qtrue; + // calc the alpha + flameAlpha = 1.0 - ( (float)( cg.time - le->onFireStart ) / (float)( le->onFireEnd - le->onFireStart ) ); + if ( flameAlpha < 0.0 ) { + flameAlpha = 0.0; + } + if ( flameAlpha > 1.0 ) { + flameAlpha = 1.0; + } + trap_S_AddLoopingSound( -1, le->refEntity.origin, vec3_origin, cgs.media.flameCrackSound, (int)( 5.0 * flameAlpha ) ); + } + +//----(SA) added + if ( le->leFlags & LEF_SMOKING ) { + float alpha; + refEntity_t flash; + + // create a little less smoke + + // TODO: FIXME: this is not quite right, because it'll become fps dependant - in a bad way. + // the slower the fps, the /more/ smoke there'll be, probably driving the fps lower. + if ( !cg_paused.integer ) { // don't add while paused + if ( !( rand() % 5 ) ) { + alpha = 1.0 - ( (float)( cg.time - le->startTime ) / (float)( le->endTime - le->startTime ) ); + alpha *= 0.25f; + memset( &flash, 0, sizeof( flash ) ); + CG_PositionEntityOnTag( &flash, &le->refEntity, "tag_flash", 0, NULL ); + CG_ParticleImpactSmokePuffExtended( cgs.media.smokeParticleShader, flash.origin, tv( 0,0,1 ), 8, 1000, 8, 20, 20, alpha ); + } + } + } +//----(SA) end + + if ( le->pos.trType == TR_STATIONARY ) { + int t; + + // Ridah, add the flame + if ( hasFlame ) { + refEntity_t backupEnt; + + backupEnt = le->refEntity; + + VectorClear( flameDir ); + flameDir[2] = 1; + + le->refEntity.shaderRGBA[3] = ( unsigned char )( 255.0 * flameAlpha ); + VectorCopy( flameDir, le->refEntity.fireRiseDir ); + le->refEntity.customShader = cgs.media.onFireShader; + trap_R_AddRefEntityToScene( &le->refEntity ); + le->refEntity.customShader = cgs.media.onFireShader2; + trap_R_AddRefEntityToScene( &le->refEntity ); + + le->refEntity = backupEnt; + } + + t = le->endTime - cg.time; + trap_R_AddRefEntityToScene( &le->refEntity ); + + return; + + } else if ( le->pos.trType == TR_GRAVITY_PAUSED ) { + int t; + + // Ridah, add the flame + if ( hasFlame ) { + refEntity_t backupEnt; + + backupEnt = le->refEntity; + + VectorClear( flameDir ); + flameDir[2] = 1; + + le->refEntity.shaderRGBA[3] = ( unsigned char )( 255.0 * flameAlpha ); + VectorCopy( flameDir, le->refEntity.fireRiseDir ); + le->refEntity.customShader = cgs.media.onFireShader; + trap_R_AddRefEntityToScene( &le->refEntity ); + le->refEntity.customShader = cgs.media.onFireShader2; + trap_R_AddRefEntityToScene( &le->refEntity ); + + le->refEntity = backupEnt; + } + + t = le->endTime - cg.time; + trap_R_AddRefEntityToScene( &le->refEntity ); + + + // trace a line from previous position down, to see if I should start falling again + + VectorCopy( le->refEntity.origin, newOrigin ); + newOrigin [2] -= 5; + CG_Trace( &trace, le->refEntity.origin, NULL, NULL, newOrigin, -1, CONTENTS_SOLID | CONTENTS_PLAYERCLIP | CONTENTS_MISSILECLIP ); + + if ( trace.fraction == 1.0 ) { // it's clear, start moving again + VectorClear( le->pos.trDelta ); + VectorClear( le->angles.trDelta ); + le->pos.trType = TR_GRAVITY; // nothing below me, start falling again + } else { + return; + } + } + + // calculate new position + BG_EvaluateTrajectory( &le->pos, cg.time, newOrigin ); + + if ( hasFlame ) { + // calc the flame dir + VectorSubtract( le->refEntity.origin, newOrigin, flameDir ); + if ( VectorLength( flameDir ) == 0 ) { + flameDir[2] = 1; + // play a burning sound when not moving + trap_S_AddLoopingSound( 0, newOrigin, vec3_origin, cgs.media.flameSound, (int)( 0.3 * 255.0 * flameAlpha ) ); + } else { + VectorNormalize( flameDir ); + // play a flame blow sound when moving + trap_S_AddLoopingSound( 0, newOrigin, vec3_origin, cgs.media.flameBlowSound, (int)( 0.3 * 255.0 * flameAlpha ) ); + } + } + + contents = CONTENTS_SOLID; + + // trace a line from previous position to new position + if ( ( le->leFlags & LEF_NOTOUCHPARENT ) && le->ownerNum ) { + CG_Trace( &trace, le->refEntity.origin, NULL, NULL, newOrigin, le->ownerNum, contents ); + } else { + CG_Trace( &trace, le->refEntity.origin, NULL, NULL, newOrigin, -1, contents ); + } + + // did we hit someone? + if ( le->leFlags & LEF_PLAYER_DAMAGE ) { + // only do damage if travelling at a fast enough velocity + if ( newOrigin[2] < le->refEntity.origin[2] ) { + vec3_t pmin, pmax, dmin = {-12,-12,-12}, dmax = {12,12,12}; + // debris bounds + VectorAdd( dmin, newOrigin, dmin ); + VectorAdd( dmax, newOrigin, dmax ); + dmax[2] += le->refEntity.origin[2] - newOrigin[2]; // add falling distance to box + // are we touching the player? + VectorAdd( cg.snap->ps.mins, cg.snap->ps.origin, pmin ); + VectorAdd( cg.snap->ps.maxs, cg.snap->ps.origin, pmax ); + pmin[2] = pmax[2] - 32; // only hit on the head + for ( i = 0; i < 3; i++ ) { + if ( ( dmax[i] < pmin[i] ) || ( dmin[i] > pmax[i] ) ) { + break; + } + } + if ( i == 3 ) { + trap_S_StartSound( cg.snap->ps.origin, cg.snap->ps.clientNum, CHAN_VOICE, cgs.media.debrisHitSound ); + CG_ClientDamage( cg.snap->ps.clientNum, ENTITYNUM_WORLD, CLDMG_DEBRIS ); + // disable damage now for this debris + le->leFlags &= ~LEF_PLAYER_DAMAGE; + } + } + } + + if ( trace.fraction == 1.0 ) { + + // still in free fall + VectorCopy( newOrigin, le->refEntity.origin ); + + if ( le->leFlags & LEF_TUMBLE || le->angles.trType == TR_LINEAR ) { + vec3_t angles; + + BG_EvaluateTrajectory( &le->angles, cg.time, angles ); + AnglesToAxis( angles, le->refEntity.axis ); + if ( le->sizeScale && le->sizeScale != 1.0 ) { + for ( i = 0; i < 3; i++ ) VectorScale( le->refEntity.axis[i], le->sizeScale, le->refEntity.axis[i] ); + } + } + + // Ridah, add the flame + if ( hasFlame ) { + refEntity_t backupEnt; + + backupEnt = le->refEntity; + + le->refEntity.shaderRGBA[3] = ( unsigned char )( 255.0 * flameAlpha ); + VectorCopy( flameDir, le->refEntity.fireRiseDir ); + le->refEntity.customShader = cgs.media.onFireShader; + trap_R_AddRefEntityToScene( &le->refEntity ); + le->refEntity.customShader = cgs.media.onFireShader2; + trap_R_AddRefEntityToScene( &le->refEntity ); + + le->refEntity = backupEnt; + } + + trap_R_AddRefEntityToScene( &le->refEntity ); + + // add a blood trail + if ( le->leBounceSoundType == LEBS_BLOOD ) { + CG_BloodTrail( le ); + } + + return; + } + + // if it is in a nodrop zone, remove it + // this keeps gibs from waiting at the bottom of pits of death + // and floating levels + if ( trap_CM_PointContents( trace.endpos, 0 ) & CONTENTS_NODROP ) { + CG_FreeLocalEntity( le ); + return; + } + + // do a bouncy sound + CG_FragmentBounceSound( le, &trace ); + + // reflect the velocity on the trace plane + CG_ReflectVelocity( le, &trace ); + + + // (SA) disabled since it caused debris to get stuck in walls (flags mostly) + // RF, if it has come to a halt, pause velocity +// if (VectorLength( le->pos.trDelta ) < 1) { +// le->pos.trType = TR_STATIONARY; +// VectorCopy( trace.endpos, le->pos.trBase ); +// VectorClear( le->pos.trDelta ); +// } + + // break on contact? + if ( le->breakCount ) { + clientInfo_t *ci; + int clientNum; + localEntity_t *nle; + vec3_t dir; + + clientNum = le->ownerNum; + if ( clientNum < 0 || clientNum >= MAX_CLIENTS ) { + CG_Error( "Bad clientNum on player entity" ); + } + ci = &cgs.clientinfo[ clientNum ]; + + // spawn some new fragments + for ( i = 0; i <= le->breakCount; i++ ) { + nle = CG_AllocLocalEntity(); + memcpy( &( nle->leType ), &( le->leType ), sizeof( localEntity_t ) - 2 * sizeof( localEntity_t * ) ); + if ( nle->breakCount-- < 2 ) { + nle->refEntity.hModel = ci->gibModels[rand() % 2]; + } else { + nle->refEntity.hModel = ci->gibModels[rand() % 4]; + } + // make it smaller + nle->endTime = le->endTime + ( cg.time - le->startTime ); + nle->sizeScale *= 0.8; + if ( nle->sizeScale < 0.7 ) { + nle->sizeScale = 0.7; + nle->leBounceSoundType = 0; + } + // move us a bit + VectorNormalize2( nle->pos.trDelta, dir ); + VectorMA( trace.endpos, 4.0 * le->sizeScale * i, dir, nle->pos.trBase ); + // randomize vel a bit + VectorMA( nle->pos.trDelta, VectorLength( nle->pos.trDelta ) * 0.3, bytedirs[rand() % NUMVERTEXNORMALS], nle->pos.trDelta ); + } + // we're done + CG_FreeLocalEntity( le ); + return; + } + + if ( le->pos.trType == TR_STATIONARY && le->leMarkType == LEMT_BLOOD ) { + // RF, disabled for performance reasons in boss1 + //if (le->leBounceSoundType) + // CG_BloodPool (le, cgs.media.bloodPool, &trace); + + // leave a mark + if ( le->leMarkType ) { + CG_FragmentBounceMark( le, &trace ); + } + } + + // Ridah, add the flame + if ( hasFlame ) { + refEntity_t backupEnt; + + backupEnt = le->refEntity; + + le->refEntity.shaderRGBA[3] = ( unsigned char )( 255.0 * flameAlpha ); + VectorCopy( flameDir, le->refEntity.fireRiseDir ); + le->refEntity.customShader = cgs.media.onFireShader; + trap_R_AddRefEntityToScene( &le->refEntity ); + le->refEntity.customShader = cgs.media.onFireShader2; + trap_R_AddRefEntityToScene( &le->refEntity ); + + le->refEntity = backupEnt; + } + + trap_R_AddRefEntityToScene( &le->refEntity ); +} + +// Ridah +/* +================ +CG_AddMovingTracer +================ +*/ +void CG_AddMovingTracer( localEntity_t *le ) { + vec3_t start, end, dir; + + BG_EvaluateTrajectory( &le->pos, cg.time, start ); + VectorNormalize2( le->pos.trDelta, dir ); + VectorMA( start, cg_tracerLength.value, dir, end ); + + CG_DrawTracer( start, end ); +} + +/* +================ +CG_AddSparkElements +================ +*/ +void CG_AddSparkElements( localEntity_t *le ) { + vec3_t newOrigin; + trace_t trace; + float time; + float lifeFrac; + + time = (float)( cg.time - cg.frametime ); + + while ( 1 ) { + // calculate new position + BG_EvaluateTrajectory( &le->pos, cg.time, newOrigin ); + +// if ((le->endTime - le->startTime) > 500) { + + // trace a line from previous position to new position + CG_Trace( &trace, le->refEntity.origin, NULL, NULL, newOrigin, -1, MASK_SHOT ); + + // if stuck, kill it + if ( trace.startsolid ) { + // HACK, some walls screw up, so just pass through if starting in a solid + VectorCopy( newOrigin, trace.endpos ); + trace.fraction = 1.0; + } + + // moved some distance + VectorCopy( trace.endpos, le->refEntity.origin ); +/* + } else + { // just move it there + + VectorCopy( newOrigin, le->refEntity.origin ); + trace.fraction = 1.0; + + } +*/ + time += cg.frametime * trace.fraction; + + lifeFrac = (float)( cg.time - le->startTime ) / (float)( le->endTime - le->startTime ); + + // add a trail + le->headJuncIndex = CG_AddSparkJunc( le->headJuncIndex, + le->refEntity.customShader, + le->refEntity.origin, + 200, + 1.0 - lifeFrac, // start alpha + 0.0, //1.0 - lifeFrac, // end alpha + lifeFrac * 2.0 * ( ( ( le->endTime - le->startTime ) > 400 ) + 1 ) * 1.5, + lifeFrac * 2.0 * ( ( ( le->endTime - le->startTime ) > 400 ) + 1 ) * 1.5 ); + + // if it is in a nodrop zone, remove it + // this keeps gibs from waiting at the bottom of pits of death + // and floating levels +// for some reason SFM1.BSP is one big NODROP zone +// if ( trap_CM_PointContents( le->refEntity.origin, 0 ) & CONTENTS_NODROP ) { +// CG_FreeLocalEntity( le ); +// return; +// } + + if ( trace.fraction < 1.0 ) { + // just kill it + CG_FreeLocalEntity( le ); + return; +/* + // reflect the velocity on the trace plane + CG_ReflectVelocity( le, &trace ); + // the intersection is a fraction of the frametime + le->pos.trTime = (int)time; +*/ + } + + if ( trace.fraction == 1.0 || time >= (float)cg.time ) { + return; + } + } + +} + +/* +================ +CG_AddFuseSparkElements +================ +*/ +void CG_AddFuseSparkElements( localEntity_t *le ) { + + float FUSE_SPARK_WIDTH = 1.0; + + int step = 10; + float time; + float lifeFrac; + static vec3_t whiteColor = {1,1,1}; + + time = (float)( le->lastTrailTime ); + + while ( time < cg.time ) { + + // calculate new position + BG_EvaluateTrajectory( &le->pos, time, le->refEntity.origin ); + + lifeFrac = (float)( time - le->startTime ) / (float)( le->endTime - le->startTime ); + + //if (lifeFrac > 0.2) { + // add a trail + le->headJuncIndex = CG_AddTrailJunc( le->headJuncIndex, cgs.media.sparkParticleShader, time, STYPE_STRETCH, le->refEntity.origin, (int)( lifeFrac * (float)( le->endTime - le->startTime ) / 2.0 ), + 1.0 /*(1.0 - lifeFrac)*/, 0.0, FUSE_SPARK_WIDTH * ( 1.0 - lifeFrac ), FUSE_SPARK_WIDTH * ( 1.0 - lifeFrac ), TJFL_SPARKHEADFLARE, whiteColor, whiteColor, 0, 0 ); + //} + + time += step; + + le->lastTrailTime = time; + } + +} + +/* +================ +CG_AddBloodElements +================ +*/ +void CG_AddBloodElements( localEntity_t *le ) { + vec3_t newOrigin; + trace_t trace; + float time; + float lifeFrac; + + time = (float)( cg.time - cg.frametime ); + + while ( 1 ) { + // calculate new position + BG_EvaluateTrajectory( &le->pos, cg.time, newOrigin ); + + // trace a line from previous position to new position + CG_Trace( &trace, le->refEntity.origin, NULL, NULL, newOrigin, -1, MASK_SHOT ); + + // if stuck, kill it + if ( trace.startsolid ) { + // HACK, some walls screw up, so just pass through if starting in a solid + VectorCopy( newOrigin, trace.endpos ); + trace.fraction = 1.0; + } + + // moved some distance + VectorCopy( trace.endpos, le->refEntity.origin ); + time += cg.frametime * trace.fraction; + + lifeFrac = (float)( cg.time - le->startTime ) / (float)( le->endTime - le->startTime ); + + // add a trail + le->headJuncIndex = CG_AddSparkJunc( le->headJuncIndex, + cgs.media.bloodTrailShader, + le->refEntity.origin, + 200, + 1.0 - lifeFrac, // start alpha + 1.0 - lifeFrac, // end alpha + 3.0, + 5.0 ); + + if ( trace.fraction < 1.0 ) { + // reflect the velocity on the trace plane + CG_ReflectVelocity( le, &trace ); + + // TODO: spawn a blood decal here? + + // the intersection is a fraction of the frametime + le->pos.trTime = (int)time; + } + + if ( trace.fraction == 1.0 || time >= (float)cg.time ) { + return; + } + } + +} + +/* +=================== +CG_AddSpiritViewflash +=================== +*/ +void CG_AddSpiritViewflash( localEntity_t *le ) { + float alpha; +#define SPIRIT_FLASH_FADEIN 50 +#define SPIRIT_FLASH_DURATION 400 +#define SPIRIT_FLASH_FADEOUT 2000 + + if ( cg.viewFade > 1.0 ) { + return; + } + + if ( cg.time < le->startTime + SPIRIT_FLASH_FADEIN ) { + alpha = (float)( cg.time - le->startTime ) / (float)SPIRIT_FLASH_FADEIN; + } else if ( cg.time < le->startTime + SPIRIT_FLASH_FADEIN + SPIRIT_FLASH_DURATION ) { + alpha = 1.0; + } else if ( cg.time < le->startTime + SPIRIT_FLASH_FADEIN + SPIRIT_FLASH_DURATION + SPIRIT_FLASH_FADEOUT ) { + alpha = 1.0 - (float)( cg.time - ( le->startTime + SPIRIT_FLASH_FADEIN + SPIRIT_FLASH_DURATION ) ) / (float)SPIRIT_FLASH_FADEOUT; + } else { + return; + } + + if ( alpha < 0 ) { + return; + } + + // only ever use the highest fade + if ( cg.viewFade < alpha ) { + cg.viewFade = alpha; + } +} + +/* +================ +CG_AddClientCritter +================ +*/ +void CG_AddClientCritter( localEntity_t *le ) { + vec3_t newOrigin; + trace_t trace; + int time, step = 25, i; + vec3_t v, ang, v2, oDelta; + localEntity_t backup; + float oldSpeed, enemyDist, of; + vec3_t enemyPos; + float alpha = 0.0f, fadeRatio; // TTimo: init + + if ( cg_entities[le->ownerNum].currentState.otherEntityNum2 == cg.snap->ps.clientNum ) { + VectorCopy( cg.snap->ps.origin, enemyPos ); + enemyPos[2] += cg.snap->ps.viewheight; + } else { + VectorCopy( cg_entities[le->ownerNum].currentState.origin2, enemyPos ); + } + + VectorCopy( le->pos.trDelta, oDelta ); + + // vary the enemyPos to create a psuedo-randomness + of = (float)cg.time + le->startTime; + enemyPos[0] += 12 * ( sin( of / 100 ) * cos( of / 78 ) ); + enemyPos[1] += 12 * ( sin( of / 70 ) * cos( of / 82 ) ); + enemyPos[2] += 12 * ( sin( of / 67 ) * cos( of / 98 ) ); + + time = le->lastTrailTime + step; + + fadeRatio = (float)( cg.time - le->startTime ) / 2000.0; + if ( fadeRatio < 0.0 ) { + fadeRatio = 0.0; + } + if ( fadeRatio > 1.0 ) { + fadeRatio = 1.0; + } + + while ( time <= cg.time ) { + if ( time > le->refEntity.fadeStartTime ) { + alpha = (float)( time - le->refEntity.fadeStartTime ) / (float)( le->refEntity.fadeEndTime - le->refEntity.fadeStartTime ); + if ( alpha < 0 ) { + alpha = 0; + } else if ( alpha > 1 ) { + alpha = 1; + } + } else { + alpha = fadeRatio; + } + + // calculate new position + BG_EvaluateTrajectory( &le->pos, time, newOrigin ); + + VectorSubtract( enemyPos, le->refEntity.origin, v ); + enemyDist = VectorNormalize( v ); + + // trace a line from previous position to new position + CG_Trace( &trace, le->refEntity.origin, NULL, NULL, newOrigin, le->ownerNum, MASK_SHOT ); + + // if stuck, kill it + if ( trace.startsolid || ( trace.fraction < 1.0 ) ) { + // let heinrich spirits pass through geometry + if ( !( le->leType == LE_HELGA_SPIRIT && ( le->refEntity.hModel == cgs.media.ssSpiritSkullModel ) ) ) { + // kill it + CG_FreeLocalEntity( le ); + return; + } else { + VectorCopy( newOrigin, trace.endpos ); + } + } + + // moved some distance + VectorCopy( trace.endpos, le->refEntity.origin ); + + // record this pos + le->validOldPos[le->oldPosHead] = 1; + VectorCopy( le->refEntity.origin, le->oldPos[le->oldPosHead] ); + if ( ++le->oldPosHead >= MAX_OLD_POS ) { + le->oldPosHead = 0; + } + + if ( le->leType == LE_ZOMBIE_SPIRIT ) { + le->headJuncIndex = CG_AddTrailJunc( le->headJuncIndex, + cgs.media.zombieSpiritTrailShader, + time, + STYPE_STRETCH, + le->refEntity.origin, + (int)le->effectWidth, // trail life + 0.3 * alpha, + 0.0, + le->radius, + 0, + 0, //TJFL_FIXDISTORT, + colorWhite, + colorWhite, + 1.0, 1 ); + } + + if ( le->leType == LE_HELGA_SPIRIT && le->refEntity.hModel != cgs.media.ssSpiritSkullModel ) { + le->headJuncIndex = CG_AddTrailJunc( le->headJuncIndex, + cgs.media.helgaSpiritTrailShader, + time, + STYPE_STRETCH, + le->refEntity.origin, + (int)le->effectWidth, // trail life + 0.3 * alpha, + 0.0, + le->radius, + 0, + 0, //TJFL_FIXDISTORT, + colorWhite, + colorWhite, + 1.0, 1 ); + } + + // tracking factor + if ( le->leType == LE_ZOMBIE_BAT ) { + le->bounceFactor = 3.0 * (float)step / 1000.0; + } else { + le->bounceFactor = 5.0 * (float)step / 1000.0; + } + oldSpeed = VectorLength( le->pos.trDelta ); + + // track the enemy + backup = *le; + VectorSubtract( enemyPos, le->refEntity.origin, v ); + enemyDist = VectorNormalize( v ); + + if ( alpha > 0.5 && ( le->lastSpiritDmgTime < time - 100 ) && enemyDist < 24 ) { + localEntity_t *fb; + + // if dead, ignore + if ( !( le->ownerNum != cg.snap->ps.clientNum ? cg_entities[le->ownerNum].currentState.eFlags & EF_DEAD : cg.snap->ps.pm_type == PM_DEAD ) ) { + // inflict the damage! + CG_ClientDamage( cg_entities[le->ownerNum].currentState.otherEntityNum2, le->ownerNum, CLDMG_SPIRIT ); + le->lastSpiritDmgTime = time; + + if ( le->leType == LE_HELGA_SPIRIT ) { + // spawn a "flashbang" thinker + fb = CG_AllocLocalEntity(); + fb->leType = LE_SPIRIT_VIEWFLASH; + fb->startTime = cg.time + 50; + fb->endTime = fb->startTime + SPIRIT_FLASH_FADEIN + SPIRIT_FLASH_DURATION + SPIRIT_FLASH_FADEOUT; + // gasp! + CG_SoundPlayIndexedScript( cgs.media.helgaGaspSound, NULL, cg_entities[le->ownerNum].currentState.otherEntityNum2 ); + } + } + } + + VectorMA( le->pos.trDelta, le->bounceFactor * oldSpeed, v, le->pos.trDelta ); + //VectorCopy( v, le->pos.trDelta ); + if ( VectorLength( le->pos.trDelta ) < 1 ) { + CG_FreeLocalEntity( le ); + return; + } + + le->bounceFactor = 5.0 * (float)step / 1000.0; // avoidance factor + + // the intersection is a fraction of the frametime + le->pos.trTime = time; + VectorCopy( le->refEntity.origin, le->pos.trBase ); + VectorNormalize( le->pos.trDelta ); + VectorScale( le->pos.trDelta, oldSpeed, le->pos.trDelta ); + + // now trace ahead of time, if we're going to hit something, then avoid it + // only avoid dangers if we don't have direct sight to the enemy + trap_CM_BoxTrace( &trace, le->refEntity.origin, enemyPos, NULL, NULL, 0, MASK_SOLID ); + if ( trace.fraction < 1.0 ) { + BG_EvaluateTrajectory( &le->pos, time + 1000, newOrigin ); + + // if we would go passed the enemy, don't bother + if ( VectorDistance( le->refEntity.origin, enemyPos ) > VectorDistance( le->refEntity.origin, newOrigin ) ) { + + trap_CM_BoxTrace( &trace, le->refEntity.origin, newOrigin, NULL, NULL, 0, MASK_SOLID ); + + if ( trace.fraction < 1.0 ) { + // make sure we are not heading away from the enemy too much + VectorNormalize2( le->pos.trDelta, v2 ); + if ( DotProduct( v, v2 ) > 0.7 ) { + // avoid world geometry + backup = *le; + le->bounceFactor = ( 1.0 - trace.fraction ) * 10.0 * (float)step / 1000.0; // tracking and avoidance factor + // reflect the velocity on the trace plane + VectorMA( le->pos.trDelta, le->bounceFactor * oldSpeed, trace.plane.normal, le->pos.trDelta ); + if ( VectorLength( le->pos.trDelta ) < 1 ) { + CG_FreeLocalEntity( le ); + return; + } + // the intersection is a fraction of the frametime + le->pos.trTime = time; + VectorCopy( le->refEntity.origin, le->pos.trBase ); + VectorNormalize( le->pos.trDelta ); + VectorScale( le->pos.trDelta, oldSpeed, le->pos.trDelta ); + // + // double check end velocity + VectorNormalize2( le->pos.trDelta, v2 ); + if ( DotProduct( v, v2 ) <= 0.2 ) { + // restore + *le = backup; + } + } + } + } + } + + // set the angles + VectorNormalize2( oDelta, v ); + // HACK!!! skull model is back-to-front, need to fix + if ( le->leType == LE_ZOMBIE_SPIRIT /*|| le->leType == LE_HELGA_SPIRIT*/ ) { + VectorInverse( v ); + } + vectoangles( v, ang ); + AnglesToAxis( ang, le->refEntity.axis ); + // lean when turning + if ( le->leType == LE_ZOMBIE_BAT || le->leType == LE_HELGA_SPIRIT ) { + VectorSubtract( le->pos.trDelta, oDelta, v2 ); + ang[ROLL] = -0.5 * DotProduct( le->refEntity.axis[1], v2 ); + if ( fabs( ang[ROLL] ) < 20 ) { + ang[ROLL] = 0; + } else { + if ( ang[ROLL] < 0 ) { + ang[ROLL] += 20; + } else { + ang[ROLL] -= 20; + } + } + if ( fabs( ang[ROLL] ) > 80 ) { + if ( ang[ROLL] > 80 ) { + ang[ROLL] = 80; + } else { ang[ROLL] = -80;} + } + AnglesToAxis( ang, le->refEntity.axis ); + } + + // HACK: the skull is slightly higher than the origin + if ( le->leType == LE_ZOMBIE_SPIRIT ) { + // set the size scale + for ( i = 0; i < 3; i++ ) + VectorScale( le->refEntity.axis[i], 0.35, le->refEntity.axis[i] ); + VectorMA( le->refEntity.origin, -10, le->refEntity.axis[2], le->refEntity.origin ); + } + + le->lastTrailTime = time; + time += step; + } + + // Bats, set the frame + if ( le->leType == LE_ZOMBIE_BAT ) { + #define BAT_ANIM_FRAMETIME 30 + le->refEntity.frame = ( cg.time / BAT_ANIM_FRAMETIME + 1 ) % 19; + le->refEntity.oldframe = ( cg.time / BAT_ANIM_FRAMETIME ) % 19; + le->refEntity.backlerp = 1.0 - ( (float)( cg.time % BAT_ANIM_FRAMETIME ) / (float)BAT_ANIM_FRAMETIME ); + } + + // add the sound + if ( le->loopingSound ) { + if ( cg.time > le->refEntity.fadeStartTime ) { + trap_S_AddLoopingSound( 0, le->refEntity.origin, vec3_origin, le->loopingSound, 255 - (int)( 255.0 * (float)( cg.time - le->refEntity.fadeStartTime ) / (float)( le->refEntity.fadeEndTime - le->refEntity.fadeStartTime ) ) ); + } else { + trap_S_AddLoopingSound( 0, le->refEntity.origin, vec3_origin, le->loopingSound, 255 - (int)( 255.0 * ( 1.0 - alpha ) ) ); + } + } +/* + if (le->leType == LE_HELGA_SPIRIT) { + int cnt=1; + float alpha; + refEntity_t re; + + // add the "motion blur" ghosts + re = le->refEntity; + i = le->oldPosHead - 1; + if (i < 0) i = MAX_OLD_POS-1; + while (i != le->oldPosHead && le->validOldPos[i]) { + alpha = 1.0 - ((float)cnt / (float)MAX_OLD_POS); + if (alpha > 1.0) alpha = 1.0; + if (alpha < 0.0) alpha = 0.0; + + re.shaderTime = le->refEntity.shaderTime - cnt*100; + VectorCopy( le->oldPos[i], re.origin ); + re.shaderRGBA[3] = (unsigned char)(255.0 * alpha); + trap_R_AddRefEntityToScene( &re ); + + if (--i<0) i=MAX_OLD_POS-1; + cnt++; + } + } else { +*/ trap_R_AddRefEntityToScene( &le->refEntity ); +// } + + // Bats, add the flame + if ( le->leType == LE_ZOMBIE_BAT ) { + // + le->refEntity.shaderRGBA[3] = 255; + VectorNormalize2( le->pos.trDelta, v ); + VectorInverse( v ); + v[2] += 1; + VectorNormalize2( v, le->refEntity.fireRiseDir ); + + le->refEntity.customShader = cgs.media.onFireShader2; + trap_R_AddRefEntityToScene( &le->refEntity ); + le->refEntity.shaderTime = 1434; + trap_R_AddRefEntityToScene( &le->refEntity ); + + le->refEntity.customShader = 0; + le->refEntity.shaderTime = 0; + } +} + +/* +================ +CG_AddDebrisElements +================ +*/ +void CG_AddDebrisElements( localEntity_t *le ) { + vec3_t newOrigin; + trace_t trace; + float lifeFrac; + int t, step = 50; + + for ( t = le->lastTrailTime + step; t < cg.time; t += step ) { + // calculate new position + BG_EvaluateTrajectory( &le->pos, t, newOrigin ); + + // trace a line from previous position to new position + CG_Trace( &trace, le->refEntity.origin, NULL, NULL, newOrigin, -1, MASK_SHOT ); + + // if stuck, kill it + if ( trace.startsolid ) { + // HACK, some walls screw up, so just pass through if starting in a solid + VectorCopy( newOrigin, trace.endpos ); + trace.fraction = 1.0; + } + + // moved some distance + VectorCopy( trace.endpos, le->refEntity.origin ); + + // add a trail + lifeFrac = (float)( t - le->startTime ) / (float)( le->endTime - le->startTime ); + +#if 0 + // fire +#if 1 // flame + if ( le->effectWidth > 0 ) { + le->headJuncIndex = CG_AddSparkJunc( le->headJuncIndex, + cgs.media.fireTrailShader, + le->refEntity.origin, + (int)( 500.0 * ( 0.5 + 0.5 * ( 1.0 - lifeFrac ) ) ), // trail life + 1.0, // alpha + 0.5, // end alpha + 3, // start width + le->effectWidth ); // end width +#else // spark line + if ( le->effectWidth > 0 ) { + le->headJuncIndex = CG_AddSparkJunc( le->headJuncIndex, + cgs.media.sparkParticleShader, + le->refEntity.origin, + (int)( 600.0 * ( 0.5 + 0.5 * ( 0.5 - lifeFrac ) ) ), // trail life + 1.0 - lifeFrac * 2, // alpha + 0.5 * ( 1.0 - lifeFrac ), // end alpha + 5.0 * ( 1.0 - lifeFrac ), // start width + 5.0 * ( 1.0 - lifeFrac ) ); // end width +#endif + } +#endif + + // smoke + if ( le->effectFlags & 1 ) { + le->headJuncIndex2 = CG_AddSmokeJunc( le->headJuncIndex2, + cgs.media.smokeTrailShader, + le->refEntity.origin, + (int)( 2000.0 * ( 0.5 + 0.5 * ( 1.0 - lifeFrac ) ) ), // trail life + 1.0 * ( trace.fraction == 1.0 ) * ( 0.5 + 0.5 * ( 1.0 - lifeFrac ) ), // alpha + 1, // start width + (int)( 60.0 * ( 0.5 + 0.5 * ( 1.0 - lifeFrac ) ) ) ); // end width + } + + // if it is in a nodrop zone, remove it + // this keeps gibs from waiting at the bottom of pits of death + // and floating levels +// if ( trap_CM_PointContents( trace.endpos, 0 ) & CONTENTS_NODROP ) { +// CG_FreeLocalEntity( le ); +// return; +// } + + if ( trace.fraction < 1.0 ) { + // reflect the velocity on the trace plane + CG_ReflectVelocity( le, &trace ); + if ( VectorLength( le->pos.trDelta ) < 1 ) { + CG_FreeLocalEntity( le ); + return; + } + // the intersection is a fraction of the frametime + le->pos.trTime = t; + } + + le->lastTrailTime = t; + } + +} + +// Rafael Shrapnel +/* +=============== +CG_AddShrapnel +=============== +*/ +void CG_AddShrapnel( localEntity_t *le ) { + vec3_t newOrigin; + trace_t trace; + + if ( le->pos.trType == TR_STATIONARY ) { + // sink into the ground if near the removal time + int t; + float oldZ; + + t = le->endTime - cg.time; + if ( t < SINK_TIME ) { + // we must use an explicit lighting origin, otherwise the + // lighting would be lost as soon as the origin went + // into the ground + VectorCopy( le->refEntity.origin, le->refEntity.lightingOrigin ); + le->refEntity.renderfx |= RF_LIGHTING_ORIGIN; + oldZ = le->refEntity.origin[2]; + le->refEntity.origin[2] -= 16 * ( 1.0 - (float)t / SINK_TIME ); + trap_R_AddRefEntityToScene( &le->refEntity ); + le->refEntity.origin[2] = oldZ; + } else { + trap_R_AddRefEntityToScene( &le->refEntity ); + CG_AddParticleShrapnel( le ); + } + + return; + } + + // calculate new position + BG_EvaluateTrajectory( &le->pos, cg.time, newOrigin ); + + // trace a line from previous position to new position + CG_Trace( &trace, le->refEntity.origin, NULL, NULL, newOrigin, -1, CONTENTS_SOLID ); + if ( trace.fraction == 1.0 ) { + // still in free fall + VectorCopy( newOrigin, le->refEntity.origin ); + + if ( le->leFlags & LEF_TUMBLE ) { + vec3_t angles; + + BG_EvaluateTrajectory( &le->angles, cg.time, angles ); + AnglesToAxis( angles, le->refEntity.axis ); + } + + trap_R_AddRefEntityToScene( &le->refEntity ); + CG_AddParticleShrapnel( le ); + return; + } + + // if it is in a nodrop zone, remove it + // this keeps gibs from waiting at the bottom of pits of death + // and floating levels + if ( trap_CM_PointContents( trace.endpos, 0 ) & CONTENTS_NODROP ) { + CG_FreeLocalEntity( le ); + return; + } + + // leave a mark + CG_FragmentBounceMark( le, &trace ); + + // do a bouncy sound + CG_FragmentBounceSound( le, &trace ); + + // reflect the velocity on the trace plane + CG_ReflectVelocity( le, &trace ); + + trap_R_AddRefEntityToScene( &le->refEntity ); + CG_AddParticleShrapnel( le ); +} +// done. + +/* +===================================================================== + +TRIVIAL LOCAL ENTITIES + +These only do simple scaling or modulation before passing to the renderer +===================================================================== +*/ + +/* +==================== +CG_AddFadeRGB +==================== +*/ +void CG_AddFadeRGB( localEntity_t *le ) { + refEntity_t *re; + float c; + + re = &le->refEntity; + + c = ( le->endTime - cg.time ) * le->lifeRate; + c *= 0xff; + + re->shaderRGBA[0] = le->color[0] * c; + re->shaderRGBA[1] = le->color[1] * c; + re->shaderRGBA[2] = le->color[2] * c; + re->shaderRGBA[3] = le->color[3] * c; + + trap_R_AddRefEntityToScene( re ); +} + +/* +================== +CG_AddMoveScaleFade +================== +*/ +static void CG_AddMoveScaleFade( localEntity_t *le ) { + refEntity_t *re; + float c; + vec3_t delta; + float len; + + re = &le->refEntity; + + // fade / grow time +// c = ( le->endTime - cg.time ) * le->lifeRate; + if ( le->fadeInTime > le->startTime && cg.time < le->fadeInTime ) { + // fade / grow time + c = 1.0 - (float) ( le->fadeInTime - cg.time ) / ( le->fadeInTime - le->startTime ); + } else { + // fade / grow time + c = ( le->endTime - cg.time ) * le->lifeRate; + } + + // Ridah, spark + if ( !( le->leFlags & LEF_NOFADEALPHA ) ) { + // done. + re->shaderRGBA[3] = 0xff * c * le->color[3]; + } + + if ( !( le->leFlags & LEF_PUFF_DONT_SCALE ) ) { + c = ( le->endTime - cg.time ) * le->lifeRate; + re->radius = le->radius * ( 1.0 - c ) + 8; + } + + BG_EvaluateTrajectory( &le->pos, cg.time, re->origin ); + + // if the view would be "inside" the sprite, kill the sprite + // so it doesn't add too much overdraw + VectorSubtract( re->origin, cg.refdef.vieworg, delta ); + len = VectorLength( delta ); + if ( len < le->radius ) { + CG_FreeLocalEntity( le ); + return; + } + + trap_R_AddRefEntityToScene( re ); +} + + +/* +=================== +CG_AddScaleFade + +For rocket smokes that hang in place, fade out, and are +removed if the view passes through them. +There are often many of these, so it needs to be simple. +=================== +*/ +static void CG_AddScaleFade( localEntity_t *le ) { + refEntity_t *re; + float c; + vec3_t delta; + float len; + + re = &le->refEntity; + + // fade / grow time + c = ( le->endTime - cg.time ) * le->lifeRate; + + re->shaderRGBA[3] = 0xff * c * le->color[3]; + if ( !( le->leFlags & LEF_PUFF_DONT_SCALE ) ) { + re->radius = le->radius * ( 1.0 - c ) + 8; + } + + // if the view would be "inside" the sprite, kill the sprite + // so it doesn't add too much overdraw + VectorSubtract( re->origin, cg.refdef.vieworg, delta ); + len = VectorLength( delta ); + if ( len < le->radius ) { + CG_FreeLocalEntity( le ); + return; + } + + trap_R_AddRefEntityToScene( re ); +} + + +/* +================= +CG_AddFallScaleFade + +This is just an optimized CG_AddMoveScaleFade +For blood mists that drift down, fade out, and are +removed if the view passes through them. +There are often 100+ of these, so it needs to be simple. +================= +*/ +static void CG_AddFallScaleFade( localEntity_t *le ) { + refEntity_t *re; + float c; + vec3_t delta; + float len; + + re = &le->refEntity; + + // fade time + c = ( le->endTime - cg.time ) * le->lifeRate; + + re->shaderRGBA[3] = 0xff * c * le->color[3]; + + re->origin[2] = le->pos.trBase[2] - ( 1.0 - c ) * le->pos.trDelta[2]; + + re->radius = le->radius * ( 1.0 - c ) + 16; + + // if the view would be "inside" the sprite, kill the sprite + // so it doesn't add too much overdraw + VectorSubtract( re->origin, cg.refdef.vieworg, delta ); + len = VectorLength( delta ); + if ( len < le->radius ) { + CG_FreeLocalEntity( le ); + return; + } + + trap_R_AddRefEntityToScene( re ); +} + + + +/* +================ +CG_AddExplosion +================ +*/ +static void CG_AddExplosion( localEntity_t *ex ) { + refEntity_t *ent; + + ent = &ex->refEntity; + + // add the entity + // RF, don't add if shader is invalid + if ( ent->customShader >= 0 ) { + trap_R_AddRefEntityToScene( ent ); + } + + // add the dlight + if ( ex->light ) { + float light; + + light = (float)( cg.time - ex->startTime ) / ( ex->endTime - ex->startTime ); + if ( light < 0.5 ) { + light = 1.0; + } else { + light = 1.0 - ( light - 0.5 ) * 2; + } + light = ex->light * light; + trap_R_AddLightToScene( ent->origin, light, ex->lightColor[0], ex->lightColor[1], ex->lightColor[2], 0 ); + } +} + +/* +================ +CG_AddSpriteExplosion +================ +*/ +static void CG_AddSpriteExplosion( localEntity_t *le ) { + refEntity_t re; + float c; + + re = le->refEntity; + + c = ( le->endTime - cg.time ) / ( float ) ( le->endTime - le->startTime ); + if ( c > 1 ) { + c = 1.0; // can happen during connection problems + } + + re.shaderRGBA[0] = 0xff; + re.shaderRGBA[1] = 0xff; + re.shaderRGBA[2] = 0xff; + re.shaderRGBA[3] = 0xff * c * 0.33; + + re.reType = RT_SPRITE; + re.radius = 42 * ( 1.0 - c ) + 30; + + // Ridah, move away from surface + VectorMA( le->pos.trBase, ( 1.0 - c ), le->pos.trDelta, re.origin ); + // done. + + // RF, don't add if shader is invalid + if ( re.customShader >= 0 ) { + trap_R_AddRefEntityToScene( &re ); + } + + // add the dlight + if ( le->light ) { + float light; + + // Ridah, modified this so the light fades out rather than shrinking + /* + light = (float)( cg.time - le->startTime ) / ( le->endTime - le->startTime ); + if ( light < 0.5 ) { + light = 1.0; + } else { + light = 1.0 - ( light - 0.5 ) * 2; + } + light = le->light * light; + trap_R_AddLightToScene(re.origin, light, le->lightColor[0], le->lightColor[1], le->lightColor[2], 0 ); + */ + light = (float)( cg.time - le->startTime ) / ( le->endTime - le->startTime ); + if ( light < 0.5 ) { + light = 1.0; + } else { + light = 1.0 - ( light - 0.5 ) * 2; + } + trap_R_AddLightToScene( re.origin, le->light, light * le->lightColor[0], light * le->lightColor[1], light * le->lightColor[2], 0 ); + // done. + } +} + +//============================================================================== + +/* +=================== +CG_AddLocalEntities + +=================== +*/ +void CG_AddLocalEntities( void ) { + localEntity_t *le, *next; + + cg.viewFade = 0.0; + + // walk the list backwards, so any new local entities generated + // (trails, marks, etc) will be present this frame + le = cg_activeLocalEntities.prev; + for ( ; le != &cg_activeLocalEntities ; le = next ) { + // grab next now, so if the local entity is freed we + // still have it + next = le->prev; + + if ( cg.time >= le->endTime ) { + CG_FreeLocalEntity( le ); + continue; + } + switch ( le->leType ) { + default: + CG_Error( "Bad leType: %i", le->leType ); + break; + + // Ridah + case LE_MOVING_TRACER: + CG_AddMovingTracer( le ); + break; + case LE_SPARK: + CG_AddSparkElements( le ); + break; + case LE_FUSE_SPARK: + CG_AddFuseSparkElements( le ); + break; + case LE_DEBRIS: + CG_AddDebrisElements( le ); + break; + case LE_BLOOD: + CG_AddBloodElements( le ); + break; + case LE_HELGA_SPIRIT: + case LE_ZOMBIE_SPIRIT: + case LE_ZOMBIE_BAT: + CG_AddClientCritter( le ); + break; + case LE_SPIRIT_VIEWFLASH: + CG_AddSpiritViewflash( le ); + // done. + + case LE_MARK: + break; + + case LE_SPRITE_EXPLOSION: + CG_AddSpriteExplosion( le ); + break; + + case LE_EXPLOSION: + CG_AddExplosion( le ); + break; + + case LE_FRAGMENT: // gibs and brass + CG_AddFragment( le ); + break; + + case LE_MOVE_SCALE_FADE: // water bubbles + CG_AddMoveScaleFade( le ); + break; + + case LE_FADE_RGB: // teleporters, railtrails + CG_AddFadeRGB( le ); + break; + + case LE_FALL_SCALE_FADE: // gib blood trails + CG_AddFallScaleFade( le ); + break; + + case LE_SCALE_FADE: // rocket trails + CG_AddScaleFade( le ); + break; + + case LE_EMITTER: + CG_AddEmitter( le ); + break; + + } + } +} + diff --git a/Projects/Android/jni/rtcw/src/cgame/cg_main.c b/Projects/Android/jni/rtcw/src/cgame/cg_main.c new file mode 100644 index 0000000..ca808c8 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/cgame/cg_main.c @@ -0,0 +1,2427 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +/* + * name: cg_main.c + * + * desc: initialization and primary entry point for cgame + * +*/ + + +#include "cg_local.h" +#include "../ui/ui_shared.h" + +displayContextDef_t cgDC; + +int forceModelModificationCount = -1; + +void CG_Init( int serverMessageNum, int serverCommandSequence ); +void CG_Shutdown( void ); + + +/* +================ +vmMain + +This is the only way control passes into the module. +This must be the very first function compiled into the .q3vm file +================ +*/ +#if defined( __MACOS__ ) // TTimo: guarding +#pragma export on +#endif +int vmMain( int command, int arg0, int arg1, int arg2, int arg3, int arg4, int arg5, int arg6, int arg7, int arg8, int arg9, int arg10, int arg11 ) { +#if defined( __MACOS__ ) +#pragma export off +#endif + switch ( command ) { + case CG_GET_TAG: + return CG_GetTag( arg0, (char *)arg1, (orientation_t *)arg2 ); + case CG_DRAW_ACTIVE_FRAME: + CG_DrawActiveFrame( arg0, arg1, arg2 ); + return 0; + case CG_EVENT_HANDLING: + CG_EventHandling( arg0 ); + return 0; + case CG_INIT: + CG_Init( arg0, arg1 ); + return 0; + case CG_SHUTDOWN: + CG_Shutdown(); + return 0; + case CG_CONSOLE_COMMAND: + return CG_ConsoleCommand(); + case CG_CROSSHAIR_PLAYER: + return CG_CrosshairPlayer(); + case CG_LAST_ATTACKER: + return CG_LastAttacker(); + case CG_KEY_EVENT: + CG_KeyEvent( arg0, arg1 ); + return 0; + case CG_MOUSE_EVENT: + cgDC.cursorx = cgs.cursorX; + cgDC.cursory = cgs.cursorY; + CG_MouseEvent( arg0, arg1 ); + return 0; + default: + CG_Error( "vmMain: unknown command %i", command ); + break; + } + return -1; +} + + +cg_t cg; +cgs_t cgs; +centity_t cg_entities[MAX_GENTITIES]; +weaponInfo_t cg_weapons[MAX_WEAPONS]; +itemInfo_t cg_items[MAX_ITEMS]; + + +vmCvar_t cg_railTrailTime; +vmCvar_t cg_centertime; +vmCvar_t cg_runpitch; +vmCvar_t cg_runroll; +vmCvar_t cg_bobup; +vmCvar_t cg_bobpitch; +vmCvar_t cg_bobroll; +vmCvar_t cg_swingSpeed; +vmCvar_t cg_shadows; +vmCvar_t cg_gibs; +vmCvar_t cg_drawTimer; +vmCvar_t cg_drawFPS; +vmCvar_t cg_drawSnapshot; +vmCvar_t cg_draw3dIcons; +vmCvar_t cg_drawIcons; +vmCvar_t cg_youGotMail; //----(SA) added +vmCvar_t cg_drawAmmoWarning; +vmCvar_t cg_drawCrosshair; +vmCvar_t cg_drawCrosshairNames; +vmCvar_t cg_drawCrosshairPickups; +vmCvar_t cg_hudAlpha; +vmCvar_t cg_weaponCycleDelay; //----(SA) added +vmCvar_t cg_cycleAllWeaps; +vmCvar_t cg_useWeapsForZoom; +vmCvar_t cg_drawAllWeaps; +vmCvar_t cg_drawRewards; +vmCvar_t cg_crosshairSize; +vmCvar_t cg_crosshairAlpha; //----(SA) added +vmCvar_t cg_crosshairX; +vmCvar_t cg_crosshairY; +vmCvar_t cg_crosshairHealth; +vmCvar_t cg_draw2D; +vmCvar_t cg_drawFrags; +vmCvar_t cg_teamChatsOnly; +vmCvar_t cg_drawStatus; +vmCvar_t cg_animSpeed; +vmCvar_t cg_drawSpreadScale; +vmCvar_t cg_debugAnim; +vmCvar_t cg_debugPosition; +vmCvar_t cg_debugEvents; +vmCvar_t cg_errorDecay; +vmCvar_t cg_nopredict; +vmCvar_t cg_noPlayerAnims; +vmCvar_t cg_showmiss; +vmCvar_t cg_footsteps; +vmCvar_t cg_markTime; +vmCvar_t cg_brassTime; +vmCvar_t cg_viewsize; +vmCvar_t cg_letterbox; +vmCvar_t cg_drawGun; +vmCvar_t cg_drawFPGun; +vmCvar_t cg_drawGamemodels; +vmCvar_t cg_cursorHints; +vmCvar_t cg_hintFadeTime; //----(SA) added +vmCvar_t cg_gun_frame; +vmCvar_t cg_gun_x; +vmCvar_t cg_gun_y; +vmCvar_t cg_gun_z; +vmCvar_t cg_tracerChance; +vmCvar_t cg_tracerWidth; +vmCvar_t cg_tracerLength; +vmCvar_t cg_tracerSpeed; +vmCvar_t cg_autoswitch; +vmCvar_t cg_ignore; +vmCvar_t cg_simpleItems; +vmCvar_t cg_fov; +vmCvar_t cg_zoomFov; +vmCvar_t cg_zoomStepBinoc; +vmCvar_t cg_zoomStepSniper; +vmCvar_t cg_zoomStepSnooper; +vmCvar_t cg_zoomStepFG; //----(SA) added +vmCvar_t cg_zoomDefaultBinoc; +vmCvar_t cg_zoomDefaultSniper; +vmCvar_t cg_zoomDefaultSnooper; +vmCvar_t cg_zoomDefaultFG; //----(SA) added +vmCvar_t cg_reticles; +vmCvar_t cg_reticleBrightness; //----(SA) added +vmCvar_t cg_thirdPerson; +vmCvar_t cg_thirdPersonRange; +vmCvar_t cg_thirdPersonAngle; +vmCvar_t cg_stereoSeparation; +vmCvar_t cg_lagometer; +vmCvar_t cg_drawAttacker; +vmCvar_t cg_synchronousClients; +vmCvar_t cg_teamChatTime; +vmCvar_t cg_teamChatHeight; +vmCvar_t cg_stats; +vmCvar_t cg_buildScript; +vmCvar_t cg_forceModel; +vmCvar_t cg_coronafardist; +vmCvar_t cg_coronas; +vmCvar_t cg_paused; +vmCvar_t cg_blood; +vmCvar_t cg_predictItems; +vmCvar_t cg_deferPlayers; +vmCvar_t cg_drawTeamOverlay; +vmCvar_t cg_enableBreath; +vmCvar_t cg_autoactivate; +vmCvar_t cg_useSuggestedWeapons; //----(SA) added +vmCvar_t cg_emptyswitch; +vmCvar_t cg_particleDist; +vmCvar_t cg_particleLOD; +vmCvar_t cg_blinktime; //----(SA) added + +vmCvar_t cg_smoothClients; +vmCvar_t pmove_fixed; +vmCvar_t pmove_msec; + +// Rafael - particle switch +vmCvar_t cg_wolfparticles; +// done + +// Ridah +vmCvar_t cg_gameType; +vmCvar_t cg_bloodTime; +vmCvar_t cg_norender; +vmCvar_t cg_skybox; + +// Rafael +vmCvar_t cg_gameSkill; +// done + +vmCvar_t cg_reloading; //----(SA) added + +// JPW NERVE +vmCvar_t cg_medicChargeTime; +vmCvar_t cg_engineerChargeTime; +vmCvar_t cg_LTChargeTime; +vmCvar_t cg_soldierChargeTime; +vmCvar_t cg_redlimbotime; +vmCvar_t cg_bluelimbotime; +// jpw + +vmCvar_t cg_hunkUsed; +vmCvar_t cg_soundAdjust; +vmCvar_t cg_expectedhunkusage; + +vmCvar_t cg_showAIState; + +vmCvar_t cg_notebook; +vmCvar_t cg_notebookpages; // bitflags for the currently accessable pages. if they wanna cheat, let 'em. Most won't, or will wait 'til they actually play it. + +vmCvar_t cg_currentSelectedPlayer; +vmCvar_t cg_currentSelectedPlayerName; +vmCvar_t cg_cameraMode; +vmCvar_t cg_cameraOrbit; +vmCvar_t cg_cameraOrbitDelay; +vmCvar_t cg_timescaleFadeEnd; +vmCvar_t cg_timescaleFadeSpeed; +vmCvar_t cg_timescale; +vmCvar_t cg_smallFont; +vmCvar_t cg_bigFont; +vmCvar_t cg_hudFiles; + +vmCvar_t cg_animState; +vmCvar_t cg_missionStats; +vmCvar_t cg_waitForFire; + +vmCvar_t cg_loadWeaponSelect; + +// NERVE - SMF - Wolf multiplayer configuration cvars +vmCvar_t mp_playerType; +vmCvar_t mp_team; +vmCvar_t mp_weapon; +vmCvar_t mp_pistol; +vmCvar_t mp_item1; +vmCvar_t mp_item2; +vmCvar_t mp_mapDesc; +vmCvar_t mp_mapTitle; +vmCvar_t mp_itemDesc; +// -NERVE - SMF + +typedef struct { + vmCvar_t *vmCvar; + char *cvarName; + char *defaultString; + int cvarFlags; +} cvarTable_t; + +cvarTable_t cvarTable[] = { + { &cg_ignore, "cg_ignore", "0", 0 }, // used for debugging + { &cg_autoswitch, "cg_autoswitch", "2", CVAR_ARCHIVE }, + { &cg_drawGun, "cg_drawGun", "1", CVAR_ARCHIVE }, + { &cg_drawGamemodels, "cg_drawGamemodels", "1", CVAR_CHEAT }, + { &cg_drawFPGun, "cg_drawFPGun", "1", CVAR_ARCHIVE }, + { &cg_gun_frame, "cg_gun_frame", "0", CVAR_TEMP }, + { &cg_cursorHints, "cg_cursorHints", "1", CVAR_ARCHIVE }, + { &cg_hintFadeTime, "cg_hintFadeTime", "500", CVAR_ARCHIVE }, //----(SA) added + { &cg_zoomFov, "cg_zoomfov", "22.5", CVAR_ARCHIVE }, + { &cg_zoomDefaultBinoc, "cg_zoomDefaultBinoc", "22.5", CVAR_ARCHIVE }, + { &cg_zoomDefaultSniper, "cg_zoomDefaultSniper", "15", CVAR_ARCHIVE }, + { &cg_zoomDefaultSnooper, "cg_zoomDefaultSnooper", "40", CVAR_ARCHIVE }, + { &cg_zoomDefaultFG, "cg_zoomDefaultFG", "55", CVAR_ARCHIVE }, //----(SA) added + { &cg_zoomStepBinoc, "cg_zoomStepBinoc", "3", CVAR_ARCHIVE }, + { &cg_zoomStepSniper, "cg_zoomStepSniper", "2", CVAR_ARCHIVE }, + { &cg_zoomStepSnooper, "cg_zoomStepSnooper", "5", CVAR_ARCHIVE }, + { &cg_zoomStepFG, "cg_zoomStepFG", "10", CVAR_ARCHIVE }, //----(SA) added + { &cg_fov, "cg_fov", "90", CVAR_ARCHIVE | CVAR_CHEAT }, // JPW NERVE added cheat protect NOTE: there is already a dmflag (DF_FIXED_FOV) to allow server control of this cheat + { &cg_viewsize, "cg_viewsize", "100", CVAR_ARCHIVE }, + { &cg_letterbox, "cg_letterbox", "0", CVAR_TEMP }, //----(SA) added + { &cg_stereoSeparation, "cg_stereoSeparation", "0.4", CVAR_ARCHIVE }, + { &cg_shadows, "cg_shadows", "1", CVAR_ARCHIVE }, + { &cg_gibs, "cg_gibs", "1", CVAR_ARCHIVE }, + { &cg_draw2D, "cg_draw2D", "1", CVAR_ARCHIVE }, + { &cg_drawSpreadScale, "cg_drawSpreadScale", "1", CVAR_ARCHIVE }, + { &cg_drawFrags, "cg_drawFrags", "1", CVAR_ARCHIVE }, + { &cg_drawStatus, "cg_drawStatus", "1", CVAR_ARCHIVE }, + { &cg_drawTimer, "cg_drawTimer", "0", CVAR_ARCHIVE }, + { &cg_drawFPS, "cg_drawFPS", "0", CVAR_ARCHIVE }, + { &cg_drawSnapshot, "cg_drawSnapshot", "0", CVAR_ARCHIVE }, + { &cg_draw3dIcons, "cg_draw3dIcons", "1", CVAR_ARCHIVE }, + { &cg_drawIcons, "cg_drawIcons", "1", CVAR_ARCHIVE }, + { &cg_drawAmmoWarning, "cg_drawAmmoWarning", "1", CVAR_ARCHIVE }, + { &cg_drawAttacker, "cg_drawAttacker", "1", CVAR_ARCHIVE }, + { &cg_drawCrosshair, "cg_drawCrosshair", "4", CVAR_ARCHIVE }, + { &cg_drawCrosshairNames, "cg_drawCrosshairNames", "1", CVAR_ARCHIVE }, + { &cg_drawCrosshairPickups, "cg_drawCrosshairPickups", "1", CVAR_ARCHIVE }, + { &cg_drawRewards, "cg_drawRewards", "1", CVAR_ARCHIVE }, + { &cg_hudAlpha, "cg_hudAlpha", "0.8", CVAR_ARCHIVE }, + { &cg_useWeapsForZoom, "cg_useWeapsForZoom", "1", CVAR_ARCHIVE }, + { &cg_weaponCycleDelay, "cg_weaponCycleDelay", "150", CVAR_ARCHIVE }, //----(SA) added + { &cg_cycleAllWeaps, "cg_cycleAllWeaps", "1", CVAR_ARCHIVE }, + { &cg_drawAllWeaps, "cg_drawAllWeaps", "1", CVAR_ARCHIVE }, + { &cg_crosshairSize, "cg_crosshairSize", "24", CVAR_ARCHIVE }, + { &cg_crosshairAlpha, "cg_crosshairAlpha", "0.5", CVAR_ARCHIVE }, //----(SA) added + { &cg_crosshairHealth, "cg_crosshairHealth", "1", CVAR_ARCHIVE }, + { &cg_crosshairX, "cg_crosshairX", "0", CVAR_ARCHIVE }, + { &cg_crosshairY, "cg_crosshairY", "0", CVAR_ARCHIVE }, + { &cg_brassTime, "cg_brassTime", "1250", CVAR_ARCHIVE }, + { &cg_simpleItems, "cg_simpleItems", "0", CVAR_ARCHIVE }, + { &cg_reticles, "cg_reticles", "1", CVAR_CHEAT }, + { &cg_reticleBrightness, "cg_reticleBrightness", "0.7", CVAR_ARCHIVE }, + { &cg_markTime, "cg_marktime", "20000", CVAR_ARCHIVE }, + { &cg_lagometer, "cg_lagometer", "1", CVAR_ARCHIVE }, + { &cg_railTrailTime, "cg_railTrailTime", "400", CVAR_ARCHIVE }, + { &cg_gun_x, "cg_gunX", "0", CVAR_CHEAT }, + { &cg_gun_y, "cg_gunY", "0", CVAR_CHEAT }, + { &cg_gun_z, "cg_gunZ", "0", CVAR_CHEAT }, + { &cg_centertime, "cg_centertime", "3", CVAR_CHEAT }, + { &cg_runpitch, "cg_runpitch", "0.002", CVAR_ARCHIVE}, + { &cg_runroll, "cg_runroll", "0.005", CVAR_ARCHIVE }, + { &cg_bobup, "cg_bobup", "0.005", CVAR_ARCHIVE }, + { &cg_bobpitch, "cg_bobpitch", "0.002", CVAR_ARCHIVE }, + { &cg_bobroll, "cg_bobroll", "0.002", CVAR_ARCHIVE }, + + // JOSEPH 10-27-99 + { &cg_autoactivate, "cg_autoactivate", "1", CVAR_ARCHIVE }, + { &cg_emptyswitch, "cg_emptyswitch", "0", CVAR_ARCHIVE }, + // END JOSEPH + +//----(SA) added + { &cg_particleDist, "cg_particleDist", "1024", CVAR_ARCHIVE }, + { &cg_particleLOD, "cg_particleLOD", "0", CVAR_ARCHIVE }, + { &cg_useSuggestedWeapons, "cg_useSuggestedWeapons", "1", CVAR_ARCHIVE }, //----(SA) added +//----(SA) end + + // Ridah, more fluid rotations + { &cg_swingSpeed, "cg_swingSpeed", "0.1", CVAR_CHEAT }, // was 0.3 for Q3 + { &cg_bloodTime, "cg_bloodTime", "120", CVAR_ARCHIVE }, + { &cg_hunkUsed, "com_hunkUsed", "0", 0 }, + { &cg_soundAdjust, "hunk_soundadjust", "0", 0 }, + + { &cg_skybox, "cg_skybox", "1", CVAR_CHEAT }, + // done. + + { &cg_animSpeed, "cg_animspeed", "1", CVAR_CHEAT }, + { &cg_debugAnim, "cg_debuganim", "0", CVAR_CHEAT }, + { &cg_debugPosition, "cg_debugposition", "0", CVAR_CHEAT }, + { &cg_debugEvents, "cg_debugevents", "0", CVAR_CHEAT }, + { &cg_errorDecay, "cg_errordecay", "100", 0 }, + { &cg_nopredict, "cg_nopredict", "0", 0 }, + { &cg_noPlayerAnims, "cg_noplayeranims", "0", CVAR_CHEAT }, + { &cg_showmiss, "cg_showmiss", "0", 0 }, + { &cg_footsteps, "cg_footsteps", "1", CVAR_CHEAT }, + { &cg_tracerChance, "cg_tracerchance", "0.4", CVAR_CHEAT }, + { &cg_tracerWidth, "cg_tracerwidth", "0.8", CVAR_CHEAT }, + { &cg_tracerSpeed, "cg_tracerSpeed", "4500", CVAR_CHEAT }, + { &cg_tracerLength, "cg_tracerlength", "160", CVAR_CHEAT }, + { &cg_thirdPersonRange, "cg_thirdPersonRange", "40", 0 }, + { &cg_thirdPersonAngle, "cg_thirdPersonAngle", "0", CVAR_CHEAT }, + { &cg_thirdPerson, "cg_thirdPerson", "0", 0 }, + { &cg_teamChatTime, "cg_teamChatTime", "3000", CVAR_ARCHIVE }, + { &cg_teamChatHeight, "cg_teamChatHeight", "8", CVAR_ARCHIVE }, + { &cg_forceModel, "cg_forceModel", "0", CVAR_ARCHIVE }, + { &cg_coronafardist, "cg_coronafardist", "1536", CVAR_ARCHIVE }, + { &cg_coronas, "cg_coronas", "1", CVAR_ARCHIVE }, + { &cg_predictItems, "cg_predictItems", "1", CVAR_ARCHIVE }, + { &cg_deferPlayers, "cg_deferPlayers", "1", CVAR_ARCHIVE }, + { &cg_drawTeamOverlay, "cg_drawTeamOverlay", "0", CVAR_ARCHIVE }, + { &cg_stats, "cg_stats", "0", 0 }, + { &cg_blinktime, "cg_blinktime", "100", CVAR_ARCHIVE}, //----(SA) added + + { &cg_enableBreath, "g_enableBreath", "1", CVAR_SERVERINFO}, + { &cg_cameraOrbit, "cg_cameraOrbit", "0", CVAR_CHEAT}, + { &cg_cameraOrbitDelay, "cg_cameraOrbitDelay", "50", CVAR_ARCHIVE}, + { &cg_timescaleFadeEnd, "cg_timescaleFadeEnd", "1", 0}, + { &cg_timescaleFadeSpeed, "cg_timescaleFadeSpeed", "0", 0}, + { &cg_timescale, "timescale", "1", 0}, +// { &cg_smoothClients, "cg_smoothClients", "0", CVAR_USERINFO | CVAR_ARCHIVE}, + { &cg_cameraMode, "com_cameraMode", "0", CVAR_CHEAT}, + + { &pmove_fixed, "pmove_fixed", "0", 0}, + { &pmove_msec, "pmove_msec", "8", 0}, + { &cg_smallFont, "ui_smallFont", "0.25", CVAR_ARCHIVE}, + { &cg_bigFont, "ui_bigFont", "0.4", CVAR_ARCHIVE}, + { &cg_hudFiles, "cg_hudFiles", "ui/hud.txt", CVAR_ARCHIVE}, + + { &cg_teamChatsOnly, "cg_teamChatsOnly", "0", CVAR_ARCHIVE }, + // the following variables are created in other parts of the system, + // but we also reference them here + + { &cg_buildScript, "com_buildScript", "0", 0 }, // force loading of all possible data amd error on failures + { &cg_paused, "cl_paused", "0", CVAR_ROM }, + + { &cg_blood, "com_blood", "1", CVAR_ARCHIVE }, + { &cg_synchronousClients, "g_syncronousClients", "0", 0 }, // communicated by systeminfo + { &cg_currentSelectedPlayer, "cg_currentSelectedPlayer", "0", CVAR_ARCHIVE}, + { &cg_currentSelectedPlayerName, "cg_currentSelectedPlayerName", "", CVAR_ARCHIVE}, + + // Rafael - particle switch + { &cg_wolfparticles, "cg_wolfparticles", "1", CVAR_ARCHIVE }, + // done + + // Ridah + { &cg_gameType, "g_gametype", "0", 0 }, // communicated by systeminfo + { &cg_norender, "cg_norender", "0", 0 }, // only used during single player, to suppress rendering until the server is ready + + { &cg_gameSkill, "g_gameskill", "2", 0 }, // communicated by systeminfo // (SA) new default '2' (was '1') + + { &cg_reloading, "g_reloading", "0", 0 }, //----(SA) added + + // JPW NERVE + { &cg_medicChargeTime, "g_medicChargeTime", "10000", 0 }, // communicated by systeminfo + { &cg_LTChargeTime, "g_LTChargeTime", "30000", 0 }, // communicated by systeminfo + { &cg_engineerChargeTime, "g_engineerChargeTime", "30000", 0 }, // communicated by systeminfo + { &cg_soldierChargeTime, "g_soldierChargeTime", "20000", 0 }, // communicated by systeminfo + { &cg_bluelimbotime, "g_bluelimbotime", "30000", 0 }, // communicated by systeminfo + { &cg_redlimbotime, "g_redlimbotime","30000", 0 }, // communicated by systeminfo + // jpw + + { &cg_notebook, "cl_notebook", "0", CVAR_ROM }, + { &cg_notebookpages, "cg_notebookpages", "0", CVAR_ROM}, +// { &cg_youGotMail, "cg_youGotMail", "0", CVAR_ROM}, // used to display notebook new-info icon + { &cg_youGotMail, "cg_youGotMail", "0", 0}, // used to display notebook new-info icon + + { &cg_animState, "cg_animState", "0", CVAR_CHEAT}, + { &cg_missionStats, "g_missionStats", "0", CVAR_ROM}, + { &cg_waitForFire, "cl_waitForFire", "0", CVAR_ROM}, + + { &cg_loadWeaponSelect, "cg_loadWeaponSelect", "0", CVAR_ROM}, + + { &cg_expectedhunkusage, "com_expectedhunkusage", "0", CVAR_ROM}, + + // NERVE - SMF + { &mp_playerType, "mp_playerType", "0", 0 }, + { &mp_team, "mp_team", "0", 0 }, + { &mp_weapon, "mp_weapon", "0", 0 }, + { &mp_pistol, "mp_pistol", "0", 0 }, + { &mp_item1, "mp_item1", "0", 0 }, + { &mp_item2, "mp_item2", "0", 0 }, + { &mp_mapDesc, "mp_mapDesc", "", 0 }, + { &mp_mapTitle, "mp_mapTitle", "", 0 }, + { &mp_itemDesc, "mp_itemDesc", "", 0 }, + // -NERVE - SMF + + { &cg_showAIState, "cg_showAIState", "0", CVAR_CHEAT}, +}; +int cvarTableSize = sizeof( cvarTable ) / sizeof( cvarTable[0] ); + +/* +================= +CG_RegisterCvars +================= +*/ +void CG_RegisterCvars( void ) { + int i; + cvarTable_t *cv; + char var[MAX_TOKEN_CHARS]; + + trap_Cvar_Set( "cg_letterbox", "0" ); // force this for people who might have it in their + + for ( i = 0, cv = cvarTable ; i < cvarTableSize ; i++, cv++ ) { + trap_Cvar_Register( cv->vmCvar, cv->cvarName, + cv->defaultString, cv->cvarFlags ); + } + + // see if we are also running the server on this machine + trap_Cvar_VariableStringBuffer( "sv_running", var, sizeof( var ) ); + cgs.localServer = atoi( var ); + + forceModelModificationCount = cg_forceModel.modificationCount; + + trap_Cvar_Register( NULL, "model", DEFAULT_MODEL, CVAR_USERINFO | CVAR_ARCHIVE ); + trap_Cvar_Register( NULL, "head", DEFAULT_HEAD, CVAR_USERINFO | CVAR_ARCHIVE ); + + +} + +/* +=================== +CG_ForceModelChange +=================== +*/ +// TTimo: unused +/* +static void CG_ForceModelChange( void ) { + int i; + + for (i=0 ; ivmCvar ); + } +/* RF, disabled this, not needed anymore + // if force model changed + if ( forceModelModificationCount != cg_forceModel.modificationCount ) { + forceModelModificationCount = cg_forceModel.modificationCount; + CG_ForceModelChange(); + } +*/ +} + + +int CG_CrosshairPlayer( void ) { + if ( cg.time > ( cg.crosshairClientTime + 1000 ) ) { + return -1; + } + return cg.crosshairClientNum; +} + +int CG_LastAttacker( void ) { + if ( !cg.attackerTime ) { + return -1; + } + return cg.snap->ps.persistant[PERS_ATTACKER]; +} + +void QDECL CG_Printf( const char *msg, ... ) { + va_list argptr; + char text[1024]; + + va_start( argptr, msg ); + vsprintf( text, msg, argptr ); + va_end( argptr ); + + trap_Print( text ); +} + +void QDECL CG_Error( const char *msg, ... ) { + va_list argptr; + char text[1024]; + + va_start( argptr, msg ); + vsprintf( text, msg, argptr ); + va_end( argptr ); + + trap_Error( text ); +} + +// TTimo: was commented out for Mac, guarding +#if !defined( CGAME_HARD_LINKED ) || defined( __MACOS__ ) +// this is only here so the functions in q_shared.c and bg_*.c can link (FIXME) + +void QDECL Com_Error( int level, const char *error, ... ) { + va_list argptr; + char text[1024]; + + va_start( argptr, error ); + vsprintf( text, error, argptr ); + va_end( argptr ); + + CG_Error( "%s", text ); +} + +void QDECL Com_Printf( const char *msg, ... ) { + va_list argptr; + char text[1024]; + + va_start( argptr, msg ); + vsprintf( text, msg, argptr ); + va_end( argptr ); + + CG_Printf( "%s", text ); +} + +#endif + +/* +================ +CG_Argv +================ +*/ +const char *CG_Argv( int arg ) { + static char buffer[MAX_STRING_CHARS]; + + trap_Argv( arg, buffer, sizeof( buffer ) ); + + return buffer; +} + + +//======================================================================== +void CG_SetupDlightstyles( void ) { + int i, j; + char *str; + char *token; + int entnum; + centity_t *cent; + + cg.lightstylesInited = qtrue; + + for ( i = 1; i < MAX_DLIGHT_CONFIGSTRINGS; i++ ) + { + str = (char *) CG_ConfigString( CS_DLIGHTS + i ); + if ( !strlen( str ) ) { + break; + } + + token = COM_Parse( &str ); // ent num + entnum = atoi( token ); + cent = &cg_entities[entnum]; + + token = COM_Parse( &str ); // stylestring + Q_strncpyz( cent->dl_stylestring, token, strlen( token ) ); + + token = COM_Parse( &str ); // offset + cent->dl_frame = atoi( token ); + cent->dl_oldframe = cent->dl_frame - 1; + if ( cent->dl_oldframe < 0 ) { + cent->dl_oldframe = strlen( cent->dl_stylestring ); + } + + token = COM_Parse( &str ); // sound id + cent->dl_sound = atoi( token ); + + token = COM_Parse( &str ); // attenuation + cent->dl_atten = atoi( token ); + + for ( j = 0; j < strlen( cent->dl_stylestring ); j++ ) { + + cent->dl_stylestring[j] += cent->dl_atten; // adjust character for attenuation/amplification + + // clamp result + if ( cent->dl_stylestring[j] < 'a' ) { + cent->dl_stylestring[j] = 'a'; + } + if ( cent->dl_stylestring[j] > 'z' ) { + cent->dl_stylestring[j] = 'z'; + } + } + + cent->dl_backlerp = 0.0; + cent->dl_time = cg.time; + } + +} + +//======================================================================== + +/* +================= +CG_RegisterItemSounds + +The server says this item is used on this level +================= +*/ +static void CG_RegisterItemSounds( int itemNum ) { + gitem_t *item; + char data[MAX_QPATH]; + char *s, *start; + int len; + + item = &bg_itemlist[ itemNum ]; + + if ( item->pickup_sound ) { + trap_S_RegisterSound( item->pickup_sound ); + } + + // parse the space seperated precache string for other media + s = item->sounds; + if ( !s || !s[0] ) { + return; + } + + while ( *s ) { + start = s; + while ( *s && *s != ' ' ) { + s++; + } + + len = s - start; + if ( len >= MAX_QPATH || len < 5 ) { + CG_Error( "PrecacheItem: %s has bad precache string", + item->classname ); + return; + } + memcpy( data, start, len ); + data[len] = 0; + if ( *s ) { + s++; + } + + if ( !strcmp( data + len - 3, "wav" ) ) { + trap_S_RegisterSound( data ); + } + } +} + + +//----(SA) added + +// this is the only thing that sets a cap on # items. would like it to be adaptable. +// (rather than 256 max items with pickup name fixed at 32 chars) + +/* +============== +CG_LoadPickupNames +============== +*/ +#define MAX_BUFFER 20000 +static void CG_LoadPickupNames( void ) { + char buffer[MAX_BUFFER]; + char *text; + char filename[MAX_QPATH]; + fileHandle_t f; + int len, i; + char *token; + + Com_sprintf( filename, MAX_QPATH, "text/pickupnames.txt" ); + len = trap_FS_FOpenFile( filename, &f, FS_READ ); + if ( len <= 0 ) { + CG_Printf( S_COLOR_RED "WARNING: pickup name file (pickupnames.txt not found in main/text)\n" ); + return; + } + if ( len > MAX_BUFFER ) { + CG_Error( "%s is too big, make it smaller (max = %i bytes)\n", filename, MAX_BUFFER ); + } + + // load the file into memory + trap_FS_Read( buffer, len, f ); + buffer[len] = 0; + trap_FS_FCloseFile( f ); + // parse the list + text = buffer; + + for ( i = 0; i < bg_numItems; i++ ) { + token = COM_ParseExt( &text, qtrue ); + if ( !token[0] ) { + break; + } + if ( !Q_stricmp( token, "---" ) ) { // no name. use hardcoded value + if ( bg_itemlist[i].pickup_name && strlen( bg_itemlist[i].pickup_name ) ) { + Com_sprintf( cgs.itemPrintNames[i], MAX_QPATH, bg_itemlist[ i ].pickup_name ); + } else { + cgs.itemPrintNames[i][0] = 0; + } + } else { + Com_sprintf( cgs.itemPrintNames[i], MAX_QPATH, token ); + } + } +} + +// a straight dupe right now so I don't mess anything up while adding this +static void CG_LoadTranslationStrings( void ) { + char buffer[MAX_BUFFER]; + char *text; + char filename[MAX_QPATH]; + fileHandle_t f; + int len, i, numStrings; + char *token; + + Com_sprintf( filename, MAX_QPATH, "text/strings.txt" ); + len = trap_FS_FOpenFile( filename, &f, FS_READ ); + if ( len <= 0 ) { + CG_Printf( S_COLOR_RED "WARNING: string translation file (strings.txt not found in main/text)\n" ); + return; + } + if ( len > MAX_BUFFER ) { + CG_Error( "%s is too big, make it smaller (max = %i bytes)\n", filename, MAX_BUFFER ); + } + + // load the file into memory + trap_FS_Read( buffer, len, f ); + buffer[len] = 0; + trap_FS_FCloseFile( f ); + // parse the list + text = buffer; + + numStrings = sizeof( translateStrings ) / sizeof( translateStrings[0] ) - 1; + + for ( i = 0; i < numStrings; i++ ) { + token = COM_ParseExt( &text, qtrue ); + if ( !token[0] ) { + break; + } + translateStrings[i].localname = malloc( strlen( token ) + 1 ); + strcpy( translateStrings[i].localname, token ); + } +} + + +static void CG_LoadTranslateStrings( void ) { + CG_LoadPickupNames(); + CG_LoadTranslationStrings(); // right now just centerprint +} + +//----(SA) end + + +/* +================= +CG_RegisterSounds + +called during a precache command +================= +*/ +static void CG_RegisterSounds( void ) { + int i; + char items[MAX_ITEMS + 1]; + char name[MAX_QPATH]; + const char *soundName; + + // Ridah, init sound scripts + CG_SoundInit(); + // done. + + cgs.media.n_health = trap_S_RegisterSound( "sound/items/n_health.wav" ); + cgs.media.noFireUnderwater = trap_S_RegisterSound( "sound/weapons/underwaterfire.wav" ); //----(SA) added + + cgs.media.snipersound = trap_S_RegisterSound( "sound/weapons/mauser/mauserf1.wav" ); + cgs.media.tracerSound = trap_S_RegisterSound( "sound/weapons/machinegun/buletby1.wav" ); + cgs.media.selectSound = trap_S_RegisterSound( "sound/weapons/change.wav" ); + cgs.media.wearOffSound = trap_S_RegisterSound( "sound/items/wearoff.wav" ); + cgs.media.useNothingSound = trap_S_RegisterSound( "sound/items/use_nothing.wav" ); + cgs.media.gibSound = trap_S_RegisterSound( "sound/player/gibsplt1.wav" ); + cgs.media.gibBounce1Sound = trap_S_RegisterSound( "sound/player/gibimp1.wav" ); + cgs.media.gibBounce2Sound = trap_S_RegisterSound( "sound/player/gibimp2.wav" ); + cgs.media.gibBounce3Sound = trap_S_RegisterSound( "sound/player/gibimp3.wav" ); + +// cgs.media.teleInSound = trap_S_RegisterSound( "sound/world/telein.wav" ); +// cgs.media.teleOutSound = trap_S_RegisterSound( "sound/world/teleout.wav" ); +// cgs.media.respawnSound = trap_S_RegisterSound( "sound/items/respawn1.wav" ); + + + cgs.media.grenadebounce[GRENBOUNCE_DEFAULT][0] = trap_S_RegisterSound( "sound/weapons/grenade/hgrenb1a.wav" ); + cgs.media.grenadebounce[GRENBOUNCE_DEFAULT][1] = trap_S_RegisterSound( "sound/weapons/grenade/hgrenb2a.wav" ); + cgs.media.grenadebounce[GRENBOUNCE_DIRT][0] = trap_S_RegisterSound( "sound/weapons/grenade/hg_dirt1a.wav" ); + cgs.media.grenadebounce[GRENBOUNCE_DIRT][1] = trap_S_RegisterSound( "sound/weapons/grenade/hg_dirt2a.wav" ); + cgs.media.grenadebounce[GRENBOUNCE_WOOD][0] = trap_S_RegisterSound( "sound/weapons/grenade/hg_wood1a.wav" ); + cgs.media.grenadebounce[GRENBOUNCE_WOOD][1] = trap_S_RegisterSound( "sound/weapons/grenade/hg_wood2a.wav" ); + cgs.media.grenadebounce[GRENBOUNCE_METAL][0] = trap_S_RegisterSound( "sound/weapons/grenade/hg_metal1a.wav" ); + cgs.media.grenadebounce[GRENBOUNCE_METAL][1] = trap_S_RegisterSound( "sound/weapons/grenade/hg_metal2a.wav" ); + + cgs.media.dynamitebounce1 = trap_S_RegisterSound( "sound/weapons/dynamite/dynamite_bounce.wav" ); + + cgs.media.fbarrelexp1 = trap_S_RegisterSound( "sound/weapons/flamebarrel/fbarrela.wav" ); + cgs.media.fbarrelexp2 = trap_S_RegisterSound( "sound/weapons/flamebarrel/fbarrelb.wav" ); + + + cgs.media.fkickwall = trap_S_RegisterSound( "sound/weapons/melee/fstatck.wav" ); + cgs.media.fkickflesh = trap_S_RegisterSound( "sound/weapons/melee/fstatck.wav" ); + cgs.media.fkickmiss = trap_S_RegisterSound( "sound/weapons/melee/fstmiss.wav" ); + + + cgs.media.noAmmoSound = trap_S_RegisterSound( "sound/weapons/noammo.wav" ); + + cgs.media.talkSound = trap_S_RegisterSound( "sound/player/talk.wav" ); + cgs.media.landSound = trap_S_RegisterSound( "sound/player/land1.wav" ); + + cgs.media.watrInSound = trap_S_RegisterSound( "sound/player/watr_in.wav" ); + cgs.media.watrOutSound = trap_S_RegisterSound( "sound/player/watr_out.wav" ); + cgs.media.watrUnSound = trap_S_RegisterSound( "sound/player/watr_un.wav" ); + + cgs.media.underWaterSound = trap_S_RegisterSound( "sound/world/underwater03.wav" ); + + for ( i = 0 ; i < 4 ; i++ ) { + Com_sprintf( name, sizeof( name ), "sound/player/footsteps/step%i.wav", i + 1 ); + cgs.media.footsteps[FOOTSTEP_NORMAL][i] = trap_S_RegisterSound( name ); + + Com_sprintf( name, sizeof( name ), "sound/player/footsteps/boot%i.wav", i + 1 ); + cgs.media.footsteps[FOOTSTEP_BOOT][i] = trap_S_RegisterSound( name ); + + Com_sprintf( name, sizeof( name ), "sound/player/footsteps/flesh%i.wav", i + 1 ); + cgs.media.footsteps[FOOTSTEP_FLESH][i] = trap_S_RegisterSound( name ); + + Com_sprintf( name, sizeof( name ), "sound/player/footsteps/mech%i.wav", i + 1 ); + cgs.media.footsteps[FOOTSTEP_MECH][i] = trap_S_RegisterSound( name ); + + Com_sprintf( name, sizeof( name ), "sound/player/footsteps/energy%i.wav", i + 1 ); + cgs.media.footsteps[FOOTSTEP_ENERGY][i] = trap_S_RegisterSound( name ); + + Com_sprintf( name, sizeof( name ), "sound/player/footsteps/splash%i.wav", i + 1 ); + cgs.media.footsteps[FOOTSTEP_SPLASH][i] = trap_S_RegisterSound( name ); + + Com_sprintf( name, sizeof( name ), "sound/player/footsteps/clank%i.wav", i + 1 ); + cgs.media.footsteps[FOOTSTEP_METAL][i] = trap_S_RegisterSound( name ); + + + // (SA) Wolf footstep sound registration + Com_sprintf( name, sizeof( name ), "sound/player/footsteps/wood%i.wav", i + 1 ); + cgs.media.footsteps[FOOTSTEP_WOOD][i] = trap_S_RegisterSound( name ); + + Com_sprintf( name, sizeof( name ), "sound/player/footsteps/grass%i.wav", i + 1 ); + cgs.media.footsteps[FOOTSTEP_GRASS][i] = trap_S_RegisterSound( name ); + + Com_sprintf( name, sizeof( name ), "sound/player/footsteps/gravel%i.wav", i + 1 ); + cgs.media.footsteps[FOOTSTEP_GRAVEL][i] = trap_S_RegisterSound( name ); + + Com_sprintf( name, sizeof( name ), "sound/player/footsteps/roof%i.wav", i + 1 ); + cgs.media.footsteps[FOOTSTEP_ROOF][i] = trap_S_RegisterSound( name ); + + Com_sprintf( name, sizeof( name ), "sound/player/footsteps/snow%i.wav", i + 1 ); + cgs.media.footsteps[FOOTSTEP_SNOW][i] = trap_S_RegisterSound( name ); + + Com_sprintf( name, sizeof( name ), "sound/player/footsteps/carpet%i.wav", i + 1 ); //----(SA) + cgs.media.footsteps[FOOTSTEP_CARPET][i] = trap_S_RegisterSound( name ); + } + + // only register the items that the server says we need + strcpy( items, CG_ConfigString( CS_ITEMS ) ); + + for ( i = 1 ; i < bg_numItems ; i++ ) { + if ( items[ i ] == '1' || cg_buildScript.integer ) { + CG_RegisterItemSounds( i ); + } + } + + for ( i = 1 ; i < MAX_SOUNDS ; i++ ) { + soundName = CG_ConfigString( CS_SOUNDS + i ); + if ( !soundName[0] ) { + break; + } + if ( soundName[0] == '*' ) { + continue; // custom sound + } + + // Ridah, register sound scripts seperately + if ( !strstr( soundName, ".wav" ) ) { + cgs.gameSounds[i] = CG_SoundScriptPrecache( soundName ); //----(SA) shouldn't this be okay? The cs index is reserved anyway, so it can't hurt, right? + cgs.gameSoundTypes[i] = 2; + } else { + cgs.gameSounds[i] = trap_S_RegisterSound( soundName ); + cgs.gameSoundTypes[i] = 1; + } + } + + //----(SA) added + cgs.media.grenadePulseSound4 = trap_S_RegisterSound( "sound/weapons/grenade/grenpulse4.wav" ); + cgs.media.grenadePulseSound3 = trap_S_RegisterSound( "sound/weapons/grenade/grenpulse3.wav" ); + cgs.media.grenadePulseSound2 = trap_S_RegisterSound( "sound/weapons/grenade/grenpulse2.wav" ); + cgs.media.grenadePulseSound1 = trap_S_RegisterSound( "sound/weapons/grenade/grenpulse1.wav" ); + //----(SA) end + + //----(SA) added + cgs.media.debBounce1Sound = trap_S_RegisterSound( "sound/world/block.wav" ); + cgs.media.debBounce2Sound = trap_S_RegisterSound( "sound/world/brick.wav" ); + cgs.media.debBounce3Sound = trap_S_RegisterSound( "sound/world/brick2.wav" ); + + // Ridah + cgs.media.flameSound = trap_S_RegisterSound( "sound/weapons/flamethrower/fl_fire.wav" ); + cgs.media.flameBlowSound = trap_S_RegisterSound( "sound/weapons/flamethrower/fl_blow.wav" ); + cgs.media.flameStartSound = trap_S_RegisterSound( "sound/weapons/flamethrower/fl_start.wav" ); + cgs.media.flameStreamSound = trap_S_RegisterSound( "sound/weapons/flamethrower/fl_stream.wav" ); + cgs.media.flameCrackSound = trap_S_RegisterSound( "sound/world/firecrack1.wav" ); + cgs.media.boneBounceSound = trap_S_RegisterSound( "sound/world/boardbreak.wav" ); // TODO: need a real sound for this + + cgs.media.lightningSounds[0] = trap_S_RegisterSound( "sound/world/electzap1.wav" ); + cgs.media.lightningSounds[1] = trap_S_RegisterSound( "sound/world/electzap2.wav" ); + cgs.media.lightningSounds[2] = trap_S_RegisterSound( "sound/world/electzap3.wav" ); + cgs.media.lightningZap = trap_S_RegisterSound( "sound/world/electrocute.wav" ); + + // precache sound scripts that get called from the cgame + cgs.media.bulletHitFleshScript = CG_SoundScriptPrecache( "bulletHitFlesh" ); + cgs.media.bulletHitFleshMetalScript = CG_SoundScriptPrecache( "bulletHitFleshMetal" ); + + cgs.media.teslaZapScript = CG_SoundScriptPrecache( "teslaZap" ); + cgs.media.teslaLoopSound = trap_S_RegisterSound( "sound/weapons/tesla/loop.wav" ); + + cgs.media.batsFlyingLoopSound = trap_S_RegisterSound( "sound/world/bats_flying.wav" ); + + // FIXME: only needed with item +// cgs.media.flightSound = trap_S_RegisterSound( "sound/items/flight.wav" ); +// cgs.media.medkitSound = trap_S_RegisterSound ("sound/items/use_medkit.wav"); + cgs.media.elecSound = trap_S_RegisterSound( "sound/items/use_elec.wav" ); + cgs.media.fireSound = trap_S_RegisterSound( "sound/items/use_fire.wav" ); + cgs.media.waterSound = trap_S_RegisterSound( "sound/items/use_water.wav" ); + cgs.media.wineSound = trap_S_RegisterSound( "sound/pickup/holdable/use_wine.wav" ); //----(SA) modified + cgs.media.bookSound = trap_S_RegisterSound( "sound/pickup/holdable/use_book.wav" ); //----(SA) added + cgs.media.staminaSound = trap_S_RegisterSound( "sound/pickup/holdable/use_stamina.wav" ); //----(SA) added + cgs.media.quadSound = trap_S_RegisterSound( "sound/items/damage3.wav" ); + cgs.media.sfx_ric1 = trap_S_RegisterSound( "sound/weapons/machinegun/ric1.wav" ); + cgs.media.sfx_ric2 = trap_S_RegisterSound( "sound/weapons/machinegun/ric2.wav" ); + cgs.media.sfx_ric3 = trap_S_RegisterSound( "sound/weapons/machinegun/ric3.wav" ); +// cgs.media.sfx_railg = trap_S_RegisterSound ("sound/weapons/railgun/railgf1a.wav"); + cgs.media.sfx_rockexp = trap_S_RegisterSound( "sound/weapons/rocket/rocklx1a.wav" ); + cgs.media.sfx_dynamiteexp = trap_S_RegisterSound( "sound/weapons/dynamite/dynamite_exp.wav" ); + cgs.media.sfx_dynamiteexpDist = trap_S_RegisterSound( "sound/weapons/dynamite/dynamite_exp_dist.wav" ); //----(SA) added + + + cgs.media.sfx_spearhit = trap_S_RegisterSound( "sound/weapons/speargun/spearhit.wav" ); + + cgs.media.sfx_knifehit[0] = trap_S_RegisterSound( "sound/weapons/knife/knife_hit1.wav" ); // hitting player + cgs.media.sfx_knifehit[1] = trap_S_RegisterSound( "sound/weapons/knife/knife_hit2.wav" ); + cgs.media.sfx_knifehit[2] = trap_S_RegisterSound( "sound/weapons/knife/knife_hit3.wav" ); + cgs.media.sfx_knifehit[3] = trap_S_RegisterSound( "sound/weapons/knife/knife_hit4.wav" ); + + cgs.media.sfx_knifehit[4] = trap_S_RegisterSound( "sound/weapons/knife/knife_hitwall1.wav" ); // hitting wall + + cgs.media.sfx_bullet_metalhit[0] = trap_S_RegisterSound( "sound/weapons/bullethit_metal1.wav" ); + cgs.media.sfx_bullet_metalhit[1] = trap_S_RegisterSound( "sound/weapons/bullethit_metal2.wav" ); + cgs.media.sfx_bullet_metalhit[2] = trap_S_RegisterSound( "sound/weapons/bullethit_metal3.wav" ); + + cgs.media.sfx_bullet_woodhit[0] = trap_S_RegisterSound( "sound/weapons/bullethit_wood1.wav" ); + cgs.media.sfx_bullet_woodhit[1] = trap_S_RegisterSound( "sound/weapons/bullethit_wood2.wav" ); + cgs.media.sfx_bullet_woodhit[2] = trap_S_RegisterSound( "sound/weapons/bullethit_wood3.wav" ); + + cgs.media.sfx_bullet_roofhit[0] = trap_S_RegisterSound( "sound/weapons/bullethit_roof1.wav" ); + cgs.media.sfx_bullet_roofhit[1] = trap_S_RegisterSound( "sound/weapons/bullethit_roof2.wav" ); + cgs.media.sfx_bullet_roofhit[2] = trap_S_RegisterSound( "sound/weapons/bullethit_roof3.wav" ); + + cgs.media.sfx_bullet_ceramichit[0] = trap_S_RegisterSound( "sound/weapons/bullethit_ceramic1.wav" ); + cgs.media.sfx_bullet_ceramichit[1] = trap_S_RegisterSound( "sound/weapons/bullethit_ceramic2.wav" ); + cgs.media.sfx_bullet_ceramichit[2] = trap_S_RegisterSound( "sound/weapons/bullethit_ceramic3.wav" ); + + cgs.media.sfx_bullet_glasshit[0] = trap_S_RegisterSound( "sound/weapons/bullethit_glass1.wav" ); + cgs.media.sfx_bullet_glasshit[1] = trap_S_RegisterSound( "sound/weapons/bullethit_glass2.wav" ); + cgs.media.sfx_bullet_glasshit[2] = trap_S_RegisterSound( "sound/weapons/bullethit_glass3.wav" ); + + + cgs.media.sparkSounds[0] = trap_S_RegisterSound( "sound/world/saarc2.wav" ); + cgs.media.sparkSounds[1] = trap_S_RegisterSound( "sound/world/arc2.wav" ); + + +//----(SA) doors and kick + + //----(SA) removed some unnecessary stuff + + trap_S_RegisterSound( "sound/weapons/melee/fstatck.wav" ); + trap_S_RegisterSound( "sound/weapons/melee/fstmiss.wav" ); + + trap_S_RegisterSound( "sound/Loogie/spit.wav" ); + trap_S_RegisterSound( "sound/Loogie/sizzle.wav" ); + +} + + +//=================================================================================== + + + +/* +================= +CG_RegisterGraphics + +This function may execute for a couple of minutes with a slow disk. +================= +*/ +static void CG_RegisterGraphics( void ) { + char name[1024]; + + int i; + char items[MAX_ITEMS + 1]; + static char *sb_nums[11] = { + "gfx/2d/numbers/zero_32b", + "gfx/2d/numbers/one_32b", + "gfx/2d/numbers/two_32b", + "gfx/2d/numbers/three_32b", + "gfx/2d/numbers/four_32b", + "gfx/2d/numbers/five_32b", + "gfx/2d/numbers/six_32b", + "gfx/2d/numbers/seven_32b", + "gfx/2d/numbers/eight_32b", + "gfx/2d/numbers/nine_32b", + "gfx/2d/numbers/minus_32b", + }; + + + // clear any references to old media + memset( &cg.refdef, 0, sizeof( cg.refdef ) ); + trap_R_ClearScene(); + + CG_LoadingString( cgs.mapname ); + + trap_R_LoadWorldMap( cgs.mapname ); + + // precache status bar pics + CG_LoadingString( "game media" ); + + + CG_LoadingString( " - textures" ); + + for ( i = 0 ; i < 11 ; i++ ) { + cgs.media.numberShaders[i] = trap_R_RegisterShader( sb_nums[i] ); + } + + + cgs.media.smokePuffShader = trap_R_RegisterShader( "smokePuff" ); + + // Rafael - blood pool + //cgs.media.bloodPool = trap_R_RegisterShader ("bloodPool"); + + // RF, blood cloud + cgs.media.bloodCloudShader = trap_R_RegisterShader( "bloodCloud" ); + + // Rafael - cannon + cgs.media.smokePuffShaderdirty = trap_R_RegisterShader( "smokePuffdirty" ); + cgs.media.smokePuffShaderb1 = trap_R_RegisterShader( "smokePuffblack1" ); + cgs.media.smokePuffShaderb2 = trap_R_RegisterShader( "smokePuffblack2" ); + cgs.media.smokePuffShaderb3 = trap_R_RegisterShader( "smokePuffblack3" ); + cgs.media.smokePuffShaderb4 = trap_R_RegisterShader( "smokePuffblack4" ); + cgs.media.smokePuffShaderb5 = trap_R_RegisterShader( "smokePuffblack5" ); + // done + + // Rafael - bleedanim + for ( i = 0; i < 5; i++ ) { + cgs.media.viewBloodAni[i] = trap_R_RegisterShader( va( "viewBloodBlend%i", i + 1 ) ); + } + cgs.media.viewFlashBlood = trap_R_RegisterShader( "viewFlashBlood" ); + for ( i = 0; i < 16; i++ ) { + cgs.media.viewFlashFire[i] = trap_R_RegisterShader( va( "viewFlashFire%i", i + 1 ) ); + } + // done + + // Rafael bats + for ( i = 0; i < 10; i++ ) { + cgs.media.bats[i] = trap_R_RegisterShader( va( "bats%i",i + 1 ) ); + } + // done + + cgs.media.smokePuffRageProShader = trap_R_RegisterShader( "smokePuffRagePro" ); + cgs.media.shotgunSmokePuffShader = trap_R_RegisterShader( "shotgunSmokePuff" ); + + cgs.media.bloodTrailShader = trap_R_RegisterShader( "bloodTrail" ); + cgs.media.lagometerShader = trap_R_RegisterShader( "lagometer" ); + cgs.media.connectionShader = trap_R_RegisterShader( "disconnected" ); + + cgs.media.nailPuffShader = trap_R_RegisterShader( "nailtrail" ); + + +// cgs.media.reticleShaderSimple = trap_R_RegisterShader( "gfx/misc/reticlesimple" ); // TODO: remove + cgs.media.reticleShaderSimpleQ = trap_R_RegisterShader( "gfx/misc/reticlesimple_quarter" ); + + cgs.media.snooperShaderSimple = trap_R_RegisterShader( "gfx/misc/snoopersimple" ); + +// cgs.media.binocShaderSimple = trap_R_RegisterShader( "gfx/misc/binocsimple" ); // TODO: remove + cgs.media.binocShaderSimpleQ = trap_R_RegisterShader( "gfx/misc/binocsimple_quarter" ); //----(SA) added + + + // Rafael + // cgs.media.snowShader = trap_R_RegisterShader ( "snowPuff" ); + cgs.media.snowShader = trap_R_RegisterShader( "snow_tri" ); + + cgs.media.oilParticle = trap_R_RegisterShader( "oilParticle" ); + cgs.media.oilSlick = trap_R_RegisterShader( "oilSlick" ); + + cgs.media.waterBubbleShader = trap_R_RegisterShader( "waterBubble" ); + + cgs.media.tracerShader = trap_R_RegisterShader( "gfx/misc/tracer" ); + cgs.media.selectShader = trap_R_RegisterShader( "gfx/2d/select" ); + + + cgs.media.hintShaders[HINT_ACTIVATE] = trap_R_RegisterShader( "gfx/2d/usableHint" ); + cgs.media.hintShaders[HINT_NOACTIVATE] = trap_R_RegisterShader( "gfx/2d/notUsableHint" ); + cgs.media.hintShaders[HINT_DOOR] = trap_R_RegisterShader( "gfx/2d/doorHint" ); + cgs.media.hintShaders[HINT_DOOR_ROTATING] = trap_R_RegisterShader( "gfx/2d/doorRotateHint" ); + cgs.media.hintShaders[HINT_DOOR_LOCKED] = trap_R_RegisterShader( "gfx/2d/doorLockHint" ); + cgs.media.hintShaders[HINT_DOOR_ROTATING_LOCKED] = trap_R_RegisterShader( "gfx/2d/doorRotateLockHint" ); + cgs.media.hintShaders[HINT_MG42] = trap_R_RegisterShader( "gfx/2d/mg42Hint" ); + cgs.media.hintShaders[HINT_BREAKABLE] = trap_R_RegisterShader( "gfx/2d/breakableHint" ); + cgs.media.hintShaders[HINT_CHAIR] = trap_R_RegisterShader( "gfx/2d/chairHint" ); + cgs.media.hintShaders[HINT_ALARM] = trap_R_RegisterShader( "gfx/2d/alarmHint" ); + cgs.media.hintShaders[HINT_HEALTH] = trap_R_RegisterShader( "gfx/2d/healthHint" ); + cgs.media.hintShaders[HINT_TREASURE] = trap_R_RegisterShader( "gfx/2d/treasureHint" ); + cgs.media.hintShaders[HINT_KNIFE] = trap_R_RegisterShader( "gfx/2d/knifeHint" ); + cgs.media.hintShaders[HINT_LADDER] = trap_R_RegisterShader( "gfx/2d/ladderHint" ); + cgs.media.hintShaders[HINT_BUTTON] = trap_R_RegisterShader( "gfx/2d/buttonHint" ); + cgs.media.hintShaders[HINT_WATER] = trap_R_RegisterShader( "gfx/2d/waterHint" ); + cgs.media.hintShaders[HINT_CAUTION] = trap_R_RegisterShader( "gfx/2d/cautionHint" ); + cgs.media.hintShaders[HINT_DANGER] = trap_R_RegisterShader( "gfx/2d/dangerHint" ); + cgs.media.hintShaders[HINT_SECRET] = trap_R_RegisterShader( "gfx/2d/secretHint" ); + cgs.media.hintShaders[HINT_QUESTION] = trap_R_RegisterShader( "gfx/2d/questionHint" ); + cgs.media.hintShaders[HINT_EXCLAMATION] = trap_R_RegisterShader( "gfx/2d/exclamationHint" ); + cgs.media.hintShaders[HINT_CLIPBOARD] = trap_R_RegisterShader( "gfx/2d/clipboardHint" ); + cgs.media.hintShaders[HINT_WEAPON] = trap_R_RegisterShader( "gfx/2d/weaponHint" ); + cgs.media.hintShaders[HINT_AMMO] = trap_R_RegisterShader( "gfx/2d/ammoHint" ); + cgs.media.hintShaders[HINT_ARMOR] = trap_R_RegisterShader( "gfx/2d/armorHint" ); + cgs.media.hintShaders[HINT_POWERUP] = trap_R_RegisterShader( "gfx/2d/powerupHint" ); + cgs.media.hintShaders[HINT_HOLDABLE] = trap_R_RegisterShader( "gfx/2d/holdableHint" ); + cgs.media.hintShaders[HINT_INVENTORY] = trap_R_RegisterShader( "gfx/2d/inventoryHint" ); + cgs.media.hintShaders[HINT_EXIT] = trap_R_RegisterShader( "gfx/2d/exitHint" ); + cgs.media.hintShaders[HINT_NOEXIT] = cgs.media.hintShaders[HINT_EXIT]; + cgs.media.hintShaders[HINT_EXIT_FAR] = cgs.media.hintShaders[HINT_EXIT]; + cgs.media.hintShaders[HINT_NOEXIT_FAR] = cgs.media.hintShaders[HINT_EXIT]; + +// cgs.media.hintShaders[HINT_PLYR_FRIEND] = trap_R_RegisterShader( "gfx/2d/hintPlrFriend" ); +// cgs.media.hintShaders[HINT_PLYR_NEUTRAL] = trap_R_RegisterShader( "gfx/2d/hintPlrNeutral" ); +// cgs.media.hintShaders[HINT_PLYR_ENEMY] = trap_R_RegisterShader( "gfx/2d/hintPlrEnemy" ); +// cgs.media.hintShaders[HINT_PLYR_UNKNOWN] = trap_R_RegisterShader( "gfx/2d/hintPlrUnknown" ); + +// cgs.media.hintShaders[HINT_BUILD] = trap_R_RegisterShader( "gfx/2d/buildHint" ); // DHM - Nerve + + cgs.media.youGotMailShader = trap_R_RegisterShader( "gfx/2d/yougotmail" ); //----(SA) added + cgs.media.youGotObjectiveShader = trap_R_RegisterShader( "gfx/2d/yougotobjective" ); //----(SA) added + +//----(SA) end + + for ( i = 0 ; i < NUM_CROSSHAIRS ; i++ ) { + cgs.media.crosshairShader[i] = trap_R_RegisterShaderNoMip( va( "gfx/2d/crosshair%c", 'a' + i ) ); + } + + cgs.media.crosshairFriendly = trap_R_RegisterShader( "gfx/2d/friendlycross" ); //----(SA) added + + cgs.media.backTileShader = trap_R_RegisterShader( "gfx/2d/backtile" ); + cgs.media.noammoShader = trap_R_RegisterShader( "icons/noammo" ); + + // powerup shaders +// cgs.media.quadShader = trap_R_RegisterShader("powerups/quad" ); +// cgs.media.quadWeaponShader = trap_R_RegisterShader("powerups/quadWeapon" ); +// cgs.media.battleSuitShader = trap_R_RegisterShader("powerups/battleSuit" ); +// cgs.media.battleWeaponShader = trap_R_RegisterShader("powerups/battleWeapon" ); +// cgs.media.invisShader = trap_R_RegisterShader("powerups/invisibility" ); +// cgs.media.regenShader = trap_R_RegisterShader("powerups/regen" ); +// cgs.media.hastePuffShader = trap_R_RegisterShader("hasteSmokePuff" ); + + // DHM - Nerve :: Allow flags again, will change later to more appropriate models + if ( cgs.gametype == GT_CTF || cgs.gametype == GT_WOLF || cg_buildScript.integer ) { + cgs.media.redFlagModel = trap_R_RegisterModel( "models/flags/r_flag.md3" ); + //cgs.media.redFlagModel = trap_R_RegisterModel( "models/powerups/keys/chalice.md3" ); + cgs.media.blueFlagModel = trap_R_RegisterModel( "models/flags/b_flag.md3" ); + } + +// if ( cgs.gametype >= GT_TEAM || cg_buildScript.integer ) { +// cgs.media.friendShader = trap_R_RegisterShader( "sprites/foe" ); +// cgs.media.redQuadShader = trap_R_RegisterShader("powerups/blueflag" ); +// cgs.media.teamStatusBar = trap_R_RegisterShader( "gfx/2d/colorbar.tga" ); +// } + + CG_LoadingString( " - models" ); + + cgs.media.machinegunBrassModel = trap_R_RegisterModel( "models/weapons2/shells/m_shell.md3" ); + cgs.media.panzerfaustBrassModel = trap_R_RegisterModel( "models/weapons2/shells/pf_shell.md3" ); + cgs.media.smallgunBrassModel = trap_R_RegisterModel( "models/weapons2/shells/sm_shell.md3" ); + + cgs.media.debBlock[0] = trap_R_RegisterModel( "models/mapobjects/debris/brick1.md3" ); + cgs.media.debBlock[1] = trap_R_RegisterModel( "models/mapobjects/debris/brick2.md3" ); + cgs.media.debBlock[2] = trap_R_RegisterModel( "models/mapobjects/debris/brick3.md3" ); + cgs.media.debBlock[3] = trap_R_RegisterModel( "models/mapobjects/debris/brick4.md3" ); + cgs.media.debBlock[4] = trap_R_RegisterModel( "models/mapobjects/debris/brick5.md3" ); + cgs.media.debBlock[5] = trap_R_RegisterModel( "models/mapobjects/debris/brick6.md3" ); + + cgs.media.debRock[0] = trap_R_RegisterModel( "models/mapobjects/debris/rubble1.md3" ); + cgs.media.debRock[1] = trap_R_RegisterModel( "models/mapobjects/debris/rubble2.md3" ); + cgs.media.debRock[2] = trap_R_RegisterModel( "models/mapobjects/debris/rubble3.md3" ); + + + cgs.media.debWood[0] = trap_R_RegisterModel( "models/gibs/wood/wood1.md3" ); + cgs.media.debWood[1] = trap_R_RegisterModel( "models/gibs/wood/wood2.md3" ); + cgs.media.debWood[2] = trap_R_RegisterModel( "models/gibs/wood/wood3.md3" ); + cgs.media.debWood[3] = trap_R_RegisterModel( "models/gibs/wood/wood4.md3" ); + cgs.media.debWood[4] = trap_R_RegisterModel( "models/gibs/wood/wood5.md3" ); + cgs.media.debWood[5] = trap_R_RegisterModel( "models/gibs/wood/wood6.md3" ); +// cgs.media.debWoodl = trap_R_RegisterModel( "models/mapobjects/debris/woodxl.md3" ); +// cgs.media.debWoodm = trap_R_RegisterModel( "models/mapobjects/debris/woodm.md3" ); +// cgs.media.debWoods = trap_R_RegisterModel( "models/mapobjects/debris/woodsm.md3" ); + + cgs.media.debFabric[0] = trap_R_RegisterModel( "models/shards/fabric1.md3" ); + cgs.media.debFabric[1] = trap_R_RegisterModel( "models/shards/fabric2.md3" ); + cgs.media.debFabric[2] = trap_R_RegisterModel( "models/shards/fabric3.md3" ); + + //----(SA) end + +// cgs.media.medicReviveShader = trap_R_RegisterShader( "sprites/medic_revive" ); //----(SA) commented out from MP + cgs.media.balloonShader = trap_R_RegisterShader( "sprites/balloon3" ); + + for ( i = 0; i < MAX_AISTATES; i++ ) { + cgs.media.aiStateShaders[i] = trap_R_RegisterShader( va( "sprites/aistate%i", i + 1 ) ); + } + + cgs.media.bloodExplosionShader = trap_R_RegisterShader( "bloodExplosion" ); + + //cgs.media.bleedExplosionShader = trap_R_RegisterShader( "bleedExplosion" ); + + //----(SA) water splash + //cgs.media.waterSplashModel = trap_R_RegisterModel("models/weaphits/bullet.md3"); + //cgs.media.waterSplashShader = trap_R_RegisterShader( "waterSplash" ); + //----(SA) end + + //cgs.media.spearModel = trap_R_RegisterModel("models/weaphits/spear.md3"); //----(SA) + + //cgs.media.bulletFlashModel = trap_R_RegisterModel("models/weaphits/bullet.md3"); + //cgs.media.ringFlashModel = trap_R_RegisterModel("models/weaphits/ring02.md3"); + //cgs.media.dishFlashModel = trap_R_RegisterModel("models/weaphits/boom01.md3"); +// cgs.media.teleportEffectModel = trap_R_RegisterModel( "models/misc/telep.md3" ); +// cgs.media.teleportEffectShader = trap_R_RegisterShader( "teleportEffect" ); + +// cgs.media.batModel = trap_R_RegisterModel( "models/mapobjects/bat/bat.md3" ); + +// cgs.media.medalImpressive = trap_R_RegisterShaderNoMip( "medal_impressive" ); +// cgs.media.medalExcellent = trap_R_RegisterShaderNoMip( "medal_excellent" ); +// cgs.media.medalGauntlet = trap_R_RegisterShaderNoMip( "medal_gauntlet" ); + + // Ridah, spark particles + cgs.media.sparkParticleShader = trap_R_RegisterShader( "sparkParticle" ); + cgs.media.smokeTrailShader = trap_R_RegisterShader( "smokeTrail" ); +// cgs.media.fireTrailShader = trap_R_RegisterShader( "fireTrail" ); + cgs.media.lightningBoltShader = trap_R_RegisterShader( "lightningBolt" ); + //cgs.media.lightningBoltShaderGreen = trap_R_RegisterShader( "lightningBoltGreen" ); //----(SA) alternate lightning color + cgs.media.flamethrowerFireStream = trap_R_RegisterShader( "flamethrowerFireStream" ); + cgs.media.flamethrowerBlueStream = trap_R_RegisterShader( "flamethrowerBlueStream" ); + //cgs.media.flamethrowerFuelStream = trap_R_RegisterShader( "flamethrowerFuelStream" ); + //cgs.media.flamethrowerFuelShader = trap_R_RegisterShader( "flamethrowerFuel" ); + cgs.media.onFireShader2 = trap_R_RegisterShader( "entityOnFire1" ); + cgs.media.onFireShader = trap_R_RegisterShader( "entityOnFire2" ); + //cgs.media.dripWetShader2 = trap_R_RegisterShader( "dripWet2" ); + //cgs.media.dripWetShader = trap_R_RegisterShader( "dripWet1" ); + cgs.media.viewFadeBlack = trap_R_RegisterShader( "viewFadeBlack" ); + cgs.media.sparkFlareShader = trap_R_RegisterShader( "sparkFlareParticle" ); + + // spotlight + // shaders + cgs.media.spotLightShader = trap_R_RegisterShader( "spotLight" ); + cgs.media.spotLightBeamShader = trap_R_RegisterShader( "lightBeam" ); + + // models + cgs.media.spotLightBaseModel = trap_R_RegisterModel( "models/mapobjects/light/searchlight1_b.md3" ); + cgs.media.spotLightLightModel = trap_R_RegisterModel( "models/mapobjects/light/searchlight1_l.md3" ); + cgs.media.spotLightLightModelBroke = trap_R_RegisterModel( "models/mapobjects/light/searchlight_l_broke.md3" ); + + // end spotlight + + cgs.media.lightningHitWallShader = trap_R_RegisterShader( "lightningHitWall" ); + cgs.media.lightningWaveShader = trap_R_RegisterShader( "lightningWave" ); + cgs.media.bulletParticleTrailShader = trap_R_RegisterShader( "bulletParticleTrail" ); + cgs.media.smokeParticleShader = trap_R_RegisterShader( "smokeParticle" ); + + // DHM - Nerve :: bullet hitting dirt + cgs.media.dirtParticle1Shader = trap_R_RegisterShader( "dirt_splash" ); + cgs.media.dirtParticle2Shader = trap_R_RegisterShader( "water_splash" ); + //cgs.media.dirtParticle3Shader = trap_R_RegisterShader( "dirtParticle3" ); + + cgs.media.teslaDamageEffectShader = trap_R_RegisterShader( "teslaDamageEffect" ); + cgs.media.teslaAltDamageEffectShader = trap_R_RegisterShader( "teslaAltDamageEffect" ); + cgs.media.viewTeslaDamageEffectShader = trap_R_RegisterShader( "viewTeslaDamageEffect" ); + cgs.media.viewTeslaAltDamageEffectShader = trap_R_RegisterShader( "viewTeslaAltDamageEffect" ); + // done. + + cgs.media.railCoreShader = trap_R_RegisterShader( "railCore" ); // (SA) for debugging server traces + + + cgs.media.thirdPersonBinocModel = trap_R_RegisterModel( "models/powerups/holdable/binocs_thirdperson.md3" ); //----(SA) added + cgs.media.cigModel = trap_R_RegisterModel( "models/players/infantryss/acc/cig.md3" ); //----(SA) added + + // RF, not used anymore + //cgs.media.targetEffectExplosionShader = trap_R_RegisterShader( "targetEffectExplode" ); + //cgs.media.rocketExplosionShader = trap_R_RegisterShader( "rocketExplosion" ); + //cgs.media.grenadeExplosionShader = trap_R_RegisterShader( "grenadeExplosion" ); + + // zombie shot + //cgs.media.zombieLoogie = trap_R_RegisterModel( "models/mapobjects/bodyparts/zom_loog.md3" ); + cgs.media.flamebarrel = trap_R_RegisterModel( "models/furniture/barrel/barrel_a.md3" ); + //----(SA) end + + cgs.media.mg42muzzleflash = trap_R_RegisterModel( "models/weapons2/machinegun/mg42_flash.md3" ); + // cgs.media.mg42muzzleflashgg = trap_R_RegisterModel ("models/weapons2/machinegun/mg42_flash_gg.md3" ); + + cgs.media.planemuzzleflash = trap_R_RegisterModel( "models/mapobjects/vehicles/gunflare.md3" ); + + cgs.media.crowbar = trap_R_RegisterModel( "models/weapons2/wrench/wrench.md3" ); + + // Rafael shards + cgs.media.shardGlass1 = trap_R_RegisterModel( "models/shards/glass1.md3" ); + cgs.media.shardGlass2 = trap_R_RegisterModel( "models/shards/glass2.md3" ); + cgs.media.shardWood1 = trap_R_RegisterModel( "models/shards/wood1.md3" ); + cgs.media.shardWood2 = trap_R_RegisterModel( "models/shards/wood2.md3" ); + cgs.media.shardMetal1 = trap_R_RegisterModel( "models/shards/metal1.md3" ); + cgs.media.shardMetal2 = trap_R_RegisterModel( "models/shards/metal2.md3" ); + cgs.media.shardCeramic1 = trap_R_RegisterModel( "models/shards/ceramic1.md3" ); + cgs.media.shardCeramic2 = trap_R_RegisterModel( "models/shards/ceramic2.md3" ); + // done + + cgs.media.shardRubble1 = trap_R_RegisterModel( "models/mapobjects/debris/brick000.md3" ); + cgs.media.shardRubble2 = trap_R_RegisterModel( "models/mapobjects/debris/brick001.md3" ); + cgs.media.shardRubble3 = trap_R_RegisterModel( "models/mapobjects/debris/brick002.md3" ); + + for ( i = 0; i < MAX_LOCKER_DEBRIS; i++ ) + { + Com_sprintf( name, sizeof( name ), "models/mapobjects/debris/personal%i.md3", i + 1 ); + cgs.media.shardJunk[i] = trap_R_RegisterModel( name ); + } + + memset( cg_items, 0, sizeof( cg_items ) ); + memset( cg_weapons, 0, sizeof( cg_weapons ) ); + + CG_LoadTranslateStrings(); //----(SA) added. for localization, read on-screen print names from text file + +// TODO: FIXME: REMOVE REGISTRATION OF EACH MODEL FOR EVERY LEVEL LOAD + + + //----(SA) okay, new stuff to intialize rather than doing it at level load time (or "give all" time) + // (I'm certainly not against being efficient here, but I'm tired of the rocket launcher effect only registering + // sometimes and want it to work for sure for this demo) + +/////////// +// code is almost complete for doing this correctly. will remove when that is complete. + CG_LoadingString( " - weapons" ); + for ( i = WP_KNIFE; i < WP_GAUNTLET; i++ ) { +// CG_LoadingString( va(" - %d", i) ); + CG_RegisterWeapon( i ); + } +/////////// +// END + + + // only register the items that the server says we need + strcpy( items, CG_ConfigString( CS_ITEMS ) ); + + CG_LoadingString( " - items" ); + + for ( i = 1 ; i < bg_numItems ; i++ ) { + if ( items[ i ] == '1' || cg_buildScript.integer ) { + +// TODO: get weapons added to the list that are 'set' from a script + CG_LoadingItem( i ); + CG_RegisterItemVisuals( i ); + } + } + + // wall marks + cgs.media.bulletMarkShader = trap_R_RegisterShader( "gfx/damage/bullet_mrk" ); + cgs.media.burnMarkShader = trap_R_RegisterShader( "gfx/damage/burn_med_mrk" ); + cgs.media.holeMarkShader = trap_R_RegisterShader( "gfx/damage/hole_lg_mrk" ); + cgs.media.shadowMarkShader = trap_R_RegisterShader( "markShadow" ); + cgs.media.shadowFootShader = trap_R_RegisterShader( "markShadowFoot" ); + cgs.media.shadowTorsoShader = trap_R_RegisterShader( "markShadowTorso" ); + cgs.media.wakeMarkShader = trap_R_RegisterShader( "wake" ); + cgs.media.wakeMarkShaderAnim = trap_R_RegisterShader( "wakeAnim" ); // (SA) + + cgs.media.bulletMarkShaderMetal = trap_R_RegisterShader( "gfx/damage/metal_mrk" ); + cgs.media.bulletMarkShaderWood = trap_R_RegisterShader( "gfx/damage/wood_mrk" ); + cgs.media.bulletMarkShaderCeramic = trap_R_RegisterShader( "gfx/damage/ceramic_mrk" ); + cgs.media.bulletMarkShaderGlass = trap_R_RegisterShader( "gfx/damage/glass_mrk" ); + + for ( i = 0 ; i < 5 ; i++ ) { + char name[32]; + //Com_sprintf( name, sizeof(name), "textures/decals/blood%i", i+1 ); + //cgs.media.bloodMarkShaders[i] = trap_R_RegisterShader( name ); + Com_sprintf( name, sizeof( name ), "blood_dot%i", i + 1 ); + cgs.media.bloodDotShaders[i] = trap_R_RegisterShader( name ); + } + + CG_LoadingString( " - inline models" ); + + // register the inline models + cgs.numInlineModels = trap_CM_NumInlineModels(); + for ( i = 1 ; i < cgs.numInlineModels ; i++ ) { + char name[10]; + vec3_t mins, maxs; + int j; + + Com_sprintf( name, sizeof( name ), "*%i", i ); + cgs.inlineDrawModel[i] = trap_R_RegisterModel( name ); + trap_R_ModelBounds( cgs.inlineDrawModel[i], mins, maxs ); + for ( j = 0 ; j < 3 ; j++ ) { + cgs.inlineModelMidpoints[i][j] = mins[j] + 0.5 * ( maxs[j] - mins[j] ); + } + } + + CG_LoadingString( " - server models" ); + + // register all the server specified models + for ( i = 1 ; i < MAX_MODELS ; i++ ) { + const char *modelName; + + modelName = CG_ConfigString( CS_MODELS + i ); + if ( !modelName[0] ) { + break; + } + cgs.gameModels[i] = trap_R_RegisterModel( modelName ); + } + + CG_LoadingString( " - particles" ); + CG_ClearParticles(); + + for ( i = 1; i < MAX_PARTICLES_AREAS; i++ ) + { + { + int rval; + + rval = CG_NewParticleArea( CS_PARTICLES + i ); + if ( !rval ) { + break; + } + } + } + +// cgs.media.cursor = trap_R_RegisterShaderNoMip( "menu/art/3_cursor2" ); + cgs.media.sizeCursor = trap_R_RegisterShaderNoMip( "ui/assets/sizecursor.tga" ); + cgs.media.selectCursor = trap_R_RegisterShaderNoMip( "ui/assets/selectcursor.tga" ); + CG_LoadingString( " - game media done" ); + +} + +/* +=================== +CG_RegisterClients + +=================== +*/ +static void CG_RegisterClients( void ) { + int i; + + for ( i = 0 ; i < MAX_CLIENTS ; i++ ) { + const char *clientInfo; + + clientInfo = CG_ConfigString( CS_PLAYERS + i ); + if ( !clientInfo[0] ) { + continue; + } + CG_LoadingClient( i ); + CG_NewClientInfo( i ); + } +} + +//=========================================================================== + +/* +================= +CG_ConfigString +================= +*/ +const char *CG_ConfigString( int index ) { + if ( index < 0 || index >= MAX_CONFIGSTRINGS ) { + CG_Error( "CG_ConfigString: bad index: %i", index ); + } + return cgs.gameState.stringData + cgs.gameState.stringOffsets[ index ]; +} + +//================================================================== + +/* +====================== +CG_StartMusic + +====================== +*/ +void CG_StartMusic( void ) { + char *s; + char parm1[MAX_QPATH], parm2[MAX_QPATH]; + + // start the background music + s = (char *)CG_ConfigString( CS_MUSIC ); + Q_strncpyz( parm1, COM_Parse( &s ), sizeof( parm1 ) ); + Q_strncpyz( parm2, COM_Parse( &s ), sizeof( parm2 ) ); + + if ( strlen( parm1 ) ) { + trap_S_StartBackgroundTrack( parm1, parm2, 0 ); + } +} + +//----(SA) added +/* +============== +CG_QueueMusic +============== +*/ +void CG_QueueMusic( void ) { + char *s; + char parm[MAX_QPATH]; + + // prepare the next background track + s = (char *)CG_ConfigString( CS_MUSIC_QUEUE ); + Q_strncpyz( parm, COM_Parse( &s ), sizeof( parm ) ); + + // even if no strlen(parm). we want to be able to clear the queue + + // TODO: \/ the values stored in here will be made accessable so + // it doesn't have to go through startbackgroundtrack() (which is stupid) + trap_S_StartBackgroundTrack( parm, "", -2 ); // '-2' for 'queue looping track' (QUEUED_PLAY_LOOPED) +} + +//----(SA) end + + +char *CG_GetMenuBuffer( const char *filename ) { + int len; + fileHandle_t f; + static char buf[MAX_MENUFILE]; + + len = trap_FS_FOpenFile( filename, &f, FS_READ ); + if ( !f ) { + trap_Print( va( S_COLOR_RED "menu file not found: %s, using default\n", filename ) ); + return NULL; + } + if ( len >= MAX_MENUFILE ) { + trap_Print( va( S_COLOR_RED "menu file too large: %s is %i, max allowed is %i", filename, len, MAX_MENUFILE ) ); + trap_FS_FCloseFile( f ); + return NULL; + } + + trap_FS_Read( buf, len, f ); + buf[len] = 0; + trap_FS_FCloseFile( f ); + + return buf; +} + +// +// ============================== +// new hud stuff ( mission pack ) +// ============================== +// +qboolean CG_Asset_Parse( int handle ) { + pc_token_t token; + const char *tempStr; + + if ( !trap_PC_ReadToken( handle, &token ) ) { + return qfalse; + } + if ( Q_stricmp( token.string, "{" ) != 0 ) { + return qfalse; + } + + while ( 1 ) { + if ( !trap_PC_ReadToken( handle, &token ) ) { + return qfalse; + } + + if ( Q_stricmp( token.string, "}" ) == 0 ) { + return qtrue; + } + + // font + if ( Q_stricmp( token.string, "font" ) == 0 ) { + int pointSize; + if ( !PC_String_Parse( handle, &tempStr ) || !PC_Int_Parse( handle, &pointSize ) ) { + return qfalse; + } + cgDC.registerFont( tempStr, pointSize, &cgDC.Assets.textFont ); + continue; + } + + // smallFont + if ( Q_stricmp( token.string, "smallFont" ) == 0 ) { + int pointSize; + if ( !PC_String_Parse( handle, &tempStr ) || !PC_Int_Parse( handle, &pointSize ) ) { + return qfalse; + } + cgDC.registerFont( tempStr, pointSize, &cgDC.Assets.smallFont ); + continue; + } + + // font + if ( Q_stricmp( token.string, "bigfont" ) == 0 ) { + int pointSize; + if ( !PC_String_Parse( handle, &tempStr ) || !PC_Int_Parse( handle, &pointSize ) ) { + return qfalse; + } + cgDC.registerFont( tempStr, pointSize, &cgDC.Assets.bigFont ); + continue; + } + + // handwriting + if ( Q_stricmp( token.string, "handwritingFont" ) == 0 ) { + int pointSize; + if ( !PC_String_Parse( handle, &tempStr ) || !PC_Int_Parse( handle, &pointSize ) ) { + return qfalse; + } + cgDC.registerFont( tempStr, pointSize, &cgDC.Assets.handwritingFont ); + continue; + } + + // gradientbar + if ( Q_stricmp( token.string, "gradientbar" ) == 0 ) { + if ( !PC_String_Parse( handle, &tempStr ) ) { + return qfalse; + } + cgDC.Assets.gradientBar = trap_R_RegisterShaderNoMip( tempStr ); + continue; + } + + // enterMenuSound + if ( Q_stricmp( token.string, "menuEnterSound" ) == 0 ) { + if ( !PC_String_Parse( handle, &tempStr ) ) { + return qfalse; + } + cgDC.Assets.menuEnterSound = trap_S_RegisterSound( tempStr ); + continue; + } + + // exitMenuSound + if ( Q_stricmp( token.string, "menuExitSound" ) == 0 ) { + if ( !PC_String_Parse( handle, &tempStr ) ) { + return qfalse; + } + cgDC.Assets.menuExitSound = trap_S_RegisterSound( tempStr ); + continue; + } + + // itemFocusSound + if ( Q_stricmp( token.string, "itemFocusSound" ) == 0 ) { + if ( !PC_String_Parse( handle, &tempStr ) ) { + return qfalse; + } + cgDC.Assets.itemFocusSound = trap_S_RegisterSound( tempStr ); + continue; + } + + // menuBuzzSound + if ( Q_stricmp( token.string, "menuBuzzSound" ) == 0 ) { + if ( !PC_String_Parse( handle, &tempStr ) ) { + return qfalse; + } + cgDC.Assets.menuBuzzSound = trap_S_RegisterSound( tempStr ); + continue; + } + + if ( Q_stricmp( token.string, "cursor" ) == 0 ) { + if ( !PC_String_Parse( handle, &cgDC.Assets.cursorStr ) ) { + return qfalse; + } + cgDC.Assets.cursor = trap_R_RegisterShaderNoMip( cgDC.Assets.cursorStr ); + continue; + } + + if ( Q_stricmp( token.string, "fadeClamp" ) == 0 ) { + if ( !PC_Float_Parse( handle, &cgDC.Assets.fadeClamp ) ) { + return qfalse; + } + continue; + } + + if ( Q_stricmp( token.string, "fadeCycle" ) == 0 ) { + if ( !PC_Int_Parse( handle, &cgDC.Assets.fadeCycle ) ) { + return qfalse; + } + continue; + } + + if ( Q_stricmp( token.string, "fadeAmount" ) == 0 ) { + if ( !PC_Float_Parse( handle, &cgDC.Assets.fadeAmount ) ) { + return qfalse; + } + continue; + } + + if ( Q_stricmp( token.string, "shadowX" ) == 0 ) { + if ( !PC_Float_Parse( handle, &cgDC.Assets.shadowX ) ) { + return qfalse; + } + continue; + } + + if ( Q_stricmp( token.string, "shadowY" ) == 0 ) { + if ( !PC_Float_Parse( handle, &cgDC.Assets.shadowY ) ) { + return qfalse; + } + continue; + } + + if ( Q_stricmp( token.string, "shadowColor" ) == 0 ) { + if ( !PC_Color_Parse( handle, &cgDC.Assets.shadowColor ) ) { + return qfalse; + } + cgDC.Assets.shadowFadeClamp = cgDC.Assets.shadowColor[3]; + continue; + } + } + //return qfalse; +} + +void CG_ParseMenu( const char *menuFile ) { + pc_token_t token; + int handle; + + handle = trap_PC_LoadSource( menuFile ); + if ( !handle ) { + handle = trap_PC_LoadSource( "ui/testhud.menu" ); + } + if ( !handle ) { + return; + } + + while ( 1 ) { + if ( !trap_PC_ReadToken( handle, &token ) ) { + break; + } + + //if ( Q_stricmp( token, "{" ) ) { + // Com_Printf( "Missing { in menu file\n" ); + // break; + //} + + //if ( menuCount == MAX_MENUS ) { + // Com_Printf( "Too many menus!\n" ); + // break; + //} + + if ( token.string[0] == '}' ) { + break; + } + + if ( Q_stricmp( token.string, "assetGlobalDef" ) == 0 ) { + if ( CG_Asset_Parse( handle ) ) { + continue; + } else { + break; + } + } + + + if ( Q_stricmp( token.string, "menudef" ) == 0 ) { + // start a new menu + Menu_New( handle ); + } + } + trap_PC_FreeSource( handle ); +} + +qboolean CG_Load_Menu( char **p ) { + char *token; + + token = COM_ParseExt( p, qtrue ); + + if ( token[0] != '{' ) { + return qfalse; + } + + while ( 1 ) { + + token = COM_ParseExt( p, qtrue ); + + if ( Q_stricmp( token, "}" ) == 0 ) { + return qtrue; + } + + if ( !token || token[0] == 0 ) { + return qfalse; + } + + CG_ParseMenu( token ); + } + return qfalse; +} + + + +void CG_LoadMenus( const char *menuFile ) { + char *token; + char *p; + int len, start; + fileHandle_t f; + static char buf[MAX_MENUDEFFILE]; + + start = trap_Milliseconds(); + + len = trap_FS_FOpenFile( menuFile, &f, FS_READ ); + if ( !f ) { + trap_Error( va( S_COLOR_YELLOW "menu file not found: %s, using default\n", menuFile ) ); + len = trap_FS_FOpenFile( "ui/hud.txt", &f, FS_READ ); + if ( !f ) { + trap_Error( va( S_COLOR_RED "default menu file not found: ui/hud.txt, unable to continue!\n", menuFile ) ); + } + } + + if ( len >= MAX_MENUDEFFILE ) { + trap_Error( va( S_COLOR_RED "menu file too large: %s is %i, max allowed is %i", menuFile, len, MAX_MENUDEFFILE ) ); + trap_FS_FCloseFile( f ); + return; + } + + trap_FS_Read( buf, len, f ); + buf[len] = 0; + trap_FS_FCloseFile( f ); + + COM_Compress( buf ); + + Menu_Reset(); + + p = buf; + + while ( 1 ) { + token = COM_ParseExt( &p, qtrue ); + if ( !token || token[0] == 0 || token[0] == '}' ) { + break; + } + + //if ( Q_stricmp( token, "{" ) ) { + // Com_Printf( "Missing { in menu file\n" ); + // break; + //} + + //if ( menuCount == MAX_MENUS ) { + // Com_Printf( "Too many menus!\n" ); + // break; + //} + + if ( Q_stricmp( token, "}" ) == 0 ) { + break; + } + + if ( Q_stricmp( token, "loadmenu" ) == 0 ) { + if ( CG_Load_Menu( &p ) ) { + continue; + } else { + break; + } + } + } + + Com_Printf( "UI menu load time = %d milli seconds\n", trap_Milliseconds() - start ); + +} + + + +static qboolean CG_OwnerDrawHandleKey( int ownerDraw, int flags, float *special, int key ) { + return qfalse; +} + + +static int CG_FeederCount( float feederID ) { + int i, count; + count = 0; + if ( feederID == FEEDER_REDTEAM_LIST ) { + for ( i = 0; i < cg.numScores; i++ ) { + if ( cg.scores[i].team == TEAM_RED ) { + count++; + } + } + } else if ( feederID == FEEDER_BLUETEAM_LIST ) { + for ( i = 0; i < cg.numScores; i++ ) { + if ( cg.scores[i].team == TEAM_BLUE ) { + count++; + } + } + } else if ( feederID == FEEDER_SCOREBOARD ) { + return cg.numScores; + } + return count; +} + + + + +/////////////////////////// +/////////////////////////// + +static clientInfo_t * CG_InfoFromScoreIndex( int index, int team, int *scoreIndex ) { + int i, count; + if ( cgs.gametype >= GT_TEAM ) { + count = 0; + for ( i = 0; i < cg.numScores; i++ ) { + if ( cg.scores[i].team == team ) { + if ( count == index ) { + *scoreIndex = i; + return &cgs.clientinfo[cg.scores[i].client]; + } + count++; + } + } + } + *scoreIndex = index; + return &cgs.clientinfo[ cg.scores[index].client ]; +} + +static const char *CG_FeederItemText( float feederID, int index, int column, qhandle_t *handle ) { +#ifdef MISSIONPACK + gitem_t *item; +#endif // #ifdef MISSIONPACK + int scoreIndex = 0; + clientInfo_t *info = NULL; + int team = -1; + score_t *sp = NULL; + + *handle = -1; + + if ( feederID == FEEDER_REDTEAM_LIST ) { + team = TEAM_RED; + } else if ( feederID == FEEDER_BLUETEAM_LIST ) { + team = TEAM_BLUE; + } + + info = CG_InfoFromScoreIndex( index, team, &scoreIndex ); + sp = &cg.scores[scoreIndex]; + + if ( info && info->infoValid ) { + switch ( column ) { + case 0: +#ifdef MISSIONPACK + if ( info->powerups & ( 1 << PW_NEUTRALFLAG ) ) { + item = BG_FindItemForPowerup( PW_NEUTRALFLAG ); + *handle = cg_items[ ITEM_INDEX( item ) ].icon; + } else if ( info->powerups & ( 1 << PW_REDFLAG ) ) { + item = BG_FindItemForPowerup( PW_REDFLAG ); + *handle = cg_items[ ITEM_INDEX( item ) ].icon; + } else if ( info->powerups & ( 1 << PW_BLUEFLAG ) ) { + item = BG_FindItemForPowerup( PW_BLUEFLAG ); + *handle = cg_items[ ITEM_INDEX( item ) ].icon; + } else { + if ( info->botSkill > 0 && info->botSkill <= 5 ) { + *handle = cgs.media.botSkillShaders[ info->botSkill - 1 ]; + } else if ( info->handicap < 100 ) { + return va( "%i", info->handicap ); + } + } + break; + case 1: + if ( team == -1 ) { + return ""; + } else { + *handle = CG_StatusHandle( info->teamTask ); + } + break; + case 2: + if ( cg.snap->ps.stats[ STAT_CLIENTS_READY ] & ( 1 << sp->client ) ) { + return "Ready"; + } + if ( team == -1 ) { + if ( cgs.gametype == GT_TOURNAMENT ) { + return va( "%i/%i", info->wins, info->losses ); + } else if ( info->infoValid && info->team == TEAM_SPECTATOR ) { + return "Spectator"; + } else { + return ""; + } + } else { + if ( info->teamLeader ) { + return "Leader"; + } + } +#endif // #ifdef MISSIONPACK + break; + case 3: + return info->name; + break; + case 4: + return va( "%i", info->score ); + break; + case 5: + return va( "%4i", sp->time ); + break; + case 6: + if ( sp->ping == -1 ) { + return "connecting"; + } + return va( "%4i", sp->ping ); + break; + } + } + + return ""; +} + +static qhandle_t CG_FeederItemImage( float feederID, int index ) { + return 0; +} + +static void CG_FeederSelection( float feederID, int index ) { + if ( cgs.gametype >= GT_TEAM ) { + int i, count; + int team = ( feederID == FEEDER_REDTEAM_LIST ) ? TEAM_RED : TEAM_BLUE; + count = 0; + for ( i = 0; i < cg.numScores; i++ ) { + if ( cg.scores[i].team == team ) { + if ( index == count ) { + cg.selectedScore = i; + } + count++; + } + } + } else { + cg.selectedScore = index; + } +} + +static float CG_Cvar_Get( const char *cvar ) { + char buff[128]; + memset( buff, 0, sizeof( buff ) ); + trap_Cvar_VariableStringBuffer( cvar, buff, sizeof( buff ) ); + return atof( buff ); +} + +void CG_Text_PaintWithCursor( float x, float y, int font, float scale, vec4_t color, const char *text, int cursorPos, char cursor, int limit, int style ) { + CG_Text_Paint( x, y, font, scale, color, text, 0, limit, style ); +} + +static int CG_OwnerDrawWidth( int ownerDraw, int font, float scale ) { + switch ( ownerDraw ) { + case CG_GAME_TYPE: + return CG_Text_Width( CG_GameTypeString(), font, scale, 0 ); + case CG_GAME_STATUS: + return CG_Text_Width( CG_GetGameStatusText(), font, scale, 0 ); + break; + case CG_KILLER: + return CG_Text_Width( CG_GetKillerText(), font, scale, 0 ); + break; +#ifdef MISSIONPACK + case CG_RED_NAME: + return CG_Text_Width( cg_redTeamName.string, font, scale, 0 ); + break; + case CG_BLUE_NAME: + return CG_Text_Width( cg_blueTeamName.string, font, scale, 0 ); + break; +#endif + + } + return 0; +} + +static int CG_PlayCinematic( const char *name, float x, float y, float w, float h ) { + return trap_CIN_PlayCinematic( name, x, y, w, h, CIN_loop ); +} + +static void CG_StopCinematic( int handle ) { + trap_CIN_StopCinematic( handle ); +} + +static void CG_DrawCinematic( int handle, float x, float y, float w, float h ) { + trap_CIN_SetExtents( handle, x, y, w, h ); + trap_CIN_DrawCinematic( handle ); +} + +static void CG_RunCinematicFrame( int handle ) { + trap_CIN_RunCinematic( handle ); +} + + + +/* +============== +CG_translateString + presumably if this gets used more extensively, it'll be modified to a hash table +============== +*/ +const char *CG_translateString( const char *str ) { + int i, numStrings; + + numStrings = sizeof( translateStrings ) / sizeof( translateStrings[0] ) - 1; + + for ( i = 0; i < numStrings; i++ ) { + if ( !translateStrings[i].name || !strlen( translateStrings[i].name ) ) { + return str; + } + + if ( !strcmp( str, translateStrings[i].name ) ) { + if ( translateStrings[i].localname && strlen( translateStrings[i].localname ) ) { + return translateStrings[i].localname; + } + break; + } + } + + return str; +} + +/* +================= +CG_LoadHudMenu(); + +================= +*/ +void CG_LoadHudMenu() { + char buff[1024]; + const char *hudSet; + + cgDC.registerShaderNoMip = &trap_R_RegisterShaderNoMip; + cgDC.setColor = &trap_R_SetColor; + cgDC.drawHandlePic = &CG_DrawPic; + cgDC.drawStretchPic = &trap_R_DrawStretchPic; + cgDC.drawText = &CG_Text_Paint; + cgDC.textWidth = &CG_Text_Width; + cgDC.textHeight = &CG_Text_Height; + cgDC.registerModel = &trap_R_RegisterModel; + cgDC.modelBounds = &trap_R_ModelBounds; + cgDC.fillRect = &CG_FillRect; + cgDC.drawRect = &CG_DrawRect; + cgDC.drawSides = &CG_DrawSides; + cgDC.drawTopBottom = &CG_DrawTopBottom; + cgDC.clearScene = &trap_R_ClearScene; + cgDC.addRefEntityToScene = &trap_R_AddRefEntityToScene; + cgDC.renderScene = &trap_R_RenderScene; + cgDC.registerFont = &trap_R_RegisterFont; + cgDC.ownerDrawItem = &CG_OwnerDraw; + cgDC.getValue = &CG_GetValue; + cgDC.ownerDrawVisible = &CG_OwnerDrawVisible; + cgDC.runScript = &CG_RunMenuScript; + cgDC.getTeamColor = &CG_GetTeamColor; + cgDC.setCVar = trap_Cvar_Set; + cgDC.getCVarString = trap_Cvar_VariableStringBuffer; + cgDC.getCVarValue = CG_Cvar_Get; + cgDC.drawTextWithCursor = &CG_Text_PaintWithCursor; + //cgDC.setOverstrikeMode = &trap_Key_SetOverstrikeMode; + //cgDC.getOverstrikeMode = &trap_Key_GetOverstrikeMode; + cgDC.startLocalSound = &trap_S_StartLocalSound; + cgDC.ownerDrawHandleKey = &CG_OwnerDrawHandleKey; + cgDC.feederCount = &CG_FeederCount; + cgDC.feederItemImage = &CG_FeederItemImage; + cgDC.feederItemText = &CG_FeederItemText; + cgDC.feederSelection = &CG_FeederSelection; + //cgDC.setBinding = &trap_Key_SetBinding; + //cgDC.getBindingBuf = &trap_Key_GetBindingBuf; + //cgDC.keynumToStringBuf = &trap_Key_KeynumToStringBuf; + //cgDC.executeText = &trap_Cmd_ExecuteText; + + cgDC.getTranslatedString = &CG_translateString; //----(SA) added + + cgDC.Error = &Com_Error; + cgDC.Print = &Com_Printf; + cgDC.ownerDrawWidth = &CG_OwnerDrawWidth; + //cgDC.Pause = &CG_Pause; + cgDC.registerSound = &trap_S_RegisterSound; + cgDC.startBackgroundTrack = &trap_S_StartBackgroundTrack; + cgDC.stopBackgroundTrack = &trap_S_StopBackgroundTrack; + cgDC.playCinematic = &CG_PlayCinematic; + cgDC.stopCinematic = &CG_StopCinematic; + cgDC.drawCinematic = &CG_DrawCinematic; + cgDC.runCinematicFrame = &CG_RunCinematicFrame; + + Init_Display( &cgDC ); + + Menu_Reset(); + + trap_Cvar_VariableStringBuffer( "cg_hudFiles", buff, sizeof( buff ) ); + hudSet = buff; + if ( hudSet[0] == '\0' ) { + hudSet = "ui/hud.txt"; + } + + CG_LoadMenus( hudSet ); +} + +void CG_AssetCache() { + //if (Assets.textFont == NULL) { + // trap_R_RegisterFont("fonts/arial.ttf", 72, &Assets.textFont); + //} + //Assets.background = trap_R_RegisterShaderNoMip( ASSET_BACKGROUND ); + //Com_Printf("Menu Size: %i bytes\n", sizeof(Menus)); + cgDC.Assets.gradientBar = trap_R_RegisterShaderNoMip( ASSET_GRADIENTBAR ); + cgDC.Assets.fxBasePic = trap_R_RegisterShaderNoMip( ART_FX_BASE ); + cgDC.Assets.fxPic[0] = trap_R_RegisterShaderNoMip( ART_FX_RED ); + cgDC.Assets.fxPic[1] = trap_R_RegisterShaderNoMip( ART_FX_YELLOW ); + cgDC.Assets.fxPic[2] = trap_R_RegisterShaderNoMip( ART_FX_GREEN ); + cgDC.Assets.fxPic[3] = trap_R_RegisterShaderNoMip( ART_FX_TEAL ); + cgDC.Assets.fxPic[4] = trap_R_RegisterShaderNoMip( ART_FX_BLUE ); + cgDC.Assets.fxPic[5] = trap_R_RegisterShaderNoMip( ART_FX_CYAN ); + cgDC.Assets.fxPic[6] = trap_R_RegisterShaderNoMip( ART_FX_WHITE ); + cgDC.Assets.scrollBar = trap_R_RegisterShaderNoMip( ASSET_SCROLLBAR ); + cgDC.Assets.scrollBarArrowDown = trap_R_RegisterShaderNoMip( ASSET_SCROLLBAR_ARROWDOWN ); + cgDC.Assets.scrollBarArrowUp = trap_R_RegisterShaderNoMip( ASSET_SCROLLBAR_ARROWUP ); + cgDC.Assets.scrollBarArrowLeft = trap_R_RegisterShaderNoMip( ASSET_SCROLLBAR_ARROWLEFT ); + cgDC.Assets.scrollBarArrowRight = trap_R_RegisterShaderNoMip( ASSET_SCROLLBAR_ARROWRIGHT ); + cgDC.Assets.scrollBarThumb = trap_R_RegisterShaderNoMip( ASSET_SCROLL_THUMB ); + cgDC.Assets.sliderBar = trap_R_RegisterShaderNoMip( ASSET_SLIDER_BAR ); + cgDC.Assets.sliderThumb = trap_R_RegisterShaderNoMip( ASSET_SLIDER_THUMB ); +} + + +/* +================= +CG_Init + +Called after every level change or subsystem restart +Will perform callbacks to make the loading info screen update. +================= +*/ +void CG_Init( int serverMessageNum, int serverCommandSequence ) { + const char *s; + + // clear everything + memset( &cgs, 0, sizeof( cgs ) ); + memset( &cg, 0, sizeof( cg ) ); + memset( cg_entities, 0, sizeof( cg_entities ) ); + memset( cg_weapons, 0, sizeof( cg_weapons ) ); + memset( cg_items, 0, sizeof( cg_items ) ); + + // RF, init the anim scripting + cgs.animScriptData.soundIndex = CG_SoundScriptPrecache; + cgs.animScriptData.playSound = CG_SoundPlayIndexedScript; + + cgs.processedSnapshotNum = serverMessageNum; + cgs.serverCommandSequence = serverCommandSequence; + + // load a few needed things before we do any screen updates + // (SA) using Nerve's text since they have foreign characters + cgs.media.charsetShader = trap_R_RegisterShader( "gfx/2d/hudchars" ); //trap_R_RegisterShader( "gfx/2d/bigchars" ); + // JOSEPH 4-17-00 + cgs.media.menucharsetShader = trap_R_RegisterShader( "gfx/2d/hudchars" ); + // END JOSEPH + cgs.media.whiteShader = trap_R_RegisterShader( "white" ); + cgs.media.charsetProp = trap_R_RegisterShaderNoMip( "menu/art/font1_prop.tga" ); + cgs.media.charsetPropGlow = trap_R_RegisterShaderNoMip( "menu/art/font1_prop_glo.tga" ); + cgs.media.charsetPropB = trap_R_RegisterShaderNoMip( "menu/art/font2_prop.tga" ); + + CG_RegisterCvars(); + + CG_InitConsoleCommands(); + +// cg.weaponSelect = WP_MP40; + + // get the rendering configuration from the client system + trap_GetGlconfig( &cgs.glconfig ); + cgs.screenXScale = cgs.glconfig.vidWidth / 640.0; + cgs.screenYScale = cgs.glconfig.vidHeight / 480.0; + + // get the gamestate from the client system + trap_GetGameState( &cgs.gameState ); + + // check version + s = CG_ConfigString( CS_GAME_VERSION ); + if ( strcmp( s, GAME_VERSION ) ) { + CG_Error( "Client/Server game mismatch: %s/%s", GAME_VERSION, s ); + } + + s = CG_ConfigString( CS_LEVEL_START_TIME ); + cgs.levelStartTime = atoi( s ); + + CG_ParseServerinfo(); + + // load the new map + CG_LoadingString( "collision map" ); + + trap_CM_LoadMap( cgs.mapname ); + + String_Init(); + + cg.loading = qtrue; // force players to load instead of defer + + CG_LoadingString( "sounds" ); + + CG_RegisterSounds(); + + CG_LoadingString( "graphics" ); + + CG_RegisterGraphics(); + + CG_LoadingString( "flamechunks" ); + + CG_InitFlameChunks(); // RF, register and clear all flamethrower resources + + CG_LoadingString( "clients" ); + + CG_RegisterClients(); // if low on memory, some clients will be deferred + + CG_AssetCache(); + CG_LoadHudMenu(); // load new hud stuff + + cg.loading = qfalse; // future players will be deferred + + CG_InitLocalEntities(); + + CG_InitMarkPolys(); + + // RF, init ZombieFX + trap_RB_ZombieFXAddNewHit( -1, NULL, NULL ); + + // remove the last loading update + cg.infoScreenText[0] = 0; + + // Make sure we have update values (scores) + CG_SetConfigValues(); + + CG_StartMusic(); + + cg.lightstylesInited = qfalse; + + CG_LoadingString( "" ); + + CG_ShaderStateChanged(); + + // RF, clear all sounds, so we dont hear anything after level load + trap_S_ClearLoopingSounds( 2 ); + + // start level load music + // too late... +// trap_S_StartBackgroundTrack( "sound/music/fla_mp03.wav", "sound/music/fla_mp03.wav", 1 ); + + + // NERVE - SMF +// JPW NERVE -- commented out 'cause this moved + + if ( cgs.gametype == GT_WOLF ) { + trap_Cvar_Set( "cg_drawTimer", "0" ); // jpw + + } + // jpw + // -NERVE - SMF +} + +/* +================= +CG_Shutdown + +Called before every level change or subsystem restart +================= +*/ +void CG_Shutdown( void ) { + + // some mods may need to do cleanup work here, + // like closing files or archiving session data +} + + diff --git a/Projects/Android/jni/rtcw/src/cgame/cg_marks.c b/Projects/Android/jni/rtcw/src/cgame/cg_marks.c new file mode 100644 index 0000000..b7358b6 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/cgame/cg_marks.c @@ -0,0 +1,352 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +// cg_marks.c -- wall marks + +#include "cg_local.h" + +/* +=================================================================== + +MARK POLYS + +=================================================================== +*/ + + +markPoly_t cg_activeMarkPolys; // double linked list +markPoly_t *cg_freeMarkPolys; // single linked list +markPoly_t cg_markPolys[MAX_MARK_POLYS]; + +/* +=================== +CG_InitMarkPolys + +This is called at startup and for tournement restarts +=================== +*/ +void CG_InitMarkPolys( void ) { + int i; + markPoly_t *trav, *lasttrav; + + memset( cg_markPolys, 0, sizeof( cg_markPolys ) ); + + cg_activeMarkPolys.nextMark = &cg_activeMarkPolys; + cg_activeMarkPolys.prevMark = &cg_activeMarkPolys; + cg_freeMarkPolys = cg_markPolys; + for ( i = 0, trav = cg_markPolys + 1, lasttrav = cg_markPolys ; i < MAX_MARK_POLYS - 1 ; i++, trav++ ) { + lasttrav->nextMark = trav; + lasttrav = trav; + } +} + + +/* +================== +CG_FreeMarkPoly +================== +*/ +void CG_FreeMarkPoly( markPoly_t *le ) { + if ( !le->prevMark ) { + CG_Error( "CG_FreeLocalEntity: not active" ); + } + + // remove from the doubly linked active list + le->prevMark->nextMark = le->nextMark; + le->nextMark->prevMark = le->prevMark; + + // the free list is only singly linked + le->nextMark = cg_freeMarkPolys; + cg_freeMarkPolys = le; +} + +/* +=================== +CG_AllocMark + +Will allways succeed, even if it requires freeing an old active mark +=================== +*/ +markPoly_t *CG_AllocMark( int endTime ) { + markPoly_t *le; //, *trav, *lastTrav; + int time; + + if ( !cg_freeMarkPolys ) { + // no free entities, so free the one at the end of the chain + // remove the oldest active entity + time = cg_activeMarkPolys.prevMark->time; + while ( cg_activeMarkPolys.prevMark && time == cg_activeMarkPolys.prevMark->time ) { + CG_FreeMarkPoly( cg_activeMarkPolys.prevMark ); + } + } + + le = cg_freeMarkPolys; + cg_freeMarkPolys = cg_freeMarkPolys->nextMark; + + memset( le, 0, sizeof( *le ) ); + + // Ridah, TODO: sort this, so the list is always sorted by longest duration -> shortest duration, + // this way the shortest duration mark will always get overwritten first + //for (trav = cg_activeMarkPolys.nextMark; (trav->duration + trav->time > endTime) && (trav != cg_activeMarkPolys.prevMark) ; lastTrav = trav, trav++ ) { + // Respect the FOR loop + //} + + // link into the active list + le->nextMark = cg_activeMarkPolys.nextMark; + le->prevMark = &cg_activeMarkPolys; + cg_activeMarkPolys.nextMark->prevMark = le; + cg_activeMarkPolys.nextMark = le; + return le; +} + + + +/* +================= +CG_ImpactMark + +origin should be a point within a unit of the plane +dir should be the plane normal + +temporary marks will not be stored or randomly oriented, but immediately +passed to the renderer. +================= +*/ +// Ridah, increased this since we leave them around for longer +#define MAX_MARK_FRAGMENTS 384 +#define MAX_MARK_POINTS 1024 +//#define MAX_MARK_FRAGMENTS 128 +//#define MAX_MARK_POINTS 384 + +// these are ignored now for the most part +//#define MARK_TOTAL_TIME 20000 // (SA) made this a cvar: cg_markTime (we could cap the time or remove marks quicker if too long a time starts to cause new marks to not appear) +#define MARK_FADE_TIME 10000 + +void CG_ImpactMark( qhandle_t markShader, const vec3_t origin, const vec3_t dir, + float orientation, float red, float green, float blue, float alpha, + qboolean alphaFade, float radius, qboolean temporary, int duration ) { + vec3_t axis[3]; + float texCoordScale; + vec3_t originalPoints[4]; + byte colors[4]; + int i, j; + int numFragments; + markFragment_t markFragments[MAX_MARK_FRAGMENTS], *mf; + vec5_t markPoints[MAX_MARK_POINTS]; // Ridah, made it vec5_t so it includes S/T + vec3_t projection; + int multMaxFragments = 1; + + if ( !cg_markTime.integer ) { + return; + } + + if ( radius <= 0 ) { + // just ignore it, don't error out + return; +// CG_Error( "CG_ImpactMark called with <= 0 radius" ); + } + + // Ridah, if no duration, use the default + if ( duration < 0 ) { + if ( duration == -2 ) { + multMaxFragments = -1; // use original mapping + } + +// duration = MARK_TOTAL_TIME; + duration = cg_markTime.integer; + } + + // create the texture axis + VectorNormalize2( dir, axis[0] ); + PerpendicularVector( axis[1], axis[0] ); + RotatePointAroundVector( axis[2], axis[0], axis[1], orientation ); + CrossProduct( axis[0], axis[2], axis[1] ); + + texCoordScale = 0.5 * 1.0 / radius; + + // create the full polygon + for ( i = 0 ; i < 3 ; i++ ) { + originalPoints[0][i] = origin[i] - radius * axis[1][i] - radius * axis[2][i]; + originalPoints[1][i] = origin[i] + radius * axis[1][i] - radius * axis[2][i]; + originalPoints[2][i] = origin[i] + radius * axis[1][i] + radius * axis[2][i]; + originalPoints[3][i] = origin[i] - radius * axis[1][i] + radius * axis[2][i]; + } + + // get the fragments + //VectorScale( dir, -20, projection ); + VectorScale( dir, radius * 2, projection ); + numFragments = trap_CM_MarkFragments( (int)orientation, (void *)originalPoints, + projection, MAX_MARK_POINTS, (float *)&markPoints[0], + MAX_MARK_FRAGMENTS * multMaxFragments, markFragments ); + + colors[0] = red * 255; + colors[1] = green * 255; + colors[2] = blue * 255; + colors[3] = alpha * 255; + + for ( i = 0, mf = markFragments ; i < numFragments ; i++, mf++ ) { + polyVert_t *v; + polyVert_t verts[MAX_VERTS_ON_POLY]; + markPoly_t *mark; + qboolean hasST; + + // we have an upper limit on the complexity of polygons + // that we store persistantly + if ( mf->numPoints > MAX_VERTS_ON_POLY ) { + mf->numPoints = MAX_VERTS_ON_POLY; + } + if ( mf->numPoints < 0 ) { + hasST = qtrue; + mf->numPoints *= -1; + } else { + hasST = qfalse; + } + for ( j = 0, v = verts ; j < mf->numPoints ; j++, v++ ) { + vec3_t delta; + + VectorCopy( markPoints[mf->firstPoint + j], v->xyz ); + + if ( !hasST ) { + VectorSubtract( v->xyz, origin, delta ); + v->st[0] = 0.5 + DotProduct( delta, axis[1] ) * texCoordScale; + v->st[1] = 0.5 + DotProduct( delta, axis[2] ) * texCoordScale; + } else { + v->st[0] = markPoints[mf->firstPoint + j][3]; + v->st[1] = markPoints[mf->firstPoint + j][4]; + } + + *(int *)v->modulate = *(int *)colors; + } + + // if it is a temporary (shadow) mark, add it immediately and forget about it + if ( temporary ) { + trap_R_AddPolyToScene( markShader, mf->numPoints, verts ); + continue; + } + + // otherwise save it persistantly + mark = CG_AllocMark( cg.time + duration ); + mark->time = cg.time; + mark->alphaFade = alphaFade; + mark->markShader = markShader; + mark->poly.numVerts = mf->numPoints; + mark->color[0] = red; + mark->color[1] = green; + mark->color[2] = blue; + mark->color[3] = alpha; + mark->duration = duration; + memcpy( mark->verts, verts, mf->numPoints * sizeof( verts[0] ) ); + } +} + + +/* +=============== +CG_AddMarks +=============== +*/ + +void CG_AddMarks( void ) { + int j; + markPoly_t *mp, *next; + int t; + int fade; + + if ( !cg_markTime.integer ) { + return; + } + + mp = cg_activeMarkPolys.nextMark; + for ( ; mp != &cg_activeMarkPolys ; mp = next ) { + // grab next now, so if the local entity is freed we + // still have it + next = mp->nextMark; + + // see if it is time to completely remove it + if ( cg.time > mp->time + mp->duration ) { + CG_FreeMarkPoly( mp ); + continue; + } + + // fade out the energy bursts + if ( mp->markShader == cgs.media.energyMarkShader ) { + + fade = 450 - 450 * ( ( cg.time - mp->time ) / 3000.0 ); + if ( fade < 255 ) { + if ( fade < 0 ) { + fade = 0; + } + if ( mp->verts[0].modulate[0] != 0 ) { + for ( j = 0 ; j < mp->poly.numVerts ; j++ ) { + mp->verts[j].modulate[0] = mp->color[0] * fade; + mp->verts[j].modulate[1] = mp->color[1] * fade; + mp->verts[j].modulate[2] = mp->color[2] * fade; + } + } + } + } + + // fade in the zombie spirit marks + if ( mp->markShader == cgs.media.zombieSpiritWallShader ) { + + fade = 255 * ( ( cg.time - mp->time ) / 2000.0 ); + if ( fade < 255 ) { + if ( fade < 0 ) { + fade = 0; + } + if ( mp->verts[0].modulate[0] != 0 ) { + for ( j = 0 ; j < mp->poly.numVerts ; j++ ) { + mp->verts[j].modulate[0] = mp->color[0] * fade; + mp->verts[j].modulate[1] = mp->color[1] * fade; + mp->verts[j].modulate[2] = mp->color[2] * fade; + } + } + } + } + + // fade all marks out with time + t = mp->time + mp->duration - cg.time; + if ( t < (float)mp->duration / 2.0 ) { + fade = (int)( 255.0 * (float)t / ( (float)mp->duration / 2.0 ) ); + if ( mp->alphaFade ) { + for ( j = 0 ; j < mp->poly.numVerts ; j++ ) { + mp->verts[j].modulate[3] = fade; + } + } else { + for ( j = 0 ; j < mp->poly.numVerts ; j++ ) { + mp->verts[j].modulate[0] = mp->color[0] * fade; + mp->verts[j].modulate[1] = mp->color[1] * fade; + mp->verts[j].modulate[2] = mp->color[2] * fade; + } + } + } + + trap_R_AddPolyToScene( mp->markShader, mp->poly.numVerts, mp->verts ); + } +} + diff --git a/Projects/Android/jni/rtcw/src/cgame/cg_newDraw.c b/Projects/Android/jni/rtcw/src/cgame/cg_newDraw.c new file mode 100644 index 0000000..fac465b --- /dev/null +++ b/Projects/Android/jni/rtcw/src/cgame/cg_newDraw.c @@ -0,0 +1,2598 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + + +#include "cg_local.h" +#include "../ui/ui_shared.h" + +extern displayContextDef_t cgDC; + +// set in CG_ParseTeamInfo + +//static int sortedTeamPlayers[TEAM_MAXOVERLAY]; +//static int numSortedTeamPlayers; +int drawTeamOverlayModificationCount = -1; + +//static char systemChat[256]; +//static char teamChat1[256]; +//static char teamChat2[256]; + +void CG_InitTeamChat() { +#ifdef MISSIONPACK + memset( teamChat1, 0, sizeof( teamChat1 ) ); + memset( teamChat2, 0, sizeof( teamChat2 ) ); + memset( systemChat, 0, sizeof( systemChat ) ); +#endif // #ifdef MISSIONPACK +} + +void CG_SetPrintString( int type, const char *p ) { + if ( type == SYSTEM_PRINT ) { + strcpy( systemChat, p ); + } else { + strcpy( teamChat2, teamChat1 ); + strcpy( teamChat1, p ); + } +} + +void CG_CheckOrderPending() { +#ifdef MISSIONPACK + if ( cgs.gametype < GT_CTF ) { + return; + } + if ( cgs.orderPending ) { + //clientInfo_t *ci = cgs.clientinfo + sortedTeamPlayers[cg_currentSelectedPlayer.integer]; + const char *p1, *p2, *b; + p1 = p2 = b = NULL; + switch ( cgs.currentOrder ) { + case TEAMTASK_OFFENSE: + p1 = VOICECHAT_ONOFFENSE; + p2 = VOICECHAT_OFFENSE; + b = "+button7; wait; -button7"; + break; + case TEAMTASK_DEFENSE: + p1 = VOICECHAT_ONDEFENSE; + p2 = VOICECHAT_DEFEND; + b = "+button8; wait; -button8"; + break; + case TEAMTASK_PATROL: + p1 = VOICECHAT_ONPATROL; + p2 = VOICECHAT_PATROL; + b = "+button9; wait; -button9"; + break; + case TEAMTASK_FOLLOW: + p1 = VOICECHAT_ONFOLLOW; + p2 = VOICECHAT_FOLLOWME; + b = "+button10; wait; -button10"; + break; + case TEAMTASK_CAMP: + p1 = VOICECHAT_ONCAMPING; + p2 = VOICECHAT_CAMP; + break; + case TEAMTASK_RETRIEVE: + p1 = VOICECHAT_ONGETFLAG; + p2 = VOICECHAT_RETURNFLAG; + break; + case TEAMTASK_ESCORT: + p1 = VOICECHAT_ONFOLLOWCARRIER; + p2 = VOICECHAT_FOLLOWFLAGCARRIER; + break; + } + + if ( cg_currentSelectedPlayer.integer == numSortedTeamPlayers ) { + // to everyone + trap_SendConsoleCommand( va( "cmd vsay_team %s\n", p2 ) ); + } else { + // for the player self + if ( sortedTeamPlayers[cg_currentSelectedPlayer.integer] == cg.snap->ps.clientNum && p1 ) { + trap_SendConsoleCommand( va( "teamtask %i\n", cgs.currentOrder ) ); + //trap_SendConsoleCommand(va("cmd say_team %s\n", p2)); + trap_SendConsoleCommand( va( "cmd vsay_team %s\n", p1 ) ); + } else if ( p2 ) { + //trap_SendConsoleCommand(va("cmd say_team %s, %s\n", ci->name,p)); + trap_SendConsoleCommand( va( "cmd vtell %d %s\n", sortedTeamPlayers[cg_currentSelectedPlayer.integer], p2 ) ); + } + } + if ( b ) { + trap_SendConsoleCommand( b ); + } + cgs.orderPending = qfalse; + } +#endif // #ifdef MISSIONPACK +} + +static void CG_SetSelectedPlayerName() { + if ( cg_currentSelectedPlayer.integer >= 0 && cg_currentSelectedPlayer.integer < numSortedTeamPlayers ) { + clientInfo_t *ci = cgs.clientinfo + sortedTeamPlayers[cg_currentSelectedPlayer.integer]; + if ( ci ) { + trap_Cvar_Set( "cg_selectedPlayerName", ci->name ); + trap_Cvar_Set( "cg_selectedPlayer", va( "%d", sortedTeamPlayers[cg_currentSelectedPlayer.integer] ) ); +// cgs.currentOrder = ci->teamTask; + } + } else { + trap_Cvar_Set( "cg_selectedPlayerName", "Everyone" ); + } +} +int CG_GetSelectedPlayer() { + if ( cg_currentSelectedPlayer.integer < 0 || cg_currentSelectedPlayer.integer >= numSortedTeamPlayers ) { + cg_currentSelectedPlayer.integer = 0; + } + return cg_currentSelectedPlayer.integer; +} + +void CG_SelectNextPlayer() { + CG_CheckOrderPending(); + if ( cg_currentSelectedPlayer.integer >= 0 && cg_currentSelectedPlayer.integer < numSortedTeamPlayers ) { + cg_currentSelectedPlayer.integer++; + } else { + cg_currentSelectedPlayer.integer = 0; + } + CG_SetSelectedPlayerName(); +} + +void CG_SelectPrevPlayer() { + CG_CheckOrderPending(); + if ( cg_currentSelectedPlayer.integer > 0 && cg_currentSelectedPlayer.integer < numSortedTeamPlayers ) { + cg_currentSelectedPlayer.integer--; + } else { + cg_currentSelectedPlayer.integer = numSortedTeamPlayers; + } + CG_SetSelectedPlayerName(); +} + + +// (SA) not sure what you'd use this for anyway... + +static void CG_DrawPlayerArmorIcon( rectDef_t *rect, qboolean draw2D ) { +#ifdef MISSIONPACK + centity_t *cent; + playerState_t *ps; + vec3_t angles; + vec3_t origin; + + if ( cg_drawStatus.integer == 0 ) { + return; + } + + cent = &cg_entities[cg.snap->ps.clientNum]; + ps = &cg.snap->ps; + + if ( draw2D || !cg_draw3dIcons.integer && cg_drawIcons.integer ) { + CG_DrawPic( rect->x, rect->y + rect->h / 2 + 1, rect->w, rect->h, cgs.media.armorIcon ); + } else if ( cg_draw3dIcons.integer ) { + VectorClear( angles ); + origin[0] = 90; + origin[1] = 0; + origin[2] = -10; + angles[YAW] = ( cg.time & 2047 ) * 360 / 2048.0; + + CG_Draw3DModel( rect->x, rect->y, rect->w, rect->h, cgs.media.armorModel, 0, origin, angles ); + } +#endif +} + +static void CG_DrawPlayerArmorValue( rectDef_t *rect, int font, float scale, vec4_t color, qhandle_t shader, int textStyle ) { + char num[16]; + int value; + centity_t *cent; + playerState_t *ps; + + cent = &cg_entities[cg.snap->ps.clientNum]; + ps = &cg.snap->ps; + + value = ps->stats[STAT_ARMOR]; + + + if ( shader ) { + trap_R_SetColor( color ); + CG_DrawPic( rect->x, rect->y, rect->w, rect->h, shader ); + trap_R_SetColor( NULL ); + } else { + Com_sprintf( num, sizeof( num ), "%i", value ); + value = CG_Text_Width( num, font, scale, 0 ); + CG_Text_Paint( rect->x + ( rect->w - value ) / 2, rect->y + rect->h, font, scale, color, num, 0, 0, textStyle ); + } +} + +// TTimo: unused +/* +static float healthColors[4][4] = { +// { 0.2, 1.0, 0.2, 1.0 } , { 1.0, 0.2, 0.2, 1.0 }, {0.5, 0.5, 0.5, 1} }; + { 1, 0.69f, 0, 1.0f } , // normal + { 1.0f, 0.2f, 0.2f, 1.0f }, // low health + {0.5f, 0.5f, 0.5f, 1}, // weapon firing + { 1, 1, 1, 1 } }; // health > 100 +*/ + +/* +============== +weapIconDrawSize +============== +*/ +static int weapIconDrawSize( int weap ) { + switch ( weap ) { + + // weapons to not draw + case WP_KNIFE: + return 0; + + // weapons with 'wide' icons + case WP_THOMPSON: + case WP_MP40: + case WP_STEN: + case WP_MAUSER: + case WP_GARAND: + case WP_VENOM: + case WP_TESLA: + case WP_PANZERFAUST: + case WP_FLAMETHROWER: + case WP_FG42: + case WP_FG42SCOPE: + case WP_SNOOPERSCOPE: + case WP_SNIPERRIFLE: + return 2; + } + + return 1; +} + + +/* +============== +CG_DrawPlayerWeaponIcon +============== +*/ +static void CG_DrawPlayerWeaponIcon( rectDef_t *rect, qboolean drawHighlighted, int align ) { + int size; + int realweap; // DHM - Nerve + qhandle_t icon; + float scale,halfScale; + + if ( !cg_drawIcons.integer ) { + return; + } + + // DHM - Nerve :: special case for WP_CLASS_SPECIAL + + realweap = cg.predictedPlayerState.weapon; + + if ( cgs.gametype == GT_WOLF && realweap == WP_CLASS_SPECIAL ) { + switch ( cg.predictedPlayerState.stats[ STAT_PLAYER_CLASS ] ) { + case PC_MEDIC: + realweap = WP_MEDIC_HEAL; + break; + case PC_LT: + realweap = WP_GRENADE_SMOKE; + break; + default: + break; + } + } + // dhm + + size = weapIconDrawSize( realweap ); + + if ( !size ) { + return; + } + + if ( drawHighlighted ) { + icon = cg_weapons[ realweap ].weaponIcon[1]; + } else { + icon = cg_weapons[ realweap ].weaponIcon[0]; + } + + + + // pulsing grenade icon to help the player 'count' in their head + if ( cg.predictedPlayerState.grenadeTimeLeft ) { // grenades and dynamite set this + + // these time differently + if ( realweap == WP_DYNAMITE ) { + if ( ( ( cg.grenLastTime ) % 1000 ) > ( ( cg.predictedPlayerState.grenadeTimeLeft ) % 1000 ) ) { + trap_S_StartLocalSound( cgs.media.grenadePulseSound4, CHAN_LOCAL_SOUND ); + } + } else { + if ( ( ( cg.grenLastTime ) % 1000 ) < ( ( cg.predictedPlayerState.grenadeTimeLeft ) % 1000 ) ) { + switch ( cg.predictedPlayerState.grenadeTimeLeft / 1000 ) { + case 3: + trap_S_StartLocalSound( cgs.media.grenadePulseSound4, CHAN_LOCAL_SOUND ); + break; + case 2: + trap_S_StartLocalSound( cgs.media.grenadePulseSound3, CHAN_LOCAL_SOUND ); + break; + case 1: + trap_S_StartLocalSound( cgs.media.grenadePulseSound2, CHAN_LOCAL_SOUND ); + break; + case 0: + trap_S_StartLocalSound( cgs.media.grenadePulseSound1, CHAN_LOCAL_SOUND ); + break; + } + } + } + + scale = (float)( ( cg.predictedPlayerState.grenadeTimeLeft ) % 1000 ) / 100.0f; + halfScale = scale * 0.5f; + + cg.grenLastTime = cg.predictedPlayerState.grenadeTimeLeft; + } else { + scale = halfScale = 0; + } + + + if ( icon ) { + float x, y, w, h; + + if ( size == 1 ) { // draw half width to match the icon asset + + // start at left + x = rect->x - halfScale; + y = rect->y - halfScale; + w = rect->w / 2 + scale; + h = rect->h + scale; + + switch ( align ) { + case ITEM_ALIGN_CENTER: + x += rect->w / 4; + break; + case ITEM_ALIGN_RIGHT: + x += rect->w / 2; + break; + case ITEM_ALIGN_LEFT: + default: + break; + } + + } else { + x = rect->x - halfScale; + y = rect->y - halfScale; + w = rect->w + scale; + h = rect->h + scale; + } + + + CG_DrawPic( x, y, w, h, icon ); + } +} + + +/* +============== +CG_DrawPlayerAmmoIcon +============== +*/ +static void CG_DrawPlayerAmmoIcon( rectDef_t *rect, qboolean draw2D ) { + centity_t *cent; + playerState_t *ps; + vec3_t angles; + vec3_t origin; + + cent = &cg_entities[cg.snap->ps.clientNum]; + ps = &cg.snap->ps; + + // TTimo: gcc: suggests () around && within || + if ( draw2D || ( !cg_draw3dIcons.integer && cg_drawIcons.integer ) ) { + qhandle_t icon; + icon = cg_weapons[ cg.predictedPlayerState.weapon ].ammoIcon; + if ( icon ) { + CG_DrawPic( rect->x, rect->y, rect->w, rect->h, icon ); + } + } else if ( cg_draw3dIcons.integer ) { + if ( cent->currentState.weapon && cg_weapons[ cent->currentState.weapon ].ammoModel ) { + VectorClear( angles ); + origin[0] = 70; + origin[1] = 0; + origin[2] = 0; + angles[YAW] = 90 + 20 * sin( cg.time / 1000.0 ); + CG_Draw3DModel( rect->x, rect->y, rect->w, rect->h, cg_weapons[ cent->currentState.weapon ].ammoModel, 0, origin, angles ); + } + } +} + +extern void CG_CheckForCursorHints( void ); +#define CURSORHINT_SCALE 10 + +/* +============== +CG_DrawCursorHints + + cg_cursorHints.integer == + 0: no hints + 1: sin size pulse + 2: one way size pulse + 3: alpha pulse + 4+: static image + +============== +*/ +extern void CG_DrawExitStats( void ); + +static void CG_DrawCursorhint( rectDef_t *rect ) { + float *color; + qhandle_t icon, icon2 = 0; + float scale, halfscale; + qboolean redbar = qfalse; + + if ( !cg_cursorHints.integer ) { + return; + } + + CG_CheckForCursorHints(); + + icon = cgs.media.hintShaders[cg.cursorHintIcon]; + + switch ( cg.cursorHintIcon ) { + case HINT_NONE: + case HINT_FORCENONE: + icon = 0; + break; + case HINT_BREAKABLE_DYNAMITE: + icon = cgs.media.hintShaders[HINT_BREAKABLE]; + break; + case HINT_CHAIR: + // only show 'pickupable' if you're not armed, or are armed with a single handed weapon + if ( cg.predictedPlayerState.weapon && !( WEAPS_ONE_HANDED & ( 1 << ( cg.predictedPlayerState.weapon ) ) ) ) { // (SA) this was backwards + icon = cgs.media.hintShaders[HINT_NOACTIVATE]; + } + break; + + case HINT_PLAYER: + icon = cgs.media.hintShaders[HINT_NOACTIVATE]; + break; + + case HINT_PLYR_FRIEND: + break; + + case HINT_NOEXIT_FAR: + redbar = qtrue; // draw the status bar in red to show that you can't exit yet + case HINT_EXIT_FAR: + break; + + case HINT_NOEXIT: + redbar = qtrue; // draw the status bar in red to show that you can't exit yet + case HINT_EXIT: + cg.exitStatsFade = 250; // fade /up/ time + if ( !cg.exitStatsTime ) { + cg.exitStatsTime = cg.time; + } + CG_DrawExitStats(); + break; + + default: + break; + } + + if ( !icon ) { + return; + } + + + // color + color = CG_FadeColor( cg.cursorHintTime, cg.cursorHintFade ); + if ( !color ) { + trap_R_SetColor( NULL ); + cg.exitStatsTime = 0; // exit stats will fade up next time they're hit + cg.cursorHintIcon = HINT_NONE; // clear the hint + return; + } + + if ( cg_cursorHints.integer == 3 ) { + color[3] *= 0.5 + 0.5 * sin( (float)cg.time / 150.0 ); + } + + + // size + if ( cg_cursorHints.integer >= 3 ) { // no size pulsing + scale = halfscale = 0; + } else { + if ( cg_cursorHints.integer == 2 ) { + scale = (float)( ( cg.cursorHintTime ) % 1000 ) / 100.0f; // one way size pulse + } else { + scale = CURSORHINT_SCALE * ( 0.5 + 0.5 * sin( (float)cg.time / 150.0 ) ); // sin pulse + + } + halfscale = scale * 0.5f; + } + + // set color and draw the hint + trap_R_SetColor( color ); + CG_DrawPic( rect->x - halfscale, rect->y - halfscale, rect->w + scale, rect->h + scale, icon ); + + if ( icon2 ) { + CG_DrawPic( rect->x - halfscale, rect->y - halfscale, rect->w + scale, rect->h + scale, icon2 ); + } + + trap_R_SetColor( NULL ); + + // draw status bar under the cursor hint + if ( cg.cursorHintValue && ( !( cg.time - cg.cursorHintTime ) ) ) { // don't fade bar out w/ hint icon + if ( redbar ) { + Vector4Set( color, 1, 0, 0, 0.5f ); + } else { + Vector4Set( color, 0, 0, 1, 0.5f ); + } + CG_FilledBar( rect->x, rect->y + rect->h + 4, rect->w, 8, color, NULL, NULL, (float)cg.cursorHintValue / 255.0f, 0 ); + } + +} + + + +/* +============== +CG_DrawMessageIcon +============== +*/ +//----(SA) added + +static void CG_DrawMessageIcon( rectDef_t *rect ) { + int icon; + + if ( !cg_youGotMail.integer ) { + return; + } + + if ( cg_youGotMail.integer == 2 ) { + icon = cgs.media.youGotObjectiveShader; + } else { + icon = cgs.media.youGotMailShader; + } + + CG_DrawPic( rect->x, rect->y, rect->w, rect->h, icon ); +} + + + +/* +============== +CG_DrawPlayerAmmoValue + 0 - ammo + 1 - clip +============== +*/ +static void CG_DrawPlayerAmmoValue( rectDef_t *rect, int font, float scale, vec4_t color, qhandle_t shader, int textStyle, int type ) { + char num[16]; + int value, value2 = 0; + centity_t *cent; + playerState_t *ps; + int weap; + qboolean special = qfalse; + + cent = &cg_entities[cg.snap->ps.clientNum]; + ps = &cg.snap->ps; + + weap = cent->currentState.weapon; + + if ( !weap ) { + return; + } + + if ( ps->weaponstate == WEAPON_RELOADING && type != 0 ) { + return; + } + + switch ( weap ) { // some weapons don't draw ammo count text + case WP_KNIFE: + case WP_CLASS_SPECIAL: // DHM - Nerve + return; + + case WP_AKIMBO: + special = qtrue; + break; + + case WP_GRENADE_LAUNCHER: + case WP_GRENADE_PINEAPPLE: + case WP_DYNAMITE: + case WP_TESLA: + case WP_FLAMETHROWER: + if ( type == 0 ) { // don't draw reserve value, just clip (since these weapons have all their ammo in the clip) + return; + } + break; + + default: + break; + } + + + if ( type == 0 ) { // ammo + value = cg.snap->ps.ammo[BG_FindAmmoForWeapon( weap )]; + } else { // clip + value = ps->ammoclip[BG_FindClipForWeapon( weap )]; + if ( special ) { + value2 = value; + if ( weapAlts[weap] ) { + value = ps->ammoclip[weapAlts[weap]]; + } +// value2 = ps->ammoclip[weapAlts[weap]]; + } + } + + if ( value > -1 ) { + if ( shader ) { + trap_R_SetColor( color ); + CG_DrawPic( rect->x, rect->y, rect->w, rect->h, shader ); + trap_R_SetColor( NULL ); + } else { + Com_sprintf( num, sizeof( num ), "%i", value ); + value = CG_Text_Width( num, font, scale, 0 ); + CG_Text_Paint( rect->x + ( rect->w - value ) / 2, rect->y + rect->h, font, scale, color, num, 0, 0, textStyle ); + +// if(special) { // draw '0' for akimbo guns + if ( value2 || ( special && type == 1 ) ) { + Com_sprintf( num, sizeof( num ), "%i /", value2 ); + value = CG_Text_Width( num, font, scale, 0 ); + CG_Text_Paint( -30 + rect->x + ( rect->w - value ) / 2, rect->y + rect->h, font, scale, color, num, 0, 0, textStyle ); + } + } + } +} + + + +static void CG_DrawPlayerHead( rectDef_t *rect, qboolean draw2D ) { + vec3_t angles; + float size, stretch; + float frac; + float x = rect->x; + + VectorClear( angles ); + + if ( cg.damageTime && cg.time - cg.damageTime < DAMAGE_TIME ) { + frac = (float)( cg.time - cg.damageTime ) / DAMAGE_TIME; + size = rect->w * 1.25 * ( 1.5 - frac * 0.5 ); + + stretch = size - rect->w * 1.25; + // kick in the direction of damage + x -= stretch * 0.5 + cg.damageX * stretch * 0.5; + + cg.headStartYaw = 180 + cg.damageX * 45; + + cg.headEndYaw = 180 + 20 * cos( crandom() * M_PI ); + cg.headEndPitch = 5 * cos( crandom() * M_PI ); + + cg.headStartTime = cg.time; + cg.headEndTime = cg.time + 100 + random() * 2000; + } else { + if ( cg.time >= cg.headEndTime ) { + // select a new head angle + cg.headStartYaw = cg.headEndYaw; + cg.headStartPitch = cg.headEndPitch; + cg.headStartTime = cg.headEndTime; + cg.headEndTime = cg.time + 100 + random() * 2000; + + cg.headEndYaw = 180 + 20 * cos( crandom() * M_PI ); + cg.headEndPitch = 5 * cos( crandom() * M_PI ); + } + + size = rect->w * 1.25; + } + + // if the server was frozen for a while we may have a bad head start time + if ( cg.headStartTime > cg.time ) { + cg.headStartTime = cg.time; + } + + frac = ( cg.time - cg.headStartTime ) / (float)( cg.headEndTime - cg.headStartTime ); + frac = frac * frac * ( 3 - 2 * frac ); + angles[YAW] = cg.headStartYaw + ( cg.headEndYaw - cg.headStartYaw ) * frac; + angles[PITCH] = cg.headStartPitch + ( cg.headEndPitch - cg.headStartPitch ) * frac; + + CG_DrawHead( x, rect->y, rect->w, rect->h, cg.snap->ps.clientNum, angles ); +} + +static void CG_DrawSelectedPlayerHealth( rectDef_t *rect, int font, float scale, vec4_t color, qhandle_t shader, int textStyle ) { + clientInfo_t *ci; + int value; + char num[16]; + + ci = cgs.clientinfo + sortedTeamPlayers[CG_GetSelectedPlayer()]; + if ( ci ) { + if ( shader ) { + trap_R_SetColor( color ); + CG_DrawPic( rect->x, rect->y, rect->w, rect->h, shader ); + trap_R_SetColor( NULL ); + } else { + Com_sprintf( num, sizeof( num ), "%i", ci->health ); + value = CG_Text_Width( num, font, scale, 0 ); + CG_Text_Paint( rect->x + ( rect->w - value ) / 2, rect->y + rect->h, font, scale, color, num, 0, 0, textStyle ); + } + } +} + +static void CG_DrawSelectedPlayerArmor( rectDef_t *rect, int font, float scale, vec4_t color, qhandle_t shader, int textStyle ) { + clientInfo_t *ci; + int value; + char num[16]; + + ci = cgs.clientinfo + sortedTeamPlayers[CG_GetSelectedPlayer()]; + if ( ci ) { + if ( ci->armor > 0 ) { + if ( shader ) { + trap_R_SetColor( color ); + CG_DrawPic( rect->x, rect->y, rect->w, rect->h, shader ); + trap_R_SetColor( NULL ); + } else { + Com_sprintf( num, sizeof( num ), "%i", ci->armor ); + value = CG_Text_Width( num, font, scale, 0 ); + CG_Text_Paint( rect->x + ( rect->w - value ) / 2, rect->y + rect->h, font, scale, color, num, 0, 0, textStyle ); + } + } + } +} + +qhandle_t CG_StatusHandle( int task ) { +#ifdef MISSIONPACK + qhandle_t h = cgs.media.assaultShader; + switch ( task ) { + case TEAMTASK_OFFENSE: + h = cgs.media.assaultShader; + break; + case TEAMTASK_DEFENSE: + h = cgs.media.defendShader; + break; + case TEAMTASK_PATROL: + h = cgs.media.patrolShader; + break; + case TEAMTASK_FOLLOW: + h = cgs.media.followShader; + break; + case TEAMTASK_CAMP: + h = cgs.media.campShader; + break; + case TEAMTASK_RETRIEVE: + h = cgs.media.retrieveShader; + break; + case TEAMTASK_ESCORT: + h = cgs.media.escortShader; + break; + default: + h = cgs.media.assaultShader; + break; + } + return h; +#else + return 0; +#endif // #ifdef MISSIONPACK +} + +static void CG_DrawSelectedPlayerStatus( rectDef_t *rect ) { +#ifdef MISSIONPACK + clientInfo_t *ci = cgs.clientinfo + sortedTeamPlayers[CG_GetSelectedPlayer()]; + if ( ci ) { + qhandle_t h; + if ( cgs.orderPending ) { + // blink the icon + if ( cg.time > cgs.orderTime - 2500 && ( cg.time >> 9 ) & 1 ) { + return; + } + h = CG_StatusHandle( cgs.currentOrder ); + } else { + h = CG_StatusHandle( ci->teamTask ); + } + CG_DrawPic( rect->x, rect->y, rect->w, rect->h, h ); + } +#endif // #ifdef MISSIONPACK +} + + +static void CG_DrawPlayerStatus( rectDef_t *rect ) { +#ifdef MISSIONPACK + clientInfo_t *ci = &cgs.clientinfo[cg.snap->ps.clientNum]; + if ( ci ) { + qhandle_t h = CG_StatusHandle( ci->teamTask ); + CG_DrawPic( rect->x, rect->y, rect->w, rect->h, h ); + } +#endif // #ifdef MISSIONPACK +} + + +static void CG_DrawSelectedPlayerName( rectDef_t *rect, int font, float scale, vec4_t color, qboolean voice, int textStyle ) { + clientInfo_t *ci; + +// ci = cgs.clientinfo + ((voice) ? cgs.currentVoiceClient : sortedTeamPlayers[CG_GetSelectedPlayer()]); + ci = cgs.clientinfo + sortedTeamPlayers[CG_GetSelectedPlayer()]; + if ( ci ) { + CG_Text_Paint( rect->x, rect->y + rect->h, font, scale, color, ci->name, 0, 0, textStyle ); + } +} + +static void CG_DrawSelectedPlayerLocation( rectDef_t *rect, int font, float scale, vec4_t color, int textStyle ) { + clientInfo_t *ci; + ci = cgs.clientinfo + sortedTeamPlayers[CG_GetSelectedPlayer()]; + if ( ci ) { + const char *p = CG_ConfigString( CS_LOCATIONS + ci->location ); + + if ( !p || !*p ) { + p = "unknown"; + } + CG_Text_Paint( rect->x, rect->y + rect->h, font, scale, color, p, 0, 0, textStyle ); + } +} + +static void CG_DrawPlayerLocation( rectDef_t *rect, int font, float scale, vec4_t color, int textStyle ) { + clientInfo_t *ci = &cgs.clientinfo[cg.snap->ps.clientNum]; + if ( ci ) { + const char *p = CG_ConfigString( CS_LOCATIONS + ci->location ); + if ( !p || !*p ) { + p = "unknown"; + } + CG_Text_Paint( rect->x, rect->y + rect->h, font, scale, color, p, 0, 0, textStyle ); + } +} + + + +static void CG_DrawSelectedPlayerWeapon( rectDef_t *rect ) { + clientInfo_t *ci; + + ci = cgs.clientinfo + sortedTeamPlayers[CG_GetSelectedPlayer()]; + if ( ci ) { + if ( cg_weapons[ci->curWeapon].weaponIcon[1] ) { + CG_DrawPic( rect->x, rect->y, rect->w, rect->h, cg_weapons[ci->curWeapon].weaponIcon[1] ); // (SA) using the 'selected' version of the icon + } else { + CG_DrawPic( rect->x, rect->y, rect->w, rect->h, cgs.media.deferShader ); + } + } +} + +static void CG_DrawPlayerScore( rectDef_t *rect, int font, float scale, vec4_t color, qhandle_t shader, int textStyle ) { + char num[16]; + int value = cg.snap->ps.persistant[PERS_SCORE]; + + if ( shader ) { + trap_R_SetColor( color ); + CG_DrawPic( rect->x, rect->y, rect->w, rect->h, shader ); + trap_R_SetColor( NULL ); + } else { + Com_sprintf( num, sizeof( num ), "%i", value ); + value = CG_Text_Width( num, font, scale, 0 ); + CG_Text_Paint( rect->x + ( rect->w - value ) / 2, rect->y + rect->h, font, scale, color, num, 0, 0, textStyle ); + } +} + + +static void CG_DrawHoldableItem( rectDef_t *rect, int font, float scale, qboolean draw2D ) { + int value; + gitem_t *item; + + item = BG_FindItemForHoldable( cg.holdableSelect ); + + if ( !item ) { + return; + } + + value = cg.predictedPlayerState.holdable[cg.holdableSelect]; + + if ( value ) { +// CG_RegisterItemVisuals( value ); + CG_RegisterItemVisuals( item - bg_itemlist ); + + if ( cg.holdableSelect == HI_WINE ) { + if ( value > 3 ) { + value = 3; // 3 stages to icon, just draw full if beyond 'full' + } +// CG_DrawPic( rect->x, rect->y, rect->w, rect->h, cg_items[ value ].icons[2-(value-1)] ); + CG_DrawPic( rect->x, rect->y, rect->w, rect->h, cg_items[item - bg_itemlist].icons[2 - ( value - 1 )] ); + } else { +// CG_DrawPic( rect->x, rect->y, rect->w, rect->h, cg_items[ value ].icons[0] ); + CG_DrawPic( rect->x, rect->y, rect->w, rect->h, cg_items[item - bg_itemlist].icons[0] ); + } + } +} + +void flubfoo() { + int value; + gitem_t *item; + + if ( !cg.holdableSelect ) { + return; + } + + item = BG_FindItemForHoldable( cg.holdableSelect ); + + if ( !item ) { + return; + } + + value = cg.predictedPlayerState.holdable[cg.holdableSelect]; + + if ( value ) { + + trap_R_SetColor( NULL ); + + CG_RegisterItemVisuals( item - bg_itemlist ); + + if ( cg.holdableSelect == HI_WINE ) { + if ( value > 3 ) { + value = 3; // 3 stages to icon, just draw full if beyond 'full' + + } + //----(SA) trying smaller text + //----(SA) and off to the right side of the HUD +// CG_DrawPic( 100, (SCREEN_HEIGHT-ICON_SIZE)-8, ICON_SIZE/2, ICON_SIZE, cg_items[item - bg_itemlist].icons[2-(value-1)] ); + CG_DrawPic( 606, 366, 24, 48, cg_items[item - bg_itemlist].icons[2 - ( value - 1 )] ); + + } else { +// CG_DrawPic( 100, (SCREEN_HEIGHT-ICON_SIZE)-8, ICON_SIZE/2, ICON_SIZE, cg_items[item - bg_itemlist].icons[0] ); + CG_DrawPic( 606, 366, 24, 48, cg_items[item - bg_itemlist].icons[0] ); + + } + + // draw the selection box so it's not just floating in space + CG_DrawPic( 606 - 4, 366 - 4, 32, 56, cgs.media.selectShader ); + } +} + + + +static void CG_DrawPlayerItem( rectDef_t *rect, int font, float scale, qboolean draw2D ) { + int value; + vec3_t origin, angles; + + value = cg.snap->ps.stats[STAT_HOLDABLE_ITEM]; + + if ( value ) { + CG_RegisterItemVisuals( value ); + + if ( qtrue ) { + CG_RegisterItemVisuals( value ); + CG_DrawPic( rect->x, rect->y, rect->w, rect->h, cg_items[ value ].icons[0] ); + } else { + VectorClear( angles ); + origin[0] = 90; + origin[1] = 0; + origin[2] = -10; + angles[YAW] = ( cg.time & 2047 ) * 360 / 2048.0; + CG_Draw3DModel( rect->x, rect->y, rect->w, rect->h, cg_items[ value ].models[0], 0, origin, angles ); + } + } +} + + +static void CG_DrawSelectedPlayerPowerup( rectDef_t *rect, qboolean draw2D ) { + clientInfo_t *ci; + int j; + float x, y; + + ci = cgs.clientinfo + sortedTeamPlayers[CG_GetSelectedPlayer()]; + if ( ci ) { + x = rect->x; + y = rect->y; + + for ( j = 0; j < PW_NUM_POWERUPS; j++ ) { + if ( ci->powerups & ( 1 << j ) ) { + gitem_t *item; + item = BG_FindItemForPowerup( j ); + if ( item ) { + CG_DrawPic( x, y, rect->w, rect->h, trap_R_RegisterShader( item->icon ) ); + x += 3; + y += 3; + return; + } + } + } + } +} + + +static void CG_DrawSelectedPlayerHead( rectDef_t *rect, qboolean draw2D, qboolean voice ) { + clipHandle_t cm; + clientInfo_t *ci; + float len; + vec3_t origin; + vec3_t mins, maxs, angles; + + +// ci = cgs.clientinfo + ((voice) ? cgs.currentVoiceClient : sortedTeamPlayers[CG_GetSelectedPlayer()]); + ci = cgs.clientinfo + sortedTeamPlayers[CG_GetSelectedPlayer()]; + + if ( ci ) { + if ( cg_draw3dIcons.integer ) { + cm = ci->headModel; + if ( !cm ) { + return; + } + + // offset the origin y and z to center the head + trap_R_ModelBounds( cm, mins, maxs ); + + origin[2] = -0.5 * ( mins[2] + maxs[2] ); + origin[1] = 0.5 * ( mins[1] + maxs[1] ); + + // calculate distance so the head nearly fills the box + // assume heads are taller than wide + len = 0.7 * ( maxs[2] - mins[2] ); + origin[0] = len / 0.268; // len / tan( fov/2 ) + + // allow per-model tweaking + VectorAdd( origin, ci->modelInfo->headOffset, origin ); + + angles[PITCH] = 0; + angles[YAW] = 180; + angles[ROLL] = 0; + + CG_Draw3DModel( rect->x, rect->y, rect->w, rect->h, ci->headModel, ci->headSkin, origin, angles ); + + } else if ( cg_drawIcons.integer ) { + CG_DrawPic( rect->x, rect->y, rect->w, rect->h, ci->modelIcon ); + } + + // if they are deferred, draw a cross out + if ( ci->deferred ) { + CG_DrawPic( rect->x, rect->y, rect->w, rect->h, cgs.media.deferShader ); + } + } +} + + +static void CG_DrawPlayerHealth( rectDef_t *rect, int font, float scale, vec4_t color, qhandle_t shader, int textStyle ) { + playerState_t *ps; + int value; + char num[16]; + + ps = &cg.snap->ps; + + value = ps->stats[STAT_HEALTH]; + + if ( shader ) { + trap_R_SetColor( color ); + CG_DrawPic( rect->x, rect->y, rect->w, rect->h, shader ); + trap_R_SetColor( NULL ); + } else { + Com_sprintf( num, sizeof( num ), "%i", value ); + value = CG_Text_Width( num, font, scale, 0 ); + CG_Text_Paint( rect->x + ( rect->w - value ) / 2, rect->y + rect->h, font, scale, color, num, 0, 0, textStyle ); + } +} + + +static void CG_DrawRedScore( rectDef_t *rect, int font, float scale, vec4_t color, qhandle_t shader, int textStyle ) { + int value; + char num[16]; + if ( cgs.scores1 == SCORE_NOT_PRESENT ) { + Com_sprintf( num, sizeof( num ), "-" ); + } else { + Com_sprintf( num, sizeof( num ), "%i", cgs.scores1 ); + } + value = CG_Text_Width( num, font, scale, 0 ); + CG_Text_Paint( rect->x + rect->w - value, rect->y + rect->h, font, scale, color, num, 0, 0, textStyle ); +} + +static void CG_DrawBlueScore( rectDef_t *rect, int font, float scale, vec4_t color, qhandle_t shader, int textStyle ) { + int value; + char num[16]; + + if ( cgs.scores2 == SCORE_NOT_PRESENT ) { + Com_sprintf( num, sizeof( num ), "-" ); + } else { + Com_sprintf( num, sizeof( num ), "%i", cgs.scores2 ); + } + value = CG_Text_Width( num, font, scale, 0 ); + CG_Text_Paint( rect->x + rect->w - value, rect->y + rect->h, font, scale, color, num, 0, 0, textStyle ); +} + +// FIXME: team name support +static void CG_DrawRedName( rectDef_t *rect, int font, float scale, vec4_t color, int textStyle ) { +#ifdef MISSIONPACK + CG_Text_Paint( rect->x, rect->y + rect->h, font, scale, color, cg_redTeamName.string, 0, 0, textStyle ); +#endif // #ifdef MISSIONPACK +} + +static void CG_DrawBlueName( rectDef_t *rect, int font, float scale, vec4_t color, int textStyle ) { +#ifdef MISSIONPACK + CG_Text_Paint( rect->x, rect->y + rect->h, font, scale, color, cg_blueTeamName.string, 0, 0, textStyle ); +#endif // #ifdef MISSIONPACK +} + +static void CG_DrawBlueFlagName( rectDef_t *rect, int font, float scale, vec4_t color, int textStyle ) { +#ifdef MISSIONPACK + int i; + for ( i = 0 ; i < cgs.maxclients ; i++ ) { + if ( cgs.clientinfo[i].infoValid && cgs.clientinfo[i].team == TEAM_RED && cgs.clientinfo[i].powerups & ( 1 << PW_BLUEFLAG ) ) { + CG_Text_Paint( rect->x, rect->y + rect->h, scale, color, cgs.clientinfo[i].name, 0, 0, textStyle ); + return; + } + } +#endif // #ifdef MISSIONPACK +} + +static void CG_DrawBlueFlagStatus( rectDef_t *rect, qhandle_t shader ) { +#ifdef MISSIONPACK + if ( cgs.gametype != GT_CTF && cgs.gametype != GT_1FCTF ) { + if ( cgs.gametype == GT_HARVESTER ) { + vec4_t color = {0, 0, 1, 1}; + trap_R_SetColor( color ); + CG_DrawPic( rect->x, rect->y, rect->w, rect->h, cgs.media.blueCubeIcon ); + trap_R_SetColor( NULL ); + } + return; + } + if ( shader ) { + CG_DrawPic( rect->x, rect->y, rect->w, rect->h, shader ); + } else { + gitem_t *item = BG_FindItemForPowerup( PW_BLUEFLAG ); + if ( item ) { + vec4_t color = {0, 0, 1, 1}; + trap_R_SetColor( color ); + if ( cgs.blueflag >= 0 && cgs.blueflag <= 2 ) { + CG_DrawPic( rect->x, rect->y, rect->w, rect->h, cgs.media.flagShaders[cgs.blueflag] ); + } else { + CG_DrawPic( rect->x, rect->y, rect->w, rect->h, cgs.media.flagShaders[0] ); + } + trap_R_SetColor( NULL ); + } + } +#endif // #ifdef MISSIONPACK +} + +static void CG_DrawBlueFlagHead( rectDef_t *rect ) { +#ifdef MISSIONPACK + int i; + for ( i = 0 ; i < cgs.maxclients ; i++ ) { + if ( cgs.clientinfo[i].infoValid && cgs.clientinfo[i].team == TEAM_RED && cgs.clientinfo[i].powerups & ( 1 << PW_BLUEFLAG ) ) { + vec3_t angles; + VectorClear( angles ); + angles[YAW] = 180 + 20 * sin( cg.time / 650.0 );; + CG_DrawHead( rect->x, rect->y, rect->w, rect->h, 0,angles ); + return; + } + } +#endif // #ifdef MISSIONPACK +} + +static void CG_DrawRedFlagName( rectDef_t *rect, int font, float scale, vec4_t color, int textStyle ) { +#ifdef MISSIONPACK + int i; + for ( i = 0 ; i < cgs.maxclients ; i++ ) { + if ( cgs.clientinfo[i].infoValid && cgs.clientinfo[i].team == TEAM_BLUE && cgs.clientinfo[i].powerups & ( 1 << PW_REDFLAG ) ) { + CG_Text_Paint( rect->x, rect->y + rect->h, scale, color, cgs.clientinfo[i].name, 0, 0, textStyle ); + return; + } + } +#endif // #ifdef MISSIONPACK +} + +static void CG_DrawRedFlagStatus( rectDef_t *rect, qhandle_t shader ) { +#ifdef MISSIONPACK + if ( cgs.gametype != GT_CTF && cgs.gametype != GT_1FCTF ) { + if ( cgs.gametype == GT_HARVESTER ) { + vec4_t color = {1, 0, 0, 1}; + trap_R_SetColor( color ); + CG_DrawPic( rect->x, rect->y, rect->w, rect->h, cgs.media.redCubeIcon ); + trap_R_SetColor( NULL ); + } + return; + } + if ( shader ) { + CG_DrawPic( rect->x, rect->y, rect->w, rect->h, shader ); + } else { + gitem_t *item = BG_FindItemForPowerup( PW_REDFLAG ); + if ( item ) { + vec4_t color = {1, 0, 0, 1}; + trap_R_SetColor( color ); + if ( cgs.redflag >= 0 && cgs.redflag <= 2 ) { + CG_DrawPic( rect->x, rect->y, rect->w, rect->h, cgs.media.flagShaders[cgs.redflag] ); + } else { + CG_DrawPic( rect->x, rect->y, rect->w, rect->h, cgs.media.flagShaders[0] ); + } + trap_R_SetColor( NULL ); + } + } +#endif // #ifdef MISSIONPACK +} + +static void CG_DrawRedFlagHead( rectDef_t *rect ) { +#ifdef MISSIONPACK + int i; + for ( i = 0 ; i < cgs.maxclients ; i++ ) { + if ( cgs.clientinfo[i].infoValid && cgs.clientinfo[i].team == TEAM_BLUE && cgs.clientinfo[i].powerups & ( 1 << PW_REDFLAG ) ) { + vec3_t angles; + VectorClear( angles ); + angles[YAW] = 180 + 20 * sin( cg.time / 650.0 );; + CG_DrawHead( rect->x, rect->y, rect->w, rect->h, 0,angles ); + return; + } + } +#endif // #ifdef MISSIONPACK +} + +static void CG_HarvesterSkulls( rectDef_t *rect, int font, float scale, vec4_t color, qboolean force2D, int textStyle ) { +#ifdef MISSIONPACK + char num[16]; + vec3_t origin, angles; + qhandle_t handle; + int value = cg.snap->ps.generic1; + + if ( cgs.gametype != GT_HARVESTER ) { + return; + } + + if ( value > 99 ) { + value = 99; + } + + Com_sprintf( num, sizeof( num ), "%i", value ); + value = CG_Text_Width( num, font, scale, 0 ); + CG_Text_Paint( rect->x + ( rect->w - value ), rect->y + rect->h, scale, color, num, 0, 0, textStyle ); + + if ( cg_drawIcons.integer ) { + if ( !force2D && cg_draw3dIcons.integer ) { + VectorClear( angles ); + origin[0] = 90; + origin[1] = 0; + origin[2] = -10; + angles[YAW] = ( cg.time & 2047 ) * 360 / 2048.0; + if ( cg.snap->ps.persistant[PERS_TEAM] == TEAM_BLUE ) { + handle = cgs.media.redCubeModel; + } else { + handle = cgs.media.blueCubeModel; + } + CG_Draw3DModel( rect->x, rect->y, 35, 35, handle, 0, origin, angles ); + } else { + if ( cg.snap->ps.persistant[PERS_TEAM] == TEAM_BLUE ) { + handle = cgs.media.redCubeIcon; + } else { + handle = cgs.media.blueCubeIcon; + } + CG_DrawPic( rect->x + 3, rect->y + 16, 20, 20, handle ); + } + } +#endif // #ifdef MISSIONPACK +} + +static void CG_OneFlagStatus( rectDef_t *rect ) { +#ifdef MISSIONPACK + if ( cgs.gametype != GT_1FCTF ) { + return; + } else { + gitem_t *item = BG_FindItemForPowerup( PW_NEUTRALFLAG ); + if ( item ) { + if ( cgs.flagStatus >= 0 && cgs.flagStatus <= 4 ) { + vec4_t color = {1, 1, 1, 1}; + int index = 0; + if ( cgs.flagStatus == FLAG_TAKEN_RED ) { + color[1] = color[2] = 0; + index = 1; + } else if ( cgs.flagStatus == FLAG_TAKEN_BLUE ) { + color[0] = color[1] = 0; + index = 1; + } else if ( cgs.flagStatus == FLAG_DROPPED ) { + index = 2; + } + trap_R_SetColor( color ); + CG_DrawPic( rect->x, rect->y, rect->w, rect->h, cgs.media.flagShaders[index] ); + } + } + } +#endif // #ifdef MISSIONPACK +} + + +static void CG_DrawCTFPowerUp( rectDef_t *rect ) { +#ifdef MISSIONPACK + int value; + value = cg.snap->ps.stats[STAT_PERSISTANT_POWERUP]; + if ( value ) { + CG_RegisterItemVisuals( value ); + CG_DrawPic( rect->x, rect->y, rect->w, rect->h, cg_items[ value ].icon ); + } +#endif // #ifdef MISSIONPACK +} + + + +static void CG_DrawTeamColor( rectDef_t *rect, vec4_t color ) { + CG_DrawTeamBackground( rect->x, rect->y, rect->w, rect->h, color[3], cg.snap->ps.persistant[PERS_TEAM] ); +} + + +static void CG_DrawAreaHoldable( rectDef_t *rect, int align, float spacing, int font, float scale, vec4_t color ) { +} + +static void CG_DrawAreaWeapons( rectDef_t *rect, int align, float spacing, int font, float scale, vec4_t color ) { +} + + +static void CG_DrawAreaPowerUp( rectDef_t *rect, int align, float spacing, int font, float scale, vec4_t color ) { + char num[16]; + int sorted[MAX_POWERUPS]; + int sortedTime[MAX_POWERUPS]; + int i, j, k; + int active; + playerState_t *ps; + int t; + gitem_t *item; + float f; + rectDef_t r2; + float *inc; + r2.x = rect->x; + r2.y = rect->y; + r2.w = rect->w; + r2.h = rect->h; + + inc = ( align == HUD_VERTICAL ) ? &r2.y : &r2.x; + + ps = &cg.snap->ps; + + if ( ps->stats[STAT_HEALTH] <= 0 ) { + return; + } + + // sort the list by time remaining + active = 0; + for ( i = 0 ; i < MAX_POWERUPS ; i++ ) { + if ( !ps->powerups[ i ] ) { + continue; + } + t = ps->powerups[ i ] - cg.time; + // ZOID--don't draw if the power up has unlimited time (999 seconds) + // This is true of the CTF flags + if ( t <= 0 || t >= 999000 ) { + continue; + } + + // insert into the list + for ( j = 0 ; j < active ; j++ ) { + if ( sortedTime[j] >= t ) { + for ( k = active - 1 ; k >= j ; k-- ) { + sorted[k + 1] = sorted[k]; + sortedTime[k + 1] = sortedTime[k]; + } + break; + } + } + sorted[j] = i; + sortedTime[j] = t; + active++; + } + + // draw the icons and timers + for ( i = 0 ; i < active ; i++ ) { + item = BG_FindItemForPowerup( sorted[i] ); + + if ( item ) { + t = ps->powerups[ sorted[i] ]; + if ( t - cg.time >= POWERUP_BLINKS * POWERUP_BLINK_TIME ) { + trap_R_SetColor( NULL ); + } else { + vec4_t modulate; + + f = (float)( t - cg.time ) / POWERUP_BLINK_TIME; + f -= (int)f; + modulate[0] = modulate[1] = modulate[2] = modulate[3] = f; + trap_R_SetColor( modulate ); + } + + CG_DrawPic( r2.x, r2.y, r2.w * .75, r2.h, trap_R_RegisterShader( item->icon ) ); + + Com_sprintf( num, sizeof( num ), "%i", sortedTime[i] / 1000 ); + CG_Text_Paint( r2.x + ( r2.w * .75 ) + 3, r2.y + r2.h, font, scale, color, num, 0, 0, 0 ); + *inc += r2.w + spacing; + } + + } + trap_R_SetColor( NULL ); + +} + +float CG_GetValue( int ownerDraw, int type ) { + centity_t *cent; + clientInfo_t *ci; + playerState_t *ps; + + cent = &cg_entities[cg.snap->ps.clientNum]; + ps = &cg.snap->ps; + + switch ( ownerDraw ) { + + case CG_SELECTEDPLAYER_ARMOR: + ci = cgs.clientinfo + sortedTeamPlayers[CG_GetSelectedPlayer()]; + return ci->armor; + break; + case CG_SELECTEDPLAYER_HEALTH: + ci = cgs.clientinfo + sortedTeamPlayers[CG_GetSelectedPlayer()]; + return ci->health; + break; + + case CG_PLAYER_ARMOR_VALUE: + return ps->stats[STAT_ARMOR]; + break; + case CG_PLAYER_AMMO_VALUE: + if ( cent->currentState.weapon ) { + if ( type == RANGETYPE_RELATIVE ) { + int weap = BG_FindAmmoForWeapon( cent->currentState.weapon ); + return (float)ps->ammo[weap] / (float)ammoTable[weap].maxammo; + } else { + return ps->ammo[BG_FindAmmoForWeapon( cent->currentState.weapon )]; + } + } + break; + case CG_PLAYER_AMMOCLIP_VALUE: + if ( cent->currentState.weapon ) { + if ( type == RANGETYPE_RELATIVE ) { + return (float)ps->ammoclip[BG_FindClipForWeapon( cent->currentState.weapon )] / (float)ammoTable[cent->currentState.weapon].maxclip; + } else { + return ps->ammoclip[BG_FindClipForWeapon( cent->currentState.weapon )]; + } + } + break; + case CG_PLAYER_SCORE: + return cg.snap->ps.persistant[PERS_SCORE]; + break; + case CG_PLAYER_HEALTH: + return ps->stats[STAT_HEALTH]; + break; + case CG_RED_SCORE: + return cgs.scores1; + break; + case CG_BLUE_SCORE: + return cgs.scores2; + break; + case CG_PLAYER_WEAPON_STABILITY: //----(SA) added + return ps->aimSpreadScale; + break; + +#define BONUSTIME 60000.0f +#define SPRINTTIME 20000.0f + + case CG_STAMINA: //----(SA) added + if ( type == RANGETYPE_RELATIVE ) { + return (float)cg.snap->ps.sprintTime / SPRINTTIME; + } else { + return cg.snap->ps.sprintTime; + } + break; + default: + break; + } + + return -1; +} + +qboolean CG_OtherTeamHasFlag() { +#ifdef MISSIONPACK + if ( cgs.gametype == GT_CTF || cgs.gametype == GT_1FCTF ) { + int team = cg.snap->ps.persistant[PERS_TEAM]; + if ( cgs.gametype == GT_1FCTF ) { + if ( team == TEAM_RED && cgs.flagStatus == FLAG_TAKEN_BLUE ) { + return qtrue; + } else if ( team == TEAM_BLUE && cgs.flagStatus == FLAG_TAKEN_RED ) { + return qtrue; + } else { + return qfalse; + } + } else { + if ( team == TEAM_RED && cgs.redflag == FLAG_TAKEN ) { + return qtrue; + } else if ( team == TEAM_BLUE && cgs.blueflag == FLAG_TAKEN ) { + return qtrue; + } else { + return qfalse; + } + } + } +#endif // #ifdef MISSIONPACK + return qfalse; +} + +qboolean CG_YourTeamHasFlag() { +#ifdef MISSIONPACK + if ( cgs.gametype == GT_CTF || cgs.gametype == GT_1FCTF ) { + int team = cg.snap->ps.persistant[PERS_TEAM]; + if ( cgs.gametype == GT_1FCTF ) { + if ( team == TEAM_RED && cgs.flagStatus == FLAG_TAKEN_RED ) { + return qtrue; + } else if ( team == TEAM_BLUE && cgs.flagStatus == FLAG_TAKEN_BLUE ) { + return qtrue; + } else { + return qfalse; + } + } else { + if ( team == TEAM_RED && cgs.blueflag == FLAG_TAKEN ) { + return qtrue; + } else if ( team == TEAM_BLUE && cgs.redflag == FLAG_TAKEN ) { + return qtrue; + } else { + return qfalse; + } + } + } +#endif // #ifdef MISSIONPACK + return qfalse; +} + +// THINKABOUTME: should these be exclusive or inclusive.. +// +qboolean CG_OwnerDrawVisible( int flags ) { + +//----(SA) added + if ( flags & CG_SHOW_NOT_V_BINOC ) { // if looking through binocs + if ( cg.zoomedBinoc ) { + return qfalse; + } + } + + if ( flags & CG_SHOW_NOT_V_SNIPER ) { // if looking through sniper scope + if ( cg.weaponSelect == WP_SNIPERRIFLE ) { + return qfalse; + } + } + + if ( flags & CG_SHOW_NOT_V_SNOOPER ) { // if looking through snooper scope + if ( cg.weaponSelect == WP_SNOOPERSCOPE ) { + return qfalse; + } + } + + if ( flags & CG_SHOW_NOT_V_FGSCOPE ) { // if looking through fg42 scope + if ( cg.weaponSelect == WP_FG42SCOPE ) { + return qfalse; + } + } + +//----(SA) end + + if ( flags & CG_SHOW_TEAMINFO ) { + return ( cg_currentSelectedPlayer.integer == numSortedTeamPlayers ); + } + + if ( flags & CG_SHOW_NOTEAMINFO ) { + return !( cg_currentSelectedPlayer.integer == numSortedTeamPlayers ); + } + + if ( flags & CG_SHOW_OTHERTEAMHASFLAG ) { + return CG_OtherTeamHasFlag(); + } + + if ( flags & CG_SHOW_YOURTEAMHASENEMYFLAG ) { + return CG_YourTeamHasFlag(); + } + +#ifdef MISSIONPACK + if ( flags & ( CG_SHOW_BLUE_TEAM_HAS_REDFLAG | CG_SHOW_RED_TEAM_HAS_BLUEFLAG ) ) { + if ( flags & CG_SHOW_BLUE_TEAM_HAS_REDFLAG && ( cgs.redflag == FLAG_TAKEN || cgs.flagStatus == FLAG_TAKEN_RED ) ) { + return qtrue; + } else if ( flags & CG_SHOW_RED_TEAM_HAS_BLUEFLAG && ( cgs.blueflag == FLAG_TAKEN || cgs.flagStatus == FLAG_TAKEN_BLUE ) ) { + return qtrue; + } + return qfalse; + } +#endif // #ifdef MISSIONPACK + + if ( flags & CG_SHOW_ANYTEAMGAME ) { + if ( cgs.gametype >= GT_TEAM ) { + return qtrue; + } + } + + if ( flags & CG_SHOW_ANYNONTEAMGAME ) { + if ( cgs.gametype < GT_TEAM ) { + return qtrue; + } + } + +#ifdef MISSIONPACK + if ( flags & CG_SHOW_HARVESTER ) { + if ( cgs.gametype == GT_HARVESTER ) { + return qtrue; + } else { + return qfalse; + } + } + + if ( flags & CG_SHOW_ONEFLAG ) { + if ( cgs.gametype == GT_1FCTF ) { + return qtrue; + } else { + return qfalse; + } + } + +#endif // #ifdef MISSIONPACK + if ( flags & CG_SHOW_CTF ) { + if ( cgs.gametype == GT_CTF ) { + return qtrue; + } + } + +#ifdef MISSIONPACK + if ( flags & CG_SHOW_OBELISK ) { + if ( cgs.gametype == GT_OBELISK ) { + return qtrue; + } else { + return qfalse; + } + } +#endif // #ifdef MISSIONPACK + + if ( flags & CG_SHOW_HEALTHCRITICAL ) { + if ( cg.snap->ps.stats[STAT_HEALTH] < 25 ) { + return qtrue; + } + } + + if ( flags & CG_SHOW_HEALTHOK ) { + if ( cg.snap->ps.stats[STAT_HEALTH] > 25 ) { + return qtrue; + } + } + + if ( flags & CG_SHOW_SINGLEPLAYER ) { + if ( cgs.gametype == GT_SINGLE_PLAYER ) { + return qtrue; + } + } + + if ( flags & CG_SHOW_TOURNAMENT ) { + if ( cgs.gametype == GT_TOURNAMENT ) { + return qtrue; + } + } + + if ( flags & CG_SHOW_DURINGINCOMINGVOICE ) { + } + +#ifdef MISSIONPACK + if ( flags & CG_SHOW_IF_PLAYER_HAS_FLAG ) { + if ( cg.snap->ps.powerups[PW_REDFLAG] || cg.snap->ps.powerups[PW_BLUEFLAG] || cg.snap->ps.powerups[PW_NEUTRALFLAG] ) { + return qtrue; + } + } +#endif // #ifdef MISSIONPACK + +//----(SA) added + if ( flags & CG_SHOW_NOT_V_CLEAR ) { + // if /not/ looking through binocs,snooper or sniper + if ( !cg.zoomedBinoc && !( cg.weaponSelect == WP_SNIPERRIFLE ) && !( cg.weaponSelect == WP_SNOOPERSCOPE ) && !( cg.weaponSelect == WP_FG42SCOPE ) ) { + return qfalse; + } + } + + if ( flags & ( CG_SHOW_NOT_V_BINOC | CG_SHOW_NOT_V_SNIPER | CG_SHOW_NOT_V_SNOOPER | CG_SHOW_NOT_V_FGSCOPE ) ) { + // setting any of these does not necessarily disable drawing in regular view + // CG_SHOW_NOT_V_CLEAR must also be set to hide for reg view + if ( !( flags & CG_SHOW_NOT_V_CLEAR ) ) { + return qtrue; + } + } + +//----(SA) end + + + return qfalse; +} + + + +static void CG_DrawPlayerHasFlag( rectDef_t *rect, qboolean force2D ) { +#ifdef MISSIONPACK + int adj = ( force2D ) ? 0 : 2; + if ( cg.predictedPlayerState.powerups[PW_REDFLAG] ) { + CG_DrawFlagModel( rect->x + adj, rect->y + adj, rect->w - adj, rect->h - adj, TEAM_RED, force2D ); + } else if ( cg.predictedPlayerState.powerups[PW_BLUEFLAG] ) { + CG_DrawFlagModel( rect->x + adj, rect->y + adj, rect->w - adj, rect->h - adj, TEAM_BLUE, force2D ); + } else if ( cg.predictedPlayerState.powerups[PW_NEUTRALFLAG] ) { + CG_DrawFlagModel( rect->x + adj, rect->y + adj, rect->w - adj, rect->h - adj, TEAM_FREE, force2D ); + } +#endif // #ifdef MISSIONPACK +} + +static void CG_DrawAreaSystemChat( rectDef_t *rect, int font, float scale, vec4_t color, qhandle_t shader ) { + CG_Text_Paint( rect->x, rect->y + rect->h, font, scale, color, systemChat, 0, 0, 0 ); +} + +static void CG_DrawAreaTeamChat( rectDef_t *rect, int font, float scale, vec4_t color, qhandle_t shader ) { + CG_Text_Paint( rect->x, rect->y + rect->h, font, scale, color,teamChat1, 0, 0, 0 ); +} + +static void CG_DrawAreaChat( rectDef_t *rect, int font, float scale, vec4_t color, qhandle_t shader ) { + CG_Text_Paint( rect->x, rect->y + rect->h, font, scale, color, teamChat2, 0, 0, 0 ); +} + +const char *CG_GetKillerText() { + const unsigned char *s = ""; + if ( cg.killerName[0] ) { + s = va( "Fragged by %s", cg.killerName ); + } + return s; +} + + +static void CG_DrawKiller( rectDef_t *rect, int font, float scale, vec4_t color, qhandle_t shader, int textStyle ) { + // fragged by ... line + if ( cg.killerName[0] ) { + int x = rect->x + rect->w / 2; + CG_Text_Paint( x - CG_Text_Width( CG_GetKillerText(),font, scale, 0 ) / 2, rect->y + rect->h, font, scale, color, CG_GetKillerText(), 0, 0, textStyle ); + } + +} + + +static void CG_DrawCapFragLimit( rectDef_t *rect, int font, float scale, vec4_t color, qhandle_t shader, int textStyle ) { + int limit = ( cgs.gametype >= GT_CTF ) ? cgs.capturelimit : cgs.fraglimit; + CG_Text_Paint( rect->x, rect->y, font, scale, color, va( "%2i", limit ),0, 0, textStyle ); +} + +static void CG_Draw1stPlace( rectDef_t *rect, int font, float scale, vec4_t color, qhandle_t shader, int textStyle ) { + if ( cgs.scores1 != SCORE_NOT_PRESENT ) { + CG_Text_Paint( rect->x, rect->y, font, scale, color, va( "%2i", cgs.scores1 ),0, 0, textStyle ); + } +} + +static void CG_Draw2ndPlace( rectDef_t *rect, int font, float scale, vec4_t color, qhandle_t shader, int textStyle ) { + if ( cgs.scores2 != SCORE_NOT_PRESENT ) { + CG_Text_Paint( rect->x, rect->y, font, scale, color, va( "%2i", cgs.scores2 ),0, 0, textStyle ); + } +} + +const char *CG_GetGameStatusText() { + const /*unsigned*/ char *s = ""; /*SEB*/ + if ( cgs.gametype < GT_TEAM ) { + if ( cg.snap->ps.persistant[PERS_TEAM] != TEAM_SPECTATOR ) { + s = va( "%s place with %i",CG_PlaceString( cg.snap->ps.persistant[PERS_RANK] + 1 ),cg.snap->ps.persistant[PERS_SCORE] ); + } + } else { + if ( cg.teamScores[0] == cg.teamScores[1] ) { + s = va( "Teams are tied at %i", cg.teamScores[0] ); + } else if ( cg.teamScores[0] >= cg.teamScores[1] ) { + s = va( "Red leads Blue, %i to %i", cg.teamScores[0], cg.teamScores[1] ); + } else { + s = va( "Blue leads Red, %i to %i", cg.teamScores[1], cg.teamScores[0] ); + } + } + return s; +} + +static void CG_DrawGameStatus( rectDef_t *rect, int font, float scale, vec4_t color, qhandle_t shader, int textStyle ) { + CG_Text_Paint( rect->x, rect->y + rect->h, font, scale, color, CG_GetGameStatusText(), 0, 0, textStyle ); +} + +const char *CG_GameTypeString() { + if ( cgs.gametype == GT_FFA ) { + return "Free For All"; + } else if ( cgs.gametype == GT_TEAM ) { + return "Team Deathmatch"; + } else if ( cgs.gametype == GT_CTF ) { + return "Capture the Flag"; +#ifdef MISSIONPACK + } else if ( cgs.gametype == GT_1FCTF ) { + return "One Flag CTF"; + } else if ( cgs.gametype == GT_OBELISK ) { + return "Overload"; + } else if ( cgs.gametype == GT_HARVESTER ) { + return "Harvester"; +#endif // #ifdef MISSIONPACK + } + return ""; +} +static void CG_DrawGameType( rectDef_t *rect, int font, float scale, vec4_t color, qhandle_t shader, int textStyle ) { + CG_Text_Paint( rect->x, rect->y + rect->h, font, scale, color, CG_GameTypeString(), 0, 0, textStyle ); +} + +static void CG_Text_Paint_Limit( float *maxX, float x, float y, int font, float scale, vec4_t color, const char* text, float adjust, int limit ) { + int len, count; + vec4_t newColor; + glyphInfo_t *glyph; + if ( text ) { + const /*unsigned*/ char *s = text; /*SEB*/ + float max = *maxX; + float useScale; + + fontInfo_t *fnt = &cgDC.Assets.textFont; + if ( font == UI_FONT_DEFAULT ) { + if ( scale <= cg_smallFont.value ) { + fnt = &cgDC.Assets.smallFont; + } else if ( scale > cg_bigFont.value ) { + fnt = &cgDC.Assets.bigFont; + } + } else if ( font == UI_FONT_BIG ) { + fnt = &cgDC.Assets.bigFont; + } else if ( font == UI_FONT_SMALL ) { + fnt = &cgDC.Assets.smallFont; + } else if ( font == UI_FONT_HANDWRITING ) { + fnt = &cgDC.Assets.handwritingFont; + } + + useScale = scale * fnt->glyphScale; + trap_R_SetColor( color ); + len = strlen( text ); + if ( limit > 0 && len > limit ) { + len = limit; + } + count = 0; + while ( s && *s && count < len ) { + glyph = &fnt->glyphs[*s]; + if ( Q_IsColorString( s ) ) { + memcpy( newColor, g_color_table[ColorIndex( *( s + 1 ) )], sizeof( newColor ) ); + newColor[3] = color[3]; + trap_R_SetColor( newColor ); + s += 2; + continue; + } else { + float yadj = useScale * glyph->top; + if ( CG_Text_Width( s, font, useScale, 1 ) + x > max ) { + *maxX = 0; + break; + } + CG_Text_PaintChar( x, y - yadj, + glyph->imageWidth, + glyph->imageHeight, + useScale, + glyph->s, + glyph->t, + glyph->s2, + glyph->t2, + glyph->glyph ); + x += ( glyph->xSkip * useScale ) + adjust; + *maxX = x; + count++; + s++; + } + } + trap_R_SetColor( NULL ); + } + +} + + + +#define PIC_WIDTH 12 + +void CG_DrawNewTeamInfo( rectDef_t *rect, float text_x, float text_y, int font, float scale, vec4_t color, qhandle_t shader ) { +#ifdef MISSIONPACK + int xx; + float y; + int i, j, len, count; + const char *p; + vec4_t hcolor; + float pwidth, lwidth, maxx, leftOver; + clientInfo_t *ci; + gitem_t *item; + qhandle_t h; + + // max player name width + pwidth = 0; + count = ( numSortedTeamPlayers > 8 ) ? 8 : numSortedTeamPlayers; + for ( i = 0; i < count; i++ ) { + ci = cgs.clientinfo + sortedTeamPlayers[i]; + if ( ci->infoValid && ci->team == cg.snap->ps.persistant[PERS_TEAM] ) { + len = CG_Text_Width( ci->name, font, scale, 0 ); + if ( len > pwidth ) { + pwidth = len; + } + } + } + + // max location name width + lwidth = 0; + for ( i = 1; i < MAX_LOCATIONS; i++ ) { + p = CG_ConfigString( CS_LOCATIONS + i ); + if ( p && *p ) { + len = CG_Text_Width( p, font, scale, 0 ); + if ( len > lwidth ) { + lwidth = len; + } + } + } + + y = rect->y; + + for ( i = 0; i < count; i++ ) { + ci = cgs.clientinfo + sortedTeamPlayers[i]; + if ( ci->infoValid && ci->team == cg.snap->ps.persistant[PERS_TEAM] ) { + + xx = rect->x + 1; + for ( j = 0; j <= PW_NUM_POWERUPS; j++ ) { + if ( ci->powerups & ( 1 << j ) ) { + + item = BG_FindItemForPowerup( j ); + + if ( item ) { + CG_DrawPic( xx, y, PIC_WIDTH, PIC_WIDTH, trap_R_RegisterShader( item->icon ) ); + xx += PIC_WIDTH; + } + } + } + + // FIXME: max of 3 powerups shown properly + xx = rect->x + ( PIC_WIDTH * 3 ) + 2; + + CG_GetColorForHealth( ci->health, ci->armor, hcolor ); + trap_R_SetColor( hcolor ); + CG_DrawPic( xx, y + 1, PIC_WIDTH - 2, PIC_WIDTH - 2, cgs.media.heartShader ); + + //Com_sprintf (st, sizeof(st), "%3i %3i", ci->health, ci->armor); + //CG_Text_Paint(xx, y + text_y, scale, hcolor, st, 0, 0); + + // draw weapon icon + xx += PIC_WIDTH + 1; + +// weapon used is not that useful, use the space for task +#if 0 + if ( cg_weapons[ci->curWeapon].weaponIcon ) { + CG_DrawPic( xx, y, PIC_WIDTH, PIC_WIDTH, cg_weapons[ci->curWeapon].weaponIcon ); + } else { + CG_DrawPic( xx, y, PIC_WIDTH, PIC_WIDTH, cgs.media.deferShader ); + } +#endif + + trap_R_SetColor( NULL ); + if ( cgs.orderPending ) { + // blink the icon + if ( cg.time > cgs.orderTime - 2500 && ( cg.time >> 9 ) & 1 ) { + h = 0; + } else { + h = CG_StatusHandle( cgs.currentOrder ); + } + } else { + h = CG_StatusHandle( ci->teamTask ); + } + + if ( h ) { + CG_DrawPic( xx, y, PIC_WIDTH, PIC_WIDTH, h ); + } + + xx += PIC_WIDTH + 1; + + leftOver = rect->w - xx; + maxx = xx + leftOver / 3; + + + + CG_Text_Paint_Limit( &maxx, xx, y + text_y, UI_FONT_DEFAULT, scale, color, ci->name, 0, 0 ); + + p = CG_ConfigString( CS_LOCATIONS + ci->location ); + if ( !p || !*p ) { + p = "unknown"; + } + + xx += leftOver / 3 + 2; + maxx = rect->w - 4; + + CG_Text_Paint_Limit( &maxx, xx, y + text_y, UI_FONT_DEFAULT, scale, color, p, 0, 0 ); + y += text_y + 2; + if ( y + text_y + 2 > rect->y + rect->h ) { + break; + } + + } + } +#endif // #ifdef MISSIONPACK +} + + +void CG_DrawTeamSpectators( rectDef_t *rect, int font, float scale, vec4_t color, qhandle_t shader ) { + if ( cg.spectatorLen ) { + float maxX; + + if ( cg.spectatorWidth == -1 ) { + cg.spectatorWidth = 0; + cg.spectatorPaintX = rect->x + 1; + cg.spectatorPaintX2 = -1; + } + + if ( cg.spectatorOffset > cg.spectatorLen ) { + cg.spectatorOffset = 0; + cg.spectatorPaintX = rect->x + 1; + cg.spectatorPaintX2 = -1; + } + + if ( cg.time > cg.spectatorTime ) { + cg.spectatorTime = cg.time + 10; + if ( cg.spectatorPaintX <= rect->x + 2 ) { + if ( cg.spectatorOffset < cg.spectatorLen ) { + cg.spectatorPaintX += CG_Text_Width( &cg.spectatorList[cg.spectatorOffset], font, scale, 1 ) - 1; + cg.spectatorOffset++; + } else { + cg.spectatorOffset = 0; + if ( cg.spectatorPaintX2 >= 0 ) { + cg.spectatorPaintX = cg.spectatorPaintX2; + } else { + cg.spectatorPaintX = rect->x + rect->w - 2; + } + cg.spectatorPaintX2 = -1; + } + } else { + cg.spectatorPaintX--; + if ( cg.spectatorPaintX2 >= 0 ) { + cg.spectatorPaintX2--; + } + } + } + + maxX = rect->x + rect->w - 2; + CG_Text_Paint_Limit( &maxX, cg.spectatorPaintX, rect->y + rect->h - 3, UI_FONT_DEFAULT, scale, color, &cg.spectatorList[cg.spectatorOffset], 0, 0 ); + if ( cg.spectatorPaintX2 >= 0 ) { + float maxX2 = rect->x + rect->w - 2; + CG_Text_Paint_Limit( &maxX2, cg.spectatorPaintX2, rect->y + rect->h - 3, UI_FONT_DEFAULT, scale, color, cg.spectatorList, 0, cg.spectatorOffset ); + } + if ( cg.spectatorOffset && maxX > 0 ) { + // if we have an offset ( we are skipping the first part of the string ) and we fit the string + if ( cg.spectatorPaintX2 == -1 ) { + cg.spectatorPaintX2 = rect->x + rect->w - 2; + } + } else { + cg.spectatorPaintX2 = -1; + } + + } +} + + + +void CG_DrawMedal( int ownerDraw, rectDef_t *rect, int font, float scale, vec4_t color, qhandle_t shader ) { + score_t *score = &cg.scores[cg.selectedScore]; + float value = 0; + char *text = NULL; + color[3] = 0.25; + + switch ( ownerDraw ) { + case CG_ACCURACY: + value = score->accuracy; + break; + case CG_ASSISTS: + value = score->assistCount; + break; + case CG_DEFEND: + value = score->defendCount; + break; + case CG_EXCELLENT: + value = score->excellentCount; + break; + case CG_IMPRESSIVE: + value = score->impressiveCount; + break; + case CG_PERFECT: + value = score->perfect; + break; + case CG_GAUNTLET: + value = score->guantletCount; + break; + case CG_CAPTURES: + value = score->captures; + break; + } + + if ( value > 0 ) { + if ( ownerDraw != CG_PERFECT ) { + if ( ownerDraw == CG_ACCURACY ) { + text = va( "%i%%", (int)value ); + if ( value > 50 ) { + color[3] = 1.0; + } + } else { + text = va( "%i", (int)value ); + color[3] = 1.0; + } + } else { + if ( value ) { + color[3] = 1.0; + } + text = "Wow"; + } + } + + trap_R_SetColor( color ); + CG_DrawPic( rect->x, rect->y, rect->w, rect->h, shader ); + + if ( text ) { + color[3] = 1.0; + value = CG_Text_Width( text, font, scale, 0 ); + CG_Text_Paint( rect->x + ( rect->w - value ) / 2, rect->y + rect->h + 10, font, scale, color, text, 0, 0, 0 ); + } + trap_R_SetColor( NULL ); + +} + + +/* +============== +CG_DrawWeapStability + draw a bar showing current stability level (0-255), max at current weapon/ability, and 'perfect' reference mark + + probably only drawn for scoped weapons +============== +*/ +void CG_DrawWeapStability( rectDef_t *rect, vec4_t color, int align ) { + vec4_t goodColor = {0, 1, 0, 0.5f}, badColor = {1, 0, 0, 0.5f}; + + if ( !cg_drawSpreadScale.integer ) { + return; + } + + if ( cg_drawSpreadScale.integer == 1 && !( cg.weaponSelect == WP_SNOOPERSCOPE || cg.weaponSelect == WP_SNIPERRIFLE || cg.weaponSelect == WP_FG42SCOPE ) ) { + // cg_drawSpreadScale of '1' means only draw for scoped weapons, '2' means draw all the time (for debugging) + return; + } + + if ( !( cg.snap->ps.aimSpreadScale ) ) { + return; + } + + CG_FilledBar( rect->x, rect->y, rect->w, rect->h, goodColor, badColor, NULL, (float)cg.snap->ps.aimSpreadScale / 255.0f, 2 | 4 | 256 ); // flags (BAR_CENTER|BAR_VERT|BAR_LERP_COLOR) +} + + +/* +============== +CG_DrawWeapHeat +============== +*/ +void CG_DrawWeapHeat( rectDef_t *rect, int align ) { + vec4_t color = {1, 0, 0, 0.2f}, color2 = {1, 0, 0, 0.5f}; + int flags = 0; + + if ( !( cg.snap->ps.curWeapHeat ) ) { + return; + } + + if ( align != HUD_HORIZONTAL ) { + flags |= 4; // BAR_VERT + + } + flags |= 1; // BAR_LEFT - this is hardcoded now, but will be decided by the menu script + flags |= 16; // BAR_BG - draw the filled contrast box +// flags|=32; // BAR_BGSPACING_X0Y5 - different style + + flags |= 256; // BAR_COLOR_LERP + CG_FilledBar( rect->x, rect->y, rect->w, rect->h, color, color2, NULL, (float)cg.snap->ps.curWeapHeat / 255.0f, flags ); +} + + +/* +============== +CG_DrawFatigue +============== +*/ + +static void CG_DrawFatigue( rectDef_t *rect, vec4_t color, int align ) { + // vec4_t color = {0, 1, 0, 1}, color2 = {1, 0, 0, 1}; + vec4_t colorBonus = {1, 1, 0, 0.45f}; // yellow (a little more solid for the 'bonus' stamina) + float barFrac; //, omBarFrac; + int flags = 0; + float chargeTime; // DHM - Nerve + + barFrac = (float)cg.snap->ps.sprintTime / SPRINTTIME; +// omBarFrac = 1.0f-barFrac; + + if ( align != HUD_HORIZONTAL ) { + flags |= 4; // BAR_VERT + flags |= 1; // BAR_LEFT (left, when vertical means grow 'up') + } + + CG_FilledBar( rect->x, rect->y, rect->w, rect->h, color, NULL, NULL, (float)cg.snap->ps.sprintTime / SPRINTTIME, flags ); + + // fill in the left side of the bar with the counter for the nofatigue powerup + if ( cg.snap->ps.powerups[PW_NOFATIGUE] ) { + CG_FilledBar( rect->x, rect->y, rect->w / 2, rect->h, colorBonus, NULL, NULL, cg.snap->ps.powerups[PW_NOFATIGUE] / BONUSTIME, flags ); + } +// JPW NERVE -- added drawWeaponPercent in multiplayer, drawn to left + if ( cgs.gametype != GT_SINGLE_PLAYER ) { + + if ( cg.snap->ps.stats[ STAT_PLAYER_CLASS ] == PC_ENGINEER ) { + chargeTime = cg_engineerChargeTime.value; + } else if ( cg.snap->ps.stats[ STAT_PLAYER_CLASS ] == PC_MEDIC ) { + chargeTime = cg_medicChargeTime.value; + } else if ( cg.snap->ps.stats[ STAT_PLAYER_CLASS ] == PC_LT ) { + chargeTime = cg_LTChargeTime.value; + } else { + chargeTime = cg_soldierChargeTime.value; + } + + barFrac = (float)( cg.time - cg.snap->ps.classWeaponTime ) / chargeTime; + + if ( barFrac > 1.0 ) { + barFrac = 1.0; + } + + color[0] = 1.0f; + color[1] = color[2] = barFrac; + color[3] = 0.25 + barFrac * 0.5; + + CG_FilledBar( rect->x - rect->w, rect->y, rect->w / 2, rect->h, color, NULL, NULL, barFrac, flags ); + } +// jpw +} + + +/* +============== +CG_OwnerDraw +============== +*/ +void CG_OwnerDraw( float x, float y, float w, float h, float text_x, float text_y, int ownerDraw, int ownerDrawFlags, int align, float special, int font, float scale, vec4_t color, qhandle_t shader, int textStyle ) { + rectDef_t rect; + + if ( cg_drawStatus.integer == 0 ) { + return; + } + + //if (ownerDrawFlags != 0 && !CG_OwnerDrawVisible(ownerDrawFlags)) { + // return; + //} + + rect.x = x; + rect.y = y; + rect.w = w; + rect.h = h; + + switch ( ownerDraw ) { + case CG_PLAYER_WEAPON_ICON2D: + CG_DrawPlayerWeaponIcon( &rect, ownerDrawFlags & CG_SHOW_HIGHLIGHTED, align ); + break; + case CG_PLAYER_ARMOR_ICON: + CG_DrawPlayerArmorIcon( &rect, ownerDrawFlags & CG_SHOW_2DONLY ); + break; + case CG_PLAYER_ARMOR_ICON2D: + CG_DrawPlayerArmorIcon( &rect, qtrue ); + break; + case CG_PLAYER_ARMOR_VALUE: + CG_DrawPlayerArmorValue( &rect, font, scale, color, shader, textStyle ); + break; + case CG_PLAYER_AMMO_ICON: + CG_DrawPlayerAmmoIcon( &rect, ownerDrawFlags & CG_SHOW_2DONLY ); + break; + case CG_PLAYER_AMMO_ICON2D: + CG_DrawPlayerAmmoIcon( &rect, qtrue ); + break; + case CG_PLAYER_AMMO_VALUE: + CG_DrawPlayerAmmoValue( &rect, font, scale, color, shader, textStyle, 0 ); + break; + case CG_CURSORHINT: + CG_DrawCursorhint( &rect ); + break; +//----(SA) added + case CG_NEWMESSAGE: + CG_DrawMessageIcon( &rect ); + break; +//----(SA) end + case CG_PLAYER_AMMOCLIP_VALUE: + CG_DrawPlayerAmmoValue( &rect, font, scale, color, shader, textStyle, 1 ); + break; + case CG_SELECTEDPLAYER_HEAD: + CG_DrawSelectedPlayerHead( &rect, ownerDrawFlags & CG_SHOW_2DONLY, qfalse ); + break; + case CG_VOICE_HEAD: + CG_DrawSelectedPlayerHead( &rect, ownerDrawFlags & CG_SHOW_2DONLY, qtrue ); + break; + case CG_VOICE_NAME: + CG_DrawSelectedPlayerName( &rect, font, scale, color, qtrue, textStyle ); + break; + case CG_SELECTEDPLAYER_STATUS: + CG_DrawSelectedPlayerStatus( &rect ); + break; + case CG_SELECTEDPLAYER_ARMOR: + CG_DrawSelectedPlayerArmor( &rect, font, scale, color, shader, textStyle ); + break; + case CG_SELECTEDPLAYER_HEALTH: + CG_DrawSelectedPlayerHealth( &rect, font, scale, color, shader, textStyle ); + break; + case CG_SELECTEDPLAYER_NAME: + CG_DrawSelectedPlayerName( &rect, font, scale, color, qfalse, textStyle ); + break; + case CG_SELECTEDPLAYER_LOCATION: + CG_DrawSelectedPlayerLocation( &rect, font, scale, color, textStyle ); + break; + case CG_SELECTEDPLAYER_WEAPON: + CG_DrawSelectedPlayerWeapon( &rect ); + break; + case CG_SELECTEDPLAYER_POWERUP: + CG_DrawSelectedPlayerPowerup( &rect, ownerDrawFlags & CG_SHOW_2DONLY ); + break; + case CG_PLAYER_WEAPON_HEAT: + CG_DrawWeapHeat( &rect, align ); + break; + case CG_PLAYER_WEAPON_STABILITY: + CG_DrawWeapStability( &rect, color, align ); + break; + case CG_STAMINA: + CG_DrawFatigue( &rect, color, align ); + break; + case CG_PLAYER_HEAD: + CG_DrawPlayerHead( &rect, ownerDrawFlags & CG_SHOW_2DONLY ); + break; + case CG_PLAYER_HOLDABLE: + CG_DrawHoldableItem( &rect, font, scale, ownerDrawFlags & CG_SHOW_2DONLY ); + break; + case CG_PLAYER_ITEM: + CG_DrawPlayerItem( &rect, font, scale, ownerDrawFlags & CG_SHOW_2DONLY ); + break; + case CG_PLAYER_SCORE: + CG_DrawPlayerScore( &rect, font, scale, color, shader, textStyle ); + break; + case CG_PLAYER_HEALTH: + CG_DrawPlayerHealth( &rect, font, scale, color, shader, textStyle ); + break; + case CG_RED_SCORE: + CG_DrawRedScore( &rect, font, scale, color, shader, textStyle ); + break; + case CG_BLUE_SCORE: + CG_DrawBlueScore( &rect, font, scale, color, shader, textStyle ); + break; + case CG_RED_NAME: + CG_DrawRedName( &rect, font, scale, color, textStyle ); + break; + case CG_BLUE_NAME: + CG_DrawBlueName( &rect, font, scale, color, textStyle ); + break; + case CG_BLUE_FLAGHEAD: + CG_DrawBlueFlagHead( &rect ); + break; + case CG_BLUE_FLAGSTATUS: + CG_DrawBlueFlagStatus( &rect, shader ); + break; + case CG_BLUE_FLAGNAME: + CG_DrawBlueFlagName( &rect, font, scale, color, textStyle ); + break; + case CG_RED_FLAGHEAD: + CG_DrawRedFlagHead( &rect ); + break; + case CG_RED_FLAGSTATUS: + CG_DrawRedFlagStatus( &rect, shader ); + break; + case CG_RED_FLAGNAME: + CG_DrawRedFlagName( &rect, font, scale, color, textStyle ); + break; + case CG_HARVESTER_SKULLS: + CG_HarvesterSkulls( &rect, font, scale, color, qfalse, textStyle ); + break; + case CG_HARVESTER_SKULLS2D: + CG_HarvesterSkulls( &rect, font, scale, color, qtrue, textStyle ); + break; + case CG_ONEFLAG_STATUS: + CG_OneFlagStatus( &rect ); + break; + case CG_PLAYER_LOCATION: + CG_DrawPlayerLocation( &rect, font, scale, color, textStyle ); + break; + case CG_TEAM_COLOR: + CG_DrawTeamColor( &rect, color ); + break; + case CG_CTF_POWERUP: + CG_DrawCTFPowerUp( &rect ); + break; + case CG_AREA_WEAPON: + CG_DrawAreaWeapons( &rect, align, special, font, scale, color ); + break; + case CG_AREA_HOLDABLE: + CG_DrawAreaHoldable( &rect, align, special, font, scale, color ); + break; + case CG_AREA_POWERUP: + CG_DrawAreaPowerUp( &rect, align, special, font, scale, color ); + break; + case CG_PLAYER_STATUS: + CG_DrawPlayerStatus( &rect ); + break; + case CG_PLAYER_HASFLAG: + CG_DrawPlayerHasFlag( &rect, qfalse ); + break; + case CG_PLAYER_HASFLAG2D: + CG_DrawPlayerHasFlag( &rect, qtrue ); + break; + case CG_AREA_SYSTEMCHAT: + CG_DrawAreaSystemChat( &rect, font, scale, color, shader ); + break; + case CG_AREA_TEAMCHAT: + CG_DrawAreaTeamChat( &rect, font, scale, color, shader ); + break; + case CG_AREA_CHAT: + CG_DrawAreaChat( &rect, font, scale, color, shader ); + break; + case CG_GAME_TYPE: + CG_DrawGameType( &rect, font, scale, color, shader, textStyle ); + break; + case CG_GAME_STATUS: + CG_DrawGameStatus( &rect, font, scale, color, shader, textStyle ); + break; + case CG_KILLER: + CG_DrawKiller( &rect, font, scale, color, shader, textStyle ); + break; + case CG_ACCURACY: + case CG_ASSISTS: + case CG_DEFEND: + case CG_EXCELLENT: + case CG_IMPRESSIVE: + case CG_PERFECT: + case CG_GAUNTLET: + case CG_CAPTURES: + CG_DrawMedal( ownerDraw, &rect, font, scale, color, shader ); + break; + case CG_SPECTATORS: + CG_DrawTeamSpectators( &rect, font, scale, color, shader ); + break; + case CG_TEAMINFO: + if ( cg_currentSelectedPlayer.integer == numSortedTeamPlayers ) { + CG_DrawNewTeamInfo( &rect, text_x, text_y, font, scale, color, shader ); + } + break; + case CG_CAPFRAGLIMIT: + CG_DrawCapFragLimit( &rect, font, scale, color, shader, textStyle ); + break; + case CG_1STPLACE: + CG_Draw1stPlace( &rect, font, scale, color, shader, textStyle ); + break; + case CG_2NDPLACE: + CG_Draw2ndPlace( &rect, font, scale, color, shader, textStyle ); + break; + default: + break; + } +} + +void CG_MouseEvent( int x, int y ) { + int n; + + if ( ( cg.predictedPlayerState.pm_type == PM_NORMAL || cg.predictedPlayerState.pm_type == PM_SPECTATOR ) && cg.showScores == qfalse ) { + trap_Key_SetCatcher( 0 ); + return; + } + + cgs.cursorX += x; + if ( cgs.cursorX < 0 ) { + cgs.cursorX = 0; + } else if ( cgs.cursorX > 640 ) { + cgs.cursorX = 640; + } + + cgs.cursorY += y; + if ( cgs.cursorY < 0 ) { + cgs.cursorY = 0; + } else if ( cgs.cursorY > 480 ) { + cgs.cursorY = 480; + } + + n = Display_CursorType( cgs.cursorX, cgs.cursorY ); + cgs.activeCursor = 0; + if ( n == CURSOR_ARROW ) { + cgs.activeCursor = cgs.media.selectCursor; + } else if ( n == CURSOR_SIZER ) { + cgs.activeCursor = cgs.media.sizeCursor; + } + + if ( cgs.capturedItem ) { + Display_MouseMove( cgs.capturedItem, x, y ); + } else { + Display_MouseMove( NULL, cgs.cursorX, cgs.cursorY ); + } + +} + +/* +================== +CG_HideTeamMenus +================== + +*/ +void CG_HideTeamMenu() { + Menus_CloseByName( "teamMenu" ); + Menus_CloseByName( "getMenu" ); +} + +/* +================== +CG_ShowTeamMenus +================== + +*/ +void CG_ShowTeamMenu() { + Menus_OpenByName( "teamMenu" ); +} + + + + +/* +================== +CG_EventHandling +================== + type 0 - no event handling + 1 - team menu + 2 - hud editor + +*/ +void CG_EventHandling( int type ) { + cgs.eventHandling = type; + if ( type == CGAME_EVENT_NONE ) { + CG_HideTeamMenu(); + } else if ( type == CGAME_EVENT_TEAMMENU ) { + //CG_ShowTeamMenu(); + } else if ( type == CGAME_EVENT_SCOREBOARD ) { + } + +} + + + +void CG_KeyEvent( int key, qboolean down ) { + + if ( !down ) { + return; + } + + if ( cg.predictedPlayerState.pm_type == PM_NORMAL || ( cg.predictedPlayerState.pm_type == PM_SPECTATOR && cg.showScores == qfalse ) ) { + CG_EventHandling( CGAME_EVENT_NONE ); + trap_Key_SetCatcher( 0 ); + return; + } + + //if (key == trap_Key_GetKey("teamMenu") || !Display_CaptureItem(cgs.cursorX, cgs.cursorY)) { + // if we see this then we should always be visible + // CG_EventHandling(CGAME_EVENT_NONE); + // trap_Key_SetCatcher(0); + //} + + + + Display_HandleKey( key, down, cgs.cursorX, cgs.cursorY ); + + if ( cgs.capturedItem ) { + cgs.capturedItem = NULL; + } else { + if ( key == K_MOUSE2 && down ) { + cgs.capturedItem = Display_CaptureItem( cgs.cursorX, cgs.cursorY ); + } + } +} + +int CG_ClientNumFromName( const char *p ) { + int i; + for ( i = 0; i < cgs.maxclients; i++ ) { + if ( cgs.clientinfo[i].infoValid && Q_stricmp( cgs.clientinfo[i].name, p ) == 0 ) { + return i; + } + } + return -1; +} + +void CG_ShowResponseHead() { + Menus_OpenByName( "voiceMenu" ); + trap_Cvar_Set( "cl_conXOffset", "72" ); + cg.voiceTime = cg.time; +} + +void CG_RunMenuScript( char **args ) { +} + + +void CG_GetTeamColor( vec4_t *color ) { + if ( cg.snap->ps.persistant[PERS_TEAM] == TEAM_RED ) { + ( *color )[0] = 1; + ( *color )[3] = .25f; + ( *color )[1] = ( *color )[2] = 0; + } else if ( cg.snap->ps.persistant[PERS_TEAM] == TEAM_BLUE ) { + ( *color )[0] = ( *color )[1] = 0; + ( *color )[2] = 1; + ( *color )[3] = .25f; + } else { + ( *color )[0] = ( *color )[2] = 0; + ( *color )[1] = .17f; + ( *color )[3] = .25f; + } +} + diff --git a/Projects/Android/jni/rtcw/src/cgame/cg_particles.c b/Projects/Android/jni/rtcw/src/cgame/cg_particles.c new file mode 100644 index 0000000..c4f7774 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/cgame/cg_particles.c @@ -0,0 +1,2626 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +// Rafael particles +// cg_particles.c + +#include "cg_local.h" + +#define MUSTARD 1 +#define BLOODRED 2 +#define EMISIVEFADE 3 +#define GREY75 4 +#define ZOMBIE 5 + +typedef struct particle_s +{ + struct particle_s *next; + + float time; + float endtime; + + vec3_t org; + vec3_t vel; + vec3_t accel; + int color; + float colorvel; + float alpha; + float alphavel; + int type; + qhandle_t pshader; + + float height; + float width; + + float endheight; + float endwidth; + + float start; + float end; + + float startfade; + qboolean rotate; + int snum; + + qboolean link; + + // Ridah + int shaderAnim; + int roll; + + int accumroll; + +} cparticle_t; + +typedef enum +{ + P_NONE, + P_WEATHER, + P_FLAT, + P_SMOKE, + P_ROTATE, + P_WEATHER_TURBULENT, + P_ANIM, // Ridah + P_BAT, + P_BLEED, + P_FLAT_SCALEUP, + P_FLAT_SCALEUP_FADE, + P_WEATHER_FLURRY, + P_SMOKE_IMPACT, + P_BUBBLE, + P_BUBBLE_TURBULENT, + P_SPRITE +} particle_type_t; + +#define MAX_SHADER_ANIMS 8 +#define MAX_SHADER_ANIM_FRAMES 64 +static char *shaderAnimNames[MAX_SHADER_ANIMS] = { + "explode1", + "blacksmokeanim", + "twiltb2", + "expblue", + "blacksmokeanimb", // uses 'explode1' sequence + "blood", + NULL +}; +static qhandle_t shaderAnims[MAX_SHADER_ANIMS][MAX_SHADER_ANIM_FRAMES]; +static int shaderAnimCounts[MAX_SHADER_ANIMS] = { + 23, + 23, // (SA) removing warning messages from startup + 45, + 25, + 23, + 5, +}; +static float shaderAnimSTRatio[MAX_SHADER_ANIMS] = { + 1.405, + 1, + 1, + 1, + 1, + 1, +}; +static int numShaderAnims; +// done. + +#define PARTICLE_GRAVITY 40 +#define MAX_PARTICLES 1024 * 8 + +cparticle_t *active_particles, *free_particles; +cparticle_t particles[MAX_PARTICLES]; +int cl_numparticles = MAX_PARTICLES; + +qboolean initparticles = qfalse; +vec3_t vforward, vright, vup; +vec3_t rforward, rright, rup; + +float oldtime; + + +/* +============== +CG_ParticleLODCheck +============== +*/ +qboolean CG_ParticleLODCheck( void ) { + if ( cg_particleLOD.integer <= 1 ) { + return qtrue; + } + + + if ( !( rand() % ( cg_particleLOD.integer ) ) ) { // let particle lod thin out particles + return qtrue; + } + + return qfalse; +} + +/* +=============== +CL_ClearParticles +=============== +*/ +void CG_ClearParticles( void ) { + int i; + + memset( particles, 0, sizeof( particles ) ); + + free_particles = &particles[0]; + active_particles = NULL; + + for ( i = 0 ; i < cl_numparticles ; i++ ) + { + particles[i].next = &particles[i + 1]; + particles[i].type = 0; + } + particles[cl_numparticles - 1].next = NULL; + + oldtime = cg.time; + + // Ridah, init the shaderAnims + for ( i = 0; shaderAnimNames[i]; i++ ) { + int j; + + for ( j = 0; j < shaderAnimCounts[i]; j++ ) { + shaderAnims[i][j] = trap_R_RegisterShader( va( "%s%i", shaderAnimNames[i], j + 1 ) ); + } + } + numShaderAnims = i; + // done. + + initparticles = qtrue; +} + + +/* +===================== +CG_AddParticleToScene +===================== +*/ +void CG_AddParticleToScene( cparticle_t *p, vec3_t org, float alpha ) { + + vec3_t point; + polyVert_t verts[4]; + float width; + float height; + float time, time2; + float ratio; + float invratio; + vec3_t color; + polyVert_t TRIverts[3]; + vec3_t rright2, rup2; + + if ( p->type == P_WEATHER || p->type == P_WEATHER_TURBULENT || p->type == P_WEATHER_FLURRY + || p->type == P_BUBBLE || p->type == P_BUBBLE_TURBULENT ) { // create a front facing polygon + + if ( p->type != P_WEATHER_FLURRY ) { + if ( p->type == P_BUBBLE || p->type == P_BUBBLE_TURBULENT ) { + if ( org[2] > p->end ) { + p->time = cg.time; + VectorCopy( org, p->org ); // Ridah, fixes rare snow flakes that flicker on the ground + + p->org[2] = ( p->start + crandom() * 4 ); + + + if ( p->type == P_BUBBLE_TURBULENT ) { + p->vel[0] = crandom() * 4; + p->vel[1] = crandom() * 4; + } + + } + } else + { + if ( org[2] < p->end ) { + p->time = cg.time; + VectorCopy( org, p->org ); // Ridah, fixes rare snow flakes that flicker on the ground + + while ( p->org[2] < p->end ) + { + p->org[2] += ( p->start - p->end ); + } + + + if ( p->type == P_WEATHER_TURBULENT ) { + p->vel[0] = crandom() * 16; + p->vel[1] = crandom() * 16; + } + + } + } + + + // Rafael snow pvs check + if ( !p->link ) { + return; + } + + p->alpha = 1; + } + + // Ridah, had to do this or MAX_POLYS is being exceeded in village1.bsp + //----(SA) made the dist a cvar + + // dot product removal (gets you the dist^2, which you needed anyway, also dot lets you adjust lod when zooming) + if ( 1 ) { + vec3_t dir; + float dot, distSqrd; + + VectorSubtract( cg.refdef.vieworg, org, dir ); + distSqrd = dir[0] * dir[0] + dir[1] * dir[1] + dir[2] * dir[2]; + + dot = DotProduct( dir, cg.refdef.viewaxis[0] ); + + if ( distSqrd > ( cg_particleDist.value * cg_particleDist.value ) ) { + return; + } + } + + + + // done. + + if ( p->type == P_BUBBLE || p->type == P_BUBBLE_TURBULENT ) { + VectorMA( org, -p->height, vup, point ); + VectorMA( point, -p->width, vright, point ); + VectorCopy( point, verts[0].xyz ); + verts[0].st[0] = 0; + verts[0].st[1] = 0; + verts[0].modulate[0] = 255; + verts[0].modulate[1] = 255; + verts[0].modulate[2] = 255; + verts[0].modulate[3] = 255 * p->alpha; + + VectorMA( org, -p->height, vup, point ); + VectorMA( point, p->width, vright, point ); + VectorCopy( point, verts[1].xyz ); + verts[1].st[0] = 0; + verts[1].st[1] = 1; + verts[1].modulate[0] = 255; + verts[1].modulate[1] = 255; + verts[1].modulate[2] = 255; + verts[1].modulate[3] = 255 * p->alpha; + + VectorMA( org, p->height, vup, point ); + VectorMA( point, p->width, vright, point ); + VectorCopy( point, verts[2].xyz ); + verts[2].st[0] = 1; + verts[2].st[1] = 1; + verts[2].modulate[0] = 255; + verts[2].modulate[1] = 255; + verts[2].modulate[2] = 255; + verts[2].modulate[3] = 255 * p->alpha; + + VectorMA( org, p->height, vup, point ); + VectorMA( point, -p->width, vright, point ); + VectorCopy( point, verts[3].xyz ); + verts[3].st[0] = 1; + verts[3].st[1] = 0; + verts[3].modulate[0] = 255; + verts[3].modulate[1] = 255; + verts[3].modulate[2] = 255; + verts[3].modulate[3] = 255 * p->alpha; + } else + { + VectorMA( org, -p->height, vup, point ); + VectorMA( point, -p->width, vright, point ); + VectorCopy( point, TRIverts[0].xyz ); + TRIverts[0].st[0] = 1; + TRIverts[0].st[1] = 0; + TRIverts[0].modulate[0] = 255; + TRIverts[0].modulate[1] = 255; + TRIverts[0].modulate[2] = 255; + TRIverts[0].modulate[3] = 255 * p->alpha; + + VectorMA( org, p->height, vup, point ); + VectorMA( point, -p->width, vright, point ); + VectorCopy( point, TRIverts[1].xyz ); + TRIverts[1].st[0] = 0; + TRIverts[1].st[1] = 0; + TRIverts[1].modulate[0] = 255; + TRIverts[1].modulate[1] = 255; + TRIverts[1].modulate[2] = 255; + TRIverts[1].modulate[3] = 255 * p->alpha; + + VectorMA( org, p->height, vup, point ); + VectorMA( point, p->width, vright, point ); + VectorCopy( point, TRIverts[2].xyz ); + TRIverts[2].st[0] = 0; + TRIverts[2].st[1] = 1; + TRIverts[2].modulate[0] = 255; + TRIverts[2].modulate[1] = 255; + TRIverts[2].modulate[2] = 255; + TRIverts[2].modulate[3] = 255 * p->alpha; + } + + } else if ( p->type == P_SPRITE ) { + vec3_t rr, ru; + vec3_t rotate_ang; + + VectorSet( color, 1.0, 1.0, 1.0 ); + time = cg.time - p->time; + time2 = p->endtime - p->time; + ratio = time / time2; + + width = p->width + ( ratio * ( p->endwidth - p->width ) ); + height = p->height + ( ratio * ( p->endheight - p->height ) ); + + if ( p->roll ) { + vectoangles( cg.refdef.viewaxis[0], rotate_ang ); + rotate_ang[ROLL] += p->roll; + AngleVectors( rotate_ang, NULL, rr, ru ); + } + + if ( p->roll ) { + VectorMA( org, -height, ru, point ); + VectorMA( point, -width, rr, point ); + } else { + VectorMA( org, -height, vup, point ); + VectorMA( point, -width, vright, point ); + } + VectorCopy( point, verts[0].xyz ); + verts[0].st[0] = 0; + verts[0].st[1] = 0; + verts[0].modulate[0] = 255; + verts[0].modulate[1] = 255; + verts[0].modulate[2] = 255; + verts[0].modulate[3] = 255; + + if ( p->roll ) { + VectorMA( point, 2 * height, ru, point ); + } else { + VectorMA( point, 2 * height, vup, point ); + } + VectorCopy( point, verts[1].xyz ); + verts[1].st[0] = 0; + verts[1].st[1] = 1; + verts[1].modulate[0] = 255; + verts[1].modulate[1] = 255; + verts[1].modulate[2] = 255; + verts[1].modulate[3] = 255; + + if ( p->roll ) { + VectorMA( point, 2 * width, rr, point ); + } else { + VectorMA( point, 2 * width, vright, point ); + } + VectorCopy( point, verts[2].xyz ); + verts[2].st[0] = 1; + verts[2].st[1] = 1; + verts[2].modulate[0] = 255; + verts[2].modulate[1] = 255; + verts[2].modulate[2] = 255; + verts[2].modulate[3] = 255; + + if ( p->roll ) { + VectorMA( point, -2 * height, ru, point ); + } else { + VectorMA( point, -2 * height, vup, point ); + } + VectorCopy( point, verts[3].xyz ); + verts[3].st[0] = 1; + verts[3].st[1] = 0; + verts[3].modulate[0] = 255; + verts[3].modulate[1] = 255; + verts[3].modulate[2] = 255; + verts[3].modulate[3] = 255; + } else if ( p->type == P_SMOKE || p->type == P_SMOKE_IMPACT ) { // create a front rotating facing polygon + +// if ( p->type == P_SMOKE_IMPACT && Distance( cg.snap->ps.origin, org ) > 1024) { +// return; +// } + + // dot product removal (gets you the dist^2, which you needed anyway, also dot lets you adjust lod when zooming) + if ( 1 ) { + vec3_t dir; + float dot, distSqrd, fardist; + + VectorSubtract( org, cg.refdef.vieworg, dir ); + distSqrd = dir[0] * dir[0] + dir[1] * dir[1] + dir[2] * dir[2]; + + VectorNormalize( dir ); + dot = DotProduct( dir, cg.refdef.viewaxis[0] ); + + if ( dot < 0 ) { // behind camera + return; + } + + fardist = ( cg_particleDist.value * cg_particleDist.value ); + // push distance out when zooming + if ( cg.predictedPlayerState.eFlags & EF_ZOOMING ) { + fardist *= 2; + } + +// if(fabs(dot) < 0.8) +// return; + + if ( distSqrd > fardist ) { + return; + } + } + + + if ( p->color == MUSTARD ) { + VectorSet( color, 0.42, 0.33, 0.19 ); + } else if ( p->color == BLOODRED ) { + VectorSet( color, 0.22, 0, 0 ); + } else if ( p->color == ZOMBIE ) { + VectorSet( color, 0.4, 0.28, 0.23 ); + } else if ( p->color == GREY75 ) { + float len; + float greyit; + float val; + len = Distance( cg.snap->ps.origin, org ); + if ( !len ) { + len = 1; + } + + val = 4096 / len; + greyit = 0.25 * val; + if ( greyit > 0.5 ) { + greyit = 0.5; + } + + VectorSet( color, greyit, greyit, greyit ); + } else { + VectorSet( color, 1.0, 1.0, 1.0 ); + } + + time = cg.time - p->time; + time2 = p->endtime - p->time; + ratio = time / time2; + + if ( cg.time > p->startfade ) { + invratio = 1 - ( ( cg.time - p->startfade ) / ( p->endtime - p->startfade ) ); + + if ( p->color == EMISIVEFADE ) { + float fval; + fval = ( invratio * invratio ); + if ( fval < 0 ) { + fval = 0; + } + VectorSet( color, fval, fval, fval ); + } + invratio *= p->alpha; + } else { + invratio = 1 * p->alpha; + } + + if ( cgs.glconfig.hardwareType == GLHW_RAGEPRO ) { + invratio = 1; + } + + if ( invratio > 1 ) { + invratio = 1; + } + + width = p->width + ( ratio * ( p->endwidth - p->width ) ); + height = p->height + ( ratio * ( p->endheight - p->height ) ); + +// if (p->type != P_SMOKE_IMPACT) + { + vec3_t temp; + + vectoangles( rforward, temp ); + p->accumroll += p->roll; + temp[ROLL] += p->accumroll * 0.1; +// temp[ROLL] += p->roll * 0.1; + AngleVectors( temp, NULL, rright2, rup2 ); + } +// else +// { +// VectorCopy (rright, rright2); +// VectorCopy (rup, rup2); +// } + + if ( p->rotate ) { + VectorMA( org, -height, rup2, point ); + VectorMA( point, -width, rright2, point ); + } else + { + VectorMA( org, -p->height, vup, point ); + VectorMA( point, -p->width, vright, point ); + } + VectorCopy( point, verts[0].xyz ); + verts[0].st[0] = 0; + verts[0].st[1] = 0; + verts[0].modulate[0] = 255 * color[0]; + verts[0].modulate[1] = 255 * color[1]; + verts[0].modulate[2] = 255 * color[2]; + verts[0].modulate[3] = 255 * invratio; + + if ( p->rotate ) { + VectorMA( org, -height, rup2, point ); + VectorMA( point, width, rright2, point ); + } else + { + VectorMA( org, -p->height, vup, point ); + VectorMA( point, p->width, vright, point ); + } + VectorCopy( point, verts[1].xyz ); + verts[1].st[0] = 0; + verts[1].st[1] = 1; + verts[1].modulate[0] = 255 * color[0]; + verts[1].modulate[1] = 255 * color[1]; + verts[1].modulate[2] = 255 * color[2]; + verts[1].modulate[3] = 255 * invratio; + + if ( p->rotate ) { + VectorMA( org, height, rup2, point ); + VectorMA( point, width, rright2, point ); + } else + { + VectorMA( org, p->height, vup, point ); + VectorMA( point, p->width, vright, point ); + } + VectorCopy( point, verts[2].xyz ); + verts[2].st[0] = 1; + verts[2].st[1] = 1; + verts[2].modulate[0] = 255 * color[0]; + verts[2].modulate[1] = 255 * color[1]; + verts[2].modulate[2] = 255 * color[2]; + verts[2].modulate[3] = 255 * invratio; + + if ( p->rotate ) { + VectorMA( org, height, rup2, point ); + VectorMA( point, -width, rright2, point ); + } else + { + VectorMA( org, p->height, vup, point ); + VectorMA( point, -p->width, vright, point ); + } + VectorCopy( point, verts[3].xyz ); + verts[3].st[0] = 1; + verts[3].st[1] = 0; + verts[3].modulate[0] = 255 * color[0]; + verts[3].modulate[1] = 255 * color[1]; + verts[3].modulate[2] = 255 * color[2]; + verts[3].modulate[3] = 255 * invratio; + + } else if ( p->type == P_BAT ) { + p->pshader = cgs.media.bats[( cg.time / 50 + (int)( p - particles ) ) % 10]; + + VectorMA( org, -p->height, vup, point ); + VectorMA( point, -p->width, vright, point ); + VectorCopy( point, verts[0].xyz ); + verts[0].st[0] = 0; + verts[0].st[1] = 0; + verts[0].modulate[0] = 255; + verts[0].modulate[1] = 255; + verts[0].modulate[2] = 255; + verts[0].modulate[3] = 255; + + VectorMA( org, -p->height, vup, point ); + VectorMA( point, p->width, vright, point ); + VectorCopy( point, verts[1].xyz ); + verts[1].st[0] = 0; + verts[1].st[1] = 1; + verts[1].modulate[0] = 255; + verts[1].modulate[1] = 255; + verts[1].modulate[2] = 255; + verts[1].modulate[3] = 255; + + VectorMA( org, p->height, vup, point ); + VectorMA( point, p->width, vright, point ); + VectorCopy( point, verts[2].xyz ); + verts[2].st[0] = 1; + verts[2].st[1] = 1; + verts[2].modulate[0] = 255; + verts[2].modulate[1] = 255; + verts[2].modulate[2] = 255; + verts[2].modulate[3] = 255; + + VectorMA( org, p->height, vup, point ); + VectorMA( point, -p->width, vright, point ); + VectorCopy( point, verts[3].xyz ); + verts[3].st[0] = 1; + verts[3].st[1] = 0; + verts[3].modulate[0] = 255; + verts[3].modulate[1] = 255; + verts[3].modulate[2] = 255; + verts[3].modulate[3] = 255; + + } else if ( p->type == P_BLEED ) { + vec3_t rr, ru; + vec3_t rotate_ang; + float alpha; + + alpha = p->alpha; + + if ( cgs.glconfig.hardwareType == GLHW_RAGEPRO ) { + alpha = 1; + } + + if ( p->roll ) { + vectoangles( cg.refdef.viewaxis[0], rotate_ang ); + rotate_ang[ROLL] += p->roll; + AngleVectors( rotate_ang, NULL, rr, ru ); + } else + { + VectorCopy( vup, ru ); + VectorCopy( vright, rr ); + } + + VectorMA( org, -p->height, ru, point ); + VectorMA( point, -p->width, rr, point ); + VectorCopy( point, verts[0].xyz ); + verts[0].st[0] = 0; + verts[0].st[1] = 0; + verts[0].modulate[0] = 111; + verts[0].modulate[1] = 19; + verts[0].modulate[2] = 9; + verts[0].modulate[3] = 255 * alpha; + + VectorMA( org, -p->height, ru, point ); + VectorMA( point, p->width, rr, point ); + VectorCopy( point, verts[1].xyz ); + verts[1].st[0] = 0; + verts[1].st[1] = 1; + verts[1].modulate[0] = 111; + verts[1].modulate[1] = 19; + verts[1].modulate[2] = 9; + verts[1].modulate[3] = 255 * alpha; + + VectorMA( org, p->height, ru, point ); + VectorMA( point, p->width, rr, point ); + VectorCopy( point, verts[2].xyz ); + verts[2].st[0] = 1; + verts[2].st[1] = 1; + verts[2].modulate[0] = 111; + verts[2].modulate[1] = 19; + verts[2].modulate[2] = 9; + verts[2].modulate[3] = 255 * alpha; + + VectorMA( org, p->height, ru, point ); + VectorMA( point, -p->width, rr, point ); + VectorCopy( point, verts[3].xyz ); + verts[3].st[0] = 1; + verts[3].st[1] = 0; + verts[3].modulate[0] = 111; + verts[3].modulate[1] = 19; + verts[3].modulate[2] = 9; + verts[3].modulate[3] = 255 * alpha; + + } else if ( p->type == P_FLAT_SCALEUP ) { + float width, height; + float sinR, cosR; + + if ( p->color == BLOODRED ) { + VectorSet( color, 1, 1, 1 ); + } else { + VectorSet( color, 0.5, 0.5, 0.5 ); + } + + time = cg.time - p->time; + time2 = p->endtime - p->time; + ratio = time / time2; + + width = p->width + ( ratio * ( p->endwidth - p->width ) ); + height = p->height + ( ratio * ( p->endheight - p->height ) ); + + if ( width > p->endwidth ) { + width = p->endwidth; + } + + if ( height > p->endheight ) { + height = p->endheight; + } + + sinR = height * sin( DEG2RAD( p->roll ) ) * sqrt( 2 ); + cosR = width * cos( DEG2RAD( p->roll ) ) * sqrt( 2 ); + + VectorCopy( org, verts[0].xyz ); + verts[0].xyz[0] -= sinR; + verts[0].xyz[1] -= cosR; + verts[0].st[0] = 0; + verts[0].st[1] = 0; + verts[0].modulate[0] = 255 * color[0]; + verts[0].modulate[1] = 255 * color[1]; + verts[0].modulate[2] = 255 * color[2]; + verts[0].modulate[3] = 255; + + VectorCopy( org, verts[1].xyz ); + verts[1].xyz[0] -= cosR; + verts[1].xyz[1] += sinR; + verts[1].st[0] = 0; + verts[1].st[1] = 1; + verts[1].modulate[0] = 255 * color[0]; + verts[1].modulate[1] = 255 * color[1]; + verts[1].modulate[2] = 255 * color[2]; + verts[1].modulate[3] = 255; + + VectorCopy( org, verts[2].xyz ); + verts[2].xyz[0] += sinR; + verts[2].xyz[1] += cosR; + verts[2].st[0] = 1; + verts[2].st[1] = 1; + verts[2].modulate[0] = 255 * color[0]; + verts[2].modulate[1] = 255 * color[1]; + verts[2].modulate[2] = 255 * color[2]; + verts[2].modulate[3] = 255; + + VectorCopy( org, verts[3].xyz ); + verts[3].xyz[0] += cosR; + verts[3].xyz[1] -= sinR; + verts[3].st[0] = 1; + verts[3].st[1] = 0; + verts[3].modulate[0] = 255 * color[0]; + verts[3].modulate[1] = 255 * color[1]; + verts[3].modulate[2] = 255 * color[2]; + verts[3].modulate[3] = 255; + } else if ( p->type == P_FLAT ) { + + VectorCopy( org, verts[0].xyz ); + verts[0].xyz[0] -= p->height; + verts[0].xyz[1] -= p->width; + verts[0].st[0] = 0; + verts[0].st[1] = 0; + verts[0].modulate[0] = 255; + verts[0].modulate[1] = 255; + verts[0].modulate[2] = 255; + verts[0].modulate[3] = 255; + + VectorCopy( org, verts[1].xyz ); + verts[1].xyz[0] -= p->height; + verts[1].xyz[1] += p->width; + verts[1].st[0] = 0; + verts[1].st[1] = 1; + verts[1].modulate[0] = 255; + verts[1].modulate[1] = 255; + verts[1].modulate[2] = 255; + verts[1].modulate[3] = 255; + + VectorCopy( org, verts[2].xyz ); + verts[2].xyz[0] += p->height; + verts[2].xyz[1] += p->width; + verts[2].st[0] = 1; + verts[2].st[1] = 1; + verts[2].modulate[0] = 255; + verts[2].modulate[1] = 255; + verts[2].modulate[2] = 255; + verts[2].modulate[3] = 255; + + VectorCopy( org, verts[3].xyz ); + verts[3].xyz[0] += p->height; + verts[3].xyz[1] -= p->width; + verts[3].st[0] = 1; + verts[3].st[1] = 0; + verts[3].modulate[0] = 255; + verts[3].modulate[1] = 255; + verts[3].modulate[2] = 255; + verts[3].modulate[3] = 255; + + } + // Ridah + else if ( p->type == P_ANIM ) { + vec3_t rr, ru; + vec3_t rotate_ang; + int i, j; + + time = cg.time - p->time; + time2 = p->endtime - p->time; + ratio = time / time2; + if ( ratio >= 1.0 ) { + ratio = 0.9999; + } + + width = p->width + ( ratio * ( p->endwidth - p->width ) ); + height = p->height + ( ratio * ( p->endheight - p->height ) ); + + // if we are "inside" this sprite, don't draw + if ( Distance( cg.snap->ps.origin, org ) < width / 1.5 ) { + return; + } + + i = p->shaderAnim; + j = (int)floor( ratio * shaderAnimCounts[p->shaderAnim] ); + p->pshader = shaderAnims[i][j]; + + if ( p->roll ) { + vectoangles( cg.refdef.viewaxis[0], rotate_ang ); + rotate_ang[ROLL] += p->roll; + AngleVectors( rotate_ang, NULL, rr, ru ); + } + + if ( p->roll ) { + VectorMA( org, -height, ru, point ); + VectorMA( point, -width, rr, point ); + } else { + VectorMA( org, -height, vup, point ); + VectorMA( point, -width, vright, point ); + } + VectorCopy( point, verts[0].xyz ); + verts[0].st[0] = 0; + verts[0].st[1] = 0; + verts[0].modulate[0] = 255; + verts[0].modulate[1] = 255; + verts[0].modulate[2] = 255; + verts[0].modulate[3] = 255; + + if ( p->roll ) { + VectorMA( point, 2 * height, ru, point ); + } else { + VectorMA( point, 2 * height, vup, point ); + } + VectorCopy( point, verts[1].xyz ); + verts[1].st[0] = 0; + verts[1].st[1] = 1; + verts[1].modulate[0] = 255; + verts[1].modulate[1] = 255; + verts[1].modulate[2] = 255; + verts[1].modulate[3] = 255; + + if ( p->roll ) { + VectorMA( point, 2 * width, rr, point ); + } else { + VectorMA( point, 2 * width, vright, point ); + } + VectorCopy( point, verts[2].xyz ); + verts[2].st[0] = 1; + verts[2].st[1] = 1; + verts[2].modulate[0] = 255; + verts[2].modulate[1] = 255; + verts[2].modulate[2] = 255; + verts[2].modulate[3] = 255; + + if ( p->roll ) { + VectorMA( point, -2 * height, ru, point ); + } else { + VectorMA( point, -2 * height, vup, point ); + } + VectorCopy( point, verts[3].xyz ); + verts[3].st[0] = 1; + verts[3].st[1] = 0; + verts[3].modulate[0] = 255; + verts[3].modulate[1] = 255; + verts[3].modulate[2] = 255; + verts[3].modulate[3] = 255; + } + // done. + + if ( !cg_wolfparticles.integer ) { + return; + } + + if ( !p->pshader ) { +// (SA) temp commented out for DM again. FIXME: TODO: this needs to be addressed +// CG_Printf ("CG_AddParticleToScene type %d p->pshader == ZERO\n", p->type); + return; + } + + if ( p->type == P_WEATHER || p->type == P_WEATHER_TURBULENT || p->type == P_WEATHER_FLURRY ) { + trap_R_AddPolyToScene( p->pshader, 3, TRIverts ); + } else { + trap_R_AddPolyToScene( p->pshader, 4, verts ); + } + +} + +// Ridah, made this static so it doesn't interfere with other files +static float roll = 0.0; + +/* +=============== +CG_AddParticles +=============== +*/ +void CG_AddParticles( void ) { + cparticle_t *p, *next; + float alpha; + float time, time2; + vec3_t org; + int color; + cparticle_t *active, *tail; + int type; + vec3_t rotate_ang; + + if ( !initparticles ) { + CG_ClearParticles(); + } + + VectorCopy( cg.refdef.viewaxis[0], vforward ); + VectorCopy( cg.refdef.viewaxis[1], vright ); + VectorCopy( cg.refdef.viewaxis[2], vup ); + + vectoangles( cg.refdef.viewaxis[0], rotate_ang ); + roll += ( ( cg.time - oldtime ) * 0.1 ) ; + rotate_ang[ROLL] += ( roll * 0.9 ); + AngleVectors( rotate_ang, rforward, rright, rup ); + + oldtime = cg.time; + + active = NULL; + tail = NULL; + + for ( p = active_particles ; p ; p = next ) + { + + next = p->next; + + time = ( cg.time - p->time ) * 0.001; + + alpha = p->alpha + time * p->alphavel; + if ( alpha <= 0 ) { // faded out + p->next = free_particles; + free_particles = p; + p->type = 0; + p->color = 0; + p->alpha = 0; + continue; + } + + if ( p->type == P_SMOKE || p->type == P_ANIM || p->type == P_BLEED || p->type == P_SMOKE_IMPACT ) { + if ( cg.time > p->endtime ) { + p->next = free_particles; + free_particles = p; + p->type = 0; + p->color = 0; + p->alpha = 0; + + continue; + } + + } + + if ( p->type == P_WEATHER_FLURRY ) { + if ( cg.time > p->endtime ) { + p->next = free_particles; + free_particles = p; + p->type = 0; + p->color = 0; + p->alpha = 0; + + continue; + } + } + + + if ( p->type == P_FLAT_SCALEUP_FADE ) { + if ( cg.time > p->endtime ) { + p->next = free_particles; + free_particles = p; + p->type = 0; + p->color = 0; + p->alpha = 0; + continue; + } + + } + + if ( ( p->type == P_BAT || p->type == P_SPRITE ) && p->endtime < 0 ) { + // temporary sprite + CG_AddParticleToScene( p, p->org, alpha ); + p->next = free_particles; + free_particles = p; + p->type = 0; + p->color = 0; + p->alpha = 0; + continue; + } + + p->next = NULL; + if ( !tail ) { + active = tail = p; + } else + { + tail->next = p; + tail = p; + } + + if ( alpha > 1.0 ) { + alpha = 1; + } + + color = p->color; + + time2 = time * time; + + org[0] = p->org[0] + p->vel[0] * time + p->accel[0] * time2; + org[1] = p->org[1] + p->vel[1] * time + p->accel[1] * time2; + org[2] = p->org[2] + p->vel[2] * time + p->accel[2] * time2; + + type = p->type; + + CG_AddParticleToScene( p, org, alpha ); + } + + active_particles = active; +} + +/* +====================== +CG_AddParticles +====================== +*/ +void CG_ParticleSnowFlurry( qhandle_t pshader, centity_t *cent ) { + cparticle_t *p; + qboolean turb = qtrue; + + if ( !pshader ) { + CG_Printf( "CG_ParticleSnowFlurry pshader == ZERO!\n" ); + } + + if ( !free_particles ) { + return; + } + + if ( !CG_ParticleLODCheck() ) { + return; + } + + p = free_particles; + free_particles = p->next; + p->next = active_particles; + active_particles = p; + p->time = cg.time; + p->color = 0; + p->alpha = 0.90; + p->alphavel = 0; + + p->start = cent->currentState.origin2[0]; + p->end = cent->currentState.origin2[1]; + + p->endtime = cg.time + cent->currentState.time; + p->startfade = cg.time + cent->currentState.time2; + + p->pshader = pshader; + + if ( rand() % 100 > 90 ) { + p->height = 32; + p->width = 32; + p->alpha = 0.10; + } else + { + p->height = 1; + p->width = 1; + } + + p->vel[2] = -20; + + p->type = P_WEATHER_FLURRY; + + if ( turb ) { + p->vel[2] = -10; + } + + VectorCopy( cent->currentState.origin, p->org ); + + p->org[0] = p->org[0]; + p->org[1] = p->org[1]; + p->org[2] = p->org[2]; + + p->vel[0] = p->vel[1] = 0; + + p->accel[0] = p->accel[1] = p->accel[2] = 0; + + p->vel[0] += cent->currentState.angles[0] * 32 + ( crandom() * 16 ); + p->vel[1] += cent->currentState.angles[1] * 32 + ( crandom() * 16 ); + p->vel[2] += cent->currentState.angles[2]; + + if ( turb ) { + p->accel[0] = crandom() * 16; + p->accel[1] = crandom() * 16; + } + +} + +void CG_ParticleSnow( qhandle_t pshader, vec3_t origin, vec3_t origin2, int turb, float range, int snum ) { + cparticle_t *p; + + if ( !pshader ) { + CG_Printf( "CG_ParticleSnow pshader == ZERO!\n" ); + } + + if ( !free_particles ) { + return; + } + + if ( !CG_ParticleLODCheck() ) { + return; + } + + p = free_particles; + free_particles = p->next; + p->next = active_particles; + active_particles = p; + p->time = cg.time; + p->color = 0; + p->alpha = 0.40; + p->alphavel = 0; + p->start = origin[2]; + p->end = origin2[2]; + p->pshader = pshader; + p->height = 1; + p->width = 1; + + p->vel[2] = -50; + + if ( turb ) { + p->type = P_WEATHER_TURBULENT; + p->vel[2] = -50 * 1.3; + } else + { + p->type = P_WEATHER; + } + + VectorCopy( origin, p->org ); + + p->org[0] = p->org[0] + ( crandom() * range ); + p->org[1] = p->org[1] + ( crandom() * range ); + p->org[2] = p->org[2] + ( crandom() * ( p->start - p->end ) ); + + p->vel[0] = p->vel[1] = 0; + + p->accel[0] = p->accel[1] = p->accel[2] = 0; + + if ( turb ) { + p->vel[0] = crandom() * 16; + p->vel[1] = crandom() * 16; + } + + // Rafael snow pvs check + p->snum = snum; + p->link = qtrue; + +} + +void CG_ParticleBubble( qhandle_t pshader, vec3_t origin, vec3_t origin2, int turb, float range, int snum ) { + cparticle_t *p; + float randsize; + + if ( !pshader ) { + CG_Printf( "CG_ParticleSnow pshader == ZERO!\n" ); + } + + if ( !free_particles ) { + return; + } + + if ( !CG_ParticleLODCheck() ) { + return; + } + + p = free_particles; + free_particles = p->next; + p->next = active_particles; + active_particles = p; + p->time = cg.time; + p->color = 0; + p->alpha = 0.40; + p->alphavel = 0; + p->start = origin[2]; + p->end = origin2[2]; + p->pshader = pshader; + + randsize = 1 + ( crandom() * 0.5 ); + + p->height = randsize; + p->width = randsize; + + p->vel[2] = 50 + ( crandom() * 10 ); + + if ( turb ) { + p->type = P_BUBBLE_TURBULENT; + p->vel[2] = 50 * 1.3; + } else + { + p->type = P_BUBBLE; + } + + VectorCopy( origin, p->org ); + + p->org[0] = p->org[0] + ( crandom() * range ); + p->org[1] = p->org[1] + ( crandom() * range ); + p->org[2] = p->org[2] + ( crandom() * ( p->start - p->end ) ); + + p->vel[0] = p->vel[1] = 0; + + p->accel[0] = p->accel[1] = p->accel[2] = 0; + + if ( turb ) { + p->vel[0] = crandom() * 4; + p->vel[1] = crandom() * 4; + } + + // Rafael snow pvs check + p->snum = snum; + p->link = qtrue; + +} + +void CG_ParticleSmoke( qhandle_t pshader, centity_t *cent ) { + + // using cent->density = enttime + // cent->frame = startfade + cparticle_t *p; + vec3_t dir; + + if ( !pshader ) { + CG_Printf( "CG_ParticleSmoke == ZERO!\n" ); + } + + if ( !free_particles ) { + return; + } + + if ( !CG_ParticleLODCheck() ) { + return; + } + + p = free_particles; + free_particles = p->next; + p->next = active_particles; + active_particles = p; + p->time = cg.time; + + p->endtime = cg.time + cent->currentState.time; + p->startfade = cg.time + cent->currentState.time2; + + p->color = 0; + p->alpha = 1.0; + p->alphavel = 0; + p->start = cent->currentState.origin[2]; + p->end = cent->currentState.origin2[2]; + p->pshader = pshader; + if ( cent->currentState.density == 1 ) { + p->rotate = qfalse; + p->height = 8; + p->width = 8; + p->endheight = 32; + p->endwidth = 32; + } else if ( cent->currentState.density == 2 ) { + p->rotate = qtrue; + p->height = 4; + p->width = 4; + p->endheight = 8; + p->endwidth = 8; + } else if ( cent->currentState.density == 3 ) { + p->rotate = qfalse; + { + float scale; + + scale = 16 + ( crandom() * 8 ); + p->height = 24 + scale; + p->width = 24 + scale; + p->endheight = 64 + scale; + p->endwidth = 64 + scale; + } + } else if ( cent->currentState.density == 4 ) { // white smoke + p->rotate = qtrue; + p->height = cent->currentState.angles2[0]; + p->width = cent->currentState.angles2[0]; + p->endheight = cent->currentState.angles2[1]; + p->endwidth = cent->currentState.angles2[1]; + p->color = GREY75; + } else if ( cent->currentState.density == 5 ) { // mustard gas + p->rotate = qtrue; + p->height = cent->currentState.angles2[0]; + p->width = cent->currentState.angles2[0]; + p->endheight = cent->currentState.angles2[1]; + p->endwidth = cent->currentState.angles2[1]; + p->color = MUSTARD; + p->alpha = 0.75; + } else // black smoke + { + p->rotate = qtrue; + p->height = cent->currentState.angles2[0]; + p->width = cent->currentState.angles2[0]; + p->endheight = cent->currentState.angles2[1]; + p->endwidth = cent->currentState.angles2[1]; + + { + int rval; + rval = rand() % 6; + if ( rval == 1 ) { + p->pshader = cgs.media.smokePuffShaderb1; + } else if ( rval == 2 ) { + p->pshader = cgs.media.smokePuffShaderb2; + } else if ( rval == 3 ) { + p->pshader = cgs.media.smokePuffShaderb3; + } else if ( rval == 4 ) { + p->pshader = cgs.media.smokePuffShaderb4; + } else { + p->pshader = cgs.media.smokePuffShaderb5; + } + } + } + + + p->type = P_SMOKE; + + VectorCopy( cent->currentState.origin, p->org ); + + p->vel[0] = p->vel[1] = 0; + p->accel[0] = p->accel[1] = p->accel[2] = 0; + + if ( cent->currentState.density == 1 ) { + p->vel[2] = 5; + } else if ( cent->currentState.density == 2 ) { + p->vel[2] = 5; + } else if ( cent->currentState.density == 3 ) { // cannon + VectorCopy( cent->currentState.origin2, dir ); + p->vel[0] = dir[0] * 128 + ( crandom() * 64 ); + p->vel[1] = dir[1] * 128 + ( crandom() * 64 ); + p->vel[2] = 15 + ( crandom() * 16 ); + } else if ( cent->currentState.density == 5 ) { // gas or cover smoke + VectorCopy( cent->currentState.origin2, dir ); + p->vel[0] = dir[0] * 32 + ( crandom() * 16 ); + p->vel[1] = dir[1] * 32 + ( crandom() * 16 ); + p->vel[2] = 4 + ( crandom() * 2 ); + } else // smoke + { + VectorCopy( cent->currentState.origin2, dir ); + p->vel[0] = dir[0] + ( crandom() * p->height ); + p->vel[1] = dir[1] + ( crandom() * p->height ); + p->vel[2] = cent->currentState.angles2[2]; + } + + if ( cent->currentState.frame == 1 ) { // reverse gravity + p->vel[2] *= -1; + } + +// p->roll = 8 + (crandom() * 4); + p->roll = rand() % ( 2 * 8 ); + p->roll -= 8; +} + + +void CG_ParticleBulletDebris( vec3_t org, vec3_t vel, int duration ) { + + cparticle_t *p; + + if ( !free_particles ) { + return; + } + + if ( !CG_ParticleLODCheck() ) { + return; + } + + p = free_particles; + free_particles = p->next; + p->next = active_particles; + active_particles = p; + p->time = cg.time; + + p->endtime = cg.time + duration; + p->startfade = cg.time + duration / 2; + + p->color = EMISIVEFADE; + p->alpha = 1.0; + p->alphavel = 0; + + p->height = 0.5; + p->width = 0.5; + p->endheight = 0.5; + p->endwidth = 0.5; + + p->pshader = cgs.media.tracerShader; + + p->type = P_SMOKE; + + VectorCopy( org, p->org ); + + p->vel[0] = vel[0]; + p->vel[1] = vel[1]; + p->vel[2] = vel[2]; + p->accel[0] = p->accel[1] = p->accel[2] = 0; + + p->accel[2] = -60; + p->vel[2] += -20; + +} + +// DHM - Nerve :: bullets hitting dirt + +void CG_ParticleDirtBulletDebris( vec3_t org, vec3_t vel, int duration ) { + int r = rand() % 3; + cparticle_t *p; + + if ( !free_particles ) { + return; + } + p = free_particles; + free_particles = p->next; + p->next = active_particles; + active_particles = p; + p->time = cg.time; + + p->endtime = cg.time + duration; + p->startfade = cg.time + duration / 2; + + p->color = EMISIVEFADE; + p->alpha = 1.0; + p->alphavel = 0; + + p->height = 1.2; + p->width = 1.2; + p->endheight = 4.5; + p->endwidth = 4.5; + + if ( r == 0 ) { + p->pshader = cgs.media.dirtParticle1Shader; + } else if ( r == 1 ) { + p->pshader = cgs.media.dirtParticle2Shader; + } else { + p->pshader = cgs.media.dirtParticle3Shader; + } + + p->type = P_SMOKE; + + VectorCopy( org, p->org ); + + p->vel[0] = vel[0]; + p->vel[1] = vel[1]; + p->vel[2] = vel[2]; + p->accel[0] = p->accel[1] = p->accel[2] = 0; + + p->accel[2] = -330; + p->vel[2] += -20; +} + +// NERVE - SMF :: the core of the dirt explosion +void CG_ParticleDirtBulletDebris_Core( vec3_t org, vec3_t vel, int duration, + float width, float height, float alpha, char *shadername ) { // JPW NERVE +// int r = rand(); // TTimo: unused + cparticle_t *p; + + if ( !free_particles ) { + return; + } + p = free_particles; + free_particles = p->next; + p->next = active_particles; + active_particles = p; + p->time = cg.time; + + p->endtime = cg.time + duration; + p->startfade = cg.time + duration / 2; + + p->color = EMISIVEFADE; + p->alpha = alpha; + p->alphavel = 0; + + p->height = width; // JPW NERVE was 512/5.f; + p->width = height; // JPW NERVE was 128/5.f; + p->endheight = p->height; + p->endwidth = p->width; + + p->rotate = 0; + + p->pshader = trap_R_RegisterShader( shadername ); // JPW NERVE was "dirt_splash" + + p->type = P_SMOKE; + + VectorCopy( org, p->org ); + VectorCopy( vel, p->vel ); + +// p->vel[0] = vel[0]; +// p->vel[1] = vel[1]; +// p->vel[2] = vel[2]; + p->accel[0] = p->accel[1] = p->accel[2] = 0; + + p->accel[2] = -330; +// p->vel[2] += -20; +} + +/* +====================== +CG_ParticleExplosion +====================== +*/ + +void CG_ParticleExplosion( char *animStr, vec3_t origin, vec3_t vel, int duration, int sizeStart, int sizeEnd ) { + cparticle_t *p; + int anim; + + if ( animStr < (char *)10 ) { + CG_Error( "CG_ParticleExplosion: animStr is probably an index rather than a string" ); + } + + if ( !CG_ParticleLODCheck() ) { + return; + } + + // find the animation string + for ( anim = 0; shaderAnimNames[anim]; anim++ ) { + if ( !Q_strcasecmp( animStr, shaderAnimNames[anim] ) ) { + break; + } + } + if ( !shaderAnimNames[anim] ) { + CG_Error( "CG_ParticleExplosion: unknown animation string: %s\n", animStr ); + return; + } + + if ( !free_particles ) { + return; + } + p = free_particles; + free_particles = p->next; + p->next = active_particles; + active_particles = p; + p->time = cg.time; + p->alpha = 1.0; + p->alphavel = 0; + + if ( duration < 0 ) { + duration *= -1; + p->roll = 0; + } else { + p->roll = crandom() * 179; + } + + p->shaderAnim = anim; + + p->width = sizeStart; + p->height = sizeStart * shaderAnimSTRatio[anim]; // for sprites that are stretch in either direction + + p->endheight = sizeEnd; + p->endwidth = sizeEnd * shaderAnimSTRatio[anim]; + + p->endtime = cg.time + duration; + + p->type = P_ANIM; + + VectorCopy( origin, p->org ); + VectorCopy( vel, p->vel ); + VectorClear( p->accel ); + +} + +// Rafael Shrapnel +void CG_AddParticleShrapnel( localEntity_t *le ) { + return; +} +// done. + +int CG_NewParticleArea( int num ) { + // const char *str; + char *str; + char *token; + int type; + vec3_t origin, origin2; + int i; + float range = 0; + int turb; + int numparticles; + int snum; + + str = (char *) CG_ConfigString( num ); + if ( !str[0] ) { + return ( 0 ); + } + + // returns type 128 64 or 32 + token = COM_Parse( &str ); + type = atoi( token ); + + if ( type == 1 ) { + range = 128; + } else if ( type == 2 ) { + range = 64; + } else if ( type == 3 ) { + range = 32; + } else if ( type == 0 ) { + range = 256; + } else if ( type == 4 ) { + range = 8; + } else if ( type == 5 ) { + range = 16; + } else if ( type == 6 ) { + range = 32; + } else if ( type == 7 ) { + range = 64; + } + + + for ( i = 0; i < 3; i++ ) + { + token = COM_Parse( &str ); + origin[i] = atof( token ); + } + + for ( i = 0; i < 3; i++ ) + { + token = COM_Parse( &str ); + origin2[i] = atof( token ); + } + + token = COM_Parse( &str ); + numparticles = atoi( token ); + + token = COM_Parse( &str ); + turb = atoi( token ); + + token = COM_Parse( &str ); + snum = atoi( token ); + + for ( i = 0; i < numparticles; i++ ) + { + if ( type >= 4 ) { + CG_ParticleBubble( cgs.media.waterBubbleShader, origin, origin2, turb, range, snum ); + } else { + CG_ParticleSnow( cgs.media.snowShader, origin, origin2, turb, range, snum ); + } + } + + return ( 1 ); +} + +void CG_SnowLink( centity_t *cent, qboolean particleOn ) { + cparticle_t *p, *next; + int id; + + id = cent->currentState.frame; + + for ( p = active_particles ; p ; p = next ) + { + next = p->next; + + if ( p->type == P_WEATHER || p->type == P_WEATHER_TURBULENT ) { + if ( p->snum == id ) { + if ( particleOn ) { + p->link = qtrue; + } else { + p->link = qfalse; + } + } + } + + } +} + +void CG_ParticleBat( centity_t *cent ) { + cparticle_t *p; + vec3_t origin; + + if ( !free_particles ) { + return; + } + + p = free_particles; + free_particles = p->next; + p->next = active_particles; + active_particles = p; + p->time = cg.time; + p->color = 0; + p->alpha = 1.0; + p->alphavel = 0; + p->height = 4; + p->width = 4; + + VectorCopy( cent->lerpOrigin, origin ); + VectorCopy( origin, p->org ); + VectorClear( p->vel ); + + p->accel[0] = p->accel[1] = p->accel[2] = 0; + + p->snum = cent->currentState.frame; + + p->type = P_BAT; + p->endtime = -1; // last one frame only +} + + +void CG_ParticleBats( qhandle_t pshader, centity_t *cent ) { + cparticle_t *p; + vec3_t origin; + + if ( !free_particles ) { + return; + } + p = free_particles; + free_particles = p->next; + p->next = active_particles; + active_particles = p; + p->time = cg.time; + p->color = 0; + p->alpha = 0.40; + p->alphavel = 0; + p->pshader = pshader; + p->height = 4; + p->width = 4; + + VectorCopy( cent->currentState.origin, origin ); + VectorCopy( origin, p->org ); + + p->org[0] = p->org[0] + ( crandom() * 32 ); + p->org[1] = p->org[1] + ( crandom() * 32 ); + p->org[2] = p->org[2] + ( crandom() * 32 ); + + p->vel[0] = cent->currentState.angles[0] * cent->currentState.time; + p->vel[1] = cent->currentState.angles[1] * cent->currentState.time; + p->vel[2] = cent->currentState.angles[2] * cent->currentState.time; + + p->accel[0] = p->accel[1] = p->accel[2] = 0; + + p->snum = cent->currentState.frame; + + p->type = P_BAT; +} + +void CG_BatsUpdatePosition( centity_t *cent ) { + cparticle_t *p, *next; + int id; + float time; + + id = cent->currentState.frame; + + for ( p = active_particles ; p ; p = next ) + { + next = p->next; + + if ( p->type == P_BAT ) { + if ( p->snum == id ) { + time = ( cg.time - p->time ) * 0.001; + + p->org[0] = p->org[0] + p->vel[0] * time; + p->org[1] = p->org[1] + p->vel[1] * time; + p->org[2] = p->org[2] + p->vel[2] * time; + + p->time = cg.time; + + p->vel[0] = cent->currentState.angles[0] * cent->currentState.time; + p->vel[1] = cent->currentState.angles[1] * cent->currentState.time; + p->vel[2] = cent->currentState.angles[2] * cent->currentState.time; + + } + } + + } +} + + +void CG_ParticleImpactSmokePuffExtended( qhandle_t pshader, vec3_t origin, vec3_t dir, int radius, int lifetime, int vel, int acc, int maxroll, float alpha ) { + cparticle_t *p; + + if ( !pshader ) { + CG_Printf( "CG_ParticleImpactSmokePuff pshader == ZERO!\n" ); + } + + if ( !free_particles ) { + return; + } + + if ( !CG_ParticleLODCheck() ) { + return; + } + + p = free_particles; + free_particles = p->next; + p->next = active_particles; + active_particles = p; + p->time = cg.time; + p->alpha = alpha; + p->alphavel = 0; + + // (SA) roll either direction + p->roll = rand() % ( 2 * maxroll ); +// p->roll = crandom()*(float)(maxroll*2); + p->roll -= maxroll; + + p->pshader = pshader; + + p->endtime = cg.time + lifetime; + p->startfade = cg.time + 100; + + p->width = rand() % 4 + radius; //----(SA) + p->height = rand() % 4 + radius; //----(SA) + + p->endheight = p->height * 2; + p->endwidth = p->width * 2; + + p->type = P_SMOKE_IMPACT; + + VectorCopy( origin, p->org ); + VectorScale( dir, vel, p->vel ); + VectorScale( dir, acc, p->accel ); +// VectorSet(p->vel, 0, 0, vel); +// VectorSet(p->accel, 0, 0, acc); + + p->rotate = qtrue; +} + +void CG_ParticleImpactSmokePuff( qhandle_t pshader, vec3_t origin ) { + CG_ParticleImpactSmokePuffExtended( pshader, origin, tv( 0,0,1 ), 8, 500, 20, 20, 30, 0.25f ); +} + + +void CG_Particle_Bleed( qhandle_t pshader, vec3_t start, vec3_t dir, int fleshEntityNum, int duration ) { + cparticle_t *p; + + if ( !pshader ) { + CG_Printf( "CG_Particle_Bleed pshader == ZERO!\n" ); + } + + if ( !CG_ParticleLODCheck() ) { + return; + } + + if ( !free_particles ) { + return; + } + p = free_particles; + free_particles = p->next; + p->next = active_particles; + active_particles = p; + p->time = cg.time; + p->alpha = 1.0; + p->alphavel = 0; + p->roll = 0; + + p->pshader = pshader; + + p->endtime = cg.time + duration; + + if ( fleshEntityNum ) { + p->startfade = cg.time; + } else { + p->startfade = cg.time + 100; + } + + p->width = 4; + p->height = 4; + + p->endheight = 4 + rand() % 3; + p->endwidth = p->endheight; + + p->type = P_SMOKE; + + VectorCopy( start, p->org ); + p->vel[0] = 0; + p->vel[1] = 0; + p->vel[2] = -20; + VectorClear( p->accel ); + + p->rotate = qfalse; + + p->roll = rand() % 179; + + if ( fleshEntityNum ) { + p->color = MUSTARD; + } else { + p->color = BLOODRED; + } + p->alpha = 0.75; + +} + +//void CG_Particle_OilParticle (qhandle_t pshader, centity_t *cent) +void CG_Particle_OilParticle( qhandle_t pshader, vec3_t origin, vec3_t dir, int ptime, int snum ) { // snum is parent ent number? + cparticle_t *p; + + int time; + int time2; + float ratio; + +// float duration = 1500; + float duration = 2000; + + time = cg.time; + time2 = cg.time + ptime; + + ratio = (float)1 - ( (float)time / (float)time2 ); + + if ( !pshader ) { + CG_Printf( "CG_Particle_OilParticle == ZERO!\n" ); + } + + if ( !free_particles ) { + return; + } + + if ( !CG_ParticleLODCheck() ) { + return; + } + + p = free_particles; + free_particles = p->next; + p->next = active_particles; + active_particles = p; + p->time = cg.time; + p->alphavel = 0; + p->roll = 0; + + p->pshader = pshader; + + p->endtime = cg.time + duration; + + p->startfade = p->endtime; + + p->width = 2; + p->height = 2; + + p->endwidth = 1; + p->endheight = 1; + + p->type = P_SMOKE; + + VectorCopy( origin, p->org ); + + p->vel[0] = ( dir[0] * ( 16 * ratio ) ); + p->vel[1] = ( dir[1] * ( 16 * ratio ) ); + p->vel[2] = ( dir[2] * ( 16 * ratio ) ); +// p->vel[2] = (dir[2]); + + p->snum = snum; + + VectorClear( p->accel ); + + p->accel[2] = -20; + + p->rotate = qfalse; + + p->roll = rand() % 179; + + p->alpha = 0.5; + + p->color = BLOODRED; + +} + + +void CG_Particle_OilSlick( qhandle_t pshader, centity_t *cent ) { + cparticle_t *p; + + if ( !pshader ) { + CG_Printf( "CG_Particle_OilSlick == ZERO!\n" ); + } + + if ( !free_particles ) { + return; + } + + if ( !CG_ParticleLODCheck() ) { + return; + } + + p = free_particles; + free_particles = p->next; + p->next = active_particles; + active_particles = p; + p->time = cg.time; + + if ( cent->currentState.angles2[2] ) { + p->endtime = cg.time + cent->currentState.angles2[2]; + } else { + p->endtime = cg.time + 60000; + } + + p->startfade = p->endtime; + + p->alpha = 1.0; + p->alphavel = 0; + p->roll = 0; + + p->pshader = pshader; + + if ( cent->currentState.angles2[0] || cent->currentState.angles2[1] ) { + p->width = cent->currentState.angles2[0]; + p->height = cent->currentState.angles2[0]; + + p->endheight = cent->currentState.angles2[1]; + p->endwidth = cent->currentState.angles2[1]; + } else + { + p->width = 8; + p->height = 8; + + p->endheight = 16; + p->endwidth = 16; + } + + p->type = P_FLAT_SCALEUP; + + p->snum = cent->currentState.density; + + VectorCopy( cent->currentState.origin, p->org ); + + p->org[2] += 0.55 + ( crandom() * 0.5 ); + + p->vel[0] = 0; + p->vel[1] = 0; + p->vel[2] = 0; + VectorClear( p->accel ); + + p->rotate = qfalse; + + p->roll = rand() % 179; + + p->alpha = 0.75; + +} + +void CG_OilSlickRemove( centity_t *cent ) { + cparticle_t *p, *next; + int id; + + id = cent->currentState.density; + + if ( !id ) { + CG_Printf( "CG_OilSlickRevove NULL id\n" ); + } + + for ( p = active_particles ; p ; p = next ) + { + next = p->next; + + if ( p->type == P_FLAT_SCALEUP ) { + if ( p->snum == id ) { + p->endtime = cg.time + 100; + p->startfade = p->endtime; + p->type = P_FLAT_SCALEUP_FADE; + + } + } + + } +} + +qboolean ValidBloodPool( vec3_t start ) { +#define EXTRUDE_DIST 0.5 + + vec3_t angles; + vec3_t right, up; + vec3_t this_pos, x_pos, center_pos, end_pos; + float x, y; + float fwidth, fheight; + trace_t trace; + vec3_t normal; + + fwidth = 16; + fheight = 16; + + VectorSet( normal, 0, 0, 1 ); + + vectoangles( normal, angles ); + AngleVectors( angles, NULL, right, up ); + + VectorMA( start, EXTRUDE_DIST, normal, center_pos ); + + for ( x = -fwidth / 2; x < fwidth; x += fwidth ) + { + VectorMA( center_pos, x, right, x_pos ); + + for ( y = -fheight / 2; y < fheight; y += fheight ) + { + VectorMA( x_pos, y, up, this_pos ); + VectorMA( this_pos, -EXTRUDE_DIST * 2, normal, end_pos ); + + CG_Trace( &trace, this_pos, NULL, NULL, end_pos, -1, CONTENTS_SOLID ); + + + if ( trace.entityNum < ( MAX_ENTITIES - 1 ) ) { // may only land on world + return qfalse; + } + + if ( !( !trace.startsolid && trace.fraction < 1 ) ) { + return qfalse; + } + + } + } + + return qtrue; +} + +void CG_BloodPool( localEntity_t *le, qhandle_t pshader, trace_t *tr ) { + cparticle_t *p; + qboolean legit; + vec3_t start; + float rndSize; + + if ( !pshader ) { + CG_Printf( "CG_BloodPool pshader == ZERO!\n" ); + } + + if ( !free_particles ) { + return; + } + + VectorCopy( tr->endpos, start ); + legit = ValidBloodPool( start ); + + if ( !legit ) { + return; + } + + p = free_particles; + free_particles = p->next; + p->next = active_particles; + active_particles = p; + p->time = cg.time; + + p->endtime = cg.time + 3000; + p->startfade = p->endtime; + + p->alpha = 1.0; + p->alphavel = 0; + p->roll = 0; + + p->pshader = pshader; + + rndSize = 0.4 + random() * 0.6; + + p->width = 8 * rndSize; + p->height = 8 * rndSize; + + p->endheight = 16 * rndSize; + p->endwidth = 16 * rndSize; + + p->type = P_FLAT_SCALEUP; + + VectorCopy( start, p->org ); + + p->vel[0] = 0; + p->vel[1] = 0; + p->vel[2] = 0; + VectorClear( p->accel ); + + p->rotate = qfalse; + + p->roll = rand() % 179; + + p->alpha = 0.75; + + p->color = BLOODRED; +} + +#define NORMALSIZE 16 +#define LARGESIZE 32 + +void CG_ParticleBloodCloud( centity_t *cent, vec3_t origin, vec3_t dir ) { + float length; + float dist; + float crittersize; + vec3_t angles, forward; + vec3_t point; + cparticle_t *p; + int i; + + dist = 0; + + length = VectorLength( dir ); + vectoangles( dir, angles ); + AngleVectors( angles, forward, NULL, NULL ); + + if ( cent->currentState.density == 0 ) { // normal ai size + crittersize = NORMALSIZE; + } else { + crittersize = LARGESIZE; + } + + if ( length ) { + dist = length / crittersize; + } + + if ( dist < 1 ) { + dist = 1; + } + + VectorCopy( origin, point ); + + for ( i = 0; i < dist; i++ ) + { + VectorMA( point, crittersize, forward, point ); + + if ( !free_particles ) { + return; + } + + p = free_particles; + free_particles = p->next; + p->next = active_particles; + active_particles = p; + + p->time = cg.time; + p->alpha = 1.0; + p->alphavel = 0; + p->roll = 0; + + p->pshader = cgs.media.smokePuffShader; + + p->endtime = cg.time + 450 + ( crandom() * 100 ); + + if ( cent->currentState.aiChar == AICHAR_HELGA || cent->currentState.aiChar == AICHAR_HEINRICH ) { + // stick around longer + p->endtime += 3000; + } + + p->startfade = cg.time; + + if ( cent->currentState.density == 0 ) { // normal ai size + p->width = NORMALSIZE; + p->height = NORMALSIZE; + + p->endheight = NORMALSIZE; + p->endwidth = NORMALSIZE; + } else // large frame + { + p->width = LARGESIZE; + p->height = LARGESIZE; + + p->endheight = LARGESIZE; + p->endwidth = LARGESIZE; + } + + p->type = P_SMOKE; + + VectorCopy( origin, p->org ); + + p->vel[0] = 0; + p->vel[1] = 0; + p->vel[2] = -1; + + VectorClear( p->accel ); + + p->rotate = qfalse; + + p->roll = rand() % 179; + + if ( cent->currentState.aiChar == AICHAR_ZOMBIE ) { + p->color = MUSTARD; + } else { + p->color = BLOODRED; + } + + p->alpha = 0.75; + + } + + +} + +void CG_ParticleBloodCloudZombie( centity_t *cent, vec3_t origin, vec3_t dir ) { + float length; + float dist; + float crittersize; + vec3_t angles, forward; + vec3_t point; + cparticle_t *p; + int i; + + dist = 0; + + length = VectorLength( dir ); + vectoangles( dir, angles ); + AngleVectors( angles, forward, NULL, NULL ); + + if ( cent->currentState.density == 0 ) { // normal ai size + crittersize = NORMALSIZE / 4; + } else { + crittersize = LARGESIZE / 3; + } + + if ( length ) { + dist = length / crittersize; + } + + if ( dist < 1 ) { + dist = 1; + } + + VectorCopy( origin, point ); + + for ( i = 0; i < dist; i++ ) + { + VectorMA( point, crittersize, forward, point ); + + if ( !free_particles ) { + return; + } + + p = free_particles; + free_particles = p->next; + p->next = active_particles; + active_particles = p; + + p->time = cg.time; + p->alpha = 0.2; + p->alphavel = 0; + p->roll = 0; + + p->pshader = cgs.media.bloodCloudShader; + + // RF, stay around for long enough to expand and dissipate naturally + if ( length ) { + p->endtime = cg.time + 3500 + ( crandom() * 2000 ); + } else { + p->endtime = cg.time + 750 + ( crandom() * 500 ); + } + + p->startfade = cg.time; + + if ( cent->currentState.density == 0 ) { // normal ai size + p->width = NORMALSIZE; + p->height = NORMALSIZE; + + // RF, expand while falling + p->endheight = NORMALSIZE * 4.0; + p->endwidth = NORMALSIZE * 4.0; + } else // large frame + { + p->width = LARGESIZE; + p->height = LARGESIZE; + + // RF, expand while falling + p->endheight = LARGESIZE * 3.0; + p->endwidth = LARGESIZE * 3.0; + } + + if ( !length ) { + p->width *= 0.2; + p->height *= 0.2; + + p->endheight = NORMALSIZE; + p->endwidth = NORMALSIZE; + } + + p->type = P_SMOKE; + + VectorCopy( origin, p->org ); + + p->vel[0] = crandom() * 6; + p->vel[1] = crandom() * 6; + p->vel[2] = random() * 6; + + // RF, add some gravity/randomness + p->accel[0] = crandom() * 3; + p->accel[1] = crandom() * 3; + p->accel[2] = -PARTICLE_GRAVITY * 0.2; + + VectorClear( p->accel ); + + p->rotate = qfalse; + + p->roll = rand() % 179; + + p->color = ZOMBIE; + + } + + +} + +void CG_ParticleSparks( vec3_t org, vec3_t vel, int duration, float x, float y, float speed ) { + cparticle_t *p; + + if ( !free_particles ) { + return; + } + + if ( !CG_ParticleLODCheck() ) { + return; + } + + p = free_particles; + free_particles = p->next; + p->next = active_particles; + active_particles = p; + p->time = cg.time; + + p->endtime = cg.time + duration; + p->startfade = cg.time + duration / 2; + + p->color = EMISIVEFADE; + p->alpha = 0.4; + p->alphavel = 0; + + p->height = 0.5; + p->width = 0.5; + p->endheight = 0.5; + p->endwidth = 0.5; + + p->pshader = cgs.media.tracerShader; + + p->type = P_SMOKE; + + VectorCopy( org, p->org ); + + p->org[0] += ( crandom() * x ); + p->org[1] += ( crandom() * y ); + + p->vel[0] = vel[0]; + p->vel[1] = vel[1]; + p->vel[2] = vel[2]; + + p->accel[0] = p->accel[1] = p->accel[2] = 0; + + p->vel[0] += ( crandom() * 4 ); + p->vel[1] += ( crandom() * 4 ); + p->vel[2] += ( 20 + ( crandom() * 10 ) ) * speed; + + p->accel[0] = crandom() * 4; + p->accel[1] = crandom() * 4; + +} + +void CG_ParticleDust( centity_t *cent, vec3_t origin, vec3_t dir ) { + float length; + float dist; + float crittersize; + vec3_t angles, forward; + vec3_t point; + cparticle_t *p; + int i; + + dist = 0; + + VectorNegate( dir, dir ); + length = VectorLength( dir ); + vectoangles( dir, angles ); + AngleVectors( angles, forward, NULL, NULL ); + + if ( cent->currentState.density == 0 ) { // normal ai size + crittersize = NORMALSIZE; + } else { + crittersize = LARGESIZE; + } + + if ( length ) { + dist = length / crittersize; + } + + if ( dist < 1 ) { + dist = 1; + } + + VectorCopy( origin, point ); + + for ( i = 0; i < dist; i++ ) + { + VectorMA( point, crittersize, forward, point ); + + if ( !free_particles ) { + return; + } + + p = free_particles; + free_particles = p->next; + p->next = active_particles; + active_particles = p; + + p->time = cg.time; + p->alpha = 5.0; + p->alphavel = 0; + p->roll = 0; + + p->pshader = cgs.media.bloodCloudShader; + + // RF, stay around for long enough to expand and dissipate naturally + if ( length ) { + p->endtime = cg.time + 4500 + ( crandom() * 3500 ); + } else { + p->endtime = cg.time + 750 + ( crandom() * 500 ); + } + + p->startfade = cg.time; + + if ( cent->currentState.density == 0 ) { // normal ai size + p->width = NORMALSIZE; + p->height = NORMALSIZE; + + // RF, expand while falling + p->endheight = NORMALSIZE * 4.0; + p->endwidth = NORMALSIZE * 4.0; + } else // large frame + { + p->width = LARGESIZE; + p->height = LARGESIZE; + + // RF, expand while falling + p->endheight = LARGESIZE * 3.0; + p->endwidth = LARGESIZE * 3.0; + } + + if ( !length ) { + p->width *= 0.2; + p->height *= 0.2; + + p->endheight = NORMALSIZE; + p->endwidth = NORMALSIZE; + } + + p->type = P_SMOKE; + + VectorCopy( point, p->org ); + + p->vel[0] = crandom() * 6; + p->vel[1] = crandom() * 6; + p->vel[2] = random() * 20; + + // RF, add some gravity/randomness + p->accel[0] = crandom() * 3; + p->accel[1] = crandom() * 3; + p->accel[2] = -PARTICLE_GRAVITY * 0.4; + + VectorClear( p->accel ); + + p->rotate = qfalse; + + p->roll = rand() % 179; + + if ( cent->currentState.density ) { + p->color = GREY75; + } else { + p->color = MUSTARD; + } + + p->alpha = 0.75; + + } + + +} + +void CG_ParticleMisc( qhandle_t pshader, vec3_t origin, int size, int duration, float alpha ) { + cparticle_t *p; + + if ( !pshader ) { + CG_Printf( "CG_ParticleImpactSmokePuff pshader == ZERO!\n" ); + } + + if ( !free_particles ) { + return; + } + + if ( !CG_ParticleLODCheck() ) { + return; + } + + p = free_particles; + free_particles = p->next; + p->next = active_particles; + active_particles = p; + p->time = cg.time; + p->alpha = 1.0; + p->alphavel = 0; + p->roll = rand() % 179; + + p->pshader = pshader; + + if ( duration > 0 ) { + p->endtime = cg.time + duration; + } else { + p->endtime = duration; + } + + p->startfade = cg.time; + + p->width = size; + p->height = size; + + p->endheight = size; + p->endwidth = size; + + p->type = P_SPRITE; + + VectorCopy( origin, p->org ); + + p->rotate = qfalse; +} diff --git a/Projects/Android/jni/rtcw/src/cgame/cg_players.c b/Projects/Android/jni/rtcw/src/cgame/cg_players.c new file mode 100644 index 0000000..69aec41 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/cgame/cg_players.c @@ -0,0 +1,5589 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +/* + * name: cg_players.c + * + * desc: handle the media and animation for player entities + * +*/ + +#include "cg_local.h" + +#define SWING_RIGHT 1 +#define SWING_LEFT 2 + +char *cg_customSoundNames[MAX_CUSTOM_SOUNDS] = { + "*death1.wav", + "*death2.wav", + "*death3.wav", + "*jump1.wav", + "*pain25_1.wav", + "*pain50_1.wav", + "*pain75_1.wav", + "*pain100_1.wav", + "*falling1.wav", + "*gasp.wav", + "*drown.wav", + "*fall1.wav", + "*fall2.wav", + "*taunt.wav", + "*exert1.wav", + "*exert2.wav", + "*exert3.wav", +}; + +/* +================ +CG_EntOnFire +================ +*/ +qboolean CG_EntOnFire( centity_t *cent ) { + return ( ( cent->currentState.onFireStart < cg.time ) && + ( cent->currentState.onFireEnd > cg.time ) ); +} + +/* +================ +CG_IsCrouchingAnim +================ +*/ +qboolean CG_IsCrouchingAnim( clientInfo_t *ci, int animNum ) { + animation_t *anim; + + // FIXME: make compatible with new scripting + animNum &= ~ANIM_TOGGLEBIT; + // + anim = BG_GetAnimationForIndex( ci->clientNum, animNum ); + // + if ( anim->movetype & ( ( 1 << ANIM_MT_IDLECR ) | ( 1 << ANIM_MT_WALKCR ) | ( 1 << ANIM_MT_WALKCRBK ) ) ) { + return qtrue; + } + // + return qfalse; +} + +/* +================ +CG_CustomSound + +================ +*/ +sfxHandle_t CG_CustomSound( int clientNum, const char *soundName ) { + clientInfo_t *ci; + int i; + + if ( soundName[0] != '*' ) { + return trap_S_RegisterSound( soundName ); + } + + if ( clientNum < 0 || clientNum >= MAX_CLIENTS ) { + clientNum = 0; + } + ci = &cgs.clientinfo[ clientNum ]; + + for ( i = 0 ; i < MAX_CUSTOM_SOUNDS && cg_customSoundNames[i] ; i++ ) { + if ( !Q_stricmp( soundName, cg_customSoundNames[i] ) ) { + return ci->sounds[i]; + } + } + + CG_Error( "Unknown custom sound: %s", soundName ); + return 0; +} + + + +/* +============================================================================= + +CLIENT INFO + +============================================================================= +*/ + +/* +====================== +CG_ParseGibModels + +Read a configuration file containing gib models for use with this character +====================== +*/ +static qboolean CG_ParseGibModels( const char *filename, clientInfo_t *ci ) { + char *text_p; + int len; + int i; + char *token; + char text[20000]; + fileHandle_t f; + + memset( ci->gibModels, 0, sizeof( ci->gibModels ) ); + + // load the file + len = trap_FS_FOpenFile( filename, &f, FS_READ ); + if ( len <= 0 ) { + return qfalse; + } + if ( len >= sizeof( text ) - 1 ) { + CG_Printf( "File %s too long\n", filename ); + return qfalse; + } + trap_FS_Read( text, len, f ); + text[len] = 0; + trap_FS_FCloseFile( f ); + + // parse the text + text_p = text; + + for ( i = 0; i < MAX_GIB_MODELS; i++ ) { + token = COM_Parse( &text_p ); + if ( !token ) { + break; + } + // cache this model + ci->gibModels[i] = trap_R_RegisterModel( token ); + } + + return qtrue; +} + + +/* +================== +CG_CalcMoveSpeeds +================== +*/ +void CG_CalcMoveSpeeds( clientInfo_t *ci ) { + char *tags[2] = {"tag_footleft", "tag_footright"}; + vec3_t oldPos[2]; + refEntity_t refent; + animation_t *anim; + int i, j, k; + float totalSpeed; + int numSpeed; + int lastLow, low, numSteps, lastFirst, thisFirst; + qboolean isStrafe; + orientation_t o[2]; + + refent.hModel = ci->legsModel; + + for ( i = 0, anim = ci->modelInfo->animations; i < ci->modelInfo->numAnimations; i++, anim++ ) { + + if ( anim->moveSpeed == 0 ) { + continue; + } + + totalSpeed = 0; + lastLow = -1; + numSpeed = 0; + numSteps = 0; + isStrafe = qfalse; + if ( strstr( anim->name, "strafe" ) ) { + isStrafe = qtrue; + } + + // first, get the end frame positions, since thats where we loop from + refent.frame = anim->firstFrame + anim->numFrames - 1; + refent.oldframe = refent.frame; + // for each foot + for ( k = 0; k < 2; k++ ) { + if ( trap_R_LerpTag( &o[k], &refent, tags[k], 0 ) < 0 ) { + CG_Error( "CG_CalcMoveSpeeds: unable to find tag %s, cannot calculate movespeed", tags[k] ); + } + } + // save the positions + for ( k = 0; k < 2; k++ ) { + VectorCopy( o[k].origin, oldPos[k] ); + } + // + // set the numSteps + if ( !isStrafe ) { + if ( o[0].origin[0] > o[1].origin[0] ) { + thisFirst = 0; + } else { thisFirst = 1;} + } else { + if ( o[0].origin[1] > o[1].origin[1] ) { + thisFirst = 0; + } else { thisFirst = 1;} + } + lastFirst = thisFirst; + + // for each frame + for ( j = 0; j < anim->numFrames; j++ ) { + + refent.frame = anim->firstFrame + j; + refent.oldframe = refent.frame; + + // for each foot + for ( k = 0; k < 2; k++ ) { + if ( trap_R_LerpTag( &o[k], &refent, tags[k], 0 ) < 0 ) { + CG_Error( "CG_CalcMoveSpeeds: unable to find tag %s, cannot calculate movespeed", tags[k] ); + } + } + + // find the contact foot + if ( anim->flags & ANIMFL_LADDERANIM ) { + if ( o[0].origin[0] > o[1].origin[0] ) { + low = 0; + } else { + low = 1; + } + totalSpeed += fabs( oldPos[low][2] - o[low].origin[2] ); + } else { + if ( o[0].origin[2] < o[1].origin[2] ) { + low = 0; + } else { + low = 1; + } + if ( !isStrafe ) { + totalSpeed += fabs( oldPos[low][0] - o[low].origin[0] ); + } else { + totalSpeed += fabs( oldPos[low][1] - o[low].origin[1] ); + } + // + // set the numSteps + if ( !isStrafe ) { + if ( o[0].origin[0] > o[1].origin[0] ) { + thisFirst = 0; + } else { thisFirst = 1;} + } else { + if ( o[0].origin[1] > o[1].origin[1] ) { + thisFirst = 0; + } else { thisFirst = 1;} + } + // if they have changed, record the step + if ( lastFirst != thisFirst ) { + numSteps++; + lastFirst = thisFirst; + } + } + + numSpeed++; + + // save the positions + for ( k = 0; k < 2; k++ ) { + VectorCopy( o[k].origin, oldPos[k] ); + } + lastLow = low; + } + + // record the speed + if ( anim->moveSpeed < 0 ) { // use the auto calculations + anim->moveSpeed = (int)( ( totalSpeed / numSpeed ) * 1000.0 / anim->frameLerp ); + } + // set the stepGap + if ( !numSteps ) { + numSteps = 2; + } + if ( numSteps % 2 ) { + numSteps++; // round it up if odd number of steps + } + anim->stepGap = ( 0.5 * ( (float)anim->moveSpeed * (float)anim->duration / 1000.0 ) ); + anim->stepGap /= ( numSteps / 2 ); // in case there are more than 2 steps in animation + if ( isStrafe ) { + anim->stepGap *= 1.3; // HACK + } + } + + if ( cgs.localServer ) { + CG_SendMoveSpeed( ci->modelInfo->animations, ci->modelInfo->numAnimations, ci->modelInfo->modelname ); + } +} + +/* +====================== +CG_ParseAnimationFiles + + Read in all the configuration and script files for this model. +====================== +*/ + +#if 0 // RF, this entire function not used anymore, since we now grab all this stuff from the server + +static qboolean CG_ParseAnimationFiles( const char *modelname, clientInfo_t *ci, int client ) { + char text[100000]; + char filename[MAX_QPATH]; + fileHandle_t f; + int len; + + // set the name of the model in the modelinfo structure + Q_strncpyz( ci->modelInfo->modelname, modelname, sizeof( ci->modelInfo->modelname ) ); + + // load the cfg file + Com_sprintf( filename, sizeof( filename ), "models/players/%s/wolfanim.cfg", modelname ); + len = trap_FS_FOpenFile( filename, &f, FS_READ ); + if ( len <= 0 ) { + return qfalse; + } + if ( len >= sizeof( text ) - 1 ) { + CG_Printf( "File %s too long\n", filename ); + return qfalse; + } + trap_FS_Read( text, len, f ); + text[len] = 0; + trap_FS_FCloseFile( f ); + + // parse the text + BG_AnimParseAnimConfig( ci->modelInfo, filename, text ); + + if ( ci->isSkeletal != ci->modelInfo->isSkeletal ) { + CG_Error( "Mis-match in %s, loaded skeletal model, but file does not specify SKELETAL\n", filename ); + } + + // calc movespeed values if required + CG_CalcMoveSpeeds( ci ); + + // load the script file + Com_sprintf( filename, sizeof( filename ), "models/players/%s/wolfanim.script", modelname ); + len = trap_FS_FOpenFile( filename, &f, FS_READ ); + if ( len <= 0 ) { + if ( ci->modelInfo->version > 1 ) { + return qfalse; + } + // try loading the default script for old legacy models + Com_sprintf( filename, sizeof( filename ), "models/players/default.script", modelname ); + len = trap_FS_FOpenFile( filename, &f, FS_READ ); + if ( len <= 0 ) { + return qfalse; + } + } + if ( len >= sizeof( text ) - 1 ) { + CG_Printf( "File %s too long\n", filename ); + return qfalse; + } + trap_FS_Read( text, len, f ); + text[len] = 0; + trap_FS_FCloseFile( f ); + + // parse the text + BG_AnimParseAnimScript( ci->modelInfo, &cgs.animScriptData, ci->clientNum, filename, text ); + return qtrue; +} +#endif + +/* +========================== +CG_RegisterClientSkin +========================== +*/ + +//----(SA) modified this for head separation + +static qboolean CG_RegisterClientSkin( clientInfo_t *ci, const char *modelName, const char *skinName ) { + char filename[MAX_QPATH]; + + // RF, try and register the new "body_*.skin" file for skeletal animation + Com_sprintf( filename, sizeof( filename ), "models/players/%s/body_%s.skin", modelName, skinName ); + ci->legsSkin = trap_R_RegisterSkin( filename ); + if ( ci->legsSkin ) { // skeletal model + ci->torsoSkin = ci->legsSkin; + return qtrue; + } + + Com_sprintf( filename, sizeof( filename ), "models/players/%s/lower_%s.skin", modelName, skinName ); + ci->legsSkin = trap_R_RegisterSkin( filename ); + + Com_sprintf( filename, sizeof( filename ), "models/players/%s/upper_%s.skin", modelName, skinName ); + ci->torsoSkin = trap_R_RegisterSkin( filename ); + + if ( !ci->legsSkin || !ci->torsoSkin ) { + return qfalse; + } + + return qtrue; +} + +/* +============== +CG_RegisterClientHeadSkin +============== +*/ +static qboolean CG_RegisterClientHeadSkin( clientInfo_t *ci, const char *modelName, const char *hSkinName ) { + char filename[MAX_QPATH]; + + Com_sprintf( filename, sizeof( filename ), "models/players/%s/head_%s.skin", modelName, hSkinName ); + ci->headSkin = trap_R_RegisterSkin( filename ); + + if ( !ci->headSkin ) { + return qfalse; + } + + return qtrue; + +} + +//----(SA) end + + + +//----(SA) added +/* +============== +CG_RegisterAcc +============== +*/ +static qboolean CG_RegisterAcc( clientInfo_t *ci, const char *modelName, const char *skinName, int *model, int *skin ) { + char namefromskin[MAX_QPATH]; + char filename[MAX_QPATH]; + + if ( !model || !skin ) { + return qfalse; + } + + // FIXME: have the check the last 4 chars rather than strstr() + if ( !strstr( skinName, ".md3" ) ) { // try to find a skin in the acc folder that matches + *skin = trap_R_RegisterSkin( va( "%s/%s.skin", modelName, skinName ) ); + + if ( *skin ) { + if ( trap_R_GetSkinModel( *skin, "md3_part", &namefromskin[0] ) ) { + Com_sprintf( filename, sizeof( filename ), "%s/acc/%s", modelName, namefromskin ); + // NOTE: FIXME: this will currently only work with accessories in the /acc directory. + // It will have to strip the directory off the end and then use the remaining + // path in order to work for arbitrary sub-directories. +// Com_sprintf( filename, sizeof( filename ), "%s/%s/%s.md3", modelName, , namefromskin ); + + } else { + Com_sprintf( filename, sizeof( filename ), "%s/%s.md3", modelName, skinName ); + } + } else { + Com_sprintf( filename, sizeof( filename ), "%s/%s.md3", modelName, skinName ); + } + } else { // the skin wants a straight model + Com_sprintf( filename, sizeof( filename ), "%s/%s", modelName, skinName ); + } + + + *model = trap_R_RegisterModel( filename ); + + if ( *model ) { + return qtrue; + } + + return qfalse; +} + +//----(SA) end + + +/* +================== +CG_CheckForExistingModelInfo + + If this player model has already been parsed, then use the existing information. + Otherwise, set the modelInfo pointer to the first free slot. + + returns qtrue if existing model found, qfalse otherwise +================== +*/ +extern animScriptData_t *globalScriptData; +qboolean CG_CheckForExistingModelInfo( clientInfo_t *ci, char *modelName, animModelInfo_t **modelInfo ) { + int i; + animModelInfo_t *trav; // *firstFree=NULL; // TTimo: unused + + globalScriptData = &cgs.animScriptData; + + for ( i = 0; i < MAX_ANIMSCRIPT_MODELS; i++ ) { + trav = cgs.animScriptData.modelInfo[i]; + if ( trav && trav->modelname[0] ) { + // this model is used, so check if it's a match + if ( !Q_stricmp( trav->modelname, modelName ) ) { + // found a match, use this modelinfo + *modelInfo = trav; + cgs.animScriptData.clientModels[ci->clientNum] = i + 1; + return qtrue; + } + } else { + // if we fell down to here, then we have found a free slot + + // request it from the server (game module) + if ( trap_GetModelInfo( ci->clientNum, modelName, &cgs.animScriptData.modelInfo[i] ) ) { + + // success + cgs.animScriptData.clientModels[ci->clientNum] = i + 1; + *modelInfo = cgs.animScriptData.modelInfo[i]; + // calc movespeed/footstep values + CG_CalcMoveSpeeds( ci ); + return qfalse; // we need to cache all the assets for this character + + } + + // huh!? + CG_Error( "CG_CheckForExistingModelInfo: unable to optain modelInfo from server" ); + } + + } + + CG_Error( "unable to find a free modelinfo slot, cannot continue\n" ); + // qfalse signifies that we need to parse the information from the script files + return qfalse; +} + + +/* +========================== +CG_RegisterClientModelname +========================== +*/ + +//----(SA) modified this for head separation + +static qboolean CG_RegisterClientModelname( clientInfo_t *ci, const char *modelName, const char *skinName ) { + char namefromskin[MAX_QPATH]; + char filename[MAX_QPATH]; + char name[MAX_QPATH]; + int i; + + // if any skins failed to load, return failure +//----(SA) modified this for head separation + if ( !CG_RegisterClientSkin( ci, modelName, skinName ) ) { + Com_Printf( "Failed to load skin file: %s/%s\n", modelName, skinName ); + return qfalse; + } + + // load cmodels before models so filecache works + + if ( trap_R_GetSkinModel( ci->legsSkin, "md3_part", &namefromskin[0] ) ) { + Com_sprintf( filename, sizeof( filename ), "models/players/%s/%s", modelName, namefromskin ); + ci->legsModel = trap_R_RegisterModel( filename ); + } else { // try skeletal model + Com_sprintf( filename, sizeof( filename ), "models/players/%s/body.mds", modelName ); + ci->legsModel = trap_R_RegisterModel( filename ); + + if ( !ci->legsModel ) { // revert to mesh animation + Com_sprintf( filename, sizeof( filename ), "models/players/%s/lower.md3", modelName ); + ci->legsModel = trap_R_RegisterModel( filename ); + } else { // found skeletal model + ci->isSkeletal = qtrue; + ci->torsoModel = ci->legsModel; + } + } + + if ( !ci->isSkeletal ) { + + if ( !ci->legsModel ) { + Com_Printf( "Failed to load legs model file %s\n", filename ); + return qfalse; + } + + if ( trap_R_GetSkinModel( ci->torsoSkin, "md3_part", &namefromskin[0] ) ) { + Com_sprintf( filename, sizeof( filename ), "models/players/%s/%s", modelName, namefromskin ); + } else { + Com_sprintf( filename, sizeof( filename ), "models/players/%s/upper.md3", modelName ); + } + + ci->torsoModel = trap_R_RegisterModel( filename ); + + if ( !ci->torsoModel ) { + Com_Printf( "Failed to load torso model file %s\n", filename ); + return qfalse; + } + + } + +//----(SA) testing + { + char scaleString[MAX_QPATH]; + char *string_p; + char *scaleToken; + qboolean badscale = qfalse; + + string_p = scaleString; + + if ( trap_R_GetSkinModel( ci->legsSkin, "playerscale", &scaleString[0] ) ) { + scaleToken = COM_Parse( &string_p ); + if ( !scaleToken ) { + badscale = qtrue; // and drop to "if(badscale)" below + } else + { + ci->playermodelScale[0] = atof( scaleToken ); + + scaleToken = COM_Parse( &string_p ); + if ( !scaleToken ) { + badscale = qtrue; // and drop to "if(badscale)" below + } else + { + ci->playermodelScale[1] = atof( scaleToken ); + + scaleToken = COM_Parse( &string_p ); + if ( !scaleToken ) { + badscale = qtrue; // and drop to "if(badscale)" below + } else + { + ci->playermodelScale[2] = atof( scaleToken ); + } + } + } + } + + if ( badscale ) { + ci->playermodelScale[0] = + ci->playermodelScale[1] = + ci->playermodelScale[2] = 0.0f; + } + } +//----(SA) end + + + // try all the accessories + if ( trap_R_GetSkinModel( ci->legsSkin, "md3_beltr", &namefromskin[0] ) ) { + CG_RegisterAcc( ci, va( "models/players/%s", modelName ), namefromskin, &ci->accModels[ACC_BELT_LEFT], &ci->accSkins[ACC_BELT_LEFT] ); + } + if ( trap_R_GetSkinModel( ci->legsSkin, "md3_beltl", &namefromskin[0] ) ) { + CG_RegisterAcc( ci, va( "models/players/%s", modelName ), namefromskin, &ci->accModels[ACC_BELT_RIGHT], &ci->accSkins[ACC_BELT_RIGHT] ); + } + if ( trap_R_GetSkinModel( ci->torsoSkin, "md3_belt", &namefromskin[0] ) ) { + CG_RegisterAcc( ci, va( "models/players/%s", modelName ), namefromskin, &ci->accModels[ACC_BELT], &ci->accSkins[ACC_BELT] ); + } + if ( trap_R_GetSkinModel( ci->torsoSkin, "md3_back", &namefromskin[0] ) ) { + CG_RegisterAcc( ci, va( "models/players/%s", modelName ), namefromskin, &ci->accModels[ACC_BACK], &ci->accSkins[ACC_BACK] ); + } + if ( trap_R_GetSkinModel( ci->torsoSkin, "md3_weapon", &namefromskin[0] ) ) { + CG_RegisterAcc( ci, va( "models/players/%s", modelName ), namefromskin, &ci->accModels[ACC_WEAPON], &ci->accSkins[ACC_WEAPON] ); + } + if ( trap_R_GetSkinModel( ci->torsoSkin, "md3_weapon2", &namefromskin[0] ) ) { + CG_RegisterAcc( ci, va( "models/players/%s", modelName ), namefromskin, &ci->accModels[ACC_WEAPON2], &ci->accSkins[ACC_WEAPON2] ); + } +//----(SA) added + // try anim script parts + for ( i = 0; i < 8; i++ ) { + if ( trap_R_GetSkinModel( ci->torsoSkin, va( "md3_animscript%d", i ), &namefromskin[0] ) ) { + CG_RegisterAcc( ci, va( "models/players/%s", modelName ), namefromskin, &ci->partModels[ACC_WEAPON], &ci->partSkins[ACC_WEAPON] ); + } + } +//----(SA) end + + // look for this model in the list of models already opened + if ( !CG_CheckForExistingModelInfo( ci, (char *)modelName, &ci->modelInfo ) ) { +/* + if ( !CG_ParseAnimationFiles( modelName, ci, ci->clientNum ) ) { + Com_Printf( "Failed to load animation file %s\n", filename ); + return qfalse; + } +*/ + // special case, only cache certain shaders/models for certain characters + if ( !Q_strcasecmp( (char *)modelName, "zombie" ) ) { + cgs.media.zombieSpiritWallShader = trap_R_RegisterShader( "zombieDeathWindTrail" ); + cgs.media.zombieSpiritTrailShader = trap_R_RegisterShader( "zombieSpiritTrail" ); + cgs.media.zombieSpiritSkullShader = trap_R_RegisterShader( "zombieSpiritSkull" ); + //cgs.media.zombieDeathDustShader = trap_R_RegisterShader( "zombieDeathDust" ); + //cgs.media.zombieBodyFadeShader = trap_R_RegisterShader( "zombieBodyFade" ); + //cgs.media.zombieHeadFadeShader = trap_R_RegisterShader( "zombieHeadFade" ); + + cgs.media.skeletonSkinShader = trap_R_RegisterShader( "skeletonSkin" ); + cgs.media.skeletonLegsModel = trap_R_RegisterModel( "models/players/skel/lower.md3" ); + cgs.media.skeletonLegsSkin = trap_R_RegisterSkin( "models/players/skel/lower_default.skin" ); + cgs.media.skeletonTorsoModel = trap_R_RegisterModel( "models/players/skel/upper.md3" ); + cgs.media.skeletonTorsoSkin = trap_R_RegisterSkin( "models/players/skel/upper_default.skin" ); + cgs.media.skeletonHeadModel = trap_R_RegisterModel( "models/players/skel/head.md3" ); + cgs.media.skeletonHeadSkin = trap_R_RegisterSkin( "models/players/skel/head_default.skin" ); + + cgs.media.zombieSpiritSound = trap_S_RegisterSound( "sound/zombie/attack/spirit_start.wav" ); + cgs.media.zombieSpiritLoopSound = trap_S_RegisterSound( "sound/zombie/attack/spirit_loop.wav" ); + cgs.media.zombieDeathSound = trap_S_RegisterSound( "sound/world/ceramicbreak.wav" ); // Zombie Gib + + cgs.media.spiritSkullModel = trap_R_RegisterModel( "models/mapobjects/skull/skul2t.md3" ); + + CG_RegisterWeapon( WP_GAUNTLET ); + } else if ( !Q_strcasecmp( (char *)modelName, "beast" ) ) { + cgs.media.helgaSpiritSkullShader = trap_R_RegisterShader( "helgaSpiritGhost" ); + cgs.media.helgaSpiritTrailShader = trap_R_RegisterShader( "helgaSpiritTrail" ); + cgs.media.helgaGhostModel = trap_R_RegisterModel( "models/players/beast/ghost.md3" ); + cgs.media.helgaSpiritLoopSound = trap_S_RegisterSound( "sound/beast/tortured_souls_loop.wav" ); + cgs.media.helgaSpiritSound = CG_SoundScriptPrecache( "helgaSpiritStartSound" ); + cgs.media.helgaGaspSound = CG_SoundScriptPrecache( "helgaSpiritGasp" ); + } else if ( !Q_strcasecmp( (char *)modelName, "loper" ) ) { + //cgs.media.loperGroundChargeShader = trap_R_RegisterShader( "loperGroundCharge" ); + } else if ( !Q_strcasecmp( (char *)modelName, "protosoldier" ) ) { + cgs.media.protoArmorBreak = CG_SoundScriptPrecache( "Protosoldier_loseArmor" ); + + cgs.media.protoArmor[0] = trap_R_RegisterModel( "models/players/protosoldier/armor/nodam_chest.md3" ); + cgs.media.protoArmor[1] = trap_R_RegisterModel( "models/players/protosoldier/armor/nodam_lftcalf.md3" ); + cgs.media.protoArmor[2] = trap_R_RegisterModel( "models/players/protosoldier/armor/nodam_lftforarm.md3" ); + cgs.media.protoArmor[3] = trap_R_RegisterModel( "models/players/protosoldier/armor/nodam_lftshoulder.md3" ); + cgs.media.protoArmor[4] = trap_R_RegisterModel( "models/players/protosoldier/armor/nodam_lftthigh.md3" ); + cgs.media.protoArmor[5] = trap_R_RegisterModel( "models/players/protosoldier/armor/nodam_rtcalf.md3" ); + cgs.media.protoArmor[6] = trap_R_RegisterModel( "models/players/protosoldier/armor/nodam_rtforarm.md3" ); + cgs.media.protoArmor[7] = trap_R_RegisterModel( "models/players/protosoldier/armor/nodam_rtshoulder.md3" ); + cgs.media.protoArmor[8] = trap_R_RegisterModel( "models/players/protosoldier/armor/nodam_rtthigh.md3" ); + + cgs.media.protoArmor[9] = trap_R_RegisterModel( "models/players/protosoldier/armor/dam_chest1.md3" ); + cgs.media.protoArmor[10] = trap_R_RegisterModel( "models/players/protosoldier/armor/dam_lftcalf1.md3" ); + cgs.media.protoArmor[11] = trap_R_RegisterModel( "models/players/protosoldier/armor/dam_lftforarm1.md3" ); + cgs.media.protoArmor[12] = trap_R_RegisterModel( "models/players/protosoldier/armor/dam_lftshoulder1.md3" ); + cgs.media.protoArmor[13] = trap_R_RegisterModel( "models/players/protosoldier/armor/dam_lftthigh1.md3" ); + cgs.media.protoArmor[14] = trap_R_RegisterModel( "models/players/protosoldier/armor/dam_rtcalf1.md3" ); + cgs.media.protoArmor[15] = trap_R_RegisterModel( "models/players/protosoldier/armor/dam_rtforarm1.md3" ); + cgs.media.protoArmor[16] = trap_R_RegisterModel( "models/players/protosoldier/armor/dam_rtshoulder1.md3" ); + cgs.media.protoArmor[17] = trap_R_RegisterModel( "models/players/protosoldier/armor/dam_rtthigh1.md3" ); + + cgs.media.protoArmor[18] = trap_R_RegisterModel( "models/players/protosoldier/armor/dam_chest2.md3" ); + cgs.media.protoArmor[19] = trap_R_RegisterModel( "models/players/protosoldier/armor/dam_lftcalf2.md3" ); + cgs.media.protoArmor[20] = trap_R_RegisterModel( "models/players/protosoldier/armor/dam_lftforarm2.md3" ); + cgs.media.protoArmor[21] = trap_R_RegisterModel( "models/players/protosoldier/armor/dam_lftshoulder2.md3" ); + cgs.media.protoArmor[22] = trap_R_RegisterModel( "models/players/protosoldier/armor/dam_lftthigh2.md3" ); + cgs.media.protoArmor[23] = trap_R_RegisterModel( "models/players/protosoldier/armor/dam_rtcalf2.md3" ); + cgs.media.protoArmor[24] = trap_R_RegisterModel( "models/players/protosoldier/armor/dam_rtforarm2.md3" ); + cgs.media.protoArmor[25] = trap_R_RegisterModel( "models/players/protosoldier/armor/dam_rtshoulder2.md3" ); + cgs.media.protoArmor[26] = trap_R_RegisterModel( "models/players/protosoldier/armor/dam_rtthigh2.md3" ); + } else if ( !Q_strcasecmp( (char *)modelName, "supersoldier" ) ) { + + cgs.media.superArmorBreak = CG_SoundScriptPrecache( "Supersoldier_loseArmor" ); + + cgs.media.superArmor[0] = trap_R_RegisterModel( "models/players/supersoldier/armor/nodam_chest.md3" ); + cgs.media.superArmor[1] = trap_R_RegisterModel( "models/players/supersoldier/armor/nodam_lftcalf.md3" ); + cgs.media.superArmor[2] = trap_R_RegisterModel( "models/players/supersoldier/armor/nodam_lftforarm.md3" ); + cgs.media.superArmor[3] = trap_R_RegisterModel( "models/players/supersoldier/armor/nodam_lftshoulder.md3" ); + cgs.media.superArmor[4] = trap_R_RegisterModel( "models/players/supersoldier/armor/nodam_lftthigh.md3" ); + cgs.media.superArmor[5] = trap_R_RegisterModel( "models/players/supersoldier/armor/nodam_rtcalf.md3" ); + cgs.media.superArmor[6] = trap_R_RegisterModel( "models/players/supersoldier/armor/nodam_rtforarm.md3" ); + cgs.media.superArmor[7] = trap_R_RegisterModel( "models/players/supersoldier/armor/nodam_rtshoulder.md3" ); + cgs.media.superArmor[8] = trap_R_RegisterModel( "models/players/supersoldier/armor/nodam_rtthigh.md3" ); + + cgs.media.superArmor[9] = trap_R_RegisterModel( "models/players/supersoldier/armor/nodam_lftfoot.md3" ); + cgs.media.superArmor[10] = trap_R_RegisterModel( "models/players/supersoldier/armor/nodam_rtfoot.md3" ); + cgs.media.superArmor[11] = trap_R_RegisterModel( "models/players/supersoldier/armor/nodam_lftuparm.md3" ); + cgs.media.superArmor[12] = trap_R_RegisterModel( "models/players/supersoldier/armor/nodam_rtuparm.md3" ); + cgs.media.superArmor[13] = trap_R_RegisterModel( "models/players/supersoldier/armor/nodam_waist.md3" ); + cgs.media.superArmor[14] = trap_R_RegisterModel( "models/players/supersoldier/armor/nodam_lftknee.md3" ); + cgs.media.superArmor[15] = trap_R_RegisterModel( "models/players/supersoldier/armor/nodam_rtknee.md3" ); + + + + cgs.media.superArmor[16] = trap_R_RegisterModel( "models/players/supersoldier/armor/dam_chest1.md3" ); + cgs.media.superArmor[17] = trap_R_RegisterModel( "models/players/supersoldier/armor/dam_lftcalf1.md3" ); + cgs.media.superArmor[18] = trap_R_RegisterModel( "models/players/supersoldier/armor/dam_lftforarm1.md3" ); + cgs.media.superArmor[19] = trap_R_RegisterModel( "models/players/supersoldier/armor/dam_lftshoulder1.md3" ); + cgs.media.superArmor[20] = trap_R_RegisterModel( "models/players/supersoldier/armor/dam_lftthigh1.md3" ); + cgs.media.superArmor[21] = trap_R_RegisterModel( "models/players/supersoldier/armor/dam_rtcalf1.md3" ); + cgs.media.superArmor[22] = trap_R_RegisterModel( "models/players/supersoldier/armor/dam_rtforarm1.md3" ); + cgs.media.superArmor[23] = trap_R_RegisterModel( "models/players/supersoldier/armor/dam_rtshoulder1.md3" ); + cgs.media.superArmor[24] = trap_R_RegisterModel( "models/players/supersoldier/armor/dam_rtthigh1.md3" ); + + cgs.media.superArmor[25] = trap_R_RegisterModel( "models/players/supersoldier/armor/dam_lftfoot1.md3" ); + cgs.media.superArmor[26] = trap_R_RegisterModel( "models/players/supersoldier/armor/dam_rtfoot1.md3" ); + cgs.media.superArmor[27] = trap_R_RegisterModel( "models/players/supersoldier/armor/dam_lftuparm1.md3" ); + cgs.media.superArmor[28] = trap_R_RegisterModel( "models/players/supersoldier/armor/dam_rtuparm1.md3" ); + cgs.media.superArmor[29] = trap_R_RegisterModel( "models/players/supersoldier/armor/dam_waist1.md3" ); + + cgs.media.superArmor[30] = 0; + cgs.media.superArmor[31] = 0; + + + cgs.media.superArmor[32] = trap_R_RegisterModel( "models/players/supersoldier/armor/dam_chest2.md3" ); + cgs.media.superArmor[33] = trap_R_RegisterModel( "models/players/supersoldier/armor/dam_lftcalf2.md3" ); + cgs.media.superArmor[34] = trap_R_RegisterModel( "models/players/supersoldier/armor/dam_lftforarm2.md3" ); + cgs.media.superArmor[35] = trap_R_RegisterModel( "models/players/supersoldier/armor/dam_lftshoulder2.md3" ); + cgs.media.superArmor[36] = trap_R_RegisterModel( "models/players/supersoldier/armor/dam_lftthigh2.md3" ); + cgs.media.superArmor[37] = trap_R_RegisterModel( "models/players/supersoldier/armor/dam_rtcalf2.md3" ); + cgs.media.superArmor[38] = trap_R_RegisterModel( "models/players/supersoldier/armor/dam_rtforarm2.md3" ); + cgs.media.superArmor[39] = trap_R_RegisterModel( "models/players/supersoldier/armor/dam_rtshoulder2.md3" ); + cgs.media.superArmor[30] = trap_R_RegisterModel( "models/players/supersoldier/armor/dam_rtthigh2.md3" ); + + cgs.media.superArmor[31] = trap_R_RegisterModel( "models/players/supersoldier/armor/dam_lftfoot2.md3" ); + cgs.media.superArmor[32] = trap_R_RegisterModel( "models/players/supersoldier/armor/dam_rtfoot2.md3" ); + cgs.media.superArmor[33] = trap_R_RegisterModel( "models/players/supersoldier/armor/dam_lftuparm2.md3" ); + cgs.media.superArmor[44] = trap_R_RegisterModel( "models/players/supersoldier/armor/dam_rtuparm2.md3" ); + cgs.media.superArmor[45] = trap_R_RegisterModel( "models/players/supersoldier/armor/dam_waist2.md3" ); + + cgs.media.superArmor[46] = 0; + cgs.media.superArmor[47] = 0; +/* +super has that proto doesn't... + +dam_chest3 attached to tag_chest + +dam_lftfoot1 +dam_lftfoot2 +nodam_lftfoot attached to tag_footleft + +dam_rtfoot1 +dam_rtfoot2 +nodam_rtfoot attached to tag_footright + +dam_lftuparm1 +dam_lftuparm2 +nodam_lftuparm attached to tag_sholeft + +dam_rtuparm1 +dam_rtuparm2 +nodam_rtuparm attached to tag_shoright + +dam_waist1 +dam_waist2 +nodam_waist attached to tag_torso + +nodam_lftknee attached to tag_calfleft + +nodam_rtknee attached to tag_calfright +*/ + } else if ( !Q_strcasecmp( (char *)modelName, "dark" ) ) { + + cgs.media.superArmorBreak = CG_SoundScriptPrecache( "Supersoldier_loseArmor" ); + + cgs.media.superArmor[0] = trap_R_RegisterModel( "models/players/dark/armor/nodam_chest.md3" ); + cgs.media.superArmor[1] = trap_R_RegisterModel( "models/players/dark/armor/nodam_lftcalf.md3" ); + cgs.media.superArmor[2] = trap_R_RegisterModel( "models/players/dark/armor/nodam_lftforarm.md3" ); + cgs.media.superArmor[3] = trap_R_RegisterModel( "models/players/dark/armor/nodam_lftshoulder.md3" ); + cgs.media.superArmor[4] = trap_R_RegisterModel( "models/players/dark/armor/nodam_lftthigh.md3" ); + cgs.media.superArmor[5] = trap_R_RegisterModel( "models/players/dark/armor/nodam_rtcalf.md3" ); + cgs.media.superArmor[6] = trap_R_RegisterModel( "models/players/dark/armor/nodam_rtforarm.md3" ); + cgs.media.superArmor[7] = trap_R_RegisterModel( "models/players/dark/armor/nodam_rtshoulder.md3" ); + cgs.media.superArmor[8] = trap_R_RegisterModel( "models/players/dark/armor/nodam_rtthigh.md3" ); + + cgs.media.superArmor[9] = trap_R_RegisterModel( "models/players/dark/armor/nodam_lftfoot.md3" ); + cgs.media.superArmor[10] = trap_R_RegisterModel( "models/players/dark/armor/nodam_rtfoot.md3" ); + cgs.media.superArmor[11] = trap_R_RegisterModel( "models/players/dark/armor/nodam_lftuparm.md3" ); + cgs.media.superArmor[12] = trap_R_RegisterModel( "models/players/dark/armor/nodam_rtuparm.md3" ); + cgs.media.superArmor[13] = trap_R_RegisterModel( "models/players/dark/armor/nodam_waist.md3" ); + cgs.media.superArmor[14] = trap_R_RegisterModel( "models/players/dark/armor/nodam_lftknee.md3" ); + cgs.media.superArmor[15] = trap_R_RegisterModel( "models/players/dark/armor/nodam_rtknee.md3" ); + + + + cgs.media.superArmor[16] = trap_R_RegisterModel( "models/players/dark/armor/dam_chest1.md3" ); + cgs.media.superArmor[17] = trap_R_RegisterModel( "models/players/dark/armor/dam_lftcalf1.md3" ); + cgs.media.superArmor[18] = trap_R_RegisterModel( "models/players/dark/armor/dam_lftforarm1.md3" ); + cgs.media.superArmor[19] = trap_R_RegisterModel( "models/players/dark/armor/dam_lftshoulder1.md3" ); + cgs.media.superArmor[20] = trap_R_RegisterModel( "models/players/dark/armor/dam_lftthigh1.md3" ); + cgs.media.superArmor[21] = trap_R_RegisterModel( "models/players/dark/armor/dam_rtcalf1.md3" ); + cgs.media.superArmor[22] = trap_R_RegisterModel( "models/players/dark/armor/dam_rtforarm1.md3" ); + cgs.media.superArmor[23] = trap_R_RegisterModel( "models/players/dark/armor/dam_rtshoulder1.md3" ); + cgs.media.superArmor[24] = trap_R_RegisterModel( "models/players/dark/armor/dam_rtthigh1.md3" ); + + cgs.media.superArmor[25] = trap_R_RegisterModel( "models/players/dark/armor/dam_lftfoot1.md3" ); + cgs.media.superArmor[26] = trap_R_RegisterModel( "models/players/dark/armor/dam_rtfoot1.md3" ); + cgs.media.superArmor[27] = trap_R_RegisterModel( "models/players/dark/armor/dam_lftuparm1.md3" ); + cgs.media.superArmor[28] = trap_R_RegisterModel( "models/players/dark/armor/dam_rtuparm1.md3" ); + cgs.media.superArmor[29] = trap_R_RegisterModel( "models/players/dark/armor/dam_waist1.md3" ); + + cgs.media.superArmor[30] = 0; + cgs.media.superArmor[31] = 0; + + + cgs.media.superArmor[32] = trap_R_RegisterModel( "models/players/dark/armor/dam_chest2.md3" ); + cgs.media.superArmor[33] = trap_R_RegisterModel( "models/players/dark/armor/dam_lftcalf2.md3" ); + cgs.media.superArmor[34] = trap_R_RegisterModel( "models/players/dark/armor/dam_lftforarm2.md3" ); + cgs.media.superArmor[35] = trap_R_RegisterModel( "models/players/dark/armor/dam_lftshoulder2.md3" ); + cgs.media.superArmor[36] = trap_R_RegisterModel( "models/players/dark/armor/dam_lftthigh2.md3" ); + cgs.media.superArmor[37] = trap_R_RegisterModel( "models/players/dark/armor/dam_rtcalf2.md3" ); + cgs.media.superArmor[38] = trap_R_RegisterModel( "models/players/dark/armor/dam_rtforarm2.md3" ); + cgs.media.superArmor[39] = trap_R_RegisterModel( "models/players/dark/armor/dam_rtshoulder2.md3" ); + cgs.media.superArmor[30] = trap_R_RegisterModel( "models/players/dark/armor/dam_rtthigh2.md3" ); + + cgs.media.superArmor[31] = trap_R_RegisterModel( "models/players/dark/armor/dam_lftfoot2.md3" ); + cgs.media.superArmor[32] = trap_R_RegisterModel( "models/players/dark/armor/dam_rtfoot2.md3" ); + cgs.media.superArmor[33] = trap_R_RegisterModel( "models/players/dark/armor/dam_lftuparm2.md3" ); + cgs.media.superArmor[44] = trap_R_RegisterModel( "models/players/dark/armor/dam_rtuparm2.md3" ); + cgs.media.superArmor[45] = trap_R_RegisterModel( "models/players/dark/armor/dam_waist2.md3" ); + + cgs.media.superArmor[46] = 0; + cgs.media.superArmor[47] = 0; + + } else if ( !Q_strcasecmp( (char *)modelName, "heinrich" ) ) { + + cgs.media.heinrichArmorBreak = CG_SoundScriptPrecache( "Heinrich_loseArmor" ); + + // RF, these are also used but supersoldier "spirits" in end map + cgs.media.zombieSpiritLoopSound = trap_S_RegisterSound( "sound/zombie/attack/spirit_loop.wav" ); + cgs.media.ssSpiritSkullModel = trap_R_RegisterModel( "models/players/supersoldier/ssghost.md3" ); + + cgs.media.zombieSpiritTrailShader = trap_R_RegisterShader( "zombieSpiritTrail" ); + cgs.media.zombieSpiritLoopSound = trap_S_RegisterSound( "sound/zombie/attack/spirit_loop.wav" ); + cgs.media.helgaGaspSound = CG_SoundScriptPrecache( "helgaSpiritGasp" ); + + cgs.media.debrisHitSound = trap_S_RegisterSound( "sound/world/debris_hit.wav" ); + + cgs.media.heinrichArmor[0] = trap_R_RegisterModel( "models/players/heinrich/armor/nodam_chest.md3" ); + cgs.media.heinrichArmor[1] = trap_R_RegisterModel( "models/players/heinrich/armor/nodam_lftcalf.md3" ); + cgs.media.heinrichArmor[2] = trap_R_RegisterModel( "models/players/heinrich/armor/nodam_lftforarm.md3" ); + cgs.media.heinrichArmor[3] = trap_R_RegisterModel( "models/players/heinrich/armor/nodam_lftshoulder.md3" ); + cgs.media.heinrichArmor[4] = trap_R_RegisterModel( "models/players/heinrich/armor/nodam_lftthigh.md3" ); + cgs.media.heinrichArmor[5] = trap_R_RegisterModel( "models/players/heinrich/armor/nodam_rtcalf.md3" ); + cgs.media.heinrichArmor[6] = trap_R_RegisterModel( "models/players/heinrich/armor/nodam_rtforarm.md3" ); + cgs.media.heinrichArmor[7] = trap_R_RegisterModel( "models/players/heinrich/armor/nodam_rtshoulder.md3" ); + cgs.media.heinrichArmor[8] = trap_R_RegisterModel( "models/players/heinrich/armor/nodam_rtthigh.md3" ); + + cgs.media.heinrichArmor[9] = trap_R_RegisterModel( "models/players/heinrich/armor/nodam_lftfoot.md3" ); + cgs.media.heinrichArmor[10] = trap_R_RegisterModel( "models/players/heinrich/armor/nodam_rtfoot.md3" ); + cgs.media.heinrichArmor[11] = trap_R_RegisterModel( "models/players/heinrich/armor/nodam_lftuparm.md3" ); + cgs.media.heinrichArmor[12] = trap_R_RegisterModel( "models/players/heinrich/armor/nodam_rtuparm.md3" ); + cgs.media.heinrichArmor[13] = trap_R_RegisterModel( "models/players/heinrich/armor/nodam_waist.md3" ); + cgs.media.heinrichArmor[14] = trap_R_RegisterModel( "models/players/heinrich/armor/nodam_lftknee.md3" ); + cgs.media.heinrichArmor[15] = trap_R_RegisterModel( "models/players/heinrich/armor/nodam_rtknee.md3" ); + + cgs.media.heinrichArmor[16] = trap_R_RegisterModel( "models/players/heinrich/armor/nodam_lftelbow.md3" ); + cgs.media.heinrichArmor[17] = trap_R_RegisterModel( "models/players/heinrich/armor/nodam_rtelbow.md3" ); + cgs.media.heinrichArmor[18] = trap_R_RegisterModel( "models/players/heinrich/armor/nodam_lfthip.md3" ); + cgs.media.heinrichArmor[19] = trap_R_RegisterModel( "models/players/heinrich/armor/nodam_rthip.md3" ); + cgs.media.heinrichArmor[20] = trap_R_RegisterModel( "models/players/heinrich/armor/nodam_lftshin.md3" ); + cgs.media.heinrichArmor[21] = trap_R_RegisterModel( "models/players/heinrich/armor/nodam_rtshin.md3" ); + + + cgs.media.heinrichArmor[22] = trap_R_RegisterModel( "models/players/heinrich/armor/dam_chest1.md3" ); + cgs.media.heinrichArmor[23] = trap_R_RegisterModel( "models/players/heinrich/armor/dam_lftcalf1.md3" ); + cgs.media.heinrichArmor[24] = trap_R_RegisterModel( "models/players/heinrich/armor/dam_lftforarm1.md3" ); + cgs.media.heinrichArmor[25] = trap_R_RegisterModel( "models/players/heinrich/armor/dam_lftshoulder1.md3" ); + cgs.media.heinrichArmor[26] = trap_R_RegisterModel( "models/players/heinrich/armor/dam_lftthigh1.md3" ); + cgs.media.heinrichArmor[27] = trap_R_RegisterModel( "models/players/heinrich/armor/dam_rtcalf1.md3" ); + cgs.media.heinrichArmor[28] = trap_R_RegisterModel( "models/players/heinrich/armor/dam_rtforarm1.md3" ); + cgs.media.heinrichArmor[29] = trap_R_RegisterModel( "models/players/heinrich/armor/dam_rtshoulder1.md3" ); + cgs.media.heinrichArmor[30] = trap_R_RegisterModel( "models/players/heinrich/armor/dam_rtthigh1.md3" ); + + cgs.media.heinrichArmor[31] = trap_R_RegisterModel( "models/players/heinrich/armor/dam_lftfoot1.md3" ); + cgs.media.heinrichArmor[32] = trap_R_RegisterModel( "models/players/heinrich/armor/dam_rtfoot1.md3" ); + cgs.media.heinrichArmor[33] = trap_R_RegisterModel( "models/players/heinrich/armor/dam_lftuparm1.md3" ); + cgs.media.heinrichArmor[34] = trap_R_RegisterModel( "models/players/heinrich/armor/dam_rtuparm1.md3" ); + cgs.media.heinrichArmor[35] = trap_R_RegisterModel( "models/players/heinrich/armor/dam_waist1.md3" ); + cgs.media.heinrichArmor[36] = trap_R_RegisterModel( "models/players/heinrich/armor/dam_lftknee1.md3" ); + cgs.media.heinrichArmor[37] = trap_R_RegisterModel( "models/players/heinrich/armor/dam_rtknee1.md3" ); + + cgs.media.heinrichArmor[38] = trap_R_RegisterModel( "models/players/heinrich/armor/dam_lftelbow1.md3" ); + cgs.media.heinrichArmor[39] = trap_R_RegisterModel( "models/players/heinrich/armor/dam_rtelbow1.md3" ); + cgs.media.heinrichArmor[40] = trap_R_RegisterModel( "models/players/heinrich/armor/dam_lfthip1.md3" ); + cgs.media.heinrichArmor[41] = trap_R_RegisterModel( "models/players/heinrich/armor/dam_rthip1.md3" ); + cgs.media.heinrichArmor[42] = 0; + cgs.media.heinrichArmor[43] = 0; + + + cgs.media.heinrichArmor[44] = trap_R_RegisterModel( "models/players/heinrich/armor/dam_chest2.md3" ); + cgs.media.heinrichArmor[45] = trap_R_RegisterModel( "models/players/heinrich/armor/dam_lftcalf2.md3" ); + cgs.media.heinrichArmor[46] = trap_R_RegisterModel( "models/players/heinrich/armor/dam_lftforarm2.md3" ); + cgs.media.heinrichArmor[47] = trap_R_RegisterModel( "models/players/heinrich/armor/dam_lftshoulder2.md3" ); + cgs.media.heinrichArmor[48] = trap_R_RegisterModel( "models/players/heinrich/armor/dam_lftthigh2.md3" ); + cgs.media.heinrichArmor[49] = trap_R_RegisterModel( "models/players/heinrich/armor/dam_rtcalf2.md3" ); + cgs.media.heinrichArmor[50] = trap_R_RegisterModel( "models/players/heinrich/armor/dam_rtforarm2.md3" ); + cgs.media.heinrichArmor[51] = trap_R_RegisterModel( "models/players/heinrich/armor/dam_rtshoulder2.md3" ); + cgs.media.heinrichArmor[52] = trap_R_RegisterModel( "models/players/heinrich/armor/dam_rtthigh2.md3" ); + + cgs.media.heinrichArmor[43] = trap_R_RegisterModel( "models/players/heinrich/armor/dam_lftfoot2.md3" ); + cgs.media.heinrichArmor[54] = trap_R_RegisterModel( "models/players/heinrich/armor/dam_rtfoot2.md3" ); + cgs.media.heinrichArmor[55] = trap_R_RegisterModel( "models/players/heinrich/armor/dam_lftuparm2.md3" ); + cgs.media.heinrichArmor[56] = trap_R_RegisterModel( "models/players/heinrich/armor/dam_rtuparm2.md3" ); + cgs.media.heinrichArmor[57] = trap_R_RegisterModel( "models/players/heinrich/armor/dam_waist2.md3" ); + cgs.media.heinrichArmor[58] = trap_R_RegisterModel( "models/players/heinrich/armor/dam_lftknee2.md3" ); + cgs.media.heinrichArmor[59] = trap_R_RegisterModel( "models/players/heinrich/armor/dam_rtknee2.md3" ); + + cgs.media.heinrichArmor[60] = trap_R_RegisterModel( "models/players/heinrich/armor/dam_lftelbow2.md3" ); + cgs.media.heinrichArmor[61] = trap_R_RegisterModel( "models/players/heinrich/armor/dam_rtelbow2.md3" ); + cgs.media.heinrichArmor[62] = trap_R_RegisterModel( "models/players/heinrich/armor/dam_lfthip2.md3" ); + cgs.media.heinrichArmor[63] = trap_R_RegisterModel( "models/players/heinrich/armor/dam_rthip2.md3" ); + cgs.media.heinrichArmor[64] = 0; + cgs.media.heinrichArmor[65] = 0; + +/* +heinrich has that ss doesn't... + +dam_lftelbow +dam_lftelbow1 +dam_lftelbow2 attached to tag_sholeft + +nodam_rtelbow +dam_rtelbow1 +dam_rtelbow2 attached to tag_shoright + +nodam_lfthip +dam_lfthip1 +dam_lfthip2 +dam_lfthip3 attached to tag_legleft + +nodam_rthip +dam_rthip1 +dam_rthip2 +dam_rthip3 attached to tag_legright + +nodam_lftshin attached to tag_calfleft + +nodam_rtshin attached to tag_calfright +*/ + } +//----(SA) end + +// end special AI model loading + + + // -------- FOOTSTEP SOUNDS --------- + // load model specific footsteps + // FIXME: this should be moved over to per model scripts or animation scripting + if ( !Q_strcasecmp( (char *)modelName, "eliteguard" ) ) { + // ELITEGUARD + + for ( i = 0; i < 4; i++ ) { + Com_sprintf( name, sizeof( name ), "sound/player/footsteps/eliteguard/step%i.wav", i + 1 ); + cgs.media.footsteps[FOOTSTEP_ELITE_STEP][i] = trap_S_RegisterSound( name ); + + Com_sprintf( name, sizeof( name ), "sound/player/footsteps/eliteguard/clank%i.wav", i + 1 ); + cgs.media.footsteps[FOOTSTEP_ELITE_METAL][i] = trap_S_RegisterSound( name ); + +// Com_sprintf (name, sizeof(name), "sound/player/footsteps/eliteguard/roof%i.wav", i+1); +// cgs.media.footsteps[FOOTSTEP_ELITE_ROOF][i] = trap_S_RegisterSound (name); + + Com_sprintf( name, sizeof( name ), "sound/player/footsteps/eliteguard/wood%i.wav", i + 1 ); + cgs.media.footsteps[FOOTSTEP_ELITE_WOOD][i] = trap_S_RegisterSound( name ); + + Com_sprintf( name, sizeof( name ), "sound/player/footsteps/eliteguard/gravel%i.wav", i + 1 ); + cgs.media.footsteps[FOOTSTEP_ELITE_GRAVEL][i] = trap_S_RegisterSound( name ); + } + } else if ( !Q_strcasecmp( (char *)modelName, "protosoldier" ) ) { + // ProtoSoldier + for ( i = 0; i < 4; i++ ) { + Com_sprintf( name, sizeof( name ), "sound/player/footsteps/protosoldier/step%i.wav", i + 1 ); + cgs.media.footsteps[FOOTSTEP_PROTOSOLDIER_STEP][i] = trap_S_RegisterSound( name ); + + Com_sprintf( name, sizeof( name ), "sound/player/footsteps/protosoldier/clank%i.wav", i + 1 ); + cgs.media.footsteps[FOOTSTEP_PROTOSOLDIER_METAL][i] = trap_S_RegisterSound( name ); + + Com_sprintf( name, sizeof( name ), "sound/player/footsteps/protosoldier/grass%i.wav", i + 1 ); + cgs.media.footsteps[FOOTSTEP_PROTOSOLDIER_GRASS][i] = trap_S_RegisterSound( name ); + + Com_sprintf( name, sizeof( name ), "sound/player/footsteps/protosoldier/gravel%i.wav", i + 1 ); + cgs.media.footsteps[FOOTSTEP_PROTOSOLDIER_GRAVEL][i] = trap_S_RegisterSound( name ); + + Com_sprintf( name, sizeof( name ), "sound/player/footsteps/protosoldier/wood%i.wav", i + 1 ); + cgs.media.footsteps[FOOTSTEP_PROTOSOLDIER_WOOD][i] = trap_S_RegisterSound( name ); + } + } else if ( !Q_strcasecmp( (char *)modelName, "supersoldier" ) ) { + // SuperSoldier/HEINRICH + for ( i = 0; i < 4; i++ ) { + Com_sprintf( name, sizeof( name ), "sound/player/footsteps/supersoldier/step%i.wav", i + 1 ); + cgs.media.footsteps[FOOTSTEP_SUPERSOLDIER_STEP][i] = trap_S_RegisterSound( name ); + + Com_sprintf( name, sizeof( name ), "sound/player/footsteps/supersoldier/clank%i.wav", i + 1 ); + cgs.media.footsteps[FOOTSTEP_SUPERSOLDIER_METAL][i] = trap_S_RegisterSound( name ); + + Com_sprintf( name, sizeof( name ), "sound/player/footsteps/supersoldier/grass%i.wav", i + 1 ); + cgs.media.footsteps[FOOTSTEP_SUPERSOLDIER_GRASS][i] = trap_S_RegisterSound( name ); + + Com_sprintf( name, sizeof( name ), "sound/player/footsteps/supersoldier/gravel%i.wav", i + 1 ); + cgs.media.footsteps[FOOTSTEP_SUPERSOLDIER_GRAVEL][i] = trap_S_RegisterSound( name ); + + Com_sprintf( name, sizeof( name ), "sound/player/footsteps/supersoldier/wood%i.wav", i + 1 ); + cgs.media.footsteps[FOOTSTEP_SUPERSOLDIER_WOOD][i] = trap_S_RegisterSound( name ); + } + } + // Heinrich special + else if ( !Q_strcasecmp( (char *)modelName, "heinrich" ) ) { + // SuperSoldier/HEINRICH + for ( i = 0; i < 4; i++ ) { + Com_sprintf( name, sizeof( name ), "sound/player/footsteps/heinrich/step%i.wav", i + 1 ); + cgs.media.footsteps[FOOTSTEP_HEINRICH][i] = trap_S_RegisterSound( name ); + } + } else if ( !Q_strcasecmp( (char *)modelName, "loper" ) ) { + // Loper + for ( i = 0; i < 4; i++ ) { + Com_sprintf( name, sizeof( name ), "sound/player/footsteps/loper/clank%i.wav", i + 1 ); + cgs.media.footsteps[FOOTSTEP_LOPER_METAL][i] = trap_S_RegisterSound( name ); + + Com_sprintf( name, sizeof( name ), "sound/player/footsteps/loper/step%i.wav", i + 1 ); + cgs.media.footsteps[FOOTSTEP_LOPER_STEP][i] = trap_S_RegisterSound( name ); + + Com_sprintf( name, sizeof( name ), "sound/player/footsteps/loper/wood%i.wav", i + 1 ); + cgs.media.footsteps[FOOTSTEP_LOPER_WOOD][i] = trap_S_RegisterSound( name ); + } + } else if ( !Q_strcasecmp( (char *)modelName, "zombie" ) ) { + // Zombie + for ( i = 0; i < 4; i++ ) { + Com_sprintf( name, sizeof( name ), "sound/player/footsteps/zombie/gravel%i.wav", i + 1 ); + cgs.media.footsteps[FOOTSTEP_ZOMBIE_GRAVEL][i] = trap_S_RegisterSound( name ); + + Com_sprintf( name, sizeof( name ), "sound/player/footsteps/zombie/step%i.wav", i + 1 ); + cgs.media.footsteps[FOOTSTEP_ZOMBIE_STEP][i] = trap_S_RegisterSound( name ); + + Com_sprintf( name, sizeof( name ), "sound/player/footsteps/zombie/wood%i.wav", i + 1 ); + cgs.media.footsteps[FOOTSTEP_ZOMBIE_WOOD][i] = trap_S_RegisterSound( name ); + } + } else if ( !Q_strcasecmp( (char *)modelName, "beast" ) ) { + // Helga Boss + cgs.media.footsteps[FOOTSTEP_BEAST][0] = CG_SoundScriptPrecache( "beastStep" ); // just precache the sound script + } + } + + // whoops! this stuff would never get set if it found one existing already!! + if ( !Q_strcasecmp( (char *)modelName, "loper" ) ) { + ci->partModels[8] = trap_R_RegisterModel( va( "models/players/%s/spinner.md3", modelName ) ); + } else if ( !Q_strcasecmp( (char *)modelName, "sealoper" ) ) { + ci->partModels[8] = trap_R_RegisterModel( va( "models/players/%s/spinner.md3", modelName ) ); + } + + + return qtrue; +} + +/* +============== +CG_RegisterClientHeadname +============== +*/ +static qboolean CG_RegisterClientHeadname( clientInfo_t *ci, const char *modelName, const char *hSkinName ) { + char namefromskin[MAX_QPATH]; + char filename[MAX_QPATH]; + int i; + + if ( !CG_RegisterClientHeadSkin( ci, modelName, hSkinName ) ) { + Com_Printf( "Failed to load head skin file: %s/head_%s.skin\n", modelName, hSkinName ); //----(SA) + return qfalse; + } + + if ( trap_R_GetSkinModel( ci->headSkin, "md3_part", &namefromskin[0] ) ) { + Com_sprintf( filename, sizeof( filename ), "models/players/%s/%s", modelName, namefromskin ); + } else { + Com_sprintf( filename, sizeof( filename ), "models/players/%s/head.md3", modelName ); + } + + ci->headModel = trap_R_RegisterModel( filename ); + if ( !ci->headModel ) { + Com_Printf( "Failed to load head model file %s\n", filename ); //----(SA) + return qfalse; + } + + if ( trap_R_GetSkinModel( ci->headSkin, "md3_hat", &namefromskin[0] ) ) { + CG_RegisterAcc( ci, va( "models/players/%s", modelName ), namefromskin, &ci->accModels[ACC_HAT], &ci->accSkins[ACC_HAT] ); + } + + for ( i = 0; i < ACC_NUM_MOUTH - 1; i++ ) { + if ( trap_R_GetSkinModel( ci->headSkin, va( "md3_hat%d", 2 + i ), &namefromskin[0] ) ) { + CG_RegisterAcc( ci, va( "models/players/%s", modelName ), namefromskin, &ci->accModels[ACC_MOUTH2 + i], &ci->accSkins[ACC_MOUTH2 + i] ); + } + } + + return qtrue; +} +/* +==================== +CG_ColorFromString +==================== +*/ +static void CG_ColorFromString( const char *v, vec3_t color ) { + int val; + + VectorClear( color ); + + val = atoi( v ); + + if ( val < 1 || val > 7 ) { + VectorSet( color, 1, 1, 1 ); + return; + } + + if ( val & 1 ) { + color[2] = 1.0f; + } + if ( val & 2 ) { + color[1] = 1.0f; + } + if ( val & 4 ) { + color[0] = 1.0f; + } +} + +/* +=================== +CG_LoadClientInfo + +Load it now, taking the disk hits. +This will usually be deferred to a safe time +=================== +*/ +void CG_LoadClientInfo( clientInfo_t *ci ) { + const char *dir, *fallback; + int i; + const char *s; + int clientNum; + int headfail = 0; + char filename[MAX_QPATH]; + +//----(SA) modified this for head separation + + // load the head first (since if the head loads but there is a problem with something in the lower + // body, you will want to default the model back to a default and want the head to match) + // + + if ( !CG_RegisterClientHeadname( ci, ci->modelName, ci->hSkinName ) ) { + if ( cg_buildScript.integer ) { + CG_Error( "CG_RegisterClientHeadname( %s, %s ) failed. setting default", ci->modelName, ci->hSkinName ); + } + + // fall back to default head + if ( !CG_RegisterClientHeadname( ci, ci->modelName, "default" ) ) { + headfail = 1; + if ( cg_buildScript.integer ) { + CG_Error( "head model/skin (%s/default) failed to register", ci->modelName ); //----(SA) + } + } + } + + if ( headfail || !CG_RegisterClientModelname( ci, ci->modelName, ci->skinName ) ) { + if ( cg_buildScript.integer ) { + CG_Error( "CG_RegisterClientModelname( %s, %s ) failed", ci->modelName, ci->skinName ); + } + + // fall back + if ( cgs.gametype >= GT_TEAM ) { + // keep skin name but set default model + if ( !CG_RegisterClientModelname( ci, DEFAULT_MODEL, ci->skinName ) ) { + CG_Error( "DEFAULT_MODEL / skin (%s/%s) failed to register", DEFAULT_MODEL, ci->skinName ); + } + } else if ( cgs.gametype == GT_SINGLE_PLAYER && !headfail ) { + // try to keep the model but default the skin (so you can tell bad guys from good) + if ( !CG_RegisterClientModelname( ci, ci->modelName, "default" ) ) { + CG_Error( "DEFAULT_MODEL (%s/default) failed to register", ci->modelName ); + } + } else { + // go totally default + if ( !CG_RegisterClientModelname( ci, DEFAULT_MODEL, "default" ) ) { + CG_Error( "DEFAULT_MODEL (%s/default) failed to register", DEFAULT_MODEL ); + } + + // fall back to default head + if ( !CG_RegisterClientHeadname( ci, DEFAULT_MODEL, "default" ) ) { + CG_Error( "model/ DEFAULT_HEAD / skin (%s/default) failed to register", DEFAULT_HEAD ); + } + + } + + } + +//----(SA) end + + // sounds + dir = ci->modelName; + fallback = DEFAULT_MODEL; + + for ( i = 0 ; i < MAX_CUSTOM_SOUNDS ; i++ ) { + s = cg_customSoundNames[i]; + if ( !s ) { + break; + } + ci->sounds[i] = trap_S_RegisterSound( va( "sound/player/%s/%s", dir, s + 1 ) ); + if ( !ci->sounds[i] ) { + ci->sounds[i] = trap_S_RegisterSound( va( "sound/player/%s/%s", fallback, s + 1 ) ); + } + } + + // load the gibs + Com_sprintf( filename, sizeof( filename ), "models/players/%s/gibs.cfg", dir ); + if ( !CG_ParseGibModels( filename, ci ) ) { + // n/mind.. gib code will automatically fall back to old gibs + } + + ci->deferred = qfalse; + + // reset any existing players and bodies, because they might be in bad + // frames for this new model + clientNum = ci - cgs.clientinfo; + for ( i = 0 ; i < MAX_GENTITIES ; i++ ) { + if ( cg_entities[i].currentState.clientNum == clientNum + && cg_entities[i].currentState.eType == ET_PLAYER ) { + CG_ResetPlayerEntity( &cg_entities[i] ); + } + } +} + +/* +====================== +CG_CopyClientInfoModel +====================== +*/ +static void CG_CopyClientInfoModel( clientInfo_t *from, clientInfo_t *to ) { + VectorCopy( from->playermodelScale, to->playermodelScale ); + + to->legsModel = from->legsModel; + to->legsSkin = from->legsSkin; + to->torsoModel = from->torsoModel; + to->torsoSkin = from->torsoSkin; + to->headModel = from->headModel; + to->headSkin = from->headSkin; + to->isSkeletal = from->isSkeletal; + to->modelIcon = from->modelIcon; + +//----(SA) + memcpy( to->accModels, from->accModels, sizeof( to->accModels ) ); + memcpy( to->accSkins, from->accSkins, sizeof( to->accSkins ) ); + memcpy( to->partModels, from->partModels, sizeof( to->partModels ) ); +// memcpy( to->partSkins, from->partSkins, sizeof( to->partSkins ) ); +//----(SA) end + + memcpy( to->sounds, from->sounds, sizeof( to->sounds ) ); + + // Ridah + memcpy( to->gibModels, from->gibModels, sizeof( to->gibModels ) ); + // done. + + // copy the modelInfo + to->modelInfo = from->modelInfo; + cgs.animScriptData.clientModels[ to->clientNum ] = cgs.animScriptData.clientModels[ from->clientNum ]; + +} + +/* +====================== +CG_ScanForExistingClientInfo +====================== +*/ +static qboolean CG_ScanForExistingClientInfo( clientInfo_t *ci ) { + int i; + clientInfo_t *match; + + for ( i = 0 ; i < cgs.maxclients ; i++ ) { + match = &cgs.clientinfo[ i ]; + if ( !match->infoValid ) { + continue; + } + if ( match->deferred ) { + continue; + } +//----(SA) added checks for same head. FIXME: soon this will be more efficient than just looking for a complete character (body/head) match. + if ( + !Q_stricmp( ci->modelName, match->modelName ) + && !Q_stricmp( ci->skinName, match->skinName ) + && !Q_stricmp( ci->hSkinName, match->hSkinName ) + ) { + +//----(SA) done + + // this clientinfo is identical, so use it's handles + + ci->deferred = qfalse; + + CG_CopyClientInfoModel( match, ci ); + + return qtrue; + } + } + + // nothing matches, so defer the load + return qfalse; +} + +/* +====================== +CG_SetDeferredClientInfo + +We aren't going to load it now, so grab some other +client's info to use until we have some spare time. +====================== +*/ +static void CG_SetDeferredClientInfo( clientInfo_t *ci ) { + int i; + clientInfo_t *match; + + // if we are in teamplay, only grab a model if the skin is correct + if ( cgs.gametype >= GT_TEAM ) { + for ( i = 0 ; i < cgs.maxclients ; i++ ) { + match = &cgs.clientinfo[ i ]; + if ( !match->infoValid ) { + continue; + } + if ( Q_stricmp( ci->skinName, match->skinName ) ) { + continue; + } + ci->deferred = qtrue; + CG_CopyClientInfoModel( match, ci ); + return; + } + + // load the full model, because we don't ever want to show + // an improper team skin. This will cause a hitch for the first + // player, when the second enters. Combat shouldn't be going on + // yet, so it shouldn't matter + CG_LoadClientInfo( ci ); + return; + } + + // find the first valid clientinfo and grab its stuff + for ( i = 0 ; i < cgs.maxclients ; i++ ) { + match = &cgs.clientinfo[ i ]; + if ( !match->infoValid ) { + continue; + } + + ci->deferred = qtrue; + CG_CopyClientInfoModel( match, ci ); + return; + } + + // we should never get here... + CG_Printf( "CG_SetDeferredClientInfo: no valid clients!\n" ); + + CG_LoadClientInfo( ci ); +} + + +/* +====================== +CG_NewClientInfo +====================== +*/ +void CG_NewClientInfo( int clientNum ) { + clientInfo_t *ci; + clientInfo_t newInfo; + const char *configstring; + const char *v; + char *slash; + + ci = &cgs.clientinfo[clientNum]; + + configstring = CG_ConfigString( clientNum + CS_PLAYERS ); + if ( !configstring[0] ) { + memset( ci, 0, sizeof( *ci ) ); + return; // player just left + } + + // build into a temp buffer so the defer checks can use + // the old value + memset( &newInfo, 0, sizeof( newInfo ) ); + + newInfo.clientNum = clientNum; + + // isolate the player's name + v = Info_ValueForKey( configstring, "n" ); + Q_strncpyz( newInfo.name, v, sizeof( newInfo.name ) ); + + // colors + v = Info_ValueForKey( configstring, "c1" ); + CG_ColorFromString( v, newInfo.color ); + + // bot skill + v = Info_ValueForKey( configstring, "skill" ); + newInfo.botSkill = atoi( v ); + + // handicap + v = Info_ValueForKey( configstring, "hc" ); + newInfo.handicap = atoi( v ); + + // wins + v = Info_ValueForKey( configstring, "w" ); + newInfo.wins = atoi( v ); + + // losses + v = Info_ValueForKey( configstring, "l" ); + newInfo.losses = atoi( v ); + + // team + v = Info_ValueForKey( configstring, "t" ); + newInfo.team = atoi( v ); + +//----(SA) modified this for head separation + +// (SA) note to Ryan: The problem I see with having the model set for cg_forceModel in the game (g_forcemodel) +// is that it was initally there for a performance/fairness thing so you can connect to a +// server and not use other players goofy models or whatever. We should still have some simple +// client-side thing for defaulting all models to one particular player model or something. (did that make sense?) + + // head + v = Info_ValueForKey( configstring, "head" ); +/* RF, disabled this, not needed anymore + if ( cg_forceModel.integer ) + { + char modelStr[MAX_QPATH]; + + // forcemodel makes everyone use a single model + // to prevent load hitches + + trap_Cvar_VariableStringBuffer( "head", modelStr, sizeof( modelStr ) ); + Q_strncpyz( newInfo.hSkinName, modelStr, sizeof( newInfo.hSkinName ) ); + } + else { +*/ + Q_strncpyz( newInfo.hSkinName, v, sizeof( newInfo.hSkinName ) ); +// } + +//----(SA) modified this for head separation + + // model + v = Info_ValueForKey( configstring, "model" ); +/* RF, disabled this, not needed anymore + if ( cg_forceModel.integer ) { + // forcemodel makes everyone use a single model + // to prevent load hitches + char modelStr[MAX_QPATH]; + char *skin; + + trap_Cvar_VariableStringBuffer( "model", modelStr, sizeof( modelStr ) ); + if ( ( skin = strchr( modelStr, '/' ) ) == NULL) { + skin = "default"; + } else { + *skin++ = 0; + } + + Q_strncpyz( newInfo.skinName, skin, sizeof( newInfo.skinName ) ); + Q_strncpyz( newInfo.modelName, modelStr, sizeof( newInfo.modelName ) ); + + if ( cgs.gametype >= GT_TEAM ) { + // keep skin name + slash = strchr( v, '/' ); + if ( slash ) { + Q_strncpyz( newInfo.skinName, slash + 1, sizeof( newInfo.skinName ) ); + } + } + } else { +*/ + Q_strncpyz( newInfo.modelName, v, sizeof( newInfo.modelName ) ); + + slash = strchr( newInfo.modelName, '/' ); + if ( !slash ) { + // modelName did not include a skin name + Q_strncpyz( newInfo.skinName, "default", sizeof( newInfo.skinName ) ); + } else { + Q_strncpyz( newInfo.skinName, slash + 1, sizeof( newInfo.skinName ) ); + // truncate modelName + *slash = 0; + } +// } + + //----(SA) modify \/ to differentiate for head models/skins as well + + + // scan for an existing clientinfo that matches this modelname + // so we can avoid loading checks if possible + if ( !CG_ScanForExistingClientInfo( &newInfo ) ) { + qboolean forceDefer; + + // RF, disabled this, we can't have this happening in Wolf. If there is not enough memory, + // then we have a leak or havent allocated enough hunk + forceDefer = qfalse; + +// forceDefer = trap_MemoryRemaining() < 4000000; + + // if we are defering loads, just have it pick the first valid +// if ( forceDefer || ( cg_deferPlayers.integer && !cg_buildScript.integer && !cg.loading ) ) { + + // very temporary! do not defer any players just yet + // we need to get ai's to be non-deferred players before we can + // do this (SA) + if ( forceDefer ) { + // keep whatever they had if it won't violate team skins + if ( ci->infoValid && + ( cgs.gametype < GT_TEAM || !Q_stricmp( newInfo.skinName, ci->skinName ) ) ) { + CG_CopyClientInfoModel( ci, &newInfo ); + newInfo.deferred = qtrue; + } else { + // use whatever is available + CG_SetDeferredClientInfo( &newInfo ); + } + // if we are low on memory, leave them with this model + if ( forceDefer ) { + CG_Printf( "Memory is low. Using deferred model.\n" ); + newInfo.deferred = qfalse; + } + } else { + CG_LoadClientInfo( &newInfo ); + } + } + + // replace whatever was there with the new one + newInfo.infoValid = qtrue; + *ci = newInfo; +} + + + +/* +====================== +CG_LoadDeferredPlayers + +Called each frame when a player is dead +and the scoreboard is up +so deferred players can be loaded +====================== +*/ +void CG_LoadDeferredPlayers( void ) { + int i; + clientInfo_t *ci; + + // scan for a deferred player to load + for ( i = 0, ci = cgs.clientinfo ; i < cgs.maxclients ; i++, ci++ ) { + if ( ci->infoValid && ci->deferred ) { + // if we are low on memory, leave it deferred + if ( trap_MemoryRemaining() < 4000000 ) { + CG_Printf( "Memory is low. Using deferred model.\n" ); + ci->deferred = qfalse; + continue; + } + CG_LoadClientInfo( ci ); + } + } +} + +/* +============================================================================= + +PLAYER ANIMATION + +============================================================================= +*/ + + +/* +=============== +CG_SetLerpFrameAnimation + +may include ANIM_TOGGLEBIT +=============== +*/ +static void CG_SetLerpFrameAnimation( clientInfo_t *ci, lerpFrame_t *lf, int newAnimation ) { + animation_t *anim; + + if ( !ci->modelInfo ) { + return; + } + + lf->animationNumber = newAnimation; + newAnimation &= ~ANIM_TOGGLEBIT; + + if ( newAnimation < 0 || newAnimation >= ci->modelInfo->numAnimations ) { + CG_Error( "Bad animation number (CG_SLFA): %i", newAnimation ); + } + + anim = &ci->modelInfo->animations[ newAnimation ]; + + lf->animation = anim; + lf->animationTime = lf->frameTime + anim->initialLerp; + + if ( cg_debugAnim.integer == 1 ) { // DHM - Nerve :: extra debug info + CG_Printf( "Anim: %i, %s\n", newAnimation, ci->modelInfo->animations[newAnimation].name ); + } +} + +/* +=============== +CG_RunLerpFrame + +Sets cg.snap, cg.oldFrame, and cg.backlerp +cg.time should be between oldFrameTime and frameTime after exit +=============== +*/ +void CG_RunLerpFrame( clientInfo_t *ci, lerpFrame_t *lf, int newAnimation, float speedScale ) { + int f; + animation_t *anim; + + // debugging tool to get no animations + if ( cg_animSpeed.integer == 0 ) { + lf->oldFrame = lf->frame = lf->backlerp = 0; + return; + } + + // see if the animation sequence is switching + if ( ci && ( newAnimation != lf->animationNumber || !lf->animation ) ) { //----(SA) modified + CG_SetLerpFrameAnimation( ci, lf, newAnimation ); + } + + // if we have passed the current frame, move it to + // oldFrame and calculate a new frame + if ( cg.time >= lf->frameTime ) { + lf->oldFrame = lf->frame; + lf->oldFrameTime = lf->frameTime; + + // get the next frame based on the animation + anim = lf->animation; + if ( !anim->frameLerp ) { + return; // shouldn't happen + } + if ( cg.time < lf->animationTime ) { + lf->frameTime = lf->animationTime; // initial lerp + } else { + lf->frameTime = lf->oldFrameTime + anim->frameLerp; + } + f = ( lf->frameTime - lf->animationTime ) / anim->frameLerp; + f *= speedScale; // adjust for haste, etc + if ( f >= anim->numFrames ) { + f -= anim->numFrames; + if ( anim->loopFrames ) { + f %= anim->loopFrames; + f += anim->numFrames - anim->loopFrames; + } else { + f = anim->numFrames - 1; + // the animation is stuck at the end, so it + // can immediately transition to another sequence + lf->frameTime = cg.time; + } + } + lf->frame = anim->firstFrame + f; + if ( cg.time > lf->frameTime ) { + lf->frameTime = cg.time; + if ( cg_debugAnim.integer ) { + CG_Printf( "Clamp lf->frameTime\n" ); + } + } + } + + if ( lf->frameTime > cg.time + 200 ) { + lf->frameTime = cg.time; + } + + if ( lf->oldFrameTime > cg.time ) { + lf->oldFrameTime = cg.time; + } + // calculate current lerp value + if ( lf->frameTime == lf->oldFrameTime ) { + lf->backlerp = 0; + } else { + lf->backlerp = 1.0 - (float)( cg.time - lf->oldFrameTime ) / ( lf->frameTime - lf->oldFrameTime ); + } +} + + +/* +=============== +CG_ClearLerpFrame +=============== +*/ +static void CG_ClearLerpFrame( clientInfo_t *ci, lerpFrame_t *lf, int animationNumber ) { + lf->frameTime = lf->oldFrameTime = cg.time; + CG_SetLerpFrameAnimation( ci, lf, animationNumber ); + if ( lf->animation ) { + lf->oldFrame = lf->frame = lf->animation->firstFrame; + } +} + +//------------------------------------------------------------------------------ +// Ridah, variable speed animations +/* +=============== +CG_SetLerpFrameAnimationRate + +may include ANIM_TOGGLEBIT +=============== +*/ +void CG_SetLerpFrameAnimationRate( centity_t *cent, clientInfo_t *ci, lerpFrame_t *lf, int newAnimation ) { + animation_t *anim, *oldanim; + int transitionMin = -1, oldAnimTime, oldAnimNum; + qboolean firstAnim = qfalse; + + if ( !ci->modelInfo ) { + return; + } + + oldAnimTime = lf->animationTime; + oldanim = lf->animation; + oldAnimNum = lf->animationNumber; + + if ( !lf->animation ) { + firstAnim = qtrue; + } + + lf->animationNumber = newAnimation; + newAnimation &= ~ANIM_TOGGLEBIT; + + if ( newAnimation < 0 || newAnimation >= ci->modelInfo->numAnimations ) { + CG_Error( "Bad animation number (CG_SLFAR): %i", newAnimation ); + } + + anim = &ci->modelInfo->animations[ newAnimation ]; + + lf->animation = anim; + lf->animationTime = lf->frameTime + anim->initialLerp; + + if ( !( anim->flags & ANIMFL_FIRINGANIM ) || ( lf != ¢->pe.torso ) ) { + if ( ( lf == ¢->pe.legs ) && ( CG_IsCrouchingAnim( ci, newAnimation ) != CG_IsCrouchingAnim( ci, oldAnimNum ) ) ) { + if ( anim->moveSpeed || ( anim->movetype & ( ( 1 << ANIM_MT_TURNLEFT ) | ( 1 << ANIM_MT_TURNRIGHT ) ) ) ) { // if unknown movetype, go there faster + transitionMin = lf->frameTime + 200; // slowly raise/drop + } else { + transitionMin = lf->frameTime + 350; // slowly raise/drop + } + } else if ( anim->moveSpeed ) { + transitionMin = lf->frameTime + 120; // always do some lerping (?) + } else { // not moving, so take your time + transitionMin = lf->frameTime + 170; // always do some lerping (?) + + } + if ( oldanim && oldanim->animBlend ) { //transitionMin < lf->frameTime + oldanim->animBlend) { + transitionMin = lf->frameTime + oldanim->animBlend; + lf->animationTime = transitionMin; + } else { + // slow down transitions according to speed + if ( anim->moveSpeed && lf->animSpeedScale < 1.0 ) { + lf->animationTime += anim->initialLerp; + } + + if ( lf->animationTime < transitionMin ) { + lf->animationTime = transitionMin; + } + } + } + + // if first anim, go immediately + if ( firstAnim ) { + lf->frameTime = cg.time - 1; + lf->animationTime = cg.time - 1; + lf->frame = anim->firstFrame; + } + + // if death frame, move straight to last frame + if ( cent->currentState.eFlags & EF_DEATH_FRAME ) { + lf->frameTime = cg.time - 1; + lf->animationTime = cg.time - 1; + lf->frame = anim->firstFrame + anim->numFrames - 1; + lf->oldFrame = lf->frame; + lf->oldAnimationNumber = lf->animationNumber; + } + + if ( cg_debugAnim.integer == 1 ) { // DHM - Nerve :: extra debug info + CG_Printf( "Anim: %i, %s\n", newAnimation, ci->modelInfo->animations[newAnimation].name ); + } +} + +/* +=============== +CG_RunLerpFrameRate + +Sets cg.snap, cg.oldFrame, and cg.backlerp +cg.time should be between oldFrameTime and frameTime after exit +=============== +*/ +void CG_RunLerpFrameRate( clientInfo_t *ci, lerpFrame_t *lf, int newAnimation, centity_t *cent, int recursion ) { + int f; + animation_t *anim, *oldAnim; + animation_t *otherAnim = NULL; // TTimo: init + qboolean isLadderAnim; + +#define ANIM_SCALEMAX_LOW 1.1 +#define ANIM_SCALEMAX_HIGH 1.6 + +#define ANIM_SPEEDMAX_LOW 100 +#define ANIM_SPEEDMAX_HIGH 20 + + // debugging tool to get no animations + if ( cg_animSpeed.integer == 0 ) { + lf->oldFrame = lf->frame = lf->backlerp = 0; + return; + } + + isLadderAnim = lf->animation && ( lf->animation->flags & ANIMFL_LADDERANIM ); + + oldAnim = lf->animation; + + // see if the animation sequence is switching + if ( newAnimation != lf->animationNumber || !lf->animation ) { +#if 0 +#ifdef _DEBUG // RF, debugging anims +//if ( cent->currentState.number == 3 ) + CG_Printf( "(%i) %s anim change on %s: %s -> %s\n", cg.time, ci->modelInfo->modelname, ( lf == ¢->pe.legs ? "LEGS" : "TORSO" ), lf->animation->name, ci->modelInfo->animations[newAnimation & ~( 1 << 9 )].name ); +#endif +#endif + CG_SetLerpFrameAnimationRate( cent, ci, lf, newAnimation ); + } + + anim = lf->animation; + + // check for forcing last frame + if ( cent->currentState.eFlags & EF_FORCE_END_FRAME ) { + lf->frame = anim->firstFrame + anim->numFrames - 1; + lf->oldFrame = lf->frame; + lf->backlerp = 0; + return; + } + + // Ridah, make sure the animation speed is updated when possible + if ( anim->moveSpeed && lf->oldFrameSnapshotTime ) { + float moveSpeed; + + // calculate the speed at which we moved over the last frame + if ( cg.latestSnapshotTime != lf->oldFrameSnapshotTime && cg.nextSnap ) { + if ( cent->currentState.number == cg.snap->ps.clientNum ) { + if ( isLadderAnim ) { // only use Z axis for speed + lf->oldFramePos[0] = cent->lerpOrigin[0]; + lf->oldFramePos[1] = cent->lerpOrigin[1]; + } else { // only use x/y axis + lf->oldFramePos[2] = cent->lerpOrigin[2]; + } + moveSpeed = Distance( cent->lerpOrigin, lf->oldFramePos ) / ( (float)( cg.time - lf->oldFrameTime ) / 1000.0 ); + } else { + if ( isLadderAnim ) { // only use Z axis for speed + lf->oldFramePos[0] = cent->currentState.pos.trBase[0]; + lf->oldFramePos[1] = cent->currentState.pos.trBase[1]; + } + // TTimo + // show_bug.cgi?id=407 + if ( cg.snap != cg.nextSnap ) { + moveSpeed = Distance( cent->currentState.pos.trBase, cent->nextState.pos.trBase ) / ( (float)( cg.nextSnap->serverTime - cg.snap->serverTime ) / 1000.0 ); + } else + { + moveSpeed = 0; + } + } + // + // convert it to a factor of this animation's movespeed + lf->animSpeedScale = moveSpeed / (float)anim->moveSpeed; + lf->oldFrameSnapshotTime = cg.latestSnapshotTime; + } + } else { + // move at normal speed + lf->animSpeedScale = 1.0; + lf->oldFrameSnapshotTime = cg.latestSnapshotTime; + } + // adjust with manual setting (pain anims) + lf->animSpeedScale *= cent->pe.animSpeed; + + // if we have passed the current frame, move it to + // oldFrame and calculate a new frame + if ( cg.time >= lf->frameTime ) { + + lf->oldFrame = lf->frame; + lf->oldFrameTime = lf->frameTime; + VectorCopy( cent->lerpOrigin, lf->oldFramePos ); + + // restrict the speed range + if ( lf->animSpeedScale < 0.25 ) { // if it's too slow, then a really slow spped, combined with a sudden take-off, can leave them playing a really slow frame while they a moving really fast + if ( lf->animSpeedScale < 0.01 && isLadderAnim ) { + lf->animSpeedScale = 0.0; + } else { + lf->animSpeedScale = 0.25; + } + } else if ( lf->animSpeedScale > ANIM_SCALEMAX_LOW ) { + + if ( !( anim->flags & ANIMFL_LADDERANIM ) ) { + // allow slower anims to speed up more than faster anims + if ( anim->moveSpeed > ANIM_SPEEDMAX_LOW ) { + lf->animSpeedScale = ANIM_SCALEMAX_LOW; + } else if ( anim->moveSpeed < ANIM_SPEEDMAX_HIGH ) { + if ( lf->animSpeedScale > ANIM_SCALEMAX_HIGH ) { + lf->animSpeedScale = ANIM_SCALEMAX_HIGH; + } + } else { + lf->animSpeedScale = ANIM_SCALEMAX_HIGH - ( ANIM_SCALEMAX_HIGH - ANIM_SCALEMAX_LOW ) * (float)( anim->moveSpeed - ANIM_SPEEDMAX_HIGH ) / (float)( ANIM_SPEEDMAX_LOW - ANIM_SPEEDMAX_HIGH ); + } + } else if ( lf->animSpeedScale > 4.0 ) { + lf->animSpeedScale = 4.0; + } + + } + + if ( lf == ¢->pe.legs ) { + otherAnim = cent->pe.torso.animation; + } else if ( lf == ¢->pe.torso ) { + otherAnim = cent->pe.legs.animation; + } + + // get the next frame based on the animation + if ( !lf->animSpeedScale ) { + // stopped on the ladder, so stay on the same frame + f = lf->frame - anim->firstFrame; + lf->frameTime += anim->frameLerp; // don't wait too long before starting to move again + } else if ( lf->oldAnimationNumber != lf->animationNumber && + ( !anim->moveSpeed || lf->oldFrame < anim->firstFrame || lf->oldFrame >= anim->firstFrame + anim->numFrames ) ) { // Ridah, added this so walking frames don't always get reset to 0, which can happen in the middle of a walking anim, which looks wierd + lf->frameTime = lf->animationTime; // initial lerp + if ( oldAnim && anim->moveSpeed ) { // keep locomotions going continuously + f = ( lf->frame - oldAnim->firstFrame ) + 1; + while ( f < 0 ) { + f += anim->numFrames; + } + } else { + f = 0; + } + } else if ( ( lf == ¢->pe.legs ) && otherAnim && !( anim->flags & ANIMFL_FIRINGANIM ) && ( ( lf->animationNumber & ~ANIM_TOGGLEBIT ) == ( cent->pe.torso.animationNumber & ~ANIM_TOGGLEBIT ) ) && ( !anim->moveSpeed ) ) { + // legs should synch with torso + f = cent->pe.torso.frame - otherAnim->firstFrame; + if ( f >= anim->numFrames || f < 0 ) { + f = 0; // wait at the start for the legs to catch up (assuming they are still in an old anim) + } + lf->frameTime = cent->pe.torso.frameTime; + } else if ( ( lf == ¢->pe.torso ) && otherAnim && !( anim->flags & ANIMFL_FIRINGANIM ) && ( ( lf->animationNumber & ~ANIM_TOGGLEBIT ) == ( cent->pe.legs.animationNumber & ~ANIM_TOGGLEBIT ) ) && ( otherAnim->moveSpeed ) ) { + // torso needs to sync with legs + f = cent->pe.legs.frame - otherAnim->firstFrame; + if ( f >= anim->numFrames || f < 0 ) { + f = 0; // wait at the start for the legs to catch up (assuming they are still in an old anim) + } + lf->frameTime = cent->pe.legs.frameTime; + } else { +#if 0 + lf->frameTime = lf->oldFrameTime + (int)( (float)anim->frameLerp * ( 1.0 / lf->animSpeedScale ) ); + if ( lf->frameTime < cg.time ) { + lf->frameTime = cg.time; + } + + // check for skipping frames (eg. death anims play in slo-mo if low framerate) + if ( cg.time > lf->frameTime && !anim->moveSpeed ) { + f = ( lf->frame - anim->firstFrame ) + 1 + ( cg.time - lf->frameTime ) / anim->frameLerp; + } else { + f = ( lf->frame - anim->firstFrame ) + 1; + } +#else + if ( anim->moveSpeed || lf->frameTime + 1000 < cg.time ) { + lf->frameTime = lf->oldFrameTime + (int)( (float)anim->frameLerp * ( 1.0 / lf->animSpeedScale ) ); + f = ( lf->frame - anim->firstFrame ) + 1; +/* if (lf->frameTime < cg.time) { + lf->frameTime = cg.time; + } +*/ + while ( lf->frameTime < cg.time ) { + lf->frameTime += (int)( (float)anim->frameLerp * ( 1.0 / lf->animSpeedScale ) ); + f++; + while ( f >= anim->numFrames ) + f -= anim->numFrames; + } + } else { // skip frames as required + f = lf->frame - anim->firstFrame; + if ( f < 0 ) { + f = 0; + } + while ( lf->frameTime < cg.time ) { + lf->frameTime += (int)anim->frameLerp; + f++; // f is allowed to go over anim->numFrame, since it gets adjusted later + } + } +#endif + + if ( f < 0 ) { + f = 0; + } + } + //f = ( lf->frameTime - lf->animationTime ) / anim->frameLerp; + if ( f >= anim->numFrames ) { + f -= anim->numFrames; + if ( anim->loopFrames ) { + f %= anim->loopFrames; + f += anim->numFrames - anim->loopFrames; + } else { + f = anim->numFrames - 1; + // the animation is stuck at the end, so it + // can immediately transition to another sequence + lf->frameTime = cg.time; + } + } + lf->frame = anim->firstFrame + f; + if ( cg.time > lf->frameTime ) { + // NOTE TTimo + // show_bug.cgi?id=424 + // is that a related problem? +#if 0 +// disabled, causes bad jolting when oldFrame is updated incorrectly + // Ridah, run the frame again until we move ahead of the current time, fixes walking speeds for zombie + if ( recursion > MAX_LERPFRAME_RECURSION ) { + lf->frameTime = cg.time; + } else { + CG_RunLerpFrameRate( ci, lf, newAnimation, cent, recursion + 1 ); + } +#endif + lf->frameTime = cg.time; + +#if 0 + if ( cg_debugAnim.integer ) { + CG_Printf( "Clamp lf->frameTime\n" ); + } +#endif + } + lf->oldAnimationNumber = lf->animationNumber; + } + + if ( lf->oldFrameTime > cg.time ) { + lf->oldFrameTime = cg.time; + } + // calculate current lerp value + if ( lf->frameTime == lf->oldFrameTime ) { + lf->backlerp = 0; + } else { + lf->backlerp = 1.0 - (float)( cg.time - lf->oldFrameTime ) / ( lf->frameTime - lf->oldFrameTime ); + } +} + +/* +=============== +CG_ClearLerpFrameRate +=============== +*/ +void CG_ClearLerpFrameRate( clientInfo_t *ci, lerpFrame_t *lf, int animationNumber, centity_t *cent ) { + lf->frameTime = lf->oldFrameTime = cg.time; + CG_SetLerpFrameAnimationRate( cent, ci, lf, animationNumber ); + if ( lf->animation ) { + lf->oldFrame = lf->frame = lf->animation->firstFrame; + } +} + +// done. +//------------------------------------------------------------------------------ + + + +/* +=============== +CG_PlayerAnimation +=============== +*/ +static void CG_PlayerAnimation( centity_t *cent, int *legsOld, int *legs, float *legsBackLerp, + int *torsoOld, int *torso, float *torsoBackLerp ) { + clientInfo_t *ci; + int clientNum; + int animIndex, tempIndex; + + clientNum = cent->currentState.clientNum; + + if ( cg_noPlayerAnims.integer ) { + *legsOld = *legs = *torsoOld = *torso = 0; + return; + } + + ci = &cgs.clientinfo[ clientNum ]; + + // default to whatever the legs are currently doing + animIndex = cent->currentState.legsAnim; + + // do the shuffle turn frames locally + if ( !( cent->currentState.eFlags & ( EF_DEAD | EF_NO_TURN_ANIM ) ) && cent->pe.legs.yawing ) { +//CG_Printf("turn: %i\n", cg.time ); + tempIndex = BG_GetAnimScriptAnimation( clientNum, cent->currentState.aiState, ( cent->pe.legs.yawing == SWING_RIGHT ? ANIM_MT_TURNRIGHT : ANIM_MT_TURNLEFT ) ); + if ( tempIndex > -1 ) { + animIndex = tempIndex; + } + } + // run the animation + CG_RunLerpFrameRate( ci, ¢->pe.legs, animIndex, cent, 0 ); + + *legsOld = cent->pe.legs.oldFrame; + *legs = cent->pe.legs.frame; + *legsBackLerp = cent->pe.legs.backlerp; + + CG_RunLerpFrameRate( ci, ¢->pe.torso, cent->currentState.torsoAnim, cent, 0 ); + + *torsoOld = cent->pe.torso.oldFrame; + *torso = cent->pe.torso.frame; + *torsoBackLerp = cent->pe.torso.backlerp; +} + +/* +============================================================================= + +PLAYER ANGLES + +============================================================================= +*/ + +/* +================== +CG_SwingAngles +================== +*/ +static void CG_SwingAngles( float destination, float swingTolerance, float clampTolerance, + float speed, float *angle, qboolean *swinging ) { + float swing; + float move; + float scale; + + if ( !*swinging ) { + // see if a swing should be started + swing = AngleSubtract( *angle, destination ); + if ( swing > swingTolerance || swing < -swingTolerance ) { + *swinging = qtrue; + } + } + + if ( !*swinging ) { + return; + } + + // modify the speed depending on the delta + // so it doesn't seem so linear + swing = AngleSubtract( destination, *angle ); + scale = fabs( swing ); + scale *= 0.05; + if ( scale < 0.5 ) { + scale = 0.5; + } + + // swing towards the destination angle + if ( swing >= 0 ) { + move = cg.frametime * scale * speed; + if ( move >= swing ) { + move = swing; + *swinging = qfalse; + } else { + *swinging = SWING_LEFT; // left + } + *angle = AngleMod( *angle + move ); + } else if ( swing < 0 ) { + move = cg.frametime * scale * -speed; + if ( move <= swing ) { + move = swing; + *swinging = qfalse; + } else { + *swinging = SWING_RIGHT; // right + } + *angle = AngleMod( *angle + move ); + } + + // clamp to no more than tolerance + swing = AngleSubtract( destination, *angle ); + if ( swing > clampTolerance ) { + *angle = AngleMod( destination - ( clampTolerance - 1 ) ); + } else if ( swing < -clampTolerance ) { + *angle = AngleMod( destination + ( clampTolerance - 1 ) ); + } +} + +/* +================= +CG_AddPainTwitch +================= +*/ +static void CG_AddPainTwitch( centity_t *cent, vec3_t torsoAngles ) { + int t; + float f; + int duration; + float direction; + + if ( !cent->pe.animSpeed ) { + // we need to inititialize this stuff + cent->pe.painAnimLegs = -1; + cent->pe.painAnimTorso = -1; + cent->pe.animSpeed = 1.0; + } + + if ( cent->currentState.eFlags & EF_DEAD ) { + cent->pe.painAnimLegs = -1; + cent->pe.painAnimTorso = -1; + cent->pe.animSpeed = 1.0; + return; + } + + // special pain anims for AI + if ( cent->currentState.aiChar ) { + if ( cent->pe.painAnimTorso >= 0 ) { + animation_t *anim; + clientInfo_t *ci; + + ci = &cgs.clientinfo[ cent->currentState.number ]; + anim = &ci->modelInfo->animations[ cent->pe.painAnimTorso ]; + + // play the current animation + if ( cent->pe.torso.frame != cent->pe.torso.oldFrame || cent->pe.torso.frame != anim->firstFrame + anim->numFrames - 1 ) { + if ( cent->pe.painAnimLegs >= 0 ) { + cent->currentState.legsAnim = cent->pe.painAnimLegs; + } + cent->currentState.torsoAnim = cent->pe.painAnimTorso; + } else { // end it + cent->pe.painAnimLegs = -1; + cent->pe.painAnimTorso = -1; + cent->pe.animSpeed = 1.0; + } + } + + return; + } + + if ( cent->pe.painDuration ) { + duration = cent->pe.painDuration; + } else { + duration = PAIN_TWITCH_TIME; + } + direction = (float)duration * 0.085; + if ( direction > 30 ) { + direction = 30; + } + if ( direction < 10 ) { + direction = 10; + } + direction *= (float)( cent->pe.painDirection * 2 ) - 1; + + t = cg.time - cent->pe.painTime; + if ( t >= duration ) { + return; + } + + if ( cent->currentState.clientNum && cgs.gametype == GT_SINGLE_PLAYER ) { + #define FADEIN_RATIO 0.25 + #define FADEOUT_RATIO ( 1.0 - FADEIN_RATIO ) + f = (float)t / duration; + if ( f < FADEIN_RATIO ) { + torsoAngles[ROLL] += ( 0.5 * direction * ( f * ( 1.0 / FADEIN_RATIO ) ) ); + torsoAngles[PITCH] -= ( fabs( direction ) * ( f * ( 1.0 / FADEIN_RATIO ) ) ); + torsoAngles[YAW] += ( direction * ( f * ( 1.0 / FADEIN_RATIO ) ) ); + } else { + torsoAngles[ROLL] += ( 0.5 * direction * ( 1.0 - ( f - FADEIN_RATIO ) ) * ( 1.0 / FADEOUT_RATIO ) ); + torsoAngles[PITCH] -= ( fabs( direction ) * ( 1.0 - ( f - FADEIN_RATIO ) ) * ( 1.0 / FADEOUT_RATIO ) ); + torsoAngles[YAW] += ( direction * ( 1.0 - ( f - FADEIN_RATIO ) ) * ( 1.0 / FADEOUT_RATIO ) ); + } + } else { // fast, Q3 style + f = 1.0 - (float)t / duration; + if ( cent->pe.painDirection ) { + torsoAngles[ROLL] += 20 * f; + } else { + torsoAngles[ROLL] -= 20 * f; + } + } +} + +/* +================ +CG_IdleHeadMovement +================ +*/ +static void CG_IdleHeadMovement( centity_t *cent, const vec3_t torsoAngles, vec3_t headAngles ) { + const float angleSpeedMax = 60; + const float angleSpeedAccel = 40; + //const float diffThreshold = 50; // don't yaw from torso beyond this in any axis + const float diffRandMax = 30; + const float stopTime = 3000; + + int i; + + if ( ( cent->currentState.eFlags & EF_DEAD ) || !( cent->currentState.eFlags & EF_HEADLOOK ) ) { + // center + VectorClear( cent->pe.headLookIdeal ); + cent->pe.headLookStopTime = 0; + cent->pe.headLookSpeed = 100; // hurry back to normal + } else if ( !cent->pe.headLookSpeedMax && cent->pe.headLookStopTime < cg.time ) { + // need new ideal angles + VectorSet( cent->pe.headLookIdeal, + diffRandMax * ( -0.25 + crandom() ) * 0.25, // pitch + diffRandMax * crandom(), // yaw + 0 ); // roll + cent->pe.headLookSpeedMax = angleSpeedMax; // * (0.5 + 0.5*random()); + cent->pe.headLookStopTime = cg.time - 1; + } + + // move towards ideal position + if ( cent->pe.headLookStopTime < cg.time && !VectorCompare( cent->pe.headLookIdeal, cent->pe.headLookOffset ) ) { + // slow down as we get closer + if ( fabs( cent->pe.headLookOffset[YAW] - cent->pe.headLookIdeal[YAW] ) < angleSpeedMax * 1.2 ) { + cent->pe.headLookSpeedMax = angleSpeedMax * ( 0.1 + 0.9 * ( fabs( cent->pe.headLookOffset[YAW] - cent->pe.headLookIdeal[YAW] ) / ( angleSpeedMax * 1.2 ) ) ); + } + // accelerate angle speed + if ( cent->pe.headLookSpeed < cent->pe.headLookSpeedMax ) { + cent->pe.headLookSpeed += angleSpeedAccel * ( 0.001 * cg.frametime ); + if ( cent->pe.headLookSpeed > cent->pe.headLookSpeedMax ) { + cent->pe.headLookSpeed = cent->pe.headLookSpeedMax; + } + } else if ( cent->pe.headLookSpeed > cent->pe.headLookSpeedMax ) { + cent->pe.headLookSpeed -= angleSpeedAccel * ( 0.001 * cg.frametime ); + if ( cent->pe.headLookSpeed < cent->pe.headLookSpeedMax ) { + cent->pe.headLookSpeed = cent->pe.headLookSpeedMax; + } + } + // move towards the ideal angles + for ( i = 0; i < 3; i++ ) { + if ( cent->pe.headLookOffset[i] < cent->pe.headLookIdeal[i] ) { + cent->pe.headLookOffset[i] += cent->pe.headLookSpeed * 0.001 * cg.frametime; + if ( cent->pe.headLookOffset[i] > cent->pe.headLookIdeal[i] ) { + cent->pe.headLookOffset[i] = cent->pe.headLookIdeal[i]; + } + } else if ( cent->pe.headLookOffset[i] > cent->pe.headLookIdeal[i] ) { + cent->pe.headLookOffset[i] -= cent->pe.headLookSpeed * 0.001 * cg.frametime; + if ( cent->pe.headLookOffset[i] < cent->pe.headLookIdeal[i] ) { + cent->pe.headLookOffset[i] = cent->pe.headLookIdeal[i]; + } + } + } + // if we made it, stop here for a bit + if ( VectorCompare( cent->pe.headLookIdeal, cent->pe.headLookOffset ) ) { + cent->pe.headLookStopTime = cg.time + (int)( stopTime * ( 0.5 + 0.5 * random() ) ); + } + // randomly choose a new destination before reaching ideal angles + if ( cent->pe.headLookStopTime % 2 && rand() % ( cg.time - cent->pe.headLookStopTime ) > 700 ) { + cent->pe.headLookSpeedMax = 0; + } + } else { + cent->pe.headLookSpeedMax = 0; + cent->pe.headLookSpeed = 0; // accelerate when resuming idle movement + } +/* + // make sure these angles don't place us too far from the torso angles + for (i=0; i<3; i++) { + if (fabs(cent->pe.headLookOffset[i] + headAngles[i] - torsoAngles[i]) > diffThreshold) { + if (cent->pe.headLookOffset[i] + headAngles[i] - torsoAngles[i] > 0) + cent->pe.headLookOffset[i] = diffThreshold - (headAngles[i] - torsoAngles[i]); + else + cent->pe.headLookOffset[i] = -diffThreshold - (headAngles[i] - torsoAngles[i]); + } + } +*/ + // finally, add the headLookOffset to the head angles + VectorAdd( headAngles, cent->pe.headLookOffset, headAngles ); +} + +/* +=============== +CG_PlayerAngles + +Handles seperate torso motion + + legs pivot based on direction of movement + + head always looks exactly at cent->lerpAngles + + if motion < 20 degrees, show in head only + if < 45 degrees, also show in torso +=============== +*/ +static void CG_PlayerAngles( centity_t *cent, vec3_t legs[3], vec3_t torso[3], vec3_t head[3] ) { + vec3_t legsAngles, torsoAngles, headAngles; + float dest; + //static int movementOffsets[8] = { 0, 22, 45, -22, 0, 22, -45, -22 }; // TTimo: unused + vec3_t velocity; + float speed; + float clampTolerance; + int legsSet, torsoSet; + clientInfo_t *ci; + ci = &cgs.clientinfo[ cent->currentState.number ]; + + // special case (female zombie while climbing wall) + if ( cent->currentState.eFlags & EF_FORCED_ANGLES ) { + // torso & legs parts should turn to face the given angles + VectorCopy( cent->lerpAngles, legsAngles ); + AnglesToAxis( legsAngles, legs ); + AnglesToAxis( vec3_origin, torso ); + AnglesToAxis( vec3_origin, head ); + return; + } + + legsSet = cent->currentState.legsAnim & ~ANIM_TOGGLEBIT; + torsoSet = cent->currentState.torsoAnim & ~ANIM_TOGGLEBIT; + + VectorCopy( cent->lerpAngles, headAngles ); + headAngles[YAW] = AngleMod( headAngles[YAW] ); + VectorClear( legsAngles ); + VectorClear( torsoAngles ); + + // --------- yaw ------------- + + // allow yaw to drift a bit, unless these conditions don't allow them + if ( !( BG_GetConditionValue( cent->currentState.number, ANIM_COND_MOVETYPE, qfalse ) & ( ( 1 << ANIM_MT_IDLE ) | ( 1 << ANIM_MT_IDLECR ) ) )/* + || (BG_GetConditionValue( cent->currentState.number, ANIM_COND_MOVETYPE, qfalse ) & ((1<pe.torso.yawing = qtrue; // always center + cent->pe.torso.pitching = qtrue; // always center + cent->pe.legs.yawing = qtrue; // always center + + // if firing, make sure torso and head are always aligned + } else if ( BG_GetConditionValue( cent->currentState.number, ANIM_COND_FIRING, qtrue ) ) { + + cent->pe.torso.yawing = qtrue; // always center + cent->pe.torso.pitching = qtrue; // always center + + } + + // adjust legs for movement dir + if ( cent->currentState.eFlags & EF_DEAD ) { + // don't let dead bodies twitch + legsAngles[YAW] = headAngles[YAW]; + torsoAngles[YAW] = headAngles[YAW]; + } else { + legsAngles[YAW] = headAngles[YAW] + cent->currentState.angles2[YAW]; + + if ( cent->currentState.eFlags & EF_NOSWINGANGLES ) { + legsAngles[YAW] = torsoAngles[YAW] = headAngles[YAW]; // always face firing direction + clampTolerance = 40; + } else if ( !( cent->currentState.eFlags & EF_FIRING ) && !( cent->currentState.eFlags & EF_RECENTLY_FIRING ) ) { + torsoAngles[YAW] = headAngles[YAW] + 0.35 * cent->currentState.angles2[YAW]; + clampTolerance = 60; + } else { // must be firing + torsoAngles[YAW] = headAngles[YAW]; // always face firing direction + //if (fabs(cent->currentState.angles2[YAW]) > 30) + // legsAngles[YAW] = headAngles[YAW]; + clampTolerance = 40; + } + + // torso + if ( !cent->pe.torso.yawing ) { + CG_SwingAngles( torsoAngles[YAW], 30, clampTolerance, 0.5 * cg_swingSpeed.value, ¢->pe.torso.yawAngle, ¢->pe.torso.yawing ); + } else if ( !( cent->currentState.eFlags & EF_FIRING ) && !( cent->currentState.eFlags & EF_RECENTLY_FIRING ) ) { + // not firing + CG_SwingAngles( torsoAngles[YAW], 0, clampTolerance, 0.5 * cg_swingSpeed.value, ¢->pe.torso.yawAngle, ¢->pe.torso.yawing ); + } else { // firing + CG_SwingAngles( torsoAngles[YAW], 0, clampTolerance, 4.0 * cg_swingSpeed.value, ¢->pe.torso.yawAngle, ¢->pe.torso.yawing ); + } + + // if the legs are yawing (facing heading direction), allow them to rotate a bit, so we don't keep calling + // the legs_turn animation while an AI is firing, and therefore his angles will be randomizing according to their accuracy + + clampTolerance = 90; + + if ( BG_GetConditionValue( ci->clientNum, ANIM_COND_MOVETYPE, qfalse ) & ( 1 << ANIM_MT_IDLE ) ) { + if ( cent->pe.legs.yawing ) { + CG_SwingAngles( legsAngles[YAW], 0, clampTolerance, 0.75 * cg_swingSpeed.value, ¢->pe.legs.yawAngle, ¢->pe.legs.yawing ); + } else { + cent->pe.legs.yawing = qfalse; // set it if they really need to swing + CG_SwingAngles( legsAngles[YAW], 50, clampTolerance, 0.75 * cg_swingSpeed.value, ¢->pe.legs.yawAngle, ¢->pe.legs.yawing ); + } + } else + //if ( BG_GetConditionValue( ci->clientNum, ANIM_COND_MOVETYPE, qfalse ) & ((1<clientNum, legsSet ), "strafe" ) ) { + cent->pe.legs.yawing = qfalse; // set it if they really need to swing + legsAngles[YAW] = headAngles[YAW]; + CG_SwingAngles( legsAngles[YAW], 0, clampTolerance, cg_swingSpeed.value, ¢->pe.legs.yawAngle, ¢->pe.legs.yawing ); + } else + if ( cent->pe.legs.yawing ) { + CG_SwingAngles( legsAngles[YAW], 0, clampTolerance, cg_swingSpeed.value, ¢->pe.legs.yawAngle, ¢->pe.legs.yawing ); + } else + { + CG_SwingAngles( legsAngles[YAW], 50, clampTolerance, cg_swingSpeed.value, ¢->pe.legs.yawAngle, ¢->pe.legs.yawing ); + } + + torsoAngles[YAW] = cent->pe.torso.yawAngle; + legsAngles[YAW] = cent->pe.legs.yawAngle; + } + + // --------- pitch ------------- + + // only show a fraction of the pitch angle in the torso + if ( headAngles[PITCH] > 180 ) { + dest = ( -360 + headAngles[PITCH] ) * 0.75; + } else { + dest = headAngles[PITCH] * 0.75; + } + CG_SwingAngles( dest, 15, 30, 0.1, ¢->pe.torso.pitchAngle, ¢->pe.torso.pitching ); + torsoAngles[PITCH] = cent->pe.torso.pitchAngle; + + // --------- roll ------------- + + + // lean towards the direction of travel + VectorCopy( cent->currentState.pos.trDelta, velocity ); + speed = VectorNormalize( velocity ); + if ( speed ) { + vec3_t axis[3]; + float side; + + speed *= 0.05; + + AnglesToAxis( legsAngles, axis ); + side = speed * DotProduct( velocity, axis[1] ); + legsAngles[ROLL] -= side; + + side = speed * DotProduct( velocity, axis[0] ); + legsAngles[PITCH] += side; + } + + // pain twitch + CG_AddPainTwitch( cent, torsoAngles ); + + // RF, add the head movement if flag is set for looking around + CG_IdleHeadMovement( cent, torsoAngles, headAngles ); + + // pull the angles back out of the hierarchial chain + AnglesSubtract( headAngles, torsoAngles, headAngles ); + AnglesSubtract( torsoAngles, legsAngles, torsoAngles ); + AnglesToAxis( legsAngles, legs ); + AnglesToAxis( torsoAngles, torso ); + AnglesToAxis( headAngles, head ); +} + + +//========================================================================== + +/* +=============== +CG_HasteTrail +=============== +*/ +static void CG_HasteTrail( centity_t *cent ) { + localEntity_t *smoke; + vec3_t origin; + int anim; + + if ( cent->trailTime > cg.time ) { + return; + } + anim = cent->pe.legs.animationNumber & ~ANIM_TOGGLEBIT; +// RF, this is all broken by scripting system +// if ( anim != LEGS_RUN && anim != LEGS_BACK ) { +// return; +// } + + cent->trailTime += 100; + if ( cent->trailTime < cg.time ) { + cent->trailTime = cg.time; + } + + VectorCopy( cent->lerpOrigin, origin ); + origin[2] -= 16; + + smoke = CG_SmokePuff( origin, vec3_origin, + 8, + 1, 1, 1, 1, + 500, + cg.time, + 0, + 0, + cgs.media.hastePuffShader ); + + // use the optimized local entity add + smoke->leType = LE_SCALE_FADE; +} + + +//----(SA) added and modified from missionpack +/* +=============== +CG_BreathPuffs +=============== +*/ +static void CG_BreathPuffs( centity_t *cent, refEntity_t *head ) { + clientInfo_t *ci; + vec3_t up, forward; + int contents; + + vec3_t mang, morg, maxis[3]; //, mang; + + ci = &cgs.clientinfo[ cent->currentState.number ]; + + if ( !cg_enableBreath.integer ) { + return; + } + + if ( cent->currentState.number == cg.snap->ps.clientNum && !cg.renderingThirdPerson ) { + return; + } + if ( cent->currentState.eFlags & EF_DEAD ) { + return; + } + + // allow cg_enableBreath to force everyone to have breath + if ( cg_enableBreath.integer == 1 ) { + if ( !( cent->currentState.eFlags & EF_BREATH ) ) { + return; + } + } + + contents = trap_CM_PointContents( head->origin, 0 ); + if ( contents & ( CONTENTS_WATER | CONTENTS_SLIME | CONTENTS_LAVA ) ) { + return; + } + if ( ci->breathPuffTime > cg.time ) { + return; + } + + CG_GetOriginForTag( cent, head, "tag_mouth", 0, morg, maxis ); + AxisToAngles( maxis, mang ); + AngleVectors( mang, forward, NULL, up ); + + //push the origin out a tad so it's not right in the guys face (tad==4) + VectorMA( morg, 4, forward, morg ); + + forward[0] = up[0] * 8 + forward[0] * 5; + forward[1] = up[1] * 8 + forward[1] * 5; + forward[2] = up[2] * 8 + forward[2] * 5; + + CG_SmokePuff( morg, forward, 4, 1, 1, 1, 0.5f, 2000, cg.time, cg.time + 400, 0, cgs.media.shotgunSmokePuffShader ); + + + ci->breathPuffTime = cg.time + 3000 + random() * 1000; + +} + +//----(SA) end + +/* +=============== +CG_TrailItem +=============== +*/ +static void CG_TrailItem( centity_t *cent, qhandle_t hModel ) { + refEntity_t ent; + vec3_t angles; + vec3_t axis[3]; + + VectorCopy( cent->lerpAngles, angles ); + angles[PITCH] = 0; + angles[ROLL] = 0; + AnglesToAxis( angles, axis ); + + memset( &ent, 0, sizeof( ent ) ); + // DHM - Nerve :: adjusted values + VectorMA( cent->lerpOrigin, -4, axis[0], ent.origin ); + ent.origin[2] += 36; + VectorScale( cg.autoAxis[0], 0.75, ent.axis[0] ); + VectorScale( cg.autoAxis[1], 0.75, ent.axis[1] ); + VectorScale( cg.autoAxis[2], 0.75, ent.axis[2] ); + ent.hModel = hModel; + trap_R_AddRefEntityToScene( &ent ); +} + + +/* +=============== +CG_PlayerPowerups +=============== +*/ +static void CG_PlayerPowerups( centity_t *cent ) { + int powerups; + + if ( cent->pe.teslaDamagedTime > cg.time - 400 ) { + trap_R_AddLightToScene( cent->lerpOrigin, 128 + 128 * sin( cg.time * cg.time ), 0.2, 0.6, 1, 0 ); + } + + // RF, AI don't use these effects, they are generally added manually by the game + if ( cent->currentState.aiChar ) { + return; + } + +//----(SA) test stuff leave in, but comment out +// if(cg_forceModel.integer) { +// vec3_t orig, forward, li; +// trace_t trace; +// +// AngleVectors(cg.refdefViewAngles, forward, NULL, NULL); +// VectorNormalize(forward); // just in case +// VectorCopy(cent->lerpOrigin, orig); +// orig[2]+=cg.predictedPlayerState.viewheight; +// VectorMA(orig, 1000, forward, li); +// CG_Trace(&trace, orig, NULL, NULL, li, -1, MASK_SHOT); +// VectorMA(trace.endpos, -5, forward, li); +// trap_R_AddLightToScene( li, 100 + 100*trace.fraction, 1, 1, 1, 1 ); +// } +//----(SA) end + + powerups = cent->currentState.powerups; + if ( !powerups ) { + return; + } + + // quad gives a dlight + if ( powerups & ( 1 << PW_QUAD ) ) { + trap_R_AddLightToScene( cent->lerpOrigin, 200 + ( rand() & 31 ), 0.2, 0.2, 1, 0 ); + } + + // flight plays a looped sound +// if ( powerups & ( 1 << PW_FLIGHT ) ) { +// trap_S_AddLoopingSound( cent->currentState.number, cent->lerpOrigin, vec3_origin, cgs.media.flightSound, 255 ); +// } + + // redflag + if ( powerups & ( 1 << PW_REDFLAG ) ) { + CG_TrailItem( cent, cgs.media.redFlagModel ); + trap_R_AddLightToScene( cent->lerpOrigin, 200 + ( rand() & 31 ), 1, 0.2, 0.2, 0 ); + } + + // blueflag + if ( powerups & ( 1 << PW_BLUEFLAG ) ) { + CG_TrailItem( cent, cgs.media.blueFlagModel ); + trap_R_AddLightToScene( cent->lerpOrigin, 200 + ( rand() & 31 ), 0.2, 0.2, 1, 0 ); + } + + // haste leaves smoke trails + if ( powerups & ( 1 << PW_HASTE ) ) { + CG_HasteTrail( cent ); + } +} + + +/* +=============== +CG_PlayerFloatSprite + +Float a sprite over the player's head +DHM - Nerve :: added height parameter +=============== +*/ +static void CG_PlayerFloatSprite( centity_t *cent, qhandle_t shader, int height ) { + int rf; + refEntity_t ent; + + if ( cent->currentState.number == cg.snap->ps.clientNum && !cg.renderingThirdPerson ) { + rf = RF_THIRD_PERSON; // only show in mirrors + } else { + rf = 0; + } + + memset( &ent, 0, sizeof( ent ) ); + VectorCopy( cent->lerpOrigin, ent.origin ); + ent.origin[2] += height; // DHM - Nerve :: was '48' + ent.reType = RT_SPRITE; + ent.customShader = shader; + ent.radius = 10; + ent.renderfx = rf; + ent.shaderRGBA[0] = 255; + ent.shaderRGBA[1] = 255; + ent.shaderRGBA[2] = 255; + ent.shaderRGBA[3] = 255; + trap_R_AddRefEntityToScene( &ent ); +} + + + +/* +=============== +CG_PlayerSprites + +Float sprites over the player's head +=============== +*/ +static void CG_PlayerSprites( centity_t *cent ) { + int team; + + if ( cg_showAIState.integer && cent->currentState.aiChar ) { + CG_PlayerFloatSprite( cent, cgs.media.aiStateShaders[cent->currentState.aiState], 48 ); + return; + } + + if ( cent->currentState.eFlags & EF_CONNECTION ) { + CG_PlayerFloatSprite( cent, cgs.media.connectionShader, 48 ); + return; + } + + // DHM - Nerve :: If this client is a medic, draw a 'revive' icon over + // dead players that are not in limbo yet. + team = cgs.clientinfo[ cent->currentState.clientNum ].team; + if ( cgs.gametype == GT_WOLF && ( cent->currentState.eFlags & EF_DEAD ) + && cent->currentState.number == cent->currentState.clientNum + && cg.snap->ps.stats[ STAT_PLAYER_CLASS ] == PC_MEDIC + && cg.snap->ps.persistant[PERS_TEAM] == team ) { + +// CG_PlayerFloatSprite( cent, cgs.media.medicReviveShader, 8 ); //----(SA) commented out from MP + return; + } + + // DHM - Nerve :: not using, gives away position if chatting to coordinate attack +// if ( cent->currentState.eFlags & EF_TALK ) { +// CG_PlayerFloatSprite( cent, cgs.media.balloonShader, 48 ); +// return; +// } + +//----(SA) commented out +// if ( cent->currentState.eFlags & EF_AWARD_IMPRESSIVE ) { +// CG_PlayerFloatSprite( cent, cgs.media.medalImpressive, 48 ); +// return; +// } + +//----(SA) commented out +// if ( cent->currentState.eFlags & EF_AWARD_EXCELLENT ) { +// CG_PlayerFloatSprite( cent, cgs.media.medalExcellent, 48 ); +// return; +// } + +//----(SA) commented out +// if ( cent->currentState.eFlags & EF_AWARD_GAUNTLET ) { +// CG_PlayerFloatSprite( cent, cgs.media.medalGauntlet, 48 ); +// return; +// } +// DHM - Nerve :: Not using friendly sprites in GT_WOLF + if ( cgs.gametype != GT_WOLF && cgs.gametype >= GT_TEAM && + !( cent->currentState.eFlags & EF_DEAD ) && + cg.snap->ps.persistant[PERS_TEAM] == team ) { + + CG_PlayerFloatSprite( cent, cgs.media.friendShader, 48 ); + return; + } +} + +/* +=============== +CG_PlayerShadow + +Returns the Z component of the surface being shadowed + + should it return a full plane instead of a Z? +=============== +*/ +#define SHADOW_DISTANCE 64 +typedef struct { + char *tagname; + float size; + float maxdist; + float maxalpha; + qhandle_t shader; +} shadowPart_t; + +static qboolean CG_PlayerShadow( centity_t *cent, float *shadowPlane ) { + vec3_t end; + trace_t trace; + float alpha, dist, distfade, scale, dot; + int tagIndex, subIndex; + vec3_t origin, angles, axis[3]; + #define ZOFS 6.0 + #define SHADOW_MIN_DIST 250.0 + #define SHADOW_MAX_DIST 512.0 + shadowPart_t shadowParts[] = { + {"tag_footleft", 10, 4, 0.5, 0}, + {"tag_footright", 10, 4, 0.5, 0}, + {"tag_torso", 18, 96, 0.4, 0}, + {NULL, 0} + }; + + shadowParts[0].shader = cgs.media.shadowFootShader; //DAJ pulled out of initliization + shadowParts[1].shader = cgs.media.shadowFootShader; + shadowParts[2].shader = cgs.media.shadowTorsoShader; + *shadowPlane = 0; + + if ( cg_shadows.integer == 0 ) { + return qfalse; + } + + // no shadows when invisible + if ( cent->currentState.powerups & ( 1 << PW_INVIS ) ) { + return qfalse; + } + + // send a trace down from the player to the ground + VectorCopy( cent->lerpOrigin, end ); + end[2] -= SHADOW_DISTANCE; + + trap_CM_BoxTrace( &trace, cent->lerpOrigin, end, NULL, NULL, 0, MASK_PLAYERSOLID ); + + // no shadow if too high + if ( trace.fraction == 1.0 ) { + return qfalse; + } + + *shadowPlane = trace.endpos[2] + 1; + + if ( cg_shadows.integer != 1 ) { // no mark for stencil or projection shadows + return qtrue; + } + + // no shadows when dead + if ( cent->currentState.eFlags & EF_DEAD ) { + return qfalse; + } + + if ( cg.snap && cent->currentState.number != cg.snap->ps.clientNum ) { + // scale shadow according to bounding box size + scale = ( cent->currentState.solid & 255 ); + scale /= 18.0; + } else { + scale = 1.0; + } + + // fade the shadow out with height + alpha = 1.0 - trace.fraction; + + // if zooming, dont draw shadows if we're not looking in their direction + if ( cg.predictedPlayerState.eFlags & EF_ZOOMING ) { + VectorSubtract( cent->lerpOrigin, cg.refdef.vieworg, end ); + VectorNormalize( end ); + dot = DotProduct( cg.refdef.viewaxis[0], end ); + if ( dot < 0.96 ) { + return qfalse; + } else if ( dot < 0.98 ) { + alpha *= ( dot - 0.94 ) / ( 0.97 - 0.94 ); + } + } + + // if the torso is below the ground, dont draw shadows + if ( CG_GetOriginForTag( cent, ¢->pe.legsRefEnt, "tag_torso", 0, origin, axis ) ) { + if ( origin[2] - cent->lerpOrigin[2] < -26 ) { + return qfalse; + } + } + + // add the mark as a temporary, so it goes directly to the renderer + // without taking a spot in the cg_marks array + dist = VectorDistance( cent->lerpOrigin, cg.refdef.vieworg ); + if ( dist > SHADOW_MIN_DIST ) { + if ( dist < SHADOW_MAX_DIST ) { + distfade = ( dist - SHADOW_MIN_DIST ) / ( SHADOW_MAX_DIST - SHADOW_MIN_DIST ); + } else { + if ( dist > SHADOW_MAX_DIST * 2 ) { + return qfalse; + } else { // fade out + distfade = 1.0 - ( ( dist - SHADOW_MAX_DIST ) / SHADOW_MAX_DIST ); + } + } + alpha *= distfade; + CG_ImpactMark( cgs.media.shadowTorsoShader, trace.endpos, trace.plane.normal, + 0, alpha,alpha,alpha,1, qfalse, 18 * scale, qtrue, -1 ); + } else { + distfade = 0.0; + } + + if ( dist < SHADOW_MAX_DIST ) { // show more detail + // now add shadows for the various body parts + for ( tagIndex = 0; shadowParts[tagIndex].tagname; tagIndex++ ) { + // grab each tag with this name + for ( subIndex = 0; ( subIndex = CG_GetOriginForTag( cent, ¢->pe.legsRefEnt, shadowParts[tagIndex].tagname, subIndex, origin, axis ) ) >= 0; subIndex++ ) { + // move the shadow center forward + VectorMA( origin, 4, axis[0], origin ); + // project it onto the shadow plane + if ( origin[2] < *shadowPlane ) { + origin[2] = *shadowPlane; + } + alpha = 1.0 - ( ( origin[2] - ( *shadowPlane + ZOFS ) ) / shadowParts[tagIndex].maxdist ); + if ( alpha < 0 ) { + continue; + } + if ( alpha > shadowParts[tagIndex].maxalpha ) { + alpha = shadowParts[tagIndex].maxalpha; + } + alpha *= ( 1.0 - distfade ); + + origin[2] = *shadowPlane; + + AxisToAngles( axis, angles ); + + CG_ImpactMark( shadowParts[tagIndex].shader, origin, trace.plane.normal, + angles[YAW] /*cent->pe.legs.yawAngle*/, alpha,alpha,alpha,1, qfalse, shadowParts[tagIndex].size * scale, qtrue, -1 ); + } + } + } + + return qtrue; +} + + + +/* +=============== +CG_PlayerSplash + +Draw a mark at the water surface +=============== +*/ +static void CG_PlayerSplash( centity_t *cent ) { + vec3_t start, end; + trace_t trace; + int contents; + polyVert_t verts[4]; + + if ( !cg_shadows.integer ) { + return; + } + + VectorCopy( cent->lerpOrigin, end ); + end[2] -= 24; + + // if the feet aren't in liquid, don't make a mark + // this won't handle moving water brushes, but they wouldn't draw right anyway... + contents = trap_CM_PointContents( end, 0 ); + if ( !( contents & ( CONTENTS_WATER | CONTENTS_SLIME | CONTENTS_LAVA ) ) ) { + return; + } + + VectorCopy( cent->lerpOrigin, start ); + start[2] += 32; + + // if the head isn't out of liquid, don't make a mark + contents = trap_CM_PointContents( start, 0 ); + if ( contents & ( CONTENTS_SOLID | CONTENTS_WATER | CONTENTS_SLIME | CONTENTS_LAVA ) ) { + return; + } + + // trace down to find the surface + trap_CM_BoxTrace( &trace, start, end, NULL, NULL, 0, ( CONTENTS_WATER | CONTENTS_SLIME | CONTENTS_LAVA ) ); + + if ( trace.fraction == 1.0 ) { + return; + } + + // create a mark polygon + VectorCopy( trace.endpos, verts[0].xyz ); + verts[0].xyz[0] -= 32; + verts[0].xyz[1] -= 32; + verts[0].st[0] = 0; + verts[0].st[1] = 0; + verts[0].modulate[0] = 255; + verts[0].modulate[1] = 255; + verts[0].modulate[2] = 255; + verts[0].modulate[3] = 255; + + VectorCopy( trace.endpos, verts[1].xyz ); + verts[1].xyz[0] -= 32; + verts[1].xyz[1] += 32; + verts[1].st[0] = 0; + verts[1].st[1] = 1; + verts[1].modulate[0] = 255; + verts[1].modulate[1] = 255; + verts[1].modulate[2] = 255; + verts[1].modulate[3] = 255; + + VectorCopy( trace.endpos, verts[2].xyz ); + verts[2].xyz[0] += 32; + verts[2].xyz[1] += 32; + verts[2].st[0] = 1; + verts[2].st[1] = 1; + verts[2].modulate[0] = 255; + verts[2].modulate[1] = 255; + verts[2].modulate[2] = 255; + verts[2].modulate[3] = 255; + + VectorCopy( trace.endpos, verts[3].xyz ); + verts[3].xyz[0] += 32; + verts[3].xyz[1] -= 32; + verts[3].st[0] = 1; + verts[3].st[1] = 0; + verts[3].modulate[0] = 255; + verts[3].modulate[1] = 255; + verts[3].modulate[2] = 255; + verts[3].modulate[3] = 255; + + trap_R_AddPolyToScene( cgs.media.wakeMarkShader, 4, verts ); +} + +//========================================================================== +// Zombie Effects + +/* +============== +CG_SpawnZombieSpirit +============== +*/ +void CG_SpawnZombieSpirit( vec3_t origin, vec3_t vel, int trailHead, int ownerNum, refEntity_t *oldrefent, int trailLife, int idealWidth ) { + localEntity_t *le; + refEntity_t *re; + + le = CG_AllocLocalEntity(); + re = &le->refEntity; + + *re = *oldrefent; + + le->leType = LE_ZOMBIE_SPIRIT; + le->startTime = cg.time - 5000; // set it back so we dont fade it in like the "end" spirits + le->endTime = cg.time + 5000; + + le->pos.trType = TR_LINEAR; + le->pos.trTime = cg.time; + VectorCopy( origin, le->pos.trBase ); + VectorCopy( vel, le->pos.trDelta ); + + le->effectWidth = trailLife; + le->radius = idealWidth; + le->lastTrailTime = cg.time; + le->headJuncIndex = trailHead; + le->loopingSound = cgs.media.zombieSpiritLoopSound; + + le->ownerNum = ownerNum; + + re->fadeStartTime = le->endTime - 2000; + re->fadeEndTime = le->endTime; +} + +/* +============== +CG_AddZombieSpiritEffect +============== +*/ +void CG_AddZombieSpiritEffect( centity_t *cent ) { + const int trailLife = 600; + const float idealWidth = 14.0; + const int fadeInTime = 1200; + const int fadeOutTime = 2000; + const int minRotationTime = 3000; + const int maxRotationTime = 4000; + const int minRadiusCycleTime = 2400; + const int maxRadiusCycleTime = 2900; + const int zCycleTime = 3000; + + const float minDist = 16; + const float maxDist = 40; + const float fadeDist = 4; + + const int sndIntervalMin = 300; + const int sndIntervalMax = 1400; + const int sndDelay = 0; + //const int sndDuration = 99999;//1500; // TTimo: init + + const int step = 50; + + int i, t; + vec3_t v,p[MAX_ZOMBIE_SPIRITS], ang; + float fadeRatio, alpha, radius; + int rotationTime, radiusCycleTime; + trace_t trace; + refEntity_t refent; + + qboolean active = qfalse; + + static int lastSpiritRelease; + + if ( cent->currentState.aiChar != AICHAR_ZOMBIE ) { + return; + } + + // sanity check the server time to make sure we don't start the effect + // to early, whilst reloading a savegame or something + if ( cg.time < cent->currentState.effect1Time ) { + return; + } + + if ( cent->currentState.eFlags & EF_MONSTER_EFFECT ) { + + if ( !cent->pe.cueZombieSpirit ) { + // starting a new effect + cent->pe.cueZombieSpirit = qtrue; + cent->pe.zombieSpiritStartTime = cent->currentState.effect1Time; + cent->pe.lastZombieSpirit = cg.time; + cent->pe.nextZombieSpiritSound = cg.time + sndDelay; + for ( i = 0; i < MAX_ZOMBIE_SPIRITS; i++ ) { + cent->pe.zombieSpiritTrailHead[i] = -1; + cent->pe.zombieSpiritRotationTimes[i] = minRotationTime + ( random() * ( maxRotationTime - minRotationTime ) ); + cent->pe.zombieSpiritRadiusCycleTimes[i] = minRadiusCycleTime + ( random() * ( maxRadiusCycleTime - minRadiusCycleTime ) ); + cent->pe.zombieSpiritStartTimes[i] = cent->currentState.effect1Time; + } + } + cent->pe.zombieSpiritEndTime = cg.time; + + } else { + + // if running another effect, dont mess with its variables + if ( cent->currentState.eFlags & EF_MONSTER_EFFECT3 || cent->currentState.effect1Time < cent->currentState.effect3Time ) { + return; + } + + if ( !cent->pe.zombieSpiritEndTime ) { + return; + } + // clear the flag, and let the effect fade itself out + cent->pe.cueZombieSpirit = qfalse; + } + + for ( t = cent->pe.lastZombieSpirit + step; t <= cg.time; t += step ) { + + // add the spirits + for ( i = 0; i < MAX_ZOMBIE_SPIRITS; i++ ) { + + if ( cent->pe.zombieSpiritTrailHead[i] < -1 ) { + // spirit has gone, create a new one + cent->pe.zombieSpiritTrailHead[i] = -1; + cent->pe.zombieSpiritRotationTimes[i] = minRotationTime + ( random() * ( maxRotationTime - minRotationTime ) ); + cent->pe.zombieSpiritRadiusCycleTimes[i] = minRadiusCycleTime + ( random() * ( maxRadiusCycleTime - minRadiusCycleTime ) ); + cent->pe.zombieSpiritStartTimes[i] = cg.time - step; + } + + fadeRatio = (float)( cg.time - cent->pe.zombieSpiritStartTimes[i] ) / (float)fadeInTime; + if ( fadeRatio < 0.0 ) { + fadeRatio = 0.0; + } + if ( fadeRatio > 1.0 ) { + fadeRatio = 1.0; + } + + if ( cent->pe.cueZombieSpirit ) { + alpha = fadeRatio; + } else { + alpha = 1.0 - ( (float)( cg.time - cent->pe.zombieSpiritEndTime ) / (float)fadeOutTime ); + fadeRatio = alpha; + if ( alpha < 0.0 ) { + cent->pe.zombieSpiritTrailHead[i] = -2; // kill it + continue; + } + } + + active = qtrue; // we have an active spirit, so continue effect + + alpha *= 0.3; + + if ( cent->pe.cueZombieSpirit ) { + rotationTime = cent->pe.zombieSpiritRotationTimes[i]; + radiusCycleTime = cent->pe.zombieSpiritRadiusCycleTimes[i]; + + radius = ( minDist + sin( M_PI * 2 * (float)( (float)( (int)( t + ( (float)( radiusCycleTime * i ) / MAX_ZOMBIE_SPIRITS ) ) % radiusCycleTime ) / (float)radiusCycleTime ) ) * ( maxDist - minDist ) ); + + // get the position + v[0] = ( 0.5 + 0.5 * fadeRatio ) * sin( M_PI * 2 * (float)( (float)( (int)( t + ( (float)( rotationTime * i ) / MAX_ZOMBIE_SPIRITS ) ) % rotationTime ) / (float)rotationTime ) ) * radius; + v[1] = ( 0.5 + 0.5 * fadeRatio ) * cos( M_PI * 2 * (float)( (float)( (int)( t + ( (float)( rotationTime * i ) / MAX_ZOMBIE_SPIRITS ) ) % rotationTime ) / (float)rotationTime ) ) * radius; + v[2] = 12 + 36 * ( 0.5 + 0.5 * fadeRatio ) * sin( M_PI * 2 * (float)( (float)( (int)( t + ( (float)( zCycleTime * i ) / MAX_ZOMBIE_SPIRITS ) ) % zCycleTime ) / (float)zCycleTime ) ); + v[2] -= ( 1.0 - fadeRatio ) * 32; + + VectorAdd( cent->lerpOrigin, v, p[i] ); + } else { + // expand the radius, if it enters world geometry, kill it + rotationTime = cent->pe.zombieSpiritRotationTimes[i]; + radiusCycleTime = cent->pe.zombieSpiritRadiusCycleTimes[i]; + + radius = pow( 1.0 - fadeRatio, 2 ) * fadeDist + ( 1.0 - pow( 1.0 - fadeRatio, 2 ) ) * ( minDist + sin( M_PI * 2 * (float)( (float)( (int)( t + ( (float)( radiusCycleTime * i ) / MAX_ZOMBIE_SPIRITS ) ) % radiusCycleTime ) / (float)radiusCycleTime ) ) * ( maxDist - minDist ) ); + + // get the position + v[0] = sin( M_PI * 2 * (float)( (float)( (int)( t + ( (float)( rotationTime * i ) / MAX_ZOMBIE_SPIRITS ) ) % rotationTime ) / (float)rotationTime ) ) * radius; + v[1] = cos( M_PI * 2 * (float)( (float)( (int)( t + ( (float)( rotationTime * i ) / MAX_ZOMBIE_SPIRITS ) ) % rotationTime ) / (float)rotationTime ) ) * radius; + v[2] = 12 + 36 * sin( M_PI * 2 * (float)( (float)( (int)( t + ( (float)( zCycleTime * i ) / MAX_ZOMBIE_SPIRITS ) ) % zCycleTime ) / (float)zCycleTime ) ); + v[2] -= ( 1.0 - fadeRatio ) * 32; + + VectorAdd( cent->lerpOrigin, v, p[i] ); + + // check for sinking into geometry + trap_CM_BoxTrace( &trace, p[i], p[i], NULL, NULL, 0, MASK_SOLID ); + // if we hit something, clip the velocity, but maintain speed + if ( trace.startsolid ) { + cent->pe.zombieSpiritTrailHead[i] = -2; // kill it + continue; + } + } + + VectorSubtract( p[i], cent->pe.zombieSpiritPos[i], cent->pe.zombieSpiritDir[i] ); + cent->pe.zombieSpiritSpeed[i] = 1000.0 / step * VectorNormalize( cent->pe.zombieSpiritDir[i] ); + VectorCopy( p[i], cent->pe.zombieSpiritPos[i] ); + + cent->pe.zombieSpiritTrailHead[i] = CG_AddTrailJunc( cent->pe.zombieSpiritTrailHead[i], + cgs.media.zombieSpiritTrailShader, + t, + STYPE_STRETCH, + p[i], + trailLife * 2, + alpha, + 0.0, + ( 0.5 + 0.5 * fadeRatio ) * idealWidth, + 0, + TJFL_NOCULL, + colorWhite, + colorWhite, + 1.0, 1 ); + + } + + cent->pe.lastZombieSpirit = t; + + if ( !active ) { // effect has gone + cent->pe.zombieSpiritEndTime = 0; + } + } + + // add the skull at the head of the spirits + memset( &refent, 0, sizeof( refent ) ); + refent.hModel = cgs.media.spiritSkullModel; + refent.backlerp = 0; + refent.renderfx = RF_NOSHADOW | RF_MINLIGHT; //----(SA) + refent.customShader = cgs.media.zombieSpiritSkullShader; + refent.reType = RT_MODEL; + for ( i = 0; i < MAX_ZOMBIE_SPIRITS; i++ ) { + if ( cent->pe.zombieSpiritTrailHead[i] < -1 ) { + continue; // spirit has gone + } + fadeRatio = (float)( cg.time - cent->pe.zombieSpiritStartTimes[i] ) / (float)fadeInTime; + if ( fadeRatio < 0.0 ) { + fadeRatio = 0.0; + } + if ( fadeRatio > 1.0 ) { + fadeRatio = 1.0; + } + + if ( cent->pe.cueZombieSpirit ) { + alpha = fadeRatio; + } else { + alpha = 1.0 - ( (float)( cg.time - cent->pe.zombieSpiritEndTime ) / (float)fadeOutTime ); + fadeRatio = alpha; + if ( alpha < 0.0 ) { + cent->pe.zombieSpiritTrailHead[i] = -2; // kill it + continue; + } + } + + refent.shaderRGBA[3] = (byte)( 0.5 * alpha * 255.0 ); + VectorCopy( cent->pe.zombieSpiritPos[i], refent.origin ); + + // HACK!!! skull model is back-to-front, need to fix + VectorInverse( cent->pe.zombieSpiritDir[i] ); + vectoangles( cent->pe.zombieSpiritDir[i], ang ); + VectorInverse( cent->pe.zombieSpiritDir[i] ); + AnglesToAxis( ang, refent.axis ); + // create the non-normalized axis so we can size it + refent.nonNormalizedAxes = qtrue; + for ( t = 0; t < 3; t++ ) { + VectorNormalize( refent.axis[t] ); + VectorScale( refent.axis[t], 0.35, refent.axis[t] ); + } + // + // add the sound + trap_S_AddLoopingSound( cent->currentState.number, cent->lerpOrigin, vec3_origin, cgs.media.zombieSpiritLoopSound, fadeRatio ); + // + // if this spirit is in a good position to be released and head to the enemy, then release it + if ( fadeRatio == 1.0 && ( lastSpiritRelease > cg.time || ( lastSpiritRelease < cg.time - 2000 ) ) ) { + VectorSubtract( cent->currentState.origin2, refent.origin, v ); + VectorNormalize( v ); + if ( DotProduct( cent->pe.zombieSpiritDir[i], v ) > 0.6 || ( cent->currentState.eFlags & EF_DEAD ) ) { + // check for sinking into geometry + trap_CM_BoxTrace( &trace, refent.origin, refent.origin, NULL, NULL, 0, MASK_SOLID ); + // if we hit something, don't release it yet + if ( !trace.startsolid ) { + if ( cent->pe.zombieSpiritSpeed[i] < 300 ) { + cent->pe.zombieSpiritSpeed[i] = 300; + } + VectorScale( cent->pe.zombieSpiritDir[i], cent->pe.zombieSpiritSpeed[i], v ); + CG_SpawnZombieSpirit( refent.origin, v, cent->pe.zombieSpiritTrailHead[i], cent->currentState.number, &refent, trailLife, idealWidth ); + lastSpiritRelease = cg.time; + cent->pe.zombieSpiritTrailHead[i] = -2; // kill this version of it + continue; + } + } + } + // + // if we didn't kill it, draw it + trap_R_AddRefEntityToScene( &refent ); + } + + if ( cg.time > cent->pe.nextZombieSpiritSound && cent->pe.cueZombieSpirit ) { //&& (cg.time < cent->pe.zombieSpiritStartTime + sndDuration)) { + // spawn a new sound + trap_S_StartSound( cent->lerpOrigin, -1, CHAN_AUTO, cgs.media.zombieSpiritSound ); + cent->pe.nextZombieSpiritSound = cg.time + sndIntervalMin + (int)( (float)( sndIntervalMax - sndIntervalMin ) * random() ); + } + + // add a negative light around us + fadeRatio = (float)( cg.time - cent->pe.zombieSpiritStartTime ) / (float)fadeInTime; + if ( fadeRatio < 0.0 ) { + fadeRatio = 0.0; + } + if ( fadeRatio > 1.0 ) { + fadeRatio = 1.0; + } + + if ( cent->pe.cueZombieSpirit ) { + alpha = fadeRatio; + } else { + alpha = 1.0 - ( (float)( cg.time - cent->pe.zombieSpiritEndTime ) / (float)fadeOutTime ); + fadeRatio = alpha; + if ( alpha < 0.0 ) { + cent->pe.zombieSpiritEndTime = 0; // stop the effect + return; + } + } + fadeRatio *= 0.7; + trap_R_AddLightToScene( cent->lerpOrigin, 300.0, 1.0 * fadeRatio, 1.0 * fadeRatio, 1.0 * fadeRatio, 10 ); +} + +/* +============== +CG_SpawnZombieBat +============== +*/ +void CG_SpawnZombieBat( centity_t *cent, refEntity_t *oldrefent ) { + localEntity_t *le; + refEntity_t *re; + + le = CG_AllocLocalEntity(); + re = &le->refEntity; + + *re = *oldrefent; + + le->leType = LE_ZOMBIE_BAT; + le->startTime = cg.time; + le->endTime = le->startTime + 6000; // TODO: some kind of effect when the bat "burns up" + + le->pos.trType = TR_LINEAR; + le->pos.trTime = cg.time; + CG_PositionEntityOnTag( re, ¢->pe.headRefEnt, "tag_mouth", 0, NULL ); + VectorCopy( re->origin, le->pos.trBase ); + VectorScale( re->axis[0], 150 + 50 * random(), le->pos.trDelta ); + + //le->effectWidth = trailLife; + //le->radius = idealWidth; + le->lastTrailTime = cg.time; + //le->headJuncIndex = trailHead; + le->loopingSound = cgs.media.batsFlyingLoopSound; + + le->ownerNum = cent->currentState.number; + + re->fadeStartTime = le->endTime - 2000; + re->fadeEndTime = le->endTime; +} + +/* +============== +CG_AddZombieFlameEffect +============== +*/ +void CG_AddZombieFlameEffect( centity_t *cent ) { + //const float flameRadius = ZOMBIE_FLAME_RADIUS*2; // TTimo: unused + + const int fadeInTime = 500; + const int fadeOutTime = 0; + + // TTimo: unused + /* + const int spawnIntervalMin = 300; + const int spawnIntervalMax = 1200; + + const int sndIntervalMin = 300; + const int sndIntervalMax = 1400; + */ + const int sndDelay = 0; + // const int sndDuration = 99999; // TTimo: unused + + // const int step = 50; // TTimo: unused + + vec3_t morg, maxis[3], mang; + + float alpha, fadeRatio; + + // qboolean active=qfalse; // TTimo: unused + + if ( cent->currentState.aiChar != AICHAR_ZOMBIE ) { + return; + } + + if ( cent->currentState.eFlags & EF_DEAD ) { + return; + } + + if ( !IS_FLAMING_ZOMBIE( cent->currentState ) ) { + return; + } + + if ( cent->currentState.time > cg.time ) { // doing short burst + return; + } + + if ( ( cent->currentState.eFlags & EF_MONSTER_EFFECT3 ) && ( cg.time > cent->currentState.effect3Time ) ) { + + if ( !cent->pe.cueZombieSpirit ) { + // starting a new effect + cent->pe.cueZombieSpirit = qtrue; + cent->pe.zombieSpiritStartTime = cent->currentState.effect3Time; + cent->pe.lastZombieSpirit = cg.time; + cent->pe.nextZombieSpiritSound = cg.time + sndDelay; + } + cent->pe.zombieSpiritEndTime = cg.time + fadeOutTime; + } else { + + // if running another effect, dont mess with its variables + if ( cent->currentState.eFlags & EF_MONSTER_EFFECT || cent->currentState.effect1Time > cent->currentState.effect3Time ) { + CG_FireFlameChunks( cent, morg, mang, 0.05, qfalse, 0 ); + return; + } + + if ( cent->pe.zombieSpiritEndTime < cg.time ) { + CG_FireFlameChunks( cent, morg, mang, 0.05, qfalse, 0 ); + return; + } + + // clear the flag, and let the effect fade itself out + cent->pe.cueZombieSpirit = qfalse; + } + + // expand the flame dlight + fadeRatio = (float)( cg.time - cent->pe.zombieSpiritStartTime ) / (float)fadeInTime; + if ( fadeRatio < 0.0 ) { + fadeRatio = 0.0; + } + if ( fadeRatio > 1.0 ) { + fadeRatio = 1.0; + } + + if ( cent->pe.cueZombieSpirit ) { + alpha = fadeRatio; + } else { + alpha = ( (float)( cent->pe.zombieSpiritEndTime - cg.time ) / (float)fadeOutTime ); + fadeRatio = alpha; + if ( alpha < 0.0 ) { + cent->pe.zombieSpiritEndTime = 0; // stop the effect + CG_FireFlameChunks( cent, morg, mang, 0.1, qfalse, 0 ); + return; + } + } + + if ( fadeRatio >= 1.0 ) { + CG_GetOriginForTag( cent, ¢->pe.headRefEnt, "tag_mouth", 0, morg, maxis ); + AxisToAngles( maxis, mang ); + CG_FireFlameChunks( cent, morg, mang, ZOMBIE_FLAME_SCALE, qtrue, 0 ); + trap_S_AddLoopingSound( cent->currentState.number, cent->lerpOrigin, vec3_origin, cgs.media.flameSound, 50 ); + } +} + + +/* +============== +CG_AddZombieFlameEffect +============== +*/ +void CG_AddZombieFlameShort( centity_t *cent ) { + vec3_t morg, maxis[3], mang; + + if ( cent->currentState.aiChar != AICHAR_ZOMBIE ) { + return; + } + + if ( cent->currentState.eFlags & EF_DEAD ) { + return; + } + + if ( !IS_FLAMING_ZOMBIE( cent->currentState ) ) { + return; + } + + if ( cent->currentState.time < cg.time ) { + return; + } + + CG_GetOriginForTag( cent, ¢->pe.headRefEnt, "tag_mouth", 0, morg, maxis ); + AxisToAngles( maxis, mang ); + + // shoot this only in bursts + if ( ( cg.time + cent->currentState.number * 100 ) % 1000 > 200 ) { + CG_FireFlameChunks( cent, morg, cent->lerpAngles, 0.1, qfalse, 0 ); + return; + } + + CG_FireFlameChunks( cent, morg, cent->lerpAngles, 0.4, 2, 0 ); + trap_S_AddLoopingSound( cent->currentState.number, cent->lerpOrigin, vec3_origin, cgs.media.flameSound, 50 ); +} + +//========================================================================== + +/* +=============== +LoperLightningEffect + + If loper is alive, a constant lightning effect surrounds him +=============== +*/ +void CG_AddLoperLightningEffect( centity_t *cent ) { +#define LOPER_LIGHTNING_POINT_TIMEOUT 200 +#define LOPER_LIGHTNING_MAX_DIST 360 +#define LOPER_LIGHTNING_NORMAL_DIST 80 +#define LOPER_MAX_POINT_TESTS 10 +#define LOPER_MAX_POINT_TESTS_PERFRAME 20 + + int i, j, pointTests = 0; + vec3_t testPos, tagPos, c, v; + trace_t tr; + float maxDist; + int numPoints; + float colTake; + + if ( cent->currentState.aiChar != AICHAR_LOPER ) { + return; + } + + if ( !cent->currentValid ) { + return; + } + + if ( cent->currentState.eFlags & EF_DEAD ) { + return; + } + + if ( !cent->pe.legsRefEnt.hModel ) { + return; + } + + if ( cent->currentState.eFlags & EF_MONSTER_EFFECT3 ) { + maxDist = LOPER_LIGHTNING_MAX_DIST; + numPoints = MAX_LOPER_LIGHTNING_POINTS; + } else { + maxDist = LOPER_LIGHTNING_NORMAL_DIST; + numPoints = MAX_LOPER_LIGHTNING_POINTS / 3; + } + + CG_GetOriginForTag( cent, ¢->pe.legsRefEnt, "tag_spinner", 0, tagPos, NULL ); + + // show a dlight + // color + colTake = 0.8 - fabs( sin( cg.time ) ) * 0.3; + c[0] = 1.0 - colTake; + c[1] = 1.0 - 0.7 * colTake; + c[2] = 1.0; //c[1] + 0.2; + if ( c[2] > 1.0 ) { + c[2] = 1.0; + } + //VectorScale( c, alpha, c ); + // add the light + trap_R_AddLightToScene( tagPos, LOPER_LIGHTNING_NORMAL_DIST * ( 2.5 + ( 1.0 + sin( cg.time ) ) / 4.0 ), c[0], c[1], c[2], 1 ); + + for ( i = 0; i < numPoints; i++ ) { + // if this point has timed out, find a new spot + if ( ( cent->currentState.eFlags & EF_MONSTER_EFFECT ) && + ( ( !cent->pe.lightningTimes[i] ) || + ( cent->pe.lightningTimes[i] > cg.time ) || + ( cent->pe.lightningTimes[i] < cg.time - 50 ) || + ( VectorDistance( cent->lerpOrigin, cent->pe.lightningPoints[i] ) > maxDist ) ) ) { + // attacking the player + VectorSet( testPos, 12 * crandom(), + 12 * crandom(), + 32 * crandom() ); + VectorAdd( testPos, cg.snap->ps.origin, testPos ); + cent->pe.lightningTimes[i] = cg.time - rand() % ( LOPER_LIGHTNING_POINT_TIMEOUT / 2 ); + VectorCopy( testPos, cent->pe.lightningPoints[i] ); + // play a zap sound + if ( cent->pe.lightningSoundTime < cg.time - 100 ) { + trap_S_StartSound( testPos, ENTITYNUM_WORLD, CHAN_AUTO, cgs.media.lightningZap /*cgs.media.lightningSounds[rand()%3]*/ ); + cent->pe.lightningSoundTime = cg.time; + } + } else if ( ( !cent->pe.lightningTimes[i] ) || + ( cent->pe.lightningTimes[i] > cg.time ) || + ( cent->pe.lightningTimes[i] < cg.time - LOPER_LIGHTNING_POINT_TIMEOUT ) || + ( VectorDistance( cent->lerpOrigin, cent->pe.lightningPoints[i] ) > maxDist ) ) { + + if ( cent->currentState.groundEntityNum == ENTITYNUM_NONE ) { + continue; // must be on the ground + + } + // find a new spot + for ( j = 0; j < LOPER_MAX_POINT_TESTS; j++ ) { + VectorSet( testPos, maxDist * crandom(), + maxDist * crandom(), + maxDist * ( crandom() - 0.5 ) ); + VectorAdd( testPos, cent->lerpOrigin, testPos ); + // try a trace to find a world collision + CG_Trace( &tr, cent->lerpOrigin, NULL, NULL, testPos, cent->currentState.number, MASK_SOLID ); + if ( tr.fraction < 1 && tr.entityNum == ENTITYNUM_WORLD ) { + // found a valid spot! + cent->pe.lightningTimes[i] = cg.time - rand() % ( LOPER_LIGHTNING_POINT_TIMEOUT / 2 ); + VectorCopy( tr.endpos, cent->pe.lightningPoints[i] ); + // play a zap sound + if ( cent->pe.lightningSoundTime < cg.time - 100 ) { + // HACK, move ths sound away from the viewpos, to simulate lower volume + VectorSubtract( testPos, cg.refdef.vieworg, v ); + VectorMA( cg.refdef.vieworg, 3.0, v, v ); + trap_S_StartSound( v, ENTITYNUM_WORLD, CHAN_AUTO, cgs.media.lightningSounds[rand() % 3] ); + cent->pe.lightningSoundTime = cg.time; + } + break; + } + if ( pointTests++ > LOPER_MAX_POINT_TESTS_PERFRAME ) { + j = LOPER_MAX_POINT_TESTS; + continue; + } + } + if ( j == LOPER_MAX_POINT_TESTS ) { + continue; // just don't draw this point + } + } + // + // we have a valid lightning point, so draw it + // sanity check though to make sure it's valid + if ( VectorDistance( cent->lerpOrigin, cent->pe.lightningPoints[i] ) <= maxDist ) { + CG_DynamicLightningBolt( cgs.media.lightningBoltShader, tagPos, cent->pe.lightningPoints[i], 1, 25 + 12.0 * random(), ( cent->currentState.eFlags & EF_MONSTER_EFFECT ) == 0, 1.0, 0, i * i * 2 ); + } + } +} + +/* +=============== +LoperGroundEffect + + Electrical charge applied to ground through torso +=============== +*/ +void CG_AddLoperGroundEffect( centity_t *cent ) { +#define LOPER_GROUNDCHARGE_INTERVAL 30 +#define LOPER_GROUNDCHARGE_DURATION 100 +#define LOPER_GROUNDCHARGE_FADEOUT 400 +#define LOPER_GROUNDCHARGE_RADIUS 150 + vec3_t org, c; + //static vec3_t up = {0,0,1}; // TTimo: unused + float colTake; + int duration; + float alpha, lightAlpha = 0.0f; // TTimo: init + + if ( cent->currentState.aiChar != AICHAR_LOPER ) { + return; + } + + if ( !cent->currentValid ) { + return; + } + + if ( cent->currentState.eFlags & EF_DEAD ) { + return; + } + + if ( !cent->pe.legsRefEnt.hModel ) { + return; + } + + if ( !( cent->currentState.eFlags & EF_MONSTER_EFFECT3 ) ) { + if ( !cent->pe.loperGroundValidTime ) { + alpha = 0.0; + } else { + // alpha for lightning mark + duration = LOPER_GROUNDCHARGE_FADEOUT - ( cg.time - cent->pe.loperGroundValidTime ); + if ( duration <= 0 ) { + cent->pe.loperGroundValidTime = 0; + } + alpha = (float)duration / (float)LOPER_GROUNDCHARGE_FADEOUT; + if ( alpha < 0 ) { + alpha = 0; + } + // light lives on a bit after the last lightning mark is spawned + lightAlpha = (float)( duration + LOPER_GROUNDCHARGE_DURATION ) / (float)( LOPER_GROUNDCHARGE_FADEOUT + LOPER_GROUNDCHARGE_DURATION ); + if ( lightAlpha < 0 ) { + lightAlpha = 0; + } + } + } else { + cent->pe.loperGroundValidTime = cg.time; + duration = LOPER_GROUNDCHARGE_DURATION; + alpha = 1.0; + lightAlpha = 1.0; + } + + if ( !lightAlpha ) { + cent->pe.loperGroundValidTime = 0; + return; + } + + // show a dlight + // color + colTake = 0.8 - fabs( sin( cg.time ) ) * 0.3; + c[0] = 1.0 - colTake; + c[1] = 1.0 - 0.8 * colTake; + c[2] = 1.0; //c[1] + 0.2; + if ( c[2] > 1.0 ) { + c[2] = 1.0; + } + VectorScale( c, alpha, c ); + // add the light + trap_R_AddLightToScene( cent->lerpOrigin, LOPER_GROUNDCHARGE_RADIUS * ( 3.0 + 2.0 * ( 1.0 + sin( 0.001 * ( ( cg.time ) % ( 1000 * ( 2 + cent->currentState.number ) ) ) ) ) / 2.0 ), c[0], c[1], c[2], 1 ); + //trap_R_AddLightToScene( cent->lerpOrigin, LOPER_GROUNDCHARGE_RADIUS*(2.0 + 1.0*(1.0+cos(0.001343*((cg.time)%(1000*(2+cent->currentState.number)))))/2.0), c[0], c[1], c[2], 0 ); + + if ( !alpha ) { + return; + } + + // create a fading mark at intervals + if ( cent->pe.loperLastGroundChargeTime < cg.time - LOPER_GROUNDCHARGE_INTERVAL ) { + // org + VectorCopy( cent->lerpOrigin, org ); + org[2] -= 20; + // color + if ( cent->pe.loperGroundChargeToggle ^= 1 ) { + // random blue + colTake = 0.5 + random() * 0.5; + c[0] = 1.0 - colTake; + c[1] = 1.0 - /*(0.5 + 0.5*random())**/ colTake; + c[2] = c[1] + 0.2; + if ( c[2] > 1.0 ) { + c[2] = 1.0; + } + } else { + VectorSet( c, 1,1,1 ); + } + // draw the mark + //CG_ImpactMark( cgs.media.loperGroundChargeShader, org, up, random()*360, c[0], c[1], c[2], alpha, qtrue, (0.5+0.5*random())*LOPER_GROUNDCHARGE_RADIUS, qfalse, LOPER_GROUNDCHARGE_DURATION ); + cent->pe.loperLastGroundChargeTime = cg.time; + // make a new sound + VectorSet( org, org[0] + crandom() * 256, org[1] + crandom() * 256, org[2] + crandom() * 256 ); + trap_S_StartSound( org, ENTITYNUM_WORLD, CHAN_AUTO, cgs.media.lightningZap ); + } + +} + +//========================================================================== + +/* +============== +CG_SpawnHelgaSpirit +============== +*/ +void CG_SpawnHelgaSpirit( vec3_t origin, vec3_t vel, int trailHead, int ownerNum, refEntity_t *oldrefent, int trailLife, int idealWidth ) { + localEntity_t *le; + refEntity_t *re; + + le = CG_AllocLocalEntity(); + re = &le->refEntity; + + *re = *oldrefent; + + le->leType = LE_HELGA_SPIRIT; + le->startTime = cg.time - 5000; // set it back so we dont fade it in like the "end" spirits + le->endTime = cg.time + 5000; + + le->pos.trType = TR_LINEAR; + le->pos.trTime = cg.time; + VectorCopy( origin, le->pos.trBase ); + VectorCopy( vel, le->pos.trDelta ); + + le->effectWidth = trailLife; + le->radius = idealWidth; + le->lastTrailTime = cg.time; + le->headJuncIndex = trailHead; + le->loopingSound = cgs.media.helgaSpiritLoopSound; + + le->ownerNum = ownerNum; + + re->fadeStartTime = le->endTime - 2000; + re->fadeEndTime = le->endTime; + re->shaderTime = cg.time; +} + +/* +============== +CG_AddHelgaSpiritEffect +============== +*/ +void CG_AddHelgaSpiritEffect( centity_t *cent ) { + const int trailLife = 600; + const float idealWidth = 30.0; + const int fadeInTime = 2000; + const int fadeOutTime = 2000; + const int minRotationTime = 6000; + const int maxRotationTime = 10000; + const int minRadiusCycleTime = 2400; + const int maxRadiusCycleTime = 2900; + const int zCycleTime = 3000; + + const float minDist = 50; + const float maxDist = 100; + const float fadeDist = 4; + + const int sndIntervalMin = 300; + const int sndIntervalMax = 1400; + const int sndDelay = 0; + //const int sndDuration = 99999;//1500; // TTimo: unused + + const int step = 25; + + int i, t; + vec3_t v,p[MAX_ZOMBIE_SPIRITS], ang; + float fadeRatio, alpha, radius; + int rotationTime, radiusCycleTime; + trace_t trace; + refEntity_t refent; + + static int lastSpiritRelease; + + qboolean active = qfalse; + + if ( cent->currentState.aiChar != AICHAR_HELGA ) { + return; + } + + // sanity check the server time to make sure we don't start the effect + // to early, whilst reloading a savegame or something + if ( cg.time < cent->currentState.effect1Time ) { + return; + } + + if ( cent->currentState.eFlags & EF_MONSTER_EFFECT ) { + + if ( !cent->pe.cueZombieSpirit ) { + // starting a new effect + cent->pe.cueZombieSpirit = qtrue; + cent->pe.zombieSpiritStartTime = cent->currentState.effect1Time; + cent->pe.lastZombieSpirit = cg.time; + cent->pe.nextZombieSpiritSound = cg.time + sndDelay; + for ( i = 0; i < MAX_ZOMBIE_SPIRITS; i++ ) { + cent->pe.zombieSpiritTrailHead[i] = -1; + cent->pe.zombieSpiritRotationTimes[i] = minRotationTime + ( random() * ( maxRotationTime - minRotationTime ) ); + cent->pe.zombieSpiritRadiusCycleTimes[i] = minRadiusCycleTime + ( random() * ( maxRadiusCycleTime - minRadiusCycleTime ) ); + cent->pe.zombieSpiritStartTimes[i] = cent->currentState.effect1Time; + } + } + cent->pe.zombieSpiritEndTime = cg.time; + + } else { + + // if running another effect, dont mess with its variables + if ( cent->currentState.eFlags & EF_MONSTER_EFFECT3 || cent->currentState.effect1Time < cent->currentState.effect3Time ) { + return; + } + + if ( !cent->pe.zombieSpiritEndTime ) { + return; + } + // clear the flag, and let the effect fade itself out + cent->pe.cueZombieSpirit = qfalse; + } + + for ( t = cent->pe.lastZombieSpirit + step; t <= cg.time; t += step ) { + + // add the spirits + for ( i = 0; i < MAX_ZOMBIE_SPIRITS; i++ ) { + + if ( cent->pe.zombieSpiritTrailHead[i] < -1 ) { + // spirit has gone, create a new one + cent->pe.zombieSpiritTrailHead[i] = -1; + cent->pe.zombieSpiritRotationTimes[i] = minRotationTime + ( random() * ( maxRotationTime - minRotationTime ) ); + cent->pe.zombieSpiritRadiusCycleTimes[i] = minRadiusCycleTime + ( random() * ( maxRadiusCycleTime - minRadiusCycleTime ) ); + cent->pe.zombieSpiritStartTimes[i] = cg.time - step; + } + + fadeRatio = (float)( cg.time - cent->pe.zombieSpiritStartTimes[i] ) / (float)fadeInTime; + if ( fadeRatio < 0.0 ) { + fadeRatio = 0.0; + } + if ( fadeRatio > 1.0 ) { + fadeRatio = 1.0; + } + + if ( cent->pe.cueZombieSpirit ) { + alpha = fadeRatio; + } else { + alpha = 1.0 - ( (float)( cg.time - cent->pe.zombieSpiritEndTime ) / (float)fadeOutTime ); + fadeRatio = alpha; + if ( alpha < 0.0 ) { + cent->pe.zombieSpiritTrailHead[i] = -2; // kill it + continue; + } + } + + active = qtrue; // we have an active spirit, so continue effect + + alpha *= 0.3; + + if ( cent->pe.cueZombieSpirit ) { + rotationTime = cent->pe.zombieSpiritRotationTimes[i]; + radiusCycleTime = cent->pe.zombieSpiritRadiusCycleTimes[i]; + + radius = ( minDist + sin( M_PI * 2 * (float)( (float)( (int)( t + ( (float)( radiusCycleTime * i ) / MAX_ZOMBIE_SPIRITS ) ) % radiusCycleTime ) / (float)radiusCycleTime ) ) * ( maxDist - minDist ) ); + + // get the position + v[0] = ( 0.5 + 0.5 * fadeRatio ) * sin( M_PI * 2 * (float)( (float)( (int)( t + ( (float)( rotationTime * i ) / MAX_ZOMBIE_SPIRITS ) ) % rotationTime ) / (float)rotationTime ) ) * radius; + v[1] = ( 0.5 + 0.5 * fadeRatio ) * cos( M_PI * 2 * (float)( (float)( (int)( t + ( (float)( rotationTime * i ) / MAX_ZOMBIE_SPIRITS ) ) % rotationTime ) / (float)rotationTime ) ) * radius; + v[2] = 12 + 36 * ( 0.5 + 0.5 * fadeRatio ) * sin( M_PI * 2 * (float)( (float)( (int)( t + ( (float)( zCycleTime * i ) / MAX_ZOMBIE_SPIRITS ) ) % zCycleTime ) / (float)zCycleTime ) ); + v[2] -= ( 1.0 - fadeRatio ) * 32; + + VectorAdd( cent->lerpOrigin, v, p[i] ); + } else { + // expand the radius, if it enters world geometry, kill it + rotationTime = cent->pe.zombieSpiritRotationTimes[i]; + radiusCycleTime = cent->pe.zombieSpiritRadiusCycleTimes[i]; + + radius = pow( 1.0 - fadeRatio, 2 ) * fadeDist + ( 1.0 - pow( 1.0 - fadeRatio, 2 ) ) * ( minDist + sin( M_PI * 2 * (float)( (float)( (int)( t + ( (float)( radiusCycleTime * i ) / MAX_ZOMBIE_SPIRITS ) ) % radiusCycleTime ) / (float)radiusCycleTime ) ) * ( maxDist - minDist ) ); + + // get the position + v[0] = sin( M_PI * 2 * (float)( (float)( (int)( t + ( (float)( rotationTime * i ) / MAX_ZOMBIE_SPIRITS ) ) % rotationTime ) / (float)rotationTime ) ) * radius; + v[1] = cos( M_PI * 2 * (float)( (float)( (int)( t + ( (float)( rotationTime * i ) / MAX_ZOMBIE_SPIRITS ) ) % rotationTime ) / (float)rotationTime ) ) * radius; + v[2] = 12 + 36 * sin( M_PI * 2 * (float)( (float)( (int)( t + ( (float)( zCycleTime * i ) / MAX_ZOMBIE_SPIRITS ) ) % zCycleTime ) / (float)zCycleTime ) ); + v[2] -= ( 1.0 - fadeRatio ) * 32; + + VectorAdd( cent->lerpOrigin, v, p[i] ); + + // check for sinking into geometry + trap_CM_BoxTrace( &trace, p[i], p[i], NULL, NULL, 0, MASK_SOLID ); + // if we hit something, clip the velocity, but maintain speed + if ( trace.startsolid ) { + cent->pe.zombieSpiritTrailHead[i] = -2; // kill it + continue; + } + } + + VectorSubtract( p[i], cent->pe.zombieSpiritPos[i], cent->pe.zombieSpiritDir[i] ); + cent->pe.zombieSpiritSpeed[i] = 1000.0 / step * VectorNormalize( cent->pe.zombieSpiritDir[i] ); + VectorCopy( p[i], cent->pe.zombieSpiritPos[i] ); + + cent->pe.zombieSpiritTrailHead[i] = CG_AddTrailJunc( cent->pe.zombieSpiritTrailHead[i], + cgs.media.zombieSpiritTrailShader, + t, + STYPE_STRETCH, + p[i], + trailLife * 2, + alpha, + 0.0, + ( 0.5 + 0.5 * fadeRatio ) * idealWidth, + 0, + TJFL_NOCULL, + colorWhite, + colorWhite, + 1.0, 1 ); + + } + + cent->pe.lastZombieSpirit = t; + + if ( !active ) { // effect has gone + cent->pe.zombieSpiritEndTime = 0; + } + } + + // add the skull at the head of the spirits + memset( &refent, 0, sizeof( refent ) ); + refent.hModel = cgs.media.helgaGhostModel; + refent.backlerp = 0; + refent.renderfx = RF_NOSHADOW | RF_MINLIGHT; //----(SA) + refent.customShader = cgs.media.helgaSpiritSkullShader; + refent.reType = RT_MODEL; + for ( i = 0; i < MAX_ZOMBIE_SPIRITS; i++ ) { + if ( cent->pe.zombieSpiritTrailHead[i] < -1 ) { + continue; // spirit has gone + } + fadeRatio = (float)( cg.time - cent->pe.zombieSpiritStartTimes[i] ) / (float)fadeInTime; + if ( fadeRatio < 0.0 ) { + fadeRatio = 0.0; + } + if ( fadeRatio > 1.0 ) { + fadeRatio = 1.0; + } + + if ( cent->pe.cueZombieSpirit ) { + alpha = fadeRatio; + } else { + alpha = 1.0 - ( (float)( cg.time - cent->pe.zombieSpiritEndTime ) / (float)fadeOutTime ); + fadeRatio = alpha; + if ( alpha < 0.0 ) { + cent->pe.zombieSpiritTrailHead[i] = -2; // kill it + continue; + } + } + + refent.shaderRGBA[3] = (byte)( 0.5 * alpha * 255.0 ); + VectorCopy( cent->pe.zombieSpiritPos[i], refent.origin ); + + // HACK!!! skull model is back-to-front, need to fix + //VectorInverse(cent->pe.zombieSpiritDir[i]); + vectoangles( cent->pe.zombieSpiritDir[i], ang ); + //VectorInverse(cent->pe.zombieSpiritDir[i]); + AnglesToAxis( ang, refent.axis ); +/* // create the non-normalized axis so we can size it + refent.nonNormalizedAxes = qtrue; + for (t=0; t<3; t++) { + VectorNormalize( refent.axis[t] ); + VectorScale( refent.axis[t], 0.35, refent.axis[t] ); + } +*/ // + // add the sound + trap_S_AddLoopingSound( -1, cent->lerpOrigin, vec3_origin, cgs.media.helgaSpiritLoopSound, fadeRatio ); + // + // if this spirit is in a good position to be released and head to the enemy, then release it + if ( fadeRatio == 1.0 && ( lastSpiritRelease > cg.time || ( lastSpiritRelease < cg.time - 1000 ) ) ) { + VectorSubtract( cent->currentState.origin2, refent.origin, v ); + VectorNormalize( v ); + if ( DotProduct( cent->pe.zombieSpiritDir[i], v ) > 0.4 || ( cent->currentState.eFlags & EF_DEAD ) ) { + // check for sinking into geometry + trap_CM_BoxTrace( &trace, refent.origin, refent.origin, NULL, NULL, 0, MASK_SOLID ); + // if we hit something, don't release it yet + if ( !trace.startsolid ) { + if ( cent->pe.zombieSpiritSpeed[i] < 300 ) { + cent->pe.zombieSpiritSpeed[i] = 300; + } + VectorScale( cent->pe.zombieSpiritDir[i], cent->pe.zombieSpiritSpeed[i], v ); + CG_SpawnHelgaSpirit( refent.origin, v, cent->pe.zombieSpiritTrailHead[i], cent->currentState.number, &refent, trailLife, idealWidth ); + lastSpiritRelease = cg.time; + cent->pe.zombieSpiritTrailHead[i] = -2; // kill this version of it + continue; + } + } + } + // + // if we didn't kill it, draw it + trap_R_AddRefEntityToScene( &refent ); + } + + if ( cg.time > cent->pe.nextZombieSpiritSound && cent->pe.cueZombieSpirit ) { //&& (cg.time < cent->pe.zombieSpiritStartTime + sndDuration)) { + // spawn a new sound + //trap_S_StartSound( cent->lerpOrigin, -1, CHAN_AUTO, cgs.media.helgaSpiritSound ); + CG_SoundPlayIndexedScript( cgs.media.helgaSpiritSound, NULL, cent->currentState.number ); + cent->pe.nextZombieSpiritSound = cg.time + sndIntervalMin + (int)( (float)( sndIntervalMax - sndIntervalMin ) * random() ); + } + + // add a negative light around us + fadeRatio = (float)( cg.time - cent->pe.zombieSpiritStartTime ) / (float)fadeInTime; + if ( fadeRatio < 0.0 ) { + fadeRatio = 0.0; + } + if ( fadeRatio > 1.0 ) { + fadeRatio = 1.0; + } + + if ( cent->pe.cueZombieSpirit ) { + alpha = fadeRatio; + } else { + alpha = 1.0 - ( (float)( cg.time - cent->pe.zombieSpiritEndTime ) / (float)fadeOutTime ); + fadeRatio = alpha; + if ( alpha < 0.0 ) { + cent->pe.zombieSpiritEndTime = 0; // stop the effect + return; + } + } + fadeRatio *= 0.7; + trap_R_AddLightToScene( cent->lerpOrigin, 500.0, 1.0 * fadeRatio, 1.0 * fadeRatio, 1.0 * fadeRatio, 10 ); +} + +//========================================================================== + +/* +=============== +CG_AddRefEntityWithPowerups + +Adds a piece with modifications or duplications for powerups +Also called by CG_Missile for quad rockets, but nobody can tell... +=============== +*/ +void CG_AddRefEntityWithPowerups( refEntity_t *ent, int powerups, int team, entityState_t *es, const vec3_t fireRiseDir ) { + centity_t *cent; + refEntity_t backupRefEnt; //, parentEnt; + qboolean onFire = qfalse; + float alpha = 0.0; + + cent = &cg_entities[es->number]; + + ent->entityNum = es->number; + + if ( cent->pe.forceLOD ) { + ent->reFlags |= REFLAG_FORCE_LOD; + } + + // RF, if in camera mode, force a full lod, since we are in a controlled environment + if ( cg.cameraMode ) { + ent->reFlags |= REFLAG_FULL_LOD; + } + +//----(SA) testing + // (SA) disabling +// if(cent->currentState.eFlags & EF_DEAD) { +// ent->reFlags |= REFLAG_DEAD_LOD; +// } +//----(SA) end + + backupRefEnt = *ent; + + if ( powerups & ( 1 << PW_INVIS ) ) { + ent->customShader = cgs.media.invisShader; + trap_R_AddRefEntityToScene( ent ); +#if 0 + // ------------------------------- + // Zombie effects + // + } else if ( es->aiChar == AICHAR_ZOMBIE ) { + + // Zombie needs special processing, to remove the bits of flesh that have been torn away + + if ( ent->hModel == cent->pe.torsoRefEnt.hModel ) { + //ent->reFlags = REFLAG_ZOMBIEFX; + ent->shaderTime = 0; + } else if ( ent->hModel == cent->pe.legsRefEnt.hModel ) { + //ent->reFlags = REFLAG_ZOMBIEFX2; // ref needs to know this is the legs + ent->shaderTime = 0; + } + + // first, check for portal spawning + if ( es->time2 ) { + if ( es->time2 < cg.time ) { + return; // not ready yet + } + // fade in the skeleton, skin should "compose" (reverse decomposition) + alpha = (float)( cg.time - es->time2 ) / PORTAL_ZOMBIE_SPAWNTIME; + if ( alpha > 1 ) { + alpha = 1; + } + // skeleton fades in towards end of effect + if ( alpha < 0.5 ) { + ent->shaderRGBA[3] = 0; + } else { ent->shaderRGBA[3] = ( unsigned char )( ( alpha - 0.5 ) * 2.0 * 255 );} + // + ent->shaderTime = 0.001 * ( 1.0 - alpha ) * ZOMBIEFX_FADEOUT_TIME; + + if ( ent->hModel == cent->pe.headRefEnt.hModel ) { + //ent->reFlags = REFLAG_ZOMBIEFX; + ent->customShader = cgs.media.zombieHeadFadeShader; + } + + trap_R_AddRefEntityToScene( ent ); + + // add flaming effect + onFire = qtrue; + alpha *= 0.5; + + } else { + + // if the Zombie is dead, the skin should decompose + + ent->shaderRGBA[3] = 255; + + if ( es->eFlags & EF_MONSTER_EFFECT2 && + cent->currentState.effect2Time < cg.time ) { // Ridah, Zombie death effect + + if ( ent->hModel == cent->pe.headRefEnt.hModel ) { + //ent->reFlags = REFLAG_ZOMBIEFX; + ent->customShader = cgs.media.zombieHeadFadeShader; + } + + ent->shaderTime = 0.001 * ( cg.time - cent->currentState.effect2Time ); + trap_R_AddRefEntityToScene( ent ); +/* + // skeleton: add legs and head parts + if (ent->hModel == cent->pe.legsRefEnt.hModel) { + ent->skinNum = 0; + ent->reFlags = 0; + ent->customShader = cgs.media.skeletonSkinShader; + + // legs + ent->hModel = cgs.media.skeletonLegsModel; + trap_R_AddRefEntityToScene( ent ); + + // torso (just get this so we can place the head correctly) + parentEnt = *ent; + CG_PositionEntityOnTag( ent, &parentEnt, parentEnt.hModel, "tag_torso", NULL ); + ent->hModel = cgs.media.skeletonTorsoModel; + + // head + parentEnt = *ent; + CG_PositionEntityOnTag( ent, &parentEnt, parentEnt.hModel, "tag_head", NULL ); + ent->hModel = cgs.media.skeletonHeadModel; + trap_R_AddRefEntityToScene( ent ); + } +*/ + } else { // show it normally + trap_R_AddRefEntityToScene( ent ); + } + } + + // restore previous state + *ent = backupRefEnt; +#endif +/* + } else if (es->eFlags & EF_MONSTER_EFFECT2 && es->aiChar == AICHAR_ZOMBIE && + cent->currentState.effect2Time < cg.time) { // Ridah, Zombie death effect + const int fadeRiseTime = 4000; + + if (cent->pe.zombieDeathFadeStart < cg.time && ent->hModel == cent->pe.legsRefEnt.hModel) { + // add the skeleton models starting with the legs + ent->fadeEndTime = 0; + ent->fadeStartTime = 0; + ent->skinNum = 0; + + // legs + ent->hModel = cgs.media.skeletonLegsModel; + ent->customSkin = cgs.media.skeletonLegsSkin; + trap_R_AddRefEntityToScene( ent ); + + // torso + parentEnt = *ent; + CG_PositionEntityOnTag( ent, &parentEnt, parentEnt.hModel, "tag_torso", NULL ); + ent->hModel = cgs.media.skeletonTorsoModel; + ent->customSkin = cgs.media.skeletonTorsoSkin; + trap_R_AddRefEntityToScene( ent ); + + // head + parentEnt = *ent; + CG_PositionEntityOnTag( ent, &parentEnt, parentEnt.hModel, "tag_head", NULL ); + ent->hModel = cgs.media.skeletonHeadModel; + ent->customSkin = cgs.media.skeletonHeadSkin; + trap_R_AddRefEntityToScene( ent ); + + // restore previous state + *ent = backupRefEnt; + } + + if (cent->pe.zombieDeathFadeEnd + fadeRiseTime > cg.time) { + // slowly fade the zombie "skin" out, revealing the skeleton underneath + + //VectorSubtract( ent->origin, cg.snap->ps.origin, ent->fireRiseDir ); + //VectorNegate( ent->axis[0], ent->fireRiseDir ); + VectorNormalize2( ent->axis[0], ent->fireRiseDir ); + + if (cent->pe.zombieDeathFadeEnd > cg.time) { + + // the zombie has hard-edged alpha blending on it's body texture by default + // so we need to override that for smooth fading + if (ent->hModel == cent->pe.legsRefEnt.hModel || + ent->hModel == cent->pe.torsoRefEnt.hModel) { + ent->customShader = cgs.media.zombieBodyFadeShader; + } else if (ent->hModel == cent->pe.headRefEnt.hModel) { + ent->customShader = cgs.media.zombieHeadFadeShader; + } + // fade the alpha from 0 -> 255 as the time goes, which will fade from front to back + if (cent->pe.zombieDeathFadeStart > cg.time) { + ent->shaderRGBA[3] = 128; + } else { + ent->shaderRGBA[3] = 128 - (unsigned char)(128.0*pow(((float)(cg.time - cent->pe.zombieDeathFadeStart) / (float)(cent->pe.zombieDeathFadeEnd - cent->pe.zombieDeathFadeStart)), 2)); + } + ent->shaderTime = 1.0; + + trap_R_AddRefEntityToScene( ent ); + } + } +*/ + // ------------------------------- + } else { + + if ( CG_EntOnFire( &cg_entities[es->number] ) ) { + ent->reFlags |= REFLAG_FORCE_LOD; + } + + trap_R_AddRefEntityToScene( ent ); + + if ( powerups & ( 1 << PW_QUAD ) ) { + if ( team == TEAM_RED ) { + ent->customShader = cgs.media.redQuadShader; + } else { + ent->customShader = cgs.media.quadShader; + } + trap_R_AddRefEntityToScene( ent ); + } + if ( powerups & ( 1 << PW_REGEN ) ) { + if ( ( ( cg.time / 100 ) % 10 ) == 1 ) { + ent->customShader = cgs.media.regenShader; + trap_R_AddRefEntityToScene( ent ); + } + } + if ( powerups & ( 1 << PW_BATTLESUIT ) ) { + ent->customShader = cgs.media.battleSuitShader; + trap_R_AddRefEntityToScene( ent ); + } + } + + if ( !onFire && CG_EntOnFire( &cg_entities[es->number] ) ) { + onFire = qtrue; + // set the alpha + alpha = ( cg.time - es->onFireStart ) / 1500.0; + if ( alpha > 1.0 ) { + alpha = ( es->onFireEnd - cg.time ) / 1500.0; + if ( alpha > 1.0 ) { + alpha = 1.0; + } + } + } + // Flaming zombie always shows a little fire + if ( !es->time2 && alpha < 1.0 && ( cent->currentState.aiChar == AICHAR_ZOMBIE ) && IS_FLAMING_ZOMBIE( cent->currentState ) /*&& !(cent->currentState.eFlags & EF_DEAD)*/ ) { + onFire = qtrue; + // set the alpha + alpha = 1.0; + } + + if ( onFire ) { + if ( alpha < 0.0 ) { + alpha = 0.0; + } + ent->shaderRGBA[3] = ( unsigned char )( 255.0 * alpha ); + VectorCopy( fireRiseDir, ent->fireRiseDir ); + if ( VectorCompare( ent->fireRiseDir, vec3_origin ) ) { + VectorSet( ent->fireRiseDir, 0, 0, 1 ); + } +/* + if (ent->fireRiseDir[2] > 0) + ent->fireRiseDir[2] *= -1; + + ent->customShader = cgs.media.dripWetShader2; + trap_R_AddRefEntityToScene( ent ); + + ent->customShader = cgs.media.dripWetShader; + trap_R_AddRefEntityToScene( ent ); + + VectorCopy( fireRiseDir, ent->fireRiseDir ); +*/ + ent->customShader = cgs.media.onFireShader; + trap_R_AddRefEntityToScene( ent ); + + ent->customShader = cgs.media.onFireShader2; + trap_R_AddRefEntityToScene( ent ); + + if ( ent->hModel == cent->pe.legsRefEnt.hModel ) { + trap_S_AddLoopingSound( es->number, ent->origin, vec3_origin, cgs.media.flameCrackSound, (int)( 40.0 * alpha ) ); + } + } + + // tesla effect + if ( cg_entities[es->number].pe.teslaDamagedTime > cg.time - 400 ) { + float alpha; + + alpha = ( 400.0 - (float)( cg.time - cg_entities[es->number].pe.teslaDamagedTime ) ) / 400.0; + + ent->shaderRGBA[0] = ( unsigned char )( 50.0 * alpha ); + ent->shaderRGBA[1] = ( unsigned char )( 130.0 * alpha ); + ent->shaderRGBA[2] = ( unsigned char )( 255.0 * alpha ); + + if ( ( cg.time / 50 ) % ( 2 + ( cg.time % 2 ) ) == 0 ) { + ent->customShader = cgs.media.teslaAltDamageEffectShader; + } else { + ent->customShader = cgs.media.teslaDamageEffectShader; + } + trap_R_AddRefEntityToScene( ent ); + } + + *ent = backupRefEnt; +} + +char *vtosf( const vec3_t v ) { + static int index; + static char str[8][64]; + char *s; + + // use an array so that multiple vtos won't collide + s = str[index]; + index = ( index + 1 ) & 7; + + Com_sprintf( s, 64, "(%f %f %f)", v[0], v[1], v[2] ); + + return s; +} + + +#define SPINNER_SPEED 0.3f +/* +============== +CG_SpinnerSpinAngle +============== +*/ +static float CG_SpinnerSpinAngle( centity_t *cent ) { + int delta; + + if ( cent->currentState.eFlags & EF_DEAD ) { // don't spin for dead loper (TODO: spindown, or blow off parts rather than just stopping) + return cent->pe.spinnerAngle; + } + + delta = cg.time - cent->pe.spinnerTime; + + return -( cent->pe.spinnerAngle + delta * SPINNER_SPEED ); +} + +/* +============== +CG_AddFireLight +============== +*/ +static void CG_AddFireLight( centity_t *cent ) { + + return; + +/* OPTIMIZATION, TOO MANY DLIGHTS WHEN FIRE IS AROUND + + entityState_t *es; + float alpha; + + if (CG_EntOnFire(&cg_entities[cent->currentState.number])) { + + es = ¢->currentState; + + // set the alpha + alpha = (cg.time - es->onFireStart) / 1500.0; + if (alpha > 1.0) { + alpha = (es->onFireEnd - cg.time) / 1500.0; + if (alpha > 1.0) { + alpha = 1.0; + } + } + if (alpha <= 0.0) return; + + trap_R_AddLightToScene( cent->lerpOrigin, 128 + 128*alpha, 1.000000*alpha, 0.603922*alpha, 0.207843*alpha, 0 ); + } +*/ +} + +/* +=============== +CG_AnimPlayerConditions + + predict, or calculate condition for this entity, if it is not the local client +=============== +*/ +void CG_AnimPlayerConditions( centity_t *cent ) { + entityState_t *es; + clientInfo_t *ci; +// int legsAnim; + + if ( cg.snap && cg.snap->ps.clientNum == cent->currentState.number && !cg.renderingThirdPerson ) { + return; + } + + es = ¢->currentState; + // DHM-Nerve + //ci = &cgs.clientinfo[es->number]; // es->number is not always a valid client num + ci = &cgs.clientinfo[es->clientNum]; + // dhm-Nerve + + // WEAPON + BG_UpdateConditionValue( es->clientNum, ANIM_COND_WEAPON, es->weapon, qtrue ); + + // MOUNTED + if ( es->eFlags & EF_MG42_ACTIVE ) { + BG_UpdateConditionValue( es->clientNum, ANIM_COND_MOUNTED, MOUNTED_MG42, qtrue ); + } else { + BG_UpdateConditionValue( es->clientNum, ANIM_COND_MOUNTED, MOUNTED_UNUSED, qtrue ); + } + + // UNDERHAND + BG_UpdateConditionValue( es->clientNum, ANIM_COND_UNDERHAND, cent->lerpAngles[0] > 0, qtrue ); + + // LEANING + /* TODO??? + if (es->lean > 0) { + BG_UpdateConditionValue( es->clientNum, ANIM_COND_LEANING, LEANING_RIGHT, qtrue ); + } else if (es->lean < 0) { + BG_UpdateConditionValue( es->clientNum, ANIM_COND_LEANING, LEANING_LEFT, qtrue ); + } else { + BG_UpdateConditionValue( es->clientNum, ANIM_COND_LEANING, LEANING_UNUSED, qtrue ); + } + */ + + if ( es->eFlags & EF_CROUCHING ) { + BG_UpdateConditionValue( es->clientNum, ANIM_COND_CROUCHING, qtrue, qtrue ); + } else { + BG_UpdateConditionValue( es->clientNum, ANIM_COND_CROUCHING, qfalse, qtrue ); + } + + if ( es->eFlags & EF_FIRING ) { + BG_UpdateConditionValue( es->clientNum, ANIM_COND_FIRING, qtrue, qtrue ); + } else { + BG_UpdateConditionValue( es->clientNum, ANIM_COND_FIRING, qfalse, qtrue ); + } + + // reverse engineer the legs anim -> movetype (if possible) + //legsAnim = es->legsAnim & ~ANIM_TOGGLEBIT; + //if (ci->modelInfo->animations[legsAnim].movetype) { + // BG_UpdateConditionValue( es->clientNum, ANIM_COND_MOVETYPE, ci->modelInfo->animations[legsAnim].movetype, qfalse ); + //} + // RF, changed this since we dont need to be careful about bandwidth anymore, and this method + // is much more accurate + if ( cent->currentState.animMovetype ) { + BG_UpdateConditionValue( es->clientNum, ANIM_COND_MOVETYPE, cent->currentState.animMovetype, qtrue ); + } +} + +void CG_DeadSink( centity_t *cent ) { + if ( cent->currentState.aiChar != AICHAR_WARZOMBIE ) { + return; + } + if ( !( cent->currentState.eFlags & EF_DEAD ) ) { + return; + } + if ( !cent->currentState.effect3Time ) { + return; + } + if ( cent->currentState.effect3Time >= cg.time ) { + return; + } + // sink + cent->lerpOrigin[2] -= DEAD_SINK_DEPTH * ( (float)( cg.time - cent->currentState.effect3Time ) / DEAD_SINK_DURATION ); +} + +/* +=============== +CG_Player +=============== +*/ +void CG_Player( centity_t *cent ) { + int i; + clientInfo_t *ci; + refEntity_t legs; + refEntity_t torso; + refEntity_t head; + refEntity_t acc; + + vec3_t lightorigin; + + int clientNum; + int renderfx; + qboolean shadow; //, drawweap = qtrue; // TTimo: unused + float shadowPlane; + + float gumsflappin = 0; // talking amplitude + + centity_t *cgsnap; + + cgsnap = &cg_entities[cg.snap->ps.clientNum]; + + shadow = qfalse; // gjd added to make sure it was initialized + shadowPlane = 0.0; // ditto + + // if set to invisible, skip + if ( cent->currentState.eFlags & EF_NODRAW ) { + return; + } + + // the client number is stored in clientNum. It can't be derived + // from the entity number, because a single client may have + // multiple corpses on the level using the same clientinfo + clientNum = cent->currentState.clientNum; + if ( clientNum < 0 || clientNum >= MAX_CLIENTS ) { + CG_Error( "Bad clientNum on player entity" ); + } + ci = &cgs.clientinfo[ clientNum ]; + +//----(SA) we need to not see the player in the camera +// if (cg.cameraMode && clientNum == cg.snap->ps.clientNum) { +// return; +// } +//----(SA) end + + // it is possible to see corpses from disconnected players that may + // not have valid clientinfo + if ( !ci->infoValid ) { + return; + } + + // check time + if ( cent->pe.lastTime > cg.time ) { + CG_ResetPlayerEntity( cent ); + } + cent->pe.lastTime = cg.time; + + memset( &legs, 0, sizeof( legs ) ); + memset( &torso, 0, sizeof( torso ) ); + memset( &head, 0, sizeof( head ) ); + memset( &acc, 0, sizeof( acc ) ); + + // get the rotation information + CG_PlayerAngles( cent, legs.axis, torso.axis, head.axis ); + +//----(SA) added + // setting the legs axis should pass the scale down through the other parts/tags/etc. + // and will need to be 'undone' for the weapon + if ( ci->playermodelScale[0] ) { + VectorScale( legs.axis[0], ci->playermodelScale[0], legs.axis[0] ); + VectorScale( legs.axis[1], ci->playermodelScale[1], legs.axis[1] ); + VectorScale( legs.axis[2], ci->playermodelScale[2], legs.axis[2] ); + legs.nonNormalizedAxes = qtrue; + torso.nonNormalizedAxes = qtrue; + head.nonNormalizedAxes = qtrue; + } +//----(SA) end + + // copy the torso rotation to the accessories + AxisCopy( torso.axis, acc.axis ); + + // calculate client-side conditions + CG_AnimPlayerConditions( cent ); + + // get the animation state (after rotation, to allow feet shuffle) + CG_PlayerAnimation( cent, &legs.oldframe, &legs.frame, &legs.backlerp, + &torso.oldframe, &torso.frame, &torso.backlerp ); + + // add powerups floating behind the player + CG_PlayerPowerups( cent ); + + // add the talk baloon or disconnect icon + CG_PlayerSprites( cent ); + + // add a water splash if partially in and out of water + CG_PlayerSplash( cent ); + + // get the player model information + renderfx = 0; + if ( cent->currentState.number == cg.snap->ps.clientNum && !cg.renderingThirdPerson ) { + renderfx = RF_THIRD_PERSON; // only draw in mirrors + } + + // draw the player in cameras +// if(cg.cameraMode) +// renderfx &= ~RF_THIRD_PERSON; + + if ( cg_shadows.integer == 3 && shadow ) { + renderfx |= RF_SHADOW_PLANE; + } + renderfx |= RF_LIGHTING_ORIGIN; // use the same origin for all + + // set renderfx for accessories + acc.renderfx = renderfx; + +//CG_Printf("%i cl_org: %s\n", clientNum, vtosf(cent->lerpOrigin) ); + + VectorCopy( cent->lerpOrigin, lightorigin ); + lightorigin[2] += 31 + (float)cg_drawFPGun.integer; + + // dead sink? + CG_DeadSink( cent ); + + // + // add special monster effects here + // + CG_AddZombieSpiritEffect( cent ); + CG_AddZombieFlameEffect( cent ); + CG_AddZombieFlameShort( cent ); + CG_AddLoperLightningEffect( cent ); + CG_AddLoperGroundEffect( cent ); + CG_AddHelgaSpiritEffect( cent ); + + // + // add dynamic lights, and other misc effects + // + CG_AddFireLight( cent ); + + // + // add the legs + // + legs.hModel = ci->legsModel; + legs.customSkin = ci->legsSkin; + + VectorCopy( cent->lerpOrigin, legs.origin ); + + if ( ci->playermodelScale[0] != 0 ) { // player scaled, adjust for the (-24) offset of player legs origin to ground + legs.origin[2] -= 24.0f * ( 1.0f - ci->playermodelScale[2] ); + } + + VectorCopy( lightorigin, legs.lightingOrigin ); + legs.shadowPlane = shadowPlane; + legs.renderfx = renderfx; + VectorCopy( legs.origin, legs.oldorigin ); // don't positionally lerp at all + + if ( !ci->isSkeletal ) { + CG_AddRefEntityWithPowerups( &legs, cent->currentState.powerups, ci->team, ¢->currentState, cent->fireRiseDir ); + } + + cent->pe.legsRefEnt = legs; + + // if the model failed, allow the default nullmodel to be displayed + if ( !legs.hModel ) { + return; + } + + // (SA) only need to set this once... + VectorCopy( lightorigin, acc.lightingOrigin ); + + + // + // add the torso + // + torso.hModel = ci->torsoModel; + + if ( !torso.hModel ) { + return; + } + + torso.customSkin = ci->torsoSkin; + + VectorCopy( lightorigin, torso.lightingOrigin ); + + //----(SA) check for ladder and if you're on it, don't allow torso model rotation (so the body climbs aligned with the ladder) + //----(SA) also taking care of the Loper's interesting heirarchy (his upper body is effectively the same as a weapon_hand.md3. it keeps things connected, but has no geometry) + + if ( !ci->isSkeletal ) { + + if ( ( cgsnap == cent && ( cg.snap->ps.pm_flags & PMF_LADDER ) ) + || ( cent->currentState.aiChar == AICHAR_LOPER ) ) { + CG_PositionEntityOnTag( &torso, &legs, "tag_torso", 0, NULL ); + } else { + CG_PositionRotatedEntityOnTag( &torso, &legs, "tag_torso" ); + } + + } else { // just clear out the angles + + if ( ( cgsnap == cent && ( cg.snap->ps.pm_flags & PMF_LADDER ) ) + || ( cent->currentState.aiChar == AICHAR_LOPER ) ) { + memcpy( torso.axis, legs.axis, sizeof( torso.axis ) ); + } + + } + + torso.shadowPlane = shadowPlane; + torso.renderfx = renderfx; + + if ( !ci->isSkeletal ) { + + CG_AddRefEntityWithPowerups( &torso, cent->currentState.powerups, ci->team, ¢->currentState, cent->fireRiseDir ); + + } else { // SKELETAL ANIMATION + + // skeletal models combine the legs and torso, so we must build a compiled refEntity_t + + legs.torsoFrame = torso.frame; + legs.oldTorsoFrame = torso.oldframe; + + memcpy( legs.torsoAxis, torso.axis, sizeof( torso.axis ) ); + legs.torsoBacklerp = torso.backlerp; + + CG_AddRefEntityWithPowerups( &legs, cent->currentState.powerups, ci->team, ¢->currentState, cent->fireRiseDir ); + + cent->pe.legsRefEnt = legs; + torso = legs; // so tag calls use the correct values + } + + cent->pe.torsoRefEnt = torso; + + +// if ( cent->currentState.eFlags & EF_DEAD) { +// if(cent->currentState.eFlags & EF_HEADSHOT) +// // dead guy with no head +// return; +// } + + // + // add the head + // + head.hModel = ci->headModel; + if ( !head.hModel ) { + return; + } + head.customSkin = ci->headSkin; + + VectorCopy( lightorigin, head.lightingOrigin ); + + CG_PositionRotatedEntityOnTag( &head, &torso, "tag_head" ); + + head.shadowPlane = shadowPlane; + head.renderfx = renderfx; + + + // Ridah, talking animations + if ( !( cent->currentState.eFlags & EF_DEAD ) ) { + #define HEAD_EMOTION_SUBTYPES 8 // closed, A, O, I, E + int talk_frame; //, subtype; + qboolean closed; + + #define NUM_EMOTIONS 2 // 0 neutral, 1 happy, 2 angry + int emotion = 0; // this should default to the entity's current emotion + + gumsflappin = (float)trap_S_GetVoiceAmplitude( clientNum ); + talk_frame = (int)floor( ( HEAD_EMOTION_SUBTYPES - 1 ) * ( gumsflappin / 256.0 ) ); + + // add the current frame to the total, so when it comes to pick a new frame, we choose the average + // of those we missed over the last frame + cent->pe.head.animationTime += talk_frame; + cent->pe.head.animationNumber++; + + // if we are starting a talk after idling, hurry up the animation + if ( ( cent->pe.head.frameTime > cg.time + 30 ) && cent->pe.head.animationTime && !( ( cent->pe.head.frame - ci->modelInfo->headAnims[0].firstFrame ) % HEAD_EMOTION_SUBTYPES ) && !( ( cent->pe.head.oldFrame - ci->modelInfo->headAnims[0].firstFrame ) % HEAD_EMOTION_SUBTYPES ) ) { + cent->pe.head.frameTime = cg.time + 30; + } + + if ( cent->pe.head.frameTime < cg.time ) { // set the new frame + cent->pe.head.oldFrame = cent->pe.head.frame; + cent->pe.head.oldFrameTime = cent->pe.head.frameTime; + + if ( cent->pe.head.animationTime ) { + + talk_frame = (int)( (float)cent->pe.head.animationTime / (float)cent->pe.head.animationNumber ); + //subtype = rand()%HEAD_EMOTION_SUBTYPES; + emotion = rand() % NUM_EMOTIONS; // this helps animate the mouth more realistically while talking + + switch ( cent->currentState.aiChar ) { + case AICHAR_ZOMBIE: + case AICHAR_LOPER: + talk_frame = (int)( (float)talk_frame * 1.2 ); + closed = qfalse; + break; + default: + // randomly set it back to 0 amplitude to simulate certain synonyms pronounced with a closed mouth + closed = ( ( rand() % 5 ) == 0 ) && ( talk_frame < ( HEAD_EMOTION_SUBTYPES - 1 ) ); + } + + if ( closed ) { + talk_frame -= rand() % ( HEAD_EMOTION_SUBTYPES / 2 ); + if ( talk_frame < 0 ) { + talk_frame = 0; + } + } + + if ( talk_frame >= HEAD_EMOTION_SUBTYPES ) { + talk_frame = HEAD_EMOTION_SUBTYPES - 1; + } + + cent->pe.head.frame = emotion * HEAD_EMOTION_SUBTYPES + talk_frame; //ci->modelInfo->headAnims[emotion*HEAD_EMOTION_SUBTYPES].firstFrame + talk_frame; + cent->pe.head.frameTime = cg.time + 80 + rand() % 40; // interpolate for smoother animation vs latency + + //CG_Printf("%i head: frame %i, oldframe %i, nextframetime %i\n", cg.time, cent->pe.head.frame, cent->pe.head.oldFrame, cent->pe.head.frameTime ); + + //if (closed) + // cent->pe.head.frameTime += 30; // slow it down a bit + } else { +#if 0 + // debugging, play all the frames and display the frame numbers + if ( ++cent->pe.head.frame > ( ci->headAnims[( NUM_EMOTIONS - 1 ) * HEAD_EMOTION_SUBTYPES + HEAD_EMOTION_SUBTYPES - 1].firstFrame ) ) { + cent->pe.head.frame = ci->headAnims[0].firstFrame; + } + cent->pe.head.frameTime = cg.time + 2000; + CG_Printf( "%d - %d\n", cent->currentState.number, cent->pe.head.oldFrame ); +#else + while ( ( emotion = rand() % NUM_EMOTIONS ) == 1 ) ; // don't use happy emotion + if ( ( cent->pe.head.frame - ci->modelInfo->headAnims[0].firstFrame ) % HEAD_EMOTION_SUBTYPES ) { + cent->pe.head.frame = ci->modelInfo->headAnims[emotion * HEAD_EMOTION_SUBTYPES].firstFrame; + cent->pe.head.frameTime = cg.time + 150; + } else { // mouth is currently closed + cent->pe.head.frame = ci->modelInfo->headAnims[emotion * HEAD_EMOTION_SUBTYPES].firstFrame; + cent->pe.head.frameTime = cent->pe.head.frameTime + 1000 + rand() % 2000; + if ( cent->pe.head.frameTime < cg.time ) { + cent->pe.head.frameTime = cg.time + 1000; + } + } +#endif + } + + cent->pe.head.animationTime = 0; + cent->pe.head.animationNumber = 0; + } + + head.frame = cent->pe.head.frame; + head.oldframe = cent->pe.head.oldFrame; + head.backlerp = 1.0 - (float)( cg.time - cent->pe.head.oldFrameTime ) / ( cent->pe.head.frameTime - cent->pe.head.oldFrameTime ); + + } else { // dead + head.frame = 0; + head.oldframe = 0; + head.backlerp = 0.0; + } + // done. + + + + // set blinking flag + if ( cent->currentState.eFlags & EF_DEAD ) { + // dead guy, eyes closed. + head.renderfx |= RF_BLINK; + + } else if ( ci->blinkTime <= cg.time ) { + + head.renderfx |= RF_BLINK; + + if ( ci->blinkTime <= ( cg.time - cg_blinktime.integer ) ) { + ci->blinkTime = cg.time + 500 + random() * 4000; + + // blink more often when talking + if ( gumsflappin >= 0 ) { + ci->blinkTime = max( cg.time, ci->blinkTime - 1000 ); + } + } + } + + + CG_AddRefEntityWithPowerups( &head, cent->currentState.powerups, ci->team, ¢->currentState, cent->fireRiseDir ); + + cent->pe.headRefEnt = head; + + // add the shadow + shadow = CG_PlayerShadow( cent, &shadowPlane ); + + // set the shadowplane for accessories + acc.shadowPlane = shadowPlane; + + CG_BreathPuffs( cent, &head ); + + // + // add the gun / barrel / flash + // + CG_AddPlayerWeapon( &torso, NULL, cent ); + + cent->lastWeaponClientFrame = cg.clientFrame; + + // + // add binoculars (if it's not the player) + // + if ( ( cent->currentState.clientNum != cg.snap->ps.clientNum ) && + cent->currentState.eFlags & EF_ZOOMING ) { + + acc.hModel = cgs.media.thirdPersonBinocModel; + CG_PositionEntityOnTag( &acc, &torso, "tag_weapon", 0, NULL ); + CG_AddRefEntityWithPowerups( &acc, cent->currentState.powerups, ci->team, ¢->currentState, cent->fireRiseDir ); + } + + if ( ( cent->currentState.clientNum != cg.snap->ps.clientNum ) && + cent->currentState.eFlags & EF_CIG ) { + + acc.hModel = cgs.media.cigModel; + CG_PositionEntityOnTag( &acc, &torso, "tag_weapon2", 0, NULL ); + CG_AddRefEntityWithPowerups( &acc, cent->currentState.powerups, ci->team, ¢->currentState, cent->fireRiseDir ); + + // smoke + if ( !cg_paused.integer ) { // don't add while paused + if ( !( rand() % 3 ) ) { + CG_ParticleImpactSmokePuffExtended( cgs.media.smokeParticleShader, acc.origin, tv( 0,0,1 ), 1, 1000, 6, 4, 10, 0.15f ); + } + } + } + + + + // + // add player specific models + // + + if ( cent->currentState.aiChar == AICHAR_LOPER ) { + if ( ci->partModels[8] ) { + vec3_t angles; + + acc.hModel = ci->partModels[8]; + VectorClear( angles ); + angles[YAW] = CG_SpinnerSpinAngle( cent ); + AnglesToAxis( angles, acc.axis ); + CG_PositionRotatedEntityOnTag( &acc, &legs, "tag_spinner" ); + CG_AddRefEntityWithPowerups( &acc, cent->currentState.powerups, ci->team, ¢->currentState, cent->fireRiseDir ); + } + } +//----(SA) modified + else if ( cent->currentState.aiChar == AICHAR_PROTOSOLDIER || + cent->currentState.aiChar == AICHAR_SUPERSOLDIER || + cent->currentState.aiChar == AICHAR_HEINRICH ) { + + char *protoTags[] = { "tag_chest", + "tag_calfleft", + "tag_armleft", + "tag_back", + "tag_legleft", + "tag_calfright", + "tag_armright", + "tag_back", + "tag_legright"}; + + char *ssTags[] = { "tag_chest", + "tag_calfleft", + "tag_armleft", + "tag_back", + "tag_legleft", + "tag_calfright", + "tag_armright", + "tag_back", + "tag_legright", + + "tag_footleft", + "tag_footright", + "tag_sholeft", + "tag_shoright", + "tag_torso", + "tag_calfleft", + "tag_calfright"}; + + char *heinrichTags[] = {"tag_chest", + "tag_calfleft", + "tag_armleft", + "tag_back", + "tag_legleft", + "tag_calfright", + "tag_armright", + "tag_back", + "tag_legright", + + "tag_footleft", + "tag_footright", + "tag_sholeft", + "tag_shoright", + "tag_torso", + "tag_legleft", + "tag_legright", + + "tag_sholeft", + "tag_shoright", + "tag_legleft", + "tag_legright", + "tag_legleft", + "tag_legright"}; + + // TTimo: init + int totalparts = 0, dynamicparts = 0, protoParts = 9, superParts = 16, heinrichParts = 22; + char **tags = NULL; + qhandle_t *models = NULL; + int dmgbits = 16; // 32/2; + + if ( cent->currentState.aiChar == AICHAR_PROTOSOLDIER ) { + tags = &protoTags[0]; + models = &cgs.media.protoArmor[0]; + dynamicparts = totalparts = protoParts; + } else if ( cent->currentState.aiChar == AICHAR_SUPERSOLDIER ) { + tags = &ssTags[0]; + models = &cgs.media.superArmor[0]; + dynamicparts = 14; // the other two stay permanent + totalparts = superParts; + } else if ( cent->currentState.aiChar == AICHAR_HEINRICH ) { + tags = &heinrichTags[0]; + models = &cgs.media.heinrichArmor[0]; + dynamicparts = 20; // will get kicked down to 16 + totalparts = heinrichParts; + } + + if ( dynamicparts > dmgbits ) { + dynamicparts = dmgbits; + } + + for ( i = 0; i < totalparts; i++ ) { + if ( ( i >= dynamicparts ) || ( !( cent->currentState.dmgFlags & ( 1 << i ) ) ) ) { // ones beyond 16 just draw the good part + acc.hModel = models[i]; + } else { + if ( cent->currentState.dmgFlags & ( 1 << ( i + totalparts ) ) ) { + acc.hModel = models[i + totalparts]; + } else { + acc.hModel = models[i + ( 2 * totalparts )]; + } + } + + if ( !acc.hModel ) { + continue; + } + + CG_PositionEntityOnTag( &acc, &torso, tags[i], 0, NULL ); + + if ( cent->currentState.aiChar == AICHAR_PROTOSOLDIER && !( cent->currentState.eFlags & EF_DEAD ) ) { + if ( acc.hModel != models[i] ) { + vec3_t dir; + int mynum; + + VectorSubtract( acc.origin, cent->currentState.pos.trBase, dir ); + dir[2] += 20; + VectorNormalize( dir ); + + mynum = ( rand() % 100 ); + if ( mynum < 2 ) { + CG_AddBulletParticles( acc.origin, dir, 30, 10 * mynum, 3, 300.0f ); + } + } + } + + CG_AddRefEntityWithPowerups( &acc, cent->currentState.powerups, ci->team, ¢->currentState, cent->fireRiseDir ); + } + } else if ( cent->currentState.aiChar == AICHAR_WARZOMBIE && + ( !Q_strcasecmp( (char *)ci->modelInfo->modelname, "dark" ) ) ) { + // TTimo: unused + /* + char *tags[] = { "tag_armleft", + "tag_armright", + "tag_back", + "tag_back", + "tag_calfleft", + "tag_calfleft", + "tag_calfright", + "tag_calfright", + "tag_chest", + "tag_chest", + "tag_footleft", + "tag_footright", + "tag_legleft", + "tag_sholeft", + "tag_shoright", + "tag_torso" + }; + */ + +// TTimo: unused + /* +int parts[] = { 34, + 38, + 0, + 19, + 0, + 14, + 21, + 15, + 16, + 0, + 0, + 32, + 0, + 33, + 0, + 45 + }; + */ + +// char *parts[] = { "dam_lftforarm2",// 34 +// "dam_rtforarm2",//38 +// "dam_rtshoulder", +// "dam_lftshoulder1",//19 +// "dam_lftcalf", +// "nodam_lftknee",//14 +// "dam_rtcalf1",//21 +// "nodam_rtknee",//15 +// "dam_chest1",//16 +// "dam_chest3", +// "dam_lftfoot", +// "dam_rtfoot2",//32 +// "dam_lftthigh", +// "dam_lftuparm2",//33 +// "dam_rtuparm", +// "dam_waist2"//45 +// }; + + +// do not turn on unless asked for +/* + for(i=0;i<16;i++) { + acc.hModel = cgs.media.superArmor[parts[i]]; + CG_PositionEntityOnTag( &acc, &torso, tags[i], 0, NULL); + CG_AddRefEntityWithPowerups( &acc, cent->currentState.powerups, ci->team, ¢->currentState, cent->fireRiseDir ); + } +*/ +// + } + + + +//#if 1 +#ifdef TEST_HEADLIGHT + // used for testing spotlights. + // this just puts one in the mouth of every other player so you can + // get a good read of how well the various elements of spots are working +// if(cent->currentState.number != cg.predictedPlayerState.clientNum) + { + vec3_t morg, viewDir; +// vec4_t color = {1,1,1,0.1f}; + vec4_t color = {0.7,0.7,0.7,0.1f}; + + CG_GetOriginForTag( cent, &head, "tag_mouth", 0, morg, NULL ); + AngleVectors( cent->lerpAngles, viewDir, NULL, NULL ); + CG_Spotlight( cent, color, morg, viewDir, 12, 512, 2, 5, SL_TRACEWORLDONLY | SL_NOCORE | SL_LOCKUV ); // SL_NOTRACE +// color[0] = 1; +// color[1] = 1; +// color[2] = 1; + color[3] = 0.1f; + CG_Spotlight( cent, color, morg, viewDir, 12, 512, 1.5, 2, SL_TRACEWORLDONLY | SL_NOCORE | SL_NODLIGHT | SL_LOCKUV ); // SL_NOTRACE + } +#endif + + + // + // add accessories + // + + for ( i = ACC_BELT_LEFT; i < ACC_MAX; i++ ) { + if ( !( ci->accModels[i] ) ) { + continue; + } + + // first 8 can be hidden by animation scripts + if ( i < 8 ) { + if ( cg.snap->ps.accHideBits & ( 1 << i ) ) { + continue; + } + } + + acc.hModel = ci->accModels[i]; // set the model + + if ( ci->accSkins[i] ) { + acc.customSkin = ci->accSkins[i]; // and the skin if there is one + + + } + switch ( i ) { + case ACC_BELT_LEFT: + CG_PositionEntityOnTag( &acc, &legs, "tag_bright", 0, NULL ); + break; + case ACC_BELT_RIGHT: + CG_PositionEntityOnTag( &acc, &legs, "tag_bleft", 0, NULL ); + break; + + case ACC_BELT: + CG_PositionEntityOnTag( &acc, &torso, "tag_ubelt", 0, NULL ); + break; + case ACC_BACK: + CG_PositionEntityOnTag( &acc, &torso, "tag_back", 0, NULL ); + break; + + case ACC_HAT: //hat + if ( cent->currentState.eFlags & EF_HEADSHOT ) { + continue; + } + case ACC_MOUTH2: // hat2 + case ACC_MOUTH3: // hat3 + CG_PositionEntityOnTag( &acc, &head, "tag_mouth", 0, NULL ); + break; + + // weapon and weapon2 + // these are used by characters who have permanent weapons attached to their character in the skin + case ACC_WEAPON: // weap + CG_PositionEntityOnTag( &acc, &torso, "tag_weapon", 0, NULL ); + break; + case ACC_WEAPON2: // weap2 + CG_PositionEntityOnTag( &acc, &torso, "tag_weapon2", 0, NULL ); + break; + + default: + continue; + } + + CG_AddRefEntityWithPowerups( &acc, cent->currentState.powerups, ci->team, ¢->currentState, cent->fireRiseDir ); + } + + for ( i = 0; i < 8; i++ ) { + if ( !( ci->partModels[i] ) ) { + continue; + } + + // first 8 can be hidden by animation scripts + if ( !( cg.snap->ps.accShowBits & ( 1 << i ) ) ) { + continue; + } + + acc.hModel = ci->partModels[i]; // set the model + if ( ci->partSkins[i] ) { + acc.customSkin = ci->partSkins[i]; // and the skin if there is one + + } + CG_PositionEntityOnTag( &acc, &legs, va( "tag_animscript%s", i ), 0, NULL ); + CG_AddRefEntityWithPowerups( &acc, cent->currentState.powerups, ci->team, ¢->currentState, cent->fireRiseDir ); + } + + +} + + +//===================================================================== + +extern void CG_ClearWeapLerpFrame( clientInfo_t *ci, lerpFrame_t *lf, int animationNumber ); + +/* +=============== +CG_ResetPlayerEntity + +A player just came into view or teleported, so reset all animation info +=============== +*/ +void CG_ResetPlayerEntity( centity_t *cent ) { + cent->errorTime = -99999; // guarantee no error decay added + cent->extrapolated = qfalse; + + if ( !( cent->currentState.eFlags & EF_DEAD ) ) { + CG_ClearLerpFrameRate( &cgs.clientinfo[ cent->currentState.clientNum ], ¢->pe.legs, cent->currentState.legsAnim, cent ); + CG_ClearLerpFrame( &cgs.clientinfo[ cent->currentState.clientNum ], ¢->pe.torso, cent->currentState.torsoAnim ); + + memset( ¢->pe.legs, 0, sizeof( cent->pe.legs ) ); + cent->pe.legs.yawAngle = cent->nextState.apos.trBase[YAW]; //cent->rawAngles[YAW]; + cent->pe.legs.yawing = qfalse; + cent->pe.legs.pitchAngle = cent->nextState.apos.trBase[PITCH]; + cent->pe.legs.pitching = qfalse; + + memset( ¢->pe.torso, 0, sizeof( cent->pe.legs ) ); + cent->pe.torso.yawAngle = cent->nextState.apos.trBase[YAW]; //cent->rawAngles[YAW]; + cent->pe.torso.yawing = qfalse; + cent->pe.torso.pitchAngle = cent->nextState.apos.trBase[PITCH]; //cent->rawAngles[PITCH]; + cent->pe.torso.pitching = qfalse; + } + + BG_EvaluateTrajectory( ¢->currentState.pos, cg.time, cent->lerpOrigin ); + BG_EvaluateTrajectory( ¢->currentState.apos, cg.time, cent->lerpAngles ); + + VectorCopy( cent->lerpOrigin, cent->rawOrigin ); + VectorCopy( cent->lerpAngles, cent->rawAngles ); + + if ( cg_debugPosition.integer ) { + CG_Printf( "%i ResetPlayerEntity yaw=%i\n", cent->currentState.number, cent->pe.torso.yawAngle ); + } + + cent->pe.painAnimLegs = -1; + cent->pe.painAnimTorso = -1; + cent->pe.animSpeed = 1.0; + +} + +void CG_GetBleedOrigin( vec3_t head_origin, vec3_t torso_origin, vec3_t legs_origin, int fleshEntityNum ) { + clientInfo_t *ci; + refEntity_t legs; + refEntity_t torso; + refEntity_t head; + //int clientNum; + centity_t *cent, backupCent; + + // clientNum = cg.snap->entities[fleshEntityNum].clientNum; + ci = &cgs.clientinfo[ fleshEntityNum ]; + + // cent = &cg_entities[ cg.snap->entities[fleshEntityNum].number ]; + cent = &cg_entities [ fleshEntityNum ]; + backupCent = *cent; + + // cent = &cg_entities [ cg.snap->entities [ fleshEntityNum - 1].clientNum ]; + + if ( !ci->infoValid ) { + return; + } + + memset( &legs, 0, sizeof( legs ) ); + memset( &torso, 0, sizeof( torso ) ); + memset( &head, 0, sizeof( head ) ); + + CG_PlayerAngles( cent, legs.axis, torso.axis, head.axis ); + CG_PlayerAnimation( cent, &legs.oldframe, &legs.frame, &legs.backlerp, + &torso.oldframe, &torso.frame, &torso.backlerp ); + + legs.hModel = ci->legsModel; +// VectorCopy( cg.snap->entities[fleshEntityNum - 1].pos.trBase, legs.origin ); + VectorCopy( cent->lerpOrigin, legs.origin ); + VectorCopy( legs.origin, legs.oldorigin ); + + // Ridah, restore the cent so we don't interfere with animation timings + *cent = backupCent; + + if ( !legs.hModel ) { + return; + } + + torso.hModel = ci->torsoModel; + if ( !torso.hModel ) { + return; + } + + head.hModel = ci->headModel; + if ( !head.hModel ) { + return; + } + + CG_PositionRotatedEntityOnTag( &torso, &legs, "tag_torso" ); + CG_PositionRotatedEntityOnTag( &head, &torso, "tag_head" ); + + VectorCopy( head.origin, head_origin ); + VectorCopy( torso.origin, torso_origin ); + VectorCopy( legs.origin, legs_origin ); +} + +/* +=============== +CG_GetTag +=============== +*/ +qboolean CG_GetTag( int clientNum, char *tagname, orientation_t *or ) { + clientInfo_t *ci; + centity_t *cent; + refEntity_t *refent; + vec3_t tempAxis[3]; + vec3_t org; + int i; + + ci = &cgs.clientinfo[ clientNum ]; + + if ( !ci->isSkeletal ) { + return qfalse; // only skeletal models supported + + } + if ( cg.snap && clientNum == cg.snap->ps.clientNum && cg.renderingThirdPerson ) { + cent = &cg.predictedPlayerEntity; + } else { + cent = &cg_entities[ci->clientNum]; + if ( !cent->currentValid ) { + return qfalse; // not currently in PVS + } + } + + refent = ¢->pe.legsRefEnt; + + if ( trap_R_LerpTag( or, refent, tagname, 0 ) < 0 ) { + return qfalse; + } + + VectorCopy( refent->origin, org ); + + for ( i = 0 ; i < 3 ; i++ ) { + VectorMA( org, or->origin[i], refent->axis[i], org ); + } + + VectorCopy( org, or->origin ); + + // add the origin of the entity + //VectorAdd( refent->origin, or->origin, or->origin ); + + // rotate with entity + MatrixMultiply( refent->axis, or->axis, tempAxis ); + memcpy( or->axis, tempAxis, sizeof( vec3_t ) * 3 ); + + return qtrue; +} + +/* +=============== +CG_GetWeaponTag +=============== +*/ +qboolean CG_GetWeaponTag( int clientNum, char *tagname, orientation_t *or ) { + clientInfo_t *ci; + centity_t *cent; + refEntity_t *refent; + vec3_t tempAxis[3]; + vec3_t org; + int i; + + ci = &cgs.clientinfo[ clientNum ]; + + if ( !ci->isSkeletal ) { + return qfalse; // only skeletal models supported + + } + if ( cg.snap && clientNum == cg.snap->ps.clientNum && cg.renderingThirdPerson ) { + cent = &cg.predictedPlayerEntity; + } else { + cent = &cg_entities[ci->clientNum]; + if ( !cent->currentValid ) { + return qfalse; // not currently in PVS + } + } + + if ( cent->pe.gunRefEntFrame < cg.clientFrame - 1 ) { + return qfalse; + } + + refent = ¢->pe.gunRefEnt; + + if ( trap_R_LerpTag( or, refent, tagname, 0 ) < 0 ) { + return qfalse; + } + + VectorCopy( refent->origin, org ); + + for ( i = 0 ; i < 3 ; i++ ) { + VectorMA( org, or->origin[i], refent->axis[i], org ); + } + + VectorCopy( org, or->origin ); + + // add the origin of the entity + //VectorAdd( refent->origin, or->origin, or->origin ); + + // rotate with entity + MatrixMultiply( refent->axis, or->axis, tempAxis ); + memcpy( or->axis, tempAxis, sizeof( vec3_t ) * 3 ); + + return qtrue; +} diff --git a/Projects/Android/jni/rtcw/src/cgame/cg_playerstate.c b/Projects/Android/jni/rtcw/src/cgame/cg_playerstate.c new file mode 100644 index 0000000..e19b5a4 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/cgame/cg_playerstate.c @@ -0,0 +1,555 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + + +// cg_playerstate.c -- this file acts on changes in a new playerState_t +// With normal play, this will be done after local prediction, but when +// following another player or playing back a demo, it will be checked +// when the snapshot transitions like all the other entities + +#include "cg_local.h" + +/* +============== +CG_CheckAmmo + +If the ammo has gone low enough to generate the warning, play a sound +============== +*/ +void CG_CheckAmmo( void ) { + int i; + int total; + int weapons[MAX_WEAPONS / ( sizeof( int ) * 8 )]; + + // see about how many seconds of ammo we have remaining + memcpy( weapons, cg.snap->ps.weapons, sizeof( weapons ) ); + + if ( !weapons[0] && !weapons[1] ) { // (SA) we start out with no weapons, so don't make a click on startup + return; + } + + total = 0; + + // first weap now WP_LUGER + for ( i = WP_FIRST ; i < WP_NUM_WEAPONS ; i++ ) + { + if ( !( weapons[0] & ( 1 << i ) ) ) { + continue; + } + switch ( i ) + { + case WP_PANZERFAUST: + case WP_GRENADE_LAUNCHER: + case WP_GRENADE_PINEAPPLE: + case WP_LUGER: + case WP_COLT: + case WP_AKIMBO: + case WP_SILENCER: + case WP_FG42: + case WP_FG42SCOPE: + case WP_MP40: + case WP_THOMPSON: + case WP_STEN: + case WP_VENOM: + case WP_TESLA: + case WP_MAUSER: + case WP_GARAND: + default: + total += cg.snap->ps.ammo[BG_FindAmmoForWeapon( i )] * 1000; +// break; +// default: +// total += cg.snap->ps.ammo[BG_FindAmmoForWeapon(i)] * 200; +// break; + } + + if ( total >= 5000 ) { + cg.lowAmmoWarning = 0; + return; + } + } + + if ( !cg.lowAmmoWarning ) { + // play a sound on this transition + trap_S_StartLocalSound( cgs.media.noAmmoSound, CHAN_LOCAL_SOUND ); + } + + if ( total == 0 ) { + cg.lowAmmoWarning = 2; + } else { + cg.lowAmmoWarning = 1; + } +} + +/* +============== +CG_DamageFeedback +============== +*/ +void CG_DamageFeedback( int yawByte, int pitchByte, int damage ) { + float left, front, up; + float kick; + int health; + float scale; + vec3_t dir; + vec3_t angles; + float dist; + float yaw, pitch; + int slot; + viewDamage_t *vd; + + // show the attacking player's head and name in corner + cg.attackerTime = cg.time; + + // the lower on health you are, the greater the view kick will be + health = cg.snap->ps.stats[STAT_HEALTH]; + if ( health < 40 ) { + scale = 1; + } else { + scale = 40.0 / health; + } + kick = damage * scale; + + if ( kick < 5 ) { + kick = 5; + } + if ( kick > 10 ) { + kick = 10; + } + + // find a free slot + for ( slot = 0; slot < MAX_VIEWDAMAGE; slot++ ) { + if ( cg.viewDamage[slot].damageTime + cg.viewDamage[slot].damageDuration < cg.time ) { + break; + } + } + + if ( slot == MAX_VIEWDAMAGE ) { + return; // no free slots, never override or splats will suddenly disappear + + } + vd = &cg.viewDamage[slot]; + + // if yaw and pitch are both 255, make the damage always centered (falling, etc) + if ( yawByte == 255 && pitchByte == 255 ) { + vd->damageX = 0; + vd->damageY = 0; + cg.v_dmg_roll = 0; + cg.v_dmg_pitch = -kick; + } else { + // positional + pitch = pitchByte / 255.0 * 360; + yaw = yawByte / 255.0 * 360; + + angles[PITCH] = pitch; + angles[YAW] = yaw; + angles[ROLL] = 0; + + AngleVectors( angles, dir, NULL, NULL ); + VectorSubtract( vec3_origin, dir, dir ); + + front = DotProduct( dir, cg.refdef.viewaxis[0] ); + left = DotProduct( dir, cg.refdef.viewaxis[1] ); + up = DotProduct( dir, cg.refdef.viewaxis[2] ); + + dir[0] = front; + dir[1] = left; + dir[2] = 0; + dist = VectorLength( dir ); + if ( dist < 0.1 ) { + dist = 0.1; + } + + cg.v_dmg_roll = kick * left; + + cg.v_dmg_pitch = -kick * front; + + if ( front <= 0.1 ) { + front = 0.1; + } + vd->damageX = crandom() * 0.3 + - left / front; + vd->damageY = crandom() * 0.3 + up / dist; + } + + // clamp the position + if ( vd->damageX > 1.0 ) { + vd->damageX = 1.0; + } + if ( vd->damageX < -1.0 ) { + vd->damageX = -1.0; + } + + if ( vd->damageY > 1.0 ) { + vd->damageY = 1.0; + } + if ( vd->damageY < -1.0 ) { + vd->damageY = -1.0; + } + + // don't let the screen flashes vary as much + if ( kick > 10 ) { + kick = 10; + } + vd->damageValue = kick; + cg.v_dmg_time = cg.time + DAMAGE_TIME; + vd->damageTime = cg.snap->serverTime; + vd->damageDuration = kick * 50 * ( 1 + 2 * ( !vd->damageX && !vd->damageY ) ); + cg.damageTime = cg.snap->serverTime; + cg.damageIndex = slot; +} + + + + +/* +================ +CG_Respawn + +A respawn happened this snapshot +================ +*/ +void CG_Respawn( void ) { + // no error decay on player movement + cg.thisFrameTeleport = qtrue; + + // need to reset client-side weapon animations + cg.predictedPlayerState.weapAnim = WEAP_IDLE1; // reset weapon animations + cg.predictedPlayerState.weapAnimTimer = 0; // allow other animations to happen right away + cg.predictedPlayerState.weaponstate = WEAPON_RAISING; // hmm, set this? what to? + + // display weapons available + cg.weaponSelectTime = cg.time; + + cg.holdableSelectTime = 0; //----(SA) reset holdable timer + cg.centerPrintTime = 0; //----(SA) reset centerprint counter so previous messages don't re-appear + cg.cursorHintIcon = 0; + cg.cursorHintTime = 0; + cg.yougotmailTime = 0; + +// cg.cameraMode = 0; //----(SA) get out of camera for sure + + // select the weapon the server says we are using + //cg.weaponSelect = cg.snap->ps.weapon; + // DHM - Nerve :: Clear even more things on respawn + cg.zoomedBinoc = qfalse; + cg.zoomedBinoc = cg.zoomedScope = qfalse; + cg.zoomTime = 0; + cg.zoomval = 0; + + // reset fog to world fog (if present) +// trap_R_SetFog(FOG_CMD_SWITCHFOG, FOG_MAP,20,0,0,0,0); + + // dhm - end + + trap_Cvar_Set( "cg_notebookpages", "3" ); // (SA) TEMP: clear notebook pages on spawn (cept for page 1&2) this is temporary + trap_Cvar_Set( "ui_notebookCurrentPage", "0" ); // (SA) TEMP: clear notebook pages on spawn (cept for page 1) this is temporary + + +// trap_S_FadeAllSound(1.0f, 1000); // make sure sound fades up + +} + +extern char *eventnames[]; + +/* +============== +CG_CheckPlayerstateEvents +============== +*/ +void CG_CheckPlayerstateEvents_wolf( playerState_t *ps, playerState_t *ops ) { + int i; + int event; + centity_t *cent; +/* + if ( ps->externalEvent && ps->externalEvent != ops->externalEvent ) { + cent = &cg_entities[ ps->clientNum ]; + cent->currentState.event = ps->externalEvent; + cent->currentState.eventParm = ps->externalEventParm; + CG_EntityEvent( cent, cent->lerpOrigin ); + } +*/ + cent = &cg.predictedPlayerEntity; // cg_entities[ ps->clientNum ]; + // go through the predictable events buffer + for ( i = ps->eventSequence - MAX_EVENTS ; i < ps->eventSequence ; i++ ) { + if ( ps->events[i & ( MAX_EVENTS - 1 )] != ops->events[i & ( MAX_EVENTS - 1 )] + || i >= ops->eventSequence ) { + event = ps->events[ i & ( MAX_EVENTS - 1 ) ]; + + cent->currentState.event = event; + cent->currentState.eventParm = ps->eventParms[ i & ( MAX_EVENTS - 1 ) ]; + CG_EntityEvent( cent, cent->lerpOrigin ); + } + } +} + +void CG_CheckPlayerstateEvents( playerState_t *ps, playerState_t *ops ) { + int i; + int event; + centity_t *cent; + + if ( ps->externalEvent && ps->externalEvent != ops->externalEvent ) { + cent = &cg_entities[ ps->clientNum ]; + cent->currentState.event = ps->externalEvent; + cent->currentState.eventParm = ps->externalEventParm; + CG_EntityEvent( cent, cent->lerpOrigin ); + } + + cent = &cg.predictedPlayerEntity; // cg_entities[ ps->clientNum ]; + // go through the predictable events buffer + for ( i = ps->eventSequence - MAX_EVENTS ; i < ps->eventSequence ; i++ ) { + // if we have a new predictable event + if ( i >= ops->eventSequence + // or the server told us to play another event instead of a predicted event we already issued + // or something the server told us changed our prediction causing a different event + || ( i > ops->eventSequence - MAX_EVENTS && ps->events[i & ( MAX_EVENTS - 1 )] != ops->events[i & ( MAX_EVENTS - 1 )] ) ) { + + event = ps->events[ i & ( MAX_EVENTS - 1 ) ]; + cent->currentState.event = event; + cent->currentState.eventParm = ps->eventParms[ i & ( MAX_EVENTS - 1 ) ]; + CG_EntityEvent( cent, cent->lerpOrigin ); + + cg.predictableEvents[ i & ( MAX_PREDICTED_EVENTS - 1 ) ] = event; + + cg.eventSequence++; + } + } +} + +/* +================== +CG_CheckChangedPredictableEvents +================== +*/ +void CG_CheckChangedPredictableEvents( playerState_t *ps ) { + int i; + int event; + centity_t *cent; + + cent = &cg.predictedPlayerEntity; + for ( i = ps->eventSequence - MAX_EVENTS ; i < ps->eventSequence ; i++ ) { + // + if ( i >= cg.eventSequence ) { + continue; + } + // if this event is not further back in than the maximum predictable events we remember + if ( i > cg.eventSequence - MAX_PREDICTED_EVENTS ) { + // if the new playerstate event is different from a previously predicted one + if ( ps->events[i & ( MAX_EVENTS - 1 )] != cg.predictableEvents[i & ( MAX_PREDICTED_EVENTS - 1 ) ] ) { + + event = ps->events[ i & ( MAX_EVENTS - 1 ) ]; + cent->currentState.event = event; + cent->currentState.eventParm = ps->eventParms[ i & ( MAX_EVENTS - 1 ) ]; + CG_EntityEvent( cent, cent->lerpOrigin ); + + cg.predictableEvents[ i & ( MAX_PREDICTED_EVENTS - 1 ) ] = event; + + if ( cg_showmiss.integer ) { + CG_Printf( "WARNING: changed predicted event\n" ); + } + } + } + } +} + + +/* +================== +CG_CheckLocalSounds +================== +*/ +void CG_CheckLocalSounds( playerState_t *ps, playerState_t *ops ) { + const char *s; + int highScore; + + // hit changes + if ( ps->persistant[PERS_HITS] > ops->persistant[PERS_HITS] ) { + trap_S_StartLocalSound( cgs.media.hitSound, CHAN_LOCAL_SOUND ); + } else if ( ps->persistant[PERS_HITS] < ops->persistant[PERS_HITS] ) { + trap_S_StartLocalSound( cgs.media.hitTeamSound, CHAN_LOCAL_SOUND ); + } + + // health changes of more than -1 should make pain sounds + if ( ps->stats[STAT_HEALTH] < ops->stats[STAT_HEALTH] - 1 ) { + if ( ps->stats[STAT_HEALTH] > 0 ) { + CG_PainEvent( &cg.predictedPlayerEntity, ps->stats[STAT_HEALTH], qfalse ); + } + } + + + // if we are going into the intermission, don't start any voices + if ( cg.intermissionStarted ) { + return; + } + + // reward sounds + if ( ps->persistant[PERS_REWARD_COUNT] > ops->persistant[PERS_REWARD_COUNT] ) { + switch ( ps->persistant[PERS_REWARD] ) { + case REWARD_IMPRESSIVE: + trap_S_StartLocalSound( cgs.media.impressiveSound, CHAN_ANNOUNCER ); + cg.rewardTime = cg.time; + cg.rewardShader = cgs.media.medalImpressive; + cg.rewardCount = ps->persistant[PERS_IMPRESSIVE_COUNT]; + break; + case REWARD_EXCELLENT: + trap_S_StartLocalSound( cgs.media.excellentSound, CHAN_ANNOUNCER ); + cg.rewardTime = cg.time; + cg.rewardShader = cgs.media.medalExcellent; + cg.rewardCount = ps->persistant[PERS_EXCELLENT_COUNT]; + break; + case REWARD_DENIED: + trap_S_StartLocalSound( cgs.media.deniedSound, CHAN_ANNOUNCER ); + break; + case REWARD_GAUNTLET: + trap_S_StartLocalSound( cgs.media.humiliationSound, CHAN_ANNOUNCER ); + // if we are the killer and not the killee, show the award + if ( ps->stats[STAT_HEALTH] ) { + cg.rewardTime = cg.time; + cg.rewardShader = cgs.media.medalGauntlet; + cg.rewardCount = ps->persistant[PERS_GAUNTLET_FRAG_COUNT]; + } + break; + default: + CG_Error( "Bad reward_t" ); + } + } else { + // lead changes (only if no reward) + s = CG_ConfigString( CS_WARMUP ); + if ( !s[0] ) { + // never play lead changes during warmup + if ( ps->persistant[PERS_RANK] != ops->persistant[PERS_RANK] ) { + if ( cgs.gametype >= GT_TEAM ) { + if ( ps->persistant[PERS_RANK] == 2 ) { + trap_S_StartLocalSound( cgs.media.teamsTiedSound, CHAN_ANNOUNCER ); + } else if ( ps->persistant[PERS_RANK] == 0 ) { + trap_S_StartLocalSound( cgs.media.redLeadsSound, CHAN_ANNOUNCER ); + } else if ( ps->persistant[PERS_RANK] == 1 ) { + trap_S_StartLocalSound( cgs.media.blueLeadsSound, CHAN_ANNOUNCER ); + } + } else { + if ( ps->persistant[PERS_RANK] == 0 ) { + trap_S_StartLocalSound( cgs.media.takenLeadSound, CHAN_ANNOUNCER ); + } else if ( ps->persistant[PERS_RANK] == RANK_TIED_FLAG ) { + trap_S_StartLocalSound( cgs.media.tiedLeadSound, CHAN_ANNOUNCER ); + } else if ( ( ops->persistant[PERS_RANK] & ~RANK_TIED_FLAG ) == 0 ) { + trap_S_StartLocalSound( cgs.media.lostLeadSound, CHAN_ANNOUNCER ); + } + } + } + } + } + + // timelimit warnings + if ( cgs.timelimit > 0 ) { + int msec; + + msec = cg.time - cgs.levelStartTime; + + if ( cgs.timelimit > 5 && !( cg.timelimitWarnings & 1 ) && msec > ( cgs.timelimit - 5 ) * 60 * 1000 ) { + cg.timelimitWarnings |= 1; + trap_S_StartLocalSound( cgs.media.fiveMinuteSound, CHAN_ANNOUNCER ); + } + if ( !( cg.timelimitWarnings & 2 ) && msec > ( cgs.timelimit - 1 ) * 60 * 1000 ) { + cg.timelimitWarnings |= 2; + trap_S_StartLocalSound( cgs.media.oneMinuteSound, CHAN_ANNOUNCER ); + } + if ( !( cg.timelimitWarnings & 4 ) && msec > ( cgs.timelimit * 60 + 2 ) * 1000 ) { + cg.timelimitWarnings |= 4; + trap_S_StartLocalSound( cgs.media.suddenDeathSound, CHAN_ANNOUNCER ); + } + } + + // fraglimit warnings + if ( cgs.fraglimit > 0 && cgs.gametype != GT_CTF ) { + highScore = cgs.scores1; + if ( cgs.fraglimit > 3 && !( cg.fraglimitWarnings & 1 ) && highScore == ( cgs.fraglimit - 3 ) ) { + cg.fraglimitWarnings |= 1; + trap_S_StartLocalSound( cgs.media.threeFragSound, CHAN_ANNOUNCER ); + } + if ( cgs.fraglimit > 2 && !( cg.fraglimitWarnings & 2 ) && highScore == ( cgs.fraglimit - 2 ) ) { + cg.fraglimitWarnings |= 2; + trap_S_StartLocalSound( cgs.media.twoFragSound, CHAN_ANNOUNCER ); + } + if ( !( cg.fraglimitWarnings & 4 ) && highScore == ( cgs.fraglimit - 1 ) ) { + cg.fraglimitWarnings |= 4; + trap_S_StartLocalSound( cgs.media.oneFragSound, CHAN_ANNOUNCER ); + } + } +} + +/* +=============== +CG_TransitionPlayerState + +=============== +*/ +void CG_TransitionPlayerState( playerState_t *ps, playerState_t *ops ) { + // check for changing follow mode + if ( ps->clientNum != ops->clientNum ) { + cg.thisFrameTeleport = qtrue; + // make sure we don't get any unwanted transition effects + *ops = *ps; + + // DHM - Nerve :: After Limbo, make sure and do a CG_Respawn + if ( ps->clientNum == cg.clientNum ) { + ops->persistant[PERS_SPAWN_COUNT]--; + } + } + + // damage events (player is getting wounded) + if ( ps->damageEvent != ops->damageEvent && ps->damageCount ) { + CG_DamageFeedback( ps->damageYaw, ps->damagePitch, ps->damageCount ); + } + + // respawning + if ( ps->persistant[PERS_SPAWN_COUNT] != ops->persistant[PERS_SPAWN_COUNT] ) { + CG_Respawn(); + } + + if ( cg.mapRestart ) { + CG_Respawn(); + cg.mapRestart = qfalse; + } + + if ( cg.snap->ps.pm_type != PM_INTERMISSION + && ps->persistant[PERS_TEAM] != TEAM_SPECTATOR ) { + CG_CheckLocalSounds( ps, ops ); + } + + // check for going low on ammo + CG_CheckAmmo(); + + // run events + CG_CheckPlayerstateEvents( ps, ops ); + + // smooth the ducking viewheight change + if ( ps->viewheight != ops->viewheight ) { + cg.duckChange = ps->viewheight - ops->viewheight; + cg.duckTime = cg.time; + } +} + diff --git a/Projects/Android/jni/rtcw/src/cgame/cg_predict.c b/Projects/Android/jni/rtcw/src/cgame/cg_predict.c new file mode 100644 index 0000000..0a06e47 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/cgame/cg_predict.c @@ -0,0 +1,765 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + + +// cg_predict.c -- this file generates cg.predictedPlayerState by either +// interpolating between snapshots from the server or locally predicting +// ahead the client's movement. +// It also handles local physics interaction, like fragments bouncing off walls + +#include "cg_local.h" + +static pmove_t cg_pmove; + +static int cg_numSolidEntities; +static centity_t *cg_solidEntities[MAX_ENTITIES_IN_SNAPSHOT]; +static int cg_numTriggerEntities; +static centity_t *cg_triggerEntities[MAX_ENTITIES_IN_SNAPSHOT]; + +/* +==================== +CG_BuildSolidList + +When a new cg.snap has been set, this function builds a sublist +of the entities that are actually solid, to make for more +efficient collision detection +==================== +*/ +void CG_BuildSolidList( void ) { + int i; + centity_t *cent; + snapshot_t *snap; + entityState_t *ent; + + cg_numSolidEntities = 0; + cg_numTriggerEntities = 0; + + if ( cg.nextSnap && !cg.nextFrameTeleport && !cg.thisFrameTeleport ) { + snap = cg.nextSnap; + } else { + snap = cg.snap; + } + + for ( i = 0 ; i < snap->numEntities ; i++ ) { + cent = &cg_entities[ snap->entities[ i ].number ]; + ent = ¢->currentState; + + // RF, dont clip again non-solid bmodels + if ( cent->nextState.solid == SOLID_BMODEL && ( cent->nextState.eFlags & EF_NONSOLID_BMODEL ) ) { + continue; + } + + if ( ent->eType == ET_ITEM || ent->eType == ET_PUSH_TRIGGER || ent->eType == ET_TELEPORT_TRIGGER ) { + cg_triggerEntities[cg_numTriggerEntities] = cent; + cg_numTriggerEntities++; + continue; + } + + if ( cent->nextState.solid ) { + cg_solidEntities[cg_numSolidEntities] = cent; + cg_numSolidEntities++; + continue; + } + } +} + +/* +==================== +CG_ClipMoveToEntities + +==================== +*/ +static void CG_ClipMoveToEntities( const vec3_t start, const vec3_t mins, const vec3_t maxs, const vec3_t end, + int skipNumber, int mask, int capsule, trace_t *tr ) { + int i, x, zd, zu; + trace_t trace; + entityState_t *ent; + clipHandle_t cmodel; + vec3_t bmins, bmaxs; + vec3_t origin, angles; + centity_t *cent; + + for ( i = 0 ; i < cg_numSolidEntities ; i++ ) { + cent = cg_solidEntities[ i ]; + ent = ¢->currentState; + + if ( ent->number == skipNumber ) { + continue; + } + + // RF, special case, ignore chairs if we are carrying them + if ( ent->eType == ET_PROP && ent->otherEntityNum == skipNumber + 1 ) { + continue; + } + + if ( ent->solid == SOLID_BMODEL ) { + // special value for bmodel + cmodel = trap_CM_InlineModel( ent->modelindex ); +// VectorCopy( cent->lerpAngles, angles ); + BG_EvaluateTrajectory( ¢->currentState.apos, cg.physicsTime, angles ); + BG_EvaluateTrajectory( ¢->currentState.pos, cg.physicsTime, origin ); + } else { + // encoded bbox + x = ( ent->solid & 255 ); + zd = ( ( ent->solid >> 8 ) & 255 ); + zu = ( ( ent->solid >> 16 ) & 255 ) - 32; + + bmins[0] = bmins[1] = -x; + bmaxs[0] = bmaxs[1] = x; + bmins[2] = -zd; + bmaxs[2] = zu; + + // MrE: use bbox or capsule + if ( ent->eFlags & EF_CAPSULE ) { + cmodel = trap_CM_TempCapsuleModel( bmins, bmaxs ); + } else { + cmodel = trap_CM_TempBoxModel( bmins, bmaxs ); + } + VectorCopy( vec3_origin, angles ); + VectorCopy( cent->lerpOrigin, origin ); + } + // MrE: use bbox of capsule + if ( capsule ) { + trap_CM_TransformedCapsuleTrace( &trace, start, end, + mins, maxs, cmodel, mask, origin, angles ); + } else { + trap_CM_TransformedBoxTrace( &trace, start, end, + mins, maxs, cmodel, mask, origin, angles ); + } + + if ( trace.allsolid || trace.fraction < tr->fraction ) { + trace.entityNum = ent->number; + *tr = trace; + } else if ( trace.startsolid ) { + tr->startsolid = qtrue; + } + if ( tr->allsolid ) { + return; + } + } +} + +/* +================ +CG_Trace +================ +*/ +void CG_Trace( trace_t *result, const vec3_t start, const vec3_t mins, const vec3_t maxs, const vec3_t end, + int skipNumber, int mask ) { + trace_t t; + + trap_CM_BoxTrace( &t, start, end, mins, maxs, 0, mask ); + t.entityNum = t.fraction != 1.0 ? ENTITYNUM_WORLD : ENTITYNUM_NONE; + // check all other solid models + CG_ClipMoveToEntities( start, mins, maxs, end, skipNumber, mask, qfalse, &t ); + + *result = t; +} + +/* +================ +CG_TraceCapsule +================ +*/ +void CG_TraceCapsule( trace_t *result, const vec3_t start, const vec3_t mins, const vec3_t maxs, const vec3_t end, + int skipNumber, int mask ) { + trace_t t; + + trap_CM_CapsuleTrace( &t, start, end, mins, maxs, 0, mask ); + t.entityNum = t.fraction != 1.0 ? ENTITYNUM_WORLD : ENTITYNUM_NONE; + // check all other solid models + CG_ClipMoveToEntities( start, mins, maxs, end, skipNumber, mask, qtrue, &t ); + + *result = t; +} + +/* +================ +CG_PointContents +================ +*/ +int CG_PointContents( const vec3_t point, int passEntityNum ) { + int i; + entityState_t *ent; + centity_t *cent; + clipHandle_t cmodel; + int contents; + + contents = trap_CM_PointContents( point, 0 ); + + for ( i = 0 ; i < cg_numSolidEntities ; i++ ) { + cent = cg_solidEntities[ i ]; + + ent = ¢->currentState; + + if ( ent->number == passEntityNum ) { + continue; + } + + if ( ent->solid != SOLID_BMODEL ) { // special value for bmodel + continue; + } + + cmodel = trap_CM_InlineModel( ent->modelindex ); + if ( !cmodel ) { + continue; + } + + contents |= trap_CM_TransformedPointContents( point, cmodel, ent->origin, ent->angles ); + } + + return contents; +} + + +/* +======================== +CG_InterpolatePlayerState + +Generates cg.predictedPlayerState by interpolating between +cg.snap->player_state and cg.nextFrame->player_state +======================== +*/ +static void CG_InterpolatePlayerState( qboolean grabAngles ) { + float f; + int i; + playerState_t *out; + snapshot_t *prev, *next; + + out = &cg.predictedPlayerState; + prev = cg.snap; + next = cg.nextSnap; + + *out = cg.snap->ps; + + // if we are still allowing local input, short circuit the view angles + if ( grabAngles ) { + usercmd_t cmd; + int cmdNum; + + cmdNum = trap_GetCurrentCmdNumber(); + trap_GetUserCmd( cmdNum, &cmd ); + + PM_UpdateViewAngles( out, &cmd, CG_Trace ); + } + + // if the next frame is a teleport, we can't lerp to it + if ( cg.nextFrameTeleport ) { + return; + } + + if ( !next || next->serverTime <= prev->serverTime ) { + return; + } + + f = (float)( cg.time - prev->serverTime ) / ( next->serverTime - prev->serverTime ); + + i = next->ps.bobCycle; + if ( i < prev->ps.bobCycle ) { + i += 256; // handle wraparound + } + out->bobCycle = prev->ps.bobCycle + f * ( i - prev->ps.bobCycle ); + + for ( i = 0 ; i < 3 ; i++ ) { + out->origin[i] = prev->ps.origin[i] + f * ( next->ps.origin[i] - prev->ps.origin[i] ); + if ( !grabAngles ) { + out->viewangles[i] = LerpAngle( + prev->ps.viewangles[i], next->ps.viewangles[i], f ); + } + out->velocity[i] = prev->ps.velocity[i] + + f * ( next->ps.velocity[i] - prev->ps.velocity[i] ); + } + +} + +/* +=================== +CG_TouchItem +=================== +*/ +static void CG_TouchItem( centity_t *cent ) { + gitem_t *item; + + if ( !cg_predictItems.integer ) { + return; + } + +//----(SA) wolf -- not allowing this for single player games +// if( cgs.gametype == GT_SINGLE_PLAYER) { +// return; +// } + +//----(SA) autoactivate + if ( !cg_autoactivate.integer ) { + return; + } +//----(SA) end + + + if ( !BG_PlayerTouchesItem( &cg.predictedPlayerState, ¢->currentState, cg.time ) ) { + return; + } + + // never pick an item up twice in a prediction + if ( cent->miscTime == cg.time ) { + return; + } + + if ( !BG_CanItemBeGrabbed( ¢->currentState, &cg.predictedPlayerState ) ) { + return; // can't hold it + } + + item = &bg_itemlist[ cent->currentState.modelindex ]; + + // (SA) no prediction of books/clipboards + if ( item->giType == IT_HOLDABLE ) { + if ( item->giTag >= HI_BOOK1 && item->giTag <= HI_BOOK3 ) { + return; + } + } + if ( item->giType == IT_CLIPBOARD ) { + return; + } + + // Special case for flags. + // We don't predict touching our own flag + if ( cg.predictedPlayerState.persistant[PERS_TEAM] == TEAM_RED && + item->giTag == PW_REDFLAG ) { + return; + } + if ( cg.predictedPlayerState.persistant[PERS_TEAM] == TEAM_BLUE && + item->giTag == PW_BLUEFLAG ) { + return; + } + + + // grab it + BG_AddPredictableEventToPlayerstate( EV_ITEM_PICKUP, cent->currentState.modelindex, &cg.predictedPlayerState ); + + // remove it from the frame so it won't be drawn + cent->currentState.eFlags |= EF_NODRAW; + + // don't touch it again this prediction + cent->miscTime = cg.time; + + // if its a weapon, give them some predicted ammo so the autoswitch will work + if ( item->giType == IT_WEAPON ) { + int weapon; +//----(SA) added + weapon = item->giTag; + + if ( weapon == WP_COLT ) { + if ( COM_BitCheck( cg.predictedPlayerState.weapons, WP_COLT ) ) { + // you got the colt, you gettin' another + weapon = WP_AKIMBO; + } + } +//----(SA) end + + COM_BitSet( cg.predictedPlayerState.weapons, weapon ); + +//----(SA) added + if ( weapon == WP_SNOOPERSCOPE ) { + COM_BitSet( cg.predictedPlayerState.weapons, WP_GARAND ); + } else if ( weapon == WP_GARAND ) { + COM_BitSet( cg.predictedPlayerState.weapons, WP_SNOOPERSCOPE ); + } else if ( weapon == WP_FG42 ) { + COM_BitSet( cg.predictedPlayerState.weapons, WP_FG42SCOPE ); + } else if ( weapon == WP_SNIPERRIFLE ) { + COM_BitSet( cg.predictedPlayerState.weapons, WP_MAUSER ); + } +//----(SA) end + + if ( !cg.predictedPlayerState.ammo[ BG_FindAmmoForWeapon( weapon )] ) { + cg.predictedPlayerState.ammo[ BG_FindAmmoForWeapon( weapon )] = 1; + } + } + +//----(SA) + if ( item->giType == IT_HOLDABLE ) { + cg.predictedPlayerState.stats[ STAT_HOLDABLE_ITEM ] |= 1 << item->giTag; + } +//----(SA) end +} + + +/* +========================= +CG_TouchTriggerPrediction + +Predict push triggers and items +========================= +*/ +static void CG_TouchTriggerPrediction( void ) { + int i; + trace_t trace; + entityState_t *ent; + clipHandle_t cmodel; + centity_t *cent; + qboolean spectator; + + // dead clients don't activate triggers + if ( cg.predictedPlayerState.stats[STAT_HEALTH] <= 0 ) { + return; + } + + spectator = ( ( cg.predictedPlayerState.pm_type == PM_SPECTATOR ) || ( cg.predictedPlayerState.pm_flags & PMF_LIMBO ) ); // JPW NERVE + + if ( cg.predictedPlayerState.pm_type != PM_NORMAL && !spectator ) { + return; + } + + for ( i = 0 ; i < cg_numTriggerEntities ; i++ ) { + cent = cg_triggerEntities[ i ]; + ent = ¢->currentState; + + if ( ent->eType == ET_ITEM && !spectator ) { + CG_TouchItem( cent ); + continue; + } + + if ( ent->solid != SOLID_BMODEL ) { + continue; + } + + cmodel = trap_CM_InlineModel( ent->modelindex ); + if ( !cmodel ) { + continue; + } + + trap_CM_BoxTrace( &trace, cg.predictedPlayerState.origin, cg.predictedPlayerState.origin, + cg_pmove.mins, cg_pmove.maxs, cmodel, -1 ); + + if ( !trace.startsolid ) { + continue; + } + + if ( ent->eType == ET_TELEPORT_TRIGGER ) { + cg.hyperspace = qtrue; + } else { + float s; + vec3_t dir; + + // we hit this push trigger + if ( spectator ) { + continue; + } + + // flying characters don't hit bounce pads + if ( cg.predictedPlayerState.powerups[PW_FLIGHT] ) { + continue; + } + + // if we are already flying along the bounce direction, don't play sound again + VectorNormalize2( ent->origin2, dir ); + s = DotProduct( cg.predictedPlayerState.velocity, dir ); + if ( s < 500 ) { + // don't play the event sound again if we are in a fat trigger + BG_AddPredictableEventToPlayerstate( EV_JUMP_PAD, 0, &cg.predictedPlayerState ); + } + VectorCopy( ent->origin2, cg.predictedPlayerState.velocity ); + } + } +} + + + +/* +================= +CG_PredictPlayerState + +Generates cg.predictedPlayerState for the current cg.time +cg.predictedPlayerState is guaranteed to be valid after exiting. + +For demo playback, this will be an interpolation between two valid +playerState_t. + +For normal gameplay, it will be the result of predicted usercmd_t on +top of the most recent playerState_t received from the server. + +Each new snapshot will usually have one or more new usercmd over the last, +but we simulate all unacknowledged commands each time, not just the new ones. +This means that on an internet connection, quite a few pmoves may be issued +each frame. + +OPTIMIZE: don't re-simulate unless the newly arrived snapshot playerState_t +differs from the predicted one. Would require saving all intermediate +playerState_t during prediction. (this is "dead reckoning" and would definately +be nice to have in there (SA)) + +We detect prediction errors and allow them to be decayed off over several frames +to ease the jerk. +================= +*/ +void CG_PredictPlayerState( void ) { + int cmdNum, current; + playerState_t oldPlayerState; + qboolean moved; + usercmd_t oldestCmd; + usercmd_t latestCmd; + vec3_t deltaAngles; + + cg.hyperspace = qfalse; // will be set if touching a trigger_teleport + + // if this is the first frame we must guarantee + // predictedPlayerState is valid even if there is some + // other error condition + if ( !cg.validPPS ) { + cg.validPPS = qtrue; + cg.predictedPlayerState = cg.snap->ps; + } + + // demo playback just copies the moves + if ( cg.demoPlayback || ( cg.snap->ps.pm_flags & PMF_FOLLOW ) ) { + CG_InterpolatePlayerState( qfalse ); + return; + } + + // non-predicting local movement will grab the latest angles + if ( cg_nopredict.integer || cg_synchronousClients.integer + || ( cg.snap->ps.eFlags & EF_MG42_ACTIVE ) ) { // RF, somewhat of a hack, but just disable prediction if on MG42, since it's just not very prediction friendly + CG_InterpolatePlayerState( qtrue ); + return; + } + + // prepare for pmove + cg_pmove.ps = &cg.predictedPlayerState; + cg_pmove.trace = CG_TraceCapsule; + cg_pmove.pointcontents = CG_PointContents; + if ( cg_pmove.ps->pm_type == PM_DEAD ) { + cg_pmove.tracemask = MASK_PLAYERSOLID & ~CONTENTS_BODY; + // DHM-Nerve added:: EF_DEAD is checked for in Pmove functions, but wasn't being set + // until after Pmove + cg_pmove.ps->eFlags |= EF_DEAD; + // dhm-Nerve end + } else { + cg_pmove.tracemask = MASK_PLAYERSOLID; + } + if ( ( cg.snap->ps.persistant[PERS_TEAM] == TEAM_SPECTATOR ) || ( cg.snap->ps.pm_flags & PMF_LIMBO ) ) { // JPW NERVE limbo + cg_pmove.tracemask &= ~CONTENTS_BODY; // spectators can fly through bodies + } + cg_pmove.noFootsteps = ( cgs.dmflags & DF_NO_FOOTSTEPS ) > 0; + + //----(SA) added + cg_pmove.noWeapClips = ( cgs.dmflags & DF_NO_WEAPRELOAD ) > 0; + if ( cg.predictedPlayerState.aiChar ) { + cg_pmove.noWeapClips = qtrue; // ensure AI characters don't use clips + } +//----(SA) end + + + // save the state before the pmove so we can detect transitions + oldPlayerState = cg.predictedPlayerState; + + current = trap_GetCurrentCmdNumber(); + + // if we don't have the commands right after the snapshot, we + // can't accurately predict a current position, so just freeze at + // the last good position we had + cmdNum = current - CMD_BACKUP + 1; + trap_GetUserCmd( cmdNum, &oldestCmd ); + if ( oldestCmd.serverTime > cg.snap->ps.commandTime + && oldestCmd.serverTime < cg.time ) { // special check for map_restart + if ( cg_showmiss.integer ) { + CG_Printf( "exceeded PACKET_BACKUP on commands\n" ); + } +// return; + } + + // get the latest command so we can know which commands are from previous map_restarts + trap_GetUserCmd( current, &latestCmd ); + + // get the most recent information we have, even if + // the server time is beyond our current cg.time, + // because predicted player positions are going to + // be ahead of everything else anyway + if ( cg.nextSnap && !cg.nextFrameTeleport && !cg.thisFrameTeleport ) { + cg.predictedPlayerState = cg.nextSnap->ps; + cg.physicsTime = cg.nextSnap->serverTime; + } else { + cg.predictedPlayerState = cg.snap->ps; + cg.physicsTime = cg.snap->serverTime; + } + + if ( pmove_msec.integer < 8 ) { + trap_Cvar_Set( "pmove_msec", "8" ); + } else if ( pmove_msec.integer > 33 ) { + trap_Cvar_Set( "pmove_msec", "33" ); + } + + cg_pmove.pmove_fixed = pmove_fixed.integer; // | cg_pmove_fixed.integer; + cg_pmove.pmove_msec = pmove_msec.integer; + +//----(SA) added + // restore persistant client-side playerstate variables before doing the pmove + // this could be done as suggested in qshared.h ~line 991, but right now I copy each variable individually + cg.predictedPlayerState.weapAnim = oldPlayerState.weapAnim; + cg.predictedPlayerState.weapAnimTimer = oldPlayerState.weapAnimTimer; + cg.predictedPlayerState.venomTime = oldPlayerState.venomTime; + // show_bug.cgi?id=416 + // FIXME TTimo this causing a double weapon reload sound if you hit reload at the same time you run out of ammo + // cg.predictedPlayerState.weaponstate = oldPlayerState.weaponstate; // RF, added this, since they can become unsynched on loadgame, leaving incorrect anims + +//----(SA) end + + // RF, anim system + if ( cg_animState.integer ) { + cg.predictedPlayerState.aiState = cg_animState.integer - 1; + } + + // run cmds + moved = qfalse; + for ( cmdNum = current - CMD_BACKUP + 1 ; cmdNum <= current ; cmdNum++ ) { + // get the command + trap_GetUserCmd( cmdNum, &cg_pmove.cmd ); + // get the previous command + trap_GetUserCmd( cmdNum - 1, &cg_pmove.oldcmd ); + + if ( cg_pmove.pmove_fixed ) { + PM_UpdateViewAngles( cg_pmove.ps, &cg_pmove.cmd, CG_Trace ); + } + + // don't do anything if the time is before the snapshot player time + if ( cg_pmove.cmd.serverTime <= cg.predictedPlayerState.commandTime ) { + continue; + } + + // don't do anything if the command was from a previous map_restart + if ( cg_pmove.cmd.serverTime > latestCmd.serverTime ) { + continue; + } + + // check for a prediction error from last frame + // on a lan, this will often be the exact value + // from the snapshot, but on a wan we will have + // to predict several commands to get to the point + // we want to compare + if ( cg.predictedPlayerState.commandTime == oldPlayerState.commandTime ) { + vec3_t delta; + float len; + + if ( cg.thisFrameTeleport ) { + // a teleport will not cause an error decay + VectorClear( cg.predictedError ); + if ( cg_showmiss.integer ) { + CG_Printf( "PredictionTeleport\n" ); + } + cg.thisFrameTeleport = qfalse; + } else { + vec3_t adjusted; + CG_AdjustPositionForMover( cg.predictedPlayerState.origin, + cg.predictedPlayerState.groundEntityNum, cg.physicsTime, cg.oldTime, adjusted, deltaAngles ); + // RF, add the deltaAngles (fixes jittery view while riding trains) + cg.predictedPlayerState.delta_angles[YAW] += ANGLE2SHORT( deltaAngles[YAW] ); + + if ( cg_showmiss.integer ) { + if ( !VectorCompare( oldPlayerState.origin, adjusted ) ) { + CG_Printf( "prediction error\n" ); + } + } + VectorSubtract( oldPlayerState.origin, adjusted, delta ); + len = VectorLength( delta ); + if ( len > 0.1 ) { + if ( cg_showmiss.integer ) { + CG_Printf( "Prediction miss: %f\n", len ); + } + if ( cg_errorDecay.integer ) { + int t; + float f; + + t = cg.time - cg.predictedErrorTime; + f = ( cg_errorDecay.value - t ) / cg_errorDecay.value; + if ( f < 0 ) { + f = 0; + } + if ( f > 0 && cg_showmiss.integer ) { + CG_Printf( "Double prediction decay: %f\n", f ); + } + VectorScale( cg.predictedError, f, cg.predictedError ); + } else { + VectorClear( cg.predictedError ); + } + VectorAdd( delta, cg.predictedError, cg.predictedError ); + cg.predictedErrorTime = cg.oldTime; + } + } + } + + // don't predict gauntlet firing, which is only supposed to happen + // when it actually inflicts damage + cg_pmove.gauntletHit = qfalse; + + if ( cg_pmove.pmove_fixed ) { + cg_pmove.cmd.serverTime = ( ( cg_pmove.cmd.serverTime + pmove_msec.integer - 1 ) / pmove_msec.integer ) * pmove_msec.integer; + } + + // RF, if waiting for mission stats to go, ignore all input + if ( ( cgs.scrFadeAlphaCurrent ) || cg_norender.integer ) { + cg_pmove.cmd.buttons = 0; + cg_pmove.cmd.forwardmove = 0; + cg_pmove.cmd.rightmove = 0; + cg_pmove.cmd.upmove = 0; + cg_pmove.cmd.wbuttons = 0; + cg_pmove.cmd.wolfkick = 0; + cg_pmove.cmd.angles[0] = cg_pmove.oldcmd.angles[0]; + cg_pmove.cmd.angles[1] = cg_pmove.oldcmd.angles[1]; + cg_pmove.cmd.angles[2] = cg_pmove.oldcmd.angles[2]; + if ( cg_pmove.cmd.serverTime - cg.predictedPlayerState.commandTime > 1 ) { + cg_pmove.cmd.serverTime = cg.predictedPlayerState.commandTime + 1; + } + } + + Pmove( &cg_pmove ); + + moved = qtrue; + + // add push trigger movement effects + CG_TouchTriggerPrediction(); + } + + if ( cg_showmiss.integer > 1 ) { + CG_Printf( "[%i : %i] ", cg_pmove.cmd.serverTime, cg.time ); + } + + if ( !moved ) { + if ( cg_showmiss.integer ) { + CG_Printf( "not moved\n" ); + } + return; + } + + // adjust for the movement of the groundentity + CG_AdjustPositionForMover( cg.predictedPlayerState.origin, + cg.predictedPlayerState.groundEntityNum, + cg.physicsTime, cg.time, cg.predictedPlayerState.origin, deltaAngles ); + + // fire events and other transition triggered things + CG_TransitionPlayerState( &cg.predictedPlayerState, &oldPlayerState ); +} + diff --git a/Projects/Android/jni/rtcw/src/cgame/cg_public.h b/Projects/Android/jni/rtcw/src/cgame/cg_public.h new file mode 100644 index 0000000..d951595 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/cgame/cg_public.h @@ -0,0 +1,278 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + + +#define CMD_BACKUP 64 +#define CMD_MASK ( CMD_BACKUP - 1 ) +// allow a lot of command backups for very fast systems +// multiple commands may be combined into a single packet, so this +// needs to be larger than PACKET_BACKUP + + +#define MAX_ENTITIES_IN_SNAPSHOT 256 + +// snapshots are a view of the server at a given time + +// Snapshots are generated at regular time intervals by the server, +// but they may not be sent if a client's rate level is exceeded, or +// they may be dropped by the network. +typedef struct { + int snapFlags; // SNAPFLAG_RATE_DELAYED, etc + int ping; + + int serverTime; // server time the message is valid for (in msec) + + byte areamask[MAX_MAP_AREA_BYTES]; // portalarea visibility bits + + playerState_t ps; // complete information about the current player at this time + + int numEntities; // all of the entities that need to be presented + entityState_t entities[MAX_ENTITIES_IN_SNAPSHOT]; // at the time of this snapshot + + int numServerCommands; // text based server commands to execute when this + int serverCommandSequence; // snapshot becomes current +} snapshot_t; + +enum { + CGAME_EVENT_NONE, + CGAME_EVENT_TEAMMENU, + CGAME_EVENT_SCOREBOARD, + CGAME_EVENT_EDITHUD +}; + + +/* +================================================================== + +functions imported from the main executable + +================================================================== +*/ + +#define CGAME_IMPORT_API_VERSION 3 + +typedef enum { + CG_PRINT, + CG_ERROR, + CG_MILLISECONDS, + CG_CVAR_REGISTER, + CG_CVAR_UPDATE, + CG_CVAR_SET, + CG_CVAR_VARIABLESTRINGBUFFER, + CG_ARGC, + CG_ARGV, + CG_ARGS, + CG_FS_FOPENFILE, + CG_FS_READ, + CG_FS_WRITE, + CG_FS_FCLOSEFILE, + CG_SENDCONSOLECOMMAND, + CG_ADDCOMMAND, + CG_SENDCLIENTCOMMAND, + CG_UPDATESCREEN, + CG_CM_LOADMAP, + CG_CM_NUMINLINEMODELS, + CG_CM_INLINEMODEL, + CG_CM_LOADMODEL, + CG_CM_TEMPBOXMODEL, + CG_CM_POINTCONTENTS, + CG_CM_TRANSFORMEDPOINTCONTENTS, + CG_CM_BOXTRACE, + CG_CM_TRANSFORMEDBOXTRACE, +// MrE: + CG_CM_CAPSULETRACE, + CG_CM_TRANSFORMEDCAPSULETRACE, + CG_CM_TEMPCAPSULEMODEL, +// done. + CG_CM_MARKFRAGMENTS, + CG_S_STARTSOUND, + CG_S_STARTSOUNDEX, //----(SA) added + CG_S_STARTLOCALSOUND, + CG_S_CLEARLOOPINGSOUNDS, + CG_S_ADDLOOPINGSOUND, + CG_S_UPDATEENTITYPOSITION, +// Ridah, talking animations + CG_S_GETVOICEAMPLITUDE, +// done. + CG_S_RESPATIALIZE, + CG_S_REGISTERSOUND, + CG_S_STARTBACKGROUNDTRACK, + CG_S_FADESTREAMINGSOUND, //----(SA) modified + CG_S_FADEALLSOUNDS, //----(SA) added for fading out everything + CG_S_STARTSTREAMINGSOUND, + CG_R_LOADWORLDMAP, + CG_R_REGISTERMODEL, + CG_R_REGISTERSKIN, + CG_R_REGISTERSHADER, + + CG_R_GETSKINMODEL, // client allowed to view what the .skin loaded so they can set their model appropriately + CG_R_GETMODELSHADER, // client allowed the shader handle for given model/surface (for things like debris inheriting shader from explosive) + + CG_R_REGISTERFONT, + CG_R_CLEARSCENE, + CG_R_ADDREFENTITYTOSCENE, + CG_GET_ENTITY_TOKEN, + CG_R_ADDPOLYTOSCENE, +// Ridah + CG_R_ADDPOLYSTOSCENE, + CG_RB_ZOMBIEFXADDNEWHIT, +// done. + CG_R_ADDLIGHTTOSCENE, + + CG_R_ADDCORONATOSCENE, + CG_R_SETFOG, + + CG_R_RENDERSCENE, + CG_R_SETCOLOR, + CG_R_DRAWSTRETCHPIC, + CG_R_DRAWSTRETCHPIC_GRADIENT, //----(SA) added + CG_R_MODELBOUNDS, + CG_R_LERPTAG, + CG_GETGLCONFIG, + CG_GETGAMESTATE, + CG_GETCURRENTSNAPSHOTNUMBER, + CG_GETSNAPSHOT, + CG_GETSERVERCOMMAND, + CG_GETCURRENTCMDNUMBER, + CG_GETUSERCMD, + CG_SETUSERCMDVALUE, + CG_R_REGISTERSHADERNOMIP, + CG_MEMORY_REMAINING, + + CG_KEY_ISDOWN, + CG_KEY_GETCATCHER, + CG_KEY_SETCATCHER, + CG_KEY_GETKEY, + + CG_PC_ADD_GLOBAL_DEFINE, + CG_PC_LOAD_SOURCE, + CG_PC_FREE_SOURCE, + CG_PC_READ_TOKEN, + CG_PC_SOURCE_FILE_AND_LINE, + CG_S_STOPBACKGROUNDTRACK, + CG_REAL_TIME, + CG_SNAPVECTOR, + CG_REMOVECOMMAND, +// CG_R_LIGHTFORPOINT, // not currently used (sorry, trying to keep CG_MEMSET @ 100) + + CG_SENDMOVESPEEDSTOGAME, + + CG_CIN_PLAYCINEMATIC, + CG_CIN_STOPCINEMATIC, + CG_CIN_RUNCINEMATIC, + CG_CIN_DRAWCINEMATIC, + CG_CIN_SETEXTENTS, + CG_R_REMAP_SHADER, +// CG_S_ADDREALLOOPINGSOUND, // not currently used (sorry, trying to keep CG_MEMSET @ 100) + CG_S_STOPLOOPINGSOUND, + CG_S_STOPSTREAMINGSOUND, //----(SA) added + + CG_LOADCAMERA, + CG_STARTCAMERA, + CG_STOPCAMERA, //----(SA) added + CG_GETCAMERAINFO, + + CG_MEMSET = 110, + CG_MEMCPY, + CG_STRNCPY, + CG_SIN, + CG_COS, + CG_ATAN2, + CG_SQRT, + CG_FLOOR, + CG_CEIL, + + CG_TESTPRINTINT, + CG_TESTPRINTFLOAT, + CG_ACOS, + + CG_INGAME_POPUP, //----(SA) added + CG_INGAME_CLOSEPOPUP, // NERVE - SMF + CG_LIMBOCHAT, // NERVE - SMF + + CG_GETMODELINFO +} cgameImport_t; + + +/* +================================================================== + +functions exported to the main executable + +================================================================== +*/ + +typedef enum { + CG_INIT, +// void CG_Init( int serverMessageNum, int serverCommandSequence ) + // called when the level loads or when the renderer is restarted + // all media should be registered at this time + // cgame will display loading status by calling SCR_Update, which + // will call CG_DrawInformation during the loading process + // reliableCommandSequence will be 0 on fresh loads, but higher for + // demos, tourney restarts, or vid_restarts + + CG_SHUTDOWN, +// void (*CG_Shutdown)( void ); + // oportunity to flush and close any open files + + CG_CONSOLE_COMMAND, +// qboolean (*CG_ConsoleCommand)( void ); + // a console command has been issued locally that is not recognized by the + // main game system. + // use Cmd_Argc() / Cmd_Argv() to read the command, return qfalse if the + // command is not known to the game + + CG_DRAW_ACTIVE_FRAME, +// void (*CG_DrawActiveFrame)( int serverTime, stereoFrame_t stereoView, qboolean demoPlayback ); + // Generates and draws a game scene and status information at the given time. + // If demoPlayback is set, local movement prediction will not be enabled + + CG_CROSSHAIR_PLAYER, +// int (*CG_CrosshairPlayer)( void ); + + CG_LAST_ATTACKER, +// int (*CG_LastAttacker)( void ); + + CG_KEY_EVENT, +// void (*CG_KeyEvent)( int key, qboolean down ); + + CG_MOUSE_EVENT, +// void (*CG_MouseEvent)( int dx, int dy ); + CG_EVENT_HANDLING, +// void (*CG_EventHandling)(int type); + + CG_GET_TAG, +// qboolean CG_GetTag( int clientNum, char *tagname, orientation_t *or ); + + MAX_CGAME_EXPORT + +} cgameExport_t; + +//---------------------------------------------- diff --git a/Projects/Android/jni/rtcw/src/cgame/cg_scoreboard.c b/Projects/Android/jni/rtcw/src/cgame/cg_scoreboard.c new file mode 100644 index 0000000..a787a0a --- /dev/null +++ b/Projects/Android/jni/rtcw/src/cgame/cg_scoreboard.c @@ -0,0 +1,698 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +// cg_scoreboard -- draw the scoreboard on top of the game screen +#include "cg_local.h" + + +#define SCOREBOARD_WIDTH ( 31 * BIGCHAR_WIDTH ) + +/* +================= +CG_DrawScoreboard +================= +*/ +static void CG_DrawClientScore( int x, int y, score_t *score, float *color, float fade ) { + char string[1024]; + vec3_t headAngles; + clientInfo_t *ci; + + if ( score->client < 0 || score->client >= cgs.maxclients ) { + Com_Printf( "Bad score->client: %i\n", score->client ); + return; + } + + ci = &cgs.clientinfo[score->client]; + + // draw the handicap or bot skill marker + if ( ci->botSkill > 0 && ci->botSkill <= 5 ) { + CG_DrawPic( 0, y - 8, 32, 32, cgs.media.botSkillShaders[ ci->botSkill - 1 ] ); + } else if ( ci->handicap < 100 ) { + Com_sprintf( string, sizeof( string ), "%i", ci->handicap ); + CG_DrawSmallStringColor( 8, y, string, color ); + } + + // draw the wins / losses + if ( cgs.gametype == GT_TOURNAMENT ) { + Com_sprintf( string, sizeof( string ), "%i/%i", ci->wins, ci->losses ); + CG_DrawSmallStringColor( x + SCOREBOARD_WIDTH + 2, y, string, color ); + } + + // draw the face + VectorClear( headAngles ); + headAngles[YAW] = 180; + + CG_DrawHead( x - ICON_SIZE, y - ( ICON_SIZE - BIGCHAR_HEIGHT ) / 2, ICON_SIZE, ICON_SIZE, + score->client, headAngles ); + + if ( ci->powerups & ( 1 << PW_REDFLAG ) ) { + CG_DrawFlagModel( x - ICON_SIZE - ICON_SIZE / 2, y - ( ICON_SIZE - BIGCHAR_HEIGHT ) / 2, ICON_SIZE, ICON_SIZE, + TEAM_RED ); + } else if ( ci->powerups & ( 1 << PW_BLUEFLAG ) ) { + CG_DrawFlagModel( x - ICON_SIZE - ICON_SIZE / 2, y - ( ICON_SIZE - BIGCHAR_HEIGHT ) / 2, ICON_SIZE, ICON_SIZE, + TEAM_BLUE ); + } + + // draw the score line + if ( score->ping == -1 ) { + Com_sprintf( string, sizeof( string ), + "connecting %s", ci->name ); + } else if ( ci->team == TEAM_SPECTATOR ) { + Com_sprintf( string, sizeof( string ), + "SPECT %4i %4i %s", score->ping, score->time, ci->name ); + } else { + Com_sprintf( string, sizeof( string ), + "%5i %4i %4i %s", score->score, score->ping, score->time, ci->name ); + } + + // highlight your position + if ( score->client == cg.snap->ps.clientNum ) { + float hcolor[4]; + int rank; + + if ( cg.snap->ps.persistant[PERS_TEAM] == TEAM_SPECTATOR + || cgs.gametype >= GT_TEAM ) { + rank = -1; + } else { + rank = cg.snap->ps.persistant[PERS_RANK] & ~RANK_TIED_FLAG; + } + + if ( rank == 0 ) { + hcolor[0] = 0; + hcolor[1] = 0; + hcolor[2] = 0.7; + } else if ( rank == 1 ) { + hcolor[0] = 0.7; + hcolor[1] = 0; + hcolor[2] = 0; + } else if ( rank == 2 ) { + hcolor[0] = 0.7; + hcolor[1] = 0.7; + hcolor[2] = 0; + } else { + hcolor[0] = 0.7; + hcolor[1] = 0.7; + hcolor[2] = 0.7; + } + + hcolor[3] = fade * 0.7; + CG_FillRect( x - 2, y, SCOREBOARD_WIDTH, BIGCHAR_HEIGHT + 1, hcolor ); + } + + CG_DrawBigString( x, y, string, fade ); + + // add the "ready" marker for intermission exiting + if ( cg.snap->ps.stats[ STAT_CLIENTS_READY ] & ( 1 << score->client ) ) { + CG_DrawBigStringColor( 0, y, "READY", color ); + } +} + +/* +================= +CG_TeamScoreboard +================= +*/ +static int CG_TeamScoreboard( int x, int y, team_t team, float fade ) { + int i; + score_t *score; + float color[4]; + int count; + int lineHeight; + clientInfo_t *ci; + + color[0] = color[1] = color[2] = 1.0; + color[3] = fade; + + count = 0; + lineHeight = 40; + // don't draw more than 9 rows + for ( i = 0 ; i < cg.numScores && count < 9 ; i++ ) { + score = &cg.scores[i]; + ci = &cgs.clientinfo[ score->client ]; + + if ( team != ci->team ) { + continue; + } + + CG_DrawClientScore( x, y + lineHeight * count, score, color, fade ); + count++; + } + + return y + count * lineHeight + 20; +} + +// NERVE - SMF +/* +================= +WM_DrawClientScore +================= +*/ +static int INFO_PLAYER_WIDTH = 300; +static int INFO_SCORE_WIDTH = 50; +static int INFO_LATENCY_WIDTH = 80; +static int INFO_TEAM_HEIGHT = 24; +static int INFO_BORDER = 2; + +static void WM_DrawClientScore( int x, int y, score_t *score, float *color, float fade ) { + float tempx; + vec4_t hcolor; + clientInfo_t *ci; + + if ( y + SMALLCHAR_HEIGHT >= 440 ) { + return; + } + + if ( score->client == cg.snap->ps.clientNum ) { + tempx = x; + + hcolor[3] = fade * 0.3; + VectorSet( hcolor, 0.4452, 0.1172, 0.0782 ); // DARK-RED + + CG_FillRect( tempx, y + 1, INFO_PLAYER_WIDTH - INFO_BORDER, SMALLCHAR_HEIGHT - 1, hcolor ); + tempx += INFO_PLAYER_WIDTH; + + CG_FillRect( tempx, y + 1, INFO_SCORE_WIDTH - INFO_BORDER, SMALLCHAR_HEIGHT - 1, hcolor ); + tempx += INFO_SCORE_WIDTH; + + CG_FillRect( tempx, y + 1, INFO_LATENCY_WIDTH - INFO_BORDER, SMALLCHAR_HEIGHT - 1, hcolor ); + tempx += INFO_LATENCY_WIDTH; + } + + tempx = x; + ci = &cgs.clientinfo[score->client]; + + CG_DrawSmallString( tempx, y, ci->name, fade ); + tempx += INFO_PLAYER_WIDTH; + + CG_DrawSmallString( tempx, y, va( "%4i", score->score ), fade ); + tempx += INFO_SCORE_WIDTH; + + CG_DrawSmallString( tempx, y, va( "%4i", score->ping ), fade ); + tempx += INFO_LATENCY_WIDTH; +} + +/* +================= +WM_TeamScoreboard +================= +*/ +static int WM_TeamScoreboard( int x, int y, team_t team, float fade ) { + vec4_t hcolor; + float tempx; + int i; + + hcolor[3] = fade; + if ( team == TEAM_RED ) { + VectorSet( hcolor, 0.4452, 0.1172, 0.0782 ); // LIGHT-RED + } else if ( team == TEAM_BLUE ) { + VectorSet( hcolor, 0.1836, 0.2422, 0.1680 ); // LIGHT-GREEN + } else { + VectorSet( hcolor, 0.2, 0.2, 0.2 ); // DARK-GREY + + } + // dont draw spectator if there are none + for ( i = 0; i < cg.numScores; i++ ) { + if ( team == cgs.clientinfo[ cg.scores[i].client ].team ) { + break; + } + } + if ( team == TEAM_SPECTATOR && i == cg.numScores ) { + return y; + } + + // draw team header + if ( y + SMALLCHAR_HEIGHT >= 440 ) { + return y; + } + + tempx = x; + + CG_FillRect( tempx, y, INFO_PLAYER_WIDTH - INFO_BORDER, INFO_TEAM_HEIGHT, hcolor ); + if ( team == TEAM_RED ) { + CG_DrawSmallString( tempx, y, "Axis", fade ); + } else if ( team == TEAM_BLUE ) { + CG_DrawSmallString( tempx, y, "Allies", fade ); + } else { + CG_DrawSmallString( tempx, y, "Spectators", fade ); + } + tempx += INFO_PLAYER_WIDTH; + + CG_FillRect( tempx, y, INFO_SCORE_WIDTH - INFO_BORDER, INFO_TEAM_HEIGHT, hcolor ); + tempx += INFO_SCORE_WIDTH; + + CG_FillRect( tempx, y, INFO_LATENCY_WIDTH - INFO_BORDER, INFO_TEAM_HEIGHT, hcolor ); + tempx += INFO_LATENCY_WIDTH; + + // draw player info + VectorSet( hcolor, 1, 1, 1 ); + hcolor[3] = fade; + + y += INFO_TEAM_HEIGHT + INFO_BORDER; + + for ( i = 0; i < cg.numScores; i++ ) { + if ( team != cgs.clientinfo[ cg.scores[i].client ].team ) { + continue; + } + + WM_DrawClientScore( x, y, &cg.scores[i], hcolor, fade ); + y += SMALLCHAR_HEIGHT; + } + + y += 4; + + return y; +} + +/* +================= +WM_DrawObjectives +================= +*/ +int WM_DrawObjectives( int x, int y, int width, float fade ) { + const char *s, *buf, *str; + char teamstr[32]; + int i, num, strwidth, status; + + y += 32; + + // determine character's team + if ( cg.snap->ps.persistant[PERS_TEAM] == TEAM_RED ) { + strcpy( teamstr, "axis_desc" ); + } else { + strcpy( teamstr, "allied_desc" ); + } + + s = CG_ConfigString( CS_MULTI_INFO ); + buf = Info_ValueForKey( s, "numobjectives" ); + + if ( buf && atoi( buf ) ) { + num = atoi( buf ); + + for ( i = 0; i < num; i++ ) { + s = CG_ConfigString( CS_MULTI_OBJECTIVE1 + i ); + buf = Info_ValueForKey( s, teamstr ); + + // draw text + str = va( "%s", buf ); + strwidth = CG_DrawStrlen( str ) * SMALLCHAR_WIDTH; + CG_DrawSmallString( x + width / 2 - strwidth / 2 - 12, y, str, fade ); + + // draw status flags + status = atoi( Info_ValueForKey( s, "status" ) ); + + if ( status == 0 ) { + CG_DrawPic( x + width / 2 - strwidth / 2 - 16 - 24, y, 24, 16, trap_R_RegisterShaderNoMip( "ui/assets/ger_flag.tga" ) ); + CG_DrawPic( x + width / 2 + strwidth / 2 - 12 + 4, y, 24, 16, trap_R_RegisterShaderNoMip( "ui/assets/ger_flag.tga" ) ); + } else if ( status == 1 ) { + CG_DrawPic( x + width / 2 - strwidth / 2 - 16 - 24, y, 24, 16, trap_R_RegisterShaderNoMip( "ui/assets/usa_flag.tga" ) ); + CG_DrawPic( x + width / 2 + strwidth / 2 - 12 + 4, y, 24, 16, trap_R_RegisterShaderNoMip( "ui/assets/usa_flag.tga" ) ); + } + + y += 16; + } + } + + return y; +} + +/* +================= +WM_ScoreboardOverlay +================= +*/ +int WM_ScoreboardOverlay( int x, int y, float fade ) { + vec4_t hcolor; + int width; + char *s; // JPW NERVE + int msec, mins, seconds, tens; // JPW NERVE + + width = INFO_PLAYER_WIDTH + INFO_LATENCY_WIDTH + INFO_SCORE_WIDTH + 25; + + VectorSet( hcolor, 0, 0, 0 ); + hcolor[3] = 0.7 * fade; + + // draw background + CG_FillRect( x - 12, y, width, 400, hcolor ); + + // draw title frame + VectorSet( hcolor, 0.0039, 0.0039, 0.2461 ); + hcolor[3] = 1 * fade; + CG_FillRect( x - 12, y, width, 30, hcolor ); + CG_DrawRect( x - 12, y, width, 400, 2, hcolor ); + + if ( cg.snap->ps.pm_type == PM_INTERMISSION ) { + const char *s, *buf; + + s = CG_ConfigString( CS_MULTI_INFO ); + buf = Info_ValueForKey( s, "winner" ); + + if ( atoi( buf ) ) { + CG_DrawSmallString( x - 12 + 5, y, "ALLIES WIN!", fade ); + } else { + CG_DrawSmallString( x - 12 + 5, y, "AXIS WIN!", fade ); + } + } +// JPW NERVE -- mission time & reinforce time + else { + msec = ( cgs.timelimit * 60.f * 1000.f ) - ( cg.time - cgs.levelStartTime ); + + seconds = msec / 1000; + mins = seconds / 60; + seconds -= mins * 60; + tens = seconds / 10; + seconds -= tens * 10; + + s = va( "Mission time: %2.0f:%i%i", (float)mins, tens, seconds ); // float cast to line up with reinforce time + CG_DrawSmallString( x - 7,y,s,fade ); + + if ( cgs.clientinfo[cg.snap->ps.clientNum].team == TEAM_RED ) { + msec = cg_redlimbotime.integer - ( cg.time % cg_redlimbotime.integer ); + } else if ( cgs.clientinfo[cg.snap->ps.clientNum].team == TEAM_BLUE ) { + msec = cg_bluelimbotime.integer - ( cg.time % cg_bluelimbotime.integer ); + } else { // no team (spectator mode) + msec = 0; + } + + if ( msec ) { + seconds = msec / 1000; + mins = seconds / 60; + seconds -= mins * 60; + tens = seconds / 10; + seconds -= tens * 10; + + s = va( "Reinforce time: %2.0f:%i%i", (float)mins, tens, seconds ); + CG_DrawSmallString( x - 7,y + 16,s,fade ); + } + } +// jpw +// CG_DrawSmallString( x - 12 + 5, y, "Wolfenstein Multiplayer", fade ); // old one + + y = WM_DrawObjectives( x, y, width, fade ); + y += 5; + + // draw field names + CG_DrawSmallString( x, y, "Players", fade ); + x += INFO_PLAYER_WIDTH; + + CG_DrawSmallString( x, y, "Score", fade ); + x += INFO_SCORE_WIDTH; + + CG_DrawSmallString( x, y, "Latency", fade ); + x += INFO_LATENCY_WIDTH; + + y += 20; + + return y; +} +// -NERVE - SMF + +/* +================= +CG_DrawScoreboard + +Draw the normal in-game scoreboard +================= +*/ +qboolean CG_DrawScoreboard( void ) { + int x = 0, y = 0, w; // TTimo init + float fade; + float *fadeColor; + char *s; + + // don't draw amuthing if the menu or console is up + if ( cg_paused.integer ) { + cg.deferredPlayerLoading = 0; + return qfalse; + } + + // still need to see 'mission failed' message in SP + if ( cgs.gametype == GT_SINGLE_PLAYER && cg.predictedPlayerState.pm_type == PM_DEAD ) { + return qfalse; + } + + if ( cgs.gametype == GT_SINGLE_PLAYER && cg.predictedPlayerState.pm_type == PM_INTERMISSION ) { + cg.deferredPlayerLoading = 0; + return qfalse; + } + + // don't draw scoreboard during death while warmup up + if ( cg.warmup && !cg.showScores ) { + return qfalse; + } + + if ( cg.showScores || cg.predictedPlayerState.pm_type == PM_DEAD || + cg.predictedPlayerState.pm_type == PM_INTERMISSION ) { + fade = 1.0; + fadeColor = colorWhite; + } else { + fadeColor = CG_FadeColor( cg.scoreFadeTime, FADE_TIME ); + + if ( !fadeColor ) { + // next time scoreboard comes up, don't print killer + cg.deferredPlayerLoading = 0; + cg.killerName[0] = 0; + return qfalse; + } + fade = *fadeColor; + } + + + // fragged by ... line + if ( cg.killerName[0] ) { + s = va( "Killed by %s", cg.killerName ); + w = CG_DrawStrlen( s ) * BIGCHAR_WIDTH; + x = ( SCREEN_WIDTH - w ) / 2; + y = 40; + CG_DrawBigString( x, y, s, fade ); + } + + // current rank + + //----(SA) enclosed this so it doesn't draw for SP + if ( cgs.gametype != GT_SINGLE_PLAYER && cgs.gametype != GT_WOLF ) { // NERVE - SMF - added wolf multiplayer check + if ( cg.snap->ps.persistant[PERS_TEAM] != TEAM_SPECTATOR ) { + if ( cgs.gametype < GT_TEAM ) { + s = va( "%s place with %i", + CG_PlaceString( cg.snap->ps.persistant[PERS_RANK] + 1 ), + cg.snap->ps.persistant[PERS_SCORE] ); + w = CG_DrawStrlen( s ) * BIGCHAR_WIDTH; + x = ( SCREEN_WIDTH - w ) / 2; + y = 60; + CG_DrawBigString( x, y, s, fade ); + } else { + if ( cg.teamScores[0] == cg.teamScores[1] ) { + s = va( "Teams are tied at %i", cg.teamScores[0] ); + } else if ( cg.teamScores[0] >= cg.teamScores[1] ) { + s = va( "Red leads %i to %i",cg.teamScores[0], cg.teamScores[1] ); + } else { + s = va( "Blue leads %i to %i",cg.teamScores[1], cg.teamScores[0] ); + } + + w = CG_DrawStrlen( s ) * BIGCHAR_WIDTH; + x = ( SCREEN_WIDTH - w ) / 2; + y = 60; + CG_DrawBigString( x, y, s, fade ); + } + } + + // scoreboard + x = 320 - SCOREBOARD_WIDTH / 2; + y = 86; + + #if 0 + CG_DrawBigStringColor( x, y, "SCORE PING TIME NAME", fadeColor ); + CG_DrawBigStringColor( x, y + 12, "----- ---- ---- ---------------", fadeColor ); + #endif + CG_DrawPic( x + 1 * 16, y, 64, 32, cgs.media.scoreboardScore ); + CG_DrawPic( x + 6 * 16 + 8, y, 64, 32, cgs.media.scoreboardPing ); + CG_DrawPic( x + 11 * 16 + 8, y, 64, 32, cgs.media.scoreboardTime ); + CG_DrawPic( x + 16 * 16, y, 64, 32, cgs.media.scoreboardName ); + + y += 32; + } + + // NERVE - SMF + if ( cgs.gametype == GT_WOLF ) { + // + // teamplay scoreboard + // + x = 320 - SCOREBOARD_WIDTH / 2 + 20 + 20; + y = 40; + + y = WM_ScoreboardOverlay( x, y, fade ); + + if ( cg.teamScores[0] >= cg.teamScores[1] ) { + y = WM_TeamScoreboard( x, y, TEAM_RED, fade ); + y = WM_TeamScoreboard( x, y, TEAM_BLUE, fade ); + } else { + y = WM_TeamScoreboard( x, y, TEAM_BLUE, fade ); + y = WM_TeamScoreboard( x, y, TEAM_RED, fade ); + } + y = WM_TeamScoreboard( x, y, TEAM_SPECTATOR, fade ); + } + // -NERVE - SMF + else if ( cgs.gametype >= GT_TEAM ) { + // + // teamplay scoreboard + // + if ( cg.teamScores[0] >= cg.teamScores[1] ) { + y = CG_TeamScoreboard( x, y, TEAM_RED, fade ); + y = CG_TeamScoreboard( x, y, TEAM_BLUE, fade ); + } else { + y = CG_TeamScoreboard( x, y, TEAM_BLUE, fade ); + y = CG_TeamScoreboard( x, y, TEAM_RED, fade ); + } + y = CG_TeamScoreboard( x, y, TEAM_SPECTATOR, fade ); + + } else if ( cgs.gametype != GT_SINGLE_PLAYER ) { //----(SA) modified + // + // free for all scoreboard + // + y = CG_TeamScoreboard( x, y, TEAM_FREE, fade ); + y = CG_TeamScoreboard( x, y, TEAM_SPECTATOR, fade ); + } + + // load any models that have been deferred + if ( ++cg.deferredPlayerLoading > 1 ) { + CG_LoadDeferredPlayers(); + } + + return qtrue; +} + +//================================================================================ + +/* +================ +CG_CenterGiantLine +================ +*/ +static void CG_CenterGiantLine( float y, const char *string ) { + float x; + vec4_t color; + + color[0] = 1; + color[1] = 1; + color[2] = 1; + color[3] = 1; + + x = 0.5 * ( 640 - GIANT_WIDTH * CG_DrawStrlen( string ) ); + + CG_DrawStringExt( x, y, string, color, qtrue, qtrue, GIANT_WIDTH, GIANT_HEIGHT, 0 ); +} + +/* +================= +CG_DrawTourneyScoreboard + +Draw the oversize scoreboard for tournements +================= +*/ +void CG_DrawTourneyScoreboard( void ) { + const char *s; + vec4_t color; + int min, tens, ones; + clientInfo_t *ci; + int y; + int i; + + // request more scores regularly + if ( cg.scoresRequestTime + 2000 < cg.time ) { + cg.scoresRequestTime = cg.time; + trap_SendClientCommand( "score" ); + } + + color[0] = 1; + color[1] = 1; + color[2] = 1; + color[3] = 1; + + // draw the dialog background + color[0] = color[1] = color[2] = 0; + color[3] = 1; + CG_FillRect( 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, color ); + + // print the mesage of the day + s = CG_ConfigString( CS_MOTD ); + if ( !s[0] ) { + s = "Scoreboard"; + } + + // print optional title + CG_CenterGiantLine( 8, s ); + + // print server time + ones = cg.time / 1000; + min = ones / 60; + ones %= 60; + tens = ones / 10; + ones %= 10; + s = va( "%i:%i%i", min, tens, ones ); + + CG_CenterGiantLine( 64, s ); + + + // print the two scores + + y = 160; + if ( cgs.gametype >= GT_TEAM ) { + // + // teamplay scoreboard + // + CG_DrawStringExt( 8, y, "Red Team", color, qtrue, qtrue, GIANT_WIDTH, GIANT_HEIGHT, 0 ); + s = va( "%i", cg.teamScores[0] ); + CG_DrawStringExt( 632 - GIANT_WIDTH * strlen( s ), y, s, color, qtrue, qtrue, GIANT_WIDTH, GIANT_HEIGHT, 0 ); + + y += 64; + + CG_DrawStringExt( 8, y, "Blue Team", color, qtrue, qtrue, GIANT_WIDTH, GIANT_HEIGHT, 0 ); + s = va( "%i", cg.teamScores[1] ); + CG_DrawStringExt( 632 - GIANT_WIDTH * strlen( s ), y, s, color, qtrue, qtrue, GIANT_WIDTH, GIANT_HEIGHT, 0 ); + } else { + // + // free for all scoreboard + // + for ( i = 0 ; i < MAX_CLIENTS ; i++ ) { + ci = &cgs.clientinfo[i]; + if ( !ci->infoValid ) { + continue; + } + if ( ci->team != TEAM_FREE ) { + continue; + } + + CG_DrawStringExt( 8, y, ci->name, color, qtrue, qtrue, GIANT_WIDTH, GIANT_HEIGHT, 0 ); + s = va( "%i", ci->score ); + CG_DrawStringExt( 632 - GIANT_WIDTH * strlen( s ), y, s, color, qtrue, qtrue, GIANT_WIDTH, GIANT_HEIGHT, 0 ); + y += 64; + } + } + + +} + diff --git a/Projects/Android/jni/rtcw/src/cgame/cg_servercmds.c b/Projects/Android/jni/rtcw/src/cgame/cg_servercmds.c new file mode 100644 index 0000000..a03aa96 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/cgame/cg_servercmds.c @@ -0,0 +1,1043 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + + +// cg_servercmds.c -- reliably sequenced text commands sent by the server +// these are processed at snapshot transition time, so there will definately +// be a valid snapshot this frame + +#include "cg_local.h" +#include "../ui/ui_shared.h" // bk001205 - for Q3_ui as well + + +/* +================= +CG_ParseScores + +================= +*/ +static void CG_ParseScores( void ) { + int i, powerups; + + cg.numScores = atoi( CG_Argv( 1 ) ); + if ( cg.numScores > MAX_CLIENTS ) { + cg.numScores = MAX_CLIENTS; + } + + cg.teamScores[0] = atoi( CG_Argv( 2 ) ); + cg.teamScores[1] = atoi( CG_Argv( 3 ) ); + + memset( cg.scores, 0, sizeof( cg.scores ) ); + for ( i = 0 ; i < cg.numScores ; i++ ) { + // + cg.scores[i].client = atoi( CG_Argv( i * 6 + 4 ) ); + cg.scores[i].score = atoi( CG_Argv( i * 6 + 5 ) ); + cg.scores[i].ping = atoi( CG_Argv( i * 6 + 6 ) ); + cg.scores[i].time = atoi( CG_Argv( i * 6 + 7 ) ); + cg.scores[i].scoreFlags = atoi( CG_Argv( i * 6 + 8 ) ); + powerups = atoi( CG_Argv( i * 6 + 9 ) ); + // DHM - Nerve :: the following parameters are not sent by server + /* + cg.scores[i].accuracy = atoi(CG_Argv(i * 14 + 10)); + cg.scores[i].impressiveCount = atoi(CG_Argv(i * 14 + 11)); + cg.scores[i].excellentCount = atoi(CG_Argv(i * 14 + 12)); + cg.scores[i].guantletCount = atoi(CG_Argv(i * 14 + 13)); + cg.scores[i].defendCount = atoi(CG_Argv(i * 14 + 14)); + cg.scores[i].assistCount = atoi(CG_Argv(i * 14 + 15)); + cg.scores[i].perfect = atoi(CG_Argv(i * 14 + 16)); + cg.scores[i].captures = atoi(CG_Argv(i * 14 + 17)); + */ + + if ( cg.scores[i].client < 0 || cg.scores[i].client >= MAX_CLIENTS ) { + cg.scores[i].client = 0; + } + cgs.clientinfo[ cg.scores[i].client ].score = cg.scores[i].score; + cgs.clientinfo[ cg.scores[i].client ].powerups = powerups; + + cg.scores[i].team = cgs.clientinfo[cg.scores[i].client].team; + } +#ifdef MISSIONPACK + CG_SetScoreSelection( NULL ); +#endif + +} + +/* +================= +CG_ParseTeamInfo + +================= +*/ +static void CG_ParseTeamInfo( void ) { + int i; + int client; + + numSortedTeamPlayers = atoi( CG_Argv( 1 ) ); + + for ( i = 0 ; i < numSortedTeamPlayers ; i++ ) { + client = atoi( CG_Argv( i * 6 + 2 ) ); + + sortedTeamPlayers[i] = client; + + cgs.clientinfo[ client ].location = atoi( CG_Argv( i * 6 + 3 ) ); + cgs.clientinfo[ client ].health = atoi( CG_Argv( i * 6 + 4 ) ); + cgs.clientinfo[ client ].armor = atoi( CG_Argv( i * 6 + 5 ) ); + cgs.clientinfo[ client ].curWeapon = atoi( CG_Argv( i * 6 + 6 ) ); + cgs.clientinfo[ client ].powerups = atoi( CG_Argv( i * 6 + 7 ) ); + } +} + + +/* +================ +CG_ParseServerinfo + +This is called explicitly when the gamestate is first received, +and whenever the server updates any serverinfo flagged cvars +================ +*/ +void CG_ParseServerinfo( void ) { + const char *info; + char *mapname; + + info = CG_ConfigString( CS_SERVERINFO ); + cgs.gametype = atoi( Info_ValueForKey( info, "g_gametype" ) ); + trap_Cvar_Set( "g_gametype", va( "%i", cgs.gametype ) ); + cgs.dmflags = atoi( Info_ValueForKey( info, "dmflags" ) ); + cgs.teamflags = atoi( Info_ValueForKey( info, "teamflags" ) ); + cgs.fraglimit = atoi( Info_ValueForKey( info, "fraglimit" ) ); + cgs.capturelimit = atoi( Info_ValueForKey( info, "capturelimit" ) ); + cgs.timelimit = atoi( Info_ValueForKey( info, "timelimit" ) ); + cgs.maxclients = atoi( Info_ValueForKey( info, "sv_maxclients" ) ); + mapname = Info_ValueForKey( info, "mapname" ); + Com_sprintf( cgs.mapname, sizeof( cgs.mapname ), "maps/%s.bsp", mapname ); + +// JPW NERVE +// prolly should parse all CS_SERVERINFO keys automagically, but I don't want to break anything that might be improperly set for wolf SP, so I'm just parsing MP relevant stuff here + trap_Cvar_Set( "g_medicChargeTime",Info_ValueForKey( info,"g_medicChargeTime" ) ); + trap_Cvar_Set( "g_engineerChargeTime",Info_ValueForKey( info,"g_engineerChargeTime" ) ); + trap_Cvar_Set( "g_soldierChargeTime",Info_ValueForKey( info,"g_soldierChargeTime" ) ); + trap_Cvar_Set( "g_LTChargeTime",Info_ValueForKey( info,"g_LTChargeTime" ) ); + trap_Cvar_Set( "g_redlimbotime",Info_ValueForKey( info,"g_redlimbotime" ) ); + trap_Cvar_Set( "g_bluelimbotime",Info_ValueForKey( info,"g_bluelimbotime" ) ); +// jpw + + // Q_strncpyz( cgs.redTeam, Info_ValueForKey( info, "g_redTeam" ), sizeof(cgs.redTeam) ); +// trap_Cvar_Set("g_redTeam", cgs.redTeam); +// Q_strncpyz( cgs.blueTeam, Info_ValueForKey( info, "g_blueTeam" ), sizeof(cgs.blueTeam) ); +// trap_Cvar_Set("g_blueTeam", cgs.blueTeam); +} + + +//----(SA) added +/* +============== +CG_ParseMissionStats + time h/m/s + objectives n/n + secrets n/n + treasure n/n + artifacts n/n + attempts num +============== +*/ +static void CG_ParseMissionStats( void ) { + const char *info; + char *token; + + info = CG_ConfigString( CS_MISSIONSTATS ); + +// time + token = COM_Parse( (char **)&info ); + cg.playTimeH = atoi( token ); + token = COM_Parse( (char **)&info ); + cg.playTimeM = atoi( token ); + token = COM_Parse( (char **)&info ); + cg.playTimeS = atoi( token ); + +// objectives + token = COM_Parse( (char **)&info ); + cg.numObjectivesFound = atoi( token ); + token = COM_Parse( (char **)&info ); + cg.numObjectives = atoi( token ); + +// secrets + token = COM_Parse( (char **)&info ); + cg.numSecretsFound = atoi( token ); + token = COM_Parse( (char **)&info ); + cg.numSecrets = atoi( token ); + +// treasure + token = COM_Parse( (char **)&info ); + cg.numTreasureFound = atoi( token ); + token = COM_Parse( (char **)&info ); + cg.numTreasure = atoi( token ); + +// artifacts + token = COM_Parse( (char **)&info ); + cg.numArtifactsFound = atoi( token ); + token = COM_Parse( (char **)&info ); + cg.numArtifacts = atoi( token ); + +// attempts + token = COM_Parse( (char **)&info ); + cg.attempts = atoi( token ); + +} +//----(SA) end + + +/* +================== +CG_ParseWarmup +================== +*/ +static void CG_ParseWarmup( void ) { + const char *info; + int warmup; + + info = CG_ConfigString( CS_WARMUP ); + + warmup = atoi( info ); + cg.warmupCount = -1; + + if ( warmup == 0 && cg.warmup ) { + + } else if ( warmup > 0 && cg.warmup <= 0 ) { + trap_S_StartLocalSound( cgs.media.countPrepareSound, CHAN_ANNOUNCER ); + } + + cg.warmup = warmup; +} + +/* +===================== +CG_ParseScreenFade +===================== +*/ +static void CG_ParseScreenFade( void ) { + const char *info; + char *token; + float fadealpha; + int fadestart, fadeduration; + + info = CG_ConfigString( CS_SCREENFADE ); + token = COM_Parse( (char **)&info ); + fadealpha = atof( token ); + token = COM_Parse( (char **)&info ); + fadestart = atoi( token ); + token = COM_Parse( (char **)&info ); + fadeduration = atoi( token ); + + CG_Fade( 0, 0, 0, (int)( fadealpha * 255.0f ), fadestart, fadeduration ); +} + + +/* +============== +CG_ParseFog + float near dist + float far dist + float density + float[3] r,g,b + int time +============== +*/ +static void CG_ParseFog( void ) { + const char *info; + char *token; + float ne, fa, r, g, b, density; + int time; + + info = CG_ConfigString( CS_FOGVARS ); + token = COM_Parse( (char **)&info ); ne = atof( token ); + token = COM_Parse( (char **)&info ); + + if ( !token || !token[0] ) { + // set to 'no fog' + // 'FOG_MAP' is not registered, so it will always make fog go away + trap_R_SetFog( FOG_CMD_SWITCHFOG, FOG_MAP, (int)ne, 0, 0, 0, 0 ); + return; + } + + fa = atof( token ); + + token = COM_Parse( (char **)&info ); density = atof( token ); + token = COM_Parse( (char **)&info ); r = atof( token ); + token = COM_Parse( (char **)&info ); g = atof( token ); + token = COM_Parse( (char **)&info ); b = atof( token ); + token = COM_Parse( (char **)&info ); time = atoi( token ); + + trap_R_SetFog( FOG_SERVER, (int)ne, (int)fa, r, g, b, density ); + trap_R_SetFog( FOG_CMD_SWITCHFOG, FOG_SERVER, time, 0, 0, 0, 0 ); +} + +/* +================ +CG_SetConfigValues + +Called on load to set the initial values from configure strings +================ +*/ +void CG_SetConfigValues( void ) { +#ifdef MISSIONPACK + const char *s; +#endif + + cgs.scores1 = atoi( CG_ConfigString( CS_SCORES1 ) ); + cgs.scores2 = atoi( CG_ConfigString( CS_SCORES2 ) ); + cgs.levelStartTime = atoi( CG_ConfigString( CS_LEVEL_START_TIME ) ); +#ifdef MISSIONPACK + if ( cgs.gametype == GT_CTF ) { + s = CG_ConfigString( CS_FLAGSTATUS ); + cgs.redflag = s[0] - '0'; + cgs.blueflag = s[1] - '0'; + } else if ( cgs.gametype == GT_1FCTF ) { + s = CG_ConfigString( CS_FLAGSTATUS ); + cgs.flagStatus = s[0] - '0'; + } +#endif + cg.warmup = atoi( CG_ConfigString( CS_WARMUP ) ); +} + +/* +===================== +CG_ShaderStateChanged +===================== +*/ +void CG_ShaderStateChanged( void ) { + char originalShader[MAX_QPATH]; + char newShader[MAX_QPATH]; + char timeOffset[16]; + const char *o; + char *n,*t; + + o = CG_ConfigString( CS_SHADERSTATE ); + while ( o && *o ) { + n = strstr( o, "=" ); + if ( n && *n ) { + strncpy( originalShader, o, n - o ); + originalShader[n - o] = 0; + n++; + t = strstr( n, ":" ); + if ( t && *t ) { + strncpy( newShader, n, t - n ); + newShader[t - n] = 0; + } else { + break; + } + t++; + o = strstr( t, "@" ); + if ( o ) { + strncpy( timeOffset, t, o - t ); + timeOffset[o - t] = 0; + o++; + trap_R_RemapShader( originalShader, newShader, timeOffset ); + } + } else { + break; + } + } +} + +/* +================ +CG_ConfigStringModified + +================ +*/ +static void CG_ConfigStringModified( void ) { + const char *str; + int num; + + num = atoi( CG_Argv( 1 ) ); + + // get the gamestate from the client system, which will have the + // new configstring already integrated + trap_GetGameState( &cgs.gameState ); + + // look up the individual string that was modified + str = CG_ConfigString( num ); + + // do something with it if necessary + if ( num == CS_MUSIC ) { + CG_StartMusic(); + } else if ( num == CS_MUSIC_QUEUE ) { //----(SA) added + CG_QueueMusic(); + } else if ( num == CS_MISSIONSTATS ) { //----(SA) added + CG_ParseMissionStats(); + } else if ( num == CS_SERVERINFO ) { + CG_ParseServerinfo(); + } else if ( num == CS_WARMUP ) { + CG_ParseWarmup(); + } else if ( num == CS_SCORES1 ) { + cgs.scores1 = atoi( str ); + } else if ( num == CS_SCORES2 ) { + cgs.scores2 = atoi( str ); + } else if ( num == CS_LEVEL_START_TIME ) { + cgs.levelStartTime = atoi( str ); + } else if ( num == CS_VOTE_TIME ) { + cgs.voteTime = atoi( str ); + cgs.voteModified = qtrue; + } else if ( num == CS_VOTE_YES ) { + cgs.voteYes = atoi( str ); + cgs.voteModified = qtrue; + } else if ( num == CS_VOTE_NO ) { + cgs.voteNo = atoi( str ); + cgs.voteModified = qtrue; + } else if ( num == CS_VOTE_STRING ) { + Q_strncpyz( cgs.voteString, str, sizeof( cgs.voteString ) ); +#if 0 + trap_S_StartLocalSound( cgs.media.voteNow, CHAN_ANNOUNCER ); + } else if ( num >= CS_TEAMVOTE_TIME && num <= CS_TEAMVOTE_TIME + 1 ) { + cgs.teamVoteTime[num - CS_TEAMVOTE_TIME] = atoi( str ); + cgs.teamVoteModified[num - CS_TEAMVOTE_TIME] = qtrue; + } else if ( num >= CS_TEAMVOTE_YES && num <= CS_TEAMVOTE_YES + 1 ) { + cgs.teamVoteYes[num - CS_TEAMVOTE_YES] = atoi( str ); + cgs.teamVoteModified[num - CS_TEAMVOTE_YES] = qtrue; + } else if ( num >= CS_TEAMVOTE_NO && num <= CS_TEAMVOTE_NO + 1 ) { + cgs.teamVoteNo[num - CS_TEAMVOTE_NO] = atoi( str ); + cgs.teamVoteModified[num - CS_TEAMVOTE_NO] = qtrue; + } else if ( num >= CS_TEAMVOTE_STRING && num <= CS_TEAMVOTE_STRING + 1 ) { + Q_strncpyz( cgs.teamVoteString[num - CS_TEAMVOTE_STRING], str, sizeof( cgs.teamVoteString ) ); + trap_S_StartLocalSound( cgs.media.voteNow, CHAN_ANNOUNCER ); +#endif + } else if ( num == CS_INTERMISSION ) { + cg.intermissionStarted = atoi( str ); + } else if ( num == CS_SCREENFADE ) { + CG_ParseScreenFade(); + } else if ( num == CS_FOGVARS ) { + CG_ParseFog(); + } else if ( num >= CS_MODELS && num < CS_MODELS + MAX_MODELS ) { + cgs.gameModels[ num - CS_MODELS ] = trap_R_RegisterModel( str ); + } else if ( num >= CS_SOUNDS && num < CS_SOUNDS + MAX_MODELS ) { + if ( str[0] != '*' ) { // player specific sounds don't register here + + // Ridah, register sound scripts seperately + if ( !strstr( str, ".wav" ) ) { + CG_SoundScriptPrecache( str ); + } else { + cgs.gameSounds[ num - CS_SOUNDS] = trap_S_RegisterSound( str ); + } + + } + } else if ( num >= CS_PLAYERS && num < CS_PLAYERS + MAX_CLIENTS ) { + CG_NewClientInfo( num - CS_PLAYERS ); + } + // Rafael particle configstring + else if ( num >= CS_PARTICLES && num < CS_PARTICLES + MAX_PARTICLES_AREAS ) { + CG_NewParticleArea( num ); + } +//----(SA) have not reached this code yet so I don't know if I really need this here + else if ( num >= CS_DLIGHTS && num < CS_DLIGHTS + MAX_DLIGHTS ) { + CG_Printf( ">>>>>>>>>>>got configstring for dlight: %d\ntell Sherman!!!!!!!!!!", num - CS_DLIGHTS ); +//----(SA) + } else if ( num == CS_SHADERSTATE ) { + CG_ShaderStateChanged(); + } + +} + + +/* +======================= +CG_AddToTeamChat + +======================= +*/ +static void CG_AddToTeamChat( const char *str ) { + int len; + char *p, *ls; + int lastcolor; + int chatHeight; + + if ( cg_teamChatHeight.integer < TEAMCHAT_HEIGHT ) { + chatHeight = cg_teamChatHeight.integer; + } else { + chatHeight = TEAMCHAT_HEIGHT; + } + + if ( chatHeight <= 0 || cg_teamChatTime.integer <= 0 ) { + // team chat disabled, dump into normal chat + cgs.teamChatPos = cgs.teamLastChatPos = 0; + return; + } + + len = 0; + + p = cgs.teamChatMsgs[cgs.teamChatPos % chatHeight]; + *p = 0; + + lastcolor = '7'; + + ls = NULL; + while ( *str ) { + if ( len > TEAMCHAT_WIDTH - 1 ) { + if ( ls ) { + str -= ( p - ls ); + str++; + p -= ( p - ls ); + } + *p = 0; + + cgs.teamChatMsgTimes[cgs.teamChatPos % chatHeight] = cg.time; + + cgs.teamChatPos++; + p = cgs.teamChatMsgs[cgs.teamChatPos % chatHeight]; + *p = 0; + *p++ = Q_COLOR_ESCAPE; + *p++ = lastcolor; + len = 0; + ls = NULL; + } + + if ( Q_IsColorString( str ) ) { + *p++ = *str++; + lastcolor = *str; + *p++ = *str++; + continue; + } + if ( *str == ' ' ) { + ls = p; + } + *p++ = *str++; + len++; + } + *p = 0; + + cgs.teamChatMsgTimes[cgs.teamChatPos % chatHeight] = cg.time; + cgs.teamChatPos++; + + if ( cgs.teamChatPos - cgs.teamLastChatPos > chatHeight ) { + cgs.teamLastChatPos = cgs.teamChatPos - chatHeight; + } +} + +/* +=============== +CG_SendMoveSpeed +=============== +*/ +void CG_SendMoveSpeed( animation_t *animList, int numAnims, char *modelName ) { + animation_t *anim; + int i; + char text[10000]; + + if ( !cgs.localServer ) { + return; + } + + text[0] = 0; + Q_strcat( text, sizeof( text ), modelName ); + + for ( i = 0, anim = animList; i < numAnims; i++, anim++ ) { + if ( anim->moveSpeed <= 0 ) { + continue; + } + + // add this to the list + Q_strcat( text, sizeof( text ), va( " %s %i %.1f", anim->name, anim->moveSpeed, anim->stepGap ) ); + } + + // send the movespeeds to the server + trap_SendMoveSpeedsToGame( 0, text ); +} + +/* +=============== +CG_SendMoveSpeeds + + send moveSpeeds for all unique models +=============== +*/ +#if 0 +void CG_SendMoveSpeeds( void ) { + int i,j; + animModelInfo_t *modelInfo; + clientInfo_t *ci; + + for ( i = 0; i < MAX_ANIMSCRIPT_MODELS; i++ ) { + + modelInfo = cgs.animScriptData.modelInfo[i]; + + if ( modelInfo == NULL ) { + continue; + } + + if ( !modelInfo->modelname[0] ) { + continue; + } +/* + // recalc them + // find a client that uses this model + for (ci = cgs.clientinfo, j=0; jmodelInfo && ci->modelInfo == modelInfo) { + CG_CalcMoveSpeeds( ci ); + break; + } + } +*/ +// if (j==MAX_CLIENTS) +// CG_Error( "CG_SendMoveSpeeds: cannot find client with modelName \"%s\" for moveSpeed calc", modelInfo->modelname ); + + // send this model + //CG_SendMoveSpeed( modelInfo->animations, modelInfo->numAnimations, modelInfo->modelname ); + } + +} +#endif + +/* +=============== +CG_MapRestart + +The server has issued a map_restart, so the next snapshot +is completely new and should not be interpolated to. + +A tournement restart will clear everything, but doesn't +require a reload of all the media +=============== +*/ +static void CG_MapRestart( void ) { +// char buff[64]; + int i; + if ( cg_showmiss.integer ) { + CG_Printf( "CG_MapRestart\n" ); + } + + memset( &cg.lastWeapSelInBank[0], 0, MAX_WEAP_BANKS * sizeof( int ) ); // clear weapon bank selections + + cg.centerPrintTime = 0; // reset centerprint counter so previous messages don't re-appear + cg.itemPickupTime = 0; // reset item pickup counter so previous messages don't re-appear + cg.cursorHintFade = 0; // reset cursor hint timer + cg.yougotmailTime = 0; // reset + + // (SA) clear zoom (so no warpies) + cg.zoomedBinoc = qfalse; + cg.zoomedBinoc = cg.zoomedScope = qfalse; + cg.zoomTime = 0; + cg.zoomval = 0; + + // reset fog to world fog (if present) +// trap_R_SetFog(FOG_CMD_SWITCHFOG, FOG_MAP,20,0,0,0,0); +// trap_Cvar_VariableStringBuffer("r_mapFogColor", buff, sizeof(buff)); +// trap_SendClientCommand(va("fogswitch %s", buff) ); + + CG_InitLocalEntities(); + CG_InitMarkPolys(); + + //Rafael particles + CG_ClearParticles(); + // done. + + for ( i = 1; i < MAX_PARTICLES_AREAS; i++ ) + { + { + int rval; + + rval = CG_NewParticleArea( CS_PARTICLES + i ); + if ( !rval ) { + break; + } + } + } + + + // Ridah, trails + CG_ClearTrails(); + // done. + + // Ridah + CG_ClearFlameChunks(); + CG_SoundInit(); + // done. + + // RF, init ZombieFX + trap_RB_ZombieFXAddNewHit( -1, NULL, NULL ); + + // make sure the "3 frags left" warnings play again + cg.fraglimitWarnings = 0; + + cg.timelimitWarnings = 0; + + cg.intermissionStarted = qfalse; + + cgs.voteTime = 0; + + cg.lightstylesInited = qfalse; + + cg.mapRestart = qtrue; + + CG_StartMusic(); + + trap_S_ClearLoopingSounds( qtrue ); + + // we really should clear more parts of cg here and stop sounds + cg.v_dmg_time = 0; + cg.v_noFireTime = 0; + cg.v_fireTime = 0; + + // RF, clear out animScriptData so we recalc everything and get new pointers from server + memset( cgs.animScriptData.modelInfo, 0, sizeof( cgs.animScriptData.modelInfo ) ); + for ( i = 0; i < MAX_CLIENTS; i++ ) { + if ( cgs.clientinfo[i].infoValid ) { + CG_LoadClientInfo( &cgs.clientinfo[i] ); // re-register the valid clients + } + } + // always clear the weapon selection + cg.weaponSelect = WP_NONE; + // clear out the player weapon info + memset( &cg_entities[0].pe.weap, 0, sizeof( cg_entities[0].pe.weap ) ); + // check for server set weapons we might not know about + // (FIXME: this is a hack for the time being since a scripted "selectweapon" does + // not hit the first snap, the server weapon set in cg_playerstate.c line 219 doesn't + // do the trick) + if ( !cg.weaponSelect ) { + if ( cg_loadWeaponSelect.integer > 0 ) { + cg.weaponSelect = cg_loadWeaponSelect.integer; + cg.weaponSelectTime = cg.time; + trap_Cvar_Set( "cg_loadWeaponSelect", "0" ); // turn it off + } + } + // clear out rumble effects + memset( cg.cameraShake, 0, sizeof( cg.cameraShake ) ); + memset( cg.cameraShakeAngles, 0, sizeof( cg.cameraShakeAngles ) ); + cg.rumbleScale = 0; + + // play the "fight" sound if this is a restart without warmup +// if ( cg.warmup == 0 /* && cgs.gametype == GT_TOURNAMENT */) { +// trap_S_StartLocalSound( cgs.media.countFightSound, CHAN_ANNOUNCER ); +// CG_CenterPrint( "FIGHT!", 120, GIANTCHAR_WIDTH*2 ); +// } +#ifdef MISSIONPACK + if ( cg_singlePlayerActive.integer ) { + trap_Cvar_Set( "ui_matchStartTime", va( "%i", cg.time ) ); + if ( cg_recordSPDemo.integer && cg_recordSPDemoName.string && *cg_recordSPDemoName.string ) { + trap_SendConsoleCommand( va( "set g_synchronousclients 1 ; record %s \n", cg_recordSPDemoName.string ) ); + } + } +#endif + trap_Cvar_Set( "cg_thirdPerson", "0" ); +} + +/* +================= +CG_RequestMoveSpeed +================= +*/ +void CG_RequestMoveSpeed( const char *modelname ) { + animModelInfo_t *modelInfo; + + modelInfo = BG_ModelInfoForModelname( (char *)modelname ); + + if ( !modelInfo ) { + // ignore it + return; + } + + // send it + CG_SendMoveSpeed( modelInfo->animations, modelInfo->numAnimations, (char *)modelname ); +} + +/* +================= +CG_RemoveChatEscapeChar +================= +*/ +static void CG_RemoveChatEscapeChar( char *text ) { + int i, l; + + l = 0; + for ( i = 0; text[i]; i++ ) { + if ( text[i] == '\x19' ) { + continue; + } + text[l++] = text[i]; + } + text[l] = '\0'; +} + +/* +================= +CG_ServerCommand + +The string has been tokenized and can be retrieved with +Cmd_Argc() / Cmd_Argv() +================= +*/ +void CG_ObjectivePrint( const char *str, int charWidth, int team ); // NERVE - SMF + +static void CG_ServerCommand( void ) { + const char *cmd; + char text[MAX_SAY_TEXT]; + /*SEB*/ + char a1[128], a2[128]; + + cmd = CG_Argv( 0 ); + + if ( !cmd[0] ) { + // server claimed the command + return; + } + + if ( !strcmp( cmd, "startCam" ) ) { + Q_strncpyz( a1, CG_Argv( 1 ), 128 ); + Q_strncpyz( a2, CG_Argv( 2 ), 128 ); + CG_StartCamera( a1, atoi(a2) ); +// CG_StartCamera( CG_Argv( 1 ), atoi( CG_Argv( 2 ) ) ); + return; + } + + if ( !strcmp( cmd, "stopCam" ) ) { + CG_StopCamera(); + return; + } + + if ( !strcmp( cmd, "mvspd" ) ) { + CG_RequestMoveSpeed( CG_Argv( 1 ) ); + return; + } + + if ( !strcmp( cmd, "dp" ) ) { // dynamite print (what a hack :( + + CG_CenterPrint( va( "%s %d %s", CG_translateString( "dynamitetimer" ), atoi( CG_Argv( 1 ) ), CG_translateString( "seconds" ) ), + SCREEN_HEIGHT - ( SCREEN_HEIGHT * 0.25 ), SMALLCHAR_WIDTH ); + return; + } + + if ( !strcmp( cmd, "cp" ) ) { + CG_CenterPrint( CG_Argv( 1 ), SCREEN_HEIGHT - ( SCREEN_HEIGHT * 0.25 ), SMALLCHAR_WIDTH ); + return; + } + + if ( !strcmp( cmd, "cs" ) ) { + CG_ConfigStringModified(); + return; + } + + if ( !strcmp( cmd, "print" ) ) { + CG_Printf( "%s", CG_Argv( 1 ) ); +#ifdef MISSIONPACK + cmd = CG_Argv( 1 ); // yes, this is obviously a hack, but so is the way we hear about + // votes passing or failing + if ( !Q_stricmpn( cmd, "vote failed", 11 ) || !Q_stricmpn( cmd, "team vote failed", 16 ) ) { + trap_S_StartLocalSound( cgs.media.voteFailed, CHAN_ANNOUNCER ); + } else if ( !Q_stricmpn( cmd, "vote passed", 11 ) || !Q_stricmpn( cmd, "team vote passed", 16 ) ) { + trap_S_StartLocalSound( cgs.media.votePassed, CHAN_ANNOUNCER ); + } +#endif + return; + } + + if ( !strcmp( cmd, "chat" ) ) { + if ( !cg_teamChatsOnly.integer ) { + trap_S_StartLocalSound( cgs.media.talkSound, CHAN_LOCAL_SOUND ); + Q_strncpyz( text, CG_Argv( 1 ), MAX_SAY_TEXT ); + CG_RemoveChatEscapeChar( text ); + CG_Printf( "%s\n", text ); + } + return; + } + + if ( !strcmp( cmd, "tchat" ) ) { + trap_S_StartLocalSound( cgs.media.talkSound, CHAN_LOCAL_SOUND ); + Q_strncpyz( text, CG_Argv( 1 ), MAX_SAY_TEXT ); + CG_RemoveChatEscapeChar( text ); + CG_AddToTeamChat( text ); + CG_Printf( "%s\n", text ); + return; + } + + // NERVE - SMF - limbo chat + if ( !strcmp( cmd, "lchat" ) ) { + trap_S_StartLocalSound( cgs.media.talkSound, CHAN_LOCAL_SOUND ); + Q_strncpyz( text, CG_Argv( 1 ), MAX_SAY_TEXT ); + CG_RemoveChatEscapeChar( text ); +// CG_AddToLimboChat( text ); + trap_UI_LimboChat( text ); + CG_Printf( "%s\n", text ); + return; + } + // -NERVE - SMF + + if ( !strcmp( cmd, "vchat" ) ) { +// CG_VoiceChat( SAY_ALL ); + return; + } + + if ( !strcmp( cmd, "vtchat" ) ) { +// CG_VoiceChat( SAY_TEAM ); + return; + } + + if ( !strcmp( cmd, "vtell" ) ) { +// CG_VoiceChat( SAY_TELL ); + return; + } + + if ( !strcmp( cmd, "scores" ) ) { + CG_ParseScores(); + return; + } + + if ( !strcmp( cmd, "tinfo" ) ) { + CG_ParseTeamInfo(); + return; + } + + if ( !strcmp( cmd, "map_restart" ) ) { + CG_MapRestart(); + return; + } + + if ( Q_stricmp( cmd, "remapShader" ) == 0 ) { + if ( trap_Argc() == 4 ) { + trap_R_RemapShader( CG_Argv( 1 ), CG_Argv( 2 ), CG_Argv( 3 ) ); + } + } + + // loaddeferred can be both a servercmd and a consolecmd + if ( !strcmp( cmd, "loaddeferred" ) ) { // spelling fixed (SA) + CG_LoadDeferredPlayers(); + return; + } + + // clientLevelShot is sent before taking a special screenshot for + // the menu system during development + if ( !strcmp( cmd, "clientLevelShot" ) ) { + cg.levelShot = qtrue; + return; + } + + // NERVE - SMF + if ( !Q_stricmp( cmd, "oid" ) ) { + CG_ObjectivePrint( CG_Argv( 2 ), SMALLCHAR_WIDTH, atoi( CG_Argv( 1 ) ) ); + return; + } + // -NERVE - SMF + + + // + // music + // + + // loops \/ + if ( !strcmp( cmd, "mu_start" ) ) { // has optional parameter for fade-up time + int fadeTime = 0; // default to instant start + + Q_strncpyz( text, CG_Argv( 2 ), MAX_SAY_TEXT ); + if ( text && strlen( text ) ) { + fadeTime = atoi( text ); + } + + trap_S_StartBackgroundTrack( CG_Argv( 1 ), CG_Argv( 1 ), fadeTime ); + return; + } + // plays once then back to whatever the loop was \/ + if ( !strcmp( cmd, "mu_play" ) ) { // has optional parameter for fade-up time + int fadeTime = 0; // default to instant start + + Q_strncpyz( text, CG_Argv( 2 ), MAX_SAY_TEXT ); + if ( text && strlen( text ) ) { + fadeTime = atoi( text ); + } + + trap_S_StartBackgroundTrack( CG_Argv( 1 ), "onetimeonly", fadeTime ); + return; + } + + if ( !strcmp( cmd, "mu_stop" ) ) { // has optional parameter for fade-down time + int fadeTime = 0; // default to instant stop + + Q_strncpyz( text, CG_Argv( 1 ), MAX_SAY_TEXT ); + if ( text && strlen( text ) ) { + fadeTime = atoi( text ); + } + trap_S_FadeBackgroundTrack( 0.0f, fadeTime, 0 ); + trap_S_StartBackgroundTrack( "", "", -2 ); // '-2' for 'queue looping track' (QUEUED_PLAY_LOOPED) + return; + } + + if ( !strcmp( cmd, "mu_fade" ) ) { + trap_S_FadeBackgroundTrack( atof( CG_Argv( 1 ) ), atoi( CG_Argv( 2 ) ), 0 ); + return; + } + + if ( !strcmp( cmd, "snd_fade" ) ) { + trap_S_FadeAllSound( atof( CG_Argv( 1 ) ), atoi( CG_Argv( 2 ) ) ); + return; + } + + if ( !strcmp( cmd, "rockandroll" ) ) { // map loaded, game is ready to begin. + CG_Fade( 0, 0, 0, 255, cg.time, 0 ); // go black + trap_UI_Popup( "pregame" ); // start pregame menu + trap_Cvar_Set( "cg_norender", "1" ); // don't render the world until the player clicks in and the 'playerstart' func has been called (g_main in G_UpdateCvars() ~ilne 949) + + trap_S_FadeAllSound( 1.0f, 1000 ); // fade sound up + + return; + } + + + + // ensure a file gets into a build (mainly for scripted music calls) + if ( !strcmp( cmd, "addToBuild" ) ) { + fileHandle_t f; + + if ( !cg_buildScript.integer ) { + return; + } + + // just open the file so it gets copied to the build dir + //CG_FileTouchForBuild(CG_Argv(1)); + trap_FS_FOpenFile( CG_Argv( 1 ), &f, FS_READ ); + trap_FS_FCloseFile( f ); + return; + } + + + CG_Printf( "Unknown client game command: %s\n", cmd ); +} + + +/* +==================== +CG_ExecuteNewServerCommands + +Execute all of the server commands that were received along +with this this snapshot. +==================== +*/ +void CG_ExecuteNewServerCommands( int latestSequence ) { + while ( cgs.serverCommandSequence < latestSequence ) { + if ( trap_GetServerCommand( ++cgs.serverCommandSequence ) ) { + CG_ServerCommand(); + } + } +} diff --git a/Projects/Android/jni/rtcw/src/cgame/cg_snapshot.c b/Projects/Android/jni/rtcw/src/cgame/cg_snapshot.c new file mode 100644 index 0000000..8c164bd --- /dev/null +++ b/Projects/Android/jni/rtcw/src/cgame/cg_snapshot.c @@ -0,0 +1,526 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +// cg_snapshot.c -- things that happen on snapshot transition, +// not necessarily every single rendered frame + + + +#include "cg_local.h" + + + +/* +================== +CG_ResetEntity +================== +*/ +static void CG_ResetEntity( centity_t *cent ) { + // if an event is set, assume it is new enough to use + // if the event had timed out, it would have been cleared + // RF, not needed for wolf + // DHM - Nerve :: Wolf is now using this. + cent->previousEvent = 0; + + cent->trailTime = cg.snap->serverTime; + + // Ridah + cent->headJuncIndex = 0; + cent->headJuncIndex2 = 0; + // RF, disabled this, since we clear events out now in g_main.c, this is redundant, and actually + // causes "double-door-sound" syndrome if a door is triggered and heard, and then comes into view before + // it has timed out in g_main.c, therefore playing the sound again, since it thinks it hasn't processed this + // event yet. + //cent->previousEventSequence = 0; + // done. + + VectorCopy( cent->currentState.origin, cent->lerpOrigin ); + VectorCopy( cent->currentState.angles, cent->lerpAngles ); + if ( cent->currentState.eType == ET_PLAYER ) { + CG_ResetPlayerEntity( cent ); + } +} + + + +/* +=============== +CG_TransitionEntity + +cent->nextState is moved to cent->currentState and events are fired +=============== +*/ +static void CG_TransitionEntity( centity_t *cent ) { + + // Ridah, update the fireDir if it's on fire + if ( CG_EntOnFire( cent ) ) { + vec3_t newDir, newPos, oldPos; + float adjust; + // + BG_EvaluateTrajectory( ¢->nextState.pos, cg.snap->serverTime, newPos ); + BG_EvaluateTrajectory( ¢->currentState.pos, cg.snap->serverTime, oldPos ); + // update the fireRiseDir + VectorSubtract( oldPos, newPos, newDir ); + // fire should go upwards if travelling slow + newDir[2] += 2; + if ( VectorNormalize( newDir ) < 1 ) { + VectorClear( newDir ); + newDir[2] = 1; + } + // now move towards the newDir + adjust = 0.3; + VectorMA( cent->fireRiseDir, adjust, newDir, cent->fireRiseDir ); + if ( VectorNormalize( cent->fireRiseDir ) <= 0.1 ) { + VectorCopy( newDir, cent->fireRiseDir ); + } + } + + //----(SA) the ent lost or gained some part(s), do any necessary effects + //TODO: check for ai first + if ( cent->currentState.dmgFlags != cent->nextState.dmgFlags ) { + CG_AttachedPartChange( cent ); + } + + + cent->currentState = cent->nextState; + cent->currentValid = qtrue; + + // reset if the entity wasn't in the last frame or was teleported + if ( !cent->interpolate ) { + CG_ResetEntity( cent ); + } + + // clear the next state. if will be set by the next CG_SetNextSnap + cent->interpolate = qfalse; + + // check for events + CG_CheckEvents( cent ); +} + + +/* +================== +CG_SetInitialSnapshot + +This will only happen on the very first snapshot, or +on tourney restarts. All other times will use +CG_TransitionSnapshot instead. + +FIXME: Also called by map_restart? +================== +*/ +void CG_SetInitialSnapshot( snapshot_t *snap ) { + char buf[64]; + int i; + centity_t *cent; + entityState_t *state; + + cg.snap = snap; + + BG_PlayerStateToEntityState( &snap->ps, &cg_entities[ snap->ps.clientNum ].currentState, qfalse ); + + // sort out solid entities + CG_BuildSolidList(); + + CG_ExecuteNewServerCommands( snap->serverCommandSequence ); + + trap_SendClientCommand( "fogswitch 0" ); // clear it out so the set below will take + + trap_Cvar_VariableStringBuffer( "r_savegameFogColor", buf, sizeof( buf ) ); + trap_Cvar_Set( "r_savegameFogColor", "0" ); + if ( strlen( buf ) > 1 ) { + if ( !Q_stricmp( buf, "none" ) ) { + trap_SendClientCommand( "fogswitch 0" ); // 'off' + } else { + trap_SendClientCommand( va( "fogswitch %s", buf ) ); + } + } else { + trap_Cvar_VariableStringBuffer( "r_mapFogColor", buf, sizeof( buf ) ); + trap_SendClientCommand( va( "fogswitch %s", buf ) ); + } + + // set our local weapon selection pointer to + // what the server has indicated the current weapon is + CG_Respawn(); + + for ( i = 0 ; i < cg.snap->numEntities ; i++ ) { + state = &cg.snap->entities[ i ]; + cent = &cg_entities[ state->number ]; + + memcpy( ¢->currentState, state, sizeof( entityState_t ) ); + //cent->currentState = *state; + cent->interpolate = qfalse; + cent->currentValid = qtrue; + + CG_ResetEntity( cent ); + + // check for events + CG_CheckEvents( cent ); + } + + // DHM - Nerve :: Set cg.clientNum so that it may be used elsewhere + cg.clientNum = snap->ps.clientNum; + + // NERVE - SMF + { + static char prevmap[64] = { 0 }; + char curmap[64]; + + trap_Cvar_VariableStringBuffer( "mapname", curmap, 64 ); + + if ( cgs.gametype == GT_WOLF && Q_stricmp( curmap, prevmap ) ) { + strcpy( prevmap, curmap ); + trap_SendConsoleCommand( "openLimboMenu\n" ); + } + } + // -NERVE - SMF +} + + +/* +=================== +CG_TransitionSnapshot + +The transition point from snap to nextSnap has passed +=================== +*/ +static void CG_TransitionSnapshot( void ) { + centity_t *cent; + snapshot_t *oldFrame; + int i; + + if ( !cg.snap ) { + CG_Error( "CG_TransitionSnapshot: NULL cg.snap" ); + } + if ( !cg.nextSnap ) { + CG_Error( "CG_TransitionSnapshot: NULL cg.nextSnap" ); + } + + // execute any server string commands before transitioning entities + CG_ExecuteNewServerCommands( cg.nextSnap->serverCommandSequence ); + + // if we had a map_restart, set everthing with initial + + if ( !( cg.snap ) || !( cg.nextSnap ) ) { + return; + } + + // clear the currentValid flag for all entities in the existing snapshot + for ( i = 0 ; i < cg.snap->numEntities ; i++ ) { + cent = &cg_entities[ cg.snap->entities[ i ].number ]; + cent->currentValid = qfalse; + } + + // move nextSnap to snap and do the transitions + oldFrame = cg.snap; + cg.snap = cg.nextSnap; + + BG_PlayerStateToEntityState( &cg.snap->ps, &cg_entities[ cg.snap->ps.clientNum ].currentState, qfalse ); + cg_entities[ cg.snap->ps.clientNum ].interpolate = qfalse; + + for ( i = 0 ; i < cg.snap->numEntities ; i++ ) { + cent = &cg_entities[ cg.snap->entities[ i ].number ]; + CG_TransitionEntity( cent ); + } + + cg.nextSnap = NULL; + + // check for playerstate transition events + if ( oldFrame ) { + playerState_t *ops, *ps; + + ops = &oldFrame->ps; + ps = &cg.snap->ps; + // teleporting checks are irrespective of prediction + if ( ( ps->eFlags ^ ops->eFlags ) & EF_TELEPORT_BIT ) { + cg.thisFrameTeleport = qtrue; // will be cleared by prediction code + } + + // if we are not doing client side movement prediction for any + // reason, then the client events and view changes will be issued now + if ( cg.demoPlayback || ( cg.snap->ps.pm_flags & PMF_FOLLOW ) + || cg_nopredict.integer || cg_synchronousClients.integer ) { + CG_TransitionPlayerState( ps, ops ); + } + } + +} + + +/* +=================== +CG_SetNextSnap + +A new snapshot has just been read in from the client system. +=================== +*/ +static void CG_SetNextSnap( snapshot_t *snap ) { + int num; + entityState_t *es; + centity_t *cent; + + cg.nextSnap = snap; + + BG_PlayerStateToEntityState( &snap->ps, &cg_entities[ snap->ps.clientNum ].nextState, qfalse ); + cg_entities[ cg.snap->ps.clientNum ].interpolate = qtrue; + + // check for extrapolation errors + for ( num = 0 ; num < snap->numEntities ; num++ ) { + es = &snap->entities[num]; + cent = &cg_entities[ es->number ]; + + memcpy( ¢->nextState, es, sizeof( entityState_t ) ); + //cent->nextState = *es; + + // if this frame is a teleport, or the entity wasn't in the + // previous frame, don't interpolate + if ( !cent->currentValid || ( ( cent->currentState.eFlags ^ es->eFlags ) & EF_TELEPORT_BIT ) ) { + cent->interpolate = qfalse; + } else { + cent->interpolate = qtrue; + } + } + + // if the next frame is a teleport for the playerstate, we + // can't interpolate during demos + if ( cg.snap && ( ( snap->ps.eFlags ^ cg.snap->ps.eFlags ) & EF_TELEPORT_BIT ) ) { + cg.nextFrameTeleport = qtrue; + } else { + cg.nextFrameTeleport = qfalse; + } + + // if changing follow mode, don't interpolate + if ( cg.nextSnap->ps.clientNum != cg.snap->ps.clientNum ) { + cg.nextFrameTeleport = qtrue; + } + + // if changing server restarts, don't interpolate + if ( ( cg.nextSnap->snapFlags ^ cg.snap->snapFlags ) & SNAPFLAG_SERVERCOUNT ) { + cg.nextFrameTeleport = qtrue; + } + + // sort out solid entities + CG_BuildSolidList(); +} + + +/* +======================== +CG_ReadNextSnapshot + +This is the only place new snapshots are requested +This may increment cgs.processedSnapshotNum multiple +times if the client system fails to return a +valid snapshot. +======================== +*/ +static snapshot_t *CG_ReadNextSnapshot( void ) { + qboolean r; + snapshot_t *dest; + + if ( cg.latestSnapshotNum > cgs.processedSnapshotNum + 1000 ) { + CG_Printf( "WARNING: CG_ReadNextSnapshot: way out of range, %i > %i", + cg.latestSnapshotNum, cgs.processedSnapshotNum ); + } + + while ( cgs.processedSnapshotNum < cg.latestSnapshotNum ) { + // decide which of the two slots to load it into + if ( cg.snap == &cg.activeSnapshots[0] ) { + dest = &cg.activeSnapshots[1]; + } else { + dest = &cg.activeSnapshots[0]; + } + + // try to read the snapshot from the client system + cgs.processedSnapshotNum++; + r = trap_GetSnapshot( cgs.processedSnapshotNum, dest ); + + // FIXME: why would trap_GetSnapshot return a snapshot with the same server time + if ( cg.snap && r && dest->serverTime == cg.snap->serverTime ) { + //continue; + } + + // if it succeeded, return + if ( r ) { + CG_AddLagometerSnapshotInfo( dest ); + + // RF, if we have no weapon selected, and this snapshots says we have a weapon, then switch to that + if ( cg.snap && !cg.weaponSelect && cg.snap->ps.weapon ) { + cg.weaponSelect = cg.snap->ps.weapon; + cg.weaponSelectTime = cg.time; + } + + // Ridah, savegame: we should use this as our new base snapshot + // server has been restarted + if ( cg.snap && ( dest->snapFlags ^ cg.snap->snapFlags ) & SNAPFLAG_SERVERCOUNT ) { + int i; + centity_t backupCent; + CG_SetInitialSnapshot( dest ); + cg.nextFrameTeleport = qtrue; + cg.damageTime = 0; + cg.duckTime = -1; + cg.landTime = -1; + cg.stepTime = -1; + // RF, loadgame hasn't occured yet, so this is likely wrong + //cg.weaponSelect = cg.snap->ps.weapon; + cg.weaponSelectTime = cg.time; + memset( cg.viewDamage, 0, sizeof( cg.viewDamage ) ); + memset( cg.cameraShake, 0, sizeof( cg.cameraShake ) ); + // go through an reset the cent's + for ( i = 0; i < MAX_GENTITIES; i++ ) { + backupCent = cg_entities[i]; + memset( &cg_entities[i], 0, sizeof( centity_t ) ); + cg_entities[i].currentState = backupCent.currentState; + cg_entities[i].nextState = backupCent.nextState; + cg_entities[i].currentValid = backupCent.currentValid; + cg_entities[i].interpolate = backupCent.interpolate; + } + // reset the predicted cent + memset( &cg.predictedPlayerEntity, 0, sizeof( centity_t ) ); + cg.predictedPlayerEntity.currentState = backupCent.currentState; + cg.predictedPlayerEntity.nextState = backupCent.nextState; + cg.predictedPlayerEntity.currentValid = backupCent.currentValid; + cg.predictedPlayerEntity.interpolate = backupCent.interpolate; + + return NULL; + } + + return dest; + } + + // a GetSnapshot will return failure if the snapshot + // never arrived, or is so old that its entities + // have been shoved off the end of the circular + // buffer in the client system. + + // record as a dropped packet + CG_AddLagometerSnapshotInfo( NULL ); + + // If there are additional snapshots, continue trying to + // read them. + } + + // nothing left to read + return NULL; +} + + +/* +============ +CG_ProcessSnapshots + +We are trying to set up a renderable view, so determine +what the simulated time is, and try to get snapshots +both before and after that time if available. + +If we don't have a valid cg.snap after exiting this function, +then a 3D game view cannot be rendered. This should only happen +right after the initial connection. After cg.snap has been valid +once, it will never turn invalid. + +Even if cg.snap is valid, cg.nextSnap may not be, if the snapshot +hasn't arrived yet (it becomes an extrapolating situation instead +of an interpolating one) + +============ +*/ +void CG_ProcessSnapshots( void ) { + snapshot_t *snap; + int n; + + // see what the latest snapshot the client system has is + trap_GetCurrentSnapshotNumber( &n, &cg.latestSnapshotTime ); + if ( n != cg.latestSnapshotNum ) { + if ( n < cg.latestSnapshotNum ) { + // this should never happen + CG_Error( "CG_ProcessSnapshots: n < cg.latestSnapshotNum" ); + } + cg.latestSnapshotNum = n; + } + + // If we have yet to receive a snapshot, check for it. + // Once we have gotten the first snapshot, cg.snap will + // always have valid data for the rest of the game + while ( !cg.snap ) { + snap = CG_ReadNextSnapshot(); + if ( !snap ) { + // we can't continue until we get a snapshot + return; + } + + // set our weapon selection to what + // the playerstate is currently using + if ( !( snap->snapFlags & SNAPFLAG_NOT_ACTIVE ) ) { + CG_SetInitialSnapshot( snap ); + } + } + + // loop until we either have a valid nextSnap with a serverTime + // greater than cg.time to interpolate towards, or we run + // out of available snapshots + do { + // if we don't have a nextframe, try and read a new one in + if ( !cg.nextSnap ) { + snap = CG_ReadNextSnapshot(); + + // if we still don't have a nextframe, we will just have to + // extrapolate + if ( !snap ) { + break; + } + + CG_SetNextSnap( snap ); + + // if time went backwards, we have a level restart + if ( cg.nextSnap->serverTime < cg.snap->serverTime ) { + CG_Error( "CG_ProcessSnapshots: Server time went backwards" ); + } + } + + // if our time is < nextFrame's, we have a nice interpolating state + if ( cg.time >= cg.snap->serverTime && cg.time < cg.nextSnap->serverTime ) { + break; + } + + // we have passed the transition from nextFrame to frame + CG_TransitionSnapshot(); + } while ( 1 ); + + // assert our valid conditions upon exiting + if ( cg.snap == NULL ) { + CG_Error( "CG_ProcessSnapshots: cg.snap == NULL" ); + } + if ( cg.time < cg.snap->serverTime ) { + // this can happen right after a vid_restart + cg.time = cg.snap->serverTime; + } + if ( cg.nextSnap != NULL && cg.nextSnap->serverTime <= cg.time ) { + CG_Error( "CG_ProcessSnapshots: cg.nextSnap->serverTime <= cg.time" ); + } + +} diff --git a/Projects/Android/jni/rtcw/src/cgame/cg_sound.c b/Projects/Android/jni/rtcw/src/cgame/cg_sound.c new file mode 100644 index 0000000..d84da3e --- /dev/null +++ b/Projects/Android/jni/rtcw/src/cgame/cg_sound.c @@ -0,0 +1,461 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +// Ridah, cg_sound.c - parsing and use of sound script files + +#include "cg_local.h" + + +// we have to define these static lists, since we can't alloc memory within the cgame + +soundScript_t* hashTable[FILE_HASH_SIZE]; +soundScript_t soundScripts[MAX_SOUND_SCRIPTS]; +int numSoundScripts = 0; +soundScriptSound_t soundScriptSounds[MAX_SOUND_SCRIPT_SOUNDS]; +int numSoundScriptSounds = 0; + +/* +================ +return a hash value for the filename +================ +*/ +static long generateHashValue( const char *fname ) { + int i; + long hash; + char letter; + + hash = 0; + i = 0; + while ( fname[i] != '\0' ) { + letter = tolower( fname[i] ); + if ( letter == '.' ) { + break; // don't include extension + } + if ( letter == '\\' ) { + letter = '/'; // damn path names + } + hash += (long)( letter ) * ( i + 119 ); + i++; + } + hash &= ( FILE_HASH_SIZE - 1 ); + return hash; +} + +/* +============== +CG_SoundScriptPrecache + + returns the index+1 of the script in the global list, for fast calling +============== +*/ +int CG_SoundScriptPrecache( const char *name ) { + soundScriptSound_t *scriptSound; + long hash; + char *s; + soundScript_t *sound; + byte buf[1024]; + + if ( !name || !name[0] ) { + return 0; + } + + hash = generateHashValue( name ); + + s = (char *)name; + sound = hashTable[hash]; + while ( sound ) { + if ( !Q_strcasecmp( s, sound->name ) ) { + // found a match, precache these sounds + scriptSound = sound->soundList; + if ( !sound->streaming ) { + while ( scriptSound ) { + scriptSound->sfxHandle = trap_S_RegisterSound( scriptSound->filename ); + scriptSound = scriptSound->next; + } + } else /*if (cg_buildScript.integer)*/ { // RF, 11/6/01 enabled this permanently so that streaming sounds get touched within file system on startup + while ( scriptSound ) { + // just open the file so it gets copied to the build dir + fileHandle_t f; + trap_FS_FOpenFile( scriptSound->filename, &f, FS_READ ); + // read a few bytes so the operating system does a better job of caching it for us + trap_FS_Read( buf, sizeof( buf ), f ); + trap_FS_FCloseFile( f ); + scriptSound = scriptSound->next; + } + } + return sound->index + 1; + } + sound = sound->nextHash; + } + + return 0; +} + +/* +============== +CG_SoundPickOldestRandomSound +============== +*/ +void CG_SoundPickOldestRandomSound( soundScript_t *sound, vec3_t org, int entnum ) { + int oldestTime = 0; // TTimo: init + soundScriptSound_t *oldestSound; + soundScriptSound_t *scriptSound; + vec3_t eOrg; + + oldestSound = NULL; + scriptSound = sound->soundList; + while ( scriptSound ) { + if ( !oldestSound || ( scriptSound->lastPlayed < oldestTime ) ) { + oldestTime = scriptSound->lastPlayed; + oldestSound = scriptSound; + } + scriptSound = scriptSound->next; + } + + if ( oldestSound ) { + // play this sound + if ( !sound->streaming ) { + if ( !oldestSound->sfxHandle ) { + oldestSound->sfxHandle = trap_S_RegisterSound( oldestSound->filename ); + } + if ( sound->attenuation ) { + trap_S_StartSound( org, entnum, sound->channel, oldestSound->sfxHandle ); + } else { + trap_S_StartLocalSound( oldestSound->sfxHandle, sound->channel ); + } + } else { + trap_S_StartStreamingSound( oldestSound->filename, sound->looping ? oldestSound->filename : NULL, entnum, sound->channel, sound->attenuation ); + } + oldestSound->lastPlayed = cg.time; + // + // shake the view? + if ( sound->shakeScale ) { + // get the origin + if ( org ) { + VectorCopy( org, eOrg ); + } else { + VectorCopy( cg_entities[entnum].lerpOrigin, eOrg ); + } + // + // start the shaker + CG_StartShakeCamera( sound->shakeScale, sound->shakeDuration, eOrg, sound->shakeRadius ); + } + } else { + CG_Error( "Unable to locate a valid sound for soundScript: %s\n", sound->name ); + } +} + +/* +============== +CG_SoundPlaySoundScript + + returns qtrue is a script is found +============== +*/ +qboolean CG_SoundPlaySoundScript( const char *name, vec3_t org, int entnum ) { + long hash; + char *s; + soundScript_t *sound; + + if ( !name || !name[0] ) { + return qfalse; + } + + hash = generateHashValue( name ); + + s = (char *)name; + sound = hashTable[hash]; + while ( sound ) { + if ( !Q_strcasecmp( s, sound->name ) ) { + // found a match, pick the oldest sound + CG_SoundPickOldestRandomSound( sound, org, entnum ); + return qtrue; + } + sound = sound->nextHash; + } + + //CG_Printf( S_COLOR_RED "CG_SoundPlaySoundScript: cannot find sound script '%s'\n", name ); + return qfalse; +} + + + +/* +============== +CG_SoundPlayIndexedScript + + returns qtrue is a script is found +============== +*/ +void CG_SoundPlayIndexedScript( int index, vec3_t org, int entnum ) { + soundScript_t *sound; + + if ( !index ) { + return; + } + + if ( index > numSoundScripts ) { + return; + } + + sound = &soundScripts[index - 1]; + // pick the oldest sound + CG_SoundPickOldestRandomSound( sound, org, entnum ); +} + +/* +=============== +CG_SoundParseSounds +=============== +*/ +static void CG_SoundParseSounds( char *filename, char *buffer ) { + char *token, **text; + int s; + long hash; + soundScript_t sound; // the current sound being read + soundScriptSound_t *scriptSound; + qboolean inSound, wantSoundName; + + s = 0; + inSound = qfalse; + wantSoundName = qtrue; + text = &buffer; + + while ( 1 ) { + token = COM_ParseExt( text, qtrue ); + if ( !token[0] ) { + if ( inSound ) { + CG_Error( "no concluding '}' in sound %s, file %s\n", sound.name, filename ); + } + return; + } + if ( !Q_strcasecmp( token, "{" ) ) { + if ( inSound ) { + CG_Error( "no concluding '}' in sound %s, file %s\n", sound.name, filename ); + } + if ( wantSoundName ) { + CG_Error( "'{' found but not expected, after %s, file %s\n", sound.name, filename ); + } + inSound = qtrue; + continue; + } + if ( !Q_strcasecmp( token, "}" ) ) { + if ( !inSound ) { + CG_Error( "'}' unexpected after sound %s, file %s\n", sound.name, filename ); + } + + // end of a sound, copy it to the global list and stick it in the hashTable + hash = generateHashValue( sound.name ); + sound.nextHash = hashTable[hash]; + soundScripts[numSoundScripts] = sound; + hashTable[hash] = &soundScripts[numSoundScripts++]; + + if ( numSoundScripts == MAX_SOUND_SCRIPTS ) { + CG_Error( "MAX_SOUND_SCRIPTS exceeded.\nReduce number of sound scripts.\n" ); + } + + inSound = qfalse; + wantSoundName = qtrue; + continue; + } + if ( !inSound ) { + // this is the identifier for a new sound + if ( !wantSoundName ) { + CG_Error( "'%s' unexpected after sound %s, file %s\n", token, sound.name, filename ); + } + memset( &sound, 0, sizeof( sound ) ); + Q_strncpyz( sound.name, token, sizeof( sound.name ) ); + wantSoundName = qfalse; + sound.index = numSoundScripts; + // setup the new sound defaults + sound.channel = CHAN_AUTO; + sound.attenuation = 1; // default to fade away with distance (for streaming sounds) + // + continue; + } + + // we are inside a sound script + + if ( !Q_strcasecmp( token, "channel" ) ) { + // ignore this now, just look for the channel identifiers explicitly + continue; + } + if ( !Q_strcasecmp( token, "local" ) ) { + sound.channel = CHAN_LOCAL; + continue; + } else if ( !Q_strcasecmp( token, "announcer" ) ) { + sound.channel = CHAN_ANNOUNCER; + continue; + } else if ( !Q_strcasecmp( token, "body" ) ) { + sound.channel = CHAN_BODY; + continue; + } else if ( !Q_strcasecmp( token, "voice" ) ) { + sound.channel = CHAN_VOICE; + continue; + } else if ( !Q_strcasecmp( token, "weapon" ) ) { + sound.channel = CHAN_WEAPON; + continue; + } else if ( !Q_strcasecmp( token, "item" ) ) { + sound.channel = CHAN_ITEM; + continue; + } else if ( !Q_strcasecmp( token, "auto" ) ) { + sound.channel = CHAN_AUTO; + continue; + } + if ( !Q_strcasecmp( token, "global" ) ) { + sound.attenuation = 0; + continue; + } + if ( !Q_strcasecmp( token, "streaming" ) ) { + sound.streaming = qtrue; + continue; + } + if ( !Q_strcasecmp( token, "looping" ) ) { + sound.looping = qtrue; + continue; + } + if ( !Q_strcasecmp( token, "shake" ) ) { + token = COM_ParseExt( text, qfalse ); + sound.shakeScale = atof( token ); + token = COM_ParseExt( text, qfalse ); + sound.shakeRadius = atof( token ); + token = COM_ParseExt( text, qfalse ); + if ( !token || !token[0] ) { + sound.shakeDuration = 350 + 900 * ( sound.shakeScale * sound.shakeScale ); + } else { + sound.shakeDuration = atoi( token ); + } + } + if ( !Q_strcasecmp( token, "sound" ) ) { + // grab a free scriptSound + scriptSound = &soundScriptSounds[numSoundScriptSounds++]; + + if ( numSoundScripts == MAX_SOUND_SCRIPT_SOUNDS ) { + CG_Error( "MAX_SOUND_SCRIPT_SOUNDS exceeded.\nReduce number of sound scripts.\n" ); + } + + token = COM_ParseExt( text, qtrue ); + Q_strncpyz( scriptSound->filename, token, sizeof( scriptSound->filename ) ); + scriptSound->lastPlayed = 0; + scriptSound->sfxHandle = 0; + scriptSound->next = sound.soundList; + sound.soundList = scriptSound; + continue; + } + } +} + +/* +=============== +CG_SoundLoadSoundFiles +=============== +*/ +#define MAX_SOUND_FILES 128 +#define MAX_BUFFER 20000 +static void CG_SoundLoadSoundFiles( void ) { + char soundFiles[MAX_SOUND_FILES][MAX_QPATH]; + char buffer[MAX_BUFFER]; + char *text; + char filename[MAX_QPATH]; + fileHandle_t f; + int numSounds; + int i, len; + char *token; + + // scan for sound files + Com_sprintf( filename, MAX_QPATH, "sound/scripts/filelist.txt" ); + len = trap_FS_FOpenFile( filename, &f, FS_READ ); + if ( len <= 0 ) { + CG_Printf( S_COLOR_RED "WARNING: no sound files found (filelist.txt not found in sound/scripts)\n" ); + return; + } + if ( len > MAX_BUFFER ) { + CG_Error( "%s is too big, make it smaller (max = %i bytes)\n", filename, MAX_BUFFER ); + } + // load the file into memory + trap_FS_Read( buffer, len, f ); + buffer[len] = 0; + trap_FS_FCloseFile( f ); + // parse the list + text = buffer; + numSounds = 0; + while ( 1 ) { + token = COM_ParseExt( &text, qtrue ); + if ( !token[0] ) { + break; + } + Com_sprintf( soundFiles[numSounds++], MAX_QPATH, token ); + } + + if ( !numSounds ) { + CG_Printf( S_COLOR_RED "WARNING: no sound files found\n" ); + return; + } + + // load and parse sound files + for ( i = 0; i < numSounds; i++ ) + { + Com_sprintf( filename, sizeof( filename ), "sound/scripts/%s", soundFiles[i] ); + CG_Printf( "...loading '%s'\n", filename ); + len = trap_FS_FOpenFile( filename, &f, FS_READ ); + if ( len <= 0 ) { + CG_Error( "Couldn't load %s", filename ); + } + if ( len > MAX_BUFFER ) { + CG_Error( "%s is too big, make it smaller (max = %i bytes)\n", filename, MAX_BUFFER ); + } + memset( buffer, 0, sizeof( buffer ) ); + trap_FS_Read( buffer, len, f ); + trap_FS_FCloseFile( f ); + CG_SoundParseSounds( filename, buffer ); + } +} + +/* +============== +CG_SoundInit +============== +*/ +void CG_SoundInit( void ) { + + if ( numSoundScripts ) { + // keep all the information, just reset the vars + int i; + + for ( i = 0; i < numSoundScriptSounds; i++ ) { + soundScriptSounds[i].lastPlayed = 0; + soundScriptSounds[i].sfxHandle = 0; + } + } else { + CG_Printf( "\n.........................\n" + "Initializing Sound Scripts\n" ); + CG_SoundLoadSoundFiles(); + CG_Printf( "done.\n" ); + } + +} diff --git a/Projects/Android/jni/rtcw/src/cgame/cg_syscalls.c b/Projects/Android/jni/rtcw/src/cgame/cg_syscalls.c new file mode 100644 index 0000000..1ab6ebe --- /dev/null +++ b/Projects/Android/jni/rtcw/src/cgame/cg_syscalls.c @@ -0,0 +1,546 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +// cg_syscalls.c -- this file is only included when building a dll +// cg_syscalls.asm is included instead when building a qvm +#include "cg_local.h" + +static int ( QDECL * syscall )( int arg, ... ) = ( int ( QDECL * )( int, ... ) ) - 1; + +// TTimo: guarding +#if defined( __MACOS__ ) +#pragma export on +#endif +void dllEntry( int ( QDECL *syscallptr )( int arg,... ) ) { +#if defined( __MACOS__ ) +#pragma export off +#endif + syscall = syscallptr; +} + + +int PASSFLOAT( float x ) { + float floatTemp; + floatTemp = x; + return *(int *)&floatTemp; +} + +void trap_Print( const char *fmt ) { + syscall( CG_PRINT, fmt ); +} + +void trap_Error( const char *fmt ) { + syscall( CG_ERROR, fmt ); +} + +int trap_Milliseconds( void ) { + return syscall( CG_MILLISECONDS ); +} + +void trap_Cvar_Register( vmCvar_t *vmCvar, const char *varName, const char *defaultValue, int flags ) { + syscall( CG_CVAR_REGISTER, vmCvar, varName, defaultValue, flags ); +} + +void trap_Cvar_Update( vmCvar_t *vmCvar ) { + syscall( CG_CVAR_UPDATE, vmCvar ); +} + +void trap_Cvar_Set( const char *var_name, const char *value ) { + syscall( CG_CVAR_SET, var_name, value ); +} + +void trap_Cvar_VariableStringBuffer( const char *var_name, char *buffer, int bufsize ) { + syscall( CG_CVAR_VARIABLESTRINGBUFFER, var_name, buffer, bufsize ); +} + +int trap_Argc( void ) { + return syscall( CG_ARGC ); +} + +void trap_Argv( int n, char *buffer, int bufferLength ) { + syscall( CG_ARGV, n, buffer, bufferLength ); +} + +void trap_Args( char *buffer, int bufferLength ) { + syscall( CG_ARGS, buffer, bufferLength ); +} + +int trap_FS_FOpenFile( const char *qpath, fileHandle_t *f, fsMode_t mode ) { + return syscall( CG_FS_FOPENFILE, qpath, f, mode ); +} + +void trap_FS_Read( void *buffer, int len, fileHandle_t f ) { + syscall( CG_FS_READ, buffer, len, f ); +} + +void trap_FS_Write( const void *buffer, int len, fileHandle_t f ) { + syscall( CG_FS_WRITE, buffer, len, f ); +} + +void trap_FS_FCloseFile( fileHandle_t f ) { + syscall( CG_FS_FCLOSEFILE, f ); +} + +void trap_SendConsoleCommand( const char *text ) { + syscall( CG_SENDCONSOLECOMMAND, text ); +} + +void trap_AddCommand( const char *cmdName ) { + syscall( CG_ADDCOMMAND, cmdName ); +} + +void trap_SendClientCommand( const char *s ) { + syscall( CG_SENDCLIENTCOMMAND, s ); +} + +void trap_UpdateScreen( void ) { + syscall( CG_UPDATESCREEN ); +} + +void trap_CM_LoadMap( const char *mapname ) { + syscall( CG_CM_LOADMAP, mapname ); +} + +int trap_CM_NumInlineModels( void ) { + return syscall( CG_CM_NUMINLINEMODELS ); +} + +clipHandle_t trap_CM_InlineModel( int index ) { + return syscall( CG_CM_INLINEMODEL, index ); +} + +clipHandle_t trap_CM_TempBoxModel( const vec3_t mins, const vec3_t maxs ) { + return syscall( CG_CM_TEMPBOXMODEL, mins, maxs ); +} + +clipHandle_t trap_CM_TempCapsuleModel( const vec3_t mins, const vec3_t maxs ) { + return syscall( CG_CM_TEMPCAPSULEMODEL, mins, maxs ); +} + +int trap_CM_PointContents( const vec3_t p, clipHandle_t model ) { + return syscall( CG_CM_POINTCONTENTS, p, model ); +} + +int trap_CM_TransformedPointContents( const vec3_t p, clipHandle_t model, const vec3_t origin, const vec3_t angles ) { + return syscall( CG_CM_TRANSFORMEDPOINTCONTENTS, p, model, origin, angles ); +} + +void trap_CM_BoxTrace( trace_t *results, const vec3_t start, const vec3_t end, + const vec3_t mins, const vec3_t maxs, + clipHandle_t model, int brushmask ) { + syscall( CG_CM_BOXTRACE, results, start, end, mins, maxs, model, brushmask ); +} + +void trap_CM_TransformedBoxTrace( trace_t *results, const vec3_t start, const vec3_t end, + const vec3_t mins, const vec3_t maxs, + clipHandle_t model, int brushmask, + const vec3_t origin, const vec3_t angles ) { + syscall( CG_CM_TRANSFORMEDBOXTRACE, results, start, end, mins, maxs, model, brushmask, origin, angles ); +} + +void trap_CM_CapsuleTrace( trace_t *results, const vec3_t start, const vec3_t end, + const vec3_t mins, const vec3_t maxs, + clipHandle_t model, int brushmask ) { + syscall( CG_CM_CAPSULETRACE, results, start, end, mins, maxs, model, brushmask ); +} + +void trap_CM_TransformedCapsuleTrace( trace_t *results, const vec3_t start, const vec3_t end, + const vec3_t mins, const vec3_t maxs, + clipHandle_t model, int brushmask, + const vec3_t origin, const vec3_t angles ) { + syscall( CG_CM_TRANSFORMEDCAPSULETRACE, results, start, end, mins, maxs, model, brushmask, origin, angles ); +} + +int trap_CM_MarkFragments( int numPoints, const vec3_t *points, + const vec3_t projection, + int maxPoints, vec3_t pointBuffer, + int maxFragments, markFragment_t *fragmentBuffer ) { + return syscall( CG_CM_MARKFRAGMENTS, numPoints, points, projection, maxPoints, pointBuffer, maxFragments, fragmentBuffer ); +} + +void trap_S_StartSound( vec3_t origin, int entityNum, int entchannel, sfxHandle_t sfx ) { + syscall( CG_S_STARTSOUND, origin, entityNum, entchannel, sfx ); +} + +//----(SA) added +void trap_S_StartSoundEx( vec3_t origin, int entityNum, int entchannel, sfxHandle_t sfx, int flags ) { + syscall( CG_S_STARTSOUNDEX, origin, entityNum, entchannel, sfx, flags ); +} +//----(SA) end + +void trap_S_StartLocalSound( sfxHandle_t sfx, int channelNum ) { + syscall( CG_S_STARTLOCALSOUND, sfx, channelNum ); +} + +void trap_S_ClearLoopingSounds( qboolean killall ) { + syscall( CG_S_CLEARLOOPINGSOUNDS, killall ); +} + +void trap_S_AddLoopingSound( int entityNum, const vec3_t origin, const vec3_t velocity, sfxHandle_t sfx, int volume ) { + syscall( CG_S_ADDLOOPINGSOUND, entityNum, origin, velocity, 1250, sfx, volume ); // volume was previously removed from CG_S_ADDLOOPINGSOUND. I added 'range' +} + +//----(SA) added +void trap_S_AddRangedLoopingSound( int entityNum, const vec3_t origin, const vec3_t velocity, sfxHandle_t sfx, int range ) { + syscall( CG_S_ADDLOOPINGSOUND, entityNum, origin, velocity, range, sfx, 255 ); // RF, assume full volume, since thats how it worked before +} +//----(SA) end + +void trap_S_AddRealLoopingSound( int entityNum, const vec3_t origin, const vec3_t velocity, sfxHandle_t sfx ) { +// not in use +// syscall( CG_S_ADDREALLOOPINGSOUND, entityNum, origin, velocity, 1250, sfx, 255 ); //----(SA) modified +} + +void trap_S_StopLoopingSound( int entityNum ) { + syscall( CG_S_STOPLOOPINGSOUND, entityNum ); +} + +//----(SA) added +void trap_S_StopStreamingSound( int entityNum ) { + syscall( CG_S_STOPSTREAMINGSOUND, entityNum ); +} +//----(SA) end + +void trap_S_UpdateEntityPosition( int entityNum, const vec3_t origin ) { + syscall( CG_S_UPDATEENTITYPOSITION, entityNum, origin ); +} + +// Ridah, talking animations +int trap_S_GetVoiceAmplitude( int entityNum ) { + return syscall( CG_S_GETVOICEAMPLITUDE, entityNum ); +} +// done. + +void trap_S_Respatialize( int entityNum, const vec3_t origin, vec3_t axis[3], int inwater ) { + syscall( CG_S_RESPATIALIZE, entityNum, origin, axis, inwater ); +} + +sfxHandle_t trap_S_RegisterSound( const char *sample ) { + CG_DrawInformation(); + return syscall( CG_S_REGISTERSOUND, sample ); +} + +void trap_S_StartBackgroundTrack( const char *intro, const char *loop, int fadeupTime ) { + syscall( CG_S_STARTBACKGROUNDTRACK, intro, loop, fadeupTime ); +} + +void trap_S_FadeBackgroundTrack( float targetvol, int time, int num ) { // yes, i know. fadebackground coming in, fadestreaming going out. will have to see where functionality leads... + syscall( CG_S_FADESTREAMINGSOUND, PASSFLOAT( targetvol ), time, num ); // 'num' is '0' if it's music, '1' if it's "all streaming sounds" +} + +void trap_S_FadeAllSound( float targetvol, int time ) { + syscall( CG_S_FADEALLSOUNDS, PASSFLOAT( targetvol ), time ); +} + +//----(SA) end + +void trap_S_StartStreamingSound( const char *intro, const char *loop, int entnum, int channel, int attenuation ) { + syscall( CG_S_STARTSTREAMINGSOUND, intro, loop, entnum, channel, attenuation ); +} + +void trap_R_LoadWorldMap( const char *mapname ) { + syscall( CG_R_LOADWORLDMAP, mapname ); +} + +qhandle_t trap_R_RegisterModel( const char *name ) { + CG_DrawInformation(); + return syscall( CG_R_REGISTERMODEL, name ); +} + +//----(SA) added +qboolean trap_R_GetSkinModel( qhandle_t skinid, const char *type, char *name ) { + return syscall( CG_R_GETSKINMODEL, skinid, type, name ); +} + +qhandle_t trap_R_GetShaderFromModel( qhandle_t modelid, int surfnum, int withlightmap ) { + return syscall( CG_R_GETMODELSHADER, modelid, surfnum, withlightmap ); +} +//----(SA) end + +qhandle_t trap_R_RegisterSkin( const char *name ) { + CG_DrawInformation(); + return syscall( CG_R_REGISTERSKIN, name ); +} + +qhandle_t trap_R_RegisterShader( const char *name ) { + CG_DrawInformation(); + return syscall( CG_R_REGISTERSHADER, name ); +} + +qhandle_t trap_R_RegisterShaderNoMip( const char *name ) { + CG_DrawInformation(); + return syscall( CG_R_REGISTERSHADERNOMIP, name ); +} + +void trap_R_RegisterFont( const char *fontName, int pointSize, fontInfo_t *font ) { + syscall( CG_R_REGISTERFONT, fontName, pointSize, font ); +} + +void trap_R_ClearScene( void ) { + syscall( CG_R_CLEARSCENE ); +} + +void trap_R_AddRefEntityToScene( const refEntity_t *re ) { + syscall( CG_R_ADDREFENTITYTOSCENE, re ); +} + +void trap_R_AddPolyToScene( qhandle_t hShader, int numVerts, const polyVert_t *verts ) { + syscall( CG_R_ADDPOLYTOSCENE, hShader, numVerts, verts ); +} + +// Ridah +void trap_R_AddPolysToScene( qhandle_t hShader, int numVerts, const polyVert_t *verts, int numPolys ) { + syscall( CG_R_ADDPOLYSTOSCENE, hShader, numVerts, verts, numPolys ); +} + +void trap_RB_ZombieFXAddNewHit( int entityNum, const vec3_t hitPos, const vec3_t hitDir ) { + syscall( CG_RB_ZOMBIEFXADDNEWHIT, entityNum, hitPos, hitDir ); +} +// done. + +void trap_R_AddLightToScene( const vec3_t org, float intensity, float r, float g, float b, int overdraw ) { + syscall( CG_R_ADDLIGHTTOSCENE, org, PASSFLOAT( intensity ), PASSFLOAT( r ), PASSFLOAT( g ), PASSFLOAT( b ), overdraw ); +} + +//----(SA) +void trap_R_AddCoronaToScene( const vec3_t org, float r, float g, float b, float scale, int id, int flags ) { + syscall( CG_R_ADDCORONATOSCENE, org, PASSFLOAT( r ), PASSFLOAT( g ), PASSFLOAT( b ), PASSFLOAT( scale ), id, flags ); +} +//----(SA) + +//----(SA) +void trap_R_SetFog( int fogvar, int var1, int var2, float r, float g, float b, float density ) { + syscall( CG_R_SETFOG, fogvar, var1, var2, PASSFLOAT( r ), PASSFLOAT( g ), PASSFLOAT( b ), PASSFLOAT( density ) ); +} +//----(SA) +void trap_R_RenderScene( const refdef_t *fd ) { + syscall( CG_R_RENDERSCENE, fd ); +} + +void trap_R_SetColor( const float *rgba ) { + syscall( CG_R_SETCOLOR, rgba ); +} + +void trap_R_DrawStretchPic( float x, float y, float w, float h, + float s1, float t1, float s2, float t2, qhandle_t hShader ) { + syscall( CG_R_DRAWSTRETCHPIC, PASSFLOAT( x ), PASSFLOAT( y ), PASSFLOAT( w ), PASSFLOAT( h ), PASSFLOAT( s1 ), PASSFLOAT( t1 ), PASSFLOAT( s2 ), PASSFLOAT( t2 ), hShader ); +} + +void trap_R_DrawStretchPicGradient( float x, float y, float w, float h, + float s1, float t1, float s2, float t2, qhandle_t hShader, + const float *gradientColor, int gradientType ) { + syscall( CG_R_DRAWSTRETCHPIC_GRADIENT, PASSFLOAT( x ), PASSFLOAT( y ), PASSFLOAT( w ), PASSFLOAT( h ), PASSFLOAT( s1 ), PASSFLOAT( t1 ), PASSFLOAT( s2 ), PASSFLOAT( t2 ), hShader, gradientColor, gradientType ); +} + +void trap_R_ModelBounds( clipHandle_t model, vec3_t mins, vec3_t maxs ) { + syscall( CG_R_MODELBOUNDS, model, mins, maxs ); +} + +int trap_R_LerpTag( orientation_t *tag, const refEntity_t *refent, const char *tagName, int startIndex ) { + return syscall( CG_R_LERPTAG, tag, refent, tagName, startIndex ); +} + +void trap_R_RemapShader( const char *oldShader, const char *newShader, const char *timeOffset ) { + syscall( CG_R_REMAP_SHADER, oldShader, newShader, timeOffset ); +} + +void trap_GetGlconfig( glconfig_t *glconfig ) { + syscall( CG_GETGLCONFIG, glconfig ); +} + +void trap_GetGameState( gameState_t *gamestate ) { + syscall( CG_GETGAMESTATE, gamestate ); +} + +void trap_GetCurrentSnapshotNumber( int *snapshotNumber, int *serverTime ) { + syscall( CG_GETCURRENTSNAPSHOTNUMBER, snapshotNumber, serverTime ); +} + +qboolean trap_GetSnapshot( int snapshotNumber, snapshot_t *snapshot ) { + return syscall( CG_GETSNAPSHOT, snapshotNumber, snapshot ); +} + +qboolean trap_GetServerCommand( int serverCommandNumber ) { + return syscall( CG_GETSERVERCOMMAND, serverCommandNumber ); +} + +int trap_GetCurrentCmdNumber( void ) { + return syscall( CG_GETCURRENTCMDNUMBER ); +} + +qboolean trap_GetUserCmd( int cmdNumber, usercmd_t *ucmd ) { + return syscall( CG_GETUSERCMD, cmdNumber, ucmd ); +} +#ifdef AUTOAIM +void trap_SetUserCmdValue( int stateValue, int holdableValue, float sensitivityScale, int cld, int lastFire, int crossHairStatus ) { //----(SA) // NERVE - SMF - added cld + syscall( CG_SETUSERCMDVALUE, stateValue, holdableValue, PASSFLOAT( sensitivityScale ), cld, lastFire, crossHairStatus ); + #else +void trap_SetUserCmdValue( int stateValue, int holdableValue, float sensitivityScale, int cld ) { //----(SA) // NERVE - SMF - added cld + syscall( CG_SETUSERCMDVALUE, stateValue, holdableValue, PASSFLOAT( sensitivityScale ), cld ); + #endif +} + +void testPrintInt( char *string, int i ) { + syscall( CG_TESTPRINTINT, string, i ); +} + +void testPrintFloat( char *string, float f ) { + syscall( CG_TESTPRINTFLOAT, string, PASSFLOAT( f ) ); +} + +int trap_MemoryRemaining( void ) { + return syscall( CG_MEMORY_REMAINING ); +} + +qboolean trap_loadCamera( int camNum, const char *name ) { + return syscall( CG_LOADCAMERA, camNum, name ); +} + +void trap_startCamera( int camNum, int time ) { + syscall( CG_STARTCAMERA, camNum, time ); +} + +//----(SA) added +void trap_stopCamera( int camNum ) { + syscall( CG_STOPCAMERA, camNum ); +} +//----(SA) end + +qboolean trap_getCameraInfo( int camNum, int time, vec3_t *origin, vec3_t *angles, float *fov ) { + return syscall( CG_GETCAMERAINFO, camNum, time, origin, angles, fov ); +} + + +qboolean trap_Key_IsDown( int keynum ) { + return syscall( CG_KEY_ISDOWN, keynum ); +} + +int trap_Key_GetCatcher( void ) { + return syscall( CG_KEY_GETCATCHER ); +} + +void trap_Key_SetCatcher( int catcher ) { + syscall( CG_KEY_SETCATCHER, catcher ); +} + +int trap_Key_GetKey( const char *binding ) { + return syscall( CG_KEY_GETKEY, binding ); +} + + +int trap_PC_AddGlobalDefine( char *define ) { + return syscall( CG_PC_ADD_GLOBAL_DEFINE, define ); +} + +int trap_PC_LoadSource( const char *filename ) { + return syscall( CG_PC_LOAD_SOURCE, filename ); +} + +int trap_PC_FreeSource( int handle ) { + return syscall( CG_PC_FREE_SOURCE, handle ); +} + +int trap_PC_ReadToken( int handle, pc_token_t *pc_token ) { + return syscall( CG_PC_READ_TOKEN, handle, pc_token ); +} + + +int trap_PC_SourceFileAndLine( int handle, char *filename, int *line ) { + return syscall( CG_PC_SOURCE_FILE_AND_LINE, handle, filename, line ); +} + +void trap_S_StopBackgroundTrack( void ) { + syscall( CG_S_STOPBACKGROUNDTRACK ); +} + +int trap_RealTime( qtime_t *qtime ) { + return syscall( CG_REAL_TIME, qtime ); +} + +void trap_SnapVector( float *v ) { + syscall( CG_SNAPVECTOR, v ); +} + +void trap_SendMoveSpeedsToGame( int entnum, char *movespeeds ) { + syscall( CG_SENDMOVESPEEDSTOGAME, entnum, movespeeds ); +} + +// this returns a handle. arg0 is the name in the format "idlogo.roq", set arg1 to NULL, alteredstates to qfalse (do not alter gamestate) +int trap_CIN_PlayCinematic( const char *arg0, int xpos, int ypos, int width, int height, int bits ) { + return syscall( CG_CIN_PLAYCINEMATIC, arg0, xpos, ypos, width, height, bits ); +} + +// stops playing the cinematic and ends it. should always return FMV_EOF +// cinematics must be stopped in reverse order of when they are started +e_status trap_CIN_StopCinematic( int handle ) { + return syscall( CG_CIN_STOPCINEMATIC, handle ); +} + + +// will run a frame of the cinematic but will not draw it. Will return FMV_EOF if the end of the cinematic has been reached. +e_status trap_CIN_RunCinematic( int handle ) { + return syscall( CG_CIN_RUNCINEMATIC, handle ); +} + + +// draws the current frame +void trap_CIN_DrawCinematic( int handle ) { + syscall( CG_CIN_DRAWCINEMATIC, handle ); +} + + +// allows you to resize the animation dynamically +void trap_CIN_SetExtents( int handle, int x, int y, int w, int h ) { + syscall( CG_CIN_SETEXTENTS, handle, x, y, w, h ); +} + +qboolean trap_GetEntityToken( char *buffer, int bufferSize ) { + return syscall( CG_GET_ENTITY_TOKEN, buffer, bufferSize ); +} + +//----(SA) added +// bring up a popup menu +extern void Menus_OpenByName( const char *p ); + +void trap_UI_Popup( const char *arg0 ) { + syscall( CG_INGAME_POPUP, arg0 ); +} + +// NERVE - SMF +void trap_UI_LimboChat( const char *arg0 ) { + syscall( CG_LIMBOCHAT, arg0 ); +} + +void trap_UI_ClosePopup( const char *arg0 ) { + syscall( CG_INGAME_CLOSEPOPUP, arg0 ); +} +// -NERVE - SMF + +qboolean trap_GetModelInfo( int clientNum, char *modelName, animModelInfo_t **modelInfo ) { + return syscall( CG_GETMODELINFO, clientNum, modelName, modelInfo ); +} diff --git a/Projects/Android/jni/rtcw/src/cgame/cg_trails.c b/Projects/Android/jni/rtcw/src/cgame/cg_trails.c new file mode 100644 index 0000000..4956165 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/cgame/cg_trails.c @@ -0,0 +1,785 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +// Ridah, cg_trails.c - draws a trail using multiple junction points + +#include "cg_local.h" + +typedef struct trailJunc_s +{ + struct trailJunc_s *nextGlobal, *prevGlobal; // next junction in the global list it is in (free or used) + struct trailJunc_s *nextJunc; // next junction in the trail + struct trailJunc_s *nextHead, *prevHead; // next head junc in the world + + qboolean inuse, freed; + int ownerIndex; + qhandle_t shader; + + int sType; + int flags; + float sTex; + vec3_t pos; + int spawnTime, endTime; + float alphaStart, alphaEnd; + vec3_t colorStart, colorEnd; + float widthStart, widthEnd; + + // current settings + float alpha; + float width; + vec3_t color; + +} trailJunc_t; + +#define MAX_TRAILJUNCS 4096 + +trailJunc_t trailJuncs[MAX_TRAILJUNCS]; +trailJunc_t *freeTrails, *activeTrails; +trailJunc_t *headTrails; + +qboolean initTrails = qfalse; + +int numTrailsInuse; + +/* +=============== +CG_ClearTrails +=============== +*/ +void CG_ClearTrails( void ) { + int i; + + memset( trailJuncs, 0, sizeof( trailJunc_t ) * MAX_TRAILJUNCS ); + + freeTrails = trailJuncs; + activeTrails = NULL; + headTrails = NULL; + + for ( i = 0 ; i < MAX_TRAILJUNCS ; i++ ) + { + trailJuncs[i].nextGlobal = &trailJuncs[i + 1]; + + if ( i > 0 ) { + trailJuncs[i].prevGlobal = &trailJuncs[i - 1]; + } else { + trailJuncs[i].prevGlobal = NULL; + } + + trailJuncs[i].inuse = qfalse; + } + trailJuncs[MAX_TRAILJUNCS - 1].nextGlobal = NULL; + + initTrails = qtrue; + numTrailsInuse = 0; +} + +/* +=============== +CG_SpawnTrailJunc +=============== +*/ +trailJunc_t *CG_SpawnTrailJunc( trailJunc_t *headJunc ) { + trailJunc_t *j; + + if ( !freeTrails ) { + return NULL; + } + + if ( cg_paused.integer ) { + return NULL; + } + + // select the first free trail, and remove it from the list + j = freeTrails; + freeTrails = j->nextGlobal; + if ( freeTrails ) { + freeTrails->prevGlobal = NULL; + } + + j->nextGlobal = activeTrails; + if ( activeTrails ) { + activeTrails->prevGlobal = j; + } + activeTrails = j; + j->prevGlobal = NULL; + j->inuse = qtrue; + j->freed = qfalse; + + // if this owner has a headJunc, add us to the start + if ( headJunc ) { + // remove the headJunc from the list of heads + if ( headJunc == headTrails ) { + headTrails = headJunc->nextHead; + if ( headTrails ) { + headTrails->prevHead = NULL; + } + } else { + if ( headJunc->nextHead ) { + headJunc->nextHead->prevHead = headJunc->prevHead; + } + if ( headJunc->prevHead ) { + headJunc->prevHead->nextHead = headJunc->nextHead; + } + } + headJunc->prevHead = NULL; + headJunc->nextHead = NULL; + } + // make us the headTrail + if ( headTrails ) { + headTrails->prevHead = j; + } + j->nextHead = headTrails; + j->prevHead = NULL; + headTrails = j; + + j->nextJunc = headJunc; // if headJunc is NULL, then we'll just be the end of the list + + numTrailsInuse++; + + // debugging +// CG_Printf( "NumTrails: %i\n", numTrailsInuse ); + + return j; +} + + +/* +=============== +CG_AddTrailJunc + + returns the index of the trail junction created + + Used for generic trails +=============== +*/ +int CG_AddTrailJunc( int headJuncIndex, qhandle_t shader, int spawnTime, int sType, vec3_t pos, int trailLife, float alphaStart, float alphaEnd, float startWidth, float endWidth, int flags, vec3_t colorStart, vec3_t colorEnd, float sRatio, float animSpeed ) { + trailJunc_t *j, *headJunc; + + if ( headJuncIndex > 0 ) { + headJunc = &trailJuncs[headJuncIndex - 1]; + + if ( !headJunc->inuse ) { + headJunc = NULL; + } + } else { + headJunc = NULL; + } + + j = CG_SpawnTrailJunc( headJunc ); + if ( !j ) { +// CG_Printf("couldnt spawn trail junc\n"); + return 0; + } + + if ( alphaStart > 1.0 ) { + alphaStart = 1.0; + } + if ( alphaStart < 0.0 ) { + alphaStart = 0.0; + } + if ( alphaEnd > 1.0 ) { + alphaEnd = 1.0; + } + if ( alphaEnd < 0.0 ) { + alphaEnd = 0.0; + } + + // setup the trail junction + j->shader = shader; + j->sType = sType; + VectorCopy( pos, j->pos ); + j->flags = flags; + + j->spawnTime = spawnTime; + j->endTime = spawnTime + trailLife; + + VectorCopy( colorStart, j->colorStart ); + VectorCopy( colorEnd, j->colorEnd ); + + j->alphaStart = alphaStart; + j->alphaEnd = alphaEnd; + + j->widthStart = startWidth; + j->widthEnd = endWidth; + + if ( sType == STYPE_REPEAT ) { + if ( headJunc ) { + j->sTex = headJunc->sTex + ( ( Distance( headJunc->pos, pos ) / sRatio ) / j->widthEnd ); + } else { + // FIXME: need a way to specify offset timing + j->sTex = ( animSpeed * ( 1.0 - ( (float)( cg.time % 1000 ) / 1000.0 ) ) ) / ( sRatio ); +// j->sTex = 0; + } + } + + return ( (int)( j - trailJuncs ) + 1 ); +} + +/* +=============== +CG_AddSparkJunc + + returns the index of the trail junction created +=============== +*/ +int CG_AddSparkJunc( int headJuncIndex, qhandle_t shader, vec3_t pos, int trailLife, float alphaStart, float alphaEnd, float startWidth, float endWidth ) { + trailJunc_t *j, *headJunc; + + if ( headJuncIndex > 0 ) { + headJunc = &trailJuncs[headJuncIndex - 1]; + + if ( !headJunc->inuse ) { + headJunc = NULL; + } + } else { + headJunc = NULL; + } + + j = CG_SpawnTrailJunc( headJunc ); + if ( !j ) { + return 0; + } + + // setup the trail junction + j->shader = shader; + j->sType = STYPE_STRETCH; + VectorCopy( pos, j->pos ); + j->flags = TJFL_NOCULL; // don't worry about fading up close + + j->spawnTime = cg.time; + j->endTime = cg.time + trailLife; + + VectorSet( j->colorStart, 1.0, 0.8 + 0.2 * alphaStart, 0.4 + 0.4 * alphaStart ); + VectorSet( j->colorEnd, 1.0, 0.8 + 0.2 * alphaEnd, 0.4 + 0.4 * alphaEnd ); +// VectorScale( j->colorStart, alphaStart, j->colorStart ); +// VectorScale( j->colorEnd, alphaEnd, j->colorEnd ); + + j->alphaStart = alphaStart * 2; + j->alphaEnd = alphaEnd * 2; +// j->alphaStart = 1.0; +// j->alphaEnd = 1.0; + + j->widthStart = startWidth; + j->widthEnd = endWidth; + + return ( (int)( j - trailJuncs ) + 1 ); +} + +/* +=============== +CG_AddSmokeJunc + + returns the index of the trail junction created +=============== +*/ +int CG_AddSmokeJunc( int headJuncIndex, qhandle_t shader, vec3_t pos, int trailLife, float alpha, float startWidth, float endWidth ) { +#define ST_RATIO 4.0 // sprite image: width / height + trailJunc_t *j, *headJunc; + + if ( headJuncIndex > 0 ) { + headJunc = &trailJuncs[headJuncIndex - 1]; + + if ( !headJunc->inuse ) { + headJunc = NULL; + } + } else { + headJunc = NULL; + } + + j = CG_SpawnTrailJunc( headJunc ); + if ( !j ) { + return 0; + } + + // setup the trail junction + j->shader = shader; + j->sType = STYPE_REPEAT; + VectorCopy( pos, j->pos ); + j->flags = TJFL_FADEIN; + + j->spawnTime = cg.time; + j->endTime = cg.time + trailLife; + + // VectorSet(j->colorStart, 0.2, 0.2, 0.2); + VectorSet( j->colorStart, 0.0, 0.0, 0.0 ); + // VectorSet(j->colorEnd, 0.1, 0.1, 0.1); + VectorSet( j->colorEnd, 0.0, 0.0, 0.0 ); + + j->alphaStart = alpha; + j->alphaEnd = 0.0; + + j->widthStart = startWidth; + j->widthEnd = endWidth; + + if ( headJunc ) { + j->sTex = headJunc->sTex + ( ( Distance( headJunc->pos, pos ) / ST_RATIO ) / j->widthEnd ); + } else { + // first junction, so this will become the "tail" very soon, make it fade out + j->sTex = 0; + j->alphaStart = 0.0; + j->alphaEnd = 0.0; + } + + return ( (int)( j - trailJuncs ) + 1 ); +} + +void CG_KillTrail( trailJunc_t *t ); + +/* +=========== +CG_FreeTrailJunc +=========== +*/ +void CG_FreeTrailJunc( trailJunc_t *junc ) { + // kill any juncs after us, so they aren't left hanging + if ( junc->nextJunc ) { + CG_KillTrail( junc ); + } + + // make it non-active + junc->inuse = qfalse; + junc->freed = qtrue; + if ( junc->nextGlobal ) { + junc->nextGlobal->prevGlobal = junc->prevGlobal; + } + if ( junc->prevGlobal ) { + junc->prevGlobal->nextGlobal = junc->nextGlobal; + } + if ( junc == activeTrails ) { + activeTrails = junc->nextGlobal; + } + + // if it's a head, remove it + if ( junc == headTrails ) { + headTrails = junc->nextHead; + } + if ( junc->nextHead ) { + junc->nextHead->prevHead = junc->prevHead; + } + if ( junc->prevHead ) { + junc->prevHead->nextHead = junc->nextHead; + } + junc->nextHead = NULL; + junc->prevHead = NULL; + + // stick it in the free list + junc->prevGlobal = NULL; + junc->nextGlobal = freeTrails; + if ( freeTrails ) { + freeTrails->prevGlobal = junc; + } + freeTrails = junc; + + numTrailsInuse--; +} + +/* +=========== +CG_KillTrail +=========== +*/ +void CG_KillTrail( trailJunc_t *t ) { + trailJunc_t *next; + + next = t->nextJunc; + + // kill the trail here + t->nextJunc = NULL; + + if ( next ) { + CG_FreeTrailJunc( next ); + } +} + +/* +============== +CG_AddTrailToScene + + TODO: this can do with some major optimization +============== +*/ +static vec3_t vforward, vright, vup; + +void CG_AddTrailToScene( trailJunc_t *trail, int iteration, int numJuncs ) { + #define MAX_TRAIL_VERTS 2048 + polyVert_t verts[MAX_TRAIL_VERTS]; + polyVert_t outVerts[MAX_TRAIL_VERTS * 3]; + int k, i, n, l, numOutVerts; + polyVert_t mid; + float mod[4]; + float sInc = 0.0f, s = 0.0f; // TTimo: init + trailJunc_t *j, *jNext; + vec3_t fwd, up, p, v; + // clipping vars + #define TRAIL_FADE_CLOSE_DIST 64.0 + #define TRAIL_FADE_FAR_SCALE 4.0 + vec3_t viewProj; + float viewDist, fadeAlpha; + + // add spark shader at head position + if ( trail->flags & TJFL_SPARKHEADFLARE ) { + j = trail; + VectorCopy( j->pos, p ); + VectorMA( p, -j->width * 2, vup, p ); + VectorMA( p, -j->width * 2, vright, p ); + VectorCopy( p, verts[0].xyz ); + verts[0].st[0] = 0; + verts[0].st[1] = 0; + verts[0].modulate[0] = 255; + verts[0].modulate[1] = 255; + verts[0].modulate[2] = 255; + verts[0].modulate[3] = ( unsigned char )( j->alpha * 255.0 ); + + VectorCopy( j->pos, p ); + VectorMA( p, -j->width * 2, vup, p ); + VectorMA( p, j->width * 2, vright, p ); + VectorCopy( p, verts[1].xyz ); + verts[1].st[0] = 0; + verts[1].st[1] = 1; + verts[1].modulate[0] = 255; + verts[1].modulate[1] = 255; + verts[1].modulate[2] = 255; + verts[1].modulate[3] = ( unsigned char )( j->alpha * 255.0 ); + + VectorCopy( j->pos, p ); + VectorMA( p, j->width * 2, vup, p ); + VectorMA( p, j->width * 2, vright, p ); + VectorCopy( p, verts[2].xyz ); + verts[2].st[0] = 1; + verts[2].st[1] = 1; + verts[2].modulate[0] = 255; + verts[2].modulate[1] = 255; + verts[2].modulate[2] = 255; + verts[2].modulate[3] = ( unsigned char )( j->alpha * 255.0 ); + + VectorCopy( j->pos, p ); + VectorMA( p, j->width * 2, vup, p ); + VectorMA( p, -j->width * 2, vright, p ); + VectorCopy( p, verts[3].xyz ); + verts[3].st[0] = 1; + verts[3].st[1] = 0; + verts[3].modulate[0] = 255; + verts[3].modulate[1] = 255; + verts[3].modulate[2] = 255; + verts[3].modulate[3] = ( unsigned char )( j->alpha * 255.0 ); + + trap_R_AddPolyToScene( cgs.media.sparkFlareShader, 4, verts ); + } + +// if (trail->flags & TJFL_CROSSOVER && iteration < 1) { +// iteration = 1; +// } + + if ( !numJuncs ) { + // first count the number of juncs in the trail + j = trail; + numJuncs = 0; + sInc = 0; + while ( j ) { + numJuncs++; + + // check for a dead next junc + if ( !j->inuse && j->nextJunc && !j->nextJunc->inuse ) { + CG_KillTrail( j ); + } else if ( j->nextJunc && j->nextJunc->freed ) { + // not sure how this can happen, but it does, and causes infinite loops + j->nextJunc = NULL; + } + + if ( j->nextJunc ) { + sInc += VectorDistance( j->nextJunc->pos, j->pos ); + } + + j = j->nextJunc; + } + } + + if ( numJuncs < 2 ) { + return; + } + + if ( trail->sType == STYPE_STRETCH ) { + //sInc = ((1.0 - 0.1) / (float)(numJuncs)); // hack, the end of funnel shows a bit of the start (looping) + s = 0.05; + //s = 0.05; + } else if ( trail->sType == STYPE_REPEAT ) { + s = trail->sTex; + } + + // now traverse the list + j = trail; + jNext = j->nextJunc; + i = 0; + while ( jNext ) { + + // first get the directional vectors to the next junc + VectorSubtract( jNext->pos, j->pos, fwd ); + GetPerpendicularViewVector( cg.refdef.vieworg, j->pos, jNext->pos, up ); + + // if it's a crossover, draw it twice + if ( j->flags & TJFL_CROSSOVER ) { + if ( iteration > 0 ) { + ProjectPointOntoVector( cg.refdef.vieworg, j->pos, jNext->pos, viewProj ); + VectorSubtract( cg.refdef.vieworg, viewProj, v ); + VectorNormalize( v ); + + if ( iteration == 1 ) { + VectorMA( up, 0.3, v, up ); + } else { + VectorMA( up, -0.3, v, up ); + } + VectorNormalize( up ); + } + } + // do fading when moving towards the projection point onto the trail segment vector + else if ( !( j->flags & TJFL_NOCULL ) && ( j->widthEnd > 4 || jNext->widthEnd > 4 ) ) { + ProjectPointOntoVector( cg.refdef.vieworg, j->pos, jNext->pos, viewProj ); + viewDist = Distance( viewProj, cg.refdef.vieworg ); + if ( viewDist < ( TRAIL_FADE_CLOSE_DIST * TRAIL_FADE_FAR_SCALE ) ) { + if ( viewDist < TRAIL_FADE_CLOSE_DIST ) { + fadeAlpha = 0.0; + } else { + fadeAlpha = ( viewDist - TRAIL_FADE_CLOSE_DIST ) / ( TRAIL_FADE_CLOSE_DIST * TRAIL_FADE_FAR_SCALE ); + } + if ( fadeAlpha < j->alpha ) { + j->alpha = fadeAlpha; + } + if ( fadeAlpha < jNext->alpha ) { + jNext->alpha = fadeAlpha; + } + } + } + + // now output the QUAD for this segment + + // 1 ---- + VectorMA( j->pos, 0.5 * j->width, up, p ); + VectorCopy( p, verts[i].xyz ); + verts[i].st[0] = s; + verts[i].st[1] = 1.0; + for ( k = 0; k < 3; k++ ) + verts[i].modulate[k] = ( unsigned char )( j->color[k] * 255.0 ); + verts[i].modulate[3] = ( unsigned char )( j->alpha * 255.0 ); + + // blend this with the previous junc + if ( j != trail ) { + VectorAdd( verts[i].xyz, verts[i - 1].xyz, verts[i].xyz ); + VectorScale( verts[i].xyz, 0.5, verts[i].xyz ); + VectorCopy( verts[i].xyz, verts[i - 1].xyz ); + } else if ( j->flags & TJFL_FADEIN ) { + verts[i].modulate[3] = 0; // fade in + } + + i++; + + // 2 ---- + VectorMA( p, -1 * j->width, up, p ); + VectorCopy( p, verts[i].xyz ); + verts[i].st[0] = s; + verts[i].st[1] = 0.0; + for ( k = 0; k < 3; k++ ) + verts[i].modulate[k] = ( unsigned char )( j->color[k] * 255.0 ); + verts[i].modulate[3] = ( unsigned char )( j->alpha * 255.0 ); + + // blend this with the previous junc + if ( j != trail ) { + VectorAdd( verts[i].xyz, verts[i - 3].xyz, verts[i].xyz ); + VectorScale( verts[i].xyz, 0.5, verts[i].xyz ); + VectorCopy( verts[i].xyz, verts[i - 3].xyz ); + } else if ( j->flags & TJFL_FADEIN ) { + verts[i].modulate[3] = 0; // fade in + } + + i++; + + if ( trail->sType == STYPE_REPEAT ) { + s = jNext->sTex; + } else { + //s += sInc; + s += VectorDistance( j->pos, jNext->pos ) / sInc; + if ( s > 1.0 ) { + s = 1.0; + } + } + + // 3 ---- + VectorMA( jNext->pos, -0.5 * jNext->width, up, p ); + VectorCopy( p, verts[i].xyz ); + verts[i].st[0] = s; + verts[i].st[1] = 0.0; + for ( k = 0; k < 3; k++ ) + verts[i].modulate[k] = ( unsigned char )( jNext->color[k] * 255.0 ); + verts[i].modulate[3] = ( unsigned char )( jNext->alpha * 255.0 ); + i++; + + // 4 ---- + VectorMA( p, jNext->width, up, p ); + VectorCopy( p, verts[i].xyz ); + verts[i].st[0] = s; + verts[i].st[1] = 1.0; + for ( k = 0; k < 3; k++ ) + verts[i].modulate[k] = ( unsigned char )( jNext->color[k] * 255.0 ); + verts[i].modulate[3] = ( unsigned char )( jNext->alpha * 255.0 ); + i++; + + if ( i + 4 > MAX_TRAIL_VERTS ) { + break; + } + + j = jNext; + jNext = j->nextJunc; + } + + if ( trail->flags & TJFL_FIXDISTORT ) { + // build the list of outVerts, by dividing up the QUAD's into 4 Tri's each, so as to allow + // any shaped (convex) Quad without bilinear distortion + for ( k = 0, numOutVerts = 0; k < i; k += 4 ) { + VectorCopy( verts[k].xyz, mid.xyz ); + mid.st[0] = verts[k].st[0]; + mid.st[1] = verts[k].st[1]; + for ( l = 0; l < 4; l++ ) { + mod[l] = (float)verts[k].modulate[l]; + } + for ( n = 1; n < 4; n++ ) { + VectorAdd( verts[k + n].xyz, mid.xyz, mid.xyz ); + mid.st[0] += verts[k + n].st[0]; + mid.st[1] += verts[k + n].st[1]; + for ( l = 0; l < 4; l++ ) { + mod[l] += (float)verts[k + n].modulate[l]; + } + } + VectorScale( mid.xyz, 0.25, mid.xyz ); + mid.st[0] *= 0.25; + mid.st[1] *= 0.25; + for ( l = 0; l < 4; l++ ) { + mid.modulate[l] = ( unsigned char )( mod[l] / 4.0 ); + } + + // now output the tri's + for ( n = 0; n < 4; n++ ) { + outVerts[numOutVerts++] = verts[k + n]; + outVerts[numOutVerts++] = mid; + if ( n < 3 ) { + outVerts[numOutVerts++] = verts[k + n + 1]; + } else { + outVerts[numOutVerts++] = verts[k]; + } + } + + } + + if ( !( trail->flags & TJFL_NOPOLYMERGE ) ) { + trap_R_AddPolysToScene( trail->shader, 3, &outVerts[0], numOutVerts / 3 ); + } else { + int k; + for ( k = 0; k < numOutVerts / 3; k++ ) { + trap_R_AddPolyToScene( trail->shader, 3, &outVerts[k * 3] ); + } + } + } else + { + // send the polygons + // FIXME: is it possible to send a GL_STRIP here? We are actually sending 2x the verts we really need to + if ( !( trail->flags & TJFL_NOPOLYMERGE ) ) { + trap_R_AddPolysToScene( trail->shader, 4, &verts[0], i / 4 ); + } else { + int k; + for ( k = 0; k < i / 4; k++ ) { + trap_R_AddPolyToScene( trail->shader, 4, &verts[k * 4] ); + } + } + } + + // do we need to make another pass? + if ( trail->flags & TJFL_CROSSOVER ) { + if ( iteration < 2 ) { + CG_AddTrailToScene( trail, iteration + 1, numJuncs ); + } + } + +} + +/* +=============== +CG_AddTrails +=============== +*/ +void CG_AddTrails( void ) { + float lifeFrac; + trailJunc_t *j, *jNext; + + if ( !initTrails ) { + CG_ClearTrails(); + } + + //AngleVectors( cg.snap->ps.viewangles, vforward, vright, vup ); + VectorCopy( cg.refdef.viewaxis[0], vforward ); + VectorCopy( cg.refdef.viewaxis[1], vright ); + VectorCopy( cg.refdef.viewaxis[2], vup ); + + // update the settings for each junc + j = activeTrails; + while ( j ) { + lifeFrac = (float)( cg.time - j->spawnTime ) / (float)( j->endTime - j->spawnTime ); + if ( lifeFrac >= 1.0 ) { + j->inuse = qfalse; // flag it as dead + j->width = j->widthEnd; + j->alpha = j->alphaEnd; + if ( j->alpha > 1.0 ) { + j->alpha = 1.0; + } else if ( j->alpha < 0.0 ) { + j->alpha = 0.0; + } + VectorCopy( j->colorEnd, j->color ); + } else { + j->width = j->widthStart + ( j->widthEnd - j->widthStart ) * lifeFrac; + j->alpha = j->alphaStart + ( j->alphaEnd - j->alphaStart ) * lifeFrac; + if ( j->alpha > 1.0 ) { + j->alpha = 1.0; + } else if ( j->alpha < 0.0 ) { + j->alpha = 0.0; + } + VectorSubtract( j->colorEnd, j->colorStart, j->color ); + VectorMA( j->colorStart, lifeFrac, j->color, j->color ); + } + + j = j->nextGlobal; + } + + // draw the trailHeads + j = headTrails; + while ( j ) { + jNext = j->nextHead; // in case it gets removed + if ( !j->inuse ) { + CG_FreeTrailJunc( j ); + } else { + CG_AddTrailToScene( j, 0, 0 ); + } + j = jNext; + } +} diff --git a/Projects/Android/jni/rtcw/src/cgame/cg_view.c b/Projects/Android/jni/rtcw/src/cgame/cg_view.c new file mode 100644 index 0000000..5c1a913 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/cgame/cg_view.c @@ -0,0 +1,1660 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +// cg_view.c -- setup all the parameters (position, angle, etc) +// for a 3D rendering +#include "cg_local.h" + +//======================== +extern int notebookModel; +//======================== + +/* +============================================================================= + + MODEL TESTING + +The viewthing and gun positioning tools from Q2 have been integrated and +enhanced into a single model testing facility. + +Model viewing can begin with either "testmodel " or "testgun ". + +The names must be the full pathname after the basedir, like +"models/weapons/v_launch/tris.md3" or "players/male/tris.md3" + +Testmodel will create a fake entity 100 units in front of the current view +position, directly facing the viewer. It will remain immobile, so you can +move around it to view it from different angles. + +Testgun will cause the model to follow the player around and supress the real +view weapon model. The default frame 0 of most guns is completely off screen, +so you will probably have to cycle a couple frames to see it. + +"nextframe", "prevframe", "nextskin", and "prevskin" commands will change the +frame or skin of the testmodel. These are bound to F5, F6, F7, and F8 in +q3default.cfg. + +If a gun is being tested, the "gun_x", "gun_y", and "gun_z" variables will let +you adjust the positioning. + +Note that none of the model testing features update while the game is paused, so +it may be convenient to test with deathmatch set to 1 so that bringing down the +console doesn't pause the game. + +============================================================================= +*/ + +/* +================= +CG_TestModel_f + +Creates an entity in front of the current position, which +can then be moved around +================= +*/ +void CG_TestModel_f( void ) { + vec3_t angles; + + memset( &cg.testModelEntity, 0, sizeof( cg.testModelEntity ) ); + if ( trap_Argc() < 2 ) { + return; + } + + Q_strncpyz( cg.testModelName, CG_Argv( 1 ), MAX_QPATH ); + cg.testModelEntity.hModel = trap_R_RegisterModel( cg.testModelName ); + + if ( trap_Argc() == 3 ) { + cg.testModelEntity.backlerp = atof( CG_Argv( 2 ) ); + cg.testModelEntity.frame = 1; + cg.testModelEntity.oldframe = 0; + } + if ( !cg.testModelEntity.hModel ) { + CG_Printf( "Can't register model\n" ); + return; + } + + VectorMA( cg.refdef.vieworg, 100, cg.refdef.viewaxis[0], cg.testModelEntity.origin ); + + angles[PITCH] = 0; + angles[YAW] = 180 + cg.refdefViewAngles[1]; + angles[ROLL] = 0; + + AnglesToAxis( angles, cg.testModelEntity.axis ); + cg.testGun = qfalse; +} + +/* +================= +CG_TestGun_f + +Replaces the current view weapon with the given model +================= +*/ +void CG_TestGun_f( void ) { + CG_TestModel_f(); + cg.testGun = qtrue; + cg.testModelEntity.renderfx = RF_MINLIGHT | RF_DEPTHHACK | RF_FIRST_PERSON; +} + + +void CG_TestModelNextFrame_f( void ) { + cg.testModelEntity.frame++; + CG_Printf( "frame %i\n", cg.testModelEntity.frame ); +} + +void CG_TestModelPrevFrame_f( void ) { + cg.testModelEntity.frame--; + if ( cg.testModelEntity.frame < 0 ) { + cg.testModelEntity.frame = 0; + } + CG_Printf( "frame %i\n", cg.testModelEntity.frame ); +} + +void CG_TestModelNextSkin_f( void ) { + cg.testModelEntity.skinNum++; + CG_Printf( "skin %i\n", cg.testModelEntity.skinNum ); +} + +void CG_TestModelPrevSkin_f( void ) { + cg.testModelEntity.skinNum--; + if ( cg.testModelEntity.skinNum < 0 ) { + cg.testModelEntity.skinNum = 0; + } + CG_Printf( "skin %i\n", cg.testModelEntity.skinNum ); +} + +static void CG_AddTestModel( void ) { + int i; + + // re-register the model, because the level may have changed + cg.testModelEntity.hModel = trap_R_RegisterModel( cg.testModelName ); + if ( !cg.testModelEntity.hModel ) { + CG_Printf( "Can't register model\n" ); + return; + } + + // if testing a gun, set the origin reletive to the view origin + if ( cg.testGun ) { + VectorCopy( cg.refdef.vieworg, cg.testModelEntity.origin ); + VectorCopy( cg.refdef.viewaxis[0], cg.testModelEntity.axis[0] ); + VectorCopy( cg.refdef.viewaxis[1], cg.testModelEntity.axis[1] ); + VectorCopy( cg.refdef.viewaxis[2], cg.testModelEntity.axis[2] ); + + // allow the position to be adjusted + for ( i = 0 ; i < 3 ; i++ ) { + cg.testModelEntity.origin[i] += cg.refdef.viewaxis[0][i] * cg_gun_x.value; + cg.testModelEntity.origin[i] += cg.refdef.viewaxis[1][i] * cg_gun_y.value; + cg.testModelEntity.origin[i] += cg.refdef.viewaxis[2][i] * cg_gun_z.value; + } + } + + trap_R_AddRefEntityToScene( &cg.testModelEntity ); +} + + + +//============================================================================ + + +/* +================= +CG_CalcVrect + +Sets the coordinates of the rendered window +================= +*/ +// TTimo: unused +//static float letterbox_frac = 1.0f; // used for transitioning to letterbox for cutscenes // TODO: add to cg. + +static void CG_CalcVrect( void ) { + int xsize, ysize; + float lbheight, lbdiff; + + // NERVE - SMF + if ( cg.limboMenu ) { + float x, y, w, h; + x = LIMBO_3D_X; + y = LIMBO_3D_Y; + w = LIMBO_3D_W; + h = LIMBO_3D_H; + + cg.refdef.width = 0; + CG_AdjustFrom640( &x, &y, &w, &h ); + + cg.refdef.x = x; + cg.refdef.y = y; + cg.refdef.width = w; + cg.refdef.height = h; + return; + } + // -NERVE - SMF + + // the intermission should allways be full screen + if ( cg.snap->ps.pm_type == PM_INTERMISSION ) { + xsize = ysize = 100; + } else { + // bound normal viewsize + if ( cg_viewsize.integer < 30 ) { + trap_Cvar_Set( "cg_viewsize","30" ); + xsize = ysize = 30; + } else if ( cg_viewsize.integer > 100 ) { + trap_Cvar_Set( "cg_viewsize","100" ); + xsize = ysize = 100; + } else { + xsize = ysize = cg_viewsize.integer; + } + } + +//----(SA) added transition to/from letterbox +// normal aspect is xx:xx +// letterbox is yy:yy (85% of 'normal' height) + + lbheight = ysize * 0.85; + lbdiff = ysize - lbheight; + + if ( cg_letterbox.integer ) { + ysize = lbheight; +// if(letterbox_frac != 0) { +// letterbox_frac -= 0.01f; // (SA) TODO: make non fps dependant +// if(letterbox_frac < 0) +// letterbox_frac = 0; +// ysize += (lbdiff * letterbox_frac); +// } +// } else { +// if(letterbox_frac != 1) { +// letterbox_frac += 0.01f; // (SA) TODO: make non fps dependant +// if(letterbox_frac > 1) +// letterbox_frac = 1; +// ysize = lbheight + (lbdiff * letterbox_frac); +// } + } +//----(SA) end + + + cg.refdef.width = cgs.glconfig.vidWidth * xsize / 100; + cg.refdef.width &= ~1; + + cg.refdef.height = cgs.glconfig.vidHeight * ysize / 100; + cg.refdef.height &= ~1; + + cg.refdef.x = ( cgs.glconfig.vidWidth - cg.refdef.width ) / 2; + cg.refdef.y = ( cgs.glconfig.vidHeight - cg.refdef.height ) / 2; +} + +//============================================================================== + + +/* +=============== +CG_OffsetThirdPersonView + +=============== +*/ +#define FOCUS_DISTANCE 512 +static void CG_OffsetThirdPersonView( void ) { + vec3_t forward, right, up; + vec3_t view; + vec3_t focusAngles; + trace_t trace; + static vec3_t mins = { -4, -4, -4 }; + static vec3_t maxs = { 4, 4, 4 }; + vec3_t focusPoint; + float focusDist; + float forwardScale, sideScale; + + cg.refdef.vieworg[2] += cg.predictedPlayerState.viewheight; + + VectorCopy( cg.refdefViewAngles, focusAngles ); + + // if dead, look at killer + if ( cg.predictedPlayerState.stats[STAT_HEALTH] <= 0 ) { + focusAngles[YAW] = cg.predictedPlayerState.stats[STAT_DEAD_YAW]; + cg.refdefViewAngles[YAW] = cg.predictedPlayerState.stats[STAT_DEAD_YAW]; + } + + if ( focusAngles[PITCH] > 45 ) { + focusAngles[PITCH] = 45; // don't go too far overhead + } + AngleVectors( focusAngles, forward, NULL, NULL ); + + VectorMA( cg.refdef.vieworg, FOCUS_DISTANCE, forward, focusPoint ); + + VectorCopy( cg.refdef.vieworg, view ); + + view[2] += 8; + + cg.refdefViewAngles[PITCH] *= 0.5; + + AngleVectors( cg.refdefViewAngles, forward, right, up ); + + forwardScale = cos( cg_thirdPersonAngle.value / 180 * M_PI ); + sideScale = sin( cg_thirdPersonAngle.value / 180 * M_PI ); + VectorMA( view, -cg_thirdPersonRange.value * forwardScale, forward, view ); + VectorMA( view, -cg_thirdPersonRange.value * sideScale, right, view ); + + // trace a ray from the origin to the viewpoint to make sure the view isn't + // in a solid block. Use an 8 by 8 block to prevent the view from near clipping anything + + CG_Trace( &trace, cg.refdef.vieworg, mins, maxs, view, cg.predictedPlayerState.clientNum, MASK_SOLID ); + + if ( trace.fraction != 1.0 ) { + VectorCopy( trace.endpos, view ); + view[2] += ( 1.0 - trace.fraction ) * 32; + // try another trace to this position, because a tunnel may have the ceiling + // close enogh that this is poking out + + CG_Trace( &trace, cg.refdef.vieworg, mins, maxs, view, cg.predictedPlayerState.clientNum, MASK_SOLID ); + VectorCopy( trace.endpos, view ); + } + + + VectorCopy( view, cg.refdef.vieworg ); + + // select pitch to look at focus point from vieword + VectorSubtract( focusPoint, cg.refdef.vieworg, focusPoint ); + focusDist = sqrt( focusPoint[0] * focusPoint[0] + focusPoint[1] * focusPoint[1] ); + if ( focusDist < 1 ) { + focusDist = 1; // should never happen + } + cg.refdefViewAngles[PITCH] = -180 / M_PI * atan2( focusPoint[2], focusDist ); + cg.refdefViewAngles[YAW] -= cg_thirdPersonAngle.value; +} + + +// this causes a compiler bug on mac MrC compiler +static void CG_StepOffset( void ) { + int timeDelta; + + // smooth out stair climbing + timeDelta = cg.time - cg.stepTime; + // Ridah + if ( timeDelta < 0 ) { + cg.stepTime = cg.time; + } + if ( timeDelta < STEP_TIME ) { + cg.refdef.vieworg[2] -= cg.stepChange + * ( STEP_TIME - timeDelta ) / STEP_TIME; + } +} + +/* +================ +CG_KickAngles +================ +*/ +void CG_KickAngles( void ) { + const vec3_t centerSpeed = {2400, 2400, 2400}; + const float recoilCenterSpeed = 200; + const float recoilIgnoreCutoff = 15; + const float recoilMaxSpeed = 50; + const vec3_t maxKickAngles = {10,10,10}; + float idealCenterSpeed, kickChange; + int i, frametime, t; + float ft; + #define STEP 20 + + // this code is frametime-dependant, so split it up into small chunks + //cg.kickAngles[PITCH] = 0; + cg.recoilPitchAngle = 0; + for ( t = cg.frametime; t > 0; t -= STEP ) { + if ( t > STEP ) { + frametime = STEP; + } else { + frametime = t; + } + + ft = ( (float)frametime / 1000 ); + + // kickAngles is spring-centered + for ( i = 0; i < 3; i++ ) { + if ( cg.kickAVel[i] || cg.kickAngles[i] ) { + // apply centering forces to kickAvel + if ( cg.kickAngles[i] && frametime ) { + idealCenterSpeed = -( 2.0 * ( cg.kickAngles[i] > 0 ) - 1.0 ) * centerSpeed[i]; + if ( idealCenterSpeed ) { + cg.kickAVel[i] += idealCenterSpeed * ft; + } + } + // add the kickAVel to the kickAngles + kickChange = cg.kickAVel[i] * ft; + if ( cg.kickAngles[i] && ( cg.kickAngles[i] < 0 ) != ( kickChange < 0 ) ) { // slower when returning to center + kickChange *= 0.06; + } + // check for crossing back over the center point + if ( !cg.kickAngles[i] || ( ( cg.kickAngles[i] + kickChange ) < 0 ) == ( cg.kickAngles[i] < 0 ) ) { + cg.kickAngles[i] += kickChange; + if ( !cg.kickAngles[i] && frametime ) { + cg.kickAVel[i] = 0; + } else if ( fabs( cg.kickAngles[i] ) > maxKickAngles[i] ) { + cg.kickAngles[i] = maxKickAngles[i] * ( ( 2 * ( cg.kickAngles[i] > 0 ) ) - 1 ); + cg.kickAVel[i] = 0; // force Avel to return us to center rather than keep going outside range + } + } else { // about to cross, so just zero it out + cg.kickAngles[i] = 0; + cg.kickAVel[i] = 0; + } + } + } + + // recoil is added to input viewangles per frame + if ( cg.recoilPitch ) { + // apply max recoil + if ( fabs( cg.recoilPitch ) > recoilMaxSpeed ) { + if ( cg.recoilPitch > 0 ) { + cg.recoilPitch = recoilMaxSpeed; + } else { + cg.recoilPitch = -recoilMaxSpeed; + } + } + // apply centering forces to kickAvel + if ( frametime ) { + idealCenterSpeed = -( 2.0 * ( cg.recoilPitch > 0 ) - 1.0 ) * recoilCenterSpeed * ft; + if ( idealCenterSpeed ) { + if ( fabs( idealCenterSpeed ) < fabs( cg.recoilPitch ) ) { + cg.recoilPitch += idealCenterSpeed; + } else { // back zero out + cg.recoilPitch = 0; + } + } + } + } + if ( fabs( cg.recoilPitch ) > recoilIgnoreCutoff ) { + cg.recoilPitchAngle += cg.recoilPitch * ft; + } + } + // encode the kick angles into a 24bit number, for sending to the client exe +//----(SA) commented out since it doesn't appear to be used, and it spams the console when in "developer 1" +// trap_Cvar_Set( "cg_recoilPitch", va("%f", cg.recoilPitchAngle) ); +} + + +/* +CG_Concussive +*/ +void CG_Concussive( centity_t *cent ) { + float length; +// vec3_t dir, forward; + vec3_t vec; +// float dot; + + // + float pitchRecoilAdd, pitchAdd; + float yawRandom; + vec3_t recoil; + // + + if ( !cg.renderingThirdPerson && cent->currentState.density == cg.snap->ps.clientNum ) { + // + pitchRecoilAdd = 0; + pitchAdd = 0; + yawRandom = 0; + // + + VectorSubtract( cg.snap->ps.origin, cent->currentState.origin, vec ); + length = VectorLength( vec ); + + // pitchAdd = 12+rand()%3; + // yawRandom = 6; + + if ( length > 1024 ) { + return; + } + + pitchAdd = ( 32 / length ) * 64; + yawRandom = ( 32 / length ) * 64; + + // recoil[YAW] = crandom()*yawRandom; + if ( rand() % 100 > 50 ) { + recoil[YAW] = -yawRandom; + } else { + recoil[YAW] = yawRandom; + } + + recoil[ROLL] = -recoil[YAW]; // why not + recoil[PITCH] = -pitchAdd; + // scale it up a bit (easier to modify this while tweaking) + VectorScale( recoil, 30, recoil ); + // set the recoil + VectorCopy( recoil, cg.kickAVel ); + // set the recoil + cg.recoilPitch -= pitchRecoilAdd; + + } +} + + +/* +============== +CG_ZoomSway + sway for scoped weapons. + this takes aimspread into account so the view settles after a bit +============== +*/ +static void CG_ZoomSway( void ) { + float spreadfrac; + float phase; + + if ( !cg.zoomval ) { // not zoomed + return; + } + + if ( cg.snap->ps.eFlags & EF_MG42_ACTIVE ) { // don't draw when on mg_42 + return; + } + + spreadfrac = (float)cg.snap->ps.aimSpreadScale / 255.0; + + phase = cg.time / 1000.0 * ZOOM_PITCH_FREQUENCY * M_PI * 2; + cg.refdefViewAngles[PITCH] += ZOOM_PITCH_AMPLITUDE * sin( phase ) * ( spreadfrac + ZOOM_PITCH_MIN_AMPLITUDE ); + + phase = cg.time / 1000.0 * ZOOM_YAW_FREQUENCY * M_PI * 2; + cg.refdefViewAngles[YAW] += ZOOM_YAW_AMPLITUDE * sin( phase ) * ( spreadfrac + ZOOM_YAW_MIN_AMPLITUDE ); + +} + + + +/* +=============== +CG_OffsetFirstPersonView + +=============== +*/ +static void CG_OffsetFirstPersonView( void ) { + float *origin; + float *angles; + float bob; + float ratio; + float delta; + float speed; + float f; + vec3_t predictedVelocity; + int timeDelta; + + if ( cg.snap->ps.pm_type == PM_INTERMISSION ) { + return; + } + + origin = cg.refdef.vieworg; + angles = cg.refdefViewAngles; + + // if dead, fix the angle and don't add any kick + if ( cg.snap->ps.stats[STAT_HEALTH] <= 0 ) { + angles[ROLL] = 40; + angles[PITCH] = -15; + angles[YAW] = cg.snap->ps.stats[STAT_DEAD_YAW]; + origin[2] += cg.predictedPlayerState.viewheight; + return; + } + + // add angles based on weapon kick + VectorAdd( angles, cg.kick_angles, angles ); + + // RF, add new weapon kick angles + CG_KickAngles(); + VectorAdd( angles, cg.kickAngles, angles ); + // RF, pitch is already added + //angles[0] -= cg.kickAngles[PITCH]; + + // add angles based on damage kick + if ( cg.damageTime ) { + ratio = cg.time - cg.damageTime; + if ( ratio < DAMAGE_DEFLECT_TIME ) { + ratio /= DAMAGE_DEFLECT_TIME; + angles[PITCH] += ratio * cg.v_dmg_pitch; + angles[ROLL] += ratio * cg.v_dmg_roll; + } else { + ratio = 1.0 - ( ratio - DAMAGE_DEFLECT_TIME ) / DAMAGE_RETURN_TIME; + if ( ratio > 0 ) { + angles[PITCH] += ratio * cg.v_dmg_pitch; + angles[ROLL] += ratio * cg.v_dmg_roll; + } + } + } + + // add pitch based on fall kick +#if 0 + ratio = ( cg.time - cg.landTime ) / FALL_TIME; + if ( ratio < 0 ) { + ratio = 0; + } + angles[PITCH] += ratio * cg.fall_value; +#endif + + // add angles based on velocity + VectorCopy( cg.predictedPlayerState.velocity, predictedVelocity ); + + delta = DotProduct( predictedVelocity, cg.refdef.viewaxis[0] ); + angles[PITCH] += delta * cg_runpitch.value; + + delta = DotProduct( predictedVelocity, cg.refdef.viewaxis[1] ); + angles[ROLL] -= delta * cg_runroll.value; + + // add angles based on bob + + // make sure the bob is visible even at low speeds + speed = cg.xyspeed > 200 ? cg.xyspeed : 200; + + delta = cg.bobfracsin * cg_bobpitch.value * speed; + if ( cg.predictedPlayerState.pm_flags & PMF_DUCKED ) { + delta *= 3; // crouching + } + angles[PITCH] += delta; + delta = cg.bobfracsin * cg_bobroll.value * speed; + if ( cg.predictedPlayerState.pm_flags & PMF_DUCKED ) { + delta *= 3; // crouching accentuates roll + } + if ( cg.bobcycle & 1 ) { + delta = -delta; + } + angles[ROLL] += delta; + +//=================================== + + // add view height + origin[2] += cg.predictedPlayerState.viewheight; + + // smooth out duck height changes + timeDelta = cg.time - cg.duckTime; + if ( timeDelta < 0 ) { // Ridah + cg.duckTime = cg.time - DUCK_TIME; + } + if ( timeDelta < DUCK_TIME ) { + cg.refdef.vieworg[2] -= cg.duckChange + * ( DUCK_TIME - timeDelta ) / DUCK_TIME; + } + + // add bob height + bob = cg.bobfracsin * cg.xyspeed * cg_bobup.value; + if ( bob > 6 ) { + bob = 6; + } + + origin[2] += bob; + + + // add fall height + delta = cg.time - cg.landTime; + if ( delta < 0 ) { // Ridah + cg.landTime = cg.time - ( LAND_DEFLECT_TIME + LAND_RETURN_TIME ); + } + if ( delta < LAND_DEFLECT_TIME ) { + f = delta / LAND_DEFLECT_TIME; + cg.refdef.vieworg[2] += cg.landChange * f; + } else if ( delta < LAND_DEFLECT_TIME + LAND_RETURN_TIME ) { + delta -= LAND_DEFLECT_TIME; + f = 1.0 - ( delta / LAND_RETURN_TIME ); + cg.refdef.vieworg[2] += cg.landChange * f; + } + + // add step offset + CG_StepOffset(); + + CG_ZoomSway(); + + // adjust for 'lean' + if ( cg.predictedPlayerState.leanf != 0 ) { + //add leaning offset + vec3_t right; + cg.refdefViewAngles[2] += cg.predictedPlayerState.leanf / 2.0f; + AngleVectors( cg.refdefViewAngles, NULL, right, NULL ); + VectorMA( cg.refdef.vieworg, cg.predictedPlayerState.leanf, right, cg.refdef.vieworg ); + } + + // add kick offset + + VectorAdd( origin, cg.kick_origin, origin ); + + // pivot the eye based on a neck length +#if 0 + { +#define NECK_LENGTH 8 + vec3_t forward, up; + + cg.refdef.vieworg[2] -= NECK_LENGTH; + AngleVectors( cg.refdefViewAngles, forward, NULL, up ); + VectorMA( cg.refdef.vieworg, 3, forward, cg.refdef.vieworg ); + VectorMA( cg.refdef.vieworg, NECK_LENGTH, up, cg.refdef.vieworg ); + } +#endif +} + +//====================================================================== + +// +// Zoom controls +// + + +// probably move to server variables +float zoomTable[ZOOM_MAX_ZOOMS][2] = { +// max {out,in} + {0, 0}, + + {36, 8}, // binoc + {20, 4}, // sniper + {60, 20}, // snooper + {55, 55}, // fg42 + {55, 55} // mg42 +}; + +void CG_AdjustZoomVal( float val, int type ) { + cg.zoomval += val; + if ( cg.zoomval > zoomTable[type][ZOOM_OUT] ) { + cg.zoomval = zoomTable[type][ZOOM_OUT]; + } + if ( cg.zoomval < zoomTable[type][ZOOM_IN] ) { + cg.zoomval = zoomTable[type][ZOOM_IN]; + } +} + +void CG_ZoomIn_f( void ) { + if ( cg_entities[cg.snap->ps.clientNum].currentState.weapon == WP_SNIPERRIFLE ) { + CG_AdjustZoomVal( -( cg_zoomStepSniper.value ), ZOOM_SNIPER ); + } else if ( cg_entities[cg.snap->ps.clientNum].currentState.weapon == WP_SNOOPERSCOPE ) { + CG_AdjustZoomVal( -( cg_zoomStepSnooper.value ), ZOOM_SNOOPER ); + } else if ( cg_entities[cg.snap->ps.clientNum].currentState.weapon == WP_FG42SCOPE ) { + CG_AdjustZoomVal( -( cg_zoomStepSnooper.value ), ZOOM_FG42SCOPE ); + } else if ( cg.zoomedBinoc ) { + CG_AdjustZoomVal( -( cg_zoomStepBinoc.value ), ZOOM_BINOC ); + } +} + +void CG_ZoomOut_f( void ) { + if ( cg_entities[cg.snap->ps.clientNum].currentState.weapon == WP_SNIPERRIFLE ) { + CG_AdjustZoomVal( cg_zoomStepSniper.value, ZOOM_SNIPER ); + } else if ( cg_entities[cg.snap->ps.clientNum].currentState.weapon == WP_SNOOPERSCOPE ) { + CG_AdjustZoomVal( cg_zoomStepSnooper.value, ZOOM_SNOOPER ); + } else if ( cg_entities[cg.snap->ps.clientNum].currentState.weapon == WP_FG42SCOPE ) { + CG_AdjustZoomVal( cg_zoomStepSnooper.value, ZOOM_FG42SCOPE ); + } else if ( cg.zoomedBinoc ) { + CG_AdjustZoomVal( cg_zoomStepBinoc.value, ZOOM_BINOC ); + } +} + + +/* +============== +CG_Zoom +============== +*/ +void CG_Zoom( void ) { + if ( cg.predictedPlayerState.eFlags & EF_ZOOMING ) { + if ( cg.zoomedBinoc ) { + return; + } + cg.zoomedBinoc = qtrue; + cg.zoomTime = cg.time; + cg.zoomval = cg_zoomDefaultBinoc.value; + } else { + if ( !cg.zoomedBinoc ) { + return; + } + cg.zoomedBinoc = qfalse; + cg.zoomTime = cg.time; + + // check for scope wepon in use, and switch to if necessary + if ( cg.predictedPlayerState.weapon == WP_SNOOPERSCOPE ) { + cg.zoomval = cg_zoomDefaultSnooper.value; + } else if ( cg.predictedPlayerState.weapon == WP_SNIPERRIFLE ) { + cg.zoomval = cg_zoomDefaultSniper.value; + } else if ( cg.predictedPlayerState.weapon == WP_FG42SCOPE ) { + cg.zoomval = cg_zoomDefaultFG.value; + } else { + cg.zoomval = 0; + } + } +} + + +/* +==================== +CG_CalcFov + +Fixed fov at intermissions, otherwise account for fov variable and zooms. +==================== +*/ +#define WAVE_AMPLITUDE 1 +#define WAVE_FREQUENCY 0.4 + +static int CG_CalcFov( void ) { + static float lastfov = 90; // for transitions back from zoomed in modes + float x; + float phase; + float v; + int contents; + float fov_x, fov_y; + float zoomFov; + float f; + int inwater; + qboolean dead; + + CG_Zoom(); + + if ( cg.predictedPlayerState.stats[STAT_HEALTH] <= 0 ) { + dead = qtrue; + cg.zoomedBinoc = qfalse; + cg.zoomTime = 0; + cg.zoomval = 0; + } else { + dead = qfalse; + } + + if ( cg.predictedPlayerState.pm_type == PM_INTERMISSION ) { + // if in intermission, use a fixed value + fov_x = 90; + } else { + // user selectable + if ( cgs.dmflags & DF_FIXED_FOV ) { + // dmflag to prevent wide fov for all clients + fov_x = 90; + } else { + fov_x = cg_fov.value; + if ( fov_x < 1 ) { + fov_x = 1; + } else if ( fov_x > 160 ) { + fov_x = 160; + } + } + + // account for zooms + if ( cg.zoomval ) { + zoomFov = cg.zoomval; // (SA) use user scrolled amount + + if ( zoomFov < 1 ) { + zoomFov = 1; + } else if ( zoomFov > 160 ) { + zoomFov = 160; + } + } else { + zoomFov = lastfov; + } + + // do smooth transitions for the binocs + if ( cg.zoomedBinoc ) { // binoc zooming in + f = ( cg.time - cg.zoomTime ) / (float)ZOOM_TIME; + if ( f > 1.0 ) { + fov_x = zoomFov; + } else { + fov_x = fov_x + f * ( zoomFov - fov_x ); + } + lastfov = fov_x; + } else if ( cg.zoomval ) { // zoomed by sniper/snooper + fov_x = cg.zoomval; + lastfov = fov_x; + } else { // binoc zooming out + f = ( cg.time - cg.zoomTime ) / (float)ZOOM_TIME; + if ( f > 1.0 ) { + fov_x = fov_x; + } else { + fov_x = zoomFov + f * ( fov_x - zoomFov ); + } + } + } + + // DHM - Nerve :: zoom in for Limbo or Spectator + if ( cgs.gametype == GT_WOLF ) { + if ( cg.snap->ps.pm_flags & PMF_FOLLOW && cg.snap->ps.weapon == WP_SNIPERRIFLE ) { + fov_x = cg_zoomDefaultSniper.value; + } + } + // dhm - end + + if ( !dead && ( cg.weaponSelect == WP_SNOOPERSCOPE ) ) { + cg.refdef.rdflags |= RDF_SNOOPERVIEW; + } else { + cg.refdef.rdflags &= ~RDF_SNOOPERVIEW; + } + + + if ( cg.snap->ps.persistant[PERS_HWEAPON_USE] ) { + fov_x = 55; + } + + x = cg.refdef.width / tan( fov_x / 360 * M_PI ); + fov_y = atan2( cg.refdef.height, x ); + fov_y = fov_y * 360 / M_PI; + + // warp if underwater + contents = CG_PointContents( cg.refdef.vieworg, -1 ); + if ( contents & ( CONTENTS_WATER | CONTENTS_SLIME | CONTENTS_LAVA ) ) { + phase = cg.time / 1000.0 * WAVE_FREQUENCY * M_PI * 2; + v = WAVE_AMPLITUDE * sin( phase ); + fov_x += v; + fov_y -= v; + inwater = qtrue; + cg.refdef.rdflags |= RDF_UNDERWATER; + } else { + cg.refdef.rdflags &= ~RDF_UNDERWATER; + inwater = qfalse; + } + + contents = CG_PointContents( cg.refdef.vieworg, -1 ); + if ( contents & ( CONTENTS_WATER | CONTENTS_SLIME | CONTENTS_LAVA ) ) { + cg.refdef.rdflags |= RDF_UNDERWATER; + } else { + cg.refdef.rdflags &= ~RDF_UNDERWATER; + } + + // set it + cg.refdef.fov_x = fov_x; + cg.refdef.fov_y = fov_y; + + if ( !cg.zoomedBinoc ) { + // NERVE - SMF - fix for zoomed in/out movement bug + if ( cg.zoomval ) { + if ( cg.snap->ps.weapon == WP_SNOOPERSCOPE ) { + cg.zoomSensitivity = 0.3f * ( cg.zoomval / 90.f ); // NERVE - SMF - changed to get less sensitive as you zoom in; + } +// cg.zoomSensitivity = 0.2; + else { + cg.zoomSensitivity = 0.6 * ( cg.zoomval / 90.f ); // NERVE - SMF - changed to get less sensitive as you zoom in + } +// cg.zoomSensitivity = 0.1; + } else { + cg.zoomSensitivity = 1; + } + // -NERVE - SMF + } else { + cg.zoomSensitivity = cg.refdef.fov_y / 75.0; + } + + return inwater; +} + + +/* +============== +CG_UnderwaterSounds +============== +*/ +#define UNDERWATER_BIT 8 +static void CG_UnderwaterSounds( void ) { +// trap_S_AddLoopingSound( cent->currentState.number, cent->lerpOrigin, vec3_origin, cgs.media.underWaterSound, 255 ); + trap_S_AddLoopingSound( cg.snap->ps.clientNum, cg.snap->ps.origin, vec3_origin, cgs.media.underWaterSound, 255 & ( 1 << 8 ) ); +} + + +/* +=============== +CG_DamageBlendBlob + +=============== +*/ +static void CG_DamageBlendBlob( void ) { + int t,i; + int maxTime; + refEntity_t ent; + qboolean pointDamage; + viewDamage_t *vd; + float redFlash; + + // ragePro systems can't fade blends, so don't obscure the screen + if ( cgs.glconfig.hardwareType == GLHW_RAGEPRO ) { + return; + } + + redFlash = 0; + + for ( i = 0; i < MAX_VIEWDAMAGE; i++ ) { + + vd = &cg.viewDamage[i]; + + if ( !vd->damageValue ) { + continue; + } + + maxTime = vd->damageDuration; + t = cg.time - vd->damageTime; + if ( t <= 0 || t >= maxTime ) { + vd->damageValue = 0; + continue; + } + + pointDamage = !( !vd->damageX && !vd->damageY ); + + // if not point Damage, only do flash blend + if ( !pointDamage ) { + redFlash += 10.0 * ( 1.0 - (float)t / maxTime ); + continue; + } + + memset( &ent, 0, sizeof( ent ) ); + ent.reType = RT_SPRITE; + ent.renderfx = RF_FIRST_PERSON; + + VectorMA( cg.refdef.vieworg, 8, cg.refdef.viewaxis[0], ent.origin ); + VectorMA( ent.origin, vd->damageX * -8, cg.refdef.viewaxis[1], ent.origin ); + VectorMA( ent.origin, vd->damageY * 8, cg.refdef.viewaxis[2], ent.origin ); + + ent.radius = vd->damageValue * 0.4 * ( 0.5 + 0.5 * (float)t / maxTime ) * ( 0.75 + 0.5 * fabs( sin( vd->damageTime ) ) ); + + ent.customShader = cgs.media.viewBloodAni[(int)( floor( ( (float)t / maxTime ) * 4.9 ) )]; //cgs.media.viewBloodShader; + ent.shaderRGBA[0] = 255; + ent.shaderRGBA[1] = 255; + ent.shaderRGBA[2] = 255; + ent.shaderRGBA[3] = 255; + trap_R_AddRefEntityToScene( &ent ); + + redFlash += ent.radius; + } + + /* moved over to cg_draw.c + if (cg.v_dmg_time > cg.time) { + redFlash = fabs(cg.v_dmg_pitch * ((cg.v_dmg_time - cg.time) / DAMAGE_TIME)); + + // blend the entire screen red + if (redFlash > 5) + redFlash = 5; + + memset( &ent, 0, sizeof( ent ) ); + ent.reType = RT_SPRITE; + ent.renderfx = RF_FIRST_PERSON; + + VectorMA( cg.refdef.vieworg, 8, cg.refdef.viewaxis[0], ent.origin ); + ent.radius = 80; // occupy entire screen + ent.customShader = cgs.media.viewFlashBlood; + ent.shaderRGBA[3] = (int)(180.0 * redFlash/5.0); + + trap_R_AddRefEntityToScene( &ent ); + } + */ +} + +/* +=============== +CG_CalcViewValues + +Sets cg.refdef view values +=============== +*/ +static int CG_CalcViewValues( void ) { + playerState_t *ps; + static vec3_t oldOrigin = {0,0,0}; + + memset( &cg.refdef, 0, sizeof( cg.refdef ) ); + + // strings for in game rendering + // Q_strncpyz( cg.refdef.text[0], "Park Ranger", sizeof(cg.refdef.text[0]) ); + // Q_strncpyz( cg.refdef.text[1], "19", sizeof(cg.refdef.text[1]) ); + + // calculate size of 3D view + CG_CalcVrect(); + + ps = &cg.predictedPlayerState; + + if ( cg.cameraMode ) { + vec3_t origin, angles; + float fov = 90; + float x; + + if ( trap_getCameraInfo( CAM_PRIMARY, cg.time, &origin, &angles, &fov ) ) { + VectorCopy( origin, cg.refdef.vieworg ); + angles[ROLL] = 0; + angles[PITCH] = -angles[PITCH]; // (SA) compensate for reversed pitch (this makes the game match the editor, however I'm guessing the real fix is to be done there) + VectorCopy( angles, cg.refdefViewAngles ); + AnglesToAxis( cg.refdefViewAngles, cg.refdef.viewaxis ); + + x = cg.refdef.width / tan( fov / 360 * M_PI ); + cg.refdef.fov_y = atan2( cg.refdef.height, x ); + cg.refdef.fov_y = cg.refdef.fov_y * 360 / M_PI; + cg.refdef.fov_x = fov; + + // RF, had to disable, sometimes a loadgame to a camera in the same position + // can cause the game to not know where the camera is, therefore snapshots + // dont show the correct entities + //if(VectorCompare(origin, oldOrigin)) + // return 0; + + VectorCopy( origin, oldOrigin ); + trap_SendClientCommand( va( "setCameraOrigin %f %f %f", origin[0], origin[1], origin[2] ) ); + return 0; + + } else { + cg.cameraMode = qfalse; // camera off in cgame + trap_Cvar_Set( "cg_letterbox", "0" ); + trap_SendClientCommand( "stopCamera" ); // camera off in game + trap_stopCamera( CAM_PRIMARY ); // camera off in client + + CG_Fade( 0, 0, 0, 255, 0, 0 ); // go black + CG_Fade( 0, 0, 0, 0, cg.time + 200, 1500 ); // then fadeup + } + } + + // intermission view + if ( ps->pm_type == PM_INTERMISSION ) { + VectorCopy( ps->origin, cg.refdef.vieworg ); + VectorCopy( ps->viewangles, cg.refdefViewAngles ); + AnglesToAxis( cg.refdefViewAngles, cg.refdef.viewaxis ); + return CG_CalcFov(); + } + + cg.bobcycle = ( ps->bobCycle & 128 ) >> 7; + cg.bobfracsin = fabs( sin( ( ps->bobCycle & 127 ) / 127.0 * M_PI ) ); + cg.xyspeed = sqrt( ps->velocity[0] * ps->velocity[0] + + ps->velocity[1] * ps->velocity[1] ); + + + VectorCopy( ps->origin, cg.refdef.vieworg ); + VectorCopy( ps->viewangles, cg.refdefViewAngles ); + + // add error decay + if ( cg_errorDecay.value > 0 ) { + int t; + float f; + + t = cg.time - cg.predictedErrorTime; + f = ( cg_errorDecay.value - t ) / cg_errorDecay.value; + if ( f > 0 && f < 1 ) { + VectorMA( cg.refdef.vieworg, f, cg.predictedError, cg.refdef.vieworg ); + } else { + cg.predictedErrorTime = 0; + } + } + + // Ridah, lock the viewangles if the game has told us to + if ( ps->viewlocked ) { + + /* + if (ps->viewlocked == 4) + { + centity_t *tent; + tent = &cg_entities[ps->viewlocked_entNum]; + VectorCopy (tent->currentState.apos.trBase, cg.refdefViewAngles); + } + else + */ + BG_EvaluateTrajectory( &cg_entities[ps->viewlocked_entNum].currentState.apos, cg.time, cg.refdefViewAngles ); + + if ( ps->viewlocked == 2 ) { + cg.refdefViewAngles[0] += crandom(); + cg.refdefViewAngles[1] += crandom(); + } + } + // done. + + if ( cg.renderingThirdPerson ) { + // back away from character + CG_OffsetThirdPersonView(); + } else { + // offset for local bobbing and kicks + CG_OffsetFirstPersonView(); + + // Ridah, lock the viewangles if the game has told us to + if ( ps->viewlocked == 4 ) { + vec3_t fwd; + AngleVectors( cg.refdefViewAngles, fwd, NULL, NULL ); + VectorMA( cg_entities[ps->viewlocked_entNum].currentState.pos.trBase, 16, fwd, cg.refdef.vieworg ); + } else if ( ps->viewlocked ) { + vec3_t fwd; + float oldZ; + // set our position to be behind it + oldZ = cg.refdef.vieworg[2]; + AngleVectors( cg.refdefViewAngles, fwd, NULL, NULL ); + VectorMA( cg_entities[ps->viewlocked_entNum].currentState.pos.trBase, -34, fwd, cg.refdef.vieworg ); + cg.refdef.vieworg[2] = oldZ; + } + // done. + } + + // position eye reletive to origin + AnglesToAxis( cg.refdefViewAngles, cg.refdef.viewaxis ); + + if ( cg.hyperspace ) { + cg.refdef.rdflags |= RDF_NOWORLDMODEL | RDF_HYPERSPACE; + } + + // field of view + return CG_CalcFov(); +} + + +/* +===================== +CG_PowerupTimerSounds +===================== +*/ +static void CG_PowerupTimerSounds( void ) { + int i; + int t; + + // powerup timers going away + for ( i = 0 ; i < MAX_POWERUPS ; i++ ) { + t = cg.snap->ps.powerups[i]; + if ( t <= cg.time ) { + continue; + } + if ( t - cg.time >= POWERUP_BLINKS * POWERUP_BLINK_TIME ) { + continue; + } + if ( ( t - cg.time ) / POWERUP_BLINK_TIME != ( t - cg.oldTime ) / POWERUP_BLINK_TIME ) { + trap_S_StartSound( NULL, cg.snap->ps.clientNum, CHAN_ITEM, cgs.media.wearOffSound ); + } + } +} + +//========================================================================= + +/* +============== +CG_DrawSkyBoxPortal +============== +*/ +void CG_DrawSkyBoxPortal( void ) { + static float lastfov = 90; // for transitions back from zoomed in modes + refdef_t backuprefdef; + float fov_x; + float fov_y; + float x; + char *cstr; + char *token; + float zoomFov; + float f; + static qboolean foginited = qfalse; // only set the portal fog values once + + if ( !( cstr = (char *)CG_ConfigString( CS_SKYBOXORG ) ) || !strlen( cstr ) ) { + // no skybox in this map + return; + } + + // if they are waiting at the mission stats screen, show the stats + if ( cg_gameType.integer == GT_SINGLE_PLAYER ) { + if ( strlen( cg_missionStats.string ) > 1 ) { + return; + } + } + + backuprefdef = cg.refdef; + + if ( cg_skybox.integer ) { + token = COM_ParseExt( &cstr, qfalse ); + if ( !token || !token[0] ) { + CG_Error( "CG_DrawSkyBoxPortal: error parsing skybox configstring\n" ); + } + cg.refdef.vieworg[0] = atof( token ); + + token = COM_ParseExt( &cstr, qfalse ); + if ( !token || !token[0] ) { + CG_Error( "CG_DrawSkyBoxPortal: error parsing skybox configstring\n" ); + } + cg.refdef.vieworg[1] = atof( token ); + + token = COM_ParseExt( &cstr, qfalse ); + if ( !token || !token[0] ) { + CG_Error( "CG_DrawSkyBoxPortal: error parsing skybox configstring\n" ); + } + cg.refdef.vieworg[2] = atof( token ); + + token = COM_ParseExt( &cstr, qfalse ); + if ( !token || !token[0] ) { + CG_Error( "CG_DrawSkyBoxPortal: error parsing skybox configstring\n" ); + } + fov_x = atoi( token ); + + if ( !fov_x ) { + fov_x = 90; + } + + + // setup fog the first time, ignore this part of the configstring after that + token = COM_ParseExt( &cstr, qfalse ); + if ( !token || !token[0] ) { + CG_Error( "CG_DrawSkyBoxPortal: error parsing skybox configstring. No fog state\n" ); + } else { + vec4_t fogColor; + int fogStart, fogEnd; + + if ( atoi( token ) ) { // this camera has fog + // if(!foginited) { + if ( 1 ) { + token = COM_ParseExt( &cstr, qfalse ); + if ( !token || !token[0] ) { + CG_Error( "CG_DrawSkyBoxPortal: error parsing skybox configstring. No fog[0]\n" ); + } + fogColor[0] = atof( token ); + + token = COM_ParseExt( &cstr, qfalse ); + if ( !token || !token[0] ) { + CG_Error( "CG_DrawSkyBoxPortal: error parsing skybox configstring. No fog[1]\n" ); + } + fogColor[1] = atof( token ); + + token = COM_ParseExt( &cstr, qfalse ); + if ( !token || !token[0] ) { + CG_Error( "CG_DrawSkyBoxPortal: error parsing skybox configstring. No fog[2]\n" ); + } + fogColor[2] = atof( token ); + + token = COM_ParseExt( &cstr, qfalse ); + if ( !token || !token[0] ) { + fogStart = 0; + } else { + fogStart = atoi( token ); + } + + token = COM_ParseExt( &cstr, qfalse ); + if ( !token || !token[0] ) { + fogEnd = 0; + } else { + fogEnd = atoi( token ); + } + + trap_R_SetFog( FOG_PORTALVIEW, fogStart, fogEnd, fogColor[0], fogColor[1], fogColor[2], 1.1 ); + foginited = qtrue; + } + } else { + if ( !foginited ) { + trap_R_SetFog( FOG_PORTALVIEW, 0,0,0,0,0,0 ); // init to null + foginited = qtrue; + } + } + } + + //----(SA) end + + + if ( cg.predictedPlayerState.pm_type == PM_INTERMISSION ) { + // if in intermission, use a fixed value + fov_x = 90; + } else { + // user selectable + if ( cgs.dmflags & DF_FIXED_FOV ) { + // dmflag to prevent wide fov for all clients + fov_x = 90; + } else { + fov_x = cg_fov.value; + if ( fov_x < 1 ) { + fov_x = 1; + } else if ( fov_x > 160 ) { + fov_x = 160; + } + } + + // account for zooms + if ( cg.zoomval ) { + zoomFov = cg.zoomval; // (SA) use user scrolled amount + + if ( zoomFov < 1 ) { + zoomFov = 1; + } else if ( zoomFov > 160 ) { + zoomFov = 160; + } + } else { + zoomFov = lastfov; + } + + // do smooth transitions for the binocs + if ( cg.zoomedBinoc ) { // binoc zooming in + f = ( cg.time - cg.zoomTime ) / (float)ZOOM_TIME; + if ( f > 1.0 ) { + fov_x = zoomFov; + } else { + fov_x = fov_x + f * ( zoomFov - fov_x ); + } + lastfov = fov_x; + } else if ( cg.zoomval ) { // zoomed by sniper/snooper + fov_x = cg.zoomval; + lastfov = fov_x; + } else { // binoc zooming out + f = ( cg.time - cg.zoomTime ) / (float)ZOOM_TIME; + if ( f > 1.0 ) { + fov_x = fov_x; + } else { + fov_x = zoomFov + f * ( fov_x - zoomFov ); + } + } + } + + if ( cg.weaponSelect == WP_SNOOPERSCOPE ) { + cg.refdef.rdflags |= RDF_SNOOPERVIEW; + } else { + cg.refdef.rdflags &= ~RDF_SNOOPERVIEW; + } + + if ( cg.snap->ps.persistant[PERS_HWEAPON_USE] ) { + fov_x = 55; + } + + x = cg.refdef.width / tan( fov_x / 360 * M_PI ); + fov_y = atan2( cg.refdef.height, x ); + fov_y = fov_y * 360 / M_PI; + + cg.refdef.fov_x = fov_x; + cg.refdef.fov_y = fov_y; + + cg.refdef.rdflags |= RDF_SKYBOXPORTAL; + cg.refdef.rdflags |= RDF_DRAWSKYBOX; + + } else { // end if(cg_skybox.integer) + + cg.refdef.rdflags |= RDF_SKYBOXPORTAL; + cg.refdef.rdflags &= ~RDF_DRAWSKYBOX; + } + + + cg.refdef.time = cg.time; + + // draw the skybox + trap_R_RenderScene( &cg.refdef ); + + cg.refdef = backuprefdef; +} + +/* +========================= +removed CG_DrawNotebook +========================= +*/ + + +//========================================================================= + +extern void CG_SetupDlightstyles( void ); + + +//#define DEBUGTIME_ENABLED +#ifdef DEBUGTIME_ENABLED +#define DEBUGTIME CG_Printf( "t%i:%i ", dbgCnt++, elapsed = ( trap_Milliseconds() - dbgTime ) ); dbgTime += elapsed; +#else +#define DEBUGTIME +#endif + +/* +================= +CG_DrawActiveFrame + +Generates and draws a game scene and status information at the given time. +================= +*/ +void CG_DrawActiveFrame( int serverTime, stereoFrame_t stereoView, qboolean demoPlayback ) { + int inwater; + + cg.cld = 0; // NERVE - SMF - reset clientDamage + +#ifdef DEBUGTIME_ENABLED + int dbgTime = trap_Milliseconds(),elapsed; + int dbgCnt = 0; +#endif + + cg.time = serverTime; + cg.demoPlayback = demoPlayback; + + // update cvars + CG_UpdateCvars(); +/* + // RF, if we should force a weapon, then do so + if( !cg.weaponSelect ) { + if (cg_loadWeaponSelect.integer > 0) { + cg.weaponSelect = cg_loadWeaponSelect.integer; + cg.weaponSelectTime = cg.time; + trap_Cvar_Set( "cg_loadWeaponSelect", "0" ); // turn it off + } + } +*/ +#ifdef DEBUGTIME_ENABLED + CG_Printf( "\n" ); +#endif + DEBUGTIME + + // if we are only updating the screen as a loading + // pacifier, don't even try to read snapshots + if ( cg.infoScreenText[0] != 0 ) { + CG_DrawInformation(); + return; + } + + // any looped sounds will be respecified as entities + // are added to the render list + trap_S_ClearLoopingSounds( qfalse ); + + DEBUGTIME + + // clear all the render lists + trap_R_ClearScene(); + + DEBUGTIME + + // set up cg.snap and possibly cg.nextSnap + CG_ProcessSnapshots(); + + DEBUGTIME + + // if we haven't received any snapshots yet, all + // we can draw is the information screen + if ( !cg.snap || ( cg.snap->snapFlags & SNAPFLAG_NOT_ACTIVE ) ) { + CG_DrawInformation(); + return; + } + + if ( cg.weaponSelect == WP_FG42SCOPE || cg.weaponSelect == WP_SNOOPERSCOPE || cg.weaponSelect == WP_SNIPERRIFLE ) { + float spd; + spd = VectorLength( cg.snap->ps.velocity ); + if ( spd > 180.0f ) { + switch ( cg.weaponSelect ) { + case WP_FG42SCOPE: + CG_FinishWeaponChange( cg.weaponSelect, WP_FG42 ); + break; + case WP_SNOOPERSCOPE: + CG_FinishWeaponChange( cg.weaponSelect, WP_GARAND ); + break; + case WP_SNIPERRIFLE: + CG_FinishWeaponChange( cg.weaponSelect, WP_MAUSER ); + break; + } + } + } + + DEBUGTIME + + if ( !cg.lightstylesInited ) { + CG_SetupDlightstyles(); + } + + DEBUGTIME + + // if we have been told not to render, don't + if ( cg_norender.integer ) { + return; + } + + // this counter will be bumped for every valid scene we generate + cg.clientFrame++; + + // update cg.predictedPlayerState + CG_PredictPlayerState(); + + DEBUGTIME + + // decide on third person view + cg.renderingThirdPerson = cg_thirdPerson.integer /*|| (cg.snap->ps.stats[STAT_HEALTH] <= 0)*/; + + // build cg.refdef + inwater = CG_CalcViewValues(); + + CG_CalcShakeCamera(); + CG_ApplyShakeCamera(); + + DEBUGTIME + + // RF, draw the skyboxportal + CG_DrawSkyBoxPortal(); + + DEBUGTIME + + if ( inwater ) { + CG_UnderwaterSounds(); + } + + DEBUGTIME + + // first person blend blobs, done after AnglesToAxis + if ( !cg.renderingThirdPerson ) { + CG_DamageBlendBlob(); + } + + DEBUGTIME + + // build the render lists + if ( !cg.hyperspace ) { + CG_AddPacketEntities(); // adter calcViewValues, so predicted player state is correct + CG_AddMarks(); + + DEBUGTIME + + // Rafael particles + CG_AddParticles(); + // done. + + DEBUGTIME + + CG_AddLocalEntities(); + + DEBUGTIME + } + + + CG_AddViewWeapon( &cg.predictedPlayerState ); + + + DEBUGTIME + + // Ridah, trails + if ( !cg.hyperspace ) { + CG_AddFlameChunks(); + CG_AddTrails(); // this must come last, so the trails dropped this frame get drawn + } + // done. + + DEBUGTIME + + // finish up the rest of the refdef + if ( cg.testModelEntity.hModel ) { + CG_AddTestModel(); + } + cg.refdef.time = cg.time; + memcpy( cg.refdef.areamask, cg.snap->areamask, sizeof( cg.refdef.areamask ) ); + + DEBUGTIME + + // warning sounds when powerup is wearing off + CG_PowerupTimerSounds(); + + // make sure the lagometerSample and frame timing isn't done twice when in stereo + if ( stereoView != STEREO_RIGHT ) { + cg.frametime = cg.time - cg.oldTime; + if ( cg.frametime < 0 ) { + cg.frametime = 0; + } + cg.oldTime = cg.time; + CG_AddLagometerFrameInfo(); + } + + DEBUGTIME + + // let the client system know what our weapon, holdable item and zoom settings are +#ifdef AUTOAIM + trap_SetUserCmdValue( cg.weaponSelect, cg.holdableSelect, cg.zoomSensitivity, cg.cld, cg.lastFireTime, cg.crossHairStatus ); +#else + trap_SetUserCmdValue( cg.weaponSelect, cg.holdableSelect, cg.zoomSensitivity, cg.cld ); +#endif + + // actually issue the rendering calls + CG_DrawActive( stereoView ); + + DEBUGTIME + + // update audio positions + trap_S_Respatialize( cg.snap->ps.clientNum, cg.refdef.vieworg, cg.refdef.viewaxis, inwater ); + + if ( cg_stats.integer ) { + CG_Printf( "cg.clientFrame:%i\n", cg.clientFrame ); + } + + DEBUGTIME +} + diff --git a/Projects/Android/jni/rtcw/src/cgame/cg_weapons.c b/Projects/Android/jni/rtcw/src/cgame/cg_weapons.c new file mode 100644 index 0000000..4ce1a4a --- /dev/null +++ b/Projects/Android/jni/rtcw/src/cgame/cg_weapons.c @@ -0,0 +1,6303 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +/* + * name: cg_weapons.c + * + * desc: events and effects dealing with weapons + * +*/ + +#include "cg_local.h" + +int wolfkickModel; +int hWeaponSnd; +int hflakWeaponSnd; +int notebookModel; +int propellerModel; + +vec3_t ejectBrassCasingOrigin; + +//----(SA) +// forward decs +static int getAltWeapon( int weapnum ); +int getEquivWeapon( int weapnum ); +int CG_WeaponIndex( int weapnum, int *bank, int *cycle ); +static qboolean CG_WeaponHasAmmo( int i ); + +static int maxWeapBanks = MAX_WEAP_BANKS, maxWeapsInBank = MAX_WEAPS_IN_BANK; // JPW NERVE + +int weapBanks[MAX_WEAP_BANKS][MAX_WEAPS_IN_BANK] = { + // bank + {0, 0, 0 }, // 0 (empty) + + {WP_KNIFE, 0, 0 }, // 1 + {WP_LUGER, WP_COLT, 0 }, // 2 // WP_AKIMBO + {WP_MP40, WP_THOMPSON, WP_STEN }, // 3 + {WP_MAUSER, WP_GARAND, 0 }, // 4 + {WP_FG42, 0, 0 }, // 5 + {WP_GRENADE_LAUNCHER, WP_GRENADE_PINEAPPLE, WP_DYNAMITE }, // 6 + {WP_PANZERFAUST, 0, 0 }, // 7 + {WP_VENOM, 0, 0 }, // 8 + {WP_FLAMETHROWER, 0, 0 }, // 9 + {WP_TESLA, 0, 0 } // 10 +}; + +// JPW NERVE -- in mutiplayer, characters get knife/special on button 1, pistols on 2, 2-handed on 3 +int weapBanksMultiPlayer[MAX_WEAP_BANKS_MP][MAX_WEAPS_IN_BANK_MP] = { + {0, 0, 0, 0, 0, 0, 0, 0 }, // empty bank '0' + {WP_KNIFE, 0, 0, 0, 0, 0, 0, 0 }, + {WP_LUGER, WP_COLT, 0, 0, 0, 0, 0, 0 }, + {WP_MP40, WP_THOMPSON, WP_STEN, WP_MAUSER, WP_GARAND, WP_PANZERFAUST, WP_VENOM, WP_FLAMETHROWER }, + {WP_GRENADE_LAUNCHER, WP_GRENADE_PINEAPPLE, 0, 0, 0, 0, 0, 0, }, + {WP_CLASS_SPECIAL, 0, 0, 0, 0, 0, 0, 0, }, + {WP_DYNAMITE, 0, 0, 0, 0, 0, 0, 0 } +}; +// jpw + +//----(SA) end + + +/* +============== +CG_MachineGunEjectBrassNew +============== +*/ +static void CG_MachineGunEjectBrassNew( centity_t *cent ) { + localEntity_t *le; + refEntity_t *re; + vec3_t velocity, xvelocity; + float waterScale = 1.0f; + vec3_t v[3]; + + if ( cg_brassTime.integer <= 0 ) { + return; + } + + le = CG_AllocLocalEntity(); + re = &le->refEntity; + + velocity[0] = 16; + velocity[1] = -50 + 40 * crandom(); + velocity[2] = 100 + 50 * crandom(); + + le->leType = LE_FRAGMENT; + le->startTime = cg.time; + le->endTime = le->startTime + cg_brassTime.integer + ( cg_brassTime.integer / 4 ) * random(); + + le->pos.trType = TR_GRAVITY; + le->pos.trTime = cg.time - ( rand() & 15 ); + + AnglesToAxis( cent->lerpAngles, v ); + + VectorCopy( ejectBrassCasingOrigin, re->origin ); + + VectorCopy( re->origin, le->pos.trBase ); + + if ( CG_PointContents( re->origin, -1 ) & ( CONTENTS_WATER | CONTENTS_SLIME ) ) { //----(SA) modified since slime is no longer deadly +// if ( CG_PointContents( re->origin, -1 ) & CONTENTS_WATER ) { + waterScale = 0.10; + } + + xvelocity[0] = velocity[0] * v[0][0] + velocity[1] * v[1][0] + velocity[2] * v[2][0]; + xvelocity[1] = velocity[0] * v[0][1] + velocity[1] * v[1][1] + velocity[2] * v[2][1]; + xvelocity[2] = velocity[0] * v[0][2] + velocity[1] * v[1][2] + velocity[2] * v[2][2]; + VectorScale( xvelocity, waterScale, le->pos.trDelta ); + + AxisCopy( axisDefault, re->axis ); + re->hModel = cgs.media.smallgunBrassModel; + + le->bounceFactor = 0.4 * waterScale; + + le->angles.trType = TR_LINEAR; + le->angles.trTime = cg.time; + le->angles.trBase[0] = rand() & 31; + le->angles.trBase[1] = rand() & 31; + le->angles.trBase[2] = rand() & 31; + le->angles.trDelta[0] = 2; + le->angles.trDelta[1] = 1; + le->angles.trDelta[2] = 0; + + le->leFlags = LEF_TUMBLE; + + + { + int contents; + vec3_t end; + VectorCopy( cent->lerpOrigin, end ); + end[2] -= 24; + contents = trap_CM_PointContents( end, 0 ); + if ( contents & ( CONTENTS_WATER | CONTENTS_SLIME | CONTENTS_LAVA ) ) { + le->leBounceSoundType = LEBS_NONE; + } else { + le->leBounceSoundType = LEBS_BRASS; + } + } + + le->leMarkType = LEMT_NONE; +} + +/* +========================== +CG_MachineGunEjectBrass +========================== +*/ + +static void CG_MachineGunEjectBrass( centity_t *cent ) { + localEntity_t *le; + refEntity_t *re; + vec3_t velocity, xvelocity; + vec3_t offset, xoffset; + float waterScale = 1.0f; + vec3_t v[3]; + + if ( cg_brassTime.integer <= 0 ) { + return; + } + + if ( !( cg.snap->ps.persistant[PERS_HWEAPON_USE] ) && ( cent->currentState.clientNum == cg.snap->ps.clientNum ) ) { + CG_MachineGunEjectBrassNew( cent ); + return; + } + + le = CG_AllocLocalEntity(); + re = &le->refEntity; + + // velocity[0] = 0; + velocity[0] = 16; // Maxx Kaufman offset value + velocity[1] = -50 + 40 * crandom(); + velocity[2] = 100 + 50 * crandom(); + + le->leType = LE_FRAGMENT; + le->startTime = cg.time; + le->endTime = le->startTime + cg_brassTime.integer + ( cg_brassTime.integer / 4 ) * random(); + + le->pos.trType = TR_GRAVITY; + le->pos.trTime = cg.time - ( rand() & 15 ); + + AnglesToAxis( cent->lerpAngles, v ); + + if ( cg.snap->ps.persistant[PERS_HWEAPON_USE] ) { + offset[0] = 32; + offset[1] = -4; + offset[2] = 0; + } else if ( cg.predictedPlayerState.weapon == WP_MP40 || cg.predictedPlayerState.weapon == WP_THOMPSON ) { + offset[0] = 20; // Maxx Kaufman offset value + offset[1] = -4; + offset[2] = 24; + } else if ( cg.predictedPlayerState.weapon == WP_VENOM ) { + offset[0] = 12; + offset[1] = -4; + offset[2] = 24; + } else { + VectorClear( offset ); + } + + + + xoffset[0] = offset[0] * v[0][0] + offset[1] * v[1][0] + offset[2] * v[2][0]; + xoffset[1] = offset[0] * v[0][1] + offset[1] * v[1][1] + offset[2] * v[2][1]; + xoffset[2] = offset[0] * v[0][2] + offset[1] * v[1][2] + offset[2] * v[2][2]; + VectorAdd( cent->lerpOrigin, xoffset, re->origin ); + + VectorCopy( re->origin, le->pos.trBase ); + + if ( CG_PointContents( re->origin, -1 ) & ( CONTENTS_WATER | CONTENTS_SLIME ) ) { //----(SA) modified since slime is no longer deadly +// if ( CG_PointContents( re->origin, -1 ) & CONTENTS_WATER ) { + waterScale = 0.10; + } + + xvelocity[0] = velocity[0] * v[0][0] + velocity[1] * v[1][0] + velocity[2] * v[2][0]; + xvelocity[1] = velocity[0] * v[0][1] + velocity[1] * v[1][1] + velocity[2] * v[2][1]; + xvelocity[2] = velocity[0] * v[0][2] + velocity[1] * v[1][2] + velocity[2] * v[2][2]; + VectorScale( xvelocity, waterScale, le->pos.trDelta ); + + AxisCopy( axisDefault, re->axis ); + re->hModel = cgs.media.machinegunBrassModel; + + le->bounceFactor = 0.4 * waterScale; + + le->angles.trType = TR_LINEAR; + le->angles.trTime = cg.time; + le->angles.trBase[0] = rand() & 31; + le->angles.trBase[1] = rand() & 31; + le->angles.trBase[2] = rand() & 31; + le->angles.trDelta[0] = 2; + le->angles.trDelta[1] = 1; + le->angles.trDelta[2] = 0; + + le->leFlags = LEF_TUMBLE; + + { + int contents; + vec3_t end; + VectorCopy( cent->lerpOrigin, end ); + end[2] -= 24; + contents = trap_CM_PointContents( end, 0 ); + if ( contents & ( CONTENTS_WATER | CONTENTS_SLIME | CONTENTS_LAVA ) ) { + le->leBounceSoundType = LEBS_NONE; + } else { + le->leBounceSoundType = LEBS_BRASS; + } + } + + le->leMarkType = LEMT_NONE; +} + + +//----(SA) added +/* +============== +CG_PanzerFaustEjectBrass + toss the 'used' panzerfaust casing (unit is one-shot, disposable) +============== +*/ +static void CG_PanzerFaustEjectBrass( centity_t *cent ) { + localEntity_t *le; + refEntity_t *re; + vec3_t velocity, xvelocity; + vec3_t offset, xoffset; + float waterScale = 1.0f; + vec3_t v[3]; + + le = CG_AllocLocalEntity(); + re = &le->refEntity; + +// velocity[0] = 16; +// velocity[1] = -50 + 40 * crandom(); +// velocity[2] = 100 + 50 * crandom(); + + velocity[0] = 16; + velocity[1] = -200; + velocity[2] = 0; + + le->leType = LE_FRAGMENT; + le->startTime = cg.time; +// le->startTime = cg.time + 2000; + le->endTime = le->startTime + ( cg_brassTime.integer * 8 ) + ( cg_brassTime.integer * random() ); + + le->pos.trType = TR_GRAVITY; + le->pos.trTime = cg.time - ( rand() & 15 ); +// le->pos.trTime = cg.time - 2000; + + AnglesToAxis( cent->lerpAngles, v ); + +// offset[0] = 12; +// offset[1] = -4; +// offset[2] = 24; + + offset[0] = -24; // forward + offset[1] = -4; // left + offset[2] = 24; // up + + xoffset[0] = offset[0] * v[0][0] + offset[1] * v[1][0] + offset[2] * v[2][0]; + xoffset[1] = offset[0] * v[0][1] + offset[1] * v[1][1] + offset[2] * v[2][1]; + xoffset[2] = offset[0] * v[0][2] + offset[1] * v[1][2] + offset[2] * v[2][2]; + VectorAdd( cent->lerpOrigin, xoffset, re->origin ); + + VectorCopy( re->origin, le->pos.trBase ); + + if ( CG_PointContents( re->origin, -1 ) & ( CONTENTS_WATER | CONTENTS_SLIME ) ) { + waterScale = 0.10; + } + + xvelocity[0] = velocity[0] * v[0][0] + velocity[1] * v[1][0] + velocity[2] * v[2][0]; + xvelocity[1] = velocity[0] * v[0][1] + velocity[1] * v[1][1] + velocity[2] * v[2][1]; + xvelocity[2] = velocity[0] * v[0][2] + velocity[1] * v[1][2] + velocity[2] * v[2][2]; + VectorScale( xvelocity, waterScale, le->pos.trDelta ); + + AxisCopy( axisDefault, re->axis ); + + // (SA) make it bigger + le->sizeScale = 3.0f; + + re->hModel = cgs.media.panzerfaustBrassModel; + + le->bounceFactor = 0.4 * waterScale; + + le->angles.trType = TR_LINEAR; + le->angles.trTime = cg.time; +// le->angles.trBase[0] = rand()&31; +// le->angles.trBase[1] = rand()&31; +// le->angles.trBase[2] = rand()&31; + le->angles.trBase[0] = 0; + le->angles.trBase[1] = cent->currentState.apos.trBase[1]; // rotate to match the player + le->angles.trBase[2] = 0; +// le->angles.trDelta[0] = 2; +// le->angles.trDelta[1] = 1; +// le->angles.trDelta[2] = 0; + le->angles.trDelta[0] = 0; + le->angles.trDelta[1] = 0; + le->angles.trDelta[2] = 0; + + le->leFlags = LEF_TUMBLE | LEF_SMOKING; // (SA) probably doesn't need to be 'tumble' since it doesn't really rotate much when flying + + le->leBounceSoundType = LEBS_NONE; + + le->leMarkType = LEMT_NONE; +} +/* +============== +CG_SpearTrail + simple bubble trail behind a missile +============== +*/ +void CG_SpearTrail( centity_t *ent, const weaponInfo_t *wi ) { + int contents, lastContents; + vec3_t origin, lastPos; + entityState_t *es; + + es = &ent->currentState; + BG_EvaluateTrajectory( &es->pos, cg.time, origin ); + contents = CG_PointContents( origin, -1 ); + + BG_EvaluateTrajectory( &es->pos, ent->trailTime, lastPos ); + lastContents = CG_PointContents( lastPos, -1 ); + + ent->trailTime = cg.time; + + if ( contents & ( CONTENTS_WATER | CONTENTS_SLIME | CONTENTS_LAVA ) ) { + if ( contents & lastContents & CONTENTS_WATER ) { + CG_BubbleTrail( lastPos, origin, 1, 8 ); + } + } +} + + +// JPW NERVE -- LT pyro for marking air strikes +/* +========================== +CG_PyroSmokeTrail +========================== +*/ +void CG_PyroSmokeTrail( centity_t *ent, const weaponInfo_t *wi ) { + int step; + vec3_t origin, lastPos, dir; + int contents; + int lastContents, startTime; + entityState_t *es; + int t; + float rnd; + static float grounddir = 99; + localEntity_t *le; + + if ( grounddir == 99 ) { // pick a wind direction -- cheap trick because it can be different + grounddir = crandom(); // on different clients, but it's all smoke and mirrors anyway + + } + step = 30; + es = &ent->currentState; + startTime = ent->trailTime; + t = step * ( ( startTime + step ) / step ); + + BG_EvaluateTrajectory( &es->pos, cg.time, origin ); + contents = CG_PointContents( origin, -1 ); + + BG_EvaluateTrajectory( &es->pos, ent->trailTime, lastPos ); + lastContents = CG_PointContents( lastPos, -1 ); + + ent->trailTime = cg.time; + +/* smoke pyro works fine in water (well, it's dye in real life, might wanna change this in-game) + if ( contents & ( CONTENTS_WATER | CONTENTS_SLIME | CONTENTS_LAVA ) ) + return; +*/ + + // drop fire trail sprites + for ( ; t <= ent->trailTime ; t += step ) { + + BG_EvaluateTrajectory( &es->pos, t, lastPos ); + rnd = random(); + + //VectorCopy (ent->lerpOrigin, lastPos); + + if ( ent->currentState.density ) { // corkscrew effect + vec3_t right; + vec3_t angles; + VectorCopy( ent->currentState.apos.trBase, angles ); + angles[ROLL] += cg.time % 360; + AngleVectors( angles, NULL, right, NULL ); + VectorMA( lastPos, ent->currentState.density, right, lastPos ); + } + + dir[0] = crandom() * 5; // compute offset from flare base + dir[1] = crandom() * 5; + dir[2] = 0; + VectorAdd( lastPos,dir,origin ); // store in origin + + rnd = random(); + + dir[0] = random() * 0.25; + dir[1] = grounddir; // simulate a little wind so it looks natural + dir[2] = random(); // one direction (so smoke goes side-like) + VectorNormalize( dir ); + VectorScale( dir,45,dir ); // was 75 + + if ( !ent->currentState.otherEntityNum2 ) { // axis team, generate red smoke + le = CG_SmokePuff( origin, dir, + 25 + rnd * 110, // width + rnd * 0.5 + 0.5, rnd * 0.5 + 0.5, 1, 0.5, + 4800 + ( rand() % 2800 ), // duration was 2800+ + t, + 0, + 0, + cgs.media.smokePuffShader ); + } else { + le = CG_SmokePuff( origin, dir, + 25 + rnd * 110, // width + 1.0, rnd * 0.5 + 0.5, rnd * 0.5 + 0.5, 0.5, + 4800 + ( rand() % 2800 ), // duration was 2800+ + t, + 0, + 0, + cgs.media.smokePuffShader ); + } +// CG_ParticleExplosion( "expblue", lastPos, vec3_origin, 100 + (int)(rnd*400), 4, 4 ); // fire "flare" + + + // use the optimized local entity add +// le->leType = LE_SCALE_FADE; +/* this one works + if (rand()%4) + CG_ParticleExplosion( "blacksmokeanim", origin, dir, 2800+(int)(random()*1500), 15, 45+(int)(rnd*90) ); // smoke blacksmokeanim + else + CG_ParticleExplosion( "expblue", lastPos, vec3_origin, 100 + (int)(rnd*400), 4, 4 ); // fire "flare" +*/ + } +} +// jpw + + +// Ridah, new trail effects +/* +========================== +CG_RocketTrail +========================== +*/ +void CG_RocketTrail( centity_t *ent, const weaponInfo_t *wi ) { + int step; + vec3_t origin, lastPos; + int contents; + int lastContents, startTime; + entityState_t *es; + int t; +// localEntity_t *le; + + if ( ent->currentState.eType == ET_FLAMEBARREL ) { + step = 30; + } else if ( ent->currentState.eType == ET_FP_PARTS ) { + step = 50; + } else if ( ent->currentState.eType == ET_RAMJET ) { + step = 10; + } else { + step = 10; + } + + es = &ent->currentState; + startTime = ent->trailTime; + t = step * ( ( startTime + step ) / step ); + + BG_EvaluateTrajectory( &es->pos, cg.time, origin ); + contents = CG_PointContents( origin, -1 ); + + // if object (e.g. grenade) is stationary, don't toss up smoke + if ( ( ent->currentState.eType != ET_RAMJET ) && es->pos.trType == TR_STATIONARY ) { + ent->trailTime = cg.time; + return; + } + + BG_EvaluateTrajectory( &es->pos, ent->trailTime, lastPos ); + lastContents = CG_PointContents( lastPos, -1 ); + + ent->trailTime = cg.time; + + if ( contents & ( CONTENTS_WATER | CONTENTS_SLIME | CONTENTS_LAVA ) ) { + if ( contents & lastContents & CONTENTS_WATER ) { + CG_BubbleTrail( lastPos, origin, 3, 8 ); + } + return; + } + + // drop fire trail sprites + for ( ; t <= ent->trailTime ; t += step ) { + float rnd; + + BG_EvaluateTrajectory( &es->pos, t, lastPos ); + /* + le = CG_SmokePuff( lastPos, vec3_origin, + 5, // width + 1, 1, 1, 0.33, + 150 + rand()%350, // duration + t, + 0, + cgs.media.flameThrowerhitShader ); + + // use the optimized local entity add + le->leType = LE_SCALE_FADE; + */ + rnd = random(); + if ( ent->currentState.eType == ET_FLAMEBARREL ) { + if ( ( rand() % 100 ) > 50 ) { + CG_ParticleExplosion( "twiltb2", lastPos, vec3_origin, 100 + (int)( rnd * 400 ), 5, 7 + (int)( rnd * 10 ) ); // fire + + } + CG_ParticleExplosion( "blacksmokeanim", lastPos, vec3_origin, 800 + (int)( rnd * 1500 ), 5, 12 + (int)( rnd * 30 ) ); // smoke + } else if ( ent->currentState.eType == ET_FP_PARTS ) { + if ( ( rand() % 100 ) > 50 ) { + CG_ParticleExplosion( "twiltb2", lastPos, vec3_origin, 100 + (int)( rnd * 400 ), 5, 7 + (int)( rnd * 10 ) ); // fire + + } + CG_ParticleExplosion( "blacksmokeanim", lastPos, vec3_origin, 800 + (int)( rnd * 1500 ), 5, 12 + (int)( rnd * 30 ) ); // smoke + } else if ( ent->currentState.eType == ET_RAMJET ) { + int duration; + + VectorCopy( ent->lerpOrigin, lastPos ); + duration = 100; + CG_ParticleExplosion( "twiltb2", lastPos, vec3_origin, duration + (int)( rnd * 100 ), 5, 5 + (int)( rnd * 10 ) ); // fire + CG_ParticleExplosion( "blacksmokeanim", lastPos, vec3_origin, 400 + (int)( rnd * 750 ), 12, 24 + (int)( rnd * 30 ) ); // smoke + } else if ( ent->currentState.eType == ET_FIRE_COLUMN || ent->currentState.eType == ET_FIRE_COLUMN_SMOKE ) { + int duration; + int sizeStart; + int sizeEnd; + + //VectorCopy (ent->lerpOrigin, lastPos); + + if ( ent->currentState.density ) { // corkscrew effect + vec3_t right; + vec3_t angles; + VectorCopy( ent->currentState.apos.trBase, angles ); + angles[ROLL] += cg.time % 360; + AngleVectors( angles, NULL, right, NULL ); + VectorMA( lastPos, ent->currentState.density, right, lastPos ); + } + + duration = ent->currentState.angles[0]; + sizeStart = ent->currentState.angles[1]; + sizeEnd = ent->currentState.angles[2]; + + if ( !duration ) { + duration = 100; + } + + if ( !sizeStart ) { + sizeStart = 5; + } + + if ( !sizeEnd ) { + sizeEnd = 7; + } + + CG_ParticleExplosion( "twiltb2", lastPos, vec3_origin, duration + (int)( rnd * 400 ), sizeStart, sizeEnd + (int)( rnd * 10 ) ); // fire + + if ( ent->currentState.eType == ET_FIRE_COLUMN_SMOKE && ( rand() % 100 ) > 50 ) { + CG_ParticleExplosion( "blacksmokeanim", lastPos, vec3_origin, 800 + (int)( rnd * 1500 ), 5, 12 + (int)( rnd * 30 ) ); // smoke + } + } else + { + //CG_ParticleExplosion( "twiltb", lastPos, vec3_origin, 300+(int)(rnd*100), 4, 14+(int)(rnd*8) ); // fire + CG_ParticleExplosion( "blacksmokeanim", lastPos, vec3_origin, 800 + (int)( rnd * 1500 ), 5, 12 + (int)( rnd * 30 ) ); // smoke + } + } +/* + // spawn a smoke junction + if ((cg.time - ent->lastTrailTime) >= 50 + rand()%50) { + ent->headJuncIndex = CG_AddSmokeJunc( ent->headJuncIndex, + cgs.media.smokeTrailShader, + origin, + 4500, 0.4, 20, 80 ); + ent->lastTrailTime = cg.time; + } +*/ +// done. +} + + +// Ridah +/* +========================== +CG_GrenadeTrail +========================== +*/ +static void CG_GrenadeTrail( centity_t *ent, const weaponInfo_t *wi ) { + int step; + vec3_t origin, lastPos; + int contents; + int lastContents, startTime; + entityState_t *es; + int t; + + step = 15; // nice and smooth curves + + es = &ent->currentState; + startTime = ent->trailTime; + t = step * ( ( startTime + step ) / step ); + + BG_EvaluateTrajectory( &es->pos, cg.time, origin ); + contents = CG_PointContents( origin, -1 ); + + // if object (e.g. grenade) is stationary, don't toss up smoke + if ( es->pos.trType == TR_STATIONARY ) { + ent->trailTime = cg.time; + return; + } + + BG_EvaluateTrajectory( &es->pos, ent->trailTime, lastPos ); + lastContents = CG_PointContents( lastPos, -1 ); + + ent->trailTime = cg.time; + + if ( contents & ( CONTENTS_WATER | CONTENTS_SLIME | CONTENTS_LAVA ) ) { + if ( contents & lastContents & CONTENTS_WATER ) { + CG_BubbleTrail( lastPos, origin, 2, 8 ); + } + return; + } + +//----(SA) trying this back on for DM + + // spawn smoke junctions + for ( ; t <= ent->trailTime ; t += step ) { + BG_EvaluateTrajectory( &es->pos, t, origin ); + ent->headJuncIndex = CG_AddSmokeJunc( ent->headJuncIndex, + cgs.media.smokeTrailShader, + origin, +// 1500, 0.3, 10, 50 ); + 1000, 0.3, 2, 20 ); + ent->lastTrailTime = cg.time; + } +//----(SA) end +} +// done. + + + + +/* +========================== +CG_NailgunEjectBrass +========================== +*/ +// TTimo: unused +/* +static void CG_NailgunEjectBrass( centity_t *cent ) { + localEntity_t *smoke; + vec3_t origin; + vec3_t v[3]; + vec3_t offset; + vec3_t xoffset; + vec3_t up; + + AnglesToAxis( cent->lerpAngles, v ); + + offset[0] = 0; + offset[1] = -12; + offset[2] = 24; + + xoffset[0] = offset[0] * v[0][0] + offset[1] * v[1][0] + offset[2] * v[2][0]; + xoffset[1] = offset[0] * v[0][1] + offset[1] * v[1][1] + offset[2] * v[2][1]; + xoffset[2] = offset[0] * v[0][2] + offset[1] * v[1][2] + offset[2] * v[2][2]; + VectorAdd( cent->lerpOrigin, xoffset, origin ); + + VectorSet( up, 0, 0, 64 ); + + smoke = CG_SmokePuff( origin, up, 32, 1, 1, 1, 0.33f, 700, cg.time, 0, 0, cgs.media.smokePuffShader ); + // use the optimized local entity add + smoke->leType = LE_SCALE_FADE; +} + +static void CG_NailTrail( centity_t *ent, const weaponInfo_t *wi ) { + int step; + vec3_t origin, lastPos; + int t; + int startTime, contents; + int lastContents; + entityState_t *es; + vec3_t up; + localEntity_t *smoke; + + up[0] = 0; + up[1] = 0; + up[2] = 0; + + step = 50; + + es = &ent->currentState; + startTime = ent->trailTime; + t = step * ( (startTime + step) / step ); + + BG_EvaluateTrajectory( &es->pos, cg.time, origin ); + contents = CG_PointContents( origin, -1 ); + + // if object (e.g. grenade) is stationary, don't toss up smoke + if ( es->pos.trType == TR_STATIONARY ) { + ent->trailTime = cg.time; + return; + } + + BG_EvaluateTrajectory( &es->pos, ent->trailTime, lastPos ); + lastContents = CG_PointContents( lastPos, -1 ); + + ent->trailTime = cg.time; + + if ( contents & ( CONTENTS_WATER | CONTENTS_SLIME | CONTENTS_LAVA ) ) { + if ( contents & lastContents & CONTENTS_WATER ) { + CG_BubbleTrail( lastPos, origin, 1, 8 ); + } + return; + } + + for ( ; t <= ent->trailTime ; t += step ) { + BG_EvaluateTrajectory( &es->pos, t, lastPos ); + + smoke = CG_SmokePuff( lastPos, up, + wi->trailRadius, + 1, 1, 1, 0.33f, + wi->wiTrailTime, + t, + 0, + 0, + cgs.media.nailPuffShader ); + // use the optimized local entity add + smoke->leType = LE_SCALE_FADE; + } + +} +*/ + +/* +========================== +CG_RailTrail + SA: re-inserted this as a debug mechanism for bullets +========================== +*/ +void CG_RailTrail2( clientInfo_t *ci, vec3_t start, vec3_t end ) { + localEntity_t *le; + refEntity_t *re; + + le = CG_AllocLocalEntity(); + re = &le->refEntity; + + le->leType = LE_FADE_RGB; + le->startTime = cg.time; + le->endTime = cg.time + cg_railTrailTime.value; + le->lifeRate = 1.0 / ( le->endTime - le->startTime ); + + re->shaderTime = cg.time / 1000.0f; + re->reType = RT_RAIL_CORE; + re->customShader = cgs.media.railCoreShader; + + VectorCopy( start, re->origin ); + VectorCopy( end, re->oldorigin ); + +// // still allow different colors so we can tell AI shots from player shots, etc. + if ( ci ) { + le->color[0] = ci->color[0] * 0.75; + le->color[1] = ci->color[1] * 0.75; + le->color[2] = ci->color[2] * 0.75; + } else { + le->color[0] = 1; + le->color[1] = 0; + le->color[2] = 0; + } + le->color[3] = 1.0f; + + AxisClear( re->axis ); +} + +//void CG_RailTrailBox( clientInfo_t *ci, vec3_t start, vec3_t end) { +/* +============== +CG_RailTrail + modified so we could draw boxes for debugging as well +============== +*/ +void CG_RailTrail( clientInfo_t *ci, vec3_t start, vec3_t end, int type ) { //----(SA) added 'type' + vec3_t diff, v1, v2, v3, v4, v5, v6; + + if ( !type ) { // just a line + CG_RailTrail2( ci, start, end ); + return; + } + + // type '1' (box) + + VectorSubtract( start, end, diff ); + + VectorCopy( start, v1 ); + VectorCopy( start, v2 ); + VectorCopy( start, v3 ); + v1[0] -= diff[0]; + v2[1] -= diff[1]; + v3[2] -= diff[2]; + CG_RailTrail2( ci, start, v1 ); + CG_RailTrail2( ci, start, v2 ); + CG_RailTrail2( ci, start, v3 ); + + VectorCopy( end, v4 ); + VectorCopy( end, v5 ); + VectorCopy( end, v6 ); + v4[0] += diff[0]; + v5[1] += diff[1]; + v6[2] += diff[2]; + CG_RailTrail2( ci, end, v4 ); + CG_RailTrail2( ci, end, v5 ); + CG_RailTrail2( ci, end, v6 ); + + CG_RailTrail2( ci, v2, v6 ); + CG_RailTrail2( ci, v6, v1 ); + CG_RailTrail2( ci, v1, v5 ); + + CG_RailTrail2( ci, v2, v4 ); + CG_RailTrail2( ci, v4, v3 ); + CG_RailTrail2( ci, v3, v5 ); + +} + + + + + +/* +====================== +CG_ParseWeaponConfig + read information for weapon animations (first/length/fps) +====================== +*/ +static qboolean CG_ParseWeaponConfig( const char *filename, weaponInfo_t *wi ) { + char *text_p, *prev; + int len; + int i; + float fps; + char *token; + qboolean newfmt = qfalse; //----(SA) + char text[20000]; + fileHandle_t f; + + // load the file + len = trap_FS_FOpenFile( filename, &f, FS_READ ); + if ( len <= 0 ) { + return qfalse; + } + + if ( len >= sizeof( text ) - 1 ) { + CG_Printf( "File %s too long\n", filename ); + return qfalse; + } + + trap_FS_Read( text, len, f ); + text[len] = 0; + trap_FS_FCloseFile( f ); + + // parse the text + text_p = text; + + // read optional parameters + while ( 1 ) { + prev = text_p; // so we can unget + token = COM_Parse( &text_p ); + if ( !token ) { // get the variable + break; + } + if ( !Q_stricmp( token, "whatever_variable" ) ) { + token = COM_Parse( &text_p ); // get the value + if ( !token ) { + break; + } + continue; + } + + if ( !Q_stricmp( token, "newfmt" ) ) { + newfmt = qtrue; + continue; + } + + // if it is a number, start parsing animations + if ( Q_isnumeric( token[0] ) ) { + text_p = prev; // unget the token + break; + } + Com_Printf( "unknown token in weapon cfg '%s' is %s\n", token, filename ); + } + + + for ( i = 0 ; i < MAX_WP_ANIMATIONS ; i++ ) { + + token = COM_Parse( &text_p ); // first frame + if ( !token ) { + break; + } + wi->weapAnimations[i].firstFrame = atoi( token ); + + token = COM_Parse( &text_p ); // length + if ( !token ) { + break; + } + wi->weapAnimations[i].numFrames = atoi( token ); + + token = COM_Parse( &text_p ); // fps + if ( !token ) { + break; + } + fps = atof( token ); + if ( fps == 0 ) { + fps = 1; + } + + wi->weapAnimations[i].frameLerp = 1000 / fps; + wi->weapAnimations[i].initialLerp = 1000 / fps; + + token = COM_Parse( &text_p ); // looping frames + if ( !token ) { + break; + } + wi->weapAnimations[i].loopFrames = atoi( token ); + if ( wi->weapAnimations[i].loopFrames > wi->weapAnimations[i].numFrames ) { + wi->weapAnimations[i].loopFrames = wi->weapAnimations[i].numFrames; + } else if ( wi->weapAnimations[i].loopFrames < 0 ) { + wi->weapAnimations[i].loopFrames = 0; + } + + + // store animation/draw bits in '.moveSpeed' + + wi->weapAnimations[i].moveSpeed = 0; + + if ( newfmt ) { + token = COM_Parse( &text_p ); // barrel anim bits + if ( !token ) { + break; + } + wi->weapAnimations[i].moveSpeed = atoi( token ); + + token = COM_Parse( &text_p ); // animated weapon + if ( !token ) { + break; + } + if ( atoi( token ) ) { + wi->weapAnimations[i].moveSpeed |= ( 1 << W_MAX_PARTS ); // set the bit one higher than can be set by the barrel bits + + } + token = COM_Parse( &text_p ); // barrel hide bits (so objects can be flagged to not be drawn during all sequences (a reloading hand that comes in from off screen for that one animation for example) + if ( !token ) { + break; + } + wi->weapAnimations[i].moveSpeed |= ( ( atoi( token ) ) << 8 ); // use 2nd byte for draw bits + } + + } + + if ( i != MAX_WP_ANIMATIONS ) { + CG_Printf( "Error parsing weapon animation file: %s", filename ); + return qfalse; + } + + + return qtrue; +} + + +/* +================= +CG_RegisterWeapon + +The server says this item is used on this level +================= +*/ +void CG_RegisterWeapon( int weaponNum ) { + weaponInfo_t *weaponInfo; + gitem_t *item, *ammo; + char path[MAX_QPATH], comppath[MAX_QPATH]; + vec3_t mins, maxs; + int i; + + weaponInfo = &cg_weapons[weaponNum]; + + // don't bother trying + switch ( weaponNum ) { + case WP_NONE: + case WP_CLASS_SPECIAL: + case WP_MONSTER_ATTACK1: + case WP_MONSTER_ATTACK2: + case WP_MONSTER_ATTACK3: + case WP_GAUNTLET: + case WP_SNIPER: + case WP_MORTAR: + +// (SA) i don't know about these, but we don't have models for 'em + case WP_GRENADE_SMOKE: + case WP_MEDIC_HEAL: + return; + default: + break; + } + + + if ( weaponInfo->registered ) { + return; + } + + memset( weaponInfo, 0, sizeof( *weaponInfo ) ); + weaponInfo->registered = qtrue; + + for ( item = bg_itemlist + 1 ; item->classname ; item++ ) { + if ( item->giType == IT_WEAPON && item->giTag == weaponNum ) { + weaponInfo->item = item; + break; + } + } + if ( !item->classname ) { + CG_Error( "Couldn't find weapon %i", weaponNum ); + } + CG_RegisterItemVisuals( item - bg_itemlist ); + + // load cmodel before model so filecache works + + // alternate view weapon + weaponInfo->weaponModel[W_TP_MODEL] = trap_R_RegisterModel( item->world_model[W_TP_MODEL] ); + weaponInfo->weaponModel[W_FP_MODEL] = trap_R_RegisterModel( item->world_model[W_FP_MODEL] ); + weaponInfo->weaponModel[W_SKTP_MODEL] = trap_R_RegisterModel( item->world_model[W_SKTP_MODEL] ); + + if ( !weaponInfo->weaponModel[W_FP_MODEL] || !cg_drawFPGun.integer ) { + weaponInfo->weaponModel[W_FP_MODEL] = weaponInfo->weaponModel[W_TP_MODEL]; + } + + if ( !weaponInfo->weaponModel[W_TP_MODEL] ) { + // left commented out since we have level-loading optimization issues to still resolve. + // ie. every weapon and it's associated effects/parts/sounds etc. are loaded for every level. + // This was turned off when we started (the "only load what the level calls for" thing) because when + // DM does a "give all" and fires, he doesn't want to wait for everything to load. So perhaps a "cacheallweaps" or something. +// CG_Printf( "Couldn't register weapon model %i (unable to load view model)", weaponNum ); +// RF, I need to be able to run the game, I dont have the silencer weapon (19) +#ifndef _DEBUG +// CG_Error( "Couldn't register weapon model %i (unable to load view model)", weaponNum ); +#endif + return; + } + + + // load weapon config +//----(SA) modified. use first person model for finding weapon config name, not third + if ( item->world_model[W_FP_MODEL] ) { + COM_StripFilename( item->world_model[W_FP_MODEL], path ); + if ( !CG_ParseWeaponConfig( va( "%sweapon.cfg", path ), weaponInfo ) ) { + CG_Error( "Couldn't register weapon %i (%s) (failed to parse weapon.cfg)", weaponNum, path ); + } + } +//----(SA) end + + // calc midpoint for rotation + trap_R_ModelBounds( weaponInfo->weaponModel[W_TP_MODEL], mins, maxs ); + + for ( i = 0 ; i < 3 ; i++ ) { + weaponInfo->weaponMidpoint[i] = mins[i] + 0.5 * ( maxs[i] - mins[i] ); + } + + weaponInfo->weaponIcon[0] = trap_R_RegisterShader( item->icon ); + weaponInfo->weaponIcon[1] = trap_R_RegisterShader( va( "%s_select", item->icon ) ); // get the 'selected' icon as well + + // JOSEPH 4-17-00 + weaponInfo->ammoIcon = trap_R_RegisterShader( item->ammoicon ); + // END JOSEPH + + for ( ammo = bg_itemlist + 1 ; ammo->classname ; ammo++ ) { + if ( ( ammo->giType == IT_AMMO && ammo->giTag == BG_FindAmmoForWeapon( weaponNum ) ) ) { + break; + } + } + if ( ammo->classname && ammo->world_model[0] ) { + weaponInfo->ammoModel = trap_R_RegisterModel( ammo->world_model[0] ); + } + + if ( item->world_model[W_FP_MODEL] ) { + strcpy( comppath, item->world_model[W_FP_MODEL] ); // first try the fp view weap + } else if ( item->world_model[W_TP_MODEL] ) { + strcpy( comppath, item->world_model[W_TP_MODEL] ); // not there, use the standard view hand + + } + if ( ( !comppath || !cg_drawFPGun.integer ) && // then if it didn't find the 1st person one or you are set to not use one + item->world_model[W_TP_MODEL] ) { + strcpy( comppath, item->world_model[W_TP_MODEL] ); // use the standard view hand + + } + for ( i = W_TP_MODEL; i < W_NUM_TYPES; i++ ) + { + int j; + + if ( !item->world_model[i] ) { + strcpy( path, comppath ); + } else { + strcpy( path, item->world_model[i] ); + } + + COM_StripExtension( path, path ); + strcat( path, "_flash.md3" ); + weaponInfo->flashModel[i] = trap_R_RegisterModel( path ); + + + for ( j = 0; j < W_MAX_PARTS; j++ ) { + if ( !item->world_model[i] ) { + strcpy( path, comppath ); + } else { + strcpy( path, item->world_model[i] ); + } + COM_StripExtension( path, path ); + if ( j == W_PART_1 ) { + strcat( path, "_barrel.md3" ); + } else { + strcat( path, va( "_barrel%d.md3", j + 1 ) ); + } + weaponInfo->wpPartModels[i][j] = trap_R_RegisterModel( path ); + } + + // used for spinning belt on venom + if ( i == W_FP_MODEL ) { + if ( !item->world_model[2] ) { + strcpy( path, comppath ); + } else { + strcpy( path, item->world_model[2] ); + } + COM_StripExtension( path, path ); + strcat( path, "_barrel6b.md3" ); + weaponInfo->wpPartModels[i][W_PART_7] = trap_R_RegisterModel( path ); + } + } + + + // sniper scope model + if ( weaponNum == WP_MAUSER || weaponNum == WP_GARAND ) { + + if ( !item->world_model[W_FP_MODEL] ) { + strcpy( path, comppath ); + } else { + strcpy( path, item->world_model[W_FP_MODEL] ); + } + COM_StripExtension( path, path ); + strcat( path, "_scope.md3" ); + weaponInfo->modModel[0] = trap_R_RegisterModel( path ); + } + + if ( !item->world_model[W_FP_MODEL] ) { + strcpy( path, comppath ); + } else { + strcpy( path, item->world_model[W_FP_MODEL] ); + } + COM_StripExtension( path, path ); + strcat( path, "_hand.md3" ); + weaponInfo->handsModel = trap_R_RegisterModel( path ); + + if ( !weaponInfo->handsModel ) { + weaponInfo->handsModel = trap_R_RegisterModel( "models/weapons2/shotgun/shotgun_hand.md3" ); + } + + +//----(SA) weapon pickup 'stand' + if ( !item->world_model[W_TP_MODEL] ) { + strcpy( path, comppath ); + } else { + strcpy( path, item->world_model[W_TP_MODEL] ); + } + COM_StripExtension( path, path ); + strcat( path, "_stand.md3" ); + weaponInfo->standModel = trap_R_RegisterModel( path ); +//----(SA) end + + switch ( weaponNum ) { + case WP_MONSTER_ATTACK1: + case WP_MONSTER_ATTACK2: + case WP_MONSTER_ATTACK3: + break; + + + case WP_AKIMBO: //----(SA) added + // same as colt + MAKERGB( weaponInfo->flashDlightColor, 1.0, 0.6, 0.23 ); + weaponInfo->flashSound[0] = trap_S_RegisterSound( "sound/weapons/colt/coltf1.wav" ); + weaponInfo->flashEchoSound[0] = trap_S_RegisterSound( "sound/weapons/mp40/mp40e1.wav" ); // use same as mp40 + weaponInfo->ejectBrassFunc = CG_MachineGunEjectBrass; + + // unique + weaponInfo->reloadSound = trap_S_RegisterSound( "sound/weapons/colt/colt_reload2.wav" ); + break; + + case WP_COLT: + MAKERGB( weaponInfo->flashDlightColor, 1.0, 0.6, 0.23 ); + weaponInfo->flashSound[0] = trap_S_RegisterSound( "sound/weapons/colt/coltf1.wav" ); + weaponInfo->flashEchoSound[0] = trap_S_RegisterSound( "sound/weapons/mp40/mp40e1.wav" ); // use same as mp40 + weaponInfo->reloadSound = trap_S_RegisterSound( "sound/weapons/colt/colt_reload.wav" ); + weaponInfo->ejectBrassFunc = CG_MachineGunEjectBrass; + break; + + + case WP_KNIFE: + weaponInfo->flashSound[0] = trap_S_RegisterSound( "sound/weapons/knife/knife_slash1.wav" ); + weaponInfo->flashSound[1] = trap_S_RegisterSound( "sound/weapons/knife/knife_slash2.wav" ); + break; + + case WP_LUGER: + MAKERGB( weaponInfo->flashDlightColor, 1.0, 0.6, 0.23 ); + + weaponInfo->switchSound[0] = trap_S_RegisterSound( "sound/weapons/luger/silencerremove.wav" ); //----(SA) added + + weaponInfo->flashSound[0] = trap_S_RegisterSound( "sound/weapons/luger/lugerf1.wav" ); + weaponInfo->flashEchoSound[0] = trap_S_RegisterSound( "sound/weapons/mp40/mp40e1.wav" ); // use same as mp40 + weaponInfo->reloadSound = trap_S_RegisterSound( "sound/weapons/luger/luger_reload.wav" ); + weaponInfo->ejectBrassFunc = CG_MachineGunEjectBrass; + break; + + case WP_SILENCER: // luger mod + MAKERGB( weaponInfo->flashDlightColor, 1.0, 0.6, 0.23 ); + + weaponInfo->switchSound[0] = trap_S_RegisterSound( "sound/weapons/luger/silencerattatch.wav" ); //----(SA) added + + weaponInfo->flashSound[0] = trap_S_RegisterSound( "sound/weapons/luger/silencerf1.wav" ); + weaponInfo->reloadSound = trap_S_RegisterSound( "sound/weapons/luger/luger_reload.wav" ); + weaponInfo->ejectBrassFunc = CG_MachineGunEjectBrass; + break; + + case WP_MAUSER: + MAKERGB( weaponInfo->flashDlightColor, 1.0, 0.6, 0.23 ); + weaponInfo->flashSound[0] = trap_S_RegisterSound( "sound/weapons/mauser/mauserf1.wav" ); + weaponInfo->flashEchoSound[0] = trap_S_RegisterSound( "sound/weapons/mauser/mausere1.wav" ); + weaponInfo->lastShotSound[0] = trap_S_RegisterSound( "sound/weapons/mauser/mauserf1_last.wav" ); + weaponInfo->reloadSound = trap_S_RegisterSound( "sound/weapons/mauser/mauser_reload.wav" ); + weaponInfo->ejectBrassFunc = CG_MachineGunEjectBrass; + break; + case WP_SNIPERRIFLE: + MAKERGB( weaponInfo->flashDlightColor, 1.0, 0.6, 0.23 ); + weaponInfo->flashSound[0] = trap_S_RegisterSound( "sound/weapons/mauser/sniperf1.wav" ); + weaponInfo->flashEchoSound[0] = trap_S_RegisterSound( "sound/weapons/mauser/mausere1.wav" ); + weaponInfo->reloadSound = trap_S_RegisterSound( "sound/weapons/mauser/sniper_reload.wav" ); + weaponInfo->ejectBrassFunc = CG_MachineGunEjectBrass; + break; + + case WP_GARAND: + MAKERGB( weaponInfo->flashDlightColor, 1.0, 0.6, 0.23 ); + weaponInfo->flashSound[0] = trap_S_RegisterSound( "sound/weapons/garand/garandf1.wav" ); + weaponInfo->reloadSound = trap_S_RegisterSound( "sound/weapons/garand/garand_reload.wav" ); + weaponInfo->ejectBrassFunc = CG_MachineGunEjectBrass; + break; + case WP_SNOOPERSCOPE: + MAKERGB( weaponInfo->flashDlightColor, 1.0, 0.6, 0.23 ); + weaponInfo->flashSound[0] = trap_S_RegisterSound( "sound/weapons/garand/snooperf1.wav" ); + weaponInfo->reloadSound = trap_S_RegisterSound( "sound/weapons/garand/snooper_reload.wav" ); + weaponInfo->ejectBrassFunc = CG_MachineGunEjectBrass; + break; + + case WP_THOMPSON: + MAKERGB( weaponInfo->flashDlightColor, 1.0, 0.6, 0.23 ); + weaponInfo->flashSound[0] = trap_S_RegisterSound( "sound/weapons/thompson/thompson.wav" ); + weaponInfo->flashEchoSound[0] = trap_S_RegisterSound( "sound/weapons/mp40/mp40e1.wav" ); // use same as mp40 + weaponInfo->reloadSound = trap_S_RegisterSound( "sound/weapons/thompson/thompson_reload.wav" ); + weaponInfo->overheatSound = trap_S_RegisterSound( "sound/weapons/thompson/thompson_overheat.wav" ); + weaponInfo->ejectBrassFunc = CG_MachineGunEjectBrass; + break; + + case WP_MP40: + MAKERGB( weaponInfo->flashDlightColor, 1.0, 0.6, 0.23 ); + weaponInfo->flashSound[0] = trap_S_RegisterSound( "sound/weapons/mp40/mp40f1.wav" ); + weaponInfo->flashEchoSound[0] = trap_S_RegisterSound( "sound/weapons/mp40/mp40e1.wav" ); + weaponInfo->reloadSound = trap_S_RegisterSound( "sound/weapons/mp40/mp40_reload.wav" ); + weaponInfo->overheatSound = trap_S_RegisterSound( "sound/weapons/mp40/mp40_overheat.wav" ); + weaponInfo->ejectBrassFunc = CG_MachineGunEjectBrass; + break; + + case WP_STEN: + MAKERGB( weaponInfo->flashDlightColor, 1.0, 0.6, 0.23 ); + weaponInfo->flashSound[0] = trap_S_RegisterSound( "sound/weapons/sten/stenf1.wav" ); + weaponInfo->reloadSound = trap_S_RegisterSound( "sound/weapons/sten/sten_reload.wav" ); + weaponInfo->overheatSound = trap_S_RegisterSound( "sound/weapons/sten/sten_overheat.wav" ); + weaponInfo->ejectBrassFunc = CG_MachineGunEjectBrass; + break; + + + case WP_FG42: + case WP_FG42SCOPE: + MAKERGB( weaponInfo->flashDlightColor, 1.0, 0.6, 0.23 ); + weaponInfo->flashSound[0] = trap_S_RegisterSound( "sound/weapons/fg42/fg42f1.wav" ); + weaponInfo->flashEchoSound[0] = trap_S_RegisterSound( "sound/weapons/fg42/fg42e1.wav" ); + weaponInfo->reloadSound = trap_S_RegisterSound( "sound/weapons/fg42/fg42_reload.wav" ); + weaponInfo->ejectBrassFunc = CG_MachineGunEjectBrass; + break; + + + case WP_PANZERFAUST: + weaponInfo->ejectBrassFunc = CG_PanzerFaustEjectBrass; + weaponInfo->missileModel = trap_R_RegisterModel( "models/ammo/rocket/rocket.md3" ); + weaponInfo->missileSound = trap_S_RegisterSound( "sound/weapons/rocket/rockfly.wav" ); + weaponInfo->missileTrailFunc = CG_RocketTrail; + weaponInfo->missileDlight = 200; + weaponInfo->wiTrailTime = 2000; + weaponInfo->trailRadius = 64; + MAKERGB( weaponInfo->flashDlightColor, 0.75, 0.3, 0.0 ); + MAKERGB( weaponInfo->missileDlightColor, 0.75, 0.3, 0.0 ); + weaponInfo->flashSound[0] = trap_S_RegisterSound( "sound/weapons/rocket/rocklf1a.wav" ); + weaponInfo->reloadSound = trap_S_RegisterSound( "sound/weapons/rocket/rocklf_reload.wav" ); + cgs.media.rocketExplosionShader = trap_R_RegisterShader( "rocketExplosion" ); + break; + + case WP_MORTAR: + weaponInfo->flashSound[0] = trap_S_RegisterSound( "sound/weapons/mortar/mortarf1.wav" ); + weaponInfo->missileTrailFunc = CG_GrenadeTrail; + weaponInfo->missileDlight = 400; + weaponInfo->missileSound = trap_S_RegisterSound( "sound/weapons/rocket/rockfly.wav" ); + weaponInfo->wiTrailTime = 300; + weaponInfo->trailRadius = 32; + MAKERGB( weaponInfo->flashDlightColor, 1, 0.7, 0.5 ); + break; +// JPW NERVE + case WP_GRENADE_SMOKE: + weaponInfo->missileModel = trap_R_RegisterModel( "models/weapons2/grenade/pineapple.md3" ); + weaponInfo->missileTrailFunc = CG_PyroSmokeTrail; + weaponInfo->missileDlight = 200; + weaponInfo->wiTrailTime = 4000; + weaponInfo->trailRadius = 256; + break; +// jpw +// DHM - Nerve - temp effects + case WP_CLASS_SPECIAL: + case WP_MEDIC_HEAL: + weaponInfo->flashSound[0] = trap_S_RegisterSound( "sound/weapons/knife/knife_slash1.wav" ); + weaponInfo->flashSound[1] = trap_S_RegisterSound( "sound/weapons/knife/knife_slash2.wav" ); + break; +// dhm + case WP_GRENADE_LAUNCHER: + case WP_GRENADE_PINEAPPLE: + if ( weaponNum == WP_GRENADE_LAUNCHER ) { + weaponInfo->missileModel = trap_R_RegisterModel( "models/ammo/grenade1.md3" ); + } else { + weaponInfo->missileModel = trap_R_RegisterModel( "models/weapons2/grenade/pineapple.md3" ); + } + weaponInfo->missileTrailFunc = CG_GrenadeTrail; + weaponInfo->wiTrailTime = 700; +// weaponInfo->wiTrailTime = 2000; + weaponInfo->wiTrailTime = 1000; + weaponInfo->trailRadius = 32; + MAKERGB( weaponInfo->flashDlightColor, 1, 0.7, 0.5 ); + weaponInfo->flashSound[0] = trap_S_RegisterSound( "sound/weapons/grenade/grenlf1a.wav" ); + weaponInfo->reloadSound = trap_S_RegisterSound( "sound/weapons/grenade/grenlf_reload.wav" ); + cgs.media.grenadeExplosionShader = trap_R_RegisterShader( "grenadeExplosion" ); + break; + + case WP_DYNAMITE: + weaponInfo->missileModel = trap_R_RegisterModel( "models/ammo/dynamite.md3" ); +// weaponInfo->flashSound[0] = trap_S_RegisterSound( "sound/weapons/grenade/grenlf1a.wav" ); +// weaponInfo->reloadSound = trap_S_RegisterSound( "sound/weapons/grenade/grenlf_reload.wav" ); + cgs.media.grenadeExplosionShader = trap_R_RegisterShader( "grenadeExplosion" ); + break; + + case WP_VENOM: + MAKERGB( weaponInfo->flashDlightColor, 1.0, 0.6, 0.23 ); + weaponInfo->spinupSound = trap_S_RegisterSound( "sound/weapons/venom/venomsu1.wav" ); //----(SA) added + weaponInfo->spindownSound = trap_S_RegisterSound( "sound/weapons/venom/venomsd1.wav" ); //----(SA) added + weaponInfo->flashSound[0] = trap_S_RegisterSound( "sound/weapons/venom/venomf1.wav" ); + weaponInfo->reloadSound = trap_S_RegisterSound( "sound/weapons/venom/venom_reload.wav" ); + weaponInfo->overheatSound = trap_S_RegisterSound( "sound/weapons/venom/venom_overheat.wav" ); + weaponInfo->ejectBrassFunc = CG_MachineGunEjectBrass; + break; + + case WP_FLAMETHROWER: + //MAKERGB( weaponInfo->flashDlightColor, 1.0, 0.7, 0.4 ); + break; + + case WP_TESLA: + MAKERGB( weaponInfo->flashDlightColor, 0.2, 0.6, 1 ); + weaponInfo->flashSound[0] = trap_S_RegisterSound( "sound/weapons/tesla/teslaf1.wav" ); + weaponInfo->reloadSound = trap_S_RegisterSound( "sound/weapons/tesla/tesla_reload.wav" ); + weaponInfo->overheatSound = trap_S_RegisterSound( "sound/weapons/tesla/tesla_overheat.wav" ); + break; + + + case WP_GAUNTLET: + MAKERGB( weaponInfo->flashDlightColor, 0.6, 0.6, 1 ); + //weaponInfo->firingSound = trap_S_RegisterSound( "sound/weapons/melee/fstrun.wav" ); + weaponInfo->flashSound[0] = trap_S_RegisterSound( "sound/weapons/melee/fstatck.wav" ); + break; + + default: + MAKERGB( weaponInfo->flashDlightColor, 1, 1, 1 ); + weaponInfo->flashSound[0] = trap_S_RegisterSound( "sound/weapons/rocket/rocklf1a.wav" ); + break; + } +} + +/* +================= +CG_RegisterItemVisuals + +The server says this item is used on this level +================= +*/ +void CG_RegisterItemVisuals( int itemNum ) { + itemInfo_t *itemInfo; + gitem_t *item; + int i; + + itemInfo = &cg_items[ itemNum ]; + if ( itemInfo->registered ) { + return; + } + + item = &bg_itemlist[ itemNum ]; + + memset( itemInfo, 0, sizeof( &itemInfo ) ); + +//----(SA) umm, why was this set here? It sets registered to true, +//----(SA) then in the register weapon(below) it returns since +//----(SA) the first thing it does is to check if it's registered. + + // itemInfo->registered = qtrue; + + for ( i = 0; i < MAX_ITEM_MODELS; i++ ) + itemInfo->models[i] = trap_R_RegisterModel( item->world_model[i] ); + + + itemInfo->icons[0] = trap_R_RegisterShader( item->icon ); + if ( item->giType == IT_HOLDABLE ) { + // (SA) register alternate icons (since holdables can have multiple uses, they might have different icons to represent how many uses are left) + for ( i = 1; i < MAX_ITEM_ICONS; i++ ) + itemInfo->icons[i] = trap_R_RegisterShader( va( "%s%i", item->icon, i + 1 ) ); + } + + if ( item->giType == IT_WEAPON ) { + CG_RegisterWeapon( item->giTag ); + } + + itemInfo->registered = qtrue; //----(SA) moved this down after the registerweapon() + + wolfkickModel = trap_R_RegisterModel( "models/weapons2/foot/v_wolfoot_10f.md3" ); + hWeaponSnd = trap_S_RegisterSound( "sound/weapons/mg42/37mm.wav" ); + + hflakWeaponSnd = trap_S_RegisterSound( "sound/weapons/flak/flak.wav" ); + + notebookModel = trap_R_RegisterModel( "models/mapobjects/book/book.md3" ); + + propellerModel = trap_R_RegisterModel( "models/mapobjects/vehicles/m109_prop.md3" ); + +// JPW NERVE had to put this somewhere, this seems OK + if ( cg_gameType.integer != GT_WOLF ) { + maxWeapBanks = MAX_WEAP_BANKS; + maxWeapsInBank = MAX_WEAPS_IN_BANK; + } else { + trap_R_RegisterModel( "models/mapobjects/vehicles/m109.md3" ); + CG_RegisterWeapon( WP_GRENADE_SMOKE ); // register WP_CLASS_SPECIAL visuals here + CG_RegisterWeapon( WP_MEDIC_HEAL ); + maxWeapBanks = MAX_WEAP_BANKS_MP; + maxWeapsInBank = MAX_WEAPS_IN_BANK_MP; + } +// if player runs out of SMG ammunition, it shouldn't *also* deplete pistol ammunition. If you change this, change +// g_spawn.c as well + if ( cg_gameType.integer != GT_SINGLE_PLAYER ) { + item = BG_FindItem( "Thompson" ); + item->giAmmoIndex = WP_THOMPSON; + item = BG_FindItem( "Sten" ); + item->giAmmoIndex = WP_STEN; + item = BG_FindItem( "MP40" ); + item->giAmmoIndex = WP_MP40; + } +// jpw + + // + // powerups have an accompanying ring or sphere + // +// if ( item->giType == IT_POWERUP || item->giType == IT_HEALTH || +// item->giType == IT_ARMOR || item->giType == IT_HOLDABLE ) { +// if ( item->world_model[W_FP_MODEL] ) { +// itemInfo->models[W_FP_MODEL] = trap_R_RegisterModel( item->world_model[W_FP_MODEL] ); +// } +// } +} + + +/* +======================================================================================== + +VIEW WEAPON + +======================================================================================== +*/ + + +// +// weapon animations +// + +/* +============== +CG_GetPartFramesFromWeap + get animation info from the parent if necessary +============== +*/ +qboolean CG_GetPartFramesFromWeap( centity_t *cent, refEntity_t *part, refEntity_t *parent, int partid, weaponInfo_t *wi ) { + int i; + int frameoffset = 0; + animation_t *anim; + + anim = cent->pe.weap.animation; + + if ( partid == W_MAX_PARTS ) { + return qtrue; // primary weap model drawn for all frames right now + } + + // check draw bit + if ( anim->moveSpeed & ( 1 << ( partid + 8 ) ) ) { // hide bits are in high byte + return qfalse; // not drawn for current sequence + } + + // find part's start frame for this animation sequence + for ( i = 0; i < cent->pe.weap.animationNumber; i++ ) { + if ( wi->weapAnimations[i].moveSpeed & ( 1 << partid ) ) { // this part has animation for this sequence + frameoffset += wi->weapAnimations[i].numFrames; + } + } + + // now set the correct frame into the part + if ( anim->moveSpeed & ( 1 << partid ) ) { + part->backlerp = parent->backlerp; + part->oldframe = frameoffset + ( parent->oldframe - anim->firstFrame ); + part->frame = frameoffset + ( parent->frame - anim->firstFrame ); + } + + return qtrue; +} + + +/* +=============== +CG_SetWeapLerpFrameAnimation + +may include ANIM_TOGGLEBIT +=============== +*/ +static void CG_SetWeapLerpFrameAnimation( weaponInfo_t *wi, lerpFrame_t *lf, int newAnimation ) { + animation_t *anim; + + lf->animationNumber = newAnimation; + newAnimation &= ~ANIM_TOGGLEBIT; + + if ( newAnimation < 0 || newAnimation >= MAX_WP_ANIMATIONS ) { + CG_Error( "Bad animation number (CG_SWLFA): %i", newAnimation ); + } + + anim = &wi->weapAnimations[ newAnimation ]; + + lf->animation = anim; + lf->animationTime = lf->frameTime + anim->initialLerp; + + if ( cg_debugAnim.integer & 2 ) { + CG_Printf( "Weap Anim: %d\n", newAnimation ); + } +} + + +/* +=============== +CG_ClearWeapLerpFrame +=============== +*/ +void CG_ClearWeapLerpFrame( weaponInfo_t *wi, lerpFrame_t *lf, int animationNumber ) { + lf->frameTime = lf->oldFrameTime = cg.time; + CG_SetWeapLerpFrameAnimation( wi, lf, animationNumber ); + lf->oldFrame = lf->frame = lf->animation->firstFrame; + +} + + +/* +=============== +CG_RunWeapLerpFrame + +Sets cg.snap, cg.oldFrame, and cg.backlerp +cg.time should be between oldFrameTime and frameTime after exit +=============== +*/ +static void CG_RunWeapLerpFrame( clientInfo_t *ci, weaponInfo_t *wi, lerpFrame_t *lf, int newAnimation, float speedScale ) { + int f; + animation_t *anim; + + // debugging tool to get no animations + if ( cg_animSpeed.integer == 0 ) { + lf->oldFrame = lf->frame = lf->backlerp = 0; + return; + } + + // see if the animation sequence is switching + if ( !lf->animation ) { + CG_ClearWeapLerpFrame( wi, lf, newAnimation ); + } else if ( newAnimation != lf->animationNumber ) { + if ( ( newAnimation & ~ANIM_TOGGLEBIT ) == WEAP_RAISE || + ( newAnimation & ~ANIM_TOGGLEBIT ) == WEAP_ALTSWITCHFROM || + ( newAnimation & ~ANIM_TOGGLEBIT ) == WEAP_ALTSWITCHTO ) { + CG_ClearWeapLerpFrame( wi, lf, newAnimation ); // clear when switching to raise (since it should be out of view anyway) + } else { + CG_SetWeapLerpFrameAnimation( wi, lf, newAnimation ); + } + } + // RF, if the animation number is the same, but we are using a different weapon, we need to reset the lf->animation + //else if ( memcmp( &wi->weapAnimations[newAnimation&~ANIM_TOGGLEBIT], lf->animation, sizeof(*lf->animation) ) ) { + // CG_ClearWeapLerpFrame(wi, lf, newAnimation ); // clear when switching to raise (since it should be out of view anyway) + //} + + // if we have passed the current frame, move it to + // oldFrame and calculate a new frame + if ( cg.time >= lf->frameTime ) { + lf->oldFrame = lf->frame; + lf->oldFrameTime = lf->frameTime; + + // get the next frame based on the animation + anim = lf->animation; + if ( !anim->frameLerp ) { + return; // shouldn't happen + } + if ( cg.time < lf->animationTime ) { + lf->frameTime = lf->animationTime; // initial lerp + } else { + lf->frameTime = lf->oldFrameTime + anim->frameLerp; + } + f = ( lf->frameTime - lf->animationTime ) / anim->frameLerp; + f *= speedScale; // adjust for haste, etc + if ( f >= anim->numFrames ) { + f -= anim->numFrames; + if ( anim->loopFrames ) { + f %= anim->loopFrames; + f += anim->numFrames - anim->loopFrames; + } else { + f = anim->numFrames - 1; + // the animation is stuck at the end, so it + // can immediately transition to another sequence + lf->frameTime = cg.time; + } + } + lf->frame = anim->firstFrame + f; + if ( cg.time > lf->frameTime ) { + lf->frameTime = cg.time; + if ( cg_debugAnim.integer ) { +// CG_Printf( "Clamp lf->frameTime\n"); + } + } + } + + if ( lf->frameTime > cg.time + 200 ) { + lf->frameTime = cg.time; + } + + if ( lf->oldFrameTime > cg.time ) { + lf->oldFrameTime = cg.time; + } + // calculate current lerp value + if ( lf->frameTime == lf->oldFrameTime ) { + lf->backlerp = 0; + } else { + lf->backlerp = 1.0 - (float)( cg.time - lf->oldFrameTime ) / ( lf->frameTime - lf->oldFrameTime ); + } +} + + + +/* +============== +CG_WeaponAnimation +============== +*/ + +//----(SA) modified. this is now client-side only (server does not dictate weapon animation info) +static void CG_WeaponAnimation( playerState_t *ps, weaponInfo_t *weapon, int *weapOld, int *weap, float *weapBackLerp ) { + + centity_t *cent = &cg.predictedPlayerEntity; + clientInfo_t *ci = &cgs.clientinfo[ ps->clientNum ]; + + if ( cg_noPlayerAnims.integer ) { + *weapOld = *weap = 0; + return; + } + + CG_RunWeapLerpFrame( ci, weapon, ¢->pe.weap, ps->weapAnim, 1 ); + + *weapOld = cent->pe.weap.oldFrame; + *weap = cent->pe.weap.frame; + *weapBackLerp = cent->pe.weap.backlerp; + + if ( cg_debugAnim.integer == 3 ) { + CG_Printf( "oldframe: %d frame: %d backlerp: %f\n", cent->pe.weap.oldFrame, cent->pe.weap.frame, cent->pe.weap.backlerp ); + } +} + +//////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////// + + +// (SA) it wasn't used anyway + + +/* +============== +CG_CalculateWeaponPosition +============== +*/ +static void CG_CalculateWeaponPosition( vec3_t origin, vec3_t angles ) { + float scale; + int delta; + float fracsin, leanscale; + + VectorCopy( cg.refdef.vieworg, origin ); + VectorCopy( cg.refdefViewAngles, angles ); + + // adjust 'lean' into weapon + if ( cg.predictedPlayerState.leanf != 0 ) { + vec3_t right, up; + + leanscale = 1.0f; + + switch ( cg.predictedPlayerState.weapon ) { + case WP_GARAND: + leanscale = 3.0f; + break; + case WP_FLAMETHROWER: + case WP_TESLA: + case WP_MAUSER: + leanscale = 2.0f; + break; + + // never adjust + case WP_KNIFE: + case WP_GRENADE_LAUNCHER: + case WP_GRENADE_PINEAPPLE: + break; + + // adjust when leaning right (in case of reload) + default: + if ( cg.predictedPlayerState.leanf > 0 ) { + leanscale = 1.3f; + } + break; + } + + // reverse the roll on the weapon so it stays relatively level + angles[ROLL] -= cg.predictedPlayerState.leanf / ( leanscale * 2.0f ); + AngleVectors( angles, NULL, right, up ); + VectorMA( origin, angles[ROLL], right, origin ); + + // pitch the gun down a bit to show that firing is not allowed when leaning + angles[PITCH] += ( abs( cg.predictedPlayerState.leanf ) / 2.0f ); + + // this gives you some impression that the weapon stays in relatively the same + // position while you lean, so you appear to 'peek' over the weapon + AngleVectors( cg.refdefViewAngles, NULL, right, NULL ); + VectorMA( origin, -cg.predictedPlayerState.leanf / 4.0f, right, origin ); + } + + + // on odd legs, invert some angles + if ( cg.bobcycle & 1 ) { + scale = -cg.xyspeed; + } else { + scale = cg.xyspeed; + } + + // gun angles from bobbing + + angles[ROLL] += scale * cg.bobfracsin * 0.005; + angles[YAW] += scale * cg.bobfracsin * 0.01; + angles[PITCH] += cg.xyspeed * cg.bobfracsin * 0.005; + + // drop the weapon when landing + delta = cg.time - cg.landTime; + if ( delta < LAND_DEFLECT_TIME ) { + origin[2] += cg.landChange * 0.25 * delta / LAND_DEFLECT_TIME; + } else if ( delta < LAND_DEFLECT_TIME + LAND_RETURN_TIME ) { + origin[2] += cg.landChange * 0.25 * + ( LAND_DEFLECT_TIME + LAND_RETURN_TIME - delta ) / LAND_RETURN_TIME; + } + +#if 0 + // drop the weapon when stair climbing + delta = cg.time - cg.stepTime; + if ( delta < STEP_TIME / 2 ) { + origin[2] -= cg.stepChange * 0.25 * delta / ( STEP_TIME / 2 ); + } else if ( delta < STEP_TIME ) { + origin[2] -= cg.stepChange * 0.25 * ( STEP_TIME - delta ) / ( STEP_TIME / 2 ); + } +#endif + + // idle drift +//----(SA) adjustment for MAX KAUFMAN +// scale = cg.xyspeed + 40; + scale = 80; +//----(SA) end + fracsin = sin( cg.time * 0.001 ); + angles[ROLL] += scale * fracsin * 0.01; + angles[YAW] += scale * fracsin * 0.01; + angles[PITCH] += scale * fracsin * 0.01; + + // RF, subtract the kickAngles + VectorMA( angles, -1.0, cg.kickAngles, angles ); + +} + + +// Ridah +/* +=============== +CG_FlamethrowerFlame +=============== +*/ +static void CG_FlamethrowerFlame( centity_t *cent, vec3_t origin ) { + + if ( cent->currentState.weapon != WP_FLAMETHROWER ) { + return; + } + + if ( cent->currentState.number == cg.snap->ps.clientNum ) { + if ( cg.snap->ps.weapon != WP_FLAMETHROWER || ( cg.snap->ps.weaponstate != WEAPON_FIRING && cg.snap->ps.weaponstate != WEAPON_READY ) ) { + return; + } + } + +// if (cent->currentState.aiChar) +// CG_FireFlameChunks( cent, origin, cent->lerpAngles, 650.0 / FLAMETHROWER_RANGE, qtrue, 0 ); // fixed length for AI +// else + CG_FireFlameChunks( cent, origin, cent->lerpAngles, 1.0, qtrue, 0 ); + + return; +} +// done. + +/* +====================== +CG_MachinegunSpinAngle +====================== +*/ +//#define SPIN_SPEED 0.9 +//#define COAST_TIME 1000 +#define SPIN_SPEED 1 +#define COAST_TIME 2000 + +// TTimo: unused +/* +static float CG_MachinegunSpinAngle( centity_t *cent ) { + int delta; + float angle; + float speed; + + delta = cg.time - cent->pe.barrelTime; + if ( cent->pe.barrelSpinning ) { + angle = cent->pe.barrelAngle + delta * SPIN_SPEED; + } else { + if ( delta > COAST_TIME ) { + delta = COAST_TIME; + } + + speed = 0.5 * ( SPIN_SPEED + (float)( COAST_TIME - delta ) / COAST_TIME ); + angle = cent->pe.barrelAngle + delta * speed; + } + + if ( cent->pe.barrelSpinning == !(cent->currentState.eFlags & EF_FIRING) ) { + cent->pe.barrelTime = cg.time; + cent->pe.barrelAngle = AngleMod( angle ); + cent->pe.barrelSpinning = !!(cent->currentState.eFlags & EF_FIRING); + } + + return angle; +} +*/ + +/* +============== +CG_TeslaSpinAngle +============== +*/ + +//#define TESLA_SPINSPEED .2 +//#define TESLA_COASTTIME 2000 +#define TESLA_SPINSPEED .05 +#define TESLA_IDLESPEED .15 +#define TESLA_COASTTIME 1000 + +static float CG_TeslaSpinAngle( centity_t *cent ) { + int delta; + float angle; + float speed; + + delta = cg.time - cent->pe.barrelTime; + + angle = cent->pe.barrelAngle; + + if ( cent->currentState.eFlags & EF_FIRING ) { + angle += delta * TESLA_SPINSPEED; + } else { + angle += delta * TESLA_IDLESPEED; + } + + cent->pe.barrelAngle = AngleMod( angle ); + + cent->pe.barrelTime = cg.time; + + return AngleMod( angle ); + +//----(SA) trying new tesla effect scheme for MK +// angle = -(cent->pe.barrelAngle + delta * TESLA_SPINSPEED); +// cent->pe.barrelAngle = AngleMod( angle ); + +// if(cent->currentState.eFlags & EF_FIRING) +// cent->pe.barrelAngle += delta * TESLA_SPINSPEED; +// else +// cent->pe.barrelAngle += delta * TESLA_IDLESPEED; + + return AngleMod( cent->pe.barrelAngle ); + + + + + + return angle; + + + if ( cent->pe.barrelSpinning ) { + angle = -( cent->pe.barrelAngle + delta * TESLA_SPINSPEED ); + } else { + if ( delta > TESLA_COASTTIME ) { + delta = TESLA_COASTTIME; + } + + speed = 0.5 * ( TESLA_SPINSPEED + (float)( TESLA_COASTTIME - delta ) / TESLA_COASTTIME ); + angle = -( cent->pe.barrelAngle + delta * speed ); + } + + if ( cent->pe.barrelSpinning == !( cent->currentState.eFlags & EF_FIRING ) ) { + cent->pe.barrelTime = cg.time; + cent->pe.barrelAngle = AngleMod( angle ); + cent->pe.barrelSpinning = !!( cent->currentState.eFlags & EF_FIRING ); + } + + return angle; +} + + +//----(SA) added + +/* +====================== +CG_VenomSpinAngle +====================== +*/ + +#define VENOM_LOADTIME 2000 +#define VENOM_DELTATIME ( VENOM_LOADTIME / 10 ) // as there are 10 shots to be loaded + +static float CG_VenomSpinAngle( centity_t *cent ) { + int delta; + float ramp; + float angle; + float speed; + qboolean firing; + + delta = cg.time - cent->pe.barrelTime; + + ramp = delta % VENOM_DELTATIME; + + firing = (qboolean)( cent->currentState.eFlags & EF_FIRING ); + +// if((cent->pe.weap.animationNumber & ~ANIM_TOGGLEBIT) >= WEAP_DROP) + if ( cg.snap->ps.weaponstate != WEAPON_FIRING ) { // (SA) this seems better + firing = qfalse; + } + + + delta = cg.time - cent->pe.barrelTime; + if ( cent->pe.barrelSpinning ) { + angle = cent->pe.barrelAngle + delta * SPIN_SPEED; + } else { + if ( delta > COAST_TIME ) { + delta = COAST_TIME; + } + + speed = 0.5 * ( SPIN_SPEED + (float)( COAST_TIME - delta ) / COAST_TIME ); + angle = cent->pe.barrelAngle + delta * speed; + } + + if ( cent->pe.barrelSpinning == !firing ) { + cent->pe.barrelTime = cg.time; + cent->pe.barrelAngle = AngleMod( angle ); + cent->pe.barrelSpinning = !!firing; + + // just switching between not spinning and spinning, play the appropriate weapon sound + if ( cent->pe.barrelSpinning ) { + if ( cg_weapons[WP_VENOM].spinupSound ) { + trap_S_StartSoundEx( NULL, cent->currentState.number, CHAN_WEAPON, cg_weapons[WP_VENOM].spinupSound, SND_OKTOCUT ); + } + } else { + if ( cg_weapons[WP_VENOM].spindownSound ) { + trap_S_StartSound( NULL, cent->currentState.number, CHAN_WEAPON, cg_weapons[WP_VENOM].spindownSound ); + } + } + + } + + return angle; +} + + + + +/* +============== +CG_DrawRealWeapons +============== +*/ +qboolean CG_DrawRealWeapons( centity_t *cent ) { + + switch ( cent->currentState.aiChar ) { + case AICHAR_LOPER: + case AICHAR_SUPERSOLDIER: //----(SA) added + case AICHAR_PROTOSOLDIER: + case AICHAR_ZOMBIE: + case AICHAR_HELGA: //----(SA) added // boss1 is now helga-blob + case AICHAR_WARZOMBIE: + return qfalse; + } + + return qtrue; +} + + +/* +======================== +CG_AddWeaponWithPowerups +======================== +*/ +static void CG_AddWeaponWithPowerups( refEntity_t *gun, int powerups, playerState_t *ps, centity_t *cent ) { + + + // add powerup effects + if ( powerups & ( 1 << PW_INVIS ) ) { + gun->customShader = cgs.media.invisShader; + trap_R_AddRefEntityToScene( gun ); + } else { + trap_R_AddRefEntityToScene( gun ); + + if ( powerups & ( 1 << PW_BATTLESUIT ) ) { + gun->customShader = cgs.media.battleWeaponShader; + trap_R_AddRefEntityToScene( gun ); + } + if ( powerups & ( 1 << PW_QUAD ) ) { + gun->customShader = cgs.media.quadWeaponShader; + trap_R_AddRefEntityToScene( gun ); + } + } +/* + if (ps && ps->clientNum == cg.snap->ps.clientNum) { + float alpha, adjust; + weaponInfo_t *weapon; + + weapon = &cg_weapons[ps->weapon]; + //if (gun->hModel == weapon->handsModel) +// if (cg.snap->ps.onFireStart) + { + + // add the flames if on fire +// alpha = 2.0 * (float)(FIRE_FLASH_TIME - (cg.time - cg.snap->ps.onFireStart))/FIRE_FLASH_TIME; +alpha = 1; + if (alpha > 0) { + if (alpha >= 1.0) { + alpha = 1.0; + } + gun->shaderRGBA[3] = (unsigned char)(255.0*alpha); + // calc the fireRiseDir from the velocity + VectorNegate( cg.snap->ps.velocity, gun->fireRiseDir ); + VectorNormalize( gun->fireRiseDir ); + gun->fireRiseDir[2] += 1; + if (VectorNormalize( gun->fireRiseDir ) < 1) { + VectorClear( gun->fireRiseDir ); + gun->fireRiseDir[2] = 1; + } + // now move towards the newDir + adjust = 5.0*(0.001*cg.frametime); + VectorMA( cg.v_fireRiseDir, adjust, gun->fireRiseDir, cg.v_fireRiseDir ); + if (VectorNormalize( cg.v_fireRiseDir ) <= 0.1) { + VectorCopy( gun->fireRiseDir, cg.v_fireRiseDir ); + } + VectorCopy( cg.v_fireRiseDir, gun->fireRiseDir ); + +// gun->reFlags |= REFLAG_ONLYHAND; +gun->customShader = cgs.media.dripWetShader2; +// gun->customShader = cgs.media.onFireShader; + trap_R_AddRefEntityToScene( gun ); +// gun->shaderTime = 500; +// trap_R_AddRefEntityToScene( gun ); +gun->customShader = cgs.media.dripWetShader; +// gun->customShader = cgs.media.onFireShader2; + trap_R_AddRefEntityToScene( gun ); +// gun->reFlags &= ~REFLAG_ONLYHAND; + } + } + } +*/ +} + +/* +============== +CG_PlayerTeslaCoilFire + + TODO: this needs to be fixed for multiplay. entities being hurt need to be sent + by server to all clients, so they draw the correct effects. +============== +*/ +void CG_PlayerTeslaCoilFire( centity_t *cent, vec3_t flashorigin ) { + +#define TESLA_LIGHTNING_POINT_TIMEOUT 3000 +#define TESLA_LIGHTNING_MAX_DIST ( cent->currentState.aiChar == AICHAR_SUPERSOLDIER ? TESLA_SUPERSOLDIER_RANGE : TESLA_RANGE ) // use these to perhaps vary the distance according to aiming +#define TESLA_LIGHTNING_NORMAL_DIST ( TESLA_RANGE / 2.0 ) +#define TESLA_MAX_POINT_TESTS 10 +#define TESLA_MAX_POINT_TESTS_PERFRAME 20 + + int i, j, pointTests = 0; + vec3_t testPos, tagPos, vec; + trace_t tr; + float maxDist; + int numPoints; + vec3_t viewAngles, viewDir; + int visEnemies[16]; + float visDists[16]; + int visEnemiesSorted[MAX_TESLA_BOLTS]; + int numEnemies, numSorted = 0, best; // TTimo: init + float bestDist; + centity_t *ctrav; + vec3_t traceOrg; + int playerTeam; + + if ( cent->currentState.weapon != WP_TESLA ) { + return; + } + +// JPW NERVE no tesla in multiplayer + if ( cg_gameType.integer != GT_SINGLE_PLAYER ) { + return; + } + + //if (cent->currentState.number == cg.snap->ps.clientNum) + // VectorCopy( cg.snap->ps.viewangles, viewAngles ); + //else + VectorCopy( cent->lerpAngles, viewAngles ); + + AngleVectors( viewAngles, viewDir, NULL, NULL ); + + if ( cent->currentState.number == cg.snap->ps.clientNum ) { + VectorCopy( cg.snap->ps.origin, traceOrg ); + playerTeam = cg.snap->ps.teamNum; + } else { + VectorCopy( cent->lerpOrigin, traceOrg ); + playerTeam = cent->currentState.teamNum; + } + + maxDist = TESLA_LIGHTNING_MAX_DIST; + numPoints = MAX_TESLA_BOLTS; + + VectorCopy( flashorigin, tagPos ); + + // first, build a list of visible enemies that can be hurt by this tesla, then filter by distance + if ( !cent->pe.teslaDamageApplyTime || cent->pe.teslaDamageApplyTime < cg.time - 200 ) { + numEnemies = 0; + // check the local playing client + VectorSubtract( cg.snap->ps.origin, traceOrg, vec ); + VectorNormalize( vec ); + if ( ( cent != &cg_entities[cg.snap->ps.clientNum] ) && + ( cg.snap->ps.teamNum != playerTeam ) && + ( Distance( tagPos, cg.snap->ps.origin ) < TESLA_LIGHTNING_MAX_DIST ) && + ( DotProduct( viewDir, vec ) > 0.8 ) ) { + CG_Trace( &tr, traceOrg, NULL, NULL, cg.snap->ps.origin, cg.snap->ps.clientNum, MASK_SHOT & ~( CONTENTS_BODY ) ); + if ( tr.fraction == 1 || tr.entityNum == cg.snap->ps.clientNum ) { + visDists[numEnemies] = Distance( tagPos, cg.snap->ps.origin ); + visEnemies[numEnemies++] = cg.snap->ps.clientNum; + } else { // try head + VectorCopy( cg.snap->ps.origin, vec ); + vec[2] += cg.snap->ps.viewheight; + CG_Trace( &tr, tagPos, NULL, NULL, vec, cg.snap->ps.clientNum, MASK_SHOT & ~( CONTENTS_BODY ) ); + if ( tr.fraction == 1 || tr.entityNum == cg.snap->ps.clientNum ) { + visDists[numEnemies] = Distance( tagPos, cg.snap->ps.origin ); + visEnemies[numEnemies++] = cg.snap->ps.clientNum; + } else { // try body, from tag + VectorCopy( cg.snap->ps.origin, vec ); + CG_Trace( &tr, tagPos, NULL, NULL, vec, cg.snap->ps.clientNum, MASK_SHOT & ~( CONTENTS_BODY ) ); + if ( tr.fraction == 1 || tr.entityNum == cg.snap->ps.clientNum ) { + visDists[numEnemies] = Distance( tagPos, cg.snap->ps.origin ); + visEnemies[numEnemies++] = cg.snap->ps.clientNum; + } + } + } + } + + if ( cgs.localServer && cgs.gametype == GT_SINGLE_PLAYER ) { + // check for AI's getting hurt (TODO: bot support?) + for ( ctrav = cg_entities, i = 0; i < cgs.maxclients && numEnemies < 16; ctrav++, i++ ) { + // RF, proto and supersoldier are invulnerable to tesla +/* switch (ctrav->currentState.aiChar) { + case AICHAR_SUPERSOLDIER: + case AICHAR_PROTOSOLDIER: + continue; + } +*/ // + if ( ctrav->currentState.aiChar && + ( ctrav != cent ) && + ( ctrav->currentState.teamNum != playerTeam ) && + !( ctrav->currentState.eFlags & EF_DEAD ) && + ctrav->currentValid && // is in the visible frame + ( Distance( tagPos, ctrav->lerpOrigin ) < TESLA_LIGHTNING_MAX_DIST ) ) { + VectorSubtract( ctrav->lerpOrigin, traceOrg, vec ); + VectorNormalize( vec ); + + if ( DotProduct( viewDir, vec ) > 0.8 ) { + CG_Trace( &tr, traceOrg, NULL, NULL, ctrav->lerpOrigin, ctrav->currentState.number, MASK_SHOT & ~CONTENTS_BODY ); + if ( tr.fraction == 1 || tr.entityNum == ctrav->currentState.number ) { + visDists[numEnemies] = Distance( tagPos, ctrav->lerpOrigin ); + visEnemies[numEnemies++] = ctrav->currentState.number; + } + } + } + } + } + + // now sort by distance + for ( j = 0; j < MAX_TESLA_BOLTS; j++ ) { + visEnemiesSorted[j] = -1; + + bestDist = 99999; + best = -1; + for ( i = 0; i < numEnemies; i++ ) { + if ( visEnemies[i] < 0 ) { + continue; + } + if ( visDists[i] < bestDist ) { + bestDist = visDists[i]; + visEnemiesSorted[j] = visEnemies[i]; + best = i; + } + } + + if ( best >= 0 ) { + visEnemies[best] = -1; + numSorted = j + 1; + } + } + + // now fill in the teslaEnemy[]'s + for ( i = 0; i < MAX_TESLA_BOLTS; i++ ) { + if ( numSorted && i / numSorted < 1 /*(MAX_TESLA_BOLTS/3)*/ ) { // bolts per enemy + j = i % numSorted; + cent->pe.teslaEnemy[i] = visEnemiesSorted[j]; + // apply damage + CG_ClientDamage( visEnemiesSorted[j], cent->currentState.number, CLDMG_TESLA ); + // show the effect + cg_entities[ visEnemiesSorted[j] ].pe.teslaDamagedTime = cg.time; + } else { + if ( cent->pe.teslaEnemy[i] >= 0 ) { + cent->pe.teslaEndPointTimes[i] = 0; // make sure we find a new spot + } + cent->pe.teslaEnemy[i] = -1; + } + } + cent->pe.teslaDamageApplyTime = cg.time; + } + + for ( i = 0; i < numPoints; i++ ) { + + //if (!(rand()%3)) + // continue; + + VectorSubtract( cent->pe.teslaEndPoints[i], tagPos, vec ); + VectorNormalize( vec ); + + // if this point has timed out, find a new spot + if ( cent->pe.teslaEnemy[i] >= 0 ) { + // attacking the player + VectorSet( testPos, 6 * crandom(), + 6 * crandom(), + 20 * crandom() - 8 ); + //VectorClear( testPos ); + if ( cent->pe.teslaEnemy[i] != cg.snap->ps.clientNum ) { + VectorAdd( testPos, cg_entities[cent->pe.teslaEnemy[i]].lerpOrigin, testPos ); + } else { + VectorAdd( testPos, cg.snap->ps.origin, testPos ); + } + cent->pe.teslaEndPointTimes[i] = cg.time; // - rand()%(TESLA_LIGHTNING_POINT_TIMEOUT/2); + VectorCopy( testPos, cent->pe.teslaEndPoints[i] ); + } else if ( ( !cent->pe.teslaEndPointTimes[i] ) || + ( cent->pe.teslaEndPointTimes[i] > cg.time ) || + ( cent->pe.teslaEndPointTimes[i] < cg.time - TESLA_LIGHTNING_POINT_TIMEOUT ) || + ( VectorDistance( tagPos, cent->pe.teslaEndPoints[i] ) > maxDist ) || + ( DotProduct( viewDir, vec ) < 0.7 ) ) { + + //if (cent->currentState.groundEntityNum == ENTITYNUM_NONE) + // continue; // must be on the ground + + // find a new spot + for ( j = 0; j < TESLA_MAX_POINT_TESTS; j++ ) { + VectorSet( testPos, cg.refdef.fov_y * crandom() * 0.5, + cg.refdef.fov_x * crandom() * 0.5, + 0 ); + VectorAdd( viewAngles, testPos, testPos ); + AngleVectors( testPos, vec, NULL, NULL ); + VectorMA( tagPos, TESLA_LIGHTNING_NORMAL_DIST, vec, testPos ); + // try a trace to find a world collision + CG_Trace( &tr, tagPos, NULL, NULL, testPos, cent->currentState.number, MASK_SHOT & ~CONTENTS_BODY ); + if ( tr.fraction < 1 && tr.entityNum == ENTITYNUM_WORLD && !( tr.surfaceFlags & ( SURF_NOIMPACT | SURF_SKY ) ) ) { + // found a valid spot! + cent->pe.teslaEndPointTimes[i] = cg.time - rand() % ( TESLA_LIGHTNING_POINT_TIMEOUT / 2 ); + VectorCopy( tr.endpos, cent->pe.teslaEndPoints[i] ); + break; + } + if ( pointTests++ > TESLA_MAX_POINT_TESTS_PERFRAME ) { + j = TESLA_MAX_POINT_TESTS; + continue; + } + } + if ( j == TESLA_MAX_POINT_TESTS ) { + continue; // just don't draw this point + } + + // add an impact mark on the wall + VectorSubtract( cent->pe.teslaEndPoints[i], tagPos, vec ); + VectorNormalize( vec ); + VectorInverse( vec ); + CG_ImpactMark( cgs.media.lightningHitWallShader, cent->pe.teslaEndPoints[i], vec, random() * 360, 0.2, 0.2, 0.2, 1.0, qtrue, 4, qfalse, 300 ); + } + // + // we have a valid lightning point, so draw it + // sanity check though to make sure it's valid + if ( VectorDistance( tagPos, cent->pe.teslaEndPoints[i] ) <= maxDist ) { + CG_DynamicLightningBolt( cgs.media.lightningBoltShader, tagPos, cent->pe.teslaEndPoints[i], 1 + ( ( cg.time % ( ( i + 2 ) * ( i + 3 ) ) ) + i ) % 2, 20 + (float)( i % 3 ) * 5 + 6.0 * random(), ( cent->pe.teslaEnemy[i] < 0 ), 1.0, 0, i * i * 3 ); + + // play a zap sound + if ( cent->pe.lightningSoundTime < cg.time - 200 ) { + CG_SoundPlayIndexedScript( cgs.media.teslaZapScript, cent->pe.teslaEndPoints[i], ENTITYNUM_WORLD ); + CG_SoundPlayIndexedScript( cgs.media.teslaZapScript, cent->lerpOrigin, ENTITYNUM_WORLD ); + //trap_S_StartSound( cent->pe.teslaEndPoints[i], ENTITYNUM_WORLD, CHAN_AUTO, cgs.media.lightningSounds[rand()%3] ); + cent->pe.lightningSoundTime = cg.time + rand() % 200; + } + } + } + + if ( cg.time % 3 ) { // break it up a bit + // add the looping sound + trap_S_AddLoopingSound( cent->currentState.number, cent->lerpOrigin, vec3_origin, cgs.media.teslaLoopSound, 255 ); + } + + // drop a dynamic light out infront of us + AngleVectors( viewAngles, vec, NULL, NULL ); + VectorMA( tagPos, 300, vec, testPos ); + // try a trace to find a world collision + CG_Trace( &tr, tagPos, NULL, NULL, testPos, cent->currentState.number, MASK_SOLID ); + + if ( ( cg.time / 50 ) % ( 4 + ( cg.time % 4 ) ) == 0 ) { + // alt light + trap_R_AddLightToScene( tr.endpos, 256 + 600 * tr.fraction, 0.2, 0.6, 1, 1 ); + } else if ( ( cg.time / 50 ) % ( 4 + ( cg.time % 4 ) ) == 1 ) { + // no light + //trap_R_AddLightToScene( tr.endpos, 128 + 500*tr.fraction, 1, 1, 1, 10 ); + } else { + // blue light + trap_R_AddLightToScene( tr.endpos, 256 + 600 * tr.fraction, 0.2, 0.6, 1, 0 ); + } + + + // shake the camera a bit + CG_StartShakeCamera( 0.05, 200, cent->lerpOrigin, 100 ); + +} + +//----(SA) +/* +============== +CG_AddProtoWeapons +============== +*/ +void CG_AddProtoWeapons( refEntity_t *parent, playerState_t *ps, centity_t *cent ) { + refEntity_t gun; + + return; + + if ( !( cent->currentState.aiChar == AICHAR_PROTOSOLDIER ) ) { + return; + } + memset( &gun, 0, sizeof( gun ) ); + VectorCopy( parent->lightingOrigin, gun.lightingOrigin ); +// gun.hModel = cgs.media.protoWeapon; + gun.shadowPlane = parent->shadowPlane; + gun.renderfx = parent->renderfx; + CG_PositionEntityOnTag( &gun, parent, "tag_armright", 0, NULL ); + CG_AddWeaponWithPowerups( &gun, cent->currentState.powerups, ps, cent ); +} +//----(SA) end + + + +// Ridah +/* +============== +CG_MonsterUsingWeapon +============== +*/ +qboolean CG_MonsterUsingWeapon( centity_t *cent, int aiChar, int weaponNum ) { + return ( cent->currentState.aiChar == aiChar ) && ( cent->currentState.weapon == weaponNum ); +} + + + + + +/* +============= +CG_AddPlayerWeapon + +Used for both the view weapon (ps is valid) and the world modelother character models (ps is NULL) +The main player will have this called for BOTH cases, so effects like light and +sound should only be done on the world model case. +============= +*/ +static qboolean debuggingweapon = qfalse; + +void CG_AddPlayerWeapon( refEntity_t *parent, playerState_t *ps, centity_t *cent ) { + + refEntity_t gun; + refEntity_t barrel; + refEntity_t flash; + vec3_t angles; + weapon_t weaponNum, weapSelect; + weaponInfo_t *weapon; + centity_t *nonPredictedCent; + qboolean firing; // Ridah + + qboolean akimboFire = qfalse; //----(SA) added + + qboolean playerScaled; + qboolean drawpart, drawrealweap; + int i; + qboolean isPlayer; + + // (SA) might as well have this check consistant throughout the routine + isPlayer = (qboolean)( cent->currentState.clientNum == cg.snap->ps.clientNum ); + + weaponNum = cent->currentState.weapon; + weapSelect = cg.weaponSelect; + + if ( ps && cg.cameraMode ) { + return; + } + + // don't draw any weapons when the binocs are up + if ( cent->currentState.eFlags & EF_ZOOMING ) { + if ( isPlayer ) { + if ( !cg.renderingThirdPerson ) { + return; + } + } else { + return; + } + } + + // don't draw weapon stuff when looking through a scope + if ( weaponNum == WP_SNOOPERSCOPE || weaponNum == WP_SNIPERRIFLE || weaponNum == WP_FG42SCOPE || + weapSelect == WP_SNOOPERSCOPE || weapSelect == WP_SNIPERRIFLE || weapSelect == WP_FG42SCOPE ) { + if ( isPlayer && !cg.renderingThirdPerson ) { + return; + } + } + + // no weapon when on mg_42 + if ( cent->currentState.eFlags & EF_MG42_ACTIVE ) { + return; + } + + // DHM - Nerve :: Special case for WP_CLASS_SPECIAL + if ( cgs.gametype == GT_WOLF && weaponNum == WP_CLASS_SPECIAL ) { + switch ( cent->currentState.teamNum ) { + case PC_ENGINEER: + CG_RegisterWeapon( WP_CLASS_SPECIAL ); + weapon = &cg_weapons[WP_CLASS_SPECIAL]; + break; + case PC_MEDIC: + CG_RegisterWeapon( WP_MEDIC_HEAL ); + weapon = &cg_weapons[WP_MEDIC_HEAL]; + break; + case PC_LT: + CG_RegisterWeapon( WP_GRENADE_SMOKE ); + weapon = &cg_weapons[WP_GRENADE_SMOKE]; + break; + default: + CG_RegisterWeapon( weaponNum ); + weapon = &cg_weapons[weaponNum]; + break; + } + } else { + CG_RegisterWeapon( weaponNum ); + weapon = &cg_weapons[weaponNum]; + } + // dhm - end + + + if ( isPlayer ) { + akimboFire = BG_AkimboFireSequence( weaponNum, cg.predictedPlayerState.ammoclip[WP_AKIMBO], cg.predictedPlayerState.ammoclip[WP_COLT] ); + } else if ( ps ) { + akimboFire = BG_AkimboFireSequence( weaponNum, ps->ammoclip[WP_AKIMBO], ps->ammoclip[WP_AKIMBO] ); + } + + // add the weapon + memset( &gun, 0, sizeof( gun ) ); + VectorCopy( parent->lightingOrigin, gun.lightingOrigin ); + gun.shadowPlane = parent->shadowPlane; + gun.renderfx = parent->renderfx; + + // set custom shading for railgun refire rate + if ( ps ) { + gun.shaderRGBA[0] = 255; + gun.shaderRGBA[1] = 255; + gun.shaderRGBA[2] = 255; + gun.shaderRGBA[3] = 255; + } + + if ( ps ) { + gun.hModel = weapon->weaponModel[W_FP_MODEL]; + } else { + CG_AddProtoWeapons( parent, ps, cent ); + // skeletal guys use a different third person weapon (for different tag business) + if ( cgs.clientinfo[ cent->currentState.clientNum ].isSkeletal && weapon->weaponModel[W_SKTP_MODEL] ) { + gun.hModel = weapon->weaponModel[W_SKTP_MODEL]; + } else { + gun.hModel = weapon->weaponModel[W_TP_MODEL]; + } + } + + if ( !gun.hModel ) { + if ( debuggingweapon ) { + CG_Printf( "returning due to: !gun.hModel\n" ); + } + return; + } + + if ( weaponNum == WP_GAUNTLET ) { // (SA) this is the 'knife'. no model yet, so we can give it to the zombie and have him visually 'unarmed' + if ( debuggingweapon ) { + CG_Printf( "returning due to: weaponNum == WP_GAUNTLET\n" ); + } + return; + } + + if ( !ps && cg.snap->ps.pm_flags & PMF_LADDER && isPlayer ) { //----(SA) player on ladder + if ( debuggingweapon ) { + CG_Printf( "returning due to: !ps && cg.snap->ps.pm_flags & PMF_LADDER\n" ); + } + return; + } + + + if ( !ps ) { + // add weapon ready sound + cent->pe.lightningFiring = qfalse; + if ( ( cent->currentState.eFlags & EF_FIRING ) && weapon->firingSound ) { + // lightning gun and guantlet make a different sound when fire is held down + trap_S_AddLoopingSound( cent->currentState.number, cent->lerpOrigin, vec3_origin, weapon->firingSound, 255 ); + cent->pe.lightningFiring = qtrue; + } else if ( weapon->readySound ) { + trap_S_AddLoopingSound( cent->currentState.number, cent->lerpOrigin, vec3_origin, weapon->readySound, 255 ); + } + } + + + // Ridah + firing = ( ( cent->currentState.eFlags & EF_FIRING ) != 0 ); + + CG_PositionEntityOnTag( &gun, parent, "tag_weapon", 0, NULL ); + + playerScaled = (qboolean)( cgs.clientinfo[ cent->currentState.clientNum ].playermodelScale[0] != 0 ); + if ( !ps && playerScaled ) { // don't "un-scale" weap up in 1st person + for ( i = 0; i < 3; i++ ) { // scale weapon back up so it doesn't pick up the adjusted scale of the character models. + // this will affect any parts attached to the gun as well (barrel/bolt/flash/brass/etc.) + VectorScale( gun.axis[i], 1.0 / ( cgs.clientinfo[ cent->currentState.clientNum ].playermodelScale[i] ), gun.axis[i] ); + } + + } + + // characters that draw their own special weapon model will not draw the standard ones + if ( CG_DrawRealWeapons( cent ) ) { + drawrealweap = qtrue; + } else { + drawrealweap = qfalse; + } + + if ( ps ) { + drawpart = CG_GetPartFramesFromWeap( cent, &gun, parent, W_MAX_PARTS, weapon ); // W_MAX_PARTS specifies this as the primary view model + } else { + drawpart = qtrue; + } + + if ( drawpart && drawrealweap ) { + CG_AddWeaponWithPowerups( &gun, cent->currentState.powerups, ps, cent ); + } + + if ( isPlayer ) { + refEntity_t brass; + + // opposite tag in akimbo, since at this point the weapon + // has fired and the fire seq has switched over + if ( weaponNum == WP_AKIMBO && akimboFire ) { + CG_PositionRotatedEntityOnTag( &brass, &gun, "tag_brass2" ); + } else { + CG_PositionRotatedEntityOnTag( &brass, &gun, "tag_brass" ); + } + + VectorCopy( brass.origin, ejectBrassCasingOrigin ); + } + + memset( &barrel, 0, sizeof( barrel ) ); + VectorCopy( parent->lightingOrigin, barrel.lightingOrigin ); + barrel.shadowPlane = parent->shadowPlane; + barrel.renderfx = parent->renderfx; + + // add barrels + // attach generic weapon parts to the first person weapon. + // if a barrel should be attached for third person, add it in the (!ps) section below + angles[YAW] = angles[PITCH] = 0; + + if ( ps ) { + qboolean spunpart; + + for ( i = W_PART_1; i < W_MAX_PARTS; i++ ) { + + spunpart = qfalse; + barrel.hModel = weapon->wpPartModels[W_FP_MODEL][i]; + + // check for spinning + if ( weaponNum == WP_VENOM ) { + if ( i == W_PART_1 ) { + angles[ROLL] = CG_VenomSpinAngle( cent ); + spunpart = qtrue; + } else if ( i == W_PART_2 ) { + angles[ROLL] = -CG_VenomSpinAngle( cent ); + spunpart = qtrue; + } + // 'blurry' barel when firing + // (SA) not right now. at the moment, just spin the belt when firing, no swapout + else if ( i == W_PART_3 ) { + if ( ( cent->pe.weap.animationNumber & ~ANIM_TOGGLEBIT ) == WEAP_ATTACK1 ) { +// barrel.hModel = weapon->wpPartModels[W_FP_MODEL_SWAP][i]; + barrel.hModel = weapon->wpPartModels[W_FP_MODEL][i]; + angles[ROLL] = -CG_VenomSpinAngle( cent ); + angles[ROLL] = -( angles[ROLL] / 8.0f ); + } else { + angles[ROLL] = 0; + } + spunpart = qtrue; + } + + } else if ( weaponNum == WP_TESLA ) { + if ( i == W_PART_1 || i == W_PART_2 ) { + angles[ROLL] = CG_TeslaSpinAngle( cent ); + spunpart = qtrue; + } + } + + if ( spunpart ) { + AnglesToAxis( angles, barrel.axis ); + } + // end spinning + + + if ( barrel.hModel ) { + if ( i == W_PART_1 ) { + if ( spunpart ) { + CG_PositionRotatedEntityOnTag( &barrel, parent, "tag_barrel" ); + } else { CG_PositionEntityOnTag( &barrel, parent, "tag_barrel", 0, NULL );} + } else { + if ( spunpart ) { + CG_PositionRotatedEntityOnTag( &barrel, parent, va( "tag_barrel%d", i + 1 ) ); + } else { CG_PositionEntityOnTag( &barrel, parent, va( "tag_barrel%d", i + 1 ), 0, NULL );} + } + + drawpart = CG_GetPartFramesFromWeap( cent, &barrel, parent, i, weapon ); + + if ( drawpart && drawrealweap ) { + CG_AddWeaponWithPowerups( &barrel, cent->currentState.powerups, ps, cent ); + } + } + } + } else { // weapons with barrels drawn in third person + if ( drawrealweap ) { + if ( weaponNum == WP_VENOM ) { + + angles[ROLL] = CG_VenomSpinAngle( cent ); + AnglesToAxis( angles, barrel.axis ); + + barrel.hModel = weapon->wpPartModels[W_TP_MODEL][W_PART_1]; + CG_PositionRotatedEntityOnTag( &barrel, &gun, "tag_barrel" ); + CG_AddWeaponWithPowerups( &barrel, cent->currentState.powerups, ps, cent ); + } + } + } + + // add the scope model to the rifle if you've got it + if ( isPlayer && !cg.renderingThirdPerson ) { // (SA) for now just do it on the first person weapons + if ( weaponNum == WP_MAUSER ) { + if ( COM_BitCheck( cg.predictedPlayerState.weapons, WP_SNIPERRIFLE ) ) { + barrel.hModel = weapon->modModel[0]; + if ( barrel.hModel ) { + CG_PositionEntityOnTag( &barrel, &gun, "tag_scope", 0, NULL ); + CG_AddWeaponWithPowerups( &barrel, cent->currentState.powerups, ps, cent ); + } + } + } + } + + + // make sure we aren't looking at cg.predictedPlayerEntity for LG + nonPredictedCent = &cg_entities[cent->currentState.clientNum]; + + // if the index of the nonPredictedCent is not the same as the clientNum + // then this is a fake player (like on the single player podiums), so + // go ahead and use the cent + if ( ( nonPredictedCent - cg_entities ) != cent->currentState.clientNum ) { + nonPredictedCent = cent; + } + + + // add the flash + memset( &flash, 0, sizeof( flash ) ); + VectorCopy( parent->lightingOrigin, flash.lightingOrigin ); + flash.shadowPlane = parent->shadowPlane; + flash.renderfx = parent->renderfx; + + if ( ps ) { + flash.hModel = weapon->flashModel[W_FP_MODEL]; + } else { + flash.hModel = weapon->flashModel[W_TP_MODEL]; + } + + angles[YAW] = 0; + angles[PITCH] = 0; + angles[ROLL] = crandom() * 10; + AnglesToAxis( angles, flash.axis ); + + CG_PositionRotatedEntityOnTag( &flash, &gun, "tag_flash" ); + + // store this position for other cgame elements to access + cent->pe.gunRefEnt = gun; + cent->pe.gunRefEntFrame = cg.clientFrame; + + if ( ( weaponNum == WP_FLAMETHROWER || weaponNum == WP_TESLA ) && ( nonPredictedCent->currentState.eFlags & EF_FIRING ) ) { + // continuous flash + + } else { + + // continuous smoke after firing +#define BARREL_SMOKE_TIME 1000 + + if ( ps || cg.renderingThirdPerson || !isPlayer ) { + if ( weaponNum == WP_VENOM || weaponNum == WP_STEN ) { + if ( !cg_paused.integer ) { // don't add while paused + // hot smoking gun + if ( cg.time - cent->overheatTime < 3000 ) { + if ( !( rand() % 3 ) ) { + float alpha; + alpha = 1.0f - ( (float)( cg.time - cent->overheatTime ) / 3000.0f ); + alpha *= 0.25f; // .25 max alpha + if ( weaponNum == WP_VENOM ) { // silly thing that makes the smoke off the venom swirlier since it's spinning real fast + CG_ParticleImpactSmokePuffExtended( cgs.media.smokeParticleShader, flash.origin, tv( 0,0,1 ), 8, 1000, 8, 20, 70, alpha ); + } else { + CG_ParticleImpactSmokePuffExtended( cgs.media.smokeParticleShader, flash.origin, tv( 0,0,1 ), 8, 1000, 8, 20, 30, alpha ); + } + } + } + } + + } else if ( weaponNum == WP_PANZERFAUST ) { + if ( !cg_paused.integer ) { // don't add while paused + if ( cg.time - cent->muzzleFlashTime < BARREL_SMOKE_TIME ) { + if ( !( rand() % 5 ) ) { + float alpha; + alpha = 1.0f - ( (float)( cg.time - cent->muzzleFlashTime ) / (float)BARREL_SMOKE_TIME ); // what fraction of BARREL_SMOKE_TIME are we at + alpha *= 0.25f; // .25 max alpha + CG_ParticleImpactSmokePuffExtended( cgs.media.smokeParticleShader, flash.origin, tv( 0,0,1 ), 8, 1000, 8, 20, 30, alpha ); + } + } + } + } + } + + // impulse flash + if ( cg.time - cent->muzzleFlashTime > MUZZLE_FLASH_TIME ) { + // Ridah, blue ignition flame if not firing flamer + if ( weaponNum != WP_FLAMETHROWER && weaponNum != WP_TESLA ) { + return; + } + } + + } + + // weapons that don't need to go any further as they have no flash or light + if ( weaponNum == WP_GRENADE_LAUNCHER || + weaponNum == WP_GRENADE_PINEAPPLE || + weaponNum == WP_KNIFE || + weaponNum == WP_DYNAMITE ) { + return; + } + + if ( weaponNum == WP_STEN ) { // sten has no muzzleflash + flash.hModel = 0; + } + + // weaps with barrel smoke + if ( ps || cg.renderingThirdPerson || !isPlayer ) { + if ( !cg_paused.integer ) { // don't add while paused + if ( weaponNum == WP_STEN || weaponNum == WP_VENOM ) { + if ( cg.time - cent->muzzleFlashTime < 100 ) { +// CG_ParticleImpactSmokePuff (cgs.media.smokeParticleShader, flash.origin); + CG_ParticleImpactSmokePuffExtended( cgs.media.smokeParticleShader, flash.origin, tv( 0,0,1 ), 8, 500, 8, 20, 30, 0.25f ); + } + } + } + } + + if ( isPlayer ) { + if ( weaponNum == WP_AKIMBO ) { + if ( !cent->akimboFire ) { + CG_PositionRotatedEntityOnTag( &flash, &gun, "tag_flash2" ); + } + } + } + + + if ( flash.hModel ) { + if ( weaponNum != WP_FLAMETHROWER && weaponNum != WP_TESLA ) { //Ridah, hide the flash also for now + // RF, changed this so the muzzle flash stays onscreen for long enough to be seen + if ( cg.time - cent->muzzleFlashTime < MUZZLE_FLASH_TIME ) { +// if (firing) { // Ridah + trap_R_AddRefEntityToScene( &flash ); + } + } + } + + // Ridah, zombie fires from his head + //if (CG_MonsterUsingWeapon( cent, AICHAR_ZOMBIE, WP_MONSTER_ATTACK1 )) { + // CG_PositionEntityOnTag( &flash, parent, parent->hModel, "tag_head", NULL); + //} + + if ( ps || cg.renderingThirdPerson || !isPlayer ) { + + if ( firing ) { + // Ridah, Flamethrower effect + CG_FlamethrowerFlame( cent, flash.origin ); + + // RF, Tesla coil + CG_PlayerTeslaCoilFire( cent, flash.origin ); + + // make a dlight for the flash + if ( weapon->flashDlightColor[0] || weapon->flashDlightColor[1] || weapon->flashDlightColor[2] ) { + trap_R_AddLightToScene( flash.origin, 200 + ( rand() & 31 ), weapon->flashDlightColor[0], + weapon->flashDlightColor[1], weapon->flashDlightColor[2], 0 ); + } + } else { + if ( weaponNum == WP_FLAMETHROWER ) { + vec3_t angles; + AxisToAngles( flash.axis, angles ); + CG_FireFlameChunks( cent, flash.origin, angles, 1.0, qfalse, 0 ); + } + } + } +} + +void CG_AddPlayerFoot( refEntity_t *parent, playerState_t *ps, centity_t *cent ) { + refEntity_t wolfkick; + vec3_t kickangle; + weaponInfo_t *weapon; + weapon_t weaponNum; + int frame; + static int oldtime = 0; + + if ( !( cg.snap->ps.persistant[PERS_WOLFKICK] ) ) { + oldtime = 0; + return; + } + + weaponNum = cent->currentState.weapon; + weapon = &cg_weapons[weaponNum]; + + memset( &wolfkick, 0, sizeof( wolfkick ) ); + + VectorCopy( parent->lightingOrigin, wolfkick.lightingOrigin ); + wolfkick.shadowPlane = parent->shadowPlane; + + // note to self we want this to lerp and advance frame + wolfkick.renderfx = RF_DEPTHHACK | RF_FIRST_PERSON;; + wolfkick.hModel = wolfkickModel; + + VectorCopy( cg.refdef.vieworg, wolfkick.origin ); + //----(SA) allow offsets for testing boot model + if ( cg_gun_x.value ) { + VectorMA( wolfkick.origin, cg_gun_x.value, cg.refdef.viewaxis[0], wolfkick.origin ); + } + if ( cg_gun_y.value ) { + VectorMA( wolfkick.origin, cg_gun_y.value, cg.refdef.viewaxis[1], wolfkick.origin ); + } + if ( cg_gun_z.value ) { + VectorMA( wolfkick.origin, cg_gun_z.value, cg.refdef.viewaxis[2], wolfkick.origin ); + } + //----(SA) end + + + VectorCopy( cg.refdefViewAngles, kickangle ); + if ( kickangle[0] < 0 ) { + kickangle[0] = 0; //----(SA) avoid "Rockette" syndrome :) + } + AnglesToAxis( kickangle, wolfkick.axis ); + + + frame = cg.snap->ps.persistant[PERS_WOLFKICK]; + +// CG_Printf("frame: %d\n", frame); + + wolfkick.frame = frame; + wolfkick.oldframe = frame - 1; + wolfkick.backlerp = 1 - cg.frameInterpolation; + trap_R_AddRefEntityToScene( &wolfkick ); + +} + +/* +============== +CG_AddViewWeapon + +Add the weapon, and flash for the player's view +============== +*/ +void CG_AddViewWeapon( playerState_t *ps ) { + refEntity_t hand; + float fovOffset; + vec3_t angles; + vec3_t gunoff; + weaponInfo_t *weapon; + + if ( ps->persistant[PERS_TEAM] == TEAM_SPECTATOR ) { + return; + } + + if ( ps->pm_type == PM_INTERMISSION ) { + return; + } + + // no gun if in third person view + if ( cg.renderingThirdPerson ) { + return; + } + + // allow the gun to be completely removed + if ( !cg_drawGun.integer ) { +/* + vec3_t origin; + + if ( cg.predictedPlayerState.eFlags & EF_FIRING ) { + // special hack for lightning gun... + VectorCopy( cg.refdef.vieworg, origin ); + VectorMA( origin, -8, cg.refdef.viewaxis[2], origin ); + CG_LightningBolt( &cg_entities[ps->clientNum], origin ); + } +*/ + return; + } + + // don't draw if testing a gun model + if ( cg.testGun ) { + return; + } + + if ( ps->eFlags & EF_MG42_ACTIVE ) { + return; + } + + + // drop gun lower at higher fov + if ( cg_fov.integer > 90 ) { + fovOffset = -0.2 * ( cg_fov.integer - 90 ); + } else { + fovOffset = 0; + } + + if ( ps->weapon > WP_NONE ) { + // DHM - Nerve :: handle WP_CLASS_SPECIAL for different classes + if ( cgs.gametype == GT_WOLF && ps->weapon == WP_CLASS_SPECIAL ) { + switch ( ps->stats[ STAT_PLAYER_CLASS ] ) { + case PC_ENGINEER: + CG_RegisterWeapon( WP_CLASS_SPECIAL ); + weapon = &cg_weapons[ WP_CLASS_SPECIAL ]; + break; + case PC_MEDIC: + CG_RegisterWeapon( WP_MEDIC_HEAL ); + weapon = &cg_weapons[ WP_MEDIC_HEAL ]; + break; + case PC_LT: + CG_RegisterWeapon( WP_GRENADE_SMOKE ); + weapon = &cg_weapons[ WP_GRENADE_SMOKE ]; + break; + default: + CG_RegisterWeapon( ps->weapon ); + weapon = &cg_weapons[ ps->weapon ]; + break; + } + } else { + CG_RegisterWeapon( ps->weapon ); + weapon = &cg_weapons[ ps->weapon ]; + } + // dhm - end + + memset( &hand, 0, sizeof( hand ) ); + + // set up gun position + CG_CalculateWeaponPosition( hand.origin, angles ); + + gunoff[0] = cg_gun_x.value; + gunoff[1] = cg_gun_y.value; + gunoff[2] = cg_gun_z.value; + +//----(SA) removed + + VectorMA( hand.origin, gunoff[0], cg.refdef.viewaxis[0], hand.origin ); + VectorMA( hand.origin, gunoff[1], cg.refdef.viewaxis[1], hand.origin ); + VectorMA( hand.origin, ( gunoff[2] + fovOffset ), cg.refdef.viewaxis[2], hand.origin ); + + AnglesToAxis( angles, hand.axis ); + + if ( cg_gun_frame.integer ) { + hand.frame = hand.oldframe = cg_gun_frame.integer; + hand.backlerp = 0; + } else { // get the animation state + CG_WeaponAnimation( ps, weapon, &hand.oldframe, &hand.frame, &hand.backlerp ); //----(SA) changed + } + + + hand.hModel = weapon->handsModel; + hand.renderfx = RF_DEPTHHACK | RF_FIRST_PERSON | RF_MINLIGHT; //----(SA) + + // add everything onto the hand + CG_AddPlayerWeapon( &hand, ps, &cg.predictedPlayerEntity ); + // Ridah + + } // end "if ( ps->weapon > WP_NONE)" + + // Rafael + // add the foot + CG_AddPlayerFoot( &hand, ps, &cg.predictedPlayerEntity ); + + cg.predictedPlayerEntity.lastWeaponClientFrame = cg.clientFrame; +} + +/* +============================================================================== + +WEAPON SELECTION + +============================================================================== +*/ + +#define WP_ICON_X 38 // new sizes per MK +#define WP_ICON_X_WIDE 72 // new sizes per MK +#define WP_ICON_Y 38 +#define WP_ICON_SPACE_Y 10 +#define WP_DRAW_X 640 - WP_ICON_X - 4 // 4 is 'selected' border width +#define WP_DRAW_X_WIDE 640 - WP_ICON_X_WIDE - 4 +#define WP_DRAW_Y 4 + +// secondary fire icons +#define WP_ICON_SEC_X 18 // new sizes per MK +#define WP_ICON_SEC_Y 18 + + +/* +=================== +CG_DrawWeaponSelect +=================== +*/ +void CG_DrawWeaponSelect( void ) { + int i; + int x, y; + int curweap, curweapbank = 0, curweapcycle = 0, drawweap; + int realweap; // DHM - Nerve + int bits[MAX_WEAPONS / ( sizeof( int ) * 8 )]; + float *color; + + // don't display if dead + if ( cg.predictedPlayerState.stats[STAT_HEALTH] <= 0 ) { + return; + } + + if ( !cg.weaponSelect ) { + return; + } + + color = CG_FadeColor( cg.weaponSelectTime, WEAPON_SELECT_TIME ); + if ( !color ) { + return; + } + trap_R_SetColor( color ); + + +//----(SA) neither of these overlap the weapon selection area anymore, so let them stay + // showing weapon select clears pickup item display, but not the blend blob +// cg.itemPickupTime = 0; + + // also clear holdable list +// cg.holdableSelectTime = 0; +//----(SA) end + + // count the number of weapons owned + memcpy( bits, cg.snap->ps.weapons, sizeof( bits ) ); + + curweap = cg.weaponSelect; + + // get bank/cycle of current weapon + if ( !CG_WeaponIndex( curweap, &curweapbank, &curweapcycle ) ) { + + // weapon selected isn't a primary weapon, so draw the alternates bank + CG_WeaponIndex( getAltWeapon( curweap ), &curweapbank, &curweapcycle ); + + } + + y = WP_DRAW_Y; + + for ( i = 0; i < maxWeapsInBank; i++ ) { + + qboolean wideweap; // is the icon one of the double width ones + + // primary fire +// JPW NERVE + if ( cg_gameType.integer == GT_WOLF ) { + drawweap = weapBanksMultiPlayer[curweapbank][i]; + } else { +// jpw + drawweap = weapBanks[curweapbank][i]; + } + + realweap = drawweap; // DHM - Nerve + + switch ( drawweap ) { + case WP_THOMPSON: + case WP_MP40: + case WP_STEN: + case WP_MAUSER: + case WP_GARAND: + case WP_VENOM: + case WP_TESLA: + case WP_PANZERFAUST: + case WP_FLAMETHROWER: + case WP_FG42: + case WP_FG42SCOPE: + wideweap = qtrue; + break; + default: + wideweap = qfalse; + break; + } + + if ( wideweap ) { + x = WP_DRAW_X_WIDE; + } else { + x = WP_DRAW_X; + } + + if ( drawweap && ( bits[0] & ( 1 << drawweap ) ) ) { + // you've got it, draw it + + // DHM - Nerve :: Special case for WP_CLASS_SPECIAL + if ( cgs.gametype == GT_WOLF && drawweap == WP_CLASS_SPECIAL ) { + switch ( cg.predictedPlayerState.stats[ STAT_PLAYER_CLASS ] ) { + case PC_ENGINEER: + drawweap = WP_CLASS_SPECIAL; + break; + case PC_MEDIC: + drawweap = WP_MEDIC_HEAL; + break; + case PC_LT: + drawweap = WP_GRENADE_SMOKE; + break; + default: + break; + } + } + // dhm - end + + CG_RegisterWeapon( drawweap ); + + if ( wideweap ) { + // weapon icon + if ( realweap == curweap ) { + CG_DrawPic( x, y, WP_ICON_X_WIDE, WP_ICON_Y, cg_weapons[drawweap].weaponIcon[1] ); + } else { + CG_DrawPic( x, y, WP_ICON_X_WIDE, WP_ICON_Y, cg_weapons[drawweap].weaponIcon[0] ); + } + + // no ammo cross + if ( !CG_WeaponHasAmmo( realweap ) ) { // DHM - Nerve + CG_DrawPic( x, y, WP_ICON_X_WIDE, WP_ICON_Y, cgs.media.noammoShader ); + } + } else { + // weapon icon + if ( realweap == curweap ) { + CG_DrawPic( x, y, WP_ICON_X, WP_ICON_Y, cg_weapons[drawweap].weaponIcon[1] ); + } else { + CG_DrawPic( x, y, WP_ICON_X, WP_ICON_Y, cg_weapons[drawweap].weaponIcon[0] ); + } + + // no ammo cross + if ( !CG_WeaponHasAmmo( realweap ) ) { // DHM - Nerve + CG_DrawPic( x, y, WP_ICON_X, WP_ICON_Y, cgs.media.noammoShader ); + } + } + + } else { + continue; + } + + // secondary fire + if ( wideweap ) { + x = WP_DRAW_X_WIDE - WP_ICON_SEC_X - 4; + } else { + x = WP_DRAW_X - WP_ICON_SEC_X - 4; + } + +// JPW NERVE + if ( cg_gameType.integer == GT_WOLF ) { + drawweap = getAltWeapon( weapBanksMultiPlayer[curweapbank][i] ); + } else { +// jpw + drawweap = getAltWeapon( weapBanks[curweapbank][i] ); + } + + // clear drawweap if getaltweap() returns the same weap as passed in. (no secondary available) +// JPW NERVE + if ( cg_gameType.integer == GT_WOLF ) { + if ( drawweap == weapBanksMultiPlayer[curweapbank][i] ) { + drawweap = 0; + } + } else { +// jpw + if ( drawweap == weapBanks[curweapbank][i] ) { + drawweap = 0; + } + } + + realweap = drawweap; // DHM - Nerve + + if ( drawweap && ( bits[0] & ( 1 << drawweap ) ) ) { + // you've got it, draw it + // DHM - Nerve :: Special case for WP_CLASS_SPECIAL + if ( cgs.gametype == GT_WOLF && drawweap == WP_CLASS_SPECIAL ) { + switch ( cg.predictedPlayerState.stats[ STAT_PLAYER_CLASS ] ) { + case PC_ENGINEER: + drawweap = WP_CLASS_SPECIAL; + break; + case PC_MEDIC: + drawweap = WP_MEDIC_HEAL; + break; + case PC_LT: + drawweap = WP_GRENADE_SMOKE; + break; + default: + break; + } + } + // dhm - end + + CG_RegisterWeapon( drawweap ); + + // weapon icon + if ( realweap == cg.weaponSelect ) { + CG_DrawPic( x, y, WP_ICON_SEC_X, WP_ICON_SEC_Y, cg_weapons[drawweap].weaponIcon[1] ); + } else { + CG_DrawPic( x, y, WP_ICON_SEC_X, WP_ICON_SEC_Y, cg_weapons[drawweap].weaponIcon[0] ); + } + + // no ammo cross + if ( !CG_WeaponHasAmmo( realweap ) ) { + CG_DrawPic( x, y, WP_ICON_SEC_X, WP_ICON_SEC_Y, cgs.media.noammoShader ); + } + } + + + y += ( WP_ICON_Y + WP_ICON_SPACE_Y ); + } +} + + + + +/* +============== +CG_WeaponHasAmmo + check for ammo +============== +*/ +static qboolean CG_WeaponHasAmmo( int i ) { + if ( !( cg.predictedPlayerState.ammo[BG_FindAmmoForWeapon( i )] ) && + !( cg.predictedPlayerState.ammoclip[BG_FindClipForWeapon( i )] ) ) { + return qfalse; + } + + return qtrue; +} + + +/* +=============== +CG_WeaponSelectable +=============== +*/ +static qboolean CG_WeaponSelectable( int i ) { + + // allow the player to unselect all weapons +// if(i == WP_NONE) +// return qtrue; + + // if holding a melee weapon (chair/shield/etc.) only allow single-handed weapons + if ( cg.snap->ps.eFlags & EF_MELEE_ACTIVE ) { + if ( !( WEAPS_ONE_HANDED & ( 1 << i ) ) ) { + return qfalse; + } + } + + // allow switch out of scope for weapons where you fired the last shot while scoped + // and we left you in that view to see the result of the shot + switch ( cg.weaponSelect ) { + case WP_SNOOPERSCOPE: + if ( i == WP_GARAND ) { + return qtrue; + } + break; + case WP_SNIPERRIFLE: + if ( i == WP_MAUSER ) { + return qtrue; + } + break; + case WP_FG42SCOPE: + if ( i == WP_FG42 ) { + return qtrue; + } + break; + default: + break; + } + + + // check for weapon + if ( !( COM_BitCheck( cg.predictedPlayerState.weapons, i ) ) ) { + return qfalse; + } + + if ( !CG_WeaponHasAmmo( i ) ) { + return qfalse; + } + + return qtrue; +} + + + + +/* +============== +CG_WeaponIndex +============== +*/ +int CG_WeaponIndex( int weapnum, int *bank, int *cycle ) { + static int bnk, cyc; + + if ( weapnum <= 0 || weapnum >= WP_NUM_WEAPONS ) { + if ( bank ) { + *bank = 0; + } + if ( cycle ) { + *cycle = 0; + } + return 0; + } + + for ( bnk = 0; bnk < maxWeapBanks; bnk++ ) { + for ( cyc = 0; cyc < maxWeapsInBank; cyc++ ) { + + // end of cycle, go to next bank + if ( cg_gameType.integer != GT_WOLF ) { // JPW NERVE + if ( !weapBanks[bnk][cyc] ) { + break; + } + + // found the current weapon + if ( weapBanks[bnk][cyc] == weapnum ) { + if ( bank ) { + *bank = bnk; + } + if ( cycle ) { + *cycle = cyc; + } + return 1; + } + } +// JPW NERVE + else { + if ( !weapBanksMultiPlayer[bnk][cyc] ) { + break; + } + + // found the current weapon + if ( weapBanksMultiPlayer[bnk][cyc] == weapnum ) { + if ( bank ) { + *bank = bnk; + } + if ( cycle ) { + *cycle = cyc; + } + return 1; + } + } +// jpw + } + } + + // failed to find the weapon in the table + // probably an alternate + + return 0; +} + + + +/* +============== +getNextWeapInBank + Pass in a bank and cycle and this will return the next valid weapon higher in the cycle. + if the weap passed in is above highest in a cycle (maxWeapsInBank), this will safely loop around +============== +*/ +static int getNextWeapInBank( int bank, int cycle ) { + + cycle++; + + cycle = cycle % maxWeapsInBank; + + if ( cg_gameType.integer != GT_WOLF ) { // JPW NERVE + if ( weapBanks[bank][cycle] ) { // return next weapon in bank if there is one + return weapBanks[bank][cycle]; + } else { // return first in bank + return weapBanks[bank][0]; + } + } +// JPW NERVE + else { + if ( weapBanksMultiPlayer[bank][cycle] ) { // return next weapon in bank if there is one + return weapBanksMultiPlayer[bank][cycle]; + } else { // return first in bank + return weapBanksMultiPlayer[bank][0]; + } + } +// jpw +} + +static int getNextWeapInBankBynum( int weapnum ) { + int bank, cycle; + + if ( !CG_WeaponIndex( weapnum, &bank, &cycle ) ) { + return weapnum; + } + + return getNextWeapInBank( bank, cycle ); +} + + +/* +============== +getPrevWeapInBank + Pass in a bank and cycle and this will return the next valid weapon lower in the cycle. + if the weap passed in is the lowest in a cycle (0), this will loop around to the + top (maxWeapsInBank-1) and start down from there looking for a valid weapon position +============== +*/ +static int getPrevWeapInBank( int bank, int cycle ) { + cycle--; + if ( cycle < 0 ) { + cycle = maxWeapsInBank - 1; + } + + + if ( cg_gameType.integer != GT_WOLF ) { + while ( !weapBanks[bank][cycle] ) { + cycle--; + + if ( cycle < 0 ) { + cycle = maxWeapsInBank - 1; + } + } + return weapBanks[bank][cycle]; + } else { + while ( !weapBanksMultiPlayer[bank][cycle] ) { + cycle--; + + if ( cycle < 0 ) { + cycle = maxWeapsInBank - 1; + } + } + return weapBanksMultiPlayer[bank][cycle]; + } +} + + +static int getPrevWeapInBankBynum( int weapnum ) { + int bank, cycle; + + if ( !CG_WeaponIndex( weapnum, &bank, &cycle ) ) { + return weapnum; + } + + return getPrevWeapInBank( bank, cycle ); +} + + + +/* +============== +getNextBankWeap + Pass in a bank and cycle and this will return the next valid weapon in a higher bank. + sameBankPosition: if there's a weapon in the next bank at the same cycle, + return that (colt returns thompson for example) rather than the lowest weapon +============== +*/ +static int getNextBankWeap( int bank, int cycle, qboolean sameBankPosition ) { + bank++; + + bank = bank % maxWeapBanks; + + if ( cg_gameType.integer != GT_WOLF ) { // JPW NERVE + if ( sameBankPosition && weapBanks[bank][cycle] ) { + return weapBanks[bank][cycle]; + } else { + return weapBanks[bank][0]; + } + } +// JPW NERVE + else { + if ( sameBankPosition && weapBanksMultiPlayer[bank][cycle] ) { + return weapBanksMultiPlayer[bank][cycle]; + } else { + return weapBanksMultiPlayer[bank][0]; + } + } +// jpw +} + +/* +============== +getPrevBankWeap + Pass in a bank and cycle and this will return the next valid weapon in a lower bank. + sameBankPosition: if there's a weapon in the prev bank at the same cycle, + return that (thompson returns colt for example) rather than the highest weapon +============== +*/ +static int getPrevBankWeap( int bank, int cycle, qboolean sameBankPosition ) { + int i; + + bank--; + + if ( bank < 0 ) { // don't go below 0, cycle up to top + bank += maxWeapBanks; + } + + bank = bank % maxWeapBanks; + + if ( cg_gameType.integer != GT_WOLF ) { // JPW NERVE + if ( sameBankPosition && weapBanks[bank][cycle] ) { + return weapBanks[bank][cycle]; + } else + { // find highest weap in bank + for ( i = maxWeapsInBank - 1; i >= 0; i-- ) { + if ( weapBanks[bank][i] ) { + return weapBanks[bank][i]; + } + } + + // if it gets to here, no valid weaps in this bank, go down another bank + return getPrevBankWeap( bank, cycle, sameBankPosition ); + } + } +// JPW NERVE + else { + if ( sameBankPosition && weapBanksMultiPlayer[bank][cycle] ) { + return weapBanksMultiPlayer[bank][cycle]; + } else + { // find highest weap in bank + for ( i = maxWeapsInBank - 1; i >= 0; i-- ) { + if ( weapBanksMultiPlayer[bank][i] ) { + return weapBanksMultiPlayer[bank][i]; + } + } + + // if it gets to here, no valid weaps in this bank, go down another bank + return getPrevBankWeap( bank, cycle, sameBankPosition ); + } + } +// jpw +} + +/* +============== +getAltWeapon +============== +*/ +static int getAltWeapon( int weapnum ) { + if ( weapnum > MAX_WEAP_ALTS ) { + return weapnum; + } + + if ( weapAlts[weapnum] ) { + return weapAlts[weapnum]; + } + + return weapnum; +} + + + +/* +============== +getEquivWeapon + return the id of the opposite team's weapon. + Passing the weapnum of the mp40 returns the id of the thompson, and likewise + passing the weapnum of the thompson returns the id of the mp40. + No equivalent available will return the weapnum passed in. +============== +*/ +int getEquivWeapon( int weapnum ) { + int num = weapnum; + + switch ( weapnum ) { + // going from german to american + case WP_LUGER: num = WP_COLT; break; + case WP_MAUSER: num = WP_GARAND; break; + case WP_MP40: num = WP_THOMPSON; break; + case WP_GRENADE_LAUNCHER: num = WP_GRENADE_PINEAPPLE; break; + + // going from american to german + case WP_COLT: num = WP_LUGER; break; + case WP_GARAND: num = WP_MAUSER; break; + case WP_THOMPSON: num = WP_MP40; break; + case WP_GRENADE_PINEAPPLE: num = WP_GRENADE_LAUNCHER; break; + } + return num; +} + + + +/* +============== +CG_WeaponSuggest +============== +*/ +void CG_WeaponSuggest( int weap ) { + int bank, cycle; + + return; // not currently supported + + if ( !cg_useSuggestedWeapons.integer ) { + return; + } + + cg.weaponSelectTime = cg.time; + + CG_WeaponIndex( weap, &bank, &cycle ); // get location of this weap + + cg.lastWeapSelInBank[bank] = weap; // make this weap first priority in that bank + +} + + +/* +============== +CG_SetSniperZoom +============== +*/ + +void CG_SetSniperZoom( int lastweap, int newweap ) { + int zoomindex; + float shake = 0; + + if ( lastweap == newweap ) { + return; + } + + cg.zoomval = 0; + cg.zoomedScope = 0; + + // check for fade-outs + switch ( lastweap ) { + case WP_SNIPERRIFLE: +// cg.zoomedScope = 500; // TODO: add to zoomTable +// cg.zoomTime = cg.time; + break; + case WP_SNOOPERSCOPE: +// cg.zoomedScope = 500; // TODO: add to zoomTable +// cg.zoomTime = cg.time; + break; + case WP_FG42SCOPE: +// cg.zoomedScope = 1; // TODO: add to zoomTable +// cg.zoomTime = cg.time; + break; + } + + switch ( newweap ) { + + default: + return; // no sniper zoom, get out. + + case WP_SNIPERRIFLE: + cg.zoomval = cg_zoomDefaultSniper.value; + cg.zoomedScope = 900; // TODO: add to zoomTable + zoomindex = ZOOM_SNIPER; +// shake = 0.04; + shake = 0.03f; + break; + case WP_SNOOPERSCOPE: + cg.zoomval = cg_zoomDefaultSnooper.value; + cg.zoomedScope = 800; // TODO: add to zoomTable + zoomindex = ZOOM_SNOOPER; + shake = 0.04f; + break; + case WP_FG42SCOPE: + cg.zoomval = cg_zoomDefaultFG.value; + cg.zoomedScope = 1; // TODO: add to zoomTable + zoomindex = ZOOM_FG42SCOPE; + shake = 0.01f; + break; + } + +// if(shake) { +// (SA) all shake disabled 11/12 +// CG_StartShakeCamera( shake, 1000, cg.snap->ps.origin, 100 ); +// } + + // constrain user preferred fov to weapon limitations + if ( cg.zoomval > zoomTable[zoomindex][ZOOM_OUT] ) { + cg.zoomval = zoomTable[zoomindex][ZOOM_OUT]; + } + if ( cg.zoomval < zoomTable[zoomindex][ZOOM_IN] ) { + cg.zoomval = zoomTable[zoomindex][ZOOM_IN]; + } + + cg.zoomTime = cg.time; +} + + +/* +============== +CG_PlaySwitchSound + Get special switching sounds if they're there +============== +*/ +void CG_PlaySwitchSound( int lastweap, int newweap ) { +// weaponInfo_t *weap; +// weap = &cg_weapons[ ent->weapon ]; + sfxHandle_t switchsound; + + switchsound = cgs.media.selectSound; + + if ( getAltWeapon( lastweap ) == newweap ) { // alt switch + switch ( newweap ) { + case WP_SILENCER: + case WP_LUGER: + switchsound = cg_weapons[newweap].switchSound[0]; + break; + default: + break; + } + } + + trap_S_StartSound( NULL, cg.snap->ps.clientNum, CHAN_WEAPON, switchsound ); +} + + +/* +============== +CG_FinishWeaponChange +============== +*/ +void CG_FinishWeaponChange( int lastweap, int newweap ) { + int newbank; + + cg.weaponSelectTime = cg.time; // flash the weapon icon + + // remember which weapon in this bank was last selected so when cycling back + // to this bank, that weap will be highlighted first + if ( CG_WeaponIndex( newweap, &newbank, NULL ) ) { + cg.lastWeapSelInBank[newbank] = newweap; + } + + if ( lastweap == newweap ) { // no need to do any more than flash the icon + return; + } + + CG_PlaySwitchSound( lastweap, newweap ); //----(SA) added + + CG_SetSniperZoom( lastweap, newweap ); + + // setup for a user call to CG_LastWeaponUsed_f() + if ( lastweap == cg.lastFiredWeapon ) { + // don't set switchback for some weaps... + switch ( lastweap ) { + case WP_SNIPERRIFLE: + case WP_SNOOPERSCOPE: + case WP_FG42SCOPE: + break; + default: + cg.switchbackWeapon = lastweap; + break; + } + } else { + // if this ended up having the switchback be the same + // as the new weapon, set the switchback to the prev + // selected weapon will become the switchback + if ( cg.switchbackWeapon == newweap ) { + cg.switchbackWeapon = lastweap; + } + } + + cg.weaponSelect = newweap; +} + +/* +============== +CG_AltfireWeapon_f + for example, switching between WP_MAUSER and WP_SNIPERRIFLE +============== +*/ +void CG_AltWeapon_f( void ) { + int original, num; + + if ( !cg.snap ) { + return; + } + if ( cg.snap->ps.pm_flags & PMF_FOLLOW ) { + return; + } + + if ( cg.snap->ps.eFlags & EF_MG42_ACTIVE ) { // no alt-switching when on mg42 + return; + } + + if ( cg.time - cg.weaponSelectTime < cg_weaponCycleDelay.integer ) { + return; // force pause so holding it down won't go too fast + + } + // Don't try to switch when in the middle of reloading. + if ( cg.snap->ps.weaponstate == WEAPON_RELOADING ) { + return; + } + + original = cg.weaponSelect; + + num = getAltWeapon( original ); + + if ( CG_WeaponSelectable( num ) ) { // new weapon is valid + +//----(SA) testing mod functionality for the silencer on the luger + // (SA) this way, if you switch away from the silenced luger, + // the silencer will still be attached when you switch back + // (until you remove it) + // TODO: will need to make sure the table gets initialized properly on restart/death/whatever. + // I still think I'm going to make the weapon banks stored in the config, so this will + // just be a matter of resetting the banks to what's in the config. + switch ( original ) { + case WP_LUGER: + if ( cg.snap->ps.eFlags & EF_MELEE_ACTIVE ) { // if you're holding a chair, you can't screw on the silencer + return; + } + weapBanks[2][0] = WP_SILENCER; + break; + case WP_SILENCER: + if ( cg.snap->ps.eFlags & EF_MELEE_ACTIVE ) { // if you're holding a chair, you can't remove the silencer + return; + } + weapBanks[2][0] = WP_LUGER; + break; + + case WP_AKIMBO: + weapBanks[2][1] = WP_COLT; + break; + case WP_COLT: + weapBanks[2][1] = WP_AKIMBO; + break; + } + +//----(SA) end + CG_FinishWeaponChange( original, num ); + } +} + + +/* +============== +CG_NextWeap + + switchBanks - curweap is the last in a bank, 'qtrue' means go to the next available bank, 'qfalse' means loop to the head of the bank +============== +*/ +void CG_NextWeap( qboolean switchBanks ) { + int bank = 0, cycle = 0, newbank = 0, newcycle = 0; + int num, curweap; + qboolean nextbank = qfalse; // need to switch to the next bank of weapons? + int i, j; + + num = curweap = cg.weaponSelect; + + CG_WeaponIndex( curweap, &bank, &cycle ); // get bank/cycle of current weapon + + // if you're using an alt mode weapon, try switching back to the parent first + if ( curweap >= WP_BEGINSECONDARY && curweap <= WP_LASTSECONDARY ) { + num = getAltWeapon( curweap ); // base any further changes on the parent + if ( CG_WeaponSelectable( num ) ) { // the parent was selectable, drop back to that + CG_FinishWeaponChange( curweap, num ); + return; + } + } + + +// if(cg_cycleAllWeaps.integer || !switchBanks) { + if ( 1 ) { + for ( i = 0; i < maxWeapsInBank; i++ ) { + num = getNextWeapInBankBynum( num ); + + CG_WeaponIndex( num, NULL, &newcycle ); // get cycle of new weapon. if it's lower than the original, then it cycled around + + if ( switchBanks ) { + if ( newcycle <= cycle ) { + nextbank = qtrue; + break; + } + } else { // don't switch banks if you get to the end + + if ( num == curweap ) { // back to start, just leave it where it is + return; + } + } + + if ( CG_WeaponSelectable( num ) ) { + break; + } + } + } else { + nextbank = qtrue; + } + + if ( nextbank ) { + for ( i = 0; i < maxWeapBanks; i++ ) { +// if(cg_cycleAllWeaps.integer) + if ( 1 ) { + num = getNextBankWeap( bank + i, cycle, qfalse ); // cycling all weaps always starts the next bank at the bottom + } else { + if ( cg.lastWeapSelInBank[bank + i + 1] ) { + num = cg.lastWeapSelInBank[bank + i + 1]; + } else { + num = getNextBankWeap( bank + i, cycle, qtrue ); + } + } + + if ( num == 0 ) { + continue; + } + + if ( CG_WeaponSelectable( num ) ) { // first entry in bank was selectable, no need to scan the bank + break; + } + + CG_WeaponIndex( num, &newbank, &newcycle ); // get the bank of the new weap + + for ( j = newcycle; j < maxWeapsInBank; j++ ) { + num = getNextWeapInBank( newbank, j ); + + if ( CG_WeaponSelectable( num ) ) { // found selectable weapon + break; + } + + num = 0; + } + + if ( num ) { // a selectable weapon was found in the current bank + break; + } + } + } + + CG_FinishWeaponChange( curweap, num ); //----(SA) +} + +/* +============== +CG_PrevWeap + + switchBanks - curweap is the last in a bank + 'qtrue' - go to the next available bank + 'qfalse' - loop to the head of the bank +============== +*/ +void CG_PrevWeap( qboolean switchBanks ) { + int bank = 0, cycle = 0, newbank = 0, newcycle = 0; + int num, curweap; + qboolean prevbank = qfalse; // need to switch to the next bank of weapons? + int i, j; + + num = curweap = cg.weaponSelect; + + CG_WeaponIndex( curweap, &bank, &cycle ); // get bank/cycle of current weapon + + // if you're using an alt mode weapon, try switching back to the parent first + if ( curweap >= WP_BEGINSECONDARY && curweap <= WP_LASTSECONDARY ) { + num = getAltWeapon( curweap ); // base any further changes on the parent + if ( CG_WeaponSelectable( num ) ) { // the parent was selectable, drop back to that + CG_FinishWeaponChange( curweap, num ); + return; + } + } + + // initially, just try to find a lower weapon in the current bank +// if(cg_cycleAllWeaps.integer || !switchBanks) { + if ( 1 ) { + +// if(cycle == 0) { // already at bottom of list +// prevbank = qtrue; +// } else { + for ( i = cycle; i >= 0; i-- ) { +// num = getPrevWeapInBank(bank, i); + num = getPrevWeapInBankBynum( num ); + + CG_WeaponIndex( num, NULL, &newcycle ); // get cycle of new weapon. if it's greater than the original, then it cycled around + + if ( switchBanks ) { + if ( newcycle > ( cycle - 1 ) ) { + prevbank = qtrue; + break; + } + } else { // don't switch banks if you get to the end + if ( num == curweap ) { // back to start, just leave it where it is + return; + } + } + + if ( CG_WeaponSelectable( num ) ) { + break; + } + } +// } + } else { + prevbank = qtrue; + } + + // cycle to previous bank. + // if cycleAllWeaps: find highest weapon in bank + // else: try to find weap in bank that matches cycle position + // else: use base weap in bank + + if ( prevbank ) { + for ( i = 0; i < maxWeapBanks; i++ ) { +// if(cg_cycleAllWeaps.integer) + if ( 1 ) { + num = getPrevBankWeap( bank - i, cycle, qfalse ); // cycling all weaps always starts the next bank at the bottom + } else { + num = getPrevBankWeap( bank - i, cycle, qtrue ); + } + + if ( num == 0 ) { + continue; + } + + if ( CG_WeaponSelectable( num ) ) { // first entry in bank was selectable, no need to scan the bank + break; + } + + CG_WeaponIndex( num, &newbank, &newcycle ); // get the bank of the new weap + + for ( j = maxWeapsInBank; j > 0; j-- ) { + num = getPrevWeapInBank( newbank, j ); + + if ( CG_WeaponSelectable( num ) ) { // found selectable weapon + break; + } + + num = 0; + } + + if ( num ) { // a selectable weapon was found in the current bank + break; + } + } + } + + CG_FinishWeaponChange( curweap, num ); //----(SA) +} + + +/* +============== +CG_LastWeaponUsed_f +============== +*/ +void CG_LastWeaponUsed_f( void ) { + int lastweap; + + if ( cg.time - cg.weaponSelectTime < cg_weaponCycleDelay.integer ) { + return; // force pause so holding it down won't go too fast + + } + cg.weaponSelectTime = cg.time; // flash the current weapon icon + + // don't switchback if reloading (it nullifies the reload) + if ( cg.snap->ps.weaponstate == WEAPON_RELOADING ) { + return; + } + + if ( !cg.switchbackWeapon ) { + cg.switchbackWeapon = cg.weaponSelect; + return; + } + + if ( CG_WeaponSelectable( cg.switchbackWeapon ) ) { + lastweap = cg.weaponSelect; + CG_FinishWeaponChange( cg.weaponSelect, cg.switchbackWeapon ); + } else { // switchback no longer selectable, reset cycle + cg.switchbackWeapon = 0; + } + +} + +/* +============== +CG_NextWeaponInBank_f +============== +*/ +void CG_NextWeaponInBank_f( void ) { + + if ( cg.time - cg.weaponSelectTime < cg_weaponCycleDelay.integer ) { + return; // force pause so holding it down won't go too fast + + } + // this cvar is an option that lets the player use his weapon switching keys (probably the mousewheel) + // for zooming (binocs/snooper/sniper/etc.) + if ( cg.zoomval ) { + if ( cg_useWeapsForZoom.integer == 1 ) { + CG_ZoomIn_f(); + return; + } else if ( cg_useWeapsForZoom.integer == 2 ) { + CG_ZoomOut_f(); + return; + } + } + + cg.weaponSelectTime = cg.time; // flash the current weapon icon + + CG_NextWeap( qfalse ); +} + +/* +============== +CG_PrevWeaponInBank_f +============== +*/ +void CG_PrevWeaponInBank_f( void ) { + + if ( cg.time - cg.weaponSelectTime < cg_weaponCycleDelay.integer ) { + return; // force pause so holding it down won't go too fast + + } + // this cvar is an option that lets the player use his weapon switching keys (probably the mousewheel) + // for zooming (binocs/snooper/sniper/etc.) + if ( cg.zoomval ) { + if ( cg_useWeapsForZoom.integer == 2 ) { + CG_ZoomIn_f(); + return; + } else if ( cg_useWeapsForZoom.integer == 1 ) { + CG_ZoomOut_f(); + return; + } + } + + cg.weaponSelectTime = cg.time; // flash the current weapon icon + + CG_PrevWeap( qfalse ); +} + + +/* +============== +CG_NextWeapon_f +============== +*/ +void CG_NextWeapon_f( void ) { + + if ( !cg.snap ) { + return; + } + if ( cg.snap->ps.pm_flags & PMF_FOLLOW ) { + return; + } + + // this cvar is an option that lets the player use his weapon switching keys (probably the mousewheel) + // for zooming (binocs/snooper/sniper/etc.) + if ( cg.zoomval ) { + if ( cg_useWeapsForZoom.integer == 1 ) { + CG_ZoomIn_f(); + return; + } else if ( cg_useWeapsForZoom.integer == 2 ) { + CG_ZoomOut_f(); + return; + } + } + + if ( cg.time - cg.weaponSelectTime < cg_weaponCycleDelay.integer ) { + return; // force pause so holding it down won't go too fast + + } + cg.weaponSelectTime = cg.time; // flash the current weapon icon + + // Don't try to switch when in the middle of reloading. + // cheatinfo: The server actually would let you switch if this check were not + // present, but would discard the reload. So the when you switched + // back you'd have to start the reload over. This seems bad, however + // the delay for the current reload is already in effect, so you'd lose + // the reload time twice. (the first pause for the current weapon reload, + // and the pause when you have to reload again 'cause you canceled this one) + + if ( cg.snap->ps.weaponstate == WEAPON_RELOADING ) { + return; + } + + CG_NextWeap( qtrue ); +} + + +/* +============== +CG_PrevWeapon_f +============== +*/ +void CG_PrevWeapon_f( void ) { + // TTimo: unused + /* + int bank = 0, cycle = 0, newbank = 0, newcycle = 0; + qboolean prevbank = qfalse; // need to switch to the next bank of weapons? + */ + + if ( !cg.snap ) { + return; + } + if ( cg.snap->ps.pm_flags & PMF_FOLLOW ) { + return; + } + + // this cvar is an option that lets the player use his weapon switching keys (probably the mousewheel) + // for zooming (binocs/snooper/sniper/etc.) + if ( cg.zoomval ) { + if ( cg_useWeapsForZoom.integer == 1 ) { + CG_ZoomOut_f(); + return; + } else if ( cg_useWeapsForZoom.integer == 2 ) { + CG_ZoomIn_f(); + return; + } + } + + if ( cg.time - cg.weaponSelectTime < cg_weaponCycleDelay.integer ) { + return; // force pause so holding it down won't go too fast + + } + cg.weaponSelectTime = cg.time; // flash the current weapon icon + + // Don't try to switch when in the middle of reloading. + if ( cg.snap->ps.weaponstate == WEAPON_RELOADING ) { + return; + } + + CG_PrevWeap( qtrue ); +} + + +/* +============== +CG_WeaponBank_f + weapon keys are not generally bound directly('bind 1 weapon 1'), + rather the key is bound to a given bank ('bind 1 weaponbank 1') +============== +*/ +void CG_WeaponBank_f( void ) { + int num, i, curweap; + int curbank = 0, curcycle = 0, bank = 0, cycle = 0; + + if ( !cg.snap ) { + return; + } + + if ( cg.snap->ps.pm_flags & PMF_FOLLOW ) { + return; + } + + if ( cg.time - cg.weaponSelectTime < cg_weaponCycleDelay.integer ) { + return; // force pause so holding it down won't go too fast + + } + cg.weaponSelectTime = cg.time; // flash the current weapon icon + + // Don't try to switch when in the middle of reloading. + if ( cg.snap->ps.weaponstate == WEAPON_RELOADING ) { + return; + } + + bank = atoi( CG_Argv( 1 ) ); + + if ( bank <= 0 || bank > maxWeapBanks ) { + return; + } + + curweap = cg.weaponSelect; + CG_WeaponIndex( curweap, &curbank, &curcycle ); // get bank/cycle of current weapon + + if ( !cg.lastWeapSelInBank[bank] ) { + if ( cg_gameType.integer != GT_WOLF ) { // JPW NERVE + num = weapBanks[bank][0]; + } +// JPW NERVE + else { + num = weapBanksMultiPlayer[bank][0]; + } +// jpw + cycle -= 1; // cycle up to first weap + } else { + num = cg.lastWeapSelInBank[bank]; + CG_WeaponIndex( num, &bank, &cycle ); + if ( bank != curbank ) { + cycle -= 1; + } + + } + + for ( i = 0; i < maxWeapsInBank; i++ ) { + num = getNextWeapInBank( bank, cycle + i ); + + if ( CG_WeaponSelectable( num ) ) { + break; + } + } + + if ( i == maxWeapsInBank ) { + return; + } + + CG_FinishWeaponChange( curweap, num ); + +} + +/* +=============== +CG_Weapon_f +=============== +*/ +void CG_Weapon_f( void ) { + int num, i, curweap; + int bank = 0, cycle = 0, newbank = 0, newcycle = 0; + qboolean banked = qfalse; + + if ( !cg.snap ) { + return; + } + + if ( cg.snap->ps.pm_flags & PMF_FOLLOW ) { + return; + } + + num = atoi( CG_Argv( 1 ) ); + +// JPW NERVE +// weapon bind should execute weaponbank instead -- for splitting out class weapons, per Id request + if ( cg_gameType.integer == GT_WOLF ) { + if ( num < maxWeapBanks ) { + CG_WeaponBank_f(); + } + return; + } +// jpw + + cg.weaponSelectTime = cg.time; // flash the current weapon icon + + // Don't try to switch when in the middle of reloading. + if ( cg.snap->ps.weaponstate == WEAPON_RELOADING ) { + return; + } + + + if ( num <= WP_NONE || num > WP_NUM_WEAPONS ) { + return; + } + + curweap = cg.weaponSelect; + + CG_WeaponIndex( curweap, &bank, &cycle ); // get bank/cycle of current weapon + banked = CG_WeaponIndex( num, &newbank, &newcycle ); // get bank/cycle of requested weapon + + // the new weapon was not found in the reglar banks + // assume the player want's to go directly to it if possible + if ( !banked ) { + if ( CG_WeaponSelectable( num ) ) { + CG_FinishWeaponChange( curweap, num ); + return; + } + } + + if ( bank != newbank ) { + cycle = newcycle - 1; // drop down one from the requested weap's cycle so it will + } + // try to initially cycle up to the requested weapon + + for ( i = 0; i < maxWeapsInBank; i++ ) { + num = getNextWeapInBank( newbank, cycle + i ); + + if ( num == curweap ) { // no other weapons in bank + return; + } + + if ( CG_WeaponSelectable( num ) ) { + break; + } + } + + if ( i == maxWeapsInBank ) { + return; + } + + CG_FinishWeaponChange( curweap, num ); +} + +/* +=================== +CG_OutOfAmmoChange + +The current weapon has just run out of ammo +=================== +*/ +void CG_OutOfAmmoChange( void ) { + int i; + int bank, cycle; + int equiv = WP_NONE; + + // + // trivial switching + // + + // if you're using an alt mode weapon, try switching back to the parent + // otherwise, switch to the equivalent if you've got it + if ( cg.weaponSelect >= WP_BEGINSECONDARY && cg.weaponSelect <= WP_LASTSECONDARY ) { + cg.weaponSelect = equiv = getAltWeapon( cg.weaponSelect ); // base any further changes on the parent + if ( CG_WeaponSelectable( equiv ) ) { // the parent was selectable, drop back to that + CG_FinishWeaponChange( cg.predictedPlayerState.weapon, cg.weaponSelect ); //----(SA) + return; + } + } + + + // now try the opposite team's equivalent weap + equiv = getEquivWeapon( cg.weaponSelect ); + + if ( equiv != cg.weaponSelect && CG_WeaponSelectable( equiv ) ) { + cg.weaponSelect = equiv; + CG_FinishWeaponChange( cg.predictedPlayerState.weapon, cg.weaponSelect ); //----(SA) + return; + } + + // + // more complicated selection + // + + // didn't have available alternative or equivalent, try another weap in the bank + CG_WeaponIndex( cg.weaponSelect, &bank, &cycle ); // get bank/cycle of current weapon + + for ( i = cycle; i < maxWeapsInBank; i++ ) { + equiv = getNextWeapInBank( bank, i ); + if ( CG_WeaponSelectable( equiv ) ) { // found a reasonable replacement + cg.weaponSelect = equiv; + CG_FinishWeaponChange( cg.predictedPlayerState.weapon, cg.weaponSelect ); //----(SA) + return; + } + } + + + // still nothing available, just go to the next + // available weap using the regular selection scheme + CG_NextWeap( qtrue ); + +} + +/* +=================================================================================================== + +WEAPON EVENTS + +=================================================================================================== +*/ + +// Note to self this is dead code +void CG_MG42EFX( centity_t *cent ) { + vec3_t forward; + vec3_t point; + refEntity_t flash; + +// trap_S_StartSound( NULL, cent->currentState.number, CHAN_WEAPON, hWeaponSnd ); + + VectorCopy( cent->currentState.origin, point ); + AngleVectors( cent->currentState.angles, forward, NULL, NULL ); + VectorMA( point, 40, forward, point ); + trap_R_AddLightToScene( point, 200 + ( rand() & 31 ),1.0, 0.6, 0.23, 0 ); + + memset( &flash, 0, sizeof( flash ) ); + flash.renderfx = RF_LIGHTING_ORIGIN; + flash.hModel = cgs.media.mg42muzzleflash; + + VectorCopy( point, flash.origin ); + AnglesToAxis( cg.refdefViewAngles, flash.axis ); + + trap_R_AddRefEntityToScene( &flash ); +} + +void CG_FLAKEFX( centity_t *cent, int whichgun ) { + entityState_t *ent; + vec3_t forward, right, up; + vec3_t point; + refEntity_t flash; + + ent = ¢->currentState; + + VectorCopy( cent->currentState.pos.trBase, point ); + AngleVectors( cent->currentState.apos.trBase, forward, right, up ); + + // gun 1 and 2 were switched + if ( whichgun == 2 ) { + VectorMA( point, 136, forward, point ); + VectorMA( point, 31, up, point ); + VectorMA( point, 22, right, point ); + } else if ( whichgun == 1 ) { + VectorMA( point, 136, forward, point ); + VectorMA( point, 31, up, point ); + VectorMA( point, -22, right, point ); + } else if ( whichgun == 3 ) { + VectorMA( point, 136, forward, point ); + VectorMA( point, 10, up, point ); + VectorMA( point, 22, right, point ); + } else if ( whichgun == 4 ) { + VectorMA( point, 136, forward, point ); + VectorMA( point, 10, up, point ); + VectorMA( point, -22, right, point ); + } + + trap_R_AddLightToScene( point, 200 + ( rand() & 31 ),1.0, 0.6, 0.23, 0 ); + + memset( &flash, 0, sizeof( flash ) ); + flash.renderfx = RF_LIGHTING_ORIGIN; + flash.hModel = cgs.media.mg42muzzleflash; + + VectorCopy( point, flash.origin ); + AnglesToAxis( cg.refdefViewAngles, flash.axis ); + + trap_R_AddRefEntityToScene( &flash ); + + trap_S_StartSound( NULL, ent->number, CHAN_WEAPON, hflakWeaponSnd ); +} + + +//----(SA) +/* +============== +CG_MortarEFX + Right now mostly copied directly from Raf's MG42 FX, but with the optional addtion of smoke +============== +*/ +void CG_MortarEFX( centity_t *cent ) { + refEntity_t flash; + + if ( cent->currentState.density & 1 ) { + // smoke + CG_ParticleImpactSmokePuff( cgs.media.smokePuffShader, cent->currentState.origin ); + } + + if ( cent->currentState.density & 2 ) { + // light + trap_R_AddLightToScene( cent->currentState.origin, 200 + ( rand() & 31 ), 1.0, 1.0, 1.0, 0 ); + + // muzzle flash + memset( &flash, 0, sizeof( flash ) ); + flash.renderfx = RF_LIGHTING_ORIGIN; + flash.hModel = cgs.media.mg42muzzleflash; + VectorCopy( cent->currentState.origin, flash.origin ); + AnglesToAxis( cg.refdefViewAngles, flash.axis ); + trap_R_AddRefEntityToScene( &flash ); + } +} + +//----(SA) end + + +// RF +/* +============== +CG_WeaponFireRecoil +============== +*/ +void CG_WeaponFireRecoil( int weapon ) { +// const vec3_t maxKickAngles = {25, 30, 25}; + float pitchRecoilAdd, pitchAdd; + float yawRandom; + vec3_t recoil; + // + pitchRecoilAdd = 0; + pitchAdd = 0; + yawRandom = 0; + // + switch ( weapon ) { + case WP_LUGER: + case WP_SILENCER: + case WP_COLT: + case WP_AKIMBO: //----(SA) added + //pitchAdd = 2+rand()%3; + //yawRandom = 2; + break; + case WP_MAUSER: + case WP_GARAND: + //pitchAdd = 4+rand()%3; + //yawRandom = 4; + pitchAdd = 2; //----(SA) for DM + yawRandom = 1; //----(SA) for DM + break; + case WP_SNIPERRIFLE: + case WP_SNOOPERSCOPE: + pitchAdd = 0.6; + break; + case WP_FG42SCOPE: + case WP_FG42: + case WP_MP40: + case WP_THOMPSON: + case WP_STEN: + //pitchRecoilAdd = 1; + pitchAdd = 1 + rand() % 3; + yawRandom = 2; + + + pitchAdd *= 0.3; + yawRandom *= 0.3; + break; + case WP_PANZERFAUST: + //pitchAdd = 12+rand()%3; + //yawRandom = 6; + + CG_StartShakeCamera( 0.05, 700, cg.snap->ps.origin, 100 ); + + // push the player back instead + break; + case WP_VENOM: + pitchRecoilAdd = pow( random(),8 ) * ( 10 + VectorLength( cg.snap->ps.velocity ) / 5 ); + pitchAdd = ( rand() % 5 ) - 2; + yawRandom = 2; + + + pitchRecoilAdd *= 0.5; + pitchAdd *= 0.5; + yawRandom *= 0.5; + break; + default: + return; + } + // calc the recoil + recoil[YAW] = crandom() * yawRandom; + recoil[ROLL] = -recoil[YAW]; // why not + recoil[PITCH] = -pitchAdd; + // scale it up a bit (easier to modify this while tweaking) + VectorScale( recoil, 30, recoil ); + // set the recoil + VectorCopy( recoil, cg.kickAVel ); + // set the recoil + cg.recoilPitch -= pitchRecoilAdd; +} + + +/* +================ +CG_FireWeapon + +Caused by an EV_FIRE_WEAPON event + +================ +*/ +void CG_FireWeapon( centity_t *cent ) { + entityState_t *ent; + int c; + weaponInfo_t *weap; + sfxHandle_t *firesound; + sfxHandle_t *fireEchosound; + + ent = ¢->currentState; + + // Rafael - mg42 + if ( ( cent->currentState.clientNum == cg.snap->ps.clientNum && cg.snap->ps.persistant[PERS_HWEAPON_USE] ) || + ( cent->currentState.clientNum != cg.snap->ps.clientNum && ( cent->currentState.eFlags & EF_MG42_ACTIVE ) ) ) { + if ( cg.snap->ps.gunfx ) { + return; + } + + trap_S_StartSound( NULL, cent->currentState.number, CHAN_WEAPON, hWeaponSnd ); + //trap_S_StartSound( NULL, ent->number, CHAN_WEAPON, hWeaponSnd ); + if ( cg_brassTime.integer > 0 ) { + CG_MachineGunEjectBrass( cent ); + } + + // CG_MG42EFX (cent); + + return; + } + + if ( ent->weapon == WP_NONE ) { + return; + } + if ( ent->weapon >= WP_NUM_WEAPONS ) { + CG_Error( "CG_FireWeapon: ent->weapon >= WP_NUM_WEAPONS" ); + return; + } + weap = &cg_weapons[ ent->weapon ]; + + cg.lastFiredWeapon = ent->weapon; //----(SA) added + + // mark the entity as muzzle flashing, so when it is added it will + // append the flash to the weapon model + cent->muzzleFlashTime = cg.time; + + // RF, kick angles + if ( ent->number == cg.snap->ps.clientNum ) { + CG_WeaponFireRecoil( ent->weapon ); + } + + // lightning gun only does this this on initial press + if ( ent->weapon == WP_FLAMETHROWER ) { + if ( cent->pe.lightningFiring ) { + return; + } + } else if ( ent->weapon == WP_GRENADE_LAUNCHER || + ent->weapon == WP_GRENADE_PINEAPPLE || + ent->weapon == WP_DYNAMITE || + ent->weapon == WP_GRENADE_SMOKE ) { // JPW NERVE + if ( ent->weapon == WP_GRENADE_SMOKE ) { + CG_Printf( "smoke grenade!\n" ); + } + if ( ent->apos.trBase[0] > 0 ) { // underhand + return; + } + } + + // play quad sound if needed + if ( cent->currentState.powerups & ( 1 << PW_QUAD ) ) { + trap_S_StartSound( NULL, cent->currentState.number, CHAN_ITEM, cgs.media.quadSound ); + } + + if ( ( cent->currentState.event & ~EV_EVENT_BITS ) == EV_FIRE_WEAPON_LASTSHOT ) { + firesound = &weap->lastShotSound[0]; + fireEchosound = &weap->flashEchoSound[0]; + + // try to use the lastShotSound, but don't assume it's there. + // if a weapon without the sound calls it, drop back to regular fire sound + + for ( c = 0; c < 4; c++ ) { + if ( !firesound[c] ) { + break; + } + } + if ( !c ) { + firesound = &weap->flashSound[0]; + fireEchosound = &weap->flashEchoSound[0]; + } + } else { + firesound = &weap->flashSound[0]; + fireEchosound = &weap->flashEchoSound[0]; + } + + + // play a sound + for ( c = 0 ; c < 4 ; c++ ) { + if ( !firesound[c] ) { + break; + } + } + if ( c > 0 ) { + c = rand() % c; + if ( firesound[c] ) { + trap_S_StartSound( NULL, ent->number, CHAN_WEAPON, firesound[c] ); + + if ( fireEchosound && fireEchosound[c] ) { // check for echo + centity_t *cent; + vec3_t porg, gorg, norm; // player/gun origin + float gdist; + + cent = &cg_entities[ent->number]; + VectorCopy( cent->currentState.pos.trBase, gorg ); + VectorCopy( cg.refdef.vieworg, porg ); + VectorSubtract( gorg, porg, norm ); + gdist = VectorNormalize( norm ); + if ( gdist > 512 && gdist < 4096 ) { // temp dist. TODO: use numbers that are weapon specific + // use gorg as the new sound origin + VectorMA( cg.refdef.vieworg, 64, norm, gorg ); // sound-on-a-stick + trap_S_StartSoundEx( gorg, ent->number, CHAN_WEAPON, fireEchosound[c], SND_NOCUT ); + } + } + } + } + + // do brass ejection + if ( weap->ejectBrassFunc && cg_brassTime.integer > 0 ) { + weap->ejectBrassFunc( cent ); + } +} + + +// Ridah +/* +================= +CG_AddSparks +================= +*/ +void CG_AddSparks( vec3_t origin, vec3_t dir, int speed, int duration, int count, float randScale ) { + localEntity_t *le; + refEntity_t *re; + vec3_t velocity; + int i; + + for ( i = 0; i < count; i++ ) { + le = CG_AllocLocalEntity(); + re = &le->refEntity; + + VectorSet( velocity, dir[0] + crandom() * randScale, dir[1] + crandom() * randScale, dir[2] + crandom() * randScale ); + VectorScale( velocity, (float)speed, velocity ); + + le->leType = LE_SPARK; + le->startTime = cg.time; + le->endTime = le->startTime + duration - (int)( 0.5 * random() * duration ); + le->lastTrailTime = cg.time; + + VectorCopy( origin, re->origin ); + AxisCopy( axisDefault, re->axis ); + + le->pos.trType = TR_GRAVITY_LOW; + VectorCopy( origin, le->pos.trBase ); + VectorMA( le->pos.trBase, 2 + random() * 4, dir, le->pos.trBase ); + VectorCopy( velocity, le->pos.trDelta ); + le->pos.trTime = cg.time; + + le->refEntity.customShader = cgs.media.sparkParticleShader; + + le->bounceFactor = 0.9; + +// le->leBounceSoundType = LEBS_BLOOD; +// le->leMarkType = LEMT_BLOOD; + } +} +/* +================= +CG_AddBulletParticles +================= +*/ +void CG_AddBulletParticles( vec3_t origin, vec3_t dir, int speed, int duration, int count, float randScale ) { +// localEntity_t *le; +// refEntity_t *re; + vec3_t velocity, pos; + int i; +/* + // add the falling streaks + for (i=0; irefEntity; + + VectorSet( velocity, dir[0] + crandom()*randScale, dir[1] + crandom()*randScale, dir[2] + crandom()*randScale ); + VectorScale( velocity, (float)speed*3, velocity ); + + le->leType = LE_SPARK; + le->startTime = cg.time; + le->endTime = le->startTime + duration - (int)(0.5 * random() * duration); + le->lastTrailTime = cg.time; + + VectorCopy( origin, re->origin ); + AxisCopy( axisDefault, re->axis ); + + le->pos.trType = TR_GRAVITY; + VectorCopy( origin, le->pos.trBase ); + VectorMA( le->pos.trBase, 2 + random()*4, dir, le->pos.trBase ); + VectorCopy( velocity, le->pos.trDelta ); + le->pos.trTime = cg.time; + + le->refEntity.customShader = cgs.media.bulletParticleTrailShader; +// le->refEntity.customShader = cgs.media.sparkParticleShader; + + le->bounceFactor = 0.9; + +// le->leBounceSoundType = LEBS_BLOOD; +// le->leMarkType = LEMT_BLOOD; + } +*/ + // add the falling particles + for ( i = 0; i < count; i++ ) { + + VectorSet( velocity, dir[0] + crandom() * randScale, dir[1] + crandom() * randScale, dir[2] + crandom() * randScale ); + VectorScale( velocity, (float)speed, velocity ); + + VectorCopy( origin, pos ); + VectorMA( pos, 2 + random() * 4, dir, pos ); + + CG_ParticleBulletDebris( pos, velocity, 300 + rand() % 300 ); + + } +} + +//----(SA) from MP +/* +================= +CG_AddDirtBulletParticles +================= +*/ +void CG_AddDirtBulletParticles( vec3_t origin, vec3_t dir, int speed, int duration, int count, float randScale, + float width, float height, float alpha, char *shadername ) { // JPW NERVE + vec3_t velocity, pos; + int i; + + // add the big falling particle + VectorSet( velocity, 0, 0, (float)speed ); + + VectorCopy( origin, pos ); + +// JPW NERVE + CG_ParticleDirtBulletDebris_Core( pos, velocity, duration, width,height, alpha, shadername ); //600 + rand()%300 ); // keep central one + for ( i = 0; i < count; i++ ) { + VectorSet( velocity, dir[0] * crandom() * speed * randScale, + dir[1] * crandom() * speed * randScale, dir[2] * random() * speed ); + CG_ParticleDirtBulletDebris_Core( pos, velocity, duration + ( rand() % ( duration >> 1 ) ), // dur * 0.5, but int + width,height, alpha, shadername ); + } +} +//----(SA) end + +/* +================= +CG_AddDebris +================= +*/ +void CG_AddDebris( vec3_t origin, vec3_t dir, int speed, int duration, int count ) { + localEntity_t *le; + refEntity_t *re; + vec3_t velocity, unitvel; + float timeAdd; + int i; + + for ( i = 0; i < count; i++ ) { + le = CG_AllocLocalEntity(); + re = &le->refEntity; + + VectorSet( unitvel, dir[0] + crandom() * 0.9, dir[1] + crandom() * 0.9, fabs( dir[2] ) > 0.5 ? dir[2] * ( 0.2 + 0.8 * random() ) : random() * 0.6 ); + VectorScale( unitvel, (float)speed + (float)speed * 0.5 * crandom(), velocity ); + + le->leType = LE_DEBRIS; + le->startTime = cg.time; + le->endTime = le->startTime + duration + (int)( (float)duration * 0.8 * crandom() ); + le->lastTrailTime = cg.time; + + VectorCopy( origin, re->origin ); + AxisCopy( axisDefault, re->axis ); + + le->pos.trType = TR_GRAVITY_LOW; + VectorCopy( origin, le->pos.trBase ); + VectorCopy( velocity, le->pos.trDelta ); + le->pos.trTime = cg.time; + + timeAdd = 10.0 + random() * 40.0; + BG_EvaluateTrajectory( &le->pos, cg.time + (int)timeAdd, le->pos.trBase ); + + le->bounceFactor = 0.5; + +// if (!rand()%2) +// le->effectWidth = 0; // no flame +// else + le->effectWidth = 5 + random() * 5; + +// if (rand()%3) + le->effectFlags |= 1; // smoke trail + + +// le->leBounceSoundType = LEBS_BLOOD; +// le->leMarkType = LEMT_BLOOD; + } +} +// done. + + +/* +============== +CG_WaterRipple +============== +*/ +void CG_WaterRipple( qhandle_t shader, vec3_t loc, vec3_t dir, int size, int lifetime ) { + localEntity_t *le; + refEntity_t *re; + + le = CG_AllocLocalEntity(); + le->leType = LE_SCALE_FADE; + le->leFlags = LEF_PUFF_DONT_SCALE; + + le->startTime = cg.time; + le->endTime = cg.time + lifetime; + le->lifeRate = 1.0 / ( le->endTime - le->startTime ); + + re = &le->refEntity; + VectorCopy( loc, re->origin ); + re->shaderTime = cg.time / 1000.0f; + re->reType = RT_SPLASH; + re->radius = size; + re->customShader = shader; + re->shaderRGBA[0] = 0xff; + re->shaderRGBA[1] = 0xff; + re->shaderRGBA[2] = 0xff; + re->shaderRGBA[3] = 0xff; + le->color[3] = 1.0; +} + +/* +================= +CG_MissileHitWall + +Caused by an EV_MISSILE_MISS event, or directly by local bullet tracing + +ClientNum is a dummy field used to define what sort of effect to spawn +================= +*/ +void CG_MissileHitWall( int weapon, int clientNum, vec3_t origin, vec3_t dir, int surfFlags ) { // (SA) modified to send missilehitwall surface parameters + qhandle_t mod; + qhandle_t mark; + qhandle_t shader; + sfxHandle_t sfx, sfx2; + float radius; + float light; + vec3_t lightColor; + localEntity_t *le; + int r; + qboolean alphaFade = qfalse; + qboolean isSprite; + int duration; + // Ridah + int lightOverdraw; + vec3_t sprOrg; + vec3_t sprVel; + int i,j; + int markDuration; + +//----(SA) added + float shakeAmt; + int shakeDur, shakeRad; + shakeAmt = 0; + shakeDur = shakeRad = 0; +//----(SA) end + + mark = 0; + radius = 32; + sfx = 0; + sfx2 = 0; + mod = 0; + shader = 0; + light = 0; + lightColor[0] = 1; + lightColor[1] = 1; + lightColor[2] = 0; + // Ridah + lightOverdraw = 0; + + // set defaults + isSprite = qfalse; + duration = 600; + markDuration = -1; + + if ( surfFlags & SURF_SKY ) { + return; + } + + switch ( weapon ) { + case WP_KNIFE: + sfx = cgs.media.sfx_knifehit[4]; // different values for different types (stone/metal/wood/etc.) + mark = cgs.media.bulletMarkShader; + radius = 1 + rand() % 2; + + CG_AddBulletParticles( origin, dir, + 20, // speed + 800, // duration + 3 + rand() % 6, // count + 1.0 ); // rand scale + break; + + case WP_LUGER: + case WP_AKIMBO: //----(SA) added + case WP_COLT: + case WP_MAUSER: + case WP_GARAND: + case WP_SNIPERRIFLE: + case WP_SNOOPERSCOPE: + case WP_MP40: + case WP_FG42: + case WP_FG42SCOPE: + case WP_THOMPSON: + case WP_STEN: + case WP_SILENCER: + case WP_VENOM: + + // actually yeah. meant that. very rare. + if ( cg_gameType.integer == GT_SINGLE_PLAYER ) { // JPW NERVE + r = rand() & 31; + } else { + r = ( rand() & 3 ) + 1; // JPW NERVE increased spark frequency so players can tell where rounds are coming from in MP + + } + if ( r == 3 ) { + sfx = cgs.media.sfx_ric1; + } else if ( r == 2 ) { + sfx = cgs.media.sfx_ric2; + } else if ( r == 1 ) { + sfx = cgs.media.sfx_ric3; + } + + // clientNum is a dummy field used to define what sort of effect to spawn + + if ( !clientNum ) { + // RF, why is this here? we need sparks if clientNum = 0, used for warzombie + // if ( sfx ) + CG_AddSparks( origin, dir, + 350, // speed + 200, // duration + 15 + rand() % 7, // count + 0.2 ); // rand scale + } else if ( clientNum == 1 ) { // just do a little smoke puff + vec3_t d, o; + VectorMA( origin, 12, dir, o ); + VectorScale( dir, 7, d ); + d[2] += 16; + + // just snow + if ( surfFlags & SURF_SNOW ) { + CG_AddDirtBulletParticles( origin, dir, + 120, // speed + 900, // duration + 3, // count + 0.6f, + 20, + 4, + 0.3f, + "water_splash" ); // rand scale + } + + // grass/gravel + if ( surfFlags & ( SURF_GRASS | SURF_GRAVEL ) ) { + CG_AddDirtBulletParticles( origin, dir, + 190, // speed + 800, // duration + 3, // count + 0.1, + 60, + 10, + 0.5, + "dirt_splash" ); // rand scale + } else { + + CG_ParticleImpactSmokePuff( cgs.media.smokeParticleShader, o ); + + // some debris particles + CG_AddBulletParticles( origin, dir, + 20, // speed + 800, // duration + 3 + rand() % 6, // count + 1.0 ); // rand scale + + // just do a little one + if ( sfx && ( rand() % 3 == 0 ) ) { + CG_AddSparks( origin, dir, + 450, // speed + 300, // duration + 3 + rand() % 3, // count + 0.5 ); // rand scale + } + } + } else if ( clientNum == 2 ) { + sfx = 0; + mark = 0; + + // (SA) needed to do the CG_WaterRipple using a localent since I needed the timer reset on the shader for each shot + CG_WaterRipple( cgs.media.wakeMarkShaderAnim, origin, tv( 0, 0, 1 ), 32, 1000 ); + + CG_AddDirtBulletParticles( origin, dir, + 190, // speed + 900, // duration + 5, // count + 0.5, // rand scale + 50, // w + 12, // h + 0.125, // alpha + "water_splash" ); + + break; // (SA) testing + + // play a water splash + mod = cgs.media.waterSplashModel; + shader = cgs.media.waterSplashShader; + duration = 250; + + } + + // Ridah, optimization, only spawn the bullet hole if we are close + // enough to see it, this way we can leave other marks around a lot + // longer, since most of the time we can't actually see the bullet holes +// (SA) small modification. only do this for non-rifles (so you can see your shots hitting when you're zooming with a rifle scope) + if ( weapon == WP_FG42SCOPE || weapon == WP_SNIPERRIFLE || weapon == WP_SNOOPERSCOPE || ( Distance( cg.refdef.vieworg, origin ) < 384 ) ) { + + if ( clientNum ) { + + // mark and sound can potentially use the surface for override values + + mark = cgs.media.bulletMarkShader; // default + alphaFade = qtrue; // max made the bullet mark alpha (he'll make everything in the game out of 1024 textures, all with alpha blend funcs yet...) + radius = 1.5f + rand() % 2; // slightly larger for DM + + if ( surfFlags & SURF_METAL ) { + sfx = cgs.media.sfx_bullet_metalhit[rand() % 3]; + mark = cgs.media.bulletMarkShaderMetal; + alphaFade = qtrue; + } else if ( surfFlags & SURF_WOOD ) { + sfx = cgs.media.sfx_bullet_woodhit[rand() % 3]; + mark = cgs.media.bulletMarkShaderWood; + alphaFade = qtrue; + radius += 1; // experimenting with different mark sizes per surface + +/* + if (rand()%100 > 75) + { + gentity_t *sfx; + vec3_t start; + vec3_t dir; + + sfx = G_Spawn (); + + sfx->s.density = type; + + VectorCopy (tr.endpos, start); + + VectorCopy (muzzleTrace, dir); + VectorNegate (dir, dir); + + G_SetOrigin (sfx, start); + G_SetAngle (sfx, dir); + + G_AddEvent( sfx, EV_SHARD, DirToByte( dir )); + + sfx->think = G_FreeEntity; + sfx->nextthink = level.time + 1000; + + sfx->s.frame = 3 + (rand()%3) ; + + trap_LinkEntity (sfx); + + +void CG_Shard(centity_t *cent, vec3_t origin, vec3_t dir) + CG_Shard + + } + +*/ + + + } else if ( surfFlags & SURF_CERAMIC ) { + sfx = cgs.media.sfx_bullet_ceramichit[rand() % 3]; + mark = cgs.media.bulletMarkShaderCeramic; + alphaFade = qtrue; + radius += 2; // experimenting with different mark sizes per surface + + } else if ( surfFlags & SURF_GLASS ) { + sfx = cgs.media.sfx_bullet_glasshit[rand() % 3]; + mark = cgs.media.bulletMarkShaderGlass; + alphaFade = qtrue; + } else if ( surfFlags & SURF_GRASS ) { + + } else if ( surfFlags & SURF_GRAVEL ) { + + } else if ( surfFlags & SURF_SNOW ) { + + } else if ( surfFlags & SURF_ROOF ) { + + } else if ( surfFlags & SURF_CARPET ) { + + } + + } + } + break; + + + case WP_MORTAR: + sfx = cgs.media.sfx_rockexp; + mark = cgs.media.burnMarkShader; + markDuration = 60000; + radius = 64; + light = 300; + isSprite = qtrue; + duration = 1000; + lightColor[0] = 0.75; + lightColor[1] = 0.5; + lightColor[2] = 0.1; + + shakeAmt = 0.15f; + shakeDur = 600; + shakeRad = 700; + + VectorScale( dir, 16, sprVel ); + for ( i = 0; i < 5; i++ ) { + for ( j = 0; j < 3; j++ ) + sprOrg[j] = origin[j] + 64 * dir[j] + 24 * crandom(); + sprVel[2] += rand() % 50; +// CG_ParticleExplosion( 2, sprOrg, sprVel, 1000+rand()%250, 20, 40+rand()%60 ); + CG_ParticleExplosion( "blacksmokeanimb", sprOrg, sprVel, 3500 + rand() % 250, 10, 250 + rand() % 60 ); + } + + VectorMA( origin, 24, dir, sprOrg ); + VectorScale( dir, 64, sprVel ); + // RF, I like this new animation, feel free to revert + CG_ParticleExplosion( "expblue", sprOrg, sprVel, 1000, 20, 300 ); + //CG_ParticleExplosion( "explode1", sprOrg, sprVel, 1200, 9, 300 ); + break; + + case WP_DYNAMITE: + shader = cgs.media.rocketExplosionShader; + sfx = cgs.media.sfx_dynamiteexp; + sfx2 = cgs.media.sfx_dynamiteexpDist; + mark = cgs.media.burnMarkShader; + markDuration = 60000; + radius = 64; + light = 300; + isSprite = qtrue; + duration = 1000; + lightColor[0] = 0.75; + lightColor[1] = 0.5; + lightColor[2] = 0.1; + + shakeAmt = 0.25f; + shakeDur = 2800; + shakeRad = 8192; + + if ( cg_gameType.integer == GT_SINGLE_PLAYER ) { // JPW NERVE + for ( i = 0; i < 5; i++ ) { + for ( j = 0; j < 3; j++ ) + sprOrg[j] = origin[j] + 64 * dir[j] + 24 * crandom(); + sprVel[2] += rand() % 50; + CG_ParticleExplosion( "blacksmokeanimb", sprOrg, sprVel, + 3500 + rand() % 250, // duration + 10, // startsize + 250 + rand() % 60 ); // endsize + } + + VectorMA( origin, 16, dir, sprOrg ); + VectorScale( dir, 100, sprVel ); + + // trying this one just for now just for variety + CG_ParticleExplosion( "explode1", sprOrg, sprVel, + 1200, // duration + 9, // startsize + 300 ); // endsize + + CG_AddDebris( origin, dir, + 280, // speed + 1400, // duration + 7 + rand() % 2 ); // count + } +// JPW NERVE + else { + for ( i = 0; i < 5; i++ ) { + for ( j = 0; j < 2; j++ ) + sprOrg[j] = origin[j] + 96 * crandom(); + sprOrg[2] = origin[2] + 32 * random(); + sprVel[2] += rand() % 75; + CG_ParticleExplosion( "blacksmokeanimb", sprOrg, sprVel, + 3500 + rand() % 250, // duration + 10, // startsize + 250 + rand() % 400 ); // endsize + } + + VectorMA( origin, 16, dir, sprOrg ); + VectorScale( dir, 100, sprVel ); + + // trying this one just for now just for variety + CG_ParticleExplosion( "explode1", sprOrg, sprVel, + 1200, // duration + 9, // startsize + 250 + rand() % 400 ); // endsize + + CG_AddDebris( origin, dir, + 400 + random() * 300, // speed + 1400, // duration + 7 + rand() % 12 ); // count + } +// jpw + break; + + case WP_GRENADE_SMOKE: // JPW NERVE + case WP_GRENADE_LAUNCHER: + case WP_GRENADE_PINEAPPLE: +// mod = cgs.media.dishFlashModel; +// shader = cgs.media.grenadeExplosionShader; + shader = cgs.media.rocketExplosionShader; // copied from RL + sfx = cgs.media.sfx_rockexp; + mark = cgs.media.burnMarkShader; + markDuration = 60000; + radius = 64; + light = 300; + isSprite = qtrue; + duration = 1000; + lightColor[0] = 0.75; + lightColor[1] = 0.5; + lightColor[2] = 0.1; + + if ( weapon != WP_GRENADE_SMOKE ) { + shakeAmt = 0.15f; + shakeDur = 1000; + shakeRad = 600; + } + + // Ridah, explosion sprite animation + VectorMA( origin, 16, dir, sprOrg ); + VectorScale( dir, 100, sprVel ); + + // RF, testing new explosion animation + CG_ParticleExplosion( "expblue", sprOrg, sprVel, 700, 20, 160 ); + //CG_ParticleExplosion( "twiltb", sprOrg, sprVel, 600, 9, 100 ); + //CG_ParticleExplosion( 3, sprOrg, sprVel, 900, 9, 250 ); +/* + r = 2 + rand()%3; + for (i=0; i<3; i++) { + for (j=0;j<3;j++) sprOrg[j] = origin[j] + 14*dir[j] + 14*crandom(); + CG_ParticleExplosion( 3, sprOrg, sprVel, 800+rand()%250, 9, 60+rand()%200 ); + } +*/ + // Ridah, throw some debris + CG_AddDebris( origin, dir, + 280, // speed + 1400, // duration + // 15 + rand()%5 ); // count + 7 + rand() % 2 ); // count + + break; + case VERYBIGEXPLOSION: + case WP_PANZERFAUST: +// mod = cgs.media.dishFlashModel; +// shader = cgs.media.rocketExplosionShader; + sfx = cgs.media.sfx_rockexp; + mark = cgs.media.burnMarkShader; + markDuration = 60000; + radius = 64; + light = 600; + isSprite = qtrue; + duration = 1000; + // Ridah, changed to flamethrower colors +// lightColor[0] = 1; +// lightColor[1] = 1;//0.75; +// lightColor[2] = 0.6;//0.0; + lightColor[0] = 0.75; + lightColor[1] = 0.5; + lightColor[2] = 0.1; + + // explosion sprite animation + VectorMA( origin, 24, dir, sprOrg ); + VectorScale( dir, 64, sprVel ); + + // cam shake + if ( weapon == VERYBIGEXPLOSION ) { + shakeAmt = 0.2f; + shakeDur = 1000; + shakeRad = 1200; + } else { + shakeAmt = 0.15f; + shakeDur = 800; + shakeRad = 1000; + } + +// JPW NERVE + if ( cg_gameType.integer == GT_SINGLE_PLAYER ) { + if ( weapon == VERYBIGEXPLOSION ) { + CG_ParticleExplosion( "explode1", sprOrg, sprVel, 1200, 20, 300 ); + } else { + CG_ParticleExplosion( "explode1", sprOrg, sprVel, 1400, 40, 70 ); + } + + // NOTE: these must all have the same duration, so that we are less likely to use a wider range of images per scene + r = 2 + rand() % 3; + for ( i = 0; i < 4; i++ ) { + if ( weapon == VERYBIGEXPLOSION ) { + for ( j = 0; j < 3; j++ ) sprOrg[j] = origin[j] + 32 * dir[j] + 32 * crandom(); + CG_ParticleExplosion( "explode1", sprOrg, sprVel, 1200, 40, 160 + rand() % 120 ); + } else if ( i < 2 ) { + for ( j = 0; j < 3; j++ ) sprOrg[j] = origin[j] + 24 * dir[j] + 16 * crandom(); + CG_ParticleExplosion( "explode1", sprOrg, sprVel, 1400, 15, 40 + rand() % 30 ); + } + } + + // Ridah, throw some debris + CG_AddDebris( origin, dir, + 120, // speed + 2000, //350, // duration + // 15 + rand()%5 ); // count + 7 + rand() % 2 ); // count + } +// JPW NERVE -- multiplayer explosions over the top due to large damage radiusesesizes + else { + CG_ParticleExplosion( "explode1", sprOrg, sprVel, 1600, 20, 200 + random() * 400 ); + + // NOTE: these must all have the same duration, so that we are less likely to use a wider range of images per scene + r = 2 + rand() % 3; + for ( i = 0; i < 4; i++ ) { + for ( j = 0; j < 3; j++ ) sprOrg[j] = origin[j] + 160 * crandom(); + CG_ParticleExplosion( "explode1", sprOrg, sprVel, 1600, 40, 260 + rand() % 120 ); + } + + CG_AddDebris( origin, dir, + 400 + random() * 200, // speed + rand() % 2000 + 1000, //350, // duration + // 15 + rand()%5 ); // count + 5 + rand() % 5 ); // count + + } +// jpw +/* + // some sparks + CG_AddSparks( origin, dir, + 200, // speed + 800, // duration + 5 + rand()%10, // count + 0.8 ); // rand scale +*/ + // done. + + break; + + default: + case WP_FLAMETHROWER: + // no explosion at LG impact, it is added with the beam + return; + + break; + + } + // done. + + if ( sfx ) { + trap_S_StartSound( origin, ENTITYNUM_WORLD, CHAN_AUTO, sfx ); + } + +//----(SA) added + if ( sfx2 ) { // distant sounds for weapons with a broadcast fire sound (so you /always/ hear dynamite explosions) + trap_S_StartLocalSound( sfx2, CHAN_AUTO ); + } +//----(SA) end + + + // + // camera shake + // + if ( shakeAmt ) { + CG_StartShakeCamera( shakeAmt, shakeDur, origin, shakeRad ); + } + + + // + // create the explosion + // + if ( mod ) { + le = CG_MakeExplosion( origin, dir, + mod, shader, + duration, isSprite ); + le->light = light; + // Ridah + le->lightOverdraw = lightOverdraw; + VectorCopy( lightColor, le->lightColor ); + } + + // + // impact mark + // + if ( mark ) { + CG_ImpactMark( mark, origin, dir, random() * 360, 1,1,1,1, alphaFade, radius, qfalse, -1 ); + } +} + +/* +============== +CG_MissileHitWallSmall +============== +*/ +void CG_MissileHitWallSmall( int weapon, int clientNum, vec3_t origin, vec3_t dir ) { + qhandle_t mod; + qhandle_t mark; + qhandle_t shader; + sfxHandle_t sfx; + float radius; + float light; + vec3_t lightColor; + localEntity_t *le; +// int r; + qboolean alphaFade; + qboolean isSprite; + int duration; + // Ridah + int lightOverdraw; + vec3_t sprOrg; + vec3_t sprVel; +// int i,j; + + mark = 0; + radius = 32; + sfx = 0; + mod = 0; + shader = 0; + light = 0; + lightColor[0] = 1; + lightColor[1] = 1; + lightColor[2] = 0; + // Ridah + lightOverdraw = 0; + + // set defaults + isSprite = qfalse; + duration = 600; + + shader = cgs.media.rocketExplosionShader; // copied from RL + sfx = cgs.media.sfx_rockexp; + mark = cgs.media.burnMarkShader; + radius = 64; + light = 300; + isSprite = qtrue; + duration = 1000; + lightColor[0] = 0.75; + lightColor[1] = 0.5; + lightColor[2] = 0.1; + + // Ridah, explosion sprite animation + VectorMA( origin, 16, dir, sprOrg ); + VectorScale( dir, 64, sprVel ); + + CG_ParticleExplosion( "explode1", sprOrg, sprVel, 600, 6, 50 ); + + // Ridah, throw some debris + CG_AddDebris( origin, dir, + 280, // speed + 1400, // duration + // 15 + rand()%5 ); // count + 7 + rand() % 2 ); // count + + if ( sfx ) { + trap_S_StartSound( origin, ENTITYNUM_WORLD, CHAN_AUTO, sfx ); + } + + // + // create the explosion + // + if ( mod ) { + le = CG_MakeExplosion( origin, dir, + mod, shader, + duration, isSprite ); + le->light = light; + // Ridah + le->lightOverdraw = lightOverdraw; + VectorCopy( lightColor, le->lightColor ); + } + + // + // impact mark + // + alphaFade = ( mark == cgs.media.energyMarkShader ); // plasma fades alpha, all others fade color + // CG_ImpactMark( mark, origin, dir, random()*360, 1,1,1,1, alphaFade, radius, qfalse, 60000 ); + CG_ImpactMark( mark, origin, dir, random() * 360, 1,1,1,1, alphaFade, radius, qfalse, 0xffffffff ); + + CG_StartShakeCamera( 0.05, 300, origin, 300 ); +} + +/* +================= +CG_MissileHitPlayer +================= +*/ +void CG_MissileHitPlayer( centity_t *cent, int weapon, vec3_t origin, vec3_t dir, int entityNum ) { + int i; + + CG_Bleed( origin, entityNum ); + + // some weapons will make an explosion with the blood, while + // others will just make the blood + switch ( weapon ) { + // knives just make the flesh hit sound. no other effects + case WP_KNIFE: + i = rand() % 4; + if ( cgs.media.sfx_knifehit[i] ) { + trap_S_StartSound( origin, cent->currentState.number, CHAN_WEAPON, cgs.media.sfx_knifehit[i] ); + } + + if ( cent->currentState.number == cg.snap->ps.clientNum ) { + CG_StartShakeCamera( 0.03, 500, origin, 100 ); + } + break; + + case WP_GRENADE_LAUNCHER: + case WP_PANZERFAUST: + // this shake is /on top/ of the shake from the impact (done in CG_MissileHitWall) + CG_StartShakeCamera( 0.1, 500, origin, 100 ); + CG_MissileHitWall( weapon, 0, origin, dir, 0 ); // (SA) modified to send missilehitwall surface parameters + break; + default: + break; + } +} + + + +/* +============================================================================ + +VENOM GUN TRACING + +============================================================================ +*/ + +/* +================ +CG_VenomPellet +================ +*/ +static void CG_VenomPellet( vec3_t start, vec3_t end, int skipNum ) +{} + + +//----(SA) all changes to venom below should be mine +#define DEFAULT_VENOM_COUNT 10 +//#define DEFAULT_VENOM_SPREAD 20 +//#define DEFAULT_VENOM_SPREAD 400 +#define DEFAULT_VENOM_SPREAD 700 + +/* +================ +CG_VenomPattern + +Perform the same traces the server did to locate the +hit splashes (FIXME: random seed isn't synced anymore) + + (SA) right now this is random like a shotgun. I want to make it more + organized so that the pattern is more of a circle (with some degree of randomness) +================ +*/ +static void CG_VenomPattern( vec3_t origin, vec3_t origin2, int otherEntNum ) { + int i; + float r, u; + vec3_t end; + vec3_t forward, right, up; + + // derive the right and up vectors from the forward vector, because + // the client won't have any other information + VectorNormalize2( origin2, forward ); + PerpendicularVector( right, forward ); + CrossProduct( forward, right, up ); + + // generate the "random" spread pattern + for ( i = 0 ; i < DEFAULT_VENOM_COUNT ; i++ ) { + r = crandom() * DEFAULT_VENOM_SPREAD; + u = crandom() * DEFAULT_VENOM_SPREAD; + VectorMA( origin, 8192, forward, end ); + VectorMA( end, r, right, end ); + VectorMA( end, u, up, end ); + + CG_VenomPellet( origin, end, otherEntNum ); + } +} + +/* +============== +CG_VenomFire +============== +*/ +void CG_VenomFire( entityState_t *es, qboolean fullmode ) { + vec3_t v; + int contents; + + VectorSubtract( es->origin2, es->pos.trBase, v ); + VectorNormalize( v ); + VectorScale( v, 32, v ); + VectorAdd( es->pos.trBase, v, v ); + if ( cgs.glconfig.hardwareType != GLHW_RAGEPRO ) { + // ragepro can't alpha fade, so don't even bother with smoke + vec3_t up; + + contents = trap_CM_PointContents( es->pos.trBase, 0 ); + if ( !( contents & CONTENTS_WATER ) ) { + VectorSet( up, 0, 0, 32 ); + if ( fullmode ) { + CG_SmokePuff( v, up, 24, 1, 1, 1, 0.33, 1200, cg.time, 0, 0, cgs.media.shotgunSmokePuffShader ); // LEF_PUFF_DONT_SCALE + } +//----(SA) for the time being don't do the single shot smoke as it's position is funky +// else +// CG_SmokePuff( v, up, 4, 1, 1, 1, 0.33, 700, cg.time, 0, cgs.media.shotgunSmokePuffShader ); + } + } + if ( fullmode ) { + CG_VenomPattern( es->pos.trBase, es->origin2, es->otherEntityNum ); + } +} + +/* +============================================================================ + +BULLETS + +============================================================================ +*/ + +/* +=============== +CG_SpawnTracer +=============== +*/ +void CG_SpawnTracer( int sourceEnt, vec3_t pstart, vec3_t pend ) { + localEntity_t *le; + float dist; + vec3_t dir, ofs; + orientation_t or; + vec3_t start, end; + + VectorCopy( pstart, start ); + VectorCopy( pend, end ); + + VectorSubtract( end, start, dir ); + dist = VectorNormalize( dir ); + + if ( dist < 2.0 * cg_tracerLength.value ) { + return; // segment isnt long enough, dont bother + + } + if ( sourceEnt < cgs.maxclients ) { + // for visual purposes, find the actual tag_weapon for this client + // and offset the start and end accordingly + if ( cg_entities[sourceEnt].currentState.eFlags & EF_MG42_ACTIVE ) { // mounted + start[2] -= 32; // (SA) hack to get the tracer down below the barrel FIXME: do properly + } else { + if ( CG_GetWeaponTag( sourceEnt, "tag_flash", &or ) ) { + VectorSubtract( or.origin, start, ofs ); + if ( VectorLength( ofs ) < 64 ) { + VectorAdd( start, ofs, start ); + //VectorAdd( end, ofs, end ); + } + } + } + } + + // subtract the length of the tracer from the end point, so we dont go through the end point + VectorMA( end, -cg_tracerLength.value, dir, end ); + dist = VectorDistance( start, end ); + + le = CG_AllocLocalEntity(); + le->leType = LE_MOVING_TRACER; + le->startTime = cg.time - ( cg.frametime ? ( rand() % cg.frametime ) / 2 : 0 ); + le->endTime = le->startTime + 1000.0 * dist / cg_tracerSpeed.value; + + le->pos.trType = TR_LINEAR; + le->pos.trTime = le->startTime; + VectorCopy( start, le->pos.trBase ); + VectorScale( dir, cg_tracerSpeed.value, le->pos.trDelta ); +} + +/* +=============== +CG_DrawTracer +=============== +*/ +void CG_DrawTracer( vec3_t start, vec3_t finish ) { + vec3_t forward, right; + polyVert_t verts[4]; + vec3_t line; + + VectorSubtract( finish, start, forward ); + + line[0] = DotProduct( forward, cg.refdef.viewaxis[1] ); + line[1] = DotProduct( forward, cg.refdef.viewaxis[2] ); + + VectorScale( cg.refdef.viewaxis[1], line[1], right ); + VectorMA( right, -line[0], cg.refdef.viewaxis[2], right ); + VectorNormalize( right ); + + VectorMA( finish, cg_tracerWidth.value, right, verts[0].xyz ); + verts[0].st[0] = 1; + verts[0].st[1] = 1; + verts[0].modulate[0] = 255; + verts[0].modulate[1] = 255; + verts[0].modulate[2] = 255; + verts[0].modulate[3] = 255; + + VectorMA( finish, -cg_tracerWidth.value, right, verts[1].xyz ); + verts[1].st[0] = 1; + verts[1].st[1] = 0; + verts[1].modulate[0] = 255; + verts[1].modulate[1] = 255; + verts[1].modulate[2] = 255; + verts[1].modulate[3] = 255; + + VectorMA( start, -cg_tracerWidth.value, right, verts[2].xyz ); + verts[2].st[0] = 0; + verts[2].st[1] = 0; + verts[2].modulate[0] = 255; + verts[2].modulate[1] = 255; + verts[2].modulate[2] = 255; + verts[2].modulate[3] = 255; + + VectorMA( start, cg_tracerWidth.value, right, verts[3].xyz ); + verts[3].st[0] = 0; + verts[3].st[1] = 1; + verts[3].modulate[0] = 255; + verts[3].modulate[1] = 255; + verts[3].modulate[2] = 255; + verts[3].modulate[3] = 255; + + trap_R_AddPolyToScene( cgs.media.tracerShader, 4, verts ); +} + +/* +=============== +CG_Tracer +=============== +*/ +void CG_Tracer( vec3_t source, vec3_t dest, int sparks ) { + float len, begin, end; + vec3_t start, finish; + vec3_t midpoint; + vec3_t forward; + + // tracer + VectorSubtract( dest, source, forward ); + len = VectorNormalize( forward ); + + // start at least a little ways from the muzzle + if ( len < 100 && !sparks ) { + return; + } + begin = 50 + random() * ( len - 60 ); + end = begin + cg_tracerLength.value; + if ( end > len ) { + end = len; + } + VectorMA( source, begin, forward, start ); + VectorMA( source, end, forward, finish ); + + CG_DrawTracer( start, finish ); + + midpoint[0] = ( start[0] + finish[0] ) * 0.5; + midpoint[1] = ( start[1] + finish[1] ) * 0.5; + midpoint[2] = ( start[2] + finish[2] ) * 0.5; + + // add the tracer sound + // trap_S_StartSound( midpoint, ENTITYNUM_WORLD, CHAN_AUTO, cgs.media.tracerSound ); + +} + + +/* +====================== +CG_CalcMuzzlePoint +====================== +*/ +static qboolean CG_CalcMuzzlePoint( int entityNum, vec3_t muzzle ) { + vec3_t forward, right, up; + centity_t *cent; + int anim; + + if ( entityNum == cg.snap->ps.clientNum ) { + VectorCopy( cg.snap->ps.origin, muzzle ); + muzzle[2] += cg.snap->ps.viewheight; + AngleVectors( cg.snap->ps.viewangles, forward, NULL, NULL ); + VectorMA( muzzle, 14, forward, muzzle ); + return qtrue; + } + + cent = &cg_entities[entityNum]; +//----(SA) removed check. is this still necessary? (this way works for ai's firing mg42) should I check for mg42? +// if ( !cent->currentValid ) { +// return qfalse; +// } +//----(SA) end + + VectorCopy( cent->currentState.pos.trBase, muzzle ); + + AngleVectors( cent->currentState.apos.trBase, forward, right, up ); + anim = cent->currentState.legsAnim & ~ANIM_TOGGLEBIT; +// RF, this is all broken by scripting system +// if ( anim == LEGS_WALKCR || anim == LEGS_IDLECR || anim == LEGS_IDLE_ALT ) { +// muzzle[2] += CROUCH_VIEWHEIGHT; +// } else { + muzzle[2] += DEFAULT_VIEWHEIGHT; +// } + + VectorMA( muzzle, 14, forward, muzzle ); + + return qtrue; + +} + +/* +====================== +CG_Bullet + +Renders bullet effects. +====================== +*/ +void CG_Bullet( vec3_t end, int sourceEntityNum, vec3_t normal, qboolean flesh, int fleshEntityNum, qboolean wolfkick, int otherEntNum2 ) { + trace_t trace; + int sourceContentType = 0, destContentType = 0; // TTimo: init + vec3_t dir; + vec3_t start, trend, tmp; // JPW + static int lastBloodSpat; + centity_t *cent; + + cent = &cg_entities[fleshEntityNum]; + + // if the shooter is currently valid, calc a source point and possibly + // do trail effects + if ( sourceEntityNum >= 0 && cg_tracerChance.value > 0 ) { + if ( CG_CalcMuzzlePoint( sourceEntityNum, start ) ) { + sourceContentType = trap_CM_PointContents( start, 0 ); + destContentType = trap_CM_PointContents( end, 0 ); + + // do a complete bubble trail if necessary + if ( ( sourceContentType == destContentType ) && ( sourceContentType & CONTENTS_WATER ) ) { + CG_BubbleTrail( start, end, .5, 8 ); + } + // bubble trail from water into air + else if ( ( sourceContentType & CONTENTS_WATER ) ) { + trap_CM_BoxTrace( &trace, end, start, NULL, NULL, 0, CONTENTS_WATER ); + CG_BubbleTrail( start, trace.endpos, .5, 8 ); + } + // bubble trail from air into water + else if ( ( destContentType & CONTENTS_WATER ) ) { +// CG_Printf( "Dist: %f\n", Distance(cg.refdef.vieworg, end) ); +// CG_AddDirtBulletParticles( end, dir, +// 190, // speed +// 900, // duration +// 5, // count +// 0.5, 80, 16, 0.125, "water_splash" ); // rand scale + // only add bubbles if effect is close to viewer + if ( Distance( cg.snap->ps.origin, end ) < 1024 ) { + trap_CM_BoxTrace( &trace, start, end, NULL, NULL, 0, CONTENTS_WATER ); + CG_BubbleTrail( end, trace.endpos, .5, 8 ); + } + } + + // if not flesh, then do a moving tracer + if ( flesh ) { + // draw a tracer + if ( !wolfkick && random() < cg_tracerChance.value ) { + CG_Tracer( start, end, 0 ); + } + } else { // (not flesh) + if ( otherEntNum2 >= 0 && otherEntNum2 != ENTITYNUM_NONE ) { + CG_SpawnTracer( otherEntNum2, start, end ); + } else { + CG_SpawnTracer( sourceEntityNum, start, end ); + } + } + } + } + + // impact splash and mark + if ( flesh ) { + vec3_t origin; + int aiType; + + aiType = cg_entities[fleshEntityNum].currentState.aiChar; + + if ( fleshEntityNum < MAX_CLIENTS ) { + CG_Bleed( end, fleshEntityNum ); + } + + // play the bullet hit flesh sound + // HACK, if this is not us getting hit, make it quieter + if ( fleshEntityNum == cg.snap->ps.clientNum ) { + + // (SA) TODO: for metal guys, make metal a flag rather than an aitype check? + if ( aiType == AICHAR_PROTOSOLDIER || + aiType == AICHAR_SUPERSOLDIER ) { + CG_SoundPlayIndexedScript( cgs.media.bulletHitFleshMetalScript, NULL, fleshEntityNum ); + } else { + CG_SoundPlayIndexedScript( cgs.media.bulletHitFleshScript, NULL, fleshEntityNum ); + } + } else { + VectorSubtract( cg_entities[fleshEntityNum].lerpOrigin, cg.snap->ps.origin, origin ); + VectorMA( cg.snap->ps.origin, 3, origin, origin ); + if ( aiType == AICHAR_PROTOSOLDIER || + aiType == AICHAR_SUPERSOLDIER ) { + CG_SoundPlayIndexedScript( cgs.media.bulletHitFleshMetalScript, origin, ENTITYNUM_WORLD ); + } else { + CG_SoundPlayIndexedScript( cgs.media.bulletHitFleshScript, origin, ENTITYNUM_WORLD ); + } + } + + /* + // special FX for Zombie + if (cent->currentState.aiChar == AICHAR_ZOMBIE) { + VectorSubtract( end, start, dir ); + VectorNormalize( dir ); + // upper + trap_RB_ZombieFXAddNewHit( cent->currentState.number, end, dir ); + // lower + trap_RB_ZombieFXAddNewHit( cent->currentState.number | (1<<30), end, dir ); + return; + } + */ + + // if we haven't dropped a blood spat in a while, check if this is a good scenario + if ( lastBloodSpat > cg.time || lastBloodSpat < cg.time - 500 ) { + if ( CG_CalcMuzzlePoint( sourceEntityNum, start ) ) { + VectorSubtract( end, start, dir ); + VectorNormalize( dir ); + VectorMA( end, 128, dir, trend ); + trap_CM_BoxTrace( &trace, end, trend, NULL, NULL, 0, MASK_SHOT & ~CONTENTS_BODY ); + + if ( trace.fraction < 1 ) { + CG_ImpactMark( cgs.media.bloodDotShaders[rand() % 5], trace.endpos, trace.plane.normal, random() * 360, + 1,1,1,1, qtrue, 15 + random() * 20, qfalse, cg_bloodTime.integer * 1000 ); + lastBloodSpat = cg.time; + } else if ( lastBloodSpat < cg.time - 1000 ) { + // drop one on the ground? + VectorCopy( end, trend ); + trend[2] -= 64; + trap_CM_BoxTrace( &trace, end, trend, NULL, NULL, 0, MASK_SHOT & ~CONTENTS_BODY ); + + if ( trace.fraction < 1 ) { + CG_ImpactMark( cgs.media.bloodDotShaders[rand() % 5], trace.endpos, trace.plane.normal, random() * 360, + 1,1,1,1, qtrue, 15 + random() * 10, qfalse, cg_bloodTime.integer * 1000 ); + lastBloodSpat = cg.time; + } + } + } + } + + } else { // (not flesh) + int fromweap; + fromweap = cg_entities[sourceEntityNum].currentState.weapon; + + if ( !fromweap || cg_entities[sourceEntityNum].currentState.eFlags & EF_MG42_ACTIVE ) { // mounted + fromweap = WP_MP40; + } + + // TODO: not sure what kind of effect were going to do + if ( wolfkick ) { + return; + } + + // if we didn't hit flesh, spawn a moving tracer + // moved this up to (what seems like) the proper area. trails above. didn't always have valid start/end positions here. +// if (sourceEntityNum >= 0) { +// if(otherEntNum2 >=0 && otherEntNum2 != ENTITYNUM_NONE) +// CG_SpawnTracer( otherEntNum2, start, end ); +// else +// CG_SpawnTracer( sourceEntityNum, start, end ); +// } + + if ( CG_CalcMuzzlePoint( sourceEntityNum, start ) + || cg.snap->ps.persistant[PERS_HWEAPON_USE] ) { + vec3_t start2; + VectorSubtract( end, start, dir ); + VectorNormalize( dir ); + VectorMA( end, -4, dir, start2 ); // back off a little so it doesn't start in solid + VectorMA( end, 64, dir, dir ); + trap_CM_BoxTrace( &trace, start2, dir, NULL, NULL, 0, MASK_SHOT ); + + if ( ( trace.surfaceFlags & SURF_METAL ) || !( rand() % 10 ) || ( otherEntNum2 != ENTITYNUM_NONE ) ) { + // JPW NERVE compute new spark direction from normal & dir (rotate -dir 180 degrees about normal) + + // (SA) NOTE: isn't this done by the server and sent along in the 'normal' that's passed into this routine? (1107 g_weapon.c) + + VectorScale( dir,-1.0f,tmp ); + RotatePointAroundVector( tmp,normal,tmp,180.0f ); + CG_MissileHitWall( fromweap, 0, end, tmp, trace.surfaceFlags ); // sparks // (SA) modified to send missilehitwall surface parameters +// jpw +// CG_MissileHitWall( fromweap, 0, end, normal, trace.surfaceFlags ); // sparks // (SA) modified to send missilehitwall surface parameters + } + if ( !( sourceContentType & CONTENTS_WATER ) && ( destContentType & ( CONTENTS_WATER | CONTENTS_SLIME | CONTENTS_LAVA ) ) ) { // only when shooting /into/ water + trap_CM_BoxTrace( &trace, start, end, NULL, NULL, 0, MASK_WATER ); +// CG_Trace(&trace, start, NULL, NULL, end, -1, MASK_WATER); +// if (!(trace.surfaceFlags & SURF_NOMARKS)) { // check to see if the surface should draw splashes + CG_MissileHitWall( fromweap, 2, trace.endpos, trace.plane.normal, trace.surfaceFlags ); +// } + } else { + CG_MissileHitWall( fromweap, 1, end, normal, trace.surfaceFlags ); // smoke puff // (SA) modified to send missilehitwall surface parameters + + if ( 0 ) { + localEntity_t *le; + le = CG_AllocLocalEntity(); + le->leType = LE_EMITTER; + le->startTime = cg.time; + le->endTime = le->startTime + 20000; + le->pos.trType = TR_STATIONARY; + VectorCopy( end, le->pos.trBase ); + VectorCopy( normal, le->angles.trBase ); + le->ownerNum = 0; + } + } + } + } + +} + +/* +============ +CG_ClientDamage +============ +*/ +void CG_ClientDamage( int entnum, int enemynum, int id ) { + if ( id > CLDMG_MAX ) { + CG_Error( "CG_ClientDamage: unknown damage type: %i\n", id ); + } + + // NERVE - SMF - clientDamage commands are now sent through usercmds for multiplayer + if ( cgs.gametype == GT_WOLF ) { + if ( entnum == cg.snap->ps.clientNum ) { + // NOTE: MAX_CLIENTS currently only needs 7 bits, the rest is for id tag + cg.cld = id << 7; + cg.cld |= enemynum; + } + } + // -NERVE - SMF + else { + trap_SendClientCommand( va( "cld %i %i %i", entnum, enemynum, id ) ); + } +} + diff --git a/Projects/Android/jni/rtcw/src/cgame/cgame.def b/Projects/Android/jni/rtcw/src/cgame/cgame.def new file mode 100644 index 0000000..2ee748e --- /dev/null +++ b/Projects/Android/jni/rtcw/src/cgame/cgame.def @@ -0,0 +1,3 @@ +EXPORTS + vmMain + dllEntry diff --git a/Projects/Android/jni/rtcw/src/cgame/cgame.vcproj b/Projects/Android/jni/rtcw/src/cgame/cgame.vcproj new file mode 100644 index 0000000..3f88bd8 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/cgame/cgame.vcproj @@ -0,0 +1,914 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Projects/Android/jni/rtcw/src/cgame/cgame.vcxproj b/Projects/Android/jni/rtcw/src/cgame/cgame.vcxproj new file mode 100644 index 0000000..01eddb7 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/cgame/cgame.vcxproj @@ -0,0 +1,201 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {A981B743-DF98-4346-AA89-5DECB39C165D} + + + + DynamicLibrary + v110 + false + + + DynamicLibrary + v110 + false + + + + + + + + + + + + + + + <_ProjectFileVersion>11.0.50727.1 + + + .\Debug\ + .\Debug\ + true + + + .\Release\ + .\Release\ + false + + + + _DEBUG;%(PreprocessorDefinitions) + true + true + Win32 + .\Debug/cgame.tlb + + + + Disabled + WIN32;_DEBUG;_WINDOWS;CGAMEDLL;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + true + MultiThreadedDebug + .\Debug/cgame.pch + .\Debug/ + .\Debug/ + .\Debug/ + true + Level3 + true + EditAndContinue + + + _DEBUG;%(PreprocessorDefinitions) + 0x0409 + + + odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + ..\Debug/cgamex86.dll + true + .\cgame.def + true + .\Debug/cgamex86.pdb + true + .\Debug/cgamex86.map + Windows + 0x30000000 + false + + .\Debug/cgamex86.lib + MachineX86 + + + true + .\Debug/cgame.bsc + + + + + NDEBUG;%(PreprocessorDefinitions) + true + true + Win32 + .\Release/cgame.tlb + + + + MaxSpeed + OnlyExplicitInline + WIN32;NDEBUG;_WINDOWS;CGAMEDLL;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + true + MultiThreaded + true + .\Release/cgame.pch + .\Release/ + .\Release/ + .\Release/ + Level4 + true + + + NDEBUG;%(PreprocessorDefinitions) + 0x0409 + + + odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + ../Release/cgamex86.dll + true + .\cgame.def + .\Release/cgamex86.pdb + true + .\Release/cgamex86.map + Windows + 0x30000000 + false + + .\Release/cgamex86.lib + MachineX86 + + + true + .\Release/cgame.bsc + + + + + + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Projects/Android/jni/rtcw/src/cgame/cgame.vcxproj.filters b/Projects/Android/jni/rtcw/src/cgame/cgame.vcxproj.filters new file mode 100644 index 0000000..fabbfaf --- /dev/null +++ b/Projects/Android/jni/rtcw/src/cgame/cgame.vcxproj.filters @@ -0,0 +1,146 @@ + + + + + {60b47c13-cbf3-4189-8be4-2ac660f8eff9} + c + + + {7b6aab7a-73c0-4cfc-840a-9e9cd1b0cf67} + h + + + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + + + + \ No newline at end of file diff --git a/Projects/Android/jni/rtcw/src/cgame/tr_types.h b/Projects/Android/jni/rtcw/src/cgame/tr_types.h new file mode 100644 index 0000000..ed90d9e --- /dev/null +++ b/Projects/Android/jni/rtcw/src/cgame/tr_types.h @@ -0,0 +1,343 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +#ifndef __TR_TYPES_H +#define __TR_TYPES_H + + +#define MAX_CORONAS 32 //----(SA) not really a reason to limit this other than trying to keep a reasonable count +#define MAX_DLIGHTS 32 // can't be increased, because bit flags are used on surfaces +#define MAX_ENTITIES 1023 // can't be increased without changing drawsurf bit packing + +// renderfx flags +#define RF_MINLIGHT 1 // allways have some light (viewmodel, some items) +#define RF_THIRD_PERSON 2 // don't draw through eyes, only mirrors (player bodies, chat sprites) +#define RF_FIRST_PERSON 4 // only draw through eyes (view weapon, damage blood blob) +#define RF_DEPTHHACK 8 // for view weapon Z crunching +#define RF_NOSHADOW 64 // don't add stencil shadows + +#define RF_LIGHTING_ORIGIN 128 // use refEntity->lightingOrigin instead of refEntity->origin + // for lighting. This allows entities to sink into the floor + // with their origin going solid, and allows all parts of a + // player to get the same lighting +#define RF_SHADOW_PLANE 256 // use refEntity->shadowPlane +#define RF_WRAP_FRAMES 512 // mod the model frames by the maxframes to allow continuous + // animation without needing to know the frame count + +#define RF_HILIGHT ( 1 << 8 ) // more than RF_MINLIGHT. For when an object is "Highlighted" (looked at/training identification/etc) +#define RF_BLINK ( 1 << 9 ) // eyes in 'blink' state + +// refdef flags +#define RDF_NOWORLDMODEL 1 // used for player configuration screen +#define RDF_HYPERSPACE 4 // teleportation effect + +// Rafael +#define RDF_SKYBOXPORTAL 8 + +#define RDF_DRAWSKYBOX 16 // the above marks a scene as being a 'portal sky'. this flag says to draw it or not + +//----(SA) +#define RDF_UNDERWATER ( 1 << 4 ) // so the renderer knows to use underwater fog when the player is underwater +#define RDF_DRAWINGSKY ( 1 << 5 ) +#define RDF_SNOOPERVIEW ( 1 << 6 ) //----(SA) added + + +typedef struct { + vec3_t xyz; + float st[2]; + byte modulate[4]; +} polyVert_t; + +typedef struct poly_s { + qhandle_t hShader; + int numVerts; + polyVert_t *verts; +} poly_t; + +typedef enum { + RT_MODEL, + RT_POLY, + RT_SPRITE, + RT_SPLASH, // ripple effect + RT_BEAM, + RT_RAIL_CORE, + RT_RAIL_CORE_TAPER, // a modified core that creates a properly texture mapped core that's wider at one end + RT_RAIL_RINGS, + RT_LIGHTNING, + RT_PORTALSURFACE, // doesn't draw anything, just info for portals + + RT_MAX_REF_ENTITY_TYPE +} refEntityType_t; + +#define ZOMBIEFX_FADEOUT_TIME 10000 + +#define REFLAG_ONLYHAND 1 // only draw hand surfaces +#define REFLAG_ZOMBIEFX 2 // special post-tesselation processing for zombie skin +#define REFLAG_ZOMBIEFX2 4 // special post-tesselation processing for zombie skin +#define REFLAG_FORCE_LOD 8 // force a low lod +#define REFLAG_ORIENT_LOD 16 // on LOD switch, align the model to the player's camera +#define REFLAG_DEAD_LOD 32 // allow the LOD to go lower than recommended +#define REFLAG_SCALEDSPHERECULL 64 // on LOD switch, align the model to the player's camera +#define REFLAG_FULL_LOD 8 // force a FULL lod + +typedef struct { + refEntityType_t reType; + int renderfx; + + qhandle_t hModel; // opaque type outside refresh + + // most recent data + vec3_t lightingOrigin; // so multi-part models can be lit identically (RF_LIGHTING_ORIGIN) + float shadowPlane; // projection shadows go here, stencils go slightly lower + + vec3_t axis[3]; // rotation vectors + vec3_t torsoAxis[3]; // rotation vectors for torso section of skeletal animation + qboolean nonNormalizedAxes; // axis are not normalized, i.e. they have scale + float origin[3]; // also used as MODEL_BEAM's "from" + int frame; // also used as MODEL_BEAM's diameter + int torsoFrame; // skeletal torso can have frame independant of legs frame + + vec3_t scale; //----(SA) added + + // previous data for frame interpolation + float oldorigin[3]; // also used as MODEL_BEAM's "to" + int oldframe; + int oldTorsoFrame; + float backlerp; // 0.0 = current, 1.0 = old + float torsoBacklerp; + + // texturing + int skinNum; // inline skin index + qhandle_t customSkin; // NULL for default skin + qhandle_t customShader; // use one image for the entire thing + + // misc + byte shaderRGBA[4]; // colors used by rgbgen entity shaders + float shaderTexCoord[2]; // texture coordinates used by tcMod entity modifiers + float shaderTime; // subtracted from refdef time to control effect start times + + // extra sprite information + float radius; + float rotation; + + // Ridah + vec3_t fireRiseDir; + + // Ridah, entity fading (gibs, debris, etc) + int fadeStartTime, fadeEndTime; + + float hilightIntensity; //----(SA) added + + int reFlags; + + int entityNum; // currentState.number, so we can attach rendering effects to specific entities (Zombie) + +} refEntity_t; + +//----(SA) + +// // +// WARNING:: synch FOG_SERVER in sv_ccmds.c if you change anything // +// // +typedef enum { + FOG_NONE, // 0 + + FOG_SKY, // 1 fog values to apply to the sky when using density fog for the world (non-distance clipping fog) (only used if(glfogsettings[FOG_MAP].registered) or if(glfogsettings[FOG_MAP].registered)) + FOG_PORTALVIEW, // 2 used by the portal sky scene + FOG_HUD, // 3 used by the 3D hud scene + + // The result of these for a given frame is copied to the scene.glFog when the scene is rendered + + // the following are fogs applied to the main world scene + FOG_MAP, // 4 use fog parameter specified using the "fogvars" in the sky shader + FOG_WATER, // 5 used when underwater + FOG_SERVER, // 6 the server has set my fog (probably a target_fog) (keep synch in sv_ccmds.c !!!) + FOG_CURRENT, // 7 stores the current values when a transition starts + FOG_LAST, // 8 stores the current values when a transition starts + FOG_TARGET, // 9 the values it's transitioning to. + + FOG_CMD_SWITCHFOG, // 10 transition to the fog specified in the second parameter of R_SetFog(...) (keep synch in sv_ccmds.c !!!) + + NUM_FOGS +} glfogType_t; + + +typedef struct { + int mode; // GL_LINEAR, GL_EXP + int hint; // GL_DONT_CARE + int startTime; // in ms + int finishTime; // in ms + float color[4]; + float start; // near + float end; // far + qboolean useEndForClip; // use the 'far' value for the far clipping plane + float density; // 0.0-1.0 + qboolean registered; // has this fog been set up? + qboolean drawsky; // draw skybox + qboolean clearscreen; // clear the GL color buffer + + int dirty; +} glfog_t; + +//----(SA) end + + +#define MAX_RENDER_STRINGS 8 +#define MAX_RENDER_STRING_LENGTH 32 + +typedef struct { + int x, y, width, height; + float fov_x, fov_y; + vec3_t vieworg; + vec3_t viewaxis[3]; // transformation matrix + + int time; // time in milliseconds for shader effects and other time dependent rendering issues + int rdflags; // RDF_NOWORLDMODEL, etc + + // 1 bits will prevent the associated area from rendering at all + byte areamask[MAX_MAP_AREA_BYTES]; + + + + + // text messages for deform text shaders + char text[MAX_RENDER_STRINGS][MAX_RENDER_STRING_LENGTH]; + + +//----(SA) added (needed to pass fog infos into the portal sky scene) + glfog_t glfog; +//----(SA) end + +} refdef_t; + + +typedef enum { + STEREO_CENTER, + STEREO_LEFT, + STEREO_RIGHT +} stereoFrame_t; + + +/* +** glconfig_t +** +** Contains variables specific to the OpenGL configuration +** being run right now. These are constant once the OpenGL +** subsystem is initialized. +*/ +typedef enum { + TC_NONE, + TC_S3TC, + TC_EXT_COMP_S3TC +} textureCompression_t; + +typedef enum { + GLDRV_ICD, // driver is integrated with window system + // WARNING: there are tests that check for + // > GLDRV_ICD for minidriverness, so this + // should always be the lowest value in this + // enum set + GLDRV_STANDALONE, // driver is a non-3Dfx standalone driver + GLDRV_VOODOO // driver is a 3Dfx standalone driver +} glDriverType_t; + +typedef enum { + GLHW_GENERIC, // where everthing works the way it should + GLHW_3DFX_2D3D, // Voodoo Banshee or Voodoo3, relevant since if this is + // the hardware type then there can NOT exist a secondary + // display adapter + GLHW_RIVA128, // where you can't interpolate alpha + GLHW_RAGEPRO, // where you can't modulate alpha on alpha textures + GLHW_PERMEDIA2 // where you don't have src*dst +} glHardwareType_t; + +typedef struct { + char renderer_string[MAX_STRING_CHARS]; + char vendor_string[MAX_STRING_CHARS]; + char version_string[MAX_STRING_CHARS]; + char extensions_string[4 * MAX_STRING_CHARS]; // this is actually too short for many current cards/drivers // (SA) doubled from 2x to 4x MAX_STRING_CHARS + + int maxTextureSize; // queried from GL + int maxActiveTextures; // multitexture ability + + int colorBits, depthBits, stencilBits; + + glDriverType_t driverType; + glHardwareType_t hardwareType; + + qboolean deviceSupportsGamma; + textureCompression_t textureCompression; + qboolean textureEnvAddAvailable; + qboolean anisotropicAvailable; //----(SA) added + float maxAnisotropy; //----(SA) added + + // vendor-specific support + // NVidia + qboolean NVFogAvailable; //----(SA) added + int NVFogMode; //----(SA) added + // ATI + int ATIMaxTruformTess; // for truform support + int ATINormalMode; // for truform support + int ATIPointMode; // for truform support + + + int vidWidth, vidHeight; + // aspect is the screen's physical width / height, which may be different + // than scrWidth / scrHeight if the pixels are non-square + // normal screens should be 4/3, but wide aspect monitors may be 16/9 + float windowAspect; + + int displayFrequency; + + // synonymous with "does rendering consume the entire screen?", therefore + // a Voodoo or Voodoo2 will have this set to TRUE, as will a Win32 ICD that + // used CDS. + qboolean isFullscreen; + qboolean stereoEnabled; + qboolean smpActive; // dual processor + + qboolean textureFilterAnisotropicAvailable; //DAJ +} glconfig_t; + + +#if !defined _WIN32 + +#define _3DFX_DRIVER_NAME "libMesaVoodooGL.so.3.1" +#define OPENGL_DRIVER_NAME "libGL.so.1" + +#else + +#define _3DFX_DRIVER_NAME "3dfxvgl" +#define OPENGL_DRIVER_NAME "opengl32" +#define WICKED3D_V5_DRIVER_NAME "gl/openglv5.dll" +#define WICKED3D_V3_DRIVER_NAME "gl/openglv3.dll" + +#endif // !defined _WIN32 + + +#endif // __TR_TYPES_H diff --git a/Projects/Android/jni/rtcw/src/client/cl_cgame.c b/Projects/Android/jni/rtcw/src/client/cl_cgame.c new file mode 100644 index 0000000..714c24d --- /dev/null +++ b/Projects/Android/jni/rtcw/src/client/cl_cgame.c @@ -0,0 +1,1299 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +// cl_cgame.c -- client system interaction with client game + +#include "client.h" + +#include "../game/botlib.h" + +extern botlib_export_t *botlib_export; + +extern qboolean loadCamera( int camNum, const char *name ); +extern void startCamera( int camNum, int time ); +extern qboolean getCameraInfo( int camNum, int time, vec3_t *origin, vec3_t *angles, float *fov ); + +// RF, this is only used when running a local server +extern void SV_SendMoveSpeedsToGame( int entnum, char *text ); +extern qboolean SV_GetModelInfo( int clientNum, char *modelName, animModelInfo_t **modelInfo ); + + +/* +==================== +CL_GetGameState +==================== +*/ +void CL_GetGameState( gameState_t *gs ) { + *gs = cl.gameState; +} + +/* +==================== +CL_GetGlconfig +==================== +*/ +void CL_GetGlconfig( glconfig_t *glconfig ) { + *glconfig = cls.glconfig; +} + + +/* +==================== +CL_GetUserCmd +==================== +*/ +qboolean CL_GetUserCmd( int cmdNumber, usercmd_t *ucmd ) { + // cmds[cmdNumber] is the last properly generated command + + // can't return anything that we haven't created yet + if ( cmdNumber > cl.cmdNumber ) { + Com_Error( ERR_DROP, "CL_GetUserCmd: %i >= %i", cmdNumber, cl.cmdNumber ); + } + + // the usercmd has been overwritten in the wrapping + // buffer because it is too far out of date + if ( cmdNumber <= cl.cmdNumber - CMD_BACKUP ) { + return qfalse; + } + + *ucmd = cl.cmds[ cmdNumber & CMD_MASK ]; + + return qtrue; +} + +int CL_GetCurrentCmdNumber( void ) { + return cl.cmdNumber; +} + + +/* +==================== +CL_GetParseEntityState +==================== +*/ +qboolean CL_GetParseEntityState( int parseEntityNumber, entityState_t *state ) { + // can't return anything that hasn't been parsed yet + if ( parseEntityNumber >= cl.parseEntitiesNum ) { + Com_Error( ERR_DROP, "CL_GetParseEntityState: %i >= %i", + parseEntityNumber, cl.parseEntitiesNum ); + } + + // can't return anything that has been overwritten in the circular buffer + if ( parseEntityNumber <= cl.parseEntitiesNum - MAX_PARSE_ENTITIES ) { + return qfalse; + } + + *state = cl.parseEntities[ parseEntityNumber & ( MAX_PARSE_ENTITIES - 1 ) ]; + return qtrue; +} + +/* +==================== +CL_GetCurrentSnapshotNumber +==================== +*/ +void CL_GetCurrentSnapshotNumber( int *snapshotNumber, int *serverTime ) { + *snapshotNumber = cl.snap.messageNum; + *serverTime = cl.snap.serverTime; +} + +/* +==================== +CL_GetSnapshot +==================== +*/ +qboolean CL_GetSnapshot( int snapshotNumber, snapshot_t *snapshot ) { + clSnapshot_t *clSnap; + int i, count; + + if ( snapshotNumber > cl.snap.messageNum ) { + Com_Error( ERR_DROP, "CL_GetSnapshot: snapshotNumber > cl.snapshot.messageNum" ); + } + + // if the frame has fallen out of the circular buffer, we can't return it + if ( cl.snap.messageNum - snapshotNumber >= PACKET_BACKUP ) { + return qfalse; + } + + // if the frame is not valid, we can't return it + clSnap = &cl.snapshots[snapshotNumber & PACKET_MASK]; + if ( !clSnap->valid ) { + return qfalse; + } + + // if the entities in the frame have fallen out of their + // circular buffer, we can't return it + if ( cl.parseEntitiesNum - clSnap->parseEntitiesNum >= MAX_PARSE_ENTITIES ) { + return qfalse; + } + + // write the snapshot + snapshot->snapFlags = clSnap->snapFlags; + snapshot->serverCommandSequence = clSnap->serverCommandNum; + snapshot->ping = clSnap->ping; + snapshot->serverTime = clSnap->serverTime; + memcpy( snapshot->areamask, clSnap->areamask, sizeof( snapshot->areamask ) ); + snapshot->ps = clSnap->ps; + count = clSnap->numEntities; + if ( count > MAX_ENTITIES_IN_SNAPSHOT ) { + Com_DPrintf( "CL_GetSnapshot: truncated %i entities to %i\n", count, MAX_ENTITIES_IN_SNAPSHOT ); + count = MAX_ENTITIES_IN_SNAPSHOT; + } + snapshot->numEntities = count; + for ( i = 0 ; i < count ; i++ ) { + snapshot->entities[i] = + cl.parseEntities[ ( clSnap->parseEntitiesNum + i ) & ( MAX_PARSE_ENTITIES - 1 ) ]; + } + + // FIXME: configstring changes and server commands!!! + + return qtrue; +} + +/* +============== +CL_SetUserCmdValue +============== +*/ +#ifdef AUTOAIM +void CL_SetUserCmdValue( int userCmdValue, int holdableValue, float sensitivityScale, int cld, int lastfire, int crosshairstat ) { + cl.cgameLastFireTime = lastfire; + cl.cgameCrossHairStatus = crosshairstat; +#else +void CL_SetUserCmdValue( int userCmdValue, int holdableValue, float sensitivityScale, int cld ) { +#endif + cl.cgameUserCmdValue = userCmdValue; + cl.cgameUserHoldableValue = holdableValue; + cl.cgameSensitivity = sensitivityScale; + cl.cgameCld = cld; +} + +/* +============== +CL_AddCgameCommand +============== +*/ +void CL_AddCgameCommand( const char *cmdName ) { + Cmd_AddCommand( cmdName, NULL ); +} + +/* +============== +CL_CgameError +============== +*/ +void CL_CgameError( const char *string ) { + Com_Error( ERR_DROP, "%s", string ); +} + + +/* +===================== +CL_ConfigstringModified +===================== +*/ +void CL_ConfigstringModified( void ) { + char *old, *s; + int i, index; + char *dup; + gameState_t oldGs; + int len; + + index = atoi( Cmd_Argv( 1 ) ); + if ( index < 0 || index >= MAX_CONFIGSTRINGS ) { + Com_Error( ERR_DROP, "configstring > MAX_CONFIGSTRINGS" ); + } +// s = Cmd_Argv(2); + // get everything after "cs " + s = Cmd_ArgsFrom( 2 ); + + old = cl.gameState.stringData + cl.gameState.stringOffsets[ index ]; + if ( !strcmp( old, s ) ) { + return; // unchanged + } + + // build the new gameState_t + oldGs = cl.gameState; + + memset( &cl.gameState, 0, sizeof( cl.gameState ) ); + + // leave the first 0 for uninitialized strings + cl.gameState.dataCount = 1; + + for ( i = 0 ; i < MAX_CONFIGSTRINGS ; i++ ) { + if ( i == index ) { + dup = s; + } else { + dup = oldGs.stringData + oldGs.stringOffsets[ i ]; + } + if ( !dup[0] ) { + continue; // leave with the default empty string + } + + len = strlen( dup ); + + if ( len + 1 + cl.gameState.dataCount > MAX_GAMESTATE_CHARS ) { + Com_Error( ERR_DROP, "MAX_GAMESTATE_CHARS exceeded" ); + } + + // append it to the gameState string buffer + cl.gameState.stringOffsets[ i ] = cl.gameState.dataCount; + memcpy( cl.gameState.stringData + cl.gameState.dataCount, dup, len + 1 ); + cl.gameState.dataCount += len + 1; + } + + if ( index == CS_SYSTEMINFO ) { + // parse serverId and other cvars + CL_SystemInfoChanged(); + } + +} + + +/* +=================== +CL_GetServerCommand + +Set up argc/argv for the given command +=================== +*/ +qboolean CL_GetServerCommand( int serverCommandNumber ) { + char *s; + char *cmd; + static char bigConfigString[BIG_INFO_STRING]; + + // if we have irretrievably lost a reliable command, drop the connection + if ( serverCommandNumber <= clc.serverCommandSequence - MAX_RELIABLE_COMMANDS ) { + // when a demo record was started after the client got a whole bunch of + // reliable commands then the client never got those first reliable commands + if ( clc.demoplaying ) { + return qfalse; + } + Com_Error( ERR_DROP, "CL_GetServerCommand: a reliable command was cycled out" ); + return qfalse; + } + + if ( serverCommandNumber > clc.serverCommandSequence ) { + Com_Error( ERR_DROP, "CL_GetServerCommand: requested a command not received" ); + return qfalse; + } + + s = clc.serverCommands[ serverCommandNumber & ( MAX_RELIABLE_COMMANDS - 1 ) ]; + clc.lastExecutedServerCommand = serverCommandNumber; + + Com_DPrintf( "serverCommand: %i : %s\n", serverCommandNumber, s ); + +rescan: + Cmd_TokenizeString( s ); + cmd = Cmd_Argv( 0 ); + + if ( !strcmp( cmd, "disconnect" ) ) { + Com_Error( ERR_SERVERDISCONNECT,"Server disconnected\n" ); + } + + if ( !strcmp( cmd, "bcs0" ) ) { + Com_sprintf( bigConfigString, BIG_INFO_STRING, "cs %s \"%s", Cmd_Argv( 1 ), Cmd_Argv( 2 ) ); + return qfalse; + } + + if ( !strcmp( cmd, "bcs1" ) ) { + s = Cmd_Argv( 2 ); + if ( strlen( bigConfigString ) + strlen( s ) >= BIG_INFO_STRING ) { + Com_Error( ERR_DROP, "bcs exceeded BIG_INFO_STRING" ); + } + strcat( bigConfigString, s ); + return qfalse; + } + + if ( !strcmp( cmd, "bcs2" ) ) { + s = Cmd_Argv( 2 ); + if ( strlen( bigConfigString ) + strlen( s ) + 1 >= BIG_INFO_STRING ) { + Com_Error( ERR_DROP, "bcs exceeded BIG_INFO_STRING" ); + } + strcat( bigConfigString, s ); + strcat( bigConfigString, "\"" ); + s = bigConfigString; + goto rescan; + } + + if ( !strcmp( cmd, "cs" ) ) { + CL_ConfigstringModified(); + // reparse the string, because CL_ConfigstringModified may have done another Cmd_TokenizeString() + Cmd_TokenizeString( s ); + return qtrue; + } + + if ( !strcmp( cmd, "map_restart" ) ) { + // clear notify lines and outgoing commands before passing + // the restart to the cgame + Con_ClearNotify(); + memset( cl.cmds, 0, sizeof( cl.cmds ) ); + return qtrue; + } + + if ( !strcmp( cmd, "popup" ) ) { // direct server to client popup request, bypassing cgame +// trap_UI_Popup(Cmd_Argv(1)); +// if ( cls.state == CA_ACTIVE && !clc.demoplaying ) { +// VM_Call( uivm, UI_SET_ACTIVE_MENU, UIMENU_CLIPBOARD); +// Menus_OpenByName(Cmd_Argv(1)); +// } + return qfalse; + } + + + // the clientLevelShot command is used during development + // to generate 128*128 screenshots from the intermission + // point of levels for the menu system to use + // we pass it along to the cgame to make apropriate adjustments, + // but we also clear the console and notify lines here + if ( !strcmp( cmd, "clientLevelShot" ) ) { + // don't do it if we aren't running the server locally, + // otherwise malicious remote servers could overwrite + // the existing thumbnails + if ( !com_sv_running->integer ) { + return qfalse; + } + // close the console + Con_Close(); + // take a special screenshot next frame + Cbuf_AddText( "wait ; wait ; wait ; wait ; screenshot levelshot\n" ); + return qtrue; + } + + // we may want to put a "connect to other server" command here + + // cgame can now act on the command + return qtrue; +} + + +/* +==================== +CL_CM_LoadMap + +Just adds default parameters that cgame doesn't need to know about +==================== +*/ +void CL_CM_LoadMap( const char *mapname ) { + int checksum; + + CM_LoadMap( mapname, qtrue, &checksum ); +} + +/* +==================== +CL_ShutdonwCGame + +==================== +*/ +void CL_ShutdownCGame( void ) { + cls.keyCatchers &= ~KEYCATCH_CGAME; + cls.cgameStarted = qfalse; + if ( !cgvm ) { + return; + } + VM_Call( cgvm, CG_SHUTDOWN ); + VM_Free( cgvm ); + cgvm = NULL; +} + +static int FloatAsInt( float f ) { + int temp; + + *(float *)&temp = f; + + return temp; +} + +/* +==================== +CL_CgameSystemCalls + +The cgame module is making a system call +==================== +*/ +#define VMA( x ) VM_ArgPtr( args[x] ) +#define VMF( x ) ( (float *)args )[x] +int CL_CgameSystemCalls( int *args ) { + switch ( args[0] ) { + case CG_PRINT: + Com_Printf( "%s", VMA( 1 ) ); + return 0; + case CG_ERROR: + Com_Error( ERR_DROP, "%s", VMA( 1 ) ); + return 0; + case CG_MILLISECONDS: + return Sys_Milliseconds(); + case CG_CVAR_REGISTER: + Cvar_Register( VMA( 1 ), VMA( 2 ), VMA( 3 ), args[4] ); + return 0; + case CG_CVAR_UPDATE: + Cvar_Update( VMA( 1 ) ); + return 0; + case CG_CVAR_SET: + Cvar_Set( VMA( 1 ), VMA( 2 ) ); + return 0; + case CG_CVAR_VARIABLESTRINGBUFFER: + Cvar_VariableStringBuffer( VMA( 1 ), VMA( 2 ), args[3] ); + return 0; + case CG_ARGC: + return Cmd_Argc(); + case CG_ARGV: + Cmd_ArgvBuffer( args[1], VMA( 2 ), args[3] ); + return 0; + case CG_ARGS: + Cmd_ArgsBuffer( VMA( 1 ), args[2] ); + return 0; + case CG_FS_FOPENFILE: + return FS_FOpenFileByMode( VMA( 1 ), VMA( 2 ), args[3] ); + case CG_FS_READ: + FS_Read( VMA( 1 ), args[2], args[3] ); + return 0; + case CG_FS_WRITE: + return FS_Write( VMA( 1 ), args[2], args[3] ); + case CG_FS_FCLOSEFILE: + FS_FCloseFile( args[1] ); + return 0; + case CG_SENDCONSOLECOMMAND: + Cbuf_AddText( VMA( 1 ) ); + return 0; + case CG_ADDCOMMAND: + CL_AddCgameCommand( VMA( 1 ) ); + return 0; + case CG_REMOVECOMMAND: + Cmd_RemoveCommand( VMA( 1 ) ); + return 0; + case CG_SENDCLIENTCOMMAND: + CL_AddReliableCommand( VMA( 1 ) ); + return 0; + case CG_UPDATESCREEN: + // this is used during lengthy level loading, so pump message loop +// Com_EventLoop(); // FIXME: if a server restarts here, BAD THINGS HAPPEN! +// We can't call Com_EventLoop here, a restart will crash and this _does_ happen +// if there is a map change while we are downloading at pk3. +// ZOID + SCR_UpdateScreen(); + return 0; + case CG_CM_LOADMAP: + CL_CM_LoadMap( VMA( 1 ) ); + return 0; + case CG_CM_NUMINLINEMODELS: + return CM_NumInlineModels(); + case CG_CM_INLINEMODEL: + return CM_InlineModel( args[1] ); + case CG_CM_TEMPBOXMODEL: + return CM_TempBoxModel( VMA( 1 ), VMA( 2 ), qfalse ); + case CG_CM_TEMPCAPSULEMODEL: + return CM_TempBoxModel( VMA( 1 ), VMA( 2 ), qtrue ); + case CG_CM_POINTCONTENTS: + return CM_PointContents( VMA( 1 ), args[2] ); + case CG_CM_TRANSFORMEDPOINTCONTENTS: + return CM_TransformedPointContents( VMA( 1 ), args[2], VMA( 3 ), VMA( 4 ) ); + case CG_CM_BOXTRACE: + CM_BoxTrace( VMA( 1 ), VMA( 2 ), VMA( 3 ), VMA( 4 ), VMA( 5 ), args[6], args[7], /*int capsule*/ qfalse ); + return 0; + case CG_CM_TRANSFORMEDBOXTRACE: + CM_TransformedBoxTrace( VMA( 1 ), VMA( 2 ), VMA( 3 ), VMA( 4 ), VMA( 5 ), args[6], args[7], VMA( 8 ), VMA( 9 ), /*int capsule*/ qfalse ); + return 0; + case CG_CM_CAPSULETRACE: + CM_BoxTrace( VMA( 1 ), VMA( 2 ), VMA( 3 ), VMA( 4 ), VMA( 5 ), args[6], args[7], /*int capsule*/ qtrue ); + return 0; + case CG_CM_TRANSFORMEDCAPSULETRACE: + CM_TransformedBoxTrace( VMA( 1 ), VMA( 2 ), VMA( 3 ), VMA( 4 ), VMA( 5 ), args[6], args[7], VMA( 8 ), VMA( 9 ), /*int capsule*/ qtrue ); + return 0; + case CG_CM_MARKFRAGMENTS: + return re.MarkFragments( args[1], VMA( 2 ), VMA( 3 ), args[4], VMA( 5 ), args[6], VMA( 7 ) ); + case CG_S_STARTSOUND: + S_StartSound( VMA( 1 ), args[2], args[3], args[4] ); + return 0; +//----(SA) added + case CG_S_STARTSOUNDEX: + S_StartSoundEx( VMA( 1 ), args[2], args[3], args[4], args[5] ); + return 0; +//----(SA) end + case CG_S_STARTLOCALSOUND: + S_StartLocalSound( args[1], args[2] ); + return 0; + case CG_S_CLEARLOOPINGSOUNDS: + S_ClearLoopingSounds(); // (SA) modified so no_pvs sounds can function + // RF, if killall, then stop all sounds + if ( args[1] == 1 ) { + S_ClearSounds( qtrue, qfalse ); + } else if ( args[1] == 2 ) { + S_ClearSounds( qtrue, qtrue ); + } + return 0; + case CG_S_ADDLOOPINGSOUND: + // FIXME MrE: handling of looping sounds changed + S_AddLoopingSound( args[1], VMA( 2 ), VMA( 3 ), args[4], args[5], args[6] ); + return 0; +// not in use +// case CG_S_ADDREALLOOPINGSOUND: +// S_AddLoopingSound( args[1], VMA(2), VMA(3), args[4], args[5], args[6] ); +// //S_AddRealLoopingSound( args[1], VMA(2), VMA(3), args[4], args[5] ); +// return 0; + +//----(SA) added + case CG_S_STOPSTREAMINGSOUND: + S_StopEntStreamingSound( args[1] ); + return 0; +//----(SA) end + + case CG_S_STOPLOOPINGSOUND: + // RF, not functional anymore, since we reverted to old looping code + //S_StopLoopingSound( args[1] ); + return 0; + case CG_S_UPDATEENTITYPOSITION: + S_UpdateEntityPosition( args[1], VMA( 2 ) ); + return 0; +// Ridah, talking animations + case CG_S_GETVOICEAMPLITUDE: + return S_GetVoiceAmplitude( args[1] ); +// done. + case CG_S_RESPATIALIZE: + S_Respatialize( args[1], VMA( 2 ), VMA( 3 ), args[4] ); + return 0; + case CG_S_REGISTERSOUND: +#ifdef DOOMSOUND ///// (SA) DOOMSOUND + return S_RegisterSound( VMA( 1 ) ); +#else + return S_RegisterSound( VMA( 1 ), qfalse ); +#endif ///// (SA) DOOMSOUND + case CG_S_STARTBACKGROUNDTRACK: + S_StartBackgroundTrack( VMA( 1 ), VMA( 2 ), args[3] ); //----(SA) added fadeup time + return 0; + case CG_S_FADESTREAMINGSOUND: + S_FadeStreamingSound( VMF( 1 ), args[2], args[3] ); //----(SA) added music/all-streaming options + return 0; + case CG_S_STARTSTREAMINGSOUND: + S_StartStreamingSound( VMA( 1 ), VMA( 2 ), args[3], args[4], args[5] ); + return 0; + case CG_S_FADEALLSOUNDS: + S_FadeAllSounds( VMF( 1 ), args[2] ); //----(SA) added + return 0; + case CG_R_LOADWORLDMAP: + re.LoadWorld( VMA( 1 ) ); + return 0; + case CG_R_REGISTERMODEL: + return re.RegisterModel( VMA( 1 ) ); + case CG_R_REGISTERSKIN: + return re.RegisterSkin( VMA( 1 ) ); + + //----(SA) added + case CG_R_GETSKINMODEL: + return re.GetSkinModel( args[1], VMA( 2 ), VMA( 3 ) ); + case CG_R_GETMODELSHADER: + return re.GetShaderFromModel( args[1], args[2], args[3] ); + //----(SA) end + + case CG_R_REGISTERSHADER: + return re.RegisterShader( VMA( 1 ) ); + case CG_R_REGISTERFONT: + re.RegisterFont( VMA( 1 ), args[2], VMA( 3 ) ); + case CG_R_REGISTERSHADERNOMIP: + return re.RegisterShaderNoMip( VMA( 1 ) ); + case CG_R_CLEARSCENE: + re.ClearScene(); + return 0; + case CG_R_ADDREFENTITYTOSCENE: + re.AddRefEntityToScene( VMA( 1 ) ); + return 0; + case CG_R_ADDPOLYTOSCENE: + re.AddPolyToScene( args[1], args[2], VMA( 3 ) ); + return 0; + // Ridah + case CG_R_ADDPOLYSTOSCENE: + re.AddPolysToScene( args[1], args[2], VMA( 3 ), args[4] ); + return 0; + case CG_RB_ZOMBIEFXADDNEWHIT: + re.ZombieFXAddNewHit( args[1], VMA( 2 ), VMA( 3 ) ); + return 0; + // done. +// case CG_R_LIGHTFORPOINT: +// return re.LightForPoint( VMA(1), VMA(2), VMA(3), VMA(4) ); + case CG_R_ADDLIGHTTOSCENE: + re.AddLightToScene( VMA( 1 ), VMF( 2 ), VMF( 3 ), VMF( 4 ), VMF( 5 ), args[6] ); + return 0; +// case CG_R_ADDADDITIVELIGHTTOSCENE: +// re.AddAdditiveLightToScene( VMA(1), VMF(2), VMF(3), VMF(4), VMF(5) ); +// return 0; + case CG_R_ADDCORONATOSCENE: + re.AddCoronaToScene( VMA( 1 ), VMF( 2 ), VMF( 3 ), VMF( 4 ), VMF( 5 ), args[6], args[7] ); + return 0; + case CG_R_SETFOG: + re.SetFog( args[1], args[2], args[3], VMF( 4 ), VMF( 5 ), VMF( 6 ), VMF( 7 ) ); + return 0; + case CG_R_RENDERSCENE: + re.RenderScene( VMA( 1 ) ); + return 0; + case CG_R_SETCOLOR: + re.SetColor( VMA( 1 ) ); + return 0; + case CG_R_DRAWSTRETCHPIC: + re.DrawStretchPic( VMF( 1 ), VMF( 2 ), VMF( 3 ), VMF( 4 ), VMF( 5 ), VMF( 6 ), VMF( 7 ), VMF( 8 ), args[9] ); + return 0; + case CG_R_DRAWSTRETCHPIC_GRADIENT: + re.DrawStretchPicGradient( VMF( 1 ), VMF( 2 ), VMF( 3 ), VMF( 4 ), VMF( 5 ), VMF( 6 ), VMF( 7 ), VMF( 8 ), args[9], VMA( 10 ), args[11] ); + return 0; + case CG_R_MODELBOUNDS: + re.ModelBounds( args[1], VMA( 2 ), VMA( 3 ) ); + return 0; + case CG_R_LERPTAG: + return re.LerpTag( VMA( 1 ), VMA( 2 ), VMA( 3 ), args[4] ); + case CG_GETGLCONFIG: + CL_GetGlconfig( VMA( 1 ) ); + return 0; + case CG_GETGAMESTATE: + CL_GetGameState( VMA( 1 ) ); + return 0; + case CG_GETCURRENTSNAPSHOTNUMBER: + CL_GetCurrentSnapshotNumber( VMA( 1 ), VMA( 2 ) ); + return 0; + case CG_GETSNAPSHOT: + return CL_GetSnapshot( args[1], VMA( 2 ) ); + case CG_GETSERVERCOMMAND: + return CL_GetServerCommand( args[1] ); + case CG_GETCURRENTCMDNUMBER: + return CL_GetCurrentCmdNumber(); + case CG_GETUSERCMD: + return CL_GetUserCmd( args[1], VMA( 2 ) ); + case CG_SETUSERCMDVALUE: + #ifdef AUTOAIM + CL_SetUserCmdValue( args[1], args[2], VMF( 3 ), args[4], args[5], args[6] ); //----(SA) modified // NERVE - SMF - added fourth arg [cld], *SEB* added 5 (lastfire) and 6 (crosshairstat) + #else + CL_SetUserCmdValue( args[1], args[2], VMF( 3 ), args[4] ); //----(SA) modified // NERVE - SMF - added fourth arg [cld] + #endif + return 0; + case CG_MEMORY_REMAINING: + return Hunk_MemoryRemaining(); + case CG_KEY_ISDOWN: + return Key_IsDown( args[1] ); + case CG_KEY_GETCATCHER: + return Key_GetCatcher(); + case CG_KEY_SETCATCHER: + Key_SetCatcher( args[1] ); + return 0; + case CG_KEY_GETKEY: + return Key_GetKey( VMA( 1 ) ); + + + + case CG_MEMSET: + return (int)memset( VMA( 1 ), args[2], args[3] ); + case CG_MEMCPY: + return (int)memcpy( VMA( 1 ), VMA( 2 ), args[3] ); + case CG_STRNCPY: + return (int)strncpy( VMA( 1 ), VMA( 2 ), args[3] ); + case CG_SIN: + return FloatAsInt( sin( VMF( 1 ) ) ); + case CG_COS: + return FloatAsInt( cos( VMF( 1 ) ) ); + case CG_ATAN2: + return FloatAsInt( atan2( VMF( 1 ), VMF( 2 ) ) ); + case CG_SQRT: + return FloatAsInt( sqrt( VMF( 1 ) ) ); + case CG_FLOOR: + return FloatAsInt( floor( VMF( 1 ) ) ); + case CG_CEIL: + return FloatAsInt( ceil( VMF( 1 ) ) ); + case CG_ACOS: + return FloatAsInt( Q_acos( VMF( 1 ) ) ); + + case CG_PC_ADD_GLOBAL_DEFINE: + return botlib_export->PC_AddGlobalDefine( VMA( 1 ) ); + case CG_PC_LOAD_SOURCE: + return botlib_export->PC_LoadSourceHandle( VMA( 1 ) ); + case CG_PC_FREE_SOURCE: + return botlib_export->PC_FreeSourceHandle( args[1] ); + case CG_PC_READ_TOKEN: + return botlib_export->PC_ReadTokenHandle( args[1], VMA( 2 ) ); + case CG_PC_SOURCE_FILE_AND_LINE: + return botlib_export->PC_SourceFileAndLine( args[1], VMA( 2 ), VMA( 3 ) ); + + case CG_S_STOPBACKGROUNDTRACK: + S_StopBackgroundTrack(); + return 0; + + case CG_REAL_TIME: + return Com_RealTime( VMA( 1 ) ); + case CG_SNAPVECTOR: + Sys_SnapVector( VMA( 1 ) ); + return 0; + + case CG_SENDMOVESPEEDSTOGAME: + SV_SendMoveSpeedsToGame( args[1], VMA( 2 ) ); + return 0; + + case CG_CIN_PLAYCINEMATIC: + return CIN_PlayCinematic( VMA( 1 ), args[2], args[3], args[4], args[5], args[6] ); + + case CG_CIN_STOPCINEMATIC: + return CIN_StopCinematic( args[1] ); + + case CG_CIN_RUNCINEMATIC: + return CIN_RunCinematic( args[1] ); + + case CG_CIN_DRAWCINEMATIC: + CIN_DrawCinematic( args[1] ); + return 0; + + case CG_CIN_SETEXTENTS: + CIN_SetExtents( args[1], args[2], args[3], args[4], args[5] ); + return 0; + + case CG_R_REMAP_SHADER: + re.RemapShader( VMA( 1 ), VMA( 2 ), VMA( 3 ) ); + return 0; + + case CG_TESTPRINTINT: + Com_Printf( "%s%i\n", VMA( 1 ), args[2] ); + return 0; + case CG_TESTPRINTFLOAT: + Com_Printf( "%s%f\n", VMA( 1 ), VMF( 2 ) ); + return 0; + + case CG_LOADCAMERA: + return loadCamera( args[1], VMA( 2 ) ); + + case CG_STARTCAMERA: + if ( args[1] == 0 ) { // CAM_PRIMARY + cl.cameraMode = qtrue; //----(SA) added + } + startCamera( args[1], args[2] ); + return 0; + +//----(SA) added + case CG_STOPCAMERA: + if ( args[1] == 0 ) { // CAM_PRIMARY + cl.cameraMode = qfalse; + } +// stopCamera(args[1]); + return 0; +//----(SA) end + + case CG_GETCAMERAINFO: + return getCameraInfo( args[1], args[2], VMA( 3 ), VMA( 4 ), VMA( 5 ) ); + + case CG_GET_ENTITY_TOKEN: + return re.GetEntityToken( VMA( 1 ), args[2] ); + + case CG_INGAME_POPUP: + if ( VMA( 1 ) && !Q_stricmp( VMA( 1 ), "briefing" ) ) { //----(SA) added + VM_Call( uivm, UI_SET_ACTIVE_MENU, UIMENU_BRIEFING ); + return 0; + } + + if ( cls.state == CA_ACTIVE && !clc.demoplaying ) { + // NERVE - SMF + if ( VMA( 1 ) && !Q_stricmp( VMA( 1 ), "UIMENU_WM_PICKTEAM" ) ) { + VM_Call( uivm, UI_SET_ACTIVE_MENU, UIMENU_WM_PICKTEAM ); + } else if ( VMA( 1 ) && !Q_stricmp( VMA( 1 ), "UIMENU_WM_PICKPLAYER" ) ) { + VM_Call( uivm, UI_SET_ACTIVE_MENU, UIMENU_WM_PICKPLAYER ); + } else if ( VMA( 1 ) && !Q_stricmp( VMA( 1 ), "UIMENU_WM_QUICKMESSAGE" ) ) { + VM_Call( uivm, UI_SET_ACTIVE_MENU, UIMENU_WM_QUICKMESSAGE ); + } else if ( VMA( 1 ) && !Q_stricmp( VMA( 1 ), "UIMENU_WM_LIMBO" ) ) { + VM_Call( uivm, UI_SET_ACTIVE_MENU, UIMENU_WM_LIMBO ); + } + // -NERVE - SMF + else if ( VMA( 1 ) && !Q_stricmp( VMA( 1 ), "hbook1" ) ) { //----(SA) + VM_Call( uivm, UI_SET_ACTIVE_MENU, UIMENU_BOOK1 ); + } else if ( VMA( 1 ) && !Q_stricmp( VMA( 1 ), "hbook2" ) ) { //----(SA) + VM_Call( uivm, UI_SET_ACTIVE_MENU, UIMENU_BOOK2 ); + } else if ( VMA( 1 ) && !Q_stricmp( VMA( 1 ), "hbook3" ) ) { //----(SA) + VM_Call( uivm, UI_SET_ACTIVE_MENU, UIMENU_BOOK3 ); + } else if ( VMA( 1 ) && !Q_stricmp( VMA( 1 ), "pregame" ) ) { //----(SA) added + VM_Call( uivm, UI_SET_ACTIVE_MENU, UIMENU_PREGAME ); + } else { + VM_Call( uivm, UI_SET_ACTIVE_MENU, UIMENU_CLIPBOARD ); + } + } + return 0; + + // NERVE - SMF + case CG_INGAME_CLOSEPOPUP: + VM_Call( uivm, UI_KEY_EVENT, K_ESCAPE, qtrue ); + return 0; + + case CG_LIMBOCHAT: + if ( VMA( 1 ) ) { + CL_AddToLimboChat( VMA( 1 ) ); + } + return 0; + // - NERVE - SMF + + case CG_GETMODELINFO: + return SV_GetModelInfo( args[1], VMA( 2 ), VMA( 3 ) ); + + default: + Com_Error( ERR_DROP, "Bad cgame system trap: %i", args[0] ); + } + return 0; +} + +/* +==================== +CL_UpdateLevelHunkUsage + + This updates the "hunkusage.dat" file with the current map and it's hunk usage count + + This is used for level loading, so we can show a percentage bar dependant on the amount + of hunk memory allocated so far + + This will be slightly inaccurate if some settings like sound quality are changed, but these + things should only account for a small variation (hopefully) +==================== +*/ +void CL_UpdateLevelHunkUsage( void ) { + int handle; + char *memlistfile = "hunkusage.dat"; + char *buf, *outbuf; + char *buftrav, *outbuftrav; + char *token; + char outstr[256]; + int len, memusage; + + memusage = Cvar_VariableIntegerValue( "com_hunkused" ) + Cvar_VariableIntegerValue( "hunk_soundadjust" ); + + len = FS_FOpenFileByMode( memlistfile, &handle, FS_READ ); + if ( len >= 0 ) { // the file exists, so read it in, strip out the current entry for this map, and save it out, so we can append the new value + + buf = (char *)Z_Malloc( len + 1 ); + memset( buf, 0, len + 1 ); + outbuf = (char *)Z_Malloc( len + 1 ); + memset( outbuf, 0, len + 1 ); + + FS_Read( (void *)buf, len, handle ); + FS_FCloseFile( handle ); + + // now parse the file, filtering out the current map + buftrav = buf; + outbuftrav = outbuf; + outbuftrav[0] = '\0'; + while ( ( token = COM_Parse( &buftrav ) ) && token[0] ) { + if ( !Q_strcasecmp( token, cl.mapname ) ) { + // found a match + token = COM_Parse( &buftrav ); // read the size + if ( token && token[0] ) { + if ( atoi( token ) == memusage ) { // if it is the same, abort this process + Z_Free( buf ); + Z_Free( outbuf ); + return; + } + } + } else { // send it to the outbuf + Q_strcat( outbuftrav, len + 1, token ); + Q_strcat( outbuftrav, len + 1, " " ); + token = COM_Parse( &buftrav ); // read the size + if ( token && token[0] ) { + Q_strcat( outbuftrav, len + 1, token ); + Q_strcat( outbuftrav, len + 1, "\n" ); + } else { + Com_Error( ERR_DROP, "hunkusage.dat file is corrupt\n" ); + } + } + } + +#ifdef __MACOS__ //DAJ MacOS file typing + { + extern _MSL_IMP_EXP_C long _fcreator, _ftype; + _ftype = 'WlfB'; + _fcreator = 'WlfS'; + } +#endif + handle = FS_FOpenFileWrite( memlistfile ); + if ( handle < 0 ) { + Com_Error( ERR_DROP, "cannot create %s\n", memlistfile ); + } + // input file is parsed, now output to the new file + len = strlen( outbuf ); + if ( FS_Write( (void *)outbuf, len, handle ) != len ) { + Com_Error( ERR_DROP, "cannot write to %s\n", memlistfile ); + } + FS_FCloseFile( handle ); + + Z_Free( buf ); + Z_Free( outbuf ); + } + // now append the current map to the current file + FS_FOpenFileByMode( memlistfile, &handle, FS_APPEND ); + if ( handle < 0 ) { + Com_Error( ERR_DROP, "cannot write to hunkusage.dat, check disk full\n" ); + } + Com_sprintf( outstr, sizeof( outstr ), "%s %i\n", cl.mapname, memusage ); + FS_Write( outstr, strlen( outstr ), handle ); + FS_FCloseFile( handle ); + + // now just open it and close it, so it gets copied to the pak dir + len = FS_FOpenFileByMode( memlistfile, &handle, FS_READ ); + if ( len >= 0 ) { + FS_FCloseFile( handle ); + } +} + +/* +==================== +CL_InitCGame + +Should only by called by CL_StartHunkUsers +==================== +*/ +void CL_InitCGame( void ) { + const char *info; + const char *mapname; + int t1, t2; + vmInterpret_t interpret; + + t1 = Sys_Milliseconds(); + + // put away the console + Con_Close(); + + // find the current mapname + info = cl.gameState.stringData + cl.gameState.stringOffsets[ CS_SERVERINFO ]; + mapname = Info_ValueForKey( info, "mapname" ); + Com_sprintf( cl.mapname, sizeof( cl.mapname ), "maps/%s.bsp", mapname ); + + // load the dll or bytecode + if ( cl_connectedToPureServer != 0 ) { + // if sv_pure is set we only allow qvms to be loaded + interpret = VMI_COMPILED; + } else { + interpret = Cvar_VariableValue( "vm_cgame" ); + } + cgvm = VM_Create( "cgame", CL_CgameSystemCalls, interpret ); +// cgvm = VM_Create( "cgame", CL_CgameSystemCalls, Cvar_VariableValue( "vm_cgame" ) ); + if ( !cgvm ) { + Com_Error( ERR_DROP, "VM_Create on cgame failed" ); + } + cls.state = CA_LOADING; + + // init for this gamestate + // use the lastExecutedServerCommand instead of the serverCommandSequence + // otherwise server commands sent just before a gamestate are dropped + VM_Call( cgvm, CG_INIT, clc.serverMessageSequence, clc.lastExecutedServerCommand, clc.clientNum ); +// VM_Call( cgvm, CG_INIT, clc.serverMessageSequence, clc.serverCommandSequence ); + + // we will send a usercmd this frame, which + // will cause the server to send us the first snapshot + cls.state = CA_PRIMED; + + t2 = Sys_Milliseconds(); + + Com_Printf( "CL_InitCGame: %5.2f seconds\n", ( t2 - t1 ) / 1000.0 ); + + // have the renderer touch all its images, so they are present + // on the card even if the driver does deferred loading + re.EndRegistration(); + + // make sure everything is paged in + if ( !Sys_LowPhysicalMemory() ) { + Com_TouchMemory(); + } + + // clear anything that got printed + Con_ClearNotify(); + + // Ridah, update the memory usage file + CL_UpdateLevelHunkUsage(); +} + + +/* +==================== +CL_GameCommand + +See if the current console command is claimed by the cgame +==================== +*/ +qboolean CL_GameCommand( void ) { + if ( !cgvm ) { + return qfalse; + } + + return VM_Call( cgvm, CG_CONSOLE_COMMAND ); +} + + + +/* +===================== +CL_CGameRendering +===================== +*/ +void CL_CGameRendering( stereoFrame_t stereo ) { + VM_Call( cgvm, CG_DRAW_ACTIVE_FRAME, cl.serverTime, stereo, clc.demoplaying ); + VM_Debug( 0 ); +} + + +/* +================= +CL_AdjustTimeDelta + +Adjust the clients view of server time. + +We attempt to have cl.serverTime exactly equal the server's view +of time plus the timeNudge, but with variable latencies over +the internet it will often need to drift a bit to match conditions. + +Our ideal time would be to have the adjusted time approach, but not pass, +the very latest snapshot. + +Adjustments are only made when a new snapshot arrives with a rational +latency, which keeps the adjustment process framerate independent and +prevents massive overadjustment during times of significant packet loss +or bursted delayed packets. +================= +*/ + +#define RESET_TIME 500 + +void CL_AdjustTimeDelta( void ) { + int resetTime; + int newDelta; + int deltaDelta; + + cl.newSnapshots = qfalse; + + // the delta never drifts when replaying a demo + if ( clc.demoplaying ) { + return; + } + + // if the current time is WAY off, just correct to the current value + if ( com_sv_running->integer ) { + resetTime = 100; + } else { + resetTime = RESET_TIME; + } + + newDelta = cl.snap.serverTime - cls.realtime; + deltaDelta = abs( newDelta - cl.serverTimeDelta ); + + if ( deltaDelta > RESET_TIME ) { + cl.serverTimeDelta = newDelta; + cl.oldServerTime = cl.snap.serverTime; // FIXME: is this a problem for cgame? + cl.serverTime = cl.snap.serverTime; + if ( cl_showTimeDelta->integer ) { + Com_Printf( " " ); + } + } else if ( deltaDelta > 100 ) { + // fast adjust, cut the difference in half + if ( cl_showTimeDelta->integer ) { + Com_Printf( " " ); + } + cl.serverTimeDelta = ( cl.serverTimeDelta + newDelta ) >> 1; + } else { + // slow drift adjust, only move 1 or 2 msec + + // if any of the frames between this and the previous snapshot + // had to be extrapolated, nudge our sense of time back a little + // the granularity of +1 / -2 is too high for timescale modified frametimes + if ( com_timescale->value == 0 || com_timescale->value == 1 ) { + if ( cl.extrapolatedSnapshot ) { + cl.extrapolatedSnapshot = qfalse; + cl.serverTimeDelta -= 2; + } else { + // otherwise, move our sense of time forward to minimize total latency + cl.serverTimeDelta++; + } + } + } + + if ( cl_showTimeDelta->integer ) { + Com_Printf( "%i ", cl.serverTimeDelta ); + } +} + + +/* +================== +CL_FirstSnapshot +================== +*/ +void CL_FirstSnapshot( void ) { + // ignore snapshots that don't have entities + if ( cl.snap.snapFlags & SNAPFLAG_NOT_ACTIVE ) { + return; + } + cls.state = CA_ACTIVE; + + // set the timedelta so we are exactly on this first frame + cl.serverTimeDelta = cl.snap.serverTime - cls.realtime; + cl.oldServerTime = cl.snap.serverTime; + + clc.timeDemoBaseTime = cl.snap.serverTime; + + // if this is the first frame of active play, + // execute the contents of activeAction now + // this is to allow scripting a timedemo to start right + // after loading + if ( cl_activeAction->string[0] ) { + Cbuf_AddText( cl_activeAction->string ); + Cvar_Set( "activeAction", "" ); + } + + Sys_BeginProfiling(); +} + +/* +================== +CL_SetCGameTime +================== +*/ +void CL_SetCGameTime( void ) { + // getting a valid frame message ends the connection process + if ( cls.state != CA_ACTIVE ) { + if ( cls.state != CA_PRIMED ) { + return; + } + if ( clc.demoplaying ) { + // we shouldn't get the first snapshot on the same frame + // as the gamestate, because it causes a bad time skip + if ( !clc.firstDemoFrameSkipped ) { + clc.firstDemoFrameSkipped = qtrue; + return; + } + CL_ReadDemoMessage(); + } + if ( cl.newSnapshots ) { + cl.newSnapshots = qfalse; + CL_FirstSnapshot(); + } + if ( cls.state != CA_ACTIVE ) { + return; + } + } + + // if we have gotten to this point, cl.snap is guaranteed to be valid + if ( !cl.snap.valid ) { + Com_Error( ERR_DROP, "CL_SetCGameTime: !cl.snap.valid" ); + } + + // allow pause in single player + if ( sv_paused->integer && cl_paused->integer && com_sv_running->integer ) { + // paused + return; + } + + if ( cl.snap.serverTime < cl.oldFrameServerTime ) { + // Ridah, if this is a localhost, then we are probably loading a savegame + if ( !Q_stricmp( cls.servername, "localhost" ) ) { + // do nothing? + CL_FirstSnapshot(); + } else { + Com_Error( ERR_DROP, "cl.snap.serverTime < cl.oldFrameServerTime" ); + } + } + cl.oldFrameServerTime = cl.snap.serverTime; + + + // get our current view of time + + if ( clc.demoplaying && cl_freezeDemo->integer ) { + // cl_freezeDemo is used to lock a demo in place for single frame advances + + } else { + // cl_timeNudge is a user adjustable cvar that allows more + // or less latency to be added in the interest of better + // smoothness or better responsiveness. + int tn; + + tn = cl_timeNudge->integer; + if ( tn < -30 ) { + tn = -30; + } else if ( tn > 30 ) { + tn = 30; + } + + cl.serverTime = cls.realtime + cl.serverTimeDelta - tn; + + // guarantee that time will never flow backwards, even if + // serverTimeDelta made an adjustment or cl_timeNudge was changed + if ( cl.serverTime < cl.oldServerTime ) { + cl.serverTime = cl.oldServerTime; + } + cl.oldServerTime = cl.serverTime; + + // note if we are almost past the latest frame (without timeNudge), + // so we will try and adjust back a bit when the next snapshot arrives + if ( cls.realtime + cl.serverTimeDelta >= cl.snap.serverTime - 5 ) { + cl.extrapolatedSnapshot = qtrue; + } + } + + // if we have gotten new snapshots, drift serverTimeDelta + // don't do this every frame, or a period of packet loss would + // make a huge adjustment + if ( cl.newSnapshots ) { + CL_AdjustTimeDelta(); + } + + if ( !clc.demoplaying ) { + return; + } + + // if we are playing a demo back, we can just keep reading + // messages from the demo file until the cgame definately + // has valid snapshots to interpolate between + + // a timedemo will always use a deterministic set of time samples + // no matter what speed machine it is run on, + // while a normal demo may have different time samples + // each time it is played back + if ( cl_timedemo->integer ) { + if ( !clc.timeDemoStart ) { + clc.timeDemoStart = Sys_Milliseconds(); + } + clc.timeDemoFrames++; + cl.serverTime = clc.timeDemoBaseTime + clc.timeDemoFrames * 50; + } + + while ( cl.serverTime >= cl.snap.serverTime ) { + // feed another messag, which should change + // the contents of cl.snap + CL_ReadDemoMessage(); + if ( cls.state != CA_ACTIVE ) { + return; // end of demo + } + } + +} + +/* +==================== +CL_GetTag +==================== +*/ +qboolean CL_GetTag( int clientNum, char *tagname, orientation_t *or ) { + if ( !cgvm ) { + return qfalse; + } + + return VM_Call( cgvm, CG_GET_TAG, clientNum, tagname, or ); +} diff --git a/Projects/Android/jni/rtcw/src/client/cl_cin.c b/Projects/Android/jni/rtcw/src/client/cl_cin.c new file mode 100644 index 0000000..1a768d0 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/client/cl_cin.c @@ -0,0 +1,1925 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +/***************************************************************************** + * name: cl_cin.c + * + * desc: video and cinematic playback + * + * + * cl_glconfig.hwtype trtypes 3dfx/ragepro need 256x256 + * + *****************************************************************************/ + +//#define ADAPTED_TO_STREAMING_SOUND +// (SA) MISSIONPACK MERGE +// s_rawend for wolf is [] and for q3 is just a single value +// I need to ask Ryan if it's as simple as a constant index or +// if some more coding needs to be done. + + +#include "client.h" +//#include "snd_local.h" + +#define MAXSIZE 8 +#define MINSIZE 4 + +#define DEFAULT_CIN_WIDTH 512 +#define DEFAULT_CIN_HEIGHT 512 + +#define LETTERBOX_OFFSET 105 + + +#define ROQ_QUAD 0x1000 +#define ROQ_QUAD_INFO 0x1001 +#define ROQ_CODEBOOK 0x1002 +#define ROQ_QUAD_VQ 0x1011 +#define ROQ_QUAD_JPEG 0x1012 +#define ROQ_QUAD_HANG 0x1013 +#define ROQ_PACKET 0x1030 +#define ZA_SOUND_MONO 0x1020 +#define ZA_SOUND_STEREO 0x1021 + +#define MAX_VIDEO_HANDLES 16 + +#ifndef HAVE_GLES +extern glconfig_t glConfig; +#endif +extern int s_paintedtime; +extern int s_soundtime; +extern int s_rawend[]; //DAJ added [] to match definition + +#define CIN_STREAM 0 //DAJ const for the sound stream used for cinematics +static void RoQ_init( void ); + +/****************************************************************************** +* +* Class: trFMV +* +* Description: RoQ/RnR manipulation routines +* not entirely complete for first run +* +******************************************************************************/ + +static long ROQ_YY_tab[256]; +static long ROQ_UB_tab[256]; +static long ROQ_UG_tab[256]; +static long ROQ_VG_tab[256]; +static long ROQ_VR_tab[256]; +static unsigned short vq2[256 * 16 * 4]; +static unsigned short vq4[256 * 64 * 4]; +static unsigned short vq8[256 * 256 * 4]; + + +typedef struct { + byte linbuf[DEFAULT_CIN_WIDTH * DEFAULT_CIN_HEIGHT * 4 * 2]; + byte file[65536]; + signed short sqrTable[256]; + + /*unsigned*/ int mcomp[256]; + byte *qStatus[2][32768]; + + long oldXOff, oldYOff, oldysize, oldxsize; + + int currentHandle; +} cinematics_t; + +typedef struct { + char fileName[MAX_OSPATH]; + int CIN_WIDTH, CIN_HEIGHT; + int xpos, ypos, width, height; + qboolean looping, holdAtEnd, dirty, alterGameState, silent, shader, letterBox, sound; + fileHandle_t iFile; + e_status status; + unsigned int startTime; + unsigned int lastTime; + long tfps; + long RoQPlayed; + long ROQSize; + unsigned int RoQFrameSize; + long onQuad; + long numQuads; + long samplesPerLine; + unsigned int roq_id; + signed long screenDelta; + + void ( *VQ0 )( byte *status, void *qdata ); + void ( *VQ1 )( byte *status, void *qdata ); + void ( *VQNormal )( byte *status, void *qdata ); + void ( *VQBuffer )( byte *status, void *qdata ); + + long samplesPerPixel; // defaults to 2 + byte* gray; + unsigned int xsize, ysize, maxsize, minsize; + + qboolean half, smootheddouble, inMemory; + signed long normalBuffer0; + signed long roq_flags; + signed long roqF0; + signed long roqF1; + signed long t[2]; + long roqFPS; + int playonwalls; + byte* buf; + long drawX, drawY; +} cin_cache; + +static cinematics_t cin; +static cin_cache cinTable[MAX_VIDEO_HANDLES]; +static int currentHandle = -1; +static int CL_handle = -1; + +void CIN_CloseAllVideos( void ) { + int i; + + for ( i = 0 ; i < MAX_VIDEO_HANDLES ; i++ ) { + if ( cinTable[i].fileName[0] != 0 ) { + CIN_StopCinematic( i ); + } + } +} + + +static int CIN_HandleForVideo( void ) { + int i; + + for ( i = 0 ; i < MAX_VIDEO_HANDLES ; i++ ) { + if ( cinTable[i].fileName[0] == 0 ) { + return i; + } + } + Com_Error( ERR_DROP, "CIN_HandleForVideo: none free" ); + return -1; +} + + +extern int CL_ScaledMilliseconds( void ); + +//----------------------------------------------------------------------------- +// RllSetupTable +// +// Allocates and initializes the square table. +// +// Parameters: None +// +// Returns: Nothing +//----------------------------------------------------------------------------- +static void RllSetupTable() { + int z; + + for ( z = 0; z < 128; z++ ) { + cin.sqrTable[z] = (signed short)( z * z ); + cin.sqrTable[z + 128] = (signed short)( -cin.sqrTable[z] ); + } +} + + + +//----------------------------------------------------------------------------- +// RllDecodeMonoToMono +// +// Decode mono source data into a mono buffer. +// +// Parameters: from -> buffer holding encoded data +// to -> buffer to hold decoded data +// size = number of bytes of input (= # of shorts of output) +// signedOutput = 0 for unsigned output, non-zero for signed output +// flag = flags from asset header +// +// Returns: Number of samples placed in output buffer +//----------------------------------------------------------------------------- +long RllDecodeMonoToMono( unsigned char *from,short *to,unsigned int size,char signedOutput,unsigned short flag ) { + unsigned int z; + signed short prev; //DAJ was int + + if ( signedOutput ) { + prev = flag - 0x8000; + } else { + prev = flag; + } + + for ( z = 0; z < size; z++ ) { + prev = to[z] = (signed short)( prev + cin.sqrTable[from[z]] ); + } + return size; //*sizeof(short)); +} + + +//----------------------------------------------------------------------------- +// RllDecodeMonoToStereo +// +// Decode mono source data into a stereo buffer. Output is 4 times the number +// of bytes in the input. +// +// Parameters: from -> buffer holding encoded data +// to -> buffer to hold decoded data +// size = number of bytes of input (= 1/4 # of bytes of output) +// signedOutput = 0 for unsigned output, non-zero for signed output +// flag = flags from asset header +// +// Returns: Number of samples placed in output buffer +//----------------------------------------------------------------------------- +long RllDecodeMonoToStereo( unsigned char *from,short *to,unsigned int size,char signedOutput,unsigned short flag ) { + unsigned int z; + signed short prev; //DAJ was int + + if ( signedOutput ) { + prev = flag - 0x8000; + } else { + prev = flag; + } + + for ( z = 0; z < size; z++ ) { + prev = (signed short)( prev + cin.sqrTable[from[z]] ); + to[z * 2 + 0] = to[z * 2 + 1] = (signed short)( prev ); + } + + return size; // * 2 * sizeof(short)); +} + + +//----------------------------------------------------------------------------- +// RllDecodeStereoToStereo +// +// Decode stereo source data into a stereo buffer. +// +// Parameters: from -> buffer holding encoded data +// to -> buffer to hold decoded data +// size = number of bytes of input (= 1/2 # of bytes of output) +// signedOutput = 0 for unsigned output, non-zero for signed output +// flag = flags from asset header +// +// Returns: Number of samples placed in output buffer +//----------------------------------------------------------------------------- +long RllDecodeStereoToStereo( unsigned char *from,short *to,unsigned int size,char signedOutput, unsigned short flag ) { + unsigned int z; + unsigned char *zz = from; + signed short prevL, prevR; //DAJ was int + + if ( signedOutput ) { + prevL = ( flag & 0xff00 ) - 0x8000; + prevR = ( ( flag & 0x00ff ) << 8 ) - 0x8000; + } else { + prevL = flag & 0xff00; + prevR = ( flag & 0x00ff ) << 8; + } + + for ( z = 0; z < size; z += 2 ) { + prevL = (signed short)( prevL + cin.sqrTable[*zz++] ); + prevR = (signed short)( prevR + cin.sqrTable[*zz++] ); + to[z + 0] = (signed short)( prevL ); + to[z + 1] = (signed short)( prevR ); + } + + return ( size >> 1 ); //*sizeof(short)); +} + + +//----------------------------------------------------------------------------- +// RllDecodeStereoToMono +// +// Decode stereo source data into a mono buffer. +// +// Parameters: from -> buffer holding encoded data +// to -> buffer to hold decoded data +// size = number of bytes of input (= # of bytes of output) +// signedOutput = 0 for unsigned output, non-zero for signed output +// flag = flags from asset header +// +// Returns: Number of samples placed in output buffer +//----------------------------------------------------------------------------- +long RllDecodeStereoToMono( unsigned char *from,short *to,unsigned int size,char signedOutput, unsigned short flag ) { + unsigned int z; + signed short prevL, prevR; //DAJ was int + + if ( signedOutput ) { + prevL = ( flag & 0xff00 ) - 0x8000; + prevR = ( ( flag & 0x00ff ) << 8 ) - 0x8000; + } else { + prevL = flag & 0xff00; + prevR = ( flag & 0x00ff ) << 8; + } + + for ( z = 0; z < size; z += 1 ) { + prevL = prevL + cin.sqrTable[from[z * 2]]; + prevR = prevR + cin.sqrTable[from[z * 2 + 1]]; + to[z] = (signed short)( ( prevL + prevR ) / 2 ); + } + + return size; +} + +/****************************************************************************** +* +* Function: +* +* Description: +* +******************************************************************************/ + +static void move8_32( byte *src, byte *dst, int spl ) { +#ifdef ARM + int i; + for (i=0; i<8; i++) { + memcpy(dst, src, 32); + dst+=spl; src+=spl; + } +#else + double *dsrc, *ddst; + int dspl; + + dsrc = (double *)src; + ddst = (double *)dst; + dspl = spl >> 3; + + ddst[0] = dsrc[0]; ddst[1] = dsrc[1]; ddst[2] = dsrc[2]; ddst[3] = dsrc[3]; + dsrc += dspl; ddst += dspl; + ddst[0] = dsrc[0]; ddst[1] = dsrc[1]; ddst[2] = dsrc[2]; ddst[3] = dsrc[3]; + dsrc += dspl; ddst += dspl; + ddst[0] = dsrc[0]; ddst[1] = dsrc[1]; ddst[2] = dsrc[2]; ddst[3] = dsrc[3]; + dsrc += dspl; ddst += dspl; + ddst[0] = dsrc[0]; ddst[1] = dsrc[1]; ddst[2] = dsrc[2]; ddst[3] = dsrc[3]; + dsrc += dspl; ddst += dspl; + ddst[0] = dsrc[0]; ddst[1] = dsrc[1]; ddst[2] = dsrc[2]; ddst[3] = dsrc[3]; + dsrc += dspl; ddst += dspl; + ddst[0] = dsrc[0]; ddst[1] = dsrc[1]; ddst[2] = dsrc[2]; ddst[3] = dsrc[3]; + dsrc += dspl; ddst += dspl; + ddst[0] = dsrc[0]; ddst[1] = dsrc[1]; ddst[2] = dsrc[2]; ddst[3] = dsrc[3]; + dsrc += dspl; ddst += dspl; + ddst[0] = dsrc[0]; ddst[1] = dsrc[1]; ddst[2] = dsrc[2]; ddst[3] = dsrc[3]; +#endif +} + +/****************************************************************************** +* +* Function: +* +* Description: +* +******************************************************************************/ + +static void move4_32( byte *src, byte *dst, int spl ) { +#ifdef ARM + int i; + for (i=0; i<4; i++) { + memcpy(dst, src, 16); + dst+=spl; src+=spl; + } +#else + double *dsrc, *ddst; + int dspl; + + dsrc = (double *)src; + ddst = (double *)dst; + dspl = spl >> 3; + + ddst[0] = dsrc[0]; ddst[1] = dsrc[1]; + dsrc += dspl; ddst += dspl; + ddst[0] = dsrc[0]; ddst[1] = dsrc[1]; + dsrc += dspl; ddst += dspl; + ddst[0] = dsrc[0]; ddst[1] = dsrc[1]; + dsrc += dspl; ddst += dspl; + ddst[0] = dsrc[0]; ddst[1] = dsrc[1]; +#endif +} + +/****************************************************************************** +* +* Function: +* +* Description: +* +******************************************************************************/ + +static void blit8_32( byte *src, byte *dst, int spl ) { +#ifdef ARM + int i; + for (i=0; i<8; i++) { + memcpy(dst, src, 32); + dst+=spl; src+=32; + } +#else + double *dsrc, *ddst; + int dspl; + + dsrc = (double *)src; + ddst = (double *)dst; + dspl = spl >> 3; + + ddst[0] = dsrc[0]; ddst[1] = dsrc[1]; ddst[2] = dsrc[2]; ddst[3] = dsrc[3]; + dsrc += 4; ddst += dspl; + ddst[0] = dsrc[0]; ddst[1] = dsrc[1]; ddst[2] = dsrc[2]; ddst[3] = dsrc[3]; + dsrc += 4; ddst += dspl; + ddst[0] = dsrc[0]; ddst[1] = dsrc[1]; ddst[2] = dsrc[2]; ddst[3] = dsrc[3]; + dsrc += 4; ddst += dspl; + ddst[0] = dsrc[0]; ddst[1] = dsrc[1]; ddst[2] = dsrc[2]; ddst[3] = dsrc[3]; + dsrc += 4; ddst += dspl; + ddst[0] = dsrc[0]; ddst[1] = dsrc[1]; ddst[2] = dsrc[2]; ddst[3] = dsrc[3]; + dsrc += 4; ddst += dspl; + ddst[0] = dsrc[0]; ddst[1] = dsrc[1]; ddst[2] = dsrc[2]; ddst[3] = dsrc[3]; + dsrc += 4; ddst += dspl; + ddst[0] = dsrc[0]; ddst[1] = dsrc[1]; ddst[2] = dsrc[2]; ddst[3] = dsrc[3]; + dsrc += 4; ddst += dspl; + ddst[0] = dsrc[0]; ddst[1] = dsrc[1]; ddst[2] = dsrc[2]; ddst[3] = dsrc[3]; +#endif +} + +/****************************************************************************** +* +* Function: +* +* Description: +* +******************************************************************************/ +#define movs double +static void blit4_32( byte *src, byte *dst, int spl ) { +#ifdef ARM + int i; + for (i=0; i<4; i++) { + memcpy(dst, src, 16); + dst+=spl; src+=16; + } +#else + movs *dsrc, *ddst; + int dspl; + + dsrc = (movs *)src; + ddst = (movs *)dst; + dspl = spl >> 3; + + ddst[0] = dsrc[0]; ddst[1] = dsrc[1]; + dsrc += 2; ddst += dspl; + ddst[0] = dsrc[0]; ddst[1] = dsrc[1]; + dsrc += 2; ddst += dspl; + ddst[0] = dsrc[0]; ddst[1] = dsrc[1]; + dsrc += 2; ddst += dspl; + ddst[0] = dsrc[0]; ddst[1] = dsrc[1]; +#endif +} + +/****************************************************************************** +* +* Function: +* +* Description: +* +******************************************************************************/ + +static void blit2_32( byte *src, byte *dst, int spl ) { +#ifdef ARM + int i; + for (i=0; i<2; i++) { + memcpy(dst, src, 8); + dst+=spl; src+=8; + } +#else + double *dsrc, *ddst; + int dspl; + + dsrc = (double *)src; + ddst = (double *)dst; + dspl = spl >> 3; + + ddst[0] = dsrc[0]; + ddst[dspl] = dsrc[1]; +#endif +} + +/****************************************************************************** +* +* Function: +* +* Description: +* +******************************************************************************/ + +static void blitVQQuad32fs( byte **status, unsigned char *data ) { + unsigned short newd, celdata, code; + unsigned int index, i; + int spl; + + newd = 0; + celdata = 0; + index = 0; + + spl = cinTable[currentHandle].samplesPerLine; + + do { + if ( !newd ) { + newd = 7; + celdata = data[0] + data[1] * 256; + data += 2; + } else { + newd--; + } + + code = ( unsigned short )( celdata & 0xc000 ); + celdata <<= 2; + + switch ( code ) { + case 0x8000: // vq code + blit8_32( (byte *)&vq8[( *data ) * 128], status[index], spl ); + data++; + index += 5; + break; + case 0xc000: // drop + index++; // skip 8x8 + for ( i = 0; i < 4; i++ ) { + if ( !newd ) { + newd = 7; + celdata = data[0] + data[1] * 256; + data += 2; + } else { + newd--; + } + + code = ( unsigned short )( celdata & 0xc000 ); celdata <<= 2; + + switch ( code ) { // code in top two bits of code + case 0x8000: // 4x4 vq code + blit4_32( (byte *)&vq4[( *data ) * 32], status[index], spl ); + data++; + break; + case 0xc000: // 2x2 vq code + blit2_32( (byte *)&vq2[( *data ) * 8], status[index], spl ); + data++; + blit2_32( (byte *)&vq2[( *data ) * 8], status[index] + 8, spl ); + data++; + blit2_32( (byte *)&vq2[( *data ) * 8], status[index] + spl * 2, spl ); + data++; + blit2_32( (byte *)&vq2[( *data ) * 8], status[index] + spl * 2 + 8, spl ); + data++; + break; + case 0x4000: // motion compensation + move4_32( status[index] + cin.mcomp[( *data )], status[index], spl ); + data++; + break; + } + index++; + } + break; + case 0x4000: // motion compensation + move8_32( status[index] + cin.mcomp[( *data )], status[index], spl ); + data++; + index += 5; + break; + case 0x0000: + index += 5; + break; + } + } while ( status[index] != NULL ); +} + +/****************************************************************************** +* +* Function: +* +* Description: +* +******************************************************************************/ + +static void ROQ_GenYUVTables( void ) { + float t_ub,t_vr,t_ug,t_vg; + long i; + + t_ub = ( 1.77200f / 2.0f ) * (float)( 1 << 6 ) + 0.5f; + t_vr = ( 1.40200f / 2.0f ) * (float)( 1 << 6 ) + 0.5f; + t_ug = ( 0.34414f / 2.0f ) * (float)( 1 << 6 ) + 0.5f; + t_vg = ( 0.71414f / 2.0f ) * (float)( 1 << 6 ) + 0.5f; + for ( i = 0; i < 256; i++ ) { + float x = (float)( 2 * i - 255 ); + + ROQ_UB_tab[i] = (long)( ( t_ub * x ) + ( 1 << 5 ) ); + ROQ_VR_tab[i] = (long)( ( t_vr * x ) + ( 1 << 5 ) ); + ROQ_UG_tab[i] = (long)( ( -t_ug * x ) ); + ROQ_VG_tab[i] = (long)( ( -t_vg * x ) + ( 1 << 5 ) ); + ROQ_YY_tab[i] = (long)( ( i << 6 ) | ( i >> 2 ) ); + } +} + +#define VQ2TO4( a,b,c,d ) { \ + *c++ = a[0]; \ + *d++ = a[0]; \ + *d++ = a[0]; \ + *c++ = a[1]; \ + *d++ = a[1]; \ + *d++ = a[1]; \ + *c++ = b[0]; \ + *d++ = b[0]; \ + *d++ = b[0]; \ + *c++ = b[1]; \ + *d++ = b[1]; \ + *d++ = b[1]; \ + *d++ = a[0]; \ + *d++ = a[0]; \ + *d++ = a[1]; \ + *d++ = a[1]; \ + *d++ = b[0]; \ + *d++ = b[0]; \ + *d++ = b[1]; \ + *d++ = b[1]; \ + a += 2; b += 2; } + +#define VQ2TO2( a,b,c,d ) { \ + *c++ = *a; \ + *d++ = *a; \ + *d++ = *a; \ + *c++ = *b; \ + *d++ = *b; \ + *d++ = *b; \ + *d++ = *a; \ + *d++ = *a; \ + *d++ = *b; \ + *d++ = *b; \ + a++; b++; } + +/****************************************************************************** +* +* Function: +* +* Description: +* +******************************************************************************/ + +static unsigned short yuv_to_rgb( long y, long u, long v ) { + long r,g,b,YY = (long)( ROQ_YY_tab[( y )] ); + + r = ( YY + ROQ_VR_tab[v] ) >> 9; + g = ( YY + ROQ_UG_tab[u] + ROQ_VG_tab[v] ) >> 8; + b = ( YY + ROQ_UB_tab[u] ) >> 9; + + if ( r < 0 ) { + r = 0; + } + if ( g < 0 ) { + g = 0; + } + if ( b < 0 ) { + b = 0; + } + if ( r > 31 ) { + r = 31; + } + if ( g > 63 ) { + g = 63; + } + if ( b > 31 ) { + b = 31; + } + + return ( unsigned short )( ( r << 11 ) + ( g << 5 ) + ( b ) ); +} + +/****************************************************************************** +* +* Function: +* +* Description: +* +******************************************************************************/ +#if defined( __MACOS__ ) + +static inline unsigned int yuv_to_rgb24( long y, long u, long v ) { + long r,g,b,YY; + + YY = (long)( ROQ_YY_tab[( y )] ); + + r = ( YY + ROQ_VR_tab[v] ) >> 6; + g = ( YY + ROQ_UG_tab[u] + ROQ_VG_tab[v] ) >> 6; + b = ( YY + ROQ_UB_tab[u] ) >> 6; + + if ( r < 0 ) { + r = 0; + } + if ( g < 0 ) { + g = 0; + } + if ( b < 0 ) { + b = 0; + } + if ( r > 255 ) { + r = 255; + } + if ( g > 255 ) { + g = 255; + } + if ( b > 255 ) { + b = 255; + } + + return ( ( r << 24 ) | ( g << 16 ) | ( b << 8 ) ) | ( 255 ); //+(255<<24)); +} + +#else +static unsigned int yuv_to_rgb24( long y, long u, long v ) { + long r,g,b,YY = (long)( ROQ_YY_tab[( y )] ); + + r = ( YY + ROQ_VR_tab[v] ) >> 6; + g = ( YY + ROQ_UG_tab[u] + ROQ_VG_tab[v] ) >> 6; + b = ( YY + ROQ_UB_tab[u] ) >> 6; + + if ( r < 0 ) { + r = 0; + } + if ( g < 0 ) { + g = 0; + } + if ( b < 0 ) { + b = 0; + } + if ( r > 255 ) { + r = 255; + } + if ( g > 255 ) { + g = 255; + } + if ( b > 255 ) { + b = 255; + } + + return LittleLong( ( r ) | ( g << 8 ) | ( b << 16 ) | ( 255 << 24 ) ); +} +#endif + +/****************************************************************************** +* +* Function: +* +* Description: +* +******************************************************************************/ + +static void decodeCodeBook( byte *input, unsigned short roq_flags ) { + long i, j, two, four; + unsigned short *aptr, *bptr, *cptr, *dptr; + long y0,y1,y2,y3,cr,cb; + byte *bbptr, *baptr, *bcptr, *bdptr; + unsigned int *iaptr, *ibptr, *icptr, *idptr; + + if ( !roq_flags ) { + two = four = 256; + } else { + two = roq_flags >> 8; + if ( !two ) { + two = 256; + } + four = roq_flags & 0xff; + } + + four *= 2; + + bptr = (unsigned short *)vq2; + + if ( !cinTable[currentHandle].half ) { + if ( !cinTable[currentHandle].smootheddouble ) { +// +// normal height +// + if ( cinTable[currentHandle].samplesPerPixel == 2 ) { + for ( i = 0; i < two; i++ ) { + y0 = (long)*input++; + y1 = (long)*input++; + y2 = (long)*input++; + y3 = (long)*input++; + cr = (long)*input++; + cb = (long)*input++; + *bptr++ = yuv_to_rgb( y0, cr, cb ); + *bptr++ = yuv_to_rgb( y1, cr, cb ); + *bptr++ = yuv_to_rgb( y2, cr, cb ); + *bptr++ = yuv_to_rgb( y3, cr, cb ); + } + + cptr = (unsigned short *)vq4; + dptr = (unsigned short *)vq8; + + for ( i = 0; i < four; i++ ) { + aptr = (unsigned short *)vq2 + ( *input++ ) * 4; + bptr = (unsigned short *)vq2 + ( *input++ ) * 4; + for ( j = 0; j < 2; j++ ) + VQ2TO4( aptr,bptr,cptr,dptr ); + } + } else if ( cinTable[currentHandle].samplesPerPixel == 4 ) { + ibptr = (unsigned int *)bptr; + for ( i = 0; i < two; i++ ) { + y0 = (long)*input++; + y1 = (long)*input++; + y2 = (long)*input++; + y3 = (long)*input++; + cr = (long)*input++; + cb = (long)*input++; + *ibptr++ = yuv_to_rgb24( y0, cr, cb ); + *ibptr++ = yuv_to_rgb24( y1, cr, cb ); + *ibptr++ = yuv_to_rgb24( y2, cr, cb ); + *ibptr++ = yuv_to_rgb24( y3, cr, cb ); + } + + icptr = (unsigned int *)vq4; + idptr = (unsigned int *)vq8; + + for ( i = 0; i < four; i++ ) { + iaptr = (unsigned int *)vq2 + ( *input++ ) * 4; + ibptr = (unsigned int *)vq2 + ( *input++ ) * 4; + for ( j = 0; j < 2; j++ ) + VQ2TO4( iaptr, ibptr, icptr, idptr ); + } + } else if ( cinTable[currentHandle].samplesPerPixel == 1 ) { + bbptr = (byte *)bptr; + for ( i = 0; i < two; i++ ) { + *bbptr++ = cinTable[currentHandle].gray[*input++]; + *bbptr++ = cinTable[currentHandle].gray[*input++]; + *bbptr++ = cinTable[currentHandle].gray[*input++]; + *bbptr++ = cinTable[currentHandle].gray[*input]; input += 3; + } + + bcptr = (byte *)vq4; + bdptr = (byte *)vq8; + + for ( i = 0; i < four; i++ ) { + baptr = (byte *)vq2 + ( *input++ ) * 4; + bbptr = (byte *)vq2 + ( *input++ ) * 4; + for ( j = 0; j < 2; j++ ) + VQ2TO4( baptr,bbptr,bcptr,bdptr ); + } + } + } else { +// +// double height, smoothed +// + if ( cinTable[currentHandle].samplesPerPixel == 2 ) { + for ( i = 0; i < two; i++ ) { + y0 = (long)*input++; + y1 = (long)*input++; + y2 = (long)*input++; + y3 = (long)*input++; + cr = (long)*input++; + cb = (long)*input++; + *bptr++ = yuv_to_rgb( y0, cr, cb ); + *bptr++ = yuv_to_rgb( y1, cr, cb ); + *bptr++ = yuv_to_rgb( ( ( y0 * 3 ) + y2 ) / 4, cr, cb ); + *bptr++ = yuv_to_rgb( ( ( y1 * 3 ) + y3 ) / 4, cr, cb ); + *bptr++ = yuv_to_rgb( ( y0 + ( y2 * 3 ) ) / 4, cr, cb ); + *bptr++ = yuv_to_rgb( ( y1 + ( y3 * 3 ) ) / 4, cr, cb ); + *bptr++ = yuv_to_rgb( y2, cr, cb ); + *bptr++ = yuv_to_rgb( y3, cr, cb ); + } + + cptr = (unsigned short *)vq4; + dptr = (unsigned short *)vq8; + + for ( i = 0; i < four; i++ ) { + aptr = (unsigned short *)vq2 + ( *input++ ) * 8; + bptr = (unsigned short *)vq2 + ( *input++ ) * 8; + for ( j = 0; j < 2; j++ ) { + VQ2TO4( aptr,bptr,cptr,dptr ); + VQ2TO4( aptr,bptr,cptr,dptr ); + } + } + } else if ( cinTable[currentHandle].samplesPerPixel == 4 ) { + ibptr = (unsigned int *)bptr; + for ( i = 0; i < two; i++ ) { + y0 = (long)*input++; + y1 = (long)*input++; + y2 = (long)*input++; + y3 = (long)*input++; + cr = (long)*input++; + cb = (long)*input++; + *ibptr++ = yuv_to_rgb24( y0, cr, cb ); + *ibptr++ = yuv_to_rgb24( y1, cr, cb ); + *ibptr++ = yuv_to_rgb24( ( ( y0 * 3 ) + y2 ) / 4, cr, cb ); + *ibptr++ = yuv_to_rgb24( ( ( y1 * 3 ) + y3 ) / 4, cr, cb ); + *ibptr++ = yuv_to_rgb24( ( y0 + ( y2 * 3 ) ) / 4, cr, cb ); + *ibptr++ = yuv_to_rgb24( ( y1 + ( y3 * 3 ) ) / 4, cr, cb ); + *ibptr++ = yuv_to_rgb24( y2, cr, cb ); + *ibptr++ = yuv_to_rgb24( y3, cr, cb ); + } + + icptr = (unsigned int *)vq4; + idptr = (unsigned int *)vq8; + + for ( i = 0; i < four; i++ ) { + iaptr = (unsigned int *)vq2 + ( *input++ ) * 8; + ibptr = (unsigned int *)vq2 + ( *input++ ) * 8; + for ( j = 0; j < 2; j++ ) { + VQ2TO4( iaptr, ibptr, icptr, idptr ); + VQ2TO4( iaptr, ibptr, icptr, idptr ); + } + } + } else if ( cinTable[currentHandle].samplesPerPixel == 1 ) { + bbptr = (byte *)bptr; + for ( i = 0; i < two; i++ ) { + y0 = (long)*input++; + y1 = (long)*input++; + y2 = (long)*input++; + y3 = (long)*input; input += 3; + *bbptr++ = cinTable[currentHandle].gray[y0]; + *bbptr++ = cinTable[currentHandle].gray[y1]; + *bbptr++ = cinTable[currentHandle].gray[( ( y0 * 3 ) + y2 ) / 4]; + *bbptr++ = cinTable[currentHandle].gray[( ( y1 * 3 ) + y3 ) / 4]; + *bbptr++ = cinTable[currentHandle].gray[( y0 + ( y2 * 3 ) ) / 4]; + *bbptr++ = cinTable[currentHandle].gray[( y1 + ( y3 * 3 ) ) / 4]; + *bbptr++ = cinTable[currentHandle].gray[y2]; + *bbptr++ = cinTable[currentHandle].gray[y3]; + } + + bcptr = (byte *)vq4; + bdptr = (byte *)vq8; + + for ( i = 0; i < four; i++ ) { + baptr = (byte *)vq2 + ( *input++ ) * 8; + bbptr = (byte *)vq2 + ( *input++ ) * 8; + for ( j = 0; j < 2; j++ ) { + VQ2TO4( baptr,bbptr,bcptr,bdptr ); + VQ2TO4( baptr,bbptr,bcptr,bdptr ); + } + } + } + } + } else { +// +// 1/4 screen +// + if ( cinTable[currentHandle].samplesPerPixel == 2 ) { + for ( i = 0; i < two; i++ ) { + y0 = (long)*input; input += 2; + y2 = (long)*input; input += 2; + cr = (long)*input++; + cb = (long)*input++; + *bptr++ = yuv_to_rgb( y0, cr, cb ); + *bptr++ = yuv_to_rgb( y2, cr, cb ); + } + + cptr = (unsigned short *)vq4; + dptr = (unsigned short *)vq8; + + for ( i = 0; i < four; i++ ) { + aptr = (unsigned short *)vq2 + ( *input++ ) * 2; + bptr = (unsigned short *)vq2 + ( *input++ ) * 2; + for ( j = 0; j < 2; j++ ) { + VQ2TO2( aptr,bptr,cptr,dptr ); + } + } + } else if ( cinTable[currentHandle].samplesPerPixel == 1 ) { + bbptr = (byte *)bptr; + + for ( i = 0; i < two; i++ ) { + *bbptr++ = cinTable[currentHandle].gray[*input]; input += 2; + *bbptr++ = cinTable[currentHandle].gray[*input]; input += 4; + } + + bcptr = (byte *)vq4; + bdptr = (byte *)vq8; + + for ( i = 0; i < four; i++ ) { + baptr = (byte *)vq2 + ( *input++ ) * 2; + bbptr = (byte *)vq2 + ( *input++ ) * 2; + for ( j = 0; j < 2; j++ ) { + VQ2TO2( baptr,bbptr,bcptr,bdptr ); + } + } + } else if ( cinTable[currentHandle].samplesPerPixel == 4 ) { + ibptr = (unsigned int *) bptr; + for ( i = 0; i < two; i++ ) { + y0 = (long)*input; input += 2; + y2 = (long)*input; input += 2; + cr = (long)*input++; + cb = (long)*input++; + *ibptr++ = yuv_to_rgb24( y0, cr, cb ); + *ibptr++ = yuv_to_rgb24( y2, cr, cb ); + } + + icptr = (unsigned int *)vq4; + idptr = (unsigned int *)vq8; + + for ( i = 0; i < four; i++ ) { + iaptr = (unsigned int *)vq2 + ( *input++ ) * 2; + ibptr = (unsigned int *)vq2 + ( *input++ ) * 2; + for ( j = 0; j < 2; j++ ) { + VQ2TO2( iaptr,ibptr,icptr,idptr ); + } + } + } + } +} + +/****************************************************************************** +* +* Function: +* +* Description: +* +******************************************************************************/ + +static void recurseQuad( long startX, long startY, long quadSize, long xOff, long yOff ) { + byte *scroff; + long bigx, bigy, lowx, lowy, useY; + long offset; + + offset = cinTable[currentHandle].screenDelta; + + lowx = lowy = 0; + bigx = cinTable[currentHandle].xsize; + bigy = cinTable[currentHandle].ysize; + + if ( bigx > cinTable[currentHandle].CIN_WIDTH ) { + bigx = cinTable[currentHandle].CIN_WIDTH; + } + if ( bigy > cinTable[currentHandle].CIN_HEIGHT ) { + bigy = cinTable[currentHandle].CIN_HEIGHT; + } + + if ( ( startX >= lowx ) && ( startX + quadSize ) <= ( bigx ) && ( startY + quadSize ) <= ( bigy ) && ( startY >= lowy ) && quadSize <= MAXSIZE ) { + useY = startY; + scroff = cin.linbuf + ( useY + ( ( cinTable[currentHandle].CIN_HEIGHT - bigy ) >> 1 ) + yOff ) * ( cinTable[currentHandle].samplesPerLine ) + ( ( ( startX + xOff ) ) * cinTable[currentHandle].samplesPerPixel ); + + cin.qStatus[0][cinTable[currentHandle].onQuad ] = scroff; + cin.qStatus[1][cinTable[currentHandle].onQuad++] = scroff + offset; + } + + if ( quadSize != MINSIZE ) { + quadSize >>= 1; + recurseQuad( startX, startY, quadSize, xOff, yOff ); + recurseQuad( startX + quadSize, startY, quadSize, xOff, yOff ); + recurseQuad( startX, startY + quadSize, quadSize, xOff, yOff ); + recurseQuad( startX + quadSize, startY + quadSize, quadSize, xOff, yOff ); + } +} + + +/****************************************************************************** +* +* Function: +* +* Description: +* +******************************************************************************/ + +static void setupQuad( long xOff, long yOff ) { + long numQuadCels, i,x,y; + byte *temp; + + if ( xOff == cin.oldXOff && yOff == cin.oldYOff && cinTable[currentHandle].ysize == cin.oldysize && cinTable[currentHandle].xsize == cin.oldxsize ) { + return; + } + + cin.oldXOff = xOff; + cin.oldYOff = yOff; + cin.oldysize = cinTable[currentHandle].ysize; + cin.oldxsize = cinTable[currentHandle].xsize; + + numQuadCels = ( cinTable[currentHandle].CIN_WIDTH * cinTable[currentHandle].CIN_HEIGHT ) / ( 16 ); + numQuadCels += numQuadCels / 4 + numQuadCels / 16; + numQuadCels += 64; // for overflow + + numQuadCels = ( cinTable[currentHandle].xsize * cinTable[currentHandle].ysize ) / ( 16 ); + numQuadCels += numQuadCels / 4; + numQuadCels += 64; // for overflow + + cinTable[currentHandle].onQuad = 0; + + for ( y = 0; y < (long)cinTable[currentHandle].ysize; y += 16 ) + for ( x = 0; x < (long)cinTable[currentHandle].xsize; x += 16 ) + recurseQuad( x, y, 16, xOff, yOff ); + + temp = NULL; + + for ( i = ( numQuadCels - 64 ); i < numQuadCels; i++ ) { + cin.qStatus[0][i] = temp; // eoq + cin.qStatus[1][i] = temp; // eoq + } +} + +/****************************************************************************** +* +* Function: +* +* Description: +* +******************************************************************************/ + +static void readQuadInfo( byte *qData ) { + if ( currentHandle < 0 ) { + return; + } + + cinTable[currentHandle].xsize = qData[0] + qData[1] * 256; + cinTable[currentHandle].ysize = qData[2] + qData[3] * 256; + cinTable[currentHandle].maxsize = qData[4] + qData[5] * 256; + cinTable[currentHandle].minsize = qData[6] + qData[7] * 256; + + cinTable[currentHandle].CIN_HEIGHT = cinTable[currentHandle].ysize; + cinTable[currentHandle].CIN_WIDTH = cinTable[currentHandle].xsize; + + cinTable[currentHandle].samplesPerLine = cinTable[currentHandle].CIN_WIDTH * cinTable[currentHandle].samplesPerPixel; + cinTable[currentHandle].screenDelta = cinTable[currentHandle].CIN_HEIGHT * cinTable[currentHandle].samplesPerLine; + + cinTable[currentHandle].half = qfalse; + cinTable[currentHandle].smootheddouble = qfalse; + + cinTable[currentHandle].VQ0 = cinTable[currentHandle].VQNormal; + cinTable[currentHandle].VQ1 = cinTable[currentHandle].VQBuffer; + + cinTable[currentHandle].t[0] = ( 0 - (signed int)cin.linbuf ) + (unsigned int)cin.linbuf + cinTable[currentHandle].screenDelta; + cinTable[currentHandle].t[1] = ( 0 - ( (signed int)cin.linbuf + cinTable[currentHandle].screenDelta ) ) + (unsigned int)cin.linbuf; + + cinTable[currentHandle].drawX = cinTable[currentHandle].CIN_WIDTH; + cinTable[currentHandle].drawY = cinTable[currentHandle].CIN_HEIGHT; + +#ifndef HAVE_GLES + // rage pro is very slow at 512 wide textures, voodoo can't do it at all + if ( glConfig.hardwareType == GLHW_RAGEPRO || glConfig.maxTextureSize <= 256 ) { + if ( cinTable[currentHandle].drawX > 256 ) { + cinTable[currentHandle].drawX = 256; + } + if ( cinTable[currentHandle].drawY > 256 ) { + cinTable[currentHandle].drawY = 256; + } + if ( cinTable[currentHandle].CIN_WIDTH != 256 || cinTable[currentHandle].CIN_HEIGHT != 256 ) { + Com_Printf( "HACK: approxmimating cinematic for Rage Pro or Voodoo\n" ); + } + } +#endif +#if defined( MACOS_X ) + cinTable[currentHandle].drawX = 256; + cinTable[currentHandle].drawX = 256; +#endif +} + +/****************************************************************************** +* +* Function: +* +* Description: +* +******************************************************************************/ + +static void RoQPrepMcomp( long xoff, long yoff ) { + signed long i, j, x, y, temp, temp2; + + i = cinTable[currentHandle].samplesPerLine; j = cinTable[currentHandle].samplesPerPixel; + if ( cinTable[currentHandle].xsize == ( cinTable[currentHandle].ysize * 4 ) && !cinTable[currentHandle].half ) { + j = j + j; i = i + i; + } + + for ( y = 0; y < 16; y++ ) { + temp2 = ( y + yoff - 8 ) * i; + for ( x = 0; x < 16; x++ ) { + temp = ( x + xoff - 8 ) * j; + cin.mcomp[( x * 16 ) + y] = cinTable[currentHandle].normalBuffer0 - ( temp2 + temp ); + } + } +} + +/****************************************************************************** +* +* Function: +* +* Description: +* +******************************************************************************/ + +static void initRoQ() { + if ( currentHandle < 0 ) { + return; + } + + cinTable[currentHandle].VQNormal = ( void( * ) ( byte *, void * ) )blitVQQuad32fs; + cinTable[currentHandle].VQBuffer = ( void( * ) ( byte *, void * ) )blitVQQuad32fs; + cinTable[currentHandle].samplesPerPixel = 4; + ROQ_GenYUVTables(); + RllSetupTable(); +} + +/****************************************************************************** +* +* Function: +* +* Description: +* +******************************************************************************/ +/* +static byte* RoQFetchInterlaced( byte *source ) { + int x, *src, *dst; + + if (currentHandle < 0) return NULL; + + src = (int *)source; + dst = (int *)cinTable[currentHandle].buf2; + + for(x=0;x<256*256;x++) { + *dst = *src; + dst++; src += 2; + } + return cinTable[currentHandle].buf2; +} +*/ +static void RoQReset() { + + if ( currentHandle < 0 ) { + return; + } + + Sys_EndStreamedFile( cinTable[currentHandle].iFile ); + + // DHM - Properly close file so we don't run out of handles + FS_FCloseFile( cinTable[currentHandle].iFile ); + cinTable[currentHandle].iFile = 0; + // dhm - end + + FS_FOpenFileRead( cinTable[currentHandle].fileName, &cinTable[currentHandle].iFile, qtrue ); + // let the background thread start reading ahead + Sys_BeginStreamedFile( cinTable[currentHandle].iFile, 0x10000 ); + Sys_StreamedRead( cin.file, 16, 1, cinTable[currentHandle].iFile ); + RoQ_init(); + cinTable[currentHandle].status = FMV_LOOPED; +} + +/****************************************************************************** +* +* Function: +* +* Description: +* +******************************************************************************/ + +static void RoQInterrupt( void ) { + byte *framedata; + short sbuf[32768]; + int ssize; + + if ( currentHandle < 0 ) { + return; + } +//resound: + Sys_StreamedRead( cin.file, cinTable[currentHandle].RoQFrameSize + 8, 1, cinTable[currentHandle].iFile ); + if ( cinTable[currentHandle].RoQPlayed >= cinTable[currentHandle].ROQSize ) { + if ( cinTable[currentHandle].holdAtEnd == qfalse ) { + if ( cinTable[currentHandle].looping ) { + RoQReset(); + } else { + cinTable[currentHandle].status = FMV_EOF; + } + } else { + cinTable[currentHandle].status = FMV_IDLE; + } + return; + } + framedata = cin.file; +// +// new frame is ready +// +redump: + switch ( cinTable[currentHandle].roq_id ) + { + case ROQ_QUAD_VQ: + if ( ( cinTable[currentHandle].numQuads & 1 ) ) { + cinTable[currentHandle].normalBuffer0 = cinTable[currentHandle].t[1]; + RoQPrepMcomp( cinTable[currentHandle].roqF0, cinTable[currentHandle].roqF1 ); + cinTable[currentHandle].VQ1( (byte *)cin.qStatus[1], framedata ); + cinTable[currentHandle].buf = cin.linbuf + cinTable[currentHandle].screenDelta; + } else { + cinTable[currentHandle].normalBuffer0 = cinTable[currentHandle].t[0]; + RoQPrepMcomp( cinTable[currentHandle].roqF0, cinTable[currentHandle].roqF1 ); + cinTable[currentHandle].VQ0( (byte *)cin.qStatus[0], framedata ); + cinTable[currentHandle].buf = cin.linbuf; + } + if ( cinTable[currentHandle].numQuads == 0 ) { // first frame + Com_Memcpy( cin.linbuf + cinTable[currentHandle].screenDelta, cin.linbuf, cinTable[currentHandle].samplesPerLine * cinTable[currentHandle].ysize ); + } + cinTable[currentHandle].numQuads++; + cinTable[currentHandle].dirty = qtrue; + break; + case ROQ_CODEBOOK: + decodeCodeBook( framedata, (unsigned short)cinTable[currentHandle].roq_flags ); + break; + case ZA_SOUND_MONO: + if ( !cinTable[currentHandle].silent ) { + ssize = RllDecodeMonoToStereo( framedata, sbuf, cinTable[currentHandle].RoQFrameSize, 0, (unsigned short)cinTable[currentHandle].roq_flags ); + S_RawSamples( ssize, 22050, 2, 1, (byte *)sbuf, 1.0f, 1.0f, CIN_STREAM ); + cinTable[currentHandle].sound = 1; + } + break; + case ZA_SOUND_STEREO: + if ( !cinTable[currentHandle].silent ) { + if ( cinTable[currentHandle].numQuads == -1 ) { + S_Update(); + Com_DPrintf( "S_Update: Setting rawend to %i\n", s_soundtime ); + s_rawend[CIN_STREAM] = s_soundtime; //DAJ added [CIN_STREAM] + } + ssize = RllDecodeStereoToStereo( framedata, sbuf, cinTable[currentHandle].RoQFrameSize, 0, (unsigned short)cinTable[currentHandle].roq_flags ); +// Com_Printf("%i\n", ssize+s_rawend[CIN_STREAM]- s_soundtime ); + S_RawSamples( ssize, 22050, 2, 2, (byte *)sbuf, 1.0f, 1.0f, CIN_STREAM ); + cinTable[currentHandle].sound = 1; + } + break; + case ROQ_QUAD_INFO: + if ( cinTable[currentHandle].numQuads == -1 ) { + readQuadInfo( framedata ); + setupQuad( 0, 0 ); + // we need to use CL_ScaledMilliseconds because of the smp mode calls from the renderer + cinTable[currentHandle].startTime = cinTable[currentHandle].lastTime = CL_ScaledMilliseconds() * com_timescale->value; + } + if ( cinTable[currentHandle].numQuads != 1 ) { + cinTable[currentHandle].numQuads = 0; + } + break; + case ROQ_PACKET: + cinTable[currentHandle].inMemory = cinTable[currentHandle].roq_flags; + cinTable[currentHandle].RoQFrameSize = 0; // for header + break; + case ROQ_QUAD_HANG: + cinTable[currentHandle].RoQFrameSize = 0; + break; + case ROQ_QUAD_JPEG: + break; + default: + cinTable[currentHandle].status = FMV_EOF; + break; + } +// +// read in next frame data +// + if ( cinTable[currentHandle].RoQPlayed >= cinTable[currentHandle].ROQSize ) { + if ( cinTable[currentHandle].holdAtEnd == qfalse ) { + if ( cinTable[currentHandle].looping ) { + RoQReset(); + } else { + cinTable[currentHandle].status = FMV_EOF; + } + } else { + cinTable[currentHandle].status = FMV_IDLE; + } + return; + } + + framedata += cinTable[currentHandle].RoQFrameSize; + cinTable[currentHandle].roq_id = framedata[0] + framedata[1] * 256; + cinTable[currentHandle].RoQFrameSize = framedata[2] + framedata[3] * 256 + framedata[4] * 65536; + cinTable[currentHandle].roq_flags = framedata[6] + framedata[7] * 256; + cinTable[currentHandle].roqF0 = (signed char)framedata[7]; + cinTable[currentHandle].roqF1 = (signed char)framedata[6]; + + if ( cinTable[currentHandle].RoQFrameSize > 65536 || cinTable[currentHandle].roq_id == 0x1084 ) { + Com_DPrintf( "roq_size>65536||roq_id==0x1084\n" ); + cinTable[currentHandle].status = FMV_EOF; + if ( cinTable[currentHandle].looping ) { + RoQReset(); + } + return; + } + if ( cinTable[currentHandle].inMemory && ( cinTable[currentHandle].status != FMV_EOF ) ) { + cinTable[currentHandle].inMemory--; framedata += 8; goto redump; + } + +// if (cinTable[currentHandle].roq_id == ZA_SOUND_STEREO) { +// / cinTable[currentHandle].RoQPlayed += cinTable[currentHandle].RoQFrameSize+8; +// goto resound; +// } + +// +// one more frame hits the dust +// +// assert(cinTable[currentHandle].RoQFrameSize <= 65536); +// r = Sys_StreamedRead( cin.file, cinTable[currentHandle].RoQFrameSize+8, 1, cinTable[currentHandle].iFile ); + cinTable[currentHandle].RoQPlayed += cinTable[currentHandle].RoQFrameSize + 8; +} + +/****************************************************************************** +* +* Function: +* +* Description: +* +******************************************************************************/ + +static void RoQ_init( void ) { + // we need to use CL_ScaledMilliseconds because of the smp mode calls from the renderer + cinTable[currentHandle].startTime = cinTable[currentHandle].lastTime = CL_ScaledMilliseconds() * com_timescale->value; + + cinTable[currentHandle].RoQPlayed = 24; + +/* get frame rate */ + cinTable[currentHandle].roqFPS = cin.file[ 6] + cin.file[ 7] * 256; + + if ( !cinTable[currentHandle].roqFPS ) { + cinTable[currentHandle].roqFPS = 30; + } + + cinTable[currentHandle].numQuads = -1; + + cinTable[currentHandle].roq_id = cin.file[ 8] + cin.file[ 9] * 256; + cinTable[currentHandle].RoQFrameSize = cin.file[10] + cin.file[11] * 256 + cin.file[12] * 65536; + cinTable[currentHandle].roq_flags = cin.file[14] + cin.file[15] * 256; + + if ( cinTable[currentHandle].RoQFrameSize > 65536 || !cinTable[currentHandle].RoQFrameSize ) { + return; + } + +} + +/****************************************************************************** +* +* Function: +* +* Description: +* +******************************************************************************/ + +static void RoQShutdown( void ) { + const char *s; + + if ( !cinTable[currentHandle].buf ) { + return; + } + + if ( cinTable[currentHandle].status == FMV_IDLE ) { + return; + } + Com_DPrintf( "finished cinematic\n" ); + cinTable[currentHandle].status = FMV_IDLE; + + if ( cinTable[currentHandle].iFile ) { + Sys_EndStreamedFile( cinTable[currentHandle].iFile ); + FS_FCloseFile( cinTable[currentHandle].iFile ); + cinTable[currentHandle].iFile = 0; + } + + if ( cinTable[currentHandle].alterGameState ) { + cls.state = CA_DISCONNECTED; + // we can't just do a vstr nextmap, because + // if we are aborting the intro cinematic with + // a devmap command, nextmap would be valid by + // the time it was referenced + s = Cvar_VariableString( "nextmap" ); + if ( s[0] ) { + Cbuf_ExecuteText( EXEC_APPEND, va( "%s\n", s ) ); + Cvar_Set( "nextmap", "" ); + } + CL_handle = -1; + } + cinTable[currentHandle].fileName[0] = 0; + currentHandle = -1; +} + +/* +================== +SCR_StopCinematic +================== +*/ +e_status CIN_StopCinematic( int handle ) { + + if ( handle < 0 || handle >= MAX_VIDEO_HANDLES || cinTable[handle].status == FMV_EOF ) { + return FMV_EOF; + } + currentHandle = handle; + + Com_DPrintf( "trFMV::stop(), closing %s\n", cinTable[currentHandle].fileName ); + + if ( !cinTable[currentHandle].buf ) { + return FMV_EOF; + } + + if ( cinTable[currentHandle].alterGameState ) { + if ( cls.state != CA_CINEMATIC ) { + return cinTable[currentHandle].status; + } + } + cinTable[currentHandle].status = FMV_EOF; + RoQShutdown(); + + return FMV_EOF; +} + +/* +================== +SCR_RunCinematic + +Fetch and decompress the pending frame +================== +*/ + + +e_status CIN_RunCinematic( int handle ) { + // bk001204 - init + int start = 0; + int thisTime = 0; + int played = 0; + + if ( handle < 0 || handle >= MAX_VIDEO_HANDLES || cinTable[handle].status == FMV_EOF ) { + return FMV_EOF; + } + + if ( cin.currentHandle != handle ) { + currentHandle = handle; + cin.currentHandle = currentHandle; + cinTable[currentHandle].status = FMV_EOF; + RoQReset(); + } + + if ( cinTable[handle].playonwalls < -1 ) { + return cinTable[handle].status; + } + + currentHandle = handle; + + if ( cinTable[currentHandle].alterGameState ) { + if ( cls.state != CA_CINEMATIC ) { + return cinTable[currentHandle].status; + } + } + + if ( cinTable[currentHandle].status == FMV_IDLE ) { + return cinTable[currentHandle].status; + } + + // we need to use CL_ScaledMilliseconds because of the smp mode calls from the renderer + thisTime = CL_ScaledMilliseconds(); + if ( cinTable[currentHandle].shader && ( abs( thisTime - cinTable[currentHandle].lastTime ) ) > 100 ) { + cinTable[currentHandle].startTime += thisTime - cinTable[currentHandle].lastTime; + } + +//----(SA) modified to use specified fps for roq's + + // we need to use CL_ScaledMilliseconds because of the smp mode calls from the renderer + cinTable[currentHandle].tfps = ( ( ( CL_ScaledMilliseconds() - cinTable[currentHandle].startTime ) * cinTable[currentHandle].roqFPS ) / 1000 ); + + start = cinTable[currentHandle].startTime; + while ( ( cinTable[currentHandle].tfps != cinTable[currentHandle].numQuads ) + && cinTable[currentHandle].status == FMV_PLAY ) + { + RoQInterrupt(); + if ( start != cinTable[currentHandle].startTime ) { + // we need to use CL_ScaledMilliseconds because of the smp mode calls from the renderer + cinTable[currentHandle].tfps = ( ( ( CL_ScaledMilliseconds() - cinTable[currentHandle].startTime ) * cinTable[currentHandle].roqFPS ) / 1000 ); + + start = cinTable[currentHandle].startTime; + } + played = 1; + } + +//DAJ added [CIN_STREAM]'s + if ( played && cinTable[currentHandle].sound ) { + if ( s_rawend[CIN_STREAM] < s_soundtime && ( s_soundtime - s_rawend[CIN_STREAM] ) < 100 ) { + cinTable[currentHandle].startTime -= ( s_soundtime - s_rawend[CIN_STREAM] ); + do { + RoQInterrupt(); + } while ( s_rawend[CIN_STREAM] < s_soundtime && cinTable[currentHandle].status == FMV_PLAY ); + } + } + + +//----(SA) end + + cinTable[currentHandle].lastTime = thisTime; + + if ( cinTable[currentHandle].status == FMV_LOOPED ) { + cinTable[currentHandle].status = FMV_PLAY; + } + + if ( cinTable[currentHandle].status == FMV_EOF ) { + if ( cinTable[currentHandle].looping ) { + RoQReset(); + } else { + RoQShutdown(); + } + } + + return cinTable[currentHandle].status; +} + +/* +================== +CL_PlayCinematic + +================== +*/ +int CIN_PlayCinematic( const char *arg, int x, int y, int w, int h, int systemBits ) { + unsigned short RoQID; + char name[MAX_OSPATH]; + int i; + + + // TODO: Laird says don't play cine's in widescreen mode + + + if ( strstr( arg, "/" ) == NULL && strstr( arg, "\\" ) == NULL ) { + Com_sprintf( name, sizeof( name ), "video/%s", arg ); + } else { + Com_sprintf( name, sizeof( name ), "%s", arg ); + } + + if ( !( systemBits & CIN_system ) ) { + for ( i = 0 ; i < MAX_VIDEO_HANDLES ; i++ ) { + if ( !Q_stricmp( cinTable[i].fileName, name ) ) { + return i; + } + } + } + + Com_DPrintf( "SCR_PlayCinematic( %s )\n", arg ); + + Com_Memset( &cin, 0, sizeof( cinematics_t ) ); + currentHandle = CIN_HandleForVideo(); + + cin.currentHandle = currentHandle; + + strcpy( cinTable[currentHandle].fileName, name ); + + cinTable[currentHandle].ROQSize = 0; + cinTable[currentHandle].ROQSize = FS_FOpenFileRead( cinTable[currentHandle].fileName, &cinTable[currentHandle].iFile, qtrue ); + + if ( cinTable[currentHandle].ROQSize <= 0 ) { + Com_DPrintf( "play(%s), ROQSize<=0\n", arg ); + cinTable[currentHandle].fileName[0] = 0; + return -1; + } + + CIN_SetExtents( currentHandle, x, y, w, h ); + CIN_SetLooping( currentHandle, ( systemBits & CIN_loop ) != 0 ); + + cinTable[currentHandle].CIN_HEIGHT = DEFAULT_CIN_HEIGHT; + cinTable[currentHandle].CIN_WIDTH = DEFAULT_CIN_WIDTH; + cinTable[currentHandle].holdAtEnd = ( systemBits & CIN_hold ) != 0; + cinTable[currentHandle].alterGameState = ( systemBits & CIN_system ) != 0; + cinTable[currentHandle].playonwalls = 1; + cinTable[currentHandle].silent = ( systemBits & CIN_silent ) != 0; + cinTable[currentHandle].shader = ( systemBits & CIN_shader ) != 0; + cinTable[currentHandle].letterBox = ( systemBits & CIN_letterBox ) != 0; + cinTable[currentHandle].sound = 0; + + if ( cinTable[currentHandle].alterGameState ) { + // close the menu + if ( uivm ) { + VM_Call( uivm, UI_SET_ACTIVE_MENU, UIMENU_NONE ); + } + } else { + cinTable[currentHandle].playonwalls = cl_inGameVideo->integer; + } + + initRoQ(); + + FS_Read( cin.file, 16, cinTable[currentHandle].iFile ); + + RoQID = ( unsigned short )( cin.file[0] ) + ( unsigned short )( cin.file[1] ) * 256; + if ( RoQID == 0x1084 ) { + RoQ_init(); +// FS_Read (cin.file, cinTable[currentHandle].RoQFrameSize+8, cinTable[currentHandle].iFile); + // let the background thread start reading ahead + Sys_BeginStreamedFile( cinTable[currentHandle].iFile, 0x10000 ); + + cinTable[currentHandle].status = FMV_PLAY; + Com_DPrintf( "trFMV::play(), playing %s\n", arg ); + + if ( cinTable[currentHandle].alterGameState ) { + cls.state = CA_CINEMATIC; + } + + Con_Close(); + + Com_DPrintf( "Setting rawend to %i\n", s_soundtime ); + s_rawend[CIN_STREAM] = s_soundtime; + + return currentHandle; + } + Com_DPrintf( "trFMV::play(), invalid RoQ ID\n" ); + + RoQShutdown(); + return -1; +} + +void CIN_SetExtents( int handle, int x, int y, int w, int h ) { + if ( handle < 0 || handle >= MAX_VIDEO_HANDLES || cinTable[handle].status == FMV_EOF ) { + return; + } + cinTable[handle].xpos = x; + cinTable[handle].ypos = y; + cinTable[handle].width = w; + cinTable[handle].height = h; + cinTable[handle].dirty = qtrue; +} + +void CIN_SetLooping( int handle, qboolean loop ) { + if ( handle < 0 || handle >= MAX_VIDEO_HANDLES || cinTable[handle].status == FMV_EOF ) { + return; + } + cinTable[handle].looping = loop; +} + +/* +================== +SCR_DrawCinematic + +================== +*/ +void CIN_DrawCinematic( int handle ) { + float x, y, w, h; //, barheight; + byte *buf; + + if ( handle < 0 || handle >= MAX_VIDEO_HANDLES || cinTable[handle].status == FMV_EOF ) { + return; + } + + if ( !cinTable[handle].buf ) { + return; + } + + x = cinTable[handle].xpos; + y = cinTable[handle].ypos; + w = cinTable[handle].width; + h = cinTable[handle].height; + buf = cinTable[handle].buf; +//Com_Printf( "SCR_AdjustFrom640 before x=%f, y=%f, w=%f, h=%f\n", x,y,w,h ); + SCR_AdjustFrom640( &x, &y, &w, &h ); +//Com_Printf( "SCR_AdjustFrom640 x=%f, y=%f, w=%f, h=%f\n", x,y,w,h ); + + if ( cinTable[handle].letterBox ) { + float barheight; + float vh; + vh = (float)cls.glconfig.vidHeight; + + barheight = ( (float)LETTERBOX_OFFSET / 480.0f ) * vh; //----(SA) added + +//Com_Printf( "letterBox, barheight=%f\n", barheight ); + re.SetColor( &colorBlack[0] ); +// re.DrawStretchPic( 0, 0, SCREEN_WIDTH, LETTERBOX_OFFSET, 0, 0, 0, 0, cls.whiteShader ); +// re.DrawStretchPic( 0, SCREEN_HEIGHT-LETTERBOX_OFFSET, SCREEN_WIDTH, LETTERBOX_OFFSET, 0, 0, 0, 0, cls.whiteShader ); + //----(SA) adjust for 640x480 + re.DrawStretchPic( 0, 0, w, barheight, 0, 0, 0, 0, cls.whiteShader ); + re.DrawStretchPic( 0, vh - barheight - 1, w, barheight + 1, 0, 0, 0, 0, cls.whiteShader ); + } + + if ( cinTable[handle].dirty && ( cinTable[handle].CIN_WIDTH != cinTable[handle].drawX || cinTable[handle].CIN_HEIGHT != cinTable[handle].drawY ) ) { + int ix, iy, *buf2, *buf3, xm, ym, ll; + xm = cinTable[handle].CIN_WIDTH / 256; + ym = cinTable[handle].CIN_HEIGHT / 256; + ll = 8; + if ( cinTable[handle].CIN_WIDTH == 512 ) { + ll = 9; + } + + buf3 = (int*)buf; + buf2 = Hunk_AllocateTempMemory( 256 * 256 * 4 ); + if ( xm == 2 && ym == 2 ) { + byte *bc2, *bc3; + int ic, iiy; + + bc2 = (byte *)buf2; + bc3 = (byte *)buf3; + for ( iy = 0; iy < 256; iy++ ) { + iiy = iy << 12; + for ( ix = 0; ix < 2048; ix += 8 ) { + for ( ic = ix; ic < ( ix + 4 ); ic++ ) { + *bc2 = ( bc3[iiy + ic] + bc3[iiy + 4 + ic] + bc3[iiy + 2048 + ic] + bc3[iiy + 2048 + 4 + ic] ) >> 2; + bc2++; + } + } + } + } else if ( xm == 2 && ym == 1 ) { + byte *bc2, *bc3; + int ic, iiy; + + bc2 = (byte *)buf2; + bc3 = (byte *)buf3; + for ( iy = 0; iy < 256; iy++ ) { + iiy = iy << 11; + for ( ix = 0; ix < 2048; ix += 8 ) { + for ( ic = ix; ic < ( ix + 4 ); ic++ ) { + *bc2 = ( bc3[iiy + ic] + bc3[iiy + 4 + ic] ) >> 1; + bc2++; + } + } + } + } else { + for ( iy = 0; iy < 256; iy++ ) { + for ( ix = 0; ix < 256; ix++ ) { + buf2[( iy << 8 ) + ix] = buf3[( ( iy * ym ) << ll ) + ( ix * xm )]; + } + } + } + re.DrawStretchRaw( x, y, w, h, 256, 256, (byte *)buf2, handle, qtrue ); + cinTable[handle].dirty = qfalse; + Hunk_FreeTempMemory( buf2 ); + return; + } + +//Com_Printf( "re.DrawStretchRaw(%f, %f, %f, %f, %i, %i, %p, %i, %i )\n", x, y, w, h, cinTable[handle].drawX, cinTable[handle].drawY, buf, handle, cinTable[handle].dirty ); +//Com_Printf( "premier point %x )\n", *(unsigned int*)buf ); + re.DrawStretchRaw( x, y, w, h, cinTable[handle].drawX, cinTable[handle].drawY, buf, handle, cinTable[handle].dirty ); + cinTable[handle].dirty = qfalse; +} + +/* +============== +CL_PlayCinematic_f +============== +*/ +void CL_PlayCinematic_f( void ) { + char *arg, *s; + qboolean holdatend; + int bits = CIN_system; + + Com_DPrintf( "CL_PlayCinematic_f\n" ); + if ( cls.state == CA_CINEMATIC ) { + SCR_StopCinematic(); + } + + arg = Cmd_Argv( 1 ); + s = Cmd_Argv( 2 ); + + holdatend = qfalse; + if ( ( s && s[0] == '1' ) || Q_stricmp( arg,"demoend.roq" ) == 0 || Q_stricmp( arg,"end.roq" ) == 0 ) { + bits |= CIN_hold; + } + if ( s && s[0] == '2' ) { + bits |= CIN_loop; + } + if ( s && s[0] == '3' ) { + bits |= CIN_letterBox; + } + + S_StopAllSounds(); + // make sure volume is up for cine + S_FadeAllSounds( 1, 0 ); + + if ( bits & CIN_letterBox ) { + CL_handle = CIN_PlayCinematic( arg, 0, LETTERBOX_OFFSET, SCREEN_WIDTH, SCREEN_HEIGHT - ( LETTERBOX_OFFSET * 2 ), bits ); + } else { + CL_handle = CIN_PlayCinematic( arg, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, bits ); + } + + if ( CL_handle >= 0 ) { + do { + SCR_RunCinematic(); + } while ( cinTable[currentHandle].buf == NULL && cinTable[currentHandle].status == FMV_PLAY ); // wait for first frame (load codebook and sound) + } +} + + +void SCR_DrawCinematic( void ) { + if ( CL_handle >= 0 && CL_handle < MAX_VIDEO_HANDLES ) { + CIN_DrawCinematic( CL_handle ); + } +} + +void SCR_RunCinematic( void ) { + if ( CL_handle >= 0 && CL_handle < MAX_VIDEO_HANDLES ) { + CIN_RunCinematic( CL_handle ); + } +} + +void SCR_StopCinematic( void ) { + if ( CL_handle >= 0 && CL_handle < MAX_VIDEO_HANDLES ) { + CIN_StopCinematic( CL_handle ); + S_StopAllSounds(); + CL_handle = -1; + } +} + +void CIN_UploadCinematic( int handle ) { + if ( handle >= 0 && handle < MAX_VIDEO_HANDLES ) { + if ( !cinTable[handle].buf ) { + return; + } + if ( cinTable[handle].playonwalls <= 0 && cinTable[handle].dirty ) { + if ( cinTable[handle].playonwalls == 0 ) { + cinTable[handle].playonwalls = -1; + } else { + if ( cinTable[handle].playonwalls == -1 ) { + cinTable[handle].playonwalls = -2; + } else { + cinTable[handle].dirty = qfalse; + } + } + } + re.UploadCinematic( 256, 256, 256, 256, cinTable[handle].buf, handle, cinTable[handle].dirty ); + if ( cl_inGameVideo->integer == 0 && cinTable[handle].playonwalls == 1 ) { + cinTable[handle].playonwalls--; + } + } +} + diff --git a/Projects/Android/jni/rtcw/src/client/cl_console.c b/Projects/Android/jni/rtcw/src/client/cl_console.c new file mode 100644 index 0000000..bf6a958 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/client/cl_console.c @@ -0,0 +1,866 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +// console.c + +#include "client.h" + + +int g_console_field_width = 78; + + +#define COLNSOLE_COLOR COLOR_WHITE //COLOR_BLACK + +#define NUM_CON_TIMES 4 + +//#define CON_TEXTSIZE 32768 +#define CON_TEXTSIZE 65536 // (SA) DM want's more console... + +typedef struct { + qboolean initialized; + + short text[CON_TEXTSIZE]; + int current; // line where next message will be printed + int x; // offset in current line for next print + int display; // bottom of console displays this line + + int linewidth; // characters across screen + int totallines; // total lines in console scrollback + + float xadjust; // for wide aspect screens + + float displayFrac; // aproaches finalFrac at scr_conspeed + float finalFrac; // 0.0 to 1.0 lines of console to display + + int vislines; // in scanlines + + int times[NUM_CON_TIMES]; // cls.realtime time the line was generated + // for transparent notify lines + vec4_t color; +} console_t; + +extern console_t con; + +console_t con; + +cvar_t *con_debug; +cvar_t *con_conspeed; +cvar_t *con_notifytime; + +#define DEFAULT_CONSOLE_WIDTH 78 + +vec4_t console_color = {1.0, 1.0, 1.0, 1.0}; + + +/* +================ +Con_ToggleConsole_f +================ +*/ +void Con_ToggleConsole_f( void ) { + // closing a full screen console restarts the demo loop + if ( cls.state == CA_DISCONNECTED && cls.keyCatchers == KEYCATCH_CONSOLE ) { + CL_StartDemoLoop(); + return; + } + + Field_Clear( &g_consoleField ); + g_consoleField.widthInChars = g_console_field_width; + + Con_ClearNotify(); + cls.keyCatchers ^= KEYCATCH_CONSOLE; +} + +/* +================ +Con_MessageMode_f +================ +*/ +void Con_MessageMode_f( void ) { + chat_playerNum = -1; + chat_team = qfalse; +// chat_limbo = qfalse; // NERVE - SMF + Field_Clear( &chatField ); + chatField.widthInChars = 30; + + cls.keyCatchers ^= KEYCATCH_MESSAGE; +} + +/* +================ +Con_MessageMode2_f +================ +*/ +void Con_MessageMode2_f( void ) { + chat_playerNum = -1; + chat_team = qtrue; +// chat_limbo = qfalse; // NERVE - SMF + Field_Clear( &chatField ); + chatField.widthInChars = 25; + cls.keyCatchers ^= KEYCATCH_MESSAGE; +} + +/* +================ +Con_MessageMode3_f +================ +*/ +void Con_MessageMode3_f( void ) { + chat_playerNum = VM_Call( cgvm, CG_CROSSHAIR_PLAYER ); + if ( chat_playerNum < 0 || chat_playerNum >= MAX_CLIENTS ) { + chat_playerNum = -1; + return; + } + chat_team = qfalse; +// chat_limbo = qfalse; // NERVE - SMF + Field_Clear( &chatField ); + chatField.widthInChars = 30; + cls.keyCatchers ^= KEYCATCH_MESSAGE; +} + +/* +================ +Con_MessageMode4_f +================ +*/ +void Con_MessageMode4_f( void ) { + chat_playerNum = VM_Call( cgvm, CG_LAST_ATTACKER ); + if ( chat_playerNum < 0 || chat_playerNum >= MAX_CLIENTS ) { + chat_playerNum = -1; + return; + } + chat_team = qfalse; +// chat_limbo = qfalse; // NERVE - SMF + Field_Clear( &chatField ); + chatField.widthInChars = 30; + cls.keyCatchers ^= KEYCATCH_MESSAGE; +} + +// NERVE - SMF +/* +================ +Con_StartLimboMode_f +================ +*/ +void Con_StartLimboMode_f( void ) { +// chat_playerNum = -1; +// chat_team = qfalse; + chat_limbo = qtrue; // NERVE - SMF +// Field_Clear( &chatField ); +// chatField.widthInChars = 30; + +// cls.keyCatchers ^= KEYCATCH_MESSAGE; +} + +/* +================ +Con_StopLimboMode_f +================ +*/ +void Con_StopLimboMode_f( void ) { +// chat_playerNum = -1; +// chat_team = qfalse; + chat_limbo = qfalse; // NERVE - SMF +// Field_Clear( &chatField ); +// chatField.widthInChars = 30; + +// cls.keyCatchers &= ~KEYCATCH_MESSAGE; +} +// -NERVE - SMF + +/* +================ +Con_Clear_f +================ +*/ +void Con_Clear_f( void ) { + int i; + + for ( i = 0 ; i < CON_TEXTSIZE ; i++ ) { + con.text[i] = ( ColorIndex( COLNSOLE_COLOR ) << 8 ) | ' '; + } + + Con_Bottom(); // go to end +} + + +/* +================ +Con_Dump_f + +Save the console contents out to a file +================ +*/ +void Con_Dump_f( void ) { + int l, x, i; + short *line; + fileHandle_t f; + char buffer[1024]; + + if ( Cmd_Argc() != 2 ) { + Com_Printf( "usage: condump \n" ); + return; + } + + Com_Printf( "Dumped console text to %s.\n", Cmd_Argv( 1 ) ); + +#ifdef __MACOS__ //DAJ MacOS file typing + { + extern _MSL_IMP_EXP_C long _fcreator, _ftype; + _ftype = 'TEXT'; + _fcreator = 'R*ch'; + } +#endif + f = FS_FOpenFileWrite( Cmd_Argv( 1 ) ); + if ( !f ) { + Com_Printf( "ERROR: couldn't open.\n" ); + return; + } + + // skip empty lines + for ( l = con.current - con.totallines + 1 ; l <= con.current ; l++ ) + { + line = con.text + ( l % con.totallines ) * con.linewidth; + for ( x = 0 ; x < con.linewidth ; x++ ) + if ( ( line[x] & 0xff ) != ' ' ) { + break; + } + if ( x != con.linewidth ) { + break; + } + } + + // write the remaining lines + buffer[con.linewidth] = 0; + for ( ; l <= con.current ; l++ ) + { + line = con.text + ( l % con.totallines ) * con.linewidth; + for ( i = 0; i < con.linewidth; i++ ) + buffer[i] = line[i] & 0xff; + for ( x = con.linewidth - 1 ; x >= 0 ; x-- ) + { + if ( buffer[x] == ' ' ) { + buffer[x] = 0; + } else { + break; + } + } + strcat( buffer, "\n" ); + FS_Write( buffer, strlen( buffer ), f ); + } + + FS_FCloseFile( f ); +} + + +/* +================ +Con_ClearNotify +================ +*/ +void Con_ClearNotify( void ) { + int i; + + for ( i = 0 ; i < NUM_CON_TIMES ; i++ ) { + con.times[i] = 0; + } +} + + + +/* +================ +Con_CheckResize + +If the line width has changed, reformat the buffer. +================ +*/ +void Con_CheckResize( void ) { + int i, j, width, oldwidth, oldtotallines, numlines, numchars; + MAC_STATIC short tbuf[CON_TEXTSIZE]; + + width = ( SCREEN_WIDTH / SMALLCHAR_WIDTH ) - 2; + + if ( width == con.linewidth ) { + return; + } + + if ( width < 1 ) { // video hasn't been initialized yet + width = DEFAULT_CONSOLE_WIDTH; + con.linewidth = width; + con.totallines = CON_TEXTSIZE / con.linewidth; + for ( i = 0; i < CON_TEXTSIZE; i++ ) + + con.text[i] = ( ColorIndex( COLNSOLE_COLOR ) << 8 ) | ' '; + } else + { + oldwidth = con.linewidth; + con.linewidth = width; + oldtotallines = con.totallines; + con.totallines = CON_TEXTSIZE / con.linewidth; + numlines = oldtotallines; + + if ( con.totallines < numlines ) { + numlines = con.totallines; + } + + numchars = oldwidth; + + if ( con.linewidth < numchars ) { + numchars = con.linewidth; + } + + memcpy( tbuf, con.text, CON_TEXTSIZE * sizeof( short ) ); + for ( i = 0; i < CON_TEXTSIZE; i++ ) + + con.text[i] = ( ColorIndex( COLNSOLE_COLOR ) << 8 ) | ' '; + + + for ( i = 0 ; i < numlines ; i++ ) + { + for ( j = 0 ; j < numchars ; j++ ) + { + con.text[( con.totallines - 1 - i ) * con.linewidth + j] = + tbuf[( ( con.current - i + oldtotallines ) % + oldtotallines ) * oldwidth + j]; + } + } + + Con_ClearNotify(); + } + + con.current = con.totallines - 1; + con.display = con.current; +} + + +/* +================ +Con_Init +================ +*/ +void Con_Init( void ) { + int i; + + con_notifytime = Cvar_Get( "con_notifytime", "3", 0 ); + con_conspeed = Cvar_Get( "scr_conspeed", "3", 0 ); + con_debug = Cvar_Get( "con_debug", "0", CVAR_ARCHIVE ); //----(SA) added + + Field_Clear( &g_consoleField ); + g_consoleField.widthInChars = g_console_field_width; + for ( i = 0 ; i < COMMAND_HISTORY ; i++ ) { + Field_Clear( &historyEditLines[i] ); + historyEditLines[i].widthInChars = g_console_field_width; + } + + Cmd_AddCommand( "toggleconsole", Con_ToggleConsole_f ); + Cmd_AddCommand( "messagemode", Con_MessageMode_f ); + Cmd_AddCommand( "messagemode2", Con_MessageMode2_f ); + Cmd_AddCommand( "messagemode3", Con_MessageMode3_f ); + Cmd_AddCommand( "messagemode4", Con_MessageMode4_f ); + Cmd_AddCommand( "startLimboMode", Con_StartLimboMode_f ); // NERVE - SMF + Cmd_AddCommand( "stopLimboMode", Con_StopLimboMode_f ); // NERVE - SMF + Cmd_AddCommand( "clear", Con_Clear_f ); + Cmd_AddCommand( "condump", Con_Dump_f ); +} + + +/* +=============== +Con_Linefeed +=============== +*/ +void Con_Linefeed( void ) { + int i; + + // mark time for transparent overlay + if ( con.current >= 0 ) { + con.times[con.current % NUM_CON_TIMES] = cls.realtime; + } + + con.x = 0; + if ( con.display == con.current ) { + con.display++; + } + con.current++; + for ( i = 0; i < con.linewidth; i++ ) + con.text[( con.current % con.totallines ) * con.linewidth + i] = ( ColorIndex( COLNSOLE_COLOR ) << 8 ) | ' '; +} + +/* +================ +CL_ConsolePrint + +Handles cursor positioning, line wrapping, etc +All console printing must go through this in order to be logged to disk +If no console is visible, the text will appear at the top of the game window +================ +*/ +void CL_ConsolePrint( char *txt ) { + int y; + int c, l; + int color; + + // for some demos we don't want to ever show anything on the console + if ( cl_noprint && cl_noprint->integer ) { + return; + } + + if ( !con.initialized ) { + con.color[0] = + con.color[1] = + con.color[2] = + con.color[3] = 1.0f; + con.linewidth = -1; + Con_CheckResize(); + con.initialized = qtrue; + } + + color = ColorIndex( COLNSOLE_COLOR ); + + while ( ( c = *txt ) != 0 ) { + if ( Q_IsColorString( txt ) ) { + color = ColorIndex( *( txt + 1 ) ); + txt += 2; + continue; + } + + // count word length + for ( l = 0 ; l < con.linewidth ; l++ ) { + if ( txt[l] <= ' ' ) { + break; + } + + } + + // word wrap + if ( l != con.linewidth && ( con.x + l >= con.linewidth ) ) { + Con_Linefeed(); + + } + + txt++; + + switch ( c ) + { + case '\n': + Con_Linefeed(); + break; + case '\r': + con.x = 0; + break; + default: // display character and advance + y = con.current % con.totallines; + con.text[y * con.linewidth + con.x] = ( color << 8 ) | c; + con.x++; + if ( con.x >= con.linewidth ) { + + Con_Linefeed(); + con.x = 0; + } + break; + } + } + + + // mark time for transparent overlay + + if ( con.current >= 0 ) { + con.times[con.current % NUM_CON_TIMES] = cls.realtime; + } +} + + +/* +============================================================================== + +DRAWING + +============================================================================== +*/ + + +/* +================ +Con_DrawInput + +Draw the editline after a ] prompt +================ +*/ +void Con_DrawInput( void ) { + int y; + + if ( cls.state != CA_DISCONNECTED && !( cls.keyCatchers & KEYCATCH_CONSOLE ) ) { + return; + } + + y = con.vislines - ( SMALLCHAR_HEIGHT * 2 ); + + re.SetColor( con.color ); + + SCR_DrawSmallChar( con.xadjust + 1 * SMALLCHAR_WIDTH, y, ']' ); + + Field_Draw( &g_consoleField, con.xadjust + 2 * SMALLCHAR_WIDTH, y, + SCREEN_WIDTH - 3 * SMALLCHAR_WIDTH, qtrue ); +} + + +/* +================ +Con_DrawNotify + +Draws the last few lines of output transparently over the game top +================ +*/ +void Con_DrawNotify( void ) { + int x, v; + short *text; + int i; + int time; + int skip; + int currentColor; + + currentColor = 7; + re.SetColor( g_color_table[currentColor] ); + + v = 0; + for ( i = con.current - NUM_CON_TIMES + 1 ; i <= con.current ; i++ ) + { + if ( i < 0 ) { + continue; + } + time = con.times[i % NUM_CON_TIMES]; + if ( time == 0 ) { + continue; + } + time = cls.realtime - time; + if ( time > con_notifytime->value * 1000 ) { + continue; + } + text = con.text + ( i % con.totallines ) * con.linewidth; + + if ( cl.snap.ps.pm_type != PM_INTERMISSION && cls.keyCatchers & ( KEYCATCH_UI | KEYCATCH_CGAME ) ) { + continue; + } + + for ( x = 0 ; x < con.linewidth ; x++ ) { + if ( ( text[x] & 0xff ) == ' ' ) { + continue; + } + if ( ( ( text[x] >> 8 ) & 7 ) != currentColor ) { + currentColor = ( text[x] >> 8 ) & 7; + re.SetColor( g_color_table[currentColor] ); + } + SCR_DrawSmallChar( cl_conXOffset->integer + con.xadjust + ( x + 1 ) * SMALLCHAR_WIDTH, v, text[x] & 0xff ); + } + + v += SMALLCHAR_HEIGHT; + } + + re.SetColor( NULL ); + + if ( cls.keyCatchers & ( KEYCATCH_UI | KEYCATCH_CGAME ) ) { + return; + } + + // draw the chat line + if ( cls.keyCatchers & KEYCATCH_MESSAGE ) { + if ( chat_team ) { + SCR_DrawBigString( 8, v, "say_team:", 1.0f ); + skip = 11; + } else + { + SCR_DrawBigString( 8, v, "say:", 1.0f ); + skip = 5; + } + + Field_BigDraw( &chatField, skip * BIGCHAR_WIDTH, v, + SCREEN_WIDTH - ( skip + 1 ) * BIGCHAR_WIDTH, qtrue ); + + v += BIGCHAR_HEIGHT; + } + +} + +/* +================ +Con_DrawSolidConsole + +Draws the console with the solid background +================ +*/ + +void Con_DrawSolidConsole( float frac ) { + int i, x, y; + int rows; + short *text; + int row; + int lines; +// qhandle_t conShader; + int currentColor; + vec4_t color; + + lines = cls.glconfig.vidHeight * frac; + if ( lines <= 0 ) { + return; + } + + if ( lines > cls.glconfig.vidHeight ) { + lines = cls.glconfig.vidHeight; + } + + // on wide screens, we will center the text + con.xadjust = 0; + SCR_AdjustFrom640( &con.xadjust, NULL, NULL, NULL ); + + // draw the background + y = frac * SCREEN_HEIGHT - 2; + if ( y < 1 ) { + y = 0; + } else { + SCR_DrawPic( 0, 0, SCREEN_WIDTH, y, cls.consoleShader ); + + if ( frac >= 0.5f ) { // only draw when the console is down all the way (for now) + color[0] = color[1] = color[2] = frac * 2.0f; + color[3] = 1.0f; + re.SetColor( color ); + + // draw the logo + SCR_DrawPic( 192, 70, 256, 128, cls.consoleShader2 ); + re.SetColor( NULL ); + } + } + + color[0] = 0; + color[1] = 0; + color[2] = 0; + color[3] = 0.6f; + SCR_FillRect( 0, y, SCREEN_WIDTH, 2, color ); + + // draw the version number + + re.SetColor( g_color_table[ColorIndex( COLNSOLE_COLOR )] ); + + i = strlen( Q3_VERSION ); + + for ( x = 0 ; x < i ; x++ ) { + + SCR_DrawSmallChar( cls.glconfig.vidWidth - ( i - x ) * SMALLCHAR_WIDTH, + + ( lines - ( SMALLCHAR_HEIGHT + SMALLCHAR_HEIGHT / 2 ) ), Q3_VERSION[x] ); + + } + + + // draw the text + con.vislines = lines; + rows = ( lines - SMALLCHAR_WIDTH ) / SMALLCHAR_WIDTH; // rows of text to draw + + y = lines - ( SMALLCHAR_HEIGHT * 3 ); + + // draw from the bottom up + if ( con.display != con.current ) { + // draw arrows to show the buffer is backscrolled + re.SetColor( g_color_table[ColorIndex( COLOR_WHITE )] ); + for ( x = 0 ; x < con.linewidth ; x += 4 ) + SCR_DrawSmallChar( con.xadjust + ( x + 1 ) * SMALLCHAR_WIDTH, y, '^' ); + y -= SMALLCHAR_HEIGHT; + rows--; + } + + row = con.display; + + if ( con.x == 0 ) { + row--; + } + + currentColor = 7; + re.SetColor( g_color_table[currentColor] ); + + for ( i = 0 ; i < rows ; i++, y -= SMALLCHAR_HEIGHT, row-- ) + { + if ( row < 0 ) { + break; + } + if ( con.current - row >= con.totallines ) { + // past scrollback wrap point + continue; + } + + text = con.text + ( row % con.totallines ) * con.linewidth; + + for ( x = 0 ; x < con.linewidth ; x++ ) { + if ( ( text[x] & 0xff ) == ' ' ) { + continue; + } + + if ( ( ( text[x] >> 8 ) & 7 ) != currentColor ) { + currentColor = ( text[x] >> 8 ) & 7; + re.SetColor( g_color_table[currentColor] ); + } + SCR_DrawSmallChar( con.xadjust + ( x + 1 ) * SMALLCHAR_WIDTH, y, text[x] & 0xff ); + } + } + + // draw the input prompt, user text, and cursor if desired + Con_DrawInput(); + + re.SetColor( NULL ); +} + + + +/* +================== +Con_DrawConsole +================== +*/ +void Con_DrawConsole( void ) { + // check for console width changes from a vid mode change + Con_CheckResize(); + + // if disconnected, render console full screen + switch ( cls.state ) { + case CA_UNINITIALIZED: + case CA_CONNECTING: // sending request packets to the server + case CA_CHALLENGING: // sending challenge packets to the server + case CA_CONNECTED: // netchan_t established, getting gamestate + case CA_PRIMED: // got gamestate, waiting for first frame + case CA_LOADING: // only during cgame initialization, never during main loop + if ( !con_debug->integer ) { // these are all 'no console at all' when con_debug is not set + return; + } + + if ( cls.keyCatchers & KEYCATCH_UI ) { + return; + } + + Con_DrawSolidConsole( 1.0 ); + return; + + case CA_DISCONNECTED: // not talking to a server + if ( !( cls.keyCatchers & KEYCATCH_UI ) ) { + Con_DrawSolidConsole( 1.0 ); + return; + } + break; + + case CA_ACTIVE: // game views should be displayed + if ( con.displayFrac ) { + if ( con_debug->integer == 2 ) { // 2 means draw full screen console at '~' +// Con_DrawSolidConsole( 1.0f ); + Con_DrawSolidConsole( con.displayFrac * 2.0f ); + return; + } + } + + break; + + + case CA_CINEMATIC: // playing a cinematic or a static pic, not connected to a server + default: + break; + } + + if ( con.displayFrac ) { + Con_DrawSolidConsole( con.displayFrac ); + } else { + Con_DrawNotify(); // draw notify lines + } +} + +//================================================================ + +/* +================== +Con_RunConsole + +Scroll it up or down +================== +*/ +void Con_RunConsole( void ) { + // decide on the destination height of the console + if ( cls.keyCatchers & KEYCATCH_CONSOLE ) { + con.finalFrac = 0.5; // half screen + } else { + con.finalFrac = 0; // none visible + + } + // scroll towards the destination height + if ( con.finalFrac < con.displayFrac ) { + con.displayFrac -= con_conspeed->value * cls.realFrametime * 0.001; + if ( con.finalFrac > con.displayFrac ) { + con.displayFrac = con.finalFrac; + } + + } else if ( con.finalFrac > con.displayFrac ) { + con.displayFrac += con_conspeed->value * cls.realFrametime * 0.001; + if ( con.finalFrac < con.displayFrac ) { + con.displayFrac = con.finalFrac; + } + } + +} + + +void Con_PageUp( void ) { + con.display -= 2; + if ( con.current - con.display >= con.totallines ) { + con.display = con.current - con.totallines + 1; + } +} + +void Con_PageDown( void ) { + con.display += 2; + if ( con.display > con.current ) { + con.display = con.current; + } +} + +void Con_Top( void ) { + con.display = con.totallines; + if ( con.current - con.display >= con.totallines ) { + con.display = con.current - con.totallines + 1; + } +} + +void Con_Bottom( void ) { + con.display = con.current; +} + + +void Con_Close( void ) { + if ( !com_cl_running->integer ) { + return; + } + Field_Clear( &g_consoleField ); + Con_ClearNotify(); + cls.keyCatchers &= ~KEYCATCH_CONSOLE; + con.finalFrac = 0; // none visible + con.displayFrac = 0; +} diff --git a/Projects/Android/jni/rtcw/src/client/cl_input.c b/Projects/Android/jni/rtcw/src/client/cl_input.c new file mode 100644 index 0000000..65006fd --- /dev/null +++ b/Projects/Android/jni/rtcw/src/client/cl_input.c @@ -0,0 +1,1196 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +// cl.input.c -- builds an intended movement command to send to the server + +#include "client.h" + +unsigned frame_msec; +int old_com_frameTime; + +/* +=============================================================================== + +KEY BUTTONS + +Continuous button event tracking is complicated by the fact that two different +input sources (say, mouse button 1 and the control key) can both press the +same button, but the button should only be released when both of the +pressing key have been released. + +When a key event issues a button command (+forward, +attack, etc), it appends +its key number as argv(1) so it can be matched up with the release. + +argv(2) will be set to the time the event happened, which allows exact +control even at low framerates when the down and up events may both get qued +at the same time. + +=============================================================================== +*/ + +kbutton_t kb[NUM_BUTTONS]; + +void IN_MLookDown( void ) { + kb[KB_MLOOK].active = qtrue; +} + +void IN_MLookUp( void ) { + kb[KB_MLOOK].active = qfalse; + if ( !cl_freelook->integer ) { + IN_CenterView(); + } +} + +void IN_KeyDown( kbutton_t *b ) { + int k; + char *c; + + c = Cmd_Argv( 1 ); + if ( c[0] ) { + k = atoi( c ); + } else { + k = -1; // typed manually at the console for continuous down + } + + if ( k == b->down[0] || k == b->down[1] ) { + return; // repeating key + } + + if ( !b->down[0] ) { + b->down[0] = k; + } else if ( !b->down[1] ) { + b->down[1] = k; + } else { + Com_Printf( "Three keys down for a button!\n" ); + return; + } + + if ( b->active ) { + return; // still down + } + + // save timestamp for partial frame summing + c = Cmd_Argv( 2 ); + b->downtime = atoi( c ); + + b->active = qtrue; + b->wasPressed = qtrue; +} + +void IN_KeyUp( kbutton_t *b ) { + int k; + char *c; + unsigned uptime; + + c = Cmd_Argv( 1 ); + if ( c[0] ) { + k = atoi( c ); + } else { + // typed manually at the console, assume for unsticking, so clear all + b->down[0] = b->down[1] = 0; + b->active = qfalse; + return; + } + + if ( b->down[0] == k ) { + b->down[0] = 0; + } else if ( b->down[1] == k ) { + b->down[1] = 0; + } else { + return; // key up without coresponding down (menu pass through) + } + if ( b->down[0] || b->down[1] ) { + return; // some other key is still holding it down + } + + b->active = qfalse; + + // save timestamp for partial frame summing + c = Cmd_Argv( 2 ); + uptime = atoi( c ); + if ( uptime ) { + b->msec += uptime - b->downtime; + } else { + b->msec += frame_msec / 2; + } + + b->active = qfalse; +} + +#ifdef PANDORA +void IN_ToggleKeyDown( kbutton_t *b ) { + int k; + char *c; + unsigned uptime; + + c = Cmd_Argv( 1 ); + if ( c[0] ) { + k = atoi( c ); + } else { + k = -1; // typed manually at the console for continuous down + } + + if ( k == b->down[0] || k == b->down[1] ) { + return; // repeating key + } + + if ( !b->down[0] ) { + b->down[0] = k; + } else if ( !b->down[1] ) { + b->down[1] = k; + } else { + Com_Printf( "Three keys down for a button!\n" ); + return; + } + + b->active = 1-b->active; // toggle + // save timestamp for partial frame summing + c = Cmd_Argv( 2 ); + uptime = atoi( c ); + if (b->active) + b->downtime = uptime; + else + { + if ( uptime ) { + b->msec += uptime - b->downtime; + } else { + b->msec += frame_msec / 2; + } + } + b->wasPressed = b->active; +} + +void IN_ToggleKeyUp( kbutton_t *b ) { + int k; + char *c; + + c = Cmd_Argv( 1 ); + if ( c[0] ) { + k = atoi( c ); + } else { + // typed manually at the console, assume for unsticking, so clear all + b->down[0] = b->down[1] = 0; + b->active = qfalse; + return; + } + + if ( b->down[0] == k ) { + b->down[0] = 0; + } else if ( b->down[1] == k ) { + b->down[1] = 0; + } else { + return; // key up without coresponding down (menu pass through) + } + if ( b->down[0] || b->down[1] ) { + return; // some other key is still holding it down + } + +} +#endif + +/* +=============== +CL_KeyState + +Returns the fraction of the frame that the key was down +=============== +*/ +float CL_KeyState( kbutton_t *key ) { + float val; + int msec; + + msec = key->msec; + key->msec = 0; + + if ( key->active ) { + // still down + if ( !key->downtime ) { + msec = com_frameTime; + } else { + msec += com_frameTime - key->downtime; + } + key->downtime = com_frameTime; + } + +#if 0 + if ( msec ) { + Com_Printf( "%i ", msec ); + } +#endif + + val = (float)msec / frame_msec; + if ( val < 0 ) { + val = 0; + } + if ( val > 1 ) { + val = 1; + } + + return val; +} + + + +#ifdef PANDORA +void IN_UpDown( void ) {kb[KB_DOWN].active = 0; IN_KeyDown( &kb[KB_UP] );} +#else +void IN_UpDown( void ) {IN_KeyDown( &kb[KB_UP] );} +#endif +void IN_UpUp( void ) {IN_KeyUp( &kb[KB_UP] );} +#ifdef PANDORA +void IN_DownDown( void ) {IN_ToggleKeyDown( &kb[KB_DOWN] );} +void IN_DownUp( void ) {IN_ToggleKeyUp( &kb[KB_DOWN] );} +#else +void IN_DownDown( void ) {IN_KeyDown( &kb[KB_DOWN] );} +void IN_DownUp( void ) {IN_KeyUp( &kb[KB_DOWN] );} +#endif +void IN_LeftDown( void ) {IN_KeyDown( &kb[KB_LEFT] );} +void IN_LeftUp( void ) {IN_KeyUp( &kb[KB_LEFT] );} +void IN_RightDown( void ) {IN_KeyDown( &kb[KB_RIGHT] );} +void IN_RightUp( void ) {IN_KeyUp( &kb[KB_RIGHT] );} +void IN_ForwardDown( void ) {IN_KeyDown( &kb[KB_FORWARD] );} +void IN_ForwardUp( void ) {IN_KeyUp( &kb[KB_FORWARD] );} +void IN_BackDown( void ) {IN_KeyDown( &kb[KB_BACK] );} +void IN_BackUp( void ) {IN_KeyUp( &kb[KB_BACK] );} +void IN_LookupDown( void ) {IN_KeyDown( &kb[KB_LOOKUP] );} +void IN_LookupUp( void ) {IN_KeyUp( &kb[KB_LOOKUP] );} +void IN_LookdownDown( void ) {IN_KeyDown( &kb[KB_LOOKDOWN] );} +void IN_LookdownUp( void ) {IN_KeyUp( &kb[KB_LOOKDOWN] );} +void IN_MoveleftDown( void ) {IN_KeyDown( &kb[KB_MOVELEFT] );} +void IN_MoveleftUp( void ) {IN_KeyUp( &kb[KB_MOVELEFT] );} +void IN_MoverightDown( void ) {IN_KeyDown( &kb[KB_MOVERIGHT] );} +void IN_MoverightUp( void ) {IN_KeyUp( &kb[KB_MOVERIGHT] );} + +void IN_SpeedDown( void ) {IN_KeyDown( &kb[KB_SPEED] );} +void IN_SpeedUp( void ) {IN_KeyUp( &kb[KB_SPEED] );} +void IN_StrafeDown( void ) {IN_KeyDown( &kb[KB_STRAFE] );} +void IN_StrafeUp( void ) {IN_KeyUp( &kb[KB_STRAFE] );} + +void IN_Button0Down( void ) {IN_KeyDown( &kb[KB_BUTTONS0] );} +void IN_Button0Up( void ) {IN_KeyUp( &kb[KB_BUTTONS0] );} +void IN_Button1Down( void ) {IN_KeyDown( &kb[KB_BUTTONS1] );} +void IN_Button1Up( void ) {IN_KeyUp( &kb[KB_BUTTONS1] );} +void IN_UseItemDown( void ) {IN_KeyDown( &kb[KB_BUTTONS2] );} +void IN_UseItemUp( void ) {IN_KeyUp( &kb[KB_BUTTONS2] );} +void IN_Button3Down( void ) {IN_KeyDown( &kb[KB_BUTTONS3] );} +void IN_Button3Up( void ) {IN_KeyUp( &kb[KB_BUTTONS3] );} +void IN_Button4Down( void ) {IN_KeyDown( &kb[KB_BUTTONS4] );} +void IN_Button4Up( void ) {IN_KeyUp( &kb[KB_BUTTONS4] );} +// void IN_Button5Down(void) {IN_KeyDown(&kb[KB_BUTTONS5]);} +// void IN_Button5Up(void) {IN_KeyUp(&kb[KB_BUTTONS5]);} + +// void IN_Button6Down(void) {IN_KeyDown(&kb[KB_BUTTONS6]);} +// void IN_Button6Up(void) {IN_KeyUp(&kb[KB_BUTTONS6]);} + +// Rafael activate +void IN_ActivateDown( void ) {IN_KeyDown( &kb[KB_BUTTONS6] );} +void IN_ActivateUp( void ) {IN_KeyUp( &kb[KB_BUTTONS6] );} +// done. + +// Rafael Kick +void IN_KickDown( void ) {IN_KeyDown( &kb[KB_KICK] );} +void IN_KickUp( void ) {IN_KeyUp( &kb[KB_KICK] );} +// done. + +void IN_SprintDown( void ) {IN_KeyDown( &kb[KB_BUTTONS5] );} +void IN_SprintUp( void ) {IN_KeyUp( &kb[KB_BUTTONS5] );} + + +// wbuttons (wolf buttons) +void IN_Wbutton0Down( void ) { IN_KeyDown( &kb[KB_WBUTTONS0] ); } //----(SA) secondary fire button +void IN_Wbutton0Up( void ) { IN_KeyUp( &kb[KB_WBUTTONS0] ); } +void IN_ZoomDown( void ) { IN_KeyDown( &kb[KB_WBUTTONS1] ); } //----(SA) zoom key +void IN_ZoomUp( void ) { IN_KeyUp( &kb[KB_WBUTTONS1] ); } +void IN_QuickGrenDown( void ) { IN_KeyDown( &kb[KB_WBUTTONS2] ); } //----(SA) "Quickgrenade" +void IN_QuickGrenUp( void ) { IN_KeyUp( &kb[KB_WBUTTONS2] ); } +void IN_ReloadDown( void ) { IN_KeyDown( &kb[KB_WBUTTONS3] ); } //----(SA) manual weapon re-load +void IN_ReloadUp( void ) { IN_KeyUp( &kb[KB_WBUTTONS3] ); } +void IN_LeanLeftDown( void ) { IN_KeyDown( &kb[KB_WBUTTONS4] ); } //----(SA) lean left +void IN_LeanLeftUp( void ) { IN_KeyUp( &kb[KB_WBUTTONS4] ); } +void IN_LeanRightDown( void ) { IN_KeyDown( &kb[KB_WBUTTONS5] ); } //----(SA) lean right +void IN_LeanRightUp( void ) { IN_KeyUp( &kb[KB_WBUTTONS5] ); } + +// unused +void IN_Wbutton6Down( void ) { IN_KeyDown( &kb[KB_WBUTTONS6] ); } +void IN_Wbutton6Up( void ) { IN_KeyUp( &kb[KB_WBUTTONS6] ); } +void IN_Wbutton7Down( void ) { IN_KeyDown( &kb[KB_WBUTTONS7] ); } +void IN_Wbutton7Up( void ) { IN_KeyUp( &kb[KB_WBUTTONS7] ); } + + + + +void IN_ButtonDown( void ) { + IN_KeyDown( &kb[KB_BUTTONS1] ); +} +void IN_ButtonUp( void ) { + IN_KeyUp( &kb[KB_BUTTONS1] ); +} + +void IN_CenterView( void ) { + cl.viewangles[PITCH] = -SHORT2ANGLE( cl.snap.ps.delta_angles[PITCH] ); +} + +void IN_Notebook( void ) { + if ( cls.state == CA_ACTIVE && !clc.demoplaying ) { + Cvar_Set( "cg_youGotMail", "0" ); // clear icon //----(SA) added + VM_Call( uivm, UI_SET_ACTIVE_MENU, UIMENU_NOTEBOOK ); // startup notebook + } +} + +void IN_Help( void ) { + if ( cls.state == CA_ACTIVE && !clc.demoplaying ) { + VM_Call( uivm, UI_SET_ACTIVE_MENU, UIMENU_HELP ); // startup help system + } +} + + +//========================================================================== + +cvar_t *cl_upspeed; +cvar_t *cl_forwardspeed; +cvar_t *cl_sidespeed; + +cvar_t *cl_yawspeed; +cvar_t *cl_pitchspeed; + +cvar_t *cl_run; + +cvar_t *cl_anglespeedkey; + +cvar_t *cl_recoilPitch; + +/* +================ +CL_AdjustAngles + +Moves the local angle positions +================ +*/ +void CL_AdjustAngles( void ) { + float speed; + + if ( kb[KB_SPEED].active ) { + speed = 0.001 * cls.frametime * cl_anglespeedkey->value; + } else { + speed = 0.001 * cls.frametime; + } + + if ( !kb[KB_STRAFE].active ) { + cl.viewangles[YAW] -= speed * cl_yawspeed->value * CL_KeyState( &kb[KB_RIGHT] ); + cl.viewangles[YAW] += speed * cl_yawspeed->value * CL_KeyState( &kb[KB_LEFT] ); + } + + cl.viewangles[PITCH] -= speed * cl_pitchspeed->value * CL_KeyState( &kb[KB_LOOKUP] ); + cl.viewangles[PITCH] += speed * cl_pitchspeed->value * CL_KeyState( &kb[KB_LOOKDOWN] ); +} + +/* +================ +CL_KeyMove + +Sets the usercmd_t based on key states +================ +*/ +void CL_KeyMove( usercmd_t *cmd ) { + int movespeed; + int forward, side, up; + // Rafael Kick + int kick; + // done + + // + // adjust for speed key / running + // the walking flag is to keep animations consistant + // even during acceleration and develeration + // + if ( kb[KB_SPEED].active ^ cl_run->integer ) { + movespeed = 127; + cmd->buttons &= ~BUTTON_WALKING; + } else { + cmd->buttons |= BUTTON_WALKING; + movespeed = 64; + } + + forward = 0; + side = 0; + up = 0; + if ( kb[KB_STRAFE].active ) { + side += movespeed * CL_KeyState( &kb[KB_RIGHT] ); + side -= movespeed * CL_KeyState( &kb[KB_LEFT] ); + } + + side += movespeed * CL_KeyState( &kb[KB_MOVERIGHT] ); + side -= movespeed * CL_KeyState( &kb[KB_MOVELEFT] ); + +//----(SA) added + if ( cmd->buttons & BUTTON_ACTIVATE ) { + if ( side > 0 ) { + cmd->wbuttons |= WBUTTON_LEANRIGHT; + } else if ( side < 0 ) { + cmd->wbuttons |= WBUTTON_LEANLEFT; + } + + side = 0; // disallow the strafe when holding 'activate' + } +//----(SA) end + + up += movespeed * CL_KeyState( &kb[KB_UP] ); + up -= movespeed * CL_KeyState( &kb[KB_DOWN] ); + + forward += movespeed * CL_KeyState( &kb[KB_FORWARD] ); + forward -= movespeed * CL_KeyState( &kb[KB_BACK] ); + + // Rafael Kick + kick = CL_KeyState( &kb[KB_KICK] ); + // done + + if ( !( cl.snap.ps.persistant[PERS_HWEAPON_USE] ) ) { + cmd->forwardmove = ClampChar( forward ); + cmd->rightmove = ClampChar( side ); + cmd->upmove = ClampChar( up ); + + // Rafael - Kick + cmd->wolfkick = ClampChar( kick ); + // done + + } +} + +/* +================= +CL_MouseEvent +================= +*/ +void CL_MouseEvent( int dx, int dy, int time ) { + if ( cls.keyCatchers & KEYCATCH_UI ) { + VM_Call( uivm, UI_MOUSE_EVENT, dx, dy ); + } else if ( cls.keyCatchers & KEYCATCH_CGAME ) { + VM_Call( cgvm, CG_MOUSE_EVENT, dx, dy ); + } else { + cl.mouseDx[cl.mouseIndex] += dx; + cl.mouseDy[cl.mouseIndex] += dy; + } +} + +/* +================= +CL_JoystickEvent + +Joystick values stay set until changed +================= +*/ +void CL_JoystickEvent( int axis, int value, int time ) { + if ( axis < 0 || axis >= MAX_JOYSTICK_AXIS ) { + Com_Error( ERR_DROP, "CL_JoystickEvent: bad axis %i", axis ); + } + cl.joystickAxis[axis] = value; +} + +/* +================= +CL_JoystickMove +================= +*/ +void CL_JoystickMove( usercmd_t *cmd ) { + int movespeed; + float anglespeed; + + if ( kb[KB_SPEED].active ^ cl_run->integer ) { + movespeed = 2; + } else { + movespeed = 1; + cmd->buttons |= BUTTON_WALKING; + } + + if ( kb[KB_SPEED].active ) { + anglespeed = 0.001 * cls.frametime * cl_anglespeedkey->value; + } else { + anglespeed = 0.001 * cls.frametime; + } + +#ifdef __MACOS__ + cmd->rightmove = ClampChar( cmd->rightmove + cl.joystickAxis[AXIS_SIDE] ); +#else +#ifdef PANDORA + if ( kb[KB_STRAFE].active ) { +#else + if ( !kb[KB_STRAFE].active ) { +#endif + cl.viewangles[YAW] += anglespeed * cl_yawspeed->value * cl.joystickAxis[AXIS_SIDE]; + } else { + cmd->rightmove = ClampChar( cmd->rightmove + cl.joystickAxis[AXIS_SIDE] ); + } +#endif + if ( kb[KB_MLOOK].active ) { + cl.viewangles[PITCH] += anglespeed * cl_pitchspeed->value * cl.joystickAxis[AXIS_FORWARD]; + } else { + cmd->forwardmove = ClampChar( cmd->forwardmove + cl.joystickAxis[AXIS_FORWARD] ); + } + + cmd->upmove = ClampChar( cmd->upmove + cl.joystickAxis[AXIS_UP] ); +} + +/* +================= +CL_MouseMove +================= +*/ +void CL_MouseMove( usercmd_t *cmd ) { + float mx, my; + float accelSensitivity; + float rate; +#ifdef AUTOAIM + int g_lastFireTime = 0; + int cg_crossHairStatus = 0/*(serverCursorHint==HINT_PLYR_ENEMY)?1:0*/; + + g_lastFireTime = cl.cgameLastFireTime; + cg_crossHairStatus = cl.cgameCrossHairStatus; + +#endif + + // allow mouse smoothing + if ( m_filter->integer ) { + mx = ( cl.mouseDx[0] + cl.mouseDx[1] ) * 0.5; + my = ( cl.mouseDy[0] + cl.mouseDy[1] ) * 0.5; + } else { + mx = cl.mouseDx[cl.mouseIndex]; + my = cl.mouseDy[cl.mouseIndex]; + } +#ifdef AUTOAIM + const float m_hoverSensitivity = 0.2f; + if (cg_crossHairStatus != 0) + { + mx *= m_hoverSensitivity; + my *= m_hoverSensitivity; + } +#endif + cl.mouseIndex ^= 1; + cl.mouseDx[cl.mouseIndex] = 0; + cl.mouseDy[cl.mouseIndex] = 0; + +#ifdef AUTOAIM + if (cg_crossHairStatus) + rate = 0; + else +#endif + rate = sqrt( mx * mx + my * my ) / (float)frame_msec; + accelSensitivity = cl_sensitivity->value + rate * cl_mouseAccel->value; + + // scale by FOV + accelSensitivity *= cl.cgameSensitivity; + +/* NERVE - SMF - this has moved to CG_CalcFov to fix zoomed-in/out transition movement bug + if ( cl.snap.ps.stats[STAT_ZOOMED_VIEW] ) { + if(cl.snap.ps.weapon == WP_SNIPERRIFLE) { + accelSensitivity *= 0.1; + } + else if(cl.snap.ps.weapon == WP_SNOOPERSCOPE) { + accelSensitivity *= 0.2; + } + } +*/ + if ( rate && cl_showMouseRate->integer ) { + Com_Printf( "%f : %f\n", rate, accelSensitivity ); + } + +// Ridah, experimenting with a slow tracking gun + + // Rafael - mg42 + if ( cl.snap.ps.persistant[PERS_HWEAPON_USE] ) { + mx *= 2.5f; //(accelSensitivity * 0.1); + #ifdef PANDORA + my *= 1.25f; //(accelSensitivity * 0.075); + #else + my *= 2; //(accelSensitivity * 0.075); + #endif + } else + { + mx *= accelSensitivity; + #ifdef PANDORA + my *= accelSensitivity*0.5f; + #else + my *= accelSensitivity; + #endif + } + + if ( !mx && !my ) { +#ifdef AUTOAIM0 + // If there was a movement but no change in angles then start auto-leveling the camera + float autolevelSpeed = 0.03f; + + if (cg_crossHairStatus != 1 && // Not looking at an enemy + cl.joystickAxis[AXIS_FORWARD] && // Moving forward/backward + cl.frame.ps.groundEntityNum != ENTITYNUM_NONE && // Not in the air + Cvar_VariableIntegerValue("cl_autolevel") && // Autolevel is turned on + g_lastFireTime < Sys_Milliseconds() - 1000) // Haven't fired recently + { + float normAngle = -SHORT2ANGLE(cl.frame.ps.delta_angles[PITCH]); + // The adjustment to normAngle below is meant to add or remove some multiple + // of 360, so that normAngle is within 180 of viewangles[PITCH]. It should + // be correct. + int diff = (int)(cl.viewangles[PITCH] - normAngle); + if (diff > 180) + normAngle += 360.0f * ((diff+180) / 360); + else if (diff < -180) + normAngle -= 360.0f * ((-diff+180) / 360); + + if (Cvar_VariableIntegerValue("cg_thirdperson") == 1) + { +// normAngle += 10; // Removed by BTO, 2003/05/14, I hate it + autolevelSpeed *= 1.5f; + } + if (cl.viewangles[PITCH] > normAngle) + { + cl.viewangles[PITCH] -= autolevelSpeed * speed; + if (cl.viewangles[PITCH] < normAngle) cl.viewangles[PITCH] = normAngle; + } + else if (cl.viewangles[PITCH] < normAngle) + { + cl.viewangles[PITCH] += autolevelSpeed * speed; + if (cl.viewangles[PITCH] > normAngle) cl.viewangles[PITCH] = normAngle; + } + } +#endif + return; + } + +#ifdef AUTOAIM0 + const float cl_pitchSensitivity = 0.5f; +#else + const float cl_pitchSensitivity = 1.0f; +#endif + // add mouse X/Y movement to cmd + if ( kb[KB_STRAFE].active ) { + cmd->rightmove = ClampChar( cmd->rightmove + m_side->value * mx * cl_pitchSensitivity); + } else { + cl.viewangles[YAW] -= m_yaw->value * mx * cl_pitchSensitivity; + } + + if ( ( kb[KB_MLOOK].active || cl_freelook->integer ) && !kb[KB_STRAFE].active ) { + cl.viewangles[PITCH] += m_pitch->value * my * cl_pitchSensitivity; + } else { + cmd->forwardmove = ClampChar( cmd->forwardmove - m_forward->value * my ); + } +} + + +/* +============== +CL_CmdButtons +============== +*/ +void CL_CmdButtons( usercmd_t *cmd ) { + int i; + + // + // figure button bits + // send a button bit even if the key was pressed and released in + // less than a frame + // + for ( i = 0 ; i < 7 ; i++ ) { + if ( kb[KB_BUTTONS0 + i].active || kb[KB_BUTTONS0 + i].wasPressed ) { + cmd->buttons |= 1 << i; + } + kb[KB_BUTTONS0 + i].wasPressed = qfalse; + } + + for ( i = 0 ; i < 7 ; i++ ) { + if ( kb[KB_WBUTTONS0 + i].active || kb[KB_WBUTTONS0 + i].wasPressed ) { + cmd->wbuttons |= 1 << i; + } + kb[KB_WBUTTONS0 + i].wasPressed = qfalse; + } + + if ( cls.keyCatchers ) { + cmd->buttons |= BUTTON_TALK; + } + + // allow the game to know if any key at all is + // currently pressed, even if it isn't bound to anything + if ( anykeydown && !cls.keyCatchers ) { + cmd->buttons |= BUTTON_ANY; + } +} + + +/* +============== +CL_FinishMove +============== +*/ +void CL_FinishMove( usercmd_t *cmd ) { + int i; + + // copy the state that the cgame is currently sending + cmd->weapon = cl.cgameUserCmdValue; + + cmd->holdable = cl.cgameUserHoldableValue; //----(SA) modified + + // send the current server time so the amount of movement + // can be determined without allowing cheating + cmd->serverTime = cl.serverTime; + + for ( i = 0 ; i < 3 ; i++ ) { + cmd->angles[i] = ANGLE2SHORT( cl.viewangles[i] ); + } +} + +#ifdef __ANDROID__ +void CL_AndroidMove( usercmd_t *cmd ); +#endif +/* +================= +CL_CreateCmd +================= +*/ +usercmd_t CL_CreateCmd( void ) { + usercmd_t cmd; + vec3_t oldAngles; + float recoilAdd; + + VectorCopy( cl.viewangles, oldAngles ); + + // keyboard angle adjustment + CL_AdjustAngles(); + + memset( &cmd, 0, sizeof( cmd ) ); + + CL_CmdButtons( &cmd ); + + // get basic movement from keyboard + CL_KeyMove( &cmd ); + + // get basic movement from mouse + CL_MouseMove( &cmd ); + + // get basic movement from joystick + CL_JoystickMove( &cmd ); + +#ifdef __ANDROID__ + CL_AndroidMove ( &cmd ); +#endif + + // check to make sure the angles haven't wrapped + if ( cl.viewangles[PITCH] - oldAngles[PITCH] > 90 ) { + cl.viewangles[PITCH] = oldAngles[PITCH] + 90; + } else if ( oldAngles[PITCH] - cl.viewangles[PITCH] > 90 ) { + cl.viewangles[PITCH] = oldAngles[PITCH] - 90; + } + + // RF, set the kickAngles so aiming is effected + recoilAdd = cl_recoilPitch->value; + if ( fabs( cl.viewangles[PITCH] + recoilAdd ) < 40 ) { + cl.viewangles[PITCH] += recoilAdd; + } + // the recoilPitch has been used, so clear it out + cl_recoilPitch->value = 0; + + // store out the final values + CL_FinishMove( &cmd ); + + // draw debug graphs of turning for mouse testing + if ( cl_debugMove->integer ) { + if ( cl_debugMove->integer == 1 ) { + SCR_DebugGraph( abs( cl.viewangles[YAW] - oldAngles[YAW] ), 0 ); + } + if ( cl_debugMove->integer == 2 ) { + SCR_DebugGraph( abs( cl.viewangles[PITCH] - oldAngles[PITCH] ), 0 ); + } + } + + cmd.cld = cl.cgameCld; // NERVE - SMF + + return cmd; +} + + +/* +================= +CL_CreateNewCommands + +Create a new usercmd_t structure for this frame +================= +*/ +void CL_CreateNewCommands( void ) { + usercmd_t *cmd; + int cmdNum; + + // no need to create usercmds until we have a gamestate + if ( cls.state < CA_PRIMED ) { + return; + } + + frame_msec = com_frameTime - old_com_frameTime; + + // if running less than 5fps, truncate the extra time to prevent + // unexpected moves after a hitch + if ( frame_msec > 200 ) { + frame_msec = 200; + } + old_com_frameTime = com_frameTime; + + + // generate a command for this frame + cl.cmdNumber++; + cmdNum = cl.cmdNumber & CMD_MASK; + cl.cmds[cmdNum] = CL_CreateCmd(); + cmd = &cl.cmds[cmdNum]; +} + +/* +================= +CL_ReadyToSendPacket + +Returns qfalse if we are over the maxpackets limit +and should choke back the bandwidth a bit by not sending +a packet this frame. All the commands will still get +delivered in the next packet, but saving a header and +getting more delta compression will reduce total bandwidth. +================= +*/ +qboolean CL_ReadyToSendPacket( void ) { + int oldPacketNum; + int delta; + + // don't send anything if playing back a demo + if ( clc.demoplaying || cls.state == CA_CINEMATIC ) { + return qfalse; + } + + // If we are downloading, we send no less than 50ms between packets + if ( *clc.downloadTempName && + cls.realtime - clc.lastPacketSentTime < 50 ) { + return qfalse; + } + + // if we don't have a valid gamestate yet, only send + // one packet a second + if ( cls.state != CA_ACTIVE && + cls.state != CA_PRIMED && + !*clc.downloadTempName && + cls.realtime - clc.lastPacketSentTime < 1000 ) { + return qfalse; + } + + // send every frame for loopbacks + if ( clc.netchan.remoteAddress.type == NA_LOOPBACK ) { + return qtrue; + } + + // send every frame for LAN + if ( Sys_IsLANAddress( clc.netchan.remoteAddress ) ) { + return qtrue; + } + + // check for exceeding cl_maxpackets + if ( cl_maxpackets->integer < 15 ) { + Cvar_Set( "cl_maxpackets", "15" ); + } else if ( cl_maxpackets->integer > 100 ) { + Cvar_Set( "cl_maxpackets", "100" ); + } + oldPacketNum = ( clc.netchan.outgoingSequence - 1 ) & PACKET_MASK; + delta = cls.realtime - cl.outPackets[ oldPacketNum ].p_realtime; + if ( delta < 1000 / cl_maxpackets->integer ) { + // the accumulated commands will go out in the next packet + return qfalse; + } + + return qtrue; +} + +/* +=================== +CL_WritePacket + +Create and send the command packet to the server +Including both the reliable commands and the usercmds + +During normal gameplay, a client packet will contain something like: + +4 sequence number +2 qport +4 serverid +4 acknowledged sequence number +4 clc.serverCommandSequence + +1 clc_move or clc_moveNoDelta +1 command count + + +=================== +*/ +void CL_WritePacket( void ) { + msg_t buf; + byte data[MAX_MSGLEN]; + int i, j; + usercmd_t *cmd, *oldcmd; + usercmd_t nullcmd; + int packetNum; + int oldPacketNum; + int count, key; + + // don't send anything if playing back a demo + if ( clc.demoplaying || cls.state == CA_CINEMATIC ) { + return; + } + + memset( &nullcmd, 0, sizeof( nullcmd ) ); + oldcmd = &nullcmd; + + MSG_Init( &buf, data, sizeof( data ) ); + + MSG_Bitstream( &buf ); + // write the current serverId so the server + // can tell if this is from the current gameState + MSG_WriteLong( &buf, cl.serverId ); + + // write the last message we received, which can + // be used for delta compression, and is also used + // to tell if we dropped a gamestate + MSG_WriteLong( &buf, clc.serverMessageSequence ); + + // write the last reliable message we received + MSG_WriteLong( &buf, clc.serverCommandSequence ); + + // write any unacknowledged clientCommands + for ( i = clc.reliableAcknowledge + 1 ; i <= clc.reliableSequence ; i++ ) { + MSG_WriteByte( &buf, clc_clientCommand ); + MSG_WriteLong( &buf, i ); + MSG_WriteString( &buf, clc.reliableCommands[ i & ( MAX_RELIABLE_COMMANDS - 1 ) ] ); + } + + // we want to send all the usercmds that were generated in the last + // few packet, so even if a couple packets are dropped in a row, + // all the cmds will make it to the server + if ( cl_packetdup->integer < 0 ) { + Cvar_Set( "cl_packetdup", "0" ); + } else if ( cl_packetdup->integer > 5 ) { + Cvar_Set( "cl_packetdup", "5" ); + } + oldPacketNum = ( clc.netchan.outgoingSequence - 1 - cl_packetdup->integer ) & PACKET_MASK; + count = cl.cmdNumber - cl.outPackets[ oldPacketNum ].p_cmdNumber; + if ( count > MAX_PACKET_USERCMDS ) { + count = MAX_PACKET_USERCMDS; + Com_Printf( "MAX_PACKET_USERCMDS\n" ); + } + if ( count >= 1 ) { + if ( cl_showSend->integer ) { + Com_Printf( "(%i)", count ); + } + + // begin a client move command + if ( cl_nodelta->integer || !cl.snap.valid || clc.demowaiting + || clc.serverMessageSequence != cl.snap.messageNum ) { + MSG_WriteByte( &buf, clc_moveNoDelta ); + } else { + MSG_WriteByte( &buf, clc_move ); + } + + // write the command count + MSG_WriteByte( &buf, count ); + + // use the checksum feed in the key + key = clc.checksumFeed; + // also use the message acknowledge + key ^= clc.serverMessageSequence; + // also use the last acknowledged server command in the key + key ^= Com_HashKey( clc.serverCommands[ clc.serverCommandSequence & ( MAX_RELIABLE_COMMANDS - 1 ) ], 32 ); + + // write all the commands, including the predicted command + for ( i = 0 ; i < count ; i++ ) { + j = ( cl.cmdNumber - count + i + 1 ) & CMD_MASK; + cmd = &cl.cmds[j]; + MSG_WriteDeltaUsercmdKey( &buf, key, oldcmd, cmd ); + oldcmd = cmd; + } + } + + // + // deliver the message + // + packetNum = clc.netchan.outgoingSequence & PACKET_MASK; + cl.outPackets[ packetNum ].p_realtime = cls.realtime; + cl.outPackets[ packetNum ].p_serverTime = oldcmd->serverTime; + cl.outPackets[ packetNum ].p_cmdNumber = cl.cmdNumber; + clc.lastPacketSentTime = cls.realtime; + + if ( cl_showSend->integer ) { + Com_Printf( "%i ", buf.cursize ); + } +// Netchan_Transmit (&clc.netchan, buf.cursize, buf.data); + CL_Netchan_Transmit( &clc.netchan, &buf ); + + // clients never really should have messages large enough + // to fragment, but in case they do, fire them all off + // at once + while ( clc.netchan.unsentFragments ) { + CL_Netchan_TransmitNextFragment( &clc.netchan ); + } +} + +/* +================= +CL_SendCmd + +Called every frame to builds and sends a command packet to the server. +================= +*/ +void CL_SendCmd( void ) { + // don't send any message if not connected + if ( cls.state < CA_CONNECTED ) { + return; + } + + // don't send commands if paused + if ( com_sv_running->integer && sv_paused->integer && cl_paused->integer ) { + return; + } + + // we create commands even if a demo is playing, + CL_CreateNewCommands(); + + // don't send a packet if the last packet was sent too recently + if ( !CL_ReadyToSendPacket() ) { + if ( cl_showSend->integer ) { + Com_Printf( ". " ); + } + return; + } + + CL_WritePacket(); +} + +/* +============ +CL_InitInput +============ +*/ +void CL_InitInput( void ) { + Cmd_AddCommand( "centerview",IN_CenterView ); + + Cmd_AddCommand( "+moveup",IN_UpDown ); + Cmd_AddCommand( "-moveup",IN_UpUp ); + Cmd_AddCommand( "+movedown",IN_DownDown ); + Cmd_AddCommand( "-movedown",IN_DownUp ); + Cmd_AddCommand( "+left",IN_LeftDown ); + Cmd_AddCommand( "-left",IN_LeftUp ); + Cmd_AddCommand( "+right",IN_RightDown ); + Cmd_AddCommand( "-right",IN_RightUp ); + Cmd_AddCommand( "+forward",IN_ForwardDown ); + Cmd_AddCommand( "-forward",IN_ForwardUp ); + Cmd_AddCommand( "+back",IN_BackDown ); + Cmd_AddCommand( "-back",IN_BackUp ); + Cmd_AddCommand( "+lookup", IN_LookupDown ); + Cmd_AddCommand( "-lookup", IN_LookupUp ); + Cmd_AddCommand( "+lookdown", IN_LookdownDown ); + Cmd_AddCommand( "-lookdown", IN_LookdownUp ); + Cmd_AddCommand( "+strafe", IN_StrafeDown ); + Cmd_AddCommand( "-strafe", IN_StrafeUp ); + Cmd_AddCommand( "+moveleft", IN_MoveleftDown ); + Cmd_AddCommand( "-moveleft", IN_MoveleftUp ); + Cmd_AddCommand( "+moveright", IN_MoverightDown ); + Cmd_AddCommand( "-moveright", IN_MoverightUp ); + Cmd_AddCommand( "+speed", IN_SpeedDown ); + Cmd_AddCommand( "-speed", IN_SpeedUp ); + + Cmd_AddCommand( "+attack", IN_Button0Down ); // ---- id (primary firing) + Cmd_AddCommand( "-attack", IN_Button0Up ); +// Cmd_AddCommand ("+button0", IN_Button0Down); +// Cmd_AddCommand ("-button0", IN_Button0Up); + + Cmd_AddCommand( "+button1", IN_Button1Down ); + Cmd_AddCommand( "-button1", IN_Button1Up ); + + Cmd_AddCommand( "+useitem", IN_UseItemDown ); + Cmd_AddCommand( "-useitem", IN_UseItemUp ); + + Cmd_AddCommand( "+salute", IN_Button3Down ); //----(SA) salute + Cmd_AddCommand( "-salute", IN_Button3Up ); +// Cmd_AddCommand ("+button3", IN_Button3Down); +// Cmd_AddCommand ("-button3", IN_Button3Up); + + Cmd_AddCommand( "+button4", IN_Button4Down ); + Cmd_AddCommand( "-button4", IN_Button4Up ); + //Cmd_AddCommand ("+button5", IN_Button5Down); + //Cmd_AddCommand ("-button5", IN_Button5Up); + + //Cmd_AddCommand ("+button6", IN_Button6Down); + //Cmd_AddCommand ("-button6", IN_Button6Up); + + // Rafael Activate + Cmd_AddCommand( "+activate", IN_ActivateDown ); + Cmd_AddCommand( "-activate", IN_ActivateUp ); + // done. + + // Rafael Kick + Cmd_AddCommand( "+kick", IN_KickDown ); + Cmd_AddCommand( "-kick", IN_KickUp ); + // done + + Cmd_AddCommand( "+sprint", IN_SprintDown ); + Cmd_AddCommand( "-sprint", IN_SprintUp ); + + + // wolf buttons + Cmd_AddCommand( "+attack2", IN_Wbutton0Down ); //----(SA) secondary firing + Cmd_AddCommand( "-attack2", IN_Wbutton0Up ); + Cmd_AddCommand( "+zoom", IN_ZoomDown ); // + Cmd_AddCommand( "-zoom", IN_ZoomUp ); + Cmd_AddCommand( "+quickgren", IN_QuickGrenDown ); // + Cmd_AddCommand( "-quickgren", IN_QuickGrenUp ); + Cmd_AddCommand( "+reload", IN_ReloadDown ); // + Cmd_AddCommand( "-reload", IN_ReloadUp ); + Cmd_AddCommand( "+leanleft", IN_LeanLeftDown ); + Cmd_AddCommand( "-leanleft", IN_LeanLeftUp ); + Cmd_AddCommand( "+leanright", IN_LeanRightDown ); + Cmd_AddCommand( "-leanright", IN_LeanRightUp ); + Cmd_AddCommand( "+wbutton6", IN_Wbutton6Down ); // + Cmd_AddCommand( "-wbutton6", IN_Wbutton6Up ); + Cmd_AddCommand( "+wbutton7", IN_Wbutton7Down ); // + Cmd_AddCommand( "-wbutton7", IN_Wbutton7Up ); +//----(SA) end + + Cmd_AddCommand( "+mlook", IN_MLookDown ); + Cmd_AddCommand( "-mlook", IN_MLookUp ); + + Cmd_AddCommand( "notebook",IN_Notebook ); +// Cmd_AddCommand ("help",IN_Help); + + cl_nodelta = Cvar_Get( "cl_nodelta", "0", 0 ); + cl_debugMove = Cvar_Get( "cl_debugMove", "0", 0 ); +} + + +/* +============ +CL_ClearKeys +============ +*/ +void CL_ClearKeys( void ) { + memset( kb, 0, sizeof( kb ) ); +} diff --git a/Projects/Android/jni/rtcw/src/client/cl_keys.c b/Projects/Android/jni/rtcw/src/client/cl_keys.c new file mode 100644 index 0000000..997eacb --- /dev/null +++ b/Projects/Android/jni/rtcw/src/client/cl_keys.c @@ -0,0 +1,1907 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +#include "client.h" + +/* + +key up events are sent even if in console mode + +*/ + +field_t historyEditLines[COMMAND_HISTORY]; + +int nextHistoryLine; // the last line in the history buffer, not masked +int historyLine; // the line being displayed from history buffer + // will be <= nextHistoryLine + +field_t g_consoleField; +field_t chatField; +qboolean chat_team; +qboolean chat_limbo; // NERVE - SMF + +int chat_playerNum; + + +qboolean key_overstrikeMode; + +qboolean anykeydown; +qkey_t keys[MAX_KEYS]; + + +typedef struct { + char *name; + int keynum; +} keyname_t; + +qboolean UI_checkKeyExec( int key ); // NERVE - SMF + +// names not in this list can either be lowercase ascii, or '0xnn' hex sequences +keyname_t keynames[] = +{ + {"TAB", K_TAB}, + {"ENTER", K_ENTER}, + {"ESCAPE", K_ESCAPE}, + {"SPACE", K_SPACE}, + {"BACKSPACE", K_BACKSPACE}, + {"UPARROW", K_UPARROW}, + {"DOWNARROW", K_DOWNARROW}, + {"LEFTARROW", K_LEFTARROW}, + {"RIGHTARROW", K_RIGHTARROW}, + + {"ALT", K_ALT}, + {"CTRL", K_CTRL}, + {"SHIFT", K_SHIFT}, + + {"CAPSLOCK", K_CAPSLOCK}, + + + {"F1", K_F1}, + {"F2", K_F2}, + {"F3", K_F3}, + {"F4", K_F4}, + {"F5", K_F5}, + {"F6", K_F6}, + {"F7", K_F7}, + {"F8", K_F8}, + {"F9", K_F9}, + {"F10", K_F10}, + {"F11", K_F11}, + {"F12", K_F12}, + + {"INS", K_INS}, + {"DEL", K_DEL}, + {"PGDN", K_PGDN}, + {"PGUP", K_PGUP}, + {"HOME", K_HOME}, + {"END", K_END}, + + {"MOUSE1", K_MOUSE1}, + {"MOUSE2", K_MOUSE2}, + {"MOUSE3", K_MOUSE3}, + {"MOUSE4", K_MOUSE4}, + {"MOUSE5", K_MOUSE5}, + + {"MWHEELUP", K_MWHEELUP }, + {"MWHEELDOWN", K_MWHEELDOWN }, + + {"JOY1", K_JOY1}, + {"JOY2", K_JOY2}, + {"JOY3", K_JOY3}, + {"JOY4", K_JOY4}, + {"JOY5", K_JOY5}, + {"JOY6", K_JOY6}, + {"JOY7", K_JOY7}, + {"JOY8", K_JOY8}, + {"JOY9", K_JOY9}, + {"JOY10", K_JOY10}, + {"JOY11", K_JOY11}, + {"JOY12", K_JOY12}, + {"JOY13", K_JOY13}, + {"JOY14", K_JOY14}, + {"JOY15", K_JOY15}, + {"JOY16", K_JOY16}, + {"JOY17", K_JOY17}, + {"JOY18", K_JOY18}, + {"JOY19", K_JOY19}, + {"JOY20", K_JOY20}, + {"JOY21", K_JOY21}, + {"JOY22", K_JOY22}, + {"JOY23", K_JOY23}, + {"JOY24", K_JOY24}, + {"JOY25", K_JOY25}, + {"JOY26", K_JOY26}, + {"JOY27", K_JOY27}, + {"JOY28", K_JOY28}, + {"JOY29", K_JOY29}, + {"JOY30", K_JOY30}, + {"JOY31", K_JOY31}, + {"JOY32", K_JOY32}, + + {"AUX1", K_AUX1}, + {"AUX2", K_AUX2}, + {"AUX3", K_AUX3}, + {"AUX4", K_AUX4}, + {"AUX5", K_AUX5}, + {"AUX6", K_AUX6}, + {"AUX7", K_AUX7}, + {"AUX8", K_AUX8}, + {"AUX9", K_AUX9}, + {"AUX10", K_AUX10}, + {"AUX11", K_AUX11}, + {"AUX12", K_AUX12}, + {"AUX13", K_AUX13}, + {"AUX14", K_AUX14}, + {"AUX15", K_AUX15}, + {"AUX16", K_AUX16}, + + {"KP_HOME", K_KP_HOME }, + {"KP_UPARROW", K_KP_UPARROW }, + {"KP_PGUP", K_KP_PGUP }, + {"KP_LEFTARROW", K_KP_LEFTARROW }, + {"KP_5", K_KP_5 }, + {"KP_RIGHTARROW", K_KP_RIGHTARROW }, + {"KP_END", K_KP_END }, + {"KP_DOWNARROW", K_KP_DOWNARROW }, + {"KP_PGDN", K_KP_PGDN }, + {"KP_ENTER", K_KP_ENTER }, + {"KP_INS", K_KP_INS }, + {"KP_DEL", K_KP_DEL }, + {"KP_SLASH", K_KP_SLASH }, + {"KP_MINUS", K_KP_MINUS }, + {"KP_PLUS", K_KP_PLUS }, + {"KP_NUMLOCK", K_KP_NUMLOCK }, + {"KP_STAR", K_KP_STAR }, + {"KP_EQUALS", K_KP_EQUALS }, + + {"PAUSE", K_PAUSE}, + + {"SEMICOLON", ';'}, // because a raw semicolon seperates commands + + {"COMMAND", K_COMMAND}, //mac + + {NULL,0} +}; + +keyname_t keynames_d[] = //deutsch +{ + {"TAB", K_TAB}, + {"EINGABETASTE", K_ENTER}, + {"ESC", K_ESCAPE}, + {"LEERTASTE", K_SPACE}, + {"RÜCKTASTE", K_BACKSPACE}, + {"PFEILT.AUF", K_UPARROW}, + {"PFEILT.UNTEN", K_DOWNARROW}, + {"PFEILT.LINKS", K_LEFTARROW}, + {"PFEILT.RECHTS", K_RIGHTARROW}, + + {"ALT", K_ALT}, + {"STRG", K_CTRL}, + {"UMSCHALT", K_SHIFT}, // (SA) removed one 'L' for laird 11/15/01 + + {"FESTSTELLT", K_CAPSLOCK}, + + {"F1", K_F1}, + {"F2", K_F2}, + {"F3", K_F3}, + {"F4", K_F4}, + {"F5", K_F5}, + {"F6", K_F6}, + {"F7", K_F7}, + {"F8", K_F8}, + {"F9", K_F9}, + {"F10", K_F10}, + {"F11", K_F11}, + {"F12", K_F12}, + + {"EINFG", K_INS}, + {"ENTF", K_DEL}, + {"BILD-AB", K_PGDN}, + {"BILD-AUF", K_PGUP}, + {"POS1", K_HOME}, + {"ENDE", K_END}, + + {"MAUS1", K_MOUSE1}, + {"MAUS2", K_MOUSE2}, + {"MAUS3", K_MOUSE3}, + {"MAUS4", K_MOUSE4}, + {"MAUS5", K_MOUSE5}, + + {"MRADOBEN", K_MWHEELUP }, + {"MRADUNTEN", K_MWHEELDOWN }, + + {"JOY1", K_JOY1}, + {"JOY2", K_JOY2}, + {"JOY3", K_JOY3}, + {"JOY4", K_JOY4}, + {"JOY5", K_JOY5}, + {"JOY6", K_JOY6}, + {"JOY7", K_JOY7}, + {"JOY8", K_JOY8}, + {"JOY9", K_JOY9}, + {"JOY10", K_JOY10}, + {"JOY11", K_JOY11}, + {"JOY12", K_JOY12}, + {"JOY13", K_JOY13}, + {"JOY14", K_JOY14}, + {"JOY15", K_JOY15}, + {"JOY16", K_JOY16}, + {"JOY17", K_JOY17}, + {"JOY18", K_JOY18}, + {"JOY19", K_JOY19}, + {"JOY20", K_JOY20}, + {"JOY21", K_JOY21}, + {"JOY22", K_JOY22}, + {"JOY23", K_JOY23}, + {"JOY24", K_JOY24}, + {"JOY25", K_JOY25}, + {"JOY26", K_JOY26}, + {"JOY27", K_JOY27}, + {"JOY28", K_JOY28}, + {"JOY29", K_JOY29}, + {"JOY30", K_JOY30}, + {"JOY31", K_JOY31}, + {"JOY32", K_JOY32}, + + {"AUX1", K_AUX1}, + {"AUX2", K_AUX2}, + {"AUX3", K_AUX3}, + {"AUX4", K_AUX4}, + {"AUX5", K_AUX5}, + {"AUX6", K_AUX6}, + {"AUX7", K_AUX7}, + {"AUX8", K_AUX8}, + {"AUX9", K_AUX9}, + {"AUX10", K_AUX10}, + {"AUX11", K_AUX11}, + {"AUX12", K_AUX12}, + {"AUX13", K_AUX13}, + {"AUX14", K_AUX14}, + {"AUX15", K_AUX15}, + {"AUX16", K_AUX16}, + + {"ZB_POS1", K_KP_HOME }, + {"ZB_PFEILT.AUF", K_KP_UPARROW }, + {"ZB_BILD-AUF", K_KP_PGUP }, + {"ZB_PFEILT.LINKS", K_KP_LEFTARROW }, + {"ZB_5", K_KP_5 }, + {"ZB_PFEILT.RECHTS",K_KP_RIGHTARROW }, + {"ZB_ENDE", K_KP_END }, + {"ZB_PFEILT.UNTEN", K_KP_DOWNARROW }, + {"ZB_BILD-AB", K_KP_PGDN }, + {"ZB_ENTER", K_KP_ENTER }, + {"ZB_EINFG", K_KP_INS }, + {"ZB_ENTF", K_KP_DEL }, + {"ZB_SLASH", K_KP_SLASH }, + {"ZB_MINUS", K_KP_MINUS }, + {"ZB_PLUS", K_KP_PLUS }, + {"ZB_NUM", K_KP_NUMLOCK }, + {"ZB_*", K_KP_STAR }, + {"ZB_EQUALS", K_KP_EQUALS }, + + {"PAUSE", K_PAUSE}, + + {"COMMAND", K_COMMAND}, //mac + {NULL,0} +}; //end german + +keyname_t keynames_f[] = //french +{ + {"TAB", K_TAB}, + {"ENTREE", K_ENTER}, + {"ECHAP", K_ESCAPE}, + {"ESPACE", K_SPACE}, + {"RETOUR", K_BACKSPACE}, + {"HAUT", K_UPARROW}, + {"BAS", K_DOWNARROW}, + {"GAUCHE", K_LEFTARROW}, + {"DROITE", K_RIGHTARROW}, + + {"ALT", K_ALT}, + {"CTRL", K_CTRL}, + {"MAJ", K_SHIFT}, + + {"VERRMAJ", K_CAPSLOCK}, + + {"F1", K_F1}, + {"F2", K_F2}, + {"F3", K_F3}, + {"F4", K_F4}, + {"F5", K_F5}, + {"F6", K_F6}, + {"F7", K_F7}, + {"F8", K_F8}, + {"F9", K_F9}, + {"F10", K_F10}, + {"F11", K_F11}, + {"F12", K_F12}, + + {"INSER", K_INS}, + {"SUPPR", K_DEL}, + {"PGBAS", K_PGDN}, + {"PGHAUT", K_PGUP}, + {"ORIGINE", K_HOME}, + {"FIN", K_END}, + + {"SOURIS1", K_MOUSE1}, + {"SOURIS2", K_MOUSE2}, + {"SOURIS3", K_MOUSE3}, + {"SOURIS4", K_MOUSE4}, + {"SOURIS5", K_MOUSE5}, + + {"MOLETTEHT.", K_MWHEELUP }, + {"MOLETTEBAS", K_MWHEELDOWN }, + + {"JOY1", K_JOY1}, + {"JOY2", K_JOY2}, + {"JOY3", K_JOY3}, + {"JOY4", K_JOY4}, + {"JOY5", K_JOY5}, + {"JOY6", K_JOY6}, + {"JOY7", K_JOY7}, + {"JOY8", K_JOY8}, + {"JOY9", K_JOY9}, + {"JOY10", K_JOY10}, + {"JOY11", K_JOY11}, + {"JOY12", K_JOY12}, + {"JOY13", K_JOY13}, + {"JOY14", K_JOY14}, + {"JOY15", K_JOY15}, + {"JOY16", K_JOY16}, + {"JOY17", K_JOY17}, + {"JOY18", K_JOY18}, + {"JOY19", K_JOY19}, + {"JOY20", K_JOY20}, + {"JOY21", K_JOY21}, + {"JOY22", K_JOY22}, + {"JOY23", K_JOY23}, + {"JOY24", K_JOY24}, + {"JOY25", K_JOY25}, + {"JOY26", K_JOY26}, + {"JOY27", K_JOY27}, + {"JOY28", K_JOY28}, + {"JOY29", K_JOY29}, + {"JOY30", K_JOY30}, + {"JOY31", K_JOY31}, + {"JOY32", K_JOY32}, + + {"AUX1", K_AUX1}, + {"AUX2", K_AUX2}, + {"AUX3", K_AUX3}, + {"AUX4", K_AUX4}, + {"AUX5", K_AUX5}, + {"AUX6", K_AUX6}, + {"AUX7", K_AUX7}, + {"AUX8", K_AUX8}, + {"AUX9", K_AUX9}, + {"AUX10", K_AUX10}, + {"AUX11", K_AUX11}, + {"AUX12", K_AUX12}, + {"AUX13", K_AUX13}, + {"AUX14", K_AUX14}, + {"AUX15", K_AUX15}, + {"AUX16", K_AUX16}, + + {"PN_ORIGINE", K_KP_HOME }, + {"PN_HAUT", K_KP_UPARROW }, + {"PN_PGBAS", K_KP_PGUP }, + {"PN_GAUCHE", K_KP_LEFTARROW }, + {"PN_5", K_KP_5 }, + {"PN_DROITE", K_KP_RIGHTARROW }, + {"PN_FIN", K_KP_END }, + {"PN_BAS", K_KP_DOWNARROW }, + {"PN_PGBAS", K_KP_PGDN }, + {"PN_ENTR", K_KP_ENTER }, + {"PN_INSER", K_KP_INS }, + {"PN_SUPPR", K_KP_DEL }, + {"PN_SLASH", K_KP_SLASH }, + {"PN_MOINS", K_KP_MINUS }, + {"PN_PLUS", K_KP_PLUS }, + {"PN_VERRNUM", K_KP_NUMLOCK }, + {"PN_*", K_KP_STAR }, + {"PN_EQUALS", K_KP_EQUALS }, + + {"PAUSE", K_PAUSE}, + + {"COMMAND", K_COMMAND}, //mac + + {NULL,0} +}; //end french + +keyname_t keynames_s[] = //Spanish - Updated 11/5 +{ + {"TABULADOR", K_TAB}, + {"INTRO", K_ENTER}, + {"ESC", K_ESCAPE}, + {"BARRA_ESPACIAD", K_SPACE}, + {"RETROCESO", K_BACKSPACE}, + {"CURSOR_ARRIBA", K_UPARROW}, + {"CURSOR_ABAJO", K_DOWNARROW}, + {"CURSOR_IZQDA", K_LEFTARROW}, + {"CURSOR_DERECHA", K_RIGHTARROW}, + + {"ALT", K_ALT}, + {"CTRL", K_CTRL}, + {"MAYÚS", K_SHIFT}, + + {"BLOQ_MAYÚS", K_CAPSLOCK}, + + {"F1", K_F1}, + {"F2", K_F2}, + {"F3", K_F3}, + {"F4", K_F4}, + {"F5", K_F5}, + {"F6", K_F6}, + {"F7", K_F7}, + {"F8", K_F8}, + {"F9", K_F9}, + {"F10", K_F10}, + {"F11", K_F11}, + {"F12", K_F12}, + + {"INSERT", K_INS}, + {"SUPR", K_DEL}, + {"AV_PÁG", K_PGDN}, + {"RE_PÁG", K_PGUP}, + {"INICIO", K_HOME}, + {"FIN", K_END}, + + {"RATÓN1", K_MOUSE1}, + {"RATÓN2", K_MOUSE2}, + {"RATÓN3", K_MOUSE3}, + {"RATÓN4", K_MOUSE4}, + {"RATÓN5", K_MOUSE5}, + + {"RUEDA_HACIA_ARRIBA", K_MWHEELUP }, + {"RUEDA_HACIA_ABAJO", K_MWHEELDOWN }, + + {"JOY1", K_JOY1}, + {"JOY2", K_JOY2}, + {"JOY3", K_JOY3}, + {"JOY4", K_JOY4}, + {"JOY5", K_JOY5}, + {"JOY6", K_JOY6}, + {"JOY7", K_JOY7}, + {"JOY8", K_JOY8}, + {"JOY9", K_JOY9}, + {"JOY10", K_JOY10}, + {"JOY11", K_JOY11}, + {"JOY12", K_JOY12}, + {"JOY13", K_JOY13}, + {"JOY14", K_JOY14}, + {"JOY15", K_JOY15}, + {"JOY16", K_JOY16}, + {"JOY17", K_JOY17}, + {"JOY18", K_JOY18}, + {"JOY19", K_JOY19}, + {"JOY20", K_JOY20}, + {"JOY21", K_JOY21}, + {"JOY22", K_JOY22}, + {"JOY23", K_JOY23}, + {"JOY24", K_JOY24}, + {"JOY25", K_JOY25}, + {"JOY26", K_JOY26}, + {"JOY27", K_JOY27}, + {"JOY28", K_JOY28}, + {"JOY29", K_JOY29}, + {"JOY30", K_JOY30}, + {"JOY31", K_JOY31}, + {"JOY32", K_JOY32}, + + {"AUX1", K_AUX1}, + {"AUX2", K_AUX2}, + {"AUX3", K_AUX3}, + {"AUX4", K_AUX4}, + {"AUX5", K_AUX5}, + {"AUX6", K_AUX6}, + {"AUX7", K_AUX7}, + {"AUX8", K_AUX8}, + {"AUX9", K_AUX9}, + {"AUX10", K_AUX10}, + {"AUX11", K_AUX11}, + {"AUX12", K_AUX12}, + {"AUX13", K_AUX13}, + {"AUX14", K_AUX14}, + {"AUX15", K_AUX15}, + {"AUX16", K_AUX16}, + + {"INICIO(NUM)", K_KP_HOME }, + {"ARRIBA(NUM)", K_KP_UPARROW }, + {"RE_PÁG(NUM)", K_KP_PGUP }, + {"IZQUIERDA(NUM)", K_KP_LEFTARROW }, + {"5(NUM)", K_KP_5 }, + {"DERECHA(NUM)", K_KP_RIGHTARROW }, + {"FIN(NUM)", K_KP_END }, + {"ABAJO(NUM)", K_KP_DOWNARROW }, + {"AV_PÁG(NUM)", K_KP_PGDN }, + {"INTRO(NUM)", K_KP_ENTER }, + {"INS(NUM)", K_KP_INS }, + {"SUPR(NUM)", K_KP_DEL }, + {"/(NUM)", K_KP_SLASH }, + {"-(NUM)", K_KP_MINUS }, + {"+(NUM)", K_KP_PLUS }, + {"BLOQ_NUM", K_KP_NUMLOCK }, + {"*(NUM)", K_KP_STAR }, + {"INTRO(NUM)", K_KP_EQUALS }, + + {"PAUSA", K_PAUSE}, + + {"PUNTO_Y_COMA", ';'}, // because a raw semicolon seperates commands + + {"COMANDO", K_COMMAND}, //mac + + {NULL,0} +}; + + +keyname_t keynames_i[] = //Italian +{ + {"TAB", K_TAB}, + {"INVIO", K_ENTER}, + {"ESC", K_ESCAPE}, + {"SPAZIO", K_SPACE}, + {"BACKSPACE", K_BACKSPACE}, + {"FRECCIASU", K_UPARROW}, + {"FRECCIAGIÙ", K_DOWNARROW}, + {"FRECCIASX", K_LEFTARROW}, + {"FRECCIADX", K_RIGHTARROW}, + + {"ALT", K_ALT}, + {"CTRL", K_CTRL}, + {"MAIUSC", K_SHIFT}, + + {"BLOCMAIUSC", K_CAPSLOCK}, + + {"F1", K_F1}, + {"F2", K_F2}, + {"F3", K_F3}, + {"F4", K_F4}, + {"F5", K_F5}, + {"F6", K_F6}, + {"F7", K_F7}, + {"F8", K_F8}, + {"F9", K_F9}, + {"F10", K_F10}, + {"F11", K_F11}, + {"F12", K_F12}, + + {"INS", K_INS}, + {"CANC", K_DEL}, + {"PAGGIÙ", K_PGDN}, + {"PAGGSU", K_PGUP}, + {"HOME", K_HOME}, + {"FINE", K_END}, + + {"MOUSE1", K_MOUSE1}, + {"MOUSE2", K_MOUSE2}, + {"MOUSE3", K_MOUSE3}, + {"MOUSE4", K_MOUSE4}, + {"MOUSE5", K_MOUSE5}, + + {"ROTELLASU", K_MWHEELUP }, + {"ROTELLAGIÙ", K_MWHEELDOWN }, + + {"JOY1", K_JOY1}, + {"JOY2", K_JOY2}, + {"JOY3", K_JOY3}, + {"JOY4", K_JOY4}, + {"JOY5", K_JOY5}, + {"JOY6", K_JOY6}, + {"JOY7", K_JOY7}, + {"JOY8", K_JOY8}, + {"JOY9", K_JOY9}, + {"JOY10", K_JOY10}, + {"JOY11", K_JOY11}, + {"JOY12", K_JOY12}, + {"JOY13", K_JOY13}, + {"JOY14", K_JOY14}, + {"JOY15", K_JOY15}, + {"JOY16", K_JOY16}, + {"JOY17", K_JOY17}, + {"JOY18", K_JOY18}, + {"JOY19", K_JOY19}, + {"JOY20", K_JOY20}, + {"JOY21", K_JOY21}, + {"JOY22", K_JOY22}, + {"JOY23", K_JOY23}, + {"JOY24", K_JOY24}, + {"JOY25", K_JOY25}, + {"JOY26", K_JOY26}, + {"JOY27", K_JOY27}, + {"JOY28", K_JOY28}, + {"JOY29", K_JOY29}, + {"JOY30", K_JOY30}, + {"JOY31", K_JOY31}, + {"JOY32", K_JOY32}, + + {"AUX1", K_AUX1}, + {"AUX2", K_AUX2}, + {"AUX3", K_AUX3}, + {"AUX4", K_AUX4}, + {"AUX5", K_AUX5}, + {"AUX6", K_AUX6}, + {"AUX7", K_AUX7}, + {"AUX8", K_AUX8}, + {"AUX9", K_AUX9}, + {"AUX10", K_AUX10}, + {"AUX11", K_AUX11}, + {"AUX12", K_AUX12}, + {"AUX13", K_AUX13}, + {"AUX14", K_AUX14}, + {"AUX15", K_AUX15}, + {"AUX16", K_AUX16}, + + {"TN_HOME", K_KP_HOME }, + {"TN_FRECCIASU", K_KP_UPARROW }, + {"TN_PAGGSU", K_KP_PGUP }, + {"TN_FRECCIASX", K_KP_LEFTARROW }, + {"TN_5", K_KP_5 }, + {"TN_FRECCIA_DX", K_KP_RIGHTARROW }, + {"TN_FINE", K_KP_END }, + {"TN_FRECCIAGIÙ", K_KP_DOWNARROW }, + {"TN_PAGGIÙ", K_KP_PGDN }, + {"TN_INVIO", K_KP_ENTER }, + {"TN_INS", K_KP_INS }, + {"TN_CANC", K_KP_DEL }, + {"TN_/", K_KP_SLASH }, + {"TN_-", K_KP_MINUS }, + {"TN_+", K_KP_PLUS }, + {"TN_BLOCNUM", K_KP_NUMLOCK }, + {"TN_*", K_KP_STAR }, + {"TN_=", K_KP_EQUALS }, + + {"PAUSA", K_PAUSE}, + + {"ò", ';'}, // because a raw semicolon seperates commands + + {"COMMAND", K_COMMAND}, //mac + + {NULL,0} +}; + +/* +============================================================================= + +EDIT FIELDS + +============================================================================= +*/ + + +/* +=================== +Field_Draw + +Handles horizontal scrolling and cursor blinking +x, y, amd width are in pixels +=================== +*/ +void Field_VariableSizeDraw( field_t *edit, int x, int y, int width, int size, qboolean showCursor ) { + int len; + int drawLen; + int prestep; + int cursorChar; + char str[MAX_STRING_CHARS]; + int i; + + drawLen = edit->widthInChars; + len = strlen( edit->buffer ) + 1; + + // guarantee that cursor will be visible + if ( len <= drawLen ) { + prestep = 0; + } else { + if ( edit->scroll + drawLen > len ) { + edit->scroll = len - drawLen; + if ( edit->scroll < 0 ) { + edit->scroll = 0; + } + } + prestep = edit->scroll; + +/* + if ( edit->cursor < len - drawLen ) { + prestep = edit->cursor; // cursor at start + } else { + prestep = len - drawLen; + } +*/ + } + + if ( prestep + drawLen > len ) { + drawLen = len - prestep; + } + + // extract characters from the field at + if ( drawLen >= MAX_STRING_CHARS ) { + Com_Error( ERR_DROP, "drawLen >= MAX_STRING_CHARS" ); + } + + memcpy( str, edit->buffer + prestep, drawLen ); + str[ drawLen ] = 0; + + // draw it + if ( size == SMALLCHAR_WIDTH ) { + float color[4]; + + color[0] = color[1] = color[2] = color[3] = 1.0; + SCR_DrawSmallStringExt( x, y, str, color, qfalse ); + } else { + // draw big string with drop shadow + SCR_DrawBigString( x, y, str, 1.0 ); + } + + // draw the cursor + if ( !showCursor ) { + return; + } + + if ( (int)( cls.realtime >> 8 ) & 1 ) { + return; // off blink + } + + if ( key_overstrikeMode ) { + cursorChar = 11; + } else { + cursorChar = 10; + } + + i = drawLen - ( Q_PrintStrlen( str ) + 1 ); + + if ( size == SMALLCHAR_WIDTH ) { + SCR_DrawSmallChar( x + ( edit->cursor - prestep - i ) * size, y, cursorChar ); + } else { + str[0] = cursorChar; + str[1] = 0; + SCR_DrawBigString( x + ( edit->cursor - prestep - i ) * size, y, str, 1.0 ); + + } +} + +void Field_Draw( field_t *edit, int x, int y, int width, qboolean showCursor ) { + Field_VariableSizeDraw( edit, x, y, width, SMALLCHAR_WIDTH, showCursor ); +} + +void Field_BigDraw( field_t *edit, int x, int y, int width, qboolean showCursor ) { + Field_VariableSizeDraw( edit, x, y, width, BIGCHAR_WIDTH, showCursor ); +} + +/* +================ +Field_Paste +================ +*/ +void Field_Paste( field_t *edit ) { + char *cbd; + int pasteLen, i; + + cbd = Sys_GetClipboardData(); + + if ( !cbd ) { + return; + } + + // send as if typed, so insert / overstrike works properly + pasteLen = strlen( cbd ); + for ( i = 0 ; i < pasteLen ; i++ ) { + Field_CharEvent( edit, cbd[i] ); + } + + free( cbd ); +} + +/* +================= +Field_KeyDownEvent + +Performs the basic line editing functions for the console, +in-game talk, and menu fields + +Key events are used for non-printable characters, others are gotten from char events. +================= +*/ +void Field_KeyDownEvent( field_t *edit, int key ) { + int len; + + // shift-insert is paste + if ( ( ( key == K_INS ) || ( key == K_KP_INS ) ) && keys[K_SHIFT].down ) { + Field_Paste( edit ); + return; + } + + len = strlen( edit->buffer ); + + if ( key == K_DEL ) { + if ( edit->cursor < len ) { + memmove( edit->buffer + edit->cursor, + edit->buffer + edit->cursor + 1, len - edit->cursor ); + } + return; + } + + if ( key == K_RIGHTARROW ) { + if ( edit->cursor < len ) { + edit->cursor++; + } + + if ( edit->cursor >= edit->scroll + edit->widthInChars && edit->cursor <= len ) { + edit->scroll++; + } + return; + } + + if ( key == K_LEFTARROW ) { + if ( edit->cursor > 0 ) { + edit->cursor--; + } + if ( edit->cursor < edit->scroll ) { + edit->scroll--; + } + return; + } + + if ( key == K_HOME || ( tolower( key ) == 'a' && keys[K_CTRL].down ) ) { + edit->cursor = 0; + return; + } + + if ( key == K_END || ( tolower( key ) == 'e' && keys[K_CTRL].down ) ) { + edit->cursor = len; + return; + } + + if ( key == K_INS ) { + key_overstrikeMode = !key_overstrikeMode; + return; + } +} + +/* +================== +Field_CharEvent +================== +*/ +void Field_CharEvent( field_t *edit, int ch ) { + int len; + + if ( ch == 'v' - 'a' + 1 ) { // ctrl-v is paste + Field_Paste( edit ); + return; + } + + if ( ch == 'c' - 'a' + 1 ) { // ctrl-c clears the field + Field_Clear( edit ); + return; + } + + len = strlen( edit->buffer ); + + if ( ch == 'h' - 'a' + 1 ) { // ctrl-h is backspace + if ( edit->cursor > 0 ) { + memmove( edit->buffer + edit->cursor - 1, + edit->buffer + edit->cursor, len + 1 - edit->cursor ); + edit->cursor--; + if ( edit->cursor < edit->scroll ) { + edit->scroll--; + } + } + return; + } + + if ( ch == 'a' - 'a' + 1 ) { // ctrl-a is home + edit->cursor = 0; + edit->scroll = 0; + return; + } + + if ( ch == 'e' - 'a' + 1 ) { // ctrl-e is end + edit->cursor = len; + edit->scroll = edit->cursor - edit->widthInChars; + return; + } + + // + // ignore any other non printable chars + // + if ( ch < 32 ) { + return; + } + + if ( key_overstrikeMode ) { + if ( edit->cursor == MAX_EDIT_LINE - 1 ) { + return; + } + edit->buffer[edit->cursor] = ch; + edit->cursor++; + } else { // insert mode + if ( len == MAX_EDIT_LINE - 1 ) { + return; // all full + } + memmove( edit->buffer + edit->cursor + 1, + edit->buffer + edit->cursor, len + 1 - edit->cursor ); + edit->buffer[edit->cursor] = ch; + edit->cursor++; + } + + + if ( edit->cursor >= edit->widthInChars ) { + edit->scroll++; + } + + if ( edit->cursor == len + 1 ) { + edit->buffer[edit->cursor] = 0; + } +} + +/* +============================================================================= + +CONSOLE LINE EDITING + +============================================================================== +*/ + +static const char *completionString; +static char shortestMatch[MAX_TOKEN_CHARS]; +static int matchCount; + +/* +=============== +FindMatches + +=============== +*/ +static void FindMatches( const char *s ) { + int i; + + if ( Q_stricmpn( s, completionString, strlen( completionString ) ) ) { + return; + } + matchCount++; + if ( matchCount == 1 ) { + Q_strncpyz( shortestMatch, s, sizeof( shortestMatch ) ); + return; + } + + // cut shortestMatch to the amount common with s + for ( i = 0 ; s[i] ; i++ ) { + if ( tolower( shortestMatch[i] ) != tolower( s[i] ) ) { + shortestMatch[i] = 0; + } + } +} + +/* +=============== +PrintMatches + +=============== +*/ +static void PrintMatches( const char *s ) { + if ( !Q_stricmpn( s, shortestMatch, strlen( shortestMatch ) ) ) { + Com_Printf( " %s\n", s ); + } +} + +static void keyConcatArgs( void ) { + int i; + char *arg; + + for ( i = 1 ; i < Cmd_Argc() ; i++ ) { + Q_strcat( g_consoleField.buffer, sizeof( g_consoleField.buffer ), " " ); + arg = Cmd_Argv( i ); + while ( *arg ) { + if ( *arg == ' ' ) { + Q_strcat( g_consoleField.buffer, sizeof( g_consoleField.buffer ), "\"" ); + break; + } + arg++; + } + Q_strcat( g_consoleField.buffer, sizeof( g_consoleField.buffer ), Cmd_Argv( i ) ); + if ( *arg == ' ' ) { + Q_strcat( g_consoleField.buffer, sizeof( g_consoleField.buffer ), "\"" ); + } + } +} + +static void ConcatRemaining( const char *src, const char *start ) { + char *str; + + str = strstr( src, start ); + if ( !str ) { + keyConcatArgs(); + return; + } + + str += strlen( start ); + Q_strcat( g_consoleField.buffer, sizeof( g_consoleField.buffer ), str ); +} + + +/* +=============== +CompleteCommand + +Tab expansion +=============== +*/ +static void CompleteCommand( void ) { + field_t *edit; + field_t temp; + + edit = &g_consoleField; + + // only look at the first token for completion purposes + Cmd_TokenizeString( edit->buffer ); + + completionString = Cmd_Argv( 0 ); + if ( completionString[0] == '\\' || completionString[0] == '/' ) { + completionString++; + } + matchCount = 0; + shortestMatch[0] = 0; + + if ( strlen( completionString ) == 0 ) { + return; + } + + Cmd_CommandCompletion( FindMatches ); + Cvar_CommandCompletion( FindMatches ); + + if ( matchCount == 0 ) { + return; // no matches + } + + Com_Memcpy( &temp, edit, sizeof( field_t ) ); + + if ( matchCount == 1 ) { + Com_sprintf( edit->buffer, sizeof( edit->buffer ), "\\%s", shortestMatch ); + if ( Cmd_Argc() == 1 ) { + Q_strcat( g_consoleField.buffer, sizeof( g_consoleField.buffer ), " " ); + } else { + ConcatRemaining( temp.buffer, completionString ); + } + edit->cursor = strlen( edit->buffer ); + return; + } + + // multiple matches, complete to shortest + Com_sprintf( edit->buffer, sizeof( edit->buffer ), "\\%s", shortestMatch ); + edit->cursor = strlen( edit->buffer ); + ConcatRemaining( temp.buffer, completionString ); + + Com_Printf( "]%s\n", edit->buffer ); + + // run through again, printing matches + Cmd_CommandCompletion( PrintMatches ); + Cvar_CommandCompletion( PrintMatches ); +} + + +/* +==================== +Console_Key + +Handles history and console scrollback +==================== +*/ +void Console_Key( int key ) { + // ctrl-L clears screen + if ( key == 'l' && keys[K_CTRL].down ) { + Cbuf_AddText( "clear\n" ); + return; + } + + // enter finishes the line + if ( key == K_ENTER || key == K_KP_ENTER ) { + // if not in the game explicitly prepent a slash if needed + if ( cls.state != CA_ACTIVE && g_consoleField.buffer[0] != '\\' + && g_consoleField.buffer[0] != '/' ) { + char temp[MAX_STRING_CHARS]; + + Q_strncpyz( temp, g_consoleField.buffer, sizeof( temp ) ); + Com_sprintf( g_consoleField.buffer, sizeof( g_consoleField.buffer ), "\\%s", temp ); + g_consoleField.cursor++; + } + + Com_Printf( "]%s\n", g_consoleField.buffer ); + + // leading slash is an explicit command + if ( g_consoleField.buffer[0] == '\\' || g_consoleField.buffer[0] == '/' ) { + Cbuf_AddText( g_consoleField.buffer + 1 ); // valid command + Cbuf_AddText( "\n" ); + } else { + // other text will be chat messages + if ( !g_consoleField.buffer[0] ) { + return; // empty lines just scroll the console without adding to history + } else { + Cbuf_AddText( "cmd say " ); + Cbuf_AddText( g_consoleField.buffer ); + Cbuf_AddText( "\n" ); + } + } + + // copy line to history buffer + historyEditLines[nextHistoryLine % COMMAND_HISTORY] = g_consoleField; + nextHistoryLine++; + historyLine = nextHistoryLine; + + Field_Clear( &g_consoleField ); + + g_consoleField.widthInChars = g_console_field_width; + + if ( cls.state == CA_DISCONNECTED ) { + SCR_UpdateScreen(); // force an update, because the command + } // may take some time + return; + } + + // command completion + + if ( key == K_TAB ) { + CompleteCommand(); + return; + } + + // command history (ctrl-p ctrl-n for unix style) + + //----(SA) added some mousewheel functionality to the console + if ( ( key == K_MWHEELUP && keys[K_SHIFT].down ) || ( key == K_UPARROW ) || ( key == K_KP_UPARROW ) || + ( ( tolower( key ) == 'p' ) && keys[K_CTRL].down ) ) { + if ( nextHistoryLine - historyLine < COMMAND_HISTORY + && historyLine > 0 ) { + historyLine--; + } + g_consoleField = historyEditLines[ historyLine % COMMAND_HISTORY ]; + return; + } + + //----(SA) added some mousewheel functionality to the console + if ( ( key == K_MWHEELDOWN && keys[K_SHIFT].down ) || ( key == K_DOWNARROW ) || ( key == K_KP_DOWNARROW ) || + ( ( tolower( key ) == 'n' ) && keys[K_CTRL].down ) ) { + if ( historyLine == nextHistoryLine ) { + return; + } + historyLine++; + g_consoleField = historyEditLines[ historyLine % COMMAND_HISTORY ]; + return; + } + + // console scrolling + if ( key == K_PGUP ) { + Con_PageUp(); + return; + } + + if ( key == K_PGDN ) { + Con_PageDown(); + return; + } + + if ( key == K_MWHEELUP ) { //----(SA) added some mousewheel functionality to the console + Con_PageUp(); + if ( keys[K_CTRL].down ) { // hold to accelerate scrolling + Con_PageUp(); + Con_PageUp(); + } + return; + } + + if ( key == K_MWHEELDOWN ) { //----(SA) added some mousewheel functionality to the console + Con_PageDown(); + if ( keys[K_CTRL].down ) { // hold to accelerate scrolling + Con_PageDown(); + Con_PageDown(); + } + return; + } + + // ctrl-home = top of console + if ( key == K_HOME && keys[K_CTRL].down ) { + Con_Top(); + return; + } + + // ctrl-end = bottom of console + if ( key == K_END && keys[K_CTRL].down ) { + Con_Bottom(); + return; + } + + // pass to the normal editline routine + Field_KeyDownEvent( &g_consoleField, key ); +} + +//============================================================================ + + +/* +================ +Message_Key + +In game talk message +================ +*/ +void Message_Key( int key ) { + + char buffer[MAX_STRING_CHARS]; + + + if ( key == K_ESCAPE ) { + cls.keyCatchers &= ~KEYCATCH_MESSAGE; + Field_Clear( &chatField ); + return; + } + + if ( key == K_ENTER || key == K_KP_ENTER ) { + if ( chatField.buffer[0] && cls.state == CA_ACTIVE ) { + if ( chat_playerNum != -1 ) { + + Com_sprintf( buffer, sizeof( buffer ), "tell %i \"%s\"\n", chat_playerNum, chatField.buffer ); + } else if ( chat_team ) { + + Com_sprintf( buffer, sizeof( buffer ), "say_team \"%s\"\n", chatField.buffer ); + } + // NERVE - SMF + else if ( chat_limbo ) { + + Com_sprintf( buffer, sizeof( buffer ), "say_limbo \"%s\"\n", chatField.buffer ); + } + // -NERVE - SMF + else { + Com_sprintf( buffer, sizeof( buffer ), "say \"%s\"\n", chatField.buffer ); + } + + + + CL_AddReliableCommand( buffer ); + } + cls.keyCatchers &= ~KEYCATCH_MESSAGE; + Field_Clear( &chatField ); + return; + } + + Field_KeyDownEvent( &chatField, key ); +} + +//============================================================================ + + +qboolean Key_GetOverstrikeMode( void ) { + return key_overstrikeMode; +} + + +void Key_SetOverstrikeMode( qboolean state ) { + key_overstrikeMode = state; +} + + +/* +=================== +Key_IsDown +=================== +*/ +qboolean Key_IsDown( int keynum ) { + if ( keynum == -1 ) { + return qfalse; + } + + return keys[keynum].down; +} + + +/* +=================== +Key_StringToKeynum + +Returns a key number to be used to index keys[] by looking at +the given string. Single ascii characters return themselves, while +the K_* names are matched up. + +0x11 will be interpreted as raw hex, which will allow new controlers + +to be configured even if they don't have defined names. +=================== +*/ +int Key_StringToKeynum( char *str ) { + keyname_t *kn; + + if ( !str || !str[0] ) { + return -1; + } + if ( !str[1] ) { + return str[0]; + } + + // check for hex code + if ( str[0] == '0' && str[1] == 'x' && strlen( str ) == 4 ) { + int n1, n2; + + n1 = str[2]; + if ( Q_isnumeric( n1 ) ) { + n1 -= '0'; + } else if ( n1 >= 'a' && n1 <= 'f' ) { + n1 = n1 - 'a' + 10; + } else { + n1 = 0; + } + + n2 = str[3]; + if ( Q_isnumeric( n2 ) ) { + n2 -= '0'; + } else if ( n2 >= 'a' && n2 <= 'f' ) { + n2 = n2 - 'a' + 10; + } else { + n2 = 0; + } + + return n1 * 16 + n2; + } + + // scan for a text match + for ( kn = keynames ; kn->name ; kn++ ) { + if ( !Q_stricmp( str,kn->name ) ) { + return kn->keynum; + } + } + + return -1; +} + +/* +=================== +Key_KeynumToString + +Returns a string (either a single ascii char, a K_* name, or a 0x11 hex string) for the +given keynum. +=================== +*/ +char *Key_KeynumToString( int keynum, qboolean bTranslate ) { + keyname_t *kn; + static char tinystr[5]; + int i, j; + + if ( keynum == -1 ) { + return ""; + } + + if ( keynum < 0 || keynum > 255 ) { + return ""; + } + + // check for printable ascii (don't use quote) + if ( keynum > 32 && keynum < 127 && keynum != '"' ) { + tinystr[0] = keynum; + tinystr[1] = 0; + if ( keynum == ';' && !bTranslate ) { + //fall through and use keyname table + } else { + return tinystr; + } + } + + + kn = keynames; //init to english + if ( bTranslate ) { + if ( cl_language->integer - 1 == LANGUAGE_FRENCH ) { + kn = keynames_f; //use french + } else if ( cl_language->integer - 1 == LANGUAGE_GERMAN ) { + kn = keynames_d; //use german + } else if ( cl_language->integer - 1 == LANGUAGE_ITALIAN ) { + kn = keynames_i; //use italian + } else if ( cl_language->integer - 1 == LANGUAGE_SPANISH ) { + kn = keynames_s; //use spanish + } + } + + // check for a key string + for ( ; kn->name ; kn++ ) { + if ( keynum == kn->keynum ) { + return kn->name; + } + } + + // make a hex string + i = keynum >> 4; + j = keynum & 15; + + tinystr[0] = '0'; + tinystr[1] = 'x'; + tinystr[2] = i > 9 ? i - 10 + 'a' : i + '0'; + tinystr[3] = j > 9 ? j - 10 + 'a' : j + '0'; + tinystr[4] = 0; + + return tinystr; +} + + +/* +=================== +Key_SetBinding +=================== +*/ +void Key_SetBinding( int keynum, const char *binding ) { + if ( keynum == -1 ) { + return; + } + + // free old bindings + if ( keys[ keynum ].binding ) { + Z_Free( keys[ keynum ].binding ); + } + + // allocate memory for new binding + keys[keynum].binding = CopyString( binding ); + + + // consider this like modifying an archived cvar, so the + // file write will be triggered at the next oportunity + cvar_modifiedFlags |= CVAR_ARCHIVE; +} + + +/* +=================== +Key_GetBinding +=================== +*/ +char *Key_GetBinding( int keynum ) { + if ( keynum == -1 ) { + return ""; + } + + return keys[ keynum ].binding; +} + +/* +=================== +Key_GetKey +=================== +*/ + +int Key_GetKey( const char *binding ) { + int i; + + if ( binding ) { + for ( i = 0 ; i < 256 ; i++ ) { + if ( keys[i].binding && Q_stricmp( binding, keys[i].binding ) == 0 ) { + return i; + } + } + } + return -1; +} + +/* +=================== +Key_Unbind_f +=================== +*/ +void Key_Unbind_f( void ) { + int b; + + if ( Cmd_Argc() != 2 ) { + Com_Printf( "unbind : remove commands from a key\n" ); + return; + } + + b = Key_StringToKeynum( Cmd_Argv( 1 ) ); + if ( b == -1 ) { + Com_Printf( "\"%s\" isn't a valid key\n", Cmd_Argv( 1 ) ); + return; + } + + Key_SetBinding( b, "" ); +} + +/* +=================== +Key_Unbindall_f +=================== +*/ +void Key_Unbindall_f( void ) { + int i; + + for ( i = 0 ; i < 256 ; i++ ) + if ( keys[i].binding ) { + Key_SetBinding( i, "" ); + } +} + + +/* +=================== +Key_Bind_f +=================== +*/ +void Key_Bind_f( void ) { + int i, c, b; + char cmd[1024]; + + c = Cmd_Argc(); + + if ( c < 2 ) { + Com_Printf( "bind [command] : attach a command to a key\n" ); + return; + } + b = Key_StringToKeynum( Cmd_Argv( 1 ) ); + if ( b == -1 ) { + Com_Printf( "\"%s\" isn't a valid key\n", Cmd_Argv( 1 ) ); + return; + } + + if ( c == 2 ) { + if ( keys[b].binding ) { + Com_Printf( "\"%s\" = \"%s\"\n", Cmd_Argv( 1 ), keys[b].binding ); + } else { + Com_Printf( "\"%s\" is not bound\n", Cmd_Argv( 1 ) ); + } + return; + } + +// copy the rest of the command line + cmd[0] = 0; // start out with a null string + for ( i = 2 ; i < c ; i++ ) + { + strcat( cmd, Cmd_Argv( i ) ); + if ( i != ( c - 1 ) ) { + strcat( cmd, " " ); + } + } + + Key_SetBinding( b, cmd ); +} + +/* +============ +Key_WriteBindings + +Writes lines containing "bind key value" +============ +*/ +void Key_WriteBindings( fileHandle_t f ) { + int i; + + FS_Printf( f, "unbindall\n" ); + + for ( i = 0 ; i < 256 ; i++ ) { + if ( keys[i].binding && keys[i].binding[0] ) { + FS_Printf( f, "bind %s \"%s\"\n", Key_KeynumToString( i, qfalse ), keys[i].binding ); + + } + + } +} + + +/* +============ +Key_Bindlist_f + +============ +*/ +void Key_Bindlist_f( void ) { + int i; + + for ( i = 0 ; i < 256 ; i++ ) { + if ( keys[i].binding && keys[i].binding[0] ) { + Com_Printf( "%s \"%s\"\n", Key_KeynumToString( i, qfalse ), keys[i].binding ); + } + } +} + + +/* +=================== +CL_InitKeyCommands +=================== +*/ +void CL_InitKeyCommands( void ) { + // register our functions + Cmd_AddCommand( "bind",Key_Bind_f ); + Cmd_AddCommand( "unbind",Key_Unbind_f ); + Cmd_AddCommand( "unbindall",Key_Unbindall_f ); + Cmd_AddCommand( "bindlist",Key_Bindlist_f ); +} + +/* +=================== +CL_KeyEvent + +Called by the system for both key up and key down events +=================== +*/ +//static int consoleCount = 0; // TTimo: unused +void CL_KeyEvent( int key, qboolean down, unsigned time ) { + char *kb; + char cmd[1024]; + int activeMenu = 0; + + // update auto-repeat status and BUTTON_ANY status + keys[key].down = down; + + if ( down ) { + keys[key].repeats++; + if ( keys[key].repeats == 1 ) { + anykeydown++; + } + } else { + keys[key].repeats = 0; + anykeydown--; + if ( anykeydown < 0 ) { + anykeydown = 0; + } + } + +#ifdef __linux__ + if ( key == K_ENTER ) { + if ( down ) { + if ( keys[K_ALT].down ) { + Key_ClearStates(); + if ( Cvar_VariableValue( "r_fullscreen" ) == 0 ) { + Com_Printf( "Switching to fullscreen rendering\n" ); + Cvar_Set( "r_fullscreen", "1" ); + } else + { + Com_Printf( "Switching to windowed rendering\n" ); + Cvar_Set( "r_fullscreen", "0" ); + } + Cbuf_ExecuteText( EXEC_APPEND, "vid_restart\n" ); + return; + } + } + } +#endif + + // console key is hardcoded, so the user can never unbind it + if ( key == '`' || key == '~' ) { + if ( !down ) { + return; + + } + Con_ToggleConsole_f(); + return; + } + +//----(SA) added + if ( cl.cameraMode ) { + if ( !( cls.keyCatchers & ( KEYCATCH_UI | KEYCATCH_CONSOLE ) ) ) { // let menu/console handle keys if necessary + + // in cutscenes we need to handle keys specially (pausing not allowed in camera mode) + if ( ( key == K_ESCAPE || + key == K_SPACE || + key == K_ENTER ) && down ) { + if ( down ) { + CL_AddReliableCommand( "cameraInterrupt" ); + } + return; + } + + // eat all keys + if ( down ) { + return; + } + } + + if ( ( cls.keyCatchers & KEYCATCH_CONSOLE ) && key == K_ESCAPE ) { + // don't allow menu starting when console is down and camera running + return; + } + } +//----(SA) end + + + // most keys during demo playback will bring up the menu, but non-ascii + + // keys can still be used for bound actions + if ( down && ( key < 128 || key == K_MOUSE1 ) + && ( clc.demoplaying || cls.state == CA_CINEMATIC ) && !cls.keyCatchers ) { + + Cvar_Set( "nextdemo","" ); + key = K_ESCAPE; + } + +//----(SA) get the active menu if in ui mode + if ( cls.keyCatchers & KEYCATCH_UI ) { + activeMenu = VM_Call( uivm, UI_GET_ACTIVE_MENU ); + } + + + // escape is always handled special + if ( key == K_ESCAPE && down ) { + if ( cls.keyCatchers & KEYCATCH_MESSAGE ) { + // clear message mode + Message_Key( key ); + return; + } + + // escape always gets out of CGAME stuff + if ( cls.keyCatchers & KEYCATCH_CGAME ) { + cls.keyCatchers &= ~KEYCATCH_CGAME; + VM_Call( cgvm, CG_EVENT_HANDLING, CGAME_EVENT_NONE ); + return; + } + + if ( !( cls.keyCatchers & KEYCATCH_UI ) ) { + if ( cls.state == CA_ACTIVE && !clc.demoplaying ) { + VM_Call( uivm, UI_SET_ACTIVE_MENU, UIMENU_INGAME ); + } else { + CL_Disconnect_f(); + S_StopAllSounds(); + VM_Call( uivm, UI_SET_ACTIVE_MENU, UIMENU_MAIN ); + } + return; + } + + if ( activeMenu == UIMENU_PREGAME ) { // eat escape too at this point + return; + } + + VM_Call( uivm, UI_KEY_EVENT, key, down ); + return; + } + + // + // key up events only perform actions if the game key binding is + // a button command (leading + sign). These will be processed even in + // console mode and menu mode, to keep the character from continuing + // an action started before a mode switch. + // + if ( !down ) { + kb = keys[key].binding; + if ( kb && kb[0] == '+' ) { + // button commands add keynum and time as parms so that multiple + // sources can be discriminated and subframe corrected + Com_sprintf( cmd, sizeof( cmd ), "-%s %i %i\n", kb + 1, key, time ); + Cbuf_AddText( cmd ); + } + + if ( cls.keyCatchers & KEYCATCH_UI && uivm ) { + VM_Call( uivm, UI_KEY_EVENT, key, down ); + } else if ( cls.keyCatchers & KEYCATCH_CGAME && cgvm ) { + VM_Call( cgvm, CG_KEY_EVENT, key, down ); + } + + return; + } + + + // distribute the key down event to the apropriate handler + if ( cls.keyCatchers & KEYCATCH_CONSOLE ) { + Console_Key( key ); + } else if ( cls.keyCatchers & KEYCATCH_UI ) { + kb = keys[key].binding; + + if ( activeMenu == UIMENU_CLIPBOARD ) { + // any key gets out of clipboard + key = K_ESCAPE; + } else if ( activeMenu == UIMENU_PREGAME ) { + if ( key != K_MOUSE1 ) { + return; // eat all keys except mouse click + } + } else { + + // when in the notebook, check for the key bound to "notebook" and allow that as an escape key + + if ( kb ) { + if ( !Q_stricmp( "notebook", kb ) ) { + if ( VM_Call( uivm, UI_GET_ACTIVE_MENU ) == UIMENU_NOTEBOOK ) { + key = K_ESCAPE; + } + } + +// if(!Q_stricmp("help", kb)) { +// if(VM_Call( uivm, UI_GET_ACTIVE_MENU) == UIMENU_HELP) +// key = K_ESCAPE; +/// } + } + } + + if ( uivm ) { + VM_Call( uivm, UI_KEY_EVENT, key, down ); + } + + } else if ( cls.keyCatchers & KEYCATCH_CGAME ) { + if ( cgvm ) { + VM_Call( cgvm, CG_KEY_EVENT, key, down ); + } + } else if ( cls.keyCatchers & KEYCATCH_MESSAGE ) { + Message_Key( key ); + } else if ( cls.state == CA_DISCONNECTED ) { + + Console_Key( key ); + + } else { + // send the bound action + kb = keys[key].binding; + if ( !kb ) { + if ( key >= 200 ) { + Com_Printf( "%s is unbound, use controls menu to set.\n" + , Key_KeynumToString( key, qfalse ) ); + } + } else if ( kb[0] == '+' ) { + // button commands add keynum and time as parms so that multiple + // sources can be discriminated and subframe corrected + Com_sprintf( cmd, sizeof( cmd ), "%s %i %i\n", kb, key, time ); + Cbuf_AddText( cmd ); + } else { + // down-only command + Cbuf_AddText( kb ); + Cbuf_AddText( "\n" ); + } + } +} + + +/* +=================== +CL_CharEvent + +Normal keyboard characters, already shifted / capslocked / etc +=================== +*/ +void CL_CharEvent( int key ) { + // the console key should never be used as a char + if ( key == '`' || key == '~' ) { + return; + } + + // distribute the key down event to the apropriate handler + if ( cls.keyCatchers & KEYCATCH_CONSOLE ) { + Field_CharEvent( &g_consoleField, key ); + } else if ( cls.keyCatchers & KEYCATCH_UI ) { + VM_Call( uivm, UI_KEY_EVENT, key | K_CHAR_FLAG, qtrue ); + } else if ( cls.keyCatchers & KEYCATCH_MESSAGE ) { + Field_CharEvent( &chatField, key ); + } else if ( cls.state == CA_DISCONNECTED ) { + Field_CharEvent( &g_consoleField, key ); + } +} + + +/* +=================== +Key_ClearStates +=================== +*/ +void Key_ClearStates( void ) { + int i; + + anykeydown = qfalse; + + for ( i = 0 ; i < MAX_KEYS ; i++ ) { + if ( keys[i].down ) { + CL_KeyEvent( i, qfalse, 0 ); + + } + keys[i].down = 0; + keys[i].repeats = 0; + } +} + diff --git a/Projects/Android/jni/rtcw/src/client/cl_main.c b/Projects/Android/jni/rtcw/src/client/cl_main.c new file mode 100644 index 0000000..20abecb --- /dev/null +++ b/Projects/Android/jni/rtcw/src/client/cl_main.c @@ -0,0 +1,3621 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +// cl_main.c -- client main loop + +#include "client.h" +#include + +cvar_t *cl_nodelta; +cvar_t *cl_debugMove; + +cvar_t *cl_noprint; +cvar_t *cl_motd; + +cvar_t *rcon_client_password; +cvar_t *rconAddress; + +cvar_t *cl_timeout; +cvar_t *cl_maxpackets; +cvar_t *cl_packetdup; +cvar_t *cl_timeNudge; +cvar_t *cl_showTimeDelta; +cvar_t *cl_freezeDemo; + +cvar_t *cl_shownet = NULL; // NERVE - SMF - This is referenced in msg.c and we need to make sure it is NULL +cvar_t *cl_showSend; +cvar_t *cl_timedemo; +cvar_t *cl_avidemo; +cvar_t *cl_forceavidemo; + +cvar_t *cl_freelook; +cvar_t *cl_sensitivity; + +cvar_t *cl_mouseAccel; +cvar_t *cl_showMouseRate; + +cvar_t *m_pitch; +cvar_t *m_yaw; +cvar_t *m_forward; +cvar_t *m_side; +cvar_t *m_filter; + +cvar_t *cl_activeAction; + +cvar_t *cl_motdString; + +cvar_t *cl_allowDownload; +cvar_t *cl_conXOffset; +cvar_t *cl_inGameVideo; + +cvar_t *cl_serverStatusResendTime; +cvar_t *cl_trn; +cvar_t *cl_missionStats; +cvar_t *cl_waitForFire; + +// NERVE - SMF - localization +cvar_t *cl_language; +cvar_t *cl_debugTranslation; +// -NERVE - SMF + + +char cl_cdkey[34] = " "; + +clientActive_t cl; +clientConnection_t clc; +clientStatic_t cls; +vm_t *cgvm; + +// Structure containing functions exported from refresh DLL +refexport_t re; + +ping_t cl_pinglist[MAX_PINGREQUESTS]; + +typedef struct serverStatus_s +{ + char string[BIG_INFO_STRING]; + netadr_t address; + int time, startTime; + qboolean pending; + qboolean print; + qboolean retrieved; +} serverStatus_t; + +serverStatus_t cl_serverStatusList[MAX_SERVERSTATUSREQUESTS]; +int serverStatusCount; + +#if 0 // MrE defined __USEA3D && defined __A3D_GEOM +void hA3Dg_ExportRenderGeom( refexport_t *incoming_re ); +#endif + +extern void SV_BotFrame( int time ); +void CL_CheckForResend( void ); +void CL_ShowIP_f( void ); +void CL_ServerStatus_f( void ); +void CL_ServerStatusResponse( netadr_t from, msg_t *msg ); + + +/* +============== +CL_EndgameMenu + +Called by Com_Error when a game has ended and is dropping out to main menu in the "endgame" menu ('credits' right now) +============== +*/ +void CL_EndgameMenu( void ) { + cls.endgamemenu = qtrue; // start it next frame +} + + +/* +=============== +CL_CDDialog + +Called by Com_Error when a cd is needed +=============== +*/ +void CL_CDDialog( void ) { + cls.cddialog = qtrue; // start it next frame +} + + +/* +======================================================================= + +CLIENT RELIABLE COMMAND COMMUNICATION + +======================================================================= +*/ + +/* +====================== +CL_AddReliableCommand + +The given command will be transmitted to the server, and is gauranteed to +not have future usercmd_t executed before it is executed +====================== +*/ +void CL_AddReliableCommand( const char *cmd ) { + int index; + + // if we would be losing an old command that hasn't been acknowledged, + // we must drop the connection +// if(cl.cameraMode) +// Com_Printf ("cmd: %s\n", cmd); + + if ( clc.reliableSequence - clc.reliableAcknowledge > MAX_RELIABLE_COMMANDS ) { + Com_Error( ERR_DROP, "Client command overflow" ); + } + clc.reliableSequence++; + index = clc.reliableSequence & ( MAX_RELIABLE_COMMANDS - 1 ); + Q_strncpyz( clc.reliableCommands[ index ], cmd, sizeof( clc.reliableCommands[ index ] ) ); +} + +/* +====================== +CL_ChangeReliableCommand +====================== +*/ +void CL_ChangeReliableCommand( void ) { + int r, index, l; + + r = clc.reliableSequence - ( random() * 5 ); + index = clc.reliableSequence & ( MAX_RELIABLE_COMMANDS - 1 ); + l = strlen( clc.reliableCommands[ index ] ); + if ( l >= MAX_STRING_CHARS - 1 ) { + l = MAX_STRING_CHARS - 2; + } + clc.reliableCommands[ index ][ l ] = '\n'; + clc.reliableCommands[ index ][ l + 1 ] = '\0'; +} + +/* +======================================================================= + +CLIENT SIDE DEMO RECORDING + +======================================================================= +*/ + +/* +==================== +CL_WriteDemoMessage + +Dumps the current net message, prefixed by the length +==================== +*/ +void CL_WriteDemoMessage( msg_t *msg, int headerBytes ) { + int len, swlen; + + // write the packet sequence + len = clc.serverMessageSequence; + swlen = LittleLong( len ); + FS_Write( &swlen, 4, clc.demofile ); + + // skip the packet sequencing information + len = msg->cursize - headerBytes; + swlen = LittleLong( len ); + FS_Write( &swlen, 4, clc.demofile ); + FS_Write( msg->data + headerBytes, len, clc.demofile ); +} + + +/* +==================== +CL_StopRecording_f + +stop recording a demo +==================== +*/ +void CL_StopRecord_f( void ) { + int len; + + if ( !clc.demorecording ) { + Com_Printf( "Not recording a demo.\n" ); + return; + } + + // finish up + len = -1; + FS_Write( &len, 4, clc.demofile ); + FS_Write( &len, 4, clc.demofile ); + FS_FCloseFile( clc.demofile ); + clc.demofile = 0; + clc.demorecording = qfalse; + Com_Printf( "Stopped demo.\n" ); +} + +/* +================== +CL_DemoFilename +================== +*/ +void CL_DemoFilename( int number, char *fileName ) { + int a,b,c,d; + + if ( number < 0 || number > 9999 ) { + Com_sprintf( fileName, MAX_OSPATH, "demo9999.tga" ); + return; + } + + a = number / 1000; + number -= a * 1000; + b = number / 100; + number -= b * 100; + c = number / 10; + number -= c * 10; + d = number; + + Com_sprintf( fileName, MAX_OSPATH, "demo%i%i%i%i" + , a, b, c, d ); +} + +/* +==================== +CL_Record_f + +record + +Begins recording a demo from the current position +==================== +*/ +static char demoName[MAX_QPATH]; // compiler bug workaround +void CL_Record_f( void ) { + char name[MAX_OSPATH]; + byte bufData[MAX_MSGLEN]; + msg_t buf; + int i; + int len; + entityState_t *ent; + entityState_t nullstate; + char *s; + + if ( Cmd_Argc() > 2 ) { + Com_Printf( "record \n" ); + return; + } + + if ( clc.demorecording ) { + Com_Printf( "Already recording.\n" ); + return; + } + + if ( cls.state != CA_ACTIVE ) { + Com_Printf( "You must be in a level to record.\n" ); + return; + } + + if ( !Cvar_VariableValue( "g_synchronousClients" ) ) { + Com_Printf( "The server must have 'g_synchronousClients 1' set for demos\n" ); + return; + } + + if ( Cmd_Argc() == 2 ) { + s = Cmd_Argv( 1 ); + Q_strncpyz( demoName, s, sizeof( demoName ) ); + Com_sprintf( name, sizeof( name ), "demos/%s.dm_%d", demoName, PROTOCOL_VERSION ); + } else { + int number; + + // scan for a free demo name + for ( number = 0 ; number <= 9999 ; number++ ) { + CL_DemoFilename( number, demoName ); + Com_sprintf( name, sizeof( name ), "demos/%s.dm_%d", demoName, PROTOCOL_VERSION ); + + len = FS_ReadFile( name, NULL ); + if ( len <= 0 ) { + break; // file doesn't exist + } + } + } + + // open the demo file +#ifdef __MACOS__ //DAJ MacOS file typing + { + extern _MSL_IMP_EXP_C long _fcreator, _ftype; + _ftype = 'WlfB'; + _fcreator = 'WlfS'; + } +#endif + + Com_Printf( "recording to %s.\n", name ); + clc.demofile = FS_FOpenFileWrite( name ); + if ( !clc.demofile ) { + Com_Printf( "ERROR: couldn't open.\n" ); + return; + } + clc.demorecording = qtrue; + Q_strncpyz( clc.demoName, demoName, sizeof( clc.demoName ) ); + + // don't start saving messages until a non-delta compressed message is received + clc.demowaiting = qtrue; + + // write out the gamestate message + MSG_Init( &buf, bufData, sizeof( bufData ) ); + MSG_Bitstream( &buf ); + + // NOTE, MRE: all server->client messages now acknowledge + MSG_WriteLong( &buf, clc.reliableSequence ); + + MSG_WriteByte( &buf, svc_gamestate ); + MSG_WriteLong( &buf, clc.serverCommandSequence ); + + // configstrings + for ( i = 0 ; i < MAX_CONFIGSTRINGS ; i++ ) { + if ( !cl.gameState.stringOffsets[i] ) { + continue; + } + s = cl.gameState.stringData + cl.gameState.stringOffsets[i]; + MSG_WriteByte( &buf, svc_configstring ); + MSG_WriteShort( &buf, i ); + MSG_WriteBigString( &buf, s ); + } + + // baselines + memset( &nullstate, 0, sizeof( nullstate ) ); + for ( i = 0; i < MAX_GENTITIES ; i++ ) { + ent = &cl.entityBaselines[i]; + if ( !ent->number ) { + continue; + } + MSG_WriteByte( &buf, svc_baseline ); + MSG_WriteDeltaEntity( &buf, &nullstate, ent, qtrue ); + } + + MSG_WriteByte( &buf, svc_EOF ); + + // finished writing the gamestate stuff + + // write the client num + MSG_WriteLong( &buf, clc.clientNum ); + // write the checksum feed + MSG_WriteLong( &buf, clc.checksumFeed ); + + // finished writing the client packet + MSG_WriteByte( &buf, svc_EOF ); + + // write it to the demo file + len = LittleLong( clc.serverMessageSequence - 1 ); + FS_Write( &len, 4, clc.demofile ); + + len = LittleLong( buf.cursize ); + FS_Write( &len, 4, clc.demofile ); + FS_Write( buf.data, buf.cursize, clc.demofile ); + + // the rest of the demo file will be copied from net messages +} + +/* +======================================================================= + +CLIENT SIDE DEMO PLAYBACK + +======================================================================= +*/ + +/* +================= +CL_DemoCompleted +================= +*/ +void CL_DemoCompleted( void ) { + if ( cl_timedemo && cl_timedemo->integer ) { + int time; + + time = Sys_Milliseconds() - clc.timeDemoStart; + if ( time > 0 ) { + Com_Printf( "%i frames, %3.1f seconds: %3.1f fps\n", clc.timeDemoFrames, + time / 1000.0, clc.timeDemoFrames * 1000.0 / time ); + } + } + + CL_Disconnect( qtrue ); + CL_NextDemo(); +} + +/* +================= +CL_ReadDemoMessage +================= +*/ +void CL_ReadDemoMessage( void ) { + int r; + msg_t buf; + byte bufData[ MAX_MSGLEN ]; + int s; + + if ( !clc.demofile ) { + CL_DemoCompleted(); + return; + } + + // get the sequence number + r = FS_Read( &s, 4, clc.demofile ); + if ( r != 4 ) { + CL_DemoCompleted(); + return; + } + clc.serverMessageSequence = LittleLong( s ); + + // init the message + MSG_Init( &buf, bufData, sizeof( bufData ) ); + + // get the length + r = FS_Read( &buf.cursize, 4, clc.demofile ); + if ( r != 4 ) { + CL_DemoCompleted(); + return; + } + buf.cursize = LittleLong( buf.cursize ); + if ( buf.cursize == -1 ) { + CL_DemoCompleted(); + return; + } + if ( buf.cursize > buf.maxsize ) { + Com_Error( ERR_DROP, "CL_ReadDemoMessage: demoMsglen > MAX_MSGLEN" ); + } + r = FS_Read( buf.data, buf.cursize, clc.demofile ); + if ( r != buf.cursize ) { + Com_Printf( "Demo file was truncated.\n" ); + CL_DemoCompleted(); + return; + } + + clc.lastPacketTime = cls.realtime; + buf.readcount = 0; + CL_ParseServerMessage( &buf ); +} + +/* +==================== +CL_PlayDemo_f + +demo + +==================== +*/ +void CL_PlayDemo_f( void ) { + char name[MAX_OSPATH], extension[32]; + char *arg; + + if ( Cmd_Argc() != 2 ) { + Com_Printf( "playdemo \n" ); + return; + } + + // make sure a local server is killed + Cvar_Set( "sv_killserver", "1" ); + + CL_Disconnect( qtrue ); + + +// CL_FlushMemory(); //----(SA) MEM NOTE: in missionpack, this is moved to CL_DownloadsComplete + + + // open the demo file + arg = Cmd_Argv( 1 ); + Com_sprintf( extension, sizeof( extension ), ".dm_%d", PROTOCOL_VERSION ); + if ( !Q_stricmp( arg + strlen( arg ) - strlen( extension ), extension ) ) { + Com_sprintf( name, sizeof( name ), "demos/%s", arg ); + } else { + Com_sprintf( name, sizeof( name ), "demos/%s.dm_%d", arg, PROTOCOL_VERSION ); + } + + FS_FOpenFileRead( name, &clc.demofile, qtrue ); + if ( !clc.demofile ) { + Com_Error( ERR_DROP, "couldn't open %s", name ); + return; + } + Q_strncpyz( clc.demoName, Cmd_Argv( 1 ), sizeof( clc.demoName ) ); + + Con_Close(); + + cls.state = CA_CONNECTED; + clc.demoplaying = qtrue; + Q_strncpyz( cls.servername, Cmd_Argv( 1 ), sizeof( cls.servername ) ); + + // read demo messages until connected + while ( cls.state >= CA_CONNECTED && cls.state < CA_PRIMED ) { + CL_ReadDemoMessage(); + } + // don't get the first snapshot this frame, to prevent the long + // time from the gamestate load from messing causing a time skip + clc.firstDemoFrameSkipped = qfalse; +} + + +/* +==================== +CL_StartDemoLoop + +Closing the main menu will restart the demo loop +==================== +*/ +void CL_StartDemoLoop( void ) { + // start the demo loop again + Cbuf_AddText( "d1\n" ); + cls.keyCatchers = 0; +} + +/* +================== +CL_NextDemo + +Called when a demo or cinematic finishes +If the "nextdemo" cvar is set, that command will be issued +================== +*/ +void CL_NextDemo( void ) { + char v[MAX_STRING_CHARS]; + + Q_strncpyz( v, Cvar_VariableString( "nextdemo" ), sizeof( v ) ); + v[MAX_STRING_CHARS - 1] = 0; + Com_DPrintf( "CL_NextDemo: %s\n", v ); + if ( !v[0] ) { + return; + } + + Cvar_Set( "nextdemo","" ); + Cbuf_AddText( v ); + Cbuf_AddText( "\n" ); + Cbuf_Execute(); +} + + +//====================================================================== + +/* +===================== +CL_ShutdownAll +===================== +*/ +void CL_ShutdownAll( void ) { + + // clear sounds + S_DisableSounds(); + // shutdown CGame + CL_ShutdownCGame(); + // shutdown UI + CL_ShutdownUI(); + + // shutdown the renderer + if ( re.Shutdown ) { + re.Shutdown( qfalse ); // don't destroy window or context + } + + cls.uiStarted = qfalse; + cls.cgameStarted = qfalse; + cls.rendererStarted = qfalse; + cls.soundRegistered = qfalse; +} + +/* +================= +CL_FlushMemory + +Called by CL_MapLoading, CL_Connect_f, CL_PlayDemo_f, and CL_ParseGamestate the only +ways a client gets into a game +Also called by Com_Error +================= +*/ +void CL_FlushMemory( void ) { + + // shutdown all the client stuff + CL_ShutdownAll(); + + // if not running a server clear the whole hunk + if ( !com_sv_running->integer ) { + // clear the whole hunk + Hunk_Clear(); +// // clear collision map data +// CM_ClearMap(); + } else { + // clear all the client data on the hunk + Hunk_ClearToMark(); + } + + CL_StartHunkUsers(); +} + +/* +===================== +CL_MapLoading + +A local server is starting to load a map, so update the +screen to let the user know about it, then dump all client +memory on the hunk from cgame, ui, and renderer +===================== +*/ +void CL_MapLoading( void ) { + if ( !com_cl_running->integer ) { + return; + } + + Con_Close(); + cls.keyCatchers = 0; + +// this was for multi-threaded music +// S_StartBackgroundTrack( "sound/music/l_briefing_1.wav", "", -2); // '-2' for 'queue looping track' (QUEUED_PLAY_LOOPED) + + // if we are already connected to the local host, stay connected + if ( cls.state >= CA_CONNECTED && !Q_stricmp( cls.servername, "localhost" ) ) { + cls.state = CA_CONNECTED; // so the connect screen is drawn + memset( cls.updateInfoString, 0, sizeof( cls.updateInfoString ) ); + memset( clc.serverMessage, 0, sizeof( clc.serverMessage ) ); + memset( &cl.gameState, 0, sizeof( cl.gameState ) ); + clc.lastPacketSentTime = -9999; + SCR_UpdateScreen(); + } else { + // clear nextmap so the cinematic shutdown doesn't execute it + Cvar_Set( "nextmap", "" ); + CL_Disconnect( qtrue ); + Q_strncpyz( cls.servername, "localhost", sizeof( cls.servername ) ); + cls.state = CA_CHALLENGING; // so the connect screen is drawn + cls.keyCatchers = 0; + SCR_UpdateScreen(); + clc.connectTime = -RETRANSMIT_TIMEOUT; + NET_StringToAdr( cls.servername, &clc.serverAddress ); + // we don't need a challenge on the localhost + + CL_CheckForResend(); + } + + // make sure sound is quiet + S_FadeAllSounds( 0, 0 ); +} + +/* +===================== +CL_ClearState + +Called before parsing a gamestate +===================== +*/ +void CL_ClearState( void ) { + + S_StopAllSounds(); + + memset( &cl, 0, sizeof( cl ) ); +} + + +/* +===================== +CL_Disconnect + +Called when a connection, demo, or cinematic is being terminated. +Goes from a connected state to either a menu state or a console state +Sends a disconnect message to the server +This is also called on Com_Error and Com_Quit, so it shouldn't cause any errors +===================== +*/ +void CL_Disconnect( qboolean showMainMenu ) { + if ( !com_cl_running || !com_cl_running->integer ) { + return; + } + + // shutting down the client so enter full screen ui mode + Cvar_Set( "r_uiFullScreen", "1" ); + + if ( clc.demorecording ) { + CL_StopRecord_f(); + } + + if ( clc.download ) { + FS_FCloseFile( clc.download ); + clc.download = 0; + } + *clc.downloadTempName = *clc.downloadName = 0; + Cvar_Set( "cl_downloadName", "" ); + + if ( clc.demofile ) { + FS_FCloseFile( clc.demofile ); + clc.demofile = 0; + } + + if ( uivm && showMainMenu ) { + VM_Call( uivm, UI_SET_ACTIVE_MENU, UIMENU_NONE ); + } + + SCR_StopCinematic(); + S_ClearSoundBuffer( qtrue ); //----(SA) modified + + // send a disconnect message to the server + // send it a few times in case one is dropped + if ( cls.state >= CA_CONNECTED ) { + CL_AddReliableCommand( "disconnect" ); + CL_WritePacket(); + CL_WritePacket(); + CL_WritePacket(); + } + + CL_ClearState(); + + // wipe the client connection + memset( &clc, 0, sizeof( clc ) ); + + cls.state = CA_DISCONNECTED; + + // allow cheats locally +#ifndef WOLF_SP_DEMO + // except for demo + Cvar_Set( "sv_cheats", "1" ); +#endif + + // not connected to a pure server anymore + cl_connectedToPureServer = qfalse; +} + + +/* +=================== +CL_ForwardCommandToServer + +adds the current command line as a clientCommand +things like godmode, noclip, etc, are commands directed to the server, +so when they are typed in at the console, they will need to be forwarded. +=================== +*/ +void CL_ForwardCommandToServer( const char *string ) { + char *cmd; + + cmd = Cmd_Argv( 0 ); + + // ignore key up commands + if ( cmd[0] == '-' ) { + return; + } + + if ( clc.demoplaying || cls.state < CA_CONNECTED || cmd[0] == '+' ) { + Com_Printf( "Unknown command \"%s\"\n", cmd ); + return; + } + + if ( Cmd_Argc() > 1 ) { + CL_AddReliableCommand( string ); + } else { + CL_AddReliableCommand( cmd ); + } +} + +/* +=================== +CL_RequestMotd + +=================== +*/ +void CL_RequestMotd( void ) { + char info[MAX_INFO_STRING]; + + if ( !cl_motd->integer ) { + return; + } + Com_Printf( "Resolving %s\n", UPDATE_SERVER_NAME ); + if ( !NET_StringToAdr( UPDATE_SERVER_NAME, &cls.updateServer ) ) { + Com_Printf( "Couldn't resolve address\n" ); + return; + } + cls.updateServer.port = BigShort( PORT_UPDATE ); + Com_Printf( "%s resolved to %i.%i.%i.%i:%i\n", UPDATE_SERVER_NAME, + cls.updateServer.ip[0], cls.updateServer.ip[1], + cls.updateServer.ip[2], cls.updateServer.ip[3], + BigShort( cls.updateServer.port ) ); + + info[0] = 0; + Com_sprintf( cls.updateChallenge, sizeof( cls.updateChallenge ), "%i", rand() ); + + Info_SetValueForKey( info, "challenge", cls.updateChallenge ); + Info_SetValueForKey( info, "renderer", cls.glconfig.renderer_string ); + Info_SetValueForKey( info, "version", com_version->string ); + + NET_OutOfBandPrint( NS_CLIENT, cls.updateServer, "getmotd \"%s\"\n", info ); +} + + +/* +=================== +CL_RequestAuthorization + +Authorization server protocol +----------------------------- + +All commands are text in Q3 out of band packets (leading 0xff 0xff 0xff 0xff). + +Whenever the client tries to get a challenge from the server it wants to +connect to, it also blindly fires off a packet to the authorize server: + +getKeyAuthorize + +cdkey may be "demo" + + +#OLD The authorize server returns a: +#OLD +#OLD keyAthorize +#OLD +#OLD A client will be accepted if the cdkey is valid and it has not been used by any other IP +#OLD address in the last 15 minutes. + + +The server sends a: + +getIpAuthorize + +The authorize server returns a: + +ipAuthorize + +A client will be accepted if a valid cdkey was sent by that ip (only) in the last 15 minutes. +If no response is received from the authorize server after two tries, the client will be let +in anyway. +=================== +*/ +void CL_RequestAuthorization( void ) { + char nums[64]; + int i, j, l; + cvar_t *fs; + + if ( !cls.authorizeServer.port ) { + Com_Printf( "Resolving %s\n", AUTHORIZE_SERVER_NAME ); + if ( !NET_StringToAdr( AUTHORIZE_SERVER_NAME, &cls.authorizeServer ) ) { + Com_Printf( "Couldn't resolve address\n" ); + return; + } + + cls.authorizeServer.port = BigShort( PORT_AUTHORIZE ); + Com_Printf( "%s resolved to %i.%i.%i.%i:%i\n", AUTHORIZE_SERVER_NAME, + cls.authorizeServer.ip[0], cls.authorizeServer.ip[1], + cls.authorizeServer.ip[2], cls.authorizeServer.ip[3], + BigShort( cls.authorizeServer.port ) ); + } + if ( cls.authorizeServer.type == NA_BAD ) { + return; + } + + if ( Cvar_VariableValue( "fs_restrict" ) ) { + Q_strncpyz( nums, "demo", sizeof( nums ) ); + } else { + // only grab the alphanumeric values from the cdkey, to avoid any dashes or spaces + j = 0; + l = strlen( cl_cdkey ); + if ( l > 32 ) { + l = 32; + } + for ( i = 0 ; i < l ; i++ ) { + if ( ( cl_cdkey[i] >= '0' && cl_cdkey[i] <= '9' ) + || ( cl_cdkey[i] >= 'a' && cl_cdkey[i] <= 'z' ) + || ( cl_cdkey[i] >= 'A' && cl_cdkey[i] <= 'Z' ) + ) { + nums[j] = cl_cdkey[i]; + j++; + } + } + nums[j] = 0; + } + + fs = Cvar_Get( "cl_anonymous", "0", CVAR_INIT | CVAR_SYSTEMINFO ); + NET_OutOfBandPrint( NS_CLIENT, cls.authorizeServer, va( "getKeyAuthorize %i %s", fs->integer, nums ) ); +} + +/* +====================================================================== + +CONSOLE COMMANDS + +====================================================================== +*/ + +/* +================== +CL_ForwardToServer_f +================== +*/ +void CL_ForwardToServer_f( void ) { + if ( cls.state != CA_ACTIVE || clc.demoplaying ) { + Com_Printf( "Not connected to a server.\n" ); + return; + } + + // don't forward the first argument + if ( Cmd_Argc() > 1 ) { + CL_AddReliableCommand( Cmd_Args() ); + } +} + +/* +================== +CL_Setenv_f + +Mostly for controlling voodoo environment variables +================== +*/ +void CL_Setenv_f( void ) { + int argc = Cmd_Argc(); + + if ( argc > 2 ) { + char buffer[1024]; + int i; + + strcpy( buffer, Cmd_Argv( 1 ) ); + strcat( buffer, "=" ); + + for ( i = 2; i < argc; i++ ) { + strcat( buffer, Cmd_Argv( i ) ); + strcat( buffer, " " ); + } + + Q_putenv( buffer ); + } else if ( argc == 2 ) { + char *env = getenv( Cmd_Argv( 1 ) ); + + if ( env ) { + Com_Printf( "%s=%s\n", Cmd_Argv( 1 ), env ); + } else { + Com_Printf( "%s undefined\n", Cmd_Argv( 1 ), env ); + } + } +} + + +/* +================== +CL_Disconnect_f +================== +*/ +void CL_Disconnect_f( void ) { + SCR_StopCinematic(); + // RF, make sure loading variables are turned off + Cvar_Set( "savegame_loading", "0" ); + Cvar_Set( "g_reloading", "0" ); + if ( cls.state != CA_DISCONNECTED && cls.state != CA_CINEMATIC ) { + Com_Error( ERR_DISCONNECT, "Disconnected from server" ); + } +} + + +/* +================ +CL_Reconnect_f + +================ +*/ +void CL_Reconnect_f( void ) { + if ( !strlen( cls.servername ) || !strcmp( cls.servername, "localhost" ) ) { + Com_Printf( "Can't reconnect to localhost.\n" ); + return; + } + Cbuf_AddText( va( "connect %s\n", cls.servername ) ); +} + +/* +================ +CL_Connect_f + +================ +*/ +void CL_Connect_f( void ) { + char *server; + + if ( Cmd_Argc() != 2 ) { + Com_Printf( "usage: connect [server]\n" ); + return; + } + + // starting to load a map so we get out of full screen ui mode + Cvar_Set( "r_uiFullScreen", "0" ); + + // fire a message off to the motd server + CL_RequestMotd(); + + // clear any previous "server full" type messages + clc.serverMessage[0] = 0; + + server = Cmd_Argv( 1 ); + + if ( com_sv_running->integer && !strcmp( server, "localhost" ) ) { + // if running a local server, kill it + SV_Shutdown( "Server quit\n" ); + } + + // make sure a local server is killed + Cvar_Set( "sv_killserver", "1" ); + SV_Frame( 0 ); + + CL_Disconnect( qtrue ); + Con_Close(); + +// CL_FlushMemory(); //----(SA) MEM NOTE: in missionpack, this is moved to CL_DownloadsComplete + + + + Q_strncpyz( cls.servername, server, sizeof( cls.servername ) ); + + if ( !NET_StringToAdr( cls.servername, &clc.serverAddress ) ) { + Com_Printf( "Bad server address\n" ); + cls.state = CA_DISCONNECTED; + return; + } + if ( clc.serverAddress.port == 0 ) { + clc.serverAddress.port = BigShort( PORT_SERVER ); + } + Com_Printf( "%s resolved to %i.%i.%i.%i:%i\n", cls.servername, + clc.serverAddress.ip[0], clc.serverAddress.ip[1], + clc.serverAddress.ip[2], clc.serverAddress.ip[3], + BigShort( clc.serverAddress.port ) ); + + // if we aren't playing on a lan, we need to authenticate + // with the cd key + if ( NET_IsLocalAddress( clc.serverAddress ) ) { + cls.state = CA_CHALLENGING; + } else { + cls.state = CA_CONNECTING; + } + + cls.keyCatchers = 0; + clc.connectTime = -99999; // CL_CheckForResend() will fire immediately + clc.connectPacketCount = 0; + + // server connection string + Cvar_Set( "cl_currentServerAddress", server ); +} + + +/* +===================== +CL_Rcon_f + + Send the rest of the command line over as + an unconnected command. +===================== +*/ +void CL_Rcon_f( void ) { + char message[1024]; + int i; + netadr_t to; + + if ( !rcon_client_password->string ) { + Com_Printf( "You must set 'rcon_password' before\n" + "issuing an rcon command.\n" ); + return; + } + + message[0] = -1; + message[1] = -1; + message[2] = -1; + message[3] = -1; + message[4] = 0; + + strcat( message, "rcon " ); + + strcat( message, rcon_client_password->string ); + strcat( message, " " ); + + for ( i = 1 ; i < Cmd_Argc() ; i++ ) { + strcat( message, Cmd_Argv( i ) ); + strcat( message, " " ); + } + + if ( cls.state >= CA_CONNECTED ) { + to = clc.netchan.remoteAddress; + } else { + if ( !strlen( rconAddress->string ) ) { + Com_Printf( "You must either be connected,\n" + "or set the 'rconAddress' cvar\n" + "to issue rcon commands\n" ); + + return; + } + NET_StringToAdr( rconAddress->string, &to ); + if ( to.port == 0 ) { + to.port = BigShort( PORT_SERVER ); + } + } + + NET_SendPacket( NS_CLIENT, strlen( message ) + 1, message, to ); +} + +/* +================= +CL_SendPureChecksums +================= +*/ +void CL_SendPureChecksums( void ) { + const char *pChecksums; + char cMsg[MAX_INFO_VALUE]; + int i; + + // if we are pure we need to send back a command with our referenced pk3 checksums + pChecksums = FS_ReferencedPakPureChecksums(); + + // "cp" + // "Yf" + Com_sprintf( cMsg, sizeof( cMsg ), "Yf " ); + Q_strcat( cMsg, sizeof( cMsg ), pChecksums ); + for ( i = 0; i < 2; i++ ) { + cMsg[i] += 10; + } + CL_AddReliableCommand( cMsg ); +} + +/* +================= +CL_ResetPureClientAtServer +================= +*/ +void CL_ResetPureClientAtServer( void ) { + CL_AddReliableCommand( va( "vdr" ) ); +} + +/* +================= +CL_Vid_Restart_f + +Restart the video subsystem + +we also have to reload the UI and CGame because the renderer +doesn't know what graphics to reload +================= +*/ +void CL_Vid_Restart_f( void ) { + + vmCvar_t musicCvar; + + // RF, don't show percent bar, since the memory usage will just sit at the same level anyway + Cvar_Set( "com_expectedhunkusage", "-1" ); + + // don't let them loop during the restart + S_StopAllSounds(); + // shutdown the UI + CL_ShutdownUI(); + // shutdown the CGame + CL_ShutdownCGame(); + // shutdown the renderer and clear the renderer interface + CL_ShutdownRef(); + // client is no longer pure untill new checksums are sent + CL_ResetPureClientAtServer(); + // clear pak references + FS_ClearPakReferences( FS_UI_REF | FS_CGAME_REF ); + // reinitialize the filesystem if the game directory or checksum has changed + FS_ConditionalRestart( clc.checksumFeed ); + + S_BeginRegistration(); // all sound handles are now invalid + + cls.rendererStarted = qfalse; + cls.uiStarted = qfalse; + cls.cgameStarted = qfalse; + cls.soundRegistered = qfalse; + + // unpause so the cgame definately gets a snapshot and renders a frame + Cvar_Set( "cl_paused", "0" ); + + // if not running a server clear the whole hunk + if ( !com_sv_running->integer ) { + // clear the whole hunk + Hunk_Clear(); + } else { + // clear all the client data on the hunk + Hunk_ClearToMark(); + } + + // initialize the renderer interface + CL_InitRef(); + + // startup all the client stuff + CL_StartHunkUsers(); + + // start the cgame if connected + if ( cls.state > CA_CONNECTED && cls.state != CA_CINEMATIC ) { + cls.cgameStarted = qtrue; + CL_InitCGame(); + // send pure checksums + CL_SendPureChecksums(); + } + + // start music if there was any + + Cvar_Register( &musicCvar, "s_currentMusic", "", CVAR_ROM ); + if ( strlen( musicCvar.string ) ) { + S_StartBackgroundTrack( musicCvar.string, musicCvar.string, 1000 ); + } + + // fade up volume + S_FadeAllSounds( 1, 0 ); +} + +/* +================= +CL_Snd_Restart_f + +Restart the sound subsystem +The cgame and game must also be forced to restart because +handles will be invalid +================= +*/ +void CL_Snd_Restart_f( void ) { + S_Shutdown(); + S_Init(); + + CL_Vid_Restart_f(); +} + + +/* +================== +CL_PK3List_f +================== +*/ +void CL_OpenedPK3List_f( void ) { + Com_Printf( "Opened PK3 Names: %s\n", FS_LoadedPakNames() ); +} + +/* +================== +CL_PureList_f +================== +*/ +void CL_ReferencedPK3List_f( void ) { + Com_Printf( "Referenced PK3 Names: %s\n", FS_ReferencedPakNames() ); +} + +/* +================== +CL_Configstrings_f +================== +*/ +void CL_Configstrings_f( void ) { + int i; + int ofs; + + if ( cls.state != CA_ACTIVE ) { + Com_Printf( "Not connected to a server.\n" ); + return; + } + + for ( i = 0 ; i < MAX_CONFIGSTRINGS ; i++ ) { + ofs = cl.gameState.stringOffsets[ i ]; + if ( !ofs ) { + continue; + } + Com_Printf( "%4i: %s\n", i, cl.gameState.stringData + ofs ); + } +} + +/* +============== +CL_Clientinfo_f +============== +*/ +void CL_Clientinfo_f( void ) { + Com_Printf( "--------- Client Information ---------\n" ); + Com_Printf( "state: %i\n", cls.state ); + Com_Printf( "Server: %s\n", cls.servername ); + Com_Printf( "User info settings:\n" ); + Info_Print( Cvar_InfoString( CVAR_USERINFO ) ); + Com_Printf( "--------------------------------------\n" ); +} + + +//==================================================================== + +/* +================= +CL_DownloadsComplete + +Called when all downloading has been completed +================= +*/ +void CL_DownloadsComplete( void ) { + + // if we downloaded files we need to restart the file system + if ( clc.downloadRestart ) { + clc.downloadRestart = qfalse; + + FS_Restart( clc.checksumFeed ); // We possibly downloaded a pak, restart the file system to load it + + // inform the server so we get new gamestate info + CL_AddReliableCommand( "donedl" ); + + // by sending the donenl command we request a new gamestate + // so we don't want to load stuff yet + return; + } + + // let the client game init and load data + cls.state = CA_LOADING; + +//----(SA) removed some loading stuff + Com_EventLoop(); + + // if the gamestate was changed by calling Com_EventLoop + // then we loaded everything already and we don't want to do it again. + if ( cls.state != CA_LOADING ) { + return; + } + + // starting to load a map so we get out of full screen ui mode + Cvar_Set( "r_uiFullScreen", "0" ); + + // flush client memory and start loading stuff + // this will also (re)load the UI + // if this is a local client then only the client part of the hunk + // will be cleared, note that this is done after the hunk mark has been set + CL_FlushMemory(); + + // initialize the CGame + cls.cgameStarted = qtrue; + CL_InitCGame(); + + // set pure checksums + CL_SendPureChecksums(); + + CL_WritePacket(); + CL_WritePacket(); + CL_WritePacket(); +} + +/* +================= +CL_BeginDownload + +Requests a file to download from the server. Stores it in the current +game directory. +================= +*/ +void CL_BeginDownload( const char *localName, const char *remoteName ) { + + Com_DPrintf( "***** CL_BeginDownload *****\n" + "Localname: %s\n" + "Remotename: %s\n" + "****************************\n", localName, remoteName ); + + Q_strncpyz( clc.downloadName, localName, sizeof( clc.downloadName ) ); + Com_sprintf( clc.downloadTempName, sizeof( clc.downloadTempName ), "%s.tmp", localName ); + + // Set so UI gets access to it + Cvar_Set( "cl_downloadName", remoteName ); + Cvar_Set( "cl_downloadSize", "0" ); + Cvar_Set( "cl_downloadCount", "0" ); + Cvar_SetValue( "cl_downloadTime", cls.realtime ); + + clc.downloadBlock = 0; // Starting new file + clc.downloadCount = 0; + + CL_AddReliableCommand( va( "download %s", remoteName ) ); +} + +/* +================= +CL_NextDownload + +A download completed or failed +================= +*/ +void CL_NextDownload( void ) { + char *s; + char *remoteName, *localName; + + // We are looking to start a download here + if ( *clc.downloadList ) { + s = clc.downloadList; + + // format is: + // @remotename@localname@remotename@localname, etc. + + if ( *s == '@' ) { + s++; + } + remoteName = s; + + if ( ( s = strchr( s, '@' ) ) == NULL ) { + CL_DownloadsComplete(); + return; + } + + *s++ = 0; + localName = s; + if ( ( s = strchr( s, '@' ) ) != NULL ) { + *s++ = 0; + } else { + s = localName + strlen( localName ); // point at the nul byte + + } + CL_BeginDownload( localName, remoteName ); + + clc.downloadRestart = qtrue; + + // move over the rest + memmove( clc.downloadList, s, strlen( s ) + 1 ); + + return; + } + + CL_DownloadsComplete(); +} + +/* +================= +CL_InitDownloads + +After receiving a valid game state, we valid the cgame and local zip files here +and determine if we need to download them +================= +*/ +void CL_InitDownloads( void ) { + + if ( cl_allowDownload->integer && + FS_ComparePaks( clc.downloadList, sizeof( clc.downloadList ), qfalse ) ) { + + if ( *clc.downloadList ) { + // if autodownloading is not enabled on the server + cls.state = CA_CONNECTED; + CL_NextDownload(); + return; + } + + } + + CL_DownloadsComplete(); +} + +/* +================= +CL_CheckForResend + +Resend a connect message if the last one has timed out +================= +*/ +void CL_CheckForResend( void ) { + int port; + char info[MAX_INFO_STRING]; + + // don't send anything if playing back a demo + if ( clc.demoplaying ) { + return; + } + + // resend if we haven't gotten a reply yet + if ( cls.state != CA_CONNECTING && cls.state != CA_CHALLENGING ) { + return; + } + + if ( cls.realtime - clc.connectTime < RETRANSMIT_TIMEOUT ) { + return; + } + + clc.connectTime = cls.realtime; // for retransmit requests + clc.connectPacketCount++; + + + switch ( cls.state ) { + case CA_CONNECTING: + // requesting a challenge + if ( !Sys_IsLANAddress( clc.serverAddress ) ) { + CL_RequestAuthorization(); + } + NET_OutOfBandPrint( NS_CLIENT, clc.serverAddress, "getchallenge" ); + break; + + case CA_CHALLENGING: + // sending back the challenge + port = Cvar_VariableValue( "net_qport" ); + + Q_strncpyz( info, Cvar_InfoString( CVAR_USERINFO ), sizeof( info ) ); + Info_SetValueForKey( info, "protocol", va( "%i", PROTOCOL_VERSION ) ); + Info_SetValueForKey( info, "qport", va( "%i", port ) ); + Info_SetValueForKey( info, "challenge", va( "%i", clc.challenge ) ); + NET_OutOfBandPrint( NS_CLIENT, clc.serverAddress, "connect \"%s\"", info ); + // the most current userinfo has been sent, so watch for any + // newer changes to userinfo variables + cvar_modifiedFlags &= ~CVAR_USERINFO; + break; + + default: + Com_Error( ERR_FATAL, "CL_CHeckForResend: bad cls.state" ); + } +} + + +/* +=================== +CL_DisconnectPacket + +Sometimes the server can drop the client and the netchan based +disconnect can be lost. If the client continues to send packets +to the server, the server will send out of band disconnect packets +to the client so it doesn't have to wait for the full timeout period. +=================== +*/ +void CL_DisconnectPacket( netadr_t from ) { + if ( cls.state < CA_AUTHORIZING ) { + return; + } + + // if not from our server, ignore it + if ( !NET_CompareAdr( from, clc.netchan.remoteAddress ) ) { + return; + } + + // if we have received packets within three seconds, ignore it + // (it might be a malicious spoof) + if ( cls.realtime - clc.lastPacketTime < 3000 ) { + return; + } + + // drop the connection (FIXME: connection dropped dialog) + Com_Printf( "Server disconnected for unknown reason\n" ); + CL_Disconnect( qtrue ); +} + + +/* +=================== +CL_MotdPacket + +=================== +*/ +void CL_MotdPacket( netadr_t from ) { + char *challenge; + char *info; + + // if not from our server, ignore it + if ( !NET_CompareAdr( from, cls.updateServer ) ) { + return; + } + + info = Cmd_Argv( 1 ); + + // check challenge + challenge = Info_ValueForKey( info, "challenge" ); + if ( strcmp( challenge, cls.updateChallenge ) ) { + return; + } + + challenge = Info_ValueForKey( info, "motd" ); + + Q_strncpyz( cls.updateInfoString, info, sizeof( cls.updateInfoString ) ); + Cvar_Set( "cl_motdString", challenge ); +} + +/* +=================== +CL_InitServerInfo +=================== +*/ +void CL_InitServerInfo( serverInfo_t *server, serverAddress_t *address ) { + server->adr.type = NA_IP; + server->adr.ip[0] = address->ip[0]; + server->adr.ip[1] = address->ip[1]; + server->adr.ip[2] = address->ip[2]; + server->adr.ip[3] = address->ip[3]; + server->adr.port = address->port; + server->clients = 0; + server->hostName[0] = '\0'; + server->mapName[0] = '\0'; + server->maxClients = 0; + server->maxPing = 0; + server->minPing = 0; + server->ping = -1; + server->game[0] = '\0'; + server->gameType = 0; + server->netType = 0; + server->allowAnonymous = 0; +} + +#define MAX_SERVERSPERPACKET 256 + +/* +=================== +CL_ServersResponsePacket +=================== +*/ +void CL_ServersResponsePacket( netadr_t from, msg_t *msg ) { + int i, count, max, total; + serverAddress_t addresses[MAX_SERVERSPERPACKET]; + int numservers; + byte* buffptr; + byte* buffend; + + Com_Printf( "CL_ServersResponsePacket\n" ); + + if ( cls.numglobalservers == -1 ) { + // state to detect lack of servers or lack of response + cls.numglobalservers = 0; + cls.numGlobalServerAddresses = 0; + } + + if ( cls.nummplayerservers == -1 ) { + cls.nummplayerservers = 0; + } + + // parse through server response string + numservers = 0; + buffptr = msg->data; + buffend = buffptr + msg->cursize; + while ( buffptr + 1 < buffend ) { + // advance to initial token + do { + if ( *buffptr++ == '\\' ) { + break; + } + } + while ( buffptr < buffend ); + + // parse out ip + addresses[numservers].ip[0] = *buffptr++; + addresses[numservers].ip[1] = *buffptr++; + addresses[numservers].ip[2] = *buffptr++; + addresses[numservers].ip[3] = *buffptr++; + + // parse out port + addresses[numservers].port = ( *buffptr++ ) << 8; + addresses[numservers].port += *buffptr++; + addresses[numservers].port = BigShort( addresses[numservers].port ); + + // syntax check + if ( *buffptr != '\\' ) { + break; + } + + Com_DPrintf( "server: %d ip: %d.%d.%d.%d:%d\n",numservers, + addresses[numservers].ip[0], + addresses[numservers].ip[1], + addresses[numservers].ip[2], + addresses[numservers].ip[3], + addresses[numservers].port ); + + numservers++; + if ( numservers >= MAX_SERVERSPERPACKET ) { + break; + } + + // parse out EOT + if ( buffptr[1] == 'E' && buffptr[2] == 'O' && buffptr[3] == 'T' ) { + break; + } + } + + if ( cls.masterNum == 0 ) { + count = cls.numglobalservers; + max = MAX_GLOBAL_SERVERS; + } else { + count = cls.nummplayerservers; + max = MAX_OTHER_SERVERS; + } + + for ( i = 0; i < numservers && count < max; i++ ) { + // build net address + serverInfo_t *server = ( cls.masterNum == 0 ) ? &cls.globalServers[count] : &cls.mplayerServers[count]; + + CL_InitServerInfo( server, &addresses[i] ); + // advance to next slot + count++; + } + + // if getting the global list + if ( cls.masterNum == 0 ) { + if ( cls.numGlobalServerAddresses < MAX_GLOBAL_SERVERS ) { + // if we couldn't store the servers in the main list anymore + for (; i < numservers && count >= max; i++ ) { + serverAddress_t *addr; + // just store the addresses in an additional list + addr = &cls.globalServerAddresses[cls.numGlobalServerAddresses++]; + addr->ip[0] = addresses[i].ip[0]; + addr->ip[1] = addresses[i].ip[1]; + addr->ip[2] = addresses[i].ip[2]; + addr->ip[3] = addresses[i].ip[3]; + addr->port = addresses[i].port; + } + } + } + + if ( cls.masterNum == 0 ) { + cls.numglobalservers = count; + total = count + cls.numGlobalServerAddresses; + } else { + cls.nummplayerservers = count; + total = count; + } + + Com_Printf( "%d servers parsed (total %d)\n", numservers, total ); +} + +/* +================= +CL_ConnectionlessPacket + +Responses to broadcasts, etc +================= +*/ +void CL_ConnectionlessPacket( netadr_t from, msg_t *msg ) { + char *s; + char *c; + + MSG_BeginReadingOOB( msg ); + MSG_ReadLong( msg ); // skip the -1 + + s = MSG_ReadStringLine( msg ); + + Cmd_TokenizeString( s ); + + c = Cmd_Argv( 0 ); + + Com_DPrintf( "CL packet %s: %s\n", NET_AdrToString( from ), c ); + + // challenge from the server we are connecting to + if ( !Q_stricmp( c, "challengeResponse" ) ) { + if ( cls.state != CA_CONNECTING ) { + Com_Printf( "Unwanted challenge response received. Ignored.\n" ); + } else { + // start sending challenge repsonse instead of challenge request packets + clc.challenge = atoi( Cmd_Argv( 1 ) ); + cls.state = CA_CHALLENGING; + clc.connectPacketCount = 0; + clc.connectTime = -99999; + + // take this address as the new server address. This allows + // a server proxy to hand off connections to multiple servers + clc.serverAddress = from; + } + return; + } + + // server connection + if ( !Q_stricmp( c, "connectResponse" ) ) { + if ( cls.state >= CA_CONNECTED ) { + Com_Printf( "Dup connect received. Ignored.\n" ); + return; + } + if ( cls.state != CA_CHALLENGING ) { + Com_Printf( "connectResponse packet while not connecting. Ignored.\n" ); + return; + } + if ( !NET_CompareBaseAdr( from, clc.serverAddress ) ) { + Com_Printf( "connectResponse from a different address. Ignored.\n" ); + Com_Printf( "%s should have been %s\n", NET_AdrToString( from ), + NET_AdrToString( clc.serverAddress ) ); + return; + } + Netchan_Setup( NS_CLIENT, &clc.netchan, from, Cvar_VariableValue( "net_qport" ) ); + cls.state = CA_CONNECTED; + clc.lastPacketSentTime = -9999; // send first packet immediately + return; + } + + // server responding to an info broadcast + if ( !Q_stricmp( c, "infoResponse" ) ) { + CL_ServerInfoPacket( from, msg ); + return; + } + + // server responding to a get playerlist + if ( !Q_stricmp( c, "statusResponse" ) ) { + CL_ServerStatusResponse( from, msg ); + return; + } + + // a disconnect message from the server, which will happen if the server + // dropped the connection but it is still getting packets from us + if ( !Q_stricmp( c, "disconnect" ) ) { + CL_DisconnectPacket( from ); + return; + } + + // echo request from server + if ( !Q_stricmp( c, "echo" ) ) { + NET_OutOfBandPrint( NS_CLIENT, from, "%s", Cmd_Argv( 1 ) ); + return; + } + + // cd check + if ( !Q_stricmp( c, "keyAuthorize" ) ) { + // we don't use these now, so dump them on the floor + return; + } + + // global MOTD from id + if ( !Q_stricmp( c, "motd" ) ) { + CL_MotdPacket( from ); + return; + } + + // echo request from server + if ( !Q_stricmp( c, "print" ) ) { + s = MSG_ReadString( msg ); + Q_strncpyz( clc.serverMessage, s, sizeof( clc.serverMessage ) ); + Com_Printf( "%s", s ); + return; + } + + // echo request from server + if ( !Q_stricmp( c, "getserversResponse\\" ) ) { + CL_ServersResponsePacket( from, msg ); + return; + } + + Com_DPrintf( "Unknown connectionless packet command.\n" ); +} + + +/* +================= +CL_PacketEvent + +A packet has arrived from the main event loop +================= +*/ +void CL_PacketEvent( netadr_t from, msg_t *msg ) { + int headerBytes; + + clc.lastPacketTime = cls.realtime; + + if ( msg->cursize >= 4 && *(int *)msg->data == -1 ) { + CL_ConnectionlessPacket( from, msg ); + return; + } + + if ( cls.state < CA_CONNECTED ) { + return; // can't be a valid sequenced packet + } + + if ( msg->cursize < 4 ) { + Com_Printf( "%s: Runt packet\n",NET_AdrToString( from ) ); + return; + } + + // + // packet from server + // + if ( !NET_CompareAdr( from, clc.netchan.remoteAddress ) ) { + Com_DPrintf( "%s:sequenced packet without connection\n" + ,NET_AdrToString( from ) ); + // FIXME: send a client disconnect? + return; + } + + if ( !CL_Netchan_Process( &clc.netchan, msg ) ) { + return; // out of order, duplicated, etc + } + + // the header is different lengths for reliable and unreliable messages + headerBytes = msg->readcount; + + // track the last message received so it can be returned in + // client messages, allowing the server to detect a dropped + // gamestate + clc.serverMessageSequence = LittleLong( *(int *)msg->data ); + + clc.lastPacketTime = cls.realtime; + CL_ParseServerMessage( msg ); + + // + // we don't know if it is ok to save a demo message until + // after we have parsed the frame + // + if ( clc.demorecording && !clc.demowaiting ) { + CL_WriteDemoMessage( msg, headerBytes ); + } +} + +/* +================== +CL_CheckTimeout + +================== +*/ +void CL_CheckTimeout( void ) { + // + // check timeout + // + if ( ( !cl_paused->integer || !sv_paused->integer ) + && cls.state >= CA_CONNECTED && cls.state != CA_CINEMATIC + && cls.realtime - clc.lastPacketTime > cl_timeout->value * 1000 ) { + if ( ++cl.timeoutcount > 5 ) { // timeoutcount saves debugger + Com_Printf( "\nServer connection timed out.\n" ); + CL_Disconnect( qtrue ); + return; + } + } else { + cl.timeoutcount = 0; + } +} + + +//============================================================================ + +/* +================== +CL_CheckUserinfo + +================== +*/ +void CL_CheckUserinfo( void ) { + // don't add reliable commands when not yet connected + if ( cls.state < CA_CHALLENGING ) { + return; + } + // don't overflow the reliable command buffer when paused + if ( cl_paused->integer ) { + return; + } + // send a reliable userinfo update if needed + if ( cvar_modifiedFlags & CVAR_USERINFO ) { + cvar_modifiedFlags &= ~CVAR_USERINFO; + CL_AddReliableCommand( va( "userinfo \"%s\"", Cvar_InfoString( CVAR_USERINFO ) ) ); + } + +} + +/* +================== +CL_Frame + +================== +*/ +void CL_Frame( int msec ) { + + if ( !com_cl_running->integer ) { + return; + } + + if ( cls.cddialog ) { + // bring up the cd error dialog if needed + cls.cddialog = qfalse; +#ifdef __MACOS__ //DAJ hide the cursor for intro movie + VM_Call( uivm, UI_SET_ACTIVE_MENU, UIMENU_BRIEFING ); +#else + VM_Call( uivm, UI_SET_ACTIVE_MENU, UIMENU_NEED_CD ); +#endif + } else if ( cls.endgamemenu ) { + cls.endgamemenu = qfalse; + VM_Call( uivm, UI_SET_ACTIVE_MENU, UIMENU_ENDGAME ); + } else if ( cls.state == CA_DISCONNECTED && !( cls.keyCatchers & KEYCATCH_UI ) + && !com_sv_running->integer ) { + // if disconnected, bring up the menu + S_StopAllSounds(); + VM_Call( uivm, UI_SET_ACTIVE_MENU, UIMENU_MAIN ); + } + + // if recording an avi, lock to a fixed fps + if ( cl_avidemo->integer && msec ) { + // save the current screen + if ( cls.state == CA_ACTIVE || cl_forceavidemo->integer ) { + Cbuf_ExecuteText( EXEC_NOW, "screenshot silent\n" ); + } + // fixed time for next frame + msec = ( 1000 / cl_avidemo->integer ) * com_timescale->value; + if ( msec == 0 ) { + msec = 1; + } + } + + // save the msec before checking pause + cls.realFrametime = msec; + + // decide the simulation time + cls.frametime = msec; + + cls.realtime += cls.frametime; + + if ( cl_timegraph->integer ) { + SCR_DebugGraph( cls.realFrametime * 0.25, 0 ); + } + + // see if we need to update any userinfo + CL_CheckUserinfo(); + + // if we haven't gotten a packet in a long time, + // drop the connection + CL_CheckTimeout(); + + // send intentions now + CL_SendCmd(); + + // resend a connection request if necessary + CL_CheckForResend(); + + // decide on the serverTime to render + CL_SetCGameTime(); + + // update the screen + SCR_UpdateScreen(); + + // Ridah, don't update if we're doing a quick reload +// if (Cvar_VariableIntegerValue("savegame_loading") != 2) { +// // if waiting at intermission, don't update sound +// char buf[MAX_QPATH]; +// Cvar_VariableStringBuffer( "g_missionStats", buf, sizeof(buf) ); +// if (strlen(buf) <= 1 ) { +// // update audio + S_Update(); +// } +// } + + // advance local effects for next frame + SCR_RunCinematic(); + + Con_RunConsole(); + + cls.framecount++; +} + + +//============================================================================ +// Ridah, startup-caching system +typedef struct { + char name[MAX_QPATH]; + int hits; + int lastSetIndex; +} cacheItem_t; +typedef enum { + CACHE_SOUNDS, + CACHE_MODELS, + CACHE_IMAGES, + + CACHE_NUMGROUPS +} cacheGroup_t; +static cacheItem_t cacheGroups[CACHE_NUMGROUPS] = { + {{'s','o','u','n','d',0}, CACHE_SOUNDS}, + {{'m','o','d','e','l',0}, CACHE_MODELS}, + {{'i','m','a','g','e',0}, CACHE_IMAGES}, +}; +#define MAX_CACHE_ITEMS 4096 +#define CACHE_HIT_RATIO 0.75 // if hit on this percentage of maps, it'll get cached + +static int cacheIndex; +static cacheItem_t cacheItems[CACHE_NUMGROUPS][MAX_CACHE_ITEMS]; + +static void CL_Cache_StartGather_f( void ) { + cacheIndex = 0; + memset( cacheItems, 0, sizeof( cacheItems ) ); + + Cvar_Set( "cl_cacheGathering", "1" ); +} + +static void CL_Cache_UsedFile_f( void ) { + char groupStr[MAX_QPATH]; + char itemStr[MAX_QPATH]; + int i,group; + cacheItem_t *item; + + if ( Cmd_Argc() < 2 ) { + Com_Error( ERR_DROP, "usedfile without enough parameters\n" ); + return; + } + + strcpy( groupStr, Cmd_Argv( 1 ) ); + + strcpy( itemStr, Cmd_Argv( 2 ) ); + for ( i = 3; i < Cmd_Argc(); i++ ) { + strcat( itemStr, " " ); + strcat( itemStr, Cmd_Argv( i ) ); + } + Q_strlwr( itemStr ); + + // find the cache group + for ( i = 0; i < CACHE_NUMGROUPS; i++ ) { + if ( !Q_strncmp( groupStr, cacheGroups[i].name, MAX_QPATH ) ) { + break; + } + } + if ( i == CACHE_NUMGROUPS ) { + Com_Error( ERR_DROP, "usedfile without a valid cache group\n" ); + return; + } + + // see if it's already there + group = i; + for ( i = 0, item = cacheItems[group]; i < MAX_CACHE_ITEMS; i++, item++ ) { + if ( !item->name[0] ) { + // didn't find it, so add it here + Q_strncpyz( item->name, itemStr, MAX_QPATH ); + if ( cacheIndex > 9999 ) { // hack, but yeh + item->hits = cacheIndex; + } else { + item->hits++; + } + item->lastSetIndex = cacheIndex; + break; + } + if ( item->name[0] == itemStr[0] && !Q_strncmp( item->name, itemStr, MAX_QPATH ) ) { + if ( item->lastSetIndex != cacheIndex ) { + item->hits++; + item->lastSetIndex = cacheIndex; + } + break; + } + } +} + +static void CL_Cache_SetIndex_f( void ) { + if ( Cmd_Argc() < 2 ) { + Com_Error( ERR_DROP, "setindex needs an index\n" ); + return; + } + + cacheIndex = atoi( Cmd_Argv( 1 ) ); +} + +static void CL_Cache_MapChange_f( void ) { + cacheIndex++; +} + +static void CL_Cache_EndGather_f( void ) { + // save the frequently used files to the cache list file + int i, j, handle, cachePass; + char filename[MAX_QPATH]; + + cachePass = (int)floor( (float)cacheIndex * CACHE_HIT_RATIO ); + + for ( i = 0; i < CACHE_NUMGROUPS; i++ ) { + Q_strncpyz( filename, cacheGroups[i].name, MAX_QPATH ); + Q_strcat( filename, MAX_QPATH, ".cache" ); + +#ifdef __MACOS__ //DAJ MacOS file typing + { + extern _MSL_IMP_EXP_C long _fcreator, _ftype; + _ftype = 'WlfB'; + _fcreator = 'WlfS'; + } +#endif + handle = FS_FOpenFileWrite( filename ); + + for ( j = 0; j < MAX_CACHE_ITEMS; j++ ) { + // if it's a valid filename, and it's been hit enough times, cache it + if ( cacheItems[i][j].hits >= cachePass && strstr( cacheItems[i][j].name, "/" ) ) { + FS_Write( cacheItems[i][j].name, strlen( cacheItems[i][j].name ), handle ); + FS_Write( "\n", 1, handle ); + } + } + + FS_FCloseFile( handle ); + } + + Cvar_Set( "cl_cacheGathering", "0" ); +} + +// done. +//============================================================================ + +/* +================ +CL_MapRestart_f +================ +*/ +void CL_MapRestart_f( void ) { + if ( !com_cl_running ) { + return; + } + if ( !com_cl_running->integer ) { + return; + } + Com_Printf( "This command is no longer functional.\nUse \"loadgame current\" to load the current map." ); +} + +/* +================ +CL_SetRecommended_f +================ +*/ +void CL_SetRecommended_f( void ) { + if ( Cmd_Argc() > 1 ) { + Com_SetRecommended( qtrue ); + } else { + Com_SetRecommended( qfalse ); + } + +} + + + +/* +================ +CL_RefPrintf + +DLL glue +================ +*/ +#define MAXPRINTMSG 4096 +void QDECL CL_RefPrintf( int print_level, const char *fmt, ... ) { + va_list argptr; + char msg[MAXPRINTMSG]; + + va_start( argptr,fmt ); + vsprintf( msg,fmt,argptr ); + va_end( argptr ); + + if ( print_level == PRINT_ALL ) { + Com_Printf( "%s", msg ); + } else if ( print_level == PRINT_WARNING ) { + Com_Printf( S_COLOR_YELLOW "%s", msg ); // yellow + } else if ( print_level == PRINT_DEVELOPER ) { + Com_DPrintf( S_COLOR_RED "%s", msg ); // red + } +} + + + +/* +============ +CL_ShutdownRef +============ +*/ +void CL_ShutdownRef( void ) { + if ( !re.Shutdown ) { + return; + } + re.Shutdown( qtrue ); + memset( &re, 0, sizeof( re ) ); +} + +/* +============ +CL_InitRenderer +============ +*/ +void CL_InitRenderer( void ) { + // this sets up the renderer and calls R_Init + re.BeginRegistration( &cls.glconfig ); + + // load character sets + cls.charSetShader = re.RegisterShader( "gfx/2d/bigchars" ); + cls.whiteShader = re.RegisterShader( "white" ); + cls.consoleShader = re.RegisterShader( "console" ); + cls.consoleShader2 = re.RegisterShader( "console2" ); + g_console_field_width = cls.glconfig.vidWidth / SMALLCHAR_WIDTH - 2; + g_consoleField.widthInChars = g_console_field_width; +} + +/* +============================ +CL_StartHunkUsers + +After the server has cleared the hunk, these will need to be restarted +This is the only place that any of these functions are called from +============================ +*/ +void CL_StartHunkUsers( void ) { + if ( !com_cl_running ) { + return; + } + + if ( !com_cl_running->integer ) { + return; + } + + if ( !cls.rendererStarted ) { + cls.rendererStarted = qtrue; + CL_InitRenderer(); + } + + if ( !cls.soundStarted ) { + cls.soundStarted = qtrue; + S_Init(); + } + + if ( !cls.soundRegistered ) { + cls.soundRegistered = qtrue; + S_BeginRegistration(); + } + + if ( !cls.uiStarted ) { + cls.uiStarted = qtrue; + CL_InitUI(); + } +} + + +int CL_ScaledMilliseconds( void ) { + return Sys_Milliseconds() * com_timescale->value; +} + +/* +============ +CL_InitRef +============ +*/ +void CL_InitRef( void ) { + refimport_t ri; + refexport_t *ret; + + Com_Printf( "----- Initializing Renderer ----\n" ); + + ri.Cmd_AddCommand = Cmd_AddCommand; + ri.Cmd_RemoveCommand = Cmd_RemoveCommand; + ri.Cmd_Argc = Cmd_Argc; + ri.Cmd_Argv = Cmd_Argv; + ri.Cmd_ExecuteText = Cbuf_ExecuteText; + ri.Printf = CL_RefPrintf; + ri.Error = Com_Error; + ri.Milliseconds = CL_ScaledMilliseconds; + ri.Hunk_Clear = Hunk_ClearToMark; +#ifdef HUNK_DEBUG + ri.Hunk_AllocDebug = Hunk_AllocDebug; +#else + ri.Hunk_Alloc = Hunk_Alloc; +#endif + ri.Hunk_AllocateTempMemory = Hunk_AllocateTempMemory; + ri.Hunk_FreeTempMemory = Hunk_FreeTempMemory; + ri.CM_DrawDebugSurface = CM_DrawDebugSurface; + ri.FS_ReadFile = FS_ReadFile; + ri.FS_FreeFile = FS_FreeFile; + ri.FS_WriteFile = FS_WriteFile; + ri.FS_FreeFileList = FS_FreeFileList; + ri.FS_ListFiles = FS_ListFiles; + ri.FS_FileIsInPAK = FS_FileIsInPAK; + ri.FS_FileExists = FS_FileExists; + ri.Cvar_Get = Cvar_Get; + ri.Cvar_Set = Cvar_Set; + + // cinematic stuff + + ri.CIN_UploadCinematic = CIN_UploadCinematic; + ri.CIN_PlayCinematic = CIN_PlayCinematic; + ri.CIN_RunCinematic = CIN_RunCinematic; + + ret = GetRefAPI( REF_API_VERSION, &ri ); + +#if 0 // MrE defined __USEA3D && defined __A3D_GEOM + hA3Dg_ExportRenderGeom( ret ); +#endif + + Com_Printf( "-------------------------------\n" ); + + if ( !ret ) { + Com_Error( ERR_FATAL, "Couldn't initialize refresh" ); + } + + re = *ret; + + // unpause so the cgame definately gets a snapshot and renders a frame + Cvar_Set( "cl_paused", "0" ); +} + +// RF, trap manual client damage commands so users can't issue them manually +void CL_ClientDamageCommand( void ) { + // do nothing +} + +// NERVE - SMF +void CL_startMultiplayer_f( void ) { +#ifdef __MACOS__ //DAJ + Sys_StartProcess( "Wolfenstein MP", qtrue ); +#elif defined( __linux__ ) + Sys_StartProcess( "./wolf.x86", qtrue ); +#else + Sys_StartProcess( "WolfMP.exe", qtrue ); +#endif +} +// -NERVE - SMF + +//----(SA) added +/* +============== +CL_ShellExecute_URL_f +Format: + shellExecute "open" + +TTimo + show_bug.cgi?id=447 + only supporting "open" syntax for URL openings, others are not portable or need to be added on a case-by-case basis + the shellExecute syntax as been kept to remain compatible with win32 SP demo pk3, but this thing only does open URL + +============== +*/ + +void CL_ShellExecute_URL_f( void ) { + qboolean doexit; + + Com_DPrintf( "CL_ShellExecute_URL_f\n" ); + + if ( Q_stricmp( Cmd_Argv( 1 ),"open" ) ) { + Com_DPrintf( "invalid CL_ShellExecute_URL_f syntax (shellExecute \"open\" )\n" ); + return; + } + + if ( Cmd_Argc() < 4 ) { + doexit = qtrue; + } else { + doexit = (qboolean)( atoi( Cmd_Argv( 3 ) ) ); + } + + Sys_OpenURL( Cmd_Argv( 2 ),doexit ); +} +//----(SA) end +//=========================================================================================== + +/* +==================== +CL_Init +==================== +*/ +void CL_Init( void ) { + Com_Printf( "----- Client Initialization -----\n" ); + + Con_Init(); + + CL_ClearState(); + + cls.state = CA_DISCONNECTED; // no longer CA_UNINITIALIZED + + cls.realtime = 0; + + CL_InitInput(); + + // + // register our variables + // + cl_noprint = Cvar_Get( "cl_noprint", "0", 0 ); + cl_motd = Cvar_Get( "cl_motd", "1", 0 ); + + cl_timeout = Cvar_Get( "cl_timeout", "200", 0 ); + + cl_timeNudge = Cvar_Get( "cl_timeNudge", "0", CVAR_TEMP ); + cl_shownet = Cvar_Get( "cl_shownet", "0", CVAR_TEMP ); + cl_showSend = Cvar_Get( "cl_showSend", "0", CVAR_TEMP ); + cl_showTimeDelta = Cvar_Get( "cl_showTimeDelta", "0", CVAR_TEMP ); + cl_freezeDemo = Cvar_Get( "cl_freezeDemo", "0", CVAR_TEMP ); + rcon_client_password = Cvar_Get( "rconPassword", "", CVAR_TEMP ); + cl_activeAction = Cvar_Get( "activeAction", "", CVAR_TEMP ); + + cl_timedemo = Cvar_Get( "timedemo", "0", 0 ); + cl_avidemo = Cvar_Get( "cl_avidemo", "0", 0 ); + cl_forceavidemo = Cvar_Get( "cl_forceavidemo", "0", 0 ); + + rconAddress = Cvar_Get( "rconAddress", "", 0 ); + + cl_yawspeed = Cvar_Get( "cl_yawspeed", "140", CVAR_ARCHIVE ); + cl_pitchspeed = Cvar_Get( "cl_pitchspeed", "140", CVAR_ARCHIVE ); + cl_anglespeedkey = Cvar_Get( "cl_anglespeedkey", "1.5", 0 ); + + cl_maxpackets = Cvar_Get( "cl_maxpackets", "30", CVAR_ARCHIVE ); + cl_packetdup = Cvar_Get( "cl_packetdup", "1", CVAR_ARCHIVE ); + + cl_run = Cvar_Get( "cl_run", "1", CVAR_ARCHIVE ); + cl_sensitivity = Cvar_Get( "sensitivity", "5", CVAR_ARCHIVE ); + cl_mouseAccel = Cvar_Get( "cl_mouseAccel", "0", CVAR_ARCHIVE ); + cl_freelook = Cvar_Get( "cl_freelook", "1", CVAR_ARCHIVE ); + + cl_showMouseRate = Cvar_Get( "cl_showmouserate", "0", 0 ); + + cl_allowDownload = Cvar_Get( "cl_allowDownload", "0", CVAR_ARCHIVE ); + + // init autoswitch so the ui will have it correctly even + // if the cgame hasn't been started + Cvar_Get( "cg_autoswitch", "2", CVAR_ARCHIVE ); + + // Rafael - particle switch + Cvar_Get( "cg_wolfparticles", "1", CVAR_ARCHIVE ); + // done + + cl_conXOffset = Cvar_Get( "cl_conXOffset", "0", 0 ); + cl_inGameVideo = Cvar_Get( "r_inGameVideo", "1", CVAR_ARCHIVE ); + + cl_serverStatusResendTime = Cvar_Get( "cl_serverStatusResendTime", "750", 0 ); + + // RF + cl_recoilPitch = Cvar_Get( "cg_recoilPitch", "0", CVAR_ROM ); + + m_pitch = Cvar_Get( "m_pitch", "0.022", CVAR_ARCHIVE ); + m_yaw = Cvar_Get( "m_yaw", "0.022", CVAR_ARCHIVE ); + m_forward = Cvar_Get( "m_forward", "0.25", CVAR_ARCHIVE ); + m_side = Cvar_Get( "m_side", "0.25", CVAR_ARCHIVE ); + m_filter = Cvar_Get( "m_filter", "0", CVAR_ARCHIVE ); + + cl_motdString = Cvar_Get( "cl_motdString", "", CVAR_ROM ); + + Cvar_Get( "cl_maxPing", "800", CVAR_ARCHIVE ); + + // userinfo + Cvar_Get( "name", "Player", CVAR_USERINFO | CVAR_ARCHIVE ); + Cvar_Get( "rate", "3000", CVAR_USERINFO | CVAR_ARCHIVE ); + Cvar_Get( "snaps", "20", CVAR_USERINFO | CVAR_ARCHIVE ); + Cvar_Get( "model", "bj2", CVAR_USERINFO | CVAR_ARCHIVE ); // temp until we have an skeletal american model + Cvar_Get( "head", "default", CVAR_USERINFO | CVAR_ARCHIVE ); + Cvar_Get( "color", "4", CVAR_USERINFO | CVAR_ARCHIVE ); + Cvar_Get( "handicap", "100", CVAR_USERINFO | CVAR_ARCHIVE ); + Cvar_Get( "sex", "male", CVAR_USERINFO | CVAR_ARCHIVE ); + Cvar_Get( "cl_anonymous", "0", CVAR_USERINFO | CVAR_ARCHIVE ); + + Cvar_Get( "password", "", CVAR_USERINFO ); + Cvar_Get( "cg_predictItems", "1", CVAR_USERINFO | CVAR_ARCHIVE ); + +//----(SA) added + Cvar_Get( "cg_autoactivate", "1", CVAR_USERINFO | CVAR_ARCHIVE ); + Cvar_Get( "cg_emptyswitch", "0", CVAR_USERINFO | CVAR_ARCHIVE ); +//----(SA) end + + // cgame might not be initialized before menu is used + Cvar_Get( "cg_viewsize", "100", CVAR_ARCHIVE ); + + cl_missionStats = Cvar_Get( "g_missionStats", "0", CVAR_ROM ); + cl_waitForFire = Cvar_Get( "cl_waitForFire", "0", CVAR_ROM ); + + // NERVE - SMF - localization + cl_language = Cvar_Get( "cl_language", "0", CVAR_ARCHIVE ); + cl_debugTranslation = Cvar_Get( "cl_debugTranslation", "0", 0 ); + // -NERVE - SMF + + // + // register our commands + // + Cmd_AddCommand( "cmd", CL_ForwardToServer_f ); + Cmd_AddCommand( "configstrings", CL_Configstrings_f ); + Cmd_AddCommand( "clientinfo", CL_Clientinfo_f ); + Cmd_AddCommand( "snd_restart", CL_Snd_Restart_f ); + Cmd_AddCommand( "vid_restart", CL_Vid_Restart_f ); + Cmd_AddCommand( "disconnect", CL_Disconnect_f ); + Cmd_AddCommand( "record", CL_Record_f ); + Cmd_AddCommand( "demo", CL_PlayDemo_f ); + Cmd_AddCommand( "cinematic", CL_PlayCinematic_f ); + Cmd_AddCommand( "stoprecord", CL_StopRecord_f ); + Cmd_AddCommand( "connect", CL_Connect_f ); + Cmd_AddCommand( "reconnect", CL_Reconnect_f ); + Cmd_AddCommand( "localservers", CL_LocalServers_f ); + Cmd_AddCommand( "globalservers", CL_GlobalServers_f ); + Cmd_AddCommand( "rcon", CL_Rcon_f ); + Cmd_AddCommand( "setenv", CL_Setenv_f ); + Cmd_AddCommand( "ping", CL_Ping_f ); + Cmd_AddCommand( "serverstatus", CL_ServerStatus_f ); + Cmd_AddCommand( "showip", CL_ShowIP_f ); + Cmd_AddCommand( "fs_openedList", CL_OpenedPK3List_f ); + Cmd_AddCommand( "fs_referencedList", CL_ReferencedPK3List_f ); + + // Ridah, startup-caching system + Cmd_AddCommand( "cache_startgather", CL_Cache_StartGather_f ); + Cmd_AddCommand( "cache_usedfile", CL_Cache_UsedFile_f ); + Cmd_AddCommand( "cache_setindex", CL_Cache_SetIndex_f ); + Cmd_AddCommand( "cache_mapchange", CL_Cache_MapChange_f ); + Cmd_AddCommand( "cache_endgather", CL_Cache_EndGather_f ); + + Cmd_AddCommand( "updatehunkusage", CL_UpdateLevelHunkUsage ); + Cmd_AddCommand( "updatescreen", SCR_UpdateScreen ); + // done. + + // RF, add this command so clients can't bind a key to send client damage commands to the server + Cmd_AddCommand( "cld", CL_ClientDamageCommand ); + + Cmd_AddCommand( "startMultiplayer", CL_startMultiplayer_f ); // NERVE - SMF + + // TTimo + // show_bug.cgi?id=447 + Cmd_AddCommand( "shellExecute", CL_ShellExecute_URL_f ); + //Cmd_AddCommand ( "shellExecute", CL_ShellExecute_f ); //----(SA) added (mainly for opening web pages from the menu) + + // RF, prevent users from issuing a map_restart manually + Cmd_AddCommand( "map_restart", CL_MapRestart_f ); + + Cmd_AddCommand( "setRecommended", CL_SetRecommended_f ); + + CL_InitRef(); + + SCR_Init(); + + Cbuf_Execute(); + + Cvar_Set( "cl_running", "1" ); + + Com_Printf( "----- Client Initialization Complete -----\n" ); +} + + +/* +=============== +CL_Shutdown + +=============== +*/ +void CL_Shutdown( void ) { + static qboolean recursive = qfalse; + + Com_Printf( "----- CL_Shutdown -----\n" ); + + if ( recursive ) { + printf( "recursive shutdown\n" ); + return; + } + recursive = qtrue; + + CL_Disconnect( qtrue ); + + S_Shutdown(); + CL_ShutdownRef(); + + CL_ShutdownUI(); + + Cmd_RemoveCommand( "cmd" ); + Cmd_RemoveCommand( "configstrings" ); + Cmd_RemoveCommand( "userinfo" ); + Cmd_RemoveCommand( "snd_restart" ); + Cmd_RemoveCommand( "vid_restart" ); + Cmd_RemoveCommand( "disconnect" ); + Cmd_RemoveCommand( "record" ); + Cmd_RemoveCommand( "demo" ); + Cmd_RemoveCommand( "cinematic" ); + Cmd_RemoveCommand( "stoprecord" ); + Cmd_RemoveCommand( "connect" ); + Cmd_RemoveCommand( "localservers" ); + Cmd_RemoveCommand( "globalservers" ); + Cmd_RemoveCommand( "rcon" ); + Cmd_RemoveCommand( "setenv" ); + Cmd_RemoveCommand( "ping" ); + Cmd_RemoveCommand( "serverstatus" ); + Cmd_RemoveCommand( "showip" ); + Cmd_RemoveCommand( "model" ); + + // Ridah, startup-caching system + Cmd_RemoveCommand( "cache_startgather" ); + Cmd_RemoveCommand( "cache_usedfile" ); + Cmd_RemoveCommand( "cache_setindex" ); + Cmd_RemoveCommand( "cache_mapchange" ); + Cmd_RemoveCommand( "cache_endgather" ); + + Cmd_RemoveCommand( "updatehunkusage" ); + // done. + + Cvar_Set( "cl_running", "0" ); + + recursive = qfalse; + + memset( &cls, 0, sizeof( cls ) ); + + Com_Printf( "-----------------------\n" ); +} + + +static void CL_SetServerInfo( serverInfo_t *server, const char *info, int ping ) { + if ( server ) { + if ( info ) { + server->clients = atoi( Info_ValueForKey( info, "clients" ) ); + Q_strncpyz( server->hostName,Info_ValueForKey( info, "hostname" ), MAX_NAME_LENGTH ); + Q_strncpyz( server->mapName, Info_ValueForKey( info, "mapname" ), MAX_NAME_LENGTH ); + server->maxClients = atoi( Info_ValueForKey( info, "sv_maxclients" ) ); + Q_strncpyz( server->game,Info_ValueForKey( info, "game" ), MAX_NAME_LENGTH ); + server->gameType = atoi( Info_ValueForKey( info, "gametype" ) ); + server->netType = atoi( Info_ValueForKey( info, "nettype" ) ); + server->minPing = atoi( Info_ValueForKey( info, "minping" ) ); + server->maxPing = atoi( Info_ValueForKey( info, "maxping" ) ); + server->allowAnonymous = atoi( Info_ValueForKey( info, "sv_allowAnonymous" ) ); + } + server->ping = ping; + } +} + +static void CL_SetServerInfoByAddress( netadr_t from, const char *info, int ping ) { + int i; + + for ( i = 0; i < MAX_OTHER_SERVERS; i++ ) { + if ( NET_CompareAdr( from, cls.localServers[i].adr ) ) { + CL_SetServerInfo( &cls.localServers[i], info, ping ); + } + } + + for ( i = 0; i < MAX_OTHER_SERVERS; i++ ) { + if ( NET_CompareAdr( from, cls.mplayerServers[i].adr ) ) { + CL_SetServerInfo( &cls.mplayerServers[i], info, ping ); + } + } + + for ( i = 0; i < MAX_GLOBAL_SERVERS; i++ ) { + if ( NET_CompareAdr( from, cls.globalServers[i].adr ) ) { + CL_SetServerInfo( &cls.globalServers[i], info, ping ); + } + } + + for ( i = 0; i < MAX_OTHER_SERVERS; i++ ) { + if ( NET_CompareAdr( from, cls.favoriteServers[i].adr ) ) { + CL_SetServerInfo( &cls.favoriteServers[i], info, ping ); + } + } + +} + +/* +=================== +CL_ServerInfoPacket +=================== +*/ +void CL_ServerInfoPacket( netadr_t from, msg_t *msg ) { + int i, type; + char info[MAX_INFO_STRING]; + char* str; + char *infoString; + int prot; + + infoString = MSG_ReadString( msg ); + + // if this isn't the correct protocol version, ignore it + prot = atoi( Info_ValueForKey( infoString, "protocol" ) ); + if ( prot != PROTOCOL_VERSION ) { + Com_DPrintf( "Different protocol info packet: %s\n", infoString ); +// return; + } + + // iterate servers waiting for ping response + for ( i = 0; i < MAX_PINGREQUESTS; i++ ) + { + if ( cl_pinglist[i].adr.port && !cl_pinglist[i].time && NET_CompareAdr( from, cl_pinglist[i].adr ) ) { + // calc ping time + cl_pinglist[i].time = cls.realtime - cl_pinglist[i].start + 1; + Com_DPrintf( "ping time %dms from %s\n", cl_pinglist[i].time, NET_AdrToString( from ) ); + + // save of info + Q_strncpyz( cl_pinglist[i].info, infoString, sizeof( cl_pinglist[i].info ) ); + + // tack on the net type + // NOTE: make sure these types are in sync with the netnames strings in the UI + switch ( from.type ) + { + case NA_BROADCAST: + case NA_IP: + str = "udp"; + type = 1; + break; + + case NA_IPX: + case NA_BROADCAST_IPX: + str = "ipx"; + type = 2; + break; + + default: + str = "???"; + type = 0; + break; + } + Info_SetValueForKey( cl_pinglist[i].info, "nettype", va( "%d", type ) ); + CL_SetServerInfoByAddress( from, infoString, cl_pinglist[i].time ); + + return; + } + } + + // if not just sent a local broadcast or pinging local servers + if ( cls.pingUpdateSource != AS_LOCAL ) { + return; + } + + for ( i = 0 ; i < MAX_OTHER_SERVERS ; i++ ) { + // empty slot + if ( cls.localServers[i].adr.port == 0 ) { + break; + } + + // avoid duplicate + if ( NET_CompareAdr( from, cls.localServers[i].adr ) ) { + return; + } + } + + if ( i == MAX_OTHER_SERVERS ) { + Com_DPrintf( "MAX_OTHER_SERVERS hit, dropping infoResponse\n" ); + return; + } + + // add this to the list + cls.numlocalservers = i + 1; + cls.localServers[i].adr = from; + cls.localServers[i].clients = 0; + cls.localServers[i].hostName[0] = '\0'; + cls.localServers[i].mapName[0] = '\0'; + cls.localServers[i].maxClients = 0; + cls.localServers[i].maxPing = 0; + cls.localServers[i].minPing = 0; + cls.localServers[i].ping = -1; + cls.localServers[i].game[0] = '\0'; + cls.localServers[i].gameType = 0; + cls.localServers[i].netType = from.type; + cls.localServers[i].allowAnonymous = 0; + + Q_strncpyz( info, MSG_ReadString( msg ), MAX_INFO_STRING ); + if ( strlen( info ) ) { + if ( info[strlen( info ) - 1] != '\n' ) { + strncat( info, "\n", sizeof( info ) ); + } + Com_Printf( "%s: %s", NET_AdrToString( from ), info ); + } +} + +/* +=================== +CL_GetServerStatus +=================== +*/ +serverStatus_t *CL_GetServerStatus( netadr_t from ) { + serverStatus_t *serverStatus; + int i, oldest, oldestTime; + + serverStatus = NULL; + for ( i = 0; i < MAX_SERVERSTATUSREQUESTS; i++ ) { + if ( NET_CompareAdr( from, cl_serverStatusList[i].address ) ) { + return &cl_serverStatusList[i]; + } + } + for ( i = 0; i < MAX_SERVERSTATUSREQUESTS; i++ ) { + if ( cl_serverStatusList[i].retrieved ) { + return &cl_serverStatusList[i]; + } + } + oldest = -1; + oldestTime = 0; + for ( i = 0; i < MAX_SERVERSTATUSREQUESTS; i++ ) { + if ( oldest == -1 || cl_serverStatusList[i].startTime < oldestTime ) { + oldest = i; + oldestTime = cl_serverStatusList[i].startTime; + } + } + if ( oldest != -1 ) { + return &cl_serverStatusList[oldest]; + } + serverStatusCount++; + return &cl_serverStatusList[serverStatusCount & ( MAX_SERVERSTATUSREQUESTS - 1 )]; +} + +/* +=================== +CL_ServerStatus +=================== +*/ +int CL_ServerStatus( char *serverAddress, char *serverStatusString, int maxLen ) { + int i; + netadr_t to; + serverStatus_t *serverStatus; + + // if no server address then reset all server status requests + if ( !serverAddress ) { + for ( i = 0; i < MAX_SERVERSTATUSREQUESTS; i++ ) { + cl_serverStatusList[i].address.port = 0; + cl_serverStatusList[i].retrieved = qtrue; + } + return qfalse; + } + // get the address + if ( !NET_StringToAdr( serverAddress, &to ) ) { + return qfalse; + } + serverStatus = CL_GetServerStatus( to ); + // if no server status string then reset the server status request for this address + if ( !serverStatusString ) { + serverStatus->retrieved = qtrue; + return qfalse; + } + + // if this server status request has the same address + if ( NET_CompareAdr( to, serverStatus->address ) ) { + // if we recieved an response for this server status request + if ( !serverStatus->pending ) { + Q_strncpyz( serverStatusString, serverStatus->string, maxLen ); + serverStatus->retrieved = qtrue; + serverStatus->startTime = 0; + return qtrue; + } + // resend the request regularly + else if ( serverStatus->startTime < Sys_Milliseconds() - cl_serverStatusResendTime->integer ) { + serverStatus->print = qfalse; + serverStatus->pending = qtrue; + serverStatus->retrieved = qfalse; + serverStatus->time = 0; + serverStatus->startTime = Sys_Milliseconds(); + NET_OutOfBandPrint( NS_CLIENT, to, "getstatus" ); + return qfalse; + } + } + // if retrieved + else if ( serverStatus->retrieved ) { + serverStatus->address = to; + serverStatus->print = qfalse; + serverStatus->pending = qtrue; + serverStatus->retrieved = qfalse; + serverStatus->startTime = Sys_Milliseconds(); + serverStatus->time = 0; + NET_OutOfBandPrint( NS_CLIENT, to, "getstatus" ); + return qfalse; + } + return qfalse; +} + +/* +=================== +CL_ServerStatusResponse +=================== +*/ +void CL_ServerStatusResponse( netadr_t from, msg_t *msg ) { + char *s; + char info[MAX_INFO_STRING]; + int i, l, score, ping; + int len; + serverStatus_t *serverStatus; + + serverStatus = NULL; + for ( i = 0; i < MAX_SERVERSTATUSREQUESTS; i++ ) { + if ( NET_CompareAdr( from, cl_serverStatusList[i].address ) ) { + serverStatus = &cl_serverStatusList[i]; + break; + } + } + // if we didn't request this server status + if ( !serverStatus ) { + return; + } + + s = MSG_ReadStringLine( msg ); + + len = 0; + Com_sprintf( &serverStatus->string[len], sizeof( serverStatus->string ) - len, "%s", s ); + + if ( serverStatus->print ) { + Com_Printf( "Server settings:\n" ); + // print cvars + while ( *s ) { + for ( i = 0; i < 2 && *s; i++ ) { + if ( *s == '\\' ) { + s++; + } + l = 0; + while ( *s ) { + info[l++] = *s; + if ( l >= MAX_INFO_STRING - 1 ) { + break; + } + s++; + if ( *s == '\\' ) { + break; + } + } + info[l] = '\0'; + if ( i ) { + Com_Printf( "%s\n", info ); + } else { + Com_Printf( "%-24s", info ); + } + } + } + } + + len = strlen( serverStatus->string ); + Com_sprintf( &serverStatus->string[len], sizeof( serverStatus->string ) - len, "\\" ); + + if ( serverStatus->print ) { + Com_Printf( "\nPlayers:\n" ); + Com_Printf( "num: score: ping: name:\n" ); + } + for ( i = 0, s = MSG_ReadStringLine( msg ); *s; s = MSG_ReadStringLine( msg ), i++ ) { + + len = strlen( serverStatus->string ); + Com_sprintf( &serverStatus->string[len], sizeof( serverStatus->string ) - len, "\\%s", s ); + + if ( serverStatus->print ) { + score = ping = 0; + sscanf( s, "%d %d", &score, &ping ); + s = strchr( s, ' ' ); + if ( s ) { + s = strchr( s + 1, ' ' ); + } + if ( s ) { + s++; + } else { + s = "unknown"; + } + Com_Printf( "%-2d %-3d %-3d %s\n", i, score, ping, s ); + } + } + len = strlen( serverStatus->string ); + Com_sprintf( &serverStatus->string[len], sizeof( serverStatus->string ) - len, "\\" ); + + serverStatus->time = Sys_Milliseconds(); + serverStatus->address = from; + serverStatus->pending = qfalse; + if ( serverStatus->print ) { + serverStatus->retrieved = qtrue; + } +} + +/* +================== +CL_LocalServers_f +================== +*/ +void CL_LocalServers_f( void ) { + char *message; + int i, j; + netadr_t to; + + Com_Printf( "Scanning for servers on the local network...\n" ); + + // reset the list, waiting for response + cls.numlocalservers = 0; + cls.pingUpdateSource = AS_LOCAL; + + for ( i = 0; i < MAX_OTHER_SERVERS; i++ ) { + qboolean b = cls.localServers[i].visible; + Com_Memset( &cls.localServers[i], 0, sizeof( cls.localServers[i] ) ); + cls.localServers[i].visible = b; + } + Com_Memset( &to, 0, sizeof( to ) ); + + // The 'xxx' in the message is a challenge that will be echoed back + // by the server. We don't care about that here, but master servers + // can use that to prevent spoofed server responses from invalid ip + message = "\377\377\377\377getinfo xxx"; + + // send each message twice in case one is dropped + for ( i = 0 ; i < 2 ; i++ ) { + // send a broadcast packet on each server port + // we support multiple server ports so a single machine + // can nicely run multiple servers + for ( j = 0 ; j < NUM_SERVER_PORTS ; j++ ) { + to.port = BigShort( (short)( PORT_SERVER + j ) ); + + to.type = NA_BROADCAST; + NET_SendPacket( NS_CLIENT, strlen( message ), message, to ); + + to.type = NA_BROADCAST_IPX; + NET_SendPacket( NS_CLIENT, strlen( message ), message, to ); + } + } +} + +/* +================== +CL_GlobalServers_f +================== +*/ +void CL_GlobalServers_f( void ) { + netadr_t to; + int i; + int count; + char *buffptr; + char command[1024]; + + if ( Cmd_Argc() < 3 ) { + Com_Printf( "usage: globalservers [keywords]\n" ); + return; + } + + cls.masterNum = atoi( Cmd_Argv( 1 ) ); + + Com_Printf( "Requesting servers from the master...\n" ); + + // reset the list, waiting for response + // -1 is used to distinguish a "no response" + + if ( cls.masterNum == 1 ) { + NET_StringToAdr( "master.quake3world.com", &to ); + cls.nummplayerservers = -1; + cls.pingUpdateSource = AS_MPLAYER; + } else { + NET_StringToAdr( MASTER_SERVER_NAME, &to ); + cls.numglobalservers = -1; + cls.pingUpdateSource = AS_GLOBAL; + } + to.type = NA_IP; + to.port = BigShort( PORT_MASTER ); + + sprintf( command, "getservers %s", Cmd_Argv( 2 ) ); + + // tack on keywords + buffptr = command + strlen( command ); + count = Cmd_Argc(); + for ( i = 3; i < count; i++ ) + buffptr += sprintf( buffptr, " %s", Cmd_Argv( i ) ); + + // if we are a demo, automatically add a "demo" keyword + if ( Cvar_VariableValue( "fs_restrict" ) ) { + buffptr += sprintf( buffptr, " demo" ); + } + + NET_OutOfBandPrint( NS_SERVER, to, command ); +} + + +/* +================== +CL_GetPing +================== +*/ +void CL_GetPing( int n, char *buf, int buflen, int *pingtime ) { + const char *str; + int time; + int maxPing; + + if ( !cl_pinglist[n].adr.port ) { + // empty slot + buf[0] = '\0'; + *pingtime = 0; + return; + } + + str = NET_AdrToString( cl_pinglist[n].adr ); + Q_strncpyz( buf, str, buflen ); + + time = cl_pinglist[n].time; + if ( !time ) { + // check for timeout + time = cls.realtime - cl_pinglist[n].start; + maxPing = Cvar_VariableIntegerValue( "cl_maxPing" ); + if ( maxPing < 100 ) { + maxPing = 100; + } + if ( time < maxPing ) { + // not timed out yet + time = 0; + } + } + + CL_SetServerInfoByAddress( cl_pinglist[n].adr, cl_pinglist[n].info, cl_pinglist[n].time ); + + *pingtime = time; +} + +/* +================== +CL_UpdateServerInfo +================== +*/ +void CL_UpdateServerInfo( int n ) { + if ( !cl_pinglist[n].adr.port ) { + return; + } + + CL_SetServerInfoByAddress( cl_pinglist[n].adr, cl_pinglist[n].info, cl_pinglist[n].time ); +} + +/* +================== +CL_GetPingInfo +================== +*/ +void CL_GetPingInfo( int n, char *buf, int buflen ) { + if ( !cl_pinglist[n].adr.port ) { + // empty slot + if ( buflen ) { + buf[0] = '\0'; + } + return; + } + + Q_strncpyz( buf, cl_pinglist[n].info, buflen ); +} + +/* +================== +CL_ClearPing +================== +*/ +void CL_ClearPing( int n ) { + if ( n < 0 || n >= MAX_PINGREQUESTS ) { + return; + } + + cl_pinglist[n].adr.port = 0; +} + +/* +================== +CL_GetPingQueueCount +================== +*/ +int CL_GetPingQueueCount( void ) { + int i; + int count; + ping_t* pingptr; + + count = 0; + pingptr = cl_pinglist; + + for ( i = 0; i < MAX_PINGREQUESTS; i++, pingptr++ ) { + if ( pingptr->adr.port ) { + count++; + } + } + + return ( count ); +} + +/* +================== +CL_GetFreePing +================== +*/ +ping_t* CL_GetFreePing( void ) { + ping_t* pingptr; + ping_t* best; + int oldest; + int i; + int time; + + pingptr = cl_pinglist; + for ( i = 0; i < MAX_PINGREQUESTS; i++, pingptr++ ) + { + // find free ping slot + if ( pingptr->adr.port ) { + if ( !pingptr->time ) { + if ( cls.realtime - pingptr->start < 500 ) { + // still waiting for response + continue; + } + } else if ( pingptr->time < 500 ) { + // results have not been queried + continue; + } + } + + // clear it + pingptr->adr.port = 0; + return ( pingptr ); + } + + // use oldest entry + pingptr = cl_pinglist; + best = cl_pinglist; + oldest = INT_MIN; + for ( i = 0; i < MAX_PINGREQUESTS; i++, pingptr++ ) + { + // scan for oldest + time = cls.realtime - pingptr->start; + if ( time > oldest ) { + oldest = time; + best = pingptr; + } + } + + return ( best ); +} + +/* +================== +CL_Ping_f +================== +*/ +void CL_Ping_f( void ) { + netadr_t to; + ping_t* pingptr; + char* server; + + if ( Cmd_Argc() != 2 ) { + Com_Printf( "usage: ping [server]\n" ); + return; + } + + memset( &to, 0, sizeof( netadr_t ) ); + + server = Cmd_Argv( 1 ); + + if ( !NET_StringToAdr( server, &to ) ) { + return; + } + + pingptr = CL_GetFreePing(); + + memcpy( &pingptr->adr, &to, sizeof( netadr_t ) ); + pingptr->start = cls.realtime; + pingptr->time = 0; + + CL_SetServerInfoByAddress( pingptr->adr, NULL, 0 ); + + NET_OutOfBandPrint( NS_CLIENT, to, "getinfo xxx" ); +} + +/* +================== +CL_UpdateVisiblePings_f +================== +*/ +qboolean CL_UpdateVisiblePings_f( int source ) { + int slots, i; + char buff[MAX_STRING_CHARS]; + int pingTime; + int max; + qboolean status = qfalse; + + if ( source < 0 || source > AS_FAVORITES ) { + return qfalse; + } + + cls.pingUpdateSource = source; + + slots = CL_GetPingQueueCount(); + if ( slots < MAX_PINGREQUESTS ) { + serverInfo_t *server = NULL; + + max = ( source == AS_GLOBAL ) ? MAX_GLOBAL_SERVERS : MAX_OTHER_SERVERS; + switch ( source ) { + case AS_LOCAL: + server = &cls.localServers[0]; + max = cls.numlocalservers; + break; + case AS_MPLAYER: + server = &cls.mplayerServers[0]; + max = cls.nummplayerservers; + break; + case AS_GLOBAL: + server = &cls.globalServers[0]; + max = cls.numglobalservers; + break; + case AS_FAVORITES: + server = &cls.favoriteServers[0]; + max = cls.numfavoriteservers; + break; + } + for ( i = 0; i < max; i++ ) { + if ( server[i].visible ) { + if ( server[i].ping == -1 ) { + int j; + + if ( slots >= MAX_PINGREQUESTS ) { + break; + } + for ( j = 0; j < MAX_PINGREQUESTS; j++ ) { + if ( !cl_pinglist[j].adr.port ) { + continue; + } + if ( NET_CompareAdr( cl_pinglist[j].adr, server[i].adr ) ) { + // already on the list + break; + } + } + if ( j >= MAX_PINGREQUESTS ) { + status = qtrue; + for ( j = 0; j < MAX_PINGREQUESTS; j++ ) { + if ( !cl_pinglist[j].adr.port ) { + break; + } + } + memcpy( &cl_pinglist[j].adr, &server[i].adr, sizeof( netadr_t ) ); + cl_pinglist[j].start = cls.realtime; + cl_pinglist[j].time = 0; + NET_OutOfBandPrint( NS_CLIENT, cl_pinglist[j].adr, "getinfo xxx" ); + slots++; + } + } + // if the server has a ping higher than cl_maxPing or + // the ping packet got lost + else if ( server[i].ping == 0 ) { + // if we are updating global servers + if ( source == AS_GLOBAL ) { + // + if ( cls.numGlobalServerAddresses > 0 ) { + // overwrite this server with one from the additional global servers + cls.numGlobalServerAddresses--; + CL_InitServerInfo( &server[i], &cls.globalServerAddresses[cls.numGlobalServerAddresses] ); + // NOTE: the server[i].visible flag stays untouched + } + } + } + } + } + } + + if ( slots ) { + status = qtrue; + } + for ( i = 0; i < MAX_PINGREQUESTS; i++ ) { + if ( !cl_pinglist[i].adr.port ) { + continue; + } + CL_GetPing( i, buff, MAX_STRING_CHARS, &pingTime ); + if ( pingTime != 0 ) { + CL_ClearPing( i ); + status = qtrue; + } + } + + return status; +} + +/* +================== +CL_ServerStatus_f +================== +*/ +void CL_ServerStatus_f( void ) { + netadr_t to; + char *server; + serverStatus_t *serverStatus; + + Com_Memset( &to, 0, sizeof( netadr_t ) ); + + if ( Cmd_Argc() != 2 ) { + if ( cls.state != CA_ACTIVE || clc.demoplaying ) { + Com_Printf( "Not connected to a server.\n" ); + Com_Printf( "Usage: serverstatus [server]\n" ); + return; + } + server = cls.servername; + } else { + server = Cmd_Argv( 1 ); + } + + if ( !NET_StringToAdr( server, &to ) ) { + return; + } + + NET_OutOfBandPrint( NS_CLIENT, to, "getstatus" ); + + serverStatus = CL_GetServerStatus( to ); + serverStatus->address = to; + serverStatus->print = qtrue; + serverStatus->pending = qtrue; +} + +/* +================== +CL_ShowIP_f +================== +*/ +void CL_ShowIP_f( void ) { + Sys_ShowIP(); +} + +/* +================= +bool CL_CDKeyValidate +================= +*/ +qboolean CL_CDKeyValidate( const char *key, const char *checksum ) { + char ch; + byte sum; + char chs[3]; + int i, len; + + len = strlen( key ); + if ( len != CDKEY_LEN ) { + return qfalse; + } + + if ( checksum && strlen( checksum ) != CDCHKSUM_LEN ) { + return qfalse; + } + + sum = 0; + // for loop gets rid of conditional assignment warning + for ( i = 0; i < len; i++ ) { + ch = *key++; + if ( ch >= 'a' && ch <= 'z' ) { + ch -= 32; + } + switch ( ch ) { + case '2': + case '3': + case '7': + case 'A': + case 'B': + case 'C': + case 'D': + case 'G': + case 'H': + case 'J': + case 'L': + case 'P': + case 'R': + case 'S': + case 'T': + case 'W': + sum += ch; + continue; + default: + return qfalse; + } + } + + + sprintf( chs, "%02x", sum ); + + if ( checksum && !Q_stricmp( chs, checksum ) ) { + return qtrue; + } + + if ( !checksum ) { + return qtrue; + } + + return qfalse; +} + +// NERVE - SMF +/* +======================= +CL_AddToLimboChat + +======================= +*/ +void CL_AddToLimboChat( const char *str ) { + int len; + char *p, *ls; + int lastcolor; + int chatHeight; + int i; + + chatHeight = LIMBOCHAT_HEIGHT; + cl.limboChatPos = LIMBOCHAT_HEIGHT - 1; + len = 0; + + // copy old strings + for ( i = cl.limboChatPos; i > 0; i-- ) { + strcpy( cl.limboChatMsgs[i], cl.limboChatMsgs[i - 1] ); + } + + // copy new string + p = cl.limboChatMsgs[0]; + *p = 0; + + lastcolor = '7'; + + ls = NULL; + while ( *str ) { + if ( len > LIMBOCHAT_WIDTH - 1 ) { +#if 0 + if ( ls ) { + str -= ( p - ls ); + str++; + p -= ( p - ls ); + } + *p = 0; + + if ( cl.limboChatPos < LIMBOCHAT_HEIGHT - 1 ) { + cl.limboChatPos++; + } + p = cl.limboChatMsgs[cl.limboChatPos]; + *p = 0; + *p++ = Q_COLOR_ESCAPE; + *p++ = lastcolor; + len = 0; + ls = NULL; +#endif + break; + } + + if ( Q_IsColorString( str ) ) { + *p++ = *str++; + lastcolor = *str; + *p++ = *str++; + continue; + } + if ( *str == ' ' ) { + ls = p; + } + *p++ = *str++; + len++; + } + *p = 0; +} + +/* +======================= +CL_GetLimboString + +======================= +*/ +qboolean CL_GetLimboString( int index, char *buf ) { + if ( index >= LIMBOCHAT_HEIGHT ) { + return qfalse; + } + + strncpy( buf, cl.limboChatMsgs[index], 140 ); + return qtrue; +} +// -NERVE - SMF diff --git a/Projects/Android/jni/rtcw/src/client/cl_net_chan.c b/Projects/Android/jni/rtcw/src/client/cl_net_chan.c new file mode 100644 index 0000000..cd30b7e --- /dev/null +++ b/Projects/Android/jni/rtcw/src/client/cl_net_chan.c @@ -0,0 +1,197 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +#include "../game/q_shared.h" +#include "../qcommon/qcommon.h" +#include "client.h" + +#if DO_NET_ENCODE +/* +============== +CL_Netchan_Encode + + // first 12 bytes of the data are always: + long serverId; + long messageAcknowledge; + long reliableAcknowledge; + +============== +*/ +static void CL_Netchan_Encode( msg_t *msg ) { + int serverId, messageAcknowledge, reliableAcknowledge; + int i, index, srdc, sbit, soob; + byte key, *string; + + if ( msg->cursize <= CL_ENCODE_START ) { + return; + } + + srdc = msg->readcount; + sbit = msg->bit; + soob = msg->oob; + + msg->bit = 0; + msg->readcount = 0; + msg->oob = 0; + + serverId = MSG_ReadLong( msg ); + messageAcknowledge = MSG_ReadLong( msg ); + reliableAcknowledge = MSG_ReadLong( msg ); + + msg->oob = soob; + msg->bit = sbit; + msg->readcount = srdc; + + string = (byte *)clc.serverCommands[ reliableAcknowledge & ( MAX_RELIABLE_COMMANDS - 1 ) ]; + index = 0; + // + key = clc.challenge ^ serverId ^ messageAcknowledge; + for ( i = CL_ENCODE_START; i < msg->cursize; i++ ) { + // modify the key with the last received now acknowledged server command + if ( !string[index] ) { + index = 0; + } + if ( string[index] > 127 || string[index] == '%' ) { + key ^= '.' << ( i & 1 ); + } else { + key ^= string[index] << ( i & 1 ); + } + index++; + // encode the data with this key + *( msg->data + i ) = ( *( msg->data + i ) ) ^ key; + } +} + +/* +============== +CL_Netchan_Decode + + // first four bytes of the data are always: + long reliableAcknowledge; + +============== +*/ +static void CL_Netchan_Decode( msg_t *msg ) { + long reliableAcknowledge, i, index; + byte key, *string; + int srdc, sbit, soob; + + srdc = msg->readcount; + sbit = msg->bit; + soob = msg->oob; + + msg->oob = 0; + + reliableAcknowledge = MSG_ReadLong( msg ); + + msg->oob = soob; + msg->bit = sbit; + msg->readcount = srdc; + + string = clc.reliableCommands[ reliableAcknowledge & ( MAX_RELIABLE_COMMANDS - 1 ) ]; + index = 0; + // xor the client challenge with the netchan sequence number (need something that changes every message) + key = clc.challenge ^ LittleLong( *(unsigned *)msg->data ); + for ( i = msg->readcount + CL_DECODE_START; i < msg->cursize; i++ ) { + // modify the key with the last sent and with this message acknowledged client command + if ( !string[index] ) { + index = 0; + } + if ( string[index] > 127 || string[index] == '%' ) { + key ^= '.' << ( i & 1 ); + } else { + key ^= string[index] << ( i & 1 ); + } + index++; + // decode the data with this key + *( msg->data + i ) = *( msg->data + i ) ^ key; + } +} +#endif + +/* +================= +CL_Netchan_TransmitNextFragment +================= +*/ +void CL_Netchan_TransmitNextFragment( netchan_t *chan ) { + Netchan_TransmitNextFragment( chan ); +} + +//byte chksum[65536]; + +/* +=============== +CL_Netchan_Transmit +================ +*/ +void CL_Netchan_Transmit( netchan_t *chan, msg_t* msg ) { +// int i; + MSG_WriteByte( msg, clc_EOF ); +// for(i=CL_ENCODE_START;icursize;i++) { +// chksum[i-CL_ENCODE_START] = msg->data[i]; +// } + +// Huff_Compress( msg, CL_ENCODE_START ); +#if DO_NET_ENCODE + CL_Netchan_Encode( msg ); +#endif + Netchan_Transmit( chan, msg->cursize, msg->data ); +} + +extern int oldsize; +int newsize = 0; + +/* +================= +CL_Netchan_Process +================= +*/ +qboolean CL_Netchan_Process( netchan_t *chan, msg_t *msg ) { + int ret; +// int i; +// static int newsize = 0; + + ret = Netchan_Process( chan, msg ); + if ( !ret ) { + return qfalse; + } +#if DO_NET_ENCODE + CL_Netchan_Decode( msg ); +#endif +// Huff_Decompress( msg, CL_DECODE_START ); +// for(i=CL_DECODE_START+msg->readcount;icursize;i++) { +// if (msg->data[i] != chksum[i-(CL_DECODE_START+msg->readcount)]) { +// Com_Error(ERR_DROP,"bad %d v %d\n", msg->data[i], chksum[i-(CL_DECODE_START+msg->readcount)]); +// } +// } + newsize += msg->cursize; +// Com_Printf("saved %d to %d (%d%%)\n", (oldsize>>3), newsize, 100-(newsize*100/(oldsize>>3))); + return qtrue; +} diff --git a/Projects/Android/jni/rtcw/src/client/cl_parse.c b/Projects/Android/jni/rtcw/src/client/cl_parse.c new file mode 100644 index 0000000..ea3f1a4 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/client/cl_parse.c @@ -0,0 +1,654 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +// cl_parse.c -- parse a message received from the server + +#include "client.h" + +char *svc_strings[256] = { + "svc_bad", + + "svc_nop", + "svc_gamestate", + "svc_configstring", + "svc_baseline", + "svc_serverCommand", + "svc_download", + "svc_snapshot" +}; + +void SHOWNET( msg_t *msg, char *s ) { + if ( cl_shownet->integer >= 2 ) { + Com_Printf( "%3i %3i:%s\n", msg->readcount - 1, msg->cursize, s ); + } +} + + +/* +========================================================================= + +MESSAGE PARSING + +========================================================================= +*/ + +/* +================== +CL_DeltaEntity + +Parses deltas from the given base and adds the resulting entity +to the current frame +================== +*/ +void CL_DeltaEntity( msg_t *msg, clSnapshot_t *frame, int newnum, entityState_t *old, + qboolean unchanged ) { + entityState_t *state; + + // save the parsed entity state into the big circular buffer so + // it can be used as the source for a later delta + state = &cl.parseEntities[cl.parseEntitiesNum & ( MAX_PARSE_ENTITIES - 1 )]; + + if ( unchanged ) { + *state = *old; + } else { + MSG_ReadDeltaEntity( msg, old, state, newnum ); + } + + if ( state->number == ( MAX_GENTITIES - 1 ) ) { + return; // entity was delta removed + } + cl.parseEntitiesNum++; + frame->numEntities++; +} + +/* +================== +CL_ParsePacketEntities + +================== +*/ +void CL_ParsePacketEntities( msg_t *msg, clSnapshot_t *oldframe, clSnapshot_t *newframe ) { + int newnum; + entityState_t *oldstate; + int oldindex, oldnum; + + newframe->parseEntitiesNum = cl.parseEntitiesNum; + newframe->numEntities = 0; + + // delta from the entities present in oldframe + oldindex = 0; + oldstate = NULL; + if ( !oldframe ) { + oldnum = 99999; + } else { + if ( oldindex >= oldframe->numEntities ) { + oldnum = 99999; + } else { + oldstate = &cl.parseEntities[ + ( oldframe->parseEntitiesNum + oldindex ) & ( MAX_PARSE_ENTITIES - 1 )]; + oldnum = oldstate->number; + } + } + + while ( 1 ) { + // read the entity index number + newnum = MSG_ReadBits( msg, GENTITYNUM_BITS ); + + if ( newnum == ( MAX_GENTITIES - 1 ) ) { + break; + } + + if ( msg->readcount > msg->cursize ) { + Com_Error( ERR_DROP,"CL_ParsePacketEntities: end of message" ); + } + + while ( oldnum < newnum ) { + // one or more entities from the old packet are unchanged + if ( cl_shownet->integer == 3 ) { + Com_Printf( "%3i: unchanged: %i\n", msg->readcount, oldnum ); + } + CL_DeltaEntity( msg, newframe, oldnum, oldstate, qtrue ); + + oldindex++; + + if ( oldindex >= oldframe->numEntities ) { + oldnum = 99999; + } else { + oldstate = &cl.parseEntities[ + ( oldframe->parseEntitiesNum + oldindex ) & ( MAX_PARSE_ENTITIES - 1 )]; + oldnum = oldstate->number; + } + } + if ( oldnum == newnum ) { + // delta from previous state + if ( cl_shownet->integer == 3 ) { + Com_Printf( "%3i: delta: %i\n", msg->readcount, newnum ); + } + CL_DeltaEntity( msg, newframe, newnum, oldstate, qfalse ); + + oldindex++; + + if ( oldindex >= oldframe->numEntities ) { + oldnum = 99999; + } else { + oldstate = &cl.parseEntities[ + ( oldframe->parseEntitiesNum + oldindex ) & ( MAX_PARSE_ENTITIES - 1 )]; + oldnum = oldstate->number; + } + continue; + } + + if ( oldnum > newnum ) { + // delta from baseline + if ( cl_shownet->integer == 3 ) { + Com_Printf( "%3i: baseline: %i\n", msg->readcount, newnum ); + } + CL_DeltaEntity( msg, newframe, newnum, &cl.entityBaselines[newnum], qfalse ); + continue; + } + + } + + // any remaining entities in the old frame are copied over + while ( oldnum != 99999 ) { + // one or more entities from the old packet are unchanged + if ( cl_shownet->integer == 3 ) { + Com_Printf( "%3i: unchanged: %i\n", msg->readcount, oldnum ); + } + CL_DeltaEntity( msg, newframe, oldnum, oldstate, qtrue ); + + oldindex++; + + if ( oldindex >= oldframe->numEntities ) { + oldnum = 99999; + } else { + oldstate = &cl.parseEntities[ + ( oldframe->parseEntitiesNum + oldindex ) & ( MAX_PARSE_ENTITIES - 1 )]; + oldnum = oldstate->number; + } + } +} + + +/* +================ +CL_ParseSnapshot + +If the snapshot is parsed properly, it will be copied to +cl.snap and saved in cl.snapshots[]. If the snapshot is invalid +for any reason, no changes to the state will be made at all. +================ +*/ +void CL_ParseSnapshot( msg_t *msg ) { + int len; + clSnapshot_t *old; + clSnapshot_t newSnap; + int deltaNum; + int oldMessageNum; + int i, packetNum; + + // get the reliable sequence acknowledge number + // NOTE: now sent with all server to client messages + //clc.reliableAcknowledge = MSG_ReadLong( msg ); + + // read in the new snapshot to a temporary buffer + // we will only copy to cl.snap if it is valid + memset( &newSnap, 0, sizeof( newSnap ) ); + + // we will have read any new server commands in this + // message before we got to svc_snapshot + newSnap.serverCommandNum = clc.serverCommandSequence; + + newSnap.serverTime = MSG_ReadLong( msg ); + + newSnap.messageNum = clc.serverMessageSequence; + + deltaNum = MSG_ReadByte( msg ); + if ( !deltaNum ) { + newSnap.deltaNum = -1; + } else { + newSnap.deltaNum = newSnap.messageNum - deltaNum; + } + newSnap.snapFlags = MSG_ReadByte( msg ); + + // If the frame is delta compressed from data that we + // no longer have available, we must suck up the rest of + // the frame, but not use it, then ask for a non-compressed + // message + if ( newSnap.deltaNum <= 0 ) { + newSnap.valid = qtrue; // uncompressed frame + old = NULL; + clc.demowaiting = qfalse; // we can start recording now + } else { + old = &cl.snapshots[newSnap.deltaNum & PACKET_MASK]; + if ( !old->valid ) { + // should never happen + Com_Printf( "Delta from invalid frame (not supposed to happen!).\n" ); + } else if ( old->messageNum != newSnap.deltaNum ) { + // The frame that the server did the delta from + // is too old, so we can't reconstruct it properly. + Com_Printf( "Delta frame too old.\n" ); + } else if ( cl.parseEntitiesNum - old->parseEntitiesNum > MAX_PARSE_ENTITIES - 128 ) { + Com_Printf( "Delta parseEntitiesNum too old.\n" ); + } else { + newSnap.valid = qtrue; // valid delta parse + } + } + + // read areamask + len = MSG_ReadByte( msg ); + MSG_ReadData( msg, &newSnap.areamask, len ); + + // read playerinfo + SHOWNET( msg, "playerstate" ); + if ( old ) { + MSG_ReadDeltaPlayerstate( msg, &old->ps, &newSnap.ps ); + } else { + MSG_ReadDeltaPlayerstate( msg, NULL, &newSnap.ps ); + } + + // read packet entities + SHOWNET( msg, "packet entities" ); + CL_ParsePacketEntities( msg, old, &newSnap ); + + // if not valid, dump the entire thing now that it has + // been properly read + if ( !newSnap.valid ) { + return; + } + + // clear the valid flags of any snapshots between the last + // received and this one, so if there was a dropped packet + // it won't look like something valid to delta from next + // time we wrap around in the buffer + oldMessageNum = cl.snap.messageNum + 1; + + if ( newSnap.messageNum - oldMessageNum >= PACKET_BACKUP ) { + oldMessageNum = newSnap.messageNum - ( PACKET_BACKUP - 1 ); + } + for ( ; oldMessageNum < newSnap.messageNum ; oldMessageNum++ ) { + cl.snapshots[oldMessageNum & PACKET_MASK].valid = qfalse; + } + + // copy to the current good spot + cl.snap = newSnap; + cl.snap.ping = 999; + // calculate ping time + for ( i = 0 ; i < PACKET_BACKUP ; i++ ) { + packetNum = ( clc.netchan.outgoingSequence - 1 - i ) & PACKET_MASK; + if ( cl.snap.ps.commandTime >= cl.outPackets[ packetNum ].p_serverTime ) { + cl.snap.ping = cls.realtime - cl.outPackets[ packetNum ].p_realtime; + break; + } + } + // save the frame off in the backup array for later delta comparisons + cl.snapshots[cl.snap.messageNum & PACKET_MASK] = cl.snap; + + if ( cl_shownet->integer == 3 ) { + Com_Printf( " snapshot:%i delta:%i ping:%i\n", cl.snap.messageNum, + cl.snap.deltaNum, cl.snap.ping ); + } + + cl.newSnapshots = qtrue; +} + + +//===================================================================== + +int cl_connectedToPureServer; + +/* +================== +CL_SystemInfoChanged + +The systeminfo configstring has been changed, so parse +new information out of it. This will happen at every +gamestate, and possibly during gameplay. +================== +*/ +void CL_SystemInfoChanged( void ) { + char *systemInfo; + const char *s, *t; + char key[BIG_INFO_KEY]; + char value[BIG_INFO_VALUE]; + + systemInfo = cl.gameState.stringData + cl.gameState.stringOffsets[ CS_SYSTEMINFO ]; + cl.serverId = atoi( Info_ValueForKey( systemInfo, "sv_serverid" ) ); + + // don't set any vars when playing a demo + if ( clc.demoplaying ) { + return; + } + + s = Info_ValueForKey( systemInfo, "sv_cheats" ); + if ( atoi( s ) == 0 ) { + Cvar_SetCheatState(); + } + + // check pure server string + s = Info_ValueForKey( systemInfo, "sv_paks" ); + t = Info_ValueForKey( systemInfo, "sv_pakNames" ); + FS_PureServerSetLoadedPaks( s, t ); + + s = Info_ValueForKey( systemInfo, "sv_referencedPaks" ); + t = Info_ValueForKey( systemInfo, "sv_referencedPakNames" ); + FS_PureServerSetReferencedPaks( s, t ); + + + // scan through all the variables in the systeminfo and locally set cvars to match + s = systemInfo; + while ( s ) { + Info_NextPair( &s, key, value ); + if ( !key[0] ) { + break; + } + + Cvar_Set( key, value ); + } + cl_connectedToPureServer = Cvar_VariableValue( "sv_pure" ); +} + +/* +================== +CL_ParseGamestate +================== +*/ +void CL_ParseGamestate( msg_t *msg ) { + int i; + entityState_t *es; + int newnum; + entityState_t nullstate; + int cmd; + char *s; + + Con_Close(); + + clc.connectPacketCount = 0; + + // wipe local client state + CL_ClearState(); + + // a gamestate always marks a server command sequence + clc.serverCommandSequence = MSG_ReadLong( msg ); + + // parse all the configstrings and baselines + cl.gameState.dataCount = 1; // leave a 0 at the beginning for uninitialized configstrings + while ( 1 ) { + cmd = MSG_ReadByte( msg ); + + if ( cmd == svc_EOF ) { + break; + } + + if ( cmd == svc_configstring ) { + int len; + + i = MSG_ReadShort( msg ); + if ( i < 0 || i >= MAX_CONFIGSTRINGS ) { + Com_Error( ERR_DROP, "configstring > MAX_CONFIGSTRINGS" ); + } + s = MSG_ReadBigString( msg ); + len = strlen( s ); + + if ( len + 1 + cl.gameState.dataCount > MAX_GAMESTATE_CHARS ) { + Com_Error( ERR_DROP, "MAX_GAMESTATE_CHARS exceeded" ); + } + + // append it to the gameState string buffer + cl.gameState.stringOffsets[ i ] = cl.gameState.dataCount; + memcpy( cl.gameState.stringData + cl.gameState.dataCount, s, len + 1 ); + cl.gameState.dataCount += len + 1; + } else if ( cmd == svc_baseline ) { + newnum = MSG_ReadBits( msg, GENTITYNUM_BITS ); + if ( newnum < 0 || newnum >= MAX_GENTITIES ) { + Com_Error( ERR_DROP, "Baseline number out of range: %i", newnum ); + } + memset( &nullstate, 0, sizeof( nullstate ) ); + es = &cl.entityBaselines[ newnum ]; + MSG_ReadDeltaEntity( msg, &nullstate, es, newnum ); + } else { + Com_Error( ERR_DROP, "CL_ParseGamestate: bad command byte" ); + } + } + + clc.clientNum = MSG_ReadLong( msg ); + // read the checksum feed + clc.checksumFeed = MSG_ReadLong( msg ); + + // parse serverId and other cvars + CL_SystemInfoChanged(); + + // reinitialize the filesystem if the game directory has changed + if ( FS_ConditionalRestart( clc.checksumFeed ) ) { + // don't set to true because we yet have to start downloading + // enabling this can cause double loading of a map when connecting to + // a server which has a different game directory set + //clc.downloadRestart = qtrue; + } + + // This used to call CL_StartHunkUsers, but now we enter the download state before loading the + // cgame + CL_InitDownloads(); + + // make sure the game starts + Cvar_Set( "cl_paused", "0" ); +} + + +//===================================================================== + +/* +===================== +CL_ParseDownload + +A download message has been received from the server +===================== +*/ +void CL_ParseDownload( msg_t *msg ) { + int size; + unsigned char data[MAX_MSGLEN]; + int block; + + // read the data + block = MSG_ReadShort( msg ); + + if ( !block ) { + // block zero is special, contains file size + clc.downloadSize = MSG_ReadLong( msg ); + + Cvar_SetValue( "cl_downloadSize", clc.downloadSize ); + + if ( clc.downloadSize < 0 ) { + Com_Error( ERR_DROP, MSG_ReadString( msg ) ); + return; + } + } + + size = MSG_ReadShort( msg ); + if ( size > 0 ) { + MSG_ReadData( msg, data, size ); + } + + if ( clc.downloadBlock != block ) { + Com_DPrintf( "CL_ParseDownload: Expected block %d, got %d\n", clc.downloadBlock, block ); + return; + } + + // open the file if not opened yet + if ( !clc.download ) { + if ( !*clc.downloadTempName ) { + Com_Printf( "Server sending download, but no download was requested\n" ); + CL_AddReliableCommand( "stopdl" ); + return; + } + + clc.download = FS_SV_FOpenFileWrite( clc.downloadTempName ); + + if ( !clc.download ) { + Com_Printf( "Could not create %s\n", clc.downloadTempName ); + CL_AddReliableCommand( "stopdl" ); + CL_NextDownload(); + return; + } + } + + if ( size ) { + FS_Write( data, size, clc.download ); + } + + CL_AddReliableCommand( va( "nextdl %d", clc.downloadBlock ) ); + clc.downloadBlock++; + + clc.downloadCount += size; + + // So UI gets access to it + Cvar_SetValue( "cl_downloadCount", clc.downloadCount ); + + if ( !size ) { // A zero length block means EOF + if ( clc.download ) { + FS_FCloseFile( clc.download ); + clc.download = 0; + + // rename the file + FS_SV_Rename( clc.downloadTempName, clc.downloadName ); + } + *clc.downloadTempName = *clc.downloadName = 0; + Cvar_Set( "cl_downloadName", "" ); + + // send intentions now + // We need this because without it, we would hold the last nextdl and then start + // loading right away. If we take a while to load, the server is happily trying + // to send us that last block over and over. + // Write it twice to help make sure we acknowledge the download + CL_WritePacket(); + CL_WritePacket(); + + // get another file if needed + CL_NextDownload(); + } +} + +/* +===================== +CL_ParseCommandString + +Command strings are just saved off until cgame asks for them +when it transitions a snapshot +===================== +*/ +void CL_ParseCommandString( msg_t *msg ) { + char *s; + int seq; + int index; + + seq = MSG_ReadLong( msg ); + s = MSG_ReadString( msg ); + + // see if we have already executed stored it off + if ( clc.serverCommandSequence >= seq ) { + return; + } + clc.serverCommandSequence = seq; + + index = seq & ( MAX_RELIABLE_COMMANDS - 1 ); + Q_strncpyz( clc.serverCommands[ index ], s, sizeof( clc.serverCommands[ index ] ) ); +} + + +/* +===================== +CL_ParseServerMessage +===================== +*/ +void CL_ParseServerMessage( msg_t *msg ) { + int cmd; + msg_t msgback; + + msgback = *msg; + + if ( cl_shownet->integer == 1 ) { + Com_Printf( "%i ",msg->cursize ); + } else if ( cl_shownet->integer >= 2 ) { + Com_Printf( "------------------\n" ); + } + + MSG_Bitstream( msg ); + + // get the reliable sequence acknowledge number + clc.reliableAcknowledge = MSG_ReadLong( msg ); + // + if ( clc.reliableAcknowledge < clc.reliableSequence - MAX_RELIABLE_COMMANDS ) { + clc.reliableAcknowledge = clc.reliableSequence; + } + + // + // parse the message + // + while ( 1 ) { + if ( msg->readcount > msg->cursize ) { + Com_Error( ERR_DROP,"CL_ParseServerMessage: read past end of server message" ); + break; + } + + cmd = MSG_ReadByte( msg ); + + if ( cmd == svc_EOF ) { + SHOWNET( msg, "END OF MESSAGE" ); + break; + } + + if ( cl_shownet->integer >= 2 ) { + if ( !svc_strings[cmd] ) { + Com_Printf( "%3i:BAD CMD %i\n", msg->readcount - 1, cmd ); + } else { + SHOWNET( msg, svc_strings[cmd] ); + } + } + + // other commands + switch ( cmd ) { + default: + Com_Error( ERR_DROP,"CL_ParseServerMessage: Illegible server message\n" ); + break; + case svc_nop: + break; + case svc_serverCommand: + CL_ParseCommandString( msg ); + break; + case svc_gamestate: + CL_ParseGamestate( msg ); + break; + case svc_snapshot: + CL_ParseSnapshot( msg ); + break; + case svc_download: + CL_ParseDownload( msg ); + break; + } + } +} diff --git a/Projects/Android/jni/rtcw/src/client/cl_scrn.c b/Projects/Android/jni/rtcw/src/client/cl_scrn.c new file mode 100644 index 0000000..e35d0f2 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/client/cl_scrn.c @@ -0,0 +1,564 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +// cl_scrn.c -- master for refresh, status bar, console, chat, notify, etc + +#include "client.h" + +qboolean scr_initialized; // ready to draw + +cvar_t *cl_timegraph; +cvar_t *cl_debuggraph; +cvar_t *cl_graphheight; +cvar_t *cl_graphscale; +cvar_t *cl_graphshift; + +/* +================ +SCR_DrawNamedPic + +Coordinates are 640*480 virtual values +================= +*/ +void SCR_DrawNamedPic( float x, float y, float width, float height, const char *picname ) { + qhandle_t hShader; + + assert( width != 0 ); + + hShader = re.RegisterShader( picname ); + SCR_AdjustFrom640( &x, &y, &width, &height ); + re.DrawStretchPic( x, y, width, height, 0, 0, 1, 1, hShader ); +} + + +/* +================ +SCR_AdjustFrom640 + +Adjusted for resolution and screen aspect ratio +================ +*/ +void SCR_AdjustFrom640( float *x, float *y, float *w, float *h ) { + float xscale; + float yscale; + +#ifdef PANDORA + // adjust for wide screens + if ( cls.glconfig.vidWidth * 480 > cls.glconfig.vidHeight * 640 ) { +// *x += 0.5 * ( cls.glconfig.vidWidth - ( cls.glconfig.vidHeight * 640 / 480 ) ); + } +#endif + + // scale for screen sizes + xscale = cls.glconfig.vidWidth / 640.0; + yscale = cls.glconfig.vidHeight / 480.0; +/* #ifdef PANDORA + if (xscale>yscale) + yscale=xscale; + else + xscale=yscale; + #endif*/ + if ( x ) { + *x *= xscale; + } + if ( y ) { + *y *= yscale; + } + if ( w ) { + *w *= xscale; + } + if ( h ) { + *h *= yscale; + } +} + +/* +================ +SCR_FillRect + +Coordinates are 640*480 virtual values +================= +*/ +void SCR_FillRect( float x, float y, float width, float height, const float *color ) { + re.SetColor( color ); + + SCR_AdjustFrom640( &x, &y, &width, &height ); + re.DrawStretchPic( x, y, width, height, 0, 0, 0, 0, cls.whiteShader ); + + re.SetColor( NULL ); +} + + +/* +================ +SCR_DrawPic + +Coordinates are 640*480 virtual values +================= +*/ +void SCR_DrawPic( float x, float y, float width, float height, qhandle_t hShader ) { + SCR_AdjustFrom640( &x, &y, &width, &height ); + re.DrawStretchPic( x, y, width, height, 0, 0, 1, 1, hShader ); +} + + + +/* +** SCR_DrawChar +** chars are drawn at 640*480 virtual screen size +*/ +static void SCR_DrawChar( int x, int y, float size, int ch ) { + int row, col; + float frow, fcol; + float ax, ay, aw, ah; + + ch &= 255; + + if ( ch == ' ' ) { + return; + } + + if ( y < -size ) { + return; + } + + ax = x; + ay = y; + aw = size; + ah = size; + SCR_AdjustFrom640( &ax, &ay, &aw, &ah ); + + row = ch >> 4; + col = ch & 15; + + frow = row * 0.0625; + fcol = col * 0.0625; + size = 0.0625; + + re.DrawStretchPic( ax, ay, aw, ah, + fcol, frow, + fcol + size, frow + size, + cls.charSetShader ); +} + +/* +** SCR_DrawSmallChar +** small chars are drawn at native screen resolution +*/ +void SCR_DrawSmallChar( int x, int y, int ch ) { + int row, col; + float frow, fcol; + float size; + + ch &= 255; + + if ( ch == ' ' ) { + return; + } + + if ( y < -SMALLCHAR_HEIGHT ) { + return; + } + + row = ch >> 4; + col = ch & 15; + + frow = row * 0.0625; + fcol = col * 0.0625; + size = 0.0625; + + re.DrawStretchPic( x, y, SMALLCHAR_WIDTH, SMALLCHAR_HEIGHT, + fcol, frow, + fcol + size, frow + size, + cls.charSetShader ); +} + + +/* +================== +SCR_DrawBigString[Color] + +Draws a multi-colored string with a drop shadow, optionally forcing +to a fixed color. + +Coordinates are at 640 by 480 virtual resolution +================== +*/ +void SCR_DrawStringExt( int x, int y, float size, const char *string, float *setColor, qboolean forceColor ) { + vec4_t color; + const char *s; + int xx; + + // draw the drop shadow + color[0] = color[1] = color[2] = 0; + color[3] = setColor[3]; + re.SetColor( color ); + s = string; + xx = x; + while ( *s ) { + if ( Q_IsColorString( s ) ) { + s += 2; + continue; + } + SCR_DrawChar( xx + 2, y + 2, size, *s ); + xx += size; + s++; + } + + + // draw the colored text + s = string; + xx = x; + re.SetColor( setColor ); + while ( *s ) { + if ( Q_IsColorString( s ) ) { + if ( !forceColor ) { + memcpy( color, g_color_table[ColorIndex( *( s + 1 ) )], sizeof( color ) ); + color[3] = setColor[3]; + re.SetColor( color ); + } + s += 2; + continue; + } + SCR_DrawChar( xx, y, size, *s ); + xx += size; + s++; + } + re.SetColor( NULL ); +} + + +void SCR_DrawBigString( int x, int y, const char *s, float alpha ) { + float color[4]; + + color[0] = color[1] = color[2] = 1.0; + color[3] = alpha; + SCR_DrawStringExt( x, y, BIGCHAR_WIDTH, s, color, qfalse ); +} + +void SCR_DrawBigStringColor( int x, int y, const char *s, vec4_t color ) { + SCR_DrawStringExt( x, y, BIGCHAR_WIDTH, s, color, qtrue ); +} + + +/* +================== +SCR_DrawSmallString[Color] + +Draws a multi-colored string with a drop shadow, optionally forcing +to a fixed color. + +Coordinates are at 640 by 480 virtual resolution +================== +*/ +void SCR_DrawSmallStringExt( int x, int y, const char *string, float *setColor, qboolean forceColor ) { + vec4_t color; + const char *s; + int xx; + + // draw the colored text + s = string; + xx = x; + re.SetColor( setColor ); + while ( *s ) { + if ( Q_IsColorString( s ) ) { + if ( !forceColor ) { + memcpy( color, g_color_table[ColorIndex( *( s + 1 ) )], sizeof( color ) ); + color[3] = setColor[3]; + re.SetColor( color ); + } + s += 2; + continue; + } + SCR_DrawSmallChar( xx, y, *s ); + xx += SMALLCHAR_WIDTH; + s++; + } + re.SetColor( NULL ); +} + + + +/* +** SCR_Strlen -- skips color escape codes +*/ +static int SCR_Strlen( const char *str ) { + const char *s = str; + int count = 0; + + while ( *s ) { + if ( Q_IsColorString( s ) ) { + s += 2; + } else { + count++; + s++; + } + } + + return count; +} + +/* +** SCR_GetBigStringWidth +*/ +int SCR_GetBigStringWidth( const char *str ) { + return SCR_Strlen( str ) * 16; +} + + +//=============================================================================== + +/* +================= +SCR_DrawDemoRecording +================= +*/ +void SCR_DrawDemoRecording( void ) { + char string[1024]; + int pos; + + if ( !clc.demorecording ) { + return; + } + + pos = FS_FTell( clc.demofile ); + sprintf( string, "RECORDING %s: %ik", clc.demoName, pos / 1024 ); + + SCR_DrawStringExt( 320 - strlen( string ) * 4, 20, 8, string, g_color_table[7], qtrue ); +} + + +/* +=============================================================================== + +DEBUG GRAPH + +=============================================================================== +*/ + +typedef struct +{ + float value; + int color; +} graphsamp_t; + +static int current; +static graphsamp_t values[1024]; + +/* +============== +SCR_DebugGraph +============== +*/ +void SCR_DebugGraph( float value, int color ) { + values[current & 1023].value = value; + values[current & 1023].color = color; + current++; +} + +/* +============== +SCR_DrawDebugGraph +============== +*/ +void SCR_DrawDebugGraph( void ) { + int a, x, y, w, i, h; + float v; + int color; + + // + // draw the graph + // + w = cls.glconfig.vidWidth; + x = 0; + y = cls.glconfig.vidHeight; + re.SetColor( g_color_table[0] ); + re.DrawStretchPic( x, y - cl_graphheight->integer, + w, cl_graphheight->integer, 0, 0, 0, 0, cls.whiteShader ); + re.SetColor( NULL ); + + for ( a = 0 ; a < w ; a++ ) + { + i = ( current - 1 - a + 1024 ) & 1023; + v = values[i].value; + color = values[i].color; + v = v * cl_graphscale->integer + cl_graphshift->integer; + + if ( v < 0 ) { + v += cl_graphheight->integer * ( 1 + (int)( -v / cl_graphheight->integer ) ); + } + h = (int)v % cl_graphheight->integer; + re.DrawStretchPic( x + w - 1 - a, y - h, 1, h, 0, 0, 0, 0, cls.whiteShader ); + } +} + +//============================================================================= + +/* +================== +SCR_Init +================== +*/ +void SCR_Init( void ) { + cl_timegraph = Cvar_Get( "timegraph", "0", CVAR_CHEAT ); + cl_debuggraph = Cvar_Get( "debuggraph", "0", CVAR_CHEAT ); + cl_graphheight = Cvar_Get( "graphheight", "32", CVAR_CHEAT ); + cl_graphscale = Cvar_Get( "graphscale", "1", CVAR_CHEAT ); + cl_graphshift = Cvar_Get( "graphshift", "0", CVAR_CHEAT ); + + scr_initialized = qtrue; +} + + +//======================================================= + +/* +================== +SCR_DrawScreenField + +This will be called twice if rendering in stereo mode +================== +*/ +void SCR_DrawScreenField( stereoFrame_t stereoFrame ) { + re.BeginFrame( stereoFrame ); + + // wide aspect ratio screens need to have the sides cleared + // unless they are displaying game renderings + // SEB: commented, since this break cinematics + if ( cls.state != CA_ACTIVE ) { +/* if ( cls.glconfig.vidWidth * 480 > cls.glconfig.vidHeight * 640 ) { + re.SetColor( g_color_table[0] ); + re.DrawStretchPic( 0, 0, cls.glconfig.vidWidth, cls.glconfig.vidHeight, 0, 0, 0, 0, cls.whiteShader ); + re.SetColor( NULL ); + }*/ + } + + if ( !uivm ) { + Com_DPrintf( "draw screen without UI loaded\n" ); + return; + } + + // if the menu is going to cover the entire screen, we + // don't need to render anything under it + if ( !VM_Call( uivm, UI_IS_FULLSCREEN ) ) { + switch ( cls.state ) { + default: + Com_Error( ERR_FATAL, "SCR_DrawScreenField: bad cls.state" ); + break; + case CA_CINEMATIC: + SCR_DrawCinematic(); + break; + case CA_DISCONNECTED: + // force menu up + S_StopAllSounds(); + VM_Call( uivm, UI_SET_ACTIVE_MENU, UIMENU_MAIN ); + break; + case CA_CONNECTING: + case CA_CHALLENGING: + case CA_CONNECTED: + // connecting clients will only show the connection dialog + // refresh to update the time + VM_Call( uivm, UI_REFRESH, cls.realtime ); + VM_Call( uivm, UI_DRAW_CONNECT_SCREEN, qfalse ); + break; +// // Ridah, if the cgame is valid, fall through to there +// if (!cls.cgameStarted || !com_sv_running->integer) { +// // connecting clients will only show the connection dialog +// VM_Call( uivm, UI_DRAW_CONNECT_SCREEN, qfalse ); +// break; +// } + case CA_LOADING: + case CA_PRIMED: + // draw the game information screen and loading progress + CL_CGameRendering( stereoFrame ); + + // also draw the connection information, so it doesn't + // flash away too briefly on local or lan games + //if (!com_sv_running->value || Cvar_VariableIntegerValue("sv_cheats")) // Ridah, don't draw useless text if not in dev mode + VM_Call( uivm, UI_REFRESH, cls.realtime ); + VM_Call( uivm, UI_DRAW_CONNECT_SCREEN, qtrue ); + break; + case CA_ACTIVE: + CL_CGameRendering( stereoFrame ); + SCR_DrawDemoRecording(); + break; + } + } + + // the menu draws next + if ( cls.keyCatchers & KEYCATCH_UI && uivm ) { + VM_Call( uivm, UI_REFRESH, cls.realtime ); + } + + // console draws next + Con_DrawConsole(); + + // debug graph can be drawn on top of anything + if ( cl_debuggraph->integer || cl_timegraph->integer || cl_debugMove->integer ) { + SCR_DrawDebugGraph(); + } +} + +/* +================== +SCR_UpdateScreen + +This is called every frame, and can also be called explicitly to flush +text to the screen. +================== +*/ +void SCR_UpdateScreen( void ) { + static int recursive; + + if ( !scr_initialized ) { + return; // not initialized yet + } + + if ( ++recursive > 2 ) { + Com_Error( ERR_FATAL, "SCR_UpdateScreen: recursively called" ); + } + recursive = 1; +#ifndef HAVE_GLES + // if running in stereo, we need to draw the frame twice + if ( cls.glconfig.stereoEnabled ) { + SCR_DrawScreenField( STEREO_LEFT ); + SCR_DrawScreenField( STEREO_RIGHT ); + } else +#endif + { + SCR_DrawScreenField( STEREO_CENTER ); + } + + if ( com_speeds->integer ) { + re.EndFrame( &time_frontend, &time_backend ); + } else { + re.EndFrame( NULL, NULL ); + } + + recursive = 0; +} diff --git a/Projects/Android/jni/rtcw/src/client/cl_ui.c b/Projects/Android/jni/rtcw/src/client/cl_ui.c new file mode 100644 index 0000000..18d48ed --- /dev/null +++ b/Projects/Android/jni/rtcw/src/client/cl_ui.c @@ -0,0 +1,1256 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +#include "client.h" + +#include "../game/botlib.h" + +extern botlib_export_t *botlib_export; + +vm_t *uivm; + +extern char cl_cdkey[34]; + + +/* +==================== +GetClientState +==================== +*/ +static void GetClientState( uiClientState_t *state ) { + state->connectPacketCount = clc.connectPacketCount; + state->connState = cls.state; + Q_strncpyz( state->servername, cls.servername, sizeof( state->servername ) ); + Q_strncpyz( state->updateInfoString, cls.updateInfoString, sizeof( state->updateInfoString ) ); + Q_strncpyz( state->messageString, clc.serverMessage, sizeof( state->messageString ) ); + state->clientNum = cl.snap.ps.clientNum; +} + +/* +==================== +LAN_LoadCachedServers +==================== +*/ +void LAN_LoadCachedServers() { + // TTimo: stub, this is only relevant to MP, SP kills the servercache.dat (and favorites) + // show_bug.cgi?id=445 + /* + int size; + fileHandle_t fileIn; + cls.numglobalservers = cls.nummplayerservers = cls.numfavoriteservers = 0; + cls.numGlobalServerAddresses = 0; + if (FS_SV_FOpenFileRead("servercache.dat", &fileIn)) { + FS_Read(&cls.numglobalservers, sizeof(int), fileIn); + FS_Read(&cls.nummplayerservers, sizeof(int), fileIn); + FS_Read(&cls.numfavoriteservers, sizeof(int), fileIn); + FS_Read(&size, sizeof(int), fileIn); + if (size == sizeof(cls.globalServers) + sizeof(cls.favoriteServers) + sizeof(cls.mplayerServers)) { + FS_Read(&cls.globalServers, sizeof(cls.globalServers), fileIn); + FS_Read(&cls.mplayerServers, sizeof(cls.mplayerServers), fileIn); + FS_Read(&cls.favoriteServers, sizeof(cls.favoriteServers), fileIn); + } else { + cls.numglobalservers = cls.nummplayerservers = cls.numfavoriteservers = 0; + cls.numGlobalServerAddresses = 0; + } + FS_FCloseFile(fileIn); + } + */ +} + +/* +==================== +LAN_SaveServersToCache +==================== +*/ +void LAN_SaveServersToCache() { + // TTimo: stub, this is only relevant to MP, SP kills the servercache.dat (and favorites) + // show_bug.cgi?id=445 + /* + int size; + fileHandle_t fileOut; + #ifdef __MACOS__ //DAJ MacOS file typing + { + extern _MSL_IMP_EXP_C long _fcreator, _ftype; + _ftype = 'WlfB'; + _fcreator = 'WlfS'; + } + #endif + fileOut = FS_SV_FOpenFileWrite("servercache.dat"); + FS_Write(&cls.numglobalservers, sizeof(int), fileOut); + FS_Write(&cls.nummplayerservers, sizeof(int), fileOut); + FS_Write(&cls.numfavoriteservers, sizeof(int), fileOut); + size = sizeof(cls.globalServers) + sizeof(cls.favoriteServers) + sizeof(cls.mplayerServers); + FS_Write(&size, sizeof(int), fileOut); + FS_Write(&cls.globalServers, sizeof(cls.globalServers), fileOut); + FS_Write(&cls.mplayerServers, sizeof(cls.mplayerServers), fileOut); + FS_Write(&cls.favoriteServers, sizeof(cls.favoriteServers), fileOut); + FS_FCloseFile(fileOut); + */ +} + + +/* +==================== +LAN_ResetPings +==================== +*/ +static void LAN_ResetPings( int source ) { + int count,i; + serverInfo_t *servers = NULL; + count = 0; + + switch ( source ) { + case AS_LOCAL: + servers = &cls.localServers[0]; + count = MAX_OTHER_SERVERS; + break; + case AS_MPLAYER: + servers = &cls.mplayerServers[0]; + count = MAX_OTHER_SERVERS; + break; + case AS_GLOBAL: + servers = &cls.globalServers[0]; + count = MAX_GLOBAL_SERVERS; + break; + case AS_FAVORITES: + servers = &cls.favoriteServers[0]; + count = MAX_OTHER_SERVERS; + break; + } + if ( servers ) { + for ( i = 0; i < count; i++ ) { + servers[i].ping = -1; + } + } +} + +/* +==================== +LAN_AddServer +==================== +*/ +static int LAN_AddServer( int source, const char *name, const char *address ) { + int max, *count, i; + netadr_t adr; + serverInfo_t *servers = NULL; + max = MAX_OTHER_SERVERS; + count = 0; + + switch ( source ) { + case AS_LOCAL: + count = &cls.numlocalservers; + servers = &cls.localServers[0]; + break; + case AS_MPLAYER: + count = &cls.nummplayerservers; + servers = &cls.mplayerServers[0]; + break; + case AS_GLOBAL: + max = MAX_GLOBAL_SERVERS; + count = &cls.numglobalservers; + servers = &cls.globalServers[0]; + break; + case AS_FAVORITES: + count = &cls.numfavoriteservers; + servers = &cls.favoriteServers[0]; + break; + } + if ( servers && *count < max ) { + NET_StringToAdr( address, &adr ); + for ( i = 0; i < *count; i++ ) { + if ( NET_CompareAdr( servers[i].adr, adr ) ) { + break; + } + } + if ( i >= *count ) { + servers[*count].adr = adr; + Q_strncpyz( servers[*count].hostName, name, sizeof( servers[*count].hostName ) ); + servers[*count].visible = qtrue; + ( *count )++; + return 1; + } + return 0; + } + return -1; +} + +/* +==================== +LAN_RemoveServer +==================== +*/ +static void LAN_RemoveServer( int source, const char *addr ) { + int *count, i; + serverInfo_t *servers = NULL; + count = 0; + switch ( source ) { + case AS_LOCAL: + count = &cls.numlocalservers; + servers = &cls.localServers[0]; + break; + case AS_MPLAYER: + count = &cls.nummplayerservers; + servers = &cls.mplayerServers[0]; + break; + case AS_GLOBAL: + count = &cls.numglobalservers; + servers = &cls.globalServers[0]; + break; + case AS_FAVORITES: + count = &cls.numfavoriteservers; + servers = &cls.favoriteServers[0]; + break; + } + if ( servers ) { + netadr_t comp; + NET_StringToAdr( addr, &comp ); + for ( i = 0; i < *count; i++ ) { + if ( NET_CompareAdr( comp, servers[i].adr ) ) { + int j = i; + while ( j < *count - 1 ) { + Com_Memcpy( &servers[j], &servers[j + 1], sizeof( servers[j] ) ); + j++; + } + ( *count )--; + break; + } + } + } +} + + +/* +==================== +LAN_GetServerCount +==================== +*/ +static int LAN_GetServerCount( int source ) { + switch ( source ) { + case AS_LOCAL: + return cls.numlocalservers; + break; + case AS_MPLAYER: + return cls.nummplayerservers; + break; + case AS_GLOBAL: + return cls.numglobalservers; + break; + case AS_FAVORITES: + return cls.numfavoriteservers; + break; + } + return 0; +} + +/* +==================== +LAN_GetLocalServerAddressString +==================== +*/ +static void LAN_GetServerAddressString( int source, int n, char *buf, int buflen ) { + switch ( source ) { + case AS_LOCAL: + if ( n >= 0 && n < MAX_OTHER_SERVERS ) { + Q_strncpyz( buf, NET_AdrToString( cls.localServers[n].adr ), buflen ); + return; + } + break; + case AS_MPLAYER: + if ( n >= 0 && n < MAX_OTHER_SERVERS ) { + Q_strncpyz( buf, NET_AdrToString( cls.mplayerServers[n].adr ), buflen ); + return; + } + break; + case AS_GLOBAL: + if ( n >= 0 && n < MAX_GLOBAL_SERVERS ) { + Q_strncpyz( buf, NET_AdrToString( cls.globalServers[n].adr ), buflen ); + return; + } + break; + case AS_FAVORITES: + if ( n >= 0 && n < MAX_OTHER_SERVERS ) { + Q_strncpyz( buf, NET_AdrToString( cls.favoriteServers[n].adr ), buflen ); + return; + } + break; + } + buf[0] = '\0'; +} + +/* +==================== +LAN_GetServerInfo +==================== +*/ +static void LAN_GetServerInfo( int source, int n, char *buf, int buflen ) { + char info[MAX_STRING_CHARS]; + serverInfo_t *server = NULL; + info[0] = '\0'; + switch ( source ) { + case AS_LOCAL: + if ( n >= 0 && n < MAX_OTHER_SERVERS ) { + server = &cls.localServers[n]; + } + break; + case AS_MPLAYER: + if ( n >= 0 && n < MAX_OTHER_SERVERS ) { + server = &cls.mplayerServers[n]; + } + break; + case AS_GLOBAL: + if ( n >= 0 && n < MAX_GLOBAL_SERVERS ) { + server = &cls.globalServers[n]; + } + break; + case AS_FAVORITES: + if ( n >= 0 && n < MAX_OTHER_SERVERS ) { + server = &cls.favoriteServers[n]; + } + break; + } + if ( server && buf ) { + buf[0] = '\0'; + Info_SetValueForKey( info, "hostname", server->hostName ); + Info_SetValueForKey( info, "mapname", server->mapName ); + Info_SetValueForKey( info, "clients", va( "%i",server->clients ) ); + Info_SetValueForKey( info, "sv_maxclients", va( "%i",server->maxClients ) ); + Info_SetValueForKey( info, "ping", va( "%i",server->ping ) ); + Info_SetValueForKey( info, "minping", va( "%i",server->minPing ) ); + Info_SetValueForKey( info, "maxping", va( "%i",server->maxPing ) ); + Info_SetValueForKey( info, "game", server->game ); + Info_SetValueForKey( info, "gametype", va( "%i",server->gameType ) ); + Info_SetValueForKey( info, "nettype", va( "%i",server->netType ) ); + Info_SetValueForKey( info, "addr", NET_AdrToString( server->adr ) ); + Info_SetValueForKey( info, "sv_allowAnonymous", va( "%i", server->allowAnonymous ) ); + Q_strncpyz( buf, info, buflen ); + } else { + if ( buf ) { + buf[0] = '\0'; + } + } +} + +/* +==================== +LAN_GetServerPing +==================== +*/ +static int LAN_GetServerPing( int source, int n ) { + serverInfo_t *server = NULL; + switch ( source ) { + case AS_LOCAL: + if ( n >= 0 && n < MAX_OTHER_SERVERS ) { + server = &cls.localServers[n]; + } + break; + case AS_MPLAYER: + if ( n >= 0 && n < MAX_OTHER_SERVERS ) { + server = &cls.mplayerServers[n]; + } + break; + case AS_GLOBAL: + if ( n >= 0 && n < MAX_GLOBAL_SERVERS ) { + server = &cls.globalServers[n]; + } + break; + case AS_FAVORITES: + if ( n >= 0 && n < MAX_OTHER_SERVERS ) { + server = &cls.favoriteServers[n]; + } + break; + } + if ( server ) { + return server->ping; + } + return -1; +} + +/* +==================== +LAN_GetServerPtr +==================== +*/ +static serverInfo_t *LAN_GetServerPtr( int source, int n ) { + switch ( source ) { + case AS_LOCAL: + if ( n >= 0 && n < MAX_OTHER_SERVERS ) { + return &cls.localServers[n]; + } + break; + case AS_MPLAYER: + if ( n >= 0 && n < MAX_OTHER_SERVERS ) { + return &cls.mplayerServers[n]; + } + break; + case AS_GLOBAL: + if ( n >= 0 && n < MAX_GLOBAL_SERVERS ) { + return &cls.globalServers[n]; + } + break; + case AS_FAVORITES: + if ( n >= 0 && n < MAX_OTHER_SERVERS ) { + return &cls.favoriteServers[n]; + } + break; + } + return NULL; +} + +/* +==================== +LAN_CompareServers +==================== +*/ +static int LAN_CompareServers( int source, int sortKey, int sortDir, int s1, int s2 ) { + int res; + serverInfo_t *server1, *server2; + + server1 = LAN_GetServerPtr( source, s1 ); + server2 = LAN_GetServerPtr( source, s2 ); + if ( !server1 || !server2 ) { + return 0; + } + + res = 0; + switch ( sortKey ) { + case SORT_HOST: + res = Q_stricmp( server1->hostName, server2->hostName ); + break; + + case SORT_MAP: + res = Q_stricmp( server1->mapName, server2->mapName ); + break; + case SORT_CLIENTS: + if ( server1->clients < server2->clients ) { + res = -1; + } else if ( server1->clients > server2->clients ) { + res = 1; + } else { + res = 0; + } + break; + case SORT_GAME: + if ( server1->gameType < server2->gameType ) { + res = -1; + } else if ( server1->gameType > server2->gameType ) { + res = 1; + } else { + res = 0; + } + break; + case SORT_PING: + if ( server1->ping < server2->ping ) { + res = -1; + } else if ( server1->ping > server2->ping ) { + res = 1; + } else { + res = 0; + } + break; + } + + if ( sortDir ) { + if ( res < 0 ) { + return 1; + } + if ( res > 0 ) { + return -1; + } + return 0; + } + return res; +} + +/* +==================== +LAN_GetPingQueueCount +==================== +*/ +static int LAN_GetPingQueueCount( void ) { + return ( CL_GetPingQueueCount() ); +} + +/* +==================== +LAN_ClearPing +==================== +*/ +static void LAN_ClearPing( int n ) { + CL_ClearPing( n ); +} + +/* +==================== +LAN_GetPing +==================== +*/ +static void LAN_GetPing( int n, char *buf, int buflen, int *pingtime ) { + CL_GetPing( n, buf, buflen, pingtime ); +} + +/* +==================== +LAN_GetPingInfo +==================== +*/ +static void LAN_GetPingInfo( int n, char *buf, int buflen ) { + CL_GetPingInfo( n, buf, buflen ); +} + +/* +==================== +LAN_MarkServerVisible +==================== +*/ +static void LAN_MarkServerVisible( int source, int n, qboolean visible ) { + if ( n == -1 ) { + int count = MAX_OTHER_SERVERS; + serverInfo_t *server = NULL; + switch ( source ) { + case AS_LOCAL: + server = &cls.localServers[0]; + break; + case AS_MPLAYER: + server = &cls.mplayerServers[0]; + break; + case AS_GLOBAL: + server = &cls.globalServers[0]; + count = MAX_GLOBAL_SERVERS; + break; + case AS_FAVORITES: + server = &cls.favoriteServers[0]; + break; + } + if ( server ) { + for ( n = 0; n < count; n++ ) { + server[n].visible = visible; + } + } + + } else { + switch ( source ) { + case AS_LOCAL: + if ( n >= 0 && n < MAX_OTHER_SERVERS ) { + cls.localServers[n].visible = visible; + } + break; + case AS_MPLAYER: + if ( n >= 0 && n < MAX_OTHER_SERVERS ) { + cls.mplayerServers[n].visible = visible; + } + break; + case AS_GLOBAL: + if ( n >= 0 && n < MAX_GLOBAL_SERVERS ) { + cls.globalServers[n].visible = visible; + } + break; + case AS_FAVORITES: + if ( n >= 0 && n < MAX_OTHER_SERVERS ) { + cls.favoriteServers[n].visible = visible; + } + break; + } + } +} + + +/* +======================= +LAN_ServerIsVisible +======================= +*/ +static int LAN_ServerIsVisible( int source, int n ) { + switch ( source ) { + case AS_LOCAL: + if ( n >= 0 && n < MAX_OTHER_SERVERS ) { + return cls.localServers[n].visible; + } + break; + case AS_MPLAYER: + if ( n >= 0 && n < MAX_OTHER_SERVERS ) { + return cls.mplayerServers[n].visible; + } + break; + case AS_GLOBAL: + if ( n >= 0 && n < MAX_GLOBAL_SERVERS ) { + return cls.globalServers[n].visible; + } + break; + case AS_FAVORITES: + if ( n >= 0 && n < MAX_OTHER_SERVERS ) { + return cls.favoriteServers[n].visible; + } + break; + } + return qfalse; +} + +/* +======================= +LAN_UpdateVisiblePings +======================= +*/ +qboolean LAN_UpdateVisiblePings( int source ) { + return CL_UpdateVisiblePings_f( source ); +} + +/* +==================== +LAN_GetServerStatus +==================== +*/ +int LAN_GetServerStatus( char *serverAddress, char *serverStatus, int maxLen ) { + return CL_ServerStatus( serverAddress, serverStatus, maxLen ); +} + +/* +==================== +CL_GetGlConfig +==================== +*/ +static void CL_GetGlconfig( glconfig_t *config ) { + *config = cls.glconfig; +} + +/* +==================== +GetClipboardData +==================== +*/ +static void GetClipboardData( char *buf, int buflen ) { + char *cbd; + + cbd = Sys_GetClipboardData(); + + if ( !cbd ) { + *buf = 0; + return; + } + + Q_strncpyz( buf, cbd, buflen ); + + Z_Free( cbd ); +} + +/* +==================== +Key_KeynumToStringBuf +==================== +*/ +static void Key_KeynumToStringBuf( int keynum, char *buf, int buflen ) { + Q_strncpyz( buf, Key_KeynumToString( keynum, qtrue ), buflen ); +} + +/* +==================== +Key_GetBindingBuf +==================== +*/ +static void Key_GetBindingBuf( int keynum, char *buf, int buflen ) { + char *value; + + value = Key_GetBinding( keynum ); + if ( value ) { + Q_strncpyz( buf, value, buflen ); + } else { + *buf = 0; + } +} + +/* +==================== +Key_GetCatcher +==================== +*/ +int Key_GetCatcher( void ) { + return cls.keyCatchers; +} + +/* +==================== +Ket_SetCatcher +==================== +*/ +void Key_SetCatcher( int catcher ) { + cls.keyCatchers = catcher; +} + + +/* +==================== +CLUI_GetCDKey +==================== +*/ +static void CLUI_GetCDKey( char *buf, int buflen ) { + cvar_t *fs; + fs = Cvar_Get( "fs_game", "", CVAR_INIT | CVAR_SYSTEMINFO ); + if ( UI_usesUniqueCDKey() && fs && fs->string[0] != 0 ) { + memcpy( buf, &cl_cdkey[16], 16 ); + buf[16] = 0; + } else { + memcpy( buf, cl_cdkey, 16 ); + buf[16] = 0; + } +} + + +/* +==================== +CLUI_SetCDKey +==================== +*/ +static void CLUI_SetCDKey( char *buf ) { + cvar_t *fs; + fs = Cvar_Get( "fs_game", "", CVAR_INIT | CVAR_SYSTEMINFO ); + if ( UI_usesUniqueCDKey() && fs && fs->string[0] != 0 ) { + memcpy( &cl_cdkey[16], buf, 16 ); + cl_cdkey[32] = 0; + // set the flag so the fle will be written at the next opportunity + cvar_modifiedFlags |= CVAR_ARCHIVE; + } else { + memcpy( cl_cdkey, buf, 16 ); + // set the flag so the fle will be written at the next opportunity + cvar_modifiedFlags |= CVAR_ARCHIVE; + } +} + + +/* +==================== +GetConfigString +==================== +*/ +static int GetConfigString( int index, char *buf, int size ) { + int offset; + + if ( index < 0 || index >= MAX_CONFIGSTRINGS ) { + return qfalse; + } + + offset = cl.gameState.stringOffsets[index]; + if ( !offset ) { + if ( size ) { + buf[0] = 0; + } + return qfalse; + } + + Q_strncpyz( buf, cl.gameState.stringData + offset, size ); + + return qtrue; +} + +/* +==================== +FloatAsInt +==================== +*/ +static int FloatAsInt( float f ) { + int temp; + + *(float *)&temp = f; + + return temp; +} + +void *VM_ArgPtr( int intValue ); +#define VMA( x ) VM_ArgPtr( args[x] ) +#define VMF( x ) ( (float *)args )[x] + + +extern void showKeyboard(int val); + +/* +==================== +CL_UISystemCalls + +The ui module is making a system call +==================== +*/ +int CL_UISystemCalls( int *args ) { + switch ( args[0] ) { + case UI_ERROR: + Com_Error( ERR_DROP, "%s", VMA( 1 ) ); + return 0; + + case UI_PRINT: + Com_Printf( "%s", VMA( 1 ) ); + return 0; + + case UI_MILLISECONDS: + return Sys_Milliseconds(); + + case UI_CVAR_REGISTER: + Cvar_Register( VMA( 1 ), VMA( 2 ), VMA( 3 ), args[4] ); + return 0; + + case UI_CVAR_UPDATE: + Cvar_Update( VMA( 1 ) ); + return 0; + + case UI_CVAR_SET: + Cvar_Set( VMA( 1 ), VMA( 2 ) ); + return 0; + + case UI_CVAR_VARIABLEVALUE: + return FloatAsInt( Cvar_VariableValue( VMA( 1 ) ) ); + + case UI_CVAR_VARIABLESTRINGBUFFER: + Cvar_VariableStringBuffer( VMA( 1 ), VMA( 2 ), args[3] ); + return 0; + + case UI_CVAR_SETVALUE: + Cvar_SetValue( VMA( 1 ), VMF( 2 ) ); + return 0; + + case UI_CVAR_RESET: + Cvar_Reset( VMA( 1 ) ); + return 0; + + case UI_CVAR_CREATE: + Cvar_Get( VMA( 1 ), VMA( 2 ), args[3] ); + return 0; + + case UI_CVAR_INFOSTRINGBUFFER: + Cvar_InfoStringBuffer( args[1], VMA( 2 ), args[3] ); + return 0; + + case UI_ARGC: + return Cmd_Argc(); + + case UI_ARGV: + Cmd_ArgvBuffer( args[1], VMA( 2 ), args[3] ); + return 0; + + case UI_CMD_EXECUTETEXT: + Cbuf_ExecuteText( args[1], VMA( 2 ) ); + return 0; + + case UI_FS_FOPENFILE: + return FS_FOpenFileByMode( VMA( 1 ), VMA( 2 ), args[3] ); + + case UI_FS_READ: + FS_Read( VMA( 1 ), args[2], args[3] ); + return 0; + +//----(SA) added + case UI_FS_SEEK: + FS_Seek( args[1], args[2], args[3] ); + return 0; +//----(SA) end + + case UI_FS_WRITE: + FS_Write( VMA( 1 ), args[2], args[3] ); + return 0; + + case UI_FS_FCLOSEFILE: + FS_FCloseFile( args[1] ); + return 0; + + case UI_FS_DELETEFILE: + return FS_Delete( VMA( 1 ) ); + + case UI_FS_GETFILELIST: + return FS_GetFileList( VMA( 1 ), VMA( 2 ), VMA( 3 ), args[4] ); + + case UI_R_REGISTERMODEL: + return re.RegisterModel( VMA( 1 ) ); + + case UI_R_REGISTERSKIN: + return re.RegisterSkin( VMA( 1 ) ); + + case UI_R_REGISTERSHADERNOMIP: + return re.RegisterShaderNoMip( VMA( 1 ) ); + + case UI_R_CLEARSCENE: + re.ClearScene(); + return 0; + + case UI_R_ADDREFENTITYTOSCENE: + re.AddRefEntityToScene( VMA( 1 ) ); + return 0; + + case UI_R_ADDPOLYTOSCENE: + re.AddPolyToScene( args[1], args[2], VMA( 3 ) ); + return 0; + + // Ridah + case UI_R_ADDPOLYSTOSCENE: + re.AddPolysToScene( args[1], args[2], VMA( 3 ), args[4] ); + return 0; + // done. + + case UI_R_ADDLIGHTTOSCENE: + re.AddLightToScene( VMA( 1 ), VMF( 2 ), VMF( 3 ), VMF( 4 ), VMF( 5 ), args[6] ); + return 0; + + case UI_R_ADDCORONATOSCENE: + re.AddCoronaToScene( VMA( 1 ), VMF( 2 ), VMF( 3 ), VMF( 4 ), VMF( 5 ), args[6], args[7] ); + return 0; + + case UI_R_RENDERSCENE: + re.RenderScene( VMA( 1 ) ); + return 0; + + case UI_R_SETCOLOR: + re.SetColor( VMA( 1 ) ); + return 0; + + case UI_R_DRAWSTRETCHPIC: + re.DrawStretchPic( VMF( 1 ), VMF( 2 ), VMF( 3 ), VMF( 4 ), VMF( 5 ), VMF( 6 ), VMF( 7 ), VMF( 8 ), args[9] ); + return 0; + + case UI_R_MODELBOUNDS: + re.ModelBounds( args[1], VMA( 2 ), VMA( 3 ) ); + return 0; + + case UI_UPDATESCREEN: + SCR_UpdateScreen(); + return 0; + + case UI_CM_LERPTAG: + return re.LerpTag( VMA( 1 ), VMA( 2 ), VMA( 3 ), args[4] ); + + case UI_S_REGISTERSOUND: +#ifdef DOOMSOUND ///// (SA) DOOMSOUND + return S_RegisterSound( VMA( 1 ) ); +#else + return S_RegisterSound( VMA( 1 ), qfalse ); +#endif ///// (SA) DOOMSOUND + + case UI_S_STARTLOCALSOUND: + S_StartLocalSound( args[1], args[2] ); + return 0; + +//----(SA) added + case UI_S_FADESTREAMINGSOUND: + S_FadeStreamingSound( VMF( 1 ), args[2], args[3] ); + return 0; + + case UI_S_FADEALLSOUNDS: + S_FadeAllSounds( VMF( 1 ), args[2] ); + return 0; +//----(SA) end + + case UI_KEY_KEYNUMTOSTRINGBUF: + Key_KeynumToStringBuf( args[1], VMA( 2 ), args[3] ); + return 0; + + case UI_KEY_GETBINDINGBUF: + Key_GetBindingBuf( args[1], VMA( 2 ), args[3] ); + return 0; + + case UI_KEY_SETBINDING: + Key_SetBinding( args[1], VMA( 2 ) ); + return 0; + + case UI_KEY_ISDOWN: + return Key_IsDown( args[1] ); + + case UI_KEY_GETOVERSTRIKEMODE: + return Key_GetOverstrikeMode(); + + case UI_KEY_SETOVERSTRIKEMODE: + Key_SetOverstrikeMode( args[1] ); + return 0; + + case UI_KEY_CLEARSTATES: + Key_ClearStates(); + return 0; + + case UI_KEY_GETCATCHER: + return Key_GetCatcher(); + + case UI_KEY_SETCATCHER: + Key_SetCatcher( args[1] ); + return 0; + + case UI_GETCLIPBOARDDATA: + GetClipboardData( VMA( 1 ), args[2] ); + return 0; + + case UI_GETCLIENTSTATE: + GetClientState( VMA( 1 ) ); + return 0; + + case UI_GETGLCONFIG: + CL_GetGlconfig( VMA( 1 ) ); + return 0; + + case UI_GETCONFIGSTRING: + return GetConfigString( args[1], VMA( 2 ), args[3] ); + + case UI_LAN_LOADCACHEDSERVERS: + LAN_LoadCachedServers(); + return 0; + + case UI_LAN_SAVECACHEDSERVERS: + LAN_SaveServersToCache(); + return 0; + + case UI_LAN_ADDSERVER: + return LAN_AddServer( args[1], VMA( 2 ), VMA( 3 ) ); + + case UI_LAN_REMOVESERVER: + LAN_RemoveServer( args[1], VMA( 2 ) ); + return 0; + + case UI_LAN_GETPINGQUEUECOUNT: + return LAN_GetPingQueueCount(); + + case UI_LAN_CLEARPING: + LAN_ClearPing( args[1] ); + return 0; + + case UI_LAN_GETPING: + LAN_GetPing( args[1], VMA( 2 ), args[3], VMA( 4 ) ); + return 0; + + case UI_LAN_GETPINGINFO: + LAN_GetPingInfo( args[1], VMA( 2 ), args[3] ); + return 0; + + case UI_LAN_GETSERVERCOUNT: + return LAN_GetServerCount( args[1] ); + + case UI_LAN_GETSERVERADDRESSSTRING: + LAN_GetServerAddressString( args[1], args[2], VMA( 3 ), args[4] ); + return 0; + + case UI_LAN_GETSERVERINFO: + LAN_GetServerInfo( args[1], args[2], VMA( 3 ), args[4] ); + return 0; + + case UI_LAN_GETSERVERPING: + return LAN_GetServerPing( args[1], args[2] ); + + case UI_LAN_MARKSERVERVISIBLE: + LAN_MarkServerVisible( args[1], args[2], args[3] ); + return 0; + + case UI_LAN_SERVERISVISIBLE: + return LAN_ServerIsVisible( args[1], args[2] ); + + case UI_LAN_UPDATEVISIBLEPINGS: + return LAN_UpdateVisiblePings( args[1] ); + + case UI_LAN_RESETPINGS: + LAN_ResetPings( args[1] ); + return 0; + + case UI_LAN_SERVERSTATUS: + return LAN_GetServerStatus( VMA( 1 ), VMA( 2 ), args[3] ); + + case UI_LAN_COMPARESERVERS: + return LAN_CompareServers( args[1], args[2], args[3], args[4], args[5] ); + + case UI_MEMORY_REMAINING: + return Hunk_MemoryRemaining(); + + case UI_GET_CDKEY: + CLUI_GetCDKey( VMA( 1 ), args[2] ); + return 0; + + case UI_SET_CDKEY: + CLUI_SetCDKey( VMA( 1 ) ); + return 0; + + case UI_R_REGISTERFONT: + re.RegisterFont( VMA( 1 ), args[2], VMA( 3 ) ); + return 0; + + case UI_MEMSET: + return (int)memset( VMA( 1 ), args[2], args[3] ); + + case UI_MEMCPY: + return (int)memcpy( VMA( 1 ), VMA( 2 ), args[3] ); + + case UI_STRNCPY: + return (int)strncpy( VMA( 1 ), VMA( 2 ), args[3] ); + + case UI_SIN: + return FloatAsInt( sin( VMF( 1 ) ) ); + + case UI_COS: + return FloatAsInt( cos( VMF( 1 ) ) ); + + case UI_ATAN2: + return FloatAsInt( atan2( VMF( 1 ), VMF( 2 ) ) ); + + case UI_SQRT: + return FloatAsInt( sqrt( VMF( 1 ) ) ); + + case UI_FLOOR: + return FloatAsInt( floor( VMF( 1 ) ) ); + + case UI_CEIL: + return FloatAsInt( ceil( VMF( 1 ) ) ); + + case UI_PC_ADD_GLOBAL_DEFINE: + return botlib_export->PC_AddGlobalDefine( VMA( 1 ) ); + case UI_PC_LOAD_SOURCE: + return botlib_export->PC_LoadSourceHandle( VMA( 1 ) ); + case UI_PC_FREE_SOURCE: + return botlib_export->PC_FreeSourceHandle( args[1] ); + case UI_PC_READ_TOKEN: + return botlib_export->PC_ReadTokenHandle( args[1], VMA( 2 ) ); + case UI_PC_SOURCE_FILE_AND_LINE: + return botlib_export->PC_SourceFileAndLine( args[1], VMA( 2 ), VMA( 3 ) ); + + case UI_S_STOPBACKGROUNDTRACK: + S_StopBackgroundTrack(); + return 0; + case UI_S_STARTBACKGROUNDTRACK: + S_StartBackgroundTrack( VMA( 1 ), VMA( 2 ), args[3] ); //----(SA) added fadeup time + return 0; + + case UI_REAL_TIME: + return Com_RealTime( VMA( 1 ) ); + + case UI_CIN_PLAYCINEMATIC: + Com_DPrintf( "UI_CIN_PlayCinematic\n" ); + return CIN_PlayCinematic( VMA( 1 ), args[2], args[3], args[4], args[5], args[6] ); + + case UI_CIN_STOPCINEMATIC: + return CIN_StopCinematic( args[1] ); + + case UI_CIN_RUNCINEMATIC: + return CIN_RunCinematic( args[1] ); + + case UI_CIN_DRAWCINEMATIC: + CIN_DrawCinematic( args[1] ); + return 0; + + case UI_CIN_SETEXTENTS: + CIN_SetExtents( args[1], args[2], args[3], args[4], args[5] ); + return 0; + + case UI_R_REMAP_SHADER: + re.RemapShader( VMA( 1 ), VMA( 2 ), VMA( 3 ) ); + return 0; + + case UI_VERIFY_CDKEY: + return CL_CDKeyValidate( VMA( 1 ), VMA( 2 ) ); + + // NERVE - SMF + case UI_CL_GETLIMBOSTRING: + return CL_GetLimboString( args[1], VMA( 2 ) ); + // -NERVE - SMF + case UI_CIN_SHOWSOFTKEYBOARD: + showKeyboard(args[1]); + return; + default: + Com_Error( ERR_DROP, "Bad UI system trap: %i", args[0] ); + + } + + return 0; +} + +/* +==================== +CL_ShutdownUI +==================== +*/ +void CL_ShutdownUI( void ) { + cls.keyCatchers &= ~KEYCATCH_UI; + cls.uiStarted = qfalse; + if ( !uivm ) { + return; + } + VM_Call( uivm, UI_SHUTDOWN ); + VM_Free( uivm ); + uivm = NULL; +} + +/* +==================== +CL_InitUI +==================== +*/ + +void CL_InitUI( void ) { + int v; + vmInterpret_t interpret; + + // load the dll or bytecode + if ( cl_connectedToPureServer != 0 ) { + // if sv_pure is set we only allow qvms to be loaded + interpret = VMI_COMPILED; + } else { + interpret = Cvar_VariableValue( "vm_ui" ); + } + +//----(SA) always dll + +#ifdef WOLF_SP_DEMO + uivm = VM_Create( "ui", CL_UISystemCalls, VMI_NATIVE ); +#else + uivm = VM_Create( "ui", CL_UISystemCalls, Cvar_VariableValue( "vm_ui" ) ); +#endif + + if ( !uivm ) { + Com_Error( ERR_FATAL, "VM_Create on UI failed" ); + } + + // sanity check + v = VM_Call( uivm, UI_GETAPIVERSION ); + if ( v != UI_API_VERSION ) { + Com_Error( ERR_FATAL, "User Interface is version %d, expected %d", v, UI_API_VERSION ); + cls.uiStarted = qfalse; + } + + // init for this gamestate +// VM_Call( uivm, UI_INIT ); + VM_Call( uivm, UI_INIT, ( cls.state >= CA_AUTHORIZING && cls.state < CA_ACTIVE ) ); +} + + +qboolean UI_usesUniqueCDKey() { + if ( uivm ) { + return ( VM_Call( uivm, UI_HASUNIQUECDKEY ) == qtrue ); + } else { + return qfalse; + } +} + +/* +==================== +UI_GameCommand + +See if the current console command is claimed by the ui +==================== +*/ +qboolean UI_GameCommand( void ) { + if ( !uivm ) { + return qfalse; + } + + return VM_Call( uivm, UI_CONSOLE_COMMAND, cls.realtime ); +} diff --git a/Projects/Android/jni/rtcw/src/client/client.h b/Projects/Android/jni/rtcw/src/client/client.h new file mode 100644 index 0000000..0bfa258 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/client/client.h @@ -0,0 +1,593 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +// client.h -- primary header for client + +#include "../game/q_shared.h" +#include "../qcommon/qcommon.h" +#include "../renderer/tr_public.h" +#include "../ui/ui_public.h" +#include "keys.h" +#include "snd_public.h" +#include "../cgame/cg_public.h" +#include "../game/bg_public.h" + +#define RETRANSMIT_TIMEOUT 3000 // time between connection packet retransmits + +#define LIMBOCHAT_WIDTH 140 // NERVE - SMF +#define LIMBOCHAT_HEIGHT 7 // NERVE - SMF + +// snapshots are a view of the server at a given time +typedef struct { + qboolean valid; // cleared if delta parsing was invalid + int snapFlags; // rate delayed and dropped commands + + int serverTime; // server time the message is valid for (in msec) + + int messageNum; // copied from netchan->incoming_sequence + int deltaNum; // messageNum the delta is from + int ping; // time from when cmdNum-1 was sent to time packet was reeceived + byte areamask[MAX_MAP_AREA_BYTES]; // portalarea visibility bits + + int cmdNum; // the next cmdNum the server is expecting + playerState_t ps; // complete information about the current player at this time + + int numEntities; // all of the entities that need to be presented + int parseEntitiesNum; // at the time of this snapshot + + int serverCommandNum; // execute all commands up to this before + // making the snapshot current +} clSnapshot_t; + + + +/* +============================================================================= + +the clientActive_t structure is wiped completely at every +new gamestate_t, potentially several times during an established connection + +============================================================================= +*/ + +typedef struct { + int p_cmdNumber; // cl.cmdNumber when packet was sent + int p_serverTime; // usercmd->serverTime when packet was sent + int p_realtime; // cls.realtime when packet was sent +} outPacket_t; + +// the parseEntities array must be large enough to hold PACKET_BACKUP frames of +// entities, so that when a delta compressed message arives from the server +// it can be un-deltad from the original +#define MAX_PARSE_ENTITIES 2048 + +extern int g_console_field_width; + +typedef struct { + int timeoutcount; // it requres several frames in a timeout condition + // to disconnect, preventing debugging breaks from + // causing immediate disconnects on continue + clSnapshot_t snap; // latest received from server + + int serverTime; // may be paused during play + int oldServerTime; // to prevent time from flowing bakcwards + int oldFrameServerTime; // to check tournament restarts + int serverTimeDelta; // cl.serverTime = cls.realtime + cl.serverTimeDelta + // this value changes as net lag varies + qboolean extrapolatedSnapshot; // set if any cgame frame has been forced to extrapolate + // cleared when CL_AdjustTimeDelta looks at it + qboolean newSnapshots; // set on parse of any valid packet + + gameState_t gameState; // configstrings + char mapname[MAX_QPATH]; // extracted from CS_SERVERINFO + + int parseEntitiesNum; // index (not anded off) into cl_parse_entities[] + + int mouseDx[2], mouseDy[2]; // added to by mouse events + int mouseIndex; + int joystickAxis[MAX_JOYSTICK_AXIS]; // set by joystick events + + // cgame communicates a few values to the client system + int cgameUserCmdValue; // current weapon to add to usercmd_t + int cgameUserHoldableValue; // current holdable item to add to usercmd_t //----(SA) added + float cgameSensitivity; + int cgameCld; // NERVE - SMF +#ifdef AUTOAIM + int cgameLastFireTime; + short cgameCrossHairStatus; +#endif + // cmds[cmdNumber] is the predicted command, [cmdNumber-1] is the last + // properly generated command + usercmd_t cmds[CMD_BACKUP]; // each mesage will send several old cmds + int cmdNumber; // incremented each frame, because multiple + // frames may need to be packed into a single packet + + outPacket_t outPackets[PACKET_BACKUP]; // information about each packet we have sent out + + // the client maintains its own idea of view angles, which are + // sent to the server each frame. It is cleared to 0 upon entering each level. + // the server sends a delta each frame which is added to the locally + // tracked view angles to account for standing on rotating objects, + // and teleport direction changes + vec3_t viewangles; + + int serverId; // included in each client message so the server + // can tell if it is for a prior map_restart + // big stuff at end of structure so most offsets are 15 bits or less + clSnapshot_t snapshots[PACKET_BACKUP]; + + entityState_t entityBaselines[MAX_GENTITIES]; // for delta compression when not in previous frame + + entityState_t parseEntities[MAX_PARSE_ENTITIES]; + + // NERVE - SMF + char limboChatMsgs[LIMBOCHAT_HEIGHT][LIMBOCHAT_WIDTH * 3 + 1]; + int limboChatPos; + // -NERVE - SMF + + qboolean cameraMode; //----(SA) added for control of input while watching cinematics + +} clientActive_t; + +extern clientActive_t cl; + +/* +============================================================================= + +the clientConnection_t structure is wiped when disconnecting from a server, +either to go to a full screen console, play a demo, or connect to a different server + +A connection can be to either a server through the network layer or a +demo through a file. + +============================================================================= +*/ + + +typedef struct { + + int clientNum; + int lastPacketSentTime; // for retransmits during connection + int lastPacketTime; // for timeouts + + netadr_t serverAddress; + int connectTime; // for connection retransmits + int connectPacketCount; // for display on connection dialog + char serverMessage[MAX_STRING_TOKENS]; // for display on connection dialog + + int challenge; // from the server to use for connecting + int checksumFeed; // from the server for checksum calculations + + // these are our reliable messages that go to the server + int reliableSequence; + int reliableAcknowledge; // the last one the server has executed + char reliableCommands[MAX_RELIABLE_COMMANDS][MAX_TOKEN_CHARS]; + + // server message (unreliable) and command (reliable) sequence + // numbers are NOT cleared at level changes, but continue to + // increase as long as the connection is valid + + // message sequence is used by both the network layer and the + // delta compression layer + int serverMessageSequence; + + // reliable messages received from server + int serverCommandSequence; + int lastExecutedServerCommand; // last server command grabbed or executed with CL_GetServerCommand + char serverCommands[MAX_RELIABLE_COMMANDS][MAX_TOKEN_CHARS]; + + // file transfer from server + fileHandle_t download; + char downloadTempName[MAX_OSPATH]; + char downloadName[MAX_OSPATH]; + int downloadNumber; + int downloadBlock; // block we are waiting for + int downloadCount; // how many bytes we got + int downloadSize; // how many bytes we got + char downloadList[MAX_INFO_STRING]; // list of paks we need to download + qboolean downloadRestart; // if true, we need to do another FS_Restart because we downloaded a pak + + // demo information + char demoName[MAX_QPATH]; + qboolean demorecording; + qboolean demoplaying; + qboolean demowaiting; // don't record until a non-delta message is received + qboolean firstDemoFrameSkipped; + fileHandle_t demofile; + + int timeDemoFrames; // counter of rendered frames + int timeDemoStart; // cls.realtime before first frame + int timeDemoBaseTime; // each frame will be at this time + frameNum * 50 + + // big stuff at end of structure so most offsets are 15 bits or less + netchan_t netchan; +} clientConnection_t; + +extern clientConnection_t clc; + +/* +================================================================== + +the clientStatic_t structure is never wiped, and is used even when +no client connection is active at all + +================================================================== +*/ + +typedef struct { + netadr_t adr; + int start; + int time; + char info[MAX_INFO_STRING]; +} ping_t; + +typedef struct { + netadr_t adr; + char hostName[MAX_NAME_LENGTH]; + char mapName[MAX_NAME_LENGTH]; + char game[MAX_NAME_LENGTH]; + int netType; + int gameType; + int clients; + int maxClients; + int minPing; + int maxPing; + int ping; + qboolean visible; + int allowAnonymous; +} serverInfo_t; + +typedef struct { + byte ip[4]; + unsigned short port; +} serverAddress_t; + +typedef struct { + connstate_t state; // connection status + int keyCatchers; // bit flags + + qboolean cddialog; // bring up the cd needed dialog next frame + qboolean endgamemenu; // bring up the end game credits menu next frame + + char servername[MAX_OSPATH]; // name of server from original connect (used by reconnect) + + // when the server clears the hunk, all of these must be restarted + qboolean rendererStarted; + qboolean soundStarted; + qboolean soundRegistered; + qboolean uiStarted; + qboolean cgameStarted; + + int framecount; + int frametime; // msec since last frame + + int realtime; // ignores pause + int realFrametime; // ignoring pause, so console always works + + int numlocalservers; + serverInfo_t localServers[MAX_OTHER_SERVERS]; + + int numglobalservers; + serverInfo_t globalServers[MAX_GLOBAL_SERVERS]; + // additional global servers + int numGlobalServerAddresses; + serverAddress_t globalServerAddresses[MAX_GLOBAL_SERVERS]; + + int numfavoriteservers; + serverInfo_t favoriteServers[MAX_OTHER_SERVERS]; + + int nummplayerservers; + serverInfo_t mplayerServers[MAX_OTHER_SERVERS]; + + int pingUpdateSource; // source currently pinging or updating + + int masterNum; + + // update server info + netadr_t updateServer; + char updateChallenge[MAX_TOKEN_CHARS]; + char updateInfoString[MAX_INFO_STRING]; + + netadr_t authorizeServer; + + // rendering info + glconfig_t glconfig; + qhandle_t charSetShader; + qhandle_t whiteShader; + qhandle_t consoleShader; + qhandle_t consoleShader2; //----(SA) added + +} clientStatic_t; + +extern clientStatic_t cls; + +//============================================================================= + +extern vm_t *cgvm; // interface to cgame dll or vm +extern vm_t *uivm; // interface to ui dll or vm +extern refexport_t re; // interface to refresh .dll + + +// +// cvars +// +extern cvar_t *cl_nodelta; +extern cvar_t *cl_debugMove; +extern cvar_t *cl_noprint; +extern cvar_t *cl_timegraph; +extern cvar_t *cl_maxpackets; +extern cvar_t *cl_packetdup; +extern cvar_t *cl_shownet; +extern cvar_t *cl_showSend; +extern cvar_t *cl_timeNudge; +extern cvar_t *cl_showTimeDelta; +extern cvar_t *cl_freezeDemo; + +extern cvar_t *cl_yawspeed; +extern cvar_t *cl_pitchspeed; +extern cvar_t *cl_run; +extern cvar_t *cl_anglespeedkey; + +extern cvar_t *cl_recoilPitch; // RF + +extern cvar_t *cl_sensitivity; +extern cvar_t *cl_freelook; + +extern cvar_t *cl_mouseAccel; +extern cvar_t *cl_showMouseRate; + +extern cvar_t *m_pitch; +extern cvar_t *m_yaw; +extern cvar_t *m_forward; +extern cvar_t *m_side; +extern cvar_t *m_filter; + +extern cvar_t *cl_timedemo; + +extern cvar_t *cl_activeAction; + +extern cvar_t *cl_allowDownload; +extern cvar_t *cl_conXOffset; +extern cvar_t *cl_inGameVideo; + +extern cvar_t *cl_missionStats; +extern cvar_t *cl_waitForFire; + +// NERVE - SMF - localization +extern cvar_t *cl_language; +// -NERVE - SMF +//================================================= + +// +// cl_main +// + +void CL_Init( void ); +void CL_FlushMemory( void ); +void CL_ShutdownAll( void ); +void CL_AddReliableCommand( const char *cmd ); + +void CL_StartHunkUsers( void ); + +void CL_Disconnect_f( void ); +void CL_GetChallengePacket( void ); +void CL_Vid_Restart_f( void ); +void CL_Snd_Restart_f( void ); +void CL_StartDemoLoop( void ); +void CL_NextDemo( void ); +void CL_ReadDemoMessage( void ); + +void CL_InitDownloads( void ); +void CL_NextDownload( void ); + +void CL_GetPing( int n, char *buf, int buflen, int *pingtime ); +void CL_GetPingInfo( int n, char *buf, int buflen ); +void CL_ClearPing( int n ); +int CL_GetPingQueueCount( void ); + +void CL_ShutdownRef( void ); +void CL_InitRef( void ); +qboolean CL_CDKeyValidate( const char *key, const char *checksum ); +int CL_ServerStatus( char *serverAddress, char *serverStatusString, int maxLen ); + +void CL_AddToLimboChat( const char *str ); // NERVE - SMF +qboolean CL_GetLimboString( int index, char *buf ); // NERVE - SMF + +// +// cl_input +// +typedef struct { + int down[2]; // key nums holding it down + unsigned downtime; // msec timestamp + unsigned msec; // msec down this frame if both a down and up happened + qboolean active; // current state + qboolean wasPressed; // set when down, not cleared when up +} kbutton_t; + +typedef enum { + KB_LEFT, + KB_RIGHT, + KB_FORWARD, + KB_BACK, + KB_LOOKUP, + KB_LOOKDOWN, + KB_MOVELEFT, + KB_MOVERIGHT, + KB_STRAFE, + KB_SPEED, + KB_UP, + KB_DOWN, + KB_BUTTONS0, + KB_BUTTONS1, + KB_BUTTONS2, + KB_BUTTONS3, + KB_BUTTONS4, + KB_BUTTONS5, + KB_BUTTONS6, + KB_BUTTONS7, + KB_WBUTTONS0, + KB_WBUTTONS1, + KB_WBUTTONS2, + KB_WBUTTONS3, + KB_WBUTTONS4, + KB_WBUTTONS5, + KB_WBUTTONS6, + KB_WBUTTONS7, + KB_MLOOK, + KB_KICK, + + NUM_BUTTONS +} kbuttons_t; + + +void CL_ClearKeys( void ); + +void CL_InitInput( void ); +void CL_SendCmd( void ); +void CL_ClearState( void ); +void CL_ReadPackets( void ); + +void CL_WritePacket( void ); +void IN_CenterView( void ); +void IN_Notebook( void ); +void IN_Help( void ); + +//----(SA) salute +void IN_Salute( void ); +//----(SA) + +void CL_VerifyCode( void ); + +float CL_KeyState( kbutton_t *key ); +char *Key_KeynumToString( int keynum, qboolean bTranslate ); + +// +// cl_parse.c +// +extern int cl_connectedToPureServer; + +void CL_SystemInfoChanged( void ); +void CL_ParseServerMessage( msg_t *msg ); + +//==================================================================== + +void CL_ServerInfoPacket( netadr_t from, msg_t *msg ); +void CL_LocalServers_f( void ); +void CL_GlobalServers_f( void ); +void CL_FavoriteServers_f( void ); +void CL_Ping_f( void ); +qboolean CL_UpdateVisiblePings_f( int source ); + + +// +// console +// +void Con_DrawCharacter( int cx, int line, int num ); + +void Con_CheckResize( void ); +void Con_Init( void ); +void Con_Clear_f( void ); +void Con_ToggleConsole_f( void ); +void Con_DrawNotify( void ); +void Con_ClearNotify( void ); +void Con_RunConsole( void ); +void Con_DrawConsole( void ); +void Con_PageUp( void ); +void Con_PageDown( void ); +void Con_Top( void ); +void Con_Bottom( void ); +void Con_Close( void ); + + +// +// cl_scrn.c +// +void SCR_Init( void ); +void SCR_UpdateScreen( void ); + +void SCR_DebugGraph( float value, int color ); + +int SCR_GetBigStringWidth( const char *str ); // returns in virtual 640x480 coordinates + +void SCR_AdjustFrom640( float *x, float *y, float *w, float *h ); +void SCR_FillRect( float x, float y, float width, float height, + const float *color ); +void SCR_DrawPic( float x, float y, float width, float height, qhandle_t hShader ); +void SCR_DrawNamedPic( float x, float y, float width, float height, const char *picname ); + +void SCR_DrawBigString( int x, int y, const char *s, float alpha ); // draws a string with embedded color control characters with fade +void SCR_DrawBigStringColor( int x, int y, const char *s, vec4_t color ); // ignores embedded color control characters +void SCR_DrawSmallStringExt( int x, int y, const char *string, float *setColor, qboolean forceColor ); +void SCR_DrawSmallChar( int x, int y, int ch ); + + +// +// cl_cin.c +// + +void CL_PlayCinematic_f( void ); +void SCR_DrawCinematic( void ); +void SCR_RunCinematic( void ); +void SCR_StopCinematic( void ); +int CIN_PlayCinematic( const char *arg0, int xpos, int ypos, int width, int height, int bits ); +e_status CIN_StopCinematic( int handle ); +e_status CIN_RunCinematic( int handle ); +void CIN_DrawCinematic( int handle ); +void CIN_SetExtents( int handle, int x, int y, int w, int h ); +void CIN_SetLooping( int handle, qboolean loop ); +void CIN_UploadCinematic( int handle ); +void CIN_CloseAllVideos( void ); + +// +// cl_cgame.c +// +void CL_InitCGame( void ); +void CL_ShutdownCGame( void ); +qboolean CL_GameCommand( void ); +void CL_CGameRendering( stereoFrame_t stereo ); +void CL_SetCGameTime( void ); +void CL_FirstSnapshot( void ); +void CL_ShaderStateChanged( void ); +void CL_UpdateLevelHunkUsage( void ); +// +// cl_ui.c +// +void CL_InitUI( void ); +void CL_ShutdownUI( void ); +int Key_GetCatcher( void ); +void Key_SetCatcher( int catcher ); +void LAN_LoadCachedServers(); +void LAN_SaveServersToCache(); + + +// +// cl_net_chan.c +// +void CL_Netchan_Transmit( netchan_t *chan, msg_t* msg ); //int length, const byte *data ); +void CL_Netchan_TransmitNextFragment( netchan_t *chan ); +qboolean CL_Netchan_Process( netchan_t *chan, msg_t *msg ); diff --git a/Projects/Android/jni/rtcw/src/client/keys.h b/Projects/Android/jni/rtcw/src/client/keys.h new file mode 100644 index 0000000..961b2d7 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/client/keys.h @@ -0,0 +1,66 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +#include "../ui/keycodes.h" + +#define MAX_KEYS 256 + +typedef struct { + qboolean down; + int repeats; // if > 1, it is autorepeating + char *binding; +} qkey_t; + +extern qboolean key_overstrikeMode; +extern qkey_t keys[MAX_KEYS]; + +// NOTE TTimo the declaration of field_t and Field_Clear is now in qcommon/qcommon.h + +void Field_KeyDownEvent( field_t *edit, int key ); +void Field_CharEvent( field_t *edit, int ch ); +void Field_Draw( field_t *edit, int x, int y, int width, qboolean showCursor ); +void Field_BigDraw( field_t *edit, int x, int y, int width, qboolean showCursor ); + +#define COMMAND_HISTORY 32 +extern field_t historyEditLines[COMMAND_HISTORY]; + +extern field_t g_consoleField; +extern field_t chatField; +extern qboolean anykeydown; +extern qboolean chat_team; +extern qboolean chat_limbo; // NERVE - SMF +extern int chat_playerNum; + +void Key_WriteBindings( fileHandle_t f ); +void Key_SetBinding( int keynum, const char *binding ); +char *Key_GetBinding( int keynum ); +qboolean Key_IsDown( int keynum ); +qboolean Key_GetOverstrikeMode( void ); +void Key_SetOverstrikeMode( qboolean state ); +void Key_ClearStates( void ); +int Key_GetKey( const char *binding ); diff --git a/Projects/Android/jni/rtcw/src/client/snd_adpcm.c b/Projects/Android/jni/rtcw/src/client/snd_adpcm.c new file mode 100644 index 0000000..26ebd2b --- /dev/null +++ b/Projects/Android/jni/rtcw/src/client/snd_adpcm.c @@ -0,0 +1,142 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +#include "snd_local.h" + + +void S_AdpcmEncode( short indata[], char outdata[], int len, struct adpcm_state *state ) { + // LordHavoc: removed 4-clause BSD code for Intel ADPCM codec +} + + +void S_AdpcmDecode( const char indata[], short *outdata, int len, struct adpcm_state *state ) { + // LordHavoc: removed 4-clause BSD code for Intel ADPCM codec +} + + +/* +==================== +S_AdpcmMemoryNeeded + +Returns the amount of memory (in bytes) needed to store the samples in out internal adpcm format +==================== +*/ +int S_AdpcmMemoryNeeded( const wavinfo_t *info ) { + float scale; + int scaledSampleCount; + int sampleMemory; + int blockCount; + int headerMemory; + + // determine scale to convert from input sampling rate to desired sampling rate + scale = (float)info->rate / dma.speed; + + // calc number of samples at playback sampling rate + scaledSampleCount = info->samples / scale; + + // calc memory need to store those samples using ADPCM at 4 bits per sample + sampleMemory = scaledSampleCount / 2; + + // calc number of sample blocks needed of PAINTBUFFER_SIZE + blockCount = scaledSampleCount / PAINTBUFFER_SIZE; + if ( scaledSampleCount % PAINTBUFFER_SIZE ) { + blockCount++; + } + + // calc memory needed to store the block headers + headerMemory = blockCount * sizeof( adpcm_state_t ); + + return sampleMemory + headerMemory; +} + + +/* +==================== +S_AdpcmGetSamples +==================== +*/ +void S_AdpcmGetSamples( sndBuffer *chunk, short *to ) { + adpcm_state_t state; + byte *out; + + // get the starting state from the block header + state.index = chunk->adpcm.index; + state.sample = chunk->adpcm.sample; + + out = (byte *)chunk->sndChunk; + // get samples + S_AdpcmDecode( (const char*)out, to, SND_CHUNK_SIZE_BYTE * 2, &state ); //DAJ added (const char*) +} + + +/* +==================== +S_AdpcmEncodeSound +==================== +*/ +void S_AdpcmEncodeSound( sfx_t *sfx, short *samples ) { + adpcm_state_t state; + int inOffset; + int count; + int n; + sndBuffer *newchunk, *chunk; + byte *out; + + inOffset = 0; + count = sfx->soundLength; + state.index = 0; + state.sample = samples[0]; + + chunk = NULL; + while ( count ) { + n = count; + if ( n > SND_CHUNK_SIZE_BYTE * 2 ) { + n = SND_CHUNK_SIZE_BYTE * 2; + } + + newchunk = SND_malloc(); + if ( sfx->soundData == NULL ) { + sfx->soundData = newchunk; + } else { + chunk->next = newchunk; + } + chunk = newchunk; + + // output the header + chunk->adpcm.index = state.index; + chunk->adpcm.sample = state.sample; + + out = (byte *)chunk->sndChunk; + + // encode the samples + S_AdpcmEncode( samples + inOffset, (char*)out, n, &state ); //DAJ added (char*) + + inOffset += n; + count -= n; + } +} \ No newline at end of file diff --git a/Projects/Android/jni/rtcw/src/client/snd_dma.c b/Projects/Android/jni/rtcw/src/client/snd_dma.c new file mode 100644 index 0000000..e29e390 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/client/snd_dma.c @@ -0,0 +1,2575 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +/***************************************************************************** + * name: snd_dma.c + * + * desc: main control for any streaming sound output device + * + * $Archive: /Wolf5/src/client/snd_dma.c $ + * + *****************************************************************************/ + +#include "snd_local.h" +#include "client.h" + + +void S_Play_f( void ); +void S_SoundList_f( void ); +void S_Music_f( void ); +void S_QueueMusic_f( void ); +void S_StreamingSound_f( void ); +void S_ClearSounds( qboolean clearStreaming, qboolean clearMusic ); //----(SA) modified + +void S_Update_Mix(); +void S_StopAllSounds( void ); +void S_UpdateStreamingSounds( void ); + +snd_t snd; // globals for sound + +// Ridah, streaming sounds +// !! NOTE: the first streaming sound is always the music +streamingSound_t streamingSounds[MAX_STREAMING_SOUNDS]; +int numStreamingSounds = 0; + + +void *crit; + + +// ======================================================================= +// Internal sound data & structures +// ======================================================================= + +// only begin attenuating sound volumes when outside the FULLVOLUME range +#define SOUND_FULLVOLUME 80 + +#define SOUND_ATTENUATE 0.0008f +#define SOUND_RANGE_DEFAULT 1250 + +channel_t s_channels[MAX_CHANNELS]; +channel_t loop_channels[MAX_CHANNELS]; +int numLoopChannels; + +dma_t dma; + +static int listener_number; +static vec3_t listener_origin; +static vec3_t listener_axis[3]; + +int s_soundtime; // sample PAIRS +int s_paintedtime; // sample PAIRS + +// MAX_SFX may be larger than MAX_SOUNDS because +// of custom player sounds +#define MAX_SFX 4096 +sfx_t s_knownSfx[MAX_SFX]; + + +cvar_t *s_volume; +cvar_t *s_testsound; +cvar_t *s_khz; +cvar_t *s_show; +cvar_t *s_mixahead; +cvar_t *s_mixPreStep; +cvar_t *s_musicVolume; +cvar_t *s_currentMusic; //----(SA) added +cvar_t *s_separation; +cvar_t *s_doppler; +cvar_t *s_mute; // (SA) for DM so he can 'toggle' sound on/off without disturbing volume levels +cvar_t *s_defaultsound; // (SA) added to silence the default beep sound if desired +cvar_t *cl_cacheGathering; // Ridah +cvar_t *s_wavonly; +cvar_t *s_debugMusic; //----(SA) added + + +// Rafael +cvar_t *s_nocompressed; + +// for streaming sounds +int s_rawend[MAX_STREAMING_SOUNDS]; +int s_rawpainted[MAX_STREAMING_SOUNDS]; +portable_samplepair_t s_rawsamples[MAX_STREAMING_SOUNDS][MAX_RAW_SAMPLES]; +// RF, store the volumes, since now they get adjusted at time of painting, so we can extract talking data first +portable_samplepair_t s_rawVolume[MAX_STREAMING_SOUNDS]; + + +/* +================ +S_SoundInfo_f +================ +*/ +void S_SoundInfo_f( void ) { + Com_Printf( "----- Sound Info -----\n" ); + if ( !snd.s_soundStarted ) { + Com_Printf( "sound system not started\n" ); + } else { + if ( snd.s_soundMute ) { + Com_Printf( "sound system is muted\n" ); + } + + Com_Printf( "%5d stereo\n", dma.channels - 1 ); + Com_Printf( "%5d samples\n", dma.samples ); + Com_Printf( "%5d samplebits\n", dma.samplebits ); + Com_Printf( "%5d submission_chunk\n", dma.submission_chunk ); + Com_Printf( "%5d speed\n", dma.speed ); + Com_Printf( "0x%x dma buffer\n", dma.buffer ); + if ( streamingSounds[0].file ) { + Com_Printf( "Background file: %s\n", streamingSounds[0].loop ); + } else { + Com_Printf( "No background file.\n" ); + } + + } + Com_Printf( "----------------------\n" ); +} + +void S_ChannelSetup(); + +/* +================ +S_Init +================ +*/ +void S_Init( void ) { + cvar_t *cv; + qboolean r; + + Com_Printf( "\n------- sound initialization -------\n" ); + + s_mute = Cvar_Get( "s_mute", "0", CVAR_TEMP ); //----(SA) added + s_volume = Cvar_Get( "s_volume", "0.8", CVAR_ARCHIVE ); + s_musicVolume = Cvar_Get( "s_musicvolume", "0.25", CVAR_ARCHIVE ); + s_currentMusic = Cvar_Get( "s_currentMusic", "", CVAR_ROM ); + s_separation = Cvar_Get( "s_separation", "0.5", CVAR_ARCHIVE ); + s_doppler = Cvar_Get( "s_doppler", "1", CVAR_ARCHIVE ); + s_khz = Cvar_Get( "s_khz", "22", CVAR_ARCHIVE ); + s_mixahead = Cvar_Get( "s_mixahead", "0.5", CVAR_ARCHIVE ); //DAJ was 0.2 + s_debugMusic = Cvar_Get( "s_debugMusic", "0", CVAR_TEMP ); + + s_mixPreStep = Cvar_Get( "s_mixPreStep", "0.05", CVAR_ARCHIVE ); + s_show = Cvar_Get( "s_show", "0", CVAR_CHEAT ); + s_testsound = Cvar_Get( "s_testsound", "0", CVAR_CHEAT ); + s_defaultsound = Cvar_Get( "s_defaultsound", "0", CVAR_ARCHIVE ); + s_wavonly = Cvar_Get( "s_wavonly", "0", CVAR_ARCHIVE | CVAR_LATCH ); + // Ridah + cl_cacheGathering = Cvar_Get( "cl_cacheGathering", "0", 0 ); + + // Rafael + s_nocompressed = Cvar_Get( "s_nocompressed", "0", CVAR_INIT ); + + cv = Cvar_Get( "s_initsound", "1", 0 ); + if ( !cv->integer ) { + Com_Printf( "not initializing.\n" ); + Com_Printf( "------------------------------------\n" ); + return; + } + + crit = Sys_InitializeCriticalSection(); + + Cmd_AddCommand( "play", S_Play_f ); + Cmd_AddCommand( "music", S_Music_f ); + Cmd_AddCommand( "queuemusic", S_QueueMusic_f ); + Cmd_AddCommand( "streamingsound", S_StreamingSound_f ); + Cmd_AddCommand( "s_list", S_SoundList_f ); + Cmd_AddCommand( "s_info", S_SoundInfo_f ); + Cmd_AddCommand( "s_stop", S_StopAllSounds ); + + r = SNDDMA_Init(); + Com_Printf( "------------------------------------\n" ); + + if ( r ) { + Com_Memset( &snd, 0, sizeof( snd ) ); +// Com_Memset(snd.sfxHash, 0, sizeof(sfx_t *)*LOOP_HASH); + + snd.s_soundStarted = 1; + snd.s_soundMute = 1; +// snd.s_numSfx = 0; +// snd.volTarget = 1.0f; // full volume + snd.volTarget = 0.0f; // full volume + + s_soundtime = 0; + s_paintedtime = 0; + + S_StopAllSounds(); + + S_SoundInfo_f(); + S_ChannelSetup(); + } + +} + +/* +================ +S_ChannelFree +================ +*/ +void S_ChannelFree( channel_t *v ) { + v->thesfx = NULL; + v->threadReady = qfalse; +#ifdef _DEBUG + if ( v > &s_channels[MAX_CHANNELS] || v < &s_channels[0] ) { + Com_DPrintf( "s_channel OUT OF BOUNDS\n" ); + return; + } +#endif + *(channel_t **)snd.endflist = v; + snd.endflist = v; + *(channel_t **)v = NULL; +} + +/* +================ +S_ChannelMalloc +================ +*/ +channel_t* S_ChannelMalloc() { + channel_t *v; + if ( snd.freelist == NULL ) { + return NULL; + } + // RF, be careful not to lose our freelist + if ( *(channel_t **)snd.freelist == NULL ) { + return NULL; + } +#ifdef _DEBUG + if ( *(channel_t **)snd.freelist > &s_channels[MAX_CHANNELS] || *(channel_t **)snd.freelist < &s_channels[0] ) { //DAJ extra check + Com_DPrintf( "s_channel OUT OF BOUNDS\n" ); + return NULL; + } +#endif + v = snd.freelist; + snd.freelist = *(channel_t **)snd.freelist; + v->allocTime = Sys_Milliseconds(); + return v; +} + +/* +================ +S_ChannelSetup +================ +*/ +void S_ChannelSetup() { + channel_t *p, *q; + + // clear all the sounds so they don't + Com_Memset( s_channels, 0, sizeof( s_channels ) ); + + p = s_channels;; + q = p + MAX_CHANNELS; + while ( --q > p ) { + *(channel_t **)q = q - 1; + } + + snd.endflist = q; + *(channel_t **)q = NULL; + snd.freelist = p + MAX_CHANNELS - 1; + Com_DPrintf( "Channel memory manager started\n" ); +} + +/* +================ +S_Shutdown +================ +*/ +void S_Shutdown( void ) { + if ( !snd.s_soundStarted ) { + return; + } + + Sys_EnterCriticalSection( crit ); + + SNDDMA_Shutdown(); + + snd.s_soundStarted = 0; + snd.s_soundMute = 1; + + Cmd_RemoveCommand( "play" ); + Cmd_RemoveCommand( "music" ); + Cmd_RemoveCommand( "stopsound" ); + Cmd_RemoveCommand( "soundlist" ); + Cmd_RemoveCommand( "soundinfo" ); +} + +/* +================ +S_HashSFXName + +return a hash value for the sfx name +================ +*/ +static long S_HashSFXName( const char *name ) { + int i; + long hash; + char letter; + + hash = 0; + i = 0; + while ( name[i] != '\0' ) { + letter = tolower( name[i] ); + if ( letter == '.' ) { + break; // don't include extension + } + if ( letter == '\\' ) { + letter = '/'; // damn path names + } + hash += (long)( letter ) * ( i + 119 ); + i++; + } + hash &= ( LOOP_HASH - 1 ); + return hash; +} + +/* +================== +S_FindName + +Will allocate a new sfx if it isn't found +================== +*/ +static sfx_t *S_FindName( const char *name ) { + int i; + int hash; + + sfx_t *sfx; + + if ( !name ) { + //Com_Error (ERR_FATAL, "S_FindName: NULL\n"); + name = "*default*"; + } + if ( !name[0] ) { + //Com_Error (ERR_FATAL, "S_FindName: empty name\n"); + name = "*default*"; + } + + if ( strlen( name ) >= MAX_QPATH ) { + Com_Error( ERR_FATAL, "Sound name too long: %s", name ); + } + + // Ridah, caching + if ( cl_cacheGathering->integer ) { + Cbuf_ExecuteText( EXEC_NOW, va( "cache_usedfile sound %s\n", name ) ); + } + + hash = S_HashSFXName( name ); + + sfx = snd.sfxHash[hash]; + // see if already loaded + while ( sfx ) { + if ( !Q_stricmp( sfx->soundName, name ) ) { + return sfx; + } + sfx = sfx->next; + } + + // find a free sfx + for ( i = 0 ; i < snd.s_numSfx ; i++ ) { + if ( !s_knownSfx[i].soundName[0] ) { + break; + } + } + + if ( i == snd.s_numSfx ) { + if ( snd.s_numSfx == MAX_SFX ) { + Com_Error( ERR_FATAL, "S_FindName: out of sfx_t" ); + } + snd.s_numSfx++; + } + + sfx = &s_knownSfx[i]; + Com_Memset( sfx, 0, sizeof( *sfx ) ); + strcpy( sfx->soundName, name ); + + sfx->next = snd.sfxHash[hash]; + snd.sfxHash[hash] = sfx; + + return sfx; +} + +/* +================= +S_DefaultSound +================= +*/ +void S_DefaultSound( sfx_t *sfx ) { + + int i; + + if ( s_defaultsound->integer ) { + sfx->soundLength = 512; + } else { + sfx->soundLength = 8; + } + + sfx->soundData = SND_malloc(); + sfx->soundData->next = NULL; + + if ( s_defaultsound->integer ) { + for ( i = 0 ; i < sfx->soundLength ; i++ ) { + sfx->soundData->sndChunk[i] = i; + } + } else { + for ( i = 0 ; i < sfx->soundLength ; i++ ) { + sfx->soundData->sndChunk[i] = 0; + } + } +} + +/* +=================== +S_DisableSounds + +Disables sounds until the next S_BeginRegistration. +This is called when the hunk is cleared and the sounds +are no longer valid. +=================== +*/ +void S_DisableSounds( void ) { + S_StopAllSounds(); + snd.s_soundMute = 1; +} + +/* +===================== +S_BeginRegistration + +===================== +*/ +void S_BeginRegistration( void ) { + sfx_t *sfx; + + snd.s_soundMute = 0; // we can play again + + if ( snd.s_numSfx == 0 ) { + SND_setup(); + + snd.s_numSfx = 0; + Com_Memset( s_knownSfx, 0, sizeof( s_knownSfx ) ); + Com_Memset( snd.sfxHash, 0, sizeof( sfx_t * ) * LOOP_HASH ); + + sfx = S_FindName( "***DEFAULT***" ); + S_DefaultSound( sfx ); + } +} + +/* +================== +S_RegisterSound + +Creates a default buzz sound if the file can't be loaded +================== +*/ +sfxHandle_t S_RegisterSound( const char *name, qboolean compressed ) { + sfx_t *sfx; + + compressed = qfalse; + if ( !snd.s_soundStarted ) { + return 0; + } + + if ( strlen( name ) >= MAX_QPATH ) { + Com_Printf( "Sound name exceeds MAX_QPATH\n" ); + return 0; + } + + sfx = S_FindName( name ); + if ( sfx->soundData ) { + if ( sfx->defaultSound ) { + if ( com_developer->integer ) { + Com_Printf( S_COLOR_YELLOW "WARNING: could not find %s - using default\n", sfx->soundName ); + } + return 0; + } + return sfx - s_knownSfx; + } + + sfx->inMemory = qfalse; + sfx->soundCompressed = compressed; + +// if (!compressed) { + S_memoryLoad( sfx ); +// } + + if ( sfx->defaultSound ) { + if ( com_developer->integer ) { + Com_Printf( S_COLOR_YELLOW "WARNING: could not find %s - using default\n", sfx->soundName ); + } + return 0; + } + + return sfx - s_knownSfx; +} + +/* +================= +S_memoryLoad +================= +*/ +void S_memoryLoad( sfx_t *sfx ) { + // load the sound file + if ( !S_LoadSound( sfx ) ) { +// Com_Printf( S_COLOR_YELLOW "WARNING: couldn't load sound: %s\n", sfx->soundName ); + sfx->defaultSound = qtrue; + } + sfx->inMemory = qtrue; +} + +//============================================================================= + +/* +================= +S_SpatializeOrigin + +Used for spatializing s_channels +================= +*/ +void S_SpatializeOrigin( vec3_t origin, int master_vol, int *left_vol, int *right_vol, float range ) { + vec_t dot; + vec_t dist; + vec_t lscale, rscale, scale; + vec3_t source_vec; + vec3_t vec; + +// const float dist_mult = SOUND_ATTENUATE; + float dist_mult, dist_fullvol; + + dist_fullvol = range * 0.064f; // default range of 1250 gives 80 + dist_mult = dist_fullvol * 0.00001f; // default range of 1250 gives .0008 +// dist_mult = range*0.00000064f; // default range of 1250 gives .0008 + + // calculate stereo seperation and distance attenuation + VectorSubtract( origin, listener_origin, source_vec ); + + dist = VectorNormalize( source_vec ); +// dist -= SOUND_FULLVOLUME; + dist -= dist_fullvol; + if ( dist < 0 ) { + dist = 0; // close enough to be at full volume + + } + if ( dist ) { + dist = dist / range; // FIXME: lose the divide again + } +// dist *= dist_mult; // different attenuation levels + + VectorRotate( source_vec, listener_axis, vec ); + + dot = -vec[1]; + + if ( dma.channels == 1 ) { // no attenuation = no spatialization + rscale = 1.0; + lscale = 1.0; + } else + { + rscale = 0.5 * ( 1.0 + dot ); + lscale = 0.5 * ( 1.0 - dot ); + //rscale = s_separation->value + ( 1.0 - s_separation->value ) * dot; + //lscale = s_separation->value - ( 1.0 - s_separation->value ) * dot; + if ( rscale < 0 ) { + rscale = 0; + } + if ( lscale < 0 ) { + lscale = 0; + } + } + + // add in distance effect + scale = ( 1.0 - dist ) * rscale; + *right_vol = ( master_vol * scale ); + if ( *right_vol < 0 ) { + *right_vol = 0; + } + + scale = ( 1.0 - dist ) * lscale; + *left_vol = ( master_vol * scale ); + if ( *left_vol < 0 ) { + *left_vol = 0; + } +} + +/* +==================== +S_StartSound + +Validates the parms and queues the sound up +if pos is NULL, the sound will be dynamically sourced from the entity +Entchannel 0 will never override a playing sound + + flags: (currently apply only to non-looping sounds) + SND_NORMAL 0 - (default) allow sound to be cut off only by the same sound on this channel + SND_OKTOCUT 0x001 - allow sound to be cut off by any following sounds on this channel + SND_REQUESTCUT 0x002 - allow sound to be cut off by following sounds on this channel only for sounds who request cutoff + SND_CUTOFF 0x004 - cut off sounds on this channel that are marked 'SND_REQUESTCUT' + SND_CUTOFF_ALL 0x008 - cut off all sounds on this channel +==================== +*/ +void S_ThreadStartSoundEx( vec3_t origin, int entityNum, int entchannel, sfxHandle_t sfxHandle, int flags ); + +void S_StartSoundEx( vec3_t origin, int entityNum, int entchannel, sfxHandle_t sfxHandle, int flags ) { + if ( !snd.s_soundStarted || snd.s_soundMute || ( cls.state != CA_ACTIVE && cls.state != CA_DISCONNECTED ) ) { + return; + } + + // RF, we have lots of NULL sounds using up valuable channels, so just ignore them + if ( !sfxHandle && entchannel != CHAN_WEAPON ) { // let null weapon sounds try to play. they kill any weapon sounds playing when a guy dies + return; + } + + // RF, make the call now, or else we could override following streaming sounds in the same frame, due to the delay + S_ThreadStartSoundEx( origin, entityNum, entchannel, sfxHandle, flags ); +/* + if (snd.tart < MAX_PUSHSTACK) { + sfx_t *sfx; + if (origin) { + VectorCopy( origin, snd.pushPop[snd.tart].origin ); + snd.pushPop[snd.tart].fixedOrigin = qtrue; + } else { + snd.pushPop[snd.tart].fixedOrigin = qfalse; + } + snd.pushPop[snd.tart].entityNum = entityNum; + snd.pushPop[snd.tart].entityChannel = entchannel; + snd.pushPop[snd.tart].sfx = sfxHandle; + snd.pushPop[snd.tart].flags = flags; + sfx = &s_knownSfx[ sfxHandle ]; + + if (sfx->inMemory == qfalse) { + S_memoryLoad(sfx); + } + + snd.tart++; + } +*/ +} + +void S_ThreadStartSoundEx( vec3_t origin, int entityNum, int entchannel, sfxHandle_t sfxHandle, int flags ) { + channel_t *ch; + sfx_t *sfx; + int i, oldest, chosen; + + chosen = -1; + if ( !snd.s_soundStarted || snd.s_soundMute ) { + return; + } + + if ( !origin && ( entityNum < 0 || entityNum > MAX_GENTITIES ) ) { + Com_Error( ERR_DROP, "S_StartSound: bad entitynum %i", entityNum ); + } + + if ( sfxHandle < 0 || sfxHandle >= snd.s_numSfx ) { + Com_Printf( S_COLOR_YELLOW, "S_StartSound: handle %i out of range\n", sfxHandle ); + return; + } + + sfx = &s_knownSfx[ sfxHandle ]; + + if ( s_show->integer == 1 ) { + Com_Printf( "%i : %s\n", s_paintedtime, sfx->soundName ); + } + +// Com_Printf("playing %s\n", sfx->soundName); + + sfx->lastTimeUsed = Sys_Milliseconds(); + + // check for a streaming sound that this entity is playing in this channel + // kill it if it exists + if ( entityNum >= 0 ) { + for ( i = 1; i < MAX_STREAMING_SOUNDS; i++ ) { // track 0 is music/cinematics + if ( !streamingSounds[i].file ) { + continue; + } + // check to see if this character currently has another sound streaming on the same channel + if ( ( entchannel != CHAN_AUTO ) && ( streamingSounds[i].entnum >= 0 ) && ( streamingSounds[i].channel == entchannel ) && ( streamingSounds[i].entnum == entityNum ) ) { + // found a match, override this channel + streamingSounds[i].kill = 1; + break; + } + } + } + + ch = NULL; + +//----(SA) modified + + // shut off other sounds on this channel if necessary + for ( i = 0 ; i < MAX_CHANNELS ; i++ ) { + if ( s_channels[i].entnum == entityNum && s_channels[i].thesfx && s_channels[i].entchannel == entchannel ) { + + // cutoff all on channel + if ( flags & SND_CUTOFF_ALL ) { + S_ChannelFree( &s_channels[i] ); + continue; + } + + if ( s_channels[i].flags & SND_NOCUT ) { + continue; + } + + // RF, let client voice sounds be overwritten + if ( entityNum < MAX_CLIENTS && s_channels[i].entchannel != CHAN_AUTO && s_channels[i].entchannel != CHAN_WEAPON ) { + S_ChannelFree( &s_channels[i] ); + continue; + } + + // cutoff sounds that expect to be overwritten + if ( s_channels[i].flags & SND_OKTOCUT ) { + S_ChannelFree( &s_channels[i] ); + continue; + } + + // cutoff 'weak' sounds on channel + if ( flags & SND_CUTOFF ) { + if ( s_channels[i].flags & SND_REQUESTCUT ) { + S_ChannelFree( &s_channels[i] ); + continue; + } + } + + } + } + + // re-use channel if applicable + for ( i = 0 ; i < MAX_CHANNELS ; i++ ) { + if ( s_channels[i].entnum == entityNum && s_channels[i].entchannel == entchannel && entchannel != CHAN_AUTO ) { + if ( !( s_channels[i].flags & SND_NOCUT ) && s_channels[i].thesfx == sfx ) { + ch = &s_channels[i]; + break; + } + } + } + + if ( !ch ) { + ch = S_ChannelMalloc(); + } +//----(SA) end + + if ( !ch ) { + ch = s_channels; + + oldest = sfx->lastTimeUsed; + for ( i = 0 ; i < MAX_CHANNELS ; i++, ch++ ) { + if ( ch->entnum == entityNum && ch->thesfx == sfx ) { + chosen = i; + break; + } + if ( ch->entnum != listener_number && ch->entnum == entityNum && ch->allocTime < oldest && ch->entchannel != CHAN_ANNOUNCER ) { + oldest = ch->allocTime; + chosen = i; + } + } + if ( chosen == -1 ) { + ch = s_channels; + for ( i = 0 ; i < MAX_CHANNELS ; i++, ch++ ) { + if ( ch->entnum != listener_number && ch->allocTime < oldest && ch->entchannel != CHAN_ANNOUNCER ) { + oldest = ch->allocTime; + chosen = i; + } + } + if ( chosen == -1 ) { + if ( ch->entnum == listener_number ) { + for ( i = 0 ; i < MAX_CHANNELS ; i++, ch++ ) { + if ( ch->allocTime < oldest ) { + oldest = ch->allocTime; + chosen = i; + } + } + } + if ( chosen == -1 ) { + //Com_Printf("dropping sound\n"); + return; + } + } + } + ch = &s_channels[chosen]; + ch->allocTime = sfx->lastTimeUsed; + } + +#ifdef _DEBUG + if ( ch > &s_channels[MAX_CHANNELS] || ch < &s_channels[0] ) { //DAJ extra check + Com_DPrintf( "s_channel OUT OF BOUNDS\n" ); + return; + } +#endif + if ( origin ) { + VectorCopy( origin, ch->origin ); + ch->fixed_origin = qtrue; + } else { + ch->fixed_origin = qfalse; + } + + ch->flags = flags; //----(SA) added + ch->master_vol = 127; + ch->entnum = entityNum; + ch->thesfx = sfx; + ch->entchannel = entchannel; + ch->leftvol = ch->master_vol; // these will get calced at next spatialize + ch->rightvol = ch->master_vol; // unless the game isn't running + ch->doppler = qfalse; + + if ( ch->fixed_origin ) { + S_SpatializeOrigin( ch->origin, ch->master_vol, &ch->leftvol, &ch->rightvol, SOUND_RANGE_DEFAULT ); + } else { + S_SpatializeOrigin( snd.entityPositions[ ch->entnum ], ch->master_vol, &ch->leftvol, &ch->rightvol, SOUND_RANGE_DEFAULT ); + } + + ch->startSample = START_SAMPLE_IMMEDIATE; + ch->threadReady = qtrue; +} + +/* +============== +S_StartSound +============== +*/ +void S_StartSound( vec3_t origin, int entityNum, int entchannel, sfxHandle_t sfxHandle ) { + S_StartSoundEx( origin, entityNum, entchannel, sfxHandle, 0 ); +} + + + +/* +================== +S_StartLocalSound +================== +*/ +void S_StartLocalSound( sfxHandle_t sfxHandle, int channelNum ) { + if ( !snd.s_soundStarted || snd.s_soundMute ) { + return; + } + + if ( sfxHandle < 0 || sfxHandle >= snd.s_numSfx ) { + Com_Printf( S_COLOR_YELLOW, "S_StartLocalSound: handle %i out of range\n", sfxHandle ); + return; + } + + S_StartSound( NULL, listener_number, channelNum, sfxHandle ); +} + + +/* +================== +S_ClearSoundBuffer + +If we are about to perform file access, clear the buffer +so sound doesn't stutter. +================== +*/ +void S_ClearSoundBuffer( qboolean killStreaming ) { + if ( !snd.s_soundStarted ) { + return; + } + + if ( !snd.s_soundPainted ) { // RF, buffers are clear, no point clearing again + return; + } + + snd.s_soundPainted = qfalse; + +// snd.s_clearSoundBuffer = 4; + snd.s_clearSoundBuffer = 3; + + S_ClearSounds( killStreaming, qtrue ); // do this now since you might not be allowed to in a sec (no multi-threaeded) +} + +/* +================== +S_StopAllSounds +================== +*/ +void S_StopAllSounds( void ) { + int i; + if ( !snd.s_soundStarted ) { + return; + } + + Sys_EnterCriticalSection( crit ); + +//DAJ BUGFIX for(i=0;i= MAX_LOOP_SOUNDS ) { + return; + } + if ( !volume ) { + return; + } + + if ( sfxHandle < 0 || sfxHandle >= snd.s_numSfx ) { + Com_Error( ERR_DROP, "S_AddLoopingSound: handle %i out of range", sfxHandle ); + } + + sfx = &s_knownSfx[ sfxHandle ]; + + if ( sfx->inMemory == qfalse ) { + S_memoryLoad( sfx ); + } + + if ( !sfx->soundLength ) { + Com_Error( ERR_DROP, "%s has length 0", sfx->soundName ); + } + VectorCopy( origin, snd.loopSounds[snd.numLoopSounds].origin ); + VectorCopy( velocity, snd.loopSounds[snd.numLoopSounds].velocity ); + snd.loopSounds[snd.numLoopSounds].sfx = sfx; + if ( range ) { + snd.loopSounds[snd.numLoopSounds].range = range; + } else { + snd.loopSounds[snd.numLoopSounds].range = SOUND_RANGE_DEFAULT; + } + + if ( volume & 1 << UNDERWATER_BIT ) { + snd.loopSounds[snd.numLoopSounds].loudUnderWater = qtrue; + } + + if ( volume > 255 ) { + volume = 255; + } else if ( volume < 0 ) { + volume = 0; + } + + snd.loopSounds[snd.numLoopSounds].vol = (int)( (float)volume * snd.volCurrent ); //----(SA) modified + + snd.numLoopSounds++; +} + +/* +================== +S_AddLoopSounds + +Spatialize all of the looping sounds. +All sounds are on the same cycle, so any duplicates can just +sum up the channel multipliers. +================== +*/ +void S_AddLoopSounds( void ) { + int i, j, time; + int left_total, right_total, left, right; + channel_t *ch; + loopSound_t *loop, *loop2; + static int loopFrame; + +// Sys_EnterCriticalSection(crit); + + numLoopChannels = 0; + + time = Sys_Milliseconds(); + + loopFrame++; + for ( i = 0 ; i < snd.numLoopSounds ; i++ ) { + loop = &snd.loopSounds[i]; + if ( loop->mergeFrame == loopFrame ) { + continue; // already merged into an earlier sound + } + + //if (loop->kill) { + // S_SpatializeOrigin( loop->origin, 127, &left_total, &right_total, loop->range); // 3d + //} else { + S_SpatializeOrigin( loop->origin, 90, &left_total, &right_total, loop->range ); // sphere + //} + + // adjust according to volume + left_total = (int)( (float)loop->vol * (float)left_total / 256.0 ); + right_total = (int)( (float)loop->vol * (float)right_total / 256.0 ); + + loop->sfx->lastTimeUsed = time; + + for ( j = ( i + 1 ); j < numLoopChannels ; j++ ) { + loop2 = &snd.loopSounds[j]; + if ( loop2->sfx != loop->sfx ) { + continue; + } + loop2->mergeFrame = loopFrame; + + //if (loop2->kill) { + // S_SpatializeOrigin( loop2->origin, 127, &left, &right, loop2->range); // 3d + //} else { + S_SpatializeOrigin( loop2->origin, 90, &left, &right, loop2->range ); // sphere + //} + + // adjust according to volume + left = (int)( (float)loop2->vol * (float)left / 256.0 ); + right = (int)( (float)loop2->vol * (float)right / 256.0 ); + + loop2->sfx->lastTimeUsed = time; + left_total += left; + right_total += right; + } + if ( left_total == 0 && right_total == 0 ) { + continue; // not audible + } + + // allocate a channel + ch = &loop_channels[numLoopChannels]; + + if ( left_total > 255 ) { + left_total = 255; + } + if ( right_total > 255 ) { + right_total = 255; + } + + ch->master_vol = 127; + ch->leftvol = left_total; + ch->rightvol = right_total; + ch->thesfx = loop->sfx; + // RF, disabled doppler for looping sounds for now, since we are reverting to the old looping sound code + ch->doppler = qfalse; + //ch->doppler = loop->doppler; + //ch->dopplerScale = loop->dopplerScale; + //ch->oldDopplerScale = loop->oldDopplerScale; + numLoopChannels++; + if ( numLoopChannels == MAX_CHANNELS ) { + i = snd.numLoopSounds + 1; + } + } +// Sys_LeaveCriticalSection(crit); +} + +//============================================================================= + +/* +================= +S_ByteSwapRawSamples + +If raw data has been loaded in little endien binary form, this must be done. +If raw data was calculated, as with ADPCM, this should not be called. +================= +*/ +//DAJ void S_ByteSwapRawSamples( int samples, int width, int s_channels, const byte *data ) { +void S_ByteSwapRawSamples( int samples, int width, int s_channels, short *data ) { + int i; + + if ( width != 2 ) { + return; + } +#ifndef __MACOS__ //DAJ save this test + if ( LittleShort( 256 ) == 256 ) { + return; + } +#endif + //DAJ use a faster loop technique + if ( s_channels == 2 ) { + i = samples << 1; + } else { + i = samples; + } + + do { + *data = LittleShort( *data ); + data++; +//DAJ ((short *)data)[i] = LittleShort( ((short *)data)[i] ); + } while ( --i ); +} + +/* +============ +S_GetRawSamplePointer +============ +*/ +portable_samplepair_t *S_GetRawSamplePointer() { + return s_rawsamples[0]; +} + +/* +============ +S_RawSamples + +Music streaming +============ +*/ +void S_RawSamples( int samples, int rate, int width, int s_channels, const byte *data, float lvol, float rvol, int streamingIndex ) { + int i; + int src, dst; + float scale; + int intVolumeL, intVolumeR; + + if ( !snd.s_soundStarted || ( snd.s_soundMute == 1 ) ) { + return; + } + + // volume taken into account when mixed + s_rawVolume[streamingIndex].left = 256 * lvol; + s_rawVolume[streamingIndex].right = 256 * rvol; + + intVolumeL = 256; + intVolumeR = 256; + + if ( s_rawend[streamingIndex] < s_soundtime ) { + Com_DPrintf( "S_RawSamples: resetting minumum: %i\n",s_soundtime - s_rawend[streamingIndex] ); + s_rawend[streamingIndex] = s_soundtime; + } + + scale = (float)rate / dma.speed; + + if ( s_channels == 2 && width == 2 ) { + if ( scale == 1.0 ) { // optimized case + for ( i = 0; i < samples; i++ ) + { + dst = s_rawend[streamingIndex] & ( MAX_RAW_SAMPLES - 1 ); + s_rawend[streamingIndex]++; + s_rawsamples[streamingIndex][dst].left = ( (short *)data )[i * 2] * intVolumeL; + s_rawsamples[streamingIndex][dst].right = ( (short *)data )[i * 2 + 1] * intVolumeR; + } + } else + { + for ( i = 0; ; i++ ) + { + src = i * scale; + if ( src >= samples ) { + break; + } + dst = s_rawend[streamingIndex] & ( MAX_RAW_SAMPLES - 1 ); + s_rawend[streamingIndex]++; + s_rawsamples[streamingIndex][dst].left = ( (short *)data )[src * 2] * intVolumeL; + s_rawsamples[streamingIndex][dst].right = ( (short *)data )[src * 2 + 1] * intVolumeR; + } + } + } else if ( s_channels == 1 && width == 2 ) { + for ( i = 0; ; i++ ) + { + src = i * scale; + if ( src >= samples ) { + break; + } + dst = s_rawend[streamingIndex] & ( MAX_RAW_SAMPLES - 1 ); + s_rawend[streamingIndex]++; + s_rawsamples[streamingIndex][dst].left = ( (short *)data )[src] * intVolumeL; + s_rawsamples[streamingIndex][dst].right = ( (short *)data )[src] * intVolumeR; + } + } else if ( s_channels == 2 && width == 1 ) { + intVolumeL *= 256; + intVolumeR *= 256; + + for ( i = 0 ; ; i++ ) + { + src = i * scale; + if ( src >= samples ) { + break; + } + dst = s_rawend[streamingIndex] & ( MAX_RAW_SAMPLES - 1 ); + s_rawend[streamingIndex]++; + s_rawsamples[streamingIndex][dst].left = ( (char *)data )[src * 2] * intVolumeL; + s_rawsamples[streamingIndex][dst].right = ( (char *)data )[src * 2 + 1] * intVolumeR; + } + } else if ( s_channels == 1 && width == 1 ) { + intVolumeL *= 256; + intVolumeR *= 256; + + for ( i = 0; ; i++ ) + { + src = i * scale; + if ( src >= samples ) { + break; + } + dst = s_rawend[streamingIndex] & ( MAX_RAW_SAMPLES - 1 ); + s_rawend[streamingIndex]++; + s_rawsamples[streamingIndex][dst].left = ( ( (byte *)data )[src] - 128 ) * intVolumeL; + s_rawsamples[streamingIndex][dst].right = ( ( (byte *)data )[src] - 128 ) * intVolumeR; + } + } + + if ( s_rawend[streamingIndex] > ( s_soundtime + MAX_RAW_SAMPLES ) ) { +// Com_DPrintf( "S_RawSamples: overflowed %i\n", s_rawend[streamingIndex]-(s_soundtime+ MAX_RAW_SAMPLES) ); + } +} + +//============================================================================= + +/* +===================== +S_UpdateEntityPosition + +let the sound system know where an entity currently is +====================== +*/ +void S_UpdateEntityPosition( int entityNum, const vec3_t origin ) { + if ( entityNum < 0 || entityNum > MAX_GENTITIES ) { + Com_Error( ERR_DROP, "S_UpdateEntityPosition: bad entitynum %i", entityNum ); + } + VectorCopy( origin, snd.entityPositions[entityNum] ); +} + + +/* +============ +S_Respatialize + +Change the volumes of all the playing sounds for changes in their positions +============ +*/ +void S_Respatialize( int entityNum, const vec3_t head, vec3_t axis[3], int inwater ) { + + if ( !snd.s_soundStarted || ( snd.s_soundMute == 1 ) ) { + return; + } + + listener_number = entityNum; + VectorCopy( head, listener_origin ); + VectorCopy( axis[0], listener_axis[0] ); + VectorCopy( axis[1], listener_axis[1] ); + VectorCopy( axis[2], listener_axis[2] ); +} + +void S_ThreadRespatialize() { + int i; + channel_t *ch; + vec3_t origin; + // update spatialization for dynamic sounds + ch = s_channels; + for ( i = 0 ; i < MAX_CHANNELS ; i++, ch++ ) { + if ( !ch->thesfx ) { + continue; + } + // anything coming from the view entity will always be full volume + if ( ch->entnum == listener_number ) { + ch->leftvol = ch->master_vol; + ch->rightvol = ch->master_vol; + } else { + if ( ch->fixed_origin ) { + VectorCopy( ch->origin, origin ); + } else { + VectorCopy( snd.entityPositions[ ch->entnum ], origin ); + } + + S_SpatializeOrigin( origin, ch->master_vol, &ch->leftvol, &ch->rightvol, SOUND_RANGE_DEFAULT ); + } + } +} + +/* +======================== +S_ScanChannelStarts + +Returns qtrue if any new sounds were started since the last mix +======================== +*/ +qboolean S_ScanChannelStarts( void ) { + channel_t *ch; + int i; + qboolean newSamples; + + newSamples = qfalse; + ch = s_channels; + + for ( i = 0; i < MAX_CHANNELS; i++, ch++ ) { + if ( !ch->thesfx ) { + continue; + } + // if this channel was just started this frame, + // set the sample count to it begins mixing + // into the very first sample + if ( ch->startSample == START_SAMPLE_IMMEDIATE && ch->threadReady == qtrue ) { + ch->startSample = s_paintedtime; + newSamples = qtrue; + continue; + } + + // if it is completely finished by now, clear it + if ( ch->startSample + ( ch->thesfx->soundLength ) <= s_paintedtime ) { +//----(SA) got from TA sound. correct? +// Com_Memset(ch, 0, sizeof(*ch)); + S_ChannelFree( ch ); + } + } + + return newSamples; +} + +/* +============== +S_CheckForQueuedMusic +============== +*/ +int S_CheckForQueuedMusic( void ) { + streamingSound_t *ss; + char *nextMusicVA; + + if ( !snd.nextMusicTrack[0] ) { // we didn't actually care about the length + return 0; + } + + nextMusicVA = va( "%s", snd.nextMusicTrack ); + + ss = &streamingSounds[0]; + + if ( snd.nextMusicTrackType == QUEUED_PLAY_ONCE_SILENT ) { + // do nothing. current music is dead, don't start another + } else if ( snd.nextMusicTrackType == QUEUED_PLAY_ONCE ) { + S_StartBackgroundTrack( nextMusicVA, ss->name, 0 ); // play once, then go back to looping what's currently playing + } else { // QUEUED_PLAY_LOOPED + S_StartBackgroundTrack( nextMusicVA, nextMusicVA, 0 ); // take over + } + + snd.nextMusicTrackType = 0; // clear out music queue +// snd.nextMusicTrack[0] = 0; // clear out music queue + + return 1; +} + +/* +============ +S_Update + +Called once each time through the main loop +============ +*/ + +void S_Update( void ) { + int i; + int total; + channel_t *ch; + + if ( !snd.s_soundStarted || ( snd.s_soundMute == 1 ) ) { +// Com_DPrintf ("not started or muted\n"); + return; + } + + // + // debugging output + // + if ( s_show->integer == 2 ) { + total = 0; + ch = s_channels; + for ( i = 0; i < MAX_CHANNELS; i++, ch++ ) { + if ( ch->thesfx && ( ch->leftvol || ch->rightvol ) ) { + Com_Printf( "%f %f %s\n", ch->leftvol, ch->rightvol, ch->thesfx->soundName ); // <- this is not thread safe + total++; + } + } + + Com_Printf( "----(%i)---- painted: %i\n", total, s_paintedtime ); + } + // add loopsounds + S_AddLoopSounds(); + S_UpdateThread(); +} + + +/* +============== +S_ClearSounds +============== +*/ +void S_ClearSounds( qboolean clearStreaming, qboolean clearMusic ) { + int clear; + int i; + channel_t *ch; + streamingSound_t *ss; + + Sys_EnterCriticalSection( crit ); + + // stop looping sounds + S_ClearLoopingSounds(); + + // RF, moved this up so streaming sounds dont get updated with the music, below, and leave us with a snippet off streaming sounds after we reload + if ( clearStreaming ) { // we don't want to stop guys with long dialogue from getting cut off by a file read + // RF, clear talking amplitudes + Com_Memset( s_entityTalkAmplitude, 0, sizeof( s_entityTalkAmplitude ) ); + + for ( i = 0, ss = streamingSounds; i < MAX_STREAMING_SOUNDS; i++, ss++ ) { + if ( i > 0 || clearMusic ) { + s_rawend[i] = 0; + ss->kill = 2; // get rid of it next sound update + } + } + + // RF, we should also kill all channels, since we are killing streaming sounds anyway (fixes siren in forest playing after a map_restart/loadgame + ch = s_channels; + for ( i = 0; i < MAX_CHANNELS; i++, ch++ ) { + if ( ch->thesfx ) { + S_ChannelFree( ch ); + } + } + + } + + if ( !clearMusic ) { + S_UpdateStreamingSounds(); //----(SA) added so music will get updated if not cleared + } else { + // music cleanup + snd.nextMusicTrack[0] = 0; + snd.nextMusicTrackType = 0; + } + + if ( clearStreaming && clearMusic ) { + if ( dma.samplebits == 8 ) { + clear = 0x80; + } else { + clear = 0; + } + + SNDDMA_BeginPainting(); + if ( dma.buffer ) { + Com_Memset( dma.buffer, clear, dma.samples * dma.samplebits / 8 ); + } + SNDDMA_Submit(); + + Sys_LeaveCriticalSection( crit ); + } +} + +/* +============== +S_UpdateThread +============== +*/ +void S_UpdateThread( void ) { + + if ( !snd.s_soundStarted || ( snd.s_soundMute == 1 ) ) { +// Com_DPrintf ("not started or muted\n"); + return; + } + +#ifdef TALKANIM + // default to ZERO amplitude, overwrite if sound is playing + memset( s_entityTalkAmplitude, 0, sizeof( s_entityTalkAmplitude ) ); +#endif + + if ( snd.s_clearSoundBuffer ) { + S_ClearSounds( qtrue, (qboolean)( snd.s_clearSoundBuffer >= 4 ) ); //----(SA) modified + snd.s_clearSoundBuffer = 0; + } else { + Sys_EnterCriticalSection( crit ); + + S_ThreadRespatialize(); + // add raw data from streamed samples + S_UpdateStreamingSounds(); + // mix some sound + S_Update_Mix(); + + Sys_LeaveCriticalSection( crit ); + } +} +/* +============ +S_GetSoundtime +============ +*/ +void S_GetSoundtime( void ) { + int samplepos; + static int buffers; + static int oldsamplepos; + int fullsamples; + + fullsamples = dma.samples / dma.channels; + + // it is possible to miscount buffers if it has wrapped twice between + // calls to S_Update. Oh well. + samplepos = SNDDMA_GetDMAPos(); + if ( samplepos < oldsamplepos ) { + buffers++; // buffer wrapped + + if ( s_paintedtime > 0x40000000 ) { // time to chop things off to avoid 32 bit limits + buffers = 0; + s_paintedtime = fullsamples; + S_StopAllSounds(); + } + } + oldsamplepos = samplepos; + + s_soundtime = buffers * fullsamples + samplepos / dma.channels; + +#if 0 +// check to make sure that we haven't overshot + if ( s_paintedtime < s_soundtime ) { + Com_DPrintf( "S_GetSoundtime : overflow\n" ); + s_paintedtime = s_soundtime; + } +#endif + + if ( dma.submission_chunk < 256 ) { + s_paintedtime = s_soundtime + s_mixPreStep->value * dma.speed; + } else { + s_paintedtime = s_soundtime + dma.submission_chunk; + } +} + +/* +============ +S_Update_Mix +============ +*/ +void S_Update_Mix( void ) { + unsigned endtime; + int samps; //, i; + static float lastTime = 0.0f; + float ma, op; + float thisTime, sane; + + if ( !snd.s_soundStarted || ( snd.s_soundMute == 1 ) ) { + return; + } + + // RF, this isn't used anymore, since it was causing timing problems with streaming sounds, since the + // starting of the sound is delayed, it could cause streaming sounds to be cutoff, when the steaming sound was issued after + // this sound +/* + for(i=0;ivalue * dma.speed; + op = s_mixPreStep->value + sane * dma.speed * 0.01; + + if ( op < ma ) { + ma = op; + } + + // mix ahead of current position + endtime = s_soundtime + ma; + + // mix to an even submission block size + endtime = ( endtime + dma.submission_chunk - 1 ) + & ~( dma.submission_chunk - 1 ); + + // never mix more than the complete buffer + samps = dma.samples >> ( dma.channels - 1 ); + if ( endtime - s_soundtime > samps ) { + endtime = s_soundtime + samps; + } + +//----(SA) added + // global volume fading + + // endtime or s_paintedtime or s_soundtime... + if ( s_soundtime < snd.volTime2 ) { // still has fading to do + if ( s_soundtime > snd.volTime1 ) { // has started fading + snd.volFadeFrac = ( (float)( s_soundtime - snd.volTime1 ) / (float)( snd.volTime2 - snd.volTime1 ) ); + snd.volCurrent = ( ( 1.0 - snd.volFadeFrac ) * snd.volStart + snd.volFadeFrac * snd.volTarget ); + +//DAJ Com_DPrintf( "master vol: %f\n", snd.volCurrent ); + + } else { + snd.volCurrent = snd.volStart; + } + } else { + snd.volCurrent = snd.volTarget; + } +//----(SA) end + + + SNDDMA_BeginPainting(); + S_PaintChannels( endtime ); + SNDDMA_Submit(); + + lastTime = thisTime; +} + +/* +=============================================================================== + +console functions + +=============================================================================== +*/ + +void S_Play_f( void ) { + int i; + sfxHandle_t h; + char name[256]; + + i = 1; + while ( i < Cmd_Argc() ) { + if ( !Q_strrchr( Cmd_Argv( i ), '.' ) ) { + Com_sprintf( name, sizeof( name ), "%s.wav", Cmd_Argv( 1 ) ); + } else { + Q_strncpyz( name, Cmd_Argv( i ), sizeof( name ) ); + } + h = S_RegisterSound( name, qfalse ); + if ( h ) { + S_StartLocalSound( h, CHAN_LOCAL_SOUND ); + } + i++; + } +} + +/* +============== +S_QueueMusic_f + console interface really just for testing +============== +*/ +void S_QueueMusic_f( void ) { + int type = -2; // default to setting this as the next continual loop + int c; + + c = Cmd_Argc(); + + if ( c == 3 ) { + type = atoi( Cmd_Argv( 2 ) ); + } + + if ( type != -1 ) { // clamp to valid values (-1, -2) + type = -2; + } + + // NOTE: could actually use this to touch the file now so there's not a hit when the queue'd music is played? + S_StartBackgroundTrack( Cmd_Argv( 1 ), Cmd_Argv( 1 ), type ); +} + +void S_Music_f( void ) { + int c; + + c = Cmd_Argc(); + + if ( c == 2 ) { + S_StartBackgroundTrack( Cmd_Argv( 1 ), Cmd_Argv( 1 ), 0 ); + } else if ( c == 3 ) { + S_StartBackgroundTrack( Cmd_Argv( 1 ), Cmd_Argv( 2 ), 0 ); + Q_strncpyz( streamingSounds[0].loop, Cmd_Argv( 2 ), sizeof( streamingSounds[0].loop ) ); + } else { + Com_Printf( "music [loopfile]\n" ); + return; + } +} + +// Ridah, just for testing the streaming sounds +void S_StreamingSound_f( void ) { + int c; + + c = Cmd_Argc(); + + if ( c == 2 ) { + S_StartStreamingSound( Cmd_Argv( 1 ), 0, -1, 0, 0 ); + } else if ( c == 5 ) { + S_StartStreamingSound( Cmd_Argv( 1 ), 0, atoi( Cmd_Argv( 2 ) ), atoi( Cmd_Argv( 3 ) ), atoi( Cmd_Argv( 4 ) ) ); + } else { + Com_Printf( "streamingsound [entnum channel attenuation]\n" ); + return; + } + +} + +void S_SoundList_f( void ) { + int i; + sfx_t *sfx; + int size, total; + char type[4][16]; + char mem[2][16]; + + strcpy( type[0], "16bit" ); + strcpy( type[1], "adpcm" ); + strcpy( type[2], "daub4" ); + strcpy( type[3], "mulaw" ); + strcpy( mem[0], "paged out" ); + strcpy( mem[1], "resident " ); + total = 0; + for ( sfx = s_knownSfx, i = 0 ; i < snd.s_numSfx ; i++, sfx++ ) { + size = sfx->soundLength; + total += size; + Com_Printf( "%6i[%s] : %s[%s]\n", size, type[sfx->soundCompressionMethod], sfx->soundName, mem[sfx->inMemory] ); + } + Com_Printf( "Total resident: %i\n", total ); + S_DisplayFreeMemory(); +} + + +/* +=============================================================================== + +STREAMING SOUND + +=============================================================================== +*/ + +int FGetLittleLong( const fileHandle_t f ) { + int v; + + FS_Read( &v, sizeof( v ), f ); + + return LittleLong( v ); +} + +int FGetLittleShort( const fileHandle_t f ) { + short v; + + FS_Read( &v, sizeof( v ), f ); + + return LittleShort( v ); +} + +// returns the length of the data in the chunk, or 0 if not found +int S_FindWavChunk( const fileHandle_t f, const char *chunk ) { + char name[5]; + int len; + int r; + + name[4] = 0; + len = 0; + r = FS_Read( name, 4, f ); + if ( r != 4 ) { + return 0; + } + len = FGetLittleLong( f ); + if ( len < 0 || len > 0xfffffff ) { + len = 0; + return 0; + } + len = ( len + 1 ) & ~1; // pad to word boundary +// s_nextWavChunk += len + 8; + + if ( strcmp( name, chunk ) ) { + return 0; + } + + return len; +} + + + + +/* +====================== +S_StartBackgroundTrack +====================== +*/ +void S_StartBackgroundTrack( const char *intro, const char *loop, int fadeupTime ) { + int len; + char dump[16]; +// char name[MAX_QPATH]; + char loopMusic[MAX_QPATH]; + streamingSound_t *ss; + fileHandle_t fh; + + // music is always track 0 + ss = &streamingSounds[0]; + +//----(SA) added + if ( fadeupTime < 0 ) { // queue, don't play until music fades to 0 or is stopped + // -1 - queue to play once then return to music + // -2 - queue to set as new looping music + + if ( intro && strlen( intro ) ) { + strcpy( snd.nextMusicTrack, intro ); + snd.nextMusicTrackType = fadeupTime; + if ( fadeupTime == -2 ) { + Cvar_Set( "s_currentMusic", intro ); //----(SA) so the savegame will have the right music + + } + if ( s_debugMusic->integer ) { + if ( fadeupTime == -1 ) { + Com_Printf( "MUSIC: StartBgTrack: queueing '%s' for play once\n", intro ); + } else if ( fadeupTime == -2 ) { + Com_Printf( "MUSIC: StartBgTrack: queueing '%s' as new loop\n", intro ); + } + } + + } else { + snd.nextMusicTrack[0] = 0; // clear out the next track so things go on as they are + snd.nextMusicTrackType = 0; // be quiet at the next opportunity + + // clear out looping sound in current music so that it'll stop when it's done + if ( ss && ss->loop ) { + ss->loop[0] = 0; // clear loop + } + + if ( s_debugMusic->integer ) { + Com_Printf( "S_StartBgTrack(): queue cleared\n" ); + } + } + + return; // don't actually start any queued sounds + } + + // clear out nextMusic +// snd.nextMusicTrack[0] = 0; +//----(SA) end + + if ( !snd.s_soundStarted || !crit ) { + return; + } + + Sys_EnterCriticalSection( crit ); + + if ( !intro ) { + intro = ""; + } + if ( !loop || !loop[0] ) { + Q_strncpyz( loopMusic, intro, sizeof( loopMusic ) ); + } else { + Q_strncpyz( loopMusic, loop, sizeof( loopMusic ) ); + } + + Cvar_Set( "s_currentMusic", "" ); //----(SA) so the savegame will have the right music + + if ( !Q_stricmp( loop, "onetimeonly" ) ) { // don't change the loop if you're playing a single hit + Q_strncpyz( loopMusic, ss->loop, sizeof( loopMusic ) ); + } + + Q_strncpyz( ss->loop, loopMusic, sizeof( ss->loop ) - 4 ); + + Q_strncpyz( ss->name, intro, sizeof( ss->name ) - 4 ); + COM_DefaultExtension( ss->name, sizeof( ss->name ), ".wav" ); + + // close the current sound if present, but DON'T reset s_rawend + if ( ss->file ) { + Sys_EndStreamedFile( ss->file ); + FS_FCloseFile( ss->file ); + ss->file = 0; + } + + if ( !intro[0] ) { + Com_DPrintf( "Fail to start: %s\n", ss->name ); // (SA) TEMP + Sys_LeaveCriticalSection( crit ); + return; + } + + ss->channel = 0; + ss->entnum = -1; + ss->attenuation = 0; + + fh = 0; + // + // open up a wav file and get all the info + // + FS_FOpenFileRead( ss->name, &fh, qtrue ); + if ( !fh ) { + Com_Printf( "Couldn't open streaming sound file %s\n", ss->name ); + Sys_LeaveCriticalSection( crit ); + return; + } + + // skip the riff wav header + + FS_Read( dump, 12, fh ); + + if ( !S_FindWavChunk( fh, "fmt " ) ) { + Com_Printf( "No fmt chunk in %s\n", ss->name ); + FS_FCloseFile( fh ); + Sys_LeaveCriticalSection( crit ); + return; + } + + // save name for soundinfo + ss->info.format = FGetLittleShort( fh ); + ss->info.channels = FGetLittleShort( fh ); + ss->info.rate = FGetLittleLong( fh ); + FGetLittleLong( fh ); + FGetLittleShort( fh ); + ss->info.width = FGetLittleShort( fh ) / 8; + + if ( ss->info.format != WAV_FORMAT_PCM ) { + FS_FCloseFile( fh ); + Com_Printf( "Not a microsoft PCM format wav: %s\n", ss->name ); + Sys_LeaveCriticalSection( crit ); + return; + } + + if ( ss->info.channels != 2 || ss->info.rate != 22050 ) { + Com_Printf( "WARNING: music file %s is not 22k stereo\n", ss->name ); + } + + if ( ( len = S_FindWavChunk( fh, "data" ) ) == 0 ) { + FS_FCloseFile( fh ); + Com_Printf( "No data chunk in %s\n", ss->name ); + Sys_LeaveCriticalSection( crit ); + return; + } + + if ( s_debugMusic->integer ) { + Com_Printf( "MUSIC: StartBgTrack:\n playing %s\n looping %s %d\n", intro, loopMusic, fadeupTime ); + } + + Cvar_Set( "s_currentMusic", loopMusic ); //----(SA) so the savegame will have the right music + + ss->info.samples = len / ( ss->info.width * ss->info.channels ); + + ss->samples = ss->info.samples; + + ss->fadeStartVol = 0; + ss->fadeStart = 0; + ss->fadeEnd = 0; + ss->fadeTargetVol = 0; + + if ( fadeupTime ) { + ss->fadeStart = s_soundtime; + ss->fadeEnd = s_soundtime + ( ( (float)( ss->info.rate ) / 1000.0f ) * fadeupTime ); +// ss->fadeStart = s_paintedtime; +// ss->fadeEnd = s_paintedtime + (((float)(ss->info.rate)/1000.0f ) * fadeupTime); + ss->fadeTargetVol = 1.0; + } + + // + // start the background streaming + // + Sys_BeginStreamedFile( fh, 0x10000 ); + + ss->looped = 0; //----(SA) added + + ss->file = fh; + ss->kill = 0; + numStreamingSounds++; + + Com_DPrintf( "S_StartBackgroundTrack - Success\n" ); + Sys_LeaveCriticalSection( crit ); +} + + +/* +============== +S_FadeAllSounds + +============== +*/ +void S_FadeAllSounds( float targetVol, int time ) { + + snd.volStart = snd.volCurrent; + snd.volTarget = targetVol; + + snd.volTime1 = s_soundtime; + snd.volTime2 = s_soundtime + ( ( (float)( dma.speed ) / 1000.0f ) * time ); + + // instant + if ( !time ) { + snd.volTarget = snd.volStart = snd.volCurrent = targetVol; // set it + snd.volTime1 = snd.volTime2 = 0; // no fading + } +} + + +//----(SA) added +/* +============== +S_FadeStreamingSound +============== +*/ +void S_FadeStreamingSound( float targetVol, int time, int ssNum ) { + streamingSound_t *ss; + + if ( ssNum >= numStreamingSounds ) { // invalid sound + return; + } + + ss = &streamingSounds[ssNum]; + + if ( !ss ) { + return; + } + + if ( ss->kill ) { + return; + } + + ss->fadeStartVol = 1.0f; + + if ( ssNum == 0 ) { + if ( s_debugMusic->integer ) { + Com_Printf( "MUSIC: Fade: %0.2f %d\n", targetVol, time ); + } + } + + // get current fraction if already fading/faded + if ( ss->fadeStart ) { + if ( ss->fadeEnd <= s_soundtime ) { +// if(ss->fadeEnd <= s_paintedtime) + ss->fadeStartVol = ss->fadeTargetVol; + } else { + ss->fadeStartVol = ( (float)( s_soundtime - ss->fadeStart ) / (float)( ss->fadeEnd - ss->fadeStart ) ); + } +// ss->fadeStartVol = ( (float)(s_paintedtime - ss->fadeStart)/(float)(ss->fadeEnd - ss->fadeStart) ); + } + + ss->fadeStart = s_soundtime; + ss->fadeEnd = s_soundtime + ( ( (float)( ss->info.rate ) / 1000.0f ) * time ); +// ss->fadeStart = s_paintedtime; +// ss->fadeEnd = s_paintedtime + (((float)(ss->info.rate)/1000.0f ) * time); + ss->fadeTargetVol = targetVol; +} + + +/* +============== +S_GetStreamingFade +============== +*/ +float S_GetStreamingFade( streamingSound_t *ss ) { + float oldfrac, newfrac; + +// if(ss->kill) +// return 0; + + if ( !ss->fadeStart ) { + return 1.0f; // full volume + + } + if ( ss->fadeEnd <= s_soundtime ) { // it's hit it's target +// if(ss->fadeEnd <= s_paintedtime) { // it's hit it's target + if ( ss->fadeTargetVol <= 0 ) { // faded out. die next update + ss->kill = 1; + } + return ss->fadeTargetVol; + } + + newfrac = (float)( s_soundtime - ss->fadeStart ) / (float)( ss->fadeEnd - ss->fadeStart ); +// newfrac = (float)(s_paintedtime - ss->fadeStart)/(float)(ss->fadeEnd - ss->fadeStart); + oldfrac = 1.0f - newfrac; + + return ( oldfrac * ss->fadeStartVol ) + ( newfrac * ss->fadeTargetVol ); +} + +//----(SA) end + +/* +====================== +S_StartStreamingSound + + FIXME: record the starting cg.time of the sound, so we can determine the + position by looking at the current cg.time, this way pausing or loading a + savegame won't screw up the timing of important sounds +====================== +*/ +void S_StartStreamingSound( const char *intro, const char *loop, int entnum, int channel, int attenuation ) { + int len; + char dump[16]; +// char name[MAX_QPATH]; + int i; + streamingSound_t *ss; + fileHandle_t fh; + + if ( !crit || !snd.s_soundStarted || snd.s_soundMute || cls.state != CA_ACTIVE ) { + return; + } + + Sys_EnterCriticalSection( crit ); + if ( !intro || !intro[0] ) { + if ( loop && loop[0] ) { + intro = loop; + } else { + intro = ""; + } + } + Com_DPrintf( "S_StartStreamingSound( %s, %s, %i, %i, %i )\n", intro, loop, entnum, channel, attenuation ); + + // look for a free track, but first check for overriding a currently playing sound for this entity + ss = NULL; + if ( entnum >= 0 ) { + for ( i = 1; i < MAX_STREAMING_SOUNDS; i++ ) { // track 0 is music/cinematics + if ( !streamingSounds[i].file ) { + continue; + } + // check to see if this character currently has another sound streaming on the same channel + if ( ( channel != CHAN_AUTO ) && ( streamingSounds[i].entnum >= 0 ) && ( streamingSounds[i].channel == channel ) && ( streamingSounds[i].entnum == entnum ) ) { + // found a match, override this channel + streamingSounds[i].kill = 1; + ss = &streamingSounds[i]; // use this track to start the new stream + break; + } + } + } + if ( !ss ) { + // no need to override a current stream, so look for a free track + for ( i = 1; i < MAX_STREAMING_SOUNDS; i++ ) { // track 0 is music/cinematics + if ( !streamingSounds[i].file ) { + ss = &streamingSounds[i]; + break; + } + } + } + if ( !ss ) { + if ( !s_mute->integer ) { // don't do the print if you're muted + Com_Printf( "S_StartStreamingSound: No free streaming tracks\n" ); + } + Sys_LeaveCriticalSection( crit ); + return; + } + + if ( ss->loop && loop ) { + Q_strncpyz( ss->loop, loop, sizeof( ss->loop ) - 4 ); + } else { + ss->loop[0] = 0; + } + + Q_strncpyz( ss->name, intro, sizeof( ss->name ) - 4 ); + COM_DefaultExtension( ss->name, sizeof( ss->name ), ".wav" ); + + // close the current sound if present, but DON'T reset s_rawend + if ( ss->file ) { + Sys_EndStreamedFile( ss->file ); + FS_FCloseFile( ss->file ); + ss->file = 0; + } + + if ( !intro[0] ) { + Sys_LeaveCriticalSection( crit ); + return; + } + + fh = 0; + // + // open up a wav file and get all the info + // + FS_FOpenFileRead( ss->name, &fh, qtrue ); + if ( !fh ) { + Com_Printf( "Couldn't open streaming sound file %s\n", ss->name ); + Sys_LeaveCriticalSection( crit ); + return; + } + + // skip the riff wav header + + FS_Read( dump, 12, fh ); + + if ( !S_FindWavChunk( fh, "fmt " ) ) { + Com_Printf( "No fmt chunk in %s\n", ss->name ); + FS_FCloseFile( fh ); + Sys_LeaveCriticalSection( crit ); + return; + } + + // save name for soundinfo + ss->info.format = FGetLittleShort( fh ); + ss->info.channels = FGetLittleShort( fh ); + ss->info.rate = FGetLittleLong( fh ); + FGetLittleLong( fh ); + FGetLittleShort( fh ); + ss->info.width = FGetLittleShort( fh ) / 8; + + if ( ss->info.format != WAV_FORMAT_PCM ) { + FS_FCloseFile( fh ); + Com_Printf( "Not a microsoft PCM format wav: %s\n", ss->name ); + Sys_LeaveCriticalSection( crit ); + return; + } + + //if ( ss->info.channels != 2 || ss->info.rate != 22050 ) { + // Com_Printf("WARNING: music file %s is not 22k stereo\n", ss->name ); + //} + + if ( ( len = S_FindWavChunk( fh, "data" ) ) == 0 ) { + FS_FCloseFile( fh ); + Com_Printf( "No data chunk in %s\n", ss->name ); + Sys_LeaveCriticalSection( crit ); + return; + } + + ss->info.samples = len / ( ss->info.width * ss->info.channels ); + + ss->samples = ss->info.samples; + ss->channel = channel; + ss->attenuation = attenuation; + ss->entnum = entnum; + ss->kill = 0; + + ss->fadeStartVol = 0; + ss->fadeStart = 0; + ss->fadeEnd = 0; + ss->fadeTargetVol = 0; + + // + // start the background streaming + // + Sys_BeginStreamedFile( fh, 0x10000 ); + + ss->file = fh; + numStreamingSounds++; + Sys_LeaveCriticalSection( crit ); +} + +/* +====================== +S_StopStreamingSound +====================== +*/ +void S_StopStreamingSound( int index ) { + if ( !streamingSounds[index].file ) { + return; + } + Sys_EnterCriticalSection( crit ); + streamingSounds[index].kill = 1; + Sys_LeaveCriticalSection( crit ); +} + +//----(SA) added +/* +============== +S_StopEntStreamingSound +============== +*/ +void S_StopEntStreamingSound( int entNum ) { + int i; + + if ( entNum < 0 ) { + return; + } + + for ( i = 1; i < MAX_STREAMING_SOUNDS; i++ ) { // track 0 is music/cinematics + if ( !streamingSounds[i].file ) { + continue; + } + + if ( streamingSounds[i].entnum != entNum ) { + continue; + } + + S_StopStreamingSound( i ); + s_rawend[i] = 0; // stop it /now/ + } +} +//----(SA) end + +/* +====================== +S_StopBackgroundTrack +====================== +*/ +void S_StopBackgroundTrack( void ) { + S_StopStreamingSound( 0 ); +} + +/* +====================== +S_UpdateStreamingSounds +====================== +*/ +void S_UpdateStreamingSounds( void ) { + int bufferSamples; + int fileSamples; + byte raw[30000]; // just enough to fit in a mac stack frame + int fileBytes; + int r, i; + streamingSound_t *ss; + int *re, *rp; +// qboolean looped; + float lvol, rvol; + int soundMixAheadTime; + float streamingVol = 1.0f; + + if ( !snd.s_soundStarted || !crit ) { + return; + } + + // seems like the mute would be better down lower so no timing gets messed up + +// if ( s_mute->value ) { //----(SA) sound is muted, skip everything +// return; +// } + + soundMixAheadTime = s_soundtime; // + (int)(0.35 * dma.speed); // allow for talking animations + + snd.s_soundPainted = qtrue; + + for ( i = 0, ss = streamingSounds, re = s_rawend, rp = s_rawpainted; i < MAX_STREAMING_SOUNDS; i++, ss++, re++, rp++ ) { + if ( ss->kill && ss->file ) { + fileHandle_t file; + file = ss->file; + ss->file = 0; + Sys_EndStreamedFile( file ); + FS_FCloseFile( file ); + numStreamingSounds--; + + if ( i == 0 || ss->kill == 2 ) { // kill whole channel /now/ +// memset( &s_rawsamples[i], 0, MAX_RAW_SAMPLES*sizeof(portable_samplepair_t) ); + *re = 0; // reset rawend + + } + ss->kill = 0; + continue; + } + + *rp = qfalse; + + // don't bother playing anything if musicvolume is 0 + if ( i == 0 && s_musicVolume->value <= 0 ) { + continue; + } + if ( i > 0 && s_volume->value <= 0 ) { + continue; + } + + if ( !ss->file ) { + if ( i == 0 ) { // music + // quiet now, so start up queued music if it exists + S_CheckForQueuedMusic(); + } + continue; // skip until next frame + } + + // see how many samples should be copied into the raw buffer + if ( *re < soundMixAheadTime ) { // RF, read a bit ahead of time to allow for talking animations + *re = soundMixAheadTime; + } + +// looped = qfalse; + + while ( *re < soundMixAheadTime + MAX_RAW_SAMPLES ) { + bufferSamples = MAX_RAW_SAMPLES - ( *re - soundMixAheadTime ); + + // decide how much data needs to be read from the file + fileSamples = bufferSamples * ss->info.rate / dma.speed; + + // if there are no samples due to be read this frame, abort painting + // but keep the streaming going, since it might just need to wait until + // the next frame before it needs to paint some more + if ( !fileSamples ) { + break; + } + + // don't try and read past the end of the file + if ( fileSamples > ss->samples ) { + fileSamples = ss->samples; + } + + // our max buffer size + fileBytes = fileSamples * ( ss->info.width * ss->info.channels ); + if ( fileBytes > sizeof( raw ) ) { + fileBytes = sizeof( raw ); + fileSamples = fileBytes / ( ss->info.width * ss->info.channels ); + } + + r = Sys_StreamedRead( raw, 1, fileBytes, ss->file ); + if ( r != fileBytes ) { + Com_DPrintf( "StreamedRead failure on stream sound\n" ); + ss->kill = 1; + break; + } + + // byte swap if needed + S_ByteSwapRawSamples( fileSamples, ss->info.width, ss->info.channels, (short*)raw ); + + // calculate the volume + streamingVol = S_GetStreamingFade( ss ); + + streamingVol *= snd.volCurrent; // get current global volume level + + if ( s_mute->value ) { //----(SA) sound is muted. process to maintain timing, but play at 0 volume + streamingVol = 0; + } + + if ( i == 0 ) { // music + lvol = rvol = s_musicVolume->value * streamingVol; + } else { // attenuate if required + if ( ss->entnum >= 0 && ss->attenuation ) { + int r, l; + S_SpatializeOrigin( snd.entityPositions[ ss->entnum ], s_volume->value * 255.0f, &l, &r, SOUND_RANGE_DEFAULT ); + if ( ( lvol = ( (float)l / 255.0 ) ) > 1.0 ) { + lvol = 1.0; + } + if ( ( rvol = ( (float)r / 255.0 ) ) > 1.0 ) { + rvol = 1.0; + } + lvol *= streamingVol; + rvol *= streamingVol; + } else { + lvol = rvol = s_volume->value * streamingVol; + } + } + + // add to raw buffer + S_RawSamples( fileSamples, ss->info.rate, + ss->info.width, ss->info.channels, raw, lvol, rvol, i ); + + *rp = qtrue; + + ss->samples -= fileSamples; + + if ( !ss->samples ) { // at the end of the sound + + // Queued music will take over as the new loop + // start up queued music if it exists + if ( i == 0 && snd.nextMusicTrackType ) { // queued music is queued + if ( ss->file ) { + fileHandle_t file; + file = ss->file; + ss->file = 0; + Sys_EndStreamedFile( file ); + FS_FCloseFile( file ); + numStreamingSounds--; +// memset( &s_rawsamples[i], 0, MAX_RAW_SAMPLES*sizeof(portable_samplepair_t) ); // really clear it + s_rawend[i] = 0; // reset rawend + } +/* + nextMusicVA = va("%s", snd.nextMusicTrack); + if(snd.nextMusicTrackType == QUEUED_PLAY_ONCE) { + S_StartBackgroundTrack( nextMusicVA, ss->name, 0); // play once, then go back to looping what's currently playing + } else { // QUEUED_PLAY_LOOPED + S_StartBackgroundTrack( nextMusicVA, nextMusicVA, 0); // take over + } + snd.nextMusicTrack[0] = 0; // clear out music queue +*/ + break; // this is now the music ss->file, no need to re-start next time through + } else { + // loop + if ( ss->loop && ss->loop[0] ) { + if ( ss->looped ) { + char dump[16]; + Sys_StreamSeek( ss->file, 0, FS_SEEK_SET ); // just go back to the beginning + FS_Read( dump, 12, ss->file ); + + if ( !S_FindWavChunk( ss->file, "fmt " ) ) { + ss->kill = 1; + break; + } + + // save name for soundinfo + ss->info.format = FGetLittleShort( ss->file ); + ss->info.channels = FGetLittleShort( ss->file ); + ss->info.rate = FGetLittleLong( ss->file ); + FGetLittleLong( ss->file ); + FGetLittleShort( ss->file ); + ss->info.width = FGetLittleShort( ss->file ) / 8; + ss->samples = ss->info.samples; + if ( ( S_FindWavChunk( ss->file, "data" ) ) == 0 ) { + ss->kill = 1; + } + if ( s_debugMusic->integer ) { + Com_Printf( "MUSIC: looping current track\n" ); + } + break; + } else { // start up the sound + S_StartBackgroundTrack( ss->loop, ss->loop, 0 ); + ss->looped = qtrue; // this is now the music ss->file, no need to re-start next time through + break; + } + + + // no loop, just stop + } else { + ss->kill = 1; + if ( i == 0 ) { + Cvar_Set( "s_currentMusic", "" ); //----(SA) so the savegame know's it's supposed to be quiet + + if ( s_debugMusic->integer ) { + Com_Printf( "MUSIC: Ending current track-> no loop\n" ); + } + } + + break; + } + } + } + } + } +} + + +/* +====================== +S_FreeOldestSound +====================== +*/ +void S_FreeOldestSound( void ) { + int i, oldest, used; + sfx_t *sfx; + sndBuffer *buffer, *nbuffer; + + oldest = Sys_Milliseconds(); + used = 0; + + for ( i = 1 ; i < snd.s_numSfx ; i++ ) { + sfx = &s_knownSfx[i]; + if ( sfx->inMemory && sfx->lastTimeUsed < oldest ) { + used = i; + oldest = sfx->lastTimeUsed; + } + } + + sfx = &s_knownSfx[used]; + + Com_DPrintf( "S_FreeOldestSound: freeing sound %s\n", sfx->soundName ); + + buffer = sfx->soundData; + while ( buffer != NULL ) { + nbuffer = buffer->next; + SND_free( buffer ); + buffer = nbuffer; + } + sfx->inMemory = qfalse; + sfx->soundData = NULL; +} + diff --git a/Projects/Android/jni/rtcw/src/client/snd_local.h b/Projects/Android/jni/rtcw/src/client/snd_local.h new file mode 100644 index 0000000..3ff7ea7 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/client/snd_local.h @@ -0,0 +1,315 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +// snd_local.h -- private sound definations + + +#include "../game/q_shared.h" +#include "../qcommon/qcommon.h" +#include "snd_public.h" + +#define PAINTBUFFER_SIZE 4096 // this is in samples + +#define SND_CHUNK_SIZE 1024 // samples +#define SND_CHUNK_SIZE_FLOAT ( SND_CHUNK_SIZE / 2 ) // floats +#define SND_CHUNK_SIZE_BYTE ( SND_CHUNK_SIZE * 2 ) // floats + +#define TALKANIM + +typedef struct { + int left; // the final values will be clamped to +/- 0x00ffff00 and shifted down + int right; +} portable_samplepair_t; + +typedef struct adpcm_state { + short sample; /* Previous output value */ + char index; /* Index into stepsize table */ +#if defined( __MACOS__ ) + char pad; /* //DAJ added pad for alignment */ +#endif +} adpcm_state_t; + +typedef struct sndBuffer_s { + short sndChunk[SND_CHUNK_SIZE]; + struct sndBuffer_s *next; + int size; + adpcm_state_t adpcm; +} sndBuffer; + +typedef struct sfx_s { + sndBuffer *soundData; + qboolean defaultSound; // couldn't be loaded, so use buzz + qboolean inMemory; // not in Memory + qboolean soundCompressed; // not in Memory + int soundCompressionMethod; + int soundLength; + char soundName[MAX_QPATH]; + int lastTimeUsed; + struct sfx_s *next; +} sfx_t; + +typedef struct { + int channels; + int samples; // mono samples in buffer + int submission_chunk; // don't mix less than this # + int samplebits; + int speed; + int samplepos; + byte *buffer; +} dma_t; + +#define START_SAMPLE_IMMEDIATE 0x7fffffff + +typedef struct loopSound_s { + vec3_t origin; + vec3_t velocity; + float range; //----(SA) added + sfx_t *sfx; + int mergeFrame; + int vol; + qboolean loudUnderWater; // (SA) set if this sound should be played at full vol even when under water (under water loop sound for ex.) +} loopSound_t; + +typedef struct +{ + int *ptr; //DAJ BUGFIX for freelist/endlist pointer + int allocTime; + int startSample; // START_SAMPLE_IMMEDIATE = set immediately on next mix + int entnum; // to allow overriding a specific sound + int entchannel; // to allow overriding a specific sound + int leftvol; // 0-255 volume after spatialization + int rightvol; // 0-255 volume after spatialization + int master_vol; // 0-255 volume before spatialization + float dopplerScale; + float oldDopplerScale; + vec3_t origin; // only use if fixed_origin is set + qboolean fixed_origin; // use origin instead of fetching entnum's origin + sfx_t *thesfx; // sfx structure + qboolean doppler; + int flags; //----(SA) added + qboolean threadReady; +} channel_t; + + +#define WAV_FORMAT_PCM 1 + + +typedef struct { + int format; + int rate; + int width; + int channels; + int samples; + int dataofs; // chunk starts this many bytes from file start +} wavinfo_t; + + +/* +==================================================================== + + SYSTEM SPECIFIC FUNCTIONS + +==================================================================== +*/ + +// initializes cycling through a DMA buffer and returns information on it +qboolean SNDDMA_Init( void ); + +// gets the current DMA position +int SNDDMA_GetDMAPos( void ); + +// shutdown the DMA xfer. +void SNDDMA_Shutdown( void ); + +void SNDDMA_BeginPainting( void ); + +void SNDDMA_Submit( void ); + +//==================================================================== + +#if defined( __MACOS__ ) + #define MAX_CHANNELS 64 +#else + #define MAX_CHANNELS 96 +#endif + +extern channel_t s_channels[MAX_CHANNELS]; +extern channel_t loop_channels[MAX_CHANNELS]; +extern int numLoopChannels; + +extern int s_paintedtime; +extern vec3_t listener_forward; +extern vec3_t listener_right; +extern vec3_t listener_up; +extern dma_t dma; + +#ifdef TALKANIM +extern unsigned char s_entityTalkAmplitude[MAX_CLIENTS]; +#endif + +//----(SA) some flags for queued music tracks +#define QUEUED_PLAY_ONCE -1 +#define QUEUED_PLAY_LOOPED -2 +#define QUEUED_PLAY_ONCE_SILENT -3 // when done it goes quiet +//----(SA) end + +// Ridah, streaming sounds +typedef struct { + fileHandle_t file; + wavinfo_t info; + int samples; + char name[MAX_QPATH]; //----(SA) added + char loop[MAX_QPATH]; + int looped; //----(SA) added + int entnum; + int channel; + int attenuation; + int kill; //----(SA) changed + + int fadeStart; //----(SA) added + int fadeEnd; //----(SA) added + float fadeStartVol; //----(SA) added + float fadeTargetVol; //----(SA) added +} streamingSound_t; + + + + +typedef struct { + vec3_t origin; + qboolean fixedOrigin; + int entityNum; + int entityChannel; + sfxHandle_t sfx; + int flags; +} s_pushStack; + +#define MAX_PUSHSTACK 64 +#define LOOP_HASH 128 +#define MAX_LOOP_SOUNDS 128 + +// removed many statics into a common sound struct +typedef struct { + sfx_t *sfxHash[LOOP_HASH]; + int numLoopSounds; + loopSound_t loopSounds[MAX_LOOP_SOUNDS]; + + float volTarget; + float volStart; + int volTime1; + int volTime2; + float volFadeFrac; + float volCurrent; + + channel_t *freelist; + channel_t *endflist; + + int s_numSfx; + + s_pushStack pushPop[MAX_PUSHSTACK]; + int tart; + + qboolean s_soundPainted; + int s_clearSoundBuffer; + + int s_soundStarted; +// qboolean s_soundMute; + int s_soundMute; // 0 - not muted, 1 - muted, 2 - no new sounds, but play out remaining sounds (so they can die if necessary) + + vec3_t entityPositions[MAX_GENTITIES]; + + char nextMusicTrack[MAX_QPATH]; // extracted from CS_MUSIC_QUEUE //----(SA) added + int nextMusicTrackType; +} snd_t; + +extern snd_t snd; // globals for sound + + + +#define MAX_STREAMING_SOUNDS 12 // need to keep it low, or the rawsamples will get too big +#define MAX_RAW_SAMPLES 16384 + +extern streamingSound_t streamingSounds[MAX_STREAMING_SOUNDS]; +extern int s_rawend[MAX_STREAMING_SOUNDS]; +extern portable_samplepair_t s_rawsamples[MAX_STREAMING_SOUNDS][MAX_RAW_SAMPLES]; +extern portable_samplepair_t s_rawVolume[MAX_STREAMING_SOUNDS]; + + +extern cvar_t *s_volume; +extern cvar_t *s_nosound; +extern cvar_t *s_khz; +extern cvar_t *s_show; +extern cvar_t *s_mixahead; +extern cvar_t *s_mute; + +extern cvar_t *s_testsound; +extern cvar_t *s_separation; +extern cvar_t *s_currentMusic; //----(SA) added +extern cvar_t *s_debugMusic; //----(SA) added + +qboolean S_LoadSound( sfx_t *sfx ); + +void SND_free( sndBuffer *v ); +sndBuffer* SND_malloc(); +void SND_setup(); + +void S_PaintChannels( int endtime ); + +void S_memoryLoad( sfx_t *sfx ); +portable_samplepair_t *S_GetRawSamplePointer(); + +// spatializes a channel +void S_Spatialize( channel_t *ch ); + +// adpcm functions +int S_AdpcmMemoryNeeded( const wavinfo_t *info ); +void S_AdpcmEncodeSound( sfx_t *sfx, short *samples ); +void S_AdpcmGetSamples( sndBuffer *chunk, short *to ); + +// wavelet function + +#define SENTINEL_MULAW_ZERO_RUN 127 +#define SENTINEL_MULAW_FOUR_BIT_RUN 126 + +void S_FreeOldestSound(); + +#define NXStream byte + +void encodeWavelet( sfx_t *sfx, short *packets ); +void decodeWavelet( sndBuffer *stream, short *packets ); + +void encodeMuLaw( sfx_t *sfx, short *packets ); +extern short mulawToShort[256]; + +extern short *sfxScratchBuffer; +extern const sfx_t *sfxScratchPointer; +extern int sfxScratchIndex; + +extern unsigned char s_entityTalkAmplitude[MAX_CLIENTS]; + +extern float S_GetStreamingFade( streamingSound_t *ss ); //----(SA) added diff --git a/Projects/Android/jni/rtcw/src/client/snd_mem.c b/Projects/Android/jni/rtcw/src/client/snd_mem.c new file mode 100644 index 0000000..b0dd0b3 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/client/snd_mem.c @@ -0,0 +1,446 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +/***************************************************************************** + * name: snd_mem.c + * + * desc: sound caching + * + * $Archive: /Wolf5/src/client/snd_mem.c $ + * + *****************************************************************************/ + +#include "snd_local.h" + +#define DEF_COMSOUNDMEGS "24" // (SA) upped for GD + +/* +=============================================================================== + +SOUND MEMORY MANAGENT + +=============================================================================== +*/ + +static sndBuffer *buffer = NULL; +static sndBuffer *freelist = NULL; +static int inUse = 0; +static int totalInUse = 0; + +short *sfxScratchBuffer = NULL; +const sfx_t *sfxScratchPointer = NULL; +int sfxScratchIndex = 0; + +extern cvar_t *s_nocompressed; + +/* +================ +SND_free +================ +*/ +void SND_free( sndBuffer *v ) { + *(sndBuffer **)v = freelist; + freelist = (sndBuffer*)v; + inUse += sizeof( sndBuffer ); +} + +/* +================ +SND_malloc +================ +*/ +sndBuffer* SND_malloc() { + sndBuffer *v; + + while ( freelist == NULL ) { + S_FreeOldestSound(); + } + + inUse -= sizeof( sndBuffer ); + totalInUse += sizeof( sndBuffer ); + + v = freelist; + freelist = *(sndBuffer **)freelist; + v->next = NULL; + return v; +} + +/* +================ +SND_setup +================ +*/ +void SND_setup() { + sndBuffer *p, *q; + cvar_t *cv; + int scs; + + cv = Cvar_Get( "com_soundMegs", DEF_COMSOUNDMEGS, CVAR_LATCH | CVAR_ARCHIVE ); + + scs = cv->integer * 512; + + buffer = malloc( scs * sizeof( sndBuffer ) ); + // allocate the stack based hunk allocator + sfxScratchBuffer = malloc( SND_CHUNK_SIZE * sizeof( short ) * 4 ); //Hunk_Alloc(SND_CHUNK_SIZE * sizeof(short) * 4); + sfxScratchPointer = NULL; + + inUse = scs * sizeof( sndBuffer ); + p = buffer;; + q = p + scs; + while ( --q > p ) { + *(sndBuffer **)q = q - 1; + } + *(sndBuffer **)q = NULL; + freelist = p + scs - 1; + + Com_Printf( "Sound memory manager started\n" ); +} + +/* +=============================================================================== + +WAV loading + +=============================================================================== +*/ + +static byte *data_p; +static byte *iff_end; +static byte *last_chunk; +static byte *iff_data; +static int iff_chunk_len; + +/* +================ +GetLittleShort +================ +*/ +static short GetLittleShort( void ) { + short val = 0; + val = *data_p; + val = val + ( *( data_p + 1 ) << 8 ); + data_p += 2; + return val; +} + +/* +================ +GetLittleLong +================ +*/ +static int GetLittleLong( void ) { + int val = 0; + val = *data_p; + val = val + ( *( data_p + 1 ) << 8 ); + val = val + ( *( data_p + 2 ) << 16 ); + val = val + ( *( data_p + 3 ) << 24 ); + data_p += 4; + return val; +} + +/* +================ +FindNextChunk +================ +*/ +static void FindNextChunk( char *name ) { + while ( 1 ) + { + data_p = last_chunk; + + if ( data_p >= iff_end ) { // didn't find the chunk + data_p = NULL; + return; + } + + data_p += 4; + iff_chunk_len = GetLittleLong(); + if ( iff_chunk_len < 0 ) { + data_p = NULL; + return; + } + data_p -= 8; + last_chunk = data_p + 8 + ( ( iff_chunk_len + 1 ) & ~1 ); + if ( !strncmp( (char *)data_p, name, 4 ) ) { + return; + } + } +} + +/* +================ +FindChunk +================ +*/ +static void FindChunk( char *name ) { + last_chunk = iff_data; + FindNextChunk( name ); +} + +/* +============ +GetWavinfo +============ +*/ +static wavinfo_t GetWavinfo( char *name, byte *wav, int wavlength ) { + wavinfo_t info; + + Com_Memset( &info, 0, sizeof( info ) ); + + if ( !wav ) { + return info; + } + + iff_data = wav; + iff_end = wav + wavlength; + +// find "RIFF" chunk + FindChunk( "RIFF" ); + if ( !( data_p && !strncmp( (char *)data_p + 8, "WAVE", 4 ) ) ) { + Com_Printf( "Missing RIFF/WAVE chunks\n" ); + return info; + } + +// get "fmt " chunk + iff_data = data_p + 12; +// DumpChunks (); + + FindChunk( "fmt " ); + if ( !data_p ) { + Com_Printf( "Missing fmt chunk\n" ); + return info; + } + data_p += 8; + info.format = GetLittleShort(); + info.channels = GetLittleShort(); + info.rate = GetLittleLong(); + data_p += 4 + 2; + info.width = GetLittleShort() / 8; + + if ( info.format != 1 ) { + Com_Printf( "Microsoft PCM format only\n" ); + return info; + } + + +// find data chunk + FindChunk( "data" ); + if ( !data_p ) { + Com_Printf( "Missing data chunk\n" ); + return info; + } + + data_p += 4; + info.samples = GetLittleLong() / info.width; + info.dataofs = data_p - wav; + + return info; +} + +/* +================ +ResampleSfx + +resample / decimate to the current source rate +================ +*/ +static void ResampleSfx( sfx_t *sfx, int inrate, int inwidth, byte *data, qboolean compressed ) { + int outcount; + int srcsample; + float stepscale; + int i; + int sample, samplefrac, fracstep; + int part; + sndBuffer *chunk; + + stepscale = (float)inrate / dma.speed; // this is usually 0.5, 1, or 2 + + outcount = sfx->soundLength / stepscale; + sfx->soundLength = outcount; + + samplefrac = 0; + fracstep = stepscale * 256; + chunk = sfx->soundData; + + for ( i = 0 ; i < outcount ; i++ ) + { + srcsample = samplefrac >> 8; + samplefrac += fracstep; + if ( inwidth == 2 ) { + sample = LittleShort( ( (short *)data )[srcsample] ); + } else { + sample = (int)( ( unsigned char )( data[srcsample] ) - 128 ) << 8; + } + part = ( i & ( SND_CHUNK_SIZE - 1 ) ); + if ( part == 0 ) { + sndBuffer *newchunk; + newchunk = SND_malloc(); + if ( chunk == NULL ) { + sfx->soundData = newchunk; + } else { + chunk->next = newchunk; + } + chunk = newchunk; + } + + chunk->sndChunk[part] = sample; + } +} + +/* +================ +ResampleSfx + +resample / decimate to the current source rate +================ +*/ +static int ResampleSfxRaw( short *sfx, int inrate, int inwidth, int samples, byte *data ) { + int outcount; + int srcsample; + float stepscale; + int i; + int sample, samplefrac, fracstep; + + stepscale = (float)inrate / dma.speed; // this is usually 0.5, 1, or 2 + + outcount = samples / stepscale; + + samplefrac = 0; + fracstep = stepscale * 256; + + for ( i = 0 ; i < outcount ; i++ ) + { + srcsample = samplefrac >> 8; + samplefrac += fracstep; + if ( inwidth == 2 ) { + sample = LittleShort( ( (short *)data )[srcsample] ); + } else { + sample = (int)( ( unsigned char )( data[srcsample] ) - 128 ) << 8; + } + sfx[i] = sample; + } + return outcount; +} + + +//============================================================================= + +/* +============== +S_LoadSound + +The filename may be different than sfx->name in the case +of a forced fallback of a player specific sound +============== +*/ +qboolean S_LoadSound( sfx_t *sfx ) { + byte *data; + short *samples; + wavinfo_t info; + int size; + + // player specific sounds are never directly loaded + if ( sfx->soundName[0] == '*' ) { + return qfalse; + } + + // load it in + size = FS_ReadFile( sfx->soundName, (void **)&data ); + if ( !data ) { + return qfalse; + } + + info = GetWavinfo( sfx->soundName, data, size ); + if ( info.channels != 1 ) { + Com_Printf( "%s is a stereo wav file\n", sfx->soundName ); + FS_FreeFile( data ); + return qfalse; + } + + if ( info.width == 1 ) { + Com_DPrintf( S_COLOR_YELLOW "WARNING: %s is a 8 bit wav file\n", sfx->soundName ); + } + + if ( info.rate != 22050 ) { + Com_DPrintf( S_COLOR_YELLOW "WARNING: %s is not a 22kHz wav file\n", sfx->soundName ); + } + + samples = Hunk_AllocateTempMemory( info.samples * sizeof( short ) * 2 ); + + sfx->lastTimeUsed = Sys_Milliseconds() + 1; + + // each of these compression schemes works just fine + // but the 16bit quality is much nicer and with a local + // install assured we can rely upon the sound memory + // manager to do the right thing for us and page + // sound in as needed + + + if ( s_nocompressed->value ) { + sfx->soundCompressionMethod = 0; + sfx->soundLength = info.samples; + sfx->soundData = NULL; + ResampleSfx( sfx, info.rate, info.width, data + info.dataofs, qfalse ); + } else if ( sfx->soundCompressed == qtrue ) { + sfx->soundCompressionMethod = 1; + sfx->soundData = NULL; + sfx->soundLength = ResampleSfxRaw( samples, info.rate, info.width, info.samples, ( data + info.dataofs ) ); + S_AdpcmEncodeSound( sfx, samples ); +#ifdef COMPRESSION + } else if ( info.samples > ( SND_CHUNK_SIZE * 16 ) && info.width > 1 ) { + sfx->soundCompressionMethod = 3; + sfx->soundData = NULL; + sfx->soundLength = ResampleSfxRaw( samples, info.rate, info.width, info.samples, ( data + info.dataofs ) ); + encodeMuLaw( sfx, samples ); + } else if ( info.samples > ( SND_CHUNK_SIZE * 6400 ) && info.width > 1 ) { + sfx->soundCompressionMethod = 2; + sfx->soundData = NULL; + sfx->soundLength = ResampleSfxRaw( samples, info.rate, info.width, info.samples, ( data + info.dataofs ) ); + encodeWavelet( sfx, samples ); +#endif + } else { + sfx->soundCompressionMethod = 0; + sfx->soundLength = info.samples; + sfx->soundData = NULL; + ResampleSfx( sfx, info.rate, info.width, data + info.dataofs, qfalse ); + } + Hunk_FreeTempMemory( samples ); + FS_FreeFile( data ); + + return qtrue; +} + +/* +================ +S_DisplayFreeMemory +================ +*/ +void S_DisplayFreeMemory() { + Com_Printf( "%d bytes free sound buffer memory, %d total used\n", inUse, totalInUse ); +} diff --git a/Projects/Android/jni/rtcw/src/client/snd_mix.c b/Projects/Android/jni/rtcw/src/client/snd_mix.c new file mode 100644 index 0000000..3aab0fa --- /dev/null +++ b/Projects/Android/jni/rtcw/src/client/snd_mix.c @@ -0,0 +1,952 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +/***************************************************************************** + * name: snd_mix.c + * + * desc: portable code to mix sounds for snd_dma.c + * + * + *****************************************************************************/ + +#include "snd_local.h" + +portable_samplepair_t paintbuffer[PAINTBUFFER_SIZE]; +static int snd_vol; + +// TTimo not static, required by unix/snd_mixa.s +int *snd_p; +int snd_linear_count; +short *snd_out; + +#if !( defined __linux__ && defined __i386__ ) +#if !id386 + +/* +=================== +S_WriteLinearBlastStereo16 +=================== +*/ +void S_WriteLinearBlastStereo16( void ) { + int i; + int val; + + for ( i = 0 ; i < snd_linear_count ; i += 2 ) + { + val = snd_p[i] >> 8; + if ( val > 0x7fff ) { + snd_out[i] = 0x7fff; + } else if ( val < (short)0x8000 ) { + snd_out[i] = (short)0x8000; + } else { + snd_out[i] = val; + } + + val = snd_p[i + 1] >> 8; + if ( val > 0x7fff ) { + snd_out[i + 1] = 0x7fff; + } else if ( val < (short)0x8000 ) { + snd_out[i + 1] = (short)0x8000; + } else { + snd_out[i + 1] = val; + } + } +} + +#else // !id386 + +__declspec( naked ) void S_WriteLinearBlastStereo16( void ) { + __asm { + + push edi + push ebx + mov ecx,ds : dword ptr[snd_linear_count] + mov ebx,ds : dword ptr[snd_p] + mov edi,ds : dword ptr[snd_out] +LWLBLoopTop: + mov eax,ds : dword ptr[-8 + ebx + ecx * 4] + sar eax,8 + cmp eax,07FFFh + jg LClampHigh + cmp eax,0FFFF8000h + jnl LClampDone + mov eax,0FFFF8000h + jmp LClampDone +LClampHigh: + mov eax,07FFFh +LClampDone: + mov edx,ds : dword ptr[-4 + ebx + ecx * 4] + sar edx,8 + cmp edx,07FFFh + jg LClampHigh2 + cmp edx,0FFFF8000h + jnl LClampDone2 + mov edx,0FFFF8000h + jmp LClampDone2 +LClampHigh2: + mov edx,07FFFh +LClampDone2: + shl edx,16 + and eax,0FFFFh + or edx,eax + mov ds : dword ptr[-4 + edi + ecx * 2],edx + sub ecx,2 + jnz LWLBLoopTop + pop ebx + pop edi + ret + } +} + +#endif // !id386 + +#else // !(defined __linux__ && defined __i386__) + +// snd_mixa.s +void S_WriteLinearBlastStereo16( void ); + +#endif + +/* +=================== +S_TransferStereo16 +=================== +*/ +void S_TransferStereo16( unsigned long *pbuf, int endtime ) { + int lpos; + int ls_paintedtime; + + snd_p = (int *) paintbuffer; + ls_paintedtime = s_paintedtime; + + while ( ls_paintedtime < endtime ) + { + // handle recirculating buffer issues + lpos = ls_paintedtime & ( ( dma.samples >> 1 ) - 1 ); + + snd_out = (short *) pbuf + ( lpos << 1 ); + + snd_linear_count = ( dma.samples >> 1 ) - lpos; + if ( ls_paintedtime + snd_linear_count > endtime ) { + snd_linear_count = endtime - ls_paintedtime; + } + + snd_linear_count <<= 1; + + // write a linear blast of samples + S_WriteLinearBlastStereo16(); + + snd_p += snd_linear_count; + ls_paintedtime += ( snd_linear_count >> 1 ); + } +} + +/* +=================== +S_TransferPaintBuffer +=================== +*/ +void S_TransferPaintBuffer( int endtime ) { + int out_idx; + int count; + int out_mask; + int *p; + int step; + int val; + unsigned long *pbuf; + + pbuf = (unsigned long *)dma.buffer; + if ( !pbuf ) { + return; + } + + if ( s_testsound->integer ) { + int i; + int count; + + // write a fixed sine wave + count = ( endtime - s_paintedtime ); + for ( i = 0 ; i < count ; i++ ) { + float v; + v = sin( M_PI * 2 * i / 64 ); + paintbuffer[i].left = paintbuffer[i].right = v * 0x400000; + } + } + + + if ( dma.samplebits == 16 && dma.channels == 2 ) { + // optimized case + S_TransferStereo16( pbuf, endtime ); + } else + { // general case + p = (int *) paintbuffer; + count = ( endtime - s_paintedtime ) * dma.channels; + out_mask = dma.samples - 1; + out_idx = s_paintedtime * dma.channels & out_mask; + step = 3 - dma.channels; + + if ( dma.samplebits == 16 ) { + short *out = (short *) pbuf; + while ( count-- ) + { + val = *p >> 8; + p += step; + if ( val > 0x7fff ) { + val = 0x7fff; + } else if ( val < -32768 ) { + val = -32768; + } + out[out_idx] = val; + out_idx = ( out_idx + 1 ) & out_mask; + } + } else if ( dma.samplebits == 8 ) { + unsigned char *out = (unsigned char *) pbuf; + while ( count-- ) + { + val = *p >> 8; + p += step; + if ( val > 0x7fff ) { + val = 0x7fff; + } else if ( val < -32768 ) { + val = -32768; + } + out[out_idx] = ( val >> 8 ) + 128; + out_idx = ( out_idx + 1 ) & out_mask; + } + } + } +} + +/* +=============================================================================== + +LIP SYNCING + +=============================================================================== +*/ + +#ifdef TALKANIM + +unsigned char s_entityTalkAmplitude[MAX_CLIENTS]; + +/* +=================== +S_SetVoiceAmplitudeFrom16 +=================== +*/ +void S_SetVoiceAmplitudeFrom16( const sfx_t *sc, int sampleOffset, int count, int entnum ) { + int data, i, sfx_count; + sndBuffer *chunk; + short *samples; + + if ( count <= 0 ) { + return; // must have gone ahead of the end of the sound + } + chunk = sc->soundData; + while ( sampleOffset >= SND_CHUNK_SIZE ) { + chunk = chunk->next; + sampleOffset -= SND_CHUNK_SIZE; + if ( !chunk ) { + chunk = sc->soundData; + } + } + + sfx_count = 0; + samples = chunk->sndChunk; + for ( i = 0; i < count; i++ ) { + if ( sampleOffset >= SND_CHUNK_SIZE ) { + chunk = chunk->next; + samples = chunk->sndChunk; + sampleOffset = 0; + } + data = samples[sampleOffset++]; + if ( abs( data ) > 5000 ) { + sfx_count += ( data * 255 ) >> 8; + } + } + //Com_Printf("Voice sfx_count = %d, count = %d\n", sfx_count, count ); + // adjust the sfx_count according to the frametime (scale down for longer frametimes) + sfx_count = abs( sfx_count ); + sfx_count = (int)( (float)sfx_count / ( 2.0 * (float)count ) ); + if ( sfx_count > 255 ) { + sfx_count = 255; + } + if ( sfx_count < 25 ) { + sfx_count = 0; + } + //Com_Printf("sfx_count = %d\n", sfx_count ); + // update the amplitude for this entity + s_entityTalkAmplitude[entnum] = (unsigned char)sfx_count; +} + +/* +=================== +S_SetVoiceAmplitudeFromADPCM +=================== +*/ +void S_SetVoiceAmplitudeFromADPCM( const sfx_t *sc, int sampleOffset, int count, int entnum ) { + int data, i, sfx_count; + sndBuffer *chunk; + short *samples; + + if ( count <= 0 ) { + return; // must have gone ahead of the end of the sound + } + i = 0; + chunk = sc->soundData; + while ( sampleOffset >= ( SND_CHUNK_SIZE * 4 ) ) { + chunk = chunk->next; + sampleOffset -= ( SND_CHUNK_SIZE * 4 ); + i++; + } + + if ( i != sfxScratchIndex || sfxScratchPointer != sc ) { + S_AdpcmGetSamples( chunk, sfxScratchBuffer ); + sfxScratchIndex = i; + sfxScratchPointer = sc; + } + + sfx_count = 0; + samples = sfxScratchBuffer; + for ( i = 0; i < count; i++ ) { + if ( sampleOffset >= SND_CHUNK_SIZE * 4 ) { + chunk = chunk->next; + S_AdpcmGetSamples( chunk, sfxScratchBuffer ); + sampleOffset = 0; + sfxScratchIndex++; + } + data = samples[sampleOffset++]; + if ( abs( data ) > 5000 ) { + sfx_count += ( data * 255 ) >> 8; + } + } + //Com_Printf("Voice sfx_count = %d, count = %d\n", sfx_count, count ); + // adjust the sfx_count according to the frametime (scale down for longer frametimes) + sfx_count = abs( sfx_count ); + sfx_count = (int)( (float)sfx_count / ( 2.0 * (float)count ) ); + if ( sfx_count > 255 ) { + sfx_count = 255; + } + if ( sfx_count < 25 ) { + sfx_count = 0; + } + //Com_Printf("sfx_count = %d\n", sfx_count ); + // update the amplitude for this entity + s_entityTalkAmplitude[entnum] = (unsigned char)sfx_count; +} + +/* +=================== +S_SetVoiceAmplitudeFromWavelet +=================== +*/ +void S_SetVoiceAmplitudeFromWavelet( const sfx_t *sc, int sampleOffset, int count, int entnum ) { + int data, i, sfx_count; + sndBuffer *chunk; + short *samples; + + if ( count <= 0 ) { + return; // must have gone ahead of the end of the sound + } + i = 0; + chunk = sc->soundData; + while ( sampleOffset >= ( SND_CHUNK_SIZE_FLOAT * 4 ) ) { + chunk = chunk->next; + sampleOffset -= ( SND_CHUNK_SIZE_FLOAT * 4 ); + i++; + } + if ( i != sfxScratchIndex || sfxScratchPointer != sc ) { + decodeWavelet( chunk, sfxScratchBuffer ); + sfxScratchIndex = i; + sfxScratchPointer = sc; + } + sfx_count = 0; + samples = sfxScratchBuffer; + for ( i = 0; i < count; i++ ) { + if ( sampleOffset >= ( SND_CHUNK_SIZE_FLOAT * 4 ) ) { + chunk = chunk->next; + decodeWavelet( chunk, sfxScratchBuffer ); + sfxScratchIndex++; + sampleOffset = 0; + } + data = samples[sampleOffset++]; + if ( abs( data ) > 5000 ) { + sfx_count += ( data * 255 ) >> 8; + } + } + + //Com_Printf("Voice sfx_count = %d, count = %d\n", sfx_count, count ); + // adjust the sfx_count according to the frametime (scale down for longer frametimes) + sfx_count = abs( sfx_count ); + sfx_count = (int)( (float)sfx_count / ( 2.0 * (float)count ) ); + if ( sfx_count > 255 ) { + sfx_count = 255; + } + if ( sfx_count < 25 ) { + sfx_count = 0; + } + //Com_Printf("sfx_count = %d\n", sfx_count ); + // update the amplitude for this entity + s_entityTalkAmplitude[entnum] = (unsigned char)sfx_count; +} + +/* +=================== +S_SetVoiceAmplitudeFromMuLaw +=================== +*/ +void S_SetVoiceAmplitudeFromMuLaw( const sfx_t *sc, int sampleOffset, int count, int entnum ) { + int data, i, sfx_count; + sndBuffer *chunk; + byte *samples; + + if ( count <= 0 ) { + return; // must have gone ahead of the end of the sound + } + chunk = sc->soundData; + while ( sampleOffset >= ( SND_CHUNK_SIZE * 2 ) ) { + chunk = chunk->next; + sampleOffset -= ( SND_CHUNK_SIZE * 2 ); + if ( !chunk ) { + chunk = sc->soundData; + } + } + sfx_count = 0; + samples = (byte *)chunk->sndChunk + sampleOffset; + for ( i = 0; i < count; i++ ) { + if ( samples >= (byte *)chunk->sndChunk + ( SND_CHUNK_SIZE * 2 ) ) { + chunk = chunk->next; + samples = (byte *)chunk->sndChunk; + } + data = mulawToShort[*samples]; + if ( abs( data ) > 5000 ) { + sfx_count += ( data * 255 ) >> 8; + } + samples++; + } + //Com_Printf("Voice sfx_count = %d, count = %d\n", sfx_count, count ); + // adjust the sfx_count according to the frametime (scale down for longer frametimes) + sfx_count = abs( sfx_count ); + sfx_count = (int)( (float)sfx_count / ( 2.0 * (float)count ) ); + if ( sfx_count > 255 ) { + sfx_count = 255; + } + if ( sfx_count < 25 ) { + sfx_count = 0; + } + //Com_Printf("sfx_count = %d\n", sfx_count ); + // update the amplitude for this entity + s_entityTalkAmplitude[entnum] = (unsigned char)sfx_count; +} + +/* +=================== +S_GetVoiceAmplitude +=================== +*/ +int S_GetVoiceAmplitude( int entityNum ) { + if ( entityNum >= MAX_CLIENTS ) { + Com_Printf( "Error: S_GetVoiceAmplitude() called for a non-client\n" ); + return 0; + } + + return (int)s_entityTalkAmplitude[entityNum]; +} +#endif + +/* +=============================================================================== + +CHANNEL MIXING + +=============================================================================== +*/ + +/* +=================== +S_PaintChannelFrom16 +=================== +*/ +static void S_PaintChannelFrom16( channel_t *ch, const sfx_t *sc, int count, int sampleOffset, int bufferOffset ) { + int data, aoff, boff; + int leftvol, rightvol; + int i, j; + portable_samplepair_t *samp; + sndBuffer *chunk; + short *samples; + float ooff, fdata, fdiv, fleftvol, frightvol; + + samp = &paintbuffer[ bufferOffset ]; + + if ( ch->doppler ) { + sampleOffset = sampleOffset * ch->oldDopplerScale; + } + + chunk = sc->soundData; + while ( sampleOffset >= SND_CHUNK_SIZE ) { + chunk = chunk->next; + sampleOffset -= SND_CHUNK_SIZE; + if ( !chunk ) { + chunk = sc->soundData; + } + } + + if ( !ch->doppler ) { + leftvol = ch->leftvol * snd_vol; + rightvol = ch->rightvol * snd_vol; + + samples = chunk->sndChunk; + for ( i = 0; i < count; i++ ) { + if ( sampleOffset >= SND_CHUNK_SIZE ) { + chunk = chunk->next; + if ( chunk == NULL ) { + chunk = sc->soundData; + } + samples = chunk->sndChunk; + sampleOffset -= SND_CHUNK_SIZE; + } + data = samples[sampleOffset++]; + samp[i].left += ( data * leftvol ) >> 8; + samp[i].right += ( data * rightvol ) >> 8; + } + } else { + fleftvol = ch->leftvol * snd_vol; + frightvol = ch->rightvol * snd_vol; + + ooff = sampleOffset; + samples = chunk->sndChunk; + + for ( i = 0 ; i < count ; i++ ) { + aoff = ooff; + ooff = ooff + ch->dopplerScale; + boff = ooff; + fdata = 0; + for ( j = aoff; j < boff; j++ ) { + if ( j >= SND_CHUNK_SIZE ) { + chunk = chunk->next; + if ( !chunk ) { + chunk = sc->soundData; + } + samples = chunk->sndChunk; + ooff -= SND_CHUNK_SIZE; + } + fdata += samples[j & ( SND_CHUNK_SIZE - 1 )]; + } + fdiv = 256 * ( boff - aoff ); + samp[i].left += ( fdata * fleftvol ) / fdiv; + samp[i].right += ( fdata * frightvol ) / fdiv; + } + } +} + +/* +=================== +S_PaintChannelFromWavelet +=================== +*/ +void S_PaintChannelFromWavelet( channel_t *ch, sfx_t *sc, int count, int sampleOffset, int bufferOffset ) { + int data; + int leftvol, rightvol; + int i; + portable_samplepair_t *samp; + sndBuffer *chunk; + short *samples; + + leftvol = ch->leftvol * snd_vol; + rightvol = ch->rightvol * snd_vol; + + i = 0; + samp = &paintbuffer[ bufferOffset ]; + chunk = sc->soundData; + while ( sampleOffset >= ( SND_CHUNK_SIZE_FLOAT * 4 ) ) { + chunk = chunk->next; + sampleOffset -= ( SND_CHUNK_SIZE_FLOAT * 4 ); + i++; + } + + if ( i != sfxScratchIndex || sfxScratchPointer != sc ) { + decodeWavelet( chunk, sfxScratchBuffer ); + sfxScratchIndex = i; + sfxScratchPointer = sc; + } + + samples = sfxScratchBuffer; + + // FIXME: doppler + + for ( i = 0; i < count; i++ ) { + if ( sampleOffset >= ( SND_CHUNK_SIZE_FLOAT * 4 ) ) { + chunk = chunk->next; + decodeWavelet( chunk, sfxScratchBuffer ); + sfxScratchIndex++; + sampleOffset = 0; + } + data = samples[sampleOffset++]; + samp[i].left += ( data * leftvol ) >> 8; + samp[i].right += ( data * rightvol ) >> 8; + } +} + +/* +=================== +S_PaintChannelFromADPCM +=================== +*/ +void S_PaintChannelFromADPCM( channel_t *ch, sfx_t *sc, int count, int sampleOffset, int bufferOffset ) { + int data; + int leftvol, rightvol; + int i; + portable_samplepair_t *samp; + sndBuffer *chunk; + short *samples; + + leftvol = ch->leftvol * snd_vol; + rightvol = ch->rightvol * snd_vol; + + i = 0; + samp = &paintbuffer[ bufferOffset ]; + chunk = sc->soundData; + + if ( ch->doppler ) { + sampleOffset = sampleOffset * ch->oldDopplerScale; + } + + while ( sampleOffset >= ( SND_CHUNK_SIZE * 4 ) ) { + chunk = chunk->next; + sampleOffset -= ( SND_CHUNK_SIZE * 4 ); + i++; + } + + if ( i != sfxScratchIndex || sfxScratchPointer != sc ) { + S_AdpcmGetSamples( chunk, sfxScratchBuffer ); + sfxScratchIndex = i; + sfxScratchPointer = sc; + } + + samples = sfxScratchBuffer; + for ( i = 0; i < count; i++ ) { + if ( sampleOffset >= SND_CHUNK_SIZE * 4 ) { + chunk = chunk->next; + if ( !chunk ) { + chunk = sc->soundData; + } + S_AdpcmGetSamples( chunk, sfxScratchBuffer ); + sampleOffset = 0; + sfxScratchIndex++; + } + data = samples[sampleOffset++]; + samp[i].left += ( data * leftvol ) >> 8; + samp[i].right += ( data * rightvol ) >> 8; + } +} + +/* +=================== +S_PaintChannelFromMuLaw +=================== +*/ +void S_PaintChannelFromMuLaw( channel_t *ch, sfx_t *sc, int count, int sampleOffset, int bufferOffset ) { + int data; + int leftvol, rightvol; + int i; + portable_samplepair_t *samp; + sndBuffer *chunk; + byte *samples; + float ooff; + + leftvol = ch->leftvol * snd_vol; + rightvol = ch->rightvol * snd_vol; + + samp = &paintbuffer[ bufferOffset ]; + chunk = sc->soundData; + while ( sampleOffset >= ( SND_CHUNK_SIZE * 2 ) ) { + chunk = chunk->next; + sampleOffset -= ( SND_CHUNK_SIZE * 2 ); + if ( !chunk ) { + chunk = sc->soundData; + } + } + + if ( !ch->doppler ) { + samples = (byte *)chunk->sndChunk + sampleOffset; + for ( i = 0; i < count; i++ ) { + if ( samples >= (byte *)chunk->sndChunk + ( SND_CHUNK_SIZE * 2 ) ) { + chunk = chunk->next; + samples = (byte *)chunk->sndChunk; + } + data = mulawToShort[*samples]; + samp[i].left += ( data * leftvol ) >> 8; + samp[i].right += ( data * rightvol ) >> 8; + samples++; + } + } else { + ooff = sampleOffset; + samples = (byte *)chunk->sndChunk; + for ( i = 0; i < count; i++ ) { + if ( ooff >= SND_CHUNK_SIZE * 2 ) { + chunk = chunk->next; + if ( !chunk ) { + chunk = sc->soundData; + } + samples = (byte *)chunk->sndChunk; + ooff = 0.0; + } + data = mulawToShort[samples[(int)( ooff )]]; + ooff = ooff + ch->dopplerScale; + samp[i].left += ( data * leftvol ) >> 8; + samp[i].right += ( data * rightvol ) >> 8; + } + } +} + +#define TALK_FUTURE_SEC 0.25 // go this far into the future (seconds) + +/* +=================== +S_PaintChannels +=================== +*/ +void S_PaintChannels( int endtime ) { + int i, si; + int end; + channel_t *ch; + sfx_t *sc; + int ltime, count; + int sampleOffset; + streamingSound_t *ss; + qboolean firstPass = qtrue; + + if ( s_mute->value ) { + snd_vol = 0; + } else { + snd_vol = s_volume->value * 256; + } + + if ( snd.volCurrent < 1 ) { // only when fading (at map start/end) + snd_vol = (int)( (float)snd_vol * snd.volCurrent ); + } + + //Com_Printf ("%i to %i\n", s_paintedtime, endtime); + while ( s_paintedtime < endtime ) { + // if paintbuffer is smaller than DMA buffer + // we may need to fill it multiple times + end = endtime; + if ( endtime - s_paintedtime > PAINTBUFFER_SIZE ) { + Com_DPrintf( "endtime exceeds PAINTBUFFER_SIZE %i\n", endtime - s_paintedtime ); + end = s_paintedtime + PAINTBUFFER_SIZE; + } + + // clear pain buffer for the current time + Com_Memset( paintbuffer, 0, ( end - s_paintedtime ) * sizeof( portable_samplepair_t ) ); + // mix all streaming sounds into paint buffer + for ( si = 0, ss = streamingSounds; si < MAX_STREAMING_SOUNDS; si++, ss++ ) { + // if this streaming sound is still playing + if ( s_rawend[si] >= s_paintedtime ) { + // copy from the streaming sound source + int s; + int stop; +// float fsir, fsil; // TTimo: unused + + stop = ( end < s_rawend[si] ) ? end : s_rawend[si]; + + // precalculating this saves zillions of cycles +//DAJ fsir = ((float)s_rawVolume[si].left/255.0f); +//DAJ fsil = ((float)s_rawVolume[si].right/255.0f); + + for ( i = s_paintedtime ; i < stop ; i++ ) { + s = i & ( MAX_RAW_SAMPLES - 1 ); +//DAJ paintbuffer[i-s_paintedtime].left += (int)((float)s_rawsamples[si][s].left * fsir); +//DAJ paintbuffer[i-s_paintedtime].right += (int)((float)s_rawsamples[si][s].right * fsil); + //DAJ even faster + paintbuffer[i - s_paintedtime].left += ( s_rawsamples[si][s].left * s_rawVolume[si].left ) >> 8; + paintbuffer[i - s_paintedtime].right += ( s_rawsamples[si][s].right * s_rawVolume[si].right ) >> 8; + } + +#ifdef TALKANIM + if ( firstPass && ss->channel == CHAN_VOICE && ss->entnum < MAX_CLIENTS ) { + int talkcnt, talktime; + int sfx_count, vstop; + int data; + + // we need to go into the future, since the interpolated behaviour of the facial + // animation creates lag in the time it takes to display the current facial frame + talktime = s_paintedtime + (int)( TALK_FUTURE_SEC * (float)s_khz->integer * 1000 ); + vstop = ( talktime + 100 < s_rawend[si] ) ? talktime + 100 : s_rawend[si]; + talkcnt = 1; + sfx_count = 0; + + for ( i = talktime ; i < vstop ; i++ ) { + s = i & ( MAX_RAW_SAMPLES - 1 ); + data = abs( ( s_rawsamples[si][s].left ) / 8000 ); + if ( data > sfx_count ) { + sfx_count = data; + } + } + + if ( sfx_count > 255 ) { + sfx_count = 255; + } + if ( sfx_count < 25 ) { + sfx_count = 0; + } + + //Com_Printf("sfx_count = %d\n", sfx_count ); + + // update the amplitude for this entity + s_entityTalkAmplitude[ss->entnum] = (unsigned char)sfx_count; + } +#endif + } + } + + // paint in the channels. + ch = s_channels; + for ( i = 0; i < MAX_CHANNELS; i++, ch++ ) { + if ( ch->startSample == START_SAMPLE_IMMEDIATE || !ch->thesfx || ( ch->leftvol < 0.25 && ch->rightvol < 0.25 ) ) { + continue; + } + + ltime = s_paintedtime; + sc = ch->thesfx; + + // (SA) hmm, why was this commented out? + if ( !sc->inMemory ) { + S_memoryLoad( sc ); + } + + sampleOffset = ltime - ch->startSample; + count = end - ltime; + if ( sampleOffset + count > sc->soundLength ) { + count = sc->soundLength - sampleOffset; + } + + if ( count > 0 ) { +#ifdef TALKANIM + // Ridah, talking animations + // TODO: check that this entity has talking animations enabled! + if ( firstPass && ch->entchannel == CHAN_VOICE && ch->entnum < MAX_CLIENTS ) { + int talkofs, talkcnt, talktime; + // we need to go into the future, since the interpolated behaviour of the facial + // animation creates lag in the time it takes to display the current facial frame + talktime = ltime + (int)( TALK_FUTURE_SEC * (float)s_khz->integer * 1000 ); + talkofs = talktime - ch->startSample; + talkcnt = 100; + if ( talkofs + talkcnt < sc->soundLength ) { + if ( sc->soundCompressionMethod == 1 ) { + S_SetVoiceAmplitudeFromADPCM( sc, talkofs, talkcnt, ch->entnum ); + } else if ( sc->soundCompressionMethod == 2 ) { + S_SetVoiceAmplitudeFromWavelet( sc, talkofs, talkcnt, ch->entnum ); + } else if ( sc->soundCompressionMethod == 3 ) { + S_SetVoiceAmplitudeFromMuLaw( sc, talkofs, talkcnt, ch->entnum ); + } else { + S_SetVoiceAmplitudeFrom16( sc, talkofs, talkcnt, ch->entnum ); + } + } + } +#endif + if ( sc->soundCompressionMethod == 1 ) { + S_PaintChannelFromADPCM( ch, sc, count, sampleOffset, ltime - s_paintedtime ); + } else if ( sc->soundCompressionMethod == 2 ) { + S_PaintChannelFromWavelet( ch, sc, count, sampleOffset, ltime - s_paintedtime ); + } else if ( sc->soundCompressionMethod == 3 ) { + S_PaintChannelFromMuLaw( ch, sc, count, sampleOffset, ltime - s_paintedtime ); + } else { + S_PaintChannelFrom16( ch, sc, count, sampleOffset, ltime - s_paintedtime ); + } + } + } + + // paint in the looped channels. + ch = loop_channels; + for ( i = 0; i < numLoopChannels ; i++, ch++ ) { + sc = ch->thesfx; + if ( !ch->thesfx || ( !ch->leftvol && !ch->rightvol ) ) { + continue; + } + + ltime = s_paintedtime; + + if ( sc->soundData == NULL || sc->soundLength == 0 ) { + continue; + } + // we might have to make two passes if it + // is a looping sound effect and the end of + // the sample is hit + do { + sampleOffset = ( ltime % sc->soundLength ); + + count = end - ltime; + if ( sampleOffset + count > sc->soundLength ) { + count = sc->soundLength - sampleOffset; + } + + if ( count > 0 ) { +#ifdef TALKANIM + // Ridah, talking animations + // TODO: check that this entity has talking animations enabled! + if ( firstPass && ch->entchannel == CHAN_VOICE && ch->entnum < MAX_CLIENTS ) { + int talkofs, talkcnt, talktime; + // we need to go into the future, since the interpolated behaviour of the facial + // animation creates lag in the time it takes to display the current facial frame + talktime = ltime + (int)( TALK_FUTURE_SEC * (float)s_khz->integer * 1000 ); + talkofs = talktime % sc->soundLength; + talkcnt = 100; + if ( talkofs + talkcnt < sc->soundLength ) { + if ( sc->soundCompressionMethod == 1 ) { + S_SetVoiceAmplitudeFromADPCM( sc, talkofs, talkcnt, ch->entnum ); + } else if ( sc->soundCompressionMethod == 2 ) { + S_SetVoiceAmplitudeFromWavelet( sc, talkofs, talkcnt, ch->entnum ); + } else if ( sc->soundCompressionMethod == 3 ) { + S_SetVoiceAmplitudeFromMuLaw( sc, talkofs, talkcnt, ch->entnum ); + } else { + S_SetVoiceAmplitudeFrom16( sc, talkofs, talkcnt, ch->entnum ); + } + } + } +#endif + if ( sc->soundCompressionMethod == 1 ) { + S_PaintChannelFromADPCM( ch, sc, count, sampleOffset, ltime - s_paintedtime ); + } else if ( sc->soundCompressionMethod == 2 ) { + S_PaintChannelFromWavelet( ch, sc, count, sampleOffset, ltime - s_paintedtime ); + } else if ( sc->soundCompressionMethod == 3 ) { + S_PaintChannelFromMuLaw( ch, sc, count, sampleOffset, ltime - s_paintedtime ); + } else { + S_PaintChannelFrom16( ch, sc, count, sampleOffset, ltime - s_paintedtime ); + } + ltime += count; + } + } while ( ltime < end ); + } + + // transfer out according to DMA format + S_TransferPaintBuffer( end ); + s_paintedtime = end; + firstPass = qfalse; + } +} diff --git a/Projects/Android/jni/rtcw/src/client/snd_public.h b/Projects/Android/jni/rtcw/src/client/snd_public.h new file mode 100644 index 0000000..e8ccf16 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/client/snd_public.h @@ -0,0 +1,105 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +#ifdef DOOMSOUND ///// (SA) DOOMSOUND +#ifdef __cplusplus +extern "C" { +#endif +#endif ///// (SA) DOOMSOUND + +void S_Init( void ); +void S_Shutdown( void ); +void S_UpdateThread( void ); + +// if origin is NULL, the sound will be dynamically sourced from the entity +void S_StartSound( vec3_t origin, int entnum, int entchannel, sfxHandle_t sfx ); +void S_StartSoundEx( vec3_t origin, int entnum, int entchannel, sfxHandle_t sfx, int flags ); +void S_StartLocalSound( sfxHandle_t sfx, int channelNum ); + +void S_StartBackgroundTrack( const char *intro, const char *loop, int fadeupTime ); +void S_StopBackgroundTrack( void ); +void S_QueueBackgroundTrack( const char *loop ); //----(SA) added +void S_FadeStreamingSound( float targetvol, int time, int ssNum ); //----(SA) added +void S_FadeAllSounds( float targetvol, int time ); //----(SA) added + +void S_StartStreamingSound( const char *intro, const char *loop, int entnum, int channel, int attenuation ); +void S_StopStreamingSound( int index ); +void S_StopEntStreamingSound( int entNum ); //----(SA) added + +// cinematics and voice-over-network will send raw samples +// 1.0 volume will be direct output of source samples +void S_RawSamples( int samples, int rate, int width, int s_channels, + const byte *data, float lvol, float rvol, int streamingIndex ); + +// stop all sounds and the background track +void S_StopAllSounds( void ); + +// all continuous looping sounds must be added before calling S_Update +void S_ClearLoopingSounds( void ); +void S_ClearSounds( qboolean clearStreaming, qboolean clearMusic ); //----(SA) modified +void S_AddLoopingSound( int entityNum, const vec3_t origin, const vec3_t velocity, const int range, sfxHandle_t sfxHandle, int volume ); +void S_AddRealLoopingSound( int entityNum, const vec3_t origin, const vec3_t velocity, const int range, sfxHandle_t sfx ); +void S_StopLoopingSound( int entityNum ); + +#ifdef DOOMSOUND ///// (SA) DOOMSOUND +void S_ClearSoundBuffer( void ); +#endif ///// (SA) DOOMSOUND +// recompute the reletive volumes for all running sounds +// reletive to the given entityNum / orientation +void S_Respatialize( int entityNum, const vec3_t origin, vec3_t axis[3], int inwater ); + +// let the sound system know where an entity currently is +void S_UpdateEntityPosition( int entityNum, const vec3_t origin ); + +void S_Update( void ); + +void S_DisableSounds( void ); + +void S_BeginRegistration( void ); + +// RegisterSound will allways return a valid sample, even if it +// has to create a placeholder. This prevents continuous filesystem +// checks for missing files +#ifdef DOOMSOUND ///// (SA) DOOMSOUND +sfxHandle_t S_RegisterSound( const char *sample ); +#else +sfxHandle_t S_RegisterSound( const char *sample, qboolean compressed ); +#endif ///// (SA) DOOMSOUND + +void S_DisplayFreeMemory( void ); + +// +int S_GetVoiceAmplitude( int entityNum ); + + +#ifdef DOOMSOUND ///// (SA) DOOMSOUND +#ifdef __cplusplus +} +#endif +#endif ///// (SA) DOOMSOUND diff --git a/Projects/Android/jni/rtcw/src/client/snd_wavelet.c b/Projects/Android/jni/rtcw/src/client/snd_wavelet.c new file mode 100644 index 0000000..892fb0f --- /dev/null +++ b/Projects/Android/jni/rtcw/src/client/snd_wavelet.c @@ -0,0 +1,280 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +/***************************************************************************** + * name: snd_wavelet.c + * + * desc: + * + * + *****************************************************************************/ + +#include "snd_local.h" + +long myftol( float f ); + +#define C0 0.4829629131445341 +#define C1 0.8365163037378079 +#define C2 0.2241438680420134 +#define C3 -0.1294095225512604 + +void daub4( float b[], unsigned long n, int isign ) { + float wksp[4097]; + float *a = b - 1; // numerical recipies so a[1] = b[0] + + unsigned long nh,nh1,i,j; + + if ( n < 4 ) { + return; + } + + nh1 = ( nh = n >> 1 ) + 1; + if ( isign >= 0 ) { + for ( i = 1, j = 1; j <= n - 3; j += 2, i++ ) { + wksp[i] = C0 * a[j] + C1 * a[j + 1] + C2 * a[j + 2] + C3 * a[j + 3]; + wksp[i + nh] = C3 * a[j] - C2 * a[j + 1] + C1 * a[j + 2] - C0 * a[j + 3]; + } + wksp[i ] = C0 * a[n - 1] + C1 * a[n] + C2 * a[1] + C3 * a[2]; + wksp[i + nh] = C3 * a[n - 1] - C2 * a[n] + C1 * a[1] - C0 * a[2]; + } else { + wksp[1] = C2 * a[nh] + C1 * a[n] + C0 * a[1] + C3 * a[nh1]; + wksp[2] = C3 * a[nh] - C0 * a[n] + C1 * a[1] - C2 * a[nh1]; + for ( i = 1, j = 3; i < nh; i++ ) { + wksp[j++] = C2 * a[i] + C1 * a[i + nh] + C0 * a[i + 1] + C3 * a[i + nh1]; + wksp[j++] = C3 * a[i] - C0 * a[i + nh] + C1 * a[i + 1] - C2 * a[i + nh1]; + } + } + for ( i = 1; i <= n; i++ ) { + a[i] = wksp[i]; + } +} + +void wt1( float a[], unsigned long n, int isign ) { + unsigned long nn; + int inverseStartLength = n / 4; + if ( n < inverseStartLength ) { + return; + } + if ( isign >= 0 ) { + for ( nn = n; nn >= inverseStartLength; nn >>= 1 ) daub4( a,nn,isign ); + } else { + for ( nn = inverseStartLength; nn <= n; nn <<= 1 ) daub4( a,nn,isign ); + } +} + +/* The number of bits required by each value */ +static unsigned char numBits[] = { + 0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5, + 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, + 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, + 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, + 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, + 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, + 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, + 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, +}; + +byte MuLawEncode( short s ) { + unsigned long adjusted; + byte sign, exponent, mantissa; + + sign = ( s < 0 ) ? 0 : 0x80; + + if ( s < 0 ) { + s = -s; + } + adjusted = (long)s << ( 16 - sizeof( short ) * 8 ); + adjusted += 128L + 4L; + if ( adjusted > 32767 ) { + adjusted = 32767; + } + exponent = numBits[( adjusted >> 7 ) & 0xff] - 1; + mantissa = ( adjusted >> ( exponent + 3 ) ) & 0xf; + return ~( sign | ( exponent << 4 ) | mantissa ); +} + +short MuLawDecode( byte uLaw ) { + signed long adjusted; + byte exponent, mantissa; + + uLaw = ~uLaw; + exponent = ( uLaw >> 4 ) & 0x7; + mantissa = ( uLaw & 0xf ) + 16; + adjusted = ( mantissa << ( exponent + 3 ) ) - 128 - 4; + + return ( uLaw & 0x80 ) ? adjusted : -adjusted; +} + +short mulawToShort[256]; +static qboolean madeTable = qfalse; + +static int NXStreamCount; + +void NXPutc( NXStream *stream, char out ) { + stream[NXStreamCount++] = out; +} + + +void encodeWavelet( sfx_t *sfx, short *packets ) { + float wksp[4097], temp; + int i, samples, size; + sndBuffer *newchunk, *chunk; + byte *out; + + if ( !madeTable ) { + for ( i = 0; i < 256; i++ ) { + mulawToShort[i] = (float)MuLawDecode( (byte)i ); + } + madeTable = qtrue; + } + chunk = NULL; + + samples = sfx->soundLength; + while ( samples > 0 ) { + size = samples; + if ( size > ( SND_CHUNK_SIZE * 2 ) ) { + size = ( SND_CHUNK_SIZE * 2 ); + } + + if ( size < 4 ) { + size = 4; + } + + newchunk = SND_malloc(); + if ( sfx->soundData == NULL ) { + sfx->soundData = newchunk; + } else { + chunk->next = newchunk; + } + chunk = newchunk; + for ( i = 0; i < size; i++ ) { + wksp[i] = *packets; + packets++; + } + wt1( wksp, size, 1 ); + out = (byte *)chunk->sndChunk; + + for ( i = 0; i < size; i++ ) { + temp = wksp[i]; + if ( temp > 32767 ) { + temp = 32767; + } else if ( temp < -32768 ) { + temp = -32768; + } + out[i] = MuLawEncode( (short)temp ); + } + + chunk->size = size; + samples -= size; + } +} + +void decodeWavelet( sndBuffer *chunk, short *to ) { + float wksp[4097]; + int i; + byte *out; + + int size = chunk->size; + + out = (byte *)chunk->sndChunk; + for ( i = 0; i < size; i++ ) { + wksp[i] = mulawToShort[out[i]]; + } + + wt1( wksp, size, -1 ); + + if ( !to ) { + return; + } + + for ( i = 0; i < size; i++ ) { + to[i] = wksp[i]; + } +} + + +void encodeMuLaw( sfx_t *sfx, short *packets ) { + int i, samples, size, grade, poop; + sndBuffer *newchunk, *chunk; + byte *out; + + if ( !madeTable ) { + for ( i = 0; i < 256; i++ ) { + mulawToShort[i] = (float)MuLawDecode( (byte)i ); + } + madeTable = qtrue; + } + + chunk = NULL; + samples = sfx->soundLength; + grade = 0; + + while ( samples > 0 ) { + size = samples; + if ( size > ( SND_CHUNK_SIZE * 2 ) ) { + size = ( SND_CHUNK_SIZE * 2 ); + } + + newchunk = SND_malloc(); + if ( sfx->soundData == NULL ) { + sfx->soundData = newchunk; + } else { + chunk->next = newchunk; + } + chunk = newchunk; + out = (byte *)chunk->sndChunk; + for ( i = 0; i < size; i++ ) { + poop = packets[0] + grade; + if ( poop > 32767 ) { + poop = 32767; + } else if ( poop < -32768 ) { + poop = -32768; + } + out[i] = MuLawEncode( (short)poop ); + grade = poop - mulawToShort[out[i]]; + packets++; + } + chunk->size = size; + samples -= size; + } +} + +void decodeMuLaw( sndBuffer *chunk, short *to ) { + int i; + byte *out; + + int size = chunk->size; + + out = (byte *)chunk->sndChunk; + for ( i = 0; i < size; i++ ) { + to[i] = mulawToShort[out[i]]; + } +} + + diff --git a/Projects/Android/jni/rtcw/src/extractfuncs/ChangeLog b/Projects/Android/jni/rtcw/src/extractfuncs/ChangeLog new file mode 100644 index 0000000..c20e613 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/extractfuncs/ChangeLog @@ -0,0 +1,17 @@ +2001-12-07 Timothee Besset + +Imported from the Wolf MP version, Mac/Linux friendly version +Fixed argbase bug in *nix main +Escape BoxOnPlaneSide on linux (taken out by preprocessing) + +2001-11-02 Timothee Besset + +Modified extractfuncs to works on linux +Would still need to integrate it correctly with the build system +Changed the command line syntax of the linux ver: +screwup [-o ] [ ..] + +if none specified, is "g_funcs" + +on linux at least, those header files need to be tweaked by hand +because unresolved externs are not ignored by gcc (otherwise harmless on win32) diff --git a/Projects/Android/jni/rtcw/src/extractfuncs/Conscript b/Projects/Android/jni/rtcw/src/extractfuncs/Conscript new file mode 100644 index 0000000..f8be465 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/extractfuncs/Conscript @@ -0,0 +1,9 @@ +# extractfuncs building + +$env = new cons( + CC => 'gcc', + CFLAGS => '-g -DSCREWUP ' + ); + +Program $env 'extractfuncs', 'extractfuncs.c', 'l_log.c', 'l_memory.c', 'l_precomp.c', 'l_script.c'; +Install $env '#', 'extractfuncs'; diff --git a/Projects/Android/jni/rtcw/src/extractfuncs/extractfuncs.c b/Projects/Android/jni/rtcw/src/extractfuncs/extractfuncs.c new file mode 100644 index 0000000..c6e9903 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/extractfuncs/extractfuncs.c @@ -0,0 +1,653 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +#include +#include +#include +#include +#include +#ifdef _WIN32 +#include +#include +#endif +#include "l_memory.h" +#include "l_script.h" +#include "l_precomp.h" +#include "l_log.h" + +typedef enum {false, true} qboolean; + +//#define PATHSEPERATOR_STR "\\" + +void Error( char *error, ... ) { + va_list argptr; + + va_start( argptr, error ); + vprintf( error, argptr ); + va_end( argptr ); + + exit( 1 ); +} + +/* +int FileLength (FILE *f) +{ + int pos; + int end; + + pos = ftell (f); + fseek (f, 0, SEEK_END); + end = ftell (f); + fseek (f, pos, SEEK_SET); + + return end; +} //end of the function FileLength + +void Remove(char *buf, int length, char *from, char *to, char *skip) +{ + int i, remove = false; + + for (i = 0; i < length; i++) + { + if (remove) + { + if ((unsigned) length - i > strlen(skip)) + { + if (!strncmp(&buf[i], skip, strlen(skip))) + { + i += strlen(skip); + } //end if + } //end if + if ((unsigned) length - i > strlen(to)) + { + if (!strncmp(&buf[i], to, strlen(to))) + { + length = i + strlen(to); + } //end if + } //end if + if (buf[i]) buf[i] = 'a'; + } //end if + else + { + if ((unsigned) length - i < strlen(from)) return; + if (!strncmp(&buf[i], from, strlen(from))) remove = true; + } //end else + } //end for +} //end of the function Remove + +void main(int argc, char *argv[]) +{ + FILE *fp; + int filelength; + char *from, *to, *skip, *ptr; + + if (argc < 2) Error("USAGE: screwup "); + fp = fopen(argv[1], "rb"); + if (!fp) Error("error opening %s\n", argv[1]); + + filelength = FileLength(fp); + ptr = malloc(filelength); + fread(ptr, filelength, 1, fp); + fclose(fp); + + from = argv[3];//"be_aas_bspq2.c"; + to = argv[4];//"BotWeaponNameFromModel"; + skip = "GetBotAPI"; + + Remove(ptr, filelength, from, to, skip); + + fp = fopen(argv[2], "wb"); + if (!fp) Error("error opening %s\n", argv[2]); + fwrite(ptr, filelength, 1, fp); + fclose(fp); + + free(ptr); +} //end of the function main +*/ + +typedef struct replacefunc_s +{ + char *name; + char *newname; + char *filename; + char dec[MAX_TOKEN]; //function declaration + struct replacefunc_s *next; +} replacefunc_t; + +replacefunc_t *replacefuncs; +int numfuncs; + +extern int Q_stricmp( const char *s1, const char *s2 ); + +// the function names +//#define DEFAULT_FUNCBASE "g_func" +static char *func_filename = "g_funcs.h"; +static char *func_filedesc = "g_func_decs.h"; + +void DumpReplaceFunctions( void ) { + replacefunc_t *rf; + char path[_MAX_PATH]; + FILE *f; + int len, newlen; + unsigned char *buf, *newbuf; + int updated; + + updated = 0; + + // dump the function header + strcpy( path, "." ); + strcat( path, PATHSEPERATOR_STR ); + strcat( path, "g_funcs.tmp" ); + Log_Open( path ); + for ( rf = replacefuncs; rf; rf = rf->next ) + { + Log_Print( "{\"%s\", (byte *)%s},\n", rf->name, rf->name ); + } //end for + Log_Print( "{0, 0}\n" ); + Log_Close(); + + // if it's different, rename the file over the real header + strcpy( path, "g_funcs.tmp" ); + f = fopen( path, "rb" ); + fseek( f, 0, SEEK_END ); + len = ftell( f ); + buf = (unsigned char *) malloc( len + 1 ); + fseek( f, 0, SEEK_SET ); + fread( buf, len, 1, f ); + buf[len] = 0; + fclose( f ); + + strcpy( path, func_filename ); + if ( f = fopen( path, "rb" ) ) { + fseek( f, 0, SEEK_END ); + newlen = ftell( f ); + newbuf = (unsigned char *) malloc( newlen + 1 ); + fseek( f, 0, SEEK_SET ); + fread( newbuf, newlen, 1, f ); + newbuf[newlen] = 0; + fclose( f ); + + if ( len != newlen || Q_stricmp( buf, newbuf ) ) { + char newpath[_MAX_PATH]; + + // delete the old file, rename the new one + strcpy( path, func_filename ); + remove( path ); + + strcpy( newpath, "g_funcs.tmp" ); + rename( newpath, path ); + + // make g_save recompile itself + remove( "debug\\g_save.obj" ); + remove( "debug\\g_save.sbr" ); + remove( "release\\g_save.obj" ); + remove( "release\\g_save.sbr" ); + + updated = 1; + } else { + // delete the old file + strcpy( path, "g_funcs.tmp" ); + remove( path ); + } + } else { + rename( "g_funcs.tmp", func_filename ); + } + + free( buf ); + free( newbuf ); + + // dump the function declarations + strcpy( path, "g_func_decs.tmp" ); + Log_Open( path ); + for ( rf = replacefuncs; rf; rf = rf->next ) + { + Log_Print( "extern %s;\n", rf->dec ); + } //end for + Log_Close(); + + // if it's different, rename the file over the real header + strcpy( path, "g_func_decs.tmp" ); + f = fopen( path, "rb" ); + fseek( f, 0, SEEK_END ); + len = ftell( f ); + buf = (unsigned char *) malloc( len + 1 ); + fseek( f, 0, SEEK_SET ); + fread( buf, len, 1, f ); + buf[len] = 0; + fclose( f ); + + strcpy( path, func_filedesc ); + if ( f = fopen( path, "rb" ) ) { + fseek( f, 0, SEEK_END ); + newlen = ftell( f ); + newbuf = (unsigned char *) malloc( newlen + 1 ); + fseek( f, 0, SEEK_SET ); + fread( newbuf, newlen, 1, f ); + newbuf[newlen] = 0; + fclose( f ); + + if ( len != newlen || Q_stricmp( buf, newbuf ) ) { + char newpath[_MAX_PATH]; + + // delete the old file, rename the new one + strcpy( path, func_filedesc ); + remove( path ); + + strcpy( newpath, "g_func_decs.tmp" ); + rename( newpath, path ); + + // make g_save recompile itself + // NOTE TTimo win32 only? (harmless on *nix anyway) + remove( "debug\\g_save.obj" ); + remove( "debug\\g_save.sbr" ); + remove( "release\\g_save.obj" ); + remove( "release\\g_save.sbr" ); + + updated = 1; + } else { + // delete the old file + strcpy( path, "g_func_decs.tmp" ); + remove( path ); + } + } else { + rename( "g_func_decs.tmp", func_filedesc ); + } + + free( buf ); + free( newbuf ); + + if ( updated ) { + printf( "Updated the function table, recompile required.\n" ); + } + +} //end of the function DumpReplaceFunctions + +replacefunc_t *FindFunctionName( char *funcname ) { + replacefunc_t *f; + + for ( f = replacefuncs; f; f = f->next ) + { + if ( !strcmp( f->name, funcname ) ) { + return f; + } + } //end for + return NULL; +} //end of the function FindFunctionName + +int MayScrewUp( char *funcname ) { + if ( !strcmp( funcname, "GetBotAPI" ) ) { + return false; + } + if ( !strcmp( funcname, "main" ) ) { + return false; + } + if ( !strcmp( funcname, "WinMain" ) ) { + return false; + } + return true; +} //end of the function MayScrewUp + +typedef struct tokenList_s { + token_t token; + struct tokenList_s *next; +} tokenList_t; + +#define MAX_TOKEN_LIST 64 +tokenList_t tokenList[MAX_TOKEN_LIST]; +int tokenListHead = 0; + +void ConcatDec( tokenList_t *list, char *str, int inc ) { +/* + if (!((list->token.type == TT_NAME) || (list->token.string[0] == '*'))) { + if (list->token.string[0] == ')' || list->token.string[0] == '(') { + if (inc++ >= 2) + return; + } else { + return; + } + } +*/ + if ( list->next ) { + ConcatDec( list->next, str, inc ); + } + strcat( str, list->token.string ); + strcat( str, " " ); +} + +void AddFunctionName( char *funcname, char *filename, tokenList_t *head ) { + replacefunc_t *f; + tokenList_t *list; + + if ( FindFunctionName( funcname ) ) { + return; + } + +#if defined( __linux__ ) + // the bad thing is, this doesn't preprocess .. on __linux__ this + // function is not implemented (q_math.c) + if ( !Q_stricmp( funcname, "BoxOnPlaneSide" ) ) { + return; + } +#endif + + // NERVE - SMF - workaround for Graeme's predifined MACOSX functions + // TTimo - looks like linux version needs to escape those too +#if defined( _WIN32 ) || defined( __linux__ ) + if ( !Q_stricmp( funcname, "qmax" ) ) { + return; + } else if ( !Q_stricmp( funcname, "qmin" ) ) { + return; + } +#endif + // -NERVE - SMF + + f = (replacefunc_t *) GetMemory( sizeof( replacefunc_t ) + strlen( funcname ) + 1 + 6 + strlen( filename ) + 1 ); + f->name = (char *) f + sizeof( replacefunc_t ); + strcpy( f->name, funcname ); + f->newname = (char *) f + sizeof( replacefunc_t ) + strlen( funcname ) + 1; + sprintf( f->newname, "F%d", numfuncs++ ); + f->filename = (char *) f + sizeof( replacefunc_t ) + strlen( funcname ) + 1 + strlen( f->newname ) + 1; + strcpy( f->filename, filename ); + f->next = replacefuncs; + replacefuncs = f; + + // construct the declaration + list = head; + f->dec[0] = '\0'; + ConcatDec( list, f->dec, 0 ); + +} //end of the function AddFunctionName + +void AddTokenToList( tokenList_t **head, token_t *token ) { + tokenList_t *newhead; + + newhead = &tokenList[tokenListHead++]; //GetMemory( sizeof( tokenList_t ) ); + if ( tokenListHead == MAX_TOKEN_LIST ) { + tokenListHead = 0; + } + + newhead->next = *head; + newhead->token = *token; + + *head = newhead; +} +/* +void KillTokenList( tokenList_t *head ) +{ + if (head->next) { + KillTokenList( head->next ); + FreeMemory( head->next ); + head->next = NULL; + } +} +*/ +void StripTokenList( tokenList_t *head ) { + tokenList_t *trav, *lastTrav; + + trav = head; + + // now go back to the start of the declaration + lastTrav = trav; + trav = trav->next; // should be on the function name now + while ( ( trav->token.type == TT_NAME ) || ( trav->token.string[0] == '*' ) ) { + lastTrav = trav; + trav = trav->next; + if ( !trav ) { + return; + } + } + // now kill everything after lastTrav +// KillTokenList( lastTrav ); + lastTrav->next = NULL; +} + +void GetFunctionNamesFromFile( char *filename ) { + source_t *source; + token_t token, lasttoken; + int indent = 0, brace; + int isStatic = 0; + tokenList_t *listHead; + + // filter some files out + if ( !Q_stricmp( filename, "bg_lib.c" ) ) { + return; + } + + listHead = NULL; + source = LoadSourceFile( filename ); + if ( !source ) { + Error( "error opening %s", filename ); + return; + } //end if +// printf("loaded %s\n", filename); +// if (!PC_ReadToken(source, &lasttoken)) +// { +// FreeSource(source); +// return; +// } //end if + while ( 1 ) + { + if ( !PC_ReadToken( source, &token ) ) { + break; + } + AddTokenToList( &listHead, &token ); + if ( token.type == TT_PUNCTUATION ) { + switch ( token.string[0] ) + { + case ';': + { + isStatic = 0; + break; + } + case '{': + { + indent++; + break; + } //end case + case '}': + { + indent--; + if ( indent < 0 ) { + indent = 0; + } + break; + } //end case + case '(': + { + if ( indent <= 0 && lasttoken.type == TT_NAME ) { + StripTokenList( listHead ); + + brace = 1; + while ( PC_ReadToken( source, &token ) ) + { + AddTokenToList( &listHead, &token ); + if ( token.string[0] == '(' ) { + brace++; + } //end if + else if ( token.string[0] == ')' ) { + brace--; + if ( brace <= 0 ) { + if ( !PC_ReadToken( source, &token ) ) { + break; + } + if ( token.string[0] == '{' ) { + indent++; + if ( !isStatic && MayScrewUp( lasttoken.string ) ) { + AddFunctionName( lasttoken.string, filename, listHead ); + } //end if + } //end if + break; + } //end if + } //end if + } //end while + } //end if + break; + } //end case + } //end if + } //end switch + if ( token.type == TT_NAME ) { + if ( token.string[0] == 's' && !strcmp( token.string, "static" ) ) { + isStatic = 1; + } + } + memcpy( &lasttoken, &token, sizeof( token_t ) ); + } //end while + FreeSource( source ); +} //end of the function GetFunctionNamesFromFile + +void WriteWhiteSpace( FILE *fp, script_t *script ) { + int c; + //write out the white space + c = PS_NextWhiteSpaceChar( script ); + while ( c ) + { + //NOTE: do NOT write out carriage returns (for unix/linux compatibility + if ( c != 13 ) { + fputc( c, fp ); + } + c = PS_NextWhiteSpaceChar( script ); + } //end while +} //end of the function WriteWhiteSpace + +void WriteString( FILE *fp, script_t *script ) { + char *ptr; + + ptr = script->endwhitespace_p; + while ( ptr < script->script_p ) + { + fputc( *ptr, fp ); + ptr++; + } //end while +} //end of the function WriteString + +void ScrewUpFile( char *oldfile, char *newfile ) { + FILE *fp; + script_t *script; + token_t token; + replacefunc_t *f; + char *ptr; + + printf( "screwing up file %s\n", oldfile ); + script = LoadScriptFile( oldfile ); + if ( !script ) { + Error( "error opening %s\n", oldfile ); + } + fp = fopen( newfile, "wb" ); + if ( !fp ) { + Error( "error opening %s\n", newfile ); + } + // + while ( PS_ReadToken( script, &token ) ) + { + WriteWhiteSpace( fp, script ); + if ( token.type == TT_NAME ) { + f = FindFunctionName( token.string ); + if ( f ) { + ptr = f->newname; + } else { ptr = token.string;} + while ( *ptr ) + { + fputc( *ptr, fp ); + ptr++; + } //end while + } //end if + else + { + WriteString( fp, script ); + } //end else + } //end while + WriteWhiteSpace( fp, script ); + FreeMemory( script ); + fclose( fp ); +} //end of the function ScrewUpFile + +int verbose = 0; + +#ifdef _WIN32 + +void main( int argc, char *argv[] ) { + WIN32_FIND_DATA filedata; + HWND handle; + int done; //, i; + + if ( argc < 2 ) { + Error( "USAGE: screwup \n" ); + } //end if + + handle = FindFirstFile( argv[1], &filedata ); + done = ( handle == INVALID_HANDLE_VALUE ); + while ( !done ) + { + if ( !( filedata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) ) { + // + GetFunctionNamesFromFile( filedata.cFileName ); + } //end if + //find the next file + done = !FindNextFile( handle, &filedata ); + } //end while + DumpReplaceFunctions(); +} //end of the function main + +#else + +void Usage() { + Error( "USAGE: screwup [-o ] [ ..]\n" + "no -o defaults to g_funcs.h g_func_decs.h\n" ); +} + +/* +*nix version, let the shell do the pattern matching +(that's what shells are for :-)) +*/ +int main( int argc, char *argv[] ) { + int i; + int argbase = 1; + + if ( argc < 2 ) { + Usage(); + } //end if + + if ( !Q_stricmp( argv[1],"-o" ) ) { + if ( argc < 5 ) { + Usage(); + } + func_filename = argv[2]; + func_filedesc = argv[3]; + argbase = 4; + } + + for ( i = argbase; i < argc; i++ ) + { + printf( "%d: %s\n", i, argv[i] ); + GetFunctionNamesFromFile( argv[i] ); + } + DumpReplaceFunctions(); +} + +#endif diff --git a/Projects/Android/jni/rtcw/src/extractfuncs/extractfuncs.vcproj b/Projects/Android/jni/rtcw/src/extractfuncs/extractfuncs.vcproj new file mode 100644 index 0000000..675a468 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/extractfuncs/extractfuncs.vcproj @@ -0,0 +1,428 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Projects/Android/jni/rtcw/src/extractfuncs/extractfuncs.vcxproj b/Projects/Android/jni/rtcw/src/extractfuncs/extractfuncs.vcxproj new file mode 100644 index 0000000..a479e54 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/extractfuncs/extractfuncs.vcxproj @@ -0,0 +1,170 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {0FC559FD-6DCD-4A81-B286-688F79286AEF} + + + + Application + v110 + false + MultiByte + + + Application + v110 + false + MultiByte + + + + + + + + + + + + + + + <_ProjectFileVersion>11.0.50727.1 + + + .\Debug\ + .\Debug\ + true + + + .\Release\ + .\Release\ + false + + + + .\Debug/extractfuncs.tlb + + + + Disabled + WIN32;_DEBUG;_CONSOLE;SCREWUP;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + MultiThreadedDebug + .\Debug/extractfuncs.pch + .\Debug/ + .\Debug/ + .\Debug/ + true + Level3 + true + EditAndContinue + + + _DEBUG;%(PreprocessorDefinitions) + 0x0409 + + + extractfuncs.exe + true + true + true + .\Debug/extractfuncs.map + Console + false + + MachineX86 + + + true + .\Debug/extractfuncs.bsc + + + + + .\Release/extractfuncs.tlb + + + + MaxSpeed + OnlyExplicitInline + WIN32;NDEBUG;_CONSOLE;SCREWUP;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + true + MultiThreaded + true + .\Release/extractfuncs.pch + .\Release/ + .\Release/ + .\Release/ + Level3 + true + + + NDEBUG;%(PreprocessorDefinitions) + 0x0409 + + + extractfuncs.exe + true + .\Release/extractfuncs.pdb + Console + false + + MachineX86 + + + true + .\Release/extractfuncs.bsc + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + true + + + + + + \ No newline at end of file diff --git a/Projects/Android/jni/rtcw/src/extractfuncs/extractfuncs.vcxproj.filters b/Projects/Android/jni/rtcw/src/extractfuncs/extractfuncs.vcxproj.filters new file mode 100644 index 0000000..e34d431 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/extractfuncs/extractfuncs.vcxproj.filters @@ -0,0 +1,110 @@ + + + + + {e328a37f-5a99-44cc-a509-82c4e395dfed} + cpp;c;cxx;rc;def;r;odl;idl;hpj;bat + + + {ad952143-bab1-4eb3-a62b-d9600fff0d1c} + h;hpp;hxx;hm;inl + + + {d67a8e30-9c5a-48af-98e3-3f1c53eaa9cb} + ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe + + + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + + + Source Files + + + \ No newline at end of file diff --git a/Projects/Android/jni/rtcw/src/extractfuncs/l_log.c b/Projects/Android/jni/rtcw/src/extractfuncs/l_log.c new file mode 100644 index 0000000..afa0072 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/extractfuncs/l_log.c @@ -0,0 +1,199 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +//=========================================================================== +// +// Name: l_log.c +// Function: log file stuff +// Programmer: Mr Elusive (MrElusive@demigod.demon.nl) +// Last update: 1997-12-31 +// Tab Size: 3 +//=========================================================================== + +#include +#include +#include + +#define MAX_QPATH 64 +#include "../bspc/qbsp.h" + +#define MAX_LOGFILENAMESIZE 1024 + +typedef struct logfile_s +{ + char filename[MAX_LOGFILENAMESIZE]; + FILE *fp; + int numwrites; +} logfile_t; + +logfile_t logfile; + +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void Log_Open( char *filename ) { + if ( !filename || !strlen( filename ) ) { + printf( "openlog \n" ); + return; + } //end if + if ( logfile.fp ) { + printf( "log file %s is already opened\n", logfile.filename ); + return; + } //end if + logfile.fp = fopen( filename, "wb" ); + if ( !logfile.fp ) { + printf( "can't open the log file %s\n", filename ); + return; + } //end if + strncpy( logfile.filename, filename, MAX_LOGFILENAMESIZE ); +// printf("Opened log %s\n", logfile.filename); +} //end of the function Log_Create +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void Log_Close( void ) { + if ( !logfile.fp ) { + printf( "no log file to close\n" ); + return; + } //end if + if ( fclose( logfile.fp ) ) { + printf( "can't close log file %s\n", logfile.filename ); + return; + } //end if + logfile.fp = NULL; +// printf("Closed log %s\n", logfile.filename); +} //end of the function Log_Close +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void Log_Shutdown( void ) { + if ( logfile.fp ) { + Log_Close(); + } +} //end of the function Log_Shutdown +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void Log_Print( char *fmt, ... ) { + va_list ap; +#ifdef WINBSPC + char buf[2048]; +#endif //WINBSPC + + if ( verbose ) { + va_start( ap, fmt ); +#ifdef WINBSPC + vsprintf( buf, fmt, ap ); + WinBSPCPrint( buf ); +#else + vprintf( fmt, ap ); +#endif //WINBSPS + va_end( ap ); + } //end if + + va_start( ap, fmt ); + if ( logfile.fp ) { + vfprintf( logfile.fp, fmt, ap ); + fflush( logfile.fp ); + } //end if + va_end( ap ); +} //end of the function Log_Print +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void Log_Write( char *fmt, ... ) { + va_list ap; + + if ( !logfile.fp ) { + return; + } + va_start( ap, fmt ); + vfprintf( logfile.fp, fmt, ap ); + va_end( ap ); + fflush( logfile.fp ); +} //end of the function Log_Write +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void Log_WriteTimeStamped( char *fmt, ... ) { + va_list ap; + + if ( !logfile.fp ) { + return; + } +/* fprintf(logfile.fp, "%d %02d:%02d:%02d:%02d ", + logfile.numwrites, + (int) (botlibglobals.time / 60 / 60), + (int) (botlibglobals.time / 60), + (int) (botlibglobals.time), + (int) ((int) (botlibglobals.time * 100)) - + ((int) botlibglobals.time) * 100);*/ + va_start( ap, fmt ); + vfprintf( logfile.fp, fmt, ap ); + va_end( ap ); + logfile.numwrites++; + fflush( logfile.fp ); +} //end of the function Log_Write +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +FILE *Log_FileStruct( void ) { + return logfile.fp; +} //end of the function Log_FileStruct +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void Log_Flush( void ) { + if ( logfile.fp ) { + fflush( logfile.fp ); + } +} //end of the function Log_Flush diff --git a/Projects/Android/jni/rtcw/src/extractfuncs/l_log.h b/Projects/Android/jni/rtcw/src/extractfuncs/l_log.h new file mode 100644 index 0000000..b1f6c1b --- /dev/null +++ b/Projects/Android/jni/rtcw/src/extractfuncs/l_log.h @@ -0,0 +1,59 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +//=========================================================================== +// +// Name: l_log.h +// Function: log file stuff +// Programmer: Mr Elusive (MrElusive@demigod.demon.nl) +// Last update: 1997-12-31 +// Tab Size: 3 +//=========================================================================== + +//open a log file +void Log_Open( char *filename ); +//close the current log file +void Log_Close( void ); +//close log file if present +void Log_Shutdown( void ); +//print on stdout and write to the current opened log file +void Log_Print( char *fmt, ... ); +//write to the current opened log file +void Log_Write( char *fmt, ... ); +//write to the current opened log file with a time stamp +void Log_WriteTimeStamped( char *fmt, ... ); +//returns the log file structure +FILE *Log_FileStruct( void ); +//flush log file +void Log_Flush( void ); + +int Log_Written( void ); + +#ifdef WINBSPC +void WinBSPCPrint( char *str ); +#endif //WINBSPC diff --git a/Projects/Android/jni/rtcw/src/extractfuncs/l_memory.c b/Projects/Android/jni/rtcw/src/extractfuncs/l_memory.c new file mode 100644 index 0000000..71526c0 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/extractfuncs/l_memory.c @@ -0,0 +1,444 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +/***************************************************************************** + * name: l_memory.c + * + * desc: memory allocation + * + * + *****************************************************************************/ + +#include "../game/q_shared.h" +#include "../game/botlib.h" +#include "l_log.h" +#include "../../src/botlib/be_interface.h" + +//#define MEMDEBUG +//#define MEMORYMANEGER + +#define MEM_ID 0x12345678l +#define HUNK_ID 0x87654321l + +int allocatedmemory; +int totalmemorysize; +int numblocks; + +#ifdef MEMORYMANEGER + +typedef struct memoryblock_s +{ + unsigned long int id; + void *ptr; + int size; +#ifdef MEMDEBUG + char *label; + char *file; + int line; +#endif //MEMDEBUG + struct memoryblock_s *prev, *next; +} memoryblock_t; + +memoryblock_t *memory; + +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void LinkMemoryBlock( memoryblock_t *block ) { + block->prev = NULL; + block->next = memory; + if ( memory ) { + memory->prev = block; + } + memory = block; +} //end of the function LinkMemoryBlock +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void UnlinkMemoryBlock( memoryblock_t *block ) { + if ( block->prev ) { + block->prev->next = block->next; + } else { memory = block->next;} + if ( block->next ) { + block->next->prev = block->prev; + } +} //end of the function UnlinkMemoryBlock +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +#ifdef MEMDEBUG +void *GetMemoryDebug( unsigned long size, char *label, char *file, int line ) +#else +void *GetMemory( unsigned long size ) +#endif //MEMDEBUG +{ + void *ptr; + memoryblock_t *block; + + ptr = malloc( size + sizeof( memoryblock_t ) ); + block = (memoryblock_t *) ptr; + block->id = MEM_ID; + block->ptr = (char *) ptr + sizeof( memoryblock_t ); + block->size = size + sizeof( memoryblock_t ); +#ifdef MEMDEBUG + block->label = label; + block->file = file; + block->line = line; +#endif //MEMDEBUG + LinkMemoryBlock( block ); + allocatedmemory += block->size; + totalmemorysize += block->size + sizeof( memoryblock_t ); + numblocks++; + return block->ptr; +} //end of the function GetMemoryDebug +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +#ifdef MEMDEBUG +void *GetClearedMemoryDebug( unsigned long size, char *label, char *file, int line ) +#else +void *GetClearedMemory( unsigned long size ) +#endif //MEMDEBUG +{ + void *ptr; +#ifdef MEMDEBUG + ptr = GetMemoryDebug( size, label, file, line ); +#else + ptr = GetMemory( size ); +#endif //MEMDEBUG + memset( ptr, 0, size ); + return ptr; +} //end of the function GetClearedMemory +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +#ifdef MEMDEBUG +void *GetHunkMemoryDebug( unsigned long size, char *label, char *file, int line ) +#else +void *GetHunkMemory( unsigned long size ) +#endif //MEMDEBUG +{ + void *ptr; + memoryblock_t *block; + + ptr = malloc( size + sizeof( memoryblock_t ) ); + block = (memoryblock_t *) ptr; + block->id = HUNK_ID; + block->ptr = (char *) ptr + sizeof( memoryblock_t ); + block->size = size + sizeof( memoryblock_t ); +#ifdef MEMDEBUG + block->label = label; + block->file = file; + block->line = line; +#endif //MEMDEBUG + LinkMemoryBlock( block ); + allocatedmemory += block->size; + totalmemorysize += block->size + sizeof( memoryblock_t ); + numblocks++; + return block->ptr; +} //end of the function GetHunkMemoryDebug +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +#ifdef MEMDEBUG +void *GetClearedHunkMemoryDebug( unsigned long size, char *label, char *file, int line ) +#else +void *GetClearedHunkMemory( unsigned long size ) +#endif //MEMDEBUG +{ + void *ptr; +#ifdef MEMDEBUG + ptr = GetHunkMemoryDebug( size, label, file, line ); +#else + ptr = GetHunkMemory( size ); +#endif //MEMDEBUG + memset( ptr, 0, size ); + return ptr; +} //end of the function GetClearedHunkMemory +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +memoryblock_t *BlockFromPointer( void *ptr, char *str ) { + memoryblock_t *block; + + if ( !ptr ) { +#ifdef MEMDEBUG + //char *crash = (char *) NULL; + //crash[0] = 1; + printf( PRT_FATAL, "%s: NULL pointer\n", str ); +#endif MEMDEBUG + return NULL; + } //end if + block = ( memoryblock_t * )( (char *) ptr - sizeof( memoryblock_t ) ); + if ( block->id != MEM_ID && block->id != HUNK_ID ) { + printf( PRT_FATAL, "%s: invalid memory block\n", str ); + return NULL; + } //end if + if ( block->ptr != ptr ) { + printf( PRT_FATAL, "%s: memory block pointer invalid\n", str ); + return NULL; + } //end if + return block; +} //end of the function BlockFromPointer +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void FreeMemory( void *ptr ) { + memoryblock_t *block; + + block = BlockFromPointer( ptr, "FreeMemory" ); + if ( !block ) { + return; + } + UnlinkMemoryBlock( block ); + allocatedmemory -= block->size; + totalmemorysize -= block->size + sizeof( memoryblock_t ); + numblocks--; + // + if ( block->id == MEM_ID ) { + free( block ); + } //end if +} //end of the function FreeMemory +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int MemoryByteSize( void *ptr ) { + memoryblock_t *block; + + block = BlockFromPointer( ptr, "MemoryByteSize" ); + if ( !block ) { + return 0; + } + return block->size; +} //end of the function MemoryByteSize +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void PrintUsedMemorySize( void ) { + printf( PRT_MESSAGE, "total allocated memory: %d KB\n", allocatedmemory >> 10 ); + printf( PRT_MESSAGE, "total botlib memory: %d KB\n", totalmemorysize >> 10 ); + printf( PRT_MESSAGE, "total memory blocks: %d\n", numblocks ); +} //end of the function PrintUsedMemorySize +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void PrintMemoryLabels( void ) { + memoryblock_t *block; + int i; + + PrintUsedMemorySize(); + i = 0; + Log_Write( "\r\n" ); + for ( block = memory; block; block = block->next ) + { +#ifdef MEMDEBUG + if ( block->id == HUNK_ID ) { + Log_Write( "%6d, hunk %p, %8d: %24s line %6d: %s\r\n", i, block->ptr, block->size, block->file, block->line, block->label ); + } //end if + else + { + Log_Write( "%6d, %p, %8d: %24s line %6d: %s\r\n", i, block->ptr, block->size, block->file, block->line, block->label ); + } //end else +#endif //MEMDEBUG + i++; + } //end for +} //end of the function PrintMemoryLabels +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void DumpMemory( void ) { + memoryblock_t *block; + + for ( block = memory; block; block = memory ) + { + FreeMemory( block->ptr ); + } //end for + totalmemorysize = 0; + allocatedmemory = 0; +} //end of the function DumpMemory + +#else + +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +#ifdef MEMDEBUG +void *GetMemoryDebug( unsigned long size, char *label, char *file, int line ) +#else +void *GetMemory( unsigned long size ) +#endif //MEMDEBUG +{ + void *ptr; + unsigned long int *memid; + + ptr = malloc( size + sizeof( unsigned long int ) ); + if ( !ptr ) { + return NULL; + } + memid = (unsigned long int *) ptr; + *memid = MEM_ID; + return (unsigned long int *) ( (char *) ptr + sizeof( unsigned long int ) ); +} //end of the function GetMemory +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +#ifdef MEMDEBUG +void *GetClearedMemoryDebug( unsigned long size, char *label, char *file, int line ) +#else +void *GetClearedMemory( unsigned long size ) +#endif //MEMDEBUG +{ + void *ptr; +#ifdef MEMDEBUG + ptr = GetMemoryDebug( size, label, file, line ); +#else +ptr = GetMemory( size ); +#endif //MEMDEBUG +memset( ptr, 0, size ); +return ptr; +} //end of the function GetClearedMemory +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +#ifdef MEMDEBUG +void *GetHunkMemoryDebug( unsigned long size, char *label, char *file, int line ) +#else +void *GetHunkMemory( unsigned long size ) +#endif //MEMDEBUG +{ + void *ptr; + unsigned long int *memid; + + ptr = malloc( size + sizeof( unsigned long int ) ); + if ( !ptr ) { + return NULL; + } + memid = (unsigned long int *) ptr; + *memid = HUNK_ID; + return (unsigned long int *) ( (char *) ptr + sizeof( unsigned long int ) ); +} //end of the function GetHunkMemory +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +#ifdef MEMDEBUG +void *GetClearedHunkMemoryDebug( unsigned long size, char *label, char *file, int line ) +#else +void *GetClearedHunkMemory( unsigned long size ) +#endif //MEMDEBUG +{ + void *ptr; +#ifdef MEMDEBUG + ptr = GetHunkMemoryDebug( size, label, file, line ); +#else +ptr = GetHunkMemory( size ); +#endif //MEMDEBUG +memset( ptr, 0, size ); +return ptr; +} //end of the function GetClearedHunkMemory +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void FreeMemory( void *ptr ) { + unsigned long int *memid; + + memid = (unsigned long int *) ( (char *) ptr - sizeof( unsigned long int ) ); + + if ( *memid == MEM_ID ) { + free( memid ); + } //end if +} //end of the function FreeMemory +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void PrintUsedMemorySize( void ) { +} //end of the function PrintUsedMemorySize +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void PrintMemoryLabels( void ) { +} //end of the function PrintMemoryLabels + +#endif diff --git a/Projects/Android/jni/rtcw/src/extractfuncs/l_memory.h b/Projects/Android/jni/rtcw/src/extractfuncs/l_memory.h new file mode 100644 index 0000000..c33d715 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/extractfuncs/l_memory.h @@ -0,0 +1,80 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +/***************************************************************************** + * name: l_memory.h + * + * desc: memory management + * + * + *****************************************************************************/ + +//#define MEMDEBUG + +#ifdef MEMDEBUG +#define GetMemory( size ) GetMemoryDebug( size, # size, __FILE__, __LINE__ ); +#define GetClearedMemory( size ) GetClearedMemoryDebug( size, # size, __FILE__, __LINE__ ); +//allocate a memory block of the given size +void *GetMemoryDebug( unsigned long size, char *label, char *file, int line ); +//allocate a memory block of the given size and clear it +void *GetClearedMemoryDebug( unsigned long size, char *label, char *file, int line ); +// +#define GetHunkMemory( size ) GetHunkMemoryDebug( size, # size, __FILE__, __LINE__ ); +#define GetClearedHunkMemory( size ) GetClearedHunkMemoryDebug( size, # size, __FILE__, __LINE__ ); +//allocate a memory block of the given size +void *GetHunkMemoryDebug( unsigned long size, char *label, char *file, int line ); +//allocate a memory block of the given size and clear it +void *GetClearedHunkMemoryDebug( unsigned long size, char *label, char *file, int line ); +#else +//allocate a memory block of the given size +void *GetMemory( unsigned long size ); +//allocate a memory block of the given size and clear it +void *GetClearedMemory( unsigned long size ); +// +#ifdef BSPC +#define GetHunkMemory GetMemory +#define GetClearedHunkMemory GetClearedMemory +#else +//allocate a memory block of the given size +void *GetHunkMemory( unsigned long size ); +//allocate a memory block of the given size and clear it +void *GetClearedHunkMemory( unsigned long size ); +#endif +#endif + +//free the given memory block +void FreeMemory( void *ptr ); +//prints the total used memory size +void PrintUsedMemorySize( void ); +//print all memory blocks with label +void PrintMemoryLabels( void ); +//returns the size of the memory block in bytes +int MemoryByteSize( void *ptr ); +//free all allocated memory +void DumpMemory( void ); diff --git a/Projects/Android/jni/rtcw/src/extractfuncs/l_precomp.c b/Projects/Android/jni/rtcw/src/extractfuncs/l_precomp.c new file mode 100644 index 0000000..23be10c --- /dev/null +++ b/Projects/Android/jni/rtcw/src/extractfuncs/l_precomp.c @@ -0,0 +1,3167 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +/***************************************************************************** + * name: l_precomp.c + * + * desc: pre compiler + * + * + *****************************************************************************/ + +//Notes: fix: PC_StringizeTokens + +#ifdef SCREWUP +#include +#include +#include +#include +#include +#include +#include +#include "l_memory.h" +#include "l_script.h" +#include "l_precomp.h" +#include "l_log.h" + +typedef enum {qfalse, qtrue} qboolean; + +// Ridah, ripped from q_shared.c +/* +============= +Q_strncpyz + +Safe strncpy that ensures a trailing zero +============= +*/ +extern void Error( char *error, ... ); +void Q_strncpyz( char *dest, const char *src, int destsize ) { + if ( !src ) { + Error( "Q_strncpyz: NULL src" ); + } + if ( destsize < 1 ) { + Error( "Q_strncpyz: destsize < 1" ); + } + + strncpy( dest, src, destsize - 1 ); + dest[destsize - 1] = 0; +} + +int Q_stricmpn( const char *s1, const char *s2, int n ) { + int c1, c2; + + do { + c1 = *s1++; + c2 = *s2++; + + if ( !n-- ) { + return 0; // strings are equal until end point + } + + if ( c1 != c2 ) { + if ( c1 >= 'a' && c1 <= 'z' ) { + c1 -= ( 'a' - 'A' ); + } + if ( c2 >= 'a' && c2 <= 'z' ) { + c2 -= ( 'a' - 'A' ); + } + if ( c1 != c2 ) { + return c1 < c2 ? -1 : 1; + } + } + } while ( c1 ); + + return 0; // strings are equal +} + +int Q_strncmp( const char *s1, const char *s2, int n ) { + int c1, c2; + + do { + c1 = *s1++; + c2 = *s2++; + + if ( !n-- ) { + return 0; // strings are equal until end point + } + + if ( c1 != c2 ) { + return c1 < c2 ? -1 : 1; + } + } while ( c1 ); + + return 0; // strings are equal +} + +int Q_stricmp( const char *s1, const char *s2 ) { + return Q_stricmpn( s1, s2, 99999 ); +} + + +char *Q_strlwr( char *s1 ) { + char *s; + + s = s1; + while ( *s ) { + *s = tolower( *s ); + s++; + } + return s1; +} + +char *Q_strupr( char *s1 ) { + char *s; + + s = s1; + while ( *s ) { + *s = toupper( *s ); + s++; + } + return s1; +} + +#endif //SCREWUP + +#ifdef BOTLIB +#include "../game/q_shared.h" +#include "botlib.h" +#include "be_interface.h" +#include "l_memory.h" +#include "l_script.h" +#include "l_precomp.h" +#include "l_log.h" +#endif //BOTLIB + +#ifdef MEQCC +#include "qcc.h" +#include "time.h" //time & ctime +#include "math.h" //fabs +#include "l_memory.h" +#include "l_script.h" +#include "l_precomp.h" +#include "l_log.h" + +#define qtrue true +#define qfalse false +#endif //MEQCC + +#ifdef BSPC +//include files for usage in the BSP Converter +#include "../bspc/qbsp.h" +#include "../bspc/l_log.h" +#include "../bspc/l_mem.h" +#include "l_precomp.h" + +#define qtrue true +#define qfalse false +#define Q_stricmp stricmp +#endif //BSPC + +#if defined( QUAKE ) && !defined( BSPC ) +#include "l_utils.h" +#endif //QUAKE + +//#define DEBUG_EVAL + +#define MAX_DEFINEPARMS 128 + +#define DEFINEHASHING 1 + +//directive name with parse function +typedef struct directive_s +{ + char *name; + int ( *func )( source_t *source ); +} directive_t; + +#define DEFINEHASHSIZE 1024 + +#define TOKEN_HEAP_SIZE 4096 + +int numtokens; +/* +int tokenheapinitialized; //true when the token heap is initialized +token_t token_heap[TOKEN_HEAP_SIZE]; //heap with tokens +token_t *freetokens; //free tokens from the heap +*/ + +//list with global defines added to every source loaded +define_t *globaldefines; + +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void QDECL SourceError( source_t *source, char *str, ... ) { + char text[1024]; + va_list ap; + + va_start( ap, str ); + vsprintf( text, str, ap ); + va_end( ap ); +#ifdef BOTLIB + botimport.Print( PRT_ERROR, "file %s, line %d: %s\n", source->scriptstack->filename, source->scriptstack->line, text ); +#endif //BOTLIB +#ifdef MEQCC + printf( "error: file %s, line %d: %s\n", source->scriptstack->filename, source->scriptstack->line, text ); +#endif //MEQCC +#ifdef BSPC + Log_Print( "error: file %s, line %d: %s\n", source->scriptstack->filename, source->scriptstack->line, text ); +#endif //BSPC +} //end of the function SourceError +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void QDECL SourceWarning( source_t *source, char *str, ... ) { + char text[1024]; + va_list ap; + + va_start( ap, str ); + vsprintf( text, str, ap ); + va_end( ap ); +#ifdef BOTLIB + botimport.Print( PRT_WARNING, "file %s, line %d: %s\n", source->scriptstack->filename, source->scriptstack->line, text ); +#endif //BOTLIB +#ifdef MEQCC + printf( "warning: file %s, line %d: %s\n", source->scriptstack->filename, source->scriptstack->line, text ); +#endif //MEQCC +#ifdef BSPC + Log_Print( "warning: file %s, line %d: %s\n", source->scriptstack->filename, source->scriptstack->line, text ); +#endif //BSPC +} //end of the function ScriptWarning +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void PC_PushIndent( source_t *source, int type, int skip ) { + indent_t *indent; + + indent = (indent_t *) GetMemory( sizeof( indent_t ) ); + indent->type = type; + indent->script = source->scriptstack; + indent->skip = ( skip != 0 ); + source->skip += indent->skip; + indent->next = source->indentstack; + source->indentstack = indent; +} //end of the function PC_PushIndent +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void PC_PopIndent( source_t *source, int *type, int *skip ) { + indent_t *indent; + + *type = 0; + *skip = 0; + + indent = source->indentstack; + if ( !indent ) { + return; + } + + //must be an indent from the current script + if ( source->indentstack->script != source->scriptstack ) { + return; + } + + *type = indent->type; + *skip = indent->skip; + source->indentstack = source->indentstack->next; + source->skip -= indent->skip; + FreeMemory( indent ); +} //end of the function PC_PopIndent +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void PC_PushScript( source_t *source, script_t *script ) { + script_t *s; + + for ( s = source->scriptstack; s; s = s->next ) + { + if ( !Q_stricmp( s->filename, script->filename ) ) { + SourceError( source, "%s recursively included", script->filename ); + return; + } //end if + } //end for + //push the script on the script stack + script->next = source->scriptstack; + source->scriptstack = script; +} //end of the function PC_PushScript +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void PC_InitTokenHeap( void ) { + /* + int i; + + if (tokenheapinitialized) return; + freetokens = NULL; + for (i = 0; i < TOKEN_HEAP_SIZE; i++) + { + token_heap[i].next = freetokens; + freetokens = &token_heap[i]; + } //end for + tokenheapinitialized = qtrue; + */ +} //end of the function PC_InitTokenHeap +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +token_t *PC_CopyToken( token_t *token ) { + token_t *t; + +// t = (token_t *) malloc(sizeof(token_t)); + t = (token_t *) GetMemory( sizeof( token_t ) ); +// t = freetokens; + if ( !t ) { +#ifdef BSPC + Error( "out of token space\n" ); +#else +#ifdef SCREWUP + Error( "out of token space\n" ); +#else + Com_Error( ERR_FATAL, "out of token space\n" ); +#endif +#endif + return NULL; + } //end if +// freetokens = freetokens->next; + memcpy( t, token, sizeof( token_t ) ); + t->next = NULL; + numtokens++; + return t; +} //end of the function PC_CopyToken +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void PC_FreeToken( token_t *token ) { + //free(token); + FreeMemory( token ); +// token->next = freetokens; +// freetokens = token; + numtokens--; +} //end of the function PC_FreeToken +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_ReadSourceToken( source_t *source, token_t *token ) { + token_t *t; + script_t *script; + int type, skip; + + //if there's no token already available + while ( !source->tokens ) + { + //if there's a token to read from the script + if ( PS_ReadToken( source->scriptstack, token ) ) { + return qtrue; + } + //if at the end of the script + if ( EndOfScript( source->scriptstack ) ) { + //remove all indents of the script + while ( source->indentstack && + source->indentstack->script == source->scriptstack ) + { + SourceWarning( source, "missing #endif" ); + PC_PopIndent( source, &type, &skip ); + } //end if + } //end if + //if this was the initial script + if ( !source->scriptstack->next ) { + return qfalse; + } + //remove the script and return to the last one + script = source->scriptstack; + source->scriptstack = source->scriptstack->next; + FreeScript( script ); + } //end while + //copy the already available token + memcpy( token, source->tokens, sizeof( token_t ) ); + //free the read token + t = source->tokens; + source->tokens = source->tokens->next; + PC_FreeToken( t ); + return qtrue; +} //end of the function PC_ReadSourceToken +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_UnreadSourceToken( source_t *source, token_t *token ) { + token_t *t; + + t = PC_CopyToken( token ); + t->next = source->tokens; + source->tokens = t; + return qtrue; +} //end of the function PC_UnreadSourceToken +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_ReadDefineParms( source_t *source, define_t *define, token_t **parms, int maxparms ) { + token_t token, *t, *last; + int i, done, lastcomma, numparms, indent; + + if ( !PC_ReadSourceToken( source, &token ) ) { + SourceError( source, "define %s missing parms", define->name ); + return qfalse; + } //end if + // + if ( define->numparms > maxparms ) { + SourceError( source, "define with more than %d parameters", maxparms ); + return qfalse; + } //end if + // + for ( i = 0; i < define->numparms; i++ ) parms[i] = NULL; + //if no leading "(" + if ( strcmp( token.string, "(" ) ) { + PC_UnreadSourceToken( source, &token ); + SourceError( source, "define %s missing parms", define->name ); + return qfalse; + } //end if + //read the define parameters + for ( done = 0, numparms = 0, indent = 0; !done; ) + { + if ( numparms >= maxparms ) { + SourceError( source, "define %s with too many parms", define->name ); + return qfalse; + } //end if + if ( numparms >= define->numparms ) { + SourceWarning( source, "define %s has too many parms", define->name ); + return qfalse; + } //end if + parms[numparms] = NULL; + lastcomma = 1; + last = NULL; + while ( !done ) + { + // + if ( !PC_ReadSourceToken( source, &token ) ) { + SourceError( source, "define %s incomplete", define->name ); + return qfalse; + } //end if + // + if ( !strcmp( token.string, "," ) ) { + if ( indent <= 0 ) { + if ( lastcomma ) { + SourceWarning( source, "too many comma's" ); + } + lastcomma = 1; + break; + } //end if + } //end if + lastcomma = 0; + // + if ( !strcmp( token.string, "(" ) ) { + indent++; + continue; + } //end if + else if ( !strcmp( token.string, ")" ) ) { + if ( --indent <= 0 ) { + if ( !parms[define->numparms - 1] ) { + SourceWarning( source, "too few define parms" ); + } //end if + done = 1; + break; + } //end if + } //end if + // + if ( numparms < define->numparms ) { + // + t = PC_CopyToken( &token ); + t->next = NULL; + if ( last ) { + last->next = t; + } else { parms[numparms] = t;} + last = t; + } //end if + } //end while + numparms++; + } //end for + return qtrue; +} //end of the function PC_ReadDefineParms +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_StringizeTokens( token_t *tokens, token_t *token ) { + token_t *t; + + token->type = TT_STRING; + token->whitespace_p = NULL; + token->endwhitespace_p = NULL; + token->string[0] = '\0'; + strcat( token->string, "\"" ); + for ( t = tokens; t; t = t->next ) + { + strncat( token->string, t->string, MAX_TOKEN - strlen( token->string ) ); + } //end for + strncat( token->string, "\"", MAX_TOKEN - strlen( token->string ) ); + return qtrue; +} //end of the function PC_StringizeTokens +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_MergeTokens( token_t *t1, token_t *t2 ) { + //merging of a name with a name or number + if ( t1->type == TT_NAME && ( t2->type == TT_NAME || t2->type == TT_NUMBER ) ) { + strcat( t1->string, t2->string ); + return qtrue; + } //end if + //merging of two strings + if ( t1->type == TT_STRING && t2->type == TT_STRING ) { + //remove trailing double quote + t1->string[strlen( t1->string ) - 1] = '\0'; + //concat without leading double quote + strcat( t1->string, &t2->string[1] ); + return qtrue; + } //end if + //FIXME: merging of two number of the same sub type + return qfalse; +} //end of the function PC_MergeTokens +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +/* +void PC_PrintDefine(define_t *define) +{ + printf("define->name = %s\n", define->name); + printf("define->flags = %d\n", define->flags); + printf("define->builtin = %d\n", define->builtin); + printf("define->numparms = %d\n", define->numparms); +// token_t *parms; //define parameters +// token_t *tokens; //macro tokens (possibly containing parm tokens) +// struct define_s *next; //next defined macro in a list +} //end of the function PC_PrintDefine*/ +#if DEFINEHASHING +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void PC_PrintDefineHashTable( define_t **definehash ) { + int i; + define_t *d; + + for ( i = 0; i < DEFINEHASHSIZE; i++ ) + { + Log_Write( "%4d:", i ); + for ( d = definehash[i]; d; d = d->hashnext ) + { + Log_Write( " %s", d->name ); + } //end for + Log_Write( "\n" ); + } //end for +} //end of the function PC_PrintDefineHashTable +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +//char primes[16] = {1, 3, 5, 7, 11, 13, 17, 19, 23, 27, 29, 31, 37, 41, 43, 47}; + +int PC_NameHash( char *name ) { + int register hash, i; + + hash = 0; + for ( i = 0; name[i] != '\0'; i++ ) + { + hash += name[i] * ( 119 + i ); + //hash += (name[i] << 7) + i; + //hash += (name[i] << (i&15)); + } //end while + hash = ( hash ^ ( hash >> 10 ) ^ ( hash >> 20 ) ) & ( DEFINEHASHSIZE - 1 ); + return hash; +} //end of the function PC_NameHash +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void PC_AddDefineToHash( define_t *define, define_t **definehash ) { + int hash; + + hash = PC_NameHash( define->name ); + define->hashnext = definehash[hash]; + definehash[hash] = define; +} //end of the function PC_AddDefineToHash +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +define_t *PC_FindHashedDefine( define_t **definehash, char *name ) { + define_t *d; + int hash; + + hash = PC_NameHash( name ); + for ( d = definehash[hash]; d; d = d->hashnext ) + { + if ( !strcmp( d->name, name ) ) { + return d; + } + } //end for + return NULL; +} //end of the function PC_FindHashedDefine +#endif //DEFINEHASHING +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +define_t *PC_FindDefine( define_t *defines, char *name ) { + define_t *d; + + for ( d = defines; d; d = d->next ) + { + if ( !strcmp( d->name, name ) ) { + return d; + } + } //end for + return NULL; +} //end of the function PC_FindDefine +//============================================================================ +// +// Parameter: - +// Returns: number of the parm +// if no parm found with the given name -1 is returned +// Changes Globals: - +//============================================================================ +int PC_FindDefineParm( define_t *define, char *name ) { + token_t *p; + int i; + + i = 0; + for ( p = define->parms; p; p = p->next ) + { + if ( !strcmp( p->string, name ) ) { + return i; + } + i++; + } //end for + return -1; +} //end of the function PC_FindDefineParm +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void PC_FreeDefine( define_t *define ) { + token_t *t, *next; + + //free the define parameters + for ( t = define->parms; t; t = next ) + { + next = t->next; + PC_FreeToken( t ); + } //end for + //free the define tokens + for ( t = define->tokens; t; t = next ) + { + next = t->next; + PC_FreeToken( t ); + } //end for + //free the define + FreeMemory( define ); +} //end of the function PC_FreeDefine +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void PC_AddBuiltinDefines( source_t *source ) { + int i; + define_t *define; + struct builtin + { + char *string; + int builtin; + } builtin[] = { + "__LINE__", BUILTIN_LINE, + "__FILE__", BUILTIN_FILE, + "__DATE__", BUILTIN_DATE, + "__TIME__", BUILTIN_TIME, +// "__STDC__", BUILTIN_STDC, + NULL, 0 + }; + + for ( i = 0; builtin[i].string; i++ ) + { + define = (define_t *) GetMemory( sizeof( define_t ) + strlen( builtin[i].string ) + 1 ); + memset( define, 0, sizeof( define_t ) ); + define->name = (char *) define + sizeof( define_t ); + strcpy( define->name, builtin[i].string ); + define->flags |= DEFINE_FIXED; + define->builtin = builtin[i].builtin; + //add the define to the source +#if DEFINEHASHING + PC_AddDefineToHash( define, source->definehash ); +#else + define->next = source->defines; + source->defines = define; +#endif //DEFINEHASHING + } //end for +} //end of the function PC_AddBuiltinDefines +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_ExpandBuiltinDefine( source_t *source, define_t *define, + token_t **firsttoken, token_t **lasttoken ) { + token_t token; + unsigned long t; // time_t t; //to prevent LCC warning + char *curtime; + + memcpy( &token, &source->token, sizeof( token_t ) ); + switch ( define->builtin ) + { + case BUILTIN_LINE: + { + sprintf( token.string, "%d", source->token.line ); +#ifdef NUMBERVALUE + token.intvalue = source->token.line; + token.floatvalue = source->token.line; +#endif //NUMBERVALUE + token.type = TT_NUMBER; + token.subtype = TT_DECIMAL | TT_INTEGER; + *firsttoken = &token; + *lasttoken = &token; + break; + } //end case + case BUILTIN_FILE: + { + strcpy( token.string, source->scriptstack->filename ); + token.type = TT_NAME; + token.subtype = strlen( token.string ); + *firsttoken = &token; + *lasttoken = &token; + break; + } //end case + case BUILTIN_DATE: + { + t = time( NULL ); + curtime = ctime( &t ); + strcpy( token.string, "\"" ); + strncat( token.string, curtime + 4, 7 ); + strncat( token.string + 7, curtime + 20, 4 ); + strcat( token.string, "\"" ); + free( curtime ); + token.type = TT_NAME; + token.subtype = strlen( token.string ); + *firsttoken = &token; + *lasttoken = &token; + break; + } //end case + case BUILTIN_TIME: + { + t = time( NULL ); + curtime = ctime( &t ); + strcpy( token.string, "\"" ); + strncat( token.string, curtime + 11, 8 ); + strcat( token.string, "\"" ); + free( curtime ); + token.type = TT_NAME; + token.subtype = strlen( token.string ); + *firsttoken = &token; + *lasttoken = &token; + break; + } //end case + case BUILTIN_STDC: + default: + { + *firsttoken = NULL; + *lasttoken = NULL; + break; + } //end case + } //end switch + return qtrue; +} //end of the function PC_ExpandBuiltinDefine +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_ExpandDefine( source_t *source, define_t *define, + token_t **firsttoken, token_t **lasttoken ) { + token_t *parms[MAX_DEFINEPARMS], *dt, *pt, *t; + token_t *t1, *t2, *first, *last, *nextpt, token; + int parmnum, i; + + //if it is a builtin define + if ( define->builtin ) { + return PC_ExpandBuiltinDefine( source, define, firsttoken, lasttoken ); + } //end if + //if the define has parameters + if ( define->numparms ) { + if ( !PC_ReadDefineParms( source, define, parms, MAX_DEFINEPARMS ) ) { + return qfalse; + } +#ifdef DEBUG_EVAL + for ( i = 0; i < define->numparms; i++ ) + { + Log_Write( "define parms %d:", i ); + for ( pt = parms[i]; pt; pt = pt->next ) + { + Log_Write( "%s", pt->string ); + } //end for + } //end for +#endif //DEBUG_EVAL + } //end if + //empty list at first + first = NULL; + last = NULL; + //create a list with tokens of the expanded define + for ( dt = define->tokens; dt; dt = dt->next ) + { + parmnum = -1; + //if the token is a name, it could be a define parameter + if ( dt->type == TT_NAME ) { + parmnum = PC_FindDefineParm( define, dt->string ); + } //end if + //if it is a define parameter + if ( parmnum >= 0 ) { + for ( pt = parms[parmnum]; pt; pt = pt->next ) + { + t = PC_CopyToken( pt ); + //add the token to the list + t->next = NULL; + if ( last ) { + last->next = t; + } else { first = t;} + last = t; + } //end for + } //end if + else + { + //if stringizing operator + if ( dt->string[0] == '#' && dt->string[1] == '\0' ) { + //the stringizing operator must be followed by a define parameter + if ( dt->next ) { + parmnum = PC_FindDefineParm( define, dt->next->string ); + } else { parmnum = -1;} + // + if ( parmnum >= 0 ) { + //step over the stringizing operator + dt = dt->next; + //stringize the define parameter tokens + if ( !PC_StringizeTokens( parms[parmnum], &token ) ) { + SourceError( source, "can't stringize tokens" ); + return qfalse; + } //end if + t = PC_CopyToken( &token ); + } //end if + else + { + SourceWarning( source, "stringizing operator without define parameter" ); + continue; + } //end if + } //end if + else + { + t = PC_CopyToken( dt ); + } //end else + //add the token to the list + t->next = NULL; + if ( last ) { + last->next = t; + } else { first = t;} + last = t; + } //end else + } //end for + //check for the merging operator + for ( t = first; t; ) + { + if ( t->next ) { + //if the merging operator + if ( t->next->string[0] == '#' && t->next->string[1] == '#' ) { + t1 = t; + t2 = t->next->next; + if ( t2 ) { + if ( !PC_MergeTokens( t1, t2 ) ) { + SourceError( source, "can't merge %s with %s", t1->string, t2->string ); + return qfalse; + } //end if + PC_FreeToken( t1->next ); + t1->next = t2->next; + if ( t2 == last ) { + last = t1; + } + PC_FreeToken( t2 ); + continue; + } //end if + } //end if + } //end if + t = t->next; + } //end for + //store the first and last token of the list + *firsttoken = first; + *lasttoken = last; + //free all the parameter tokens + for ( i = 0; i < define->numparms; i++ ) + { + for ( pt = parms[i]; pt; pt = nextpt ) + { + nextpt = pt->next; + PC_FreeToken( pt ); + } //end for + } //end for + // + return qtrue; +} //end of the function PC_ExpandDefine +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_ExpandDefineIntoSource( source_t *source, define_t *define ) { + token_t *firsttoken, *lasttoken; + + if ( !PC_ExpandDefine( source, define, &firsttoken, &lasttoken ) ) { + return qfalse; + } + + if ( firsttoken && lasttoken ) { + lasttoken->next = source->tokens; + source->tokens = firsttoken; + return qtrue; + } //end if + return qfalse; +} //end of the function PC_ExpandDefineIntoSource +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void PC_ConvertPath( char *path ) { + char *ptr; + + //remove double path seperators + for ( ptr = path; *ptr; ) + { + if ( ( *ptr == '\\' || *ptr == '/' ) && + ( *( ptr + 1 ) == '\\' || *( ptr + 1 ) == '/' ) ) { + strcpy( ptr, ptr + 1 ); + } //end if + else + { + ptr++; + } //end else + } //end while + //set OS dependent path seperators + for ( ptr = path; *ptr; ) + { + if ( *ptr == '/' || *ptr == '\\' ) { + *ptr = PATHSEPERATOR_CHAR; + } + ptr++; + } //end while +} //end of the function PC_ConvertPath +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_Directive_include( source_t *source ) { + script_t *script; + token_t token; + char path[_MAX_PATH]; +#ifdef QUAKE + foundfile_t file; +#endif //QUAKE + + if ( source->skip > 0 ) { + return qtrue; + } + // + if ( !PC_ReadSourceToken( source, &token ) ) { + SourceError( source, "#include without file name" ); + return qfalse; + } //end if + if ( token.linescrossed > 0 ) { + SourceError( source, "#include without file name" ); + return qfalse; + } //end if + if ( token.type == TT_STRING ) { + StripDoubleQuotes( token.string ); + PC_ConvertPath( token.string ); + script = LoadScriptFile( token.string ); + if ( !script ) { + strcpy( path, source->includepath ); + strcat( path, token.string ); + script = LoadScriptFile( path ); + } //end if + } //end if + else if ( token.type == TT_PUNCTUATION && *token.string == '<' ) { + strcpy( path, source->includepath ); + while ( PC_ReadSourceToken( source, &token ) ) + { + if ( token.linescrossed > 0 ) { + PC_UnreadSourceToken( source, &token ); + break; + } //end if + if ( token.type == TT_PUNCTUATION && *token.string == '>' ) { + break; + } + strncat( path, token.string, _MAX_PATH ); + } //end while + if ( *token.string != '>' ) { + SourceWarning( source, "#include missing trailing >" ); + } //end if + if ( !strlen( path ) ) { + SourceError( source, "#include without file name between < >" ); + return qfalse; + } //end if + PC_ConvertPath( path ); + script = LoadScriptFile( path ); + } //end if + else + { + SourceError( source, "#include without file name" ); + return qfalse; + } //end else +#ifdef QUAKE + if ( !script ) { + memset( &file, 0, sizeof( foundfile_t ) ); + script = LoadScriptFile( path ); + if ( script ) { + strncpy( script->filename, path, _MAX_PATH ); + } + } //end if +#endif //QUAKE + if ( !script ) { +#ifdef SCREWUP + SourceWarning( source, "file %s not found", path ); + return qtrue; +#else + SourceError( source, "file %s not found", path ); + return qfalse; +#endif //SCREWUP + } //end if + PC_PushScript( source, script ); + return qtrue; +} //end of the function PC_Directive_include +//============================================================================ +// reads a token from the current line, continues reading on the next +// line only if a backslash '\' is encountered. +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_ReadLine( source_t *source, token_t *token ) { + int crossline; + + crossline = 0; + do + { + if ( !PC_ReadSourceToken( source, token ) ) { + return qfalse; + } + + if ( token->linescrossed > crossline ) { + PC_UnreadSourceToken( source, token ); + return qfalse; + } //end if + crossline = 1; + } while ( !strcmp( token->string, "\\" ) ); + return qtrue; +} //end of the function PC_ReadLine +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_WhiteSpaceBeforeToken( token_t *token ) { + return token->endwhitespace_p - token->whitespace_p > 0; +} //end of the function PC_WhiteSpaceBeforeToken +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void PC_ClearTokenWhiteSpace( token_t *token ) { + token->whitespace_p = NULL; + token->endwhitespace_p = NULL; + token->linescrossed = 0; +} //end of the function PC_ClearTokenWhiteSpace +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_Directive_undef( source_t *source ) { + token_t token; + define_t *define, *lastdefine; + int hash; + + if ( source->skip > 0 ) { + return qtrue; + } + // + if ( !PC_ReadLine( source, &token ) ) { + SourceError( source, "undef without name" ); + return qfalse; + } //end if + if ( token.type != TT_NAME ) { + PC_UnreadSourceToken( source, &token ); + SourceError( source, "expected name, found %s", token.string ); + return qfalse; + } //end if +#if DEFINEHASHING + + hash = PC_NameHash( token.string ); + for ( lastdefine = NULL, define = source->definehash[hash]; define; define = define->hashnext ) + { + if ( !strcmp( define->name, token.string ) ) { + if ( define->flags & DEFINE_FIXED ) { + SourceWarning( source, "can't undef %s", token.string ); + } //end if + else + { + if ( lastdefine ) { + lastdefine->hashnext = define->hashnext; + } else { source->definehash[hash] = define->hashnext;} + PC_FreeDefine( define ); + } //end else + break; + } //end if + lastdefine = define; + } //end for +#else //DEFINEHASHING + for ( lastdefine = NULL, define = source->defines; define; define = define->next ) + { + if ( !strcmp( define->name, token.string ) ) { + if ( define->flags & DEFINE_FIXED ) { + SourceWarning( source, "can't undef %s", token.string ); + } //end if + else + { + if ( lastdefine ) { + lastdefine->next = define->next; + } else { source->defines = define->next;} + PC_FreeDefine( define ); + } //end else + break; + } //end if + lastdefine = define; + } //end for +#endif //DEFINEHASHING + return qtrue; +} //end of the function PC_Directive_undef +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_Directive_define( source_t *source ) { + token_t token, *t, *last; + define_t *define; + + if ( source->skip > 0 ) { + return qtrue; + } + // + if ( !PC_ReadLine( source, &token ) ) { + SourceError( source, "#define without name" ); + return qfalse; + } //end if + if ( token.type != TT_NAME ) { + PC_UnreadSourceToken( source, &token ); + SourceError( source, "expected name after #define, found %s", token.string ); + return qfalse; + } //end if + //check if the define already exists +#if DEFINEHASHING + define = PC_FindHashedDefine( source->definehash, token.string ); +#else + define = PC_FindDefine( source->defines, token.string ); +#endif //DEFINEHASHING + if ( define ) { + if ( define->flags & DEFINE_FIXED ) { + SourceError( source, "can't redefine %s", token.string ); + return qfalse; + } //end if + SourceWarning( source, "redefinition of %s", token.string ); + //unread the define name before executing the #undef directive + PC_UnreadSourceToken( source, &token ); + if ( !PC_Directive_undef( source ) ) { + return qfalse; + } + //if the define was not removed (define->flags & DEFINE_FIXED) +#if DEFINEHASHING + define = PC_FindHashedDefine( source->definehash, token.string ); +#else + define = PC_FindDefine( source->defines, token.string ); +#endif //DEFINEHASHING + } //end if + //allocate define + define = (define_t *) GetMemory( sizeof( define_t ) + strlen( token.string ) + 1 ); + memset( define, 0, sizeof( define_t ) ); + define->name = (char *) define + sizeof( define_t ); + strcpy( define->name, token.string ); + //add the define to the source +#if DEFINEHASHING + PC_AddDefineToHash( define, source->definehash ); +#else //DEFINEHASHING + define->next = source->defines; + source->defines = define; +#endif //DEFINEHASHING + //if nothing is defined, just return + if ( !PC_ReadLine( source, &token ) ) { + return qtrue; + } + //if it is a define with parameters + if ( !PC_WhiteSpaceBeforeToken( &token ) && !strcmp( token.string, "(" ) ) { + //read the define parameters + last = NULL; + if ( !PC_CheckTokenString( source, ")" ) ) { + while ( 1 ) + { + if ( !PC_ReadLine( source, &token ) ) { + SourceError( source, "expected define parameter" ); + return qfalse; + } //end if + //if it isn't a name + if ( token.type != TT_NAME ) { + SourceError( source, "invalid define parameter" ); + return qfalse; + } //end if + // + if ( PC_FindDefineParm( define, token.string ) >= 0 ) { + SourceError( source, "two the same define parameters" ); + return qfalse; + } //end if + //add the define parm + t = PC_CopyToken( &token ); + PC_ClearTokenWhiteSpace( t ); + t->next = NULL; + if ( last ) { + last->next = t; + } else { define->parms = t;} + last = t; + define->numparms++; + //read next token + if ( !PC_ReadLine( source, &token ) ) { + SourceError( source, "define parameters not terminated" ); + return qfalse; + } //end if + // + if ( !strcmp( token.string, ")" ) ) { + break; + } + //then it must be a comma + if ( strcmp( token.string, "," ) ) { + SourceError( source, "define not terminated" ); + return qfalse; + } //end if + } //end while + } //end if + if ( !PC_ReadLine( source, &token ) ) { + return qtrue; + } + } //end if + //read the defined stuff + last = NULL; + do + { + t = PC_CopyToken( &token ); + if ( t->type == TT_NAME && !strcmp( t->string, define->name ) ) { + SourceError( source, "recursive define (removed recursion)" ); + continue; + } //end if + PC_ClearTokenWhiteSpace( t ); + t->next = NULL; + if ( last ) { + last->next = t; + } else { define->tokens = t;} + last = t; + } while ( PC_ReadLine( source, &token ) ); + // + if ( last ) { + //check for merge operators at the beginning or end + if ( !strcmp( define->tokens->string, "##" ) || + !strcmp( last->string, "##" ) ) { + SourceError( source, "define with misplaced ##" ); + return qfalse; + } //end if + } //end if + return qtrue; +} //end of the function PC_Directive_define +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +define_t *PC_DefineFromString( char *string ) { + script_t *script; + source_t src; + token_t *t; + int res, i; + define_t *def; + + PC_InitTokenHeap(); + + script = LoadScriptMemory( string, strlen( string ), "*extern" ); + //create a new source + memset( &src, 0, sizeof( source_t ) ); + strncpy( src.filename, "*extern", _MAX_PATH ); + src.scriptstack = script; +#if DEFINEHASHING + src.definehash = GetClearedMemory( DEFINEHASHSIZE * sizeof( define_t * ) ); +#endif //DEFINEHASHING + //create a define from the source + res = PC_Directive_define( &src ); + //free any tokens if left + for ( t = src.tokens; t; t = src.tokens ) + { + src.tokens = src.tokens->next; + PC_FreeToken( t ); + } //end for +#ifdef DEFINEHASHING + def = NULL; + for ( i = 0; i < DEFINEHASHSIZE; i++ ) + { + if ( src.definehash[i] ) { + def = src.definehash[i]; + break; + } //end if + } //end for +#else + def = src.defines; +#endif //DEFINEHASHING + // +#if DEFINEHASHING + FreeMemory( src.definehash ); +#endif //DEFINEHASHING + // + FreeScript( script ); + //if the define was created succesfully + if ( res > 0 ) { + return def; + } + //free the define if created + if ( src.defines ) { + PC_FreeDefine( def ); + } + // + return NULL; +} //end of the function PC_DefineFromString +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_AddDefine( source_t *source, char *string ) { + define_t *define; + + define = PC_DefineFromString( string ); + if ( !define ) { + return qfalse; + } +#if DEFINEHASHING + PC_AddDefineToHash( define, source->definehash ); +#else //DEFINEHASHING + define->next = source->defines; + source->defines = define; +#endif //DEFINEHASHING + return qtrue; +} //end of the function PC_AddDefine +//============================================================================ +// add a globals define that will be added to all opened sources +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_AddGlobalDefine( char *string ) { + define_t *define; + + define = PC_DefineFromString( string ); + if ( !define ) { + return qfalse; + } + define->next = globaldefines; + globaldefines = define; + return qtrue; +} //end of the function PC_AddGlobalDefine +//============================================================================ +// remove the given global define +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_RemoveGlobalDefine( char *name ) { + define_t *define; + + define = PC_FindDefine( globaldefines, name ); + if ( define ) { + PC_FreeDefine( define ); + return qtrue; + } //end if + return qfalse; +} //end of the function PC_RemoveGlobalDefine +//============================================================================ +// remove all globals defines +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void PC_RemoveAllGlobalDefines( void ) { + define_t *define; + + for ( define = globaldefines; define; define = globaldefines ) + { + globaldefines = globaldefines->next; + PC_FreeDefine( define ); + } //end for +} //end of the function PC_RemoveAllGlobalDefines +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +define_t *PC_CopyDefine( source_t *source, define_t *define ) { + define_t *newdefine; + token_t *token, *newtoken, *lasttoken; + + newdefine = (define_t *) GetMemory( sizeof( define_t ) + strlen( define->name ) + 1 ); + //copy the define name + newdefine->name = (char *) newdefine + sizeof( define_t ); + strcpy( newdefine->name, define->name ); + newdefine->flags = define->flags; + newdefine->builtin = define->builtin; + newdefine->numparms = define->numparms; + //the define is not linked + newdefine->next = NULL; + newdefine->hashnext = NULL; + //copy the define tokens + newdefine->tokens = NULL; + for ( lasttoken = NULL, token = define->tokens; token; token = token->next ) + { + newtoken = PC_CopyToken( token ); + newtoken->next = NULL; + if ( lasttoken ) { + lasttoken->next = newtoken; + } else { newdefine->tokens = newtoken;} + lasttoken = newtoken; + } //end for + //copy the define parameters + newdefine->parms = NULL; + for ( lasttoken = NULL, token = define->parms; token; token = token->next ) + { + newtoken = PC_CopyToken( token ); + newtoken->next = NULL; + if ( lasttoken ) { + lasttoken->next = newtoken; + } else { newdefine->parms = newtoken;} + lasttoken = newtoken; + } //end for + return newdefine; +} //end of the function PC_CopyDefine +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void PC_AddGlobalDefinesToSource( source_t *source ) { + define_t *define, *newdefine; + + for ( define = globaldefines; define; define = define->next ) + { + newdefine = PC_CopyDefine( source, define ); +#if DEFINEHASHING + PC_AddDefineToHash( newdefine, source->definehash ); +#else //DEFINEHASHING + newdefine->next = source->defines; + source->defines = newdefine; +#endif //DEFINEHASHING + } //end for +} //end of the function PC_AddGlobalDefinesToSource +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_Directive_if_def( source_t *source, int type ) { + token_t token; + define_t *d; + int skip; + + if ( !PC_ReadLine( source, &token ) ) { + SourceError( source, "#ifdef without name" ); + return qfalse; + } //end if + if ( token.type != TT_NAME ) { + PC_UnreadSourceToken( source, &token ); + SourceError( source, "expected name after #ifdef, found %s", token.string ); + return qfalse; + } //end if +#if DEFINEHASHING + d = PC_FindHashedDefine( source->definehash, token.string ); +#else + d = PC_FindDefine( source->defines, token.string ); +#endif //DEFINEHASHING + skip = ( type == INDENT_IFDEF ) == ( d == NULL ); + PC_PushIndent( source, type, skip ); + return qtrue; +} //end of the function PC_Directiveif_def +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_Directive_ifdef( source_t *source ) { + return PC_Directive_if_def( source, INDENT_IFDEF ); +} //end of the function PC_Directive_ifdef +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_Directive_ifndef( source_t *source ) { + return PC_Directive_if_def( source, INDENT_IFNDEF ); +} //end of the function PC_Directive_ifndef +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_Directive_else( source_t *source ) { + int type, skip; + + PC_PopIndent( source, &type, &skip ); + if ( !type ) { + SourceError( source, "misplaced #else" ); + return qfalse; + } //end if + if ( type == INDENT_ELSE ) { + SourceError( source, "#else after #else" ); + return qfalse; + } //end if + PC_PushIndent( source, INDENT_ELSE, !skip ); + return qtrue; +} //end of the function PC_Directive_else +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_Directive_endif( source_t *source ) { + int type, skip; + + PC_PopIndent( source, &type, &skip ); + if ( !type ) { + SourceError( source, "misplaced #endif" ); + return qfalse; + } //end if + return qtrue; +} //end of the function PC_Directive_endif +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +typedef struct operator_s +{ + int operator; + int priority; + int parentheses; + struct operator_s *prev, *next; +} operator_t; + +typedef struct value_s +{ + signed long int intvalue; + double floatvalue; + int parentheses; + struct value_s *prev, *next; +} value_t; + +int PC_OperatorPriority( int op ) { + switch ( op ) + { + case P_MUL: return 15; + case P_DIV: return 15; + case P_MOD: return 15; + case P_ADD: return 14; + case P_SUB: return 14; + + case P_LOGIC_AND: return 7; + case P_LOGIC_OR: return 6; + case P_LOGIC_GEQ: return 12; + case P_LOGIC_LEQ: return 12; + case P_LOGIC_EQ: return 11; + case P_LOGIC_UNEQ: return 11; + + case P_LOGIC_NOT: return 16; + case P_LOGIC_GREATER: return 12; + case P_LOGIC_LESS: return 12; + + case P_RSHIFT: return 13; + case P_LSHIFT: return 13; + + case P_BIN_AND: return 10; + case P_BIN_OR: return 8; + case P_BIN_XOR: return 9; + case P_BIN_NOT: return 16; + + case P_COLON: return 5; + case P_QUESTIONMARK: return 5; + } //end switch + return qfalse; +} //end of the function PC_OperatorPriority + +//#define AllocValue() GetClearedMemory(sizeof(value_t)); +//#define FreeValue(val) FreeMemory(val) +//#define AllocOperator(op) op = (operator_t *) GetClearedMemory(sizeof(operator_t)); +//#define FreeOperator(op) FreeMemory(op); + +#define MAX_VALUES 64 +#define MAX_OPERATORS 64 +#define AllocValue( val ) \ + if ( numvalues >= MAX_VALUES ) { \ + SourceError( source, "out value space\n" ); \ + error = 1; \ + break; \ + } \ + else { \ + val = &value_heap[numvalues++];} +#define FreeValue( val ) +// +#define AllocOperator( op ) \ + if ( numoperators >= MAX_OPERATORS ) { \ + SourceError( source, "out operator space\n" ); \ + error = 1; \ + break; \ + } \ + else { \ + op = &operator_heap[numoperators++];} +#define FreeOperator( op ) + +int PC_EvaluateTokens( source_t *source, token_t *tokens, signed long int *intvalue, + double *floatvalue, int integer ) { + operator_t *o, *firstoperator, *lastoperator; + value_t *v, *firstvalue, *lastvalue, *v1, *v2; + token_t *t; + int brace = 0; + int parentheses = 0; + int error = 0; + int lastwasvalue = 0; + int negativevalue = 0; + int questmarkintvalue = 0; + double questmarkfloatvalue = 0; + int gotquestmarkvalue = qfalse; + int lastoperatortype = 0; + // + operator_t operator_heap[MAX_OPERATORS]; + int numoperators = 0; + value_t value_heap[MAX_VALUES]; + int numvalues = 0; + + firstoperator = lastoperator = NULL; + firstvalue = lastvalue = NULL; + if ( intvalue ) { + *intvalue = 0; + } + if ( floatvalue ) { + *floatvalue = 0; + } + for ( t = tokens; t; t = t->next ) + { + switch ( t->type ) + { + case TT_NAME: + { + if ( lastwasvalue || negativevalue ) { + SourceError( source, "syntax error in #if/#elif" ); + error = 1; + break; + } //end if + if ( strcmp( t->string, "defined" ) ) { + SourceError( source, "undefined name %s in #if/#elif", t->string ); + error = 1; + break; + } //end if + t = t->next; + if ( !strcmp( t->string, "(" ) ) { + brace = qtrue; + t = t->next; + } //end if + if ( !t || t->type != TT_NAME ) { + SourceError( source, "defined without name in #if/#elif" ); + error = 1; + break; + } //end if + //v = (value_t *) GetClearedMemory(sizeof(value_t)); + AllocValue( v ); +#if DEFINEHASHING + if ( PC_FindHashedDefine( source->definehash, t->string ) ) +#else + if ( PC_FindDefine( source->defines, t->string ) ) +#endif //DEFINEHASHING + { + v->intvalue = 1; + v->floatvalue = 1; + } //end if + else + { + v->intvalue = 0; + v->floatvalue = 0; + } //end else + v->parentheses = parentheses; + v->next = NULL; + v->prev = lastvalue; + if ( lastvalue ) { + lastvalue->next = v; + } else { firstvalue = v;} + lastvalue = v; + if ( brace ) { + t = t->next; + if ( !t || strcmp( t->string, ")" ) ) { + SourceError( source, "defined without ) in #if/#elif" ); + error = 1; + break; + } //end if + } //end if + brace = qfalse; + // defined() creates a value + lastwasvalue = 1; + break; + } //end case + case TT_NUMBER: + { + if ( lastwasvalue ) { + SourceError( source, "syntax error in #if/#elif" ); + error = 1; + break; + } //end if + //v = (value_t *) GetClearedMemory(sizeof(value_t)); + AllocValue( v ); + if ( negativevalue ) { + v->intvalue = -(signed int) t->intvalue; + v->floatvalue = -t->floatvalue; + } //end if + else + { + v->intvalue = t->intvalue; + v->floatvalue = t->floatvalue; + } //end else + v->parentheses = parentheses; + v->next = NULL; + v->prev = lastvalue; + if ( lastvalue ) { + lastvalue->next = v; + } else { firstvalue = v;} + lastvalue = v; + //last token was a value + lastwasvalue = 1; + // + negativevalue = 0; + break; + } //end case + case TT_PUNCTUATION: + { + if ( negativevalue ) { + SourceError( source, "misplaced minus sign in #if/#elif" ); + error = 1; + break; + } //end if + if ( t->subtype == P_PARENTHESESOPEN ) { + parentheses++; + break; + } //end if + else if ( t->subtype == P_PARENTHESESCLOSE ) { + parentheses--; + if ( parentheses < 0 ) { + SourceError( source, "too many ) in #if/#elsif" ); + error = 1; + } //end if + break; + } //end else if + //check for invalid operators on floating point values + if ( !integer ) { + if ( t->subtype == P_BIN_NOT || t->subtype == P_MOD || + t->subtype == P_RSHIFT || t->subtype == P_LSHIFT || + t->subtype == P_BIN_AND || t->subtype == P_BIN_OR || + t->subtype == P_BIN_XOR ) { + SourceError( source, "illigal operator %s on floating point operands\n", t->string ); + error = 1; + break; + } //end if + } //end if + switch ( t->subtype ) + { + case P_LOGIC_NOT: + case P_BIN_NOT: + { + if ( lastwasvalue ) { + SourceError( source, "! or ~ after value in #if/#elif" ); + error = 1; + break; + } //end if + break; + } //end case + case P_SUB: + { + if ( !lastwasvalue ) { + negativevalue = 1; + break; + } //end if + } //end case + + case P_MUL: + case P_DIV: + case P_MOD: + case P_ADD: + + case P_LOGIC_AND: + case P_LOGIC_OR: + case P_LOGIC_GEQ: + case P_LOGIC_LEQ: + case P_LOGIC_EQ: + case P_LOGIC_UNEQ: + + case P_LOGIC_GREATER: + case P_LOGIC_LESS: + + case P_RSHIFT: + case P_LSHIFT: + + case P_BIN_AND: + case P_BIN_OR: + case P_BIN_XOR: + + case P_COLON: + case P_QUESTIONMARK: + { + if ( !lastwasvalue ) { + SourceError( source, "operator %s after operator in #if/#elif", t->string ); + error = 1; + break; + } //end if + break; + } //end case + default: + { + SourceError( source, "invalid operator %s in #if/#elif", t->string ); + error = 1; + break; + } //end default + } //end switch + if ( !error && !negativevalue ) { + //o = (operator_t *) GetClearedMemory(sizeof(operator_t)); + AllocOperator( o ); + o->operator = t->subtype; + o->priority = PC_OperatorPriority( t->subtype ); + o->parentheses = parentheses; + o->next = NULL; + o->prev = lastoperator; + if ( lastoperator ) { + lastoperator->next = o; + } else { firstoperator = o;} + lastoperator = o; + lastwasvalue = 0; + } //end if + break; + } //end case + default: + { + SourceError( source, "unknown %s in #if/#elif", t->string ); + error = 1; + break; + } //end default + } //end switch + if ( error ) { + break; + } + } //end for + if ( !error ) { + if ( !lastwasvalue ) { + SourceError( source, "trailing operator in #if/#elif" ); + error = 1; + } //end if + else if ( parentheses ) { + SourceError( source, "too many ( in #if/#elif" ); + error = 1; + } //end else if + } //end if + // + gotquestmarkvalue = qfalse; + questmarkintvalue = 0; + questmarkfloatvalue = 0; + //while there are operators + while ( !error && firstoperator ) + { + v = firstvalue; + for ( o = firstoperator; o->next; o = o->next ) + { + //if the current operator is nested deeper in parentheses + //than the next operator + if ( o->parentheses > o->next->parentheses ) { + break; + } + //if the current and next operator are nested equally deep in parentheses + if ( o->parentheses == o->next->parentheses ) { + //if the priority of the current operator is equal or higher + //than the priority of the next operator + if ( o->priority >= o->next->priority ) { + break; + } + } //end if + //if the arity of the operator isn't equal to 1 + if ( o->operator != P_LOGIC_NOT + && o->operator != P_BIN_NOT ) { + v = v->next; + } + //if there's no value or no next value + if ( !v ) { + SourceError( source, "mising values in #if/#elif" ); + error = 1; + break; + } //end if + } //end for + if ( error ) { + break; + } + v1 = v; + v2 = v->next; +#ifdef DEBUG_EVAL + if ( integer ) { + Log_Write( "operator %s, value1 = %d", PunctuationFromNum( source->scriptstack, o->operator ), v1->intvalue ); + if ( v2 ) { + Log_Write( "value2 = %d", v2->intvalue ); + } + } //end if + else + { + Log_Write( "operator %s, value1 = %f", PunctuationFromNum( source->scriptstack, o->operator ), v1->floatvalue ); + if ( v2 ) { + Log_Write( "value2 = %f", v2->floatvalue ); + } + } //end else +#endif //DEBUG_EVAL + switch ( o->operator ) + { + case P_LOGIC_NOT: v1->intvalue = !v1->intvalue; + v1->floatvalue = !v1->floatvalue; break; + case P_BIN_NOT: v1->intvalue = ~v1->intvalue; + break; + case P_MUL: v1->intvalue *= v2->intvalue; + v1->floatvalue *= v2->floatvalue; break; + case P_DIV: v1->intvalue /= v2->intvalue; + v1->floatvalue /= v2->floatvalue; break; + case P_MOD: v1->intvalue %= v2->intvalue; + break; + case P_ADD: v1->intvalue += v2->intvalue; + v1->floatvalue += v2->floatvalue; break; + case P_SUB: v1->intvalue -= v2->intvalue; + v1->floatvalue -= v2->floatvalue; break; + case P_LOGIC_AND: v1->intvalue = v1->intvalue && v2->intvalue; + v1->floatvalue = v1->floatvalue && v2->floatvalue; break; + case P_LOGIC_OR: v1->intvalue = v1->intvalue || v2->intvalue; + v1->floatvalue = v1->floatvalue || v2->floatvalue; break; + case P_LOGIC_GEQ: v1->intvalue = v1->intvalue >= v2->intvalue; + v1->floatvalue = v1->floatvalue >= v2->floatvalue; break; + case P_LOGIC_LEQ: v1->intvalue = v1->intvalue <= v2->intvalue; + v1->floatvalue = v1->floatvalue <= v2->floatvalue; break; + case P_LOGIC_EQ: v1->intvalue = v1->intvalue == v2->intvalue; + v1->floatvalue = v1->floatvalue == v2->floatvalue; break; + case P_LOGIC_UNEQ: v1->intvalue = v1->intvalue != v2->intvalue; + v1->floatvalue = v1->floatvalue != v2->floatvalue; break; + case P_LOGIC_GREATER: v1->intvalue = v1->intvalue > v2->intvalue; + v1->floatvalue = v1->floatvalue > v2->floatvalue; break; + case P_LOGIC_LESS: v1->intvalue = v1->intvalue < v2->intvalue; + v1->floatvalue = v1->floatvalue < v2->floatvalue; break; + case P_RSHIFT: v1->intvalue >>= v2->intvalue; + break; + case P_LSHIFT: v1->intvalue <<= v2->intvalue; + break; + case P_BIN_AND: v1->intvalue &= v2->intvalue; + break; + case P_BIN_OR: v1->intvalue |= v2->intvalue; + break; + case P_BIN_XOR: v1->intvalue ^= v2->intvalue; + break; + case P_COLON: + { + if ( !gotquestmarkvalue ) { + SourceError( source, ": without ? in #if/#elif" ); + error = 1; + break; + } //end if + if ( integer ) { + if ( !questmarkintvalue ) { + v1->intvalue = v2->intvalue; + } + } //end if + else + { + if ( !questmarkfloatvalue ) { + v1->floatvalue = v2->floatvalue; + } + } //end else + gotquestmarkvalue = qfalse; + break; + } //end case + case P_QUESTIONMARK: + { + if ( gotquestmarkvalue ) { + SourceError( source, "? after ? in #if/#elif" ); + error = 1; + break; + } //end if + questmarkintvalue = v1->intvalue; + questmarkfloatvalue = v1->floatvalue; + gotquestmarkvalue = qtrue; + break; + } //end if + } //end switch +#ifdef DEBUG_EVAL + if ( integer ) { + Log_Write( "result value = %d", v1->intvalue ); + } else { Log_Write( "result value = %f", v1->floatvalue );} +#endif //DEBUG_EVAL + if ( error ) { + break; + } + lastoperatortype = o->operator; + //if not an operator with arity 1 + if ( o->operator != P_LOGIC_NOT + && o->operator != P_BIN_NOT ) { + //remove the second value if not question mark operator + if ( o->operator != P_QUESTIONMARK ) { + v = v->next; + } + // + if ( v->prev ) { + v->prev->next = v->next; + } else { firstvalue = v->next;} + if ( v->next ) { + v->next->prev = v->prev; + } else { lastvalue = v->prev;} + //FreeMemory(v); + FreeValue( v ); + } //end if + //remove the operator + if ( o->prev ) { + o->prev->next = o->next; + } else { firstoperator = o->next;} + if ( o->next ) { + o->next->prev = o->prev; + } else { lastoperator = o->prev;} + //FreeMemory(o); + FreeOperator( o ); + } //end while + if ( firstvalue ) { + if ( intvalue ) { + *intvalue = firstvalue->intvalue; + } + if ( floatvalue ) { + *floatvalue = firstvalue->floatvalue; + } + } //end if + for ( o = firstoperator; o; o = lastoperator ) + { + lastoperator = o->next; + //FreeMemory(o); + FreeOperator( o ); + } //end for + for ( v = firstvalue; v; v = lastvalue ) + { + lastvalue = v->next; + //FreeMemory(v); + FreeValue( v ); + } //end for + if ( !error ) { + return qtrue; + } + if ( intvalue ) { + *intvalue = 0; + } + if ( floatvalue ) { + *floatvalue = 0; + } + return qfalse; +} //end of the function PC_EvaluateTokens +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_Evaluate( source_t *source, signed long int *intvalue, + double *floatvalue, int integer ) { + token_t token, *firsttoken, *lasttoken; + token_t *t, *nexttoken; + define_t *define; + int defined = qfalse; + + if ( intvalue ) { + *intvalue = 0; + } + if ( floatvalue ) { + *floatvalue = 0; + } + // + if ( !PC_ReadLine( source, &token ) ) { + SourceError( source, "no value after #if/#elif" ); + return qfalse; + } //end if + firsttoken = NULL; + lasttoken = NULL; + do + { + //if the token is a name + if ( token.type == TT_NAME ) { + if ( defined ) { + defined = qfalse; + t = PC_CopyToken( &token ); + t->next = NULL; + if ( lasttoken ) { + lasttoken->next = t; + } else { firsttoken = t;} + lasttoken = t; + } //end if + else if ( !strcmp( token.string, "defined" ) ) { + defined = qtrue; + t = PC_CopyToken( &token ); + t->next = NULL; + if ( lasttoken ) { + lasttoken->next = t; + } else { firsttoken = t;} + lasttoken = t; + } //end if + else + { + //then it must be a define +#if DEFINEHASHING + define = PC_FindHashedDefine( source->definehash, token.string ); +#else + define = PC_FindDefine( source->defines, token.string ); +#endif //DEFINEHASHING + if ( !define ) { + SourceError( source, "can't evaluate %s, not defined", token.string ); + return qfalse; + } //end if + if ( !PC_ExpandDefineIntoSource( source, define ) ) { + return qfalse; + } + } //end else + } //end if + //if the token is a number or a punctuation + else if ( token.type == TT_NUMBER || token.type == TT_PUNCTUATION ) { + t = PC_CopyToken( &token ); + t->next = NULL; + if ( lasttoken ) { + lasttoken->next = t; + } else { firsttoken = t;} + lasttoken = t; + } //end else + else //can't evaluate the token + { + SourceError( source, "can't evaluate %s", token.string ); + return qfalse; + } //end else + } while ( PC_ReadLine( source, &token ) ); + // + if ( !PC_EvaluateTokens( source, firsttoken, intvalue, floatvalue, integer ) ) { + return qfalse; + } + // +#ifdef DEBUG_EVAL + Log_Write( "eval:" ); +#endif //DEBUG_EVAL + for ( t = firsttoken; t; t = nexttoken ) + { +#ifdef DEBUG_EVAL + Log_Write( " %s", t->string ); +#endif //DEBUG_EVAL + nexttoken = t->next; + PC_FreeToken( t ); + } //end for +#ifdef DEBUG_EVAL + if ( integer ) { + Log_Write( "eval result: %d", *intvalue ); + } else { Log_Write( "eval result: %f", *floatvalue );} +#endif //DEBUG_EVAL + // + return qtrue; +} //end of the function PC_Evaluate +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_DollarEvaluate( source_t *source, signed long int *intvalue, + double *floatvalue, int integer ) { + int indent, defined = qfalse; + token_t token, *firsttoken, *lasttoken; + token_t *t, *nexttoken; + define_t *define; + + if ( intvalue ) { + *intvalue = 0; + } + if ( floatvalue ) { + *floatvalue = 0; + } + // + if ( !PC_ReadSourceToken( source, &token ) ) { + SourceError( source, "no leading ( after $evalint/$evalfloat" ); + return qfalse; + } //end if + if ( !PC_ReadSourceToken( source, &token ) ) { + SourceError( source, "nothing to evaluate" ); + return qfalse; + } //end if + indent = 1; + firsttoken = NULL; + lasttoken = NULL; + do + { + //if the token is a name + if ( token.type == TT_NAME ) { + if ( defined ) { + defined = qfalse; + t = PC_CopyToken( &token ); + t->next = NULL; + if ( lasttoken ) { + lasttoken->next = t; + } else { firsttoken = t;} + lasttoken = t; + } //end if + else if ( !strcmp( token.string, "defined" ) ) { + defined = qtrue; + t = PC_CopyToken( &token ); + t->next = NULL; + if ( lasttoken ) { + lasttoken->next = t; + } else { firsttoken = t;} + lasttoken = t; + } //end if + else + { + //then it must be a define +#if DEFINEHASHING + define = PC_FindHashedDefine( source->definehash, token.string ); +#else + define = PC_FindDefine( source->defines, token.string ); +#endif //DEFINEHASHING + if ( !define ) { + SourceError( source, "can't evaluate %s, not defined", token.string ); + return qfalse; + } //end if + if ( !PC_ExpandDefineIntoSource( source, define ) ) { + return qfalse; + } + } //end else + } //end if + //if the token is a number or a punctuation + else if ( token.type == TT_NUMBER || token.type == TT_PUNCTUATION ) { + if ( *token.string == '(' ) { + indent++; + } else if ( *token.string == ')' ) { + indent--; + } + if ( indent <= 0 ) { + break; + } + t = PC_CopyToken( &token ); + t->next = NULL; + if ( lasttoken ) { + lasttoken->next = t; + } else { firsttoken = t;} + lasttoken = t; + } //end else + else //can't evaluate the token + { + SourceError( source, "can't evaluate %s", token.string ); + return qfalse; + } //end else + } while ( PC_ReadSourceToken( source, &token ) ); + // + if ( !PC_EvaluateTokens( source, firsttoken, intvalue, floatvalue, integer ) ) { + return qfalse; + } + // +#ifdef DEBUG_EVAL + Log_Write( "$eval:" ); +#endif //DEBUG_EVAL + for ( t = firsttoken; t; t = nexttoken ) + { +#ifdef DEBUG_EVAL + Log_Write( " %s", t->string ); +#endif //DEBUG_EVAL + nexttoken = t->next; + PC_FreeToken( t ); + } //end for +#ifdef DEBUG_EVAL + if ( integer ) { + Log_Write( "$eval result: %d", *intvalue ); + } else { Log_Write( "$eval result: %f", *floatvalue );} +#endif //DEBUG_EVAL + // + return qtrue; +} //end of the function PC_DollarEvaluate +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_Directive_elif( source_t *source ) { + signed long int value; + int type, skip; + + PC_PopIndent( source, &type, &skip ); + if ( !type || type == INDENT_ELSE ) { + SourceError( source, "misplaced #elif" ); + return qfalse; + } //end if + if ( !PC_Evaluate( source, &value, NULL, qtrue ) ) { + return qfalse; + } + skip = ( value == 0 ); + PC_PushIndent( source, INDENT_ELIF, skip ); + return qtrue; +} //end of the function PC_Directive_elif +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_Directive_if( source_t *source ) { + signed long int value; + int skip; + + if ( !PC_Evaluate( source, &value, NULL, qtrue ) ) { + return qfalse; + } + skip = ( value == 0 ); + PC_PushIndent( source, INDENT_IF, skip ); + return qtrue; +} //end of the function PC_Directive +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_Directive_line( source_t *source ) { + SourceError( source, "#line directive not supported" ); + return qfalse; +} //end of the function PC_Directive_line +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_Directive_error( source_t *source ) { + token_t token; + + strcpy( token.string, "" ); + PC_ReadSourceToken( source, &token ); + SourceError( source, "#error directive: %s", token.string ); + return qfalse; +} //end of the function PC_Directive_error +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_Directive_pragma( source_t *source ) { + token_t token; + + SourceWarning( source, "#pragma directive not supported" ); + while ( PC_ReadLine( source, &token ) ) ; + return qtrue; +} //end of the function PC_Directive_pragma +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void UnreadSignToken( source_t *source ) { + token_t token; + + token.line = source->scriptstack->line; + token.whitespace_p = source->scriptstack->script_p; + token.endwhitespace_p = source->scriptstack->script_p; + token.linescrossed = 0; + strcpy( token.string, "-" ); + token.type = TT_PUNCTUATION; + token.subtype = P_SUB; + PC_UnreadSourceToken( source, &token ); +} //end of the function UnreadSignToken +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_Directive_eval( source_t *source ) { + signed long int value; + token_t token; + + if ( !PC_Evaluate( source, &value, NULL, qtrue ) ) { + return qfalse; + } + // + token.line = source->scriptstack->line; + token.whitespace_p = source->scriptstack->script_p; + token.endwhitespace_p = source->scriptstack->script_p; + token.linescrossed = 0; + sprintf( token.string, "%d", abs( value ) ); + token.type = TT_NUMBER; + token.subtype = TT_INTEGER | TT_LONG | TT_DECIMAL; + PC_UnreadSourceToken( source, &token ); + if ( value < 0 ) { + UnreadSignToken( source ); + } + return qtrue; +} //end of the function PC_Directive_eval +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_Directive_evalfloat( source_t *source ) { + double value; + token_t token; + + if ( !PC_Evaluate( source, NULL, &value, qfalse ) ) { + return qfalse; + } + token.line = source->scriptstack->line; + token.whitespace_p = source->scriptstack->script_p; + token.endwhitespace_p = source->scriptstack->script_p; + token.linescrossed = 0; + sprintf( token.string, "%1.2f", fabs( value ) ); + token.type = TT_NUMBER; + token.subtype = TT_FLOAT | TT_LONG | TT_DECIMAL; + PC_UnreadSourceToken( source, &token ); + if ( value < 0 ) { + UnreadSignToken( source ); + } + return qtrue; +} //end of the function PC_Directive_evalfloat +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +directive_t directives[20] = +{ + {"if", PC_Directive_if}, + {"ifdef", PC_Directive_ifdef}, + {"ifndef", PC_Directive_ifndef}, + {"elif", PC_Directive_elif}, + {"else", PC_Directive_else}, + {"endif", PC_Directive_endif}, + {"include", PC_Directive_include}, + {"define", PC_Directive_define}, + {"undef", PC_Directive_undef}, + {"line", PC_Directive_line}, + {"error", PC_Directive_error}, + {"pragma", PC_Directive_pragma}, + {"eval", PC_Directive_eval}, + {"evalfloat", PC_Directive_evalfloat}, + {NULL, NULL} +}; + +int PC_ReadDirective( source_t *source ) { + token_t token; + int i; + + //read the directive name + if ( !PC_ReadSourceToken( source, &token ) ) { + SourceError( source, "found # without name" ); + return qfalse; + } //end if + //directive name must be on the same line + if ( token.linescrossed > 0 ) { + PC_UnreadSourceToken( source, &token ); + SourceError( source, "found # at end of line" ); + return qfalse; + } //end if + //if if is a name + if ( token.type == TT_NAME ) { + //find the precompiler directive + for ( i = 0; directives[i].name; i++ ) + { + if ( !strcmp( directives[i].name, token.string ) ) { + return directives[i].func( source ); + } //end if + } //end for + } //end if + SourceError( source, "unknown precompiler directive %s", token.string ); + return qfalse; +} //end of the function PC_ReadDirective +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_DollarDirective_evalint( source_t *source ) { + signed long int value; + token_t token; + + if ( !PC_DollarEvaluate( source, &value, NULL, qtrue ) ) { + return qfalse; + } + // + token.line = source->scriptstack->line; + token.whitespace_p = source->scriptstack->script_p; + token.endwhitespace_p = source->scriptstack->script_p; + token.linescrossed = 0; + sprintf( token.string, "%d", abs( value ) ); + token.type = TT_NUMBER; + token.subtype = TT_INTEGER | TT_LONG | TT_DECIMAL; +#ifdef NUMBERVALUE + token.intvalue = value; + token.floatvalue = value; +#endif //NUMBERVALUE + PC_UnreadSourceToken( source, &token ); + if ( value < 0 ) { + UnreadSignToken( source ); + } + return qtrue; +} //end of the function PC_DollarDirective_evalint +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_DollarDirective_evalfloat( source_t *source ) { + double value; + token_t token; + + if ( !PC_DollarEvaluate( source, NULL, &value, qfalse ) ) { + return qfalse; + } + token.line = source->scriptstack->line; + token.whitespace_p = source->scriptstack->script_p; + token.endwhitespace_p = source->scriptstack->script_p; + token.linescrossed = 0; + sprintf( token.string, "%1.2f", fabs( value ) ); + token.type = TT_NUMBER; + token.subtype = TT_FLOAT | TT_LONG | TT_DECIMAL; +#ifdef NUMBERVALUE + token.intvalue = (unsigned long) value; + token.floatvalue = value; +#endif //NUMBERVALUE + PC_UnreadSourceToken( source, &token ); + if ( value < 0 ) { + UnreadSignToken( source ); + } + return qtrue; +} //end of the function PC_DollarDirective_evalfloat +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +directive_t dollardirectives[20] = +{ + {"evalint", PC_DollarDirective_evalint}, + {"evalfloat", PC_DollarDirective_evalfloat}, + {NULL, NULL} +}; + +int PC_ReadDollarDirective( source_t *source ) { + token_t token; + int i; + + //read the directive name + if ( !PC_ReadSourceToken( source, &token ) ) { + SourceError( source, "found $ without name" ); + return qfalse; + } //end if + //directive name must be on the same line + if ( token.linescrossed > 0 ) { + PC_UnreadSourceToken( source, &token ); + SourceError( source, "found $ at end of line" ); + return qfalse; + } //end if + //if if is a name + if ( token.type == TT_NAME ) { + //find the precompiler directive + for ( i = 0; dollardirectives[i].name; i++ ) + { + if ( !strcmp( dollardirectives[i].name, token.string ) ) { + return dollardirectives[i].func( source ); + } //end if + } //end for + } //end if + PC_UnreadSourceToken( source, &token ); + SourceError( source, "unknown precompiler directive %s", token.string ); + return qfalse; +} //end of the function PC_ReadDirective + +#ifdef QUAKEC +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int BuiltinFunction( source_t *source ) { + token_t token; + + if ( !PC_ReadSourceToken( source, &token ) ) { + return qfalse; + } + if ( token.type == TT_NUMBER ) { + PC_UnreadSourceToken( source, &token ); + return qtrue; + } //end if + else + { + PC_UnreadSourceToken( source, &token ); + return qfalse; + } //end else +} //end of the function BuiltinFunction +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int QuakeCMacro( source_t *source ) { + int i; + token_t token; + + if ( !PC_ReadSourceToken( source, &token ) ) { + return qtrue; + } + if ( token.type != TT_NAME ) { + PC_UnreadSourceToken( source, &token ); + return qtrue; + } //end if + //find the precompiler directive + for ( i = 0; dollardirectives[i].name; i++ ) + { + if ( !strcmp( dollardirectives[i].name, token.string ) ) { + PC_UnreadSourceToken( source, &token ); + return qfalse; + } //end if + } //end for + PC_UnreadSourceToken( source, &token ); + return qtrue; +} //end of the function QuakeCMacro +#endif //QUAKEC +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_ReadToken( source_t *source, token_t *token ) { + define_t *define; + + while ( 1 ) + { + if ( !PC_ReadSourceToken( source, token ) ) { + return qfalse; + } + + //check for precompiler directives + if ( token->type == TT_PUNCTUATION && *token->string == '#' ) { +#ifdef SCREWUP // Ridah, skip all # directives + while ( PC_ReadLine( source, token ) ) ; + continue; +#endif // SCREWUP + +#ifdef QUAKEC + if ( !BuiltinFunction( source ) ) +#endif //QUAKC + { + //read the precompiler directive + if ( !PC_ReadDirective( source ) ) { + return qfalse; + } + continue; + } //end if + } //end if + if ( token->type == TT_PUNCTUATION && *token->string == '$' ) { +#ifdef QUAKEC + if ( !QuakeCMacro( source ) ) +#endif //QUAKEC + { + //read the precompiler directive + if ( !PC_ReadDollarDirective( source ) ) { + return qfalse; + } + continue; + } //end if + } //end if + //if skipping source because of conditional compilation + if ( source->skip ) { + continue; + } + //if the token is a name + if ( token->type == TT_NAME ) { + //check if the name is a define macro +#if DEFINEHASHING + define = PC_FindHashedDefine( source->definehash, token->string ); +#else + define = PC_FindDefine( source->defines, token->string ); +#endif //DEFINEHASHING + //if it is a define macro + if ( define ) { + //expand the defined macro + if ( !PC_ExpandDefineIntoSource( source, define ) ) { + return qfalse; + } + continue; + } //end if + } //end if + //copy token for unreading + memcpy( &source->token, token, sizeof( token_t ) ); + //found a token + return qtrue; + } //end while +} //end of the function PC_ReadToken +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_ExpectTokenString( source_t *source, char *string ) { + token_t token; + + if ( !PC_ReadToken( source, &token ) ) { + SourceError( source, "couldn't find expected %s", string ); + return qfalse; + } //end if + + if ( strcmp( token.string, string ) ) { + SourceError( source, "expected %s, found %s", string, token.string ); + return qfalse; + } //end if + return qtrue; +} //end of the function PC_ExpectTokenString +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_ExpectTokenType( source_t *source, int type, int subtype, token_t *token ) { + char str[MAX_TOKEN]; + + if ( !PC_ReadToken( source, token ) ) { + SourceError( source, "couldn't read expected token" ); + return qfalse; + } //end if + + if ( token->type != type ) { + strcpy( str, "" ); + if ( type == TT_STRING ) { + strcpy( str, "string" ); + } + if ( type == TT_LITERAL ) { + strcpy( str, "literal" ); + } + if ( type == TT_NUMBER ) { + strcpy( str, "number" ); + } + if ( type == TT_NAME ) { + strcpy( str, "name" ); + } + if ( type == TT_PUNCTUATION ) { + strcpy( str, "punctuation" ); + } + SourceError( source, "expected a %s, found %s", str, token->string ); + return qfalse; + } //end if + if ( token->type == TT_NUMBER ) { + if ( ( token->subtype & subtype ) != subtype ) { + if ( subtype & TT_DECIMAL ) { + strcpy( str, "decimal" ); + } + if ( subtype & TT_HEX ) { + strcpy( str, "hex" ); + } + if ( subtype & TT_OCTAL ) { + strcpy( str, "octal" ); + } + if ( subtype & TT_BINARY ) { + strcpy( str, "binary" ); + } + if ( subtype & TT_LONG ) { + strcat( str, " long" ); + } + if ( subtype & TT_UNSIGNED ) { + strcat( str, " unsigned" ); + } + if ( subtype & TT_FLOAT ) { + strcat( str, " float" ); + } + if ( subtype & TT_INTEGER ) { + strcat( str, " integer" ); + } + SourceError( source, "expected %s, found %s", str, token->string ); + return qfalse; + } //end if + } //end if + else if ( token->type == TT_PUNCTUATION ) { + if ( token->subtype != subtype ) { + SourceError( source, "found %s", token->string ); + return qfalse; + } //end if + } //end else if + return qtrue; +} //end of the function PC_ExpectTokenType +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_ExpectAnyToken( source_t *source, token_t *token ) { + if ( !PC_ReadToken( source, token ) ) { + SourceError( source, "couldn't read expected token" ); + return qfalse; + } //end if + else + { + return qtrue; + } //end else +} //end of the function PC_ExpectAnyToken +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_CheckTokenString( source_t *source, char *string ) { + token_t tok; + + if ( !PC_ReadToken( source, &tok ) ) { + return qfalse; + } + //if the token is available + if ( !strcmp( tok.string, string ) ) { + return qtrue; + } + // + PC_UnreadSourceToken( source, &tok ); + return qfalse; +} //end of the function PC_CheckTokenString +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_CheckTokenType( source_t *source, int type, int subtype, token_t *token ) { + token_t tok; + + if ( !PC_ReadToken( source, &tok ) ) { + return qfalse; + } + //if the type matches + if ( tok.type == type && + ( tok.subtype & subtype ) == subtype ) { + memcpy( token, &tok, sizeof( token_t ) ); + return qtrue; + } //end if + // + PC_UnreadSourceToken( source, &tok ); + return qfalse; +} //end of the function PC_CheckTokenType +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_SkipUntilString( source_t *source, char *string ) { + token_t token; + + while ( PC_ReadToken( source, &token ) ) + { + if ( !strcmp( token.string, string ) ) { + return qtrue; + } + } //end while + return qfalse; +} //end of the function PC_SkipUntilString +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void PC_UnreadLastToken( source_t *source ) { + PC_UnreadSourceToken( source, &source->token ); +} //end of the function PC_UnreadLastToken +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void PC_UnreadToken( source_t *source, token_t *token ) { + PC_UnreadSourceToken( source, token ); +} //end of the function PC_UnreadToken +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void PC_SetIncludePath( source_t *source, char *path ) { + strncpy( source->includepath, path, _MAX_PATH ); + //add trailing path seperator + if ( source->includepath[strlen( source->includepath ) - 1] != '\\' && + source->includepath[strlen( source->includepath ) - 1] != '/' ) { + strcat( source->includepath, PATHSEPERATOR_STR ); + } //end if +} //end of the function PC_SetIncludePath +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void PC_SetPunctuations( source_t *source, punctuation_t *p ) { + source->punctuations = p; +} //end of the function PC_SetPunctuations +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +source_t *LoadSourceFile( char *filename ) { + source_t *source; + script_t *script; + + PC_InitTokenHeap(); + + script = LoadScriptFile( filename ); + if ( !script ) { + return NULL; + } + + script->next = NULL; + + source = (source_t *) GetMemory( sizeof( source_t ) ); + memset( source, 0, sizeof( source_t ) ); + + strncpy( source->filename, filename, _MAX_PATH ); + source->scriptstack = script; + source->tokens = NULL; + source->defines = NULL; + source->indentstack = NULL; + source->skip = 0; + +#if DEFINEHASHING + source->definehash = GetClearedMemory( DEFINEHASHSIZE * sizeof( define_t * ) ); +#endif //DEFINEHASHING + PC_AddGlobalDefinesToSource( source ); + return source; +} //end of the function LoadSourceFile +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +source_t *LoadSourceMemory( char *ptr, int length, char *name ) { + source_t *source; + script_t *script; + + PC_InitTokenHeap(); + + script = LoadScriptMemory( ptr, length, name ); + if ( !script ) { + return NULL; + } + script->next = NULL; + + source = (source_t *) GetMemory( sizeof( source_t ) ); + memset( source, 0, sizeof( source_t ) ); + + strncpy( source->filename, name, _MAX_PATH ); + source->scriptstack = script; + source->tokens = NULL; + source->defines = NULL; + source->indentstack = NULL; + source->skip = 0; + +#if DEFINEHASHING + source->definehash = GetClearedMemory( DEFINEHASHSIZE * sizeof( define_t * ) ); +#endif //DEFINEHASHING + PC_AddGlobalDefinesToSource( source ); + return source; +} //end of the function LoadSourceMemory +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void FreeSource( source_t *source ) { + script_t *script; + token_t *token; + define_t *define; + indent_t *indent; + int i; + + //PC_PrintDefineHashTable(source->definehash); + //free all the scripts + while ( source->scriptstack ) + { + script = source->scriptstack; + source->scriptstack = source->scriptstack->next; + FreeScript( script ); + } //end for + //free all the tokens + while ( source->tokens ) + { + token = source->tokens; + source->tokens = source->tokens->next; + PC_FreeToken( token ); + } //end for +#if DEFINEHASHING + for ( i = 0; i < DEFINEHASHSIZE; i++ ) + { + while ( source->definehash[i] ) + { + define = source->definehash[i]; + source->definehash[i] = source->definehash[i]->hashnext; + PC_FreeDefine( define ); + } //end while + } //end for +#else //DEFINEHASHING + //free all defines + while ( source->defines ) + { + define = source->defines; + source->defines = source->defines->next; + PC_FreeDefine( define ); + } //end for +#endif //DEFINEHASHING + //free all indents + while ( source->indentstack ) + { + indent = source->indentstack; + source->indentstack = source->indentstack->next; + FreeMemory( indent ); + } //end for +#if DEFINEHASHING + // + if ( source->definehash ) { + FreeMemory( source->definehash ); + } +#endif //DEFINEHASHING + //free the source itself + FreeMemory( source ); +} //end of the function FreeSource + diff --git a/Projects/Android/jni/rtcw/src/extractfuncs/l_precomp.h b/Projects/Android/jni/rtcw/src/extractfuncs/l_precomp.h new file mode 100644 index 0000000..1d2b9ea --- /dev/null +++ b/Projects/Android/jni/rtcw/src/extractfuncs/l_precomp.h @@ -0,0 +1,158 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +/***************************************************************************** + * name: l_precomp.h + * + * desc: pre compiler + * + * + *****************************************************************************/ + +#ifndef _MAX_PATH + #define MAX_PATH MAX_QPATH +#endif + +#ifndef PATH_SEPERATORSTR + #if defined( WIN32 ) | defined( _WIN32 ) | defined( __NT__ ) | defined( __WINDOWS__ ) | defined( __WINDOWS_386__ ) + #define PATHSEPERATOR_STR "\\" + #else + #define PATHSEPERATOR_STR "/" + #endif +#endif +#ifndef PATH_SEPERATORCHAR + #if defined( WIN32 ) | defined( _WIN32 ) | defined( __NT__ ) | defined( __WINDOWS__ ) | defined( __WINDOWS_386__ ) + #define PATHSEPERATOR_CHAR '\\' + #else + #define PATHSEPERATOR_CHAR '/' + #endif +#endif + + +#define DEFINE_FIXED 0x0001 + +#define BUILTIN_LINE 1 +#define BUILTIN_FILE 2 +#define BUILTIN_DATE 3 +#define BUILTIN_TIME 4 +#define BUILTIN_STDC 5 + +#define INDENT_IF 0x0001 +#define INDENT_ELSE 0x0002 +#define INDENT_ELIF 0x0004 +#define INDENT_IFDEF 0x0008 +#define INDENT_IFNDEF 0x0010 + +//macro definitions +typedef struct define_s +{ + char *name; //define name + int flags; //define flags + int builtin; // > 0 if builtin define + int numparms; //number of define parameters + token_t *parms; //define parameters + token_t *tokens; //macro tokens (possibly containing parm tokens) + struct define_s *next; //next defined macro in a list + struct define_s *hashnext; //next define in the hash chain +} define_t; + +//indents +//used for conditional compilation directives: +//#if, #else, #elif, #ifdef, #ifndef +typedef struct indent_s +{ + int type; //indent type + int skip; //true if skipping current indent + script_t *script; //script the indent was in + struct indent_s *next; //next indent on the indent stack +} indent_t; + +//source file +typedef struct source_s +{ + char filename[_MAX_PATH]; //file name of the script + char includepath[_MAX_PATH]; //path to include files + punctuation_t *punctuations; //punctuations to use + script_t *scriptstack; //stack with scripts of the source + token_t *tokens; //tokens to read first + define_t *defines; //list with macro definitions + define_t **definehash; //hash chain with defines + indent_t *indentstack; //stack with indents + int skip; // > 0 if skipping conditional code + token_t token; //last read token +} source_t; + + +//read a token from the source +int PC_ReadToken( source_t *source, token_t *token ); +//expect a certain token +int PC_ExpectTokenString( source_t *source, char *string ); +//expect a certain token type +int PC_ExpectTokenType( source_t *source, int type, int subtype, token_t *token ); +//expect a token +int PC_ExpectAnyToken( source_t *source, token_t *token ); +//returns true when the token is available +int PC_CheckTokenString( source_t *source, char *string ); +//returns true an reads the token when a token with the given type is available +int PC_CheckTokenType( source_t *source, int type, int subtype, token_t *token ); +//skip tokens until the given token string is read +int PC_SkipUntilString( source_t *source, char *string ); +//unread the last token read from the script +void PC_UnreadLastToken( source_t *source ); +//unread the given token +void PC_UnreadToken( source_t *source, token_t *token ); +//read a token only if on the same line, lines are concatenated with a slash +int PC_ReadLine( source_t *source, token_t *token ); +//returns true if there was a white space in front of the token +int PC_WhiteSpaceBeforeToken( token_t *token ); +//add a define to the source +int PC_AddDefine( source_t *source, char *string ); +//add a globals define that will be added to all opened sources +int PC_AddGlobalDefine( char *string ); +//remove the given global define +int PC_RemoveGlobalDefine( char *name ); +//remove all globals defines +void PC_RemoveAllGlobalDefines( void ); +//add builtin defines +void PC_AddBuiltinDefines( source_t *source ); +//set the source include path +void PC_SetIncludePath( source_t *source, char *path ); +//set the punction set +void PC_SetPunctuations( source_t *source, punctuation_t *p ); +//load a source file +source_t *LoadSourceFile( char *filename ); +//load a source from memory +source_t *LoadSourceMemory( char *ptr, int length, char *name ); +//free the given source +void FreeSource( source_t *source ); +//print a source error +void QDECL SourceError( source_t *source, char *str, ... ); +//print a source warning +void QDECL SourceWarning( source_t *source, char *str, ... ); + diff --git a/Projects/Android/jni/rtcw/src/extractfuncs/l_script.c b/Projects/Android/jni/rtcw/src/extractfuncs/l_script.c new file mode 100644 index 0000000..e1b4308 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/extractfuncs/l_script.c @@ -0,0 +1,1419 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +/***************************************************************************** + * name: l_script.c + * + * desc: lexicographical parser + * + * + *****************************************************************************/ + +//#define SCREWUP +//#define BOTLIB +//#define MEQCC +//#define BSPC + +#ifdef SCREWUP +#include +#include +#include +#include +#include +#include "l_memory.h" +#include "l_script.h" + +typedef enum {qfalse, qtrue} qboolean; + +#endif //SCREWUP + +#ifdef BOTLIB +//include files for usage in the bot library +#include "../game/q_shared.h" +#include "botlib.h" +#include "be_interface.h" +#include "l_script.h" +#include "l_memory.h" +#include "l_log.h" +#include "l_libvar.h" +#endif //BOTLIB + +#ifdef MEQCC +//include files for usage in MrElusive's QuakeC Compiler +#include "qcc.h" +#include "l_script.h" +#include "l_memory.h" +#include "l_log.h" + +#define qtrue true +#define qfalse false +#endif //MEQCC + +#ifdef BSPC +//include files for usage in the BSP Converter +#include "../bspc/qbsp.h" +#include "../bspc/l_log.h" +#include "../bspc/l_mem.h" + +#define qtrue true +#define qfalse false +#endif //BSPC + + +#define PUNCTABLE + +//longer punctuations first +punctuation_t default_punctuations[] = +{ + //binary operators + {">>=",P_RSHIFT_ASSIGN, NULL}, + {"<<=",P_LSHIFT_ASSIGN, NULL}, + // + {"...",P_PARMS, NULL}, + //define merge operator + {"##",P_PRECOMPMERGE, NULL}, + //logic operators + {"&&",P_LOGIC_AND, NULL}, + {"||",P_LOGIC_OR, NULL}, + {">=",P_LOGIC_GEQ, NULL}, + {"<=",P_LOGIC_LEQ, NULL}, + {"==",P_LOGIC_EQ, NULL}, + {"!=",P_LOGIC_UNEQ, NULL}, + //arithmatic operators + {"*=",P_MUL_ASSIGN, NULL}, + {"/=",P_DIV_ASSIGN, NULL}, + {"%=",P_MOD_ASSIGN, NULL}, + {"+=",P_ADD_ASSIGN, NULL}, + {"-=",P_SUB_ASSIGN, NULL}, + {"++",P_INC, NULL}, + {"--",P_DEC, NULL}, + //binary operators + {"&=",P_BIN_AND_ASSIGN, NULL}, + {"|=",P_BIN_OR_ASSIGN, NULL}, + {"^=",P_BIN_XOR_ASSIGN, NULL}, + {">>",P_RSHIFT, NULL}, + {"<<",P_LSHIFT, NULL}, + //reference operators + {"->",P_POINTERREF, NULL}, + //C++ + {"::",P_CPP1, NULL}, + {".*",P_CPP2, NULL}, + //arithmatic operators + {"*",P_MUL, NULL}, + {"/",P_DIV, NULL}, + {"%",P_MOD, NULL}, + {"+",P_ADD, NULL}, + {"-",P_SUB, NULL}, + {"=",P_ASSIGN, NULL}, + //binary operators + {"&",P_BIN_AND, NULL}, + {"|",P_BIN_OR, NULL}, + {"^",P_BIN_XOR, NULL}, + {"~",P_BIN_NOT, NULL}, + //logic operators + {"!",P_LOGIC_NOT, NULL}, + {">",P_LOGIC_GREATER, NULL}, + {"<",P_LOGIC_LESS, NULL}, + //reference operator + {".",P_REF, NULL}, + //seperators + {",",P_COMMA, NULL}, + {";",P_SEMICOLON, NULL}, + //label indication + {":",P_COLON, NULL}, + //if statement + {"?",P_QUESTIONMARK, NULL}, + //embracements + {"(",P_PARENTHESESOPEN, NULL}, + {")",P_PARENTHESESCLOSE, NULL}, + {"{",P_BRACEOPEN, NULL}, + {"}",P_BRACECLOSE, NULL}, + {"[",P_SQBRACKETOPEN, NULL}, + {"]",P_SQBRACKETCLOSE, NULL}, + // + {"\\",P_BACKSLASH, NULL}, + //precompiler operator + {"#",P_PRECOMP, NULL}, +#ifdef DOLLAR + {"$",P_DOLLAR, NULL}, +#endif //DOLLAR + {NULL, 0} +}; + +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void PS_CreatePunctuationTable( script_t *script, punctuation_t *punctuations ) { + int i; + punctuation_t *p, *lastp, *newp; + + //get memory for the table + if ( !script->punctuationtable ) { + script->punctuationtable = (punctuation_t **) + GetMemory( 256 * sizeof( punctuation_t * ) ); + } + memset( script->punctuationtable, 0, 256 * sizeof( punctuation_t * ) ); + //add the punctuations in the list to the punctuation table + for ( i = 0; punctuations[i].p; i++ ) + { + newp = &punctuations[i]; + lastp = NULL; + //sort the punctuations in this table entry on length (longer punctuations first) + for ( p = script->punctuationtable[(unsigned int) newp->p[0]]; p; p = p->next ) + { + if ( strlen( p->p ) < strlen( newp->p ) ) { + newp->next = p; + if ( lastp ) { + lastp->next = newp; + } else { script->punctuationtable[(unsigned int) newp->p[0]] = newp;} + break; + } //end if + lastp = p; + } //end for + if ( !p ) { + newp->next = NULL; + if ( lastp ) { + lastp->next = newp; + } else { script->punctuationtable[(unsigned int) newp->p[0]] = newp;} + } //end if + } //end for +} //end of the function PS_CreatePunctuationTable +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +char *PunctuationFromNum( script_t *script, int num ) { + int i; + + for ( i = 0; script->punctuations[i].p; i++ ) + { + if ( script->punctuations[i].n == num ) { + return script->punctuations[i].p; + } + } //end for + return "unkown punctuation"; +} //end of the function PunctuationFromNum +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void QDECL ScriptError( script_t *script, char *str, ... ) { + char text[1024]; + va_list ap; + + if ( script->flags & SCFL_NOERRORS ) { + return; + } + + va_start( ap, str ); + vsprintf( text, str, ap ); + va_end( ap ); +#ifdef BOTLIB + botimport.Print( PRT_ERROR, "file %s, line %d: %s\n", script->filename, script->line, text ); +#endif //BOTLIB +#ifdef MEQCC + printf( "error: file %s, line %d: %s\n", script->filename, script->line, text ); +#endif //MEQCC +#ifdef BSPC + Log_Print( "error: file %s, line %d: %s\n", script->filename, script->line, text ); +#endif //BSPC +} //end of the function ScriptError +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void QDECL ScriptWarning( script_t *script, char *str, ... ) { + char text[1024]; + va_list ap; + + if ( script->flags & SCFL_NOWARNINGS ) { + return; + } + + va_start( ap, str ); + vsprintf( text, str, ap ); + va_end( ap ); +#ifdef BOTLIB + botimport.Print( PRT_WARNING, "file %s, line %d: %s\n", script->filename, script->line, text ); +#endif //BOTLIB +#ifdef MEQCC + printf( "warning: file %s, line %d: %s\n", script->filename, script->line, text ); +#endif //MEQCC +#ifdef BSPC + Log_Print( "warning: file %s, line %d: %s\n", script->filename, script->line, text ); +#endif //BSPC +} //end of the function ScriptWarning +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void SetScriptPunctuations( script_t *script, punctuation_t *p ) { +#ifdef PUNCTABLE + if ( p ) { + PS_CreatePunctuationTable( script, p ); + } else { PS_CreatePunctuationTable( script, default_punctuations );} +#endif //PUNCTABLE + if ( p ) { + script->punctuations = p; + } else { script->punctuations = default_punctuations;} +} //end of the function SetScriptPunctuations +//============================================================================ +// Reads spaces, tabs, C-like comments etc. +// When a newline character is found the scripts line counter is increased. +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PS_ReadWhiteSpace( script_t *script ) { + while ( 1 ) + { + //skip white space + while ( *script->script_p <= ' ' ) + { + if ( !*script->script_p ) { + return 0; + } + if ( *script->script_p == '\n' ) { + script->line++; + } + script->script_p++; + } //end while + //skip comments + if ( *script->script_p == '/' ) { + //comments // + if ( *( script->script_p + 1 ) == '/' ) { + script->script_p++; + do + { + script->script_p++; + if ( !*script->script_p ) { + return 0; + } + } //end do + while ( *script->script_p != '\n' ); + script->line++; + script->script_p++; + if ( !*script->script_p ) { + return 0; + } + continue; + } //end if + //comments /* */ + else if ( *( script->script_p + 1 ) == '*' ) { + script->script_p++; + do + { + script->script_p++; + if ( !*script->script_p ) { + return 0; + } + if ( *script->script_p == '\n' ) { + script->line++; + } + } //end do + while ( !( *script->script_p == '*' && *( script->script_p + 1 ) == '/' ) ); + script->script_p++; + if ( !*script->script_p ) { + return 0; + } + script->script_p++; + if ( !*script->script_p ) { + return 0; + } + continue; + } //end if + } //end if + break; + } //end while + return 1; +} //end of the function PS_ReadWhiteSpace +//============================================================================ +// Reads an escape character. +// +// Parameter: script : script to read from +// ch : place to store the read escape character +// Returns: - +// Changes Globals: - +//============================================================================ +int PS_ReadEscapeCharacter( script_t *script, char *ch ) { + int c, val, i; + + //step over the leading '\\' + script->script_p++; + //determine the escape character + switch ( *script->script_p ) + { + case '\\': c = '\\'; break; + case 'n': c = '\n'; break; + case 'r': c = '\r'; break; + case 't': c = '\t'; break; + case 'v': c = '\v'; break; + case 'b': c = '\b'; break; + case 'f': c = '\f'; break; + case 'a': c = '\a'; break; + case '\'': c = '\''; break; + case '\"': c = '\"'; break; + case '\?': c = '\?'; break; + case 'x': + { + script->script_p++; + for ( i = 0, val = 0; ; i++, script->script_p++ ) + { + c = *script->script_p; + if ( c >= '0' && c <= '9' ) { + c = c - '0'; + } else if ( c >= 'A' && c <= 'Z' ) { + c = c - 'A' + 10; + } else if ( c >= 'a' && c <= 'z' ) { + c = c - 'a' + 10; + } else { break;} + val = ( val << 4 ) + c; + } //end for + script->script_p--; + if ( val > 0xFF ) { + ScriptWarning( script, "too large value in escape character" ); + val = 0xFF; + } //end if + c = val; + break; + } //end case + default: //NOTE: decimal ASCII code, NOT octal + { + if ( *script->script_p < '0' || *script->script_p > '9' ) { + ScriptError( script, "unknown escape char" ); + } + for ( i = 0, val = 0; ; i++, script->script_p++ ) + { + c = *script->script_p; + if ( c >= '0' && c <= '9' ) { + c = c - '0'; + } else { break;} + val = val * 10 + c; + } //end for + script->script_p--; + if ( val > 0xFF ) { + ScriptWarning( script, "too large value in escape character" ); + val = 0xFF; + } //end if + c = val; + break; + } //end default + } //end switch + //step over the escape character or the last digit of the number + script->script_p++; + //store the escape character + *ch = c; + //succesfully read escape character + return 1; +} //end of the function PS_ReadEscapeCharacter +//============================================================================ +// Reads C-like string. Escape characters are interpretted. +// Quotes are included with the string. +// Reads two strings with a white space between them as one string. +// +// Parameter: script : script to read from +// token : buffer to store the string +// Returns: qtrue when a string was read succesfully +// Changes Globals: - +//============================================================================ +int PS_ReadString( script_t *script, token_t *token, int quote ) { + int len, tmpline; + char *tmpscript_p; + + if ( quote == '\"' ) { + token->type = TT_STRING; + } else { token->type = TT_LITERAL;} + + len = 0; + //leading quote + token->string[len++] = *script->script_p++; + // + while ( 1 ) + { + //minus 2 because trailing double quote and zero have to be appended + if ( len >= MAX_TOKEN - 2 ) { + ScriptError( script, "string longer than MAX_TOKEN = %d", MAX_TOKEN ); + return 0; + } //end if + //if there is an escape character and + //if escape characters inside a string are allowed + if ( *script->script_p == '\\' && !( script->flags & SCFL_NOSTRINGESCAPECHARS ) ) { + if ( !PS_ReadEscapeCharacter( script, &token->string[len] ) ) { + token->string[len] = 0; + return 0; + } //end if + len++; + } //end if + //if a trailing quote + else if ( *script->script_p == quote ) { + //step over the double quote + script->script_p++; + //if white spaces in a string are not allowed + if ( script->flags & SCFL_NOSTRINGWHITESPACES ) { + break; + } + // + tmpscript_p = script->script_p; + tmpline = script->line; + //read unusefull stuff between possible two following strings + if ( !PS_ReadWhiteSpace( script ) ) { + script->script_p = tmpscript_p; + script->line = tmpline; + break; + } //end if + //if there's no leading double qoute + if ( *script->script_p != quote ) { + script->script_p = tmpscript_p; + script->line = tmpline; + break; + } //end if + //step over the new leading double quote + script->script_p++; + } //end if + else + { + if ( *script->script_p == '\0' ) { + token->string[len] = 0; + ScriptError( script, "missing trailing quote" ); + return 0; + } //end if + if ( *script->script_p == '\n' ) { + token->string[len] = 0; + ScriptError( script, "newline inside string %s", token->string ); + return 0; + } //end if + token->string[len++] = *script->script_p++; + } //end else + } //end while + //trailing quote + token->string[len++] = quote; + //end string with a zero + token->string[len] = '\0'; + //the sub type is the length of the string + token->subtype = len; + return 1; +} //end of the function PS_ReadString +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PS_ReadName( script_t *script, token_t *token ) { + int len = 0; + char c; + + token->type = TT_NAME; + do + { + token->string[len++] = *script->script_p++; + if ( len >= MAX_TOKEN ) { + ScriptError( script, "name longer than MAX_TOKEN = %d", MAX_TOKEN ); + return 0; + } //end if + c = *script->script_p; + } while ( ( c >= 'a' && c <= 'z' ) || + ( c >= 'A' && c <= 'Z' ) || + ( c >= '0' && c <= '9' ) || + c == '_' ); + token->string[len] = '\0'; + //the sub type is the length of the name + token->subtype = len; + return 1; +} //end of the function PS_ReadName +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void NumberValue( char *string, int subtype, unsigned long int *intvalue, + long double *floatvalue ) { + unsigned long int dotfound = 0; + + *intvalue = 0; + *floatvalue = 0; + //floating point number + if ( subtype & TT_FLOAT ) { + while ( *string ) + { + if ( *string == '.' ) { + if ( dotfound ) { + return; + } + dotfound = 10; + string++; + } //end if + if ( dotfound ) { + *floatvalue = *floatvalue + ( long double )( *string - '0' ) / + (long double) dotfound; + dotfound *= 10; + } //end if + else + { + *floatvalue = *floatvalue * 10.0 + ( long double )( *string - '0' ); + } //end else + string++; + } //end while + *intvalue = (unsigned long) *floatvalue; + } //end if + else if ( subtype & TT_DECIMAL ) { + while ( *string ) *intvalue = *intvalue * 10 + ( *string++ - '0' ); + *floatvalue = *intvalue; + } //end else if + else if ( subtype & TT_HEX ) { + //step over the leading 0x or 0X + string += 2; + while ( *string ) + { + *intvalue <<= 4; + if ( *string >= 'a' && *string <= 'f' ) { + *intvalue += *string - 'a' + 10; + } else if ( *string >= 'A' && *string <= 'F' ) { + *intvalue += *string - 'A' + 10; + } else { *intvalue += *string - '0';} + string++; + } //end while + *floatvalue = *intvalue; + } //end else if + else if ( subtype & TT_OCTAL ) { + //step over the first zero + string += 1; + while ( *string ) *intvalue = ( *intvalue << 3 ) + ( *string++ - '0' ); + *floatvalue = *intvalue; + } //end else if + else if ( subtype & TT_BINARY ) { + //step over the leading 0b or 0B + string += 2; + while ( *string ) *intvalue = ( *intvalue << 1 ) + ( *string++ - '0' ); + *floatvalue = *intvalue; + } //end else if +} //end of the function NumberValue +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PS_ReadNumber( script_t *script, token_t *token ) { + int len = 0, i; + int octal, dot; + char c; +// unsigned long int intvalue = 0; +// long double floatvalue = 0; + + token->type = TT_NUMBER; + //check for a hexadecimal number + if ( *script->script_p == '0' && + ( *( script->script_p + 1 ) == 'x' || + *( script->script_p + 1 ) == 'X' ) ) { + token->string[len++] = *script->script_p++; + token->string[len++] = *script->script_p++; + c = *script->script_p; + //hexadecimal + while ( ( c >= '0' && c <= '9' ) || + ( c >= 'a' && c <= 'f' ) || + ( c >= 'A' && c <= 'A' ) ) + { + token->string[len++] = *script->script_p++; + if ( len >= MAX_TOKEN ) { + ScriptError( script, "hexadecimal number longer than MAX_TOKEN = %d", MAX_TOKEN ); + return 0; + } //end if + c = *script->script_p; + } //end while + token->subtype |= TT_HEX; + } //end if +#ifdef BINARYNUMBERS + //check for a binary number + else if ( *script->script_p == '0' && + ( *( script->script_p + 1 ) == 'b' || + *( script->script_p + 1 ) == 'B' ) ) { + token->string[len++] = *script->script_p++; + token->string[len++] = *script->script_p++; + c = *script->script_p; + //hexadecimal + while ( c == '0' || c == '1' ) + { + token->string[len++] = *script->script_p++; + if ( len >= MAX_TOKEN ) { + ScriptError( script, "binary number longer than MAX_TOKEN = %d", MAX_TOKEN ); + return 0; + } //end if + c = *script->script_p; + } //end while + token->subtype |= TT_BINARY; + } //end if +#endif //BINARYNUMBERS + else //decimal or octal integer or floating point number + { + octal = qfalse; + dot = qfalse; + if ( *script->script_p == '0' ) { + octal = qtrue; + } + while ( 1 ) + { + token->string[len++] = *script->script_p++; + if ( len >= MAX_TOKEN ) { + ScriptError( script, "number longer than MAX_TOKEN = %d", MAX_TOKEN ); + return 0; + } //end if + c = *script->script_p; + if ( c == '.' ) { + dot = qtrue; + } else if ( c == '8' || c == '9' ) { + octal = qfalse; + } else if ( c < '0' || c > '9' ) { + break; + } + } //end while + if ( octal ) { + token->subtype |= TT_OCTAL; + } else { token->subtype |= TT_DECIMAL;} + if ( dot ) { + token->subtype |= TT_FLOAT; + } + } //end else + for ( i = 0; i < 2; i++ ) + { + c = *script->script_p; + //check for a LONG number + if ( c == 'l' || c == 'L' && + !( token->subtype & TT_LONG ) ) { + script->script_p++; + token->subtype |= TT_LONG; + } //end if + //check for an UNSIGNED number + else if ( c == 'u' || c == 'U' && + !( token->subtype & ( TT_UNSIGNED | TT_FLOAT ) ) ) { + script->script_p++; + token->subtype |= TT_UNSIGNED; + } //end if + } //end for + token->string[len] = '\0'; +#ifdef NUMBERVALUE + NumberValue( token->string, token->subtype, &token->intvalue, &token->floatvalue ); +#endif //NUMBERVALUE + if ( !( token->subtype & TT_FLOAT ) ) { + token->subtype |= TT_INTEGER; + } + return 1; +} //end of the function PS_ReadNumber +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PS_ReadLiteral( script_t *script, token_t *token ) { + token->type = TT_LITERAL; + //first quote + token->string[0] = *script->script_p++; + //check for end of file + if ( !*script->script_p ) { + ScriptError( script, "end of file before trailing \'" ); + return 0; + } //end if + //if it is an escape character + if ( *script->script_p == '\\' ) { + if ( !PS_ReadEscapeCharacter( script, &token->string[1] ) ) { + return 0; + } + } //end if + else + { + token->string[1] = *script->script_p++; + } //end else + //check for trailing quote + if ( *script->script_p != '\'' ) { + ScriptWarning( script, "too many characters in literal, ignored" ); + while ( *script->script_p && + *script->script_p != '\'' && + *script->script_p != '\n' ) + { + script->script_p++; + } //end while + if ( *script->script_p == '\'' ) { + script->script_p++; + } + } //end if + //store the trailing quote + token->string[2] = *script->script_p++; + //store trailing zero to end the string + token->string[3] = '\0'; + //the sub type is the integer literal value + token->subtype = token->string[1]; + // + return 1; +} //end of the function PS_ReadLiteral +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PS_ReadPunctuation( script_t *script, token_t *token ) { + int len; + char *p; + punctuation_t *punc; + +#ifdef PUNCTABLE + for ( punc = script->punctuationtable[(unsigned int)*script->script_p]; punc; punc = punc->next ) + { +#else + int i; + + for ( i = 0; script->punctuations[i].p; i++ ) + { + punc = &script->punctuations[i]; +#endif //PUNCTABLE + p = punc->p; + len = strlen( p ); + //if the script contains at least as much characters as the punctuation + if ( script->script_p + len <= script->end_p ) { + //if the script contains the punctuation + if ( !strncmp( script->script_p, p, len ) ) { + strncpy( token->string, p, MAX_TOKEN ); + script->script_p += len; + token->type = TT_PUNCTUATION; + //sub type is the number of the punctuation + token->subtype = punc->n; + return 1; + } //end if + } //end if + } //end for + return 0; +} //end of the function PS_ReadPunctuation +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PS_ReadPrimitive( script_t *script, token_t *token ) { + int len; + + len = 0; + while ( *script->script_p > ' ' && *script->script_p != ';' ) + { + if ( len >= MAX_TOKEN ) { + ScriptError( script, "primitive token longer than MAX_TOKEN = %d", MAX_TOKEN ); + return 0; + } //end if + token->string[len++] = *script->script_p++; + } //end while + token->string[len] = 0; + //copy the token into the script structure + memcpy( &script->token, token, sizeof( token_t ) ); + //primitive reading successfull + return 1; +} //end of the function PS_ReadPrimitive +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PS_ReadToken( script_t *script, token_t *token ) { + //if there is a token available (from UnreadToken) + if ( script->tokenavailable ) { + script->tokenavailable = 0; + memcpy( token, &script->token, sizeof( token_t ) ); + return 1; + } //end if + //save script pointer + script->lastscript_p = script->script_p; + //save line counter + script->lastline = script->line; + //clear the token stuff + memset( token, 0, sizeof( token_t ) ); + //start of the white space + script->whitespace_p = script->script_p; + token->whitespace_p = script->script_p; + //read unusefull stuff + if ( !PS_ReadWhiteSpace( script ) ) { + return 0; + } + //end of the white space + script->endwhitespace_p = script->script_p; + token->endwhitespace_p = script->script_p; + //line the token is on + token->line = script->line; + //number of lines crossed before token + token->linescrossed = script->line - script->lastline; + //if there is a leading double quote + if ( *script->script_p == '\"' ) { + if ( !PS_ReadString( script, token, '\"' ) ) { + return 0; + } + } //end if + //if an literal + else if ( *script->script_p == '\'' ) { + //if (!PS_ReadLiteral(script, token)) return 0; + if ( !PS_ReadString( script, token, '\'' ) ) { + return 0; + } + } //end if + //if there is a number + else if ( ( *script->script_p >= '0' && *script->script_p <= '9' ) || + ( *script->script_p == '.' && + ( *( script->script_p + 1 ) >= '0' && *( script->script_p + 1 ) <= '9' ) ) ) { + if ( !PS_ReadNumber( script, token ) ) { + return 0; + } + } //end if + //if this is a primitive script + else if ( script->flags & SCFL_PRIMITIVE ) { + return PS_ReadPrimitive( script, token ); + } //end else if + //if there is a name + else if ( ( *script->script_p >= 'a' && *script->script_p <= 'z' ) || + ( *script->script_p >= 'A' && *script->script_p <= 'Z' ) || + *script->script_p == '_' ) { + if ( !PS_ReadName( script, token ) ) { + return 0; + } + } //end if + //check for punctuations + else if ( !PS_ReadPunctuation( script, token ) ) { + ScriptError( script, "can't read token" ); + return 0; + } //end if + //copy the token into the script structure + memcpy( &script->token, token, sizeof( token_t ) ); + //succesfully read a token + return 1; +} //end of the function PS_ReadToken +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PS_ExpectTokenString( script_t *script, char *string ) { + token_t token; + + if ( !PS_ReadToken( script, &token ) ) { + ScriptError( script, "couldn't find expected %s", string ); + return 0; + } //end if + + if ( strcmp( token.string, string ) ) { + ScriptError( script, "expected %s, found %s", string, token.string ); + return 0; + } //end if + return 1; +} //end of the function PS_ExpectToken +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PS_ExpectTokenType( script_t *script, int type, int subtype, token_t *token ) { + char str[MAX_TOKEN]; + + if ( !PS_ReadToken( script, token ) ) { + ScriptError( script, "couldn't read expected token" ); + return 0; + } //end if + + if ( token->type != type ) { + if ( type == TT_STRING ) { + strcpy( str, "string" ); + } + if ( type == TT_LITERAL ) { + strcpy( str, "literal" ); + } + if ( type == TT_NUMBER ) { + strcpy( str, "number" ); + } + if ( type == TT_NAME ) { + strcpy( str, "name" ); + } + if ( type == TT_PUNCTUATION ) { + strcpy( str, "punctuation" ); + } + ScriptError( script, "expected a %s, found %s", str, token->string ); + return 0; + } //end if + if ( token->type == TT_NUMBER ) { + if ( ( token->subtype & subtype ) != subtype ) { + if ( subtype & TT_DECIMAL ) { + strcpy( str, "decimal" ); + } + if ( subtype & TT_HEX ) { + strcpy( str, "hex" ); + } + if ( subtype & TT_OCTAL ) { + strcpy( str, "octal" ); + } + if ( subtype & TT_BINARY ) { + strcpy( str, "binary" ); + } + if ( subtype & TT_LONG ) { + strcat( str, " long" ); + } + if ( subtype & TT_UNSIGNED ) { + strcat( str, " unsigned" ); + } + if ( subtype & TT_FLOAT ) { + strcat( str, " float" ); + } + if ( subtype & TT_INTEGER ) { + strcat( str, " integer" ); + } + ScriptError( script, "expected %s, found %s", str, token->string ); + return 0; + } //end if + } //end if + else if ( token->type == TT_PUNCTUATION ) { + if ( subtype < 0 ) { + ScriptError( script, "BUG: wrong punctuation subtype" ); + return 0; + } //end if + if ( token->subtype != subtype ) { + ScriptError( script, "expected %s, found %s", + script->punctuations[subtype], token->string ); + return 0; + } //end if + } //end else if + return 1; +} //end of the function PS_ExpectTokenType +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PS_ExpectAnyToken( script_t *script, token_t *token ) { + if ( !PS_ReadToken( script, token ) ) { + ScriptError( script, "couldn't read expected token" ); + return 0; + } //end if + else + { + return 1; + } //end else +} //end of the function PS_ExpectAnyToken +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PS_CheckTokenString( script_t *script, char *string ) { + token_t tok; + + if ( !PS_ReadToken( script, &tok ) ) { + return 0; + } + //if the token is available + if ( !strcmp( tok.string, string ) ) { + return 1; + } + //token not available + script->script_p = script->lastscript_p; + return 0; +} //end of the function PS_CheckTokenString +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PS_CheckTokenType( script_t *script, int type, int subtype, token_t *token ) { + token_t tok; + + if ( !PS_ReadToken( script, &tok ) ) { + return 0; + } + //if the type matches + if ( tok.type == type && + ( tok.subtype & subtype ) == subtype ) { + memcpy( token, &tok, sizeof( token_t ) ); + return 1; + } //end if + //token is not available + script->script_p = script->lastscript_p; + return 0; +} //end of the function PS_CheckTokenType +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PS_SkipUntilString( script_t *script, char *string ) { + token_t token; + + while ( PS_ReadToken( script, &token ) ) + { + if ( !strcmp( token.string, string ) ) { + return 1; + } + } //end while + return 0; +} //end of the function PS_SkipUntilString +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void PS_UnreadLastToken( script_t *script ) { + script->tokenavailable = 1; +} //end of the function UnreadLastToken +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void PS_UnreadToken( script_t *script, token_t *token ) { + memcpy( &script->token, token, sizeof( token_t ) ); + script->tokenavailable = 1; +} //end of the function UnreadToken +//============================================================================ +// returns the next character of the read white space, returns NULL if none +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +char PS_NextWhiteSpaceChar( script_t *script ) { + if ( script->whitespace_p != script->endwhitespace_p ) { + return *script->whitespace_p++; + } //end if + else + { + return 0; + } //end else +} //end of the function PS_NextWhiteSpaceChar +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void StripDoubleQuotes( char *string ) { + if ( *string == '\"' ) { + strcpy( string, string + 1 ); + } //end if + if ( string[strlen( string ) - 1] == '\"' ) { + string[strlen( string ) - 1] = '\0'; + } //end if +} //end of the function StripDoubleQuotes +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void StripSingleQuotes( char *string ) { + if ( *string == '\'' ) { + strcpy( string, string + 1 ); + } //end if + if ( string[strlen( string ) - 1] == '\'' ) { + string[strlen( string ) - 1] = '\0'; + } //end if +} //end of the function StripSingleQuotes +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +long double ReadSignedFloat( script_t *script ) { + token_t token; + long double sign = 1; + + PS_ExpectAnyToken( script, &token ); + if ( !strcmp( token.string, "-" ) ) { + sign = -1; + PS_ExpectTokenType( script, TT_NUMBER, 0, &token ); + } //end if + else if ( token.type != TT_NUMBER ) { + ScriptError( script, "expected float value, found %s\n", token.string ); + } //end else if + return sign * token.floatvalue; +} //end of the function ReadSignedFloat +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +signed long int ReadSignedInt( script_t *script ) { + token_t token; + signed long int sign = 1; + + PS_ExpectAnyToken( script, &token ); + if ( !strcmp( token.string, "-" ) ) { + sign = -1; + PS_ExpectTokenType( script, TT_NUMBER, TT_INTEGER, &token ); + } //end if + else if ( token.type != TT_NUMBER || token.subtype == TT_FLOAT ) { + ScriptError( script, "expected integer value, found %s\n", token.string ); + } //end else if + return sign * token.intvalue; +} //end of the function ReadSignedInt +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void SetScriptFlags( script_t *script, int flags ) { + script->flags = flags; +} //end of the function SetScriptFlags +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int GetScriptFlags( script_t *script ) { + return script->flags; +} //end of the function GetScriptFlags +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void ResetScript( script_t *script ) { + //pointer in script buffer + script->script_p = script->buffer; + //pointer in script buffer before reading token + script->lastscript_p = script->buffer; + //begin of white space + script->whitespace_p = NULL; + //end of white space + script->endwhitespace_p = NULL; + //set if there's a token available in script->token + script->tokenavailable = 0; + // + script->line = 1; + script->lastline = 1; + //clear the saved token + memset( &script->token, 0, sizeof( token_t ) ); +} //end of the function ResetScript +//============================================================================ +// returns true if at the end of the script +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int EndOfScript( script_t *script ) { + return script->script_p >= script->end_p; +} //end of the function EndOfScript +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int NumLinesCrossed( script_t *script ) { + return script->line - script->lastline; +} //end of the function NumLinesCrossed +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int ScriptSkipTo( script_t *script, char *value ) { + int len; + char firstchar; + + firstchar = *value; + len = strlen( value ); + do + { + if ( !PS_ReadWhiteSpace( script ) ) { + return 0; + } + if ( *script->script_p == firstchar ) { + if ( !strncmp( script->script_p, value, len ) ) { + return 1; + } //end if + } //end if + script->script_p++; + } while ( 1 ); +} //end of the function ScriptSkipTo +#ifndef BOTLIB +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int FileLength( FILE *fp ) { + int pos; + int end; + + pos = ftell( fp ); + fseek( fp, 0, SEEK_END ); + end = ftell( fp ); + fseek( fp, pos, SEEK_SET ); + + return end; +} //end of the function FileLength +#endif +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +script_t *LoadScriptFile( char *filename ) { +#ifdef BOTLIB + fileHandle_t fp; + char pathname[MAX_QPATH]; +#else + FILE *fp; +#endif + int length; + void *buffer; + script_t *script; + +#ifdef BOTLIB + Com_sprintf( pathname, MAX_QPATH, "botfiles/%s", filename ); + length = botimport.FS_FOpenFile( pathname, &fp, FS_READ ); + if ( !fp ) { + return NULL; + } +#else + fp = fopen( filename, "rb" ); + if ( !fp ) { + return NULL; + } + + length = FileLength( fp ); +#endif + + buffer = GetClearedMemory( sizeof( script_t ) + length + 1 ); + script = (script_t *) buffer; + memset( script, 0, sizeof( script_t ) ); + strcpy( script->filename, filename ); + script->buffer = (char *) buffer + sizeof( script_t ); + script->buffer[length] = 0; + script->length = length; + //pointer in script buffer + script->script_p = script->buffer; + //pointer in script buffer before reading token + script->lastscript_p = script->buffer; + //pointer to end of script buffer + script->end_p = &script->buffer[length]; + //set if there's a token available in script->token + script->tokenavailable = 0; + // + script->line = 1; + script->lastline = 1; + // + SetScriptPunctuations( script, NULL ); + // +#ifdef BOTLIB + botimport.FS_Read( script->buffer, length, fp ); + botimport.FS_FCloseFile( fp ); +#else + if ( fread( script->buffer, length, 1, fp ) != 1 ) { + FreeMemory( buffer ); + script = NULL; + } //end if + fclose( fp ); +#endif + // + return script; +} //end of the function LoadScriptFile +//============================================================================ +//load a script from the given memory with the given length +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +script_t *LoadScriptMemory( char *ptr, int length, char *name ) { + void *buffer; + script_t *script; + + buffer = GetClearedMemory( sizeof( script_t ) + length + 1 ); + script = (script_t *) buffer; + memset( script, 0, sizeof( script_t ) ); + strcpy( script->filename, name ); + script->buffer = (char *) buffer + sizeof( script_t ); + script->buffer[length] = 0; + script->length = length; + //pointer in script buffer + script->script_p = script->buffer; + //pointer in script buffer before reading token + script->lastscript_p = script->buffer; + //pointer to end of script buffer + script->end_p = &script->buffer[length]; + //set if there's a token available in script->token + script->tokenavailable = 0; + // + script->line = 1; + script->lastline = 1; + // + SetScriptPunctuations( script, NULL ); + // + memcpy( script->buffer, ptr, length ); + // + return script; +} //end of the function LoadScriptMemory +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void FreeScript( script_t *script ) { +#ifdef PUNCTABLE + if ( script->punctuationtable ) { + FreeMemory( script->punctuationtable ); + } +#endif //PUNCTABLE + FreeMemory( script ); +} //end of the function FreeScript diff --git a/Projects/Android/jni/rtcw/src/extractfuncs/l_script.h b/Projects/Android/jni/rtcw/src/extractfuncs/l_script.h new file mode 100644 index 0000000..78cb90a --- /dev/null +++ b/Projects/Android/jni/rtcw/src/extractfuncs/l_script.h @@ -0,0 +1,266 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +/***************************************************************************** + * name: l_script.h + * + * desc: lexicographical parser + * + * + *****************************************************************************/ + +// Ridah, can't get it to compile without this +#ifndef QDECL + +// for windows fastcall option +#define QDECL +//======================= WIN32 DEFINES ================================= +#ifdef WIN32 +#undef QDECL +#define QDECL __cdecl +#endif +#endif +// done. + +//undef if binary numbers of the form 0b... or 0B... are not allowed +#define BINARYNUMBERS +//undef if not using the token.intvalue and token.floatvalue +#define NUMBERVALUE +//use dollar sign also as punctuation +#define DOLLAR + +//maximum token length +#define MAX_TOKEN 1024 +//maximum path length +#ifndef MAX_QPATH + #define MAX_QPATH 64 +#endif +#ifndef _MAX_PATH + #define _MAX_PATH MAX_QPATH +#endif + +//script flags +#define SCFL_NOERRORS 0x0001 +#define SCFL_NOWARNINGS 0x0002 +#define SCFL_NOSTRINGWHITESPACES 0x0004 +#define SCFL_NOSTRINGESCAPECHARS 0x0008 +#define SCFL_PRIMITIVE 0x0010 +#define SCFL_NOBINARYNUMBERS 0x0020 +#define SCFL_NONUMBERVALUES 0x0040 + +//token types +#define TT_STRING 1 // string +#define TT_LITERAL 2 // literal +#define TT_NUMBER 3 // number +#define TT_NAME 4 // name +#define TT_PUNCTUATION 5 // punctuation + +//string sub type +//--------------- +// the length of the string +//literal sub type +//---------------- +// the ASCII code of the literal +//number sub type +//--------------- +#define TT_DECIMAL 0x0008 // decimal number +#define TT_HEX 0x0100 // hexadecimal number +#define TT_OCTAL 0x0200 // octal number +#ifdef BINARYNUMBERS +#define TT_BINARY 0x0400 // binary number +#endif //BINARYNUMBERS +#define TT_FLOAT 0x0800 // floating point number +#define TT_INTEGER 0x1000 // integer number +#define TT_LONG 0x2000 // long number +#define TT_UNSIGNED 0x4000 // unsigned number +//punctuation sub type +//-------------------- +#define P_RSHIFT_ASSIGN 1 +#define P_LSHIFT_ASSIGN 2 +#define P_PARMS 3 +#define P_PRECOMPMERGE 4 + +#define P_LOGIC_AND 5 +#define P_LOGIC_OR 6 +#define P_LOGIC_GEQ 7 +#define P_LOGIC_LEQ 8 +#define P_LOGIC_EQ 9 +#define P_LOGIC_UNEQ 10 + +#define P_MUL_ASSIGN 11 +#define P_DIV_ASSIGN 12 +#define P_MOD_ASSIGN 13 +#define P_ADD_ASSIGN 14 +#define P_SUB_ASSIGN 15 +#define P_INC 16 +#define P_DEC 17 + +#define P_BIN_AND_ASSIGN 18 +#define P_BIN_OR_ASSIGN 19 +#define P_BIN_XOR_ASSIGN 20 +#define P_RSHIFT 21 +#define P_LSHIFT 22 + +#define P_POINTERREF 23 +#define P_CPP1 24 +#define P_CPP2 25 +#define P_MUL 26 +#define P_DIV 27 +#define P_MOD 28 +#define P_ADD 29 +#define P_SUB 30 +#define P_ASSIGN 31 + +#define P_BIN_AND 32 +#define P_BIN_OR 33 +#define P_BIN_XOR 34 +#define P_BIN_NOT 35 + +#define P_LOGIC_NOT 36 +#define P_LOGIC_GREATER 37 +#define P_LOGIC_LESS 38 + +#define P_REF 39 +#define P_COMMA 40 +#define P_SEMICOLON 41 +#define P_COLON 42 +#define P_QUESTIONMARK 43 + +#define P_PARENTHESESOPEN 44 +#define P_PARENTHESESCLOSE 45 +#define P_BRACEOPEN 46 +#define P_BRACECLOSE 47 +#define P_SQBRACKETOPEN 48 +#define P_SQBRACKETCLOSE 49 +#define P_BACKSLASH 50 + +#define P_PRECOMP 51 +#define P_DOLLAR 52 +//name sub type +//------------- +// the length of the name + +//punctuation +typedef struct punctuation_s +{ + char *p; //punctuation character(s) + int n; //punctuation indication + struct punctuation_s *next; //next punctuation +} punctuation_t; + +//token +typedef struct token_s +{ + char string[MAX_TOKEN]; //available token + int type; //last read token type + int subtype; //last read token sub type +#ifdef NUMBERVALUE + unsigned long int intvalue; //integer value + long double floatvalue; //floating point value +#endif //NUMBERVALUE + char *whitespace_p; //start of white space before token + char *endwhitespace_p; //start of white space before token + int line; //line the token was on + int linescrossed; //lines crossed in white space + struct token_s *next; //next token in chain +} token_t; + +//script file +typedef struct script_s +{ + char filename[_MAX_PATH]; //file name of the script + char *buffer; //buffer containing the script + char *script_p; //current pointer in the script + char *end_p; //pointer to the end of the script + char *lastscript_p; //script pointer before reading token + char *whitespace_p; //begin of the white space + char *endwhitespace_p; //end of the white space + int length; //length of the script in bytes + int line; //current line in script + int lastline; //line before reading token + int tokenavailable; //set by UnreadLastToken + int flags; //several script flags + punctuation_t *punctuations; //the punctuations used in the script + punctuation_t **punctuationtable; + token_t token; //available token + struct script_s *next; //next script in a chain +} script_t; + +//read a token from the script +int PS_ReadToken( script_t *script, token_t *token ); +//expect a certain token +int PS_ExpectTokenString( script_t *script, char *string ); +//expect a certain token type +int PS_ExpectTokenType( script_t *script, int type, int subtype, token_t *token ); +//expect a token +int PS_ExpectAnyToken( script_t *script, token_t *token ); +//returns true when the token is available +int PS_CheckTokenString( script_t *script, char *string ); +//returns true an reads the token when a token with the given type is available +int PS_CheckTokenType( script_t *script, int type, int subtype, token_t *token ); +//skip tokens until the given token string is read +int PS_SkipUntilString( script_t *script, char *string ); +//unread the last token read from the script +void PS_UnreadLastToken( script_t *script ); +//unread the given token +void PS_UnreadToken( script_t *script, token_t *token ); +//returns the next character of the read white space, returns NULL if none +char PS_NextWhiteSpaceChar( script_t *script ); +//remove any leading and trailing double quotes from the token +void StripDoubleQuotes( char *string ); +//remove any leading and trailing single quotes from the token +void StripSingleQuotes( char *string ); +//read a possible signed integer +signed long int ReadSignedInt( script_t *script ); +//read a possible signed floating point number +long double ReadSignedFloat( script_t *script ); +//set an array with punctuations, NULL restores default C/C++ set +void SetScriptPunctuations( script_t *script, punctuation_t *p ); +//set script flags +void SetScriptFlags( script_t *script, int flags ); +//get script flags +int GetScriptFlags( script_t *script ); +//reset a script +void ResetScript( script_t *script ); +//returns true if at the end of the script +int EndOfScript( script_t *script ); +//returns a pointer to the punctuation with the given number +char *PunctuationFromNum( script_t *script, int num ); +//load a script from the given file at the given offset with the given length +script_t *LoadScriptFile( char *filename ); +//load a script from the given memory with the given length +script_t *LoadScriptMemory( char *ptr, int length, char *name ); +//free a script +void FreeScript( script_t *script ); +//print a script error with filename and line number +void QDECL ScriptError( script_t *script, char *str, ... ); +//print a script warning with filename and line number +void QDECL ScriptWarning( script_t *script, char *str, ... ); + + diff --git a/Projects/Android/jni/rtcw/src/extractfuncs/out/src/botlib/be_interface.h b/Projects/Android/jni/rtcw/src/extractfuncs/out/src/botlib/be_interface.h new file mode 100644 index 0000000..e2355ce --- /dev/null +++ b/Projects/Android/jni/rtcw/src/extractfuncs/out/src/botlib/be_interface.h @@ -0,0 +1,93 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +/***************************************************************************** + * name: be_interface.h + * + * desc: botlib interface + * + * + *****************************************************************************/ + +/* +"Do not go where the path leads, rather go where there's no track and leave a trail." + +"AAS (Area Awareness System)" + +"Part of the Gladiator is BoGuS (Bot Guidance System)" + +"ANSI (Advanced Navigational System Interface)" + +"to make things work the only thing you really have to do is think things work." + +"a madman is just someone living in another reality which isn't shared among many people" +*/ + +//#define DEBUG //debug code +#define RANDOMIZE //randomize bot behaviour +#if defined( WIN32 ) || defined( _WIN32 ) +#define AASZIP //allow reading directly from aasX.zip files +#endif +#define QUAKE2 //bot for Quake2 +//#define HALFLIFE //bot for Half-Life + +//========================================================== +// +// global variable structures +// +//========================================================== + +//FIXME: get rid of this global structure +typedef struct botlib_globals_s +{ + int botlibsetup; //true when the bot library has been setup + int maxentities; //maximum number of entities + int maxclients; //maximum number of clients + float time; //the global time +#ifdef DEBUG + qboolean debug; //true if debug is on + int goalareanum; + vec3_t goalorigin; + int runai; +#endif +} botlib_globals_t; + +//========================================================== +// +// global variables +// +//========================================================== + +extern botlib_globals_t botlibglobals; +extern botlib_import_t botimport; +extern int bot_developer; //true if developer is on + +// +int Sys_MilliSeconds( void ); + diff --git a/Projects/Android/jni/rtcw/src/extractfuncs/out/src/botlib/l_script.h b/Projects/Android/jni/rtcw/src/extractfuncs/out/src/botlib/l_script.h new file mode 100644 index 0000000..461276e --- /dev/null +++ b/Projects/Android/jni/rtcw/src/extractfuncs/out/src/botlib/l_script.h @@ -0,0 +1,268 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +/***************************************************************************** + * name: l_script.h + * + * desc: lexicographical parser + * + * + *****************************************************************************/ + +// Ridah, can't get it to compile without this +#ifndef QDECL + +// for windows fastcall option +#define QDECL +//======================= WIN32 DEFINES ================================= +#ifdef WIN32 +#undef QDECL +#define QDECL __cdecl +#endif +#endif +// done. + +//undef if binary numbers of the form 0b... or 0B... are not allowed +#define BINARYNUMBERS +//undef if not using the token.intvalue and token.floatvalue +#define NUMBERVALUE +//use dollar sign also as punctuation +#define DOLLAR + +//maximum token length +#define MAX_TOKEN 1024 +//maximum path length +#ifndef _MAX_PATH +// TTimo: used to be MAX_QPATH, which is the game filesystem max len, and not the OS max len + #define _MAX_PATH 1024 +#endif + + +//script flags +#define SCFL_NOERRORS 0x0001 +#define SCFL_NOWARNINGS 0x0002 +#define SCFL_NOSTRINGWHITESPACES 0x0004 +#define SCFL_NOSTRINGESCAPECHARS 0x0008 +#define SCFL_PRIMITIVE 0x0010 +#define SCFL_NOBINARYNUMBERS 0x0020 +#define SCFL_NONUMBERVALUES 0x0040 + +//token types +#define TT_STRING 1 // string +#define TT_LITERAL 2 // literal +#define TT_NUMBER 3 // number +#define TT_NAME 4 // name +#define TT_PUNCTUATION 5 // punctuation + +//string sub type +//--------------- +// the length of the string +//literal sub type +//---------------- +// the ASCII code of the literal +//number sub type +//--------------- +#define TT_DECIMAL 0x0008 // decimal number +#define TT_HEX 0x0100 // hexadecimal number +#define TT_OCTAL 0x0200 // octal number +#ifdef BINARYNUMBERS +#define TT_BINARY 0x0400 // binary number +#endif //BINARYNUMBERS +#define TT_FLOAT 0x0800 // floating point number +#define TT_INTEGER 0x1000 // integer number +#define TT_LONG 0x2000 // long number +#define TT_UNSIGNED 0x4000 // unsigned number +//punctuation sub type +//-------------------- +#define P_RSHIFT_ASSIGN 1 +#define P_LSHIFT_ASSIGN 2 +#define P_PARMS 3 +#define P_PRECOMPMERGE 4 + +#define P_LOGIC_AND 5 +#define P_LOGIC_OR 6 +#define P_LOGIC_GEQ 7 +#define P_LOGIC_LEQ 8 +#define P_LOGIC_EQ 9 +#define P_LOGIC_UNEQ 10 + +#define P_MUL_ASSIGN 11 +#define P_DIV_ASSIGN 12 +#define P_MOD_ASSIGN 13 +#define P_ADD_ASSIGN 14 +#define P_SUB_ASSIGN 15 +#define P_INC 16 +#define P_DEC 17 + +#define P_BIN_AND_ASSIGN 18 +#define P_BIN_OR_ASSIGN 19 +#define P_BIN_XOR_ASSIGN 20 +#define P_RSHIFT 21 +#define P_LSHIFT 22 + +#define P_POINTERREF 23 +#define P_CPP1 24 +#define P_CPP2 25 +#define P_MUL 26 +#define P_DIV 27 +#define P_MOD 28 +#define P_ADD 29 +#define P_SUB 30 +#define P_ASSIGN 31 + +#define P_BIN_AND 32 +#define P_BIN_OR 33 +#define P_BIN_XOR 34 +#define P_BIN_NOT 35 + +#define P_LOGIC_NOT 36 +#define P_LOGIC_GREATER 37 +#define P_LOGIC_LESS 38 + +#define P_REF 39 +#define P_COMMA 40 +#define P_SEMICOLON 41 +#define P_COLON 42 +#define P_QUESTIONMARK 43 + +#define P_PARENTHESESOPEN 44 +#define P_PARENTHESESCLOSE 45 +#define P_BRACEOPEN 46 +#define P_BRACECLOSE 47 +#define P_SQBRACKETOPEN 48 +#define P_SQBRACKETCLOSE 49 +#define P_BACKSLASH 50 + +#define P_PRECOMP 51 +#define P_DOLLAR 52 +//name sub type +//------------- +// the length of the name + +//punctuation +typedef struct punctuation_s +{ + char *p; //punctuation character(s) + int n; //punctuation indication + struct punctuation_s *next; //next punctuation +} punctuation_t; + +//token +typedef struct token_s +{ + char string[MAX_TOKEN]; //available token + int type; //last read token type + int subtype; //last read token sub type +#ifdef NUMBERVALUE + unsigned long int intvalue; //integer value + long double floatvalue; //floating point value +#endif //NUMBERVALUE + char *whitespace_p; //start of white space before token + char *endwhitespace_p; //start of white space before token + int line; //line the token was on + int linescrossed; //lines crossed in white space + struct token_s *next; //next token in chain +} token_t; + +//script file +typedef struct script_s +{ + char filename[_MAX_PATH]; //file name of the script + char *buffer; //buffer containing the script + char *script_p; //current pointer in the script + char *end_p; //pointer to the end of the script + char *lastscript_p; //script pointer before reading token + char *whitespace_p; //begin of the white space + char *endwhitespace_p; //end of the white space + int length; //length of the script in bytes + int line; //current line in script + int lastline; //line before reading token + int tokenavailable; //set by UnreadLastToken + int flags; //several script flags + punctuation_t *punctuations; //the punctuations used in the script + punctuation_t **punctuationtable; + token_t token; //available token + struct script_s *next; //next script in a chain +} script_t; + +//read a token from the script +int PS_ReadToken( script_t *script, token_t *token ); +//expect a certain token +int PS_ExpectTokenString( script_t *script, char *string ); +//expect a certain token type +int PS_ExpectTokenType( script_t *script, int type, int subtype, token_t *token ); +//expect a token +int PS_ExpectAnyToken( script_t *script, token_t *token ); +//returns true when the token is available +int PS_CheckTokenString( script_t *script, char *string ); +//returns true an reads the token when a token with the given type is available +int PS_CheckTokenType( script_t *script, int type, int subtype, token_t *token ); +//skip tokens until the given token string is read +int PS_SkipUntilString( script_t *script, char *string ); +//unread the last token read from the script +void PS_UnreadLastToken( script_t *script ); +//unread the given token +void PS_UnreadToken( script_t *script, token_t *token ); +//returns the next character of the read white space, returns NULL if none +char PS_NextWhiteSpaceChar( script_t *script ); +//remove any leading and trailing double quotes from the token +void StripDoubleQuotes( char *string ); +//remove any leading and trailing single quotes from the token +void StripSingleQuotes( char *string ); +//read a possible signed integer +signed long int ReadSignedInt( script_t *script ); +//read a possible signed floating point number +long double ReadSignedFloat( script_t *script ); +//set an array with punctuations, NULL restores default C/C++ set +void SetScriptPunctuations( script_t *script, punctuation_t *p ); +//set script flags +void SetScriptFlags( script_t *script, int flags ); +//get script flags +int GetScriptFlags( script_t *script ); +//reset a script +void ResetScript( script_t *script ); +//returns true if at the end of the script +int EndOfScript( script_t *script ); +//returns a pointer to the punctuation with the given number +char *PunctuationFromNum( script_t *script, int num ); +//load a script from the given file at the given offset with the given length +script_t *LoadScriptFile( const char *filename ); +//load a script from the given memory with the given length +script_t *LoadScriptMemory( char *ptr, int length, char *name ); +//free a script +void FreeScript( script_t *script ); +//set the base folder to load files from +void PS_SetBaseFolder( char *path ); +//print a script error with filename and line number +void QDECL ScriptError( script_t *script, char *str, ... ); +//print a script warning with filename and line number +void QDECL ScriptWarning( script_t *script, char *str, ... ); + + + diff --git a/Projects/Android/jni/rtcw/src/extractfuncs/out/src/bspc/l_bsp_ent.h b/Projects/Android/jni/rtcw/src/extractfuncs/out/src/bspc/l_bsp_ent.h new file mode 100644 index 0000000..42257a4 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/extractfuncs/out/src/bspc/l_bsp_ent.h @@ -0,0 +1,65 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +#ifndef MAX_MAP_ENTITIES +#define MAX_MAP_ENTITIES 2048 +#endif + +typedef struct epair_s +{ + struct epair_s *next; + char *key; + char *value; +} epair_t; + +typedef struct +{ + vec3_t origin; + int firstbrush; + int numbrushes; + epair_t *epairs; + // only valid for func_areaportals + int areaportalnum; + int portalareas[2]; + int modelnum; //for bsp 2 map conversion + qboolean wasdetail; //for SIN +} entity_t; + +extern int num_entities; +extern entity_t entities[MAX_MAP_ENTITIES]; + +void StripTrailing( char *e ); +void SetKeyValue( entity_t *ent, char *key, char *value ); +char *ValueForKey( entity_t *ent, char *key ); // will return "" if not present +vec_t FloatForKey( entity_t *ent, char *key ); +void GetVectorForKey( entity_t *ent, char *key, vec3_t vec ); +qboolean ParseEntity( script_t *script ); +epair_t *ParseEpair( script_t *script ); +void PrintEntity( entity_t *ent ); + diff --git a/Projects/Android/jni/rtcw/src/extractfuncs/out/src/bspc/l_cmd.h b/Projects/Android/jni/rtcw/src/extractfuncs/out/src/bspc/l_cmd.h new file mode 100644 index 0000000..6d0e1fe --- /dev/null +++ b/Projects/Android/jni/rtcw/src/extractfuncs/out/src/bspc/l_cmd.h @@ -0,0 +1,164 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +// cmdlib.h + +#ifndef SIN +#define SIN +#endif //SIN + +#ifndef __CMDLIB__ +#define __CMDLIB__ + +#ifdef _WIN32 +#pragma warning(disable : 4244) // MIPS +#pragma warning(disable : 4136) // X86 +#pragma warning(disable : 4051) // ALPHA + +#pragma warning(disable : 4018) // signed/unsigned mismatch +#pragma warning(disable : 4305) // truncate from double to float +#endif + +#include +#include +#include +#include +#include +#include +#include + +#ifndef __BYTEBOOL__ +#define __BYTEBOOL__ +typedef enum {false, true} qboolean; +typedef unsigned char byte; +#endif + +// the dec offsetof macro doesnt work very well... +#define myoffsetof( type,identifier ) ( (size_t)&( (type *)0 )->identifier ) + + +// set these before calling CheckParm +extern int myargc; +extern char **myargv; + +char *strupr( char *in ); +char *strlower( char *in ); +int Q_strncasecmp( char *s1, char *s2, int n ); +int Q_strcasecmp( char *s1, char *s2 ); +void Q_getwd( char *out ); + +int Q_filelength( FILE *f ); +int FileTime( char *path ); + +void Q_mkdir( char *path ); + +extern char qdir[1024]; +extern char gamedir[1024]; +void SetQdirFromPath( char *path ); +char *ExpandArg( char *path ); // from cmd line +char *ExpandPath( char *path ); // from scripts +char *ExpandPathAndArchive( char *path ); + + +double I_FloatTime( void ); + +void Error( char *error, ... ); +void Warning( char *warning, ... ); + +int CheckParm( char *check ); + +FILE *SafeOpenWrite( char *filename ); +FILE *SafeOpenRead( char *filename ); +void SafeRead( FILE *f, void *buffer, int count ); +void SafeWrite( FILE *f, void *buffer, int count ); + +int LoadFile( char *filename, void **bufferptr, int offset, int length ); +int TryLoadFile( char *filename, void **bufferptr ); +void SaveFile( char *filename, void *buffer, int count ); +qboolean FileExists( char *filename ); + +void DefaultExtension( char *path, char *extension ); +void DefaultPath( char *path, char *basepath ); +void StripFilename( char *path ); +void StripExtension( char *path ); + +void ExtractFilePath( char *path, char *dest ); +void ExtractFileBase( char *path, char *dest ); +void ExtractFileExtension( char *path, char *dest ); + +int ParseNum( char *str ); + +short BigShort( short l ); +short LittleShort( short l ); +int BigLong( int l ); +int LittleLong( int l ); +float BigFloat( float l ); +float LittleFloat( float l ); + +#ifdef SIN +unsigned short BigUnsignedShort( unsigned short l ); +unsigned short LittleUnsignedShort( unsigned short l ); +unsigned BigUnsigned( unsigned l ); +unsigned LittleUnsigned( unsigned l ); +#endif + + +char *COM_Parse( char *data ); + +extern char com_token[1024]; +extern qboolean com_eof; + +char *copystring( char *s ); + + +void CRC_Init( unsigned short *crcvalue ); +void CRC_ProcessByte( unsigned short *crcvalue, byte data ); +unsigned short CRC_Value( unsigned short crcvalue ); + +void CreatePath( char *path ); +void QCopyFile( char *from, char *to ); + +extern qboolean archive; +extern char archivedir[1024]; + + +extern qboolean verbose; +void qprintf( char *format, ... ); + +void ExpandWildcards( int *argc, char ***argv ); + + +// for compression routines +typedef struct +{ + byte *data; + int count; +} cblock_t; + +#endif + diff --git a/Projects/Android/jni/rtcw/src/extractfuncs/out/src/bspc/l_log.h b/Projects/Android/jni/rtcw/src/extractfuncs/out/src/bspc/l_log.h new file mode 100644 index 0000000..978b19d --- /dev/null +++ b/Projects/Android/jni/rtcw/src/extractfuncs/out/src/bspc/l_log.h @@ -0,0 +1,57 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +//=========================================================================== +// +// Name: l_log.h +// Function: log file stuff +// Programmer: Mr Elusive (MrElusive@demigod.demon.nl) +// Last update: 1997-12-31 +// Tab Size: 3 +//=========================================================================== + +//open a log file +void Log_Open( char *filename ); +//close the current log file +void Log_Close( void ); +//close log file if present +void Log_Shutdown( void ); +//print on stdout and write to the current opened log file +void Log_Print( char *fmt, ... ); +//write to the current opened log file +void Log_Write( char *fmt, ... ); +//write to the current opened log file with a time stamp +void Log_WriteTimeStamped( char *fmt, ... ); +//returns the log file structure +FILE *Log_FileStruct( void ); +//flush log file +void Log_Flush( void ); + +#ifdef WINBSPC +void WinBSPCPrint( char *str ); +#endif //WINBSPC diff --git a/Projects/Android/jni/rtcw/src/extractfuncs/out/src/bspc/l_math.h b/Projects/Android/jni/rtcw/src/extractfuncs/out/src/bspc/l_math.h new file mode 100644 index 0000000..872c4c5 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/extractfuncs/out/src/bspc/l_math.h @@ -0,0 +1,100 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +#ifndef __MATHLIB__ +#define __MATHLIB__ + +// mathlib.h + +#include + +#ifdef DOUBLEVEC_T +typedef double vec_t; +#else +typedef float vec_t; +#endif +typedef vec_t vec3_t[3]; +typedef vec_t vec4_t[4]; + +#define SIDE_FRONT 0 +#define SIDE_ON 2 +#define SIDE_BACK 1 +#define SIDE_CROSS -2 + +#define PITCH 0 +#define YAW 1 +#define ROLL 2 + +#define Q_PI 3.14159265358979323846 + +#define DEG2RAD( a ) ( a * M_PI ) / 180.0F + +#ifndef M_PI +#define M_PI 3.14159265358979323846 // matches value in gcc v2 math.h +#endif + +extern vec3_t vec3_origin; + +#define EQUAL_EPSILON 0.001 + +qboolean VectorCompare( vec3_t v1, vec3_t v2 ); + +#define DotProduct( x,y ) ( x[0] * y[0] + x[1] * y[1] + x[2] * y[2] ) +#define VectorSubtract( a,b,c ) {c[0] = a[0] - b[0]; c[1] = a[1] - b[1]; c[2] = a[2] - b[2];} +#define VectorAdd( a,b,c ) {c[0] = a[0] + b[0]; c[1] = a[1] + b[1]; c[2] = a[2] + b[2];} +#define VectorCopy( a,b ) {b[0] = a[0]; b[1] = a[1]; b[2] = a[2];} +#define Vector4Copy( a,b ) {b[0] = a[0]; b[1] = a[1]; b[2] = a[2]; b[3] = a[3];} +#define VectorScale( v, s, o ) ( ( o )[0] = ( v )[0] * ( s ),( o )[1] = ( v )[1] * ( s ),( o )[2] = ( v )[2] * ( s ) ) +#define VectorClear( x ) {x[0] = x[1] = x[2] = 0;} +#define VectorNegate( x, y ) {y[0] = -x[0]; y[1] = -x[1]; y[2] = -x[2];} +#define VectorMA( v, s, b, o ) ( ( o )[0] = ( v )[0] + ( b )[0] * ( s ),( o )[1] = ( v )[1] + ( b )[1] * ( s ),( o )[2] = ( v )[2] + ( b )[2] * ( s ) ) + +vec_t Q_rint( vec_t in ); +vec_t _DotProduct( vec3_t v1, vec3_t v2 ); +void _VectorSubtract( vec3_t va, vec3_t vb, vec3_t out ); +void _VectorAdd( vec3_t va, vec3_t vb, vec3_t out ); +void _VectorCopy( vec3_t in, vec3_t out ); +void _VectorScale( vec3_t v, vec_t scale, vec3_t out ); +void _VectorMA( vec3_t va, double scale, vec3_t vb, vec3_t vc ); + +double VectorLength( vec3_t v ); +void CrossProduct( const vec3_t v1, const vec3_t v2, vec3_t cross ); +vec_t VectorNormalize( vec3_t inout ); +vec_t ColorNormalize( vec3_t in, vec3_t out ); +vec_t VectorNormalize2( const vec3_t v, vec3_t out ); +void VectorInverse( vec3_t v ); + +void ClearBounds( vec3_t mins, vec3_t maxs ); +void AddPointToBounds( const vec3_t v, vec3_t mins, vec3_t maxs ); + +void AngleVectors( const vec3_t angles, vec3_t forward, vec3_t right, vec3_t up ); +void R_ConcatRotations( float in1[3][3], float in2[3][3], float out[3][3] ); +void RotatePoint( vec3_t point, float matrix[3][3] ); +void CreateRotationMatrix( vec3_t angles, float matrix[3][3] ); + +#endif diff --git a/Projects/Android/jni/rtcw/src/extractfuncs/out/src/bspc/l_mem.h b/Projects/Android/jni/rtcw/src/extractfuncs/out/src/bspc/l_mem.h new file mode 100644 index 0000000..5b29f81 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/extractfuncs/out/src/bspc/l_mem.h @@ -0,0 +1,58 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + + +//============================================================================= + +// memory.h +//#define MEMDEBUG +#undef MEMDEBUG + +#ifndef MEMDEBUG + +void *GetClearedMemory( int size ); +void *GetMemory( unsigned long size ); + +#else + +#define GetMemory( size ) GetMemoryDebug( size, # size, __FILE__, __LINE__ ); +#define GetClearedMemory( size ) GetClearedMemoryDebug( size, # size, __FILE__, __LINE__ ); +//allocate a memory block of the given size +void *GetMemoryDebug( unsigned long size, char *label, char *file, int line ); +//allocate a memory block of the given size and clear it +void *GetClearedMemoryDebug( unsigned long size, char *label, char *file, int line ); +// +void PrintMemoryLabels( void ); +#endif //MEMDEBUG + +void FreeMemory( void *ptr ); +int MemorySize( void *ptr ); +void PrintMemorySize( unsigned long size ); +int TotalAllocatedMemory( void ); + diff --git a/Projects/Android/jni/rtcw/src/extractfuncs/out/src/bspc/l_poly.h b/Projects/Android/jni/rtcw/src/extractfuncs/out/src/bspc/l_poly.h new file mode 100644 index 0000000..028fc22 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/extractfuncs/out/src/bspc/l_poly.h @@ -0,0 +1,136 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +//=========================================================================== +// +// Name: l_poly.h +// Function: +// Programmer: id Sofware +// Mr Elusive (MrElusive@demigod.demon.nl) +// Last update: 1997-12-04 +// Tab Size: 3 +//=========================================================================== + +//a winding gives the bounding points of a convex polygon +typedef struct +{ + int numpoints; + vec3_t p[4]; //variable sized +} winding_t; + +#define MAX_POINTS_ON_WINDING 96 + +//you can define on_epsilon in the makefile as tighter +#ifndef ON_EPSILON +#define ON_EPSILON 0.1 +#endif +//winding errors +#define WE_NONE 0 +#define WE_NOTENOUGHPOINTS 1 +#define WE_SMALLAREA 2 +#define WE_POINTBOGUSRANGE 3 +#define WE_POINTOFFPLANE 4 +#define WE_DEGENERATEEDGE 5 +#define WE_NONCONVEX 6 + +//allocates a winding +winding_t *AllocWinding( int points ); +//returns the area of the winding +vec_t WindingArea( winding_t *w ); +//gives the center of the winding +void WindingCenter( winding_t *w, vec3_t center ); +//clips the given winding to the given plane and gives the front +//and back part of the clipped winding +void ClipWindingEpsilon( winding_t *in, vec3_t normal, vec_t dist, + vec_t epsilon, winding_t **front, winding_t **back ); +//returns the fragment of the given winding that is on the front +//side of the cliping plane. The original is freed. +winding_t *ChopWinding( winding_t *in, vec3_t normal, vec_t dist ); +//returns a copy of the given winding +winding_t *CopyWinding( winding_t *w ); +//returns the reversed winding of the given one +winding_t *ReverseWinding( winding_t *w ); +//returns a base winding for the given plane +winding_t *BaseWindingForPlane( vec3_t normal, vec_t dist ); +//checks the winding for errors +void CheckWinding( winding_t *w ); +//returns the plane normal and dist the winding is in +void WindingPlane( winding_t *w, vec3_t normal, vec_t *dist ); +//removes colinear points from the winding +void RemoveColinearPoints( winding_t *w ); +//returns on which side of the plane the winding is situated +int WindingOnPlaneSide( winding_t *w, vec3_t normal, vec_t dist ); +//frees the winding +void FreeWinding( winding_t *w ); +//gets the bounds of the winding +void WindingBounds( winding_t *w, vec3_t mins, vec3_t maxs ); +//chops the winding with the given plane, the original winding is freed if clipped +void ChopWindingInPlace( winding_t **w, vec3_t normal, vec_t dist, vec_t epsilon ); +//prints the winding points on STDOUT +void pw( winding_t *w ); +//try to merge the two windings which are in the given plane +//the original windings are undisturbed +//the merged winding is returned when merging was possible +//NULL is returned otherwise +winding_t *TryMergeWinding( winding_t *f1, winding_t *f2, vec3_t planenormal ); +//brute force winding merging... creates a convex winding out of +//the two whatsoever +winding_t *MergeWindings( winding_t *w1, winding_t *w2, vec3_t planenormal ); + +//#ifdef ME +void ResetWindings( void ); +//returns the amount of winding memory +int WindingMemory( void ); +int WindingPeakMemory( void ); +int ActiveWindings( void ); +//returns the winding error string +char *WindingErrorString( void ); +//returns one of the WE_ flags when the winding has errors +int WindingError( winding_t *w ); +//removes equal points from the winding +void RemoveEqualPoints( winding_t *w, float epsilon ); +//returns a winding with a point added at the given spot to the +//given winding, original winding is NOT freed +winding_t *AddWindingPoint( winding_t *w, vec3_t point, int spot ); +//returns true if the point is on one of the winding 'edges' +//when the point is on one of the edged the number of the first +//point of the edge is stored in 'spot' +int PointOnWinding( winding_t *w, vec3_t normal, float dist, vec3_t point, int *spot ); +//find a plane seperating the two windings +//true is returned when the windings area adjacent +//the seperating plane normal and distance area stored in 'normal' and 'dist' +//this plane will contain both the piece of common edge of the two windings +//and the vector 'dir' +int FindPlaneSeperatingWindings( winding_t *w1, winding_t *w2, vec3_t dir, + vec3_t normal, float *dist ); +// +int WindingsNonConvex( winding_t *w1, winding_t *w2, + vec3_t normal1, vec3_t normal2, + float dist1, float dist2 ); +//#endif //ME + diff --git a/Projects/Android/jni/rtcw/src/extractfuncs/out/src/bspc/l_qfiles.h b/Projects/Android/jni/rtcw/src/extractfuncs/out/src/bspc/l_qfiles.h new file mode 100644 index 0000000..7b331ad --- /dev/null +++ b/Projects/Android/jni/rtcw/src/extractfuncs/out/src/bspc/l_qfiles.h @@ -0,0 +1,106 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +//=========================================================================== +// +// Name: l_qfiles.h +// Function: - +// Programmer: Mr Elusive +// Last update: 1999-12-01 +// Tab Size: 3 +//=========================================================================== + +#include "../qcommon/unzip.h" + +#define QFILETYPE_UNKNOWN 0x8000 +#define QFILETYPE_PAK 0x0001 +#define QFILETYPE_PK3 0x0002 +#define QFILETYPE_BSP 0x0004 +#define QFILETYPE_MAP 0x0008 +#define QFILETYPE_MDL 0x0010 +#define QFILETYPE_MD2 0x0020 +#define QFILETYPE_MD3 0x0040 +#define QFILETYPE_WAL 0x0080 +#define QFILETYPE_WAV 0x0100 +#define QFILETYPE_AAS 0x4000 + +#define QFILEEXT_UNKNOWN "" +#define QFILEEXT_PAK ".PAK" +#define QFILEEXT_PK3 ".PK3" +#define QFILEEXT_SIN ".SIN" +#define QFILEEXT_BSP ".BSP" +#define QFILEEXT_MAP ".MAP" +#define QFILEEXT_MDL ".MDL" +#define QFILEEXT_MD2 ".MD2" +#define QFILEEXT_MD3 ".MD3" +#define QFILEEXT_WAL ".WAL" +#define QFILEEXT_WAV ".WAV" +#define QFILEEXT_AAS ".AAS" + +//maximum path length +#ifndef _MAX_PATH + #define _MAX_PATH 1024 +#endif + +//for Sin packs +#define MAX_PAK_FILENAME_LENGTH 120 +#define SINPAKHEADER ( ( 'K' << 24 ) + ( 'A' << 16 ) + ( 'P' << 8 ) + 'S' ) + +typedef struct +{ + char name[MAX_PAK_FILENAME_LENGTH]; + int filepos, filelen; +} dsinpackfile_t; + +typedef struct quakefile_s +{ + char pakfile[_MAX_PATH]; + char filename[_MAX_PATH]; + char origname[_MAX_PATH]; + int zipfile; + int type; + int offset; + int length; + unz_s zipinfo; + struct quakefile_s *next; +} quakefile_t; + +//returns the file extension for the given type +char *QuakeFileTypeExtension( int type ); +//returns the file type for the given extension +int QuakeFileExtensionType( char *extension ); +//return the Quake file type for the given file +int QuakeFileType( char *filename ); +//returns true if the filename complies to the filter +int FileFilter( char *filter, char *filename, int casesensitive ); +//find Quake files using the given filter +quakefile_t *FindQuakeFiles( char *filter ); +//load the given Quake file, returns the length of the file +int LoadQuakeFile( quakefile_t *qf, void **bufferptr ); +//read part of a Quake file into the buffer +int ReadQuakeFile( quakefile_t *qf, void *buffer, int offset, int length ); diff --git a/Projects/Android/jni/rtcw/src/extractfuncs/out/src/bspc/l_threads.h b/Projects/Android/jni/rtcw/src/extractfuncs/out/src/bspc/l_threads.h new file mode 100644 index 0000000..70ad0fa --- /dev/null +++ b/Projects/Android/jni/rtcw/src/extractfuncs/out/src/bspc/l_threads.h @@ -0,0 +1,52 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +extern int numthreads; + +void ThreadSetDefault( void ); +int GetThreadWork( void ); +void RunThreadsOnIndividual( int workcnt, qboolean showpacifier, void ( *func )( int ) ); +void RunThreadsOn( int workcnt, qboolean showpacifier, void ( *func )( int ) ); + +//mutex +void ThreadSetupLock( void ); +void ThreadShutdownLock( void ); +void ThreadLock( void ); +void ThreadUnlock( void ); +//semaphore +void ThreadSetupSemaphore( void ); +void ThreadShutdownSemaphore( void ); +void ThreadSemaphoreWait( void ); +void ThreadSemaphoreIncrease( int count ); +//add/remove threads +void AddThread( void ( *func )( int ) ); +void RemoveThread( int threadid ); +void WaitForAllThreadsFinished( void ); +int GetNumThreads( void ); + diff --git a/Projects/Android/jni/rtcw/src/extractfuncs/out/src/bspc/l_utils.h b/Projects/Android/jni/rtcw/src/extractfuncs/out/src/bspc/l_utils.h new file mode 100644 index 0000000..4b9949e --- /dev/null +++ b/Projects/Android/jni/rtcw/src/extractfuncs/out/src/bspc/l_utils.h @@ -0,0 +1,94 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +//=========================================================================== +// +// Name: l_utils.h +// Function: several utils +// Programmer: Mr Elusive (MrElusive@demigod.demon.nl) +// Last update: 1997-12-31 +// Tab Size: 3 +//=========================================================================== + +#ifndef MAX_PATH + #define MAX_PATH 64 +#endif + +#ifndef PATH_SEPERATORSTR + #if defined( WIN32 ) | defined( _WIN32 ) | defined( __NT__ ) | defined( __WINDOWS__ ) | defined( __WINDOWS_386__ ) + #define PATHSEPERATOR_STR "\\" + #else + #define PATHSEPERATOR_STR "/" + #endif +#endif +#ifndef PATH_SEPERATORCHAR + #if defined( WIN32 ) | defined( _WIN32 ) | defined( __NT__ ) | defined( __WINDOWS__ ) | defined( __WINDOWS_386__ ) + #define PATHSEPERATOR_CHAR '\\' + #else + #define PATHSEPERATOR_CHAR '/' + #endif +#endif + +//random in the range [0, 1] +#define random() ( ( rand() & 0x7fff ) / ( (float)0x7fff ) ) +//random in the range [-1, 1] +#define crandom() ( 2.0 * ( random() - 0.5 ) ) +//min and max +#define Maximum( x,y ) ( x > y ? x : y ) +#define Minimum( x,y ) ( x < y ? x : y ) +//absolute value +#define FloatAbs( x ) ( *(float *) &( ( *(int *) &( x ) ) & 0x7FFFFFFF ) ) +#define IntAbs( x ) ( ~( x ) ) +//coordinates +#define _X 0 +#define _Y 1 +#define _Z 2 + +typedef struct foundfile_s +{ + int offset; + int length; + char filename[MAX_PATH]; //screw LCC, array must be at end of struct +} foundfile_t; + +void Vector2Angles( vec3_t value1, vec3_t angles ); +//set the correct path seperators +void ConvertPath( char *path ); +//append a path seperator to the given path not exceeding the length +void AppendPathSeperator( char *path, int length ); +//find a file in a pak file +qboolean FindFileInPak( char *pakfile, char *filename, foundfile_t *file ); +//find a quake file +#ifdef BOTLIB +qboolean FindQuakeFile( char *filename, foundfile_t *file ); +#else //BOTLIB +qboolean FindQuakeFile( char *basedir, char *gamedir, char *filename, foundfile_t *file ); +#endif //BOTLIB + + + diff --git a/Projects/Android/jni/rtcw/src/extractfuncs/out/src/bspc/q2files.h b/Projects/Android/jni/rtcw/src/extractfuncs/out/src/bspc/q2files.h new file mode 100644 index 0000000..9c33e06 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/extractfuncs/out/src/bspc/q2files.h @@ -0,0 +1,494 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +// +// qfiles.h: quake file formats +// This file must be identical in the quake and utils directories +// + +/* +======================================================================== + +The .pak files are just a linear collapse of a directory tree + +======================================================================== +*/ + +#define IDPAKHEADER ( ( 'K' << 24 ) + ( 'C' << 16 ) + ( 'A' << 8 ) + 'P' ) + +typedef struct +{ + char name[56]; + int filepos, filelen; +} dpackfile_t; + +typedef struct +{ + int ident; // == IDPAKHEADER + int dirofs; + int dirlen; +} dpackheader_t; + +#define MAX_FILES_IN_PACK 4096 + + +/* +======================================================================== + +PCX files are used for as many images as possible + +======================================================================== +*/ + +typedef struct +{ + char manufacturer; + char version; + char encoding; + char bits_per_pixel; + unsigned short xmin,ymin,xmax,ymax; + unsigned short hres,vres; + unsigned char palette[48]; + char reserved; + char color_planes; + unsigned short bytes_per_line; + unsigned short palette_type; + char filler[58]; + unsigned char data; // unbounded +} pcx_t; + + +/* +======================================================================== + +.MD2 triangle model file format + +======================================================================== +*/ + +#define IDALIASHEADER ( ( '2' << 24 ) + ( 'P' << 16 ) + ( 'D' << 8 ) + 'I' ) +#define ALIAS_VERSION 8 + +#define MAX_TRIANGLES 4096 +#define MAX_VERTS 2048 +#define MAX_FRAMES 512 +#define MAX_MD2SKINS 32 +#define MAX_SKINNAME 64 + +typedef struct +{ + short s; + short t; +} dstvert_t; + +typedef struct +{ + short index_xyz[3]; + short index_st[3]; +} dtriangle_t; + +typedef struct +{ + byte v[3]; // scaled byte to fit in frame mins/maxs + byte lightnormalindex; +} dtrivertx_t; + +#define DTRIVERTX_V0 0 +#define DTRIVERTX_V1 1 +#define DTRIVERTX_V2 2 +#define DTRIVERTX_LNI 3 +#define DTRIVERTX_SIZE 4 + +typedef struct +{ + float scale[3]; // multiply byte verts by this + float translate[3]; // then add this + char name[16]; // frame name from grabbing + dtrivertx_t verts[1]; // variable sized +} daliasframe_t; + + +// the glcmd format: +// a positive integer starts a tristrip command, followed by that many +// vertex structures. +// a negative integer starts a trifan command, followed by -x vertexes +// a zero indicates the end of the command list. +// a vertex consists of a floating point s, a floating point t, +// and an integer vertex index. + + +typedef struct +{ + int ident; + int version; + + int skinwidth; + int skinheight; + int framesize; // byte size of each frame + + int num_skins; + int num_xyz; + int num_st; // greater than num_xyz for seams + int num_tris; + int num_glcmds; // dwords in strip/fan command list + int num_frames; + + int ofs_skins; // each skin is a MAX_SKINNAME string + int ofs_st; // byte offset from start for stverts + int ofs_tris; // offset for dtriangles + int ofs_frames; // offset for first frame + int ofs_glcmds; + int ofs_end; // end of file + +} dmdl_t; + +/* +======================================================================== + +.SP2 sprite file format + +======================================================================== +*/ + +#define IDSPRITEHEADER ( ( '2' << 24 ) + ( 'S' << 16 ) + ( 'D' << 8 ) + 'I' ) +// little-endian "IDS2" +#define SPRITE_VERSION 2 + +typedef struct +{ + int width, height; + int origin_x, origin_y; // raster coordinates inside pic + char name[MAX_SKINNAME]; // name of pcx file +} dsprframe_t; + +typedef struct { + int ident; + int version; + int numframes; + dsprframe_t frames[1]; // variable sized +} dsprite_t; + +/* +============================================================================== + + .WAL texture file format + +============================================================================== +*/ + + +#define MIPLEVELS 4 +typedef struct miptex_s +{ + char name[32]; + unsigned width, height; + unsigned offsets[MIPLEVELS]; // four mip maps stored + char animname[32]; // next frame in animation chain + int flags; + int contents; + int value; +} miptex_t; + + + +/* +============================================================================== + + .BSP file format + +============================================================================== +*/ + +#define IDBSPHEADER ( ( 'P' << 24 ) + ( 'S' << 16 ) + ( 'B' << 8 ) + 'I' ) +// little-endian "IBSP" + +#define BSPVERSION 38 + + +// upper design bounds +// leaffaces, leafbrushes, planes, and verts are still bounded by +// 16 bit short limits +#define MAX_MAP_MODELS 1024 +#define MAX_MAP_BRUSHES 8192 +#define MAX_MAP_ENTITIES 2048 +#define MAX_MAP_ENTSTRING 0x40000 +#define MAX_MAP_TEXINFO 8192 + +#define MAX_MAP_AREAS 256 +#define MAX_MAP_AREAPORTALS 1024 +#define MAX_MAP_PLANES 65536 +#define MAX_MAP_NODES 65536 +#define MAX_MAP_BRUSHSIDES 65536 +#define MAX_MAP_LEAFS 65536 +#define MAX_MAP_VERTS 65536 +#define MAX_MAP_FACES 65536 +#define MAX_MAP_LEAFFACES 65536 +#define MAX_MAP_LEAFBRUSHES 65536 +#define MAX_MAP_PORTALS 65536 +#define MAX_MAP_EDGES 128000 +#define MAX_MAP_SURFEDGES 256000 +#define MAX_MAP_LIGHTING 0x320000 +#define MAX_MAP_VISIBILITY 0x280000 + +// key / value pair sizes + +#define MAX_KEY 32 +#define MAX_VALUE 1024 + +//============================================================================= + +typedef struct +{ + int fileofs, filelen; +} lump_t; + +#define LUMP_ENTITIES 0 +#define LUMP_PLANES 1 +#define LUMP_VERTEXES 2 +#define LUMP_VISIBILITY 3 +#define LUMP_NODES 4 +#define LUMP_TEXINFO 5 +#define LUMP_FACES 6 +#define LUMP_LIGHTING 7 +#define LUMP_LEAFS 8 +#define LUMP_LEAFFACES 9 +#define LUMP_LEAFBRUSHES 10 +#define LUMP_EDGES 11 +#define LUMP_SURFEDGES 12 +#define LUMP_MODELS 13 +#define LUMP_BRUSHES 14 +#define LUMP_BRUSHSIDES 15 +#define LUMP_POP 16 +#define LUMP_AREAS 17 +#define LUMP_AREAPORTALS 18 +#define HEADER_LUMPS 19 + +typedef struct +{ + int ident; + int version; + lump_t lumps[HEADER_LUMPS]; +} dheader_t; + +typedef struct +{ + float mins[3], maxs[3]; + float origin[3]; // for sounds or lights + int headnode; + int firstface, numfaces; // submodels just draw faces + // without walking the bsp tree +} dmodel_t; + + +typedef struct +{ + float point[3]; +} dvertex_t; + + +// 0-2 are axial planes +#define PLANE_X 0 +#define PLANE_Y 1 +#define PLANE_Z 2 + +// 3-5 are non-axial planes snapped to the nearest +#define PLANE_ANYX 3 +#define PLANE_ANYY 4 +#define PLANE_ANYZ 5 + +// planes (x&~1) and (x&~1)+1 are allways opposites + +typedef struct +{ + float normal[3]; + float dist; + int type; // PLANE_X - PLANE_ANYZ ?remove? trivial to regenerate +} dplane_t; + + +// contents flags are seperate bits +// a given brush can contribute multiple content bits +// multiple brushes can be in a single leaf + +// these definitions also need to be in q_shared.h! + +// lower bits are stronger, and will eat weaker brushes completely +#define CONTENTS_SOLID 1 // an eye is never valid in a solid +#define CONTENTS_WINDOW 2 // translucent, but not watery +#define CONTENTS_AUX 4 +#define CONTENTS_LAVA 8 +#define CONTENTS_SLIME 16 +#define CONTENTS_WATER 32 +#define CONTENTS_MIST 64 +#define LAST_VISIBLE_CONTENTS 64 + +// remaining contents are non-visible, and don't eat brushes + +#define CONTENTS_AREAPORTAL 0x8000 + +#define CONTENTS_PLAYERCLIP 0x10000 +#define CONTENTS_MONSTERCLIP 0x20000 + +// currents can be added to any other contents, and may be mixed +#define CONTENTS_CURRENT_0 0x40000 +#define CONTENTS_CURRENT_90 0x80000 +#define CONTENTS_CURRENT_180 0x100000 +#define CONTENTS_CURRENT_270 0x200000 +#define CONTENTS_CURRENT_UP 0x400000 +#define CONTENTS_CURRENT_DOWN 0x800000 + +#define CONTENTS_ORIGIN 0x1000000 // removed before bsping an entity + +#define CONTENTS_MONSTER 0x2000000 // should never be on a brush, only in game +#define CONTENTS_DEADMONSTER 0x4000000 +#define CONTENTS_DETAIL 0x8000000 // brushes to be added after vis leafs +//renamed because it's in conflict with the Q3A translucent contents +#define CONTENTS_Q2TRANSLUCENT 0x10000000 // auto set if any surface has trans +#define CONTENTS_LADDER 0x20000000 + + + +#define SURF_LIGHT 0x1 // value will hold the light strength + +#define SURF_SLICK 0x2 // effects game physics + +#define SURF_SKY 0x4 // don't draw, but add to skybox +#define SURF_WARP 0x8 // turbulent water warp +#define SURF_TRANS33 0x10 +#define SURF_TRANS66 0x20 +#define SURF_FLOWING 0x40 // scroll towards angle +#define SURF_NODRAW 0x80 // don't bother referencing the texture + +#define SURF_HINT 0x100 // make a primary bsp splitter +#define SURF_SKIP 0x200 // completely ignore, allowing non-closed brushes + + + +typedef struct +{ + int planenum; + int children[2]; // negative numbers are -(leafs+1), not nodes + short mins[3]; // for frustom culling + short maxs[3]; + unsigned short firstface; + unsigned short numfaces; // counting both sides +} dnode_t; + + +typedef struct texinfo_s +{ + float vecs[2][4]; // [s/t][xyz offset] + int flags; // miptex flags + overrides + int value; // light emission, etc + char texture[32]; // texture name (textures/*.wal) + int nexttexinfo; // for animations, -1 = end of chain +} texinfo_t; + + +// note that edge 0 is never used, because negative edge nums are used for +// counterclockwise use of the edge in a face +typedef struct +{ + unsigned short v[2]; // vertex numbers +} dedge_t; + +#define MAXLIGHTMAPS 4 +typedef struct +{ + unsigned short planenum; + short side; + + int firstedge; // we must support > 64k edges + short numedges; + short texinfo; + +// lighting info + byte styles[MAXLIGHTMAPS]; + int lightofs; // start of [numstyles*surfsize] samples +} dface_t; + +typedef struct +{ + int contents; // OR of all brushes (not needed?) + + short cluster; + short area; + + short mins[3]; // for frustum culling + short maxs[3]; + + unsigned short firstleafface; + unsigned short numleaffaces; + + unsigned short firstleafbrush; + unsigned short numleafbrushes; +} dleaf_t; + +typedef struct +{ + unsigned short planenum; // facing out of the leaf + short texinfo; +} dbrushside_t; + +typedef struct +{ + int firstside; + int numsides; + int contents; +} dbrush_t; + +#define ANGLE_UP -1 +#define ANGLE_DOWN -2 + + +// the visibility lump consists of a header with a count, then +// byte offsets for the PVS and PHS of each cluster, then the raw +// compressed bit vectors +#define DVIS_PVS 0 +#define DVIS_PHS 1 +typedef struct +{ + int numclusters; + int bitofs[8][2]; // bitofs[numclusters][2] +} dvis_t; + +// each area has a list of portals that lead into other areas +// when portals are closed, other areas may not be visible or +// hearable even if the vis info says that it should be +typedef struct +{ + int portalnum; + int otherarea; +} dareaportal_t; + +typedef struct +{ + int numareaportals; + int firstareaportal; +} darea_t; diff --git a/Projects/Android/jni/rtcw/src/extractfuncs/out/src/bspc/qbsp.h b/Projects/Android/jni/rtcw/src/extractfuncs/out/src/bspc/qbsp.h new file mode 100644 index 0000000..ceb257d --- /dev/null +++ b/Projects/Android/jni/rtcw/src/extractfuncs/out/src/bspc/qbsp.h @@ -0,0 +1,498 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + + +#if defined( WIN32 ) || defined( _WIN32 ) +#include +#endif +#include +#include "l_cmd.h" +#include "l_math.h" +#include "l_poly.h" +#include "l_threads.h" +#include "../botlib/l_script.h" +#include "l_bsp_ent.h" +#include "q2files.h" +#include "l_mem.h" +#include "l_utils.h" +#include "l_log.h" +#include "l_qfiles.h" + +//Mr Elusive shit +#define ME +#define DEBUG +#define NODELIST +#define SIN + +#define MAX_BRUSH_SIDES 128 //maximum number of sides per brush +#define CLIP_EPSILON 0.1 +//#define MAX_MAP_BOUNDS 65535 +#define MAX_MAP_BOUNDS ( 128 * 1024 ) // (SA) (9/17/01) new map dimensions (from Q3TA) +#define BOGUS_RANGE ( MAX_MAP_BOUNDS + 128 ) //somewhere outside the map + +#define TEXINFO_NODE -1 //side is allready on a node +#define PLANENUM_LEAF -1 //used for leaf nodes +#define MAXEDGES 20 //maximum number of face edges +#define MAX_NODE_BRUSHES 8 //maximum brushes in a node +//side flags +#define SFL_TESTED 1 +#define SFL_VISIBLE 2 +#define SFL_BEVEL 4 +#define SFL_TEXTURED 8 +#define SFL_CURVE 16 + +//map plane +typedef struct plane_s +{ + vec3_t normal; + vec_t dist; + int type; + int signbits; + struct plane_s *hash_chain; +} plane_t; +//brush texture +typedef struct +{ + vec_t shift[2]; + vec_t rotate; + vec_t scale[2]; + char name[32]; + int flags; + int value; +} brush_texture_t; +//brush side +typedef struct side_s +{ + int planenum; // map plane this side is in + int texinfo; // texture reference + winding_t *winding; // winding of this side + struct side_s *original; // bspbrush_t sides will reference the mapbrush_t sides + int lightinfo; // for SIN only + int contents; // from miptex + int surf; // from miptex + unsigned short flags; // side flags +} side_t; //sizeof(side_t) = 36 +//map brush +typedef struct mapbrush_s +{ + int entitynum; + int brushnum; + + int contents; +#ifdef ME + int expansionbbox; //bbox used for expansion of the brush + int leafnum; + int modelnum; +#endif + + vec3_t mins, maxs; + + int numsides; + side_t *original_sides; +} mapbrush_t; +//bsp face +typedef struct face_s +{ + struct face_s *next; // on node + + // the chain of faces off of a node can be merged or split, + // but each face_t along the way will remain in the chain + // until the entire tree is freed + struct face_s *merged; // if set, this face isn't valid anymore + struct face_s *split[2]; // if set, this face isn't valid anymore + + struct portal_s *portal; + int texinfo; +#ifdef SIN + int lightinfo; +#endif + int planenum; + int contents; // faces in different contents can't merge + int outputnumber; + winding_t *w; + int numpoints; + qboolean badstartvert; // tjunctions cannot be fixed without a midpoint vertex + int vertexnums[MAXEDGES]; +} face_t; +//bsp brush +typedef struct bspbrush_s +{ + struct bspbrush_s *next; + vec3_t mins, maxs; + int side, testside; // side of node during construction + mapbrush_t *original; + int numsides; + side_t sides[6]; // variably sized +} bspbrush_t; //sizeof(bspbrush_t) = 44 + numsides * sizeof(side_t) +//bsp node +typedef struct node_s +{ + //both leafs and nodes + int planenum; // -1 = leaf node + struct node_s *parent; + vec3_t mins, maxs; // valid after portalization + bspbrush_t *volume; // one for each leaf/node + + // nodes only + qboolean detail_seperator; // a detail brush caused the split + side_t *side; // the side that created the node + struct node_s *children[2]; + face_t *faces; + + // leafs only + bspbrush_t *brushlist; // fragments of all brushes in this leaf + int contents; // OR of all brush contents + int occupied; // 1 or greater can reach entity + entity_t *occupant; // for leak file testing + int cluster; // for portalfile writing + int area; // for areaportals + struct portal_s *portals; // also on nodes during construction +#ifdef NODELIST + struct node_s *next; //next node in the nodelist +#endif +#ifdef ME + int expansionbboxes; //OR of all bboxes used for expansion of the brushes + int modelnum; +#endif +} node_t; //sizeof(node_t) = 80 bytes +//bsp portal +typedef struct portal_s +{ + plane_t plane; + node_t *onnode; // NULL = outside box + node_t *nodes[2]; // [0] = front side of plane + struct portal_s *next[2]; + winding_t *winding; + + qboolean sidefound; // false if ->side hasn't been checked + side_t *side; // NULL = non-visible + face_t *face[2]; // output face in bsp file +#ifdef ME + struct tmp_face_s *tmpface; //pointer to the tmpface created for this portal + int planenum; //number of the map plane used by the portal +#endif +} portal_t; +//bsp tree +typedef struct +{ + node_t *headnode; + node_t outside_node; + vec3_t mins, maxs; +} tree_t; + +//============================================================================= +// bspc.c +//============================================================================= + +extern qboolean noprune; +extern qboolean nodetail; +extern qboolean fulldetail; +extern qboolean nomerge; +extern qboolean nosubdiv; +extern qboolean nowater; +extern qboolean noweld; +extern qboolean noshare; +extern qboolean notjunc; +extern qboolean onlyents; +#ifdef ME +extern qboolean nocsg; +extern qboolean create_aas; +extern qboolean freetree; +extern qboolean lessbrushes; +extern qboolean nobrushmerge; +extern qboolean cancelconversion; +extern qboolean noliquids; +extern qboolean capsule_collision; +extern qboolean writeaasmap; +#endif //ME + +extern float subdivide_size; +extern vec_t microvolume; + +extern char outbase[32]; +extern char source[1024]; + +//============================================================================= +// map.c +//============================================================================= + +#define MAX_MAPFILE_PLANES 128000 +#define MAX_MAPFILE_BRUSHES 65535 //16384 +#define MAX_MAPFILE_BRUSHSIDES ( MAX_MAPFILE_BRUSHES * 8 ) +#define MAX_MAPFILE_TEXINFO 8192 + +extern int entity_num; + +extern plane_t mapplanes[MAX_MAPFILE_PLANES]; +extern int nummapplanes; +extern int mapplaneusers[MAX_MAPFILE_PLANES]; + +extern int nummapbrushes; +extern mapbrush_t mapbrushes[MAX_MAPFILE_BRUSHES]; + +extern vec3_t map_mins, map_maxs; + +extern int nummapbrushsides; +extern side_t brushsides[MAX_MAPFILE_BRUSHSIDES]; +extern brush_texture_t side_brushtextures[MAX_MAPFILE_BRUSHSIDES]; + +#ifdef ME + +typedef struct +{ + float vecs[2][4]; // [s/t][xyz offset] + int flags; // miptex flags + overrides + int value; + char texture[64]; // texture name (textures/*.wal) + int nexttexinfo; // for animations, -1 = end of chain +} map_texinfo_t; + +extern map_texinfo_t map_texinfo[MAX_MAPFILE_TEXINFO]; +extern int map_numtexinfo; +#define NODESTACKSIZE 1024 + +#define MAPTYPE_QUAKE1 1 +#define MAPTYPE_QUAKE2 2 +#define MAPTYPE_QUAKE3 3 +#define MAPTYPE_HALFLIFE 4 +#define MAPTYPE_SIN 5 + +extern int nodestack[NODESTACKSIZE]; +extern int *nodestackptr; +extern int nodestacksize; +extern int brushmodelnumbers[MAX_MAPFILE_BRUSHES]; +extern int dbrushleafnums[MAX_MAPFILE_BRUSHES]; +extern int dplanes2mapplanes[MAX_MAPFILE_PLANES]; + +extern int loadedmaptype; +#endif //ME + +extern int c_boxbevels; +extern int c_edgebevels; +extern int c_areaportals; +extern int c_clipbrushes; +extern int c_squattbrushes; + +//finds a float plane for the given normal and distance +int FindFloatPlane( vec3_t normal, vec_t dist ); +//returns the plane type for the given normal +int PlaneTypeForNormal( vec3_t normal ); +//returns the plane defined by the three given points +int PlaneFromPoints( int *p0, int *p1, int *p2 ); +//add bevels to the map brush +void AddBrushBevels( mapbrush_t *b ); +//makes brush side windings for the brush +qboolean MakeBrushWindings( mapbrush_t *ob ); +//marks brush bevels of the brush as bevel +void MarkBrushBevels( mapbrush_t *brush ); +//returns true if the map brush already exists +int BrushExists( mapbrush_t *brush ); +//loads a map from a bsp file +int LoadMapFromBSP( struct quakefile_s *qf ); +//resets map loading +void ResetMapLoading( void ); +//print some map info +void PrintMapInfo( void ); +//writes a map file (type depending on loaded map type) +void WriteMapFile( char *filename ); + +//============================================================================= +// map_q2.c +//============================================================================= + +void Q2_ResetMapLoading( void ); +//loads a Quake2 map file +void Q2_LoadMapFile( char *filename ); +//loads a map from a Quake2 bsp file +void Q2_LoadMapFromBSP( char *filename, int offset, int length ); + +//============================================================================= +// map_q1.c +//============================================================================= + +void Q1_ResetMapLoading( void ); +//loads a Quake2 map file +void Q1_LoadMapFile( char *filename ); +//loads a map from a Quake1 bsp file +void Q1_LoadMapFromBSP( char *filename, int offset, int length ); + +//============================================================================= +// map_q3.c +//============================================================================= +void Q3_ResetMapLoading( void ); +//loads a map from a Quake3 bsp file +void Q3_LoadMapFromBSP( struct quakefile_s *qf ); + +//============================================================================= +// map_sin.c +//============================================================================= + +void Sin_ResetMapLoading( void ); +//loads a Sin map file +void Sin_LoadMapFile( char *filename ); +//loads a map from a Sin bsp file +void Sin_LoadMapFromBSP( char *filename, int offset, int length ); + +//============================================================================= +// map_hl.c +//============================================================================= + +void HL_ResetMapLoading( void ); +//loads a Half-Life map file +void HL_LoadMapFile( char *filename ); +//loads a map from a Half-Life bsp file +void HL_LoadMapFromBSP( char *filename, int offset, int length ); + +//============================================================================= +// textures.c +//============================================================================= + +typedef struct +{ + char name[64]; + int flags; + int value; + int contents; + char animname[64]; +} textureref_t; + +#define MAX_MAP_TEXTURES 1024 + +extern textureref_t textureref[MAX_MAP_TEXTURES]; + +int FindMiptex( char *name ); +int TexinfoForBrushTexture( plane_t *plane, brush_texture_t *bt, vec3_t origin ); +void TextureAxisFromPlane( plane_t *pln, vec3_t xv, vec3_t yv ); + +//============================================================================= +// csg +//============================================================================= + +bspbrush_t *MakeBspBrushList( int startbrush, int endbrush, vec3_t clipmins, vec3_t clipmaxs ); +bspbrush_t *ChopBrushes( bspbrush_t *head ); +bspbrush_t *InitialBrushList( bspbrush_t *list ); +bspbrush_t *OptimizedBrushList( bspbrush_t *list ); +void WriteBrushMap( char *name, bspbrush_t *list ); +void CheckBSPBrush( bspbrush_t *brush ); +void BSPBrushWindings( bspbrush_t *brush ); +bspbrush_t *TryMergeBrushes( bspbrush_t *brush1, bspbrush_t *brush2 ); +tree_t *ProcessWorldBrushes( int brush_start, int brush_end ); + +//============================================================================= +// brushbsp +//============================================================================= + +#define PSIDE_FRONT 1 +#define PSIDE_BACK 2 +#define PSIDE_BOTH ( PSIDE_FRONT | PSIDE_BACK ) +#define PSIDE_FACING 4 + +void WriteBrushList( char *name, bspbrush_t *brush, qboolean onlyvis ); +bspbrush_t *CopyBrush( bspbrush_t *brush ); +void SplitBrush( bspbrush_t *brush, int planenum, bspbrush_t **front, bspbrush_t **back ); +node_t *AllocNode( void ); +bspbrush_t *AllocBrush( int numsides ); +int CountBrushList( bspbrush_t *brushes ); +void FreeBrush( bspbrush_t *brushes ); +vec_t BrushVolume( bspbrush_t *brush ); +void BoundBrush( bspbrush_t *brush ); +void FreeBrushList( bspbrush_t *brushes ); +tree_t *BrushBSP( bspbrush_t *brushlist, vec3_t mins, vec3_t maxs ); + +bspbrush_t *BrushFromBounds( vec3_t mins, vec3_t maxs ); +int BrushMostlyOnSide( bspbrush_t *brush, plane_t *plane ); +qboolean WindingIsHuge( winding_t *w ); +qboolean WindingIsTiny( winding_t *w ); +void ResetBrushBSP( void ); + +//============================================================================= +// portals.c +//============================================================================= + +int VisibleContents( int contents ); +void MakeHeadnodePortals( tree_t *tree ); +void MakeNodePortal( node_t *node ); +void SplitNodePortals( node_t *node ); +qboolean Portal_VisFlood( portal_t *p ); +qboolean FloodEntities( tree_t *tree ); +void FillOutside( node_t *headnode ); +void FloodAreas( tree_t *tree ); +void MarkVisibleSides( tree_t *tree, int start, int end ); +void FreePortal( portal_t *p ); +void EmitAreaPortals( node_t *headnode ); +void MakeTreePortals( tree_t *tree ); + +//============================================================================= +// glfile.c +//============================================================================= + +void OutputWinding( winding_t *w, FILE *glview ); +void WriteGLView( tree_t *tree, char *source ); + +//============================================================================= +// gldraw.c +//============================================================================= + +extern vec3_t draw_mins, draw_maxs; +extern qboolean drawflag; + +void Draw_ClearWindow( void ); +void DrawWinding( winding_t *w ); +void GLS_BeginScene( void ); +void GLS_Winding( winding_t *w, int code ); +void GLS_EndScene( void ); + +//============================================================================= +// leakfile.c +//============================================================================= + +void LeakFile( tree_t *tree ); + +//============================================================================= +// tree.c +//============================================================================= + +tree_t *Tree_Alloc( void ); +void Tree_Free( tree_t *tree ); +void Tree_Free_r( node_t *node ); +void Tree_Print_r( node_t *node, int depth ); +void Tree_FreePortals_r( node_t *node ); +void Tree_PruneNodes_r( node_t *node ); +void Tree_PruneNodes( node_t *node ); + +//============================================================================= +// faces.c +//============================================================================= + +face_t *AllocFace( void ); +void FreeFace( face_t *f ); +void MakeFaces( node_t *headnode ); +void FixTjuncs( node_t *headnode ); +int GetEdge2( int v1, int v2, face_t *f ); +void MergeNodeFaces( node_t *node ); diff --git a/Projects/Android/jni/rtcw/src/extractfuncs/out/src/extractfuncs/.consign b/Projects/Android/jni/rtcw/src/extractfuncs/out/src/extractfuncs/.consign new file mode 100644 index 0000000..85ee841 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/extractfuncs/out/src/extractfuncs/.consign @@ -0,0 +1,6 @@ +l_memory.o:1375636567 0a1228068c14c9174bba2b83addbb992 +l_log.o:1373264700 38d94a29ed5b1d108f647e5cca4983d6 +l_precomp.o:1375636569 57cc9189b07b9f48cb277f323fc09e86 +extractfuncs.o:1373264699 5821769ec4cb1694dcdba42fcb332da6 +extractfuncs:1375636570 b395d3518fdcc92b32dd2b45b8f7c812 +l_script.o:1375636570 9667d7aeb55533e4d2d5f73d95343db0 diff --git a/Projects/Android/jni/rtcw/src/extractfuncs/out/src/extractfuncs/extractfuncs b/Projects/Android/jni/rtcw/src/extractfuncs/out/src/extractfuncs/extractfuncs new file mode 100644 index 0000000..7e1d3a3 Binary files /dev/null and b/Projects/Android/jni/rtcw/src/extractfuncs/out/src/extractfuncs/extractfuncs differ diff --git a/Projects/Android/jni/rtcw/src/extractfuncs/out/src/extractfuncs/extractfuncs.c b/Projects/Android/jni/rtcw/src/extractfuncs/out/src/extractfuncs/extractfuncs.c new file mode 100644 index 0000000..c6e9903 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/extractfuncs/out/src/extractfuncs/extractfuncs.c @@ -0,0 +1,653 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +#include +#include +#include +#include +#include +#ifdef _WIN32 +#include +#include +#endif +#include "l_memory.h" +#include "l_script.h" +#include "l_precomp.h" +#include "l_log.h" + +typedef enum {false, true} qboolean; + +//#define PATHSEPERATOR_STR "\\" + +void Error( char *error, ... ) { + va_list argptr; + + va_start( argptr, error ); + vprintf( error, argptr ); + va_end( argptr ); + + exit( 1 ); +} + +/* +int FileLength (FILE *f) +{ + int pos; + int end; + + pos = ftell (f); + fseek (f, 0, SEEK_END); + end = ftell (f); + fseek (f, pos, SEEK_SET); + + return end; +} //end of the function FileLength + +void Remove(char *buf, int length, char *from, char *to, char *skip) +{ + int i, remove = false; + + for (i = 0; i < length; i++) + { + if (remove) + { + if ((unsigned) length - i > strlen(skip)) + { + if (!strncmp(&buf[i], skip, strlen(skip))) + { + i += strlen(skip); + } //end if + } //end if + if ((unsigned) length - i > strlen(to)) + { + if (!strncmp(&buf[i], to, strlen(to))) + { + length = i + strlen(to); + } //end if + } //end if + if (buf[i]) buf[i] = 'a'; + } //end if + else + { + if ((unsigned) length - i < strlen(from)) return; + if (!strncmp(&buf[i], from, strlen(from))) remove = true; + } //end else + } //end for +} //end of the function Remove + +void main(int argc, char *argv[]) +{ + FILE *fp; + int filelength; + char *from, *to, *skip, *ptr; + + if (argc < 2) Error("USAGE: screwup "); + fp = fopen(argv[1], "rb"); + if (!fp) Error("error opening %s\n", argv[1]); + + filelength = FileLength(fp); + ptr = malloc(filelength); + fread(ptr, filelength, 1, fp); + fclose(fp); + + from = argv[3];//"be_aas_bspq2.c"; + to = argv[4];//"BotWeaponNameFromModel"; + skip = "GetBotAPI"; + + Remove(ptr, filelength, from, to, skip); + + fp = fopen(argv[2], "wb"); + if (!fp) Error("error opening %s\n", argv[2]); + fwrite(ptr, filelength, 1, fp); + fclose(fp); + + free(ptr); +} //end of the function main +*/ + +typedef struct replacefunc_s +{ + char *name; + char *newname; + char *filename; + char dec[MAX_TOKEN]; //function declaration + struct replacefunc_s *next; +} replacefunc_t; + +replacefunc_t *replacefuncs; +int numfuncs; + +extern int Q_stricmp( const char *s1, const char *s2 ); + +// the function names +//#define DEFAULT_FUNCBASE "g_func" +static char *func_filename = "g_funcs.h"; +static char *func_filedesc = "g_func_decs.h"; + +void DumpReplaceFunctions( void ) { + replacefunc_t *rf; + char path[_MAX_PATH]; + FILE *f; + int len, newlen; + unsigned char *buf, *newbuf; + int updated; + + updated = 0; + + // dump the function header + strcpy( path, "." ); + strcat( path, PATHSEPERATOR_STR ); + strcat( path, "g_funcs.tmp" ); + Log_Open( path ); + for ( rf = replacefuncs; rf; rf = rf->next ) + { + Log_Print( "{\"%s\", (byte *)%s},\n", rf->name, rf->name ); + } //end for + Log_Print( "{0, 0}\n" ); + Log_Close(); + + // if it's different, rename the file over the real header + strcpy( path, "g_funcs.tmp" ); + f = fopen( path, "rb" ); + fseek( f, 0, SEEK_END ); + len = ftell( f ); + buf = (unsigned char *) malloc( len + 1 ); + fseek( f, 0, SEEK_SET ); + fread( buf, len, 1, f ); + buf[len] = 0; + fclose( f ); + + strcpy( path, func_filename ); + if ( f = fopen( path, "rb" ) ) { + fseek( f, 0, SEEK_END ); + newlen = ftell( f ); + newbuf = (unsigned char *) malloc( newlen + 1 ); + fseek( f, 0, SEEK_SET ); + fread( newbuf, newlen, 1, f ); + newbuf[newlen] = 0; + fclose( f ); + + if ( len != newlen || Q_stricmp( buf, newbuf ) ) { + char newpath[_MAX_PATH]; + + // delete the old file, rename the new one + strcpy( path, func_filename ); + remove( path ); + + strcpy( newpath, "g_funcs.tmp" ); + rename( newpath, path ); + + // make g_save recompile itself + remove( "debug\\g_save.obj" ); + remove( "debug\\g_save.sbr" ); + remove( "release\\g_save.obj" ); + remove( "release\\g_save.sbr" ); + + updated = 1; + } else { + // delete the old file + strcpy( path, "g_funcs.tmp" ); + remove( path ); + } + } else { + rename( "g_funcs.tmp", func_filename ); + } + + free( buf ); + free( newbuf ); + + // dump the function declarations + strcpy( path, "g_func_decs.tmp" ); + Log_Open( path ); + for ( rf = replacefuncs; rf; rf = rf->next ) + { + Log_Print( "extern %s;\n", rf->dec ); + } //end for + Log_Close(); + + // if it's different, rename the file over the real header + strcpy( path, "g_func_decs.tmp" ); + f = fopen( path, "rb" ); + fseek( f, 0, SEEK_END ); + len = ftell( f ); + buf = (unsigned char *) malloc( len + 1 ); + fseek( f, 0, SEEK_SET ); + fread( buf, len, 1, f ); + buf[len] = 0; + fclose( f ); + + strcpy( path, func_filedesc ); + if ( f = fopen( path, "rb" ) ) { + fseek( f, 0, SEEK_END ); + newlen = ftell( f ); + newbuf = (unsigned char *) malloc( newlen + 1 ); + fseek( f, 0, SEEK_SET ); + fread( newbuf, newlen, 1, f ); + newbuf[newlen] = 0; + fclose( f ); + + if ( len != newlen || Q_stricmp( buf, newbuf ) ) { + char newpath[_MAX_PATH]; + + // delete the old file, rename the new one + strcpy( path, func_filedesc ); + remove( path ); + + strcpy( newpath, "g_func_decs.tmp" ); + rename( newpath, path ); + + // make g_save recompile itself + // NOTE TTimo win32 only? (harmless on *nix anyway) + remove( "debug\\g_save.obj" ); + remove( "debug\\g_save.sbr" ); + remove( "release\\g_save.obj" ); + remove( "release\\g_save.sbr" ); + + updated = 1; + } else { + // delete the old file + strcpy( path, "g_func_decs.tmp" ); + remove( path ); + } + } else { + rename( "g_func_decs.tmp", func_filedesc ); + } + + free( buf ); + free( newbuf ); + + if ( updated ) { + printf( "Updated the function table, recompile required.\n" ); + } + +} //end of the function DumpReplaceFunctions + +replacefunc_t *FindFunctionName( char *funcname ) { + replacefunc_t *f; + + for ( f = replacefuncs; f; f = f->next ) + { + if ( !strcmp( f->name, funcname ) ) { + return f; + } + } //end for + return NULL; +} //end of the function FindFunctionName + +int MayScrewUp( char *funcname ) { + if ( !strcmp( funcname, "GetBotAPI" ) ) { + return false; + } + if ( !strcmp( funcname, "main" ) ) { + return false; + } + if ( !strcmp( funcname, "WinMain" ) ) { + return false; + } + return true; +} //end of the function MayScrewUp + +typedef struct tokenList_s { + token_t token; + struct tokenList_s *next; +} tokenList_t; + +#define MAX_TOKEN_LIST 64 +tokenList_t tokenList[MAX_TOKEN_LIST]; +int tokenListHead = 0; + +void ConcatDec( tokenList_t *list, char *str, int inc ) { +/* + if (!((list->token.type == TT_NAME) || (list->token.string[0] == '*'))) { + if (list->token.string[0] == ')' || list->token.string[0] == '(') { + if (inc++ >= 2) + return; + } else { + return; + } + } +*/ + if ( list->next ) { + ConcatDec( list->next, str, inc ); + } + strcat( str, list->token.string ); + strcat( str, " " ); +} + +void AddFunctionName( char *funcname, char *filename, tokenList_t *head ) { + replacefunc_t *f; + tokenList_t *list; + + if ( FindFunctionName( funcname ) ) { + return; + } + +#if defined( __linux__ ) + // the bad thing is, this doesn't preprocess .. on __linux__ this + // function is not implemented (q_math.c) + if ( !Q_stricmp( funcname, "BoxOnPlaneSide" ) ) { + return; + } +#endif + + // NERVE - SMF - workaround for Graeme's predifined MACOSX functions + // TTimo - looks like linux version needs to escape those too +#if defined( _WIN32 ) || defined( __linux__ ) + if ( !Q_stricmp( funcname, "qmax" ) ) { + return; + } else if ( !Q_stricmp( funcname, "qmin" ) ) { + return; + } +#endif + // -NERVE - SMF + + f = (replacefunc_t *) GetMemory( sizeof( replacefunc_t ) + strlen( funcname ) + 1 + 6 + strlen( filename ) + 1 ); + f->name = (char *) f + sizeof( replacefunc_t ); + strcpy( f->name, funcname ); + f->newname = (char *) f + sizeof( replacefunc_t ) + strlen( funcname ) + 1; + sprintf( f->newname, "F%d", numfuncs++ ); + f->filename = (char *) f + sizeof( replacefunc_t ) + strlen( funcname ) + 1 + strlen( f->newname ) + 1; + strcpy( f->filename, filename ); + f->next = replacefuncs; + replacefuncs = f; + + // construct the declaration + list = head; + f->dec[0] = '\0'; + ConcatDec( list, f->dec, 0 ); + +} //end of the function AddFunctionName + +void AddTokenToList( tokenList_t **head, token_t *token ) { + tokenList_t *newhead; + + newhead = &tokenList[tokenListHead++]; //GetMemory( sizeof( tokenList_t ) ); + if ( tokenListHead == MAX_TOKEN_LIST ) { + tokenListHead = 0; + } + + newhead->next = *head; + newhead->token = *token; + + *head = newhead; +} +/* +void KillTokenList( tokenList_t *head ) +{ + if (head->next) { + KillTokenList( head->next ); + FreeMemory( head->next ); + head->next = NULL; + } +} +*/ +void StripTokenList( tokenList_t *head ) { + tokenList_t *trav, *lastTrav; + + trav = head; + + // now go back to the start of the declaration + lastTrav = trav; + trav = trav->next; // should be on the function name now + while ( ( trav->token.type == TT_NAME ) || ( trav->token.string[0] == '*' ) ) { + lastTrav = trav; + trav = trav->next; + if ( !trav ) { + return; + } + } + // now kill everything after lastTrav +// KillTokenList( lastTrav ); + lastTrav->next = NULL; +} + +void GetFunctionNamesFromFile( char *filename ) { + source_t *source; + token_t token, lasttoken; + int indent = 0, brace; + int isStatic = 0; + tokenList_t *listHead; + + // filter some files out + if ( !Q_stricmp( filename, "bg_lib.c" ) ) { + return; + } + + listHead = NULL; + source = LoadSourceFile( filename ); + if ( !source ) { + Error( "error opening %s", filename ); + return; + } //end if +// printf("loaded %s\n", filename); +// if (!PC_ReadToken(source, &lasttoken)) +// { +// FreeSource(source); +// return; +// } //end if + while ( 1 ) + { + if ( !PC_ReadToken( source, &token ) ) { + break; + } + AddTokenToList( &listHead, &token ); + if ( token.type == TT_PUNCTUATION ) { + switch ( token.string[0] ) + { + case ';': + { + isStatic = 0; + break; + } + case '{': + { + indent++; + break; + } //end case + case '}': + { + indent--; + if ( indent < 0 ) { + indent = 0; + } + break; + } //end case + case '(': + { + if ( indent <= 0 && lasttoken.type == TT_NAME ) { + StripTokenList( listHead ); + + brace = 1; + while ( PC_ReadToken( source, &token ) ) + { + AddTokenToList( &listHead, &token ); + if ( token.string[0] == '(' ) { + brace++; + } //end if + else if ( token.string[0] == ')' ) { + brace--; + if ( brace <= 0 ) { + if ( !PC_ReadToken( source, &token ) ) { + break; + } + if ( token.string[0] == '{' ) { + indent++; + if ( !isStatic && MayScrewUp( lasttoken.string ) ) { + AddFunctionName( lasttoken.string, filename, listHead ); + } //end if + } //end if + break; + } //end if + } //end if + } //end while + } //end if + break; + } //end case + } //end if + } //end switch + if ( token.type == TT_NAME ) { + if ( token.string[0] == 's' && !strcmp( token.string, "static" ) ) { + isStatic = 1; + } + } + memcpy( &lasttoken, &token, sizeof( token_t ) ); + } //end while + FreeSource( source ); +} //end of the function GetFunctionNamesFromFile + +void WriteWhiteSpace( FILE *fp, script_t *script ) { + int c; + //write out the white space + c = PS_NextWhiteSpaceChar( script ); + while ( c ) + { + //NOTE: do NOT write out carriage returns (for unix/linux compatibility + if ( c != 13 ) { + fputc( c, fp ); + } + c = PS_NextWhiteSpaceChar( script ); + } //end while +} //end of the function WriteWhiteSpace + +void WriteString( FILE *fp, script_t *script ) { + char *ptr; + + ptr = script->endwhitespace_p; + while ( ptr < script->script_p ) + { + fputc( *ptr, fp ); + ptr++; + } //end while +} //end of the function WriteString + +void ScrewUpFile( char *oldfile, char *newfile ) { + FILE *fp; + script_t *script; + token_t token; + replacefunc_t *f; + char *ptr; + + printf( "screwing up file %s\n", oldfile ); + script = LoadScriptFile( oldfile ); + if ( !script ) { + Error( "error opening %s\n", oldfile ); + } + fp = fopen( newfile, "wb" ); + if ( !fp ) { + Error( "error opening %s\n", newfile ); + } + // + while ( PS_ReadToken( script, &token ) ) + { + WriteWhiteSpace( fp, script ); + if ( token.type == TT_NAME ) { + f = FindFunctionName( token.string ); + if ( f ) { + ptr = f->newname; + } else { ptr = token.string;} + while ( *ptr ) + { + fputc( *ptr, fp ); + ptr++; + } //end while + } //end if + else + { + WriteString( fp, script ); + } //end else + } //end while + WriteWhiteSpace( fp, script ); + FreeMemory( script ); + fclose( fp ); +} //end of the function ScrewUpFile + +int verbose = 0; + +#ifdef _WIN32 + +void main( int argc, char *argv[] ) { + WIN32_FIND_DATA filedata; + HWND handle; + int done; //, i; + + if ( argc < 2 ) { + Error( "USAGE: screwup \n" ); + } //end if + + handle = FindFirstFile( argv[1], &filedata ); + done = ( handle == INVALID_HANDLE_VALUE ); + while ( !done ) + { + if ( !( filedata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) ) { + // + GetFunctionNamesFromFile( filedata.cFileName ); + } //end if + //find the next file + done = !FindNextFile( handle, &filedata ); + } //end while + DumpReplaceFunctions(); +} //end of the function main + +#else + +void Usage() { + Error( "USAGE: screwup [-o ] [ ..]\n" + "no -o defaults to g_funcs.h g_func_decs.h\n" ); +} + +/* +*nix version, let the shell do the pattern matching +(that's what shells are for :-)) +*/ +int main( int argc, char *argv[] ) { + int i; + int argbase = 1; + + if ( argc < 2 ) { + Usage(); + } //end if + + if ( !Q_stricmp( argv[1],"-o" ) ) { + if ( argc < 5 ) { + Usage(); + } + func_filename = argv[2]; + func_filedesc = argv[3]; + argbase = 4; + } + + for ( i = argbase; i < argc; i++ ) + { + printf( "%d: %s\n", i, argv[i] ); + GetFunctionNamesFromFile( argv[i] ); + } + DumpReplaceFunctions(); +} + +#endif diff --git a/Projects/Android/jni/rtcw/src/extractfuncs/out/src/extractfuncs/l_log.c b/Projects/Android/jni/rtcw/src/extractfuncs/out/src/extractfuncs/l_log.c new file mode 100644 index 0000000..afa0072 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/extractfuncs/out/src/extractfuncs/l_log.c @@ -0,0 +1,199 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +//=========================================================================== +// +// Name: l_log.c +// Function: log file stuff +// Programmer: Mr Elusive (MrElusive@demigod.demon.nl) +// Last update: 1997-12-31 +// Tab Size: 3 +//=========================================================================== + +#include +#include +#include + +#define MAX_QPATH 64 +#include "../bspc/qbsp.h" + +#define MAX_LOGFILENAMESIZE 1024 + +typedef struct logfile_s +{ + char filename[MAX_LOGFILENAMESIZE]; + FILE *fp; + int numwrites; +} logfile_t; + +logfile_t logfile; + +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void Log_Open( char *filename ) { + if ( !filename || !strlen( filename ) ) { + printf( "openlog \n" ); + return; + } //end if + if ( logfile.fp ) { + printf( "log file %s is already opened\n", logfile.filename ); + return; + } //end if + logfile.fp = fopen( filename, "wb" ); + if ( !logfile.fp ) { + printf( "can't open the log file %s\n", filename ); + return; + } //end if + strncpy( logfile.filename, filename, MAX_LOGFILENAMESIZE ); +// printf("Opened log %s\n", logfile.filename); +} //end of the function Log_Create +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void Log_Close( void ) { + if ( !logfile.fp ) { + printf( "no log file to close\n" ); + return; + } //end if + if ( fclose( logfile.fp ) ) { + printf( "can't close log file %s\n", logfile.filename ); + return; + } //end if + logfile.fp = NULL; +// printf("Closed log %s\n", logfile.filename); +} //end of the function Log_Close +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void Log_Shutdown( void ) { + if ( logfile.fp ) { + Log_Close(); + } +} //end of the function Log_Shutdown +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void Log_Print( char *fmt, ... ) { + va_list ap; +#ifdef WINBSPC + char buf[2048]; +#endif //WINBSPC + + if ( verbose ) { + va_start( ap, fmt ); +#ifdef WINBSPC + vsprintf( buf, fmt, ap ); + WinBSPCPrint( buf ); +#else + vprintf( fmt, ap ); +#endif //WINBSPS + va_end( ap ); + } //end if + + va_start( ap, fmt ); + if ( logfile.fp ) { + vfprintf( logfile.fp, fmt, ap ); + fflush( logfile.fp ); + } //end if + va_end( ap ); +} //end of the function Log_Print +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void Log_Write( char *fmt, ... ) { + va_list ap; + + if ( !logfile.fp ) { + return; + } + va_start( ap, fmt ); + vfprintf( logfile.fp, fmt, ap ); + va_end( ap ); + fflush( logfile.fp ); +} //end of the function Log_Write +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void Log_WriteTimeStamped( char *fmt, ... ) { + va_list ap; + + if ( !logfile.fp ) { + return; + } +/* fprintf(logfile.fp, "%d %02d:%02d:%02d:%02d ", + logfile.numwrites, + (int) (botlibglobals.time / 60 / 60), + (int) (botlibglobals.time / 60), + (int) (botlibglobals.time), + (int) ((int) (botlibglobals.time * 100)) - + ((int) botlibglobals.time) * 100);*/ + va_start( ap, fmt ); + vfprintf( logfile.fp, fmt, ap ); + va_end( ap ); + logfile.numwrites++; + fflush( logfile.fp ); +} //end of the function Log_Write +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +FILE *Log_FileStruct( void ) { + return logfile.fp; +} //end of the function Log_FileStruct +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void Log_Flush( void ) { + if ( logfile.fp ) { + fflush( logfile.fp ); + } +} //end of the function Log_Flush diff --git a/Projects/Android/jni/rtcw/src/extractfuncs/out/src/extractfuncs/l_log.h b/Projects/Android/jni/rtcw/src/extractfuncs/out/src/extractfuncs/l_log.h new file mode 100644 index 0000000..b1f6c1b --- /dev/null +++ b/Projects/Android/jni/rtcw/src/extractfuncs/out/src/extractfuncs/l_log.h @@ -0,0 +1,59 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +//=========================================================================== +// +// Name: l_log.h +// Function: log file stuff +// Programmer: Mr Elusive (MrElusive@demigod.demon.nl) +// Last update: 1997-12-31 +// Tab Size: 3 +//=========================================================================== + +//open a log file +void Log_Open( char *filename ); +//close the current log file +void Log_Close( void ); +//close log file if present +void Log_Shutdown( void ); +//print on stdout and write to the current opened log file +void Log_Print( char *fmt, ... ); +//write to the current opened log file +void Log_Write( char *fmt, ... ); +//write to the current opened log file with a time stamp +void Log_WriteTimeStamped( char *fmt, ... ); +//returns the log file structure +FILE *Log_FileStruct( void ); +//flush log file +void Log_Flush( void ); + +int Log_Written( void ); + +#ifdef WINBSPC +void WinBSPCPrint( char *str ); +#endif //WINBSPC diff --git a/Projects/Android/jni/rtcw/src/extractfuncs/out/src/extractfuncs/l_memory.c b/Projects/Android/jni/rtcw/src/extractfuncs/out/src/extractfuncs/l_memory.c new file mode 100644 index 0000000..71526c0 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/extractfuncs/out/src/extractfuncs/l_memory.c @@ -0,0 +1,444 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +/***************************************************************************** + * name: l_memory.c + * + * desc: memory allocation + * + * + *****************************************************************************/ + +#include "../game/q_shared.h" +#include "../game/botlib.h" +#include "l_log.h" +#include "../../src/botlib/be_interface.h" + +//#define MEMDEBUG +//#define MEMORYMANEGER + +#define MEM_ID 0x12345678l +#define HUNK_ID 0x87654321l + +int allocatedmemory; +int totalmemorysize; +int numblocks; + +#ifdef MEMORYMANEGER + +typedef struct memoryblock_s +{ + unsigned long int id; + void *ptr; + int size; +#ifdef MEMDEBUG + char *label; + char *file; + int line; +#endif //MEMDEBUG + struct memoryblock_s *prev, *next; +} memoryblock_t; + +memoryblock_t *memory; + +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void LinkMemoryBlock( memoryblock_t *block ) { + block->prev = NULL; + block->next = memory; + if ( memory ) { + memory->prev = block; + } + memory = block; +} //end of the function LinkMemoryBlock +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void UnlinkMemoryBlock( memoryblock_t *block ) { + if ( block->prev ) { + block->prev->next = block->next; + } else { memory = block->next;} + if ( block->next ) { + block->next->prev = block->prev; + } +} //end of the function UnlinkMemoryBlock +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +#ifdef MEMDEBUG +void *GetMemoryDebug( unsigned long size, char *label, char *file, int line ) +#else +void *GetMemory( unsigned long size ) +#endif //MEMDEBUG +{ + void *ptr; + memoryblock_t *block; + + ptr = malloc( size + sizeof( memoryblock_t ) ); + block = (memoryblock_t *) ptr; + block->id = MEM_ID; + block->ptr = (char *) ptr + sizeof( memoryblock_t ); + block->size = size + sizeof( memoryblock_t ); +#ifdef MEMDEBUG + block->label = label; + block->file = file; + block->line = line; +#endif //MEMDEBUG + LinkMemoryBlock( block ); + allocatedmemory += block->size; + totalmemorysize += block->size + sizeof( memoryblock_t ); + numblocks++; + return block->ptr; +} //end of the function GetMemoryDebug +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +#ifdef MEMDEBUG +void *GetClearedMemoryDebug( unsigned long size, char *label, char *file, int line ) +#else +void *GetClearedMemory( unsigned long size ) +#endif //MEMDEBUG +{ + void *ptr; +#ifdef MEMDEBUG + ptr = GetMemoryDebug( size, label, file, line ); +#else + ptr = GetMemory( size ); +#endif //MEMDEBUG + memset( ptr, 0, size ); + return ptr; +} //end of the function GetClearedMemory +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +#ifdef MEMDEBUG +void *GetHunkMemoryDebug( unsigned long size, char *label, char *file, int line ) +#else +void *GetHunkMemory( unsigned long size ) +#endif //MEMDEBUG +{ + void *ptr; + memoryblock_t *block; + + ptr = malloc( size + sizeof( memoryblock_t ) ); + block = (memoryblock_t *) ptr; + block->id = HUNK_ID; + block->ptr = (char *) ptr + sizeof( memoryblock_t ); + block->size = size + sizeof( memoryblock_t ); +#ifdef MEMDEBUG + block->label = label; + block->file = file; + block->line = line; +#endif //MEMDEBUG + LinkMemoryBlock( block ); + allocatedmemory += block->size; + totalmemorysize += block->size + sizeof( memoryblock_t ); + numblocks++; + return block->ptr; +} //end of the function GetHunkMemoryDebug +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +#ifdef MEMDEBUG +void *GetClearedHunkMemoryDebug( unsigned long size, char *label, char *file, int line ) +#else +void *GetClearedHunkMemory( unsigned long size ) +#endif //MEMDEBUG +{ + void *ptr; +#ifdef MEMDEBUG + ptr = GetHunkMemoryDebug( size, label, file, line ); +#else + ptr = GetHunkMemory( size ); +#endif //MEMDEBUG + memset( ptr, 0, size ); + return ptr; +} //end of the function GetClearedHunkMemory +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +memoryblock_t *BlockFromPointer( void *ptr, char *str ) { + memoryblock_t *block; + + if ( !ptr ) { +#ifdef MEMDEBUG + //char *crash = (char *) NULL; + //crash[0] = 1; + printf( PRT_FATAL, "%s: NULL pointer\n", str ); +#endif MEMDEBUG + return NULL; + } //end if + block = ( memoryblock_t * )( (char *) ptr - sizeof( memoryblock_t ) ); + if ( block->id != MEM_ID && block->id != HUNK_ID ) { + printf( PRT_FATAL, "%s: invalid memory block\n", str ); + return NULL; + } //end if + if ( block->ptr != ptr ) { + printf( PRT_FATAL, "%s: memory block pointer invalid\n", str ); + return NULL; + } //end if + return block; +} //end of the function BlockFromPointer +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void FreeMemory( void *ptr ) { + memoryblock_t *block; + + block = BlockFromPointer( ptr, "FreeMemory" ); + if ( !block ) { + return; + } + UnlinkMemoryBlock( block ); + allocatedmemory -= block->size; + totalmemorysize -= block->size + sizeof( memoryblock_t ); + numblocks--; + // + if ( block->id == MEM_ID ) { + free( block ); + } //end if +} //end of the function FreeMemory +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +int MemoryByteSize( void *ptr ) { + memoryblock_t *block; + + block = BlockFromPointer( ptr, "MemoryByteSize" ); + if ( !block ) { + return 0; + } + return block->size; +} //end of the function MemoryByteSize +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void PrintUsedMemorySize( void ) { + printf( PRT_MESSAGE, "total allocated memory: %d KB\n", allocatedmemory >> 10 ); + printf( PRT_MESSAGE, "total botlib memory: %d KB\n", totalmemorysize >> 10 ); + printf( PRT_MESSAGE, "total memory blocks: %d\n", numblocks ); +} //end of the function PrintUsedMemorySize +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void PrintMemoryLabels( void ) { + memoryblock_t *block; + int i; + + PrintUsedMemorySize(); + i = 0; + Log_Write( "\r\n" ); + for ( block = memory; block; block = block->next ) + { +#ifdef MEMDEBUG + if ( block->id == HUNK_ID ) { + Log_Write( "%6d, hunk %p, %8d: %24s line %6d: %s\r\n", i, block->ptr, block->size, block->file, block->line, block->label ); + } //end if + else + { + Log_Write( "%6d, %p, %8d: %24s line %6d: %s\r\n", i, block->ptr, block->size, block->file, block->line, block->label ); + } //end else +#endif //MEMDEBUG + i++; + } //end for +} //end of the function PrintMemoryLabels +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void DumpMemory( void ) { + memoryblock_t *block; + + for ( block = memory; block; block = memory ) + { + FreeMemory( block->ptr ); + } //end for + totalmemorysize = 0; + allocatedmemory = 0; +} //end of the function DumpMemory + +#else + +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +#ifdef MEMDEBUG +void *GetMemoryDebug( unsigned long size, char *label, char *file, int line ) +#else +void *GetMemory( unsigned long size ) +#endif //MEMDEBUG +{ + void *ptr; + unsigned long int *memid; + + ptr = malloc( size + sizeof( unsigned long int ) ); + if ( !ptr ) { + return NULL; + } + memid = (unsigned long int *) ptr; + *memid = MEM_ID; + return (unsigned long int *) ( (char *) ptr + sizeof( unsigned long int ) ); +} //end of the function GetMemory +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +#ifdef MEMDEBUG +void *GetClearedMemoryDebug( unsigned long size, char *label, char *file, int line ) +#else +void *GetClearedMemory( unsigned long size ) +#endif //MEMDEBUG +{ + void *ptr; +#ifdef MEMDEBUG + ptr = GetMemoryDebug( size, label, file, line ); +#else +ptr = GetMemory( size ); +#endif //MEMDEBUG +memset( ptr, 0, size ); +return ptr; +} //end of the function GetClearedMemory +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +#ifdef MEMDEBUG +void *GetHunkMemoryDebug( unsigned long size, char *label, char *file, int line ) +#else +void *GetHunkMemory( unsigned long size ) +#endif //MEMDEBUG +{ + void *ptr; + unsigned long int *memid; + + ptr = malloc( size + sizeof( unsigned long int ) ); + if ( !ptr ) { + return NULL; + } + memid = (unsigned long int *) ptr; + *memid = HUNK_ID; + return (unsigned long int *) ( (char *) ptr + sizeof( unsigned long int ) ); +} //end of the function GetHunkMemory +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +#ifdef MEMDEBUG +void *GetClearedHunkMemoryDebug( unsigned long size, char *label, char *file, int line ) +#else +void *GetClearedHunkMemory( unsigned long size ) +#endif //MEMDEBUG +{ + void *ptr; +#ifdef MEMDEBUG + ptr = GetHunkMemoryDebug( size, label, file, line ); +#else +ptr = GetHunkMemory( size ); +#endif //MEMDEBUG +memset( ptr, 0, size ); +return ptr; +} //end of the function GetClearedHunkMemory +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void FreeMemory( void *ptr ) { + unsigned long int *memid; + + memid = (unsigned long int *) ( (char *) ptr - sizeof( unsigned long int ) ); + + if ( *memid == MEM_ID ) { + free( memid ); + } //end if +} //end of the function FreeMemory +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void PrintUsedMemorySize( void ) { +} //end of the function PrintUsedMemorySize +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void PrintMemoryLabels( void ) { +} //end of the function PrintMemoryLabels + +#endif diff --git a/Projects/Android/jni/rtcw/src/extractfuncs/out/src/extractfuncs/l_memory.h b/Projects/Android/jni/rtcw/src/extractfuncs/out/src/extractfuncs/l_memory.h new file mode 100644 index 0000000..c33d715 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/extractfuncs/out/src/extractfuncs/l_memory.h @@ -0,0 +1,80 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +/***************************************************************************** + * name: l_memory.h + * + * desc: memory management + * + * + *****************************************************************************/ + +//#define MEMDEBUG + +#ifdef MEMDEBUG +#define GetMemory( size ) GetMemoryDebug( size, # size, __FILE__, __LINE__ ); +#define GetClearedMemory( size ) GetClearedMemoryDebug( size, # size, __FILE__, __LINE__ ); +//allocate a memory block of the given size +void *GetMemoryDebug( unsigned long size, char *label, char *file, int line ); +//allocate a memory block of the given size and clear it +void *GetClearedMemoryDebug( unsigned long size, char *label, char *file, int line ); +// +#define GetHunkMemory( size ) GetHunkMemoryDebug( size, # size, __FILE__, __LINE__ ); +#define GetClearedHunkMemory( size ) GetClearedHunkMemoryDebug( size, # size, __FILE__, __LINE__ ); +//allocate a memory block of the given size +void *GetHunkMemoryDebug( unsigned long size, char *label, char *file, int line ); +//allocate a memory block of the given size and clear it +void *GetClearedHunkMemoryDebug( unsigned long size, char *label, char *file, int line ); +#else +//allocate a memory block of the given size +void *GetMemory( unsigned long size ); +//allocate a memory block of the given size and clear it +void *GetClearedMemory( unsigned long size ); +// +#ifdef BSPC +#define GetHunkMemory GetMemory +#define GetClearedHunkMemory GetClearedMemory +#else +//allocate a memory block of the given size +void *GetHunkMemory( unsigned long size ); +//allocate a memory block of the given size and clear it +void *GetClearedHunkMemory( unsigned long size ); +#endif +#endif + +//free the given memory block +void FreeMemory( void *ptr ); +//prints the total used memory size +void PrintUsedMemorySize( void ); +//print all memory blocks with label +void PrintMemoryLabels( void ); +//returns the size of the memory block in bytes +int MemoryByteSize( void *ptr ); +//free all allocated memory +void DumpMemory( void ); diff --git a/Projects/Android/jni/rtcw/src/extractfuncs/out/src/extractfuncs/l_precomp.c b/Projects/Android/jni/rtcw/src/extractfuncs/out/src/extractfuncs/l_precomp.c new file mode 100644 index 0000000..23be10c --- /dev/null +++ b/Projects/Android/jni/rtcw/src/extractfuncs/out/src/extractfuncs/l_precomp.c @@ -0,0 +1,3167 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +/***************************************************************************** + * name: l_precomp.c + * + * desc: pre compiler + * + * + *****************************************************************************/ + +//Notes: fix: PC_StringizeTokens + +#ifdef SCREWUP +#include +#include +#include +#include +#include +#include +#include +#include "l_memory.h" +#include "l_script.h" +#include "l_precomp.h" +#include "l_log.h" + +typedef enum {qfalse, qtrue} qboolean; + +// Ridah, ripped from q_shared.c +/* +============= +Q_strncpyz + +Safe strncpy that ensures a trailing zero +============= +*/ +extern void Error( char *error, ... ); +void Q_strncpyz( char *dest, const char *src, int destsize ) { + if ( !src ) { + Error( "Q_strncpyz: NULL src" ); + } + if ( destsize < 1 ) { + Error( "Q_strncpyz: destsize < 1" ); + } + + strncpy( dest, src, destsize - 1 ); + dest[destsize - 1] = 0; +} + +int Q_stricmpn( const char *s1, const char *s2, int n ) { + int c1, c2; + + do { + c1 = *s1++; + c2 = *s2++; + + if ( !n-- ) { + return 0; // strings are equal until end point + } + + if ( c1 != c2 ) { + if ( c1 >= 'a' && c1 <= 'z' ) { + c1 -= ( 'a' - 'A' ); + } + if ( c2 >= 'a' && c2 <= 'z' ) { + c2 -= ( 'a' - 'A' ); + } + if ( c1 != c2 ) { + return c1 < c2 ? -1 : 1; + } + } + } while ( c1 ); + + return 0; // strings are equal +} + +int Q_strncmp( const char *s1, const char *s2, int n ) { + int c1, c2; + + do { + c1 = *s1++; + c2 = *s2++; + + if ( !n-- ) { + return 0; // strings are equal until end point + } + + if ( c1 != c2 ) { + return c1 < c2 ? -1 : 1; + } + } while ( c1 ); + + return 0; // strings are equal +} + +int Q_stricmp( const char *s1, const char *s2 ) { + return Q_stricmpn( s1, s2, 99999 ); +} + + +char *Q_strlwr( char *s1 ) { + char *s; + + s = s1; + while ( *s ) { + *s = tolower( *s ); + s++; + } + return s1; +} + +char *Q_strupr( char *s1 ) { + char *s; + + s = s1; + while ( *s ) { + *s = toupper( *s ); + s++; + } + return s1; +} + +#endif //SCREWUP + +#ifdef BOTLIB +#include "../game/q_shared.h" +#include "botlib.h" +#include "be_interface.h" +#include "l_memory.h" +#include "l_script.h" +#include "l_precomp.h" +#include "l_log.h" +#endif //BOTLIB + +#ifdef MEQCC +#include "qcc.h" +#include "time.h" //time & ctime +#include "math.h" //fabs +#include "l_memory.h" +#include "l_script.h" +#include "l_precomp.h" +#include "l_log.h" + +#define qtrue true +#define qfalse false +#endif //MEQCC + +#ifdef BSPC +//include files for usage in the BSP Converter +#include "../bspc/qbsp.h" +#include "../bspc/l_log.h" +#include "../bspc/l_mem.h" +#include "l_precomp.h" + +#define qtrue true +#define qfalse false +#define Q_stricmp stricmp +#endif //BSPC + +#if defined( QUAKE ) && !defined( BSPC ) +#include "l_utils.h" +#endif //QUAKE + +//#define DEBUG_EVAL + +#define MAX_DEFINEPARMS 128 + +#define DEFINEHASHING 1 + +//directive name with parse function +typedef struct directive_s +{ + char *name; + int ( *func )( source_t *source ); +} directive_t; + +#define DEFINEHASHSIZE 1024 + +#define TOKEN_HEAP_SIZE 4096 + +int numtokens; +/* +int tokenheapinitialized; //true when the token heap is initialized +token_t token_heap[TOKEN_HEAP_SIZE]; //heap with tokens +token_t *freetokens; //free tokens from the heap +*/ + +//list with global defines added to every source loaded +define_t *globaldefines; + +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void QDECL SourceError( source_t *source, char *str, ... ) { + char text[1024]; + va_list ap; + + va_start( ap, str ); + vsprintf( text, str, ap ); + va_end( ap ); +#ifdef BOTLIB + botimport.Print( PRT_ERROR, "file %s, line %d: %s\n", source->scriptstack->filename, source->scriptstack->line, text ); +#endif //BOTLIB +#ifdef MEQCC + printf( "error: file %s, line %d: %s\n", source->scriptstack->filename, source->scriptstack->line, text ); +#endif //MEQCC +#ifdef BSPC + Log_Print( "error: file %s, line %d: %s\n", source->scriptstack->filename, source->scriptstack->line, text ); +#endif //BSPC +} //end of the function SourceError +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void QDECL SourceWarning( source_t *source, char *str, ... ) { + char text[1024]; + va_list ap; + + va_start( ap, str ); + vsprintf( text, str, ap ); + va_end( ap ); +#ifdef BOTLIB + botimport.Print( PRT_WARNING, "file %s, line %d: %s\n", source->scriptstack->filename, source->scriptstack->line, text ); +#endif //BOTLIB +#ifdef MEQCC + printf( "warning: file %s, line %d: %s\n", source->scriptstack->filename, source->scriptstack->line, text ); +#endif //MEQCC +#ifdef BSPC + Log_Print( "warning: file %s, line %d: %s\n", source->scriptstack->filename, source->scriptstack->line, text ); +#endif //BSPC +} //end of the function ScriptWarning +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void PC_PushIndent( source_t *source, int type, int skip ) { + indent_t *indent; + + indent = (indent_t *) GetMemory( sizeof( indent_t ) ); + indent->type = type; + indent->script = source->scriptstack; + indent->skip = ( skip != 0 ); + source->skip += indent->skip; + indent->next = source->indentstack; + source->indentstack = indent; +} //end of the function PC_PushIndent +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void PC_PopIndent( source_t *source, int *type, int *skip ) { + indent_t *indent; + + *type = 0; + *skip = 0; + + indent = source->indentstack; + if ( !indent ) { + return; + } + + //must be an indent from the current script + if ( source->indentstack->script != source->scriptstack ) { + return; + } + + *type = indent->type; + *skip = indent->skip; + source->indentstack = source->indentstack->next; + source->skip -= indent->skip; + FreeMemory( indent ); +} //end of the function PC_PopIndent +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void PC_PushScript( source_t *source, script_t *script ) { + script_t *s; + + for ( s = source->scriptstack; s; s = s->next ) + { + if ( !Q_stricmp( s->filename, script->filename ) ) { + SourceError( source, "%s recursively included", script->filename ); + return; + } //end if + } //end for + //push the script on the script stack + script->next = source->scriptstack; + source->scriptstack = script; +} //end of the function PC_PushScript +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void PC_InitTokenHeap( void ) { + /* + int i; + + if (tokenheapinitialized) return; + freetokens = NULL; + for (i = 0; i < TOKEN_HEAP_SIZE; i++) + { + token_heap[i].next = freetokens; + freetokens = &token_heap[i]; + } //end for + tokenheapinitialized = qtrue; + */ +} //end of the function PC_InitTokenHeap +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +token_t *PC_CopyToken( token_t *token ) { + token_t *t; + +// t = (token_t *) malloc(sizeof(token_t)); + t = (token_t *) GetMemory( sizeof( token_t ) ); +// t = freetokens; + if ( !t ) { +#ifdef BSPC + Error( "out of token space\n" ); +#else +#ifdef SCREWUP + Error( "out of token space\n" ); +#else + Com_Error( ERR_FATAL, "out of token space\n" ); +#endif +#endif + return NULL; + } //end if +// freetokens = freetokens->next; + memcpy( t, token, sizeof( token_t ) ); + t->next = NULL; + numtokens++; + return t; +} //end of the function PC_CopyToken +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void PC_FreeToken( token_t *token ) { + //free(token); + FreeMemory( token ); +// token->next = freetokens; +// freetokens = token; + numtokens--; +} //end of the function PC_FreeToken +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_ReadSourceToken( source_t *source, token_t *token ) { + token_t *t; + script_t *script; + int type, skip; + + //if there's no token already available + while ( !source->tokens ) + { + //if there's a token to read from the script + if ( PS_ReadToken( source->scriptstack, token ) ) { + return qtrue; + } + //if at the end of the script + if ( EndOfScript( source->scriptstack ) ) { + //remove all indents of the script + while ( source->indentstack && + source->indentstack->script == source->scriptstack ) + { + SourceWarning( source, "missing #endif" ); + PC_PopIndent( source, &type, &skip ); + } //end if + } //end if + //if this was the initial script + if ( !source->scriptstack->next ) { + return qfalse; + } + //remove the script and return to the last one + script = source->scriptstack; + source->scriptstack = source->scriptstack->next; + FreeScript( script ); + } //end while + //copy the already available token + memcpy( token, source->tokens, sizeof( token_t ) ); + //free the read token + t = source->tokens; + source->tokens = source->tokens->next; + PC_FreeToken( t ); + return qtrue; +} //end of the function PC_ReadSourceToken +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_UnreadSourceToken( source_t *source, token_t *token ) { + token_t *t; + + t = PC_CopyToken( token ); + t->next = source->tokens; + source->tokens = t; + return qtrue; +} //end of the function PC_UnreadSourceToken +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_ReadDefineParms( source_t *source, define_t *define, token_t **parms, int maxparms ) { + token_t token, *t, *last; + int i, done, lastcomma, numparms, indent; + + if ( !PC_ReadSourceToken( source, &token ) ) { + SourceError( source, "define %s missing parms", define->name ); + return qfalse; + } //end if + // + if ( define->numparms > maxparms ) { + SourceError( source, "define with more than %d parameters", maxparms ); + return qfalse; + } //end if + // + for ( i = 0; i < define->numparms; i++ ) parms[i] = NULL; + //if no leading "(" + if ( strcmp( token.string, "(" ) ) { + PC_UnreadSourceToken( source, &token ); + SourceError( source, "define %s missing parms", define->name ); + return qfalse; + } //end if + //read the define parameters + for ( done = 0, numparms = 0, indent = 0; !done; ) + { + if ( numparms >= maxparms ) { + SourceError( source, "define %s with too many parms", define->name ); + return qfalse; + } //end if + if ( numparms >= define->numparms ) { + SourceWarning( source, "define %s has too many parms", define->name ); + return qfalse; + } //end if + parms[numparms] = NULL; + lastcomma = 1; + last = NULL; + while ( !done ) + { + // + if ( !PC_ReadSourceToken( source, &token ) ) { + SourceError( source, "define %s incomplete", define->name ); + return qfalse; + } //end if + // + if ( !strcmp( token.string, "," ) ) { + if ( indent <= 0 ) { + if ( lastcomma ) { + SourceWarning( source, "too many comma's" ); + } + lastcomma = 1; + break; + } //end if + } //end if + lastcomma = 0; + // + if ( !strcmp( token.string, "(" ) ) { + indent++; + continue; + } //end if + else if ( !strcmp( token.string, ")" ) ) { + if ( --indent <= 0 ) { + if ( !parms[define->numparms - 1] ) { + SourceWarning( source, "too few define parms" ); + } //end if + done = 1; + break; + } //end if + } //end if + // + if ( numparms < define->numparms ) { + // + t = PC_CopyToken( &token ); + t->next = NULL; + if ( last ) { + last->next = t; + } else { parms[numparms] = t;} + last = t; + } //end if + } //end while + numparms++; + } //end for + return qtrue; +} //end of the function PC_ReadDefineParms +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_StringizeTokens( token_t *tokens, token_t *token ) { + token_t *t; + + token->type = TT_STRING; + token->whitespace_p = NULL; + token->endwhitespace_p = NULL; + token->string[0] = '\0'; + strcat( token->string, "\"" ); + for ( t = tokens; t; t = t->next ) + { + strncat( token->string, t->string, MAX_TOKEN - strlen( token->string ) ); + } //end for + strncat( token->string, "\"", MAX_TOKEN - strlen( token->string ) ); + return qtrue; +} //end of the function PC_StringizeTokens +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_MergeTokens( token_t *t1, token_t *t2 ) { + //merging of a name with a name or number + if ( t1->type == TT_NAME && ( t2->type == TT_NAME || t2->type == TT_NUMBER ) ) { + strcat( t1->string, t2->string ); + return qtrue; + } //end if + //merging of two strings + if ( t1->type == TT_STRING && t2->type == TT_STRING ) { + //remove trailing double quote + t1->string[strlen( t1->string ) - 1] = '\0'; + //concat without leading double quote + strcat( t1->string, &t2->string[1] ); + return qtrue; + } //end if + //FIXME: merging of two number of the same sub type + return qfalse; +} //end of the function PC_MergeTokens +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +/* +void PC_PrintDefine(define_t *define) +{ + printf("define->name = %s\n", define->name); + printf("define->flags = %d\n", define->flags); + printf("define->builtin = %d\n", define->builtin); + printf("define->numparms = %d\n", define->numparms); +// token_t *parms; //define parameters +// token_t *tokens; //macro tokens (possibly containing parm tokens) +// struct define_s *next; //next defined macro in a list +} //end of the function PC_PrintDefine*/ +#if DEFINEHASHING +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void PC_PrintDefineHashTable( define_t **definehash ) { + int i; + define_t *d; + + for ( i = 0; i < DEFINEHASHSIZE; i++ ) + { + Log_Write( "%4d:", i ); + for ( d = definehash[i]; d; d = d->hashnext ) + { + Log_Write( " %s", d->name ); + } //end for + Log_Write( "\n" ); + } //end for +} //end of the function PC_PrintDefineHashTable +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +//char primes[16] = {1, 3, 5, 7, 11, 13, 17, 19, 23, 27, 29, 31, 37, 41, 43, 47}; + +int PC_NameHash( char *name ) { + int register hash, i; + + hash = 0; + for ( i = 0; name[i] != '\0'; i++ ) + { + hash += name[i] * ( 119 + i ); + //hash += (name[i] << 7) + i; + //hash += (name[i] << (i&15)); + } //end while + hash = ( hash ^ ( hash >> 10 ) ^ ( hash >> 20 ) ) & ( DEFINEHASHSIZE - 1 ); + return hash; +} //end of the function PC_NameHash +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void PC_AddDefineToHash( define_t *define, define_t **definehash ) { + int hash; + + hash = PC_NameHash( define->name ); + define->hashnext = definehash[hash]; + definehash[hash] = define; +} //end of the function PC_AddDefineToHash +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +define_t *PC_FindHashedDefine( define_t **definehash, char *name ) { + define_t *d; + int hash; + + hash = PC_NameHash( name ); + for ( d = definehash[hash]; d; d = d->hashnext ) + { + if ( !strcmp( d->name, name ) ) { + return d; + } + } //end for + return NULL; +} //end of the function PC_FindHashedDefine +#endif //DEFINEHASHING +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +define_t *PC_FindDefine( define_t *defines, char *name ) { + define_t *d; + + for ( d = defines; d; d = d->next ) + { + if ( !strcmp( d->name, name ) ) { + return d; + } + } //end for + return NULL; +} //end of the function PC_FindDefine +//============================================================================ +// +// Parameter: - +// Returns: number of the parm +// if no parm found with the given name -1 is returned +// Changes Globals: - +//============================================================================ +int PC_FindDefineParm( define_t *define, char *name ) { + token_t *p; + int i; + + i = 0; + for ( p = define->parms; p; p = p->next ) + { + if ( !strcmp( p->string, name ) ) { + return i; + } + i++; + } //end for + return -1; +} //end of the function PC_FindDefineParm +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void PC_FreeDefine( define_t *define ) { + token_t *t, *next; + + //free the define parameters + for ( t = define->parms; t; t = next ) + { + next = t->next; + PC_FreeToken( t ); + } //end for + //free the define tokens + for ( t = define->tokens; t; t = next ) + { + next = t->next; + PC_FreeToken( t ); + } //end for + //free the define + FreeMemory( define ); +} //end of the function PC_FreeDefine +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void PC_AddBuiltinDefines( source_t *source ) { + int i; + define_t *define; + struct builtin + { + char *string; + int builtin; + } builtin[] = { + "__LINE__", BUILTIN_LINE, + "__FILE__", BUILTIN_FILE, + "__DATE__", BUILTIN_DATE, + "__TIME__", BUILTIN_TIME, +// "__STDC__", BUILTIN_STDC, + NULL, 0 + }; + + for ( i = 0; builtin[i].string; i++ ) + { + define = (define_t *) GetMemory( sizeof( define_t ) + strlen( builtin[i].string ) + 1 ); + memset( define, 0, sizeof( define_t ) ); + define->name = (char *) define + sizeof( define_t ); + strcpy( define->name, builtin[i].string ); + define->flags |= DEFINE_FIXED; + define->builtin = builtin[i].builtin; + //add the define to the source +#if DEFINEHASHING + PC_AddDefineToHash( define, source->definehash ); +#else + define->next = source->defines; + source->defines = define; +#endif //DEFINEHASHING + } //end for +} //end of the function PC_AddBuiltinDefines +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_ExpandBuiltinDefine( source_t *source, define_t *define, + token_t **firsttoken, token_t **lasttoken ) { + token_t token; + unsigned long t; // time_t t; //to prevent LCC warning + char *curtime; + + memcpy( &token, &source->token, sizeof( token_t ) ); + switch ( define->builtin ) + { + case BUILTIN_LINE: + { + sprintf( token.string, "%d", source->token.line ); +#ifdef NUMBERVALUE + token.intvalue = source->token.line; + token.floatvalue = source->token.line; +#endif //NUMBERVALUE + token.type = TT_NUMBER; + token.subtype = TT_DECIMAL | TT_INTEGER; + *firsttoken = &token; + *lasttoken = &token; + break; + } //end case + case BUILTIN_FILE: + { + strcpy( token.string, source->scriptstack->filename ); + token.type = TT_NAME; + token.subtype = strlen( token.string ); + *firsttoken = &token; + *lasttoken = &token; + break; + } //end case + case BUILTIN_DATE: + { + t = time( NULL ); + curtime = ctime( &t ); + strcpy( token.string, "\"" ); + strncat( token.string, curtime + 4, 7 ); + strncat( token.string + 7, curtime + 20, 4 ); + strcat( token.string, "\"" ); + free( curtime ); + token.type = TT_NAME; + token.subtype = strlen( token.string ); + *firsttoken = &token; + *lasttoken = &token; + break; + } //end case + case BUILTIN_TIME: + { + t = time( NULL ); + curtime = ctime( &t ); + strcpy( token.string, "\"" ); + strncat( token.string, curtime + 11, 8 ); + strcat( token.string, "\"" ); + free( curtime ); + token.type = TT_NAME; + token.subtype = strlen( token.string ); + *firsttoken = &token; + *lasttoken = &token; + break; + } //end case + case BUILTIN_STDC: + default: + { + *firsttoken = NULL; + *lasttoken = NULL; + break; + } //end case + } //end switch + return qtrue; +} //end of the function PC_ExpandBuiltinDefine +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_ExpandDefine( source_t *source, define_t *define, + token_t **firsttoken, token_t **lasttoken ) { + token_t *parms[MAX_DEFINEPARMS], *dt, *pt, *t; + token_t *t1, *t2, *first, *last, *nextpt, token; + int parmnum, i; + + //if it is a builtin define + if ( define->builtin ) { + return PC_ExpandBuiltinDefine( source, define, firsttoken, lasttoken ); + } //end if + //if the define has parameters + if ( define->numparms ) { + if ( !PC_ReadDefineParms( source, define, parms, MAX_DEFINEPARMS ) ) { + return qfalse; + } +#ifdef DEBUG_EVAL + for ( i = 0; i < define->numparms; i++ ) + { + Log_Write( "define parms %d:", i ); + for ( pt = parms[i]; pt; pt = pt->next ) + { + Log_Write( "%s", pt->string ); + } //end for + } //end for +#endif //DEBUG_EVAL + } //end if + //empty list at first + first = NULL; + last = NULL; + //create a list with tokens of the expanded define + for ( dt = define->tokens; dt; dt = dt->next ) + { + parmnum = -1; + //if the token is a name, it could be a define parameter + if ( dt->type == TT_NAME ) { + parmnum = PC_FindDefineParm( define, dt->string ); + } //end if + //if it is a define parameter + if ( parmnum >= 0 ) { + for ( pt = parms[parmnum]; pt; pt = pt->next ) + { + t = PC_CopyToken( pt ); + //add the token to the list + t->next = NULL; + if ( last ) { + last->next = t; + } else { first = t;} + last = t; + } //end for + } //end if + else + { + //if stringizing operator + if ( dt->string[0] == '#' && dt->string[1] == '\0' ) { + //the stringizing operator must be followed by a define parameter + if ( dt->next ) { + parmnum = PC_FindDefineParm( define, dt->next->string ); + } else { parmnum = -1;} + // + if ( parmnum >= 0 ) { + //step over the stringizing operator + dt = dt->next; + //stringize the define parameter tokens + if ( !PC_StringizeTokens( parms[parmnum], &token ) ) { + SourceError( source, "can't stringize tokens" ); + return qfalse; + } //end if + t = PC_CopyToken( &token ); + } //end if + else + { + SourceWarning( source, "stringizing operator without define parameter" ); + continue; + } //end if + } //end if + else + { + t = PC_CopyToken( dt ); + } //end else + //add the token to the list + t->next = NULL; + if ( last ) { + last->next = t; + } else { first = t;} + last = t; + } //end else + } //end for + //check for the merging operator + for ( t = first; t; ) + { + if ( t->next ) { + //if the merging operator + if ( t->next->string[0] == '#' && t->next->string[1] == '#' ) { + t1 = t; + t2 = t->next->next; + if ( t2 ) { + if ( !PC_MergeTokens( t1, t2 ) ) { + SourceError( source, "can't merge %s with %s", t1->string, t2->string ); + return qfalse; + } //end if + PC_FreeToken( t1->next ); + t1->next = t2->next; + if ( t2 == last ) { + last = t1; + } + PC_FreeToken( t2 ); + continue; + } //end if + } //end if + } //end if + t = t->next; + } //end for + //store the first and last token of the list + *firsttoken = first; + *lasttoken = last; + //free all the parameter tokens + for ( i = 0; i < define->numparms; i++ ) + { + for ( pt = parms[i]; pt; pt = nextpt ) + { + nextpt = pt->next; + PC_FreeToken( pt ); + } //end for + } //end for + // + return qtrue; +} //end of the function PC_ExpandDefine +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_ExpandDefineIntoSource( source_t *source, define_t *define ) { + token_t *firsttoken, *lasttoken; + + if ( !PC_ExpandDefine( source, define, &firsttoken, &lasttoken ) ) { + return qfalse; + } + + if ( firsttoken && lasttoken ) { + lasttoken->next = source->tokens; + source->tokens = firsttoken; + return qtrue; + } //end if + return qfalse; +} //end of the function PC_ExpandDefineIntoSource +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void PC_ConvertPath( char *path ) { + char *ptr; + + //remove double path seperators + for ( ptr = path; *ptr; ) + { + if ( ( *ptr == '\\' || *ptr == '/' ) && + ( *( ptr + 1 ) == '\\' || *( ptr + 1 ) == '/' ) ) { + strcpy( ptr, ptr + 1 ); + } //end if + else + { + ptr++; + } //end else + } //end while + //set OS dependent path seperators + for ( ptr = path; *ptr; ) + { + if ( *ptr == '/' || *ptr == '\\' ) { + *ptr = PATHSEPERATOR_CHAR; + } + ptr++; + } //end while +} //end of the function PC_ConvertPath +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_Directive_include( source_t *source ) { + script_t *script; + token_t token; + char path[_MAX_PATH]; +#ifdef QUAKE + foundfile_t file; +#endif //QUAKE + + if ( source->skip > 0 ) { + return qtrue; + } + // + if ( !PC_ReadSourceToken( source, &token ) ) { + SourceError( source, "#include without file name" ); + return qfalse; + } //end if + if ( token.linescrossed > 0 ) { + SourceError( source, "#include without file name" ); + return qfalse; + } //end if + if ( token.type == TT_STRING ) { + StripDoubleQuotes( token.string ); + PC_ConvertPath( token.string ); + script = LoadScriptFile( token.string ); + if ( !script ) { + strcpy( path, source->includepath ); + strcat( path, token.string ); + script = LoadScriptFile( path ); + } //end if + } //end if + else if ( token.type == TT_PUNCTUATION && *token.string == '<' ) { + strcpy( path, source->includepath ); + while ( PC_ReadSourceToken( source, &token ) ) + { + if ( token.linescrossed > 0 ) { + PC_UnreadSourceToken( source, &token ); + break; + } //end if + if ( token.type == TT_PUNCTUATION && *token.string == '>' ) { + break; + } + strncat( path, token.string, _MAX_PATH ); + } //end while + if ( *token.string != '>' ) { + SourceWarning( source, "#include missing trailing >" ); + } //end if + if ( !strlen( path ) ) { + SourceError( source, "#include without file name between < >" ); + return qfalse; + } //end if + PC_ConvertPath( path ); + script = LoadScriptFile( path ); + } //end if + else + { + SourceError( source, "#include without file name" ); + return qfalse; + } //end else +#ifdef QUAKE + if ( !script ) { + memset( &file, 0, sizeof( foundfile_t ) ); + script = LoadScriptFile( path ); + if ( script ) { + strncpy( script->filename, path, _MAX_PATH ); + } + } //end if +#endif //QUAKE + if ( !script ) { +#ifdef SCREWUP + SourceWarning( source, "file %s not found", path ); + return qtrue; +#else + SourceError( source, "file %s not found", path ); + return qfalse; +#endif //SCREWUP + } //end if + PC_PushScript( source, script ); + return qtrue; +} //end of the function PC_Directive_include +//============================================================================ +// reads a token from the current line, continues reading on the next +// line only if a backslash '\' is encountered. +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_ReadLine( source_t *source, token_t *token ) { + int crossline; + + crossline = 0; + do + { + if ( !PC_ReadSourceToken( source, token ) ) { + return qfalse; + } + + if ( token->linescrossed > crossline ) { + PC_UnreadSourceToken( source, token ); + return qfalse; + } //end if + crossline = 1; + } while ( !strcmp( token->string, "\\" ) ); + return qtrue; +} //end of the function PC_ReadLine +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_WhiteSpaceBeforeToken( token_t *token ) { + return token->endwhitespace_p - token->whitespace_p > 0; +} //end of the function PC_WhiteSpaceBeforeToken +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void PC_ClearTokenWhiteSpace( token_t *token ) { + token->whitespace_p = NULL; + token->endwhitespace_p = NULL; + token->linescrossed = 0; +} //end of the function PC_ClearTokenWhiteSpace +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_Directive_undef( source_t *source ) { + token_t token; + define_t *define, *lastdefine; + int hash; + + if ( source->skip > 0 ) { + return qtrue; + } + // + if ( !PC_ReadLine( source, &token ) ) { + SourceError( source, "undef without name" ); + return qfalse; + } //end if + if ( token.type != TT_NAME ) { + PC_UnreadSourceToken( source, &token ); + SourceError( source, "expected name, found %s", token.string ); + return qfalse; + } //end if +#if DEFINEHASHING + + hash = PC_NameHash( token.string ); + for ( lastdefine = NULL, define = source->definehash[hash]; define; define = define->hashnext ) + { + if ( !strcmp( define->name, token.string ) ) { + if ( define->flags & DEFINE_FIXED ) { + SourceWarning( source, "can't undef %s", token.string ); + } //end if + else + { + if ( lastdefine ) { + lastdefine->hashnext = define->hashnext; + } else { source->definehash[hash] = define->hashnext;} + PC_FreeDefine( define ); + } //end else + break; + } //end if + lastdefine = define; + } //end for +#else //DEFINEHASHING + for ( lastdefine = NULL, define = source->defines; define; define = define->next ) + { + if ( !strcmp( define->name, token.string ) ) { + if ( define->flags & DEFINE_FIXED ) { + SourceWarning( source, "can't undef %s", token.string ); + } //end if + else + { + if ( lastdefine ) { + lastdefine->next = define->next; + } else { source->defines = define->next;} + PC_FreeDefine( define ); + } //end else + break; + } //end if + lastdefine = define; + } //end for +#endif //DEFINEHASHING + return qtrue; +} //end of the function PC_Directive_undef +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_Directive_define( source_t *source ) { + token_t token, *t, *last; + define_t *define; + + if ( source->skip > 0 ) { + return qtrue; + } + // + if ( !PC_ReadLine( source, &token ) ) { + SourceError( source, "#define without name" ); + return qfalse; + } //end if + if ( token.type != TT_NAME ) { + PC_UnreadSourceToken( source, &token ); + SourceError( source, "expected name after #define, found %s", token.string ); + return qfalse; + } //end if + //check if the define already exists +#if DEFINEHASHING + define = PC_FindHashedDefine( source->definehash, token.string ); +#else + define = PC_FindDefine( source->defines, token.string ); +#endif //DEFINEHASHING + if ( define ) { + if ( define->flags & DEFINE_FIXED ) { + SourceError( source, "can't redefine %s", token.string ); + return qfalse; + } //end if + SourceWarning( source, "redefinition of %s", token.string ); + //unread the define name before executing the #undef directive + PC_UnreadSourceToken( source, &token ); + if ( !PC_Directive_undef( source ) ) { + return qfalse; + } + //if the define was not removed (define->flags & DEFINE_FIXED) +#if DEFINEHASHING + define = PC_FindHashedDefine( source->definehash, token.string ); +#else + define = PC_FindDefine( source->defines, token.string ); +#endif //DEFINEHASHING + } //end if + //allocate define + define = (define_t *) GetMemory( sizeof( define_t ) + strlen( token.string ) + 1 ); + memset( define, 0, sizeof( define_t ) ); + define->name = (char *) define + sizeof( define_t ); + strcpy( define->name, token.string ); + //add the define to the source +#if DEFINEHASHING + PC_AddDefineToHash( define, source->definehash ); +#else //DEFINEHASHING + define->next = source->defines; + source->defines = define; +#endif //DEFINEHASHING + //if nothing is defined, just return + if ( !PC_ReadLine( source, &token ) ) { + return qtrue; + } + //if it is a define with parameters + if ( !PC_WhiteSpaceBeforeToken( &token ) && !strcmp( token.string, "(" ) ) { + //read the define parameters + last = NULL; + if ( !PC_CheckTokenString( source, ")" ) ) { + while ( 1 ) + { + if ( !PC_ReadLine( source, &token ) ) { + SourceError( source, "expected define parameter" ); + return qfalse; + } //end if + //if it isn't a name + if ( token.type != TT_NAME ) { + SourceError( source, "invalid define parameter" ); + return qfalse; + } //end if + // + if ( PC_FindDefineParm( define, token.string ) >= 0 ) { + SourceError( source, "two the same define parameters" ); + return qfalse; + } //end if + //add the define parm + t = PC_CopyToken( &token ); + PC_ClearTokenWhiteSpace( t ); + t->next = NULL; + if ( last ) { + last->next = t; + } else { define->parms = t;} + last = t; + define->numparms++; + //read next token + if ( !PC_ReadLine( source, &token ) ) { + SourceError( source, "define parameters not terminated" ); + return qfalse; + } //end if + // + if ( !strcmp( token.string, ")" ) ) { + break; + } + //then it must be a comma + if ( strcmp( token.string, "," ) ) { + SourceError( source, "define not terminated" ); + return qfalse; + } //end if + } //end while + } //end if + if ( !PC_ReadLine( source, &token ) ) { + return qtrue; + } + } //end if + //read the defined stuff + last = NULL; + do + { + t = PC_CopyToken( &token ); + if ( t->type == TT_NAME && !strcmp( t->string, define->name ) ) { + SourceError( source, "recursive define (removed recursion)" ); + continue; + } //end if + PC_ClearTokenWhiteSpace( t ); + t->next = NULL; + if ( last ) { + last->next = t; + } else { define->tokens = t;} + last = t; + } while ( PC_ReadLine( source, &token ) ); + // + if ( last ) { + //check for merge operators at the beginning or end + if ( !strcmp( define->tokens->string, "##" ) || + !strcmp( last->string, "##" ) ) { + SourceError( source, "define with misplaced ##" ); + return qfalse; + } //end if + } //end if + return qtrue; +} //end of the function PC_Directive_define +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +define_t *PC_DefineFromString( char *string ) { + script_t *script; + source_t src; + token_t *t; + int res, i; + define_t *def; + + PC_InitTokenHeap(); + + script = LoadScriptMemory( string, strlen( string ), "*extern" ); + //create a new source + memset( &src, 0, sizeof( source_t ) ); + strncpy( src.filename, "*extern", _MAX_PATH ); + src.scriptstack = script; +#if DEFINEHASHING + src.definehash = GetClearedMemory( DEFINEHASHSIZE * sizeof( define_t * ) ); +#endif //DEFINEHASHING + //create a define from the source + res = PC_Directive_define( &src ); + //free any tokens if left + for ( t = src.tokens; t; t = src.tokens ) + { + src.tokens = src.tokens->next; + PC_FreeToken( t ); + } //end for +#ifdef DEFINEHASHING + def = NULL; + for ( i = 0; i < DEFINEHASHSIZE; i++ ) + { + if ( src.definehash[i] ) { + def = src.definehash[i]; + break; + } //end if + } //end for +#else + def = src.defines; +#endif //DEFINEHASHING + // +#if DEFINEHASHING + FreeMemory( src.definehash ); +#endif //DEFINEHASHING + // + FreeScript( script ); + //if the define was created succesfully + if ( res > 0 ) { + return def; + } + //free the define if created + if ( src.defines ) { + PC_FreeDefine( def ); + } + // + return NULL; +} //end of the function PC_DefineFromString +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_AddDefine( source_t *source, char *string ) { + define_t *define; + + define = PC_DefineFromString( string ); + if ( !define ) { + return qfalse; + } +#if DEFINEHASHING + PC_AddDefineToHash( define, source->definehash ); +#else //DEFINEHASHING + define->next = source->defines; + source->defines = define; +#endif //DEFINEHASHING + return qtrue; +} //end of the function PC_AddDefine +//============================================================================ +// add a globals define that will be added to all opened sources +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_AddGlobalDefine( char *string ) { + define_t *define; + + define = PC_DefineFromString( string ); + if ( !define ) { + return qfalse; + } + define->next = globaldefines; + globaldefines = define; + return qtrue; +} //end of the function PC_AddGlobalDefine +//============================================================================ +// remove the given global define +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_RemoveGlobalDefine( char *name ) { + define_t *define; + + define = PC_FindDefine( globaldefines, name ); + if ( define ) { + PC_FreeDefine( define ); + return qtrue; + } //end if + return qfalse; +} //end of the function PC_RemoveGlobalDefine +//============================================================================ +// remove all globals defines +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void PC_RemoveAllGlobalDefines( void ) { + define_t *define; + + for ( define = globaldefines; define; define = globaldefines ) + { + globaldefines = globaldefines->next; + PC_FreeDefine( define ); + } //end for +} //end of the function PC_RemoveAllGlobalDefines +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +define_t *PC_CopyDefine( source_t *source, define_t *define ) { + define_t *newdefine; + token_t *token, *newtoken, *lasttoken; + + newdefine = (define_t *) GetMemory( sizeof( define_t ) + strlen( define->name ) + 1 ); + //copy the define name + newdefine->name = (char *) newdefine + sizeof( define_t ); + strcpy( newdefine->name, define->name ); + newdefine->flags = define->flags; + newdefine->builtin = define->builtin; + newdefine->numparms = define->numparms; + //the define is not linked + newdefine->next = NULL; + newdefine->hashnext = NULL; + //copy the define tokens + newdefine->tokens = NULL; + for ( lasttoken = NULL, token = define->tokens; token; token = token->next ) + { + newtoken = PC_CopyToken( token ); + newtoken->next = NULL; + if ( lasttoken ) { + lasttoken->next = newtoken; + } else { newdefine->tokens = newtoken;} + lasttoken = newtoken; + } //end for + //copy the define parameters + newdefine->parms = NULL; + for ( lasttoken = NULL, token = define->parms; token; token = token->next ) + { + newtoken = PC_CopyToken( token ); + newtoken->next = NULL; + if ( lasttoken ) { + lasttoken->next = newtoken; + } else { newdefine->parms = newtoken;} + lasttoken = newtoken; + } //end for + return newdefine; +} //end of the function PC_CopyDefine +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void PC_AddGlobalDefinesToSource( source_t *source ) { + define_t *define, *newdefine; + + for ( define = globaldefines; define; define = define->next ) + { + newdefine = PC_CopyDefine( source, define ); +#if DEFINEHASHING + PC_AddDefineToHash( newdefine, source->definehash ); +#else //DEFINEHASHING + newdefine->next = source->defines; + source->defines = newdefine; +#endif //DEFINEHASHING + } //end for +} //end of the function PC_AddGlobalDefinesToSource +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_Directive_if_def( source_t *source, int type ) { + token_t token; + define_t *d; + int skip; + + if ( !PC_ReadLine( source, &token ) ) { + SourceError( source, "#ifdef without name" ); + return qfalse; + } //end if + if ( token.type != TT_NAME ) { + PC_UnreadSourceToken( source, &token ); + SourceError( source, "expected name after #ifdef, found %s", token.string ); + return qfalse; + } //end if +#if DEFINEHASHING + d = PC_FindHashedDefine( source->definehash, token.string ); +#else + d = PC_FindDefine( source->defines, token.string ); +#endif //DEFINEHASHING + skip = ( type == INDENT_IFDEF ) == ( d == NULL ); + PC_PushIndent( source, type, skip ); + return qtrue; +} //end of the function PC_Directiveif_def +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_Directive_ifdef( source_t *source ) { + return PC_Directive_if_def( source, INDENT_IFDEF ); +} //end of the function PC_Directive_ifdef +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_Directive_ifndef( source_t *source ) { + return PC_Directive_if_def( source, INDENT_IFNDEF ); +} //end of the function PC_Directive_ifndef +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_Directive_else( source_t *source ) { + int type, skip; + + PC_PopIndent( source, &type, &skip ); + if ( !type ) { + SourceError( source, "misplaced #else" ); + return qfalse; + } //end if + if ( type == INDENT_ELSE ) { + SourceError( source, "#else after #else" ); + return qfalse; + } //end if + PC_PushIndent( source, INDENT_ELSE, !skip ); + return qtrue; +} //end of the function PC_Directive_else +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_Directive_endif( source_t *source ) { + int type, skip; + + PC_PopIndent( source, &type, &skip ); + if ( !type ) { + SourceError( source, "misplaced #endif" ); + return qfalse; + } //end if + return qtrue; +} //end of the function PC_Directive_endif +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +typedef struct operator_s +{ + int operator; + int priority; + int parentheses; + struct operator_s *prev, *next; +} operator_t; + +typedef struct value_s +{ + signed long int intvalue; + double floatvalue; + int parentheses; + struct value_s *prev, *next; +} value_t; + +int PC_OperatorPriority( int op ) { + switch ( op ) + { + case P_MUL: return 15; + case P_DIV: return 15; + case P_MOD: return 15; + case P_ADD: return 14; + case P_SUB: return 14; + + case P_LOGIC_AND: return 7; + case P_LOGIC_OR: return 6; + case P_LOGIC_GEQ: return 12; + case P_LOGIC_LEQ: return 12; + case P_LOGIC_EQ: return 11; + case P_LOGIC_UNEQ: return 11; + + case P_LOGIC_NOT: return 16; + case P_LOGIC_GREATER: return 12; + case P_LOGIC_LESS: return 12; + + case P_RSHIFT: return 13; + case P_LSHIFT: return 13; + + case P_BIN_AND: return 10; + case P_BIN_OR: return 8; + case P_BIN_XOR: return 9; + case P_BIN_NOT: return 16; + + case P_COLON: return 5; + case P_QUESTIONMARK: return 5; + } //end switch + return qfalse; +} //end of the function PC_OperatorPriority + +//#define AllocValue() GetClearedMemory(sizeof(value_t)); +//#define FreeValue(val) FreeMemory(val) +//#define AllocOperator(op) op = (operator_t *) GetClearedMemory(sizeof(operator_t)); +//#define FreeOperator(op) FreeMemory(op); + +#define MAX_VALUES 64 +#define MAX_OPERATORS 64 +#define AllocValue( val ) \ + if ( numvalues >= MAX_VALUES ) { \ + SourceError( source, "out value space\n" ); \ + error = 1; \ + break; \ + } \ + else { \ + val = &value_heap[numvalues++];} +#define FreeValue( val ) +// +#define AllocOperator( op ) \ + if ( numoperators >= MAX_OPERATORS ) { \ + SourceError( source, "out operator space\n" ); \ + error = 1; \ + break; \ + } \ + else { \ + op = &operator_heap[numoperators++];} +#define FreeOperator( op ) + +int PC_EvaluateTokens( source_t *source, token_t *tokens, signed long int *intvalue, + double *floatvalue, int integer ) { + operator_t *o, *firstoperator, *lastoperator; + value_t *v, *firstvalue, *lastvalue, *v1, *v2; + token_t *t; + int brace = 0; + int parentheses = 0; + int error = 0; + int lastwasvalue = 0; + int negativevalue = 0; + int questmarkintvalue = 0; + double questmarkfloatvalue = 0; + int gotquestmarkvalue = qfalse; + int lastoperatortype = 0; + // + operator_t operator_heap[MAX_OPERATORS]; + int numoperators = 0; + value_t value_heap[MAX_VALUES]; + int numvalues = 0; + + firstoperator = lastoperator = NULL; + firstvalue = lastvalue = NULL; + if ( intvalue ) { + *intvalue = 0; + } + if ( floatvalue ) { + *floatvalue = 0; + } + for ( t = tokens; t; t = t->next ) + { + switch ( t->type ) + { + case TT_NAME: + { + if ( lastwasvalue || negativevalue ) { + SourceError( source, "syntax error in #if/#elif" ); + error = 1; + break; + } //end if + if ( strcmp( t->string, "defined" ) ) { + SourceError( source, "undefined name %s in #if/#elif", t->string ); + error = 1; + break; + } //end if + t = t->next; + if ( !strcmp( t->string, "(" ) ) { + brace = qtrue; + t = t->next; + } //end if + if ( !t || t->type != TT_NAME ) { + SourceError( source, "defined without name in #if/#elif" ); + error = 1; + break; + } //end if + //v = (value_t *) GetClearedMemory(sizeof(value_t)); + AllocValue( v ); +#if DEFINEHASHING + if ( PC_FindHashedDefine( source->definehash, t->string ) ) +#else + if ( PC_FindDefine( source->defines, t->string ) ) +#endif //DEFINEHASHING + { + v->intvalue = 1; + v->floatvalue = 1; + } //end if + else + { + v->intvalue = 0; + v->floatvalue = 0; + } //end else + v->parentheses = parentheses; + v->next = NULL; + v->prev = lastvalue; + if ( lastvalue ) { + lastvalue->next = v; + } else { firstvalue = v;} + lastvalue = v; + if ( brace ) { + t = t->next; + if ( !t || strcmp( t->string, ")" ) ) { + SourceError( source, "defined without ) in #if/#elif" ); + error = 1; + break; + } //end if + } //end if + brace = qfalse; + // defined() creates a value + lastwasvalue = 1; + break; + } //end case + case TT_NUMBER: + { + if ( lastwasvalue ) { + SourceError( source, "syntax error in #if/#elif" ); + error = 1; + break; + } //end if + //v = (value_t *) GetClearedMemory(sizeof(value_t)); + AllocValue( v ); + if ( negativevalue ) { + v->intvalue = -(signed int) t->intvalue; + v->floatvalue = -t->floatvalue; + } //end if + else + { + v->intvalue = t->intvalue; + v->floatvalue = t->floatvalue; + } //end else + v->parentheses = parentheses; + v->next = NULL; + v->prev = lastvalue; + if ( lastvalue ) { + lastvalue->next = v; + } else { firstvalue = v;} + lastvalue = v; + //last token was a value + lastwasvalue = 1; + // + negativevalue = 0; + break; + } //end case + case TT_PUNCTUATION: + { + if ( negativevalue ) { + SourceError( source, "misplaced minus sign in #if/#elif" ); + error = 1; + break; + } //end if + if ( t->subtype == P_PARENTHESESOPEN ) { + parentheses++; + break; + } //end if + else if ( t->subtype == P_PARENTHESESCLOSE ) { + parentheses--; + if ( parentheses < 0 ) { + SourceError( source, "too many ) in #if/#elsif" ); + error = 1; + } //end if + break; + } //end else if + //check for invalid operators on floating point values + if ( !integer ) { + if ( t->subtype == P_BIN_NOT || t->subtype == P_MOD || + t->subtype == P_RSHIFT || t->subtype == P_LSHIFT || + t->subtype == P_BIN_AND || t->subtype == P_BIN_OR || + t->subtype == P_BIN_XOR ) { + SourceError( source, "illigal operator %s on floating point operands\n", t->string ); + error = 1; + break; + } //end if + } //end if + switch ( t->subtype ) + { + case P_LOGIC_NOT: + case P_BIN_NOT: + { + if ( lastwasvalue ) { + SourceError( source, "! or ~ after value in #if/#elif" ); + error = 1; + break; + } //end if + break; + } //end case + case P_SUB: + { + if ( !lastwasvalue ) { + negativevalue = 1; + break; + } //end if + } //end case + + case P_MUL: + case P_DIV: + case P_MOD: + case P_ADD: + + case P_LOGIC_AND: + case P_LOGIC_OR: + case P_LOGIC_GEQ: + case P_LOGIC_LEQ: + case P_LOGIC_EQ: + case P_LOGIC_UNEQ: + + case P_LOGIC_GREATER: + case P_LOGIC_LESS: + + case P_RSHIFT: + case P_LSHIFT: + + case P_BIN_AND: + case P_BIN_OR: + case P_BIN_XOR: + + case P_COLON: + case P_QUESTIONMARK: + { + if ( !lastwasvalue ) { + SourceError( source, "operator %s after operator in #if/#elif", t->string ); + error = 1; + break; + } //end if + break; + } //end case + default: + { + SourceError( source, "invalid operator %s in #if/#elif", t->string ); + error = 1; + break; + } //end default + } //end switch + if ( !error && !negativevalue ) { + //o = (operator_t *) GetClearedMemory(sizeof(operator_t)); + AllocOperator( o ); + o->operator = t->subtype; + o->priority = PC_OperatorPriority( t->subtype ); + o->parentheses = parentheses; + o->next = NULL; + o->prev = lastoperator; + if ( lastoperator ) { + lastoperator->next = o; + } else { firstoperator = o;} + lastoperator = o; + lastwasvalue = 0; + } //end if + break; + } //end case + default: + { + SourceError( source, "unknown %s in #if/#elif", t->string ); + error = 1; + break; + } //end default + } //end switch + if ( error ) { + break; + } + } //end for + if ( !error ) { + if ( !lastwasvalue ) { + SourceError( source, "trailing operator in #if/#elif" ); + error = 1; + } //end if + else if ( parentheses ) { + SourceError( source, "too many ( in #if/#elif" ); + error = 1; + } //end else if + } //end if + // + gotquestmarkvalue = qfalse; + questmarkintvalue = 0; + questmarkfloatvalue = 0; + //while there are operators + while ( !error && firstoperator ) + { + v = firstvalue; + for ( o = firstoperator; o->next; o = o->next ) + { + //if the current operator is nested deeper in parentheses + //than the next operator + if ( o->parentheses > o->next->parentheses ) { + break; + } + //if the current and next operator are nested equally deep in parentheses + if ( o->parentheses == o->next->parentheses ) { + //if the priority of the current operator is equal or higher + //than the priority of the next operator + if ( o->priority >= o->next->priority ) { + break; + } + } //end if + //if the arity of the operator isn't equal to 1 + if ( o->operator != P_LOGIC_NOT + && o->operator != P_BIN_NOT ) { + v = v->next; + } + //if there's no value or no next value + if ( !v ) { + SourceError( source, "mising values in #if/#elif" ); + error = 1; + break; + } //end if + } //end for + if ( error ) { + break; + } + v1 = v; + v2 = v->next; +#ifdef DEBUG_EVAL + if ( integer ) { + Log_Write( "operator %s, value1 = %d", PunctuationFromNum( source->scriptstack, o->operator ), v1->intvalue ); + if ( v2 ) { + Log_Write( "value2 = %d", v2->intvalue ); + } + } //end if + else + { + Log_Write( "operator %s, value1 = %f", PunctuationFromNum( source->scriptstack, o->operator ), v1->floatvalue ); + if ( v2 ) { + Log_Write( "value2 = %f", v2->floatvalue ); + } + } //end else +#endif //DEBUG_EVAL + switch ( o->operator ) + { + case P_LOGIC_NOT: v1->intvalue = !v1->intvalue; + v1->floatvalue = !v1->floatvalue; break; + case P_BIN_NOT: v1->intvalue = ~v1->intvalue; + break; + case P_MUL: v1->intvalue *= v2->intvalue; + v1->floatvalue *= v2->floatvalue; break; + case P_DIV: v1->intvalue /= v2->intvalue; + v1->floatvalue /= v2->floatvalue; break; + case P_MOD: v1->intvalue %= v2->intvalue; + break; + case P_ADD: v1->intvalue += v2->intvalue; + v1->floatvalue += v2->floatvalue; break; + case P_SUB: v1->intvalue -= v2->intvalue; + v1->floatvalue -= v2->floatvalue; break; + case P_LOGIC_AND: v1->intvalue = v1->intvalue && v2->intvalue; + v1->floatvalue = v1->floatvalue && v2->floatvalue; break; + case P_LOGIC_OR: v1->intvalue = v1->intvalue || v2->intvalue; + v1->floatvalue = v1->floatvalue || v2->floatvalue; break; + case P_LOGIC_GEQ: v1->intvalue = v1->intvalue >= v2->intvalue; + v1->floatvalue = v1->floatvalue >= v2->floatvalue; break; + case P_LOGIC_LEQ: v1->intvalue = v1->intvalue <= v2->intvalue; + v1->floatvalue = v1->floatvalue <= v2->floatvalue; break; + case P_LOGIC_EQ: v1->intvalue = v1->intvalue == v2->intvalue; + v1->floatvalue = v1->floatvalue == v2->floatvalue; break; + case P_LOGIC_UNEQ: v1->intvalue = v1->intvalue != v2->intvalue; + v1->floatvalue = v1->floatvalue != v2->floatvalue; break; + case P_LOGIC_GREATER: v1->intvalue = v1->intvalue > v2->intvalue; + v1->floatvalue = v1->floatvalue > v2->floatvalue; break; + case P_LOGIC_LESS: v1->intvalue = v1->intvalue < v2->intvalue; + v1->floatvalue = v1->floatvalue < v2->floatvalue; break; + case P_RSHIFT: v1->intvalue >>= v2->intvalue; + break; + case P_LSHIFT: v1->intvalue <<= v2->intvalue; + break; + case P_BIN_AND: v1->intvalue &= v2->intvalue; + break; + case P_BIN_OR: v1->intvalue |= v2->intvalue; + break; + case P_BIN_XOR: v1->intvalue ^= v2->intvalue; + break; + case P_COLON: + { + if ( !gotquestmarkvalue ) { + SourceError( source, ": without ? in #if/#elif" ); + error = 1; + break; + } //end if + if ( integer ) { + if ( !questmarkintvalue ) { + v1->intvalue = v2->intvalue; + } + } //end if + else + { + if ( !questmarkfloatvalue ) { + v1->floatvalue = v2->floatvalue; + } + } //end else + gotquestmarkvalue = qfalse; + break; + } //end case + case P_QUESTIONMARK: + { + if ( gotquestmarkvalue ) { + SourceError( source, "? after ? in #if/#elif" ); + error = 1; + break; + } //end if + questmarkintvalue = v1->intvalue; + questmarkfloatvalue = v1->floatvalue; + gotquestmarkvalue = qtrue; + break; + } //end if + } //end switch +#ifdef DEBUG_EVAL + if ( integer ) { + Log_Write( "result value = %d", v1->intvalue ); + } else { Log_Write( "result value = %f", v1->floatvalue );} +#endif //DEBUG_EVAL + if ( error ) { + break; + } + lastoperatortype = o->operator; + //if not an operator with arity 1 + if ( o->operator != P_LOGIC_NOT + && o->operator != P_BIN_NOT ) { + //remove the second value if not question mark operator + if ( o->operator != P_QUESTIONMARK ) { + v = v->next; + } + // + if ( v->prev ) { + v->prev->next = v->next; + } else { firstvalue = v->next;} + if ( v->next ) { + v->next->prev = v->prev; + } else { lastvalue = v->prev;} + //FreeMemory(v); + FreeValue( v ); + } //end if + //remove the operator + if ( o->prev ) { + o->prev->next = o->next; + } else { firstoperator = o->next;} + if ( o->next ) { + o->next->prev = o->prev; + } else { lastoperator = o->prev;} + //FreeMemory(o); + FreeOperator( o ); + } //end while + if ( firstvalue ) { + if ( intvalue ) { + *intvalue = firstvalue->intvalue; + } + if ( floatvalue ) { + *floatvalue = firstvalue->floatvalue; + } + } //end if + for ( o = firstoperator; o; o = lastoperator ) + { + lastoperator = o->next; + //FreeMemory(o); + FreeOperator( o ); + } //end for + for ( v = firstvalue; v; v = lastvalue ) + { + lastvalue = v->next; + //FreeMemory(v); + FreeValue( v ); + } //end for + if ( !error ) { + return qtrue; + } + if ( intvalue ) { + *intvalue = 0; + } + if ( floatvalue ) { + *floatvalue = 0; + } + return qfalse; +} //end of the function PC_EvaluateTokens +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_Evaluate( source_t *source, signed long int *intvalue, + double *floatvalue, int integer ) { + token_t token, *firsttoken, *lasttoken; + token_t *t, *nexttoken; + define_t *define; + int defined = qfalse; + + if ( intvalue ) { + *intvalue = 0; + } + if ( floatvalue ) { + *floatvalue = 0; + } + // + if ( !PC_ReadLine( source, &token ) ) { + SourceError( source, "no value after #if/#elif" ); + return qfalse; + } //end if + firsttoken = NULL; + lasttoken = NULL; + do + { + //if the token is a name + if ( token.type == TT_NAME ) { + if ( defined ) { + defined = qfalse; + t = PC_CopyToken( &token ); + t->next = NULL; + if ( lasttoken ) { + lasttoken->next = t; + } else { firsttoken = t;} + lasttoken = t; + } //end if + else if ( !strcmp( token.string, "defined" ) ) { + defined = qtrue; + t = PC_CopyToken( &token ); + t->next = NULL; + if ( lasttoken ) { + lasttoken->next = t; + } else { firsttoken = t;} + lasttoken = t; + } //end if + else + { + //then it must be a define +#if DEFINEHASHING + define = PC_FindHashedDefine( source->definehash, token.string ); +#else + define = PC_FindDefine( source->defines, token.string ); +#endif //DEFINEHASHING + if ( !define ) { + SourceError( source, "can't evaluate %s, not defined", token.string ); + return qfalse; + } //end if + if ( !PC_ExpandDefineIntoSource( source, define ) ) { + return qfalse; + } + } //end else + } //end if + //if the token is a number or a punctuation + else if ( token.type == TT_NUMBER || token.type == TT_PUNCTUATION ) { + t = PC_CopyToken( &token ); + t->next = NULL; + if ( lasttoken ) { + lasttoken->next = t; + } else { firsttoken = t;} + lasttoken = t; + } //end else + else //can't evaluate the token + { + SourceError( source, "can't evaluate %s", token.string ); + return qfalse; + } //end else + } while ( PC_ReadLine( source, &token ) ); + // + if ( !PC_EvaluateTokens( source, firsttoken, intvalue, floatvalue, integer ) ) { + return qfalse; + } + // +#ifdef DEBUG_EVAL + Log_Write( "eval:" ); +#endif //DEBUG_EVAL + for ( t = firsttoken; t; t = nexttoken ) + { +#ifdef DEBUG_EVAL + Log_Write( " %s", t->string ); +#endif //DEBUG_EVAL + nexttoken = t->next; + PC_FreeToken( t ); + } //end for +#ifdef DEBUG_EVAL + if ( integer ) { + Log_Write( "eval result: %d", *intvalue ); + } else { Log_Write( "eval result: %f", *floatvalue );} +#endif //DEBUG_EVAL + // + return qtrue; +} //end of the function PC_Evaluate +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_DollarEvaluate( source_t *source, signed long int *intvalue, + double *floatvalue, int integer ) { + int indent, defined = qfalse; + token_t token, *firsttoken, *lasttoken; + token_t *t, *nexttoken; + define_t *define; + + if ( intvalue ) { + *intvalue = 0; + } + if ( floatvalue ) { + *floatvalue = 0; + } + // + if ( !PC_ReadSourceToken( source, &token ) ) { + SourceError( source, "no leading ( after $evalint/$evalfloat" ); + return qfalse; + } //end if + if ( !PC_ReadSourceToken( source, &token ) ) { + SourceError( source, "nothing to evaluate" ); + return qfalse; + } //end if + indent = 1; + firsttoken = NULL; + lasttoken = NULL; + do + { + //if the token is a name + if ( token.type == TT_NAME ) { + if ( defined ) { + defined = qfalse; + t = PC_CopyToken( &token ); + t->next = NULL; + if ( lasttoken ) { + lasttoken->next = t; + } else { firsttoken = t;} + lasttoken = t; + } //end if + else if ( !strcmp( token.string, "defined" ) ) { + defined = qtrue; + t = PC_CopyToken( &token ); + t->next = NULL; + if ( lasttoken ) { + lasttoken->next = t; + } else { firsttoken = t;} + lasttoken = t; + } //end if + else + { + //then it must be a define +#if DEFINEHASHING + define = PC_FindHashedDefine( source->definehash, token.string ); +#else + define = PC_FindDefine( source->defines, token.string ); +#endif //DEFINEHASHING + if ( !define ) { + SourceError( source, "can't evaluate %s, not defined", token.string ); + return qfalse; + } //end if + if ( !PC_ExpandDefineIntoSource( source, define ) ) { + return qfalse; + } + } //end else + } //end if + //if the token is a number or a punctuation + else if ( token.type == TT_NUMBER || token.type == TT_PUNCTUATION ) { + if ( *token.string == '(' ) { + indent++; + } else if ( *token.string == ')' ) { + indent--; + } + if ( indent <= 0 ) { + break; + } + t = PC_CopyToken( &token ); + t->next = NULL; + if ( lasttoken ) { + lasttoken->next = t; + } else { firsttoken = t;} + lasttoken = t; + } //end else + else //can't evaluate the token + { + SourceError( source, "can't evaluate %s", token.string ); + return qfalse; + } //end else + } while ( PC_ReadSourceToken( source, &token ) ); + // + if ( !PC_EvaluateTokens( source, firsttoken, intvalue, floatvalue, integer ) ) { + return qfalse; + } + // +#ifdef DEBUG_EVAL + Log_Write( "$eval:" ); +#endif //DEBUG_EVAL + for ( t = firsttoken; t; t = nexttoken ) + { +#ifdef DEBUG_EVAL + Log_Write( " %s", t->string ); +#endif //DEBUG_EVAL + nexttoken = t->next; + PC_FreeToken( t ); + } //end for +#ifdef DEBUG_EVAL + if ( integer ) { + Log_Write( "$eval result: %d", *intvalue ); + } else { Log_Write( "$eval result: %f", *floatvalue );} +#endif //DEBUG_EVAL + // + return qtrue; +} //end of the function PC_DollarEvaluate +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_Directive_elif( source_t *source ) { + signed long int value; + int type, skip; + + PC_PopIndent( source, &type, &skip ); + if ( !type || type == INDENT_ELSE ) { + SourceError( source, "misplaced #elif" ); + return qfalse; + } //end if + if ( !PC_Evaluate( source, &value, NULL, qtrue ) ) { + return qfalse; + } + skip = ( value == 0 ); + PC_PushIndent( source, INDENT_ELIF, skip ); + return qtrue; +} //end of the function PC_Directive_elif +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_Directive_if( source_t *source ) { + signed long int value; + int skip; + + if ( !PC_Evaluate( source, &value, NULL, qtrue ) ) { + return qfalse; + } + skip = ( value == 0 ); + PC_PushIndent( source, INDENT_IF, skip ); + return qtrue; +} //end of the function PC_Directive +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_Directive_line( source_t *source ) { + SourceError( source, "#line directive not supported" ); + return qfalse; +} //end of the function PC_Directive_line +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_Directive_error( source_t *source ) { + token_t token; + + strcpy( token.string, "" ); + PC_ReadSourceToken( source, &token ); + SourceError( source, "#error directive: %s", token.string ); + return qfalse; +} //end of the function PC_Directive_error +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_Directive_pragma( source_t *source ) { + token_t token; + + SourceWarning( source, "#pragma directive not supported" ); + while ( PC_ReadLine( source, &token ) ) ; + return qtrue; +} //end of the function PC_Directive_pragma +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void UnreadSignToken( source_t *source ) { + token_t token; + + token.line = source->scriptstack->line; + token.whitespace_p = source->scriptstack->script_p; + token.endwhitespace_p = source->scriptstack->script_p; + token.linescrossed = 0; + strcpy( token.string, "-" ); + token.type = TT_PUNCTUATION; + token.subtype = P_SUB; + PC_UnreadSourceToken( source, &token ); +} //end of the function UnreadSignToken +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_Directive_eval( source_t *source ) { + signed long int value; + token_t token; + + if ( !PC_Evaluate( source, &value, NULL, qtrue ) ) { + return qfalse; + } + // + token.line = source->scriptstack->line; + token.whitespace_p = source->scriptstack->script_p; + token.endwhitespace_p = source->scriptstack->script_p; + token.linescrossed = 0; + sprintf( token.string, "%d", abs( value ) ); + token.type = TT_NUMBER; + token.subtype = TT_INTEGER | TT_LONG | TT_DECIMAL; + PC_UnreadSourceToken( source, &token ); + if ( value < 0 ) { + UnreadSignToken( source ); + } + return qtrue; +} //end of the function PC_Directive_eval +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_Directive_evalfloat( source_t *source ) { + double value; + token_t token; + + if ( !PC_Evaluate( source, NULL, &value, qfalse ) ) { + return qfalse; + } + token.line = source->scriptstack->line; + token.whitespace_p = source->scriptstack->script_p; + token.endwhitespace_p = source->scriptstack->script_p; + token.linescrossed = 0; + sprintf( token.string, "%1.2f", fabs( value ) ); + token.type = TT_NUMBER; + token.subtype = TT_FLOAT | TT_LONG | TT_DECIMAL; + PC_UnreadSourceToken( source, &token ); + if ( value < 0 ) { + UnreadSignToken( source ); + } + return qtrue; +} //end of the function PC_Directive_evalfloat +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +directive_t directives[20] = +{ + {"if", PC_Directive_if}, + {"ifdef", PC_Directive_ifdef}, + {"ifndef", PC_Directive_ifndef}, + {"elif", PC_Directive_elif}, + {"else", PC_Directive_else}, + {"endif", PC_Directive_endif}, + {"include", PC_Directive_include}, + {"define", PC_Directive_define}, + {"undef", PC_Directive_undef}, + {"line", PC_Directive_line}, + {"error", PC_Directive_error}, + {"pragma", PC_Directive_pragma}, + {"eval", PC_Directive_eval}, + {"evalfloat", PC_Directive_evalfloat}, + {NULL, NULL} +}; + +int PC_ReadDirective( source_t *source ) { + token_t token; + int i; + + //read the directive name + if ( !PC_ReadSourceToken( source, &token ) ) { + SourceError( source, "found # without name" ); + return qfalse; + } //end if + //directive name must be on the same line + if ( token.linescrossed > 0 ) { + PC_UnreadSourceToken( source, &token ); + SourceError( source, "found # at end of line" ); + return qfalse; + } //end if + //if if is a name + if ( token.type == TT_NAME ) { + //find the precompiler directive + for ( i = 0; directives[i].name; i++ ) + { + if ( !strcmp( directives[i].name, token.string ) ) { + return directives[i].func( source ); + } //end if + } //end for + } //end if + SourceError( source, "unknown precompiler directive %s", token.string ); + return qfalse; +} //end of the function PC_ReadDirective +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_DollarDirective_evalint( source_t *source ) { + signed long int value; + token_t token; + + if ( !PC_DollarEvaluate( source, &value, NULL, qtrue ) ) { + return qfalse; + } + // + token.line = source->scriptstack->line; + token.whitespace_p = source->scriptstack->script_p; + token.endwhitespace_p = source->scriptstack->script_p; + token.linescrossed = 0; + sprintf( token.string, "%d", abs( value ) ); + token.type = TT_NUMBER; + token.subtype = TT_INTEGER | TT_LONG | TT_DECIMAL; +#ifdef NUMBERVALUE + token.intvalue = value; + token.floatvalue = value; +#endif //NUMBERVALUE + PC_UnreadSourceToken( source, &token ); + if ( value < 0 ) { + UnreadSignToken( source ); + } + return qtrue; +} //end of the function PC_DollarDirective_evalint +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_DollarDirective_evalfloat( source_t *source ) { + double value; + token_t token; + + if ( !PC_DollarEvaluate( source, NULL, &value, qfalse ) ) { + return qfalse; + } + token.line = source->scriptstack->line; + token.whitespace_p = source->scriptstack->script_p; + token.endwhitespace_p = source->scriptstack->script_p; + token.linescrossed = 0; + sprintf( token.string, "%1.2f", fabs( value ) ); + token.type = TT_NUMBER; + token.subtype = TT_FLOAT | TT_LONG | TT_DECIMAL; +#ifdef NUMBERVALUE + token.intvalue = (unsigned long) value; + token.floatvalue = value; +#endif //NUMBERVALUE + PC_UnreadSourceToken( source, &token ); + if ( value < 0 ) { + UnreadSignToken( source ); + } + return qtrue; +} //end of the function PC_DollarDirective_evalfloat +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +directive_t dollardirectives[20] = +{ + {"evalint", PC_DollarDirective_evalint}, + {"evalfloat", PC_DollarDirective_evalfloat}, + {NULL, NULL} +}; + +int PC_ReadDollarDirective( source_t *source ) { + token_t token; + int i; + + //read the directive name + if ( !PC_ReadSourceToken( source, &token ) ) { + SourceError( source, "found $ without name" ); + return qfalse; + } //end if + //directive name must be on the same line + if ( token.linescrossed > 0 ) { + PC_UnreadSourceToken( source, &token ); + SourceError( source, "found $ at end of line" ); + return qfalse; + } //end if + //if if is a name + if ( token.type == TT_NAME ) { + //find the precompiler directive + for ( i = 0; dollardirectives[i].name; i++ ) + { + if ( !strcmp( dollardirectives[i].name, token.string ) ) { + return dollardirectives[i].func( source ); + } //end if + } //end for + } //end if + PC_UnreadSourceToken( source, &token ); + SourceError( source, "unknown precompiler directive %s", token.string ); + return qfalse; +} //end of the function PC_ReadDirective + +#ifdef QUAKEC +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int BuiltinFunction( source_t *source ) { + token_t token; + + if ( !PC_ReadSourceToken( source, &token ) ) { + return qfalse; + } + if ( token.type == TT_NUMBER ) { + PC_UnreadSourceToken( source, &token ); + return qtrue; + } //end if + else + { + PC_UnreadSourceToken( source, &token ); + return qfalse; + } //end else +} //end of the function BuiltinFunction +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int QuakeCMacro( source_t *source ) { + int i; + token_t token; + + if ( !PC_ReadSourceToken( source, &token ) ) { + return qtrue; + } + if ( token.type != TT_NAME ) { + PC_UnreadSourceToken( source, &token ); + return qtrue; + } //end if + //find the precompiler directive + for ( i = 0; dollardirectives[i].name; i++ ) + { + if ( !strcmp( dollardirectives[i].name, token.string ) ) { + PC_UnreadSourceToken( source, &token ); + return qfalse; + } //end if + } //end for + PC_UnreadSourceToken( source, &token ); + return qtrue; +} //end of the function QuakeCMacro +#endif //QUAKEC +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_ReadToken( source_t *source, token_t *token ) { + define_t *define; + + while ( 1 ) + { + if ( !PC_ReadSourceToken( source, token ) ) { + return qfalse; + } + + //check for precompiler directives + if ( token->type == TT_PUNCTUATION && *token->string == '#' ) { +#ifdef SCREWUP // Ridah, skip all # directives + while ( PC_ReadLine( source, token ) ) ; + continue; +#endif // SCREWUP + +#ifdef QUAKEC + if ( !BuiltinFunction( source ) ) +#endif //QUAKC + { + //read the precompiler directive + if ( !PC_ReadDirective( source ) ) { + return qfalse; + } + continue; + } //end if + } //end if + if ( token->type == TT_PUNCTUATION && *token->string == '$' ) { +#ifdef QUAKEC + if ( !QuakeCMacro( source ) ) +#endif //QUAKEC + { + //read the precompiler directive + if ( !PC_ReadDollarDirective( source ) ) { + return qfalse; + } + continue; + } //end if + } //end if + //if skipping source because of conditional compilation + if ( source->skip ) { + continue; + } + //if the token is a name + if ( token->type == TT_NAME ) { + //check if the name is a define macro +#if DEFINEHASHING + define = PC_FindHashedDefine( source->definehash, token->string ); +#else + define = PC_FindDefine( source->defines, token->string ); +#endif //DEFINEHASHING + //if it is a define macro + if ( define ) { + //expand the defined macro + if ( !PC_ExpandDefineIntoSource( source, define ) ) { + return qfalse; + } + continue; + } //end if + } //end if + //copy token for unreading + memcpy( &source->token, token, sizeof( token_t ) ); + //found a token + return qtrue; + } //end while +} //end of the function PC_ReadToken +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_ExpectTokenString( source_t *source, char *string ) { + token_t token; + + if ( !PC_ReadToken( source, &token ) ) { + SourceError( source, "couldn't find expected %s", string ); + return qfalse; + } //end if + + if ( strcmp( token.string, string ) ) { + SourceError( source, "expected %s, found %s", string, token.string ); + return qfalse; + } //end if + return qtrue; +} //end of the function PC_ExpectTokenString +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_ExpectTokenType( source_t *source, int type, int subtype, token_t *token ) { + char str[MAX_TOKEN]; + + if ( !PC_ReadToken( source, token ) ) { + SourceError( source, "couldn't read expected token" ); + return qfalse; + } //end if + + if ( token->type != type ) { + strcpy( str, "" ); + if ( type == TT_STRING ) { + strcpy( str, "string" ); + } + if ( type == TT_LITERAL ) { + strcpy( str, "literal" ); + } + if ( type == TT_NUMBER ) { + strcpy( str, "number" ); + } + if ( type == TT_NAME ) { + strcpy( str, "name" ); + } + if ( type == TT_PUNCTUATION ) { + strcpy( str, "punctuation" ); + } + SourceError( source, "expected a %s, found %s", str, token->string ); + return qfalse; + } //end if + if ( token->type == TT_NUMBER ) { + if ( ( token->subtype & subtype ) != subtype ) { + if ( subtype & TT_DECIMAL ) { + strcpy( str, "decimal" ); + } + if ( subtype & TT_HEX ) { + strcpy( str, "hex" ); + } + if ( subtype & TT_OCTAL ) { + strcpy( str, "octal" ); + } + if ( subtype & TT_BINARY ) { + strcpy( str, "binary" ); + } + if ( subtype & TT_LONG ) { + strcat( str, " long" ); + } + if ( subtype & TT_UNSIGNED ) { + strcat( str, " unsigned" ); + } + if ( subtype & TT_FLOAT ) { + strcat( str, " float" ); + } + if ( subtype & TT_INTEGER ) { + strcat( str, " integer" ); + } + SourceError( source, "expected %s, found %s", str, token->string ); + return qfalse; + } //end if + } //end if + else if ( token->type == TT_PUNCTUATION ) { + if ( token->subtype != subtype ) { + SourceError( source, "found %s", token->string ); + return qfalse; + } //end if + } //end else if + return qtrue; +} //end of the function PC_ExpectTokenType +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_ExpectAnyToken( source_t *source, token_t *token ) { + if ( !PC_ReadToken( source, token ) ) { + SourceError( source, "couldn't read expected token" ); + return qfalse; + } //end if + else + { + return qtrue; + } //end else +} //end of the function PC_ExpectAnyToken +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_CheckTokenString( source_t *source, char *string ) { + token_t tok; + + if ( !PC_ReadToken( source, &tok ) ) { + return qfalse; + } + //if the token is available + if ( !strcmp( tok.string, string ) ) { + return qtrue; + } + // + PC_UnreadSourceToken( source, &tok ); + return qfalse; +} //end of the function PC_CheckTokenString +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_CheckTokenType( source_t *source, int type, int subtype, token_t *token ) { + token_t tok; + + if ( !PC_ReadToken( source, &tok ) ) { + return qfalse; + } + //if the type matches + if ( tok.type == type && + ( tok.subtype & subtype ) == subtype ) { + memcpy( token, &tok, sizeof( token_t ) ); + return qtrue; + } //end if + // + PC_UnreadSourceToken( source, &tok ); + return qfalse; +} //end of the function PC_CheckTokenType +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PC_SkipUntilString( source_t *source, char *string ) { + token_t token; + + while ( PC_ReadToken( source, &token ) ) + { + if ( !strcmp( token.string, string ) ) { + return qtrue; + } + } //end while + return qfalse; +} //end of the function PC_SkipUntilString +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void PC_UnreadLastToken( source_t *source ) { + PC_UnreadSourceToken( source, &source->token ); +} //end of the function PC_UnreadLastToken +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void PC_UnreadToken( source_t *source, token_t *token ) { + PC_UnreadSourceToken( source, token ); +} //end of the function PC_UnreadToken +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void PC_SetIncludePath( source_t *source, char *path ) { + strncpy( source->includepath, path, _MAX_PATH ); + //add trailing path seperator + if ( source->includepath[strlen( source->includepath ) - 1] != '\\' && + source->includepath[strlen( source->includepath ) - 1] != '/' ) { + strcat( source->includepath, PATHSEPERATOR_STR ); + } //end if +} //end of the function PC_SetIncludePath +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void PC_SetPunctuations( source_t *source, punctuation_t *p ) { + source->punctuations = p; +} //end of the function PC_SetPunctuations +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +source_t *LoadSourceFile( char *filename ) { + source_t *source; + script_t *script; + + PC_InitTokenHeap(); + + script = LoadScriptFile( filename ); + if ( !script ) { + return NULL; + } + + script->next = NULL; + + source = (source_t *) GetMemory( sizeof( source_t ) ); + memset( source, 0, sizeof( source_t ) ); + + strncpy( source->filename, filename, _MAX_PATH ); + source->scriptstack = script; + source->tokens = NULL; + source->defines = NULL; + source->indentstack = NULL; + source->skip = 0; + +#if DEFINEHASHING + source->definehash = GetClearedMemory( DEFINEHASHSIZE * sizeof( define_t * ) ); +#endif //DEFINEHASHING + PC_AddGlobalDefinesToSource( source ); + return source; +} //end of the function LoadSourceFile +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +source_t *LoadSourceMemory( char *ptr, int length, char *name ) { + source_t *source; + script_t *script; + + PC_InitTokenHeap(); + + script = LoadScriptMemory( ptr, length, name ); + if ( !script ) { + return NULL; + } + script->next = NULL; + + source = (source_t *) GetMemory( sizeof( source_t ) ); + memset( source, 0, sizeof( source_t ) ); + + strncpy( source->filename, name, _MAX_PATH ); + source->scriptstack = script; + source->tokens = NULL; + source->defines = NULL; + source->indentstack = NULL; + source->skip = 0; + +#if DEFINEHASHING + source->definehash = GetClearedMemory( DEFINEHASHSIZE * sizeof( define_t * ) ); +#endif //DEFINEHASHING + PC_AddGlobalDefinesToSource( source ); + return source; +} //end of the function LoadSourceMemory +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void FreeSource( source_t *source ) { + script_t *script; + token_t *token; + define_t *define; + indent_t *indent; + int i; + + //PC_PrintDefineHashTable(source->definehash); + //free all the scripts + while ( source->scriptstack ) + { + script = source->scriptstack; + source->scriptstack = source->scriptstack->next; + FreeScript( script ); + } //end for + //free all the tokens + while ( source->tokens ) + { + token = source->tokens; + source->tokens = source->tokens->next; + PC_FreeToken( token ); + } //end for +#if DEFINEHASHING + for ( i = 0; i < DEFINEHASHSIZE; i++ ) + { + while ( source->definehash[i] ) + { + define = source->definehash[i]; + source->definehash[i] = source->definehash[i]->hashnext; + PC_FreeDefine( define ); + } //end while + } //end for +#else //DEFINEHASHING + //free all defines + while ( source->defines ) + { + define = source->defines; + source->defines = source->defines->next; + PC_FreeDefine( define ); + } //end for +#endif //DEFINEHASHING + //free all indents + while ( source->indentstack ) + { + indent = source->indentstack; + source->indentstack = source->indentstack->next; + FreeMemory( indent ); + } //end for +#if DEFINEHASHING + // + if ( source->definehash ) { + FreeMemory( source->definehash ); + } +#endif //DEFINEHASHING + //free the source itself + FreeMemory( source ); +} //end of the function FreeSource + diff --git a/Projects/Android/jni/rtcw/src/extractfuncs/out/src/extractfuncs/l_precomp.h b/Projects/Android/jni/rtcw/src/extractfuncs/out/src/extractfuncs/l_precomp.h new file mode 100644 index 0000000..1d2b9ea --- /dev/null +++ b/Projects/Android/jni/rtcw/src/extractfuncs/out/src/extractfuncs/l_precomp.h @@ -0,0 +1,158 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +/***************************************************************************** + * name: l_precomp.h + * + * desc: pre compiler + * + * + *****************************************************************************/ + +#ifndef _MAX_PATH + #define MAX_PATH MAX_QPATH +#endif + +#ifndef PATH_SEPERATORSTR + #if defined( WIN32 ) | defined( _WIN32 ) | defined( __NT__ ) | defined( __WINDOWS__ ) | defined( __WINDOWS_386__ ) + #define PATHSEPERATOR_STR "\\" + #else + #define PATHSEPERATOR_STR "/" + #endif +#endif +#ifndef PATH_SEPERATORCHAR + #if defined( WIN32 ) | defined( _WIN32 ) | defined( __NT__ ) | defined( __WINDOWS__ ) | defined( __WINDOWS_386__ ) + #define PATHSEPERATOR_CHAR '\\' + #else + #define PATHSEPERATOR_CHAR '/' + #endif +#endif + + +#define DEFINE_FIXED 0x0001 + +#define BUILTIN_LINE 1 +#define BUILTIN_FILE 2 +#define BUILTIN_DATE 3 +#define BUILTIN_TIME 4 +#define BUILTIN_STDC 5 + +#define INDENT_IF 0x0001 +#define INDENT_ELSE 0x0002 +#define INDENT_ELIF 0x0004 +#define INDENT_IFDEF 0x0008 +#define INDENT_IFNDEF 0x0010 + +//macro definitions +typedef struct define_s +{ + char *name; //define name + int flags; //define flags + int builtin; // > 0 if builtin define + int numparms; //number of define parameters + token_t *parms; //define parameters + token_t *tokens; //macro tokens (possibly containing parm tokens) + struct define_s *next; //next defined macro in a list + struct define_s *hashnext; //next define in the hash chain +} define_t; + +//indents +//used for conditional compilation directives: +//#if, #else, #elif, #ifdef, #ifndef +typedef struct indent_s +{ + int type; //indent type + int skip; //true if skipping current indent + script_t *script; //script the indent was in + struct indent_s *next; //next indent on the indent stack +} indent_t; + +//source file +typedef struct source_s +{ + char filename[_MAX_PATH]; //file name of the script + char includepath[_MAX_PATH]; //path to include files + punctuation_t *punctuations; //punctuations to use + script_t *scriptstack; //stack with scripts of the source + token_t *tokens; //tokens to read first + define_t *defines; //list with macro definitions + define_t **definehash; //hash chain with defines + indent_t *indentstack; //stack with indents + int skip; // > 0 if skipping conditional code + token_t token; //last read token +} source_t; + + +//read a token from the source +int PC_ReadToken( source_t *source, token_t *token ); +//expect a certain token +int PC_ExpectTokenString( source_t *source, char *string ); +//expect a certain token type +int PC_ExpectTokenType( source_t *source, int type, int subtype, token_t *token ); +//expect a token +int PC_ExpectAnyToken( source_t *source, token_t *token ); +//returns true when the token is available +int PC_CheckTokenString( source_t *source, char *string ); +//returns true an reads the token when a token with the given type is available +int PC_CheckTokenType( source_t *source, int type, int subtype, token_t *token ); +//skip tokens until the given token string is read +int PC_SkipUntilString( source_t *source, char *string ); +//unread the last token read from the script +void PC_UnreadLastToken( source_t *source ); +//unread the given token +void PC_UnreadToken( source_t *source, token_t *token ); +//read a token only if on the same line, lines are concatenated with a slash +int PC_ReadLine( source_t *source, token_t *token ); +//returns true if there was a white space in front of the token +int PC_WhiteSpaceBeforeToken( token_t *token ); +//add a define to the source +int PC_AddDefine( source_t *source, char *string ); +//add a globals define that will be added to all opened sources +int PC_AddGlobalDefine( char *string ); +//remove the given global define +int PC_RemoveGlobalDefine( char *name ); +//remove all globals defines +void PC_RemoveAllGlobalDefines( void ); +//add builtin defines +void PC_AddBuiltinDefines( source_t *source ); +//set the source include path +void PC_SetIncludePath( source_t *source, char *path ); +//set the punction set +void PC_SetPunctuations( source_t *source, punctuation_t *p ); +//load a source file +source_t *LoadSourceFile( char *filename ); +//load a source from memory +source_t *LoadSourceMemory( char *ptr, int length, char *name ); +//free the given source +void FreeSource( source_t *source ); +//print a source error +void QDECL SourceError( source_t *source, char *str, ... ); +//print a source warning +void QDECL SourceWarning( source_t *source, char *str, ... ); + diff --git a/Projects/Android/jni/rtcw/src/extractfuncs/out/src/extractfuncs/l_script.c b/Projects/Android/jni/rtcw/src/extractfuncs/out/src/extractfuncs/l_script.c new file mode 100644 index 0000000..e1b4308 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/extractfuncs/out/src/extractfuncs/l_script.c @@ -0,0 +1,1419 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +/***************************************************************************** + * name: l_script.c + * + * desc: lexicographical parser + * + * + *****************************************************************************/ + +//#define SCREWUP +//#define BOTLIB +//#define MEQCC +//#define BSPC + +#ifdef SCREWUP +#include +#include +#include +#include +#include +#include "l_memory.h" +#include "l_script.h" + +typedef enum {qfalse, qtrue} qboolean; + +#endif //SCREWUP + +#ifdef BOTLIB +//include files for usage in the bot library +#include "../game/q_shared.h" +#include "botlib.h" +#include "be_interface.h" +#include "l_script.h" +#include "l_memory.h" +#include "l_log.h" +#include "l_libvar.h" +#endif //BOTLIB + +#ifdef MEQCC +//include files for usage in MrElusive's QuakeC Compiler +#include "qcc.h" +#include "l_script.h" +#include "l_memory.h" +#include "l_log.h" + +#define qtrue true +#define qfalse false +#endif //MEQCC + +#ifdef BSPC +//include files for usage in the BSP Converter +#include "../bspc/qbsp.h" +#include "../bspc/l_log.h" +#include "../bspc/l_mem.h" + +#define qtrue true +#define qfalse false +#endif //BSPC + + +#define PUNCTABLE + +//longer punctuations first +punctuation_t default_punctuations[] = +{ + //binary operators + {">>=",P_RSHIFT_ASSIGN, NULL}, + {"<<=",P_LSHIFT_ASSIGN, NULL}, + // + {"...",P_PARMS, NULL}, + //define merge operator + {"##",P_PRECOMPMERGE, NULL}, + //logic operators + {"&&",P_LOGIC_AND, NULL}, + {"||",P_LOGIC_OR, NULL}, + {">=",P_LOGIC_GEQ, NULL}, + {"<=",P_LOGIC_LEQ, NULL}, + {"==",P_LOGIC_EQ, NULL}, + {"!=",P_LOGIC_UNEQ, NULL}, + //arithmatic operators + {"*=",P_MUL_ASSIGN, NULL}, + {"/=",P_DIV_ASSIGN, NULL}, + {"%=",P_MOD_ASSIGN, NULL}, + {"+=",P_ADD_ASSIGN, NULL}, + {"-=",P_SUB_ASSIGN, NULL}, + {"++",P_INC, NULL}, + {"--",P_DEC, NULL}, + //binary operators + {"&=",P_BIN_AND_ASSIGN, NULL}, + {"|=",P_BIN_OR_ASSIGN, NULL}, + {"^=",P_BIN_XOR_ASSIGN, NULL}, + {">>",P_RSHIFT, NULL}, + {"<<",P_LSHIFT, NULL}, + //reference operators + {"->",P_POINTERREF, NULL}, + //C++ + {"::",P_CPP1, NULL}, + {".*",P_CPP2, NULL}, + //arithmatic operators + {"*",P_MUL, NULL}, + {"/",P_DIV, NULL}, + {"%",P_MOD, NULL}, + {"+",P_ADD, NULL}, + {"-",P_SUB, NULL}, + {"=",P_ASSIGN, NULL}, + //binary operators + {"&",P_BIN_AND, NULL}, + {"|",P_BIN_OR, NULL}, + {"^",P_BIN_XOR, NULL}, + {"~",P_BIN_NOT, NULL}, + //logic operators + {"!",P_LOGIC_NOT, NULL}, + {">",P_LOGIC_GREATER, NULL}, + {"<",P_LOGIC_LESS, NULL}, + //reference operator + {".",P_REF, NULL}, + //seperators + {",",P_COMMA, NULL}, + {";",P_SEMICOLON, NULL}, + //label indication + {":",P_COLON, NULL}, + //if statement + {"?",P_QUESTIONMARK, NULL}, + //embracements + {"(",P_PARENTHESESOPEN, NULL}, + {")",P_PARENTHESESCLOSE, NULL}, + {"{",P_BRACEOPEN, NULL}, + {"}",P_BRACECLOSE, NULL}, + {"[",P_SQBRACKETOPEN, NULL}, + {"]",P_SQBRACKETCLOSE, NULL}, + // + {"\\",P_BACKSLASH, NULL}, + //precompiler operator + {"#",P_PRECOMP, NULL}, +#ifdef DOLLAR + {"$",P_DOLLAR, NULL}, +#endif //DOLLAR + {NULL, 0} +}; + +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void PS_CreatePunctuationTable( script_t *script, punctuation_t *punctuations ) { + int i; + punctuation_t *p, *lastp, *newp; + + //get memory for the table + if ( !script->punctuationtable ) { + script->punctuationtable = (punctuation_t **) + GetMemory( 256 * sizeof( punctuation_t * ) ); + } + memset( script->punctuationtable, 0, 256 * sizeof( punctuation_t * ) ); + //add the punctuations in the list to the punctuation table + for ( i = 0; punctuations[i].p; i++ ) + { + newp = &punctuations[i]; + lastp = NULL; + //sort the punctuations in this table entry on length (longer punctuations first) + for ( p = script->punctuationtable[(unsigned int) newp->p[0]]; p; p = p->next ) + { + if ( strlen( p->p ) < strlen( newp->p ) ) { + newp->next = p; + if ( lastp ) { + lastp->next = newp; + } else { script->punctuationtable[(unsigned int) newp->p[0]] = newp;} + break; + } //end if + lastp = p; + } //end for + if ( !p ) { + newp->next = NULL; + if ( lastp ) { + lastp->next = newp; + } else { script->punctuationtable[(unsigned int) newp->p[0]] = newp;} + } //end if + } //end for +} //end of the function PS_CreatePunctuationTable +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +char *PunctuationFromNum( script_t *script, int num ) { + int i; + + for ( i = 0; script->punctuations[i].p; i++ ) + { + if ( script->punctuations[i].n == num ) { + return script->punctuations[i].p; + } + } //end for + return "unkown punctuation"; +} //end of the function PunctuationFromNum +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void QDECL ScriptError( script_t *script, char *str, ... ) { + char text[1024]; + va_list ap; + + if ( script->flags & SCFL_NOERRORS ) { + return; + } + + va_start( ap, str ); + vsprintf( text, str, ap ); + va_end( ap ); +#ifdef BOTLIB + botimport.Print( PRT_ERROR, "file %s, line %d: %s\n", script->filename, script->line, text ); +#endif //BOTLIB +#ifdef MEQCC + printf( "error: file %s, line %d: %s\n", script->filename, script->line, text ); +#endif //MEQCC +#ifdef BSPC + Log_Print( "error: file %s, line %d: %s\n", script->filename, script->line, text ); +#endif //BSPC +} //end of the function ScriptError +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void QDECL ScriptWarning( script_t *script, char *str, ... ) { + char text[1024]; + va_list ap; + + if ( script->flags & SCFL_NOWARNINGS ) { + return; + } + + va_start( ap, str ); + vsprintf( text, str, ap ); + va_end( ap ); +#ifdef BOTLIB + botimport.Print( PRT_WARNING, "file %s, line %d: %s\n", script->filename, script->line, text ); +#endif //BOTLIB +#ifdef MEQCC + printf( "warning: file %s, line %d: %s\n", script->filename, script->line, text ); +#endif //MEQCC +#ifdef BSPC + Log_Print( "warning: file %s, line %d: %s\n", script->filename, script->line, text ); +#endif //BSPC +} //end of the function ScriptWarning +//=========================================================================== +// +// Parameter: - +// Returns: - +// Changes Globals: - +//=========================================================================== +void SetScriptPunctuations( script_t *script, punctuation_t *p ) { +#ifdef PUNCTABLE + if ( p ) { + PS_CreatePunctuationTable( script, p ); + } else { PS_CreatePunctuationTable( script, default_punctuations );} +#endif //PUNCTABLE + if ( p ) { + script->punctuations = p; + } else { script->punctuations = default_punctuations;} +} //end of the function SetScriptPunctuations +//============================================================================ +// Reads spaces, tabs, C-like comments etc. +// When a newline character is found the scripts line counter is increased. +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PS_ReadWhiteSpace( script_t *script ) { + while ( 1 ) + { + //skip white space + while ( *script->script_p <= ' ' ) + { + if ( !*script->script_p ) { + return 0; + } + if ( *script->script_p == '\n' ) { + script->line++; + } + script->script_p++; + } //end while + //skip comments + if ( *script->script_p == '/' ) { + //comments // + if ( *( script->script_p + 1 ) == '/' ) { + script->script_p++; + do + { + script->script_p++; + if ( !*script->script_p ) { + return 0; + } + } //end do + while ( *script->script_p != '\n' ); + script->line++; + script->script_p++; + if ( !*script->script_p ) { + return 0; + } + continue; + } //end if + //comments /* */ + else if ( *( script->script_p + 1 ) == '*' ) { + script->script_p++; + do + { + script->script_p++; + if ( !*script->script_p ) { + return 0; + } + if ( *script->script_p == '\n' ) { + script->line++; + } + } //end do + while ( !( *script->script_p == '*' && *( script->script_p + 1 ) == '/' ) ); + script->script_p++; + if ( !*script->script_p ) { + return 0; + } + script->script_p++; + if ( !*script->script_p ) { + return 0; + } + continue; + } //end if + } //end if + break; + } //end while + return 1; +} //end of the function PS_ReadWhiteSpace +//============================================================================ +// Reads an escape character. +// +// Parameter: script : script to read from +// ch : place to store the read escape character +// Returns: - +// Changes Globals: - +//============================================================================ +int PS_ReadEscapeCharacter( script_t *script, char *ch ) { + int c, val, i; + + //step over the leading '\\' + script->script_p++; + //determine the escape character + switch ( *script->script_p ) + { + case '\\': c = '\\'; break; + case 'n': c = '\n'; break; + case 'r': c = '\r'; break; + case 't': c = '\t'; break; + case 'v': c = '\v'; break; + case 'b': c = '\b'; break; + case 'f': c = '\f'; break; + case 'a': c = '\a'; break; + case '\'': c = '\''; break; + case '\"': c = '\"'; break; + case '\?': c = '\?'; break; + case 'x': + { + script->script_p++; + for ( i = 0, val = 0; ; i++, script->script_p++ ) + { + c = *script->script_p; + if ( c >= '0' && c <= '9' ) { + c = c - '0'; + } else if ( c >= 'A' && c <= 'Z' ) { + c = c - 'A' + 10; + } else if ( c >= 'a' && c <= 'z' ) { + c = c - 'a' + 10; + } else { break;} + val = ( val << 4 ) + c; + } //end for + script->script_p--; + if ( val > 0xFF ) { + ScriptWarning( script, "too large value in escape character" ); + val = 0xFF; + } //end if + c = val; + break; + } //end case + default: //NOTE: decimal ASCII code, NOT octal + { + if ( *script->script_p < '0' || *script->script_p > '9' ) { + ScriptError( script, "unknown escape char" ); + } + for ( i = 0, val = 0; ; i++, script->script_p++ ) + { + c = *script->script_p; + if ( c >= '0' && c <= '9' ) { + c = c - '0'; + } else { break;} + val = val * 10 + c; + } //end for + script->script_p--; + if ( val > 0xFF ) { + ScriptWarning( script, "too large value in escape character" ); + val = 0xFF; + } //end if + c = val; + break; + } //end default + } //end switch + //step over the escape character or the last digit of the number + script->script_p++; + //store the escape character + *ch = c; + //succesfully read escape character + return 1; +} //end of the function PS_ReadEscapeCharacter +//============================================================================ +// Reads C-like string. Escape characters are interpretted. +// Quotes are included with the string. +// Reads two strings with a white space between them as one string. +// +// Parameter: script : script to read from +// token : buffer to store the string +// Returns: qtrue when a string was read succesfully +// Changes Globals: - +//============================================================================ +int PS_ReadString( script_t *script, token_t *token, int quote ) { + int len, tmpline; + char *tmpscript_p; + + if ( quote == '\"' ) { + token->type = TT_STRING; + } else { token->type = TT_LITERAL;} + + len = 0; + //leading quote + token->string[len++] = *script->script_p++; + // + while ( 1 ) + { + //minus 2 because trailing double quote and zero have to be appended + if ( len >= MAX_TOKEN - 2 ) { + ScriptError( script, "string longer than MAX_TOKEN = %d", MAX_TOKEN ); + return 0; + } //end if + //if there is an escape character and + //if escape characters inside a string are allowed + if ( *script->script_p == '\\' && !( script->flags & SCFL_NOSTRINGESCAPECHARS ) ) { + if ( !PS_ReadEscapeCharacter( script, &token->string[len] ) ) { + token->string[len] = 0; + return 0; + } //end if + len++; + } //end if + //if a trailing quote + else if ( *script->script_p == quote ) { + //step over the double quote + script->script_p++; + //if white spaces in a string are not allowed + if ( script->flags & SCFL_NOSTRINGWHITESPACES ) { + break; + } + // + tmpscript_p = script->script_p; + tmpline = script->line; + //read unusefull stuff between possible two following strings + if ( !PS_ReadWhiteSpace( script ) ) { + script->script_p = tmpscript_p; + script->line = tmpline; + break; + } //end if + //if there's no leading double qoute + if ( *script->script_p != quote ) { + script->script_p = tmpscript_p; + script->line = tmpline; + break; + } //end if + //step over the new leading double quote + script->script_p++; + } //end if + else + { + if ( *script->script_p == '\0' ) { + token->string[len] = 0; + ScriptError( script, "missing trailing quote" ); + return 0; + } //end if + if ( *script->script_p == '\n' ) { + token->string[len] = 0; + ScriptError( script, "newline inside string %s", token->string ); + return 0; + } //end if + token->string[len++] = *script->script_p++; + } //end else + } //end while + //trailing quote + token->string[len++] = quote; + //end string with a zero + token->string[len] = '\0'; + //the sub type is the length of the string + token->subtype = len; + return 1; +} //end of the function PS_ReadString +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PS_ReadName( script_t *script, token_t *token ) { + int len = 0; + char c; + + token->type = TT_NAME; + do + { + token->string[len++] = *script->script_p++; + if ( len >= MAX_TOKEN ) { + ScriptError( script, "name longer than MAX_TOKEN = %d", MAX_TOKEN ); + return 0; + } //end if + c = *script->script_p; + } while ( ( c >= 'a' && c <= 'z' ) || + ( c >= 'A' && c <= 'Z' ) || + ( c >= '0' && c <= '9' ) || + c == '_' ); + token->string[len] = '\0'; + //the sub type is the length of the name + token->subtype = len; + return 1; +} //end of the function PS_ReadName +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void NumberValue( char *string, int subtype, unsigned long int *intvalue, + long double *floatvalue ) { + unsigned long int dotfound = 0; + + *intvalue = 0; + *floatvalue = 0; + //floating point number + if ( subtype & TT_FLOAT ) { + while ( *string ) + { + if ( *string == '.' ) { + if ( dotfound ) { + return; + } + dotfound = 10; + string++; + } //end if + if ( dotfound ) { + *floatvalue = *floatvalue + ( long double )( *string - '0' ) / + (long double) dotfound; + dotfound *= 10; + } //end if + else + { + *floatvalue = *floatvalue * 10.0 + ( long double )( *string - '0' ); + } //end else + string++; + } //end while + *intvalue = (unsigned long) *floatvalue; + } //end if + else if ( subtype & TT_DECIMAL ) { + while ( *string ) *intvalue = *intvalue * 10 + ( *string++ - '0' ); + *floatvalue = *intvalue; + } //end else if + else if ( subtype & TT_HEX ) { + //step over the leading 0x or 0X + string += 2; + while ( *string ) + { + *intvalue <<= 4; + if ( *string >= 'a' && *string <= 'f' ) { + *intvalue += *string - 'a' + 10; + } else if ( *string >= 'A' && *string <= 'F' ) { + *intvalue += *string - 'A' + 10; + } else { *intvalue += *string - '0';} + string++; + } //end while + *floatvalue = *intvalue; + } //end else if + else if ( subtype & TT_OCTAL ) { + //step over the first zero + string += 1; + while ( *string ) *intvalue = ( *intvalue << 3 ) + ( *string++ - '0' ); + *floatvalue = *intvalue; + } //end else if + else if ( subtype & TT_BINARY ) { + //step over the leading 0b or 0B + string += 2; + while ( *string ) *intvalue = ( *intvalue << 1 ) + ( *string++ - '0' ); + *floatvalue = *intvalue; + } //end else if +} //end of the function NumberValue +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PS_ReadNumber( script_t *script, token_t *token ) { + int len = 0, i; + int octal, dot; + char c; +// unsigned long int intvalue = 0; +// long double floatvalue = 0; + + token->type = TT_NUMBER; + //check for a hexadecimal number + if ( *script->script_p == '0' && + ( *( script->script_p + 1 ) == 'x' || + *( script->script_p + 1 ) == 'X' ) ) { + token->string[len++] = *script->script_p++; + token->string[len++] = *script->script_p++; + c = *script->script_p; + //hexadecimal + while ( ( c >= '0' && c <= '9' ) || + ( c >= 'a' && c <= 'f' ) || + ( c >= 'A' && c <= 'A' ) ) + { + token->string[len++] = *script->script_p++; + if ( len >= MAX_TOKEN ) { + ScriptError( script, "hexadecimal number longer than MAX_TOKEN = %d", MAX_TOKEN ); + return 0; + } //end if + c = *script->script_p; + } //end while + token->subtype |= TT_HEX; + } //end if +#ifdef BINARYNUMBERS + //check for a binary number + else if ( *script->script_p == '0' && + ( *( script->script_p + 1 ) == 'b' || + *( script->script_p + 1 ) == 'B' ) ) { + token->string[len++] = *script->script_p++; + token->string[len++] = *script->script_p++; + c = *script->script_p; + //hexadecimal + while ( c == '0' || c == '1' ) + { + token->string[len++] = *script->script_p++; + if ( len >= MAX_TOKEN ) { + ScriptError( script, "binary number longer than MAX_TOKEN = %d", MAX_TOKEN ); + return 0; + } //end if + c = *script->script_p; + } //end while + token->subtype |= TT_BINARY; + } //end if +#endif //BINARYNUMBERS + else //decimal or octal integer or floating point number + { + octal = qfalse; + dot = qfalse; + if ( *script->script_p == '0' ) { + octal = qtrue; + } + while ( 1 ) + { + token->string[len++] = *script->script_p++; + if ( len >= MAX_TOKEN ) { + ScriptError( script, "number longer than MAX_TOKEN = %d", MAX_TOKEN ); + return 0; + } //end if + c = *script->script_p; + if ( c == '.' ) { + dot = qtrue; + } else if ( c == '8' || c == '9' ) { + octal = qfalse; + } else if ( c < '0' || c > '9' ) { + break; + } + } //end while + if ( octal ) { + token->subtype |= TT_OCTAL; + } else { token->subtype |= TT_DECIMAL;} + if ( dot ) { + token->subtype |= TT_FLOAT; + } + } //end else + for ( i = 0; i < 2; i++ ) + { + c = *script->script_p; + //check for a LONG number + if ( c == 'l' || c == 'L' && + !( token->subtype & TT_LONG ) ) { + script->script_p++; + token->subtype |= TT_LONG; + } //end if + //check for an UNSIGNED number + else if ( c == 'u' || c == 'U' && + !( token->subtype & ( TT_UNSIGNED | TT_FLOAT ) ) ) { + script->script_p++; + token->subtype |= TT_UNSIGNED; + } //end if + } //end for + token->string[len] = '\0'; +#ifdef NUMBERVALUE + NumberValue( token->string, token->subtype, &token->intvalue, &token->floatvalue ); +#endif //NUMBERVALUE + if ( !( token->subtype & TT_FLOAT ) ) { + token->subtype |= TT_INTEGER; + } + return 1; +} //end of the function PS_ReadNumber +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PS_ReadLiteral( script_t *script, token_t *token ) { + token->type = TT_LITERAL; + //first quote + token->string[0] = *script->script_p++; + //check for end of file + if ( !*script->script_p ) { + ScriptError( script, "end of file before trailing \'" ); + return 0; + } //end if + //if it is an escape character + if ( *script->script_p == '\\' ) { + if ( !PS_ReadEscapeCharacter( script, &token->string[1] ) ) { + return 0; + } + } //end if + else + { + token->string[1] = *script->script_p++; + } //end else + //check for trailing quote + if ( *script->script_p != '\'' ) { + ScriptWarning( script, "too many characters in literal, ignored" ); + while ( *script->script_p && + *script->script_p != '\'' && + *script->script_p != '\n' ) + { + script->script_p++; + } //end while + if ( *script->script_p == '\'' ) { + script->script_p++; + } + } //end if + //store the trailing quote + token->string[2] = *script->script_p++; + //store trailing zero to end the string + token->string[3] = '\0'; + //the sub type is the integer literal value + token->subtype = token->string[1]; + // + return 1; +} //end of the function PS_ReadLiteral +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PS_ReadPunctuation( script_t *script, token_t *token ) { + int len; + char *p; + punctuation_t *punc; + +#ifdef PUNCTABLE + for ( punc = script->punctuationtable[(unsigned int)*script->script_p]; punc; punc = punc->next ) + { +#else + int i; + + for ( i = 0; script->punctuations[i].p; i++ ) + { + punc = &script->punctuations[i]; +#endif //PUNCTABLE + p = punc->p; + len = strlen( p ); + //if the script contains at least as much characters as the punctuation + if ( script->script_p + len <= script->end_p ) { + //if the script contains the punctuation + if ( !strncmp( script->script_p, p, len ) ) { + strncpy( token->string, p, MAX_TOKEN ); + script->script_p += len; + token->type = TT_PUNCTUATION; + //sub type is the number of the punctuation + token->subtype = punc->n; + return 1; + } //end if + } //end if + } //end for + return 0; +} //end of the function PS_ReadPunctuation +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PS_ReadPrimitive( script_t *script, token_t *token ) { + int len; + + len = 0; + while ( *script->script_p > ' ' && *script->script_p != ';' ) + { + if ( len >= MAX_TOKEN ) { + ScriptError( script, "primitive token longer than MAX_TOKEN = %d", MAX_TOKEN ); + return 0; + } //end if + token->string[len++] = *script->script_p++; + } //end while + token->string[len] = 0; + //copy the token into the script structure + memcpy( &script->token, token, sizeof( token_t ) ); + //primitive reading successfull + return 1; +} //end of the function PS_ReadPrimitive +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PS_ReadToken( script_t *script, token_t *token ) { + //if there is a token available (from UnreadToken) + if ( script->tokenavailable ) { + script->tokenavailable = 0; + memcpy( token, &script->token, sizeof( token_t ) ); + return 1; + } //end if + //save script pointer + script->lastscript_p = script->script_p; + //save line counter + script->lastline = script->line; + //clear the token stuff + memset( token, 0, sizeof( token_t ) ); + //start of the white space + script->whitespace_p = script->script_p; + token->whitespace_p = script->script_p; + //read unusefull stuff + if ( !PS_ReadWhiteSpace( script ) ) { + return 0; + } + //end of the white space + script->endwhitespace_p = script->script_p; + token->endwhitespace_p = script->script_p; + //line the token is on + token->line = script->line; + //number of lines crossed before token + token->linescrossed = script->line - script->lastline; + //if there is a leading double quote + if ( *script->script_p == '\"' ) { + if ( !PS_ReadString( script, token, '\"' ) ) { + return 0; + } + } //end if + //if an literal + else if ( *script->script_p == '\'' ) { + //if (!PS_ReadLiteral(script, token)) return 0; + if ( !PS_ReadString( script, token, '\'' ) ) { + return 0; + } + } //end if + //if there is a number + else if ( ( *script->script_p >= '0' && *script->script_p <= '9' ) || + ( *script->script_p == '.' && + ( *( script->script_p + 1 ) >= '0' && *( script->script_p + 1 ) <= '9' ) ) ) { + if ( !PS_ReadNumber( script, token ) ) { + return 0; + } + } //end if + //if this is a primitive script + else if ( script->flags & SCFL_PRIMITIVE ) { + return PS_ReadPrimitive( script, token ); + } //end else if + //if there is a name + else if ( ( *script->script_p >= 'a' && *script->script_p <= 'z' ) || + ( *script->script_p >= 'A' && *script->script_p <= 'Z' ) || + *script->script_p == '_' ) { + if ( !PS_ReadName( script, token ) ) { + return 0; + } + } //end if + //check for punctuations + else if ( !PS_ReadPunctuation( script, token ) ) { + ScriptError( script, "can't read token" ); + return 0; + } //end if + //copy the token into the script structure + memcpy( &script->token, token, sizeof( token_t ) ); + //succesfully read a token + return 1; +} //end of the function PS_ReadToken +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PS_ExpectTokenString( script_t *script, char *string ) { + token_t token; + + if ( !PS_ReadToken( script, &token ) ) { + ScriptError( script, "couldn't find expected %s", string ); + return 0; + } //end if + + if ( strcmp( token.string, string ) ) { + ScriptError( script, "expected %s, found %s", string, token.string ); + return 0; + } //end if + return 1; +} //end of the function PS_ExpectToken +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PS_ExpectTokenType( script_t *script, int type, int subtype, token_t *token ) { + char str[MAX_TOKEN]; + + if ( !PS_ReadToken( script, token ) ) { + ScriptError( script, "couldn't read expected token" ); + return 0; + } //end if + + if ( token->type != type ) { + if ( type == TT_STRING ) { + strcpy( str, "string" ); + } + if ( type == TT_LITERAL ) { + strcpy( str, "literal" ); + } + if ( type == TT_NUMBER ) { + strcpy( str, "number" ); + } + if ( type == TT_NAME ) { + strcpy( str, "name" ); + } + if ( type == TT_PUNCTUATION ) { + strcpy( str, "punctuation" ); + } + ScriptError( script, "expected a %s, found %s", str, token->string ); + return 0; + } //end if + if ( token->type == TT_NUMBER ) { + if ( ( token->subtype & subtype ) != subtype ) { + if ( subtype & TT_DECIMAL ) { + strcpy( str, "decimal" ); + } + if ( subtype & TT_HEX ) { + strcpy( str, "hex" ); + } + if ( subtype & TT_OCTAL ) { + strcpy( str, "octal" ); + } + if ( subtype & TT_BINARY ) { + strcpy( str, "binary" ); + } + if ( subtype & TT_LONG ) { + strcat( str, " long" ); + } + if ( subtype & TT_UNSIGNED ) { + strcat( str, " unsigned" ); + } + if ( subtype & TT_FLOAT ) { + strcat( str, " float" ); + } + if ( subtype & TT_INTEGER ) { + strcat( str, " integer" ); + } + ScriptError( script, "expected %s, found %s", str, token->string ); + return 0; + } //end if + } //end if + else if ( token->type == TT_PUNCTUATION ) { + if ( subtype < 0 ) { + ScriptError( script, "BUG: wrong punctuation subtype" ); + return 0; + } //end if + if ( token->subtype != subtype ) { + ScriptError( script, "expected %s, found %s", + script->punctuations[subtype], token->string ); + return 0; + } //end if + } //end else if + return 1; +} //end of the function PS_ExpectTokenType +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PS_ExpectAnyToken( script_t *script, token_t *token ) { + if ( !PS_ReadToken( script, token ) ) { + ScriptError( script, "couldn't read expected token" ); + return 0; + } //end if + else + { + return 1; + } //end else +} //end of the function PS_ExpectAnyToken +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PS_CheckTokenString( script_t *script, char *string ) { + token_t tok; + + if ( !PS_ReadToken( script, &tok ) ) { + return 0; + } + //if the token is available + if ( !strcmp( tok.string, string ) ) { + return 1; + } + //token not available + script->script_p = script->lastscript_p; + return 0; +} //end of the function PS_CheckTokenString +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PS_CheckTokenType( script_t *script, int type, int subtype, token_t *token ) { + token_t tok; + + if ( !PS_ReadToken( script, &tok ) ) { + return 0; + } + //if the type matches + if ( tok.type == type && + ( tok.subtype & subtype ) == subtype ) { + memcpy( token, &tok, sizeof( token_t ) ); + return 1; + } //end if + //token is not available + script->script_p = script->lastscript_p; + return 0; +} //end of the function PS_CheckTokenType +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int PS_SkipUntilString( script_t *script, char *string ) { + token_t token; + + while ( PS_ReadToken( script, &token ) ) + { + if ( !strcmp( token.string, string ) ) { + return 1; + } + } //end while + return 0; +} //end of the function PS_SkipUntilString +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void PS_UnreadLastToken( script_t *script ) { + script->tokenavailable = 1; +} //end of the function UnreadLastToken +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void PS_UnreadToken( script_t *script, token_t *token ) { + memcpy( &script->token, token, sizeof( token_t ) ); + script->tokenavailable = 1; +} //end of the function UnreadToken +//============================================================================ +// returns the next character of the read white space, returns NULL if none +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +char PS_NextWhiteSpaceChar( script_t *script ) { + if ( script->whitespace_p != script->endwhitespace_p ) { + return *script->whitespace_p++; + } //end if + else + { + return 0; + } //end else +} //end of the function PS_NextWhiteSpaceChar +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void StripDoubleQuotes( char *string ) { + if ( *string == '\"' ) { + strcpy( string, string + 1 ); + } //end if + if ( string[strlen( string ) - 1] == '\"' ) { + string[strlen( string ) - 1] = '\0'; + } //end if +} //end of the function StripDoubleQuotes +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void StripSingleQuotes( char *string ) { + if ( *string == '\'' ) { + strcpy( string, string + 1 ); + } //end if + if ( string[strlen( string ) - 1] == '\'' ) { + string[strlen( string ) - 1] = '\0'; + } //end if +} //end of the function StripSingleQuotes +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +long double ReadSignedFloat( script_t *script ) { + token_t token; + long double sign = 1; + + PS_ExpectAnyToken( script, &token ); + if ( !strcmp( token.string, "-" ) ) { + sign = -1; + PS_ExpectTokenType( script, TT_NUMBER, 0, &token ); + } //end if + else if ( token.type != TT_NUMBER ) { + ScriptError( script, "expected float value, found %s\n", token.string ); + } //end else if + return sign * token.floatvalue; +} //end of the function ReadSignedFloat +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +signed long int ReadSignedInt( script_t *script ) { + token_t token; + signed long int sign = 1; + + PS_ExpectAnyToken( script, &token ); + if ( !strcmp( token.string, "-" ) ) { + sign = -1; + PS_ExpectTokenType( script, TT_NUMBER, TT_INTEGER, &token ); + } //end if + else if ( token.type != TT_NUMBER || token.subtype == TT_FLOAT ) { + ScriptError( script, "expected integer value, found %s\n", token.string ); + } //end else if + return sign * token.intvalue; +} //end of the function ReadSignedInt +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void SetScriptFlags( script_t *script, int flags ) { + script->flags = flags; +} //end of the function SetScriptFlags +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int GetScriptFlags( script_t *script ) { + return script->flags; +} //end of the function GetScriptFlags +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void ResetScript( script_t *script ) { + //pointer in script buffer + script->script_p = script->buffer; + //pointer in script buffer before reading token + script->lastscript_p = script->buffer; + //begin of white space + script->whitespace_p = NULL; + //end of white space + script->endwhitespace_p = NULL; + //set if there's a token available in script->token + script->tokenavailable = 0; + // + script->line = 1; + script->lastline = 1; + //clear the saved token + memset( &script->token, 0, sizeof( token_t ) ); +} //end of the function ResetScript +//============================================================================ +// returns true if at the end of the script +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int EndOfScript( script_t *script ) { + return script->script_p >= script->end_p; +} //end of the function EndOfScript +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int NumLinesCrossed( script_t *script ) { + return script->line - script->lastline; +} //end of the function NumLinesCrossed +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int ScriptSkipTo( script_t *script, char *value ) { + int len; + char firstchar; + + firstchar = *value; + len = strlen( value ); + do + { + if ( !PS_ReadWhiteSpace( script ) ) { + return 0; + } + if ( *script->script_p == firstchar ) { + if ( !strncmp( script->script_p, value, len ) ) { + return 1; + } //end if + } //end if + script->script_p++; + } while ( 1 ); +} //end of the function ScriptSkipTo +#ifndef BOTLIB +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +int FileLength( FILE *fp ) { + int pos; + int end; + + pos = ftell( fp ); + fseek( fp, 0, SEEK_END ); + end = ftell( fp ); + fseek( fp, pos, SEEK_SET ); + + return end; +} //end of the function FileLength +#endif +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +script_t *LoadScriptFile( char *filename ) { +#ifdef BOTLIB + fileHandle_t fp; + char pathname[MAX_QPATH]; +#else + FILE *fp; +#endif + int length; + void *buffer; + script_t *script; + +#ifdef BOTLIB + Com_sprintf( pathname, MAX_QPATH, "botfiles/%s", filename ); + length = botimport.FS_FOpenFile( pathname, &fp, FS_READ ); + if ( !fp ) { + return NULL; + } +#else + fp = fopen( filename, "rb" ); + if ( !fp ) { + return NULL; + } + + length = FileLength( fp ); +#endif + + buffer = GetClearedMemory( sizeof( script_t ) + length + 1 ); + script = (script_t *) buffer; + memset( script, 0, sizeof( script_t ) ); + strcpy( script->filename, filename ); + script->buffer = (char *) buffer + sizeof( script_t ); + script->buffer[length] = 0; + script->length = length; + //pointer in script buffer + script->script_p = script->buffer; + //pointer in script buffer before reading token + script->lastscript_p = script->buffer; + //pointer to end of script buffer + script->end_p = &script->buffer[length]; + //set if there's a token available in script->token + script->tokenavailable = 0; + // + script->line = 1; + script->lastline = 1; + // + SetScriptPunctuations( script, NULL ); + // +#ifdef BOTLIB + botimport.FS_Read( script->buffer, length, fp ); + botimport.FS_FCloseFile( fp ); +#else + if ( fread( script->buffer, length, 1, fp ) != 1 ) { + FreeMemory( buffer ); + script = NULL; + } //end if + fclose( fp ); +#endif + // + return script; +} //end of the function LoadScriptFile +//============================================================================ +//load a script from the given memory with the given length +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +script_t *LoadScriptMemory( char *ptr, int length, char *name ) { + void *buffer; + script_t *script; + + buffer = GetClearedMemory( sizeof( script_t ) + length + 1 ); + script = (script_t *) buffer; + memset( script, 0, sizeof( script_t ) ); + strcpy( script->filename, name ); + script->buffer = (char *) buffer + sizeof( script_t ); + script->buffer[length] = 0; + script->length = length; + //pointer in script buffer + script->script_p = script->buffer; + //pointer in script buffer before reading token + script->lastscript_p = script->buffer; + //pointer to end of script buffer + script->end_p = &script->buffer[length]; + //set if there's a token available in script->token + script->tokenavailable = 0; + // + script->line = 1; + script->lastline = 1; + // + SetScriptPunctuations( script, NULL ); + // + memcpy( script->buffer, ptr, length ); + // + return script; +} //end of the function LoadScriptMemory +//============================================================================ +// +// Parameter: - +// Returns: - +// Changes Globals: - +//============================================================================ +void FreeScript( script_t *script ) { +#ifdef PUNCTABLE + if ( script->punctuationtable ) { + FreeMemory( script->punctuationtable ); + } +#endif //PUNCTABLE + FreeMemory( script ); +} //end of the function FreeScript diff --git a/Projects/Android/jni/rtcw/src/extractfuncs/out/src/extractfuncs/l_script.h b/Projects/Android/jni/rtcw/src/extractfuncs/out/src/extractfuncs/l_script.h new file mode 100644 index 0000000..78cb90a --- /dev/null +++ b/Projects/Android/jni/rtcw/src/extractfuncs/out/src/extractfuncs/l_script.h @@ -0,0 +1,266 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +/***************************************************************************** + * name: l_script.h + * + * desc: lexicographical parser + * + * + *****************************************************************************/ + +// Ridah, can't get it to compile without this +#ifndef QDECL + +// for windows fastcall option +#define QDECL +//======================= WIN32 DEFINES ================================= +#ifdef WIN32 +#undef QDECL +#define QDECL __cdecl +#endif +#endif +// done. + +//undef if binary numbers of the form 0b... or 0B... are not allowed +#define BINARYNUMBERS +//undef if not using the token.intvalue and token.floatvalue +#define NUMBERVALUE +//use dollar sign also as punctuation +#define DOLLAR + +//maximum token length +#define MAX_TOKEN 1024 +//maximum path length +#ifndef MAX_QPATH + #define MAX_QPATH 64 +#endif +#ifndef _MAX_PATH + #define _MAX_PATH MAX_QPATH +#endif + +//script flags +#define SCFL_NOERRORS 0x0001 +#define SCFL_NOWARNINGS 0x0002 +#define SCFL_NOSTRINGWHITESPACES 0x0004 +#define SCFL_NOSTRINGESCAPECHARS 0x0008 +#define SCFL_PRIMITIVE 0x0010 +#define SCFL_NOBINARYNUMBERS 0x0020 +#define SCFL_NONUMBERVALUES 0x0040 + +//token types +#define TT_STRING 1 // string +#define TT_LITERAL 2 // literal +#define TT_NUMBER 3 // number +#define TT_NAME 4 // name +#define TT_PUNCTUATION 5 // punctuation + +//string sub type +//--------------- +// the length of the string +//literal sub type +//---------------- +// the ASCII code of the literal +//number sub type +//--------------- +#define TT_DECIMAL 0x0008 // decimal number +#define TT_HEX 0x0100 // hexadecimal number +#define TT_OCTAL 0x0200 // octal number +#ifdef BINARYNUMBERS +#define TT_BINARY 0x0400 // binary number +#endif //BINARYNUMBERS +#define TT_FLOAT 0x0800 // floating point number +#define TT_INTEGER 0x1000 // integer number +#define TT_LONG 0x2000 // long number +#define TT_UNSIGNED 0x4000 // unsigned number +//punctuation sub type +//-------------------- +#define P_RSHIFT_ASSIGN 1 +#define P_LSHIFT_ASSIGN 2 +#define P_PARMS 3 +#define P_PRECOMPMERGE 4 + +#define P_LOGIC_AND 5 +#define P_LOGIC_OR 6 +#define P_LOGIC_GEQ 7 +#define P_LOGIC_LEQ 8 +#define P_LOGIC_EQ 9 +#define P_LOGIC_UNEQ 10 + +#define P_MUL_ASSIGN 11 +#define P_DIV_ASSIGN 12 +#define P_MOD_ASSIGN 13 +#define P_ADD_ASSIGN 14 +#define P_SUB_ASSIGN 15 +#define P_INC 16 +#define P_DEC 17 + +#define P_BIN_AND_ASSIGN 18 +#define P_BIN_OR_ASSIGN 19 +#define P_BIN_XOR_ASSIGN 20 +#define P_RSHIFT 21 +#define P_LSHIFT 22 + +#define P_POINTERREF 23 +#define P_CPP1 24 +#define P_CPP2 25 +#define P_MUL 26 +#define P_DIV 27 +#define P_MOD 28 +#define P_ADD 29 +#define P_SUB 30 +#define P_ASSIGN 31 + +#define P_BIN_AND 32 +#define P_BIN_OR 33 +#define P_BIN_XOR 34 +#define P_BIN_NOT 35 + +#define P_LOGIC_NOT 36 +#define P_LOGIC_GREATER 37 +#define P_LOGIC_LESS 38 + +#define P_REF 39 +#define P_COMMA 40 +#define P_SEMICOLON 41 +#define P_COLON 42 +#define P_QUESTIONMARK 43 + +#define P_PARENTHESESOPEN 44 +#define P_PARENTHESESCLOSE 45 +#define P_BRACEOPEN 46 +#define P_BRACECLOSE 47 +#define P_SQBRACKETOPEN 48 +#define P_SQBRACKETCLOSE 49 +#define P_BACKSLASH 50 + +#define P_PRECOMP 51 +#define P_DOLLAR 52 +//name sub type +//------------- +// the length of the name + +//punctuation +typedef struct punctuation_s +{ + char *p; //punctuation character(s) + int n; //punctuation indication + struct punctuation_s *next; //next punctuation +} punctuation_t; + +//token +typedef struct token_s +{ + char string[MAX_TOKEN]; //available token + int type; //last read token type + int subtype; //last read token sub type +#ifdef NUMBERVALUE + unsigned long int intvalue; //integer value + long double floatvalue; //floating point value +#endif //NUMBERVALUE + char *whitespace_p; //start of white space before token + char *endwhitespace_p; //start of white space before token + int line; //line the token was on + int linescrossed; //lines crossed in white space + struct token_s *next; //next token in chain +} token_t; + +//script file +typedef struct script_s +{ + char filename[_MAX_PATH]; //file name of the script + char *buffer; //buffer containing the script + char *script_p; //current pointer in the script + char *end_p; //pointer to the end of the script + char *lastscript_p; //script pointer before reading token + char *whitespace_p; //begin of the white space + char *endwhitespace_p; //end of the white space + int length; //length of the script in bytes + int line; //current line in script + int lastline; //line before reading token + int tokenavailable; //set by UnreadLastToken + int flags; //several script flags + punctuation_t *punctuations; //the punctuations used in the script + punctuation_t **punctuationtable; + token_t token; //available token + struct script_s *next; //next script in a chain +} script_t; + +//read a token from the script +int PS_ReadToken( script_t *script, token_t *token ); +//expect a certain token +int PS_ExpectTokenString( script_t *script, char *string ); +//expect a certain token type +int PS_ExpectTokenType( script_t *script, int type, int subtype, token_t *token ); +//expect a token +int PS_ExpectAnyToken( script_t *script, token_t *token ); +//returns true when the token is available +int PS_CheckTokenString( script_t *script, char *string ); +//returns true an reads the token when a token with the given type is available +int PS_CheckTokenType( script_t *script, int type, int subtype, token_t *token ); +//skip tokens until the given token string is read +int PS_SkipUntilString( script_t *script, char *string ); +//unread the last token read from the script +void PS_UnreadLastToken( script_t *script ); +//unread the given token +void PS_UnreadToken( script_t *script, token_t *token ); +//returns the next character of the read white space, returns NULL if none +char PS_NextWhiteSpaceChar( script_t *script ); +//remove any leading and trailing double quotes from the token +void StripDoubleQuotes( char *string ); +//remove any leading and trailing single quotes from the token +void StripSingleQuotes( char *string ); +//read a possible signed integer +signed long int ReadSignedInt( script_t *script ); +//read a possible signed floating point number +long double ReadSignedFloat( script_t *script ); +//set an array with punctuations, NULL restores default C/C++ set +void SetScriptPunctuations( script_t *script, punctuation_t *p ); +//set script flags +void SetScriptFlags( script_t *script, int flags ); +//get script flags +int GetScriptFlags( script_t *script ); +//reset a script +void ResetScript( script_t *script ); +//returns true if at the end of the script +int EndOfScript( script_t *script ); +//returns a pointer to the punctuation with the given number +char *PunctuationFromNum( script_t *script, int num ); +//load a script from the given file at the given offset with the given length +script_t *LoadScriptFile( char *filename ); +//load a script from the given memory with the given length +script_t *LoadScriptMemory( char *ptr, int length, char *name ); +//free a script +void FreeScript( script_t *script ); +//print a script error with filename and line number +void QDECL ScriptError( script_t *script, char *str, ... ); +//print a script warning with filename and line number +void QDECL ScriptWarning( script_t *script, char *str, ... ); + + diff --git a/Projects/Android/jni/rtcw/src/extractfuncs/out/src/game/botlib.h b/Projects/Android/jni/rtcw/src/extractfuncs/out/src/game/botlib.h new file mode 100644 index 0000000..347b9b8 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/extractfuncs/out/src/game/botlib.h @@ -0,0 +1,521 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +//=========================================================================== +// +/***************************************************************************** + * name: botlib.h + * + * desc: bot AI library + * + * + *****************************************************************************/ + +#define BOTLIB_API_VERSION 2 + +struct aas_clientmove_s; +struct aas_entityinfo_s; +struct bot_consolemessage_s; +struct bot_match_s; +struct bot_goal_s; +struct bot_moveresult_s; +struct bot_initmove_s; +struct weaponinfo_s; + + +//debug line colors +#define LINECOLOR_NONE -1 +#define LINECOLOR_RED 1 //0xf2f2f0f0L +#define LINECOLOR_GREEN 2 //0xd0d1d2d3L +#define LINECOLOR_BLUE 3 //0xf3f3f1f1L +#define LINECOLOR_YELLOW 4 //0xdcdddedfL +#define LINECOLOR_ORANGE 5 //0xe0e1e2e3L + +//Print types +#define PRT_MESSAGE 1 +#define PRT_WARNING 2 +#define PRT_ERROR 3 +#define PRT_FATAL 4 +#define PRT_EXIT 5 + +//console message types +#define CMS_NORMAL 0 +#define CMS_CHAT 1 + +//botlib error codes +#define BLERR_NOERROR 0 //no error +#define BLERR_LIBRARYNOTSETUP 1 //library not setup +#define BLERR_LIBRARYALREADYSETUP 2 //BotSetupLibrary: library already setup +#define BLERR_INVALIDCLIENTNUMBER 3 //invalid client number +#define BLERR_INVALIDENTITYNUMBER 4 //invalid entity number +#define BLERR_NOAASFILE 5 //BotLoadMap: no AAS file available +#define BLERR_CANNOTOPENAASFILE 6 //BotLoadMap: cannot open AAS file +#define BLERR_CANNOTSEEKTOAASFILE 7 //BotLoadMap: cannot seek to AAS file +#define BLERR_CANNOTREADAASHEADER 8 //BotLoadMap: cannot read AAS header +#define BLERR_WRONGAASFILEID 9 //BotLoadMap: incorrect AAS file id +#define BLERR_WRONGAASFILEVERSION 10 //BotLoadMap: incorrect AAS file version +#define BLERR_CANNOTREADAASLUMP 11 //BotLoadMap: cannot read AAS file lump +#define BLERR_NOBSPFILE 12 //BotLoadMap: no BSP file available +#define BLERR_CANNOTOPENBSPFILE 13 //BotLoadMap: cannot open BSP file +#define BLERR_CANNOTSEEKTOBSPFILE 14 //BotLoadMap: cannot seek to BSP file +#define BLERR_CANNOTREADBSPHEADER 15 //BotLoadMap: cannot read BSP header +#define BLERR_WRONGBSPFILEID 16 //BotLoadMap: incorrect BSP file id +#define BLERR_WRONGBSPFILEVERSION 17 //BotLoadMap: incorrect BSP file version +#define BLERR_CANNOTREADBSPLUMP 18 //BotLoadMap: cannot read BSP file lump +#define BLERR_AICLIENTNOTSETUP 19 //BotAI: client not setup +#define BLERR_AICLIENTALREADYSETUP 20 //BotSetupClient: client already setup +#define BLERR_AIMOVEINACTIVECLIENT 21 //BotMoveClient: cannot move inactive client +#define BLERR_AIMOVETOACTIVECLIENT 22 //BotMoveClient: cannot move to active client +#define BLERR_AICLIENTALREADYSHUTDOWN 23 //BotShutdownClient: client not setup +#define BLERR_AIUPDATEINACTIVECLIENT 24 //BotUpdateClient: called for inactive client +#define BLERR_AICMFORINACTIVECLIENT 25 //BotConsoleMessage: called for inactive client +#define BLERR_SETTINGSINACTIVECLIENT 26 //BotClientSettings: called for inactive client +#define BLERR_CANNOTLOADICHAT 27 //BotSetupClient: cannot load initial chats +#define BLERR_CANNOTLOADITEMWEIGHTS 28 //BotSetupClient: cannot load item weights +#define BLERR_CANNOTLOADITEMCONFIG 29 //BotSetupLibrary: cannot load item config +#define BLERR_CANNOTLOADWEAPONWEIGHTS 30 //BotSetupClient: cannot load weapon weights +#define BLERR_CANNOTLOADWEAPONCONFIG 31 //BotSetupLibrary: cannot load weapon config +#define BLERR_INVALIDSOUNDINDEX 32 //BotAddSound: invalid sound index value + +//action flags +#define ACTION_ATTACK 1 +#define ACTION_USE 2 +#define ACTION_RESPAWN 4 +#define ACTION_JUMP 8 +#define ACTION_MOVEUP 8 +#define ACTION_CROUCH 16 +#define ACTION_MOVEDOWN 16 +#define ACTION_MOVEFORWARD 32 +#define ACTION_MOVEBACK 64 +#define ACTION_MOVELEFT 128 +#define ACTION_MOVERIGHT 256 +#define ACTION_DELAYEDJUMP 512 +#define ACTION_TALK 1024 +#define ACTION_GESTURE 2048 +#define ACTION_WALK 4096 +#define ACTION_RELOAD 8192 + +//the bot input, will be converted to an usercmd_t +typedef struct bot_input_s +{ + float thinktime; //time since last output (in seconds) + vec3_t dir; //movement direction + float speed; //speed in the range [0, 400] + vec3_t viewangles; //the view angles + int actionflags; //one of the ACTION_? flags + int weapon; //weapon to use +} bot_input_t; + +#ifndef BSPTRACE + +//bsp_trace_t hit surface +typedef struct bsp_surface_s +{ + char name[16]; + int flags; + int value; +} bsp_surface_t; + +//remove the bsp_trace_s structure definition l8r on +//a trace is returned when a box is swept through the world +typedef struct bsp_trace_s +{ + qboolean allsolid; // if true, plane is not valid + qboolean startsolid; // if true, the initial point was in a solid area + float fraction; // time completed, 1.0 = didn't hit anything + vec3_t endpos; // final position + cplane_t plane; // surface normal at impact + float exp_dist; // expanded plane distance + int sidenum; // number of the brush side hit + bsp_surface_t surface; // the hit point surface + int contents; // contents on other side of surface hit + int ent; // number of entity hit +} bsp_trace_t; + +#define BSPTRACE +#endif // BSPTRACE + +//entity state +typedef struct bot_entitystate_s +{ + int type; // entity type + int flags; // entity flags + vec3_t origin; // origin of the entity + vec3_t angles; // angles of the model + vec3_t old_origin; // for lerping + vec3_t mins; // bounding box minimums + vec3_t maxs; // bounding box maximums + int groundent; // ground entity + int solid; // solid type + int modelindex; // model used + int modelindex2; // weapons, CTF flags, etc + int frame; // model frame number + int event; // impulse events -- muzzle flashes, footsteps, etc + int eventParm; // even parameter + int powerups; // bit flags + int weapon; // determines weapon and flash model, etc + int legsAnim; // mask off ANIM_TOGGLEBIT + int torsoAnim; // mask off ANIM_TOGGLEBIT +// int weapAnim; // mask off ANIM_TOGGLEBIT //----(SA) added +//----(SA) didn't want to comment in as I wasn't sure of any implications of changing this structure. +} bot_entitystate_t; + +//bot AI library exported functions +typedef struct botlib_import_s +{ + //print messages from the bot library + void ( QDECL * Print )( int type, char *fmt, ... ); + //trace a bbox through the world + void ( *Trace )( bsp_trace_t *trace, vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end, int passent, int contentmask ); + //trace a bbox against a specific entity + void ( *EntityTrace )( bsp_trace_t *trace, vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end, int entnum, int contentmask ); + //retrieve the contents at the given point + int ( *PointContents )( vec3_t point ); + //check if the point is in potential visible sight + int ( *inPVS )( vec3_t p1, vec3_t p2 ); + //retrieve the BSP entity data lump + char *( *BSPEntityData )( void ); + // + void ( *BSPModelMinsMaxsOrigin )( int modelnum, vec3_t angles, vec3_t mins, vec3_t maxs, vec3_t origin ); + //send a bot client command + void ( *BotClientCommand )( int client, char *command ); + //memory allocation + void *( *GetMemory )( int size ); + void ( *FreeMemory )( void *ptr ); + void *( *HunkAlloc )( int size ); + //file system access + int ( *FS_FOpenFile )( const char *qpath, fileHandle_t *file, fsMode_t mode ); + int ( *FS_Read )( void *buffer, int len, fileHandle_t f ); + int ( *FS_Write )( const void *buffer, int len, fileHandle_t f ); + void ( *FS_FCloseFile )( fileHandle_t f ); + int ( *FS_Seek )( fileHandle_t f, long offset, int origin ); + //debug visualisation stuff + int ( *DebugLineCreate )( void ); + void ( *DebugLineDelete )( int line ); + void ( *DebugLineShow )( int line, vec3_t start, vec3_t end, int color ); + // + int ( *DebugPolygonCreate )( int color, int numPoints, vec3_t *points ); + void ( *DebugPolygonDelete )( int id ); + // + // Ridah, Cast AI stuff + qboolean ( *AICast_VisibleFromPos )( vec3_t srcpos, int srcnum, + vec3_t destpos, int destnum, qboolean updateVisPos ); + qboolean ( *AICast_CheckAttackAtPos )( int entnum, int enemy, vec3_t pos, qboolean ducking, qboolean allowHitWorld ); + // done. +} botlib_import_t; + +typedef struct aas_export_s +{ + //----------------------------------- + // be_aas_entity.h + //----------------------------------- + void ( *AAS_EntityInfo )( int entnum, struct aas_entityinfo_s *info ); + //----------------------------------- + // be_aas_main.h + //----------------------------------- + int ( *AAS_Initialized )( void ); + void ( *AAS_PresenceTypeBoundingBox )( int presencetype, vec3_t mins, vec3_t maxs ); + float ( *AAS_Time )( void ); + //-------------------------------------------- + // be_aas_sample.c + //-------------------------------------------- + int ( *AAS_PointAreaNum )( vec3_t point ); + int ( *AAS_TraceAreas )( vec3_t start, vec3_t end, int *areas, vec3_t *points, int maxareas ); + //-------------------------------------------- + // be_aas_bspq3.c + //-------------------------------------------- + int ( *AAS_PointContents )( vec3_t point ); + int ( *AAS_NextBSPEntity )( int ent ); + int ( *AAS_ValueForBSPEpairKey )( int ent, char *key, char *value, int size ); + int ( *AAS_VectorForBSPEpairKey )( int ent, char *key, vec3_t v ); + int ( *AAS_FloatForBSPEpairKey )( int ent, char *key, float *value ); + int ( *AAS_IntForBSPEpairKey )( int ent, char *key, int *value ); + //-------------------------------------------- + // be_aas_reach.c + //-------------------------------------------- + int ( *AAS_AreaReachability )( int areanum ); + //-------------------------------------------- + // be_aas_route.c + //-------------------------------------------- + int ( *AAS_AreaTravelTimeToGoalArea )( int areanum, vec3_t origin, int goalareanum, int travelflags ); + //-------------------------------------------- + // be_aas_move.c + //-------------------------------------------- + int ( *AAS_Swimming )( vec3_t origin ); + int ( *AAS_PredictClientMovement )( struct aas_clientmove_s *move, + int entnum, vec3_t origin, + int presencetype, int onground, + vec3_t velocity, vec3_t cmdmove, + int cmdframes, + int maxframes, float frametime, + int stopevent, int stopareanum, int visualize ); + + // Ridah, route-tables + //-------------------------------------------- + // be_aas_routetable.c + //-------------------------------------------- + void ( *AAS_RT_ShowRoute )( vec3_t srcpos, int srcnum, int destnum ); + qboolean ( *AAS_RT_GetHidePos )( vec3_t srcpos, int srcnum, int srcarea, vec3_t destpos, int destnum, int destarea, vec3_t returnPos ); + int ( *AAS_FindAttackSpotWithinRange )( int srcnum, int rangenum, int enemynum, float rangedist, int travelflags, float *outpos ); + qboolean ( *AAS_GetRouteFirstVisPos )( vec3_t srcpos, vec3_t destpos, int travelflags, vec3_t retpos ); + void ( *AAS_SetAASBlockingEntity )( vec3_t absmin, vec3_t absmax, qboolean blocking ); + // done. + + // Ridah + void ( *AAS_SetCurrentWorld )( int index ); + // done. + +} aas_export_t; + +typedef struct ea_export_s +{ + //ClientCommand elementary actions + void ( *EA_Say )( int client, char *str ); + void ( *EA_SayTeam )( int client, char *str ); + void ( *EA_UseItem )( int client, char *it ); + void ( *EA_DropItem )( int client, char *it ); + void ( *EA_UseInv )( int client, char *inv ); + void ( *EA_DropInv )( int client, char *inv ); + void ( *EA_Gesture )( int client ); + void ( *EA_Command )( int client, char *command ); + //regular elementary actions + void ( *EA_SelectWeapon )( int client, int weapon ); + void ( *EA_Talk )( int client ); + void ( *EA_Attack )( int client ); + void ( *EA_Reload )( int client ); + void ( *EA_Use )( int client ); + void ( *EA_Respawn )( int client ); + void ( *EA_Jump )( int client ); + void ( *EA_DelayedJump )( int client ); + void ( *EA_Crouch )( int client ); + void ( *EA_MoveUp )( int client ); + void ( *EA_MoveDown )( int client ); + void ( *EA_MoveForward )( int client ); + void ( *EA_MoveBack )( int client ); + void ( *EA_MoveLeft )( int client ); + void ( *EA_MoveRight )( int client ); + void ( *EA_Move )( int client, vec3_t dir, float speed ); + void ( *EA_View )( int client, vec3_t viewangles ); + //send regular input to the server + void ( *EA_EndRegular )( int client, float thinktime ); + void ( *EA_GetInput )( int client, float thinktime, bot_input_t *input ); + void ( *EA_ResetInput )( int client, bot_input_t *init ); +} ea_export_t; + +typedef struct ai_export_s +{ + //----------------------------------- + // be_ai_char.h + //----------------------------------- + int ( *BotLoadCharacter )( char *charfile, int skill ); + void ( *BotFreeCharacter )( int character ); + float ( *Characteristic_Float )( int character, int index ); + float ( *Characteristic_BFloat )( int character, int index, float min, float max ); + int ( *Characteristic_Integer )( int character, int index ); + int ( *Characteristic_BInteger )( int character, int index, int min, int max ); + void ( *Characteristic_String )( int character, int index, char *buf, int size ); + //----------------------------------- + // be_ai_chat.h + //----------------------------------- + int ( *BotAllocChatState )( void ); + void ( *BotFreeChatState )( int handle ); + void ( *BotQueueConsoleMessage )( int chatstate, int type, char *message ); + void ( *BotRemoveConsoleMessage )( int chatstate, int handle ); + int ( *BotNextConsoleMessage )( int chatstate, struct bot_consolemessage_s *cm ); + int ( *BotNumConsoleMessages )( int chatstate ); + void ( *BotInitialChat )( int chatstate, char *type, int mcontext, char *var0, char *var1, char *var2, char *var3, char *var4, char *var5, char *var6, char *var7 ); + int ( *BotNumInitialChats )( int chatstate, char *type ); + int ( *BotReplyChat )( int chatstate, char *message, int mcontext, int vcontext, char *var0, char *var1, char *var2, char *var3, char *var4, char *var5, char *var6, char *var7 ); + int ( *BotChatLength )( int chatstate ); + void ( *BotEnterChat )( int chatstate, int client, int sendto ); + void ( *BotGetChatMessage )( int chatstate, char *buf, int size ); + int ( *StringContains )( char *str1, char *str2, int casesensitive ); + int ( *BotFindMatch )( char *str, struct bot_match_s *match, unsigned long int context ); + void ( *BotMatchVariable )( struct bot_match_s *match, int variable, char *buf, int size ); + void ( *UnifyWhiteSpaces )( char *string ); + void ( *BotReplaceSynonyms )( char *string, unsigned long int context ); + int ( *BotLoadChatFile )( int chatstate, char *chatfile, char *chatname ); + void ( *BotSetChatGender )( int chatstate, int gender ); + void ( *BotSetChatName )( int chatstate, char *name ); + //----------------------------------- + // be_ai_goal.h + //----------------------------------- + void ( *BotResetGoalState )( int goalstate ); + void ( *BotResetAvoidGoals )( int goalstate ); + void ( *BotRemoveFromAvoidGoals )( int goalstate, int number ); + void ( *BotPushGoal )( int goalstate, struct bot_goal_s *goal ); + void ( *BotPopGoal )( int goalstate ); + void ( *BotEmptyGoalStack )( int goalstate ); + void ( *BotDumpAvoidGoals )( int goalstate ); + void ( *BotDumpGoalStack )( int goalstate ); + void ( *BotGoalName )( int number, char *name, int size ); + int ( *BotGetTopGoal )( int goalstate, struct bot_goal_s *goal ); + int ( *BotGetSecondGoal )( int goalstate, struct bot_goal_s *goal ); + int ( *BotChooseLTGItem )( int goalstate, vec3_t origin, int *inventory, int travelflags ); + int ( *BotChooseNBGItem )( int goalstate, vec3_t origin, int *inventory, int travelflags, + struct bot_goal_s *ltg, float maxtime ); + int ( *BotTouchingGoal )( vec3_t origin, struct bot_goal_s *goal ); + int ( *BotItemGoalInVisButNotVisible )( int viewer, vec3_t eye, vec3_t viewangles, struct bot_goal_s *goal ); + int ( *BotGetLevelItemGoal )( int index, char *classname, struct bot_goal_s *goal ); + int ( *BotGetNextCampSpotGoal )( int num, struct bot_goal_s *goal ); + int ( *BotGetMapLocationGoal )( char *name, struct bot_goal_s *goal ); + float ( *BotAvoidGoalTime )( int goalstate, int number ); + void ( *BotInitLevelItems )( void ); + void ( *BotUpdateEntityItems )( void ); + int ( *BotLoadItemWeights )( int goalstate, char *filename ); + void ( *BotFreeItemWeights )( int goalstate ); + void ( *BotInterbreedGoalFuzzyLogic )( int parent1, int parent2, int child ); + void ( *BotSaveGoalFuzzyLogic )( int goalstate, char *filename ); + void ( *BotMutateGoalFuzzyLogic )( int goalstate, float range ); + int ( *BotAllocGoalState )( int client ); + void ( *BotFreeGoalState )( int handle ); + //----------------------------------- + // be_ai_move.h + //----------------------------------- + void ( *BotResetMoveState )( int movestate ); + void ( *BotMoveToGoal )( struct bot_moveresult_s *result, int movestate, struct bot_goal_s *goal, int travelflags ); + int ( *BotMoveInDirection )( int movestate, vec3_t dir, float speed, int type ); + void ( *BotResetAvoidReach )( int movestate ); + void ( *BotResetLastAvoidReach )( int movestate ); + int ( *BotReachabilityArea )( vec3_t origin, int testground ); + int ( *BotMovementViewTarget )( int movestate, struct bot_goal_s *goal, int travelflags, float lookahead, vec3_t target ); + int ( *BotPredictVisiblePosition )( vec3_t origin, int areanum, struct bot_goal_s *goal, int travelflags, vec3_t target ); + int ( *BotAllocMoveState )( void ); + void ( *BotFreeMoveState )( int handle ); + void ( *BotInitMoveState )( int handle, struct bot_initmove_s *initmove ); + // Ridah + void ( *BotInitAvoidReach )( int handle ); + // done. + //----------------------------------- + // be_ai_weap.h + //----------------------------------- + int ( *BotChooseBestFightWeapon )( int weaponstate, int *inventory ); + void ( *BotGetWeaponInfo )( int weaponstate, int weapon, struct weaponinfo_s *weaponinfo ); + int ( *BotLoadWeaponWeights )( int weaponstate, char *filename ); + int ( *BotAllocWeaponState )( void ); + void ( *BotFreeWeaponState )( int weaponstate ); + void ( *BotResetWeaponState )( int weaponstate ); + //----------------------------------- + // be_ai_gen.h + //----------------------------------- + int ( *GeneticParentsAndChildSelection )( int numranks, float *ranks, int *parent1, int *parent2, int *child ); +} ai_export_t; + +//bot AI library imported functions +typedef struct botlib_export_s +{ + //Area Awareness System functions + aas_export_t aas; + //Elementary Action functions + ea_export_t ea; + //AI functions + ai_export_t ai; + //setup the bot library, returns BLERR_ + int ( *BotLibSetup )( void ); + //shutdown the bot library, returns BLERR_ + int ( *BotLibShutdown )( void ); + //sets a library variable returns BLERR_ + int ( *BotLibVarSet )( char *var_name, char *value ); + //gets a library variable returns BLERR_ + int ( *BotLibVarGet )( char *var_name, char *value, int size ); + + //sets a C-like define returns BLERR_ + int ( *PC_AddGlobalDefine )( char *string ); + int ( *PC_LoadSourceHandle )( const char *filename ); + int ( *PC_FreeSourceHandle )( int handle ); + int ( *PC_ReadTokenHandle )( int handle, pc_token_t *pc_token ); + int ( *PC_SourceFileAndLine )( int handle, char *filename, int *line ); + + //start a frame in the bot library + int ( *BotLibStartFrame )( float time ); + //load a new map in the bot library + int ( *BotLibLoadMap )( const char *mapname ); + //entity updates + int ( *BotLibUpdateEntity )( int ent, bot_entitystate_t *state ); + //just for testing + int ( *Test )( int parm0, char *parm1, vec3_t parm2, vec3_t parm3 ); +} botlib_export_t; + +//linking of bot library +botlib_export_t *GetBotLibAPI( int apiVersion, botlib_import_t *import ); + +/* Library variables: + +name: default: module(s): description: + +"basedir" "" l_utils.c Quake2 base directory +"gamedir" "" l_utils.c Quake2 game directory +"cddir" "" l_utils.c Quake2 CD directory + +"autolaunchbspc" "0" be_aas_load.c automatically launch (Win)BSPC +"log" "0" l_log.c enable/disable creating a log file +"maxclients" "4" be_interface.c maximum number of clients +"maxentities" "1024" be_interface.c maximum number of entities + +"sv_friction" "6" be_aas_move.c ground friction +"sv_stopspeed" "100" be_aas_move.c stop speed +"sv_gravity" "800" be_aas_move.c gravity value +"sv_waterfriction" "1" be_aas_move.c water friction +"sv_watergravity" "400" be_aas_move.c gravity in water +"sv_maxvelocity" "300" be_aas_move.c maximum velocity +"sv_maxwalkvelocity" "300" be_aas_move.c maximum walk velocity +"sv_maxcrouchvelocity" "100" be_aas_move.c maximum crouch velocity +"sv_maxswimvelocity" "150" be_aas_move.c maximum swim velocity +"sv_walkaccelerate" "10" be_aas_move.c walk acceleration +"sv_airaccelerate" "1" be_aas_move.c air acceleration +"sv_swimaccelerate" "4" be_aas_move.c swim acceleration +"sv_maxstep" "18" be_aas_move.c maximum step height +"sv_maxbarrier" "32" be_aas_move.c maximum barrier height +"sv_maxsteepness" "0.7" be_aas_move.c maximum floor steepness +"sv_jumpvel" "270" be_aas_move.c jump z velocity +"sv_maxwaterjump" "20" be_aas_move.c maximum waterjump height + +"max_aaslinks" "4096" be_aas_sample.c maximum links in the AAS +"max_bsplinks" "4096" be_aas_bsp.c maximum links in the BSP + +"notspawnflags" "2048" be_ai_goal.c entities with these spawnflags will be removed +"itemconfig" "items.c" be_ai_goal.c item configuration file +"weaponconfig" "weapons.c" be_ai_weap.c weapon configuration file +"synfile" "syn.c" be_ai_chat.c file with synonyms +"rndfile" "rnd.c" be_ai_chat.c file with random strings +"matchfile" "match.c" be_ai_chat.c file with match strings +"max_messages" "1024" be_ai_chat.c console message heap size +"max_weaponinfo" "32" be_ai_weap.c maximum number of weapon info +"max_projectileinfo" "32" be_ai_weap.c maximum number of projectile info +"max_iteminfo" "256" be_ai_goal.c maximum number of item info +"max_levelitems" "256" be_ai_goal.c maximum number of level items +"framereachability" "" be_aas_reach.c number of reachabilities to calucate per frame +"forceclustering" "0" be_aas_main.c force recalculation of clusters +"forcereachability" "0" be_aas_main.c force recalculation of reachabilities +"forcewrite" "0" be_aas_main.c force writing of aas file +"nooptimize" "0" be_aas_main.c no aas optimization + +"laserhook" "0" be_ai_move.c 0 = CTF hook, 1 = laser hook + +*/ + diff --git a/Projects/Android/jni/rtcw/src/extractfuncs/out/src/game/q_shared.h b/Projects/Android/jni/rtcw/src/extractfuncs/out/src/game/q_shared.h new file mode 100644 index 0000000..a87e2b3 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/extractfuncs/out/src/game/q_shared.h @@ -0,0 +1,1544 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +#ifndef __Q_SHARED_H +#define __Q_SHARED_H + +// q_shared.h -- included first by ALL program modules. +// A user mod should never modify this file + +#define Q3_VERSION "Wolf 1.41" +// ver 1.0.0 - release +// ver 1.0.1 - post-release work +// ver 1.1.0 - patch 1 (12/12/01) +// ver 1.1b - TTimo SP linux release (+ MP update) +// ver 1.2.b5 - Mac code merge in +// ver 1.3 - patch 2 (02/13/02) + +#define NEW_ANIMS +#define MAX_TEAMNAME 32 + +#ifdef _WIN32 + +#pragma warning(disable : 4018) // signed/unsigned mismatch +#pragma warning(disable : 4032) +#pragma warning(disable : 4051) +#pragma warning(disable : 4057) // slightly different base types +#pragma warning(disable : 4100) // unreferenced formal parameter +#pragma warning(disable : 4115) +#pragma warning(disable : 4125) // decimal digit terminates octal escape sequence +#pragma warning(disable : 4127) // conditional expression is constant +#pragma warning(disable : 4136) +#pragma warning(disable : 4152) // nonstandard extension, function/data pointer conversion in expression +#pragma warning(disable : 4201) +#pragma warning(disable : 4214) +#pragma warning(disable : 4244) +//#pragma warning(disable : 4142) // benign redefinition +#pragma warning(disable : 4305) // truncation from const double to float +//#pragma warning(disable : 4310) // cast truncates constant value +//#pragma warning(disable : 4505) // unreferenced local function has been removed +#pragma warning(disable : 4514) +#pragma warning(disable : 4702) // unreachable code +#pragma warning(disable : 4711) // selected for automatic inline expansion +#pragma warning(disable : 4220) // varargs matches remaining parameters +#endif + +#if defined( ppc ) || defined( __ppc ) || defined( __ppc__ ) || defined( __POWERPC__ ) +#define idppc 1 +#endif + +/********************************************************************** + VM Considerations + + The VM can not use the standard system headers because we aren't really + using the compiler they were meant for. We use bg_lib.h which contains + prototypes for the functions we define for our own use in bg_lib.c. + + When writing mods, please add needed headers HERE, do not start including + stuff like in the various .c files that make up each of the VMs + since you will be including system headers files can will have issues. + + Remember, if you use a C library function that is not defined in bg_lib.c, + you will have to add your own version for support in the VM. + + **********************************************************************/ + +#ifdef Q3_VM + +#include "bg_lib.h" + +#else + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#endif + +#ifdef _WIN32 + +//#pragma intrinsic( memset, memcpy ) + +#endif + + +// this is the define for determining if we have an asm version of a C function +#if ( defined _M_IX86 || defined __i386__ ) && !defined __sun__ && !defined __LCC__ +#define id386 1 +#else +#define id386 0 +#endif + +// for windows fastcall option + +#define QDECL + +//======================= WIN32 DEFINES ================================= + +#ifdef WIN32 + +#define MAC_STATIC + +#undef QDECL +#define QDECL __cdecl + +// buildstring will be incorporated into the version string +#ifdef NDEBUG +#ifdef _M_IX86 +#define CPUSTRING "win-x86" +#elif defined _M_ALPHA +#define CPUSTRING "win-AXP" +#endif +#else +#ifdef _M_IX86 +#define CPUSTRING "win-x86-debug" +#elif defined _M_ALPHA +#define CPUSTRING "win-AXP-debug" +#endif +#endif + + +#define PATH_SEP '\\' + +#endif + +//======================= MAC OS X SERVER DEFINES ===================== + +#if defined( __MACH__ ) && defined( __APPLE__ ) + +#define MAC_STATIC + +#ifdef __ppc__ +#define CPUSTRING "MacOSXS-ppc" +#elif defined __i386__ +#define CPUSTRING "MacOSXS-i386" +#else +#define CPUSTRING "MacOSXS-other" +#endif + +#define PATH_SEP '/' + +#define GAME_HARD_LINKED +#define CGAME_HARD_LINKED +#define UI_HARD_LINKED +#define BOTLIB_HARD_LINKED + +#endif + +//======================= MAC DEFINES ================================= + +#ifdef __MACOS__ + +#include +//DAJ #define MAC_STATIC static +#define MAC_STATIC + +#define CPUSTRING "MacOS-PPC" + +#define PATH_SEP ':' + +#define GAME_HARD_LINKED +#define CGAME_HARD_LINKED +#define UI_HARD_LINKED +#define BOTLIB_HARD_LINKED + +void Sys_PumpEvents( void ); + +#endif + +//======================= LINUX DEFINES ================================= + +// the mac compiler can't handle >32k of locals, so we +// just waste space and make big arrays static... +#ifdef __linux__ + +#define MAC_STATIC + +#ifdef __i386__ +#define CPUSTRING "linux-i386" +#elif defined __axp__ +#define CPUSTRING "linux-alpha" +#elif defined ARM +#define CPUSTRING "linux-arm" +#else +#define CPUSTRING "linux-other" +#endif + +#define PATH_SEP '/' + +#endif + +//============================================================= + + +typedef unsigned char byte; + +typedef enum {qfalse, qtrue} qboolean; +#if defined( __MACOS__ ) +#define qboolean int //DAJ +#endif + +typedef int qhandle_t; +typedef int sfxHandle_t; +typedef int fileHandle_t; +typedef int clipHandle_t; + +#ifndef ID_INLINE +#ifdef _WIN32 +#define ID_INLINE __inline +#else +#define ID_INLINE inline +#endif +#endif + +//#define SND_NORMAL 0x000 // (default) Allow sound to be cut off only by the same sound on this channel +#define SND_OKTOCUT 0x001 // Allow sound to be cut off by any following sounds on this channel +#define SND_REQUESTCUT 0x002 // Allow sound to be cut off by following sounds on this channel only for sounds who request cutoff +#define SND_CUTOFF 0x004 // Cut off sounds on this channel that are marked 'SND_REQUESTCUT' +#define SND_CUTOFF_ALL 0x008 // Cut off all sounds on this channel +#define SND_NOCUT 0x010 // Don't cut off. Always let finish (overridden by SND_CUTOFF_ALL) + + +#ifndef NULL +#define NULL ( (void *)0 ) +#endif + +#define MAX_QINT 0x7fffffff +#define MIN_QINT ( -MAX_QINT - 1 ) + + +#ifndef max +#define max( x, y ) ( ( ( x ) > ( y ) ) ? ( x ) : ( y ) ) +#define min( x, y ) ( ( ( x ) < ( y ) ) ? ( x ) : ( y ) ) +#endif + +// angle indexes +#define PITCH 0 // up / down +#define YAW 1 // left / right +#define ROLL 2 // fall over + +// RF, this is just here so different elements of the engine can be aware of this setting as it changes +#define MAX_SP_CLIENTS 64 // increasing this will increase memory usage significantly + +// the game guarantees that no string from the network will ever +// exceed MAX_STRING_CHARS +#define MAX_STRING_CHARS 1024 // max length of a string passed to Cmd_TokenizeString +#define MAX_STRING_TOKENS 256 // max tokens resulting from Cmd_TokenizeString +#define MAX_TOKEN_CHARS 1024 // max length of an individual token + +#define MAX_INFO_STRING 1024 +#define MAX_INFO_KEY 1024 +#define MAX_INFO_VALUE 1024 + +#define BIG_INFO_STRING 8192 // used for system info key only +#define BIG_INFO_KEY 8192 +#define BIG_INFO_VALUE 8192 + +#define MAX_QPATH 64 // max length of a quake game pathname +#define MAX_OSPATH 256 // max length of a filesystem pathname + +#define MAX_NAME_LENGTH 32 // max length of a client name + +#define MAX_SAY_TEXT 150 + +// paramters for command buffer stuffing +typedef enum { + EXEC_NOW, // don't return until completed, a VM should NEVER use this, + // because some commands might cause the VM to be unloaded... + EXEC_INSERT, // insert at current position, but don't run yet + EXEC_APPEND // add to end of the command buffer (normal case) +} cbufExec_t; + + +// +// these aren't needed by any of the VMs. put in another header? +// +#define MAX_MAP_AREA_BYTES 32 // bit vector of area visibility + + +// print levels from renderer (FIXME: set up for game / cgame?) +typedef enum { + PRINT_ALL, + PRINT_DEVELOPER, // only print when "developer 1" + PRINT_WARNING, + PRINT_ERROR +} printParm_t; + +#ifdef ERR_FATAL +#undef ERR_FATAL // this is be defined in malloc.h +#endif + +// parameters to the main Error routine +typedef enum { + ERR_FATAL, // exit the entire game with a popup window + ERR_DROP, // print to console and disconnect from game + ERR_SERVERDISCONNECT, // don't kill server + ERR_DISCONNECT, // client disconnected from the server + ERR_NEED_CD, // pop up the need-cd dialog + ERR_ENDGAME // not an error. just clean up properly, exit to the menu, and start up the "endgame" menu //----(SA) added +} errorParm_t; + + +// font rendering values used by ui and cgame + +#define PROP_GAP_WIDTH 3 +#define PROP_SPACE_WIDTH 8 +#define PROP_HEIGHT 27 +#define PROP_SMALL_SIZE_SCALE 0.75f + +#define BLINK_DIVISOR 200 +#define PULSE_DIVISOR 75 + +#define UI_LEFT 0x00000000 // default +#define UI_CENTER 0x00000001 +#define UI_RIGHT 0x00000002 +#define UI_FORMATMASK 0x00000007 +#define UI_SMALLFONT 0x00000010 +#define UI_BIGFONT 0x00000020 // default +#define UI_GIANTFONT 0x00000040 +#define UI_DROPSHADOW 0x00000800 +#define UI_BLINK 0x00001000 +#define UI_INVERSE 0x00002000 +#define UI_PULSE 0x00004000 +// JOSEPH 10-24-99 +#define UI_MENULEFT 0x00008000 +#define UI_MENURIGHT 0x00010000 +#define UI_EXSMALLFONT 0x00020000 +#define UI_MENUFULL 0x00080000 +// END JOSEPH + +#define UI_SMALLFONT75 0x00100000 + +#if defined( _DEBUG ) && !defined( BSPC ) + #define HUNK_DEBUG +#endif + +typedef enum { + h_high, + h_low, + h_dontcare +} ha_pref; + +#ifdef HUNK_DEBUG +#define Hunk_Alloc( size, preference ) Hunk_AllocDebug( size, preference, # size, __FILE__, __LINE__ ) +void *Hunk_AllocDebug( int size, ha_pref preference, char *label, char *file, int line ); +#else +void *Hunk_Alloc( int size, ha_pref preference ); +#endif + +void Com_Memset( void* dest, const int val, const size_t count ); +void Com_Memcpy( void* dest, const void* src, const size_t count ); + +#define CIN_system 0x01 +#define CIN_loop 0x02 +#define CIN_hold 0x04 +#define CIN_silent 0x08 +#define CIN_shader 0x10 +#define CIN_letterBox 0x20 + + +/* +============================================================== + +MATHLIB + +============================================================== +*/ + + +typedef float vec_t; +typedef vec_t vec2_t[2]; +typedef vec_t vec3_t[3]; +typedef vec_t vec4_t[4]; +typedef vec_t vec5_t[5]; + +typedef int fixed4_t; +typedef int fixed8_t; +typedef int fixed16_t; + +#ifndef M_PI +#define M_PI 3.14159265358979323846f // matches value in gcc v2 math.h +#endif + +#define NUMVERTEXNORMALS 162 +extern vec3_t bytedirs[NUMVERTEXNORMALS]; + +// all drawing is done to a 640*480 virtual screen size +// and will be automatically scaled to the real resolution +#define SCREEN_WIDTH 640 +#define SCREEN_HEIGHT 480 + +#define TINYCHAR_WIDTH ( SMALLCHAR_WIDTH ) +#define TINYCHAR_HEIGHT ( SMALLCHAR_HEIGHT / 2 ) + +#define SMALLCHAR_WIDTH 8 +#define SMALLCHAR_HEIGHT 16 + +#define BIGCHAR_WIDTH 16 +#define BIGCHAR_HEIGHT 16 + +#define GIANTCHAR_WIDTH 32 +#define GIANTCHAR_HEIGHT 48 + +extern vec4_t colorBlack; +extern vec4_t colorRed; +extern vec4_t colorGreen; +extern vec4_t colorBlue; +extern vec4_t colorYellow; +extern vec4_t colorMagenta; +extern vec4_t colorCyan; +extern vec4_t colorWhite; +extern vec4_t colorLtGrey; +extern vec4_t colorMdGrey; +extern vec4_t colorDkGrey; + +#define Q_COLOR_ESCAPE '^' +#define Q_IsColorString( p ) ( p && *( p ) == Q_COLOR_ESCAPE && *( ( p ) + 1 ) && *( ( p ) + 1 ) != Q_COLOR_ESCAPE ) + +#define COLOR_BLACK '0' +#define COLOR_RED '1' +#define COLOR_GREEN '2' +#define COLOR_YELLOW '3' +#define COLOR_BLUE '4' +#define COLOR_CYAN '5' +#define COLOR_MAGENTA '6' +#define COLOR_WHITE '7' +#define ColorIndex( c ) ( ( ( c ) - '0' ) & 7 ) + +#define S_COLOR_BLACK "^0" +#define S_COLOR_RED "^1" +#define S_COLOR_GREEN "^2" +#define S_COLOR_YELLOW "^3" +#define S_COLOR_BLUE "^4" +#define S_COLOR_CYAN "^5" +#define S_COLOR_MAGENTA "^6" +#define S_COLOR_WHITE "^7" + +extern vec4_t g_color_table[8]; + +#define MAKERGB( v, r, g, b ) v[0] = r; v[1] = g; v[2] = b +#define MAKERGBA( v, r, g, b, a ) v[0] = r; v[1] = g; v[2] = b; v[3] = a + +#define DEG2RAD( a ) ( ( ( a ) * M_PI ) / 180.0F ) +#define RAD2DEG( a ) ( ( ( a ) * 180.0f ) / M_PI ) + +struct cplane_s; + +extern vec3_t vec3_origin; +extern vec3_t axisDefault[3]; + +#define nanmask ( 255 << 23 ) +#define IS_NAN( x ) ( ( ( *(int *)&x ) & nanmask ) == nanmask ) + +// TTimo +// handy stuff when tracking isnan problems +#ifndef NDEBUG +#define CHECK_NAN( x ) assert( !IS_NAN( x ) ) +#define CHECK_NAN_VEC( v ) assert( !IS_NAN( v[0] ) && !IS_NAN( v[1] ) && !IS_NAN( v[2] ) ) +#else +#define CHECK_NAN +#define CHECK_NAN_VEC +#endif + +float Q_fabs( float f ); +float Q_rsqrt( float f ); // reciprocal square root + +#define SQRTFAST( x ) ( 1.0f / Q_rsqrt( x ) ) + +signed char ClampChar( int i ); +signed short ClampShort( int i ); + +// this isn't a real cheap function to call! +int DirToByte( vec3_t dir ); +void ByteToDir( int b, vec3_t dir ); + +#if 1 + +#define DotProduct( x,y ) ( ( x )[0] * ( y )[0] + ( x )[1] * ( y )[1] + ( x )[2] * ( y )[2] ) +#define VectorSubtract( a,b,c ) ( ( c )[0] = ( a )[0] - ( b )[0],( c )[1] = ( a )[1] - ( b )[1],( c )[2] = ( a )[2] - ( b )[2] ) +#define VectorAdd( a,b,c ) ( ( c )[0] = ( a )[0] + ( b )[0],( c )[1] = ( a )[1] + ( b )[1],( c )[2] = ( a )[2] + ( b )[2] ) +#define VectorCopy( a,b ) ( ( b )[0] = ( a )[0],( b )[1] = ( a )[1],( b )[2] = ( a )[2] ) +#define VectorCopy4( a,b ) ( ( b )[0] = ( a )[0],( b )[1] = ( a )[1],( b )[2] = ( a )[2],( b )[3] = ( a )[3] ) +#define VectorScale( v, s, o ) ( ( o )[0] = ( v )[0] * ( s ),( o )[1] = ( v )[1] * ( s ),( o )[2] = ( v )[2] * ( s ) ) +#define VectorMA( v, s, b, o ) ( ( o )[0] = ( v )[0] + ( b )[0] * ( s ),( o )[1] = ( v )[1] + ( b )[1] * ( s ),( o )[2] = ( v )[2] + ( b )[2] * ( s ) ) + +#else + +#define DotProduct( x,y ) _DotProduct( x,y ) +#define VectorSubtract( a,b,c ) _VectorSubtract( a,b,c ) +#define VectorAdd( a,b,c ) _VectorAdd( a,b,c ) +#define VectorCopy( a,b ) _VectorCopy( a,b ) +#define VectorScale( v, s, o ) _VectorScale( v,s,o ) +#define VectorMA( v, s, b, o ) _VectorMA( v,s,b,o ) + +#endif + +#ifdef __LCC__ +#ifdef VectorCopy +#undef VectorCopy +// this is a little hack to get more efficient copies in our interpreter +typedef struct { + float v[3]; +} vec3struct_t; +#define VectorCopy( a,b ) * (vec3struct_t *)b = *(vec3struct_t *)a; +#endif +#endif + +#define VectorClear( a ) ( ( a )[0] = ( a )[1] = ( a )[2] = 0 ) +#define VectorNegate( a,b ) ( ( b )[0] = -( a )[0],( b )[1] = -( a )[1],( b )[2] = -( a )[2] ) +#define VectorSet( v, x, y, z ) ( ( v )[0] = ( x ), ( v )[1] = ( y ), ( v )[2] = ( z ) ) + +#define Vector4Set( v, x, y, z, n ) ( ( v )[0] = ( x ),( v )[1] = ( y ),( v )[2] = ( z ),( v )[3] = ( n ) ) +#define Vector4Copy( a,b ) ( ( b )[0] = ( a )[0],( b )[1] = ( a )[1],( b )[2] = ( a )[2],( b )[3] = ( a )[3] ) +#define Vector4MA( v, s, b, o ) ( ( o )[0] = ( v )[0] + ( b )[0] * ( s ),( o )[1] = ( v )[1] + ( b )[1] * ( s ),( o )[2] = ( v )[2] + ( b )[2] * ( s ),( o )[3] = ( v )[3] + ( b )[3] * ( s ) ) +#define Vector4Average( v, b, s, o ) ( ( o )[0] = ( ( v )[0] * ( 1 - ( s ) ) ) + ( ( b )[0] * ( s ) ),( o )[1] = ( ( v )[1] * ( 1 - ( s ) ) ) + ( ( b )[1] * ( s ) ),( o )[2] = ( ( v )[2] * ( 1 - ( s ) ) ) + ( ( b )[2] * ( s ) ),( o )[3] = ( ( v )[3] * ( 1 - ( s ) ) ) + ( ( b )[3] * ( s ) ) ) + +#define SnapVector( v ) {v[0] = ( (int)( v[0] ) ); v[1] = ( (int)( v[1] ) ); v[2] = ( (int)( v[2] ) );} + +// just in case you do't want to use the macros +vec_t _DotProduct( const vec3_t v1, const vec3_t v2 ); +void _VectorSubtract( const vec3_t veca, const vec3_t vecb, vec3_t out ); +void _VectorAdd( const vec3_t veca, const vec3_t vecb, vec3_t out ); +void _VectorCopy( const vec3_t in, vec3_t out ); +void _VectorScale( const vec3_t in, float scale, vec3_t out ); +void _VectorMA( const vec3_t veca, float scale, const vec3_t vecb, vec3_t vecc ); + +unsigned ColorBytes3( float r, float g, float b ); +unsigned ColorBytes4( float r, float g, float b, float a ); + +float NormalizeColor( const vec3_t in, vec3_t out ); + +float RadiusFromBounds( const vec3_t mins, const vec3_t maxs ); +void ClearBounds( vec3_t mins, vec3_t maxs ); +void AddPointToBounds( const vec3_t v, vec3_t mins, vec3_t maxs ); +int VectorCompare( const vec3_t v1, const vec3_t v2 ); +vec_t VectorLength( const vec3_t v ); +vec_t VectorLengthSquared( const vec3_t v ); +vec_t Distance( const vec3_t p1, const vec3_t p2 ); +vec_t DistanceSquared( const vec3_t p1, const vec3_t p2 ); +void CrossProduct( const vec3_t v1, const vec3_t v2, vec3_t cross ); +vec_t VectorNormalize( vec3_t v ); // returns vector length +void VectorNormalizeFast( vec3_t v ); // does NOT return vector length, uses rsqrt approximation +vec_t VectorNormalize2( const vec3_t v, vec3_t out ); +void VectorInverse( vec3_t v ); +void Vector4Scale( const vec4_t in, vec_t scale, vec4_t out ); +void VectorRotate( vec3_t in, vec3_t matrix[3], vec3_t out ); +int Q_log2( int val ); + +float Q_acos( float c ); + +int Q_rand( int *seed ); +float Q_random( int *seed ); +float Q_crandom( int *seed ); + +#define random() ( ( rand() & 0x7fff ) / ( (float)0x7fff ) ) +#define crandom() ( 2.0 * ( random() - 0.5 ) ) + +void vectoangles( const vec3_t value1, vec3_t angles ); +float vectoyaw( const vec3_t vec ); +void AnglesToAxis( const vec3_t angles, vec3_t axis[3] ); +// TTimo: const vec_t ** would require explicit casts for ANSI C conformance +// see unix/const-arg.c +void AxisToAngles( /*const*/ vec3_t axis[3], vec3_t angles ); +float VectorDistance( vec3_t v1, vec3_t v2 ); + +void AxisClear( vec3_t axis[3] ); +void AxisCopy( vec3_t in[3], vec3_t out[3] ); + +void SetPlaneSignbits( struct cplane_s *out ); +int BoxOnPlaneSide( vec3_t emins, vec3_t emaxs, struct cplane_s *plane ); + +float AngleMod( float a ); +float LerpAngle( float from, float to, float frac ); +float AngleSubtract( float a1, float a2 ); +void AnglesSubtract( vec3_t v1, vec3_t v2, vec3_t v3 ); + +float AngleNormalize360( float angle ); +float AngleNormalize180( float angle ); +float AngleDelta( float angle1, float angle2 ); + +qboolean PlaneFromPoints( vec4_t plane, const vec3_t a, const vec3_t b, const vec3_t c ); +void ProjectPointOnPlane( vec3_t dst, const vec3_t p, const vec3_t normal ); +void RotatePointAroundVector( vec3_t dst, const vec3_t dir, const vec3_t point, float degrees ); +void RotateAroundDirection( vec3_t axis[3], float yaw ); +void MakeNormalVectors( const vec3_t forward, vec3_t right, vec3_t up ); +// perpendicular vector could be replaced by this + +int PlaneTypeForNormal( vec3_t normal ); + +void MatrixMultiply( float in1[3][3], float in2[3][3], float out[3][3] ); +void AngleVectors( const vec3_t angles, vec3_t forward, vec3_t right, vec3_t up ); +void PerpendicularVector( vec3_t dst, const vec3_t src ); + +// Ridah +void GetPerpendicularViewVector( const vec3_t point, const vec3_t p1, const vec3_t p2, vec3_t up ); +void ProjectPointOntoVector( vec3_t point, vec3_t vStart, vec3_t vEnd, vec3_t vProj ); +// done. + +//============================================= + +float Com_Clamp( float min, float max, float value ); + +char *COM_SkipPath( char *pathname ); +void COM_StripExtension( const char *in, char *out ); +void COM_StripFilename( char *in, char *out ); +void COM_DefaultExtension( char *path, int maxSize, const char *extension ); + +void COM_BeginParseSession( const char *name ); +void COM_RestoreParseSession( char **data_p ); +void COM_SetCurrentParseLine( int line ); +int COM_GetCurrentParseLine( void ); +char *COM_Parse( char **data_p ); +char *COM_ParseExt( char **data_p, qboolean allowLineBreak ); +int COM_Compress( char *data_p ); +void COM_ParseError( char *format, ... ); +void COM_ParseWarning( char *format, ... ); + +// TTimo +qboolean COM_BitCheck( const int array[], int bitNum ); +void COM_BitSet( int array[], int bitNum ); +void COM_BitClear( int array[], int bitNum ); + +#define MAX_TOKENLENGTH 1024 + +#ifndef TT_STRING +//token types +#define TT_STRING 1 // string +#define TT_LITERAL 2 // literal +#define TT_NUMBER 3 // number +#define TT_NAME 4 // name +#define TT_PUNCTUATION 5 // punctuation +#endif + +typedef struct pc_token_s +{ + int type; + int subtype; + int intvalue; + float floatvalue; + char string[MAX_TOKENLENGTH]; +} pc_token_t; + +// data is an in/out parm, returns a parsed out token + +void COM_MatchToken( char**buf_p, char *match ); + +void SkipBracedSection( char **program ); +void SkipRestOfLine( char **data ); + +void Parse1DMatrix( char **buf_p, int x, float *m ); +void Parse2DMatrix( char **buf_p, int y, int x, float *m ); +void Parse3DMatrix( char **buf_p, int z, int y, int x, float *m ); + +void QDECL Com_sprintf( char *dest, int size, const char *fmt, ... ); + + +// mode parm for FS_FOpenFile +typedef enum { + FS_READ, + FS_WRITE, + FS_APPEND, + FS_APPEND_SYNC +} fsMode_t; + +typedef enum { + FS_SEEK_CUR, + FS_SEEK_END, + FS_SEEK_SET +} fsOrigin_t; + +//============================================= + +int Q_isprint( int c ); +int Q_islower( int c ); +int Q_isupper( int c ); +int Q_isalpha( int c ); +int Q_isnumeric( int c ); //----(SA) added +int Q_isalphanumeric( int c ); //----(SA) added +int Q_isforfilename( int c ); //----(SA) added + +// portable case insensitive compare +int Q_stricmp( const char *s1, const char *s2 ); +int Q_strncmp( const char *s1, const char *s2, int n ); +int Q_stricmpn( const char *s1, const char *s2, int n ); +char *Q_strlwr( char *s1 ); +char *Q_strupr( char *s1 ); +char *Q_strrchr( const char* string, int c ); + +#ifdef _WIN32 +#define Q_putenv _putenv +#else +#define Q_putenv putenv +#endif + +// buffer size safe library replacements +void Q_strncpyz( char *dest, const char *src, int destsize ); +void Q_strcat( char *dest, int size, const char *src ); + +// strlen that discounts Quake color sequences +int Q_PrintStrlen( const char *string ); +// removes color sequences from string +char *Q_CleanStr( char *string ); +// Ridah +int Q_strncasecmp( char *s1, char *s2, int n ); +int Q_strcasecmp( char *s1, char *s2 ); +// done. +//============================================= + +// 64-bit integers for global rankings interface +// implemented as a struct for qvm compatibility +typedef struct +{ + byte b0; + byte b1; + byte b2; + byte b3; + byte b4; + byte b5; + byte b6; + byte b7; +} qint64; + +//============================================= + +short BigShort( short l ); +short LittleShort( short l ); +int BigLong( int l ); +int LittleLong( int l ); +qint64 BigLong64( qint64 l ); +qint64 LittleLong64( qint64 l ); +float BigFloat( float l ); +float LittleFloat( float l ); + +void Swap_Init( void ); +char * QDECL va( char *format, ... ); +float *tv( float x, float y, float z ); + +//============================================= + +// +// key / value info strings +// +char *Info_ValueForKey( const char *s, const char *key ); +void Info_RemoveKey( char *s, const char *key ); +void Info_RemoveKey_big( char *s, const char *key ); +void Info_SetValueForKey( char *s, const char *key, const char *value ); +void Info_SetValueForKey_Big( char *s, const char *key, const char *value ); +qboolean Info_Validate( const char *s ); +void Info_NextPair( const char **s, char *key, char *value ); + +// this is only here so the functions in q_shared.c and bg_*.c can link +void QDECL Com_Error( int level, const char *error, ... ); +void QDECL Com_Printf( const char *msg, ... ); + + +/* +============================================================== + +SAVE + + 12 - + 13 - (SA) added 'episode' tracking to savegame + 14 - RF added 'skill' + 15 - (SA) moved time info above the main game reading + 16 - (SA) added fog + 17 - (SA) rats, changed fog. + 18 - TTimo targetdeath fix + show_bug.cgi?id=434 + +============================================================== +*/ + +#define SAVE_VERSION 18 +#define SAVE_INFOSTRING_LENGTH 256 + + + +/* +========================================================== + + RELOAD STATES + +========================================================== +*/ + +#define RELOAD_SAVEGAME 0x01 +#define RELOAD_NEXTMAP 0x02 +#define RELOAD_NEXTMAP_WAITING 0x04 +#define RELOAD_FAILED 0x08 +#define RELOAD_ENDGAME 0x10 + + +/* +========================================================== + +CVARS (console variables) + +Many variables can be used for cheating purposes, so when +cheats is zero, force all unspecified variables to their +default values. +========================================================== +*/ + +#define CVAR_ARCHIVE 1 // set to cause it to be saved to vars.rc + // used for system variables, not for player + // specific configurations +#define CVAR_USERINFO 2 // sent to server on connect or change +#define CVAR_SERVERINFO 4 // sent in response to front end requests +#define CVAR_SYSTEMINFO 8 // these cvars will be duplicated on all clients +#define CVAR_INIT 16 // don't allow change from console at all, + // but can be set from the command line +#define CVAR_LATCH 32 // will only change when C code next does + // a Cvar_Get(), so it can't be changed + // without proper initialization. modified + // will be set, even though the value hasn't + // changed yet +#define CVAR_ROM 64 // display only, cannot be set by user at all +#define CVAR_USER_CREATED 128 // created by a set command +#define CVAR_TEMP 256 // can be set even when cheats are disabled, but is not archived +#define CVAR_CHEAT 512 // can not be changed if cheats are disabled +#define CVAR_NORESTART 1024 // do not clear when a cvar_restart is issued + +// nothing outside the Cvar_*() functions should modify these fields! +typedef struct cvar_s { + char *name; + char *string; + char *resetString; // cvar_restart will reset to this value + char *latchedString; // for CVAR_LATCH vars + int flags; + qboolean modified; // set each time the cvar is changed + int modificationCount; // incremented each time the cvar is changed + float value; // atof( string ) + int integer; // atoi( string ) + struct cvar_s *next; + struct cvar_s *hashNext; +} cvar_t; + +#define MAX_CVAR_VALUE_STRING 256 + +typedef int cvarHandle_t; + +// the modules that run in the virtual machine can't access the cvar_t directly, +// so they must ask for structured updates +typedef struct { + cvarHandle_t handle; + int modificationCount; + float value; + int integer; + char string[MAX_CVAR_VALUE_STRING]; +} vmCvar_t; + +/* +============================================================== + +COLLISION DETECTION + +============================================================== +*/ + +#include "surfaceflags.h" // shared with the q3map utility + +// plane types are used to speed some tests +// 0-2 are axial planes +#define PLANE_X 0 +#define PLANE_Y 1 +#define PLANE_Z 2 +#define PLANE_NON_AXIAL 3 + + +/* +================= +PlaneTypeForNormal +================= +*/ + +#define PlaneTypeForNormal( x ) ( x[0] == 1.0 ? PLANE_X : ( x[1] == 1.0 ? PLANE_Y : ( x[2] == 1.0 ? PLANE_Z : PLANE_NON_AXIAL ) ) ) + +// plane_t structure +// !!! if this is changed, it must be changed in asm code too !!! +typedef struct cplane_s { + vec3_t normal; + float dist; + byte type; // for fast side tests: 0,1,2 = axial, 3 = nonaxial + byte signbits; // signx + (signy<<1) + (signz<<2), used as lookup during collision + byte pad[2]; +} cplane_t; + + +// a trace is returned when a box is swept through the world +typedef struct { + qboolean allsolid; // if true, plane is not valid + qboolean startsolid; // if true, the initial point was in a solid area + float fraction; // time completed, 1.0 = didn't hit anything + vec3_t endpos; // final position + cplane_t plane; // surface normal at impact, transformed to world space + int surfaceFlags; // surface hit + int contents; // contents on other side of surface hit + int entityNum; // entity the contacted sirface is a part of +} trace_t; + +// trace->entityNum can also be 0 to (MAX_GENTITIES-1) +// or ENTITYNUM_NONE, ENTITYNUM_WORLD + + +// markfragments are returned by CM_MarkFragments() +typedef struct { + int firstPoint; + int numPoints; +} markFragment_t; + + + +typedef struct { + vec3_t origin; + vec3_t axis[3]; +} orientation_t; + +//===================================================================== + + +// in order from highest priority to lowest +// if none of the catchers are active, bound key strings will be executed +#define KEYCATCH_CONSOLE 0x0001 +#define KEYCATCH_UI 0x0002 +#define KEYCATCH_MESSAGE 0x0004 +#define KEYCATCH_CGAME 0x0008 + + +// sound channels +// channel 0 never willingly overrides +// other channels will allways override a playing sound on that channel +typedef enum { + CHAN_AUTO, + CHAN_LOCAL, // menu sounds, etc + CHAN_WEAPON, + CHAN_VOICE, + CHAN_ITEM, + CHAN_BODY, + CHAN_LOCAL_SOUND, // chat messages, etc + CHAN_ANNOUNCER // announcer voices, etc +} soundChannel_t; + + +/* +======================================================================== + + ELEMENTS COMMUNICATED ACROSS THE NET + +======================================================================== +*/ +#define ANIM_BITS 10 + +#define ANGLE2SHORT( x ) ( (int)( ( x ) * 65536 / 360 ) & 65535 ) +#define SHORT2ANGLE( x ) ( ( x ) * ( 360.0 / 65536 ) ) + +#define SNAPFLAG_RATE_DELAYED 1 +#define SNAPFLAG_NOT_ACTIVE 2 // snapshot used during connection and for zombies +#define SNAPFLAG_SERVERCOUNT 4 // toggled every map_restart so transitions can be detected + +// +// per-level limits +// +#define MAX_CLIENTS 128 // absolute limit +#define MAX_LOCATIONS 64 + +#define GENTITYNUM_BITS 10 // don't need to send any more +//#define GENTITYNUM_BITS 11 // don't need to send any more (SA) upped 4/21/2001 adjusted: tr_local.h (802-822), tr_main.c (1501), sv_snapshot (206) +#define MAX_GENTITIES ( 1 << GENTITYNUM_BITS ) + +// entitynums are communicated with GENTITY_BITS, so any reserved +// values thatare going to be communcated over the net need to +// also be in this range +#define ENTITYNUM_NONE ( MAX_GENTITIES - 1 ) +#define ENTITYNUM_WORLD ( MAX_GENTITIES - 2 ) +#define ENTITYNUM_MAX_NORMAL ( MAX_GENTITIES - 2 ) + + +#define MAX_MODELS 256 // these are sent over the net as 8 bits +#define MAX_SOUNDS 256 // so they cannot be blindly increased + + +#define MAX_PARTICLES_AREAS 128 + +#define MAX_MULTI_SPAWNTARGETS 16 // JPW NERVE + +//#define MAX_CONFIGSTRINGS 1024 +#define MAX_CONFIGSTRINGS 2048 + +#define MAX_DLIGHT_CONFIGSTRINGS 128 +#define MAX_CLIPBOARD_CONFIGSTRINGS 64 +#define MAX_SPLINE_CONFIGSTRINGS 64 + +#define PARTICLE_SNOW128 1 +#define PARTICLE_SNOW64 2 +#define PARTICLE_SNOW32 3 +#define PARTICLE_SNOW256 0 + +#define PARTICLE_BUBBLE8 4 +#define PARTICLE_BUBBLE16 5 +#define PARTICLE_BUBBLE32 6 +#define PARTICLE_BUBBLE64 7 + +// these are the only configstrings that the system reserves, all the +// other ones are strictly for servergame to clientgame communication +#define CS_SERVERINFO 0 // an info string with all the serverinfo cvars +#define CS_SYSTEMINFO 1 // an info string for server system to client system configuration (timescale, etc) + +#define RESERVED_CONFIGSTRINGS 2 // game can't modify below this, only the system can + +#define MAX_GAMESTATE_CHARS 16000 +typedef struct { + int stringOffsets[MAX_CONFIGSTRINGS]; + char stringData[MAX_GAMESTATE_CHARS]; + int dataCount; +} gameState_t; + +#define REF_FORCE_DLIGHT ( 1 << 31 ) // RF, passed in through overdraw parameter, force this dlight under all conditions +#define REF_JUNIOR_DLIGHT ( 1 << 30 ) // (SA) this dlight does not light surfaces. it only affects dynamic light grid + +//========================================================= +// shared by AI and animation scripting +// +typedef enum +{ + AISTATE_RELAXED, + AISTATE_QUERY, + AISTATE_ALERT, + AISTATE_COMBAT, + + MAX_AISTATES +} aistateEnum_t; + +//========================================================= + + +// weapon grouping +#define MAX_WEAP_BANKS 12 +#define MAX_WEAPS_IN_BANK 3 +// JPW NERVE +#define MAX_WEAPS_IN_BANK_MP 8 +#define MAX_WEAP_BANKS_MP 7 +// jpw +#define MAX_WEAP_ALTS WP_DYNAMITE + + +// bit field limits +#define MAX_STATS 16 +#define MAX_PERSISTANT 16 +#define MAX_POWERUPS 16 +#define MAX_WEAPONS 64 // (SA) and yet more! +#define MAX_HOLDABLE 16 + +// Ridah, increased this +//#define MAX_PS_EVENTS 2 +// ACK: I'd really like to make this 4, but that seems to cause network problems +#define MAX_EVENTS 4 // max events per frame before we drop events +//#define MAX_EVENTS 2 // max events per frame before we drop events + + +#define PS_PMOVEFRAMECOUNTBITS 6 + +// playerState_t is the information needed by both the client and server +// to predict player motion and actions +// nothing outside of pmove should modify these, or some degree of prediction error +// will occur + +// you can't add anything to this without modifying the code in msg.c + +// playerState_t is a full superset of entityState_t as it is used by players, +// so if a playerState_t is transmitted, the entityState_t can be fully derived +// from it. +// +// NOTE: all fields in here must be 32 bits (or those within sub-structures) +typedef struct playerState_s { + int commandTime; // cmd->serverTime of last executed command + int pm_type; + int bobCycle; // for view bobbing and footstep generation + int pm_flags; // ducked, jump_held, etc + int pm_time; + + vec3_t origin; + vec3_t velocity; + int weaponTime; + int weaponDelay; // for weapons that don't fire immediately when 'fire' is hit (grenades, venom, ...) + int grenadeTimeLeft; // for delayed grenade throwing. this is set to a #define for grenade + // lifetime when the attack button goes down, then when attack is released + // this is the amount of time left before the grenade goes off (or if it + // gets to 0 while in players hand, it explodes) + + + int gravity; + float leanf; // amount of 'lean' when player is looking around corner //----(SA) added + + int speed; + int delta_angles[3]; // add to command angles to get view direction + // changed by spawns, rotating objects, and teleporters + + int groundEntityNum; // ENTITYNUM_NONE = in air + + int legsTimer; // don't change low priority animations until this runs out + int legsAnim; // mask off ANIM_TOGGLEBIT + + int torsoTimer; // don't change low priority animations until this runs out + int torsoAnim; // mask off ANIM_TOGGLEBIT + + int movementDir; // a number 0 to 7 that represents the reletive angle + // of movement to the view angle (axial and diagonals) + // when at rest, the value will remain unchanged + // used to twist the legs during strafing + + + + int eFlags; // copied to entityState_t->eFlags + + int eventSequence; // pmove generated events + int events[MAX_EVENTS]; + int eventParms[MAX_EVENTS]; + int oldEventSequence; // so we can see which events have been added since we last converted to entityState_t + + int externalEvent; // events set on player from another source + int externalEventParm; + int externalEventTime; + + int clientNum; // ranges from 0 to MAX_CLIENTS-1 + + // weapon info + int weapon; // copied to entityState_t->weapon + int weaponstate; + + // item info + int item; + + vec3_t viewangles; // for fixed views + int viewheight; + + // damage feedback + int damageEvent; // when it changes, latch the other parms + int damageYaw; + int damagePitch; + int damageCount; + + int stats[MAX_STATS]; + int persistant[MAX_PERSISTANT]; // stats that aren't cleared on death + int powerups[MAX_POWERUPS]; // level.time that the powerup runs out + int ammo[MAX_WEAPONS]; // total amount of ammo + int ammoclip[MAX_WEAPONS]; // ammo in clip + int holdable[MAX_HOLDABLE]; + int holding; // the current item in holdable[] that is selected (held) + int weapons[MAX_WEAPONS / ( sizeof( int ) * 8 )]; // 64 bits for weapons held + + // Ridah, allow for individual bounding boxes + vec3_t mins, maxs; + float crouchMaxZ; + float crouchViewHeight, standViewHeight, deadViewHeight; + // variable movement speed + float runSpeedScale, sprintSpeedScale, crouchSpeedScale; + // done. + + // Ridah, view locking for mg42 + int viewlocked; + int viewlocked_entNum; + + // Ridah, need this to fix friction problems with slow zombie's whereby + // the friction prevents them from accelerating to their full potential + float friction; + + // Ridah, AI character id is used for weapon association + int aiChar; + int teamNum; + + // Rafael + int gunfx; + + // RF, burning effect is required for view blending effect + int onFireStart; + + int serverCursorHint; // what type of cursor hint the server is dictating + int serverCursorHintVal; // a value (0-255) associated with the above + + trace_t serverCursorHintTrace; // not communicated over net, but used to store the current server-side cursorhint trace + + // ---------------------------------------------------------------------- + // not communicated over the net at all + // FIXME: this doesn't get saved between predicted frames on the clients-side (cg.predictedPlayerState) + // So to use persistent variables here, which don't need to come from the server, + // we could use a marker variable, and use that to store everything after it + // before we read in the new values for the predictedPlayerState, then restore them + // after copying the structure recieved from the server. + + // (SA) yeah. this is causing me a little bit of trouble too. can we go ahead with the above suggestion or find an alternative? + + int ping; // server to game info for scoreboard + int pmove_framecount; // FIXME: don't transmit over the network + int entityEventSequence; + + int sprintTime; + int sprintExertTime; + + // JPW NERVE -- value for all multiplayer classes with regenerating "class weapons" -- ie LT artillery, medic medpack, engineer build points, etc + int classWeaponTime; + int jumpTime; // used in SP/MP to prevent jump accel + // jpw + + int weapAnimTimer; // don't change low priority animations until this runs out + int weapAnim; // mask off ANIM_TOGGLEBIT + + qboolean releasedFire; + + float aimSpreadScaleFloat; // (SA) the server-side aimspreadscale that lets it track finer changes but still only + // transmit the 8bit int to the client + int aimSpreadScale; // 0 - 255 increases with angular movement + int lastFireTime; // used by server to hold last firing frame briefly when randomly releasing trigger (AI) + + int quickGrenTime; + + int leanStopDebounceTime; + + int weapHeat[MAX_WEAPONS]; // some weapons can overheat. this tracks (server-side) how hot each weapon currently is. + int curWeapHeat; // value for the currently selected weapon (for transmission to client) + + int venomTime; + +//----(SA) added + int accShowBits; // RF (changed from short), these should all be 32 bit + int accHideBits; +//----(SA) end + + aistateEnum_t aiState; + + float footstepCount; + +} playerState_t; + + +//==================================================================== + + +// +// usercmd_t->button bits, many of which are generated by the client system, +// so they aren't game/cgame only definitions +// +#define BUTTON_ATTACK 1 +#define BUTTON_TALK 2 // displays talk balloon and disables actions +#define BUTTON_USE_HOLDABLE 4 +#define BUTTON_GESTURE 8 +#define BUTTON_WALKING 16 // walking can't just be infered from MOVE_RUN + // because a key pressed late in the frame will + // only generate a small move value for that frame + // walking will use different animations and + // won't generate footsteps +//----(SA) added +#define BUTTON_SPRINT 32 +#define BUTTON_ACTIVATE 64 +//----(SA) end + +#define BUTTON_ANY 128 // any key whatsoever + + + + +//----(SA) wolf buttons +#define WBUTTON_ATTACK2 1 +#define WBUTTON_ZOOM 2 +#define WBUTTON_QUICKGREN 4 +#define WBUTTON_RELOAD 8 +#define WBUTTON_LEANLEFT 16 +#define WBUTTON_LEANRIGHT 32 + +// unused +#define WBUTTON_EXTRA6 64 +#define WBUTTON_EXTRA7 128 +//----(SA) end + +#define MOVE_RUN 120 // if forwardmove or rightmove are >= MOVE_RUN, + // then BUTTON_WALKING should be set + + +// usercmd_t is sent to the server each client frame +typedef struct usercmd_s { + int serverTime; + byte buttons; + byte wbuttons; + byte weapon; + byte holdable; //----(SA) added + int angles[3]; + + + signed char forwardmove, rightmove, upmove; + signed char wolfkick; // RF, we should move this over to a wbutton, this is a huge waste of bandwidth + + unsigned short cld; // NERVE - SMF - send client damage in usercmd instead of as a server command +} usercmd_t; + +//=================================================================== + +// if entityState->solid == SOLID_BMODEL, modelindex is an inline model number +#define SOLID_BMODEL 0xffffff + +typedef enum { + TR_STATIONARY, + TR_INTERPOLATE, // non-parametric, but interpolate between snapshots + TR_LINEAR, + TR_LINEAR_STOP, + TR_LINEAR_STOP_BACK, //----(SA) added. so reverse movement can be different than forward + TR_SINE, // value = base + sin( time / duration ) * delta + TR_GRAVITY, + // Ridah + TR_GRAVITY_LOW, + TR_GRAVITY_FLOAT, // super low grav with no gravity acceleration (floating feathers/fabric/leaves/...) + TR_GRAVITY_PAUSED, //----(SA) has stopped, but will still do a short trace to see if it should be switched back to TR_GRAVITY + TR_ACCELERATE, + TR_DECCELERATE +} trType_t; + +typedef struct { + trType_t trType; + int trTime; + int trDuration; // if non 0, trTime + trDuration = stop time +//----(SA) removed + vec3_t trBase; + vec3_t trDelta; // velocity, etc +//----(SA) removed +} trajectory_t; + +// RF, put this here so we have a central means of defining a Zombie (kind of a hack, but this is to minimize bandwidth usage) +#define SET_FLAMING_ZOMBIE( x,y ) ( x.frame = y ) +#define IS_FLAMING_ZOMBIE( x ) ( x.frame == 1 ) + +// entityState_t is the information conveyed from the server +// in an update message about entities that the client will +// need to render in some way +// Different eTypes may use the information in different ways +// The messages are delta compressed, so it doesn't really matter if +// the structure size is fairly large +// +// NOTE: all fields in here must be 32 bits (or those within sub-structures) + +typedef struct entityState_s { + int number; // entity index + int eType; // entityType_t + int eFlags; + + trajectory_t pos; // for calculating position + trajectory_t apos; // for calculating angles + + int time; + int time2; + + vec3_t origin; + vec3_t origin2; + + vec3_t angles; + vec3_t angles2; + + int otherEntityNum; // shotgun sources, etc + int otherEntityNum2; + + int groundEntityNum; // -1 = in air + + int constantLight; // r + (g<<8) + (b<<16) + (intensity<<24) + int dl_intensity; // used for coronas + int loopSound; // constantly loop this sound + + int modelindex; + int modelindex2; + int clientNum; // 0 to (MAX_CLIENTS - 1), for players and corpses + int frame; + + int solid; // for client side prediction, trap_linkentity sets this properly + + // old style events, in for compatibility only + int event; + int eventParm; + + int eventSequence; // pmove generated events + int events[MAX_EVENTS]; + int eventParms[MAX_EVENTS]; + + // for players + int powerups; // bit flags + int weapon; // determines weapon and flash model, etc + int legsAnim; // mask off ANIM_TOGGLEBIT + int torsoAnim; // mask off ANIM_TOGGLEBIT +// int weapAnim; // mask off ANIM_TOGGLEBIT //----(SA) removed (weap anims will be client-side only) + + int density; // for particle effects + + int dmgFlags; // to pass along additional information for damage effects for players/ Also used for cursorhints for non-player entities + + // Ridah + int onFireStart, onFireEnd; + + int aiChar, teamNum; + + int effect1Time, effect2Time, effect3Time; + + aistateEnum_t aiState; + + int animMovetype; // clients can't derive movetype of other clients for anim scripting system + + +} entityState_t; + +typedef enum { + CA_UNINITIALIZED, + CA_DISCONNECTED, // not talking to a server + CA_AUTHORIZING, // not used any more, was checking cd key + CA_CONNECTING, // sending request packets to the server + CA_CHALLENGING, // sending challenge packets to the server + CA_CONNECTED, // netchan_t established, getting gamestate + CA_LOADING, // only during cgame initialization, never during main loop + CA_PRIMED, // got gamestate, waiting for first frame + CA_ACTIVE, // game views should be displayed + CA_CINEMATIC // playing a cinematic or a static pic, not connected to a server +} connstate_t; + +// font support + +#define GLYPH_START 0 +#define GLYPH_END 255 +#define GLYPH_CHARSTART 32 +#define GLYPH_CHAREND 127 +#define GLYPHS_PER_FONT GLYPH_END - GLYPH_START + 1 +typedef struct { + int height; // number of scan lines + int top; // top of glyph in buffer + int bottom; // bottom of glyph in buffer + int pitch; // width for copying + int xSkip; // x adjustment + int imageWidth; // width of actual image + int imageHeight; // height of actual image + float s; // x offset in image where glyph starts + float t; // y offset in image where glyph starts + float s2; + float t2; + qhandle_t glyph; // handle to the shader with the glyph + char shaderName[32]; +} glyphInfo_t; + +typedef struct { + glyphInfo_t glyphs [GLYPHS_PER_FONT]; + float glyphScale; + char name[MAX_QPATH]; +} fontInfo_t; + +#define Square( x ) ( ( x ) * ( x ) ) + +// real time +//============================================= + + +typedef struct qtime_s { + int tm_sec; /* seconds after the minute - [0,59] */ + int tm_min; /* minutes after the hour - [0,59] */ + int tm_hour; /* hours since midnight - [0,23] */ + int tm_mday; /* day of the month - [1,31] */ + int tm_mon; /* months since January - [0,11] */ + int tm_year; /* years since 1900 */ + int tm_wday; /* days since Sunday - [0,6] */ + int tm_yday; /* days since January 1 - [0,365] */ + int tm_isdst; /* daylight savings time flag */ +} qtime_t; + + +// server browser sources +#define AS_LOCAL 0 +#define AS_MPLAYER 1 +#define AS_GLOBAL 2 +#define AS_FAVORITES 3 + + +// cinematic states +typedef enum { + FMV_IDLE, + FMV_PLAY, // play + FMV_EOF, // all other conditions, i.e. stop/EOF/abort + FMV_ID_BLT, + FMV_ID_IDLE, + FMV_LOOPED, + FMV_ID_WAIT +} e_status; + +typedef enum _flag_status { + FLAG_ATBASE = 0, + FLAG_TAKEN, // CTF + FLAG_TAKEN_RED, // One Flag CTF + FLAG_TAKEN_BLUE, // One Flag CTF + FLAG_DROPPED +} flagStatus_t; + + + +#define MAX_GLOBAL_SERVERS 2048 +#define MAX_OTHER_SERVERS 128 +#define MAX_PINGREQUESTS 16 +#define MAX_SERVERSTATUSREQUESTS 16 + +#define SAY_ALL 0 +#define SAY_TEAM 1 +#define SAY_TELL 2 + +#define CDKEY_LEN 16 +#define CDCHKSUM_LEN 2 + +// NERVE - SMF - localization +typedef enum { + LANGUAGE_FRENCH = 0, + LANGUAGE_GERMAN, + LANGUAGE_ITALIAN, + LANGUAGE_SPANISH, + MAX_LANGUAGES +} languages_t; + +#endif // __Q_SHARED_H diff --git a/Projects/Android/jni/rtcw/src/extractfuncs/out/src/game/surfaceflags.h b/Projects/Android/jni/rtcw/src/extractfuncs/out/src/game/surfaceflags.h new file mode 100644 index 0000000..6a0d397 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/extractfuncs/out/src/game/surfaceflags.h @@ -0,0 +1,130 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +// This file must be identical in the quake and utils directories + + + + + + +// contents flags are seperate bits +// a given brush can contribute multiple content bits + +// these definitions also need to be in q_shared.h! + +#define CONTENTS_SOLID 1 // an eye is never valid in a solid + +#define CONTENTS_LIGHTGRID 4 //----(SA) added + +#define CONTENTS_LAVA 8 +#define CONTENTS_SLIME 16 +#define CONTENTS_WATER 32 +#define CONTENTS_FOG 64 + + +//----(SA) added +#define CONTENTS_MISSILECLIP 128 // 0x80 +#define CONTENTS_ITEM 256 // 0x100 +//----(SA) end + +// RF, AI sight/nosight & bullet/nobullet +#define CONTENTS_AI_NOSIGHT 0x1000 // AI cannot see through this +#define CONTENTS_CLIPSHOT 0x2000 // bullets hit this +// RF, end + +#define CONTENTS_MOVER 0x4000 +#define CONTENTS_AREAPORTAL 0x8000 + +#define CONTENTS_PLAYERCLIP 0x10000 +#define CONTENTS_MONSTERCLIP 0x20000 + +//bot specific contents types +#define CONTENTS_TELEPORTER 0x40000 +#define CONTENTS_JUMPPAD 0x80000 +#define CONTENTS_CLUSTERPORTAL 0x100000 +#define CONTENTS_DONOTENTER 0x200000 +#define CONTENTS_DONOTENTER_LARGE 0x400000 + +#define CONTENTS_ORIGIN 0x1000000 // removed before bsping an entity + +#define CONTENTS_BODY 0x2000000 // should never be on a brush, only in game +#define CONTENTS_CORPSE 0x4000000 +#define CONTENTS_DETAIL 0x8000000 // brushes not used for the bsp + +#define CONTENTS_STRUCTURAL 0x10000000 // brushes used for the bsp +#define CONTENTS_TRANSLUCENT 0x20000000 // don't consume surface fragments inside +#define CONTENTS_TRIGGER 0x40000000 +#define CONTENTS_NODROP 0x80000000 // don't leave bodies or items (death fog, lava)zz + +#define SURF_NODAMAGE 0x1 // never give falling damage +#define SURF_SLICK 0x2 // effects game physics +#define SURF_SKY 0x4 // lighting from environment map +#define SURF_LADDER 0x8 +#define SURF_NOIMPACT 0x10 // don't make missile explosions +#define SURF_NOMARKS 0x20 // don't leave missile marks +//#define SURF_FLESH 0x40 // make flesh sounds and effects +#define SURF_CERAMIC 0x40 // out of surf's, so replacing unused 'SURF_FLESH' +#define SURF_NODRAW 0x80 // don't generate a drawsurface at all +#define SURF_HINT 0x100 // make a primary bsp splitter +#define SURF_SKIP 0x200 // completely ignore, allowing non-closed brushes +#define SURF_NOLIGHTMAP 0x400 // surface doesn't need a lightmap +#define SURF_POINTLIGHT 0x800 // generate lighting info at vertexes +// JOSEPH 9-16-99 +#define SURF_METAL 0x1000 // clanking footsteps +// END JOSEPH +#define SURF_NOSTEPS 0x2000 // no footstep sounds +#define SURF_NONSOLID 0x4000 // don't collide against curves with this set +#define SURF_LIGHTFILTER 0x8000 // act as a light filter during q3map -light +#define SURF_ALPHASHADOW 0x10000 // do per-pixel light shadow casting in q3map +#define SURF_NODLIGHT 0x20000 // don't dlight even if solid (solid lava, skies) +// JOSEPH 9-16-99 +// Ridah, 11-01-99 (Q3 merge) +#define SURF_WOOD 0x40000 +#define SURF_GRASS 0x80000 +#define SURF_GRAVEL 0x100000 +// END JOSEPH + +// (SA) +//#define SURF_SMGROUP 0x200000 +#define SURF_GLASS 0x200000 // out of surf's, so replacing unused 'SURF_SMGROUP' +#define SURF_SNOW 0x400000 +#define SURF_ROOF 0x800000 + +//#define SURF_RUBBLE 0x1000000 // stole 'rubble' for +#define SURF_RUBBLE 0x1000000 +#define SURF_CARPET 0x2000000 + +#define SURF_MONSTERSLICK 0x4000000 // slick surf that only affects ai's +// #define SURF_DUST 0x8000000 // leave a dust trail when walking on this surface +#define SURF_MONSLICK_W 0x8000000 + +#define SURF_MONSLICK_N 0x10000000 +#define SURF_MONSLICK_E 0x20000000 +#define SURF_MONSLICK_S 0x40000000 + diff --git a/Projects/Android/jni/rtcw/src/extractfuncs/out/src/qcommon/unzip.h b/Projects/Android/jni/rtcw/src/extractfuncs/out/src/qcommon/unzip.h new file mode 100644 index 0000000..12277c9 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/extractfuncs/out/src/qcommon/unzip.h @@ -0,0 +1,341 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + + +#if defined( STRICTUNZIP ) || defined( STRICTZIPUNZIP ) +/* like the STRICT of WIN32, we define a pointer that cannot be converted + from (void*) without cast */ +typedef struct TagunzFile__ { int unused; } unzFile__; +typedef unzFile__ *unzFile; +#else +typedef void* unzFile; +#endif + +/* tm_unz contain date/time info */ +typedef struct tm_unz_s +{ + unsigned int tm_sec; /* seconds after the minute - [0,59] */ + unsigned int tm_min; /* minutes after the hour - [0,59] */ + unsigned int tm_hour; /* hours since midnight - [0,23] */ + unsigned int tm_mday; /* day of the month - [1,31] */ + unsigned int tm_mon; /* months since January - [0,11] */ + unsigned int tm_year; /* years - [1980..2044] */ +} tm_unz; + +/* unz_global_info structure contain global data about the ZIPfile + These data comes from the end of central dir */ +typedef struct unz_global_info_s +{ + unsigned long number_entry; /* total number of entries in the central dir on this disk */ + unsigned long size_comment; /* size of the global comment of the zipfile */ +} unz_global_info; + + +/* unz_file_info contain information about a file in the zipfile */ +typedef struct unz_file_info_s +{ + unsigned long version; /* version made by 2 unsigned chars */ + unsigned long version_needed; /* version needed to extract 2 unsigned chars */ + unsigned long flag; /* general purpose bit flag 2 unsigned chars */ + unsigned long compression_method; /* compression method 2 unsigned chars */ + unsigned long dosDate; /* last mod file date in Dos fmt 4 unsigned chars */ + unsigned long crc; /* crc-32 4 unsigned chars */ + unsigned long compressed_size; /* compressed size 4 unsigned chars */ + unsigned long uncompressed_size; /* uncompressed size 4 unsigned chars */ + unsigned long size_filename; /* filename length 2 unsigned chars */ + unsigned long size_file_extra; /* extra field length 2 unsigned chars */ + unsigned long size_file_comment; /* file comment length 2 unsigned chars */ + + unsigned long disk_num_start; /* disk number start 2 unsigned chars */ + unsigned long internal_fa; /* internal file attributes 2 unsigned chars */ + unsigned long external_fa; /* external file attributes 4 unsigned chars */ + + tm_unz tmu_date; +} unz_file_info; + +/* unz_file_info_interntal contain internal info about a file in zipfile*/ +typedef struct unz_file_info_internal_s +{ + unsigned long offset_curfile; /* relative offset of static header 4 unsigned chars */ +} unz_file_info_internal; + +typedef void* ( *alloc_func )( void* opaque, unsigned int items, unsigned int size ); +typedef void ( *free_func )( void* opaque, void* address ); + +struct internal_state; + +typedef struct z_stream_s { + unsigned char *next_in; /* next input unsigned char */ + unsigned int avail_in; /* number of unsigned chars available at next_in */ + unsigned long total_in; /* total nb of input unsigned chars read so */ + + unsigned char *next_out; /* next output unsigned char should be put there */ + unsigned int avail_out; /* remaining free space at next_out */ + unsigned long total_out; /* total nb of unsigned chars output so */ + + char *msg; /* last error message, NULL if no error */ + struct internal_state *state; /* not visible by applications */ + + alloc_func zalloc; /* used to allocate the internal state */ + free_func zfree; /* used to free the internal state */ + unsigned char* opaque; /* private data object passed to zalloc and zfree */ + + int data_type; /* best guess about the data type: ascii or binary */ + unsigned long adler; /* adler32 value of the uncompressed data */ + unsigned long reserved; /* reserved for future use */ +} z_stream; + +typedef z_stream *z_streamp; + + +/* file_in_zip_read_info_s contain internal information about a file in zipfile, + when reading and decompress it */ +typedef struct +{ + char *read_buffer; /* internal buffer for compressed data */ + z_stream stream; /* zLib stream structure for inflate */ + + unsigned long pos_in_zipfile; /* position in unsigned char on the zipfile, for fseek*/ + unsigned long stream_initialised; /* flag set if stream structure is initialised*/ + + unsigned long offset_local_extrafield; /* offset of the static extra field */ + unsigned int size_local_extrafield; /* size of the static extra field */ + unsigned long pos_local_extrafield; /* position in the static extra field in read*/ + + unsigned long crc32; /* crc32 of all data uncompressed */ + unsigned long crc32_wait; /* crc32 we must obtain after decompress all */ + unsigned long rest_read_compressed; /* number of unsigned char to be decompressed */ + unsigned long rest_read_uncompressed; /*number of unsigned char to be obtained after decomp*/ + FILE* file; /* io structore of the zipfile */ + unsigned long compression_method; /* compression method (0==store) */ + unsigned long byte_before_the_zipfile; /* unsigned char before the zipfile, (>0 for sfx)*/ +} file_in_zip_read_info_s; + + +/* unz_s contain internal information about the zipfile +*/ +typedef struct +{ + FILE* file; /* io structore of the zipfile */ + unz_global_info gi; /* public global information */ + unsigned long byte_before_the_zipfile; /* unsigned char before the zipfile, (>0 for sfx)*/ + unsigned long num_file; /* number of the current file in the zipfile*/ + unsigned long pos_in_central_dir; /* pos of the current file in the central dir*/ + unsigned long current_file_ok; /* flag about the usability of the current file*/ + unsigned long central_pos; /* position of the beginning of the central dir*/ + + unsigned long size_central_dir; /* size of the central directory */ + unsigned long offset_central_dir; /* offset of start of central directory with + respect to the starting disk number */ + + unz_file_info cur_file_info; /* public info about the current file in zip*/ + unz_file_info_internal cur_file_info_internal; /* private info about it*/ + file_in_zip_read_info_s* pfile_in_zip_read; /* structure about the current + file if we are decompressing it */ +} unz_s; + +#define UNZ_OK ( 0 ) +#define UNZ_END_OF_LIST_OF_FILE ( -100 ) +#define UNZ_ERRNO ( Z_ERRNO ) +#define UNZ_EOF ( 0 ) +#define UNZ_PARAMERROR ( -102 ) +#define UNZ_BADZIPFILE ( -103 ) +#define UNZ_INTERNALERROR ( -104 ) +#define UNZ_CRCERROR ( -105 ) + +#define UNZ_CASESENSITIVE 1 +#define UNZ_NOTCASESENSITIVE 2 +#define UNZ_OSDEFAULTCASE 0 + +extern int unzStringFileNameCompare( const char* fileName1, const char* fileName2, int iCaseSensitivity ); + +/* + Compare two filename (fileName1,fileName2). + If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp) + If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi + or strcasecmp) + If iCaseSenisivity = 0, case sensitivity is defaut of your operating system + (like 1 on Unix, 2 on Windows) +*/ + +extern unzFile unzOpen( const char *path ); +extern unzFile unzReOpen( const char* path, unzFile file ); + +/* + Open a Zip file. path contain the full pathname (by example, + on a Windows NT computer "c:\\zlib\\zlib111.zip" or on an Unix computer + "zlib/zlib111.zip". + If the zipfile cannot be opened (file don't exist or in not valid), the + return value is NULL. + Else, the return value is a unzFile Handle, usable with other function + of this unzip package. +*/ + +extern int unzClose( unzFile file ); + +/* + Close a ZipFile opened with unzipOpen. + If there is files inside the .Zip opened with unzOpenCurrentFile (see later), + these files MUST be closed with unzipCloseCurrentFile before call unzipClose. + return UNZ_OK if there is no problem. */ + +extern int unzGetGlobalInfo( unzFile file, unz_global_info *pglobal_info ); + +/* + Write info about the ZipFile in the *pglobal_info structure. + No preparation of the structure is needed + return UNZ_OK if there is no problem. */ + + +extern int unzGetGlobalComment( unzFile file, char *szComment, unsigned long uSizeBuf ); + +/* + Get the global comment string of the ZipFile, in the szComment buffer. + uSizeBuf is the size of the szComment buffer. + return the number of unsigned char copied or an error code <0 +*/ + + +/***************************************************************************/ +/* Unzip package allow you browse the directory of the zipfile */ + +extern int unzGoToFirstFile( unzFile file ); + +/* + Set the current file of the zipfile to the first file. + return UNZ_OK if there is no problem +*/ + +extern int unzGoToNextFile( unzFile file ); + +/* + Set the current file of the zipfile to the next file. + return UNZ_OK if there is no problem + return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest. +*/ + +extern int unzGetCurrentFileInfoPosition( unzFile file, unsigned long *pos ); + +/* + Get the position of the info of the current file in the zip. + return UNZ_OK if there is no problem +*/ + +extern int unzSetCurrentFileInfoPosition( unzFile file, unsigned long pos ); + +/* + Set the position of the info of the current file in the zip. + return UNZ_OK if there is no problem +*/ + +extern int unzLocateFile( unzFile file, const char *szFileName, int iCaseSensitivity ); + +/* + Try locate the file szFileName in the zipfile. + For the iCaseSensitivity signification, see unzStringFileNameCompare + + return value : + UNZ_OK if the file is found. It becomes the current file. + UNZ_END_OF_LIST_OF_FILE if the file is not found +*/ + + +extern int unzGetCurrentFileInfo( unzFile file, unz_file_info *pfile_info, char *szFileName, unsigned long fileNameBufferSize, void *extraField, unsigned long extraFieldBufferSize, char *szComment, unsigned long commentBufferSize ); + +/* + Get Info about the current file + if pfile_info!=NULL, the *pfile_info structure will contain somes info about + the current file + if szFileName!=NULL, the filemane string will be copied in szFileName + (fileNameBufferSize is the size of the buffer) + if extraField!=NULL, the extra field information will be copied in extraField + (extraFieldBufferSize is the size of the buffer). + This is the Central-header version of the extra field + if szComment!=NULL, the comment string of the file will be copied in szComment + (commentBufferSize is the size of the buffer) +*/ + +/***************************************************************************/ +/* for reading the content of the current zipfile, you can open it, read data + from it, and close it (you can close it before reading all the file) + */ + +extern int unzOpenCurrentFile( unzFile file ); + +/* + Open for reading data the current file in the zipfile. + If there is no error, the return value is UNZ_OK. +*/ + +extern int unzCloseCurrentFile( unzFile file ); + +/* + Close the file in zip opened with unzOpenCurrentFile + Return UNZ_CRCERROR if all the file was read but the CRC is not good +*/ + + +extern int unzReadCurrentFile( unzFile file, void* buf, unsigned len ); + +/* + Read unsigned chars from the current file (opened by unzOpenCurrentFile) + buf contain buffer where data must be copied + len the size of buf. + + return the number of unsigned char copied if somes unsigned chars are copied + return 0 if the end of file was reached + return <0 with error code if there is an error + (UNZ_ERRNO for IO error, or zLib error for uncompress error) +*/ + +extern long unztell( unzFile file ); + +/* + Give the current position in uncompressed data +*/ + +extern int unzeof( unzFile file ); + +/* + return 1 if the end of file was reached, 0 elsewhere +*/ + +extern int unzGetLocalExtrafield( unzFile file, void* buf, unsigned len ); + +/* + Read extra field from the current file (opened by unzOpenCurrentFile) + This is the local-header version of the extra field (sometimes, there is + more info in the local-header version than in the central-header) + + if buf==NULL, it return the size of the local extra field + + if buf!=NULL, len is the size of the buffer, the extra header is copied in + buf. + the return value is the number of unsigned chars copied in buf, or (if <0) + the error code +*/ diff --git a/Projects/Android/jni/rtcw/src/ft2/ahangles.c b/Projects/Android/jni/rtcw/src/ft2/ahangles.c new file mode 100644 index 0000000..18f7444 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/ft2/ahangles.c @@ -0,0 +1,128 @@ +/***************************************************************************/ +/* */ +/* ahangles.h */ +/* */ +/* A routine used to compute vector angles with limited accuracy */ +/* and very high speed (body). */ +/* */ +/* Copyright 2000 Catharon Productions Inc. */ +/* Author: David Turner */ +/* */ +/* This file is part of the Catharon Typography Project and shall only */ +/* be used, modified, and distributed under the terms of the Catharon */ +/* Open Source License that should come with this file under the name */ +/* `CatharonLicense.txt'. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/* Note that this license is compatible with the FreeType license. */ +/* */ +/***************************************************************************/ + + +#include "ahangles.h" + + +/* the following table has been automatically generated with */ +/* the `mather.py' Python script */ + +const AH_Angle ah_arctan[1L << AH_ATAN_BITS] = +{ + 0, 0, 1, 1, 1, 2, 2, 2, + 3, 3, 3, 3, 4, 4, 4, 5, + 5, 5, 6, 6, 6, 7, 7, 7, + 8, 8, 8, 9, 9, 9, 10, 10, + 10, 10, 11, 11, 11, 12, 12, 12, + 13, 13, 13, 14, 14, 14, 14, 15, + 15, 15, 16, 16, 16, 17, 17, 17, + 18, 18, 18, 18, 19, 19, 19, 20, + 20, 20, 21, 21, 21, 21, 22, 22, + 22, 23, 23, 23, 24, 24, 24, 24, + 25, 25, 25, 26, 26, 26, 26, 27, + 27, 27, 28, 28, 28, 28, 29, 29, + 29, 30, 30, 30, 30, 31, 31, 31, + 31, 32, 32, 32, 33, 33, 33, 33, + 34, 34, 34, 34, 35, 35, 35, 35, + 36, 36, 36, 36, 37, 37, 37, 38, + 38, 38, 38, 39, 39, 39, 39, 40, + 40, 40, 40, 41, 41, 41, 41, 42, + 42, 42, 42, 42, 43, 43, 43, 43, + 44, 44, 44, 44, 45, 45, 45, 45, + 46, 46, 46, 46, 46, 47, 47, 47, + 47, 48, 48, 48, 48, 48, 49, 49, + 49, 49, 50, 50, 50, 50, 50, 51, + 51, 51, 51, 51, 52, 52, 52, 52, + 52, 53, 53, 53, 53, 53, 54, 54, + 54, 54, 54, 55, 55, 55, 55, 55, + 56, 56, 56, 56, 56, 57, 57, 57, + 57, 57, 57, 58, 58, 58, 58, 58, + 59, 59, 59, 59, 59, 59, 60, 60, + 60, 60, 60, 61, 61, 61, 61, 61, + 61, 62, 62, 62, 62, 62, 62, 63, + 63, 63, 63, 63, 63, 64, 64, 64 +}; + + +LOCAL_FUNC +AH_Angle ah_angle( FT_Vector* v ) { + FT_Pos dx, dy; + AH_Angle angle; + + + dx = v->x; + dy = v->y; + + /* check trivial cases */ + if ( dy == 0 ) { + angle = 0; + if ( dx < 0 ) { + angle = AH_PI; + } + return angle; + } else if ( dx == 0 ) { + angle = AH_HALF_PI; + if ( dy < 0 ) { + angle = -AH_HALF_PI; + } + return angle; + } + + angle = 0; + if ( dx < 0 ) { + dx = -v->x; + dy = -v->y; + angle = AH_PI; + } + + if ( dy < 0 ) { + FT_Pos tmp; + + + tmp = dx; + dx = -dy; + dy = tmp; + angle -= AH_HALF_PI; + } + + if ( dx == 0 && dy == 0 ) { + return 0; + } + + if ( dx == dy ) { + angle += AH_PI / 4; + } else if ( dx > dy ) { + angle += ah_arctan[FT_DivFix( dy, dx ) >> ( 16 - AH_ATAN_BITS )]; + } else { + angle += AH_HALF_PI - + ah_arctan[FT_DivFix( dx, dy ) >> ( 16 - AH_ATAN_BITS )]; + } + + if ( angle > AH_PI ) { + angle -= AH_2PI; + } + + return angle; +} + + +/* END */ diff --git a/Projects/Android/jni/rtcw/src/ft2/ahangles.h b/Projects/Android/jni/rtcw/src/ft2/ahangles.h new file mode 100644 index 0000000..e16b637 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/ft2/ahangles.h @@ -0,0 +1,55 @@ +/***************************************************************************/ +/* */ +/* ahangles.h */ +/* */ +/* A routine used to compute vector angles with limited accuracy */ +/* and very high speed (specification). */ +/* */ +/* Copyright 2000 Catharon Productions Inc. */ +/* Author: David Turner */ +/* */ +/* This file is part of the Catharon Typography Project and shall only */ +/* be used, modified, and distributed under the terms of the Catharon */ +/* Open Source License that should come with this file under the name */ +/* `CatharonLicense.txt'. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/* Note that this license is compatible with the FreeType license. */ +/* */ +/***************************************************************************/ + + +#ifndef AHANGLES_H +#define AHANGLES_H + + + +#include "ahtypes.h" + +#include "ftobjs.h" + + +/* PI expressed in ah_angles -- we don't really need an important */ +/* precision, so 256 should be enough */ +#define AH_PI 256 +#define AH_2PI ( AH_PI * 2 ) +#define AH_HALF_PI ( AH_PI / 2 ) +#define AH_2PIMASK ( AH_2PI - 1 ) + +/* the number of bits used to express an arc tangent; */ +/* see the structure of the lookup table */ +#define AH_ATAN_BITS 8 + +extern +const AH_Angle ah_arctan[1L << AH_ATAN_BITS]; + + +LOCAL_DEF +AH_Angle ah_angle( FT_Vector* v ); + + +#endif /* AHANGLES_H */ + + +/* END */ diff --git a/Projects/Android/jni/rtcw/src/ft2/ahglobal.c b/Projects/Android/jni/rtcw/src/ft2/ahglobal.c new file mode 100644 index 0000000..8957327 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/ft2/ahglobal.c @@ -0,0 +1,397 @@ +/***************************************************************************/ +/* */ +/* ahglobal.c */ +/* */ +/* Routines used to compute global metrics automatically (body). */ +/* */ +/* Copyright 2000 Catharon Productions Inc. */ +/* Author: David Turner */ +/* */ +/* This file is part of the Catharon Typography Project and shall only */ +/* be used, modified, and distributed under the terms of the Catharon */ +/* Open Source License that should come with this file under the name */ +/* `CatharonLicense.txt'. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/* Note that this license is compatible with the FreeType license. */ +/* */ +/***************************************************************************/ + +#include "ahglobal.h" +#include "ahglyph.h" + +#define MAX_TEST_CHARACTERS 12 + +static +const char* blue_chars[ah_blue_max] = +{ + "THEZOCQS", + "HEZLOCUS", + "xzroesc", + "xzroesc", + "pqgjy" +}; + + +/* simple insertion sort */ +static +void sort_values( FT_Int count, + FT_Pos* table ) { + FT_Int i, j, swap; + + + for ( i = 1; i < count; i++ ) + { + for ( j = i; j > 1; j-- ) + { + if ( table[j] > table[j - 1] ) { + break; + } + + swap = table[j]; + table[j] = table[j - 1]; + table[j - 1] = swap; + } + } +} + + +static +FT_Error ah_hinter_compute_blues( AH_Hinter* hinter ) { + AH_Blue blue; + AH_Globals* globals = &hinter->globals->design; + FT_Pos flats [MAX_TEST_CHARACTERS]; + FT_Pos rounds[MAX_TEST_CHARACTERS]; + FT_Int num_flats; + FT_Int num_rounds; + + FT_Face face; + FT_GlyphSlot glyph; + FT_Error error; + FT_CharMap charmap; + + + face = hinter->face; + glyph = face->glyph; + + /* save current charmap */ + charmap = face->charmap; + + /* do we have a Unicode charmap in there? */ + error = FT_Select_Charmap( face, ft_encoding_unicode ); + if ( error ) { + goto Exit; + } + + /* we compute the blues simply by loading each character from the */ + /* 'blue_chars[blues]' string, then compute its top-most and */ + /* bottom-most points */ + + AH_LOG( ( "blue zones computation\n" ) ); + AH_LOG( ( "------------------------------------------------\n" ) ); + + for ( blue = ah_blue_capital_top; blue < ah_blue_max; blue++ ) + { + const char* p = blue_chars[blue]; + const char* limit = p + MAX_TEST_CHARACTERS; + FT_Pos *blue_ref, *blue_shoot; + + + AH_LOG( ( "blue %3d: ", blue ) ); + + num_flats = 0; + num_rounds = 0; + + for ( ; p < limit; p++ ) + { + FT_UInt glyph_index; + FT_Vector* extremum; + FT_Vector* points; + FT_Vector* point_limit; + FT_Vector* point; + FT_Bool round; + + + /* exit if we reach the end of the string */ + if ( !*p ) { + break; + } + + AH_LOG( ( "`%c'", *p ) ); + + /* load the character in the face -- skip unknown or empty ones */ + glyph_index = FT_Get_Char_Index( face, ( FT_UInt ) * p ); + if ( glyph_index == 0 ) { + continue; + } + + error = FT_Load_Glyph( face, glyph_index, FT_LOAD_NO_SCALE ); + if ( error || glyph->outline.n_points <= 0 ) { + continue; + } + + /* now compute min or max point indices and coordinates */ + points = glyph->outline.points; + point_limit = points + glyph->outline.n_points; + point = points; + extremum = point; + point++; + + if ( AH_IS_TOP_BLUE( blue ) ) { + for ( ; point < point_limit; point++ ) + if ( point->y > extremum->y ) { + extremum = point; + } + } else + { + for ( ; point < point_limit; point++ ) + if ( point->y < extremum->y ) { + extremum = point; + } + } + + AH_LOG( ( "%5d", (int)extremum->y ) ); + + /* now, check whether the point belongs to a straight or round */ + /* segment; we first need to find in which contour the extremum */ + /* lies, then see its previous and next points */ + { + FT_Int index = extremum - points; + FT_Int n; + FT_Int first, last, prev, next, end; + FT_Pos dist; + + + last = -1; + first = 0; + + for ( n = 0; n < glyph->outline.n_contours; n++ ) + { + end = glyph->outline.contours[n]; + if ( end >= index ) { + last = end; + break; + } + first = end + 1; + } + + /* XXX: should never happen! */ + if ( last < 0 ) { + continue; + } + + /* now look for the previous and next points that are not on the */ + /* same Y coordinate. Threshold the `closeness'... */ + + prev = index; + next = prev; + + do + { + if ( prev > first ) { + prev--; + } else { + prev = last; + } + + dist = points[prev].y - extremum->y; + if ( dist < -5 || dist > 5 ) { + break; + } + + } while ( prev != index ); + + do + { + if ( next < last ) { + next++; + } else { + next = first; + } + + dist = points[next].y - extremum->y; + if ( dist < -5 || dist > 5 ) { + break; + } + + } while ( next != index ); + + /* now, set the `round' flag depending on the segment's kind */ + round = + FT_CURVE_TAG( glyph->outline.tags[prev] ) != FT_Curve_Tag_On || + FT_CURVE_TAG( glyph->outline.tags[next] ) != FT_Curve_Tag_On ; + + AH_LOG( ( "%c ", round ? 'r' : 'f' ) ); + } + + if ( round ) { + rounds[num_rounds++] = extremum->y; + } else { + flats[num_flats++] = extremum->y; + } + } + + AH_LOG( ( "\n" ) ); + + /* we have computed the contents of the `rounds' and `flats' tables, */ + /* now determine the reference and overshoot position of the blue; */ + /* we simply take the median value after a simple short */ + sort_values( num_rounds, rounds ); + sort_values( num_flats, flats ); + + blue_ref = globals->blue_refs + blue; + blue_shoot = globals->blue_shoots + blue; + if ( num_flats == 0 && num_rounds == 0 ) { + *blue_ref = -10000; + *blue_shoot = -10000; + } else if ( num_flats == 0 ) { + *blue_ref = + *blue_shoot = rounds[num_rounds / 2]; + } else if ( num_rounds == 0 ) { + *blue_ref = + *blue_shoot = flats[num_flats / 2]; + } else + { + *blue_ref = flats[num_flats / 2]; + *blue_shoot = rounds[num_rounds / 2]; + } + + /* there are sometimes problems: if the overshoot position of top */ + /* zones is under its reference position, or the opposite for bottom */ + /* zones. We must thus check everything there and correct the errors */ + if ( *blue_shoot != *blue_ref ) { + FT_Pos ref = *blue_ref; + FT_Pos shoot = *blue_shoot; + FT_Bool over_ref = ( shoot > ref ); + + + if ( AH_IS_TOP_BLUE( blue ) ^ over_ref ) { + *blue_shoot = *blue_ref = ( shoot + ref ) / 2; + } + } + + AH_LOG( ( "-- ref = %ld, shoot = %ld\n", *blue_ref, *blue_shoot ) ); + } + + /* reset original face charmap */ + FT_Set_Charmap( face, charmap ); + error = 0; + +Exit: + return error; +} + + +static +FT_Error ah_hinter_compute_widths( AH_Hinter* hinter ) { + /* scan the array of segments in each direction */ + AH_Outline* outline = hinter->glyph; + AH_Segment* segments; + AH_Segment* limit; + AH_Globals* globals = &hinter->globals->design; + FT_Pos* widths; + FT_Int dimension; + FT_Int* p_num_widths; + FT_Error error = 0; + FT_Pos edge_distance_threshold = 32000; + + + globals->num_widths = 0; + globals->num_heights = 0; + + /* For now, compute the standard width and height from the `o' */ + /* character. I started computing the stem width of the `i' and the */ + /* stem height of the "-", but it wasn't too good. Moreover, we now */ + /* have a single character that gives us standard width and height. */ + { + FT_UInt glyph_index; + + + glyph_index = FT_Get_Char_Index( hinter->face, 'o' ); + if ( glyph_index == 0 ) { + return 0; + } + + error = FT_Load_Glyph( hinter->face, glyph_index, FT_LOAD_NO_SCALE ); + if ( error ) { + goto Exit; + } + + error = ah_outline_load( hinter->glyph, hinter->face ); + if ( error ) { + goto Exit; + } + + ah_outline_compute_segments( hinter->glyph ); + ah_outline_link_segments( hinter->glyph ); + } + + segments = outline->horz_segments; + limit = segments + outline->num_hsegments; + widths = globals->heights; + p_num_widths = &globals->num_heights; + + for ( dimension = 1; dimension >= 0; dimension-- ) + { + AH_Segment* seg = segments; + AH_Segment* link; + FT_Int num_widths = 0; + + + for ( ; seg < limit; seg++ ) + { + link = seg->link; + /* we only consider stem segments there! */ + if ( link && link->link == seg && link > seg ) { + FT_Int dist; + + + dist = seg->pos - link->pos; + if ( dist < 0 ) { + dist = -dist; + } + + if ( num_widths < 12 ) { + widths[num_widths++] = dist; + } + } + } + + sort_values( num_widths, widths ); + *p_num_widths = num_widths; + + /* we will now try to find the smallest width */ + if ( num_widths > 0 && widths[0] < edge_distance_threshold ) { + edge_distance_threshold = widths[0]; + } + + segments = outline->vert_segments; + limit = segments + outline->num_vsegments; + widths = globals->widths; + p_num_widths = &globals->num_widths; + + } + + /* Now, compute the edge distance threshold as a fraction of the */ + /* smallest width in the font. Set it in `hinter.glyph' too! */ + if ( edge_distance_threshold == 32000 ) { + edge_distance_threshold = 50; + } + + /* let's try 20% */ + hinter->glyph->edge_distance_threshold = edge_distance_threshold / 5; + +Exit: + return error; +} + + +LOCAL_FUNC +FT_Error ah_hinter_compute_globals( AH_Hinter* hinter ) { + return ah_hinter_compute_widths( hinter ) || + ah_hinter_compute_blues( hinter ); +} + + +/* END */ diff --git a/Projects/Android/jni/rtcw/src/ft2/ahglobal.h b/Projects/Android/jni/rtcw/src/ft2/ahglobal.h new file mode 100644 index 0000000..db3ca64 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/ft2/ahglobal.h @@ -0,0 +1,42 @@ +/***************************************************************************/ +/* */ +/* ahglobal.h */ +/* */ +/* Routines used to compute global metrics automatically */ +/* (specification). */ +/* */ +/* Copyright 2000 Catharon Productions Inc. */ +/* Author: David Turner */ +/* */ +/* This file is part of the Catharon Typography Project and shall only */ +/* be used, modified, and distributed under the terms of the Catharon */ +/* Open Source License that should come with this file under the name */ +/* `CatharonLicense.txt'. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/* Note that this license is compatible with the FreeType license. */ +/* */ +/***************************************************************************/ + + +#ifndef AHGLOBAL_H +#define AHGLOBAL_H + +#include "ahtypes.h" + +#include "ftobjs.h" + +#define AH_IS_TOP_BLUE( b ) ( ( b ) == ah_blue_capital_top || \ + ( b ) == ah_blue_small_top ) + + +/* compute global metrics automatically */ +LOCAL_DEF +FT_Error ah_hinter_compute_globals( AH_Hinter* hinter ); + + +#endif /* AHGLOBAL_H */ + + +/* END */ diff --git a/Projects/Android/jni/rtcw/src/ft2/ahglyph.c b/Projects/Android/jni/rtcw/src/ft2/ahglyph.c new file mode 100644 index 0000000..5294ac5 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/ft2/ahglyph.c @@ -0,0 +1,1275 @@ +/***************************************************************************/ +/* */ +/* ahglyph.c */ +/* */ +/* Routines used to load and analyze a given glyph before hinting */ +/* (body). */ +/* */ +/* Copyright 2000 Catharon Productions Inc. */ +/* Author: David Turner */ +/* */ +/* This file is part of the Catharon Typography Project and shall only */ +/* be used, modified, and distributed under the terms of the Catharon */ +/* Open Source License that should come with this file under the name */ +/* `CatharonLicense.txt'. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/* Note that this license is compatible with the FreeType license. */ +/* */ +/***************************************************************************/ + + +#include "ahglyph.h" +#include "ahangles.h" +#include "ahglobal.h" + +#include + + +#define xxxAH_DEBUG_GLYPH + + +/* compute the direction value of a given vector.. */ +static +AH_Direction ah_compute_direction( FT_Pos dx, + FT_Pos dy ) { + AH_Direction dir; + FT_Pos ax = ABS( dx ); + FT_Pos ay = ABS( dy ); + + + dir = ah_dir_none; + + /* test for vertical direction */ + if ( ax * 12 < ay ) { + dir = dy > 0 ? ah_dir_up : ah_dir_down; + } + /* test for horizontal direction */ + else if ( ay * 12 < ax ) { + dir = dx > 0 ? ah_dir_right : ah_dir_left; + } + + return dir; +} + + +/*************************************************************************/ +/* */ +/* */ +/* ah_outline_new */ +/* */ +/* */ +/* Creates a new and empty AH_Outline object. */ +/* */ +LOCAL_FUNC +FT_Error ah_outline_new( FT_Memory memory, + AH_Outline** aoutline ) { + FT_Error error; + AH_Outline* outline; + + + if ( !ALLOC( outline, sizeof( *outline ) ) ) { + outline->memory = memory; + *aoutline = outline; + } + + return error; +} + + +/*************************************************************************/ +/* */ +/* */ +/* ah_outline_done */ +/* */ +/* */ +/* Destroys a given AH_Outline object. */ +/* */ +LOCAL_FUNC +void ah_outline_done( AH_Outline* outline ) { + FT_Memory memory = outline->memory; + + + FREE( outline->horz_edges ); + FREE( outline->horz_segments ); + FREE( outline->contours ); + FREE( outline->points ); + + FREE( outline ); +} + + +/*************************************************************************/ +/* */ +/* */ +/* ah_outline_save */ +/* */ +/* */ +/* Saves the content of a given AH_Outline object into a face's glyph */ +/* slot. */ +/* */ +LOCAL_FUNC +void ah_outline_save( AH_Outline* outline, + AH_Loader* gloader ) { + AH_Point* point = outline->points; + AH_Point* limit = point + outline->num_points; + FT_Vector* vec = gloader->current.outline.points; + char* tag = gloader->current.outline.tags; + + + /* we assume that the glyph loader has already been checked for storage */ + for ( ; point < limit; point++, vec++, tag++ ) + { + vec->x = point->x; + vec->y = point->y; + + if ( point->flags & ah_flah_conic ) { + tag[0] = FT_Curve_Tag_Conic; + } else if ( point->flags & ah_flah_cubic ) { + tag[0] = FT_Curve_Tag_Cubic; + } else { + tag[0] = FT_Curve_Tag_On; + } + } +} + + +/*************************************************************************/ +/* */ +/* */ +/* ah_outline_load */ +/* */ +/* */ +/* Loads an unscaled outline from a glyph slot into an AH_Outline */ +/* object. */ +/* */ +LOCAL_FUNC +FT_Error ah_outline_load( AH_Outline* outline, + FT_Face face ) { + FT_Memory memory = outline->memory; + FT_Error error = FT_Err_Ok; + FT_Outline* source = &face->glyph->outline; + FT_Int num_points = source->n_points; + FT_Int num_contours = source->n_contours; + AH_Point* points; + + + /* check arguments */ + if ( !face || + !face->size || + face->glyph->format != ft_glyph_format_outline ) { + return FT_Err_Invalid_Argument; + } + + /* first of all, reallocate the contours array if necessary */ + if ( num_contours > outline->max_contours ) { + FT_Int new_contours = ( num_contours + 3 ) & - 4; + + + if ( REALLOC_ARRAY( outline->contours, outline->max_contours, + new_contours, AH_Point* ) ) { + goto Exit; + } + + outline->max_contours = new_contours; + } + + /* then, realloc the points, segments & edges arrays if needed */ + if ( num_points > outline->max_points ) { + FT_Int news = ( num_points + 7 ) & - 8; + FT_Int max = outline->max_points; + + + if ( REALLOC_ARRAY( outline->points, max, news, AH_Point ) || + REALLOC_ARRAY( outline->horz_edges, max, news, AH_Edge ) || + REALLOC_ARRAY( outline->horz_segments, max, news, AH_Segment ) ) { + goto Exit; + } + + /* readjust some pointers */ + outline->vert_edges = outline->horz_edges + ( news >> 1 ); + outline->vert_segments = outline->horz_segments + ( news >> 1 ); + outline->max_points = news; + } + + outline->num_points = num_points; + outline->num_contours = num_contours; + + outline->num_hedges = 0; + outline->num_vedges = 0; + outline->num_hsegments = 0; + outline->num_vsegments = 0; + + /* Compute the vertical and horizontal major directions; this is */ + /* currently done by inspecting the `ft_outline_reverse_fill' flag. */ + /* However, some fonts have improper glyphs, and it'd be a good idea */ + /* to be able to re-compute these values on the fly. */ + outline->vert_major_dir = ah_dir_up; + outline->horz_major_dir = ah_dir_left; + + if ( source->flags & ft_outline_reverse_fill ) { + outline->vert_major_dir = ah_dir_down; + outline->horz_major_dir = ah_dir_right; + } + + outline->x_scale = face->size->metrics.x_scale; + outline->y_scale = face->size->metrics.y_scale; + + points = outline->points; + + { + /* do one thing at a time -- it is easier to understand, and */ + /* the code is clearer */ + AH_Point* point = points; + AH_Point* limit = point + outline->num_points; + + + /* compute coordinates */ + { + FT_Vector* vec = source->points; + FT_Fixed x_scale = outline->x_scale; + FT_Fixed y_scale = outline->y_scale; + + + for (; point < limit; vec++, point++ ) + { + point->fx = vec->x; + point->fy = vec->y; + point->ox = point->x = FT_MulFix( vec->x, x_scale ); + point->oy = point->y = FT_MulFix( vec->y, y_scale ); + + point->flags = 0; + } + } + + /* compute Bezier flags */ + { + char* tag = source->tags; + + + for ( point = points; point < limit; point++, tag++ ) + { + switch ( FT_CURVE_TAG( *tag ) ) + { + case FT_Curve_Tag_Conic: + point->flags = ah_flah_conic; break; + case FT_Curve_Tag_Cubic: + point->flags = ah_flah_cubic; break; + default: + ; + } + } + } + + /* compute `next' and `prev' */ + { + FT_Int contour_index; + AH_Point* prev; + AH_Point* first; + AH_Point* end; + + + contour_index = 0; + + first = points; + end = points + source->contours[0]; + prev = end; + + for ( point = points; point < limit; point++ ) + { + point->prev = prev; + if ( point < end ) { + point->next = point + 1; + prev = point; + } else + { + point->next = first; + contour_index++; + if ( point + 1 < limit ) { + end = points + source->contours[contour_index]; + first = point + 1; + prev = end; + } + } + } + } + + /* set-up the contours array */ + { + AH_Point** contour = outline->contours; + AH_Point** limit = contour + outline->num_contours; + short* end = source->contours; + short index = 0; + + + for ( ; contour < limit; contour++, end++ ) + { + contour[0] = points + index; + index = end[0] + 1; + } + } + + /* compute directions of in & out vectors */ + { + for ( point = points; point < limit; point++ ) + { + AH_Point* prev; + AH_Point* next; + FT_Vector vec; + + + prev = point->prev; + vec.x = point->fx - prev->fx; + vec.y = point->fy - prev->fy; + + point->in_dir = ah_compute_direction( vec.x, vec.y ); + +#ifndef AH_OPTION_NO_WEAK_INTERPOLATION + point->in_angle = ah_angle( &vec ); +#endif + + next = point->next; + vec.x = next->fx - point->fx; + vec.y = next->fy - point->fy; + + point->out_dir = ah_compute_direction( vec.x, vec.y ); + +#ifndef AH_OPTION_NO_WEAK_INTERPOLATION + point->out_angle = ah_angle( &vec ); + + { + AH_Angle delta = point->in_angle - point->out_angle; + + + if ( delta < 0 ) { + delta = -delta; + } + if ( delta < 2 ) { + point->flags |= ah_flah_weak_interpolation; + } + } + +#if 0 + if ( point->flags & ( ah_flah_conic | ah_flah_cubic ) ) { + point->flags |= ah_flah_weak_interpolation; + } +#endif + +#endif /* !AH_OPTION_NO_WEAK_INTERPOLATION */ + +#ifdef AH_OPTION_NO_STRONG_INTERPOLATION + point->flags |= ah_flah_weak_interpolation; +#endif + } + } + } + +Exit: + return error; +} + + +LOCAL_FUNC +void ah_setup_uv( AH_Outline* outline, + AH_UV source ) { + AH_Point* point = outline->points; + AH_Point* limit = point + outline->num_points; + + + for ( ; point < limit; point++ ) + { + FT_Pos u, v; + + + switch ( source ) + { + case ah_uv_fxy: + u = point->fx; + v = point->fy; + break; + case ah_uv_fyx: + u = point->fy; + v = point->fx; + break; + case ah_uv_oxy: + u = point->ox; + v = point->oy; + break; + case ah_uv_oyx: + u = point->oy; + v = point->ox; + break; + case ah_uv_yx: + u = point->y; + v = point->x; + break; + case ah_uv_ox: + u = point->x; + v = point->ox; + break; + case ah_uv_oy: + u = point->y; + v = point->oy; + break; + default: + u = point->x; + v = point->y; + break; + } + point->u = u; + point->v = v; + } +} + + +LOCAL_FUNC +void ah_outline_compute_segments( AH_Outline* outline ) { + int dimension; + AH_Segment* segments; + FT_Int* p_num_segments; + AH_Direction segment_dir; + AH_Direction major_dir; + + + segments = outline->horz_segments; + p_num_segments = &outline->num_hsegments; + major_dir = ah_dir_right; /* This value must be positive! */ + segment_dir = major_dir; + + /* set up (u,v) in each point */ + ah_setup_uv( outline, ah_uv_fyx ); + + for ( dimension = 1; dimension >= 0; dimension-- ) + { + AH_Point** contour = outline->contours; + AH_Point** contour_limit = contour + outline->num_contours; + AH_Segment* segment = segments; + FT_Int num_segments = 0; + +#ifdef AH_HINT_METRICS + AH_Point* min_point = 0; + AH_Point* max_point = 0; + FT_Pos min_coord = 32000; + FT_Pos max_coord = -32000; +#endif + + + /* do each contour separately */ + for ( ; contour < contour_limit; contour++ ) + { + AH_Point* point = contour[0]; + AH_Point* last = point->prev; + int on_edge = 0; + FT_Pos min_pos = +32000; /* minimum segment pos != min_coord */ + FT_Pos max_pos = -32000; /* maximum segment pos != max_coord */ + FT_Bool passed; + + +#ifdef AH_HINT_METRICS + if ( point->u < min_coord ) { + min_coord = point->u; + min_point = point; + } + if ( point->u > max_coord ) { + max_coord = point->u; + max_point = point; + } +#endif + + if ( point == last ) { /* skip singletons -- just in case? */ + continue; + } + + if ( ABS( last->out_dir ) == major_dir && + ABS( point->out_dir ) == major_dir ) { + /* we are already on an edge, try to locate its start */ + last = point; + + for (;; ) + { + point = point->prev; + if ( ABS( point->out_dir ) != major_dir ) { + point = point->next; + break; + } + if ( point == last ) { + break; + } + } + + } + + last = point; + passed = 0; + + for (;; ) + { + FT_Pos u, v; + + + if ( on_edge ) { + u = point->u; + if ( u < min_pos ) { + min_pos = u; + } + if ( u > max_pos ) { + max_pos = u; + } + + if ( point->out_dir != segment_dir || point == last ) { + /* we are just leaving an edge; record a new segment! */ + segment->last = point; + segment->pos = ( min_pos + max_pos ) >> 1; + + /* a segment is round if either its first or last point */ + /* is a control point */ + if ( ( segment->first->flags | point->flags ) & + ah_flah_control ) { + segment->flags |= ah_edge_round; + } + + /* compute segment size */ + min_pos = max_pos = point->v; + + v = segment->first->v; + if ( v < min_pos ) { + min_pos = v; + } + if ( v > max_pos ) { + max_pos = v; + } + + segment->min_coord = min_pos; + segment->max_coord = max_pos; + + on_edge = 0; + num_segments++; + segment++; + /* fallthrough */ + } + } + + /* now exit if we are at the start/end point */ + if ( point == last ) { + if ( passed ) { + break; + } + passed = 1; + } + + if ( !on_edge && ABS( point->out_dir ) == major_dir ) { + /* this is the start of a new segment! */ + segment_dir = point->out_dir; + + /* clear all segment fields */ + memset( segment, 0, sizeof( *segment ) ); + + segment->dir = segment_dir; + segment->flags = ah_edge_normal; + min_pos = max_pos = point->u; + segment->first = point; + segment->last = point; + segment->contour = contour; + on_edge = 1; + + if ( point == max_point ) { + max_point = 0; + } + + if ( point == min_point ) { + min_point = 0; + } + } + + point = point->next; + } + + } /* contours */ + +#ifdef AH_HINT_METRICS + /* we need to ensure that there are edges on the left-most and */ + /* right-most points of the glyph in order to hint the metrics; */ + /* we do this by inserting fake segments when needed */ + if ( dimension == 0 ) { + AH_Point* point = outline->points; + AH_Point* limit = point + outline->num_points; + + AH_Point* min_point = 0; + AH_Point* max_point = 0; + FT_Pos min_pos = 32000; + FT_Pos max_pos = -32000; + + + /* compute minimum and maximum points */ + for ( ; point < limit; point++ ) + { + FT_Pos x = point->fx; + + + if ( x < min_pos ) { + min_pos = x; + min_point = point; + } + if ( x > max_pos ) { + max_pos = x; + max_point = point; + } + } + + /* insert minimum segment */ + if ( min_point ) { + /* clear all segment fields */ + memset( segment, 0, sizeof( *segment ) ); + + segment->dir = segment_dir; + segment->flags = ah_edge_normal; + segment->first = min_point; + segment->last = min_point; + segment->pos = min_pos; + + num_segments++; + segment++; + } + + /* insert maximum segment */ + if ( max_point ) { + /* clear all segment fields */ + memset( segment, 0, sizeof( *segment ) ); + + segment->dir = segment_dir; + segment->flags = ah_edge_normal; + segment->first = max_point; + segment->last = max_point; + segment->pos = max_pos; + + num_segments++; + segment++; + } + } +#endif /* AH_HINT_METRICS */ + + *p_num_segments = num_segments; + + segments = outline->vert_segments; + major_dir = ah_dir_up; + p_num_segments = &outline->num_vsegments; + ah_setup_uv( outline, ah_uv_fxy ); + } +} + + +LOCAL_FUNC +void ah_outline_link_segments( AH_Outline* outline ) { + AH_Segment* segments; + AH_Segment* limit; + int dimension; + + + ah_setup_uv( outline, ah_uv_fyx ); + + segments = outline->horz_segments; + limit = segments + outline->num_hsegments; + + for ( dimension = 1; dimension >= 0; dimension-- ) + { + AH_Segment* seg1; + AH_Segment* seg2; + + + /* now compare each segment to the others */ + for ( seg1 = segments; seg1 < limit; seg1++ ) + { + FT_Pos best_score = 32000; + AH_Segment* best_segment = 0; + + + /* the fake segments are introduced to hint the metrics -- */ + /* we must never link them to anything */ + if ( seg1->first == seg1->last ) { + continue; + } + + for ( seg2 = segments; seg2 < limit; seg2++ ) + if ( seg1 != seg2 && seg1->dir + seg2->dir == 0 ) { + FT_Pos pos1 = seg1->pos; + FT_Pos pos2 = seg2->pos; + FT_Bool is_dir; + FT_Bool is_pos; + + + /* check that the segments are correctly oriented and */ + /* positioned to form a black distance */ + + is_dir = ( seg1->dir == outline->horz_major_dir || + seg1->dir == outline->vert_major_dir ); + is_pos = pos1 > pos2; + + if ( pos1 == pos2 || !( is_dir ^ is_pos ) ) { + continue; + } + + /* Check the two segments. We now have a better algorithm */ + /* that doesn't rely on the segment points themselves but */ + /* on their relative position. This gets rids of many */ + /* unpleasant artefacts and incorrect stem/serifs */ + /* computations. */ + + /* first of all, compute the size of the `common' height */ + { + FT_Pos min = seg1->min_coord; + FT_Pos max = seg1->max_coord; + FT_Pos len, score; + FT_Pos size1, size2; + + + size1 = max - min; + size2 = seg2->max_coord - seg2->min_coord; + + if ( min < seg2->min_coord ) { + min = seg2->min_coord; + } + + if ( max < seg2->max_coord ) { + max = seg2->max_coord; + } + + len = max - min; + score = seg2->pos - seg1->pos; + if ( score < 0 ) { + score = -score; + } + + /* before comparing the scores, take care that the segments */ + /* are really facing each other (often not for italics..) */ + if ( 4 * len >= size1 && 4 * len >= size2 ) { + if ( score < best_score ) { + best_score = score; + best_segment = seg2; + } + } + } + } + + if ( best_segment ) { + seg1->link = best_segment; + seg1->score = best_score; + + best_segment->num_linked++; + } + + + } /* edges 1 */ + + /* now, compute the `serif' segments */ + for ( seg1 = segments; seg1 < limit; seg1++ ) + { + seg2 = seg1->link; + + if ( seg2 && seg2->link != seg1 ) { + seg1->link = 0; + seg1->serif = seg2->link; + } + } + + ah_setup_uv( outline, ah_uv_fxy ); + + segments = outline->vert_segments; + limit = segments + outline->num_vsegments; + } +} + + +#ifdef AH_DEBUG_GLYPH + +/* A function used to dump the array of linked segments */ +void ah_dump_segments( AH_Outline* outline ) { + AH_Segment* segments; + AH_Segment* limit; + AH_Point* points; + FT_Int dimension; + + + points = outline->points; + segments = outline->horz_segments; + limit = segments + outline->num_hsegments; + + for ( dimension = 1; dimension >= 0; dimension-- ) + { + AH_Segment* seg; + + + printf( "Table of %s segments:\n", + !dimension ? "vertical" : "horizontal" ); + printf( " [ index | pos | dir | link | serif |" + " numl | first | start ]\n" ); + + for ( seg = segments; seg < limit; seg++ ) + { + printf( " [ %5d | %4d | %5s | %4d | %5d | %4d | %5d | %5d ]\n", + seg - segments, + (int)seg->pos, + seg->dir == ah_dir_up + ? "up" + : ( seg->dir == ah_dir_down + ? "down" + : ( seg->dir == ah_dir_left + ? "left" + : ( seg->dir == ah_dir_right + ? "right" + : "none" ) ) ), + seg->link ? ( seg->link - segments ) : -1, + seg->serif ? ( seg->serif - segments ) : -1, + (int)seg->num_linked, + seg->first - points, + seg->last - points ); + } + + segments = outline->vert_segments; + limit = segments + outline->num_vsegments; + } +} + +#endif /* AH_DEBUG_GLYPH */ + + +static +void ah_outline_compute_edges( AH_Outline* outline ) { + AH_Edge* edges; + AH_Segment* segments; + AH_Segment* segment_limit; + AH_Direction up_dir; + FT_Int* p_num_edges; + FT_Int dimension; + FT_Fixed scale; + FT_Pos edge_distance_threshold; + + + edges = outline->horz_edges; + segments = outline->horz_segments; + segment_limit = segments + outline->num_hsegments; + p_num_edges = &outline->num_hedges; + up_dir = ah_dir_right; + scale = outline->y_scale; + + for ( dimension = 1; dimension >= 0; dimension-- ) + { + AH_Edge* edge; + AH_Edge* edge_limit; /* really == edge + num_edges */ + AH_Segment* seg; + + + /*********************************************************************/ + /* */ + /* We will begin by generating a sorted table of edges for the */ + /* current direction. To do so, we simply scan each segment and try */ + /* to find an edge in our table that corresponds to its position. */ + /* */ + /* If no edge is found, we create and insert a new edge in the */ + /* sorted table. Otherwise, we simply add the segment to the edge's */ + /* list which will be processed in the second step to compute the */ + /* edge's properties. */ + /* */ + /* Note that the edges table is sorted along the segment/edge */ + /* position. */ + /* */ + /*********************************************************************/ + + edge_distance_threshold = FT_MulFix( outline->edge_distance_threshold, + scale ); + if ( edge_distance_threshold > 64 / 4 ) { + edge_distance_threshold = 64 / 4; + } + + edge_limit = edges; + for ( seg = segments; seg < segment_limit; seg++ ) + { + AH_Edge* found = 0; + + + /* look for an edge corresponding to the segment */ + for ( edge = edges; edge < edge_limit; edge++ ) + { + FT_Pos dist; + + + dist = seg->pos - edge->fpos; + if ( dist < 0 ) { + dist = -dist; + } + + dist = FT_MulFix( dist, scale ); + if ( dist < edge_distance_threshold ) { + found = edge; + break; + } + } + + if ( !found ) { + /* insert a new edge in the list and */ + /* sort according to the position */ + while ( edge > edges && edge[-1].fpos > seg->pos ) + { + edge[0] = edge[-1]; + edge--; + } + edge_limit++; + + /* clear all edge fields */ + memset( edge, 0, sizeof( *edge ) ); + + /* add the segment to the new edge's list */ + edge->first = seg; + edge->last = seg; + edge->fpos = seg->pos; + edge->opos = edge->pos = FT_MulFix( seg->pos, scale ); + seg->edge_next = seg; + } else + { + /* if an edge was found, simply add the segment to the edge's */ + /* list */ + seg->edge_next = edge->first; + edge->last->edge_next = seg; + edge->last = seg; + } + } + + *p_num_edges = edge_limit - edges; + + + /*********************************************************************/ + /* */ + /* Good, we will now compute each edge's properties according to */ + /* segments found on its position. Basically, these are: */ + /* */ + /* - edge's main direction */ + /* - stem edge, serif edge or both (which defaults to stem then) */ + /* - rounded edge, straigth or both (which defaults to straight) */ + /* - link for edge */ + /* */ + /*********************************************************************/ + + /* first of all, set the `edge' field in each segment -- this is */ + /* required in order to compute edge links */ + for ( edge = edges; edge < edge_limit; edge++ ) + { + seg = edge->first; + if ( seg ) { + do + { + seg->edge = edge; + seg = seg->edge_next; + } + while ( seg != edge->first ); + } + } + + /* now, compute each edge properties */ + for ( edge = edges; edge < edge_limit; edge++ ) + { + int is_round = 0; /* does it contain round segments? */ + int is_straight = 0; /* does it contain straight segments? */ + int ups = 0; /* number of upwards segments */ + int downs = 0; /* number of downwards segments */ + + + seg = edge->first; + + do + { + FT_Bool is_serif; + + + /* check for roundness of segment */ + if ( seg->flags & ah_edge_round ) { + is_round++; + } else { + is_straight++; + } + + /* check for segment direction */ + if ( seg->dir == up_dir ) { + ups += seg->max_coord - seg->min_coord; + } else { + downs += seg->max_coord - seg->min_coord; + } + + /* check for links -- if seg->serif is set, then seg->link must */ + /* be ignored */ + is_serif = seg->serif && seg->serif->edge != edge; + + if ( seg->link || is_serif ) { + AH_Edge* edge2; + AH_Segment* seg2; + + + edge2 = edge->link; + seg2 = seg->link; + + if ( is_serif ) { + seg2 = seg->serif; + edge2 = edge->serif; + } + + if ( edge2 ) { + FT_Pos edge_delta; + FT_Pos seg_delta; + + + edge_delta = edge->fpos - edge2->fpos; + if ( edge_delta < 0 ) { + edge_delta = -edge_delta; + } + + seg_delta = seg->pos - seg2->pos; + if ( seg_delta < 0 ) { + seg_delta = -seg_delta; + } + + if ( seg_delta < edge_delta ) { + edge2 = seg2->edge; + } + } else { + edge2 = seg2->edge; + } + + if ( is_serif ) { + edge->serif = edge2; + } else { + edge->link = edge2; + } + } + + seg = seg->edge_next; + + } while ( seg != edge->first ); + + /* set the round/straight flags */ + edge->flags = ah_edge_normal; + + if ( is_straight == 0 && is_round ) { + edge->flags |= ah_edge_round; + } + + /* set the edge's main direction */ + edge->dir = ah_dir_none; + + if ( ups > downs ) { + edge->dir = up_dir; + } else if ( ups < downs ) { + edge->dir = -up_dir; + } else if ( ups == downs ) { + edge->dir = 0; /* both up and down !! */ + + } + /* gets rid of serifs if link is set */ + /* XXX: This gets rid of many unpleasant artefacts! */ + /* Example: the `c' in cour.pfa at size 13 */ + + if ( edge->serif && edge->link ) { + edge->serif = 0; + } + } + + edges = outline->vert_edges; + segments = outline->vert_segments; + segment_limit = segments + outline->num_vsegments; + p_num_edges = &outline->num_vedges; + up_dir = ah_dir_up; + scale = outline->x_scale; + } +} + + +/*************************************************************************/ +/* */ +/* */ +/* ah_outline_detect_features */ +/* */ +/* */ +/* Performs feature detection on a given AH_Outline object. */ +/* */ +LOCAL_FUNC +void ah_outline_detect_features( AH_Outline* outline ) { + ah_outline_compute_segments( outline ); + ah_outline_link_segments( outline ); + ah_outline_compute_edges( outline ); +} + + +/*************************************************************************/ +/* */ +/* */ +/* ah_outline_compute_blue_edges */ +/* */ +/* */ +/* Computes the `blue edges' in a given outline (i.e. those that must */ +/* be snapped to a blue zone edge (top or bottom). */ +/* */ +LOCAL_FUNC +void ah_outline_compute_blue_edges( AH_Outline* outline, + AH_Face_Globals* face_globals ) { + AH_Edge* edge = outline->horz_edges; + AH_Edge* limit = edge + outline->num_hedges; + AH_Globals* globals = &face_globals->design; + FT_Fixed y_scale = outline->y_scale; + + + /* compute for each horizontal edge, which blue zone is closer */ + for ( ; edge < limit; edge++ ) + { + AH_Blue blue; + FT_Pos* best_blue = 0; + FT_Pos best_dist; /* initial threshold */ + + + /* compute the initial threshold as a fraction of the EM size */ + best_dist = FT_MulFix( face_globals->face->units_per_EM / 40, y_scale ); + if ( best_dist > 64 / 4 ) { + best_dist = 64 / 4; + } + + for ( blue = ah_blue_capital_top; blue < ah_blue_max; blue++ ) + { + /* if it is a top zone, check for right edges -- if it is a bottom */ + /* zone, check for left edges */ + /* */ + /* of course, that's for TrueType XXX */ + FT_Bool is_top_blue = AH_IS_TOP_BLUE( blue ); + FT_Bool is_major_dir = edge->dir == outline->horz_major_dir; + + + /* if it is a top zone, the edge must be against the major */ + /* direction; if it is a bottom zone, it must be in the major */ + /* direction */ + if ( is_top_blue ^ is_major_dir ) { + FT_Pos dist; + FT_Pos* blue_pos = globals->blue_refs + blue; + + + /* first of all, compare it to the reference position */ + dist = edge->fpos - *blue_pos; + if ( dist < 0 ) { + dist = -dist; + } + + dist = FT_MulFix( dist, y_scale ); + if ( dist < best_dist ) { + best_dist = dist; + best_blue = blue_pos; + } + + /* now, compare it to the overshoot position if the edge is */ + /* rounded, and if the edge is over the reference position of a */ + /* top zone, or under the reference position of a bottom zone */ + if ( edge->flags & ah_edge_round && dist != 0 ) { + FT_Bool is_under_ref = edge->fpos < *blue_pos; + + + if ( is_top_blue ^ is_under_ref ) { + blue_pos = globals->blue_shoots + blue; + dist = edge->fpos - *blue_pos; + if ( dist < 0 ) { + dist = -dist; + } + + dist = FT_MulFix( dist, y_scale ); + if ( dist < best_dist ) { + best_dist = dist; + best_blue = blue_pos; + } + } + } + } + } + + if ( best_blue ) { + edge->blue_edge = best_blue; + } + } +} + + +/*************************************************************************/ +/* */ +/* */ +/* ah_outline_scale_blue_edges */ +/* */ +/* */ +/* This functions must be called before hinting in order to re-adjust */ +/* the contents of the detected edges (basically change the `blue */ +/* edge' pointer from `design units' to `scaled ones'). */ +/* */ +LOCAL_FUNC +void ah_outline_scale_blue_edges( AH_Outline* outline, + AH_Face_Globals* globals ) { + AH_Edge* edge = outline->horz_edges; + AH_Edge* limit = edge + outline->num_hedges; + FT_Int delta; + + + delta = globals->scaled.blue_refs - globals->design.blue_refs; + + for ( ; edge < limit; edge++ ) + { + if ( edge->blue_edge ) { + edge->blue_edge += delta; + } + } +} + + +#ifdef AH_DEBUG_GLYPH + +void ah_dump_edges( AH_Outline* outline ) { + AH_Edge* edges; + AH_Edge* limit; + AH_Segment* segments; + FT_Int dimension; + + + edges = outline->horz_edges; + limit = edges + outline->num_hedges; + segments = outline->horz_segments; + + for ( dimension = 1; dimension >= 0; dimension-- ) + { + AH_Edge* edge; + + + printf( "Table of %s edges:\n", + !dimension ? "vertical" : "horizontal" ); + printf( " [ index | pos | dir | link |" + " serif | blue | opos | pos ]\n" ); + + for ( edge = edges; edge < limit; edge++ ) + { + printf( " [ %5d | %4d | %5s | %4d | %5d | %c | %5.2f | %5.2f ]\n", + edge - edges, + (int)edge->fpos, + edge->dir == ah_dir_up + ? "up" + : ( edge->dir == ah_dir_down + ? "down" + : ( edge->dir == ah_dir_left + ? "left" + : ( edge->dir == ah_dir_right + ? "right" + : "none" ) ) ), + edge->link ? ( edge->link - edges ) : -1, + edge->serif ? ( edge->serif - edges ) : -1, + edge->blue_edge ? 'y' : 'n', + edge->opos / 64.0, + edge->pos / 64.0 ); + } + + edges = outline->vert_edges; + limit = edges + outline->num_vedges; + segments = outline->vert_segments; + } +} + +#endif /* AH_DEBUG_GLYPH */ + + +/* END */ diff --git a/Projects/Android/jni/rtcw/src/ft2/ahglyph.h b/Projects/Android/jni/rtcw/src/ft2/ahglyph.h new file mode 100644 index 0000000..0e50e10 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/ft2/ahglyph.h @@ -0,0 +1,86 @@ +/***************************************************************************/ +/* */ +/* ahglyph.h */ +/* */ +/* Routines used to load and analyze a given glyph before hinting */ +/* (specification). */ +/* */ +/* Copyright 2000 Catharon Productions Inc. */ +/* Author: David Turner */ +/* */ +/* This file is part of the Catharon Typography Project and shall only */ +/* be used, modified, and distributed under the terms of the Catharon */ +/* Open Source License that should come with this file under the name */ +/* `CatharonLicense.txt'. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/* Note that this license is compatible with the FreeType license. */ +/* */ +/***************************************************************************/ + + +#ifndef AHGLYPH_H +#define AHGLYPH_H + + +#include "ahtypes.h" + + +typedef enum AH_UV_ +{ + ah_uv_fxy, + ah_uv_fyx, + ah_uv_oxy, + ah_uv_oyx, + ah_uv_ox, + ah_uv_oy, + ah_uv_yx, + ah_uv_xy /* should always be last! */ + +} AH_UV; + + +LOCAL_DEF +void ah_setup_uv( AH_Outline* outline, + AH_UV source ); + + +/* AH_Outline functions - they should be typically called in this order */ + +LOCAL_DEF +FT_Error ah_outline_new( FT_Memory memory, + AH_Outline** aoutline ); + +LOCAL_DEF +FT_Error ah_outline_load( AH_Outline* outline, + FT_Face face ); + +LOCAL_DEF +void ah_outline_compute_segments( AH_Outline* outline ); + +LOCAL_DEF +void ah_outline_link_segments( AH_Outline* outline ); + +LOCAL_DEF +void ah_outline_detect_features( AH_Outline* outline ); + +LOCAL_DEF +void ah_outline_compute_blue_edges( AH_Outline* outline, + AH_Face_Globals* globals ); + +LOCAL_DEF +void ah_outline_scale_blue_edges( AH_Outline* outline, + AH_Face_Globals* globals ); + +LOCAL_DEF +void ah_outline_save( AH_Outline* outline, AH_Loader* loader ); + +LOCAL_DEF +void ah_outline_done( AH_Outline* outline ); + + +#endif /* AHGLYPH_H */ + + +/* END */ diff --git a/Projects/Android/jni/rtcw/src/ft2/ahhint.c b/Projects/Android/jni/rtcw/src/ft2/ahhint.c new file mode 100644 index 0000000..5cf8f08 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/ft2/ahhint.c @@ -0,0 +1,1362 @@ +/***************************************************************************/ +/* */ +/* ahhint.c */ +/* */ +/* Glyph hinter (body). */ +/* */ +/* Copyright 2000 Catharon Productions Inc. */ +/* Author: David Turner */ +/* */ +/* This file is part of the Catharon Typography Project and shall only */ +/* be used, modified, and distributed under the terms of the Catharon */ +/* Open Source License that should come with this file under the name */ +/* `CatharonLicense.txt'. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/* Note that this license is compatible with the FreeType license. */ +/* */ +/***************************************************************************/ + + +#include "ahhint.h" +#include "ahglyph.h" +#include "ahangles.h" + +#include "ftoutln.h" + + +#define FACE_GLOBALS( face ) ( (AH_Face_Globals*)( face )->autohint.data ) + +#define AH_USE_IUP + + +/*************************************************************************/ +/*************************************************************************/ +/**** ****/ +/**** Hinting routines ****/ +/**** ****/ +/*************************************************************************/ +/*************************************************************************/ + + +static int disable_horz_edges = 0; +static int disable_vert_edges = 0; + + +/* snap a given width in scaled coordinates to one of the */ +/* current standard widths */ +static +FT_Pos ah_snap_width( FT_Pos* widths, + FT_Int count, + FT_Pos width ) { + int n; + FT_Pos best = 64 + 32 + 2; + FT_Pos reference = width; + + + for ( n = 0; n < count; n++ ) + { + FT_Pos w; + FT_Pos dist; + + + w = widths[n]; + dist = width - w; + if ( dist < 0 ) { + dist = -dist; + } + if ( dist < best ) { + best = dist; + reference = w; + } + } + + if ( width >= reference ) { + width -= 0x21; + if ( width < reference ) { + width = reference; + } + } else + { + width += 0x21; + if ( width > reference ) { + width = reference; + } + } + + return width; +} + + +/* align one stem edge relative to the previous stem edge */ +static +void ah_align_linked_edge( AH_Hinter* hinter, + AH_Edge* base_edge, + AH_Edge* stem_edge, + int vertical ) { + FT_Pos dist = stem_edge->opos - base_edge->opos; + AH_Globals* globals = &hinter->globals->scaled; + FT_Pos sign = 1; + + + if ( dist < 0 ) { + dist = -dist; + sign = -1; + } + + if ( vertical ) { + dist = ah_snap_width( globals->heights, globals->num_heights, dist ); + + /* in the case of vertical hinting, always round */ + /* the stem heights to integer pixels */ + if ( dist >= 64 ) { + dist = ( dist + 16 ) & - 64; + } else { + dist = 64; + } + } else + { + dist = ah_snap_width( globals->widths, globals->num_widths, dist ); + + if ( hinter->flags & ah_hinter_monochrome ) { + /* monochrome horizontal hinting: snap widths to integer pixels */ + /* with a different threshold */ + if ( dist < 64 ) { + dist = 64; + } else { + dist = ( dist + 32 ) & - 64; + } + } else + { + /* for horizontal anti-aliased hinting, we adopt a more subtle */ + /* approach: we strengthen small stems, round stems whose size */ + /* is between 1 and 2 pixels to an integer, otherwise nothing */ + if ( dist < 48 ) { + dist = ( dist + 64 ) >> 1; + } else if ( dist < 128 ) { + dist = ( dist + 42 ) & - 64; + } + } + } + + stem_edge->pos = base_edge->pos + sign * dist; +} + + +static +void ah_align_serif_edge( AH_Hinter* hinter, + AH_Edge* base, + AH_Edge* serif ) { + FT_Pos dist; + FT_Pos sign = 1; + + UNUSED( hinter ); + + + dist = serif->opos - base->opos; + if ( dist < 0 ) { + dist = -dist; + sign = -1; + } + + /* do not strengthen serifs */ + if ( base->flags & ah_edge_done ) { + if ( dist > 64 ) { + dist = ( dist + 16 ) & - 64; + } else if ( dist <= 32 ) { + dist = ( dist + 33 ) >> 1; + } + } + + serif->pos = base->pos + sign * dist; +} + + +/*************************************************************************/ +/*************************************************************************/ +/*************************************************************************/ +/**** ****/ +/**** E D G E H I N T I N G ****/ +/**** ****/ +/*************************************************************************/ +/*************************************************************************/ +/*************************************************************************/ + + +/* Another alternative edge hinting algorithm */ +static +void ah_hint_edges_3( AH_Hinter* hinter ) { + AH_Edge* edges; + AH_Edge* edge_limit; + AH_Outline* outline = hinter->glyph; + FT_Int dimension; + + + edges = outline->horz_edges; + edge_limit = edges + outline->num_hedges; + + for ( dimension = 1; dimension >= 0; dimension-- ) + { + AH_Edge* edge; + AH_Edge* before = 0; + AH_Edge* after = 0; + AH_Edge* anchor = 0; + int has_serifs = 0; + + + if ( disable_vert_edges && !dimension ) { + goto Next_Dimension; + } + + if ( disable_horz_edges && dimension ) { + goto Next_Dimension; + } + + /* we begin by aligning all stems relative to the blue zone */ + /* if needed -- that's only for horizontal edges */ + if ( dimension ) { + for ( edge = edges; edge < edge_limit; edge++ ) + { + FT_Pos* blue; + AH_Edge *edge1, *edge2; + + + if ( edge->flags & ah_edge_done ) { + continue; + } + + blue = edge->blue_edge; + edge1 = 0; + edge2 = edge->link; + + if ( blue ) { + edge1 = edge; + } else if ( edge2 && edge2->blue_edge ) { + blue = edge2->blue_edge; + edge1 = edge2; + edge2 = edge; + } + + if ( !edge1 ) { + continue; + } + + edge1->pos = blue[0]; + edge1->flags |= ah_edge_done; + + if ( edge2 && !edge2->blue_edge ) { + ah_align_linked_edge( hinter, edge1, edge2, dimension ); + edge2->flags |= ah_edge_done; + } + + if ( !anchor ) { + anchor = edge; + } + } + } + + /* now, we will align all stem edges, trying to maintain the */ + /* relative order of stems in the glyph.. */ + before = 0; + after = 0; + for ( edge = edges; edge < edge_limit; edge++ ) + { + AH_Edge *edge2; + + + if ( edge->flags & ah_edge_done ) { + continue; + } + + /* skip all non-stem edges */ + edge2 = edge->link; + if ( !edge2 ) { + has_serifs++; + continue; + } + + /* now, align the stem */ + + /* this should not happen, but it's better to be safe.. */ + if ( edge2->blue_edge || edge2 < edge ) { + +#if 0 + printf( "strange blue alignement, edge %d to %d\n", + edge - edges, edge2 - edges ); +#endif + + ah_align_linked_edge( hinter, edge2, edge, dimension ); + edge->flags |= ah_edge_done; + continue; + } + + { + FT_Bool min = 0; + FT_Pos delta; + + if ( !anchor ) { + edge->pos = ( edge->opos + 32 ) & - 64; + anchor = edge; + } else { + edge->pos = anchor->pos + + ( ( edge->opos - anchor->opos + 32 ) & - 64 ); + } + + edge->flags |= ah_edge_done; + + if ( edge > edges && edge->pos < edge[-1].pos ) { + edge->pos = edge[-1].pos; + min = 1; + } + + ah_align_linked_edge( hinter, edge, edge2, dimension ); + delta = 0; + if ( edge2 + 1 < edge_limit && + edge2[1].flags & ah_edge_done ) { + delta = edge2[1].pos - edge2->pos; + } + + if ( delta < 0 ) { + edge2->pos += delta; + if ( !min ) { + edge->pos += delta; + } + } + edge2->flags |= ah_edge_done; + } + } + + if ( !has_serifs ) { + goto Next_Dimension; + } + + /* now, hint the remaining edges (serifs and single) in order */ + /* to complete our processing */ + for ( edge = edges; edge < edge_limit; edge++ ) + { + if ( edge->flags & ah_edge_done ) { + continue; + } + + if ( edge->serif ) { + ah_align_serif_edge( hinter, edge->serif, edge ); + } else if ( !anchor ) { + edge->pos = ( edge->opos + 32 ) & - 64; + anchor = edge; + } else { + edge->pos = anchor->pos + + ( ( edge->opos - anchor->opos + 32 ) & - 64 ); + } + + edge->flags |= ah_edge_done; + + if ( edge > edges && edge->pos < edge[-1].pos ) { + edge->pos = edge[-1].pos; + } + + if ( edge + 1 < edge_limit && + edge[1].flags & ah_edge_done && + edge->pos > edge[1].pos ) { + edge->pos = edge[1].pos; + } + } + +Next_Dimension: + edges = outline->vert_edges; + edge_limit = edges + outline->num_vedges; + } +} + + +LOCAL_FUNC +void ah_hinter_hint_edges( AH_Hinter* hinter, + int no_horz_edges, + int no_vert_edges ) { + disable_horz_edges = no_horz_edges; + disable_vert_edges = no_vert_edges; + + /* AH_Interpolate_Blue_Edges( hinter ); -- doesn't seem to help */ + /* reduce the problem of the disappearing eye in the `e' of Times... */ + /* also, creates some artifacts near the blue zones? */ + { + ah_hint_edges_3( hinter ); + +#if 0 + /* outline optimizer removed temporarily */ + if ( hinter->flags & ah_hinter_optimize ) { + AH_Optimizer opt; + + + if ( !AH_Optimizer_Init( &opt, hinter->glyph, hinter->memory ) ) { + AH_Optimizer_Compute( &opt ); + AH_Optimizer_Done( &opt ); + } + } +#endif + + } +} + + +/*************************************************************************/ +/*************************************************************************/ +/*************************************************************************/ +/**** ****/ +/**** P O I N T H I N T I N G ****/ +/**** ****/ +/*************************************************************************/ +/*************************************************************************/ +/*************************************************************************/ + +static +void ah_hinter_align_edge_points( AH_Hinter* hinter ) { + AH_Outline* outline = hinter->glyph; + AH_Edge* edges; + AH_Edge* edge_limit; + FT_Int dimension; + + + edges = outline->horz_edges; + edge_limit = edges + outline->num_hedges; + + for ( dimension = 1; dimension >= 0; dimension-- ) + { + AH_Edge* edge; + AH_Edge* before; + AH_Edge* after; + + + before = 0; + after = 0; + + edge = edges; + for ( ; edge < edge_limit; edge++ ) + { + /* move the points of each segment */ + /* in each edge to the edge's position */ + AH_Segment* seg = edge->first; + + + do + { + AH_Point* point = seg->first; + + + for (;; ) + { + if ( dimension ) { + point->y = edge->pos; + point->flags |= ah_flah_touch_y; + } else + { + point->x = edge->pos; + point->flags |= ah_flah_touch_x; + } + + if ( point == seg->last ) { + break; + } + + point = point->next; + } + + seg = seg->edge_next; + + } while ( seg != edge->first ); + } + + edges = outline->vert_edges; + edge_limit = edges + outline->num_vedges; + } +} + + +/* hint the strong points -- this is equivalent to the TrueType `IP' */ +static +void ah_hinter_align_strong_points( AH_Hinter* hinter ) { + AH_Outline* outline = hinter->glyph; + FT_Int dimension; + AH_Edge* edges; + AH_Edge* edge_limit; + AH_Point* points; + AH_Point* point_limit; + AH_Flags touch_flag; + + + points = outline->points; + point_limit = points + outline->num_points; + + edges = outline->horz_edges; + edge_limit = edges + outline->num_hedges; + touch_flag = ah_flah_touch_y; + + for ( dimension = 1; dimension >= 0; dimension-- ) + { + AH_Point* point; + AH_Edge* edge; + AH_Edge* before; + AH_Edge* after; + + + before = 0; + after = 0; + + if ( edges < edge_limit ) { + for ( point = points; point < point_limit; point++ ) + { + FT_Pos u, ou, fu; /* point position */ + FT_Pos delta; + + + if ( point->flags & touch_flag ) { + continue; + } + +#ifndef AH_OPTION_NO_WEAK_INTERPOLATION + /* if this point is candidate to weak interpolation, we will */ + /* interpolate it after all strong points have been processed */ + if ( point->flags & ah_flah_weak_interpolation ) { + continue; + } +#endif + + if ( dimension ) { + u = point->fy; + ou = point->oy; + } else + { + u = point->fx; + ou = point->ox; + } + + fu = u; + + /* is the point before the first edge? */ + edge = edges; + delta = edge->fpos - u; + if ( delta >= 0 ) { + u = edge->pos - ( edge->opos - ou ); + goto Store_Point; + } + + /* is the point after the last edge ? */ + edge = edge_limit - 1; + delta = u - edge->fpos; + if ( delta >= 0 ) { + u = edge->pos + ( ou - edge->opos ); + goto Store_Point; + } + + /* otherwise, interpolate the point in between */ + { + AH_Edge* before = 0; + AH_Edge* after = 0; + + + for ( edge = edges; edge < edge_limit; edge++ ) + { + if ( u == edge->fpos ) { + u = edge->pos; + goto Store_Point; + } + if ( u < edge->fpos ) { + break; + } + before = edge; + } + + for ( edge = edge_limit - 1; edge >= edges; edge-- ) + { + if ( u == edge->fpos ) { + u = edge->pos; + goto Store_Point; + } + if ( u > edge->fpos ) { + break; + } + after = edge; + } + + /* assert( before && after && before != after ) */ + u = before->pos + FT_MulDiv( fu - before->fpos, + after->pos - before->pos, + after->fpos - before->fpos ); + } + +Store_Point: + + /* save the point position */ + if ( dimension ) { + point->y = u; + } else { + point->x = u; + } + + point->flags |= touch_flag; + } + } + + edges = outline->vert_edges; + edge_limit = edges + outline->num_vedges; + touch_flag = ah_flah_touch_x; + } +} + + +#ifndef AH_OPTION_NO_WEAK_INTERPOLATION + +static +void ah_iup_shift( AH_Point* p1, + AH_Point* p2, + AH_Point* ref ) { + AH_Point* p; + FT_Pos delta = ref->u - ref->v; + + + for ( p = p1; p < ref; p++ ) + p->u = p->v + delta; + + for ( p = ref + 1; p <= p2; p++ ) + p->u = p->v + delta; +} + + +static +void ah_iup_interp( AH_Point* p1, + AH_Point* p2, + AH_Point* ref1, + AH_Point* ref2 ) { + AH_Point* p; + FT_Pos u; + FT_Pos v1 = ref1->v; + FT_Pos v2 = ref2->v; + FT_Pos d1 = ref1->u - v1; + FT_Pos d2 = ref2->u - v2; + + + if ( p1 > p2 ) { + return; + } + + if ( v1 == v2 ) { + for ( p = p1; p <= p2; p++ ) + { + FT_Pos u = p->v; + + + if ( u <= v1 ) { + u += d1; + } else { + u += d2; + } + + p->u = u; + } + return; + } + + if ( v1 < v2 ) { + for ( p = p1; p <= p2; p++ ) + { + u = p->v; + + if ( u <= v1 ) { + u += d1; + } else if ( u >= v2 ) { + u += d2; + } else { + u = ref1->u + FT_MulDiv( u - v1, ref2->u - ref1->u, v2 - v1 ); + } + + p->u = u; + } + } else + { + for ( p = p1; p <= p2; p++ ) + { + u = p->v; + + if ( u <= v2 ) { + u += d2; + } else if ( u >= v1 ) { + u += d1; + } else { + u = ref1->u + FT_MulDiv( u - v1, ref2->u - ref1->u, v2 - v1 ); + } + + p->u = u; + } + } +} + + +/* interpolate weak points -- this is equivalent to the TrueType `IUP' */ +static +void ah_hinter_align_weak_points( AH_Hinter* hinter ) { + AH_Outline* outline = hinter->glyph; + FT_Int dimension; + AH_Edge* edges; + AH_Edge* edge_limit; + AH_Point* points; + AH_Point* point_limit; + AH_Point** contour_limit; + AH_Flags touch_flag; + + + points = outline->points; + point_limit = points + outline->num_points; + + /* PASS 1: Move segment points to edge positions */ + + edges = outline->horz_edges; + edge_limit = edges + outline->num_hedges; + touch_flag = ah_flah_touch_y; + + contour_limit = outline->contours + outline->num_contours; + + ah_setup_uv( outline, ah_uv_oy ); + + for ( dimension = 1; dimension >= 0; dimension-- ) + { + AH_Point* point; + AH_Point* end_point; + AH_Point* first_point; + AH_Point** contour; + + + point = points; + contour = outline->contours; + + for ( ; contour < contour_limit; contour++ ) + { + point = *contour; + end_point = point->prev; + first_point = point; + + while ( point <= end_point && !( point->flags & touch_flag ) ) + point++; + + if ( point <= end_point ) { + AH_Point* first_touched = point; + AH_Point* cur_touched = point; + + + point++; + while ( point <= end_point ) + { + if ( point->flags & touch_flag ) { + /* we found two successive touched points; we interpolate */ + /* all contour points between them */ + ah_iup_interp( cur_touched + 1, point - 1, + cur_touched, point ); + cur_touched = point; + } + point++; + } + + if ( cur_touched == first_touched ) { + /* this is a special case: only one point was touched in the */ + /* contour; we thus simply shift the whole contour */ + ah_iup_shift( first_point, end_point, cur_touched ); + } else + { + /* now interpolate after the last touched point to the end */ + /* of the contour */ + ah_iup_interp( cur_touched + 1, end_point, + cur_touched, first_touched ); + + /* if the first contour point isn't touched, interpolate */ + /* from the contour start to the first touched point */ + if ( first_touched > points ) { + ah_iup_interp( first_point, first_touched - 1, + cur_touched, first_touched ); + } + } + } + } + + /* now save the interpolated values back to x/y */ + if ( dimension ) { + for ( point = points; point < point_limit; point++ ) + point->y = point->u; + + touch_flag = ah_flah_touch_x; + ah_setup_uv( outline, ah_uv_ox ); + } else + { + for ( point = points; point < point_limit; point++ ) + point->x = point->u; + + break; /* exit loop */ + } + } +} + +#endif /* !AH_OPTION_NO_WEAK_INTERPOLATION */ + + +LOCAL_FUNC +void ah_hinter_align_points( AH_Hinter* hinter ) { + ah_hinter_align_edge_points( hinter ); + +#ifndef AH_OPTION_NO_STRONG_INTERPOLATION + ah_hinter_align_strong_points( hinter ); +#endif + +#ifndef AH_OPTION_NO_WEAK_INTERPOLATION + ah_hinter_align_weak_points( hinter ); +#endif +} + + +/*************************************************************************/ +/*************************************************************************/ +/*************************************************************************/ +/**** ****/ +/**** H I N T E R O B J E C T M E T H O D S ****/ +/**** ****/ +/*************************************************************************/ +/*************************************************************************/ +/*************************************************************************/ + + +/* scale and fit the global metrics */ +static +void ah_hinter_scale_globals( AH_Hinter* hinter, + FT_Fixed x_scale, + FT_Fixed y_scale ) { + FT_Int n; + AH_Face_Globals* globals = hinter->globals; + AH_Globals* design = &globals->design; + AH_Globals* scaled = &globals->scaled; + + + /* copy content */ + *scaled = *design; + + /* scale the standard widths & heights */ + for ( n = 0; n < design->num_widths; n++ ) + scaled->widths[n] = FT_MulFix( design->widths[n], x_scale ); + + for ( n = 0; n < design->num_heights; n++ ) + scaled->heights[n] = FT_MulFix( design->heights[n], y_scale ); + + /* scale the blue zones */ + for ( n = 0; n < ah_blue_max; n++ ) + { + FT_Pos delta, delta2; + + + delta = design->blue_shoots[n] - design->blue_refs[n]; + delta2 = delta; + if ( delta < 0 ) { + delta2 = -delta2; + } + delta2 = FT_MulFix( delta2, y_scale ); + + if ( delta2 < 32 ) { + delta2 = 0; + } else if ( delta2 < 64 ) { + delta2 = 32 + ( ( ( delta2 - 32 ) + 16 ) & - 32 ); + } else { + delta2 = ( delta2 + 32 ) & - 64; + } + + if ( delta < 0 ) { + delta2 = -delta2; + } + + scaled->blue_refs[n] = + ( FT_MulFix( design->blue_refs[n], y_scale ) + 32 ) & - 64; + scaled->blue_shoots[n] = scaled->blue_refs[n] + delta2; + } + + globals->x_scale = x_scale; + globals->y_scale = y_scale; +} + + +static +void ah_hinter_align( AH_Hinter* hinter ) { + ah_hinter_align_edge_points( hinter ); + ah_hinter_align_points( hinter ); +} + + +/* finalize a hinter object */ +void ah_hinter_done( AH_Hinter* hinter ) { + if ( hinter ) { + FT_Memory memory = hinter->memory; + + + ah_loader_done( hinter->loader ); + ah_outline_done( hinter->glyph ); + + /* note: the `globals' pointer is _not_ owned by the hinter */ + /* but by the current face object, we don't need to */ + /* release it */ + hinter->globals = 0; + hinter->face = 0; + + FREE( hinter ); + } +} + + +/* create a new empty hinter object */ +FT_Error ah_hinter_new( FT_Library library, + AH_Hinter** ahinter ) { + AH_Hinter* hinter = 0; + FT_Memory memory = library->memory; + FT_Error error; + + + *ahinter = 0; + + /* allocate object */ + if ( ALLOC( hinter, sizeof( *hinter ) ) ) { + goto Exit; + } + + hinter->memory = memory; + hinter->flags = 0; + + /* allocate outline and loader */ + error = ah_outline_new( memory, &hinter->glyph ) || + ah_loader_new( memory, &hinter->loader ) || + ah_loader_create_extra( hinter->loader ); + if ( error ) { + goto Exit; + } + + *ahinter = hinter; + +Exit: + if ( error ) { + ah_hinter_done( hinter ); + } + + return error; +} + + +/* create a face's autohint globals */ +FT_Error ah_hinter_new_face_globals( AH_Hinter* hinter, + FT_Face face, + AH_Globals* globals ) { + FT_Error error; + FT_Memory memory = hinter->memory; + AH_Face_Globals* face_globals; + + + if ( ALLOC( face_globals, sizeof( *face_globals ) ) ) { + goto Exit; + } + + hinter->face = face; + hinter->globals = face_globals; + + if ( globals ) { + face_globals->design = *globals; + } else { + ah_hinter_compute_globals( hinter ); + } + + face->autohint.data = face_globals; + face->autohint.finalizer = (FT_Generic_Finalizer) + ah_hinter_done_face_globals; + face_globals->face = face; + +Exit: + return error; +} + + +/* discard a face's autohint globals */ +void ah_hinter_done_face_globals( AH_Face_Globals* globals ) { + FT_Face face = globals->face; + FT_Memory memory = face->memory; + + + FREE( globals ); +} + + +static +FT_Error ah_hinter_load( AH_Hinter* hinter, + FT_UInt glyph_index, + FT_UInt load_flags, + FT_UInt depth ) { + FT_Face face = hinter->face; + FT_GlyphSlot slot = face->glyph; + FT_Fixed x_scale = face->size->metrics.x_scale; + FT_Fixed y_scale = face->size->metrics.y_scale; + FT_Glyph_Metrics metrics; /* temporary metrics */ + FT_Error error; + AH_Outline* outline = hinter->glyph; + AH_Loader* gloader = hinter->loader; + FT_Bool no_horz_hints = + ( load_flags & AH_HINT_NO_HORZ_EDGES ) != 0; + FT_Bool no_vert_hints = + ( load_flags & AH_HINT_NO_VERT_EDGES ) != 0; + + + /* load the glyph */ + error = FT_Load_Glyph( face, glyph_index, load_flags ); + if ( error ) { + goto Exit; + } + + /* save current glyph metrics */ + metrics = slot->metrics; + + switch ( slot->format ) + { + case ft_glyph_format_outline: + /* first of all, copy the outline points in the loader's current */ + /* extra points, which is used to keep original glyph coordinates */ + error = ah_loader_check_points( gloader, slot->outline.n_points + 2, + slot->outline.n_contours ); + if ( error ) { + goto Exit; + } + + MEM_Copy( gloader->current.extra_points, slot->outline.points, + slot->outline.n_points * sizeof( FT_Vector ) ); + + MEM_Copy( gloader->current.outline.contours, slot->outline.contours, + slot->outline.n_contours * sizeof( short ) ); + + MEM_Copy( gloader->current.outline.tags, slot->outline.tags, + slot->outline.n_points * sizeof( char ) ); + + gloader->current.outline.n_points = slot->outline.n_points; + gloader->current.outline.n_contours = slot->outline.n_contours; + + /* compute original phantom points */ + hinter->pp1.x = 0; + hinter->pp1.y = 0; + hinter->pp2.x = FT_MulFix( slot->metrics.horiAdvance, x_scale ); + hinter->pp2.y = 0; + + /* be sure to check for spacing glyphs */ + if ( slot->outline.n_points == 0 ) { + goto Hint_Metrics; + } + + /* now, load the slot image into the auto-outline, and run the */ + /* automatic hinting process */ + error = ah_outline_load( outline, face ); /* XXX: change to slot */ + if ( error ) { + goto Exit; + } + + /* perform feature detection */ + ah_outline_detect_features( outline ); + + if ( !no_horz_hints ) { + ah_outline_compute_blue_edges( outline, hinter->globals ); + ah_outline_scale_blue_edges( outline, hinter->globals ); + } + + /* perform alignment control */ + ah_hinter_hint_edges( hinter, no_horz_hints, no_vert_hints ); + ah_hinter_align( hinter ); + + /* now save the current outline into the loader's current table */ + ah_outline_save( outline, gloader ); + + /* we now need to hint the metrics according to the change in */ + /* width/positioning that occured during the hinting process */ + { + FT_Pos old_width, new_width; + FT_Pos old_advance, new_advance; + FT_Pos old_lsb, new_lsb; + AH_Edge* edge1 = outline->vert_edges; /* leftmost edge */ + AH_Edge* edge2 = edge1 + + outline->num_vedges - 1; /* rightmost edge */ + + + old_width = edge2->opos - edge1->opos; + new_width = edge2->pos - edge1->pos; + + old_advance = hinter->pp2.x; + old_lsb = edge1->opos; + new_lsb = edge1->pos; + + new_advance = old_advance + + ( new_width + new_lsb - old_width - old_lsb ); + + hinter->pp1.x = ( ( new_lsb - old_lsb ) + 32 ) & - 64; + hinter->pp2.x = ( ( edge2->pos + + ( old_advance - edge2->opos ) ) + 32 ) & - 64; + } + + /* good, we simply add the glyph to our loader's base */ + ah_loader_add( gloader ); + break; + + case ft_glyph_format_composite: + { + FT_UInt nn, num_subglyphs = slot->num_subglyphs; + FT_UInt num_base_subgs, start_point, start_contour; + FT_SubGlyph* subglyph; + + + start_point = gloader->base.outline.n_points; + start_contour = gloader->base.outline.n_contours; + + /* first of all, copy the subglyph descriptors in the glyph loader */ + error = ah_loader_check_subglyphs( gloader, num_subglyphs ); + if ( error ) { + goto Exit; + } + + MEM_Copy( gloader->current.subglyphs, slot->subglyphs, + num_subglyphs * sizeof( FT_SubGlyph ) ); + + gloader->current.num_subglyphs = num_subglyphs; + num_base_subgs = gloader->base.num_subglyphs; + + /* now, read each subglyph independently */ + for ( nn = 0; nn < num_subglyphs; nn++ ) + { + FT_Vector pp1, pp2; + FT_Pos x, y; + FT_UInt num_points, num_new_points, num_base_points; + + + /* gloader.current.subglyphs can change during glyph loading due */ + /* to re-allocation -- we must recompute the current subglyph on */ + /* each iteration */ + subglyph = gloader->base.subglyphs + num_base_subgs + nn; + + pp1 = hinter->pp1; + pp2 = hinter->pp2; + + num_base_points = gloader->base.outline.n_points; + + error = ah_hinter_load( hinter, subglyph->index, + load_flags, depth + 1 ); + if ( error ) { + goto Exit; + } + + /* recompute subglyph pointer */ + subglyph = gloader->base.subglyphs + num_base_subgs + nn; + + if ( subglyph->flags & FT_SUBGLYPH_FLAG_USE_MY_METRICS ) { + pp1 = hinter->pp1; + pp2 = hinter->pp2; + } else + { + hinter->pp1 = pp1; + hinter->pp2 = pp2; + } + + num_points = gloader->base.outline.n_points; + num_new_points = num_points - num_base_points; + + /* now perform the transform required for this subglyph */ + + if ( subglyph->flags & ( FT_SUBGLYPH_FLAG_SCALE | + FT_SUBGLYPH_FLAG_XY_SCALE | + FT_SUBGLYPH_FLAG_2X2 ) ) { + FT_Vector* cur = gloader->base.outline.points + + num_base_points; + FT_Vector* org = gloader->base.extra_points + + num_base_points; + FT_Vector* limit = cur + num_new_points; + + + for ( ; cur < limit; cur++, org++ ) + { + FT_Vector_Transform( cur, &subglyph->transform ); + FT_Vector_Transform( org, &subglyph->transform ); + } + } + + /* apply offset */ + + if ( !( subglyph->flags & FT_SUBGLYPH_FLAG_ARGS_ARE_XY_VALUES ) ) { + FT_Int k = subglyph->arg1; + FT_UInt l = subglyph->arg2; + FT_Vector* p1; + FT_Vector* p2; + + + if ( start_point + k >= num_base_points || + l >= (FT_UInt)num_new_points ) { + error = FT_Err_Invalid_Composite; + goto Exit; + } + + l += num_base_points; + + /* for now, only use the current point coordinates */ + /* we may consider another approach in the near future */ + p1 = gloader->base.outline.points + start_point + k; + p2 = gloader->base.outline.points + start_point + l; + + x = p1->x - p2->x; + y = p1->y - p2->y; + } else + { + x = FT_MulFix( subglyph->arg1, x_scale ); + y = FT_MulFix( subglyph->arg2, y_scale ); + + x = ( x + 32 ) & - 64; + y = ( y + 32 ) & - 64; + } + + { + FT_Outline dummy = gloader->base.outline; + + + dummy.points += num_base_points; + dummy.n_points = num_new_points; + + FT_Outline_Translate( &dummy, x, y ); + } + } + } + break; + + default: + /* we don't support other formats (yet?) */ + error = FT_Err_Unimplemented_Feature; + } + +Hint_Metrics: + if ( depth == 0 ) { + FT_BBox bbox; + + + /* we must translate our final outline by -pp1.x, and compute */ + /* the new metrics */ + if ( hinter->pp1.x ) { + FT_Outline_Translate( &gloader->base.outline, -hinter->pp1.x, 0 ); + } + + FT_Outline_Get_CBox( &gloader->base.outline, &bbox ); + bbox.xMin &= -64; + bbox.yMin &= -64; + bbox.xMax = ( bbox.xMax + 63 ) & - 64; + bbox.yMax = ( bbox.yMax + 63 ) & - 64; + + slot->metrics.width = bbox.xMax - bbox.xMin; + slot->metrics.height = bbox.yMax - bbox.yMin; + slot->metrics.horiBearingX = bbox.xMin; + slot->metrics.horiBearingY = bbox.yMax; + slot->metrics.horiAdvance = hinter->pp2.x - hinter->pp1.x; + /* XXX: TO DO - slot->linearHoriAdvance */ + + /* now copy outline into glyph slot */ + ah_loader_rewind( slot->loader ); + error = ah_loader_copy_points( slot->loader, gloader ); + if ( error ) { + goto Exit; + } + + slot->outline = slot->loader->base.outline; + slot->format = ft_glyph_format_outline; + } + +Exit: + return error; +} + + +/* load and hint a given glyph */ +FT_Error ah_hinter_load_glyph( AH_Hinter* hinter, + FT_GlyphSlot slot, + FT_Size size, + FT_UInt glyph_index, + FT_Int load_flags ) { + FT_Face face = slot->face; + FT_Error error; + FT_Fixed x_scale = size->metrics.x_scale; + FT_Fixed y_scale = size->metrics.y_scale; + AH_Face_Globals* face_globals = FACE_GLOBALS( face ); + + + /* first of all, we need to check that we're using the correct face and */ + /* global hints to load the glyph */ + if ( hinter->face != face || hinter->globals != face_globals ) { + hinter->face = face; + if ( !face_globals ) { + error = ah_hinter_new_face_globals( hinter, face, 0 ); + if ( error ) { + goto Exit; + } + } + hinter->globals = FACE_GLOBALS( face ); + face_globals = FACE_GLOBALS( face ); + } + + /* now, we must check the current character pixel size to see if we */ + /* need to rescale the global metrics */ + if ( face_globals->x_scale != x_scale || + face_globals->y_scale != y_scale ) { + ah_hinter_scale_globals( hinter, x_scale, y_scale ); + } + + load_flags |= FT_LOAD_NO_SCALE | FT_LOAD_NO_RECURSE; + + ah_loader_rewind( hinter->loader ); + + error = ah_hinter_load( hinter, glyph_index, load_flags, 0 ); + +Exit: + return error; +} + + +/* retrieve a face's autohint globals for client applications */ +void ah_hinter_get_global_hints( AH_Hinter* hinter, + FT_Face face, + void** global_hints, + long* global_len ) { + AH_Globals* globals = 0; + FT_Memory memory = hinter->memory; + FT_Error error; + + + /* allocate new master globals */ + if ( ALLOC( globals, sizeof( *globals ) ) ) { + goto Fail; + } + + /* compute face globals if needed */ + if ( !FACE_GLOBALS( face ) ) { + error = ah_hinter_new_face_globals( hinter, face, 0 ); + if ( error ) { + goto Fail; + } + } + + *globals = FACE_GLOBALS( face )->design; + *global_hints = globals; + *global_len = sizeof( *globals ); + + return; + +Fail: + FREE( globals ); + + *global_hints = 0; + *global_len = 0; +} + + +void ah_hinter_done_global_hints( AH_Hinter* hinter, + void* global_hints ) { + FT_Memory memory = hinter->memory; + + + FREE( global_hints ); +} + + +/* END */ diff --git a/Projects/Android/jni/rtcw/src/ft2/ahhint.h b/Projects/Android/jni/rtcw/src/ft2/ahhint.h new file mode 100644 index 0000000..cefc8b1 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/ft2/ahhint.h @@ -0,0 +1,65 @@ +/***************************************************************************/ +/* */ +/* ahhint.h */ +/* */ +/* Glyph hinter (declaration). */ +/* */ +/* Copyright 2000 Catharon Productions Inc. */ +/* Author: David Turner */ +/* */ +/* This file is part of the Catharon Typography Project and shall only */ +/* be used, modified, and distributed under the terms of the Catharon */ +/* Open Source License that should come with this file under the name */ +/* `CatharonLicense.txt'. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/* Note that this license is compatible with the FreeType license. */ +/* */ +/***************************************************************************/ + + +#ifndef AHHINT_H +#define AHHINT_H + + + +#include "ahglobal.h" + + +#define AH_HINT_DEFAULT 0 +#define AH_HINT_NO_ALIGNMENT 1 +#define AH_HINT_NO_HORZ_EDGES 0x20000L +#define AH_HINT_NO_VERT_EDGES 0x40000L + + +/* create a new empty hinter object */ +FT_Error ah_hinter_new( FT_Library library, + AH_Hinter** ahinter ); + +/* Load a hinted glyph in the hinter */ +FT_Error ah_hinter_load_glyph( AH_Hinter* hinter, + FT_GlyphSlot slot, + FT_Size size, + FT_UInt glyph_index, + FT_Int load_flags ); + +/* finalize a hinter object */ +void ah_hinter_done( AH_Hinter* hinter ); + +LOCAL_DEF +void ah_hinter_done_face_globals( AH_Face_Globals* globals ); + +void ah_hinter_get_global_hints( AH_Hinter* hinter, + FT_Face face, + void** global_hints, + long* global_len ); + +void ah_hinter_done_global_hints( AH_Hinter* hinter, + void* global_hints ); + + +#endif /* AHHINT_H */ + + +/* END */ diff --git a/Projects/Android/jni/rtcw/src/ft2/ahloader.h b/Projects/Android/jni/rtcw/src/ft2/ahloader.h new file mode 100644 index 0000000..2898ce7 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/ft2/ahloader.h @@ -0,0 +1,123 @@ +/***************************************************************************/ +/* */ +/* ahloader.h */ +/* */ +/* Glyph loader for the auto-hinting module (declaration only). */ +/* */ +/* Copyright 2000 Catharon Productions Inc. */ +/* Author: David Turner */ +/* */ +/* This file is part of the Catharon Typography Project and shall only */ +/* be used, modified, and distributed under the terms of the Catharon */ +/* Open Source License that should come with this file under the name */ +/* `CatharonLicense.txt'. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/* Note that this license is compatible with the FreeType license. */ +/* */ +/***************************************************************************/ + + +/*************************************************************************/ +/* */ +/* This defines the AH_GlyphLoader type in two different ways: */ +/* */ +/* - If the module is compiled within FreeType 2, the type is simply a */ +/* typedef to FT_GlyphLoader. */ +/* */ +/* - If the module is compiled as a standalone object, AH_GlyphLoader */ +/* has its own implementation. */ +/* */ +/*************************************************************************/ + + +#ifndef AHLOADER_H +#define AHLOADER_H + +#ifdef _STANDALONE_ + +typedef struct AH_GlyphLoad_ +{ + FT_Outline outline; /* outline */ + FT_UInt num_subglyphs; /* number of subglyphs */ + FT_SubGlyph* subglyphs; /* subglyphs */ + FT_Vector* extra_points; /* extra points table */ + +} AH_GlyphLoad; + + +struct AH_GlyphLoader_ +{ + FT_Memory memory; + FT_UInt max_points; + FT_UInt max_contours; + FT_UInt max_subglyphs; + FT_Bool use_extra; + + AH_GlyphLoad base; + AH_GlyphLoad current; + + void* other; /* for possible future extensions */ +}; + + +LOCAL_DEF +FT_Error AH_GlyphLoader_New( FT_Memory memory, + AH_GlyphLoader** aloader ); + +LOCAL_DEF +FT_Error AH_GlyphLoader_Create_Extra( AH_GlyphLoader* loader ); + +LOCAL_DEF +void AH_GlyphLoader_Done( AH_GlyphLoader* loader ); + +LOCAL_DEF +void AH_GlyphLoader_Reset( AH_GlyphLoader* loader ); + +LOCAL_DEF +void AH_GlyphLoader_Rewind( AH_GlyphLoader* loader ); + +LOCAL_DEF +FT_Error AH_GlyphLoader_Check_Points( AH_GlyphLoader* loader, + FT_UInt n_points, + FT_UInt n_contours ); + +LOCAL_DEF +FT_Error AH_GlyphLoader_Check_Subglyphs( AH_GlyphLoader* loader, + FT_UInt n_subs ); + +LOCAL_DEF +void AH_GlyphLoader_Prepare( AH_GlyphLoader* loader ); + +LOCAL_DEF +void AH_GlyphLoader_Add( AH_GlyphLoader* loader ); + +LOCAL_DEF +FT_Error AH_GlyphLoader_Copy_Points( AH_GlyphLoader* target, + FT_GlyphLoader* source ); + +#else /* _STANDALONE */ + +#include "ftobjs.h" + + #define AH_Load FT_GlyphLoad + #define AH_Loader FT_GlyphLoader + + #define ah_loader_new FT_GlyphLoader_New + #define ah_loader_done FT_GlyphLoader_Done + #define ah_loader_reset FT_GlyphLoader_Reset + #define ah_loader_rewind FT_GlyphLoader_Rewind + #define ah_loader_create_extra FT_GlyphLoader_Create_Extra + #define ah_loader_check_points FT_GlyphLoader_Check_Points + #define ah_loader_check_subglyphs FT_GlyphLoader_Check_Subglyphs + #define ah_loader_prepare FT_GlyphLoader_Prepare + #define ah_loader_add FT_GlyphLoader_Add + #define ah_loader_copy_points FT_GlyphLoader_Copy_Points + +#endif /* _STANDALONE_ */ + +#endif /* AHLOADER_H */ + + +/* END */ diff --git a/Projects/Android/jni/rtcw/src/ft2/ahmodule.c b/Projects/Android/jni/rtcw/src/ft2/ahmodule.c new file mode 100644 index 0000000..a183a6f --- /dev/null +++ b/Projects/Android/jni/rtcw/src/ft2/ahmodule.c @@ -0,0 +1,114 @@ +/***************************************************************************/ +/* */ +/* ahmodule.c */ +/* */ +/* Auto-hinting module implementation (declaration). */ +/* */ +/* Copyright 2000 Catharon Productions Inc. */ +/* Author: David Turner */ +/* */ +/* This file is part of the Catharon Typography Project and shall only */ +/* be used, modified, and distributed under the terms of the Catharon */ +/* Open Source License that should come with this file under the name */ +/* `CatharonLicense.txt'. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/* Note that this license is compatible with the FreeType license. */ +/* */ +/***************************************************************************/ + + +#include "ftmodule.h" + + +#include "ahhint.h" + + +typedef struct FT_AutoHinterRec_ +{ + FT_ModuleRec root; + AH_Hinter* hinter; + +} FT_AutoHinterRec; + + +static +FT_Error ft_autohinter_init( FT_AutoHinter module ) { + return ah_hinter_new( module->root.library, &module->hinter ); +} + + +static +void ft_autohinter_done( FT_AutoHinter module ) { + ah_hinter_done( module->hinter ); +} + + +static +FT_Error ft_autohinter_load( FT_AutoHinter module, + FT_GlyphSlot slot, + FT_Size size, + FT_UInt glyph_index, + FT_ULong load_flags ) { + return ah_hinter_load_glyph( module->hinter, + slot, size, glyph_index, load_flags ); +} + + +static +void ft_autohinter_reset( FT_AutoHinter module, + FT_Face face ) { + UNUSED( module ); + + if ( face->autohint.data ) { + ah_hinter_done_face_globals( ( AH_Face_Globals* )( face->autohint.data ) ); + } +} + + +static +void ft_autohinter_get_globals( FT_AutoHinter module, + FT_Face face, + void** global_hints, + long* global_len ) { + ah_hinter_get_global_hints( module->hinter, face, + global_hints, global_len ); +} + + +static +void ft_autohinter_done_globals( FT_AutoHinter module, + void* global_hints ) { + ah_hinter_done_global_hints( module->hinter, global_hints ); +} + + +static +const FT_AutoHinter_Interface autohinter_interface = +{ + ft_autohinter_reset, + ft_autohinter_load, + ft_autohinter_get_globals, + ft_autohinter_done_globals +}; + + +const FT_Module_Class autohint_module_class = +{ + ft_module_hinter, + sizeof( FT_AutoHinterRec ), + + "autohinter", + 0x10000L, /* version 1.0 of the autohinter */ + 0x20000L, /* requires FreeType 2.0 or above */ + + (const void*)&autohinter_interface, + + (FT_Module_Constructor)ft_autohinter_init, + (FT_Module_Destructor) ft_autohinter_done, + (FT_Module_Requester) 0 +}; + + +/* END */ diff --git a/Projects/Android/jni/rtcw/src/ft2/ahmodule.h b/Projects/Android/jni/rtcw/src/ft2/ahmodule.h new file mode 100644 index 0000000..c9b523c --- /dev/null +++ b/Projects/Android/jni/rtcw/src/ft2/ahmodule.h @@ -0,0 +1,32 @@ +/***************************************************************************/ +/* */ +/* ahmodule.h */ +/* */ +/* Auto-hinting module (declaration). */ +/* */ +/* Copyright 2000 Catharon Productions Inc. */ +/* Author: David Turner */ +/* */ +/* This file is part of the Catharon Typography Project and shall only */ +/* be used, modified, and distributed under the terms of the Catharon */ +/* Open Source License that should come with this file under the name */ +/* `CatharonLicense.txt'. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/* Note that this license is compatible with the FreeType license. */ +/* */ +/***************************************************************************/ + + +#ifndef AHMODULE_H +#define AHMODULE_H + +#include "ftmodule.h" + +FT_EXPORT_VAR( const FT_Module_Class ) autohint_module_class; + +#endif /* AHMODULE_H */ + + +/* END */ diff --git a/Projects/Android/jni/rtcw/src/ft2/ahoptim.c b/Projects/Android/jni/rtcw/src/ft2/ahoptim.c new file mode 100644 index 0000000..3b62c73 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/ft2/ahoptim.c @@ -0,0 +1,875 @@ +/***************************************************************************/ +/* */ +/* ahoptim.c */ +/* */ +/* FreeType auto hinting outline optimization (body). */ +/* */ +/* Copyright 2000 Catharon Productions Inc. */ +/* Author: David Turner */ +/* */ +/* This file is part of the Catharon Typography Project and shall only */ +/* be used, modified, and distributed under the terms of the Catharon */ +/* Open Source License that should come with this file under the name */ +/* `CatharonLicense.txt'. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/* Note that this license is compatible with the FreeType license. */ +/* */ +/***************************************************************************/ + + +/*************************************************************************/ +/* */ +/* This module is in charge of optimising the outlines produced by the */ +/* auto-hinter in direct mode. This is required at small pixel sizes in */ +/* order to ensure coherent spacing, among other things.. */ +/* */ +/* The technique used in this module is a simplified simulated */ +/* annealing. */ +/* */ +/*************************************************************************/ + + +#include "ftobjs.h" /* for ALLOC_ARRAY() and FREE() */ + + +#include "ahoptim.h" + + +/* define this macro to use brute force optimisation -- this is slow, */ +/* but a good way to perfect the distortion function `by hand' through */ +/* tweaking */ +#define AH_BRUTE_FORCE + + +#define xxxAH_DEBUG_OPTIM + + +#undef LOG +#ifdef AH_DEBUG_OPTIM + +#define LOG( x ) optim_log ## x + +#else + +#define LOG( x ) + +#endif /* AH_DEBUG_OPTIM */ + + +#ifdef AH_DEBUG_OPTIM + +#include +#include +#include + +#define FLOAT( x ) ( (float)( ( x ) / 64.0 ) ) + +static +void optim_log( const char* fmt, ... ) { + va_list ap; + + + va_start( ap, fmt ); + vprintf( fmt, ap ); + va_end( ap ); +} + + +static +void AH_Dump_Stems( AH_Optimizer* optimizer ) { + int n; + AH_Stem* stem; + + + stem = optimizer->stems; + for ( n = 0; n < optimizer->num_stems; n++, stem++ ) + { + LOG( ( " %c%2d [%.1f:%.1f]={%.1f:%.1f}=" + "<%1.f..%1.f> force=%.1f speed=%.1f\n", + optimizer->vertical ? 'V' : 'H', n, + FLOAT( stem->edge1->opos ), FLOAT( stem->edge2->opos ), + FLOAT( stem->edge1->pos ), FLOAT( stem->edge2->pos ), + FLOAT( stem->min_pos ), FLOAT( stem->max_pos ), + FLOAT( stem->force ), FLOAT( stem->velocity ) ) ); + } +} + + +static +void AH_Dump_Stems2( AH_Optimizer* optimizer ) { + int n; + AH_Stem* stem; + + + stem = optimizer->stems; + for ( n = 0; n < optimizer->num_stems; n++, stem++ ) + { + LOG( ( " %c%2d [%.1f]=<%1.f..%1.f> force=%.1f speed=%.1f\n", + optimizer->vertical ? 'V' : 'H', n, + FLOAT( stem->pos ), + FLOAT( stem->min_pos ), FLOAT( stem->max_pos ), + FLOAT( stem->force ), FLOAT( stem->velocity ) ) ); + } +} + + +static +void AH_Dump_Springs( AH_Optimizer* optimizer ) { + int n; + AH_Spring* spring; + AH_Stem* stems; + + + spring = optimizer->springs; + stems = optimizer->stems; + LOG( ( "%cSprings ", optimizer->vertical ? 'V' : 'H' ) ); + + for ( n = 0; n < optimizer->num_springs; n++, spring++ ) + { + LOG( ( " [%d-%d:%.1f:%1.f:%.1f]", + spring->stem1 - stems, spring->stem2 - stems, + FLOAT( spring->owidth ), + FLOAT( spring->stem2->pos - + ( spring->stem1->pos + spring->stem1->width ) ), + FLOAT( spring->tension ) ) ); + } + + LOG( ( "\n" ) ); +} + +#endif /* AH_DEBUG_OPTIM */ + + +/*************************************************************************/ +/*************************************************************************/ +/*************************************************************************/ +/**** ****/ +/**** COMPUTE STEMS AND SPRINGS IN AN OUTLINE ****/ +/**** ****/ +/*************************************************************************/ +/*************************************************************************/ +/*************************************************************************/ + + +static +int valid_stem_segments( AH_Segment* seg1, + AH_Segment* seg2 ) { + return seg1->serif == 0 && + seg2 && + seg2->link == seg1 && + seg1->pos < seg2->pos && + seg1->min_coord <= seg2->max_coord && + seg2->min_coord <= seg1->max_coord; +} + + +/* compute all stems in an outline */ +static +int optim_compute_stems( AH_Optimizer* optimizer ) { + AH_Outline* outline = optimizer->outline; + FT_Fixed scale; + FT_Memory memory = optimizer->memory; + FT_Error error = 0; + FT_Int dimension; + AH_Edge* edges; + AH_Edge* edge_limit; + AH_Stem** p_stems; + FT_Int* p_num_stems; + + + edges = outline->horz_edges; + edge_limit = edges + outline->num_hedges; + scale = outline->y_scale; + + p_stems = &optimizer->horz_stems; + p_num_stems = &optimizer->num_hstems; + + for ( dimension = 1; dimension >= 0; dimension-- ) + { + AH_Stem* stems = 0; + FT_Int num_stems = 0; + AH_Edge* edge; + + + /* first of all, count the number of stems in this direction */ + for ( edge = edges; edge < edge_limit; edge++ ) + { + AH_Segment* seg = edge->first; + + + do + { + if ( valid_stem_segments( seg, seg->link ) ) { + num_stems++; + } + + seg = seg->edge_next; + + } while ( seg != edge->first ); + } + + /* now allocate the stems and build their table */ + if ( num_stems > 0 ) { + AH_Stem* stem; + + + if ( ALLOC_ARRAY( stems, num_stems, AH_Stem ) ) { + goto Exit; + } + + stem = stems; + for ( edge = edges; edge < edge_limit; edge++ ) + { + AH_Segment* seg = edge->first; + AH_Segment* seg2; + + + do + { + seg2 = seg->link; + if ( valid_stem_segments( seg, seg2 ) ) { + AH_Edge* edge1 = seg->edge; + AH_Edge* edge2 = seg2->edge; + + + stem->edge1 = edge1; + stem->edge2 = edge2; + stem->opos = edge1->opos; + stem->pos = edge1->pos; + stem->owidth = edge2->opos - edge1->opos; + stem->width = edge2->pos - edge1->pos; + + /* compute min_coord and max_coord */ + { + FT_Pos min_coord = seg->min_coord; + FT_Pos max_coord = seg->max_coord; + + + if ( seg2->min_coord > min_coord ) { + min_coord = seg2->min_coord; + } + + if ( seg2->max_coord < max_coord ) { + max_coord = seg2->max_coord; + } + + stem->min_coord = min_coord; + stem->max_coord = max_coord; + } + + /* compute minimum and maximum positions for stem -- */ + /* note that the left-most/bottom-most stem has always */ + /* a fixed position */ + if ( stem == stems || edge1->blue_edge || edge2->blue_edge ) { + /* this stem cannot move; it is snapped to a blue edge */ + stem->min_pos = stem->pos; + stem->max_pos = stem->pos; + } else + { + /* this edge can move; compute its min and max positions */ + FT_Pos pos1 = stem->opos; + FT_Pos pos2 = pos1 + stem->owidth - stem->width; + FT_Pos min1 = pos1 & - 64; + FT_Pos min2 = pos2 & - 64; + + + stem->min_pos = min1; + stem->max_pos = min1 + 64; + if ( min2 < min1 ) { + stem->min_pos = min2; + } else { + stem->max_pos = min2 + 64; + } + + /* XXX: just to see what it does */ + stem->max_pos += 64; + + /* just for the case where direct hinting did some */ + /* incredible things (e.g. blue edge shifts) */ + if ( stem->min_pos > stem->pos ) { + stem->min_pos = stem->pos; + } + + if ( stem->max_pos < stem->pos ) { + stem->max_pos = stem->pos; + } + } + + stem->velocity = 0; + stem->force = 0; + + stem++; + } + seg = seg->edge_next; + + } while ( seg != edge->first ); + } + } + + *p_stems = stems; + *p_num_stems = num_stems; + + edges = outline->vert_edges; + edge_limit = edges + outline->num_vedges; + scale = outline->x_scale; + + p_stems = &optimizer->vert_stems; + p_num_stems = &optimizer->num_vstems; + } + +Exit: + +#ifdef AH_DEBUG_OPTIM + AH_Dump_Stems( optimizer ); +#endif + + return error; +} + + +/* returns the spring area between two stems, 0 if none */ +static +FT_Pos stem_spring_area( AH_Stem* stem1, + AH_Stem* stem2 ) { + FT_Pos area1 = stem1->max_coord - stem1->min_coord; + FT_Pos area2 = stem2->max_coord - stem2->min_coord; + FT_Pos min = stem1->min_coord; + FT_Pos max = stem1->max_coord; + FT_Pos area; + + + /* order stems */ + if ( stem2->opos <= stem1->opos + stem1->owidth ) { + return 0; + } + + if ( min < stem2->min_coord ) { + min = stem2->min_coord; + } + + if ( max < stem2->max_coord ) { + max = stem2->max_coord; + } + + area = ( max - min ); + if ( 2 * area < area1 && 2 * area < area2 ) { + area = 0; + } + + return area; +} + + +/* compute all springs in an outline */ +static +int optim_compute_springs( AH_Optimizer* optimizer ) { + /* basically, a spring exists between two stems if most of their */ + /* surface is aligned */ + FT_Memory memory = optimizer->memory; + + AH_Stem* stems; + AH_Stem* stem_limit; + AH_Stem* stem; + int dimension; + int error = 0; + + FT_Int* p_num_springs; + AH_Spring** p_springs; + + + stems = optimizer->horz_stems; + stem_limit = stems + optimizer->num_hstems; + + p_springs = &optimizer->horz_springs; + p_num_springs = &optimizer->num_hsprings; + + for ( dimension = 1; dimension >= 0; dimension-- ) + { + FT_Int num_springs = 0; + AH_Spring* springs = 0; + + + /* first of all, count stem springs */ + for ( stem = stems; stem + 1 < stem_limit; stem++ ) + { + AH_Stem* stem2; + + + for ( stem2 = stem + 1; stem2 < stem_limit; stem2++ ) + if ( stem_spring_area( stem, stem2 ) ) { + num_springs++; + } + } + + /* then allocate and build the springs table */ + if ( num_springs > 0 ) { + AH_Spring* spring; + + + /* allocate table of springs */ + if ( ALLOC_ARRAY( springs, num_springs, AH_Spring ) ) { + goto Exit; + } + + /* fill the springs table */ + spring = springs; + for ( stem = stems; stem + 1 < stem_limit; stem++ ) + { + AH_Stem* stem2; + FT_Pos area; + + + for ( stem2 = stem + 1; stem2 < stem_limit; stem2++ ) + { + area = stem_spring_area( stem, stem2 ); + if ( area ) { + /* add a new spring here */ + spring->stem1 = stem; + spring->stem2 = stem2; + spring->owidth = stem2->opos - ( stem->opos + stem->owidth ); + spring->tension = 0; + + spring++; + } + } + } + } + *p_num_springs = num_springs; + *p_springs = springs; + + stems = optimizer->vert_stems; + stem_limit = stems + optimizer->num_vstems; + + p_springs = &optimizer->vert_springs; + p_num_springs = &optimizer->num_vsprings; + } + +Exit: + +#ifdef AH_DEBUG_OPTIM + AH_Dump_Springs( optimizer ); +#endif + + return error; +} + + +/*************************************************************************/ +/*************************************************************************/ +/*************************************************************************/ +/**** ****/ +/**** OPTIMIZE THROUGH MY STRANGE SIMULATED ANNEALING ALGO ;-) ****/ +/**** ****/ +/*************************************************************************/ +/*************************************************************************/ +/*************************************************************************/ + +#ifndef AH_BRUTE_FORCE + +/* compute all spring tensions */ +static +void optim_compute_tensions( AH_Optimizer* optimizer ) { + AH_Spring* spring = optimizer->springs; + AH_Spring* limit = spring + optimizer->num_springs; + + + for ( ; spring < limit; spring++ ) + { + AH_Stem* stem1 = spring->stem1; + AH_Stem* stem2 = spring->stem2; + FT_Int status; + + FT_Pos width; + FT_Pos tension; + FT_Pos sign; + + + /* compute the tension; it simply is -K*(new_width-old_width) */ + width = stem2->pos - ( stem1->pos + stem1->width ); + tension = width - spring->owidth; + + sign = 1; + if ( tension < 0 ) { + sign = -1; + tension = -tension; + } + + if ( width <= 0 ) { + tension = 32000; + } else { + tension = ( tension << 10 ) / width; + } + + tension = -sign * FT_MulFix( tension, optimizer->tension_scale ); + spring->tension = tension; + + /* now, distribute tension among the englobing stems, if they */ + /* are able to move */ + status = 0; + if ( stem1->pos <= stem1->min_pos ) { + status |= 1; + } + if ( stem2->pos >= stem2->max_pos ) { + status |= 2; + } + + if ( !status ) { + tension /= 2; + } + + if ( ( status & 1 ) == 0 ) { + stem1->force -= tension; + } + + if ( ( status & 2 ) == 0 ) { + stem2->force += tension; + } + } +} + + +/* compute all stem movements -- returns 0 if nothing moved */ +static +int optim_compute_stem_movements( AH_Optimizer* optimizer ) { + AH_Stem* stems = optimizer->stems; + AH_Stem* limit = stems + optimizer->num_stems; + AH_Stem* stem = stems; + int moved = 0; + + + /* set initial forces to velocity */ + for ( stem = stems; stem < limit; stem++ ) + { + stem->force = stem->velocity; + stem->velocity /= 2; /* XXX: Heuristics */ + } + + /* compute the sum of forces applied on each stem */ + optim_compute_tensions( optimizer ); + +#ifdef AH_DEBUG_OPTIM + AH_Dump_Springs( optimizer ); + AH_Dump_Stems2( optimizer ); +#endif + + /* now, see whether something can move */ + for ( stem = stems; stem < limit; stem++ ) + { + if ( stem->force > optimizer->tension_threshold ) { + /* there is enough tension to move the stem to the right */ + if ( stem->pos < stem->max_pos ) { + stem->pos += 64; + stem->velocity = stem->force / 2; + moved = 1; + } else { + stem->velocity = 0; + } + } else if ( stem->force < optimizer->tension_threshold ) { + /* there is enough tension to move the stem to the left */ + if ( stem->pos > stem->min_pos ) { + stem->pos -= 64; + stem->velocity = stem->force / 2; + moved = 1; + } else { + stem->velocity = 0; + } + } + } + + /* return 0 if nothing moved */ + return moved; +} + +#endif /* AH_BRUTE_FORCE */ + + +/* compute current global distortion from springs */ +static +FT_Pos optim_compute_distortion( AH_Optimizer* optimizer ) { + AH_Spring* spring = optimizer->springs; + AH_Spring* limit = spring + optimizer->num_springs; + FT_Pos distortion = 0; + + + for ( ; spring < limit; spring++ ) + { + AH_Stem* stem1 = spring->stem1; + AH_Stem* stem2 = spring->stem2; + FT_Pos width; + + width = stem2->pos - ( stem1->pos + stem1->width ); + width -= spring->owidth; + if ( width < 0 ) { + width = -width; + } + + distortion += width; + } + + return distortion; +} + + +/* record stems configuration in `best of' history */ +static +void optim_record_configuration( AH_Optimizer* optimizer ) { + FT_Pos distortion; + AH_Configuration* configs = optimizer->configs; + AH_Configuration* limit = configs + optimizer->num_configs; + AH_Configuration* config; + + + distortion = optim_compute_distortion( optimizer ); + LOG( ( "config distortion = %.1f ", FLOAT( distortion * 64 ) ) ); + + /* check that we really need to add this configuration to our */ + /* sorted history */ + if ( limit > configs && limit[-1].distortion < distortion ) { + LOG( ( "ejected\n" ) ); + return; + } + + /* add new configuration at the end of the table */ + { + int n; + + + config = limit; + if ( optimizer->num_configs < AH_MAX_CONFIGS ) { + optimizer->num_configs++; + } else { + config--; + } + + config->distortion = distortion; + + for ( n = 0; n < optimizer->num_stems; n++ ) + config->positions[n] = optimizer->stems[n].pos; + } + + /* move the current configuration towards the front of the list */ + /* when necessary -- yes this is slow bubble sort ;-) */ + while ( config > configs && config[0].distortion < config[-1].distortion ) + { + AH_Configuration temp; + + + config--; + temp = config[0]; + config[0] = config[1]; + config[1] = temp; + } + LOG( ( "recorded!\n" ) ); +} + + +#ifdef AH_BRUTE_FORCE + +/* optimize outline in a single direction */ +static +void optim_compute( AH_Optimizer* optimizer ) { + int n; + FT_Bool moved; + + AH_Stem* stem = optimizer->stems; + AH_Stem* limit = stem + optimizer->num_stems; + + + /* empty, exit */ + if ( stem >= limit ) { + return; + } + + optimizer->num_configs = 0; + + stem = optimizer->stems; + for ( ; stem < limit; stem++ ) + stem->pos = stem->min_pos; + + do + { + /* record current configuration */ + optim_record_configuration( optimizer ); + + /* now change configuration */ + moved = 0; + for ( stem = optimizer->stems; stem < limit; stem++ ) + { + if ( stem->pos < stem->max_pos ) { + stem->pos += 64; + moved = 1; + break; + } + + stem->pos = stem->min_pos; + } + } while ( moved ); + + /* now, set the best stem positions */ + for ( n = 0; n < optimizer->num_stems; n++ ) + { + AH_Stem* stem = optimizer->stems + n; + FT_Pos pos = optimizer->configs[0].positions[n]; + + + stem->edge1->pos = pos; + stem->edge2->pos = pos + stem->width; + + stem->edge1->flags |= ah_edge_done; + stem->edge2->flags |= ah_edge_done; + } +} + +#else /* AH_BRUTE_FORCE */ + +/* optimize outline in a single direction */ +static +void optim_compute( AH_Optimizer* optimizer ) { + int n, counter, counter2; + + + optimizer->num_configs = 0; + optimizer->tension_scale = 0x80000L; + optimizer->tension_threshold = 64; + + /* record initial configuration threshold */ + optim_record_configuration( optimizer ); + + counter = 0; + for ( counter2 = optimizer->num_stems * 8; counter2 >= 0; counter2-- ) + { + if ( counter == 0 ) { + counter = 2 * optimizer->num_stems; + } + + if ( !optim_compute_stem_movements( optimizer ) ) { + break; + } + + optim_record_configuration( optimizer ); + + counter--; + if ( counter == 0 ) { + optimizer->tension_scale /= 2; + } + } + + /* now, set the best stem positions */ + for ( n = 0; n < optimizer->num_stems; n++ ) + { + AH_Stem* stem = optimizer->stems + n; + FT_Pos pos = optimizer->configs[0].positions[n]; + + + stem->edge1->pos = pos; + stem->edge2->pos = pos + stem->width; + + stem->edge1->flags |= ah_edge_done; + stem->edge2->flags |= ah_edge_done; + } +} + +#endif /* AH_BRUTE_FORCE */ + + +/*************************************************************************/ +/*************************************************************************/ +/*************************************************************************/ +/**** ****/ +/**** HIGH-LEVEL OPTIMIZER API ****/ +/**** ****/ +/*************************************************************************/ +/*************************************************************************/ +/*************************************************************************/ + + +/* releases the optimization data */ +void AH_Optimizer_Done( AH_Optimizer* optimizer ) { + if ( optimizer ) { + FT_Memory memory = optimizer->memory; + + + FREE( optimizer->horz_stems ); + FREE( optimizer->vert_stems ); + FREE( optimizer->horz_springs ); + FREE( optimizer->vert_springs ); + FREE( optimizer->positions ); + } +} + + +/* loads the outline into the optimizer */ +int AH_Optimizer_Init( AH_Optimizer* optimizer, + AH_Outline* outline, + FT_Memory memory ) { + FT_Error error; + + + MEM_Set( optimizer, 0, sizeof( *optimizer ) ); + optimizer->outline = outline; + optimizer->memory = memory; + + LOG( ( "initializing new optimizer\n" ) ); + /* compute stems and springs */ + error = optim_compute_stems( optimizer ) || + optim_compute_springs( optimizer ); + if ( error ) { + goto Fail; + } + + /* allocate stem positions history and configurations */ + { + int n, max_stems; + + + max_stems = optimizer->num_hstems; + if ( max_stems < optimizer->num_vstems ) { + max_stems = optimizer->num_vstems; + } + + if ( ALLOC_ARRAY( optimizer->positions, + max_stems * AH_MAX_CONFIGS, FT_Pos ) ) { + goto Fail; + } + + optimizer->num_configs = 0; + for ( n = 0; n < AH_MAX_CONFIGS; n++ ) + optimizer->configs[n].positions = optimizer->positions + + n * max_stems; + } + + return error; + +Fail: + AH_Optimizer_Done( optimizer ); + return error; +} + + +/* compute optimal outline */ +void AH_Optimizer_Compute( AH_Optimizer* optimizer ) { + optimizer->num_stems = optimizer->num_hstems; + optimizer->stems = optimizer->horz_stems; + optimizer->num_springs = optimizer->num_hsprings; + optimizer->springs = optimizer->horz_springs; + + if ( optimizer->num_springs > 0 ) { + LOG( ( "horizontal optimization ------------------------\n" ) ); + optim_compute( optimizer ); + } + + optimizer->num_stems = optimizer->num_vstems; + optimizer->stems = optimizer->vert_stems; + optimizer->num_springs = optimizer->num_vsprings; + optimizer->springs = optimizer->vert_springs; + + if ( optimizer->num_springs ) { + LOG( ( "vertical optimization --------------------------\n" ) ); + optim_compute( optimizer ); + } +} + + +/* END */ diff --git a/Projects/Android/jni/rtcw/src/ft2/ahoptim.h b/Projects/Android/jni/rtcw/src/ft2/ahoptim.h new file mode 100644 index 0000000..9d9a4d2 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/ft2/ahoptim.h @@ -0,0 +1,127 @@ +/***************************************************************************/ +/* */ +/* ahoptim.h */ +/* */ +/* FreeType auto hinting outline optimization (declaration). */ +/* */ +/* Copyright 2000 Catharon Productions Inc. */ +/* Author: David Turner */ +/* */ +/* This file is part of the Catharon Typography Project and shall only */ +/* be used, modified, and distributed under the terms of the Catharon */ +/* Open Source License that should come with this file under the name */ +/* `CatharonLicense.txt'. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/* Note that this license is compatible with the FreeType license. */ +/* */ +/***************************************************************************/ + + +#ifndef AHOPTIM_H +#define AHOPTIM_H + + +#include "ahtypes.h" + +/* the maximal number of stem configurations to record */ +/* during optimization */ +#define AH_MAX_CONFIGS 8 + + +typedef struct AH_Stem_ +{ + FT_Pos pos; /* current position */ + FT_Pos velocity; /* current velocity */ + FT_Pos force; /* sum of current forces */ + FT_Pos width; /* normalized width */ + + FT_Pos min_pos; /* minimum grid position */ + FT_Pos max_pos; /* maximum grid position */ + + AH_Edge* edge1; /* left/bottom edge */ + AH_Edge* edge2; /* right/top edge */ + + FT_Pos opos; /* original position */ + FT_Pos owidth; /* original width */ + + FT_Pos min_coord; /* minimum coordinate */ + FT_Pos max_coord; /* maximum coordinate */ + +} AH_Stem; + + +/* A spring between two stems */ +typedef struct AH_Spring_ +{ + AH_Stem* stem1; + AH_Stem* stem2; + FT_Pos owidth; /* original width */ + FT_Pos tension; /* current tension */ + +} AH_Spring; + + +/* A configuration records the position of each stem at a given time */ +/* as well as the associated distortion */ +typedef struct AH_Configuration_ +{ + FT_Pos* positions; + FT_Long distortion; + +} AH_Configuration; + + +typedef struct AH_Optimizer_ +{ + FT_Memory memory; + AH_Outline* outline; + + FT_Int num_hstems; + AH_Stem* horz_stems; + + FT_Int num_vstems; + AH_Stem* vert_stems; + + FT_Int num_hsprings; + FT_Int num_vsprings; + AH_Spring* horz_springs; + AH_Spring* vert_springs; + + FT_Int num_configs; + AH_Configuration configs[AH_MAX_CONFIGS]; + FT_Pos* positions; + + /* during each pass, use these instead */ + FT_Int num_stems; + AH_Stem* stems; + + FT_Int num_springs; + AH_Spring* springs; + FT_Bool vertical; + + FT_Fixed tension_scale; + FT_Pos tension_threshold; + +} AH_Optimizer; + + +/* loads the outline into the optimizer */ +int AH_Optimizer_Init( AH_Optimizer* optimizer, + AH_Outline* outline, + FT_Memory memory ); + + +/* compute optimal outline */ +void AH_Optimizer_Compute( AH_Optimizer* optimizer ); + + +/* release the optimization data */ +void AH_Optimizer_Done( AH_Optimizer* optimizer ); + + +#endif /* AHOPTIM_H */ + + +/* END */ diff --git a/Projects/Android/jni/rtcw/src/ft2/ahtypes.h b/Projects/Android/jni/rtcw/src/ft2/ahtypes.h new file mode 100644 index 0000000..af93c5f --- /dev/null +++ b/Projects/Android/jni/rtcw/src/ft2/ahtypes.h @@ -0,0 +1,484 @@ +/***************************************************************************/ +/* */ +/* ahtypes.h */ +/* */ +/* General types and definitions for the auto-hint module */ +/* (specification only). */ +/* */ +/* Copyright 2000 Catharon Productions Inc. */ +/* Author: David Turner */ +/* */ +/* This file is part of the Catharon Typography Project and shall only */ +/* be used, modified, and distributed under the terms of the Catharon */ +/* Open Source License that should come with this file under the name */ +/* `CatharonLicense.txt'. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/* Note that this license is compatible with the FreeType license. */ +/* */ +/***************************************************************************/ + + +#ifndef AHTYPES_H +#define AHTYPES_H + + +#include "ftobjs.h" + + +#include "ahloader.h" + + +#define xxAH_DEBUG + + +#ifdef AH_DEBUG + +#include + +#define AH_LOG( x ) printf ## x + +#else + +#define AH_LOG( x ) do ;while ( 0 ) /* nothing */ + +#endif + + +/*************************************************************************/ +/*************************************************************************/ +/*************************************************************************/ +/**** ****/ +/**** COMPILE-TIME BUILD OPTIONS ****/ +/**** ****/ +/**** Toggle these configuration macros to experiment with `features' ****/ +/**** of the auto-hinter. ****/ +/**** ****/ +/*************************************************************************/ +/*************************************************************************/ +/*************************************************************************/ + + +/*************************************************************************/ +/* */ +/* If this option is defined, only strong interpolation will be used to */ +/* place the points between edges. Otherwise, `smooth' points are */ +/* detected and later hinted through weak interpolation to correct some */ +/* unpleasant artefacts. */ +/* */ +#undef AH_OPTION_NO_WEAK_INTERPOLATION + + +/*************************************************************************/ +/* */ +/* If this option is defined, only weak interpolation will be used to */ +/* place the points between edges. Otherwise, `strong' points are */ +/* detected and later hinted through strong interpolation to correct */ +/* some unpleasant artefacts. */ +/* */ +#undef AH_OPTION_NO_STRONG_INTERPOLATION + + +/*************************************************************************/ +/* */ +/* Undefine this macro if you don't want to hint the metrics. There is */ +/* no reason to do this (at least for non-CJK scripts), except for */ +/* experimentation. */ +/* */ +#define AH_HINT_METRICS + + +/*************************************************************************/ +/* */ +/* Define this macro if you do not want to insert extra edges at a */ +/* glyph's x and y extremum (if there isn't one already available). */ +/* This helps to reduce a number of artefacts and allows hinting of */ +/* metrics. */ +/* */ +#undef AH_OPTION_NO_EXTREMUM_EDGES + + +/* don't touch for now */ +#define AH_MAX_WIDTHS 12 +#define AH_MAX_HEIGHTS 12 + + +/*************************************************************************/ +/*************************************************************************/ +/*************************************************************************/ +/**** ****/ +/**** TYPE DEFINITIONS ****/ +/**** ****/ +/*************************************************************************/ +/*************************************************************************/ +/*************************************************************************/ + + +/* see agangles.h */ +typedef FT_Int AH_Angle; + + +/* hint flags */ +#define ah_flah_none 0 + +/* bezier control points flags */ +#define ah_flah_conic 1 +#define ah_flah_cubic 2 +#define ah_flah_control ( ah_flah_conic | ah_flah_cubic ) + +/* extrema flags */ +#define ah_flah_extrema_x 4 +#define ah_flah_extrema_y 8 + +/* roundness */ +#define ah_flah_round_x 16 +#define ah_flah_round_y 32 + +/* touched */ +#define ah_flah_touch_x 64 +#define ah_flah_touch_y 128 + +/* weak interpolation */ +#define ah_flah_weak_interpolation 256 + +typedef FT_Int AH_Flags; + + +/* edge hint flags */ +#define ah_edge_normal 0 +#define ah_edge_round 1 +#define ah_edge_serif 2 +#define ah_edge_done 4 + +typedef FT_Int AH_Edge_Flags; + + +/* hint directions -- the values are computed so that two vectors are */ +/* in opposite directions iff `dir1+dir2 == 0' */ +#define ah_dir_none 4 +#define ah_dir_right 1 +#define ah_dir_left -1 +#define ah_dir_up 2 +#define ah_dir_down -2 + +typedef FT_Int AH_Direction; + + +typedef struct AH_Point AH_Point; +typedef struct AH_Segment AH_Segment; +typedef struct AH_Edge AH_Edge; + + +/*************************************************************************/ +/* */ +/* */ +/* AH_Point */ +/* */ +/* */ +/* A structure used to model an outline point to the AH_Outline type. */ +/* */ +/* */ +/* flags :: The current point hint flags. */ +/* */ +/* ox, oy :: The current original scaled coordinates. */ +/* */ +/* fx, fy :: The current coordinates in font units. */ +/* */ +/* x, y :: The current hinter coordinates. */ +/* */ +/* u, v :: Point coordinates -- meaning varies with context. */ +/* */ +/* in_dir :: The direction of the inwards vector (prev->point). */ +/* */ +/* out_dir :: The direction of the outwards vector (point->next). */ +/* */ +/* in_angle :: The angle of the inwards vector. */ +/* */ +/* out_angle :: The angle of the outwards vector. */ +/* */ +/* next :: The next point in same contour. */ +/* */ +/* prev :: The previous point in same contour. */ +/* */ +struct AH_Point +{ + AH_Flags flags; /* point flags used by hinter */ + FT_Pos ox, oy; + FT_Pos fx, fy; + FT_Pos x, y; + FT_Pos u, v; + + AH_Direction in_dir; /* direction of inwards vector */ + AH_Direction out_dir; /* direction of outwards vector */ + + AH_Angle in_angle; + AH_Angle out_angle; + + AH_Point* next; /* next point in contour */ + AH_Point* prev; /* previous point in contour */ +}; + + +/*************************************************************************/ +/* */ +/* */ +/* AH_Segment */ +/* */ +/* */ +/* A structure used to describe an edge segment to the auto-hinter. */ +/* A segment is simply a sequence of successive points located on the */ +/* same horizontal or vertical `position', in a given direction. */ +/* */ +/* */ +/* flags :: The segment edge flags (straight, rounded, etc.). */ +/* */ +/* dir :: The segment direction. */ +/* */ +/* first :: The first point in the segment. */ +/* */ +/* last :: The last point in the segment. */ +/* */ +/* contour :: A pointer to the first point of the segment's */ +/* contour. */ +/* */ +/* pos :: The segment position in font units. */ +/* */ +/* size :: The segment size. */ +/* */ +/* edge :: The edge of the current segment. */ +/* */ +/* edge_next :: The next segment on the same edge. */ +/* */ +/* link :: The pairing segment for this edge. */ +/* */ +/* serif :: The primary segment for serifs. */ +/* */ +/* num_linked :: The number of other segments that link to this one. */ +/* */ +/* score :: Used to score the segment when selecting them. */ +/* */ +struct AH_Segment +{ + AH_Edge_Flags flags; + AH_Direction dir; + + AH_Point* first; /* first point in edge segment */ + AH_Point* last; /* last point in edge segment */ + AH_Point** contour; /* ptr to first point of segment's contour */ + + FT_Pos pos; /* position of segment */ + FT_Pos min_coord; /* minimum coordinate of segment */ + FT_Pos max_coord; /* maximum coordinate of segment */ + + AH_Edge* edge; + AH_Segment* edge_next; + + AH_Segment* link; /* link segment */ + AH_Segment* serif; /* primary segment for serifs */ + FT_Pos num_linked; /* number of linked segments */ + FT_Int score; +}; + + +/*************************************************************************/ +/* */ +/* */ +/* AH_Edge */ +/* */ +/* */ +/* A structure used to describe an edge, which really is a horizontal */ +/* or vertical coordinate to be hinted depending on the segments */ +/* located on it. */ +/* */ +/* */ +/* flags :: The segment edge flags (straight, rounded, etc.). */ +/* */ +/* dir :: The main segment direction on this edge. */ +/* */ +/* first :: The first edge segment. */ +/* */ +/* last :: The last edge segment. */ +/* */ +/* fpos :: The original edge position in font units. */ +/* */ +/* opos :: The original scaled edge position. */ +/* */ +/* pos :: The hinted edge position. */ +/* */ +/* link :: The linked edge. */ +/* */ +/* serif :: The serif edge. */ +/* */ +/* num_paired :: The number of other edges that pair to this one. */ +/* */ +/* score :: Used to score the edge when selecting them. */ +/* */ +/* blue_edge :: Indicate the blue zone edge this edge is related to. */ +/* Only set for some of the horizontal edges in a Latin */ +/* font. */ +/* */ +struct AH_Edge +{ + AH_Edge_Flags flags; + AH_Direction dir; + + AH_Segment* first; + AH_Segment* last; + + FT_Pos fpos; + FT_Pos opos; + FT_Pos pos; + + AH_Edge* link; + AH_Edge* serif; + FT_Int num_linked; + + FT_Int score; + FT_Pos* blue_edge; +}; + + +/* an outline as seen by the hinter */ +typedef struct AH_Outline_ +{ + FT_Memory memory; + + AH_Direction vert_major_dir; /* vertical major direction */ + AH_Direction horz_major_dir; /* horizontal major direction */ + + FT_Fixed x_scale; + FT_Fixed y_scale; + FT_Pos edge_distance_threshold; + + FT_Int max_points; + FT_Int num_points; + AH_Point* points; + + FT_Int max_contours; + FT_Int num_contours; + AH_Point** contours; + + FT_Int num_hedges; + AH_Edge* horz_edges; + + FT_Int num_vedges; + AH_Edge* vert_edges; + + FT_Int num_hsegments; + AH_Segment* horz_segments; + + FT_Int num_vsegments; + AH_Segment* vert_segments; + +} AH_Outline; + + +#define ah_blue_capital_top 0 /* THEZOCQS */ +#define ah_blue_capital_bottom ( ah_blue_capital_top + 1 ) /* HEZLOCUS */ +#define ah_blue_small_top ( ah_blue_capital_bottom + 1 ) /* xzroesc */ +#define ah_blue_small_bottom ( ah_blue_small_top + 1 ) /* xzroesc */ +#define ah_blue_small_minor ( ah_blue_small_bottom + 1 ) /* pqgjy */ +#define ah_blue_max ( ah_blue_small_minor + 1 ) + +typedef FT_Int AH_Blue; + + +#define ah_hinter_monochrome 1 +#define ah_hinter_optimize 2 + +typedef FT_Int AH_Hinter_Flags; + + +/*************************************************************************/ +/* */ +/* */ +/* AH_Globals */ +/* */ +/* */ +/* Holds the global metrics for a given font face (be it in design */ +/* units or scaled pixel values). */ +/* */ +/* */ +/* num_widths :: The number of widths. */ +/* */ +/* num_heights :: The number of heights. */ +/* */ +/* widths :: Snap widths, including standard one. */ +/* */ +/* heights :: Snap height, including standard one. */ +/* */ +/* blue_refs :: The reference positions of blue zones. */ +/* */ +/* blue_shoots :: The overshoot positions of blue zones. */ +/* */ +typedef struct AH_Globals_ +{ + FT_Int num_widths; + FT_Int num_heights; + + FT_Pos widths [AH_MAX_WIDTHS]; + FT_Pos heights[AH_MAX_HEIGHTS]; + + FT_Pos blue_refs [ah_blue_max]; + FT_Pos blue_shoots[ah_blue_max]; + +} AH_Globals; + + +/*************************************************************************/ +/* */ +/* */ +/* AH_Face_Globals */ +/* */ +/* */ +/* Holds the complete global metrics for a given font face (i.e., the */ +/* design units version + a scaled version + the current scales */ +/* used). */ +/* */ +/* */ +/* face :: A handle to the source face object */ +/* */ +/* design :: The globals in font design units. */ +/* */ +/* scaled :: Scaled globals in sub-pixel values. */ +/* */ +/* x_scale :: The current horizontal scale. */ +/* */ +/* y_scale :: The current vertical scale. */ +/* */ +typedef struct AH_Face_Globals_ +{ + FT_Face face; + AH_Globals design; + AH_Globals scaled; + FT_Fixed x_scale; + FT_Fixed y_scale; + FT_Bool control_overshoot; + +} AH_Face_Globals; + + +typedef struct AH_Hinter +{ + FT_Memory memory; + AH_Hinter_Flags flags; + + FT_Int algorithm; + FT_Face face; + + AH_Face_Globals* globals; + + AH_Outline* glyph; + + AH_Loader* loader; + FT_Vector pp1; + FT_Vector pp2; + +} AH_Hinter; + + +#endif /* AHTYPES_H */ + + +/* END */ diff --git a/Projects/Android/jni/rtcw/src/ft2/autohint.h b/Projects/Android/jni/rtcw/src/ft2/autohint.h new file mode 100644 index 0000000..05951f6 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/ft2/autohint.h @@ -0,0 +1,195 @@ +/***************************************************************************/ +/* */ +/* autohint.h */ +/* */ +/* High-level `autohint' module-specific interface (specification). */ +/* */ +/* Copyright 1996-2000 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +/*************************************************************************/ +/* */ +/* The auto-hinter is used to load and automatically hint glyphs if a */ +/* format-specific hinter isn't available. */ +/* */ +/*************************************************************************/ + + +#ifndef AUTOHINT_H +#define AUTOHINT_H + + +/*************************************************************************/ +/* */ +/* A small technical note regarding automatic hinting in order to */ +/* clarify this module interface. */ +/* */ +/* An automatic hinter might compute two kinds of data for a given face: */ +/* */ +/* - global hints: Usually some metrics that describe global properties */ +/* of the face. It is computed by scanning more or less */ +/* agressively the glyphs in the face, and thus can be */ +/* very slow to compute (even if the size of global */ +/* hints is really small). */ +/* */ +/* - glyph hints: These describe some important features of the glyph */ +/* outline, as well as how to align them. They are */ +/* generally much faster to compute than global hints. */ +/* */ +/* The current FreeType auto-hinter does a pretty good job while */ +/* performing fast computations for both global and glyph hints. */ +/* However, we might be interested in introducing more complex and */ +/* powerful algorithms in the future, like the one described in the John */ +/* D. Hobby paper, which unfortunately requires a lot more horsepower. */ +/* */ +/* Because a sufficiently sophisticated font management system would */ +/* typically implement an LRU cache of opened face objects to reduce */ +/* memory usage, it is a good idea to be able to avoid recomputing */ +/* global hints every time the same face is re-opened. */ +/* */ +/* We thus provide the ability to cache global hints outside of the face */ +/* object, in order to speed up font re-opening time. Of course, this */ +/* feature is purely optional, so most client programs won't even notice */ +/* it. */ +/* */ +/* I initially thought that it would be a good idea to cache the glyph */ +/* hints too. However, my general idea now is that if you really need */ +/* to cache these too, you are simply in need of a new font format, */ +/* where all this information could be stored within the font file and */ +/* decoded on the fly. */ +/* */ +/*************************************************************************/ + + +#include "freetype.h" + + +typedef struct FT_AutoHinterRec_ *FT_AutoHinter; + + +/*************************************************************************/ +/* */ +/* */ +/* FT_AutoHinter_Get_Global_Func */ +/* */ +/* */ +/* Retrieves the global hints computed for a given face object the */ +/* resulting data is dissociated from the face and will survive a */ +/* call to FT_Done_Face(). It must be discarded through the API */ +/* FT_AutoHinter_Done_Global_Func(). */ +/* */ +/* */ +/* hinter :: A handle to the source auto-hinter. */ +/* */ +/* face :: A handle to the source face object. */ +/* */ +/* */ +/* global_hints :: A typeless pointer to the global hints. */ +/* */ +/* global_len :: The size in bytes of the global hints. */ +/* */ +typedef void ( *FT_AutoHinter_Get_Global_Func )( + FT_AutoHinter hinter, + FT_Face face, + void** global_hints, + long* global_len ); + + +/*************************************************************************/ +/* */ +/* */ +/* FT_AutoHinter_Done_Global_Func */ +/* */ +/* */ +/* Discards the global hints retrieved through */ +/* FT_AutoHinter_Get_Global_Func(). This is the only way these hints */ +/* are freed from memory. */ +/* */ +/* */ +/* hinter :: A handle to the auto-hinter module. */ +/* */ +/* global :: A pointer to retrieved global hints to discard. */ +/* */ +typedef void ( *FT_AutoHinter_Done_Global_Func )( FT_AutoHinter hinter, + void* global ); + + +/*************************************************************************/ +/* */ +/* */ +/* FT_AutoHinter_Reset_Func */ +/* */ +/* */ +/* This function is used to recompute the global metrics in a given */ +/* font. This is useful when global font data changes (e.g. Multiple */ +/* Masters fonts where blend coordinates change). */ +/* */ +/* */ +/* hinter :: A handle to the source auto-hinter. */ +/* */ +/* face :: A handle to the face. */ +/* */ +typedef void ( *FT_AutoHinter_Reset_Func )( FT_AutoHinter hinter, + FT_Face face ); + + +/*************************************************************************/ +/* */ +/* */ +/* FT_AutoHinter_Load_Func */ +/* */ +/* */ +/* This function is used to load, scale, and automatically hint a */ +/* glyph from a given face. */ +/* */ +/* */ +/* face :: A handle to the face. */ +/* glyph_index :: The glyph index. */ +/* load_flags :: The load flags. */ +/* */ +/* */ +/* This function is capable of loading composite glyphs by hinting */ +/* each sub-glyph independently (which improves quality). */ +/* */ +/* It will call the font driver with FT_Load_Glyph(), with */ +/* FT_LOAD_NO_SCALE set. */ +/* */ +typedef FT_Error ( *FT_AutoHinter_Load_Func )( FT_AutoHinter hinter, + FT_GlyphSlot slot, + FT_Size size, + FT_UInt glyph_index, + FT_ULong load_flags ); + + +/*************************************************************************/ +/* */ +/* */ +/* FT_AutoHinter_Interface */ +/* */ +/* */ +/* The auto-hinter module's interface. */ +/* */ +typedef struct FT_AutoHinter_Interface +{ + FT_AutoHinter_Reset_Func reset_face; + FT_AutoHinter_Load_Func load_glyph; + + FT_AutoHinter_Get_Global_Func get_global_hints; + FT_AutoHinter_Done_Global_Func done_global_hints; + +} FT_AutoHinter_Interface; + + +#endif /* AUTOHINT_H */ + + +/* END */ diff --git a/Projects/Android/jni/rtcw/src/ft2/freetype.h b/Projects/Android/jni/rtcw/src/ft2/freetype.h new file mode 100644 index 0000000..530910c --- /dev/null +++ b/Projects/Android/jni/rtcw/src/ft2/freetype.h @@ -0,0 +1,2286 @@ +/***************************************************************************/ +/* */ +/* freetype.h */ +/* */ +/* FreeType high-level API and common types (specification only). */ +/* */ +/* Copyright 1996-2000 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef FREETYPE_H +#define FREETYPE_H + + +/*************************************************************************/ +/* */ +/* The `raster' component duplicates some of the declarations in */ +/* freetype.h for stand-alone use if _FREETYPE_ isn't defined. */ +/* */ +#define _FREETYPE_ + + +/*************************************************************************/ +/* */ +/* The FREETYPE_MAJOR and FREETYPE_MINOR macros are used to version the */ +/* new FreeType design, which is able to host several kinds of font */ +/* drivers. It starts at 2.0. */ +/* */ +#define FREETYPE_MAJOR 2 +#define FREETYPE_MINOR 0 + + +#include "ftconfig.h" /* read configuration information */ +#include "fterrors.h" +#include "fttypes.h" + + +#ifdef __cplusplus +extern "C" { +#endif + + +/*************************************************************************/ +/*************************************************************************/ +/* */ +/* B A S I C T Y P E S */ +/* */ +/*************************************************************************/ +/*************************************************************************/ + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Glyph_Metrics */ +/* */ +/* */ +/* A structure used to model the metrics of a single glyph. Note */ +/* that values are expressed in 26.6 fractional pixel format or in */ +/* font units, depending on context. */ +/* */ +/* */ +/* width :: The glyph's width. */ +/* */ +/* height :: The glyph's height. */ +/* */ +/* horiBearingX :: Horizontal left side bearing. */ +/* */ +/* horiBearingY :: Horizontal top side bearing. */ +/* */ +/* horiAdvance :: Horizontal advance width. */ +/* */ +/* vertBearingX :: Vertical left side bearing. */ +/* */ +/* vertBearingY :: Vertical top side bearing. */ +/* */ +/* vertAdvance :: Vertical advance height. */ +/* */ +typedef struct FT_Glyph_Metrics_ +{ + FT_Pos width; /* glyph width */ + FT_Pos height; /* glyph height */ + + FT_Pos horiBearingX; /* left side bearing in horizontal layouts */ + FT_Pos horiBearingY; /* top side bearing in horizontal layouts */ + FT_Pos horiAdvance; /* advance width for horizontal layout */ + + FT_Pos vertBearingX; /* left side bearing in vertical layouts */ + FT_Pos vertBearingY; /* top side bearing in vertical layouts */ + FT_Pos vertAdvance; /* advance height for vertical layout */ + +} FT_Glyph_Metrics; + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Generic_Finalizer */ +/* */ +/* */ +/* Describes a function used to destroy the `client' data of any */ +/* FreeType object. See the description of the FT_Generic type for */ +/* details of usage. */ +/* */ +/* */ +/* The address of the FreeType object which is under finalization. */ +/* Its client data is accessed through its `generic' field. */ +/* */ +typedef void ( *FT_Generic_Finalizer )( void* object ); + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Generic */ +/* */ +/* */ +/* Client applications often need to associate their own data to a */ +/* variety of FreeType core objects. For example, a text layout API */ +/* might want to associate a glyph cache to a given size object. */ +/* */ +/* Most FreeType object contains a `generic' field, of type */ +/* FT_Generic, which usage is left to client applications and font */ +/* servers. */ +/* */ +/* It can be used to store a pointer to client-specific data, as well */ +/* as the address of a `finalizer' function, which will be called by */ +/* FreeType when the object is destroyed (for example, the previous */ +/* client example would put the address of the glyph cache destructor */ +/* in the `finalizer' field). */ +/* */ +/* */ +/* data :: A typeless pointer to any client-specified data. This */ +/* field is completely ignored by the FreeType library. */ +/* */ +/* finalizer :: A pointer to a `generic finalizer' function, which */ +/* will be called when the object is destroyed. If this */ +/* field is set to NULL, no code will be called. */ +/* */ +typedef struct FT_Generic_ +{ + void* data; + FT_Generic_Finalizer finalizer; + +} FT_Generic; + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Bitmap_Size */ +/* */ +/* */ +/* An extremely simple structure used to model the size of a bitmap */ +/* strike (i.e., a bitmap instance of the font for a given */ +/* resolution) in a fixed-size font face. This is used for the */ +/* `available_sizes' field of the FT_Face_Properties structure. */ +/* */ +/* */ +/* height :: The character height in pixels. */ +/* */ +/* width :: The character width in pixels. */ +/* */ +typedef struct FT_Bitmap_Size_ +{ + FT_Short height; + FT_Short width; + +} FT_Bitmap_Size; + + +/*************************************************************************/ +/*************************************************************************/ +/* */ +/* O B J E C T C L A S S E S */ +/* */ +/*************************************************************************/ +/*************************************************************************/ + +/*************************************************************************/ +/* */ +/* */ +/* FT_Library */ +/* */ +/* */ +/* A handle to a FreeType library instance. Each `library' is */ +/* completely independent from the others; it is the `root' of a set */ +/* of objects like fonts, faces, sizes, etc. */ +/* */ +/* It also embeds a system object (see FT_System), as well as a */ +/* scan-line converter object (see FT_Raster). */ +/* */ +/* */ +/* Library objects are created through FT_Init_FreeType(). */ +/* */ +typedef struct FT_LibraryRec_ *FT_Library; + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Module */ +/* */ +/* */ +/* A handle to a given FreeType module object. Each module can be a */ +/* font driver, a renderer, or anything else that provides services */ +/* to the formers. */ +/* */ +typedef struct FT_ModuleRec_* FT_Module; + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Driver */ +/* */ +/* */ +/* A handle to a given FreeType font driver object. Each font driver */ +/* is able to create faces, sizes, glyph slots, and charmaps from the */ +/* resources whose format it supports. */ +/* */ +/* A driver can support either bitmap, graymap, or scalable font */ +/* formats. */ +/* */ +typedef struct FT_DriverRec_* FT_Driver; + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Renderer */ +/* */ +/* */ +/* A handle to a given FreeType renderer. A renderer is in charge of */ +/* converting a glyph image to a bitmap, when necessary. Each */ +/* supports a given glyph image format, and one or more target */ +/* surface depths. */ +/* */ +typedef struct FT_RendererRec_* FT_Renderer; + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Face */ +/* */ +/* */ +/* A handle to a given driver face object. A face object contains */ +/* all the instance and glyph independent data of a font file */ +/* typeface. */ +/* */ +/* A face object is created from a resource object through the */ +/* new_face() method of a given driver. */ +/* */ +typedef struct FT_FaceRec_* FT_Face; + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Size */ +/* */ +/* */ +/* A handle to a given driver size object. Such an object models the */ +/* _resolution_ AND _size_ dependent state of a given driver face */ +/* size. */ +/* */ +/* A size object is always created from a given face object. It is */ +/* discarded automatically by its parent face. */ +/* */ +typedef struct FT_SizeRec_* FT_Size; + + +/*************************************************************************/ +/* */ +/* */ +/* FT_GlyphSlot */ +/* */ +/* */ +/* A handle to a given `glyph slot'. A slot is a container where it */ +/* is possible to load any of the glyphs contained within its parent */ +/* face. */ +/* */ +/* A glyph slot is created from a given face object. It is discarded */ +/* automatically by its parent face. */ +/* */ +typedef struct FT_GlyphSlotRec_* FT_GlyphSlot; + + +/*************************************************************************/ +/* */ +/* */ +/* FT_CharMap */ +/* */ +/* */ +/* A handle to a given character map. A charmap is used to translate */ +/* character codes in a given encoding into glyph indexes for its */ +/* parent's face. Some font formats may provide several charmaps per */ +/* font. */ +/* */ +/* A charmap is created from a given face object. It is discarded */ +/* automatically by its parent face. */ +/* */ +typedef struct FT_CharMapRec_* FT_CharMap; + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Encoding */ +/* */ +/* */ +/* An enumeration used to specify encodings supported by charmaps. */ +/* Used in the FT_Select_CharMap() API function. */ +/* */ +/* */ +/* Because of 32-bit charcodes defined in Unicode (i.e., surrogates), */ +/* all character codes must be expressed as FT_Longs. */ +/* */ +typedef enum FT_Encoding_ +{ + ft_encoding_none = 0, + ft_encoding_symbol = FT_MAKE_TAG( 's', 'y', 'm', 'b' ), + ft_encoding_unicode = FT_MAKE_TAG( 'u', 'n', 'i', 'c' ), + ft_encoding_latin_2 = FT_MAKE_TAG( 'l', 'a', 't', '2' ), + ft_encoding_sjis = FT_MAKE_TAG( 's', 'j', 'i', 's' ), + ft_encoding_gb2312 = FT_MAKE_TAG( 'g', 'b', ' ', ' ' ), + ft_encoding_big5 = FT_MAKE_TAG( 'b', 'i', 'g', '5' ), + ft_encoding_wansung = FT_MAKE_TAG( 'w', 'a', 'n', 's' ), + ft_encoding_johab = FT_MAKE_TAG( 'j', 'o', 'h', 'a' ), + + ft_encoding_adobe_standard = FT_MAKE_TAG( 'A', 'D', 'O', 'B' ), + ft_encoding_adobe_expert = FT_MAKE_TAG( 'A', 'D', 'B', 'E' ), + ft_encoding_adobe_custom = FT_MAKE_TAG( 'A', 'D', 'B', 'C' ), + + ft_encoding_apple_roman = FT_MAKE_TAG( 'a', 'r', 'm', 'n' ) + + /* other encodings might be defined in the future */ + +} FT_Encoding; + + +/*************************************************************************/ +/* */ +/* */ +/* FT_CharMapRec */ +/* */ +/* */ +/* The base charmap class. */ +/* */ +/* */ +/* face :: A handle to the parent face object. */ +/* */ +/* flags :: A set of bit flags used to describe the charmap. */ +/* Each bit indicates that a given encoding is */ +/* supported. */ +/* */ +/* platform_id :: An ID number describing the platform for the */ +/* following encoding ID. This comes directly from */ +/* the TrueType specification and should be emulated */ +/* for other formats. */ +/* */ +/* encoding_id :: A platform specific encoding number. This also */ +/* comes from the TrueType specification and should be */ +/* emulated similarly. */ +/* */ +/* */ +/* We STRONGLY recommmend emulating a Unicode charmap for drivers */ +/* that do not support TrueType or OpenType. */ +/* */ +typedef struct FT_CharMapRec_ +{ + FT_Face face; + FT_Encoding encoding; + FT_UShort platform_id; + FT_UShort encoding_id; + +} FT_CharMapRec; + + +/*************************************************************************/ +/*************************************************************************/ +/* */ +/* B A S E O B J E C T C L A S S E S */ +/* */ +/*************************************************************************/ +/*************************************************************************/ + +/*************************************************************************/ +/* */ +/* FreeType base face class */ +/* */ +/* */ +/* FT_FaceRec */ +/* */ +/* */ +/* FreeType root face class structure. A face object models the */ +/* resolution and point-size independent data found in a font file. */ +/* */ +/* */ +/* num_faces :: In the case where the face is located in a */ +/* collection (i.e., a resource which embeds */ +/* several faces), this is the total number of */ +/* faces found in the resource. 1 by default. */ +/* */ +/* face_index :: The index of the face in its resource. */ +/* Usually, this is 0 for all normal font */ +/* formats. It can be more in the case of */ +/* collections (which embed several fonts in a */ +/* single resource/file). */ +/* */ +/* face_flags :: A set of bit flags that give important */ +/* information about the face; see the */ +/* FT_FACE_FLAG_XXX macros for details. */ +/* */ +/* style_flags :: A set of bit flags indicating the style of */ +/* the face (i.e., italic, bold, underline, */ +/* etc). */ +/* */ +/* num_glyphs :: The total number of glyphs in the face. */ +/* */ +/* family_name :: The face's family name. This is an ASCII */ +/* string, usually in English, which describes */ +/* the typeface's family (like `Times New */ +/* Roman', `Bodoni', `Garamond', etc). This */ +/* is a least common denominator used to list */ +/* fonts. Some formats (TrueType & OpenType) */ +/* provide localized and Unicode versions of */ +/* this string. Applications should use the */ +/* format specific interface to access them. */ +/* */ +/* style_name :: The face's style name. This is an ASCII */ +/* string, usually in English, which describes */ +/* the typeface's style (like `Italic', */ +/* `Bold', `Condensed', etc). Not all font */ +/* formats provide a style name, so this field */ +/* is optional, and can be set to NULL. As */ +/* for `family_name', some formats provide */ +/* localized/Unicode versions of this string. */ +/* Applications should use the format specific */ +/* interface to access them. */ +/* */ +/* num_fixed_sizes :: The number of fixed sizes available in this */ +/* face. This should be set to 0 for scalable */ +/* fonts, unless its resource includes a */ +/* complete set of glyphs (called a `strike') */ +/* for the specified size. */ +/* */ +/* available_sizes :: An array of sizes specifying the available */ +/* bitmap/graymap sizes that are contained in */ +/* in the font resource. Should be set to */ +/* NULL if the field `num_fixed_sizes' is set */ +/* to 0. */ +/* */ +/* num_charmaps :: The total number of character maps in the */ +/* face. */ +/* */ +/* charmaps :: A table of pointers to the face's charmaps */ +/* Used to scan the list of available charmaps */ +/* this table might change after a call to */ +/* FT_Attach_File/Stream (e.g. when it used */ +/* to hook and additional encoding/CMap to */ +/* the face object). */ +/* */ +/* generic :: A field reserved for client uses. See the */ +/* FT_Generic type description. */ +/* */ +/* bbox :: The font bounding box. Coordinates are */ +/* expressed in font units (see units_per_EM). */ +/* The box is large enough to contain any */ +/* glyph from the font. Thus, bbox.yMax can */ +/* be seen as the `maximal ascender', */ +/* bbox.yMin as the `minimal descender', and */ +/* the maximal glyph width is given by */ +/* `bbox.xMax-bbox.xMin' (not to be confused */ +/* with the maximal _advance_width_). Only */ +/* relevant for scalable formats. */ +/* */ +/* units_per_EM :: The number of font units per EM square for */ +/* this face. This is typically 2048 for */ +/* TrueType fonts, 1000 for Type1 fonts, and */ +/* should be set to the (unrealistic) value 1 */ +/* for fixed-sizes fonts. Only relevant for */ +/* scalable formats. */ +/* */ +/* ascender :: The face's ascender is the vertical */ +/* distance from the baseline to the topmost */ +/* point of any glyph in the face. This */ +/* field's value is positive, expressed in */ +/* font units. Some font designs use a value */ +/* different from `bbox.yMax'. Only relevant */ +/* for scalable formats. */ +/* */ +/* descender :: The face's descender is the vertical */ +/* distance from the baseline to the */ +/* bottommost point of any glyph in the face. */ +/* This field's value is positive, expressed */ +/* in font units. Some font designs use a */ +/* value different from `-bbox.yMin'. Only */ +/* relevant for scalable formats. */ +/* */ +/* height :: The face's height is the vertical distance */ +/* from one baseline to the next when writing */ +/* several lines of text. Its value is always */ +/* positive, expressed in font units. The */ +/* value can be computed as */ +/* `ascender+descender+line_gap' where the */ +/* value of `line_gap' is also called */ +/* `external leading'. Only relevant for */ +/* scalable formats. */ +/* */ +/* max_advance_width :: The maximal advance width, in font units, */ +/* for all glyphs in this face. This can be */ +/* used to make word wrapping computations */ +/* faster. Only relevant for scalable */ +/* formats. */ +/* */ +/* max_advance_height :: The maximal advance height, in font units, */ +/* for all glyphs in this face. This is only */ +/* relevant for vertical layouts, and should */ +/* be set to the `height' for fonts that do */ +/* not provide vertical metrics. Only */ +/* relevant for scalable formats. */ +/* */ +/* underline_position :: The position, in font units, of the */ +/* underline line for this face. It's the */ +/* center of the underlining stem. Only */ +/* relevant for scalable formats. */ +/* */ +/* underline_thickness :: The thickness, in font units, of the */ +/* underline for this face. Only relevant for */ +/* scalable formats. */ +/* */ +/* driver :: A handle to the face's parent driver */ +/* object. */ +/* */ +/* memory :: A handle to the face's parent memory */ +/* object. Used for the allocation of */ +/* subsequent objects. */ +/* */ +/* stream :: A handle to the face's stream. */ +/* */ +/* glyph :: The face's associated glyph slot(s). This */ +/* object is created automatically with a new */ +/* face object. However, certain kinds of */ +/* applications (mainly tools like converters) */ +/* can need more than one slot to ease their */ +/* task. */ +/* */ +/* sizes_list :: The list of child sizes for this face. */ +/* */ +/* max_points :: The maximal number of points used to store */ +/* the vectorial outline of any glyph in this */ +/* face. If this value cannot be known in */ +/* advance, or if the face isn't scalable, */ +/* this should be set to 0. Only relevant for */ +/* scalable formats. */ +/* */ +/* max_contours :: The maximal number of contours used to */ +/* store the vectorial outline of any glyph in */ +/* this face. If this value cannot be known */ +/* in advance, or if the face isn't scalable, */ +/* this should be set to 0. Only relevant for */ +/* scalable formats. */ +/* */ +/* transform_matrix :: A 2x2 matrix of 16.16 coefficients used */ +/* to transform glyph outlines after they are */ +/* loaded from the font. Only used by the */ +/* convenience functions. */ +/* */ +/* transform_delta :: A translation vector used to transform */ +/* glyph outlines after they are loaded from */ +/* the font. Only used by the convenience */ +/* functions. */ +/* */ +/* transform_flags :: Some flags used to classify the transform. */ +/* Only used by the convenience functions. */ +/* */ +typedef struct FT_FaceRec_ +{ + FT_Long num_faces; + FT_Long face_index; + + FT_Long face_flags; + FT_Long style_flags; + + FT_Long num_glyphs; + + FT_String* family_name; + FT_String* style_name; + + FT_Int num_fixed_sizes; + FT_Bitmap_Size* available_sizes; + + /* the face's table of available charmaps */ + FT_Int num_charmaps; + FT_CharMap* charmaps; + + FT_Generic generic; + + /* the following are only relevant for scalable outlines */ + FT_BBox bbox; + + FT_UShort units_per_EM; + FT_Short ascender; + FT_Short descender; + FT_Short height; + + FT_Short max_advance_width; + FT_Short max_advance_height; + + FT_Short underline_position; + FT_Short underline_thickness; + + FT_GlyphSlot glyph; + FT_Size size; + + /************************************************************/ + /* The following fields should be considered private and */ + /* rarely, if ever, used directly by client applications. */ + + FT_Driver driver; + FT_Memory memory; + FT_Stream stream; + + FT_CharMap charmap; + FT_ListRec sizes_list; + + FT_Generic autohint; + void* extensions; + + FT_UShort max_points; + FT_Short max_contours; + + FT_Matrix transform_matrix; + FT_Vector transform_delta; + FT_Int transform_flags; + +} FT_FaceRec; + + +/*************************************************************************/ +/* */ +/* */ +/* FT_FACE_FLAG_SCALABLE */ +/* */ +/* */ +/* A bit-field constant, used to indicate that a given face provides */ +/* vectorial outlines (i.e., TrueType or Type1). This doesn't */ +/* prevent embedding of bitmap strikes though, i.e., a given face can */ +/* have both this bit set, and a `num_fixed_sizes' property > 0. */ +/* */ +#define FT_FACE_FLAG_SCALABLE 1 + + +/*************************************************************************/ +/* */ +/* */ +/* FT_FACE_FLAG_FIXED_SIZES */ +/* */ +/* */ +/* A bit-field constant, used to indicate that a given face contains */ +/* `fixed sizes', i.e., bitmap strikes for some given pixel sizes. */ +/* See the `num_fixed_sizes' and `available_sizes' face properties */ +/* for more information. */ +/* */ +#define FT_FACE_FLAG_FIXED_SIZES 2 + + +/*************************************************************************/ +/* */ +/* */ +/* FT_FACE_FLAG_FIXED_WIDTH */ +/* */ +/* */ +/* A bit-field constant, used to indicate that a given face contains */ +/* fixed-width characters (like Courier, Lucida, MonoType, etc.). */ +/* */ +#define FT_FACE_FLAG_FIXED_WIDTH 4 + + +/*************************************************************************/ +/* */ +/* */ +/* FT_FACE_FLAG_SFNT */ +/* */ +/* */ +/* A bit-field constant, used to indicate that a given face uses the */ +/* `sfnt' storage fomat. For now, this means TrueType or OpenType. */ +/* */ +#define FT_FACE_FLAG_SFNT 8 + + +/*************************************************************************/ +/* */ +/* */ +/* FT_FACE_FLAG_HORIZONTAL */ +/* */ +/* */ +/* A bit-field constant, used to indicate that a given face contains */ +/* horizontal glyph metrics. This should be set for all common */ +/* formats, but who knows. */ +/* */ +#define FT_FACE_FLAG_HORIZONTAL 0x10 + + +/*************************************************************************/ +/* */ +/* */ +/* FT_FACE_FLAG_VERTICAL */ +/* */ +/* */ +/* A bit-field constant, used to indicate that a given face contains */ +/* vertical glyph metrics. If not set, the glyph loader will */ +/* synthetize vertical metrics itself to help display vertical text */ +/* correctly. */ +/* */ +#define FT_FACE_FLAG_VERTICAL 0x20 + + +/*************************************************************************/ +/* */ +/* */ +/* FT_FACE_FLAG_KERNING */ +/* */ +/* */ +/* A bit-field constant, used to indicate that a given face contains */ +/* kerning information. When set, this information can be retrieved */ +/* through the function FT_Get_Kerning(). Note that when unset, this */ +/* function will always return the kerning vector (0,0). */ +/* */ +#define FT_FACE_FLAG_KERNING 0x40 + + +/*************************************************************************/ +/* */ +/* */ +/* FT_FACE_FLAG_FAST_GLYPHS */ +/* */ +/* */ +/* A bit-field constant, used to indicate that the glyphs in a given */ +/* font can be retrieved very quickly, and that a glyph cache is thus */ +/* not necessary for any of its child size objects. */ +/* */ +/* This flag should really be set for fixed-size formats like FNT, */ +/* where each glyph bitmap is available directly in binary form */ +/* without any kind of compression. */ +/* */ +#define FT_FACE_FLAG_FAST_GLYPHS 0x80 + + +/*************************************************************************/ +/* */ +/* */ +/* FT_FACE_FLAG_MULTIPLE_MASTERS */ +/* */ +/* */ +/* A bit-field constant, used to indicate that the font contains */ +/* multiple masters and is capable of interpolating between them. */ +/* */ +#define FT_FACE_FLAG_MULTIPLE_MASTERS 0x100 + + +/*************************************************************************/ +/* */ +/* */ +/* FT_FACE_FLAG_GLYPH_NAMES */ +/* */ +/* */ +/* A bit-field constant, used to indicate that the font contains */ +/* glyph names that can be retrieved through FT_Get_Glyph_Name(). */ +/* */ +#define FT_FACE_FLAG_GLYPH_NAMES 0x200 + + +/*************************************************************************/ +/* */ +/* */ +/* FT_FACE_FLAG_EXTERNAL_STREAM */ +/* */ +/* */ +/* This bit field is used internally by FreeType to indicate that */ +/* a face's stream was provided by the client application and should */ +/* not be destroyed by FT_Done_Face(). */ +/* */ +#define FT_FACE_FLAG_EXTERNAL_STREAM 0x4000 + + +#define FT_HAS_HORIZONTAL( face ) \ + ( face->face_flags & FT_FACE_FLAG_HORIZONTAL ) +#define FT_HAS_VERTICAL( face ) \ + ( face->face_flags & FT_FACE_FLAG_VERTICAL ) +#define FT_HAS_KERNING( face ) \ + ( face->face_flags & FT_FACE_FLAG_KERNING ) +#define FT_IS_SCALABLE( face ) \ + ( face->face_flags & FT_FACE_FLAG_SCALABLE ) +#define FT_IS_SFNT( face ) \ + ( face->face_flags & FT_FACE_FLAG_SFNT ) +#define FT_IS_FIXED_WIDTH( face ) \ + ( face->face_flags & FT_FACE_FLAG_FIXED_WIDTH ) +#define FT_HAS_FIXED_SIZES( face ) \ + ( face->face_flags & FT_FACE_FLAG_FIXED_SIZES ) +#define FT_HAS_FAST_GLYPHS( face ) \ + ( face->face_flags & FT_FACE_FLAG_FAST_GLYPHS ) +#define FT_HAS_GLYPH_NAMES( face ) \ + ( face->face_flags & FT_FACE_FLAG_GLYPH_NAMES ) + +#define FT_HAS_MULTIPLE_MASTERS( face ) \ + ( face->face_flags & FT_FACE_FLAG_MULTIPLE_MASTERS ) + + +/*************************************************************************/ +/* */ +/* */ +/* FT_STYLE_FLAG_ITALIC */ +/* */ +/* */ +/* A bit-field constant, used to indicate that a given face is */ +/* italicized. */ +/* */ +#define FT_STYLE_FLAG_ITALIC 1 + + +/*************************************************************************/ +/* */ +/* */ +/* FT_STYLE_FLAG_BOLD */ +/* */ +/* */ +/* A bit-field constant, used to indicate that a given face is */ +/* emboldened. */ +/* */ +#define FT_STYLE_FLAG_BOLD 2 + + +/*************************************************************************/ +/* */ +/* FreeType base size metrics */ +/* */ +/* */ +/* FT_Size_Metrics */ +/* */ +/* */ +/* The size metrics structure returned scaled important distances for */ +/* a given size object. */ +/* */ +/* */ +/* x_ppem :: The character width, expressed in integer pixels. */ +/* This is the width of the EM square expressed in */ +/* pixels, hence the term `ppem' (pixels per EM). */ +/* */ +/* y_ppem :: The character height, expressed in integer pixels. */ +/* This is the height of the EM square expressed in */ +/* pixels, hence the term `ppem' (pixels per EM). */ +/* */ +/* x_scale :: A simple 16.16 fixed point format coefficient used */ +/* to scale horizontal distances expressed in font */ +/* units to fractional (26.6) pixel coordinates. */ +/* */ +/* y_scale :: A simple 16.16 fixed point format coefficient used */ +/* to scale vertical distances expressed in font */ +/* units to fractional (26.6) pixel coordinates. */ +/* */ +/* x_resolution :: The horizontal device resolution for this size */ +/* object, expressed in integer dots per inches */ +/* (dpi). As a convention, fixed font formats set */ +/* this value to 72. */ +/* */ +/* y_resolution :: The vertical device resolution for this size */ +/* object, expressed in integer dots per inches */ +/* (dpi). As a convention, fixed font formats set */ +/* this value to 72. */ +/* */ +/* ascender :: The ascender, expressed in 26.6 fixed point */ +/* pixels. Always positive. */ +/* */ +/* descender :: The descender, expressed in 26.6 fixed point */ +/* pixels. Always positive. */ +/* */ +/* height :: The text height, expressed in 26.6 fixed point */ +/* pixels. Always positive. */ +/* */ +/* max_advance :: Maximum horizontal advance, expressed in 26.6 */ +/* fixed point pixels. Always positive. */ +/* */ +/* */ +/* The values of `ascender', `descender', and `height' are only the */ +/* scaled versions of `face->ascender', `face->descender', and */ +/* `face->height'. */ +/* */ +/* Unfortunately, due to glyph hinting, these values might not be */ +/* exact for certain fonts, they thus must be treated as unreliable */ +/* with an error margin of at least one pixel! */ +/* */ +/* Indeed, the only way to get the exact pixel ascender and descender */ +/* is to render _all_ glyphs. As this would be a definite */ +/* performance hit, it is up to client applications to perform such */ +/* computations. */ +/* */ +typedef struct FT_Size_Metrics_ +{ + FT_UShort x_ppem; /* horizontal pixels per EM */ + FT_UShort y_ppem; /* vertical pixels per EM */ + + FT_Fixed x_scale; /* two scales used to convert font units */ + FT_Fixed y_scale; /* to 26.6 frac. pixel coordinates.. */ + + FT_Pos ascender; /* ascender in 26.6 frac. pixels */ + FT_Pos descender; /* descender in 26.6 frac. pixels */ + FT_Pos height; /* text height in 26.6 frac. pixels */ + FT_Pos max_advance; /* max horizontal advance, in 26.6 pixels */ + +} FT_Size_Metrics; + + +/*************************************************************************/ +/* */ +/* FreeType base size class */ +/* */ +/* */ +/* FT_SizeRec */ +/* */ +/* */ +/* FreeType root size class structure. A size object models the */ +/* resolution and pointsize dependent data of a given face. */ +/* */ +/* */ +/* face :: Handle to the parent face object. */ +/* */ +/* generic :: A typeless pointer, which is unused by the FreeType */ +/* library or any of its drivers. It can be used by */ +/* client applications to link their own data to each size */ +/* object. */ +/* */ +/* metrics :: Metrics for this size object. This field is read-only. */ +/* */ +typedef struct FT_SizeRec_ +{ + FT_Face face; /* parent face object */ + FT_Generic generic; /* generic pointer for client uses */ + FT_Size_Metrics metrics; /* size metrics */ + +} FT_SizeRec; + + +/*************************************************************************/ +/* */ +/* */ +/* FT_SubGlyph */ +/* */ +/* */ +/* The subglyph structure is an internal object used to describe */ +/* subglyphs (for example, in the case of composites). */ +/* */ +/* */ +/* The subglyph implementation is not part of the high-level API, */ +/* hence the forward structure declaration. */ +/* */ +typedef struct FT_SubGlyph_ FT_SubGlyph; + + +/*************************************************************************/ +/* */ +/* */ +/* FT_GlyphLoader */ +/* */ +/* */ +/* The glyph loader is an internal object used to load several glyphs */ +/* together (for example, in the case of composites). */ +/* */ +/* */ +/* The glyph loader implementation is not part of the high-level API, */ +/* hence the forward structure declaration. */ +/* */ +typedef struct FT_GlyphLoader_ FT_GlyphLoader; + + +/*************************************************************************/ +/* */ +/* FreeType Glyph Slot base class */ +/* */ +/* */ +/* FT_GlyphSlotRec */ +/* */ +/* */ +/* FreeType root glyph slot class structure. A glyph slot is a */ +/* container where individual glyphs can be loaded, be they */ +/* vectorial or bitmap/graymaps. */ +/* */ +/* */ +/* library :: A handle to the FreeType library instance */ +/* this slot belongs to. */ +/* */ +/* face :: A handle to the parent face object. */ +/* */ +/* next :: In some cases (like some font tools), several */ +/* glyph slots per face object can be a good */ +/* thing. As this is rare, the glyph slots are */ +/* listed through a direct, single-linked list */ +/* using its `next' field. */ +/* */ +/* generic :: A typeless pointer which is unused by the */ +/* FreeType library or any of its drivers. It */ +/* can be used by client applications to link */ +/* their own data to each size object. */ +/* */ +/* metrics :: The metrics of the last loaded glyph in the */ +/* slot. The returned values depend on the last */ +/* load flags (see the FT_Load_Glyph() API */ +/* function) and can be expressed either in 26.6 */ +/* fractional pixels or font units. */ +/* */ +/* Note that even when the glyph image is */ +/* transformed, the metrics are not. */ +/* */ +/* linearHoriAdvance :: For scalable formats only, this field holds */ +/* the linearly scaled horizontal advance width */ +/* for the glyph (i.e. the scaled and unhinted */ +/* value of the hori advance). This can be */ +/* important to perform correct WYSIWYG layout */ +/* */ +/* Note that this value is expressed by default */ +/* in 16.16 pixels. However, when the glyph is */ +/* loaded with the FT_LOAD_UNSCALED_LINEAR flag, */ +/* this field contains simply the value of the */ +/* advance in original font units. */ +/* */ +/* linearVertAdvance :: For scalable formats only, this field holds */ +/* the linearly scaled vertical advance height */ +/* for the glyph. See linearHoriAdvance for */ +/* comments. */ +/* */ +/* advance :: This is the transformed advance width for the */ +/* glyph. */ +/* */ +/* format :: This field indicates the format of the image */ +/* contained in the glyph slot. Typically */ +/* ft_glyph_format_bitmap, */ +/* ft_glyph_format_outline, and */ +/* ft_glyph_format_composite, but others are */ +/* possible. */ +/* */ +/* bitmap :: This field is used as a bitmap descriptor */ +/* when the slot format is */ +/* ft_glyph_format_bitmap. Note that the */ +/* address and content of the bitmap buffer can */ +/* change between calls of FT_Load_Glyph() and a */ +/* few other functions. */ +/* */ +/* bitmap_left :: This is the bitmap's left bearing expressed */ +/* in integer pixels. Of course, this is only */ +/* valid if the format is */ +/* ft_glyph_format_bitmap. */ +/* */ +/* bitmap_top :: This is the bitmap's top bearing expressed in */ +/* integer pixels. Remember that this is the */ +/* distance from the baseline to the top-most */ +/* glyph scanline, upwards y-coordinates being */ +/* *positive*. */ +/* */ +/* outline :: The outline descriptor for the current glyph */ +/* image if its format is */ +/* ft_glyph_bitmap_outline. */ +/* */ +/* num_subglyphs :: The number of subglyphs in a composite glyph. */ +/* This format is only valid for the composite */ +/* glyph format, that should normally only be */ +/* loaded with the FT_LOAD_NO_RECURSE flag. */ +/* */ +/* subglyphs :: An array of subglyph descriptors for */ +/* composite glyphs. There are `num_subglyphs' */ +/* elements in there. */ +/* */ +/* control_data :: Certain font drivers can also return the */ +/* control data for a given glyph image (e.g. */ +/* TrueType bytecode, Type 1 charstrings, etc.). */ +/* This field is a pointer to such data. */ +/* */ +/* control_len :: This is the length in bytes of the control */ +/* data. */ +/* */ +/* other :: Really wicked formats can use this pointer to */ +/* present their own glyph image to client apps. */ +/* Note that the app will need to know about the */ +/* image format. */ +/* */ +/* loader :: This is a private object for the glyph slot. */ +/* Do not touch this. */ +/* */ +/* */ +/* If FT_Load_Glyph() is called with default flags (FT_LOAD_DEFAULT), */ +/* the glyph image is loaded in the glyph slot in its native format */ +/* (e.g. a vectorial outline for TrueType and Type 1 formats). */ +/* */ +/* This image can later be converted into a bitmap by calling */ +/* FT_Render_Glyph(). This function finds the current renderer for */ +/* the native image's format then invokes it. */ +/* */ +/* The renderer is in charge of transforming the native image through */ +/* the slot's face transformation fields, then convert it into a */ +/* bitmap that is returned in `slot->bitmap'. */ +/* */ +/* Note that `slot->bitmap_left' and `slot->bitmap_top' are also used */ +/* to specify the position of the bitmap relative to the current pen */ +/* position (e.g. coordinates [0,0] on the baseline). Of course, */ +/* `slot->format' is also changed to `ft_glyph_format_bitmap' . */ +/* */ +typedef struct FT_GlyphSlotRec_ +{ + FT_Library library; + FT_Face face; + FT_GlyphSlot next; + FT_UInt flags; + FT_Generic generic; + + FT_Glyph_Metrics metrics; + FT_Fixed linearHoriAdvance; + FT_Fixed linearVertAdvance; + FT_Vector advance; + + FT_Glyph_Format format; + + FT_Bitmap bitmap; + FT_Int bitmap_left; + FT_Int bitmap_top; + + FT_Outline outline; + + FT_UInt num_subglyphs; + FT_SubGlyph* subglyphs; + + void* control_data; + long control_len; + + void* other; + + /* private fields */ + FT_GlyphLoader* loader; + +} FT_GlyphSlotRec; + + +/*************************************************************************/ +/*************************************************************************/ +/* */ +/* F U N C T I O N S */ +/* */ +/*************************************************************************/ +/*************************************************************************/ + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Init_FreeType */ +/* */ +/* */ +/* Initializes a new FreeType library object. The set of drivers */ +/* that are registered by this function is determined at build time. */ +/* */ +/* */ +/* library :: A handle to a new library object. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +FT_EXPORT_DEF( FT_Error ) FT_Init_FreeType( FT_Library * library ); + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Done_FreeType */ +/* */ +/* */ +/* Destroys a given FreeType library object and all of its childs, */ +/* including resources, drivers, faces, sizes, etc. */ +/* */ +/* */ +/* library :: A handle to the target library object. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +FT_EXPORT_DEF( FT_Error ) FT_Done_FreeType( FT_Library library ); + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Open_Flags */ +/* */ +/* */ +/* An enumeration used to list the bit flags used within */ +/* FT_Open_Args(). */ +/* */ +/* */ +/* ft_open_memory :: This is a memory-based stream. */ +/* */ +/* ft_open_stream :: Copy the stream from the `stream' field. */ +/* */ +/* ft_open_pathname :: Create a new input stream from a C pathname. */ +/* */ +/* ft_open_driver :: Use the `driver' field. */ +/* */ +/* ft_open_params :: Use the `num_params' & `params' field. */ +/* */ +typedef enum +{ + ft_open_memory = 1, + ft_open_stream = 2, + ft_open_pathname = 4, + ft_open_driver = 8, + ft_open_params = 16 + +} FT_Open_Flags; + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Parameter */ +/* */ +/* */ +/* A simple structure used to pass more or less generic parameters */ +/* to FT_Open_Face(). */ +/* */ +/* */ +/* tag :: A 4-byte identification tag. */ +/* */ +/* data :: A pointer to the parameter data. */ +/* */ +/* */ +/* The id and function of parameters are driver-specific. */ +/* */ +typedef struct FT_Parameter_ +{ + FT_ULong tag; + FT_Pointer data; + +} FT_Parameter; + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Open_Args */ +/* */ +/* */ +/* A structure used to indicate how to open a new font file/stream. */ +/* A pointer to such a structure can be used as a parameter for the */ +/* functions FT_Open_Face() & FT_Attach_Stream(). */ +/* */ +/* */ +/* flags :: A set of bit flags indicating how to use the */ +/* structure. */ +/* */ +/* memory_base :: The first byte of the file in memory. */ +/* */ +/* memory_size :: The size in bytes of the file in memory. */ +/* */ +/* pathname :: A pointer to an 8-bit file pathname. */ +/* */ +/* stream :: A handle to a source stream object. */ +/* */ +/* driver :: This field is exclusively used by FT_Open_Face(); */ +/* it simply specifies the font driver to use to open */ +/* the face. If set to 0, FreeType will try to load */ +/* the face with each one of the drivers in its list. */ +/* */ +/* num_params :: The number of extra parameters. */ +/* */ +/* params :: Extra parameters passed to the font driver when */ +/* opening a new face. */ +/* */ +/* */ +/* `stream_type' determines which fields are used to create a new */ +/* input stream. */ +/* */ +/* If it is `ft_stream_memory', a new memory-based stream will be */ +/* created using the memory block specified by `memory_base' and */ +/* `memory_size'. */ +/* */ +/* If it is `ft_stream_pathname', a new stream will be created with */ +/* the `pathname' field, calling the system-specific FT_New_Stream() */ +/* function. */ +/* */ +/* If is is `ft_stream_copy', then the content of `stream' will be */ +/* copied to a new input stream object. The object will be closed */ +/* and destroyed when the face is destroyed itself. Note that this */ +/* means that you should not close the stream before the library */ +/* does! */ +/* */ +typedef struct FT_Open_Args_ +{ + FT_Open_Flags flags; + FT_Byte* memory_base; + FT_Long memory_size; + FT_String* pathname; + FT_Stream stream; + FT_Module driver; + FT_Int num_params; + FT_Parameter* params; + +} FT_Open_Args; + + +/*************************************************************************/ +/* */ +/* */ +/* FT_New_Face */ +/* */ +/* */ +/* Creates a new face object from a given resource and typeface index */ +/* using a pathname to the font file. */ +/* */ +/* */ +/* library :: A handle to the library resource. */ +/* */ +/* */ +/* pathname :: A path to the font file. */ +/* */ +/* face_index :: The index of the face within the resource. The */ +/* first face has index 0. */ +/* */ +/* aface :: A handle to a new face object. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +/* */ +/* Unlike FreeType 1.x, this function automatically creates a glyph */ +/* slot for the face object which can be accessed directly through */ +/* `face->glyph'. */ +/* */ +/* Note that additional slots can be added to each face with the */ +/* FT_New_GlyphSlot() API function. Slots are linked in a single */ +/* list through their `next' field. */ +/* */ +/* FT_New_Face() can be used to determine and/or check the font */ +/* format of a given font resource. If the `face_index' field is */ +/* negative, the function will _not_ return any face handle in */ +/* `*face'. Its return value should be 0 if the resource is */ +/* recognized, or non-zero if not. */ +/* */ +FT_EXPORT_DEF( FT_Error ) FT_New_Face( FT_Library library, + const char* filepathname, + FT_Long face_index, + FT_Face * face ); + + +/*************************************************************************/ +/* */ +/* */ +/* FT_New_Memory_Face */ +/* */ +/* */ +/* Creates a new face object from a given resource and typeface index */ +/* using a font file already loaded into memory. */ +/* */ +/* */ +/* library :: A handle to the library resource. */ +/* */ +/* */ +/* file_base :: A pointer to the beginning of the font data. */ +/* */ +/* file_size :: The size of the memory chunk used by the font data. */ +/* */ +/* face_index :: The index of the face within the resource. The */ +/* first face has index 0. */ +/* */ +/* face :: A handle to a new face object. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +/* */ +/* Unlike FreeType 1.x, this function automatically creates a glyph */ +/* slot for the face object which can be accessed directly through */ +/* `face->glyph'. */ +/* */ +/* Note that additional slots can be added to each face with the */ +/* FT_New_GlyphSlot() API function. Slots are linked in a single */ +/* list through their `next' field. */ +/* */ +/* FT_New_Memory_Face() can be used to determine and/or check the */ +/* font format of a given font resource. If the `face_index' field */ +/* is negative, the function will _not_ return any face handle in */ +/* `*face'. Its return value should be 0 if the resource is */ +/* recognized, or non-zero if not. */ +/* */ +FT_EXPORT_DEF( FT_Error ) FT_New_Memory_Face( FT_Library library, + FT_Byte * file_base, + FT_Long file_size, + FT_Long face_index, + FT_Face * face ); + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Open_Face */ +/* */ +/* */ +/* Opens a face object from a given resource and typeface index using */ +/* an `FT_Open_Args' structure. If the face object doesn't exist, it */ +/* will be created. */ +/* */ +/* */ +/* library :: A handle to the library resource. */ +/* */ +/* */ +/* args :: A pointer to an `FT_Open_Args' structure which must */ +/* be filled by the caller. */ +/* */ +/* face_index :: The index of the face within the resource. The */ +/* first face has index 0. */ +/* */ +/* aface :: A handle to a new face object. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +/* */ +/* Unlike FreeType 1.x, this function automatically creates a glyph */ +/* slot for the face object which can be accessed directly through */ +/* `face->glyph'. */ +/* */ +/* Note that additional slots can be added to each face with the */ +/* FT_New_GlyphSlot() API function. Slots are linked in a single */ +/* list through their `next' field. */ +/* */ +/* FT_Open_Face() can be used to determine and/or check the font */ +/* format of a given font resource. If the `face_index' field is */ +/* negative, the function will _not_ return any face handle in */ +/* `*face'. Its return value should be 0 if the resource is */ +/* recognized, or non-zero if not. */ +/* */ +FT_EXPORT_DEF( FT_Error ) FT_Open_Face( FT_Library library, + FT_Open_Args * args, + FT_Long face_index, + FT_Face * face ); + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Attach_File */ +/* */ +/* */ +/* `Attaches' a given font file to an existing face. This is usually */ +/* to read additional information for a single face object. For */ +/* example, it is used to read the AFM files that come with Type 1 */ +/* fonts in order to add kerning data and other metrics. */ +/* */ +/* */ +/* face :: The target face object. */ +/* */ +/* */ +/* filepathname :: An 8-bit pathname naming the `metrics' file. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +/* */ +/* If your font file is in memory, or if you want to provide your */ +/* own input stream object, use FT_Attach_Stream(). */ +/* */ +/* The meaning of the `attach' action (i.e., what really happens when */ +/* the new file is read) is not fixed by FreeType itself. It really */ +/* depends on the font format (and thus the font driver). */ +/* */ +/* Client applications are expected to know what they are doing */ +/* when invoking this function. Most drivers simply do not implement */ +/* file attachments. */ +/* */ +FT_EXPORT_DEF( FT_Error ) FT_Attach_File( FT_Face face, + const char* filepathname ); + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Attach_Stream */ +/* */ +/* */ +/* This function is similar to FT_Attach_File() with the exception */ +/* that it reads the attachment from an arbitrary stream. */ +/* */ +/* */ +/* face :: The target face object. */ +/* */ +/* parameters :: A pointer to an FT_Open_Args structure used to */ +/* describe the input stream to FreeType. */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +/* */ +/* The meaning of the `attach' (i.e. what really happens when the */ +/* new file is read) is not fixed by FreeType itself. It really */ +/* depends on the font format (and thus the font driver). */ +/* */ +/* Client applications are expected to know what they are doing */ +/* when invoking this function. Most drivers simply do not implement */ +/* file attachments. */ +/* */ +FT_EXPORT_DEF( FT_Error ) FT_Attach_Stream( FT_Face face, + FT_Open_Args * parameters ); + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Done_Face */ +/* */ +/* */ +/* Discards a given face object, as well as all of its child slots */ +/* and sizes. */ +/* */ +/* */ +/* face :: A handle to a target face object. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +FT_EXPORT_DEF( FT_Error ) FT_Done_Face( FT_Face face ); + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Set_Char_Size */ +/* */ +/* */ +/* Sets the character dimensions of a given face object. The */ +/* `char_width' and `char_height' values are used for the width and */ +/* height, respectively, expressed in 26.6 fractional points. */ +/* */ +/* If the horizontal or vertical resolution values are zero, a */ +/* default value of 72dpi is used. Similarly, if one of the */ +/* character dimensions is zero, its value is set equal to the other. */ +/* */ +/* */ +/* size :: A handle to a target size object. */ +/* */ +/* */ +/* char_width :: The character width, in 26.6 fractional points. */ +/* */ +/* char_height :: The character height, in 26.6 fractional */ +/* points. */ +/* */ +/* horz_resolution :: The horizontal resolution. */ +/* */ +/* vert_resolution :: The vertical resolution. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +/* */ +/* When dealing with fixed-size faces (i.e., non-scalable formats), */ +/* use the function FT_Set_Pixel_Sizes(). */ +/* */ +FT_EXPORT_DEF( FT_Error ) FT_Set_Char_Size( FT_Face face, + FT_F26Dot6 char_width, + FT_F26Dot6 char_height, + FT_UInt horz_resolution, + FT_UInt vert_resolution ); + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Set_Pixel_Sizes */ +/* */ +/* */ +/* Sets the character dimensions of a given face object. The width */ +/* and height are expressed in integer pixels. */ +/* */ +/* If one of the character dimensions is zero, its value is set equal */ +/* to the other. */ +/* */ +/* */ +/* face :: A handle to the target face object. */ +/* */ +/* */ +/* pixel_width :: The character width, in integer pixels. */ +/* */ +/* pixel_height :: The character height, in integer pixels. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +FT_EXPORT_DEF( FT_Error ) FT_Set_Pixel_Sizes( FT_Face face, + FT_UInt pixel_width, + FT_UInt pixel_height ); + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Load_Glyph */ +/* */ +/* */ +/* A function used to load a single glyph within a given glyph slot, */ +/* for a given size. */ +/* */ +/* */ +/* face :: A handle to the target face object where the glyph */ +/* will be loaded. */ +/* */ +/* glyph_index :: The index of the glyph in the font file. */ +/* */ +/* load_flags :: A flag indicating what to load for this glyph. The */ +/* FT_LOAD_XXX constants can be used to control the */ +/* glyph loading process (e.g., whether the outline */ +/* should be scaled, whether to load bitmaps or not, */ +/* whether to hint the outline, etc). */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +/* */ +/* If the glyph image is not a bitmap, and if the bit flag */ +/* FT_LOAD_IGNORE_TRANSFORM is unset, the glyph image will be */ +/* transformed with the information passed to a previous call to */ +/* FT_Set_Transform. */ +/* */ +/* Note that this also transforms the `face.glyph.advance' field, but */ +/* *not* the values in `face.glyph.metrics'. */ +/* */ +FT_EXPORT_DEF( FT_Error ) FT_Load_Glyph( FT_Face face, + FT_UInt glyph_index, + FT_Int load_flags ); + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Load_Char */ +/* */ +/* */ +/* A function used to load a single glyph within a given glyph slot, */ +/* for a given size, according to its character code. */ +/* */ +/* */ +/* face :: A handle to a target face object where the glyph */ +/* will be loaded. */ +/* */ +/* char_code :: The glyph's character code, according to the */ +/* current charmap used in the face. */ +/* */ +/* load_flags :: A flag indicating what to load for this glyph. The */ +/* FT_LOAD_XXX constants can be used to control the */ +/* glyph loading process (e.g., whether the outline */ +/* should be scaled, whether to load bitmaps or not, */ +/* whether to hint the outline, etc). */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +/* */ +/* If the face has no current charmap, or if the character code */ +/* is not defined in the charmap, this function will return an */ +/* error. */ +/* */ +/* If the glyph image is not a bitmap, and if the bit flag */ +/* FT_LOAD_IGNORE_TRANSFORM is unset, the glyph image will be */ +/* transformed with the information passed to a previous call to */ +/* FT_Set_Transform(). */ +/* */ +/* Note that this also transforms the `face.glyph.advance' field, but */ +/* *not* the values in `face.glyph.metrics'. */ +/* */ +FT_EXPORT_DEF( FT_Error ) FT_Load_Char( FT_Face face, + FT_ULong char_code, + FT_Int load_flags ); + + +/*************************************************************************/ +/* */ +/* */ +/* FT_LOAD_NO_SCALE */ +/* */ +/* */ +/* A bit field constant, used with FT_Load_Glyph() to indicate that */ +/* the vector outline being loaded should not be scaled to 26.6 */ +/* fractional pixels, but kept in notional units. */ +/* */ +#define FT_LOAD_NO_SCALE 1 + + +/*************************************************************************/ +/* */ +/* */ +/* FT_LOAD_NO_HINTING */ +/* */ +/* */ +/* A bit-field constant, used with FT_Load_Glyph() to indicate that */ +/* the vector outline being loaded should not be fitted to the pixel */ +/* grid but simply scaled to 26.6 fractional pixels. */ +/* */ +/* This flag is ignored if FT_LOAD_NO_SCALE is set. */ +/* */ +#define FT_LOAD_NO_HINTING 2 + + +/*************************************************************************/ +/* */ +/* */ +/* FT_LOAD_RENDER */ +/* */ +/* */ +/* A bit-field constant, used with FT_Load_Glyph() to indicate that */ +/* the function should load the glyph and immediately convert it into */ +/* a bitmap, if necessary, by calling FT_Render_Glyph(). */ +/* */ +/* Note that by default, FT_Load_Glyph() loads the glyph image in its */ +/* native format. */ +/* */ +#define FT_LOAD_RENDER 4 + + +/*************************************************************************/ +/* */ +/* */ +/* FT_LOAD_NO_BITMAP */ +/* */ +/* */ +/* A bit-field constant, used with FT_Load_Glyph() to indicate that */ +/* the function should not load the bitmap or pixmap of a given */ +/* glyph. This is useful when you do not want to load the embedded */ +/* bitmaps of scalable formats, as the native glyph image will be */ +/* loaded, and can then be rendered through FT_Render_Glyph(). */ +/* */ +#define FT_LOAD_NO_BITMAP 8 + + +/*************************************************************************/ +/* */ +/* */ +/* FT_LOAD_VERTICAL_LAYOUT */ +/* */ +/* */ +/* A bit-field constant, used with FT_Load_Glyph() to indicate that */ +/* the glyph image should be prepared for vertical layout. This */ +/* basically means that `face.glyph.advance' will correspond to the */ +/* vertical advance height (instead of the default horizontal */ +/* advance width), and that the glyph image will translated to match */ +/* the vertical bearings positions. */ +/* */ +#define FT_LOAD_VERTICAL_LAYOUT 16 + + +/*************************************************************************/ +/* */ +/* */ +/* FT_LOAD_FORCE_AUTOHINT */ +/* */ +/* */ +/* A bit-field constant, used with FT_Load_Glyph() to indicate that */ +/* the function should try to auto-hint the glyphs, even if a driver */ +/* specific hinter is available. */ +/* */ +#define FT_LOAD_FORCE_AUTOHINT 32 + + +/*************************************************************************/ +/* */ +/* */ +/* FT_LOAD_CROP_BITMAP */ +/* */ +/* */ +/* A bit-field constant, used with FT_Load_Glyph() to indicate that */ +/* the font driver should try to crop the bitmap (i.e. remove all */ +/* space around its black bits) when loading it. For now, this */ +/* really only works with embedded bitmaps in TrueType fonts. */ +/* */ +#define FT_LOAD_CROP_BITMAP 64 + + +/*************************************************************************/ +/* */ +/* */ +/* FT_LOAD_PEDANTIC */ +/* */ +/* */ +/* A bit-field constant, used with FT_Load_Glyph() to indicate that */ +/* the glyph loader should perform a pedantic bytecode */ +/* interpretation. Many popular fonts come with broken glyph */ +/* programs. When this flag is set, loading them will return an */ +/* error. Otherwise, errors are ignored by the loader, sometimes */ +/* resulting in ugly glyphs. */ +/* */ +#define FT_LOAD_PEDANTIC 128 + + +/*************************************************************************/ +/* */ +/* */ +/* FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH */ +/* */ +/* */ +/* A bit-field constant, used with FT_Load_Glyph() to indicate that */ +/* the glyph loader should ignore the global advance width defined */ +/* in the font. As far as we know, this is only used by the */ +/* X-TrueType font server, in order to deal correctly with the */ +/* incorrect metrics contained in DynaLab's TrueType CJK fonts. */ +/* */ +#define FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH 512 + + +/*************************************************************************/ +/* */ +/* */ +/* FT_LOAD_NO_RECURSE */ +/* */ +/* */ +/* A bit-field constant, used with FT_Load_Glyph() to indicate that */ +/* the glyph loader should not load composite glyph recursively. */ +/* Rather, when a composite glyph is encountered, it should set */ +/* the values of `num_subglyphs' and `subglyphs', as well as set */ +/* `face->glyph.format' to ft_glyph_format_composite. */ +/* */ +/* This is for use by the auto-hinter and possibly other tools. */ +/* For nearly all applications, this flags should be left unset */ +/* when invoking FT_Load_Glyph(). */ +/* */ +/* Note that the flag forces the load of unscaled glyphs. */ +/* */ +#define FT_LOAD_NO_RECURSE 1024 + + +/*************************************************************************/ +/* */ +/* */ +/* FT_LOAD_IGNORE_TRANSFORM */ +/* */ +/* */ +/* A bit-field constant, used with FT_Load_Glyph() to indicate that */ +/* the glyph loader should not try to transform the loaded glyph */ +/* image. */ +/* */ +#define FT_LOAD_IGNORE_TRANSFORM 2048 + + +/*************************************************************************/ +/* */ +/* */ +/* FT_LOAD_MONOCHROME */ +/* */ +/* */ +/* Only used with FT_LOAD_RENDER set, it indicates that the returned */ +/* glyph image should be 1-bit monochrome. This really tells the */ +/* glyph loader to use `ft_render_mode_mono' when calling */ +/* FT_Render_Glyph(). */ +/* */ +#define FT_LOAD_MONOCHROME 4096 + + +/*************************************************************************/ +/* */ +/* */ +/* FT_LOAD_LINEAR_DESIGN */ +/* */ +/* */ +/* A bit-field constant, used with FT_Load_Glyph() to indicate that */ +/* the function should return the linearly scaled metrics expressed */ +/* in original font units, instead of the default 16.16 pixel values. */ +/* */ +#define FT_LOAD_LINEAR_DESIGN 8192 + + +/*************************************************************************/ +/* */ +/* */ +/* FT_LOAD_DEFAULT */ +/* */ +/* */ +/* A bit-field constant, used with FT_Load_Glyph() to indicate that */ +/* the function should try to load the glyph normally, i.e., */ +/* embedded bitmaps are favored over outlines, vectors are always */ +/* scaled and grid-fitted. */ +/* */ +#define FT_LOAD_DEFAULT 0 + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Set_Transform */ +/* */ +/* */ +/* A function used to set the transformation that is applied to glyph */ +/* images just before they are converted to bitmaps in a glyph slot */ +/* when FT_Render_Glyph() is called. */ +/* */ +/* */ +/* face :: A handle to the source face object. */ +/* */ +/* */ +/* matrix :: A pointer to the transformation's 2x2 matrix. Use 0 for */ +/* the identity matrix. */ +/* delta :: A pointer to the translation vector. Use 0 for the null */ +/* vector. */ +/* */ +/* */ +/* The transformation is only applied to scalable image formats after */ +/* the glyph has been loaded. It means that hinting is unaltered by */ +/* the transformation and is performed on the character size given in */ +/* the last call to FT_Set_Char_Sizes() or FT_Set_Pixel_Sizes(). */ +/* */ +FT_EXPORT_DEF( void ) FT_Set_Transform( FT_Face face, + FT_Matrix * matrix, + FT_Vector * delta ); + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Render_Mode */ +/* */ +/* */ +/* An enumeration type that lists the render modes supported by the */ +/* FreeType 2 renderer(s). A renderer is in charge of converting a */ +/* glyph image into a bitmap. */ +/* */ +/* */ +/* ft_render_mode_normal :: This is the default render mode; it */ +/* corresponds to 8-bit anti-aliased */ +/* bitmaps, using 256 levels of gray. */ +/* */ +/* ft_render_mode_mono :: This render mode is used to produce 1-bit */ +/* monochrome bitmaps. */ +/* */ +/* */ +/* There is no render mode to produce 8-bit `monochrome' bitmaps -- */ +/* you have to make the conversion yourself if you need such things */ +/* (besides, FreeType is not a graphics library). */ +/* */ +/* More modes might appear later for specific display modes (e.g. TV, */ +/* LCDs, etc.). They will be supported through the simple addition */ +/* of a renderer module, with no changes to the rest of the engine. */ +/* */ +typedef enum FT_Render_Mode_ +{ + ft_render_mode_normal = 0, + ft_render_mode_mono = 1 + +} FT_Render_Mode; + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Render_Glyph */ +/* */ +/* */ +/* Converts a given glyph image to a bitmap. It does so by */ +/* inspecting the glyph image format, find the relevant renderer, and */ +/* invoke it. */ +/* */ +/* */ +/* slot :: A handle to the glyph slot containing the image to */ +/* convert. */ +/* */ +/* render_mode :: This is the render mode used to render the glyph */ +/* image into a bitmap. See FT_Render_Mode for a list */ +/* of possible values. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +FT_EXPORT_DEF( FT_Error ) FT_Render_Glyph( FT_GlyphSlot slot, + FT_UInt render_mode ); + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Kerning_Mode */ +/* */ +/* */ +/* An enumeration used to specify which kerning values to return in */ +/* FT_Get_Kerning(). */ +/* */ +/* */ +/* ft_kerning_default :: Return scaled and grid-fitted kerning */ +/* distances (value is 0). */ +/* */ +/* ft_kerning_unfitted :: Return scaled but un-grid-fitted kerning */ +/* distances. */ +/* */ +/* ft_kerning_unscaled :: Return the kerning vector in original font */ +/* units. */ +/* */ +typedef enum FT_Kerning_Mode_ +{ + ft_kerning_default = 0, + ft_kerning_unfitted, + ft_kerning_unscaled + +} FT_Kerning_Mode; + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Get_Kerning */ +/* */ +/* */ +/* Returns the kerning vector between two glyphs of a same face. */ +/* */ +/* */ +/* face :: A handle to a source face object. */ +/* */ +/* left_glyph :: The index of the left glyph in the kern pair. */ +/* */ +/* right_glyph :: The index of the right glyph in the kern pair. */ +/* */ +/* kern_mode :: See FT_Kerning_Mode() for more information. */ +/* Determines the scale/dimension of the returned */ +/* kerning vector. */ +/* */ +/* */ +/* kerning :: The kerning vector. This is in font units for */ +/* scalable formats, and in pixels for fixed-sizes */ +/* formats. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +/* */ +/* Only horizontal layouts (left-to-right & right-to-left) are */ +/* supported by this method. Other layouts, or more sophisticated */ +/* kernings, are out of the scope of this API function -- they can be */ +/* implemented through format-specific interfaces. */ +/* */ +FT_EXPORT_DEF( FT_Error ) FT_Get_Kerning( FT_Face face, + FT_UInt left_glyph, + FT_UInt right_glyph, + FT_UInt kern_mode, + FT_Vector * kerning ); + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Get_Glyph_Name */ +/* */ +/* */ +/* Retrieves the ASCII name of a given glyph in a face. This only */ +/* works for those faces where FT_HAS_GLYPH_NAME(face) returns true. */ +/* */ +/* */ +/* face :: A handle to a source face object. */ +/* */ +/* glyph_index :: The glyph index. */ +/* */ +/* buffer :: A pointer to a target buffer where the name will be */ +/* copied to. */ +/* */ +/* buffer_max :: The maximal number of bytes available in the */ +/* buffer. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +/* */ +/* An error is returned if the face doesn't provide glyph names or if */ +/* the glyph index is invalid. In all cases of failure, the first */ +/* byte of `buffer' will be set to 0 to indicate an empty name. */ +/* */ +/* The glyph name is truncated to fit within the buffer if it is too */ +/* long. The returned string is always zero-terminated. */ +/* */ +/* This function is not compiled within the library if the config */ +/* macro FT_CONFIG_OPTION_NO_GLYPH_NAMES is defined in */ +/* `include/freetype/config/ftoptions.h' */ +/* */ +FT_EXPORT_DEF( FT_Error ) FT_Get_Glyph_Name( FT_Face face, + FT_UInt glyph_index, + FT_Pointer buffer, + FT_UInt buffer_max ); + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Select_Charmap */ +/* */ +/* */ +/* Selects a given charmap by its encoding tag (as listed in */ +/* `freetype.h'). */ +/* */ +/* */ +/* face :: A handle to the source face object. */ +/* */ +/* encoding :: A handle to the selected charmap. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +/* */ +/* This function will return an error if no charmap in the face */ +/* corresponds to the encoding queried here. */ +/* */ +FT_EXPORT_DEF( FT_Error ) FT_Select_Charmap( FT_Face face, + FT_Encoding encoding ); + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Set_Charmap */ +/* */ +/* */ +/* Selects a given charmap for character code to glyph index */ +/* decoding. */ +/* */ +/* */ +/* face :: A handle to the source face object. */ +/* charmap :: A handle to the selected charmap. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +/* */ +/* This function will return an error if the charmap is not part of */ +/* the face (i.e., if it is not listed in the face->charmaps[] */ +/* table). */ +/* */ +FT_EXPORT_DEF( FT_Error ) FT_Set_Charmap( FT_Face face, + FT_CharMap charmap ); + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Get_Char_Index */ +/* */ +/* */ +/* Returns the glyph index of a given character code. This function */ +/* uses a charmap object to do the translation. */ +/* */ +/* */ +/* face :: A handle to the source face object. */ +/* */ +/* charcode :: The character code. */ +/* */ +/* */ +/* The glyph index. 0 means `undefined character code'. */ +/* */ +FT_EXPORT_DEF( FT_UInt ) FT_Get_Char_Index( FT_Face face, + FT_ULong charcode ); + + +/*************************************************************************/ +/* */ +/* */ +/* FT_MulDiv */ +/* */ +/* */ +/* A very simple function used to perform the computation `(a*b)/c' */ +/* with maximal accuracy (it uses a 64-bit intermediate integer */ +/* whenever necessary). */ +/* */ +/* This function isn't necessarily as fast as some processor specific */ +/* operations, but is at least completely portable. */ +/* */ +/* */ +/* a :: The first multiplier. */ +/* b :: The second multiplier. */ +/* c :: The divisor. */ +/* */ +/* */ +/* The result of `(a*b)/c'. This function never traps when trying to */ +/* divide by zero; it simply returns `MaxInt' or `MinInt' depending */ +/* on the signs of `a' and `b'. */ +/* */ +FT_EXPORT_DEF( FT_Long ) FT_MulDiv( FT_Long a, + FT_Long b, + FT_Long c ); + + +/*************************************************************************/ +/* */ +/* */ +/* FT_MulFix */ +/* */ +/* */ +/* A very simple function used to perform the computation */ +/* `(a*b)/0x10000' with maximal accuracy. Most of the time this is */ +/* used to multiply a given value by a 16.16 fixed float factor. */ +/* */ +/* */ +/* a :: The first multiplier. */ +/* b :: The second multiplier. Use a 16.16 factor here whenever */ +/* possible (see note below). */ +/* */ +/* */ +/* The result of `(a*b)/0x10000'. */ +/* */ +/* */ +/* This function has been optimized for the case where the absolute */ +/* value of `a' is less than 2048, and `b' is a 16.16 scaling factor. */ +/* As this happens mainly when scaling from notional units to */ +/* fractional pixels in FreeType, it resulted in noticeable speed */ +/* improvements between versions 2.x and 1.x. */ +/* */ +/* As a conclusion, always try to place a 16.16 factor as the */ +/* _second_ argument of this function; this can make a great */ +/* difference. */ +/* */ +FT_EXPORT_DEF( FT_Long ) FT_MulFix( FT_Long a, + FT_Long b ); + + +/*************************************************************************/ +/* */ +/* */ +/* FT_DivFix */ +/* */ +/* */ +/* A very simple function used to perform the computation */ +/* `(a*0x10000)/b' with maximal accuracy. Most of the time, this is */ +/* used to divide a given value by a 16.16 fixed float factor. */ +/* */ +/* */ +/* a :: The first multiplier. */ +/* b :: The second multiplier. Use a 16.16 factor here whenever */ +/* possible (see note below). */ +/* */ +/* */ +/* The result of `(a*0x10000)/b'. */ +/* */ +/* */ +/* The optimization for FT_DivFix() is simple: If (a << 16) fits in */ +/* 32 bits, then the division is computed directly. Otherwise, we */ +/* use a specialized version of the old FT_MulDiv64(). */ +/* */ +FT_EXPORT_DEF( FT_Long ) FT_DivFix( FT_Long a, + FT_Long b ); + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Vector_Transform */ +/* */ +/* */ +/* Transforms a single vector through a 2x2 matrix. */ +/* */ +/* */ +/* vector :: The target vector to transform. */ +/* */ +/* */ +/* matrix :: A pointer to the source 2x2 matrix. */ +/* */ +/* */ +/* Yes. */ +/* */ +/* */ +/* The result is undefined if either `vector' or `matrix' is invalid. */ +/* */ +FT_EXPORT_DEF( void ) FT_Vector_Transform( FT_Vector * vec, + FT_Matrix * matrix ); + + + +#ifdef __cplusplus +} +#endif + + +#endif /* FREETYPE_H */ + + +/* END */ diff --git a/Projects/Android/jni/rtcw/src/ft2/ftcalc.c b/Projects/Android/jni/rtcw/src/ft2/ftcalc.c new file mode 100644 index 0000000..403eafa --- /dev/null +++ b/Projects/Android/jni/rtcw/src/ft2/ftcalc.c @@ -0,0 +1,777 @@ +/***************************************************************************/ +/* */ +/* ftcalc.c */ +/* */ +/* Arithmetic computations (body). */ +/* */ +/* Copyright 1996-2000 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + +/*************************************************************************/ +/* */ +/* Support for 1-complement arithmetic has been totally dropped in this */ +/* release. You can still write your own code if you need it. */ +/* */ +/*************************************************************************/ + +/*************************************************************************/ +/* */ +/* Implementing basic computation routines. */ +/* */ +/* FT_MulDiv(), FT_MulFix(), and FT_DivFix() are declared in freetype.h. */ +/* */ +/*************************************************************************/ + + +#include "ftcalc.h" +#include "ftdebug.h" +#include "ftobjs.h" + + +/*************************************************************************/ +/* */ +/* The macro FT_COMPONENT is used in trace mode. It is an implicit */ +/* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */ +/* messages during execution. */ +/* */ +#undef FT_COMPONENT +#define FT_COMPONENT trace_calc + + +#ifdef FT_CONFIG_OPTION_OLD_CALCS + +static const FT_Long ft_square_roots[63] = +{ + 1L, 1L, 2L, 3L, 4L, 5L, 8L, 11L, + 16L, 22L, 32L, 45L, 64L, 90L, 128L, 181L, + 256L, 362L, 512L, 724L, 1024L, 1448L, 2048L, 2896L, + 4096L, 5892L, 8192L, 11585L, 16384L, 23170L, 32768L, 46340L, + + 65536L, 92681L, 131072L, 185363L, 262144L, 370727L, + 524288L, 741455L, 1048576L, 1482910L, 2097152L, 2965820L, + 4194304L, 5931641L, 8388608L, 11863283L, 16777216L, 23726566L, + + 33554432L, 47453132L, 67108864L, 94906265L, + 134217728L, 189812531L, 268435456L, 379625062L, + 536870912L, 759250125L, 1073741824L, 1518500250L, + 2147483647L +}; + +#else + +/*************************************************************************/ +/* */ +/* */ +/* FT_Sqrt32 */ +/* */ +/* */ +/* Computes the square root of an Int32 integer (which will be */ +/* handled as an unsigned long value). */ +/* */ +/* */ +/* x :: The value to compute the root for. */ +/* */ +/* */ +/* The result of `sqrt(x)'. */ +/* */ +FT_EXPORT_FUNC( FT_Int32 ) FT_Sqrt32( FT_Int32 x ) +{ + FT_ULong val, root, newroot, mask; + + + root = 0; + mask = 0x40000000L; + val = (FT_ULong)x; + + do + { + newroot = root + mask; + if ( newroot <= val ) { + val -= newroot; + root = newroot + mask; + } + + root >>= 1; + mask >>= 2; + + } while ( mask != 0 ); + + return root; +} + +#endif /* FT_CONFIG_OPTION_OLD_CALCS */ + + +#ifdef FT_LONG64 + +/*************************************************************************/ +/* */ +/* */ +/* FT_MulDiv */ +/* */ +/* */ +/* A very simple function used to perform the computation `(a*b)/c' */ +/* with maximal accuracy (it uses a 64-bit intermediate integer */ +/* whenever necessary). */ +/* */ +/* This function isn't necessarily as fast as some processor specific */ +/* operations, but is at least completely portable. */ +/* */ +/* */ +/* a :: The first multiplier. */ +/* b :: The second multiplier. */ +/* c :: The divisor. */ +/* */ +/* */ +/* The result of `(a*b)/c'. This function never traps when trying to */ +/* divide by zero; it simply returns `MaxInt' or `MinInt' depending */ +/* on the signs of `a' and `b'. */ +/* */ +FT_EXPORT_FUNC( FT_Long ) FT_MulDiv( FT_Long a, + FT_Long b, + FT_Long c ) +{ + FT_Int s; + + + s = 1; + if ( a < 0 ) { + a = -a; s = -s; + } + if ( b < 0 ) { + b = -b; s = -s; + } + if ( c < 0 ) { + c = -c; s = -s; + } + + return s * ( c > 0 ? ( (FT_Int64)a * b + ( c >> 1 ) ) / c + : 0x7FFFFFFFL ); +} + + +/*************************************************************************/ +/* */ +/* */ +/* FT_MulFix */ +/* */ +/* */ +/* A very simple function used to perform the computation */ +/* `(a*b)/0x10000' with maximal accuracy. Most of the time this is */ +/* used to multiply a given value by a 16.16 fixed float factor. */ +/* */ +/* */ +/* a :: The first multiplier. */ +/* b :: The second multiplier. Use a 16.16 factor here whenever */ +/* possible (see note below). */ +/* */ +/* */ +/* The result of `(a*b)/0x10000'. */ +/* */ +/* */ +/* This function has been optimized for the case where the absolute */ +/* value of `a' is less than 2048, and `b' is a 16.16 scaling factor. */ +/* As this happens mainly when scaling from notional units to */ +/* fractional pixels in FreeType, it resulted in noticeable speed */ +/* improvements between versions 2.x and 1.x. */ +/* */ +/* As a conclusion, always try to place a 16.16 factor as the */ +/* _second_ argument of this function; this can make a great */ +/* difference. */ +/* */ +FT_EXPORT_FUNC( FT_Long ) FT_MulFix( FT_Long a, + FT_Long b ) +{ + FT_Int s; + + + s = 1; + if ( a < 0 ) { + a = -a; s = -s; + } + if ( b < 0 ) { + b = -b; s = -s; + } + + return s * (FT_Long)( ( (FT_Int64)a * b + 0x8000 ) >> 16 ); +} + + +/*************************************************************************/ +/* */ +/* */ +/* FT_DivFix */ +/* */ +/* */ +/* A very simple function used to perform the computation */ +/* `(a*0x10000)/b' with maximal accuracy. Most of the time, this is */ +/* used to divide a given value by a 16.16 fixed float factor. */ +/* */ +/* */ +/* a :: The first multiplier. */ +/* b :: The second multiplier. Use a 16.16 factor here whenever */ +/* possible (see note below). */ +/* */ +/* */ +/* The result of `(a*0x10000)/b'. */ +/* */ +/* */ +/* The optimization for FT_DivFix() is simple: If (a << 16) fits in */ +/* 32 bits, then the division is computed directly. Otherwise, we */ +/* use a specialized version of the old FT_MulDiv64(). */ +/* */ +FT_EXPORT_FUNC( FT_Long ) FT_DivFix( FT_Long a, + FT_Long b ) +{ + FT_Int32 s; + FT_UInt32 q; + + + s = a; a = ABS( a ); + s ^= b; b = ABS( b ); + + if ( b == 0 ) { + /* check for division by 0 */ + q = 0x7FFFFFFFL; + } else { + /* compute result directly */ + q = ( (FT_Int64)a << 16 ) / b; + } + + return (FT_Int32)( s < 0 ? -q : q ); +} + + +#ifdef FT_CONFIG_OPTION_OLD_CALCS + +/* a helper function for FT_Sqrt64() */ + +static +int ft_order64( FT_Int64 z ) { + int j = 0; + + + while ( z ) + { + z = (unsigned FT_INT64)z >> 1; + j++; + } + return j - 1; +} + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Sqrt64 */ +/* */ +/* */ +/* Computes the square root of a 64-bit value. That sounds stupid, */ +/* but it is needed to obtain maximal accuracy in the TrueType */ +/* bytecode interpreter. */ +/* */ +/* */ +/* l :: A 64-bit integer. */ +/* */ +/* */ +/* The 32-bit square-root. */ +/* */ +FT_EXPORT_FUNC( FT_Int32 ) FT_Sqrt64( FT_Int64 l ) +{ + FT_Int64 r, s; + + + if ( l <= 0 ) { + return 0; + } + if ( l == 1 ) { + return 1; + } + + r = ft_square_roots[ft_order64( l )]; + + do + { + s = r; + r = ( r + l / r ) >> 1; + + } while ( r > s || r * r > l ); + + return r; +} + +#endif /* FT_CONFIG_OPTION_OLD_CALCS */ + + +#else /* FT_LONG64 */ + + +/*************************************************************************/ +/* */ +/* */ +/* FT_MulDiv */ +/* */ +/* */ +/* A very simple function used to perform the computation `(a*b)/c' */ +/* with maximal accuracy (it uses a 64-bit intermediate integer */ +/* whenever necessary). */ +/* */ +/* This function isn't necessarily as fast as some processor specific */ +/* operations, but is at least completely portable. */ +/* */ +/* */ +/* a :: The first multiplier. */ +/* b :: The second multiplier. */ +/* c :: The divisor. */ +/* */ +/* */ +/* The result of `(a*b)/c'. This function never traps when trying to */ +/* divide by zero; it simply returns `MaxInt' or `MinInt' depending */ +/* on the signs of `a' and `b'. */ +/* */ +/* */ +/* The FT_MulDiv() function has been optimized thanks to ideas from */ +/* Graham Asher. The trick is to optimize computation if everything */ +/* fits within 32 bits (a rather common case). */ +/* */ +/* We compute `a*b+c/2', then divide it by `c' (positive values). */ +/* */ +/* 46340 is FLOOR(SQRT(2^31-1)). */ +/* */ +/* if ( a <= 46340 && b <= 46340 ) then ( a*b <= 0x7FFEA810 ) */ +/* */ +/* 0x7FFFFFFF - 0x7FFEA810 = 0x157F0 */ +/* */ +/* if ( c < 0x157F0*2 ) then ( a*b+c/2 <= 0x7FFFFFFF ) */ +/* */ +/* and 2*0x157F0 = 176096. */ +/* */ +FT_EXPORT_FUNC( FT_Long ) FT_MulDiv( FT_Long a, + FT_Long b, + FT_Long c ) +{ + long s; + + + if ( a == 0 || b == c ) { + return a; + } + + s = a; a = ABS( a ); + s ^= b; b = ABS( b ); + s ^= c; c = ABS( c ); + + if ( a <= 46340 && b <= 46340 && c <= 176095L && c > 0 ) { + a = ( a * b + ( c >> 1 ) ) / c; + } else if ( c > 0 ) { + FT_Int64 temp, temp2; + + + FT_MulTo64( a, b, &temp ); + temp2.hi = (FT_Int32)( c >> 31 ); + temp2.lo = (FT_UInt32)( c / 2 ); + FT_Add64( &temp, &temp2, &temp ); + a = FT_Div64by32( &temp, c ); + } else { + a = 0x7FFFFFFFL; + } + + return ( s < 0 ? -a : a ); +} + + +/*************************************************************************/ +/* */ +/* */ +/* FT_MulFix */ +/* */ +/* */ +/* A very simple function used to perform the computation */ +/* `(a*b)/0x10000' with maximal accuracy. Most of the time, this is */ +/* used to multiply a given value by a 16.16 fixed float factor. */ +/* */ +/* */ +/* a :: The first multiplier. */ +/* b :: The second multiplier. Use a 16.16 factor here whenever */ +/* possible (see note below). */ +/* */ +/* */ +/* The result of `(a*b)/0x10000'. */ +/* */ +/* */ +/* The optimization for FT_MulFix() is different. We could simply be */ +/* happy by applying the same principles as with FT_MulDiv(), because */ +/* */ +/* c = 0x10000 < 176096 */ +/* */ +/* However, in most cases, we have a `b' with a value around 0x10000 */ +/* which is greater than 46340. */ +/* */ +/* According to some testing, most cases have `a' < 2048, so a good */ +/* idea is to use bounds like 2048 and 1048576 (=floor((2^31-1)/2048) */ +/* for `a' and `b', respectively. */ +/* */ +FT_EXPORT_FUNC( FT_Long ) FT_MulFix( FT_Long a, + FT_Long b ) +{ + FT_Long s; + FT_ULong ua, ub; + + + if ( a == 0 || b == 0x10000L ) { + return a; + } + + s = a; a = ABS( a ); + s ^= b; b = ABS( b ); + + ua = (FT_ULong)a; + ub = (FT_ULong)b; + + if ( ua <= 2048 && ub <= 1048576L ) { + ua = ( ua * ub + 0x8000 ) >> 16; + } else + { + FT_ULong al = ua & 0xFFFF; + + + ua = ( ua >> 16 ) * ub + + al * ( ub >> 16 ) + + ( al * ( ub & 0xFFFF ) >> 16 ); + } + + return ( s < 0 ? -(FT_Long)ua : ua ); +} + + +/*************************************************************************/ +/* */ +/* */ +/* FT_DivFix */ +/* */ +/* */ +/* A very simple function used to perform the computation */ +/* `(a*0x10000)/b' with maximal accuracy. Most of the time, this is */ +/* used to divide a given value by a 16.16 fixed float factor. */ +/* */ +/* */ +/* a :: The first multiplier. */ +/* b :: The second multiplier. Use a 16.16 factor here whenever */ +/* possible (see note below). */ +/* */ +/* */ +/* The result of `(a*0x10000)/b'. */ +/* */ +/* */ +/* The optimization for FT_DivFix() is simple: If (a << 16) fits into */ +/* 32 bits, then the division is computed directly. Otherwise, we */ +/* use a specialized version of the old FT_MulDiv64(). */ +/* */ +FT_EXPORT_FUNC( FT_Long ) FT_DivFix( FT_Long a, + FT_Long b ) +{ + FT_Int32 s; + FT_UInt32 q; + + + s = a; a = ABS( a ); + s ^= b; b = ABS( b ); + + if ( b == 0 ) { + /* check for division by 0 */ + q = 0x7FFFFFFFL; + } else if ( ( a >> 16 ) == 0 ) { + /* compute result directly */ + q = (FT_UInt32)( a << 16 ) / (FT_UInt32)b; + } else + { + /* we need more bits; we have to do it by hand */ + FT_UInt32 c; + + + q = ( a / b ) << 16; + c = a % b; + + /* we must compute C*0x10000/B: we simply shift C and B so */ + /* C becomes smaller than 16 bits */ + while ( c >> 16 ) + { + c >>= 1; + b <<= 1; + } + + q += ( c << 16 ) / b; + } + + return ( s < 0 ? -(FT_Int32)q : (FT_Int32)q ); +} + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Add64 */ +/* */ +/* */ +/* Add two Int64 values. */ +/* */ +/* */ +/* x :: A pointer to the first value to be added. */ +/* y :: A pointer to the second value to be added. */ +/* */ +/* */ +/* z :: A pointer to the result of `x + y'. */ +/* */ +/* */ +/* Will be wrapped by the ADD_64() macro. */ +/* */ +FT_EXPORT_FUNC( void ) FT_Add64( FT_Int64 * x, + FT_Int64 * y, + FT_Int64 * z ) +{ + register FT_UInt32 lo, hi; + + + lo = x->lo + y->lo; + hi = x->hi + y->hi + ( lo < x->lo ); + + z->lo = lo; + z->hi = hi; +} + + +/*************************************************************************/ +/* */ +/* */ +/* FT_MulTo64 */ +/* */ +/* */ +/* Multiplies two Int32 integers. Returns an Int64 integer. */ +/* */ +/* */ +/* x :: The first multiplier. */ +/* y :: The second multiplier. */ +/* */ +/* */ +/* z :: A pointer to the result of `x * y'. */ +/* */ +/* */ +/* Will be wrapped by the MUL_64() macro. */ +/* */ +FT_EXPORT_FUNC( void ) FT_MulTo64( FT_Int32 x, + FT_Int32 y, + FT_Int64 * z ) +{ + FT_Int32 s; + + + s = x; x = ABS( x ); + s ^= y; y = ABS( y ); + + { + FT_UInt32 lo1, hi1, lo2, hi2, lo, hi, i1, i2; + + + lo1 = x & 0x0000FFFF; hi1 = x >> 16; + lo2 = y & 0x0000FFFF; hi2 = y >> 16; + + lo = lo1 * lo2; + i1 = lo1 * hi2; + i2 = lo2 * hi1; + hi = hi1 * hi2; + + /* Check carry overflow of i1 + i2 */ + i1 += i2; + if ( i1 < i2 ) { + hi += 1L << 16; + } + + hi += i1 >> 16; + i1 = i1 << 16; + + /* Check carry overflow of i1 + lo */ + lo += i1; + hi += ( lo < i1 ); + + z->lo = lo; + z->hi = hi; + } + + if ( s < 0 ) { + z->lo = ( FT_UInt32 ) - (FT_Int32)z->lo; + z->hi = ~z->hi + !( z->lo ); + } +} + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Div64by32 */ +/* */ +/* */ +/* Divides an Int64 value by an Int32 value. Returns an Int32 */ +/* integer. */ +/* */ +/* */ +/* x :: A pointer to the dividend. */ +/* y :: The divisor. */ +/* */ +/* */ +/* The result of `x / y'. */ +/* */ +/* */ +/* Will be wrapped by the DIV_64() macro. */ +/* */ +FT_EXPORT_FUNC( FT_Int32 ) FT_Div64by32( FT_Int64 * x, + FT_Int32 y ) +{ + FT_Int32 s; + FT_UInt32 q, r, i, lo; + + + s = x->hi; + if ( s < 0 ) { + x->lo = ( FT_UInt32 ) - (FT_Int32)x->lo; + x->hi = ~x->hi + !( x->lo ); + } + s ^= y; y = ABS( y ); + + /* Shortcut */ + if ( x->hi == 0 ) { + if ( y > 0 ) { + q = x->lo / y; + } else { + q = 0x7FFFFFFFL; + } + + return ( s < 0 ? -(FT_Int32)q : (FT_Int32)q ); + } + + r = x->hi; + lo = x->lo; + + if ( r >= (FT_UInt32)y ) { /* we know y is to be treated as unsigned here */ + return ( s < 0 ? 0x80000001UL : 0x7FFFFFFFUL ); + } + /* Return Max/Min Int32 if division overflow. */ + /* This includes division by zero! */ + q = 0; + for ( i = 0; i < 32; i++ ) + { + r <<= 1; + q <<= 1; + r |= lo >> 31; + + if ( r >= (FT_UInt32)y ) { + r -= y; + q |= 1; + } + lo <<= 1; + } + + return ( s < 0 ? -(FT_Int32)q : (FT_Int32)q ); +} + + +#ifdef FT_CONFIG_OPTION_OLD_CALCS + + +/* two helper functions for FT_Sqrt64() */ + +static +void FT_Sub64( FT_Int64* x, + FT_Int64* y, + FT_Int64* z ) { + register FT_UInt32 lo, hi; + + + lo = x->lo - y->lo; + hi = x->hi - y->hi - ( (FT_Int32)lo < 0 ); + + z->lo = lo; + z->hi = hi; +} + + +static +int ft_order64( FT_Int64* z ) { + FT_UInt32 i; + int j; + + + i = z->lo; + j = 0; + if ( z->hi ) { + i = z->hi; + j = 32; + } + + while ( i > 0 ) + { + i >>= 1; + j++; + } + return j - 1; +} + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Sqrt64 */ +/* */ +/* */ +/* Computes the square root of a 64-bits value. That sounds stupid, */ +/* but it is needed to obtain maximal accuracy in the TrueType */ +/* bytecode interpreter. */ +/* */ +/* */ +/* z :: A pointer to a 64-bit integer. */ +/* */ +/* */ +/* The 32-bit square-root. */ +/* */ +FT_EXPORT_FUNC( FT_Int32 ) FT_Sqrt64( FT_Int64 * l ) +{ + FT_Int64 l2; + FT_Int32 r, s; + + + if ( (FT_Int32)l->hi < 0 || + ( l->hi == 0 && l->lo == 0 ) ) { + return 0; + } + + s = ft_order64( l ); + if ( s == 0 ) { + return 1; + } + + r = ft_square_roots[s]; + do + { + s = r; + r = ( r + FT_Div64by32( l, r ) ) >> 1; + FT_MulTo64( r, r, &l2 ); + FT_Sub64( l, &l2, &l2 ); + + } while ( r > s || (FT_Int32)l2.hi < 0 ); + + return r; +} + +#endif /* FT_CONFIG_OPTION_OLD_CALCS */ + +#endif /* FT_LONG64 */ + + +/* END */ diff --git a/Projects/Android/jni/rtcw/src/ft2/ftcalc.h b/Projects/Android/jni/rtcw/src/ft2/ftcalc.h new file mode 100644 index 0000000..39cd451 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/ft2/ftcalc.h @@ -0,0 +1,123 @@ +/***************************************************************************/ +/* */ +/* ftcalc.h */ +/* */ +/* Arithmetic computations (specification). */ +/* */ +/* Copyright 1996-2000 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef FTCALC_H +#define FTCALC_H + +#include "freetype.h" +#include "ftconfig.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +#ifdef LONG64 + + +typedef INT64 FT_Int64; + +#define ADD_64( x, y, z ) z = ( x ) + ( y ) +#define MUL_64( x, y, z ) z = (FT_Int64)( x ) * ( y ) + +#define DIV_64( x, y ) ( ( x ) / ( y ) ) + + +#ifdef FT_CONFIG_OPTION_OLD_CALCS + +#define SQRT_64( z ) FT_Sqrt64( z ) + +FT_EXPORT_DEF( FT_Int32 ) FT_Sqrt64( FT_Int64 l ); + +#endif /* FT_CONFIG_OPTION_OLD_CALCS */ + + +#else /* LONG64 */ + + +typedef struct FT_Int64_ +{ + FT_UInt32 lo; + FT_UInt32 hi; + +} FT_Int64; + + +#define ADD_64( x, y, z ) FT_Add64( &x, &y, &z ) +#define MUL_64( x, y, z ) FT_MulTo64( x, y, &z ) +#define DIV_64( x, y ) FT_Div64by32( &x, y ) + + +FT_EXPORT_DEF( void ) FT_Add64( FT_Int64 * x, + FT_Int64 * y, + FT_Int64 * z ); + +FT_EXPORT_DEF( void ) FT_MulTo64( FT_Int32 x, + FT_Int32 y, + FT_Int64 * z ); + +FT_EXPORT_DEF( FT_Int32 ) FT_Div64by32( FT_Int64 * x, + FT_Int32 y ); + + +#ifdef FT_CONFIG_OPTION_OLD_CALCS + +#define SQRT_64( z ) FT_Sqrt64( &z ) + +FT_EXPORT_DEF( FT_Int32 ) FT_Sqrt64( FT_Int64 * x ); + +#endif /* FT_CONFIG_OPTION_OLD_CALCS */ + + +#endif /* LONG64 */ + + +#ifndef FT_CONFIG_OPTION_OLD_CALCS + +#define SQRT_32( x ) FT_Sqrt32( x ) + +BASE_DEF( FT_Int32 ) FT_Sqrt32( FT_Int32 x ); + +#endif /* !FT_CONFIG_OPTION_OLD_CALCS */ + + +/*************************************************************************/ +/* */ +/* FT_MulDiv() and FT_MulFix() are declared in freetype.h. */ +/* */ +/*************************************************************************/ + + +#define INT_TO_F26DOT6( x ) ( (FT_Long)( x ) << 6 ) +#define INT_TO_F2DOT14( x ) ( (FT_Long)( x ) << 14 ) +#define INT_TO_FIXED( x ) ( (FT_Long)( x ) << 16 ) +#define F2DOT14_TO_FIXED( x ) ( (FT_Long)( x ) << 2 ) +#define FLOAT_TO_FIXED( x ) ( (FT_Long)( x * 65536.0 ) ) + +#define ROUND_F26DOT6( x ) ( x >= 0 ? ( ( ( x ) + 32 ) & - 64 ) \ + : ( -( ( 32 - ( x ) ) & - 64 ) ) ) + + +#ifdef __cplusplus +} +#endif + +#endif /* FTCALC_H */ + + +/* END */ diff --git a/Projects/Android/jni/rtcw/src/ft2/ftconfig.h b/Projects/Android/jni/rtcw/src/ft2/ftconfig.h new file mode 100644 index 0000000..23988c7 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/ft2/ftconfig.h @@ -0,0 +1,187 @@ +/***************************************************************************/ +/* */ +/* ftconfig.h */ +/* */ +/* ANSI-specific configuration file (specification only). */ +/* */ +/* Copyright 1996-2000 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +/*************************************************************************/ +/* */ +/* This header file contains a number of macro definitions that are used */ +/* by the rest of the engine. Most of the macros here are automatically */ +/* determined at compile time, and you should not need to change it to */ +/* port FreeType, except to compile the library with a non-ANSI */ +/* compiler. */ +/* */ +/* Note however that if some specific modifications are needed, we */ +/* advise you to place a modified copy in your build directory. */ +/* */ +/* The build directory is usually `freetype/builds/', and */ +/* contains system-specific files that are always included first when */ +/* building the library. */ +/* */ +/* This ANSI version should stay in `include/freetype/config'. */ +/* */ +/*************************************************************************/ + + +#ifndef FTCONFIG_H +#define FTCONFIG_H + + +/* Include the header file containing all developer build options */ +#include "ftoption.h" + + +/*************************************************************************/ +/* */ +/* PLATFORM-SPECIFIC CONFIGURATION MACROS */ +/* */ +/* These macros can be toggled to suit a specific system. The current */ +/* ones are defaults used to compile FreeType in an ANSI C environment */ +/* (16bit compilers are also supported). Copy this file to your own */ +/* `freetype/builds/' directory, and edit it to port the engine. */ +/* */ +/*************************************************************************/ + + +/* We use values to know the sizes of the types. */ +#include + +/* The number of bytes in an `int' type. */ +#if UINT_MAX == 0xFFFFFFFF +#define FT_SIZEOF_INT 4 +#elif UINT_MAX == 0xFFFF +#define FT_SIZEOF_INT 2 +#elif UINT_MAX > 0xFFFFFFFF && UINT_MAX == 0xFFFFFFFFFFFFFFFF +#define FT_SIZEOF_INT 8 +#else +#error "Unsupported number of bytes in `int' type!" +#endif + +/* The number of bytes in a `long' type. */ +#if ULONG_MAX == 0xFFFFFFFF +#define FT_SIZEOF_LONG 4 +#elif ULONG_MAX > 0xFFFFFFFF && ULONG_MAX == 0xFFFFFFFFFFFFFFFF +#define FT_SIZEOF_LONG 8 +#else +#error "Unsupported number of bytes in `long' type!" +#endif + + +/* Preferred alignment of data */ +#define FT_ALIGNMENT 8 + + +/* UNUSED is a macro used to indicate that a given parameter is not used */ +/* -- this is only used to get rid of unpleasant compiler warnings */ +#ifndef FT_UNUSED +#define FT_UNUSED( arg ) ( ( arg ) = ( arg ) ) +#endif + + +/*************************************************************************/ +/* */ +/* AUTOMATIC CONFIGURATION MACROS */ +/* */ +/* These macros are computed from the ones defined above. Don't touch */ +/* their definition, unless you know precisely what you are doing. No */ +/* porter should need to mess with them. */ +/* */ +/*************************************************************************/ + + +/*************************************************************************/ +/* */ +/* IntN types */ +/* */ +/* Used to guarantee the size of some specific integers. */ +/* */ +typedef signed short FT_Int16; +typedef unsigned short FT_UInt16; + +#if FT_SIZEOF_INT == 4 + +typedef signed int FT_Int32; +typedef unsigned int FT_UInt32; + +#elif FT_SIZEOF_LONG == 4 + +typedef signed long FT_Int32; +typedef unsigned long FT_UInt32; + +#else +#error "no 32bit type found -- please check your configuration files" +#endif + +#if FT_SIZEOF_LONG == 8 + +/* FT_LONG64 must be defined if a 64-bit type is available */ +#define FT_LONG64 +#define FT_INT64 long + +#else + + +/*************************************************************************/ +/* */ +/* Many compilers provide the non-ANSI `long long' 64-bit type. You can */ +/* activate it by defining the FTCALC_USE_LONG_LONG macro in */ +/* `ftoption.h'. */ +/* */ +/* Note that this will produce many -ansi warnings during library */ +/* compilation, and that in many cases, the generated code will be */ +/* neither smaller nor faster! */ +/* */ +#ifdef FTCALC_USE_LONG_LONG + +#define FT_LONG64 +#define FT_INT64 long long + +#endif /* FTCALC_USE_LONG_LONG */ +#endif /* FT_SIZEOF_LONG == 8 */ + + +#ifdef FT_MAKE_OPTION_SINGLE_OBJECT +#define LOCAL_DEF static +#define LOCAL_FUNC static +#else +#define LOCAL_DEF extern +#define LOCAL_FUNC /* nothing */ +#endif + +#ifdef FT_MAKE_OPTION_SINGLE_LIBRARY_OBJECT +#define BASE_DEF( x ) static x +#define BASE_FUNC( x ) static x +#else +#define BASE_DEF( x ) extern x +#define BASE_FUNC( x ) extern x +#endif + +#ifndef FT_EXPORT_DEF +#define FT_EXPORT_DEF( x ) extern x +#endif + +#ifndef FT_EXPORT_FUNC +#define FT_EXPORT_FUNC( x ) extern x +#endif + +#ifndef FT_EXPORT_VAR +#define FT_EXPORT_VAR( x ) extern x +#endif + +#endif /* FTCONFIG_H */ + + +/* END */ diff --git a/Projects/Android/jni/rtcw/src/ft2/ftdebug.c b/Projects/Android/jni/rtcw/src/ft2/ftdebug.c new file mode 100644 index 0000000..8f99460 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/ft2/ftdebug.c @@ -0,0 +1,124 @@ +/***************************************************************************/ +/* */ +/* ftdebug.c */ +/* */ +/* Debugging and logging component (body). */ +/* */ +/* Copyright 1996-2000 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +/*************************************************************************/ +/* */ +/* This component contains various macros and functions used to ease the */ +/* debugging of the FreeType engine. Its main purpose is in assertion */ +/* checking, tracing, and error detection. */ +/* */ +/* There are now three debugging modes: */ +/* */ +/* - trace mode */ +/* */ +/* Error and trace messages are sent to the log file (which can be the */ +/* standard error output). */ +/* */ +/* - error mode */ +/* */ +/* Only error messages are generated. */ +/* */ +/* - release mode: */ +/* */ +/* No error message is sent or generated. The code is free from any */ +/* debugging parts. */ +/* */ +/*************************************************************************/ + + +#include "ftdebug.h" + +#ifdef FT_DEBUG_LEVEL_TRACE +char ft_trace_levels[trace_max]; +#endif + + +#if defined( FT_DEBUG_LEVEL_ERROR ) || defined( FT_DEBUG_LEVEL_TRACE ) + + +#include +#include +#include + + +FT_EXPORT_FUNC( void ) FT_Message( const char* fmt, ... ) +{ + va_list ap; + + + va_start( ap, fmt ); + vprintf( fmt, ap ); + va_end( ap ); +} + + +FT_EXPORT_FUNC( void ) FT_Panic( const char* fmt, ... ) +{ + va_list ap; + + + va_start( ap, fmt ); + vprintf( fmt, ap ); + va_end( ap ); + + exit( EXIT_FAILURE ); +} + + +#ifdef FT_DEBUG_LEVEL_TRACE + + +/*************************************************************************/ +/* */ +/* */ +/* FT_SetTraceLevel */ +/* */ +/* */ +/* Sets the trace level for debugging. */ +/* */ +/* */ +/* component :: The component which should be traced. See ftdebug.h */ +/* for a complete list. If set to `trace_any', all */ +/* components will be traced. */ +/* level :: The tracing level. */ +/* */ +FT_EXPORT_FUNC( void ) FT_SetTraceLevel( FT_Trace component, + char level ) +{ + if ( component >= trace_max ) { + return; + } + + /* if component is `trace_any', change _all_ levels at once */ + if ( component == trace_any ) { + int n; + + + for ( n = trace_any; n < trace_max; n++ ) + ft_trace_levels[n] = level; + } else { /* otherwise, only change individual component */ + ft_trace_levels[component] = level; + } +} + +#endif /* FT_DEBUG_LEVEL_TRACE */ + +#endif /* FT_DEBUG_LEVEL_TRACE || FT_DEBUG_LEVEL_ERROR */ + + +/* END */ diff --git a/Projects/Android/jni/rtcw/src/ft2/ftdebug.h b/Projects/Android/jni/rtcw/src/ft2/ftdebug.h new file mode 100644 index 0000000..b6e0515 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/ft2/ftdebug.h @@ -0,0 +1,225 @@ +/***************************************************************************/ +/* */ +/* ftdebug.h */ +/* */ +/* Debugging and logging component (specification). */ +/* */ +/* Copyright 1996-2000 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef FTDEBUG_H +#define FTDEBUG_H + +#include "ftconfig.h" +/* FT_DEBUG_LEVEL_ERROR */ + +#ifdef __cplusplus +extern "C" { +#endif + + +/* A very stupid pre-processor trick. See K&R version 2 */ +/* section A12.3 for details... */ +/* */ +/* It is also described in the section `Separate */ +/* Expansion of Macro Arguments' in the info file */ +/* `cpp.info', describing GNU cpp. */ +/* */ +#define FT_CAT( x, y ) x ## y +#define FT_XCAT( x, y ) FT_CAT( x, y ) + + +#ifdef FT_DEBUG_LEVEL_TRACE + + +/* note that not all levels are used currently */ + +typedef enum FT_Trace_ +{ + /* the first level must always be `trace_any' */ + trace_any = 0, + + /* base components */ + trace_aaraster, /* anti-aliasing raster (ftgrays.c) */ + trace_calc, /* calculations (ftcalc.c) */ + trace_extend, /* extension manager (ftextend.c) */ + trace_glyph, /* glyph manager (ftglyph.c) */ + trace_io, /* i/o monitoring (ftsystem.c) */ + trace_init, /* initialization (ftinit.c) */ + trace_list, /* list manager (ftlist.c) */ + trace_memory, /* memory manager (ftobjs.c) */ + trace_mm, /* MM interface (ftmm.c) */ + trace_objs, /* base objects (ftobjs.c) */ + trace_outline, /* outline management (ftoutln.c) */ + trace_raster, /* rasterizer (ftraster.c) */ + trace_stream, /* stream manager (ftstream.c) */ + + /* SFNT driver components */ + trace_sfobjs, /* SFNT object handler (sfobjs.c) */ + trace_ttcmap, /* charmap handler (ttcmap.c) */ + trace_ttload, /* basic TrueType tables (ttload.c) */ + trace_ttpost, /* PS table processing (ttpost.c) */ + trace_ttsbit, /* TrueType sbit handling (ttsbit.c) */ + + /* TrueType driver components */ + trace_ttdriver, /* TT font driver (ttdriver.c) */ + trace_ttgload, /* TT glyph loader (ttgload.c) */ + trace_ttinterp, /* bytecode interpreter (ttinterp.c) */ + trace_ttobjs, /* TT objects manager (ttobjs.c) */ + trace_ttpload, /* TT data/program loader (ttpload.c) */ + + /* Type 1 driver components */ + trace_t1driver, + trace_t1gload, + trace_t1hint, + trace_t1load, + trace_t1objs, + + /* experimental Type 1 driver components */ + trace_z1driver, + trace_z1gload, + trace_z1hint, + trace_z1load, + trace_z1objs, + trace_z1parse, + + /* Type 2 driver components */ + trace_t2driver, + trace_t2gload, + trace_t2load, + trace_t2objs, + trace_t2parse, + + /* CID driver components */ + trace_cidafm, + trace_ciddriver, + trace_cidgload, + trace_cidload, + trace_cidobjs, + trace_cidparse, + + /* Windows fonts component */ + trace_winfnt, + + /* the last level must always be `trace_max' */ + trace_max + +} FT_Trace; + + +/* declared in ftdebug.c */ +extern char ft_trace_levels[trace_max]; + + +/*************************************************************************/ +/* */ +/* IMPORTANT! */ +/* */ +/* Each component must define the macro FT_COMPONENT to a valid FT_Trace */ +/* value before using any TRACE macro. */ +/* */ +/*************************************************************************/ + + +#define FT_TRACE( level, varformat ) \ + do \ + { \ + if ( ft_trace_levels[FT_COMPONENT] >= level ) { \ + FT_XCAT( FT_Message, varformat );} \ + } while ( 0 ) + + +FT_EXPORT_DEF( void ) FT_SetTraceLevel( FT_Trace component, + char level ); + + +#elif defined( FT_DEBUG_LEVEL_ERROR ) + + +#define FT_TRACE( level, varformat ) do ;while ( 0 ) /* nothing */ + + +#else /* release mode */ + + +#define FT_Assert( condition ) do ;while ( 0 ) /* nothing */ + +#define FT_TRACE( level, varformat ) do ;while ( 0 ) /* nothing */ +#define FT_ERROR( varformat ) do ;while ( 0 ) /* nothing */ + + +#endif /* FT_DEBUG_LEVEL_TRACE, FT_DEBUG_LEVEL_ERROR */ + + +/*************************************************************************/ +/* */ +/* Define macros and functions that are common to the debug and trace */ +/* modes. */ +/* */ +/* You need vprintf() to be able to compile ftdebug.c. */ +/* */ +/*************************************************************************/ + + +#if defined( FT_DEBUG_LEVEL_TRACE ) || defined( FT_DEBUG_LEVEL_ERROR ) + + +#include "stdio.h" /* for vprintf() */ + + +#define FT_Assert( condition ) \ + do \ + { \ + if ( !( condition ) ) { \ + FT_Panic( "assertion failed on line %d of file %s\n", \ + __LINE__, __FILE__ );} \ + } while ( 0 ) + +/* print a message */ +FT_EXPORT_DEF( void ) FT_Message( const char* fmt, ... ); + +/* print a message and exit */ +FT_EXPORT_DEF( void ) FT_Panic( const char* fmt, ... ); + +#define FT_ERROR( varformat ) FT_XCAT( FT_Message, varformat ) + + +#endif /* FT_DEBUG_LEVEL_TRACE || FT_DEBUG_LEVEL_ERROR */ + + +/*************************************************************************/ +/* */ +/* You need two opening resp. closing parentheses! */ +/* */ +/* Example: FT_TRACE0(( "Value is %i", foo )) */ +/* */ +/*************************************************************************/ + +#define FT_TRACE0( varformat ) FT_TRACE( 0, varformat ) +#define FT_TRACE1( varformat ) FT_TRACE( 1, varformat ) +#define FT_TRACE2( varformat ) FT_TRACE( 2, varformat ) +#define FT_TRACE3( varformat ) FT_TRACE( 3, varformat ) +#define FT_TRACE4( varformat ) FT_TRACE( 4, varformat ) +#define FT_TRACE5( varformat ) FT_TRACE( 5, varformat ) +#define FT_TRACE6( varformat ) FT_TRACE( 6, varformat ) +#define FT_TRACE7( varformat ) FT_TRACE( 7, varformat ) + + +#ifdef __cplusplus +} +#endif + + +#endif /* FTDEBUG_H */ + + +/* END */ diff --git a/Projects/Android/jni/rtcw/src/ft2/ftdriver.h b/Projects/Android/jni/rtcw/src/ft2/ftdriver.h new file mode 100644 index 0000000..45f04e5 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/ft2/ftdriver.h @@ -0,0 +1,182 @@ +/***************************************************************************/ +/* */ +/* ftdriver.h */ +/* */ +/* FreeType font driver interface (specification). */ +/* */ +/* Copyright 1996-2000 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef FTDRIVER_H +#define FTDRIVER_H + + +#include "ftmodule.h" +#include "ftconfig.h" /* for FT_DEBUG_LEVEL_TRACE, */ + + +typedef FT_Error ( *FTDriver_initFace )( FT_Stream stream, + FT_Face face, + FT_Int typeface_index, + FT_Int num_params, + FT_Parameter* parameters ); + +typedef void ( *FTDriver_doneFace )( FT_Face face ); + + +typedef FT_Error ( *FTDriver_initSize )( FT_Size size ); + +typedef void ( *FTDriver_doneSize )( FT_Size size ); + + +typedef FT_Error ( *FTDriver_initGlyphSlot )( FT_GlyphSlot slot ); + +typedef void ( *FTDriver_doneGlyphSlot )( FT_GlyphSlot slot ); + + +typedef FT_Error ( *FTDriver_setCharSizes )( FT_Size size, + FT_F26Dot6 char_width, + FT_F26Dot6 char_height, + FT_UInt horz_resolution, + FT_UInt vert_resolution ); + +typedef FT_Error ( *FTDriver_setPixelSizes )( FT_Size size, + FT_UInt pixel_width, + FT_UInt pixel_height ); + +typedef FT_Error ( *FTDriver_loadGlyph )( FT_GlyphSlot slot, + FT_Size size, + FT_UInt glyph_index, + FT_Int load_flags ); + + +typedef FT_UInt ( *FTDriver_getCharIndex )( FT_CharMap charmap, + FT_Long charcode ); + +typedef FT_Error ( *FTDriver_getKerning )( FT_Face face, + FT_UInt left_glyph, + FT_UInt right_glyph, + FT_Vector* kerning ); + + +typedef FT_Error ( *FTDriver_attachFile )( FT_Face face, + FT_Stream stream ); + + +typedef FT_Error ( *FTDriver_getAdvances )( FT_Face face, + FT_UInt first, + FT_UInt count, + FT_Bool vertical, + FT_UShort* advances ); + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Driver_Class */ +/* */ +/* */ +/* The font driver class. This structure mostly contains pointers to */ +/* driver methods. */ +/* */ +/* */ +/* root :: The parent module. */ +/* */ +/* face_object_size :: The size of a face object in bytes. */ +/* */ +/* size_object_size :: The size of a size object in bytes. */ +/* */ +/* slot_object_size :: The size of a glyph object in bytes. */ +/* */ +/* init_face :: The format-specific face constructor. */ +/* */ +/* done_face :: The format-specific face destructor. */ +/* */ +/* init_size :: The format-specific size constructor. */ +/* */ +/* done_size :: The format-specific size destructor. */ +/* */ +/* init_slot :: The format-specific slot constructor. */ +/* */ +/* done_slot :: The format-specific slot destructor. */ +/* */ +/* set_char_sizes :: A handle to a function used to set the new */ +/* character size in points + resolution. Can be */ +/* set to 0 to indicate default behaviour. */ +/* */ +/* set_pixel_sizes :: A handle to a function used to set the new */ +/* character size in pixels. Can be set to 0 to */ +/* indicate default behaviour. */ +/* */ +/* load_glyph :: A function handle to load a given glyph image */ +/* in a slot. This field is mandatory! */ +/* */ +/* get_char_index :: A function handle to return the glyph index of */ +/* a given character for a given charmap. This */ +/* field is mandatory! */ +/* */ +/* get_kerning :: A function handle to return the unscaled */ +/* kerning for a given pair of glyphs. Can be */ +/* set to 0 if the format doesn't support */ +/* kerning. */ +/* */ +/* attach_file :: This function handle is used to read */ +/* additional data for a face from another */ +/* file/stream. For example, this can be used to */ +/* add data from AFM or PFM files on a Type 1 */ +/* face, or a CIDMap on a CID-keyed face. */ +/* */ +/* get_advances :: A function handle used to return the advances */ +/* of 'count' glyphs, starting at `index'. the */ +/* `vertical' flags must be set when vertical */ +/* advances are queried. The advances buffer is */ +/* caller-allocated. */ +/* */ +/* */ +/* Most function pointers, with the exception of `load_glyph' and */ +/* `get_char_index' can be set to 0 to indicate a default behaviour. */ +/* */ +typedef struct FT_Driver_Class_ +{ + FT_Module_Class root; + + FT_Int face_object_size; + FT_Int size_object_size; + FT_Int slot_object_size; + + FTDriver_initFace init_face; + FTDriver_doneFace done_face; + + FTDriver_initSize init_size; + FTDriver_doneSize done_size; + + FTDriver_initGlyphSlot init_slot; + FTDriver_doneGlyphSlot done_slot; + + FTDriver_setCharSizes set_char_sizes; + FTDriver_setPixelSizes set_pixel_sizes; + + FTDriver_loadGlyph load_glyph; + FTDriver_getCharIndex get_char_index; + + FTDriver_getKerning get_kerning; + FTDriver_attachFile attach_file; + + FTDriver_getAdvances get_advances; + +} FT_Driver_Class; + + +#endif /* FTDRIVER_H */ + + +/* END */ diff --git a/Projects/Android/jni/rtcw/src/ft2/fterrors.h b/Projects/Android/jni/rtcw/src/ft2/fterrors.h new file mode 100644 index 0000000..e5f5882 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/ft2/fterrors.h @@ -0,0 +1,166 @@ +/***************************************************************************/ +/* */ +/* fterrors.h */ +/* */ +/* FreeType error codes (specification). */ +/* */ +/* Copyright 1996-2000 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +/*************************************************************************/ +/* */ +/* This file is used to define the FreeType error enumeration constants */ +/* It can also be used to create an error message table easily with */ +/* something like: */ +/* */ +/* { */ +/* #undef FTERRORS_H */ +/* #define FT_ERRORDEF( e, v, s ) { e, s }, */ +/* #define FT_ERROR_START_LIST { */ +/* #define FT_ERROR_END_LIST { 0, 0 } }; */ +/* */ +/* const struct */ +/* { */ +/* int err_code; */ +/* const char* err_msg */ +/* } ft_errors[] = */ +/* */ +/* #include */ +/* } */ +/* */ +/*************************************************************************/ + + +#ifndef FTERRORS_H +#define FTERRORS_H + + +#ifndef FT_ERRORDEF + +#define FT_ERRORDEF( e, v, s ) e = v, +#define FT_ERROR_START_LIST enum { +#define FT_ERROR_END_LIST FT_Err_Max }; + +#endif /* !FT_ERRORDEF */ + + +#ifdef FT_ERROR_START_LIST +FT_ERROR_START_LIST +#endif + +FT_ERRORDEF( FT_Err_Ok, 0x0000, \ + "no error" ) +FT_ERRORDEF( FT_Err_Cannot_Open_Resource, 0x0001, \ + "can't open stream" ) +FT_ERRORDEF( FT_Err_Unknown_File_Format, 0x0002, \ + "unknown file format" ) +FT_ERRORDEF( FT_Err_Invalid_File_Format, 0x0003, \ + "broken file" ) + +FT_ERRORDEF( FT_Err_Invalid_Argument, 0x0010, \ + "invalid argument" ) +FT_ERRORDEF( FT_Err_Invalid_Handle, 0x0011, \ + "invalid object handle" ) +FT_ERRORDEF( FT_Err_Invalid_Glyph_Index, 0x0012, \ + "invalid glyph index" ) +FT_ERRORDEF( FT_Err_Invalid_Character_Code, 0x0013, \ + "invalid character code" ) + +FT_ERRORDEF( FT_Err_Unimplemented_Feature, 0x0020, \ + "unimplemented feature" ) +FT_ERRORDEF( FT_Err_Invalid_Glyph_Format, 0x0021, \ + "unsupported glyph image format" ) +FT_ERRORDEF( FT_Err_Cannot_Render_Glyph, 0x0022, \ + "cannot render this glyph format" ) + +FT_ERRORDEF( FT_Err_Invalid_Library_Handle, 0x0030, \ + "invalid library handle" ) +FT_ERRORDEF( FT_Err_Invalid_Driver_Handle, 0x0031, \ + "invalid module handle" ) +FT_ERRORDEF( FT_Err_Invalid_Face_Handle, 0x0032, \ + "invalid face handle" ) +FT_ERRORDEF( FT_Err_Invalid_Size_Handle, 0x0033, \ + "invalid size handle" ) +FT_ERRORDEF( FT_Err_Invalid_Slot_Handle, 0x0034, \ + "invalid glyph slot handle" ) +FT_ERRORDEF( FT_Err_Invalid_CharMap_Handle, 0x0035, \ + "invalid charmap handle" ) +FT_ERRORDEF( FT_Err_Invalid_Outline, 0x0036, \ + "invalid outline" ) +FT_ERRORDEF( FT_Err_Invalid_Version, 0x0037, \ + "invalid FreeType version" ) +FT_ERRORDEF( FT_Err_Lower_Module_Version, 0x0038, \ + "module version is too low" ) + +FT_ERRORDEF( FT_Err_Too_Many_Drivers, 0x0040, \ + "too many modules" ) +FT_ERRORDEF( FT_Err_Too_Many_Extensions, 0x0041, \ + "too many extensions" ) + +FT_ERRORDEF( FT_Err_Out_Of_Memory, 0x0050, \ + "out of memory" ) +FT_ERRORDEF( FT_Err_Unlisted_Object, 0x0051, \ + "unlisted object" ) + +FT_ERRORDEF( FT_Err_Invalid_Stream_Handle, 0x0060, \ + "invalid stream handle" ) +FT_ERRORDEF( FT_Err_Cannot_Open_Stream, 0x0061, \ + "cannot open stream" ) +FT_ERRORDEF( FT_Err_Invalid_Stream_Seek, 0x0062, \ + "invalid stream seek" ) +FT_ERRORDEF( FT_Err_Invalid_Stream_Skip, 0x0063, \ + "invalid stream skip" ) +FT_ERRORDEF( FT_Err_Invalid_Stream_Read, 0x0064, \ + "invalid stream read" ) +FT_ERRORDEF( FT_Err_Invalid_Stream_Operation, 0x0065, \ + "invalid stream operation" ) +FT_ERRORDEF( FT_Err_Invalid_Frame_Operation, 0x0066, \ + "invalid frame operation" ) +FT_ERRORDEF( FT_Err_Nested_Frame_Access, 0x0067, \ + "nested frame access" ) +FT_ERRORDEF( FT_Err_Invalid_Frame_Read, 0x0068, \ + "invalid frame read" ) + +FT_ERRORDEF( FT_Err_Invalid_Composite, 0x0070, \ + "invalid composite glyph" ) +FT_ERRORDEF( FT_Err_Too_Many_Hints, 0x0071, \ + "too many hints" ) + +FT_ERRORDEF( FT_Err_Raster_Uninitialized, 0x0080, \ + "raster uninitialized" ) +FT_ERRORDEF( FT_Err_Raster_Corrupted, 0x0081, \ + "raster corrupted" ) +FT_ERRORDEF( FT_Err_Raster_Overflow, 0x0082, \ + "raster overflow" ) +FT_ERRORDEF( FT_Err_Raster_Negative_Height, 0x0083, \ + "negative height while rastering" ) + +/* range 0x400 - 0x4FF is reserved for TrueType specific stuff */ + +/* range 0x500 - 0x5FF is reserved for CFF specific stuff */ + +/* range 0x600 - 0x6FF is reserved for Type1 specific stuff */ + +#ifdef FT_ERROR_END_LIST +FT_ERROR_END_LIST +#endif + + +#undef FT_ERROR_START_LIST +#undef FT_ERROR_END_LIST +#undef FT_ERRORDEF + + +#endif /* FTERRORS_H */ + + +/* END */ diff --git a/Projects/Android/jni/rtcw/src/ft2/ftextend.c b/Projects/Android/jni/rtcw/src/ft2/ftextend.c new file mode 100644 index 0000000..cb812ab --- /dev/null +++ b/Projects/Android/jni/rtcw/src/ft2/ftextend.c @@ -0,0 +1,332 @@ +/***************************************************************************/ +/* */ +/* ftextend.h */ +/* */ +/* FreeType extensions implementation (body). */ +/* */ +/* Copyright 1996-2000 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + +/*************************************************************************/ +/* */ +/* This is an updated version of the extension component, now located */ +/* in the main library's source directory. It allows the dynamic */ +/* registration/use of various face object extensions through a simple */ +/* API. */ +/* */ +/*************************************************************************/ + + +#include "ftextend.h" +#include "ftdebug.h" + + +/*************************************************************************/ +/* */ +/* The macro FT_COMPONENT is used in trace mode. It is an implicit */ +/* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */ +/* messages during execution. */ +/* */ +#undef FT_COMPONENT +#define FT_COMPONENT trace_extend + + +typedef struct FT_Extension_Registry_ +{ + FT_Int num_extensions; + FT_Long cur_offset; + FT_Extension_Class classes[FT_MAX_EXTENSIONS]; + +} FT_Extension_Registry; + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Init_Extensions */ +/* */ +/* */ +/* Initializes the extension component. */ +/* */ +/* */ +/* driver :: A handle to the driver object. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +LOCAL_FUNC +FT_Error FT_Init_Extensions( FT_Driver driver ) { + FT_Error error; + FT_Memory memory; + FT_Extension_Registry* registry; + + + memory = driver->root.library->memory; + if ( ALLOC( registry, sizeof( *registry ) ) ) { + return error; + } + + registry->num_extensions = 0; + registry->cur_offset = 0; + driver->extensions = registry; + + FT_TRACE2( ( "FT_Init_Extensions: success\n" ) ); + + return FT_Err_Ok; +} + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Done_Extensions */ +/* */ +/* */ +/* Finalizes the extension component. */ +/* */ +/* */ +/* driver :: A handle to the driver object. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +LOCAL_FUNC +FT_Error FT_Done_Extensions( FT_Driver driver ) { + FT_Memory memory = driver->root.memory; + + + FREE( driver->extensions ); + return FT_Err_Ok; +} + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Register_Extension */ +/* */ +/* */ +/* Registers a new extension. */ +/* */ +/* */ +/* driver :: A handle to the driver object. */ +/* class :: A pointer to a class describing the extension. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +FT_EXPORT_FUNC( FT_Error ) FT_Register_Extension( + FT_Driver driver, + FT_Extension_Class * clazz ) +{ + FT_Extension_Registry* registry; + + + if ( !driver ) { + return FT_Err_Invalid_Driver_Handle; + } + + if ( !clazz ) { + return FT_Err_Invalid_Argument; + } + + registry = (FT_Extension_Registry*)driver->extensions; + if ( registry ) { + FT_Int n = registry->num_extensions; + FT_Extension_Class* cur = registry->classes + n; + + + if ( n >= FT_MAX_EXTENSIONS ) { + return FT_Err_Too_Many_Extensions; + } + + *cur = *clazz; + + cur->offset = registry->cur_offset; + + registry->num_extensions++; + registry->cur_offset += + ( cur->size + FT_ALIGNMENT - 1 ) & - FT_ALIGNMENT; + + FT_TRACE1( ( "FT_Register_Extension: `%s' successfully registered\n", + cur->id ) ); + } + + return FT_Err_Ok; +} + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Get_Extension */ +/* */ +/* */ +/* Queries an extension block by an extension ID string. */ +/* */ +/* */ +/* face :: A handle to the face object. */ +/* extension_id :: An ID string identifying the extension. */ +/* */ +/* */ +/* extension_interface :: A generic pointer, usually pointing to a */ +/* table of functions implementing the */ +/* extension interface. */ +/* */ +/* */ +/* A generic pointer to the extension block. */ +/* */ +FT_EXPORT_FUNC( void* ) FT_Get_Extension( + FT_Face face, + const char* extension_id, + void** extension_interface ) +{ + FT_Extension_Registry* registry; + + + if ( !face || !extension_id || !extension_interface ) { + return 0; + } + + registry = (FT_Extension_Registry*)face->driver->extensions; + if ( registry && face->extensions ) { + FT_Extension_Class* cur = registry->classes; + FT_Extension_Class* limit = cur + registry->num_extensions; + + + for ( ; cur < limit; cur++ ) + if ( strcmp( cur->id, extension_id ) == 0 ) { + *extension_interface = cur->interface; + + FT_TRACE1( ( "FT_Get_Extension: got `%s'\n", extension_id ) ); + + return ( void* )( (char*)face->extensions + cur->offset ); + } + } + + /* could not find the extension id */ + + FT_ERROR( ( "FT_Get_Extension: couldn't find `%s'\n", extension_id ) ); + + *extension_interface = 0; + + return 0; +} + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Destroy_Extensions */ +/* */ +/* */ +/* Destroys all extensions within a face object. */ +/* */ +/* */ +/* face :: A handle to the face object. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +/* */ +/* Called by the face object destructor. */ +/* */ +LOCAL_FUNC +FT_Error FT_Destroy_Extensions( FT_Face face ) { + FT_Extension_Registry* registry; + FT_Memory memory; + + + registry = (FT_Extension_Registry*)face->driver->extensions; + if ( registry && face->extensions ) { + FT_Extension_Class* cur = registry->classes; + FT_Extension_Class* limit = cur + registry->num_extensions; + + + for ( ; cur < limit; cur++ ) + { + char* ext = (char*)face->extensions + cur->offset; + + if ( cur->finalize ) { + cur->finalize( ext, face ); + } + } + + memory = face->driver->root.memory; + FREE( face->extensions ); + } + + return FT_Err_Ok; +} + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Create_Extensions */ +/* */ +/* */ +/* Creates an extension object within a face object for all */ +/* registered extensions. */ +/* */ +/* */ +/* face :: A handle to the face object. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +/* */ +/* Called by the face object constructor. */ +/* */ +LOCAL_FUNC +FT_Error FT_Create_Extensions( FT_Face face ) { + FT_Extension_Registry* registry; + FT_Memory memory; + FT_Error error; + + + face->extensions = 0; + + /* load extensions registry; exit successfully if none is there */ + + registry = (FT_Extension_Registry*)face->driver->extensions; + if ( !registry ) { + return FT_Err_Ok; + } + + memory = face->driver->root.memory; + if ( ALLOC( face->extensions, registry->cur_offset ) ) { + return error; + } + + { + FT_Extension_Class* cur = registry->classes; + FT_Extension_Class* limit = cur + registry->num_extensions; + + + for ( ; cur < limit; cur++ ) + { + char* ext = (char*)face->extensions + cur->offset; + + if ( cur->init ) { + error = cur->init( ext, face ); + if ( error ) { + break; + } + } + } + } + + return error; +} + + +/* END */ diff --git a/Projects/Android/jni/rtcw/src/ft2/ftextend.h b/Projects/Android/jni/rtcw/src/ft2/ftextend.h new file mode 100644 index 0000000..ee16df3 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/ft2/ftextend.h @@ -0,0 +1,178 @@ +/***************************************************************************/ +/* */ +/* ftextend.h */ +/* */ +/* FreeType extensions implementation (specification). */ +/* */ +/* Copyright 1996-2000 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef FTEXTEND_H +#define FTEXTEND_H + + +#include "ftobjs.h" + + +#ifdef __cplusplus +extern "C" { +#endif + + +/*************************************************************************/ +/* */ +/* The extensions don't need to be integrated at compile time into the */ +/* engine, only at link time. */ +/* */ +/*************************************************************************/ + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Extension_Initializer */ +/* */ +/* */ +/* Each new face object can have several extensions associated with */ +/* it at creation time. This function is used to initialize given */ +/* extension data for a given face. */ +/* */ +/* */ +/* ext :: A typeless pointer to the extension data. */ +/* */ +/* face :: A handle to the source face object the extension is */ +/* associated with. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +/* */ +/* In case of error, the initializer should not destroy the extension */ +/* data, as the finalizer will get called later by the function's */ +/* caller. */ +/* */ +typedef FT_Error ( *FT_Extension_Initializer )( void* ext, + FT_Face face ); + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Extension_Finalizer */ +/* */ +/* */ +/* Each new face object can have several extensions associated with */ +/* it at creation time. This function is used to finalize given */ +/* extension data for a given face; it occurs before the face object */ +/* itself is finalized. */ +/* */ +/* */ +/* ext :: A typeless pointer to the extension data. */ +/* */ +/* face :: A handle to the source face object the extension is */ +/* associated with. */ +/* */ +typedef void ( *FT_Extension_Finalizer )( void* ext, + FT_Face face ); + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Extension_Class */ +/* */ +/* */ +/* A simple structure used to describe a given extension to the */ +/* FreeType base layer. An FT_Extension_Class is used as a parameter */ +/* for FT_Register_Extension(). */ +/* */ +/* */ +/* id :: The extension's ID. This is a normal C string that */ +/* is used to uniquely reference the extension's */ +/* interface. */ +/* */ +/* size :: The size in bytes of the extension data that must be */ +/* associated with each face object. */ +/* */ +/* init :: A pointer to the extension data's initializer. */ +/* */ +/* finalize :: A pointer to the extension data's finalizer. */ +/* */ +/* interface :: This pointer can be anything, but should usually */ +/* point to a table of function pointers which implement */ +/* the extension's interface. */ +/* */ +/* offset :: This field is set and used within the base layer and */ +/* should be set to 0 when registering an extension */ +/* through FT_Register_Extension(). It contains an */ +/* offset within the face's extension block for the */ +/* current extension's data. */ +/* */ +typedef struct FT_Extension_Class_ +{ + const char* id; + FT_ULong size; + FT_Extension_Initializer init; + FT_Extension_Finalizer finalize; + void* interface; + + FT_ULong offset; + +} FT_Extension_Class; + + +FT_EXPORT_DEF( FT_Error ) FT_Register_Extension( + FT_Driver driver, + FT_Extension_Class * clazz ); + + +#ifdef FT_CONFIG_OPTION_EXTEND_ENGINE + + +/* Initialize the extension component */ +LOCAL_DEF +FT_Error FT_Init_Extensions( FT_Library library ); + +/* Finalize the extension component */ +LOCAL_DEF +FT_Error FT_Done_Extensions( FT_Library library ); + +/* Create an extension within a face object. Called by the */ +/* face object constructor. */ +LOCAL_DEF +FT_Error FT_Create_Extensions( FT_Face face ); + +/* Destroy all extensions within a face object. Called by the */ +/* face object destructor. */ +LOCAL_DEF +FT_Error FT_Destroy_Extensions( FT_Face face ); + + +#endif + + +/* return an extension's data & interface according to its ID */ +FT_EXPORT_DEF( void* ) FT_Get_Extension( + FT_Face face, + const char* extension_id, + void** extension_interface ); + + +#ifdef __cplusplus +} +#endif + + +#endif /* FTEXTEND_H */ + + +/* END */ diff --git a/Projects/Android/jni/rtcw/src/ft2/ftglyph.c b/Projects/Android/jni/rtcw/src/ft2/ftglyph.c new file mode 100644 index 0000000..75b2bbd --- /dev/null +++ b/Projects/Android/jni/rtcw/src/ft2/ftglyph.c @@ -0,0 +1,1185 @@ +/***************************************************************************/ +/* */ +/* ftglyph.c */ +/* */ +/* FreeType convenience functions to handle glyphs (body). */ +/* */ +/* Copyright 1996-2000 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + +/*************************************************************************/ +/* */ +/* This file contains the definition of several convenience functions */ +/* that can be used by client applications to easily retrieve glyph */ +/* bitmaps and outlines from a given face. */ +/* */ +/* These functions should be optional if you are writing a font server */ +/* or text layout engine on top of FreeType. However, they are pretty */ +/* handy for many other simple uses of the library. */ +/* */ +/*************************************************************************/ + + +#include "ftglyph.h" +#include "ftoutln.h" +#include "ftobjs.h" + + +/*************************************************************************/ +/* */ +/* The macro FT_COMPONENT is used in trace mode. It is an implicit */ +/* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */ +/* messages during execution. */ +/* */ +#undef FT_COMPONENT +#define FT_COMPONENT trace_glyph + + +/*************************************************************************/ +/*************************************************************************/ +/**** ****/ +/**** Convenience functions ****/ +/**** ****/ +/*************************************************************************/ +/*************************************************************************/ + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Matrix_Multiply */ +/* */ +/* */ +/* Performs the matrix operation `b = a*b'. */ +/* */ +/* */ +/* a :: A pointer to matrix `a'. */ +/* */ +/* */ +/* b :: A pointer to matrix `b'. */ +/* */ +/* */ +/* Yes. */ +/* */ +/* */ +/* The result is undefined if either `a' or `b' is zero. */ +/* */ +FT_EXPORT_FUNC( void ) FT_Matrix_Multiply( FT_Matrix * a, + FT_Matrix * b ) +{ + FT_Fixed xx, xy, yx, yy; + + + if ( !a || !b ) { + return; + } + + xx = FT_MulFix( a->xx, b->xx ) + FT_MulFix( a->xy, b->yx ); + xy = FT_MulFix( a->xx, b->xy ) + FT_MulFix( a->xy, b->yy ); + yx = FT_MulFix( a->yx, b->xx ) + FT_MulFix( a->yy, b->yx ); + yy = FT_MulFix( a->yx, b->xy ) + FT_MulFix( a->yy, b->yy ); + + b->xx = xx; b->xy = xy; + b->yx = yx; b->yy = yy; +} + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Matrix_Invert */ +/* */ +/* */ +/* Inverts a 2x2 matrix. Returns an error if it can't be inverted. */ +/* */ +/* */ +/* matrix :: A pointer to the target matrix. Remains untouched in */ +/* case of error. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +/* */ +/* Yes. */ +/* */ +FT_EXPORT_FUNC( FT_Error ) FT_Matrix_Invert( FT_Matrix * matrix ) +{ + FT_Pos delta, xx, yy; + + + if ( !matrix ) { + return FT_Err_Invalid_Argument; + } + + /* compute discriminant */ + delta = FT_MulFix( matrix->xx, matrix->yy ) - + FT_MulFix( matrix->xy, matrix->yx ); + + if ( !delta ) { + return FT_Err_Invalid_Argument; /* matrix can't be inverted */ + + } + matrix->xy = -FT_DivFix( matrix->xy, delta ); + matrix->yx = -FT_DivFix( matrix->yx, delta ); + + xx = matrix->xx; + yy = matrix->yy; + + matrix->xx = FT_DivFix( yy, delta ); + matrix->yy = FT_DivFix( xx, delta ); + + return FT_Err_Ok; +} + + +/*************************************************************************/ +/*************************************************************************/ +/**** ****/ +/**** FT_BitmapGlyph support ****/ +/**** ****/ +/*************************************************************************/ +/*************************************************************************/ + +static +FT_Error ft_bitmap_copy( FT_Memory memory, + FT_Bitmap* source, + FT_Bitmap* target ) { + FT_Error error; + FT_Int pitch = source->pitch; + FT_ULong size; + + + *target = *source; + + if ( pitch < 0 ) { + pitch = -pitch; + } + + size = (FT_ULong)( pitch * source->rows ); + + if ( !ALLOC( target->buffer, size ) ) { + MEM_Copy( source->buffer, target->buffer, size ); + } + + return error; +} + + +static +FT_Error ft_bitmap_glyph_init( FT_BitmapGlyph glyph, + FT_GlyphSlot slot ) { + FT_Error error = FT_Err_Ok; + FT_Library library = FT_GLYPH( glyph )->library; + FT_Memory memory = library->memory; + + + if ( slot->format != ft_glyph_format_bitmap ) { + error = FT_Err_Invalid_Glyph_Format; + goto Exit; + } + + /* grab the bitmap in the slot - do lazy copying whenever possible */ + glyph->bitmap = slot->bitmap; + glyph->left = slot->bitmap_left; + glyph->top = slot->bitmap_top; + + if ( slot->flags & ft_glyph_own_bitmap ) { + slot->flags &= ~ft_glyph_own_bitmap; + } else + { + /* copy the bitmap into a new buffer */ + error = ft_bitmap_copy( memory, &slot->bitmap, &glyph->bitmap ); + } + +Exit: + return error; +} + + +static +FT_Error ft_bitmap_glyph_copy( FT_BitmapGlyph source, + FT_BitmapGlyph target ) { + FT_Memory memory = source->root.library->memory; + + + target->left = source->left; + target->top = source->top; + + return ft_bitmap_copy( memory, &source->bitmap, &target->bitmap ); +} + + +static +void ft_bitmap_glyph_done( FT_BitmapGlyph glyph ) { + FT_Memory memory = FT_GLYPH( glyph )->library->memory; + + + FREE( glyph->bitmap.buffer ); +} + + +static +void ft_bitmap_glyph_bbox( FT_BitmapGlyph glyph, + FT_BBox* cbox ) { + cbox->xMin = glyph->left << 6; + cbox->xMax = cbox->xMin + ( glyph->bitmap.width << 6 ); + cbox->yMax = glyph->top << 6; + cbox->yMin = cbox->xMax - ( glyph->bitmap.rows << 6 ); +} + + +const FT_Glyph_Class ft_bitmap_glyph_class = +{ + sizeof( FT_BitmapGlyphRec ), + ft_glyph_format_bitmap, + + (FT_Glyph_Init_Func) ft_bitmap_glyph_init, + (FT_Glyph_Done_Func) ft_bitmap_glyph_done, + (FT_Glyph_Copy_Func) ft_bitmap_glyph_copy, + (FT_Glyph_Transform_Func)0, + (FT_Glyph_BBox_Func) ft_bitmap_glyph_bbox, + (FT_Glyph_Prepare_Func) 0 +}; + + +/*************************************************************************/ +/*************************************************************************/ +/**** ****/ +/**** FT_OutlineGlyph support ****/ +/**** ****/ +/*************************************************************************/ +/*************************************************************************/ + + +static +FT_Error ft_outline_glyph_init( FT_OutlineGlyph glyph, + FT_GlyphSlot slot ) { + FT_Error error = FT_Err_Ok; + FT_Library library = FT_GLYPH( glyph )->library; + FT_Outline* source = &slot->outline; + FT_Outline* target = &glyph->outline; + + + /* check format in glyph slot */ + if ( slot->format != ft_glyph_format_outline ) { + error = FT_Err_Invalid_Glyph_Format; + goto Exit; + } + + /* allocate new outline */ + error = FT_Outline_New( library, source->n_points, source->n_contours, + &glyph->outline ); + if ( error ) { + goto Exit; + } + + /* copy it */ + MEM_Copy( target->points, source->points, + source->n_points * sizeof( FT_Vector ) ); + + MEM_Copy( target->tags, source->tags, + source->n_points * sizeof( FT_Byte ) ); + + MEM_Copy( target->contours, source->contours, + source->n_contours * sizeof( FT_Short ) ); + + /* copy all flags, except the `ft_outline_owner' one */ + target->flags = source->flags | ft_outline_owner; + +Exit: + return error; +} + + +static +void ft_outline_glyph_done( FT_OutlineGlyph glyph ) { + FT_Outline_Done( FT_GLYPH( glyph )->library, &glyph->outline ); +} + + +static +FT_Error ft_outline_glyph_copy( FT_OutlineGlyph source, + FT_OutlineGlyph target ) { + FT_Error error; + FT_Library library = FT_GLYPH( source )->library; + + + error = FT_Outline_New( library, source->outline.n_points, + source->outline.n_contours, &target->outline ); + if ( !error ) { + FT_Outline_Copy( &source->outline, &target->outline ); + } + + return error; +} + + +static +void ft_outline_glyph_transform( FT_OutlineGlyph glyph, + FT_Matrix* matrix, + FT_Vector* delta ) { + if ( matrix ) { + FT_Outline_Transform( &glyph->outline, matrix ); + } + + if ( delta ) { + FT_Outline_Translate( &glyph->outline, delta->x, delta->y ); + } +} + + +static +void ft_outline_glyph_bbox( FT_OutlineGlyph glyph, + FT_BBox* bbox ) { + FT_Outline_Get_CBox( &glyph->outline, bbox ); +} + + +static +FT_Error ft_outline_glyph_prepare( FT_OutlineGlyph glyph, + FT_GlyphSlot slot ) { + slot->format = ft_glyph_format_outline; + slot->outline = glyph->outline; + slot->outline.flags &= ~ft_outline_owner; + + return FT_Err_Ok; +} + + +const FT_Glyph_Class ft_outline_glyph_class = +{ + sizeof( FT_OutlineGlyphRec ), + ft_glyph_format_outline, + + (FT_Glyph_Init_Func) ft_outline_glyph_init, + (FT_Glyph_Done_Func) ft_outline_glyph_done, + (FT_Glyph_Copy_Func) ft_outline_glyph_copy, + (FT_Glyph_Transform_Func)ft_outline_glyph_transform, + (FT_Glyph_BBox_Func) ft_outline_glyph_bbox, + (FT_Glyph_Prepare_Func) ft_outline_glyph_prepare +}; + + +/*************************************************************************/ +/*************************************************************************/ +/**** ****/ +/**** FT_Glyph class and API ****/ +/**** ****/ +/*************************************************************************/ +/*************************************************************************/ + +static +FT_Error ft_new_glyph( FT_Library library, + const FT_Glyph_Class* clazz, + FT_Glyph* aglyph ) { + FT_Memory memory = library->memory; + FT_Error error; + FT_Glyph glyph; + + + *aglyph = 0; + + if ( !ALLOC( glyph, clazz->glyph_size ) ) { + glyph->library = library; + glyph->clazz = clazz; + glyph->format = clazz->glyph_format; + + *aglyph = glyph; + } + + return error; +} + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Glyph_Copy */ +/* */ +/* */ +/* A function used to copy a glyph image. */ +/* */ +/* */ +/* source :: A handle to the source glyph object. */ +/* */ +/* */ +/* target :: A handle to the target glyph object. 0 in case of */ +/* error. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +FT_EXPORT_FUNC( FT_Error ) FT_Glyph_Copy( FT_Glyph source, + FT_Glyph * target ) +{ + FT_Glyph copy; + FT_Error error; + const FT_Glyph_Class* clazz; + + + /* check arguments */ + if ( !target || !source || !source->clazz ) { + error = FT_Err_Invalid_Argument; + goto Exit; + } + + *target = 0; + + clazz = source->clazz; + error = ft_new_glyph( source->library, clazz, © ); + if ( error ) { + goto Exit; + } + + if ( clazz->glyph_copy ) { + error = clazz->glyph_copy( source, copy ); + } + + if ( error ) { + FT_Done_Glyph( copy ); + } else { + *target = copy; + } + +Exit: + return error; +} + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Get_Glyph */ +/* */ +/* */ +/* A function used to extract a glyph image from a slot. */ +/* */ +/* */ +/* slot :: A handle to the source glyph slot. */ +/* */ +/* */ +/* aglyph :: A handle to the glyph object. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +FT_EXPORT_FUNC( FT_Error ) FT_Get_Glyph( FT_GlyphSlot slot, + FT_Glyph * aglyph ) +{ + FT_Library library = slot->library; + FT_Error error; + FT_Glyph glyph; + + const FT_Glyph_Class* clazz = 0; + + + if ( !slot ) { + return FT_Err_Invalid_Slot_Handle; + } + + if ( !aglyph ) { + return FT_Err_Invalid_Argument; + } + + /* if it is a bitmap, that's easy :-) */ + if ( slot->format == ft_glyph_format_bitmap ) { + clazz = &ft_bitmap_glyph_class; + } + /* it it is an outline too */ + else if ( slot->format == ft_glyph_format_outline ) { + clazz = &ft_outline_glyph_class; + } else + { + /* try to find a renderer that supports the glyph image format */ + FT_Renderer render = FT_Lookup_Renderer( library, slot->format, 0 ); + + + if ( render ) { + clazz = &render->glyph_class; + } + } + + if ( !clazz ) { + error = FT_Err_Invalid_Glyph_Format; + goto Exit; + } + + /* create FT_Glyph object */ + error = ft_new_glyph( library, clazz, &glyph ); + if ( error ) { + goto Exit; + } + + /* copy advance while converting it to 16.16 format */ + glyph->advance.x = slot->advance.x << 10; + glyph->advance.y = slot->advance.y << 10; + + /* now import the image from the glyph slot */ + error = clazz->glyph_init( glyph, slot ); + + /* if an error occurred, destroy the glyph */ + if ( error ) { + FT_Done_Glyph( glyph ); + } else { + *aglyph = glyph; + } + +Exit: + return error; +} + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Glyph_Transform */ +/* */ +/* */ +/* Transforms a glyph image if its format is scalable. */ +/* */ +/* */ +/* glyph :: A handle to the target glyph object. */ +/* */ +/* matrix :: A pointer to a 2x2 matrix to apply. */ +/* */ +/* delta :: A pointer to a 2d vector to apply. Coordinates are */ +/* expressed in 1/64th of a pixel. */ +/* */ +/* */ +/* FreeType error code (the glyph format is not scalable if it is */ +/* not zero). */ +/* */ +/* */ +/* The 2x2 transformation matrix is also applied to the glyph's */ +/* advance vector. */ +/* */ +FT_EXPORT_FUNC( FT_Error ) FT_Glyph_Transform( FT_Glyph glyph, + FT_Matrix * matrix, + FT_Vector * delta ) +{ + const FT_Glyph_Class* clazz; + FT_Error error = FT_Err_Ok; + + + if ( !glyph || !glyph->clazz ) { + error = FT_Err_Invalid_Argument; + } else + { + clazz = glyph->clazz; + if ( clazz->glyph_transform ) { + /* transform glyph image */ + clazz->glyph_transform( glyph, matrix, delta ); + + /* transform advance vector */ + if ( matrix ) { + FT_Vector_Transform( &glyph->advance, matrix ); + } + } else { + error = FT_Err_Invalid_Glyph_Format; + } + } + return error; +} + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Glyph_Get_CBox */ +/* */ +/* */ +/* Returns the glyph image's bounding box. */ +/* */ +/* */ +/* glyph :: A handle to the source glyph object. */ +/* */ +/* mode :: A set of bit flags that indicate how to interpret the */ +/* returned bounding box values. */ +/* */ +/* */ +/* box :: The glyph bounding box. Coordinates are expressed in */ +/* 1/64th of pixels if it is grid-fitted. */ +/* */ +/* */ +/* Coordinates are relative to the glyph origin, using the Y-upwards */ +/* convention. */ +/* */ +/* If `ft_glyph_bbox_subpixels' is set in `mode', the bbox */ +/* coordinates are returned in 26.6 pixels (i.e. 1/64th of pixels). */ +/* Otherwise, coordinates are expressed in integer pixels. */ +/* */ +/* Note that the maximum coordinates are exclusive, which means that */ +/* one can compute the width and height of the glyph image (be it in */ +/* integer or 26.6 pixels) as: */ +/* */ +/* width = bbox.xMax - bbox.xMin; */ +/* height = bbox.yMax - bbox.yMin; */ +/* */ +/* Note also that for 26.6 coordinates, if the */ +/* `ft_glyph_bbox_gridfit' flag is set in `mode;, the coordinates */ +/* will also be grid-fitted, which corresponds to: */ +/* */ +/* bbox.xMin = FLOOR(bbox.xMin); */ +/* bbox.yMin = FLOOR(bbox.yMin); */ +/* bbox.xMax = CEILING(bbox.xMax); */ +/* bbox.yMax = CEILING(bbox.yMax); */ +/* */ +/* The default value (0) for `bbox_mode' is `ft_glyph_bbox_pixels'. */ +/* */ +FT_EXPORT_FUNC( void ) FT_Glyph_Get_CBox( FT_Glyph glyph, + FT_UInt bbox_mode, + FT_BBox * cbox ) +{ + const FT_Glyph_Class* clazz; + FT_Error error = FT_Err_Ok; + + + if ( !cbox || !glyph || !glyph->clazz ) { + error = FT_Err_Invalid_Argument; + } else + { + clazz = glyph->clazz; + if ( !clazz->glyph_bbox ) { + error = FT_Err_Invalid_Glyph_Format; + } else + { + /* retrieve bbox in 26.6 coordinates */ + clazz->glyph_bbox( glyph, cbox ); + + /* perform grid fitting if needed */ + if ( bbox_mode & ft_glyph_bbox_gridfit ) { + cbox->xMin &= -64; + cbox->yMin &= -64; + cbox->xMax = ( cbox->xMax + 63 ) & - 64; + cbox->yMax = ( cbox->yMax + 63 ) & - 64; + } + + /* convert to integer pixels if needed */ + if ( !( bbox_mode & ft_glyph_bbox_subpixels ) ) { + cbox->xMin >>= 6; + cbox->yMin >>= 6; + cbox->xMax >>= 6; + cbox->yMax >>= 6; + } + } + } + return; +} + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Glyph_To_Bitmap */ +/* */ +/* */ +/* Converts a given glyph object to a bitmap glyph object. */ +/* */ +/* */ +/* glyph :: A pointer to a handle to the target glyph. */ +/* */ +/* */ +/* render_mode :: A set of bit flags that describe how the data is */ +/* */ +/* */ +/* origin :: A pointer to a vector used to translate the glyph */ +/* image before rendering. Can be 0 (if no */ +/* translation). The origin is expressed in */ +/* 26.6 pixels. */ +/* */ +/* destroy :: A boolean that indicates that the original glyph */ +/* image should be destroyed by this function. It is */ +/* never destroyed in case of error. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +/* */ +/* The glyph image is translated with the `origin' vector before */ +/* rendering. In case of error, it it translated back to its */ +/* original position and the glyph is left untouched. */ +/* */ +/* The first parameter is a pointer to a FT_Glyph handle, that will */ +/* be replaced by this function. Typically, you would use (omitting */ +/* error handling): */ +/* */ +/* */ +/* { */ +/* FT_Glyph glyph; */ +/* FT_BitmapGlyph glyph_bitmap; */ +/* */ +/* */ +/* // load glyph */ +/* error = FT_Load_Char( face, glyph_index, FT_LOAD_DEFAUT ); */ +/* */ +/* // extract glyph image */ +/* error = FT_Get_Glyph( face->glyph, &glyph ); */ +/* */ +/* // convert to a bitmap (default render mode + destroy old) */ +/* if ( glyph->format != ft_glyph_format_bitmap ) */ +/* { */ +/* error = FT_Glyph_To_Bitmap( &glyph, ft_render_mode_default, */ +/* 0, 1 ); */ +/* if ( error ) // glyph unchanged */ +/* ... */ +/* } */ +/* */ +/* // access bitmap content by typecasting */ +/* glyph_bitmap = (FT_BitmapGlyph)glyph; */ +/* */ +/* // do funny stuff with it, like blitting/drawing */ +/* ... */ +/* */ +/* // discard glyph image (bitmap or not) */ +/* FT_Done_Glyph( glyph ); */ +/* } */ +/* */ +/* */ +/* This function will always fail if the glyph's format isn't */ +/* scalable. */ +/* */ +FT_EXPORT_FUNC( FT_Error ) FT_Glyph_To_Bitmap( FT_Glyph * the_glyph, + FT_ULong render_mode, + FT_Vector * origin, + FT_Bool destroy ) +{ + FT_GlyphSlotRec dummy; + FT_Error error; + FT_Glyph glyph; + FT_BitmapGlyph bitmap; + + const FT_Glyph_Class* clazz; + + + /* check argument */ + if ( !the_glyph ) { + goto Bad; + } + + /* we render the glyph into a glyph bitmap using a `dummy' glyph slot */ + /* then calling FT_Render_Glyph_Internal() */ + + glyph = *the_glyph; + if ( !glyph ) { + goto Bad; + } + + clazz = glyph->clazz; + if ( !clazz || !clazz->glyph_prepare ) { + goto Bad; + } + + MEM_Set( &dummy, 0, sizeof( dummy ) ); + dummy.library = glyph->library; + dummy.format = clazz->glyph_format; + + /* if `origin' is set, translate the glyph image */ + if ( origin ) { + FT_Glyph_Transform( glyph, 0, origin ); + } + + /* create result bitmap glyph */ + error = ft_new_glyph( glyph->library, &ft_bitmap_glyph_class, + (FT_Glyph*)&bitmap ); + if ( error ) { + goto Exit; + } + + /* prepare dummy slot for rendering */ + error = clazz->glyph_prepare( glyph, &dummy ) || + FT_Render_Glyph_Internal( glyph->library, &dummy, render_mode ); + + if ( !destroy && origin ) { + FT_Vector v; + + + v.x = -origin->x; + v.y = -origin->y; + FT_Glyph_Transform( glyph, 0, &v ); + } + + /* in case of succes, copy the bitmap to the glyph bitmap */ + if ( !error ) { + error = ft_bitmap_glyph_init( bitmap, &dummy ); + if ( error ) { + /* this should never happen, but let's be safe */ + FT_Done_Glyph( FT_GLYPH( bitmap ) ); + goto Exit; + } + + if ( destroy ) { + FT_Done_Glyph( glyph ); + } + + *the_glyph = FT_GLYPH( bitmap ); + } + +Exit: + return error; + +Bad: + error = FT_Err_Invalid_Argument; + goto Exit; +} + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Done_Glyph */ +/* */ +/* */ +/* Destroys a given glyph. */ +/* */ +/* */ +/* glyph :: A handle to the target glyph object. */ +/* */ +FT_EXPORT_FUNC( void ) FT_Done_Glyph( FT_Glyph glyph ) +{ + if ( glyph ) { + FT_Memory memory = glyph->library->memory; + const FT_Glyph_Class* clazz = glyph->clazz; + + + if ( clazz->glyph_done ) { + clazz->glyph_done( glyph ); + } + + FREE( glyph ); + } +} + + +#if 0 + +/*************************************************************************/ +/*************************************************************************/ +/**** ****/ +/**** EXPERIMENTAL EMBOLDENING/OUTLINING SUPPORT ****/ +/**** ****/ +/*************************************************************************/ +/*************************************************************************/ + +/* Compute the norm of a vector */ + +#ifdef FT_CONFIG_OPTION_OLD_CALCS + +static +FT_Pos ft_norm( FT_Vector* vec ) { + FT_Int64 t1, t2; + + + MUL_64( vec->x, vec->x, t1 ); + MUL_64( vec->y, vec->y, t2 ); + ADD_64( t1, t2, t1 ); + + return (FT_Pos)SQRT_64( t1 ); +} + +#else /* FT_CONFIG_OPTION_OLD_CALCS */ + +static +FT_Pos ft_norm( FT_Vector* vec ) { + FT_F26Dot6 u, v, d; + FT_Int shift; + FT_ULong H, L, L2, hi, lo, med; + + + u = vec->x; if ( u < 0 ) { + u = -u; + } + v = vec->y; if ( v < 0 ) { + v = -v; + } + + if ( u < v ) { + d = u; + u = v; + v = d; + } + + /* check that we are not trying to normalize zero! */ + if ( u == 0 ) { + return 0; + } + + /* compute (u*u + v*v) on 64 bits with two 32-bit registers [H:L] */ + hi = (FT_ULong)u >> 16; + lo = (FT_ULong)u & 0xFFFF; + med = hi * lo; + + H = hi * hi + ( med >> 15 ); + med <<= 17; + L = lo * lo + med; + if ( L < med ) { + H++; + } + + hi = (FT_ULong)v >> 16; + lo = (FT_ULong)v & 0xFFFF; + med = hi * lo; + + H += hi * hi + ( med >> 15 ); + med <<= 17; + L2 = lo * lo + med; + if ( L2 < med ) { + H++; + } + + L += L2; + if ( L < L2 ) { + H++; + } + + /* if the value is smaller than 32 bits */ + shift = 0; + if ( H == 0 ) { + while ( ( L & 0xC0000000UL ) == 0 ) + { + L <<= 2; + shift++; + } + return ( FT_Sqrt32( L ) >> shift ); + } else + { + while ( H ) + { + L = ( L >> 2 ) | ( H << 30 ); + H >>= 2; + shift++; + } + return ( FT_Sqrt32( L ) << shift ); + } +} + +#endif /* FT_CONFIG_OPTION_OLD_CALCS */ + + +static +int ft_test_extrema( FT_Outline* outline, + int n ) { + FT_Vector *prev, *cur, *next; + FT_Pos product; + FT_Int first, last; + + + /* we need to compute the `previous' and `next' point */ + /* for these extrema. */ + cur = outline->points + n; + prev = cur - 1; + next = cur + 1; + + first = 0; + for ( c = 0; c < outline->n_contours; c++ ) + { + last = outline->contours[c]; + + if ( n == first ) { + prev = outline->points + last; + } + + if ( n == last ) { + next = outline->points + first; + } + + first = last + 1; + } + + product = FT_MulDiv( cur->x - prev->x, /* in.x */ + next->y - cur->y, /* out.y */ + 0x40 ) + - + FT_MulDiv( cur->y - prev->y, /* in.y */ + next->x - cur->x, /* out.x */ + 0x40 ); + + if ( product ) { + product = product > 0 ? 1 : -1; + } + + return product; +} + + +/* Compute the orientation of path filling. It differs between TrueType */ +/* and Type1 formats. We could use the `ft_outline_reverse_fill' flag, */ +/* but it is better to re-compute it directly (it seems that this flag */ +/* isn't correctly set for some weird composite glyphs currently). */ +/* */ +/* We do this by computing bounding box points, and computing their */ +/* curvature. */ +/* */ +/* The function returns either 1 or -1. */ +/* */ +static +int ft_get_orientation( FT_Outline* outline ) { + FT_BBox box; + FT_BBox indices; + int n, last; + + + indices.xMin = -1; + indices.yMin = -1; + indices.xMax = -1; + indices.yMax = -1; + + box.xMin = box.yMin = 32767; + box.xMax = box.yMax = -32768; + + /* is it empty ? */ + if ( outline->n_contours < 1 ) { + return 1; + } + + last = outline->contours[outline->n_contours - 1]; + + for ( n = 0; n <= last; n++ ) + { + FT_Pos x, y; + + + x = outline->points[n].x; + if ( x < box.xMin ) { + box.xMin = x; + indices.xMin = n; + } + if ( x > box.xMax ) { + box.xMax = x; + indices.xMax = n; + } + + y = outline->points[n].y; + if ( y < box.yMin ) { + box.yMin = y; + indices.yMin = n; + } + if ( y > box.yMax ) { + box.yMax = y; + indices.yMax = n; + } + } + + /* test orientation of the xmin */ + return ft_test_extrema( outline, indices.xMin ) || + ft_test_extrema( outline, indices.yMin ) || + ft_test_extrema( outline, indices.xMax ) || + ft_test_extrema( outline, indices.yMax ) || + 1; /* this is an empty glyph? */ +} + + +static +FT_Error ft_embolden( FT_Face original, + FT_Outline* outline, + FT_Pos* advance ) { + FT_Vector u, v; + FT_Vector* points; + FT_Vector cur, prev, next; + FT_Pos distance; + int c, n, first, orientation; + + FT_UNUSED( advance ); + + + /* compute control distance */ + distance = FT_MulFix( original->em_size / 60, + original->size->metrics.y_scale ); + + orientation = ft_get_orientation( &original->glyph->outline ); + + points = original->glyph->outline.points; + + first = 0; + for ( c = 0; c < outline->n_contours; c++ ) + { + int last = outline->contours[c]; + + + prev = points[last]; + + for ( n = first; n <= last; n++ ) + { + FT_Pos norm, delta, d; + FT_Vector in, out; + + + cur = points[n]; + if ( n < last ) { + next = points[n + 1]; + } else { next = points[first];} + + /* compute the in and out vectors */ + in.x = cur.x - prev.x; + in.y = cur.y - prev.y; + + out.x = next.x - cur.x; + out.y = next.y - cur.y; + + /* compute U and V */ + norm = ft_norm( &in ); + u.x = orientation * FT_DivFix( in.y, norm ); + u.y = orientation * -FT_DivFix( in.x, norm ); + + norm = ft_norm( &out ); + v.x = orientation * FT_DivFix( out.y, norm ); + v.y = orientation * -FT_DivFix( out.x, norm ); + + d = distance; + + if ( ( outline->flags[n] & FT_Curve_Tag_On ) == 0 ) { + d *= 2; + } + + /* Check discriminant for parallel vectors */ + delta = FT_MulFix( u.x, v.y ) - FT_MulFix( u.y, v.x ); + if ( delta > FT_BOLD_THRESHOLD || delta < -FT_BOLD_THRESHOLD ) { + /* Move point -- compute A and B */ + FT_Pos x, y, A, B; + + + A = d + FT_MulFix( cur.x, u.x ) + FT_MulFix( cur.y, u.y ); + B = d + FT_MulFix( cur.x, v.x ) + FT_MulFix( cur.y, v.y ); + + x = FT_MulFix( A, v.y ) - FT_MulFix( B, u.y ); + y = FT_MulFix( B, u.x ) - FT_MulFix( A, v.x ); + + outline->points[n].x = distance + FT_DivFix( x, delta ); + outline->points[n].y = distance + FT_DivFix( y, delta ); + } else + { + /* Vectors are nearly parallel */ + FT_Pos x, y; + + + x = distance + cur.x + FT_MulFix( d, u.x + v.x ) / 2; + y = distance + cur.y + FT_MulFix( d, u.y + v.y ) / 2; + + outline->points[n].x = x; + outline->points[n].y = y; + } + + prev = cur; + } + + first = last + 1; + } + + if ( advance ) { + *advance = ( *advance + distance * 4 ) & - 64; + } + + return 0; +} + +#endif /* 0 -- EXPERIMENTAL STUFF! */ + + +/* END */ diff --git a/Projects/Android/jni/rtcw/src/ft2/ftglyph.h b/Projects/Android/jni/rtcw/src/ft2/ftglyph.h new file mode 100644 index 0000000..4aaa2f9 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/ft2/ftglyph.h @@ -0,0 +1,422 @@ +/***************************************************************************/ +/* */ +/* ftglyph.h */ +/* */ +/* FreeType convenience functions to handle glyphs (specification). */ +/* */ +/* Copyright 1996-2000 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +/*************************************************************************/ +/* */ +/* This file contains the definition of several convenience functions */ +/* that can be used by client applications to easily retrieve glyph */ +/* bitmaps and outlines from a given face. */ +/* */ +/* These functions should be optional if you are writing a font server */ +/* or text layout engine on top of FreeType. However, they are pretty */ +/* handy for many other simple uses of the library. */ +/* */ +/*************************************************************************/ + + +#ifndef FTGLYPH_H +#define FTGLYPH_H + +#include "freetype.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* forward declaration to a private type */ +typedef struct FT_Glyph_Class_ FT_Glyph_Class; + + +/*************************************************************************/ +/* */ +/* */ +/* FT_GlyphRec */ +/* */ +/* */ +/* The root glyph structure contains a given glyph image plus its */ +/* advance width in 16.16 fixed float format. */ +/* */ +/* */ +/* library :: A handle to the FreeType library object. */ +/* */ +/* clazz :: A pointer to the glyph's class. Private. */ +/* */ +/* format :: The format of the glyph's image. */ +/* */ +/* advance :: A 16.16 vector that gives the glyph's advance width. */ +/* */ +typedef struct FT_GlyphRec_ +{ + FT_Library library; + const FT_Glyph_Class* clazz; + FT_Glyph_Format format; + FT_Vector advance; + +} FT_GlyphRec, *FT_Glyph; + + +/*************************************************************************/ +/* */ +/* */ +/* FT_BitmapGlyphRec */ +/* */ +/* */ +/* A structure used for bitmap glyph images. This really is a */ +/* `sub-class' of `FT_GlyphRec'. */ +/* */ +/* */ +/* root :: The root FT_Glyph fields. */ +/* */ +/* left :: The left-side bearing, i.e., the horizontal distance */ +/* from the current pen position to the left border of the */ +/* glyph bitmap. */ +/* */ +/* top :: The top-side bearing, i.e., the vertical distance from */ +/* the current pen position to the top border of the glyph */ +/* bitmap. This distance is positive for upwards-y! */ +/* */ +/* bitmap :: A descriptor for the bitmap. */ +/* */ +/* */ +/* You can typecast FT_Glyph to FT_BitmapGlyph if you have */ +/* glyph->format == ft_glyph_format_bitmap. This lets you access */ +/* the bitmap's contents easily. */ +/* */ +/* The corresponding pixel buffer is always owned by the BitmapGlyph */ +/* and is thus created and destroyed with it. */ +/* */ +typedef struct FT_BitmapGlyphRec_ +{ + FT_GlyphRec root; + FT_Int left; + FT_Int top; + FT_Bitmap bitmap; + +} FT_BitmapGlyphRec, *FT_BitmapGlyph; + + +/*************************************************************************/ +/* */ +/* */ +/* FT_OutlineGlyphRec */ +/* */ +/* */ +/* A structure used for outline (vectorial) glyph images. This */ +/* really is a `sub-class' of `FT_GlyphRec'. */ +/* */ +/* */ +/* root :: The root FT_Glyph fields. */ +/* */ +/* outline :: A descriptor for the outline. */ +/* */ +/* */ +/* You can typecast FT_Glyph to FT_OutlineGlyph if you have */ +/* glyph->format == ft_glyph_format_outline. This lets you access */ +/* the outline's content easily. */ +/* */ +/* As the outline is extracted from a glyph slot, its coordinates are */ +/* expressed normally in 26.6 pixels, unless the flag */ +/* FT_LOAD_NO_SCALE was used in FT_Load_Glyph() or FT_Load_Char(). */ +/* */ +/* The outline's tables are always owned by the object and are */ +/* destroyed with it. */ +/* */ +typedef struct FT_OutlineGlyphRec_ +{ + FT_GlyphRec root; + FT_Outline outline; + +} FT_OutlineGlyphRec, *FT_OutlineGlyph; + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Get_Glyph */ +/* */ +/* */ +/* A function used to extract a glyph image from a slot. */ +/* */ +/* */ +/* slot :: A handle to the source glyph slot. */ +/* */ +/* */ +/* aglyph :: A handle to the glyph object. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +FT_EXPORT_DEF( FT_Error ) FT_Get_Glyph( FT_GlyphSlot slot, + FT_Glyph * aglyph ); + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Glyph_Copy */ +/* */ +/* */ +/* A function used to copy a glyph image. */ +/* */ +/* */ +/* source :: A handle to the source glyph object. */ +/* */ +/* */ +/* target :: A handle to the target glyph object. 0 in case of */ +/* error. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +FT_EXPORT_DEF( FT_Error ) FT_Glyph_Copy( FT_Glyph source, + FT_Glyph * target ); + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Glyph_Transform */ +/* */ +/* */ +/* Transforms a glyph image if its format is scalable. */ +/* */ +/* */ +/* glyph :: A handle to the target glyph object. */ +/* */ +/* matrix :: A pointer to a 2x2 matrix to apply. */ +/* */ +/* delta :: A pointer to a 2d vector to apply. Coordinates are */ +/* expressed in 1/64th of a pixel. */ +/* */ +/* */ +/* FreeType error code (the glyph format is not scalable if it is */ +/* not zero). */ +/* */ +/* */ +/* The 2x2 transformation matrix is also applied to the glyph's */ +/* advance vector. */ +/* */ +FT_EXPORT_DEF( FT_Error ) FT_Glyph_Transform( FT_Glyph glyph, + FT_Matrix * matrix, + FT_Vector * delta ); + + +enum +{ + ft_glyph_bbox_pixels = 0, + ft_glyph_bbox_subpixels = 1, + ft_glyph_bbox_gridfit = 2 +}; + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Glyph_Get_CBox */ +/* */ +/* */ +/* Returns the glyph image's bounding box. */ +/* */ +/* */ +/* glyph :: A handle to the source glyph object. */ +/* */ +/* mode :: A set of bit flags that indicate how to interpret the */ +/* returned bounding box values. */ +/* */ +/* */ +/* box :: The glyph bounding box. Coordinates are expressed in */ +/* 1/64th of pixels if it is grid-fitted. */ +/* */ +/* */ +/* Coordinates are relative to the glyph origin, using the Y-upwards */ +/* convention. */ +/* */ +/* If `ft_glyph_bbox_subpixels' is set in `mode', the bbox */ +/* coordinates are returned in 26.6 pixels (i.e. 1/64th of pixels). */ +/* Otherwise, coordinates are expressed in integer pixels. */ +/* */ +/* Note that the maximum coordinates are exclusive, which means that */ +/* one can compute the width and height of the glyph image (be it in */ +/* integer or 26.6 pixels) as: */ +/* */ +/* width = bbox.xMax - bbox.xMin; */ +/* height = bbox.yMax - bbox.yMin; */ +/* */ +/* Note also that for 26.6 coordinates, if the */ +/* `ft_glyph_bbox_gridfit' flag is set in `mode;, the coordinates */ +/* will also be grid-fitted, which corresponds to: */ +/* */ +/* bbox.xMin = FLOOR(bbox.xMin); */ +/* bbox.yMin = FLOOR(bbox.yMin); */ +/* bbox.xMax = CEILING(bbox.xMax); */ +/* bbox.yMax = CEILING(bbox.yMax); */ +/* */ +/* The default value (0) for `bbox_mode' is `ft_glyph_bbox_pixels'. */ +/* */ +FT_EXPORT_DEF( void ) FT_Glyph_Get_CBox( FT_Glyph glyph, + FT_UInt bbox_mode, + FT_BBox * cbox ); + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Glyph_To_Bitmap */ +/* */ +/* */ +/* Converts a given glyph object to a bitmap glyph object. */ +/* */ +/* */ +/* glyph :: A pointer to a handle to the target glyph. */ +/* */ +/* */ +/* render_mode :: A set of bit flags that describe how the data is */ +/* */ +/* */ +/* origin :: A pointer to a vector used to translate the glyph */ +/* image before rendering. Can be 0 (if no */ +/* translation). The origin is expressed in */ +/* 26.6 pixels. */ +/* */ +/* destroy :: A boolean that indicates that the original glyph */ +/* image should be destroyed by this function. It is */ +/* never destroyed in case of error. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +/* */ +/* The glyph image is translated with the `origin' vector before */ +/* rendering. In case of error, it it translated back to its */ +/* original position and the glyph is left untouched. */ +/* */ +/* The first parameter is a pointer to a FT_Glyph handle, that will */ +/* be replaced by this function. Typically, you would use (omitting */ +/* error handling): */ +/* */ +/* */ +/* { */ +/* FT_Glyph glyph; */ +/* FT_BitmapGlyph glyph_bitmap; */ +/* */ +/* */ +/* // load glyph */ +/* error = FT_Load_Char( face, glyph_index, FT_LOAD_DEFAUT ); */ +/* */ +/* // extract glyph image */ +/* error = FT_Get_Glyph( face->glyph, &glyph ); */ +/* */ +/* // convert to a bitmap (default render mode + destroy old) */ +/* if ( glyph->format != ft_glyph_format_bitmap ) */ +/* { */ +/* error = FT_Glyph_To_Bitmap( &glyph, ft_render_mode_default, */ +/* 0, 1 ); */ +/* if ( error ) // glyph unchanged */ +/* ... */ +/* } */ +/* */ +/* // access bitmap content by typecasting */ +/* glyph_bitmap = (FT_BitmapGlyph)glyph; */ +/* */ +/* // do funny stuff with it, like blitting/drawing */ +/* ... */ +/* */ +/* // discard glyph image (bitmap or not) */ +/* FT_Done_Glyph( glyph ); */ +/* } */ +/* */ +/* */ +/* This function will always fail if the glyph's format isn't */ +/* scalable. */ +/* */ +FT_EXPORT_DEF( FT_Error ) FT_Glyph_To_Bitmap( FT_Glyph * the_glyph, + FT_ULong render_mode, + FT_Vector * origin, + FT_Bool destroy ); + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Done_Glyph */ +/* */ +/* */ +/* Destroys a given glyph. */ +/* */ +/* */ +/* glyph :: A handle to the target glyph object. */ +/* */ +FT_EXPORT_DEF( void ) FT_Done_Glyph( FT_Glyph glyph ); + + +/* other helpful functions */ + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Matrix_Multiply */ +/* */ +/* */ +/* Performs the matrix operation `b = a*b'. */ +/* */ +/* */ +/* a :: A pointer to matrix `a'. */ +/* */ +/* */ +/* b :: A pointer to matrix `b'. */ +/* */ +/* */ +/* Yes. */ +/* */ +/* */ +/* The result is undefined if either `a' or `b' is zero. */ +/* */ +FT_EXPORT_DEF( void ) FT_Matrix_Multiply( FT_Matrix * a, + FT_Matrix * b ); + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Matrix_Invert */ +/* */ +/* */ +/* Inverts a 2x2 matrix. Returns an error if it can't be inverted. */ +/* */ +/* */ +/* matrix :: A pointer to the target matrix. Remains untouched in */ +/* case of error. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +/* */ +/* Yes. */ +/* */ +FT_EXPORT_DEF( FT_Error ) FT_Matrix_Invert( FT_Matrix * matrix ); + + +#ifdef __cplusplus +} +#endif + +#endif /* FTGLYPH_H */ + + +/* END */ diff --git a/Projects/Android/jni/rtcw/src/ft2/ftgrays.c b/Projects/Android/jni/rtcw/src/ft2/ftgrays.c new file mode 100644 index 0000000..55f2ac9 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/ft2/ftgrays.c @@ -0,0 +1,1996 @@ +/***************************************************************************/ +/* */ +/* ftgrays.c */ +/* */ +/* A new `perfect' anti-aliasing renderer (body). */ +/* */ +/* Copyright 2000 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + +/*************************************************************************/ +/* */ +/* This file can be compiled without the rest of the FreeType engine, */ +/* by defining the _STANDALONE_ macro when compiling it. You also need */ +/* to put the files `ftgrays.h' and `ftimage.h' into the current */ +/* compilation directory. Typically, you could do something like */ +/* */ +/* - copy `src/base/ftgrays.c' to your current directory */ +/* */ +/* - copy `include/freetype/ftimage.h' and */ +/* `include/freetype/ftgrays.h' to the same directory */ +/* */ +/* - compile `ftgrays' with the _STANDALONE_ macro defined, as in */ +/* */ +/* cc -c -D_STANDALONE_ ftgrays.c */ +/* */ +/* The renderer can be initialized with a call to */ +/* `ft_grays_raster.grays_raster_new'; an anti-aliased bitmap can be */ +/* generated with a call to `ft_grays_raster.grays_raster_render'. */ +/* */ +/* See the comments and documentation in the file `ftimage.h' for */ +/* more details on how the raster works. */ +/* */ +/*************************************************************************/ + +/*************************************************************************/ +/* */ +/* This is a new anti-aliasing scan-converter for FreeType 2. The */ +/* algorithm used here is _very_ different from the one in the standard */ +/* `ftraster' module. Actually, `ftgrays' computes the _exact_ */ +/* coverage of the outline on each pixel cell. */ +/* */ +/* It is based on ideas that I initially found in Raph Levien's */ +/* excellent LibArt graphics library (see http://www.levien.com/libart */ +/* for more information, though the web pages do not tell anything */ +/* about the renderer; you'll have to dive into the source code to */ +/* understand how it works). */ +/* */ +/* Note, however, that this is a _very_ different implementation */ +/* compared to Raph's. Coverage information is stored in a very */ +/* different way, and I don't use sorted vector paths. Also, it */ +/* doesn't use floating point values. */ +/* */ +/* This renderer has the following advantages: */ +/* */ +/* - It doesn't need an intermediate bitmap. Instead, one can supply */ +/* a callback function that will be called by the renderer to draw */ +/* gray spans on any target surface. You can thus do direct */ +/* composition on any kind of bitmap, provided that you give the */ +/* renderer the right callback. */ +/* */ +/* - A perfect anti-aliaser, i.e., it computes the _exact_ coverage on */ +/* each pixel cell */ +/* */ +/* - It performs a single pass on the outline (the `standard' FT2 */ +/* renderer makes two passes). */ +/* */ +/* - It can easily be modified to render to _any_ number of gray levels */ +/* cheaply. */ +/* */ +/* - For small (< 20) pixel sizes, it is faster than the standard */ +/* renderer. */ +/* */ +/*************************************************************************/ + + +#include /* for memcpy() */ + + +/*************************************************************************/ +/* */ +/* The macro FT_COMPONENT is used in trace mode. It is an implicit */ +/* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */ +/* messages during execution. */ +/* */ +#undef FT_COMPONENT +#define FT_COMPONENT trace_aaraster + + +#ifdef _STANDALONE_ + + +#define ErrRaster_Invalid_Mode -2 +#define ErrRaster_Invalid_Outline -1 + +#include "ftimage.h" +#include "ftgrays.h" + +/* This macro is used to indicate that a function parameter is unused. */ +/* Its purpose is simply to reduce compiler warnings. Note also that */ +/* simply defining it as `(void)x' doesn't avoid warnings with certain */ +/* ANSI compilers (e.g. LCC). */ +#define FT_UNUSED( x ) ( x ) = ( x ) + +/* Disable the tracing mechanism for simplicity -- developers can */ +/* activate it easily by redefining these two macros. */ +#ifndef FT_ERROR +#define FT_ERROR( x ) do ;while ( 0 ) /* nothing */ +#endif + +#ifndef FT_TRACE +#define FT_TRACE( x ) do ;while ( 0 ) /* nothing */ +#endif + + +#else /* _STANDALONE_ */ + + + +#include "ftgrays.h" + + +#include "ftobjs.h" /* for FT_UNUSED() */ +#include "ftdebug.h" /* for FT_TRACE() and FT_ERROR() */ +#include "ftoutln.h" /* for FT_Outline_Decompose() */ + +#define ErrRaster_Invalid_Mode FT_Err_Cannot_Render_Glyph +#define ErrRaster_Invalid_Outline FT_Err_Invalid_Outline + + +#endif /* _STANDALONE_ */ + + +/* define this to dump debugging information */ +#define xxxDEBUG_GRAYS + +/* as usual, for the speed hungry :-) */ + +#ifndef FT_STATIC_RASTER + + +#define RAS_ARG PRaster raster +#define RAS_ARG_ PRaster raster, + +#define RAS_VAR raster +#define RAS_VAR_ raster, + +#define ras ( *raster ) + + +#else /* FT_STATIC_RASTER */ + + +#define RAS_ARG /* empty */ +#define RAS_ARG_ /* empty */ +#define RAS_VAR /* empty */ +#define RAS_VAR_ /* empty */ + +static TRaster ras; + + +#endif /* FT_STATIC_RASTER */ + + +/* must be at least 6 bits! */ +#define PIXEL_BITS 8 + +#define ONE_PIXEL ( 1L << PIXEL_BITS ) +#define PIXEL_MASK ( -1L << PIXEL_BITS ) +#define TRUNC( x ) ( ( x ) >> PIXEL_BITS ) +#define SUBPIXELS( x ) ( ( x ) << PIXEL_BITS ) +#define FLOOR( x ) ( ( x ) & - ONE_PIXEL ) +#define CEILING( x ) ( ( ( x ) + ONE_PIXEL - 1 ) & - ONE_PIXEL ) +#define ROUND( x ) ( ( ( x ) + ONE_PIXEL / 2 ) & - ONE_PIXEL ) + +#if PIXEL_BITS >= 6 +#define UPSCALE( x ) ( ( x ) << ( PIXEL_BITS - 6 ) ) +#define DOWNSCALE( x ) ( ( x ) >> ( PIXEL_BITS - 6 ) ) +#else +#define UPSCALE( x ) ( ( x ) >> ( 6 - PIXEL_BITS ) ) +#define DOWNSCALE( x ) ( ( x ) << ( 6 - PIXEL_BITS ) ) +#endif + +/* Define this if you want to use a more compact storage scheme. This */ +/* increases the number of cells available in the render pool but slows */ +/* down the rendering a bit. It is useful if you have a really tiny */ +/* render pool. */ +#define xxxGRAYS_COMPACT + + +/*************************************************************************/ +/* */ +/* TYPE DEFINITIONS */ +/* */ +typedef int TScan; /* integer scanline/pixel coordinate */ +typedef long TPos; /* sub-pixel coordinate */ + +/* maximal number of gray spans in a call to the span callback */ +#define FT_MAX_GRAY_SPANS 32 + + +#ifdef GRAYS_COMPACT + +typedef struct TCell_ +{ + short x : 14; + short y : 14; + int cover : PIXEL_BITS + 2; + int area : PIXEL_BITS * 2 + 2; + +} TCell, *PCell; + +#else /* GRAYS_COMPACT */ + +typedef struct TCell_ +{ + TScan x; + TScan y; + int cover; + int area; + +} TCell, *PCell; + +#endif /* GRAYS_COMPACT */ + + +typedef struct TRaster_ +{ + PCell cells; + int max_cells; + int num_cells; + + TScan min_ex, max_ex; + TScan min_ey, max_ey; + + int area; + int cover; + int invalid; + + TScan ex, ey; + TScan cx, cy; + TPos x, y; + + TScan last_ey; + + FT_Vector bez_stack[32 * 3]; + int lev_stack[32]; + + FT_Outline outline; + FT_Bitmap target; + + FT_Span gray_spans[FT_MAX_GRAY_SPANS]; + int num_gray_spans; + + FT_Raster_Span_Func render_span; + void* render_span_data; + int span_y; + + int band_size; + int band_shoot; + int conic_level; + int cubic_level; + + void* memory; + +} TRaster, *PRaster; + + +/*************************************************************************/ +/* */ +/* Initialize the cells table. */ +/* */ +static +void init_cells( RAS_ARG_ void* buffer, + long byte_size ) { + ras.cells = (PCell)buffer; + ras.max_cells = byte_size / sizeof( TCell ); + ras.num_cells = 0; + ras.area = 0; + ras.cover = 0; + ras.invalid = 1; +} + + +/*************************************************************************/ +/* */ +/* Compute the outline bounding box. */ +/* */ +static +void compute_cbox( RAS_ARG_ FT_Outline* outline ) { + FT_Vector* vec = outline->points; + FT_Vector* limit = vec + outline->n_points; + + + if ( outline->n_points <= 0 ) { + ras.min_ex = ras.max_ex = 0; + ras.min_ey = ras.max_ey = 0; + return; + } + + ras.min_ex = ras.max_ex = vec->x; + ras.min_ey = ras.max_ey = vec->y; + + vec++; + + for ( ; vec < limit; vec++ ) + { + TPos x = vec->x; + TPos y = vec->y; + + + if ( x < ras.min_ex ) { + ras.min_ex = x; + } + if ( x > ras.max_ex ) { + ras.max_ex = x; + } + if ( y < ras.min_ey ) { + ras.min_ey = y; + } + if ( y > ras.max_ey ) { + ras.max_ey = y; + } + } + + /* truncate the bounding box to integer pixels */ + ras.min_ex = ras.min_ex >> 6; + ras.min_ey = ras.min_ey >> 6; + ras.max_ex = ( ras.max_ex + 63 ) >> 6; + ras.max_ey = ( ras.max_ey + 63 ) >> 6; +} + + +/*************************************************************************/ +/* */ +/* Record the current cell in the table. */ +/* */ +static +int record_cell( RAS_ARG ) { + PCell cell; + + + if ( !ras.invalid && ( ras.area | ras.cover ) ) { + if ( ras.num_cells >= ras.max_cells ) { + return 1; + } + + cell = ras.cells + ras.num_cells++; + cell->x = ras.ex - ras.min_ex; + cell->y = ras.ey - ras.min_ey; + cell->area = ras.area; + cell->cover = ras.cover; + } + + return 0; +} + + +/*************************************************************************/ +/* */ +/* Set the current cell to a new position. */ +/* */ +static +int set_cell( RAS_ARG_ TScan ex, + TScan ey ) { + int invalid, record, clean; + + + /* Move the cell pointer to a new position. We set the `invalid' */ + /* flag to indicate that the cell isn't part of those we're interested */ + /* in during the render phase. This means that: */ + /* */ + /* . the new vertical position must be within min_ey..max_ey-1. */ + /* . the new horizontal position must be strictly less than max_ex */ + /* */ + /* Note that if a cell is to the left of the clipping region, it is */ + /* actually set to the (min_ex-1) horizontal position. */ + + record = 0; + clean = 1; + + invalid = ( ey < ras.min_ey || ey >= ras.max_ey || ex >= ras.max_ex ); + if ( !invalid ) { + /* All cells that are on the left of the clipping region go to the */ + /* min_ex - 1 horizontal position. */ + if ( ex < ras.min_ex ) { + ex = ras.min_ex - 1; + } + + /* if our position is new, then record the previous cell */ + if ( ex != ras.ex || ey != ras.ey ) { + record = 1; + } else { + clean = ras.invalid; /* do not clean if we didn't move from */ + } + /* a valid cell */ + } + + /* record the previous cell if needed (i.e., if we changed the cell */ + /* position, of changed the `invalid' flag) */ + if ( ( ras.invalid != invalid || record ) && record_cell( RAS_VAR ) ) { + return 1; + } + + if ( clean ) { + ras.area = 0; + ras.cover = 0; + } + + ras.invalid = invalid; + ras.ex = ex; + ras.ey = ey; + return 0; +} + + +/*************************************************************************/ +/* */ +/* Start a new contour at a given cell. */ +/* */ +static +void start_cell( RAS_ARG_ TScan ex, + TScan ey ) { + if ( ex < ras.min_ex ) { + ex = ras.min_ex - 1; + } + + ras.area = 0; + ras.cover = 0; + ras.ex = ex; + ras.ey = ey; + ras.last_ey = SUBPIXELS( ey ); + ras.invalid = 0; + + (void)set_cell( RAS_VAR_ ex, ey ); +} + + +/*************************************************************************/ +/* */ +/* Render a scanline as one or more cells. */ +/* */ +static +int render_scanline( RAS_ARG_ TScan ey, + TPos x1, + TScan y1, + TPos x2, + TScan y2 ) { + TScan ex1, ex2, fx1, fx2, delta; + long p, first, dx; + int incr, lift, mod, rem; + + + dx = x2 - x1; + + ex1 = TRUNC( x1 ); /* if (ex1 >= ras.max_ex) ex1 = ras.max_ex-1; */ + ex2 = TRUNC( x2 ); /* if (ex2 >= ras.max_ex) ex2 = ras.max_ex-1; */ + fx1 = x1 - SUBPIXELS( ex1 ); + fx2 = x2 - SUBPIXELS( ex2 ); + + /* trivial case. Happens often */ + if ( y1 == y2 ) { + return set_cell( RAS_VAR_ ex2, ey ); + } + + /* everything is located in a single cell. That is easy! */ + /* */ + if ( ex1 == ex2 ) { + delta = y2 - y1; + ras.area += ( fx1 + fx2 ) * delta; + ras.cover += delta; + return 0; + } + + /* ok, we'll have to render a run of adjacent cells on the same */ + /* scanline... */ + /* */ + p = ( ONE_PIXEL - fx1 ) * ( y2 - y1 ); + first = ONE_PIXEL; + incr = 1; + + if ( dx < 0 ) { + p = fx1 * ( y2 - y1 ); + first = 0; + incr = -1; + dx = -dx; + } + + delta = p / dx; + mod = p % dx; + if ( mod < 0 ) { + delta--; + mod += dx; + } + + ras.area += ( fx1 + first ) * delta; + ras.cover += delta; + + ex1 += incr; + if ( set_cell( RAS_VAR_ ex1, ey ) ) { + goto Error; + } + y1 += delta; + + if ( ex1 != ex2 ) { + p = ONE_PIXEL * ( y2 - y1 ); + lift = p / dx; + rem = p % dx; + if ( rem < 0 ) { + lift--; + rem += dx; + } + + mod -= dx; + + while ( ex1 != ex2 ) + { + delta = lift; + mod += rem; + if ( mod >= 0 ) { + mod -= dx; + delta++; + } + + ras.area += ONE_PIXEL * delta; + ras.cover += delta; + y1 += delta; + ex1 += incr; + if ( set_cell( RAS_VAR_ ex1, ey ) ) { + goto Error; + } + } + } + + delta = y2 - y1; + ras.area += ( fx2 + ONE_PIXEL - first ) * delta; + ras.cover += delta; + + return 0; + +Error: + return 1; +} + + +/*************************************************************************/ +/* */ +/* Render a given line as a series of scanlines. */ +/* */ +static +int render_line( RAS_ARG_ TPos to_x, + TPos to_y ) { + TScan ey1, ey2, fy1, fy2; + TPos dx, dy, x, x2; + int p, rem, mod, lift, delta, first, incr; + + + ey1 = TRUNC( ras.last_ey ); + ey2 = TRUNC( to_y ); /* if (ey2 >= ras.max_ey) ey2 = ras.max_ey-1; */ + fy1 = ras.y - ras.last_ey; + fy2 = to_y - SUBPIXELS( ey2 ); + + dx = to_x - ras.x; + dy = to_y - ras.y; + + /* XXX: we should do something about the trivial case where dx == 0, */ + /* as it happens very often! */ + + /* perform vertical clipping */ + { + TScan min, max; + + + min = ey1; + max = ey2; + if ( ey1 > ey2 ) { + min = ey2; + max = ey1; + } + if ( min >= ras.max_ey || max < ras.min_ey ) { + goto End; + } + } + + /* everything is on a single scanline */ + if ( ey1 == ey2 ) { + if ( render_scanline( RAS_VAR_ ey1, ras.x, fy1, to_x, fy2 ) ) { + goto Error; + } + goto End; + } + + /* ok, we have to render several scanlines */ + p = ( ONE_PIXEL - fy1 ) * dx; + first = ONE_PIXEL; + incr = 1; + + if ( dy < 0 ) { + p = fy1 * dx; + first = 0; + incr = -1; + dy = -dy; + } + + delta = p / dy; + mod = p % dy; + if ( mod < 0 ) { + delta--; + mod += dy; + } + + x = ras.x + delta; + if ( render_scanline( RAS_VAR_ ey1, ras.x, fy1, x, first ) ) { + goto Error; + } + + ey1 += incr; + if ( set_cell( RAS_VAR_ TRUNC( x ), ey1 ) ) { + goto Error; + } + + if ( ey1 != ey2 ) { + p = ONE_PIXEL * dx; + lift = p / dy; + rem = p % dy; + if ( rem < 0 ) { + lift--; + rem += dy; + } + mod -= dy; + + while ( ey1 != ey2 ) + { + delta = lift; + mod += rem; + if ( mod >= 0 ) { + mod -= dy; + delta++; + } + + x2 = x + delta; + if ( render_scanline( RAS_VAR_ ey1, + x, ONE_PIXEL - first, x2, first ) ) { + goto Error; + } + x = x2; + ey1 += incr; + if ( set_cell( RAS_VAR_ TRUNC( x ), ey1 ) ) { + goto Error; + } + } + } + + if ( render_scanline( RAS_VAR_ ey1, + x, ONE_PIXEL - first, to_x, fy2 ) ) { + goto Error; + } + +End: + ras.x = to_x; + ras.y = to_y; + ras.last_ey = SUBPIXELS( ey2 ); + + return 0; + +Error: + return 1; +} + + +static +void split_conic( FT_Vector* base ) { + TPos a, b; + + + base[4].x = base[2].x; + b = base[1].x; + a = base[3].x = ( base[2].x + b ) / 2; + b = base[1].x = ( base[0].x + b ) / 2; + base[2].x = ( a + b ) / 2; + + base[4].y = base[2].y; + b = base[1].y; + a = base[3].y = ( base[2].y + b ) / 2; + b = base[1].y = ( base[0].y + b ) / 2; + base[2].y = ( a + b ) / 2; +} + + +static +int render_conic( RAS_ARG_ FT_Vector* control, + FT_Vector* to ) { + TPos dx, dy; + int top, level; + int* levels; + FT_Vector* arc; + + + dx = DOWNSCALE( ras.x ) + to->x - ( control->x << 1 ); + if ( dx < 0 ) { + dx = -dx; + } + dy = DOWNSCALE( ras.y ) + to->y - ( control->y << 1 ); + if ( dy < 0 ) { + dy = -dy; + } + if ( dx < dy ) { + dx = dy; + } + + level = 1; + dx = dx / ras.conic_level; + while ( dx > 0 ) + { + dx >>= 1; + level++; + } + + /* a shortcut to speed things up */ + if ( level <= 1 ) { + /* we compute the mid-point directly in order to avoid */ + /* calling split_conic() */ + TPos to_x, to_y, mid_x, mid_y; + + + to_x = UPSCALE( to->x ); + to_y = UPSCALE( to->y ); + mid_x = ( ras.x + to_x + 2 * UPSCALE( control->x ) ) / 4; + mid_y = ( ras.y + to_y + 2 * UPSCALE( control->y ) ) / 4; + + return render_line( RAS_VAR_ mid_x, mid_y ) || + render_line( RAS_VAR_ to_x, to_y ); + } + + arc = ras.bez_stack; + levels = ras.lev_stack; + top = 0; + levels[0] = level; + + arc[0].x = UPSCALE( to->x ); + arc[0].y = UPSCALE( to->y ); + arc[1].x = UPSCALE( control->x ); + arc[1].y = UPSCALE( control->y ); + arc[2].x = ras.x; + arc[2].y = ras.y; + + while ( top >= 0 ) + { + level = levels[top]; + if ( level > 1 ) { + /* check that the arc crosses the current band */ + TPos min, max, y; + + + min = max = arc[0].y; + + y = arc[1].y; + if ( y < min ) { + min = y; + } + if ( y > max ) { + max = y; + } + + y = arc[2].y; + if ( y < min ) { + min = y; + } + if ( y > max ) { + max = y; + } + + if ( TRUNC( min ) >= ras.max_ey || TRUNC( max ) < 0 ) { + goto Draw; + } + + split_conic( arc ); + arc += 2; + top++; + levels[top] = levels[top - 1] = level - 1; + continue; + } + +Draw: + { + TPos to_x, to_y, mid_x, mid_y; + + + to_x = arc[0].x; + to_y = arc[0].y; + mid_x = ( ras.x + to_x + 2 * arc[1].x ) / 4; + mid_y = ( ras.y + to_y + 2 * arc[1].y ) / 4; + + if ( render_line( RAS_VAR_ mid_x, mid_y ) || + render_line( RAS_VAR_ to_x, to_y ) ) { + return 1; + } + + top--; + arc -= 2; + } + } + return 0; +} + + +static +void split_cubic( FT_Vector* base ) { + TPos a, b, c, d; + + + base[6].x = base[3].x; + c = base[1].x; + d = base[2].x; + base[1].x = a = ( base[0].x + c ) / 2; + base[5].x = b = ( base[3].x + d ) / 2; + c = ( c + d ) / 2; + base[2].x = a = ( a + c ) / 2; + base[4].x = b = ( b + c ) / 2; + base[3].x = ( a + b ) / 2; + + base[6].y = base[3].y; + c = base[1].y; + d = base[2].y; + base[1].y = a = ( base[0].y + c ) / 2; + base[5].y = b = ( base[3].y + d ) / 2; + c = ( c + d ) / 2; + base[2].y = a = ( a + c ) / 2; + base[4].y = b = ( b + c ) / 2; + base[3].y = ( a + b ) / 2; +} + + +static +int render_cubic( RAS_ARG_ FT_Vector* control1, + FT_Vector* control2, + FT_Vector* to ) { + TPos dx, dy, da, db; + int top, level; + int* levels; + FT_Vector* arc; + + + dx = DOWNSCALE( ras.x ) + to->x - ( control1->x << 1 ); + if ( dx < 0 ) { + dx = -dx; + } + dy = DOWNSCALE( ras.y ) + to->y - ( control1->y << 1 ); + if ( dy < 0 ) { + dy = -dy; + } + if ( dx < dy ) { + dx = dy; + } + da = dx; + + dx = DOWNSCALE( ras.x ) + to->x - 3 * ( control1->x + control2->x ); + if ( dx < 0 ) { + dx = -dx; + } + dy = DOWNSCALE( ras.y ) + to->y - 3 * ( control1->x + control2->y ); + if ( dy < 0 ) { + dy = -dy; + } + if ( dx < dy ) { + dx = dy; + } + db = dx; + + level = 1; + da = da / ras.cubic_level; + db = db / ras.conic_level; + while ( da > 0 || db > 0 ) + { + da >>= 1; + db >>= 2; + level++; + } + + if ( level <= 1 ) { + TPos to_x, to_y, mid_x, mid_y; + + + to_x = UPSCALE( to->x ); + to_y = UPSCALE( to->y ); + mid_x = ( ras.x + to_x + + 3 * UPSCALE( control1->x + control2->x ) ) / 8; + mid_y = ( ras.y + to_y + + 3 * UPSCALE( control1->y + control2->y ) ) / 8; + + return render_line( RAS_VAR_ mid_x, mid_y ) || + render_line( RAS_VAR_ to_x, to_y ); + } + + arc = ras.bez_stack; + arc[0].x = UPSCALE( to->x ); + arc[0].y = UPSCALE( to->y ); + arc[1].x = UPSCALE( control2->x ); + arc[1].y = UPSCALE( control2->y ); + arc[2].x = UPSCALE( control1->x ); + arc[2].y = UPSCALE( control1->y ); + arc[3].x = ras.x; + arc[3].y = ras.y; + + levels = ras.lev_stack; + top = 0; + levels[0] = level; + + while ( top >= 0 ) + { + level = levels[top]; + if ( level > 1 ) { + /* check that the arc crosses the current band */ + TPos min, max, y; + + + min = max = arc[0].y; + y = arc[1].y; + if ( y < min ) { + min = y; + } + if ( y > max ) { + max = y; + } + y = arc[2].y; + if ( y < min ) { + min = y; + } + if ( y > max ) { + max = y; + } + y = arc[3].y; + if ( y < min ) { + min = y; + } + if ( y > max ) { + max = y; + } + if ( TRUNC( min ) >= ras.max_ey || TRUNC( max ) < 0 ) { + goto Draw; + } + split_cubic( arc ); + arc += 3; + top++; + levels[top] = levels[top - 1] = level - 1; + continue; + } + +Draw: + { + TPos to_x, to_y, mid_x, mid_y; + + + to_x = arc[0].x; + to_y = arc[0].y; + mid_x = ( ras.x + to_x + 3 * ( arc[1].x + arc[2].x ) ) / 8; + mid_y = ( ras.y + to_y + 3 * ( arc[1].y + arc[2].y ) ) / 8; + + if ( render_line( RAS_VAR_ mid_x, mid_y ) || + render_line( RAS_VAR_ to_x, to_y ) ) { + return 1; + } + top--; + arc -= 3; + } + } + return 0; +} + + +/* a macro comparing two cell pointers. Returns true if a <= b. */ +#if 1 + +#define PACK( a ) ( ( (long)( a )->y << 16 ) + ( a )->x ) +#define LESS_THAN( a, b ) ( PACK( a ) < PACK( b ) ) + +#else /* 1 */ + +#define LESS_THAN( a, b ) ( ( a )->y < ( b )->y || \ + ( ( a )->y == ( b )->y && ( a )->x < ( b )->x ) ) + +#endif /* 1 */ + +#define SWAP_CELLS( a, b, temp ) do \ + { \ + temp = *( a ); \ + *( a ) = *( b ); \ + *( b ) = temp; \ + } while ( 0 ) +#define DEBUG_SORT +#define QUICK_SORT + +#ifdef SHELL_SORT + +/* a simple shell sort algorithm that works directly on our */ +/* cells table */ +static +void shell_sort( PCell cells, + int count ) { + PCell i, j, limit = cells + count; + TCell temp; + int gap; + + + /* compute initial gap */ + for ( gap = 0; ++gap < count; gap *= 3 ) + ; + + while ( gap /= 3 ) + { + for ( i = cells + gap; i < limit; i++ ) + { + for ( j = i - gap; ; j -= gap ) + { + PCell k = j + gap; + + + if ( LESS_THAN( j, k ) ) { + break; + } + + SWAP_CELLS( j, k, temp ); + + if ( j < cells + gap ) { + break; + } + } + } + } +} + +#endif /* SHELL_SORT */ + + +#ifdef QUICK_SORT + +/* This is a non-recursive quicksort that directly process our cells */ +/* array. It should be faster than calling the stdlib qsort(), and we */ +/* can even tailor our insertion threshold... */ + +#define QSORT_THRESHOLD 9 /* below this size, a sub-array will be sorted */ + /* through a normal insertion sort */ + +static +void quick_sort( PCell cells, + int count ) { + PCell stack[40]; /* should be enough ;-) */ + PCell* top; /* top of stack */ + PCell base, limit; + TCell temp; + + + limit = cells + count; + base = cells; + top = stack; + + for (;; ) + { + int len = limit - base; + PCell i, j, pivot; + + + if ( len > QSORT_THRESHOLD ) { + /* we use base + len/2 as the pivot */ + pivot = base + len / 2; + SWAP_CELLS( base, pivot, temp ); + + i = base + 1; + j = limit - 1; + + /* now ensure that *i <= *base <= *j */ + if ( LESS_THAN( j, i ) ) { + SWAP_CELLS( i, j, temp ); + } + + if ( LESS_THAN( base, i ) ) { + SWAP_CELLS( base, i, temp ); + } + + if ( LESS_THAN( j, base ) ) { + SWAP_CELLS( base, j, temp ); + } + + for (;; ) + { + do i++;while ( LESS_THAN( i, base ) ); + do j--;while ( LESS_THAN( base, j ) ); + + if ( i > j ) { + break; + } + + SWAP_CELLS( i, j, temp ); + } + + SWAP_CELLS( base, j, temp ); + + /* now, push the largest sub-array */ + if ( j - base > limit - i ) { + top[0] = base; + top[1] = j; + base = i; + } else + { + top[0] = i; + top[1] = limit; + limit = j; + } + top += 2; + } else + { + /* the sub-array is small, perform insertion sort */ + j = base; + i = j + 1; + + for ( ; i < limit; j = i, i++ ) + { + for ( ; LESS_THAN( j + 1, j ); j-- ) + { + SWAP_CELLS( j + 1, j, temp ); + if ( j == base ) { + break; + } + } + } + if ( top > stack ) { + top -= 2; + base = top[0]; + limit = top[1]; + } else { + break; + } + } + } +} + +#endif /* QUICK_SORT */ + + +#ifdef DEBUG_GRAYS +#ifdef DEBUG_SORT + +static +int check_sort( PCell cells, + int count ) { + PCell p, q; + + + for ( p = cells + count - 2; p >= cells; p-- ) + { + q = p + 1; + if ( !LESS_THAN( p, q ) ) { + return 0; + } + } + return 1; +} + +#endif /* DEBUG_SORT */ +#endif /* DEBUG_GRAYS */ + + +static +int Move_To( FT_Vector* to, + FT_Raster raster ) { + TPos x, y; + + + /* record current cell, if any */ + record_cell( (PRaster)raster ); + + /* start to a new position */ + x = UPSCALE( to->x ); + y = UPSCALE( to->y ); + start_cell( (PRaster)raster, TRUNC( x ), TRUNC( y ) ); + ( (PRaster)raster )->x = x; + ( (PRaster)raster )->y = y; + return 0; +} + + +static +int Line_To( FT_Vector* to, + FT_Raster raster ) { + return render_line( (PRaster)raster, + UPSCALE( to->x ), UPSCALE( to->y ) ); +} + + +static +int Conic_To( FT_Vector* control, + FT_Vector* to, + FT_Raster raster ) { + return render_conic( (PRaster)raster, control, to ); +} + + +static +int Cubic_To( FT_Vector* control1, + FT_Vector* control2, + FT_Vector* to, + FT_Raster raster ) { + return render_cubic( (PRaster)raster, control1, control2, to ); +} + + +static +void grays_render_span( int y, + int count, + FT_Span* spans, + PRaster raster ) { + unsigned char* p; + FT_Bitmap* map = &raster->target; + + + /* first of all, compute the scanline offset */ + p = (unsigned char*)map->buffer - y * map->pitch; + if ( map->pitch >= 0 ) { + p += ( map->rows - 1 ) * map->pitch; + } + + for ( ; count > 0; count--, spans++ ) + { + if ( spans->coverage ) +#if 1 + { memset( p + spans->x, (unsigned char)spans->coverage, spans->len );} +#else /* 1 */ + { + q = p + spans->x; + limit = q + spans->len; + for ( ; q < limit; q++ ) + q[0] = (unsigned char)spans->coverage; + } +#endif /* 1 */ + } +} + + +#ifdef DEBUG_GRAYS + +#include + +static +void dump_cells( RAS_ARG ) { + PCell cell, limit; + int y = -1; + + + cell = ras.cells; + limit = cell + ras.num_cells; + + for ( ; cell < limit; cell++ ) + { + if ( cell->y != y ) { + fprintf( stderr, "\n%2d: ", cell->y ); + y = cell->y; + } + fprintf( stderr, "[%d %d %d]", + cell->x, cell->area, cell->cover ); + } + fprintf( stderr, "\n" ); +} + +#endif /* DEBUG_GRAYS */ + + +static +void grays_hline( RAS_ARG_ TScan x, + TScan y, + TPos area, + int acount ) { + FT_Span* span; + int count; + int coverage; + + + /* compute the coverage line's coverage, depending on the */ + /* outline fill rule */ + /* */ + /* the coverage percentage is area/(PIXEL_BITS*PIXEL_BITS*2) */ + /* */ + coverage = area >> ( PIXEL_BITS * 2 + 1 - 8 ); /* use range 0..256 */ + + if ( ras.outline.flags & ft_outline_even_odd_fill ) { + if ( coverage < 0 ) { + coverage = -coverage; + } + + while ( coverage >= 512 ) + coverage -= 512; + + if ( coverage > 256 ) { + coverage = 512 - coverage; + } else if ( coverage == 256 ) { + coverage = 255; + } + } else + { + /* normal non-zero winding rule */ + if ( coverage < 0 ) { + coverage = -coverage; + } + + if ( coverage >= 256 ) { + coverage = 255; + } + } + + y += ras.min_ey; + x += ras.min_ex; + + if ( coverage ) { + /* see if we can add this span to the current list */ + count = ras.num_gray_spans; + span = ras.gray_spans + count - 1; + if ( count > 0 && + ras.span_y == y && + (int)span->x + span->len == (int)x && + span->coverage == coverage ) { + span->len += acount; + return; + } + + if ( ras.span_y != y || count >= FT_MAX_GRAY_SPANS ) { + if ( ras.render_span ) { + ras.render_span( ras.span_y, count, ras.gray_spans, + ras.render_span_data ); + } + /* ras.render_span( span->y, ras.gray_spans, count ); */ + +#ifdef DEBUG_GRAYS + + if ( ras.span_y >= 0 ) { + int n; + + + fprintf( stderr, "y=%3d ", ras.span_y ); + span = ras.gray_spans; + for ( n = 0; n < count; n++, span++ ) + fprintf( stderr, "[%d..%d]:%02x ", + span->x, span->x + span->len - 1, span->coverage ); + fprintf( stderr, "\n" ); + } + +#endif /* DEBUG_GRAYS */ + + ras.num_gray_spans = 0; + ras.span_y = y; + + count = 0; + span = ras.gray_spans; + } else { + span++; + } + + /* add a gray span to the current list */ + span->x = (short)x; + span->len = (unsigned short)acount; + span->coverage = (unsigned char)coverage; + ras.num_gray_spans++; + } +} + + +static +void grays_sweep( RAS_ARG_ FT_Bitmap* target ) { + TScan x, y, cover, area; + PCell start, cur, limit; + + FT_UNUSED( target ); + + + cur = ras.cells; + limit = cur + ras.num_cells; + + cover = 0; + ras.span_y = -1; + ras.num_gray_spans = 0; + + for (;; ) + { + start = cur; + y = start->y; + x = start->x; + + area = start->area; + cover += start->cover; + + /* accumulate all start cells */ + for (;; ) + { + ++cur; + if ( cur >= limit || cur->y != start->y || cur->x != start->x ) { + break; + } + + area += cur->area; + cover += cur->cover; + } + + /* if the start cell has a non-null area, we must draw an */ + /* individual gray pixel there */ + if ( area && x >= 0 ) { + grays_hline( RAS_VAR_ x, y, cover * ( ONE_PIXEL * 2 ) - area, 1 ); + x++; + } + + if ( x < 0 ) { + x = 0; + } + + if ( cur < limit && start->y == cur->y ) { + /* draw a gray span between the start cell and the current one */ + if ( cur->x > x ) { + grays_hline( RAS_VAR_ x, y, + cover * ( ONE_PIXEL * 2 ), cur->x - x ); + } + } else + { + /* draw a gray span until the end of the clipping region */ + if ( cover && x < ras.max_ex - ras.min_ex ) { + grays_hline( RAS_VAR_ x, y, + cover * ( ONE_PIXEL * 2 ), + ras.max_ex - x - ras.min_ex ); + } + cover = 0; + } + + if ( cur >= limit ) { + break; + } + } + + if ( ras.render_span && ras.num_gray_spans > 0 ) { + ras.render_span( ras.span_y, ras.num_gray_spans, + ras.gray_spans, ras.render_span_data ); + } + +#ifdef DEBUG_GRAYS + + { + int n; + FT_Span* span; + + + fprintf( stderr, "y=%3d ", ras.span_y ); + span = ras.gray_spans; + for ( n = 0; n < ras.num_gray_spans; n++, span++ ) + fprintf( stderr, "[%d..%d]:%02x ", + span->x, span->x + span->len - 1, span->coverage ); + fprintf( stderr, "\n" ); + } + +#endif /* DEBUG_GRAYS */ + +} + + +#ifdef _STANDALONE_ + +/*************************************************************************/ +/* */ +/* The following function should only compile in stand_alone mode, */ +/* i.e., when building this component without the rest of FreeType. */ +/* */ +/*************************************************************************/ + +/*************************************************************************/ +/* */ +/* */ +/* FT_Outline_Decompose */ +/* */ +/* */ +/* Walks over an outline's structure to decompose it into individual */ +/* segments and Bezier arcs. This function is also able to emit */ +/* `move to' and `close to' operations to indicate the start and end */ +/* of new contours in the outline. */ +/* */ +/* */ +/* outline :: A pointer to the source target. */ +/* */ +/* interface :: A table of `emitters', i.e,. function pointers called */ +/* during decomposition to indicate path operations. */ +/* */ +/* user :: A typeless pointer which is passed to each emitter */ +/* during the decomposition. It can be used to store */ +/* the state during the decomposition. */ +/* */ +/* */ +/* Error code. 0 means sucess. */ +/* */ +static +int FT_Outline_Decompose( FT_Outline* outline, + FT_Outline_Funcs* interface, + void* user ) { +#undef SCALED +#define SCALED( x ) ( ( ( x ) << shift ) - delta ) + + FT_Vector v_last; + FT_Vector v_control; + FT_Vector v_start; + + FT_Vector* point; + FT_Vector* limit; + char* tags; + + int n; /* index of contour in outline */ + int first; /* index of first point in contour */ + int error; + char tag; /* current point's state */ + + int shift = interface->shift; + FT_Pos delta = interface->delta; + + + first = 0; + + for ( n = 0; n < outline->n_contours; n++ ) + { + int last; /* index of last point in contour */ + + + last = outline->contours[n]; + limit = outline->points + last; + + v_start = outline->points[first]; + v_last = outline->points[last]; + + v_start.x = SCALED( v_start.x ); v_start.y = SCALED( v_start.y ); + v_last.x = SCALED( v_last.x ); v_last.y = SCALED( v_last.y ); + + v_control = v_start; + + point = outline->points + first; + tags = outline->tags + first; + tag = FT_CURVE_TAG( tags[0] ); + + /* A contour cannot start with a cubic control point! */ + if ( tag == FT_Curve_Tag_Cubic ) { + goto Invalid_Outline; + } + + /* check first point to determine origin */ + if ( tag == FT_Curve_Tag_Conic ) { + /* first point is conic control. Yes, this happens. */ + if ( FT_CURVE_TAG( outline->tags[last] ) == FT_Curve_Tag_On ) { + /* start at last point if it is on the curve */ + v_start = v_last; + limit--; + } else + { + /* if both first and last points are conic, */ + /* start at their middle and record its position */ + /* for closure */ + v_start.x = ( v_start.x + v_last.x ) / 2; + v_start.y = ( v_start.y + v_last.y ) / 2; + + v_last = v_start; + } + point--; + tags--; + } + + error = interface->move_to( &v_start, user ); + if ( error ) { + goto Exit; + } + + while ( point < limit ) + { + point++; + tags++; + + tag = FT_CURVE_TAG( tags[0] ); + switch ( tag ) + { + case FT_Curve_Tag_On: /* emit a single line_to */ + { + FT_Vector vec; + + + vec.x = SCALED( point->x ); + vec.y = SCALED( point->y ); + + error = interface->line_to( &vec, user ); + if ( error ) { + goto Exit; + } + continue; + } + + case FT_Curve_Tag_Conic: /* consume conic arcs */ + { + v_control.x = SCALED( point->x ); + v_control.y = SCALED( point->y ); + +Do_Conic: + if ( point < limit ) { + FT_Vector vec; + FT_Vector v_middle; + + + point++; + tags++; + tag = FT_CURVE_TAG( tags[0] ); + + vec.x = SCALED( point->x ); + vec.y = SCALED( point->y ); + + if ( tag == FT_Curve_Tag_On ) { + error = interface->conic_to( &v_control, &vec, user ); + if ( error ) { + goto Exit; + } + continue; + } + + if ( tag != FT_Curve_Tag_Conic ) { + goto Invalid_Outline; + } + + v_middle.x = ( v_control.x + vec.x ) / 2; + v_middle.y = ( v_control.y + vec.y ) / 2; + + error = interface->conic_to( &v_control, &v_middle, user ); + if ( error ) { + goto Exit; + } + + v_control = vec; + goto Do_Conic; + } + + error = interface->conic_to( &v_control, &v_start, user ); + goto Close; + } + + default: /* FT_Curve_Tag_Cubic */ + { + FT_Vector vec1, vec2; + + + if ( point + 1 > limit || + FT_CURVE_TAG( tags[1] ) != FT_Curve_Tag_Cubic ) { + goto Invalid_Outline; + } + + point += 2; + tags += 2; + + vec1.x = SCALED( point[-2].x ); vec1.y = SCALED( point[-2].y ); + vec2.x = SCALED( point[-1].x ); vec2.y = SCALED( point[-1].y ); + + if ( point <= limit ) { + FT_Vector vec; + + + vec.x = SCALED( point->x ); + vec.y = SCALED( point->y ); + + error = interface->cubic_to( &vec1, &vec2, &vec, user ); + if ( error ) { + goto Exit; + } + continue; + } + + error = interface->cubic_to( &vec1, &vec2, &v_start, user ); + goto Close; + } + } + } + + /* close the contour with a line segment */ + error = interface->line_to( &v_start, user ); + +Close: + if ( error ) { + goto Exit; + } + + first = last + 1; + } + + return 0; + +Exit: + return error; + +Invalid_Outline: + return ErrRaster_Invalid_Outline; +} + +#endif /* _STANDALONE_ */ + + +typedef struct TBand_ +{ + FT_Pos min, max; + +} TBand; + + +static +int grays_convert_glyph( RAS_ARG_ FT_Outline* outline ) { + static + FT_Outline_Funcs interface = + { + (FT_Outline_MoveTo_Func) Move_To, + (FT_Outline_LineTo_Func) Line_To, + (FT_Outline_ConicTo_Func)Conic_To, + (FT_Outline_CubicTo_Func)Cubic_To, + 0, + 0 + }; + + TBand bands[40], *band; + int n, num_bands; + TPos min, max, max_y; + + + /* Set up state in the raster object */ + compute_cbox( RAS_VAR_ outline ); + + /* clip to target bitmap, exit if nothing to do */ + if ( ras.max_ex <= 0 || ras.min_ex >= ras.target.width || + ras.max_ey <= 0 || ras.min_ey >= ras.target.rows ) { + return 0; + } + + if ( ras.min_ex < 0 ) { + ras.min_ex = 0; + } + if ( ras.min_ey < 0 ) { + ras.min_ey = 0; + } + + if ( ras.max_ex > ras.target.width ) { + ras.max_ex = ras.target.width; + } + if ( ras.max_ey > ras.target.rows ) { + ras.max_ey = ras.target.rows; + } + + /* simple heuristic used to speed-up the bezier decomposition -- see */ + /* the code in render_conic() and render_cubic() for more details */ + ras.conic_level = 32; + ras.cubic_level = 16; + + { + int level = 0; + + + if ( ras.max_ex > 24 || ras.max_ey > 24 ) { + level++; + } + if ( ras.max_ex > 120 || ras.max_ey > 120 ) { + level += 2; + } + + ras.conic_level <<= level; + ras.cubic_level <<= level; + } + + /* setup vertical bands */ + num_bands = ( ras.max_ey - ras.min_ey ) / ras.band_size; + if ( num_bands == 0 ) { + num_bands = 1; + } + if ( num_bands >= 39 ) { + num_bands = 39; + } + + ras.band_shoot = 0; + + min = ras.min_ey; + max_y = ras.max_ey; + + for ( n = 0; n < num_bands; n++, min = max ) + { + max = min + ras.band_size; + if ( n == num_bands - 1 || max > max_y ) { + max = max_y; + } + + bands[0].min = min; + bands[0].max = max; + band = bands; + + while ( band >= bands ) + { + FT_Pos bottom, top, middle; + int error; + + + ras.num_cells = 0; + ras.invalid = 1; + ras.min_ey = band->min; + ras.max_ey = band->max; + + error = FT_Outline_Decompose( outline, &interface, &ras ) || + record_cell( RAS_VAR ); + + if ( !error ) { +#ifdef SHELL_SORT + shell_sort( ras.cells, ras.num_cells ); +#else + quick_sort( ras.cells, ras.num_cells ); +#endif + +#ifdef DEBUG_GRAYS + check_sort( ras.cells, ras.num_cells ); + dump_cells( RAS_VAR ); +#endif + + grays_sweep( RAS_VAR_ & ras.target ); + band--; + continue; + } + + /* render pool overflow, we will reduce the render band by half */ + bottom = band->min; + top = band->max; + middle = bottom + ( ( top - bottom ) >> 1 ); + + /* waoow! This is too complex for a single scanline, something */ + /* must be really rotten here! */ + if ( middle == bottom ) { +#ifdef DEBUG_GRAYS + fprintf( stderr, "Rotten glyph!\n" ); +#endif + return 1; + } + + if ( bottom - top >= ras.band_size ) { + ras.band_shoot++; + } + + band[1].min = bottom; + band[1].max = middle; + band[0].min = middle; + band[0].max = top; + band++; + } + } + + if ( ras.band_shoot > 8 && ras.band_size > 16 ) { + ras.band_size = ras.band_size / 2; + } + + return 0; +} + + +extern +int grays_raster_render( PRaster raster, + FT_Raster_Params* params ) { + FT_Outline* outline = (FT_Outline*)params->source; + FT_Bitmap* target_map = params->target; + + + if ( !raster || !raster->cells || !raster->max_cells ) { + return -1; + } + + /* return immediately if the outline is empty */ + if ( outline->n_points == 0 || outline->n_contours <= 0 ) { + return 0; + } + + if ( !outline || !outline->contours || !outline->points ) { + return ErrRaster_Invalid_Outline; + } + + if ( outline->n_points != + outline->contours[outline->n_contours - 1] + 1 ) { + return ErrRaster_Invalid_Outline; + } + + if ( !target_map || !target_map->buffer ) { + return -1; + } + + /* XXX: this version does not support monochrome rendering yet! */ + if ( !( params->flags & ft_raster_flag_aa ) ) { + return ErrRaster_Invalid_Mode; + } + + ras.outline = *outline; + ras.target = *target_map; + ras.num_cells = 0; + ras.invalid = 1; + + ras.render_span = (FT_Raster_Span_Func)grays_render_span; + ras.render_span_data = &ras; + + if ( params->flags & ft_raster_flag_direct ) { + ras.render_span = (FT_Raster_Span_Func)params->gray_spans; + ras.render_span_data = params->user; + } + + return grays_convert_glyph( (PRaster)raster, outline ); +} + + +/**** RASTER OBJECT CREATION: In standalone mode, we simply use *****/ +/**** a static object. *****/ + +#ifdef _STANDALONE_ + +static +int grays_raster_new( void* memory, + FT_Raster* araster ) { + static TRaster the_raster; + + FT_UNUSED( memory ); + + + *araster = ( FT_Raster ) & the_raster; + memset( &the_raster, 0, sizeof( the_raster ) ); + + return 0; +} + + +static +void grays_raster_done( FT_Raster raster ) { + /* nothing */ + FT_UNUSED( raster ); +} + +#else /* _STANDALONE_ */ + +static +int grays_raster_new( FT_Memory memory, + FT_Raster* araster ) { + FT_Error error; + PRaster raster; + + + *araster = 0; + if ( !ALLOC( raster, sizeof( TRaster ) ) ) { + raster->memory = memory; + *araster = (FT_Raster)raster; + } + + return error; +} + + +static +void grays_raster_done( FT_Raster raster ) { + FT_Memory memory = (FT_Memory)( (PRaster)raster )->memory; + + + FREE( raster ); +} + +#endif /* _STANDALONE_ */ + + +static +void grays_raster_reset( FT_Raster raster, + const char* pool_base, + long pool_size ) { + PRaster rast = (PRaster)raster; + + + if ( raster && pool_base && pool_size >= 4096 ) { + init_cells( rast, (char*)pool_base, pool_size ); + } + + rast->band_size = ( pool_size / sizeof( TCell ) ) / 8; +} + + +FT_Raster_Funcs ft_grays_raster = +{ + ft_glyph_format_outline, + + (FT_Raster_New_Func) grays_raster_new, + (FT_Raster_Reset_Func) grays_raster_reset, + (FT_Raster_Set_Mode_Func)0, + (FT_Raster_Render_Func) grays_raster_render, + (FT_Raster_Done_Func) grays_raster_done +}; + + +/* END */ diff --git a/Projects/Android/jni/rtcw/src/ft2/ftgrays.h b/Projects/Android/jni/rtcw/src/ft2/ftgrays.h new file mode 100644 index 0000000..3990d5e --- /dev/null +++ b/Projects/Android/jni/rtcw/src/ft2/ftgrays.h @@ -0,0 +1,48 @@ +/***************************************************************************/ +/* */ +/* ftgrays.h */ +/* */ +/* FreeType smooth renderer declaration */ +/* */ +/* Copyright 1996-2000 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + +#ifndef FTGRAYS_H +#define FTGRAYS_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include "ftimage.h" + +/*************************************************************************/ +/* */ +/* To make ftgrays.h independent from configuration files we check */ +/* whether FT_EXPORT_DEF has been defined already. */ +/* */ +/* On some systems and compilers (Win32 mostly), an extra keyword is */ +/* necessary to compile the library as a DLL. */ +/* */ +#ifndef FT_EXPORT_VAR +#define FT_EXPORT_VAR( x ) extern x +#endif + +FT_EXPORT_VAR( FT_Raster_Funcs ) ft_grays_raster; + +#ifdef __cplusplus +} +#endif + +#endif /* FTGRAYS_H */ + + +/* END */ diff --git a/Projects/Android/jni/rtcw/src/ft2/ftimage.h b/Projects/Android/jni/rtcw/src/ft2/ftimage.h new file mode 100644 index 0000000..e0acb64 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/ft2/ftimage.h @@ -0,0 +1,1003 @@ +/***************************************************************************/ +/* */ +/* ftimage.h */ +/* */ +/* FreeType glyph image formats and default raster interface */ +/* (specification). */ +/* */ +/* Copyright 1996-2000 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + +/*************************************************************************/ +/* */ +/* Note: A `raster' is simply a scan-line converter, used to render */ +/* FT_Outlines into FT_Bitmaps. */ +/* */ +/*************************************************************************/ + + +#ifndef FTIMAGE_H +#define FTIMAGE_H + + +#ifdef __cplusplus +extern "C" { +#endif + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Pos */ +/* */ +/* */ +/* The type FT_Pos is a 32-bit integer used to store vectorial */ +/* coordinates. Depending on the context, these can represent */ +/* distances in integer font units, or 26.6 fixed float pixel */ +/* coordinates. */ +/* */ +typedef signed long FT_Pos; + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Vector */ +/* */ +/* */ +/* A simple structure used to store a 2D vector; coordinates are of */ +/* the FT_Pos type. */ +/* */ +/* */ +/* x :: The horizontal coordinate. */ +/* y :: The vertical coordinate. */ +/* */ +typedef struct FT_Vector_ +{ + FT_Pos x; + FT_Pos y; + +} FT_Vector; + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Pixel_Mode */ +/* */ +/* */ +/* An enumeration type used to describe the format of pixels in a */ +/* given bitmap. Note that additional formats may be added in the */ +/* future. */ +/* */ +/* */ +/* ft_pixel_mode_mono :: A monochrome bitmap (1 bit/pixel). */ +/* */ +/* ft_pixel_mode_grays :: An 8-bit gray-levels bitmap. Note that the */ +/* total number of gray levels is given in the */ +/* `num_grays' field of the FT_Bitmap */ +/* structure. */ +/* */ +/* ft_pixel_mode_pal2 :: A 2-bit paletted bitmap. */ +/* Currently unused by FreeType. */ +/* */ +/* ft_pixel_mode_pal4 :: A 4-bit paletted bitmap. */ +/* Currently unused by FreeType. */ +/* */ +/* ft_pixel_mode_pal8 :: An 8-bit paletted bitmap. */ +/* Currently unused by FreeType. */ +/* */ +/* ft_pixel_mode_rgb15 :: A 15-bit RGB bitmap. Uses 5:5:5 encoding. */ +/* Currently unused by FreeType. */ +/* */ +/* ft_pixel_mode_rgb16 :: A 16-bit RGB bitmap. Uses 5:6:5 encoding. */ +/* Currently unused by FreeType. */ +/* */ +/* ft_pixel_mode_rgb24 :: A 24-bit RGB bitmap. */ +/* Currently unused by FreeType. */ +/* */ +/* ft_pixel_mode_rgb32 :: A 32-bit RGB bitmap. */ +/* Currently unused by FreeType. */ +/* */ +/* */ +/* Some anti-aliased bitmaps might be embedded in TrueType fonts */ +/* using formats pal2 or pal4, though no fonts presenting those have */ +/* been found to date. */ +/* */ +typedef enum FT_Pixel_Mode_ +{ + ft_pixel_mode_none = 0, + ft_pixel_mode_mono, + ft_pixel_mode_grays, + ft_pixel_mode_pal2, + ft_pixel_mode_pal4, + ft_pixel_mode_pal8, + ft_pixel_mode_rgb15, + ft_pixel_mode_rgb16, + ft_pixel_mode_rgb24, + ft_pixel_mode_rgb32, + + ft_pixel_mode_max /* do not remove */ + +} FT_Pixel_Mode; + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Palette_Mode */ +/* */ +/* */ +/* An enumeration type used to describe the format of a bitmap */ +/* palette, used with ft_pixel_mode_pal4 and ft_pixel_mode_pal8. */ +/* */ +/* */ +/* ft_palette_mode_rgb :: The palette is an array of 3-bytes RGB */ +/* records. */ +/* */ +/* ft_palette_mode_rgba :: The palette is an array of 4-bytes RGBA */ +/* records. */ +/* */ +/* */ +/* As ft_pixel_mode_pal2, pal4 and pal8 are currently unused by */ +/* FreeType, these types are not handled by the library itself. */ +/* */ +typedef enum FT_Palette_Mode_ +{ + ft_palette_mode_rgb = 0, + ft_palette_mode_rgba, + + ft_palettte_mode_max /* do not remove */ + +} FT_Palette_Mode; + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Bitmap */ +/* */ +/* */ +/* A structure used to describe a bitmap or pixmap to the raster. */ +/* Note that we now manage pixmaps of various depths through the */ +/* `pixel_mode' field. */ +/* */ +/* */ +/* rows :: The number of bitmap rows. */ +/* */ +/* width :: The number of pixels in bitmap row. */ +/* */ +/* pitch :: The pitch's absolute value is the number of bytes */ +/* taken by one bitmap row, including padding. */ +/* However, the pitch is positive when the bitmap has */ +/* a `down' flow, and negative when it has an `up' */ +/* flow. In all cases, the pitch is an offset to add */ +/* to a bitmap pointer in order to go down one row. */ +/* */ +/* buffer :: A typeless pointer to the bitmap buffer. This */ +/* value should be aligned on 32-bit boundaries in */ +/* most cases. */ +/* */ +/* num_grays :: This field is only used with */ +/* `ft_pixel_mode_grays'; it gives the number of gray */ +/* levels used in the bitmap. */ +/* */ +/* pixel_mode :: The pixel_mode, i.e., how pixel bits are stored. */ +/* */ +/* palette_mode :: This field is only used with paletted pixel modes; */ +/* it indicates how the palette is stored. */ +/* */ +/* palette :: A typeless pointer to the bitmap palette; only */ +/* used for paletted pixel modes. */ +/* */ +/* */ +/* For now, the only pixel mode supported by FreeType are mono and */ +/* grays. However, drivers might be added in the future to support */ +/* more `colorful' options. */ +/* */ +/* When using pixel modes pal2, pal4 and pal8 with a void `palette' */ +/* field, a gray pixmap with respectively 4, 16, and 256 levels of */ +/* gray is assumed. This, in order to be compatible with some */ +/* embedded bitmap formats defined in the TrueType specification. */ +/* */ +/* Note that no font was found presenting such embedded bitmaps, so */ +/* this is currently completely unhandled by the library. */ +/* */ +typedef struct FT_Bitmap_ +{ + int rows; + int width; + int pitch; + unsigned char* buffer; + short num_grays; + char pixel_mode; + char palette_mode; + void* palette; + +} FT_Bitmap; + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Outline */ +/* */ +/* */ +/* This structure is used to describe an outline to the scan-line */ +/* converter. */ +/* */ +/* */ +/* n_contours :: The number of contours in the outline. */ +/* */ +/* n_points :: The number of points in the outline. */ +/* */ +/* points :: A pointer to an array of `n_points' FT_Vector */ +/* elements, giving the outline's point coordinates. */ +/* */ +/* tags :: A pointer to an array of `n_points' chars, giving */ +/* giving each outline point's type. If bit 0 is */ +/* unset, the point is 'off' the curve, i.e. a Bezier */ +/* control point, while it is `on' when unset. */ +/* */ +/* Bit 1 is meaningful for `off' points only. If set, */ +/* it indicates a third-order Bezier arc control point; */ +/* and a second-order control point if unset. */ +/* */ +/* contours :: An array of `n_contours' shorts, giving the end */ +/* point of each contour within the outline. For */ +/* example, the first contour is defined by the points */ +/* `0' to `contours[0]', the second one is defined by */ +/* the points `contours[0]+1' to `contours[1]', etc. */ +/* */ +/* flags :: A set of bit flags used to characterize the outline */ +/* and give hints to the scan-converter and hinter on */ +/* how to convert/grid-fit it. See FT_Outline_Flags. */ +/* */ +typedef struct FT_Outline_ +{ + short n_contours; /* number of contours in glyph */ + short n_points; /* number of points in the glyph */ + + FT_Vector* points; /* the outline's points */ + char* tags; /* the points flags */ + short* contours; /* the contour end points */ + + int flags; /* outline masks */ + +} FT_Outline; + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Outline_Flags */ +/* */ +/* */ +/* A simple type used to enumerates the flags in an outline's */ +/* `outline_flags' field. */ +/* */ +/* */ +/* ft_outline_owner :: If set, this flag indicates that the */ +/* outline's field arrays (i.e. */ +/* `points', `flags' & `contours') are */ +/* `owned' by the outline object, and */ +/* should thus be freed when it is */ +/* destroyed. */ +/* */ +/* ft_outline_even_odd_fill :: By default, outlines are filled using */ +/* the non-zero winding rule. If set to */ +/* 1, the outline will be filled using */ +/* the even-odd fill rule (only works */ +/* with the smooth raster). */ +/* */ +/* ft_outline_reverse_fill :: By default, outside contours of an */ +/* outline are oriented in clock-wise */ +/* direction, as defined in the TrueType */ +/* specification. This flag is set if */ +/* the outline uses the opposite */ +/* direction (typically for Type 1 */ +/* fonts). This flag is ignored by the */ +/* scan-converter. However, it is very */ +/* important for the auto-hinter. */ +/* */ +/* ft_outline_ignore_dropouts :: By default, the scan converter will */ +/* try to detect drop-outs in an outline */ +/* and correct the glyph bitmap to */ +/* ensure consistent shape continuity. */ +/* If set, this flag hints the scan-line */ +/* converter to ignore such cases. */ +/* */ +/* ft_outline_high_precision :: This flag indicates that the */ +/* scan-line converter should try to */ +/* convert this outline to bitmaps with */ +/* the highest possible quality. It is */ +/* typically set for small character */ +/* sizes. Note that this is only a */ +/* hint, that might be completely */ +/* ignored by a given scan-converter. */ +/* */ +/* ft_outline_single_pass :: This flag is set to force a given */ +/* scan-converter to only use a single */ +/* pass over the outline to render a */ +/* bitmap glyph image. Normally, it is */ +/* set for very large character sizes. */ +/* It is only a hint, that might be */ +/* completely ignored by a given */ +/* scan-converter. */ +/* */ +typedef enum FT_Outline_Flags_ +{ + ft_outline_none = 0, + ft_outline_owner = 1, + ft_outline_even_odd_fill = 2, + ft_outline_reverse_fill = 4, + ft_outline_ignore_dropouts = 8, + ft_outline_high_precision = 256, + ft_outline_single_pass = 512 + +} FT_Outline_Flags; + + +#define FT_CURVE_TAG( flag ) ( flag & 3 ) + +#define FT_Curve_Tag_On 1 +#define FT_Curve_Tag_Conic 0 +#define FT_Curve_Tag_Cubic 2 + +#define FT_Curve_Tag_Touch_X 8 /* reserved for the TrueType hinter */ +#define FT_Curve_Tag_Touch_Y 16 /* reserved for the TrueType hinter */ + +#define FT_Curve_Tag_Touch_Both ( FT_Curve_Tag_Touch_X | \ + FT_Curve_Tag_Touch_Y ) + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Outline_MoveTo_Func */ +/* */ +/* */ +/* A function pointer type used to describe the signature of a `move */ +/* to' function during outline walking/decomposition. */ +/* */ +/* A `move to' is emitted to start a new contour in an outline. */ +/* */ +/* */ +/* to :: A pointer to the target point of the `move to'. */ +/* */ +/* user :: A typeless pointer which is passed from the caller of the */ +/* decomposition function. */ +/* */ +/* */ +/* Error code. 0 means success. */ +/* */ +typedef int ( *FT_Outline_MoveTo_Func )( FT_Vector* to, + void* user ); + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Outline_LineTo_Func */ +/* */ +/* */ +/* A function pointer type used to describe the signature of a `line */ +/* to' function during outline walking/decomposition. */ +/* */ +/* A `line to' is emitted to indicate a segment in the outline. */ +/* */ +/* */ +/* to :: A pointer to the target point of the `line to'. */ +/* */ +/* user :: A typeless pointer which is passed from the caller of the */ +/* decomposition function. */ +/* */ +/* */ +/* Error code. 0 means success. */ +/* */ +typedef int ( *FT_Outline_LineTo_Func )( FT_Vector* to, + void* user ); + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Outline_ConicTo_Func */ +/* */ +/* */ +/* A function pointer type use to describe the signature of a `conic */ +/* to' function during outline walking/decomposition. */ +/* */ +/* A `conic to' is emitted to indicate a second-order Bezier arc in */ +/* the outline. */ +/* */ +/* */ +/* control :: An intermediate control point between the last position */ +/* and the new target in `to'. */ +/* */ +/* to :: A pointer to the target end point of the conic arc. */ +/* */ +/* user :: A typeless pointer which is passed from the caller of */ +/* the decomposition function. */ +/* */ +/* */ +/* Error code. 0 means success. */ +/* */ +typedef int ( *FT_Outline_ConicTo_Func )( FT_Vector* control, + FT_Vector* to, + void* user ); + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Outline_CubicTo_Func */ +/* */ +/* */ +/* A function pointer type used to describe the signature of a `cubic */ +/* to' function during outline walking/decomposition. */ +/* */ +/* A `cubic to' is emitted to indicate a third-order Bezier arc. */ +/* */ +/* */ +/* control1 :: A pointer to the first Bezier control point. */ +/* */ +/* control2 :: A pointer to the second Bezier control point. */ +/* */ +/* to :: A pointer to the target end point. */ +/* */ +/* user :: A typeless pointer which is passed from the caller of */ +/* the decomposition function. */ +/* */ +/* */ +/* Error code. 0 means success. */ +/* */ +typedef int ( *FT_Outline_CubicTo_Func )( FT_Vector* control1, + FT_Vector* control2, + FT_Vector* to, + void* user ); + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Outline_Funcs */ +/* */ +/* */ +/* A structure to hold various function pointers used during outline */ +/* decomposition in order to emit segments, conic, and cubic Beziers, */ +/* as well as `move to' and `close to' operations. */ +/* */ +/* */ +/* move_to :: The `move to' emitter. */ +/* */ +/* line_to :: The segment emitter. */ +/* */ +/* conic_to :: The second-order Bezier arc emitter. */ +/* */ +/* cubic_to :: The third-order Bezier arc emitter. */ +/* */ +/* shift :: The shift that is applied to coordinates before they */ +/* are sent to the emitter. */ +/* */ +/* delta :: The delta that is applied to coordinates before they */ +/* are sent to the emitter, but after the shift. */ +/* */ +/* */ +/* The point coordinates sent to the emitters are the transformed */ +/* version of the original coordinates (this is important for high */ +/* accuracy during scan-conversion). The transformation is simple: */ +/* */ +/* x' = (x << shift) - delta */ +/* y' = (x << shift) - delta */ +/* */ +/* Set the value of `shift' and `delta' to 0 to get the original */ +/* point coordinates. */ +/* */ +typedef struct FT_Outline_Funcs_ +{ + FT_Outline_MoveTo_Func move_to; + FT_Outline_LineTo_Func line_to; + FT_Outline_ConicTo_Func conic_to; + FT_Outline_CubicTo_Func cubic_to; + + int shift; + FT_Pos delta; + +} FT_Outline_Funcs; + + +/*************************************************************************/ +/* */ +/* */ +/* FT_IMAGE_TAG */ +/* */ +/* */ +/* This macro converts four letter tags into an unsigned long. */ +/* */ +#define FT_IMAGE_TAG( _x1, _x2, _x3, _x4 ) \ + ( ( (unsigned long)_x1 << 24 ) | \ + ( (unsigned long)_x2 << 16 ) | \ + ( (unsigned long)_x3 << 8 ) | \ + (unsigned long)_x4 ) + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Glyph_Format */ +/* */ +/* */ +/* An enumeration type used to describe the format of a given glyph */ +/* image. Note that this version of FreeType only supports two image */ +/* formats, even though future font drivers will be able to register */ +/* their own format. */ +/* */ +/* */ +/* ft_glyph_format_composite :: The glyph image is a composite of */ +/* several other images. This glyph */ +/* format is _only_ used with the */ +/* FT_LOAD_FLAG_NO_RECURSE flag (XXX: */ +/* Which is currently unimplemented). */ +/* */ +/* ft_glyph_format_bitmap :: The glyph image is a bitmap, and can */ +/* be described as a FT_Bitmap. */ +/* */ +/* ft_glyph_format_outline :: The glyph image is a vectorial image */ +/* made of bezier control points, and */ +/* can be described as a FT_Outline. */ +/* */ +/* ft_glyph_format_plotter :: The glyph image is a vectorial image */ +/* made of plotter lines (some T1 fonts */ +/* like Hershey contain glyph in this */ +/* format). */ +/* */ +typedef enum FT_Glyph_Format_ +{ + ft_glyph_format_none = 0, + ft_glyph_format_composite = FT_IMAGE_TAG( 'c', 'o', 'm', 'p' ), + ft_glyph_format_bitmap = FT_IMAGE_TAG( 'b', 'i', 't', 's' ), + ft_glyph_format_outline = FT_IMAGE_TAG( 'o', 'u', 't', 'l' ), + ft_glyph_format_plotter = FT_IMAGE_TAG( 'p', 'l', 'o', 't' ) + +} FT_Glyph_Format; + + +/*************************************************************************/ +/*************************************************************************/ +/*************************************************************************/ +/***** *****/ +/***** R A S T E R D E F I N I T I O N S *****/ +/***** *****/ +/*************************************************************************/ +/*************************************************************************/ +/*************************************************************************/ + + +/*************************************************************************/ +/* */ +/* A raster is a scan converter, in charge of rendering an outline into */ +/* a a bitmap. This section contains the public API for rasters. */ +/* */ +/* Note that in FreeType 2, all rasters are now encapsulated within */ +/* specific modules called `renderers'. See `freetype/ftrender.h' for */ +/* more details on renderers. */ +/* */ +/*************************************************************************/ + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Raster */ +/* */ +/* */ +/* A handle (pointer) to a raster object. Each object can be used */ +/* independently to convert an outline into a bitmap or pixmap. */ +/* */ +typedef struct FT_RasterRec_* FT_Raster; + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Span */ +/* */ +/* */ +/* A structure used to model a single span of gray (or black) pixels */ +/* when rendering a monochrome or anti-aliased bitmap. */ +/* */ +/* */ +/* x :: The span's horizontal start position. */ +/* */ +/* len :: The span's length in pixels. */ +/* */ +/* coverage :: The span color/coverage, ranging from 0 (background) */ +/* to 255 (foreground). Only used for anti-aliased */ +/* rendering. */ +/* */ +/* */ +/* This structure is used by the span drawing callback type named */ +/* FT_Raster_Span_Func(), which takes the y-coordinate of the span as */ +/* a parameter. */ +/* */ +/* The coverage value is always between 0 and 255, even if the number */ +/* of gray levels have been set through FT_Set_Gray_Levels(). */ +/* */ +typedef struct FT_Span_ +{ + short x; + unsigned short len; + unsigned char coverage; + +} FT_Span; + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Raster_Span_Func */ +/* */ +/* */ +/* A function used as a call-back by the anti-aliased renderer in */ +/* order to let client applications draw themselves the gray pixel */ +/* spans on each scan line. */ +/* */ +/* */ +/* y :: The scanline's y-coordinate. */ +/* */ +/* count :: The number of spans to draw on this scanline. */ +/* */ +/* spans :: A table of `count' spans to draw on the scanline. */ +/* */ +/* user :: User-supplied data that is passed to the callback. */ +/* */ +/* */ +/* This callback allows client applications to directly render the */ +/* gray spans of the anti-aliased bitmap to any kind of surfaces. */ +/* */ +/* This can be used to write anti-aliased outlines directly to a */ +/* given background bitmap, and even perform translucency. */ +/* */ +/* Note that the `count' field cannot be greater than a fixed value */ +/* defined by the FT_MAX_GRAY_SPANS configuration macro in */ +/* ftoption.h. By default, this value is set to 32, which means that */ +/* if there are more than 32 spans on a given scanline, the callback */ +/* will be called several times with the same `y' parameter in order */ +/* to draw all callbacks. */ +/* */ +/* Otherwise, the callback is only called once per scan-line, and */ +/* only for those scanlines that do have `gray' pixels on them. */ +/* */ +typedef void ( *FT_Raster_Span_Func )( int y, + int count, + FT_Span* spans, + void* user ); + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Raster_BitTest_Func */ +/* */ +/* */ +/* A function used as a call-back by the monochrome scan-converter */ +/* to test whether a given target pixel is already set to the drawing */ +/* `color'. These tests are crucial to implement drop-out control */ +/* per-se the TrueType spec. */ +/* */ +/* */ +/* y :: The pixel's y-coordinate. */ +/* */ +/* x :: The pixel's x-coordinate. */ +/* */ +/* user :: User-supplied data that is passed to the callback. */ +/* */ +/* */ +/* 1 if the pixel is `set', 0 otherwise. */ +/* */ +typedef int ( *FT_Raster_BitTest_Func )( int y, + int x, + void* user ); + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Raster_BitSet_Func */ +/* */ +/* */ +/* A function used as a call-back by the monochrome scan-converter */ +/* to set an individual target pixel. This is crucial to implement */ +/* drop-out control according to the TrueType specification. */ +/* */ +/* */ +/* y :: The pixel's y-coordinate. */ +/* */ +/* x :: The pixel's x-coordinate. */ +/* */ +/* user :: User-supplied data that is passed to the callback. */ +/* */ +/* */ +/* 1 if the pixel is `set', 0 otherwise. */ +/* */ +typedef void ( *FT_Raster_BitSet_Func )( int y, + int x, + void* user ); + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Raster_Flag */ +/* */ +/* */ +/* An enumeration to list the bit flags as used in the `flags' field */ +/* of a FT_Raster_Params structure. */ +/* */ +/* */ +/* ft_raster_flag_default :: This value is 0. */ +/* */ +/* ft_raster_flag_aa :: Requests the rendering of an */ +/* anti-aliased glyph bitmap. If unset, a */ +/* monchrome bitmap will be rendered. */ +/* */ +/* ft_raster_flag_direct :: Requests direct rendering over the */ +/* target bitmap. Direct rendering uses */ +/* user-provided callbacks in order to */ +/* perform direct drawing or composition */ +/* over an existing bitmap. If this bit is */ +/* unset, the content of the target bitmap */ +/* *must be zeroed*! */ +/* */ +typedef enum +{ + ft_raster_flag_default = 0, + ft_raster_flag_aa = 1, + ft_raster_flag_direct = 2 + +} FT_Raster_Flag; + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Raster_Params */ +/* */ +/* */ +/* A structure to hold the arguments used by a raster's render */ +/* function. */ +/* */ +/* */ +/* target :: The target bitmap. */ +/* */ +/* source :: A pointer to the source glyph image (e.g. an */ +/* FT_Outline). */ +/* */ +/* flags :: The rendering flags. */ +/* */ +/* gray_spans :: The gray span drawing callback. */ +/* */ +/* black_spans :: The black span drawing callback. */ +/* */ +/* bit_test :: The bit test callback. */ +/* */ +/* bit_set :: The bit set callback. */ +/* */ +/* user :: User-supplied data that is passed to each drawing */ +/* callback. */ +/* */ +/* */ +/* An anti-aliased glyph bitmap is drawn if the ft_raster_flag_aa bit */ +/* flag is set in the `flags' field, otherwise a monochrome bitmap */ +/* will be generated. */ +/* */ +/* If the ft_raster_flag_direct bit flag is set in `flags', the */ +/* raster will call the `gray_spans' callback to draw gray pixel */ +/* spans, in the case of an aa glyph bitmap, it will call */ +/* `black_spans', and `bit_test' and `bit_set' in the case of a */ +/* monochrome bitmap. This allows direct composition over a */ +/* pre-existing bitmap through user-provided callbacks to perform the */ +/* span drawing/composition. */ +/* */ +/* Note that the `bit_test' and `bit_set' callbacks are required when */ +/* rendering a monochrome bitmap, as they are crucial to implement */ +/* correct drop-out control as defined in the TrueType specification. */ +/* */ +typedef struct FT_Raster_Params_ +{ + FT_Bitmap* target; + void* source; + int flags; + FT_Raster_Span_Func gray_spans; + FT_Raster_Span_Func black_spans; + FT_Raster_BitTest_Func bit_test; + FT_Raster_BitSet_Func bit_set; + void* user; + +} FT_Raster_Params; + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Raster_New_Func */ +/* */ +/* */ +/* A function used to create a new raster object. */ +/* */ +/* */ +/* memory :: A handle to the memory allocator. */ +/* */ +/* */ +/* raster :: A handle to the new raster object. */ +/* */ +/* */ +/* Error code. 0 means success. */ +/* */ +/* */ +/* The `memory' parameter is a typeless pointer in order to avoid */ +/* un-wanted dependencies on the rest of the FreeType code. In */ +/* practice, it is a FT_Memory, i.e., a handle to the standard */ +/* FreeType memory allocator. However, this field can be completely */ +/* ignored by a given raster implementation. */ +/* */ +typedef int ( *FT_Raster_New_Func )( void* memory, + FT_Raster* raster ); + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Raster_Done_Func */ +/* */ +/* */ +/* A function used to destroy a given raster object. */ +/* */ +/* */ +/* raster :: A handle to the raster object. */ +/* */ +typedef void ( *FT_Raster_Done_Func )( FT_Raster raster ); + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Raster_Reset_Func */ +/* */ +/* */ +/* FreeType provides an area of memory called the `render pool', */ +/* available to all registered rasters. This pool can be freely used */ +/* during a given scan-conversion but is shared by all rasters. Its */ +/* content is thus transient. */ +/* */ +/* This function is called each time the render pool changes, or just */ +/* after a new raster object is created. */ +/* */ +/* */ +/* raster :: A handle to the new raster object. */ +/* */ +/* pool_base :: The address in memory of the render pool. */ +/* */ +/* pool_size :: The size in bytes of the render pool. */ +/* */ +/* */ +/* Rasters can ignore the render pool and rely on dynamic memory */ +/* allocation if they want to (a handle to the memory allocator is */ +/* passed to the raster constructor). However, this is not */ +/* recommended for efficiency purposes. */ +/* */ +typedef void ( *FT_Raster_Reset_Func )( FT_Raster raster, + unsigned char* pool_base, + unsigned long pool_size ); + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Raster_Set_Mode_Func */ +/* */ +/* */ +/* This function is a generic facility to change modes or attributes */ +/* in a given raster. This can be used for debugging purposes, or */ +/* simply to allow implementation-specific `features' in a given */ +/* raster module. */ +/* */ +/* */ +/* raster :: A handle to the new raster object. */ +/* */ +/* mode :: A 4-byte tag used to name the mode or property. */ +/* */ +/* args :: A pointer to the new mode/property to use. */ +/* */ +typedef int ( *FT_Raster_Set_Mode_Func )( FT_Raster raster, + unsigned long mode, + void* args ); + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Raster_Render_Func */ +/* */ +/* */ +/* Invokes a given raster to scan-convert a given glyph image into a */ +/* target bitmap. */ +/* */ +/* */ +/* raster :: A handle to the raster object. */ +/* */ +/* params :: A pointer to a FT_Raster_Params structure used to store */ +/* the rendering parameters. */ +/* */ +/* */ +/* Error code. 0 means success. */ +/* */ +/* */ +/* The exact format of the source image depends on the raster's glyph */ +/* format defined in its FT_Raster_Funcs structure. It can be an */ +/* FT_Outline or anything else in order to support a large array of */ +/* glyph formats. */ +/* */ +/* Note also that the render function can fail and return a */ +/* FT_Err_Unimplemented_Feature error code if the raster used does */ +/* not support direct composition. */ +/* */ +/* XXX: For now, the standard raster doesn't support direct */ +/* composition but this should change for the final release (see */ +/* the files demos/src/ftgrays.c and demos/src/ftgrays2.c for */ +/* examples of distinct implementations which support direct */ +/* composition). */ +/* */ +typedef int ( *FT_Raster_Render_Func )( FT_Raster raster, + FT_Raster_Params* params ); + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Raster_Funcs */ +/* */ +/* */ +/* A structure used to describe a given raster class to the library. */ +/* */ +/* */ +/* glyph_format :: The supported glyph format for this raster. */ +/* */ +/* raster_new :: The raster constructor. */ +/* */ +/* raster_reset :: Used to reset the render pool within the raster. */ +/* */ +/* raster_render :: A function to render a glyph into a given bitmap. */ +/* */ +/* raster_done :: The raster destructor. */ +/* */ +typedef struct FT_Raster_Funcs_ +{ + FT_Glyph_Format glyph_format; + FT_Raster_New_Func raster_new; + FT_Raster_Reset_Func raster_reset; + FT_Raster_Set_Mode_Func raster_set_mode; + FT_Raster_Render_Func raster_render; + FT_Raster_Done_Func raster_done; + +} FT_Raster_Funcs; + + +#ifdef __cplusplus +} +#endif + + +#endif /* FTIMAGE_H */ + + +/* END */ diff --git a/Projects/Android/jni/rtcw/src/ft2/ftinit.c b/Projects/Android/jni/rtcw/src/ft2/ftinit.c new file mode 100644 index 0000000..33497df --- /dev/null +++ b/Projects/Android/jni/rtcw/src/ft2/ftinit.c @@ -0,0 +1,161 @@ +/***************************************************************************/ +/* */ +/* ftinit.c */ +/* */ +/* FreeType initialization layer (body). */ +/* */ +/* Copyright 1996-2000 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + +/*************************************************************************/ +/* */ +/* The purpose of this file is to implement the following two */ +/* functions: */ +/* */ +/* FT_Add_Default_Modules(): */ +/* This function is used to add the set of default modules to a */ +/* fresh new library object. The set is taken from the header file */ +/* `freetype/config/ftmodule.h'. See the document `FreeType 2.0 */ +/* Build System' for more information. */ +/* */ +/* FT_Init_FreeType(): */ +/* This function creates a system object for the current platform, */ +/* builds a library out of it, then calls FT_Default_Drivers(). */ +/* */ +/* Note that even if FT_Init_FreeType() uses the implementation of the */ +/* system object defined at build time, client applications are still */ +/* able to provide their own `ftsystem.c'. */ +/* */ +/*************************************************************************/ + + +#include "ftconfig.h" +#include "ftobjs.h" +#include "ftdebug.h" +#include "ftmodule.h" +#include "ttdriver.h" +#include "ahmodule.h" +#include "sfdriver.h" +#include "ftsmooth.h" +#include "ftrend1.h" + +/*************************************************************************/ +/* */ +/* The macro FT_COMPONENT is used in trace mode. It is an implicit */ +/* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */ +/* messages during execution. */ +/* */ +#undef FT_COMPONENT +#define FT_COMPONENT trace_init + +#undef FT_USE_MODULE +#define FT_USE_MODULE( x ) extern const FT_Module_Class * x; + +#ifdef macintosh +FT_USE_MODULE( fond_driver_class ) +#endif +#include "ftmodule.h" + +#undef FT_USE_MODULE +#define FT_USE_MODULE( x ) (const FT_Module_Class*)&x, + +static +const FT_Module_Class* ft_default_modules[] = +{ + //FT_USE_MODULE(autohint_module_class) + FT_USE_MODULE( ft_raster1_renderer_class ) + FT_USE_MODULE( sfnt_module_class ) + FT_USE_MODULE( ft_smooth_renderer_class ) + FT_USE_MODULE( tt_driver_class ) + +#include "ftmodule.h" + 0 +}; + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Add_Default_Modules */ +/* */ +/* */ +/* Adds the set of default drivers to a given library object. */ +/* This is only useful when you create a library object with */ +/* FT_New_Library() (usually to plug a custom memory manager). */ +/* */ +/* */ +/* library :: A handle to a new library object. */ +/* */ +FT_EXPORT_FUNC( void ) FT_Add_Default_Modules( FT_Library library ) +{ + FT_Error error; + const FT_Module_Class** cur; + + + /* test for valid `library' delayed to FT_Add_Module() */ + + cur = ft_default_modules; + while ( *cur ) + { + error = FT_Add_Module( library, *cur ); + /* notify errors, but don't stop */ + if ( error ) { + FT_ERROR( ( "FT_Add_Default_Module: Cannot install `%s', error = %x\n", + ( *cur )->module_name, error ) ); + } + cur++; + } +} + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Init_FreeType */ +/* */ +/* */ +/* Initializes a new FreeType library object. The set of drivers */ +/* that are registered by this function is determined at build time. */ +/* */ +/* */ +/* library :: A handle to a new library object. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +FT_EXPORT_FUNC( FT_Error ) FT_Init_FreeType( FT_Library * library ) +{ + FT_Error error; + FT_Memory memory; + + + /* First of all, allocate a new system object -- this function is part */ + /* of the system-specific component, i.e. `ftsystem.c'. */ + + memory = FT_New_Memory(); + if ( !memory ) { + FT_ERROR( ( "FT_Init_FreeType: cannot find memory manager\n" ) ); + return FT_Err_Unimplemented_Feature; + } + + /* build a library out of it, then fill it with the set of */ + /* default drivers. */ + + error = FT_New_Library( memory, library ); + if ( !error ) { + FT_Add_Default_Modules( *library ); + } + + return error; +} + + +/* END */ diff --git a/Projects/Android/jni/rtcw/src/ft2/ftlist.c b/Projects/Android/jni/rtcw/src/ft2/ftlist.c new file mode 100644 index 0000000..3ea0704 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/ft2/ftlist.c @@ -0,0 +1,310 @@ +/***************************************************************************/ +/* */ +/* ftlist.c */ +/* */ +/* Generic list support for FreeType (body). */ +/* */ +/* Copyright 1996-2000 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + +/*************************************************************************/ +/* */ +/* This file implements functions relative to list processing. Its */ +/* data structures are defined in `freetype/internal/ftlist.h'. */ +/* */ +/*************************************************************************/ + + +#include "ftlist.h" +#include "ftdebug.h" +#include "ftobjs.h" + + +/*************************************************************************/ +/* */ +/* The macro FT_COMPONENT is used in trace mode. It is an implicit */ +/* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */ +/* messages during execution. */ +/* */ +#undef FT_COMPONENT +#define FT_COMPONENT trace_list + + +/*************************************************************************/ +/* */ +/* */ +/* FT_List_Find */ +/* */ +/* */ +/* Finds the list node for a given listed object. */ +/* */ +/* */ +/* list :: A pointer to the parent list. */ +/* data :: The address of the listed object. */ +/* */ +/* */ +/* List node. NULL if it wasn't found. */ +/* */ +BASE_FUNC( FT_ListNode ) FT_List_Find( FT_List list, + void* data ) +{ + FT_ListNode cur; + + + cur = list->head; + while ( cur ) + { + if ( cur->data == data ) { + return cur; + } + + cur = cur->next; + } + + return (FT_ListNode)0; +} + + +/*************************************************************************/ +/* */ +/* */ +/* FT_List_Add */ +/* */ +/* */ +/* Appends an element to the end of a list. */ +/* */ +/* */ +/* list :: A pointer to the parent list. */ +/* node :: The node to append. */ +/* */ +BASE_FUNC( void ) FT_List_Add( FT_List list, + FT_ListNode node ) +{ + FT_ListNode before = list->tail; + + + node->next = 0; + node->prev = before; + + if ( before ) { + before->next = node; + } else { + list->head = node; + } + + list->tail = node; +} + + +/*************************************************************************/ +/* */ +/* */ +/* FT_List_Insert */ +/* */ +/* */ +/* Inserts an element at the head of a list. */ +/* */ +/* */ +/* list :: A pointer to parent list. */ +/* node :: The node to insert. */ +/* */ +BASE_FUNC( void ) FT_List_Insert( FT_List list, + FT_ListNode node ) +{ + FT_ListNode after = list->head; + + + node->next = after; + node->prev = 0; + + if ( !after ) { + list->tail = node; + } else { + after->prev = node; + } + + list->head = node; +} + + +/*************************************************************************/ +/* */ +/* */ +/* FT_List_Remove */ +/* */ +/* */ +/* Removes a node from a list. This function doesn't check whether */ +/* the node is in the list! */ +/* */ +/* */ +/* node :: The node to remove. */ +/* */ +/* */ +/* list :: A pointer to the parent list. */ +/* */ +BASE_FUNC( void ) FT_List_Remove( FT_List list, + FT_ListNode node ) +{ + FT_ListNode before, after; + + + before = node->prev; + after = node->next; + + if ( before ) { + before->next = after; + } else { + list->head = after; + } + + if ( after ) { + after->prev = before; + } else { + list->tail = before; + } +} + + +/*************************************************************************/ +/* */ +/* */ +/* FT_List_Up */ +/* */ +/* */ +/* Moves a node to the head/top of a list. Used to maintain LRU */ +/* lists. */ +/* */ +/* */ +/* list :: A pointer to the parent list. */ +/* node :: The node to move. */ +/* */ +BASE_FUNC( void ) FT_List_Up( FT_List list, + FT_ListNode node ) +{ + FT_ListNode before, after; + + + before = node->prev; + after = node->next; + + /* check whether we are already on top of the list */ + if ( !before ) { + return; + } + + before->next = after; + + if ( after ) { + after->prev = before; + } else { + list->tail = before; + } + + node->prev = 0; + node->next = list->head; + list->head->prev = node; + list->head = node; +} + + +/*************************************************************************/ +/* */ +/* */ +/* FT_List_Iterate */ +/* */ +/* */ +/* Parses a list and calls a given iterator function on each element. */ +/* Note that parsing is stopped as soon as one of the iterator calls */ +/* returns a non-zero value. */ +/* */ +/* */ +/* list :: A handle to the list. */ +/* iterator :: An interator function, called on each node of the */ +/* list. */ +/* user :: A user-supplied field which is passed as the second */ +/* argument to the iterator. */ +/* */ +/* */ +/* The result (a FreeType error code) of the last iterator call. */ +/* */ +BASE_FUNC( FT_Error ) FT_List_Iterate( FT_List list, + FT_List_Iterator iterator, + void* user ) +{ + FT_ListNode cur = list->head; + FT_Error error = FT_Err_Ok; + + + while ( cur ) + { + FT_ListNode next = cur->next; + + + error = iterator( cur, user ); + if ( error ) { + break; + } + + cur = next; + } + + return error; +} + + +/*************************************************************************/ +/* */ +/* */ +/* FT_List_Finalize */ +/* */ +/* */ +/* Destroys all elements in the list as well as the list itself. */ +/* */ +/* */ +/* list :: A handle to the list. */ +/* */ +/* destroy :: A list destructor that will be applied to each element */ +/* of the list. */ +/* */ +/* memory :: The current memory object which handles deallocation. */ +/* */ +/* user :: A user-supplied field which is passed as the last */ +/* argument to the destructor. */ +/* */ +BASE_FUNC( void ) FT_List_Finalize( FT_List list, + FT_List_Destructor destroy, + FT_Memory memory, + void* user ) +{ + FT_ListNode cur; + + + cur = list->head; + while ( cur ) + { + FT_ListNode next = cur->next; + void* data = cur->data; + + + if ( destroy ) { + destroy( memory, data, user ); + } + + FREE( cur ); + cur = next; + } + + list->head = 0; + list->tail = 0; +} + + +/* END */ diff --git a/Projects/Android/jni/rtcw/src/ft2/ftlist.h b/Projects/Android/jni/rtcw/src/ft2/ftlist.h new file mode 100644 index 0000000..8473833 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/ft2/ftlist.h @@ -0,0 +1,113 @@ +/***************************************************************************/ +/* */ +/* ftlist.c */ +/* */ +/* Generic list support for FreeType (specification). */ +/* */ +/* Copyright 1996-2000 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +/*************************************************************************/ +/* */ +/* This file implements functions relative to list processing. Its */ +/* data structures are defined in `freetype.h'. */ +/* */ +/*************************************************************************/ + + +#ifndef FTLIST_H +#define FTLIST_H + +#include "freetype.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +FT_EXPORT_DEF( FT_ListNode ) FT_List_Find( FT_List list, + void* data ); + +FT_EXPORT_DEF( void ) FT_List_Add( FT_List list, + FT_ListNode node ); + +FT_EXPORT_DEF( void ) FT_List_Insert( FT_List list, + FT_ListNode node ); + +FT_EXPORT_DEF( void ) FT_List_Remove( FT_List list, + FT_ListNode node ); + +FT_EXPORT_DEF( void ) FT_List_Up( FT_List list, + FT_ListNode node ); + + +/*************************************************************************/ +/* */ +/* */ +/* FT_List_Iterator */ +/* */ +/* */ +/* An FT_List iterator function which is called during a list parse */ +/* by FT_List_Iterate(). */ +/* */ +/* */ +/* node :: The current iteration list node. */ +/* */ +/* user :: A typeless pointer passed to FT_List_Iterate(). */ +/* Can be used to point to the iteration's state. */ +/* */ +typedef FT_Error ( *FT_List_Iterator )( FT_ListNode node, + void* user ); + + +FT_EXPORT_DEF( FT_Error ) FT_List_Iterate( FT_List list, + FT_List_Iterator iterator, + void* user ); + + +/*************************************************************************/ +/* */ +/* */ +/* FT_List_Destructor */ +/* */ +/* */ +/* An FT_List iterator function which is called during a list */ +/* finalization by FT_List_Finalize() to destroy all elements in a */ +/* given list. */ +/* */ +/* */ +/* system :: The current system object. */ +/* */ +/* data :: The current object to destroy. */ +/* */ +/* user :: A typeless pointer passed to FT_List_Iterate(). It can */ +/* be used to point to the iteration's state. */ +/* */ +typedef void ( *FT_List_Destructor )( FT_Memory memory, + void* data, + void* user ); + + +FT_EXPORT_DEF( void ) FT_List_Finalize( FT_List list, + FT_List_Destructor destroy, + FT_Memory memory, + void* user ); + + +#ifdef __cplusplus +} +#endif + +#endif /* FTLIST_H */ + + +/* END */ diff --git a/Projects/Android/jni/rtcw/src/ft2/ftmemory.h b/Projects/Android/jni/rtcw/src/ft2/ftmemory.h new file mode 100644 index 0000000..702dda6 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/ft2/ftmemory.h @@ -0,0 +1,127 @@ +/***************************************************************************/ +/* */ +/* ftmemory.h */ +/* */ +/* The FreeType memory management macros (specification). */ +/* */ +/* Copyright 1996-2000 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef FTMEMORY_H +#define FTMEMORY_H + + +#include "ftconfig.h" +#include "fttypes.h" + + +/*************************************************************************/ +/* */ +/* */ +/* FT_SET_ERROR */ +/* */ +/* */ +/* This macro is used to set an implicit `error' variable to a given */ +/* expression's value (usually a function call), and convert it to a */ +/* boolean which is set whenever the value is != 0. */ +/* */ +#undef FT_SET_ERROR +#define FT_SET_ERROR( expression ) \ + ( ( error = ( expression ) ) != 0 ) + + +/*************************************************************************/ +/*************************************************************************/ +/*************************************************************************/ +/**** ****/ +/**** ****/ +/**** M E M O R Y ****/ +/**** ****/ +/**** ****/ +/*************************************************************************/ +/*************************************************************************/ +/*************************************************************************/ + +BASE_DEF( FT_Error ) FT_Alloc( FT_Memory memory, + FT_Long size, + void** P ); + +BASE_DEF( FT_Error ) FT_Realloc( FT_Memory memory, + FT_Long current, + FT_Long size, + void** P ); + +BASE_DEF( void ) FT_Free( FT_Memory memory, + void** P ); + + + +/* This `#include' is needed by the MEM_xxx() macros; it should be */ +/* available on all platforms we know of. */ +#include + +#define MEM_Set( dest, byte, count ) memset( dest, byte, count ) + +#define MEM_Copy( dest, source, count ) memcpy( dest, source, count ) + +#define MEM_Move( dest, source, count ) memmove( dest, source, count ) + + +/*************************************************************************/ +/* */ +/* We now support closures to produce completely reentrant code. This */ +/* means the allocation functions now takes an additional argument */ +/* (`memory'). It is a handle to a given memory object, responsible for */ +/* all low-level operations, including memory management and */ +/* synchronisation. */ +/* */ +/* In order to keep our code readable and use the same macros in the */ +/* font drivers and the rest of the library, MEM_Alloc(), ALLOC(), and */ +/* ALLOC_ARRAY() now use an implicit variable, `memory'. It must be */ +/* defined at all locations where a memory operation is queried. */ +/* */ +#define MEM_Alloc( _pointer_, _size_ ) \ + FT_Alloc( memory, _size_, (void**)&( _pointer_ ) ) + +#define MEM_Alloc_Array( _pointer_, _count_, _type_ ) \ + FT_Alloc( memory, ( _count_ ) * sizeof( _type_ ), \ + (void**)&( _pointer_ ) ) + +#define MEM_Realloc( _pointer_, _current_, _size_ ) \ + FT_Realloc( memory, _current_, _size_, (void**)&( _pointer_ ) ) + +#define MEM_Realloc_Array( _pointer_, _current_, _new_, _type_ ) \ + FT_Realloc( memory, ( _current_ ) * sizeof( _type_ ), \ + ( _new_ ) * sizeof( _type_ ), (void**)&( _pointer_ ) ) + +#define ALLOC( _pointer_, _size_ ) \ + FT_SET_ERROR( MEM_Alloc( _pointer_, _size_ ) ) + +#define REALLOC( _pointer_, _current_, _size_ ) \ + FT_SET_ERROR( MEM_Realloc( _pointer_, _current_, _size_ ) ) + +#define ALLOC_ARRAY( _pointer_, _count_, _type_ ) \ + FT_SET_ERROR( MEM_Alloc( _pointer_, \ + ( _count_ ) * sizeof( _type_ ) ) ) + +#define REALLOC_ARRAY( _pointer_, _current_, _count_, _type_ ) \ + FT_SET_ERROR( MEM_Realloc( _pointer_, \ + ( _current_ ) * sizeof( _type_ ), \ + ( _count_ ) * sizeof( _type_ ) ) ) + +#define FREE( _pointer_ ) FT_Free( memory, (void**)&( _pointer_ ) ) + + +#endif /* FTMEMORY_H */ + + +/* END */ diff --git a/Projects/Android/jni/rtcw/src/ft2/ftmm.c b/Projects/Android/jni/rtcw/src/ft2/ftmm.c new file mode 100644 index 0000000..a031d14 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/ft2/ftmm.c @@ -0,0 +1,179 @@ +/***************************************************************************/ +/* */ +/* ftmm.c */ +/* */ +/* Multiple Master font support (body). */ +/* */ +/* Copyright 1996-2000 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#include "ftmm.h" +#include "ftobjs.h" + + +/*************************************************************************/ +/* */ +/* The macro FT_COMPONENT is used in trace mode. It is an implicit */ +/* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */ +/* messages during execution. */ +/* */ +#undef FT_COMPONENT +#define FT_COMPONENT trace_mm + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Get_Multi_Master */ +/* */ +/* */ +/* Retrieves the Multiple Master descriptor of a given font. */ +/* */ +/* */ +/* face :: A handle to the source face. */ +/* */ +/* */ +/* master :: The Multiple Masters descriptor. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +FT_EXPORT_FUNC( FT_Error ) FT_Get_Multi_Master( FT_Face face, + FT_Multi_Master * master ) +{ + FT_Error error; + + + if ( !face ) { + return FT_Err_Invalid_Face_Handle; + } + + error = FT_Err_Invalid_Argument; + + if ( FT_HAS_MULTIPLE_MASTERS( face ) ) { + FT_Driver driver = face->driver; + FT_Get_MM_Func func; + + + func = (FT_Get_MM_Func)driver->root.clazz->get_interface( + FT_MODULE( driver ), "get_mm" ); + if ( func ) { + error = func( face, master ); + } + } + + return error; +} + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Set_MM_Design_Coordinates */ +/* */ +/* */ +/* For Multiple Masters fonts, choose an interpolated font design */ +/* through design coordinates. */ +/* */ +/* */ +/* face :: A handle to the source face. */ +/* */ +/* num_coords :: The number of design coordinates (must be equal to */ +/* the number of axes in the font). */ +/* */ +/* coords :: The design coordinates. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +FT_EXPORT_FUNC( FT_Error ) FT_Set_MM_Design_Coordinates( + FT_Face face, + FT_UInt num_coords, + FT_Long * coords ) +{ + FT_Error error; + + + if ( !face ) { + return FT_Err_Invalid_Face_Handle; + } + + error = FT_Err_Invalid_Argument; + + if ( FT_HAS_MULTIPLE_MASTERS( face ) ) { + FT_Driver driver = face->driver; + FT_Set_MM_Design_Func func; + + + func = (FT_Set_MM_Design_Func)driver->root.clazz->get_interface( + FT_MODULE( driver ), "set_mm_design" ); + if ( func ) { + error = func( face, num_coords, coords ); + } + } + + return error; +} + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Set_MM_Blend_Coordinates */ +/* */ +/* */ +/* For Multiple Masters fonts, choose an interpolated font design */ +/* through normalized blend coordinates. */ +/* */ +/* */ +/* face :: A handle to the source face. */ +/* */ +/* num_coords :: The number of design coordinates (must be equal to */ +/* the number of axes in the font). */ +/* */ +/* coords :: The design coordinates (each one must be between 0 */ +/* and 1.0). */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +FT_EXPORT_FUNC( FT_Error ) FT_Set_MM_Blend_Coordinates( + FT_Face face, + FT_UInt num_coords, + FT_Fixed * coords ) +{ + FT_Error error; + + + if ( !face ) { + return FT_Err_Invalid_Face_Handle; + } + + error = FT_Err_Invalid_Argument; + + if ( FT_HAS_MULTIPLE_MASTERS( face ) ) { + FT_Driver driver = face->driver; + FT_Set_MM_Blend_Func func; + + + func = (FT_Set_MM_Blend_Func)driver->root.clazz->get_interface( + FT_MODULE( driver ), "set_mm_blend" ); + if ( func ) { + error = func( face, num_coords, coords ); + } + } + + return error; +} + + +/* END */ diff --git a/Projects/Android/jni/rtcw/src/ft2/ftmm.h b/Projects/Android/jni/rtcw/src/ft2/ftmm.h new file mode 100644 index 0000000..f7daf73 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/ft2/ftmm.h @@ -0,0 +1,175 @@ +/***************************************************************************/ +/* */ +/* ftmm.h */ +/* */ +/* FreeType Multiple Master font interface (specification). */ +/* */ +/* Copyright 1996-2000 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef FTMM_H +#define FTMM_H + +#include "t1tables.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +/*************************************************************************/ +/* */ +/* */ +/* FT_MM_Axis */ +/* */ +/* */ +/* A simple structure used to model a given axis in design space for */ +/* Multiple Masters fonts. */ +/* */ +/* */ +/* name :: The axis's name. */ +/* */ +/* minimum :: The axis's minimum design coordinate. */ +/* */ +/* maximum :: The axis's maximum design coordinate. */ +/* */ +typedef struct FT_MM_Axis_ +{ + FT_String* name; + FT_Long minimum; + FT_Long maximum; + +} FT_MM_Axis; + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Multi_Master */ +/* */ +/* */ +/* A structure used to model the axes and space of a Multiple Masters */ +/* font. */ +/* */ +/* */ +/* num_axis :: Number of axes. Cannot exceed 4. */ +/* */ +/* num_designs :: Number of designs; should ne normally 2^num_axis */ +/* even though the Type 1 specification strangely */ +/* allows for intermediate designs to be present. This */ +/* number cannot exceed 16. */ +/* */ +/* axis :: A table of axis descriptors. */ +/* */ +typedef struct FT_Multi_Master_ +{ + FT_UInt num_axis; + FT_UInt num_designs; + FT_MM_Axis axis[T1_MAX_MM_AXIS]; + +} FT_Multi_Master; + + +typedef FT_Error ( *FT_Get_MM_Func )( FT_Face face, + FT_Multi_Master* master ); + +typedef FT_Error ( *FT_Set_MM_Design_Func )( FT_Face face, + FT_UInt num_coords, + FT_Long* coords ); + +typedef FT_Error ( *FT_Set_MM_Blend_Func )( FT_Face face, + FT_UInt num_coords, + FT_Long* coords ); + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Get_Multi_Master */ +/* */ +/* */ +/* Retrieves the Multiple Master descriptor of a given font. */ +/* */ +/* */ +/* face :: A handle to the source face. */ +/* */ +/* */ +/* master :: The Multiple Masters descriptor. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +FT_EXPORT_DEF( FT_Error ) FT_Get_Multi_Master( FT_Face face, + FT_Multi_Master * master ); + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Set_MM_Design_Coordinates */ +/* */ +/* */ +/* For Multiple Masters fonts, choose an interpolated font design */ +/* through design coordinates. */ +/* */ +/* */ +/* face :: A handle to the source face. */ +/* */ +/* num_coords :: The number of design coordinates (must be equal to */ +/* the number of axes in the font). */ +/* */ +/* coords :: The design coordinates. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +FT_EXPORT_DEF( FT_Error ) FT_Set_MM_Design_Coordinates( + FT_Face face, + FT_UInt num_coords, + FT_Long * coords ); + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Set_MM_Blend_Coordinates */ +/* */ +/* */ +/* For Multiple Masters fonts, choose an interpolated font design */ +/* through normalized blend coordinates. */ +/* */ +/* */ +/* face :: A handle to the source face. */ +/* */ +/* num_coords :: The number of design coordinates (must be equal to */ +/* the number of axes in the font). */ +/* */ +/* coords :: The design coordinates (each one must be between 0 */ +/* and 1.0). */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +FT_EXPORT_DEF( FT_Error ) FT_Set_MM_Blend_Coordinates( + FT_Face face, + FT_UInt num_coords, + FT_Fixed * coords ); + + +#ifdef __cplusplus +} +#endif + +#endif /* FTMM_H */ + + +/* END */ diff --git a/Projects/Android/jni/rtcw/src/ft2/ftmodule.h b/Projects/Android/jni/rtcw/src/ft2/ftmodule.h new file mode 100644 index 0000000..f2ab117 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/ft2/ftmodule.h @@ -0,0 +1,274 @@ +/***************************************************************************/ +/* */ +/* ftmodule.h */ +/* */ +/* FreeType modules public interface (specification). */ +/* */ +/* Copyright 1996-2000 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef FTMODULE_H +#define FTMODULE_H + +#include "freetype.h" + + +#ifdef __cplusplus +extern "C" { +#endif + + +/* module bit flags */ +typedef enum FT_Module_Flags_ +{ + ft_module_font_driver = 1, /* this module is a font driver */ + ft_module_renderer = 2, /* this module is a renderer */ + ft_module_hinter = 4, /* this module is a glyph hinter */ + ft_module_styler = 8, /* this module is a styler */ + + ft_module_driver_scalable = 0x100, /* the driver supports scalable */ + /* fonts */ + ft_module_driver_no_outlines = 0x200, /* the driver does not support */ + /* vector outlines */ + ft_module_driver_has_hinter = 0x400 /* the driver provides its own */ + /* hinter */ + +} FT_Module_Flags; + + +typedef void ( *FT_Module_Interface )( void ); + +typedef FT_Error ( *FT_Module_Constructor )( FT_Module module ); + +typedef void ( *FT_Module_Destructor )( FT_Module module ); + +typedef FT_Module_Interface ( *FT_Module_Requester )( FT_Module module, + const char* name ); + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Module_Class */ +/* */ +/* */ +/* The module class descriptor. */ +/* */ +/* */ +/* module_flags :: Bit flags describing the module. */ +/* */ +/* module_size :: The size of one module object/instance in */ +/* bytes. */ +/* */ +/* module_name :: The name of the module. */ +/* */ +/* module_version :: The version, as a 16.16 fixed number */ +/* (major.minor). */ +/* */ +/* module_requires :: The version of FreeType this module requires */ +/* (starts at version 2.0, i.e 0x20000) */ +/* */ +/* module_init :: A function used to initialize (not create) a */ +/* new module object. */ +/* */ +/* module_done :: A function used to finalize (not destroy) a */ +/* given module object */ +/* */ +/* get_interface :: Queries a given module for a specific */ +/* interface by name. */ +/* */ +typedef struct FT_Module_Class_ +{ + FT_ULong module_flags; + FT_Int module_size; + const FT_String* module_name; + FT_Fixed module_version; + FT_Fixed module_requires; + + const void* module_interface; + + FT_Module_Constructor module_init; + FT_Module_Destructor module_done; + FT_Module_Requester get_interface; + +} FT_Module_Class; + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Add_Module */ +/* */ +/* */ +/* Adds a new module to a given library instance. */ +/* */ +/* */ +/* library :: A handle to the library object. */ +/* */ +/* clazz :: A pointer to class descriptor for the module. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +/* */ +/* An error will be returned if a module already exists by that name, */ +/* or if the module requires a version of FreeType that is too great. */ +/* */ +FT_EXPORT_DEF( FT_Error ) FT_Add_Module( FT_Library library, + const FT_Module_Class * clazz ); + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Get_Module */ +/* */ +/* */ +/* Finds a module by its name. */ +/* */ +/* */ +/* library :: A handle to the library object. */ +/* */ +/* module_name :: The module's name (as an ASCII string). */ +/* */ +/* */ +/* A module handle. 0 if none was found. */ +/* */ +/* */ +/* You should better be familiar with FreeType internals to know */ +/* which module to look for :-) */ +/* */ +FT_EXPORT_DEF( FT_Module ) FT_Get_Module( FT_Library library, + const char* module_name ); + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Remove_Module */ +/* */ +/* */ +/* Removes a given module from a library instance. */ +/* */ +/* */ +/* library :: A handle to a library object. */ +/* */ +/* module :: A handle to a module object. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +/* */ +/* The module object is destroyed by the function in case of success. */ +/* */ +FT_EXPORT_DEF( FT_Error ) FT_Remove_Module( FT_Library library, + FT_Module module ); + + +/*************************************************************************/ +/* */ +/* */ +/* FT_New_Library */ +/* */ +/* */ +/* This function is used to create a new FreeType library instance */ +/* from a given memory object. It is thus possible to use libraries */ +/* with distinct memory allocators within the same program. */ +/* */ +/* */ +/* memory :: A handle to the original memory object. */ +/* */ +/* */ +/* alibrary :: A pointer to handle of a new library object. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +FT_EXPORT_DEF( FT_Error ) FT_New_Library( FT_Memory memory, + FT_Library * library ); + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Done_Library */ +/* */ +/* */ +/* Discards a given library object. This closes all drivers and */ +/* discards all resource objects. */ +/* */ +/* */ +/* library :: A handle to the target library. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +FT_EXPORT_DEF( FT_Error ) FT_Done_Library( FT_Library library ); + + + +typedef void ( *FT_DebugHook_Func )( void* arg ); + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Set_Debug_Hook */ +/* */ +/* */ +/* Sets a debug hook function for debugging the interpreter of a font */ +/* format. */ +/* */ +/* */ +/* library :: A handle to the library object. */ +/* */ +/* hook_index :: The index of the debug hook. You should use the */ +/* values defined in ftobjs.h, e.g. */ +/* FT_DEBUG_HOOK_TRUETYPE */ +/* */ +/* debug_hook :: The function used to debug the interpreter. */ +/* */ +/* */ +/* Currently, four debug hook slots are available, but only two (for */ +/* the TrueType and the Type 1 interpreter) are defined. */ +/* */ +FT_EXPORT_DEF( void ) FT_Set_Debug_Hook( FT_Library library, + FT_UInt hook_index, + FT_DebugHook_Func debug_hook ); + + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Add_Default_Modules */ +/* */ +/* */ +/* Adds the set of default drivers to a given library object. */ +/* This is only useful when you create a library object with */ +/* FT_New_Library() (usually to plug a custom memory manager). */ +/* */ +/* */ +/* library :: A handle to a new library object. */ +/* */ +FT_EXPORT_DEF( void ) FT_Add_Default_Modules( FT_Library library ); + + +#ifdef __cplusplus +} +#endif + + +#endif /* FTMODULE_H */ + + +/* END */ diff --git a/Projects/Android/jni/rtcw/src/ft2/ftnames.c b/Projects/Android/jni/rtcw/src/ft2/ftnames.c new file mode 100644 index 0000000..446e204 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/ft2/ftnames.c @@ -0,0 +1,68 @@ +/***************************************************************************/ +/* */ +/* ftnames.c */ +/* */ +/* Simple interface to access SFNT name tables (which are used */ +/* to hold font names, copyright info, notices, etc.). */ +/* */ +/* This is _not_ used to retrieve glyph names! */ +/* */ +/* Copyright 1996-2000 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#include "ftnames.h" +#include "tttypes.h" + + +#ifdef FT_CONFIG_OPTION_SFNT_NAMES + + +FT_EXPORT_FUNC( FT_UInt ) FT_Get_Sfnt_Name_Count( FT_Face face ) +{ + return face && ( FT_IS_SFNT( face ) ? ( (TT_Face)face )->num_names : 0 ); +} + + +FT_EXPORT_FUNC( FT_Error ) FT_Get_Sfnt_Name( FT_Face face, + FT_UInt index, + FT_SfntName * aname ) +{ + FT_Error error = FT_Err_Invalid_Argument; + + + if ( aname && face && FT_IS_SFNT( face ) ) { + TT_Face ttface = (TT_Face)face; + + + if ( index < ttface->num_names ) { + TT_NameRec* name = ttface->name_table.names + index; + + + aname->platform_id = name->platformID; + aname->encoding_id = name->encodingID; + aname->language_id = name->languageID; + aname->name_id = name->nameID; + aname->string = (FT_Byte*)name->string; + aname->string_len = name->stringLength; + + error = FT_Err_Ok; + } + } + + return error; +} + + +#endif /* FT_CONFIG_OPTION_SFNT_NAMES */ + + +/* END */ diff --git a/Projects/Android/jni/rtcw/src/ft2/ftnames.h b/Projects/Android/jni/rtcw/src/ft2/ftnames.h new file mode 100644 index 0000000..392250a --- /dev/null +++ b/Projects/Android/jni/rtcw/src/ft2/ftnames.h @@ -0,0 +1,52 @@ +/***************************************************************************/ +/* */ +/* ftnames.h */ +/* */ +/* Simple interface to access SFNT name tables (which are used */ +/* to hold font names, copyright info, notices, etc.). */ +/* */ +/* This is _not_ used to retrieve glyph names! */ +/* */ +/* Copyright 1996-2000 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef FTNAMES_H +#define FTNAMES_H + + +#include "freetype.h" + + +typedef struct FT_SfntName_ +{ + FT_UShort platform_id; + FT_UShort encoding_id; + FT_UShort language_id; + FT_UShort name_id; + + FT_Byte* string; + FT_UInt string_len; /* in bytes */ + +} FT_SfntName; + + +FT_EXPORT_DEF( FT_UInt ) FT_Get_Sfnt_Name_Count( FT_Face face ); + +FT_EXPORT_DEF( FT_Error ) FT_Get_Sfnt_Name( FT_Face face, + FT_UInt index, + FT_SfntName * aname ); + + +#endif /* FTNAMES_H */ + + +/* END */ diff --git a/Projects/Android/jni/rtcw/src/ft2/ftobjs.c b/Projects/Android/jni/rtcw/src/ft2/ftobjs.c new file mode 100644 index 0000000..6e0bf05 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/ft2/ftobjs.c @@ -0,0 +1,3280 @@ +/***************************************************************************/ +/* */ +/* ftobjs.c */ +/* */ +/* The FreeType private base classes (body). */ +/* */ +/* Copyright 1996-2000 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#include "ftobjs.h" +#include "ftlist.h" +#include "ftdebug.h" +#include "ftstream.h" + +#include "tttables.h" + +#include /* for strcmp() */ + + +/*************************************************************************/ +/*************************************************************************/ +/*************************************************************************/ +/**** ****/ +/**** ****/ +/**** M E M O R Y ****/ +/**** ****/ +/**** ****/ +/*************************************************************************/ +/*************************************************************************/ +/*************************************************************************/ + +/*************************************************************************/ +/* */ +/* The macro FT_COMPONENT is used in trace mode. It is an implicit */ +/* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */ +/* messages during execution. */ +/* */ +#undef FT_COMPONENT +#define FT_COMPONENT trace_memory + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Alloc */ +/* */ +/* */ +/* Allocates a new block of memory. The returned area is always */ +/* zero-filled; this is a strong convention in many FreeType parts. */ +/* */ +/* */ +/* memory :: A handle to a given `memory object' which handles */ +/* allocation. */ +/* */ +/* size :: The size in bytes of the block to allocate. */ +/* */ +/* */ +/* P :: A pointer to the fresh new block. It should be set to */ +/* NULL if `size' is 0, or in case of error. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +BASE_FUNC( FT_Error ) FT_Alloc( FT_Memory memory, + FT_Long size, + void** P ) +{ + FT_Assert( P != 0 ); + + if ( size > 0 ) { + *P = memory->alloc( memory, size ); + if ( !*P ) { + FT_ERROR( ( "FT_Alloc:" ) ); + FT_ERROR( ( " Out of memory? (%ld requested)\n", + size ) ); + + return FT_Err_Out_Of_Memory; + } + MEM_Set( *P, 0, size ); + } else { + *P = NULL; + } + + FT_TRACE7( ( "FT_Alloc:" ) ); + FT_TRACE7( ( " size = %ld, block = 0x%08p, ref = 0x%08p\n", + size, *P, P ) ); + + return FT_Err_Ok; +} + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Realloc */ +/* */ +/* */ +/* Reallocates a block of memory pointed to by `*P' to `Size' bytes */ +/* from the heap, possibly changing `*P'. */ +/* */ +/* */ +/* memory :: A handle to a given `memory object' which handles */ +/* reallocation. */ +/* */ +/* current :: The current block size in bytes. */ +/* */ +/* size :: The new block size in bytes. */ +/* */ +/* */ +/* P :: A pointer to the fresh new block. It should be set to */ +/* NULL if `size' is 0, or in case of error. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +/* */ +/* All callers of FT_Realloc() _must_ provide the current block size */ +/* as well as the new one. */ +/* */ +BASE_FUNC( FT_Error ) FT_Realloc( FT_Memory memory, + FT_Long current, + FT_Long size, + void** P ) +{ + void* Q; + + + FT_Assert( P != 0 ); + + /* if the original pointer is NULL, call FT_Alloc() */ + if ( !*P ) { + return FT_Alloc( memory, size, P ); + } + + /* if the new block if zero-sized, clear the current one */ + if ( size <= 0 ) { + FT_Free( memory, P ); + return FT_Err_Ok; + } + + Q = memory->realloc( memory, current, size, *P ); + if ( !Q ) { + goto Fail; + } + + *P = Q; + return FT_Err_Ok; + +Fail: + FT_ERROR( ( "FT_Realloc:" ) ); + FT_ERROR( ( " Failed (current %ld, requested %ld)\n", + current, size ) ); + return FT_Err_Out_Of_Memory; +} + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Free */ +/* */ +/* */ +/* Releases a given block of memory allocated through FT_Alloc(). */ +/* */ +/* */ +/* memory :: A handle to a given `memory object' which handles */ +/* memory deallocation */ +/* */ +/* P :: This is the _address_ of a _pointer_ which points to the */ +/* allocated block. It is always set to NULL on exit. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +/* */ +/* If P or *P are NULL, this function should return successfully. */ +/* This is a strong convention within all of FreeType and its */ +/* drivers. */ +/* */ +BASE_FUNC( void ) FT_Free( FT_Memory memory, + void** P ) +{ + FT_TRACE7( ( "FT_Free:" ) ); + FT_TRACE7( ( " Freeing block 0x%08p, ref 0x%08p\n", + P, P ? *P : (void*)0 ) ); + + if ( P && *P ) { + memory->free( memory, *P ); + *P = 0; + } +} + + +/*************************************************************************/ +/*************************************************************************/ +/*************************************************************************/ +/**** ****/ +/**** ****/ +/**** S T R E A M ****/ +/**** ****/ +/**** ****/ +/*************************************************************************/ +/*************************************************************************/ +/*************************************************************************/ + + +/*************************************************************************/ +/* */ +/* */ +/* ft_new_input_stream */ +/* */ +/* */ +/* Creates a new input stream object from an FT_Open_Args structure. */ +/* */ +/* */ +/* The function expects a valid `astream' parameter. */ +/* */ +static +FT_Error ft_new_input_stream( FT_Library library, + FT_Open_Args* args, + FT_Stream* astream ) { + FT_Error error; + FT_Memory memory; + FT_Stream stream; + + + if ( !library ) { + return FT_Err_Invalid_Library_Handle; + } + + if ( !args ) { + return FT_Err_Invalid_Argument; + } + + *astream = 0; + memory = library->memory; + if ( ALLOC( stream, sizeof( *stream ) ) ) { + goto Exit; + } + + stream->memory = memory; + + /* now, look at the stream flags */ + if ( args->flags & ft_open_memory ) { + error = 0; + FT_New_Memory_Stream( library, + args->memory_base, + args->memory_size, + stream ); + } else if ( args->flags & ft_open_pathname ) { + error = FT_New_Stream( args->pathname, stream ); + stream->pathname.pointer = args->pathname; + } else if ( args->flags & ft_open_stream && args->stream ) { + *stream = *( args->stream ); + stream->memory = memory; + } else { + error = FT_Err_Invalid_Argument; + } + + if ( error ) { + FREE( stream ); + } + + *astream = stream; + +Exit: + return error; +} + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Done_Stream */ +/* */ +/* */ +/* Closes and destroys a stream object. */ +/* */ +/* */ +/* stream :: The stream to be closed and destroyed. */ +/* */ +FT_EXPORT_FUNC( void ) FT_Done_Stream( FT_Stream stream ) +{ + if ( stream && stream->close ) { + stream->close( stream ); + } +} + + +static +void ft_done_stream( FT_Stream* astream ) { + FT_Stream stream = *astream; + FT_Memory memory = stream->memory; + + + if ( stream->close ) { + stream->close( stream ); + } + + FREE( stream ); + *astream = 0; +} + + +#undef FT_COMPONENT +#define FT_COMPONENT trace_objs + + +/*************************************************************************/ +/*************************************************************************/ +/*************************************************************************/ +/**** ****/ +/**** ****/ +/**** G L Y P H L O A D E R ****/ +/**** ****/ +/**** ****/ +/*************************************************************************/ +/*************************************************************************/ +/*************************************************************************/ + + +/*************************************************************************/ +/* */ +/* The glyph loader is a simple object which is used to load a set of */ +/* glyphs easily. It is critical for the correct loading of composites. */ +/* */ +/* Ideally, one can see it as a stack of abstract `glyph' objects. */ +/* */ +/* loader.base Is really the bottom of the stack. It describes a */ +/* single glyph image made of the juxtaposition of */ +/* several glyphs (those `in the stack'). */ +/* */ +/* loader.current Describes the top of the stack, on which a new */ +/* glyph can be loaded. */ +/* */ +/* Rewind Clears the stack. */ +/* Prepare Set up `loader.current' for addition of a new glyph */ +/* image. */ +/* Add Add the `current' glyph image to the `base' one, */ +/* and prepare for another one. */ +/* */ +/* The glyph loader is now a base object. Each driver used to */ +/* re-implement it in one way or the other, which wasted code and */ +/* energy. */ +/* */ +/*************************************************************************/ + + +/* create a new glyph loader */ +BASE_FUNC( FT_Error ) FT_GlyphLoader_New( FT_Memory memory, + FT_GlyphLoader * *aloader ) +{ + FT_GlyphLoader* loader; + FT_Error error; + + + if ( !ALLOC( loader, sizeof( *loader ) ) ) { + loader->memory = memory; + *aloader = loader; + } + return error; +} + + +/* rewind the glyph loader - reset counters to 0 */ +BASE_FUNC( void ) FT_GlyphLoader_Rewind( FT_GlyphLoader * loader ) +{ + FT_GlyphLoad* base = &loader->base; + FT_GlyphLoad* current = &loader->current; + + + base->outline.n_points = 0; + base->outline.n_contours = 0; + base->num_subglyphs = 0; + + *current = *base; +} + + +/* reset the glyph loader, frees all allocated tables */ +/* and starts from zero */ +BASE_FUNC( void ) FT_GlyphLoader_Reset( FT_GlyphLoader * loader ) +{ + FT_Memory memory = loader->memory; + + + FREE( loader->base.outline.points ); + FREE( loader->base.outline.tags ); + FREE( loader->base.outline.contours ); + FREE( loader->base.extra_points ); + FREE( loader->base.subglyphs ); + + loader->max_points = 0; + loader->max_contours = 0; + loader->max_subglyphs = 0; + + FT_GlyphLoader_Rewind( loader ); +} + + +/* delete a glyph loader */ +BASE_FUNC( void ) FT_GlyphLoader_Done( FT_GlyphLoader * loader ) +{ + if ( loader ) { + FT_Memory memory = loader->memory; + + + FT_GlyphLoader_Reset( loader ); + FREE( loader ); + } +} + + +/* re-adjust the `current' outline fields */ +static +void FT_GlyphLoader_Adjust_Points( FT_GlyphLoader* loader ) { + FT_Outline* base = &loader->base.outline; + FT_Outline* current = &loader->current.outline; + + + current->points = base->points + base->n_points; + current->tags = base->tags + base->n_points; + current->contours = base->contours + base->n_contours; + + /* handle extra points table - if any */ + if ( loader->use_extra ) { + loader->current.extra_points = + loader->base.extra_points + base->n_points; + } +} + + +BASE_FUNC( FT_Error ) FT_GlyphLoader_Create_Extra( + FT_GlyphLoader * loader ) +{ + FT_Error error; + FT_Memory memory = loader->memory; + + + if ( !ALLOC_ARRAY( loader->base.extra_points, + loader->max_points, FT_Vector ) ) { + loader->use_extra = 1; + FT_GlyphLoader_Adjust_Points( loader ); + } + return error; +} + + +/* re-adjust the `current' subglyphs field */ +static +void FT_GlyphLoader_Adjust_Subglyphs( FT_GlyphLoader* loader ) { + FT_GlyphLoad* base = &loader->base; + FT_GlyphLoad* current = &loader->current; + + + current->subglyphs = base->subglyphs + base->num_subglyphs; +} + + +/* Ensure that we can add `n_points' and `n_contours' to our glyph. this */ +/* function reallocates its outline tables if necessary. Note that it */ +/* DOESN'T change the number of points within the loader! */ +/* */ +BASE_FUNC( FT_Error ) FT_GlyphLoader_Check_Points( + FT_GlyphLoader * loader, + FT_UInt n_points, + FT_UInt n_contours ) +{ + FT_Memory memory = loader->memory; + FT_Error error = FT_Err_Ok; + FT_Outline* base = &loader->base.outline; + FT_Outline* current = &loader->current.outline; + FT_Bool adjust = 1; + + FT_UInt new_max; + + + /* check points & tags */ + new_max = base->n_points + current->n_points + n_points; + if ( new_max > loader->max_points ) { + new_max = ( new_max + 7 ) & - 8; + if ( REALLOC_ARRAY( base->points, base->n_points, + new_max, FT_Vector ) || + REALLOC_ARRAY( base->tags, base->n_points, + new_max, FT_Byte ) ) { + goto Exit; + } + + if ( loader->use_extra && + REALLOC_ARRAY( loader->base.extra_points, base->n_points, + new_max, FT_Vector ) ) { + goto Exit; + } + + adjust = 1; + loader->max_points = new_max; + } + + /* check contours */ + new_max = base->n_contours + current->n_contours + + n_contours; + if ( new_max > loader->max_contours ) { + new_max = ( new_max + 3 ) & - 4; + if ( REALLOC_ARRAY( base->contours, base->n_contours, + new_max, FT_Short ) ) { + goto Exit; + } + + adjust = 1; + loader->max_contours = new_max; + } + + if ( adjust ) { + FT_GlyphLoader_Adjust_Points( loader ); + } + +Exit: + return error; +} + + +/* Ensure that we can add `n_subglyphs' to our glyph. this function */ +/* reallocates its subglyphs table if necessary. Note that it DOES */ +/* NOT change the number of subglyphs within the loader! */ +/* */ +BASE_FUNC( FT_Error ) FT_GlyphLoader_Check_Subglyphs( + FT_GlyphLoader * loader, + FT_UInt n_subs ) +{ + FT_Memory memory = loader->memory; + FT_Error error = FT_Err_Ok; + FT_UInt new_max; + + FT_GlyphLoad* base = &loader->base; + FT_GlyphLoad* current = &loader->current; + + + new_max = base->num_subglyphs + current->num_subglyphs + n_subs; + if ( new_max > loader->max_subglyphs ) { + new_max = ( new_max + 1 ) & - 2; + if ( REALLOC_ARRAY( base->subglyphs, base->num_subglyphs, + new_max, FT_SubGlyph ) ) { + goto Exit; + } + + loader->max_subglyphs = new_max; + + FT_GlyphLoader_Adjust_Subglyphs( loader ); + } + +Exit: + return error; +} + + +/* prepare loader for the addition of a new glyph on top of the base one */ +BASE_FUNC( void ) FT_GlyphLoader_Prepare( FT_GlyphLoader * loader ) +{ + FT_GlyphLoad* current = &loader->current; + + + current->outline.n_points = 0; + current->outline.n_contours = 0; + current->num_subglyphs = 0; + + FT_GlyphLoader_Adjust_Points( loader ); + FT_GlyphLoader_Adjust_Subglyphs( loader ); +} + + +/* add current glyph to the base image - and prepare for another */ +BASE_FUNC( void ) FT_GlyphLoader_Add( FT_GlyphLoader * loader ) +{ + FT_GlyphLoad* base = &loader->base; + FT_GlyphLoad* current = &loader->current; + + FT_UInt n_curr_contours = current->outline.n_contours; + FT_UInt n_base_points = base->outline.n_points; + FT_UInt n; + + + base->outline.n_points += current->outline.n_points; + base->outline.n_contours += current->outline.n_contours; + base->num_subglyphs += current->num_subglyphs; + + /* adjust contours count in newest outline */ + for ( n = 0; n < n_curr_contours; n++ ) + current->outline.contours[n] += n_base_points; + + /* prepare for another new glyph image */ + FT_GlyphLoader_Prepare( loader ); +} + + +BASE_FUNC( FT_Error ) FT_GlyphLoader_Copy_Points( FT_GlyphLoader * target, + FT_GlyphLoader * source ) +{ + FT_Error error; + FT_UInt num_points = source->base.outline.n_points; + FT_UInt num_contours = source->base.outline.n_contours; + + + error = FT_GlyphLoader_Check_Points( target, num_points, num_contours ); + if ( !error ) { + FT_Outline* out = &target->base.outline; + FT_Outline* in = &source->base.outline; + + + MEM_Copy( out->points, in->points, + num_points * sizeof( FT_Vector ) ); + MEM_Copy( out->tags, in->tags, + num_points * sizeof( char ) ); + MEM_Copy( out->contours, in->contours, + num_contours * sizeof( short ) ); + + /* do we need to copy the extra points? */ + if ( target->use_extra && source->use_extra ) { + MEM_Copy( target->base.extra_points, source->base.extra_points, + num_points * sizeof( FT_Vector ) ); + } + + out->n_points = num_points; + out->n_contours = num_contours; + + FT_GlyphLoader_Adjust_Points( target ); + } + + return error; +} + + +/*************************************************************************/ +/*************************************************************************/ +/*************************************************************************/ +/**** ****/ +/**** ****/ +/**** FACE, SIZE & GLYPH SLOT OBJECTS ****/ +/**** ****/ +/**** ****/ +/*************************************************************************/ +/*************************************************************************/ +/*************************************************************************/ + + +static +FT_Error ft_glyphslot_init( FT_GlyphSlot slot ) { + FT_Driver driver = slot->face->driver; + FT_Driver_Class* clazz = driver->clazz; + FT_Memory memory = driver->root.memory; + FT_Error error = FT_Err_Ok; + + + slot->library = driver->root.library; + + if ( FT_DRIVER_USES_OUTLINES( driver ) ) { + error = FT_GlyphLoader_New( memory, &slot->loader ); + } + + if ( !error && clazz->init_slot ) { + error = clazz->init_slot( slot ); + } + + return error; +} + + +static +void ft_glyphslot_clear( FT_GlyphSlot slot ) { + /* free bitmap if needed */ + if ( slot->flags & ft_glyph_own_bitmap ) { + FT_Memory memory = FT_FACE_MEMORY( slot->face ); + + + FREE( slot->bitmap.buffer ); + slot->flags &= ~ft_glyph_own_bitmap; + } + + /* clear all public fields in the glyph slot */ + MEM_Set( &slot->metrics, 0, sizeof( slot->metrics ) ); + MEM_Set( &slot->outline, 0, sizeof( slot->outline ) ); + MEM_Set( &slot->bitmap, 0, sizeof( slot->bitmap ) ); + + slot->bitmap_left = 0; + slot->bitmap_top = 0; + slot->num_subglyphs = 0; + slot->subglyphs = 0; + slot->control_data = 0; + slot->control_len = 0; + slot->other = 0; + slot->format = ft_glyph_format_none; + + slot->linearHoriAdvance = 0; + slot->linearVertAdvance = 0; +} + + +static +void ft_glyphslot_done( FT_GlyphSlot slot ) { + FT_Driver driver = slot->face->driver; + FT_Driver_Class* clazz = driver->clazz; + FT_Memory memory = driver->root.memory; + + + /* free bitmap buffer if needed */ + if ( slot->flags & ft_glyph_own_bitmap ) { + FREE( slot->bitmap.buffer ); + } + + /* free glyph loader */ + if ( FT_DRIVER_USES_OUTLINES( driver ) ) { + FT_GlyphLoader_Done( slot->loader ); + slot->loader = 0; + } + + if ( clazz->done_slot ) { + clazz->done_slot( slot ); + } +} + + +/*************************************************************************/ +/* */ +/* */ +/* FT_New_GlyphSlot */ +/* */ +/* */ +/* It is sometimes useful to have more than one glyph slot for a */ +/* given face object. This function is used to create additional */ +/* slots. All of them are automatically discarded when the face is */ +/* destroyed. */ +/* */ +/* */ +/* face :: A handle to a parent face object. */ +/* */ +/* */ +/* aslot :: A handle to a new glyph slot object. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +FT_EXPORT_FUNC( FT_Error ) FT_New_GlyphSlot( FT_Face face, + FT_GlyphSlot * aslot ) +{ + FT_Error error; + FT_Driver driver; + FT_Driver_Class* clazz; + FT_Memory memory; + FT_GlyphSlot slot; + + + if ( !face || !aslot || !face->driver ) { + return FT_Err_Invalid_Argument; + } + + *aslot = 0; + + driver = face->driver; + clazz = driver->clazz; + memory = driver->root.memory; + + FT_TRACE4( ( "FT_New_GlyphSlot: Creating new slot object\n" ) ); + if ( !ALLOC( slot, clazz->slot_object_size ) ) { + slot->face = face; + + error = ft_glyphslot_init( slot ); + if ( error ) { + ft_glyphslot_done( slot ); + FREE( slot ); + goto Exit; + } + + *aslot = slot; + } + +Exit: + FT_TRACE4( ( "FT_New_GlyphSlot: Return %d\n", error ) ); + return error; +} + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Done_GlyphSlot */ +/* */ +/* */ +/* Destroys a given glyph slot. Remember however that all slots are */ +/* automatically destroyed with its parent. Using this function is */ +/* not always mandatory. */ +/* */ +/* */ +/* slot :: A handle to a target glyph slot. */ +/* */ +FT_EXPORT_FUNC( void ) FT_Done_GlyphSlot( FT_GlyphSlot slot ) +{ + if ( slot ) { + FT_Driver driver = slot->face->driver; + FT_Memory memory = driver->root.memory; + FT_GlyphSlot* parent; + FT_GlyphSlot cur; + + + /* Remove slot from its parent face's list */ + parent = &slot->face->glyph; + cur = *parent; + + while ( cur ) + { + if ( cur == slot ) { + *parent = cur->next; + ft_glyphslot_done( slot ); + FREE( slot ); + break; + } + cur = cur->next; + } + } +} + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Set_Transform */ +/* */ +/* */ +/* A function used to set the transformation that is applied to glyph */ +/* images just before they are converted to bitmaps in a glyph slot */ +/* when FT_Render_Glyph() is called. */ +/* */ +/* */ +/* face :: A handle to the source face object. */ +/* */ +/* */ +/* matrix :: A pointer to the transformation's 2x2 matrix. Use 0 for */ +/* the identity matrix. */ +/* delta :: A pointer to the translation vector. Use 0 for the null */ +/* vector. */ +/* */ +/* */ +/* The transformation is only applied to scalable image formats after */ +/* the glyph has been loaded. It means that hinting is unaltered by */ +/* the transformation and is performed on the character size given in */ +/* the last call to FT_Set_Char_Sizes() or FT_Set_Pixel_Sizes(). */ +/* */ +FT_EXPORT_FUNC( void ) FT_Set_Transform( FT_Face face, + FT_Matrix * matrix, + FT_Vector * delta ) +{ + if ( !face ) { + return; + } + + face->transform_flags = 0; + + if ( !matrix ) { + face->transform_matrix.xx = 0x10000L; + face->transform_matrix.xy = 0; + face->transform_matrix.yx = 0; + face->transform_matrix.yy = 0x10000L; + matrix = &face->transform_matrix; + } else { + face->transform_matrix = *matrix; + } + + /* set transform_flags bit flag 0 if `matrix' isn't the identity */ + if ( ( matrix->xy | matrix->yx ) || + matrix->xx != 0x10000L || + matrix->yy != 0x10000L ) { + face->transform_flags |= 1; + } + + if ( !delta ) { + face->transform_delta.x = 0; + face->transform_delta.y = 0; + delta = &face->transform_delta; + } else { + face->transform_delta = *delta; + } + + /* set transform_flags bit flag 1 if `delta' isn't the null vector */ + if ( delta->x | delta->y ) { + face->transform_flags |= 2; + } +} + + +static FT_Renderer ft_lookup_glyph_renderer( FT_GlyphSlot slot ); + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Load_Glyph */ +/* */ +/* */ +/* A function used to load a single glyph within a given glyph slot, */ +/* for a given size. */ +/* */ +/* */ +/* face :: A handle to the target face object where the glyph */ +/* will be loaded. */ +/* */ +/* glyph_index :: The index of the glyph in the font file. */ +/* */ +/* load_flags :: A flag indicating what to load for this glyph. The */ +/* FT_LOAD_XXX constants can be used to control the */ +/* glyph loading process (e.g., whether the outline */ +/* should be scaled, whether to load bitmaps or not, */ +/* whether to hint the outline, etc). */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +/* */ +/* If the glyph image is not a bitmap, and if the bit flag */ +/* FT_LOAD_IGNORE_TRANSFORM is unset, the glyph image will be */ +/* transformed with the information passed to a previous call to */ +/* FT_Set_Transform. */ +/* */ +/* Note that this also transforms the `face.glyph.advance' field, but */ +/* *not* the values in `face.glyph.metrics'. */ +/* */ +FT_EXPORT_FUNC( FT_Error ) FT_Load_Glyph( FT_Face face, + FT_UInt glyph_index, + FT_Int load_flags ) +{ + FT_Error error; + FT_Driver driver; + FT_GlyphSlot slot; + FT_Library library; + FT_Bool autohint; + FT_Module hinter; + + + if ( !face || !face->size || !face->glyph ) { + return FT_Err_Invalid_Face_Handle; + } + + if ( glyph_index >= (FT_UInt)face->num_glyphs ) { + return FT_Err_Invalid_Argument; + } + + slot = face->glyph; + ft_glyphslot_clear( slot ); + + driver = face->driver; + + /* when the flag NO_RECURSE is set, we disable hinting and scaling */ + if ( load_flags & FT_LOAD_NO_RECURSE ) { + load_flags |= FT_LOAD_NO_SCALE | FT_LOAD_NO_HINTING; + } + + /* do we need to load the glyph through the auto-hinter? */ + library = driver->root.library; + hinter = library->auto_hinter; + autohint = hinter && + !( load_flags & ( FT_LOAD_NO_SCALE | FT_LOAD_NO_HINTING ) ); + if ( autohint ) { + if ( FT_DRIVER_HAS_HINTER( driver ) && + !( load_flags & FT_LOAD_FORCE_AUTOHINT ) ) { + autohint = 0; + } + } + + if ( autohint ) { + FT_AutoHinter_Interface* hinting; + + + hinting = (FT_AutoHinter_Interface*)hinter->clazz->module_interface; + error = hinting->load_glyph( (FT_AutoHinter)hinter, slot, face->size, + glyph_index, load_flags ); + } else { + error = driver->clazz->load_glyph( slot, + face->size, + glyph_index, + load_flags ); + } + if ( error ) { + goto Exit; + } + + /* compute the advance */ + if ( load_flags & FT_LOAD_VERTICAL_LAYOUT ) { + slot->advance.x = 0; + slot->advance.y = slot->metrics.vertAdvance; + } else + { + slot->advance.x = slot->metrics.horiAdvance; + slot->advance.y = 0; + } + + /* now, transform the glyph image when needed */ + if ( face->transform_flags ) { + /* get renderer */ + FT_Renderer renderer = ft_lookup_glyph_renderer( slot ); + + + if ( renderer ) { + error = renderer->clazz->transform_glyph( renderer, slot, + &face->transform_matrix, + &face->transform_delta ); + } + /* transform advance */ + FT_Vector_Transform( &slot->advance, &face->transform_matrix ); + } + + /* do we need to render the image now? */ + if ( !error && + slot->format != ft_glyph_format_bitmap && + slot->format != ft_glyph_format_composite && + load_flags & FT_LOAD_RENDER ) { + error = FT_Render_Glyph( slot, + ( load_flags & FT_LOAD_MONOCHROME ) + ? ft_render_mode_mono + : ft_render_mode_normal ); + } + +Exit: + return error; +} + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Load_Char */ +/* */ +/* */ +/* A function used to load a single glyph within a given glyph slot, */ +/* for a given size, according to its character code. */ +/* */ +/* */ +/* face :: A handle to a target face object where the glyph */ +/* will be loaded. */ +/* */ +/* char_code :: The glyph's character code, according to the */ +/* current charmap used in the face. */ +/* */ +/* load_flags :: A flag indicating what to load for this glyph. The */ +/* FT_LOAD_XXX constants can be used to control the */ +/* glyph loading process (e.g., whether the outline */ +/* should be scaled, whether to load bitmaps or not, */ +/* whether to hint the outline, etc). */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +/* */ +/* If the face has no current charmap, or if the character code */ +/* is not defined in the charmap, this function will return an */ +/* error. */ +/* */ +/* If the glyph image is not a bitmap, and if the bit flag */ +/* FT_LOAD_IGNORE_TRANSFORM is unset, the glyph image will be */ +/* transformed with the information passed to a previous call to */ +/* FT_Set_Transform(). */ +/* */ +/* Note that this also transforms the `face.glyph.advance' field, but */ +/* *not* the values in `face.glyph.metrics'. */ +/* */ +FT_EXPORT_FUNC( FT_Error ) FT_Load_Char( FT_Face face, + FT_ULong char_code, + FT_Int load_flags ) +{ + FT_UInt glyph_index; + + + if ( !face ) { + return FT_Err_Invalid_Face_Handle; + } + + glyph_index = (FT_UInt)char_code; + if ( face->charmap ) { + glyph_index = FT_Get_Char_Index( face, char_code ); + } + + return FT_Load_Glyph( face, glyph_index, load_flags ); +} + + +/* destructor for sizes list */ +static +void destroy_size( FT_Memory memory, + FT_Size size, + FT_Driver driver ) { + /* finalize client-specific data */ + if ( size->generic.finalizer ) { + size->generic.finalizer( size ); + } + + /* finalize format-specific stuff */ + if ( driver->clazz->done_size ) { + driver->clazz->done_size( size ); + } + + FREE( size ); +} + + +/* destructor for faces list */ +static +void destroy_face( FT_Memory memory, + FT_Face face, + FT_Driver driver ) { + FT_Driver_Class* clazz = driver->clazz; + + + /* discard auto-hinting data */ + if ( face->autohint.finalizer ) { + face->autohint.finalizer( face->autohint.data ); + } + + /* Discard glyph slots for this face */ + /* Beware! FT_Done_GlyphSlot() changes the field `face->slot' */ + while ( face->glyph ) + FT_Done_GlyphSlot( face->glyph ); + + /* Discard all sizes for this face */ + FT_List_Finalize( &face->sizes_list, + (FT_List_Destructor)destroy_size, + memory, + driver ); + face->size = 0; + + /* Now discard client data */ + if ( face->generic.finalizer ) { + face->generic.finalizer( face ); + } + + /* finalize format-specific stuff */ + if ( clazz->done_face ) { + clazz->done_face( face ); + } + + /* close the stream for this face if needed */ + if ( ( face->face_flags & FT_FACE_FLAG_EXTERNAL_STREAM ) == 0 ) { + ft_done_stream( &face->stream ); + } + + /* get rid of it */ + FREE( face ); +} + + +static +void Destroy_Driver( FT_Driver driver ) { + FT_List_Finalize( &driver->faces_list, + (FT_List_Destructor)destroy_face, + driver->root.memory, + driver ); + + /* check whether we need to drop the driver's glyph loader */ + if ( FT_DRIVER_USES_OUTLINES( driver ) ) { + FT_GlyphLoader_Done( driver->glyph_loader ); + } +} + + +/*************************************************************************/ +/* */ +/* */ +/* open_face */ +/* */ +/* */ +/* This function does some work for FT_Open_Face(). */ +/* */ +static +FT_Error open_face( FT_Driver driver, + FT_Stream stream, + FT_Long face_index, + FT_Int num_params, + FT_Parameter* params, + FT_Face* aface ) { + FT_Memory memory; + FT_Driver_Class* clazz; + FT_Face face = 0; + FT_Error error; + + + clazz = driver->clazz; + memory = driver->root.memory; + + /* allocate the face object and perform basic initialization */ + if ( ALLOC( face, clazz->face_object_size ) ) { + goto Fail; + } + + face->driver = driver; + face->memory = memory; + face->stream = stream; + + error = clazz->init_face( stream, + face, + face_index, + num_params, + params ); + if ( error ) { + goto Fail; + } + + *aface = face; + +Fail: + if ( error ) { + clazz->done_face( face ); + FREE( face ); + *aface = 0; + } + + return error; +} + + +/*************************************************************************/ +/* */ +/* */ +/* FT_New_Face */ +/* */ +/* */ +/* Creates a new face object from a given resource and typeface index */ +/* using a pathname to the font file. */ +/* */ +/* */ +/* library :: A handle to the library resource. */ +/* */ +/* */ +/* pathname :: A path to the font file. */ +/* */ +/* face_index :: The index of the face within the resource. The */ +/* first face has index 0. */ +/* */ +/* aface :: A handle to a new face object. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +/* */ +/* Unlike FreeType 1.x, this function automatically creates a glyph */ +/* slot for the face object which can be accessed directly through */ +/* `face->glyph'. */ +/* */ +/* Note that additional slots can be added to each face with the */ +/* FT_New_GlyphSlot() API function. Slots are linked in a single */ +/* list through their `next' field. */ +/* */ +/* FT_New_Face() can be used to determine and/or check the font */ +/* format of a given font resource. If the `face_index' field is */ +/* negative, the function will _not_ return any face handle in */ +/* `*face'. Its return value should be 0 if the resource is */ +/* recognized, or non-zero if not. */ +/* */ +FT_EXPORT_FUNC( FT_Error ) FT_New_Face( FT_Library library, + const char* pathname, + FT_Long face_index, + FT_Face * aface ) +{ + FT_Open_Args args; + + + /* test for valid `library' and `aface' delayed to FT_Open_Face() */ + if ( !pathname ) { + return FT_Err_Invalid_Argument; + } + + args.flags = ft_open_pathname; + args.pathname = (char*)pathname; + + return FT_Open_Face( library, &args, face_index, aface ); +} + + +/*************************************************************************/ +/* */ +/* */ +/* FT_New_Memory_Face */ +/* */ +/* */ +/* Creates a new face object from a given resource and typeface index */ +/* using a font file already loaded into memory. */ +/* */ +/* */ +/* library :: A handle to the library resource. */ +/* */ +/* */ +/* file_base :: A pointer to the beginning of the font data. */ +/* */ +/* file_size :: The size of the memory chunk used by the font data. */ +/* */ +/* face_index :: The index of the face within the resource. The */ +/* first face has index 0. */ +/* */ +/* face :: A handle to a new face object. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +/* */ +/* Unlike FreeType 1.x, this function automatically creates a glyph */ +/* slot for the face object which can be accessed directly through */ +/* `face->glyph'. */ +/* */ +/* Note that additional slots can be added to each face with the */ +/* FT_New_GlyphSlot() API function. Slots are linked in a single */ +/* list through their `next' field. */ +/* */ +/* FT_New_Memory_Face() can be used to determine and/or check the */ +/* font format of a given font resource. If the `face_index' field */ +/* is negative, the function will _not_ return any face handle in */ +/* `*face'. Its return value should be 0 if the resource is */ +/* recognized, or non-zero if not. */ +/* */ +FT_EXPORT_FUNC( FT_Error ) FT_New_Memory_Face( FT_Library library, + FT_Byte * file_base, + FT_Long file_size, + FT_Long face_index, + FT_Face * face ) +{ + FT_Open_Args args; + + + /* test for valid `library' and `face' delayed to FT_Open_Face() */ + if ( !file_base ) { + return FT_Err_Invalid_Argument; + } + + args.flags = ft_open_memory; + args.memory_base = file_base; + args.memory_size = file_size; + + return FT_Open_Face( library, &args, face_index, face ); +} + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Open_Face */ +/* */ +/* */ +/* Opens a face object from a given resource and typeface index using */ +/* an `FT_Open_Args' structure. If the face object doesn't exist, it */ +/* will be created. */ +/* */ +/* */ +/* library :: A handle to the library resource. */ +/* */ +/* */ +/* args :: A pointer to an `FT_Open_Args' structure which must */ +/* be filled by the caller. */ +/* */ +/* face_index :: The index of the face within the resource. The */ +/* first face has index 0. */ +/* */ +/* aface :: A handle to a new face object. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +/* */ +/* Unlike FreeType 1.x, this function automatically creates a glyph */ +/* slot for the face object which can be accessed directly through */ +/* `face->glyph'. */ +/* */ +/* Note that additional slots can be added to each face with the */ +/* FT_New_GlyphSlot() API function. Slots are linked in a single */ +/* list through their `next' field. */ +/* */ +/* FT_Open_Face() can be used to determine and/or check the font */ +/* format of a given font resource. If the `face_index' field is */ +/* negative, the function will _not_ return any face handle in */ +/* `*face'. Its return value should be 0 if the resource is */ +/* recognized, or non-zero if not. */ +/* */ +FT_EXPORT_FUNC( FT_Error ) FT_Open_Face( FT_Library library, + FT_Open_Args * args, + FT_Long face_index, + FT_Face * aface ) +{ + FT_Error error; + FT_Driver driver; + FT_Memory memory; + FT_Stream stream; + FT_Face face = 0; + FT_ListNode node = 0; + + + /* test for valid `library' and `args' delayed to */ + /* ft_new_input_stream() */ + + if ( !aface ) { + return FT_Err_Invalid_Argument; + } + + *aface = 0; + + /* create input stream */ + error = ft_new_input_stream( library, args, &stream ); + if ( error ) { + goto Exit; + } + + memory = library->memory; + + /* If the font driver is specified in the `args' structure, use */ + /* it. Otherwise, we scan the list of registered drivers. */ + if ( args->flags & ft_open_driver && args->driver ) { + driver = FT_DRIVER( args->driver ); + + /* not all modules are drivers, so check... */ + if ( FT_MODULE_IS_DRIVER( driver ) ) { + FT_Int num_params = 0; + FT_Parameter* params = 0; + + + if ( args->flags & ft_open_params ) { + num_params = args->num_params; + params = args->params; + } + + error = open_face( driver, stream, face_index, + num_params, params, &face ); + if ( !error ) { + goto Success; + } + } else { + error = FT_Err_Invalid_Handle; + } + + ft_done_stream( &stream ); + goto Fail; + } else + { + /* check each font driver for an appropriate format */ + FT_Module* cur = library->modules; + FT_Module* limit = cur + library->num_modules; + + + for ( ; cur < limit; cur++ ) + { + /* not all modules are font drivers, so check... */ + if ( FT_MODULE_IS_DRIVER( cur[0] ) ) { + FT_Int num_params = 0; + FT_Parameter* params = 0; + + + driver = FT_DRIVER( cur[0] ); + + if ( args->flags & ft_open_params ) { + num_params = args->num_params; + params = args->params; + } + + error = open_face( driver, stream, face_index, + num_params, params, &face ); + if ( !error ) { + goto Success; + } + + if ( error != FT_Err_Unknown_File_Format ) { + goto Fail; + } + } + } + + ft_done_stream( &stream ); + + /* no driver is able to handle this format */ + error = FT_Err_Unknown_File_Format; + goto Fail; + } + +Success: + FT_TRACE4( ( "FT_New_Face: New face object, adding to list\n" ) ); + + /* set the FT_FACE_FLAG_EXTERNAL_STREAM bit for FT_Done_Face */ + if ( args->flags & ft_open_stream && args->stream ) { + face->face_flags |= FT_FACE_FLAG_EXTERNAL_STREAM; + } + + /* add the face object to its driver's list */ + if ( ALLOC( node, sizeof( *node ) ) ) { + goto Fail; + } + + node->data = face; + /* don't assume driver is the same as face->driver, so use */ + /* face->driver instead. */ + FT_List_Add( &face->driver->faces_list, node ); + + /* now allocate a glyph slot object for the face */ + { + FT_GlyphSlot slot; + + + FT_TRACE4( ( "FT_Open_Face: Creating glyph slot\n" ) ); + + error = FT_New_GlyphSlot( face, &slot ); + if ( error ) { + goto Fail; + } + + face->glyph = slot; + } + + /* finally, allocate a size object for the face */ + { + FT_Size size; + + + FT_TRACE4( ( "FT_Open_Face: Creating size object\n" ) ); + + error = FT_New_Size( face, &size ); + if ( error ) { + goto Fail; + } + + face->size = size; + } + + /* initialize transformation for convenience functions */ + face->transform_matrix.xx = 0x10000L; + face->transform_matrix.xy = 0; + face->transform_matrix.yx = 0; + face->transform_matrix.yy = 0x10000L; + + face->transform_delta.x = 0; + face->transform_delta.y = 0; + + *aface = face; + goto Exit; + +Fail: + FT_Done_Face( face ); + +Exit: + FT_TRACE4( ( "FT_Open_Face: Return %d\n", error ) ); + + return error; +} + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Attach_File */ +/* */ +/* */ +/* `Attaches' a given font file to an existing face. This is usually */ +/* to read additional information for a single face object. For */ +/* example, it is used to read the AFM files that come with Type 1 */ +/* fonts in order to add kerning data and other metrics. */ +/* */ +/* */ +/* face :: The target face object. */ +/* */ +/* */ +/* filepathname :: An 8-bit pathname naming the `metrics' file. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +/* */ +/* If your font file is in memory, or if you want to provide your */ +/* own input stream object, use FT_Attach_Stream(). */ +/* */ +/* The meaning of the `attach' action (i.e., what really happens when */ +/* the new file is read) is not fixed by FreeType itself. It really */ +/* depends on the font format (and thus the font driver). */ +/* */ +/* Client applications are expected to know what they are doing */ +/* when invoking this function. Most drivers simply do not implement */ +/* file attachments. */ +/* */ +FT_EXPORT_FUNC( FT_Error ) FT_Attach_File( FT_Face face, + const char* filepathname ) +{ + FT_Open_Args open; + + + /* test for valid `face' delayed to FT_Attach_Stream() */ + + if ( !filepathname ) { + return FT_Err_Invalid_Argument; + } + + open.flags = ft_open_pathname; + open.pathname = (char*)filepathname; + + return FT_Attach_Stream( face, &open ); +} + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Attach_Stream */ +/* */ +/* */ +/* This function is similar to FT_Attach_File() with the exception */ +/* that it reads the attachment from an arbitrary stream. */ +/* */ +/* */ +/* face :: The target face object. */ +/* */ +/* parameters :: A pointer to an FT_Open_Args structure used to */ +/* describe the input stream to FreeType. */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +/* */ +/* The meaning of the `attach' (i.e. what really happens when the */ +/* new file is read) is not fixed by FreeType itself. It really */ +/* depends on the font format (and thus the font driver). */ +/* */ +/* Client applications are expected to know what they are doing */ +/* when invoking this function. Most drivers simply do not implement */ +/* file attachments. */ +/* */ +FT_EXPORT_FUNC( FT_Error ) FT_Attach_Stream( FT_Face face, + FT_Open_Args * parameters ) +{ + FT_Stream stream; + FT_Error error; + FT_Driver driver; + + FT_Driver_Class* clazz; + + + /* test for valid `parameters' delayed to ft_new_input_stream() */ + + if ( !face ) { + return FT_Err_Invalid_Face_Handle; + } + + driver = face->driver; + if ( !driver ) { + return FT_Err_Invalid_Driver_Handle; + } + + error = ft_new_input_stream( driver->root.library, parameters, &stream ); + if ( error ) { + goto Exit; + } + + /* we implement FT_Attach_Stream in each driver through the */ + /* `attach_file' interface */ + + error = FT_Err_Unimplemented_Feature; + clazz = driver->clazz; + if ( clazz->attach_file ) { + error = clazz->attach_file( face, stream ); + } + + /* close the attached stream */ + if ( !parameters->stream || ( parameters->flags & ft_open_stream ) ) { + ft_done_stream( &stream ); + } + +Exit: + return error; +} + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Done_Face */ +/* */ +/* */ +/* Discards a given face object, as well as all of its child slots */ +/* and sizes. */ +/* */ +/* */ +/* face :: A handle to a target face object. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +FT_EXPORT_FUNC( FT_Error ) FT_Done_Face( FT_Face face ) +{ + FT_Error error; + FT_Driver driver; + FT_Memory memory; + FT_ListNode node; + + + error = FT_Err_Invalid_Face_Handle; + if ( face && face->driver ) { + driver = face->driver; + memory = driver->root.memory; + + /* find face in driver's list */ + node = FT_List_Find( &driver->faces_list, face ); + if ( node ) { + /* remove face object from the driver's list */ + FT_List_Remove( &driver->faces_list, node ); + FREE( node ); + + /* now destroy the object proper */ + destroy_face( memory, face, driver ); + error = FT_Err_Ok; + } + } + return error; +} + + +/*************************************************************************/ +/* */ +/* */ +/* FT_New_Size */ +/* */ +/* */ +/* Creates a new size object from a given face object. */ +/* */ +/* */ +/* face :: A handle to a parent face object. */ +/* */ +/* */ +/* asize :: A handle to a new size object. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +FT_EXPORT_FUNC( FT_Error ) FT_New_Size( FT_Face face, + FT_Size * asize ) +{ + FT_Error error; + FT_Memory memory; + FT_Driver driver; + FT_Driver_Class* clazz; + + FT_Size size = 0; + FT_ListNode node = 0; + + + if ( !face ) { + return FT_Err_Invalid_Face_Handle; + } + + if ( !asize ) { + return FT_Err_Invalid_Size_Handle; + } + + if ( !face->driver ) { + return FT_Err_Invalid_Driver_Handle; + } + + *asize = 0; + + driver = face->driver; + clazz = driver->clazz; + memory = face->memory; + + /* Allocate new size object and perform basic initialisation */ + if ( ALLOC( size, clazz->size_object_size ) || + ALLOC( node, sizeof( FT_ListNodeRec ) ) ) { + goto Exit; + } + + size->face = face; + + if ( clazz->init_size ) { + error = clazz->init_size( size ); + } + + /* in case of success, add to the face's list */ + if ( !error ) { + *asize = size; + node->data = size; + FT_List_Add( &face->sizes_list, node ); + } + +Exit: + if ( error ) { + FREE( node ); + FREE( size ); + } + + return error; +} + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Done_Size */ +/* */ +/* */ +/* Discards a given size object. */ +/* */ +/* */ +/* size :: A handle to a target size object. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +FT_EXPORT_FUNC( FT_Error ) FT_Done_Size( FT_Size size ) +{ + FT_Error error; + FT_Driver driver; + FT_Memory memory; + FT_Face face; + FT_ListNode node; + + + if ( !size ) { + return FT_Err_Invalid_Size_Handle; + } + + face = size->face; + if ( !face ) { + return FT_Err_Invalid_Face_Handle; + } + + driver = face->driver; + if ( !driver ) { + return FT_Err_Invalid_Driver_Handle; + } + + memory = driver->root.memory; + + error = FT_Err_Ok; + node = FT_List_Find( &face->sizes_list, size ); + if ( node ) { + FT_List_Remove( &face->sizes_list, node ); + FREE( node ); + + if ( face->size == size ) { + face->size = 0; + if ( face->sizes_list.head ) { + face->size = (FT_Size)( face->sizes_list.head->data ); + } + } + + destroy_size( memory, size, driver ); + } else { + error = FT_Err_Invalid_Size_Handle; + } + + return FT_Err_Ok; +} + + +static +void ft_recompute_scaled_metrics( FT_Face face, + FT_Size_Metrics* metrics ) { + /* Compute root ascender, descender, test height, and max_advance */ + + metrics->ascender = ( FT_MulFix( face->ascender, + metrics->y_scale ) + 32 ) & - 64; + + metrics->descender = ( FT_MulFix( face->descender, + metrics->y_scale ) + 32 ) & - 64; + + metrics->height = ( FT_MulFix( face->height, + metrics->y_scale ) + 32 ) & - 64; + + metrics->max_advance = ( FT_MulFix( face->max_advance_width, + metrics->x_scale ) + 32 ) & - 64; +} + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Set_Char_Size */ +/* */ +/* */ +/* Sets the character dimensions of a given face object. The */ +/* `char_width' and `char_height' values are used for the width and */ +/* height, respectively, expressed in 26.6 fractional points. */ +/* */ +/* If the horizontal or vertical resolution values are zero, a */ +/* default value of 72dpi is used. Similarly, if one of the */ +/* character dimensions is zero, its value is set equal to the other. */ +/* */ +/* */ +/* size :: A handle to a target size object. */ +/* */ +/* */ +/* char_width :: The character width, in 26.6 fractional points. */ +/* */ +/* char_height :: The character height, in 26.6 fractional */ +/* points. */ +/* */ +/* horz_resolution :: The horizontal resolution. */ +/* */ +/* vert_resolution :: The vertical resolution. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +/* */ +/* When dealing with fixed-size faces (i.e., non-scalable formats), */ +/* use the function FT_Set_Pixel_Sizes(). */ +/* */ +FT_EXPORT_FUNC( FT_Error ) FT_Set_Char_Size( FT_Face face, + FT_F26Dot6 char_width, + FT_F26Dot6 char_height, + FT_UInt horz_resolution, + FT_UInt vert_resolution ) +{ + FT_Error error = FT_Err_Ok; + FT_Driver driver; + FT_Memory memory; + FT_Driver_Class* clazz; + FT_Size_Metrics* metrics; + FT_Long dim_x, dim_y; + + + if ( !face || !face->size || !face->driver ) { + return FT_Err_Invalid_Face_Handle; + } + + driver = face->driver; + metrics = &face->size->metrics; + + if ( !char_width ) { + char_width = char_height; + } else if ( !char_height ) { + char_height = char_width; + } + + if ( !horz_resolution ) { + horz_resolution = 72; + } + + if ( !vert_resolution ) { + vert_resolution = 72; + } + + driver = face->driver; + clazz = driver->clazz; + memory = driver->root.memory; + + /* default processing -- this can be overridden by the driver */ + if ( char_width < 1 * 64 ) { + char_width = 1 * 64; + } + if ( char_height < 1 * 64 ) { + char_height = 1 * 64; + } + + /* Compute pixel sizes in 26.6 units */ + dim_x = ( ( ( char_width * horz_resolution ) / 72 ) + 32 ) & - 64; + dim_y = ( ( ( char_height * vert_resolution ) / 72 ) + 32 ) & - 64; + + metrics->x_ppem = (FT_UShort)( dim_x >> 6 ); + metrics->y_ppem = (FT_UShort)( dim_y >> 6 ); + + metrics->x_scale = 0x10000L; + metrics->y_scale = 0x10000L; + + if ( face->face_flags & FT_FACE_FLAG_SCALABLE ) { + metrics->x_scale = FT_DivFix( dim_x, face->units_per_EM ); + metrics->y_scale = FT_DivFix( dim_y, face->units_per_EM ); + + ft_recompute_scaled_metrics( face, metrics ); + } + + if ( clazz->set_char_sizes ) { + error = clazz->set_char_sizes( face->size, + char_width, + char_height, + horz_resolution, + vert_resolution ); + } + return error; +} + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Set_Pixel_Sizes */ +/* */ +/* */ +/* Sets the character dimensions of a given face object. The width */ +/* and height are expressed in integer pixels. */ +/* */ +/* If one of the character dimensions is zero, its value is set equal */ +/* to the other. */ +/* */ +/* */ +/* face :: A handle to the target face object. */ +/* */ +/* */ +/* pixel_width :: The character width, in integer pixels. */ +/* */ +/* pixel_height :: The character height, in integer pixels. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +FT_EXPORT_FUNC( FT_Error ) FT_Set_Pixel_Sizes( FT_Face face, + FT_UInt pixel_width, + FT_UInt pixel_height ) +{ + FT_Error error = FT_Err_Ok; + FT_Driver driver; + FT_Memory memory; + FT_Driver_Class* clazz; + FT_Size_Metrics* metrics = &face->size->metrics; + + + if ( !face || !face->size || !face->driver ) { + return FT_Err_Invalid_Face_Handle; + } + + driver = face->driver; + clazz = driver->clazz; + memory = driver->root.memory; + + /* default processing -- this can be overridden by the driver */ + if ( pixel_width == 0 ) { + pixel_width = pixel_height; + } else if ( pixel_height == 0 ) { + pixel_height = pixel_width; + } + + if ( pixel_width < 1 ) { + pixel_width = 1; + } + if ( pixel_height < 1 ) { + pixel_height = 1; + } + + metrics->x_ppem = pixel_width; + metrics->y_ppem = pixel_height; + + if ( face->face_flags & FT_FACE_FLAG_SCALABLE ) { + metrics->x_scale = FT_DivFix( metrics->x_ppem << 6, + face->units_per_EM ); + + metrics->y_scale = FT_DivFix( metrics->y_ppem << 6, + face->units_per_EM ); + + ft_recompute_scaled_metrics( face, metrics ); + } + + if ( clazz->set_pixel_sizes ) { + error = clazz->set_pixel_sizes( face->size, + pixel_width, + pixel_height ); + } + return error; +} + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Get_Kerning */ +/* */ +/* */ +/* Returns the kerning vector between two glyphs of a same face. */ +/* */ +/* */ +/* face :: A handle to a source face object. */ +/* */ +/* left_glyph :: The index of the left glyph in the kern pair. */ +/* */ +/* right_glyph :: The index of the right glyph in the kern pair. */ +/* */ +/* kern_mode :: See FT_Kerning_Mode() for more information. */ +/* Determines the scale/dimension of the returned */ +/* kerning vector. */ +/* */ +/* */ +/* kerning :: The kerning vector. This is in font units for */ +/* scalable formats, and in pixels for fixed-sizes */ +/* formats. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +/* */ +/* Only horizontal layouts (left-to-right & right-to-left) are */ +/* supported by this method. Other layouts, or more sophisticated */ +/* kernings, are out of the scope of this API function -- they can be */ +/* implemented through format-specific interfaces. */ +/* */ +FT_EXPORT_FUNC( FT_Error ) FT_Get_Kerning( FT_Face face, + FT_UInt left_glyph, + FT_UInt right_glyph, + FT_UInt kern_mode, + FT_Vector * kerning ) +{ + FT_Error error = FT_Err_Ok; + FT_Driver driver; + FT_Memory memory; + + + if ( !face ) { + return FT_Err_Invalid_Face_Handle; + } + + if ( !kerning ) { + return FT_Err_Invalid_Argument; + } + + driver = face->driver; + memory = driver->root.memory; + + kerning->x = 0; + kerning->y = 0; + + if ( driver->clazz->get_kerning ) { + error = driver->clazz->get_kerning( face, + left_glyph, + right_glyph, + kerning ); + if ( !error ) { + if ( kern_mode != ft_kerning_unscaled ) { + kerning->x = FT_MulFix( kerning->x, face->size->metrics.x_scale ); + kerning->y = FT_MulFix( kerning->y, face->size->metrics.y_scale ); + + if ( kern_mode != ft_kerning_unfitted ) { + kerning->x = ( kerning->x + 32 ) & - 64; + kerning->y = ( kerning->y + 32 ) & - 64; + } + } + } + } + + return error; +} + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Select_Charmap */ +/* */ +/* */ +/* Selects a given charmap by its encoding tag (as listed in */ +/* `freetype.h'). */ +/* */ +/* */ +/* face :: A handle to the source face object. */ +/* */ +/* encoding :: A handle to the selected charmap. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +/* */ +/* This function will return an error if no charmap in the face */ +/* corresponds to the encoding queried here. */ +/* */ +FT_EXPORT_FUNC( FT_Error ) FT_Select_Charmap( FT_Face face, + FT_Encoding encoding ) +{ + FT_CharMap* cur; + FT_CharMap* limit; + + + if ( !face ) { + return FT_Err_Invalid_Face_Handle; + } + + cur = face->charmaps; + if ( !cur ) { + return FT_Err_Invalid_CharMap_Handle; + } + + limit = cur + face->num_charmaps; + + for ( ; cur < limit; cur++ ) + { + if ( cur[0]->encoding == encoding ) { + face->charmap = cur[0]; + return 0; + } + } + + return FT_Err_Invalid_Argument; +} + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Set_Charmap */ +/* */ +/* */ +/* Selects a given charmap for character code to glyph index */ +/* decoding. */ +/* */ +/* */ +/* face :: A handle to the source face object. */ +/* charmap :: A handle to the selected charmap. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +/* */ +/* This function will return an error if the charmap is not part of */ +/* the face (i.e., if it is not listed in the face->charmaps[] */ +/* table). */ +/* */ +FT_EXPORT_FUNC( FT_Error ) FT_Set_Charmap( FT_Face face, + FT_CharMap charmap ) +{ + FT_CharMap* cur; + FT_CharMap* limit; + + + if ( !face ) { + return FT_Err_Invalid_Face_Handle; + } + + cur = face->charmaps; + if ( !cur ) { + return FT_Err_Invalid_CharMap_Handle; + } + + limit = cur + face->num_charmaps; + + for ( ; cur < limit; cur++ ) + { + if ( cur[0] == charmap ) { + face->charmap = cur[0]; + return 0; + } + } + return FT_Err_Invalid_Argument; +} + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Get_Char_Index */ +/* */ +/* */ +/* Returns the glyph index of a given character code. This function */ +/* uses a charmap object to do the translation. */ +/* */ +/* */ +/* face :: A handle to the source face object. */ +/* */ +/* charcode :: The character code. */ +/* */ +/* */ +/* The glyph index. 0 means `undefined character code'. */ +/* */ +FT_EXPORT_FUNC( FT_UInt ) FT_Get_Char_Index( FT_Face face, + FT_ULong charcode ) +{ + FT_UInt result; + FT_Driver driver; + + + result = 0; + if ( face && face->charmap ) { + driver = face->driver; + result = driver->clazz->get_char_index( face->charmap, charcode ); + } + return result; +} + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Get_Glyph_Name */ +/* */ +/* */ +/* Retrieves the ASCII name of a given glyph in a face. This only */ +/* works for those faces where FT_HAS_GLYPH_NAME(face) returns true. */ +/* */ +/* */ +/* face :: A handle to a source face object. */ +/* */ +/* glyph_index :: The glyph index. */ +/* */ +/* buffer :: A pointer to a target buffer where the name will be */ +/* copied to. */ +/* */ +/* buffer_max :: The maximal number of bytes available in the */ +/* buffer. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +/* */ +/* An error is returned if the face doesn't provide glyph names or if */ +/* the glyph index is invalid. In all cases of failure, the first */ +/* byte of `buffer' will be set to 0 to indicate an empty name. */ +/* */ +/* The glyph name is truncated to fit within the buffer if it is too */ +/* long. The returned string is always zero-terminated. */ +/* */ +/* This function is not compiled within the library if the config */ +/* macro FT_CONFIG_OPTION_NO_GLYPH_NAMES is defined in */ +/* `include/freetype/config/ftoptions.h' */ +/* */ +FT_EXPORT_FUNC( FT_Error ) FT_Get_Glyph_Name( FT_Face face, + FT_UInt glyph_index, + FT_Pointer buffer, + FT_UInt buffer_max ) +{ + FT_Error error = FT_Err_Invalid_Argument; + + + /* clean up buffer */ + if ( buffer && buffer_max > 0 ) { + ( (FT_Byte*)buffer )[0] = 0; + } + + if ( face && + glyph_index < (FT_UInt)face->num_glyphs && + FT_HAS_GLYPH_NAMES( face ) ) { + /* now, lookup for glyph name */ + FT_Driver driver = face->driver; + FT_Module_Class* clazz = FT_MODULE_CLASS( driver ); + + + if ( clazz->get_interface ) { + FT_Glyph_Name_Requester requester; + + + requester = (FT_Glyph_Name_Requester)clazz->get_interface( + FT_MODULE( driver ), "glyph_name" ); + if ( requester ) { + error = requester( face, glyph_index, buffer, buffer_max ); + } + } + } + + return error; +} + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Get_Sfnt_Table */ +/* */ +/* */ +/* Returns a pointer to a given SFNT table within a face. */ +/* */ +/* */ +/* face :: A handle to the source face object. */ +/* tag :: An index of an SFNT table. */ +/* */ +/* */ +/* A type-less pointer to the table. This will be 0 in case of */ +/* error, or if the corresponding table was not found *OR* loaded */ +/* from the file. */ +/* */ +/* */ +/* The table is owned by the face object, and disappears with it. */ +/* */ +/* This function is only useful to access SFNT tables that are loaded */ +/* by the sfnt/truetype/opentype drivers. See the FT_Sfnt_Tag */ +/* enumeration in `tttables.h' for a list. */ +/* */ +/* You can load any table with a different function.. XXX */ +/* */ +FT_EXPORT_FUNC( void* ) FT_Get_Sfnt_Table( FT_Face face, + FT_Sfnt_Tag tag ) +{ + void* table = 0; + FT_Get_Sfnt_Table_Func func; + FT_Driver driver; + + + if ( !face || !FT_IS_SFNT( face ) ) { + goto Exit; + } + + driver = face->driver; + func = (FT_Get_Sfnt_Table_Func)driver->root.clazz->get_interface( + FT_MODULE( driver ), "get_sfnt" ); + if ( func ) { + table = func( face, tag ); + } + +Exit: + return table; +} + + +/*************************************************************************/ +/*************************************************************************/ +/*************************************************************************/ +/**** ****/ +/**** ****/ +/**** R E N D E R E R S ****/ +/**** ****/ +/**** ****/ +/*************************************************************************/ +/*************************************************************************/ +/*************************************************************************/ + +/* lookup a renderer by glyph format in the library's list */ +BASE_FUNC( FT_Renderer ) FT_Lookup_Renderer( FT_Library library, + FT_Glyph_Format format, + FT_ListNode * node ) +{ + FT_ListNode cur; + FT_Renderer result = 0; + + + if ( !library ) { + goto Exit; + } + + cur = library->renderers.head; + + if ( node ) { + if ( *node ) { + cur = ( *node )->next; + } + *node = 0; + } + + while ( cur ) + { + FT_Renderer renderer = FT_RENDERER( cur->data ); + + + if ( renderer->glyph_format == format ) { + if ( node ) { + *node = cur; + } + + result = renderer; + break; + } + cur = cur->next; + } + +Exit: + return result; +} + + +static +FT_Renderer ft_lookup_glyph_renderer( FT_GlyphSlot slot ) { + FT_Face face = slot->face; + FT_Library library = FT_FACE_LIBRARY( face ); + FT_Renderer result = library->cur_renderer; + + + if ( !result || result->glyph_format != slot->format ) { + result = FT_Lookup_Renderer( library, slot->format, 0 ); + } + + return result; +} + + +static +void ft_set_current_renderer( FT_Library library ) { + FT_Renderer renderer; + + + renderer = FT_Lookup_Renderer( library, ft_glyph_format_outline, 0 ); + library->cur_renderer = renderer; +} + + +static +FT_Error ft_add_renderer( FT_Module module ) { + FT_Library library = module->library; + FT_Memory memory = library->memory; + FT_Error error; + FT_ListNode node; + + + if ( ALLOC( node, sizeof( *node ) ) ) { + goto Exit; + } + + { + FT_Renderer render = FT_RENDERER( module ); + FT_Renderer_Class* clazz = (FT_Renderer_Class*)module->clazz; + + + render->clazz = clazz; + render->glyph_format = clazz->glyph_format; + + /* allocate raster object if needed */ + if ( clazz->glyph_format == ft_glyph_format_outline && + clazz->raster_class->raster_new ) { + error = clazz->raster_class->raster_new( memory, &render->raster ); + if ( error ) { + goto Fail; + } + + render->raster_render = clazz->raster_class->raster_render; + render->render = clazz->render_glyph; + } + + /* add to list */ + node->data = module; + FT_List_Add( &library->renderers, node ); + + ft_set_current_renderer( library ); + } + +Fail: + if ( error ) { + FREE( node ); + } + +Exit: + return error; +} + + +static +void ft_remove_renderer( FT_Module module ) { + FT_Library library = module->library; + FT_Memory memory = library->memory; + FT_ListNode node; + + + node = FT_List_Find( &library->renderers, module ); + if ( node ) { + FT_Renderer render = FT_RENDERER( module ); + + + /* release raster object, if any */ + if ( render->raster ) { + render->clazz->raster_class->raster_done( render->raster ); + } + + /* remove from list */ + FT_List_Remove( &library->renderers, node ); + FREE( node ); + + ft_set_current_renderer( library ); + } +} + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Get_Renderer */ +/* */ +/* */ +/* Retrieves the current renderer for a given glyph format. */ +/* */ +/* */ +/* library :: A handle to the library object. */ +/* */ +/* format :: The glyph format. */ +/* */ +/* */ +/* A renderer handle. 0 if none found. */ +/* */ +/* */ +/* An error will be returned if a module already exists by that name, */ +/* or if the module requires a version of FreeType that is too great. */ +/* */ +/* To add a new renderer, simply use FT_Add_Module(). To retrieve a */ +/* renderer by its name, use FT_Get_Module(). */ +/* */ +FT_EXPORT_FUNC( FT_Renderer ) FT_Get_Renderer( FT_Library library, + FT_Glyph_Format format ) +{ + /* test for valid `library' delayed to FT_Lookup_Renderer() */ + + return FT_Lookup_Renderer( library, format, 0 ); +} + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Set_Renderer */ +/* */ +/* */ +/* Sets the current renderer to use, and set additional mode. */ +/* */ +/* */ +/* library :: A handle to the library object. */ +/* */ +/* renderer :: A handle to the renderer object. */ +/* */ +/* num_params :: The number of additional parameters. */ +/* */ +/* parameters :: Additional parameters. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +/* */ +/* In case of success, the renderer will be used to convert glyph */ +/* images in the renderer's known format into bitmaps. */ +/* */ +/* This doesn't change the current renderer for other formats. */ +/* */ +FT_EXPORT_DEF( FT_Error ) FT_Set_Renderer( FT_Library library, + FT_Renderer renderer, + FT_UInt num_params, + FT_Parameter * parameters ) +{ + FT_ListNode node; + FT_Error error = FT_Err_Ok; + + + if ( !library ) { + return FT_Err_Invalid_Library_Handle; + } + + if ( !renderer ) { + return FT_Err_Invalid_Argument; + } + + node = FT_List_Find( &library->renderers, renderer ); + if ( !node ) { + error = FT_Err_Invalid_Argument; + goto Exit; + } + + FT_List_Up( &library->renderers, node ); + + if ( renderer->glyph_format == ft_glyph_format_outline ) { + library->cur_renderer = renderer; + } + + if ( num_params > 0 ) { + FTRenderer_setMode set_mode = renderer->clazz->set_mode; + + + for ( ; num_params > 0; num_params-- ) + { + error = set_mode( renderer, parameters->tag, parameters->data ); + if ( error ) { + break; + } + } + } + +Exit: + return error; +} + + +LOCAL_FUNC +FT_Error FT_Render_Glyph_Internal( FT_Library library, + FT_GlyphSlot slot, + FT_UInt render_mode ) { + FT_Error error = FT_Err_Ok; + FT_Renderer renderer; + + + /* if it is already a bitmap, no need to do anything */ + switch ( slot->format ) + { + case ft_glyph_format_bitmap: /* already a bitmap, don't do anything */ + break; + + default: + { + FT_ListNode node = 0; + FT_Bool update = 0; + + + /* small shortcut for the very common case */ + if ( slot->format == ft_glyph_format_outline ) { + renderer = library->cur_renderer; + node = library->renderers.head; + } else { + renderer = FT_Lookup_Renderer( library, slot->format, &node ); + } + + error = FT_Err_Unimplemented_Feature; + while ( renderer ) + { + error = renderer->render( renderer, slot, render_mode, 0 ); + if ( !error || error != FT_Err_Cannot_Render_Glyph ) { + break; + } + + /* FT_Err_Cannot_Render_Glyph is returned if the render mode */ + /* is unsupported by the current renderer for this glyph image */ + /* format. */ + + /* now, look for another renderer that supports the same */ + /* format. */ + renderer = FT_Lookup_Renderer( library, slot->format, &node ); + update = 1; + } + + /* if we changed the current renderer for the glyph image format */ + /* we need to select it as the next current one */ + if ( !error && update && renderer ) { + FT_Set_Renderer( library, renderer, 0, 0 ); + } + } + } + + return error; +} + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Render_Glyph */ +/* */ +/* */ +/* Converts a given glyph image to a bitmap. It does so by */ +/* inspecting the glyph image format, find the relevant renderer, and */ +/* invoke it. */ +/* */ +/* */ +/* slot :: A handle to the glyph slot containing the image to */ +/* convert. */ +/* */ +/* render_mode :: This is the render mode used to render the glyph */ +/* image into a bitmap. See FT_Render_Mode for a list */ +/* of possible values. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +FT_EXPORT_FUNC( FT_Error ) FT_Render_Glyph( FT_GlyphSlot slot, + FT_UInt render_mode ) +{ + FT_Library library; + + + if ( !slot ) { + return FT_Err_Invalid_Argument; + } + + library = FT_FACE_LIBRARY( slot->face ); + + return FT_Render_Glyph_Internal( library, slot, render_mode ); +} + + +/*************************************************************************/ +/*************************************************************************/ +/*************************************************************************/ +/**** ****/ +/**** ****/ +/**** M O D U L E S ****/ +/**** ****/ +/**** ****/ +/*************************************************************************/ +/*************************************************************************/ +/*************************************************************************/ + + +/*************************************************************************/ +/* */ +/* */ +/* Destroy_Module */ +/* */ +/* */ +/* Destroys a given module object. For drivers, this also destroys */ +/* all child faces. */ +/* */ +/* */ +/* module :: A handle to the target driver object. */ +/* */ +/* */ +/* The driver _must_ be LOCKED! */ +/* */ +static +void Destroy_Module( FT_Module module ) { + FT_Memory memory = module->memory; + FT_Module_Class* clazz = module->clazz; + FT_Library library = module->library; + + + /* finalize client-data - before anything else */ + if ( module->generic.finalizer ) { + module->generic.finalizer( module ); + } + + if ( library && library->auto_hinter == module ) { + library->auto_hinter = 0; + } + + /* if the module is a renderer */ + if ( FT_MODULE_IS_RENDERER( module ) ) { + ft_remove_renderer( module ); + } + + /* if the module is a font driver, add some steps */ + if ( FT_MODULE_IS_DRIVER( module ) ) { + Destroy_Driver( FT_DRIVER( module ) ); + } + + /* finalize the module object */ + if ( clazz->module_done ) { + clazz->module_done( module ); + } + + /* discard it */ + FREE( module ); +} + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Add_Module */ +/* */ +/* */ +/* Adds a new module to a given library instance. */ +/* */ +/* */ +/* library :: A handle to the library object. */ +/* */ +/* clazz :: A pointer to class descriptor for the module. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +/* */ +/* An error will be returned if a module already exists by that name, */ +/* or if the module requires a version of FreeType that is too great. */ +/* */ +FT_EXPORT_FUNC( FT_Error ) FT_Add_Module( FT_Library library, + const FT_Module_Class * clazz ) +{ + FT_Error error; + FT_Memory memory; + FT_Module module; + FT_UInt nn; + + +#define FREETYPE_VER_FIXED ( ( (FT_Long)FREETYPE_MAJOR << 16 ) | \ + FREETYPE_MINOR ) + + if ( !library ) { + return FT_Err_Invalid_Library_Handle; + } + + if ( !clazz ) { + return FT_Err_Invalid_Argument; + } + + /* check freetype version */ + if ( clazz->module_requires > FREETYPE_VER_FIXED ) { + return FT_Err_Invalid_Version; + } + + /* look for a module with the same name in the library's table */ + for ( nn = 0; nn < library->num_modules; nn++ ) + { + module = library->modules[nn]; + if ( strcmp( module->clazz->module_name, clazz->module_name ) == 0 ) { + /* this installed module has the same name, compare their versions */ + if ( clazz->module_version <= module->clazz->module_version ) { + return FT_Err_Lower_Module_Version; + } + + /* remove the module from our list, then exit the loop to replace */ + /* it by our new version.. */ + FT_Remove_Module( library, module ); + break; + } + } + + memory = library->memory; + error = FT_Err_Ok; + + if ( library->num_modules >= FT_MAX_MODULES ) { + error = FT_Err_Too_Many_Drivers; + goto Exit; + } + + /* allocate module object */ + if ( ALLOC( module,clazz->module_size ) ) { + goto Exit; + } + + /* base initialization */ + module->library = library; + module->memory = memory; + module->clazz = (FT_Module_Class*)clazz; + + /* check whether the module is a renderer - this must be performed */ + /* before the normal module initialization */ + if ( FT_MODULE_IS_RENDERER( module ) ) { + /* add to the renderers list */ + error = ft_add_renderer( module ); + if ( error ) { + goto Fail; + } + } + + /* is the module a auto-hinter? */ + if ( FT_MODULE_IS_HINTER( module ) ) { + library->auto_hinter = module; + } + + /* if the module is a font driver */ + if ( FT_MODULE_IS_DRIVER( module ) ) { + /* allocate glyph loader if needed */ + FT_Driver driver = FT_DRIVER( module ); + + + driver->clazz = (FT_Driver_Class*)module->clazz; + if ( FT_DRIVER_USES_OUTLINES( driver ) ) { + error = FT_GlyphLoader_New( memory, &driver->glyph_loader ); + if ( error ) { + goto Fail; + } + } + } + + if ( clazz->module_init ) { + error = clazz->module_init( module ); + if ( error ) { + goto Fail; + } + } + + /* add module to the library's table */ + library->modules[library->num_modules++] = module; + +Exit: + return error; + +Fail: + if ( FT_MODULE_IS_DRIVER( module ) ) { + FT_Driver driver = FT_DRIVER( module ); + + + if ( FT_DRIVER_USES_OUTLINES( driver ) ) { + FT_GlyphLoader_Done( driver->glyph_loader ); + } + } + + if ( FT_MODULE_IS_RENDERER( module ) ) { + FT_Renderer renderer = FT_RENDERER( module ); + + + if ( renderer->raster ) { + renderer->clazz->raster_class->raster_done( renderer->raster ); + } + } + + FREE( module ); + goto Exit; +} + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Get_Module */ +/* */ +/* */ +/* Finds a module by its name. */ +/* */ +/* */ +/* library :: A handle to the library object. */ +/* */ +/* module_name :: The module's name (as an ASCII string). */ +/* */ +/* */ +/* A module handle. 0 if none was found. */ +/* */ +/* */ +/* You should better be familiar with FreeType internals to know */ +/* which module to look for :-) */ +/* */ +FT_EXPORT_FUNC( FT_Module ) FT_Get_Module( FT_Library library, + const char* module_name ) +{ + FT_Module result = 0; + FT_Module* cur; + FT_Module* limit; + + + if ( !library || !module_name ) { + return result; + } + + cur = library->modules; + limit = cur + library->num_modules; + + for ( ; cur < limit; cur++ ) + if ( strcmp( cur[0]->clazz->module_name, module_name ) == 0 ) { + result = cur[0]; + break; + } + + return result; +} + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Get_Module_Interface */ +/* */ +/* */ +/* Finds a module and returns its specific interface as a typeless */ +/* pointer. */ +/* */ +/* */ +/* library :: A handle to the library object. */ +/* */ +/* module_name :: The module's name (as an ASCII string). */ +/* */ +/* */ +/* A module-specific interface if available, 0 otherwise. */ +/* */ +/* */ +/* You should better be familiar with FreeType internals to know */ +/* which module to look for, and what its interface is :-) */ +/* */ +BASE_FUNC( const void* ) FT_Get_Module_Interface( FT_Library library, + const char* mod_name ) +{ + FT_Module module; + + + /* test for valid `library' delayed to FT_Get_Module() */ + + module = FT_Get_Module( library, mod_name ); + + return module ? module->clazz->module_interface : 0; +} + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Remove_Module */ +/* */ +/* */ +/* Removes a given module from a library instance. */ +/* */ +/* */ +/* library :: A handle to a library object. */ +/* */ +/* module :: A handle to a module object. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +/* */ +/* The module object is destroyed by the function in case of success. */ +/* */ +FT_EXPORT_FUNC( FT_Error ) FT_Remove_Module( FT_Library library, + FT_Module module ) +{ + /* try to find the module from the table, then remove it from there */ + + if ( !library ) { + return FT_Err_Invalid_Library_Handle; + } + + if ( module ) { + FT_Module* cur = library->modules; + FT_Module* limit = cur + library->num_modules; + + + for ( ; cur < limit; cur++ ) + { + if ( cur[0] == module ) { + /* remove it from the table */ + library->num_modules--; + limit--; + while ( cur < limit ) + { + cur[0] = cur[1]; + cur++; + } + limit[0] = 0; + + /* destroy the module */ + Destroy_Module( module ); + + return FT_Err_Ok; + } + } + } + return FT_Err_Invalid_Driver_Handle; +} + + +/*************************************************************************/ +/*************************************************************************/ +/*************************************************************************/ +/**** ****/ +/**** ****/ +/**** L I B R A R Y ****/ +/**** ****/ +/**** ****/ +/*************************************************************************/ +/*************************************************************************/ +/*************************************************************************/ + + +/*************************************************************************/ +/* */ +/* */ +/* FT_New_Library */ +/* */ +/* */ +/* This function is used to create a new FreeType library instance */ +/* from a given memory object. It is thus possible to use libraries */ +/* with distinct memory allocators within the same program. */ +/* */ +/* */ +/* memory :: A handle to the original memory object. */ +/* */ +/* */ +/* alibrary :: A pointer to handle of a new library object. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +FT_EXPORT_FUNC( FT_Error ) FT_New_Library( FT_Memory memory, + FT_Library * alibrary ) +{ + FT_Library library = 0; + FT_Error error; + + + if ( !memory ) { + return FT_Err_Invalid_Argument; + } + + /* first of all, allocate the library object */ + if ( ALLOC( library, sizeof( *library ) ) ) { + return error; + } + + library->memory = memory; + + /* allocate the render pool */ + library->raster_pool_size = FT_RENDER_POOL_SIZE; + if ( ALLOC( library->raster_pool, FT_RENDER_POOL_SIZE ) ) { + goto Fail; + } + + /* That's ok now */ + *alibrary = library; + + return FT_Err_Ok; + +Fail: + FREE( library ); + return error; +} + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Done_Library */ +/* */ +/* */ +/* Discards a given library object. This closes all drivers and */ +/* discards all resource objects. */ +/* */ +/* */ +/* library :: A handle to the target library. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +FT_EXPORT_FUNC( FT_Error ) FT_Done_Library( FT_Library library ) +{ + FT_Memory memory; + FT_UInt n; + + + if ( !library ) { + return FT_Err_Invalid_Library_Handle; + } + + memory = library->memory; + + /* Discard client-data */ + if ( library->generic.finalizer ) { + library->generic.finalizer( library ); + } + + /* Close all modules in the library */ + for ( n = 0; n < library->num_modules; n++ ) + { + FT_Module module = library->modules[n]; + + + if ( module ) { + Destroy_Module( module ); + library->modules[n] = 0; + } + } + + /* Destroy raster objects */ + FREE( library->raster_pool ); + library->raster_pool_size = 0; + + FREE( library ); + return FT_Err_Ok; +} + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Set_Debug_Hook */ +/* */ +/* */ +/* Sets a debug hook function for debugging the interpreter of a font */ +/* format. */ +/* */ +/* */ +/* library :: A handle to the library object. */ +/* */ +/* hook_index :: The index of the debug hook. You should use the */ +/* values defined in ftobjs.h, e.g. */ +/* FT_DEBUG_HOOK_TRUETYPE */ +/* */ +/* debug_hook :: The function used to debug the interpreter. */ +/* */ +/* */ +/* Currently, four debug hook slots are available, but only two (for */ +/* the TrueType and the Type 1 interpreter) are defined. */ +/* */ +FT_EXPORT_FUNC( void ) FT_Set_Debug_Hook( FT_Library library, + FT_UInt hook_index, + FT_DebugHook_Func debug_hook ) +{ + if ( library && debug_hook && + hook_index < + ( sizeof( library->debug_hooks ) / sizeof( void* ) ) ) { + library->debug_hooks[hook_index] = debug_hook; + } +} + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Done_FreeType */ +/* */ +/* */ +/* Destroys a given FreeType library object and all of its childs, */ +/* including resources, drivers, faces, sizes, etc. */ +/* */ +/* */ +/* library :: A handle to the target library object. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +FT_EXPORT_FUNC( FT_Error ) FT_Done_FreeType( FT_Library library ) +{ + /* test for valid `library' delayed to FT_Done_Library() */ + + /* Discard the library object */ + FT_Done_Library( library ); + + return FT_Err_Ok; +} + + +/* END */ diff --git a/Projects/Android/jni/rtcw/src/ft2/ftobjs.h b/Projects/Android/jni/rtcw/src/ft2/ftobjs.h new file mode 100644 index 0000000..002c9e7 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/ft2/ftobjs.h @@ -0,0 +1,532 @@ +/***************************************************************************/ +/* */ +/* ftobjs.h */ +/* */ +/* The FreeType private base classes (specification). */ +/* */ +/* Copyright 1996-2000 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +/*************************************************************************/ +/* */ +/* This file contains the definition of all internal FreeType classes. */ +/* */ +/*************************************************************************/ + + +#ifndef FTOBJS_H +#define FTOBJS_H + +#include "ftmemory.h" +#include "ftrender.h" +#include "ftdriver.h" +#include "autohint.h" + + +#ifdef __cplusplus +extern "C" { +#endif + + +/*************************************************************************/ +/* */ +/* Some generic definitions. */ +/* */ +#ifndef TRUE +#define TRUE 1 +#endif + +#ifndef FALSE +#define FALSE 0 +#endif + +#ifndef NULL +#define NULL (void*)0 +#endif + +#ifndef UNUSED +#define UNUSED( arg ) ( ( arg ) = ( arg ) ) +#endif + + +/*************************************************************************/ +/* */ +/* The min and max functions missing in C. As usual, be careful not to */ +/* write things like MIN( a++, b++ ) to avoid side effects. */ +/* */ +#ifndef MIN +#define MIN( a, b ) ( ( a ) < ( b ) ? ( a ) : ( b ) ) +#endif + +#ifndef MAX +#define MAX( a, b ) ( ( a ) > ( b ) ? ( a ) : ( b ) ) +#endif + +#ifndef ABS +#define ABS( a ) ( ( a ) < 0 ? -( a ) : ( a ) ) +#endif + + +/*************************************************************************/ +/*************************************************************************/ +/*************************************************************************/ +/**** ****/ +/**** ****/ +/**** M O D U L E S ****/ +/**** ****/ +/**** ****/ +/*************************************************************************/ +/*************************************************************************/ +/*************************************************************************/ + + +/*************************************************************************/ +/* */ +/* */ +/* FT_ModuleRec */ +/* */ +/* */ +/* A module object instance. */ +/* */ +/* */ +/* clazz :: A pointer to the module's class. */ +/* */ +/* library :: A handle to the parent library object. */ +/* */ +/* memory :: A handle to the memory manager. */ +/* */ +/* generic :: A generic structure for user-level extensibility (?). */ +/* */ +typedef struct FT_ModuleRec_ +{ + FT_Module_Class* clazz; + FT_Library library; + FT_Memory memory; + FT_Generic generic; + +} FT_ModuleRec; + + +/* typecast an object to a FT_Module */ +#define FT_MODULE( x ) ( (FT_Module)( x ) ) +#define FT_MODULE_CLASS( x ) FT_MODULE( x )->clazz +#define FT_MODULE_LIBRARY( x ) FT_MODULE( x )->library +#define FT_MODULE_MEMORY( x ) FT_MODULE( x )->memory + +#define FT_MODULE_IS_DRIVER( x ) ( FT_MODULE_CLASS( x )->module_flags & \ + ft_module_font_driver ) + +#define FT_MODULE_IS_RENDERER( x ) ( FT_MODULE_CLASS( x )->module_flags & \ + ft_module_renderer ) + +#define FT_MODULE_IS_HINTER( x ) ( FT_MODULE_CLASS( x )->module_flags & \ + ft_module_hinter ) + +#define FT_MODULE_IS_STYLER( x ) ( FT_MODULE_CLASS( x )->module_flags & \ + ft_module_styler ) + +#define FT_DRIVER_IS_SCALABLE( x ) ( FT_MODULE_CLASS( x )->module_flags & \ + ft_module_driver_scalable ) + +#define FT_DRIVER_USES_OUTLINES( x ) !( FT_MODULE_CLASS( x )->module_flags & \ + ft_module_driver_no_outlines ) + +#define FT_DRIVER_HAS_HINTER( x ) ( FT_MODULE_CLASS( x )->module_flags & \ + ft_module_driver_has_hinter ) + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Get_Module_Interface */ +/* */ +/* */ +/* Finds a module and returns its specific interface as a typeless */ +/* pointer. */ +/* */ +/* */ +/* library :: A handle to the library object. */ +/* */ +/* module_name :: The module's name (as an ASCII string). */ +/* */ +/* */ +/* A module-specific interface if available, 0 otherwise. */ +/* */ +/* */ +/* You should better be familiar with FreeType internals to know */ +/* which module to look for, and what its interface is :-) */ +/* */ +BASE_DEF( const void* ) FT_Get_Module_Interface( FT_Library library, + const char* mod_name ); + + +/*************************************************************************/ +/*************************************************************************/ +/*************************************************************************/ +/**** ****/ +/**** ****/ +/**** FACE, SIZE & GLYPH SLOT OBJECTS ****/ +/**** ****/ +/**** ****/ +/*************************************************************************/ +/*************************************************************************/ +/*************************************************************************/ + +/* a few macros used to perform easy typecasts with minimal brain damage */ + +#define FT_FACE( x ) ( (FT_Face)( x ) ) +#define FT_SIZE( x ) ( (FT_Size)( x ) ) +#define FT_SLOT( x ) ( (FT_GlyphSlot)( x ) ) + +#define FT_FACE_DRIVER( x ) FT_FACE( x )->driver +#define FT_FACE_LIBRARY( x ) FT_FACE_DRIVER( x )->root.library +#define FT_FACE_MEMORY( x ) FT_FACE( x )->memory + +#define FT_SIZE_FACE( x ) FT_SIZE( x )->face +#define FT_SLOT_FACE( x ) FT_SLOT( x )->face + +#define FT_FACE_SLOT( x ) FT_FACE( x )->glyph +#define FT_FACE_SIZE( x ) FT_FACE( x )->size + + +/* this must be kept exported -- tt will be used later in our own */ +/* high-level caching font manager called SemTex (way after the */ +/* 2.0 release though */ +FT_EXPORT_DEF( FT_Error ) FT_New_Size( FT_Face face, + FT_Size * size ); + +FT_EXPORT_DEF( FT_Error ) FT_Done_Size( FT_Size size ); + + +FT_EXPORT_DEF( FT_Error ) FT_New_GlyphSlot( FT_Face face, + FT_GlyphSlot * aslot ); + +FT_EXPORT_DEF( void ) FT_Done_GlyphSlot( FT_GlyphSlot slot ); + + +/*************************************************************************/ +/*************************************************************************/ +/*************************************************************************/ +/**** ****/ +/**** ****/ +/**** G L Y P H L O A D E R ****/ +/**** ****/ +/**** ****/ +/*************************************************************************/ +/*************************************************************************/ +/*************************************************************************/ + + +#define FT_SUBGLYPH_FLAG_ARGS_ARE_WORDS 1 +#define FT_SUBGLYPH_FLAG_ARGS_ARE_XY_VALUES 2 +#define FT_SUBGLYPH_FLAG_ROUND_XY_TO_GRID 4 +#define FT_SUBGLYPH_FLAG_SCALE 8 +#define FT_SUBGLYPH_FLAG_XY_SCALE 0x40 +#define FT_SUBGLYPH_FLAG_2X2 0x80 +#define FT_SUBGLYPH_FLAG_USE_MY_METRICS 0x200 + + +enum +{ + ft_glyph_own_bitmap = 1 +}; + + +struct FT_SubGlyph_ +{ + FT_Int index; + FT_UShort flags; + FT_Int arg1; + FT_Int arg2; + FT_Matrix transform; +}; + + +typedef struct FT_GlyphLoad_ +{ + FT_Outline outline; /* outline */ + FT_UInt num_subglyphs; /* number of subglyphs */ + FT_SubGlyph* subglyphs; /* subglyphs */ + FT_Vector* extra_points; /* extra points table */ + +} FT_GlyphLoad; + + +struct FT_GlyphLoader_ +{ + FT_Memory memory; + FT_UInt max_points; + FT_UInt max_contours; + FT_UInt max_subglyphs; + FT_Bool use_extra; + + FT_GlyphLoad base; + FT_GlyphLoad current; + + void* other; /* for possible future extension? */ + +}; + + +BASE_DEF( FT_Error ) FT_GlyphLoader_New( FT_Memory memory, + FT_GlyphLoader * *aloader ); + +BASE_DEF( FT_Error ) FT_GlyphLoader_Create_Extra( + FT_GlyphLoader * loader ); + +BASE_DEF( void ) FT_GlyphLoader_Done( FT_GlyphLoader * loader ); + +BASE_DEF( void ) FT_GlyphLoader_Reset( FT_GlyphLoader * loader ); + +BASE_DEF( void ) FT_GlyphLoader_Rewind( FT_GlyphLoader * loader ); + +BASE_DEF( FT_Error ) FT_GlyphLoader_Check_Points( + FT_GlyphLoader * loader, + FT_UInt n_points, + FT_UInt n_contours ); + +BASE_DEF( FT_Error ) FT_GlyphLoader_Check_Subglyphs( + FT_GlyphLoader * loader, + FT_UInt n_subs ); + +BASE_DEF( void ) FT_GlyphLoader_Prepare( FT_GlyphLoader * loader ); + +BASE_DEF( void ) FT_GlyphLoader_Add( FT_GlyphLoader * loader ); + +BASE_DEF( FT_Error ) FT_GlyphLoader_Copy_Points( FT_GlyphLoader * target, + FT_GlyphLoader * source ); + + +/*************************************************************************/ +/*************************************************************************/ +/*************************************************************************/ +/**** ****/ +/**** ****/ +/**** R E N D E R E R S ****/ +/**** ****/ +/**** ****/ +/*************************************************************************/ +/*************************************************************************/ +/*************************************************************************/ + + +#define FT_RENDERER( x ) ( (FT_Renderer)( x ) ) +#define FT_GLYPH( x ) ( (FT_Glyph)( x ) ) +#define FT_BITMAP_GLYPH( x ) ( (FT_BitmapGlyph)( x ) ) +#define FT_OUTLINE_GLYPH( x ) ( (FT_OutlineGlyph)( x ) ) + + +typedef struct FT_RendererRec_ +{ + FT_ModuleRec root; + FT_Renderer_Class* clazz; + FT_Glyph_Format glyph_format; + const FT_Glyph_Class glyph_class; + + FT_Raster raster; + FT_Raster_Render_Func raster_render; + FTRenderer_render render; + +} FT_RendererRec; + + +/*************************************************************************/ +/*************************************************************************/ +/*************************************************************************/ +/**** ****/ +/**** ****/ +/**** F O N T D R I V E R S ****/ +/**** ****/ +/**** ****/ +/*************************************************************************/ +/*************************************************************************/ +/*************************************************************************/ + + +/* typecast a module into a driver easily */ +#define FT_DRIVER( x ) ( (FT_Driver)( x ) ) + +/* typecast a module as a driver, and get its driver class */ +#define FT_DRIVER_CLASS( x ) FT_DRIVER( x )->clazz + + +/*************************************************************************/ +/* */ +/* */ +/* FT_DriverRec */ +/* */ +/* */ +/* The root font driver class. A font driver is responsible for */ +/* managing and loading font files of a given format. */ +/* */ +/* */ +/* root :: Contains the fields of the root module class. */ +/* */ +/* clazz :: A pointer to the font driver's class. Note that */ +/* this is NOT root.clazz. `class' wasn't used */ +/* as it is a reserved word in C++. */ +/* */ +/* faces_list :: The list of faces currently opened by this */ +/* driver. */ +/* */ +/* extensions :: A typeless pointer to the driver's extensions */ +/* registry, if they are supported through the */ +/* configuration macro FT_CONFIG_OPTION_EXTENSIONS. */ +/* */ +/* glyph_loader :: The glyph loader for all faces managed by this */ +/* driver. This object isn't defined for unscalable */ +/* formats. */ +/* */ +typedef struct FT_DriverRec_ +{ + FT_ModuleRec root; + FT_Driver_Class* clazz; + + FT_ListRec faces_list; + void* extensions; + + FT_GlyphLoader* glyph_loader; + +} FT_DriverRec; + + +/*************************************************************************/ +/*************************************************************************/ +/*************************************************************************/ +/**** ****/ +/**** ****/ +/**** L I B R A R I E S ****/ +/**** ****/ +/**** ****/ +/*************************************************************************/ +/*************************************************************************/ +/*************************************************************************/ + + +#define FT_DEBUG_HOOK_TRUETYPE 0 +#define FT_DEBUG_HOOK_TYPE1 1 + + +/*************************************************************************/ +/* */ +/* */ +/* FT_LibraryRec */ +/* */ +/* */ +/* The FreeType library class. This is the root of all FreeType */ +/* data. Use FT_New_Library() to create a library object, and */ +/* FT_Done_Library() to discard it and all child objects. */ +/* */ +/* */ +/* memory :: The library's memory object. Manages memory */ +/* allocation. */ +/* */ +/* generic :: Client data variable. Used to extend the */ +/* Library class by higher levels and clients. */ +/* */ +/* num_modules :: The number of modules currently registered */ +/* within this library. This is set to 0 for new */ +/* libraries. New modules are added through the */ +/* FT_Add_Module() API function. */ +/* */ +/* modules :: A table used to store handles to the currently */ +/* registered modules. Note that each font driver */ +/* contains a list of its opened faces. */ +/* */ +/* renderers :: The list of renderers currently registered */ +/* within the library. */ +/* */ +/* cur_renderer :: The current outline renderer. This is a */ +/* shortcut used to avoid parsing the list on */ +/* each call to FT_Outline_Render(). It is a */ +/* handle to the current renderer for the */ +/* ft_glyph_format_outline format. */ +/* */ +/* auto_hinter :: XXX */ +/* */ +/* raster_pool :: The raster object's render pool. This can */ +/* ideally be changed dynamically at run-time. */ +/* */ +/* raster_pool_size :: The size of the render pool in bytes. */ +/* */ +/* debug_hooks :: XXX */ +/* */ +typedef struct FT_LibraryRec_ +{ + FT_Memory memory; /* library's memory manager */ + + FT_Generic generic; + + FT_UInt num_modules; + FT_Module modules[FT_MAX_MODULES]; /* module objects */ + + FT_ListRec renderers; /* list of renderers */ + FT_Renderer cur_renderer; /* current outline renderer */ + FT_Module auto_hinter; + + FT_Byte* raster_pool; /* scan-line conversion */ + /* render pool */ + FT_ULong raster_pool_size; /* size of render pool in bytes */ + + FT_DebugHook_Func debug_hooks[4]; + +} FT_LibraryRec; + + +BASE_DEF( FT_Renderer ) FT_Lookup_Renderer( FT_Library library, + FT_Glyph_Format format, + FT_ListNode * node ); + +BASE_DEF( FT_Error ) FT_Render_Glyph_Internal( FT_Library library, + FT_GlyphSlot slot, + FT_UInt render_mode ); + +typedef FT_Error ( *FT_Glyph_Name_Requester )( FT_Face face, + FT_UInt glyph_index, + FT_Pointer buffer, + FT_UInt buffer_max ); + + +#ifndef FT_CONFIG_OPTION_NO_DEFAULT_SYSTEM + + +FT_EXPORT_DEF( FT_Error ) FT_New_Stream( const char* filepathname, + FT_Stream astream ); + +FT_EXPORT_DEF( void ) FT_Done_Stream( FT_Stream stream ); + +FT_EXPORT_DEF( FT_Memory ) FT_New_Memory( void ); + + +#endif /* !FT_CONFIG_OPTION_NO_DEFAULT_SYSTEM */ + + +/* Define default raster's interface. The default raster is located in */ +/* `src/base/ftraster.c' */ +/* */ +/* Client applications can register new rasters through the */ +/* FT_Set_Raster() API. */ + +#ifndef FT_NO_DEFAULT_RASTER +FT_EXPORT_VAR( FT_Raster_Funcs ) ft_default_raster; +#endif + + +#ifdef __cplusplus +} +#endif + + +#endif /* FTOBJS_H */ + + +/* END */ diff --git a/Projects/Android/jni/rtcw/src/ft2/ftoption.h b/Projects/Android/jni/rtcw/src/ft2/ftoption.h new file mode 100644 index 0000000..137087c --- /dev/null +++ b/Projects/Android/jni/rtcw/src/ft2/ftoption.h @@ -0,0 +1,395 @@ +/***************************************************************************/ +/* */ +/* ftoption.h */ +/* */ +/* User-selectable configuration macros (specification only). */ +/* */ +/* Copyright 1996-2000 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef FTOPTION_H +#define FTOPTION_H + + +/*************************************************************************/ +/* */ +/* USER-SELECTABLE CONFIGURATION MACROS */ +/* */ +/* These macros can be toggled by developers to enable or disable */ +/* certain aspects of FreeType. This is a default file, where all major */ +/* options are enabled. */ +/* */ +/* Note that if some modifications are required for your build, we */ +/* advise you to put a modified copy of this file in your build */ +/* directory, rather than modifying it in-place. */ +/* */ +/* The build directory is normally `freetype/builds/' and */ +/* contains build or system-specific files that are included in */ +/* priority when building the library. */ +/* */ +/*************************************************************************/ + + +/*************************************************************************/ +/*************************************************************************/ +/**** ****/ +/**** G E N E R A L F R E E T Y P E 2 C O N F I G U R A T I O N ****/ +/**** ****/ +/*************************************************************************/ +/*************************************************************************/ + + +/*************************************************************************/ +/* */ +/* Convenience functions support */ +/* */ +/* Some functions of the FreeType 2 API are provided as a convenience */ +/* for client applications and developers. However, they are not */ +/* required to build and run the library itself. */ +/* */ +/* By defining this configuration macro, you'll disable the */ +/* compilation of these functions at build time. This can be useful */ +/* to reduce the library's code size when you don't need any of */ +/* these functions. */ +/* */ +/* All convenience functions are declared as such in their */ +/* documentation. */ +/* */ +#undef FT_CONFIG_OPTION_NO_CONVENIENCE_FUNCS + + +/*************************************************************************/ +/* */ +/* Alternate Glyph Image Format support */ +/* */ +/* By default, the glyph images returned by the FreeType glyph loader */ +/* can either be a pixmap or a vectorial outline defined through */ +/* Bezier control points. When defining the following configuration */ +/* macro, some font drivers will be able to register alternate */ +/* glyph image formats. */ +/* */ +/* Unset this macro if you are sure that you will never use a font */ +/* driver with an alternate glyph format; this will reduce the size of */ +/* the base layer code. */ +/* */ +/* Note that a few Type 1 fonts, as well as Windows `vector' fonts */ +/* use a vector `plotter' format that isn't supported when this */ +/* macro is undefined. */ +/* */ +#define FT_CONFIG_OPTION_ALTERNATE_GLYPH_FORMATS + + +/*************************************************************************/ +/* */ +/* Glyph Postscript Names handling */ +/* */ +/* By default, FreeType 2 is compiled with the `PSNames' module. This */ +/* This module is in charge of converting a glyph name string into a */ +/* Unicode value, or return a Macintosh standard glyph name for the */ +/* use with the TrueType `post' table. */ +/* */ +/* Undefine this macro if you do not want `PSNames' compiled in your */ +/* build of FreeType. This has the following effects: */ +/* */ +/* - The TrueType driver will provide its own set of glyph names, */ +/* if you build it to support postscript names in the TrueType */ +/* `post' table. */ +/* */ +/* - The Type 1 driver will not be able to synthetize a Unicode */ +/* charmap out of the glyphs found in the fonts. */ +/* */ +/* You would normally undefine this configuration macro when building */ +/* a version of FreeType that doesn't contain a Type 1 or CFF driver. */ +/* */ +#define FT_CONFIG_OPTION_POSTSCRIPT_NAMES + + +/*************************************************************************/ +/* */ +/* Postscript Names to Unicode Values support */ +/* */ +/* By default, FreeType 2 is built with the `PSNames' module compiled */ +/* in. Among other things, the module is used to convert a glyph name */ +/* into a Unicode value. This is especially useful in order to */ +/* synthetize on the fly a Unicode charmap from the CFF/Type 1 driver */ +/* through a big table named the `Adobe Glyph List' (AGL). */ +/* */ +/* Undefine this macro if you do not want the Adobe Glyph List */ +/* compiled in your `PSNames' module. The Type 1 driver will not be */ +/* able to synthetize a Unicode charmap out of the glyphs found in the */ +/* fonts. */ +/* */ +#define FT_CONFIG_OPTION_ADOBE_GLYPH_LIST + + +/*************************************************************************/ +/* */ +/* Many compilers provide the non-ANSI `long long' 64-bit type. You can */ +/* activate it by defining the FTCALC_USE_LONG_LONG macro. Note that */ +/* this will produce many -ansi warnings during library compilation, and */ +/* that in many cases the generated code will not be smaller or faster! */ +/* */ +#undef FTCALC_USE_LONG_LONG + + +/*************************************************************************/ +/* */ +/* DLL export compilation */ +/* */ +/* When compiling FreeType as a DLL, some systems/compilers need a */ +/* special keyword in front OR after the return type of function */ +/* declarations. */ +/* */ +/* Two macros are used within the FreeType source code to define */ +/* exported library functions: FT_EXPORT_DEF and FT_EXPORT_FUNC. */ +/* */ +/* FT_EXPORT_DEF( return_type ) */ +/* */ +/* is used in a function declaration, as in */ +/* */ +/* FT_EXPORT_DEF( FT_Error ) */ +/* FT_Init_FreeType( FT_Library* alibrary ); */ +/* */ +/* */ +/* FT_EXPORT_FUNC( return_type ) */ +/* */ +/* is used in a function definition, as in */ +/* */ +/* FT_EXPORT_FUNC( FT_Error ) */ +/* FT_Init_FreeType( FT_Library* alibrary ) */ +/* { */ +/* ... some code ... */ +/* return FT_Err_Ok; */ +/* } */ +/* */ +/* You can provide your own implementation of FT_EXPORT_DEF and */ +/* FT_EXPORT_FUNC here if you want. If you leave them undefined, they */ +/* will be later automatically defined as `extern return_type' to */ +/* allow normal compilation. */ +/* */ +#undef FT_EXPORT_DEF +#undef FT_EXPORT_FUNC + + +/*************************************************************************/ +/* */ +/* Debug level */ +/* */ +/* FreeType can be compiled in debug or trace mode. In debug mode, */ +/* errors are reported through the `ftdebug' component. In trace */ +/* mode, additional messages are sent to the standard output during */ +/* execution. */ +/* */ +/* Define FT_DEBUG_LEVEL_ERROR to build the library in debug mode. */ +/* Define FT_DEBUG_LEVEL_TRACE to build it in trace mode. */ +/* */ +/* Don't define any of these macros to compile in `release' mode! */ +/* */ +//#define FT_DEBUG_LEVEL_ERROR +//#define FT_DEBUG_LEVEL_TRACE + + +/*************************************************************************/ +/* */ +/* Computation Algorithms */ +/* */ +/* Used for debugging, this configuration macro should disappear */ +/* soon. */ +/* */ +#define FT_CONFIG_OPTION_OLD_CALCS + + +/*************************************************************************/ +/* */ +/* The size in bytes of the render pool used by the scan-line converter */ +/* to do all of its work. */ +/* */ +/* This must be greater than 4kByte. */ +/* */ +#define FT_RENDER_POOL_SIZE 16384 + + +/*************************************************************************/ +/* */ +/* FT_MAX_MODULES */ +/* */ +/* The maximum number of modules that can be registered in a single */ +/* FreeType library object. 16 is the default. */ +/* */ +#define FT_MAX_MODULES 16 + + +/*************************************************************************/ +/* */ +/* FT_MAX_EXTENSIONS */ +/* */ +/* The maximum number of extensions that can be registered in a single */ +/* font driver. 8 is the default. */ +/* */ +/* If you don't know what this means, you certainly do not need to */ +/* change this value. */ +/* */ +#define FT_MAX_EXTENSIONS 8 + + +/*************************************************************************/ +/*************************************************************************/ +/**** ****/ +/**** S F N T D R I V E R C O N F I G U R A T I O N ****/ +/**** ****/ +/*************************************************************************/ +/*************************************************************************/ + + +/*************************************************************************/ +/* */ +/* Define TT_CONFIG_OPTION_EMBEDDED_BITMAPS if you want to support */ +/* embedded bitmaps in all formats using the SFNT module (namely */ +/* TrueType & OpenType). */ +/* */ +#define TT_CONFIG_OPTION_EMBEDDED_BITMAPS + + +/*************************************************************************/ +/* */ +/* Define TT_CONFIG_OPTION_POSTSCRIPT_NAMES if you want to be able to */ +/* load and enumerate the glyph Postscript names in a TrueType or */ +/* OpenType file. */ +/* */ +/* Note that when you do not compile the `PSNames' module by undefining */ +/* the above FT_CONFIG_OPTION_POSTSCRIPT_NAMES, the `sfnt' module will */ +/* contain additional code used to read the PS Names table from a font. */ +/* */ +/* (By default, the module uses `PSNames' to extract glyph names.) */ +/* */ +#define TT_CONFIG_OPTION_POSTSCRIPT_NAMES + + +/*************************************************************************/ +/* */ +/* Define TT_CONFIG_OPTION_SFNT_NAMES if your applications need to */ +/* access the internal name table in a SFNT-based format like TrueType */ +/* or OpenType. The name table contains various strings used to */ +/* describe the font, like family name, copyright, version, etc. It */ +/* does not contain any glyph name though. */ +/* */ +/* Accessing SFNT names is done through the functions declared in */ +/* `freetype/ftnames.h'. */ +/* */ +#define TT_CONFIG_OPTION_SFNT_NAMES + + +/*************************************************************************/ +/*************************************************************************/ +/**** ****/ +/**** T R U E T Y P E D R I V E R C O N F I G U R A T I O N ****/ +/**** ****/ +/*************************************************************************/ +/*************************************************************************/ + +/*************************************************************************/ +/* */ +/* Define TT_CONFIG_OPTION_BYTECODE_INTERPRETER if you want to compile */ +/* a bytecode interpreter in the TrueType driver. Note that there are */ +/* important patent issues related to the use of the interpreter. */ +/* */ +/* By undefining this, you will only compile the code necessary to load */ +/* TrueType glyphs without hinting. */ +/* */ +#define TT_CONFIG_OPTION_BYTECODE_INTERPRETER + + +/*************************************************************************/ +/* */ +/* Define TT_CONFIG_OPTION_INTERPRETER_SWITCH to compile the TrueType */ +/* bytecode interpreter with a huge switch statement, rather than a call */ +/* table. This results in smaller and faster code for a number of */ +/* architectures. */ +/* */ +/* Note however that on some compiler/processor combinations, undefining */ +/* this macro will generate faster, though larger, code. */ +/* */ +#define TT_CONFIG_OPTION_INTERPRETER_SWITCH + + +/*************************************************************************/ +/*************************************************************************/ +/**** ****/ +/**** T Y P E 1 D R I V E R C O N F I G U R A T I O N ****/ +/**** ****/ +/*************************************************************************/ +/*************************************************************************/ + + +/*************************************************************************/ +/* */ +/* T1_MAX_STACK_DEPTH is the maximal depth of the token stack used by */ +/* the Type 1 parser (see t1load.c). A minimum of 16 is required. */ +/* */ +#define T1_MAX_STACK_DEPTH 16 + + +/*************************************************************************/ +/* */ +/* T1_MAX_DICT_DEPTH is the maximal depth of nest dictionaries and */ +/* arrays in the Type 1 stream (see t1load.c). A minimum of 4 is */ +/* required. */ +/* */ +#define T1_MAX_DICT_DEPTH 5 + + +/*************************************************************************/ +/* */ +/* T1_MAX_SUBRS_CALLS details the maximum number of nested sub-routine */ +/* calls during glyph loading. */ +/* */ +#define T1_MAX_SUBRS_CALLS 8 + + +/*************************************************************************/ +/* */ +/* T1_MAX_CHARSTRING_OPERANDS is the charstring stack's capacity. */ +/* */ +#define T1_MAX_CHARSTRINGS_OPERANDS 32 + + +/*************************************************************************/ +/* */ +/* Define T1_CONFIG_OPTION_DISABLE_HINTER if you want to generate a */ +/* driver with no hinter. This can be useful to debug the parser. */ +/* */ +#undef T1_CONFIG_OPTION_DISABLE_HINTER + + +/*************************************************************************/ +/* */ +/* Define this configuration macro if you want to prevent the */ +/* compilation of `t1afm', which is in charge of reading Type 1 AFM */ +/* files into an existing face. Note that if set, the T1 driver will be */ +/* unable to produce kerning distances. */ +/* */ +#undef T1_CONFIG_OPTION_NO_AFM + + +/*************************************************************************/ +/* */ +/* Define this configuration macro if you want to prevent the */ +/* compilation of the Multiple Masters font support in the Type 1 */ +/* driver. */ +/* */ +#undef T1_CONFIG_OPTION_NO_MM_SUPPORT + + +#endif /* FTOPTION_H */ + + +/* END */ diff --git a/Projects/Android/jni/rtcw/src/ft2/ftoutln.c b/Projects/Android/jni/rtcw/src/ft2/ftoutln.c new file mode 100644 index 0000000..0c45e4d --- /dev/null +++ b/Projects/Android/jni/rtcw/src/ft2/ftoutln.c @@ -0,0 +1,861 @@ +/***************************************************************************/ +/* */ +/* ftoutln.c */ +/* */ +/* FreeType outline management (body). */ +/* */ +/* Copyright 1996-2000 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +/*************************************************************************/ +/* */ +/* All functions are declared in freetype.h. */ +/* */ +/*************************************************************************/ + + +#include "ftoutln.h" +#include "ftobjs.h" + + +/*************************************************************************/ +/* */ +/* The macro FT_COMPONENT is used in trace mode. It is an implicit */ +/* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */ +/* messages during execution. */ +/* */ +#undef FT_COMPONENT +#define FT_COMPONENT trace_outline + + +static +const FT_Outline null_outline = { 0, 0, 0, 0, 0, 0 }; + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Outline_Decompose */ +/* */ +/* */ +/* Walks over an outline's structure to decompose it into individual */ +/* segments and Bezier arcs. This function is also able to emit */ +/* `move to' and `close to' operations to indicate the start and end */ +/* of new contours in the outline. */ +/* */ +/* */ +/* outline :: A pointer to the source target. */ +/* */ +/* interface :: A table of `emitters', i.e,. function pointers called */ +/* during decomposition to indicate path operations. */ +/* */ +/* user :: A typeless pointer which is passed to each emitter */ +/* during the decomposition. It can be used to store */ +/* the state during the decomposition. */ +/* */ +/* */ +/* FreeType error code. 0 means sucess. */ +/* */ +FT_EXPORT_FUNC( FT_Error ) FT_Outline_Decompose( + FT_Outline * outline, + FT_Outline_Funcs * interface, + void* user ) +{ +#undef SCALED +#define SCALED( x ) ( ( ( x ) << shift ) - delta ) + + FT_Vector v_last; + FT_Vector v_control; + FT_Vector v_start; + + FT_Vector* point; + FT_Vector* limit; + char* tags; + + FT_Error error; + + FT_Int n; /* index of contour in outline */ + FT_UInt first; /* index of first point in contour */ + char tag; /* current point's state */ + + FT_Int shift; + FT_Pos delta; + + + if ( !outline || !interface ) { + return FT_Err_Invalid_Argument; + } + + shift = interface->shift; + delta = interface->delta; + first = 0; + + for ( n = 0; n < outline->n_contours; n++ ) + { + FT_Int last; /* index of last point in contour */ + + + last = outline->contours[n]; + limit = outline->points + last; + + v_start = outline->points[first]; + v_last = outline->points[last]; + + v_start.x = SCALED( v_start.x ); v_start.y = SCALED( v_start.y ); + v_last.x = SCALED( v_last.x ); v_last.y = SCALED( v_last.y ); + + v_control = v_start; + + point = outline->points + first; + tags = outline->tags + first; + tag = FT_CURVE_TAG( tags[0] ); + + /* A contour cannot start with a cubic control point! */ + if ( tag == FT_Curve_Tag_Cubic ) { + goto Invalid_Outline; + } + + /* check first point to determine origin */ + if ( tag == FT_Curve_Tag_Conic ) { + /* first point is conic control. Yes, this happens. */ + if ( FT_CURVE_TAG( outline->tags[last] ) == FT_Curve_Tag_On ) { + /* start at last point if it is on the curve */ + v_start = v_last; + limit--; + } else + { + /* if both first and last points are conic, */ + /* start at their middle and record its position */ + /* for closure */ + v_start.x = ( v_start.x + v_last.x ) / 2; + v_start.y = ( v_start.y + v_last.y ) / 2; + + v_last = v_start; + } + point--; + tags--; + } + + error = interface->move_to( &v_start, user ); + if ( error ) { + goto Exit; + } + + while ( point < limit ) + { + point++; + tags++; + + tag = FT_CURVE_TAG( tags[0] ); + switch ( tag ) + { + case FT_Curve_Tag_On: /* emit a single line_to */ + { + FT_Vector vec; + + + vec.x = SCALED( point->x ); + vec.y = SCALED( point->y ); + + error = interface->line_to( &vec, user ); + if ( error ) { + goto Exit; + } + continue; + } + + case FT_Curve_Tag_Conic: /* consume conic arcs */ + v_control.x = SCALED( point->x ); + v_control.y = SCALED( point->y ); + +Do_Conic: + if ( point < limit ) { + FT_Vector vec; + FT_Vector v_middle; + + + point++; + tags++; + tag = FT_CURVE_TAG( tags[0] ); + + vec.x = SCALED( point->x ); + vec.y = SCALED( point->y ); + + if ( tag == FT_Curve_Tag_On ) { + error = interface->conic_to( &v_control, &vec, user ); + if ( error ) { + goto Exit; + } + continue; + } + + if ( tag != FT_Curve_Tag_Conic ) { + goto Invalid_Outline; + } + + v_middle.x = ( v_control.x + vec.x ) / 2; + v_middle.y = ( v_control.y + vec.y ) / 2; + + error = interface->conic_to( &v_control, &v_middle, user ); + if ( error ) { + goto Exit; + } + + v_control = vec; + goto Do_Conic; + } + + error = interface->conic_to( &v_control, &v_start, user ); + goto Close; + + default: /* FT_Curve_Tag_Cubic */ + { + FT_Vector vec1, vec2; + + + if ( point + 1 > limit || + FT_CURVE_TAG( tags[1] ) != FT_Curve_Tag_Cubic ) { + goto Invalid_Outline; + } + + point += 2; + tags += 2; + + vec1.x = SCALED( point[-2].x ); vec1.y = SCALED( point[-2].y ); + vec2.x = SCALED( point[-1].x ); vec2.y = SCALED( point[-1].y ); + + if ( point <= limit ) { + FT_Vector vec; + + + vec.x = SCALED( point->x ); + vec.y = SCALED( point->y ); + + error = interface->cubic_to( &vec1, &vec2, &vec, user ); + if ( error ) { + goto Exit; + } + continue; + } + + error = interface->cubic_to( &vec1, &vec2, &v_start, user ); + goto Close; + } + } + } + + /* close the contour with a line segment */ + error = interface->line_to( &v_start, user ); + +Close: + if ( error ) { + goto Exit; + } + + first = last + 1; + } + + return 0; + +Exit: + return error; + +Invalid_Outline: + return FT_Err_Invalid_Outline; +} + + +FT_EXPORT_FUNC( FT_Error ) FT_Outline_New_Internal( + FT_Memory memory, + FT_UInt numPoints, + FT_Int numContours, + FT_Outline * outline ) +{ + FT_Error error; + + + if ( !outline || !memory ) { + return FT_Err_Invalid_Argument; + } + + *outline = null_outline; + + if ( ALLOC_ARRAY( outline->points, numPoints * 2L, FT_Pos ) || + ALLOC_ARRAY( outline->tags, numPoints, FT_Byte ) || + ALLOC_ARRAY( outline->contours, numContours, FT_UShort ) ) { + goto Fail; + } + + outline->n_points = (FT_UShort)numPoints; + outline->n_contours = (FT_Short)numContours; + outline->flags |= ft_outline_owner; + + return FT_Err_Ok; + +Fail: + outline->flags |= ft_outline_owner; + FT_Outline_Done_Internal( memory, outline ); + + return error; +} + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Outline_New */ +/* */ +/* */ +/* Creates a new outline of a given size. */ +/* */ +/* */ +/* library :: A handle to the library object from where the */ +/* outline is allocated. Note however that the new */ +/* outline will NOT necessarily be FREED, when */ +/* destroying the library, by FT_Done_FreeType(). */ +/* */ +/* numPoints :: The maximal number of points within the outline. */ +/* */ +/* numContours :: The maximal number of contours within the outline. */ +/* */ +/* */ +/* outline :: A handle to the new outline. NULL in case of */ +/* error. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +/* */ +/* No. */ +/* */ +/* */ +/* The reason why this function takes a `library' parameter is simply */ +/* to use the library's memory allocator. */ +/* */ +FT_EXPORT_FUNC( FT_Error ) FT_Outline_New( FT_Library library, + FT_UInt numPoints, + FT_Int numContours, + FT_Outline * outline ) +{ + if ( !library ) { + return FT_Err_Invalid_Library_Handle; + } + + return FT_Outline_New_Internal( library->memory, numPoints, + numContours, outline ); +} + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Outline_Copy */ +/* */ +/* */ +/* Copies an outline into another one. Both objects must have the */ +/* same sizes (number of points & number of contours) when this */ +/* function is called. */ +/* */ +/* */ +/* source :: A handle to the source outline. */ +/* */ +/* */ +/* target :: A handle to the target outline. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +FT_EXPORT_FUNC( FT_Error ) FT_Outline_Copy( FT_Outline * source, + FT_Outline * target ) +{ + FT_Int is_owner; + + + if ( !source || !target || + source->n_points != target->n_points || + source->n_contours != target->n_contours ) { + return FT_Err_Invalid_Argument; + } + + MEM_Copy( target->points, source->points, + source->n_points * sizeof( FT_Vector ) ); + + MEM_Copy( target->tags, source->tags, + source->n_points * sizeof( FT_Byte ) ); + + MEM_Copy( target->contours, source->contours, + source->n_contours * sizeof( FT_Short ) ); + + /* copy all flags, except the `ft_outline_owner' one */ + is_owner = target->flags & ft_outline_owner; + target->flags = source->flags; + + target->flags &= ~ft_outline_owner; + target->flags |= is_owner; + + return FT_Err_Ok; +} + + +FT_EXPORT_FUNC( FT_Error ) FT_Outline_Done_Internal( FT_Memory memory, + FT_Outline * outline ) +{ + if ( outline ) { + if ( outline->flags & ft_outline_owner ) { + FREE( outline->points ); + FREE( outline->tags ); + FREE( outline->contours ); + } + *outline = null_outline; + + return FT_Err_Ok; + } else { + return FT_Err_Invalid_Argument; + } +} + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Outline_Done */ +/* */ +/* */ +/* Destroys an outline created with FT_Outline_New(). */ +/* */ +/* */ +/* library :: A handle of the library object used to allocate the */ +/* outline. */ +/* */ +/* outline :: A pointer to the outline object to be discarded. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +/* */ +/* No. */ +/* */ +/* */ +/* If the outline's `owner' field is not set, only the outline */ +/* descriptor will be released. */ +/* */ +/* The reason why this function takes an `outline' parameter is */ +/* simply to use FT_Free(). */ +/* */ +FT_EXPORT_FUNC( FT_Error ) FT_Outline_Done( FT_Library library, + FT_Outline * outline ) +{ + /* check for valid `outline' in FT_Outline_Done_Internal() */ + + if ( !library ) { + return FT_Err_Invalid_Library_Handle; + } + + return FT_Outline_Done_Internal( library->memory, outline ); +} + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Outline_Get_CBox */ +/* */ +/* */ +/* Returns an outline's `control box'. The control box encloses all */ +/* the outline's points, including Bezier control points. Though it */ +/* coincides with the exact bounding box for most glyphs, it can be */ +/* slightly larger in some situations (like when rotating an outline */ +/* which contains Bezier outside arcs). */ +/* */ +/* Computing the control box is very fast, while getting the bounding */ +/* box can take much more time as it needs to walk over all segments */ +/* and arcs in the outline. To get the latter, you can use the */ +/* `ftbbox' component which is dedicated to this single task. */ +/* */ +/* */ +/* outline :: A pointer to the source outline descriptor. */ +/* */ +/* */ +/* cbox :: The outline's control box. */ +/* */ +/* */ +/* Yes. */ +/* */ +FT_EXPORT_FUNC( void ) FT_Outline_Get_CBox( FT_Outline * outline, + FT_BBox * cbox ) +{ + FT_Pos xMin, yMin, xMax, yMax; + + + if ( outline && cbox ) { + if ( outline->n_points == 0 ) { + xMin = 0; + yMin = 0; + xMax = 0; + yMax = 0; + } else + { + FT_Vector* vec = outline->points; + FT_Vector* limit = vec + outline->n_points; + + + xMin = xMax = vec->x; + yMin = yMax = vec->y; + vec++; + + for ( ; vec < limit; vec++ ) + { + FT_Pos x, y; + + + x = vec->x; + if ( x < xMin ) { + xMin = x; + } + if ( x > xMax ) { + xMax = x; + } + + y = vec->y; + if ( y < yMin ) { + yMin = y; + } + if ( y > yMax ) { + yMax = y; + } + } + } + cbox->xMin = xMin; + cbox->xMax = xMax; + cbox->yMin = yMin; + cbox->yMax = yMax; + } +} + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Outline_Translate */ +/* */ +/* */ +/* Applies a simple translation to the points of an outline. */ +/* */ +/* */ +/* outline :: A pointer to the target outline descriptor. */ +/* */ +/* xOffset :: The horizontal offset. */ +/* */ +/* yOffset :: The vertical offset. */ +/* */ +/* */ +/* Yes. */ +/* */ +FT_EXPORT_FUNC( void ) FT_Outline_Translate( FT_Outline * outline, + FT_Pos xOffset, + FT_Pos yOffset ) +{ + FT_UShort n; + FT_Vector* vec = outline->points; + + + for ( n = 0; n < outline->n_points; n++ ) + { + vec->x += xOffset; + vec->y += yOffset; + vec++; + } +} + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Outline_Reverse */ +/* */ +/* */ +/* Reverses the drawing direction of an outline. This is used to */ +/* ensure consistent fill conventions for mirrored glyphs. */ +/* */ +/* */ +/* outline :: A pointer to the target outline descriptor. */ +/* */ +/* */ +/* This functions toggles the bit flag `ft_outline_reverse_fill' in */ +/* the outline's `flags' field. */ +/* */ +FT_EXPORT_FUNC( void ) FT_Outline_Reverse( FT_Outline * outline ) +{ + FT_UShort n; + FT_Int first, last; + + + first = 0; + + for ( n = 0; n < outline->n_contours; n++ ) + { + last = outline->contours[n]; + + /* reverse point table */ + { + FT_Vector* p = outline->points + first; + FT_Vector* q = outline->points + last; + FT_Vector swap; + + + while ( p < q ) + { + swap = *p; + *p = *q; + *q = swap; + p++; + q--; + } + } + + /* reverse tags table */ + { + char* p = outline->tags + first; + char* q = outline->tags + last; + char swap; + + + while ( p < q ) + { + swap = *p; + *p = *q; + *q = swap; + p++; + q--; + } + } + + first = last + 1; + } + + outline->flags ^= ft_outline_reverse_fill; +} + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Outline_Render */ +/* */ +/* */ +/* Renders an outline within a bitmap using the current scan-convert. */ +/* This functions uses an FT_Raster_Params structure as an argument, */ +/* allowing advanced features like direct composition, translucency, */ +/* etc. */ +/* */ +/* */ +/* library :: A handle to a FreeType library object. */ +/* */ +/* outline :: A pointer to the source outline descriptor. */ +/* */ +/* params :: A pointer to a FT_Raster_Params structure used to */ +/* describe the rendering operation. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +/* */ +/* YES. Rendering is synchronized, so that concurrent calls to the */ +/* scan-line converter will be serialized. */ +/* */ +/* */ +/* You should know what you are doing and how FT_Raster_Params works */ +/* to use this function. */ +/* */ +/* The field `params.source' will be set to `outline' before the scan */ +/* converter is called, which means that the value you give to it is */ +/* actually ignored. */ +/* */ +FT_EXPORT_FUNC( FT_Error ) FT_Outline_Render( FT_Library library, + FT_Outline * outline, + FT_Raster_Params * params ) +{ + FT_Error error; + FT_Bool update = 0; + FT_Renderer renderer; + FT_ListNode node; + + + if ( !library ) { + return FT_Err_Invalid_Library_Handle; + } + + if ( !params ) { + return FT_Err_Invalid_Argument; + } + + renderer = library->cur_renderer; + node = library->renderers.head; + + params->source = (void*)outline; + + error = FT_Err_Cannot_Render_Glyph; + while ( renderer ) + { + error = renderer->raster_render( renderer->raster, params ); + if ( !error || error != FT_Err_Cannot_Render_Glyph ) { + break; + } + + /* FT_Err_Cannot_Render_Glyph is returned if the render mode */ + /* is unsupported by the current renderer for this glyph image */ + /* format */ + + /* now, look for another renderer that supports the same */ + /* format */ + renderer = FT_Lookup_Renderer( library, ft_glyph_format_outline, + &node ); + update = 1; + } + + /* if we changed the current renderer for the glyph image format */ + /* we need to select it as the next current one */ + if ( !error && update && renderer ) { + FT_Set_Renderer( library, renderer, 0, 0 ); + } + + return error; +} + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Outline_Get_Bitmap */ +/* */ +/* */ +/* Renders an outline within a bitmap. The outline's image is simply */ +/* OR-ed to the target bitmap. */ +/* */ +/* */ +/* library :: A handle to a FreeType library object. */ +/* */ +/* outline :: A pointer to the source outline descriptor. */ +/* */ +/* map :: A pointer to the target bitmap descriptor. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +/* */ +/* YES. Rendering is synchronized, so that concurrent calls to the */ +/* scan-line converter will be serialized. */ +/* */ +/* */ +/* This function does NOT CREATE the bitmap, it only renders an */ +/* outline image within the one you pass to it! */ +/* */ +/* It will use the raster correponding to the default glyph format. */ +/* */ +FT_EXPORT_FUNC( FT_Error ) FT_Outline_Get_Bitmap( FT_Library library, + FT_Outline * outline, + FT_Bitmap * bitmap ) +{ + FT_Raster_Params params; + + + if ( !bitmap ) { + return FT_Err_Invalid_Argument; + } + + /* other checks are delayed to FT_Outline_Render() */ + + params.target = bitmap; + params.flags = 0; + + if ( bitmap->pixel_mode == ft_pixel_mode_grays ) { + params.flags |= ft_raster_flag_aa; + } + + return FT_Outline_Render( library, outline, ¶ms ); +} + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Vector_Transform */ +/* */ +/* */ +/* Transforms a single vector through a 2x2 matrix. */ +/* */ +/* */ +/* vector :: The target vector to transform. */ +/* */ +/* */ +/* matrix :: A pointer to the source 2x2 matrix. */ +/* */ +/* */ +/* Yes. */ +/* */ +/* */ +/* The result is undefined if either `vector' or `matrix' is invalid. */ +/* */ +FT_EXPORT_FUNC( void ) FT_Vector_Transform( FT_Vector * vector, + FT_Matrix * matrix ) +{ + FT_Pos xz, yz; + + + if ( !vector || !matrix ) { + return; + } + + xz = FT_MulFix( vector->x, matrix->xx ) + + FT_MulFix( vector->y, matrix->xy ); + + yz = FT_MulFix( vector->x, matrix->yx ) + + FT_MulFix( vector->y, matrix->yy ); + + vector->x = xz; + vector->y = yz; +} + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Outline_Transform */ +/* */ +/* */ +/* Applies a simple 2x2 matrix to all of an outline's points. Useful */ +/* for applying rotations, slanting, flipping, etc. */ +/* */ +/* */ +/* outline :: A pointer to the target outline descriptor. */ +/* */ +/* matrix :: A pointer to the transformation matrix. */ +/* */ +/* */ +/* Yes. */ +/* */ +/* */ +/* You can use FT_Outline_Translate() if you need to translate the */ +/* outline's points. */ +/* */ +FT_EXPORT_FUNC( void ) FT_Outline_Transform( FT_Outline * outline, + FT_Matrix * matrix ) +{ + FT_Vector* vec = outline->points; + FT_Vector* limit = vec + outline->n_points; + + + for ( ; vec < limit; vec++ ) + FT_Vector_Transform( vec, matrix ); +} + +/* END */ diff --git a/Projects/Android/jni/rtcw/src/ft2/ftoutln.h b/Projects/Android/jni/rtcw/src/ft2/ftoutln.h new file mode 100644 index 0000000..3ca36ba --- /dev/null +++ b/Projects/Android/jni/rtcw/src/ft2/ftoutln.h @@ -0,0 +1,344 @@ +/***************************************************************************/ +/* */ +/* ftoutln.h */ +/* */ +/* Support for the FT_Outline type used to store glyph shapes of */ +/* most scalable font formats (specification). */ +/* */ +/* Copyright 1996-2000 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef FTOUTLN_H +#define FTOUTLN_H + + +#include "freetype.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Outline_Decompose */ +/* */ +/* */ +/* Walks over an outline's structure to decompose it into individual */ +/* segments and Bezier arcs. This function is also able to emit */ +/* `move to' and `close to' operations to indicate the start and end */ +/* of new contours in the outline. */ +/* */ +/* */ +/* outline :: A pointer to the source target. */ +/* */ +/* interface :: A table of `emitters', i.e,. function pointers called */ +/* during decomposition to indicate path operations. */ +/* */ +/* user :: A typeless pointer which is passed to each emitter */ +/* during the decomposition. It can be used to store */ +/* the state during the decomposition. */ +/* */ +/* */ +/* FreeType error code. 0 means sucess. */ +/* */ +FT_EXPORT_DEF( FT_Error ) FT_Outline_Decompose( + FT_Outline * outline, + FT_Outline_Funcs * sinterface, + void* user ); + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Outline_New */ +/* */ +/* */ +/* Creates a new outline of a given size. */ +/* */ +/* */ +/* library :: A handle to the library object from where the */ +/* outline is allocated. Note however that the new */ +/* outline will NOT necessarily be FREED, when */ +/* destroying the library, by FT_Done_FreeType(). */ +/* */ +/* numPoints :: The maximal number of points within the outline. */ +/* */ +/* numContours :: The maximal number of contours within the outline. */ +/* */ +/* */ +/* outline :: A handle to the new outline. NULL in case of */ +/* error. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +/* */ +/* No. */ +/* */ +/* */ +/* The reason why this function takes a `library' parameter is simply */ +/* to use the library's memory allocator. */ +/* */ +FT_EXPORT_DEF( FT_Error ) FT_Outline_New( FT_Library library, + FT_UInt numPoints, + FT_Int numContours, + FT_Outline * outline ); + + +FT_EXPORT_DEF( FT_Error ) FT_Outline_New_Internal( + FT_Memory memory, + FT_UInt numPoints, + FT_Int numContours, + FT_Outline * outline ); + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Outline_Done */ +/* */ +/* */ +/* Destroys an outline created with FT_Outline_New(). */ +/* */ +/* */ +/* library :: A handle of the library object used to allocate the */ +/* outline. */ +/* */ +/* outline :: A pointer to the outline object to be discarded. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +/* */ +/* No. */ +/* */ +/* */ +/* If the outline's `owner' field is not set, only the outline */ +/* descriptor will be released. */ +/* */ +/* The reason why this function takes an `outline' parameter is */ +/* simply to use FT_Free(). */ +/* */ +FT_EXPORT_DEF( FT_Error ) FT_Outline_Done( FT_Library library, + FT_Outline * outline ); + + +FT_EXPORT_DEF( FT_Error ) FT_Outline_Done_Internal( FT_Memory memory, + FT_Outline * outline ); + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Outline_Get_CBox */ +/* */ +/* */ +/* Returns an outline's `control box'. The control box encloses all */ +/* the outline's points, including Bezier control points. Though it */ +/* coincides with the exact bounding box for most glyphs, it can be */ +/* slightly larger in some situations (like when rotating an outline */ +/* which contains Bezier outside arcs). */ +/* */ +/* Computing the control box is very fast, while getting the bounding */ +/* box can take much more time as it needs to walk over all segments */ +/* and arcs in the outline. To get the latter, you can use the */ +/* `ftbbox' component which is dedicated to this single task. */ +/* */ +/* */ +/* outline :: A pointer to the source outline descriptor. */ +/* */ +/* */ +/* cbox :: The outline's control box. */ +/* */ +/* */ +/* Yes. */ +/* */ +FT_EXPORT_DEF( void ) FT_Outline_Get_CBox( FT_Outline * outline, + FT_BBox * cbox ); + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Outline_Translate */ +/* */ +/* */ +/* Applies a simple translation to the points of an outline. */ +/* */ +/* */ +/* outline :: A pointer to the target outline descriptor. */ +/* */ +/* xOffset :: The horizontal offset. */ +/* */ +/* yOffset :: The vertical offset. */ +/* */ +/* */ +/* Yes. */ +/* */ +FT_EXPORT_DEF( void ) FT_Outline_Translate( FT_Outline * outline, + FT_Pos xOffset, + FT_Pos yOffset ); + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Outline_Copy */ +/* */ +/* */ +/* Copies an outline into another one. Both objects must have the */ +/* same sizes (number of points & number of contours) when this */ +/* function is called. */ +/* */ +/* */ +/* source :: A handle to the source outline. */ +/* */ +/* */ +/* target :: A handle to the target outline. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +FT_EXPORT_DEF( FT_Error ) FT_Outline_Copy( FT_Outline * source, + FT_Outline * target ); + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Vector_Transform */ +/* */ +/* */ +/* Transforms a single vector through a 2x2 matrix. */ +/* */ +/* */ +/* vector :: The target vector to transform. */ +/* */ +/* */ +/* matrix :: A pointer to the source 2x2 matrix. */ +/* */ +/* */ +/* Yes. */ +/* */ +/* */ +/* The result is undefined if either `vector' or `matrix' is invalid. */ +/* */ +FT_EXPORT_DEF( void ) FT_Outline_Transform( FT_Outline * outline, + FT_Matrix * matrix ); + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Outline_Reverse */ +/* */ +/* */ +/* Reverses the drawing direction of an outline. This is used to */ +/* ensure consistent fill conventions for mirrored glyphs. */ +/* */ +/* */ +/* outline :: A pointer to the target outline descriptor. */ +/* */ +/* */ +/* This functions toggles the bit flag `ft_outline_reverse_fill' in */ +/* the outline's `flags' field. */ +/* */ +/* It shouldn't be used by a normal client application, unless it */ +/* knows what it is doing. */ +/* */ +FT_EXPORT_DEF( void ) FT_Outline_Reverse( FT_Outline * outline ); + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Outline_Get_Bitmap */ +/* */ +/* */ +/* Renders an outline within a bitmap. The outline's image is simply */ +/* OR-ed to the target bitmap. */ +/* */ +/* */ +/* library :: A handle to a FreeType library object. */ +/* */ +/* outline :: A pointer to the source outline descriptor. */ +/* */ +/* map :: A pointer to the target bitmap descriptor. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +/* */ +/* YES. Rendering is synchronized, so that concurrent calls to the */ +/* scan-line converter will be serialized. */ +/* */ +/* */ +/* This function does NOT CREATE the bitmap, it only renders an */ +/* outline image within the one you pass to it! */ +/* */ +/* It will use the raster correponding to the default glyph format. */ +/* */ +FT_EXPORT_DEF( FT_Error ) FT_Outline_Get_Bitmap( FT_Library library, + FT_Outline * outline, + FT_Bitmap * bitmap ); + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Outline_Render */ +/* */ +/* */ +/* Renders an outline within a bitmap using the current scan-convert. */ +/* This functions uses an FT_Raster_Params structure as an argument, */ +/* allowing advanced features like direct composition, translucency, */ +/* etc. */ +/* */ +/* */ +/* library :: A handle to a FreeType library object. */ +/* */ +/* outline :: A pointer to the source outline descriptor. */ +/* */ +/* params :: A pointer to a FT_Raster_Params structure used to */ +/* describe the rendering operation. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +/* */ +/* YES. Rendering is synchronized, so that concurrent calls to the */ +/* scan-line converter will be serialized. */ +/* */ +/* */ +/* You should know what you are doing and how FT_Raster_Params works */ +/* to use this function. */ +/* */ +/* The field `params.source' will be set to `outline' before the scan */ +/* converter is called, which means that the value you give to it is */ +/* actually ignored. */ +/* */ +FT_EXPORT_DEF( FT_Error ) FT_Outline_Render( FT_Library library, + FT_Outline * outline, + FT_Raster_Params * params ); + + +#ifdef __cplusplus +} +#endif + + +#endif /* FTOUTLN_H */ + + +/* END */ diff --git a/Projects/Android/jni/rtcw/src/ft2/ftraster.c b/Projects/Android/jni/rtcw/src/ft2/ftraster.c new file mode 100644 index 0000000..8c17d0d --- /dev/null +++ b/Projects/Android/jni/rtcw/src/ft2/ftraster.c @@ -0,0 +1,3251 @@ +/***************************************************************************/ +/* */ +/* ftraster.c */ +/* */ +/* The FreeType glyph rasterizer (body). */ +/* */ +/* Copyright 1996-2000 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + +/*************************************************************************/ +/* */ +/* This is a rewrite of the FreeType 1.x scan-line converter */ +/* */ +/*************************************************************************/ + + +#include "ftraster.h" +#include "ftcalc.h" /* for FT_MulDiv() only */ + + +/*************************************************************************/ +/* */ +/* A simple technical note on how the raster works */ +/* ----------------------------------------------- */ +/* */ +/* Converting an outline into a bitmap is achieved in several steps: */ +/* */ +/* 1 - Decomposing the outline into successive `profiles'. Each */ +/* profile is simply an array of scanline intersections on a given */ +/* dimension. A profile's main attributes are */ +/* */ +/* o its scanline position boundaries, i.e. `Ymin' and `Ymax'. */ +/* */ +/* o an array of intersection coordinates for each scanline */ +/* between `Ymin' and `Ymax'. */ +/* */ +/* o a direction, indicating whether it was built going `up' or */ +/* `down', as this is very important for filling rules. */ +/* */ +/* 2 - Sweeping the target map's scanlines in order to compute segment */ +/* `spans' which are then filled. Additionally, this pass */ +/* performs drop-out control. */ +/* */ +/* The outline data is parsed during step 1 only. The profiles are */ +/* built from the bottom of the render pool, used as a stack. The */ +/* following graphics shows the profile list under construction: */ +/* */ +/* ____________________________________________________________ _ _ */ +/* | | | | | */ +/* | profile | coordinates for | profile | coordinates for |--> */ +/* | 1 | profile 1 | 2 | profile 2 |--> */ +/* |_________|___________________|_________|_________________|__ _ _ */ +/* */ +/* ^ ^ */ +/* | | */ +/* start of render pool top */ +/* */ +/* The top of the profile stack is kept in the `top' variable. */ +/* */ +/* As you can see, a profile record is pushed on top of the render */ +/* pool, which is then followed by its coordinates/intersections. If */ +/* a change of direction is detected in the outline, a new profile is */ +/* generated until the end of the outline. */ +/* */ +/* Note that when all profiles have been generated, the function */ +/* Finalize_Profile_Table() is used to record, for each profile, its */ +/* bottom-most scanline as well as the scanline above its upmost */ +/* boundary. These positions are called `y-turns' because they (sort */ +/* of) correspond to local extrema. They are stored in a sorted list */ +/* built from the top of the render pool as a downwards stack: */ +/* */ +/* _ _ _______________________________________ */ +/* | | */ +/* <--| sorted list of | */ +/* <--| extrema scanlines | */ +/* _ _ __________________|____________________| */ +/* */ +/* ^ ^ */ +/* | | */ +/* maxBuff sizeBuff = end of pool */ +/* */ +/* This list is later used during the sweep phase in order to */ +/* optimize performance (see technical note on the sweep below). */ +/* */ +/* Of course, the raster detects whether the two stacks collide and */ +/* handles the situation propertly. */ +/* */ +/*************************************************************************/ + + +/*************************************************************************/ +/*************************************************************************/ +/** **/ +/** CONFIGURATION MACROS **/ +/** **/ +/*************************************************************************/ +/*************************************************************************/ + +/* define DEBUG_RASTER if you want to compile a debugging version */ +#define xxxDEBUG_RASTER + +/* The default render pool size in bytes */ +#define RASTER_RENDER_POOL 8192 + +/* undefine FT_RASTER_OPTION_ANTI_ALIASING if you do not want to support */ +/* 5-levels anti-aliasing */ +#ifdef FT_CONFIG_OPTION_5_GRAY_LEVELS +#define FT_RASTER_OPTION_ANTI_ALIASING +#endif + +/* The size of the two-lines intermediate bitmap used */ +/* for anti-aliasing, in bytes. */ +#define RASTER_GRAY_LINES 2048 + + +/*************************************************************************/ +/*************************************************************************/ +/** **/ +/** OTHER MACROS (do not change) **/ +/** **/ +/*************************************************************************/ +/*************************************************************************/ + +/*************************************************************************/ +/* */ +/* The macro FT_COMPONENT is used in trace mode. It is an implicit */ +/* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */ +/* messages during execution. */ +/* */ +#undef FT_COMPONENT +#define FT_COMPONENT trace_raster + + +#ifdef _STANDALONE_ + + +/* This macro is used to indicate that a function parameter is unused. */ +/* Its purpose is simply to reduce compiler warnings. Note also that */ +/* simply defining it as `(void)x' doesn't avoid warnings with certain */ +/* ANSI compilers (e.g. LCC). */ +#define FT_UNUSED( x ) ( x ) = ( x ) + +/* Disable the tracing mechanism for simplicity -- developers can */ +/* activate it easily by redefining these two macros. */ +#ifndef FT_ERROR +#define FT_ERROR( x ) do ;while ( 0 ) /* nothing */ +#endif + +#ifndef FT_TRACE +#define FT_TRACE( x ) do ;while ( 0 ) /* nothing */ +#endif + +#define Raster_Err_None 0 +#define Raster_Err_Not_Ini -1 +#define Raster_Err_Overflow -2 +#define Raster_Err_Neg_Height -3 +#define Raster_Err_Invalid -4 +#define Raster_Err_Unsupported -5 + + +#else /* _STANDALONE_ */ + + +#include "ftobjs.h" +#include "ftdebug.h" /* for FT_TRACE() and FT_ERROR() */ + +#define Raster_Err_None FT_Err_Ok +#define Raster_Err_Not_Ini FT_Err_Raster_Uninitialized +#define Raster_Err_Overflow FT_Err_Raster_Overflow +#define Raster_Err_Neg_Height FT_Err_Raster_Negative_Height +#define Raster_Err_Invalid FT_Err_Invalid_Outline +#define Raster_Err_Unsupported FT_Err_Unimplemented_Feature + + +#endif /* _STANDALONE_ */ + + +/* FMulDiv means `Fast MulDiv'; it is used in case where `b' is */ +/* typically a small value and the result of a*b is known to fit into */ +/* 32 bits. */ +#define FMulDiv( a, b, c ) ( ( a ) * ( b ) / ( c ) ) + +/* On the other hand, SMulDiv means `Slow MulDiv', and is used typically */ +/* for clipping computations. It simply uses the FT_MulDiv() function */ +/* defined in `ftcalc.h'. */ +#define SMulDiv FT_MulDiv + +/* The rasterizer is a very general purpose component; please leave */ +/* the following redefinitions there (you never know your target */ +/* environment). */ + +#ifndef TRUE +#define TRUE 1 +#endif + +#ifndef FALSE +#define FALSE 0 +#endif + +#ifndef NULL +#define NULL (void*)0 +#endif + +#ifndef SUCCESS +#define SUCCESS 0 +#endif + +#ifndef FAILURE +#define FAILURE 1 +#endif + + +#define MaxBezier 32 /* The maximum number of stacked Bezier curves. */ + /* Setting this constant to more than 32 is a */ + /* pure waste of space. */ + +#define Pixel_Bits 6 /* fractional bits of *input* coordinates */ + + +/*************************************************************************/ +/*************************************************************************/ +/** **/ +/** SIMPLE TYPE DECLARATIONS **/ +/** **/ +/*************************************************************************/ +/*************************************************************************/ + +typedef int Int; +typedef unsigned int UInt; +typedef short Short; +typedef unsigned short UShort, *PUShort; +typedef long Long, *PLong; +typedef unsigned long ULong; + +typedef unsigned char Byte, *PByte; +typedef char Bool; + +typedef struct TPoint_ +{ + Long x; + Long y; + +} TPoint; + + +typedef enum TFlow_ +{ + Flow_None = 0, + Flow_Up = 1, + Flow_Down = -1 + +} TFlow; + + +/* States of each line, arc, and profile */ +typedef enum TStates_ +{ + Unknown, + Ascending, + Descending, + Flat + +} TStates; + + +typedef struct TProfile_ TProfile; +typedef TProfile* PProfile; + +struct TProfile_ +{ + FT_F26Dot6 X; /* current coordinate during sweep */ + PProfile link; /* link to next profile - various purpose */ + PLong offset; /* start of profile's data in render pool */ + Int flow; /* Profile orientation: Asc/Descending */ + Long height; /* profile's height in scanlines */ + Long start; /* profile's starting scanline */ + + UShort countL; /* number of lines to step before this */ + /* profile becomes drawable */ + + PProfile next; /* next profile in same contour, used */ + /* during drop-out control */ +}; + +typedef PProfile TProfileList; +typedef PProfile* PProfileList; + + +/* Simple record used to implement a stack of bands, required */ +/* by the sub-banding mechanism */ +typedef struct TBand_ +{ + Short y_min; /* band's minimum */ + Short y_max; /* band's maximum */ + +} TBand; + + +#define AlignProfileSize \ + ( ( sizeof( TProfile ) + sizeof( long ) - 1 ) / sizeof( long ) ) + + +#ifdef TT_STATIC_RASTER + + +#define RAS_ARGS /* void */ +#define RAS_ARG /* void */ + +#define RAS_VARS /* void */ +#define RAS_VAR /* void */ + +#define FT_UNUSED_RASTER do ;while ( 0 ) + + +#else /* TT_STATIC_RASTER */ + + +#define RAS_ARGS TRaster_Instance * raster, +#define RAS_ARG TRaster_Instance * raster + +#define RAS_VARS raster, +#define RAS_VAR raster + +#define FT_UNUSED_RASTER FT_UNUSED( raster ) + + +#endif /* TT_STATIC_RASTER */ + + +typedef struct TRaster_Instance_ TRaster_Instance; + + +/* prototypes used for sweep function dispatch */ +typedef void Function_Sweep_Init ( RAS_ARGS Short * min, + Short * max ); + +typedef void Function_Sweep_Span ( RAS_ARGS Short y, + FT_F26Dot6 x1, + FT_F26Dot6 x2, + PProfile left, + PProfile right ); + +typedef void Function_Sweep_Step ( RAS_ARG ); + + +/* NOTE: These operations are only valid on 2's complement processors */ + +#define FLOOR( x ) ( ( x ) & - ras.precision ) +#define CEILING( x ) ( ( ( x ) + ras.precision - 1 ) & - ras.precision ) +#define TRUNC( x ) ( (signed long)( x ) >> ras.precision_bits ) +#define FRAC( x ) ( ( x ) & ( ras.precision - 1 ) ) +#define SCALED( x ) ( ( ( x ) << ras.scale_shift ) - ras.precision_half ) + +/* Note that I have moved the location of some fields in the */ +/* structure to ensure that the most used variables are used */ +/* at the top. Thus, their offset can be coded with less */ +/* opcodes, and it results in a smaller executable. */ + +struct TRaster_Instance_ +{ + Int precision_bits; /* precision related variables */ + Int precision; + Int precision_half; + Long precision_mask; + Int precision_shift; + Int precision_step; + Int precision_jitter; + + Int scale_shift; /* == precision_shift for bitmaps */ + /* == precision_shift+1 for pixmaps */ + + PLong buff; /* The profiles buffer */ + PLong sizeBuff; /* Render pool size */ + PLong maxBuff; /* Profiles buffer size */ + PLong top; /* Current cursor in buffer */ + + FT_Error error; + + Int numTurns; /* number of Y-turns in outline */ + + TPoint* arc; /* current Bezier arc pointer */ + + UShort bWidth; /* target bitmap width */ + PByte bTarget; /* target bitmap buffer */ + PByte gTarget; /* target pixmap buffer */ + + Long lastX, lastY, minY, maxY; + + UShort num_Profs; /* current number of profiles */ + + Bool fresh; /* signals a fresh new profile which */ + /* 'start' field must be completed */ + Bool joint; /* signals that the last arc ended */ + /* exactly on a scanline. Allows */ + /* removal of doublets */ + PProfile cProfile; /* current profile */ + PProfile fProfile; /* head of linked list of profiles */ + PProfile gProfile; /* contour's first profile in case */ + /* of impact */ + + TStates state; /* rendering state */ + + FT_Bitmap target; /* description of target bit/pixmap */ + FT_Outline outline; + + Long traceOfs; /* current offset in target bitmap */ + Long traceG; /* current offset in target pixmap */ + + Short traceIncr; /* sweep's increment in target bitmap */ + + Short gray_min_x; /* current min x during gray rendering */ + Short gray_max_x; /* current max x during gray rendering */ + + /* dispatch variables */ + + Function_Sweep_Init* Proc_Sweep_Init; + Function_Sweep_Span* Proc_Sweep_Span; + Function_Sweep_Span* Proc_Sweep_Drop; + Function_Sweep_Step* Proc_Sweep_Step; + + Byte dropOutControl; /* current drop_out control method */ + + Bool second_pass; /* indicates wether a horizontal pass */ + /* should be performed to control */ + /* drop-out accurately when calling */ + /* Render_Glyph. Note that there is */ + /* no horizontal pass during gray */ + /* rendering. */ + + TPoint arcs[2 * MaxBezier + 1]; /* The Bezier stack */ + + TBand band_stack[16]; /* band stack used for sub-banding */ + Int band_top; /* band stack top */ + + Int count_table[256]; /* Look-up table used to quickly count */ + /* set bits in a gray 2x2 cell */ + + void* memory; + +#ifdef FT_RASTER_OPTION_ANTI_ALIASING + + Byte grays[5]; /* Palette of gray levels used for */ + /* render. */ + + Byte gray_lines[RASTER_GRAY_LINES]; + /* Intermediate table used to render the */ + /* graylevels pixmaps. */ + /* gray_lines is a buffer holding two */ + /* monochrome scanlines */ + + Short gray_width; /* width in bytes of one monochrome */ + /* intermediate scanline of gray_lines. */ + /* Each gray pixel takes 2 bits long there */ + + /* The gray_lines must hold 2 lines, thus with size */ + /* in bytes of at least `gray_width*2'. */ + +#endif /* FT_RASTER_ANTI_ALIASING */ + +#if 0 + PByte flags; /* current flags table */ + PUShort outs; /* current outlines table */ + FT_Vector* coords; + + UShort nPoints; /* number of points in current glyph */ + Short nContours; /* number of contours in current glyph */ +#endif + +}; + + +#ifdef FT_CONFIG_OPTION_STATIC_RASTER + +static TRaster_Instance cur_ras; +#define ras cur_ras + +#else + +#define ras ( *raster ) + +#endif /* FT_CONFIG_OPTION_STATIC_RASTER */ + + +/*************************************************************************/ +/*************************************************************************/ +/** **/ +/** PROFILES COMPUTATION **/ +/** **/ +/*************************************************************************/ +/*************************************************************************/ + + +/*************************************************************************/ +/* */ +/* */ +/* Set_High_Precision */ +/* */ +/* */ +/* Sets precision variables according to param flag. */ +/* */ +/* */ +/* High :: Set to True for high precision (typically for ppem < 18), */ +/* false otherwise. */ +/* */ +static +void Set_High_Precision( RAS_ARGS Int High ) { + if ( High ) { + ras.precision_bits = 10; + ras.precision_step = 128; + ras.precision_jitter = 24; + } else + { + ras.precision_bits = 6; + ras.precision_step = 32; + ras.precision_jitter = 2; + } + + FT_TRACE6( ( "Set_High_Precision(%s)\n", High ? "true" : "false" ) ); + + ras.precision = 1L << ras.precision_bits; + ras.precision_half = ras.precision / 2; + ras.precision_shift = ras.precision_bits - Pixel_Bits; + ras.precision_mask = -ras.precision; +} + + +/*************************************************************************/ +/* */ +/* */ +/* New_Profile */ +/* */ +/* */ +/* Creates a new profile in the render pool. */ +/* */ +/* */ +/* aState :: The state/orientation of the new profile. */ +/* */ +/* */ +/* SUCCESS on success. FAILURE in case of overflow or of incoherent */ +/* profile. */ +/* */ +static +Bool New_Profile( RAS_ARGS TStates aState ) { + if ( !ras.fProfile ) { + ras.cProfile = (PProfile)ras.top; + ras.fProfile = ras.cProfile; + ras.top += AlignProfileSize; + } + + if ( ras.top >= ras.maxBuff ) { + ras.error = Raster_Err_Overflow; + return FAILURE; + } + + switch ( aState ) + { + case Ascending: + ras.cProfile->flow = Flow_Up; + FT_TRACE6( ( "New ascending profile = %lx\n", (long)ras.cProfile ) ); + break; + + case Descending: + ras.cProfile->flow = Flow_Down; + FT_TRACE6( ( "New descending profile = %lx\n", (long)ras.cProfile ) ); + break; + + default: + FT_ERROR( ( "New_Profile: invalid profile direction!\n" ) ); + ras.error = Raster_Err_Invalid; + return FAILURE; + } + + ras.cProfile->start = 0; + ras.cProfile->height = 0; + ras.cProfile->offset = ras.top; + ras.cProfile->link = (PProfile)0; + ras.cProfile->next = (PProfile)0; + + if ( !ras.gProfile ) { + ras.gProfile = ras.cProfile; + } + + ras.state = aState; + ras.fresh = TRUE; + ras.joint = FALSE; + + return SUCCESS; +} + + +/*************************************************************************/ +/* */ +/* */ +/* End_Profile */ +/* */ +/* */ +/* Finalizes the current profile. */ +/* */ +/* */ +/* SUCCESS on success. FAILURE in case of overflow or incoherency. */ +/* */ +static +Bool End_Profile( RAS_ARG ) { + Long h; + PProfile oldProfile; + + + h = ras.top - ras.cProfile->offset; + + if ( h < 0 ) { + FT_ERROR( ( "End_Profile: negative height encountered!\n" ) ); + ras.error = Raster_Err_Neg_Height; + return FAILURE; + } + + if ( h > 0 ) { + FT_TRACE6( ( "Ending profile %lx, start = %ld, height = %ld\n", + (long)ras.cProfile, ras.cProfile->start, h ) ); + + oldProfile = ras.cProfile; + ras.cProfile->height = h; + ras.cProfile = (PProfile)ras.top; + + ras.top += AlignProfileSize; + + ras.cProfile->height = 0; + ras.cProfile->offset = ras.top; + oldProfile->next = ras.cProfile; + ras.num_Profs++; + } + + if ( ras.top >= ras.maxBuff ) { + FT_TRACE1( ( "overflow in End_Profile\n" ) ); + ras.error = Raster_Err_Overflow; + return FAILURE; + } + + ras.joint = FALSE; + + return SUCCESS; +} + + +/*************************************************************************/ +/* */ +/* */ +/* Insert_Y_Turn */ +/* */ +/* */ +/* Inserts a salient into the sorted list placed on top of the render */ +/* pool. */ +/* */ +/* */ +/* New y scanline position. */ +/* */ +/* */ +/* SUCCESS on success. FAILURE in case of overflow. */ +/* */ +static +Bool Insert_Y_Turn( RAS_ARGS Int y ) { + PLong y_turns; + Int y2, n; + + + n = ras.numTurns - 1; + y_turns = ras.sizeBuff - ras.numTurns; + + /* look for first y value that is <= */ + while ( n >= 0 && y < y_turns[n] ) + n--; + + /* if it is <, simply insert it, ignore if == */ + if ( n >= 0 && y > y_turns[n] ) { + while ( n >= 0 ) + { + y2 = y_turns[n]; + y_turns[n] = y; + y = y2; + n--; + } + } + + if ( n < 0 ) { + if ( ras.maxBuff <= ras.top ) { + ras.error = Raster_Err_Overflow; + return FAILURE; + } + ras.maxBuff--; + ras.numTurns++; + ras.sizeBuff[-ras.numTurns] = y; + } + + return SUCCESS; +} + + +/*************************************************************************/ +/* */ +/* */ +/* Finalize_Profile_Table */ +/* */ +/* */ +/* Adjusts all links in the profiles list. */ +/* */ +/* */ +/* SUCCESS on success. FAILURE in case of overflow. */ +/* */ +static +Bool Finalize_Profile_Table( RAS_ARG ) { + Int bottom, top; + UShort n; + PProfile p; + + + n = ras.num_Profs; + + if ( n > 1 ) { + p = ras.fProfile; + while ( n > 0 ) + { + if ( n > 1 ) { + p->link = (PProfile)( p->offset + p->height ); + } else { + p->link = NULL; + } + + switch ( p->flow ) + { + case Flow_Down: + bottom = p->start - p->height + 1; + top = p->start; + p->start = bottom; + p->offset += p->height - 1; + break; + + case Flow_Up: + default: + bottom = p->start; + top = p->start + p->height - 1; + } + + if ( Insert_Y_Turn( RAS_VARS bottom ) || + Insert_Y_Turn( RAS_VARS top + 1 ) ) { + return FAILURE; + } + + p = p->link; + n--; + } + } else { + ras.fProfile = NULL; + } + + return SUCCESS; +} + + +/*************************************************************************/ +/* */ +/* */ +/* Split_Conic */ +/* */ +/* */ +/* Subdivides one conic Bezier into two joint sub-arcs in the Bezier */ +/* stack. */ +/* */ +/* */ +/* None (subdivided Bezier is taken from the top of the stack). */ +/* */ +/* */ +/* This routine is the `beef' of this component. It is _the_ inner */ +/* loop that should be optimized to hell to get the best performance. */ +/* */ +static +void Split_Conic( TPoint* base ) { + Long a, b; + + + base[4].x = base[2].x; + b = base[1].x; + a = base[3].x = ( base[2].x + b ) / 2; + b = base[1].x = ( base[0].x + b ) / 2; + base[2].x = ( a + b ) / 2; + + base[4].y = base[2].y; + b = base[1].y; + a = base[3].y = ( base[2].y + b ) / 2; + b = base[1].y = ( base[0].y + b ) / 2; + base[2].y = ( a + b ) / 2; + + /* hand optimized. gcc doesn't seem to be too good at common */ + /* expression substitution and instruction scheduling ;-) */ +} + + +/*************************************************************************/ +/* */ +/* */ +/* Split_Cubic */ +/* */ +/* */ +/* Subdivides a third-order Bezier arc into two joint sub-arcs in the */ +/* Bezier stack. */ +/* */ +/* */ +/* This routine is the `beef' of the component. It is one of _the_ */ +/* inner loops that should be optimized like hell to get the best */ +/* performance. */ +/* */ +static +void Split_Cubic( TPoint* base ) { + Long a, b, c, d; + + + base[6].x = base[3].x; + c = base[1].x; + d = base[2].x; + base[1].x = a = ( base[0].x + c + 1 ) >> 1; + base[5].x = b = ( base[3].x + d + 1 ) >> 1; + c = ( c + d + 1 ) >> 1; + base[2].x = a = ( a + c + 1 ) >> 1; + base[4].x = b = ( b + c + 1 ) >> 1; + base[3].x = ( a + b + 1 ) >> 1; + + base[6].y = base[3].y; + c = base[1].y; + d = base[2].y; + base[1].y = a = ( base[0].y + c + 1 ) >> 1; + base[5].y = b = ( base[3].y + d + 1 ) >> 1; + c = ( c + d + 1 ) >> 1; + base[2].y = a = ( a + c + 1 ) >> 1; + base[4].y = b = ( b + c + 1 ) >> 1; + base[3].y = ( a + b + 1 ) >> 1; +} + + +/*************************************************************************/ +/* */ +/* */ +/* Line_Up */ +/* */ +/* */ +/* Computes the x-coordinates of an ascending line segment and stores */ +/* them in the render pool. */ +/* */ +/* */ +/* x1 :: The x-coordinate of the segment's start point. */ +/* */ +/* y1 :: The y-coordinate of the segment's start point. */ +/* */ +/* x2 :: The x-coordinate of the segment's end point. */ +/* */ +/* y2 :: The y-coordinate of the segment's end point. */ +/* */ +/* miny :: A lower vertical clipping bound value. */ +/* */ +/* maxy :: An upper vertical clipping bound value. */ +/* */ +/* */ +/* SUCCESS on success, FAILURE on render pool overflow. */ +/* */ +static +Bool Line_Up( RAS_ARGS Long x1, + Long y1, + Long x2, + Long y2, + Long miny, + Long maxy ) { + Long Dx, Dy; + Int e1, e2, f1, f2, size; /* XXX: is `Short' sufficient? */ + Long Ix, Rx, Ax; + + PLong top; + + + Dx = x2 - x1; + Dy = y2 - y1; + + if ( Dy <= 0 || y2 < miny || y1 > maxy ) { + return SUCCESS; + } + + if ( y1 < miny ) { + /* Take care: miny-y1 can be a very large value; we use */ + /* a slow MulDiv function to avoid clipping bugs */ + x1 += SMulDiv( Dx, miny - y1, Dy ); + e1 = TRUNC( miny ); + f1 = 0; + } else + { + e1 = TRUNC( y1 ); + f1 = FRAC( y1 ); + } + + if ( y2 > maxy ) { + /* x2 += FMulDiv( Dx, maxy - y2, Dy ); UNNECESSARY */ + e2 = TRUNC( maxy ); + f2 = 0; + } else + { + e2 = TRUNC( y2 ); + f2 = FRAC( y2 ); + } + + if ( f1 > 0 ) { + if ( e1 == e2 ) { + return SUCCESS; + } else + { + x1 += FMulDiv( Dx, ras.precision - f1, Dy ); + e1 += 1; + } + } else + if ( ras.joint ) { + ras.top--; + ras.joint = FALSE; + } + + ras.joint = ( f2 == 0 ); + + if ( ras.fresh ) { + ras.cProfile->start = e1; + ras.fresh = FALSE; + } + + size = e2 - e1 + 1; + if ( ras.top + size >= ras.maxBuff ) { + ras.error = Raster_Err_Overflow; + return FAILURE; + } + + if ( Dx > 0 ) { + Ix = ( ras.precision * Dx ) / Dy; + Rx = ( ras.precision * Dx ) % Dy; + Dx = 1; + } else + { + Ix = -( ( ras.precision * -Dx ) / Dy ); + Rx = ( ras.precision * -Dx ) % Dy; + Dx = -1; + } + + Ax = -Dy; + top = ras.top; + + while ( size > 0 ) + { + *top++ = x1; + + x1 += Ix; + Ax += Rx; + if ( Ax >= 0 ) { + Ax -= Dy; + x1 += Dx; + } + size--; + } + + ras.top = top; + return SUCCESS; +} + + +/*************************************************************************/ +/* */ +/* */ +/* Line_Down */ +/* */ +/* */ +/* Computes the x-coordinates of an descending line segment and */ +/* stores them in the render pool. */ +/* */ +/* */ +/* x1 :: The x-coordinate of the segment's start point. */ +/* */ +/* y1 :: The y-coordinate of the segment's start point. */ +/* */ +/* x2 :: The x-coordinate of the segment's end point. */ +/* */ +/* y2 :: The y-coordinate of the segment's end point. */ +/* */ +/* miny :: A lower vertical clipping bound value. */ +/* */ +/* maxy :: An upper vertical clipping bound value. */ +/* */ +/* */ +/* SUCCESS on success, FAILURE on render pool overflow. */ +/* */ +static +Bool Line_Down( RAS_ARGS Long x1, + Long y1, + Long x2, + Long y2, + Long miny, + Long maxy ) { + Bool result, fresh; + + + fresh = ras.fresh; + + result = Line_Up( RAS_VARS x1, -y1, x2, -y2, -maxy, -miny ); + + if ( fresh && !ras.fresh ) { + ras.cProfile->start = -ras.cProfile->start; + } + + return result; +} + + +/* A function type describing the functions used to split Bezier arcs */ +typedef void ( *TSplitter )( TPoint* base ); + + +/*************************************************************************/ +/* */ +/* */ +/* Bezier_Up */ +/* */ +/* */ +/* Computes the x-coordinates of an ascending Bezier arc and stores */ +/* them in the render pool. */ +/* */ +/* */ +/* degree :: The degree of the Bezier arc (either 2 or 3). */ +/* */ +/* splitter :: The function to split Bezier arcs. */ +/* */ +/* miny :: A lower vertical clipping bound value. */ +/* */ +/* maxy :: An upper vertical clipping bound value. */ +/* */ +/* */ +/* SUCCESS on success, FAILURE on render pool overflow. */ +/* */ +static +Bool Bezier_Up( RAS_ARGS Int degree, + TSplitter splitter, + Long miny, + Long maxy ) { + Long y1, y2, e, e2, e0; + Short f1; + + TPoint* arc; + TPoint* start_arc; + + PLong top; + + + arc = ras.arc; + y1 = arc[degree].y; + y2 = arc[0].y; + top = ras.top; + + if ( y2 < miny || y1 > maxy ) { + goto Fin; + } + + e2 = FLOOR( y2 ); + + if ( e2 > maxy ) { + e2 = maxy; + } + + e0 = miny; + + if ( y1 < miny ) { + e = miny; + } else + { + e = CEILING( y1 ); + f1 = FRAC( y1 ); + e0 = e; + + if ( f1 == 0 ) { + if ( ras.joint ) { + top--; + ras.joint = FALSE; + } + + *top++ = arc[degree].x; + + e += ras.precision; + } + } + + if ( ras.fresh ) { + ras.cProfile->start = TRUNC( e0 ); + ras.fresh = FALSE; + } + + if ( e2 < e ) { + goto Fin; + } + + if ( ( top + TRUNC( e2 - e ) + 1 ) >= ras.maxBuff ) { + ras.top = top; + ras.error = Raster_Err_Overflow; + return FAILURE; + } + + start_arc = arc; + + while ( arc >= start_arc && e <= e2 ) + { + ras.joint = FALSE; + + y2 = arc[0].y; + + if ( y2 > e ) { + y1 = arc[degree].y; + if ( y2 - y1 >= ras.precision_step ) { + splitter( arc ); + arc += degree; + } else + { + *top++ = arc[degree].x + FMulDiv( arc[0].x - arc[degree].x, + e - y1, y2 - y1 ); + arc -= degree; + e += ras.precision; + } + } else + { + if ( y2 == e ) { + ras.joint = TRUE; + *top++ = arc[0].x; + + e += ras.precision; + } + arc -= degree; + } + } + +Fin: + ras.top = top; + ras.arc -= degree; + return SUCCESS; +} + + +/*************************************************************************/ +/* */ +/* */ +/* Bezier_Down */ +/* */ +/* */ +/* Computes the x-coordinates of an descending Bezier arc and stores */ +/* them in the render pool. */ +/* */ +/* */ +/* degree :: The degree of the Bezier arc (either 2 or 3). */ +/* */ +/* splitter :: The function to split Bezier arcs. */ +/* */ +/* miny :: A lower vertical clipping bound value. */ +/* */ +/* maxy :: An upper vertical clipping bound value. */ +/* */ +/* */ +/* SUCCESS on success, FAILURE on render pool overflow. */ +/* */ +static +Bool Bezier_Down( RAS_ARGS Int degree, + TSplitter splitter, + Long miny, + Long maxy ) { + TPoint* arc = ras.arc; + Bool result, fresh; + + + arc[0].y = -arc[0].y; + arc[1].y = -arc[1].y; + arc[2].y = -arc[2].y; + if ( degree > 2 ) { + arc[3].y = -arc[3].y; + } + + fresh = ras.fresh; + + result = Bezier_Up( RAS_VARS degree, splitter, -maxy, -miny ); + + if ( fresh && !ras.fresh ) { + ras.cProfile->start = -ras.cProfile->start; + } + + arc[0].y = -arc[0].y; + return result; +} + + +/*************************************************************************/ +/* */ +/* */ +/* Line_To */ +/* */ +/* */ +/* Injects a new line segment and adjusts Profiles list. */ +/* */ +/* */ +/* x :: The x-coordinate of the segment's end point (its start point */ +/* is stored in `LastX'). */ +/* */ +/* y :: The y-coordinate of the segment's end point (its start point */ +/* is stored in `LastY'). */ +/* */ +/* */ +/* SUCCESS on success, FAILURE on render pool overflow or incorrect */ +/* profile. */ +/* */ +static +Bool Line_To( RAS_ARGS Long x, + Long y ) { + /* First, detect a change of direction */ + + switch ( ras.state ) + { + case Unknown: + if ( y > ras.lastY ) { + if ( New_Profile( RAS_VARS Ascending ) ) { + return FAILURE; + } + } else + { + if ( y < ras.lastY ) { + if ( New_Profile( RAS_VARS Descending ) ) { + return FAILURE; + } + } + } + break; + + case Ascending: + if ( y < ras.lastY ) { + if ( End_Profile( RAS_VAR ) || + New_Profile( RAS_VARS Descending ) ) { + return FAILURE; + } + } + break; + + case Descending: + if ( y > ras.lastY ) { + if ( End_Profile( RAS_VAR ) || + New_Profile( RAS_VARS Ascending ) ) { + return FAILURE; + } + } + break; + + default: + ; + } + + /* Then compute the lines */ + + switch ( ras.state ) + { + case Ascending: + if ( Line_Up( RAS_VARS ras.lastX, ras.lastY, + x, y, ras.minY, ras.maxY ) ) { + return FAILURE; + } + break; + + case Descending: + if ( Line_Down( RAS_VARS ras.lastX, ras.lastY, + x, y, ras.minY, ras.maxY ) ) { + return FAILURE; + } + break; + + default: + ; + } + + ras.lastX = x; + ras.lastY = y; + + return SUCCESS; +} + + +/*************************************************************************/ +/* */ +/* */ +/* Conic_To */ +/* */ +/* */ +/* Injects a new conic arc and adjusts the profile list. */ +/* */ +/* */ +/* cx :: The x-coordinate of the arc's new control point. */ +/* */ +/* cy :: The y-coordinate of the arc's new control point. */ +/* */ +/* x :: The x-coordinate of the arc's end point (its start point is */ +/* stored in `LastX'). */ +/* */ +/* y :: The y-coordinate of the arc's end point (its start point is */ +/* stored in `LastY'). */ +/* */ +/* */ +/* SUCCESS on success, FAILURE on render pool overflow or incorrect */ +/* profile. */ +/* */ +static +Bool Conic_To( RAS_ARGS Long cx, + Long cy, + Long x, + Long y ) { + Long y1, y2, y3, x3, ymin, ymax; + TStates state_bez; + + + ras.arc = ras.arcs; + ras.arc[2].x = ras.lastX; + ras.arc[2].y = ras.lastY; + ras.arc[1].x = cx; ras.arc[1].y = cy; + ras.arc[0].x = x; ras.arc[0].y = y; + + do + { + y1 = ras.arc[2].y; + y2 = ras.arc[1].y; + y3 = ras.arc[0].y; + x3 = ras.arc[0].x; + + /* first, categorize the Bezier arc */ + + if ( y1 <= y3 ) { + ymin = y1; + ymax = y3; + } else + { + ymin = y3; + ymax = y1; + } + + if ( y2 < ymin || y2 > ymax ) { + /* this arc has no given direction, split it! */ + Split_Conic( ras.arc ); + ras.arc += 2; + } else if ( y1 == y3 ) { + /* this arc is flat, ignore it and pop it from the Bezier stack */ + ras.arc -= 2; + } else + { + /* the arc is y-monotonous, either ascending or descending */ + /* detect a change of direction */ + state_bez = y1 < y3 ? Ascending : Descending; + if ( ras.state != state_bez ) { + /* finalize current profile if any */ + if ( ras.state != Unknown && + End_Profile( RAS_VAR ) ) { + goto Fail; + } + + /* create a new profile */ + if ( New_Profile( RAS_VARS state_bez ) ) { + goto Fail; + } + } + + /* now call the appropriate routine */ + if ( state_bez == Ascending ) { + if ( Bezier_Up( RAS_VARS 2, Split_Conic, ras.minY, ras.maxY ) ) { + goto Fail; + } + } else + if ( Bezier_Down( RAS_VARS 2, Split_Conic, ras.minY, ras.maxY ) ) { + goto Fail; + } + } + + } while ( ras.arc >= ras.arcs ); + + ras.lastX = x3; + ras.lastY = y3; + + return SUCCESS; + +Fail: + return FAILURE; +} + + +/*************************************************************************/ +/* */ +/* */ +/* Cubic_To */ +/* */ +/* */ +/* Injects a new cubic arc and adjusts the profile list. */ +/* */ +/* */ +/* cx1 :: The x-coordinate of the arc's first new control point. */ +/* */ +/* cy1 :: The y-coordinate of the arc's first new control point. */ +/* */ +/* cx2 :: The x-coordinate of the arc's second new control point. */ +/* */ +/* cy2 :: The y-coordinate of the arc's second new control point. */ +/* */ +/* x :: The x-coordinate of the arc's end point (its start point is */ +/* stored in `LastX'). */ +/* */ +/* y :: The y-coordinate of the arc's end point (its start point is */ +/* stored in `LastY'). */ +/* */ +/* */ +/* SUCCESS on success, FAILURE on render pool overflow or incorrect */ +/* profile. */ +/* */ +static +Bool Cubic_To( RAS_ARGS Long cx1, + Long cy1, + Long cx2, + Long cy2, + Long x, + Long y ) { + Long y1, y2, y3, y4, x4, ymin1, ymax1, ymin2, ymax2; + TStates state_bez; + + + ras.arc = ras.arcs; + ras.arc[3].x = ras.lastX; + ras.arc[3].y = ras.lastY; + ras.arc[2].x = cx1; ras.arc[2].y = cy1; + ras.arc[1].x = cx2; ras.arc[1].y = cy2; + ras.arc[0].x = x; ras.arc[0].y = y; + + do + { + y1 = ras.arc[3].y; + y2 = ras.arc[2].y; + y3 = ras.arc[1].y; + y4 = ras.arc[0].y; + x4 = ras.arc[0].x; + + /* first, categorize the Bezier arc */ + + if ( y1 <= y4 ) { + ymin1 = y1; + ymax1 = y4; + } else + { + ymin1 = y4; + ymax1 = y1; + } + + if ( y2 <= y3 ) { + ymin2 = y2; + ymax2 = y3; + } else + { + ymin2 = y3; + ymax2 = y2; + } + + if ( ymin2 < ymin1 || ymax2 > ymax1 ) { + /* this arc has no given direction, split it! */ + Split_Cubic( ras.arc ); + ras.arc += 3; + } else if ( y1 == y4 ) { + /* this arc is flat, ignore it and pop it from the Bezier stack */ + ras.arc -= 3; + } else + { + state_bez = ( y1 <= y4 ) ? Ascending : Descending; + + /* detect a change of direction */ + if ( ras.state != state_bez ) { + if ( ras.state != Unknown && + End_Profile( RAS_VAR ) ) { + goto Fail; + } + + if ( New_Profile( RAS_VARS state_bez ) ) { + goto Fail; + } + } + + /* compute intersections */ + if ( state_bez == Ascending ) { + if ( Bezier_Up( RAS_VARS 3, Split_Cubic, ras.minY, ras.maxY ) ) { + goto Fail; + } + } else + if ( Bezier_Down( RAS_VARS 3, Split_Cubic, ras.minY, ras.maxY ) ) { + goto Fail; + } + } + + } while ( ras.arc >= ras.arcs ); + + ras.lastX = x4; + ras.lastY = y4; + + return SUCCESS; + +Fail: + return FAILURE; +} + + +#undef SWAP_ +#define SWAP_( x, y ) do \ + { \ + Long swap = x; \ + \ + \ + x = y; \ + y = swap; \ + } while ( 0 ) + + +/*************************************************************************/ +/* */ +/* */ +/* Decompose_Curve */ +/* */ +/* */ +/* Scans the outline arays in order to emit individual segments and */ +/* Beziers by calling Line_To() and Bezier_To(). It handles all */ +/* weird cases, like when the first point is off the curve, or when */ +/* there are simply no `on' points in the contour! */ +/* */ +/* */ +/* first :: The index of the first point in the contour. */ +/* */ +/* last :: The index of the last point in the contour. */ +/* */ +/* flipped :: If set, flip the direction of the curve. */ +/* */ +/* */ +/* SUCCESS on success, FAILURE on error. */ +/* */ +static +Bool Decompose_Curve( RAS_ARGS UShort first, + UShort last, + int flipped ) { + FT_Vector v_last; + FT_Vector v_control; + FT_Vector v_start; + + FT_Vector* points; + FT_Vector* point; + FT_Vector* limit; + char* tags; + + char tag; /* current point's state */ + + + points = ras.outline.points; + limit = points + last; + + v_start.x = SCALED( points[first].x ); + v_start.y = SCALED( points[first].y ); + v_last.x = SCALED( points[last].x ); + v_last.y = SCALED( points[last].y ); + + if ( flipped ) { + SWAP_( v_start.x, v_start.y ); + SWAP_( v_last.x, v_last.y ); + } + + v_control = v_start; + + point = points + first; + tags = ras.outline.tags + first; + tag = FT_CURVE_TAG( tags[0] ); + + /* A contour cannot start with a cubic control point! */ + if ( tag == FT_Curve_Tag_Cubic ) { + goto Invalid_Outline; + } + + /* check first point to determine origin */ + if ( tag == FT_Curve_Tag_Conic ) { + /* first point is conic control. Yes, this happens. */ + if ( FT_CURVE_TAG( ras.outline.tags[last] ) == FT_Curve_Tag_On ) { + /* start at last point if it is on the curve */ + v_start = v_last; + limit--; + } else + { + /* if both first and last points are conic, */ + /* start at their middle and record its position */ + /* for closure */ + v_start.x = ( v_start.x + v_last.x ) / 2; + v_start.y = ( v_start.y + v_last.y ) / 2; + + v_last = v_start; + } + point--; + tags--; + } + + ras.lastX = v_start.x; + ras.lastY = v_start.y; + + while ( point < limit ) + { + point++; + tags++; + + tag = FT_CURVE_TAG( tags[0] ); + + switch ( tag ) + { + case FT_Curve_Tag_On: /* emit a single line_to */ + { + Long x, y; + + + x = SCALED( point->x ); + y = SCALED( point->y ); + if ( flipped ) { + SWAP_( x, y ); + } + + if ( Line_To( RAS_VARS x, y ) ) { + goto Fail; + } + continue; + } + + case FT_Curve_Tag_Conic: /* consume conic arcs */ + v_control.x = SCALED( point[0].x ); + v_control.y = SCALED( point[0].y ); + + if ( flipped ) { + SWAP_( v_control.x, v_control.y ); + } + +Do_Conic: + if ( point < limit ) { + FT_Vector v_middle; + Long x, y; + + + point++; + tags++; + tag = FT_CURVE_TAG( tags[0] ); + + x = SCALED( point[0].x ); + y = SCALED( point[0].y ); + + if ( flipped ) { + SWAP_( x, y ); + } + + if ( tag == FT_Curve_Tag_On ) { + if ( Conic_To( RAS_VARS v_control.x, v_control.y, x, y ) ) { + goto Fail; + } + continue; + } + + if ( tag != FT_Curve_Tag_Conic ) { + goto Invalid_Outline; + } + + v_middle.x = ( v_control.x + x ) / 2; + v_middle.y = ( v_control.y + y ) / 2; + + if ( Conic_To( RAS_VARS v_control.x, v_control.y, + v_middle.x, v_middle.y ) ) { + goto Fail; + } + + v_control.x = x; + v_control.y = y; + + goto Do_Conic; + } + + if ( Conic_To( RAS_VARS v_control.x, v_control.y, + v_start.x, v_start.y ) ) { + goto Fail; + } + + goto Close; + + default: /* FT_Curve_Tag_Cubic */ + { + Long x1, y1, x2, y2, x3, y3; + + + if ( point + 1 > limit || + FT_CURVE_TAG( tags[1] ) != FT_Curve_Tag_Cubic ) { + goto Invalid_Outline; + } + + point += 2; + tags += 2; + + x1 = SCALED( point[-2].x ); + y1 = SCALED( point[-2].y ); + x2 = SCALED( point[-1].x ); + y2 = SCALED( point[-1].y ); + x3 = SCALED( point[ 0].x ); + y3 = SCALED( point[ 0].y ); + + if ( flipped ) { + SWAP_( x1, y1 ); + SWAP_( x2, y2 ); + SWAP_( x3, y3 ); + } + + if ( point <= limit ) { + if ( Cubic_To( RAS_VARS x1, y1, x2, y2, x3, y3 ) ) { + goto Fail; + } + continue; + } + + if ( Cubic_To( RAS_VARS x1, y1, x2, y2, v_start.x, v_start.y ) ) { + goto Fail; + } + goto Close; + } + } + } + + /* close the contour with a line segment */ + if ( Line_To( RAS_VARS v_start.x, v_start.y ) ) { + goto Fail; + } + +Close: + return SUCCESS; + +Invalid_Outline: + ras.error = Raster_Err_Invalid; + +Fail: + return FAILURE; +} + + +/*************************************************************************/ +/* */ +/* */ +/* Convert_Glyph */ +/* */ +/* */ +/* Converts a glyph into a series of segments and arcs and makes a */ +/* profiles list with them. */ +/* */ +/* */ +/* flipped :: If set, flip the direction of curve. */ +/* */ +/* */ +/* SUCCESS on success, FAILURE if any error was encountered during */ +/* rendering. */ +/* */ +static +Bool Convert_Glyph( RAS_ARGS int flipped ) { + Short i; + UShort start; + + PProfile lastProfile; + + + ras.fProfile = NULL; + ras.joint = FALSE; + ras.fresh = FALSE; + + ras.maxBuff = ras.sizeBuff - AlignProfileSize; + + ras.numTurns = 0; + + ras.cProfile = (PProfile)ras.top; + ras.cProfile->offset = ras.top; + ras.num_Profs = 0; + + start = 0; + + for ( i = 0; i < ras.outline.n_contours; i++ ) + { + ras.state = Unknown; + ras.gProfile = NULL; + + if ( Decompose_Curve( RAS_VARS start, ras.outline.contours[i], flipped ) ) { + return FAILURE; + } + + start = ras.outline.contours[i] + 1; + + /* We must now see whether the extreme arcs join or not */ + if ( FRAC( ras.lastY ) == 0 && + ras.lastY >= ras.minY && + ras.lastY <= ras.maxY ) { + if ( ras.gProfile && ras.gProfile->flow == ras.cProfile->flow ) { + ras.top--; + } + } + /* Note that ras.gProfile can be nil if the contour was too small */ + /* to be drawn. */ + + lastProfile = ras.cProfile; + if ( End_Profile( RAS_VAR ) ) { + return FAILURE; + } + + /* close the `next profile in contour' linked list */ + if ( ras.gProfile ) { + lastProfile->next = ras.gProfile; + } + } + + if ( Finalize_Profile_Table( RAS_VAR ) ) { + return FAILURE; + } + + return ( ras.top < ras.maxBuff ? SUCCESS : FAILURE ); +} + + +/*************************************************************************/ +/*************************************************************************/ +/** **/ +/** SCAN-LINE SWEEPS AND DRAWING **/ +/** **/ +/*************************************************************************/ +/*************************************************************************/ + + +/*************************************************************************/ +/* */ +/* Init_Linked */ +/* */ +/* Initializes an empty linked list. */ +/* */ +static +void Init_Linked( TProfileList* l ) { + *l = NULL; +} + + +/*************************************************************************/ +/* */ +/* InsNew */ +/* */ +/* Inserts a new profile in a linked list. */ +/* */ +static +void InsNew( PProfileList list, + PProfile profile ) { + PProfile *old, current; + Long x; + + + old = list; + current = *old; + x = profile->X; + + while ( current ) + { + if ( x < current->X ) { + break; + } + old = ¤t->link; + current = *old; + } + + profile->link = current; + *old = profile; +} + + +/*************************************************************************/ +/* */ +/* DelOld */ +/* */ +/* Removes an old profile from a linked list. */ +/* */ +static +void DelOld( PProfileList list, + PProfile profile ) { + PProfile *old, current; + + + old = list; + current = *old; + + while ( current ) + { + if ( current == profile ) { + *old = current->link; + return; + } + + old = ¤t->link; + current = *old; + } + + /* we should never get there, unless the profile was not part of */ + /* the list. */ +} + + +/*************************************************************************/ +/* */ +/* Update */ +/* */ +/* Update all X offsets of a drawing list. */ +/* */ +static +void Update( PProfile first ) { + PProfile current = first; + + + while ( current ) + { + current->X = *current->offset; + current->offset += current->flow; + current->height--; + current = current->link; + } +} + + +/*************************************************************************/ +/* */ +/* Sort */ +/* */ +/* Sorts a trace list. In 95%, the list is already sorted. We need */ +/* an algorithm which is fast in this case. Bubble sort is enough */ +/* and simple. */ +/* */ +static +void Sort( PProfileList list ) { + PProfile *old, current, next; + + + /* First, set the new X coordinate of each profile */ + Update( *list ); + + /* Then sort them */ + old = list; + current = *old; + + if ( !current ) { + return; + } + + next = current->link; + + while ( next ) + { + if ( current->X <= next->X ) { + old = ¤t->link; + current = *old; + + if ( !current ) { + return; + } + } else + { + *old = next; + current->link = next->link; + next->link = current; + + old = list; + current = *old; + } + + next = current->link; + } +} + + +/*************************************************************************/ +/* */ +/* Vertical Sweep Procedure Set */ +/* */ +/* These four routines are used during the vertical black/white sweep */ +/* phase by the generic Draw_Sweep() function. */ +/* */ +/*************************************************************************/ + +static +void Vertical_Sweep_Init( RAS_ARGS Short* min, + Short* max ) { + Long pitch = ras.target.pitch; + + FT_UNUSED( max ); + + + ras.traceIncr = ( Short ) - pitch; + ras.traceOfs = -*min * pitch; + if ( pitch > 0 ) { + ras.traceOfs += ( ras.target.rows - 1 ) * pitch; + } + + ras.gray_min_x = 0; + ras.gray_max_x = 0; +} + + +static +void Vertical_Sweep_Span( RAS_ARGS Short y, + FT_F26Dot6 x1, + FT_F26Dot6 x2, + PProfile left, + PProfile right ) { + Long e1, e2; + Short c1, c2; + Byte f1, f2; + Byte* target; + + FT_UNUSED( y ); + FT_UNUSED( left ); + FT_UNUSED( right ); + + + /* Drop-out control */ + + e1 = TRUNC( CEILING( x1 ) ); + + if ( x2 - x1 - ras.precision <= ras.precision_jitter ) { + e2 = e1; + } else { + e2 = TRUNC( FLOOR( x2 ) ); + } + + if ( e2 >= 0 && e1 < ras.bWidth ) { + if ( e1 < 0 ) { + e1 = 0; + } + if ( e2 >= ras.bWidth ) { + e2 = ras.bWidth - 1; + } + + c1 = (Short)( e1 >> 3 ); + c2 = (Short)( e2 >> 3 ); + + f1 = (unsigned char)0xFF >> ( e1 & 7 ); + f2 = ~( (unsigned char)0x7F >> ( e2 & 7 ) ); + + if ( ras.gray_min_x > c1 ) { + ras.gray_min_x = c1; + } + if ( ras.gray_max_x < c2 ) { + ras.gray_max_x = c2; + } + + target = ras.bTarget + ras.traceOfs + c1; + c2 -= c1; + + if ( c2 > 0 ) { + target[0] |= f1; + + /* memset() is slower than the following code on many platforms. */ + /* This is due to the fact that, in the vast majority of cases, */ + /* the span length in bytes is relatively small. */ + c2--; + while ( c2 > 0 ) + { + *( ++target ) = 0xFF; + c2--; + } + target[1] |= f2; + } else { + *target |= ( f1 & f2 ); + } + } +} + + +static +void Vertical_Sweep_Drop( RAS_ARGS Short y, + FT_F26Dot6 x1, + FT_F26Dot6 x2, + PProfile left, + PProfile right ) { + Long e1, e2; + Short c1, f1; + + + /* Drop-out control */ + + e1 = CEILING( x1 ); + e2 = FLOOR( x2 ); + + if ( e1 > e2 ) { + if ( e1 == e2 + ras.precision ) { + switch ( ras.dropOutControl ) + { + case 1: + e1 = e2; + break; + + case 4: + e1 = CEILING( ( x1 + x2 + 1 ) / 2 ); + break; + + case 2: + case 5: + /* Drop-out Control Rule #4 */ + + /* The spec is not very clear regarding rule #4. It */ + /* presents a method that is way too costly to implement */ + /* while the general idea seems to get rid of `stubs'. */ + /* */ + /* Here, we only get rid of stubs recognized if: */ + /* */ + /* upper stub: */ + /* */ + /* - P_Left and P_Right are in the same contour */ + /* - P_Right is the successor of P_Left in that contour */ + /* - y is the top of P_Left and P_Right */ + /* */ + /* lower stub: */ + /* */ + /* - P_Left and P_Right are in the same contour */ + /* - P_Left is the successor of P_Right in that contour */ + /* - y is the bottom of P_Left */ + /* */ + + /* FIXXXME: uncommenting this line solves the disappearing */ + /* bit problem in the `7' of verdana 10pts, but */ + /* makes a new one in the `C' of arial 14pts */ + +#if 0 + if ( x2 - x1 < ras.precision_half ) +#endif + { + /* upper stub test */ + if ( left->next == right && left->height <= 0 ) { + return; + } + + /* lower stub test */ + if ( right->next == left && left->start == y ) { + return; + } + } + + /* check that the rightmost pixel isn't set */ + + e1 = TRUNC( e1 ); + + c1 = (Short)( e1 >> 3 ); + f1 = e1 & 7; + + if ( e1 >= 0 && e1 < ras.bWidth && + ras.bTarget[ras.traceOfs + c1] & ( 0x80 >> f1 ) ) { + return; + } + + if ( ras.dropOutControl == 2 ) { + e1 = e2; + } else { + e1 = CEILING( ( x1 + x2 + 1 ) / 2 ); + } + + break; + + default: + return; /* unsupported mode */ + } + } else { + return; + } + } + + e1 = TRUNC( e1 ); + + if ( e1 >= 0 && e1 < ras.bWidth ) { + c1 = (Short)( e1 >> 3 ); + f1 = e1 & 7; + + if ( ras.gray_min_x > c1 ) { + ras.gray_min_x = c1; + } + if ( ras.gray_max_x < c1 ) { + ras.gray_max_x = c1; + } + + ras.bTarget[ras.traceOfs + c1] |= (char)( 0x80 >> f1 ); + } +} + + +static +void Vertical_Sweep_Step( RAS_ARG ) { + ras.traceOfs += ras.traceIncr; +} + + +/***********************************************************************/ +/* */ +/* Horizontal Sweep Procedure Set */ +/* */ +/* These four routines are used during the horizontal black/white */ +/* sweep phase by the generic Draw_Sweep() function. */ +/* */ +/***********************************************************************/ + +static +void Horizontal_Sweep_Init( RAS_ARGS Short* min, + Short* max ) { + /* nothing, really */ + FT_UNUSED( raster ); + FT_UNUSED( min ); + FT_UNUSED( max ); +} + + +static +void Horizontal_Sweep_Span( RAS_ARGS Short y, + FT_F26Dot6 x1, + FT_F26Dot6 x2, + PProfile left, + PProfile right ) { + Long e1, e2; + PByte bits; + Byte f1; + + FT_UNUSED( left ); + FT_UNUSED( right ); + + + if ( x2 - x1 < ras.precision ) { + e1 = CEILING( x1 ); + e2 = FLOOR( x2 ); + + if ( e1 == e2 ) { + bits = ras.bTarget + ( y >> 3 ); + f1 = (Byte)( 0x80 >> ( y & 7 ) ); + + e1 = TRUNC( e1 ); + + if ( e1 >= 0 && e1 < ras.target.rows ) { + PByte p; + + + p = bits - e1 * ras.target.pitch; + if ( ras.target.pitch > 0 ) { + p += ( ras.target.rows - 1 ) * ras.target.pitch; + } + + p[0] |= f1; + } + } + } +} + + +static +void Horizontal_Sweep_Drop( RAS_ARGS Short y, + FT_F26Dot6 x1, + FT_F26Dot6 x2, + PProfile left, + PProfile right ) { + Long e1, e2; + PByte bits; + Byte f1; + + + /* During the horizontal sweep, we only take care of drop-outs */ + + e1 = CEILING( x1 ); + e2 = FLOOR( x2 ); + + if ( e1 > e2 ) { + if ( e1 == e2 + ras.precision ) { + switch ( ras.dropOutControl ) + { + case 1: + e1 = e2; + break; + + case 4: + e1 = CEILING( ( x1 + x2 + 1 ) / 2 ); + break; + + case 2: + case 5: + + /* Drop-out Control Rule #4 */ + + /* The spec is not very clear regarding rule #4. It */ + /* presents a method that is way too costly to implement */ + /* while the general idea seems to get rid of `stubs'. */ + /* */ + + /* rightmost stub test */ + if ( left->next == right && left->height <= 0 ) { + return; + } + + /* leftmost stub test */ + if ( right->next == left && left->start == y ) { + return; + } + + /* check that the rightmost pixel isn't set */ + + e1 = TRUNC( e1 ); + + bits = ras.bTarget + ( y >> 3 ); + f1 = (Byte)( 0x80 >> ( y & 7 ) ); + + bits -= e1 * ras.target.pitch; + if ( ras.target.pitch > 0 ) { + bits += ( ras.target.rows - 1 ) * ras.target.pitch; + } + + if ( e1 >= 0 && + e1 < ras.target.rows && + *bits & f1 ) { + return; + } + + if ( ras.dropOutControl == 2 ) { + e1 = e2; + } else { + e1 = CEILING( ( x1 + x2 + 1 ) / 2 ); + } + + break; + + default: + return; /* unsupported mode */ + } + } else { + return; + } + } + + bits = ras.bTarget + ( y >> 3 ); + f1 = (Byte)( 0x80 >> ( y & 7 ) ); + + e1 = TRUNC( e1 ); + + if ( e1 >= 0 && e1 < ras.target.rows ) { + bits -= e1 * ras.target.pitch; + if ( ras.target.pitch > 0 ) { + bits += ( ras.target.rows - 1 ) * ras.target.pitch; + } + + bits[0] |= f1; + } +} + + +static +void Horizontal_Sweep_Step( RAS_ARG ) { + /* Nothing, really */ + FT_UNUSED( raster ); +} + + +#ifdef FT_RASTER_OPTION_ANTI_ALIASING + + +/*************************************************************************/ +/* */ +/* Vertical Gray Sweep Procedure Set */ +/* */ +/* These two routines are used during the vertical gray-levels sweep */ +/* phase by the generic Draw_Sweep() function. */ +/* */ +/* NOTES */ +/* */ +/* - The target pixmap's width *must* be a multiple of 4. */ +/* */ +/* - You have to use the function Vertical_Sweep_Span() for the gray */ +/* span call. */ +/* */ +/*************************************************************************/ + +static +void Vertical_Gray_Sweep_Init( RAS_ARGS Short* min, + Short* max ) { + Long pitch, byte_len; + + + *min = *min & - 2; + *max = ( *max + 3 ) & - 2; + + ras.traceOfs = 0; + pitch = ras.target.pitch; + byte_len = -pitch; + ras.traceIncr = (Short)byte_len; + ras.traceG = ( *min / 2 ) * byte_len; + + if ( pitch > 0 ) { + ras.traceG += ( ras.target.rows - 1 ) * pitch; + byte_len = -byte_len; + } + + ras.gray_min_x = (Short)byte_len; + ras.gray_max_x = -(Short)byte_len; +} + + +static +void Vertical_Gray_Sweep_Step( RAS_ARG ) { + Int c1, c2; + PByte pix, bit, bit2; + Int* count = ras.count_table; + Byte* grays; + + + ras.traceOfs += ras.gray_width; + + if ( ras.traceOfs > ras.gray_width ) { + pix = ras.gTarget + ras.traceG + ras.gray_min_x * 4; + grays = ras.grays; + + if ( ras.gray_max_x >= 0 ) { + Long last_pixel = ras.target.width - 1; + Int last_cell = last_pixel >> 2; + Int last_bit = last_pixel & 3; + Bool over = 0; + + + if ( ras.gray_max_x >= last_cell && last_bit != 3 ) { + ras.gray_max_x = last_cell - 1; + over = 1; + } + + if ( ras.gray_min_x < 0 ) { + ras.gray_min_x = 0; + } + + bit = ras.bTarget + ras.gray_min_x; + bit2 = bit + ras.gray_width; + + c1 = ras.gray_max_x - ras.gray_min_x; + + while ( c1 >= 0 ) + { + c2 = count[*bit] + count[*bit2]; + + if ( c2 ) { + pix[0] = grays[( c2 >> 12 ) & 0x000F]; + pix[1] = grays[( c2 >> 8 ) & 0x000F]; + pix[2] = grays[( c2 >> 4 ) & 0x000F]; + pix[3] = grays[ c2 & 0x000F]; + + *bit = 0; + *bit2 = 0; + } + + bit++; + bit2++; + pix += 4; + c1--; + } + + if ( over ) { + c2 = count[*bit] + count[*bit2]; + if ( c2 ) { + switch ( last_bit ) + { + case 2: + pix[2] = grays[( c2 >> 4 ) & 0x000F]; + case 1: + pix[1] = grays[( c2 >> 8 ) & 0x000F]; + default: + pix[0] = grays[( c2 >> 12 ) & 0x000F]; + } + + *bit = 0; + *bit2 = 0; + } + } + } + + ras.traceOfs = 0; + ras.traceG += ras.traceIncr; + + ras.gray_min_x = 32000; + ras.gray_max_x = -32000; + } +} + + +static +void Horizontal_Gray_Sweep_Span( RAS_ARGS Short y, + FT_F26Dot6 x1, + FT_F26Dot6 x2, + PProfile left, + PProfile right ) { + /* nothing, really */ + FT_UNUSED( raster ); + FT_UNUSED( y ); + FT_UNUSED( x1 ); + FT_UNUSED( x2 ); + FT_UNUSED( left ); + FT_UNUSED( right ); +} + + +static +void Horizontal_Gray_Sweep_Drop( RAS_ARGS Short y, + FT_F26Dot6 x1, + FT_F26Dot6 x2, + PProfile left, + PProfile right ) { + Long e1, e2; + PByte pixel; + Byte color; + + + /* During the horizontal sweep, we only take care of drop-outs */ + e1 = CEILING( x1 ); + e2 = FLOOR( x2 ); + + if ( e1 > e2 ) { + if ( e1 == e2 + ras.precision ) { + switch ( ras.dropOutControl ) + { + case 1: + e1 = e2; + break; + + case 4: + e1 = CEILING( ( x1 + x2 + 1 ) / 2 ); + break; + + case 2: + case 5: + + /* Drop-out Control Rule #4 */ + + /* The spec is not very clear regarding rule #4. It */ + /* presents a method that is way too costly to implement */ + /* while the general idea seems to get rid of `stubs'. */ + /* */ + + /* rightmost stub test */ + if ( left->next == right && left->height <= 0 ) { + return; + } + + /* leftmost stub test */ + if ( right->next == left && left->start == y ) { + return; + } + + if ( ras.dropOutControl == 2 ) { + e1 = e2; + } else { + e1 = CEILING( ( x1 + x2 + 1 ) / 2 ); + } + + break; + + default: + return; /* unsupported mode */ + } + } else { + return; + } + } + + if ( e1 >= 0 ) { + if ( x2 - x1 >= ras.precision_half ) { + color = ras.grays[2]; + } else { + color = ras.grays[1]; + } + + e1 = TRUNC( e1 ) / 2; + if ( e1 < ras.target.rows ) { + pixel = ras.gTarget - e1 * ras.target.pitch + y / 2; + if ( ras.target.pitch > 0 ) { + pixel += ( ras.target.rows - 1 ) * ras.target.pitch; + } + + if ( pixel[0] == ras.grays[0] ) { + pixel[0] = color; + } + } + } +} + + +#endif /* FT_RASTER_OPTION_ANTI_ALIASING */ + + +/*************************************************************************/ +/* */ +/* Generic Sweep Drawing routine */ +/* */ +/*************************************************************************/ + +static +Bool Draw_Sweep( RAS_ARG ) { + Short y, y_change, y_height; + + PProfile P, Q, P_Left, P_Right; + + Short min_Y, max_Y, top, bottom, dropouts; + + Long x1, x2, xs, e1, e2; + + TProfileList wait; + TProfileList draw_left, draw_right; + + + /* Init empty linked lists */ + + Init_Linked( &wait ); + + Init_Linked( &draw_left ); + Init_Linked( &draw_right ); + + /* first, compute min and max Y */ + + P = ras.fProfile; + max_Y = (Short)TRUNC( ras.minY ); + min_Y = (Short)TRUNC( ras.maxY ); + + while ( P ) + { + Q = P->link; + + bottom = (Short)P->start; + top = (Short)P->start + P->height - 1; + + if ( min_Y > bottom ) { + min_Y = bottom; + } + if ( max_Y < top ) { + max_Y = top; + } + + P->X = 0; + InsNew( &wait, P ); + + P = Q; + } + + /* Check the Y-turns */ + if ( ras.numTurns == 0 ) { + ras.error = Raster_Err_Invalid; + return FAILURE; + } + + /* Now inits the sweep */ + + ras.Proc_Sweep_Init( RAS_VARS & min_Y, &max_Y ); + + /* Then compute the distance of each profile from min_Y */ + + P = wait; + + while ( P ) + { + P->countL = P->start - min_Y; + P = P->link; + } + + /* Let's go */ + + y = min_Y; + y_height = 0; + + if ( ras.numTurns > 0 && + ras.sizeBuff[-ras.numTurns] == min_Y ) { + ras.numTurns--; + } + + while ( ras.numTurns > 0 ) + { + /* look in the wait list for new activations */ + + P = wait; + + while ( P ) + { + Q = P->link; + P->countL -= y_height; + if ( P->countL == 0 ) { + DelOld( &wait, P ); + + switch ( P->flow ) + { + case Flow_Up: + InsNew( &draw_left, P ); + break; + + case Flow_Down: + InsNew( &draw_right, P ); + break; + } + } + + P = Q; + } + + /* Sort the drawing lists */ + + Sort( &draw_left ); + Sort( &draw_right ); + + y_change = (Short)ras.sizeBuff[-ras.numTurns--]; + y_height = y_change - y; + + while ( y < y_change ) + { + /* Let's trace */ + + dropouts = 0; + + P_Left = draw_left; + P_Right = draw_right; + + while ( P_Left ) + { + x1 = P_Left->X; + x2 = P_Right->X; + + if ( x1 > x2 ) { + xs = x1; + x1 = x2; + x2 = xs; + } + + if ( x2 - x1 <= ras.precision ) { + e1 = FLOOR( x1 ); + e2 = CEILING( x2 ); + + if ( ras.dropOutControl != 0 && + ( e1 > e2 || e2 == e1 + ras.precision ) ) { + /* a drop out was detected */ + + P_Left->X = x1; + P_Right->X = x2; + + /* mark profile for drop-out processing */ + P_Left->countL = 1; + dropouts++; + + goto Skip_To_Next; + } + } + + ras.Proc_Sweep_Span( RAS_VARS y, x1, x2, P_Left, P_Right ); + +Skip_To_Next: + + P_Left = P_Left->link; + P_Right = P_Right->link; + } + + /* now perform the dropouts _after_ the span drawing -- */ + /* drop-outs processing has been moved out of the loop */ + /* for performance tuning */ + if ( dropouts > 0 ) { + goto Scan_DropOuts; + } + +Next_Line: + + ras.Proc_Sweep_Step( RAS_VAR ); + + y++; + + if ( y < y_change ) { + Sort( &draw_left ); + Sort( &draw_right ); + } + } + + /* Now finalize the profiles that needs it */ + + { + PProfile Q, P; + + + P = draw_left; + while ( P ) + { + Q = P->link; + if ( P->height == 0 ) { + DelOld( &draw_left, P ); + } + P = Q; + } + } + + { + PProfile Q, P = draw_right; + + + while ( P ) + { + Q = P->link; + if ( P->height == 0 ) { + DelOld( &draw_right, P ); + } + P = Q; + } + } + } + + /* for gray-scaling, flushes the bitmap scanline cache */ + while ( y <= max_Y ) + { + ras.Proc_Sweep_Step( RAS_VAR ); + y++; + } + + return SUCCESS; + +Scan_DropOuts: + + P_Left = draw_left; + P_Right = draw_right; + + while ( P_Left ) + { + if ( P_Left->countL ) { + P_Left->countL = 0; +#if 0 + dropouts--; /* -- this is useful when debugging only */ +#endif + ras.Proc_Sweep_Drop( RAS_VARS y, + P_Left->X, + P_Right->X, + P_Left, + P_Right ); + } + + P_Left = P_Left->link; + P_Right = P_Right->link; + } + + goto Next_Line; +} + + +/*************************************************************************/ +/* */ +/* */ +/* Render_Single_Pass */ +/* */ +/* */ +/* Performs one sweep with sub-banding. */ +/* */ +/* */ +/* flipped :: If set, flip the direction of the outline. */ +/* */ +/* */ +/* Renderer error code. */ +/* */ +static +int Render_Single_Pass( RAS_ARGS Bool flipped ) { + Short i, j, k; + + + while ( ras.band_top >= 0 ) + { + ras.maxY = (Long)ras.band_stack[ras.band_top].y_max * ras.precision; + ras.minY = (Long)ras.band_stack[ras.band_top].y_min * ras.precision; + + ras.top = ras.buff; + + ras.error = Raster_Err_None; + + if ( Convert_Glyph( RAS_VARS flipped ) ) { + if ( ras.error != Raster_Err_Overflow ) { + return FAILURE; + } + + ras.error = Raster_Err_None; + + /* sub-banding */ + +#ifdef DEBUG_RASTER + ClearBand( RAS_VARS TRUNC( ras.minY ), TRUNC( ras.maxY ) ); +#endif + + i = ras.band_stack[ras.band_top].y_min; + j = ras.band_stack[ras.band_top].y_max; + + k = ( i + j ) / 2; + + if ( ras.band_top >= 7 || k < i ) { + ras.band_top = 0; + ras.error = Raster_Err_Invalid; + + return ras.error; + } + + ras.band_stack[ras.band_top + 1].y_min = k; + ras.band_stack[ras.band_top + 1].y_max = j; + + ras.band_stack[ras.band_top].y_max = k - 1; + + ras.band_top++; + } else + { + if ( ras.fProfile ) { + if ( Draw_Sweep( RAS_VAR ) ) { + return ras.error; + } + } + ras.band_top--; + } + } + + return SUCCESS; +} + + +/*************************************************************************/ +/* */ +/* */ +/* Render_Glyph */ +/* */ +/* */ +/* Renders a glyph in a bitmap. Sub-banding if needed. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +/* XXX Fixme: ftraster's error codes don't harmonize with FT2's ones! */ +/* */ +LOCAL_FUNC +FT_Error Render_Glyph( RAS_ARG ) { + FT_Error error; + + + Set_High_Precision( RAS_VARS ras.outline.flags & + ft_outline_high_precision ); + ras.scale_shift = ras.precision_shift; + ras.dropOutControl = 2; + ras.second_pass = !( ras.outline.flags & ft_outline_single_pass ); + + /* Vertical Sweep */ + ras.Proc_Sweep_Init = Vertical_Sweep_Init; + ras.Proc_Sweep_Span = Vertical_Sweep_Span; + ras.Proc_Sweep_Drop = Vertical_Sweep_Drop; + ras.Proc_Sweep_Step = Vertical_Sweep_Step; + + ras.band_top = 0; + ras.band_stack[0].y_min = 0; + ras.band_stack[0].y_max = ras.target.rows - 1; + + ras.bWidth = ras.target.width; + ras.bTarget = (Byte*)ras.target.buffer; + + if ( ( error = Render_Single_Pass( RAS_VARS 0 ) ) != 0 ) { + return error; + } + + /* Horizontal Sweep */ + if ( ras.second_pass && ras.dropOutControl != 0 ) { + ras.Proc_Sweep_Init = Horizontal_Sweep_Init; + ras.Proc_Sweep_Span = Horizontal_Sweep_Span; + ras.Proc_Sweep_Drop = Horizontal_Sweep_Drop; + ras.Proc_Sweep_Step = Horizontal_Sweep_Step; + + ras.band_top = 0; + ras.band_stack[0].y_min = 0; + ras.band_stack[0].y_max = ras.target.width - 1; + + if ( ( error = Render_Single_Pass( RAS_VARS 1 ) ) != 0 ) { + return error; + } + } + + return FT_Err_Ok; +} + + +#ifdef FT_RASTER_OPTION_ANTI_ALIASING + + +/*************************************************************************/ +/* */ +/* */ +/* Render_Gray_Glyph */ +/* */ +/* */ +/* Renders a glyph with grayscaling. Sub-banding if needed. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +LOCAL_FUNC +FT_Error Render_Gray_Glyph( RAS_ARG ) { + Long pixel_width; + FT_Error error; + + + Set_High_Precision( RAS_VARS ras.outline.flags & + ft_outline_high_precision ); + ras.scale_shift = ras.precision_shift + 1; + ras.dropOutControl = 2; + ras.second_pass = !( ras.outline.flags & ft_outline_single_pass ); + + /* Vertical Sweep */ + + ras.band_top = 0; + ras.band_stack[0].y_min = 0; + ras.band_stack[0].y_max = 2 * ras.target.rows - 1; + + ras.bWidth = ras.gray_width; + pixel_width = 2 * ( ( ras.target.width + 3 ) >> 2 ); + + if ( ras.bWidth > pixel_width ) { + ras.bWidth = pixel_width; + } + + ras.bWidth = ras.bWidth * 8; + ras.bTarget = (Byte*)ras.gray_lines; + ras.gTarget = (Byte*)ras.target.buffer; + + ras.Proc_Sweep_Init = Vertical_Gray_Sweep_Init; + ras.Proc_Sweep_Span = Vertical_Sweep_Span; + ras.Proc_Sweep_Drop = Vertical_Sweep_Drop; + ras.Proc_Sweep_Step = Vertical_Gray_Sweep_Step; + + error = Render_Single_Pass( RAS_VARS 0 ); + if ( error ) { + return error; + } + + /* Horizontal Sweep */ + if ( ras.second_pass && ras.dropOutControl != 0 ) { + ras.Proc_Sweep_Init = Horizontal_Sweep_Init; + ras.Proc_Sweep_Span = Horizontal_Gray_Sweep_Span; + ras.Proc_Sweep_Drop = Horizontal_Gray_Sweep_Drop; + ras.Proc_Sweep_Step = Horizontal_Sweep_Step; + + ras.band_top = 0; + ras.band_stack[0].y_min = 0; + ras.band_stack[0].y_max = ras.target.width * 2 - 1; + + error = Render_Single_Pass( RAS_VARS 1 ); + if ( error ) { + return error; + } + } + + return FT_Err_Ok; +} + +#else /* FT_RASTER_OPTION_ANTI_ALIASING */ + +LOCAL_FUNC +FT_Error Render_Gray_Glyph( RAS_ARG ) { + FT_UNUSED_RASTER; + + return FT_Err_Cannot_Render_Glyph; +} + +#endif /* FT_RASTER_OPTION_ANTI_ALIASING */ + + +static +void ft_black_init( TRaster_Instance* raster ) { + FT_UInt n; + FT_ULong c; + + + /* setup count table */ + for ( n = 0; n < 256; n++ ) + { + c = ( n & 0x55 ) + ( ( n & 0xAA ) >> 1 ); + + c = ( ( c << 6 ) & 0x3000 ) | + ( ( c << 4 ) & 0x0300 ) | + ( ( c << 2 ) & 0x0030 ) | + ( c & 0x0003 ); + + raster->count_table[n] = c; + } + +#ifdef FT_RASTER_OPTION_ANTI_ALIASING + + /* set default 5-levels gray palette */ + for ( n = 0; n < 5; n++ ) + raster->grays[n] = n * 255 / 4; + + raster->gray_width = RASTER_GRAY_LINES / 2; + +#endif +} + + +/**** RASTER OBJECT CREATION: In standalone mode, we simply use *****/ +/**** a static object. *****/ + + +#ifdef _STANDALONE_ + + +static +int ft_black_new( void* memory, + FT_Raster *araster ) { + static FT_RasterRec_ the_raster; + + + *araster = &the_raster; + memset( &the_raster, sizeof( the_raster ), 0 ); + ft_black_init( &the_raster ); + + return 0; +} + + +static +void ft_black_done( FT_Raster raster ) { + /* nothing */ + raster->init = 0; +} + + +#else /* _STANDALONE_ */ + + +static +int ft_black_new( FT_Memory memory, + TRaster_Instance** araster ) { + FT_Error error; + TRaster_Instance* raster; + + + *araster = 0; + if ( !ALLOC( raster, sizeof( *raster ) ) ) { + raster->memory = memory; + ft_black_init( raster ); + + *araster = raster; + } + + return error; +} + + +static +void ft_black_done( TRaster_Instance* raster ) { + FT_Memory memory = (FT_Memory)raster->memory; + FREE( raster ); +} + + +#endif /* _STANDALONE_ */ + + +static +void ft_black_reset( TRaster_Instance* raster, + const char* pool_base, + long pool_size ) { + if ( raster && pool_base && pool_size >= 4096 ) { + /* save the pool */ + raster->buff = (PLong)pool_base; + raster->sizeBuff = raster->buff + pool_size / sizeof( Long ); + } +} + + +static +void ft_black_set_mode( TRaster_Instance* raster, + unsigned long mode, + const char* palette ) { +#ifdef FT_RASTER_OPTION_ANTI_ALIASING + + if ( mode == FT_MAKE_TAG( 'p', 'a', 'l', '5' ) ) { + /* set 5-levels gray palette */ + raster->grays[0] = palette[0]; + raster->grays[1] = palette[1]; + raster->grays[2] = palette[2]; + raster->grays[3] = palette[3]; + raster->grays[4] = palette[4]; + } + +#else + + FT_UNUSED( raster ); + FT_UNUSED( mode ); + FT_UNUSED( palette ); + +#endif +} + + +static +int ft_black_render( TRaster_Instance* raster, + FT_Raster_Params* params ) { + FT_Outline* outline = (FT_Outline*)params->source; + FT_Bitmap* target_map = params->target; + + + if ( !raster || !raster->buff || !raster->sizeBuff ) { + return Raster_Err_Not_Ini; + } + + if ( !outline || !outline->contours || !outline->points ) { + return Raster_Err_Invalid; + } + + /* return immediately if the outline is empty */ + if ( outline->n_points == 0 || outline->n_contours <= 0 ) { + return Raster_Err_None; + } + + if ( outline->n_points != outline->contours[outline->n_contours - 1] + 1 ) { + return Raster_Err_Invalid; + } + + if ( !target_map || !target_map->buffer ) { + return Raster_Err_Invalid; + } + + /* this version of the raster does not support direct rendering, sorry */ + if ( params->flags & ft_raster_flag_direct ) { + return Raster_Err_Unsupported; + } + + ras.outline = *outline; + ras.target = *target_map; + + return ( ( params->flags & ft_raster_flag_aa ) + ? Render_Gray_Glyph( raster ) + : Render_Glyph( raster ) ); +} + + +FT_Raster_Funcs ft_standard_raster = +{ + ft_glyph_format_outline, + (FT_Raster_New_Func) ft_black_new, + (FT_Raster_Reset_Func) ft_black_reset, + (FT_Raster_Set_Mode_Func)ft_black_set_mode, + (FT_Raster_Render_Func) ft_black_render, + (FT_Raster_Done_Func) ft_black_done +}; + + +/* END */ diff --git a/Projects/Android/jni/rtcw/src/ft2/ftraster.h b/Projects/Android/jni/rtcw/src/ft2/ftraster.h new file mode 100644 index 0000000..f7cebe9 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/ft2/ftraster.h @@ -0,0 +1,50 @@ +/***************************************************************************/ +/* */ +/* ftraster.h */ +/* */ +/* The FreeType glyph rasterizer (specification). */ +/* */ +/* Copyright 1996-2000 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used */ +/* modified and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef FTRASTER_H +#define FTRASTER_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include "ftimage.h" + + +/*************************************************************************/ +/* */ +/* Uncomment the following line if you are using ftraster.c as a */ +/* standalone module, fully independent of FreeType. */ +/* */ +/* #define _STANDALONE_ */ + +#ifndef FT_EXPORT_VAR +#define FT_EXPORT_VAR( x ) extern x +#endif + +FT_EXPORT_VAR( FT_Raster_Funcs ) ft_standard_raster; + +#ifdef __cplusplus +} +#endif + + +#endif /* FTRASTER_H */ + + +/* END */ diff --git a/Projects/Android/jni/rtcw/src/ft2/ftrend1.c b/Projects/Android/jni/rtcw/src/ft2/ftrend1.c new file mode 100644 index 0000000..78af227 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/ft2/ftrend1.c @@ -0,0 +1,264 @@ +/***************************************************************************/ +/* */ +/* ftrend1.c */ +/* */ +/* The FreeType glyph rasterizer interface (body). */ +/* */ +/* Copyright 1996-2000 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#include "ftobjs.h" +#include "ftoutln.h" + + + +#include "ftrend1.h" +#include "ftraster.h" + + +/* initialize renderer -- init its raster */ +static +FT_Error ft_raster1_init( FT_Renderer render ) { + FT_Library library = FT_MODULE_LIBRARY( render ); + + + render->clazz->raster_class->raster_reset( render->raster, + library->raster_pool, + library->raster_pool_size ); + + return FT_Err_Ok; +} + + +/* set render-specific mode */ +static +FT_Error ft_raster1_set_mode( FT_Renderer render, + FT_ULong mode_tag, + FT_Pointer data ) { + /* we simply pass it to the raster */ + return render->clazz->raster_class->raster_set_mode( render->raster, + mode_tag, + data ); +} + + +/* transform a given glyph image */ +static +FT_Error ft_raster1_transform( FT_Renderer render, + FT_GlyphSlot slot, + FT_Matrix* matrix, + FT_Vector* delta ) { + FT_Error error = FT_Err_Ok; + + + if ( slot->format != render->glyph_format ) { + error = FT_Err_Invalid_Argument; + goto Exit; + } + + if ( matrix ) { + FT_Outline_Transform( &slot->outline, matrix ); + } + + if ( delta ) { + FT_Outline_Translate( &slot->outline, delta->x, delta->y ); + } + +Exit: + return error; +} + + +/* return the glyph's control box */ +static +void ft_raster1_get_cbox( FT_Renderer render, + FT_GlyphSlot slot, + FT_BBox* cbox ) { + MEM_Set( cbox, 0, sizeof( *cbox ) ); + + if ( slot->format == render->glyph_format ) { + FT_Outline_Get_CBox( &slot->outline, cbox ); + } +} + + +/* convert a slot's glyph image into a bitmap */ +static +FT_Error ft_raster1_render( FT_Renderer render, + FT_GlyphSlot slot, + FT_UInt mode, + FT_Vector* origin ) { + FT_Error error; + FT_Outline* outline; + FT_BBox cbox; + FT_UInt width, height, pitch; + FT_Bitmap* bitmap; + FT_Memory memory; + + FT_Raster_Params params; + + + /* check glyph image format */ + if ( slot->format != render->glyph_format ) { + error = FT_Err_Invalid_Argument; + goto Exit; + } + + /* check rendering mode */ + if ( mode != ft_render_mode_mono ) { + /* raster1 is only capable of producing monochrome bitmaps */ + if ( render->clazz == &ft_raster1_renderer_class ) { + return FT_Err_Cannot_Render_Glyph; + } + } else + { + /* raster5 is only capable of producing 5-gray-levels bitmaps */ + if ( render->clazz == &ft_raster5_renderer_class ) { + return FT_Err_Cannot_Render_Glyph; + } + } + + outline = &slot->outline; + + /* translate the outline to the new origin if needed */ + if ( origin ) { + FT_Outline_Translate( outline, origin->x, origin->y ); + } + + /* compute the control box, and grid fit it */ + FT_Outline_Get_CBox( outline, &cbox ); + + cbox.xMin &= -64; + cbox.yMin &= -64; + cbox.xMax = ( cbox.xMax + 63 ) & - 64; + cbox.yMax = ( cbox.yMax + 63 ) & - 64; + + width = ( cbox.xMax - cbox.xMin ) >> 6; + height = ( cbox.yMax - cbox.yMin ) >> 6; + bitmap = &slot->bitmap; + memory = render->root.memory; + + /* release old bitmap buffer */ + if ( slot->flags & ft_glyph_own_bitmap ) { + FREE( bitmap->buffer ); + slot->flags &= ~ft_glyph_own_bitmap; + } + + /* allocate new one, depends on pixel format */ + if ( !( mode & ft_render_mode_mono ) ) { + /* we pad to 32 bits, only for backwards compatibility with FT 1.x */ + pitch = ( width + 3 ) & - 4; + bitmap->pixel_mode = ft_pixel_mode_grays; + bitmap->num_grays = 256; + } else + { + pitch = ( width + 7 ) >> 3; + bitmap->pixel_mode = ft_pixel_mode_mono; + } + + bitmap->width = width; + bitmap->rows = height; + bitmap->pitch = pitch; + + if ( ALLOC( bitmap->buffer, (FT_ULong)pitch * height ) ) { + goto Exit; + } + + slot->flags |= ft_glyph_own_bitmap; + + /* translate outline to render it into the bitmap */ + FT_Outline_Translate( outline, -cbox.xMin, -cbox.yMin ); + + /* set up parameters */ + params.target = bitmap; + params.source = outline; + params.flags = 0; + + if ( bitmap->pixel_mode == ft_pixel_mode_grays ) { + params.flags |= ft_raster_flag_aa; + } + + /* render outline into the bitmap */ + error = render->raster_render( render->raster, ¶ms ); + if ( error ) { + goto Exit; + } + + slot->format = ft_glyph_format_bitmap; + slot->bitmap_left = cbox.xMin >> 6; + slot->bitmap_top = cbox.yMax >> 6; + +Exit: + return error; +} + + +const FT_Renderer_Class ft_raster1_renderer_class = +{ + { + ft_module_renderer, + sizeof( FT_RendererRec ), + + "raster1", + 0x10000L, + 0x20000L, + + 0, /* module specific interface */ + + (FT_Module_Constructor)ft_raster1_init, + (FT_Module_Destructor) 0, + (FT_Module_Requester) 0 + }, + + ft_glyph_format_outline, + + (FTRenderer_render) ft_raster1_render, + (FTRenderer_transform)ft_raster1_transform, + (FTRenderer_getCBox) ft_raster1_get_cbox, + (FTRenderer_setMode) ft_raster1_set_mode, + + (FT_Raster_Funcs*) &ft_standard_raster +}; + + +/* this renderer is _NOT_ part of the default modules, you'll need */ +/* to register it by hand in your application. It should only be */ +/* used for backwards-compatibility with FT 1.x anyway. */ +const FT_Renderer_Class ft_raster5_renderer_class = +{ + { + ft_module_renderer, + sizeof( FT_RendererRec ), + + "raster5", + 0x10000L, + 0x20000L, + + 0, /* module specific interface */ + + (FT_Module_Constructor)ft_raster1_init, + (FT_Module_Destructor) 0, + (FT_Module_Requester) 0 + }, + + ft_glyph_format_outline, + + (FTRenderer_render) ft_raster1_render, + (FTRenderer_transform)ft_raster1_transform, + (FTRenderer_getCBox) ft_raster1_get_cbox, + (FTRenderer_setMode) ft_raster1_set_mode, + + (FT_Raster_Funcs*) &ft_standard_raster +}; + + +/* END */ diff --git a/Projects/Android/jni/rtcw/src/ft2/ftrend1.h b/Projects/Android/jni/rtcw/src/ft2/ftrend1.h new file mode 100644 index 0000000..51f26b3 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/ft2/ftrend1.h @@ -0,0 +1,37 @@ +/***************************************************************************/ +/* */ +/* ftrend1.h */ +/* */ +/* The FreeType glyph rasterizer interface (specification). */ +/* */ +/* Copyright 1996-2000 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef FTREND1_H +#define FTREND1_H + +#include "ftrender.h" + + +FT_EXPORT_VAR( const FT_Renderer_Class ) ft_raster1_renderer_class; + +/* this renderer is _NOT_ part of the default modules, you'll need */ +/* to register it by hand in your application. It should only be */ +/* used for backwards-compatibility with FT 1.x anyway. */ +/* */ +FT_EXPORT_VAR( const FT_Renderer_Class ) ft_raster5_renderer_class; + + +#endif /* FTREND1_H */ + + +/* END */ diff --git a/Projects/Android/jni/rtcw/src/ft2/ftrender.h b/Projects/Android/jni/rtcw/src/ft2/ftrender.h new file mode 100644 index 0000000..90142be --- /dev/null +++ b/Projects/Android/jni/rtcw/src/ft2/ftrender.h @@ -0,0 +1,191 @@ +/***************************************************************************/ +/* */ +/* ftrender.h */ +/* */ +/* FreeType renderer modules public interface (specification). */ +/* */ +/* Copyright 1996-2000 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef FTRENDER_H +#define FTRENDER_H + +#include "ftmodule.h" +#include "ftglyph.h" + + +#ifdef __cplusplus +extern "C" { +#endif + + +/* create a new glyph object */ +typedef FT_Error ( *FT_Glyph_Init_Func )( FT_Glyph glyph, + FT_GlyphSlot slot ); + +/* destroys a given glyph object */ +typedef void ( *FT_Glyph_Done_Func )( FT_Glyph glyph ); + +typedef void ( *FT_Glyph_Transform_Func )( FT_Glyph glyph, + FT_Matrix* matrix, + FT_Vector* delta ); + +typedef void ( *FT_Glyph_BBox_Func )( FT_Glyph glyph, + FT_BBox* abbox ); + +typedef FT_Error ( *FT_Glyph_Copy_Func )( FT_Glyph source, + FT_Glyph target ); + +typedef FT_Error ( *FT_Glyph_Prepare_Func )( FT_Glyph glyph, + FT_GlyphSlot slot ); + +struct FT_Glyph_Class_ +{ + FT_UInt glyph_size; + FT_Glyph_Format glyph_format; + FT_Glyph_Init_Func glyph_init; + FT_Glyph_Done_Func glyph_done; + FT_Glyph_Copy_Func glyph_copy; + FT_Glyph_Transform_Func glyph_transform; + FT_Glyph_BBox_Func glyph_bbox; + FT_Glyph_Prepare_Func glyph_prepare; +}; + + +typedef FT_Error ( *FTRenderer_render )( FT_Renderer renderer, + FT_GlyphSlot slot, + FT_UInt mode, + FT_Vector* origin ); + +typedef FT_Error ( *FTRenderer_transform )( FT_Renderer renderer, + FT_GlyphSlot slot, + FT_Matrix* matrix, + FT_Vector* delta ); + +typedef void ( *FTRenderer_getCBox )( FT_Renderer renderer, + FT_GlyphSlot slot, + FT_BBox* cbox ); + +typedef FT_Error ( *FTRenderer_setMode )( FT_Renderer renderer, + FT_ULong mode_tag, + FT_Pointer mode_ptr ); + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Renderer_Class */ +/* */ +/* */ +/* The renderer module class descriptor. */ +/* */ +/* */ +/* root :: The root FT_Module_Class fields. */ +/* */ +/* glyph_format :: The glyph image format this renderer handles. */ +/* */ +/* render_glyph :: A method used to render the image that is in a */ +/* given glyph slot into a bitmap. */ +/* */ +/* set_mode :: A method used to pass additional parameters. */ +/* */ +/* raster_class :: For `ft_glyph_format_outline' renderers only, this */ +/* is a pointer to its raster's class. */ +/* */ +/* raster :: For `ft_glyph_format_outline' renderers only. this */ +/* is a pointer to the corresponding raster object, */ +/* if any. */ +/* */ +typedef struct FT_Renderer_Class_ +{ + FT_Module_Class root; + + FT_Glyph_Format glyph_format; + + FTRenderer_render render_glyph; + FTRenderer_transform transform_glyph; + FTRenderer_getCBox get_glyph_cbox; + FTRenderer_setMode set_mode; + + FT_Raster_Funcs* raster_class; + +} FT_Renderer_Class; + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Get_Renderer */ +/* */ +/* */ +/* Retrieves the current renderer for a given glyph format. */ +/* */ +/* */ +/* library :: A handle to the library object. */ +/* */ +/* format :: The glyph format. */ +/* */ +/* */ +/* A renderer handle. 0 if none found. */ +/* */ +/* */ +/* An error will be returned if a module already exists by that name, */ +/* or if the module requires a version of FreeType that is too great. */ +/* */ +/* To add a new renderer, simply use FT_Add_Module(). To retrieve a */ +/* renderer by its name, use FT_Get_Module(). */ +/* */ +FT_EXPORT_DEF( FT_Renderer ) FT_Get_Renderer( FT_Library library, + FT_Glyph_Format format ); + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Set_Renderer */ +/* */ +/* */ +/* Sets the current renderer to use, and set additional mode. */ +/* */ +/* */ +/* library :: A handle to the library object. */ +/* */ +/* renderer :: A handle to the renderer object. */ +/* */ +/* num_params :: The number of additional parameters. */ +/* */ +/* parameters :: Additional parameters. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +/* */ +/* In case of success, the renderer will be used to convert glyph */ +/* images in the renderer's known format into bitmaps. */ +/* */ +/* This doesn't change the current renderer for other formats. */ +/* */ +FT_EXPORT_DEF( FT_Error ) FT_Set_Renderer( FT_Library library, + FT_Renderer renderer, + FT_UInt num_params, + FT_Parameter * parameters ); + + +#ifdef __cplusplus +} +#endif + + +#endif /* FTRENDER_H */ + + +/* END */ diff --git a/Projects/Android/jni/rtcw/src/ft2/ftsmooth.c b/Projects/Android/jni/rtcw/src/ft2/ftsmooth.c new file mode 100644 index 0000000..25c5009 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/ft2/ftsmooth.c @@ -0,0 +1,219 @@ +/***************************************************************************/ +/* */ +/* ftsmooth.c */ +/* */ +/* Anti-aliasing renderer interface (body). */ +/* */ +/* Copyright 2000 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#include "ftobjs.h" +#include "ftoutln.h" + + +#ifdef FT_FLAT_COMPILE + +#include "ftsmooth.h" +#include "ftgrays.h" + +#else + +#include "ftsmooth.h" +#include "ftgrays.h" + +#endif + + +/* initialize renderer -- init its raster */ +static +FT_Error ft_smooth_init( FT_Renderer render ) { + FT_Library library = FT_MODULE_LIBRARY( render ); + + + render->clazz->raster_class->raster_reset( render->raster, + library->raster_pool, + library->raster_pool_size ); + + return 0; +} + + +/* sets render-specific mode */ +static +FT_Error ft_smooth_set_mode( FT_Renderer render, + FT_ULong mode_tag, + FT_Pointer data ) { + /* we simply pass it to the raster */ + return render->clazz->raster_class->raster_set_mode( render->raster, + mode_tag, + data ); +} + +/* transform a given glyph image */ +static +FT_Error ft_smooth_transform( FT_Renderer render, + FT_GlyphSlot slot, + FT_Matrix* matrix, + FT_Vector* delta ) { + FT_Error error = FT_Err_Ok; + + + if ( slot->format != render->glyph_format ) { + error = FT_Err_Invalid_Argument; + goto Exit; + } + + if ( matrix ) { + FT_Outline_Transform( &slot->outline, matrix ); + } + + if ( delta ) { + FT_Outline_Translate( &slot->outline, delta->x, delta->y ); + } + +Exit: + return error; +} + + +/* return the glyph's control box */ +static +void ft_smooth_get_cbox( FT_Renderer render, + FT_GlyphSlot slot, + FT_BBox* cbox ) { + MEM_Set( cbox, 0, sizeof( *cbox ) ); + + if ( slot->format == render->glyph_format ) { + FT_Outline_Get_CBox( &slot->outline, cbox ); + } +} + + +/* convert a slot's glyph image into a bitmap */ +static +FT_Error ft_smooth_render( FT_Renderer render, + FT_GlyphSlot slot, + FT_UInt mode, + FT_Vector* origin ) { + FT_Error error; + FT_Outline* outline; + FT_BBox cbox; + FT_UInt width, height, pitch; + FT_Bitmap* bitmap; + FT_Memory memory; + + FT_Raster_Params params; + + + /* check glyph image format */ + if ( slot->format != render->glyph_format ) { + error = FT_Err_Invalid_Argument; + goto Exit; + } + + /* check mode */ + if ( mode != ft_render_mode_normal ) { + return FT_Err_Cannot_Render_Glyph; + } + + outline = &slot->outline; + + /* translate the outline to the new origin if needed */ + if ( origin ) { + FT_Outline_Translate( outline, origin->x, origin->y ); + } + + /* compute the control box, and grid fit it */ + FT_Outline_Get_CBox( outline, &cbox ); + + cbox.xMin &= -64; + cbox.yMin &= -64; + cbox.xMax = ( cbox.xMax + 63 ) & - 64; + cbox.yMax = ( cbox.yMax + 63 ) & - 64; + + width = ( cbox.xMax - cbox.xMin ) >> 6; + height = ( cbox.yMax - cbox.yMin ) >> 6; + bitmap = &slot->bitmap; + memory = render->root.memory; + + /* release old bitmap buffer */ + if ( slot->flags & ft_glyph_own_bitmap ) { + FREE( bitmap->buffer ); + slot->flags &= ~ft_glyph_own_bitmap; + } + + /* allocate new one, depends on pixel format */ + pitch = width; + bitmap->pixel_mode = ft_pixel_mode_grays; + bitmap->num_grays = 256; + bitmap->width = width; + bitmap->rows = height; + bitmap->pitch = pitch; + + if ( ALLOC( bitmap->buffer, (FT_ULong)pitch * height ) ) { + goto Exit; + } + + slot->flags |= ft_glyph_own_bitmap; + + /* translate outline to render it into the bitmap */ + FT_Outline_Translate( outline, -cbox.xMin, -cbox.yMin ); + + /* set up parameters */ + params.target = bitmap; + params.source = outline; + params.flags = ft_raster_flag_aa; + + /* render outline into the bitmap */ + error = render->raster_render( render->raster, ¶ms ); + if ( error ) { + goto Exit; + } + + slot->format = ft_glyph_format_bitmap; + slot->bitmap_left = cbox.xMin >> 6; + slot->bitmap_top = cbox.yMax >> 6; + +Exit: + return error; +} + + +const FT_Renderer_Class ft_smooth_renderer_class = +{ + { + ft_module_renderer, + sizeof( FT_RendererRec ), + + "smooth", + 0x10000L, + 0x20000L, + + 0, /* module specific interface */ + + (FT_Module_Constructor)ft_smooth_init, + (FT_Module_Destructor) 0, + (FT_Module_Requester) 0 + }, + + ft_glyph_format_outline, + + (FTRenderer_render) ft_smooth_render, + (FTRenderer_transform)ft_smooth_transform, + (FTRenderer_getCBox) ft_smooth_get_cbox, + (FTRenderer_setMode) ft_smooth_set_mode, + + (FT_Raster_Funcs*) &ft_grays_raster +}; + + +/* END */ diff --git a/Projects/Android/jni/rtcw/src/ft2/ftsmooth.h b/Projects/Android/jni/rtcw/src/ft2/ftsmooth.h new file mode 100644 index 0000000..8da0594 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/ft2/ftsmooth.h @@ -0,0 +1,35 @@ +/***************************************************************************/ +/* */ +/* ftsmooth.h */ +/* */ +/* Anti-aliasing renderer interface (specification). */ +/* */ +/* Copyright 1996-2000 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef FTSMOOTH_H +#define FTSMOOTH_H + +#include "ftrender.h" + +#ifndef FT_CONFIG_OPTION_NO_STD_RASTER +FT_EXPORT_VAR( const FT_Renderer_Class ) ft_std_renderer_class; +#endif + +#ifndef FT_CONFIG_OPTION_NO_SMOOTH_RASTER +FT_EXPORT_VAR( const FT_Renderer_Class ) ft_smooth_renderer_class; +#endif + +#endif /* FTSMOOTH_H */ + + +/* END */ diff --git a/Projects/Android/jni/rtcw/src/ft2/ftstream.c b/Projects/Android/jni/rtcw/src/ft2/ftstream.c new file mode 100644 index 0000000..1e5468a --- /dev/null +++ b/Projects/Android/jni/rtcw/src/ft2/ftstream.c @@ -0,0 +1,807 @@ +/***************************************************************************/ +/* */ +/* ftstream.c */ +/* */ +/* I/O stream support (body). */ +/* */ +/* Copyright 2000 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#include "ftstream.h" +#include "ftdebug.h" + + +/*************************************************************************/ +/* */ +/* The macro FT_COMPONENT is used in trace mode. It is an implicit */ +/* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */ +/* messages during execution. */ +/* */ +#undef FT_COMPONENT +#define FT_COMPONENT trace_stream + + +BASE_FUNC( void ) FT_New_Memory_Stream( FT_Library library, + FT_Byte * base, + FT_ULong size, + FT_Stream stream ) +{ + stream->memory = library->memory; + stream->base = base; + stream->size = size; + stream->pos = 0; + stream->cursor = 0; + stream->read = 0; + stream->close = 0; +} + + +BASE_FUNC( FT_Error ) FT_Seek_Stream( FT_Stream stream, + FT_ULong pos ) +{ + FT_Error error; + + + stream->pos = pos; + + if ( stream->read ) { + if ( stream->read( stream, pos, 0, 0 ) ) { + FT_ERROR( ( "FT_Seek_Stream:" ) ); + FT_ERROR( ( " invalid i/o; pos = 0x%lx, size = 0x%lx\n", + pos, stream->size ) ); + + error = FT_Err_Invalid_Stream_Operation; + } else { + error = FT_Err_Ok; + } + } + /* note that seeking to the first position after the file is valid */ + else if ( pos > stream->size ) { + FT_ERROR( ( "FT_Seek_Stream:" ) ); + FT_ERROR( ( " invalid i/o; pos = 0x%lx, size = 0x%lx\n", + pos, stream->size ) ); + + error = FT_Err_Invalid_Stream_Operation; + } else { + error = FT_Err_Ok; + } + + return error; +} + + +BASE_FUNC( FT_Error ) FT_Skip_Stream( FT_Stream stream, + FT_Long distance ) +{ + return FT_Seek_Stream( stream, (FT_ULong)( stream->pos + distance ) ); +} + + +BASE_FUNC( FT_Long ) FT_Stream_Pos( FT_Stream stream ) +{ + return stream->pos; +} + + +BASE_FUNC( FT_Error ) FT_Read_Stream( FT_Stream stream, + FT_Byte * buffer, + FT_ULong count ) +{ + return FT_Read_Stream_At( stream, stream->pos, buffer, count ); +} + + +BASE_FUNC( FT_Error ) FT_Read_Stream_At( FT_Stream stream, + FT_ULong pos, + FT_Byte * buffer, + FT_ULong count ) +{ + FT_Error error = FT_Err_Ok; + FT_ULong read_bytes; + + + if ( pos >= stream->size ) { + FT_ERROR( ( "FT_Read_Stream_At:" ) ); + FT_ERROR( ( " invalid i/o; pos = 0x%lx, size = 0x%lx\n", + pos, stream->size ) ); + + return FT_Err_Invalid_Stream_Operation; + } + + if ( stream->read ) { + read_bytes = stream->read( stream, pos, buffer, count ); + } else + { + read_bytes = stream->size - pos; + if ( read_bytes > count ) { + read_bytes = count; + } + + MEM_Copy( buffer, stream->base + pos, read_bytes ); + } + + stream->pos = pos + read_bytes; + + if ( read_bytes < count ) { + FT_ERROR( ( "FT_Read_Stream_At:" ) ); + FT_ERROR( ( " invalid read; expected %lu bytes, got %lu\n", + count, read_bytes ) ); + + error = FT_Err_Invalid_Stream_Operation; + } + + return error; +} + + +BASE_FUNC( FT_Error ) FT_Extract_Frame( FT_Stream stream, + FT_ULong count, + FT_Byte * *pbytes ) +{ + FT_Error error; + + + error = FT_Access_Frame( stream, count ); + if ( !error ) { + *pbytes = (FT_Byte*)stream->cursor; + + /* equivalent to FT_Forget_Frame(), with no memory block release */ + stream->cursor = 0; + stream->limit = 0; + } + + return error; +} + + +BASE_FUNC( void ) FT_Release_Frame( FT_Stream stream, + FT_Byte * *pbytes ) +{ + if ( stream->read ) { + FT_Memory memory = stream->memory; + + + FREE( *pbytes ); + } + *pbytes = 0; +} + + +BASE_FUNC( FT_Error ) FT_Access_Frame( FT_Stream stream, + FT_ULong count ) +{ + FT_Error error = FT_Err_Ok; + FT_ULong read_bytes; + + + /* check for nested frame access */ + FT_Assert( stream && stream->cursor == 0 ); + + if ( stream->read ) { + /* allocate the frame in memory */ + FT_Memory memory = stream->memory; + + + if ( ALLOC( stream->base, count ) ) { + goto Exit; + } + + /* read it */ + read_bytes = stream->read( stream, stream->pos, + stream->base, count ); + if ( read_bytes < count ) { + FT_ERROR( ( "FT_Access_Frame:" ) ); + FT_ERROR( ( " invalid read; expected %lu bytes, got %lu\n", + count, read_bytes ) ); + + FREE( stream->base ); + error = FT_Err_Invalid_Stream_Operation; + } + stream->cursor = stream->base; + stream->limit = stream->cursor + count; + stream->pos += read_bytes; + } else + { + /* check current and new position */ + if ( stream->pos >= stream->size || + stream->pos + count > stream->size ) { + FT_ERROR( ( "FT_Access_Frame:" ) ); + FT_ERROR( ( " invalid i/o; pos = 0x%lx, count = %lu, size = 0x%lx\n", + stream->pos, count, stream->size ) ); + + error = FT_Err_Invalid_Stream_Operation; + goto Exit; + } + + /* set cursor */ + stream->cursor = stream->base + stream->pos; + stream->limit = stream->cursor + count; + stream->pos += count; + } + +Exit: + return error; +} + + +BASE_FUNC( void ) FT_Forget_Frame( FT_Stream stream ) +{ + /* IMPORTANT: The assertion stream->cursor != 0 was removed, given */ + /* that it is possible to access a frame of length 0 in */ + /* some weird fonts (usually, when accessing an array of */ + /* 0 records, like in some strange kern tables). */ + /* */ + /* In this case, the loader code handles the 0-length table */ + /* gracefully; however, stream.cursor is really set to 0 by the */ + /* FT_Access_Frame() call, and this is not an error. */ + /* */ + FT_Assert( stream ); + + if ( stream->read ) { + FT_Memory memory = stream->memory; + + + FREE( stream->base ); + } + stream->cursor = 0; + stream->limit = 0; +} + + +BASE_FUNC( FT_Char ) FT_Get_Char( FT_Stream stream ) +{ + FT_Char result; + + + FT_Assert( stream && stream->cursor ); + + result = 0; + if ( stream->cursor < stream->limit ) { + result = *stream->cursor++; + } + + return result; +} + + +BASE_FUNC( FT_Short ) FT_Get_Short( FT_Stream stream ) +{ + FT_Byte* p; + FT_Short result; + + + FT_Assert( stream && stream->cursor ); + + result = 0; + p = stream->cursor; + if ( p + 1 < stream->limit ) { + result = NEXT_Short( p ); + } + stream->cursor = p; + + return result; +} + + +BASE_FUNC( FT_Short ) FT_Get_ShortLE( FT_Stream stream ) +{ + FT_Byte* p; + FT_Short result; + + + FT_Assert( stream && stream->cursor ); + + result = 0; + p = stream->cursor; + if ( p + 1 < stream->limit ) { + result = NEXT_ShortLE( p ); + } + stream->cursor = p; + + return result; +} + + +BASE_FUNC( FT_Long ) FT_Get_Offset( FT_Stream stream ) +{ + FT_Byte* p; + FT_Long result; + + + FT_Assert( stream && stream->cursor ); + + result = 0; + p = stream->cursor; + if ( p + 2 < stream->limit ) { + result = NEXT_Offset( p ); + } + stream->cursor = p; + return result; +} + + +BASE_FUNC( FT_Long ) FT_Get_Long( FT_Stream stream ) +{ + FT_Byte* p; + FT_Long result; + + + FT_Assert( stream && stream->cursor ); + + result = 0; + p = stream->cursor; + if ( p + 3 < stream->limit ) { + result = NEXT_Long( p ); + } + stream->cursor = p; + return result; +} + + +BASE_FUNC( FT_Long ) FT_Get_LongLE( FT_Stream stream ) +{ + FT_Byte* p; + FT_Long result; + + + FT_Assert( stream && stream->cursor ); + + result = 0; + p = stream->cursor; + if ( p + 3 < stream->limit ) { + result = NEXT_LongLE( p ); + } + stream->cursor = p; + return result; +} + + +BASE_FUNC( FT_Char ) FT_Read_Char( FT_Stream stream, + FT_Error * error ) +{ + FT_Byte result = 0; + + + FT_Assert( stream ); + + *error = FT_Err_Ok; + + if ( stream->read ) { + if ( stream->read( stream, stream->pos, &result, 1L ) != 1L ) { + goto Fail; + } + } else + { + if ( stream->pos < stream->size ) { + result = stream->base[stream->pos]; + } else { + goto Fail; + } + } + stream->pos++; + + return result; + +Fail: + *error = FT_Err_Invalid_Stream_Operation; + FT_ERROR( ( "FT_Read_Char:" ) ); + FT_ERROR( ( " invalid i/o; pos = 0x%lx, size = 0x%lx\n", + stream->pos, stream->size ) ); + + return 0; +} + + +BASE_FUNC( FT_Short ) FT_Read_Short( FT_Stream stream, + FT_Error * error ) +{ + FT_Byte reads[2]; + FT_Byte* p = 0; + FT_Short result = 0; + + + FT_Assert( stream ); + + *error = FT_Err_Ok; + + if ( stream->pos + 1 < stream->size ) { + if ( stream->read ) { + if ( stream->read( stream, stream->pos, reads, 2L ) != 2L ) { + goto Fail; + } + + p = reads; + } else + { + p = stream->base + stream->pos; + } + + if ( p ) { + result = NEXT_Short( p ); + } + } else { + goto Fail; + } + + stream->pos += 2; + + return result; + +Fail: + *error = FT_Err_Invalid_Stream_Operation; + FT_ERROR( ( "FT_Read_Short:" ) ); + FT_ERROR( ( " invalid i/o; pos = 0x%lx, size = 0x%lx\n", + stream->pos, stream->size ) ); + + return 0; +} + + +BASE_FUNC( FT_Short ) FT_Read_ShortLE( FT_Stream stream, + FT_Error * error ) +{ + FT_Byte reads[2]; + FT_Byte* p = 0; + FT_Short result = 0; + + + FT_Assert( stream ); + + *error = FT_Err_Ok; + + if ( stream->pos + 1 < stream->size ) { + if ( stream->read ) { + if ( stream->read( stream, stream->pos, reads, 2L ) != 2L ) { + goto Fail; + } + + p = reads; + } else + { + p = stream->base + stream->pos; + } + + if ( p ) { + result = NEXT_ShortLE( p ); + } + } else { + goto Fail; + } + + stream->pos += 2; + + return result; + +Fail: + *error = FT_Err_Invalid_Stream_Operation; + FT_ERROR( ( "FT_Read_Short:" ) ); + FT_ERROR( ( " invalid i/o; pos = 0x%lx, size = 0x%lx\n", + stream->pos, stream->size ) ); + + return 0; +} + + +BASE_FUNC( FT_Long ) FT_Read_Offset( FT_Stream stream, + FT_Error * error ) +{ + FT_Byte reads[3]; + FT_Byte* p = 0; + FT_Long result = 0; + + + FT_Assert( stream ); + + *error = FT_Err_Ok; + + if ( stream->pos + 2 < stream->size ) { + if ( stream->read ) { + if ( stream->read( stream, stream->pos, reads, 3L ) != 3L ) { + goto Fail; + } + + p = reads; + } else + { + p = stream->base + stream->pos; + } + + if ( p ) { + result = NEXT_Offset( p ); + } + } else { + goto Fail; + } + + stream->pos += 3; + + return result; + +Fail: + *error = FT_Err_Invalid_Stream_Operation; + FT_ERROR( ( "FT_Read_Offset:" ) ); + FT_ERROR( ( " invalid i/o; pos = 0x%lx, size = 0x%lx\n", + stream->pos, stream->size ) ); + + return 0; +} + + +BASE_FUNC( FT_Long ) FT_Read_Long( FT_Stream stream, + FT_Error * error ) +{ + FT_Byte reads[4]; + FT_Byte* p = 0; + FT_Long result = 0; + + + FT_Assert( stream ); + + *error = FT_Err_Ok; + + if ( stream->pos + 3 < stream->size ) { + if ( stream->read ) { + if ( stream->read( stream, stream->pos, reads, 4L ) != 4L ) { + goto Fail; + } + + p = reads; + } else + { + p = stream->base + stream->pos; + } + + if ( p ) { + result = NEXT_Long( p ); + } + } else { + goto Fail; + } + + stream->pos += 4; + + return result; + +Fail: + FT_ERROR( ( "FT_Read_Long:" ) ); + FT_ERROR( ( " invalid i/o; pos = 0x%lx, size = 0x%lx\n", + stream->pos, stream->size ) ); + *error = FT_Err_Invalid_Stream_Operation; + + return 0; +} + + +BASE_FUNC( FT_Long ) FT_Read_LongLE( FT_Stream stream, + FT_Error * error ) +{ + FT_Byte reads[4]; + FT_Byte* p = 0; + FT_Long result = 0; + + + FT_Assert( stream ); + + *error = FT_Err_Ok; + + if ( stream->pos + 3 < stream->size ) { + if ( stream->read ) { + if ( stream->read( stream, stream->pos, reads, 4L ) != 4L ) { + goto Fail; + } + + p = reads; + } else + { + p = stream->base + stream->pos; + } + + if ( p ) { + result = NEXT_LongLE( p ); + } + } else { + goto Fail; + } + + stream->pos += 4; + + return result; + +Fail: + FT_ERROR( ( "FT_Read_Long:" ) ); + FT_ERROR( ( " invalid i/o; pos = 0x%lx, size = 0x%lx\n", + stream->pos, stream->size ) ); + *error = FT_Err_Invalid_Stream_Operation; + + return 0; +} + + +BASE_FUNC( FT_Error ) FT_Read_Fields( FT_Stream stream, + const FT_Frame_Field * fields, + void* structure ) +{ + FT_Error error; + FT_Bool frame_accessed = 0; + + + if ( !fields || !stream ) { + return FT_Err_Invalid_Argument; + } + + error = FT_Err_Ok; + do + { + FT_ULong value; + FT_Int sign_shift; + FT_Byte* p; + + + switch ( fields->value ) + { + case ft_frame_start: /* access a new frame */ + error = FT_Access_Frame( stream, fields->offset ); + if ( error ) { + goto Exit; + } + + frame_accessed = 1; + fields++; + continue; /* loop! */ + + case ft_frame_bytes: /* read a byte sequence */ + case ft_frame_skip: /* skip some bytes */ + { + FT_Int len = fields->size; + + + if ( stream->cursor + len > stream->limit ) { + error = FT_Err_Invalid_Stream_Operation; + goto Exit; + } + + if ( fields->value == ft_frame_bytes ) { + p = (FT_Byte*)structure + fields->offset; + MEM_Copy( p, stream->cursor, len ); + } + stream->cursor += len; + fields++; + continue; + } + + case ft_frame_byte: + case ft_frame_schar: /* read a single byte */ + value = GET_Byte(); + sign_shift = 24; + break; + + case ft_frame_short_be: + case ft_frame_ushort_be: /* read a 2-byte big-endian short */ + value = GET_UShort(); + sign_shift = 16; + break; + + case ft_frame_short_le: + case ft_frame_ushort_le: /* read a 2-byte little-endian short */ + { + FT_Byte* p; + + + value = 0; + p = stream->cursor; + + if ( p + 1 < stream->limit ) { + value = ( FT_UShort)p[0] | ( (FT_UShort)p[1] << 8 ); + stream->cursor += 2; + } + sign_shift = 16; + break; + } + + case ft_frame_long_be: + case ft_frame_ulong_be: /* read a 4-byte big-endian long */ + value = GET_ULong(); + sign_shift = 0; + break; + + case ft_frame_long_le: + case ft_frame_ulong_le: /* read a 4-byte little-endian long */ + { + FT_Byte* p; + + + value = 0; + p = stream->cursor; + + if ( p + 3 < stream->limit ) { + value = (FT_ULong)p[0] | + ( (FT_ULong)p[1] << 8 ) | + ( (FT_ULong)p[2] << 16 ) | + ( (FT_ULong)p[3] << 24 ); + stream->cursor += 4; + } + sign_shift = 0; + break; + } + + case ft_frame_off3_be: + case ft_frame_uoff3_be: /* read a 3-byte big-endian long */ + value = GET_UOffset(); + sign_shift = 8; + break; + + case ft_frame_off3_le: + case ft_frame_uoff3_le: /* read a 3-byte little-endian long */ + { + FT_Byte* p; + + + value = 0; + p = stream->cursor; + + if ( p + 2 < stream->limit ) { + value = (FT_ULong)p[0] | + ( (FT_ULong)p[1] << 8 ) | + ( (FT_ULong)p[2] << 16 ); + stream->cursor += 3; + } + sign_shift = 8; + break; + } + + default: + /* otherwise, exit the loop */ + goto Exit; + } + + /* now, compute the signed value is necessary */ + if ( fields->value & FT_FRAME_OP_SIGNED ) { + value = (FT_ULong)( (FT_Int32)( value << sign_shift ) >> sign_shift ); + } + + /* finally, store the value in the object */ + + p = (FT_Byte*)structure + fields->offset; + switch ( fields->size ) + { + case 1: + *(FT_Byte*)p = (FT_Byte)value; + break; + + case 2: + *(FT_UShort*)p = (FT_UShort)value; + break; + + case 4: + *(FT_UInt32*)p = (FT_UInt32)value; + break; + + default: /* for 64-bit systems */ + *(FT_ULong*)p = (FT_ULong)value; + } + + /* go to next field */ + fields++; + } + while ( 1 ); + +Exit: + /* close the frame if it was opened by this read */ + if ( frame_accessed ) { + FT_Forget_Frame( stream ); + } + + return error; +} + + +/* END */ diff --git a/Projects/Android/jni/rtcw/src/ft2/ftstream.h b/Projects/Android/jni/rtcw/src/ft2/ftstream.h new file mode 100644 index 0000000..45cf2f1 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/ft2/ftstream.h @@ -0,0 +1,361 @@ +/***************************************************************************/ +/* */ +/* ftstream.h */ +/* */ +/* Stream handling(specification). */ +/* */ +/* Copyright 1996-2000 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef FTSTREAM_H +#define FTSTREAM_H + +#include "ftobjs.h" + + +#ifdef __cplusplus +extern "C" { +#endif + + +/* format of an 8-bit frame_op value = [ xxxxx | e | s ] */ +/* s is set to 1 if the value is signed, */ +/* e is set to 1 if the value is little-endian */ +/* xxxxx is a command */ + +#define FT_FRAME_OP_SHIFT 2 +#define FT_FRAME_OP_SIGNED 1 +#define FT_FRAME_OP_LITTLE 2 +#define FT_FRAME_OP_COMMAND( x ) ( x >> FT_FRAME_OP_SHIFT ) + +#define FT_MAKE_FRAME_OP( command, little, sign ) \ + ( ( command << FT_FRAME_OP_SHIFT ) | ( little << 1 ) | sign ) + +#define FT_FRAME_OP_END 0 +#define FT_FRAME_OP_START 1 /* start a new frame */ +#define FT_FRAME_OP_BYTE 2 /* read 1-byte value */ +#define FT_FRAME_OP_SHORT 3 /* read 2-byte value */ +#define FT_FRAME_OP_LONG 4 /* read 4-byte value */ +#define FT_FRAME_OP_OFF3 5 /* read 3-byte value */ +#define FT_FRAME_OP_BYTES 6 /* read a bytes sequence */ + + +typedef enum FT_Frame_Op_ +{ + ft_frame_end = 0, + ft_frame_start = FT_MAKE_FRAME_OP( FT_FRAME_OP_START, 0, 0 ), + + ft_frame_byte = FT_MAKE_FRAME_OP( FT_FRAME_OP_BYTE, 0, 0 ), + ft_frame_schar = FT_MAKE_FRAME_OP( FT_FRAME_OP_BYTE, 0, 1 ), + + ft_frame_ushort_be = FT_MAKE_FRAME_OP( FT_FRAME_OP_SHORT, 0, 0 ), + ft_frame_short_be = FT_MAKE_FRAME_OP( FT_FRAME_OP_SHORT, 0, 1 ), + ft_frame_ushort_le = FT_MAKE_FRAME_OP( FT_FRAME_OP_SHORT, 1, 0 ), + ft_frame_short_le = FT_MAKE_FRAME_OP( FT_FRAME_OP_SHORT, 1, 1 ), + + ft_frame_ulong_be = FT_MAKE_FRAME_OP( FT_FRAME_OP_LONG, 0, 0 ), + ft_frame_ulong_le = FT_MAKE_FRAME_OP( FT_FRAME_OP_LONG, 0, 1 ), + ft_frame_long_be = FT_MAKE_FRAME_OP( FT_FRAME_OP_LONG, 1, 0 ), + ft_frame_long_le = FT_MAKE_FRAME_OP( FT_FRAME_OP_LONG, 1, 1 ), + + ft_frame_uoff3_be = FT_MAKE_FRAME_OP( FT_FRAME_OP_OFF3, 0, 0 ), + ft_frame_uoff3_le = FT_MAKE_FRAME_OP( FT_FRAME_OP_OFF3, 0, 1 ), + ft_frame_off3_be = FT_MAKE_FRAME_OP( FT_FRAME_OP_OFF3, 1, 0 ), + ft_frame_off3_le = FT_MAKE_FRAME_OP( FT_FRAME_OP_OFF3, 1, 1 ), + + ft_frame_bytes = FT_MAKE_FRAME_OP( FT_FRAME_OP_BYTES, 0, 0 ), + ft_frame_skip = FT_MAKE_FRAME_OP( FT_FRAME_OP_BYTES, 0, 1 ) + +} FT_Frame_Op; + + +typedef struct FT_Frame_Field_ +{ + FT_Frame_Op value; + char size; + FT_UShort offset; + +} FT_Frame_Field; + + +/* make-up a FT_Frame_Field out of a structure type and a field name */ +#define FT_FIELD_REF( s, f ) ( ( (s*)0 )->f ) + +#define FT_FRAME_FIELD( frame_op, struct_type, field ) \ + { \ + frame_op, \ + sizeof( FT_FIELD_REF( struct_type,field ) ), \ + (FT_UShort)(char*)&FT_FIELD_REF( struct_type, field ) \ + } + +#define FT_MAKE_EMPTY_FIELD( frame_op ) { frame_op, 0, 0 } + +#define FT_FRAME_START( s ) { ft_frame_start, 0, s } +#define FT_FRAME_END { ft_frame_end, 0, 0 } + +#define FT_FRAME_LONG( s, f ) FT_FRAME_FIELD( ft_frame_long_be, s, f ) +#define FT_FRAME_ULONG( s, f ) FT_FRAME_FIELD( ft_frame_ulong_be, s, f ) +#define FT_FRAME_SHORT( s, f ) FT_FRAME_FIELD( ft_frame_short_be, s, f ) +#define FT_FRAME_USHORT( s, f ) FT_FRAME_FIELD( ft_frame_ushort_be, s, f ) +#define FT_FRAME_BYTE( s, f ) FT_FRAME_FIELD( ft_frame_byte, s, f ) +#define FT_FRAME_CHAR( s, f ) FT_FRAME_FIELD( ft_frame_schar, s, f ) + +#define FT_FRAME_LONG_LE( s, f ) FT_FRAME_FIELD( ft_frame_long_le, s, f ) +#define FT_FRAME_ULONG_LE( s, f ) FT_FRAME_FIELD( ft_frame_ulong_le, s, f ) +#define FT_FRAME_SHORT_LE( s, f ) FT_FRAME_FIELD( ft_frame_short_le, s, f ) +#define FT_FRAME_USHORT_LE( s, f ) FT_FRAME_FIELD( ft_frame_ushort_le, s, f ) + +#define FT_FRAME_SKIP_LONG { ft_frame_long_be, 0, 0 } +#define FT_FRAME_SKIP_SHORT { ft_frame_short_be, 0, 0 } +#define FT_FRAME_SKIP_BYTE { ft_frame_byte, 0, 0 } + +#define FT_FRAME_BYTES( struct_type, field, count ) \ + { \ + ft_frame_bytes, \ + count, \ + (FT_UShort)(char*)&FT_FIELD_REF( struct_type, field ) \ + } +#define FT_FRAME_SKIP_BYTES( count ) { ft_frame_skip, count, 0 } + + + +/*************************************************************************/ +/* */ +/* integer extraction macros -- the `buffer' parameter must ALWAYS be of */ +/* type `char*' or equivalent (1-byte elements). */ +/* */ +#define NEXT_Char( buffer ) \ + ( (signed char)*buffer++ ) +#define NEXT_Byte( buffer ) \ + ( (unsigned char)*buffer++ ) + +#define NEXT_Short( buffer ) \ + ( buffer += 2, \ + ( (short)( (signed char)buffer[-2] << 8 ) | \ + (unsigned char)buffer[-1] ) ) + +#define NEXT_UShort( buffer ) \ + ( (unsigned short)NEXT_Short( buffer ) ) + +#define NEXT_Offset( buffer ) \ + ( buffer += 3, \ + ( ( (long)(signed char)buffer[-3] << 16 ) | \ + ( (long)(unsigned char)buffer[-2] << 8 ) | \ + (long)(unsigned char)buffer[-1] ) ) + +#define NEXT_UOffset( buffer ) \ + ( (unsigned long)NEXT_Offset( buffer ) ) + +#define NEXT_Long( buffer ) \ + ( buffer += 4, \ + ( ( (long)(signed char)buffer[-4] << 24 ) | \ + ( (long)(unsigned char)buffer[-3] << 16 ) | \ + ( (long)(unsigned char)buffer[-2] << 8 ) | \ + (long)(unsigned char)buffer[-1] ) ) + +#define NEXT_ULong( buffer ) \ + ( (unsigned long)NEXT_Long( buffer ) ) + + +#define NEXT_ShortLE( buffer ) \ + ( buffer += 2, \ + ( (short)( (signed char)buffer[-1] << 8 ) | \ + (unsigned char)buffer[-2] ) ) + +#define NEXT_UShortLE( buffer ) \ + ( (unsigned short)NEXT_ShortLE( buffer ) ) + +#define NEXT_OffsetLE( buffer ) \ + ( buffer += 3, \ + ( ( (long)(signed char)buffer[-1] << 16 ) | \ + ( (long)(unsigned char)buffer[-2] << 8 ) | \ + (long)(unsigned char)buffer[-3] ) ) + +#define NEXT_UOffsetLE( buffer ) \ + ( (unsigned long)NEXT_OffsetLE( buffer ) ) + + +#define NEXT_LongLE( buffer ) \ + ( buffer += 4, \ + ( ( (long)(signed char)buffer[-1] << 24 ) | \ + ( (long)(unsigned char)buffer[-2] << 16 ) | \ + ( (long)(unsigned char)buffer[-3] << 8 ) | \ + (long)(unsigned char)buffer[-4] ) ) + +#define NEXT_ULongLE( buffer ) \ + ( (unsigned long)NEXT_LongLE( buffer ) ) + + +/*************************************************************************/ +/* */ +/* Each GET_xxxx() macro uses an implicit `stream' variable. */ +/* */ +#define FT_GET_MACRO( func, type ) ( (type)func( stream ) ) + +#define GET_Char() FT_GET_MACRO( FT_Get_Char, FT_Char ) +#define GET_Byte() FT_GET_MACRO( FT_Get_Char, FT_Byte ) +#define GET_Short() FT_GET_MACRO( FT_Get_Short, FT_Short ) +#define GET_UShort() FT_GET_MACRO( FT_Get_Short, FT_UShort ) +#define GET_Offset() FT_GET_MACRO( FT_Get_Offset, FT_Long ) +#define GET_UOffset() FT_GET_MACRO( FT_Get_Offset, FT_ULong ) +#define GET_Long() FT_GET_MACRO( FT_Get_Long, FT_Long ) +#define GET_ULong() FT_GET_MACRO( FT_Get_Long, FT_ULong ) +#define GET_Tag4() FT_GET_MACRO( FT_Get_Long, FT_ULong ) + +#define GET_ShortLE() FT_GET_MACRO( FT_Get_ShortLE, FT_Short ) +#define GET_UShortLE() FT_GET_MACRO( FT_Get_ShortLE, FT_UShort ) +#define GET_LongLE() FT_GET_MACRO( FT_Get_LongLE, FT_Short ) +#define GET_ULongLE() FT_GET_MACRO( FT_Get_LongLE, FT_Short ) + +#define FT_READ_MACRO( func, type, var ) \ + ( var = (type)func( stream, &error ), \ + error != FT_Err_Ok ) + +#define READ_Byte( var ) FT_READ_MACRO( FT_Read_Char, FT_Byte, var ) +#define READ_Char( var ) FT_READ_MACRO( FT_Read_Char, FT_Char, var ) +#define READ_Short( var ) FT_READ_MACRO( FT_Read_Short, FT_Short, var ) +#define READ_UShort( var ) FT_READ_MACRO( FT_Read_Short, FT_UShort, var ) +#define READ_Offset( var ) FT_READ_MACRO( FT_Read_Offset, FT_Long, var ) +#define READ_UOffset( var ) FT_READ_MACRO( FT_Read_Offset, FT_ULong, var ) +#define READ_Long( var ) FT_READ_MACRO( FT_Read_Long, FT_Long, var ) +#define READ_ULong( var ) FT_READ_MACRO( FT_Read_Long, FT_ULong, var ) + +#define READ_ShortLE( var ) FT_READ_MACRO( FT_Read_ShortLE, FT_Short, var ) +#define READ_UShortLE( var ) FT_READ_MACRO( FT_Read_ShortLE, FT_UShort, var ) +#define READ_LongLE( var ) FT_READ_MACRO( FT_Read_LongLE, FT_Long, var ) +#define READ_ULongLE( var ) FT_READ_MACRO( FT_Read_LongLE, FT_ULong, var ) + + +BASE_DEF( void ) FT_New_Memory_Stream( FT_Library library, + FT_Byte * base, + FT_ULong size, + FT_Stream stream ); + +BASE_DEF( FT_Error ) FT_Seek_Stream( FT_Stream stream, + FT_ULong pos ); + +BASE_DEF( FT_Error ) FT_Skip_Stream( FT_Stream stream, + FT_Long distance ); + +BASE_DEF( FT_Long ) FT_Stream_Pos( FT_Stream stream ); + + +BASE_DEF( FT_Error ) FT_Read_Stream( FT_Stream stream, + FT_Byte * buffer, + FT_ULong count ); + +BASE_DEF( FT_Error ) FT_Read_Stream_At( FT_Stream stream, + FT_ULong pos, + FT_Byte * buffer, + FT_ULong count ); + +BASE_DEF( FT_Error ) FT_Access_Frame( FT_Stream stream, + FT_ULong count ); + +BASE_DEF( void ) FT_Forget_Frame( FT_Stream stream ); + +BASE_DEF( FT_Error ) FT_Extract_Frame( FT_Stream stream, + FT_ULong count, + FT_Byte * *pbytes ); + +BASE_DEF( void ) FT_Release_Frame( FT_Stream stream, + FT_Byte * *pbytes ); + +BASE_DEF( FT_Char ) FT_Get_Char( FT_Stream stream ); + +BASE_DEF( FT_Short ) FT_Get_Short( FT_Stream stream ); + +BASE_DEF( FT_Long ) FT_Get_Offset( FT_Stream stream ); + +BASE_DEF( FT_Long ) FT_Get_Long( FT_Stream stream ); + +BASE_DEF( FT_Short ) FT_Get_ShortLE( FT_Stream stream ); + +BASE_DEF( FT_Long ) FT_Get_LongLE( FT_Stream stream ); + + +BASE_DEF( FT_Char ) FT_Read_Char( FT_Stream stream, + FT_Error * error ); + +BASE_DEF( FT_Short ) FT_Read_Short( FT_Stream stream, + FT_Error * error ); + +BASE_DEF( FT_Long ) FT_Read_Offset( FT_Stream stream, + FT_Error * error ); + +BASE_DEF( FT_Long ) FT_Read_Long( FT_Stream stream, + FT_Error * error ); + +BASE_DEF( FT_Short ) FT_Read_ShortLE( FT_Stream stream, + FT_Error * error ); + +BASE_DEF( FT_Long ) FT_Read_LongLE( FT_Stream stream, + FT_Error * error ); + +BASE_DEF( FT_Error ) FT_Read_Fields( FT_Stream stream, + const FT_Frame_Field * fields, + void* structure ); + + +#define USE_Stream( resource, stream ) \ + FT_SET_ERROR( FT_Open_Stream( resource, stream ) ) + +#define DONE_Stream( stream ) \ + FT_Done_Stream( stream ) + + +#define ACCESS_Frame( size ) \ + FT_SET_ERROR( FT_Access_Frame( stream, size ) ) + +#define FORGET_Frame() \ + FT_Forget_Frame( stream ) + +#define EXTRACT_Frame( size, bytes ) \ + FT_SET_ERROR( FT_Extract_Frame( stream, size, \ + (FT_Byte**)&( bytes ) ) ) + +#define RELEASE_Frame( bytes ) \ + FT_Release_Frame( stream, (FT_Byte**)&( bytes ) ) + +#define FILE_Seek( position ) \ + FT_SET_ERROR( FT_Seek_Stream( stream, position ) ) + +#define FILE_Skip( distance ) \ + FT_SET_ERROR( FT_Skip_Stream( stream, distance ) ) + +#define FILE_Pos() \ + FT_Stream_Pos( stream ) + +#define FILE_Read( buffer, count ) \ + FT_SET_ERROR( FT_Read_Stream( stream, \ + (FT_Byte*)buffer, \ + count ) ) + +#define FILE_Read_At( position, buffer, count ) \ + FT_SET_ERROR( FT_Read_Stream_At( stream, \ + position, \ + (FT_Byte*)buffer, \ + count ) ) + +#define READ_Fields( fields, object ) \ + ( ( error = FT_Read_Fields( stream, fields, object ) ) != FT_Err_Ok ) + + +#ifdef __cplusplus +} +#endif + + +#endif /* FTSTREAM_H */ + + +/* END */ diff --git a/Projects/Android/jni/rtcw/src/ft2/ftsystem.c b/Projects/Android/jni/rtcw/src/ft2/ftsystem.c new file mode 100644 index 0000000..46b75be --- /dev/null +++ b/Projects/Android/jni/rtcw/src/ft2/ftsystem.c @@ -0,0 +1,293 @@ +/***************************************************************************/ +/* */ +/* ftsystem.c */ +/* */ +/* ANSI-specific FreeType low-level system interface (body). */ +/* */ +/* Copyright 1996-2000 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + +/*************************************************************************/ +/* */ +/* This file contains the default interface used by FreeType to access */ +/* low-level, i.e. memory management, i/o access as well as thread */ +/* synchronisation. It can be replaced by user-specific routines if */ +/* necessary. */ +/* */ +/*************************************************************************/ + + +#include "ftconfig.h" +#include "ftdebug.h" +#include "ftsystem.h" +#include "fterrors.h" +#include "fttypes.h" + +#include +#include +#include + + +/*************************************************************************/ +/* */ +/* MEMORY MANAGEMENT INTERFACE */ +/* */ +/*************************************************************************/ + +/*************************************************************************/ +/* */ +/* It is not necessary to do any error checking for the */ +/* allocation-related functions. This will be done by the higher level */ +/* routines like FT_Alloc() or FT_Realloc(). */ +/* */ +/*************************************************************************/ + + +/*************************************************************************/ +/* */ +/* */ +/* ft_alloc */ +/* */ +/* */ +/* The memory allocation function. */ +/* */ +/* */ +/* memory :: A pointer to the memory object. */ +/* */ +/* size :: The requested size in bytes. */ +/* */ +/* */ +/* block :: The address of newly allocated block. */ +/* */ +static +void* ft_alloc( FT_Memory memory, + long size ) { + FT_UNUSED( memory ); + + return malloc( size ); +} + + +/*************************************************************************/ +/* */ +/* */ +/* ft_realloc */ +/* */ +/* */ +/* The memory reallocation function. */ +/* */ +/* */ +/* memory :: A pointer to the memory object. */ +/* */ +/* cur_size :: The current size of the allocated memory block. */ +/* */ +/* new_size :: The newly requested size in bytes. */ +/* */ +/* block :: The current address of the block in memory. */ +/* */ +/* */ +/* The address of the reallocated memory block. */ +/* */ +static +void* ft_realloc( FT_Memory memory, + long cur_size, + long new_size, + void* block ) { + FT_UNUSED( memory ); + FT_UNUSED( cur_size ); + + return realloc( block, new_size ); +} + + +/*************************************************************************/ +/* */ +/* */ +/* ft_free */ +/* */ +/* */ +/* The memory release function. */ +/* */ +/* */ +/* memory :: A pointer to the memory object. */ +/* */ +/* block :: The address of block in memory to be freed. */ +/* */ +static +void ft_free( FT_Memory memory, + void* block ) { + FT_UNUSED( memory ); + + free( block ); +} + + +/*************************************************************************/ +/* */ +/* RESOURCE MANAGEMENT INTERFACE */ +/* */ +/*************************************************************************/ + + +/*************************************************************************/ +/* */ +/* The macro FT_COMPONENT is used in trace mode. It is an implicit */ +/* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */ +/* messages during execution. */ +/* */ +#undef FT_COMPONENT +#define FT_COMPONENT trace_io + +/* We use the macro STREAM_FILE for convenience to extract the */ +/* system-specific stream handle from a given FreeType stream object */ +#define STREAM_FILE( stream ) ( (FILE*)stream->descriptor.pointer ) + + +/*************************************************************************/ +/* */ +/* */ +/* ft_close_stream */ +/* */ +/* */ +/* The function to close a stream. */ +/* */ +/* */ +/* stream :: A pointer to the stream object. */ +/* */ +static +void ft_close_stream( FT_Stream stream ) { + fclose( STREAM_FILE( stream ) ); + + stream->descriptor.pointer = NULL; + stream->size = 0; + stream->base = 0; +} + + +/*************************************************************************/ +/* */ +/* */ +/* ft_io_stream */ +/* */ +/* */ +/* The function to open a stream. */ +/* */ +/* */ +/* stream :: A pointer to the stream object. */ +/* */ +/* offset :: The position in the data stream to start reading. */ +/* */ +/* buffer :: The address of buffer to store the read data. */ +/* */ +/* count :: The number of bytes to read from the stream. */ +/* */ +/* */ +/* The number of bytes actually read. */ +/* */ +static +unsigned long ft_io_stream( FT_Stream stream, + unsigned long offset, + unsigned char* buffer, + unsigned long count ) { + FILE* file; + + + file = STREAM_FILE( stream ); + + fseek( file, offset, SEEK_SET ); + + return (unsigned long)fread( buffer, 1, count, file ); +} + + +/*************************************************************************/ +/* */ +/* */ +/* FT_New_Stream */ +/* */ +/* */ +/* Creates a new stream object. */ +/* */ +/* */ +/* filepathname :: The name of the stream (usually a file) to be */ +/* opened. */ +/* */ +/* stream :: A pointer to the stream object. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +FT_EXPORT_FUNC( FT_Error ) FT_New_Stream( const char* filepathname, + FT_Stream stream ) +{ + FILE* file; + + + if ( !stream ) { + return FT_Err_Invalid_Stream_Handle; + } + + file = fopen( filepathname, "rb" ); + if ( !file ) { + FT_ERROR( ( "FT_New_Stream:" ) ); + FT_ERROR( ( " could not open `%s'\n", filepathname ) ); + + return FT_Err_Cannot_Open_Resource; + } + + fseek( file, 0, SEEK_END ); + stream->size = ftell( file ); + fseek( file, 0, SEEK_SET ); + + stream->descriptor.pointer = file; + stream->pathname.pointer = (char*)filepathname; + stream->pos = 0; + + stream->read = ft_io_stream; + stream->close = ft_close_stream; + + FT_TRACE1( ( "FT_New_Stream:" ) ); + FT_TRACE1( ( " opened `%s' (%d bytes) successfully\n", + filepathname, stream->size ) ); + + return FT_Err_Ok; +} + + +/*************************************************************************/ +/* */ +/* */ +/* FT_New_Memory */ +/* */ +/* */ +/* Creates a new memory object. */ +/* */ +/* */ +/* A pointer to the new memory object. 0 in case of error. */ +/* */ +FT_EXPORT_FUNC( FT_Memory ) FT_New_Memory( void ) +{ + FT_Memory memory; + + + memory = (FT_Memory)malloc( sizeof( *memory ) ); + if ( memory ) { + memory->user = 0; + memory->alloc = ft_alloc; + memory->realloc = ft_realloc; + memory->free = ft_free; + } + + return memory; +} + + +/* END */ diff --git a/Projects/Android/jni/rtcw/src/ft2/ftsystem.h b/Projects/Android/jni/rtcw/src/ft2/ftsystem.h new file mode 100644 index 0000000..22931cb --- /dev/null +++ b/Projects/Android/jni/rtcw/src/ft2/ftsystem.h @@ -0,0 +1,101 @@ +/***************************************************************************/ +/* */ +/* ftsystem.h */ +/* */ +/* FreeType low-level system interface definition (specification). */ +/* */ +/* Copyright 1996-2000 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef FTSYSTEM_H +#define FTSYSTEM_H + + +/*************************************************************************/ +/* */ +/* M E M O R Y M A N A G E M E N T */ +/* */ +/*************************************************************************/ + + +typedef struct FT_MemoryRec_* FT_Memory; + + +typedef void* ( *FT_Alloc_Func )( FT_Memory memory, + long size ); + +typedef void ( *FT_Free_Func )( FT_Memory memory, + void* block ); + +typedef void* ( *FT_Realloc_Func )( FT_Memory memory, + long cur_size, + long new_size, + void* block ); + + +struct FT_MemoryRec_ +{ + void* user; + FT_Alloc_Func alloc; + FT_Free_Func free; + FT_Realloc_Func realloc; +}; + + +/*************************************************************************/ +/* */ +/* I / O M A N A G E M E N T */ +/* */ +/*************************************************************************/ + + +typedef union FT_StreamDesc_ +{ + long value; + void* pointer; + +} FT_StreamDesc; + + +typedef struct FT_StreamRec_* FT_Stream; + + +typedef unsigned long ( *FT_Stream_IO )( FT_Stream stream, + unsigned long offset, + unsigned char* buffer, + unsigned long count ); + +typedef void ( *FT_Stream_Close )( FT_Stream stream ); + + +struct FT_StreamRec_ +{ + unsigned char* base; + unsigned long size; + unsigned long pos; + + FT_StreamDesc descriptor; + FT_StreamDesc pathname; /* ignored by FreeType -- */ + /* useful for debugging */ + FT_Stream_IO read; + FT_Stream_Close close; + + FT_Memory memory; + unsigned char* cursor; + unsigned char* limit; +}; + + +#endif /* FTSYSTEM_H */ + + +/* END */ diff --git a/Projects/Android/jni/rtcw/src/ft2/fttypes.h b/Projects/Android/jni/rtcw/src/ft2/fttypes.h new file mode 100644 index 0000000..209ede0 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/ft2/fttypes.h @@ -0,0 +1,400 @@ +/***************************************************************************/ +/* */ +/* fttypes.h */ +/* */ +/* FreeType simple types definitions (specification only). */ +/* */ +/* Copyright 1996-2000 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef FTTYPES_H +#define FTTYPES_H + + +#include "ftsystem.h" +#include "ftimage.h" + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Bool */ +/* */ +/* */ +/* A typedef of unsigned char, used for simple booleans. */ +/* */ +typedef unsigned char FT_Bool; + + +/*************************************************************************/ +/* */ +/* */ +/* FT_FWord */ +/* */ +/* */ +/* A signed 16-bit integer used to store a distance in original font */ +/* units. */ +/* */ +typedef signed short FT_FWord; /* distance in FUnits */ + + +/*************************************************************************/ +/* */ +/* */ +/* FT_UFWord */ +/* */ +/* */ +/* An unsigned 16-bit integer used to store a distance in original */ +/* font units. */ +/* */ +typedef unsigned short FT_UFWord; /* unsigned distance */ + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Char */ +/* */ +/* */ +/* A simple typedef for the _signed_ char type. */ +/* */ +typedef signed char FT_Char; + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Byte */ +/* */ +/* */ +/* A simple typedef for the _unsigned_ char type. */ +/* */ +typedef unsigned char FT_Byte; + + +/*************************************************************************/ +/* */ +/* */ +/* FT_String */ +/* */ +/* */ +/* A simple typedef for the char type, usually used for strings. */ +/* */ +typedef char FT_String; + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Short */ +/* */ +/* */ +/* A typedef for signed short. */ +/* */ +typedef signed short FT_Short; + + +/*************************************************************************/ +/* */ +/* */ +/* FT_UShort */ +/* */ +/* */ +/* A typedef for unsigned short. */ +/* */ +typedef unsigned short FT_UShort; + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Int */ +/* */ +/* */ +/* A typedef for the int type. */ +/* */ +typedef int FT_Int; + + +/*************************************************************************/ +/* */ +/* */ +/* FT_UInt */ +/* */ +/* */ +/* A typedef for the unsigned int type. */ +/* */ +typedef unsigned int FT_UInt; + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Long */ +/* */ +/* */ +/* A typedef for signed long. */ +/* */ +typedef signed long FT_Long; + + +/*************************************************************************/ +/* */ +/* */ +/* FT_ULong */ +/* */ +/* */ +/* A typedef for unsigned long. */ +/* */ +typedef unsigned long FT_ULong; + + +/*************************************************************************/ +/* */ +/* */ +/* FT_F2Dot14 */ +/* */ +/* */ +/* A signed 2.14 fixed float type used for unit vectors. */ +/* */ +typedef signed short FT_F2Dot14; + + +/*************************************************************************/ +/* */ +/* */ +/* FT_F26Dot6 */ +/* */ +/* */ +/* A signed 26.6 fixed float type used for vectorial pixel */ +/* coordinates. */ +/* */ +typedef signed long FT_F26Dot6; + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Fixed */ +/* */ +/* */ +/* This type is used to store 16.16 fixed float values, like scales */ +/* or matrix coefficients. */ +/* */ +typedef signed long FT_Fixed; + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Error */ +/* */ +/* */ +/* The FreeType error code type. A value of 0 is always interpreted */ +/* as a successful operation. */ +/* */ +typedef int FT_Error; + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Pointer */ +/* */ +/* */ +/* A simple typedef for a typeless pointer. */ +/* */ +typedef void* FT_Pointer; + + +/*************************************************************************/ +/* */ +/* */ +/* FT_UnitVector */ +/* */ +/* */ +/* A simple structure used to store a 2D vector unit vector. Uses */ +/* FT_F2Dot14 types. */ +/* */ +/* */ +/* x :: Horizontal coordinate. */ +/* */ +/* y :: Vertical coordinate. */ +/* */ +typedef struct FT_UnitVector_ +{ + FT_F2Dot14 x; + FT_F2Dot14 y; + +} FT_UnitVector; + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Matrix */ +/* */ +/* */ +/* A simple structure used to store a 2x2 matrix. Coefficients are */ +/* in 16.16 fixed float format. The computation performed is: */ +/* */ +/* { */ +/* x' = x*xx + y*xy */ +/* y' = x*yx + y*yy */ +/* } */ +/* */ +/* */ +/* xx :: Matrix coefficient. */ +/* */ +/* xy :: Matrix coefficient. */ +/* */ +/* yx :: Matrix coefficient. */ +/* */ +/* yy :: Matrix coefficient. */ +/* */ +typedef struct FT_Matrix_ +{ + FT_Fixed xx, xy; + FT_Fixed yx, yy; + +} FT_Matrix; + + +/*************************************************************************/ +/* */ +/* */ +/* FT_BBox */ +/* */ +/* */ +/* A structure used to hold an outline's bounding box, i.e., the */ +/* coordinates of its extrema in the horizontal and vertical */ +/* directions. */ +/* */ +/* */ +/* xMin :: The horizontal minimum (left-most). */ +/* */ +/* yMin :: The vertical minimum (bottom-most). */ +/* */ +/* xMax :: The horizontal maximum (right-most). */ +/* */ +/* yMax :: The vertical maximum (top-most). */ +/* */ +typedef struct FT_BBox_ +{ + FT_Pos xMin, yMin; + FT_Pos xMax, yMax; + +} FT_BBox; + + +/*************************************************************************/ +/* */ +/* */ +/* FT_MAKE_TAG */ +/* */ +/* */ +/* This macro converts four letter tags which are used to label */ +/* TrueType tables into an unsigned long to be used within FreeType. */ +/* */ +#define FT_MAKE_TAG( _x1, _x2, _x3, _x4 ) \ + ( ( (FT_ULong)_x1 << 24 ) | \ + ( (FT_ULong)_x2 << 16 ) | \ + ( (FT_ULong)_x3 << 8 ) | \ + (FT_ULong)_x4 ) + + +/*************************************************************************/ +/*************************************************************************/ +/* */ +/* L I S T M A N A G E M E N T */ +/* */ +/*************************************************************************/ +/*************************************************************************/ + + +/*************************************************************************/ +/* */ +/* */ +/* FT_ListNode */ +/* */ +/* */ +/* Many elements and objects in FreeType are listed through a */ +/* FT_List record (see FT_ListRec). As its name suggests, a */ +/* FT_ListNode is a handle to a single list element. */ +/* */ +typedef struct FT_ListNodeRec_* FT_ListNode; + + +/*************************************************************************/ +/* */ +/* */ +/* FT_List */ +/* */ +/* */ +/* A handle to a list record (see FT_ListRec). */ +/* */ +typedef struct FT_ListRec_* FT_List; + + +/*************************************************************************/ +/* */ +/* */ +/* FT_ListNodeRec */ +/* */ +/* */ +/* A structure used to hold a single list element. */ +/* */ +/* */ +/* prev :: The previous element in the list. NULL if first. */ +/* */ +/* next :: The next element in the list. NULL if last. */ +/* */ +/* data :: A typeless pointer to the listed object. */ +/* */ +typedef struct FT_ListNodeRec_ +{ + FT_ListNode prev; + FT_ListNode next; + void* data; + +} FT_ListNodeRec; + + +/*************************************************************************/ +/* */ +/* */ +/* FT_ListRec */ +/* */ +/* */ +/* A structure used to hold a simple doubly-linked list. These are */ +/* used in many parts of FreeType. */ +/* */ +/* */ +/* head :: The head (first element) of doubly-linked list. */ +/* */ +/* tail :: The tail (last element) of doubly-linked list. */ +/* */ +typedef struct FT_ListRec_ +{ + FT_ListNode head; + FT_ListNode tail; + +} FT_ListRec; + + +#define FT_IS_EMPTY( list ) ( ( list ).head == 0 ) + + +#endif /* FTTYPES_H */ + + +/* END */ diff --git a/Projects/Android/jni/rtcw/src/ft2/psnames.h b/Projects/Android/jni/rtcw/src/ft2/psnames.h new file mode 100644 index 0000000..2965b0b --- /dev/null +++ b/Projects/Android/jni/rtcw/src/ft2/psnames.h @@ -0,0 +1,220 @@ +/***************************************************************************/ +/* */ +/* psnames.h */ +/* */ +/* High-level interface for the `PSNames' module (in charge of */ +/* various functions related to Postscript glyph names conversion). */ +/* */ +/* Copyright 1996-2000 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef PSNAMES_H +#define PSNAMES_H + + +#include "freetype.h" + + +/*************************************************************************/ +/* */ +/* */ +/* PS_Unicode_Value_Func */ +/* */ +/* */ +/* A function used to return the Unicode index corresponding to a */ +/* given glyph name. */ +/* */ +/* */ +/* glyph_name :: The glyph name. */ +/* */ +/* */ +/* The Unicode character index resp. the non-Unicode value 0xFFFF if */ +/* the glyph name has no known Unicode meaning. */ +/* */ +/* */ +/* This function is able to map several different glyph names to the */ +/* same Unicode value, according to the rules defined in the Adobe */ +/* Glyph List table. */ +/* */ +/* This function will not be compiled if the configuration macro */ +/* FT_CONFIG_OPTION_ADOBE_GLYPH_LIST is undefined. */ +/* */ +typedef FT_ULong ( *PS_Unicode_Value_Func )( const char* glyph_name ); + + +/*************************************************************************/ +/* */ +/* */ +/* PS_Unicode_Index_Func */ +/* */ +/* */ +/* A function used to return the glyph index corresponding to a given */ +/* Unicode value. */ +/* */ +/* */ +/* num_glyphs :: The number of glyphs in the face. */ +/* */ +/* glyph_names :: An array of glyph name pointers. */ +/* */ +/* unicode :: The Unicode value. */ +/* */ +/* */ +/* The glyph index resp. 0xFFFF if no glyph corresponds to this */ +/* Unicode value. */ +/* */ +/* */ +/* This function is able to recognize several glyph names per Unicode */ +/* value, according to the Adobe Glyph List. */ +/* */ +/* This function will not be compiled if the configuration macro */ +/* FT_CONFIG_OPTION_ADOBE_GLYPH_LIST is undefined. */ +/* */ +typedef FT_UInt ( *PS_Unicode_Index_Func )( FT_UInt num_glyphs, + const char** glyph_names, + FT_ULong unicode ); + + +/*************************************************************************/ +/* */ +/* */ +/* PS_Macintosh_Name_Func */ +/* */ +/* */ +/* A function used to return the glyph name corresponding to an Apple */ +/* glyph name index. */ +/* */ +/* */ +/* name_index :: The index of the Mac name. */ +/* */ +/* */ +/* The glyph name, or 0 if the index is invalid. */ +/* */ +/* */ +/* This function will not be compiled if the configuration macro */ +/* FT_CONFIG_OPTION_POSTSCRIPT_NAMES is undefined. */ +/* */ +typedef const char* ( *PS_Macintosh_Name_Func )( FT_UInt name_index ); + + +typedef const char* ( *PS_Adobe_Std_Strings_Func )( FT_UInt string_index ); + + +typedef struct PS_UniMap_ +{ + FT_UInt unicode; + FT_UInt glyph_index; + +} PS_UniMap; + + +/*************************************************************************/ +/* */ +/* */ +/* PS_Unicodes */ +/* */ +/* */ +/* A simple table used to map Unicode values to glyph indices. It is */ +/* built by the PS_Build_Unicodes table according to the glyphs */ +/* present in a font file. */ +/* */ +/* */ +/* num_codes :: The number of glyphs in the font that match a given */ +/* Unicode value. */ +/* */ +/* unicodes :: An array of unicode values, sorted in increasing */ +/* order. */ +/* */ +/* gindex :: An array of glyph indices, corresponding to each */ +/* Unicode value. */ +/* */ +/* */ +/* Use the function PS_Lookup_Unicode() to retrieve the glyph index */ +/* corresponding to a given Unicode character code. */ +/* */ +typedef struct PS_Unicodes_ +{ + FT_UInt num_maps; + PS_UniMap* maps; + +} PS_Unicodes; + + +typedef FT_Error ( *PS_Build_Unicodes_Func )( FT_Memory memory, + FT_UInt num_glyphs, + const char** glyph_names, + PS_Unicodes* unicodes ); + +typedef FT_UInt ( *PS_Lookup_Unicode_Func )( PS_Unicodes* unicodes, + FT_UInt unicode ); + + +/*************************************************************************/ +/* */ +/* */ +/* PSNames_Interface */ +/* */ +/* */ +/* This structure defines the PSNames interface. */ +/* */ +/* */ +/* unicode_value :: A function used to convert a glyph name */ +/* into a Unicode character code. */ +/* */ +/* build_unicodes :: A function which builds up the Unicode */ +/* mapping table. */ +/* */ +/* lookup_unicode :: A function used to return the glyph index */ +/* corresponding to a given Unicode */ +/* character. */ +/* */ +/* macintosh_name :: A function used to return the standard */ +/* Apple glyph Postscript name corresponding */ +/* to a given string index (used by the */ +/* TrueType `post' table). */ +/* */ +/* adobe_std_strings :: A function that returns a pointer to a */ +/* Adobe Standard String for a given SID. */ +/* */ +/* adobe_std_encoding :: A table of 256 unsigned shorts that maps */ +/* character codes in the Adobe Standard */ +/* Encoding to SIDs. */ +/* */ +/* adobe_expert_encoding :: A table of 256 unsigned shorts that maps */ +/* character codes in the Adobe Expert */ +/* Encoding to SIDs. */ +/* */ +/* */ +/* `unicode_value' and `unicode_index' will be set to 0 if the */ +/* configuration macro FT_CONFIG_OPTION_ADOBE_GLYPH_LIST is */ +/* undefined. */ +/* */ +/* `macintosh_name' will be set to 0 if the configuration macro */ +/* FT_CONFIG_OPTION_POSTSCRIPT_NAMES is undefined. */ +/* */ +typedef struct PSNames_Interface_ +{ + PS_Unicode_Value_Func unicode_value; + PS_Build_Unicodes_Func build_unicodes; + PS_Lookup_Unicode_Func lookup_unicode; + PS_Macintosh_Name_Func macintosh_name; + + PS_Adobe_Std_Strings_Func adobe_std_strings; + const unsigned short* adobe_std_encoding; + const unsigned short* adobe_expert_encoding; + +} PSNames_Interface; + + +#endif /* PSNAMES_H */ + + +/* END */ diff --git a/Projects/Android/jni/rtcw/src/ft2/sfdriver.c b/Projects/Android/jni/rtcw/src/ft2/sfdriver.c new file mode 100644 index 0000000..703b077 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/ft2/sfdriver.c @@ -0,0 +1,211 @@ +/***************************************************************************/ +/* */ +/* sfdriver.c */ +/* */ +/* High-level SFNT driver interface (body). */ +/* */ +/* Copyright 1996-2000 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#include "sfnt.h" +#include "ftobjs.h" + + + +#include "sfdriver.h" +#include "ttload.h" +#include "ttsbit.h" +#include "ttpost.h" +#include "ttcmap.h" +#include "sfobjs.h" + +#include /* for strcmp() */ + + +static +void* get_sfnt_table( TT_Face face, + FT_Sfnt_Tag tag ) { + void* table; + + + switch ( tag ) + { + case ft_sfnt_head: + table = &face->header; + break; + + case ft_sfnt_hhea: + table = &face->horizontal; + break; + + case ft_sfnt_vhea: + table = face->vertical_info ? &face->vertical : 0; + break; + + case ft_sfnt_os2: + table = face->os2.version == 0xFFFF ? 0 : &face->os2; + break; + + case ft_sfnt_post: + table = &face->postscript; + break; + + case ft_sfnt_maxp: + table = &face->max_profile; + break; + + case ft_sfnt_pclt: + table = face->pclt.Version ? &face->pclt : 0; + break; + + default: + table = 0; + } + + return table; +} + + +#ifdef TT_CONFIG_OPTION_POSTSCRIPT_NAMES + + +static +FT_Error get_sfnt_glyph_name( TT_Face face, + FT_UInt glyph_index, + FT_Pointer buffer, + FT_UInt buffer_max ) { + FT_String* gname; + FT_Error error; + + + error = TT_Get_PS_Name( face, glyph_index, &gname ); + if ( !error && buffer_max > 0 ) { + FT_UInt len = strlen( gname ); + + + if ( len >= buffer_max ) { + len = buffer_max - 1; + } + + MEM_Copy( buffer, gname, len ); + ( (FT_Byte*)buffer )[len] = 0; + } + + return error; +} + + +#endif /* TT_CONFIG_OPTION_POSTSCRIPT_NAMES */ + + +static +FT_Module_Interface SFNT_Get_Interface( FT_Module module, + const char* interface ) { + FT_UNUSED( module ); + + if ( strcmp( interface, "get_sfnt" ) == 0 ) { + return (FT_Module_Interface)get_sfnt_table; + } + +#ifdef TT_CONFIG_OPTION_POSTSCRIPT_NAMES + if ( strcmp( interface, "glyph_name" ) == 0 ) { + return (FT_Module_Interface)get_sfnt_glyph_name; + } +#endif + return 0; +} + + +static +const SFNT_Interface sfnt_interface = +{ + TT_Goto_Table, + + SFNT_Init_Face, + SFNT_Load_Face, + SFNT_Done_Face, + SFNT_Get_Interface, + + TT_Load_Any, + TT_Load_SFNT_Header, + TT_Load_Directory, + + TT_Load_Header, + TT_Load_Metrics_Header, + TT_Load_CMap, + TT_Load_MaxProfile, + TT_Load_OS2, + TT_Load_PostScript, + + TT_Load_Names, + TT_Free_Names, + + TT_Load_Hdmx, + TT_Free_Hdmx, + + TT_Load_Kern, + TT_Load_Gasp, + TT_Load_PCLT, + +#ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS + + /* see `ttsbit.h' */ + TT_Load_SBit_Strikes, + TT_Load_SBit_Image, + TT_Free_SBit_Strikes, + +#else /* TT_CONFIG_OPTION_EMBEDDED_BITMAPS */ + + 0, + 0, + 0, + +#endif /* TT_CONFIG_OPTION_EMBEDDED_BITMAPS */ + +#ifdef TT_CONFIG_OPTION_POSTSCRIPT_NAMES + + /* see `ttpost.h' */ + TT_Get_PS_Name, + TT_Free_Post_Names, + +#else /* TT_CONFIG_OPTION_POSTSCRIPT_NAMES */ + + 0, + 0, + +#endif /* TT_CONFIG_OPTION_POSTSCRIPT_NAMES */ + + /* see `ttcmap.h' */ + TT_CharMap_Load, + TT_CharMap_Free, +}; + + +const +FT_Module_Class sfnt_module_class = +{ + 0, /* not a font driver or renderer */ + sizeof( FT_ModuleRec ), + + "sfnt", /* driver name */ + 0x10000L, /* driver version 1.0 */ + 0x20000L, /* driver requires FreeType 2.0 or higher */ + + (const void*)&sfnt_interface, /* module specific interface */ + + (FT_Module_Constructor)0, + (FT_Module_Destructor) 0, + (FT_Module_Requester) SFNT_Get_Interface +}; + + +/* END */ diff --git a/Projects/Android/jni/rtcw/src/ft2/sfdriver.h b/Projects/Android/jni/rtcw/src/ft2/sfdriver.h new file mode 100644 index 0000000..07bd555 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/ft2/sfdriver.h @@ -0,0 +1,29 @@ +/***************************************************************************/ +/* */ +/* sfdriver.h */ +/* */ +/* High-level SFNT driver interface (specification). */ +/* */ +/* Copyright 1996-2000 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef SFDRIVER_H +#define SFDRIVER_H + +#include "ftmodule.h" + +FT_EXPORT_VAR( const FT_Module_Class ) sfnt_module_class; + +#endif /* SFDRIVER_H */ + + +/* END */ diff --git a/Projects/Android/jni/rtcw/src/ft2/sfnt.h b/Projects/Android/jni/rtcw/src/ft2/sfnt.h new file mode 100644 index 0000000..4d81f9a --- /dev/null +++ b/Projects/Android/jni/rtcw/src/ft2/sfnt.h @@ -0,0 +1,492 @@ +/***************************************************************************/ +/* */ +/* sfnt.h */ +/* */ +/* High-level `sfnt' driver interface (specification). */ +/* */ +/* Copyright 1996-2000 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef SFNT_H +#define SFNT_H + + +#include "freetype.h" +#include "ftdriver.h" +#include "tttypes.h" + + +/*************************************************************************/ +/* */ +/* */ +/* TT_Init_Face_Func */ +/* */ +/* */ +/* First part of the SFNT face object initialization. This will find */ +/* the face in a SFNT file or collection, and load its format tag in */ +/* face->format_tag. */ +/* */ +/* */ +/* stream :: The input stream. */ +/* */ +/* face :: A handle to the target face object. */ +/* */ +/* face_index :: The index of the TrueType font, if we are opening a */ +/* collection. */ +/* */ +/* num_params :: The number of additional parameters. */ +/* */ +/* params :: Optional additional parameters. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +/* */ +/* The stream cursor must be at the font file's origin. */ +/* */ +/* This function recognizes fonts embedded in a `TrueType */ +/* collection'. */ +/* */ +/* Once the format tag has been validated by the font driver, it */ +/* should then call the TT_Load_Face_Func() callback to read the rest */ +/* of the SFNT tables in the object. */ +/* */ +typedef +FT_Error ( *TT_Init_Face_Func )( FT_Stream stream, + TT_Face face, + FT_Int face_index, + FT_Int num_params, + FT_Parameter* params ); + + +/*************************************************************************/ +/* */ +/* */ +/* TT_Load_Face_Func */ +/* */ +/* */ +/* Second part of the SFNT face object initialization. This will */ +/* load the common SFNT tables (head, OS/2, maxp, metrics, etc.) in */ +/* the face object. */ +/* */ +/* */ +/* stream :: The input stream. */ +/* */ +/* face :: A handle to the target face object. */ +/* */ +/* face_index :: The index of the TrueType font, if we are opening a */ +/* collection. */ +/* */ +/* num_params :: The number of additional parameters. */ +/* */ +/* params :: Optional additional parameters. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +/* */ +/* This function must be called after TT_Init_Face_Func(). */ +/* */ +typedef +FT_Error ( *TT_Load_Face_Func )( FT_Stream stream, + TT_Face face, + FT_Int face_index, + FT_Int num_params, + FT_Parameter* params ); + + +/*************************************************************************/ +/* */ +/* */ +/* TT_Done_Face_Func */ +/* */ +/* */ +/* A callback used to delete the common SFNT data from a face. */ +/* */ +/* */ +/* face :: A handle to the target face object. */ +/* */ +/* */ +/* This function does NOT destroy the face object. */ +/* */ +typedef +void ( *TT_Done_Face_Func )( TT_Face face ); + + +typedef +FT_Module_Interface ( *SFNT_Get_Interface_Func )( FT_Module module, + const char* interface ); + + +/*************************************************************************/ +/* */ +/* */ +/* TT_Load_SFNT_Header_Func */ +/* */ +/* */ +/* Loads the header of a SFNT font file. Supports collections. */ +/* */ +/* */ +/* face :: A handle to the target face object. */ +/* */ +/* stream :: The input stream. */ +/* */ +/* face_index :: The index of the TrueType font, if we are opening a */ +/* collection. */ +/* */ +/* */ +/* sfnt :: The SFNT header. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +/* */ +/* The stream cursor must be at the font file's origin. */ +/* */ +/* This function recognizes fonts embedded in a `TrueType */ +/* collection'. */ +/* */ +/* This function checks that the header is valid by looking at the */ +/* values of `search_range', `entry_selector', and `range_shift'. */ +/* */ +typedef +FT_Error ( *TT_Load_SFNT_Header_Func )( TT_Face face, + FT_Stream stream, + FT_Long face_index, + SFNT_Header* sfnt ); + + +/*************************************************************************/ +/* */ +/* */ +/* TT_Load_Directory_Func */ +/* */ +/* */ +/* Loads the table directory into a face object. */ +/* */ +/* */ +/* face :: A handle to the target face object. */ +/* */ +/* stream :: The input stream. */ +/* */ +/* sfnt :: The SFNT header. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +/* */ +/* The stream cursor must be on the first byte after the 4-byte font */ +/* format tag. This is the case just after a call to */ +/* TT_Load_Format_Tag(). */ +/* */ +typedef +FT_Error ( *TT_Load_Directory_Func )( TT_Face face, + FT_Stream stream, + SFNT_Header* sfnt ); + + +/*************************************************************************/ +/* */ +/* */ +/* TT_Load_Any_Func */ +/* */ +/* */ +/* Loads any font table into client memory. */ +/* */ +/* */ +/* face :: The face object to look for. */ +/* */ +/* tag :: The tag of table to load. Use the value 0 if you want */ +/* to access the whole font file, else set this parameter */ +/* to a valid TrueType table tag that you can forge with */ +/* the MAKE_TT_TAG macro. */ +/* */ +/* offset :: The starting offset in the table (or the file if */ +/* tag == 0). */ +/* */ +/* length :: The address of the decision variable: */ +/* */ +/* If length == NULL: */ +/* Loads the whole table. Returns an error if */ +/* `offset' == 0! */ +/* */ +/* If *length == 0: */ +/* Exits immediately; returning the length of the given */ +/* table or of the font file, depending on the value of */ +/* `tag'. */ +/* */ +/* If *length != 0: */ +/* Loads the next `length' bytes of table or font, */ +/* starting at offset `offset' (in table or font too). */ +/* */ +/* */ +/* buffer :: The address of target buffer. */ +/* */ +/* */ +/* TrueType error code. 0 means success. */ +/* */ +typedef +FT_Error ( *TT_Load_Any_Func )( TT_Face face, + FT_ULong tag, + FT_Long offset, + FT_Byte* buffer, + FT_ULong* length ); + + +/*************************************************************************/ +/* */ +/* */ +/* TT_Load_SBit_Image_Func */ +/* */ +/* */ +/* Loads a given glyph sbit image from the font resource. This also */ +/* returns its metrics. */ +/* */ +/* */ +/* face :: The target face object. */ +/* */ +/* x_ppem :: The horizontal resolution in points per EM. */ +/* */ +/* y_ppem :: The vertical resolution in points per EM. */ +/* */ +/* glyph_index :: The current glyph index. */ +/* */ +/* stream :: The input stream. */ +/* */ +/* */ +/* map :: The target pixmap. */ +/* */ +/* metrics :: A big sbit metrics structure for the glyph image. */ +/* */ +/* */ +/* FreeType error code. 0 means success. Returns an error if no */ +/* glyph sbit exists for the index. */ +/* */ +/* */ +/* The `map.buffer' field is always freed before the glyph is loaded. */ +/* */ +typedef +FT_Error ( *TT_Load_SBit_Image_Func )( TT_Face face, + FT_Int x_ppem, + FT_Int y_ppem, + FT_UInt glyph_index, + FT_UInt load_flags, + FT_Stream stream, + FT_Bitmap* map, + TT_SBit_Metrics* metrics ); + + +/*************************************************************************/ +/* */ +/* */ +/* TT_Get_PS_Name_Func */ +/* */ +/* */ +/* Gets the PostScript glyph name of a glyph. */ +/* */ +/* */ +/* index :: The glyph index. */ +/* */ +/* PSname :: The address of a string pointer. Will be NULL in case */ +/* of error, otherwise it is a pointer to the glyph name. */ +/* */ +/* You must not modify the returned string! */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +typedef +FT_Error ( *TT_Get_PS_Name_Func )( TT_Face face, + FT_UInt index, + FT_String** PSname ); + + +/*************************************************************************/ +/* */ +/* */ +/* TT_Load_Metrics_Func */ +/* */ +/* */ +/* Loads the horizontal or vertical header in a face object. */ +/* */ +/* */ +/* face :: A handle to the target face object. */ +/* */ +/* stream :: The input stream. */ +/* */ +/* vertical :: A boolean flag. If set, load vertical metrics. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +typedef +FT_Error ( *TT_Load_Metrics_Func )( TT_Face face, + FT_Stream stream, + FT_Bool vertical ); + + +/*************************************************************************/ +/* */ +/* */ +/* TT_CharMap_Load_Func */ +/* */ +/* */ +/* Loads a given TrueType character map into memory. */ +/* */ +/* */ +/* face :: A handle to the parent face object. */ +/* */ +/* stream :: A handle to the current stream object. */ +/* */ +/* */ +/* cmap :: A pointer to a cmap object. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +/* */ +/* The function assumes that the stream is already in use (i.e., */ +/* opened). In case of error, all partially allocated tables are */ +/* released. */ +/* */ +typedef +FT_Error ( *TT_CharMap_Load_Func )( TT_Face face, + TT_CMapTable* cmap, + FT_Stream input ); + + +/*************************************************************************/ +/* */ +/* */ +/* TT_CharMap_Free_Func */ +/* */ +/* */ +/* Destroys a character mapping table. */ +/* */ +/* */ +/* face :: A handle to the parent face object. */ +/* */ +/* cmap :: A handle to a cmap object. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +typedef +FT_Error ( *TT_CharMap_Free_Func )( TT_Face face, + TT_CMapTable* cmap ); + + +/*************************************************************************/ +/* */ +/* */ +/* TT_Load_Table_Func */ +/* */ +/* */ +/* Loads a given TrueType table. */ +/* */ +/* */ +/* face :: A handle to the target face object. */ +/* */ +/* stream :: The input stream. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +/* */ +/* The function will use `face->goto_table' to seek the stream to */ +/* the start of the table. */ +/* */ +typedef +FT_Error ( *TT_Load_Table_Func )( TT_Face face, + FT_Stream stream ); + + +/*************************************************************************/ +/* */ +/* */ +/* TT_Free_Table_Func */ +/* */ +/* */ +/* Frees a given TrueType table. */ +/* */ +/* */ +/* face :: A handle to the target face object. */ +/* */ +typedef +void ( *TT_Free_Table_Func )( TT_Face face ); + + +/*************************************************************************/ +/* */ +/* */ +/* SFNT_Interface */ +/* */ +/* */ +/* This structure holds pointers to the functions used to load and */ +/* free the basic tables that are required in a `sfnt' font file. */ +/* */ +/* */ +/* Check the various xxx_Func() descriptions for details. */ +/* */ +typedef struct SFNT_Interface_ +{ + TT_Goto_Table_Func goto_table; + + TT_Init_Face_Func init_face; + TT_Load_Face_Func load_face; + TT_Done_Face_Func done_face; + SFNT_Get_Interface_Func get_interface; + + TT_Load_Any_Func load_any; + TT_Load_SFNT_Header_Func load_sfnt_header; + TT_Load_Directory_Func load_directory; + + /* these functions are called by `load_face' but they can also */ + /* be called from external modules, if there is a need to do so */ + TT_Load_Table_Func load_header; + TT_Load_Metrics_Func load_metrics; + TT_Load_Table_Func load_charmaps; + TT_Load_Table_Func load_max_profile; + TT_Load_Table_Func load_os2; + TT_Load_Table_Func load_psnames; + + TT_Load_Table_Func load_names; + TT_Free_Table_Func free_names; + + /* optional tables */ + TT_Load_Table_Func load_hdmx; + TT_Free_Table_Func free_hdmx; + + TT_Load_Table_Func load_kerning; + TT_Load_Table_Func load_gasp; + TT_Load_Table_Func load_pclt; + + /* see `ttsbit.h' */ + TT_Load_Table_Func load_sbits; + TT_Load_SBit_Image_Func load_sbit_image; + TT_Free_Table_Func free_sbits; + + /* see `ttpost.h' */ + TT_Get_PS_Name_Func get_psname; + TT_Free_Table_Func free_psnames; + + /* see `ttcmap.h' */ + TT_CharMap_Load_Func load_charmap; + TT_CharMap_Free_Func free_charmap; + +} SFNT_Interface; + + +#endif /* SFNT_H */ + + +/* END */ diff --git a/Projects/Android/jni/rtcw/src/ft2/sfobjs.c b/Projects/Android/jni/rtcw/src/ft2/sfobjs.c new file mode 100644 index 0000000..6f42776 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/ft2/sfobjs.c @@ -0,0 +1,555 @@ +/***************************************************************************/ +/* */ +/* sfobjs.c */ +/* */ +/* SFNT object management (base). */ +/* */ +/* Copyright 1996-2000 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + + +#include "sfobjs.h" + + +#include "sfnt.h" +#include "psnames.h" +#include "ttnameid.h" +#include "tterrors.h" + + +/*************************************************************************/ +/* */ +/* The macro FT_COMPONENT is used in trace mode. It is an implicit */ +/* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */ +/* messages during execution. */ +/* */ +#undef FT_COMPONENT +#define FT_COMPONENT trace_sfobjs + + +/*************************************************************************/ +/* */ +/* */ +/* Get_Name */ +/* */ +/* */ +/* Returns a given ENGLISH name record in ASCII. */ +/* */ +/* */ +/* face :: A handle to the source face object. */ +/* */ +/* nameid :: The name id of the name record to return. */ +/* */ +/* */ +/* Character string. NULL if no name is present. */ +/* */ +static +FT_String* Get_Name( TT_Face face, + FT_UShort nameid ) { + FT_Memory memory = face->root.memory; + FT_UShort n; + TT_NameRec* rec; + FT_Bool wide_chars = 1; + + + rec = face->name_table.names; + for ( n = 0; n < face->name_table.numNameRecords; n++, rec++ ) + { + if ( rec->nameID == nameid ) { + /* found the name -- now create an ASCII string from it */ + FT_Bool found = 0; + + + /* test for Microsoft English language */ + if ( rec->platformID == TT_PLATFORM_MICROSOFT && + rec->encodingID <= TT_MS_ID_UNICODE_CS && + ( rec->languageID & 0x3FF ) == 0x009 ) { + found = 1; + } + /* test for Apple Unicode encoding */ + else if ( rec->platformID == TT_PLATFORM_APPLE_UNICODE ) { + found = 1; + } + /* test for Apple Roman */ + else if ( rec->platformID == TT_PLATFORM_MACINTOSH && + rec->languageID == TT_MAC_ID_ROMAN ) { + found = 1; + wide_chars = 0; + } + + /* found a Unicode name */ + if ( found ) { + FT_String* string; + FT_UInt len; + + + if ( wide_chars ) { + FT_UInt m; + + + len = (FT_UInt)rec->stringLength / 2; + if ( MEM_Alloc( string, len + 1 ) ) { + return NULL; + } + + for ( m = 0; m < len; m++ ) + string[m] = rec->string[2 * m + 1]; + } else + { + len = rec->stringLength; + if ( MEM_Alloc( string, len + 1 ) ) { + return NULL; + } + + MEM_Copy( string, rec->string, len ); + } + + string[len] = '\0'; + return string; + } + } + } + + return NULL; +} + + +static +FT_Encoding find_encoding( int platform_id, + int encoding_id ) { + typedef struct TEncoding + { + int platform_id; + int encoding_id; + FT_Encoding encoding; + + } TEncoding; + + static + const TEncoding tt_encodings[] = + { + { TT_PLATFORM_ISO, -1, ft_encoding_unicode }, + + { TT_PLATFORM_APPLE_UNICODE, -1, ft_encoding_unicode }, + + { TT_PLATFORM_MACINTOSH, TT_MAC_ID_ROMAN, ft_encoding_apple_roman }, + + { TT_PLATFORM_MICROSOFT, TT_MS_ID_UNICODE_CS, ft_encoding_unicode }, + { TT_PLATFORM_MICROSOFT, TT_MS_ID_SJIS, ft_encoding_sjis }, + { TT_PLATFORM_MICROSOFT, TT_MS_ID_GB2312, ft_encoding_gb2312 }, + { TT_PLATFORM_MICROSOFT, TT_MS_ID_BIG_5, ft_encoding_big5 }, + { TT_PLATFORM_MICROSOFT, TT_MS_ID_WANSUNG, ft_encoding_wansung }, + { TT_PLATFORM_MICROSOFT, TT_MS_ID_JOHAB, ft_encoding_johab } + }; + + const TEncoding *cur, *limit; + + + cur = tt_encodings; + limit = cur + sizeof( tt_encodings ) / sizeof( tt_encodings[0] ); + + for ( ; cur < limit; cur++ ) + { + if ( cur->platform_id == platform_id ) { + if ( cur->encoding_id == encoding_id || + cur->encoding_id == -1 ) { + return cur->encoding; + } + } + } + + return ft_encoding_none; +} + + +LOCAL_FUNC +FT_Error SFNT_Init_Face( FT_Stream stream, + TT_Face face, + FT_Int face_index, + FT_Int num_params, + FT_Parameter* params ) { + FT_Error error; + FT_Library library = face->root.driver->root.library; + SFNT_Interface* sfnt; + SFNT_Header sfnt_header; + + /* for now, parameters are unused */ + FT_UNUSED( num_params ); + FT_UNUSED( params ); + + sfnt = (SFNT_Interface*)face->sfnt; + if ( !sfnt ) { + sfnt = (SFNT_Interface*)FT_Get_Module_Interface( library, "sfnt" ); + if ( !sfnt ) { + error = FT_Err_Invalid_File_Format; + goto Exit; + } + + face->sfnt = sfnt; + face->goto_table = sfnt->goto_table; + } + + if ( !face->psnames ) { + face->psnames = (PSNames_Interface*) + FT_Get_Module_Interface( library, "psnames" ); + } + + /* check that we have a valid TrueType file */ + error = sfnt->load_sfnt_header( face, stream, face_index, &sfnt_header ); + if ( error ) { + goto Exit; + } + + face->format_tag = sfnt_header.format_tag; + face->num_tables = sfnt_header.num_tables; + + /* Load font directory */ + error = sfnt->load_directory( face, stream, &sfnt_header ); + if ( error ) { + goto Exit; + } + + face->root.num_faces = face->ttc_header.count; + if ( face->root.num_faces < 1 ) { + face->root.num_faces = 1; + } + +Exit: + return error; +} + + +#undef LOAD_ +#define LOAD_( x ) ( ( error = sfnt->load_ ## x( face, stream ) ) \ + != TT_Err_Ok ) + + +LOCAL_FUNC +FT_Error SFNT_Load_Face( FT_Stream stream, + TT_Face face, + FT_Int face_index, + FT_Int num_params, + FT_Parameter* params ) { + FT_Error error; + SFNT_Interface* sfnt = (SFNT_Interface*)face->sfnt; + + FT_UNUSED( face_index ); + FT_UNUSED( num_params ); + FT_UNUSED( params ); + + + /* Load tables */ + if ( LOAD_( header ) || + LOAD_( max_profile ) || + + /* load the `hhea' & `hmtx' tables at once */ + ( error = sfnt->load_metrics( face, stream, 0 ) ) != TT_Err_Ok || + + /* try to load the `vhea' & `vmtx' at once if present */ + ( error = sfnt->load_metrics( face, stream, 1 ) ) != TT_Err_Ok || + + LOAD_( charmaps ) || + LOAD_( names ) || + LOAD_( os2 ) || + LOAD_( psnames ) ) { + goto Exit; + } + + /* the optional tables */ + +#ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS + /* embedded bitmap support. */ + if ( sfnt->load_sbits && LOAD_( sbits ) ) { + goto Exit; + } +#endif /* TT_CONFIG_OPTION_EMBEDDED_BITMAPS */ + + if ( LOAD_( hdmx ) || + LOAD_( gasp ) || + LOAD_( kerning ) || + LOAD_( pclt ) ) { + goto Exit; + } + +#ifdef TT_CONFIG_OPTION_EXTEND_ENGINE + if ( ( error = TT_Extension_Create( face ) ) != TT_Err_Ok ) { + goto Exit; + } +#endif + + face->root.family_name = Get_Name( face, TT_NAME_ID_FONT_FAMILY ); + face->root.style_name = Get_Name( face, TT_NAME_ID_FONT_SUBFAMILY ); + + /* now set up root fields */ + { + FT_Face root = &face->root; + FT_Int flags; + TT_CharMap charmap; + FT_Int n; + FT_Memory memory; + + + memory = root->memory; + + /*********************************************************************/ + /* */ + /* Compute face flags. */ + /* */ + flags = FT_FACE_FLAG_SCALABLE | /* scalable outlines */ + FT_FACE_FLAG_SFNT | /* SFNT file format */ + FT_FACE_FLAG_HORIZONTAL; /* horizontal data */ + +#ifdef TT_CONFIG_OPTION_POSTSCRIPT_NAMES + /* might need more polish to detect the presence of a Postscript */ + /* name table in the font */ + flags |= FT_FACE_FLAG_GLYPH_NAMES; +#endif + + /* fixed width font? */ + if ( face->postscript.isFixedPitch ) { + flags |= FT_FACE_FLAG_FIXED_WIDTH; + } + + /* vertical information? */ + if ( face->vertical_info ) { + flags |= FT_FACE_FLAG_VERTICAL; + } + + /* kerning available ? */ + if ( face->kern_pairs ) { + flags |= FT_FACE_FLAG_KERNING; + } + + root->face_flags = flags; + + /*********************************************************************/ + /* */ + /* Compute style flags. */ + /* */ + flags = 0; + + if ( face->os2.version != 0xFFFF ) { + /* we have an OS/2 table; use the `fsSelection' field */ + if ( face->os2.fsSelection & 1 ) { + flags |= FT_STYLE_FLAG_ITALIC; + } + + if ( face->os2.fsSelection & 32 ) { + flags |= FT_STYLE_FLAG_BOLD; + } + } else + { + /* this is an old Mac font, use the header field */ + if ( face->header.Mac_Style & 1 ) { + flags |= FT_STYLE_FLAG_BOLD; + } + + if ( face->header.Mac_Style & 2 ) { + flags |= FT_STYLE_FLAG_ITALIC; + } + } + + root->style_flags = flags; + + /*********************************************************************/ + /* */ + /* Polish the charmaps. */ + /* */ + /* Try to set the charmap encoding according to the platform & */ + /* encoding ID of each charmap. */ + /* */ + charmap = face->charmaps; + root->num_charmaps = face->num_charmaps; + + /* allocate table of pointers */ + if ( ALLOC_ARRAY( root->charmaps, root->num_charmaps, FT_CharMap ) ) { + goto Exit; + } + + for ( n = 0; n < root->num_charmaps; n++, charmap++ ) + { + FT_Int platform = charmap->cmap.platformID; + FT_Int encoding = charmap->cmap.platformEncodingID; + + + charmap->root.face = (FT_Face)face; + charmap->root.platform_id = platform; + charmap->root.encoding_id = encoding; + charmap->root.encoding = find_encoding( platform, encoding ); + + /* now, set root->charmap with a unicode charmap */ + /* wherever available */ + if ( !root->charmap && + charmap->root.encoding == ft_encoding_unicode ) { + root->charmap = (FT_CharMap)charmap; + } + + root->charmaps[n] = (FT_CharMap)charmap; + } + +#ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS + + if ( face->num_sbit_strikes ) { + root->num_fixed_sizes = face->num_sbit_strikes; + if ( ALLOC_ARRAY( root->available_sizes, + face->num_sbit_strikes, + FT_Bitmap_Size ) ) { + return error; + } + + for ( n = 0 ; n < face->num_sbit_strikes ; n++ ) + { + root->available_sizes[n].width = + face->sbit_strikes[n].x_ppem; + root->available_sizes[n].height = + face->sbit_strikes[n].y_ppem; + } + } else { + +#else /* TT_CONFIG_OPTION_EMBEDDED_BITMAPS */ + + { + root->num_fixed_sizes = 0; + root->available_sizes = 0; + } + +#endif /* TT_CONFIG_OPTION_EMBEDDED_BITMAPS */ { + + /*********************************************************************/ + /* */ + /* Set up metrics. */ + /* */ + root->bbox.xMin = face->header.xMin; + } + root->bbox.yMin = face->header.yMin; + root->bbox.xMax = face->header.xMax; + root->bbox.yMax = face->header.yMax; + root->units_per_EM = face->header.Units_Per_EM; + + /* The ascender/descender/height are computed from the OS/2 table */ + /* when found. Otherwise, they're taken from the horizontal header. */ + if ( face->os2.version != 0xFFFF ) { + root->ascender = face->os2.sTypoAscender; + root->descender = -face->os2.sTypoDescender; + root->height = root->ascender + root->descender + + face->os2.sTypoLineGap; + } else + { + root->ascender = face->horizontal.Ascender; + root->descender = face->horizontal.Descender; + root->height = root->ascender + root->descender + + face->horizontal.Line_Gap; + } + + root->max_advance_width = face->horizontal.advance_Width_Max; + + root->max_advance_height = face->vertical_info + ? face->vertical.advance_Height_Max + : root->height; + + root->underline_position = face->postscript.underlinePosition; + root->underline_thickness = face->postscript.underlineThickness; + + /* root->max_points -- already set up */ + /* root->max_contours -- already set up */ + } + +Exit: + return error; +} + + +#undef LOAD_ + + +LOCAL_FUNC +void SFNT_Done_Face( TT_Face face ) { + FT_Memory memory = face->root.memory; + SFNT_Interface* sfnt = (SFNT_Interface*)face->sfnt; + + + if ( sfnt ) { + /* destroy the postscript names table if it is loaded */ + if ( sfnt->free_psnames ) { + sfnt->free_psnames( face ); + } + + /* destroy the embedded bitmaps table if it is loaded */ + if ( sfnt->free_sbits ) { + sfnt->free_sbits( face ); + } + } + + /* freeing the kerning table */ + FREE( face->kern_pairs ); + face->num_kern_pairs = 0; + + /* freeing the collection table */ + FREE( face->ttc_header.offsets ); + face->ttc_header.count = 0; + + /* freeing table directory */ + FREE( face->dir_tables ); + face->num_tables = 0; + + /* freeing the character mapping tables */ + if ( sfnt && sfnt->load_charmaps ) { + FT_UShort n; + + + for ( n = 0; n < face->num_charmaps; n++ ) + sfnt->free_charmap( face, &face->charmaps[n].cmap ); + } + + FREE( face->charmaps ); + face->num_charmaps = 0; + + FREE( face->root.charmaps ); + face->root.num_charmaps = 0; + face->root.charmap = 0; + + /* freeing the horizontal metrics */ + FREE( face->horizontal.long_metrics ); + FREE( face->horizontal.short_metrics ); + + /* freeing the vertical ones, if any */ + if ( face->vertical_info ) { + FREE( face->vertical.long_metrics ); + FREE( face->vertical.short_metrics ); + face->vertical_info = 0; + } + + /* freeing the gasp table */ + FREE( face->gasp.gaspRanges ); + face->gasp.numRanges = 0; + + /* freeing the name table */ + sfnt->free_names( face ); + + /* freeing the hdmx table */ + sfnt->free_hdmx( face ); + + /* freeing family and style name */ + FREE( face->root.family_name ); + FREE( face->root.style_name ); + + /* freeing sbit size table */ + face->root.num_fixed_sizes = 0; + if ( face->root.available_sizes ) { + FREE( face->root.available_sizes ); + } + + face->sfnt = 0; +} + + +/* END */ diff --git a/Projects/Android/jni/rtcw/src/ft2/sfobjs.h b/Projects/Android/jni/rtcw/src/ft2/sfobjs.h new file mode 100644 index 0000000..89b8621 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/ft2/sfobjs.h @@ -0,0 +1,57 @@ +/***************************************************************************/ +/* */ +/* sfobjs.h */ +/* */ +/* SFNT object management (specification). */ +/* */ +/* Copyright 1996-2000 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef SFOBJS_H +#define SFOBJS_H + +#include "sfnt.h" +#include "ftobjs.h" + + +#ifdef __cplusplus +extern "C" { +#endif + + +LOCAL_DEF +FT_Error SFNT_Init_Face( FT_Stream stream, + TT_Face face, + FT_Int face_index, + FT_Int num_params, + FT_Parameter* params ); + +LOCAL_DEF +FT_Error SFNT_Load_Face( FT_Stream stream, + TT_Face face, + FT_Int face_index, + FT_Int num_params, + FT_Parameter* params ); + +LOCAL_DEF +void SFNT_Done_Face( TT_Face face ); + + +#ifdef __cplusplus +} +#endif + + +#endif /* SFDRIVER_H */ + + +/* END */ diff --git a/Projects/Android/jni/rtcw/src/ft2/t1tables.h b/Projects/Android/jni/rtcw/src/ft2/t1tables.h new file mode 100644 index 0000000..ecf41f1 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/ft2/t1tables.h @@ -0,0 +1,235 @@ +/***************************************************************************/ +/* */ +/* t1tables.h */ +/* */ +/* Basic Type 1/Type 2 tables definitions and interface (specification */ +/* only). */ +/* */ +/* Copyright 1996-2000 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef T1TABLES_H +#define T1TABLES_H + + +#include "freetype.h" + + +/* Note that we separate font data in T1_FontInfo and T1_Private */ +/* structures in order to support Multiple Master fonts. */ + + +/*************************************************************************/ +/* */ +/* */ +/* T1_FontInfo */ +/* */ +/* */ +/* A structure used to model a Type1/Type2 FontInfo dictionary. Note */ +/* that for Multiple Master fonts, each instance has its own */ +/* FontInfo. */ +/* */ +typedef struct T1_FontInfo +{ + FT_String* version; + FT_String* notice; + FT_String* full_name; + FT_String* family_name; + FT_String* weight; + FT_Long italic_angle; + FT_Bool is_fixed_pitch; + FT_Short underline_position; + FT_UShort underline_thickness; + +} T1_FontInfo; + + +/*************************************************************************/ +/* */ +/* */ +/* T1_Private */ +/* */ +/* */ +/* A structure used to model a Type1/Type2 FontInfo dictionary. Note */ +/* that for Multiple Master fonts, each instance has its own Private */ +/* dict. */ +/* */ +typedef struct T1_Private +{ + FT_Int unique_id; + FT_Int lenIV; + + FT_Byte num_blue_values; + FT_Byte num_other_blues; + FT_Byte num_family_blues; + FT_Byte num_family_other_blues; + + FT_Short blue_values[14]; + FT_Short other_blues[10]; + + FT_Short family_blues [14]; + FT_Short family_other_blues[10]; + + FT_Fixed blue_scale; + FT_Int blue_shift; + FT_Int blue_fuzz; + + FT_UShort standard_width[1]; + FT_UShort standard_height[1]; + + FT_Byte num_snap_widths; + FT_Byte num_snap_heights; + FT_Bool force_bold; + FT_Bool round_stem_up; + + FT_Short snap_widths [13]; /* reserve one place for the std */ + FT_Short snap_heights[13]; /* reserve one place for the std */ + + FT_Long language_group; + FT_Long password; + + FT_Short min_feature[2]; + +} T1_Private; + + +/*************************************************************************/ +/* */ +/* */ +/* T1_Blend_Flags */ +/* */ +/* */ +/* A set of flags used to indicate which fields are present in a */ +/* given blen dictionary (font info or private). Used to support */ +/* Multiple Masters fonts. */ +/* */ +typedef enum +{ + /* required fields in a FontInfo blend dictionary */ + t1_blend_underline_position = 0, + t1_blend_underline_thickness, + t1_blend_italic_angle, + + /* required fields in a Private blend dictionary */ + t1_blend_blue_values, + t1_blend_other_blues, + t1_blend_standard_width, + t1_blend_standard_height, + t1_blend_stem_snap_widths, + t1_blend_stem_snap_heights, + t1_blend_blue_scale, + t1_blend_blue_shift, + t1_blend_family_blues, + t1_blend_family_other_blues, + t1_blend_force_bold, + + /* never remove */ + t1_blend_max + +} T1_Blend_Flags; + + +/* maximum number of Multiple Masters designs, as defined in the spec */ +#define T1_MAX_MM_DESIGNS 16 + +/* maximum number of Multiple Masters axes, as defined in the spec */ +#define T1_MAX_MM_AXIS 4 + +/* maximum number of elements in a design map */ +#define T1_MAX_MM_MAP_POINTS 20 + + +/* this structure is used to store the BlendDesignMap entry for an axis */ +typedef struct T1_DesignMap_ +{ + FT_Byte num_points; + FT_Fixed* design_points; + FT_Fixed* blend_points; + +} T1_DesignMap; + + +typedef struct T1_Blend_ +{ + FT_UInt num_designs; + FT_UInt num_axis; + + FT_String* axis_names[T1_MAX_MM_AXIS]; + FT_Fixed* design_pos[T1_MAX_MM_DESIGNS]; + T1_DesignMap design_map[T1_MAX_MM_AXIS]; + + FT_Fixed* weight_vector; + FT_Fixed* default_weight_vector; + + T1_FontInfo* font_infos[T1_MAX_MM_DESIGNS + 1]; + T1_Private* privates [T1_MAX_MM_DESIGNS + 1]; + + FT_ULong blend_bitflags; + +} T1_Blend; + + +typedef struct CID_FontDict_ +{ + T1_Private private_dict; + + FT_UInt len_buildchar; + FT_Fixed forcebold_threshold; + FT_Pos stroke_width; + FT_Fixed expansion_factor; + + FT_Byte paint_type; + FT_Byte font_type; + FT_Matrix font_matrix; + + FT_UInt num_subrs; + FT_ULong subrmap_offset; + FT_Int sd_bytes; + +} CID_FontDict; + + +typedef struct CID_Info_ +{ + FT_String* cid_font_name; + FT_Fixed cid_version; + FT_Int cid_font_type; + + FT_String* registry; + FT_String* ordering; + FT_Int supplement; + + T1_FontInfo font_info; + FT_BBox font_bbox; + FT_ULong uid_base; + + FT_Int num_xuid; + FT_ULong xuid[16]; + + + FT_ULong cidmap_offset; + FT_Int fd_bytes; + FT_Int gd_bytes; + FT_ULong cid_count; + + FT_Int num_dicts; + CID_FontDict* font_dicts; + + FT_ULong data_offset; + +} CID_Info; + + +#endif /* T1TABLES_H */ + + +/* END */ diff --git a/Projects/Android/jni/rtcw/src/ft2/ttcmap.c b/Projects/Android/jni/rtcw/src/ft2/ttcmap.c new file mode 100644 index 0000000..4eb1a77 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/ft2/ttcmap.c @@ -0,0 +1,550 @@ +/***************************************************************************/ +/* */ +/* ttcmap.c */ +/* */ +/* TrueType character mapping table (cmap) support (body). */ +/* */ +/* Copyright 1996-2000 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#include "ftdebug.h" +#include "tterrors.h" + + +#include "ttload.h" +#include "ttcmap.h" + + +/*************************************************************************/ +/* */ +/* The macro FT_COMPONENT is used in trace mode. It is an implicit */ +/* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */ +/* messages during execution. */ +/* */ +#undef FT_COMPONENT +#define FT_COMPONENT trace_ttcmap + + +static FT_UInt code_to_index0( TT_CMapTable* charmap, + FT_ULong char_code ); +static FT_UInt code_to_index2( TT_CMapTable* charmap, + FT_ULong char_code ); +static FT_UInt code_to_index4( TT_CMapTable* charmap, + FT_ULong char_code ); +static FT_UInt code_to_index6( TT_CMapTable* charmap, + FT_ULong char_code ); + + +/*************************************************************************/ +/* */ +/* */ +/* TT_CharMap_Load */ +/* */ +/* */ +/* Loads a given TrueType character map into memory. */ +/* */ +/* */ +/* face :: A handle to the parent face object. */ +/* stream :: A handle to the current stream object. */ +/* */ +/* */ +/* table :: A pointer to a cmap object. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +/* */ +/* The function assumes that the stream is already in use (i.e., */ +/* opened). In case of error, all partially allocated tables are */ +/* released. */ +/* */ +LOCAL_FUNC +FT_Error TT_CharMap_Load( TT_Face face, + TT_CMapTable* cmap, + FT_Stream stream ) { + FT_Error error; + FT_Memory memory; + FT_UShort num_SH, num_Seg, i; + + FT_UShort u, l; + + TT_CMap0* cmap0; + TT_CMap2* cmap2; + TT_CMap4* cmap4; + TT_CMap6* cmap6; + + TT_CMap2SubHeader* cmap2sub; + TT_CMap4Segment* segments; + + + if ( cmap->loaded ) { + return TT_Err_Ok; + } + + memory = stream->memory; + + if ( FILE_Seek( cmap->offset ) ) { + return error; + } + + switch ( cmap->format ) + { + case 0: + cmap0 = &cmap->c.cmap0; + + if ( ALLOC( cmap0->glyphIdArray, 256L ) || + FILE_Read( cmap0->glyphIdArray, 256L ) ) { + goto Fail; + } + + cmap->get_index = code_to_index0; + break; + + case 2: + num_SH = 0; + cmap2 = &cmap->c.cmap2; + + /* allocate subheader keys */ + + if ( ALLOC_ARRAY( cmap2->subHeaderKeys, 256, FT_UShort ) || + ACCESS_Frame( 512L ) ) { + goto Fail; + } + + for ( i = 0; i < 256; i++ ) + { + u = GET_UShort() / 8; + cmap2->subHeaderKeys[i] = u; + + if ( num_SH < u ) { + num_SH = u; + } + } + + FORGET_Frame(); + + /* load subheaders */ + + cmap2->numGlyphId = l = + ( ( cmap->length - 2L * ( 256 + 3 ) - num_SH * 8L ) & 0xFFFF ) / 2; + + if ( ALLOC_ARRAY( cmap2->subHeaders, + num_SH + 1, + TT_CMap2SubHeader ) || + ACCESS_Frame( ( num_SH + 1 ) * 8L ) ) { + goto Fail; + } + + cmap2sub = cmap2->subHeaders; + + for ( i = 0; i <= num_SH; i++ ) + { + cmap2sub->firstCode = GET_UShort(); + cmap2sub->entryCount = GET_UShort(); + cmap2sub->idDelta = GET_Short(); + /* we apply the location offset immediately */ + cmap2sub->idRangeOffset = GET_UShort() - ( num_SH - i ) * 8 - 2; + + cmap2sub++; + } + + FORGET_Frame(); + + /* load glyph IDs */ + + if ( ALLOC_ARRAY( cmap2->glyphIdArray, l, FT_UShort ) || + ACCESS_Frame( l * 2L ) ) { + goto Fail; + } + + for ( i = 0; i < l; i++ ) + cmap2->glyphIdArray[i] = GET_UShort(); + + FORGET_Frame(); + + cmap->get_index = code_to_index2; + break; + + case 4: + cmap4 = &cmap->c.cmap4; + + /* load header */ + + if ( ACCESS_Frame( 8L ) ) { + goto Fail; + } + + cmap4->segCountX2 = GET_UShort(); + cmap4->searchRange = GET_UShort(); + cmap4->entrySelector = GET_UShort(); + cmap4->rangeShift = GET_UShort(); + + num_Seg = cmap4->segCountX2 / 2; + + FORGET_Frame(); + + /* load segments */ + + if ( ALLOC_ARRAY( cmap4->segments, + num_Seg, + TT_CMap4Segment ) || + ACCESS_Frame( ( num_Seg * 4 + 1 ) * 2L ) ) { + goto Fail; + } + + segments = cmap4->segments; + + for ( i = 0; i < num_Seg; i++ ) + segments[i].endCount = GET_UShort(); + + (void)GET_UShort(); + + for ( i = 0; i < num_Seg; i++ ) + segments[i].startCount = GET_UShort(); + + for ( i = 0; i < num_Seg; i++ ) + segments[i].idDelta = GET_Short(); + + for ( i = 0; i < num_Seg; i++ ) + segments[i].idRangeOffset = GET_UShort(); + + FORGET_Frame(); + + cmap4->numGlyphId = l = + ( ( cmap->length - ( 16L + 8L * num_Seg ) ) & 0xFFFF ) / 2; + + /* load IDs */ + + if ( ALLOC_ARRAY( cmap4->glyphIdArray, l, FT_UShort ) || + ACCESS_Frame( l * 2L ) ) { + goto Fail; + } + + for ( i = 0; i < l; i++ ) + cmap4->glyphIdArray[i] = GET_UShort(); + + FORGET_Frame(); + + cmap->get_index = code_to_index4; + + cmap4->last_segment = cmap4->segments; + break; + + case 6: + cmap6 = &cmap->c.cmap6; + + if ( ACCESS_Frame( 4L ) ) { + goto Fail; + } + + cmap6->firstCode = GET_UShort(); + cmap6->entryCount = GET_UShort(); + + FORGET_Frame(); + + l = cmap6->entryCount; + + if ( ALLOC_ARRAY( cmap6->glyphIdArray, + cmap6->entryCount, + FT_Short ) || + ACCESS_Frame( l * 2L ) ) { + goto Fail; + } + + for ( i = 0; i < l; i++ ) + cmap6->glyphIdArray[i] = GET_UShort(); + + FORGET_Frame(); + cmap->get_index = code_to_index6; + break; + + default: /* corrupt character mapping table */ + return TT_Err_Invalid_CharMap_Format; + + } + + return TT_Err_Ok; + +Fail: + TT_CharMap_Free( face, cmap ); + return error; +} + + +/*************************************************************************/ +/* */ +/* */ +/* TT_CharMap_Free */ +/* */ +/* */ +/* Destroys a character mapping table. */ +/* */ +/* */ +/* face :: A handle to the parent face object. */ +/* cmap :: A handle to a cmap object. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +LOCAL_FUNC +FT_Error TT_CharMap_Free( TT_Face face, + TT_CMapTable* cmap ) { + FT_Memory memory; + + + if ( !cmap ) { + return TT_Err_Ok; + } + + memory = face->root.driver->root.memory; + + switch ( cmap->format ) + { + case 0: + FREE( cmap->c.cmap0.glyphIdArray ); + break; + + case 2: + FREE( cmap->c.cmap2.subHeaderKeys ); + FREE( cmap->c.cmap2.subHeaders ); + FREE( cmap->c.cmap2.glyphIdArray ); + break; + + case 4: + FREE( cmap->c.cmap4.segments ); + FREE( cmap->c.cmap4.glyphIdArray ); + cmap->c.cmap4.segCountX2 = 0; + break; + + case 6: + FREE( cmap->c.cmap6.glyphIdArray ); + cmap->c.cmap6.entryCount = 0; + break; + + default: + /* invalid table format, do nothing */ + ; + } + + cmap->loaded = FALSE; + return TT_Err_Ok; +} + + +/*************************************************************************/ +/* */ +/* */ +/* code_to_index0 */ +/* */ +/* */ +/* Converts the character code into a glyph index. Uses format 0. */ +/* `charCode' must be in the range 0x00-0xFF (otherwise 0 is */ +/* returned). */ +/* */ +/* */ +/* charCode :: The wanted character code. */ +/* cmap0 :: A pointer to a cmap table in format 0. */ +/* */ +/* */ +/* Glyph index into the glyphs array. 0 if the glyph does not exist. */ +/* */ +static +FT_UInt code_to_index0( TT_CMapTable* cmap, + FT_ULong charCode ) { + TT_CMap0* cmap0 = &cmap->c.cmap0; + + + return ( charCode <= 0xFF ? cmap0->glyphIdArray[charCode] : 0 ); +} + + +/*************************************************************************/ +/* */ +/* */ +/* code_to_index2 */ +/* */ +/* */ +/* Converts the character code into a glyph index. Uses format 2. */ +/* */ +/* */ +/* charCode :: The wanted character code. */ +/* cmap2 :: A pointer to a cmap table in format 2. */ +/* */ +/* */ +/* Glyph index into the glyphs array. 0 if the glyph does not exist. */ +/* */ +static +FT_UInt code_to_index2( TT_CMapTable* cmap, + FT_ULong charCode ) { + FT_UInt result, index1, offset; + FT_UInt char_lo; + FT_ULong char_hi; + TT_CMap2SubHeader* sh2; + TT_CMap2* cmap2; + + + cmap2 = &cmap->c.cmap2; + result = 0; + char_lo = (FT_UInt)( charCode & 0xFF ); + char_hi = charCode >> 8; + + if ( char_hi == 0 ) { + /* an 8-bit character code -- we use the subHeader 0 in this case */ + /* to test whether the character code is in the charmap */ + if ( cmap2->subHeaderKeys[char_lo] == 0 ) { + result = cmap2->glyphIdArray[char_lo]; + } + } else + { + /* a 16-bit character code */ + index1 = cmap2->subHeaderKeys[char_hi & 0xFF]; + if ( index1 ) { + sh2 = cmap2->subHeaders + index1; + char_lo -= sh2->firstCode; + + if ( char_lo < sh2->entryCount ) { + offset = sh2->idRangeOffset / 2 + char_lo; + if ( offset < cmap2->numGlyphId ) { + result = cmap2->glyphIdArray[offset]; + if ( result ) { + result = ( result + sh2->idDelta ) & 0xFFFF; + } + } + } + } + } + + return result; +} + + +/*************************************************************************/ +/* */ +/* */ +/* code_to_index4 */ +/* */ +/* */ +/* Converts the character code into a glyph index. Uses format 4. */ +/* */ +/* */ +/* charCode :: The wanted character code. */ +/* cmap4 :: A pointer to a cmap table in format 4. */ +/* */ +/* */ +/* Glyph index into the glyphs array. 0 if the glyph does not exist. */ +/* */ +static +FT_UInt code_to_index4( TT_CMapTable* cmap, + FT_ULong charCode ) { + FT_UInt result, index1, segCount; + TT_CMap4* cmap4; + TT_CMap4Segment *seg4, *limit; + + + cmap4 = &cmap->c.cmap4; + result = 0; + segCount = cmap4->segCountX2 / 2; + seg4 = cmap4->segments; + limit = seg4 + segCount; + + /* check against the last segment */ + seg4 = cmap4->last_segment; + + /* the following is equivalent to performing two tests, as in */ + /* */ + /* if ( charCode >= seg4->startCount && charCode <= seg4->endCount ) */ + /* */ + /* Yes, that's a bit strange, but it's faster, and the idea behind */ + /* the cache is to significantly speed up charcode to glyph index */ + /* conversion. */ + + if ( (FT_ULong)( charCode - seg4->startCount ) < + (FT_ULong)( seg4->endCount - seg4->startCount ) ) { + goto Found; + } + + for ( seg4 = cmap4->segments; seg4 < limit; seg4++ ) + { + /* the ranges are sorted in increasing order. If we are out of */ + /* the range here, the char code isn't in the charmap, so exit. */ + + if ( charCode > seg4->endCount ) { + continue; + } + + if ( charCode >= seg4->startCount ) { + goto Found; + } + } + return 0; + +Found: + cmap4->last_segment = seg4; + + /* if the idRangeOffset is 0, we can compute the glyph index */ + /* directly */ + + if ( seg4->idRangeOffset == 0 ) { + result = ( charCode + seg4->idDelta ) & 0xFFFF; + } else + { + /* otherwise, we must use the glyphIdArray to do it */ + index1 = seg4->idRangeOffset / 2 + + ( charCode - seg4->startCount ) + + ( seg4 - cmap4->segments ) + - segCount; + + if ( index1 < cmap4->numGlyphId && + cmap4->glyphIdArray[index1] != 0 ) { + result = ( cmap4->glyphIdArray[index1] + seg4->idDelta ) & 0xFFFF; + } + } + + return result; +} + + +/*************************************************************************/ +/* */ +/* */ +/* code_to_index6 */ +/* */ +/* */ +/* Converts the character code into a glyph index. Uses format 6. */ +/* */ +/* */ +/* charCode :: The wanted character code. */ +/* cmap6 :: A pointer to a cmap table in format 6. */ +/* */ +/* */ +/* Glyph index into the glyphs array. 0 if the glyph does not exist. */ +/* */ +static +FT_UInt code_to_index6( TT_CMapTable* cmap, + FT_ULong charCode ) { + TT_CMap6* cmap6; + FT_UInt result = 0; + + + cmap6 = &cmap->c.cmap6; + result = 0; + charCode -= cmap6->firstCode; + + if ( charCode < cmap6->entryCount ) { + result = cmap6->glyphIdArray[charCode]; + } + + return result; +} + + +/* END */ diff --git a/Projects/Android/jni/rtcw/src/ft2/ttcmap.h b/Projects/Android/jni/rtcw/src/ft2/ttcmap.h new file mode 100644 index 0000000..2c22cba --- /dev/null +++ b/Projects/Android/jni/rtcw/src/ft2/ttcmap.h @@ -0,0 +1,45 @@ +/***************************************************************************/ +/* */ +/* ttcmap.h */ +/* */ +/* TrueType character mapping table (cmap) support (specification). */ +/* */ +/* Copyright 1996-2000 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef TTCMAP_H +#define TTCMAP_H + +#include "tttypes.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +LOCAL_DEF +FT_Error TT_CharMap_Load( TT_Face face, + TT_CMapTable* cmap, + FT_Stream input ); + +LOCAL_DEF +FT_Error TT_CharMap_Free( TT_Face face, + TT_CMapTable* cmap ); + +#ifdef __cplusplus +} +#endif + +#endif /* TTCMAP_H */ + + +/* END */ diff --git a/Projects/Android/jni/rtcw/src/ft2/ttdriver.c b/Projects/Android/jni/rtcw/src/ft2/ttdriver.c new file mode 100644 index 0000000..cbe1502 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/ft2/ttdriver.c @@ -0,0 +1,501 @@ +/***************************************************************************/ +/* */ +/* ttdriver.c */ +/* */ +/* TrueType font driver implementation (body). */ +/* */ +/* Copyright 1996-2000 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#include "ftdebug.h" +#include "ftstream.h" +#include "sfnt.h" +#include "ttnameid.h" + + +#include "ttdriver.h" +#include "ttgload.h" + + +/*************************************************************************/ +/* */ +/* The macro FT_COMPONENT is used in trace mode. It is an implicit */ +/* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */ +/* messages during execution. */ +/* */ +#undef FT_COMPONENT +#define FT_COMPONENT trace_ttdriver + + +/*************************************************************************/ +/*************************************************************************/ +/*************************************************************************/ +/**** ****/ +/**** ****/ +/**** F A C E S ****/ +/**** ****/ +/**** ****/ +/*************************************************************************/ +/*************************************************************************/ +/*************************************************************************/ + + +#undef PAIR_TAG +#define PAIR_TAG( left, right ) ( ( (FT_ULong)left << 16 ) | \ + (FT_ULong)right ) + + +/*************************************************************************/ +/* */ +/* */ +/* Get_Kerning */ +/* */ +/* */ +/* A driver method used to return the kerning vector between two */ +/* glyphs of the same face. */ +/* */ +/* */ +/* face :: A handle to the source face object. */ +/* */ +/* left_glyph :: The index of the left glyph in the kern pair. */ +/* */ +/* right_glyph :: The index of the right glyph in the kern pair. */ +/* */ +/* */ +/* kerning :: The kerning vector. This is in font units for */ +/* scalable formats, and in pixels for fixed-sizes */ +/* formats. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +/* */ +/* Only horizontal layouts (left-to-right & right-to-left) are */ +/* supported by this function. Other layouts, or more sophisticated */ +/* kernings, are out of scope of this method (the basic driver */ +/* interface is meant to be simple). */ +/* */ +/* They can be implemented by format-specific interfaces. */ +/* */ +static +FT_Error Get_Kerning( TT_Face face, + FT_UInt left_glyph, + FT_UInt right_glyph, + FT_Vector* kerning ) { + TT_Kern_0_Pair* pair; + + + if ( !face ) { + return TT_Err_Invalid_Face_Handle; + } + + kerning->x = 0; + kerning->y = 0; + + if ( face->kern_pairs ) { + /* there are some kerning pairs in this font file! */ + FT_ULong search_tag = PAIR_TAG( left_glyph, right_glyph ); + FT_Long left, right; + + + left = 0; + right = face->num_kern_pairs - 1; + + while ( left <= right ) + { + FT_Int middle = left + ( ( right - left ) >> 1 ); + FT_ULong cur_pair; + + + pair = face->kern_pairs + middle; + cur_pair = PAIR_TAG( pair->left, pair->right ); + + if ( cur_pair == search_tag ) { + goto Found; + } + + if ( cur_pair < search_tag ) { + left = middle + 1; + } else { + right = middle - 1; + } + } + } + +Exit: + return TT_Err_Ok; + +Found: + kerning->x = pair->value; + goto Exit; +} + + +#undef PAIR_TAG + + +/*************************************************************************/ +/*************************************************************************/ +/*************************************************************************/ +/**** ****/ +/**** ****/ +/**** S I Z E S ****/ +/**** ****/ +/**** ****/ +/*************************************************************************/ +/*************************************************************************/ +/*************************************************************************/ + + +/*************************************************************************/ +/* */ +/* */ +/* Set_Char_Sizes */ +/* */ +/* */ +/* A driver method used to reset a size's character sizes (horizontal */ +/* and vertical) expressed in fractional points. */ +/* */ +/* */ +/* char_width :: The character width expressed in 26.6 */ +/* fractional points. */ +/* */ +/* char_height :: The character height expressed in 26.6 */ +/* fractional points. */ +/* */ +/* horz_resolution :: The horizontal resolution of the output device. */ +/* */ +/* vert_resolution :: The vertical resolution of the output device. */ +/* */ +/* */ +/* size :: A handle to the target size object. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +static +FT_Error Set_Char_Sizes( TT_Size size, + FT_F26Dot6 char_width, + FT_F26Dot6 char_height, + FT_UInt horz_resolution, + FT_UInt vert_resolution ) { + FT_Size_Metrics* metrics = &size->root.metrics; + TT_Face face = (TT_Face)size->root.face; + FT_Long dim_x, dim_y; + + + /* This bit flag, when set, indicates that the pixel size must be */ + /* truncated to an integer. Nearly all TrueType fonts have this */ + /* bit set, as hinting won't work really well otherwise. */ + /* */ + /* However, for those rare fonts who do not set it, we override */ + /* the default computations performed by the base layer. I */ + /* really don't know whether this is useful, but hey, that's the */ + /* spec :-) */ + /* */ + if ( ( face->header.Flags & 8 ) == 0 ) { + /* Compute pixel sizes in 26.6 units */ + dim_x = ( char_width * horz_resolution ) / 72; + dim_y = ( char_height * vert_resolution ) / 72; + + metrics->x_scale = FT_DivFix( dim_x, face->root.units_per_EM ); + metrics->y_scale = FT_DivFix( dim_y, face->root.units_per_EM ); + + metrics->x_ppem = (FT_UShort)( dim_x >> 6 ); + metrics->y_ppem = (FT_UShort)( dim_y >> 6 ); + } + + size->ttmetrics.valid = FALSE; + + return TT_Reset_Size( size ); +} + + +/*************************************************************************/ +/* */ +/* */ +/* Set_Pixel_Sizes */ +/* */ +/* */ +/* A driver method used to reset a size's character sizes (horizontal */ +/* and vertical) expressed in integer pixels. */ +/* */ +/* */ +/* pixel_width :: The character width expressed in integer pixels. */ +/* */ +/* pixel_height :: The character height expressed in integer pixels. */ +/* */ +/* */ +/* size :: A handle to the target size object. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +static +FT_Error Set_Pixel_Sizes( TT_Size size, + FT_UInt pixel_width, + FT_UInt pixel_height ) { + FT_UNUSED( pixel_width ); + FT_UNUSED( pixel_height ); + + /* many things have been pre-computed by the base layer */ + + size->ttmetrics.valid = FALSE; + + return TT_Reset_Size( size ); +} + + +/*************************************************************************/ +/* */ +/* */ +/* Load_Glyph */ +/* */ +/* */ +/* A driver method used to load a glyph within a given glyph slot. */ +/* */ +/* */ +/* slot :: A handle to the target slot object where the glyph */ +/* will be loaded. */ +/* */ +/* size :: A handle to the source face size at which the glyph */ +/* must be scaled, loaded, etc. */ +/* */ +/* glyph_index :: The index of the glyph in the font file. */ +/* */ +/* load_flags :: A flag indicating what to load for this glyph. The */ +/* FTLOAD_??? constants can be used to control the */ +/* glyph loading process (e.g., whether the outline */ +/* should be scaled, whether to load bitmaps or not, */ +/* whether to hint the outline, etc). */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +static +FT_Error Load_Glyph( TT_GlyphSlot slot, + TT_Size size, + FT_UShort glyph_index, + FT_UInt load_flags ) { + FT_Error error; + + + if ( !slot ) { + return TT_Err_Invalid_Glyph_Handle; + } + + /* check whether we want a scaled outline or bitmap */ + if ( !size ) { + load_flags |= FT_LOAD_NO_SCALE | FT_LOAD_NO_HINTING; + } + + if ( load_flags & FT_LOAD_NO_SCALE ) { + size = NULL; + } + + /* reset the size object if necessary */ + if ( size ) { + /* these two object must have the same parent */ + if ( size->root.face != slot->face ) { + return TT_Err_Invalid_Face_Handle; + } + + if ( !size->ttmetrics.valid ) { + if ( FT_SET_ERROR( TT_Reset_Size( size ) ) ) { + return error; + } + } + } + + /* now load the glyph outline if necessary */ + error = TT_Load_Glyph( size, slot, glyph_index, load_flags ); + + /* force drop-out mode to 2 - irrelevant now */ + /* slot->outline.dropout_mode = 2; */ + + return error; +} + + +/*************************************************************************/ +/*************************************************************************/ +/*************************************************************************/ +/**** ****/ +/**** ****/ +/**** C H A R A C T E R M A P P I N G S ****/ +/**** ****/ +/**** ****/ +/*************************************************************************/ +/*************************************************************************/ +/*************************************************************************/ + +/*************************************************************************/ +/* */ +/* */ +/* Get_Char_Index */ +/* */ +/* */ +/* Uses a charmap to return a given character code's glyph index. */ +/* */ +/* */ +/* charmap :: A handle to the source charmap object. */ +/* charcode :: The character code. */ +/* */ +/* */ +/* Glyph index. 0 means `undefined character code'. */ +/* */ +static +FT_UInt Get_Char_Index( TT_CharMap charmap, + FT_Long charcode ) { + FT_Error error; + TT_Face face; + TT_CMapTable* cmap; + + + cmap = &charmap->cmap; + face = (TT_Face)charmap->root.face; + + /* Load table if needed */ + if ( !cmap->loaded ) { + SFNT_Interface* sfnt = (SFNT_Interface*)face->sfnt; + + + error = sfnt->load_charmap( face, cmap, face->root.stream ); + if ( error ) { + return 0; + } + + cmap->loaded = TRUE; + } + + if ( cmap->get_index ) { + return cmap->get_index( cmap, charcode ); + } else { + return 0; + } +} + + +/*************************************************************************/ +/*************************************************************************/ +/*************************************************************************/ +/**** ****/ +/**** ****/ +/**** D R I V E R I N T E R F A C E ****/ +/**** ****/ +/**** ****/ +/*************************************************************************/ +/*************************************************************************/ +/*************************************************************************/ + + +static +FT_Module_Interface tt_get_interface( TT_Driver driver, + const char* interface ) { + FT_Module sfntd = FT_Get_Module( driver->root.root.library, + "sfnt" ); + SFNT_Interface* sfnt; + + + /* only return the default interface from the SFNT module */ + if ( sfntd ) { + sfnt = ( SFNT_Interface* )( sfntd->clazz->module_interface ); + if ( sfnt ) { + return sfnt->get_interface( FT_MODULE( driver ), interface ); + } + } + + return 0; +} + + +/* The FT_DriverInterface structure is defined in ftdriver.h. */ + +const FT_Driver_Class tt_driver_class = +{ + { + ft_module_font_driver | + ft_module_driver_scalable | +#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER + ft_module_driver_has_hinter, +#else + 0, +#endif + + sizeof( TT_DriverRec ), + + "truetype", /* driver name */ + 0x10000L, /* driver version == 1.0 */ + 0x20000L, /* driver requires FreeType 2.0 or above */ + + (void*)0, /* driver specific interface */ + + (FT_Module_Constructor)TT_Init_Driver, + (FT_Module_Destructor) TT_Done_Driver, + (FT_Module_Requester) tt_get_interface, + }, + + sizeof( TT_FaceRec ), + sizeof( TT_SizeRec ), + sizeof( FT_GlyphSlotRec ), + + + (FTDriver_initFace) TT_Init_Face, + (FTDriver_doneFace) TT_Done_Face, + (FTDriver_initSize) TT_Init_Size, + (FTDriver_doneSize) TT_Done_Size, + (FTDriver_initGlyphSlot)0, + (FTDriver_doneGlyphSlot)0, + + (FTDriver_setCharSizes) Set_Char_Sizes, + (FTDriver_setPixelSizes)Set_Pixel_Sizes, + (FTDriver_loadGlyph) Load_Glyph, + (FTDriver_getCharIndex) Get_Char_Index, + + (FTDriver_getKerning) Get_Kerning, + (FTDriver_attachFile) 0, + (FTDriver_getAdvances) 0 +}; + + +#ifdef FT_CONFIG_OPTION_DYNAMIC_DRIVERS + + +/*************************************************************************/ +/* */ +/* */ +/* getDriverInterface */ +/* */ +/* */ +/* This function is used when compiling the TrueType driver as a */ +/* shared library (`.DLL' or `.so'). It will be used by the */ +/* high-level library of FreeType to retrieve the address of the */ +/* driver's generic interface. */ +/* */ +/* It shouldn't be implemented in a static build, as each driver must */ +/* have the same function as an exported entry point. */ +/* */ +/* */ +/* The address of the TrueType's driver generic interface. The */ +/* format-specific interface can then be retrieved through the method */ +/* interface->get_format_interface. */ +/* */ +EXPORT_FUNC( const FT_Driver_Class* ) getDriverClass( void ) +{ + return &tt_driver_class; +} + + +#endif /* CONFIG_OPTION_DYNAMIC_DRIVERS */ + + +/* END */ diff --git a/Projects/Android/jni/rtcw/src/ft2/ttdriver.h b/Projects/Android/jni/rtcw/src/ft2/ttdriver.h new file mode 100644 index 0000000..27e2a05 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/ft2/ttdriver.h @@ -0,0 +1,31 @@ +/***************************************************************************/ +/* */ +/* ttdriver.h */ +/* */ +/* High-level TrueType driver interface (specification). */ +/* */ +/* Copyright 1996-2000 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef TTDRIVER_H +#define TTDRIVER_H + +#include "ftdriver.h" + + +FT_EXPORT_VAR( const FT_Driver_Class ) tt_driver_class; + + +#endif /* TTDRIVER_H */ + + +/* END */ diff --git a/Projects/Android/jni/rtcw/src/ft2/tterrors.h b/Projects/Android/jni/rtcw/src/ft2/tterrors.h new file mode 100644 index 0000000..d922944 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/ft2/tterrors.h @@ -0,0 +1,121 @@ +/***************************************************************************/ +/* */ +/* tterrors.h */ +/* */ +/* TrueType error ID definitions (specification only). */ +/* */ +/* Copyright 1996-2000 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef TTERRORS_H +#define TTERRORS_H + + +/*************************************************************************/ +/* */ +/* Error codes declaration */ +/* */ +/* The error codes are grouped in `classes' used to indicate the `level' */ +/* at which the error happened. The class is given by an error code's */ +/* high byte. */ +/* */ +/*************************************************************************/ + + +/* Success is always 0. */ + +#define TT_Err_Ok FT_Err_Ok + +/* High level API errors. */ + +#define TT_Err_Invalid_File_Format FT_Err_Invalid_File_Format +#define TT_Err_Invalid_Argument FT_Err_Invalid_Argument +#define TT_Err_Invalid_Driver_Handle FT_Err_Invalid_Driver_Handle +#define TT_Err_Invalid_Face_Handle FT_Err_Invalid_Face_Handle +#define TT_Err_Invalid_Instance_Handle FT_Err_Invalid_Size_Handle +#define TT_Err_Invalid_Glyph_Handle FT_Err_Invalid_Slot_Handle +#define TT_Err_Invalid_CharMap_Handle FT_Err_Invalid_CharMap_Handle +#define TT_Err_Invalid_Glyph_Index FT_Err_Invalid_Glyph_Index + +#define TT_Err_Unimplemented_Feature FT_Err_Unimplemented_Feature + +#define TT_Err_Invalid_Engine FT_Err_Invalid_Driver_Handle + +/* Internal errors. */ + +#define TT_Err_Out_Of_Memory FT_Err_Out_Of_Memory +#define TT_Err_Unlisted_Object FT_Err_Unlisted_Object + +/* General glyph outline errors. */ + +#define TT_Err_Too_Many_Ins FT_Err_Too_Many_Hints +#define TT_Err_Invalid_Composite FT_Err_Invalid_Composite + +/* Bytecode interpreter error codes. */ + +/* These error codes are produced by the TrueType */ +/* bytecode interpreter. They usually indicate a */ +/* broken font file, a broken glyph within a font */ +/* file, or a bug in the interpreter! */ + +#define TT_Err_Invalid_Opcode 0x400 +#define TT_Err_Too_Few_Arguments 0x401 +#define TT_Err_Stack_Overflow 0x402 +#define TT_Err_Code_Overflow 0x403 +#define TT_Err_Bad_Argument 0x404 +#define TT_Err_Divide_By_Zero 0x405 +#define TT_Err_Storage_Overflow 0x406 +#define TT_Err_Cvt_Overflow 0x407 +#define TT_Err_Invalid_Reference 0x408 +#define TT_Err_Invalid_Distance 0x409 +#define TT_Err_Interpolate_Twilight 0x40A +#define TT_Err_Debug_OpCode 0x40B +#define TT_Err_ENDF_In_Exec_Stream 0x40C +#define TT_Err_Out_Of_CodeRanges 0x40D +#define TT_Err_Nested_DEFS 0x40E +#define TT_Err_Invalid_CodeRange 0x40F +#define TT_Err_Invalid_Displacement 0x410 +#define TT_Err_Execution_Too_Long 0x411 +#define TT_Err_Too_Many_Function_Defs 0x412 +#define TT_Err_Too_Many_Instruction_Defs 0x413 + +/* Other TrueType specific error codes. */ + +#define TT_Err_Table_Missing 0x420 +#define TT_Err_Too_Many_Extensions 0x421 +#define TT_Err_Extensions_Unsupported 0x422 +#define TT_Err_Invalid_Extension_Id 0x423 + +#define TT_Err_No_Vertical_Data 0x424 + +#define TT_Err_Max_Profile_Missing 0x430 +#define TT_Err_Header_Table_Missing 0x431 +#define TT_Err_Horiz_Header_Missing 0x432 +#define TT_Err_Locations_Missing 0x433 +#define TT_Err_Name_Table_Missing 0x434 +#define TT_Err_CMap_Table_Missing 0x435 +#define TT_Err_Hmtx_Table_Missing 0x436 +#define TT_Err_OS2_Table_Missing 0x437 +#define TT_Err_Post_Table_Missing 0x438 + +#define TT_Err_Invalid_Horiz_Metrics 0x440 +#define TT_Err_Invalid_CharMap_Format 0x441 +#define TT_Err_Invalid_PPem 0x442 +#define TT_Err_Invalid_Vert_Metrics 0x443 + +#define TT_Err_Could_Not_Find_Context 0x450 + + +#endif /* TTERRORS_H */ + + +/* END */ diff --git a/Projects/Android/jni/rtcw/src/ft2/ttgload.c b/Projects/Android/jni/rtcw/src/ft2/ttgload.c new file mode 100644 index 0000000..d7bce20 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/ft2/ttgload.c @@ -0,0 +1,1432 @@ +/***************************************************************************/ +/* */ +/* ttgload.c */ +/* */ +/* TrueType Glyph Loader (body). */ +/* */ +/* Copyright 1996-2000 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#include "ftdebug.h" +#include "ftcalc.h" +#include "ftstream.h" +#include "sfnt.h" +#include "tttags.h" +#include "ftoutln.h" + + +#include "ttgload.h" + + +/*************************************************************************/ +/* */ +/* The macro FT_COMPONENT is used in trace mode. It is an implicit */ +/* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */ +/* messages during execution. */ +/* */ +#undef FT_COMPONENT +#define FT_COMPONENT trace_ttgload + + +/*************************************************************************/ +/* */ +/* Composite font flags. */ +/* */ +#define ARGS_ARE_WORDS 0x001 +#define ARGS_ARE_XY_VALUES 0x002 +#define ROUND_XY_TO_GRID 0x004 +#define WE_HAVE_A_SCALE 0x008 +/* reserved 0x010 */ +#define MORE_COMPONENTS 0x020 +#define WE_HAVE_AN_XY_SCALE 0x040 +#define WE_HAVE_A_2X2 0x080 +#define WE_HAVE_INSTR 0x100 +#define USE_MY_METRICS 0x200 + + + +/*************************************************************************/ +/* */ +/* */ +/* TT_Get_Metrics */ +/* */ +/* */ +/* Returns the horizontal or vertical metrics in font units for a */ +/* given glyph. The metrics are the left side bearing (resp. top */ +/* side bearing) and advance width (resp. advance height). */ +/* */ +/* */ +/* header :: A pointer to either the horizontal or vertical metrics */ +/* structure. */ +/* */ +/* index :: The glyph index. */ +/* */ +/* */ +/* bearing :: The bearing, either left side or top side. */ +/* */ +/* advance :: The advance width resp. advance height. */ +/* */ +/* */ +/* This function will much probably move to another component in the */ +/* near future, but I haven't decided which yet. */ +/* */ +LOCAL_FUNC +void TT_Get_Metrics( TT_HoriHeader* header, + FT_UInt index, + FT_Short* bearing, + FT_UShort* advance ) { + TT_LongMetrics* longs_m; + FT_UShort k = header->number_Of_HMetrics; + + + if ( index < k ) { + longs_m = (TT_LongMetrics*)header->long_metrics + index; + *bearing = longs_m->bearing; + *advance = longs_m->advance; + } else + { + *bearing = ( (TT_ShortMetrics*)header->short_metrics )[index - k]; + *advance = ( (TT_LongMetrics*)header->long_metrics )[k - 1].advance; + } +} + + +/*************************************************************************/ +/* */ +/* Returns the horizontal metrics in font units for a given glyph. If */ +/* `check' is true, take care of monospaced fonts by returning the */ +/* advance width maximum. */ +/* */ +static +void Get_HMetrics( TT_Face face, + FT_UInt index, + FT_Bool check, + FT_Short* lsb, + FT_UShort* aw ) { + TT_Get_Metrics( &face->horizontal, index, lsb, aw ); + + if ( check && face->postscript.isFixedPitch ) { + *aw = face->horizontal.advance_Width_Max; + } +} + + +/*************************************************************************/ +/* */ +/* Returns the advance width table for a given pixel size if it is */ +/* found in the font's `hdmx' table (if any). */ +/* */ +static +FT_Byte* Get_Advance_Widths( TT_Face face, + FT_UShort ppem ) { + FT_UShort n; + + for ( n = 0; n < face->hdmx.num_records; n++ ) + if ( face->hdmx.records[n].ppem == ppem ) { + return face->hdmx.records[n].widths; + } + + return NULL; +} + + +#define cur_to_org( n, zone ) \ + MEM_Copy( ( zone )->org, ( zone )->cur, n * sizeof( FT_Vector ) ) + +#define org_to_cur( n, zone ) \ + MEM_Copy( ( zone )->cur, ( zone )->org, n * sizeof( FT_Vector ) ) + + +/*************************************************************************/ +/* */ +/* Translates an array of coordinates. */ +/* */ +static +void translate_array( FT_UInt n, + FT_Vector* coords, + FT_Pos delta_x, + FT_Pos delta_y ) { + FT_UInt k; + + + if ( delta_x ) { + for ( k = 0; k < n; k++ ) + coords[k].x += delta_x; + } + + if ( delta_y ) { + for ( k = 0; k < n; k++ ) + coords[k].y += delta_y; + } +} + + +static +void tt_prepare_zone( TT_GlyphZone* zone, + FT_GlyphLoad* load, + FT_UInt start_point, + FT_UInt start_contour ) { + zone->n_points = load->outline.n_points - start_point; + zone->n_contours = load->outline.n_contours - start_contour; + zone->org = load->extra_points + start_point; + zone->cur = load->outline.points + start_point; + zone->tags = (FT_Byte*)load->outline.tags + start_point; + zone->contours = (FT_UShort*)load->outline.contours + start_contour; +} + + +#undef IS_HINTED +#define IS_HINTED( flags ) ( ( flags & FT_LOAD_NO_HINTING ) == 0 ) + + +/*************************************************************************/ +/* */ +/* The following functions are used by default with TrueType fonts. */ +/* However, they can be replaced by alternatives if we need to support */ +/* TrueType-compressed formats (like MicroType) in the future. */ +/* */ +/*************************************************************************/ + +static +FT_Error TT_Access_Glyph_Frame( TT_Loader* loader, + FT_UInt glyph_index, + FT_ULong offset, + FT_UInt byte_count ) { + FT_Error error; + FT_Stream stream = loader->stream; + + + /* the following line sets the `error' variable through macros! */ + (void)( FILE_Seek( offset ) || ACCESS_Frame( byte_count ) ); + + FT_TRACE5( ( "Glyph %ld\n", glyph_index ) ); + return error; +} + + +static +void TT_Forget_Glyph_Frame( TT_Loader* loader ) { + FT_Stream stream = loader->stream; + + + FORGET_Frame(); +} + + +static +FT_Error TT_Load_Glyph_Header( TT_Loader* loader ) { + FT_Stream stream = loader->stream; + + + loader->n_contours = GET_Short(); + + loader->bbox.xMin = GET_Short(); + loader->bbox.yMin = GET_Short(); + loader->bbox.xMax = GET_Short(); + loader->bbox.yMax = GET_Short(); + + FT_TRACE5( ( " # of contours: %d\n", loader->n_contours ) ); + FT_TRACE5( ( " xMin: %4d xMax: %4d\n", loader->bbox.xMin, + loader->bbox.xMax ) ); + FT_TRACE5( ( " yMin: %4d yMax: %4d\n", loader->bbox.yMin, + loader->bbox.yMax ) ); + + return FT_Err_Ok; +} + + +static +FT_Error TT_Load_Simple_Glyph( TT_Loader* load ) { + FT_Error error; + FT_Stream stream = load->stream; + FT_GlyphLoader* gloader = load->gloader; + FT_Int n_contours = load->n_contours; + FT_Outline* outline; + TT_Face face = (TT_Face)load->face; + TT_GlyphSlot slot = (TT_GlyphSlot)load->glyph; + FT_UShort n_ins; + FT_Int n, n_points; + + + /* reading the contours endpoints & number of points */ + { + short* cur = gloader->current.outline.contours; + short* limit = cur + n_contours; + + + for ( ; cur < limit; cur++ ) + cur[0] = GET_UShort(); + + n_points = 0; + if ( n_contours > 0 ) { + n_points = cur[-1] + 1; + } + + error = FT_GlyphLoader_Check_Points( gloader, n_points + 2, 0 ); + if ( error ) { + goto Fail; + } + + outline = &gloader->current.outline; + } + + /* reading the bytecode instructions */ + slot->control_len = 0; + slot->control_data = 0; + + n_ins = GET_UShort(); + + FT_TRACE5( ( " Instructions size: %d\n", n_ins ) ); + + if ( n_ins > face->max_profile.maxSizeOfInstructions ) { + FT_TRACE0( ( "ERROR: Too many instructions!\n" ) ); + error = TT_Err_Too_Many_Ins; + goto Fail; + } + + if ( stream->cursor + n_ins > stream->limit ) { + FT_TRACE0( ( "ERROR: Instruction count mismatch!\n" ) ); + error = TT_Err_Too_Many_Ins; + goto Fail; + } + +#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER + + if ( ( load->load_flags & + ( FT_LOAD_NO_SCALE | FT_LOAD_NO_HINTING ) ) == 0 && + load->instructions ) { + slot->control_len = n_ins; + slot->control_data = load->instructions; + + MEM_Copy( load->instructions, stream->cursor, n_ins ); + } + +#endif /* TT_CONFIG_OPTION_BYTECODE_INTERPRETER */ + + stream->cursor += n_ins; + + /* reading the point tags */ + + { + FT_Byte* flag = (FT_Byte*)outline->tags; + FT_Byte* limit = flag + n_points; + FT_Byte c, count; + + + for ( ; flag < limit; flag++ ) + { + *flag = c = GET_Byte(); + if ( c & 8 ) { + for ( count = GET_Byte(); count > 0; count-- ) + *++flag = c; + } + } + } + + /* reading the X coordinates */ + + { + FT_Vector* vec = outline->points; + FT_Vector* limit = vec + n_points; + FT_Byte* flag = (FT_Byte*)outline->tags; + FT_Pos x = 0; + + + for ( ; vec < limit; vec++, flag++ ) + { + FT_Pos y = 0; + + + if ( *flag & 2 ) { + y = GET_Byte(); + if ( ( *flag & 16 ) == 0 ) { + y = -y; + } + } else if ( ( *flag & 16 ) == 0 ) { + y = GET_Short(); + } + + x += y; + vec->x = x; + } + } + + /* reading the Y coordinates */ + + { + FT_Vector* vec = gloader->current.outline.points; + FT_Vector* limit = vec + n_points; + FT_Byte* flag = (FT_Byte*)outline->tags; + FT_Pos x = 0; + + + for ( ; vec < limit; vec++, flag++ ) + { + FT_Pos y = 0; + + + if ( *flag & 4 ) { + y = GET_Byte(); + if ( ( *flag & 32 ) == 0 ) { + y = -y; + } + } else if ( ( *flag & 32 ) == 0 ) { + y = GET_Short(); + } + + x += y; + vec->y = x; + } + } + + /* clear the touch tags */ + for ( n = 0; n < n_points; n++ ) + outline->tags[n] &= FT_Curve_Tag_On; + + outline->n_points = n_points; + outline->n_contours = n_contours; + +Fail: + return error; +} + + +static +FT_Error TT_Load_Composite_Glyph( TT_Loader* loader ) { + FT_Error error; + FT_Stream stream = loader->stream; + FT_GlyphLoader* gloader = loader->gloader; + FT_SubGlyph* subglyph; + FT_UInt num_subglyphs; + + + num_subglyphs = 0; + + do + { + FT_Fixed xx, xy, yy, yx; + + + /* check that we can load a new subglyph */ + error = FT_GlyphLoader_Check_Subglyphs( gloader, num_subglyphs + 1 ); + if ( error ) { + goto Fail; + } + + subglyph = gloader->current.subglyphs + num_subglyphs; + + subglyph->arg1 = subglyph->arg2 = 0; + + subglyph->flags = GET_UShort(); + subglyph->index = GET_UShort(); + + /* read arguments */ + if ( subglyph->flags & ARGS_ARE_WORDS ) { + subglyph->arg1 = GET_Short(); + subglyph->arg2 = GET_Short(); + } else + { + subglyph->arg1 = GET_Char(); + subglyph->arg2 = GET_Char(); + } + + /* read transform */ + xx = yy = 0x10000L; + xy = yx = 0; + + if ( subglyph->flags & WE_HAVE_A_SCALE ) { + xx = (FT_Fixed)GET_Short() << 2; + yy = xx; + } else if ( subglyph->flags & WE_HAVE_AN_XY_SCALE ) { + xx = (FT_Fixed)GET_Short() << 2; + yy = (FT_Fixed)GET_Short() << 2; + } else if ( subglyph->flags & WE_HAVE_A_2X2 ) { + xx = (FT_Fixed)GET_Short() << 2; + xy = (FT_Fixed)GET_Short() << 2; + yx = (FT_Fixed)GET_Short() << 2; + yy = (FT_Fixed)GET_Short() << 2; + } + + subglyph->transform.xx = xx; + subglyph->transform.xy = xy; + subglyph->transform.yx = yx; + subglyph->transform.yy = yy; + + num_subglyphs++; + + } while ( subglyph->flags & MORE_COMPONENTS ); + + gloader->current.num_subglyphs = num_subglyphs; + +#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER + { + /* we must undo the ACCESS_Frame in order to point to the */ + /* composite instructions, if we find some. */ + /* we will process them later... */ + /* */ + loader->ins_pos = FILE_Pos() + stream->cursor - stream->limit; + } +#endif + +Fail: + return error; +} + + +LOCAL_FUNC +void TT_Init_Glyph_Loading( TT_Face face ) { + face->access_glyph_frame = TT_Access_Glyph_Frame; + face->read_glyph_header = TT_Load_Glyph_Header; + face->read_simple_glyph = TT_Load_Simple_Glyph; + face->read_composite_glyph = TT_Load_Composite_Glyph; + face->forget_glyph_frame = TT_Forget_Glyph_Frame; +} + + +/*************************************************************************/ +/* */ +/* */ +/* TT_Process_Simple_Glyph */ +/* */ +/* */ +/* Once a simple glyph has been loaded, it needs to be processed. */ +/* Usually, this means scaling and hinting through bytecode */ +/* interpretation. */ +/* */ +static +FT_Error TT_Process_Simple_Glyph( TT_Loader* load, + FT_Bool debug ) { + FT_GlyphLoader* gloader = load->gloader; + FT_Outline* outline = &gloader->current.outline; + FT_UInt n_points = outline->n_points; + FT_UInt n_ins; + TT_GlyphZone* zone = &load->zone; + FT_Error error = FT_Err_Ok; + + + n_ins = load->glyph->control_len; + + /* add shadow points */ + + /* Now add the two shadow points at n and n + 1. */ + /* We need the left side bearing and advance width. */ + + { + FT_Vector* pp1; + FT_Vector* pp2; + + + /* pp1 = xMin - lsb */ + pp1 = outline->points + n_points; + pp1->x = load->bbox.xMin - load->left_bearing; + pp1->y = 0; + + /* pp2 = pp1 + aw */ + pp2 = pp1 + 1; + pp2->x = pp1->x + load->advance; + pp2->y = 0; + + outline->tags[n_points ] = 0; + outline->tags[n_points + 1] = 0; + } + + /* Note that we return two more points that are not */ + /* part of the glyph outline. */ + + n_points += 2; + + /* set up zone for hinting */ + tt_prepare_zone( zone, &gloader->current, 0, 0 ); + + /* eventually scale the glyph */ + if ( !( load->load_flags & FT_LOAD_NO_SCALE ) ) { + FT_Vector* vec = zone->cur; + FT_Vector* limit = vec + n_points; + FT_Fixed x_scale = load->size->metrics.x_scale; + FT_Fixed y_scale = load->size->metrics.y_scale; + + + /* first scale the glyph points */ + for ( ; vec < limit; vec++ ) + { + vec->x = FT_MulFix( vec->x, x_scale ); + vec->y = FT_MulFix( vec->y, y_scale ); + } + } + + cur_to_org( n_points, zone ); + + /* eventually hint the glyph */ + if ( IS_HINTED( load->load_flags ) ) { + FT_Pos x = zone->org[n_points - 2].x; + + + x = ( ( x + 32 ) & - 64 ) - x; + translate_array( n_points, zone->org, x, 0 ); + + org_to_cur( n_points, zone ); + + zone->cur[n_points - 1].x = ( zone->cur[n_points - 1].x + 32 ) & - 64; + +#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER + + /* now consider hinting */ + if ( n_ins > 0 ) { + error = TT_Set_CodeRange( load->exec, tt_coderange_glyph, + load->exec->glyphIns, n_ins ); + if ( error ) { + goto Exit; + } + + load->exec->is_composite = FALSE; + load->exec->pedantic_hinting = (FT_Bool)( load->load_flags & + FT_LOAD_PEDANTIC ); + load->exec->pts = *zone; + load->exec->pts.n_points += 2; + + error = TT_Run_Context( load->exec, debug ); + if ( error && load->exec->pedantic_hinting ) { + goto Exit; + } + + error = FT_Err_Ok; /* ignore bytecode errors in non-pedantic mode */ + } + +#endif /* TT_CONFIG_OPTION_BYTECODE_INTERPRETER */ + + } + + /* save glyph phantom points */ + if ( !load->preserve_pps ) { + load->pp1 = zone->cur[n_points - 2]; + load->pp2 = zone->cur[n_points - 1]; + } + +#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER +Exit: +#endif + return error; +} + + +/*************************************************************************/ +/* */ +/* */ +/* load_truetype_glyph */ +/* */ +/* */ +/* Loads a given truetype glyph. Handles composites and uses a */ +/* TT_Loader object. */ +/* */ +static +FT_Error load_truetype_glyph( TT_Loader* loader, + FT_UInt glyph_index ) { + FT_Stream stream = loader->stream; + FT_Error error; + TT_Face face = (TT_Face)loader->face; + FT_ULong offset; + FT_Int contours_count; + FT_UInt index, num_points, num_contours, count; + FT_Fixed x_scale, y_scale; + FT_ULong ins_offset; + FT_GlyphLoader* gloader = loader->gloader; + FT_Bool opened_frame = 0; + + + /* check glyph index */ + index = glyph_index; + if ( index >= (FT_UInt)face->root.num_glyphs ) { + error = TT_Err_Invalid_Glyph_Index; + goto Exit; + } + + loader->glyph_index = glyph_index; + num_contours = 0; + num_points = 0; + ins_offset = 0; + + x_scale = 0x10000L; + y_scale = 0x10000L; + if ( ( loader->load_flags & FT_LOAD_NO_SCALE ) == 0 ) { + x_scale = loader->size->metrics.x_scale; + y_scale = loader->size->metrics.y_scale; + } + + /* get horizontal metrics */ + { + FT_Short left_bearing; + FT_UShort advance_width; + + + Get_HMetrics( face, index, + ( FT_Bool ) !( loader->load_flags & + FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH ), + &left_bearing, + &advance_width ); + + loader->left_bearing = left_bearing; + loader->advance = advance_width; + } + + offset = face->glyph_locations[index]; + count = 0; + + if ( index < (FT_UInt)face->num_locations - 1 ) { + count = face->glyph_locations[index + 1] - offset; + } + + if ( count == 0 ) { + /* as described by Frederic Loyer, these are spaces, and */ + /* not the unknown glyph. */ + loader->bbox.xMin = 0; + loader->bbox.xMax = 0; + loader->bbox.yMin = 0; + loader->bbox.yMax = 0; + + loader->pp1.x = 0; + loader->pp2.x = loader->advance; + + if ( ( loader->load_flags & FT_LOAD_NO_SCALE ) == 0 ) { + loader->pp2.x = FT_MulFix( loader->pp2.x, x_scale ); + } + +#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER + + if ( loader->exec ) { + loader->exec->glyphSize = 0; + } + +#endif + + error = FT_Err_Ok; + goto Exit; + } + + offset = loader->glyf_offset + offset; + + /* access glyph frame */ + error = face->access_glyph_frame( loader, glyph_index, offset, count ); + if ( error ) { + goto Exit; + } + + opened_frame = 1; + + /* read first glyph header */ + error = face->read_glyph_header( loader ); + if ( error ) { + goto Fail; + } + + contours_count = loader->n_contours; + + count -= 10; + + loader->pp1.x = loader->bbox.xMin - loader->left_bearing; + loader->pp1.y = 0; + loader->pp2.x = loader->pp1.x + loader->advance; + loader->pp2.y = 0; + + if ( ( loader->load_flags & FT_LOAD_NO_SCALE ) == 0 ) { + loader->pp1.x = FT_MulFix( loader->pp1.x, x_scale ); + loader->pp2.x = FT_MulFix( loader->pp2.x, x_scale ); + } + + /***********************************************************************/ + /***********************************************************************/ + /***********************************************************************/ + + /* if it is a simple glyph, load it */ + + if ( contours_count >= 0 ) { + /* check that we can add the contours to the glyph */ + error = FT_GlyphLoader_Check_Points( gloader, 0, contours_count ); + if ( error ) { + goto Fail; + } + + error = face->read_simple_glyph( loader ); + if ( error ) { + goto Fail; + } + +#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER + + { + TT_Size size = (TT_Size)loader->size; + + + error = TT_Process_Simple_Glyph( loader, + (FT_Bool)( size && size->debug ) ); + } + +#else + + error = TT_Process_Simple_Glyph( loader, 0 ); + +#endif + + if ( error ) { + goto Fail; + } + + FT_GlyphLoader_Add( gloader ); + + /* Note: We could have put the simple loader source there */ + /* but the code is fat enough already :-) */ + } + /***********************************************************************/ + /***********************************************************************/ + /***********************************************************************/ + /* otherwise, load a composite! */ + else + { + TT_GlyphSlot glyph = (TT_GlyphSlot)loader->glyph; + FT_UInt start_point, start_contour; + FT_ULong ins_pos; /* position of composite instructions, if any */ + + + /* for each subglyph, read composite header */ + start_point = gloader->base.outline.n_points; + start_contour = gloader->base.outline.n_contours; + + error = face->read_composite_glyph( loader ); + if ( error ) { + goto Fail; + } + + ins_pos = loader->ins_pos; + face->forget_glyph_frame( loader ); + opened_frame = 0; + + /* if the flag FT_LOAD_NO_RECURSE is set, we return the subglyph */ + /* `as is' in the glyph slot (the client application will be */ + /* responsible for interpreting this data)... */ + /* */ + if ( loader->load_flags & FT_LOAD_NO_RECURSE ) { + /* set up remaining glyph fields */ + FT_GlyphLoader_Add( gloader ); + + glyph->num_subglyphs = gloader->base.num_subglyphs; + glyph->format = ft_glyph_format_composite; + glyph->subglyphs = gloader->base.subglyphs; + + goto Exit; + } + + /*********************************************************************/ + /*********************************************************************/ + /*********************************************************************/ + + /* Now, read each subglyph independently. */ + { + FT_Int n, num_base_points, num_new_points; + FT_SubGlyph* subglyph = 0; + + FT_UInt num_subglyphs = gloader->current.num_subglyphs; + FT_UInt num_base_subgs = gloader->base.num_subglyphs; + + + FT_GlyphLoader_Add( gloader ); + + for ( n = 0; n < (FT_Int)num_subglyphs; n++ ) + { + FT_Vector pp1, pp2; + FT_Pos x, y; + + + /* Each time we call load_truetype_glyph in this loop, the */ + /* value of `gloader.base.subglyphs' can change due to table */ + /* reallocations. We thus need to recompute the subglyph */ + /* pointer on each iteration. */ + subglyph = gloader->base.subglyphs + num_base_subgs + n; + + pp1 = loader->pp1; + pp2 = loader->pp2; + + num_base_points = gloader->base.outline.n_points; + + error = load_truetype_glyph( loader, subglyph->index ); + if ( error ) { + goto Fail; + } + + subglyph = gloader->base.subglyphs + num_base_subgs + n; + + if ( subglyph->flags & USE_MY_METRICS ) { + pp1 = loader->pp1; + pp2 = loader->pp2; + } else + { + loader->pp1 = pp1; + loader->pp2 = pp2; + } + + num_points = gloader->base.outline.n_points; + + num_new_points = num_points - num_base_points; + + /* now perform the transform required for this subglyph */ + + if ( subglyph->flags & ( WE_HAVE_A_SCALE | + WE_HAVE_AN_XY_SCALE | + WE_HAVE_A_2X2 ) ) { + FT_Vector* cur = gloader->base.outline.points + + num_base_points; + FT_Vector* org = gloader->base.extra_points + + num_base_points; + FT_Vector* limit = cur + num_new_points; + + + for ( ; cur < limit; cur++, org++ ) + { + FT_Vector_Transform( cur, &subglyph->transform ); + FT_Vector_Transform( org, &subglyph->transform ); + } + } + + /* apply offset */ + + if ( !( subglyph->flags & ARGS_ARE_XY_VALUES ) ) { + FT_UInt k = subglyph->arg1; + FT_UInt l = subglyph->arg2; + FT_Vector* p1; + FT_Vector* p2; + + + if ( start_point + k >= (FT_UInt)num_base_points || + l >= (FT_UInt)num_new_points ) { + error = TT_Err_Invalid_Composite; + goto Fail; + } + + l += num_base_points; + + p1 = gloader->base.outline.points + start_point + k; + p2 = gloader->base.outline.points + start_point + l; + + x = p1->x - p2->x; + y = p1->y - p2->y; + } else + { + x = subglyph->arg1; + y = subglyph->arg2; + + if ( !( loader->load_flags & FT_LOAD_NO_SCALE ) ) { + x = FT_MulFix( x, x_scale ); + y = FT_MulFix( y, y_scale ); + + if ( subglyph->flags & ROUND_XY_TO_GRID ) { + x = ( x + 32 ) & - 64; + y = ( y + 32 ) & - 64; + } + } + } + + translate_array( num_new_points, loader->zone.cur, x, y ); + cur_to_org( num_new_points, &loader->zone ); + } + + /*******************************************************************/ + /*******************************************************************/ + /*******************************************************************/ + + /* we have finished loading all sub-glyphs; now, look for */ + /* instructions for this composite! */ + +#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER + + if ( num_subglyphs > 0 && + loader->exec && + ins_pos > 0 && + subglyph->flags & WE_HAVE_INSTR ) { + FT_UShort n_ins; + TT_ExecContext exec = loader->exec; + TT_GlyphZone* pts; + FT_Vector* pp1; + + + /* read size of instructions */ + if ( FILE_Seek( ins_pos ) || + READ_UShort( n_ins ) ) { + goto Fail; + } + FT_TRACE5( ( " Instructions size = %d\n", n_ins ) ); + + /* in some fonts? */ + if ( n_ins == 0xFFFF ) { + n_ins = 0; + } + + /* check it */ + if ( n_ins > face->max_profile.maxSizeOfInstructions ) { + FT_TRACE0( ( "Too many instructions (%d) in composite glyph %ld\n", + n_ins, subglyph->index ) ); + return TT_Err_Too_Many_Ins; + } + + /* read the instructions */ + if ( FILE_Read( exec->glyphIns, n_ins ) ) { + goto Fail; + } + + glyph->control_data = exec->glyphIns; + glyph->control_len = n_ins; + + error = TT_Set_CodeRange( exec, + tt_coderange_glyph, + exec->glyphIns, + n_ins ); + if ( error ) { + goto Fail; + } + + /* prepare the execution context */ + tt_prepare_zone( &exec->pts, &gloader->base, + start_point, start_contour ); + pts = &exec->pts; + + pts->n_points = num_points + 2; + pts->n_contours = gloader->base.outline.n_contours; + + /* add phantom points */ + pp1 = pts->cur + num_points; + pp1[0] = loader->pp1; + pp1[1] = loader->pp2; + + pts->tags[num_points ] = 0; + pts->tags[num_points + 1] = 0; + + /* if hinting, round the phantom points */ + if ( IS_HINTED( loader->load_flags ) ) { + pp1[0].x = ( ( loader->pp1.x + 32 ) & - 64 ); + pp1[1].x = ( ( loader->pp2.x + 32 ) & - 64 ); + } + + { + FT_UInt k; + + + for ( k = 0; k < num_points; k++ ) + pts->tags[k] &= FT_Curve_Tag_On; + } + + cur_to_org( num_points + 2, pts ); + + /* now consider hinting */ + if ( IS_HINTED( loader->load_flags ) && n_ins > 0 ) { + exec->is_composite = TRUE; + exec->pedantic_hinting = + (FT_Bool)( loader->load_flags & FT_LOAD_PEDANTIC ); + + error = TT_Run_Context( exec, ( (TT_Size)loader->size )->debug ); + if ( error && exec->pedantic_hinting ) { + goto Fail; + } + } + + /* save glyph origin and advance points */ + loader->pp1 = pp1[0]; + loader->pp2 = pp1[1]; + } + +#endif /* TT_CONFIG_OPTION_BYTECODE_INTERPRETER */ + + } + /* end of composite loading */ + } + + /***********************************************************************/ + /***********************************************************************/ + /***********************************************************************/ + +Fail: + if ( opened_frame ) { + face->forget_glyph_frame( loader ); + } + +Exit: + return error; +} + + +static +void compute_glyph_metrics( TT_Loader* loader, + FT_UInt glyph_index ) { + FT_BBox bbox; + TT_Face face = (TT_Face)loader->face; + FT_Fixed x_scale, y_scale; + TT_GlyphSlot glyph = loader->glyph; + TT_Size size = (TT_Size)loader->size; + + + x_scale = 0x10000L; + y_scale = 0x10000L; + if ( ( loader->load_flags & FT_LOAD_NO_SCALE ) == 0 ) { + x_scale = size->root.metrics.x_scale; + y_scale = size->root.metrics.y_scale; + } + + if ( glyph->format != ft_glyph_format_composite ) { + glyph->outline.flags &= ~ft_outline_single_pass; + + /* copy outline to our glyph slot */ + FT_GlyphLoader_Copy_Points( glyph->loader, loader->gloader ); + glyph->outline = glyph->loader->base.outline; + + /* translate array so that (0,0) is the glyph's origin */ + FT_Outline_Translate( &glyph->outline, -loader->pp1.x, 0 ); + + FT_Outline_Get_CBox( &glyph->outline, &bbox ); + + if ( IS_HINTED( loader->load_flags ) ) { + /* grid-fit the bounding box */ + bbox.xMin &= -64; + bbox.yMin &= -64; + bbox.xMax = ( bbox.xMax + 63 ) & - 64; + bbox.yMax = ( bbox.yMax + 63 ) & - 64; + } + } else { + bbox = loader->bbox; + } + + /* get the device-independent horizontal advance. It is scaled later */ + /* by the base layer. */ + { + FT_Pos advance = loader->advance; + + + /* the flag FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH was introduced to */ + /* correctly support DynaLab fonts, which have an incorrect */ + /* `advance_Width_Max' field! It is used, to my knowledge, */ + /* exclusively in the X-TrueType font server. */ + /* */ + if ( face->postscript.isFixedPitch && + ( loader->load_flags & FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH ) == 0 ) { + advance = face->horizontal.advance_Width_Max; + } + + /* we need to return the advance in font units in linearHoriAdvance, */ + /* it will be scaled later by the base layer. */ + glyph->linearHoriAdvance = advance; + } + + glyph->metrics.horiBearingX = bbox.xMin; + glyph->metrics.horiBearingY = bbox.yMax; + glyph->metrics.horiAdvance = loader->pp2.x - loader->pp1.x; + + /* Now take care of vertical metrics. In the case where there is */ + /* no vertical information within the font (relatively common), make */ + /* up some metrics by `hand'... */ + + { + FT_Short top_bearing; /* vertical top side bearing (EM units) */ + FT_UShort advance_height; /* vertical advance height (EM units) */ + + FT_Pos left; /* scaled vertical left side bearing */ + FT_Pos Top; /* scaled original vertical top side bearing */ + FT_Pos top; /* scaled vertical top side bearing */ + FT_Pos advance; /* scaled vertical advance height */ + + + /* Get the unscaled `tsb' and `ah' */ + if ( face->vertical_info && + face->vertical.number_Of_VMetrics > 0 ) { + /* Don't assume that both the vertical header and vertical */ + /* metrics are present in the same font :-) */ + + TT_Get_Metrics( (TT_HoriHeader*)&face->vertical, + glyph_index, + &top_bearing, + &advance_height ); + } else + { + /* Make up the distances from the horizontal header. */ + + /* NOTE: The OS/2 values are the only `portable' ones, */ + /* which is why we use them, if there is an OS/2 */ + /* table in the font. Otherwise, we use the */ + /* values defined in the horizontal header. */ + /* */ + /* NOTE2: The sTypoDescender is negative, which is why */ + /* we compute the baseline-to-baseline distance */ + /* here with: */ + /* ascender - descender + linegap */ + /* */ + if ( face->os2.version != 0xFFFF ) { + top_bearing = face->os2.sTypoLineGap / 2; + advance_height = (FT_UShort)( face->os2.sTypoAscender - + face->os2.sTypoDescender + + face->os2.sTypoLineGap ); + } else + { + top_bearing = face->horizontal.Line_Gap / 2; + advance_height = (FT_UShort)( face->horizontal.Ascender + + face->horizontal.Descender + + face->horizontal.Line_Gap ); + } + } + + /* We must adjust the top_bearing value from the bounding box given */ + /* in the glyph header to te bounding box calculated with */ + /* FT_Get_Outline_CBox(). */ + + /* scale the metrics */ + if ( !( loader->load_flags & FT_LOAD_NO_SCALE ) ) { + Top = FT_MulFix( top_bearing, y_scale ); + top = FT_MulFix( top_bearing + loader->bbox.yMax, y_scale ) + - bbox.yMax; + advance = FT_MulFix( advance_height, y_scale ); + } else + { + Top = top_bearing; + top = top_bearing + loader->bbox.yMax - bbox.yMax; + advance = advance_height; + } + + /* set the advance height in design units. It is scaled later by */ + /* the base layer. */ + glyph->linearVertAdvance = advance_height; + + /* XXX: for now, we have no better algorithm for the lsb, but it */ + /* should work fine. */ + /* */ + left = ( bbox.xMin - bbox.xMax ) / 2; + + /* grid-fit them if necessary */ + if ( IS_HINTED( loader->load_flags ) ) { + left &= -64; + top = ( top + 63 ) & - 64; + advance = ( advance + 32 ) & - 64; + } + + glyph->metrics.vertBearingX = left; + glyph->metrics.vertBearingY = top; + glyph->metrics.vertAdvance = advance; + } + + /* adjust advance width to the value contained in the hdmx table */ + if ( !face->postscript.isFixedPitch && size && + IS_HINTED( loader->load_flags ) ) { + FT_Byte* widths = Get_Advance_Widths( face, + size->root.metrics.x_ppem ); + + + if ( widths ) { + glyph->metrics.horiAdvance = widths[glyph_index] << 6; + } + } + + /* set glyph dimensions */ + glyph->metrics.width = bbox.xMax - bbox.xMin; + glyph->metrics.height = bbox.yMax - bbox.yMin; +} + + +/*************************************************************************/ +/* */ +/* */ +/* TT_Load_Glyph */ +/* */ +/* */ +/* A function used to load a single glyph within a given glyph slot, */ +/* for a given size. */ +/* */ +/* */ +/* glyph :: A handle to a target slot object where the glyph */ +/* will be loaded. */ +/* */ +/* size :: A handle to the source face size at which the glyph */ +/* must be scaled/loaded. */ +/* */ +/* glyph_index :: The index of the glyph in the font file. */ +/* */ +/* load_flags :: A flag indicating what to load for this glyph. The */ +/* FT_LOAD_XXX constants can be used to control the */ +/* glyph loading process (e.g., whether the outline */ +/* should be scaled, whether to load bitmaps or not, */ +/* whether to hint the outline, etc). */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +LOCAL_FUNC +FT_Error TT_Load_Glyph( TT_Size size, + TT_GlyphSlot glyph, + FT_UShort glyph_index, + FT_UInt load_flags ) { + SFNT_Interface* sfnt; + TT_Face face; + FT_Stream stream; + FT_Memory memory; + FT_Error error; + TT_Loader loader; + + + face = (TT_Face)glyph->face; + sfnt = (SFNT_Interface*)face->sfnt; + stream = face->root.stream; + memory = face->root.memory; + error = 0; + + if ( !size || ( load_flags & FT_LOAD_NO_SCALE ) || + ( load_flags & FT_LOAD_NO_RECURSE ) ) { + size = NULL; + load_flags |= FT_LOAD_NO_SCALE | + FT_LOAD_NO_HINTING | + FT_LOAD_NO_BITMAP; + } + + glyph->num_subglyphs = 0; + +#ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS + + /* try to load embedded bitmap if any */ + if ( size && + ( load_flags & FT_LOAD_NO_BITMAP ) == 0 && + sfnt->load_sbits ) { + TT_SBit_Metrics metrics; + + + error = sfnt->load_sbit_image( face, + size->root.metrics.x_ppem, + size->root.metrics.y_ppem, + glyph_index, + load_flags, + stream, + &glyph->bitmap, + &metrics ); + if ( !error ) { + glyph->outline.n_points = 0; + glyph->outline.n_contours = 0; + + glyph->metrics.width = (FT_Pos)metrics.width << 6; + glyph->metrics.height = (FT_Pos)metrics.height << 6; + + glyph->metrics.horiBearingX = (FT_Pos)metrics.horiBearingX << 6; + glyph->metrics.horiBearingY = (FT_Pos)metrics.horiBearingY << 6; + glyph->metrics.horiAdvance = (FT_Pos)metrics.horiAdvance << 6; + + glyph->metrics.vertBearingX = (FT_Pos)metrics.vertBearingX << 6; + glyph->metrics.vertBearingY = (FT_Pos)metrics.vertBearingY << 6; + glyph->metrics.vertAdvance = (FT_Pos)metrics.vertAdvance << 6; + + glyph->format = ft_glyph_format_bitmap; + if ( load_flags & FT_LOAD_VERTICAL_LAYOUT ) { + glyph->bitmap_left = metrics.vertBearingX; + glyph->bitmap_top = metrics.vertBearingY; + } else + { + glyph->bitmap_left = metrics.horiBearingX; + glyph->bitmap_top = metrics.horiBearingY; + } + return error; + } + } + +#endif /* TT_CONFIG_OPTION_EMBEDDED_BITMAPS */ + + /* seek to the beginning of the glyph table. For Type 42 fonts */ + /* the table might be accessed from a Postscript stream or something */ + /* else... */ + + error = face->goto_table( face, TTAG_glyf, stream, 0 ); + if ( error ) { + FT_ERROR( ( "TT_Load_Glyph: could not access glyph table\n" ) ); + goto Exit; + } + + MEM_Set( &loader, 0, sizeof( loader ) ); + + /* update the glyph zone bounds */ + { + FT_GlyphLoader* gloader = FT_FACE_DRIVER( face )->glyph_loader; + + + loader.gloader = gloader; + + FT_GlyphLoader_Rewind( gloader ); + + tt_prepare_zone( &loader.zone, &gloader->base, 0, 0 ); + tt_prepare_zone( &loader.base, &gloader->base, 0, 0 ); + } + +#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER + + if ( size ) { + /* query new execution context */ + loader.exec = size->debug ? size->context : TT_New_Context( face ); + if ( !loader.exec ) { + return TT_Err_Could_Not_Find_Context; + } + + TT_Load_Context( loader.exec, face, size ); + loader.instructions = loader.exec->glyphIns; + + /* load default graphics state - if needed */ + if ( size->GS.instruct_control & 2 ) { + loader.exec->GS = tt_default_graphics_state; + } + } + +#endif /* TT_CONFIG_OPTION_BYTECODE_INTERPRETER */ + + /* clear all outline flags, except the `owner' one */ + glyph->outline.flags = 0; + + if ( size && size->root.metrics.y_ppem < 24 ) { + glyph->outline.flags |= ft_outline_high_precision; + } + + /* let's initialize the rest of our loader now */ + + loader.load_flags = load_flags; + + loader.face = (FT_Face)face; + loader.size = (FT_Size)size; + loader.glyph = (FT_GlyphSlot)glyph; + loader.stream = stream; + + loader.glyf_offset = FILE_Pos(); + +#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER + + /* if the cvt program has disabled hinting, the argument */ + /* is ignored. */ + if ( size && ( size->GS.instruct_control & 1 ) ) { + loader.load_flags |= FT_LOAD_NO_HINTING; + } + +#endif /* TT_CONFIG_OPTION_BYTECODE_INTERPRETER */ + + /* Main loading loop */ + glyph->format = ft_glyph_format_outline; + glyph->num_subglyphs = 0; + error = load_truetype_glyph( &loader, glyph_index ); + if ( !error ) { + compute_glyph_metrics( &loader, glyph_index ); + } + +#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER + + if ( !size || !size->debug ) { + TT_Done_Context( loader.exec ); + } + +#endif /* TT_CONFIG_OPTION_BYTECODE_INTERPRETER */ + +Exit: + return error; +} + + +/* END */ diff --git a/Projects/Android/jni/rtcw/src/ft2/ttgload.h b/Projects/Android/jni/rtcw/src/ft2/ttgload.h new file mode 100644 index 0000000..361675d --- /dev/null +++ b/Projects/Android/jni/rtcw/src/ft2/ttgload.h @@ -0,0 +1,57 @@ +/***************************************************************************/ +/* */ +/* ttgload.h */ +/* */ +/* TrueType Glyph Loader (specification). */ +/* */ +/* Copyright 1996-2000 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef TTGLOAD_H +#define TTGLOAD_H + + +#include "ttobjs.h" + +#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER +#include "ttinterp.h" +#endif + + +#ifdef __cplusplus +extern "C" { +#endif + + +LOCAL_DEF +void TT_Get_Metrics( TT_HoriHeader* header, + FT_UInt index, + FT_Short* bearing, + FT_UShort* advance ); + +LOCAL_DEF +void TT_Init_Glyph_Loading( TT_Face face ); + +LOCAL_DEF +FT_Error TT_Load_Glyph( TT_Size size, + TT_GlyphSlot glyph, + FT_UShort glyph_index, + FT_UInt load_flags ); + +#ifdef __cplusplus +} +#endif + +#endif /* TTGLOAD_H */ + + +/* END */ diff --git a/Projects/Android/jni/rtcw/src/ft2/ttinterp.c b/Projects/Android/jni/rtcw/src/ft2/ttinterp.c new file mode 100644 index 0000000..cf26388 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/ft2/ttinterp.c @@ -0,0 +1,7349 @@ +/***************************************************************************/ +/* */ +/* ttinterp.c */ +/* */ +/* TrueType bytecode interpreter (body). */ +/* */ +/* Copyright 1996-2000 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#include "ftdebug.h" +#include "ftcalc.h" +#include "ftsystem.h" + + +#include "ttinterp.h" + +#include "tterrors.h" + + +#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER + + +#define TT_MULFIX FT_MulFix +#define TT_MULDIV FT_MulDiv + +#define TT_INT64 FT_Int64 + + +/*************************************************************************/ +/* */ +/* The macro FT_COMPONENT is used in trace mode. It is an implicit */ +/* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */ +/* messages during execution. */ +/* */ +#undef FT_COMPONENT +#define FT_COMPONENT trace_ttinterp + +#undef NO_APPLE_PATENT +#define APPLE_THRESHOLD 0x4000000L + +/*************************************************************************/ +/* */ +/* In order to detect infinite loops in the code, we set up a counter */ +/* within the run loop. A single stroke of interpretation is now */ +/* limitet to a maximal number of opcodes defined below. */ +/* */ +#define MAX_RUNNABLE_OPCODES 1000000L + + +/*************************************************************************/ +/* */ +/* There are two kinds of implementations: */ +/* */ +/* a. static implementation */ +/* */ +/* The current execution context is a static variable, which fields */ +/* are accessed directly by the interpreter during execution. The */ +/* context is named `cur'. */ +/* */ +/* This version is non-reentrant, of course. */ +/* */ +/* b. indirect implementation */ +/* */ +/* The current execution context is passed to _each_ function as its */ +/* first argument, and each field is thus accessed indirectly. */ +/* */ +/* This version is fully re-entrant. */ +/* */ +/* The idea is that an indirect implementation may be slower to execute */ +/* on low-end processors that are used in some systems (like 386s or */ +/* even 486s). */ +/* */ +/* As a consequence, the indirect implementation is now the default, as */ +/* its performance costs can be considered negligible in our context. */ +/* Note, however, that we kept the same source with macros because: */ +/* */ +/* - The code is kept very close in design to the Pascal code used for */ +/* development. */ +/* */ +/* - It's much more readable that way! */ +/* */ +/* - It's still open to experimentation and tuning. */ +/* */ +/*************************************************************************/ + + +#ifndef TT_CONFIG_OPTION_STATIC_INTERPRETER /* indirect implementation */ + +#define CUR ( *exc ) /* see ttobjs.h */ + +#else /* static implementation */ + +#define CUR cur + +static +TT_ExecContextRec cur; /* static exec. context variable */ + +/* apparently, we have a _lot_ of direct indexing when accessing */ +/* the static `cur', which makes the code bigger (due to all the */ +/* four bytes addresses). */ + +#endif /* TT_CONFIG_OPTION_STATIC_INTERPRETER */ + + +/*************************************************************************/ +/* */ +/* The instruction argument stack. */ +/* */ +#define INS_ARG EXEC_OP_ FT_Long * args /* see ttobjs.h for EXEC_OP_ */ + + +/*************************************************************************/ +/* */ +/* This macro is used whenever `exec' is unused in a function, to avoid */ +/* stupid warnings from pedantic compilers. */ +/* */ +#define FT_UNUSED_EXEC FT_UNUSED( CUR ) + + +/*************************************************************************/ +/* */ +/* This macro is used whenever `args' is unused in a function, to avoid */ +/* stupid warnings from pedantic compilers. */ +/* */ +#define FT_UNUSED_ARG FT_UNUSED_EXEC; FT_UNUSED( args ) + + +/*************************************************************************/ +/* */ +/* The following macros hide the use of EXEC_ARG and EXEC_ARG_ to */ +/* increase readabilty of the code. */ +/* */ +/*************************************************************************/ + + +#define SKIP_Code() \ + SkipCode( EXEC_ARG ) + +#define GET_ShortIns() \ + GetShortIns( EXEC_ARG ) + +#define NORMalize( x, y, v ) \ + Normalize( EXEC_ARG_ x, y, v ) + +#define SET_SuperRound( scale, flags ) \ + SetSuperRound( EXEC_ARG_ scale, flags ) + +#define ROUND_None( d, c ) \ + Round_None( EXEC_ARG_ d, c ) + +#define INS_Goto_CodeRange( range, ip ) \ + Ins_Goto_CodeRange( EXEC_ARG_ range, ip ) + +#define CUR_Func_project( x, y ) \ + CUR.func_project( EXEC_ARG_ x, y ) + +#define CUR_Func_move( z, p, d ) \ + CUR.func_move( EXEC_ARG_ z, p, d ) + +#define CUR_Func_dualproj( x, y ) \ + CUR.func_dualproj( EXEC_ARG_ x, y ) + +#define CUR_Func_freeProj( x, y ) \ + CUR.func_freeProj( EXEC_ARG_ x, y ) + +#define CUR_Func_round( d, c ) \ + CUR.func_round( EXEC_ARG_ d, c ) + +#define CUR_Func_read_cvt( index ) \ + CUR.func_read_cvt( EXEC_ARG_ index ) + +#define CUR_Func_write_cvt( index, val ) \ + CUR.func_write_cvt( EXEC_ARG_ index, val ) + +#define CUR_Func_move_cvt( index, val ) \ + CUR.func_move_cvt( EXEC_ARG_ index, val ) + +#define CURRENT_Ratio() \ + Current_Ratio( EXEC_ARG ) + +#define CURRENT_Ppem() \ + Current_Ppem( EXEC_ARG ) + +#define CUR_Ppem() \ + Cur_PPEM( EXEC_ARG ) + +#define CALC_Length() \ + Calc_Length( EXEC_ARG ) + +#define INS_SxVTL( a, b, c, d ) \ + Ins_SxVTL( EXEC_ARG_ a, b, c, d ) + +#define COMPUTE_Funcs() \ + Compute_Funcs( EXEC_ARG ) + +#define COMPUTE_Round( a ) \ + Compute_Round( EXEC_ARG_ a ) + +#define COMPUTE_Point_Displacement( a, b, c, d ) \ + Compute_Point_Displacement( EXEC_ARG_ a, b, c, d ) + +#define MOVE_Zp2_Point( a, b, c, t ) \ + Move_Zp2_Point( EXEC_ARG_ a, b, c, t ) + + +/*************************************************************************/ +/* */ +/* Instruction dispatch function, as used by the interpreter. */ +/* */ +typedef void ( *TInstruction_Function )( INS_ARG ); + + +/*************************************************************************/ +/* */ +/* A simple bounds-checking macro. */ +/* */ +#define BOUNDS( x, n ) ( (FT_UInt)( x ) >= (FT_UInt)( n ) ) + + +#undef SUCCESS +#define SUCCESS 0 + +#undef FAILURE +#define FAILURE 1 + + +/*************************************************************************/ +/* */ +/* CODERANGE FUNCTIONS */ +/* */ +/*************************************************************************/ + + +/*************************************************************************/ +/* */ +/* */ +/* TT_Goto_CodeRange */ +/* */ +/* */ +/* Switches to a new code range (updates the code related elements in */ +/* `exec', and `IP'). */ +/* */ +/* */ +/* range :: The new execution code range. */ +/* */ +/* IP :: The new IP in the new code range. */ +/* */ +/* */ +/* exec :: The target execution context. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +LOCAL_FUNC +FT_Error TT_Goto_CodeRange( TT_ExecContext exec, + FT_Int range, + FT_Long IP ) { + TT_CodeRange* coderange; + + + FT_Assert( range >= 1 && range <= 3 ); + + coderange = &exec->codeRangeTable[range - 1]; + + FT_Assert( coderange->base != NULL ); + + /* NOTE: Because the last instruction of a program may be a CALL */ + /* which will return to the first byte *after* the code */ + /* range, we test for IP <= Size instead of IP < Size. */ + /* */ + FT_Assert( (FT_ULong)IP <= coderange->size ); + + exec->code = coderange->base; + exec->codeSize = coderange->size; + exec->IP = IP; + exec->curRange = range; + + return TT_Err_Ok; +} + + +/*************************************************************************/ +/* */ +/* */ +/* TT_Set_CodeRange */ +/* */ +/* */ +/* Sets a code range. */ +/* */ +/* */ +/* range :: The code range index. */ +/* */ +/* base :: The new code base. */ +/* */ +/* length :: The range size in bytes. */ +/* */ +/* */ +/* exec :: The target execution context. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +LOCAL_FUNC +FT_Error TT_Set_CodeRange( TT_ExecContext exec, + FT_Int range, + void* base, + FT_Long length ) { + FT_Assert( range >= 1 && range <= 3 ); + + exec->codeRangeTable[range - 1].base = (FT_Byte*)base; + exec->codeRangeTable[range - 1].size = length; + + return TT_Err_Ok; +} + + +/*************************************************************************/ +/* */ +/* */ +/* TT_Clear_CodeRange */ +/* */ +/* */ +/* Clears a code range. */ +/* */ +/* */ +/* range :: The code range index. */ +/* */ +/* */ +/* exec :: The target execution context. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +/* */ +/* Does not set the Error variable. */ +/* */ +LOCAL_FUNC +FT_Error TT_Clear_CodeRange( TT_ExecContext exec, + FT_Int range ) { + FT_Assert( range >= 1 && range <= 3 ); + + exec->codeRangeTable[range - 1].base = NULL; + exec->codeRangeTable[range - 1].size = 0; + + return TT_Err_Ok; +} + + +/*************************************************************************/ +/* */ +/* EXECUTION CONTEXT ROUTINES */ +/* */ +/*************************************************************************/ + + +/*************************************************************************/ +/* */ +/* */ +/* TT_Destroy_Context */ +/* */ +/* */ +/* Destroys a given context. */ +/* */ +/* */ +/* exec :: A handle to the target execution context. */ +/* */ +/* memory :: A handle to the parent memory object. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +/* */ +/* Only the glyph loader and debugger should call this function. */ +/* */ +LOCAL_FUNC +FT_Error TT_Destroy_Context( TT_ExecContext exec, + FT_Memory memory ) { + /* free composite load stack */ + FREE( exec->loadStack ); + exec->loadSize = 0; + + /* points zone */ + exec->maxPoints = 0; + exec->maxContours = 0; + + /* free stack */ + FREE( exec->stack ); + exec->stackSize = 0; + + /* free call stack */ + FREE( exec->callStack ); + exec->callSize = 0; + exec->callTop = 0; + + /* free glyph code range */ + FREE( exec->glyphIns ); + exec->glyphSize = 0; + + exec->size = NULL; + exec->face = NULL; + + FREE( exec ); + return TT_Err_Ok; +} + + +/*************************************************************************/ +/* */ +/* */ +/* Init_Context */ +/* */ +/* */ +/* Initializes a context object. */ +/* */ +/* */ +/* memory :: A handle to the parent memory object. */ +/* */ +/* face :: A handle to the source TrueType face object. */ +/* */ +/* */ +/* exec :: A handle to the target execution context. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +static +FT_Error Init_Context( TT_ExecContext exec, + TT_Face face, + FT_Memory memory ) { + FT_Error error; + + + FT_TRACE1( ( "Init_Context: new object at 0x%08p, parent = 0x%08p\n", + exec, face ) ); + + exec->memory = memory; + exec->callSize = 32; + + if ( ALLOC_ARRAY( exec->callStack, exec->callSize, TT_CallRec ) ) { + goto Fail_Memory; + } + + /* all values in the context are set to 0 already, but this is */ + /* here as a remainder */ + exec->maxPoints = 0; + exec->maxContours = 0; + + exec->stackSize = 0; + exec->loadSize = 0; + exec->glyphSize = 0; + + exec->stack = NULL; + exec->loadStack = NULL; + exec->glyphIns = NULL; + + exec->face = face; + exec->size = NULL; + + return TT_Err_Ok; + +Fail_Memory: + FT_ERROR( ( "Init_Context: not enough memory for 0x%08lx\n", + (FT_Long)exec ) ); + TT_Destroy_Context( exec, memory ); + + return error; +} + + +/*************************************************************************/ +/* */ +/* */ +/* Update_Max */ +/* */ +/* */ +/* Checks the size of a buffer and reallocates it if necessary. */ +/* */ +/* */ +/* memory :: A handle to the parent memory object. */ +/* */ +/* multiplier :: The size in bytes of each element in the buffer. */ +/* */ +/* new_max :: The new capacity (size) of the buffer. */ +/* */ +/* */ +/* size :: The address of the buffer's current size expressed */ +/* in elements. */ +/* */ +/* buff :: The address of the buffer base pointer. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +static +FT_Error Update_Max( FT_Memory memory, + FT_ULong* size, + FT_Long multiplier, + void** buff, + FT_ULong new_max ) { + FT_Error error; + + + if ( *size < new_max ) { + FREE( *buff ); + if ( ALLOC( *buff, new_max * multiplier ) ) { + return error; + } + *size = new_max; + } + + return TT_Err_Ok; +} + + +/*************************************************************************/ +/* */ +/* */ +/* TT_Load_Context */ +/* */ +/* */ +/* Prepare an execution context for glyph hinting. */ +/* */ +/* */ +/* face :: A handle to the source face object. */ +/* */ +/* size :: A handle to the source size object. */ +/* */ +/* */ +/* exec :: A handle to the target execution context. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +/* */ +/* Only the glyph loader and debugger should call this function. */ +/* */ +LOCAL_FUNC +FT_Error TT_Load_Context( TT_ExecContext exec, + TT_Face face, + TT_Size size ) { + FT_Int i; + FT_ULong tmp; + TT_MaxProfile* maxp; + FT_Error error; + + + exec->face = face; + maxp = &face->max_profile; + exec->size = size; + + if ( size ) { + exec->numFDefs = size->num_function_defs; + exec->maxFDefs = size->max_function_defs; + exec->numIDefs = size->num_instruction_defs; + exec->maxIDefs = size->max_instruction_defs; + exec->FDefs = size->function_defs; + exec->IDefs = size->instruction_defs; + exec->tt_metrics = size->ttmetrics; + exec->metrics = size->root.metrics; + + exec->maxFunc = size->max_func; + exec->maxIns = size->max_ins; + + for ( i = 0; i < TT_MAX_CODE_RANGES; i++ ) + exec->codeRangeTable[i] = size->codeRangeTable[i]; + + /* set graphics state */ + exec->GS = size->GS; + + exec->cvtSize = size->cvt_size; + exec->cvt = size->cvt; + + exec->storeSize = size->storage_size; + exec->storage = size->storage; + + exec->twilight = size->twilight; + } + + error = Update_Max( exec->memory, + &exec->loadSize, + sizeof( TT_SubGlyphRec ), + (void**)&exec->loadStack, + exec->face->max_components + 1 ); + if ( error ) { + return error; + } + + /* XXX: We reserve a little more elements on the stack to deal safely */ + /* with broken fonts like arialbs, courbs, timesbs, etc. */ + tmp = exec->stackSize; + error = Update_Max( exec->memory, + &tmp, + sizeof( FT_F26Dot6 ), + (void**)&exec->stack, + maxp->maxStackElements + 32 ); + exec->stackSize = (FT_UInt)tmp; + if ( error ) { + return error; + } + + tmp = exec->glyphSize; + error = Update_Max( exec->memory, + &tmp, + sizeof( FT_Byte ), + (void**)&exec->glyphIns, + maxp->maxSizeOfInstructions ); + exec->glyphSize = (FT_UShort)tmp; + if ( error ) { + return error; + } + + exec->pts.n_points = 0; + exec->pts.n_contours = 0; + + exec->instruction_trap = FALSE; + + return TT_Err_Ok; +} + + +/*************************************************************************/ +/* */ +/* */ +/* TT_Save_Context */ +/* */ +/* */ +/* Saves the code ranges in a `size' object. */ +/* */ +/* */ +/* exec :: A handle to the source execution context. */ +/* */ +/* */ +/* size :: A handle to the target size object. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +/* */ +/* Only the glyph loader and debugger should call this function. */ +/* */ +LOCAL_FUNC +FT_Error TT_Save_Context( TT_ExecContext exec, + TT_Size size ) { + FT_Int i; + + + /* XXXX: Will probably disappear soon with all the code range */ + /* management, which is now rather obsolete. */ + /* */ + size->num_function_defs = exec->numFDefs; + size->num_instruction_defs = exec->numIDefs; + + size->max_func = exec->maxFunc; + size->max_ins = exec->maxIns; + + for ( i = 0; i < TT_MAX_CODE_RANGES; i++ ) + size->codeRangeTable[i] = exec->codeRangeTable[i]; + + return TT_Err_Ok; +} + + +/*************************************************************************/ +/* */ +/* */ +/* TT_Run_Context */ +/* */ +/* */ +/* Executes one or more instructions in the execution context. */ +/* */ +/* */ +/* debug :: A Boolean flag. If set, the function sets some internal */ +/* variables and returns immediately, otherwise TT_RunIns() */ +/* is called. */ +/* */ +/* This is commented out currently. */ +/* */ +/* */ +/* exec :: A handle to the target execution context. */ +/* */ +/* */ +/* TrueTyoe error code. 0 means success. */ +/* */ +/* */ +/* Only the glyph loader and debugger should call this function. */ +/* */ +LOCAL_FUNC +FT_Error TT_Run_Context( TT_ExecContext exec, + FT_Bool debug ) { + FT_Error error; + + + if ( ( error = TT_Goto_CodeRange( exec, tt_coderange_glyph, 0 ) ) + != TT_Err_Ok ) { + return error; + } + + exec->zp0 = exec->pts; + exec->zp1 = exec->pts; + exec->zp2 = exec->pts; + + exec->GS.gep0 = 1; + exec->GS.gep1 = 1; + exec->GS.gep2 = 1; + + exec->GS.projVector.x = 0x4000; + exec->GS.projVector.y = 0x0000; + + exec->GS.freeVector = exec->GS.projVector; + exec->GS.dualVector = exec->GS.projVector; + + exec->GS.round_state = 1; + exec->GS.loop = 1; + + /* some glyphs leave something on the stack. so we clean it */ + /* before a new execution. */ + exec->top = 0; + exec->callTop = 0; + +#if 1 + FT_UNUSED( debug ); + + return exec->face->interpreter( exec ); +#else + if ( !debug ) { + return TT_RunIns( exec ); + } else { + return TT_Err_Ok; + } +#endif +} + + +const TT_GraphicsState tt_default_graphics_state = +{ + 0, 0, 0, + { 0x4000, 0 }, + { 0x4000, 0 }, + { 0x4000, 0 }, + 1, 64, 1, + TRUE, 68, 0, 0, 9, 3, + 0, FALSE, 2, 1, 1, 1 +}; + + +/*************************************************************************/ +/* */ +/* */ +/* TT_New_Context */ +/* */ +/* */ +/* Queries the face context for a given font. Note that there is */ +/* now a _single_ execution context in the TrueType driver which is */ +/* shared among faces. */ +/* */ +/* */ +/* face :: A handle to the source face object. */ +/* */ +/* */ +/* A handle to the execution context. Initialized for `face'. */ +/* */ +/* */ +/* Only the glyph loader and debugger should call this function. */ +/* */ +FT_EXPORT_FUNC( TT_ExecContext ) TT_New_Context( TT_Face face ) +{ + TT_Driver driver; + TT_ExecContext exec; + FT_Memory memory; + + + if ( !face ) { + return 0; + } + + driver = (TT_Driver)face->root.driver; + + memory = driver->root.root.memory; + exec = driver->context; + + if ( !driver->context ) { + FT_Error error; + + + /* allocate object */ + if ( ALLOC( exec, sizeof( *exec ) ) ) { + goto Exit; + } + + /* initialize it */ + error = Init_Context( exec, face, memory ); + if ( error ) { + goto Fail; + } + + /* store it into the driver */ + driver->context = exec; + } + +Exit: + return driver->context; + +Fail: + FREE( exec ); + + return 0; +} + + +/*************************************************************************/ +/* */ +/* */ +/* TT_Done_Context */ +/* */ +/* */ +/* Discards an execution context. */ +/* */ +/* */ +/* exec :: A handle to the target execution context. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +/* */ +/* Only the glyph loader and debugger should call this function. */ +/* */ +LOCAL_FUNC +FT_Error TT_Done_Context( TT_ExecContext exec ) { + /* Nothing at all for now */ + FT_UNUSED( exec ); + + return TT_Err_Ok; +} + + +#ifdef FT_CONFIG_OPTION_OLD_CALCS + +static FT_F26Dot6 Norm( FT_F26Dot6 X, + FT_F26Dot6 Y ) { + TT_INT64 T1, T2; + + + MUL_64( X, X, T1 ); + MUL_64( Y, Y, T2 ); + + ADD_64( T1, T2, T1 ); + + return (FT_F26Dot6)SQRT_64( T1 ); +} + +#endif /* FT_CONFIG_OPTION_OLD_CALCS */ + + +/*************************************************************************/ +/* */ +/* Before an opcode is executed, the interpreter verifies that there are */ +/* enough arguments on the stack, with the help of the Pop_Push_Count */ +/* table. */ +/* */ +/* For each opcode, the first column gives the number of arguments that */ +/* are popped from the stack; the second one gives the number of those */ +/* that are pushed in result. */ +/* */ +/* Note that for opcodes with a varying number of parameters, either 0 */ +/* or 1 arg is verified before execution, depending on the nature of the */ +/* instruction: */ +/* */ +/* - if the number of arguments is given by the bytecode stream or the */ +/* loop variable, 0 is chosen. */ +/* */ +/* - if the first argument is a count n that is followed by arguments */ +/* a1 .. an, then 1 is chosen. */ +/* */ +/*************************************************************************/ + + +#undef PACK +#define PACK( x, y ) ( ( x << 4 ) | y ) + + +static +const FT_Byte Pop_Push_Count[256] = +{ + /* opcodes are gathered in groups of 16 */ + /* please keep the spaces as they are */ + + /* SVTCA y */ PACK( 0, 0 ), + /* SVTCA x */ PACK( 0, 0 ), + /* SPvTCA y */ PACK( 0, 0 ), + /* SPvTCA x */ PACK( 0, 0 ), + /* SFvTCA y */ PACK( 0, 0 ), + /* SFvTCA x */ PACK( 0, 0 ), + /* SPvTL // */ PACK( 2, 0 ), + /* SPvTL + */ PACK( 2, 0 ), + /* SFvTL // */ PACK( 2, 0 ), + /* SFvTL + */ PACK( 2, 0 ), + /* SPvFS */ PACK( 2, 0 ), + /* SFvFS */ PACK( 2, 0 ), + /* GPV */ PACK( 0, 2 ), + /* GFV */ PACK( 0, 2 ), + /* SFvTPv */ PACK( 0, 0 ), + /* ISECT */ PACK( 5, 0 ), + + /* SRP0 */ PACK( 1, 0 ), + /* SRP1 */ PACK( 1, 0 ), + /* SRP2 */ PACK( 1, 0 ), + /* SZP0 */ PACK( 1, 0 ), + /* SZP1 */ PACK( 1, 0 ), + /* SZP2 */ PACK( 1, 0 ), + /* SZPS */ PACK( 1, 0 ), + /* SLOOP */ PACK( 1, 0 ), + /* RTG */ PACK( 0, 0 ), + /* RTHG */ PACK( 0, 0 ), + /* SMD */ PACK( 1, 0 ), + /* ELSE */ PACK( 0, 0 ), + /* JMPR */ PACK( 1, 0 ), + /* SCvTCi */ PACK( 1, 0 ), + /* SSwCi */ PACK( 1, 0 ), + /* SSW */ PACK( 1, 0 ), + + /* DUP */ PACK( 1, 2 ), + /* POP */ PACK( 1, 0 ), + /* CLEAR */ PACK( 0, 0 ), + /* SWAP */ PACK( 2, 2 ), + /* DEPTH */ PACK( 0, 1 ), + /* CINDEX */ PACK( 1, 1 ), + /* MINDEX */ PACK( 1, 0 ), + /* AlignPTS */ PACK( 2, 0 ), + /* INS_$28 */ PACK( 0, 0 ), + /* UTP */ PACK( 1, 0 ), + /* LOOPCALL */ PACK( 2, 0 ), + /* CALL */ PACK( 1, 0 ), + /* FDEF */ PACK( 1, 0 ), + /* ENDF */ PACK( 0, 0 ), + /* MDAP[0] */ PACK( 1, 0 ), + /* MDAP[1] */ PACK( 1, 0 ), + + /* IUP[0] */ PACK( 0, 0 ), + /* IUP[1] */ PACK( 0, 0 ), + /* SHP[0] */ PACK( 0, 0 ), + /* SHP[1] */ PACK( 0, 0 ), + /* SHC[0] */ PACK( 1, 0 ), + /* SHC[1] */ PACK( 1, 0 ), + /* SHZ[0] */ PACK( 1, 0 ), + /* SHZ[1] */ PACK( 1, 0 ), + /* SHPIX */ PACK( 1, 0 ), + /* IP */ PACK( 0, 0 ), + /* MSIRP[0] */ PACK( 2, 0 ), + /* MSIRP[1] */ PACK( 2, 0 ), + /* AlignRP */ PACK( 0, 0 ), + /* RTDG */ PACK( 0, 0 ), + /* MIAP[0] */ PACK( 2, 0 ), + /* MIAP[1] */ PACK( 2, 0 ), + + /* NPushB */ PACK( 0, 0 ), + /* NPushW */ PACK( 0, 0 ), + /* WS */ PACK( 2, 0 ), + /* RS */ PACK( 1, 1 ), + /* WCvtP */ PACK( 2, 0 ), + /* RCvt */ PACK( 1, 1 ), + /* GC[0] */ PACK( 1, 1 ), + /* GC[1] */ PACK( 1, 1 ), + /* SCFS */ PACK( 2, 0 ), + /* MD[0] */ PACK( 2, 1 ), + /* MD[1] */ PACK( 2, 1 ), + /* MPPEM */ PACK( 0, 1 ), + /* MPS */ PACK( 0, 1 ), + /* FlipON */ PACK( 0, 0 ), + /* FlipOFF */ PACK( 0, 0 ), + /* DEBUG */ PACK( 1, 0 ), + + /* LT */ PACK( 2, 1 ), + /* LTEQ */ PACK( 2, 1 ), + /* GT */ PACK( 2, 1 ), + /* GTEQ */ PACK( 2, 1 ), + /* EQ */ PACK( 2, 1 ), + /* NEQ */ PACK( 2, 1 ), + /* ODD */ PACK( 1, 1 ), + /* EVEN */ PACK( 1, 1 ), + /* IF */ PACK( 1, 0 ), + /* EIF */ PACK( 0, 0 ), + /* AND */ PACK( 2, 1 ), + /* OR */ PACK( 2, 1 ), + /* NOT */ PACK( 1, 1 ), + /* DeltaP1 */ PACK( 1, 0 ), + /* SDB */ PACK( 1, 0 ), + /* SDS */ PACK( 1, 0 ), + + /* ADD */ PACK( 2, 1 ), + /* SUB */ PACK( 2, 1 ), + /* DIV */ PACK( 2, 1 ), + /* MUL */ PACK( 2, 1 ), + /* ABS */ PACK( 1, 1 ), + /* NEG */ PACK( 1, 1 ), + /* FLOOR */ PACK( 1, 1 ), + /* CEILING */ PACK( 1, 1 ), + /* ROUND[0] */ PACK( 1, 1 ), + /* ROUND[1] */ PACK( 1, 1 ), + /* ROUND[2] */ PACK( 1, 1 ), + /* ROUND[3] */ PACK( 1, 1 ), + /* NROUND[0] */ PACK( 1, 1 ), + /* NROUND[1] */ PACK( 1, 1 ), + /* NROUND[2] */ PACK( 1, 1 ), + /* NROUND[3] */ PACK( 1, 1 ), + + /* WCvtF */ PACK( 2, 0 ), + /* DeltaP2 */ PACK( 1, 0 ), + /* DeltaP3 */ PACK( 1, 0 ), + /* DeltaCn[0] */ PACK( 1, 0 ), + /* DeltaCn[1] */ PACK( 1, 0 ), + /* DeltaCn[2] */ PACK( 1, 0 ), + /* SROUND */ PACK( 1, 0 ), + /* S45Round */ PACK( 1, 0 ), + /* JROT */ PACK( 2, 0 ), + /* JROF */ PACK( 2, 0 ), + /* ROFF */ PACK( 0, 0 ), + /* INS_$7B */ PACK( 0, 0 ), + /* RUTG */ PACK( 0, 0 ), + /* RDTG */ PACK( 0, 0 ), + /* SANGW */ PACK( 1, 0 ), + /* AA */ PACK( 1, 0 ), + + /* FlipPT */ PACK( 0, 0 ), + /* FlipRgON */ PACK( 2, 0 ), + /* FlipRgOFF */ PACK( 2, 0 ), + /* INS_$83 */ PACK( 0, 0 ), + /* INS_$84 */ PACK( 0, 0 ), + /* ScanCTRL */ PACK( 1, 0 ), + /* SDVPTL[0] */ PACK( 2, 0 ), + /* SDVPTL[1] */ PACK( 2, 0 ), + /* GetINFO */ PACK( 1, 1 ), + /* IDEF */ PACK( 1, 0 ), + /* ROLL */ PACK( 3, 3 ), + /* MAX */ PACK( 2, 1 ), + /* MIN */ PACK( 2, 1 ), + /* ScanTYPE */ PACK( 1, 0 ), + /* InstCTRL */ PACK( 2, 0 ), + /* INS_$8F */ PACK( 0, 0 ), + + /* INS_$90 */ PACK( 0, 0 ), + /* INS_$91 */ PACK( 0, 0 ), + /* INS_$92 */ PACK( 0, 0 ), + /* INS_$93 */ PACK( 0, 0 ), + /* INS_$94 */ PACK( 0, 0 ), + /* INS_$95 */ PACK( 0, 0 ), + /* INS_$96 */ PACK( 0, 0 ), + /* INS_$97 */ PACK( 0, 0 ), + /* INS_$98 */ PACK( 0, 0 ), + /* INS_$99 */ PACK( 0, 0 ), + /* INS_$9A */ PACK( 0, 0 ), + /* INS_$9B */ PACK( 0, 0 ), + /* INS_$9C */ PACK( 0, 0 ), + /* INS_$9D */ PACK( 0, 0 ), + /* INS_$9E */ PACK( 0, 0 ), + /* INS_$9F */ PACK( 0, 0 ), + + /* INS_$A0 */ PACK( 0, 0 ), + /* INS_$A1 */ PACK( 0, 0 ), + /* INS_$A2 */ PACK( 0, 0 ), + /* INS_$A3 */ PACK( 0, 0 ), + /* INS_$A4 */ PACK( 0, 0 ), + /* INS_$A5 */ PACK( 0, 0 ), + /* INS_$A6 */ PACK( 0, 0 ), + /* INS_$A7 */ PACK( 0, 0 ), + /* INS_$A8 */ PACK( 0, 0 ), + /* INS_$A9 */ PACK( 0, 0 ), + /* INS_$AA */ PACK( 0, 0 ), + /* INS_$AB */ PACK( 0, 0 ), + /* INS_$AC */ PACK( 0, 0 ), + /* INS_$AD */ PACK( 0, 0 ), + /* INS_$AE */ PACK( 0, 0 ), + /* INS_$AF */ PACK( 0, 0 ), + + /* PushB[0] */ PACK( 0, 1 ), + /* PushB[1] */ PACK( 0, 2 ), + /* PushB[2] */ PACK( 0, 3 ), + /* PushB[3] */ PACK( 0, 4 ), + /* PushB[4] */ PACK( 0, 5 ), + /* PushB[5] */ PACK( 0, 6 ), + /* PushB[6] */ PACK( 0, 7 ), + /* PushB[7] */ PACK( 0, 8 ), + /* PushW[0] */ PACK( 0, 1 ), + /* PushW[1] */ PACK( 0, 2 ), + /* PushW[2] */ PACK( 0, 3 ), + /* PushW[3] */ PACK( 0, 4 ), + /* PushW[4] */ PACK( 0, 5 ), + /* PushW[5] */ PACK( 0, 6 ), + /* PushW[6] */ PACK( 0, 7 ), + /* PushW[7] */ PACK( 0, 8 ), + + /* MDRP[00] */ PACK( 1, 0 ), + /* MDRP[01] */ PACK( 1, 0 ), + /* MDRP[02] */ PACK( 1, 0 ), + /* MDRP[03] */ PACK( 1, 0 ), + /* MDRP[04] */ PACK( 1, 0 ), + /* MDRP[05] */ PACK( 1, 0 ), + /* MDRP[06] */ PACK( 1, 0 ), + /* MDRP[07] */ PACK( 1, 0 ), + /* MDRP[08] */ PACK( 1, 0 ), + /* MDRP[09] */ PACK( 1, 0 ), + /* MDRP[10] */ PACK( 1, 0 ), + /* MDRP[11] */ PACK( 1, 0 ), + /* MDRP[12] */ PACK( 1, 0 ), + /* MDRP[13] */ PACK( 1, 0 ), + /* MDRP[14] */ PACK( 1, 0 ), + /* MDRP[15] */ PACK( 1, 0 ), + + /* MDRP[16] */ PACK( 1, 0 ), + /* MDRP[17] */ PACK( 1, 0 ), + /* MDRP[18] */ PACK( 1, 0 ), + /* MDRP[19] */ PACK( 1, 0 ), + /* MDRP[20] */ PACK( 1, 0 ), + /* MDRP[21] */ PACK( 1, 0 ), + /* MDRP[22] */ PACK( 1, 0 ), + /* MDRP[23] */ PACK( 1, 0 ), + /* MDRP[24] */ PACK( 1, 0 ), + /* MDRP[25] */ PACK( 1, 0 ), + /* MDRP[26] */ PACK( 1, 0 ), + /* MDRP[27] */ PACK( 1, 0 ), + /* MDRP[28] */ PACK( 1, 0 ), + /* MDRP[29] */ PACK( 1, 0 ), + /* MDRP[30] */ PACK( 1, 0 ), + /* MDRP[31] */ PACK( 1, 0 ), + + /* MIRP[00] */ PACK( 2, 0 ), + /* MIRP[01] */ PACK( 2, 0 ), + /* MIRP[02] */ PACK( 2, 0 ), + /* MIRP[03] */ PACK( 2, 0 ), + /* MIRP[04] */ PACK( 2, 0 ), + /* MIRP[05] */ PACK( 2, 0 ), + /* MIRP[06] */ PACK( 2, 0 ), + /* MIRP[07] */ PACK( 2, 0 ), + /* MIRP[08] */ PACK( 2, 0 ), + /* MIRP[09] */ PACK( 2, 0 ), + /* MIRP[10] */ PACK( 2, 0 ), + /* MIRP[11] */ PACK( 2, 0 ), + /* MIRP[12] */ PACK( 2, 0 ), + /* MIRP[13] */ PACK( 2, 0 ), + /* MIRP[14] */ PACK( 2, 0 ), + /* MIRP[15] */ PACK( 2, 0 ), + + /* MIRP[16] */ PACK( 2, 0 ), + /* MIRP[17] */ PACK( 2, 0 ), + /* MIRP[18] */ PACK( 2, 0 ), + /* MIRP[19] */ PACK( 2, 0 ), + /* MIRP[20] */ PACK( 2, 0 ), + /* MIRP[21] */ PACK( 2, 0 ), + /* MIRP[22] */ PACK( 2, 0 ), + /* MIRP[23] */ PACK( 2, 0 ), + /* MIRP[24] */ PACK( 2, 0 ), + /* MIRP[25] */ PACK( 2, 0 ), + /* MIRP[26] */ PACK( 2, 0 ), + /* MIRP[27] */ PACK( 2, 0 ), + /* MIRP[28] */ PACK( 2, 0 ), + /* MIRP[29] */ PACK( 2, 0 ), + /* MIRP[30] */ PACK( 2, 0 ), + /* MIRP[31] */ PACK( 2, 0 ) +}; + + +static +const FT_Char opcode_length[256] = +{ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + + -1,-1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 2, 3, 4, 5, 6, 7, 8, 9, 3, 5, 7, 9, 11,13,15,17, + + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 +}; + +static +const FT_Vector Null_Vector = {0,0}; + + +#undef PACK + + +#undef NULL_Vector +#define NULL_Vector (FT_Vector*)&Null_Vector + + +/*************************************************************************/ +/* */ +/* */ +/* Current_Ratio */ +/* */ +/* */ +/* Returns the current aspect ratio scaling factor depending on the */ +/* projection vector's state and device resolutions. */ +/* */ +/* */ +/* The aspect ratio in 16.16 format, always <= 1.0 . */ +/* */ +static +FT_Long Current_Ratio( EXEC_OP ) { + if ( CUR.tt_metrics.ratio ) { + return CUR.tt_metrics.ratio; + } + + if ( CUR.GS.projVector.y == 0 ) { + CUR.tt_metrics.ratio = CUR.tt_metrics.x_ratio; + } else if ( CUR.GS.projVector.x == 0 ) { + CUR.tt_metrics.ratio = CUR.tt_metrics.y_ratio; + } else + { + FT_Long x, y; + + +#ifdef FT_CONFIG_OPTION_OLD_CALCS + + x = TT_MULDIV( CUR.GS.projVector.x, CUR.tt_metrics.x_ratio, 0x4000 ); + y = TT_MULDIV( CUR.GS.projVector.y, CUR.tt_metrics.y_ratio, 0x4000 ); + CUR.tt_metrics.ratio = Norm( x, y ); + +#else + + x = TT_MULDIV( CUR.GS.projVector.x, CUR.tt_metrics.x_ratio, 0x8000 ); + y = TT_MULDIV( CUR.GS.projVector.y, CUR.tt_metrics.y_ratio, 0x8000 ); + CUR.tt_metrics.ratio = FT_Sqrt32( x * x + y * y ) << 1; + +#endif /* FT_CONFIG_OPTION_OLD_CALCS */ + + } + + return CUR.tt_metrics.ratio; +} + + +static +FT_Long Current_Ppem( EXEC_OP ) { + return TT_MULFIX( CUR.tt_metrics.ppem, CURRENT_Ratio() ); +} + + +/*************************************************************************/ +/* */ +/* Functions related to the control value table (CVT). */ +/* */ +/*************************************************************************/ + + +static +FT_F26Dot6 Read_CVT( EXEC_OP_ FT_ULong index ) { + return CUR.cvt[index]; +} + + +static +FT_F26Dot6 Read_CVT_Stretched( EXEC_OP_ FT_ULong index ) { + return TT_MULFIX( CUR.cvt[index], CURRENT_Ratio() ); +} + + +static +void Write_CVT( EXEC_OP_ FT_ULong index, + FT_F26Dot6 value ) { + CUR.cvt[index] = value; +} + + +static +void Write_CVT_Stretched( EXEC_OP_ FT_ULong index, + FT_F26Dot6 value ) { + CUR.cvt[index] = FT_DivFix( value, CURRENT_Ratio() ); +} + + +static +void Move_CVT( EXEC_OP_ FT_ULong index, + FT_F26Dot6 value ) { + CUR.cvt[index] += value; +} + + +static +void Move_CVT_Stretched( EXEC_OP_ FT_ULong index, + FT_F26Dot6 value ) { + CUR.cvt[index] += FT_DivFix( value, CURRENT_Ratio() ); +} + + +/*************************************************************************/ +/* */ +/* */ +/* GetShortIns */ +/* */ +/* */ +/* Returns a short integer taken from the instruction stream at */ +/* address IP. */ +/* */ +/* */ +/* Short read at code[IP]. */ +/* */ +/* */ +/* This one could become a macro. */ +/* */ +static FT_Short GetShortIns( EXEC_OP ) { + /* Reading a byte stream so there is no endianess (DaveP) */ + CUR.IP += 2; + return (FT_Short)( ( CUR.code[CUR.IP - 2] << 8 ) + + CUR.code[CUR.IP - 1] ); +} + + +/*************************************************************************/ +/* */ +/* */ +/* Ins_Goto_CodeRange */ +/* */ +/* */ +/* Goes to a certain code range in the instruction stream. */ +/* */ +/* */ +/* aRange :: The index of the code range. */ +/* */ +/* aIP :: The new IP address in the code range. */ +/* */ +/* */ +/* SUCCESS or FAILURE. */ +/* */ +static +FT_Bool Ins_Goto_CodeRange( EXEC_OP_ FT_Int aRange, + FT_ULong aIP ) { + TT_CodeRange* range; + + + if ( aRange < 1 || aRange > 3 ) { + CUR.error = TT_Err_Bad_Argument; + return FAILURE; + } + + range = &CUR.codeRangeTable[aRange - 1]; + + if ( range->base == NULL ) { /* invalid coderange */ + CUR.error = TT_Err_Invalid_CodeRange; + return FAILURE; + } + + /* NOTE: Because the last instruction of a program may be a CALL */ + /* which will return to the first byte *after* the code */ + /* range, we test for AIP <= Size, instead of AIP < Size. */ + + if ( aIP > range->size ) { + CUR.error = TT_Err_Code_Overflow; + return FAILURE; + } + + CUR.code = range->base; + CUR.codeSize = range->size; + CUR.IP = aIP; + CUR.curRange = aRange; + + return SUCCESS; +} + + +/*************************************************************************/ +/* */ +/* */ +/* Direct_Move */ +/* */ +/* */ +/* Moves a point by a given distance along the freedom vector. The */ +/* point will be `touched'. */ +/* */ +/* */ +/* point :: The index of the point to move. */ +/* */ +/* distance :: The distance to apply. */ +/* */ +/* */ +/* zone :: The affected glyph zone. */ +/* */ +static +void Direct_Move( EXEC_OP_ TT_GlyphZone* zone, + FT_UShort point, + FT_F26Dot6 distance ) { + FT_F26Dot6 v; + + + v = CUR.GS.freeVector.x; + + if ( v != 0 ) { + +#ifdef NO_APPLE_PATENT + + if ( ABS( CUR.F_dot_P ) > APPLE_THRESHOLD ) { + zone->cur[point].x += distance; + } + +#else + + zone->cur[point].x += TT_MULDIV( distance, + v * 0x10000L, + CUR.F_dot_P ); + +#endif + + zone->tags[point] |= FT_Curve_Tag_Touch_X; + } + + v = CUR.GS.freeVector.y; + + if ( v != 0 ) { + +#ifdef NO_APPLE_PATENT + + if ( ABS( CUR.F_dot_P ) > APPLE_THRESHOLD ) { + zone->cur[point].y += distance; + } + +#else + + zone->cur[point].y += TT_MULDIV( distance, + v * 0x10000L, + CUR.F_dot_P ); + +#endif + + zone->tags[point] |= FT_Curve_Tag_Touch_Y; + } +} + + +/*************************************************************************/ +/* */ +/* Special versions of Direct_Move() */ +/* */ +/* The following versions are used whenever both vectors are both */ +/* along one of the coordinate unit vectors, i.e. in 90% of the cases. */ +/* */ +/*************************************************************************/ + + +static +void Direct_Move_X( EXEC_OP_ TT_GlyphZone* zone, + FT_UShort point, + FT_F26Dot6 distance ) { + FT_UNUSED_EXEC; + + zone->cur[point].x += distance; + zone->tags[point] |= FT_Curve_Tag_Touch_X; +} + + +static +void Direct_Move_Y( EXEC_OP_ TT_GlyphZone* zone, + FT_UShort point, + FT_F26Dot6 distance ) { + FT_UNUSED_EXEC; + + zone->cur[point].y += distance; + zone->tags[point] |= FT_Curve_Tag_Touch_Y; +} + + +/*************************************************************************/ +/* */ +/* */ +/* Round_None */ +/* */ +/* */ +/* Does not round, but adds engine compensation. */ +/* */ +/* */ +/* distance :: The distance (not) to round. */ +/* */ +/* compensation :: The engine compensation. */ +/* */ +/* */ +/* The compensated distance. */ +/* */ +/* */ +/* The TrueType specification says very few about the relationship */ +/* between rounding and engine compensation. However, it seems from */ +/* the description of super round that we should add the compensation */ +/* before rounding. */ +/* */ +static +FT_F26Dot6 Round_None( EXEC_OP_ FT_F26Dot6 distance, + FT_F26Dot6 compensation ) { + FT_F26Dot6 val; + + FT_UNUSED_EXEC; + + + if ( distance >= 0 ) { + val = distance + compensation; + if ( val < 0 ) { + val = 0; + } + } else { + val = distance - compensation; + if ( val > 0 ) { + val = 0; + } + } + return val; +} + + +/*************************************************************************/ +/* */ +/* */ +/* Round_To_Grid */ +/* */ +/* */ +/* Rounds value to grid after adding engine compensation. */ +/* */ +/* */ +/* distance :: The distance to round. */ +/* */ +/* compensation :: The engine compensation. */ +/* */ +/* */ +/* Rounded distance. */ +/* */ +static +FT_F26Dot6 Round_To_Grid( EXEC_OP_ FT_F26Dot6 distance, + FT_F26Dot6 compensation ) { + FT_F26Dot6 val; + + FT_UNUSED_EXEC; + + + if ( distance >= 0 ) { + val = distance + compensation + 32; + if ( val > 0 ) { + val &= ~63; + } else { + val = 0; + } + } else + { + val = -( ( compensation - distance + 32 ) & - 64 ); + if ( val > 0 ) { + val = 0; + } + } + + return val; +} + + +/*************************************************************************/ +/* */ +/* */ +/* Round_To_Half_Grid */ +/* */ +/* */ +/* Rounds value to half grid after adding engine compensation. */ +/* */ +/* */ +/* distance :: The distance to round. */ +/* */ +/* compensation :: The engine compensation. */ +/* */ +/* */ +/* Rounded distance. */ +/* */ +static +FT_F26Dot6 Round_To_Half_Grid( EXEC_OP_ FT_F26Dot6 distance, + FT_F26Dot6 compensation ) { + FT_F26Dot6 val; + + FT_UNUSED_EXEC; + + + if ( distance >= 0 ) { + val = ( ( distance + compensation ) & - 64 ) + 32; + if ( val < 0 ) { + val = 0; + } + } else + { + val = -( ( ( compensation - distance ) & - 64 ) + 32 ); + if ( val > 0 ) { + val = 0; + } + } + + return val; +} + + +/*************************************************************************/ +/* */ +/* */ +/* Round_Down_To_Grid */ +/* */ +/* */ +/* Rounds value down to grid after adding engine compensation. */ +/* */ +/* */ +/* distance :: The distance to round. */ +/* */ +/* compensation :: The engine compensation. */ +/* */ +/* */ +/* Rounded distance. */ +/* */ +static +FT_F26Dot6 Round_Down_To_Grid( EXEC_OP_ FT_F26Dot6 distance, + FT_F26Dot6 compensation ) { + FT_F26Dot6 val; + + FT_UNUSED_EXEC; + + + if ( distance >= 0 ) { + val = distance + compensation; + if ( val > 0 ) { + val &= ~63; + } else { + val = 0; + } + } else + { + val = -( ( compensation - distance ) & - 64 ); + if ( val > 0 ) { + val = 0; + } + } + + return val; +} + + +/*************************************************************************/ +/* */ +/* */ +/* Round_Up_To_Grid */ +/* */ +/* */ +/* Rounds value up to grid after adding engine compensation. */ +/* */ +/* */ +/* distance :: The distance to round. */ +/* */ +/* compensation :: The engine compensation. */ +/* */ +/* */ +/* Rounded distance. */ +/* */ +static +FT_F26Dot6 Round_Up_To_Grid( EXEC_OP_ FT_F26Dot6 distance, + FT_F26Dot6 compensation ) { + FT_F26Dot6 val; + + + FT_UNUSED_EXEC; + + if ( distance >= 0 ) { + val = distance + compensation + 63; + if ( val > 0 ) { + val &= ~63; + } else { + val = 0; + } + } else + { + val = -( ( compensation - distance + 63 ) & - 64 ); + if ( val > 0 ) { + val = 0; + } + } + + return val; +} + + +/*************************************************************************/ +/* */ +/* */ +/* Round_To_Double_Grid */ +/* */ +/* */ +/* Rounds value to double grid after adding engine compensation. */ +/* */ +/* */ +/* distance :: The distance to round. */ +/* */ +/* compensation :: The engine compensation. */ +/* */ +/* */ +/* Rounded distance. */ +/* */ +static +FT_F26Dot6 Round_To_Double_Grid( EXEC_OP_ FT_F26Dot6 distance, + FT_F26Dot6 compensation ) { + FT_F26Dot6 val; + + FT_UNUSED_EXEC; + + + if ( distance >= 0 ) { + val = distance + compensation + 16; + if ( val > 0 ) { + val &= ~31; + } else { + val = 0; + } + } else + { + val = -( ( compensation - distance + 16 ) & - 32 ); + if ( val > 0 ) { + val = 0; + } + } + + return val; +} + + +/*************************************************************************/ +/* */ +/* */ +/* Round_Super */ +/* */ +/* */ +/* Super-rounds value to grid after adding engine compensation. */ +/* */ +/* */ +/* distance :: The distance to round. */ +/* */ +/* compensation :: The engine compensation. */ +/* */ +/* */ +/* Rounded distance. */ +/* */ +/* */ +/* The TrueType specification says very few about the relationship */ +/* between rounding and engine compensation. However, it seems from */ +/* the description of super round that we should add the compensation */ +/* before rounding. */ +/* */ +static +FT_F26Dot6 Round_Super( EXEC_OP_ FT_F26Dot6 distance, + FT_F26Dot6 compensation ) { + FT_F26Dot6 val; + + + if ( distance >= 0 ) { + val = ( distance - CUR.phase + CUR.threshold + compensation ) & + - CUR.period; + if ( val < 0 ) { + val = 0; + } + val += CUR.phase; + } else + { + val = -( ( CUR.threshold - CUR.phase - distance + compensation ) & + - CUR.period ); + if ( val > 0 ) { + val = 0; + } + val -= CUR.phase; + } + + return val; +} + + +/*************************************************************************/ +/* */ +/* */ +/* Round_Super_45 */ +/* */ +/* */ +/* Super-rounds value to grid after adding engine compensation. */ +/* */ +/* */ +/* distance :: The distance to round. */ +/* */ +/* compensation :: The engine compensation. */ +/* */ +/* */ +/* Rounded distance. */ +/* */ +/* */ +/* There is a separate function for Round_Super_45() as we may need */ +/* greater precision. */ +/* */ +static +FT_F26Dot6 Round_Super_45( EXEC_OP_ FT_F26Dot6 distance, + FT_F26Dot6 compensation ) { + FT_F26Dot6 val; + + + if ( distance >= 0 ) { + val = ( ( distance - CUR.phase + CUR.threshold + compensation ) / + CUR.period ) * CUR.period; + if ( val < 0 ) { + val = 0; + } + val += CUR.phase; + } else + { + val = -( ( ( CUR.threshold - CUR.phase - distance + compensation ) / + CUR.period ) * CUR.period ); + if ( val > 0 ) { + val = 0; + } + val -= CUR.phase; + } + + return val; +} + + +/*************************************************************************/ +/* */ +/* */ +/* Compute_Round */ +/* */ +/* */ +/* Sets the rounding mode. */ +/* */ +/* */ +/* round_mode :: The rounding mode to be used. */ +/* */ +static +void Compute_Round( EXEC_OP_ FT_Byte round_mode ) { + switch ( round_mode ) + { + case TT_Round_Off: + CUR.func_round = (TT_Round_Func)Round_None; + break; + + case TT_Round_To_Grid: + CUR.func_round = (TT_Round_Func)Round_To_Grid; + break; + + case TT_Round_Up_To_Grid: + CUR.func_round = (TT_Round_Func)Round_Up_To_Grid; + break; + + case TT_Round_Down_To_Grid: + CUR.func_round = (TT_Round_Func)Round_Down_To_Grid; + break; + + case TT_Round_To_Half_Grid: + CUR.func_round = (TT_Round_Func)Round_To_Half_Grid; + break; + + case TT_Round_To_Double_Grid: + CUR.func_round = (TT_Round_Func)Round_To_Double_Grid; + break; + + case TT_Round_Super: + CUR.func_round = (TT_Round_Func)Round_Super; + break; + + case TT_Round_Super_45: + CUR.func_round = (TT_Round_Func)Round_Super_45; + break; + } +} + + +/*************************************************************************/ +/* */ +/* */ +/* SetSuperRound */ +/* */ +/* */ +/* Sets Super Round parameters. */ +/* */ +/* */ +/* GridPeriod :: Grid period */ +/* selector :: SROUND opcode */ +/* */ +static +void SetSuperRound( EXEC_OP_ FT_F26Dot6 GridPeriod, + FT_Long selector ) { + switch ( (FT_Int)( selector & 0xC0 ) ) + { + case 0: + CUR.period = GridPeriod / 2; + break; + + case 0x40: + CUR.period = GridPeriod; + break; + + case 0x80: + CUR.period = GridPeriod * 2; + break; + + /* This opcode is reserved, but... */ + + case 0xC0: + CUR.period = GridPeriod; + break; + } + + switch ( (FT_Int)( selector & 0x30 ) ) + { + case 0: + CUR.phase = 0; + break; + + case 0x10: + CUR.phase = CUR.period / 4; + break; + + case 0x20: + CUR.phase = CUR.period / 2; + break; + + case 0x30: + CUR.phase = GridPeriod * 3 / 4; + break; + } + + if ( ( selector & 0x0F ) == 0 ) { + CUR.threshold = CUR.period - 1; + } else { + CUR.threshold = ( (FT_Int)( selector & 0x0F ) - 4 ) * CUR.period / 8; + } + + CUR.period /= 256; + CUR.phase /= 256; + CUR.threshold /= 256; +} + + +/*************************************************************************/ +/* */ +/* */ +/* Project */ +/* */ +/* */ +/* Computes the projection of vector given by (v2-v1) along the */ +/* current projection vector. */ +/* */ +/* */ +/* v1 :: First input vector. */ +/* v2 :: Second input vector. */ +/* */ +/* */ +/* The distance in F26dot6 format. */ +/* */ +static +FT_F26Dot6 Project( EXEC_OP_ FT_Vector* v1, + FT_Vector* v2 ) { + return TT_MULDIV( v1->x - v2->x, CUR.GS.projVector.x, 0x4000 ) + + TT_MULDIV( v1->y - v2->y, CUR.GS.projVector.y, 0x4000 ); +} + + +/*************************************************************************/ +/* */ +/* */ +/* Dual_Project */ +/* */ +/* */ +/* Computes the projection of the vector given by (v2-v1) along the */ +/* current dual vector. */ +/* */ +/* */ +/* v1 :: First input vector. */ +/* v2 :: Second input vector. */ +/* */ +/* */ +/* The distance in F26dot6 format. */ +/* */ +static +FT_F26Dot6 Dual_Project( EXEC_OP_ FT_Vector* v1, + FT_Vector* v2 ) { + return TT_MULDIV( v1->x - v2->x, CUR.GS.dualVector.x, 0x4000 ) + + TT_MULDIV( v1->y - v2->y, CUR.GS.dualVector.y, 0x4000 ); +} + + +/*************************************************************************/ +/* */ +/* */ +/* Free_Project */ +/* */ +/* */ +/* Computes the projection of the vector given by (v2-v1) along the */ +/* current freedom vector. */ +/* */ +/* */ +/* v1 :: First input vector. */ +/* v2 :: Second input vector. */ +/* */ +/* */ +/* The distance in F26dot6 format. */ +/* */ +static +FT_F26Dot6 Free_Project( EXEC_OP_ FT_Vector* v1, + FT_Vector* v2 ) { + return TT_MULDIV( v1->x - v2->x, CUR.GS.freeVector.x, 0x4000 ) + + TT_MULDIV( v1->y - v2->y, CUR.GS.freeVector.y, 0x4000 ); +} + + +/*************************************************************************/ +/* */ +/* */ +/* Project_x */ +/* */ +/* */ +/* Computes the projection of the vector given by (v2-v1) along the */ +/* horizontal axis. */ +/* */ +/* */ +/* v1 :: First input vector. */ +/* v2 :: Second input vector. */ +/* */ +/* */ +/* The distance in F26dot6 format. */ +/* */ +static +FT_F26Dot6 Project_x( EXEC_OP_ FT_Vector* v1, + FT_Vector* v2 ) { + FT_UNUSED_EXEC; + + return ( v1->x - v2->x ); +} + + +/*************************************************************************/ +/* */ +/* */ +/* Project_y */ +/* */ +/* */ +/* Computes the projection of the vector given by (v2-v1) along the */ +/* vertical axis. */ +/* */ +/* */ +/* v1 :: First input vector. */ +/* v2 :: Second input vector. */ +/* */ +/* */ +/* The distance in F26dot6 format. */ +/* */ +static +FT_F26Dot6 Project_y( EXEC_OP_ FT_Vector* v1, + FT_Vector* v2 ) { + FT_UNUSED_EXEC; + + return ( v1->y - v2->y ); +} + + +/*************************************************************************/ +/* */ +/* */ +/* Compute_Funcs */ +/* */ +/* */ +/* Computes the projection and movement function pointers according */ +/* to the current graphics state. */ +/* */ +static +void Compute_Funcs( EXEC_OP ) { + if ( CUR.GS.freeVector.x == 0x4000 ) { + CUR.func_freeProj = (TT_Project_Func)Project_x; + CUR.F_dot_P = CUR.GS.projVector.x * 0x10000L; + } else + { + if ( CUR.GS.freeVector.y == 0x4000 ) { + CUR.func_freeProj = (TT_Project_Func)Project_y; + CUR.F_dot_P = CUR.GS.projVector.y * 0x10000L; + } else + { + CUR.func_freeProj = (TT_Project_Func)Free_Project; + CUR.F_dot_P = (FT_Long)CUR.GS.projVector.x * CUR.GS.freeVector.x * 4 + + (FT_Long)CUR.GS.projVector.y * CUR.GS.freeVector.y * 4; + } + } + + if ( CUR.GS.projVector.x == 0x4000 ) { + CUR.func_project = (TT_Project_Func)Project_x; + } else + { + if ( CUR.GS.projVector.y == 0x4000 ) { + CUR.func_project = (TT_Project_Func)Project_y; + } else { + CUR.func_project = (TT_Project_Func)Project; + } + } + + if ( CUR.GS.dualVector.x == 0x4000 ) { + CUR.func_dualproj = (TT_Project_Func)Project_x; + } else + { + if ( CUR.GS.dualVector.y == 0x4000 ) { + CUR.func_dualproj = (TT_Project_Func)Project_y; + } else { + CUR.func_dualproj = (TT_Project_Func)Dual_Project; + } + } + + CUR.func_move = (TT_Move_Func)Direct_Move; + + if ( CUR.F_dot_P == 0x40000000L ) { + if ( CUR.GS.freeVector.x == 0x4000 ) { + CUR.func_move = (TT_Move_Func)Direct_Move_X; + } else + { + if ( CUR.GS.freeVector.y == 0x4000 ) { + CUR.func_move = (TT_Move_Func)Direct_Move_Y; + } + } + } + + /* at small sizes, F_dot_P can become too small, resulting */ + /* in overflows and `spikes' in a number of glyphs like `w'. */ + + if ( ABS( CUR.F_dot_P ) < 0x4000000L ) { + CUR.F_dot_P = 0x40000000L; + } + + /* Disable cached aspect ratio */ + CUR.tt_metrics.ratio = 0; +} + + +/*************************************************************************/ +/* */ +/* */ +/* Normalize */ +/* */ +/* */ +/* Norms a vector. */ +/* */ +/* */ +/* Vx :: The horizontal input vector coordinate. */ +/* Vy :: The vertical input vector coordinate. */ +/* */ +/* */ +/* R :: The normed unit vector. */ +/* */ +/* */ +/* Returns FAILURE if a vector parameter is zero. */ +/* */ +/* */ +/* In case Vx and Vy are both zero, Normalize() returns SUCCESS, and */ +/* R is undefined. */ +/* */ + +#ifdef FT_CONFIG_OPTION_OLD_CALCS + +static +FT_Bool Normalize( EXEC_OP_ FT_F26Dot6 Vx, + FT_F26Dot6 Vy, + FT_UnitVector* R ) { + FT_F26Dot6 W; + FT_Bool S1, S2; + + FT_UNUSED_EXEC; + + + if ( ABS( Vx ) < 0x10000L && ABS( Vy ) < 0x10000L ) { + Vx *= 0x100; + Vy *= 0x100; + + W = Norm( Vx, Vy ); + + if ( W == 0 ) { + /* XXX: UNDOCUMENTED! It seems that it is possible to try */ + /* to normalize the vector (0,0). Return immediately. */ + return SUCCESS; + } + + R->x = (FT_F2Dot14)FT_MulDiv( Vx, 0x4000L, W ); + R->y = (FT_F2Dot14)FT_MulDiv( Vy, 0x4000L, W ); + + return SUCCESS; + } + + W = Norm( Vx, Vy ); + + Vx = FT_MulDiv( Vx, 0x4000L, W ); + Vy = FT_MulDiv( Vy, 0x4000L, W ); + + W = Vx * Vx + Vy * Vy; + + /* Now, we want that Sqrt( W ) = 0x4000 */ + /* Or 0x1000000 <= W < 0x1004000 */ + + if ( Vx < 0 ) { + Vx = -Vx; + S1 = TRUE; + } else { + S1 = FALSE; + } + + if ( Vy < 0 ) { + Vy = -Vy; + S2 = TRUE; + } else { + S2 = FALSE; + } + + while ( W < 0x1000000L ) + { + /* We need to increase W by a minimal amount */ + if ( Vx < Vy ) { + Vx++; + } else { + Vy++; + } + + W = Vx * Vx + Vy * Vy; + } + + while ( W >= 0x1004000L ) + { + /* We need to decrease W by a minimal amount */ + if ( Vx < Vy ) { + Vx--; + } else { + Vy--; + } + + W = Vx * Vx + Vy * Vy; + } + + /* Note that in various cases, we can only */ + /* compute a Sqrt(W) of 0x3FFF, eg. Vx = Vy */ + + if ( S1 ) { + Vx = -Vx; + } + + if ( S2 ) { + Vy = -Vy; + } + + R->x = (FT_F2Dot14)Vx; /* Type conversion */ + R->y = (FT_F2Dot14)Vy; /* Type conversion */ + + return SUCCESS; +} + +#else + +static +FT_Bool Normalize( EXEC_OP_ FT_F26Dot6 Vx, + FT_F26Dot6 Vy, + FT_UnitVector* R ) { + FT_F26Dot6 u, v, d; + FT_Int shift; + FT_ULong H, L, L2, hi, lo, med; + + + u = ABS( Vx ); + v = ABS( Vy ); + + if ( u < v ) { + d = u; + u = v; + v = d; + } + + R->x = 0; + R->y = 0; + + /* check that we are not trying to normalise zero! */ + if ( u == 0 ) { + return SUCCESS; + } + + /* compute (u*u + v*v) on 64 bits with two 32-bit registers [H:L] */ + hi = (FT_ULong)u >> 16; + lo = (FT_ULong)u & 0xFFFF; + med = hi * lo; + + H = hi * hi + ( med >> 15 ); + med <<= 17; + L = lo * lo + med; + if ( L < med ) { + H++; + } + + hi = (FT_ULong)v >> 16; + lo = (FT_ULong)v & 0xFFFF; + med = hi * lo; + + H += hi * hi + ( med >> 15 ); + med <<= 17; + L2 = lo * lo + med; + if ( L2 < med ) { + H++; + } + + L += L2; + if ( L < L2 ) { + H++; + } + + /* if the value is smaller than 32-bits */ + if ( H == 0 ) { + shift = 0; + while ( ( L & 0xC0000000L ) == 0 ) + { + L <<= 2; + shift++; + } + + d = FT_Sqrt32( L ); + R->x = (FT_F2Dot14)TT_MULDIV( Vx << shift, 0x4000, d ); + R->y = (FT_F2Dot14)TT_MULDIV( Vy << shift, 0x4000, d ); + } + /* if the value is greater than 64-bits */ + else + { + shift = 0; + while ( H ) + { + L = ( L >> 2 ) | ( H << 30 ); + H >>= 2; + shift++; + } + + d = FT_Sqrt32( L ); + R->x = (FT_F2Dot14)TT_MULDIV( Vx >> shift, 0x4000, d ); + R->y = (FT_F2Dot14)TT_MULDIV( Vy >> shift, 0x4000, d ); + } + + { + FT_ULong x, y, w; + FT_Int sx, sy; + + + sx = R->x >= 0 ? 1 : -1; + sy = R->y >= 0 ? 1 : -1; + x = (FT_ULong)sx * R->x; + y = (FT_ULong)sy * R->y; + + w = x * x + y * y; + + /* we now want to adjust (x,y) in order to have sqrt(w) == 0x4000 */ + /* which means 0x1000000 <= w < 0x1004000 */ + while ( w <= 0x10000000L ) + { + /* increment the smallest coordinate */ + if ( x < y ) { + x++; + } else { + y++; + } + + w = x * x + y * y; + } + + while ( w >= 0x10040000L ) + { + /* decrement the smallest coordinate */ + if ( x < y ) { + x--; + } else { + y--; + } + + w = x * x + y * y; + } + + R->x = sx * x; + R->y = sy * y; + } + + return SUCCESS; +} + +#endif /* FT_CONFIG_OPTION_OLD_CALCS */ + + +/*************************************************************************/ +/* */ +/* Here we start with the implementation of the various opcodes. */ +/* */ +/*************************************************************************/ + + +static +FT_Bool Ins_SxVTL( EXEC_OP_ FT_UShort aIdx1, + FT_UShort aIdx2, + FT_Int aOpc, + FT_UnitVector* Vec ) { + FT_Long A, B, C; + FT_Vector* p1; + FT_Vector* p2; + + + if ( BOUNDS( aIdx1, CUR.zp2.n_points ) || + BOUNDS( aIdx2, CUR.zp1.n_points ) ) { + if ( CUR.pedantic_hinting ) { + CUR.error = TT_Err_Invalid_Reference; + } + return FAILURE; + } + + p1 = CUR.zp1.cur + aIdx2; + p2 = CUR.zp2.cur + aIdx1; + + A = p1->x - p2->x; + B = p1->y - p2->y; + + if ( ( aOpc & 1 ) != 0 ) { + C = B; /* counter clockwise rotation */ + B = A; + A = -C; + } + + NORMalize( A, B, Vec ); + + return SUCCESS; +} + + +/* When not using the big switch statements, the interpreter uses a */ +/* call table defined later below in this source. Each opcode must */ +/* thus have a corresponding function, even trivial ones. */ +/* */ +/* They are all defined there. */ + +#define DO_SVTCA \ + { \ + FT_Short A, B; \ + \ + \ + A = (FT_Short)( CUR.opcode & 1 ) << 14; \ + B = A ^ (FT_Short)0x4000; \ + \ + CUR.GS.freeVector.x = A; \ + CUR.GS.projVector.x = A; \ + CUR.GS.dualVector.x = A; \ + \ + CUR.GS.freeVector.y = B; \ + CUR.GS.projVector.y = B; \ + CUR.GS.dualVector.y = B; \ + \ + COMPUTE_Funcs(); \ + } + + +#define DO_SPVTCA \ + { \ + FT_Short A, B; \ + \ + \ + A = (FT_Short)( CUR.opcode & 1 ) << 14; \ + B = A ^ (FT_Short)0x4000; \ + \ + CUR.GS.projVector.x = A; \ + CUR.GS.dualVector.x = A; \ + \ + CUR.GS.projVector.y = B; \ + CUR.GS.dualVector.y = B; \ + \ + COMPUTE_Funcs(); \ + } + + +#define DO_SFVTCA \ + { \ + FT_Short A, B; \ + \ + \ + A = (FT_Short)( CUR.opcode & 1 ) << 14; \ + B = A ^ (FT_Short)0x4000; \ + \ + CUR.GS.freeVector.x = A; \ + CUR.GS.freeVector.y = B; \ + \ + COMPUTE_Funcs(); \ + } + + +#define DO_SPVTL \ + if ( INS_SxVTL( (FT_UShort)args[1], \ + (FT_UShort)args[0], \ + CUR.opcode, \ + &CUR.GS.projVector ) == SUCCESS ) \ + { \ + CUR.GS.dualVector = CUR.GS.projVector; \ + COMPUTE_Funcs(); \ + } + + +#define DO_SFVTL \ + if ( INS_SxVTL( (FT_UShort)args[1], \ + (FT_UShort)args[0], \ + CUR.opcode, \ + &CUR.GS.freeVector ) == SUCCESS ) { \ + COMPUTE_Funcs();} + + +#define DO_SFVTPV \ + CUR.GS.freeVector = CUR.GS.projVector; \ + COMPUTE_Funcs(); + + +#define DO_SPVFS \ + { \ + FT_Short S; \ + FT_Long X, Y; \ + \ + \ + /* Only use low 16bits, then sign extend */ \ + S = (FT_Short)args[1]; \ + Y = (FT_Long)S; \ + S = (FT_Short)args[0]; \ + X = (FT_Long)S; \ + \ + NORMalize( X, Y, &CUR.GS.projVector ); \ + \ + CUR.GS.dualVector = CUR.GS.projVector; \ + COMPUTE_Funcs(); \ + } + + +#define DO_SFVFS \ + { \ + FT_Short S; \ + FT_Long X, Y; \ + \ + \ + /* Only use low 16bits, then sign extend */ \ + S = (FT_Short)args[1]; \ + Y = (FT_Long)S; \ + S = (FT_Short)args[0]; \ + X = S; \ + \ + NORMalize( X, Y, &CUR.GS.freeVector ); \ + COMPUTE_Funcs(); \ + } + + +#define DO_GPV \ + args[0] = CUR.GS.projVector.x; \ + args[1] = CUR.GS.projVector.y; + + +#define DO_GFV \ + args[0] = CUR.GS.freeVector.x; \ + args[1] = CUR.GS.freeVector.y; + + +#define DO_SRP0 \ + CUR.GS.rp0 = (FT_UShort)args[0]; + + +#define DO_SRP1 \ + CUR.GS.rp1 = (FT_UShort)args[0]; + + +#define DO_SRP2 \ + CUR.GS.rp2 = (FT_UShort)args[0]; + + +#define DO_RTHG \ + CUR.GS.round_state = TT_Round_To_Half_Grid; \ + CUR.func_round = (TT_Round_Func)Round_To_Half_Grid; + + +#define DO_RTG \ + CUR.GS.round_state = TT_Round_To_Grid; \ + CUR.func_round = (TT_Round_Func)Round_To_Grid; + + +#define DO_RTDG \ + CUR.GS.round_state = TT_Round_To_Double_Grid; \ + CUR.func_round = (TT_Round_Func)Round_To_Double_Grid; + + +#define DO_RUTG \ + CUR.GS.round_state = TT_Round_Up_To_Grid; \ + CUR.func_round = (TT_Round_Func)Round_Up_To_Grid; + + +#define DO_RDTG \ + CUR.GS.round_state = TT_Round_Down_To_Grid; \ + CUR.func_round = (TT_Round_Func)Round_Down_To_Grid; + + +#define DO_ROFF \ + CUR.GS.round_state = TT_Round_Off; \ + CUR.func_round = (TT_Round_Func)Round_None; + + +#define DO_SROUND \ + SET_SuperRound( 0x4000, args[0] ); \ + CUR.GS.round_state = TT_Round_Super; \ + CUR.func_round = (TT_Round_Func)Round_Super; + + +#define DO_S45ROUND \ + SET_SuperRound( 0x2D41, args[0] ); \ + CUR.GS.round_state = TT_Round_Super_45; \ + CUR.func_round = (TT_Round_Func)Round_Super_45; + + +#define DO_SLOOP \ + if ( args[0] < 0 ) { \ + CUR.error = TT_Err_Bad_Argument;} \ + else { \ + CUR.GS.loop = args[0];} + + +#define DO_SMD \ + CUR.GS.minimum_distance = args[0]; + + +#define DO_SCVTCI \ + CUR.GS.control_value_cutin = (FT_F26Dot6)args[0]; + + +#define DO_SSWCI \ + CUR.GS.single_width_cutin = (FT_F26Dot6)args[0]; + + +/* XXX: UNDOCUMENTED! or bug in the Windows engine? */ +/* */ +/* It seems that the value that is read here is */ +/* expressed in 16.16 format rather than in font */ +/* units. */ +/* */ +#define DO_SSW \ + CUR.GS.single_width_value = (FT_F26Dot6)( args[0] >> 10 ); + + +#define DO_FLIPON \ + CUR.GS.auto_flip = TRUE; + + +#define DO_FLIPOFF \ + CUR.GS.auto_flip = FALSE; + + +#define DO_SDB \ + CUR.GS.delta_base = (FT_Short)args[0]; + + +#define DO_SDS \ + CUR.GS.delta_shift = (FT_Short)args[0]; + + +#define DO_MD /* nothing */ + + +#define DO_MPPEM \ + args[0] = CURRENT_Ppem(); + + +/* Note: The pointSize should be irrelevant in a given font program; */ +/* we thus decide to return only the ppem. */ +#if 0 + +#define DO_MPS \ + args[0] = CUR.metrics.pointSize; + +#else + +#define DO_MPS \ + args[0] = CURRENT_Ppem(); + +#endif /* 0 */ + + +#define DO_DUP \ + args[1] = args[0]; + + +#define DO_CLEAR \ + CUR.new_top = 0; + + +#define DO_SWAP \ + { \ + FT_Long L; \ + \ + \ + L = args[0]; \ + args[0] = args[1]; \ + args[1] = L; \ + } + + +#define DO_DEPTH \ + args[0] = CUR.top; + + +#define DO_CINDEX \ + { \ + FT_Long L; \ + \ + \ + L = args[0]; \ + \ + if ( L <= 0 || L > CUR.args ) { \ + CUR.error = TT_Err_Invalid_Reference;} \ + else { \ + args[0] = CUR.stack[CUR.args - L];} \ + } + + +#define DO_JROT \ + if ( args[1] != 0 ) \ + { \ + CUR.IP += args[0]; \ + CUR.step_ins = FALSE; \ + } + + +#define DO_JMPR \ + CUR.IP += args[0]; \ + CUR.step_ins = FALSE; + + +#define DO_JROF \ + if ( args[1] == 0 ) \ + { \ + CUR.IP += args[0]; \ + CUR.step_ins = FALSE; \ + } + + +#define DO_LT \ + args[0] = ( args[0] < args[1] ); + + +#define DO_LTEQ \ + args[0] = ( args[0] <= args[1] ); + + +#define DO_GT \ + args[0] = ( args[0] > args[1] ); + + +#define DO_GTEQ \ + args[0] = ( args[0] >= args[1] ); + + +#define DO_EQ \ + args[0] = ( args[0] == args[1] ); + + +#define DO_NEQ \ + args[0] = ( args[0] != args[1] ); + + +#define DO_ODD \ + args[0] = ( ( CUR_Func_round( args[0], 0 ) & 127 ) == 64 ); + + +#define DO_EVEN \ + args[0] = ( ( CUR_Func_round( args[0], 0 ) & 127 ) == 0 ); + + +#define DO_AND \ + args[0] = ( args[0] && args[1] ); + + +#define DO_OR \ + args[0] = ( args[0] || args[1] ); + + +#define DO_NOT \ + args[0] = !args[0]; + + +#define DO_ADD \ + args[0] += args[1]; + + +#define DO_SUB \ + args[0] -= args[1]; + + +#define DO_DIV \ + if ( args[1] == 0 ) { \ + CUR.error = TT_Err_Divide_By_Zero;} \ + else { \ + args[0] = TT_MULDIV( args[0], 64L, args[1] );} + + +#define DO_MUL \ + args[0] = TT_MULDIV( args[0], args[1], 64L ); + + +#define DO_ABS \ + args[0] = ABS( args[0] ); + + +#define DO_NEG \ + args[0] = -args[0]; + + +#define DO_FLOOR \ + args[0] &= -64; + + +#define DO_CEILING \ + args[0] = ( args[0] + 63 ) & - 64; + + +#define DO_RS \ + { \ + FT_ULong I = (FT_ULong)args[0]; \ + \ + \ + if ( BOUNDS( I, CUR.storeSize ) ) \ + { \ + if ( CUR.pedantic_hinting ) \ + { \ + ARRAY_BOUND_ERROR; \ + } \ + else { \ + args[0] = 0;} \ + } \ + else { \ + args[0] = CUR.storage[I];} \ + } + + +#define DO_WS \ + { \ + FT_ULong I = (FT_ULong)args[0]; \ + \ + \ + if ( BOUNDS( I, CUR.storeSize ) ) \ + { \ + if ( CUR.pedantic_hinting ) \ + { \ + ARRAY_BOUND_ERROR; \ + } \ + } \ + else { \ + CUR.storage[I] = args[1];} \ + } + + +#define DO_RCVT \ + { \ + FT_ULong I = (FT_ULong)args[0]; \ + \ + \ + if ( BOUNDS( I, CUR.cvtSize ) ) \ + { \ + if ( CUR.pedantic_hinting ) \ + { \ + ARRAY_BOUND_ERROR; \ + } \ + else { \ + args[0] = 0;} \ + } \ + else { \ + args[0] = CUR_Func_read_cvt( I );} \ + } + + +#define DO_WCVTP \ + { \ + FT_ULong I = (FT_ULong)args[0]; \ + \ + \ + if ( BOUNDS( I, CUR.cvtSize ) ) \ + { \ + if ( CUR.pedantic_hinting ) \ + { \ + ARRAY_BOUND_ERROR; \ + } \ + } \ + else { \ + CUR_Func_write_cvt( I, args[1] );} \ + } + + +#define DO_WCVTF \ + { \ + FT_ULong I = (FT_ULong)args[0]; \ + \ + \ + if ( BOUNDS( I, CUR.cvtSize ) ) \ + { \ + if ( CUR.pedantic_hinting ) \ + { \ + ARRAY_BOUND_ERROR; \ + } \ + } \ + else { \ + CUR.cvt[I] = TT_MULFIX( args[1], CUR.tt_metrics.scale );} \ + } + + +#define DO_DEBUG \ + CUR.error = TT_Err_Debug_OpCode; + + +#define DO_ROUND \ + args[0] = CUR_Func_round( \ + args[0], \ + CUR.tt_metrics.compensations[CUR.opcode - 0x68] ); + + +#define DO_NROUND \ + args[0] = ROUND_None( args[0], \ + CUR.tt_metrics.compensations[CUR.opcode - 0x6C] ); + + +#define DO_MAX \ + if ( args[1] > args[0] ) { \ + args[0] = args[1];} + + +#define DO_MIN \ + if ( args[1] < args[0] ) { \ + args[0] = args[1];} + + +#ifndef TT_CONFIG_OPTION_INTERPRETER_SWITCH + + +#undef ARRAY_BOUND_ERROR +#define ARRAY_BOUND_ERROR \ + { \ + CUR.error = TT_Err_Invalid_Reference; \ + return; \ + } + + +/*************************************************************************/ +/* */ +/* SVTCA[a]: Set (F and P) Vectors to Coordinate Axis */ +/* Opcode range: 0x00-0x01 */ +/* Stack: --> */ +/* */ +static +void Ins_SVTCA( INS_ARG ) { + DO_SVTCA +} + + +/*************************************************************************/ +/* */ +/* SPVTCA[a]: Set PVector to Coordinate Axis */ +/* Opcode range: 0x02-0x03 */ +/* Stack: --> */ +/* */ +static +void Ins_SPVTCA( INS_ARG ) { + DO_SPVTCA +} + + +/*************************************************************************/ +/* */ +/* SFVTCA[a]: Set FVector to Coordinate Axis */ +/* Opcode range: 0x04-0x05 */ +/* Stack: --> */ +/* */ +static +void Ins_SFVTCA( INS_ARG ) { + DO_SFVTCA +} + + +/*************************************************************************/ +/* */ +/* SPVTL[a]: Set PVector To Line */ +/* Opcode range: 0x06-0x07 */ +/* Stack: uint32 uint32 --> */ +/* */ +static +void Ins_SPVTL( INS_ARG ) { + DO_SPVTL +} + + +/*************************************************************************/ +/* */ +/* SFVTL[a]: Set FVector To Line */ +/* Opcode range: 0x08-0x09 */ +/* Stack: uint32 uint32 --> */ +/* */ +static +void Ins_SFVTL( INS_ARG ) { + DO_SFVTL +} + + +/*************************************************************************/ +/* */ +/* SFVTPV[]: Set FVector To PVector */ +/* Opcode range: 0x0E */ +/* Stack: --> */ +/* */ +static +void Ins_SFVTPV( INS_ARG ) { + DO_SFVTPV +} + + +/*************************************************************************/ +/* */ +/* SPVFS[]: Set PVector From Stack */ +/* Opcode range: 0x0A */ +/* Stack: f2.14 f2.14 --> */ +/* */ +static +void Ins_SPVFS( INS_ARG ) { + DO_SPVFS +} + + +/*************************************************************************/ +/* */ +/* SFVFS[]: Set FVector From Stack */ +/* Opcode range: 0x0B */ +/* Stack: f2.14 f2.14 --> */ +/* */ +static +void Ins_SFVFS( INS_ARG ) { + DO_SFVFS +} + + +/*************************************************************************/ +/* */ +/* GPV[]: Get Projection Vector */ +/* Opcode range: 0x0C */ +/* Stack: ef2.14 --> ef2.14 */ +/* */ +static +void Ins_GPV( INS_ARG ) { + DO_GPV +} + + +/*************************************************************************/ +/* GFV[]: Get Freedom Vector */ +/* Opcode range: 0x0D */ +/* Stack: ef2.14 --> ef2.14 */ +/* */ +static +void Ins_GFV( INS_ARG ) { + DO_GFV +} + + +/*************************************************************************/ +/* */ +/* SRP0[]: Set Reference Point 0 */ +/* Opcode range: 0x10 */ +/* Stack: uint32 --> */ +/* */ +static +void Ins_SRP0( INS_ARG ) { + DO_SRP0 +} + + +/*************************************************************************/ +/* */ +/* SRP1[]: Set Reference Point 1 */ +/* Opcode range: 0x11 */ +/* Stack: uint32 --> */ +/* */ +static +void Ins_SRP1( INS_ARG ) { + DO_SRP1 +} + + +/*************************************************************************/ +/* */ +/* SRP2[]: Set Reference Point 2 */ +/* Opcode range: 0x12 */ +/* Stack: uint32 --> */ +/* */ +static +void Ins_SRP2( INS_ARG ) { + DO_SRP2 +} + + +/*************************************************************************/ +/* */ +/* RTHG[]: Round To Half Grid */ +/* Opcode range: 0x19 */ +/* Stack: --> */ +/* */ +static +void Ins_RTHG( INS_ARG ) { + DO_RTHG +} + + +/*************************************************************************/ +/* */ +/* RTG[]: Round To Grid */ +/* Opcode range: 0x18 */ +/* Stack: --> */ +/* */ +static +void Ins_RTG( INS_ARG ) { + DO_RTG +} + + +/*************************************************************************/ +/* RTDG[]: Round To Double Grid */ +/* Opcode range: 0x3D */ +/* Stack: --> */ +/* */ +static +void Ins_RTDG( INS_ARG ) { + DO_RTDG +} + + +/*************************************************************************/ +/* RUTG[]: Round Up To Grid */ +/* Opcode range: 0x7C */ +/* Stack: --> */ +/* */ +static +void Ins_RUTG( INS_ARG ) { + DO_RUTG +} + + +/*************************************************************************/ +/* */ +/* RDTG[]: Round Down To Grid */ +/* Opcode range: 0x7D */ +/* Stack: --> */ +/* */ +static +void Ins_RDTG( INS_ARG ) { + DO_RDTG +} + + +/*************************************************************************/ +/* */ +/* ROFF[]: Round OFF */ +/* Opcode range: 0x7A */ +/* Stack: --> */ +/* */ +static +void Ins_ROFF( INS_ARG ) { + DO_ROFF +} + + +/*************************************************************************/ +/* */ +/* SROUND[]: Super ROUND */ +/* Opcode range: 0x76 */ +/* Stack: Eint8 --> */ +/* */ +static +void Ins_SROUND( INS_ARG ) { + DO_SROUND +} + + +/*************************************************************************/ +/* */ +/* S45ROUND[]: Super ROUND 45 degrees */ +/* Opcode range: 0x77 */ +/* Stack: uint32 --> */ +/* */ +static +void Ins_S45ROUND( INS_ARG ) { + DO_S45ROUND +} + + +/*************************************************************************/ +/* */ +/* SLOOP[]: Set LOOP variable */ +/* Opcode range: 0x17 */ +/* Stack: int32? --> */ +/* */ +static +void Ins_SLOOP( INS_ARG ) { + DO_SLOOP +} + + +/*************************************************************************/ +/* */ +/* SMD[]: Set Minimum Distance */ +/* Opcode range: 0x1A */ +/* Stack: f26.6 --> */ +/* */ +static +void Ins_SMD( INS_ARG ) { + DO_SMD +} + + +/*************************************************************************/ +/* */ +/* SCVTCI[]: Set Control Value Table Cut In */ +/* Opcode range: 0x1D */ +/* Stack: f26.6 --> */ +/* */ +static +void Ins_SCVTCI( INS_ARG ) { + DO_SCVTCI +} + + +/*************************************************************************/ +/* */ +/* SSWCI[]: Set Single Width Cut In */ +/* Opcode range: 0x1E */ +/* Stack: f26.6 --> */ +/* */ +static +void Ins_SSWCI( INS_ARG ) { + DO_SSWCI +} + + +/*************************************************************************/ +/* */ +/* SSW[]: Set Single Width */ +/* Opcode range: 0x1F */ +/* Stack: int32? --> */ +/* */ +static +void Ins_SSW( INS_ARG ) { + DO_SSW +} + + +/*************************************************************************/ +/* */ +/* FLIPON[]: Set auto-FLIP to ON */ +/* Opcode range: 0x4D */ +/* Stack: --> */ +/* */ +static +void Ins_FLIPON( INS_ARG ) { + DO_FLIPON +} + + +/*************************************************************************/ +/* */ +/* FLIPOFF[]: Set auto-FLIP to OFF */ +/* Opcode range: 0x4E */ +/* Stack: --> */ +/* */ +static +void Ins_FLIPOFF( INS_ARG ) { + DO_FLIPOFF +} + + +/*************************************************************************/ +/* */ +/* SANGW[]: Set ANGle Weight */ +/* Opcode range: 0x7E */ +/* Stack: uint32 --> */ +/* */ +static +void Ins_SANGW( INS_ARG ) { + /* instruction not supported anymore */ +} + + +/*************************************************************************/ +/* */ +/* SDB[]: Set Delta Base */ +/* Opcode range: 0x5E */ +/* Stack: uint32 --> */ +/* */ +static +void Ins_SDB( INS_ARG ) { + DO_SDB +} + + +/*************************************************************************/ +/* */ +/* SDS[]: Set Delta Shift */ +/* Opcode range: 0x5F */ +/* Stack: uint32 --> */ +/* */ +static +void Ins_SDS( INS_ARG ) { + DO_SDS +} + + +/*************************************************************************/ +/* */ +/* MPPEM[]: Measure Pixel Per EM */ +/* Opcode range: 0x4B */ +/* Stack: --> Euint16 */ +/* */ +static +void Ins_MPPEM( INS_ARG ) { + DO_MPPEM +} + + +/*************************************************************************/ +/* */ +/* MPS[]: Measure Point Size */ +/* Opcode range: 0x4C */ +/* Stack: --> Euint16 */ +/* */ +static +void Ins_MPS( INS_ARG ) { + DO_MPS +} + + +/*************************************************************************/ +/* */ +/* DUP[]: DUPlicate the top stack's element */ +/* Opcode range: 0x20 */ +/* Stack: StkElt --> StkElt StkElt */ +/* */ +static +void Ins_DUP( INS_ARG ) { + DO_DUP +} + + +/*************************************************************************/ +/* */ +/* POP[]: POP the stack's top element */ +/* Opcode range: 0x21 */ +/* Stack: StkElt --> */ +/* */ +static +void Ins_POP( INS_ARG ) { + /* nothing to do */ +} + + +/*************************************************************************/ +/* */ +/* CLEAR[]: CLEAR the entire stack */ +/* Opcode range: 0x22 */ +/* Stack: StkElt... --> */ +/* */ +static +void Ins_CLEAR( INS_ARG ) { + DO_CLEAR +} + + +/*************************************************************************/ +/* */ +/* SWAP[]: SWAP the stack's top two elements */ +/* Opcode range: 0x23 */ +/* Stack: 2 * StkElt --> 2 * StkElt */ +/* */ +static +void Ins_SWAP( INS_ARG ) { + DO_SWAP +} + + +/*************************************************************************/ +/* */ +/* DEPTH[]: return the stack DEPTH */ +/* Opcode range: 0x24 */ +/* Stack: --> uint32 */ +/* */ +static +void Ins_DEPTH( INS_ARG ) { + DO_DEPTH +} + + +/*************************************************************************/ +/* */ +/* CINDEX[]: Copy INDEXed element */ +/* Opcode range: 0x25 */ +/* Stack: int32 --> StkElt */ +/* */ +static +void Ins_CINDEX( INS_ARG ) { + DO_CINDEX +} + + +/*************************************************************************/ +/* */ +/* EIF[]: End IF */ +/* Opcode range: 0x59 */ +/* Stack: --> */ +/* */ +static +void Ins_EIF( INS_ARG ) { + /* nothing to do */ +} + + +/*************************************************************************/ +/* */ +/* JROT[]: Jump Relative On True */ +/* Opcode range: 0x78 */ +/* Stack: StkElt int32 --> */ +/* */ +static +void Ins_JROT( INS_ARG ) { + DO_JROT +} + + +/*************************************************************************/ +/* */ +/* JMPR[]: JuMP Relative */ +/* Opcode range: 0x1C */ +/* Stack: int32 --> */ +/* */ +static +void Ins_JMPR( INS_ARG ) { + DO_JMPR +} + + +/*************************************************************************/ +/* */ +/* JROF[]: Jump Relative On False */ +/* Opcode range: 0x79 */ +/* Stack: StkElt int32 --> */ +/* */ +static +void Ins_JROF( INS_ARG ) { + DO_JROF +} + + +/*************************************************************************/ +/* */ +/* LT[]: Less Than */ +/* Opcode range: 0x50 */ +/* Stack: int32? int32? --> bool */ +/* */ +static +void Ins_LT( INS_ARG ) { + DO_LT +} + + +/*************************************************************************/ +/* */ +/* LTEQ[]: Less Than or EQual */ +/* Opcode range: 0x51 */ +/* Stack: int32? int32? --> bool */ +/* */ +static +void Ins_LTEQ( INS_ARG ) { + DO_LTEQ +} + + +/*************************************************************************/ +/* */ +/* GT[]: Greater Than */ +/* Opcode range: 0x52 */ +/* Stack: int32? int32? --> bool */ +/* */ +static +void Ins_GT( INS_ARG ) { + DO_GT +} + + +/*************************************************************************/ +/* */ +/* GTEQ[]: Greater Than or EQual */ +/* Opcode range: 0x53 */ +/* Stack: int32? int32? --> bool */ +/* */ +static +void Ins_GTEQ( INS_ARG ) { + DO_GTEQ +} + + +/*************************************************************************/ +/* */ +/* EQ[]: EQual */ +/* Opcode range: 0x54 */ +/* Stack: StkElt StkElt --> bool */ +/* */ +static +void Ins_EQ( INS_ARG ) { + DO_EQ +} + + +/*************************************************************************/ +/* */ +/* NEQ[]: Not EQual */ +/* Opcode range: 0x55 */ +/* Stack: StkElt StkElt --> bool */ +/* */ +static +void Ins_NEQ( INS_ARG ) { + DO_NEQ +} + + +/*************************************************************************/ +/* */ +/* ODD[]: Is ODD */ +/* Opcode range: 0x56 */ +/* Stack: f26.6 --> bool */ +/* */ +static +void Ins_ODD( INS_ARG ) { + DO_ODD +} + + +/*************************************************************************/ +/* */ +/* EVEN[]: Is EVEN */ +/* Opcode range: 0x57 */ +/* Stack: f26.6 --> bool */ +/* */ +static +void Ins_EVEN( INS_ARG ) { + DO_EVEN +} + + +/*************************************************************************/ +/* */ +/* AND[]: logical AND */ +/* Opcode range: 0x5A */ +/* Stack: uint32 uint32 --> uint32 */ +/* */ +static +void Ins_AND( INS_ARG ) { + DO_AND +} + + +/*************************************************************************/ +/* */ +/* OR[]: logical OR */ +/* Opcode range: 0x5B */ +/* Stack: uint32 uint32 --> uint32 */ +/* */ +static +void Ins_OR( INS_ARG ) { + DO_OR +} + + +/*************************************************************************/ +/* */ +/* NOT[]: logical NOT */ +/* Opcode range: 0x5C */ +/* Stack: StkElt --> uint32 */ +/* */ +static +void Ins_NOT( INS_ARG ) { + DO_NOT +} + + +/*************************************************************************/ +/* */ +/* ADD[]: ADD */ +/* Opcode range: 0x60 */ +/* Stack: f26.6 f26.6 --> f26.6 */ +/* */ +static +void Ins_ADD( INS_ARG ) { + DO_ADD +} + + +/*************************************************************************/ +/* */ +/* SUB[]: SUBtract */ +/* Opcode range: 0x61 */ +/* Stack: f26.6 f26.6 --> f26.6 */ +/* */ +static +void Ins_SUB( INS_ARG ) { + DO_SUB +} + + +/*************************************************************************/ +/* */ +/* DIV[]: DIVide */ +/* Opcode range: 0x62 */ +/* Stack: f26.6 f26.6 --> f26.6 */ +/* */ +static +void Ins_DIV( INS_ARG ) { + DO_DIV +} + + +/*************************************************************************/ +/* */ +/* MUL[]: MULtiply */ +/* Opcode range: 0x63 */ +/* Stack: f26.6 f26.6 --> f26.6 */ +/* */ +static +void Ins_MUL( INS_ARG ) { + DO_MUL +} + + +/*************************************************************************/ +/* */ +/* ABS[]: ABSolute value */ +/* Opcode range: 0x64 */ +/* Stack: f26.6 --> f26.6 */ +/* */ +static +void Ins_ABS( INS_ARG ) { + DO_ABS +} + + +/*************************************************************************/ +/* */ +/* NEG[]: NEGate */ +/* Opcode range: 0x65 */ +/* Stack: f26.6 --> f26.6 */ +/* */ +static +void Ins_NEG( INS_ARG ) { + DO_NEG +} + + +/*************************************************************************/ +/* */ +/* FLOOR[]: FLOOR */ +/* Opcode range: 0x66 */ +/* Stack: f26.6 --> f26.6 */ +/* */ +static +void Ins_FLOOR( INS_ARG ) { + DO_FLOOR +} + + +/*************************************************************************/ +/* */ +/* CEILING[]: CEILING */ +/* Opcode range: 0x67 */ +/* Stack: f26.6 --> f26.6 */ +/* */ +static +void Ins_CEILING( INS_ARG ) { + DO_CEILING +} + + +/*************************************************************************/ +/* */ +/* RS[]: Read Store */ +/* Opcode range: 0x43 */ +/* Stack: uint32 --> uint32 */ +/* */ +static +void Ins_RS( INS_ARG ) { + DO_RS +} + + +/*************************************************************************/ +/* */ +/* WS[]: Write Store */ +/* Opcode range: 0x42 */ +/* Stack: uint32 uint32 --> */ +/* */ +static +void Ins_WS( INS_ARG ) { + DO_WS +} + + +/*************************************************************************/ +/* */ +/* WCVTP[]: Write CVT in Pixel units */ +/* Opcode range: 0x44 */ +/* Stack: f26.6 uint32 --> */ +/* */ +static +void Ins_WCVTP( INS_ARG ) { + DO_WCVTP +} + + +/*************************************************************************/ +/* */ +/* WCVTF[]: Write CVT in Funits */ +/* Opcode range: 0x70 */ +/* Stack: uint32 uint32 --> */ +/* */ +static +void Ins_WCVTF( INS_ARG ) { + DO_WCVTF +} + + +/*************************************************************************/ +/* */ +/* RCVT[]: Read CVT */ +/* Opcode range: 0x45 */ +/* Stack: uint32 --> f26.6 */ +/* */ +static +void Ins_RCVT( INS_ARG ) { + DO_RCVT +} + + +/*************************************************************************/ +/* */ +/* AA[]: Adjust Angle */ +/* Opcode range: 0x7F */ +/* Stack: uint32 --> */ +/* */ +static +void Ins_AA( INS_ARG ) { + /* intentionally no longer supported */ +} + + +/*************************************************************************/ +/* */ +/* DEBUG[]: DEBUG. Unsupported. */ +/* Opcode range: 0x4F */ +/* Stack: uint32 --> */ +/* */ +/* Note: The original instruction pops a value from the stack. */ +/* */ +static +void Ins_DEBUG( INS_ARG ) { + DO_DEBUG +} + + +/*************************************************************************/ +/* */ +/* ROUND[ab]: ROUND value */ +/* Opcode range: 0x68-0x6B */ +/* Stack: f26.6 --> f26.6 */ +/* */ +static +void Ins_ROUND( INS_ARG ) { + DO_ROUND +} + + +/*************************************************************************/ +/* */ +/* NROUND[ab]: No ROUNDing of value */ +/* Opcode range: 0x6C-0x6F */ +/* Stack: f26.6 --> f26.6 */ +/* */ +static +void Ins_NROUND( INS_ARG ) { + DO_NROUND +} + + +/*************************************************************************/ +/* */ +/* MAX[]: MAXimum */ +/* Opcode range: 0x68 */ +/* Stack: int32? int32? --> int32 */ +/* */ +static +void Ins_MAX( INS_ARG ) { + DO_MAX +} + + +/*************************************************************************/ +/* */ +/* MIN[]: MINimum */ +/* Opcode range: 0x69 */ +/* Stack: int32? int32? --> int32 */ +/* */ +static +void Ins_MIN( INS_ARG ) { + DO_MIN +} + + +#endif /* !TT_CONFIG_OPTION_INTERPRETER_SWITCH */ + + +/*************************************************************************/ +/* */ +/* The following functions are called as is within the switch statement. */ +/* */ +/*************************************************************************/ + + +/*************************************************************************/ +/* */ +/* MINDEX[]: Move INDEXed element */ +/* Opcode range: 0x26 */ +/* Stack: int32? --> StkElt */ +/* */ +static +void Ins_MINDEX( INS_ARG ) { + FT_Long L, K; + + + L = args[0]; + + if ( L <= 0 || L > CUR.args ) { + CUR.error = TT_Err_Invalid_Reference; + return; + } + + K = CUR.stack[CUR.args - L]; + + MEM_Move( &CUR.stack[CUR.args - L ], + &CUR.stack[CUR.args - L + 1], + ( L - 1 ) * sizeof( FT_Long ) ); + + CUR.stack[CUR.args - 1] = K; +} + + +/*************************************************************************/ +/* */ +/* ROLL[]: ROLL top three elements */ +/* Opcode range: 0x8A */ +/* Stack: 3 * StkElt --> 3 * StkElt */ +/* */ +static +void Ins_ROLL( INS_ARG ) { + FT_Long A, B, C; + + FT_UNUSED_EXEC; + + + A = args[2]; + B = args[1]; + C = args[0]; + + args[2] = C; + args[1] = A; + args[0] = B; +} + + +/*************************************************************************/ +/* */ +/* MANAGING THE FLOW OF CONTROL */ +/* */ +/* Instructions appear in the specification's order. */ +/* */ +/*************************************************************************/ + + +static +FT_Bool SkipCode( EXEC_OP ) { + CUR.IP += CUR.length; + + if ( CUR.IP < CUR.codeSize ) { + CUR.opcode = CUR.code[CUR.IP]; + + CUR.length = opcode_length[CUR.opcode]; + if ( CUR.length < 0 ) { + if ( CUR.IP + 1 > CUR.codeSize ) { + goto Fail_Overflow; + } + CUR.length = CUR.code[CUR.IP + 1] + 2; + } + + if ( CUR.IP + CUR.length <= CUR.codeSize ) { + return SUCCESS; + } + } + +Fail_Overflow: + CUR.error = TT_Err_Code_Overflow; + return FAILURE; +} + + +/*************************************************************************/ +/* */ +/* IF[]: IF test */ +/* Opcode range: 0x58 */ +/* Stack: StkElt --> */ +/* */ +static +void Ins_IF( INS_ARG ) { + FT_Int nIfs; + FT_Bool Out; + + + if ( args[0] != 0 ) { + return; + } + + nIfs = 1; + Out = 0; + + do + { + if ( SKIP_Code() == FAILURE ) { + return; + } + + switch ( CUR.opcode ) + { + case 0x58: /* IF */ + nIfs++; + break; + + case 0x1B: /* ELSE */ + Out = ( nIfs == 1 ); + break; + + case 0x59: /* EIF */ + nIfs--; + Out = ( nIfs == 0 ); + break; + } + } while ( Out == 0 ); +} + + +/*************************************************************************/ +/* */ +/* ELSE[]: ELSE */ +/* Opcode range: 0x1B */ +/* Stack: --> */ +/* */ +static +void Ins_ELSE( INS_ARG ) { + FT_Int nIfs; + + FT_UNUSED_ARG; + + + nIfs = 1; + + do + { + if ( SKIP_Code() == FAILURE ) { + return; + } + + switch ( CUR.opcode ) + { + case 0x58: /* IF */ + nIfs++; + break; + + case 0x59: /* EIF */ + nIfs--; + break; + } + } while ( nIfs != 0 ); +} + + +/*************************************************************************/ +/* */ +/* DEFINING AND USING FUNCTIONS AND INSTRUCTIONS */ +/* */ +/* Instructions appear in the specification's order. */ +/* */ +/*************************************************************************/ + + +/*************************************************************************/ +/* */ +/* FDEF[]: Function DEFinition */ +/* Opcode range: 0x2C */ +/* Stack: uint32 --> */ +/* */ +static +void Ins_FDEF( INS_ARG ) { + FT_ULong n; + TT_DefRecord* rec; + TT_DefRecord* limit; + + + /* some font programs are broken enough to redefine functions! */ + /* We will then parse the current table. */ + + rec = CUR.FDefs; + limit = rec + CUR.numFDefs; + n = args[0]; + + for ( ; rec < limit; rec++ ) + { + if ( rec->opc == n ) { + break; + } + } + + if ( rec == limit ) { + /* check that there is enough room for new functions */ + if ( CUR.numFDefs >= CUR.maxFDefs ) { + CUR.error = TT_Err_Too_Many_Function_Defs; + return; + } + CUR.numFDefs++; + } + + rec->range = CUR.curRange; + rec->opc = n; + rec->start = CUR.IP + 1; + rec->active = TRUE; + + if ( n > CUR.maxFunc ) { + CUR.maxFunc = n; + } + + /* Now skip the whole function definition. */ + /* We don't allow nested IDEFS & FDEFs. */ + + while ( SKIP_Code() == SUCCESS ) + { + switch ( CUR.opcode ) + { + case 0x89: /* IDEF */ + case 0x2C: /* FDEF */ + CUR.error = TT_Err_Nested_DEFS; + return; + + case 0x2D: /* ENDF */ + return; + } + } +} + + +/*************************************************************************/ +/* */ +/* ENDF[]: END Function definition */ +/* Opcode range: 0x2D */ +/* Stack: --> */ +/* */ +static +void Ins_ENDF( INS_ARG ) { + TT_CallRec* pRec; + + FT_UNUSED_ARG; + + + if ( CUR.callTop <= 0 ) { /* We encountered an ENDF without a call */ + CUR.error = TT_Err_ENDF_In_Exec_Stream; + return; + } + + CUR.callTop--; + + pRec = &CUR.callStack[CUR.callTop]; + + pRec->Cur_Count--; + + CUR.step_ins = FALSE; + + if ( pRec->Cur_Count > 0 ) { + CUR.callTop++; + CUR.IP = pRec->Cur_Restart; + } else { + /* Loop through the current function */ + INS_Goto_CodeRange( pRec->Caller_Range, + pRec->Caller_IP ); + } + + /* Exit the current call frame. */ + + /* NOTE: If the last intruction of a program is a */ + /* CALL or LOOPCALL, the return address is */ + /* always out of the code range. This is a */ + /* valid address, and it is why we do not test */ + /* the result of Ins_Goto_CodeRange() here! */ +} + + +/*************************************************************************/ +/* */ +/* CALL[]: CALL function */ +/* Opcode range: 0x2B */ +/* Stack: uint32? --> */ +/* */ +static +void Ins_CALL( INS_ARG ) { + FT_ULong F; + TT_CallRec* pCrec; + TT_DefRecord* def; + + + /* first of all, check the index */ + + F = args[0]; + if ( BOUNDS( F, CUR.maxFunc + 1 ) ) { + goto Fail; + } + + /* Except for some old Apple fonts, all functions in a TrueType */ + /* font are defined in increasing order, starting from 0. This */ + /* means that we normally have */ + /* */ + /* CUR.maxFunc+1 == CUR.numFDefs */ + /* CUR.FDefs[n].opc == n for n in 0..CUR.maxFunc */ + /* */ + /* If this isn't true, we need to look up the function table. */ + + def = CUR.FDefs + F; + if ( CUR.maxFunc + 1 != CUR.numFDefs || def->opc != F ) { + /* look up the FDefs table */ + TT_DefRecord* limit; + + + def = CUR.FDefs; + limit = def + CUR.numFDefs; + + while ( def < limit && def->opc != F ) + def++; + + if ( def == limit ) { + goto Fail; + } + } + + /* check that the function is active */ + if ( !def->active ) { + goto Fail; + } + + /* check the call stack */ + if ( CUR.callTop >= CUR.callSize ) { + CUR.error = TT_Err_Stack_Overflow; + return; + } + + pCrec = CUR.callStack + CUR.callTop; + + pCrec->Caller_Range = CUR.curRange; + pCrec->Caller_IP = CUR.IP + 1; + pCrec->Cur_Count = 1; + pCrec->Cur_Restart = def->start; + + CUR.callTop++; + + INS_Goto_CodeRange( def->range, + def->start ); + + CUR.step_ins = FALSE; + return; + +Fail: + CUR.error = TT_Err_Invalid_Reference; +} + + +/*************************************************************************/ +/* */ +/* LOOPCALL[]: LOOP and CALL function */ +/* Opcode range: 0x2A */ +/* Stack: uint32? Eint16? --> */ +/* */ +static +void Ins_LOOPCALL( INS_ARG ) { + FT_ULong F; + TT_CallRec* pCrec; + TT_DefRecord* def; + + + /* first of all, check the index */ + F = args[1]; + if ( BOUNDS( F, CUR.maxFunc + 1 ) ) { + goto Fail; + } + + /* Except for some old Apple fonts, all functions in a TrueType */ + /* font are defined in increasing order, starting from 0. This */ + /* means that we normally have */ + /* */ + /* CUR.maxFunc+1 == CUR.numFDefs */ + /* CUR.FDefs[n].opc == n for n in 0..CUR.maxFunc */ + /* */ + /* If this isn't true, we need to look up the function table. */ + + def = CUR.FDefs + F; + if ( CUR.maxFunc + 1 != CUR.numFDefs || def->opc != F ) { + /* look up the FDefs table */ + TT_DefRecord* limit; + + + def = CUR.FDefs; + limit = def + CUR.numFDefs; + + while ( def < limit && def->opc != F ) + def++; + + if ( def == limit ) { + goto Fail; + } + } + + /* check that the function is active */ + if ( !def->active ) { + goto Fail; + } + + /* check stack */ + if ( CUR.callTop >= CUR.callSize ) { + CUR.error = TT_Err_Stack_Overflow; + return; + } + + if ( args[0] > 0 ) { + pCrec = CUR.callStack + CUR.callTop; + + pCrec->Caller_Range = CUR.curRange; + pCrec->Caller_IP = CUR.IP + 1; + pCrec->Cur_Count = (FT_Int)args[0]; + pCrec->Cur_Restart = def->start; + + CUR.callTop++; + + INS_Goto_CodeRange( def->range, def->start ); + + CUR.step_ins = FALSE; + } + return; + +Fail: + CUR.error = TT_Err_Invalid_Reference; +} + + +/*************************************************************************/ +/* */ +/* IDEF[]: Instruction DEFinition */ +/* Opcode range: 0x89 */ +/* Stack: Eint8 --> */ +/* */ +static +void Ins_IDEF( INS_ARG ) { + TT_DefRecord* def; + TT_DefRecord* limit; + + + /* First of all, look for the same function in our table */ + + def = CUR.IDefs; + limit = def + CUR.numIDefs; + + for ( ; def < limit; def++ ) + if ( def->opc == (FT_ULong)args[0] ) { + break; + } + + if ( def == limit ) { + /* check that there is enough room for a new instruction */ + if ( CUR.numIDefs >= CUR.maxIDefs ) { + CUR.error = TT_Err_Too_Many_Instruction_Defs; + return; + } + CUR.numIDefs++; + } + + def->opc = args[0]; + def->start = CUR.IP + 1; + def->range = CUR.curRange; + def->active = TRUE; + + if ( (FT_ULong)args[0] > CUR.maxIns ) { + CUR.maxIns = args[0]; + } + + /* Now skip the whole function definition. */ + /* We don't allow nested IDEFs & FDEFs. */ + + while ( SKIP_Code() == SUCCESS ) + { + switch ( CUR.opcode ) + { + case 0x89: /* IDEF */ + case 0x2C: /* FDEF */ + CUR.error = TT_Err_Nested_DEFS; + return; + case 0x2D: /* ENDF */ + return; + } + } +} + + +/*************************************************************************/ +/* */ +/* PUSHING DATA ONTO THE INTERPRETER STACK */ +/* */ +/* Instructions appear in the specification's order. */ +/* */ +/*************************************************************************/ + + +/*************************************************************************/ +/* */ +/* NPUSHB[]: PUSH N Bytes */ +/* Opcode range: 0x40 */ +/* Stack: --> uint32... */ +/* */ +static +void Ins_NPUSHB( INS_ARG ) { + FT_UShort L, K; + + + L = (FT_UShort)CUR.code[CUR.IP + 1]; + + if ( BOUNDS( L, CUR.stackSize + 1 - CUR.top ) ) { + CUR.error = TT_Err_Stack_Overflow; + return; + } + + for ( K = 1; K <= L; K++ ) + args[K - 1] = CUR.code[CUR.IP + K + 1]; + + CUR.new_top += L; +} + + +/*************************************************************************/ +/* */ +/* NPUSHW[]: PUSH N Words */ +/* Opcode range: 0x41 */ +/* Stack: --> int32... */ +/* */ +static +void Ins_NPUSHW( INS_ARG ) { + FT_UShort L, K; + + + L = (FT_UShort)CUR.code[CUR.IP + 1]; + + if ( BOUNDS( L, CUR.stackSize + 1 - CUR.top ) ) { + CUR.error = TT_Err_Stack_Overflow; + return; + } + + CUR.IP += 2; + + for ( K = 0; K < L; K++ ) + args[K] = GET_ShortIns(); + + CUR.step_ins = FALSE; + CUR.new_top += L; +} + + +/*************************************************************************/ +/* */ +/* PUSHB[abc]: PUSH Bytes */ +/* Opcode range: 0xB0-0xB7 */ +/* Stack: --> uint32... */ +/* */ +static +void Ins_PUSHB( INS_ARG ) { + FT_UShort L, K; + + + L = (FT_UShort)CUR.opcode - 0xB0 + 1; + + if ( BOUNDS( L, CUR.stackSize + 1 - CUR.top ) ) { + CUR.error = TT_Err_Stack_Overflow; + return; + } + + for ( K = 1; K <= L; K++ ) + args[K - 1] = CUR.code[CUR.IP + K]; +} + + +/*************************************************************************/ +/* */ +/* PUSHW[abc]: PUSH Words */ +/* Opcode range: 0xB8-0xBF */ +/* Stack: --> int32... */ +/* */ +static +void Ins_PUSHW( INS_ARG ) { + FT_UShort L, K; + + + L = (FT_UShort)CUR.opcode - 0xB8 + 1; + + if ( BOUNDS( L, CUR.stackSize + 1 - CUR.top ) ) { + CUR.error = TT_Err_Stack_Overflow; + return; + } + + CUR.IP++; + + for ( K = 0; K < L; K++ ) + args[K] = GET_ShortIns(); + + CUR.step_ins = FALSE; +} + + +/*************************************************************************/ +/* */ +/* MANAGING THE GRAPHICS STATE */ +/* */ +/* Instructions appear in the specs' order. */ +/* */ +/*************************************************************************/ + + +/*************************************************************************/ +/* */ +/* GC[a]: Get Coordinate projected onto */ +/* Opcode range: 0x46-0x47 */ +/* Stack: uint32 --> f26.6 */ +/* */ +/* BULLSHIT: Measures from the original glyph must be taken along the */ +/* dual projection vector! */ +/* */ +static void Ins_GC( INS_ARG ) { + FT_ULong L; + FT_F26Dot6 R; + + + L = (FT_ULong)args[0]; + + if ( BOUNDS( L, CUR.zp2.n_points ) ) { + if ( CUR.pedantic_hinting ) { + CUR.error = TT_Err_Invalid_Reference; + return; + } else { + R = 0; + } + } else + { + if ( CUR.opcode & 1 ) { + R = CUR_Func_dualproj( CUR.zp2.org + L, NULL_Vector ); + } else { + R = CUR_Func_project( CUR.zp2.cur + L, NULL_Vector ); + } + } + + args[0] = R; +} + + +/*************************************************************************/ +/* */ +/* SCFS[]: Set Coordinate From Stack */ +/* Opcode range: 0x48 */ +/* Stack: f26.6 uint32 --> */ +/* */ +/* Formula: */ +/* */ +/* OA := OA + ( value - OA.p )/( f.p ) * f */ +/* */ +static +void Ins_SCFS( INS_ARG ) { + FT_Long K; + FT_UShort L; + + + L = (FT_UShort)args[0]; + + if ( BOUNDS( L, CUR.zp2.n_points ) ) { + if ( CUR.pedantic_hinting ) { + CUR.error = TT_Err_Invalid_Reference; + } + return; + } + + K = CUR_Func_project( CUR.zp2.cur + L, NULL_Vector ); + + CUR_Func_move( &CUR.zp2, L, args[1] - K ); + + /* not part of the specs, but here for safety */ + + if ( CUR.GS.gep2 == 0 ) { + CUR.zp2.org[L] = CUR.zp2.cur[L]; + } +} + + +/*************************************************************************/ +/* */ +/* MD[a]: Measure Distance */ +/* Opcode range: 0x49-0x4A */ +/* Stack: uint32 uint32 --> f26.6 */ +/* */ +/* BULLSHIT: Measure taken in the original glyph must be along the dual */ +/* projection vector. */ +/* */ +/* Second BULLSHIT: Flag attributes are inverted! */ +/* 0 => measure distance in original outline */ +/* 1 => measure distance in grid-fitted outline */ +/* */ +/* Third one: `zp0 - zp1', and not `zp2 - zp1! */ +/* */ +static +void Ins_MD( INS_ARG ) { + FT_UShort K, L; + FT_F26Dot6 D; + + + K = (FT_UShort)args[1]; + L = (FT_UShort)args[0]; + + if ( BOUNDS( L, CUR.zp0.n_points ) || + BOUNDS( K, CUR.zp1.n_points ) ) { + if ( CUR.pedantic_hinting ) { + CUR.error = TT_Err_Invalid_Reference; + return; + } + D = 0; + } else + { + if ( CUR.opcode & 1 ) { + D = CUR_Func_project( CUR.zp0.cur + L, CUR.zp1.cur + K ); + } else { + D = CUR_Func_dualproj( CUR.zp0.org + L, CUR.zp1.org + K ); + } + } + + args[0] = D; +} + + +/*************************************************************************/ +/* */ +/* SDPVTL[a]: Set Dual PVector to Line */ +/* Opcode range: 0x86-0x87 */ +/* Stack: uint32 uint32 --> */ +/* */ +static +void Ins_SDPVTL( INS_ARG ) { + FT_Long A, B, C; + FT_UShort p1, p2; /* was FT_Int in pas type ERROR */ + + + p1 = (FT_UShort)args[1]; + p2 = (FT_UShort)args[0]; + + if ( BOUNDS( p2, CUR.zp1.n_points ) || + BOUNDS( p1, CUR.zp2.n_points ) ) { + if ( CUR.pedantic_hinting ) { + CUR.error = TT_Err_Invalid_Reference; + } + return; + } + + { + FT_Vector* v1 = CUR.zp1.org + p2; + FT_Vector* v2 = CUR.zp2.org + p1; + + + A = v1->x - v2->x; + B = v1->y - v2->y; + } + + if ( ( CUR.opcode & 1 ) != 0 ) { + C = B; /* counter clockwise rotation */ + B = A; + A = -C; + } + + NORMalize( A, B, &CUR.GS.dualVector ); + + { + FT_Vector* v1 = CUR.zp1.cur + p2; + FT_Vector* v2 = CUR.zp2.cur + p1; + + + A = v1->x - v2->x; + B = v1->y - v2->y; + } + + if ( ( CUR.opcode & 1 ) != 0 ) { + C = B; /* counter clockwise rotation */ + B = A; + A = -C; + } + + NORMalize( A, B, &CUR.GS.projVector ); + + COMPUTE_Funcs(); +} + + +/*************************************************************************/ +/* */ +/* SZP0[]: Set Zone Pointer 0 */ +/* Opcode range: 0x13 */ +/* Stack: uint32 --> */ +/* */ +static +void Ins_SZP0( INS_ARG ) { + switch ( (FT_Int)args[0] ) + { + case 0: + CUR.zp0 = CUR.twilight; + break; + + case 1: + CUR.zp0 = CUR.pts; + break; + + default: + if ( CUR.pedantic_hinting ) { + CUR.error = TT_Err_Invalid_Reference; + } + return; + } + + CUR.GS.gep0 = (FT_UShort)args[0]; +} + + +/*************************************************************************/ +/* */ +/* SZP1[]: Set Zone Pointer 1 */ +/* Opcode range: 0x14 */ +/* Stack: uint32 --> */ +/* */ +static +void Ins_SZP1( INS_ARG ) { + switch ( (FT_Int)args[0] ) + { + case 0: + CUR.zp1 = CUR.twilight; + break; + + case 1: + CUR.zp1 = CUR.pts; + break; + + default: + if ( CUR.pedantic_hinting ) { + CUR.error = TT_Err_Invalid_Reference; + } + return; + } + + CUR.GS.gep1 = (FT_UShort)args[0]; +} + + +/*************************************************************************/ +/* */ +/* SZP2[]: Set Zone Pointer 2 */ +/* Opcode range: 0x15 */ +/* Stack: uint32 --> */ +/* */ +static +void Ins_SZP2( INS_ARG ) { + switch ( (FT_Int)args[0] ) + { + case 0: + CUR.zp2 = CUR.twilight; + break; + + case 1: + CUR.zp2 = CUR.pts; + break; + + default: + if ( CUR.pedantic_hinting ) { + CUR.error = TT_Err_Invalid_Reference; + } + return; + } + + CUR.GS.gep2 = (FT_UShort)args[0]; +} + + +/*************************************************************************/ +/* */ +/* SZPS[]: Set Zone PointerS */ +/* Opcode range: 0x16 */ +/* Stack: uint32 --> */ +/* */ +static +void Ins_SZPS( INS_ARG ) { + switch ( (FT_Int)args[0] ) + { + case 0: + CUR.zp0 = CUR.twilight; + break; + + case 1: + CUR.zp0 = CUR.pts; + break; + + default: + if ( CUR.pedantic_hinting ) { + CUR.error = TT_Err_Invalid_Reference; + } + return; + } + + CUR.zp1 = CUR.zp0; + CUR.zp2 = CUR.zp0; + + CUR.GS.gep0 = (FT_UShort)args[0]; + CUR.GS.gep1 = (FT_UShort)args[0]; + CUR.GS.gep2 = (FT_UShort)args[0]; +} + + +/*************************************************************************/ +/* */ +/* INSTCTRL[]: INSTruction ConTRoL */ +/* Opcode range: 0x8e */ +/* Stack: int32 int32 --> */ +/* */ +static +void Ins_INSTCTRL( INS_ARG ) { + FT_Long K, L; + + + K = args[1]; + L = args[0]; + + if ( K < 1 || K > 2 ) { + if ( CUR.pedantic_hinting ) { + CUR.error = TT_Err_Invalid_Reference; + } + return; + } + + if ( L != 0 ) { + L = K; + } + + CUR.GS.instruct_control = + (FT_Byte)( CUR.GS.instruct_control & ~(FT_Byte)K ) | (FT_Byte)L; +} + + +/*************************************************************************/ +/* */ +/* SCANCTRL[]: SCAN ConTRoL */ +/* Opcode range: 0x85 */ +/* Stack: uint32? --> */ +/* */ +static +void Ins_SCANCTRL( INS_ARG ) { + FT_Int A; + + + /* Get Threshold */ + A = (FT_Int)( args[0] & 0xFF ); + + if ( A == 0xFF ) { + CUR.GS.scan_control = TRUE; + return; + } else if ( A == 0 ) { + CUR.GS.scan_control = FALSE; + return; + } + + A *= 64; + +#if 0 + if ( ( args[0] & 0x100 ) != 0 && CUR.metrics.pointSize <= A ) { + CUR.GS.scan_control = TRUE; + } +#endif + + if ( ( args[0] & 0x200 ) != 0 && CUR.tt_metrics.rotated ) { + CUR.GS.scan_control = TRUE; + } + + if ( ( args[0] & 0x400 ) != 0 && CUR.tt_metrics.stretched ) { + CUR.GS.scan_control = TRUE; + } + +#if 0 + if ( ( args[0] & 0x800 ) != 0 && CUR.metrics.pointSize > A ) { + CUR.GS.scan_control = FALSE; + } +#endif + + if ( ( args[0] & 0x1000 ) != 0 && CUR.tt_metrics.rotated ) { + CUR.GS.scan_control = FALSE; + } + + if ( ( args[0] & 0x2000 ) != 0 && CUR.tt_metrics.stretched ) { + CUR.GS.scan_control = FALSE; + } +} + + +/*************************************************************************/ +/* */ +/* SCANTYPE[]: SCAN TYPE */ +/* Opcode range: 0x8D */ +/* Stack: uint32? --> */ +/* */ +static +void Ins_SCANTYPE( INS_ARG ) { + /* for compatibility with future enhancements, */ + /* we must ignore new modes */ + + if ( args[0] >= 0 && args[0] <= 5 ) { + if ( args[0] == 3 ) { + args[0] = 2; + } + + CUR.GS.scan_type = (FT_Int)args[0]; + } +} + + +/*************************************************************************/ +/* */ +/* MANAGING OUTLINES */ +/* */ +/* Instructions appear in the specification's order. */ +/* */ +/*************************************************************************/ + + +/*************************************************************************/ +/* */ +/* FLIPPT[]: FLIP PoinT */ +/* Opcode range: 0x80 */ +/* Stack: uint32... --> */ +/* */ +static +void Ins_FLIPPT( INS_ARG ) { + FT_UShort point; + + FT_UNUSED_ARG; + + + if ( CUR.top < CUR.GS.loop ) { + CUR.error = TT_Err_Too_Few_Arguments; + return; + } + + while ( CUR.GS.loop > 0 ) + { + CUR.args--; + + point = (FT_UShort)CUR.stack[CUR.args]; + + if ( BOUNDS( point, CUR.pts.n_points ) ) { + if ( CUR.pedantic_hinting ) { + CUR.error = TT_Err_Invalid_Reference; + return; + } + } else { + CUR.pts.tags[point] ^= FT_Curve_Tag_On; + } + + CUR.GS.loop--; + } + + CUR.GS.loop = 1; + CUR.new_top = CUR.args; +} + + +/*************************************************************************/ +/* */ +/* FLIPRGON[]: FLIP RanGe ON */ +/* Opcode range: 0x81 */ +/* Stack: uint32 uint32 --> */ +/* */ +static +void Ins_FLIPRGON( INS_ARG ) { + FT_UShort I, K, L; + + + K = (FT_UShort)args[1]; + L = (FT_UShort)args[0]; + + if ( BOUNDS( K, CUR.pts.n_points ) || + BOUNDS( L, CUR.pts.n_points ) ) { + if ( CUR.pedantic_hinting ) { + CUR.error = TT_Err_Invalid_Reference; + } + return; + } + + for ( I = L; I <= K; I++ ) + CUR.pts.tags[I] |= FT_Curve_Tag_On; +} + + +/*************************************************************************/ +/* */ +/* FLIPRGOFF: FLIP RanGe OFF */ +/* Opcode range: 0x82 */ +/* Stack: uint32 uint32 --> */ +/* */ +static +void Ins_FLIPRGOFF( INS_ARG ) { + FT_UShort I, K, L; + + + K = (FT_UShort)args[1]; + L = (FT_UShort)args[0]; + + if ( BOUNDS( K, CUR.pts.n_points ) || + BOUNDS( L, CUR.pts.n_points ) ) { + if ( CUR.pedantic_hinting ) { + CUR.error = TT_Err_Invalid_Reference; + } + return; + } + + for ( I = L; I <= K; I++ ) + CUR.pts.tags[I] &= ~FT_Curve_Tag_On; +} + + +static +FT_Bool Compute_Point_Displacement( EXEC_OP_ FT_F26Dot6* x, + FT_F26Dot6* y, + TT_GlyphZone* zone, + FT_UShort* refp ) { + TT_GlyphZone zp; + FT_UShort p; + FT_F26Dot6 d; + + + if ( CUR.opcode & 1 ) { + zp = CUR.zp0; + p = CUR.GS.rp1; + } else + { + zp = CUR.zp1; + p = CUR.GS.rp2; + } + + if ( BOUNDS( p, zp.n_points ) ) { + if ( CUR.pedantic_hinting ) { + CUR.error = TT_Err_Invalid_Reference; + } + return FAILURE; + } + + *zone = zp; + *refp = p; + + d = CUR_Func_project( zp.cur + p, zp.org + p ); + +#ifdef NO_APPLE_PATENT + + *x = TT_MULDIV( d, CUR.GS.freeVector.x, 0x4000 ); + *y = TT_MULDIV( d, CUR.GS.freeVector.y, 0x4000 ); + +#else + + *x = TT_MULDIV( d, + (FT_Long)CUR.GS.freeVector.x * 0x10000L, + CUR.F_dot_P ); + *y = TT_MULDIV( d, + (FT_Long)CUR.GS.freeVector.y * 0x10000L, + CUR.F_dot_P ); + +#endif /* NO_APPLE_PATENT */ + + return SUCCESS; +} + + +static +void Move_Zp2_Point( EXEC_OP_ FT_UShort point, + FT_F26Dot6 dx, + FT_F26Dot6 dy, + FT_Bool touch ) { + if ( CUR.GS.freeVector.x != 0 ) { + CUR.zp2.cur[point].x += dx; + if ( touch ) { + CUR.zp2.tags[point] |= FT_Curve_Tag_Touch_X; + } + } + + if ( CUR.GS.freeVector.y != 0 ) { + CUR.zp2.cur[point].y += dy; + if ( touch ) { + CUR.zp2.tags[point] |= FT_Curve_Tag_Touch_Y; + } + } +} + + +/*************************************************************************/ +/* */ +/* SHP[a]: SHift Point by the last point */ +/* Opcode range: 0x32-0x33 */ +/* Stack: uint32... --> */ +/* */ +static +void Ins_SHP( INS_ARG ) { + TT_GlyphZone zp; + FT_UShort refp; + + FT_F26Dot6 dx, + dy; + FT_UShort point; + + FT_UNUSED_ARG; + + + if ( CUR.top < CUR.GS.loop ) { + CUR.error = TT_Err_Invalid_Reference; + return; + } + + if ( COMPUTE_Point_Displacement( &dx, &dy, &zp, &refp ) ) { + return; + } + + while ( CUR.GS.loop > 0 ) + { + CUR.args--; + point = (FT_UShort)CUR.stack[CUR.args]; + + if ( BOUNDS( point, CUR.zp2.n_points ) ) { + if ( CUR.pedantic_hinting ) { + CUR.error = TT_Err_Invalid_Reference; + return; + } + } else { + /* XXX: UNDOCUMENTED! SHP touches the points */ + MOVE_Zp2_Point( point, dx, dy, TRUE ); + } + + CUR.GS.loop--; + } + + CUR.GS.loop = 1; + CUR.new_top = CUR.args; +} + + +/*************************************************************************/ +/* */ +/* SHC[a]: SHift Contour */ +/* Opcode range: 0x34-35 */ +/* Stack: uint32 --> */ +/* */ +static +void Ins_SHC( INS_ARG ) { + TT_GlyphZone zp; + FT_UShort refp; + FT_F26Dot6 dx, + dy; + + FT_Short contour; + FT_UShort first_point, last_point, i; + + + contour = (FT_UShort)args[0]; + + if ( BOUNDS( contour, CUR.pts.n_contours ) ) { + if ( CUR.pedantic_hinting ) { + CUR.error = TT_Err_Invalid_Reference; + } + return; + } + + if ( COMPUTE_Point_Displacement( &dx, &dy, &zp, &refp ) ) { + return; + } + + if ( contour == 0 ) { + first_point = 0; + } else { + first_point = CUR.pts.contours[contour - 1] + 1; + } + + last_point = CUR.pts.contours[contour]; + + /* XXX: this is probably wrong... at least it prevents memory */ + /* corruption when zp2 is the twilight zone */ + if ( last_point > CUR.zp2.n_points ) { + if ( CUR.zp2.n_points > 0 ) { + last_point = CUR.zp2.n_points - 1; + } else { + last_point = 0; + } + } + + /* XXX: UNDOCUMENTED! SHC doesn't touch the points */ + for ( i = first_point; i <= last_point; i++ ) + { + if ( zp.cur != CUR.zp2.cur || refp != i ) { + MOVE_Zp2_Point( i, dx, dy, FALSE ); + } + } +} + + +/*************************************************************************/ +/* */ +/* SHZ[a]: SHift Zone */ +/* Opcode range: 0x36-37 */ +/* Stack: uint32 --> */ +/* */ +static +void Ins_SHZ( INS_ARG ) { + TT_GlyphZone zp; + FT_UShort refp; + FT_F26Dot6 dx, + dy; + + FT_UShort last_point, i; + + + if ( BOUNDS( args[0], 2 ) ) { + if ( CUR.pedantic_hinting ) { + CUR.error = TT_Err_Invalid_Reference; + } + return; + } + + if ( COMPUTE_Point_Displacement( &dx, &dy, &zp, &refp ) ) { + return; + } + + if ( CUR.zp2.n_points > 0 ) { + last_point = CUR.zp2.n_points - 1; + } else { + last_point = 0; + } + + /* XXX: UNDOCUMENTED! SHZ doesn't touch the points */ + for ( i = 0; i <= last_point; i++ ) + { + if ( zp.cur != CUR.zp2.cur || refp != i ) { + MOVE_Zp2_Point( i, dx, dy, FALSE ); + } + } +} + + +/*************************************************************************/ +/* */ +/* SHPIX[]: SHift points by a PIXel amount */ +/* Opcode range: 0x38 */ +/* Stack: f26.6 uint32... --> */ +/* */ +static +void Ins_SHPIX( INS_ARG ) { + FT_F26Dot6 dx, dy; + FT_UShort point; + + + if ( CUR.top < CUR.GS.loop + 1 ) { + CUR.error = TT_Err_Invalid_Reference; + return; + } + + dx = TT_MULDIV( args[0], + (FT_Long)CUR.GS.freeVector.x, + 0x4000 ); + dy = TT_MULDIV( args[0], + (FT_Long)CUR.GS.freeVector.y, + 0x4000 ); + + while ( CUR.GS.loop > 0 ) + { + CUR.args--; + + point = (FT_UShort)CUR.stack[CUR.args]; + + if ( BOUNDS( point, CUR.zp2.n_points ) ) { + if ( CUR.pedantic_hinting ) { + CUR.error = TT_Err_Invalid_Reference; + return; + } + } else { + MOVE_Zp2_Point( point, dx, dy, TRUE ); + } + + CUR.GS.loop--; + } + + CUR.GS.loop = 1; + CUR.new_top = CUR.args; +} + + +/*************************************************************************/ +/* */ +/* MSIRP[a]: Move Stack Indirect Relative Position */ +/* Opcode range: 0x3A-0x3B */ +/* Stack: f26.6 uint32 --> */ +/* */ +static +void Ins_MSIRP( INS_ARG ) { + FT_UShort point; + FT_F26Dot6 distance; + + + point = (FT_UShort)args[0]; + + if ( BOUNDS( point, CUR.zp1.n_points ) || + BOUNDS( CUR.GS.rp0, CUR.zp0.n_points ) ) { + if ( CUR.pedantic_hinting ) { + CUR.error = TT_Err_Invalid_Reference; + } + return; + } + + /* XXX: UNDOCUMENTED! behaviour */ + if ( CUR.GS.gep0 == 0 ) { /* if in twilight zone */ + CUR.zp1.org[point] = CUR.zp0.org[CUR.GS.rp0]; + CUR.zp1.cur[point] = CUR.zp1.org[point]; + } + + distance = CUR_Func_project( CUR.zp1.cur + point, + CUR.zp0.cur + CUR.GS.rp0 ); + + CUR_Func_move( &CUR.zp1, point, args[1] - distance ); + + CUR.GS.rp1 = CUR.GS.rp0; + CUR.GS.rp2 = point; + + if ( ( CUR.opcode & 1 ) != 0 ) { + CUR.GS.rp0 = point; + } +} + + +/*************************************************************************/ +/* */ +/* MDAP[a]: Move Direct Absolute Point */ +/* Opcode range: 0x2E-0x2F */ +/* Stack: uint32 --> */ +/* */ +static +void Ins_MDAP( INS_ARG ) { + FT_UShort point; + FT_F26Dot6 cur_dist, + distance; + + + point = (FT_UShort)args[0]; + + if ( BOUNDS( point, CUR.zp0.n_points ) ) { + if ( CUR.pedantic_hinting ) { + CUR.error = TT_Err_Invalid_Reference; + } + return; + } + + /* XXX: Is there some undocumented feature while in the */ + /* twilight zone? ? */ + if ( ( CUR.opcode & 1 ) != 0 ) { + cur_dist = CUR_Func_project( CUR.zp0.cur + point, NULL_Vector ); + distance = CUR_Func_round( cur_dist, + CUR.tt_metrics.compensations[0] ) - cur_dist; + } else { + distance = 0; + } + + CUR_Func_move( &CUR.zp0, point, distance ); + + CUR.GS.rp0 = point; + CUR.GS.rp1 = point; +} + + +/*************************************************************************/ +/* */ +/* MIAP[a]: Move Indirect Absolute Point */ +/* Opcode range: 0x3E-0x3F */ +/* Stack: uint32 uint32 --> */ +/* */ +static +void Ins_MIAP( INS_ARG ) { + FT_ULong cvtEntry; + FT_UShort point; + FT_F26Dot6 distance, + org_dist; + + + cvtEntry = (FT_ULong)args[1]; + point = (FT_UShort)args[0]; + + if ( BOUNDS( point, CUR.zp0.n_points ) || + BOUNDS( cvtEntry, CUR.cvtSize ) ) { + if ( CUR.pedantic_hinting ) { + CUR.error = TT_Err_Invalid_Reference; + } + return; + } + + /* UNDOCUMENTED! */ + /* */ + /* The behaviour of an MIAP instruction is quite */ + /* different when used in the twilight zone. */ + /* */ + /* First, no control value cutin test is performed */ + /* as it would fail anyway. Second, the original */ + /* point, i.e. (org_x,org_y) of zp0.point, is set */ + /* to the absolute, unrounded distance found in */ + /* the CVT. */ + /* */ + /* This is used in the CVT programs of the Microsoft */ + /* fonts Arial, Times, etc., in order to re-adjust */ + /* some key font heights. It allows the use of the */ + /* IP instruction in the twilight zone, which */ + /* otherwise would be `illegal' according to the */ + /* specification. */ + /* */ + /* We implement it with a special sequence for the */ + /* twilight zone. This is a bad hack, but it seems */ + /* to work. */ + + distance = CUR_Func_read_cvt( cvtEntry ); + + if ( CUR.GS.gep0 == 0 ) { /* If in twilight zone */ + CUR.zp0.org[point].x = TT_MULDIV( CUR.GS.freeVector.x, + distance, 0x4000 ); + CUR.zp0.org[point].y = TT_MULDIV( CUR.GS.freeVector.y, + distance, 0x4000 ); + CUR.zp0.cur[point] = CUR.zp0.org[point]; + } + + org_dist = CUR_Func_project( CUR.zp0.cur + point, NULL_Vector ); + + if ( ( CUR.opcode & 1 ) != 0 ) { /* rounding and control cutin flag */ + if ( ABS( distance - org_dist ) > CUR.GS.control_value_cutin ) { + distance = org_dist; + } + + distance = CUR_Func_round( distance, CUR.tt_metrics.compensations[0] ); + } + + CUR_Func_move( &CUR.zp0, point, distance - org_dist ); + + CUR.GS.rp0 = point; + CUR.GS.rp1 = point; +} + + +/*************************************************************************/ +/* */ +/* MDRP[abcde]: Move Direct Relative Point */ +/* Opcode range: 0xC0-0xDF */ +/* Stack: uint32 --> */ +/* */ +static +void Ins_MDRP( INS_ARG ) { + FT_UShort point; + FT_F26Dot6 org_dist, distance; + + + point = (FT_UShort)args[0]; + + if ( BOUNDS( point, CUR.zp1.n_points ) || + BOUNDS( CUR.GS.rp0, CUR.zp0.n_points ) ) { + if ( CUR.pedantic_hinting ) { + CUR.error = TT_Err_Invalid_Reference; + } + return; + } + + /* XXX: Is there some undocumented feature while in the */ + /* twilight zone? */ + + org_dist = CUR_Func_dualproj( CUR.zp1.org + point, + CUR.zp0.org + CUR.GS.rp0 ); + + /* single width cutin test */ + + if ( ABS( org_dist ) < CUR.GS.single_width_cutin ) { + if ( org_dist >= 0 ) { + org_dist = CUR.GS.single_width_value; + } else { + org_dist = -CUR.GS.single_width_value; + } + } + + /* round flag */ + + if ( ( CUR.opcode & 4 ) != 0 ) { + distance = CUR_Func_round( + org_dist, + CUR.tt_metrics.compensations[CUR.opcode & 3] ); + } else { + distance = ROUND_None( + org_dist, + CUR.tt_metrics.compensations[CUR.opcode & 3] ); + } + + /* minimum distance flag */ + + if ( ( CUR.opcode & 8 ) != 0 ) { + if ( org_dist >= 0 ) { + if ( distance < CUR.GS.minimum_distance ) { + distance = CUR.GS.minimum_distance; + } + } else + { + if ( distance > -CUR.GS.minimum_distance ) { + distance = -CUR.GS.minimum_distance; + } + } + } + + /* now move the point */ + + org_dist = CUR_Func_project( CUR.zp1.cur + point, + CUR.zp0.cur + CUR.GS.rp0 ); + + CUR_Func_move( &CUR.zp1, point, distance - org_dist ); + + CUR.GS.rp1 = CUR.GS.rp0; + CUR.GS.rp2 = point; + + if ( ( CUR.opcode & 16 ) != 0 ) { + CUR.GS.rp0 = point; + } +} + + +/*************************************************************************/ +/* */ +/* MIRP[abcde]: Move Indirect Relative Point */ +/* Opcode range: 0xE0-0xFF */ +/* Stack: int32? uint32 --> */ +/* */ +static +void Ins_MIRP( INS_ARG ) { + FT_UShort point; + FT_ULong cvtEntry; + + FT_F26Dot6 cvt_dist, + distance, + cur_dist, + org_dist; + + + point = (FT_UShort)args[0]; + cvtEntry = (FT_ULong)( args[1] + 1 ); + + /* XXX: UNDOCUMENTED! cvt[-1] = 0 always */ + + if ( BOUNDS( point, CUR.zp1.n_points ) || + BOUNDS( cvtEntry, CUR.cvtSize + 1 ) || + BOUNDS( CUR.GS.rp0, CUR.zp0.n_points ) ) { + if ( CUR.pedantic_hinting ) { + CUR.error = TT_Err_Invalid_Reference; + } + return; + } + + if ( !cvtEntry ) { + cvt_dist = 0; + } else { + cvt_dist = CUR_Func_read_cvt( cvtEntry - 1 ); + } + + /* single width test */ + + if ( ABS( cvt_dist ) < CUR.GS.single_width_cutin ) { + if ( cvt_dist >= 0 ) { + cvt_dist = CUR.GS.single_width_value; + } else { + cvt_dist = -CUR.GS.single_width_value; + } + } + + /* XXX: UNDOCUMENTED! -- twilight zone */ + + if ( CUR.GS.gep1 == 0 ) { + CUR.zp1.org[point].x = CUR.zp0.org[CUR.GS.rp0].x + + TT_MULDIV( cvt_dist, + CUR.GS.freeVector.x, + 0x4000 ); + + CUR.zp1.org[point].y = CUR.zp0.org[CUR.GS.rp0].y + + TT_MULDIV( cvt_dist, + CUR.GS.freeVector.y, + 0x4000 ); + + CUR.zp1.cur[point] = CUR.zp1.org[point]; + } + + org_dist = CUR_Func_dualproj( CUR.zp1.org + point, + CUR.zp0.org + CUR.GS.rp0 ); + + cur_dist = CUR_Func_project( CUR.zp1.cur + point, + CUR.zp0.cur + CUR.GS.rp0 ); + + /* auto-flip test */ + + if ( CUR.GS.auto_flip ) { + if ( ( org_dist ^ cvt_dist ) < 0 ) { + cvt_dist = -cvt_dist; + } + } + + /* control value cutin and round */ + + if ( ( CUR.opcode & 4 ) != 0 ) { + /* XXX: UNDOCUMENTED! Only perform cut-in test when both points */ + /* refer to the same zone. */ + + if ( CUR.GS.gep0 == CUR.GS.gep1 ) { + if ( ABS( cvt_dist - org_dist ) >= CUR.GS.control_value_cutin ) { + cvt_dist = org_dist; + } + } + + distance = CUR_Func_round( + cvt_dist, + CUR.tt_metrics.compensations[CUR.opcode & 3] ); + } else { + distance = ROUND_None( + cvt_dist, + CUR.tt_metrics.compensations[CUR.opcode & 3] ); + } + + /* minimum distance test */ + + if ( ( CUR.opcode & 8 ) != 0 ) { + if ( org_dist >= 0 ) { + if ( distance < CUR.GS.minimum_distance ) { + distance = CUR.GS.minimum_distance; + } + } else + { + if ( distance > -CUR.GS.minimum_distance ) { + distance = -CUR.GS.minimum_distance; + } + } + } + + CUR_Func_move( &CUR.zp1, point, distance - cur_dist ); + + CUR.GS.rp1 = CUR.GS.rp0; + + if ( ( CUR.opcode & 16 ) != 0 ) { + CUR.GS.rp0 = point; + } + + /* XXX: UNDOCUMENTED! */ + + CUR.GS.rp2 = point; +} + + +/*************************************************************************/ +/* */ +/* ALIGNRP[]: ALIGN Relative Point */ +/* Opcode range: 0x3C */ +/* Stack: uint32 uint32... --> */ +/* */ +static +void Ins_ALIGNRP( INS_ARG ) { + FT_UShort point; + FT_F26Dot6 distance; + + FT_UNUSED_ARG; + + + if ( CUR.top < CUR.GS.loop || + BOUNDS( CUR.GS.rp0, CUR.zp0.n_points ) ) { + if ( CUR.pedantic_hinting ) { + CUR.error = TT_Err_Invalid_Reference; + } + return; + } + + while ( CUR.GS.loop > 0 ) + { + CUR.args--; + + point = (FT_UShort)CUR.stack[CUR.args]; + + if ( BOUNDS( point, CUR.zp1.n_points ) ) { + if ( CUR.pedantic_hinting ) { + CUR.error = TT_Err_Invalid_Reference; + return; + } + } else + { + distance = CUR_Func_project( CUR.zp1.cur + point, + CUR.zp0.cur + CUR.GS.rp0 ); + + CUR_Func_move( &CUR.zp1, point, -distance ); + } + + CUR.GS.loop--; + } + + CUR.GS.loop = 1; + CUR.new_top = CUR.args; +} + + +/*************************************************************************/ +/* */ +/* ISECT[]: moves point to InterSECTion */ +/* Opcode range: 0x0F */ +/* Stack: 5 * uint32 --> */ +/* */ +static +void Ins_ISECT( INS_ARG ) { + FT_UShort point, + a0, a1, + b0, b1; + + FT_F26Dot6 discriminant; + + FT_F26Dot6 dx, dy, + dax, day, + dbx, dby; + + FT_F26Dot6 val; + + FT_Vector R; + + + point = (FT_UShort)args[0]; + + a0 = (FT_UShort)args[1]; + a1 = (FT_UShort)args[2]; + b0 = (FT_UShort)args[3]; + b1 = (FT_UShort)args[4]; + + if ( BOUNDS( b0, CUR.zp0.n_points ) || + BOUNDS( b1, CUR.zp0.n_points ) || + BOUNDS( a0, CUR.zp1.n_points ) || + BOUNDS( a1, CUR.zp1.n_points ) || + BOUNDS( point, CUR.zp2.n_points ) ) { + if ( CUR.pedantic_hinting ) { + CUR.error = TT_Err_Invalid_Reference; + } + return; + } + + dbx = CUR.zp0.cur[b1].x - CUR.zp0.cur[b0].x; + dby = CUR.zp0.cur[b1].y - CUR.zp0.cur[b0].y; + + dax = CUR.zp1.cur[a1].x - CUR.zp1.cur[a0].x; + day = CUR.zp1.cur[a1].y - CUR.zp1.cur[a0].y; + + dx = CUR.zp0.cur[b0].x - CUR.zp1.cur[a0].x; + dy = CUR.zp0.cur[b0].y - CUR.zp1.cur[a0].y; + + CUR.zp2.tags[point] |= FT_Curve_Tag_Touch_Both; + + discriminant = TT_MULDIV( dax, -dby, 0x40 ) + + TT_MULDIV( day, dbx, 0x40 ); + + if ( ABS( discriminant ) >= 0x40 ) { + val = TT_MULDIV( dx, -dby, 0x40 ) + TT_MULDIV( dy, dbx, 0x40 ); + + R.x = TT_MULDIV( val, dax, discriminant ); + R.y = TT_MULDIV( val, day, discriminant ); + + CUR.zp2.cur[point].x = CUR.zp1.cur[a0].x + R.x; + CUR.zp2.cur[point].y = CUR.zp1.cur[a0].y + R.y; + } else + { + /* else, take the middle of the middles of A and B */ + + CUR.zp2.cur[point].x = ( CUR.zp1.cur[a0].x + + CUR.zp1.cur[a1].x + + CUR.zp0.cur[b0].x + + CUR.zp0.cur[b1].x ) / 4; + CUR.zp2.cur[point].y = ( CUR.zp1.cur[a0].y + + CUR.zp1.cur[a1].y + + CUR.zp0.cur[b0].y + + CUR.zp0.cur[b1].y ) / 4; + } +} + + +/*************************************************************************/ +/* */ +/* ALIGNPTS[]: ALIGN PoinTS */ +/* Opcode range: 0x27 */ +/* Stack: uint32 uint32 --> */ +/* */ +static +void Ins_ALIGNPTS( INS_ARG ) { + FT_UShort p1, p2; + FT_F26Dot6 distance; + + + p1 = (FT_UShort)args[0]; + p2 = (FT_UShort)args[1]; + + if ( BOUNDS( args[0], CUR.zp1.n_points ) || + BOUNDS( args[1], CUR.zp0.n_points ) ) { + if ( CUR.pedantic_hinting ) { + CUR.error = TT_Err_Invalid_Reference; + } + return; + } + + distance = CUR_Func_project( CUR.zp0.cur + p2, + CUR.zp1.cur + p1 ) / 2; + + CUR_Func_move( &CUR.zp1, p1, distance ); + CUR_Func_move( &CUR.zp0, p2, -distance ); +} + + +/*************************************************************************/ +/* */ +/* IP[]: Interpolate Point */ +/* Opcode range: 0x39 */ +/* Stack: uint32... --> */ +/* */ +static +void Ins_IP( INS_ARG ) { + FT_F26Dot6 org_a, org_b, org_x, + cur_a, cur_b, cur_x, + distance; + FT_UShort point; + + FT_UNUSED_ARG; + + + if ( CUR.top < CUR.GS.loop ) { + CUR.error = TT_Err_Invalid_Reference; + return; + } + + /* XXX: There are some glyphs in some braindead but popular */ + /* fonts out there (e.g. [aeu]grave in monotype.ttf) */ + /* calling IP[] with bad values of rp[12]. */ + /* Do something sane when this odd thing happens. */ + + if ( BOUNDS( CUR.GS.rp1, CUR.zp0.n_points ) || + BOUNDS( CUR.GS.rp2, CUR.zp1.n_points ) ) { + org_a = cur_a = 0; + org_b = cur_b = 0; + } else + { + org_a = CUR_Func_dualproj( CUR.zp0.org + CUR.GS.rp1, NULL_Vector ); + org_b = CUR_Func_dualproj( CUR.zp1.org + CUR.GS.rp2, NULL_Vector ); + + cur_a = CUR_Func_project( CUR.zp0.cur + CUR.GS.rp1, NULL_Vector ); + cur_b = CUR_Func_project( CUR.zp1.cur + CUR.GS.rp2, NULL_Vector ); + } + + while ( CUR.GS.loop > 0 ) + { + CUR.args--; + + point = (FT_UShort)CUR.stack[CUR.args]; + if ( BOUNDS( point, CUR.zp2.n_points ) ) { + if ( CUR.pedantic_hinting ) { + CUR.error = TT_Err_Invalid_Reference; + return; + } + } else + { + org_x = CUR_Func_dualproj( CUR.zp2.org + point, NULL_Vector ); + cur_x = CUR_Func_project( CUR.zp2.cur + point, NULL_Vector ); + + if ( ( org_a <= org_b && org_x <= org_a ) || + ( org_a > org_b && org_x >= org_a ) ) { + + distance = ( cur_a - org_a ) + ( org_x - cur_x ); + } else if ( ( org_a <= org_b && org_x >= org_b ) || + ( org_a > org_b && org_x < org_b ) ) { + + distance = ( cur_b - org_b ) + ( org_x - cur_x ); + } else { + /* note: it seems that rounding this value isn't a good */ + /* idea (cf. width of capital `S' in Times) */ + + distance = TT_MULDIV( cur_b - cur_a, + org_x - org_a, + org_b - org_a ) + ( cur_a - cur_x ); + } + + CUR_Func_move( &CUR.zp2, point, distance ); + } + + CUR.GS.loop--; + } + + CUR.GS.loop = 1; + CUR.new_top = CUR.args; +} + + +/*************************************************************************/ +/* */ +/* UTP[a]: UnTouch Point */ +/* Opcode range: 0x29 */ +/* Stack: uint32 --> */ +/* */ +static +void Ins_UTP( INS_ARG ) { + FT_UShort point; + FT_Byte mask; + + + point = (FT_UShort)args[0]; + + if ( BOUNDS( point, CUR.zp0.n_points ) ) { + if ( CUR.pedantic_hinting ) { + CUR.error = TT_Err_Invalid_Reference; + } + return; + } + + mask = 0xFF; + + if ( CUR.GS.freeVector.x != 0 ) { + mask &= ~FT_Curve_Tag_Touch_X; + } + + if ( CUR.GS.freeVector.y != 0 ) { + mask &= ~FT_Curve_Tag_Touch_Y; + } + + CUR.zp0.tags[point] &= mask; +} + + +/* Local variables for Ins_IUP: */ +struct LOC_Ins_IUP +{ + FT_Vector* orgs; /* original and current coordinate */ + FT_Vector* curs; /* arrays */ +}; + + +static +void Shift( FT_UInt p1, + FT_UInt p2, + FT_UInt p, + struct LOC_Ins_IUP* LINK ) { + FT_UInt i; + FT_F26Dot6 x; + + + x = LINK->curs[p].x - LINK->orgs[p].x; + + for ( i = p1; i < p; i++ ) + LINK->curs[i].x += x; + + for ( i = p + 1; i <= p2; i++ ) + LINK->curs[i].x += x; +} + + +static +void Interp( FT_UInt p1, + FT_UInt p2, + FT_UInt ref1, + FT_UInt ref2, + struct LOC_Ins_IUP* LINK ) { + FT_UInt i; + FT_F26Dot6 x, x1, x2, d1, d2; + + + if ( p1 > p2 ) { + return; + } + + x1 = LINK->orgs[ref1].x; + d1 = LINK->curs[ref1].x - LINK->orgs[ref1].x; + x2 = LINK->orgs[ref2].x; + d2 = LINK->curs[ref2].x - LINK->orgs[ref2].x; + + if ( x1 == x2 ) { + for ( i = p1; i <= p2; i++ ) + { + x = LINK->orgs[i].x; + + if ( x <= x1 ) { + x += d1; + } else { + x += d2; + } + + LINK->curs[i].x = x; + } + return; + } + + if ( x1 < x2 ) { + for ( i = p1; i <= p2; i++ ) + { + x = LINK->orgs[i].x; + + if ( x <= x1 ) { + x += d1; + } else + { + if ( x >= x2 ) { + x += d2; + } else { + x = LINK->curs[ref1].x + + TT_MULDIV( x - x1, + LINK->curs[ref2].x - LINK->curs[ref1].x, + x2 - x1 ); + } + } + LINK->curs[i].x = x; + } + return; + } + + /* x2 < x1 */ + + for ( i = p1; i <= p2; i++ ) + { + x = LINK->orgs[i].x; + if ( x <= x2 ) { + x += d2; + } else + { + if ( x >= x1 ) { + x += d1; + } else { + x = LINK->curs[ref1].x + + TT_MULDIV( x - x1, + LINK->curs[ref2].x - LINK->curs[ref1].x, + x2 - x1 ); + } + } + LINK->curs[i].x = x; + } +} + + +/*************************************************************************/ +/* */ +/* IUP[a]: Interpolate Untouched Points */ +/* Opcode range: 0x30-0x31 */ +/* Stack: --> */ +/* */ +static +void Ins_IUP( INS_ARG ) { + struct LOC_Ins_IUP V; + FT_Byte mask; + + FT_UInt first_point; /* first point of contour */ + FT_UInt end_point; /* end point (last+1) of contour */ + + FT_UInt first_touched; /* first touched point in contour */ + FT_UInt cur_touched; /* current touched point in contour */ + + FT_UInt point; /* current point */ + FT_Short contour; /* current contour */ + + FT_UNUSED_ARG; + + + if ( CUR.opcode & 1 ) { + mask = FT_Curve_Tag_Touch_X; + V.orgs = CUR.pts.org; + V.curs = CUR.pts.cur; + } else + { + mask = FT_Curve_Tag_Touch_Y; + V.orgs = ( FT_Vector* )( (FT_Pos*)CUR.pts.org + 1 ); + V.curs = ( FT_Vector* )( (FT_Pos*)CUR.pts.cur + 1 ); + } + + contour = 0; + point = 0; + + do + { + end_point = CUR.pts.contours[contour]; + first_point = point; + + while ( point <= end_point && ( CUR.pts.tags[point] & mask ) == 0 ) + point++; + + if ( point <= end_point ) { + first_touched = point; + cur_touched = point; + + point++; + + while ( point <= end_point ) + { + if ( ( CUR.pts.tags[point] & mask ) != 0 ) { + if ( point > 0 ) { + Interp( cur_touched + 1, + point - 1, + cur_touched, + point, + &V ); + } + cur_touched = point; + } + + point++; + } + + if ( cur_touched == first_touched ) { + Shift( first_point, end_point, cur_touched, &V ); + } else + { + Interp( (FT_UShort)( cur_touched + 1 ), + end_point, + cur_touched, + first_touched, + &V ); + + if ( first_touched > 0 ) { + Interp( first_point, + first_touched - 1, + cur_touched, + first_touched, + &V ); + } + } + } + contour++; + } while ( contour < CUR.pts.n_contours ); +} + + +/*************************************************************************/ +/* */ +/* DELTAPn[]: DELTA exceptions P1, P2, P3 */ +/* Opcode range: 0x5D,0x71,0x72 */ +/* Stack: uint32 (2 * uint32)... --> */ +/* */ +static +void Ins_DELTAP( INS_ARG ) { + FT_ULong k, nump; + FT_UShort A; + FT_ULong C; + FT_Long B; + + + nump = (FT_ULong)args[0]; /* some points theoretically may occur more + than once, thus UShort isn't enough */ + + for ( k = 1; k <= nump; k++ ) + { + if ( CUR.args < 2 ) { + CUR.error = TT_Err_Too_Few_Arguments; + return; + } + + CUR.args -= 2; + + A = (FT_UShort)CUR.stack[CUR.args + 1]; + B = CUR.stack[CUR.args]; + + /* XXX: Because some popular fonts contain some invalid DeltaP */ + /* instructions, we simply ignore them when the stacked */ + /* point reference is off limit, rather than returning an */ + /* error. As a delta instruction doesn't change a glyph */ + /* in great ways, this shouldn't be a problem. */ + + if ( !BOUNDS( A, CUR.zp0.n_points ) ) { + C = ( (FT_ULong)B & 0xF0 ) >> 4; + + switch ( CUR.opcode ) + { + case 0x5D: + break; + + case 0x71: + C += 16; + break; + + case 0x72: + C += 32; + break; + } + + C += CUR.GS.delta_base; + + if ( CURRENT_Ppem() == (FT_Long)C ) { + B = ( (FT_ULong)B & 0xF ) - 8; + if ( B >= 0 ) { + B++; + } + B = B * 64 / ( 1L << CUR.GS.delta_shift ); + + CUR_Func_move( &CUR.zp0, A, B ); + } + } else + if ( CUR.pedantic_hinting ) { + CUR.error = TT_Err_Invalid_Reference; + } + } + + CUR.new_top = CUR.args; +} + + +/*************************************************************************/ +/* */ +/* DELTACn[]: DELTA exceptions C1, C2, C3 */ +/* Opcode range: 0x73,0x74,0x75 */ +/* Stack: uint32 (2 * uint32)... --> */ +/* */ +static +void Ins_DELTAC( INS_ARG ) { + FT_ULong nump, k; + FT_ULong A, C; + FT_Long B; + + + nump = (FT_ULong)args[0]; + + for ( k = 1; k <= nump; k++ ) + { + if ( CUR.args < 2 ) { + CUR.error = TT_Err_Too_Few_Arguments; + return; + } + + CUR.args -= 2; + + A = (FT_ULong)CUR.stack[CUR.args + 1]; + B = CUR.stack[CUR.args]; + + if ( BOUNDS( A, CUR.cvtSize ) ) { + if ( CUR.pedantic_hinting ) { + CUR.error = TT_Err_Invalid_Reference; + return; + } + } else + { + C = ( (FT_ULong)B & 0xF0 ) >> 4; + + switch ( CUR.opcode ) + { + case 0x73: + break; + + case 0x74: + C += 16; + break; + + case 0x75: + C += 32; + break; + } + + C += CUR.GS.delta_base; + + if ( CURRENT_Ppem() == (FT_Long)C ) { + B = ( (FT_ULong)B & 0xF ) - 8; + if ( B >= 0 ) { + B++; + } + B = B * 64 / ( 1L << CUR.GS.delta_shift ); + + CUR_Func_move_cvt( A, B ); + } + } + } + + CUR.new_top = CUR.args; +} + + +/*************************************************************************/ +/* */ +/* MISC. INSTRUCTIONS */ +/* */ +/*************************************************************************/ + + +/*************************************************************************/ +/* */ +/* GETINFO[]: GET INFOrmation */ +/* Opcode range: 0x88 */ +/* Stack: uint32 --> uint32 */ +/* */ +/* XXX: According to Apple specs, bits 1 & 2 of the argument ought to be */ +/* consulted before rotated/stretched info is returned. */ +static +void Ins_GETINFO( INS_ARG ) { + FT_Long K; + + + K = 0; + + /* We return then Windows 3.1 version number */ + /* for the font scaler */ + if ( ( args[0] & 1 ) != 0 ) { + K = 3; + } + + /* Has the glyph been rotated ? */ + if ( CUR.tt_metrics.rotated ) { + K |= 0x80; + } + + /* Has the glyph been stretched ? */ + if ( CUR.tt_metrics.stretched ) { + K |= 0x100; + } + + args[0] = K; +} + + +static +void Ins_UNKNOWN( INS_ARG ) { + TT_DefRecord* def = CUR.IDefs; + TT_DefRecord* limit = def + CUR.numIDefs; + + FT_UNUSED_ARG; + + + for ( ; def < limit; def++ ) + { + if ( def->opc == CUR.opcode && def->active ) { + TT_CallRec* call; + + + if ( CUR.callTop >= CUR.callSize ) { + CUR.error = TT_Err_Stack_Overflow; + return; + } + + call = CUR.callStack + CUR.callTop++; + + call->Caller_Range = CUR.curRange; + call->Caller_IP = CUR.IP + 1; + call->Cur_Count = 1; + call->Cur_Restart = def->start; + + INS_Goto_CodeRange( def->range, def->start ); + + CUR.step_ins = FALSE; + return; + } + } + + CUR.error = TT_Err_Invalid_Opcode; +} + + +#ifndef TT_CONFIG_OPTION_INTERPRETER_SWITCH + + +static +TInstruction_Function Instruct_Dispatch[256] = +{ + /* Opcodes are gathered in groups of 16. */ + /* Please keep the spaces as they are. */ + + /* SVTCA y */ Ins_SVTCA, + /* SVTCA x */ Ins_SVTCA, + /* SPvTCA y */ Ins_SPVTCA, + /* SPvTCA x */ Ins_SPVTCA, + /* SFvTCA y */ Ins_SFVTCA, + /* SFvTCA x */ Ins_SFVTCA, + /* SPvTL // */ Ins_SPVTL, + /* SPvTL + */ Ins_SPVTL, + /* SFvTL // */ Ins_SFVTL, + /* SFvTL + */ Ins_SFVTL, + /* SPvFS */ Ins_SPVFS, + /* SFvFS */ Ins_SFVFS, + /* GPV */ Ins_GPV, + /* GFV */ Ins_GFV, + /* SFvTPv */ Ins_SFVTPV, + /* ISECT */ Ins_ISECT, + + /* SRP0 */ Ins_SRP0, + /* SRP1 */ Ins_SRP1, + /* SRP2 */ Ins_SRP2, + /* SZP0 */ Ins_SZP0, + /* SZP1 */ Ins_SZP1, + /* SZP2 */ Ins_SZP2, + /* SZPS */ Ins_SZPS, + /* SLOOP */ Ins_SLOOP, + /* RTG */ Ins_RTG, + /* RTHG */ Ins_RTHG, + /* SMD */ Ins_SMD, + /* ELSE */ Ins_ELSE, + /* JMPR */ Ins_JMPR, + /* SCvTCi */ Ins_SCVTCI, + /* SSwCi */ Ins_SSWCI, + /* SSW */ Ins_SSW, + + /* DUP */ Ins_DUP, + /* POP */ Ins_POP, + /* CLEAR */ Ins_CLEAR, + /* SWAP */ Ins_SWAP, + /* DEPTH */ Ins_DEPTH, + /* CINDEX */ Ins_CINDEX, + /* MINDEX */ Ins_MINDEX, + /* AlignPTS */ Ins_ALIGNPTS, + /* INS_0x28 */ Ins_UNKNOWN, + /* UTP */ Ins_UTP, + /* LOOPCALL */ Ins_LOOPCALL, + /* CALL */ Ins_CALL, + /* FDEF */ Ins_FDEF, + /* ENDF */ Ins_ENDF, + /* MDAP[0] */ Ins_MDAP, + /* MDAP[1] */ Ins_MDAP, + + /* IUP[0] */ Ins_IUP, + /* IUP[1] */ Ins_IUP, + /* SHP[0] */ Ins_SHP, + /* SHP[1] */ Ins_SHP, + /* SHC[0] */ Ins_SHC, + /* SHC[1] */ Ins_SHC, + /* SHZ[0] */ Ins_SHZ, + /* SHZ[1] */ Ins_SHZ, + /* SHPIX */ Ins_SHPIX, + /* IP */ Ins_IP, + /* MSIRP[0] */ Ins_MSIRP, + /* MSIRP[1] */ Ins_MSIRP, + /* AlignRP */ Ins_ALIGNRP, + /* RTDG */ Ins_RTDG, + /* MIAP[0] */ Ins_MIAP, + /* MIAP[1] */ Ins_MIAP, + + /* NPushB */ Ins_NPUSHB, + /* NPushW */ Ins_NPUSHW, + /* WS */ Ins_WS, + /* RS */ Ins_RS, + /* WCvtP */ Ins_WCVTP, + /* RCvt */ Ins_RCVT, + /* GC[0] */ Ins_GC, + /* GC[1] */ Ins_GC, + /* SCFS */ Ins_SCFS, + /* MD[0] */ Ins_MD, + /* MD[1] */ Ins_MD, + /* MPPEM */ Ins_MPPEM, + /* MPS */ Ins_MPS, + /* FlipON */ Ins_FLIPON, + /* FlipOFF */ Ins_FLIPOFF, + /* DEBUG */ Ins_DEBUG, + + /* LT */ Ins_LT, + /* LTEQ */ Ins_LTEQ, + /* GT */ Ins_GT, + /* GTEQ */ Ins_GTEQ, + /* EQ */ Ins_EQ, + /* NEQ */ Ins_NEQ, + /* ODD */ Ins_ODD, + /* EVEN */ Ins_EVEN, + /* IF */ Ins_IF, + /* EIF */ Ins_EIF, + /* AND */ Ins_AND, + /* OR */ Ins_OR, + /* NOT */ Ins_NOT, + /* DeltaP1 */ Ins_DELTAP, + /* SDB */ Ins_SDB, + /* SDS */ Ins_SDS, + + /* ADD */ Ins_ADD, + /* SUB */ Ins_SUB, + /* DIV */ Ins_DIV, + /* MUL */ Ins_MUL, + /* ABS */ Ins_ABS, + /* NEG */ Ins_NEG, + /* FLOOR */ Ins_FLOOR, + /* CEILING */ Ins_CEILING, + /* ROUND[0] */ Ins_ROUND, + /* ROUND[1] */ Ins_ROUND, + /* ROUND[2] */ Ins_ROUND, + /* ROUND[3] */ Ins_ROUND, + /* NROUND[0] */ Ins_NROUND, + /* NROUND[1] */ Ins_NROUND, + /* NROUND[2] */ Ins_NROUND, + /* NROUND[3] */ Ins_NROUND, + + /* WCvtF */ Ins_WCVTF, + /* DeltaP2 */ Ins_DELTAP, + /* DeltaP3 */ Ins_DELTAP, + /* DeltaCn[0] */ Ins_DELTAC, + /* DeltaCn[1] */ Ins_DELTAC, + /* DeltaCn[2] */ Ins_DELTAC, + /* SROUND */ Ins_SROUND, + /* S45Round */ Ins_S45ROUND, + /* JROT */ Ins_JROT, + /* JROF */ Ins_JROF, + /* ROFF */ Ins_ROFF, + /* INS_0x7B */ Ins_UNKNOWN, + /* RUTG */ Ins_RUTG, + /* RDTG */ Ins_RDTG, + /* SANGW */ Ins_SANGW, + /* AA */ Ins_AA, + + /* FlipPT */ Ins_FLIPPT, + /* FlipRgON */ Ins_FLIPRGON, + /* FlipRgOFF */ Ins_FLIPRGOFF, + /* INS_0x83 */ Ins_UNKNOWN, + /* INS_0x84 */ Ins_UNKNOWN, + /* ScanCTRL */ Ins_SCANCTRL, + /* SDPVTL[0] */ Ins_SDPVTL, + /* SDPVTL[1] */ Ins_SDPVTL, + /* GetINFO */ Ins_GETINFO, + /* IDEF */ Ins_IDEF, + /* ROLL */ Ins_ROLL, + /* MAX */ Ins_MAX, + /* MIN */ Ins_MIN, + /* ScanTYPE */ Ins_SCANTYPE, + /* InstCTRL */ Ins_INSTCTRL, + /* INS_0x8F */ Ins_UNKNOWN, + + /* INS_0x90 */ Ins_UNKNOWN, + /* INS_0x91 */ Ins_UNKNOWN, + /* INS_0x92 */ Ins_UNKNOWN, + /* INS_0x93 */ Ins_UNKNOWN, + /* INS_0x94 */ Ins_UNKNOWN, + /* INS_0x95 */ Ins_UNKNOWN, + /* INS_0x96 */ Ins_UNKNOWN, + /* INS_0x97 */ Ins_UNKNOWN, + /* INS_0x98 */ Ins_UNKNOWN, + /* INS_0x99 */ Ins_UNKNOWN, + /* INS_0x9A */ Ins_UNKNOWN, + /* INS_0x9B */ Ins_UNKNOWN, + /* INS_0x9C */ Ins_UNKNOWN, + /* INS_0x9D */ Ins_UNKNOWN, + /* INS_0x9E */ Ins_UNKNOWN, + /* INS_0x9F */ Ins_UNKNOWN, + + /* INS_0xA0 */ Ins_UNKNOWN, + /* INS_0xA1 */ Ins_UNKNOWN, + /* INS_0xA2 */ Ins_UNKNOWN, + /* INS_0xA3 */ Ins_UNKNOWN, + /* INS_0xA4 */ Ins_UNKNOWN, + /* INS_0xA5 */ Ins_UNKNOWN, + /* INS_0xA6 */ Ins_UNKNOWN, + /* INS_0xA7 */ Ins_UNKNOWN, + /* INS_0xA8 */ Ins_UNKNOWN, + /* INS_0xA9 */ Ins_UNKNOWN, + /* INS_0xAA */ Ins_UNKNOWN, + /* INS_0xAB */ Ins_UNKNOWN, + /* INS_0xAC */ Ins_UNKNOWN, + /* INS_0xAD */ Ins_UNKNOWN, + /* INS_0xAE */ Ins_UNKNOWN, + /* INS_0xAF */ Ins_UNKNOWN, + + /* PushB[0] */ Ins_PUSHB, + /* PushB[1] */ Ins_PUSHB, + /* PushB[2] */ Ins_PUSHB, + /* PushB[3] */ Ins_PUSHB, + /* PushB[4] */ Ins_PUSHB, + /* PushB[5] */ Ins_PUSHB, + /* PushB[6] */ Ins_PUSHB, + /* PushB[7] */ Ins_PUSHB, + /* PushW[0] */ Ins_PUSHW, + /* PushW[1] */ Ins_PUSHW, + /* PushW[2] */ Ins_PUSHW, + /* PushW[3] */ Ins_PUSHW, + /* PushW[4] */ Ins_PUSHW, + /* PushW[5] */ Ins_PUSHW, + /* PushW[6] */ Ins_PUSHW, + /* PushW[7] */ Ins_PUSHW, + + /* MDRP[00] */ Ins_MDRP, + /* MDRP[01] */ Ins_MDRP, + /* MDRP[02] */ Ins_MDRP, + /* MDRP[03] */ Ins_MDRP, + /* MDRP[04] */ Ins_MDRP, + /* MDRP[05] */ Ins_MDRP, + /* MDRP[06] */ Ins_MDRP, + /* MDRP[07] */ Ins_MDRP, + /* MDRP[08] */ Ins_MDRP, + /* MDRP[09] */ Ins_MDRP, + /* MDRP[10] */ Ins_MDRP, + /* MDRP[11] */ Ins_MDRP, + /* MDRP[12] */ Ins_MDRP, + /* MDRP[13] */ Ins_MDRP, + /* MDRP[14] */ Ins_MDRP, + /* MDRP[15] */ Ins_MDRP, + + /* MDRP[16] */ Ins_MDRP, + /* MDRP[17] */ Ins_MDRP, + /* MDRP[18] */ Ins_MDRP, + /* MDRP[19] */ Ins_MDRP, + /* MDRP[20] */ Ins_MDRP, + /* MDRP[21] */ Ins_MDRP, + /* MDRP[22] */ Ins_MDRP, + /* MDRP[23] */ Ins_MDRP, + /* MDRP[24] */ Ins_MDRP, + /* MDRP[25] */ Ins_MDRP, + /* MDRP[26] */ Ins_MDRP, + /* MDRP[27] */ Ins_MDRP, + /* MDRP[28] */ Ins_MDRP, + /* MDRP[29] */ Ins_MDRP, + /* MDRP[30] */ Ins_MDRP, + /* MDRP[31] */ Ins_MDRP, + + /* MIRP[00] */ Ins_MIRP, + /* MIRP[01] */ Ins_MIRP, + /* MIRP[02] */ Ins_MIRP, + /* MIRP[03] */ Ins_MIRP, + /* MIRP[04] */ Ins_MIRP, + /* MIRP[05] */ Ins_MIRP, + /* MIRP[06] */ Ins_MIRP, + /* MIRP[07] */ Ins_MIRP, + /* MIRP[08] */ Ins_MIRP, + /* MIRP[09] */ Ins_MIRP, + /* MIRP[10] */ Ins_MIRP, + /* MIRP[11] */ Ins_MIRP, + /* MIRP[12] */ Ins_MIRP, + /* MIRP[13] */ Ins_MIRP, + /* MIRP[14] */ Ins_MIRP, + /* MIRP[15] */ Ins_MIRP, + + /* MIRP[16] */ Ins_MIRP, + /* MIRP[17] */ Ins_MIRP, + /* MIRP[18] */ Ins_MIRP, + /* MIRP[19] */ Ins_MIRP, + /* MIRP[20] */ Ins_MIRP, + /* MIRP[21] */ Ins_MIRP, + /* MIRP[22] */ Ins_MIRP, + /* MIRP[23] */ Ins_MIRP, + /* MIRP[24] */ Ins_MIRP, + /* MIRP[25] */ Ins_MIRP, + /* MIRP[26] */ Ins_MIRP, + /* MIRP[27] */ Ins_MIRP, + /* MIRP[28] */ Ins_MIRP, + /* MIRP[29] */ Ins_MIRP, + /* MIRP[30] */ Ins_MIRP, + /* MIRP[31] */ Ins_MIRP +}; + + +#endif /* !TT_CONFIG_OPTION_INTERPRETER_SWITCH */ + + +/*************************************************************************/ +/* */ +/* RUN */ +/* */ +/* This function executes a run of opcodes. It will exit in the */ +/* following cases: */ +/* */ +/* - Errors (in which case it returns FALSE). */ +/* */ +/* - Reaching the end of the main code range (returns TRUE). */ +/* Reaching the end of a code range within a function call is an */ +/* error. */ +/* */ +/* - After executing one single opcode, if the flag `Instruction_Trap' */ +/* is set to TRUE (returns TRUE). */ +/* */ +/* On exit whith TRUE, test IP < CodeSize to know wether it comes from */ +/* an instruction trap or a normal termination. */ +/* */ +/* */ +/* Note: The documented DEBUG opcode pops a value from the stack. This */ +/* behaviour is unsupported; here a DEBUG opcode is always an */ +/* error. */ +/* */ +/* */ +/* THIS IS THE INTERPRETER'S MAIN LOOP. */ +/* */ +/* Instructions appear in the specification's order. */ +/* */ +/*************************************************************************/ + + +/*************************************************************************/ +/* */ +/* */ +/* TT_RunIns */ +/* */ +/* */ +/* Executes one or more instruction in the execution context. This */ +/* is the main function of the TrueType opcode interpreter. */ +/* */ +/* */ +/* exec :: A handle to the target execution context. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +/* */ +/* Only the object manager and debugger should call this function. */ +/* */ +/* This function is publicly exported because it is directly */ +/* invoked by the TrueType debugger. */ +/* */ +FT_EXPORT_FUNC( FT_Error ) TT_RunIns( TT_ExecContext exc ) +{ + FT_Long ins_counter = 0; /* executed instructions counter */ + + +#ifdef TT_CONFIG_OPTION_STATIC_RASTER + cur = *exc; +#endif + + /* set CVT functions */ + CUR.tt_metrics.ratio = 0; + if ( CUR.metrics.x_ppem != CUR.metrics.y_ppem ) { + /* non-square pixels, use the stretched routines */ + CUR.func_read_cvt = Read_CVT_Stretched; + CUR.func_write_cvt = Write_CVT_Stretched; + CUR.func_move_cvt = Move_CVT_Stretched; + } else + { + /* square pixels, use normal routines */ + CUR.func_read_cvt = Read_CVT; + CUR.func_write_cvt = Write_CVT; + CUR.func_move_cvt = Move_CVT; + } + + COMPUTE_Funcs(); + COMPUTE_Round( (FT_Byte)exc->GS.round_state ); + + do + { + CUR.opcode = CUR.code[CUR.IP]; + + if ( ( CUR.length = opcode_length[CUR.opcode] ) < 0 ) { + if ( CUR.IP + 1 > CUR.codeSize ) { + goto LErrorCodeOverflow_; + } + + CUR.length = CUR.code[CUR.IP + 1] + 2; + } + + if ( CUR.IP + CUR.length > CUR.codeSize ) { + goto LErrorCodeOverflow_; + } + + /* First, let's check for empty stack and overflow */ + CUR.args = CUR.top - ( Pop_Push_Count[CUR.opcode] >> 4 ); + + /* `args' is the top of the stack once arguments have been popped. */ + /* One can also interpret it as the index of the last argument. */ + if ( CUR.args < 0 ) { + CUR.error = TT_Err_Too_Few_Arguments; + goto LErrorLabel_; + } + + CUR.new_top = CUR.args + ( Pop_Push_Count[CUR.opcode] & 15 ); + + /* `new_top' is the new top of the stack, after the instruction's */ + /* execution. `top' will be set to `new_top' after the `switch' */ + /* statement. */ + if ( CUR.new_top > CUR.stackSize ) { + CUR.error = TT_Err_Stack_Overflow; + goto LErrorLabel_; + } + + CUR.step_ins = TRUE; + CUR.error = TT_Err_Ok; + +#ifdef TT_CONFIG_OPTION_INTERPRETER_SWITCH + + { + FT_Long* args = CUR.stack + CUR.args; + FT_Byte opcode = CUR.opcode; + + +#undef ARRAY_BOUND_ERROR +#define ARRAY_BOUND_ERROR goto Set_Invalid_Ref + + + switch ( opcode ) + { + case 0x00: /* SVTCA y */ + case 0x01: /* SVTCA x */ + case 0x02: /* SPvTCA y */ + case 0x03: /* SPvTCA x */ + case 0x04: /* SFvTCA y */ + case 0x05: /* SFvTCA x */ + { + FT_Short AA, BB; + + + AA = (FT_Short)( opcode & 1 ) << 14; + BB = AA ^ (FT_Short)0x4000; + + if ( opcode < 4 ) { + CUR.GS.projVector.x = AA; + CUR.GS.projVector.y = BB; + + CUR.GS.dualVector.x = AA; + CUR.GS.dualVector.y = BB; + } + + if ( ( opcode & 2 ) == 0 ) { + CUR.GS.freeVector.x = AA; + CUR.GS.freeVector.y = BB; + } + + COMPUTE_Funcs(); + } + break; + + case 0x06: /* SPvTL // */ + case 0x07: /* SPvTL + */ + DO_SPVTL + break; + + case 0x08: /* SFvTL // */ + case 0x09: /* SFvTL + */ + DO_SFVTL + break; + + case 0x0A: /* SPvFS */ + DO_SPVFS + break; + + case 0x0B: /* SFvFS */ + DO_SFVFS + break; + + case 0x0C: /* GPV */ + DO_GPV + break; + + case 0x0D: /* GFV */ + DO_GFV + break; + + case 0x0E: /* SFvTPv */ + DO_SFVTPV + break; + + case 0x0F: /* ISECT */ + Ins_ISECT( EXEC_ARG_ args ); + break; + + case 0x10: /* SRP0 */ + DO_SRP0 + break; + + case 0x11: /* SRP1 */ + DO_SRP1 + break; + + case 0x12: /* SRP2 */ + DO_SRP2 + break; + + case 0x13: /* SZP0 */ + Ins_SZP0( EXEC_ARG_ args ); + break; + + case 0x14: /* SZP1 */ + Ins_SZP1( EXEC_ARG_ args ); + break; + + case 0x15: /* SZP2 */ + Ins_SZP2( EXEC_ARG_ args ); + break; + + case 0x16: /* SZPS */ + Ins_SZPS( EXEC_ARG_ args ); + break; + + case 0x17: /* SLOOP */ + DO_SLOOP + break; + + case 0x18: /* RTG */ + DO_RTG + break; + + case 0x19: /* RTHG */ + DO_RTHG + break; + + case 0x1A: /* SMD */ + DO_SMD + break; + + case 0x1B: /* ELSE */ + Ins_ELSE( EXEC_ARG_ args ); + break; + + case 0x1C: /* JMPR */ + DO_JMPR + break; + + case 0x1D: /* SCVTCI */ + DO_SCVTCI + break; + + case 0x1E: /* SSWCI */ + DO_SSWCI + break; + + case 0x1F: /* SSW */ + DO_SSW + break; + + case 0x20: /* DUP */ + DO_DUP + break; + + case 0x21: /* POP */ + /* nothing :-) */ + break; + + case 0x22: /* CLEAR */ + DO_CLEAR + break; + + case 0x23: /* SWAP */ + DO_SWAP + break; + + case 0x24: /* DEPTH */ + DO_DEPTH + break; + + case 0x25: /* CINDEX */ + DO_CINDEX + break; + + case 0x26: /* MINDEX */ + Ins_MINDEX( EXEC_ARG_ args ); + break; + + case 0x27: /* ALIGNPTS */ + Ins_ALIGNPTS( EXEC_ARG_ args ); + break; + + case 0x28: /* ???? */ + Ins_UNKNOWN( EXEC_ARG_ args ); + break; + + case 0x29: /* UTP */ + Ins_UTP( EXEC_ARG_ args ); + break; + + case 0x2A: /* LOOPCALL */ + Ins_LOOPCALL( EXEC_ARG_ args ); + break; + + case 0x2B: /* CALL */ + Ins_CALL( EXEC_ARG_ args ); + break; + + case 0x2C: /* FDEF */ + Ins_FDEF( EXEC_ARG_ args ); + break; + + case 0x2D: /* ENDF */ + Ins_ENDF( EXEC_ARG_ args ); + break; + + case 0x2E: /* MDAP */ + case 0x2F: /* MDAP */ + Ins_MDAP( EXEC_ARG_ args ); + break; + + + case 0x30: /* IUP */ + case 0x31: /* IUP */ + Ins_IUP( EXEC_ARG_ args ); + break; + + case 0x32: /* SHP */ + case 0x33: /* SHP */ + Ins_SHP( EXEC_ARG_ args ); + break; + + case 0x34: /* SHC */ + case 0x35: /* SHC */ + Ins_SHC( EXEC_ARG_ args ); + break; + + case 0x36: /* SHZ */ + case 0x37: /* SHZ */ + Ins_SHZ( EXEC_ARG_ args ); + break; + + case 0x38: /* SHPIX */ + Ins_SHPIX( EXEC_ARG_ args ); + break; + + case 0x39: /* IP */ + Ins_IP( EXEC_ARG_ args ); + break; + + case 0x3A: /* MSIRP */ + case 0x3B: /* MSIRP */ + Ins_MSIRP( EXEC_ARG_ args ); + break; + + case 0x3C: /* AlignRP */ + Ins_ALIGNRP( EXEC_ARG_ args ); + break; + + case 0x3D: /* RTDG */ + DO_RTDG + break; + + case 0x3E: /* MIAP */ + case 0x3F: /* MIAP */ + Ins_MIAP( EXEC_ARG_ args ); + break; + + case 0x40: /* NPUSHB */ + Ins_NPUSHB( EXEC_ARG_ args ); + break; + + case 0x41: /* NPUSHW */ + Ins_NPUSHW( EXEC_ARG_ args ); + break; + + case 0x42: /* WS */ + DO_WS + break; + +Set_Invalid_Ref: + CUR.error = TT_Err_Invalid_Reference; + break; + + case 0x43: /* RS */ + DO_RS + break; + + case 0x44: /* WCVTP */ + DO_WCVTP + break; + + case 0x45: /* RCVT */ + DO_RCVT + break; + + case 0x46: /* GC */ + case 0x47: /* GC */ + Ins_GC( EXEC_ARG_ args ); + break; + + case 0x48: /* SCFS */ + Ins_SCFS( EXEC_ARG_ args ); + break; + + case 0x49: /* MD */ + case 0x4A: /* MD */ + Ins_MD( EXEC_ARG_ args ); + break; + + case 0x4B: /* MPPEM */ + DO_MPPEM + break; + + case 0x4C: /* MPS */ + DO_MPS + break; + + case 0x4D: /* FLIPON */ + DO_FLIPON + break; + + case 0x4E: /* FLIPOFF */ + DO_FLIPOFF + break; + + case 0x4F: /* DEBUG */ + DO_DEBUG + break; + + case 0x50: /* LT */ + DO_LT + break; + + case 0x51: /* LTEQ */ + DO_LTEQ + break; + + case 0x52: /* GT */ + DO_GT + break; + + case 0x53: /* GTEQ */ + DO_GTEQ + break; + + case 0x54: /* EQ */ + DO_EQ + break; + + case 0x55: /* NEQ */ + DO_NEQ + break; + + case 0x56: /* ODD */ + DO_ODD + break; + + case 0x57: /* EVEN */ + DO_EVEN + break; + + case 0x58: /* IF */ + Ins_IF( EXEC_ARG_ args ); + break; + + case 0x59: /* EIF */ + /* do nothing */ + break; + + case 0x5A: /* AND */ + DO_AND + break; + + case 0x5B: /* OR */ + DO_OR + break; + + case 0x5C: /* NOT */ + DO_NOT + break; + + case 0x5D: /* DELTAP1 */ + Ins_DELTAP( EXEC_ARG_ args ); + break; + + case 0x5E: /* SDB */ + DO_SDB + break; + + case 0x5F: /* SDS */ + DO_SDS + break; + + case 0x60: /* ADD */ + DO_ADD + break; + + case 0x61: /* SUB */ + DO_SUB + break; + + case 0x62: /* DIV */ + DO_DIV + break; + + case 0x63: /* MUL */ + DO_MUL + break; + + case 0x64: /* ABS */ + DO_ABS + break; + + case 0x65: /* NEG */ + DO_NEG + break; + + case 0x66: /* FLOOR */ + DO_FLOOR + break; + + case 0x67: /* CEILING */ + DO_CEILING + break; + + case 0x68: /* ROUND */ + case 0x69: /* ROUND */ + case 0x6A: /* ROUND */ + case 0x6B: /* ROUND */ + DO_ROUND + break; + + case 0x6C: /* NROUND */ + case 0x6D: /* NROUND */ + case 0x6E: /* NRRUND */ + case 0x6F: /* NROUND */ + DO_NROUND + break; + + case 0x70: /* WCVTF */ + DO_WCVTF + break; + + case 0x71: /* DELTAP2 */ + case 0x72: /* DELTAP3 */ + Ins_DELTAP( EXEC_ARG_ args ); + break; + + case 0x73: /* DELTAC0 */ + case 0x74: /* DELTAC1 */ + case 0x75: /* DELTAC2 */ + Ins_DELTAC( EXEC_ARG_ args ); + break; + + case 0x76: /* SROUND */ + DO_SROUND + break; + + case 0x77: /* S45Round */ + DO_S45ROUND + break; + + case 0x78: /* JROT */ + DO_JROT + break; + + case 0x79: /* JROF */ + DO_JROF + break; + + case 0x7A: /* ROFF */ + DO_ROFF + break; + + case 0x7B: /* ???? */ + Ins_UNKNOWN( EXEC_ARG_ args ); + break; + + case 0x7C: /* RUTG */ + DO_RUTG + break; + + case 0x7D: /* RDTG */ + DO_RDTG + break; + + case 0x7E: /* SANGW */ + case 0x7F: /* AA */ + /* nothing - obsolete */ + break; + + case 0x80: /* FLIPPT */ + Ins_FLIPPT( EXEC_ARG_ args ); + break; + + case 0x81: /* FLIPRGON */ + Ins_FLIPRGON( EXEC_ARG_ args ); + break; + + case 0x82: /* FLIPRGOFF */ + Ins_FLIPRGOFF( EXEC_ARG_ args ); + break; + + case 0x83: /* UNKNOWN */ + case 0x84: /* UNKNOWN */ + Ins_UNKNOWN( EXEC_ARG_ args ); + break; + + case 0x85: /* SCANCTRL */ + Ins_SCANCTRL( EXEC_ARG_ args ); + break; + + case 0x86: /* SDPVTL */ + case 0x87: /* SDPVTL */ + Ins_SDPVTL( EXEC_ARG_ args ); + break; + + case 0x88: /* GETINFO */ + Ins_GETINFO( EXEC_ARG_ args ); + break; + + case 0x89: /* IDEF */ + Ins_IDEF( EXEC_ARG_ args ); + break; + + case 0x8A: /* ROLL */ + Ins_ROLL( EXEC_ARG_ args ); + break; + + case 0x8B: /* MAX */ + DO_MAX + break; + + case 0x8C: /* MIN */ + DO_MIN + break; + + case 0x8D: /* SCANTYPE */ + Ins_SCANTYPE( EXEC_ARG_ args ); + break; + + case 0x8E: /* INSTCTRL */ + Ins_INSTCTRL( EXEC_ARG_ args ); + break; + + case 0x8F: + Ins_UNKNOWN( EXEC_ARG_ args ); + break; + + default: + if ( opcode >= 0xE0 ) { + Ins_MIRP( EXEC_ARG_ args ); + } else if ( opcode >= 0xC0 ) { + Ins_MDRP( EXEC_ARG_ args ); + } else if ( opcode >= 0xB8 ) { + Ins_PUSHW( EXEC_ARG_ args ); + } else if ( opcode >= 0xB0 ) { + Ins_PUSHB( EXEC_ARG_ args ); + } else { + Ins_UNKNOWN( EXEC_ARG_ args ); + } + } + + } + +#else + + Instruct_Dispatch[CUR.opcode]( EXEC_ARG_ & CUR.stack[CUR.args] ); + +#endif /* TT_CONFIG_OPTION_INTERPRETER_SWITCH */ + + if ( CUR.error != TT_Err_Ok ) { + switch ( CUR.error ) + { + case TT_Err_Invalid_Opcode: /* looking for redefined instructions */ + { + TT_DefRecord* def = CUR.IDefs; + TT_DefRecord* limit = def + CUR.numIDefs; + + + for ( ; def < limit; def++ ) + { + if ( def->active && CUR.opcode == def->opc ) { + TT_CallRec* callrec; + + + if ( CUR.callTop >= CUR.callSize ) { + CUR.error = TT_Err_Invalid_Reference; + goto LErrorLabel_; + } + + callrec = &CUR.callStack[CUR.callTop]; + + callrec->Caller_Range = CUR.curRange; + callrec->Caller_IP = CUR.IP + 1; + callrec->Cur_Count = 1; + callrec->Cur_Restart = def->start; + + if ( INS_Goto_CodeRange( def->range, def->start ) == FAILURE ) { + goto LErrorLabel_; + } + + goto LSuiteLabel_; + } + } + } + + CUR.error = TT_Err_Invalid_Opcode; + goto LErrorLabel_; + +#if 0 + break; /* Unreachable code warning suppression. */ + /* Leave to remind in case a later change the editor */ + /* to consider break; */ +#endif + + default: + goto LErrorLabel_; + +#if 0 + break; +#endif + } + } + + CUR.top = CUR.new_top; + + if ( CUR.step_ins ) { + CUR.IP += CUR.length; + } + + /* increment instruction counter and check if we didn't */ + /* run this program for too long (e.g. infinite loops). */ + if ( ++ins_counter > MAX_RUNNABLE_OPCODES ) { + return TT_Err_Execution_Too_Long; + } + +LSuiteLabel_: + if ( CUR.IP >= CUR.codeSize ) { + if ( CUR.callTop > 0 ) { + CUR.error = TT_Err_Code_Overflow; + goto LErrorLabel_; + } else { + goto LNo_Error_; + } + } + } while ( !CUR.instruction_trap ); + +LNo_Error_: + +#ifdef TT_CONFIG_OPTION_STATIC_RASTER + *exc = cur; +#endif + + return TT_Err_Ok; + +LErrorCodeOverflow_: + CUR.error = TT_Err_Code_Overflow; + +LErrorLabel_: + +#ifdef TT_CONFIG_OPTION_STATIC_RASTER + *exc = cur; +#endif + + return CUR.error; +} + + +#endif /* TT_CONFIG_OPTION_BYTECODE_INTERPRETER */ + + +/* END */ diff --git a/Projects/Android/jni/rtcw/src/ft2/ttinterp.h b/Projects/Android/jni/rtcw/src/ft2/ttinterp.h new file mode 100644 index 0000000..fab608d --- /dev/null +++ b/Projects/Android/jni/rtcw/src/ft2/ttinterp.h @@ -0,0 +1,270 @@ +/***************************************************************************/ +/* */ +/* ttinterp.h */ +/* */ +/* TrueType bytecode interpreter (specification). */ +/* */ +/* Copyright 1996-2000 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef TTINTERP_H +#define TTINTERP_H + + +#include "ttobjs.h" + + +#ifdef __cplusplus +extern "C" { +#endif + + +#ifndef TT_CONFIG_OPTION_STATIC_INTEPRETER /* indirect implementation */ + +#define EXEC_OP_ TT_ExecContext exc, +#define EXEC_OP TT_ExecContext exc +#define EXEC_ARG_ exc, +#define EXEC_ARG exc + +#else /* static implementation */ + +#define EXEC_OP_ /* void */ +#define EXEC_OP /* void */ +#define EXEC_ARG_ /* void */ +#define EXEC_ARG /* void */ + +#endif /* TT_CONFIG_OPTION_STATIC_INTERPRETER */ + + +/*************************************************************************/ +/* */ +/* Rounding mode constants. */ +/* */ +#define TT_Round_Off 5 +#define TT_Round_To_Half_Grid 0 +#define TT_Round_To_Grid 1 +#define TT_Round_To_Double_Grid 2 +#define TT_Round_Up_To_Grid 4 +#define TT_Round_Down_To_Grid 3 +#define TT_Round_Super 6 +#define TT_Round_Super_45 7 + + +/*************************************************************************/ +/* */ +/* Function types used by the interpreter, depending on various modes */ +/* (e.g. the rounding mode, whether to render a vertical or horizontal */ +/* line etc). */ +/* */ +/*************************************************************************/ + +/* Rounding function */ +typedef FT_F26Dot6 ( *TT_Round_Func )( EXEC_OP_ FT_F26Dot6 distance, + FT_F26Dot6 compensation ); + +/* Point displacement along the freedom vector routine */ +typedef void ( *TT_Move_Func )( EXEC_OP_ TT_GlyphZone* zone, + FT_UInt point, + FT_F26Dot6 distance ); + +/* Distance projection along one of the projection vectors */ +typedef FT_F26Dot6 ( *TT_Project_Func )( EXEC_OP_ FT_Vector* v1, + FT_Vector* v2 ); + +/* reading a cvt value. Take care of non-square pixels if necessary */ +typedef FT_F26Dot6 ( *TT_Get_CVT_Func )( EXEC_OP_ FT_ULong index ); + +/* setting or moving a cvt value. Take care of non-square pixels */ +/* if necessary */ +typedef void ( *TT_Set_CVT_Func )( EXEC_OP_ FT_ULong index, + FT_F26Dot6 value ); + + +/*************************************************************************/ +/* */ +/* This structure defines a call record, used to manage function calls. */ +/* */ +typedef struct TT_CallRec_ +{ + FT_Int Caller_Range; + FT_Long Caller_IP; + FT_Long Cur_Count; + FT_Long Cur_Restart; + +} TT_CallRec, *TT_CallStack; + + +/*************************************************************************/ +/* */ +/* The main structure for the interpreter which collects all necessary */ +/* variables and states. */ +/* */ +typedef struct TT_ExecContextRec_ +{ + TT_Face face; + TT_Size size; + FT_Memory memory; + + /* instructions state */ + + FT_Error error; /* last execution error */ + + FT_Long top; /* top of exec. stack */ + + FT_UInt stackSize; /* size of exec. stack */ + FT_Long* stack; /* current exec. stack */ + + FT_Long args; + FT_UInt new_top; /* new top after exec. */ + + TT_GlyphZone zp0, /* zone records */ + zp1, + zp2, + pts, + twilight; + + FT_Size_Metrics metrics; + TT_Size_Metrics tt_metrics; /* size metrics */ + + TT_GraphicsState GS; /* current graphics state */ + + FT_Int curRange; /* current code range number */ + FT_Byte* code; /* current code range */ + FT_Long IP; /* current instruction pointer */ + FT_Long codeSize; /* size of current range */ + + FT_Byte opcode; /* current opcode */ + FT_Int length; /* length of current opcode */ + + FT_Bool step_ins; /* true if the interpreter must */ + /* increment IP after ins. exec */ + FT_Long cvtSize; + FT_Long* cvt; + + FT_UInt glyphSize; /* glyph instructions buffer size */ + FT_Byte* glyphIns; /* glyph instructions buffer */ + + FT_UInt numFDefs; /* number of function defs */ + FT_UInt maxFDefs; /* maximum number of function defs */ + TT_DefArray FDefs; /* table of FDefs entries */ + + FT_UInt numIDefs; /* number of instruction defs */ + FT_UInt maxIDefs; /* maximum number of ins defs */ + TT_DefArray IDefs; /* table of IDefs entries */ + + FT_UInt maxFunc; /* maximum function index */ + FT_UInt maxIns; /* maximum instruction index */ + + FT_Int callTop, /* top of call stack during execution */ + callSize; /* size of call stack */ + TT_CallStack callStack; /* call stack */ + + FT_UShort maxPoints; /* capacity of this context's `pts' */ + FT_Short maxContours; /* record, expressed in points and */ + /* contours. */ + + TT_CodeRangeTable codeRangeTable; /* table of valid code ranges */ + /* useful for the debugger */ + + FT_UShort storeSize; /* size of current storage */ + FT_Long* storage; /* storage area */ + + FT_F26Dot6 period; /* values used for the */ + FT_F26Dot6 phase; /* `SuperRounding' */ + FT_F26Dot6 threshold; + +#if 0 + /* this seems to be unused */ + FT_Int cur_ppem; /* ppem along the current proj vector */ +#endif + + FT_Bool instruction_trap; /* If `True', the interpreter will */ + /* exit after each instruction */ + + TT_GraphicsState default_GS; /* graphics state resulting from */ + /* the prep program */ + FT_Bool is_composite; /* true if the glyph is composite */ + FT_Bool pedantic_hinting; /* true for pedantic interpretation */ + + /* latest interpreter additions */ + + FT_Long F_dot_P; /* dot product of freedom and projection */ + /* vectors */ + TT_Round_Func func_round; /* current rounding function */ + + TT_Project_Func func_project, /* current projection function */ + func_dualproj, /* current dual proj. function */ + func_freeProj; /* current freedom proj. func */ + + TT_Move_Func func_move; /* current point move function */ + + TT_Get_CVT_Func func_read_cvt; /* read a cvt entry */ + TT_Set_CVT_Func func_write_cvt; /* write a cvt entry (in pixels) */ + TT_Set_CVT_Func func_move_cvt; /* incr a cvt entry (in pixels) */ + + FT_ULong loadSize; + TT_SubGlyph_Stack loadStack; /* loading subglyph stack */ + +} TT_ExecContextRec; + + +extern const TT_GraphicsState tt_default_graphics_state; + + +LOCAL_DEF +FT_Error TT_Goto_CodeRange( TT_ExecContext exec, + FT_Int range, + FT_Long IP ); + +LOCAL_DEF +FT_Error TT_Set_CodeRange( TT_ExecContext exec, + FT_Int range, + void* base, + FT_Long length ); + +LOCAL_DEF +FT_Error TT_Clear_CodeRange( TT_ExecContext exec, + FT_Int range ); + +FT_EXPORT_DEF( TT_ExecContext ) TT_New_Context( TT_Face face ); + +LOCAL_DEF +FT_Error TT_Done_Context( TT_ExecContext exec ); + +LOCAL_DEF +FT_Error TT_Destroy_Context( TT_ExecContext exec, + FT_Memory memory ); + +LOCAL_DEF +FT_Error TT_Load_Context( TT_ExecContext exec, + TT_Face face, + TT_Size size ); + +LOCAL_DEF +FT_Error TT_Save_Context( TT_ExecContext exec, + TT_Size ins ); + +LOCAL_DEF +FT_Error TT_Run_Context( TT_ExecContext exec, + FT_Bool debug ); + +FT_EXPORT_DEF( FT_Error ) TT_RunIns( TT_ExecContext exec ); + + +#ifdef __cplusplus +} +#endif + +#endif /* TTINTERP_H */ + + +/* END */ diff --git a/Projects/Android/jni/rtcw/src/ft2/ttload.c b/Projects/Android/jni/rtcw/src/ft2/ttload.c new file mode 100644 index 0000000..d363765 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/ft2/ttload.c @@ -0,0 +1,1673 @@ +/***************************************************************************/ +/* */ +/* ttload.c */ +/* */ +/* Load the basic TrueType tables, i.e., tables that can be either in */ +/* TTF or OTF fonts (body). */ +/* */ +/* Copyright 1996-2000 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#include "ftdebug.h" +#include "tterrors.h" +#include "tttags.h" + + +#include "ttload.h" +#include "ttcmap.h" + + +/*************************************************************************/ +/* */ +/* The macro FT_COMPONENT is used in trace mode. It is an implicit */ +/* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */ +/* messages during execution. */ +/* */ +#undef FT_COMPONENT +#define FT_COMPONENT trace_ttload + + +/*************************************************************************/ +/* */ +/* */ +/* TT_LookUp_Table */ +/* */ +/* */ +/* Looks for a TrueType table by name. */ +/* */ +/* */ +/* face :: A face object handle. */ +/* tag :: The searched tag. */ +/* */ +/* */ +/* A pointer to the table directory entry. 0 if not found. */ +/* */ +LOCAL_FUNC +TT_Table* TT_LookUp_Table( TT_Face face, + FT_ULong tag ) { + TT_Table* entry; + TT_Table* limit; + + + FT_TRACE3( ( "TT_LookUp_Table: %08p, `%c%c%c%c'\n", + face, + (FT_Char)( tag >> 24 ), + (FT_Char)( tag >> 16 ), + (FT_Char)( tag >> 8 ), + (FT_Char)( tag ) ) ); + + entry = face->dir_tables; + limit = entry + face->num_tables; + + for ( ; entry < limit; entry++ ) + { + if ( entry->Tag == tag ) { + return entry; + } + } + + FT_TRACE3( ( " Could not find table!\n" ) ); + return 0; +} + + +/*************************************************************************/ +/* */ +/* */ +/* TT_Goto_Table */ +/* */ +/* */ +/* Looks for a TrueType table by name, then seek a stream to it. */ +/* */ +/* */ +/* face :: A face object handle. */ +/* tag :: The searched tag. */ +/* stream :: The stream to seek when the table is found. */ +/* */ +/* */ +/* length :: The length of the table if found, undefined otherwise. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +LOCAL_FUNC +FT_Error TT_Goto_Table( TT_Face face, + FT_ULong tag, + FT_Stream stream, + FT_ULong* length ) { + TT_Table* table; + FT_Error error; + + + table = TT_LookUp_Table( face, tag ); + if ( table ) { + if ( length ) { + *length = table->Length; + } + + (void)FILE_Seek( table->Offset ); + } else { + error = TT_Err_Table_Missing; + } + + return error; +} + + +/*************************************************************************/ +/* */ +/* */ +/* TT_Load_SFNT_Header */ +/* */ +/* */ +/* Loads the header of a SFNT font file. Supports collections. */ +/* */ +/* */ +/* face :: A handle to the target face object. */ +/* stream :: The input stream. */ +/* face_index :: If the font is a collection, the number of the font */ +/* in the collection, ignored otherwise. */ +/* */ +/* */ +/* sfnt :: The SFNT header. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +/* */ +/* The stream cursor must be at the font file's origin. */ +/* */ +/* This function recognizes fonts embedded in a `TrueType collection' */ +/* */ +/* The header will be checked whether it is valid by looking at the */ +/* values of `search_range', `entry_selector', and `range_shift'. */ +/* */ +LOCAL_FUNC +FT_Error TT_Load_SFNT_Header( TT_Face face, + FT_Stream stream, + FT_Long face_index, + SFNT_Header* sfnt ) { + FT_Error error; + FT_ULong format_tag; + FT_Memory memory = stream->memory; + + const FT_Frame_Field sfnt_header_fields[] = + { + FT_FRAME_START( 8 ), + FT_FRAME_USHORT( SFNT_Header, num_tables ), + FT_FRAME_USHORT( SFNT_Header, search_range ), + FT_FRAME_USHORT( SFNT_Header, entry_selector ), + FT_FRAME_USHORT( SFNT_Header, range_shift ), + FT_FRAME_END + }; + + const FT_Frame_Field ttc_header_fields[] = + { + FT_FRAME_START( 8 ), + FT_FRAME_LONG( TTC_Header, version ), + FT_FRAME_LONG( TTC_Header, count ), + FT_FRAME_END + }; + + + FT_TRACE2( ( "TT_Load_SFNT_Header: %08p, %ld\n", + face, face_index ) ); + + face->ttc_header.tag = 0; + face->ttc_header.version = 0; + face->ttc_header.count = 0; + + face->num_tables = 0; + + /* first of all, read the first 4 bytes. If it is `ttcf', then the */ + /* file is a TrueType collection, otherwise it can be any other */ + /* kind of font. */ + if ( READ_ULong( format_tag ) ) { + goto Exit; + } + + if ( format_tag == TTAG_ttcf ) { + FT_Int n; + + + FT_TRACE3( ( "TT_Load_SFNT_Header: file is a collection\n" ) ); + + /* it's a TrueType collection, i.e. a file containing several */ + /* font files. Read the font directory now */ + if ( READ_Fields( ttc_header_fields, &face->ttc_header ) ) { + goto Exit; + } + + /* now read the offsets of each font in the file */ + if ( ALLOC_ARRAY( face->ttc_header.offsets, + face->ttc_header.count, + FT_ULong ) || + ACCESS_Frame( face->ttc_header.count * 4L ) ) { + goto Exit; + } + + for ( n = 0; n < face->ttc_header.count; n++ ) + face->ttc_header.offsets[n] = GET_ULong(); + + FORGET_Frame(); + + /* check face index */ + if ( face_index >= face->ttc_header.count ) { + error = TT_Err_Bad_Argument; + goto Exit; + } + + /* seek to the appropriate TrueType file, then read tag */ + if ( FILE_Seek( face->ttc_header.offsets[face_index] ) || + READ_Long( format_tag ) ) { + goto Exit; + } + } + + /* the format tag was read, now check the rest of the header */ + sfnt->format_tag = format_tag; + if ( READ_Fields( sfnt_header_fields, sfnt ) ) { + goto Exit; + } + + /* now, check the values of `num_tables', `seach_range', etc. */ + { + FT_UInt num_tables = sfnt->num_tables; + FT_ULong entry_selector = 1L << sfnt->entry_selector; + + + /* IMPORTANT: Many fonts have an incorrect `search_range' value, so */ + /* we only check the `entry_selector' correctness here. */ + /* */ + if ( num_tables == 0 || + entry_selector > num_tables || + entry_selector * 2 <= num_tables ) { + FT_TRACE2( ( "TT_Load_SFNT_Header: file is not SFNT!\n" ) ); + error = FT_Err_Unknown_File_Format; + } + } + +Exit: + return error; +} + + +/*************************************************************************/ +/* */ +/* */ +/* TT_Load_Directory */ +/* */ +/* */ +/* Loads the table directory into a face object. */ +/* */ +/* */ +/* face :: A handle to the target face object. */ +/* */ +/* */ +/* stream :: The input stream. */ +/* sfnt :: The SFNT directory header. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +/* */ +/* The stream cursor must be at the font file's origin. */ +/* */ +LOCAL_FUNC +FT_Error TT_Load_Directory( TT_Face face, + FT_Stream stream, + SFNT_Header* sfnt ) { + FT_Error error; + FT_Memory memory = stream->memory; + + TT_Table *entry, *limit; + + + FT_TRACE2( ( "TT_Load_Directory: %08p\n", face ) ); + + FT_TRACE2( ( "-- Tables count: %12u\n", sfnt->num_tables ) ); + FT_TRACE2( ( "-- Format version: %08lx\n", sfnt->format_tag ) ); + + face->num_tables = sfnt->num_tables; + + if ( ALLOC_ARRAY( face->dir_tables, + face->num_tables, + TT_Table ) ) { + goto Exit; + } + + if ( ACCESS_Frame( face->num_tables * 16L ) ) { + goto Exit; + } + + entry = face->dir_tables; + limit = entry + face->num_tables; + + for ( ; entry < limit; entry++ ) + { /* loop through the tables and get all entries */ + entry->Tag = GET_Tag4(); + entry->CheckSum = GET_ULong(); + entry->Offset = GET_Long(); + entry->Length = GET_Long(); + + FT_TRACE2( ( " %c%c%c%c - %08lx - %08lx\n", + (FT_Char)( entry->Tag >> 24 ), + (FT_Char)( entry->Tag >> 16 ), + (FT_Char)( entry->Tag >> 8 ), + (FT_Char)( entry->Tag ), + entry->Offset, + entry->Length ) ); + } + + FORGET_Frame(); + + FT_TRACE2( ( "Directory loaded\n\n" ) ); + +Exit: + return error; +} + + +/*************************************************************************/ +/* */ +/* */ +/* TT_Load_Any */ +/* */ +/* */ +/* Loads any font table into client memory. */ +/* */ +/* */ +/* face :: The face object to look for. */ +/* */ +/* tag :: The tag of table to load. Use the value 0 if you want */ +/* to access the whole font file, else set this parameter */ +/* to a valid TrueType table tag that you can forge with */ +/* the MAKE_TT_TAG macro. */ +/* */ +/* offset :: The starting offset in the table (or the file if */ +/* tag == 0). */ +/* */ +/* length :: The address of the decision variable: */ +/* */ +/* If length == NULL: */ +/* Loads the whole table. Returns an error if */ +/* `offset' == 0! */ +/* */ +/* If *length == 0: */ +/* Exits immediately; returning the length of the given */ +/* table or of the font file, depending on the value of */ +/* `tag'. */ +/* */ +/* If *length != 0: */ +/* Loads the next `length' bytes of table or font, */ +/* starting at offset `offset' (in table or font too). */ +/* */ +/* */ +/* buffer :: The address of target buffer. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +LOCAL_FUNC +FT_Error TT_Load_Any( TT_Face face, + FT_ULong tag, + FT_Long offset, + FT_Byte* buffer, + FT_ULong* length ) { + FT_Error error; + FT_Stream stream; + TT_Table* table; + FT_ULong size; + + + if ( tag != 0 ) { + /* look for tag in font directory */ + table = TT_LookUp_Table( face, tag ); + if ( !table ) { + error = TT_Err_Table_Missing; + goto Exit; + } + + offset += table->Offset; + size = table->Length; + } else { + /* tag == 0 -- the user wants to access the font file directly */ + size = face->root.stream->size; + } + + if ( length && *length == 0 ) { + *length = size; + + return TT_Err_Ok; + } + + if ( length ) { + size = *length; + } + + stream = face->root.stream; + (void)FILE_Read_At( offset, buffer, size ); + +Exit: + return error; +} + + +/*************************************************************************/ +/* */ +/* */ +/* TT_Load_Header */ +/* */ +/* */ +/* Loads the TrueType font header. */ +/* */ +/* */ +/* face :: A handle to the target face object. */ +/* stream :: The input stream. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +LOCAL_FUNC +FT_Error TT_Load_Header( TT_Face face, + FT_Stream stream ) { + FT_Error error; + TT_Header* header; + + static const FT_Frame_Field header_fields[] = + { + FT_FRAME_START( 54 ), + FT_FRAME_ULONG( TT_Header, Table_Version ), + FT_FRAME_ULONG( TT_Header, Font_Revision ), + FT_FRAME_LONG( TT_Header, CheckSum_Adjust ), + FT_FRAME_LONG( TT_Header, Magic_Number ), + FT_FRAME_USHORT( TT_Header, Flags ), + FT_FRAME_USHORT( TT_Header, Units_Per_EM ), + FT_FRAME_LONG( TT_Header, Created[0] ), + FT_FRAME_LONG( TT_Header, Created[1] ), + FT_FRAME_LONG( TT_Header, Modified[0] ), + FT_FRAME_LONG( TT_Header, Modified[1] ), + FT_FRAME_SHORT( TT_Header, xMin ), + FT_FRAME_SHORT( TT_Header, yMin ), + FT_FRAME_SHORT( TT_Header, xMax ), + FT_FRAME_SHORT( TT_Header, yMax ), + FT_FRAME_USHORT( TT_Header, Mac_Style ), + FT_FRAME_USHORT( TT_Header, Lowest_Rec_PPEM ), + FT_FRAME_SHORT( TT_Header, Font_Direction ), + FT_FRAME_SHORT( TT_Header, Index_To_Loc_Format ), + FT_FRAME_SHORT( TT_Header, Glyph_Data_Format ), + FT_FRAME_END + }; + + + FT_TRACE2( ( "Load_TT_Header: %08p\n", face ) ); + + error = face->goto_table( face, TTAG_head, stream, 0 ); + if ( error ) { + FT_TRACE0( ( "Font Header is missing!\n" ) ); + goto Exit; + } + + header = &face->header; + + if ( READ_Fields( header_fields, header ) ) { + goto Exit; + } + + FT_TRACE2( ( " Units per EM: %8u\n", header->Units_Per_EM ) ); + FT_TRACE2( ( " IndexToLoc: %8d\n", header->Index_To_Loc_Format ) ); + FT_TRACE2( ( "Font Header Loaded.\n" ) ); + +Exit: + return error; +} + + +/*************************************************************************/ +/* */ +/* */ +/* TT_Load_MaxProfile */ +/* */ +/* */ +/* Loads the maximum profile into a face object. */ +/* */ +/* */ +/* face :: A handle to the target face object. */ +/* stream :: The input stream. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +LOCAL_FUNC +FT_Error TT_Load_MaxProfile( TT_Face face, + FT_Stream stream ) { + FT_Error error; + TT_MaxProfile* maxProfile = &face->max_profile; + + const FT_Frame_Field maxp_fields[] = + { + FT_FRAME_START( 32 ), + FT_FRAME_ULONG( TT_MaxProfile, version ), + FT_FRAME_USHORT( TT_MaxProfile, numGlyphs ), + FT_FRAME_USHORT( TT_MaxProfile, maxPoints ), + FT_FRAME_USHORT( TT_MaxProfile, maxContours ), + FT_FRAME_USHORT( TT_MaxProfile, maxCompositePoints ), + FT_FRAME_USHORT( TT_MaxProfile, maxCompositeContours ), + FT_FRAME_USHORT( TT_MaxProfile, maxZones ), + FT_FRAME_USHORT( TT_MaxProfile, maxTwilightPoints ), + FT_FRAME_USHORT( TT_MaxProfile, maxStorage ), + FT_FRAME_USHORT( TT_MaxProfile, maxFunctionDefs ), + FT_FRAME_USHORT( TT_MaxProfile, maxInstructionDefs ), + FT_FRAME_USHORT( TT_MaxProfile, maxStackElements ), + FT_FRAME_USHORT( TT_MaxProfile, maxSizeOfInstructions ), + FT_FRAME_USHORT( TT_MaxProfile, maxComponentElements ), + FT_FRAME_USHORT( TT_MaxProfile, maxComponentDepth ), + FT_FRAME_END + }; + + + FT_TRACE2( ( "Load_TT_MaxProfile: %08p\n", face ) ); + + error = face->goto_table( face, TTAG_maxp, stream, 0 ); + if ( error ) { + goto Exit; + } + + if ( READ_Fields( maxp_fields, maxProfile ) ) { + goto Exit; + } + + /* XXX: an adjustment that is necessary to load certain */ + /* broken fonts like `Keystrokes MT' :-( */ + /* */ + /* We allocate 64 function entries by default when */ + /* the maxFunctionDefs field is null. */ + + if ( maxProfile->maxFunctionDefs == 0 ) { + maxProfile->maxFunctionDefs = 64; + } + + face->root.num_glyphs = maxProfile->numGlyphs; + + face->root.max_points = MAX( maxProfile->maxCompositePoints, + maxProfile->maxPoints ); + + face->root.max_contours = MAX( maxProfile->maxCompositeContours, + maxProfile->maxContours ); + + face->max_components = (FT_ULong)maxProfile->maxComponentElements + + maxProfile->maxComponentDepth; + + /* XXX: some fonts have maxComponents set to 0; we will */ + /* then use 16 of them by default. */ + if ( face->max_components == 0 ) { + face->max_components = 16; + } + + /* We also increase maxPoints and maxContours in order to support */ + /* some broken fonts. */ + face->root.max_points += 8; + face->root.max_contours += 4; + + FT_TRACE2( ( "MAXP loaded.\n" ) ); + +Exit: + return error; +} + + +/*************************************************************************/ +/* */ +/* */ +/* TT_Load_Metrics */ +/* */ +/* */ +/* Loads the horizontal or vertical metrics table into a face object. */ +/* */ +/* */ +/* face :: A handle to the target face object. */ +/* stream :: The input stream. */ +/* vertical :: A boolean flag. If set, load vertical metrics. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +static +FT_Error TT_Load_Metrics( TT_Face face, + FT_Stream stream, + FT_Bool vertical ) { + FT_Error error; + FT_Memory memory = stream->memory; + + FT_ULong table_len; + FT_Long num_shorts, num_longs, num_shorts_checked; + + TT_LongMetrics** longs; + TT_ShortMetrics** shorts; + + + FT_TRACE2( ( "TT_Load_%s_Metrics: %08p\n", vertical ? "Vertical" + : "Horizontal", + face ) ); + + if ( vertical ) { + /* The table is optional, quit silently if it wasn't found */ + /* XXX: Some fonts have a valid vertical header with a non-null */ + /* `number_of_VMetrics' fields, but no corresponding `vmtx' */ + /* table to get the metrics from (e.g. mingliu). */ + /* */ + /* For safety, we set the field to 0! */ + /* */ + error = face->goto_table( face, TTAG_vmtx, stream, &table_len ); + if ( error ) { + /* Set number_Of_VMetrics to 0! */ + FT_TRACE2( ( " no vertical header in file.\n" ) ); + face->vertical.number_Of_VMetrics = 0; + error = TT_Err_Ok; + goto Exit; + } + + num_longs = face->vertical.number_Of_VMetrics; + longs = (TT_LongMetrics**)&face->vertical.long_metrics; + shorts = (TT_ShortMetrics**)&face->vertical.short_metrics; + } else + { + error = face->goto_table( face, TTAG_hmtx, stream, &table_len ); + if ( error ) { + FT_ERROR( ( " no horizontal metrics in file!\n" ) ); + error = TT_Err_Hmtx_Table_Missing; + goto Exit; + } + + num_longs = face->horizontal.number_Of_HMetrics; + longs = (TT_LongMetrics**)&face->horizontal.long_metrics; + shorts = (TT_ShortMetrics**)&face->horizontal.short_metrics; + } + + /* never trust derived values */ + + num_shorts = face->max_profile.numGlyphs - num_longs; + num_shorts_checked = ( table_len - num_longs * 4L ) / 2; + + if ( num_shorts < 0 ) { + FT_ERROR( ( "TT_Load_%s_Metrics: more metrics than glyphs!\n", + vertical ? "Vertical" + : "Horizontal" ) ); + + error = vertical ? TT_Err_Invalid_Vert_Metrics + : TT_Err_Invalid_Horiz_Metrics; + goto Exit; + } + + if ( ALLOC_ARRAY( *longs, num_longs, TT_LongMetrics ) || + ALLOC_ARRAY( *shorts, num_shorts, TT_ShortMetrics ) ) { + goto Exit; + } + + if ( ACCESS_Frame( table_len ) ) { + goto Exit; + } + + { + TT_LongMetrics* cur = *longs; + TT_LongMetrics* limit = cur + num_longs; + + + for ( ; cur < limit; cur++ ) + { + cur->advance = GET_UShort(); + cur->bearing = GET_Short(); + } + } + + /* do we have an inconsistent number of metric values? */ + { + TT_ShortMetrics* cur = *shorts; + TT_ShortMetrics* limit = cur + MIN( num_shorts, num_shorts_checked ); + + + for ( ; cur < limit; cur++ ) + *cur = GET_Short(); + + /* we fill up the missing left side bearings with the */ + /* last valid value. Since this will occur for buggy CJK */ + /* fonts usually only, nothing serious will happen */ + if ( num_shorts > num_shorts_checked && num_shorts_checked > 0 ) { + FT_Short val = *( shorts )[num_shorts_checked - 1]; + + + limit = *shorts + num_shorts; + for ( ; cur < limit; cur++ ) + *cur = val; + } + } + + FORGET_Frame(); + + FT_TRACE2( ( "loaded\n" ) ); + +Exit: + return error; +} + + +/*************************************************************************/ +/* */ +/* */ +/* TT_Load_Metrics_Header */ +/* */ +/* */ +/* Loads the horizontal or vertical header in a face object. */ +/* */ +/* */ +/* face :: A handle to the target face object. */ +/* stream :: The input stream. */ +/* vertical :: A boolean flag. If set, load vertical metrics. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +LOCAL_FUNC +FT_Error TT_Load_Metrics_Header( TT_Face face, + FT_Stream stream, + FT_Bool vertical ) { + FT_Error error; + TT_HoriHeader* header; + + const FT_Frame_Field metrics_header_fields[] = + { + FT_FRAME_START( 36 ), + FT_FRAME_ULONG( TT_HoriHeader, Version ), + FT_FRAME_SHORT( TT_HoriHeader, Ascender ), + FT_FRAME_SHORT( TT_HoriHeader, Descender ), + FT_FRAME_SHORT( TT_HoriHeader, Line_Gap ), + FT_FRAME_USHORT( TT_HoriHeader, advance_Width_Max ), + FT_FRAME_SHORT( TT_HoriHeader, min_Left_Side_Bearing ), + FT_FRAME_SHORT( TT_HoriHeader, min_Right_Side_Bearing ), + FT_FRAME_SHORT( TT_HoriHeader, xMax_Extent ), + FT_FRAME_SHORT( TT_HoriHeader, caret_Slope_Rise ), + FT_FRAME_SHORT( TT_HoriHeader, caret_Slope_Run ), + FT_FRAME_SHORT( TT_HoriHeader, Reserved[0] ), + FT_FRAME_SHORT( TT_HoriHeader, Reserved[1] ), + FT_FRAME_SHORT( TT_HoriHeader, Reserved[2] ), + FT_FRAME_SHORT( TT_HoriHeader, Reserved[3] ), + FT_FRAME_SHORT( TT_HoriHeader, Reserved[4] ), + FT_FRAME_SHORT( TT_HoriHeader, metric_Data_Format ), + FT_FRAME_USHORT( TT_HoriHeader, number_Of_HMetrics ), + FT_FRAME_END + }; + + + FT_TRACE2( ( vertical ? "Vertical header " : "Horizontal header " ) ); + + if ( vertical ) { + face->vertical_info = 0; + + /* The vertical header table is optional, so return quietly if */ + /* we don't find it. */ + error = face->goto_table( face, TTAG_vhea, stream, 0 ); + if ( error ) { + error = TT_Err_Ok; + goto Exit; + } + + face->vertical_info = 1; + header = (TT_HoriHeader*)&face->vertical; + } else + { + /* The horizontal header is mandatory; return an error if we */ + /* don't find it. */ + error = face->goto_table( face, TTAG_hhea, stream, 0 ); + if ( error ) { + error = TT_Err_Horiz_Header_Missing; + goto Exit; + } + + header = &face->horizontal; + } + + if ( READ_Fields( metrics_header_fields, header ) ) { + goto Exit; + } + + header->long_metrics = NULL; + header->short_metrics = NULL; + + FT_TRACE2( ( "loaded\n" ) ); + + /* Now try to load the corresponding metrics */ + + error = TT_Load_Metrics( face, stream, vertical ); + +Exit: + return error; +} + + +/*************************************************************************/ +/* */ +/* */ +/* TT_Load_Names */ +/* */ +/* */ +/* Loads the name records. */ +/* */ +/* */ +/* face :: A handle to the target face object. */ +/* stream :: The input stream. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +LOCAL_FUNC +FT_Error TT_Load_Names( TT_Face face, + FT_Stream stream ) { + FT_Error error; + FT_Memory memory = stream->memory; + + FT_ULong table_pos, table_len; + FT_ULong storageSize; + + TT_NameTable* names; + + const FT_Frame_Field name_table_fields[] = + { + FT_FRAME_START( 6 ), + FT_FRAME_USHORT( TT_NameTable, format ), + FT_FRAME_USHORT( TT_NameTable, numNameRecords ), + FT_FRAME_USHORT( TT_NameTable, storageOffset ), + FT_FRAME_END + }; + + const FT_Frame_Field name_record_fields[] = + { + /* no FT_FRAME_START */ + FT_FRAME_USHORT( TT_NameRec, platformID ), + FT_FRAME_USHORT( TT_NameRec, encodingID ), + FT_FRAME_USHORT( TT_NameRec, languageID ), + FT_FRAME_USHORT( TT_NameRec, nameID ), + FT_FRAME_USHORT( TT_NameRec, stringLength ), + FT_FRAME_USHORT( TT_NameRec, stringOffset ), + FT_FRAME_END + }; + + + FT_TRACE2( ( "Names " ) ); + + error = face->goto_table( face, TTAG_name, stream, &table_len ); + if ( error ) { + /* The name table is required so indicate failure. */ + FT_TRACE2( ( "is missing!\n" ) ); + error = TT_Err_Name_Table_Missing; + goto Exit; + } + + table_pos = FILE_Pos(); + + names = &face->name_table; + + if ( READ_Fields( name_table_fields, names ) ) { + goto Exit; + } + + /* Allocate the array of name records. */ + if ( ALLOC_ARRAY( names->names, + names->numNameRecords, + TT_NameRec ) || + ACCESS_Frame( names->numNameRecords * 12L ) ) { + goto Exit; + } + + /* Load the name records and determine how much storage is needed */ + /* to hold the strings themselves. */ + { + TT_NameRec* cur = names->names; + TT_NameRec* limit = cur + names->numNameRecords; + + + storageSize = 0; + + for ( ; cur < limit; cur++ ) + { + FT_ULong upper; + + + (void)READ_Fields( name_record_fields, cur ); + + upper = (FT_ULong)( cur->stringOffset + cur->stringLength ); + if ( upper > storageSize ) { + storageSize = upper; + } + } + } + + FORGET_Frame(); + + if ( storageSize > 0 ) { + /* allocate the name storage area in memory, then read it */ + if ( ALLOC( names->storage, storageSize ) || + FILE_Read_At( table_pos + names->storageOffset, + names->storage, storageSize ) ) { + goto Exit; + } + + /* Go through and assign the string pointers to the name records. */ + { + TT_NameRec* cur = names->names; + TT_NameRec* limit = cur + names->numNameRecords; + + + for ( ; cur < limit; cur++ ) + cur->string = names->storage + cur->stringOffset; + } + +#ifdef FT_DEBUG_LEVEL_TRACE + + /* Print Name Record Table in case of debugging */ + { + TT_NameRec* cur = names->names; + TT_NameRec* limit = cur + names->numNameRecords; + + + for ( ; cur < limit; cur++ ) + { + FT_UInt j; + + + FT_TRACE3( ( "%d %d %x %d\n ", + cur->platformID, + cur->encodingID, + cur->languageID, + cur->nameID ) ); + + /* I know that M$ encoded strings are Unicode, */ + /* but this works reasonable well for debugging purposes. */ + if ( cur->string ) { + for ( j = 0; j < cur->stringLength; j++ ) + { + FT_Char c = *( cur->string + j ); + + + if ( (FT_Byte)c < 128 ) { + FT_TRACE3( ( "%c", c ) ); + } + } + } + } + } + FT_TRACE3( ( "\n" ) ); + +#endif /* FT_DEBUG_LEVEL_TRACE */ + + } + FT_TRACE2( ( "loaded\n" ) ); + + /* everything went well, update face->num_names */ + face->num_names = names->numNameRecords; + +Exit: + return error; +} + + +/*************************************************************************/ +/* */ +/* */ +/* TT_Free_Names */ +/* */ +/* */ +/* Frees the name records. */ +/* */ +/* */ +/* face :: A handle to the target face object. */ +/* */ +LOCAL_FUNC +void TT_Free_Names( TT_Face face ) { + FT_Memory memory = face->root.driver->root.memory; + TT_NameTable* names = &face->name_table; + + + /* free strings table */ + FREE( names->names ); + + /* free strings storage */ + FREE( names->storage ); + + names->numNameRecords = 0; + names->format = 0; + names->storageOffset = 0; +} + + +/*************************************************************************/ +/* */ +/* */ +/* TT_Load_CMap */ +/* */ +/* */ +/* Loads the cmap directory in a face object. The cmaps itselves are */ +/* loaded on demand in the `ttcmap.c' module. */ +/* */ +/* */ +/* face :: A handle to the target face object. */ +/* stream :: A handle to the input stream. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +LOCAL_FUNC +FT_Error TT_Load_CMap( TT_Face face, + FT_Stream stream ) { + FT_Error error; + FT_Memory memory = stream->memory; + FT_Long table_start; + TT_CMapDir cmap_dir; + + const FT_Frame_Field cmap_fields[] = + { + FT_FRAME_START( 4 ), + FT_FRAME_USHORT( TT_CMapDir, tableVersionNumber ), + FT_FRAME_USHORT( TT_CMapDir, numCMaps ), + FT_FRAME_END + }; + + const FT_Frame_Field cmap_rec_fields[] = + { + FT_FRAME_START( 6 ), + FT_FRAME_USHORT( TT_CMapTable, format ), + FT_FRAME_USHORT( TT_CMapTable, length ), + FT_FRAME_USHORT( TT_CMapTable, version ), + FT_FRAME_END + }; + + + FT_TRACE2( ( "CMaps " ) ); + + error = face->goto_table( face, TTAG_cmap, stream, 0 ); + if ( error ) { + error = TT_Err_CMap_Table_Missing; + goto Exit; + } + + table_start = FILE_Pos(); + + if ( READ_Fields( cmap_fields, &cmap_dir ) ) { + goto Exit; + } + + /* reserve space in face table for cmap tables */ + if ( ALLOC_ARRAY( face->charmaps, + cmap_dir.numCMaps, + TT_CharMapRec ) ) { + goto Exit; + } + + face->num_charmaps = cmap_dir.numCMaps; + { + TT_CharMap charmap = face->charmaps; + TT_CharMap limit = charmap + face->num_charmaps; + + + /* read the header of each charmap first */ + if ( ACCESS_Frame( face->num_charmaps * 8L ) ) { + goto Exit; + } + + for ( ; charmap < limit; charmap++ ) + { + TT_CMapTable* cmap; + + + charmap->root.face = (FT_Face)face; + cmap = &charmap->cmap; + + cmap->loaded = FALSE; + cmap->platformID = GET_UShort(); + cmap->platformEncodingID = GET_UShort(); + cmap->offset = (FT_ULong)GET_Long(); + } + + FORGET_Frame(); + + /* now read the rest of each table */ + for ( charmap = face->charmaps; charmap < limit; charmap++ ) + { + TT_CMapTable* cmap = &charmap->cmap; + + + if ( FILE_Seek( table_start + (FT_Long)cmap->offset ) || + READ_Fields( cmap_rec_fields, cmap ) ) { + goto Exit; + } + + cmap->offset = FILE_Pos(); + } + } + + FT_TRACE2( ( "loaded\n" ) ); + +Exit: + return error; +} + + +/*************************************************************************/ +/* */ +/* */ +/* TT_Load_OS2 */ +/* */ +/* */ +/* Loads the OS2 table. */ +/* */ +/* */ +/* face :: A handle to the target face object. */ +/* stream :: A handle to the input stream. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +LOCAL_FUNC +FT_Error TT_Load_OS2( TT_Face face, + FT_Stream stream ) { + FT_Error error; + TT_OS2* os2; + + const FT_Frame_Field os2_fields[] = + { + FT_FRAME_START( 78 ), + FT_FRAME_USHORT( TT_OS2, version ), + FT_FRAME_SHORT( TT_OS2, xAvgCharWidth ), + FT_FRAME_USHORT( TT_OS2, usWeightClass ), + FT_FRAME_USHORT( TT_OS2, usWidthClass ), + FT_FRAME_SHORT( TT_OS2, fsType ), + FT_FRAME_SHORT( TT_OS2, ySubscriptXSize ), + FT_FRAME_SHORT( TT_OS2, ySubscriptYSize ), + FT_FRAME_SHORT( TT_OS2, ySubscriptXOffset ), + FT_FRAME_SHORT( TT_OS2, ySubscriptYOffset ), + FT_FRAME_SHORT( TT_OS2, ySuperscriptXSize ), + FT_FRAME_SHORT( TT_OS2, ySuperscriptYSize ), + FT_FRAME_SHORT( TT_OS2, ySuperscriptXOffset ), + FT_FRAME_SHORT( TT_OS2, ySuperscriptYOffset ), + FT_FRAME_SHORT( TT_OS2, yStrikeoutSize ), + FT_FRAME_SHORT( TT_OS2, yStrikeoutPosition ), + FT_FRAME_SHORT( TT_OS2, sFamilyClass ), + FT_FRAME_BYTE( TT_OS2, panose[0] ), + FT_FRAME_BYTE( TT_OS2, panose[1] ), + FT_FRAME_BYTE( TT_OS2, panose[2] ), + FT_FRAME_BYTE( TT_OS2, panose[3] ), + FT_FRAME_BYTE( TT_OS2, panose[4] ), + FT_FRAME_BYTE( TT_OS2, panose[5] ), + FT_FRAME_BYTE( TT_OS2, panose[6] ), + FT_FRAME_BYTE( TT_OS2, panose[7] ), + FT_FRAME_BYTE( TT_OS2, panose[8] ), + FT_FRAME_BYTE( TT_OS2, panose[9] ), + FT_FRAME_ULONG( TT_OS2, ulUnicodeRange1 ), + FT_FRAME_ULONG( TT_OS2, ulUnicodeRange2 ), + FT_FRAME_ULONG( TT_OS2, ulUnicodeRange3 ), + FT_FRAME_ULONG( TT_OS2, ulUnicodeRange4 ), + FT_FRAME_BYTE( TT_OS2, achVendID[0] ), + FT_FRAME_BYTE( TT_OS2, achVendID[1] ), + FT_FRAME_BYTE( TT_OS2, achVendID[2] ), + FT_FRAME_BYTE( TT_OS2, achVendID[3] ), + + FT_FRAME_USHORT( TT_OS2, fsSelection ), + FT_FRAME_USHORT( TT_OS2, usFirstCharIndex ), + FT_FRAME_USHORT( TT_OS2, usLastCharIndex ), + FT_FRAME_SHORT( TT_OS2, sTypoAscender ), + FT_FRAME_SHORT( TT_OS2, sTypoDescender ), + FT_FRAME_SHORT( TT_OS2, sTypoLineGap ), + FT_FRAME_USHORT( TT_OS2, usWinAscent ), + FT_FRAME_USHORT( TT_OS2, usWinDescent ), + FT_FRAME_END + }; + + const FT_Frame_Field os2_fields_extra[] = + { + FT_FRAME_START( 8 ), + FT_FRAME_ULONG( TT_OS2, ulCodePageRange1 ), + FT_FRAME_ULONG( TT_OS2, ulCodePageRange2 ), + FT_FRAME_END + }; + + const FT_Frame_Field os2_fields_extra2[] = + { + FT_FRAME_START( 10 ), + FT_FRAME_SHORT( TT_OS2, sxHeight ), + FT_FRAME_SHORT( TT_OS2, sCapHeight ), + FT_FRAME_USHORT( TT_OS2, usDefaultChar ), + FT_FRAME_USHORT( TT_OS2, usBreakChar ), + FT_FRAME_USHORT( TT_OS2, usMaxContext ), + FT_FRAME_END + }; + + + FT_TRACE2( ( "OS/2 Table " ) ); + + /* We now support old Mac fonts where the OS/2 table doesn't */ + /* exist. Simply put, we set the `version' field to 0xFFFF */ + /* and test this value each time we need to access the table. */ + error = face->goto_table( face, TTAG_OS2, stream, 0 ); + if ( error ) { + FT_TRACE2( ( "is missing!\n" ) ); + face->os2.version = 0xFFFF; + error = TT_Err_Ok; + goto Exit; + } + + os2 = &face->os2; + + if ( READ_Fields( os2_fields, os2 ) ) { + goto Exit; + } + + os2->ulCodePageRange1 = 0; + os2->ulCodePageRange2 = 0; + + if ( os2->version >= 0x0001 ) { + /* only version 1 tables */ + if ( READ_Fields( os2_fields_extra, os2 ) ) { + goto Exit; + } + + if ( os2->version >= 0x0002 ) { + /* only version 2 tables */ + if ( READ_Fields( os2_fields_extra2, os2 ) ) { + goto Exit; + } + } + } + + FT_TRACE2( ( "loaded\n" ) ); + +Exit: + return error; +} + + +/*************************************************************************/ +/* */ +/* */ +/* TT_Load_Postscript */ +/* */ +/* */ +/* Loads the Postscript table. */ +/* */ +/* */ +/* face :: A handle to the target face object. */ +/* stream :: A handle to the input stream. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +LOCAL_FUNC +FT_Error TT_Load_PostScript( TT_Face face, + FT_Stream stream ) { + FT_Error error; + TT_Postscript* post = &face->postscript; + + static const FT_Frame_Field post_fields[] = + { + FT_FRAME_START( 32 ), + FT_FRAME_ULONG( TT_Postscript, FormatType ), + FT_FRAME_ULONG( TT_Postscript, italicAngle ), + FT_FRAME_SHORT( TT_Postscript, underlinePosition ), + FT_FRAME_SHORT( TT_Postscript, underlineThickness ), + FT_FRAME_ULONG( TT_Postscript, isFixedPitch ), + FT_FRAME_ULONG( TT_Postscript, minMemType42 ), + FT_FRAME_ULONG( TT_Postscript, maxMemType42 ), + FT_FRAME_ULONG( TT_Postscript, minMemType1 ), + FT_FRAME_ULONG( TT_Postscript, maxMemType1 ), + FT_FRAME_END + }; + + + FT_TRACE2( ( "PostScript " ) ); + + error = face->goto_table( face, TTAG_post, stream, 0 ); + if ( error ) { + return TT_Err_Post_Table_Missing; + } + + if ( READ_Fields( post_fields, post ) ) { + return error; + } + + /* we don't load the glyph names, we do that in another */ + /* module (ttpost). */ + FT_TRACE2( ( "loaded\n" ) ); + + return TT_Err_Ok; +} + + +/*************************************************************************/ +/* */ +/* */ +/* TT_Load_PCLT */ +/* */ +/* */ +/* Loads the PCL 5 Table. */ +/* */ +/* */ +/* face :: A handle to the target face object. */ +/* stream :: A handle to the input stream. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +LOCAL_FUNC +FT_Error TT_Load_PCLT( TT_Face face, + FT_Stream stream ) { + static const FT_Frame_Field pclt_fields[] = + { + FT_FRAME_START( 54 ), + FT_FRAME_ULONG( TT_PCLT, Version ), + FT_FRAME_ULONG( TT_PCLT, FontNumber ), + FT_FRAME_USHORT( TT_PCLT, Pitch ), + FT_FRAME_USHORT( TT_PCLT, xHeight ), + FT_FRAME_USHORT( TT_PCLT, Style ), + FT_FRAME_USHORT( TT_PCLT, TypeFamily ), + FT_FRAME_USHORT( TT_PCLT, CapHeight ), + FT_FRAME_BYTES( TT_PCLT, TypeFace, 16 ), + FT_FRAME_BYTES( TT_PCLT, CharacterComplement, 8 ), + FT_FRAME_BYTES( TT_PCLT, FileName, 6 ), + FT_FRAME_CHAR( TT_PCLT, StrokeWeight ), + FT_FRAME_CHAR( TT_PCLT, WidthType ), + FT_FRAME_BYTE( TT_PCLT, SerifStyle ), + FT_FRAME_BYTE( TT_PCLT, Reserved ), + FT_FRAME_END + }; + + FT_Error error; + TT_PCLT* pclt = &face->pclt; + + + FT_TRACE2( ( "PCLT " ) ); + + /* optional table */ + error = face->goto_table( face, TTAG_PCLT, stream, 0 ); + if ( error ) { + FT_TRACE2( ( "missing (optional)\n" ) ); + pclt->Version = 0; + return TT_Err_Ok; + } + + if ( READ_Fields( pclt_fields, pclt ) ) { + goto Exit; + } + + FT_TRACE2( ( "loaded\n" ) ); + +Exit: + return error; +} + + +/*************************************************************************/ +/* */ +/* */ +/* TT_Load_Gasp */ +/* */ +/* */ +/* Loads the `gasp' table into a face object. */ +/* */ +/* */ +/* face :: A handle to the target face object. */ +/* stream :: The input stream. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +LOCAL_FUNC +FT_Error TT_Load_Gasp( TT_Face face, + FT_Stream stream ) { + FT_Error error; + FT_Memory memory = stream->memory; + + FT_UInt j,num_ranges; + TT_GaspRange* gaspranges; + + + FT_TRACE2( ( "TT_Load_Gasp: %08p\n", face ) ); + + /* the gasp table is optional */ + error = face->goto_table( face, TTAG_gasp, stream, 0 ); + if ( error ) { + return TT_Err_Ok; + } + + if ( ACCESS_Frame( 4L ) ) { + goto Exit; + } + + face->gasp.version = GET_UShort(); + face->gasp.numRanges = GET_UShort(); + + FORGET_Frame(); + + num_ranges = face->gasp.numRanges; + FT_TRACE3( ( "number of ranges = %d\n", num_ranges ) ); + + if ( ALLOC_ARRAY( gaspranges, num_ranges, TT_GaspRange ) || + ACCESS_Frame( num_ranges * 4L ) ) { + goto Exit; + } + + face->gasp.gaspRanges = gaspranges; + + for ( j = 0; j < num_ranges; j++ ) + { + gaspranges[j].maxPPEM = GET_UShort(); + gaspranges[j].gaspFlag = GET_UShort(); + + FT_TRACE3( ( " [max:%d flag:%d]", + gaspranges[j].maxPPEM, + gaspranges[j].gaspFlag ) ); + } + FT_TRACE3( ( "\n" ) ); + + FORGET_Frame(); + FT_TRACE2( ( "GASP loaded\n" ) ); + +Exit: + return error; +} + + +/*************************************************************************/ +/* */ +/* */ +/* TT_Load_Kern */ +/* */ +/* */ +/* Loads the first kerning table with format 0 in the font. Only */ +/* accepts the first horizontal kerning table. Developers should use */ +/* the `ftxkern' extension to access other kerning tables in the font */ +/* file, if they really want to. */ +/* */ +/* */ +/* face :: A handle to the target face object. */ +/* stream :: The input stream. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +LOCAL_FUNC +FT_Error TT_Load_Kern( TT_Face face, + FT_Stream stream ) { + FT_Error error; + FT_Memory memory = stream->memory; + + FT_UInt n, num_tables, version; + + + /* the kern table is optional; exit silently if it is missing */ + error = face->goto_table( face, TTAG_kern, stream, 0 ); + if ( error ) { + return TT_Err_Ok; + } + + if ( ACCESS_Frame( 4L ) ) { + goto Exit; + } + + version = GET_UShort(); + num_tables = GET_UShort(); + + FORGET_Frame(); + + for ( n = 0; n < num_tables; n++ ) + { + FT_UInt coverage; + FT_UInt length; + + + if ( ACCESS_Frame( 6L ) ) { + goto Exit; + } + + version = GET_UShort(); /* version */ + length = GET_UShort() - 6; /* substract header length */ + coverage = GET_UShort(); + + FORGET_Frame(); + + if ( coverage == 0x0001 ) { + FT_UInt num_pairs; + TT_Kern_0_Pair* pair; + TT_Kern_0_Pair* limit; + + + /* found a horizontal format 0 kerning table! */ + if ( ACCESS_Frame( 8L ) ) { + goto Exit; + } + + num_pairs = GET_UShort(); + + /* skip the rest */ + + FORGET_Frame(); + + /* allocate array of kerning pairs */ + if ( ALLOC_ARRAY( face->kern_pairs, num_pairs, TT_Kern_0_Pair ) || + ACCESS_Frame( 6L * num_pairs ) ) { + goto Exit; + } + + pair = face->kern_pairs; + limit = pair + num_pairs; + for ( ; pair < limit; pair++ ) + { + pair->left = GET_UShort(); + pair->right = GET_UShort(); + pair->value = GET_UShort(); + } + + FORGET_Frame(); + + face->num_kern_pairs = num_pairs; + face->kern_table_index = n; + goto Exit; + } + + if ( FILE_Skip( length ) ) { + goto Exit; + } + } + + /* no kern table found -- doesn't matter */ + face->kern_table_index = -1; + face->num_kern_pairs = 0; + face->kern_pairs = NULL; + +Exit: + return error; +} + + +/*************************************************************************/ +/* */ +/* */ +/* TT_Load_Hdmx */ +/* */ +/* */ +/* Loads the horizontal device metrics table. */ +/* */ +/* */ +/* face :: A handle to the target face object. */ +/* stream :: A handle to the input stream. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +LOCAL_FUNC +FT_Error TT_Load_Hdmx( TT_Face face, + FT_Stream stream ) { + FT_Error error; + FT_Memory memory = stream->memory; + + TT_Hdmx* hdmx = &face->hdmx; + FT_Long num_glyphs; + FT_Long record_size; + + + hdmx->version = 0; + hdmx->num_records = 0; + hdmx->records = 0; + + /* this table is optional */ + error = face->goto_table( face, TTAG_hdmx, stream, 0 ); + if ( error ) { + return TT_Err_Ok; + } + + if ( ACCESS_Frame( 8L ) ) { + goto Exit; + } + + hdmx->version = GET_UShort(); + hdmx->num_records = GET_Short(); + record_size = GET_Long(); + + FORGET_Frame(); + + /* Only recognize format 0 */ + if ( hdmx->version != 0 ) { + goto Exit; + } + + if ( ALLOC_ARRAY( hdmx->records, hdmx->num_records, TT_HdmxRec ) ) { + goto Exit; + } + + num_glyphs = face->root.num_glyphs; + record_size -= num_glyphs + 2; + + { + TT_HdmxRec* cur = hdmx->records; + TT_HdmxRec* limit = cur + hdmx->num_records; + + + for ( ; cur < limit; cur++ ) + { + /* read record */ + if ( READ_Byte( cur->ppem ) || + READ_Byte( cur->max_width ) ) { + goto Exit; + } + + if ( ALLOC( cur->widths, num_glyphs ) || + FILE_Read( cur->widths, num_glyphs ) ) { + goto Exit; + } + + /* skip padding bytes */ + if ( record_size > 0 && FILE_Skip( record_size ) ) { + goto Exit; + } + } + } + +Exit: + return error; +} + + +/*************************************************************************/ +/* */ +/* */ +/* TT_Free_Hdmx */ +/* */ +/* */ +/* Frees the horizontal device metrics table. */ +/* */ +/* */ +/* face :: A handle to the target face object. */ +/* */ +LOCAL_FUNC +void TT_Free_Hdmx( TT_Face face ) { + if ( face ) { + FT_Int n; + FT_Memory memory = face->root.driver->root.memory; + + + for ( n = 0; n < face->hdmx.num_records; n++ ) + FREE( face->hdmx.records[n].widths ); + + FREE( face->hdmx.records ); + face->hdmx.num_records = 0; + } +} + + +/* END */ diff --git a/Projects/Android/jni/rtcw/src/ft2/ttload.h b/Projects/Android/jni/rtcw/src/ft2/ttload.h new file mode 100644 index 0000000..96499fb --- /dev/null +++ b/Projects/Android/jni/rtcw/src/ft2/ttload.h @@ -0,0 +1,132 @@ +/***************************************************************************/ +/* */ +/* ttload.h */ +/* */ +/* Load the basic TrueType tables, i.e., tables that can be either in */ +/* TTF or OTF fonts (specification). */ +/* */ +/* Copyright 1996-2000 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef TTLOAD_H +#define TTLOAD_H + + +#include "ftstream.h" +#include "tttypes.h" + + +#ifdef __cplusplus +extern "C" { +#endif + + +LOCAL_DEF +TT_Table* TT_LookUp_Table( TT_Face face, + FT_ULong tag ); + +LOCAL_DEF +FT_Error TT_Goto_Table( TT_Face face, + FT_ULong tag, + FT_Stream stream, + FT_ULong* length ); + + +LOCAL_DEF +FT_Error TT_Load_SFNT_Header( TT_Face face, + FT_Stream stream, + FT_Long face_index, + SFNT_Header* sfnt ); +LOCAL_DEF +FT_Error TT_Load_Directory( TT_Face face, + FT_Stream stream, + SFNT_Header* sfnt ); + +LOCAL_DEF +FT_Error TT_Load_Any( TT_Face face, + FT_ULong tag, + FT_Long offset, + FT_Byte* buffer, + FT_ULong* length ); + + +LOCAL_DEF +FT_Error TT_Load_Header( TT_Face face, + FT_Stream stream ); + + +LOCAL_DEF +FT_Error TT_Load_Metrics_Header( TT_Face face, + FT_Stream stream, + FT_Bool vertical ); + + +LOCAL_DEF +FT_Error TT_Load_CMap( TT_Face face, + FT_Stream stream ); + + +LOCAL_DEF +FT_Error TT_Load_MaxProfile( TT_Face face, + FT_Stream stream ); + + +LOCAL_DEF +FT_Error TT_Load_Names( TT_Face face, + FT_Stream stream ); + + +LOCAL_DEF +FT_Error TT_Load_OS2( TT_Face face, + FT_Stream stream ); + + +LOCAL_DEF +FT_Error TT_Load_PostScript( TT_Face face, + FT_Stream stream ); + + +LOCAL_DEF +FT_Error TT_Load_Hdmx( TT_Face face, + FT_Stream stream ); + +LOCAL_DEF +FT_Error TT_Load_PCLT( TT_Face face, + FT_Stream stream ); + +LOCAL_DEF +void TT_Free_Names( TT_Face face ); + + +LOCAL_DEF +void TT_Free_Hdmx( TT_Face face ); + + +LOCAL_DEF +FT_Error TT_Load_Kern( TT_Face face, + FT_Stream stream ); + + +LOCAL_DEF +FT_Error TT_Load_Gasp( TT_Face face, + FT_Stream stream ); + + +#ifdef __cplusplus +} +#endif + + +#endif /* TTLOAD_H */ + + +/* END */ diff --git a/Projects/Android/jni/rtcw/src/ft2/ttnameid.h b/Projects/Android/jni/rtcw/src/ft2/ttnameid.h new file mode 100644 index 0000000..feb94ea --- /dev/null +++ b/Projects/Android/jni/rtcw/src/ft2/ttnameid.h @@ -0,0 +1,698 @@ +/***************************************************************************/ +/* */ +/* ttmakeid.h */ +/* */ +/* TrueType name ID definitions (specification only). */ +/* */ +/* Copyright 1996-2000 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef TTNAMEID_H +#define TTNAMEID_H + + +/*************************************************************************/ +/* */ +/* Possible values for the `platform' identifier code in the name */ +/* records of the TTF `name' table. */ +/* */ +#define TT_PLATFORM_APPLE_UNICODE 0 +#define TT_PLATFORM_MACINTOSH 1 +#define TT_PLATFORM_ISO 2 /* deprecated */ +#define TT_PLATFORM_MICROSOFT 3 + + +/*************************************************************************/ +/* */ +/* Possible values of the platform specific encoding identifier field in */ +/* the name records of the TTF `name' table if the `platform' identifier */ +/* code is TT_PLATFORM_APPLE_UNICODE. */ +/* */ +#define TT_APPLE_ID_DEFAULT 0 +#define TT_APPLE_ID_UNICODE_1_1 1 /* specify Hangul at U+34xx */ +#define TT_APPLE_ID_ISO_10646 2 /* deprecated */ +#define TT_APPLE_ID_UNICODE_2_0 3 /* or later */ + + +/*************************************************************************/ +/* */ +/* Possible values of the platform specific encoding identifier field in */ +/* the name records of the TTF `name' table if the `platform' identifier */ +/* code is TT_PLATFORM_MACINTOSH. */ +/* */ +#define TT_MAC_ID_ROMAN 0 +#define TT_MAC_ID_JAPANESE 1 +#define TT_MAC_ID_TRADITIONAL_CHINESE 2 +#define TT_MAC_ID_KOREAN 3 +#define TT_MAC_ID_ARABIC 4 +#define TT_MAC_ID_HEBREW 5 +#define TT_MAC_ID_GREEK 6 +#define TT_MAC_ID_RUSSIAN 7 +#define TT_MAC_ID_RSYMBOL 8 +#define TT_MAC_ID_DEVANAGARI 9 +#define TT_MAC_ID_GURMUKHI 10 +#define TT_MAC_ID_GUJARATI 11 +#define TT_MAC_ID_ORIYA 12 +#define TT_MAC_ID_BENGALI 13 +#define TT_MAC_ID_TAMIL 14 +#define TT_MAC_ID_TELUGU 15 +#define TT_MAC_ID_KANNADA 16 +#define TT_MAC_ID_MALAYALAM 17 +#define TT_MAC_ID_SINHALESE 18 +#define TT_MAC_ID_BURMESE 19 +#define TT_MAC_ID_KHMER 20 +#define TT_MAC_ID_THAI 21 +#define TT_MAC_ID_LAOTIAN 22 +#define TT_MAC_ID_GEORGIAN 23 +#define TT_MAC_ID_ARMENIAN 24 +#define TT_MAC_ID_MALDIVIAN 25 +#define TT_MAC_ID_SIMPLIFIED_CHINESE 25 +#define TT_MAC_ID_TIBETAN 26 +#define TT_MAC_ID_MONGOLIAN 27 +#define TT_MAC_ID_GEEZ 28 +#define TT_MAC_ID_SLAVIC 29 +#define TT_MAC_ID_VIETNAMESE 30 +#define TT_MAC_ID_SINDHI 31 +#define TT_MAC_ID_UNINTERP 32 + + +/*************************************************************************/ +/* */ +/* Possible values of the platform specific encoding identifier field in */ +/* the name records of the TTF `name' table if the `platform' identifier */ +/* code is TT_PLATFORM_ISO. */ +/* */ +/* This use is now deprecated. */ +/* */ +#define TT_ISO_ID_7BIT_ASCII 0 +#define TT_ISO_ID_10646 1 +#define TT_ISO_ID_8859_1 2 + + +/*************************************************************************/ +/* */ +/* possible values of the platform specific encoding identifier field in */ +/* the name records of the TTF `name' table if the `platform' identifier */ +/* code is TT_PLATFORM_MICROSOFT. */ +/* */ +#define TT_MS_ID_SYMBOL_CS 0 +#define TT_MS_ID_UNICODE_CS 1 +#define TT_MS_ID_SJIS 2 +#define TT_MS_ID_GB2312 3 +#define TT_MS_ID_BIG_5 4 +#define TT_MS_ID_WANSUNG 5 +#define TT_MS_ID_JOHAB 6 + + +/*************************************************************************/ +/* */ +/* Possible values of the language identifier field in the name records */ +/* of the TTF `name' table if the `platform' identifier code is */ +/* TT_PLATFORM_MACINTOSH. */ +/* */ +/* The canonical source for the Apple assigned Language ID's is at */ +/* */ +/* http://fonts.apple.com/TTRefMan/RM06/Chap6name.html */ +/* */ +#define TT_MAC_LANGID_ENGLISH 0 +#define TT_MAC_LANGID_FRENCH 1 +#define TT_MAC_LANGID_GERMAN 2 +#define TT_MAC_LANGID_ITALIAN 3 +#define TT_MAC_LANGID_DUTCH 4 +#define TT_MAC_LANGID_SWEDISH 5 +#define TT_MAC_LANGID_SPANISH 6 +#define TT_MAC_LANGID_DANISH 7 +#define TT_MAC_LANGID_PORTUGUESE 8 +#define TT_MAC_LANGID_NORWEGIAN 9 +#define TT_MAC_LANGID_HEBREW 10 +#define TT_MAC_LANGID_JAPANESE 11 +#define TT_MAC_LANGID_ARABIC 12 +#define TT_MAC_LANGID_FINNISH 13 +#define TT_MAC_LANGID_GREEK 14 +#define TT_MAC_LANGID_ICELANDIC 15 +#define TT_MAC_LANGID_MALTESE 16 +#define TT_MAC_LANGID_TURKISH 17 +#define TT_MAC_LANGID_CROATIAN 18 +#define TT_MAC_LANGID_CHINESE_TRADITIONAL 19 +#define TT_MAC_LANGID_URDU 20 +#define TT_MAC_LANGID_HINDI 21 +#define TT_MAC_LANGID_THAI 22 +#define TT_MAC_LANGID_KOREAN 23 +#define TT_MAC_LANGID_LITHUANIAN 24 +#define TT_MAC_LANGID_POLISH 25 +#define TT_MAC_LANGID_HUNGARIAN 26 +#define TT_MAC_LANGID_ESTONIAN 27 +#define TT_MAC_LANGID_LETTISH 28 +#define TT_MAC_LANGID_SAAMISK 29 +#define TT_MAC_LANGID_FAEROESE 30 +#define TT_MAC_LANGID_FARSI 31 +#define TT_MAC_LANGID_RUSSIAN 32 +#define TT_MAC_LANGID_CHINESE_SIMPLIFIED 33 +#define TT_MAC_LANGID_FLEMISH 34 +#define TT_MAC_LANGID_IRISH 35 +#define TT_MAC_LANGID_ALBANIAN 36 +#define TT_MAC_LANGID_ROMANIAN 37 +#define TT_MAC_LANGID_CZECH 38 +#define TT_MAC_LANGID_SLOVAK 39 +#define TT_MAC_LANGID_SLOVENIAN 40 +#define TT_MAC_LANGID_YIDDISH 41 +#define TT_MAC_LANGID_SERBIAN 42 +#define TT_MAC_LANGID_MACEDONIAN 43 +#define TT_MAC_LANGID_BULGARIAN 44 +#define TT_MAC_LANGID_UKRAINIAN 45 +#define TT_MAC_LANGID_BYELORUSSIAN 46 +#define TT_MAC_LANGID_UZBEK 47 +#define TT_MAC_LANGID_KAZAKH 48 +#define TT_MAC_LANGID_AZERBAIJANI 49 +#define TT_MAC_LANGID_AZERBAIJANI_CYRILLIC_SCRIPT 49 +#define TT_MAC_LANGID_AZERBAIJANI_ARABIC_SCRIPT 50 +#define TT_MAC_LANGID_ARMENIAN 51 +#define TT_MAC_LANGID_GEORGIAN 52 +#define TT_MAC_LANGID_MOLDAVIAN 53 +#define TT_MAC_LANGID_KIRGHIZ 54 +#define TT_MAC_LANGID_TAJIKI 55 +#define TT_MAC_LANGID_TURKMEN 56 +#define TT_MAC_LANGID_MONGOLIAN 57 +#define TT_MAC_LANGID_MONGOLIAN_MONGOLIAN_SCRIPT 57 +#define TT_MAC_LANGID_MONGOLIAN_CYRILLIC_SCRIPT 58 +#define TT_MAC_LANGID_PASHTO 59 +#define TT_MAC_LANGID_KURDISH 60 +#define TT_MAC_LANGID_KASHMIRI 61 +#define TT_MAC_LANGID_SINDHI 62 +#define TT_MAC_LANGID_TIBETAN 63 +#define TT_MAC_LANGID_NEPALI 64 +#define TT_MAC_LANGID_SANSKRIT 65 +#define TT_MAC_LANGID_MARATHI 66 +#define TT_MAC_LANGID_BENGALI 67 +#define TT_MAC_LANGID_ASSAMESE 68 +#define TT_MAC_LANGID_GUJARATI 69 +#define TT_MAC_LANGID_PUNJABI 70 +#define TT_MAC_LANGID_ORIYA 71 +#define TT_MAC_LANGID_MALAYALAM 72 +#define TT_MAC_LANGID_KANNADA 73 +#define TT_MAC_LANGID_TAMIL 74 +#define TT_MAC_LANGID_TELUGU 75 +#define TT_MAC_LANGID_SINHALESE 76 +#define TT_MAC_LANGID_BURMESE 77 +#define TT_MAC_LANGID_KHMER 78 +#define TT_MAC_LANGID_LAO 79 +#define TT_MAC_LANGID_VIETNAMESE 80 +#define TT_MAC_LANGID_INDONESIAN 81 +#define TT_MAC_LANGID_TAGALOG 82 +#define TT_MAC_LANGID_MALAY_ROMAN_SCRIPT 83 +#define TT_MAC_LANGID_MALAY_ARABIC_SCRIPT 84 +#define TT_MAC_LANGID_AMHARIC 85 +#define TT_MAC_LANGID_TIGRINYA 86 +#define TT_MAC_LANGID_GALLA 87 +#define TT_MAC_LANGID_SOMALI 88 +#define TT_MAC_LANGID_SWAHILI 89 +#define TT_MAC_LANGID_RUANDA 90 +#define TT_MAC_LANGID_RUNDI 91 +#define TT_MAC_LANGID_CHEWA 92 +#define TT_MAC_LANGID_MALAGASY 93 +#define TT_MAC_LANGID_ESPERANTO 94 +#define TT_MAC_LANGID_WELSH 128 +#define TT_MAC_LANGID_BASQUE 129 +#define TT_MAC_LANGID_CATALAN 130 +#define TT_MAC_LANGID_LATIN 131 +#define TT_MAC_LANGID_QUECHUA 132 +#define TT_MAC_LANGID_GUARANI 133 +#define TT_MAC_LANGID_AYMARA 134 +#define TT_MAC_LANGID_TATAR 135 +#define TT_MAC_LANGID_UIGHUR 136 +#define TT_MAC_LANGID_DZONGKHA 137 +#define TT_MAC_LANGID_JAVANESE 138 +#define TT_MAC_LANGID_SUNDANESE 139 + + +#if 0 /* these seem to be errors that have been dropped */ + +#define TT_MAC_LANGID_SCOTTISH_GAELIC 140 +#define TT_MAC_LANGID_IRISH_GAELIC 141 + +#endif + + +/* The following codes are new as of 2000-03-10 */ +#define TT_MAC_LANGID_GALICIAN 140 +#define TT_MAC_LANGID_AFRIKAANS 141 +#define TT_MAC_LANGID_BRETON 142 +#define TT_MAC_LANGID_INUKTITUT 143 +#define TT_MAC_LANGID_SCOTTISH_GAELIC 144 +#define TT_MAC_LANGID_MANX_GAELIC 145 +#define TT_MAC_LANGID_IRISH_GAELIC 146 +#define TT_MAC_LANGID_TONGAN 147 +#define TT_MAC_LANGID_GREEK_POLYTONIC 148 +#define TT_MAC_LANGID_GREELANDIC 149 +#define TT_MAC_LANGID_AZERBAIJANI_ROMAN_SCRIPT 150 + + +/*************************************************************************/ +/* */ +/* Possible values of the language identifier field in the name records */ +/* of the TTF `name' table if the `platform' identifier code is */ +/* TT_PLATFORM_MICROSOFT. */ +/* */ +/* The canonical source for the MS assigned LCID's is at */ +/* */ +/* http://www.microsoft.com/typography/OTSPEC/lcid-cp.txt */ +/* */ +#define TT_MS_LANGID_ARABIC_SAUDI_ARABIA 0x0401 +#define TT_MS_LANGID_ARABIC_IRAQ 0x0801 +#define TT_MS_LANGID_ARABIC_EGYPT 0x0c01 +#define TT_MS_LANGID_ARABIC_LIBYA 0x1001 +#define TT_MS_LANGID_ARABIC_ALGERIA 0x1401 +#define TT_MS_LANGID_ARABIC_MOROCCO 0x1801 +#define TT_MS_LANGID_ARABIC_TUNISIA 0x1c01 +#define TT_MS_LANGID_ARABIC_OMAN 0x2001 +#define TT_MS_LANGID_ARABIC_YEMEN 0x2401 +#define TT_MS_LANGID_ARABIC_SYRIA 0x2801 +#define TT_MS_LANGID_ARABIC_JORDAN 0x2c01 +#define TT_MS_LANGID_ARABIC_LEBANON 0x3001 +#define TT_MS_LANGID_ARABIC_KUWAIT 0x3401 +#define TT_MS_LANGID_ARABIC_UAE 0x3801 +#define TT_MS_LANGID_ARABIC_BAHRAIN 0x3c01 +#define TT_MS_LANGID_ARABIC_QATAR 0x4001 +#define TT_MS_LANGID_BULGARIAN_BULGARIA 0x0402 +#define TT_MS_LANGID_CATALAN_SPAIN 0x0403 +#define TT_MS_LANGID_CHINESE_TAIWAN 0x0404 +#define TT_MS_LANGID_CHINESE_PRC 0x0804 +#define TT_MS_LANGID_CHINESE_HONG_KONG 0x0c04 +#define TT_MS_LANGID_CHINESE_SINGAPORE 0x1004 +#define TT_MS_LANGID_CHINESE_MACAU 0x1404 +#define TT_MS_LANGID_CZECH_CZECH_REPUBLIC 0x0405 +#define TT_MS_LANGID_DANISH_DENMARK 0x0406 +#define TT_MS_LANGID_GERMAN_GERMANY 0x0407 +#define TT_MS_LANGID_GERMAN_SWITZERLAND 0x0807 +#define TT_MS_LANGID_GERMAN_AUSTRIA 0x0c07 +#define TT_MS_LANGID_GERMAN_LUXEMBOURG 0x1007 +#define TT_MS_LANGID_GERMAN_LIECHTENSTEI 0x1407 +#define TT_MS_LANGID_GREEK_GREECE 0x0408 +#define TT_MS_LANGID_ENGLISH_UNITED_STATES 0x0409 +#define TT_MS_LANGID_ENGLISH_UNITED_KINGDOM 0x0809 +#define TT_MS_LANGID_ENGLISH_AUSTRALIA 0x0c09 +#define TT_MS_LANGID_ENGLISH_CANADA 0x1009 +#define TT_MS_LANGID_ENGLISH_NEW_ZEALAND 0x1409 +#define TT_MS_LANGID_ENGLISH_IRELAND 0x1809 +#define TT_MS_LANGID_ENGLISH_SOUTH_AFRICA 0x1c09 +#define TT_MS_LANGID_ENGLISH_JAMAICA 0x2009 +#define TT_MS_LANGID_ENGLISH_CARIBBEAN 0x2409 +#define TT_MS_LANGID_ENGLISH_BELIZE 0x2809 +#define TT_MS_LANGID_ENGLISH_TRINIDAD 0x2c09 +#define TT_MS_LANGID_ENGLISH_ZIMBABWE 0x3009 +#define TT_MS_LANGID_ENGLISH_PHILIPPINES 0x3409 +#define TT_MS_LANGID_SPANISH_SPAIN_TRADITIONAL_SORT 0x040a +#define TT_MS_LANGID_SPANISH_MEXICO 0x080a +#define TT_MS_LANGID_SPANISH_SPAIN_INTERNATIONAL_SORT 0x0c0a +#define TT_MS_LANGID_SPANISH_GUATEMALA 0x100a +#define TT_MS_LANGID_SPANISH_COSTA_RICA 0x140a +#define TT_MS_LANGID_SPANISH_PANAMA 0x180a +#define TT_MS_LANGID_SPANISH_DOMINICAN_REPUBLIC 0x1c0a +#define TT_MS_LANGID_SPANISH_VENEZUELA 0x200a +#define TT_MS_LANGID_SPANISH_COLOMBIA 0x240a +#define TT_MS_LANGID_SPANISH_PERU 0x280a +#define TT_MS_LANGID_SPANISH_ARGENTINA 0x2c0a +#define TT_MS_LANGID_SPANISH_ECUADOR 0x300a +#define TT_MS_LANGID_SPANISH_CHILE 0x340a +#define TT_MS_LANGID_SPANISH_URUGUAY 0x380a +#define TT_MS_LANGID_SPANISH_PARAGUAY 0x3c0a +#define TT_MS_LANGID_SPANISH_BOLIVIA 0x400a +#define TT_MS_LANGID_SPANISH_EL_SALVADOR 0x440a +#define TT_MS_LANGID_SPANISH_HONDURAS 0x480a +#define TT_MS_LANGID_SPANISH_NICARAGUA 0x4c0a +#define TT_MS_LANGID_SPANISH_PUERTO_RICO 0x500a +#define TT_MS_LANGID_FINNISH_FINLAND 0x040b +#define TT_MS_LANGID_FRENCH_FRANCE 0x040c +#define TT_MS_LANGID_FRENCH_BELGIUM 0x080c +#define TT_MS_LANGID_FRENCH_CANADA 0x0c0c +#define TT_MS_LANGID_FRENCH_SWITZERLAND 0x100c +#define TT_MS_LANGID_FRENCH_LUXEMBOURG 0x140c +#define TT_MS_LANGID_FRENCH_MONACO 0x180c +#define TT_MS_LANGID_HEBREW_ISRAEL 0x040d +#define TT_MS_LANGID_HUNGARIAN_HUNGARY 0x040e +#define TT_MS_LANGID_ICELANDIC_ICELAND 0x040f +#define TT_MS_LANGID_ITALIAN_ITALY 0x0410 +#define TT_MS_LANGID_ITALIAN_SWITZERLAND 0x0810 +#define TT_MS_LANGID_JAPANESE_JAPAN 0x0411 +#define TT_MS_LANGID_KOREAN_EXTENDED_WANSUNG_KOREA 0x0412 +#define TT_MS_LANGID_KOREAN_JOHAB_KOREA 0x0812 +#define TT_MS_LANGID_DUTCH_NETHERLANDS 0x0413 +#define TT_MS_LANGID_DUTCH_BELGIUM 0x0813 +#define TT_MS_LANGID_NORWEGIAN_NORWAY_BOKMAL 0x0414 +#define TT_MS_LANGID_NORWEGIAN_NORWAY_NYNORSK 0x0814 +#define TT_MS_LANGID_POLISH_POLAND 0x0415 +#define TT_MS_LANGID_PORTUGUESE_BRAZIL 0x0416 +#define TT_MS_LANGID_PORTUGUESE_PORTUGAL 0x0816 +#define TT_MS_LANGID_RHAETO_ROMANIC_SWITZERLAND 0x0417 +#define TT_MS_LANGID_ROMANIAN_ROMANIA 0x0418 +#define TT_MS_LANGID_MOLDAVIAN_MOLDAVIA 0x0818 +#define TT_MS_LANGID_RUSSIAN_RUSSIA 0x0419 +#define TT_MS_LANGID_RUSSIAN_MOLDAVIA 0x0819 +#define TT_MS_LANGID_CROATIAN_CROATIA 0x041a +#define TT_MS_LANGID_SERBIAN_SERBIA_LATIN 0x081a +#define TT_MS_LANGID_SERBIAN_SERBIA_CYRILLIC 0x0c1a +#define TT_MS_LANGID_SLOVAK_SLOVAKIA 0x041b +#define TT_MS_LANGID_ALBANIAN_ALBANIA 0x041c +#define TT_MS_LANGID_SWEDISH_SWEDEN 0x041d +#define TT_MS_LANGID_SWEDISH_FINLAND 0x081d +#define TT_MS_LANGID_THAI_THAILAND 0x041e +#define TT_MS_LANGID_TURKISH_TURKEY 0x041f +#define TT_MS_LANGID_URDU_PAKISTAN 0x0420 +#define TT_MS_LANGID_INDONESIAN_INDONESIA 0x0421 +#define TT_MS_LANGID_UKRAINIAN_UKRAINE 0x0422 +#define TT_MS_LANGID_BELARUSIAN_BELARUS 0x0423 +#define TT_MS_LANGID_SLOVENE_SLOVENIA 0x0424 +#define TT_MS_LANGID_ESTONIAN_ESTONIA 0x0425 +#define TT_MS_LANGID_LATVIAN_LATVIA 0x0426 +#define TT_MS_LANGID_LITHUANIAN_LITHUANIA 0x0427 +#define TT_MS_LANGID_CLASSIC_LITHUANIAN_LITHUANIA 0x0827 +#define TT_MS_LANGID_MAORI_NEW_ZEALAND 0x0428 +#define TT_MS_LANGID_FARSI_IRAN 0x0429 +#define TT_MS_LANGID_VIETNAMESE_VIET_NAM 0x042a +#define TT_MS_LANGID_ARMENIAN_ARMENIA 0x042b +#define TT_MS_LANGID_AZERI_AZERBAIJAN_LATIN 0x042c +#define TT_MS_LANGID_AZERI_AZERBAIJAN_CYRILLIC 0x082c +#define TT_MS_LANGID_BASQUE_SPAIN 0x042d +#define TT_MS_LANGID_SORBIAN_GERMANY 0x042e +#define TT_MS_LANGID_MACEDONIAN_MACEDONIA 0x042f +#define TT_MS_LANGID_SUTU_SOUTH_AFRICA 0x0430 +#define TT_MS_LANGID_TSONGA_SOUTH_AFRICA 0x0431 +#define TT_MS_LANGID_TSWANA_SOUTH_AFRICA 0x0432 +#define TT_MS_LANGID_VENDA_SOUTH_AFRICA 0x0433 +#define TT_MS_LANGID_XHOSA_SOUTH_AFRICA 0x0434 +#define TT_MS_LANGID_ZULU_SOUTH_AFRICA 0x0435 +#define TT_MS_LANGID_AFRIKAANS_SOUTH_AFRICA 0x0436 +#define TT_MS_LANGID_GEORGIAN_GEORGIA 0x0437 +#define TT_MS_LANGID_FAEROESE_FAEROE_ISLANDS 0x0438 +#define TT_MS_LANGID_HINDI_INDIA 0x0439 +#define TT_MS_LANGID_MALTESE_MALTA 0x043a +#define TT_MS_LANGID_SAAMI_LAPONIA 0x043b +#define TT_MS_LANGID_IRISH_GAELIC_IRELAND 0x043c +#define TT_MS_LANGID_SCOTTISH_GAELIC_UNITED_KINGDOM 0x083c +#define TT_MS_LANGID_MALAY_MALAYSIA 0x043e +#define TT_MS_LANGID_MALAY_BRUNEI_DARUSSALAM 0x083e +#define TT_MS_LANGID_KAZAK_KAZAKSTAN 0x043f +#define TT_MS_LANGID_SWAHILI_KENYA 0x0441 +#define TT_MS_LANGID_UZBEK_UZBEKISTAN_LATIN 0x0443 +#define TT_MS_LANGID_UZBEK_UZBEKISTAN_CYRILLIC 0x0843 +#define TT_MS_LANGID_TATAR_TATARSTAN 0x0444 +#define TT_MS_LANGID_BENGALI_INDIA 0x0445 +#define TT_MS_LANGID_PUNJABI_INDIA 0x0446 +#define TT_MS_LANGID_GUJARATI_INDIA 0x0447 +#define TT_MS_LANGID_ORIYA_INDIA 0x0448 +#define TT_MS_LANGID_TAMIL_INDIA 0x0449 +#define TT_MS_LANGID_TELUGU_INDIA 0x044a +#define TT_MS_LANGID_KANNADA_INDIA 0x044b +#define TT_MS_LANGID_MALAYALAM_INDIA 0x044c +#define TT_MS_LANGID_ASSAMESE_INDIA 0x044d +#define TT_MS_LANGID_MARATHI_INDIA 0x044e +#define TT_MS_LANGID_SANSKRIT_INDIA 0x044f +#define TT_MS_LANGID_KONKANI_INDIA 0x0457 + + +/*************************************************************************/ +/* */ +/* Possible values of the `name' identifier field in the name records of */ +/* the TTF `name' table. These values are platform independent. */ +/* */ +#define TT_NAME_ID_COPYRIGHT 0 +#define TT_NAME_ID_FONT_FAMILY 1 +#define TT_NAME_ID_FONT_SUBFAMILY 2 +#define TT_NAME_ID_UNIQUE_ID 3 +#define TT_NAME_ID_FULL_NAME 4 +#define TT_NAME_ID_VERSION_STRING 5 +#define TT_NAME_ID_PS_NAME 6 +#define TT_NAME_ID_TRADEMARK 7 + +/* the following values are from the OpenType spec */ +#define TT_NAME_ID_MANUFACTURER 8 +#define TT_NAME_ID_DESIGNER 9 +#define TT_NAME_ID_DESCRIPTION 10 +#define TT_NAME_ID_VENDOR_URL 11 +#define TT_NAME_ID_DESIGNER_URL 12 +#define TT_NAME_ID_LICENSE 13 +#define TT_NAME_ID_LICENSE_URL 14 +/* number 15 is reserved */ +#define TT_NAME_ID_PREFERRED_FAMILY 16 +#define TT_NAME_ID_PREFERRED_SUBFAMILY 17 +#define TT_NAME_ID_MAC_FULL_NAME 18 + +/* The following code is new as of 2000-01-21 */ +#define TT_NAME_ID_SAMPLE_TEXT 19 + + +/*************************************************************************/ +/* */ +/* Bit mask values for the Unicode Ranges from the TTF `OS2 ' table. */ +/* */ +/* Updated 02-Jul-2000. */ +/* */ + +/* General Scripts Area */ + +/* Bit 0 C0 Controls and Basic Latin */ +#define TT_UCR_BASIC_LATIN ( 1L << 0 ) /* U+0020-U+007E */ +/* Bit 1 C1 Controls and Latin-1 Supplement */ +#define TT_UCR_LATIN1_SUPPLEMENT ( 1L << 1 ) /* U+00A0-U+00FF */ +/* Bit 2 Latin Extended-A */ +#define TT_UCR_LATIN_EXTENDED_A ( 1L << 2 ) /* U+0100-U+017F */ +/* Bit 3 Latin Extended-B */ +#define TT_UCR_LATIN_EXTENDED_B ( 1L << 3 ) /* U+0180-U+024F */ +/* Bit 4 IPA Extensions */ +#define TT_UCR_IPA_EXTENSIONS ( 1L << 4 ) /* U+0250-U+02AF */ +/* Bit 5 Spacing Modifier Letters */ +#define TT_UCR_SPACING_MODIFIER ( 1L << 5 ) /* U+02B0-U+02FF */ +/* Bit 6 Combining Diacritical Marks */ +#define TT_UCR_COMBINING_DIACRITICS ( 1L << 6 ) /* U+0300-U+036F */ +/* Bit 7 Greek */ +#define TT_UCR_GREEK ( 1L << 7 ) /* U+0370-U+03FF */ +/* Bit 8 is reserved (was: Greek Symbols and Coptic) */ +/* Bit 9 Cyrillic */ +#define TT_UCR_CYRILLIC ( 1L << 9 ) /* U+0400-U+04FF */ +/* Bit 10 Armenian */ +#define TT_UCR_ARMENIAN ( 1L << 10 ) /* U+0530-U+058F */ +/* Bit 11 Hebrew */ +#define TT_UCR_HEBREW ( 1L << 11 ) /* U+0590-U+05FF */ +/* Bit 12 is reserved (was: Hebrew Extended) */ +/* Bit 13 Arabic */ +#define TT_UCR_ARABIC ( 1L << 13 ) /* U+0600-U+06FF */ +/* Bit 14 is reserved (was: Arabic Extended) */ +/* Bit 15 Devanagari */ +#define TT_UCR_DEVANAGARI ( 1L << 15 ) /* U+0900-U+097F */ +/* Bit 16 Bengali */ +#define TT_UCR_BENGALI ( 1L << 16 ) /* U+0980-U+09FF */ +/* Bit 17 Gurmukhi */ +#define TT_UCR_GURMUKHI ( 1L << 17 ) /* U+0A00-U+0A7F */ +/* Bit 18 Gujarati */ +#define TT_UCR_GUJARATI ( 1L << 18 ) /* U+0A80-U+0AFF */ +/* Bit 19 Oriya */ +#define TT_UCR_ORIYA ( 1L << 19 ) /* U+0B00-U+0B7F */ +/* Bit 20 Tamil */ +#define TT_UCR_TAMIL ( 1L << 20 ) /* U+0B80-U+0BFF */ +/* Bit 21 Telugu */ +#define TT_UCR_TELUGU ( 1L << 21 ) /* U+0C00-U+0C7F */ +/* Bit 22 Kannada */ +#define TT_UCR_KANNADA ( 1L << 22 ) /* U+0C80-U+0CFF */ +/* Bit 23 Malayalam */ +#define TT_UCR_MALAYALAM ( 1L << 23 ) /* U+0D00-U+0D7F */ +/* Bit 24 Thai */ +#define TT_UCR_THAI ( 1L << 24 ) /* U+0E00-U+0E7F */ +/* Bit 25 Lao */ +#define TT_UCR_LAO ( 1L << 25 ) /* U+0E80-U+0EFF */ +/* Bit 26 Georgian */ +#define TT_UCR_GEORGIAN ( 1L << 26 ) /* U+10A0-U+10FF */ +/* Bit 27 is reserved (was Georgian Extended) */ +/* Bit 28 Hangul Jamo */ +#define TT_UCR_HANGUL_JAMO ( 1L << 28 ) /* U+1100-U+11FF */ +/* Bit 29 Latin Extended Additional */ +#define TT_UCR_LATIN_EXTENDED_ADDITIONAL ( 1L << 29 ) /* U+1E00-U+1EFF */ +/* Bit 30 Greek Extended */ +#define TT_UCR_GREEK_EXTENDED ( 1L << 30 ) /* U+1F00-U+1FFF */ + +/* Symbols Area */ + +/* Bit 31 General Punctuation */ +#define TT_UCR_GENERAL_PUNCTUATION ( 1L << 31 ) /* U+2000-U+206F */ +/* Bit 32 Superscripts And Subscripts */ +#define TT_UCR_SUPERSCRIPTS_SUBSCRIPTS ( 1L << 0 ) /* U+2070-U+209F */ +/* Bit 33 Currency Symbols */ +#define TT_UCR_CURRENCY_SYMBOLS ( 1L << 1 ) /* U+20A0-U+20CF */ +/* Bit 34 Combining Diacritical Marks For Symbols */ +#define TT_UCR_COMBINING_DIACRITICS_SYMB ( 1L << 2 ) /* U+20D0-U+20FF */ +/* Bit 35 Letterlike Symbols */ +#define TT_UCR_LETTERLIKE_SYMBOLS ( 1L << 3 ) /* U+2100-U+214F */ +/* Bit 36 Number Forms */ +#define TT_UCR_NUMBER_FORMS ( 1L << 4 ) /* U+2150-U+218F */ +/* Bit 37 Arrows */ +#define TT_UCR_ARROWS ( 1L << 5 ) /* U+2190-U+21FF */ +/* Bit 38 Mathematical Operators */ +#define TT_UCR_MATHEMATICAL_OPERATORS ( 1L << 6 ) /* U+2200-U+22FF */ +/* Bit 39 Miscellaneous Technical */ +#define TT_UCR_MISCELLANEOUS_TECHNICAL ( 1L << 7 ) /* U+2300-U+23FF */ +/* Bit 40 Control Pictures */ +#define TT_UCR_CONTROL_PICTURES ( 1L << 8 ) /* U+2400-U+243F */ +/* Bit 41 Optical Character Recognition */ +#define TT_UCR_OCR ( 1L << 9 ) /* U+2440-U+245F */ +/* Bit 42 Enclosed Alphanumerics */ +#define TT_UCR_ENCLOSED_ALPHANUMERICS ( 1L << 10 ) /* U+2460-U+24FF */ +/* Bit 43 Box Drawing */ +#define TT_UCR_BOX_DRAWING ( 1L << 11 ) /* U+2500-U+257F */ +/* Bit 44 Block Elements */ +#define TT_UCR_BLOCK_ELEMENTS ( 1L << 12 ) /* U+2580-U+259F */ +/* Bit 45 Geometric Shapes */ +#define TT_UCR_GEOMETRIC_SHAPES ( 1L << 13 ) /* U+25A0-U+25FF */ +/* Bit 46 Miscellaneous Symbols */ +#define TT_UCR_MISCELLANEOUS_SYMBOLS ( 1L << 14 ) /* U+2600-U+26FF */ +/* Bit 47 Dingbats */ +#define TT_UCR_DINGBATS ( 1L << 15 ) /* U+2700-U+27BF */ + +/* CJK Phonetics and Symbols Area */ + +/* Bit 48 CJK Symbols And Punctuation */ +#define TT_UCR_CJK_SYMBOLS ( 1L << 16 ) /* U+3000-U+303F */ +/* Bit 49 Hiragana */ +#define TT_UCR_HIRAGANA ( 1L << 17 ) /* U+3040-U+309F */ +/* Bit 50 Katakana */ +#define TT_UCR_KATAKANA ( 1L << 18 ) /* U+30A0-U+30FF */ +/* Bit 51 Bopomofo + Extended Bopomofo */ +#define TT_UCR_BOPOMOFO ( 1L << 19 ) /* U+3100-U+312F */ + /* U+31A0-U+31BF */ +/* Bit 52 Hangul Compatibility Jamo */ +#define TT_UCR_HANGUL_COMPATIBILITY_JAMO ( 1L << 20 ) /* U+3130-U+318F */ +/* Bit 53 CJK Miscellaneous */ +#define TT_UCR_CJK_MISC ( 1L << 21 ) /* U+3190-U+319F */ +/* Bit 54 Enclosed CJK Letters And Months */ +#define TT_UCR_ENCLOSED_CJK_LETTERS_MONTHS ( 1L << 22 ) /* U+3200-U+32FF */ +/* Bit 55 CJK Compatibility */ +#define TT_UCR_CJK_COMPATIBILITY ( 1L << 23 ) /* U+3300-U+33FF */ + +/* Hangul Syllables Area */ + +/* Bit 56 Hangul */ +#define TT_UCR_HANGUL ( 1L << 24 ) /* U+AC00-U+D7A3 */ + +/* Surrogates Area */ + +/* Bit 57 Surrogates */ +#define TT_UCR_SURROGATES ( 1L << 25 ) /* U+D800-U+DFFF */ +/* Bit 58 is reserved for Unicode SubRanges */ + +/* CJK Ideographs Area */ + +/* Bit 59 CJK Unified Ideographs + */ +/* CJK Radical Supplement + */ +/* Kangxi Radicals + */ +/* Ideographic Description + */ +/* CJK Unified Ideographs Extension A */ +#define TT_UCR_CJK_UNIFIED_IDEOGRAPHS ( 1L << 27 ) /* U+4E00-U+9FFF */ + /* U+2E80-U+2EFF */ + /* U+2F00-U+2FDF */ + /* U+2FF0-U+2FFF */ + /* U+34E0-U+4DB5 */ + +/* Private Use Area */ + +/* Bit 60 Private Use */ +#define TT_UCR_PRIVATE_USE ( 1L << 28 ) /* U+E000-U+F8FF */ + +/* Compatibility Area and Specials */ + +/* Bit 61 CJK Compatibility Ideographs */ +#define TT_UCR_CJK_COMPATIBILITY_IDEOGRAPHS ( 1L << 29 ) /* U+F900-U+FAFF */ +/* Bit 62 Alphabetic Presentation Forms */ +#define TT_UCR_ALPHABETIC_PRESENTATION_FORMS ( 1L << 30 ) /* U+FB00-U+FB4F */ +/* Bit 63 Arabic Presentation Forms-A */ +#define TT_UCR_ARABIC_PRESENTATIONS_A ( 1L << 31 ) /* U+FB50-U+FDFF */ +/* Bit 64 Combining Half Marks */ +#define TT_UCR_COMBINING_HALF_MARKS ( 1L << 0 ) /* U+FE20-U+FE2F */ +/* Bit 65 CJK Compatibility Forms */ +#define TT_UCR_CJK_COMPATIBILITY_FORMS ( 1L << 1 ) /* U+FE30-U+FE4F */ +/* Bit 66 Small Form Variants */ +#define TT_UCR_SMALL_FORM_VARIANTS ( 1L << 2 ) /* U+FE50-U+FE6F */ +/* Bit 67 Arabic Presentation Forms-B */ +#define TT_UCR_ARABIC_PRESENTATIONS_B ( 1L << 3 ) /* U+FE70-U+FEFE */ +/* Bit 68 Halfwidth And Fullwidth Forms */ +#define TT_UCR_HALFWIDTH_FULLWIDTH_FORMS ( 1L << 4 ) /* U+FF00-U+FFEF */ +/* Bit 69 Specials */ +#define TT_UCR_SPECIALS ( 1L << 5 ) /* U+FFF0-U+FFFD */ +/* Bit 70 Tibetan */ +#define TT_UCR_TIBETAN ( 1L << 6 ) /* U+0F00-U+0FCF */ +/* Bit 71 Syriac */ +#define TT_UCR_SYRIAC ( 1L << 7 ) /* U+0700-U+074F */ +/* Bit 72 Thaana */ +#define TT_UCR_THAANA ( 1L << 8 ) /* U+0780-U+07BF */ +/* Bit 73 Sinhala */ +#define TT_UCR_SINHALA ( 1L << 9 ) /* U+0D80-U+0DFF */ +/* Bit 74 Myanmar */ +#define TT_UCR_MYANMAR ( 1L << 10 ) /* U+1000-U+109F */ +/* Bit 75 Ethiopic */ +#define TT_UCR_ETHIOPIC ( 1L << 11 ) /* U+1200-U+12BF */ +/* Bit 76 Cherokee */ +#define TT_UCR_CHEROKEE ( 1L << 12 ) /* U+13A0-U+13FF */ +/* Bit 77 Canadian Aboriginal Syllabics */ +#define TT_UCR_CANADIAN_ABORIGINAL_SYLLABICS ( 1L << 13 ) /* U+1400-U+14DF */ +/* Bit 78 Ogham */ +#define TT_UCR_OGHAM ( 1L << 14 ) /* U+1680-U+169F */ +/* Bit 79 Runic */ +#define TT_UCR_RUNIC ( 1L << 15 ) /* U+16A0-U+16FF */ +/* Bit 80 Khmer */ +#define TT_UCR_KHMER ( 1L << 16 ) /* U+1780-U+17FF */ +/* Bit 81 Mongolian */ +#define TT_UCR_MONGOLIAN ( 1L << 17 ) /* U+1800-U+18AF */ +/* Bit 82 Braille */ +#define TT_UCR_BRAILLE ( 1L << 18 ) /* U+2800-U+28FF */ +/* Bit 83 Yi + Yi Radicals */ +#define TT_UCR_YI ( 1L << 19 ) /* U+A000-U+A48C */ + /* U+A490-U+A4CF */ + + +/*************************************************************************/ +/* */ +/* Some compilers have a very limited length of identifiers. */ +/* */ +#if defined( __TURBOC__ ) && __TURBOC__ < 0x0410 || defined( __PACIFIC__ ) +#define HAVE_LIMIT_ON_IDENTS +#endif + + +#ifndef HAVE_LIMIT_ON_IDENTS + + +/*************************************************************************/ +/* */ +/* Here some alias #defines in order to be clearer. */ +/* */ +/* These are not always #defined to stay within the 31 character limit */ +/* which some compilers have. */ +/* */ +/* Credits go to Dave Hoo for pointing out that modern */ +/* Borland compilers (read: from BC++ 3.1 on) can increase this limit. */ +/* If you get a warning with such a compiler, use the -i40 switch. */ +/* */ +#define TT_UCR_ARABIC_PRESENTATION_FORMS_A \ + TT_UCR_ARABIC_PRESENTATIONS_A +#define TT_UCR_ARABIC_PRESENTATION_FORMS_B \ + TT_UCR_ARABIC_PRESENTATIONS_B + +#define TT_UCR_COMBINING_DIACRITICAL_MARKS \ + TT_UCR_COMBINING_DIACRITICS +#define TT_UCR_COMBINING_DIACRITICAL_MARKS_SYMB \ + TT_UCR_COMBINING_DIACRITICS_SYMB + + +#endif /* !HAVE_LIMIT_ON_IDENTS */ + + +#endif /* TTNAMEID_H */ + + +/* END */ diff --git a/Projects/Android/jni/rtcw/src/ft2/ttobjs.c b/Projects/Android/jni/rtcw/src/ft2/ttobjs.c new file mode 100644 index 0000000..832e476 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/ft2/ttobjs.c @@ -0,0 +1,727 @@ +/***************************************************************************/ +/* */ +/* ttobjs.c */ +/* */ +/* Objects manager (body). */ +/* */ +/* Copyright 1996-2000 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#include "ftdebug.h" +#include "ftcalc.h" +#include "ftstream.h" +#include "ttnameid.h" +#include "tttags.h" + +#include "sfnt.h" +#include "psnames.h" + + +#include "ttgload.h" +#include "ttpload.h" + +#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER +#include "ttinterp.h" +#endif + +#include "tterrors.h" + + + +/*************************************************************************/ +/* */ +/* The macro FT_COMPONENT is used in trace mode. It is an implicit */ +/* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */ +/* messages during execution. */ +/* */ +#undef FT_COMPONENT +#define FT_COMPONENT trace_ttobjs + + +/*************************************************************************/ +/* */ +/* GLYPH ZONE FUNCTIONS */ +/* */ +/*************************************************************************/ + +/*************************************************************************/ +/* */ +/* */ +/* TT_Done_GlyphZone */ +/* */ +/* */ +/* Deallocates a glyph zone. */ +/* */ +/* */ +/* zone :: A pointer to the target glyph zone. */ +/* */ +LOCAL_FUNC +void TT_Done_GlyphZone( TT_GlyphZone* zone ) { + FT_Memory memory = zone->memory; + + + FREE( zone->contours ); + FREE( zone->tags ); + FREE( zone->cur ); + FREE( zone->org ); + + zone->max_points = zone->n_points = 0; + zone->max_contours = zone->n_contours = 0; +} + + +/*************************************************************************/ +/* */ +/* */ +/* TT_New_GlyphZone */ +/* */ +/* */ +/* Allocates a new glyph zone. */ +/* */ +/* */ +/* memory :: A handle to the current memory object. */ +/* */ +/* maxPoints :: The capacity of glyph zone in points. */ +/* */ +/* maxContours :: The capacity of glyph zone in contours. */ +/* */ +/* */ +/* zone :: A pointer to the target glyph zone record. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +LOCAL_FUNC +FT_Error TT_New_GlyphZone( FT_Memory memory, + FT_UShort maxPoints, + FT_Short maxContours, + TT_GlyphZone* zone ) { + FT_Error error; + + + if ( maxPoints > 0 ) { + maxPoints += 2; + } + + MEM_Set( zone, 0, sizeof( *zone ) ); + zone->memory = memory; + + if ( ALLOC_ARRAY( zone->org, maxPoints * 2, FT_F26Dot6 ) || + ALLOC_ARRAY( zone->cur, maxPoints * 2, FT_F26Dot6 ) || + ALLOC_ARRAY( zone->tags, maxPoints, FT_Byte ) || + ALLOC_ARRAY( zone->contours, maxContours, FT_UShort ) ) { + TT_Done_GlyphZone( zone ); + } + + return error; +} + + +/*************************************************************************/ +/* */ +/* */ +/* TT_Init_Face */ +/* */ +/* */ +/* Initializes a given TrueType face object. */ +/* */ +/* */ +/* stream :: The source font stream. */ +/* */ +/* face_index :: The index of the font face in the resource. */ +/* */ +/* num_params :: Number of additional generic parameters. Ignored. */ +/* */ +/* params :: Additional generic parameters. Ignored. */ +/* */ +/* */ +/* face :: The newly built face object. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +LOCAL_DEF +FT_Error TT_Init_Face( FT_Stream stream, + TT_Face face, + FT_Int face_index, + FT_Int num_params, + FT_Parameter* params ) { + FT_Error error; + FT_Library library; + SFNT_Interface* sfnt; + + + library = face->root.driver->root.library; + sfnt = (SFNT_Interface*)FT_Get_Module_Interface( library, "sfnt" ); + if ( !sfnt ) { + goto Bad_Format; + } + + /* create input stream from resource */ + if ( FILE_Seek( 0 ) ) { + goto Exit; + } + + /* check that we have a valid TrueType file */ + error = sfnt->init_face( stream, face, face_index, num_params, params ); + if ( error ) { + goto Exit; + } + + /* We must also be able to accept Mac/GX fonts, as well as OT ones */ + if ( face->format_tag != 0x00010000L && /* MS fonts */ + face->format_tag != TTAG_true ) { /* Mac fonts */ + FT_TRACE2( ( "[not a valid TTF font]\n" ) ); + goto Bad_Format; + } + + /* If we are performing a simple font format check, exit immediately */ + if ( face_index < 0 ) { + return TT_Err_Ok; + } + + /* Load font directory */ + error = sfnt->load_face( stream, face, face_index, num_params, params ); + if ( error ) { + goto Exit; + } + + error = TT_Load_Locations( face, stream ) || + TT_Load_CVT( face, stream ) || + TT_Load_Programs( face, stream ); + + /* initialize standard glyph loading routines */ + TT_Init_Glyph_Loading( face ); + +Exit: + return error; + +Bad_Format: + error = FT_Err_Unknown_File_Format; + goto Exit; +} + + +/*************************************************************************/ +/* */ +/* */ +/* TT_Done_Face */ +/* */ +/* */ +/* Finalizes a given face object. */ +/* */ +/* */ +/* face :: A pointer to the face object to destroy. */ +/* */ +LOCAL_DEF +void TT_Done_Face( TT_Face face ) { + FT_Memory memory = face->root.memory; + FT_Stream stream = face->root.stream; + + SFNT_Interface* sfnt = (SFNT_Interface*)face->sfnt; + + + /* for `extended TrueType formats' (i.e. compressed versions) */ + if ( face->extra.finalizer ) { + face->extra.finalizer( face->extra.data ); + } + + if ( sfnt ) { + sfnt->done_face( face ); + } + + /* freeing the locations table */ + FREE( face->glyph_locations ); + face->num_locations = 0; + + /* freeing the CVT */ + FREE( face->cvt ); + face->cvt_size = 0; + + /* freeing the programs */ + RELEASE_Frame( face->font_program ); + RELEASE_Frame( face->cvt_program ); + face->font_program_size = 0; + face->cvt_program_size = 0; +} + + +/*************************************************************************/ +/* */ +/* SIZE FUNCTIONS */ +/* */ +/*************************************************************************/ + + +/*************************************************************************/ +/* */ +/* */ +/* TT_Init_Size */ +/* */ +/* */ +/* Initializes a new TrueType size object. */ +/* */ +/* */ +/* size :: A handle to the size object. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +LOCAL_DEF +FT_Error TT_Init_Size( TT_Size size ) { + FT_Error error = TT_Err_Ok; + + +#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER + + TT_Face face = (TT_Face)size->root.face; + FT_Memory memory = face->root.memory; + FT_Int i; + + TT_ExecContext exec; + FT_UShort n_twilight; + TT_MaxProfile* maxp = &face->max_profile; + + + size->ttmetrics.valid = FALSE; + + size->max_function_defs = maxp->maxFunctionDefs; + size->max_instruction_defs = maxp->maxInstructionDefs; + + size->num_function_defs = 0; + size->num_instruction_defs = 0; + + size->max_func = 0; + size->max_ins = 0; + + size->cvt_size = face->cvt_size; + size->storage_size = maxp->maxStorage; + + /* Set default metrics */ + { + FT_Size_Metrics* metrics = &size->root.metrics; + TT_Size_Metrics* metrics2 = &size->ttmetrics; + + + metrics->x_ppem = 0; + metrics->y_ppem = 0; + + metrics2->rotated = FALSE; + metrics2->stretched = FALSE; + + /* set default compensation (all 0) */ + for ( i = 0; i < 4; i++ ) + metrics2->compensations[i] = 0; + } + + /* allocate function defs, instruction defs, cvt, and storage area */ + if ( ALLOC_ARRAY( size->function_defs, + size->max_function_defs, + TT_DefRecord ) || + + ALLOC_ARRAY( size->instruction_defs, + size->max_instruction_defs, + TT_DefRecord ) || + + ALLOC_ARRAY( size->cvt, + size->cvt_size, FT_Long ) || + + ALLOC_ARRAY( size->storage, + size->storage_size, FT_Long ) ) { + + goto Fail_Memory; + } + + /* reserve twilight zone */ + n_twilight = maxp->maxTwilightPoints; + error = TT_New_GlyphZone( memory, n_twilight, 0, &size->twilight ); + if ( error ) { + goto Fail_Memory; + } + + size->twilight.n_points = n_twilight; + + /* set `face->interpreter' according to the debug hook present */ + { + FT_Library library = face->root.driver->root.library; + + + face->interpreter = (TT_Interpreter) + library->debug_hooks[FT_DEBUG_HOOK_TRUETYPE]; + if ( !face->interpreter ) { + face->interpreter = (TT_Interpreter)TT_RunIns; + } + } + + /* Fine, now execute the font program! */ + exec = size->context; + /* size objects used during debugging have their own context */ + if ( !size->debug ) { + exec = TT_New_Context( face ); + } + + if ( !exec ) { + error = TT_Err_Could_Not_Find_Context; + goto Fail_Memory; + } + + size->GS = tt_default_graphics_state; + TT_Load_Context( exec, face, size ); + + exec->callTop = 0; + exec->top = 0; + + exec->period = 64; + exec->phase = 0; + exec->threshold = 0; + + { + FT_Size_Metrics* metrics = &exec->metrics; + TT_Size_Metrics* tt_metrics = &exec->tt_metrics; + + + metrics->x_ppem = 0; + metrics->y_ppem = 0; + metrics->x_scale = 0; + metrics->y_scale = 0; + + tt_metrics->ppem = 0; + tt_metrics->scale = 0; + tt_metrics->ratio = 0x10000L; + } + + exec->instruction_trap = FALSE; + + exec->cvtSize = size->cvt_size; + exec->cvt = size->cvt; + + exec->F_dot_P = 0x10000L; + + /* allow font program execution */ + TT_Set_CodeRange( exec, + tt_coderange_font, + face->font_program, + face->font_program_size ); + + /* disable CVT and glyph programs coderange */ + TT_Clear_CodeRange( exec, tt_coderange_cvt ); + TT_Clear_CodeRange( exec, tt_coderange_glyph ); + + if ( face->font_program_size > 0 ) { + error = TT_Goto_CodeRange( exec, tt_coderange_font, 0 ); + if ( !error ) { + error = face->interpreter( exec ); + } + + if ( error ) { + goto Fail_Exec; + } + } else { + error = TT_Err_Ok; + } + + TT_Save_Context( exec, size ); + + if ( !size->debug ) { + TT_Done_Context( exec ); + } + +#endif /* TT_CONFIG_OPTION_BYTECODE_INTERPRETER */ + + size->ttmetrics.valid = FALSE; + return error; + +#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER + +Fail_Exec: + if ( !size->debug ) { + TT_Done_Context( exec ); + } + +Fail_Memory: + +#endif + + TT_Done_Size( size ); + return error; +} + + +/*************************************************************************/ +/* */ +/* */ +/* TT_Done_Size */ +/* */ +/* */ +/* The TrueType size object finalizer. */ +/* */ +/* */ +/* size :: A handle to the target size object. */ +/* */ +LOCAL_FUNC +void TT_Done_Size( TT_Size size ) { + +#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER + + FT_Memory memory = size->root.face->memory; + + + if ( size->debug ) { + /* the debug context must be deleted by the debugger itself */ + size->context = NULL; + size->debug = FALSE; + } + + FREE( size->cvt ); + size->cvt_size = 0; + + /* free storage area */ + FREE( size->storage ); + size->storage_size = 0; + + /* twilight zone */ + TT_Done_GlyphZone( &size->twilight ); + + FREE( size->function_defs ); + FREE( size->instruction_defs ); + + size->num_function_defs = 0; + size->max_function_defs = 0; + size->num_instruction_defs = 0; + size->max_instruction_defs = 0; + + size->max_func = 0; + size->max_ins = 0; + +#endif + + size->ttmetrics.valid = FALSE; +} + + +/*************************************************************************/ +/* */ +/* */ +/* TT_Reset_Size */ +/* */ +/* */ +/* Resets a TrueType size when resolutions and character dimensions */ +/* have been changed. */ +/* */ +/* */ +/* size :: A handle to the target size object. */ +/* */ +LOCAL_DEF +FT_Error TT_Reset_Size( TT_Size size ) { + TT_Face face; + FT_Error error = TT_Err_Ok; + + FT_Size_Metrics* metrics; + + + if ( size->ttmetrics.valid ) { + return TT_Err_Ok; + } + + face = (TT_Face)size->root.face; + + metrics = &size->root.metrics; + + if ( metrics->x_ppem < 1 || metrics->y_ppem < 1 ) { + return TT_Err_Invalid_PPem; + } + + /* compute new transformation */ + if ( metrics->x_ppem >= metrics->y_ppem ) { + size->ttmetrics.scale = metrics->x_scale; + size->ttmetrics.ppem = metrics->x_ppem; + size->ttmetrics.x_ratio = 0x10000L; + size->ttmetrics.y_ratio = FT_MulDiv( metrics->y_ppem, + 0x10000L, + metrics->x_ppem ); + } else + { + size->ttmetrics.scale = metrics->y_scale; + size->ttmetrics.ppem = metrics->y_ppem; + size->ttmetrics.x_ratio = FT_MulDiv( metrics->x_ppem, + 0x10000L, + metrics->y_ppem ); + size->ttmetrics.y_ratio = 0x10000L; + } + + /* Compute root ascender, descender, test height, and max_advance */ + metrics->ascender = ( FT_MulFix( face->root.ascender, + metrics->y_scale ) + 32 ) & - 64; + metrics->descender = ( FT_MulFix( face->root.descender, + metrics->y_scale ) + 32 ) & - 64; + metrics->height = ( FT_MulFix( face->root.height, + metrics->y_scale ) + 32 ) & - 64; + metrics->max_advance = ( FT_MulFix( face->root.max_advance_width, + metrics->x_scale ) + 32 ) & - 64; + +#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER + + { + TT_ExecContext exec; + FT_UInt i, j; + + + /* Scale the cvt values to the new ppem. */ + /* We use by default the y ppem to scale the CVT. */ + for ( i = 0; i < size->cvt_size; i++ ) + size->cvt[i] = FT_MulFix( face->cvt[i], size->ttmetrics.scale ); + + /* All twilight points are originally zero */ + for ( j = 0; j < size->twilight.n_points; j++ ) + { + size->twilight.org[j].x = 0; + size->twilight.org[j].y = 0; + size->twilight.cur[j].x = 0; + size->twilight.cur[j].y = 0; + } + + /* clear storage area */ + for ( i = 0; i < size->storage_size; i++ ) + size->storage[i] = 0; + + size->GS = tt_default_graphics_state; + + /* get execution context and run prep program */ + if ( size->debug ) { + exec = size->context; + } else { + exec = TT_New_Context( face ); + } + /* debugging instances have their own context */ + + if ( !exec ) { + return TT_Err_Could_Not_Find_Context; + } + + TT_Load_Context( exec, face, size ); + + TT_Set_CodeRange( exec, + tt_coderange_cvt, + face->cvt_program, + face->cvt_program_size ); + + TT_Clear_CodeRange( exec, tt_coderange_glyph ); + + exec->instruction_trap = FALSE; + + exec->top = 0; + exec->callTop = 0; + + if ( face->cvt_program_size > 0 ) { + error = TT_Goto_CodeRange( exec, tt_coderange_cvt, 0 ); + if ( error ) { + goto End; + } + + if ( !size->debug ) { + error = face->interpreter( exec ); + } + } else { + error = TT_Err_Ok; + } + + size->GS = exec->GS; + /* save default graphics state */ + +End: + TT_Save_Context( exec, size ); + + if ( !size->debug ) { + TT_Done_Context( exec ); + } + /* debugging instances keep their context */ + } + +#endif /* TT_CONFIG_OPTION_BYTECODE_INTERPRETER */ + + if ( !error ) { + size->ttmetrics.valid = TRUE; + } + + return error; +} + + +/*************************************************************************/ +/* */ +/* */ +/* TT_Init_Driver */ +/* */ +/* */ +/* Initializes a given TrueType driver object. */ +/* */ +/* */ +/* driver :: A handle to the target driver object. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +LOCAL_FUNC +FT_Error TT_Init_Driver( TT_Driver driver ) { + FT_Error error; + + + /* set `extra' in glyph loader */ + error = FT_GlyphLoader_Create_Extra( FT_DRIVER( driver )->glyph_loader ); + + /* init extension registry if needed */ + +#ifdef TT_CONFIG_OPTION_EXTEND_ENGINE + if ( !error ) { + return TT_Init_Extensions( driver ); + } +#endif + + return error; +} + + +/*************************************************************************/ +/* */ +/* */ +/* TT_Done_Driver */ +/* */ +/* */ +/* Finalizes a given TrueType driver. */ +/* */ +/* */ +/* driver :: A handle to the target TrueType driver. */ +/* */ +LOCAL_FUNC +void TT_Done_Driver( TT_Driver driver ) { + /* destroy extensions registry if needed */ + +#ifdef TT_CONFIG_OPTION_EXTEND_ENGINE + + TT_Done_Extensions( driver ); + +#endif + +#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER + + /* destroy the execution context */ + if ( driver->context ) { + TT_Destroy_Context( driver->context, driver->root.root.memory ); + driver->context = NULL; + } + +#endif + +} + + +/* END */ diff --git a/Projects/Android/jni/rtcw/src/ft2/ttobjs.h b/Projects/Android/jni/rtcw/src/ft2/ttobjs.h new file mode 100644 index 0000000..eff7454 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/ft2/ttobjs.h @@ -0,0 +1,412 @@ +/***************************************************************************/ +/* */ +/* ttobjs.h */ +/* */ +/* Objects manager (specification). */ +/* */ +/* Copyright 1996-2000 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef TTOBJS_H +#define TTOBJS_H + + +#include "ftobjs.h" +#include "tttypes.h" +#include "tterrors.h" + + +#ifdef __cplusplus +extern "C" { +#endif + + +/*************************************************************************/ +/* */ +/* */ +/* TT_Driver */ +/* */ +/* */ +/* A handle to a TrueType driver object. */ +/* */ +typedef struct TT_DriverRec_* TT_Driver; + + +/*************************************************************************/ +/* */ +/* */ +/* TT_Instance */ +/* */ +/* */ +/* A handle to a TrueType size object. */ +/* */ +typedef struct TT_SizeRec_* TT_Size; + + +/*************************************************************************/ +/* */ +/* */ +/* TT_GlyphSlot */ +/* */ +/* */ +/* A handle to a TrueType glyph slot object. */ +/* */ +/* */ +/* This is a direct typedef of FT_GlyphSlot, as there is nothing */ +/* specific about the TrueType glyph slot. */ +/* */ +typedef FT_GlyphSlot TT_GlyphSlot; + + +/*************************************************************************/ +/* */ +/* */ +/* TT_GraphicsState */ +/* */ +/* */ +/* The TrueType graphics state used during bytecode interpretation. */ +/* */ +typedef struct TT_GraphicsState_ +{ + FT_UShort rp0; + FT_UShort rp1; + FT_UShort rp2; + + FT_UnitVector dualVector; + FT_UnitVector projVector; + FT_UnitVector freeVector; + + FT_Long loop; + FT_F26Dot6 minimum_distance; + FT_Int round_state; + + FT_Bool auto_flip; + FT_F26Dot6 control_value_cutin; + FT_F26Dot6 single_width_cutin; + FT_F26Dot6 single_width_value; + FT_Short delta_base; + FT_Short delta_shift; + + FT_Byte instruct_control; + FT_Bool scan_control; + FT_Int scan_type; + + FT_UShort gep0; + FT_UShort gep1; + FT_UShort gep2; + +} TT_GraphicsState; + + +LOCAL_DEF void TT_Done_GlyphZone( TT_GlyphZone* zone ); + +LOCAL_DEF FT_Error TT_New_GlyphZone( FT_Memory memory, + FT_UShort maxPoints, + FT_Short maxContours, + TT_GlyphZone* zone ); + + +/*************************************************************************/ +/* */ +/* EXECUTION SUBTABLES */ +/* */ +/* These sub-tables relate to instruction execution. */ +/* */ +/*************************************************************************/ + + +#define TT_MAX_CODE_RANGES 3 + + +/*************************************************************************/ +/* */ +/* There can only be 3 active code ranges at once: */ +/* - the Font Program */ +/* - the CVT Program */ +/* - a glyph's instructions set */ +/* */ +typedef enum TT_CodeRange_Tag_ +{ + tt_coderange_none = 0, + tt_coderange_font, + tt_coderange_cvt, + tt_coderange_glyph + +} TT_CodeRange_Tag; + + +typedef struct TT_CodeRange_ +{ + FT_Byte* base; + FT_ULong size; + +} TT_CodeRange; + +typedef TT_CodeRange TT_CodeRangeTable[TT_MAX_CODE_RANGES]; + + +/*************************************************************************/ +/* */ +/* Defines a function/instruction definition record. */ +/* */ +typedef struct TT_DefRecord_ +{ + FT_Int range; /* in which code range is it located? */ + FT_Long start; /* where does it start? */ + FT_UInt opc; /* function #, or instruction code */ + FT_Bool active; /* is it active? */ + +} TT_DefRecord, *TT_DefArray; + + +/*************************************************************************/ +/* */ +/* Subglyph transformation record. */ +/* */ +typedef struct TT_Transform_ +{ + FT_Fixed xx, xy; /* transformation matrix coefficients */ + FT_Fixed yx, yy; + FT_F26Dot6 ox, oy; /* offsets */ + +} TT_Transform; + + +/*************************************************************************/ +/* */ +/* Subglyph loading record. Used to load composite components. */ +/* */ +typedef struct TT_SubglyphRec_ +{ + FT_Long index; /* subglyph index; initialized with -1 */ + FT_Bool is_scaled; /* is the subglyph scaled? */ + FT_Bool is_hinted; /* should it be hinted? */ + FT_Bool preserve_pps; /* preserve phantom points? */ + + FT_Long file_offset; + + FT_BBox bbox; + FT_Pos left_bearing; + FT_Pos advance; + + TT_GlyphZone zone; + + FT_Long arg1; /* first argument */ + FT_Long arg2; /* second argument */ + + FT_UShort element_flag; /* current load element flag */ + + TT_Transform transform; /* transformation matrix */ + + FT_Vector pp1, pp2; /* phantom points */ + +} TT_SubGlyphRec, *TT_SubGlyph_Stack; + + +/*************************************************************************/ +/* */ +/* A note regarding non-squared pixels: */ +/* */ +/* (This text will probably go into some docs at some time; for now, it */ +/* is kept here to explain some definitions in the TIns_Metrics */ +/* record). */ +/* */ +/* The CVT is a one-dimensional array containing values that control */ +/* certain important characteristics in a font, like the height of all */ +/* capitals, all lowercase letter, default spacing or stem width/height. */ +/* */ +/* These values are found in FUnits in the font file, and must be scaled */ +/* to pixel coordinates before being used by the CVT and glyph programs. */ +/* Unfortunately, when using distinct x and y resolutions (or distinct x */ +/* and y pointsizes), there are two possible scalings. */ +/* */ +/* A first try was to implement a `lazy' scheme where all values were */ +/* scaled when first used. However, while some values are always used */ +/* in the same direction, some others are used under many different */ +/* circumstances and orientations. */ +/* */ +/* I have found a simpler way to do the same, and it even seems to work */ +/* in most of the cases: */ +/* */ +/* - All CVT values are scaled to the maximum ppem size. */ +/* */ +/* - When performing a read or write in the CVT, a ratio factor is used */ +/* to perform adequate scaling. Example: */ +/* */ +/* x_ppem = 14 */ +/* y_ppem = 10 */ +/* */ +/* We choose ppem = x_ppem = 14 as the CVT scaling size. All cvt */ +/* entries are scaled to it. */ +/* */ +/* x_ratio = 1.0 */ +/* y_ratio = y_ppem/ppem (< 1.0) */ +/* */ +/* We compute the current ratio like: */ +/* */ +/* - If projVector is horizontal, */ +/* ratio = x_ratio = 1.0 */ +/* */ +/* - if projVector is vertical, */ +/* ratio = y_ratio */ +/* */ +/* - else, */ +/* ratio = sqrt( (proj.x * x_ratio) ^ 2 + (proj.y * y_ratio) ^ 2 ) */ +/* */ +/* Reading a cvt value returns */ +/* ratio * cvt[index] */ +/* */ +/* Writing a cvt value in pixels: */ +/* cvt[index] / ratio */ +/* */ +/* The current ppem is simply */ +/* ratio * ppem */ +/* */ +/*************************************************************************/ + + +/*************************************************************************/ +/* */ +/* Metrics used by the TrueType size and context objects. */ +/* */ +typedef struct TT_Size_Metrics_ +{ + /* for non-square pixels */ + FT_Long x_ratio; + FT_Long y_ratio; + + FT_UShort ppem; /* maximum ppem size */ + FT_Long ratio; /* current ratio */ + FT_Fixed scale; + + FT_F26Dot6 compensations[4]; /* device-specific compensations */ + + FT_Bool valid; + + FT_Bool rotated; /* `is the glyph rotated?'-flag */ + FT_Bool stretched; /* `is the glyph stretched?'-flag */ + +} TT_Size_Metrics; + + +/*************************************************************************/ +/* */ +/* TrueType size class. */ +/* */ +typedef struct TT_SizeRec_ +{ + FT_SizeRec root; + + TT_Size_Metrics ttmetrics; + +#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER + + FT_UInt num_function_defs; /* number of function definitions */ + FT_UInt max_function_defs; + TT_DefArray function_defs; /* table of function definitions */ + + FT_UInt num_instruction_defs; /* number of ins. definitions */ + FT_UInt max_instruction_defs; + TT_DefArray instruction_defs; /* table of ins. definitions */ + + FT_UInt max_func; + FT_UInt max_ins; + + TT_CodeRangeTable codeRangeTable; + + TT_GraphicsState GS; + + FT_ULong cvt_size; /* the scaled control value table */ + FT_Long* cvt; + + FT_UShort storage_size; /* The storage area is now part of */ + FT_Long* storage; /* the instance */ + + TT_GlyphZone twilight; /* The instance's twilight zone */ + + /* debugging variables */ + + /* When using the debugger, we must keep the */ + /* execution context tied to the instance */ + /* object rather than asking it on demand. */ + + FT_Bool debug; + TT_ExecContext context; + +#endif /* TT_CONFIG_OPTION_BYTECODE_INTERPRETER */ + +} TT_SizeRec; + + +/*************************************************************************/ +/* */ +/* TrueType driver class. */ +/* */ +typedef struct TT_DriverRec_ +{ + FT_DriverRec root; + TT_ExecContext context; /* execution context */ + TT_GlyphZone zone; /* glyph loader points zone */ + + void* extension_component; + +} TT_DriverRec; + + +/*************************************************************************/ +/* */ +/* Face functions */ +/* */ +LOCAL_DEF +FT_Error TT_Init_Face( FT_Stream stream, + TT_Face face, + FT_Int face_index, + FT_Int num_params, + FT_Parameter* params ); + +LOCAL_DEF +void TT_Done_Face( TT_Face face ); + + +/*************************************************************************/ +/* */ +/* Size functions */ +/* */ +LOCAL_DEF +FT_Error TT_Init_Size( TT_Size size ); + +LOCAL_DEF +void TT_Done_Size( TT_Size size ); + +LOCAL_DEF +FT_Error TT_Reset_Size( TT_Size size ); + + +/*************************************************************************/ +/* */ +/* Driver functions */ +/* */ +LOCAL_DEF +FT_Error TT_Init_Driver( TT_Driver driver ); + +LOCAL_DEF +void TT_Done_Driver( TT_Driver driver ); + + +#ifdef __cplusplus +} +#endif + +#endif /* TTOBJS_H */ + + +/* END */ diff --git a/Projects/Android/jni/rtcw/src/ft2/ttpload.c b/Projects/Android/jni/rtcw/src/ft2/ttpload.c new file mode 100644 index 0000000..892e1cd --- /dev/null +++ b/Projects/Android/jni/rtcw/src/ft2/ttpload.c @@ -0,0 +1,266 @@ +/***************************************************************************/ +/* */ +/* ttpload.h */ +/* */ +/* TrueType glyph data/program tables loader (body). */ +/* */ +/* Copyright 1996-2000 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#include "ftdebug.h" +#include "ftobjs.h" +#include "ftstream.h" +#include "tttags.h" + +#include "ttpload.h" + +#include "tterrors.h" + + +/*************************************************************************/ +/* */ +/* The macro FT_COMPONENT is used in trace mode. It is an implicit */ +/* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */ +/* messages during execution. */ +/* */ +#undef FT_COMPONENT +#define FT_COMPONENT trace_ttpload + + +/*************************************************************************/ +/* */ +/* */ +/* TT_Load_Locations */ +/* */ +/* */ +/* Loads the locations table. */ +/* */ +/* */ +/* face :: A handle to the target face object. */ +/* */ +/* */ +/* stream :: The input stream. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +LOCAL_FUNC +FT_Error TT_Load_Locations( TT_Face face, + FT_Stream stream ) { + FT_Error error; + FT_Memory memory = stream->memory; + FT_Short LongOffsets; + FT_ULong table_len; + + + FT_TRACE2( ( "Locations " ) ); + LongOffsets = face->header.Index_To_Loc_Format; + + error = face->goto_table( face, TTAG_loca, stream, &table_len ); + if ( error ) { + error = TT_Err_Locations_Missing; + goto Exit; + } + + if ( LongOffsets != 0 ) { + face->num_locations = (FT_UShort)( table_len >> 2 ); + + FT_TRACE2( ( "(32bit offsets): %12d ", face->num_locations ) ); + + if ( ALLOC_ARRAY( face->glyph_locations, + face->num_locations, + FT_Long ) ) { + goto Exit; + } + + if ( ACCESS_Frame( face->num_locations * 4L ) ) { + goto Exit; + } + + { + FT_Long* loc = face->glyph_locations; + FT_Long* limit = loc + face->num_locations; + + + for ( ; loc < limit; loc++ ) + *loc = GET_Long(); + } + + FORGET_Frame(); + } else + { + face->num_locations = (FT_UShort)( table_len >> 1 ); + + FT_TRACE2( ( "(16bit offsets): %12d ", face->num_locations ) ); + + if ( ALLOC_ARRAY( face->glyph_locations, + face->num_locations, + FT_Long ) ) { + goto Exit; + } + + if ( ACCESS_Frame( face->num_locations * 2L ) ) { + goto Exit; + } + { + FT_Long* loc = face->glyph_locations; + FT_Long* limit = loc + face->num_locations; + + + for ( ; loc < limit; loc++ ) + *loc = (FT_Long)( (FT_ULong)GET_UShort() * 2 ); + } + FORGET_Frame(); + } + + FT_TRACE2( ( "loaded\n" ) ); + +Exit: + return error; +} + + +/*************************************************************************/ +/* */ +/* */ +/* TT_Load_CVT */ +/* */ +/* */ +/* Loads the control value table into a face object. */ +/* */ +/* */ +/* face :: A handle to the target face object. */ +/* */ +/* */ +/* stream :: A handle to the input stream. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +LOCAL_FUNC +FT_Error TT_Load_CVT( TT_Face face, + FT_Stream stream ) { + FT_Error error; + FT_Memory memory = stream->memory; + FT_ULong table_len; + + + FT_TRACE2( ( "CVT " ) ); + + error = face->goto_table( face, TTAG_cvt, stream, &table_len ); + if ( error ) { + FT_TRACE2( ( "is missing!\n" ) ); + + face->cvt_size = 0; + face->cvt = NULL; + error = TT_Err_Ok; + + goto Exit; + } + + face->cvt_size = table_len / 2; + + if ( ALLOC_ARRAY( face->cvt, + face->cvt_size, + FT_Short ) ) { + goto Exit; + } + + if ( ACCESS_Frame( face->cvt_size * 2L ) ) { + goto Exit; + } + + { + FT_Short* cur = face->cvt; + FT_Short* limit = cur + face->cvt_size; + + + for ( ; cur < limit; cur++ ) + *cur = GET_Short(); + } + + FORGET_Frame(); + FT_TRACE2( ( "loaded\n" ) ); + +Exit: + return error; +} + + +/*************************************************************************/ +/* */ +/* */ +/* TT_Load_Progams */ +/* */ +/* */ +/* Loads the font program and the cvt program. */ +/* */ +/* */ +/* face :: A handle to the target face object. */ +/* */ +/* */ +/* stream :: A handle to the input stream. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +LOCAL_FUNC +FT_Error TT_Load_Programs( TT_Face face, + FT_Stream stream ) { + FT_Error error; + FT_ULong table_len; + + + FT_TRACE2( ( "Font program " ) ); + + /* The font program is optional */ + error = face->goto_table( face, TTAG_fpgm, stream, &table_len ); + if ( error ) { + face->font_program = NULL; + face->font_program_size = 0; + + FT_TRACE2( ( "is missing!\n" ) ); + } else + { + face->font_program_size = table_len; + if ( EXTRACT_Frame( table_len, face->font_program ) ) { + goto Exit; + } + + FT_TRACE2( ( "loaded, %12d bytes\n", face->font_program_size ) ); + } + + FT_TRACE2( ( "Prep program " ) ); + + error = face->goto_table( face, TTAG_prep, stream, &table_len ); + if ( error ) { + face->cvt_program = NULL; + face->cvt_program_size = 0; + error = TT_Err_Ok; + + FT_TRACE2( ( "is missing!\n" ) ); + } else + { + face->cvt_program_size = table_len; + if ( EXTRACT_Frame( table_len, face->cvt_program ) ) { + goto Exit; + } + + FT_TRACE2( ( "loaded, %12d bytes\n", face->cvt_program_size ) ); + } + +Exit: + return error; +} + + +/* END */ diff --git a/Projects/Android/jni/rtcw/src/ft2/ttpload.h b/Projects/Android/jni/rtcw/src/ft2/ttpload.h new file mode 100644 index 0000000..eecf236 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/ft2/ttpload.h @@ -0,0 +1,51 @@ +/***************************************************************************/ +/* */ +/* ttpload.h */ +/* */ +/* TrueType glyph data/program tables loader (specification). */ +/* */ +/* Copyright 1996-2000 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef TTPLOAD_H +#define TTPLOAD_H + +#include "tttypes.h" + + +#ifdef __cplusplus +extern "C" { +#endif + + +LOCAL_DEF +FT_Error TT_Load_Locations( TT_Face face, + FT_Stream stream ); + +LOCAL_DEF +FT_Error TT_Load_CVT( TT_Face face, + FT_Stream stream ); + +LOCAL_DEF +FT_Error TT_Load_Programs( TT_Face face, + FT_Stream stream ); + + +#ifdef __cplusplus +} +#endif + + +#endif /* TTPLOAD_H */ + + +/* END */ diff --git a/Projects/Android/jni/rtcw/src/ft2/ttpost.c b/Projects/Android/jni/rtcw/src/ft2/ttpost.c new file mode 100644 index 0000000..811087b --- /dev/null +++ b/Projects/Android/jni/rtcw/src/ft2/ttpost.c @@ -0,0 +1,528 @@ +/***************************************************************************/ +/* */ +/* ttpost.c */ +/* */ +/* Postcript name table processing for TrueType and OpenType fonts */ +/* (body). */ +/* */ +/* Copyright 1996-2000 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + +/*************************************************************************/ +/* */ +/* The post table is not completely loaded by the core engine. This */ +/* file loads the missing PS glyph names and implements an API to access */ +/* them. */ +/* */ +/*************************************************************************/ + + +#include "ftstream.h" +#include "tterrors.h" +#include "tttags.h" + + +#include "ttpost.h" +#include "ttload.h" + + +/*************************************************************************/ +/* */ +/* The macro FT_COMPONENT is used in trace mode. It is an implicit */ +/* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */ +/* messages during execution. */ +/* */ +#undef FT_COMPONENT +#define FT_COMPONENT trace_ttpost + + +/* If this configuration macro is defined, we rely on the `PSNames' */ +/* module to grab the glyph names. */ + +#ifdef FT_CONFIG_OPTION_POSTSCRIPT_NAMES + + +#include "psnames.h" + +#define MAC_NAME( x ) ( (FT_String*)psnames->macintosh_name( x ) ) + + +#else /* FT_CONFIG_OPTION_POSTSCRIPT_NAMES */ + + +/* Otherwise, we ignore the `PSNames' module, and provide our own */ +/* table of Mac names. Thus, it is possible to build a version of */ +/* FreeType without the Type 1 driver & PSNames module. */ + +#define MAC_NAME( x ) TT_Post_Default_Names[x] + +/* the 258 default Mac PS glyph names */ + +FT_String* TT_Post_Default_Names[258] = +{ + /* 0 */ + ".notdef", ".null", "CR", "space", "exclam", + "quotedbl", "numbersign", "dollar", "percent", "ampersand", + /* 10 */ + "quotesingle", "parenleft", "parenright", "asterisk", "plus", + "comma", "hyphen", "period", "slash", "zero", + /* 20 */ + "one", "two", "three", "four", "five", + "six", "seven", "eight", "nine", "colon", + /* 30 */ + "semicolon", "less", "equal", "greater", "question", + "at", "A", "B", "C", "D", + /* 40 */ + "E", "F", "G", "H", "I", + "J", "K", "L", "M", "N", + /* 50 */ + "O", "P", "Q", "R", "S", + "T", "U", "V", "W", "X", + /* 60 */ + "Y", "Z", "bracketleft", "backslash", "bracketright", + "asciicircum", "underscore", "grave", "a", "b", + /* 70 */ + "c", "d", "e", "f", "g", + "h", "i", "j", "k", "l", + /* 80 */ + "m", "n", "o", "p", "q", + "r", "s", "t", "u", "v", + /* 90 */ + "w", "x", "y", "z", "braceleft", + "bar", "braceright", "asciitilde", "Adieresis", "Aring", + /* 100 */ + "Ccedilla", "Eacute", "Ntilde", "Odieresis", "Udieresis", + "aacute", "agrave", "acircumflex", "adieresis", "atilde", + /* 110 */ + "aring", "ccedilla", "eacute", "egrave", "ecircumflex", + "edieresis", "iacute", "igrave", "icircumflex", "idieresis", + /* 120 */ + "ntilde", "oacute", "ograve", "ocircumflex", "odieresis", + "otilde", "uacute", "ugrave", "ucircumflex", "udieresis", + /* 130 */ + "dagger", "degree", "cent", "sterling", "section", + "bullet", "paragraph", "germandbls", "registered", "copyright", + /* 140 */ + "trademark", "acute", "dieresis", "notequal", "AE", + "Oslash", "infinity", "plusminus", "lessequal", "greaterequal", + /* 150 */ + "yen", "mu", "partialdiff", "summation", "product", + "pi", "integral", "ordfeminine", "ordmasculine", "Omega", + /* 160 */ + "ae", "oslash", "questiondown", "exclamdown", "logicalnot", + "radical", "florin", "approxequal", "Delta", "guillemotleft", + /* 170 */ + "guillemotright", "ellipsis", "nbspace", "Agrave", "Atilde", + "Otilde", "OE", "oe", "endash", "emdash", + /* 180 */ + "quotedblleft", "quotedblright", "quoteleft", "quoteright", "divide", + "lozenge", "ydieresis", "Ydieresis", "fraction", "currency", + /* 190 */ + "guilsinglleft", "guilsinglright", "fi", "fl", "daggerdbl", + "periodcentered", "quotesinglbase", "quotedblbase", "perthousand", "Acircumflex", + /* 200 */ + "Ecircumflex", "Aacute", "Edieresis", "Egrave", "Iacute", + "Icircumflex", "Idieresis", "Igrave", "Oacute", "Ocircumflex", + /* 210 */ + "apple", "Ograve", "Uacute", "Ucircumflex", "Ugrave", + "dotlessi", "circumflex", "tilde", "macron", "breve", + /* 220 */ + "dotaccent", "ring", "cedilla", "hungarumlaut", "ogonek", + "caron", "Lslash", "lslash", "Scaron", "scaron", + /* 230 */ + "Zcaron", "zcaron", "brokenbar", "Eth", "eth", + "Yacute", "yacute", "Thorn", "thorn", "minus", + /* 240 */ + "multiply", "onesuperior", "twosuperior", "threesuperior", "onehalf", + "onequarter", "threequarters", "franc", "Gbreve", "gbreve", + /* 250 */ + "Idot", "Scedilla", "scedilla", "Cacute", "cacute", + "Ccaron", "ccaron", "dmacron", +}; + + +#endif /* FT_CONFIG_OPTION_POSTSCRIPT_NAMES */ + + +static +FT_Error Load_Format_20( TT_Face face, + FT_Stream stream ) { + FT_Memory memory = stream->memory; + FT_Error error; + + FT_Int num_glyphs; + FT_Int num_names; + + FT_UShort* glyph_indices = 0; + FT_Char** name_strings = 0; + + + if ( READ_UShort( num_glyphs ) ) { + goto Exit; + } + + /* UNDOCUMENTED! The number of glyphs in this table can be smaller */ + /* than the value in the maxp table (cf. cyberbit.ttf). */ + + /* There already exist fonts which have more than 32768 glyph names */ + /* in this table, so the test for this threshold has been dropped. */ + + if ( num_glyphs > face->root.num_glyphs ) { + error = TT_Err_Invalid_File_Format; + goto Exit; + } + + /* load the indices */ + { + FT_Int n; + + + if ( ALLOC_ARRAY( glyph_indices, num_glyphs, FT_UShort ) || + ACCESS_Frame( num_glyphs * 2L ) ) { + goto Fail; + } + + for ( n = 0; n < num_glyphs; n++ ) + glyph_indices[n] = GET_UShort(); + + FORGET_Frame(); + } + + /* compute number of names stored in table */ + { + FT_Int n; + + + num_names = 0; + + for ( n = 0; n < num_glyphs; n++ ) + { + FT_Int index; + + + index = glyph_indices[n]; + if ( index >= 258 ) { + index -= 257; + if ( index > num_names ) { + num_names = index; + } + } + } + } + + /* now load the name strings */ + { + FT_Int n; + + + if ( ALLOC_ARRAY( name_strings, num_names, FT_Char* ) ) { + goto Fail; + } + + for ( n = 0; n < num_names; n++ ) + { + FT_UInt len; + + + if ( READ_Byte( len ) || + ALLOC_ARRAY( name_strings[n], len + 1, FT_Char ) || + FILE_Read( name_strings[n], len ) ) { + goto Fail1; + } + + name_strings[n][len] = '\0'; + } + } + + /* all right, set table fields and exit successfuly */ + { + TT_Post_20* table = &face->postscript_names.names.format_20; + + + table->num_glyphs = num_glyphs; + table->num_names = num_names; + table->glyph_indices = glyph_indices; + table->glyph_names = name_strings; + } + return TT_Err_Ok; + + +Fail1: + { + FT_Int n; + + + for ( n = 0; n < num_names; n++ ) + FREE( name_strings[n] ); + } + +Fail: + FREE( name_strings ); + FREE( glyph_indices ); + +Exit: + return error; +} + + +static +FT_Error Load_Format_25( TT_Face face, + FT_Stream stream ) { + FT_Memory memory = stream->memory; + FT_Error error; + + FT_Int num_glyphs; + FT_Char* offset_table = 0; + + + /* UNDOCUMENTED! This value appears only in the Apple TT specs. */ + if ( READ_UShort( num_glyphs ) ) { + goto Exit; + } + + /* check the number of glyphs */ + if ( num_glyphs > face->root.num_glyphs || num_glyphs > 258 ) { + error = TT_Err_Invalid_File_Format; + goto Exit; + } + + if ( ALLOC( offset_table, num_glyphs ) || + FILE_Read( offset_table, num_glyphs ) ) { + goto Fail; + } + + /* now check the offset table */ + { + FT_Int n; + + + for ( n = 0; n < num_glyphs; n++ ) + { + FT_Long index = (FT_Long)n + offset_table[n]; + + + if ( index < 0 || index > num_glyphs ) { + error = TT_Err_Invalid_File_Format; + goto Fail; + } + } + } + + /* OK, set table fields and exit successfuly */ + { + TT_Post_25* table = &face->postscript_names.names.format_25; + + + table->num_glyphs = num_glyphs; + table->offsets = offset_table; + } + + return TT_Err_Ok; + +Fail: + FREE( offset_table ); + +Exit: + return error; +} + + +static +FT_Error Load_Post_Names( TT_Face face ) { + FT_Stream stream; + FT_Error error; + + /* get a stream for the face's resource */ + stream = face->root.stream; + + /* seek to the beginning of the PS names table */ + error = face->goto_table( face, TTAG_post, stream, 0 ); + if ( error ) { + goto Exit; + } + + /* now read postscript table */ + switch ( face->postscript.FormatType ) + { + case 0x00020000L: + error = Load_Format_20( face, stream ); + break; + + case 0x00028000L: + error = Load_Format_25( face, stream ); + break; + + default: + error = TT_Err_Invalid_File_Format; + } + + face->postscript_names.loaded = 1; + +Exit: + return error; +} + + +LOCAL_FUNC +void TT_Free_Post_Names( TT_Face face ) { + FT_Memory memory = face->root.memory; + TT_Post_Names* names = &face->postscript_names; + + + if ( names->loaded ) { + switch ( face->postscript.FormatType ) + { + case 0x00020000L: + { + TT_Post_20* table = &names->names.format_20; + FT_UInt n; + + + FREE( table->glyph_indices ); + table->num_glyphs = 0; + + for ( n = 0; n < table->num_names; n++ ) + FREE( table->glyph_names[n] ); + + FREE( table->glyph_names ); + table->num_names = 0; + } + break; + + case 0x00028000L: + { + TT_Post_25* table = &names->names.format_25; + + + FREE( table->offsets ); + table->num_glyphs = 0; + } + break; + } + } + names->loaded = 0; +} + + +/*************************************************************************/ +/* */ +/* */ +/* TT_Get_PS_Name */ +/* */ +/* */ +/* Gets the PostScript glyph name of a glyph. */ +/* */ +/* */ +/* face :: A handle to the parent face. */ +/* */ +/* index :: The glyph index. */ +/* */ +/* PSname :: The address of a string pointer. Will be NULL in case */ +/* of error, otherwise it is a pointer to the glyph name. */ +/* */ +/* You must not modify the returned string! */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +LOCAL_FUNC +FT_Error TT_Get_PS_Name( TT_Face face, + FT_UInt index, + FT_String** PSname ) { + FT_Error error; + TT_Post_Names* names; + +#ifdef FT_CONFIG_OPTION_POSTSCRIPT_NAMES + PSNames_Interface* psnames; +#endif + + + if ( !face ) { + return TT_Err_Invalid_Face_Handle; + } + + if ( index >= (FT_UInt)face->root.num_glyphs ) { + return TT_Err_Invalid_Glyph_Index; + } + +#ifdef FT_CONFIG_OPTION_POSTSCRIPT_NAMES + psnames = (PSNames_Interface*)face->psnames; + if ( !psnames ) { + return TT_Err_Unimplemented_Feature; + } +#endif + + names = &face->postscript_names; + + /* `.notdef' by default */ + *PSname = MAC_NAME( 0 ); + + switch ( face->postscript.FormatType ) + { + case 0x00010000L: + if ( index < 258 ) { /* paranoid checking */ + *PSname = MAC_NAME( index ); + } + break; + + case 0x00020000L: + { + TT_Post_20* table = &names->names.format_20; + + + if ( !names->loaded ) { + error = Load_Post_Names( face ); + if ( error ) { + break; + } + } + + if ( index < table->num_glyphs ) { + FT_UShort name_index = table->glyph_indices[index]; + + + if ( name_index < 258 ) { + *PSname = MAC_NAME( name_index ); + } else { + *PSname = (FT_String*)table->glyph_names[name_index - 258]; + } + } + } + break; + + case 0x00028000L: + { + TT_Post_25* table = &names->names.format_25; + + + if ( !names->loaded ) { + error = Load_Post_Names( face ); + if ( error ) { + break; + } + } + + if ( index < table->num_glyphs ) { /* paranoid checking */ + index += table->offsets[index]; + *PSname = MAC_NAME( index ); + } + } + break; + + case 0x00030000L: + break; /* nothing to do */ + } + + return TT_Err_Ok; +} + + +/* END */ diff --git a/Projects/Android/jni/rtcw/src/ft2/ttpost.h b/Projects/Android/jni/rtcw/src/ft2/ttpost.h new file mode 100644 index 0000000..86708f7 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/ft2/ttpost.h @@ -0,0 +1,52 @@ +/***************************************************************************/ +/* */ +/* ttpost.h */ +/* */ +/* Postcript name table processing for TrueType and OpenType fonts */ +/* (specification). */ +/* */ +/* Copyright 1996-2000 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef TTPOST_H +#define TTPOST_H + +#include "ftconfig.h" +#include "tttypes.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +#define TT_Err_Invalid_Post_Table_Format 0x0B00 +#define TT_Err_Invalid_Post_Table 0x0B01 + + +LOCAL_DEF +FT_Error TT_Get_PS_Name( TT_Face face, + FT_UInt index, + FT_String** PSname ); + +LOCAL_DEF +void TT_Free_Post_Names( TT_Face face ); + + +#ifdef __cplusplus +} +#endif + + +#endif /* TTPOST_H */ + + +/* END */ diff --git a/Projects/Android/jni/rtcw/src/ft2/ttsbit.c b/Projects/Android/jni/rtcw/src/ft2/ttsbit.c new file mode 100644 index 0000000..bb7bcaf --- /dev/null +++ b/Projects/Android/jni/rtcw/src/ft2/ttsbit.c @@ -0,0 +1,1449 @@ +/***************************************************************************/ +/* */ +/* ttsbit.c */ +/* */ +/* TrueType and OpenType embedded bitmap support (body). */ +/* */ +/* Copyright 1996-2000 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#include "ftdebug.h" +#include "tterrors.h" +#include "tttags.h" + +#include "ttsbit.h" + + + +/*************************************************************************/ +/* */ +/* The macro FT_COMPONENT is used in trace mode. It is an implicit */ +/* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */ +/* messages during execution. */ +/* */ +#undef FT_COMPONENT +#define FT_COMPONENT trace_ttsbit + + +/*************************************************************************/ +/* */ +/* */ +/* blit_sbit */ +/* */ +/* */ +/* Blits a bitmap from an input stream into a given target. Supports */ +/* x and y offsets as well as byte padded lines. */ +/* */ +/* */ +/* target :: The target bitmap/pixmap. */ +/* */ +/* source :: The input packed bitmap data. */ +/* */ +/* line_bits :: The number of bits per line. */ +/* */ +/* byte_padded :: A flag which is true if lines are byte-padded. */ +/* */ +/* x_offset :: The horizontal offset. */ +/* */ +/* y_offset :: The vertical offset. */ +/* */ +/* */ +/* IMPORTANT: The x and y offsets are relative to the top corner of */ +/* the target bitmap (unlike the normal TrueType */ +/* convention). A positive y offset indicates a downwards */ +/* direction! */ +/* */ +static +void blit_sbit( FT_Bitmap* target, + FT_Byte* source, + FT_Int line_bits, + FT_Bool byte_padded, + FT_Int x_offset, + FT_Int y_offset ) { + FT_Byte* line_buff; + FT_Int line_incr; + FT_Int height; + + FT_UShort acc; + FT_Byte loaded; + + + /* first of all, compute starting write position */ + line_incr = target->pitch; + line_buff = target->buffer; + + if ( line_incr < 0 ) { + line_buff -= line_incr * ( target->rows - 1 ); + } + + line_buff += ( x_offset >> 3 ) + y_offset * line_incr; + + /***********************************************************************/ + /* */ + /* We use the extra-classic `accumulator' trick to extract the bits */ + /* from the source byte stream. */ + /* */ + /* Namely, the variable `acc' is a 16-bit accumulator containing the */ + /* last `loaded' bits from the input stream. The bits are shifted to */ + /* the upmost position in `acc'. */ + /* */ + /***********************************************************************/ + + acc = 0; /* clear accumulator */ + loaded = 0; /* no bits were loaded */ + + for ( height = target->rows; height > 0; height-- ) + { + FT_Byte* cur = line_buff; /* current write cursor */ + FT_Int count = line_bits; /* # of bits to extract per line */ + FT_Byte shift = x_offset & 7; /* current write shift */ + FT_Byte space = 8 - shift; + + + /* first of all, read individual source bytes */ + if ( count >= 8 ) { + count -= 8; + { + do + { + FT_Byte val; + + + /* ensure that there are at least 8 bits in the accumulator */ + if ( loaded < 8 ) { + acc |= ( FT_UShort ) * source++ << ( 8 - loaded ); + loaded += 8; + } + + /* now write one byte */ + val = (FT_Byte)( acc >> 8 ); + if ( shift ) { + cur[0] |= val >> shift; + cur[1] |= val << space; + } else { + cur[0] |= val; + } + + cur++; + acc <<= 8; /* remove bits from accumulator */ + loaded -= 8; + count -= 8; + + } while ( count >= 0 ); + } + + /* restore `count' to correct value */ + count += 8; + } + + /* now write remaining bits (count < 8) */ + if ( count > 0 ) { + FT_Byte val; + + + /* ensure that there are at least `count' bits in the accumulator */ + if ( loaded < count ) { + acc |= ( FT_UShort ) * source++ << ( 8 - loaded ); + loaded += 8; + } + + /* now write remaining bits */ + val = ( (FT_Byte)( acc >> 8 ) ) & ~( 0xFF >> count ); + cur[0] |= val >> shift; + + if ( count > space ) { + cur[1] |= val << space; + } + + acc <<= count; + loaded -= count; + } + + /* now, skip to next line */ + if ( byte_padded ) { + acc = loaded = 0; /* clear accumulator on byte-padded lines */ + + } + line_buff += line_incr; + } +} + + +const FT_Frame_Field sbit_metrics_fields[] = +{ + FT_FRAME_START( 8 ), + FT_FRAME_BYTE( TT_SBit_Metrics, height ), + FT_FRAME_BYTE( TT_SBit_Metrics, width ), + + FT_FRAME_CHAR( TT_SBit_Metrics, horiBearingX ), + FT_FRAME_CHAR( TT_SBit_Metrics, horiBearingY ), + FT_FRAME_BYTE( TT_SBit_Metrics, horiAdvance ), + + FT_FRAME_CHAR( TT_SBit_Metrics, vertBearingX ), + FT_FRAME_CHAR( TT_SBit_Metrics, vertBearingY ), + FT_FRAME_BYTE( TT_SBit_Metrics, vertAdvance ), + FT_FRAME_END +}; + + +/*************************************************************************/ +/* */ +/* */ +/* TT_Load_SBit_Const_Metrics */ +/* */ +/* */ +/* Loads the metrics for `EBLC' index tables format 2 and 5. */ +/* */ +/* */ +/* range :: The target range. */ +/* */ +/* stream :: The input stream. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +static +FT_Error Load_SBit_Const_Metrics( TT_SBit_Range* range, + FT_Stream stream ) { + FT_Error error; + + + if ( READ_ULong( range->image_size ) ) { + return error; + } + + return READ_Fields( sbit_metrics_fields, &range->metrics ); +} + + +/*************************************************************************/ +/* */ +/* */ +/* TT_Load_SBit_Range_Codes */ +/* */ +/* */ +/* Loads the range codes for `EBLC' index tables format 4 and 5. */ +/* */ +/* */ +/* range :: The target range. */ +/* */ +/* stream :: The input stream. */ +/* */ +/* load_offsets :: A flag whether to load the glyph offset table. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +static +FT_Error Load_SBit_Range_Codes( TT_SBit_Range* range, + FT_Stream stream, + FT_Bool load_offsets ) { + FT_Error error; + FT_ULong count, n, size; + FT_Memory memory = stream->memory; + + + if ( READ_ULong( count ) ) { + goto Exit; + } + + range->num_glyphs = count; + + /* Allocate glyph offsets table if needed */ + if ( load_offsets ) { + if ( ALLOC_ARRAY( range->glyph_offsets, count, FT_ULong ) ) { + goto Exit; + } + + size = count * 4L; + } else { + size = count * 2L; + } + + /* Allocate glyph codes table and access frame */ + if ( ALLOC_ARRAY( range->glyph_codes, count, FT_UShort ) || + ACCESS_Frame( size ) ) { + goto Exit; + } + + for ( n = 0; n < count; n++ ) + { + range->glyph_codes[n] = GET_UShort(); + + if ( load_offsets ) { + range->glyph_offsets[n] = (FT_ULong)range->image_offset + + GET_UShort(); + } + } + + FORGET_Frame(); + +Exit: + return error; +} + + +/*************************************************************************/ +/* */ +/* */ +/* TT_Load_SBit_Range */ +/* */ +/* */ +/* Loads a given `EBLC' index/range table. */ +/* */ +/* */ +/* range :: The target range. */ +/* */ +/* stream :: The input stream. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +static +FT_Error Load_SBit_Range( TT_SBit_Range* range, + FT_Stream stream ) { + FT_Error error; + FT_Memory memory = stream->memory; + + + switch ( range->index_format ) + { + case 1: /* variable metrics with 4-byte offsets */ + case 3: /* variable metrics with 2-byte offsets */ + { + FT_ULong num_glyphs, n; + FT_Int size_elem; + FT_Bool large = ( range->index_format == 1 ); + + + num_glyphs = range->last_glyph - range->first_glyph + 1L; + range->num_glyphs = num_glyphs; + num_glyphs++; /* XXX: BEWARE - see spec */ + + size_elem = large ? 4 : 2; + + if ( ALLOC_ARRAY( range->glyph_offsets, + num_glyphs, FT_ULong ) || + ACCESS_Frame( num_glyphs * size_elem ) ) { + goto Exit; + } + + for ( n = 0; n < num_glyphs; n++ ) + range->glyph_offsets[n] = (FT_ULong)( range->image_offset + + ( large ? GET_ULong() + : GET_UShort() ) ); + FORGET_Frame(); + } + break; + + case 2: /* all glyphs have identical metrics */ + error = Load_SBit_Const_Metrics( range, stream ); + break; + + case 4: + error = Load_SBit_Range_Codes( range, stream, 1 ); + break; + + case 5: + error = Load_SBit_Const_Metrics( range, stream ) || + Load_SBit_Range_Codes( range, stream, 0 ); + break; + + default: + error = TT_Err_Invalid_File_Format; + } + +Exit: + return error; +} + + +/*************************************************************************/ +/* */ +/* */ +/* TT_Load_SBit_Strikes */ +/* */ +/* */ +/* Loads the table of embedded bitmap sizes for this face. */ +/* */ +/* */ +/* face :: The target face object. */ +/* */ +/* stream :: The input stream. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +LOCAL_FUNC +FT_Error TT_Load_SBit_Strikes( TT_Face face, + FT_Stream stream ) { + FT_Error error = 0; + FT_Memory memory = stream->memory; + FT_Fixed version; + FT_ULong num_strikes; + FT_ULong table_base; + + const FT_Frame_Field sbit_line_metrics_fields[] = + { + /* no FT_FRAME_START */ + FT_FRAME_CHAR( TT_SBit_Line_Metrics, ascender ), + FT_FRAME_CHAR( TT_SBit_Line_Metrics, descender ), + FT_FRAME_BYTE( TT_SBit_Line_Metrics, max_width ), + + FT_FRAME_CHAR( TT_SBit_Line_Metrics, caret_slope_numerator ), + FT_FRAME_CHAR( TT_SBit_Line_Metrics, caret_slope_denominator ), + FT_FRAME_CHAR( TT_SBit_Line_Metrics, caret_offset ), + + FT_FRAME_CHAR( TT_SBit_Line_Metrics, min_origin_SB ), + FT_FRAME_CHAR( TT_SBit_Line_Metrics, min_advance_SB ), + FT_FRAME_CHAR( TT_SBit_Line_Metrics, max_before_BL ), + FT_FRAME_CHAR( TT_SBit_Line_Metrics, min_after_BL ), + FT_FRAME_CHAR( TT_SBit_Line_Metrics, pads[0] ), + FT_FRAME_CHAR( TT_SBit_Line_Metrics, pads[1] ), + FT_FRAME_END + }; + + const FT_Frame_Field strike_start_fields[] = + { + /* no FT_FRAME_START */ + FT_FRAME_ULONG( TT_SBit_Strike, ranges_offset ), + FT_FRAME_SKIP_LONG, + FT_FRAME_ULONG( TT_SBit_Strike, num_ranges ), + FT_FRAME_ULONG( TT_SBit_Strike, color_ref ), + FT_FRAME_END + }; + + const FT_Frame_Field strike_end_fields[] = + { + /* no FT_FRAME_START */ + FT_FRAME_USHORT( TT_SBit_Strike, start_glyph ), + FT_FRAME_USHORT( TT_SBit_Strike, end_glyph ), + FT_FRAME_BYTE( TT_SBit_Strike, x_ppem ), + FT_FRAME_BYTE( TT_SBit_Strike, y_ppem ), + FT_FRAME_BYTE( TT_SBit_Strike, bit_depth ), + FT_FRAME_CHAR( TT_SBit_Strike, flags ), + FT_FRAME_END + }; + + + face->num_sbit_strikes = 0; + + /* this table is optional */ + error = face->goto_table( face, TTAG_EBLC, stream, 0 ); + if ( error ) { + error = face->goto_table( face, TTAG_bloc, stream, 0 ); + } + if ( error ) { + error = 0; + goto Exit; + } + + table_base = FILE_Pos(); + if ( ACCESS_Frame( 8L ) ) { + goto Exit; + } + + version = GET_Long(); + num_strikes = GET_ULong(); + + FORGET_Frame(); + + /* check version number and strike count */ + if ( version != 0x00020000L || + num_strikes >= 0x10000L ) { + FT_ERROR( ( "TT_Load_SBit_Strikes: invalid table version!\n" ) ); + error = TT_Err_Invalid_File_Format; + + goto Exit; + } + + /* allocate the strikes table */ + if ( ALLOC_ARRAY( face->sbit_strikes, num_strikes, TT_SBit_Strike ) ) { + goto Exit; + } + + face->num_sbit_strikes = num_strikes; + + /* now read each strike table separately */ + { + TT_SBit_Strike* strike = face->sbit_strikes; + FT_ULong count = num_strikes; + + + if ( ACCESS_Frame( 48L * num_strikes ) ) { + goto Exit; + } + + while ( count > 0 ) + { + (void)READ_Fields( strike_start_fields, strike ); + + (void)READ_Fields( sbit_line_metrics_fields, &strike->hori ); + (void)READ_Fields( sbit_line_metrics_fields, &strike->vert ); + + (void)READ_Fields( strike_end_fields, strike ); + + count--; + strike++; + } + + FORGET_Frame(); + } + + /* allocate the index ranges for each strike table */ + { + TT_SBit_Strike* strike = face->sbit_strikes; + FT_ULong count = num_strikes; + + + while ( count > 0 ) + { + TT_SBit_Range* range; + FT_ULong count2 = strike->num_ranges; + + + if ( ALLOC_ARRAY( strike->sbit_ranges, + strike->num_ranges, + TT_SBit_Range ) ) { + goto Exit; + } + + /* read each range */ + if ( FILE_Seek( table_base + strike->ranges_offset ) || + ACCESS_Frame( strike->num_ranges * 8L ) ) { + goto Exit; + } + + range = strike->sbit_ranges; + while ( count2 > 0 ) + { + range->first_glyph = GET_UShort(); + range->last_glyph = GET_UShort(); + range->table_offset = table_base + strike->ranges_offset + + GET_ULong(); + count2--; + range++; + } + + FORGET_Frame(); + + /* Now, read each index table */ + count2 = strike->num_ranges; + range = strike->sbit_ranges; + while ( count2 > 0 ) + { + /* Read the header */ + if ( FILE_Seek( range->table_offset ) || + ACCESS_Frame( 8L ) ) { + goto Exit; + } + + range->index_format = GET_UShort(); + range->image_format = GET_UShort(); + range->image_offset = GET_ULong(); + + FORGET_Frame(); + + error = Load_SBit_Range( range, stream ); + if ( error ) { + goto Exit; + } + + count2--; + range++; + } + + count--; + strike++; + } + } + +Exit: + return error; +} + + +/*************************************************************************/ +/* */ +/* */ +/* TT_Free_SBit_Strikes */ +/* */ +/* */ +/* Releases the embedded bitmap tables. */ +/* */ +/* */ +/* face :: The target face object. */ +/* */ +LOCAL_FUNC +void TT_Free_SBit_Strikes( TT_Face face ) { + FT_Memory memory = face->root.memory; + TT_SBit_Strike* strike = face->sbit_strikes; + TT_SBit_Strike* strike_limit = strike + face->num_sbit_strikes; + + + if ( strike ) { + for ( ; strike < strike_limit; strike++ ) + { + TT_SBit_Range* range = strike->sbit_ranges; + TT_SBit_Range* range_limit = range + strike->num_ranges; + + + if ( range ) { + for ( ; range < range_limit; range++ ) + { + /* release the glyph offsets and codes tables */ + /* where appropriate */ + FREE( range->glyph_offsets ); + FREE( range->glyph_codes ); + } + } + FREE( strike->sbit_ranges ); + strike->num_ranges = 0; + } + FREE( face->sbit_strikes ); + } + face->num_sbit_strikes = 0; +} + + +/*************************************************************************/ +/* */ +/* */ +/* Find_SBit_Range */ +/* */ +/* */ +/* Scans a given strike's ranges and return, for a given glyph */ +/* index, the corresponding sbit range, and `EBDT' offset. */ +/* */ +/* */ +/* glyph_index :: The glyph index. */ +/* strike :: The source/current sbit strike. */ +/* */ +/* */ +/* arange :: The sbit range containing the glyph index. */ +/* aglyph_offset :: The offset of the glyph data in `EBDT' table. */ +/* */ +/* */ +/* FreeType error code. 0 means the glyph index was found. */ +/* */ +static +FT_Error Find_SBit_Range( FT_UInt glyph_index, + TT_SBit_Strike* strike, + TT_SBit_Range** arange, + FT_ULong* aglyph_offset ) { + TT_SBit_Range *range, *range_limit; + + + /* check whether the glyph index is within this strike's */ + /* glyph range */ + if ( glyph_index < strike->start_glyph || + glyph_index > strike->end_glyph ) { + goto Fail; + } + + /* scan all ranges in strike */ + range = strike->sbit_ranges; + range_limit = range + strike->num_ranges; + if ( !range ) { + goto Fail; + } + + for ( ; range < range_limit; range++ ) + { + if ( glyph_index >= range->first_glyph && + glyph_index <= range->last_glyph ) { + FT_UShort delta = glyph_index - range->first_glyph; + + + switch ( range->index_format ) + { + case 1: + case 3: + *aglyph_offset = range->glyph_offsets[delta]; + break; + + case 2: + *aglyph_offset = range->image_offset + + range->image_size * delta; + break; + + case 4: + case 5: + { + FT_ULong n; + + + for ( n = 0; n < range->num_glyphs; n++ ) + { + if ( range->glyph_codes[n] == glyph_index ) { + if ( range->index_format == 4 ) { + *aglyph_offset = range->glyph_offsets[n]; + } else { + *aglyph_offset = range->image_offset + + n * range->image_size; + } + goto Found; + } + } + } + + /* fall-through */ + default: + goto Fail; + } + +Found: + /* return successfully! */ + *arange = range; + return 0; + } + } + +Fail: + *arange = 0; + *aglyph_offset = 0; + + return TT_Err_Invalid_Argument; +} + + +/*************************************************************************/ +/* */ +/* */ +/* Find_SBit_Image */ +/* */ +/* */ +/* Checks whether an embedded bitmap (an `sbit') exists for a given */ +/* glyph, at given x and y ppems. */ +/* */ +/* */ +/* face :: The target face object. */ +/* glyph_index :: The glyph index. */ +/* x_ppem :: The horizontal resolution in points per EM. */ +/* y_ppem :: The vertical resolution in points per EM. */ +/* */ +/* */ +/* arange :: The SBit range containing the glyph index. */ +/* astrike :: The SBit strike containing the glyph index. */ +/* aglyph_offset :: The offset of the glyph data in `EBDT' table. */ +/* */ +/* */ +/* FreeType error code. 0 means success. Returns */ +/* TT_Err_Invalid_Argument if no sbit exists for the requested glyph. */ +/* */ +static +FT_Error Find_SBit_Image( TT_Face face, + FT_UInt glyph_index, + FT_Int x_ppem, + FT_Int y_ppem, + + TT_SBit_Range** arange, + TT_SBit_Strike** astrike, + FT_ULong* aglyph_offset ) { + TT_SBit_Strike* strike = face->sbit_strikes; + TT_SBit_Strike* strike_limit = strike + face->num_sbit_strikes; + + + if ( !strike ) { + goto Fail; + } + + for ( ; strike < strike_limit; strike++ ) + { + if ( strike->x_ppem == x_ppem && strike->y_ppem == y_ppem ) { + FT_Error error; + + + error = Find_SBit_Range( glyph_index, strike, + arange, aglyph_offset ); + if ( error ) { + goto Fail; + } + + *astrike = strike; + + return TT_Err_Ok; + } + } + +Fail: + /* no embedded bitmap for this glyph in face */ + *arange = 0; + *astrike = 0; + *aglyph_offset = 0; + + return TT_Err_Invalid_Argument; +} + + +/*************************************************************************/ +/* */ +/* */ +/* Load_SBit_Metrics */ +/* */ +/* */ +/* Gets the big metrics for a given SBit. */ +/* */ +/* */ +/* stream :: The input stream. */ +/* */ +/* range :: The SBit range containing the glyph. */ +/* */ +/* */ +/* big_metrics :: A big SBit metrics structure for the glyph. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +/* */ +/* The stream cursor must be positioned at the glyph's offset within */ +/* the `EBDT' table before the call. */ +/* */ +/* If the image format uses variable metrics, the stream cursor is */ +/* positioned just after the metrics header in the `EBDT' table on */ +/* function exit. */ +/* */ +static +FT_Error Load_SBit_Metrics( FT_Stream stream, + TT_SBit_Range* range, + TT_SBit_Metrics* metrics ) { + FT_Error error = TT_Err_Ok; + + + switch ( range->image_format ) + { + case 1: + case 2: + case 8: + /* variable small metrics */ + { + TT_SBit_Small_Metrics smetrics; + + const FT_Frame_Field sbit_small_metrics_fields[] = + { + FT_FRAME_START( 5 ), + FT_FRAME_BYTE( TT_SBit_Small_Metrics, height ), + FT_FRAME_BYTE( TT_SBit_Small_Metrics, width ), + FT_FRAME_CHAR( TT_SBit_Small_Metrics, bearingX ), + FT_FRAME_CHAR( TT_SBit_Small_Metrics, bearingY ), + FT_FRAME_BYTE( TT_SBit_Small_Metrics, advance ), + FT_FRAME_END + }; + + + /* read small metrics */ + if ( READ_Fields( sbit_small_metrics_fields, &smetrics ) ) { + goto Exit; + } + + /* convert it to a big metrics */ + metrics->height = smetrics.height; + metrics->width = smetrics.width; + metrics->horiBearingX = smetrics.bearingX; + metrics->horiBearingY = smetrics.bearingY; + metrics->horiAdvance = smetrics.advance; + + /* these metrics are made up at a higher level when */ + /* needed. */ + metrics->vertBearingX = 0; + metrics->vertBearingY = 0; + metrics->vertAdvance = 0; + } + break; + + case 6: + case 7: + case 9: + /* variable big metrics */ + (void)READ_Fields( sbit_metrics_fields, metrics ); + break; + + case 5: + default: /* constant metrics */ + if ( range->index_format == 2 || range->index_format == 5 ) { + *metrics = range->metrics; + } else { + return TT_Err_Invalid_File_Format; + } + } + +Exit: + return error; +} + + +/*************************************************************************/ +/* */ +/* */ +/* Crop_Bitmap */ +/* */ +/* */ +/* Crops a bitmap to its tightest bounding box, and adjusts its */ +/* metrics. */ +/* */ +/* */ +/* image :: The input glyph slot. */ +/* */ +/* metrics :: The corresponding metrics structure. */ +/* */ +static +void Crop_Bitmap( FT_Bitmap* map, + TT_SBit_Metrics* metrics ) { + /***********************************************************************/ + /* */ + /* In this situation, some bounding boxes of embedded bitmaps are too */ + /* large. We need to crop it to a reasonable size. */ + /* */ + /* --------- */ + /* | | ----- */ + /* | *** | |***| */ + /* | * | | * | */ + /* | * | ------> | * | */ + /* | * | | * | */ + /* | * | | * | */ + /* | *** | |***| */ + /* --------- ----- */ + /* */ + /***********************************************************************/ + + FT_Int rows, count; + FT_Long line_len; + FT_Byte* line; + + + /***********************************************************************/ + /* */ + /* first of all, check the top-most lines of the bitmap, and remove */ + /* them if they're empty. */ + /* */ + { + line = (FT_Byte*)map->buffer; + rows = map->rows; + line_len = map->pitch; + + + for ( count = 0; count < rows; count++ ) + { + FT_Byte* cur = line; + FT_Byte* limit = line + line_len; + + + for ( ; cur < limit; cur++ ) + if ( cur[0] ) { + goto Found_Top; + } + + /* the current line was empty - skip to next one */ + line = limit; + } + +Found_Top: + /* check that we have at least one filled line */ + if ( count >= rows ) { + goto Empty_Bitmap; + } + + /* now, crop the empty upper lines */ + if ( count > 0 ) { + line = (FT_Byte*)map->buffer; + + MEM_Move( line, line + count * line_len, + ( rows - count ) * line_len ); + + metrics->height -= count; + metrics->horiBearingY -= count; + metrics->vertBearingY -= count; + + map->rows -= count; + rows -= count; + } + } + + /***********************************************************************/ + /* */ + /* second, crop the lower lines */ + /* */ + { + line = (FT_Byte*)map->buffer + ( rows - 1 ) * line_len; + + for ( count = 0; count < rows; count++ ) + { + FT_Byte* cur = line; + FT_Byte* limit = line + line_len; + + + for ( ; cur < limit; cur++ ) + if ( cur[0] ) { + goto Found_Bottom; + } + + /* the current line was empty - skip to previous one */ + line -= line_len; + } + +Found_Bottom: + if ( count > 0 ) { + metrics->height -= count; + rows -= count; + map->rows -= count; + } + } + + /***********************************************************************/ + /* */ + /* third, get rid of the space on the left side of the glyph */ + /* */ + do + { + FT_Byte* limit; + + + line = (FT_Byte*)map->buffer; + limit = line + rows * line_len; + + for ( ; line < limit; line += line_len ) + if ( line[0] & 0x80 ) { + goto Found_Left; + } + + /* shift the whole glyph one pixel to the left */ + line = (FT_Byte*)map->buffer; + limit = line + rows * line_len; + + for ( ; line < limit; line += line_len ) + { + FT_Int n, width = map->width; + FT_Byte old; + FT_Byte* cur = line; + + + old = cur[0] << 1; + for ( n = 8; n < width; n += 8 ) + { + FT_Byte val; + + + val = cur[1]; + cur[0] = old | ( val >> 7 ); + old = val << 1; + cur++; + } + cur[0] = old; + } + + map->width--; + metrics->horiBearingX++; + metrics->vertBearingX++; + metrics->width--; + + } while ( map->width > 0 ); + +Found_Left: + + /***********************************************************************/ + /* */ + /* finally, crop the bitmap width to get rid of the space on the right */ + /* side of the glyph. */ + /* */ + do + { + FT_Int right = map->width - 1; + FT_Byte* limit; + FT_Byte mask; + + + line = (FT_Byte*)map->buffer + ( right >> 3 ); + limit = line + rows * line_len; + mask = 0x80 >> ( right & 7 ); + + for ( ; line < limit; line += line_len ) + if ( line[0] & mask ) { + goto Found_Right; + } + + /* crop the whole glyph to the right */ + map->width--; + metrics->width--; + + } while ( map->width > 0 ); + +Found_Right: + /* all right, the bitmap was cropped */ + return; + +Empty_Bitmap: + map->width = 0; + map->rows = 0; + map->pitch = 0; + map->pixel_mode = ft_pixel_mode_mono; +} + + +static +FT_Error Load_SBit_Single( FT_Bitmap* map, + FT_Int x_offset, + FT_Int y_offset, + FT_Int pix_bits, + FT_UShort image_format, + TT_SBit_Metrics* metrics, + FT_Stream stream ) { + FT_Error error; + + + /* check that the source bitmap fits into the target pixmap */ + if ( x_offset < 0 || x_offset + metrics->width > map->width || + y_offset < 0 || y_offset + metrics->height > map->rows ) { + error = TT_Err_Invalid_Argument; + + goto Exit; + } + + { + FT_Int glyph_width = metrics->width; + FT_Int glyph_height = metrics->height; + FT_Int glyph_size; + FT_Int line_bits = pix_bits * glyph_width; + FT_Bool pad_bytes = 0; + + + /* compute size of glyph image */ + switch ( image_format ) + { + case 1: /* byte-padded formats */ + case 6: + { + FT_Int line_length; + + + switch ( pix_bits ) + { + case 1: line_length = ( glyph_width + 7 ) >> 3; break; + case 2: line_length = ( glyph_width + 3 ) >> 2; break; + case 4: line_length = ( glyph_width + 1 ) >> 1; break; + default: line_length = glyph_width; + } + + glyph_size = glyph_height * line_length; + pad_bytes = 1; + } + break; + + case 2: + case 5: + case 7: + line_bits = glyph_width * pix_bits; + glyph_size = ( glyph_height * line_bits + 7 ) >> 3; + break; + + default: /* invalid format */ + return TT_Err_Invalid_File_Format; + } + + /* Now read data and draw glyph into target pixmap */ + if ( ACCESS_Frame( glyph_size ) ) { + goto Exit; + } + + /* don't forget to multiply `x_offset' by `map->pix_bits' as */ + /* the sbit blitter doesn't make a difference between pixmap */ + /* depths. */ + blit_sbit( map, (FT_Byte*)stream->cursor, line_bits, pad_bytes, + x_offset * pix_bits, y_offset ); + + FORGET_Frame(); + } + +Exit: + return error; +} + + +static +FT_Error Load_SBit_Image( TT_SBit_Strike* strike, + TT_SBit_Range* range, + FT_ULong ebdt_pos, + FT_ULong glyph_offset, + FT_Bitmap* map, + FT_Int x_offset, + FT_Int y_offset, + FT_Stream stream, + TT_SBit_Metrics* metrics ) { + FT_Memory memory = stream->memory; + FT_Error error; + + + /* place stream at beginning of glyph data and read metrics */ + if ( FILE_Seek( ebdt_pos + glyph_offset ) ) { + goto Exit; + } + + error = Load_SBit_Metrics( stream, range, metrics ); + if ( error ) { + goto Exit; + } + + /* this function is recursive. At the top-level call, the */ + /* field map.buffer is NULL. We thus begin by finding the */ + /* dimensions of the higher-level glyph to allocate the */ + /* final pixmap buffer */ + if ( map->buffer == 0 ) { + FT_Long size; + + + map->width = metrics->width; + map->rows = metrics->height; + + switch ( strike->bit_depth ) + { + case 1: + map->pixel_mode = ft_pixel_mode_mono; + map->pitch = ( map->width + 7 ) >> 3; + break; + + case 2: + map->pixel_mode = ft_pixel_mode_pal2; + map->pitch = ( map->width + 3 ) >> 2; + break; + + case 4: + map->pixel_mode = ft_pixel_mode_pal4; + map->pitch = ( map->width + 1 ) >> 1; + break; + + case 8: + map->pixel_mode = ft_pixel_mode_grays; + map->pitch = map->width; + break; + + default: + return TT_Err_Invalid_File_Format; + } + + size = map->rows * map->pitch; + + /* check that there is no empty image */ + if ( size == 0 ) { + goto Exit; /* exit successfully! */ + + } + if ( ALLOC( map->buffer, size ) ) { + goto Exit; + } + } + + switch ( range->image_format ) + { + case 1: /* single sbit image - load it */ + case 2: + case 5: + case 6: + case 7: + return Load_SBit_Single( map, x_offset, y_offset, strike->bit_depth, + range->image_format, metrics, stream ); + + case 8: /* compound format */ + FT_Skip_Stream( stream, 1L ); + /* fallthrough */ + + case 9: + break; + + default: /* invalid image format */ + return TT_Err_Invalid_File_Format; + } + + /* All right, we have a compound format. First of all, read */ + /* the array of elements. */ + { + TT_SBit_Component* components; + TT_SBit_Component* comp; + FT_UShort num_components, count; + + + if ( READ_UShort( num_components ) || + ALLOC_ARRAY( components, num_components, TT_SBit_Component ) ) { + goto Exit; + } + + count = num_components; + + if ( ACCESS_Frame( 4L * num_components ) ) { + goto Fail_Memory; + } + + for ( comp = components; count > 0; count--, comp++ ) + { + comp->glyph_code = GET_UShort(); + comp->x_offset = GET_Char(); + comp->y_offset = GET_Char(); + } + + FORGET_Frame(); + + /* Now recursively load each element glyph */ + count = num_components; + comp = components; + for ( ; count > 0; count--, comp++ ) + { + TT_SBit_Range* elem_range; + TT_SBit_Metrics elem_metrics; + FT_ULong elem_offset; + + + /* find the range for this element */ + error = Find_SBit_Range( comp->glyph_code, + strike, + &elem_range, + &elem_offset ); + if ( error ) { + goto Fail_Memory; + } + + /* now load the element, recursively */ + error = Load_SBit_Image( strike, + elem_range, + ebdt_pos, + elem_offset, + map, + x_offset + comp->x_offset, + y_offset + comp->y_offset, + stream, + &elem_metrics ); + if ( error ) { + goto Fail_Memory; + } + } + +Fail_Memory: + FREE( components ); + } + +Exit: + return error; +} + + +/*************************************************************************/ +/* */ +/* */ +/* TT_Load_SBit_Image */ +/* */ +/* */ +/* Loads a given glyph sbit image from the font resource. This also */ +/* returns its metrics. */ +/* */ +/* */ +/* face :: The target face object. */ +/* */ +/* x_ppem :: The horizontal resolution in points per EM. */ +/* */ +/* y_ppem :: The vertical resolution in points per EM. */ +/* */ +/* glyph_index :: The current glyph index. */ +/* */ +/* load_flags :: The glyph load flags (the code checks for the flag */ +/* FT_LOAD_CROP_BITMAP */ +/* */ +/* stream :: The input stream. */ +/* */ +/* */ +/* map :: The target pixmap. */ +/* */ +/* metrics :: A big sbit metrics structure for the glyph image. */ +/* */ +/* */ +/* FreeType error code. 0 means success. Returns an error if no */ +/* glyph sbit exists for the index. */ +/* */ +/* */ +/* The `map.buffer' field is always freed before the glyph is loaded. */ +/* */ +LOCAL_FUNC +FT_Error TT_Load_SBit_Image( TT_Face face, + FT_Int x_ppem, + FT_Int y_ppem, + FT_UInt glyph_index, + FT_UInt load_flags, + FT_Stream stream, + FT_Bitmap* map, + TT_SBit_Metrics* metrics ) { + FT_Error error; + FT_Memory memory = stream->memory; + FT_ULong ebdt_pos, glyph_offset; + + TT_SBit_Strike* strike; + TT_SBit_Range* range; + + + /* Check whether there is a glyph sbit for the current index */ + error = Find_SBit_Image( face, glyph_index, x_ppem, y_ppem, + &range, &strike, &glyph_offset ); + if ( error ) { + goto Exit; + } + + /* now, find the location of the `EBDT' table in */ + /* the font file */ + error = face->goto_table( face, TTAG_EBDT, stream, 0 ); + if ( error ) { + error = face->goto_table( face, TTAG_bdat, stream, 0 ); + } + if ( error ) { + goto Exit; + } + + ebdt_pos = FILE_Pos(); + + /* clear the bitmap & load the bitmap */ + if ( face->root.glyph->flags & ft_glyph_own_bitmap ) { + FREE( map->buffer ); + } + + map->rows = map->pitch = map->width = 0; + + error = Load_SBit_Image( strike, range, ebdt_pos, glyph_offset, + map, 0, 0, stream, metrics ); + if ( error ) { + goto Exit; + } + + /* the glyph slot owns this bitmap buffer */ + face->root.glyph->flags |= ft_glyph_own_bitmap; + + /* setup vertical metrics if needed */ + if ( strike->flags & 1 ) { + /* in case of a horizontal strike only */ + FT_Int advance; + FT_Int top; + + + advance = strike->hori.ascender - strike->hori.descender; + top = advance / 10; + + /* some heuristic values */ + + metrics->vertBearingX = -metrics->width / 2; + metrics->vertBearingY = advance / 10; + metrics->vertAdvance = advance * 12 / 10; + } + + /* Crop the bitmap now, unless specified otherwise */ + if ( load_flags & FT_LOAD_CROP_BITMAP ) { + Crop_Bitmap( map, metrics ); + } + +Exit: + return error; +} + + +/* END */ diff --git a/Projects/Android/jni/rtcw/src/ft2/ttsbit.h b/Projects/Android/jni/rtcw/src/ft2/ttsbit.h new file mode 100644 index 0000000..0b3598e --- /dev/null +++ b/Projects/Android/jni/rtcw/src/ft2/ttsbit.h @@ -0,0 +1,57 @@ +/***************************************************************************/ +/* */ +/* ttsbit.h */ +/* */ +/* TrueType and OpenType embedded bitmap support (specification). */ +/* */ +/* Copyright 1996-2000 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef TTSBIT_H +#define TTSBIT_H + + +#include "ttload.h" + + +#ifdef __cplusplus +extern "C" { +#endif + + +LOCAL_DEF +FT_Error TT_Load_SBit_Strikes( TT_Face face, + FT_Stream stream ); + +LOCAL_DEF +void TT_Free_SBit_Strikes( TT_Face face ); + +LOCAL_DEF +FT_Error TT_Load_SBit_Image( TT_Face face, + FT_Int x_ppem, + FT_Int y_ppem, + FT_UInt glyph_index, + FT_UInt load_flags, + FT_Stream stream, + FT_Bitmap* map, + TT_SBit_Metrics* metrics ); + + +#ifdef __cplusplus +} +#endif + + +#endif /* TTSBIT_H */ + + +/* END */ diff --git a/Projects/Android/jni/rtcw/src/ft2/tttables.h b/Projects/Android/jni/rtcw/src/ft2/tttables.h new file mode 100644 index 0000000..030dd8b --- /dev/null +++ b/Projects/Android/jni/rtcw/src/ft2/tttables.h @@ -0,0 +1,583 @@ +/***************************************************************************/ +/* */ +/* tttables.h */ +/* */ +/* Basic SFNT/TrueType tables definitions and interface */ +/* (specification only). */ +/* */ +/* Copyright 1996-2000 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef TTTABLES_H +#define TTTABLES_H + + +#include "freetype.h" + + +#ifdef __cplusplus +extern "C" { +#endif + + +/*************************************************************************/ +/* */ +/* */ +/* TT_Header */ +/* */ +/* */ +/* A structure used to model a TrueType font header table. All */ +/* fields follow the TrueType specification. */ +/* */ +typedef struct TT_Header_ +{ + FT_Fixed Table_Version; + FT_Fixed Font_Revision; + + FT_Long CheckSum_Adjust; + FT_Long Magic_Number; + + FT_UShort Flags; + FT_UShort Units_Per_EM; + + FT_Long Created [2]; + FT_Long Modified[2]; + + FT_Short xMin; + FT_Short yMin; + FT_Short xMax; + FT_Short yMax; + + FT_UShort Mac_Style; + FT_UShort Lowest_Rec_PPEM; + + FT_Short Font_Direction; + FT_Short Index_To_Loc_Format; + FT_Short Glyph_Data_Format; + +} TT_Header; + + +/*************************************************************************/ +/* */ +/* */ +/* TT_HoriHeader */ +/* */ +/* */ +/* A structure used to model a TrueType horizontal header, the `hhea' */ +/* table, as well as the corresponding horizontal metrics table, */ +/* i.e., the `hmtx' table. */ +/* */ +/* */ +/* Version :: The table version. */ +/* */ +/* Ascender :: The font's ascender, i.e., the distance */ +/* from the baseline to the top-most of all */ +/* glyph points found in the font. */ +/* */ +/* This value is invalid in many fonts, as */ +/* it is usually set by the font designer, */ +/* and often reflects only a portion of the */ +/* glyphs found in the font (maybe ASCII). */ +/* */ +/* You should use the `sTypoAscender' field */ +/* of the OS/2 table instead if you want */ +/* the correct one. */ +/* */ +/* Descender :: The font's descender, i.e., the distance */ +/* from the baseline to the bottom-most of */ +/* all glyph points found in the font. It */ +/* is negative. */ +/* */ +/* This value is invalid in many fonts, as */ +/* it is usually set by the font designer, */ +/* and often reflects only a portion of the */ +/* glyphs found in the font (maybe ASCII). */ +/* */ +/* You should use the `sTypoDescender' */ +/* field of the OS/2 table instead if you */ +/* want the correct one. */ +/* */ +/* Line_Gap :: The font's line gap, i.e., the distance */ +/* to add to the ascender and descender to */ +/* get the BTB, i.e., the */ +/* baseline-to-baseline distance for the */ +/* font. */ +/* */ +/* advance_Width_Max :: This field is the maximum of all advance */ +/* widths found in the font. It can be */ +/* used to compute the maximum width of an */ +/* arbitrary string of text. */ +/* */ +/* min_Left_Side_Bearing :: The minimum left side bearing of all */ +/* glyphs within the font. */ +/* */ +/* min_Right_Side_Bearing :: The minimum right side bearing of all */ +/* glyphs within the font. */ +/* */ +/* xMax_Extent :: The maximum horizontal extent (i.e., the */ +/* `width' of a glyph's bounding box) for */ +/* all glyphs in the font. */ +/* */ +/* caret_Slope_Rise :: The rise coefficient of the cursor's */ +/* slope of the cursor (slope=rise/run). */ +/* */ +/* caret_Slope_Run :: The run coefficient of the cursor's */ +/* slope. */ +/* */ +/* Reserved :: 10 reserved bytes. */ +/* */ +/* metric_Data_Format :: Always 0. */ +/* */ +/* number_Of_HMetrics :: Number of HMetrics entries in the `hmtx' */ +/* table -- this value can be smaller than */ +/* the total number of glyphs in the font. */ +/* */ +/* long_metrics :: A pointer into the `hmtx' table. */ +/* */ +/* short_metrics :: A pointer into the `hmtx' table. */ +/* */ +/* */ +/* IMPORTANT: The TT_HoriHeader and TT_VertHeader structures should */ +/* be identical except for the names of their fields which */ +/* are different. */ +/* */ +/* This ensures that a single function in the `ttload' */ +/* module is able to read both the horizontal and vertical */ +/* headers. */ +/* */ +typedef struct TT_HoriHeader_ +{ + FT_Fixed Version; + FT_Short Ascender; + FT_Short Descender; + FT_Short Line_Gap; + + FT_UShort advance_Width_Max; /* advance width maximum */ + + FT_Short min_Left_Side_Bearing; /* minimum left-sb */ + FT_Short min_Right_Side_Bearing; /* minimum right-sb */ + FT_Short xMax_Extent; /* xmax extents */ + FT_Short caret_Slope_Rise; + FT_Short caret_Slope_Run; + FT_Short caret_Offset; + + FT_Short Reserved[4]; + + FT_Short metric_Data_Format; + FT_UShort number_Of_HMetrics; + + /* The following fields are not defined by the TrueType specification */ + /* but they're used to connect the metrics header to the relevant */ + /* `HMTX' table. */ + + void* long_metrics; + void* short_metrics; + +} TT_HoriHeader; + + +/*************************************************************************/ +/* */ +/* */ +/* TT_VertHeader */ +/* */ +/* */ +/* A structure used to model a TrueType vertical header, the `vhea' */ +/* table, as well as the corresponding vertical metrics table, i.e., */ +/* the `vmtx' table. */ +/* */ +/* */ +/* Version :: The table version. */ +/* */ +/* Ascender :: The font's ascender, i.e., the distance */ +/* from the baseline to the top-most of */ +/* all glyph points found in the font. */ +/* */ +/* This value is invalid in many fonts, as */ +/* it is usually set by the font designer, */ +/* and often reflects only a portion of */ +/* the glyphs found in the font (maybe */ +/* ASCII). */ +/* */ +/* You should use the `sTypoAscender' */ +/* field of the OS/2 table instead if you */ +/* want the correct one. */ +/* */ +/* Descender :: The font's descender, i.e., the */ +/* distance from the baseline to the */ +/* bottom-most of all glyph points found */ +/* in the font. It is negative. */ +/* */ +/* This value is invalid in many fonts, as */ +/* it is usually set by the font designer, */ +/* and often reflects only a portion of */ +/* the glyphs found in the font (maybe */ +/* ASCII). */ +/* */ +/* You should use the `sTypoDescender' */ +/* field of the OS/2 table instead if you */ +/* want the correct one. */ +/* */ +/* Line_Gap :: The font's line gap, i.e., the distance */ +/* to add to the ascender and descender to */ +/* get the BTB, i.e., the */ +/* baseline-to-baseline distance for the */ +/* font. */ +/* */ +/* advance_Height_Max :: This field is the maximum of all */ +/* advance heights found in the font. It */ +/* can be used to compute the maximum */ +/* height of an arbitrary string of text. */ +/* */ +/* min_Top_Side_Bearing :: The minimum top side bearing of all */ +/* glyphs within the font. */ +/* */ +/* min_Bottom_Side_Bearing :: The minimum bottom side bearing of all */ +/* glyphs within the font. */ +/* */ +/* yMax_Extent :: The maximum vertical extent (i.e., the */ +/* `height' of a glyph's bounding box) for */ +/* all glyphs in the font. */ +/* */ +/* caret_Slope_Rise :: The rise coefficient of the cursor's */ +/* slope of the cursor (slope=rise/run). */ +/* */ +/* caret_Slope_Run :: The run coefficient of the cursor's */ +/* slope. */ +/* */ +/* Reserved :: 10 reserved bytes. */ +/* */ +/* metric_Data_Format :: Always 0. */ +/* */ +/* number_Of_HMetrics :: Number of VMetrics entries in the */ +/* `vmtx' table -- this value can be */ +/* smaller than the total number of glyphs */ +/* in the font. */ +/* */ +/* long_metrics :: A pointer into the `vmtx' table. */ +/* */ +/* short_metrics :: A pointer into the `vmtx' table. */ +/* */ +/* */ +/* IMPORTANT: The TT_HoriHeader and TT_VertHeader structures should */ +/* be identical except for the names of their fields which */ +/* are different. */ +/* */ +/* This ensures that a single function in the `ttload' */ +/* module is able to read both the horizontal and vertical */ +/* headers. */ +/* */ +typedef struct TT_VertHeader_ +{ + FT_Fixed Version; + FT_Short Ascender; + FT_Short Descender; + FT_Short Line_Gap; + + FT_UShort advance_Height_Max; /* advance height maximum */ + + FT_Short min_Top_Side_Bearing; /* minimum left-sb or top-sb */ + FT_Short min_Bottom_Side_Bearing; /* minimum right-sb or bottom-sb */ + FT_Short yMax_Extent; /* xmax or ymax extents */ + FT_Short caret_Slope_Rise; + FT_Short caret_Slope_Run; + FT_Short caret_Offset; + + FT_Short Reserved[4]; + + FT_Short metric_Data_Format; + FT_UShort number_Of_VMetrics; + + /* The following fields are not defined by the TrueType specification */ + /* but they're used to connect the metrics header to the relevant */ + /* `HMTX' or `VMTX' table. */ + + void* long_metrics; + void* short_metrics; + +} TT_VertHeader; + + +/*************************************************************************/ +/* */ +/* */ +/* TT_OS2 */ +/* */ +/* */ +/* A structure used to model a TrueType OS/2 table. This is the long */ +/* table version. All fields comply to the TrueType specification. */ +/* */ +/* Note that we now support old Mac fonts which do not include an */ +/* OS/2 table. In this case, the `version' field is always set to */ +/* 0xFFFF. */ +/* */ +typedef struct TT_OS2_ +{ + FT_UShort version; /* 0x0001 - more or 0xFFFF */ + FT_Short xAvgCharWidth; + FT_UShort usWeightClass; + FT_UShort usWidthClass; + FT_Short fsType; + FT_Short ySubscriptXSize; + FT_Short ySubscriptYSize; + FT_Short ySubscriptXOffset; + FT_Short ySubscriptYOffset; + FT_Short ySuperscriptXSize; + FT_Short ySuperscriptYSize; + FT_Short ySuperscriptXOffset; + FT_Short ySuperscriptYOffset; + FT_Short yStrikeoutSize; + FT_Short yStrikeoutPosition; + FT_Short sFamilyClass; + + FT_Byte panose[10]; + + FT_ULong ulUnicodeRange1; /* Bits 0-31 */ + FT_ULong ulUnicodeRange2; /* Bits 32-63 */ + FT_ULong ulUnicodeRange3; /* Bits 64-95 */ + FT_ULong ulUnicodeRange4; /* Bits 96-127 */ + + FT_Char achVendID[4]; + + FT_UShort fsSelection; + FT_UShort usFirstCharIndex; + FT_UShort usLastCharIndex; + FT_Short sTypoAscender; + FT_Short sTypoDescender; + FT_Short sTypoLineGap; + FT_UShort usWinAscent; + FT_UShort usWinDescent; + + /* only version 1 tables: */ + + FT_ULong ulCodePageRange1; /* Bits 0-31 */ + FT_ULong ulCodePageRange2; /* Bits 32-63 */ + + /* only version 2 tables: */ + + FT_Short sxHeight; + FT_Short sCapHeight; + FT_UShort usDefaultChar; + FT_UShort usBreakChar; + FT_UShort usMaxContext; + +} TT_OS2; + + +/*************************************************************************/ +/* */ +/* */ +/* TT_Postscript */ +/* */ +/* */ +/* A structure used to model a TrueType Postscript table. All fields */ +/* comply to the TrueType table. This structure does not reference */ +/* the Postscript glyph names, which can be nevertheless accessed */ +/* with the `ttpost' module. */ +/* */ +typedef struct TT_Postscript_ +{ + FT_Fixed FormatType; + FT_Fixed italicAngle; + FT_Short underlinePosition; + FT_Short underlineThickness; + FT_ULong isFixedPitch; + FT_ULong minMemType42; + FT_ULong maxMemType42; + FT_ULong minMemType1; + FT_ULong maxMemType1; + + /* Glyph names follow in the file, but we don't */ + /* load them by default. See the ttpost.c file. */ + +} TT_Postscript; + + +/*************************************************************************/ +/* */ +/* */ +/* TT_PCLT */ +/* */ +/* */ +/* A structure used to model a TrueType PCLT table. All fields */ +/* comply to the TrueType table. */ +/* */ +typedef struct TT_PCLT_ +{ + FT_Fixed Version; + FT_ULong FontNumber; + FT_UShort Pitch; + FT_UShort xHeight; + FT_UShort Style; + FT_UShort TypeFamily; + FT_UShort CapHeight; + FT_UShort SymbolSet; + FT_Char TypeFace[16]; + FT_Char CharacterComplement[8]; + FT_Char FileName[6]; + FT_Char StrokeWeight; + FT_Char WidthType; + FT_Byte SerifStyle; + FT_Byte Reserved; + +} TT_PCLT; + + +/*************************************************************************/ +/* */ +/* */ +/* TT_MaxProfile */ +/* */ +/* */ +/* The maximum profile is a table containing many max values which */ +/* can be used to pre-allocate arrays. This ensures that no memory */ +/* allocation occurs during a glyph load. */ +/* */ +/* */ +/* version :: The version number. */ +/* */ +/* numGlyphs :: The number of glyphs in this TrueType */ +/* font. */ +/* */ +/* maxPoints :: The maximum number of points in a */ +/* non-composite TrueType glyph. See also */ +/* the structure element */ +/* `maxCompositePoints'. */ +/* */ +/* maxContours :: The maximum number of contours in a */ +/* non-composite TrueType glyph. See also */ +/* the structure element */ +/* `maxCompositeContours'. */ +/* */ +/* maxCompositePoints :: The maximum number of points in a */ +/* composite TrueType glyph. See also the */ +/* structure element `maxPoints'. */ +/* */ +/* maxCompositeContours :: The maximum number of contours in a */ +/* composite TrueType glyph. See also the */ +/* structure element `maxContours'. */ +/* */ +/* maxZones :: The maximum number of zones used for */ +/* glyph hinting. */ +/* */ +/* maxTwilightPoints :: The maximum number of points in the */ +/* twilight zone used for glyph hinting. */ +/* */ +/* maxStorage :: The maximum number of elements in the */ +/* storage area used for glyph hinting. */ +/* */ +/* maxFunctionDefs :: The maximum number of function */ +/* definitions in the TrueType bytecode for */ +/* this font. */ +/* */ +/* maxInstructionDefs :: The maximum number of instruction */ +/* definitions in the TrueType bytecode for */ +/* this font. */ +/* */ +/* maxStackElements :: The maximum number of stack elements used */ +/* during bytecode interpretation. */ +/* */ +/* maxSizeOfInstructions :: The maximum number of TrueType opcodes */ +/* used for glyph hinting. */ +/* */ +/* maxComponentElements :: An obscure value related to composite */ +/* glyphs definitions. */ +/* */ +/* maxComponentDepth :: An obscure value related to composite */ +/* glyphs definitions. Probably the maximum */ +/* number of simple glyphs in a composite. */ +/* */ +/* */ +/* This structure is only used during font loading. */ +/* */ +typedef struct TT_MaxProfile_ +{ + FT_Fixed version; + FT_UShort numGlyphs; + FT_UShort maxPoints; + FT_UShort maxContours; + FT_UShort maxCompositePoints; + FT_UShort maxCompositeContours; + FT_UShort maxZones; + FT_UShort maxTwilightPoints; + FT_UShort maxStorage; + FT_UShort maxFunctionDefs; + FT_UShort maxInstructionDefs; + FT_UShort maxStackElements; + FT_UShort maxSizeOfInstructions; + FT_UShort maxComponentElements; + FT_UShort maxComponentDepth; + +} TT_MaxProfile; + + +typedef enum +{ + ft_sfnt_head = 0, + ft_sfnt_maxp = 1, + ft_sfnt_os2 = 2, + ft_sfnt_hhea = 3, + ft_sfnt_vhea = 4, + ft_sfnt_post = 5, + ft_sfnt_pclt = 6, + + sfnt_max /* don't remove */ + +} FT_Sfnt_Tag; + + +/* internal use only */ +typedef void* ( *FT_Get_Sfnt_Table_Func )( FT_Face face, + FT_Sfnt_Tag tag ); + + +/*************************************************************************/ +/* */ +/* */ +/* FT_Get_Sfnt_Table */ +/* */ +/* */ +/* Returns a pointer to a given SFNT table within a face. */ +/* */ +/* */ +/* face :: A handle to the source. */ +/* */ +/* tag :: The index of the SFNT table. */ +/* */ +/* */ +/* A type-less pointer to the table. This will be 0 in case of */ +/* error, or if the corresponding table was not found *OR* loaded */ +/* from the file. */ +/* */ +/* */ +/* The table is owned by the face object and disappears with it. */ +/* */ +/* This function is only useful to access SFNT tables that are loaded */ +/* by the sfnt/truetype/opentype drivers. See FT_Sfnt_tag for a */ +/* list. */ +/* */ +/* You can load any table using the (internal) SFNT_Interface */ +/* structure -- this is available via FT_Get_Module_Interface(). */ +/* */ +FT_EXPORT_DEF( void* ) FT_Get_Sfnt_Table( FT_Face face, + FT_Sfnt_Tag tag ); + +#ifdef __cplusplus +} +#endif + + +#endif /* TTTABLES_H */ + + +/* END */ diff --git a/Projects/Android/jni/rtcw/src/ft2/tttags.h b/Projects/Android/jni/rtcw/src/ft2/tttags.h new file mode 100644 index 0000000..12e19fa --- /dev/null +++ b/Projects/Android/jni/rtcw/src/ft2/tttags.h @@ -0,0 +1,66 @@ +/***************************************************************************/ +/* */ +/* tttags.h */ +/* */ +/* Tags for TrueType tables (specification only). */ +/* */ +/* Copyright 1996-2000 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef TTAGS_H +#define TTAGS_H + + +#include "freetype.h" + + +#define TTAG_cmap FT_MAKE_TAG( 'c', 'm', 'a', 'p' ) +#define TTAG_cvt FT_MAKE_TAG( 'c', 'v', 't', ' ' ) +#define TTAG_CFF FT_MAKE_TAG( 'C', 'F', 'F', ' ' ) +#define TTAG_DSIG FT_MAKE_TAG( 'D', 'S', 'I', 'G' ) +#define TTAG_bdat FT_MAKE_TAG( 'b', 'd', 'a', 't' ) +#define TTAG_bloc FT_MAKE_TAG( 'b', 'l', 'o', 'c' ) +#define TTAG_EBDT FT_MAKE_TAG( 'E', 'B', 'D', 'T' ) +#define TTAG_EBLC FT_MAKE_TAG( 'E', 'B', 'L', 'C' ) +#define TTAG_EBSC FT_MAKE_TAG( 'E', 'B', 'S', 'C' ) +#define TTAG_fpgm FT_MAKE_TAG( 'f', 'p', 'g', 'm' ) +#define TTAG_fvar FT_MAKE_TAG( 'f', 'v', 'a', 'r' ) +#define TTAG_gasp FT_MAKE_TAG( 'g', 'a', 's', 'p' ) +#define TTAG_glyf FT_MAKE_TAG( 'g', 'l', 'y', 'f' ) +#define TTAG_GSUB FT_MAKE_TAG( 'G', 'S', 'U', 'B' ) +#define TTAG_hdmx FT_MAKE_TAG( 'h', 'd', 'm', 'x' ) +#define TTAG_head FT_MAKE_TAG( 'h', 'e', 'a', 'd' ) +#define TTAG_hhea FT_MAKE_TAG( 'h', 'h', 'e', 'a' ) +#define TTAG_hmtx FT_MAKE_TAG( 'h', 'm', 't', 'x' ) +#define TTAG_kern FT_MAKE_TAG( 'k', 'e', 'r', 'n' ) +#define TTAG_loca FT_MAKE_TAG( 'l', 'o', 'c', 'a' ) +#define TTAG_LTSH FT_MAKE_TAG( 'L', 'T', 'S', 'H' ) +#define TTAG_maxp FT_MAKE_TAG( 'm', 'a', 'x', 'p' ) +#define TTAG_MMSD FT_MAKE_TAG( 'M', 'M', 'S', 'D' ) +#define TTAG_MMFX FT_MAKE_TAG( 'M', 'M', 'F', 'X' ) +#define TTAG_name FT_MAKE_TAG( 'n', 'a', 'm', 'e' ) +#define TTAG_OS2 FT_MAKE_TAG( 'O', 'S', '/', '2' ) +#define TTAG_OTTO FT_MAKE_TAG( 'O', 'T', 'T', 'O' ) +#define TTAG_PCLT FT_MAKE_TAG( 'P', 'C', 'L', 'T' ) +#define TTAG_post FT_MAKE_TAG( 'p', 'o', 's', 't' ) +#define TTAG_prep FT_MAKE_TAG( 'p', 'r', 'e', 'p' ) +#define TTAG_true FT_MAKE_TAG( 't', 'r', 'u', 'e' ) +#define TTAG_ttc FT_MAKE_TAG( 't', 't', 'c', ' ' ) +#define TTAG_ttcf FT_MAKE_TAG( 't', 't', 'c', 'f' ) +#define TTAG_VDMX FT_MAKE_TAG( 'V', 'D', 'M', 'X' ) +#define TTAG_vhea FT_MAKE_TAG( 'v', 'h', 'e', 'a' ) +#define TTAG_vmtx FT_MAKE_TAG( 'v', 'm', 't', 'x' ) + +#endif /* TTAGS_H */ + + +/* END */ diff --git a/Projects/Android/jni/rtcw/src/ft2/tttypes.h b/Projects/Android/jni/rtcw/src/ft2/tttypes.h new file mode 100644 index 0000000..b22b381 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/ft2/tttypes.h @@ -0,0 +1,1582 @@ +/***************************************************************************/ +/* */ +/* tttypes.h */ +/* */ +/* Basic SFNT/TrueType type definitions and interface (specification */ +/* only). */ +/* */ +/* Copyright 1996-2000 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef TTTYPES_H +#define TTTYPES_H + + +#include "tttables.h" + + +/*************************************************************************/ +/*************************************************************************/ +/*************************************************************************/ +/*** ***/ +/*** ***/ +/*** REQUIRED TRUETYPE/OPENTYPE TABLES DEFINITIONS ***/ +/*** ***/ +/*** ***/ +/*************************************************************************/ +/*************************************************************************/ +/*************************************************************************/ + + +/*************************************************************************/ +/* */ +/* */ +/* TTC_Header */ +/* */ +/* */ +/* TrueType collection header. This table contains the offsets of */ +/* the font headers of each distinct TrueType face in the file. */ +/* */ +/* */ +/* tag :: Must be `ttc ' to indicate a TrueType collection. */ +/* */ +/* version :: The version number. */ +/* */ +/* count :: The number of faces in the collection. The */ +/* specification says this should be an unsigned long, but */ +/* we use a signed long since we need the value -1 for */ +/* specific purposes. */ +/* */ +/* offsets :: The offsets of the font headers, one per face. */ +/* */ +typedef struct TTC_Header_ +{ + FT_ULong tag; + FT_Fixed version; + FT_Long count; + FT_ULong* offsets; + +} TTC_Header; + + +/*************************************************************************/ +/* */ +/* */ +/* SFNT_Header */ +/* */ +/* */ +/* SFNT file format header. */ +/* */ +/* */ +/* format_tag :: The font format tag. */ +/* */ +/* num_tables :: The number of tables in file. */ +/* */ +/* search_range :: Must be 16*(max power of 2 <= num_tables). */ +/* */ +/* entry_selector :: Must be log2 of search_range/16. */ +/* */ +/* range_shift :: Must be num_tables*16 - search_range. */ +/* */ +typedef struct SFNT_Header_ +{ + FT_ULong format_tag; + FT_UShort num_tables; + FT_UShort search_range; + FT_UShort entry_selector; + FT_UShort range_shift; + +} SFNT_Header; + + +/*************************************************************************/ +/* */ +/* */ +/* TT_TableDir */ +/* */ +/* */ +/* This structure models a TrueType table directory. It is used to */ +/* access the various tables of the font face. */ +/* */ +/* */ +/* version :: The version number; starts with 0x00010000. */ +/* */ +/* numTables :: The number of tables. */ +/* */ +/* searchRange :: Unused. */ +/* */ +/* entrySelector :: Unused. */ +/* */ +/* rangeShift :: Unused. */ +/* */ +/* */ +/* This structure is only used during font opening. */ +/* */ +typedef struct TT_TableDir_ +{ + FT_Fixed version; /* should be 0x10000 */ + FT_UShort numTables; /* number of tables */ + + FT_UShort searchRange; /* These parameters are only used */ + FT_UShort entrySelector; /* for a dichotomy search in the */ + FT_UShort rangeShift; /* directory. We ignore them. */ + +} TT_TableDir; + + +/*************************************************************************/ +/* */ +/* */ +/* TT_Table */ +/* */ +/* */ +/* This structure describes a given table of a TrueType font. */ +/* */ +/* */ +/* Tag :: A four-bytes tag describing the table. */ +/* */ +/* CheckSum :: The table checksum. This value can be ignored. */ +/* */ +/* Offset :: The offset of the table from the start of the TrueType */ +/* font in its resource. */ +/* */ +/* Length :: The table length (in bytes). */ +/* */ +typedef struct TT_Table_ +{ + FT_ULong Tag; /* table type */ + FT_ULong CheckSum; /* table checksum */ + FT_ULong Offset; /* table file offset */ + FT_ULong Length; /* table length */ + +} TT_Table; + + +/*************************************************************************/ +/* */ +/* */ +/* TT_CMapDir */ +/* */ +/* */ +/* This structure describes the directory of the `cmap' table, */ +/* containing the font's character mappings table. */ +/* */ +/* */ +/* tableVersionNumber :: The version number. */ +/* */ +/* numCMaps :: The number of charmaps in the font. */ +/* */ +/* */ +/* This structure is only used during font loading. */ +/* */ +typedef struct TT_CMapDir_ +{ + FT_UShort tableVersionNumber; + FT_UShort numCMaps; + +} TT_CMapDir; + + +/*************************************************************************/ +/* */ +/* */ +/* TT_CMapDirEntry */ +/* */ +/* */ +/* This structure describes a charmap in a TrueType font. */ +/* */ +/* */ +/* platformID :: An ID used to specify for which platform this */ +/* charmap is defined (FreeType manages all platforms). */ +/* */ +/* encodingID :: A platform-specific ID used to indicate which source */ +/* encoding is used in this charmap. */ +/* */ +/* offset :: The offset of the charmap relative to the start of */ +/* the `cmap' table. */ +/* */ +/* */ +/* This structure is only used during font loading. */ +/* */ +typedef struct TT_CMapDirEntry_ +{ + FT_UShort platformID; + FT_UShort platformEncodingID; + FT_Long offset; + +} TT_CMapDirEntry; + + +/*************************************************************************/ +/* */ +/* */ +/* TT_LongMetrics */ +/* */ +/* */ +/* A structure modeling the long metrics of the `hmtx' and `vmtx' */ +/* TrueType tables. The values are expressed in font units. */ +/* */ +/* */ +/* advance :: The advance width or height for the glyph. */ +/* */ +/* bearing :: The left-side or top-side bearing for the glyph. */ +/* */ +typedef struct TT_LongMetrics_ +{ + FT_UShort advance; + FT_Short bearing; + +} TT_LongMetrics; + + +/*************************************************************************/ +/* */ +/* TT_ShortMetrics */ +/* */ +/* */ +/* A simple type to model the short metrics of the `hmtx' and `vmtx' */ +/* tables. */ +/* */ +typedef FT_Short TT_ShortMetrics; + + +/*************************************************************************/ +/* */ +/* */ +/* TT_NameRec */ +/* */ +/* */ +/* A structure modeling TrueType name records. Name records are used */ +/* to store important strings like family name, style name, */ +/* copyright, etc. in _localized_ versions (i.e., language, encoding, */ +/* etc). */ +/* */ +/* */ +/* platformID :: The ID of the name's encoding platform. */ +/* */ +/* encodingID :: The platform-specific ID for the name's encoding. */ +/* */ +/* languageID :: The platform-specific ID for the name's language. */ +/* */ +/* nameID :: The ID specifying what kind of name this is. */ +/* */ +/* stringLength :: The length of the string in bytes. */ +/* */ +/* stringOffset :: The offset to the string in the `name' table. */ +/* */ +/* string :: A pointer to the string's bytes. Note that these */ +/* are usually UTF-16 encoded characters. */ +/* */ +typedef struct TT_NameRec_ +{ + FT_UShort platformID; + FT_UShort encodingID; + FT_UShort languageID; + FT_UShort nameID; + FT_UShort stringLength; + FT_UShort stringOffset; + + /* this last field is not defined in the spec */ + /* but used by the FreeType engine */ + + FT_Byte* string; + +} TT_NameRec; + + +/*************************************************************************/ +/* */ +/* */ +/* TT_NameTable */ +/* */ +/* */ +/* A structure modeling the TrueType name table. */ +/* */ +/* */ +/* format :: The format of the name table. */ +/* */ +/* numNameRecords :: The number of names in table. */ +/* */ +/* storageOffset :: The offset of the name table in the `name' */ +/* TrueType table. */ +/* */ +/* names :: An array of name records. */ +/* */ +/* storage :: The names storage area. */ +/* */ +typedef struct TT_NameTable_ +{ + FT_UShort format; + FT_UShort numNameRecords; + FT_UShort storageOffset; + TT_NameRec* names; + FT_Byte* storage; + +} TT_NameTable; + + +/*************************************************************************/ +/*************************************************************************/ +/*************************************************************************/ +/*** ***/ +/*** ***/ +/*** OPTIONAL TRUETYPE/OPENTYPE TABLES DEFINITIONS ***/ +/*** ***/ +/*** ***/ +/*************************************************************************/ +/*************************************************************************/ +/*************************************************************************/ + + +/*************************************************************************/ +/* */ +/* */ +/* TT_GaspRange */ +/* */ +/* */ +/* A tiny structure used to model a gasp range according to the */ +/* TrueType specification. */ +/* */ +/* */ +/* maxPPEM :: The maximum ppem value to which `gaspFlag' applies. */ +/* */ +/* gaspFlag :: A flag describing the grid-fitting and anti-aliasing */ +/* modes to be used. */ +/* */ +typedef struct TT_GaspRange_ +{ + FT_UShort maxPPEM; + FT_UShort gaspFlag; + +} TT_GaspRange; + + +#define TT_GASP_GRIDFIT 0x01 +#define TT_GASP_DOGRAY 0x02 + + +/*************************************************************************/ +/* */ +/* */ +/* TT_Gasp */ +/* */ +/* */ +/* A structure modeling the TrueType `gasp' table used to specify */ +/* grid-fitting and anti-aliasing behaviour. */ +/* */ +/* */ +/* version :: The version number. */ +/* */ +/* numRanges :: The number of gasp ranges in table. */ +/* */ +/* gaspRanges :: An array of gasp ranges. */ +/* */ +typedef struct TT_Gasp_ +{ + FT_UShort version; + FT_UShort numRanges; + TT_GaspRange* gaspRanges; + +} TT_Gasp; + + +/*************************************************************************/ +/* */ +/* */ +/* TT_HdmxRec */ +/* */ +/* */ +/* A small structure used to model the pre-computed widths of a given */ +/* size. They are found in the `hdmx' table. */ +/* */ +/* */ +/* ppem :: The pixels per EM value at which these metrics apply. */ +/* */ +/* max_width :: The maximum advance width for this metric. */ +/* */ +/* widths :: An array of widths. Note: These are 8-bit bytes. */ +/* */ +typedef struct TT_HdmxRec_ +{ + FT_Byte ppem; + FT_Byte max_width; + FT_Byte* widths; + +} TT_HdmxRec; + + +/*************************************************************************/ +/* */ +/* */ +/* TT_Hdmx */ +/* */ +/* */ +/* A structure used to model the `hdmx' table, which contains */ +/* pre-computed widths for a set of given sizes/dimensions. */ +/* */ +/* */ +/* version :: The version number. */ +/* */ +/* num_records :: The number of hdmx records. */ +/* */ +/* records :: An array of hdmx records. */ +/* */ +typedef struct TT_Hdmx_ +{ + FT_UShort version; + FT_Short num_records; + TT_HdmxRec* records; + +} TT_Hdmx; + + +/*************************************************************************/ +/* */ +/* */ +/* TT_Kern_0_Pair */ +/* */ +/* */ +/* A structure used to model a kerning pair for the kerning table */ +/* format 0. The engine now loads this table if it finds one in the */ +/* font file. */ +/* */ +/* */ +/* left :: The index of the left glyph in pair. */ +/* */ +/* right :: The index of the right glyph in pair. */ +/* */ +/* value :: The kerning distance. A positive value spaces the */ +/* glyphs, a negative one makes them closer. */ +/* */ +typedef struct TT_Kern_0_Pair_ +{ + FT_UShort left; /* index of left glyph in pair */ + FT_UShort right; /* index of right glyph in pair */ + FT_FWord value; /* kerning value */ + +} TT_Kern_0_Pair; + + +/*************************************************************************/ +/*************************************************************************/ +/*************************************************************************/ +/*** ***/ +/*** ***/ +/*** EMBEDDED BITMAPS SUPPORT ***/ +/*** ***/ +/*** ***/ +/*************************************************************************/ +/*************************************************************************/ +/*************************************************************************/ + + +/*************************************************************************/ +/* */ +/* */ +/* TT_SBit_Metrics */ +/* */ +/* */ +/* A structure used to hold the big metrics of a given glyph bitmap */ +/* in a TrueType or OpenType font. These are usually found in the */ +/* `EBDT' (Microsoft) or `bdat' (Apple) table. */ +/* */ +/* */ +/* height :: The glyph height in pixels. */ +/* */ +/* width :: The glyph width in pixels. */ +/* */ +/* horiBearingX :: The horizontal left bearing. */ +/* */ +/* horiBearingY :: The horizontal top bearing. */ +/* */ +/* horiAdvance :: The horizontal advance. */ +/* */ +/* vertBearingX :: The vertical left bearing. */ +/* */ +/* vertBearingY :: The vertical top bearing. */ +/* */ +/* vertAdvance :: The vertical advance. */ +/* */ +typedef struct TT_SBit_Metrics_ +{ + FT_Byte height; + FT_Byte width; + + FT_Char horiBearingX; + FT_Char horiBearingY; + FT_Byte horiAdvance; + + FT_Char vertBearingX; + FT_Char vertBearingY; + FT_Byte vertAdvance; + +} TT_SBit_Metrics; + + +/*************************************************************************/ +/* */ +/* */ +/* TT_SBit_Small_Metrics */ +/* */ +/* */ +/* A structure used to hold the small metrics of a given glyph bitmap */ +/* in a TrueType or OpenType font. These are usually found in the */ +/* `EBDT' (Microsoft) or the `bdat' (Apple) table. */ +/* */ +/* */ +/* height :: The glyph height in pixels. */ +/* */ +/* width :: The glyph width in pixels. */ +/* */ +/* bearingX :: The left-side bearing. */ +/* */ +/* bearingY :: The top-side bearing. */ +/* */ +/* advance :: The advance width or height. */ +/* */ +typedef struct TT_SBit_Small_Metrics_ +{ + FT_Byte height; + FT_Byte width; + + FT_Char bearingX; + FT_Char bearingY; + FT_Byte advance; + +} TT_SBit_Small_Metrics; + + +/*************************************************************************/ +/* */ +/* */ +/* TT_SBit_Line_Metrics */ +/* */ +/* */ +/* A structure used to describe the text line metrics of a given */ +/* bitmap strike, for either a horizontal or vertical layout. */ +/* */ +/* */ +/* ascender :: The ascender in pixels. */ +/* */ +/* descender :: The descender in pixels. */ +/* */ +/* max_width :: The maximum glyph width in pixels. */ +/* */ +/* caret_slope_enumerator :: Rise of the caret slope, typically set */ +/* to 1 for non-italic fonts. */ +/* */ +/* caret_slope_denominator :: Rise of the caret slope, typically set */ +/* to 0 for non-italic fonts. */ +/* */ +/* caret_offset :: Offset in pixels to move the caret for */ +/* proper positioning. */ +/* */ +/* min_origin_SB :: Minimum of horiBearingX (resp. */ +/* vertBearingY). */ +/* min_advance_SB :: Minimum of */ +/* */ +/* horizontal advance - */ +/* ( horiBearingX + width ) */ +/* */ +/* resp. */ +/* */ +/* vertical advance - */ +/* ( vertBearingY + height ) */ +/* */ +/* max_before_BL :: Maximum of horiBearingY (resp. */ +/* vertBearingY). */ +/* */ +/* min_after_BL :: Minimum of */ +/* */ +/* horiBearingY - height */ +/* */ +/* resp. */ +/* */ +/* vertBearingX - width */ +/* */ +/* pads :: Unused (to make the size of the record */ +/* a multiple of 32 bits. */ +/* */ +typedef struct TT_SBit_Line_Metrics_ +{ + FT_Char ascender; + FT_Char descender; + FT_Byte max_width; + FT_Char caret_slope_numerator; + FT_Char caret_slope_denominator; + FT_Char caret_offset; + FT_Char min_origin_SB; + FT_Char min_advance_SB; + FT_Char max_before_BL; + FT_Char min_after_BL; + FT_Char pads[2]; + +} TT_SBit_Line_Metrics; + + +/*************************************************************************/ +/* */ +/* */ +/* TT_SBit_Range */ +/* */ +/* */ +/* A TrueType/OpenType subIndexTable as defined in the `EBLC' */ +/* (Microsoft) or `bloc' (Apple) tables. */ +/* */ +/* */ +/* first_glyph :: The first glyph index in the range. */ +/* */ +/* last_glyph :: The last glyph index in the range. */ +/* */ +/* index_format :: The format of index table. Valid values are 1 */ +/* to 5. */ +/* */ +/* image_format :: The format of `EBDT' image data. */ +/* */ +/* image_offset :: The offset to image data in `EBDT'. */ +/* */ +/* image_size :: For index formats 2 and 5. This is the size in */ +/* bytes of each glyph bitmap. */ +/* */ +/* big_metrics :: For index formats 2 and 5. This is the big */ +/* metrics for each glyph bitmap. */ +/* */ +/* num_glyphs :: For index formats 4 and 5. This is the number of */ +/* glyphs in the code array. */ +/* */ +/* glyph_offsets :: For index formats 1 and 3. */ +/* */ +/* glyph_codes :: For index formats 4 and 5. */ +/* */ +/* table_offset :: The offset of the index table in the `EBLC' */ +/* table. Only used during strike loading. */ +/* */ +typedef struct TT_SBit_Range +{ + FT_UShort first_glyph; + FT_UShort last_glyph; + + FT_UShort index_format; + FT_UShort image_format; + FT_ULong image_offset; + + FT_ULong image_size; + TT_SBit_Metrics metrics; + FT_ULong num_glyphs; + + FT_ULong* glyph_offsets; + FT_UShort* glyph_codes; + + FT_ULong table_offset; + +} TT_SBit_Range; + + +/*************************************************************************/ +/* */ +/* */ +/* TT_SBit_Strike */ +/* */ +/* */ +/* A structure used describe a given bitmap strike in the `EBLC' */ +/* (Microsoft) or `bloc' (Apple) tables. */ +/* */ +/* */ +/* num_index_ranges :: The number of index ranges. */ +/* */ +/* index_ranges :: An array of glyph index ranges. */ +/* */ +/* color_ref :: Unused. A color reference? */ +/* */ +/* hori :: The line metrics for horizontal layouts. */ +/* */ +/* vert :: The line metrics for vertical layouts. */ +/* */ +/* start_glyph :: The lowest glyph index for this strike. */ +/* */ +/* end_glyph :: The highest glyph index for this strike. */ +/* */ +/* x_ppem :: The number of horizontal pixels per EM. */ +/* */ +/* y_ppem :: The number of vertical pixels per EM. */ +/* */ +/* bit_depth :: The bit depth. Valid values are 1, 2, 4, */ +/* and 8. */ +/* */ +/* flags :: Is this a vertical or horizontal strike? */ +/* */ +typedef struct TT_SBit_Strike_ +{ + FT_Int num_ranges; + TT_SBit_Range* sbit_ranges; + FT_ULong ranges_offset; + + FT_ULong color_ref; + + TT_SBit_Line_Metrics hori; + TT_SBit_Line_Metrics vert; + + FT_UShort start_glyph; + FT_UShort end_glyph; + + FT_Byte x_ppem; + FT_Byte y_ppem; + + FT_Byte bit_depth; + FT_Char flags; + +} TT_SBit_Strike; + + +/*************************************************************************/ +/* */ +/* */ +/* TT_SBit_Component */ +/* */ +/* */ +/* A simple structure to describe a compound sbit element. */ +/* */ +/* */ +/* glyph_code :: The element's glyph index. */ +/* */ +/* x_offset :: The element's left bearing. */ +/* */ +/* y_offset :: The element's top bearing. */ +/* */ +typedef struct TT_SBit_Component_ +{ + FT_UShort glyph_code; + + FT_Char x_offset; + FT_Char y_offset; + +} TT_SBit_Component; + + +/*************************************************************************/ +/* */ +/* */ +/* TT_SBit_Scale */ +/* */ +/* */ +/* A structure used describe a given bitmap scaling table, as defined */ +/* in the `EBSC' table. */ +/* */ +/* */ +/* hori :: The horizontal line metrics. */ +/* */ +/* vert :: The vertical line metrics. */ +/* */ +/* x_ppem :: The number of horizontal pixels per EM. */ +/* */ +/* y_ppem :: The number of vertical pixels per EM. */ +/* */ +/* x_ppem_substitute :: Substitution x_ppem value. */ +/* */ +/* y_ppem_substitute :: Substitution y_ppem value. */ +/* */ +typedef struct TT_SBit_Scale_ +{ + TT_SBit_Line_Metrics hori; + TT_SBit_Line_Metrics vert; + + FT_Byte x_ppem; + FT_Byte y_ppem; + + FT_Byte x_ppem_substitute; + FT_Byte y_ppem_substitute; + +} TT_SBit_Scale; + + +/*************************************************************************/ +/*************************************************************************/ +/*************************************************************************/ +/*** ***/ +/*** ***/ +/*** POSTSCRIPT GLYPH NAMES SUPPORT ***/ +/*** ***/ +/*** ***/ +/*************************************************************************/ +/*************************************************************************/ +/*************************************************************************/ + + +/*************************************************************************/ +/* */ +/* */ +/* TT_Post_20 */ +/* */ +/* */ +/* Postscript names sub-table, format 2.0. Stores the PS name of */ +/* each glyph in the font face. */ +/* */ +/* */ +/* num_glyphs :: The number of named glyphs in the table. */ +/* */ +/* num_names :: The number of PS names stored in the table. */ +/* */ +/* glyph_indices :: The indices of the glyphs in the names arrays. */ +/* */ +/* glyph_names :: The PS names not in Mac Encoding. */ +/* */ +typedef struct TT_Post_20_ +{ + FT_UShort num_glyphs; + FT_UShort num_names; + FT_UShort* glyph_indices; + FT_Char** glyph_names; + +} TT_Post_20; + + +/*************************************************************************/ +/* */ +/* */ +/* TT_Post_25 */ +/* */ +/* */ +/* Postscript names sub-table, format 2.5. Stores the PS name of */ +/* each glyph in the font face. */ +/* */ +/* */ +/* num_glyphs :: The number of glyphs in the table. */ +/* */ +/* offsets :: An array of signed offsets in a normal Mac */ +/* Postscript name encoding. */ +/* */ +typedef struct TT_Post_25_ +{ + FT_UShort num_glyphs; + FT_Char* offsets; + +} TT_Post_25; + + +/*************************************************************************/ +/* */ +/* */ +/* TT_Post_Names */ +/* */ +/* */ +/* Postscript names table, either format 2.0 or 2.5. */ +/* */ +/* */ +/* loaded :: A flag to indicate whether the PS names are loaded. */ +/* */ +/* format_20 :: The sub-table used for format 2.0. */ +/* */ +/* format_25 :: The sub-table used for format 2.5. */ +/* */ +typedef struct TT_Post_Names_ +{ + FT_Bool loaded; + + union + { + TT_Post_20 format_20; + TT_Post_25 format_25; + + } names; + +} TT_Post_Names; + + +/*************************************************************************/ +/*************************************************************************/ +/*************************************************************************/ +/*** ***/ +/*** ***/ +/*** TRUETYPE CHARMAPS SUPPORT ***/ +/*** ***/ +/*** ***/ +/*************************************************************************/ +/*************************************************************************/ +/*************************************************************************/ + + +/* format 0 */ + +typedef struct TT_CMap0_ +{ + FT_Byte* glyphIdArray; + +} TT_CMap0; + + +/* format 2 */ + +typedef struct TT_CMap2SubHeader_ +{ + FT_UShort firstCode; /* first valid low byte */ + FT_UShort entryCount; /* number of valid low bytes */ + FT_Short idDelta; /* delta value to glyphIndex */ + FT_UShort idRangeOffset; /* offset from here to 1st code */ + +} TT_CMap2SubHeader; + + +typedef struct TT_CMap2_ +{ + FT_UShort* subHeaderKeys; + /* high byte mapping table */ + /* value = subHeader index * 8 */ + + TT_CMap2SubHeader* subHeaders; + FT_UShort* glyphIdArray; + FT_UShort numGlyphId; /* control value */ + +} TT_CMap2; + + +/* format 4 */ + +typedef struct TT_CMap4Segment_ +{ + FT_UShort endCount; + FT_UShort startCount; + FT_Short idDelta; + FT_UShort idRangeOffset; + +} TT_CMap4Segment; + + +typedef struct TT_CMap4_ +{ + FT_UShort segCountX2; /* number of segments * 2 */ + FT_UShort searchRange; /* these parameters can be used */ + FT_UShort entrySelector; /* for a binary search */ + FT_UShort rangeShift; + + TT_CMap4Segment* segments; + FT_UShort* glyphIdArray; + FT_UShort numGlyphId; /* control value */ + + TT_CMap4Segment* last_segment; /* last used segment; this is a small */ + /* cache to potentially increase speed */ +} TT_CMap4; + + +/* format 6 */ + +typedef struct TT_CMap6_ +{ + FT_UShort firstCode; /* first character code of subrange */ + FT_UShort entryCount; /* number of character codes in subrange */ + + FT_UShort* glyphIdArray; + +} TT_CMap6; + + +typedef struct TT_CMapTable_ TT_CMapTable; + + +typedef +FT_UInt ( *TT_CharMap_Func )( TT_CMapTable* charmap, + FT_ULong char_code ); + + +/* charmap table */ +struct TT_CMapTable_ +{ + FT_UShort platformID; + FT_UShort platformEncodingID; + FT_UShort format; + FT_UShort length; + FT_UShort version; + + FT_Bool loaded; + FT_ULong offset; + + union + { + TT_CMap0 cmap0; + TT_CMap2 cmap2; + TT_CMap4 cmap4; + TT_CMap6 cmap6; + } c; + + TT_CharMap_Func get_index; +}; + + +/*************************************************************************/ +/* */ +/* */ +/* TT_CharMapRec */ +/* */ +/* */ +/* The TrueType character map object type. */ +/* */ +/* */ +/* root :: The parent character map structure. */ +/* */ +/* cmap :: The used character map. */ +/* */ +typedef struct TT_CharMapRec_ +{ + FT_CharMapRec root; + TT_CMapTable cmap; + +} TT_CharMapRec; + + +/*************************************************************************/ +/*************************************************************************/ +/*************************************************************************/ +/*** ***/ +/*** ***/ +/*** ORIGINAL TT_FACE CLASS DEFINITION ***/ +/*** ***/ +/*** ***/ +/*************************************************************************/ +/*************************************************************************/ +/*************************************************************************/ + + +/*************************************************************************/ +/* */ +/* This structure/class is defined here because it is common to the */ +/* following formats: TTF, OpenType-TT, and OpenType-CFF. */ +/* */ +/* Note, however, that the classes TT_Size, TT_GlyphSlot, and TT_CharMap */ +/* are not shared between font drivers, and are thus defined normally in */ +/* `ttobjs.h'. */ +/* */ +/*************************************************************************/ + + +/*************************************************************************/ +/* */ +/* */ +/* TT_Face */ +/* */ +/* */ +/* A handle to a TrueType face/font object. A TT_Face encapsulates */ +/* the resolution and scaling independent parts of a TrueType font */ +/* resource. */ +/* */ +/* */ +/* The TT_Face structure is also used as a `parent class' for the */ +/* OpenType-CFF class (T2_Face). */ +/* */ +typedef struct TT_FaceRec_* TT_Face; + + +/*************************************************************************/ +/* */ +/* */ +/* TT_CharMap */ +/* */ +/* */ +/* A handle to a TrueType character mapping object. */ +/* */ +typedef struct TT_CharMapRec_* TT_CharMap; + + +/* a function type used for the truetype bytecode interpreter hooks */ +typedef FT_Error ( *TT_Interpreter )( void* exec_context ); + +/* forward declaration */ +typedef struct TT_Loader_ TT_Loader; + + +/*************************************************************************/ +/* */ +/* */ +/* TT_Goto_Table_Func */ +/* */ +/* */ +/* Seeks a stream to the start of a given TrueType table. */ +/* */ +/* */ +/* face :: A handle to the target face object. */ +/* */ +/* tag :: A 4-byte tag used to name the table. */ +/* */ +/* stream :: The input stream. */ +/* */ +/* */ +/* length :: The length of the table in bytes. Set to 0 if not */ +/* needed. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +/* */ +/* The stream cursor must be at the font file's origin. */ +/* */ +typedef +FT_Error ( *TT_Goto_Table_Func )( TT_Face face, + FT_ULong tag, + FT_Stream stream, + FT_ULong* length ); + + +/*************************************************************************/ +/* */ +/* */ +/* TT_Access_Glyph_Frame_Func */ +/* */ +/* */ +/* Seeks a stream to the start of a given glyph element, and opens a */ +/* frame for it. */ +/* */ +/* */ +/* loader :: The current TrueType glyph loader object. */ +/* */ +/* glyph index :: The index of the glyph to access. */ +/* */ +/* offset :: The offset of the glyph according to the */ +/* `locations' table. */ +/* */ +/* byte_count :: The size of the frame in bytes. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +/* */ +/* This function is normally equivalent to FILE_Seek(offset) */ +/* followed by ACCESS_Frame(byte_count) with the loader's stream, but */ +/* alternative formats (e.g. compressed ones) might use something */ +/* different. */ +/* */ +typedef +FT_Error ( *TT_Access_Glyph_Frame_Func )( TT_Loader* loader, + FT_UInt glyph_index, + FT_ULong offset, + FT_UInt byte_count ); + + +/*************************************************************************/ +/* */ +/* */ +/* TT_Load_Glyph_Element_Func */ +/* */ +/* */ +/* Reads one glyph element (its header, a simple glyph, or a */ +/* composite) from the loader's current stream frame. */ +/* */ +/* */ +/* loader :: The current TrueType glyph loader object. */ +/* */ +/* */ +/* FreeType error code. 0 means success. */ +/* */ +typedef +FT_Error ( *TT_Load_Glyph_Element_Func )( TT_Loader* loader ); + + +/*************************************************************************/ +/* */ +/* */ +/* TT_Forget_Glyph_Frame_Func */ +/* */ +/* */ +/* Closes the current loader stream frame for the glyph. */ +/* */ +/* */ +/* loader :: The current TrueType glyph loader object. */ +/* */ +typedef +void ( *TT_Forget_Glyph_Frame_Func )( TT_Loader* loader ); + + + +/*************************************************************************/ +/* */ +/* TrueType Face Type */ +/* */ +/* */ +/* TT_Face */ +/* */ +/* */ +/* The TrueType face class. These objects model the resolution and */ +/* point-size independent data found in a TrueType font file. */ +/* */ +/* */ +/* root :: The base FT_Face structure, managed by the */ +/* base layer. */ +/* */ +/* ttc_header :: The TrueType collection header, used when */ +/* the file is a `ttc' rather than a `ttf'. */ +/* For ordinary font files, the field */ +/* `ttc_header.count' is set to 0. */ +/* */ +/* format_tag :: The font format tag. */ +/* */ +/* num_tables :: The number of TrueType tables in this font */ +/* file. */ +/* */ +/* dir_tables :: The directory of TrueType tables for this */ +/* font file. */ +/* */ +/* header :: The font's font header (`head' table). */ +/* Read on font opening. */ +/* */ +/* horizontal :: The font's horizontal header (`hhea' */ +/* table). This field also contains the */ +/* associated horizontal metrics table */ +/* (`hmtx'). */ +/* */ +/* max_profile :: The font's maximum profile table. Read on */ +/* font opening. Note that some maximum */ +/* values cannot be taken directly from this */ +/* table. We thus define additional fields */ +/* below to hold the computed maxima. */ +/* */ +/* max_components :: The maximum number of glyph components */ +/* required to load any composite glyph from */ +/* this font. Used to size the load stack. */ +/* */ +/* vertical_info :: A boolean which is set when the font file */ +/* contains vertical metrics. If not, the */ +/* value of the `vertical' field is */ +/* undefined. */ +/* */ +/* vertical :: The font's vertical header (`vhea' table). */ +/* This field also contains the associated */ +/* vertical metrics table (`vmtx'), if found. */ +/* IMPORTANT: The contents of this field is */ +/* undefined if the `verticalInfo' field is */ +/* unset. */ +/* */ +/* num_names :: The number of name records within this */ +/* TrueType font. */ +/* */ +/* name_table :: The table of name records (`name'). */ +/* */ +/* os2 :: The font's OS/2 table (`OS/2'). */ +/* */ +/* postscript :: The font's PostScript table (`post' */ +/* table). The PostScript glyph names are */ +/* not loaded by the driver on face opening. */ +/* See the `ttpost' module for more details. */ +/* */ +/* num_charmaps :: The number of character mappings in the */ +/* font. */ +/* */ +/* charmaps :: The array of charmap objects for this font */ +/* file. Note that this field is a typeless */ +/* pointer. The Reason is that the format of */ +/* charmaps varies with the underlying font */ +/* format and cannot be determined here. */ +/* */ +/* goto_table :: A function called by each TrueType table */ +/* loader to position a stream's cursor to */ +/* the start of a given table according to */ +/* its tag. It defaults to TT_Goto_Face but */ +/* can be different for strange formats (e.g. */ +/* Type 42). */ +/* */ +/* access_glyph_frame :: XXX */ +/* */ +/* read_glyph_header :: XXX */ +/* */ +/* read_simple_glyph :: XXX */ +/* */ +/* read_composite_glyph :: XXX */ +/* */ +/* forget_glyph_frame :: XXX */ +/* */ +/* sfnt :: A pointer to the SFNT `driver' interface. */ +/* */ +/* psnames :: A pointer to the `PSNames' module */ +/* interface. */ +/* */ +/* hdmx :: The face's horizontal device metrics */ +/* (`hdmx' table). This table is optional in */ +/* TrueType/OpenType fonts. */ +/* */ +/* gasp :: The grid-fitting and scaling properties */ +/* table (`gasp'). This table is optional in */ +/* TrueType/OpenType fonts. */ +/* */ +/* pclt :: XXX */ +/* */ +/* num_sbit_strikes :: The number of sbit strikes, i.e., bitmap */ +/* sizes, embedded in this font. */ +/* */ +/* sbit_strikes :: An array of sbit strikes embedded in this */ +/* font. This table is optional in a */ +/* TrueType/OpenType font. */ +/* */ +/* num_sbit_scales :: The number of sbit scales for this font. */ +/* */ +/* sbit_scales :: Array of sbit scales embedded in this */ +/* font. This table is optional in a */ +/* TrueType/OpenType font. */ +/* */ +/* postscript_names :: A table used to store the Postscript names */ +/* of the glyphs for this font. See the */ +/* file `ttconfig.h' for comments on the */ +/* TT_CONFIG_OPTION_POSTSCRIPT_NAMES option. */ +/* */ +/* num_locations :: The number of glyph locations in this */ +/* TrueType file. This should be */ +/* identical to the number of glyphs. */ +/* Ignored for Type 2 fonts. */ +/* */ +/* glyph_locations :: An array of longs. These are offsets to */ +/* glyph data within the `glyf' table. */ +/* Ignored for Type 2 font faces. */ +/* */ +/* font_program_size :: Size in bytecodes of the face's font */ +/* program. 0 if none defined. Ignored for */ +/* Type 2 fonts. */ +/* */ +/* font_program :: The face's font program (bytecode stream) */ +/* executed at load time, also used during */ +/* glyph rendering. Comes from the `fpgm' */ +/* table. Ignored for Type 2 font fonts. */ +/* */ +/* cvt_program_size :: The size in bytecodes of the face's cvt */ +/* program. Ignored for Type 2 fonts. */ +/* */ +/* cvt_program :: The face's cvt program (bytecode stream) */ +/* executed each time an instance/size is */ +/* changed/reset. Comes from the `prep' */ +/* table. Ignored for Type 2 fonts. */ +/* */ +/* cvt_size :: Size of the control value table (in */ +/* entries). Ignored for Type 2 fonts. */ +/* */ +/* cvt :: The face's original control value table. */ +/* Coordinates are expressed in unscaled font */ +/* units. Comes from the `cvt ' table. */ +/* Ignored for Type 2 fonts. */ +/* */ +/* num_kern_pairs :: The number of kerning pairs present in the */ +/* font file. The engine only loads the */ +/* first horizontal format 0 kern table it */ +/* finds in the font file. You should use */ +/* the `ttxkern' structures if you want to */ +/* access other kerning tables. Ignored */ +/* for Type 2 fonts. */ +/* */ +/* kern_table_index :: The index of the kerning table in the font */ +/* kerning directory. Only used by the */ +/* ttxkern extension to avoid data */ +/* duplication. Ignored for Type 2 fonts. */ +/* */ +/* interpreter :: A pointer to the TrueType bytecode */ +/* interpreters field is also used to hook */ +/* the debugger in `ttdebug'. */ +/* */ +/* extra :: XXX */ +/* */ +typedef struct TT_FaceRec_ +{ + FT_FaceRec root; + + TTC_Header ttc_header; + + FT_ULong format_tag; + FT_UShort num_tables; + TT_Table* dir_tables; + + TT_Header header; /* TrueType header table */ + TT_HoriHeader horizontal; /* TrueType horizontal header */ + + TT_MaxProfile max_profile; + FT_ULong max_components; + + FT_Bool vertical_info; + TT_VertHeader vertical; /* TT Vertical header, if present */ + + FT_Int num_names; /* number of name records */ + TT_NameTable name_table; /* name table */ + + TT_OS2 os2; /* TrueType OS/2 table */ + TT_Postscript postscript; /* TrueType Postscript table */ + + FT_Int num_charmaps; + TT_CharMap charmaps; /* array of TT_CharMapRec */ + + TT_Goto_Table_Func goto_table; + + TT_Access_Glyph_Frame_Func access_glyph_frame; + TT_Load_Glyph_Element_Func read_glyph_header; + TT_Load_Glyph_Element_Func read_simple_glyph; + TT_Load_Glyph_Element_Func read_composite_glyph; + TT_Forget_Glyph_Frame_Func forget_glyph_frame; + + /* a typeless pointer to the SFNT_Interface table used to load */ + /* the basic TrueType tables in the face object */ + void* sfnt; + + /* a typeless pointer to the PSNames_Interface table used to */ + /* handle glyph names <-> unicode & Mac values */ + void* psnames; + + /***********************************************************************/ + /* */ + /* Optional TrueType/OpenType tables */ + /* */ + /***********************************************************************/ + + /* horizontal device metrics */ + TT_Hdmx hdmx; + + /* grid-fitting and scaling table */ + TT_Gasp gasp; /* the `gasp' table */ + + /* PCL 5 table */ + TT_PCLT pclt; + + /* embedded bitmaps support */ + FT_Int num_sbit_strikes; + TT_SBit_Strike* sbit_strikes; + + FT_Int num_sbit_scales; + TT_SBit_Scale* sbit_scales; + + /* postscript names table */ + TT_Post_Names postscript_names; + + + /***********************************************************************/ + /* */ + /* TrueType-specific fields (ignored by the OTF-Type2 driver) */ + /* */ + /***********************************************************************/ + + /* the glyph locations */ + FT_UShort num_locations; + FT_Long* glyph_locations; + + /* the font program, if any */ + FT_ULong font_program_size; + FT_Byte* font_program; + + /* the cvt program, if any */ + FT_ULong cvt_program_size; + FT_Byte* cvt_program; + + /* the original, unscaled, control value table */ + FT_ULong cvt_size; + FT_Short* cvt; + + /* the format 0 kerning table, if any */ + FT_Int num_kern_pairs; + FT_Int kern_table_index; + TT_Kern_0_Pair* kern_pairs; + + /* A pointer to the bytecode interpreter to use. This is also */ + /* used to hook the debugger for the `ttdebug' utility. */ + TT_Interpreter interpreter; + + + /***********************************************************************/ + /* */ + /* Other tables or fields. This is used by derivative formats like */ + /* OpenType. */ + /* */ + /***********************************************************************/ + + FT_Generic extra; + +} TT_FaceRec; + + +/*************************************************************************/ +/* */ +/* */ +/* TT_GlyphZone */ +/* */ +/* */ +/* A glyph zone is used to load, scale and hint glyph outline */ +/* coordinates. */ +/* */ +/* */ +/* memory :: A handle to the memory manager. */ +/* */ +/* max_points :: The maximal size in points of the zone. */ +/* */ +/* max_contours :: Max size in links contours of thez one. */ +/* */ +/* n_points :: The current number of points in the zone. */ +/* */ +/* n_contours :: The current number of contours in the zone. */ +/* */ +/* org :: The original glyph coordinates (font */ +/* units/scaled). */ +/* */ +/* cur :: The current glyph coordinates (scaled/hinted). */ +/* */ +/* tags :: The point control tags. */ +/* */ +/* contours :: The contours end points. */ +/* */ +typedef struct TT_GlyphZone_ +{ + FT_Memory memory; + FT_UShort max_points; + FT_UShort max_contours; + FT_UShort n_points; /* number of points in zone */ + FT_Short n_contours; /* number of contours */ + + FT_Vector* org; /* original point coordinates */ + FT_Vector* cur; /* current point coordinates */ + + FT_Byte* tags; /* current touch flags */ + FT_UShort* contours; /* contour end points */ + +} TT_GlyphZone; + + +/* handle to execution context */ +typedef struct TT_ExecContextRec_* TT_ExecContext; + +/* glyph loader structure */ +struct TT_Loader_ +{ + FT_Face face; + FT_Size size; + FT_GlyphSlot glyph; + FT_GlyphLoader* gloader; + + FT_ULong load_flags; + FT_UInt glyph_index; + + FT_Stream stream; + FT_Int byte_len; + + FT_Short n_contours; + FT_BBox bbox; + FT_Int left_bearing; + FT_Int advance; + FT_Bool preserve_pps; + FT_Vector pp1; + FT_Vector pp2; + + FT_ULong glyf_offset; + + /* the zone where we load our glyphs */ + TT_GlyphZone base; + TT_GlyphZone zone; + + TT_ExecContext exec; + FT_Byte* instructions; + FT_ULong ins_pos; + + /* for possible extensibility in other formats */ + void* other; + +}; + + +#endif /* TTTYPES_H */ + + +/* END */ diff --git a/Projects/Android/jni/rtcw/src/game/ai_cast.c b/Projects/Android/jni/rtcw/src/game/ai_cast.c new file mode 100644 index 0000000..6551000 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/game/ai_cast.c @@ -0,0 +1,1003 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +//=========================================================================== +// +// Name: ai_cast.c +// Function: Wolfenstein AI Character Routines +// Programmer: Ridah +// Tab Size: 4 (real tabs) +//=========================================================================== + +#include "../game/g_local.h" +#include "../game/q_shared.h" +#include "../game/botlib.h" //bot lib interface +#include "../game/be_aas.h" +#include "../game/be_ea.h" +#include "../game/be_ai_gen.h" +#include "../game/be_ai_goal.h" +#include "../game/be_ai_move.h" +#include "../botai/botai.h" //bot ai interface + +#include "ai_cast.h" + +/* +The Wolfenstein AI uses the bot movement functions, and goal handling. + +The actual core thinking and decision making is handled by the Cast AI, +typically within the ai_cast*.c files. + +Some modifications to the botlib and botai are to be expected, the extent of those +changes is currently unknown. + +Currently, this seems to the the best approach, since if we're going to +use the AAS for navigation, we want to avoid having to re-write the movement +routines which are heavily associated with the AAS information. +*/ + +//cast states (allocated at run-time) +cast_state_t *caststates; +//number of characters +int numcast; +// +qboolean saveGamePending; +// +// minimum time between thinks (maximum is double this) +int aicast_thinktime; +// maximum number of character thinks at once +int aicast_maxthink; +// maximum clients +int aicast_maxclients; +// skill scale (0.0 -> 1.0) +float aicast_skillscale; + +// cvar to enable aicast debugging, set higher for more levels of debugging +vmCvar_t aicast_debug; +vmCvar_t aicast_debugname; +vmCvar_t aicast_scripts; + +// string versions of the attributes used for per-level, per-character definitions +char *castAttributeStrings[] = +{ + "RUNNING_SPEED", // max = 300 (running speed) + "WALKING_SPEED", // max = 300 (walking speed) + "CROUCHING_SPEED", // max = 300 (crouching speed) + "FOV", // max = 360 (field of view) + "YAW_SPEED", // max = 300 (yaw speed) + "LEADER", // max = 1.0 (ability to lead an AI squadron) + "AIM_SKILL", // max = 1.0 (skill while aiming) + "AIM_ACCURACY", // max = 1.0 (accuracy of firing) + "ATTACK_SKILL", // max = 1.0 (ability to attack and do other things, like retreat) + "REACTION_TIME", // max = 1.0 (upon seeing enemy, wait this long before reaction) + "ATTACK_CROUCH", // max = 1.0 (likely to crouch while firing) + "IDLE_CROUCH", // max = 1.0 (likely to crouch while idling) + "AGGRESSION", // max = 1.0 (willingness to fight till the death) + "TACTICAL", // max = 1.0 (ability to use strategy to their advantage, also behaviour whilst hunting enemy, more likely to creep around) + "CAMPER", // max = 1.0 (set this to make them stay in the spot they are spawned) + "ALERTNESS", // max = 1.0 (ability to notice enemies at long range) + "STARTING_HEALTH", + "HEARING_SCALE", + "HEARING_SCALE_NOT_PVS", + "INNER_DETECTION_RADIUS", + "PAIN_THRESHOLD_SCALE", + + NULL +}; + +/* +============ +AICast_Printf +============ +*/ +void AICast_Printf( int type, const char *fmt, ... ) { + char str[2048]; + va_list ap; + + va_start( ap, fmt ); + vsprintf( str, fmt, ap ); + va_end( ap ); + + switch ( type ) { + case AICAST_PRT_ALWAYS: { + G_Printf( "%s", str ); + break; + } + default: { + if ( aicast_debug.integer >= type ) { + G_Printf( "%s", str ); + } + break; + } + } +} + +/* +============ +AICast_GetCastState +============ +*/ +cast_state_t *AICast_GetCastState( int entitynum ) { + if ( entitynum < 0 || entitynum > level.maxclients ) { + return NULL; + } + // + return &( caststates[ entitynum ] ); +} + +/* +============== +AICast_SetupClient +============== +*/ +int AICast_SetupClient( int client ) { + cast_state_t *cs; + bot_state_t *bs; + + if ( !botstates[client] ) { + botstates[client] = G_Alloc( sizeof( bot_state_t ) ); + memset( botstates[client], 0, sizeof( bot_state_t ) ); + } + bs = botstates[client]; + + if ( bs->inuse ) { + BotAI_Print( PRT_FATAL, "client %d already setup\n", client ); + return qfalse; + } + + cs = AICast_GetCastState( client ); + cs->bs = bs; + + //allocate a goal state + bs->gs = trap_BotAllocGoalState( client ); + + bs->inuse = qtrue; + bs->client = client; + bs->entitynum = client; + bs->setupcount = qtrue; + bs->entergame_time = trap_AAS_Time(); + bs->ms = trap_BotAllocMoveState(); + + return qtrue; +} + +/* +============== +AICast_ShutdownClient +============== +*/ +int AICast_ShutdownClient( int client ) { + cast_state_t *cs; + bot_state_t *bs; + + if ( !( bs = botstates[client] ) ) { + return BLERR_NOERROR; + } + if ( !bs->inuse ) { + BotAI_Print( PRT_ERROR, "client %d already shutdown\n", client ); + return BLERR_AICLIENTALREADYSHUTDOWN; + } + + cs = AICast_GetCastState( client ); + // + memset( cs, 0, sizeof( cast_state_t ) ); + numcast--; + + // now do the other bot stuff + +#ifdef DEBUG +// botai_import.DebugLineDelete(bs->debugline); +#endif //DEBUG + + trap_BotFreeMoveState( bs->ms ); + //free the goal state + trap_BotFreeGoalState( bs->gs ); + // + //clear the bot state + memset( bs, 0, sizeof( bot_state_t ) ); + //set the inuse flag to qfalse + bs->inuse = qfalse; + //everything went ok + return BLERR_NOERROR; +} + +/* +============ +AICast_AddCastToGame +============ +*/ +//----(SA) modified this for head separation +gentity_t *AICast_AddCastToGame( gentity_t *ent, char *castname, char *model, char *head, char *sex, char *color, char *handicap ) { + int clientNum; + gentity_t *bot; + char userinfo[MAX_INFO_STRING]; + usercmd_t cmd; + + // create the bot's userinfo + userinfo[0] = '\0'; + + Info_SetValueForKey( userinfo, "name", castname ); + Info_SetValueForKey( userinfo, "rate", "25000" ); + Info_SetValueForKey( userinfo, "snaps", "20" ); + Info_SetValueForKey( userinfo, "handicap", handicap ); + Info_SetValueForKey( userinfo, "model", model ); + Info_SetValueForKey( userinfo, "head", head ); + Info_SetValueForKey( userinfo, "color", color ); + + // have the server allocate a client slot + clientNum = trap_BotAllocateClient(); + if ( clientNum == -1 ) { + G_Printf( S_COLOR_RED "BotAllocateClient failed\n" ); + return NULL; + } + bot = &g_entities[ clientNum ]; + bot->r.svFlags |= SVF_BOT; + bot->r.svFlags |= SVF_CASTAI; // flag it for special Cast AI behaviour + + // register the userinfo + trap_SetUserinfo( bot->s.number, userinfo ); + + // have it connect to the game as a normal client +//----(SA) ClientConnect requires a third 'isbot' parameter. setting to qfalse and noting + ClientConnect( bot->s.number, qtrue, qfalse ); +//----(SA) end + + // copy the origin/angles across + VectorCopy( ent->s.origin, bot->s.origin ); + VectorCopy( ent->s.angles, bot->s.angles ); + + memset( &cmd, 0, sizeof( cmd ) ); + ClientBegin( bot->s.number ); + + // set up the ai + AICast_SetupClient( bot->s.number ); + + return bot; +} + +/* +============ +AICast_CheckLevelAttributes +============ +*/ +void AICast_CheckLevelAttributes( cast_state_t *cs, gentity_t *ent, char **ppStr ) { + char *s; + int i; + + if ( !*ppStr ) { + return; + } + + while ( 1 ) { + s = COM_Parse( ppStr ); + if ( !s[0] || !Q_strncmp( s, "}", 2 ) ) { // end of attributes + break; + } + // + for ( i = 0; i < AICAST_MAX_ATTRIBUTES; i++ ) { + if ( !Q_strcasecmp( s, castAttributeStrings[i] ) ) { + // found a match, read in the value + s = COM_Parse( ppStr ); + if ( !s[0] ) { // end of attributes + break; + } + // set the attribute + cs->attributes[i] = atof( s ); + break; + } + } + } +} + +/* +============ +AICast_SetAASIndex +============ +*/ +void AICast_SetAASIndex( cast_state_t *cs ) { + if ( aiDefaults[cs->aiCharacter].bboxType == BBOX_SMALL ) { + cs->aasWorldIndex = AASWORLD_STANDARD; + cs->travelflags = AICAST_TFL_DEFAULT; + } else if ( aiDefaults[cs->aiCharacter].bboxType == BBOX_LARGE ) { + cs->aasWorldIndex = AASWORLD_LARGE; + cs->travelflags = AICAST_TFL_DEFAULT & ~TFL_DONOTENTER_LARGE; + } else { + Com_Error( ERR_DROP, "AICast_SetAASIndex: unsupported bounds size (%i)", aiDefaults[cs->aiCharacter].bboxType ); + } + + if ( !cs->attributes[ATTACK_CROUCH] ) { + cs->travelflags &= ~TFL_CROUCH; + } +} + +/* +============ +AICast_CreateCharacter + + returns 0 if unable to create the character +============ +*/ +gentity_t *AICast_CreateCharacter( gentity_t *ent, float *attributes, cast_weapon_info_t *weaponInfo, char *castname, char *model, char *head, char *sex, char *color, char *handicap ) { + gentity_t *newent; + gclient_t *client; + cast_state_t *cs; + char **ppStr; + int j; + + if ( g_gametype.integer != GT_SINGLE_PLAYER ) { // no cast AI in multiplayer + return NULL; + } + // are bots enabled? + if ( !trap_Cvar_VariableIntegerValue( "bot_enable" ) ) { + G_Printf( S_COLOR_RED "ERROR: Unable to spawn %s, 'bot_enable' is not set\n", ent->classname ); + return NULL; + } + // + // make sure we have a free slot for them + // + if ( level.numPlayingClients + 1 > aicast_maxclients ) { + G_Error( "Exceeded sv_maxclients (%d), unable to create %s\n", aicast_maxclients, ent->classname ); + return NULL; + } + // + // add it to the list (only do this if everything else passed) + // + + newent = AICast_AddCastToGame( ent, castname, model, head, sex, color, handicap ); + + if ( !newent ) { + return NULL; + } + client = newent->client; + // + // setup the character.. + // + cs = AICast_GetCastState( newent->s.number ); + // + cs->aiCharacter = ent->aiCharacter; + client->ps.aiChar = ent->aiCharacter; + // setup the attributes + memcpy( cs->attributes, attributes, sizeof( cs->attributes ) ); + ppStr = &ent->aiAttributes; + AICast_CheckLevelAttributes( cs, ent, ppStr ); + // + AICast_SetAASIndex( cs ); + // make sure they face the right direction + VectorCopy( ent->s.angles, cs->ideal_viewangles ); + // factor in the delta_angles + for ( j = 0; j < 3; j++ ) { + cs->viewangles[j] = AngleMod( newent->s.angles[j] - SHORT2ANGLE( newent->client->ps.delta_angles[j] ) ); + } + VectorCopy( ent->s.angles, newent->s.angles ); + VectorCopy( ent->s.origin, cs->startOrigin ); + // + cs->lastEnemy = -1; + cs->enemyNum = -1; + cs->leaderNum = -1; + cs->castScriptStatus.scriptGotoEnt = -1; + // + newent->aiName = ent->aiName; + newent->aiTeam = ent->aiTeam; + newent->targetname = ent->targetname; + // + newent->AIScript_AlertEntity = ent->AIScript_AlertEntity; + newent->aiInactive = ent->aiInactive; + newent->aiCharacter = cs->aiCharacter; + // + // parse the AI script for this character (if applicable) + cs->aiFlags |= AIFL_CORPSESIGHTING; // this is on by default for all characters, disabled if they have a "friendlysightcorpse" script event + AICast_ScriptParse( cs ); + // + // setup bounding boxes + //VectorCopy( mins, client->ps.mins ); + //VectorCopy( maxs, client->ps.maxs ); + AIChar_SetBBox( newent, cs, qfalse ); + client->ps.friction = cs->attributes[RUNNING_SPEED] / 300.0; + // + // clear weapons/ammo + client->ps.weapon = 0; + memcpy( client->ps.weapons, weaponInfo->startingWeapons, sizeof( weaponInfo->startingWeapons ) ); + memcpy( client->ps.ammo, weaponInfo->startingAmmo, sizeof( client->ps.ammo ) ); + // + // starting health + if ( ent->health ) { + newent->health = client->ps.stats[STAT_HEALTH] = client->ps.stats[STAT_MAX_HEALTH] = ent->health; + } else { + newent->health = client->ps.stats[STAT_HEALTH] = client->ps.stats[STAT_MAX_HEALTH] = cs->attributes[STARTING_HEALTH]; + } + // + cs->weaponInfo = weaponInfo; + // + cs->lastThink = level.time; + // + newent->pain = AICast_Pain; + newent->die = AICast_Die; + // + //update the attack inventory values + AICast_UpdateBattleInventory( cs, cs->enemyNum ); + +//----(SA) make sure all clips are loaded so we don't hear everyone loading up +// (we don't want to do this inside AICast_UpdateBattleInventory(), only on spawn or giveweapon) + for ( j = 0; j < WP_NUM_WEAPONS; j++ ) { + Fill_Clip( &client->ps, j ); + } +//----(SA) end + + // select a weapon + AICast_ChooseWeapon( cs, qfalse ); + + // + // set the default function, overwrite if necessary + cs->aiFlags |= AIFL_JUST_SPAWNED; + AIFunc_DefaultStart( cs ); + // + numcast++; + // + return newent; +} + +/* +============ +AICast_Init + + called at each level start, before the world and it's entities have been spawned +============ +*/ +static int numSpawningCast; + +void AICast_Init( void ) { + vmCvar_t cvar; + int i; + + numcast = 0; + numSpawningCast = 0; + saveGamePending = qtrue; + + trap_Cvar_Register( &aicast_debug, "aicast_debug", "0", 0 ); + trap_Cvar_Register( &aicast_debugname, "aicast_debugname", "", 0 ); + trap_Cvar_Register( &aicast_scripts, "aicast_scripts", "1", 0 ); + + // (aicast_thinktime / sv_fps) * aicast_maxthink = number of cast's to think between each aicast frame + // so.. + // (100 / 20) * 6 = 30 + // + // so if the level has more than 30 AI cast's, they could start to bunch up, resulting in slower thinks + + trap_Cvar_Register( &cvar, "aicast_thinktime", "50", 0 ); + aicast_thinktime = trap_Cvar_VariableIntegerValue( "aicast_thinktime" ); + + trap_Cvar_Register( &cvar, "aicast_maxthink", "4", 0 ); + aicast_maxthink = trap_Cvar_VariableIntegerValue( "aicast_maxthink" ); + + aicast_maxclients = trap_Cvar_VariableIntegerValue( "sv_maxclients" ); + + aicast_skillscale = (float)trap_Cvar_VariableIntegerValue( "g_gameSkill" ) / (float)GSKILL_MAX; + + caststates = G_Alloc( aicast_maxclients * sizeof( cast_state_t ) ); + memset( caststates, 0, sizeof( caststates ) ); + for ( i = 0; i < MAX_CLIENTS; i++ ) { + caststates[i].entityNum = i; + } + +/* RF, this is useless, since the AAS hasnt been loaded yet + // try and load in the AAS now, so we can interact with it during spawning of entities + i = 0; + trap_AAS_SetCurrentWorld(0); + while (!trap_AAS_Initialized() && (i++ < 10)) { + trap_BotLibStartFrame((float) level.time / 1000); + } +*/ +} + +/* +=============== +AICast_FindEntityForName +=============== +*/ +gentity_t *AICast_FindEntityForName( char *name ) { + gentity_t *trav; + int i; + + for ( trav = g_entities, i = 0; i < aicast_maxclients; i++, trav++ ) { + if ( !trav->inuse ) { + continue; + } + if ( !trav->client ) { + continue; + } + if ( !trav->aiName ) { + continue; + } + if ( strcmp( trav->aiName, name ) ) { + continue; + } + return trav; + } + return NULL; +} + +/* +=============== +AICast_TravEntityForName +=============== +*/ +gentity_t *AICast_TravEntityForName( gentity_t *startent, char *name ) { + gentity_t *trav; + + if ( !startent ) { + trav = g_entities; + } else { + trav = startent + 1; + } + + for ( ; trav < g_entities + aicast_maxclients; trav++ ) { + if ( !trav->inuse ) { + continue; + } + if ( !trav->client ) { + continue; + } + if ( !trav->aiName ) { + continue; + } + if ( strcmp( trav->aiName, name ) ) { + continue; + } + return trav; + } + return NULL; +} + +/* +============ +AIChar_AIScript_AlertEntity + + triggered spawning, called from AI scripting +============ +*/ +void AIChar_AIScript_AlertEntity( gentity_t *ent ) { + vec3_t mins, maxs; + int numTouch, touch[10], i; + cast_state_t *cs; + + if ( !ent->aiInactive ) { + return; + } + + cs = AICast_GetCastState( ent->s.number ); + + // if the current bounding box is invalid, then wait + VectorAdd( ent->r.currentOrigin, ent->r.mins, mins ); + VectorAdd( ent->r.currentOrigin, ent->r.maxs, maxs ); + trap_UnlinkEntity( ent ); + + numTouch = trap_EntitiesInBox( mins, maxs, touch, 10 ); + + // check that another client isn't inside us + if ( numTouch ) { + for ( i = 0; i < numTouch; i++ ) { + // RF, note we should only check against clients since zombies need to spawn inside func_explosive (so they dont clip into view after it explodes) + if ( g_entities[touch[i]].client && g_entities[touch[i]].r.contents == CONTENTS_BODY ) { + //if (g_entities[touch[i]].r.contents & MASK_PLAYERSOLID) + break; + } + } + if ( i == numTouch ) { + numTouch = 0; + } + } + + if ( numTouch ) { + // invalid location + cs->aiFlags |= AIFL_WAITINGTOSPAWN; + return; + } + + // RF, has to disable this so I could test some maps which have erroneously placed alertentity calls + //ent->AIScript_AlertEntity = NULL; + cs->aiFlags &= ~AIFL_WAITINGTOSPAWN; + ent->aiInactive = qfalse; + trap_LinkEntity( ent ); + + // trigger a spawn script event + AICast_ScriptEvent( AICast_GetCastState( ent->s.number ), "spawn", "" ); + // make it think so we update animations/angles + AICast_Think( ent->s.number, (float)FRAMETIME / 1000 ); + cs->lastThink = level.time; + AICast_UpdateInput( cs, FRAMETIME ); + trap_BotUserCommand( cs->bs->client, &( cs->lastucmd ) ); +} + + +/* +================ +AICast_DelayedSpawnCast +================ +*/ +void AICast_DelayedSpawnCast( gentity_t *ent, int castType ) { + int i; + + // ............................ + // head separation + if ( !ent->aiSkin ) { + G_SpawnString( "skin", "", &ent->aiSkin ); + } + if ( !ent->aihSkin ) { + G_SpawnString( "head", "default", &ent->aihSkin ); + } + G_SpawnInt( "aiteam", "-1", &ent->aiTeam ); + // ............................ + + +//----(SA) make sure client registers the default weapons for this char + for ( i = 0; aiDefaults[ent->aiCharacter].weapons[i]; i++ ) { + RegisterItem( BG_FindItemForWeapon( aiDefaults[ent->aiCharacter].weapons[i] ) ); + } +//----(SA) end + + // we have to wait a bit before spawning it, otherwise the server will just delete it, since it's treated like a client + ent->think = AIChar_spawn; + ent->nextthink = level.time + FRAMETIME * 4; // have to wait more than 3 frames, since the server runs 3 frames before it clears all clients + + // we don't really want to start this character right away, but if we don't spawn the client + // now, if the game gets saved after the character spawns in, when it gets re-loaded, the client + // won't get spawned properly. + if ( ent->spawnflags & 1 ) { // TriggerSpawn + ent->AIScript_AlertEntity = AIChar_AIScript_AlertEntity; + ent->aiInactive = qtrue; + } + + // RF, had to move this down since some dev maps don't properly spawn the guys in, so we + // get a crash when transitioning between levels after they all spawn at once (overloading + // the client/server command buffers) + ent->nextthink += FRAMETIME * ( ( numSpawningCast + 1 ) / 3 ); // space them out a bit so we don't overflow the client + + ent->aiCharacter = castType; + numSpawningCast++; +} + +/* +================== +AICast_CastScriptThink +================== +*/ +void AICast_CastScriptThink( void ) { + int i; + gentity_t *ent; + cast_state_t *cs; + + for ( i = 0, ent = g_entities, cs = caststates; i < level.maxclients; i++, ent++, cs++ ) { + if ( !ent->inuse ) { + continue; + } + if ( !cs->bs ) { + continue; + } + if ( ent->health <= 0 ) { + continue; + } + AICast_ScriptRun( cs, qfalse ); + } +} + +/* +================== +AICast_EnableRenderingThink +================== +*/ +void AICast_EnableRenderingThink( gentity_t *ent ) { + trap_Cvar_Set( "cg_norender", "0" ); +// trap_S_FadeAllSound(1.0f, 1000); // fade sound up + G_FreeEntity( ent ); +} + +/* +================== +AICast_CheckLoadGame + + at the start of a level, the game is either saved, or loaded + + we must wait for all AI to spawn themselves, and a real client to connect +================== +*/ +void AICast_CheckLoadGame( void ) { + char loading[4]; + gentity_t *ent = NULL; // TTimo: VC6 'may be used without having been init' + qboolean ready; + cast_state_t *pcs; + + // have we already done the save or load? + if ( !saveGamePending ) { + return; + } + + // tell the cgame NOT to render the scene while we are waiting for things to settle + trap_Cvar_Set( "cg_norender", "1" ); + + trap_Cvar_VariableStringBuffer( "savegame_loading", loading, sizeof( loading ) ); + +// reloading = qtrue; + trap_Cvar_Set( "g_reloading", "1" ); + + if ( strlen( loading ) > 0 && atoi( loading ) != 0 ) { + // screen should be black if we are at this stage + trap_SetConfigstring( CS_SCREENFADE, va( "1 %i 1", level.time - 10 ) ); + +// if (!reloading && atoi(loading) == 2) { + if ( !( g_reloading.integer ) && atoi( loading ) == 2 ) { + // (SA) hmm, this seems redundant when it sets it above... +// reloading = qtrue; // this gets reset at the Map_Restart() since the server unloads the game dll + trap_Cvar_Set( "g_reloading", "1" ); + } + + ready = qtrue; + if ( numSpawningCast != numcast ) { + ready = qfalse; + } else if ( !( ent = AICast_FindEntityForName( "player" ) ) ) { + ready = qfalse; + } else if ( !ent->client || ent->client->pers.connected != CON_CONNECTED ) { + ready = qfalse; + } + + if ( ready ) { + trap_Cvar_Set( "savegame_loading", "0" ); // in-case it aborts + saveGamePending = qfalse; + G_LoadGame( NULL ); // always load the "current" savegame + + // RF, spawn a thinker that will enable rendering after the client has had time to process the entities and setup the display + //trap_Cvar_Set( "cg_norender", "0" ); + ent = G_Spawn(); + ent->nextthink = level.time + 200; + ent->think = AICast_EnableRenderingThink; + + // wait for the clients to return from faded screen + //trap_SetConfigstring( CS_SCREENFADE, va("0 %i 1500", level.time + 500) ); + trap_SetConfigstring( CS_SCREENFADE, va( "0 %i 750", level.time + 500 ) ); + level.reloadPauseTime = level.time + 1100; + + // make sure sound fades up + trap_SendServerCommand( -1, va( "snd_fade 1 %d", 2000 ) ); //----(SA) added + + AICast_CastScriptThink(); + } + } else { + + ready = qtrue; + if ( numSpawningCast != numcast ) { + ready = qfalse; + } else if ( !( ent = AICast_FindEntityForName( "player" ) ) ) { + ready = qfalse; + } else if ( !ent->client || ent->client->pers.connected != CON_CONNECTED ) { + ready = qfalse; + } + + // not loading a game, we must be in a new level, so look for some persistant data to read in, then save the game + if ( ready ) { + G_LoadPersistant(); // make sure we save the game after we have brought across the items + + trap_Cvar_Set( "g_totalPlayTime", "0" ); // reset play time + trap_Cvar_Set( "g_attempts", "0" ); + pcs = AICast_GetCastState( ent->s.number ); + pcs->totalPlayTime = 0; + pcs->lastLoadTime = 0; + pcs->attempts = 0; + + // RF, disabled, since the pregame menu turns this off after the button is pressed, this isn't + // required here + // RF, spawn a thinker that will enable rendering after the client has had time to process the entities and setup the display + //trap_Cvar_Set( "cg_norender", "0" ); + //ent = G_Spawn(); + //ent->nextthink = level.time + 200; + //ent->think = AICast_EnableRenderingThink; + + saveGamePending = qfalse; + + // wait for the clients to return from faded screen +// trap_SetConfigstring( CS_SCREENFADE, va("0 %i 1500", level.time + 500) ); +// trap_SetConfigstring( CS_SCREENFADE, va("0 %i 750", level.time + 500) ); + // (SA) send a command that will be interpreted for both the screenfade and any other effects (music cues, pregame menu, etc) + +// briefing menu will handle transition, just set a cvar for it to check for drawing the 'continue' button + trap_SendServerCommand( -1, "rockandroll\n" ); + + level.reloadPauseTime = level.time + 1100; + + AICast_CastScriptThink(); + } + } +} + +/* +=============== +AICast_SolidsInBBox +=============== +*/ +qboolean AICast_SolidsInBBox( vec3_t pos, vec3_t mins, vec3_t maxs, int entnum, int mask ) { + trace_t tr; + + if ( g_entities[entnum].health <= 0 ) { + return qfalse; + } + + trap_Trace( &tr, pos, mins, maxs, pos, entnum, mask ); + if ( tr.startsolid || tr.allsolid ) { + return qtrue; + } else { + return qfalse; + } +} + +/* +=============== +AICast_Activate +=============== +*/ +void AICast_Activate( int activatorNum, int entNum ) { + cast_state_t *cs; + + cs = AICast_GetCastState( entNum ); + if ( cs->activate ) { + cs->activate( entNum, activatorNum ); + } + + AICast_Printf( AICAST_PRT_DEBUG, "activated entity # %i\n", entNum ); +} + +/* +================ +AICast_NoFlameDamage +================ +*/ +qboolean AICast_NoFlameDamage( int entNum ) { + cast_state_t *cs; + + if ( entNum >= MAX_CLIENTS ) { + return qfalse; + } + + // DHM - Nerve :: Not in multiplayer + if ( g_gametype.integer != GT_SINGLE_PLAYER ) { + return qfalse; + } + + cs = AICast_GetCastState( entNum ); + return ( ( cs->aiFlags & AIFL_NO_FLAME_DAMAGE ) != 0 ); +} + +/* +================ +AICast_SetFlameDamage +================ +*/ +void AICast_SetFlameDamage( int entNum, qboolean status ) { + cast_state_t *cs; + + if ( entNum >= MAX_CLIENTS ) { + return; + } + + // DHM - Nerve :: Not in multiplayer + if ( g_gametype.integer != GT_SINGLE_PLAYER ) { + return; + } + + cs = AICast_GetCastState( entNum ); + + if ( status ) { + cs->aiFlags |= AIFL_NO_FLAME_DAMAGE; + } else { + cs->aiFlags &= ~AIFL_NO_FLAME_DAMAGE; + } +} + +/* +=============== +G_SetAASBlockingEntity + + Adjusts routing so AI knows it can't move through this entity +=============== +*/ +void G_SetAASBlockingEntity( gentity_t *ent, qboolean blocking ) { + ent->AASblocking = blocking; + trap_AAS_SetAASBlockingEntity( ent->r.absmin, ent->r.absmax, blocking ); +} + +/* +=============== +AICast_AdjustIdealYawForMover +=============== +*/ +void AICast_AdjustIdealYawForMover( int entnum, float yaw ) { + cast_state_t *cs = AICast_GetCastState( entnum ); + // + cs->ideal_viewangles[YAW] += yaw; +} + +/* +=============== +AICast_AgePlayTime +=============== +*/ +void AICast_AgePlayTime( int entnum ) { + cast_state_t *cs = AICast_GetCastState( entnum ); + // + if ( saveGamePending ) { + return; + } +// if (reloading) + if ( g_reloading.integer ) { + return; + } + // + if ( ( level.time - cs->lastLoadTime ) > 1000 ) { + if ( /*(level.time - cs->lastLoadTime) < 2000 &&*/ ( level.time - cs->lastLoadTime ) > 0 ) { + cs->totalPlayTime += level.time - cs->lastLoadTime; + trap_Cvar_Set( "g_totalPlayTime", va( "%i", cs->totalPlayTime ) ); + } + // + cs->lastLoadTime = level.time; + } +} + +/* +=============== +AICast_NoReload +=============== +*/ +int AICast_NoReload( int entnum ) { + cast_state_t *cs = AICast_GetCastState( entnum ); + // + return ( ( cs->aiFlags & AIFL_NO_RELOAD ) != 0 ); +} + + +/* +============== +AICast_PlayTime +============== +*/ +int AICast_PlayTime( int entnum ) { + cast_state_t *cs = AICast_GetCastState( entnum ); + return ( cs->totalPlayTime ); +} + +/* +============== +AICast_NumAttempts +============== +*/ +int AICast_NumAttempts( int entnum ) { + cast_state_t *cs = AICast_GetCastState( entnum ); + return ( cs->attempts ); +} + +void AICast_RegisterPain( int entnum ) { + cast_state_t *cs = AICast_GetCastState( entnum ); + if ( cs ) { + cs->lastPain = level.time; + } +} \ No newline at end of file diff --git a/Projects/Android/jni/rtcw/src/game/ai_cast.h b/Projects/Android/jni/rtcw/src/game/ai_cast.h new file mode 100644 index 0000000..2284992 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/game/ai_cast.h @@ -0,0 +1,746 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +//=========================================================================== +// +// Name: ai_cast.h +// Function: Wolfenstein AI Character Routines +// Programmer: Ridah +// Tab Size: 4 (real tabs) +//=========================================================================== + +#include "../botai/ai_main.h" // just so we can use the structures +#include "../botai/ai_dmq3.h" // just so we can use the structures + +#include "ai_cast_fight.h" + +// +// constants/defines +// +#define MAX_AIFUNCS 15 // if we go over this per frame, likely to have an infinite loop +// +#define SIGHT_PER_SEC 50 // do this many sight iterations per second +// +// Cast AI specific action flags (get translated into ucmd's +#define CASTACTION_WALK 1 +// +#define MAX_SCRIPT_ACCUM_BUFFERS 8 +// +#define AICAST_PRT_ALWAYS 0 +#define AICAST_PRT_DEBUG 1 +// +#define DEBUG_FOLLOW_DIST 96 +// +#define MAX_LEADER_DIST 256 +// +#define AASWORLD_STANDARD 0 +#define AASWORLD_LARGE 1 +// +// use this for returning the length of an anim +#define ANIMLENGTH( frames,fps ) ( ( frames * 1000 ) / fps ) +// +#define AICAST_TFL_DEFAULT TFL_DEFAULT & ~( TFL_JUMPPAD | TFL_ROCKETJUMP | TFL_BFGJUMP | TFL_GRAPPLEHOOK | TFL_DOUBLEJUMP | TFL_RAMPJUMP | TFL_STRAFEJUMP | TFL_LAVA ) //----(SA) modified since slime is no longer deadly +//#define AICAST_TFL_DEFAULT TFL_DEFAULT & ~(TFL_JUMPPAD|TFL_ROCKETJUMP|TFL_BFGJUMP|TFL_GRAPPLEHOOK|TFL_DOUBLEJUMP|TFL_RAMPJUMP|TFL_STRAFEJUMP|TFL_SLIME|TFL_LAVA) +// +// AI flags +#define AIFL_CATCH_GRENADE 0x1 +#define AIFL_NO_FLAME_DAMAGE 0x2 +#define AIFL_FIRED 0x4 +#define AIFL_LAND_ANIM_PLAYED 0x8 +#define AIFL_ROLL_ANIM 0x10 +#define AIFL_FLIP_ANIM 0x20 +#define AIFL_STAND_IDLE2 0x40 +#define AIFL_NOAVOID 0x80 // if set, this AI will ignore requests for us to move out the way +#define AIFL_NOPAIN 0x100 // don't stop for pain anims +#define AIFL_WALKFORWARD 0x200 // only walk forward +#define AIFL_DENYACTION 0x400 // used by scripting to prevent dynamic code from executing certain behaviour +#define AIFL_VIEWLOCKED 0x800 // prevent anything outside movement routines from changing view +#define AIFL_CORPSESIGHTING 0x1000 // share information through friendly corpses +#define AIFL_WAITINGTOSPAWN 0x2000 // waiting until space is clear to spawn in to the game +#define AIFL_JUST_SPAWNED 0x4000 +#define AIFL_NO_RELOAD 0x8000 // this character doesn't need to reload +#define AIFL_TALKING 0x10000 +#define AIFL_NO_HEADLOOK 0x20000 +#define AIFL_ATTACK_CROUCH 0x40000 +#define AIFL_MISCFLAG1 0x80000 // used various bits of code, temporarily +#define AIFL_MISCFLAG2 0x100000 // used various bits of code, temporarily +#define AIFL_ZOOMING 0x200000 +#define AIFL_NO_HEADSHOT_DMG 0x400000 +#define AIFL_DIVE_ANIM 0x800000 // able to dive to cover +#define AIFL_NO_TESLA_DAMAGE 0x1000000 +#define AIFL_EXPLICIT_ROUTING 0x2000000 // direct routing towards ai_markers, rather than using AAS +#define AIFL_DISMOUNTING 0x4000000 +#define AIFL_SPECIAL_FUNC 0x8000000 // prevent external interuption of current think func + +// +// predict events +typedef enum +{ + PREDICTSTOP_NONE, + PREDICTSTOP_HITENT, + PREDICTSTOP_HITCLIENT +} predictStop_t; +// +typedef enum +{ + AITEAM_NAZI, + AITEAM_ALLIES, + AITEAM_MONSTER, + AITEAM_SPARE1, + AITEAM_SPARE2, + AITEAM_SPARE3, + AITEAM_SPARE4, + AITEAM_NEUTRAL +} AITeam_t; +// +typedef enum +{ + BBOX_SMALL, + BBOX_LARGE +} BBoxType_t; +// +// attributes +// !!! NOTE: any changes to this must be reflected in the attributeStrings in ai_cast.c +typedef enum +{ + RUNNING_SPEED, // max = 300 (running speed) + WALKING_SPEED, // max = 300 (walking speed) + CROUCHING_SPEED, // max = 300 (crouching speed) + FOV, // max = 360 (field of view) + YAW_SPEED, // max = 300 (yaw speed, so we can make zombie's turn slowly) + LEADER, // max = 1.0 (ability to lead an AI squadron) + AIM_SKILL, // max = 1.0 (skill while aiming) + AIM_ACCURACY, // max = 1.0 (accuracy of firing) + ATTACK_SKILL, // max = 1.0 (ability to attack and do other things, like retreat) + REACTION_TIME, // max = 1.0 (upon seeing enemy, wait this long before reaction) + ATTACK_CROUCH, // max = 1.0 (likely to crouch while firing) + IDLE_CROUCH, // max = 1.0 (likely to crouch while idling) + AGGRESSION, // max = 1.0 (willingness to fight till the death) + TACTICAL, // max = 1.0 (ability to use strategy to their advantage, also behaviour whilst hunting enemy, more likely to creep around) + CAMPER, // max = 1.0 (set this to make them stay in the spot they are spawned) + ALERTNESS, // max = 1.0 (ability to notice enemies at long range) + STARTING_HEALTH, // MAX = 999 (starting health) + HEARING_SCALE, // max = 999 (multiply default hearing ranges by this) + HEARING_SCALE_NOT_PVS, // max = 999 (multiply hearing range by this if outside PVS) + INNER_DETECTION_RADIUS, // default = 512 (enemies within this range trigger immediate combat mode + PAIN_THRESHOLD_SCALE, // default = 1.0 + + AICAST_MAX_ATTRIBUTES + +} castAttributes_t; +// +typedef enum +{ + SIGHTSOUNDSCRIPT, + ATTACKSOUNDSCRIPT, + ORDERSSOUNDSCRIPT, + DEATHSOUNDSCRIPT, + QUIETDEATHSOUNDSCRIPT, //----(SA) ADDED FOR SILENT DEATHS (SNIPER/KNIFE) + FLAMEDEATHSOUNDSCRIPT, //----(SA) ADDED FOR FLAMING + PAINSOUNDSCRIPT, + + STAYSOUNDSCRIPT, + FOLLOWSOUNDSCRIPT, + ORDERSDENYSOUNDSCRIPT, + MISC1SOUNDSCRIPT, + + MAX_AI_EVENT_SOUNDS +} AIEventSounds_t; +// +typedef struct { + char *name; + float attributes[AICAST_MAX_ATTRIBUTES]; + + char *soundScripts[MAX_AI_EVENT_SOUNDS]; + + int aiTeam; + char *skin; + int weapons[8]; + int bboxType; + vec2_t crouchstandZ; + int aiFlags; + + char *( *aifuncAttack1 )( struct cast_state_s *cs ); //use this battle aifunc for monster_attack1 + char *( *aifuncAttack2 )( struct cast_state_s *cs ); //use this battle aifunc for monster_attack2 + char *( *aifuncAttack3 )( struct cast_state_s *cs ); //use this battle aifunc for monster_attack2 + + char *loopingSound; // play this sound constantly while alive + + aistateEnum_t aiState; +} AICharacterDefaults_t; + +// +// script flags +#define SFL_NOCHANGEWEAPON 0x1 +#define SFL_NOAIDAMAGE 0x2 +#define SFL_FRIENDLYSIGHTCORPSE_TRIGGERED 0x4 +#define SFL_WAITING_RESTORE 0x8 +#define SFL_FIRST_CALL 0x10 +// +// attributes strings (used for per-entity attribute definitions) +// NOTE: these must match the attributes above) +extern char *castAttributeStrings[]; +extern AICharacterDefaults_t aiDefaults[NUM_CHARACTERS]; +// +// structure defines +// +#define AIVIS_ENEMY 1 +#define AIVIS_INSPECTED 2 // we have inspected them once already +#define AIVIS_INSPECT 4 // we should inspect them when we get a chance +#define AIVIS_PROCESS_SIGHTING 8 // so we know if we have or haven't processed the sighting since they were last seen +#define AIVIS_SIGHT_SCRIPT_CALLED 0x10 // set once sight script has been called.. only call once +// +// share range +#define AIVIS_SHARE_RANGE 384 // if we are within this range of a friendly, share their vis info +// +#define MAX_CHASE_MARKERS 3 +#define CHASE_MARKER_INTERVAL 1000 +// +#define COMBAT_TIMEOUT 8000 +// sight info +typedef struct +{ + int flags; + int lastcheck_timestamp; + int real_visible_timestamp; + int real_update_timestamp; + int real_notvisible_timestamp; + int visible_timestamp; // time we last recorded a sighting + vec3_t visible_pos; // position we last knew of them being at (could be hearing, etc) + vec3_t real_visible_pos; // position we last physically saw them + vec3_t visible_vel; // velocity during last sighting + int notvisible_timestamp; // last time we didn't see the entity (used for reaction delay) + vec3_t chase_marker[MAX_CHASE_MARKERS]; + int chase_marker_count; + int lastcheck_health; +} cast_visibility_t; +// +// starting weapons, ammo, etc +typedef struct +{ + int startingWeapons[MAX_WEAPONS / ( sizeof( int ) * 8 )]; + int startingAmmo[MAX_WEAPONS]; // starting ammo values for each weapon (set to 999 for unlimited) +} cast_weapon_info_t; +// +// scripting +typedef struct +{ + char *actionString; + qboolean ( *actionFunc )( struct cast_state_s *cs, char *params ); +} cast_script_stack_action_t; +// +typedef struct +{ + // + // set during script parsing + cast_script_stack_action_t *action; // points to an action to perform + char *params; +} cast_script_stack_item_t; +// +#define AICAST_MAX_SCRIPT_STACK_ITEMS 64 +// +typedef struct +{ + cast_script_stack_item_t items[AICAST_MAX_SCRIPT_STACK_ITEMS]; + int numItems; +} cast_script_stack_t; +// +typedef struct +{ + int eventNum; // index in scriptEvents[] + char *params; // trigger targetname, etc + cast_script_stack_t stack; +} cast_script_event_t; +// +typedef struct +{ + char *eventStr; + qboolean ( *eventMatch )( cast_script_event_t *event, char *eventParm ); +} cast_script_event_define_t; +// +typedef struct +{ + int castScriptStackHead, castScriptStackChangeTime; + int castScriptEventIndex; // current event containing stack of actions to perform + // scripting system AI variables (set by scripting system, used directly by AI) + int scriptId; // incremented each time the script changes + int scriptFlags; + int scriptNoAttackTime; + int scriptNoMoveTime; + int playAnimViewlockTime; + int scriptGotoEnt; // just goto them, then resume normal behaviour (don't follow) + int scriptGotoId; + vec3_t scriptWaitPos; + int scriptWaitMovetime; + vec3_t scriptWaitHidePos; + int scriptWaitHideTime; + int scriptNoSightTime; + int scriptAttackEnt; // we should always attack this AI if they are alive + vec3_t playanim_viewangles; +} cast_script_status_t; +// +typedef struct +{ + aistateEnum_t currentState; + aistateEnum_t nextState; + int nextStateTimer; // time left until "newState" is reached +} aistate_t; +// +typedef enum +{ + MS_DEFAULT, + MS_WALK, + MS_RUN, + MS_CROUCH +} movestate_t; +// +typedef enum +{ + MSTYPE_NONE, + MSTYPE_TEMPORARY, + MSTYPE_PERMANENT +} movestateType_t; +// +// +typedef struct aicast_checkattack_cache_s +{ + int enemy; + qboolean allowHitWorld; + int time; + int weapon; + qboolean result; +} aicast_checkattack_cache_t; +// +// -------------------------------------------------------------------------------- +// the main cast structure +typedef struct cast_state_s +{ + bot_state_t *bs; + int entityNum; + + int aasWorldIndex; // set this according to our bounding box type + + // Cast specific information follows. Add to this as needed, this way the bot_state_t structure + // remains untouched. + + int aiCharacter; + int aiFlags; + int lastThink; // time they last thinked, so we can vary the think times + int actionFlags; // cast AI specific movement flags + int lastPain, lastPainDamage; + int travelflags; + int thinkFuncChangeTime; + + aistateEnum_t aiState; + movestate_t movestate; // walk, run, crouch etc (can be specified in a script) + movestateType_t movestateType; // temporary, permanent, etc + + float attributes[AICAST_MAX_ATTRIBUTES]; + // these define the abilities of each cast AI + + // scripting system + int numCastScriptEvents; + cast_script_event_t *castScriptEvents; // contains a list of actions to perform for each event type + cast_script_status_t castScriptStatus; // current status of scripting + cast_script_status_t castScriptStatusCurrent; // scripting status to use for backups + cast_script_status_t castScriptStatusBackup; // perm backup of status of scripting, only used by backup and restore commands + int scriptCallIndex; // inc'd each time a script is called + int scriptAnimTime, scriptAnimNum; // last time an anim was played using scripting + // the accumulation buffer + int scriptAccumBuffer[MAX_SCRIPT_ACCUM_BUFFERS]; + + // + cast_weapon_info_t *weaponInfo; // FIXME: make this a list, so they can have multiple weapons? + cast_visibility_t vislist[MAX_CLIENTS]; // array of all other client entities, allocated at level start-up + int weaponFireTimes[MAX_WEAPONS]; + + char *( *aifunc )( struct cast_state_s *cs ); //current AI function + char *( *oldAifunc )( struct cast_state_s *cs ); // just so we can restore the last aiFunc if required + + char *( *aifuncAttack1 )( struct cast_state_s *cs ); //use this battle aifunc for monster_attack1 + char *( *aifuncAttack2 )( struct cast_state_s *cs ); //use this battle aifunc for monster_attack2 + char *( *aifuncAttack3 )( struct cast_state_s *cs ); //use this battle aifunc for monster_attack2 + + void ( *painfunc )( gentity_t *ent, gentity_t *attacker, int damage, vec3_t point ); + void ( *deathfunc )( gentity_t *ent, gentity_t *attacker, int damage, int mod ); //----(SA) added mod + void ( *sightfunc )( gentity_t *ent, gentity_t *other, int lastSight ); + + //int (*getDeathAnim)(gentity_t *ent, gentity_t *attacker, int damage); + void ( *sightEnemy )( gentity_t *ent, gentity_t *other ); + void ( *sightFriend )( gentity_t *ent, gentity_t *other ); + + void ( *activate )( int entNum, int activatorNum ); + + // + // !!! NOTE: make sure any entityNum type variables get initialized + // to -1 in AICast_CreateCharacter(), or they'll be defaulting to + // the player (index 0) + // + + // goal/AI stuff + + int followEntity; + float followDist; + qboolean followIsGoto; // we are really just going to the entity, but should wait until scripting tells us we can stop + int followTime; // if this runs out, the scripting has probably been interupted + qboolean followSlowApproach; + + int leaderNum; // entnum of player we are following + + float speedScale; // so we can vary movement speed + + float combatGoalTime; + vec3_t combatGoalOrigin; + + int lastGetHidePos; + int startAttackCount; // incremented each time we start a standing attack + // used to make sure we only find a combat spot once per attack + int combatSpotAttackCount; + int combatSpotDelayTime; + int startBattleChaseTime; + + int blockedTime; // time they were last blocked by a solid entity + int obstructingTime; // time that we should move so we are not obstructing someone else + vec3_t obstructingPos; + + int blockedAvoidTime; + float blockedAvoidYaw; + + int deathTime; + int rebirthTime, revivingTime; + + // battle values + int enemyHeight; + int enemyDist; + + vec3_t takeCoverPos, takeCoverEnemyPos; + int takeCoverTime; + + int attackSpotTime; + + int triggerReleaseTime; + + int lastWeaponFired; // set each time a weapon is fired. used to detect when a weapon has been fired from within scripting + vec3_t lastWeaponFiredPos; + int lastWeaponFiredWeaponNum; + + // idle behaviour stuff + int lastEnemy, nextIdleAngleChange; + float idleYawChange, idleYaw; + + qboolean crouchHideFlag; + + int doorMarker, doorEntNum; + + // Rafael + int attackSNDtime; + int attacksnd; + int painSoundTime; + int firstSightTime; + qboolean secondDeadTime; + // done + + int startGrenadeFlushTime; + int lockViewAnglesTime; + int grenadeFlushEndTime; + int grenadeFlushFiring; + + int dangerEntity; + int dangerEntityValidTime; // dangerEntity is valid until this time expires + vec3_t dangerEntityPos; // dangerEntity is predicted to end up here + int dangerEntityTimestamp; // time this danger was recorded + float dangerDist; + + int mountedEntity; // mg42, etc that we have mounted + int inspectBodyTime; + vec3_t startOrigin; + + int damageQuota; + int damageQuotaTime; + + int dangerLastGetAvoid; + int lastAvoid; + + int doorMarkerTime, doorMarkerNum, doorMarkerDoor; + + int pauseTime; // absolutely don't move move while this is > level.time + + aicast_checkattack_cache_t checkAttackCache; + + int secretsFound; + + int attempts; + + qboolean grenadeGrabFlag; // if this is set, we need to play the anim before we can grab it + + vec3_t lastMoveToPosGoalOrg; // if this changes, we should reset the Bot Avoid Reach + + int noAttackTime; // used by dynamic AI to stop attacking for set time + + int lastRollMove; + int lastFlipMove; + + vec3_t stimFlyAttackPos; + + int lastDodgeRoll; // last time we rolled to get out of our enemies direct aim + int battleRollTime; + + vec3_t viewlock_viewangles; + int grenadeKickWeapon; + + int animHitCount; // for stepping through the frames on which to inflict damage + + int totalPlayTime, lastLoadTime; + + int queryStartTime, queryCountValidTime, queryCount, queryAlertSightTime; + + int lastScriptSound; + + int inspectNum; + + int scriptPauseTime; + + int bulletImpactEntity; + int bulletImpactTime; // last time we heard/saw a bullet impact + int bulletImpactIgnoreTime; + vec3_t bulletImpactStart, bulletImpactEnd; + + int audibleEventTime; + vec3_t audibleEventOrg; + int audibleEventEnt; + + int battleChaseMarker, battleChaseMarkerDir; + + int lastBattleHunted; // last time an enemy decided to hunt us + int battleHuntPauseTime, battleHuntViewTime; + + int lastAttackCrouch; + + int lastMoveThink; // last time we ran our ClientThink() + + int numEnemies; // last count of enemies that are currently pursuing us + + int noReloadTime; // dont reload prematurely until this time has expired + + int lastValidAreaNum[2]; // last valid area within each AAS world + int lastValidAreaTime[2]; // time we last got the area + + int weaponNum; // our current weapon + int enemyNum; // our current enemy + vec3_t ideal_viewangles, viewangles; + usercmd_t lastucmd; + int attackcrouch_time; + int bFlags; + + int deadSinkStartTime; + + int lastActivate; + + vec3_t loperLeapVel; + // ------------------------------------------------------------------------------------------- + // if working on a post release patch, new variables should ONLY be inserted after this point + // ------------------------------------------------------------------------------------------- + +} cast_state_t; +// +#define CSFOFS( x ) ( (int)&( ( (cast_state_t *)0 )->x ) ) +// +typedef struct aicast_predictmove_s +{ + vec3_t endpos; //position at the end of movement prediction + vec3_t velocity; //velocity at the end of movement prediction + int presencetype; //presence type at end of movement prediction + int stopevent; //event that made the prediction stop + float time; //time predicted ahead + int frames; //number of frames predicted ahead + int numtouch; + int touchents[MAXTOUCH]; + int groundEntityNum; +} aicast_predictmove_t; +// +// variables/globals +// +//cast states +extern cast_state_t *caststates; +//number of characters +extern int numcast; +// +// minimum time between thinks (maximum is double this) +extern int aicast_thinktime; +// maximum number of character thinks at once +extern int aicast_maxthink; +// maximum clients +extern int aicast_maxclients; +// skill scale +extern float aicast_skillscale; +// +// cvar to enable aicast debugging, set higher for more levels of debugging +extern vmCvar_t aicast_debug; +extern vmCvar_t aicast_debugname; +extern vmCvar_t aicast_scripts; +// +// +// procedure defines +// +// ai_cast.c +void AIChar_SetBBox( gentity_t *ent, cast_state_t *cs, qboolean useHeadTag ); +void AICast_Printf( int type, const char *fmt, ... ); +gentity_t *AICast_CreateCharacter( gentity_t *ent, float *attributes, cast_weapon_info_t *weaponInfo, char *castname, char *model, char *head, char *sex, char *color, char *handicap ); +void AICast_Init( void ); +void AICast_DelayedSpawnCast( gentity_t *ent, int castType ); +qboolean AICast_SolidsInBBox( vec3_t pos, vec3_t mins, vec3_t maxs, int entnum, int mask ); +void AICast_CheckLevelAttributes( cast_state_t *cs, gentity_t *ent, char **ppStr ); +// +// ai_cast_sight.c +void AICast_SightUpdate( int numchecks ); +qboolean AICast_VisibleFromPos( vec3_t srcpos, int srcnum, + vec3_t destpos, int destnum, qboolean updateVisPos ); +void AICast_UpdateVisibility( gentity_t *srcent, gentity_t *destent, qboolean shareVis, qboolean directview ); +qboolean AICast_CheckVisibility( gentity_t *srcent, gentity_t *destent ); +// +// ai_cast_debug.c +void AICast_DBG_InitAIFuncs( void ); +void AICast_DBG_AddAIFunc( cast_state_t *cs, char *funcname ); +void AICast_DBG_ListAIFuncs( cast_state_t *cs, int numprint ); +void AICast_DBG_RouteTable_f( vec3_t org, char *param ); +int Sys_MilliSeconds( void ); +void AICast_DebugFrame( cast_state_t *cs ); +// +// ai_cast_funcs.c +void AICast_SpecialFunc( cast_state_t *cs ); +bot_moveresult_t *AICast_MoveToPos( cast_state_t *cs, vec3_t pos, int entnum ); +float AICast_SpeedScaleForDistance( cast_state_t *cs, float startdist, float idealDist ); +char *AIFunc_DefaultStart( cast_state_t *cs ); +char *AIFunc_IdleStart( cast_state_t *cs ); +char *AIFunc_ChaseGoalIdleStart( cast_state_t *cs, int entitynum, float reachdist ); +char *AIFunc_ChaseGoalStart( cast_state_t *cs, int entitynum, float reachdist, qboolean slowApproach ); +char *AIFunc_BattleChaseStart( cast_state_t *cs ); +char *AIFunc_BattleStart( cast_state_t *cs ); +char *AIFunc_DoorMarkerStart( cast_state_t *cs, int doornum, int markernum ); +char *AIFunc_DoorMarker( cast_state_t *cs ); +char *AIFunc_BattleTakeCoverStart( cast_state_t *cs ); +char *AIFunc_GrenadeFlushStart( cast_state_t *cs ); +char *AIFunc_AvoidDangerStart( cast_state_t *cs ); +char *AIFunc_BattleMG42Start( cast_state_t *cs ); +char *AIFunc_InspectBodyStart( cast_state_t *cs ); +char *AIFunc_GrenadeKickStart( cast_state_t *cs ); +char *AIFunc_InspectFriendlyStart( cast_state_t *cs, int entnum ); +char *AIFunc_InspectBulletImpactStart( cast_state_t *cs ); +char *AIFunc_InspectAudibleEventStart( cast_state_t *cs, int entnum ); +char *AIFunc_BattleAmbushStart( cast_state_t *cs ); +char *AIFunc_BattleHuntStart( cast_state_t *cs ); +// +// ai_cast_func_attack.c +char *AIFunc_ZombieFlameAttackStart( cast_state_t *cs ); +char *AIFunc_ZombieAttack2Start( cast_state_t *cs ); +char *AIFunc_ZombieMeleeStart( cast_state_t *cs ); +char *AIFunc_LoperAttack1Start( cast_state_t *cs ); +char *AIFunc_LoperAttack2Start( cast_state_t *cs ); +char *AIFunc_LoperAttack3Start( cast_state_t *cs ); +char *AIFunc_StimSoldierAttack1Start( cast_state_t *cs ); +char *AIFunc_StimSoldierAttack2Start( cast_state_t *cs ); +char *AIFunc_BlackGuardAttack1Start( cast_state_t *cs ); +char *AIFunc_RejectAttack1Start( cast_state_t *cs ); //----(SA) +char *AIFunc_WarriorZombieMeleeStart( cast_state_t *cs ); +char *AIFunc_WarriorZombieSightStart( cast_state_t *cs ); +char *AIFunc_WarriorZombieDefenseStart( cast_state_t *cs ); +// +// ai_cast_func_boss1.c +char *AIFunc_Helga_SpiritAttack_Start( cast_state_t *cs ); +char *AIFunc_Helga_MeleeStart( cast_state_t *cs ); +char *AIFunc_FlameZombie_PortalStart( cast_state_t *cs ); +char *AIFunc_Heinrich_MeleeStart( cast_state_t *cs ); +char *AIFunc_Heinrich_RaiseDeadStart( cast_state_t *cs ); +char *AIFunc_Heinrich_SpawnSpiritsStart( cast_state_t *cs ); +void AICast_Heinrich_SoundPrecache( void ); +// +// ai_cast_fight.c +qboolean AICast_StateChange( cast_state_t *cs, aistateEnum_t newaistate ); +void AICast_WeaponSway( cast_state_t *cs, vec3_t ofs ); +int AICast_ScanForEnemies( cast_state_t *cs, int *enemies ); +void AICast_UpdateBattleInventory( cast_state_t *cs, int enemy ); +float AICast_Aggression( cast_state_t *cs ); +int AICast_WantsToChase( cast_state_t *cs ); +int AICast_WantsToTakeCover( cast_state_t *cs, qboolean attacking ); +qboolean AICast_EntityVisible( cast_state_t *cs, int enemynum, qboolean directview ); +bot_moveresult_t AICast_CombatMove( cast_state_t *cs, int tfl ); +qboolean AICast_AimAtEnemy( cast_state_t *cs ); +qboolean AICast_CheckAttackAtPos( int entnum, int enemy, vec3_t pos, qboolean ducking, qboolean allowHitWorld ); +qboolean AICast_CheckAttack( cast_state_t *cs, int enemy, qboolean allowHitWorld ); +void AICast_ProcessAttack( cast_state_t *cs ); +void AICast_ChooseWeapon( cast_state_t *cs, qboolean battleFunc ); +qboolean AICast_GetTakeCoverPos( cast_state_t *cs, int enemyNum, vec3_t enemyPos, vec3_t returnPos ); +qboolean AICast_CanMoveWhileFiringWeapon( int weaponnum ); +float AICast_GetWeaponSoundRange( int weapon ); +qboolean AICast_StopAndAttack( cast_state_t *cs ); +qboolean AICast_WantToRetreat( cast_state_t *cs ); +int AICast_SafeMissileFire( gentity_t *ent, int duration, int enemyNum, vec3_t enemyPos, int selfNum, vec3_t endPos ); +void AIChar_AttackSound( cast_state_t *cs ); +qboolean AICast_GotEnoughAmmoForWeapon( cast_state_t *cs, int weapon ); +qboolean AICast_HostileEnemy( cast_state_t *cs, int enemynum ); +qboolean AICast_QueryEnemy( cast_state_t *cs, int enemynum ); +void AICast_AudibleEvent( int srcnum, vec3_t pos, float range ); +qboolean AICast_WeaponUsable( cast_state_t *cs, int weaponNum ); +float AICast_WeaponRange( cast_state_t *cs, int weaponnum ); + +// +// ai_cast_events.c +void AICast_Pain( gentity_t *targ, gentity_t *attacker, int damage, vec3_t point ); +void AICast_Die( gentity_t *self, gentity_t *inflictor, gentity_t *attacker, int damage, int meansOfDeath ); +void AICast_Sight( gentity_t *ent, gentity_t *other, int lastSight ); +void AICast_EndChase( cast_state_t *cs ); +void AICast_ProcessActivate( int entNum, int activatorNum ); +// +// ai_cast_think.c +void AICast_Think( int client, float thinktime ); +void AICast_UpdateInput( cast_state_t *cs, int time ); +void AICast_InputToUserCommand( cast_state_t * cs, bot_input_t * bi, usercmd_t * ucmd, int delta_angles[3] ); +void AICast_PredictMovement( cast_state_t *cs, int numframes, float frametime, aicast_predictmove_t *move, usercmd_t *ucmd, int checkHitEnt ); +void AICast_Blocked( cast_state_t *cs, bot_moveresult_t *moveresult, int activate, bot_goal_t *goal ); +qboolean AICast_RequestCrouchAttack( cast_state_t *cs, vec3_t org, float time ); +qboolean AICast_GetAvoid( cast_state_t *cs, bot_goal_t *goal, vec3_t outpos, qboolean reverse, int blockEnt ); +void AICast_QueryThink( cast_state_t *cs ); +void AICast_DeadClipWalls( cast_state_t *cs ); +void AICast_IdleReload( cast_state_t *cs ); +// +// ai_cast_script.c +qboolean AICast_ScriptRun( cast_state_t *cs, qboolean force ); +// +// ai_cast_soldier.c +void AIChar_spawn( gentity_t *ent ); +// +// other/external defines +void BotCheckAir( bot_state_t *bs ); +void BotUpdateInput( bot_state_t *bs, int time ); +float AngleDifference( float ang1, float ang2 ); +float BotChangeViewAngle( float angle, float ideal_angle, float speed ); +void BotInputToUserCommand( bot_input_t * bi, usercmd_t * ucmd, int delta_angles[3] ); +void GibEntity( gentity_t *self, int killer ); +void GibHead( gentity_t *self, int killer ); +// +extern bot_state_t *botstates[MAX_CLIENTS]; diff --git a/Projects/Android/jni/rtcw/src/game/ai_cast_characters.c b/Projects/Android/jni/rtcw/src/game/ai_cast_characters.c new file mode 100644 index 0000000..ec414de --- /dev/null +++ b/Projects/Android/jni/rtcw/src/game/ai_cast_characters.c @@ -0,0 +1,1822 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +/* + * name: ai_cast_characters.c + * + * desc: + * + * $Archive: /Wolf5/src/game/ai_cast_characters.c $ +*/ + +#include "g_local.h" +#include "../game/botlib.h" //bot lib interface +#include "../game/be_aas.h" +#include "../game/be_ea.h" +#include "../game/be_ai_gen.h" +#include "../game/be_ai_goal.h" +#include "../game/be_ai_move.h" +#include "../botai/botai.h" //bot ai interface + +#include "ai_cast.h" + +//--------------------------------------------------------------------------- +// Character specific attributes (defaults, these can be altered in the editor (TODO!)) +AICharacterDefaults_t aiDefaults[NUM_CHARACTERS] = { + + //AICHAR_NONE + {0}, + + //AICHAR_SOLDIER + { + "Soldier", + { + 220, // running speed + 90, // walking speed + 80, // crouching speed + 90, // Field of View + 200, // Yaw Speed // RF change + 0.0, // leader + 0.5, // aim skill + 0.5, // aim accuracy + 0.75, // attack skill + 0.5, // reaction time + 0.4, // attack crouch + 0.0, // idle crouch + 0.5, // aggression + 0.8, // tactical + 0.0, // camper + 16000, // alertness + 100, // starting health + 1.0, // hearing scale + 0.9, // not in pvs hearing scale + 512, // relaxed detection radius + 1.0, // pain threshold multiplier + }, + { + "infantrySightPlayer", + "infantryAttackPlayer", + "infantryOrders", + "infantryDeath", + "infantrySilentDeath", //----(SA) added + "infantryFlameDeath", //----(SA) added + "infantryPain", + "infantryStay", // stay - you're told to stay put + "infantryFollow", // follow - go with ordering player ("i'm with you" rather than "yes sir!") + "infantryOrdersDeny", // deny - refuse orders (doing something else) + }, + AITEAM_NAZI, // team + "infantryss/default", // default model/skin + {WP_MP40,WP_GRENADE_LAUNCHER}, // starting weapons + BBOX_SMALL, {32,48}, // bbox, crouch/stand height + AIFL_CATCH_GRENADE | AIFL_STAND_IDLE2, // flags + NULL, NULL, NULL, // special attack routine + NULL, // looping sound + AISTATE_RELAXED + }, + + //AICHAR_AMERICAN + { + "American", + { + 220, // running speed + 90, // walking speed + 80, // crouching speed + 90, // Field of View + 200, // Yaw Speed // RF change + 0.0, // leader + 0.70, // aim skill + 0.70, // aim accuracy + 0.75, // attack skill + 0.5, // reaction time + 0.3, // attack crouch + 0.0, // idle crouch + 0.5, // aggression + 0.8, // tactical + 0.0, // camper + 16000, // alertness + 100, // starting health + 1.0, // hearing scale + 0.9, // not in pvs hearing scale + 512, // relaxed detection radius + 1.0, // pain threshold multiplier + }, + { + "americanSightPlayer", + "americanAttackPlayer", + "americanOrders", + "americanDeath", + "americanSilentDeath", //----(SA) added + "americanFlameDeath", //----(SA) added + "americanPain", + "americanStay", // stay - you're told to stay put + "americanFollow", // follow - go with ordering player ("i'm with you" rather than "yes sir!") + "americanOrdersDeny", // deny - refuse orders (doing something else) + }, + AITEAM_ALLIES, + "american/default", + {WP_THOMPSON,WP_GRENADE_PINEAPPLE}, + BBOX_SMALL, {32,48}, + AIFL_CATCH_GRENADE | AIFL_STAND_IDLE2, + NULL, NULL, NULL, + NULL, + AISTATE_RELAXED + }, + + //AICHAR_ZOMBIE + { + "Zombie", + { + 200, // running speed //----(SA) DK requested change + 60, // walking speed //----(SA) DK requested change + 80, // crouching speed + 90, // Field of View + 350, // Yaw Speed + 0.0, // leader + 0.70, // aim skill + 0.70, // aim accuracy + 0.75, // attack skill + 0.1, // reaction time + 0.0, // attack crouch + 0.0, // idle crouch + 1.0, // aggression + 0.0, // tactical + 0.0, // camper + 16000, // alertness + 180, // starting health + 1.0, // hearing scale + 0.9, // not in pvs hearing scale + 512, // relaxed detection radius + 1.0, // pain threshold multiplier + }, + { + "zombieSightPlayer", + "zombieAttackPlayer", + "zombieOrders", + "zombieDeath", + "zombieSilentDeath", //----(SA) added + "zombieFlameDeath", //----(SA) added + "zombiePain", + "sound/weapons/melee/fstatck.wav", // stay - you're told to stay put + "sound/weapons/melee/fstmiss.wav", // follow - go with ordering player ("i'm with you" rather than "yes sir!") + "zombieOrdersDeny", // deny - refuse orders (doing something else) + }, + AITEAM_MONSTER, + "zombie/default", + { /*WP_GAUNTLET,*/ WP_MONSTER_ATTACK2, WP_MONSTER_ATTACK3}, + BBOX_SMALL, {32,48}, + /*AIFL_NOPAIN|AIFL_WALKFORWARD|*/ AIFL_NO_RELOAD, + AIFunc_ZombieFlameAttackStart, AIFunc_ZombieAttack2Start, AIFunc_ZombieMeleeStart, + NULL, + AISTATE_ALERT + }, + + //AICHAR_WARZOMBIE + { + "WarriorZombie", + { + 250, // running speed (SA) upped from 200->250 per Mike/DK + 60, // walking speed + 80, // crouching speed + 90, // Field of View + 350, // Yaw Speed + 0.0, // leader + 0.70, // aim skill + 0.70, // aim accuracy + 0.75, // attack skill + 0.1, // reaction time + 0.0, // attack crouch + 0.0, // idle crouch + 1.0, // aggression + 0.0, // tactical + 0.0, // camper + 16000, // alertness + 180, // starting health + 1.0, // hearing scale + 0.9, // not in pvs hearing scale + 512, // relaxed detection radius + 1.0, // pain threshold multiplier + }, + { + "warzombieSightPlayer", + "warzombieAttackPlayer", + "warzombieOrders", + "warzombieDeath", + "warzombieSilentDeath", //----(SA) added + "warzombieFlameDeath", //----(SA) added + "warzombiePain", +//----(SA) changed per DK +// "sound/weapons/melee/fstatck.wav", // stay - you're told to stay put + "sound/weapons/melee/warz_hit.wav", +// "sound/weapons/melee/fstmiss.wav", // follow - go with ordering player ("i'm with you" rather than "yes sir!") + "sound/weapons/melee/warz_miss.wav", + "warzombieOrdersDeny", // deny - refuse orders (doing something else) + }, + AITEAM_MONSTER, + "warrior/crypt2", + {WP_MONSTER_ATTACK1,WP_MONSTER_ATTACK2,WP_MONSTER_ATTACK3}, + BBOX_SMALL, {10,48}, // very low defense position + AIFL_NO_RELOAD, + AIFunc_WarriorZombieMeleeStart, /*AIFunc_WarriorZombieSightStart*/ NULL, AIFunc_WarriorZombieDefenseStart, + NULL, + AISTATE_ALERT + }, + + //AICHAR_VENOM + { + "Venom", + { + 110, // running speed + 100, // walking speed + 80, // crouching speed + 90, // Field of View + 200, // Yaw Speed + 0.0, // leader + 0.70, // aim skill + 0.70, // aim accuracy + 0.75, // attack skill + 0.5, // reaction time + 0.05, // attack crouch + 0.0, // idle crouch + 0.9, // aggression + 0.2, // tactical + 0.0, // camper + 16000, // alertness + 240, // starting health + 1.0, // hearing scale + 0.9, // not in pvs hearing scale + 512, // relaxed detection radius + 1.0, // pain threshold multiplier + }, + { + "venomSightPlayer", + "venomAttackPlayer", + "venomOrders", + "venomDeath", + "venomSilentDeath", //----(SA) added + "venomFlameDeath", //----(SA) added + "venomPain", + "venomStay", // stay - you're told to stay put + "venomFollow", // follow - go with ordering player ("i'm with you" rather than "yes sir!") + "venomOrdersDeny", // deny - refuse orders (doing something else) + }, + AITEAM_NAZI, + "venom/default", + {WP_FLAMETHROWER}, + BBOX_SMALL, {32,48}, + AIFL_NO_FLAME_DAMAGE | AIFL_WALKFORWARD | AIFL_NO_RELOAD, // |AIFL_NO_HEADSHOT_DMG, + NULL, NULL, NULL, + NULL, + AISTATE_RELAXED + }, + + //AICHAR_LOPER + { + "Loper", + { + 220, // running speed + 70, // walking speed + 220, // crouching speed + 90, // Field of View + 200, // Yaw Speed + 0.0, // leader + 0.70, // aim skill + 0.70, // aim accuracy + 0.75, // attack skill + 0.8, // reaction time + 0.05, // attack crouch + 0.0, // idle crouch + 1.0, // aggression + 0.1, // tactical + 0.0, // camper + 16000, // alertness + 500, // starting health + 1.0, // hearing scale + 0.9, // not in pvs hearing scale + 512, // relaxed detection radius + 1.0, // pain threshold multiplier + }, + { + "loperSightPlayer", + "loperAttackPlayer", + "loperOrders", + "loperDeath", + "loperSilentDeath", //----(SA) added + "loperFlameDeath", //----(SA) added + "loperPain", + "loperAttack2Start", // stay - you're told to stay put + "loperAttackStart", // follow - go with ordering player ("i'm with you" rather than "yes sir!") + "loperHit1", // deny - refuse orders (doing something else) + "loperHit2", // misc1 + }, + AITEAM_MONSTER, + "loper/default", + { /*WP_MONSTER_ATTACK1,*/ WP_MONSTER_ATTACK2,WP_MONSTER_ATTACK3}, + BBOX_LARGE, {32,32}, // large is for wide characters + AIFL_NO_RELOAD, + NULL /*AIFunc_LoperAttack1Start*/, AIFunc_LoperAttack2Start, AIFunc_LoperAttack3Start, + "sound/world/electloop.wav", + AISTATE_ALERT + }, + + //AICHAR_ELITEGUARD + { + "Elite Guard", + { + 230, // running speed + 90, // walking speed + 100, // crouching speed + 90, // Field of View + 200, // Yaw Speed // RF change + 0.0, // leader + 0.5, // aim skill + 1.0, // aim accuracy + 0.9, // attack skill + 0.3, // reaction time + 0.4, // attack crouch + 0.0, // idle crouch + 0.5, // aggression + 1.0, // tactical + 0.0, // camper + 16000, // alertness + 120, // starting health + 1.0, // hearing scale + 0.9, // not in pvs hearing scale + 512, // relaxed detection radius + 1.0, // pain threshold multiplier + }, + { + "eliteGuardSightPlayer", + "eliteGuardAttackPlayer", + "eliteGuardOrders", + "eliteGuardDeath", + "eliteGuardSilentDeath", //----(SA) added + "eliteGuardFlameDeath", //----(SA) added + "eliteGuardPain", + "eliteGuardStay", // stay - you're told to stay put + "eliteGuardFollow", // follow - go with ordering player ("i'm with you" rather than "yes sir!") + "eliteGuardOrdersDeny", // deny - refuse orders (doing something else) + }, + AITEAM_NAZI, + "eliteguard/default", + {WP_SILENCER}, //----(SA) TODO: replace w/ "silenced luger" + BBOX_SMALL, {32,48}, + AIFL_CATCH_GRENADE | AIFL_STAND_IDLE2, + NULL, NULL, NULL, + NULL, + AISTATE_RELAXED + }, + + //AICHAR_STIMSOLDIER1 + { + "Stim Soldier", + { + 170, // running speed + 100, // walking speed + 90, // crouching speed + 90, // Field of View + 150, // Yaw Speed + 0.0, // leader + 0.7, // aim skill + 1.0, // aim accuracy + 0.9, // attack skill + 0.6, // reaction time + 0.05, // attack crouch + 0.0, // idle crouch + 0.9, // aggression + 0.1, // tactical + 0.0, // camper + 16000, // alertness + 300, // starting health + 1.0, // hearing scale + 0.9, // not in pvs hearing scale + 512, // relaxed detection radius + 1.0, // pain threshold multiplier + }, + { + "stimSoldierSightPlayer", + "stimSoldierAttackPlayer", + "stimSoldierOrders", + "stimSoldierDeath", + "stimSoldierSilentDeath", //----(SA) added + "stimSoldeirFlameDeath", //----(SA) added + "stimSoldierPain", + "stimSoldierStay", // stay - you're told to stay put + "stimSoldierFollow", // follow - go with ordering player ("i'm with you" rather than "yes sir!") + "stimSoldierOrdersDeny", // deny - refuse orders (doing something else) + }, + AITEAM_NAZI, + "stim/default", + {WP_MONSTER_ATTACK2}, // TODO: dual machinegun attack + BBOX_LARGE, {48,64}, + AIFL_NO_RELOAD, + NULL, AIFunc_StimSoldierAttack2Start, NULL, + NULL, + AISTATE_ALERT + }, + + //AICHAR_STIMSOLDIER2 + { + "Stim Soldier", + { + 170, // running speed + 100, // walking speed + 90, // crouching speed + 90, // Field of View + 150, // Yaw Speed + 0.0, // leader + 0.7, // aim skill + 1.0, // aim accuracy + 0.9, // attack skill + 0.6, // reaction time + 0.05, // attack crouch + 0.0, // idle crouch + 0.9, // aggression + 0.1, // tactical + 0.0, // camper + 16000, // alertness + 300, // starting health + 1.0, // hearing scale + 0.9, // not in pvs hearing scale + 512, // relaxed detection radius + 1.0, // pain threshold multiplier + }, + { + "stimSoldierSightPlayer", + "stimSoldierAttackPlayer", + "stimSoldierOrders", + "stimSoldierDeath", + "stimSoldierSilentDeath", //----(SA) added + "stimSoldierFlameDeath", //----(SA) added + "stimSoldierPain", + "stimSoldierStay", // stay - you're told to stay put + "stimSoldierFollow", // follow - go with ordering player ("i'm with you" rather than "yes sir!") + "stimSoldierOrdersDeny", // deny - refuse orders (doing something else) + }, + AITEAM_NAZI, + "stim/default", + {WP_MP40, WP_MONSTER_ATTACK1}, // attack1 is leaping rocket attack + BBOX_LARGE, {48,64}, + AIFL_NO_RELOAD, + AIFunc_StimSoldierAttack1Start, NULL, NULL, + NULL, + AISTATE_ALERT + }, + + //AICHAR_STIMSOLDIER3 + { + "Stim Soldier", + { + 170, // running speed + 100, // walking speed + 90, // crouching speed + 90, // Field of View + 150, // Yaw Speed + 0.0, // leader + 0.7, // aim skill + 1.0, // aim accuracy + 0.9, // attack skill + 0.6, // reaction time + 0.05, // attack crouch + 0.0, // idle crouch + 0.9, // aggression + 0.1, // tactical + 0.0, // camper + 16000, // alertness + 300, // starting health + 1.0, // hearing scale + 0.9, // not in pvs hearing scale + 512, // relaxed detection radius + 1.0, // pain threshold multiplier + }, + { + "stimSoldierSightPlayer", + "stimSoldierAttackPlayer", + "stimSoldierOrders", + "stimSoldierDeath", + "stimSoldierSilentDeath", //----(SA) added + "stimSoldierFlameDeath", //----(SA) added + "stimSoldierPain", + "stimSoldierStay", // stay - you're told to stay put + "stimSoldierFollow", // follow - go with ordering player ("i'm with you" rather than "yes sir!") + "stimSoldierOrdersDeny", // deny - refuse orders (doing something else) + }, + AITEAM_NAZI, + "stim/default", + {WP_MP40, WP_TESLA}, // no monster_attack1, since that's only used for the jumping rocket attack + BBOX_LARGE, {48,64}, + AIFL_NO_RELOAD, + AIFunc_StimSoldierAttack1Start, NULL, NULL, + NULL, + AISTATE_ALERT + }, + + //AICHAR_SUPERSOLDIER + { + "Super Soldier", + { + 170, // running speed + 100, // walking speed + 90, // crouching speed + 90, // Field of View + 150, // Yaw Speed + 0.0, // leader + 0.7, // aim skill + 1.0, // aim accuracy + 0.9, // attack skill + 0.6, // reaction time + 0.05, // attack crouch + 0.0, // idle crouch + 1.0, // aggression + 0.0, // tactical + 0.0, // camper + 16000, // alertness + 300, // starting health + 1.0, // hearing scale + 0.9, // not in pvs hearing scale + 512, // relaxed detection radius + 2.0, // pain threshold multiplier + }, + { + "superSoldierSightPlayer", + "superSoldierAttackPlayer", + "superSoldierOrders", + "superSoldierDeath", + "superSoldierSilentDeath", //----(SA) added + "superSoldierFlameDeath", //----(SA) added + "superSoldierPain", + "superSoldierStay", // stay - you're told to stay put + "superSoldierFollow", // follow - go with ordering player ("i'm with you" rather than "yes sir!") + "superSoldierOrdersDeny", // deny - refuse orders (doing something else) + }, + AITEAM_NAZI, + "supersoldier/default", + {WP_VENOM}, + BBOX_LARGE, {48,64}, + AIFL_NO_RELOAD | AIFL_NO_FLAME_DAMAGE | AIFL_NO_TESLA_DAMAGE, + NULL, NULL, NULL, + NULL, + AISTATE_ALERT + }, + + //AICHAR_BLACKGUARD + { + "Black Guard", + { + 220, // running speed + 90, // walking speed + 100, // crouching speed + 90, // Field of View + 300, // Yaw Speed + 0.0, // leader + 0.5, // aim skill + 0.8, // aim accuracy + 0.9, // attack skill + 0.3, // reaction time + 0.4, // attack crouch + 0.0, // idle crouch + 0.5, // aggression + 1.0, // tactical + 0.0, // camper + 16000, // alertness + 120, // starting health + 1.0, // hearing scale + 0.9, // not in pvs hearing scale + 512, // relaxed detection radius + 1.0, // pain threshold multiplier + }, + { + "blackGuardSightPlayer", + "blackGuardAttackPlayer", + "blackGuardOrders", + "blackGuardDeath", + "blackGuardSilentDeath", //----(SA) added + "blackGuardFlameDeath", //----(SA) added + "blackGuardPain", + "blackGuardStay", // stay - you're told to stay put + "blackGuardFollow", // follow - go with ordering player ("i'm with you" rather than "yes sir!") + "blackGuardOrdersDeny", // deny - refuse orders (doing something else) + }, + AITEAM_NAZI, + "blackguard/default", +// {WP_MP40, WP_GRENADE_LAUNCHER, WP_MONSTER_ATTACK1}, // attack1 is melee kick + {WP_FG42, WP_FG42SCOPE, WP_GRENADE_LAUNCHER, WP_MONSTER_ATTACK1}, // attack1 is melee kick + BBOX_SMALL, {32,48}, + AIFL_CATCH_GRENADE | AIFL_FLIP_ANIM | AIFL_STAND_IDLE2, + AIFunc_BlackGuardAttack1Start, NULL, NULL, + NULL, + AISTATE_RELAXED + }, + + //AICHAR_PROTOSOLDIER + { + "Protosoldier", + { + 170, // running speed + 100, // walking speed + 90, // crouching speed + 90, // Field of View + 230, // Yaw Speed + 0.0, // leader + 0.7, // aim skill + 1.0, // aim accuracy + 0.9, // attack skill + 0.2, // reaction time + 0.05, // attack crouch + 0.0, // idle crouch + 0.9, // aggression + 0.1, // tactical + 0.0, // camper + 16000, // alertness + 300, // starting health + 1.0, // hearing scale + 0.9, // not in pvs hearing scale + 512, // relaxed detection radius + 2.0, // pain threshold multiplier + }, + { + "protoSoldierSightPlayer", + "protoSoldierAttackPlayer", + "protoSoldierOrders", + "protoSoldierDeath", + "protoSoldierSilentDeath", //----(SA) added + "protoSoldierFlameDeath", //----(SA) added + "protoSoldierPain", + "protoSoldierStay", // stay - you're told to stay put + "protoSoldierFollow", // follow - go with ordering player ("i'm with you" rather than "yes sir!") + "protoSoldierOrdersDeny", // deny - refuse orders (doing something else) + }, + AITEAM_NAZI, + "protosoldier/default", + {WP_VENOM}, + BBOX_LARGE, {48,64}, + AIFL_NO_TESLA_DAMAGE | AIFL_NO_FLAME_DAMAGE | AIFL_WALKFORWARD | AIFL_NO_RELOAD, + NULL, NULL, NULL, + NULL, + AISTATE_ALERT + }, + + // AICHAR_FROGMAN + { + "Frogman", + { + 170, // running speed + 100, // walking speed + 90, // crouching speed + 90, // Field of View + 150, // Yaw Speed + 0.0, // leader + 0.7, // aim skill + 1.0, // aim accuracy + 0.9, // attack skill + 0.6, // reaction time + 0.05, // attack crouch + 0.0, // idle crouch + 0.9, // aggression + 0.1, // tactical + 0.0, // camper + 16000, // alertness + 200, // starting health + 1.0, // hearing scale + 0.9, // not in pvs hearing scale + 512, // relaxed detection radius + 1.0, // pain threshold multiplier + }, + { + "frogmanSightPlayer", + "frogmanAttackPlayer", + "frogmanOrders", + "frogmanDeath", + "frogmanSilentDeath", //----(SA) added + "frogmanFlameDeath", //----(SA) added + "frogmanPain", + "frogmanStay", // stay - you're told to stay put + "frogmanFollow", // follow - go with ordering player ("i'm with you" rather than "yes sir!") + "frogmanOrdersDeny", // deny - refuse orders (doing something else) + }, + AITEAM_NAZI, + "frogman/default", + {0}, + BBOX_SMALL, {32,48}, // bbox, crouch/stand height + 0, + NULL, NULL, NULL, + NULL, + AISTATE_RELAXED + }, + + //AICHAR_HELGA + { + "Helga", + { + 140, // running speed + 90, // walking speed + 80, // crouching speed + 90, // Field of View + 200, // Yaw Speed + 0.0, // leader + 0.5, // aim skill + 0.5, // aim accuracy + 0.75, // attack skill + 0.5, // reaction time + 0.0, // attack crouch + 0.0, // idle crouch + 1.0, // aggression + 0.0, // tactical + 0.0, // camper + 16000, // alertness + 100, // starting health + 1.0, // hearing scale + 0.9, // not in pvs hearing scale + 512, // relaxed detection radius + 3.0, // pain threshold multiplier + }, + { + "helgaAttackPlayer", + "helgaAttackPlayer", + "helgaOrders", + "helgaDeath", + "helgaSilentDeath", //----(SA) added + "helgaFlameDeath", //----(SA) added + "helgaAttackPlayer", + "sound/weapons/melee/fstatck.wav", // stay - you're told to stay put + "helgaFollow", // follow - go with ordering player ("i'm with you" rather than "yes sir!") + "helgaOrdersDeny", // deny - refuse orders (doing something else) + }, + AITEAM_MONSTER, // team + "beast/default", // default model/skin + {WP_MONSTER_ATTACK1,WP_MONSTER_ATTACK2 /*,WP_MONSTER_ATTACK3*/}, // starting weapons + BBOX_LARGE, {90,90}, // bbox, crouch/stand height + AIFL_WALKFORWARD | AIFL_NO_RELOAD, + AIFunc_Helga_MeleeStart, AIFunc_Helga_SpiritAttack_Start, NULL, // special attack routine + NULL, + AISTATE_ALERT + }, + + //AICHAR_HEINRICH + { + "Heinrich", + { + 170, // running speed + 100, // walking speed + 90, // crouching speed + 90, // Field of View + 130, // Yaw Speed + 0.0, // leader + 0.7, // aim skill + 1.0, // aim accuracy + 0.9, // attack skill + 0.2, // reaction time + 0.05, // attack crouch + 0.0, // idle crouch + 1.0, // aggression + 0.0, // tactical + 0.0, // camper + 16000, // alertness + 2000, // starting health + 1.0, // hearing scale + 0.9, // not in pvs hearing scale + 512, // relaxed detection radius + 5.0, // pain threshold multiplier + }, + { + "heinrichSightPlayer", + "heinrichAttackPlayer", + "heinrichOrders", + "heinrichDeath", + "heinrichSilentDeath", + "heinrichFlameDeath", //----(SA) added + "heinrichPain", + "heinrichStay", // stay - you're told to stay put + "heinrichFollow", // follow - go with ordering player ("i'm with you" rather than "yes sir!") + "heinrichStomp", // deny - refuse orders (doing something else) + }, + AITEAM_NAZI, + "heinrich/default", + {WP_MONSTER_ATTACK1,WP_MONSTER_ATTACK2,WP_MONSTER_ATTACK3}, // attack3 is given to him by scripting + BBOX_LARGE, {72,72}, // (SA) height is not exact. just eyeballed. + AIFL_NO_FLAME_DAMAGE | AIFL_WALKFORWARD | AIFL_NO_RELOAD, + AIFunc_Heinrich_MeleeStart, AIFunc_Heinrich_RaiseDeadStart, AIFunc_Heinrich_SpawnSpiritsStart, + NULL, + AISTATE_ALERT + }, + + //AICHAR_PARTISAN + { + "Partisan", + { + 220, // running speed + 90, // walking speed + 80, // crouching speed + 90, // Field of View + 300, // Yaw Speed + 0.0, // leader + 0.70, // aim skill + 0.70, // aim accuracy + 0.75, // attack skill + 0.5, // reaction time + 0.3, // attack crouch + 0.0, // idle crouch + 0.5, // aggression + 0.8, // tactical + 0.0, // camper + 16000, // alertness + 100, // starting health + 1.0, // hearing scale + 0.9, // not in pvs hearing scale + 512, // relaxed detection radius + 1.0, // pain threshold multiplier + }, + { + "partisanSightPlayer", + "partisanAttackPlayer", + "partisanOrders", + "partisanDeath", + "partisanSilentDeath", //----(SA) added + "partisanFlameDeath", //----(SA) added + "partisanPain", + "partisanStay", + "partisanFollow", + "partisanOrdersDeny", + }, + AITEAM_ALLIES, //----(SA) changed affiliation for DK + "partisan/default", + {WP_THOMPSON}, + BBOX_SMALL, {32,48}, + AIFL_CATCH_GRENADE | AIFL_STAND_IDLE2, + NULL, NULL, NULL, + NULL, + AISTATE_RELAXED + }, + + //AICHAR_CIVILIAN + { + "Civilian", + { + 220, // running speed + 90, // walking speed + 80, // crouching speed + 90, // Field of View + 300, // Yaw Speed + 0.0, // leader + 0.70, // aim skill + 0.70, // aim accuracy + 0.75, // attack skill + 0.5, // reaction time + 0.3, // attack crouch + 0.0, // idle crouch + 0.5, // aggression + 0.8, // tactical + 0.0, // camper + 16000, // alertness + 100, // starting health + 1.0, // hearing scale + 0.9, // not in pvs hearing scale + 512, // relaxed detection radius + 1.0, // pain threshold multiplier + }, + { + "civilianSightPlayer", + "civilianAttackPlayer", + "civilianOrders", + "civilianDeath", + "civilianSilentDeath", //----(SA) added + "civilianFlameDeath", //----(SA) added + "civilianPain", + "civilianStay", + "civilianFollow", + "civilianOrdersDeny", + }, + AITEAM_NEUTRAL, //----(SA) changed affiliation for DK + "civilian/default", + {0}, + BBOX_SMALL, {32,48}, + AIFL_CATCH_GRENADE | AIFL_STAND_IDLE2, + NULL, NULL, NULL, + NULL, + AISTATE_RELAXED + }, + +}; +//--------------------------------------------------------------------------- + +//--------------------------------------------------------------------------- +// Bounding boxes +static vec3_t bbmins[2] = {{-18, -18, -24},{-32,-32,-24}}; +static vec3_t bbmaxs[2] = {{ 18, 18, 48},{ 32, 32, 68}}; +//static float crouchMaxZ[2] = {32,48}; // same as player, will head be ok? // TTimo: unused +//--------------------------------------------------------------------------- + +//--------------------------------------------------------------------------- +// Weapon info +cast_weapon_info_t weaponInfo; +//--------------------------------------------------------------------------- + +/* +============ +AIChar_SetBBox + + FIXME: pass a maxZ into this so we can tailor the height for each character, + since height isn't important for the AAS routing (whereas width is very important) +============ +*/ +void AIChar_SetBBox( gentity_t *ent, cast_state_t *cs, qboolean useHeadTag ) { + vec3_t bbox[2]; + trace_t tr; + orientation_t or; + + if ( !useHeadTag ) { + VectorCopy( bbmins[cs->aasWorldIndex], ent->client->ps.mins ); + VectorCopy( bbmaxs[cs->aasWorldIndex], ent->client->ps.maxs ); + ent->client->ps.maxs[2] = aiDefaults[cs->aiCharacter].crouchstandZ[1]; + VectorCopy( ent->client->ps.mins, ent->r.mins ); + VectorCopy( ent->client->ps.maxs, ent->r.maxs ); + ent->client->ps.crouchMaxZ = aiDefaults[cs->aiCharacter].crouchstandZ[0]; + ent->s.density = cs->aasWorldIndex; + } else if ( trap_GetTag( ent->s.number, "tag_head", &or ) ) { // if not found, then just leave it + or.origin[2] -= ent->client->ps.origin[2]; // convert to local coordinates + or.origin[2] += 11; + if ( or.origin[2] < 0 ) { + or.origin[2] = 0; + } + if ( or.origin[2] > aiDefaults[cs->aiCharacter].crouchstandZ[1] + 30 ) { + or.origin[2] = aiDefaults[cs->aiCharacter].crouchstandZ[1] + 30; + } + + memset( &tr, 0, sizeof( tr ) ); + + // check that the new height is ok first, otherwise leave it alone + VectorCopy( bbmins[cs->aasWorldIndex], bbox[0] ); + VectorCopy( bbmaxs[cs->aasWorldIndex], bbox[1] ); + // set the head tag height + bbox[1][2] = or.origin[2]; + + if ( bbox[1][2] > ent->client->ps.maxs[2] ) { + // check this area is clear + trap_TraceCapsule( &tr, ent->client->ps.origin, bbox[0], bbox[1], ent->client->ps.origin, ent->s.number, ent->clipmask ); + } + + if ( !tr.startsolid && !tr.allsolid ) { + VectorCopy( bbox[0], ent->client->ps.mins ); + VectorCopy( bbox[1], ent->client->ps.maxs ); + VectorCopy( ent->client->ps.mins, ent->r.mins ); + VectorCopy( ent->client->ps.maxs, ent->r.maxs ); + ent->client->ps.crouchMaxZ = aiDefaults[cs->aiCharacter].crouchstandZ[0]; + ent->s.density = cs->aasWorldIndex; + } + } + + // if they are linked, then relink to update bbox + if ( ent->r.linked ) { + trap_LinkEntity( ent ); + } +} + +/* +============ +AIChar_Death +============ +*/ +void AIChar_Death( gentity_t *ent, gentity_t *attacker, int damage, int mod ) { //----(SA) added mod + // need this check otherwise sound will overwrite gib message + if ( ent->health > GIB_HEALTH ) { + if ( ent->client->ps.eFlags & EF_HEADSHOT ) { + G_AddEvent( ent, EV_GENERAL_SOUND, G_SoundIndex( aiDefaults[ent->aiCharacter].soundScripts[QUIETDEATHSOUNDSCRIPT] ) ); + } else { + switch ( mod ) { //----(SA) modified to add 'quiet' deaths + case MOD_KNIFE_STEALTH: + case MOD_SNIPERRIFLE: + case MOD_SNOOPERSCOPE: + G_AddEvent( ent, EV_GENERAL_SOUND, G_SoundIndex( aiDefaults[ent->aiCharacter].soundScripts[QUIETDEATHSOUNDSCRIPT] ) ); + break; + case MOD_FLAMETHROWER: + G_AddEvent( ent, EV_GENERAL_SOUND, G_SoundIndex( aiDefaults[ent->aiCharacter].soundScripts[FLAMEDEATHSOUNDSCRIPT] ) ); //----(SA) added + break; + default: + G_AddEvent( ent, EV_GENERAL_SOUND, G_SoundIndex( aiDefaults[ent->aiCharacter].soundScripts[DEATHSOUNDSCRIPT] ) ); + break; + } + } + } +} + +/* +============= +AIChar_GetPainLocation +============= +*/ +int AIChar_GetPainLocation( gentity_t *ent, vec3_t point ) { + static char *painTagNames[] = { + "tag_head", + "tag_chest", + "tag_torso", + "tag_groin", + "tag_armright", + "tag_armleft", + "tag_legright", + "tag_legleft", + NULL, + }; + + int tagIndex, bestTag; + float bestDist, dist; + orientation_t or; + + // first make sure the client is able to retrieve tag information + if ( !trap_GetTag( ent->s.number, painTagNames[0], &or ) ) { + return 0; + } + + // find a correct animation to play, based on the body orientation at previous frame + for ( tagIndex = 0, bestDist = 0, bestTag = -1; painTagNames[tagIndex]; tagIndex++ ) { + // grab the tag with this name + if ( trap_GetTag( ent->s.number, painTagNames[tagIndex], &or ) ) { + dist = VectorDistance( or.origin, point ); + if ( !bestDist || dist < bestDist ) { + bestTag = tagIndex; + bestDist = dist; + } + } + } + + if ( bestTag >= 0 ) { + return bestTag + 1; + } + + return 0; +} + +/* +============ +AIChar_Pain +============ +*/ +void AIChar_Pain( gentity_t *ent, gentity_t *attacker, int damage, vec3_t point ) { + #define PAIN_THRESHOLD 25 + #define STUNNED_THRESHOLD 30 + cast_state_t *cs; + float dist; + qboolean forceStun = qfalse; + float painThreshold, stunnedThreshold; + + cs = AICast_GetCastState( ent->s.number ); + + if ( g_testPain.integer == 1 ) { + ent->health = ent->client->pers.maxHealth; // debugging + } + + if ( g_testPain.integer != 2 ) { + if ( level.time < cs->painSoundTime ) { + return; + } + } + + painThreshold = PAIN_THRESHOLD * cs->attributes[PAIN_THRESHOLD_SCALE]; + stunnedThreshold = STUNNED_THRESHOLD * cs->attributes[PAIN_THRESHOLD_SCALE]; + + // if they are already playing another animation, we might get confused and cut it off, so don't play a pain + if ( ent->client->ps.torsoTimer || ent->client->ps.legsTimer ) { + return; + } + + // if we are waiting for our weapon to fire (throwing a grenade) + if ( ent->client->ps.weaponDelay ) { + return; + } + + if ( attacker->s.weapon == WP_FLAMETHROWER && !( cs->aiFlags & AIFL_NO_FLAME_DAMAGE ) ) { // flames should be recognized more often, since they stay onfire until they're dead anyway + painThreshold = 1; + stunnedThreshold = 99999; // dont be stunned + } + + // HACK: if the attacker is using the flamethrower, don't do any special pain anim or sound + // FIXME: we should pass in the MOD here, since they could have fired a grenade, then switched weapons + //if (attacker->s.weapon == WP_FLAMETHROWER) { + // return; + //} + + if ( !Q_stricmp( attacker->classname, "props_statue" ) ) { + damage = 99999; // try and force a stun + forceStun = qtrue; + } + + if ( attacker->s.weapon == WP_TESLA ) { + damage *= 2; + if ( cs->attributes[PAIN_THRESHOLD_SCALE] <= 1.0 ) { + damage = 99999; + } + } + + // now check the damageQuota to see if we should play a pain animation + // first reduce the current damageQuota with time + if ( cs->damageQuotaTime && cs->damageQuota > 0 ) { + cs->damageQuota -= (int)( ( 1.0 + ( g_gameskill.value / GSKILL_MAX ) ) * ( (float)( level.time - cs->damageQuotaTime ) / 1000 ) * ( 7.5 + cs->attributes[ATTACK_SKILL] * 10.0 ) ); + if ( cs->damageQuota < 0 ) { + cs->damageQuota = 0; + } + } + + // if it's been a long time since our last pain, scale it up + if ( cs->painSoundTime < level.time - 1000 ) { + float scale; + scale = (float)( level.time - cs->painSoundTime - 1000 ) / 1000.0; + if ( scale > 4.0 ) { + scale = 4.0; + } + damage = (int)( (float)damage * ( 1.0 + ( scale * ( 1.0 - 0.5 * g_gameskill.value / GSKILL_MAX ) ) ) ); + } + + // adjust the new damage with distance, if they are really close, scale it down, to make it + // harder to get through the game by continually rushing the enemies + if ( ( attacker->s.weapon != WP_TESLA ) && ( ( dist = VectorDistance( ent->r.currentOrigin, attacker->r.currentAngles ) ) < 384 ) ) { + damage -= (int)( (float)damage * ( 1.0 - ( dist / 384.0 ) ) * ( 0.5 + 0.5 * g_gameskill.value / GSKILL_MAX ) ); + } + + // add the new damage + cs->damageQuota += damage; + cs->damageQuotaTime = level.time; + + if ( forceStun ) { + damage = 99999; // try and force a stun + cs->damageQuota = painThreshold + 1; + } + + // if it's over the threshold, play a pain + + // don't do this if crouching, or we might clip through the world + + if ( g_testPain.integer == 2 || ( cs->damageQuota > painThreshold ) ) { + int delay; + + // stunned? + if ( damage > stunnedThreshold && ( forceStun || ( rand() % 2 ) ) ) { // stunned + BG_UpdateConditionValue( ent->s.number, ANIM_COND_STUNNED, qtrue, qfalse ); + } + // enemy weapon + if ( attacker->client ) { + BG_UpdateConditionValue( ent->s.number, ANIM_COND_ENEMY_WEAPON, attacker->s.weapon, qtrue ); + } + if ( point ) { + // location + BG_UpdateConditionValue( ent->s.number, ANIM_COND_IMPACT_POINT, AIChar_GetPainLocation( ent, point ), qtrue ); + } else { + BG_UpdateConditionValue( ent->s.number, ANIM_COND_IMPACT_POINT, 0, qfalse ); + } + + // pause while we play a pain + delay = BG_AnimScriptEvent( &ent->client->ps, ANIM_ET_PAIN, qfalse, qtrue ); + + // turn off temporary conditions + BG_UpdateConditionValue( ent->s.number, ANIM_COND_STUNNED, 0, qfalse ); + BG_UpdateConditionValue( ent->s.number, ANIM_COND_ENEMY_WEAPON, 0, qfalse ); + BG_UpdateConditionValue( ent->s.number, ANIM_COND_IMPACT_POINT, 0, qfalse ); + + if ( delay >= 0 ) { + // setup game stuff to handle the character movements, etc + cs->pauseTime = level.time + delay + 250; + cs->lockViewAnglesTime = cs->pauseTime; + // make sure we stop crouching + cs->attackcrouch_time = 0; + // don't fire while in pain? + cs->triggerReleaseTime = cs->pauseTime; + // stay crouching if we were before the pain + if ( cs->bs->cur_ps.viewheight == cs->bs->cur_ps.crouchViewHeight ) { + cs->attackcrouch_time = level.time + (float)( cs->pauseTime - level.time ) + 500; + } + } + + // if we didnt just play a scripted sound, then play one of the default sounds + if ( cs->lastScriptSound < level.time ) { + G_AddEvent( ent, EV_GENERAL_SOUND, G_SoundIndex( aiDefaults[ent->aiCharacter].soundScripts[PAINSOUNDSCRIPT] ) ); + } + + // reset the quota + cs->damageQuota = 0; + cs->damageQuotaTime = 0; + // + cs->painSoundTime = cs->pauseTime + (int)( 1000 * ( g_gameskill.value / GSKILL_MAX ) ); // add a bit more of a buffer before the next one + } + +} + +/* +============ +AIChar_Sight +============ +*/ +void AIChar_Sight( gentity_t *ent, gentity_t *other, int lastSight ) { + cast_state_t *cs; + + cs = AICast_GetCastState( ent->s.number ); + + // if we are in noattack mode, don't make sounds + if ( cs->castScriptStatus.scriptNoAttackTime >= level.time ) { + return; + } + if ( cs->noAttackTime >= level.time ) { + return; + } + + // if they have recently played a script sound, then ignore this + if ( cs->lastScriptSound > level.time - 4000 ) { + return; + } + + if ( !AICast_SameTeam( cs, other->s.number ) ) { + if ( !cs->firstSightTime || cs->firstSightTime < ( level.time - 15000 ) ) { + //G_AddEvent( ent, EV_GENERAL_SOUND, G_SoundIndex( aiDefaults[ent->aiCharacter].sightSoundScript ) ); + } + cs->firstSightTime = level.time; + } + +} + +/* +===================== +AIChar_AttackSND + + NOTE: this should just lookup a sound script for this character/weapon combo +===================== +*/ +void AIChar_AttackSound( cast_state_t *cs ) { + + gentity_t *ent; + + ent = &g_entities [cs->entityNum]; + + if ( cs->attackSNDtime > level.time ) { + return; + } + + // if we are in noattack mode, don't make sounds + if ( cs->castScriptStatus.scriptNoAttackTime >= level.time ) { + return; + } + if ( cs->noAttackTime >= level.time ) { + return; + } + + // Ridah, only yell when throwing grenades every now and then, since it's not very "stealthy" + if ( cs->weaponNum == WP_GRENADE_LAUNCHER && rand() % 5 ) { + return; + } + + cs->attackSNDtime = level.time + 5000 + ( 1000 * rand() % 10 ); + + AICast_ScriptEvent( cs, "attacksound", ent->aiName ); + if ( cs->aiFlags & AIFL_DENYACTION ) { + return; + } + + if ( cs->weaponNum == WP_LUGER ) { + G_AddEvent( ent, EV_GENERAL_SOUND, G_SoundIndex( aiDefaults[ent->aiCharacter].soundScripts[ORDERSSOUNDSCRIPT] ) ); + } else { + G_AddEvent( ent, EV_GENERAL_SOUND, G_SoundIndex( aiDefaults[ent->aiCharacter].soundScripts[ATTACKSOUNDSCRIPT] ) ); + } + +} + +/* +============ +AIChar_spawn +============ +*/ +void AIChar_spawn( gentity_t *ent ) { + gentity_t *newent; + cast_state_t *cs; + AICharacterDefaults_t *aiCharDefaults; + int i; + static int lastCall; + static int numCalls; + + // if there are other cast's waiting to spawn before us, wait for them + for ( i = MAX_CLIENTS, newent = &g_entities[MAX_CLIENTS]; i < MAX_GENTITIES; i++, newent++ ) { + if ( !newent->inuse ) { + continue; + } + if ( newent->think != AIChar_spawn ) { + continue; + } + if ( newent == ent ) { + break; // we are the first in line + } + // still waiting for someone else + ent->nextthink = level.time + FRAMETIME; + return; + } + + // if the client hasn't connected yet, wait around + if ( !AICast_FindEntityForName( "player" ) ) { + ent->nextthink = level.time + FRAMETIME; + return; + } + + if ( lastCall == level.time ) { + if ( numCalls++ > 2 ) { + ent->nextthink = level.time + FRAMETIME; + return; // spawned enough this frame already + } + } else { + numCalls = 0; + } + lastCall = level.time; + + aiCharDefaults = &aiDefaults[ent->aiCharacter]; + + // ............................ + // setup weapon info + // + // starting weapons/ammo + memset( &weaponInfo, 0, sizeof( weaponInfo ) ); + for ( i = 0; aiCharDefaults->weapons[i]; i++ ) { + //weaponInfo.startingWeapons[(aiCharDefaults->weapons[i] / 32)] |= ( 1 << aiCharDefaults->weapons[i] ); + //weaponInfo.startingWeapons[0] |= ( 1 << aiCharDefaults->weapons[i] ); + + COM_BitSet( weaponInfo.startingWeapons, aiCharDefaults->weapons[i] ); + if ( aiCharDefaults->weapons[i] == WP_GRENADE_LAUNCHER ) { // give them a bunch of grenades, but not an unlimited supply + weaponInfo.startingAmmo[BG_FindAmmoForWeapon( aiCharDefaults->weapons[i] )] = 6; + } else { + weaponInfo.startingAmmo[BG_FindAmmoForWeapon( aiCharDefaults->weapons[i] )] = 999; + } + } + // + // use the default skin if nothing specified + if ( !ent->aiSkin || !strlen( ent->aiSkin ) ) { + ent->aiSkin = aiCharDefaults->skin; + } + // ............................ + // + // create the character + + // (there will always be an ent->aiSkin (SA)) + newent = AICast_CreateCharacter( ent, aiCharDefaults->attributes, &weaponInfo, aiCharDefaults->name, ent->aiSkin, ent->aihSkin, "m", "7", "100" ); + + if ( !newent ) { + G_FreeEntity( ent ); + return; + } + // copy any character-specific information to the new entity (like editor fields, etc) + // + // copy this across so killing ai can trigger a target + newent->target = ent->target; + // + newent->classname = ent->classname; + newent->r.svFlags |= ( ent->r.svFlags & SVF_NOFOOTSTEPS ); + newent->aiCharacter = ent->aiCharacter; + newent->client->ps.aiChar = ent->aiCharacter; + newent->spawnflags = ent->spawnflags; + newent->aiTeam = ent->aiTeam; + if ( newent->aiTeam < 0 ) { + newent->aiTeam = aiCharDefaults->aiTeam; + } + newent->client->ps.teamNum = newent->aiTeam; + // + // kill the old entity + G_FreeEntity( ent ); + // attach to the new entity + ent = newent; + // + // precache any specific sounds + // + // ... + // + // get the cast state + cs = AICast_GetCastState( ent->s.number ); + // + // setup any character specific cast_state variables + cs->deathfunc = AIChar_Death; + cs->painfunc = AIChar_Pain; + cs->aiFlags |= aiCharDefaults->aiFlags; + cs->aiState = aiCharDefaults->aiState; + // + cs->queryCountValidTime = -1; + // + // randomly choose idle animation + if ( cs->aiFlags & AIFL_STAND_IDLE2 ) { + newent->client->ps.eFlags |= EF_STAND_IDLE2; + } + // + // attach any event specific functions (pain, death, etc) + // + //cs->getDeathAnim = AIChar_getDeathAnim; + cs->sightfunc = AIChar_Sight; + if ( ent->aiTeam == AITEAM_ALLIES || ent->aiTeam == AITEAM_NEUTRAL ) { // friendly + cs->activate = AICast_ProcessActivate; + } else { + cs->activate = NULL; + } + cs->aifuncAttack1 = aiCharDefaults->aifuncAttack1; + cs->aifuncAttack2 = aiCharDefaults->aifuncAttack2; + cs->aifuncAttack3 = aiCharDefaults->aifuncAttack3; + // + // looping sound? + if ( aiCharDefaults->loopingSound ) { + ent->s.loopSound = G_SoundIndex( aiCharDefaults->loopingSound ); + } + // + // precache sounds for this character + for ( i = 0; i < MAX_AI_EVENT_SOUNDS; i++ ) { + if ( aiDefaults[ent->aiCharacter].soundScripts[i] ) { + G_SoundIndex( aiDefaults[ent->aiCharacter].soundScripts[i] ); + } + } + // + if ( ent->aiCharacter == AICHAR_HEINRICH ) { + AICast_Heinrich_SoundPrecache(); + } + // + // special spawnflag stuff + if ( ent->spawnflags & 2 ) { + cs->secondDeadTime = qtrue; + } + // + // init scripting + cs->castScriptStatus.castScriptEventIndex = -1; + cs->castScriptStatus.scriptAttackEnt = -1; + // + // set crouch move speed + ent->client->ps.crouchSpeedScale = cs->attributes[CROUCHING_SPEED] / cs->attributes[RUNNING_SPEED]; + // + // check for some anims which we can use for special behaviours + if ( BG_GetAnimScriptEvent( &ent->client->ps, ANIM_ET_ROLL ) >= 0 ) { + cs->aiFlags |= AIFL_ROLL_ANIM; + } + if ( BG_GetAnimScriptEvent( &ent->client->ps, ANIM_ET_FLIP ) >= 0 ) { + cs->aiFlags |= AIFL_FLIP_ANIM; + } + if ( BG_GetAnimScriptEvent( &ent->client->ps, ANIM_ET_DIVE ) >= 0 ) { + cs->aiFlags |= AIFL_DIVE_ANIM; + } + // HACK + if ( ent->aiName && !Q_stricmp( ent->aiName, "deathshead" ) ) { + cs->aiFlags |= AIFL_NO_FLAME_DAMAGE; + } + // + // check for no headshot damage + if ( cs->aiFlags & AIFL_NO_HEADSHOT_DMG ) { + ent->headshotDamageScale = 0.0; + } + // set these values now so scripting system isn't relying on a Think having been run prior to running a script + //origin of the cast + VectorCopy( ent->client->ps.origin, cs->bs->origin ); + //velocity of the cast + VectorCopy( ent->client->ps.velocity, cs->bs->velocity ); + //playerstate + cs->bs->cur_ps = ent->client->ps; + // + if ( !ent->aiInactive ) { + // trigger a spawn script event + AICast_ScriptEvent( cs, "spawn", "" ); + } else { + trap_UnlinkEntity( ent ); + } + +} + +//---------------------------------------------------------------------------------------------------------------------------- +/*QUAKED ai_soldier (1 0.25 0) (-16 -16 -24) (16 16 64) TriggerSpawn NoRevive +soldier entity +"skin" the .skin file to use for this character (must exist in the player characters directory, otherwise 'infantryss/default' is used) +"head" the .skin file to use for his head (must exist in the pc's dir, otherwise 'default' is used) +"ainame" name of AI +*/ +/* +-------- MODEL FOR RADIANT ONLY - DO NOT SET THIS AS A KEY -------- +model="models\mapobjects\characters\test\nazi.md3" +*/ +/* +============ +SP_ai_soldier +============ +*/ +void SP_ai_soldier( gentity_t *ent ) { + AICast_DelayedSpawnCast( ent, AICHAR_SOLDIER ); +} + +//---------------------------------------------------------------------------------------------------------------------------- +/*QUAKED ai_american (1 0.25 0) (-16 -16 -24) (16 16 64) TriggerSpawn NoRevive +american entity +"skin" the .skin file to use for this character (must exist in the player characters directory, otherwise 'american/default' is used) +"head" the .skin file to use for his head (must exist in the pc's dir, otherwise 'default' is used) +"ainame" name of AI +*/ + +/* +============ +SP_ai_american +============ +*/ +void SP_ai_american( gentity_t *ent ) { + AICast_DelayedSpawnCast( ent, AICHAR_AMERICAN ); +} + +//---------------------------------------------------------------------------------------------------------------------------- +/*QUAKED ai_zombie (1 0.25 0) (-16 -16 -24) (16 16 64) TriggerSpawn NoRevive PortalZombie +zombie entity +"skin" the .skin file to use for this character (must exist in the player characters directory, otherwise 'zombie/default' is used) +"head" the .skin file to use for his head (must exist in the pc's dir, otherwise 'default' is used) +"ainame" name of AI +*/ + +/* +============ +SP_ai_zombie +============ +*/ +void SP_ai_zombie( gentity_t *ent ) { + ent->r.svFlags |= SVF_NOFOOTSTEPS; + AICast_DelayedSpawnCast( ent, AICHAR_ZOMBIE ); +} + + +//---------------------------------------------------------------------------------------------------------------------------- +/*QUAKED ai_warzombie (1 0.25 0) (-16 -16 -24) (16 16 64) TriggerSpawn NoRevive PortalZombie +warrior zombie entity +"skin" the .skin file to use for this character (must exist in the player characters directory, otherwise 'warrior/default' is used) +"head" the .skin file to use for his head (must exist in the pc's dir, otherwise 'default' is used) +"ainame" name of AI +*/ + +/* +============ +SP_ai_warzombie +============ +*/ +void SP_ai_warzombie( gentity_t *ent ) { + AICast_DelayedSpawnCast( ent, AICHAR_WARZOMBIE ); +} + + +//---------------------------------------------------------------------------------------------------------------------------- +/*QUAKED ai_venom (1 0.25 0) (-16 -16 -24) (16 16 64) TriggerSpawn NoRevive +venom entity +"skin" the .skin file to use for this character (must exist in the player characters directory, otherwise 'venom/default' is used) +"head" the .skin file to use for his head (must exist in the pc's dir, otherwise 'default' is used) +"ainame" name of AI +*/ + +/* +============ +SP_ai_venom +============ +*/ +void SP_ai_venom( gentity_t *ent ) { + ent->r.svFlags |= SVF_NOFOOTSTEPS; + AICast_DelayedSpawnCast( ent, AICHAR_VENOM ); +} + + +//---------------------------------------------------------------------------------------------------------------------------- +/*QUAKED ai_loper (1 0.25 0) (-32 -32 -24) (32 32 48) TriggerSpawn NoRevive +loper entity +"skin" the .skin file to use for this character (must exist in the player characters directory, otherwise 'loper/default' is used) +"head" the .skin file to use for his head (must exist in the pc's dir, otherwise 'default' is used) +"ainame" name of AI +*/ + +/* +============ +SP_ai_loper +============ +*/ +void SP_ai_loper( gentity_t *ent ) { + ent->r.svFlags |= SVF_NOFOOTSTEPS; + AICast_DelayedSpawnCast( ent, AICHAR_LOPER ); + // + level.loperZapSound = G_SoundIndex( "loperZap" ); +} + +//---------------------------------------------------------------------------------------------------------------------------- +/*QUAKED ai_boss_helga (1 0.25 0) (-16 -16 -24) (16 16 64) TriggerSpawn NoRevive +helga entity +"skin" the .skin file to use for this character (must exist in the player characters directory, otherwise 'helga/default' is used) +"head" the .skin file to use for his head (must exist in the pc's dir, otherwise 'default' is used) +"ainame" name of AI +*/ + +/* +============ +SP_ai_boss_helga +============ +*/ +void SP_ai_boss_helga( gentity_t *ent ) { + AICast_DelayedSpawnCast( ent, AICHAR_HELGA ); +} + +//---------------------------------------------------------------------------------------------------------------------------- +/*QUAKED ai_boss_heinrich (1 0.25 0) (-32 -32 -24) (32 32 156) TriggerSpawn NoRevive +heinrich entity +"skin" the .skin file to use for this character (must exist in the player characters directory, otherwise 'helga/default' is used) +"head" the .skin file to use for his head (must exist in the pc's dir, otherwise 'default' is used) +"ainame" name of AI +*/ + +/* +============ +SP_ai_boss_heinrich +============ +*/ +void SP_ai_boss_heinrich( gentity_t *ent ) { + AICast_DelayedSpawnCast( ent, AICHAR_HEINRICH ); +} + +//---------------------------------------------------------------------------------------------------------------------------- +/*QUAKED ai_partisan (1 0.25 0) (-16 -16 -24) (16 16 64) TriggerSpawn NoRevive +"skin" the .skin file to use for this character (must exist in the player characters directory, otherwise 'partisan/default' is used) +"head" the .skin file to use for his head (must exist in the pc's dir, otherwise 'default' is used) +"ainame" name of AI +*/ + +/* +============ +SP_ai_partisan +============ +*/ +void SP_ai_partisan( gentity_t *ent ) { + AICast_DelayedSpawnCast( ent, AICHAR_PARTISAN ); +} + +//---------------------------------------------------------------------------------------------------------------------------- +/*QUAKED ai_civilian (1 0.25 0) (-16 -16 -24) (16 16 64) TriggerSpawn NoRevive +"skin" the .skin file to use for this character (must exist in the player characters directory, otherwise 'civilian/default' is used) +"head" the .skin file to use for his head (must exist in the pc's dir, otherwise 'default' is used) +"ainame" name of AI +*/ + +/* +============ +SP_ai_civilian +============ +*/ +void SP_ai_civilian( gentity_t *ent ) { + AICast_DelayedSpawnCast( ent, AICHAR_CIVILIAN ); +} + +//---------------------------------------------------------------------------------------------------------------------------- +/*QUAKED ai_eliteguard (1 0.25 0) (-16 -16 -24) (16 16 64) TriggerSpawn NoRevive +elite guard entity +"skin" the .skin file to use for this character (must exist in the player characters directory, otherwise 'eliteguard/default' is used) +"head" the .skin file to use for his head (must exist in the pc's dir, otherwise 'default' is used) +"ainame" name of AI +*/ + +/* +============ +SP_ai_eliteguard +============ +*/ +void SP_ai_eliteguard( gentity_t *ent ) { + AICast_DelayedSpawnCast( ent, AICHAR_ELITEGUARD ); +} + + +//---------------------------------------------------------------------------------------------------------------------------- +/*QUAKED ai_frogman (1 0.25 0) (-16 -16 -24) (16 16 64) TriggerSpawn NoRevive +elite guard entity +"skin" the .skin file to use for this character (must exist in the player characters directory, otherwise 'frogman/default' is used) +"head" the .skin file to use for his head (must exist in the pc's dir, otherwise 'default' is used) +"ainame" name of AI +*/ + +/* +============ +SP_ai_frogman +============ +*/ +void SP_ai_frogman( gentity_t *ent ) { + ent->r.svFlags |= SVF_NOFOOTSTEPS; + AICast_DelayedSpawnCast( ent, AICHAR_FROGMAN ); +} + + +//---------------------------------------------------------------------------------------------------------------------------- +/*QUAKED ai_stimsoldier_dual (1 0.25 0) (-32 -32 -24) (32 32 64) TriggerSpawn NoRevive +stim soldier entity +"skin" the .skin file to use for this character (must exist in the player characters directory, otherwise 'stim/default' is used) +"head" the .skin file to use for his head (must exist in the pc's dir, otherwise 'default' is used) +"ainame" name of AI +*/ + +/* +============ +SP_ai_stimsoldier_dual +============ +*/ +void SP_ai_stimsoldier_dual( gentity_t *ent ) { + AICast_DelayedSpawnCast( ent, AICHAR_STIMSOLDIER1 ); + // + level.stimSoldierFlySound = G_SoundIndex( "sound/stimsoldier/flyloop.wav" ); +} + +//---------------------------------------------------------------------------------------------------------------------------- +/*QUAKED ai_stimsoldier_rocket (1 0.25 0) (-32 -32 -24) (32 32 64) TriggerSpawn NoRevive +stim soldier entity +"skin" the .skin file to use for this character (must exist in the player characters directory, otherwise 'stim/default' is used) +"head" the .skin file to use for his head (must exist in the pc's dir, otherwise 'default' is used) +"ainame" name of AI +*/ + +/* +============ +SP_ai_stimsoldier_rocket +============ +*/ +void SP_ai_stimsoldier_rocket( gentity_t *ent ) { + AICast_DelayedSpawnCast( ent, AICHAR_STIMSOLDIER2 ); + // + level.stimSoldierFlySound = G_SoundIndex( "sound/stimsoldier/flyloop.wav" ); +} + +//---------------------------------------------------------------------------------------------------------------------------- +/*QUAKED ai_stimsoldier_tesla (1 0.25 0) (-32 -32 -24) (32 32 64) TriggerSpawn NoRevive +stim soldier entity +"skin" the .skin file to use for this character (must exist in the player characters directory, otherwise 'stim/default' is used) +"head" the .skin file to use for his head (must exist in the pc's dir, otherwise 'default' is used) +"ainame" name of AI +*/ + +/* +============ +SP_ai_stimsoldier_tesla +============ +*/ +void SP_ai_stimsoldier_tesla( gentity_t *ent ) { + AICast_DelayedSpawnCast( ent, AICHAR_STIMSOLDIER3 ); + // + level.stimSoldierFlySound = G_SoundIndex( "sound/stimsoldier/flyloop.wav" ); +} + +//---------------------------------------------------------------------------------------------------------------------------- +/*QUAKED ai_supersoldier (1 0.25 0) (-32 -32 -24) (32 32 64) TriggerSpawn NoRevive +supersoldier entity +"skin" the .skin file to use for this character (must exist in the player characters directory, otherwise 'supersoldier/default' is used) +"head" the .skin file to use for his head (must exist in the pc's dir, otherwise 'default' is used) +"ainame" name of AI +*/ + +/* +============ +SP_ai_supersoldier +============ +*/ +void SP_ai_supersoldier( gentity_t *ent ) { + AICast_DelayedSpawnCast( ent, AICHAR_SUPERSOLDIER ); +} + +//---------------------------------------------------------------------------------------------------------------------------- +/*QUAKED ai_protosoldier (1 0.25 0) (-32 -32 -24) (32 32 64) TriggerSpawn NoRevive +protosoldier entity +"skin" the .skin file to use for this character (must exist in the player characters directory, otherwise 'protosoldier/default' is used) +"head" the .skin file to use for his head (must exist in the pc's dir, otherwise 'default' is used) +"ainame" name of AI +*/ + +/* +============ +SP_ai_protosoldier +============ +*/ +void SP_ai_protosoldier( gentity_t *ent ) { + AICast_DelayedSpawnCast( ent, AICHAR_PROTOSOLDIER ); +} + +//---------------------------------------------------------------------------------------------------------------------------- +/*QUAKED ai_blackguard (1 0.25 0) (-16 -16 -24) (16 16 64) TriggerSpawn NoRevive +black guard entity +"skin" the .skin file to use for this character (must exist in the player characters directory, otherwise 'blackguard/default' is used) +"head" the .skin file to use for his head (must exist in the pc's dir, otherwise 'default' is used) +"ainame" name of AI +*/ + +/* +============ +SP_ai_blackguard +============ +*/ +void SP_ai_blackguard( gentity_t *ent ) { + AICast_DelayedSpawnCast( ent, AICHAR_BLACKGUARD ); +} diff --git a/Projects/Android/jni/rtcw/src/game/ai_cast_debug.c b/Projects/Android/jni/rtcw/src/game/ai_cast_debug.c new file mode 100644 index 0000000..e32b202 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/game/ai_cast_debug.c @@ -0,0 +1,237 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +//=========================================================================== +// +// Name: ai_cast_debug.c +// Function: Wolfenstein AI Character Routines +// Programmer: Ridah +// Tab Size: 4 (real tabs) +//=========================================================================== + +#include "g_local.h" +#include "../game/botlib.h" //bot lib interface +#include "../game/be_aas.h" +#include "../game/be_ea.h" +#include "../game/be_ai_gen.h" +#include "../game/be_ai_goal.h" +#include "../game/be_ai_move.h" +#include "../botai/botai.h" //bot ai interface + +#include "ai_cast.h" + +static int numaifuncs; +static char *aifuncs[MAX_AIFUNCS]; + +/* +========== +AICast_DBG_InitAIFuncs +========== +*/ +void AICast_DBG_InitAIFuncs( void ) { + numaifuncs = 0; +} + +/* +========== +AICast_DBG_AddAIFunc +========== +*/ +void AICast_DBG_AddAIFunc( cast_state_t *cs, char *funcname ) { + if ( aicast_debug.integer ) { + if ( aicast_debug.integer != 2 || ( g_entities[cs->entityNum].aiName && !strcmp( aicast_debugname.string, g_entities[cs->entityNum].aiName ) ) ) { + G_Printf( "%s: %s\n", g_entities[cs->entityNum].aiName, funcname ); + } + } + aifuncs[numaifuncs] = funcname; + numaifuncs++; +} + +/* +========== +AICast_DBG_ListAIFuncs +========== +*/ +void AICast_DBG_ListAIFuncs( cast_state_t *cs, int numprint ) { + int i; + + if ( aicast_debug.integer != 2 || ( g_entities[cs->entityNum].aiName && !strcmp( aicast_debugname.string, g_entities[cs->entityNum].aiName ) ) ) { + AICast_Printf( AICAST_PRT_DEBUG, S_COLOR_RED "AICast_ProcessAIFunctions: executed more than %d AI funcs\n", MAX_AIFUNCS ); + for ( i = MAX_AIFUNCS - numprint; i < MAX_AIFUNCS; i++ ) + AICast_Printf( AICAST_PRT_DEBUG, "%s, ", aifuncs[i] ); + AICast_Printf( AICAST_PRT_DEBUG, "\n" ); + } +} + +/* +========== +AICast_DebugFrame +========== +*/ +void AICast_DebugFrame( cast_state_t *cs ) { + gentity_t *ent; + + if ( aicast_debug.integer ) { + ent = &g_entities[cs->entityNum]; + + if ( cs->castScriptStatus.castScriptEventIndex >= 0 ) { + ent->client->ps.eFlags |= EF_TALK; + } else { + ent->client->ps.eFlags &= ~EF_TALK; + } + } +} + +/* +=========== +AICast_DBG_RouteTable_f +=========== +*/ +void AICast_DBG_RouteTable_f( vec3_t org, char *param ) { + static int srcarea = 0, dstarea = 0; +// extern botlib_export_t botlib; // TTimo: unused + + if ( !param || strlen( param ) < 1 ) { + trap_Printf( "You must specify 'src', 'dest' or 'show'\n" ); + return; + } + + trap_AAS_SetCurrentWorld( 0 ); // use the default world, which should have a routetable + + if ( Q_stricmp( param, "toggle" ) == 0 ) { + trap_AAS_RT_ShowRoute( vec3_origin, -666, -666 ); // stupid toggle hack + return; + } + + if ( Q_stricmp( param, "src" ) == 0 ) { // set the src + srcarea = 1 + trap_AAS_PointAreaNum( org ); + return; + } else if ( Q_stricmp( param, "dest" ) == 0 ) { + dstarea = 1 + trap_AAS_PointAreaNum( org ); + } + + if ( srcarea && dstarea ) { // show the path + trap_AAS_RT_ShowRoute( org, srcarea - 1, dstarea - 1 ); + } else + { + trap_Printf( "You must specify 'src' & 'dest' first\n" ); + } +} + +/* +=============== +AICast_DBG_Spawn_f +=============== +*/ +void AICast_DBG_Spawn_f( gclient_t *client, char *cmd ) { + extern qboolean G_CallSpawn( gentity_t *ent ); + gentity_t *ent; + vec3_t dir; + + ent = G_Spawn(); + ent->classname = G_Alloc( strlen( cmd ) + 1 ); + strcpy( ent->classname, cmd ); + AngleVectors( client->ps.viewangles, dir, NULL, NULL ); + VectorMA( client->ps.origin, 96, dir, ent->s.origin ); + + if ( !G_CallSpawn( ent ) ) { + G_Printf( "Error: unable to spawn \"%s\" entity\n", cmd ); + } +} + +/* +=============== +AICast_DBG_Cmd_f + + General entry point for all "aicast ..." commands +=============== +*/ +void AICast_DBG_Cmd_f( int clientNum ) { + gentity_t *ent; + char cmd[MAX_TOKEN_CHARS]; + + ent = g_entities + clientNum; + if ( !ent->client ) { + return; // not fully in game yet + } + + // get the first word following "aicast" + trap_Argv( 1, cmd, sizeof( cmd ) ); + + if ( Q_stricmp( cmd, "dbg_routetable" ) == 0 ) { + trap_Argv( 2, cmd, sizeof( cmd ) ); + AICast_DBG_RouteTable_f( ent->client->ps.origin, cmd ); + return; + } + if ( Q_stricmp( cmd, "spawn" ) == 0 ) { + // spawn a given character + trap_Argv( 2, cmd, sizeof( cmd ) ); + AICast_DBG_Spawn_f( ent->client, cmd ); + return; + } + if ( Q_stricmp( cmd, "getname" ) == 0 ) { + // get name of character we're looking at +// AICast_DBG_GetName_f(ent); + return; + } + if ( Q_stricmp( cmd, "followme" ) == 0 ) { + // tell character to follow us + trap_Argv( 2, cmd, sizeof( cmd ) ); +// AICast_DBG_FollowMe_f(ent->client, cmd); + return; + } +} +/* +// Ridah, faster Win32 code +#ifdef _WIN32 +#undef MAX_PATH // this is an ugly hack, to temporarily ignore the current definition, since it's also defined in windows.h +#include +#undef MAX_PATH +#define MAX_PATH MAX_QPATH +#endif + +int Sys_MilliSeconds(void) +{ +// Ridah, faster Win32 code +#ifdef _WIN32 + int sys_curtime; + static qboolean initialized = qfalse; + static int sys_timeBase; + + if (!initialized) { + sys_timeBase = timeGetTime(); + initialized = qtrue; + } + sys_curtime = timeGetTime() - sys_timeBase; + + return sys_curtime; +#else + return clock() * 1000 / CLOCKS_PER_SEC; +#endif +} //end of the function Sys_MilliSeconds +*/ diff --git a/Projects/Android/jni/rtcw/src/game/ai_cast_events.c b/Projects/Android/jni/rtcw/src/game/ai_cast_events.c new file mode 100644 index 0000000..5b8dd8f --- /dev/null +++ b/Projects/Android/jni/rtcw/src/game/ai_cast_events.c @@ -0,0 +1,594 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +//=========================================================================== +// +// Name: ai_cast_events.c +// Function: Wolfenstein AI Character Events +// Programmer: Ridah +// Tab Size: 4 (real tabs) +//=========================================================================== + +#include "../game/g_local.h" +#include "../game/q_shared.h" +#include "../game/botlib.h" //bot lib interface +#include "../game/be_aas.h" +#include "../game/be_ea.h" +#include "../game/be_ai_gen.h" +#include "../game/be_ai_goal.h" +#include "../game/be_ai_move.h" +#include "../botai/botai.h" //bot ai interface + +#include "ai_cast.h" + +/* +Contains response functions for various events that require specific handling +for Cast AI's. +*/ + +/* +============ +AICast_Sight +============ +*/ +void AICast_Sight( gentity_t *ent, gentity_t *other, int lastSight ) { + cast_state_t *cs, *ocs; + + cs = AICast_GetCastState( ent->s.number ); + ocs = AICast_GetCastState( other->s.number ); + + // + // call the sightfunc for this cast, so we can play associated sounds, or do any character-specific things + // + if ( cs->sightfunc ) { + // factor in the reaction time + if ( AICast_EntityVisible( cs, other->s.number, qfalse ) ) { + cs->sightfunc( ent, other, lastSight ); + } + } + + if ( other->aiName && other->health <= 0 ) { + + // they died since we last saw them + if ( ocs->deathTime > lastSight ) { + if ( !AICast_SameTeam( cs, other->s.number ) ) { + AICast_ScriptEvent( cs, "enemysightcorpse", other->aiName ); + } else if ( !( cs->castScriptStatus.scriptFlags & SFL_FRIENDLYSIGHTCORPSE_TRIGGERED ) ) { + cs->castScriptStatus.scriptFlags |= SFL_FRIENDLYSIGHTCORPSE_TRIGGERED; + AICast_ScriptEvent( cs, "friendlysightcorpse", "" ); + } + } + + // if this is the first time, call the sight script event + } else if ( !lastSight && other->aiName ) { + if ( !AICast_SameTeam( cs, other->s.number ) ) { + // disabled.. triggered when entering combat mode + //AICast_ScriptEvent( cs, "enemysight", other->aiName ); + } else { + AICast_ScriptEvent( cs, "sight", other->aiName ); + } + } +} + +/* +============ +AICast_Pain +============ +*/ +void AICast_Pain( gentity_t *targ, gentity_t *attacker, int damage, vec3_t point ) { + cast_state_t *cs; + + cs = AICast_GetCastState( targ->s.number ); + + // print debugging message + if ( aicast_debug.integer == 2 && attacker->s.number == 0 ) { + G_Printf( "hit %s %i\n", targ->aiName, targ->health ); + } + + // if we are below alert mode, then go there immediately + if ( cs->aiState < AISTATE_ALERT ) { + AICast_StateChange( cs, AISTATE_ALERT ); + } + + if ( cs->aiFlags & AIFL_NOPAIN ) { + return; + } + + // process the event (turn to face the attacking direction? go into hide/retreat state?) + // need to weigh up the situation, but foremost, an inactive AI cast should always react in some way to being hurt + cs->lastPain = level.time; + + // record the sighting (FIXME: silent weapons shouldn't do this, but the AI should react in some way) + if ( attacker->client ) { + AICast_UpdateVisibility( targ, attacker, qtrue, qtrue ); + } + + // if either of us are neutral, then we are now enemies + if ( targ->aiTeam == AITEAM_NEUTRAL || attacker->aiTeam == AITEAM_NEUTRAL ) { + cs->vislist[attacker->s.number].flags |= AIVIS_ENEMY; + } + + AICast_ScriptEvent( cs, "painenemy", attacker->aiName ); + + AICast_ScriptEvent( cs, "pain", va( "%d %d", targ->health, targ->health + damage ) ); + + if ( cs->aiFlags & AIFL_DENYACTION ) { + // dont play any sounds + return; + } + + // + // call the painfunc for this cast, so we can play associated sounds, or do any character-specific things + // + if ( cs->painfunc ) { + cs->painfunc( targ, attacker, damage, point ); + } +} + +/* +============ +AICast_Die +============ +*/ +void AICast_Die( gentity_t *self, gentity_t *inflictor, gentity_t *attacker, int damage, int meansOfDeath ) { + int contents; + int killer; + cast_state_t *cs; + qboolean nogib = qtrue; + char mapname[MAX_QPATH]; + + // print debugging message + if ( aicast_debug.integer == 2 && attacker->s.number == 0 ) { + G_Printf( "killed %s\n", self->aiName ); + } + + cs = AICast_GetCastState( self->s.number ); + + if ( attacker ) { + killer = attacker->s.number; + } else { + killer = ENTITYNUM_WORLD; + } + + // record the sighting (FIXME: silent weapons shouldn't do this, but the AI should react in some way) + if ( attacker->client ) { + AICast_UpdateVisibility( self, attacker, qtrue, qtrue ); + } + + if ( self->aiCharacter == AICHAR_HEINRICH || self->aiCharacter == AICHAR_HELGA || self->aiCharacter == AICHAR_SUPERSOLDIER || self->aiCharacter == AICHAR_PROTOSOLDIER ) { + if ( self->health <= GIB_HEALTH ) { + self->health = -1; + } + } + + // the zombie should show special effect instead of gibbing + if ( self->aiCharacter == AICHAR_ZOMBIE && cs->secondDeadTime ) { + if ( cs->secondDeadTime > 1 ) { + // we are already totally dead + self->health += damage; // don't drop below gib_health if we weren't already below it + return; + } +/* + if (!cs->rebirthTime) + { + self->health = -999; + damage = 999; + } else if ( self->health >= GIB_HEALTH ) { + // while waiting for rebirth, we only "die" if we drop below gib health + return; + } +*/ + // always gib + self->health = -999; + damage = 999; + } + + // Zombies are very fragile against highly explosives + if ( self->aiCharacter == AICHAR_ZOMBIE && damage > 20 && inflictor != attacker ) { + self->health = -999; + damage = 999; + } + + // process the event + if ( self->client->ps.pm_type == PM_DEAD ) { + // already dead + if ( self->health < GIB_HEALTH ) { + if ( self->aiCharacter == AICHAR_ZOMBIE ) { + // RF, changed this so Zombies always gib now + GibEntity( self, killer ); + nogib = qfalse; +/* + // Zombie has special exploding cloud effect + if (attacker != inflictor || attacker->s.weapon == WP_VENOM) + { + GibEntity( self, killer ); + nogib = qfalse; + } else { + // Zombie will decompose upon dying + self->client->ps.eFlags |= EF_MONSTER_EFFECT2; + self->s.effect2Time = level.time+200; + self->health = -1; + } +*/ + self->takedamage = qfalse; + self->r.contents = 0; + cs->secondDeadTime = 2; + cs->rebirthTime = 0; + cs->revivingTime = 0; + } else { + body_die( self, inflictor, attacker, damage, meansOfDeath ); + return; + } + } + + } else { // this is our first death, so set everything up + + if ( level.intermissiontime ) { + return; + } + + self->client->ps.pm_type = PM_DEAD; + + self->enemy = attacker; + + // drop a weapon? + // if client is in a nodrop area, don't drop anything + contents = trap_PointContents( self->r.currentOrigin, -1 ); + if ( !( contents & CONTENTS_NODROP ) ) { + TossClientItems( self ); + } + + // make sure the client doesn't forget about this entity until it's set to "dead" frame + // otherwise it might replay it's death animation if it goes out and into client view + self->r.svFlags |= SVF_BROADCAST; + + self->takedamage = qtrue; // can still be gibbed + + self->s.weapon = WP_NONE; + if ( cs->bs ) { + cs->weaponNum = WP_NONE; + } + self->client->ps.weapon = WP_NONE; + + self->s.powerups = 0; + self->r.contents = CONTENTS_CORPSE; + + self->s.angles[0] = 0; + self->s.angles[1] = self->client->ps.viewangles[1]; + self->s.angles[2] = 0; + + VectorCopy( self->s.angles, self->client->ps.viewangles ); + + self->s.loopSound = 0; + + self->r.maxs[2] = -8; + self->client->ps.maxs[2] = self->r.maxs[2]; + + // remove powerups + memset( self->client->ps.powerups, 0, sizeof( self->client->ps.powerups ) ); + + //cs->rebirthTime = 0; + + // never gib in a nodrop + if ( self->health <= GIB_HEALTH ) { + if ( self->aiCharacter == AICHAR_ZOMBIE ) { + // RF, changed this so Zombies always gib now + GibEntity( self, killer ); + nogib = qfalse; + } else if ( !( contents & CONTENTS_NODROP ) ) { + body_die( self, inflictor, attacker, damage, meansOfDeath ); + //GibEntity( self, killer ); + nogib = qfalse; + } + } + + // if we are a zombie, and lying down during our first death, then we should just die + if ( !( self->aiCharacter == AICHAR_ZOMBIE && cs->secondDeadTime && cs->rebirthTime ) ) { + + // set enemy weapon + BG_UpdateConditionValue( self->s.number, ANIM_COND_ENEMY_WEAPON, 0, qfalse ); + if ( attacker->client ) { + BG_UpdateConditionValue( self->s.number, ANIM_COND_ENEMY_WEAPON, inflictor->s.weapon, qtrue ); + } else { + BG_UpdateConditionValue( self->s.number, ANIM_COND_ENEMY_WEAPON, 0, qfalse ); + } + + // set enemy location + BG_UpdateConditionValue( self->s.number, ANIM_COND_ENEMY_POSITION, 0, qfalse ); + if ( infront( self, inflictor ) ) { + BG_UpdateConditionValue( self->s.number, ANIM_COND_ENEMY_POSITION, POSITION_INFRONT, qtrue ); + } else { + BG_UpdateConditionValue( self->s.number, ANIM_COND_ENEMY_POSITION, POSITION_BEHIND, qtrue ); + } + + if ( self->takedamage ) { // only play the anim if we haven't gibbed + // play the animation + BG_AnimScriptEvent( &self->client->ps, ANIM_ET_DEATH, qfalse, qtrue ); + } + + // set gib delay + if ( cs->aiCharacter == AICHAR_HEINRICH || cs->aiCharacter == AICHAR_HELGA ) { + cs->lastLoadTime = level.time + self->client->ps.torsoTimer - 200; + } + + // set this flag so no other anims override us + self->client->ps.eFlags |= EF_DEAD; + self->s.eFlags |= EF_DEAD; + + // make sure we dont move around while on the ground + //self->flags |= FL_NO_HEADCHECK; + + } + + // if end map, sink into ground + cs->deadSinkStartTime = 0; + if ( cs->aiCharacter == AICHAR_WARZOMBIE ) { + trap_Cvar_VariableStringBuffer( "mapname", mapname, sizeof( mapname ) ); + if ( !Q_strncmp( mapname, "end", 3 ) ) { // !! FIXME: post beta2, make this a spawnflag! + cs->deadSinkStartTime = level.time + 4000; + } + } + } + + if ( nogib ) { + // set for rebirth + if ( self->aiCharacter == AICHAR_ZOMBIE ) { + if ( !cs->secondDeadTime ) { + cs->rebirthTime = level.time + 5000 + rand() % 2000; + // RF, only set for gib at next death, if NoRevive is not set + if ( !( self->spawnflags & 2 ) ) { + cs->secondDeadTime = qtrue; + } + cs->revivingTime = 0; + } else if ( cs->secondDeadTime > 1 ) { + cs->rebirthTime = 0; + cs->revivingTime = 0; + cs->deathTime = level.time; + } + } else { + // the body can still be gibbed + self->die = body_die; + } + } + + trap_LinkEntity( self ); + + // kill, instanly, any streaming sound the character had going + G_AddEvent( &g_entities[self->s.number], EV_STOPSTREAMINGSOUND, 0 ); + + // mark the time of death + cs->deathTime = level.time; + + // dying ai's can trigger a target + if ( !cs->rebirthTime ) { + G_UseTargets( self, self ); + // really dead now, so call the script + AICast_ScriptEvent( cs, "death", attacker->aiName ? attacker->aiName : "" ); + // call the deathfunc for this cast, so we can play associated sounds, or do any character-specific things + if ( !( cs->aiFlags & AIFL_DENYACTION ) && cs->deathfunc ) { + cs->deathfunc( self, attacker, damage, meansOfDeath ); //----(SA) added mod + } + } else { + // really dead now, so call the script + AICast_ScriptEvent( cs, "fakedeath", "" ); + // call the deathfunc for this cast, so we can play associated sounds, or do any character-specific things + if ( !( cs->aiFlags & AIFL_DENYACTION ) && cs->deathfunc ) { + cs->deathfunc( self, attacker, damage, meansOfDeath ); //----(SA) added mod + } + } +} + +/* +=============== +AICast_EndChase +=============== +*/ +void AICast_EndChase( cast_state_t *cs ) { + // anything? +} + +/* +=============== +AICast_AIDoor_Touch +=============== +*/ +void AICast_AIDoor_Touch( gentity_t *ent, gentity_t *aidoor_trigger, gentity_t *door ) { + cast_state_t *cs, *ocs; + gentity_t *trav; + int i; + trace_t tr; + vec3_t mins, pos, dir; + + cs = AICast_GetCastState( ent->s.number ); + + if ( !cs->bs ) { + return; + } + + // does the aidoor have ai_marker's? + if ( !aidoor_trigger->targetname ) { + G_Printf( "trigger_aidoor has no ai_marker's at %s\n", vtos( ent->r.currentOrigin ) ); + return; + } + + // are we heading for an ai_marker? + if ( cs->aifunc == AIFunc_DoorMarker ) { + return; + } + + // if they are moving away from the door, ignore them + if ( VectorLength( cs->bs->velocity ) > 1 ) { + VectorAdd( door->r.absmin, door->r.absmax, pos ); + VectorScale( pos, 0.5, pos ); + VectorSubtract( pos, cs->bs->origin, dir ); + if ( DotProduct( cs->bs->velocity, dir ) < 0 ) { + return; + } + } + + // TTimo: gcc: suggest () around assignment used as truth value + for ( trav = NULL; ( trav = G_Find( trav, FOFS( target ), aidoor_trigger->targetname ) ); ) { + // make sure the marker is vacant + trap_Trace( &tr, trav->r.currentOrigin, ent->r.mins, ent->r.maxs, trav->r.currentOrigin, ent->s.number, ent->clipmask ); + if ( tr.startsolid ) { + continue; + } + // search all other AI's, to see if they are heading for this marker + for ( i = 0, ocs = AICast_GetCastState( 0 ); i < aicast_maxclients; i++, ocs++ ) { + if ( !ocs->bs ) { + continue; + } + if ( ocs->aifunc != AIFunc_DoorMarker ) { + continue; + } + if ( ocs->doorMarker != trav->s.number ) { + continue; + } + // found a match + break; + } + if ( i < aicast_maxclients ) { + continue; + } + // make sure there is a clear path + VectorCopy( ent->r.mins, mins ); + mins[2] += 16; // step height + trap_Trace( &tr, ent->r.currentOrigin, mins, ent->r.maxs, trav->r.currentOrigin, ent->s.number, ent->clipmask ); + if ( tr.fraction < 1.0 ) { + continue; + } + // the marker is vacant and available + cs->doorMarkerTime = level.time; + cs->doorMarkerNum = trav->s.number; + cs->doorMarkerDoor = door->s.number; + break; + } +} + +/* +============ +AICast_ProcessActivate +============ +*/ +void AICast_ProcessActivate( int entNum, int activatorNum ) { + cast_state_t *cs; + gentity_t *newent, *ent, *activator; + gclient_t *client; + + cs = AICast_GetCastState( entNum ); + client = &level.clients[entNum]; + ent = &g_entities[entNum]; + activator = &g_entities[activatorNum]; + + if ( cs->lastActivate > level.time - 1000 ) { + return; + } + cs->lastActivate = level.time; + + if ( !AICast_SameTeam( cs, activatorNum ) ) { + + if ( ent->aiTeam == AITEAM_NEUTRAL ) { + AICast_ScriptEvent( cs, "activate", g_entities[activatorNum].aiName ); + } + + return; + } + + // try running the activate event, if it denies us the request, then abort + cs->aiFlags &= ~AIFL_DENYACTION; + AICast_ScriptEvent( cs, "activate", g_entities[activatorNum].aiName ); + if ( cs->aiFlags & AIFL_DENYACTION ) { + return; + } + + // if we are doing something else + if ( cs->castScriptStatus.castScriptEventIndex >= 0 ) { + if ( ent->eventTime != level.time ) { + G_AddEvent( &g_entities[entNum], EV_GENERAL_SOUND, G_SoundIndex( aiDefaults[cs->aiCharacter].soundScripts[ORDERSDENYSOUNDSCRIPT] ) ); + } + return; + } + + // if we are already following them, stop following + if ( cs->leaderNum == activatorNum ) { + if ( ent->eventTime != level.time ) { + G_AddEvent( &g_entities[entNum], EV_GENERAL_SOUND, G_SoundIndex( aiDefaults[cs->aiCharacter].soundScripts[STAYSOUNDSCRIPT] ) ); + } + + cs->leaderNum = -1; + + // create a goal at this position + newent = G_Spawn(); + newent->classname = "AI_wait_goal"; + newent->r.ownerNum = entNum; + G_SetOrigin( newent, cs->bs->origin ); + AIFunc_ChaseGoalStart( cs, newent->s.number, 128, qtrue ); + + //AIFunc_IdleStart( cs ); + } else { // start following + int count, i; + cast_state_t *tcs; + + // if they already have enough followers, deny + for ( count = 0, i = 0, tcs = caststates; i < level.maxclients; i++, tcs++ ) { + if ( tcs->bs && tcs != cs && tcs->entityNum != activatorNum && g_entities[tcs->entityNum].health > 0 && tcs->leaderNum == activatorNum ) { + count++; + } + } + if ( count >= 3 ) { + if ( ent->eventTime != level.time ) { + G_AddEvent( &g_entities[entNum], EV_GENERAL_SOUND, G_SoundIndex( aiDefaults[cs->aiCharacter].soundScripts[ORDERSDENYSOUNDSCRIPT] ) ); + } + return; + } + + if ( ent->eventTime != level.time ) { + G_AddEvent( &g_entities[entNum], EV_GENERAL_SOUND, G_SoundIndex( aiDefaults[cs->aiCharacter].soundScripts[FOLLOWSOUNDSCRIPT] ) ); + } + + // if they have a wait goal, free it + if ( cs->followEntity >= MAX_CLIENTS && g_entities[cs->followEntity].classname && !strcmp( g_entities[cs->followEntity].classname, "AI_wait_goal" ) ) { + G_FreeEntity( &g_entities[cs->followEntity] ); + } + + cs->followEntity = -1; + cs->leaderNum = activatorNum; + } +} + +/* +================ +AICast_RecordScriptSound +================ +*/ +void AICast_RecordScriptSound( int client ) { + cast_state_t *cs; + + cs = AICast_GetCastState( client ); + cs->lastScriptSound = level.time; +} diff --git a/Projects/Android/jni/rtcw/src/game/ai_cast_fight.c b/Projects/Android/jni/rtcw/src/game/ai_cast_fight.c new file mode 100644 index 0000000..4640b31 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/game/ai_cast_fight.c @@ -0,0 +1,2371 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +//=========================================================================== +// +// Name: ai_cast_fight.c +// Function: Wolfenstein AI Character Fighting/Combat +// Programmer: Ridah +// Tab Size: 4 (real tabs) +//=========================================================================== + +#include "../game/g_local.h" +#include "../game/q_shared.h" +#include "../game/botlib.h" //bot lib interface +#include "../game/be_aas.h" +#include "../game/be_ea.h" +#include "../game/be_ai_gen.h" +#include "../game/be_ai_goal.h" +#include "../game/be_ai_move.h" +#include "../game/be_ai_weap.h" +#include "../botai/botai.h" //bot ai interface + +#include "ai_cast.h" + +/* +Support routines for the Decision Making layer. +*/ + +// FIXME: go through here and convert all weapon/character parameters to #define's +// and move them to a seperate header file for easy modification + +/* +================= +AICast_StateChange + + returns qfalse if scripting has denied the action +================= +*/ +qboolean AICast_StateChange( cast_state_t *cs, aistateEnum_t newaistate ) { + gentity_t *ent; + int result, scriptIndex; + aistateEnum_t oldstate; + + ent = &g_entities[cs->entityNum]; + + oldstate = cs->aiState; + cs->aiState = newaistate; + + // RF, if the state is the same, ignore + if ( oldstate == newaistate ) { + return qtrue; + } + + // if moving from query mode, kill the anim and pausetime + if ( oldstate == AISTATE_QUERY ) { + // stop playing the animation + ent->client->ps.torsoTimer = 0; + ent->client->ps.legsTimer = 0; + cs->pauseTime = 0; + } + + // if moving to combat mode, default back to normal movetype (fast) + if ( newaistate == AISTATE_COMBAT ) { + cs->movestate = MS_DEFAULT; + cs->movestateType = MSTYPE_NONE; + } + + scriptIndex = cs->scriptCallIndex; + + // check scripting to see if this event should be ignored (no anim or handling) + cs->aiFlags &= ~AIFL_DENYACTION; + AICast_ScriptEvent( cs, "statechange", va( "%s %s", animStateStr[oldstate].string, animStateStr[newaistate].string ) ); + + if ( !( cs->aiFlags & AIFL_DENYACTION ) ) { + // if no script was found, try enemysight + if ( newaistate == AISTATE_COMBAT && cs->scriptCallIndex == scriptIndex && + !( cs->vislist[cs->enemyNum].flags & AIVIS_SIGHT_SCRIPT_CALLED ) ) { // no script was found, so default back to enemysight + AICast_ScriptEvent( cs, "enemysight", g_entities[cs->enemyNum].aiName ); + cs->vislist[cs->enemyNum].flags |= AIVIS_SIGHT_SCRIPT_CALLED; + if ( !( cs->aiFlags & AIFL_DENYACTION ) ) { + G_AddEvent( ent, EV_GENERAL_SOUND, G_SoundIndex( aiDefaults[ent->aiCharacter].soundScripts[SIGHTSOUNDSCRIPT] ) ); + } + + if ( cs->aiFlags & AIFL_DENYACTION ) { + // don't run any dynamic handling or default anims + return qfalse; + } + } + + // look for an animation + result = BG_AnimScriptStateChange( &ent->client->ps, newaistate, oldstate ); + + if ( result > 0 ) { + // pause while the animation plays + cs->pauseTime = level.time + result; + } + } + + // set query mode fields + if ( newaistate == AISTATE_QUERY ) { + cs->queryStartTime = level.time; + if ( cs->queryCountValidTime < level.time ) { + cs->queryCount = 0; + } else { + cs->queryCount++; + } + cs->queryCountValidTime = level.time + 60000; // one minute + switch ( cs->queryCount ) { + case 0: + cs->queryAlertSightTime = level.time + 1000; + break; + case 1: + cs->queryAlertSightTime = level.time + 500; + break; + default: + cs->queryAlertSightTime = -1; // IMMEDIATE COMBAT MODE + break; + } + } + + return qtrue; +} + +/* +================= +AICast_ScanForEnemies + + returns the number of enemies visible, filling the "enemies" list before exiting + + if we only found queryEnemies (possibly hostile, but not sure) while relaxed, + then a negative count is returned +================= +*/ +int AICast_ScanForEnemies( cast_state_t *cs, int *enemies ) { + int i, j, enemyCount, queryCount, friendlyAlertCount; + static float distances[MAX_CLIENTS]; + static int sortedEnemies[MAX_CLIENTS]; + float lastDist; + int best, oldEnemy, oldPauseTime; + cast_state_t *ocs; + + if ( cs->castScriptStatus.scriptAttackEnt >= 0 ) { + if ( g_entities[cs->castScriptStatus.scriptAttackEnt].health <= 0 ) { + cs->castScriptStatus.scriptAttackEnt = -1; + } else { + // if we are not in combat mode, then an enemy should trigger a state change straight to combat mode + if ( cs->aiState < AISTATE_COMBAT ) { + AICast_StateChange( cs, AISTATE_COMBAT ); // just go straight to combat mode + } + enemies[0] = cs->castScriptStatus.scriptAttackEnt; + return 1; + } + } + + if ( cs->castScriptStatus.scriptNoAttackTime >= level.time ) { + return qfalse; + } + + if ( cs->noAttackTime >= level.time ) { + return qfalse; + } + + if ( cs->castScriptStatus.scriptNoSightTime >= level.time ) { + return qfalse; + } + + if ( cs->pauseTime > level.time ) { + return qfalse; + } + + enemyCount = 0; + queryCount = 0; + friendlyAlertCount = 0; + + // while we're here, may as well check for some baddies + for ( i = 0; i < g_maxclients.integer; i++ ) + { + if ( g_entities[i].inuse ) { + // try not to commit suicide + if ( i != cs->entityNum ) { + if ( AICast_EntityVisible( cs, i, qfalse ) ) { + // how should we deal with them? + if ( ( g_entities[i].health > 0 ) && AICast_HostileEnemy( cs, i ) ) { // visible and a baddy! + enemies[enemyCount] = i; + enemyCount++; + queryCount = 0; + friendlyAlertCount = 0; + } else if ( !enemyCount && ( g_entities[i].health > 0 ) && AICast_QueryEnemy( cs, i ) && ( cs->vislist[i].flags & AIVIS_PROCESS_SIGHTING ) ) { + enemies[queryCount] = i; + queryCount++; + friendlyAlertCount = 0; + } else if ( !queryCount && !enemyCount && ( cs->vislist[i].flags & AIVIS_INSPECT ) ) { + enemies[friendlyAlertCount] = i; + friendlyAlertCount++; + } + // the sighting has been processed + cs->vislist[i].flags &= ~AIVIS_PROCESS_SIGHTING; + } + } + } + } + + if ( !enemyCount ) { + if ( queryCount ) { + enemyCount = queryCount; + } else if ( friendlyAlertCount ) { + enemyCount = friendlyAlertCount; + } + } + + if ( !enemyCount ) { // nothing worth doing anything about + // look for audible events that we should investigate + if ( cs->audibleEventTime && cs->audibleEventTime < level.time && cs->audibleEventTime > level.time - 2000 ) { + return -4; + } + // look for bullet impacts that have occured recently + if ( cs->bulletImpactTime && cs->bulletImpactTime < level.time && cs->bulletImpactTime > level.time - 1000 ) { + return -3; + } + return 0; + } + + // sort the enemies by distance + for ( i = 0; i < enemyCount; i++ ) { + distances[i] = Distance( cs->bs->origin, g_entities[enemies[i]].client->ps.origin ); + if ( !distances[i] ) { + G_Printf( "WARNING: zero distance between enemies:\n%s at %s, %s at %s\n", g_entities[cs->entityNum].aiName, vtos( cs->bs->origin ), g_entities[enemies[i]].aiName, vtos( g_entities[enemies[i]].client->ps.origin ) ); + distances[i] = 999998; // try to ignore them (HACK) + } + } + for ( j = 0; j < enemyCount; j++ ) { + lastDist = 999999; + best = -1; + for ( i = 0; i < enemyCount; i++ ) { + if ( distances[i] && distances[i] < lastDist ) { + lastDist = distances[i]; + best = i; + } + } + if ( best < 0 ) { + G_Error( "error sorting enemies by distance\n" ); + } + sortedEnemies[j] = enemies[best]; + distances[best] = -1; + } + memcpy( enemies, sortedEnemies, sizeof( int ) * enemyCount ); + + // if we are not in combat mode, then an enemy should trigger a state change straight to combat mode + if ( !queryCount && !friendlyAlertCount && enemyCount && cs->aiState < AISTATE_COMBAT ) { + // face them while making the transition + oldEnemy = cs->enemyNum; + // set it temporarily + cs->enemyNum = enemies[0]; + // + AICast_AimAtEnemy( cs ); + AICast_StateChange( cs, AISTATE_COMBAT ); // just go straight to combat mode + // set it back + cs->enemyNum = oldEnemy; + } + + // if we are in relaxed state, and we see a query enemy, then go into query mode + if ( queryCount ) { + if ( cs->aiState == AISTATE_RELAXED ) { + // go into query mode + if ( AICast_StateChange( cs, AISTATE_QUERY ) ) { + cs->enemyNum = enemies[0]; // lock onto the closest potential enemy + return -1; + } + return 0; // scripting obviously doesn't want us to progress from relaxed just yet + } + // else ignore the query mode, since we are already above relaxed mode + return 0; + } + if ( friendlyAlertCount ) { + // call a script event + oldPauseTime = cs->scriptPauseTime; + if ( g_entities[enemies[0]].health <= 0 ) { + AICast_ForceScriptEvent( cs, "inspectbodystart", g_entities[enemies[0]].aiName ); + if ( cs->aiFlags & AIFL_DENYACTION ) { + // ignore this friendly + cs->vislist[enemies[0]].flags |= AIVIS_INSPECTED; // they have been notified + cs->vislist[enemies[0]].flags &= ~AIVIS_INSPECT; // they have been notified + return 0; + } + } + // + if ( cs->aiState < AISTATE_COMBAT ) { + // go into alert mode, and return this entity so we can inspect it or something, + // but let dynamic AI sort out what it wants to do + if ( cs->aiState == AISTATE_ALERT || AICast_StateChange( cs, AISTATE_ALERT ) ) { + // only return the entity if they are in combat mode or dead + ocs = AICast_GetCastState( enemies[0] ); + if ( ( g_entities[enemies[0]].health <= 0 ) || ( ocs->aiState >= AISTATE_COMBAT ) ) { + return -2; + } + } + return 0; // scripting failed or they're not worth physically inspecting + } + // ignore the friendly, we have our hands full + return 0; + } + + // must be hostile enemy(s) found, so return them + return enemyCount; +} + +/* +================== +AICast_EntityVisible +================== +*/ +qboolean AICast_EntityVisible( cast_state_t *cs, int enemynum, qboolean directview ) { + cast_visibility_t *vis; + int last_visible; + int reactionTime; + float dist; + + if ( enemynum >= MAX_CLIENTS ) { + return qtrue; // FIXME: do a visibility calculation on non-client entities? + + } + vis = &cs->vislist[enemynum]; + + if ( !vis->visible_timestamp && !vis->real_visible_timestamp ) { + return qfalse; // they are not visible at all + + } + if ( directview ) { + last_visible = vis->real_visible_timestamp; + } else { + last_visible = vis->visible_timestamp; + } + + reactionTime = (int)( 1000 * cs->attributes[REACTION_TIME] ); + if ( cs->startAttackCount > 1 ) { + // we recently saw them, so we are more "aware" of their presence + reactionTime /= 2; + } + + // if they are close, we should react faster + if ( cs->bs && enemynum == cs->enemyNum ) { + dist = cs->enemyDist; + } else { + dist = VectorDistance( g_entities[cs->entityNum].client->ps.origin, cs->vislist[enemynum].visible_pos ); + } + if ( dist < 384 ) { + reactionTime *= 0.5 + 0.5 * ( dist / 384 ); + } + + if ( vis->notvisible_timestamp < ( level.time - reactionTime ) ) { + // make sure we've seen them since we've last not seen them (since the visibility checking is spread amongst server frames) + if ( vis->notvisible_timestamp < last_visible ) { + return qtrue; + } + } + + // we can't directly see them, but if they've just left our sight, pretend we can see them for another second or so + + if ( !directview && last_visible ) { + if ( vis->notvisible_timestamp > last_visible ) { + if ( vis->notvisible_timestamp < ( last_visible + 5000 ) ) { + return qtrue; + } + } + } + + + return qfalse; +} + +/* +================== +AICast_HostileEnemy + + returns qtrue if the entity is hostile +================== +*/ +qboolean AICast_HostileEnemy( cast_state_t *cs, int enemynum ) { + // if we hate them, they are an enemy + if ( cs->vislist[enemynum].flags & AIVIS_ENEMY ) { + return qtrue; + } else { + return qfalse; + } +} + +/* +================== +AICast_QueryEnemy + + returns qtrue if the entity can become hostile (they hurt us or we recognize them) +================== +*/ +qboolean AICast_QueryEnemy( cast_state_t *cs, int enemynum ) { + + if ( g_entities[cs->entityNum].aiTeam != g_entities[enemynum].aiTeam ) { + if ( g_entities[cs->entityNum].aiTeam == AITEAM_MONSTER || g_entities[enemynum].aiTeam == AITEAM_MONSTER ) { + // monsters hate all non-monsters and vice-versa + return qtrue; + } else { + // neutral's can only possibly become hostile if they hurt us, otherwise they are assumed to be harmless + if ( g_entities[cs->entityNum].aiTeam == AITEAM_NEUTRAL || g_entities[enemynum].aiTeam == AITEAM_NEUTRAL ) { + return qfalse; // one of us is neutral, assume harmless + } + return qtrue; + } + } else { // same team + return qfalse; // be cool bitch + } + +} + +/* +================== +AICast_SameTeam + + the player is always team 1, AI's default to team 0 + + MONSTER's hate everyone else except other MONSTER's + + NEUTRAL's are cool with everyone that hasn't hurt them +================== +*/ +qboolean AICast_SameTeam( cast_state_t *cs, int enemynum ) { + + if ( g_entities[cs->entityNum].aiTeam != g_entities[enemynum].aiTeam ) { + if ( g_entities[cs->entityNum].aiTeam == AITEAM_NEUTRAL || g_entities[enemynum].aiTeam == AITEAM_NEUTRAL ) { + // if we hate them, they are an enemy + if ( cs->vislist[enemynum].flags & AIVIS_ENEMY ) { + return qfalse; + } else { + return qtrue; + } + } else { + return qfalse; // they are an enemy + } + } else { + return qtrue; // be cool bitch + } + +} + +/* +================== +AICast_WeaponRange +================== +*/ +float AICast_WeaponRange( cast_state_t *cs, int weaponnum ) { + switch ( weaponnum ) { + case WP_TESLA: + switch ( cs->aiCharacter ) { + case AICHAR_SUPERSOLDIER: // BOSS2 + // if they have a panzer, give this weapon a shorter range + if ( !COM_BitCheck( cs->bs->cur_ps.weapons, WP_PANZERFAUST ) ) { + return TESLA_SUPERSOLDIER_RANGE; + } + } + return ( TESLA_RANGE * 0.9 ) - 50; // allow for bounding box + case WP_FLAMETHROWER: + return ( FLAMETHROWER_RANGE * 0.5 ) - 50; // allow for bounding box + case WP_PANZERFAUST: + return 8000; + + case WP_GRENADE_LAUNCHER: + case WP_GRENADE_PINEAPPLE: + return 800; + case WP_MONSTER_ATTACK1: + switch ( cs->aiCharacter ) { + case AICHAR_HEINRICH: + if ( cs->weaponFireTimes[weaponnum] < level.time - 8000 ) { + return 500; // lots of room for stomping + } else { + return 120; // come in real close + } + case AICHAR_HELGA: // helga BOSS1 melee + return 80; + case AICHAR_WARZOMBIE: + return 80; // make it larger so we can start swinging early, and move in while swinging + case AICHAR_LOPER: // close attack, head-butt, fist + return 60; + case AICHAR_BLACKGUARD: + return BLACKGUARD_MELEE_RANGE; + case AICHAR_STIMSOLDIER3: + return TESLA_RANGE; + case AICHAR_ZOMBIE: // zombie flaming attack + return ZOMBIE_FLAME_RADIUS - 50; // get well within range before starting + } + break; + case WP_MONSTER_ATTACK2: + switch ( cs->aiCharacter ) { + case AICHAR_HEINRICH: + return 8000; + case AICHAR_ZOMBIE: // zombie spirit attack + return 1000; + case AICHAR_HELGA: // zombie spirit attack + return 1900; + case AICHAR_LOPER: // loper leap attack + return 8000; // use it to gain on them also + } + break; + case WP_MONSTER_ATTACK3: + switch ( cs->aiCharacter ) { + case AICHAR_HEINRICH: // spirits + return 50000; + case AICHAR_LOPER: // loper ground attack + return LOPER_GROUND_RANGE; + case AICHAR_WARZOMBIE: // warzombie defense + return 2000; + case AICHAR_ZOMBIE: + return 44; + } + break; + + // Rafael added these changes as per Mikes request + case WP_MAUSER: + case WP_GARAND: + case WP_SNIPERRIFLE: + case WP_SNOOPERSCOPE: + return 8000; + break; + + + } + // default range + return 3000; +} + +/* +================== +AICast_CheckAttack_real +================== +*/ +qboolean AICast_CheckAttack_real( cast_state_t *cs, int enemy, qboolean allowHitWorld ) { + //float points; + vec3_t forward, right, start, end, dir, up, angles; + weaponinfo_t wi; + trace_t trace; + float traceDist; + static vec3_t smins = {-6, -6, -6}, smaxs = {6, 6, 6}; + static vec3_t fmins = {-30, -30, -24}, fmaxs = {30, 30, 24}; + float *mins, *maxs; + float halfHeight; + int traceMask; + int fuzzyCount, i; + gentity_t *ent, *enemyEnt; + float dist; + int passEnt; + int weapnum; + // + if ( enemy < 0 ) { + return qfalse; + } + ent = &g_entities[cs->entityNum]; + enemyEnt = &g_entities[enemy]; + // + if ( cs->bs ) { + weapnum = cs->weaponNum; + } else { + weapnum = ent->client->ps.weapon; + } + // + if ( !weapnum ) { + return qfalse; + } + // + // don't attack while in air (like on a ladder) + if ( !ent->waterlevel && ent->client->ps.groundEntityNum == ENTITYNUM_NONE && !ent->active ) { + // stim is allowed to fire while in air for flying attack + if ( !ent->client->ps.powerups[PW_FLIGHT] ) { + return qfalse; + } + } + // + if ( ent->health <= 0 ) { + return qfalse; + } + // can't attack without any ammo + if ( cs->bs ) { + if ( !AICast_GotEnoughAmmoForWeapon( cs, cs->weaponNum ) ) { + return qfalse; + } + } + // special case: warzombie should play laughing anim at first sight + if ( cs->aiCharacter == AICHAR_WARZOMBIE && weapnum == WP_MONSTER_ATTACK2 ) { + return qtrue; + } + // + //if the enemy isn't directly visible + if ( !allowHitWorld && cs->vislist[enemy].real_visible_timestamp != cs->vislist[enemy].real_update_timestamp ) { + return qfalse; + } + // + //get the weapon info (FIXME: hard-code the weapon info?) + memset( &wi, 0, sizeof( weaponinfo_t ) ); + // + traceMask = MASK_SHOT; // FIXME: assign mask's to different weapons + //end point aiming at + if ( !ent->active ) { + //get the start point shooting from + VectorCopy( enemyEnt->r.currentOrigin, start ); + start[2] += enemyEnt->client->ps.viewheight; + VectorCopy( ent->r.currentOrigin, end ); + end[2] += ent->client->ps.viewheight; + VectorSubtract( start, end, dir ); + vectoangles( dir, angles ); + AngleVectors( angles, forward, right, up ); + CalcMuzzlePoint( &g_entities[cs->entityNum], weapnum, forward, right, up, start ); + + traceDist = AICast_WeaponRange( cs, weapnum ); + switch ( weapnum ) { + case WP_GAUNTLET: + mins = NULL; + maxs = NULL; + break; + case WP_DYNAMITE: + case WP_PANZERFAUST: + case WP_GRENADE_LAUNCHER: + case WP_GRENADE_PINEAPPLE: + traceMask = MASK_MISSILESHOT; + mins = smins; + maxs = smaxs; + break; + case WP_FLAMETHROWER: + mins = fmins; + maxs = fmaxs; + break; + default: + mins = smins; + maxs = smaxs; + break; + } + passEnt = cs->entityNum; + + // don't try too far + dist = Distance( start, enemyEnt->r.currentOrigin ); + fuzzyCount = 6; + if ( traceDist > dist ) { + traceDist = dist; + } else { + dist -= enemyEnt->r.maxs[0]; // subtract distance to edge of bounding box edge + if ( traceDist < dist ) { + return qfalse; + } + } + } else { + gentity_t *mg42; + // we are mounted on a weapon + mg42 = &g_entities[cs->mountedEntity]; + VectorCopy( enemyEnt->r.currentOrigin, start ); + start[2] += enemyEnt->client->ps.viewheight; + VectorCopy( mg42->r.currentOrigin, end ); + VectorSubtract( start, end, dir ); + vectoangles( dir, angles ); + AngleVectors( angles, forward, right, up ); + + VectorCopy( mg42->r.currentOrigin, start ); + VectorMA( start, 16, forward, start ); + VectorMA( start, 16, up, start ); + // snap to integer coordinates for more efficient network bandwidth usage + SnapVector( start ); + + traceDist = 8192; + mins = NULL; + maxs = NULL; + if ( mg42->mg42BaseEnt >= 0 ) { + passEnt = mg42->mg42BaseEnt; + } else { + passEnt = cs->entityNum; + } + + // don't try too far + dist = Distance( start, enemyEnt->r.currentOrigin ); + if ( traceDist > dist ) { + traceDist = dist; + fuzzyCount = 6; + } else { //if (dist > traceDist - 32) { + return qfalse; + } + /*} else { + fuzzyCount = 0; + }*/ + } + + for ( i = 0; i <= fuzzyCount; i++ ) { + VectorMA( start, traceDist, forward, end ); + + // fuzzy end point + if ( i > 0 ) { + VectorMA( end, enemyEnt->r.maxs[0] * 0.9 * (float)( ( i % 2 ) * 2 - 1 ), right, end ); + halfHeight = ( enemyEnt->r.maxs[2] - enemyEnt->r.mins[2] ) / 2.0; + end[2] = ( enemyEnt->r.currentOrigin[2] + enemyEnt->r.mins[2] ) + halfHeight; + VectorMA( end, halfHeight * 0.9 * ( ( (float)( ( i - 1 ) - ( ( i - 1 ) % 2 ) ) / 2 - 1.0 ) ), up, end ); + } + + if ( /*allowHitWorld &&*/ !trap_InPVS( start, end ) ) { + // not possibly attackable + //continue; + return qfalse; + } + + trap_Trace( &trace, start, mins, maxs, end, passEnt, traceMask ); + if ( trace.fraction == 1.0 ) { + if ( !trace.startsolid ) { + return qtrue; // not sure why, but this fixes blackguards in chateau shooting through glass ceiling + } + //return qfalse; + continue; + } + //if won't hit the enemy + if ( trace.entityNum != enemy ) { + + // RF, assume we can shoot through props (chairs, etc) + if ( g_entities[trace.entityNum].takedamage && g_entities[trace.entityNum].health > 0 && + !Q_strncmp( g_entities[trace.entityNum].classname, "props_", 6 ) ) { + return qtrue; + } + + if ( !allowHitWorld ) { + continue; + } + + if ( trace.startsolid ) { + continue; + } + + //if the entity is a client + if ( trace.entityNum >= 0 && trace.entityNum < MAX_CLIENTS ) { + //if a teammate is hit + if ( AICast_SameTeam( cs, trace.entityNum ) ) { + return qfalse; + } + } + //if the projectile does a radial damage + if ( cs->weaponNum == WP_PANZERFAUST ) { + if ( Distance( trace.endpos, g_entities[enemy].s.pos.trBase ) > 120 ) { + continue; + } + //FIXME: check if a teammate gets radial damage + } + } + // will successfully hit enemy + return qtrue; + } + // + return qfalse; +} + +/* +================== +AICast_CheckAttackAtPos +================== +*/ +qboolean AICast_CheckAttackAtPos( int entnum, int enemy, vec3_t pos, qboolean ducking, qboolean allowHitWorld ) { + gentity_t *ent; + vec3_t savepos; + int saveview; + qboolean rval; + cast_state_t *cs; + + cs = AICast_GetCastState( entnum ); + ent = &g_entities[cs->bs->entitynum]; + + VectorCopy( ent->r.currentOrigin, savepos ); + VectorCopy( pos, ent->r.currentOrigin ); + + saveview = ent->client->ps.viewheight; + if ( ducking ) { + if ( ent->client->ps.viewheight != ent->client->ps.crouchViewHeight ) { + ent->client->ps.viewheight = ent->client->ps.crouchViewHeight; + } + } else { + if ( ent->client->ps.viewheight != ent->client->ps.standViewHeight ) { + ent->client->ps.viewheight = ent->client->ps.standViewHeight; + } + } + + rval = AICast_CheckAttack_real( cs, enemy, allowHitWorld ); + + VectorCopy( savepos, ent->r.currentOrigin ); + ent->client->ps.viewheight = saveview; + + return rval; +} + +/* +================== +AICast_CheckAttack + + optimization, uses the cache to avoid possible duplicate calls with same world paramaters +================== +*/ +qboolean AICast_CheckAttack( cast_state_t *cs, int enemy, qboolean allowHitWorld ) { + if ( cs->bs ) { + if ( ( cs->checkAttackCache.time == level.time ) + && ( cs->checkAttackCache.enemy == enemy ) + && ( cs->checkAttackCache.weapon == cs->weaponNum ) + && ( cs->checkAttackCache.allowHitWorld == allowHitWorld ) ) { + //G_Printf( "checkattack cache hit\n" ); + return ( cs->checkAttackCache.result ); + } else { + cs->checkAttackCache.allowHitWorld = allowHitWorld; + cs->checkAttackCache.enemy = enemy; + cs->checkAttackCache.time = level.time; + cs->checkAttackCache.weapon = cs->weaponNum; + return ( cs->checkAttackCache.result = AICast_CheckAttack_real( cs, enemy, allowHitWorld ) ); + } + } else { + return AICast_CheckAttack_real( cs, enemy, allowHitWorld ); + } +} + +/* +================== +AICast_UpdateBattleInventory +================== +*/ +void AICast_UpdateBattleInventory( cast_state_t *cs, int enemy ) { + vec3_t dir; + int i; + + if ( enemy >= 0 ) { + VectorSubtract( cs->vislist[cs->enemyNum].visible_pos, cs->bs->origin, dir ); + cs->enemyHeight = (int) dir[2]; + cs->enemyDist = (int) VectorLength( dir ); + } + + // stock up ammo that should never run out + for ( i = 0; i < WP_NUM_WEAPONS; i++ ) { + if ( ( i >= WP_MONSTER_ATTACK1 && i <= WP_MONSTER_ATTACK3 ) || ( g_entities[cs->bs->entitynum].client->ps.ammo[ BG_FindAmmoForWeapon( i )] > 800 ) ) { + //g_entities[cs->bs->entitynum].client->ps.ammo[ BG_FindAmmoForWeapon(i)] = 999; + Add_Ammo( &g_entities[cs->entityNum], i, 999, qfalse ); + } + } + + BotAI_GetClientState( cs->entityNum, &( cs->bs->cur_ps ) ); + +} + +/* +============== +AICast_WeaponWantScale +============== +*/ +float AICast_WeaponWantScale( cast_state_t *cs, int weapon ) { + switch ( weapon ) { + case WP_GAUNTLET: + return 0.1; + case WP_FLAMETHROWER: + return 2.0; // if we have this up close, definately use it + default: + return 1.0; + } +} + +/* +============== +AICast_GotEnoughAmmoForWeapon +============== +*/ +qboolean AICast_GotEnoughAmmoForWeapon( cast_state_t *cs, int weapon ) { + gentity_t *ent; + int ammo, clip; + + ent = &g_entities[cs->entityNum]; + ammo = ent->client->ps.ammo[BG_FindAmmoForWeapon( weapon )]; + clip = ent->client->ps.ammoclip[BG_FindClipForWeapon( weapon )]; + + // TODO!! check some kind of weapon list that holds the minimum requirements for each weapon + switch ( weapon ) { + case WP_GAUNTLET: + return qtrue; + default: + return (qboolean)( ( clip >= ammoTable[weapon].uses ) || ( ammo >= ammoTable[weapon].uses ) ); //----(SA) + } +} + +/* +============== +AICast_WeaponUsable + + This is used to prevent weapons from being selected, even if they have ammo. + + This can be used to add a delay between firing for special attacks, or make certain + that certain weapons are only selected within a certain range or under certain conditions. + + NOTE: that monster_attack2 will always override monster_attack1 if both are usable +============== +*/ +qboolean AICast_WeaponUsable( cast_state_t *cs, int weaponNum ) { + int delay, oldweap, hitclient; + float dist = -1; + gentity_t *ent, *grenade; + + if ( cs->enemyNum >= 0 ) { + dist = Distance( cs->bs->origin, g_entities[cs->enemyNum].s.pos.trBase ); + } + + oldweap = cs->weaponNum; + ent = &g_entities[cs->entityNum]; + delay = -1; + + // just return qfalse if this weapon isn't ready for use + switch ( weaponNum ) { + // don't attempt to lob a grenade more than this often, since we will abort a grenade + // throw if it's not safe, we shouldn't keep switching back too quickly + case WP_DYNAMITE: + case WP_GRENADE_LAUNCHER: + case WP_GRENADE_PINEAPPLE: + if ( cs->enemyNum < 0 ) { + return qfalse; + } + delay = 5000; + if ( dist > 0 && dist < 200 ) { + return qfalse; + } + if ( cs->weaponFireTimes[weaponNum] < level.time - delay ) { + // make sure it's safe + CalcMuzzlePoints( ent, weaponNum ); + grenade = weapon_grenadelauncher_fire( ent, weaponNum ); + hitclient = AICast_SafeMissileFire( grenade, grenade->nextthink - level.time, cs->enemyNum, g_entities[cs->enemyNum].s.pos.trBase, cs->entityNum, NULL ); + G_FreeEntity( grenade ); + if ( hitclient > -1 ) { + return qtrue; + } else { + return qfalse; // it's not safe + } + } + break; + case WP_TESLA: + switch ( cs->aiCharacter ) { + case AICHAR_STIMSOLDIER3: + if ( dist < 0 || dist >= TESLA_RANGE ) { + return qfalse; + } + } + break; + case WP_MONSTER_ATTACK1: + switch ( g_entities[cs->entityNum].aiCharacter ) { + case AICHAR_ZOMBIE: // zombie flaming attack + delay = 4000; + if ( dist < 0 ) { // || dist < 128) { + return qfalse; + } + if ( dist > 1200 ) { + return qfalse; + } + if ( cs->enemyNum < 0 ) { + return qfalse; + } + //if (cs->vislist[cs->enemyNum].notvisible_timestamp > level.time - 500) { + // return qfalse; + //} + break; + + // melee attacks are always available + case AICHAR_LOPER: + case AICHAR_WARZOMBIE: + return qtrue; // always usable + + case AICHAR_STIMSOLDIER2: + delay = 7000; + if ( dist < 0 || dist < 300 ) { + return qfalse; + } + break; + case AICHAR_STIMSOLDIER3: // stim flying tesla attack + delay = 7000; + if ( dist < 0 || dist < 300 ) { + return qfalse; + } + break; + case AICHAR_BLACKGUARD: + delay = 5000; + if ( dist < 0 || dist > BLACKGUARD_MELEE_RANGE ) { + return qfalse; + } + break; + default: + delay = -1; + break; + } + break; + case WP_MONSTER_ATTACK2: + switch ( g_entities[cs->entityNum].aiCharacter ) { + case AICHAR_HEINRICH: + delay = 6000; + break; + case AICHAR_WARZOMBIE: + delay = 9999999; + break; + case AICHAR_ZOMBIE: + delay = 6000; + // zombie "flying spirit" attack + if ( dist < 64 ) { + return qfalse; + } + if ( dist > 1200 ) { + return qfalse; + } + if ( cs->enemyNum < 0 ) { + return qfalse; + } + if ( cs->vislist[cs->enemyNum].notvisible_timestamp > level.time - 1500 ) { + return qfalse; + } + break; + case AICHAR_HELGA: + delay = 8000; + // zombie "flying spirit" attack + if ( dist < 0 || dist < 80 ) { + return qfalse; + } + if ( dist > 2000 ) { + return qfalse; + } + if ( cs->enemyNum < 0 ) { + return qfalse; + } + if ( cs->vislist[cs->enemyNum].notvisible_timestamp > level.time - 1500 ) { + return qfalse; + } + break; + case AICHAR_LOPER: // loper leap attack + if ( cs->bs->areanum && VectorLength( cs->bs->velocity ) > 1 ) { // if we are in a valid area, and are persuing, then leave a delay + // if there isn't a direct trace to our enemy, then fail + if ( cs->enemyNum >= 0 ) { + trace_t trace; + vec3_t mins; + VectorCopy( cs->bs->cur_ps.mins, mins ); + mins[0] = 0; + trap_Trace( &trace, g_entities[cs->entityNum].client->ps.origin, mins, cs->bs->cur_ps.maxs, g_entities[cs->enemyNum].client->ps.origin, cs->entityNum, g_entities[cs->entityNum].clipmask ); + if ( trace.entityNum != cs->enemyNum && trace.fraction < 1.0 ) { + return qfalse; + } + } + delay = 4500; + if ( dist < 200 ) { + return qfalse; + } + } else { + delay = 0; // jump to get out of trouble + } + break; + default: + delay = -1; + break; + } + break; + case WP_MONSTER_ATTACK3: + switch ( g_entities[cs->entityNum].aiCharacter ) { + case AICHAR_HEINRICH: // spirits + delay = 7000; + break; + case AICHAR_LOPER: // loper ground zap + delay = 3500; + if ( dist < 0 || dist > LOPER_GROUND_RANGE ) { + return qfalse; + } + break; + case AICHAR_WARZOMBIE: // warzombie defense + delay = 7000; + if ( dist < 120 || dist > 2000 ) { + return qfalse; + } + break; + case AICHAR_ZOMBIE: + return qtrue; // always usable + default: + delay = -1; + break; + } + break; + default: + delay = -1; + } + // + return ( !cs->weaponFireTimes[weaponNum] || ( cs->weaponFireTimes[weaponNum] < level.time - delay ) ); +} + +/* +============== +AICast_ChooseWeapon +============== +*/ +void AICast_ChooseWeapon( cast_state_t *cs, qboolean battleFunc ) { + int i; + int *ammo; + float wantScale, bestWantScale, enemyDist = 0; + qboolean inRange = qfalse, thisInRange, gotOne; + + BotAI_GetClientState( cs->entityNum, &( cs->bs->cur_ps ) ); + ammo = cs->bs->cur_ps.ammo; + bestWantScale = 0.0; + + if ( cs->enemyNum >= 0 ) { + enemyDist = VectorDistance( g_entities[cs->enemyNum].s.pos.trBase, cs->bs->origin ); + // subtract distance to edge of bounding box + enemyDist -= g_entities[cs->enemyNum].r.maxs[0]; + } + + if ( cs->bs->cur_ps.weaponstate == WEAPON_RAISING || + cs->bs->cur_ps.weaponstate == WEAPON_RAISING_TORELOAD || //----(SA) added + cs->bs->cur_ps.weaponstate == WEAPON_DROPPING || + cs->bs->cur_ps.weaponstate == WEAPON_DROPPING_TORELOAD ) { //----(SA) added + return; + } + +// disabled this, makes grenade guy keep trying to throw a grenade he doesn't have +// if (cs->bs->cur_ps.weaponDelay || cs->bs->cur_ps.weaponTime) +// return; + + if ( cs->weaponNum && ( cs->castScriptStatus.scriptFlags & SFL_NOCHANGEWEAPON ) ) { + if ( AICast_GotEnoughAmmoForWeapon( cs, cs->weaponNum ) && AICast_WeaponUsable( cs, cs->weaponNum ) ) { + return; + } else { + cs->castScriptStatus.scriptFlags &= ~SFL_NOCHANGEWEAPON; + } + } else { + if ( cs->weaponNum == WP_GRENADE_LAUNCHER || cs->weaponNum == WP_GRENADE_PINEAPPLE ) { + cs->weaponNum = WP_NONE; // dont use grenades at will + } + } + + gotOne = qfalse; + + // choose the best weapon to fight with + for ( i = 0; i < WP_NUM_WEAPONS; i++ ) { + if ( i == WP_GRENADE_LAUNCHER || i == WP_GRENADE_PINEAPPLE ) { + continue; // never choose grenades at will, only when going into grenade flush mode + } + + if ( !battleFunc && ( i == WP_MONSTER_ATTACK1 ) && cs->aifuncAttack1 ) { + continue; // only choose this weapon from within AIFunc_BattleStart() + } + if ( !battleFunc && ( i == WP_MONSTER_ATTACK2 ) && cs->aifuncAttack2 ) { + continue; // only choose this weapon from within AIFunc_BattleStart() + } + if ( !battleFunc && ( i == WP_MONSTER_ATTACK3 ) && cs->aifuncAttack3 ) { + continue; // only choose this weapon from within AIFunc_BattleStart() + } + + if ( COM_BitCheck( cs->bs->cur_ps.weapons, i ) ) { + gotOne = qtrue; + // check that our ammo is enough + if ( !AICast_GotEnoughAmmoForWeapon( cs, i ) || + !AICast_WeaponUsable( cs, i ) ) { + continue; + } + // get the wantScale for this weapon given the current circumstances (0.0 - 1.0) + wantScale = AICast_WeaponWantScale( cs, i ); + thisInRange = qfalse; + // in range? + if ( enemyDist && AICast_WeaponRange( cs, i ) > enemyDist ) { + thisInRange = qtrue; + } + // + if ( ( !inRange && thisInRange ) || ( ( !inRange || thisInRange ) && ( wantScale >= bestWantScale ) ) ) { + cs->weaponNum = i; + bestWantScale = wantScale; + if ( thisInRange ) { // we have found a weapon inside attackable range, don't override with one outside range + inRange = qtrue; + } + } + } + } + + if ( !gotOne && ( cs->weaponNum < WP_MONSTER_ATTACK1 || cs->weaponNum > WP_MONSTER_ATTACK3 ) ) { + if ( g_cheats.integer && ( !cs->bs->cur_ps.weapons[0] && !cs->bs->cur_ps.weapons[1] ) ) { +// (SA) the print statement is a bit much. lots of actors have no ammo... +// G_Printf( "AI: %s has no ammo\n", g_entities[cs->entityNum].aiName); + } + // select no weapon + cs->weaponNum = WP_NONE; + // if we have no weapons at all, we dont need to switch + if ( !cs->bs->cur_ps.weapons[0] && !cs->bs->cur_ps.weapons[1] ) { + g_entities[cs->entityNum].client->ps.weapon = WP_NONE; + } + } +} + +/* +================== +AICast_Aggression + + Check all possible reasons why we shouldn't attack, returning a value from 1.0 (fully willing) + to 0.0 (please don't hurt me). +================== +*/ +float AICast_Aggression( cast_state_t *cs ) { + bot_state_t *bs; + float scale, dist; + int painTime; + int *ammo; + + bs = cs->bs; + + // if we are out of ammo, we should never chase + ammo = cs->bs->cur_ps.ammo; + if ( g_entities[cs->entityNum].aiTeam != AITEAM_MONSTER ) { + if ( !AICast_GotEnoughAmmoForWeapon( cs, cs->weaponNum ) ) { + return 0; + } + } + + // start fully willing to attack + scale = 1.0; + + //if the enemy is located way higher + //if (cs->enemyHeight > 200) + // scale -= (cs->enemyHeight)/800.0; + + //if very low on health + if ( bs->cur_ps.stats[STAT_HEALTH] < 50 ) { + scale -= ( 1.0 - cs->attributes[AGGRESSION] ) * ( 1.0 - ( (float)bs->cur_ps.stats[STAT_HEALTH] / 50.0 ) ); + } + + // if they've recently hit us, factor that in, so we get scared off by being + // damaged, but later return once we've regained our confidence + painTime = 15000 - (int)( 10000.0 * cs->attributes[AGGRESSION] * cs->attributes[AGGRESSION] ); + if ( cs->lastPain + painTime > level.time ) { + scale -= 3 * ( 1.0 - cs->attributes[AGGRESSION] ) * ( (float)( cs->lastPain + painTime - level.time ) / (float)painTime ); + } + + // if we just rolled, stay out of view if we jumped behind cover + painTime = 10000 - (int)( 10000.0 * cs->attributes[AGGRESSION] * cs->attributes[AGGRESSION] ); + if ( cs->battleRollTime + painTime > level.time ) { + scale -= 2 * ( 1.0 - cs->attributes[AGGRESSION] ) * ( (float)( cs->battleRollTime + painTime - level.time ) / (float)painTime ); + } + + // gain in confidence the further we are away + if ( cs->enemyNum >= 0 ) { + dist = Distance( cs->bs->origin, g_entities[cs->enemyNum].s.pos.trBase ); + //if (dist > 512) { + scale += ( dist - 800.0 ) / ( 8000.0 ); + //} + } + + // if our weapon is reloading, we should hide + if ( cs->bs->cur_ps.weaponTime > 0 ) { + scale -= ( (float)cs->bs->cur_ps.weaponTime / 1000.0 ); + } + + scale *= cs->attributes[AGGRESSION]; + + // this should increase the chances of an ambush attack + if ( cs->entityNum >= 0 && ( ( level.time + 2000 * g_entities[cs->entityNum].aiTeam ) % ( 4000 + 500 * g_entities[cs->entityNum].aiTeam ) ) > 4000 ) { + if ( cs->vislist[cs->entityNum].visible_timestamp > level.time - 10000 ) { + scale += 0.3 * (float)( level.time - cs->vislist[cs->entityNum].visible_timestamp ) / 10000.0; + } + } + + if ( scale < 0 ) { + scale = 0; + } + + return scale; +} + +/* +================== +AICast_WantsToChase +================== +*/ +int AICast_WantsToChase( cast_state_t *cs ) { + int *ammo; + ammo = cs->bs->cur_ps.ammo; + if ( g_entities[cs->entityNum].aiTeam != AITEAM_MONSTER ) { + if ( !AICast_GotEnoughAmmoForWeapon( cs, cs->weaponNum ) ) { + return qfalse; + } + } + if ( cs->attributes[AGGRESSION] == 1.0 ) { + return qtrue; + } + if ( AICast_Aggression( cs ) > 0.6 ) { + return qtrue; + } + return qfalse; +} + +/* +================== +AICast_WantsToTakeCover +================== +*/ +int AICast_WantsToTakeCover( cast_state_t *cs, qboolean attacking ) { + float aggrScale; + int *ammo; + + ammo = cs->bs->cur_ps.ammo; + if ( g_entities[cs->entityNum].aiTeam != AITEAM_MONSTER ) { + if ( !cs->weaponNum ) { + return qtrue; + } + if ( !AICast_GotEnoughAmmoForWeapon( cs, cs->weaponNum ) ) { + return qtrue; + } + } + if ( cs->attributes[AGGRESSION] == 1.0 ) { + return qfalse; + } + // if currently attacking, we should stick around if not getting hurt + if ( attacking ) { + aggrScale = 1.2; + } else { aggrScale = 0.8 /*+ 0.4 * random()*/;} + // + // if currently following someone, we should be more aggressive + if ( cs->leaderNum >= 0 ) { + aggrScale *= 3; + } + // + // Dodge enemy aim? + if ( cs->attributes[AGGRESSION] < 1.0 && attacking && ( cs->enemyNum >= 0 ) && ( g_entities[cs->enemyNum].client->ps.weapon ) && ( cs->attributes[TACTICAL] > 0.5 ) && ( cs->aiFlags & AIFL_ROLL_ANIM ) && ( VectorLength( cs->bs->cur_ps.velocity ) < 1 ) ) { + vec3_t aim, enemyVec; + // are they aiming at us? + AngleVectors( g_entities[cs->enemyNum].client->ps.viewangles, aim, NULL, NULL ); + VectorSubtract( cs->bs->origin, g_entities[cs->enemyNum].r.currentOrigin, enemyVec ); + VectorNormalize( enemyVec ); + // if they are looking at us, we should avoid them + if ( DotProduct( aim, enemyVec ) > 0.97 ) { + //G_Printf("%s: I'm in danger, I should probably avoid\n", g_entities[cs->entityNum].aiName); + aggrScale *= 0.6; + } + } + // + // FIXME: instead of a constant, call a "attack danger" + // function, so we only attack if our aggression is greater than + // the danger + if ( AICast_Aggression( cs ) * aggrScale < 0.4 ) { + //G_Printf("%s: run for your life!\n", g_entities[cs->entityNum].aiName); + return qtrue; + } + // + return qfalse; +} + +/* +================== +AICast_CombatMove +================== +*/ +bot_moveresult_t AICast_CombatMove( cast_state_t *cs, int tfl ) { + bot_state_t *bs; + float attack_skill, croucher, dist; + vec3_t forward, backward; //, up = {0, 0, 1}; + bot_moveresult_t moveresult; + bot_goal_t goal; + + bs = cs->bs; + + //get the enemy entity info + memset( &moveresult, 0, sizeof( bot_moveresult_t ) ); + // + attack_skill = cs->attributes[ATTACK_SKILL]; + croucher = ( cs->attributes[ATTACK_CROUCH] > 0.1 ); + + //initialize the movement state + BotSetupForMovement( bs ); + //direction towards the enemy + VectorSubtract( cs->vislist[cs->enemyNum].visible_pos, bs->origin, forward ); + //the distance towards the enemy + dist = VectorNormalize( forward ); + VectorNegate( forward, backward ); + // + // do we have somewhere we are trying to get to? + if ( cs->combatGoalTime > level.time ) { + if ( VectorLength( cs->combatGoalOrigin ) > 1 ) { + //create the chase goal + goal.areanum = BotPointAreaNum( cs->combatGoalOrigin ); + VectorCopy( cs->combatGoalOrigin, goal.origin ); + + // if we are really close, stop going for it + // FIXME: a better way of doing this, so we don't stop short of the goal? + if ( ( dist = Distance( goal.origin, cs->bs->origin ) ) < 32 ) { + if ( cs->combatGoalTime > level.time + 3000 ) { + cs->combatGoalTime = level.time + 2000 + rand() % 1000; + cs->combatSpotDelayTime = level.time + 4000 + rand() % 3000; + } + VectorClear( cs->combatGoalOrigin ); + } else { + aicast_predictmove_t move; + // + AICast_MoveToPos( cs, cs->combatGoalOrigin, -1 ); + cs->speedScale = AICast_SpeedScaleForDistance( cs, dist, 32 ); + // + // if we are going to move out of view very soon, stop moving + AICast_PredictMovement( cs, 1, 0.8, &move, &cs->lastucmd, -1 ); + // + if ( move.numtouch || !AICast_CheckAttackAtPos( cs->entityNum, cs->enemyNum, move.endpos, qfalse, qfalse ) ) { + // abort the manouver, reached a good spot + cs->combatGoalTime = 0; + cs->combatSpotAttackCount = cs->startAttackCount; + } + } + + // if we are there, and the enemy can see us, but we cant hit them, abort immediately + } else if ( !AICast_CheckAttack( cs, cs->enemyNum, qfalse ) && + AICast_VisibleFromPos( cs->vislist[cs->enemyNum].visible_pos, cs->enemyNum, cs->bs->origin, cs->entityNum, qfalse ) ) { + cs->combatGoalTime = 0; + cs->combatSpotAttackCount = cs->startAttackCount; + } + } else { // look for a good position to move to? + if ( ( ( cs->attributes[CAMPER] < random() ) + && ( cs->takeCoverTime < level.time ) + && ( cs->combatSpotAttackCount < cs->startAttackCount ) + && ( cs->combatSpotDelayTime < level.time ) ) ) { + + if ( ( cs->attributes[TACTICAL] > 0.3 + random() * 0.5 ) + && trap_AAS_RT_GetHidePos( cs->bs->origin, cs->bs->entitynum, cs->bs->areanum, cs->vislist[cs->enemyNum].visible_pos, cs->enemyNum, BotPointAreaNum( cs->vislist[cs->enemyNum].visible_pos ), cs->combatGoalOrigin ) ) { + cs->combatGoalTime = level.time + 10000; // give us plenty of time to get there + //cs->combatSpotAttackCount = cs->startAttackCount + 3; // don't keep moving around to different positions on our own + cs->combatSpotDelayTime = level.time + 3000 + rand() % 3000; + } else { + // don't look again until we've moved + //cs->combatSpotAttackCount = cs->startAttackCount; + cs->combatSpotDelayTime = level.time + 3000 + rand() % 3000; + } + } + } + // + return moveresult; +} + +/* +================== +AICast_WeaponSway + + Some weapons should be "sprayed" around a bit while firing +================== +*/ +void AICast_WeaponSway( cast_state_t *cs, vec3_t ofs ) { + VectorClear( ofs ); + switch ( cs->weaponNum ) { + case WP_MONSTER_ATTACK1: + if ( cs->aiCharacter != AICHAR_ZOMBIE ) { + break; // only allow flaming zombie beyond here + } + case WP_FLAMETHROWER: + ofs[PITCH] = ( 3.0 + 4.0 * sin( ( (float)level.time / 320.0 ) ) ) * sin( ( (float)level.time / 500.0 ) ); + ofs[YAW] = ( 6.0 + 8.0 * sin( ( (float)level.time / 250.0 ) ) ) * sin( ( (float)level.time / 400.0 ) ); + ofs[ROLL] = 0; + break; + case WP_VENOM: + ofs[PITCH] = 2 * (float)cos( ( level.time / 200 ) ); + ofs[YAW] = 10 * (float)sin( ( level.time / 150 ) ) * (float)sin( ( level.time / 100 ) ); + ofs[ROLL] = 0; + break; + } +} + +/* +================== +AICast_AimAtEnemy +================== +*/ +qboolean AICast_AimAtEnemy( cast_state_t *cs ) { + bot_state_t *bs; + float aim_skill, aim_accuracy; + vec3_t dir, bestorigin, start, enemyOrg; +// vec3_t mins = {-4,-4,-4}, maxs = {4, 4, 4}; + float dist; + cast_visibility_t *vis; + + // + if ( cs->castScriptStatus.scriptNoAttackTime >= ( level.time + 500 ) ) { + return qfalse; + } + // + if ( cs->noAttackTime >= level.time ) { + return qfalse; + } + // + bs = cs->bs; + // + //if the bot has no enemy + if ( cs->enemyNum < 0 ) { + return qfalse; + } + // + aim_skill = cs->attributes[AIM_SKILL]; + aim_accuracy = AICast_GetAccuracy( cs->entityNum ); + if ( aim_accuracy <= 0 ) { + aim_accuracy = 0.0001; + } + + // StimSoldier is very good at firing Rocket Launcher + if ( cs->aiCharacter == AICHAR_STIMSOLDIER2 && cs->weaponNum == WP_PANZERFAUST ) { + aim_skill = 1; + aim_accuracy = 1; + } + + //get the weapon information + + //get the enemy entity information + vis = &cs->vislist[cs->enemyNum]; + if ( vis->visible_timestamp < vis->lastcheck_timestamp ) { + // use our last visible position of them + if ( vis->real_visible_timestamp == vis->lastcheck_timestamp ) { + VectorCopy( vis->real_visible_pos, bestorigin ); + } else { + VectorCopy( vis->visible_pos, bestorigin ); + } + } else { + // we can see them, if this weapon isn't a direct-hit weapon (bullets), + // then predict where they are going to be + if ( cs->weaponNum == WP_GRENADE_LAUNCHER || cs->weaponNum == WP_GRENADE_PINEAPPLE ) { + aicast_predictmove_t move; + AICast_PredictMovement( AICast_GetCastState( cs->enemyNum ), 1, 1.0, &move, &g_entities[cs->enemyNum].client->pers.cmd, -1 ); + VectorCopy( move.endpos, bestorigin ); + } else { // they are visible, use actual position + VectorCopy( g_entities[cs->enemyNum].client->ps.origin, bestorigin ); + } + } + + bestorigin[2] += g_entities[cs->enemyNum].client->ps.viewheight; + //get the start point shooting from + //NOTE: the x and y projectile start offsets are ignored + VectorCopy( bs->origin, start ); + start[2] += bs->cur_ps.viewheight; + // + VectorCopy( bestorigin, enemyOrg ); + // + // grenade hack: aim grenades at their feet if they are close + if ( cs->weaponNum == WP_GRENADE_LAUNCHER || cs->weaponNum == WP_GRENADE_PINEAPPLE ) { + if ( Distance( start, bestorigin ) < 180 ) { + bestorigin[2] = enemyOrg[2] + g_entities[cs->enemyNum].r.mins[2] + crandom() * 20; + } else if ( Distance( start, bestorigin ) > 400 ) { // aim up a bit for distance + bestorigin[2] += 12 + Distance( start, bestorigin ) / 50 + crandom() * 20; + } + } + dist = Distance( bs->eye, bestorigin ); + // rocket launcher should aim ahead + if ( cs->weaponNum == WP_PANZERFAUST ) { + VectorMA( bestorigin, aim_skill * aim_skill * ( dist / 900 ), g_entities[cs->enemyNum].client->ps.velocity, bestorigin ); + // if they are close, aim down at their feet + if ( dist < 512 ) { + bestorigin[2] -= ( VectorLength( g_entities[cs->enemyNum].client->ps.velocity ) / 500.0 ) * ( 1.0 - dist / 2048 ) * ( bestorigin[2] - ( g_entities[cs->enemyNum].client->ps.origin[2] + g_entities[cs->enemyNum].client->ps.mins[2] ) ); + } + } + // if the enemy is moving, they are harder to hit + if ( dist > 256 ) { + VectorMA( bestorigin, ( 0.3 + 0.7 * ( 1 - aim_accuracy ) ) * 0.4 * sin( (float)level.time / ( 500.0 + ( 100.0 * ( ( cs->entityNum + 3 ) % 4 ) ) ) ), g_entities[cs->enemyNum].client->ps.velocity, bestorigin ); + } + // if we are good at aiming, we should aim ahead of where they are now + // since by the time we have rotated to that direction, some time will have passed + if ( aim_skill > 0.2 ) { + VectorMA( bestorigin, aim_skill * 0.2, g_entities[cs->enemyNum].client->ps.velocity, bestorigin ); + } + //get aim direction + VectorSubtract( bestorigin, bs->eye, dir ); + //set the ideal view angles + vectoangles( dir, cs->ideal_viewangles ); + + return qtrue; // do real aim checking after we've moved the angles +} + +/* +================== +AICast_CanMoveWhileFiringWeapon +================== +*/ +qboolean AICast_CanMoveWhileFiringWeapon( int weaponnum ) { + switch ( weaponnum ) { + case WP_MAUSER: + case WP_GARAND: + case WP_SNIPERRIFLE: //----(SA) added + case WP_SNOOPERSCOPE: //----(SA) added + //case WP_FG42SCOPE: //----(SA) added + case WP_PANZERFAUST: + return qfalse; + default: + return qtrue; + } +} + +/* +================ +AICast_RandomTriggerRelease +================ +*/ +qboolean AICast_RandomTriggerRelease( cast_state_t *cs ) { + // some characters override all weapon settings for trigger release + switch ( cs->aiCharacter ) { + case AICHAR_BLACKGUARD: // this is here since his "ready" frame is different to his firing frame, so it looks wierd to keep swapping between them + case AICHAR_STIMSOLDIER1: + case AICHAR_STIMSOLDIER2: + case AICHAR_STIMSOLDIER3: + return qfalse; + } + + switch ( cs->weaponNum ) { + case WP_MP40: + case WP_VENOM: + case WP_FG42SCOPE: + case WP_FG42: + //case WP_FLAMETHROWER: + return qtrue; + default: + return qfalse; + } +} + +/* +================== +AICast_ProcessAttack + + NOTE: this should always be called after the movement has been processed +================== +*/ +void AICast_ProcessAttack( cast_state_t *cs ) { + bot_state_t *bs; + + // if our enemy is dead, stop attacking them + if ( cs->enemyNum >= 0 && g_entities[cs->enemyNum].health <= 0 ) { + return; + } + // + if ( cs->castScriptStatus.scriptNoAttackTime >= level.time ) { + return; + } + // + if ( cs->noAttackTime >= level.time ) { + return; + } + // select a weapon + AICast_ChooseWeapon( cs, qfalse ); + // + if ( cs->weaponNum == WP_NONE ) { + return; + } + // never fire grenades from within here (needs special AIFunc_GrenadeFlush() code) + if ( cs->weaponNum == WP_GRENADE_LAUNCHER || cs->weaponNum == WP_GRENADE_PINEAPPLE ) { + return; + } + // + bs = cs->bs; + // check for not firing while moving flag, if present, abort attack if any movement has been issued + if ( !AICast_CanMoveWhileFiringWeapon( cs->weaponNum ) ) { + // if we are moving, don't fire + bot_input_t bi; + if ( cs->bs->cur_ps.weaponTime > 200 ) { + // if we recently fired, don't let us move for a bit + cs->speedScale = 0; + AICast_AimAtEnemy( cs ); // keep looking at them regardless + } + // if we're trying to move somewhere, don't let us shoot, until we've arrived + trap_EA_GetInput( bs->client, (float) level.time / 1000, &bi ); + if ( ( cs->castScriptStatus.scriptNoMoveTime < level.time ) && + ( ( bi.actionflags & ACTION_MOVEFORWARD ) || + ( bi.actionflags & ACTION_MOVEBACK ) || + ( bi.actionflags & ACTION_MOVELEFT ) || + ( bi.actionflags & ACTION_MOVERIGHT ) || + ( bi.speed ) ) ) { + return; + } + } + // + //if not a "walk forward" AI, then aim at the enemy regardless of whether we can attack them or not + if ( !( cs->aiFlags & AIFL_WALKFORWARD ) ) { + if ( !AICast_AimAtEnemy( cs ) ) { + return; + } + } + // + // if we are stuck in this position, we should duck if we can't hit them + if ( !AICast_CheckAttack( cs, cs->enemyNum, qfalse ) ) { + // we should duck if the enemy is shooting at us, and we can't hit them + if ( cs->attributes[ATTACK_CROUCH] && ( cs->castScriptStatus.scriptNoMoveTime >= level.time ) ) { + if ( !AICast_CheckAttackAtPos( cs->entityNum, cs->enemyNum, cs->bs->origin, qfalse, qfalse ) ) { + cs->attackcrouch_time = level.time + 2000; + } else { + cs->attackcrouch_time = 0; // we can attack them if we stand, so go for it + } + } + return; + } + // + //if we are a "walk forward" AI, then aim at the enemy only if we can attack them + if ( cs->aiFlags & AIFL_WALKFORWARD ) { + if ( !AICast_AimAtEnemy( cs ) ) { + return; + } + } + // + // release the trigger every now and then + if ( AICast_RandomTriggerRelease( cs ) && cs->triggerReleaseTime < ( level.time - 500 ) ) { + if ( rand() % 5 == 0 ) { + cs->triggerReleaseTime = level.time + 100 + rand() % 100; + return; + } + } + // + if ( cs->triggerReleaseTime > level.time ) { + return; + } + // + // FIXME: handle fire-on-release weapons? + trap_EA_Attack( bs->client ); + // + cs->bFlags |= BFL_ATTACKED; + +} + +/* +============== +AICast_GetTakeCoverPos +============== +*/ +qboolean AICast_GetTakeCoverPos( cast_state_t *cs, int enemyNum, vec3_t enemyPos, vec3_t returnPos ) { + cs->crouchHideFlag = qfalse; + // + if ( cs->castScriptStatus.scriptNoMoveTime > level.time ) { + return qfalse; + } + // + cs->lastGetHidePos = level.time; + // + // can we just crouch? + if ( ( cs->attackcrouch_time < level.time ) + && ( enemyNum < aicast_maxclients ) + && AICast_CheckAttackAtPos( cs->entityNum, enemyNum, cs->bs->origin, qfalse, qfalse ) + && !AICast_CheckAttackAtPos( cs->entityNum, enemyNum, cs->bs->origin, qtrue, qfalse ) ) { + + // do a more thorough check to see if the enemy can see us if we crouch + vec3_t omaxs; + gentity_t *ent; + qboolean visible; + + ent = &g_entities[cs->entityNum]; + VectorCopy( ent->r.maxs, omaxs ); + ent->r.maxs[2] = ent->client->ps.crouchMaxZ + 4; // + 4 to be safe + + visible = AICast_VisibleFromPos( g_entities[enemyNum].r.currentOrigin, enemyNum, cs->bs->origin, cs->entityNum, qfalse ); + + ent->r.maxs[2] = omaxs[2]; + + if ( !visible ) { + VectorCopy( enemyPos, cs->takeCoverEnemyPos ); + VectorCopy( cs->bs->origin, returnPos ); + cs->crouchHideFlag = qtrue; + return qtrue; + } + } + // if we are in a void, then we can't hide + // look for a hiding spot + if ( cs->bs->areanum && trap_AAS_RT_GetHidePos( cs->bs->origin, cs->bs->entitynum, cs->bs->areanum, enemyPos, enemyNum, BotPointAreaNum( enemyPos ), returnPos ) ) { + return qtrue; + } + // if we are hiding from a dangerous entity, try and avoid it + if ( cs->dangerEntity == enemyNum && cs->dangerEntityValidTime > level.time ) { + if ( cs->dangerLastGetAvoid > level.time - 750 ) { + return qtrue; + } else if ( AICast_GetAvoid( cs, NULL, cs->takeCoverPos, qtrue, cs->dangerEntity ) ) { + cs->dangerLastGetAvoid = level.time; + return qtrue; + } + } + // + return qfalse; +} + +/* +============== +AICast_AIDamageOK +============== +*/ +qboolean AICast_AIDamageOK( cast_state_t *cs, cast_state_t *ocs ) { + if ( cs->castScriptStatus.scriptFlags & SFL_NOAIDAMAGE ) { + return qfalse; + } else { + + if ( cs->aiCharacter == AICHAR_LOPER && ocs->aiCharacter == AICHAR_LOPER ) { + return qfalse; + } + + return qtrue; + } +} + +/* +=============== +AICast_RecordWeaponFire + + used for scripting, so we know when the weapon has been fired +=============== +*/ +void AICast_RecordWeaponFire( gentity_t *ent ) { + cast_state_t *cs; + float range; + + cs = AICast_GetCastState( ent->s.number ); + cs->lastWeaponFired = level.time; + cs->lastWeaponFiredWeaponNum = ent->client->ps.weapon; + VectorCopy( ent->r.currentOrigin, cs->lastWeaponFiredPos ); + + cs->weaponFireTimes[cs->lastWeaponFiredWeaponNum] = level.time; + + // do sighting + range = AICast_GetWeaponSoundRange( cs->lastWeaponFiredWeaponNum ); + + AICast_AudibleEvent( cs->entityNum, cs->lastWeaponFiredPos, range ); + + if ( cs->bs ) { // real player's don't need to play AI sounds + AIChar_AttackSound( cs ); + } +} + +/* +=============== +AICast_GetWeaponSoundRange +=============== +*/ +float AICast_GetWeaponSoundRange( int weapon ) { + // NOTE: made this a case, that way changing the ordering of weapons won't cause problems, as it would + // with an array lookup + + switch ( weapon ) { + case WP_NONE: + return 0; + case WP_KNIFE: + case WP_GAUNTLET: + case WP_STEN: + case WP_SILENCER: + return 64; + case WP_GRENADE_LAUNCHER: + case WP_GRENADE_PINEAPPLE: + return 1500; + case WP_GARAND: + case WP_SNOOPERSCOPE: + return 128; + case WP_LUGER: + case WP_COLT: + case WP_AKIMBO: + return 700; + + case WP_MONSTER_ATTACK1: + case WP_MONSTER_ATTACK2: + case WP_MONSTER_ATTACK3: + // TODO: case for each monster + return 1000; + + case WP_MP40: + case WP_THOMPSON: + return 1000; + + case WP_FG42: + case WP_FG42SCOPE: + return 1500; + + case WP_SNIPERRIFLE: + case WP_MAUSER: + return 2000; + + case WP_DYNAMITE: + return 3000; + + case WP_PANZERFAUST: + case WP_VENOM: + case WP_FLAMETHROWER: + case WP_TESLA: + return 1000; + } + + G_Error( "AICast_GetWeaponSoundRange: unknown weapon index: %i\n", weapon ); + return 0; // shutup the compiler +} + +/* +=============== +AICast_StopAndAttack + + returns qtrue if they should go back to a battle state to attack, + qfalse if they should keep chasing while they attack (like the Zombie) +=============== +*/ +qboolean AICast_StopAndAttack( cast_state_t *cs ) { + float dist = -1; + cast_state_t *ecs; + + if ( cs->enemyNum >= 0 ) { + dist = Distance( cs->bs->origin, g_entities[cs->enemyNum].r.currentOrigin ); + } + + switch ( cs->weaponNum ) { + + // if they are using Venom, and are too far away to be effective, then keep chasing + case WP_VENOM: + if ( dist > 300 ) { + return qfalse; + } + // if we haven't injured them in a while, advance + if ( cs->enemyNum >= 0 ) { + ecs = AICast_GetCastState( cs->enemyNum ); + if ( ecs->lastPain < level.time - 3000 ) { + return qfalse; + } + } + break; + // if they are using tesla (SUPERSOLDIER / BOSS2) try and get close + case WP_TESLA: + if ( dist > 128 /*&& (level.time%10000 < 8000)*/ ) { + return qfalse; + } + // if we haven't injured them in a while, advance + if ( cs->enemyNum >= 0 ) { + ecs = AICast_GetCastState( cs->enemyNum ); + if ( ecs->lastPain < level.time - 3000 ) { + return qfalse; + } + } + break; + case WP_PANZERFAUST: + // if we haven't injured them in a while, advance + if ( ( cs->aiCharacter == AICHAR_PROTOSOLDIER || cs->aiCharacter == AICHAR_SUPERSOLDIER ) && cs->enemyNum >= 0 ) { + if ( dist > 300 ) { + return qfalse; + } + ecs = AICast_GetCastState( cs->enemyNum ); + if ( ecs->lastPain < level.time - 3000 ) { + return qfalse; + } + } + break; + case WP_FLAMETHROWER: + // if we haven't injured them in a while, advance + if ( cs->aiCharacter == AICHAR_VENOM && cs->enemyNum >= 0 ) { + ecs = AICast_GetCastState( cs->enemyNum ); + if ( ecs->lastPain < level.time - 3000 ) { + return qfalse; + } + } + break; + + } + + return qtrue; +} + +/* +=============== +AICast_GetAccuracy +=============== +*/ +float AICast_GetAccuracy( int entnum ) { + #define AICAST_VARIABLE_ACC_ENABLED 1 + #define AICAST_ACC_VISTIME ( 500 + ( 3500 * ( 1.0 - aicast_skillscale ) ) ) + #define AICAST_ACC_SCALE 0.4 + cast_state_t *cs; + float acc; + + cs = AICast_GetCastState( entnum ); + // the more they stay in our sights, the more accurate we get + acc = cs->attributes[AIM_ACCURACY]; + + if ( AICAST_VARIABLE_ACC_ENABLED ) { + if ( cs->enemyNum >= 0 ) { + if ( cs->vislist[cs->enemyNum].real_notvisible_timestamp < level.time - AICAST_ACC_VISTIME ) { + acc += 0.5 * AICAST_ACC_SCALE; + } else { + acc += AICAST_ACC_SCALE * ( (float)( -0.5 * AICAST_ACC_VISTIME + level.time - cs->vislist[cs->enemyNum].real_notvisible_timestamp ) / (float)( AICAST_ACC_VISTIME ) ); + } + + if ( acc > 1.0 ) { + acc = 1.0; + } else if ( acc < 0.0 ) { + acc = 0.0; + } + } + } + return ( acc ); +} + +/* +============== +AICast_WantToRetreat +============== +*/ +qboolean AICast_WantToRetreat( cast_state_t *cs ) { + int *ammo; + + ammo = cs->bs->cur_ps.ammo; + if ( g_entities[cs->entityNum].aiTeam != AITEAM_MONSTER ) { + if ( !cs->weaponNum ) { + return qtrue; + } + if ( !AICast_GotEnoughAmmoForWeapon( cs, cs->weaponNum ) ) { + return qtrue; + } + } + + if ( cs->attributes[AGGRESSION] >= 1.0 && cs->attributes[TACTICAL] <= 0.2 ) { + return qfalse; + } + + // RF, (Last Minute Hack) big dudes should never retreat + if ( cs->aasWorldIndex != 0 ) { + return qfalse; + } + + if ( cs->leaderNum < 0 ) { + if ( ( cs->attributes[TACTICAL] > 0.11 + random() * 0.5 ) && + ( ( cs->bs->cur_ps.weaponTime > 500 ) || + ( ( cs->takeCoverTime < level.time - 100 ) && + ( AICast_WantsToTakeCover( cs, qtrue ) ) ) ) ) { + return qtrue; + } + } + // + return qfalse; +} + +/* +============== +AICast_SafeMissileFire + + checks to see if firing the missile will be successful, neutral, or dangerous to us or a friendly +============== +*/ +int AICast_SafeMissileFire( gentity_t *ent, int duration, int enemyNum, vec3_t enemyPos, int selfNum, vec3_t endPos ) { + int rval; + vec3_t org; + gentity_t *trav; + + if ( !G_PredictMissile( ent, duration, org, qtrue ) ) { + // not point firing, since it won't explode + return 0; + } + + if ( endPos ) { + VectorCopy( org, endPos ); + } + + // at end of life, so do radius damage + rval = ( Distance( org, enemyPos ) < ent->splashRadius ) && AICast_VisibleFromPos( org, ent->s.number, enemyPos, enemyNum, qfalse ); + if ( rval ) { + // don't hurt ourselves + if ( Distance( org, g_entities[selfNum].r.currentOrigin ) < ent->splashRadius * 1.5 ) { + return -1; + } + // make sure we don't injure a friendly + for ( trav = g_entities; trav < g_entities + g_maxclients.integer; trav++ ) { + if ( !trav->inuse ) { + continue; + } + if ( !trav->client ) { + continue; + } + if ( trav->health <= 0 ) { + continue; + } + if ( trav->s.number == selfNum ) { + continue; + } + if ( AICast_SameTeam( AICast_GetCastState( selfNum ), trav->s.number ) ) { + if ( Distance( org, trav->r.currentOrigin ) < ent->splashRadius ) { + return -1; + } + } + } + } + // if it overshot the mark + if ( !rval && Distance( g_entities[ent->r.ownerNum].r.currentOrigin, org ) > Distance( g_entities[ent->r.ownerNum].r.currentOrigin, enemyPos ) ) { + return -2; // so the AI can try aiming down a bit next time + } + // + return rval; +} + +/* +============= +AICast_CheckDangerousEntity + + check to see if the given entity can harm an AI character, if so, informs them + appropriately +============= +*/ +void AICast_CheckDangerousEntity( gentity_t *ent, int dangerFlags, float dangerDist, float tacticalLevel, float aggressionLevel, qboolean hurtFriendly ) { + vec3_t org, fwd, vec; + cast_state_t *cs, *dcs; + gentity_t *trav; + int i, endTime; + float dist; + // + // + if ( dangerFlags & DANGER_MISSILE ) { + // predict where the entity will explode + if ( !( endTime = G_PredictMissile( ent, ent->nextthink - level.time, org, qtrue ) ) ) { + return; // missile won't explode, so no danger + } + } else { + // just avoid it for a bit, then forget it + endTime = level.time + 1000; + VectorCopy( ent->r.currentOrigin, org ); + } + if ( dangerFlags & DANGER_CLIENTAIM ) { + AngleVectors( ent->client->ps.viewangles, fwd, NULL, NULL ); + } + // + if ( ent->client ) { + dcs = AICast_GetCastState( ent->s.number ); + } else { + dcs = NULL; + } + // + // see if this will hurt anyone + for ( trav = g_entities, cs = AICast_GetCastState( 0 ), i = 0; i < level.numPlayingClients; cs++, trav++ ) { + if ( !trav->inuse || !trav->client ) { + continue; + } + i++; // found a connected client + if ( trav == ent ) { // don't be afraid of ourself + continue; + } + if ( trav->health <= 0 ) { + continue; + } + if ( !cs->bs ) { // not an AI, they should look out for themselves + continue; + } + if ( cs->castScriptStatus.scriptNoSightTime >= level.time ) { + continue; // absolutely no sight (or hear) information allowed + } + if ( !hurtFriendly && ent->s.number < MAX_CLIENTS && AICast_SameTeam( cs, ent->s.number ) ) { + continue; // trust that friends will not hurt us + } + if ( ( dangerFlags & DANGER_FLAMES ) && ( cs->aiFlags & AIFL_NO_FLAME_DAMAGE ) ) { + continue; // venom not effected by flames + } + if ( cs->attributes[TACTICAL] < tacticalLevel ) { // not smart enough + continue; + } + if ( cs->aiState >= AISTATE_COMBAT && cs->attributes[AGGRESSION] > aggressionLevel ) { // we are too aggressive to worry about being hurt by this + continue; + } + // if they are below alert mode, and the danger is not in FOV, then ignore it + if ( cs->aiState < AISTATE_ALERT ) { + vec3_t ang, dir; + VectorSubtract( ent->r.currentOrigin, cs->bs->origin, dir ); + VectorNormalize( dir ); + vectoangles( dir, ang ); + if ( !AICast_InFieldOfVision( cs->viewangles, cs->attributes[FOV], ang ) ) { + // can't see it + continue; + } + } + if ( ent->client && + ( !cs->vislist[ent->s.number].visible_timestamp || ( cs->vislist[ent->s.number].visible_timestamp < level.time - 3000 ) ) ) { + // (!dcs->vislist[trav->s.number].visible_timestamp || (dcs->vislist[trav->s.number].visible_timestamp < level.time - 3000)))) + continue; // not aware of them, and they're not aware of us + } + // are they in danger? + if ( cs->dangerEntityValidTime < level.time + 50 ) { + VectorSubtract( cs->bs->cur_ps.origin, org, vec ); + dist = VectorLength( vec ); + if ( dist < dangerDist ) { + if ( dangerFlags & DANGER_CLIENTAIM ) { + // also check aiming + if ( DotProduct( vec, fwd ) < ( dist * 0.95 - 100 ) ) { + continue; + } + } + // + cs->aiFlags &= ~AIFL_DENYACTION; + AICast_ScriptEvent( cs, "avoiddanger", ent->classname ); + if ( cs->aiFlags & AIFL_DENYACTION ) { + continue; + } + cs->dangerEntity = ent->s.number; + VectorCopy( org, cs->dangerEntityPos ); + cs->dangerEntityValidTime = endTime + 50; + cs->dangerDist = dangerDist * 1.5; // when we hide from it, get a good distance away + cs->dangerEntityTimestamp = level.time; + } + } + } +} + + +qboolean AICast_HasFiredWeapon( int entNum, int weapon ) { + if ( AICast_GetCastState( entNum )->weaponFireTimes[weapon] ) { + return qtrue; + } + + return qfalse; +} + +qboolean AICast_AllowFlameDamage( int entNum ) { + // DHM - Nerve :: caststates are not initialized in multiplayer + if ( g_gametype.integer != GT_SINGLE_PLAYER ) { + return qtrue; + } + // dhm + + if ( caststates[entNum].aiFlags & AIFL_NO_FLAME_DAMAGE ) { + return qfalse; + } + return qtrue; +} + +/* +============= +AICast_ProcessBullet +============= +*/ +void AICast_ProcessBullet( gentity_t *attacker, vec3_t start, vec3_t end ) { + gentity_t *tent; + int i; + float dist; + vec3_t vProj, vDir, dir; + cast_state_t *cs; + + VectorSubtract( end, start, dir ); + + // RF, AI should hear this pass by them really closely, or hitting a wall close by + for ( cs = caststates, tent = g_entities, i = 0; i < level.maxclients; i++, tent++, cs++ ) { + if ( !tent->inuse ) { + continue; + } + if ( tent == attacker ) { + continue; + } + if ( tent->aiInactive ) { + continue; + } + if ( tent->health <= 0 ) { + continue; + } + if ( cs->castScriptStatus.scriptNoSightTime > level.time ) { + continue; + } + if ( !( tent->r.svFlags & SVF_CASTAI ) ) { + continue; + } + if ( cs->aiState >= AISTATE_COMBAT ) { // RF add // already fighting, not interested in bullet impacts + continue; + } + if ( cs->bulletImpactIgnoreTime > level.time ) { + continue; + } + dist = Distance( tent->client->ps.origin, end ); + if ( dist <= cs->attributes[INNER_DETECTION_RADIUS] ) { + // close enough to hear/see the impact? + // first check pvs + if ( !trap_InPVS( tent->client->ps.origin, end ) ) { + continue; + } + // heard it + goto heard; + } + // are they within radius of the bullet path to hear it travel through the air? + ProjectPointOntoVector( tent->client->ps.origin, start, end, vProj ); + VectorSubtract( vProj, start, vDir ); + if ( DotProduct( vDir, dir ) < 0 ) { // they are behind the path of the bullet + continue; + } + if ( Distance( vProj, tent->client->ps.origin ) > 0.5 * cs->attributes[INNER_DETECTION_RADIUS] ) { + continue; + } +heard: + // call the script event + AICast_ScriptEvent( cs, "bulletimpact", "" ); + if ( cs->aiFlags & AIFL_DENYACTION ) { + continue; // ignore the bullet + } + // + cs->bulletImpactTime = level.time + 100 + rand() % 200; // random reaction delay; + VectorCopy( start, cs->bulletImpactStart ); + VectorCopy( end, cs->bulletImpactEnd ); + cs->bulletImpactEntity = attacker->s.number; + } +} + +/* +================ +AICast_AudibleEvent +================ +*/ +void AICast_AudibleEvent( int srcnum, vec3_t pos, float range ) { + int i; + cast_state_t *cs, *scs = 0; + gentity_t *ent, *sent; + float adjustedRange, localDist; + + // DHM - Nerve :: caststates are not initialized in multiplayer + if ( g_gametype.integer != GT_SINGLE_PLAYER ) { + return; + } + // dhm + + if ( g_debugAudibleEvents.integer ) { + G_Printf( "AICast_AudibleEvent: (%0.1f %0.1f %0.1f) range: %0.0f\n", pos[0], pos[1], pos[2], range ); + } + + sent = &g_entities[srcnum]; + if ( sent->flags & FL_NOTARGET ) { + if ( g_debugAudibleEvents.integer ) { + G_Printf( "NOTARGET enabled, aborting\n" ); + } + return; + } + if ( srcnum < level.maxclients ) { + scs = AICast_GetCastState( srcnum ); + } + + for ( ent = g_entities, cs = caststates, i = 0; i < level.maxclients; i++, cs++, ent++ ) { + if ( !cs->bs ) { + continue; + } + if ( ent == sent ) { + continue; + } + if ( cs->castScriptStatus.scriptNoSightTime > level.time ) { + continue; + } + if ( ent->health <= 0 ) { + continue; + } + // if within range, and this sound was made by an enemy + if ( scs ) { + if ( ( srcnum < level.maxclients ) && scs->aiState < AISTATE_COMBAT && !AICast_QueryEnemy( cs, srcnum ) ) { + continue; + } + } + // calculate the adjusted range according to this AI's hearing abilities + adjustedRange = range * cs->attributes[HEARING_SCALE]; + localDist = DistanceSquared( pos, ent->s.pos.trBase ); + if ( localDist > adjustedRange * adjustedRange ) { // fast out if already outside range + continue; + } + if ( !trap_InPVS( pos, ent->s.pos.trBase ) ) { + adjustedRange *= cs->attributes[HEARING_SCALE_NOT_PVS]; + } + if ( localDist > adjustedRange * adjustedRange ) { + continue; + } + // we heard it + + if ( g_debugAudibleEvents.integer ) { + G_Printf( "AICast_AudibleEvent heard: %s \"%s\" (dist:%0.0f s:%0.2f pvss:%0.2f)\n", ent->classname, ent->aiName, ( sqrt( localDist ) ), cs->attributes[HEARING_SCALE], cs->attributes[HEARING_SCALE_NOT_PVS] ); + } + + cs->audibleEventTime = level.time + 200 + rand() % 300; // random reaction delay + VectorCopy( pos, cs->audibleEventOrg ); + cs->audibleEventEnt = ent->s.number; + } +} diff --git a/Projects/Android/jni/rtcw/src/game/ai_cast_fight.h b/Projects/Android/jni/rtcw/src/game/ai_cast_fight.h new file mode 100644 index 0000000..a7b02eb --- /dev/null +++ b/Projects/Android/jni/rtcw/src/game/ai_cast_fight.h @@ -0,0 +1,42 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +//=========================================================================== +// +// Name: ai_cast_fight.h +// Function: Wolfenstein AI Fighting Values +// Programmer: Ridah +// Tab Size: 4 (real tabs) +//=========================================================================== + +// This is where all constants should reside, which decide when or if a character +// can attack it's enemy. + +#define LOPER_GROUND_RANGE 200 +#define BLACKGUARD_MELEE_RANGE 48 +#define REJECT_MELEE_RANGE 90 //----(SA) added diff --git a/Projects/Android/jni/rtcw/src/game/ai_cast_func_attack.c b/Projects/Android/jni/rtcw/src/game/ai_cast_func_attack.c new file mode 100644 index 0000000..57c9eae --- /dev/null +++ b/Projects/Android/jni/rtcw/src/game/ai_cast_func_attack.c @@ -0,0 +1,1259 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +//=========================================================================== +// +// Name: ai_cast_funcs.c +// Function: Wolfenstein AI Character Decision Making +// Programmer: Ridah +// Tab Size: 4 (real tabs) +//=========================================================================== + +#include "../game/g_local.h" +#include "../game/q_shared.h" +#include "../game/botlib.h" //bot lib interface +#include "../game/be_aas.h" +#include "../game/be_ea.h" +#include "../game/be_ai_gen.h" +#include "../game/be_ai_goal.h" +#include "../game/be_ai_move.h" +#include "../botai/botai.h" //bot ai interface + +#include "ai_cast.h" + +//================================================================================= +// +// ZOMBIE SPECIAL ATTACKS +// +//================================================================================= + +/* +============ +AIFunc_ZombieFlameAttack() + + Zombie "Flaming Bats" attack. + + NOTE: this actually uses the EFFECT3 slot for client-side effects (others are taken) +============ +*/ + +#define ZOMBIE_FLAME_DURATION 4000 + +char *AIFunc_ZombieFlameAttack( cast_state_t *cs ) { + bot_state_t *bs; + gentity_t *ent; + // + ent = &g_entities[cs->entityNum]; + bs = cs->bs; + // + ent->s.onFireEnd = level.time + 2000; + // + if ( ent->health < 0 ) { + ent->s.onFireEnd = 0; + return AIFunc_DefaultStart( cs ); + } + // + if ( cs->enemyNum < 0 ) { + ent->s.onFireEnd = level.time + 1500; + ent->client->ps.torsoTimer = 0; + ent->client->ps.legsTimer = 0; + return AIFunc_DefaultStart( cs ); + } +/* disabled, keep going so they cant come back for the easy kill + // + // if we can't see them anymore, abort immediately + if (cs->vislist[cs->enemyNum].real_visible_timestamp != cs->vislist[cs->enemyNum].real_update_timestamp) { + ent->s.onFireEnd = level.time + 1500; + ent->client->ps.torsoTimer = 0; + ent->client->ps.legsTimer = 0; + return AIFunc_DefaultStart( cs ); + } +*/ + // if outside range, move closer + if ( VectorDistance( cs->bs->origin, cs->vislist[cs->enemyNum].visible_pos ) > ZOMBIE_FLAME_RADIUS ) { + ent->s.onFireEnd = level.time + 1500; + ent->client->ps.torsoTimer = 0; + ent->client->ps.legsTimer = 0; + return AIFunc_DefaultStart( cs ); + } + // we are firing this weapon, so record it + cs->weaponFireTimes[WP_MONSTER_ATTACK1] = level.time; + // once an attack has started, only abort once the player leaves our view, or time runs out + if ( cs->thinkFuncChangeTime < level.time - ZOMBIE_FLAME_DURATION ) { + + // finish this attack + ent->client->ps.torsoTimer = 0; + ent->client->ps.legsTimer = 0; + return AIFunc_DefaultStart( cs ); + + } else { + + //ent->client->ps.torsoTimer = 400; + //ent->client->ps.legsTimer = 400; + + // draw the client-side effect + ent->client->ps.eFlags |= EF_MONSTER_EFFECT3; + + // inform the client of our enemies position + //VectorCopy( g_entities[cs->enemyNum].client->ps.origin, ent->s.origin2 ); + //ent->s.origin2[2] += g_entities[cs->enemyNum].client->ps.viewheight; + + // keep facing them + AICast_AimAtEnemy( cs ); + + // look slightly downwards since animation is facing upwards slightly + cs->ideal_viewangles[PITCH] += 20; + } + // + // + return NULL; +} + +char *AIFunc_ZombieFlameAttackStart( cast_state_t *cs ) { + gentity_t *ent; + // + ent = &g_entities[cs->entityNum]; + ent->s.otherEntityNum2 = cs->enemyNum; + ent->s.effect3Time = level.time; + // + // dont turn + cs->ideal_viewangles[YAW] = cs->viewangles[YAW]; + //cs->ideal_viewangles[PITCH] = -45; // look upwards + // start the flame + ent->s.onFireStart = level.time; + ent->s.onFireEnd = level.time + ZOMBIE_FLAME_DURATION; + // + // set the correct animation + BG_PlayAnimName( &ent->client->ps, "both_attack1", ANIM_BP_BOTH, qtrue, qfalse, qtrue ); + ent->client->ps.legsTimer = ZOMBIE_FLAME_DURATION; + ent->client->ps.torsoTimer = ZOMBIE_FLAME_DURATION; + // + cs->aifunc = AIFunc_ZombieFlameAttack; + return "AIFunc_ZombieFlameAttack"; +} + + + +/* +============ +AIFunc_ZombieAttack2() + + Zombie "Evil Spirit" attack. + + Character draws the light from surrounding walls (expanding negative light) and builds + up to the release of a flying translucent skull with trail effect (and beady eyes). + + Spirit should track it's enemy slightly, inflicting lots of damage, removing sprint bar, + and effecting sight temporarily. + + Speed of spirit is effected by skill level, higher skill = faster speed + + Spirits inflicting AI soldiers should kill instantly, removing all flesh from the + soldier's face (draw skull under head model, then fade head model away over a short period). +============ +*/ +extern void weapon_zombiespirit( gentity_t *ent, gentity_t *missile ); + +#define ZOMBIE_SPIRIT_BUILDUP_TIME 6000 // last for this long +#define ZOMBIE_SPIRIT_FADEOUT_TIME 1000 +#define ZOMBIE_SPIRIT_DLIGHT_RADIUS_MAX 256 +#define ZOMBIE_SPIRIT_FIRE_INTERVAL 1000 + +int lastZombieSpiritAttack; + +char *AIFunc_ZombieAttack2( cast_state_t *cs ) { + bot_state_t *bs; + gentity_t *ent; + // + ent = &g_entities[cs->entityNum]; + bs = cs->bs; + // + if ( cs->enemyNum < 0 ) { + return AIFunc_DefaultStart( cs ); + } + // + // if we can't see them anymore, abort immediately + if ( cs->vislist[cs->enemyNum].real_visible_timestamp != cs->vislist[cs->enemyNum].real_update_timestamp ) { + return AIFunc_DefaultStart( cs ); + } + // + lastZombieSpiritAttack = level.time; + // we are firing this weapon, so record it + cs->weaponFireTimes[WP_MONSTER_ATTACK2] = level.time; + // once an attack has started, only abort once the player leaves our view, or time runs out + if ( cs->thinkFuncChangeTime < level.time - ZOMBIE_SPIRIT_BUILDUP_TIME ) { + // if enough time has elapsed, finish this attack + if ( level.time > cs->thinkFuncChangeTime + ZOMBIE_SPIRIT_BUILDUP_TIME + ZOMBIE_SPIRIT_FADEOUT_TIME ) { + return AIFunc_DefaultStart( cs ); + } + } else { + + // set torso to the correct animation + // TODO + //ent->client->ps.torsoTimer = 300; // leave enough time to cancel if we stop coming in here, but stay in the anim if we come back next thing + + // draw the client-side effect + ent->client->ps.eFlags |= EF_MONSTER_EFFECT; + + // inform the client of our enemies position + VectorCopy( g_entities[cs->enemyNum].client->ps.origin, ent->s.origin2 ); + ent->s.origin2[2] += g_entities[cs->enemyNum].client->ps.viewheight; + } + // + // + return NULL; +} + +char *AIFunc_ZombieAttack2Start( cast_state_t *cs ) { + gentity_t *ent; + // + // don't allow 2 consecutive spirit attacks at once + if ( lastZombieSpiritAttack <= level.time && lastZombieSpiritAttack > level.time - 1000 ) { + return NULL; + } + lastZombieSpiritAttack = level.time; + // + ent = &g_entities[cs->entityNum]; + ent->s.otherEntityNum2 = cs->enemyNum; + ent->s.effect1Time = level.time; + // + // dont turn + cs->ideal_viewangles[YAW] = cs->viewangles[YAW]; + // set torso to the correct animation + // TODO + //ent->client->ps.torsoAnim = + // ( ( ent->client->ps.torsoAnim & ANIM_TOGGLEBIT ) ^ ANIM_TOGGLEBIT ) | BOTH_SALUTE; // FIXME: need a specific anim for this + // + cs->aifunc = AIFunc_ZombieAttack2; + return "AIFunc_ZombieAttack2"; +} + + +/* +================ +AIFunc_ZombieMelee +================ +*/ + +int zombieHitDamage[5] = { + 16, + 16, + 16, + 12, + 20 +}; + +#define NUM_ZOMBIE_ANIMS 5 +int zombieHitTimes[NUM_ZOMBIE_ANIMS][3] = { // up to three hits per attack + {ANIMLENGTH( 11,20 ),-1}, + {ANIMLENGTH( 9,20 ),-1}, + {ANIMLENGTH( 9,20 ),-1}, + {ANIMLENGTH( 8,20 ),ANIMLENGTH( 16,20 ),-1}, + {ANIMLENGTH( 8,20 ),ANIMLENGTH( 15,20 ),ANIMLENGTH( 24,20 )}, +}; + +char *AIFunc_ZombieMelee( cast_state_t *cs ) { + gentity_t *ent = &g_entities[cs->entityNum]; + int hitDelay = -1, anim; + trace_t *tr; + cast_state_t *ecs = AICast_GetCastState( cs->enemyNum ); + aicast_predictmove_t move; + float enemyDist; + + if ( !ent->client->ps.torsoTimer ) { + return AIFunc_DefaultStart( cs ); + } + + if ( ecs ) { + + anim = ( ent->client->ps.torsoAnim & ~ANIM_TOGGLEBIT ) - BG_AnimationIndexForString( "attack1", cs->entityNum ); + if ( anim < 0 || anim >= NUM_ZOMBIE_ANIMS ) { + // animation interupted + return AIFunc_DefaultStart( cs ); + } + if ( zombieHitTimes[anim][cs->animHitCount] >= 0 && cs->animHitCount < 3 ) { + + if ( !cs->animHitCount ) { + hitDelay = zombieHitTimes[anim][cs->animHitCount]; + } else { + hitDelay = zombieHitTimes[anim][cs->animHitCount] - zombieHitTimes[anim][cs->animHitCount - 1]; + } + + // check for inflicting damage + if ( level.time - cs->weaponFireTimes[cs->weaponNum] > hitDelay ) { + // do melee damage + if ( ( tr = CheckMeleeAttack( ent, AICast_WeaponRange( cs, cs->weaponNum ) + 4.0, qfalse ) ) && ( tr->entityNum == cs->enemyNum ) ) { + G_Damage( &g_entities[tr->entityNum], ent, ent, vec3_origin, tr->endpos, + zombieHitDamage[anim], 0, MOD_GAUNTLET ); + G_AddEvent( ent, EV_GENERAL_SOUND, G_SoundIndex( aiDefaults[ent->aiCharacter].soundScripts[STAYSOUNDSCRIPT] ) ); + } else { + G_AddEvent( ent, EV_GENERAL_SOUND, G_SoundIndex( aiDefaults[ent->aiCharacter].soundScripts[FOLLOWSOUNDSCRIPT] ) ); + } + cs->weaponFireTimes[cs->weaponNum] = level.time; + cs->animHitCount++; + } + } + // face them + AICast_AimAtEnemy( cs ); + if ( !ent->client->ps.legsTimer || zombieHitTimes[anim][cs->animHitCount] < 0 || cs->animHitCount >= 3 ) { + // if they are outside range, move forward + AICast_PredictMovement( ecs, 2, 0.5, &move, &g_entities[cs->enemyNum].client->pers.cmd, -1 ); + enemyDist = Distance( move.endpos, cs->bs->origin ); + enemyDist -= g_entities[cs->enemyNum].r.maxs[0]; + enemyDist -= ent->r.maxs[0]; + if ( /*anim != 4 &&*/ ( enemyDist > 16 ) ) { // we can get closer + if ( ent->client->ps.legsTimer ) { + ent->client->ps.legsTimer = 0; // allow legs us to move + if ( cs->castScriptStatus.scriptNoMoveTime < level.time + 200 ) { // dont move until the legs are done lerping out of attack anim + cs->castScriptStatus.scriptNoMoveTime = level.time + 200; + } + } + if ( !ent->client->ps.legsTimer && cs->castScriptStatus.scriptNoMoveTime < level.time ) { + trap_EA_MoveForward( cs->entityNum ); + } + } + } + + } + + return NULL; +} + +/* +================ +AIFunc_ZombieMeleeStart +================ +*/ +char *AIFunc_ZombieMeleeStart( cast_state_t *cs ) { + gentity_t *ent; + + ent = &g_entities[cs->entityNum]; + cs->weaponFireTimes[cs->weaponNum] = level.time; + cs->animHitCount = 0; + + // face them + AICast_AimAtEnemy( cs ); + + // audible sound + AIChar_AttackSound( cs ); + + // play an anim + BG_UpdateConditionValue( cs->entityNum, ANIM_COND_WEAPON, cs->weaponNum, qtrue ); + BG_AnimScriptEvent( &ent->client->ps, ANIM_ET_FIREWEAPON, qfalse, qtrue ); + + cs->aifunc = AIFunc_ZombieMelee; + return "AIFunc_ZombieMelee"; +} + +//================================================================================= +// +// LOPER MELEE ATTACK +// +//================================================================================= + +#define NUM_LOPERMELEE_ANIMS 2 +int loperHitTimes[NUM_LOPERMELEE_ANIMS] = { + ( ANIMLENGTH( 3,15 ) ), + ( ANIMLENGTH( 6,15 ) ) +}; + +#define LOPER_MELEE_DAMAGE 20 +#define LOPER_MELEE_RANGE 48 + +/* +=============== +AIFunc_LoperAttack1() + + Loper's close range melee attack +=============== +*/ +char *AIFunc_LoperAttack1( cast_state_t *cs ) { + trace_t *tr; + gentity_t *ent; + int anim; + // + ent = &g_entities[cs->entityNum]; + // + // draw the client-side lightning effect + //ent->client->ps.eFlags |= EF_MONSTER_EFFECT; + // + // have we inflicted the damage? + if ( cs->weaponFireTimes[WP_MONSTER_ATTACK1] > cs->thinkFuncChangeTime ) { + // has the animation finished? + if ( !ent->client->ps.legsTimer ) { + return AIFunc_DefaultStart( cs ); + } + return NULL; // just wait for anim to finish + } + // ready to inflict damage? + anim = ( ent->client->ps.legsAnim & ~ANIM_TOGGLEBIT ) - BG_AnimationIndexForString( "legs_extra", cs->entityNum ); + if ( cs->thinkFuncChangeTime < level.time - loperHitTimes[anim] ) { + // check for damage + // TTimo: gcc: suggests () around assignment used as truth value + if ( ( tr = CheckMeleeAttack( &g_entities[cs->entityNum], LOPER_MELEE_RANGE, qfalse ) ) ) { + G_Damage( &g_entities[tr->entityNum], ent, ent, vec3_origin, tr->endpos, + LOPER_MELEE_DAMAGE, 0, MOD_LOPER_HIT ); + // sound + if ( anim == 0 ) { + G_AddEvent( ent, EV_GENERAL_SOUND, G_SoundIndex( aiDefaults[ent->aiCharacter].soundScripts[ORDERSDENYSOUNDSCRIPT] ) ); + } else { + G_AddEvent( ent, EV_GENERAL_SOUND, G_SoundIndex( aiDefaults[ent->aiCharacter].soundScripts[MISC1SOUNDSCRIPT] ) ); + } + } + cs->weaponFireTimes[WP_MONSTER_ATTACK1] = level.time; + } + + return NULL; +} + + +char *AIFunc_LoperAttack1Start( cast_state_t *cs ) { + gentity_t *ent; + // + ent = &g_entities[cs->entityNum]; + // face them + AICast_AimAtEnemy( cs ); + // start the animation + if ( rand() % 2 ) { + G_AddEvent( ent, EV_GENERAL_SOUND, G_SoundIndex( aiDefaults[ent->aiCharacter].soundScripts[FOLLOWSOUNDSCRIPT] ) ); + BG_PlayAnimName( &ent->client->ps, "legs_extra", ANIM_BP_LEGS, qtrue, qfalse, qtrue ); + } else { + G_AddEvent( ent, EV_GENERAL_SOUND, G_SoundIndex( aiDefaults[ent->aiCharacter].soundScripts[STAYSOUNDSCRIPT] ) ); + BG_PlayAnimName( &ent->client->ps, "legs_extra2", ANIM_BP_LEGS, qtrue, qfalse, qtrue ); + } + // + cs->aifunc = AIFunc_LoperAttack1; + return "AIFunc_LoperAttack1"; +} + +//================================================================================= +// +// LOPER LEAP ATTACK +// +//================================================================================= + +#define LOPER_LEAP_ANIM LEGS_EXTRA3 +#define LOPER_LEAP_FPS 15 + +// update for a version of the loper new today (6/26) +//#define LOPER_LEAP_FRAME_COUNT 4 +#define LOPER_LEAP_FRAME_COUNT 10 +#define LOPER_LEAP_DURATION ( LOPER_LEAP_FRAME_COUNT*( 1000 / LOPER_LEAP_FPS ) ) + + +#define LOPER_LAND_ANIM LEGS_EXTRA4 +#define LOPER_LAND_FPS 15 + +// update for a version of the loper new today (6/26) +//#define LOPER_LAND_FRAME_COUNT 17 +#define LOPER_LAND_FRAME_COUNT 21 +#define LOPER_LAND_DURATION ( LOPER_LAND_FRAME_COUNT*( 1000 / LOPER_LAND_FPS ) ) + + +#define LOPER_LEAP_DAMAGE 10 +#define LOPER_LEAP_DELAY 100 // note, this needs to be something, or they'll think they're done before they even started +#define LOPER_LEAP_RANGE 200 +#define LOPER_LEAP_VELOCITY_START 750.0 +#define LOPER_LEAP_VELOCITY_END 1050.0 +#define LOPER_LEAP_VELOCITY_Z 300 +#define LOPER_LEAP_LAND_MOMENTUM 250 + +/* +=============== +AIFunc_LoperAttack2() + + Loper's leaping long range attack +=============== +*/ +char *AIFunc_LoperAttack2( cast_state_t *cs ) { + gentity_t *ent; + vec3_t vec; + qboolean onGround = qfalse; + // + ent = &g_entities[cs->entityNum]; + // + // are we waiting to inflict damage? + if ( ( cs->enemyNum >= 0 ) && ( cs->weaponFireTimes[WP_MONSTER_ATTACK2] < level.time - 50 ) && + ( cs->bs->cur_ps.groundEntityNum == ENTITYNUM_NONE ) ) { + // ready to inflict damage? + if ( cs->thinkFuncChangeTime < level.time - LOPER_LEAP_DELAY ) { + // check for damage + if ( VectorDistance( cs->bs->origin, g_entities[cs->enemyNum].client->ps.origin ) < LOPER_LEAP_RANGE ) { + // draw the client-side lightning effect + ent->client->ps.eFlags |= EF_MONSTER_EFFECT; + // do the damage + G_Damage( &g_entities[cs->enemyNum], ent, ent, vec3_origin, cs->bs->origin, LOPER_LEAP_DAMAGE, 0, MOD_LOPER_LEAP ); + G_Sound( &g_entities[cs->entityNum], level.loperZapSound ); + cs->weaponFireTimes[WP_MONSTER_ATTACK2] = level.time; + } + } + } + // + // landed? + if ( cs->bs->cur_ps.groundEntityNum != ENTITYNUM_NONE ) { + onGround = qtrue; + } else { // predict a landing + aicast_predictmove_t move; + float changeTime; + AICast_PredictMovement( cs, 1, 0.2, &move, &cs->lastucmd, cs->enemyNum ); + if ( move.groundEntityNum != ENTITYNUM_NONE ) { + onGround = qtrue; + } + // + // adjust velocity + VectorCopy( cs->loperLeapVel, vec ); + vec[2] = 0; + VectorNormalize( vec ); + changeTime = 2.0 * ( 0.001 * ( level.time - cs->thinkFuncChangeTime ) ); + if ( changeTime > 1.0 ) { + changeTime = 1.0; + } + VectorScale( vec, LOPER_LEAP_VELOCITY_START + changeTime * ( LOPER_LEAP_VELOCITY_END - LOPER_LEAP_VELOCITY_START ), vec ); + g_entities[cs->entityNum].s.pos.trDelta[0] = vec[0]; + g_entities[cs->entityNum].s.pos.trDelta[1] = vec[1]; + } + // + if ( onGround || ( cs->aiFlags & AIFL_LAND_ANIM_PLAYED ) ) { + // if we just started the attack recently, we probably haven't had a chance to get airborne yet + if ( cs->thinkFuncChangeTime < level.time - LOPER_LEAP_DELAY ) { + // loper is back on ground, wait for animation to play out + if ( !( cs->aiFlags & AIFL_LAND_ANIM_PLAYED ) ) { + BG_PlayAnimName( &ent->client->ps, "legs_extra4", ANIM_BP_LEGS, qtrue, qfalse, qtrue ); + // + cs->aiFlags |= AIFL_LAND_ANIM_PLAYED; + // TODO:play the landing thud + } + // + if ( ent->client->ps.legsTimer < 800 ) { // we're done + ent->client->ps.legsTimer = 0; + return AIFunc_DefaultStart( cs ); + } + // keep moving slightly in our facing direction to simulate landing momentum + AngleVectors( cs->viewangles, vec, NULL, NULL ); + trap_EA_Move( cs->entityNum, vec, ( (float)ent->client->ps.legsTimer / (float)LOPER_LAND_DURATION ) * (float)LOPER_LEAP_LAND_MOMENTUM ); + return NULL; + } + } + ent->client->ps.legsTimer = 500; // stay on this until landing + return NULL; +} + +char *AIFunc_LoperAttack2Start( cast_state_t *cs ) { + gentity_t *ent; + vec3_t vec, avec; + // + ent = &g_entities[cs->entityNum]; + // + if ( cs->enemyNum < 0 ) { + return AIFunc_DefaultStart( cs ); + } + // face them + AICast_AimAtEnemy( cs ); + // if not facing them yet, wait + VectorSubtract( g_entities[cs->enemyNum].client->ps.origin, cs->bs->origin, vec ); + VectorNormalize( vec ); + AngleVectors( cs->viewangles, avec, NULL, NULL ); + if ( DotProduct( vec, avec ) < 0.9 ) { + //cs->aifunc = AIFunc_LoperAttack2Start; + return NULL; + } + // OK, start the animation + BG_PlayAnimName( &ent->client->ps, "legs_extra3", ANIM_BP_LEGS, qtrue, qfalse, qtrue ); + ent->client->ps.legsTimer = 500; // stay on this until landing + // send us hurtling towards our enemy + VectorScale( vec, LOPER_LEAP_VELOCITY_START, vec ); + vec[2] = LOPER_LEAP_VELOCITY_Z; + VectorCopy( vec, ent->client->ps.velocity ); + VectorCopy( vec, cs->loperLeapVel ); + // + cs->aiFlags &= ~AIFL_LAND_ANIM_PLAYED; + // play the sound + // TODO + // + cs->aifunc = AIFunc_LoperAttack2; + return "AIFunc_LoperAttack2"; +} + +//================================================================================= +// +// LOPER GROUND ATTACK +// +//================================================================================= + +#define LOPER_GROUND_ANIM LEGS_EXTRA5 +#define LOPER_GROUND_FPS 10 + +#define LOPER_GROUND_FRAME_COUNT 8 +#define LOPER_GROUND_DURATION ( LOPER_GROUND_FRAME_COUNT*( 1000 / LOPER_GROUND_FPS ) ) + +#define LOPER_GROUND_DAMAGE 20 + +/* +=============== +AIFunc_LoperAttack3() + + Loper's ground electrical attack +=============== +*/ +char *AIFunc_LoperAttack3( cast_state_t *cs ) { + gentity_t *ent; + qboolean hitClient = qfalse; + // + ent = &g_entities[cs->entityNum]; + // + // done with this attack? + if ( !ent->client->ps.legsTimer ) { + cs->pauseTime = level.time + 600; // don't move until effect is done + ent->client->ps.legsTimer = 600; // stay down until effect is done + return AIFunc_DefaultStart( cs ); + } + // ready to inflict damage? + if ( cs->thinkFuncChangeTime < level.time - 900 ) { + // + // draw the client-side lightning effect + ent->client->ps.eFlags |= EF_MONSTER_EFFECT3; + //ent->s.effect3Time = level.time + 500;//cs->thinkFuncChangeTime + LOPER_GROUND_DELAY - 200; + // + // are we waiting to inflict damage? + if ( cs->weaponFireTimes[WP_MONSTER_ATTACK3] < level.time - 100 ) { + // check for damage + hitClient = G_RadiusDamage( cs->bs->origin, ent, LOPER_GROUND_DAMAGE, LOPER_GROUND_RANGE, ent, MOD_LOPER_GROUND ); + // + cs->weaponFireTimes[WP_MONSTER_ATTACK3] = level.time; + // TODO: client-side visual effect + // TODO: throw them backwards (away from us) + } else { + hitClient = qtrue; // so we don't abort + } + // + if ( !hitClient && ( ent->client->ps.legsTimer > 400 ) && cs->thinkFuncChangeTime < ( level.time - 1000 ) ) { // we're done with this attack + cs->pauseTime = level.time + 400; // don't move until effect is done + ent->client->ps.legsTimer = 400; // stay down until effect is done + return AIFunc_DefaultStart( cs ); + } + } + // + return NULL; +} + +char *AIFunc_LoperAttack3Start( cast_state_t *cs ) { + gentity_t *ent; + // + ent = &g_entities[cs->entityNum]; + // + // face them + AICast_AimAtEnemy( cs ); + // play the animation + BG_PlayAnimName( &ent->client->ps, "legs_extra5", ANIM_BP_LEGS, qtrue, qfalse, qtrue ); + // + // play the buildup sound + // TODO + // + cs->aifunc = AIFunc_LoperAttack3; + return "AIFunc_LoperAttack3"; +} + +//================================================================================= +// +// STIM SOLDIER FLYING ATTACK +// +//================================================================================= + +#define STIMSOLDIER_FLYJUMP_ANIM LEGS_EXTRA1 +#define STIMSOLDIER_FLYJUMP_FPS 15 +#define STIMSOLDIER_FLYJUMP_FRAME_COUNT 28 +#define STIMSOLDIER_FLYJUMP_DURATION ( STIMSOLDIER_FLYJUMP_FRAME_COUNT*( 1000 / STIMSOLDIER_FLYJUMP_FPS ) ) +#define STIMSOLDIER_FLYJUMP_DELAY ( STIMSOLDIER_FLYJUMP_DURATION + 3000 ) + +// hover plays continuously +#define STIMSOLDIER_FLYHOVER_ANIM LEGS_EXTRA2 +#define STIMSOLDIER_FLYHOVER_FPS 5 + +#define STIMSOLDIER_FLYLAND_ANIM LEGS_LAND +#define STIMSOLDIER_FLYLAND_FPS 15 +#define STIMSOLDIER_FLYLAND_FRAME_COUNT 14 +#define STIMSOLDIER_FLYLAND_DURATION ( STIMSOLDIER_FLYLAND_FRAME_COUNT*( 1000 / STIMSOLDIER_FLYLAND_FPS ) ) + +#define STIMSOLDIER_STARTJUMP_DELAY ( STIMSOLDIER_FLYJUMP_DURATION*0.5 ) + +char *AIFunc_StimSoldierAttack1( cast_state_t *cs ) { + gentity_t *ent; + vec3_t vec; + static vec3_t up = {0,0,1}; + // + ent = &g_entities[cs->entityNum]; + cs->weaponFireTimes[WP_MONSTER_ATTACK1] = level.time; + // face them + AICast_AimAtEnemy( cs ); + // + // are we done with this attack? + if ( cs->thinkFuncChangeTime < level.time - STIMSOLDIER_FLYJUMP_DELAY ) { + // have we hit the ground yet? + if ( ent->s.groundEntityNum != ENTITYNUM_NONE ) { + // we are on something, have we started the landing animation? + if ( !( cs->aiFlags & AIFL_LAND_ANIM_PLAYED ) ) { + ent->client->ps.legsAnim = + ( ( ent->client->ps.legsAnim & ANIM_TOGGLEBIT ) ^ ANIM_TOGGLEBIT ) | STIMSOLDIER_FLYLAND_ANIM; + ent->client->ps.legsTimer = STIMSOLDIER_FLYLAND_DURATION; // stay down until attack is finished + // + cs->noAttackTime = level.time + STIMSOLDIER_FLYLAND_DURATION; + cs->aiFlags |= AIFL_LAND_ANIM_PLAYED; + } else { + if ( !ent->client->ps.legsTimer ) { // animation has finished, resume AI + return AIFunc_DefaultStart( cs ); + } + } + } else { + // still flying + } + return NULL; + } + // + // are we ready to start flying? + if ( cs->thinkFuncChangeTime < ( level.time - STIMSOLDIER_STARTJUMP_DELAY ) ) { + if ( !ent->client->ps.powerups[PW_FLIGHT] ) { + // play a special ignition sound? + } + ent->client->ps.powerups[PW_FLIGHT] = 1; // let them fly + ent->s.loopSound = level.stimSoldierFlySound; + ent->client->ps.eFlags |= EF_MONSTER_EFFECT; // client-side stim engine effect + if ( ent->s.effect1Time != ( cs->thinkFuncChangeTime + STIMSOLDIER_STARTJUMP_DELAY ) ) { + ent->s.effect1Time = ( cs->thinkFuncChangeTime + STIMSOLDIER_STARTJUMP_DELAY ); + // start the hovering animation + ent->client->ps.legsAnim = + ( ( ent->client->ps.legsAnim & ANIM_TOGGLEBIT ) ^ ANIM_TOGGLEBIT ) | STIMSOLDIER_FLYHOVER_ANIM; + } + // give us some upwards velocity? + if ( cs->thinkFuncChangeTime > level.time - STIMSOLDIER_FLYJUMP_DURATION * 0.9 ) { + trap_EA_Move( cs->entityNum, up, 300 ); + //trap_EA_Jump(cs->entityNum); + VectorCopy( cs->bs->origin, cs->stimFlyAttackPos ); + } else { + // attack them + // + // if we can't attack, abort + if ( AICast_CheckAttack( cs, cs->enemyNum, qfalse ) ) { + // apply weapons.. + trap_EA_Attack( cs->entityNum ); + } + // we're done here + cs->thinkFuncChangeTime = -9999; + } + } else { + // still on ground, so move forward to account for stepping animation + AngleVectors( cs->viewangles, vec, NULL, NULL ); + trap_EA_Move( cs->entityNum, vec, 300 ); + } + // + if ( ent->client->ps.legsTimer < 1000 ) { + ent->client->ps.legsTimer = 1000; // stay down until effect is done + } + // + return NULL; +} + +char *AIFunc_StimSoldierAttack1Start( cast_state_t *cs ) { + gentity_t *ent; + //static vec3_t mins={-96,-96,0}, maxs={96,96,72}; + vec3_t pos, dir; + trace_t tr; + // + cs->weaponFireTimes[cs->weaponNum] = level.time; + ent = &g_entities[cs->entityNum]; + // + // face them + AICast_AimAtEnemy( cs ); + // first, check if this is a good place to start the flying attack + AngleVectors( cs->ideal_viewangles, dir, NULL, NULL ); + VectorMA( cs->bs->origin, 300, dir, pos ); + pos[2] += 128; + trap_Trace( &tr, cs->bs->origin, cs->bs->cur_ps.mins, cs->bs->cur_ps.maxs, pos, cs->entityNum, ent->clipmask ); + if ( tr.startsolid || tr.allsolid ) { + return NULL; // not a good place + } + // check we can attack them from there + // select our special weapon (rocket launcher or tesla) + if ( COM_BitCheck( cs->bs->cur_ps.weapons, WP_PANZERFAUST ) ) { + cs->weaponNum = WP_PANZERFAUST; + } else if ( COM_BitCheck( cs->bs->cur_ps.weapons, WP_TESLA ) ) { + cs->weaponNum = WP_TESLA; + } else { // no weapon? + G_Error( "stim soldier tried special jump attack without a tesla or rocket launcher\n" ); + } + if ( !AICast_CheckAttackAtPos( cs->entityNum, cs->enemyNum, pos, qfalse, qfalse ) ) { + AICast_ChooseWeapon( cs, qfalse ); + return NULL; + } + // play the animation + ent->client->ps.legsAnim = + ( ( ent->client->ps.legsAnim & ANIM_TOGGLEBIT ) ^ ANIM_TOGGLEBIT ) | STIMSOLDIER_FLYJUMP_ANIM; + ent->client->ps.legsTimer = STIMSOLDIER_FLYJUMP_DELAY; // stay down until attack is finished + // + cs->aiFlags &= ~AIFL_LAND_ANIM_PLAYED; + // play the buildup sound + // TODO + // + cs->aifunc = AIFunc_StimSoldierAttack1; + return "AIFunc_StimSoldierAttack1"; +} + +//================================================================================= +// +// STIM SOLDIER DUAL MACHINEGUN ATTACK +// +//================================================================================= + +char *AIFunc_StimSoldierAttack2( cast_state_t *cs ) { + return NULL; +} + +char *AIFunc_StimSoldierAttack2Start( cast_state_t *cs ) { + gentity_t *ent; + // + cs->weaponFireTimes[cs->weaponNum] = level.time; + ent = &g_entities[cs->entityNum]; + // + // face them + AICast_AimAtEnemy( cs ); + // TODO! + G_Printf( "TODO: stim dual machinegun attack\n" ); + // + cs->aifunc = AIFunc_StimSoldierAttack2; + return "AIFunc_StimSoldierAttack2"; +} + +//================================================================================= +// +// BLACK GUARD MELEE KICK ATTACK +// +//================================================================================= + +#define BLACKGUARD_KICK_DELAY 300 +#define BLACKGUARD_KICK_RANGE BLACKGUARD_MELEE_RANGE + 16 +#define BLACKGUARD_KICK_DAMAGE 25 + +char *AIFunc_BlackGuardAttack1( cast_state_t *cs ) { + gentity_t *ent = &g_entities[cs->entityNum]; + trace_t *tr; + vec3_t fwd; + + if ( !ent->client->ps.legsTimer ) { + return AIFunc_DefaultStart( cs ); + } + // + if ( cs->enemyNum < 0 ) { + return NULL; + } + // time for the melee? + if ( !( cs->aiFlags & AIFL_MISCFLAG1 ) ) { + // face them + AICast_AimAtEnemy( cs ); + // ready for damage? + if ( cs->thinkFuncChangeTime < level.time - BLACKGUARD_KICK_DELAY ) { + cs->aiFlags |= AIFL_MISCFLAG1; + // keep checking for impact status + tr = CheckMeleeAttack( ent, BLACKGUARD_KICK_RANGE, qfalse ); + // do melee damage? + if ( tr && ( tr->entityNum == cs->enemyNum ) ) { + AngleVectors( cs->viewangles, fwd, NULL, NULL ); + G_Damage( &g_entities[tr->entityNum], ent, ent, fwd, tr->endpos, BLACKGUARD_KICK_DAMAGE, 0, MOD_GAUNTLET ); + // throw them in direction of impact + fwd[2] = 0.5; + VectorMA( g_entities[cs->enemyNum].client->ps.velocity, 300, fwd, g_entities[cs->enemyNum].client->ps.velocity ); + } + } + } + + return NULL; +} + +char *AIFunc_BlackGuardAttack1Start( cast_state_t *cs ) { + gentity_t *ent = &g_entities[cs->entityNum]; + // + cs->weaponFireTimes[cs->weaponNum] = level.time; + // face them + AICast_AimAtEnemy( cs ); + // audible sound + AIChar_AttackSound( cs ); + // start the animation + BG_PlayAnimName( &ent->client->ps, "kick", ANIM_BP_BOTH, qtrue, qfalse, qtrue ); + // clear flags + cs->aiFlags &= ~( AIFL_MISCFLAG1 | AIFL_MISCFLAG2 ); + // + cs->aifunc = AIFunc_BlackGuardAttack1; + return "AIFunc_BlackGuardAttack1"; +} + + +//================================================================================= +// +// REJECT X-CREATURE +// +// Attacks are: backhand slap, blowtorch (small flamethrower) +// +//================================================================================= + +////// Backhand attack (slap) + +/* +============== +AIFunc_RejectAttack1 +============== +*/ +char *AIFunc_RejectAttack1( cast_state_t *cs ) { + return NULL; +} + +/* +============== +AIFunc_RejectAttack1Start +============== +*/ +char *AIFunc_RejectAttack1Start( cast_state_t *cs ) { + gentity_t *ent; + + ent = &g_entities[cs->entityNum]; + ent->s.effect1Time = level.time; + cs->ideal_viewangles[YAW] = cs->viewangles[YAW]; + cs->aifunc = AIFunc_RejectAttack1; + return "AIFunc_RejectAttack1"; +} + + +//================================================================================= +// +// WARRIOR ZOMBIE +// +// Standing melee attacks +// +//================================================================================= + +int warriorHitDamage[5] = { + 16, + 16, + 16, + 12, + 20 +}; + +#define NUM_WARRIOR_ANIMS 5 +int warriorHitTimes[NUM_WARRIOR_ANIMS][3] = { // up to three hits per attack + {ANIMLENGTH( 10,20 ),-1}, + {ANIMLENGTH( 15,20 ),-1}, + {ANIMLENGTH( 18,20 ),-1}, + {ANIMLENGTH( 15,20 ),-1}, + {ANIMLENGTH( 14,20 ),-1}, +}; + +/* +================ +AIFunc_WarriorZombieMelee +================ +*/ +char *AIFunc_WarriorZombieMelee( cast_state_t *cs ) { + gentity_t *ent = &g_entities[cs->entityNum]; + int hitDelay = -1, anim; + trace_t *tr; + cast_state_t *ecs = AICast_GetCastState( cs->enemyNum ); + aicast_predictmove_t move; + float enemyDist; + + if ( !ent->client->ps.torsoTimer ) { + return AIFunc_DefaultStart( cs ); + } + // + if ( cs->enemyNum < 0 ) { + return NULL; + } + if ( ecs ) { + + anim = ( ent->client->ps.torsoAnim & ~ANIM_TOGGLEBIT ) - BG_AnimationIndexForString( "attack1", cs->entityNum ); + if ( anim < 0 || anim >= NUM_WARRIOR_ANIMS ) { + // animation interupted + return AIFunc_DefaultStart( cs ); + } + if ( warriorHitTimes[anim][cs->animHitCount] >= 0 && cs->animHitCount < 3 ) { + + if ( !cs->animHitCount ) { + hitDelay = warriorHitTimes[anim][cs->animHitCount]; + } else { + hitDelay = warriorHitTimes[anim][cs->animHitCount] - warriorHitTimes[anim][cs->animHitCount - 1]; + } + + // check for inflicting damage + if ( level.time - cs->weaponFireTimes[cs->weaponNum] > hitDelay ) { + // do melee damage + if ( ( tr = CheckMeleeAttack( ent, 44, qfalse ) ) && ( tr->entityNum == cs->enemyNum ) ) { + G_Damage( &g_entities[tr->entityNum], ent, ent, vec3_origin, tr->endpos, + warriorHitDamage[anim], 0, MOD_GAUNTLET ); + G_AddEvent( ent, EV_GENERAL_SOUND, G_SoundIndex( aiDefaults[ent->aiCharacter].soundScripts[STAYSOUNDSCRIPT] ) ); + } else { + G_AddEvent( ent, EV_GENERAL_SOUND, G_SoundIndex( aiDefaults[ent->aiCharacter].soundScripts[FOLLOWSOUNDSCRIPT] ) ); + } + cs->weaponFireTimes[cs->weaponNum] = level.time; + cs->animHitCount++; + } + } + // face them + AICast_AimAtEnemy( cs ); + if ( anim < 3 ) { // back handed-swinging, dont allow legs to move + // if they are outside range, move forward + AICast_PredictMovement( ecs, 2, 0.5, &move, &g_entities[cs->enemyNum].client->pers.cmd, -1 ); + enemyDist = Distance( move.endpos, cs->bs->origin ); + enemyDist -= g_entities[cs->enemyNum].r.maxs[0]; + enemyDist -= ent->r.maxs[0]; + if ( enemyDist > 16 ) { // we can get closer + if ( ent->client->ps.legsTimer ) { + ent->client->ps.legsTimer = 0; // allow legs us to move + if ( cs->castScriptStatus.scriptNoMoveTime < level.time + 200 ) { // dont move until the legs are done lerping out of attack anim + cs->castScriptStatus.scriptNoMoveTime = level.time + 200; + } + } + if ( cs->castScriptStatus.scriptNoMoveTime < level.time ) { + trap_EA_MoveForward( cs->entityNum ); + } + } + } + } + + return NULL; +} + +/* +================ +AIFunc_WarriorZombieMeleeStart +================ +*/ +char *AIFunc_WarriorZombieMeleeStart( cast_state_t *cs ) { + gentity_t *ent; + + ent = &g_entities[cs->entityNum]; + ent->s.effect1Time = level.time; + cs->ideal_viewangles[YAW] = cs->viewangles[YAW]; + cs->weaponFireTimes[cs->weaponNum] = level.time; + cs->animHitCount = 0; + + // face them + AICast_AimAtEnemy( cs ); + + // audible sound + AIChar_AttackSound( cs ); + + // play an anim + BG_UpdateConditionValue( cs->entityNum, ANIM_COND_WEAPON, cs->weaponNum, qtrue ); + BG_AnimScriptEvent( &ent->client->ps, ANIM_ET_FIREWEAPON, qfalse, qtrue ); + + // stop charging + BG_UpdateConditionValue( cs->entityNum, ANIM_COND_CHARGING, 0, qfalse ); + ent->flags &= ~FL_WARZOMBIECHARGE; + + cs->aifunc = AIFunc_WarriorZombieMelee; + return "AIFunc_WarriorZombieMelee"; +} + +// Warrior "sight" animation +/* +================ +AIFunc_WarriorZombieSight +================ +*/ +char *AIFunc_WarriorZombieSight( cast_state_t *cs ) { + gentity_t *ent = &g_entities[cs->entityNum]; + + if ( !ent->client->ps.torsoTimer ) { + return AIFunc_DefaultStart( cs ); + } + return NULL; +} + +/* +================ +AIFunc_WarriorZombieSightStart +================ +*/ +char *AIFunc_WarriorZombieSightStart( cast_state_t *cs ) { + gentity_t *ent; + +// RF, disabled + return NULL; + + ent = &g_entities[cs->entityNum]; + cs->ideal_viewangles[YAW] = cs->viewangles[YAW]; + cs->weaponFireTimes[cs->weaponNum] = level.time; + + // face them + AICast_AimAtEnemy( cs ); + + // anim + BG_AnimScriptEvent( &ent->client->ps, ANIM_ET_FIRSTSIGHT, qfalse, qtrue ); + //BG_PlayAnimName( &ent->client->ps, "first_sight", ANIM_BP_BOTH, qtrue, qfalse, qtrue ); + + cs->aifunc = AIFunc_WarriorZombieSight; + return "AIFunc_WarriorZombieSight"; +} + +/* +================ +AIFunc_WarriorZombieDefense +================ +*/ +char *AIFunc_WarriorZombieDefense( cast_state_t *cs ) { + gentity_t *ent, *enemy; + vec3_t enemyDir, vec; + float dist; + + ent = &g_entities[cs->entityNum]; + + if ( !( ent->flags & FL_DEFENSE_GUARD ) ) { + if ( cs->weaponFireTimes[cs->weaponNum] < level.time - 100 ) { + return AIFunc_DefaultStart( cs ); + } + return NULL; + } + + if ( ( cs->enemyNum < 0 ) || ( cs->dangerEntityValidTime >= level.time ) ) { + ent->flags &= ~FL_DEFENSE_GUARD; + ent->client->ps.torsoTimer = 0; + ent->client->ps.legsTimer = 0; + return NULL; + } + + enemy = &g_entities[cs->enemyNum]; + + if ( cs->thinkFuncChangeTime < level.time - 1500 ) { + // if we cant see them + if ( !AICast_EntityVisible( cs, cs->enemyNum, qtrue ) ) { + ent->flags &= ~FL_DEFENSE_GUARD; + ent->client->ps.torsoTimer = 0; + ent->client->ps.legsTimer = 0; + return NULL; + } + + // if our enemy isn't using a dangerous weapon + if ( enemy->client->ps.weapon < WP_LUGER || enemy->client->ps.weapon > WP_CLASS_SPECIAL ) { + ent->flags &= ~FL_DEFENSE_GUARD; + ent->client->ps.torsoTimer = 0; + ent->client->ps.legsTimer = 0; + return NULL; + } + + // if our enemy isn't looking right at us, abort + VectorSubtract( ent->client->ps.origin, enemy->client->ps.origin, vec ); + dist = VectorNormalize( vec ); + if ( dist > 512 ) { + dist = 512; + } + AngleVectors( enemy->client->ps.viewangles, enemyDir, NULL, NULL ); + if ( DotProduct( vec, enemyDir ) < ( 0.98 - 0.2 * ( dist / 512 ) ) ) { + ent->flags &= ~FL_DEFENSE_GUARD; + ent->client->ps.torsoTimer = 0; + ent->client->ps.legsTimer = 0; + return NULL; + } + } + + cs->weaponFireTimes[cs->weaponNum] = level.time; + + if ( !ent->client->ps.torsoTimer ) { + ent->flags &= ~FL_DEFENSE_GUARD; + ent->client->ps.torsoTimer = 0; + ent->client->ps.legsTimer = 0; + return NULL; + } + + // face them + AICast_AimAtEnemy( cs ); + // crouching position, use smaller bounding box + trap_EA_Crouch( cs->bs->client ); + + return NULL; +} + +/* +================ +AIFunc_WarriorZombieDefenseStart +================ +*/ +char *AIFunc_WarriorZombieDefenseStart( cast_state_t *cs ) { + gentity_t *ent, *enemy; + vec3_t enemyDir, vec; + float dist; + static int lastWarriorDefense; + + if ( lastWarriorDefense <= level.time && lastWarriorDefense > level.time - 3000 ) { + return NULL; // dont all go into defense at once + } + lastWarriorDefense = level.time; + + ent = &g_entities[cs->entityNum]; + enemy = &g_entities[cs->enemyNum]; + + // if our enemy isn't using a dangerous weapon + if ( enemy->client->ps.weapon < WP_LUGER || enemy->client->ps.weapon > WP_CLASS_SPECIAL ) { + return NULL; + } + + // if we are doing a goto + if ( cs->followEntity >= 0 ) { + return NULL; + } + + // if our enemy isn't looking right at us, abort + VectorSubtract( ent->client->ps.origin, enemy->client->ps.origin, vec ); + dist = VectorNormalize( vec ); + if ( dist > 512 ) { + dist = 512; + } + if ( dist < 128 ) { + return NULL; + } + AngleVectors( enemy->client->ps.viewangles, enemyDir, NULL, NULL ); + if ( DotProduct( vec, enemyDir ) < ( 0.98 - 0.2 * ( dist / 512 ) ) ) { + return NULL; + } + + cs->weaponFireTimes[cs->weaponNum] = level.time; + + // face them + AICast_AimAtEnemy( cs ); + + // anim + BG_UpdateConditionValue( cs->entityNum, ANIM_COND_WEAPON, cs->weaponNum, qtrue ); + BG_AnimScriptEvent( &ent->client->ps, ANIM_ET_FIREWEAPON, qfalse, qtrue ); + ent->client->ps.torsoTimer = 3000; + ent->client->ps.legsTimer = 3000; + + ent->flags |= FL_DEFENSE_GUARD; + + // when they come out of defense mode, go into charge mode + BG_UpdateConditionValue( cs->entityNum, ANIM_COND_CHARGING, 1, qfalse ); + ent->flags |= FL_WARZOMBIECHARGE; + + cs->aifunc = AIFunc_WarriorZombieDefense; + return "AIFunc_WarriorZombieDefense"; +} diff --git a/Projects/Android/jni/rtcw/src/game/ai_cast_func_boss1.c b/Projects/Android/jni/rtcw/src/game/ai_cast_func_boss1.c new file mode 100644 index 0000000..2e37c75 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/game/ai_cast_func_boss1.c @@ -0,0 +1,1034 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +//=========================================================================== +// +// Name: ai_cast_funcs.c +// Function: Wolfenstein AI Character Decision Making +// Programmer: Ridah +// Tab Size: 4 (real tabs) +//=========================================================================== + +#include "../game/g_local.h" +#include "../game/q_shared.h" +#include "../game/botlib.h" //bot lib interface +#include "../game/be_aas.h" +#include "../game/be_ea.h" +#include "../game/be_ai_gen.h" +#include "../game/be_ai_goal.h" +#include "../game/be_ai_move.h" +#include "../botai/botai.h" //bot ai interface + +#include "ai_cast.h" + +// TTimo: unused +//static vec3_t forward, right, up; + +//================================================================================= +// +// Helga, the first boss +// +//================================================================================= + +#define HELGA_SPIRIT_BUILDUP_TIME 8000 // last for this long +#define HELGA_SPIRIT_FADEOUT_TIME 1000 +#define HELGA_SPIRIT_DLIGHT_RADIUS_MAX 384 +#define HELGA_SPIRIT_FIRE_INTERVAL 1000 + +extern int lastZombieSpiritAttack; + +char *AIFunc_Helga_SpiritAttack( cast_state_t *cs ) { + bot_state_t *bs; + gentity_t *ent; + // + cs->aiFlags |= AIFL_SPECIAL_FUNC; + ent = &g_entities[cs->entityNum]; + bs = cs->bs; + // make sure we're still playing the right anim + if ( ( ent->client->ps.torsoAnim & ~ANIM_TOGGLEBIT ) - BG_AnimationIndexForString( "attack1", cs->entityNum ) ) { + return AIFunc_DefaultStart( cs ); + } + // + if ( cs->enemyNum < 0 ) { + ent->client->ps.torsoTimer = 0; + ent->client->ps.legsTimer = 0; + return AIFunc_DefaultStart( cs ); + } + // + // if we can't see them anymore, abort immediately + if ( cs->vislist[cs->enemyNum].real_visible_timestamp != cs->vislist[cs->enemyNum].real_update_timestamp ) { + ent->client->ps.torsoTimer = 0; + ent->client->ps.legsTimer = 0; + return AIFunc_DefaultStart( cs ); + } + // we are firing this weapon, so record it + cs->weaponFireTimes[WP_MONSTER_ATTACK2] = level.time; + // + // once an attack has started, only abort once the player leaves our view, or time runs out + if ( cs->thinkFuncChangeTime < level.time - HELGA_SPIRIT_BUILDUP_TIME ) { + // if enough time has elapsed, finish this attack + if ( level.time > cs->thinkFuncChangeTime + HELGA_SPIRIT_BUILDUP_TIME + HELGA_SPIRIT_FADEOUT_TIME ) { + ent->client->ps.torsoTimer = 0; + ent->client->ps.legsTimer = 0; + return AIFunc_DefaultStart( cs ); + } + } else { + + // set timers + ent->client->ps.torsoTimer = 1000; + ent->client->ps.legsTimer = 1000; + + // draw the client-side effect + ent->client->ps.eFlags |= EF_MONSTER_EFFECT; + + // inform the client of our enemies position + VectorCopy( g_entities[cs->enemyNum].client->ps.origin, ent->s.origin2 ); + ent->s.origin2[2] += g_entities[cs->enemyNum].client->ps.viewheight; + } + // + // + return NULL; +} + +char *AIFunc_Helga_SpiritAttack_Start( cast_state_t *cs ) { + gentity_t *ent; + // + ent = &g_entities[cs->entityNum]; + ent->s.otherEntityNum2 = cs->enemyNum; + ent->s.effect1Time = level.time; + cs->aiFlags |= AIFL_SPECIAL_FUNC; + // + // dont turn + cs->ideal_viewangles[YAW] = cs->viewangles[YAW]; + // play an anim + BG_UpdateConditionValue( cs->entityNum, ANIM_COND_WEAPON, WP_MONSTER_ATTACK2, qtrue ); + BG_AnimScriptEvent( &ent->client->ps, ANIM_ET_FIREWEAPON, qfalse, qtrue ); + // + cs->aifunc = AIFunc_Helga_SpiritAttack; + return "AIFunc_Helga_SpiritAttack"; +} + +//================================================================================= +// +// Standing melee attacks +// +//================================================================================= + +#define NUM_HELGA_ANIMS 3 +#define MAX_HELGA_IMPACTS 3 +int helgaHitTimes[NUM_HELGA_ANIMS][MAX_HELGA_IMPACTS] = { // up to three hits per attack + {ANIMLENGTH( 16,20 ),-1}, + {ANIMLENGTH( 11,20 ),ANIMLENGTH( 19,20 ),-1}, + {ANIMLENGTH( 10,20 ),ANIMLENGTH( 17,20 ),ANIMLENGTH( 26,20 )}, +}; +int helgaHitDamage[NUM_HELGA_ANIMS] = { + 20, + 14, + 12 +}; + +/* +================ +AIFunc_Helga_Melee +================ +*/ +char *AIFunc_Helga_Melee( cast_state_t *cs ) { + gentity_t *ent = &g_entities[cs->entityNum]; + gentity_t *enemy; + cast_state_t *ecs; + int hitDelay = -1, anim; + trace_t tr; + float enemyDist; + aicast_predictmove_t move; + vec3_t vec; + + cs->aiFlags |= AIFL_SPECIAL_FUNC; + + if ( !ent->client->ps.torsoTimer || !ent->client->ps.legsTimer ) { + cs->aiFlags &= ~AIFL_SPECIAL_FUNC; + return AIFunc_DefaultStart( cs ); + } + + if ( cs->enemyNum < 0 ) { + ent->client->ps.legsTimer = 0; // allow legs us to move + ent->client->ps.torsoTimer = 0; // allow legs us to move + cs->aiFlags &= ~AIFL_SPECIAL_FUNC; + return AIFunc_DefaultStart( cs ); + } + + ecs = AICast_GetCastState( cs->enemyNum ); + enemy = &g_entities[cs->enemyNum]; + + anim = ( ent->client->ps.torsoAnim & ~ANIM_TOGGLEBIT ) - BG_AnimationIndexForString( "attack3", cs->entityNum ); + if ( anim < 0 || anim >= NUM_HELGA_ANIMS ) { + // animation interupted + cs->aiFlags &= ~AIFL_SPECIAL_FUNC; + return AIFunc_DefaultStart( cs ); + //G_Error( "AIFunc_HelgaZombieMelee: helgaBoss using invalid or unknown attack anim" ); + } + if ( cs->animHitCount < MAX_HELGA_IMPACTS && helgaHitTimes[anim][cs->animHitCount] >= 0 ) { + + // face them + VectorCopy( cs->bs->origin, vec ); + vec[2] += ent->client->ps.viewheight; + VectorSubtract( enemy->client->ps.origin, vec, vec ); + VectorNormalize( vec ); + vectoangles( vec, cs->ideal_viewangles ); + cs->ideal_viewangles[PITCH] = AngleNormalize180( cs->ideal_viewangles[PITCH] ); + + // get hitDelay + if ( !cs->animHitCount ) { + hitDelay = helgaHitTimes[anim][cs->animHitCount]; + } else { + hitDelay = helgaHitTimes[anim][cs->animHitCount] - helgaHitTimes[anim][cs->animHitCount - 1]; + } + + // check for inflicting damage + if ( level.time - cs->weaponFireTimes[cs->weaponNum] > hitDelay ) { + // do melee damage + enemyDist = VectorDistance( enemy->r.currentOrigin, ent->r.currentOrigin ); + enemyDist -= g_entities[cs->enemyNum].r.maxs[0]; + enemyDist -= ent->r.maxs[0]; + if ( enemyDist < 10 + AICast_WeaponRange( cs, cs->weaponNum ) ) { + trap_Trace( &tr, ent->r.currentOrigin, NULL, NULL, enemy->r.currentOrigin, ent->s.number, MASK_SHOT ); + if ( tr.entityNum == cs->enemyNum ) { + G_Damage( &g_entities[tr.entityNum], ent, ent, vec3_origin, tr.endpos, + helgaHitDamage[anim], 0, MOD_GAUNTLET ); + G_AddEvent( enemy, EV_GENERAL_SOUND, G_SoundIndex( aiDefaults[ent->aiCharacter].soundScripts[STAYSOUNDSCRIPT] ) ); + } + } + cs->weaponFireTimes[cs->weaponNum] = level.time; + cs->animHitCount++; + } + } + + // if they are outside range, move forward + AICast_PredictMovement( ecs, 2, 0.3, &move, &g_entities[cs->enemyNum].client->pers.cmd, -1 ); + VectorSubtract( move.endpos, cs->bs->origin, vec ); + vec[2] = 0; + enemyDist = VectorLength( vec ); + enemyDist -= g_entities[cs->enemyNum].r.maxs[0]; + enemyDist -= ent->r.maxs[0]; + if ( enemyDist > 8 ) { // we can get closer + //if (!ent->client->ps.legsTimer) { + // cs->castScriptStatus.scriptNoMoveTime = 0; + trap_EA_MoveForward( cs->entityNum ); + //} + //ent->client->ps.legsTimer = 0; // allow legs us to move + } + + return NULL; +} + +/* +================ +AIFunc_Helga_MeleeStart +================ +*/ +char *AIFunc_Helga_MeleeStart( cast_state_t *cs ) { + gentity_t *ent; + + ent = &g_entities[cs->entityNum]; + ent->s.effect1Time = level.time; + cs->ideal_viewangles[YAW] = cs->viewangles[YAW]; + cs->weaponFireTimes[cs->weaponNum] = level.time; + cs->animHitCount = 0; + cs->aiFlags |= AIFL_SPECIAL_FUNC; + + // face them + AICast_AimAtEnemy( cs ); + + // play an anim + BG_UpdateConditionValue( cs->entityNum, ANIM_COND_WEAPON, cs->weaponNum, qtrue ); + BG_AnimScriptEvent( &ent->client->ps, ANIM_ET_FIREWEAPON, qfalse, qtrue ); + + // play a sound + G_AddEvent( ent, EV_GENERAL_SOUND, G_SoundIndex( aiDefaults[ent->aiCharacter].soundScripts[ATTACKSOUNDSCRIPT] ) ); + + cs->aifunc = AIFunc_Helga_Melee; + cs->aifunc( cs ); // think once now, to prevent a delay + return "AIFunc_Helga_Melee"; +} + + +//=================================================================== + +/* +============== +AIFunc_FlameZombie_Portal +============== +*/ +char *AIFunc_FlameZombie_Portal( cast_state_t *cs ) { + gentity_t *ent = &g_entities[cs->entityNum]; + // + if ( cs->thinkFuncChangeTime < level.time - PORTAL_ZOMBIE_SPAWNTIME ) { + // HACK, make them aware of the player + AICast_UpdateVisibility( &g_entities[cs->entityNum], AICast_FindEntityForName( "player" ), qfalse, qtrue ); + ent->s.time2 = 0; // turn spawning effect off + return AIFunc_DefaultStart( cs ); + } + // + return NULL; +} + +/* +============== +AIFunc_FlameZombie_PortalStart +============== +*/ +char *AIFunc_FlameZombie_PortalStart( cast_state_t *cs ) { + gentity_t *ent = &g_entities[cs->entityNum]; + // + ent->s.time2 = level.time + 200; // hijacking this for portal spawning effect + // + // play a special animation + ent->client->ps.torsoAnim = + ( ( ent->client->ps.torsoAnim & ANIM_TOGGLEBIT ) ^ ANIM_TOGGLEBIT ) | BOTH_EXTRA1; + ent->client->ps.legsAnim = + ( ( ent->client->ps.legsAnim & ANIM_TOGGLEBIT ) ^ ANIM_TOGGLEBIT ) | BOTH_EXTRA1; + ent->client->ps.torsoTimer = PORTAL_ZOMBIE_SPAWNTIME - 200; + ent->client->ps.legsTimer = PORTAL_ZOMBIE_SPAWNTIME - 200; + // + cs->thinkFuncChangeTime = level.time; + // + cs->aifunc = AIFunc_FlameZombie_Portal; + return "AIFunc_FlameZombie_Portal"; +} + + +//================================================================================= +// +// Heinrich, the LAST boss +// +//================================================================================= + +// +// Special Sound Precache +// + +typedef enum +{ + HEINRICH_SWORDIMPACT, + HEINRICH_SWORDLUNGE_START, + HEINRICH_SWORDKNOCKBACK_START, + HEINRICH_SWORDKNOCKBACK_WEAPON, + HEINRICH_SWORDSIDESLASH_START, + HEINRICH_SWORDSIDESLASH_WEAPON, + HEINRICH_EARTHQUAKE_START, + HEINRICH_RAISEDEAD_START, + HEINRICH_TAUNT_GOODHEALTH, + HEINRICH_TAUNT_LOWHEALTH, + + MAX_HEINRICH_SOUNDS +} heinrichSounds_t; + +char *heinrichSounds[MAX_HEINRICH_SOUNDS] = { + "heinrichSwordImpact", + "heinrichSwordLungeStart", + "heinrichSwordKnockbackStart", + "heinrichSwordKnockbackWeapon", + "heinrichSwordSideSlashStart", + "heinrichSwordSideSlashWeapon", + "heinrichSwordEarthquakeStart", + "heinrichRaiseWarriorStart", + "heinrichTauntGoodHealth", + "heinrichTauntLowHealth", +}; + +int heinrichSoundIndex[MAX_HEINRICH_SOUNDS]; + +void AICast_Heinrich_SoundPrecache( void ) { + int i; + for ( i = 0; i < MAX_HEINRICH_SOUNDS; i++ ) { + heinrichSoundIndex[i] = G_SoundIndex( heinrichSounds[i] ); + } +} + +void AICast_Heinrich_Taunt( cast_state_t *cs ) { + gentity_t *ent = &g_entities[cs->entityNum]; + static int lastTaunt; + // sound + if ( ent->health > cs->attributes[STARTING_HEALTH] * 0.25 ) { + if ( lastTaunt > level.time || lastTaunt < level.time - 20000 ) { + G_AddEvent( ent, EV_GENERAL_SOUND, heinrichSoundIndex[HEINRICH_TAUNT_GOODHEALTH] ); + lastTaunt = level.time; + } + } else { + if ( lastTaunt > level.time || lastTaunt < level.time - 40000 ) { + G_AddEvent( ent, EV_GENERAL_SOUND, heinrichSoundIndex[HEINRICH_TAUNT_LOWHEALTH] ); + lastTaunt = level.time; + } + } +} + +#define HEINRICH_LUNGE_DELAY ANIMLENGTH( 15,20 ) +#define HEINRICH_LUNGE_RANGE 170 +#define HEINRICH_LUNGE_DAMAGE ( 50 + rand() % 20 ) + +char *AIFunc_Heinrich_SwordLunge( cast_state_t *cs ) { + gentity_t *ent = &g_entities[cs->entityNum]; + trace_t *tr; + vec3_t left; + float enemyDist; + aicast_predictmove_t move; + vec3_t vec; + cast_state_t *ecs; + + cs->aiFlags |= AIFL_SPECIAL_FUNC; + + if ( cs->enemyNum < 0 ) { + if ( ent->client->ps.torsoTimer ) { + return NULL; + } + return AIFunc_DefaultStart( cs ); + } + + ecs = AICast_GetCastState( cs->enemyNum ); + + + if ( ent->client->ps.torsoTimer < 500 ) { + if ( !ent->client->ps.legsTimer ) { + trap_EA_MoveForward( cs->entityNum ); + } + ent->client->ps.legsTimer = 0; + ent->client->ps.torsoTimer = 0; + cs->castScriptStatus.scriptNoMoveTime = 0; + AICast_Heinrich_Taunt( cs ); + return AIFunc_BattleChaseStart( cs ); + } + + // time for the melee? + if ( cs->enemyNum >= 0 && !( cs->aiFlags & AIFL_MISCFLAG1 ) ) { + // face them + AICast_AimAtEnemy( cs ); + // keep checking for impact status + tr = CheckMeleeAttack( ent, HEINRICH_LUNGE_RANGE, qfalse ); +/* // do we need to move? + if (!(tr && (tr->entityNum == cs->enemyNum))) { + ent->client->ps.legsTimer = 0; + cs->castScriptStatus.scriptNoMoveTime = 0; + trap_EA_MoveForward( cs->entityNum ); + } +*/ // ready for damage? + if ( cs->thinkFuncChangeTime < level.time - HEINRICH_LUNGE_DELAY ) { + cs->aiFlags |= AIFL_MISCFLAG1; + // do melee damage + if ( tr && ( tr->entityNum == cs->enemyNum ) ) { + G_Damage( &g_entities[tr->entityNum], ent, ent, left, tr->endpos, HEINRICH_LUNGE_DAMAGE, 0, MOD_GAUNTLET ); + // sound + G_AddEvent( ent, EV_GENERAL_SOUND, heinrichSoundIndex[HEINRICH_SWORDIMPACT] ); + } + } + } + + // if they are outside range, move forward + AICast_PredictMovement( ecs, 2, 0.3, &move, &g_entities[cs->enemyNum].client->pers.cmd, -1 ); + VectorSubtract( move.endpos, cs->bs->origin, vec ); + vec[2] = 0; + enemyDist = VectorLength( vec ); + enemyDist -= g_entities[cs->enemyNum].r.maxs[0]; + enemyDist -= ent->r.maxs[0]; + if ( enemyDist > 30 ) { // we can get closer + if ( ent->client->ps.legsTimer ) { + cs->castScriptStatus.scriptNoMoveTime = level.time + 100; + ent->client->ps.legsTimer = 0; // allow legs to move us + } + if ( cs->castScriptStatus.scriptNoMoveTime < level.time ) { + trap_EA_MoveForward( cs->entityNum ); + } + } + + return NULL; +} + +char *AIFunc_Heinrich_SwordLungeStart( cast_state_t *cs ) { + gentity_t *ent = &g_entities[cs->entityNum]; +// gentity_t *enemy = &g_entities[cs->enemyNum]; + + cs->aiFlags |= AIFL_SPECIAL_FUNC; + // sound + G_AddEvent( ent, EV_GENERAL_SOUND, heinrichSoundIndex[HEINRICH_SWORDLUNGE_START] ); + // face them + AICast_AimAtEnemy( cs ); + // clear flags + cs->aiFlags &= ~( AIFL_MISCFLAG1 | AIFL_MISCFLAG2 ); + // play the anim + BG_PlayAnimName( &ent->client->ps, "attack9", ANIM_BP_BOTH, qtrue, qfalse, qtrue ); + // start the func + cs->aifunc = AIFunc_Heinrich_SwordLunge; + return "AIFunc_Heinrich_SwordLunge"; +} + +#define HEINRICH_KNOCKBACK_DELAY ANIMLENGTH( 26,20 ) +#define HEINRICH_KNOCKBACK_RANGE 150 +#define HEINRICH_KNOCKBACK_DAMAGE ( 60 + rand() % 20 ) + +char *AIFunc_Heinrich_SwordKnockback( cast_state_t *cs ) { + gentity_t *ent = &g_entities[cs->entityNum]; + trace_t *tr; + vec3_t right, left; +// float enemyDist; +// aicast_predictmove_t move; +// vec3_t vec; + cast_state_t *ecs; + + cs->aiFlags |= AIFL_SPECIAL_FUNC; + + if ( cs->enemyNum < 0 ) { + if ( ent->client->ps.torsoTimer ) { + return NULL; + } + return AIFunc_DefaultStart( cs ); + } + + ecs = AICast_GetCastState( cs->enemyNum ); + + if ( ent->client->ps.torsoTimer < 500 ) { + if ( !ent->client->ps.legsTimer ) { + trap_EA_MoveForward( cs->entityNum ); + } + ent->client->ps.legsTimer = 0; + ent->client->ps.torsoTimer = 0; + cs->castScriptStatus.scriptNoMoveTime = 0; + AICast_Heinrich_Taunt( cs ); + return AIFunc_BattleChaseStart( cs ); + } + + // time for the melee? + if ( cs->enemyNum >= 0 && !( cs->aiFlags & AIFL_MISCFLAG1 ) ) { + // face them + AICast_AimAtEnemy( cs ); + // keep checking for impact status + tr = CheckMeleeAttack( ent, HEINRICH_KNOCKBACK_RANGE, qfalse ); +/* // do we need to move? + if (!(tr && (tr->entityNum == cs->enemyNum))) { + ent->client->ps.legsTimer = 0; + cs->castScriptStatus.scriptNoMoveTime = 0; + trap_EA_MoveForward( cs->entityNum ); + } +*/ // ready for damage? + if ( cs->thinkFuncChangeTime < level.time - HEINRICH_KNOCKBACK_DELAY ) { + cs->aiFlags |= AIFL_MISCFLAG1; + // do melee damage + if ( tr && ( tr->entityNum == cs->enemyNum ) ) { + AngleVectors( cs->viewangles, NULL, right, NULL ); + VectorNegate( right, left ); + G_Damage( &g_entities[tr->entityNum], ent, ent, left, tr->endpos, HEINRICH_KNOCKBACK_DAMAGE, 0, MOD_GAUNTLET ); + // sound + G_AddEvent( ent, EV_GENERAL_SOUND, heinrichSoundIndex[HEINRICH_SWORDIMPACT] ); + // throw them in direction of impact + if ( ( ent->client->ps.torsoAnim & ~ANIM_TOGGLEBIT ) == BG_AnimationIndexForString( "attack2", cs->entityNum ) ) { + // right + right[2] = 0.5; + VectorMA( g_entities[cs->enemyNum].client->ps.velocity, 400, right, g_entities[cs->enemyNum].client->ps.velocity ); + } else { + // left + left[2] = 0.5; + VectorMA( g_entities[cs->enemyNum].client->ps.velocity, 400, left, g_entities[cs->enemyNum].client->ps.velocity ); + } + } + } + } +/* DISABLED FOR SWORDKNOCKBACK..looks bad + // if they are outside range, move forward + AICast_PredictMovement( ecs, 2, 0.3, &move, &g_entities[cs->enemyNum].client->pers.cmd, -1 ); + VectorSubtract( move.endpos, cs->bs->origin, vec ); + vec[2] = 0; + enemyDist = VectorLength( vec ); + enemyDist -= g_entities[cs->enemyNum].r.maxs[0]; + enemyDist -= ent->r.maxs[0]; + if (enemyDist > 30) { // we can get closer + if (ent->client->ps.legsTimer) { + cs->castScriptStatus.scriptNoMoveTime = level.time + 100; + ent->client->ps.legsTimer = 0; // allow legs to move us + } + if (cs->castScriptStatus.scriptNoMoveTime < level.time) { + trap_EA_MoveForward(cs->entityNum); + } + } +*/ + return NULL; +} + +char *AIFunc_Heinrich_SwordKnockbackStart( cast_state_t *cs ) { + gentity_t *ent = &g_entities[cs->entityNum]; +// gentity_t *enemy = &g_entities[cs->enemyNum]; + + cs->aiFlags |= AIFL_SPECIAL_FUNC; + // sound + G_AddEvent( ent, EV_GENERAL_SOUND, heinrichSoundIndex[HEINRICH_SWORDKNOCKBACK_START] ); + // weapon sound + G_AddEvent( ent, EV_GENERAL_SOUND, heinrichSoundIndex[HEINRICH_SWORDKNOCKBACK_WEAPON] ); + // face them + AICast_AimAtEnemy( cs ); + // clear flags + cs->aiFlags &= ~( AIFL_MISCFLAG1 | AIFL_MISCFLAG2 ); + // play the anim + if ( rand() % 2 ) { + BG_PlayAnimName( &ent->client->ps, "attack2", ANIM_BP_BOTH, qtrue, qfalse, qtrue ); + } else { + BG_PlayAnimName( &ent->client->ps, "attack3", ANIM_BP_BOTH, qtrue, qfalse, qtrue ); + } + // start the func + cs->aifunc = AIFunc_Heinrich_SwordKnockback; + return "AIFunc_Heinrich_SwordKnockback"; +} + +#define HEINRICH_SLASH_DELAY ANIMLENGTH( 17,25 ) +#define HEINRICH_SLASH_RANGE 140 +#define HEINRICH_SLASH_DAMAGE ( 30 + rand() % 15 ) + +char *AIFunc_Heinrich_SwordSideSlash( cast_state_t *cs ) { + gentity_t *ent = &g_entities[cs->entityNum]; + trace_t *tr; + vec3_t right, left; + float enemyDist; + aicast_predictmove_t move; + vec3_t vec; + cast_state_t *ecs; + + cs->aiFlags |= AIFL_SPECIAL_FUNC; + + if ( cs->enemyNum < 0 ) { + if ( ent->client->ps.torsoTimer ) { + return NULL; + } + return AIFunc_DefaultStart( cs ); + } + + ecs = AICast_GetCastState( cs->enemyNum ); + + if ( ent->client->ps.torsoTimer < 500 ) { + if ( !ent->client->ps.legsTimer ) { + trap_EA_MoveForward( cs->entityNum ); + } + ent->client->ps.legsTimer = 0; + ent->client->ps.torsoTimer = 0; + cs->castScriptStatus.scriptNoMoveTime = 0; + AICast_Heinrich_Taunt( cs ); + return AIFunc_BattleChaseStart( cs ); + } + + // time for the melee? + if ( cs->enemyNum >= 0 && !( cs->aiFlags & AIFL_MISCFLAG1 ) ) { + // face them + AICast_AimAtEnemy( cs ); + // keep checking for impact status + tr = CheckMeleeAttack( ent, HEINRICH_SLASH_RANGE, qfalse ); + // ready for damage? + if ( cs->thinkFuncChangeTime < level.time - HEINRICH_SLASH_DELAY ) { + cs->aiFlags |= AIFL_MISCFLAG1; + // do melee damage + if ( tr && ( tr->entityNum == cs->enemyNum ) ) { + AngleVectors( cs->viewangles, NULL, right, NULL ); + VectorNegate( right, left ); + G_Damage( &g_entities[tr->entityNum], ent, ent, left, tr->endpos, HEINRICH_SLASH_DAMAGE, 0, MOD_GAUNTLET ); + // sound + G_AddEvent( ent, EV_GENERAL_SOUND, heinrichSoundIndex[HEINRICH_SWORDIMPACT] ); + // throw them in direction of impact + left[2] = 0.5; + VectorMA( g_entities[cs->enemyNum].client->ps.velocity, 400, left, g_entities[cs->enemyNum].client->ps.velocity ); + } + } + } + + // if they are outside range, move forward + AICast_PredictMovement( ecs, 2, 0.3, &move, &g_entities[cs->enemyNum].client->pers.cmd, -1 ); + VectorSubtract( move.endpos, cs->bs->origin, vec ); + vec[2] = 0; + enemyDist = VectorLength( vec ); + enemyDist -= g_entities[cs->enemyNum].r.maxs[0]; + enemyDist -= ent->r.maxs[0]; + if ( enemyDist > 30 ) { // we can get closer + if ( ent->client->ps.legsTimer ) { + cs->castScriptStatus.scriptNoMoveTime = level.time + 100; + ent->client->ps.legsTimer = 0; // allow legs to move us + } + if ( cs->castScriptStatus.scriptNoMoveTime < level.time ) { + trap_EA_MoveForward( cs->entityNum ); + } + } + + return NULL; +} + +char *AIFunc_Heinrich_SwordSideSlashStart( cast_state_t *cs ) { + gentity_t *ent = &g_entities[cs->entityNum]; + + cs->aiFlags |= AIFL_SPECIAL_FUNC; + // sound + G_AddEvent( ent, EV_GENERAL_SOUND, heinrichSoundIndex[HEINRICH_SWORDSIDESLASH_START] ); + // weapon sound + G_AddEvent( ent, EV_GENERAL_SOUND, heinrichSoundIndex[HEINRICH_SWORDSIDESLASH_WEAPON] ); + // face them + AICast_AimAtEnemy( cs ); + // clear flags + cs->aiFlags &= ~( AIFL_MISCFLAG1 | AIFL_MISCFLAG2 ); + // play the anim + BG_PlayAnimName( &ent->client->ps, "attack8", ANIM_BP_BOTH, qtrue, qfalse, qtrue ); + // start the func + cs->aifunc = AIFunc_Heinrich_SwordSideSlash; + return "AIFunc_Heinrich_SwordSideSlash"; +} + +#define HEINRICH_STOMP_DELAY 900 +#define HEINRICH_STOMP_RANGE 1024.0 +#define HEINRICH_STOMP_VELOCITY_Z 420 +#define HEINRICH_STOMP_DAMAGE 35 + +char *AIFunc_Heinrich_Earthquake( cast_state_t *cs ) { + gentity_t *ent = &g_entities[cs->entityNum]; + gentity_t *enemy; + cast_state_t *ecs; + vec3_t enemyVec; + float enemyDist, scale; + trace_t *tr; + + cs->aiFlags |= AIFL_SPECIAL_FUNC; + + if ( cs->enemyNum < 0 ) { + if ( !ent->client->ps.torsoTimer ) { + return AIFunc_DefaultStart( cs ); + } + return NULL; + } + + enemy = &g_entities[cs->enemyNum]; + ecs = AICast_GetCastState( cs->enemyNum ); + + VectorMA( enemy->r.currentOrigin, HEINRICH_STOMP_DELAY, enemy->client->ps.velocity, enemyVec ); + enemyDist = VectorDistance( ent->r.currentOrigin, enemyVec ); + + if ( ent->client->ps.torsoTimer < 500 ) { + int rnd; + aicast_predictmove_t move; + vec3_t vec; + + AICast_PredictMovement( ecs, 2, 0.5, &move, &g_entities[cs->enemyNum].client->pers.cmd, -1 ); + VectorSubtract( move.endpos, cs->bs->origin, vec ); + vec[2] = 0; + enemyDist = VectorLength( vec ); + enemyDist -= g_entities[cs->enemyNum].r.maxs[0]; + enemyDist -= ent->r.maxs[0]; + // + if ( enemyDist < 140 ) { + // combo attack + rnd = rand() % 3; + switch ( rnd ) { + case 0: + return AIFunc_Heinrich_SwordSideSlashStart( cs ); + case 1: + return AIFunc_Heinrich_SwordKnockbackStart( cs ); + case 2: + return AIFunc_Heinrich_SwordLungeStart( cs ); + } + } else { // back to roaming + ent->client->ps.legsTimer = 0; + ent->client->ps.torsoTimer = 0; + cs->castScriptStatus.scriptNoMoveTime = 0; + AICast_Heinrich_Taunt( cs ); + return AIFunc_DefaultStart( cs ); + } + } + + // time for the thump? + if ( !( cs->aiFlags & AIFL_MISCFLAG1 ) ) { + // face them + AICast_AimAtEnemy( cs ); + // ready for damage? + if ( cs->thinkFuncChangeTime < level.time - HEINRICH_STOMP_DELAY ) { + cs->aiFlags |= AIFL_MISCFLAG1; + // play the stomp sound + G_AddEvent( ent, EV_GENERAL_SOUND, G_SoundIndex( aiDefaults[ent->aiCharacter].soundScripts[ORDERSDENYSOUNDSCRIPT] ) ); + // check for striking the player + tr = CheckMeleeAttack( ent, 70, qfalse ); + // do melee damage + if ( tr && ( tr->entityNum == cs->enemyNum ) ) { + G_Damage( &g_entities[tr->entityNum], ent, ent, vec3_origin, tr->endpos, HEINRICH_STOMP_DAMAGE, 0, MOD_GAUNTLET ); + } + // call the debris trigger + AICast_ScriptEvent( cs, "trigger", "quake" ); + } + } + + enemyDist = Distance( enemy->s.pos.trBase, ent->s.pos.trBase ); + + // do the earthquake effects + if ( cs->thinkFuncChangeTime < level.time - HEINRICH_STOMP_DELAY ) { + // throw the player into the air, if they are on the ground + if ( ( enemy->s.groundEntityNum != ENTITYNUM_NONE ) && enemyDist < HEINRICH_STOMP_RANGE ) { + scale = 0.5 + 0.5 * ( (float)ent->client->ps.torsoTimer / 1000.0 ); + if ( scale > 1.0 ) { + scale = 1.0; + } + VectorSubtract( ent->s.pos.trBase, enemy->s.pos.trBase, enemyVec ); + VectorScale( enemyVec, 2.0 * ( 0.6 + 0.5 * random() ) * scale * ( 0.6 + 0.6 * ( 1.0 - ( enemyDist / HEINRICH_STOMP_RANGE ) ) ), enemyVec ); + enemyVec[2] = scale * HEINRICH_STOMP_VELOCITY_Z * ( 1.0 - 0.5 * ( enemyDist / HEINRICH_STOMP_RANGE ) ); + // bounce the player using this velocity + VectorAdd( enemy->client->ps.velocity, enemyVec, enemy->client->ps.velocity ); + } + } + + return NULL; +} + +char *AIFunc_Heinrich_MeleeStart( cast_state_t *cs ) { + gentity_t *ent = &g_entities[cs->entityNum]; + gentity_t *enemy = &g_entities[cs->enemyNum]; + int rnd; + static int lastStomp; + + if ( cs->enemyNum < 0 ) { + return NULL; + } + + // record weapon fire + cs->weaponFireTimes[cs->weaponNum] = level.time; + // face them + AICast_AimAtEnemy( cs ); + // clear flags + cs->aiFlags &= ~( AIFL_MISCFLAG1 | AIFL_MISCFLAG2 ); + // decide which attack to use + if ( VectorDistance( ent->r.currentOrigin, enemy->r.currentOrigin ) < 60 ) { + rnd = 0; // sword slash up close + } else if ( VectorDistance( ent->r.currentOrigin, enemy->r.currentOrigin ) >= HEINRICH_SLASH_RANGE ) { + rnd = 1; // too far away, stomp + } else { + // pick at random + rnd = rand() % 2; + } + // + switch ( rnd ) { + case 0: + { + int rnd = rand() % 3; + switch ( rnd ) { + case 0: + return AIFunc_Heinrich_SwordSideSlashStart( cs ); + case 1: + return AIFunc_Heinrich_SwordKnockbackStart( cs ); + case 2: + return AIFunc_Heinrich_SwordLungeStart( cs ); + } + } + case 1: + // dont do stomp too often + if ( lastStomp > level.time - 12000 ) { // plenty of time to let debris disappear + return NULL; + } + lastStomp = level.time; + cs->aiFlags |= AIFL_SPECIAL_FUNC; + // sound + G_AddEvent( ent, EV_GENERAL_SOUND, heinrichSoundIndex[HEINRICH_EARTHQUAKE_START] ); + // play the anim + BG_PlayAnimName( &ent->client->ps, "attack7", ANIM_BP_BOTH, qtrue, qfalse, qtrue ); + // start the func + cs->aifunc = AIFunc_Heinrich_Earthquake; + return "AIFunc_Heinrich_Earthquake"; + } + // shutup compiler + return NULL; +} + +#define HEINRICH_RAISEDEAD_DELAY 1200 +#define HEINRICH_RAISEDEAD_COUNT 3 +int lastRaise; + +char *AIFunc_Heinrich_RaiseDead( cast_state_t *cs ) { + int i; + gentity_t *ent = &g_entities[cs->entityNum]; + gentity_t *enemy = &g_entities[cs->enemyNum]; + gentity_t *trav, *closest; + float closestDist, dist; + // + cs->aiFlags |= AIFL_SPECIAL_FUNC; + if ( cs->enemyNum < 0 ) { + if ( !ent->client->ps.torsoTimer ) { + return AIFunc_DefaultStart( cs ); + } + return NULL; + } + // + // record weapon fire + cs->weaponFireTimes[cs->weaponNum] = level.time; + // + if ( !ent->client->ps.torsoTimer ) { + return AIFunc_DefaultStart( cs ); + } + if ( ent->count2 && lastRaise < level.time - HEINRICH_RAISEDEAD_DELAY ) { + lastRaise = level.time; + // summons the closest warrior + closest = NULL; + closestDist = 0; // shutup the compiler + for ( i = 0, trav = g_entities; i < level.maxclients; i++, trav++ ) { + if ( !trav->inuse ) { + continue; + } + if ( !trav->aiInactive ) { + continue; + } + if ( trav->aiCharacter != AICHAR_WARZOMBIE ) { + continue; + } + dist = VectorDistance( trav->s.pos.trBase, enemy->r.currentOrigin ); + if ( !closest || dist < closestDist ) { + closest = trav; + closestDist = dist; + } + } + // + if ( closest ) { + closest->AIScript_AlertEntity( closest ); + // make them aware of the player + AICast_UpdateVisibility( closest, enemy, qtrue, qtrue ); + // reduce the count + ent->count2--; + } + } + // + return NULL; +} + +char *AIFunc_Heinrich_RaiseDeadStart( cast_state_t *cs ) { + int i, cnt, free; + gentity_t *ent = &g_entities[cs->entityNum]; +// gentity_t *enemy = &g_entities[cs->enemyNum]; + gentity_t *trav, *spirits; + float circleDist; + // + // count the number of active warriors + cnt = 0; + free = 0; + for ( i = 0, trav = g_entities; i < level.maxclients; i++, trav++ ) { + if ( !trav->inuse ) { + continue; + } + if ( trav->aiCharacter != AICHAR_WARZOMBIE ) { + continue; + } + if ( trav->aiInactive ) { + free++; + continue; + } + if ( trav->health <= 0 ) { + continue; + } + cnt++; + } + // + if ( cnt < HEINRICH_RAISEDEAD_COUNT && free ) { // need a new one + cs->aiFlags &= ~AIFL_MISCFLAG1; + ent->count2 = HEINRICH_RAISEDEAD_COUNT - cnt; + lastRaise = level.time; + cs->aiFlags |= AIFL_SPECIAL_FUNC; + // start the animation + BG_PlayAnimName( &ent->client->ps, "attack4", ANIM_BP_BOTH, qtrue, qfalse, qtrue ); + // play the sound + G_AddEvent( ent, EV_GENERAL_SOUND, heinrichSoundIndex[HEINRICH_RAISEDEAD_START] ); + // start the func + cs->aifunc = AIFunc_Heinrich_RaiseDead; + return "AIFunc_Heinrich_RaiseDead"; + } + // enable all the spirit spawners + trav = NULL; + // TTimo: gcc: suggest () around assignment used as truth value + while ( ( trav = G_Find( trav, FOFS( classname ), "func_bats" ) ) ) { + if ( !trav->active && trav->spawnflags & 4 ) { + trav->active = 1; // let them release spirits now + } + } + // is the player outside the circle? + trav = NULL; + // TTimo: gcc: suggest () around assignment used as truth value + while ( ( trav = G_Find( trav, FOFS( classname ), "func_bats" ) ) ) { + if ( trav->spawnflags & 4 ) { + spirits = trav; + circleDist = trav->radius; + trav = G_Find( NULL, FOFS( targetname ), trav->target ); + if ( trav ) { + if ( VectorDistance( g_entities[0].s.pos.trBase, trav->s.origin ) > circleDist ) { + cs->aiFlags &= ~AIFL_MISCFLAG1; + ent->count2 = 0; + cs->aiFlags |= AIFL_SPECIAL_FUNC; + // start the animation + BG_PlayAnimName( &ent->client->ps, "attack4", ANIM_BP_BOTH, qtrue, qfalse, qtrue ); + // play the sound + G_AddEvent( ent, EV_GENERAL_SOUND, heinrichSoundIndex[HEINRICH_RAISEDEAD_START] ); + // start the func + cs->aifunc = AIFunc_Heinrich_RaiseDead; + return "AIFunc_Heinrich_RaiseDead"; + } + } + break; + } + } + // + return NULL; +} + +char *AIFunc_Heinrich_SpawnSpiritsStart( cast_state_t *cs ) { + gentity_t *ent = &g_entities[cs->entityNum]; + gentity_t *trav, *spirits; + float circleDist; + // + // enable all the spirit spawners + trav = NULL; + // TTimo: gcc: suggest () around assignment used as truth value + while ( ( trav = G_Find( trav, FOFS( classname ), "func_bats" ) ) ) { + if ( !trav->active && trav->spawnflags & 4 ) { + trav->active = 1; // let them release spirits now + } + } + // is the player outside the circle? + trav = NULL; + // TTimo: gcc: suggest () around assignment used as truth value + while ( ( trav = G_Find( trav, FOFS( classname ), "func_bats" ) ) ) { + if ( trav->spawnflags & 4 ) { + spirits = trav; + circleDist = trav->radius; + trav = G_Find( NULL, FOFS( targetname ), trav->target ); + if ( trav ) { + if ( VectorDistance( g_entities[0].s.pos.trBase, trav->s.origin ) > circleDist ) { + cs->aiFlags &= ~AIFL_MISCFLAG1; + ent->count2 = 0; + cs->aiFlags |= AIFL_SPECIAL_FUNC; + // start the animation + BG_PlayAnimName( &ent->client->ps, "attack4", ANIM_BP_BOTH, qtrue, qfalse, qtrue ); + // play the sound + G_AddEvent( ent, EV_GENERAL_SOUND, heinrichSoundIndex[HEINRICH_RAISEDEAD_START] ); + // start the func + cs->aifunc = AIFunc_Heinrich_RaiseDead; // just do raise dead, without raising any warriors + return "AIFunc_Heinrich_RaiseDead"; + } + } + break; + } + } + // + return NULL; +} \ No newline at end of file diff --git a/Projects/Android/jni/rtcw/src/game/ai_cast_funcs.c b/Projects/Android/jni/rtcw/src/game/ai_cast_funcs.c new file mode 100644 index 0000000..c581f22 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/game/ai_cast_funcs.c @@ -0,0 +1,5137 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +/* + * name: ai_cast_funcs.c + * + * desc: Wolfenstein AI Character Decision Making + * +*/ + + +#include "../game/g_local.h" +#include "../game/q_shared.h" +#include "../game/botlib.h" //bot lib interface +#include "../game/be_aas.h" +#include "../game/be_ea.h" +#include "../game/be_ai_gen.h" +#include "../game/be_ai_goal.h" +#include "../game/be_ai_move.h" +#include "../botai/botai.h" //bot ai interface + +#include "ai_cast.h" + +/* +This file contains the generic thinking states for the characters. + +Different types of movement or behaviour will be represented by +a seperate thinking function, which may or may not pass control +over to a new behaviour function. + +If control is passed onto a new function, the string name of the +current function is returned, mostly for debugging purposes. + +!!! NOTE: control must not be passed to a new AI func from outside of +this file. A new AI func must only be called from within another AI func. + +This gives us the ability to keep all code related to sections of AI +self-contained, so adding new features to the AI will be less likely to +step on other areas of AI. +*/ + +static int enemies[MAX_CLIENTS], numEnemies; + +// this is used to prevent try/abort/try/abort/etc grenade flush behaviour +static int lastGrenadeFlush = 0; + +#define AICAST_LEADERDIST_MAX 240 // try and stay at least this close to them when nothing else to do +#define AICAST_LEADERDIST_MIN 64 // get this close if we have a clear line of sight to them + +char *AIFunc_BattleChase( cast_state_t *cs ); +char *AIFunc_Battle( cast_state_t *cs ); + +static bot_moveresult_t *moveresult; + +/* +============ +AIFunc_Restore() + + restores the last aifunc that was backed up +============ +*/ +char *AIFunc_Restore( cast_state_t *cs ) { + // if the old aifunc was BattleChase, set it back to Battle, in case we have found a good position + if ( cs->oldAifunc == AIFunc_BattleChase ) { + cs->oldAifunc = AIFunc_Battle; + } + cs->aifunc = cs->oldAifunc; + return cs->aifunc( cs ); +} + +/* +============ +AICast_GetRandomViewAngle() +============ +*/ +float AICast_GetRandomViewAngle( cast_state_t *cs, float tracedist ) { + int cnt, passent, contents_mask; + vec3_t vec, dir, start, end; + trace_t trace; + float bestdist, bestyaw; + + cnt = 0; + VectorClear( vec ); + // + VectorCopy( cs->bs->origin, start ); + start[2] += cs->bs->cur_ps.viewheight; + // + passent = cs->entityNum; + contents_mask = CONTENTS_SOLID | CONTENTS_PLAYERCLIP | CONTENTS_WATER | CONTENTS_SLIME; +// contents_mask = CONTENTS_SOLID|CONTENTS_PLAYERCLIP|CONTENTS_WATER; + bestdist = 0; + bestyaw = 0; + // + while ( cnt++ < 4 ) + { + vec[YAW] = random() * 360.0; + // + AngleVectors( vec, dir, NULL, NULL ); + VectorMA( start, tracedist, dir, end ); + // + trap_Trace( &trace, start, NULL, NULL, end, passent, contents_mask ); + // + if ( trace.fraction >= 1 ) { + return vec[YAW]; + } else if ( !bestdist || bestdist < trace.fraction ) { + bestdist = trace.fraction; + bestyaw = vec[YAW]; + } + } + // + if ( bestdist ) { + return bestyaw; + } + // just return their current direction + return cs->ideal_viewangles[YAW]; +} + +/* +============ +AICast_MoveToPos() + + returns a pointer to the moveresult it used to make the move, so we can investigate it + outside of this function +============ +*/ +bot_moveresult_t *AICast_MoveToPos( cast_state_t *cs, vec3_t pos, int entnum ) { + bot_goal_t goal; + vec3_t /*target,*/ dir; + static bot_moveresult_t lmoveresult; + int tfl; + bot_state_t *bs; + float dist; + +//int pretime = Sys_MilliSeconds(); + + moveresult = NULL; + + if ( cs->castScriptStatus.scriptNoMoveTime > level.time ) { + return NULL; + } + if ( cs->pauseTime > level.time ) { + return NULL; + } + // + bs = cs->bs; + tfl = cs->travelflags; + //if in lava or slime the bot should be able to get out + if ( BotInLava( bs ) ) { + tfl |= TFL_LAVA; + } + if ( BotInSlime( bs ) ) { + tfl |= TFL_SLIME; + } + // + //create the chase goal + memset( &goal, 0, sizeof( goal ) ); + goal.entitynum = entnum; + if ( entnum >= 0 && entnum < level.maxclients && caststates[entnum].lastValidAreaTime[cs->aasWorldIndex] > level.time - 100 ) { + goal.areanum = caststates[entnum].lastValidAreaNum[cs->aasWorldIndex]; + } else { + goal.areanum = BotPointAreaNum( pos ); + if ( entnum >= 0 && entnum < level.maxclients ) { + if ( !goal.areanum ) { + // use the last valid area + goal.areanum = caststates[entnum].lastValidAreaNum[cs->aasWorldIndex]; + } + } + } + VectorCopy( pos, goal.origin ); + VectorSet( goal.mins, -8, -8, -8 ); + VectorSet( goal.maxs, 8, 8, 8 ); + if ( entnum > -1 && entnum == cs->followEntity && !cs->followSlowApproach ) { + goal.flags |= GFL_NOSLOWAPPROACH; // just speed right passed it + } + // + // debugging, show the route + if ( aicast_debug.integer == 2 && ( g_entities[cs->entityNum].aiName && !strcmp( aicast_debugname.string, g_entities[cs->entityNum].aiName ) ) ) { + trap_AAS_RT_ShowRoute( cs->bs->origin, cs->bs->areanum, goal.areanum ); + } + // + //initialize the movement state + BotSetupForMovement( bs ); + //if this is a slow moving creature, don't use avoidreach + if ( cs->attributes[RUNNING_SPEED] < 100 ) { + //reset the avoid reach, otherwise bot is stuck in current area + trap_BotResetAvoidReach( bs->ms ); + } else if ( !VectorCompare( cs->lastMoveToPosGoalOrg, pos ) ) { + //reset the avoid reach, otherwise bot is stuck in current area + trap_BotResetAvoidReach( bs->ms ); + VectorCopy( pos, cs->lastMoveToPosGoalOrg ); + } + //move towards the goal + if ( !( cs->aiFlags & AIFL_EXPLICIT_ROUTING ) || ( entnum < 0 ) || Q_strcasecmp( g_entities[entnum].classname, "ai_marker" ) ) { + // use AAS routing + trap_BotMoveToGoal( &lmoveresult, bs->ms, &goal, tfl ); + //if the movement failed + if ( lmoveresult.failure ) { + + //reset the avoid reach, otherwise bot is stuck in current area + trap_BotResetAvoidReach( bs->ms ); + //BotAI_Print(PRT_MESSAGE, "movement failure %d\n", lmoveresult.traveltype); + // clear all movement + trap_EA_Move( cs->entityNum, vec3_origin, 0 ); + + } else { + + if ( entnum > 0 && goal.areanum && entnum >= 0 && entnum < level.maxclients ) { // NOTE: dont do this for the player + // save this destination point + caststates[entnum].lastValidAreaNum[cs->aasWorldIndex] = goal.areanum; + caststates[entnum].lastValidAreaTime[cs->aasWorldIndex] = level.time; + } + + if ( lmoveresult.flags & ( MOVERESULT_MOVEMENTVIEW | MOVERESULT_SWIMVIEW ) ) { + VectorCopy( lmoveresult.ideal_viewangles, cs->ideal_viewangles ); + VectorCopy( cs->ideal_viewangles, cs->viewlock_viewangles ); + cs->aiFlags |= AIFL_VIEWLOCKED; + } else if ( !( cs->bFlags & BFL_ATTACKED ) ) { // if we are attacking, don't change angles + bot_input_t bi; + + trap_EA_GetInput( bs->client, 0.1, &bi ); + if ( VectorLength( lmoveresult.movedir ) < 0.5 ) { + VectorSubtract( goal.origin, bs->origin, dir ); + vectoangles( dir, cs->ideal_viewangles ); + } else { + // use our velocity if we are moving + if ( VectorNormalize2( cs->bs->cur_ps.velocity, dir ) > 1 ) { + vectoangles( dir, cs->ideal_viewangles ); + } else { + vectoangles( lmoveresult.movedir, cs->ideal_viewangles ); + } + } + cs->ideal_viewangles[2] *= 0.5; + // look towards our future direction (like looking around a corner as we approach it) + if ( !( cs->aiFlags & AIFL_WALKFORWARD ) && ( lmoveresult.flags & MOVERESULT_FUTUREVIEW ) ) { + if ( AngleDifference( cs->ideal_viewangles[1], lmoveresult.ideal_viewangles[1] ) > 45 ) { + cs->ideal_viewangles[1] -= 45; + } else if ( AngleDifference( cs->ideal_viewangles[1], lmoveresult.ideal_viewangles[1] ) < -45 ) { + cs->ideal_viewangles[1] += 45; + } else { + cs->ideal_viewangles[1] = lmoveresult.ideal_viewangles[1]; + } + cs->ideal_viewangles[1] = AngleNormalize360( cs->ideal_viewangles[1] ); + cs->ideal_viewangles[0] = lmoveresult.ideal_viewangles[0]; + cs->ideal_viewangles[0] = 0.5 * AngleNormalize180( cs->ideal_viewangles[0] ); + } + } + + } + + } else { // manual routing towards markers + + VectorSubtract( pos, cs->bs->origin, dir ); + if ( ( dist = VectorNormalize( dir ) ) < 64 ) { + trap_EA_Move( cs->entityNum, dir, 100.0 + 300.0 * ( dist / 64.0 ) ); + } else { + trap_EA_Move( cs->entityNum, dir, 400 ); + } + + // look towards the marker also + vectoangles( dir, cs->ideal_viewangles ); + cs->ideal_viewangles[2] *= 0.5; + + } + // this must go last so we face the direction we avoid move + AICast_Blocked( cs, &lmoveresult, qfalse, &goal ); + +//G_Printf("MoveToPos: %i ms\n", -pretime + Sys_MilliSeconds() ); +/* +// debug, print movement info +if(0) // (SA) added to hide the print +{ +bot_input_t bi; + +trap_EA_GetInput(cs->bs->client, (float) level.time / 1000, &bi); +G_Printf("spd: %i\n", (int)bi.speed ); +} +*/ + return ( moveresult = &lmoveresult ); +} + +/* +============ +AICast_SpeedScaleForDistance() +============ +*/ +float AICast_SpeedScaleForDistance( cast_state_t *cs, float startdist, float idealDist ) { +#define PREDICT_TIME_WALK 0.2 +#define PREDICT_TIME_CROUCH 0.2 +#define PREDICT_TIME_RUN 0.3 + float speed, dist; + + dist = startdist - idealDist; + if ( dist < 1 ) { + dist = 1; + } + + // if walking + if ( cs->movestate == MS_WALK ) { + speed = cs->attributes[WALKING_SPEED]; + if ( speed * PREDICT_TIME_WALK > dist ) { + return 0.2 + 0.8 * ( dist / ( speed * PREDICT_TIME_WALK ) ); + } else { + return 1.0; + } + } else + // if crouching + if ( cs->movestate == MS_CROUCH || cs->attackcrouch_time > level.time ) { + speed = cs->attributes[CROUCHING_SPEED]; + if ( speed * PREDICT_TIME_CROUCH > dist ) { + return 0.3 + 0.7 * ( dist / ( speed * PREDICT_TIME_CROUCH ) ); + } else { + return 1.0; + } + } else + // running + { + speed = cs->attributes[RUNNING_SPEED]; + if ( speed * PREDICT_TIME_RUN > dist ) { + return 0.2 + 0.8 * ( dist / ( speed * PREDICT_TIME_RUN ) ); + } else { + return 1.0; + } + } +} + +/* +============ +AICast_SpecialFunc +============ +*/ +void AICast_SpecialFunc( cast_state_t *cs ) { + gentity_t *ent = &g_entities[cs->entityNum]; + gentity_t *enemy = NULL; + + if ( cs->enemyNum >= 0 ) { + enemy = &g_entities[cs->enemyNum]; + } + + switch ( cs->aiCharacter ) { + case AICHAR_WARZOMBIE: + // disable defense unless we want it + ent->flags &= ~FL_DEFENSE_CROUCH; + // if we are pursuing the player from a distance, use our "crouch moving defense" + if ( ( enemy ) + && ( cs->vislist[cs->enemyNum].real_visible_timestamp > level.time - 5000 ) + && ( Distance( cs->bs->origin, enemy->s.pos.trBase ) > 200 ) + && ( Distance( cs->bs->origin, enemy->s.pos.trBase ) < 600 ) + && ( cs->bs->cur_ps.groundEntityNum != ENTITYNUM_NONE ) + //&& (infront( ent, enemy )) + && ( infront( enemy, ent ) ) ) { + // crouch + trap_EA_Crouch( cs->entityNum ); + // enable defense pose + ent->flags |= FL_DEFENSE_CROUCH; + } + break; + case AICHAR_HELGA: + // if she has recently finished a spirit attack, go into charge mode + if ( ( cs->weaponFireTimes[WP_MONSTER_ATTACK2] && ( cs->weaponFireTimes[WP_MONSTER_ATTACK2] > level.time - 12000 ) ) || + ( cs->weaponFireTimes[WP_MONSTER_ATTACK1] && ( cs->weaponFireTimes[WP_MONSTER_ATTACK1] > level.time - 6000 ) ) ) { + BG_UpdateConditionValue( cs->entityNum, ANIM_COND_CHARGING, 1, qfalse ); + cs->actionFlags &= ~CASTACTION_WALK; + } else { // not charging + BG_UpdateConditionValue( cs->entityNum, ANIM_COND_CHARGING, 0, qfalse ); + } + // + if ( ent->health <= 0 && ent->takedamage ) { + if ( ent->client->ps.torsoTimer < 500 ) { + // blow up + GibEntity( ent, 0 ); + ent->takedamage = qfalse; + ent->r.contents = 0; + ent->health = GIB_HEALTH - 1; + } + } + break; + case AICHAR_HEINRICH: + if ( ( ent->health <= 0.25 * cs->attributes[STARTING_HEALTH] ) + || ( cs->weaponFireTimes[WP_MONSTER_ATTACK1] > level.time - 6000 ) // walk for period after attack + || ( cs->weaponFireTimes[WP_MONSTER_ATTACK1] % 8000 < 3000 ) ) { // dont run constantly + cs->actionFlags |= CASTACTION_WALK; + } else { // charging + cs->actionFlags &= ~CASTACTION_WALK; + } + // allow running while attacking + if ( ent->client->ps.torsoTimer && !ent->client->ps.legsTimer ) { + cs->actionFlags &= ~CASTACTION_WALK; + } + // + if ( ent->health <= 0 && ent->takedamage ) { + if ( ent->client->ps.torsoTimer < 500 ) { + // blow up + GibEntity( ent, 0 ); + ent->takedamage = qfalse; + ent->r.contents = 0; + ent->health = GIB_HEALTH - 1; + } + // blow up other warriors left around + if ( !ent->takedamage || ( ent->count2 < level.time && ent->client->ps.torsoTimer < 4000 ) ) { + int i; + gentity_t *trav; + for ( i = 0, trav = g_entities; i < level.maxclients; i++, trav++ ) { + if ( !trav->inuse ) { + continue; + } + if ( trav->aiCharacter != AICHAR_WARZOMBIE ) { + continue; + } + if ( trav->aiInactive ) { + continue; + } + if ( trav->health <= 0 ) { + continue; + } + // blow it up, set some delay + G_Damage( trav, ent, ent, NULL, NULL, 99999, 0, MOD_CRUSH ); + if ( ent->takedamage ) { + ent->count2 = level.time + 200 + rand() % 1500; + } + } + } + } + break; + case AICHAR_ZOMBIE: + if ( COM_BitCheck( cs->bs->cur_ps.weapons, WP_MONSTER_ATTACK1 ) ) { // flaming zombie, run + BG_UpdateConditionValue( cs->entityNum, ANIM_COND_CHARGING, 1, qfalse ); + } + break; + } +} + +/* +============ +AIFunc_Idle() + + The cast AI is standing around, contemplating the meaning of life +============ +*/ +char *AIFunc_Idle( cast_state_t *cs ) { + gentity_t *ent = &g_entities[cs->entityNum]; + + // we are in an idle state, looking for something to do + + // + // do we need to avoid a danger? + if ( cs->dangerEntityValidTime >= level.time ) { + if ( !AICast_GetTakeCoverPos( cs, cs->dangerEntity, cs->dangerEntityPos, cs->takeCoverPos ) ) { + // shit?? + } + // go to a position that cannot be seen from the dangerPos + cs->takeCoverTime = cs->dangerEntityValidTime + 1000; + cs->attackcrouch_time = 0; + return AIFunc_AvoidDangerStart( cs ); + } + // + // are we waiting for a door? + if ( cs->doorMarkerTime > level.time - 100 ) { + return AIFunc_DoorMarkerStart( cs, cs->doorMarkerDoor, cs->doorMarkerNum ); + } + // + // do we need to go to our leader? + if ( cs->leaderNum >= 0 && Distance( cs->bs->origin, g_entities[cs->leaderNum].r.currentOrigin ) > MAX_LEADER_DIST ) { + return AIFunc_ChaseGoalStart( cs, cs->leaderNum, AICAST_LEADERDIST_MAX, qtrue ); + } + // + // look for things we should attack + numEnemies = AICast_ScanForEnemies( cs, enemies ); + if ( numEnemies == -1 ) { // query mode + return NULL; + } else if ( numEnemies == -2 ) { // inspection may be required + char *retval; + // TTimo: gcc: suggest () around assignment used as truth value + if ( ( retval = AIFunc_InspectFriendlyStart( cs, enemies[0] ) ) ) { + return retval; + } + } else if ( numEnemies == -3 ) { // bullet impact + if ( cs->aiState < AISTATE_COMBAT ) { + return AIFunc_InspectBulletImpactStart( cs ); + } + } else if ( numEnemies == -4 ) { // audible event + if ( cs->aiState < AISTATE_COMBAT ) { + return AIFunc_InspectAudibleEventStart( cs, cs->audibleEventEnt ); + } + } else if ( numEnemies > 0 ) { + int i; + + cs->enemyNum = -1; + // choose an enemy + for ( i = 0; i < numEnemies; i++ ) { + if ( Distance( cs->bs->origin, cs->vislist[enemies[i]].visible_pos ) > 16 ) { // if we are really close to the last place we saw them, no point trying to attack, since we'll just end up back here + if ( cs->enemyNum < 0 ) { + cs->enemyNum = enemies[i]; + } else if ( AICast_CheckAttack( cs, enemies[i], qfalse ) ) { + cs->enemyNum = enemies[i]; + return AIFunc_BattleStart( cs ); + } + } + } + if ( cs->enemyNum >= 0 ) { + if ( ( ( cs->leaderNum < 0 ) || ( cs->thinkFuncChangeTime < level.time - 3000 ) ) && AICast_WantsToChase( cs ) ) { // don't leave our leader as soon as we get to them + return AIFunc_BattleStart( cs ); + } else if ( AICast_EntityVisible( AICast_GetCastState( cs->enemyNum ), cs->entityNum, qtrue ) || AICast_CheckAttack( AICast_GetCastState( cs->enemyNum ), cs->entityNum, qfalse ) ) { + // if we are tactical enough, look for a hiding spot + if ( !( cs->leaderNum >= 0 ) && cs->attributes[TACTICAL] > 0.4 && cs->attributes[AGGRESSION] < 1.0 ) { + // they can see us, and we want to hide from them + if ( AICast_GetTakeCoverPos( cs, cs->enemyNum, cs->vislist[cs->enemyNum].visible_pos, cs->takeCoverPos ) ) { + // go to a position that cannot be seen from the last place we saw the enemy, and wait there for some time + cs->takeCoverTime = level.time + 2000 + rand() % 3000; + return AIFunc_BattleTakeCoverStart( cs ); + } + } + // attack them if nothing else to do, since they can attack us here + return AIFunc_BattleStart( cs ); + } else if ( cs->leaderNum < 0 ) { // we should pursue if no leader, and not wanting to hide + return AIFunc_BattleStart( cs ); + } else { + // they can't see us anyway, so ignore them + cs->lastEnemy = cs->enemyNum; // at least face them if they come to get us + cs->enemyNum = -1; + // crouching makes us look like we are hiding, which is what we are doing + if ( cs->attributes[ATTACK_CROUCH] > 0.5 ) { + cs->attackcrouch_time = level.time + 1000; + } + } + } + } + // + // if we are in combat mode, then we should relax, since we dont have an enemy + if ( cs->aiState >= AISTATE_COMBAT ) { + AICast_StateChange( cs, AISTATE_ALERT ); + } + // + // if we couldn't find anything, see if our previous enemy is still around, if so, go find them + // this is an attempt to prevent guys from running away to hide from something, never to + // be seen again. They shouldn't really "forget" that they are indeed soldiers. + if ( !( cs->leaderNum >= 0 ) && cs->lastEnemy >= 0 && g_entities[cs->lastEnemy].health > 0 && cs->vislist[cs->lastEnemy].real_visible_timestamp < level.time - 5000 && + cs->takeCoverTime < level.time - 5000 ) { + cs->enemyNum = cs->lastEnemy; // just go to the place we last saw them + return AIFunc_BattleStart( cs ); + } + // + // if we've recently been in a fight, keep looking around, so we don't look stupid + if ( cs->lastEnemy >= 0 ) { + // we have been in a battle, so face our enemy in anticipation of their return + if ( ent->aiTeam != AITEAM_ALLIES ) { + vec3_t dir; + // + //VectorSubtract( cs->vislist[cs->lastEnemy].visible_pos, cs->bs->origin, dir ); + // hack, use their real angles, prevent them from looking dumb when the player returns + VectorSubtract( g_entities[cs->lastEnemy].s.pos.trBase, cs->bs->origin, dir ); + if ( VectorLength( dir ) < 1 ) { + cs->ideal_viewangles[PITCH] = 0; + } else { + VectorNormalize( dir ); + vectoangles( dir, cs->ideal_viewangles ); + cs->ideal_viewangles[PITCH] = AngleNormalize180( cs->ideal_viewangles[PITCH] ) * 0.5; + } + } else if ( cs->attributes[TACTICAL] && cs->nextIdleAngleChange < level.time ) { + // wait a second before changing again + if ( ( cs->nextIdleAngleChange + 3000 ) < level.time ) { + + // FIXME: This could be changed to use some AAS sampling, which would: + // + // Given a src area, pick a random dest area which is visible from that area + // and return it's position, which we'd then use to set the next view angles + // + // This would result in more efficient, more realistic behaviour, since they'd + // also use PITCH angles to look at areas above/below them + + cs->idleYaw = AICast_GetRandomViewAngle( cs, 512 ); + + if ( abs( AngleDelta( cs->idleYaw, cs->ideal_viewangles[YAW] ) ) < 45 ) { + cs->nextIdleAngleChange = level.time + 1000 + rand() % 2500; + } else { // do really fast + cs->nextIdleAngleChange = level.time + 500; + } + + // adjust with time + cs->idleYawChange = AngleDelta( cs->idleYaw, cs->ideal_viewangles[YAW] ); + /// ((float)(cs->nextIdleAngleChange - level.time) / 1000.0); + + cs->ideal_viewangles[PITCH] = 0; + } + } else if ( cs->idleYawChange ) { + cs->idleYawChange = AngleDelta( cs->idleYaw, cs->ideal_viewangles[YAW] ); + cs->ideal_viewangles[YAW] = AngleMod( cs->ideal_viewangles[YAW] + ( cs->idleYawChange * cs->bs->thinktime ) ); + } + } + + // check for a movement we should be making + if ( cs->obstructingTime > level.time ) { + AICast_MoveToPos( cs, cs->obstructingPos, -1 ); + if ( cs->movestate != MS_CROUCH ) { + cs->movestate = MS_WALK; + } + cs->movestateType = MSTYPE_TEMPORARY; + } + + // set head look flag if no enemy + if ( cs->enemyNum < 0 && cs->attributes[TACTICAL] >= 0.5 && !( cs->aiFlags & AIFL_NO_HEADLOOK ) ) { + g_entities[cs->entityNum].client->ps.eFlags |= EF_HEADLOOK; + } + + // reload? + AICast_IdleReload( cs ); + + return NULL; +} + +/* +============ +AIFunc_IdleStart() +============ +*/ +char *AIFunc_IdleStart( cast_state_t *cs ) { + g_entities[cs->entityNum].flags &= ~FL_AI_GRENADE_KICK; + // stop following + cs->followEntity = -1; + // if our enemy has just died, inspect the body + if ( cs->enemyNum >= 0 ) { + if ( g_entities[cs->entityNum].aiTeam == AITEAM_NAZI && g_entities[cs->enemyNum].health <= 0 ) { + return AIFunc_InspectBodyStart( cs ); + } else { + cs->enemyNum = -1; + } + } + // make sure we don't avoid any areas when we start again + trap_BotInitAvoidReach( cs->bs->ms ); + + // randomly choose idle animation +//----(SA) try always using the 'casual' stand on spawn and change to crouching one when 'alerted' + if ( cs->aiFlags & AIFL_STAND_IDLE2 ) { +// if (rand()%2 || (cs->lastEnemy < 0 && cs->aiFlags & AIFL_TALKING)) + g_entities[cs->entityNum].client->ps.eFlags |= EF_STAND_IDLE2; +// else +// g_entities[cs->entityNum].client->ps.eFlags &= ~EF_STAND_IDLE2; + } + + cs->aifunc = AIFunc_Idle; + return "AIFunc_Idle"; +} + +/* +============ +AIFunc_InspectFriendly() +============ +*/ +char *AIFunc_InspectFriendly( cast_state_t *cs ) { + gentity_t *followent, *ent; + bot_state_t *bs; + vec3_t destorg; + float dist; + qboolean moved = qfalse; + + ent = &g_entities[cs->entityNum]; + + // if we have an enemy, attack now! + if ( cs->enemyNum >= 0 ) { + return AIFunc_BattleStart( cs ); + } + + cs->followEntity = cs->inspectNum; + cs->followDist = 64; + + cs->scriptPauseTime = level.time + 4000; // wait for at least this long before resuming any scripted walking, etc + + // do we need to avoid a danger? + if ( cs->dangerEntityValidTime >= level.time ) { + if ( AICast_GetTakeCoverPos( cs, cs->dangerEntity, cs->dangerEntityPos, cs->takeCoverPos ) ) { + // go to a position that cannot be seen from the dangerPos + cs->takeCoverTime = cs->dangerEntityValidTime + 1000; + cs->attackcrouch_time = 0; + cs->castScriptStatus.scriptGotoId = -1; + cs->movestate = MS_DEFAULT; + cs->movestateType = MSTYPE_NONE; + return AIFunc_AvoidDangerStart( cs ); + } + } + // + // are we waiting for a door? + if ( cs->doorMarkerTime > level.time - 100 ) { + return AIFunc_DoorMarkerStart( cs, cs->doorMarkerDoor, cs->doorMarkerNum ); + } + + followent = &g_entities[cs->followEntity]; + + // if the entity is not ready yet + if ( !followent->inuse ) { + // if it's a connecting client, wait + if ( cs->followEntity < MAX_CLIENTS + && ( ( followent->client && followent->client->pers.connected == CON_CONNECTING ) + || ( level.time < 3000 ) ) ) { + return AIFunc_ChaseGoalIdleStart( cs, cs->followEntity, cs->followDist ); + } else // stop following it + { + AICast_EndChase( cs ); + return AIFunc_IdleStart( cs ); + } + } + + if ( followent->client ) { + VectorCopy( followent->client->ps.origin, destorg ); + } else { + VectorCopy( followent->r.currentOrigin, destorg ); + } + + // they are ready, are they inside range? FIXME: make configurable + dist = Distance( destorg, cs->bs->origin ); + if ( !( dist < cs->followDist && ( ent->waterlevel || ( cs->bs->cur_ps.groundEntityNum != ENTITYNUM_NONE ) ) ) ) { + // + // go to them + // + bs = cs->bs; + + // set this flag so we know when we;ve just reached them + cs->aiFlags |= AIFL_MISCFLAG1; + + // move straight to them if we can + if ( !moved && + ( cs->bs->cur_ps.groundEntityNum != ENTITYNUM_NONE || g_entities[cs->entityNum].waterlevel > 1 ) ) { + aicast_predictmove_t move; + vec3_t dir; + bot_input_t bi; + usercmd_t ucmd; + trace_t tr; + qboolean simTest = qfalse; + + if ( cs->attributes[RUNNING_SPEED] < 120 ) { + simTest = qtrue; + } + + if ( !simTest ) { + // trace will eliminate most unsuccessful paths + trap_Trace( &tr, cs->bs->origin, NULL /*g_entities[cs->entityNum].r.mins*/, NULL /*g_entities[cs->entityNum].r.maxs*/, followent->r.currentOrigin, cs->entityNum, g_entities[cs->entityNum].clipmask ); + if ( tr.entityNum == cs->followEntity || tr.fraction == 1 ) { + simTest = qtrue; + } + } + + if ( simTest ) { + // try walking straight to them + VectorSubtract( followent->r.currentOrigin, cs->bs->origin, dir ); + VectorNormalize( dir ); + if ( !ent->waterlevel ) { + dir[2] = 0; + } + //trap_EA_Move(cs->entityNum, dir, 400); + trap_EA_GetInput( cs->entityNum, (float) level.time / 1000, &bi ); + VectorCopy( dir, bi.dir ); + bi.speed = 400; + bi.actionflags = 0; + AICast_InputToUserCommand( cs, &bi, &ucmd, bs->cur_ps.delta_angles ); + AICast_PredictMovement( cs, 10, 0.8, &move, &ucmd, cs->followEntity ); + + if ( move.stopevent == PREDICTSTOP_HITENT ) { // success! + trap_EA_Move( cs->entityNum, dir, 400 ); // set the movement + vectoangles( dir, cs->ideal_viewangles ); + cs->ideal_viewangles[2] *= 0.5; + moved = qtrue; + } else { // clear movement + //trap_EA_Move(cs->entityNum, dir, 0); + } + } + } + // + if ( !moved ) { + // use AAS routing + moveresult = AICast_MoveToPos( cs, followent->r.currentOrigin, cs->followEntity ); + // if we cant get there, face the path to the enemy + if ( !moveresult || moveresult->failure ) { + // if we can get a visible target, then face it + if ( !( cs->aiFlags & AIFL_MISCFLAG2 ) ) { + if ( trap_AAS_GetRouteFirstVisPos( followent->r.currentOrigin, cs->bs->origin, cs->travelflags, cs->takeCoverEnemyPos ) ) { + cs->aiFlags |= AIFL_MISCFLAG2; + } else { + // if it failed, just use their origin for now, but keep checking + VectorCopy( followent->r.currentOrigin, cs->takeCoverEnemyPos ); + } + } + VectorSubtract( cs->takeCoverEnemyPos, cs->bs->origin, destorg ); + VectorNormalize( destorg ); + vectoangles( destorg, cs->ideal_viewangles ); + } + } + + // should we slow down? + if ( cs->followDist && cs->followSlowApproach ) { + cs->speedScale = AICast_SpeedScaleForDistance( cs, dist, cs->followDist ); + } +/* + // check for a movement we should be making + if (cs->obstructingTime > level.time) + { + AICast_MoveToPos( cs, cs->obstructingPos, -1 ); + if (cs->movestate != MS_CROUCH) { + cs->movestate = MS_WALK; + } + cs->movestateType = MSTYPE_TEMPORARY; + } +*/ + } else if ( cs->aiFlags & AIFL_MISCFLAG1 ) { + cs->aiFlags &= ~AIFL_MISCFLAG1; + if ( g_entities[cs->inspectNum].health <= 0 ) { + // call a script event + cs->aiFlags &= ~AIFL_DENYACTION; + AICast_ForceScriptEvent( cs, "inspectbodyend", g_entities[cs->inspectNum].aiName ); + if ( cs->aiFlags & AIFL_DENYACTION ) { + // relinguish control back to scripting + return AIFunc_DefaultStart( cs ); + } + } else { // force a visibility update so we get their vis also + AICast_UpdateVisibility( ent, &g_entities[cs->inspectNum], qtrue, qtrue ); + } + } + + { + int numEnemies; + // + // look for things we should attack + numEnemies = AICast_ScanForEnemies( cs, enemies ); + if ( numEnemies == -1 ) { // query mode + return NULL; + } else if ( numEnemies == -2 ) { // inspection + // only override current objective if we are inspecting a dead guy, and the new inspect target is fighting someone + if ( ( g_entities[cs->inspectNum].health <= 0 ) && ( g_entities[enemies[0]].health > 0 ) ) { + return AIFunc_InspectFriendlyStart( cs, enemies[0] ); + } + } + // RF, disabled this, if we are interrupted, scripts might not work right, and anyway, this is only a bullet, not as if it's a dead guy or anything + //else if (numEnemies == -3) // bullet impact + //{ + // if (cs->aiState < AISTATE_COMBAT) { + // return AIFunc_InspectBulletImpactStart( cs ); + // } + //} + else if ( numEnemies > 0 ) { + int i; + + cs->enemyNum = enemies[0]; // just attack the first one + // override with a visible enemy + for ( i = 1; i < numEnemies; i++ ) { + if ( AICast_CheckAttack( cs, enemies[i], qfalse ) ) { + cs->enemyNum = enemies[i]; + break; + } else if ( cs->enemyNum < 0 ) { + cs->lastEnemy = enemies[i]; + } + } + + return AIFunc_BattleStart( cs ); + } + } + + if ( cs->nextIdleAngleChange < level.time ) { + // wait a second before changing again + if ( ( cs->nextIdleAngleChange + 3000 ) < level.time ) { + + // FIXME: This could be changed to use some AAS sampling, which would: + // + // Given a src area, pick a random dest area which is visible from that area + // and return it's position, which we'd then use to set the next view angles + // + // This would result in more efficient, more realistic behaviour, since they'd + // also use PITCH angles to look at areas above/below them + + cs->idleYaw = AICast_GetRandomViewAngle( cs, 512 ); + + if ( abs( AngleDelta( cs->idleYaw, cs->ideal_viewangles[YAW] ) ) < 45 ) { + cs->nextIdleAngleChange = level.time + 1000 + rand() % 2500; + } else { // do really fast + cs->nextIdleAngleChange = level.time + 500; + } + + // adjust with time + cs->idleYawChange = AngleDelta( cs->idleYaw, cs->ideal_viewangles[YAW] ); + /// ((float)(cs->nextIdleAngleChange - level.time) / 1000.0); + + cs->ideal_viewangles[PITCH] = 0; + } + } else if ( cs->idleYawChange ) { + cs->idleYawChange = AngleDelta( cs->idleYaw, cs->ideal_viewangles[YAW] ); + cs->ideal_viewangles[YAW] = AngleMod( cs->ideal_viewangles[YAW] + ( cs->idleYawChange * cs->bs->thinktime ) ); + } + + // set head look flag if no enemy + if ( cs->enemyNum < 0 && cs->attributes[TACTICAL] >= 0.5 && !( cs->aiFlags & AIFL_NO_HEADLOOK ) ) { + g_entities[cs->entityNum].client->ps.eFlags |= EF_HEADLOOK; + } + + // reload? + AICast_IdleReload( cs ); + + return NULL; +} + +/* +============ +AIFunc_InspectFriendlyStart +============ +*/ +char *AIFunc_InspectFriendlyStart( cast_state_t *cs, int entnum ) { + cast_state_t *ocs; + + ocs = AICast_GetCastState( entnum ); + + // we are about to deal with the request for inspection + cs->vislist[entnum].flags &= ~AIVIS_INSPECT; + cs->scriptPauseTime = level.time + 4000; // wait for at least this long before resuming any scripted walking, etc + + // + cs->aiFlags &= ~AIFL_MISCFLAG2; + + if ( ocs->aiState >= AISTATE_COMBAT || g_entities[entnum].health <= 0 ) { + // mark this character as having been inspected + cs->vislist[entnum].flags |= AIVIS_INSPECTED; + } + + // what should we do? wait here? hide? go see them? + + // if dead, go see them + if ( g_entities[entnum].health <= 0 ) { + cs->inspectNum = entnum; + cs->aifunc = AIFunc_InspectFriendly; + return "AIFunc_InspectFriendlyStart"; + } + + // not dead, so call scripting event + AICast_ForceScriptEvent( cs, "inspectfriendlycombatstart", g_entities[entnum].aiName ); + if ( cs->aiFlags & AIFL_DENYACTION ) { + // ignore this friendly forever and ever amen + cs->vislist[entnum].flags |= AIVIS_INSPECTED; + return NULL; + } + + // if they are in combat, then act according to aggressiveness + if ( ocs->aiState >= AISTATE_COMBAT ) { + if ( cs->attributes[AGGRESSION] < 0.3 ) { + if ( AICast_GetTakeCoverPos( cs, entnum, g_entities[entnum].client->ps.origin, cs->takeCoverPos ) ) { + cs->takeCoverTime = level.time + 10000; // hide for 10 seconds + cs->scriptPauseTime = cs->takeCoverTime; + // crouch there if possible + if ( cs->attributes[ATTACK_CROUCH] > 0.1 ) { + cs->attackcrouch_time = level.time + 3000; + } + return AIFunc_BattleTakeCoverStart( cs ); + } + } + } + + // if still around, then we need to go to them + cs->inspectNum = entnum; + cs->aifunc = AIFunc_InspectFriendly; + return "AIFunc_InspectFriendly"; +} + +/* +============ +AIFunc_InspectBulletImpact() +============ +*/ +char *AIFunc_InspectBulletImpact( cast_state_t *cs ) { + gentity_t *ent; + vec3_t v1; + gclient_t *client; + // + client = &level.clients[cs->entityNum]; + // + ent = &g_entities[cs->entityNum]; + // + cs->bulletImpactIgnoreTime = level.time + 800; + // + // do we need to avoid a danger? + if ( cs->dangerEntityValidTime >= level.time ) { + if ( AICast_GetTakeCoverPos( cs, cs->dangerEntity, cs->dangerEntityPos, cs->takeCoverPos ) ) { + // go to a position that cannot be seen from the dangerPos + cs->takeCoverTime = cs->dangerEntityValidTime + 1000; + cs->attackcrouch_time = 0; + cs->castScriptStatus.scriptGotoId = -1; + cs->movestate = MS_DEFAULT; + cs->movestateType = MSTYPE_NONE; + return AIFunc_AvoidDangerStart( cs ); + } + } + // wait until we are looking at the impact + if ( cs->aiFlags & AIFL_MISCFLAG2 ) { + // pause any scripting + cs->scriptPauseTime = level.time + 1000; + // look at bullet impact + VectorSubtract( cs->bulletImpactEnd, cs->bs->origin, v1 ); + VectorNormalize( v1 ); + vectoangles( v1, cs->ideal_viewangles ); + // + // if we are facing that direction, we've looked at the impact point + if ( fabs( cs->ideal_viewangles[YAW] - cs->viewangles[YAW] ) < 1 ) { + cs->aiFlags &= ~AIFL_MISCFLAG2; + } + return NULL; + } else if ( cs->aiFlags & AIFL_MISCFLAG1 ) { + // clear the flag now + cs->aiFlags &= ~AIFL_MISCFLAG1; + // start looking back at bullet + VectorSubtract( cs->bulletImpactStart, cs->bs->origin, v1 ); + VectorNormalize( v1 ); + vectoangles( v1, cs->ideal_viewangles ); + if ( cs->aiState < AISTATE_ALERT ) { + // change to alert state + if ( !AICast_StateChange( cs, AISTATE_ALERT ) ) { + if ( cs->lastEnemy < 0 && cs->enemyNum < 0 ) { + // look back at our original angles + VectorCopy( ent->s.angles, cs->ideal_viewangles ); + } + // stop doing whatever we are doing, and return control to scripting + cs->scriptPauseTime = 0; + return AIFunc_IdleStart( cs ); + } + // make sure we didnt change thinkfunc + if ( cs->aifunc != AIFunc_InspectBulletImpact ) { + //G_Error( "scripting passed control out of AIFunc_InspectBulletImpact(), this is bad" ); + return NULL; + } + } + // pause any scripting + if ( ent->client->ps.legsTimer ) { + cs->scriptPauseTime = level.time + ent->client->ps.legsTimer; + } else { // just wait for a few seconds looking at the source + cs->scriptPauseTime = level.time + 3500; + } + } + // are we done? + if ( cs->scriptPauseTime < level.time ) { + if ( cs->lastEnemy < 0 && cs->enemyNum < 0 ) { + // look back at our original angles + VectorCopy( ent->s.angles, cs->ideal_viewangles ); + } + return AIFunc_IdleStart( cs ); + } + // + // reload? + AICast_IdleReload( cs ); + // + // check for enemies + { + int numEnemies; + // + // look for things we should attack + numEnemies = AICast_ScanForEnemies( cs, enemies ); + if ( numEnemies == -2 ) { // inspection + // only override current objective if we are inspecting a dead guy, and the new inspect target is fighting someone + if ( ( g_entities[cs->inspectNum].health <= 0 ) && ( g_entities[enemies[0]].health > 0 ) ) { + + return AIFunc_InspectFriendlyStart( cs, enemies[0] ); + } + } else if ( numEnemies > 0 ) { + int i; + + cs->enemyNum = enemies[0]; // just attack the first one + // override with a visible enemy + for ( i = 1; i < numEnemies; i++ ) { + if ( AICast_CheckAttack( cs, enemies[i], qfalse ) ) { + cs->enemyNum = enemies[i]; + break; + } else if ( cs->enemyNum < 0 ) { + cs->lastEnemy = enemies[i]; + } + } + + return AIFunc_BattleStart( cs ); + } + } + // + return NULL; +} + +/* +============ +AIFunc_InspectBulletImpactStart() +============ +*/ +char *AIFunc_InspectBulletImpactStart( cast_state_t *cs ) { + int oldScriptIndex; + // set the impact timer so we ignore bullets while inspecting this one + cs->bulletImpactIgnoreTime = level.time + 5000; + // pause any scripting + cs->scriptPauseTime = level.time + 1000; + // set this so we know if we've started the trace back to the bullet origin + cs->aiFlags |= AIFL_MISCFLAG1; + cs->aiFlags |= AIFL_MISCFLAG2; + // + // call the script event + oldScriptIndex = cs->scriptCallIndex; + AICast_ScriptEvent( cs, "bulletimpactsound", "" ); + if ( oldScriptIndex == cs->scriptCallIndex ) { + // no script event, so call the animation script + BG_AnimScriptEvent( &g_entities[cs->entityNum].client->ps, ANIM_ET_BULLETIMPACT, qfalse, qtrue ); + } + // + // if the origin is not visible, set the bullet origin to the closest visible area from the src + if ( !trap_InPVS( cs->bulletImpactStart, cs->bs->origin ) ) { + // if it fails, then just look at the source + trap_AAS_GetRouteFirstVisPos( g_entities[cs->bulletImpactEntity].s.pos.trBase, cs->bs->origin, cs->travelflags, cs->bulletImpactStart ); + } + // + cs->aifunc = AIFunc_InspectBulletImpact; + return "AIFunc_InspectBulletImpact"; +} + +/* +============ +AIFunc_InspectAudibleEvent() +============ +*/ +char *AIFunc_InspectAudibleEvent( cast_state_t *cs ) { + gentity_t *ent; + bot_state_t *bs; + vec3_t destorg, vec; + float dist; + qboolean moved = qfalse; + + ent = &g_entities[cs->entityNum]; + + // if we have an enemy, attack now! + if ( cs->enemyNum >= 0 ) { + return AIFunc_BattleStart( cs ); + } + + cs->followDist = 64; + + // do we need to avoid a danger? + if ( cs->dangerEntityValidTime >= level.time ) { + if ( AICast_GetTakeCoverPos( cs, cs->dangerEntity, cs->dangerEntityPos, cs->takeCoverPos ) ) { + // go to a position that cannot be seen from the dangerPos + cs->takeCoverTime = cs->dangerEntityValidTime + 1000; + cs->attackcrouch_time = 0; + cs->castScriptStatus.scriptGotoId = -1; + cs->movestate = MS_DEFAULT; + cs->movestateType = MSTYPE_NONE; + return AIFunc_AvoidDangerStart( cs ); + } + } + // + // are we waiting for a door? + if ( cs->doorMarkerTime > level.time - 100 ) { + return AIFunc_DoorMarkerStart( cs, cs->doorMarkerDoor, cs->doorMarkerNum ); + } + + // are we just looking for now? + if ( cs->aiFlags & AIFL_MISCFLAG2 ) { + if ( cs->scriptPauseTime <= level.time ) { + return AIFunc_DefaultStart( cs ); + } + return NULL; + } + + VectorCopy( cs->audibleEventOrg, destorg ); + + // they are ready, are they inside range? FIXME: make configurable + dist = Distance( destorg, cs->bs->origin ); + if ( !( dist < cs->followDist && ( ent->waterlevel || ( cs->bs->cur_ps.groundEntityNum != ENTITYNUM_NONE ) ) ) ) { + // + // go to them + // + bs = cs->bs; + + // set this flag so we know when we;ve just reached them + cs->aiFlags |= AIFL_MISCFLAG1; + + // if not overly aggressive, pursue with caution + if ( cs->attributes[AGGRESSION] <= 0.8 ) { + cs->movestate = MS_CROUCH; + cs->movestateType = MSTYPE_TEMPORARY; + } + + // move straight to them if we can + if ( !moved && + ( cs->bs->cur_ps.groundEntityNum != ENTITYNUM_NONE || g_entities[cs->entityNum].waterlevel > 1 ) ) { + aicast_predictmove_t move; + vec3_t dir; + bot_input_t bi; + usercmd_t ucmd; + trace_t tr; + qboolean simTest = qfalse; + + if ( cs->attributes[RUNNING_SPEED] < 120 ) { + simTest = qtrue; + } + + if ( !simTest ) { + // trace will eliminate most unsuccessful paths + trap_Trace( &tr, cs->bs->origin, NULL /*g_entities[cs->entityNum].r.mins*/, NULL /*g_entities[cs->entityNum].r.maxs*/, destorg, cs->entityNum, g_entities[cs->entityNum].clipmask ); + if ( tr.fraction == 1 ) { + simTest = qtrue; + } + } + + if ( simTest ) { + // try walking straight to them + gentity_t *gent; + // + gent = G_Spawn(); + VectorCopy( destorg, gent->r.currentOrigin ); + // + VectorSubtract( destorg, cs->bs->origin, dir ); + VectorNormalize( dir ); + if ( !ent->waterlevel ) { + dir[2] = 0; + } + //trap_EA_Move(cs->entityNum, dir, 400); + trap_EA_GetInput( cs->entityNum, (float) level.time / 1000, &bi ); + VectorCopy( dir, bi.dir ); + bi.speed = 400; + bi.actionflags = 0; + AICast_InputToUserCommand( cs, &bi, &ucmd, bs->cur_ps.delta_angles ); + AICast_PredictMovement( cs, 10, 0.8, &move, &ucmd, gent->s.number ); + // + if ( move.stopevent == PREDICTSTOP_HITENT ) { // success! + trap_EA_Move( cs->entityNum, dir, 400 ); + vectoangles( dir, cs->ideal_viewangles ); + cs->ideal_viewangles[2] *= 0.5; + moved = qtrue; + } else { // clear movement + //trap_EA_Move(cs->entityNum, dir, 0); + } + // + G_FreeEntity( gent ); + } + } + // + if ( !moved ) { + // use AAS routing + moveresult = AICast_MoveToPos( cs, destorg, -1 ); + // if we cant get there, do something else + if ( moveresult && moveresult->failure ) { + + // if we can get a visible target, then face it + if ( trap_AAS_GetRouteFirstVisPos( cs->audibleEventOrg, cs->bs->origin, cs->travelflags, destorg ) ) { + cs->aiFlags |= AIFL_MISCFLAG2; + VectorSubtract( destorg, cs->bs->origin, destorg ); + VectorNormalize( destorg ); + vectoangles( destorg, cs->ideal_viewangles ); + return NULL; + } + + if ( cs->lastEnemy < 0 && cs->enemyNum < 0 ) { + // look back at our original angles + VectorCopy( ent->s.angles, cs->ideal_viewangles ); + } + return AIFunc_DefaultStart( cs ); + } else if ( !moveresult ) { // face it? + if ( trap_InPVS( destorg, cs->bs->origin ) ) { + VectorSubtract( destorg, cs->bs->origin, vec ); + VectorNormalize( vec ); + vectoangles( vec, cs->ideal_viewangles ); + } + } + } + + // should we slow down? + if ( cs->followDist && cs->followSlowApproach ) { + cs->speedScale = AICast_SpeedScaleForDistance( cs, dist, cs->followDist ); + } +/* + // check for a movement we should be making + if (cs->obstructingTime > level.time) + { + AICast_MoveToPos( cs, cs->obstructingPos, -1 ); + if (cs->movestate != MS_CROUCH) { + cs->movestate = MS_WALK; + } + cs->movestateType = MSTYPE_TEMPORARY; + } +*/ + } else if ( cs->aiFlags & AIFL_MISCFLAG1 ) { + cs->aiFlags &= ~AIFL_MISCFLAG1; + // call a script event + cs->aiFlags &= ~AIFL_DENYACTION; + AICast_ForceScriptEvent( cs, "inspectsoundend", g_entities[cs->audibleEventEnt].aiName ); + if ( cs->aiFlags & AIFL_DENYACTION ) { + // relinguish control back to scripting + return AIFunc_DefaultStart( cs ); + } + } else { + // look around randomly + if ( cs->battleHuntViewTime < level.time ) { + cs->battleHuntViewTime = level.time + 700 + rand() % 1000; + // set a random viewangle + cs->ideal_viewangles[YAW] = AngleMod( cs->ideal_viewangles[YAW] + ( 45.0 + random() * 45.0 ) * ( 2 * ( rand() % 2 ) - 1 ) ); + } + // + if ( cs->scriptPauseTime < level.time ) { + // we're done waiting around here + if ( cs->lastEnemy < 0 && cs->enemyNum < 0 ) { + // look back at our original angles + VectorCopy( ent->s.angles, cs->ideal_viewangles ); + } + return AIFunc_DefaultStart( cs ); + } + } + + { + int numEnemies; + // + // look for things we should attack + numEnemies = AICast_ScanForEnemies( cs, enemies ); + if ( numEnemies == -1 ) { // query mode + return NULL; + } else if ( numEnemies == -2 ) { // inspection + // only override current objective if we are inspecting a dead guy, and the new inspect target is fighting someone + if ( ( g_entities[cs->inspectNum].health <= 0 ) && ( g_entities[enemies[0]].health > 0 ) ) { + return AIFunc_InspectFriendlyStart( cs, enemies[0] ); + } + } else if ( numEnemies == -4 ) { // NEW audible event + //if (cs->aiState < AISTATE_COMBAT) { + return AIFunc_InspectAudibleEventStart( cs, cs->audibleEventEnt ); + //} + } else if ( numEnemies > 0 ) { + int i; + + cs->enemyNum = enemies[0]; // just attack the first one + // override with a visible enemy + for ( i = 1; i < numEnemies; i++ ) { + if ( AICast_CheckAttack( cs, enemies[i], qfalse ) ) { + cs->enemyNum = enemies[i]; + break; + } else if ( cs->enemyNum < 0 ) { + cs->lastEnemy = enemies[i]; + } + } + + return AIFunc_BattleStart( cs ); + } + } + + // set head look flag if no enemy + if ( cs->enemyNum < 0 && cs->attributes[TACTICAL] >= 0.5 && !( cs->aiFlags & AIFL_NO_HEADLOOK ) ) { + g_entities[cs->entityNum].client->ps.eFlags |= EF_HEADLOOK; + } + + // reload? + AICast_IdleReload( cs ); + + return NULL; +} + +/* +============ +AIFunc_InspectAudibleEventStart +============ +*/ +char *AIFunc_InspectAudibleEventStart( cast_state_t *cs, int entnum ) { + cast_state_t *ocs; + int oldScriptIndex; + + ocs = AICast_GetCastState( entnum ); + + // we have now processed the audible event (whether we act on it or not) + cs->audibleEventTime = -9999; + + // trigger a script event, which has the ability to deny the request + oldScriptIndex = cs->scriptCallIndex; + AICast_ForceScriptEvent( cs, "inspectsoundstart", g_entities[cs->audibleEventEnt].aiName ); + if ( cs->aiFlags & AIFL_DENYACTION ) { + return NULL; + } + + // if not in alert mode, go there now + if ( cs->aiState < AISTATE_ALERT ) { + AICast_StateChange( cs, AISTATE_ALERT ); + } + + if ( oldScriptIndex == cs->scriptCallIndex ) { + BG_AnimScriptEvent( &g_entities[cs->entityNum].client->ps, ANIM_ET_INSPECTSOUND, qfalse, qtrue ); + } + + // pause the scripting for now + cs->scriptPauseTime = level.time + 4000; // wait for at least this long before resuming any scripted walking, etc + + // set this when we decide to just look, rather than pursue + cs->aiFlags &= ~AIFL_MISCFLAG2; + + // what should we do? wait here? hide? go see them? + + // if dead, go see them + if ( g_entities[entnum].health <= 0 ) { + cs->inspectNum = entnum; + cs->aifunc = AIFunc_InspectFriendly; + return "AIFunc_InspectFriendlyStart"; + } + + // if they are in combat, then act according to aggressiveness + if ( ocs->aiState >= AISTATE_COMBAT ) { + if ( cs->attributes[AGGRESSION] < 0.3 ) { + if ( AICast_GetTakeCoverPos( cs, entnum, g_entities[entnum].client->ps.origin, cs->takeCoverPos ) ) { + cs->takeCoverTime = level.time + 10000; // hide for 10 seconds + cs->scriptPauseTime = cs->takeCoverTime; + // crouch there if possible + if ( cs->attributes[ATTACK_CROUCH] > 0.1 ) { + cs->attackcrouch_time = level.time + 3000; + } + return AIFunc_BattleTakeCoverStart( cs ); + } + } + } + + cs->aifunc = AIFunc_InspectAudibleEvent; + return "AIFunc_InspectAudibleEvent"; +} + +/* +============ +AIFunc_ChaseGoalIdle() +============ +*/ +char *AIFunc_ChaseGoalIdle( cast_state_t *cs ) { + gentity_t *followent; + vec3_t dir; + + if ( cs->followEntity < 0 ) { + AICast_EndChase( cs ); + return AIFunc_IdleStart( cs ); + } + + followent = &g_entities[cs->followEntity]; + + // CHECK: will this interfere with scripting? + // + // do we need to avoid a danger? + if ( cs->dangerEntityValidTime >= level.time ) { + if ( AICast_GetTakeCoverPos( cs, cs->dangerEntity, cs->dangerEntityPos, cs->takeCoverPos ) ) { + // go to a position that cannot be seen from the dangerPos + cs->takeCoverTime = cs->dangerEntityValidTime + 1000; + cs->attackcrouch_time = 0; + return AIFunc_AvoidDangerStart( cs ); + } + } + // + // are we waiting for a door? + if ( cs->doorMarkerTime > level.time - 100 ) { + return AIFunc_DoorMarkerStart( cs, cs->doorMarkerDoor, cs->doorMarkerNum ); + } + // + // if the player is not ready yet, wait + if ( !followent->inuse ) { + return NULL; + } + + // has the scripting stopped asking us to pursue this goal? + if ( cs->followIsGoto && ( cs->followTime < level.time ) ) { + return AIFunc_Idle( cs ); + } + + // they are ready, are they outside range? + if ( Distance( followent->r.currentOrigin, cs->bs->origin ) > cs->followDist ) { + return AIFunc_ChaseGoalStart( cs, cs->followEntity, cs->followDist, qtrue ); + } + + // check for a movement we should be making + if ( cs->obstructingTime > level.time ) { + AICast_MoveToPos( cs, cs->obstructingPos, -1 ); + cs->speedScale = cs->attributes[WALKING_SPEED] / cs->attributes[RUNNING_SPEED]; + } + // if we have an enemy, fire if they're visible + else if ( cs->enemyNum >= 0 ) { + //attack the enemy if possible + AICast_ProcessAttack( cs ); + } + // if we had an enemy recently, face them + else if ( cs->lastEnemy >= 0 ) { + vec3_t dir; + // + VectorSubtract( cs->vislist[cs->lastEnemy].visible_pos, cs->bs->origin, dir ); + if ( VectorLength( dir ) < 1 ) { + cs->ideal_viewangles[PITCH] = 0; + } else { + VectorNormalize( dir ); + vectoangles( dir, cs->ideal_viewangles ); + } + // reload? + AICast_IdleReload( cs ); + } else if ( followent->client ) { + // face them + VectorSubtract( followent->r.currentOrigin, cs->bs->origin, dir ); + dir[2] += followent->client->ps.viewheight - g_entities[cs->bs->entitynum].client->ps.viewheight; + VectorNormalize( dir ); + vectoangles( dir, cs->ideal_viewangles ); + } + + // look for things we should attack + numEnemies = AICast_ScanForEnemies( cs, enemies ); + if ( numEnemies == -1 ) { // query mode + return NULL; + } else if ( numEnemies == -2 ) { // inspection may be required + char *retval; + // TTimo: gcc: suggest () around assignment used as truth value + if ( ( retval = AIFunc_InspectFriendlyStart( cs, enemies[0] ) ) ) { + return retval; + } + } else if ( numEnemies == -3 ) { // bullet impact + if ( cs->aiState < AISTATE_COMBAT ) { + return AIFunc_InspectBulletImpactStart( cs ); + } + } else if ( numEnemies == -4 ) { // audible event + if ( cs->aiState < AISTATE_COMBAT ) { + return AIFunc_InspectAudibleEventStart( cs, cs->audibleEventEnt ); + } + } else if ( numEnemies > 0 ) { + cs->enemyNum = enemies[0]; // just attack the first one + } + + // set head look flag if no enemy + if ( cs->enemyNum < 0 && cs->attributes[TACTICAL] >= 0.5 && !( cs->aiFlags & AIFL_NO_HEADLOOK ) ) { + g_entities[cs->entityNum].client->ps.eFlags |= EF_HEADLOOK; + } + + return NULL; +} + +/* +============ +AIFunc_ChaseGoalIdleStart() +============ +*/ +char *AIFunc_ChaseGoalIdleStart( cast_state_t *cs, int entitynum, float reachdist ) { + // make sure we don't avoid any areas when we start again + trap_BotInitAvoidReach( cs->bs->ms ); + + // if we are following someone, always use the default (ready for action) anim + if ( entitynum < MAX_CLIENTS ) { + g_entities[cs->entityNum].client->ps.eFlags &= ~EF_STAND_IDLE2; + } else { + // randomly choose idle animation +//----(SA) try always using the 'casual' stand on spawn and change to crouching one when 'alerted' + if ( cs->aiFlags & AIFL_STAND_IDLE2 ) { +// if (cs->lastEnemy < 0) + g_entities[cs->entityNum].client->ps.eFlags |= EF_STAND_IDLE2; +// else +// g_entities[cs->entityNum].client->ps.eFlags &= ~EF_STAND_IDLE2; + } + } + + cs->followEntity = entitynum; + cs->followDist = reachdist; + cs->aifunc = AIFunc_ChaseGoalIdle; + return "AIFunc_ChaseGoalIdle"; +} + +/* +============ +AIFunc_ChaseGoal() +============ +*/ +char *AIFunc_ChaseGoal( cast_state_t *cs ) { + gentity_t *followent, *ent; + bot_state_t *bs; + vec3_t destorg; + float dist; + qboolean moved = qfalse; + + ent = &g_entities[cs->entityNum]; + + if ( cs->followEntity < 0 ) { + AICast_EndChase( cs ); + return AIFunc_IdleStart( cs ); + } + + // CHECK: will this mess with scripting? + // + // do we need to avoid a danger? + if ( cs->dangerEntityValidTime >= level.time ) { + if ( AICast_GetTakeCoverPos( cs, cs->dangerEntity, cs->dangerEntityPos, cs->takeCoverPos ) ) { + // go to a position that cannot be seen from the dangerPos + cs->takeCoverTime = cs->dangerEntityValidTime + 1000; + cs->attackcrouch_time = 0; + cs->castScriptStatus.scriptGotoId = -1; + cs->movestate = MS_DEFAULT; + cs->movestateType = MSTYPE_NONE; + return AIFunc_AvoidDangerStart( cs ); + } + } + // + // are we waiting for a door? + if ( cs->doorMarkerTime > level.time - 100 ) { + return AIFunc_DoorMarkerStart( cs, cs->doorMarkerDoor, cs->doorMarkerNum ); + } + + followent = &g_entities[cs->followEntity]; + + // if the entity is not ready yet + if ( !followent->inuse ) { + // if it's a connecting client, wait + if ( cs->followEntity < MAX_CLIENTS + && ( ( followent->client && followent->client->pers.connected == CON_CONNECTING ) + || ( level.time < 3000 ) ) ) { + return AIFunc_ChaseGoalIdleStart( cs, cs->followEntity, cs->followDist ); + } else // stop following it + { + AICast_EndChase( cs ); + return AIFunc_IdleStart( cs ); + } + } + + // has the scripting stopped asking us to pursue this goal? + if ( cs->followIsGoto && ( cs->followTime < level.time ) ) { + return AIFunc_IdleStart( cs ); + } + + if ( followent->client ) { + VectorCopy( followent->client->ps.origin, destorg ); + } else { + VectorCopy( followent->r.currentOrigin, destorg ); + } + + // they are ready, are they inside range? FIXME: make configurable + dist = Distance( destorg, cs->bs->origin ); + if ( cs->followSlowApproach && dist < cs->followDist && ( ent->waterlevel || ( cs->bs->cur_ps.groundEntityNum != ENTITYNUM_NONE ) ) ) { + // if this is a scripted GOTO, stop following now + if ( cs->followEntity == cs->castScriptStatus.scriptGotoEnt ) { + AICast_EndChase( cs ); + return AIFunc_IdleStart( cs ); + } + // if we have reached our leader + else + { + if ( cs->followEntity == cs->leaderNum ) { + if ( dist < AICAST_LEADERDIST_MIN ) { + AICast_EndChase( cs ); + return AIFunc_IdleStart( cs ); + } else { + trace_t tr; + // if we have a clear line to our leader, move closer, since there may be others following also + trap_Trace( &tr, cs->bs->origin, cs->bs->cur_ps.mins, cs->bs->cur_ps.maxs, g_entities[cs->followEntity].r.currentOrigin, cs->entityNum, g_entities[cs->entityNum].clipmask ); + if ( tr.entityNum != cs->followEntity ) { + AICast_EndChase( cs ); + return AIFunc_IdleStart( cs ); + } + // if we have crouching ability, then use it while we are just moving closer + if ( cs->attributes[ATTACK_CROUCH] > 0.1 ) { + cs->attackcrouch_time = level.time + 1000; + } + } + } else + { + return AIFunc_ChaseGoalIdleStart( cs, cs->followEntity, cs->followDist ); + } + } + } + // + // go to them + // + bs = cs->bs; + // + // RF, disabled this, MIKE sees dead people + //if (followent->client && followent->health <= 0) { + // AICast_EndChase( cs ); + // return AIFunc_IdleStart(cs); + //} + + // move straight to them if we can + if ( !moved && + ( cs->bs->cur_ps.groundEntityNum != ENTITYNUM_NONE || g_entities[cs->entityNum].waterlevel > 1 ) ) { + aicast_predictmove_t move; + vec3_t dir; + bot_input_t bi; + usercmd_t ucmd; + trace_t tr; + qboolean simTest = qfalse; + float frameTime = 0.8, goaldist; + + if ( cs->attributes[RUNNING_SPEED] < 120 ) { + simTest = qtrue; + } + + if ( !simTest ) { + // trace will eliminate most unsuccessful paths + trap_Trace( &tr, cs->bs->origin, NULL /*g_entities[cs->entityNum].r.mins*/, NULL /*g_entities[cs->entityNum].r.maxs*/, followent->r.currentOrigin, cs->entityNum, g_entities[cs->entityNum].clipmask ); + if ( tr.entityNum == cs->followEntity || tr.fraction == 1 ) { + simTest = qtrue; + } + } + + if ( simTest ) { + // try walking straight to them + VectorSubtract( followent->r.currentOrigin, cs->bs->origin, dir ); + if ( !ent->waterlevel ) { + dir[2] = 0; + } + goaldist = VectorNormalize( dir ); + //trap_EA_Move(cs->entityNum, dir, 400); + trap_EA_GetInput( cs->entityNum, (float) level.time / 1000, &bi ); + VectorCopy( dir, bi.dir ); + bi.speed = 400; + bi.actionflags = 0; + AICast_InputToUserCommand( cs, &bi, &ucmd, bs->cur_ps.delta_angles ); + AICast_PredictMovement( cs, 10, frameTime, &move, &ucmd, cs->followEntity ); + + if ( move.stopevent == PREDICTSTOP_HITENT ) { // success! + // make sure we didnt spend a lot of time sliding along an obstacle + if ( ( move.frames * frameTime ) < ( 1.0 + ( goaldist / ( bs->cur_ps.speed * bs->cur_ps.runSpeedScale ) ) ) ) { + trap_EA_Move( cs->entityNum, dir, 400 ); + vectoangles( dir, cs->ideal_viewangles ); + cs->ideal_viewangles[2] *= 0.5; + moved = qtrue; + } + } + if ( !moved ) { + //trap_EA_Move(cs->entityNum, dir, 0); + } + } + } + // + if ( !moved ) { + // use AAS routing + moveresult = AICast_MoveToPos( cs, followent->r.currentOrigin, cs->followEntity ); + if ( moveresult && moveresult->failure ) { + // shit? + } + } + + // should we slow down? + if ( cs->followDist && cs->followSlowApproach && cs->followDist < 48 ) { + cs->speedScale = AICast_SpeedScaleForDistance( cs, dist, cs->followDist ); + } + + // check for a movement we should be making + if ( cs->obstructingTime > level.time ) { + AICast_MoveToPos( cs, cs->obstructingPos, -1 ); + if ( cs->movestate != MS_CROUCH ) { + cs->movestate = MS_WALK; + } + cs->movestateType = MSTYPE_TEMPORARY; + } + + // if we have an enemy, fire if they're visible + if ( cs->enemyNum >= 0 ) { //attack the enemy if possible + AICast_ProcessAttack( cs ); + } else { + int numEnemies; + // + // look for things we should attack + numEnemies = AICast_ScanForEnemies( cs, enemies ); + if ( numEnemies == -1 ) { // query mode + return NULL; + } else if ( numEnemies == -2 ) { // inspection may be required + char *retval; + // TTimo: gcc: suggest () around assignment used as truth value + if ( ( retval = AIFunc_InspectFriendlyStart( cs, enemies[0] ) ) ) { + return retval; + } + } else if ( numEnemies == -3 ) { // bullet impact + if ( cs->aiState < AISTATE_COMBAT ) { + return AIFunc_InspectBulletImpactStart( cs ); + } + } else if ( numEnemies == -4 ) { // audible event + if ( cs->aiState < AISTATE_COMBAT ) { + return AIFunc_InspectAudibleEventStart( cs, cs->audibleEventEnt ); + } + } else if ( numEnemies > 0 ) { + int i; + + cs->enemyNum = enemies[0]; // just attack the first one + // override with a visible enemy + for ( i = 1; i < numEnemies; i++ ) { + if ( AICast_CheckAttack( cs, enemies[i], qfalse ) ) { + cs->enemyNum = enemies[i]; + break; + } else if ( cs->enemyNum < 0 ) { + cs->lastEnemy = enemies[i]; + } + } + } + // reload? + AICast_IdleReload( cs ); + } + + // set head look flag if no enemy + if ( cs->enemyNum < 0 && cs->attributes[TACTICAL] >= 0.5 && !( cs->aiFlags & AIFL_NO_HEADLOOK ) ) { + g_entities[cs->entityNum].client->ps.eFlags |= EF_HEADLOOK; + } + + return NULL; + +} + +/* +============ +AIFunc_ChaseGoalStart() +============ +*/ +char *AIFunc_ChaseGoalStart( cast_state_t *cs, int entitynum, float reachdist, qboolean slowApproach ) { + cs->followEntity = entitynum; + cs->followDist = reachdist; + cs->followIsGoto = qfalse; + cs->followSlowApproach = slowApproach; + cs->aifunc = AIFunc_ChaseGoal; + return "AIFunc_ChaseGoal"; +} + +/* +============ +AIFunc_DoorMarker() +============ +*/ +char *AIFunc_DoorMarker( cast_state_t *cs ) { + gentity_t *followent, *door; + bot_state_t *bs; + vec3_t destorg; + float dist; + // + // do we need to avoid a danger? + if ( cs->dangerEntityValidTime >= level.time ) { + if ( !AICast_GetTakeCoverPos( cs, cs->dangerEntity, cs->dangerEntityPos, cs->takeCoverPos ) ) { + // shit?? + } + // go to a position that cannot be seen from the dangerPos + cs->takeCoverTime = cs->dangerEntityValidTime + 1000; + cs->attackcrouch_time = 0; + return AIFunc_AvoidDangerStart( cs ); + } + + followent = &g_entities[cs->doorMarker]; + + // if the entity is not ready yet + if ( !followent->inuse ) { + cs->doorMarkerTime = 0; + //return AIFunc_DefaultStart( cs ); + return AIFunc_Restore( cs ); + } + + // if the door is open or idle + door = &g_entities[cs->doorEntNum]; + if ( ( !door->key ) && + ( door->s.apos.trType == TR_STATIONARY && door->s.pos.trType == TR_STATIONARY ) ) { + cs->doorMarkerTime = 0; + //return AIFunc_DefaultStart( cs ); + return AIFunc_Restore( cs ); + } + + // if we have an enemy, fire if they're visible + if ( cs->enemyNum >= 0 ) { //attack the enemy if possible + AICast_ProcessAttack( cs ); + } + + // they are ready, are they inside range? FIXME: make configurable + dist = Distance( destorg, cs->bs->origin ); + if ( dist < 12 ) { + // check for a movement we should be making + if ( cs->obstructingTime > level.time ) { + AICast_MoveToPos( cs, cs->obstructingPos, -1 ); + } + // if the door is locked, resume + if ( followent->key ) { + return AIFunc_Restore( cs ); + } + return NULL; + } + + // go to it + // + bs = cs->bs; + // + moveresult = AICast_MoveToPos( cs, followent->r.currentOrigin, followent->s.number ); + // if we cant get there, forget it + if ( moveresult && moveresult->failure ) { + return AIFunc_Restore( cs ); + } + // should we slow down? + if ( cs->followDist ) { + cs->speedScale = AICast_SpeedScaleForDistance( cs, dist, cs->followDist ); + } + // reload? + AICast_IdleReload( cs ); + return NULL; + +} + +/* +============ +AIFunc_DoorMarkerStart() +============ +*/ +char *AIFunc_DoorMarkerStart( cast_state_t *cs, int doornum, int markernum ) { + cs->doorEntNum = doornum; + cs->doorMarker = markernum; + cs->oldAifunc = cs->aifunc; + cs->aifunc = AIFunc_DoorMarker; + return "AIFunc_DoorMarker"; +} + +/* +============= +AIFunc_BattleRoll() +============= +*/ +char *AIFunc_BattleRoll( cast_state_t *cs ) { + gclient_t *client = &level.clients[cs->entityNum]; + vec3_t dir; + // + // record the time + cs->lastRollMove = level.time; + client->ps.eFlags |= EF_NOSWINGANGLES; + // + if ( !client->ps.torsoTimer ) { + if ( cs->battleRollTime < level.time ) { + return AIFunc_Restore( cs ); + } else { + // attack? + if ( cs->enemyNum >= 0 ) { + AICast_ProcessAttack( cs ); + } + } + } + if ( g_entities[cs->entityNum].health <= 0 ) { + return AIFunc_DefaultStart( cs ); + } + // + trap_EA_Crouch( cs->entityNum ); + cs->attackcrouch_time = level.time + 500; + // all characters so far only move during the first second of animation + if ( cs->thinkFuncChangeTime > level.time - 1000 ) { + // just move in the direction of our ideal_viewangles + AngleVectors( cs->ideal_viewangles, dir, NULL, NULL ); + trap_EA_Move( cs->entityNum, dir, 300 ); + // we are crouching, move a little faster than normal + cs->speedScale = 1.5; + } else if ( cs->takeCoverTime > level.time ) { + // + // if we are taking Cover, use this position, if it's bad, we'll just look for a better spot once we're done here + VectorCopy( cs->bs->origin, cs->takeCoverPos ); + } else if ( cs->enemyNum >= 0 ) { + // + // start turning towards our enemy + AICast_ProcessAttack( cs ); + } + // + return NULL; +} + +/* +============= +AIFunc_BattleRollStart() +============= +*/ +char *AIFunc_BattleRollStart( cast_state_t *cs, vec3_t vec ) { + int duration; +// gclient_t *client = &level.clients[cs->entityNum]; + // + // backup the current thinkfunc, so we can return to it when done + cs->oldAifunc = cs->aifunc; + // + // face the direction of movement + vectoangles( vec, cs->ideal_viewangles ); + // do the roll + duration = BG_AnimScriptEvent( &g_entities[cs->entityNum].client->ps, ANIM_ET_ROLL, qfalse, qtrue ); + // + if ( duration < 0 ) { // it failed + return NULL; + } + // add some duration to make sure it fully plays out + duration += 100; + g_entities[cs->entityNum].client->ps.legsTimer = duration; + g_entities[cs->entityNum].client->ps.torsoTimer = duration; + // + cs->noAttackTime = level.time + duration - 200; + // set the duration + cs->battleRollTime = level.time + duration; + // move into crouch position + //cs->attackcrouch_time = level.time + (duration) + 1000; + // record the time + cs->lastRollMove = level.time; + // + // make sure we move this frame + AIFunc_BattleRoll( cs ); + // + cs->aifunc = AIFunc_BattleRoll; + return "AIFunc_BattleRoll"; +} + +/* +============= +AIFunc_BattleDiveStart() +============= +*/ +char *AIFunc_BattleDiveStart( cast_state_t *cs, vec3_t vec ) { + int duration; +// gclient_t *client = &level.clients[cs->entityNum]; + // + // backup the current thinkfunc, so we can return to it when done + cs->oldAifunc = cs->aifunc; + // + // face the direction of movement + vectoangles( vec, cs->ideal_viewangles ); + // force crouching anim + BG_UpdateConditionValue( cs->entityNum, ANIM_COND_CROUCHING, qtrue, qfalse ); + // do the roll + duration = BG_AnimScriptEvent( &g_entities[cs->entityNum].client->ps, ANIM_ET_DIVE, qfalse, qtrue ); + // + if ( duration < 0 ) { // it failed + return NULL; + } + // + cs->noAttackTime = level.time + duration - 200; + // set the duration + cs->battleRollTime = level.time + duration; + // move into crouch position + //cs->attackcrouch_time = level.time + (duration) + 1000; + // record the time + cs->lastRollMove = level.time; + // + // make sure we move this frame + AIFunc_BattleRoll( cs ); + // + cs->aifunc = AIFunc_BattleRoll; + return "AIFunc_BattleRoll"; +} + +/* +============= +AIFunc_FlipMove() +============= +*/ +char *AIFunc_FlipMove( cast_state_t *cs ) { + gclient_t *client = &level.clients[cs->entityNum]; + vec3_t dir; + // + if ( !client->ps.torsoTimer ) { + cs->attackcrouch_time = 0; + return AIFunc_Restore( cs ); + } + if ( g_entities[cs->entityNum].health <= 0 ) { + return AIFunc_DefaultStart( cs ); + } + // + // just move in the direction of our ideal_viewangles + AngleVectors( cs->ideal_viewangles, dir, NULL, NULL ); + trap_EA_Move( cs->entityNum, dir, 400 ); + // if we are crouching, move a little faster than normal + if ( cs->attackcrouch_time > level.time ) { + cs->speedScale = 1.5; + } + // + return NULL; +} + +/* +============= +AIFunc_FlipMoveStart() +============= +*/ +char *AIFunc_FlipMoveStart( cast_state_t *cs, vec3_t vec ) { + int duration; +// gclient_t *client = &level.clients[cs->entityNum]; + // + // backup the current thinkfunc, so we can return to it when done + cs->oldAifunc = cs->aifunc; + // + // record the time + cs->lastRollMove = level.time; + // face the direction of movement + vectoangles( vec, cs->ideal_viewangles ); + cs->noAttackTime = level.time + 1200; + // do the roll + duration = BG_AnimScriptEvent( &g_entities[cs->entityNum].client->ps, ANIM_ET_ROLL, qfalse, qfalse ); + // + if ( duration < 0 ) { // it failed + return NULL; + } + // move into crouch position + cs->attackcrouch_time = level.time + 800; + // + // make sure we move this frame + AIFunc_FlipMove( cs ); + // + cs->aifunc = AIFunc_FlipMove; + return "AIFunc_FlipMove"; +} + +/* +============= +AIFunc_BattleHunt() +============= +*/ +char *AIFunc_BattleHunt( cast_state_t *cs ) { + const float chaseDist = 32; + gentity_t *followent, *ent; + bot_state_t *bs; + vec3_t destorg; + qboolean moved = qfalse; +// gclient_t *client = &level.clients[cs->entityNum]; + char *rval; + float dist; + cast_state_t *ocs; + int *ammo, i; + + ent = &g_entities[cs->entityNum]; + + // + // do we need to avoid a danger? + if ( cs->dangerEntityValidTime >= level.time ) { + if ( !AICast_GetTakeCoverPos( cs, cs->dangerEntity, cs->dangerEntityPos, cs->takeCoverPos ) ) { + // shit?? + } + // go to a position that cannot be seen from the dangerPos + cs->takeCoverTime = cs->dangerEntityValidTime + 1000; + cs->attackcrouch_time = 0; + return AIFunc_AvoidDangerStart( cs ); + } + // + // are we waiting for a door? + if ( cs->doorMarkerTime > level.time - 100 ) { + return AIFunc_DoorMarkerStart( cs, cs->doorMarkerDoor, cs->doorMarkerNum ); + } + // + bs = cs->bs; + // + if ( cs->enemyNum < 0 ) { + return AIFunc_IdleStart( cs ); + } + // + ocs = AICast_GetCastState( cs->enemyNum ); + // + if ( cs->aiFlags & AIFL_ATTACK_CROUCH ) { + cs->attackcrouch_time = level.time + 1000; + } + // + followent = &g_entities[cs->enemyNum]; + // + // if the entity is not ready yet + if ( !followent->inuse ) { + // if it's a connecting client, wait + if ( !( ( cs->enemyNum < MAX_CLIENTS ) + && ( ( followent->client && followent->client->pers.connected == CON_CONNECTING ) + || ( level.time < 3000 ) ) ) ) { // they don't exist anymore, stop attacking + cs->enemyNum = -1; + } + + return AIFunc_IdleStart( cs ); + } + // + // if we can see them, go back to an attack state + AICast_ChooseWeapon( cs, qtrue ); // enable special weapons, if we cant get them, change back + if ( AICast_EntityVisible( cs, cs->enemyNum, qtrue ) // take into account reaction time + && AICast_CheckAttack( cs, cs->enemyNum, qfalse ) + && cs->obstructingTime < level.time ) { + if ( AICast_StopAndAttack( cs ) ) { + // TTimo: gcc: suggest () around assignment used as truth value + if ( ( rval = AIFunc_BattleStart( cs ) ) ) { + return rval; + } + } else { // just attack them now and keep chasing + AICast_ProcessAttack( cs ); + } + AICast_ChooseWeapon( cs, qfalse ); + } else + { + int numEnemies, shouldAttack; + + AICast_ChooseWeapon( cs, qfalse ); + + ammo = cs->bs->cur_ps.ammo; + shouldAttack = qfalse; + numEnemies = AICast_ScanForEnemies( cs, enemies ); + if ( numEnemies == -1 ) { // query mode + return NULL; + } else if ( numEnemies == -2 ) { // inspection may be required + char *retval; + if ( cs->aiState < AISTATE_COMBAT ) { + // TTimo: gcc: suggest () around assignment used as truth value + if ( ( retval = AIFunc_InspectFriendlyStart( cs, enemies[0] ) ) ) { + return retval; + } + } + } else if ( numEnemies == -3 ) { // bullet impact + if ( cs->aiState < AISTATE_COMBAT ) { + return AIFunc_InspectBulletImpactStart( cs ); + } + } else if ( numEnemies == -4 ) { // audible event + if ( cs->aiState < AISTATE_COMBAT ) { + return AIFunc_InspectAudibleEventStart( cs, cs->audibleEventEnt ); + } + } else if ( AICast_GotEnoughAmmoForWeapon( cs, cs->bs->cur_ps.weapon ) ) { + if ( numEnemies > 0 ) { + // default to the first known enemy, overwrite if we find a clearer shot + cs->enemyNum = enemies[0]; + // + for ( i = 0; i < numEnemies; i++ ) { + if ( AICast_CheckAttack( cs, enemies[i], qfalse ) || AICast_CheckAttack( AICast_GetCastState( enemies[i] ), cs->entityNum, qfalse ) ) { + cs->enemyNum = enemies[i]; + shouldAttack = qtrue; + break; + } else if ( cs->enemyNum < 0 ) { + cs->lastEnemy = enemies[i]; + } + } + // note: next frame we'll process this new enemy an begin an attack if necessary + } + } + AICast_ChooseWeapon( cs, qfalse ); + } + + // have we spent enough time in combat mode? + if ( cs->aiState == AISTATE_COMBAT ) { + if ( cs->vislist[cs->enemyNum].visible_timestamp < level.time - COMBAT_TIMEOUT ) { + AICast_StateChange( cs, AISTATE_ALERT ); + } + } + + // while hunting, use crouch mode if possible + if ( cs->attributes[ATTACK_CROUCH] >= 0.1 ) { + cs->attackcrouch_time = level.time + 1000; + } + + if ( cs->battleHuntPauseTime ) { + if ( cs->battleHuntPauseTime < level.time ) { + // pausetime has expired, so go into ambush mode + if ( AICast_GetTakeCoverPos( cs, cs->enemyNum, cs->vislist[cs->enemyNum].chase_marker[cs->battleChaseMarker], cs->takeCoverPos ) ) { + // wait in ambush, for them to return + VectorCopy( cs->vislist[cs->enemyNum].chase_marker[cs->battleChaseMarker], cs->combatGoalOrigin ); + return AIFunc_BattleAmbushStart( cs ); + } + // couldn't find a spot, so just stay here? + VectorCopy( cs->bs->origin, cs->combatGoalOrigin ); + VectorCopy( cs->bs->origin, cs->takeCoverPos ); + return AIFunc_BattleAmbushStart( cs ); + } else { + // stay here, looking around + if ( cs->battleHuntViewTime < level.time ) { + cs->battleHuntViewTime = level.time + 700 + rand() % 1000; + // set a random viewangle + cs->ideal_viewangles[YAW] = AngleMod( cs->ideal_viewangles[YAW] + ( 45.0 + random() * 45.0 ) * ( 2 * ( rand() % 2 ) - 1 ) ); + cs->ideal_viewangles[PITCH] = 0; + } + } + } else { + // cycle through markers + VectorCopy( cs->vislist[cs->enemyNum].chase_marker[cs->battleChaseMarker], destorg ); + if ( ( dist = Distance( destorg, cs->bs->origin ) ) < chaseDist ) { + if ( cs->battleChaseMarker == ( cs->vislist[cs->enemyNum].chase_marker_count - 1 ) ) { + cs->battleHuntPauseTime = level.time + 4000; + cs->battleHuntViewTime = level.time + 1000; + } else { + cs->battleChaseMarker += cs->battleChaseMarkerDir; + if ( cs->battleChaseMarker > cs->vislist[cs->enemyNum].chase_marker_count ) { + cs->battleChaseMarkerDir *= -1; + cs->battleChaseMarker = cs->vislist[cs->enemyNum].chase_marker_count - 1; + } + if ( cs->battleChaseMarker < 0 ) { + cs->battleChaseMarkerDir = 1; + cs->battleChaseMarker = 0; + } + } + } + // + if ( cs->battleHuntPauseTime < level.time ) { + // just go to them + if ( !moved && cs->leaderNum < 0 ) { + moveresult = AICast_MoveToPos( cs, destorg, cs->enemyNum ); + if ( moveresult && moveresult->failure ) { // no path, so go back to idle behaviour + // try to go to ambush mode + cs->enemyNum = -1; + return AIFunc_DefaultStart( cs ); + } else { + moved = qtrue; + } + // slow down real close to the goal, so we don't go passed it + cs->speedScale = AICast_SpeedScaleForDistance( cs, dist, chaseDist ); + } + } + } + + // reload? + AICast_IdleReload( cs ); + + return NULL; +} + +/* +============= +AIFunc_BattleHuntStart() +============= +*/ +char *AIFunc_BattleHuntStart( cast_state_t *cs ) { + cs->combatGoalTime = 0; + cs->battleChaseMarker = 0; + cs->battleChaseMarkerDir = 1; + cs->battleHuntPauseTime = 0; + // + cs->aifunc = AIFunc_BattleHunt; + return "AIFunc_BattleHunt"; +} + +/* +============= +AIFunc_BattleAmbush() +============= +*/ +char *AIFunc_BattleAmbush( cast_state_t *cs ) { + bot_state_t *bs; + vec3_t destorg, vec; + float dist, moveDist; + int enemies[MAX_CLIENTS], numEnemies, i; + qboolean shouldAttack, idleYaw; + aicast_predictmove_t move; + int *ammo; + vec3_t dir; +// gclient_t *client = &level.clients[cs->entityNum]; + // + // do we need to avoid a danger? + if ( cs->dangerEntityValidTime >= level.time ) { + if ( AICast_GetTakeCoverPos( cs, cs->dangerEntity, cs->dangerEntityPos, cs->takeCoverPos ) ) { + // go to a position that cannot be seen from the dangerPos + cs->takeCoverTime = cs->dangerEntityValidTime + 1000; + cs->attackcrouch_time = 0; + return AIFunc_AvoidDangerStart( cs ); + } + // if not found, then keep trying, hopefully a spot will free up soon so we can run the hidepos function + } + // + // are we waiting for a door? + if ( cs->doorMarkerTime > level.time - 100 ) { + return AIFunc_DoorMarkerStart( cs, cs->doorMarkerDoor, cs->doorMarkerNum ); + } + + // we need to move towards it + bs = cs->bs; + // + // note: removing this will cause problems down below! + if ( cs->enemyNum < 0 ) { + return AIFunc_IdleStart( cs ); + } + // + // have we spent enough time in combat mode? + if ( cs->aiState == AISTATE_COMBAT ) { + if ( cs->vislist[cs->enemyNum].visible_timestamp < level.time - COMBAT_TIMEOUT ) { + AICast_StateChange( cs, AISTATE_ALERT ); + } + } + // while hunting, use crouch mode if possible + if ( cs->attributes[ATTACK_CROUCH] >= 0.1 ) { + cs->attackcrouch_time = level.time + 2000; + } + // + VectorCopy( cs->takeCoverPos, destorg ); + VectorSubtract( destorg, cs->bs->origin, vec ); + vec[2] *= 0.2; + dist = VectorLength( vec ); + // + // update the chase marker + if ( cs->vislist[cs->enemyNum].chase_marker_count > 0 ) { + VectorCopy( cs->vislist[cs->enemyNum].chase_marker[cs->vislist[cs->enemyNum].chase_marker_count - 1], cs->combatGoalOrigin ); + } + // + // look for things we should attack + // if we are out of ammo, we shouldn't bother trying to attack (and we should keep hiding) + ammo = cs->bs->cur_ps.ammo; + shouldAttack = qfalse; + numEnemies = AICast_ScanForEnemies( cs, enemies ); + + // we shouldnt be interrupted from BattleAmbush mode, so try to handle these without interference + if ( numEnemies == -1 ) { // query mode + // ... + } else if ( numEnemies == -2 ) { // inspection may be required + cs->vislist[enemies[0]].flags |= AIVIS_INSPECTED; // they have been notified + cs->vislist[enemies[0]].flags &= ~AIVIS_INSPECT; // they have been notified + } else if ( numEnemies == -3 ) { // bullet impact + // ... + } else if ( numEnemies == -4 ) { // audible event + // ... + } else if ( numEnemies > 0 ) { + + if ( AICast_GotEnoughAmmoForWeapon( cs, cs->weaponNum ) ) { + // default to the first known enemy, overwrite if we find a clearer shot + cs->enemyNum = enemies[0]; + // + for ( i = 0; i < numEnemies; i++ ) { + // if (we can get them from here) or (they can get us, AND we have stopped going to our ambush spot) + if ( ( AICast_EntityVisible( cs, enemies[i], qfalse ) && AICast_CheckAttack( cs, enemies[i], qfalse ) ) || + ( ( VectorLength( cs->takeCoverPos ) < 1 || dist <= 8 ) && ( AICast_EntityVisible( AICast_GetCastState( enemies[i] ), cs->entityNum, qfalse ) || AICast_CheckAttack( AICast_GetCastState( enemies[i] ), cs->entityNum, qfalse ) || AICast_EntityVisible( AICast_GetCastState( enemies[i] ), cs->entityNum, qtrue ) ) ) ) { + cs->enemyNum = enemies[i]; + return AIFunc_BattleStart( cs ); + } else if ( cs->enemyNum < 0 ) { + cs->lastEnemy = enemies[i]; + } else if ( AICast_EntityVisible( cs, enemies[i], qfalse ) ) { + bot_input_t bi_back; + // try and move to them, if successful, then start chasing + trap_EA_GetInput( cs->entityNum, (float) level.time / 1000, &bi_back ); + if ( AICast_MoveToPos( cs, g_entities[enemies[i]].client->ps.origin, enemies[i] ) ) { + if ( !moveresult->failure ) { + cs->enemyNum = enemies[i]; + return AIFunc_BattleChaseStart( cs ); + } + } else { + trap_EA_ResetInput( cs->entityNum, &bi_back ); + } + } + } + } else { + AICast_ChooseWeapon( cs, qfalse ); + // + if ( !AICast_GotEnoughAmmoForWeapon( cs, cs->weaponNum ) ) { + // NO AMMO LEFT!! + // hide? + if ( AICast_GetTakeCoverPos( cs, cs->enemyNum, cs->vislist[cs->enemyNum].visible_pos, cs->takeCoverPos ) ) { + // go to a position that cannot be seen from the last place we saw the enemy, and wait there for some time + cs->takeCoverTime = level.time + 2000 + rand() % 3000; + return AIFunc_BattleTakeCoverStart( cs ); + } + } + } + + } + // + // keep hiding forever + cs->takeCoverTime = level.time + 1000; + // + memset( &move, 0, sizeof( move ) ); + // + // are we close enough to the goal? + if ( VectorLength( cs->takeCoverPos ) > 1 && dist > 8 && ( cs->obstructingTime < level.time ) /*&& !shouldAttack*/ ) { + const float simTime = 0.8; + float enemyDist; + // + // we haven't reached it yet, make sure we at least wait there for a few seconds after arriving + cs->takeCoverTime = level.time + 2000 + rand() % 2000; + // + moveresult = AICast_MoveToPos( cs, destorg, -1 ); + if ( moveresult ) { + //if the movement failed + if ( moveresult->failure ) { + //reset the avoid reach, otherwise bot is stuck in current area + trap_BotResetAvoidReach( bs->ms ); + // couldn't get there, so stop trying to get there + VectorClear( cs->takeCoverPos ); + dist = 0; + } + // + if ( moveresult->blocked ) { + // abort the TakeCover + VectorClear( cs->takeCoverPos ); + dist = 0; + } + } + // + // NOTE: this is also used by hidepos prediction (below) + // if we are going to bump into something soon, abort it + AICast_PredictMovement( cs, 1, simTime, &move, &cs->lastucmd, -1 ); + enemyDist = Distance( cs->bs->origin, g_entities[cs->enemyNum].s.pos.trBase ); + VectorSubtract( move.endpos, cs->bs->origin, vec ); + moveDist = VectorNormalize( vec ); + // + if ( ( move.numtouch && move.touchents[0] < aicast_maxclients ) // hit something + // or moved closer to the enemy + || ( ( enemyDist < 128 ) + && ( ( enemyDist - 1 ) > ( Distance( move.endpos, g_entities[cs->enemyNum].s.pos.trBase ) ) ) ) ) { + // abort the manouver + VectorClear( cs->takeCoverPos ); + dist = 0; + } + // + // we should slow down on approaching the destination point + else if ( dist < 64 ) { + cs->speedScale = AICast_SpeedScaleForDistance( cs, dist, 0 ); + } + + // don't actually hide, check if we are about to, so we can hide right here + if ( !( cs->aiFlags & AIFL_MISCFLAG1 ) ) { + if ( move.numtouch || !AICast_VisibleFromPos( move.endpos, cs->entityNum, cs->combatGoalOrigin, cs->enemyNum, qfalse ) ) { + // abort the manouver, reached a good spot + cs->aiFlags |= AIFL_MISCFLAG1; + VectorCopy( cs->bs->origin, cs->takeCoverPos ); + } + } + + } else { + // + // check for a movement we should be making + if ( cs->obstructingTime > level.time ) { + AICast_MoveToPos( cs, cs->obstructingPos, -1 ); + } + // if we have some enemies that we can attack immediately (without going anywhere to chase them) + if ( shouldAttack ) { + return AIFunc_BattleStart( cs ); + } + // do we need to go to our leader? + else if ( cs->leaderNum >= 0 && Distance( cs->bs->origin, g_entities[cs->leaderNum].r.currentOrigin ) > MAX_LEADER_DIST ) { + // wait until we've been hiding for long enough + if ( level.time > cs->takeCoverTime ) { + return AIFunc_ChaseGoalStart( cs, cs->leaderNum, AICAST_LEADERDIST_MAX, qtrue ); + } + } + // else, crouch while we hide + if ( cs->attributes[ATTACK_CROUCH] > 0.1 || cs->crouchHideFlag ) { + cs->attackcrouch_time = level.time + 2000; + } + } + // + if ( !( cs->aiFlags & AIFL_WALKFORWARD ) || !VectorLength( cs->bs->cur_ps.velocity ) ) { + idleYaw = qtrue; + // if we know who we are hiding from, face them (hack, so they dont face stupid directions) + if ( cs->enemyNum >= 0 ) { + VectorSubtract( g_entities[cs->enemyNum].s.pos.trBase, cs->bs->origin, dir ); + vectoangles( dir, cs->ideal_viewangles ); + idleYaw = qfalse; + } else if ( cs->lastEnemy >= 0 ) { + VectorSubtract( g_entities[cs->lastEnemy].s.pos.trBase, cs->bs->origin, dir ); + vectoangles( dir, cs->ideal_viewangles ); + idleYaw = qfalse; + } + // if we can see the place we are hiding from, look at it + if ( idleYaw && AICast_VisibleFromPos( cs->bs->origin, cs->entityNum, cs->combatGoalOrigin, cs->lastEnemy, qfalse ) ) { + // face the position we are retreating from + VectorSubtract( cs->combatGoalOrigin, cs->bs->origin, dir ); + dir[2] = 0; + if ( VectorNormalize( dir ) > 4 ) { + idleYaw = qfalse; + vectoangles( dir, cs->ideal_viewangles ); + } + + } + // + if ( idleYaw ) { // look around randomly (but not straight into walls) + + if ( cs->nextIdleAngleChange < level.time ) { + // wait a second before changing again + if ( ( cs->nextIdleAngleChange + 3000 ) < level.time ) { + + // FIXME: This could be changed to use some AAS sampling, which would: + // + // Given a src area, pick a random dest area which is visible from that area + // and return it's position, which we'd then use to set the next view angles + // + // This would result in more efficient, more realistic behaviour, since they'd + // also use PITCH angles to look at areas above/below them + + cs->idleYaw = AICast_GetRandomViewAngle( cs, 512 ); + + if ( abs( AngleDelta( cs->idleYaw, cs->ideal_viewangles[YAW] ) ) < 45 ) { + cs->nextIdleAngleChange = level.time + 1000 + rand() % 2500; + } else { // do really fast + cs->nextIdleAngleChange = level.time + 500; + } + + // adjust with time + cs->idleYawChange = AngleDelta( cs->idleYaw, cs->ideal_viewangles[YAW] ); + /// ((float)(cs->nextIdleAngleChange - level.time) / 1000.0); + + cs->ideal_viewangles[PITCH] = 0; + } + } else if ( cs->idleYawChange ) { + cs->idleYawChange = AngleDelta( cs->idleYaw, cs->ideal_viewangles[YAW] ); + cs->ideal_viewangles[YAW] = AngleMod( cs->ideal_viewangles[YAW] + ( cs->idleYawChange * cs->bs->thinktime ) ); + } + + } + } + // + if ( !cs->crouchHideFlag && cs->enemyNum < 0 ) { // no enemy, and no need to crouch, so stop crouching + if ( cs->attackcrouch_time > level.time + 1000 ) { + cs->attackcrouch_time = level.time + 1000; + } + } + + // reload? + AICast_IdleReload( cs ); + + return NULL; +} + +/* +============= +AIFunc_BattleAmbushStart() +============= +*/ +char *AIFunc_BattleAmbushStart( cast_state_t *cs ) { + if ( !AICast_CanMoveWhileFiringWeapon( cs->weaponNum ) ) { + // always run to the cover point + cs->attackcrouch_time = 0; + } else if ( cs->attackcrouch_time > level.time + 1000 ) { + cs->attackcrouch_time = level.time + 1000; + } + + // + // start a crouch attack? + if ( cs->attributes[ATTACK_CROUCH] > 0.1 && cs->attackcrouch_time >= level.time ) { + // continue + cs->attackcrouch_time = level.time + 1000; + } + // if we arent crouching, start crouching soon after we start retreating + if ( cs->attributes[ATTACK_CROUCH] > 0.1 ) { + cs->aiFlags |= AIFL_ATTACK_CROUCH; + } else { + cs->aiFlags &= ~AIFL_ATTACK_CROUCH; + } + + // miscflag1 used to set predicted point as our goal, so we dont keep setting this over and over + cs->aiFlags &= ~AIFL_MISCFLAG1; + + cs->aifunc = AIFunc_BattleAmbush; + return "AIFunc_BattleAmbush"; +} + +/* +============ +AIFunc_BattleChase() +============ +*/ +char *AIFunc_BattleChase( cast_state_t *cs ) { + const float chaseDist = 32; + gentity_t *followent, *ent; + bot_state_t *bs; + vec3_t destorg; + qboolean moved = qfalse; + gclient_t *client = &level.clients[cs->entityNum]; + char *rval; + float dist; + cast_state_t *ocs; + + ent = &g_entities[cs->entityNum]; + + // + // do we need to avoid a danger? + if ( cs->dangerEntityValidTime >= level.time ) { + if ( !AICast_GetTakeCoverPos( cs, cs->dangerEntity, cs->dangerEntityPos, cs->takeCoverPos ) ) { + // shit?? + } + // go to a position that cannot be seen from the dangerPos + cs->takeCoverTime = cs->dangerEntityValidTime + 1000; + cs->attackcrouch_time = 0; + return AIFunc_AvoidDangerStart( cs ); + } + // + // are we waiting for a door? + if ( cs->doorMarkerTime > level.time - 100 ) { + return AIFunc_DoorMarkerStart( cs, cs->doorMarkerDoor, cs->doorMarkerNum ); + } + + bs = cs->bs; + // + if ( cs->enemyNum < 0 ) { + return AIFunc_IdleStart( cs ); + } + // + // Retreat? + if ( AICast_WantToRetreat( cs ) ) { + if ( AICast_GetTakeCoverPos( cs, cs->enemyNum, cs->vislist[cs->enemyNum].visible_pos, cs->takeCoverPos ) ) { + // go to a position that cannot be seen from the last place we saw the enemy, and wait there for some time + cs->takeCoverTime = level.time + 2000 + rand() % 3000; + return AIFunc_BattleTakeCoverStart( cs ); + } + } + // + ocs = AICast_GetCastState( cs->enemyNum ); + // + if ( cs->aiFlags & AIFL_ATTACK_CROUCH ) { + if ( cs->attackcrouch_time > level.time || ( cs->thinkFuncChangeTime < level.time - 1000 ) ) { + cs->attackcrouch_time = level.time + 1000; + } + } + // + followent = &g_entities[cs->enemyNum]; + // + // if the entity is not ready yet + if ( !followent->inuse ) { + // if it's a connecting client, wait + if ( !( ( cs->enemyNum < MAX_CLIENTS ) + && ( ( followent->client && followent->client->pers.connected == CON_CONNECTING ) + || ( level.time < 3000 ) ) ) ) { // they don't exist anymore, stop attacking + cs->enemyNum = -1; + } + + return AIFunc_IdleStart( cs ); + } + // + // if we can see them, go back to an attack state + AICast_ChooseWeapon( cs, qtrue ); // enable special weapons, if we cant get them, change back + if ( AICast_EntityVisible( cs, cs->enemyNum, qtrue ) // take into account reaction time + && AICast_CheckAttack( cs, cs->enemyNum, qfalse ) + && cs->obstructingTime < level.time ) { + if ( AICast_StopAndAttack( cs ) ) { + // TTimo: gcc: suggest () around assignment used as truth value + if ( ( rval = AIFunc_BattleStart( cs ) ) ) { + return rval; + } + } else { // just attack them now and keep chasing + AICast_ProcessAttack( cs ); + } + AICast_ChooseWeapon( cs, qfalse ); + } else + { + AICast_ChooseWeapon( cs, qfalse ); + // not visible, go to their previously visible position + /* + if (!cs->vislist[cs->enemyNum].visible_timestamp || Distance( bs->origin, cs->vislist[cs->enemyNum].visible_pos ) < 16) + { + // we're done attacking, go back to default state, which in turn will recall previous state + // + return AIFunc_DefaultStart( cs ); + } + */ + } + // + // find the chase position + if ( followent->client ) { + // go to the last visible position + VectorCopy( cs->vislist[cs->enemyNum].visible_pos, destorg ); + // if we have reached it, go into hunt mode + if ( ( dist = Distance( destorg, cs->bs->origin ) ) < chaseDist ) { + // if we haven't been hunted for a while, do so + if ( ocs->lastBattleHunted < level.time - 5000 ) { + ocs->lastBattleHunted = level.time; + return AIFunc_BattleHuntStart( cs ); + } + // otherwise, go into ambush mode + if ( AICast_GetTakeCoverPos( cs, cs->enemyNum, cs->vislist[cs->enemyNum].real_visible_pos, cs->takeCoverPos ) ) { + VectorCopy( cs->vislist[cs->enemyNum].real_visible_pos, cs->combatGoalOrigin ); + return AIFunc_BattleAmbushStart( cs ); + } + // couldn't find a spot, so just stay here? + VectorCopy( cs->bs->origin, cs->combatGoalOrigin ); + VectorCopy( cs->bs->origin, cs->takeCoverPos ); + return AIFunc_BattleAmbushStart( cs ); + } + } else // assume we know where other entities are + { + VectorCopy( followent->s.pos.trBase, destorg ); + dist = Distance( cs->bs->origin, destorg ); + } + // + // if the enemy is inside a CONTENTS_DONOTENTER brush, and we are close enough, stop chasing them + if ( AICast_EntityVisible( cs, cs->enemyNum, qtrue ) && VectorDistance( cs->bs->origin, destorg ) < 384 ) { + if ( trap_PointContents( destorg, cs->enemyNum ) & ( CONTENTS_DONOTENTER | CONTENTS_DONOTENTER_LARGE ) ) { + // just stay here, and hope they move out of the brush without finding a spot where they can hit us but we can't hit them + return NULL; + } + } + // + // is there someone else we can go for instead? + numEnemies = AICast_ScanForEnemies( cs, enemies ); + if ( numEnemies == -1 ) { // query mode + return NULL; + } else if ( numEnemies == -2 ) { // inspection may be required + char *retval; + // TTimo: gcc: suggest () around assignment used as truth value + if ( ( retval = AIFunc_InspectFriendlyStart( cs, enemies[0] ) ) ) { + return retval; + } + } + AICast_ChooseWeapon( cs, qtrue ); // enable special weapons, if we cant get them, change back + if ( numEnemies > 0 ) { + int i; + for ( i = 0; i < numEnemies; i++ ) { + if ( enemies[i] != cs->enemyNum && AICast_CheckAttack( cs, enemies[i], qfalse ) ) { + cs->enemyNum = enemies[i]; + return AIFunc_BattleStart( cs ); + } + } + } + AICast_ChooseWeapon( cs, qfalse ); + + // + // if we only recently saw them, face them + // + /* RF: disabled 9/19/01, characters like boss2 supersoldier are forced to walk backwards and look wierd + if (cs->vislist[cs->enemyNum].visible_timestamp > level.time - 3000) { + AICast_AimAtEnemy( cs ); // be ready for an attack if they become visible again + //if (cs->attributes[ATTACK_CROUCH] > 0.1) { // crouching for combat + // cs->attackcrouch_time = level.time + 1000; + //} + } + */ + + // + // Lob a Grenade? + // if we haven't thrown a grenade in a bit, go into "grenade flush mode" + if ( ( lastGrenadeFlush > level.time || lastGrenadeFlush < level.time - 5000 ) && + ( cs->aiState >= AISTATE_COMBAT ) && + ( cs->castScriptStatus.castScriptEventIndex < 0 ) && + ( cs->startGrenadeFlushTime < level.time - 3000 ) && + ( COM_BitCheck( cs->bs->cur_ps.weapons, WP_GRENADE_LAUNCHER ) ) && + ( AICast_GotEnoughAmmoForWeapon( cs, WP_GRENADE_LAUNCHER ) ) && + ( cs->weaponFireTimes[WP_GRENADE_LAUNCHER] < level.time - (int)( 1000 + aicast_skillscale * 1000 ) ) && + ( ( cs->weaponNum == WP_GRENADE_LAUNCHER ) || !( cs->castScriptStatus.scriptFlags & SFL_NOCHANGEWEAPON ) ) && + ( Distance( cs->bs->origin, cs->vislist[cs->enemyNum].visible_pos ) > 100 ) && + ( Distance( cs->bs->origin, cs->vislist[cs->enemyNum].visible_pos ) < 1400 ) ) { + // try and flush them out with a grenade + //G_Printf("pineapple?\n"); + return AIFunc_GrenadeFlushStart( cs ); + } else if ( ( lastGrenadeFlush > level.time || lastGrenadeFlush < level.time - 5000 ) && + ( cs->aiState >= AISTATE_COMBAT ) && + ( cs->castScriptStatus.castScriptEventIndex < 0 ) && + ( cs->startGrenadeFlushTime < level.time - 3000 ) && + ( COM_BitCheck( cs->bs->cur_ps.weapons, WP_GRENADE_PINEAPPLE ) ) && + ( AICast_GotEnoughAmmoForWeapon( cs, WP_GRENADE_PINEAPPLE ) ) && + ( cs->weaponFireTimes[WP_GRENADE_PINEAPPLE] < level.time - (int)( 1000 + aicast_skillscale * 1000 ) ) && + ( ( cs->weaponNum == WP_GRENADE_PINEAPPLE ) || !( cs->castScriptStatus.scriptFlags & SFL_NOCHANGEWEAPON ) ) && + ( Distance( cs->bs->origin, cs->vislist[cs->enemyNum].visible_pos ) > 100 ) && + ( Distance( cs->bs->origin, cs->vislist[cs->enemyNum].visible_pos ) < 1400 ) ) { + // try and flush them out with a grenade + //G_Printf("pineapple?\n"); + return AIFunc_GrenadeFlushStart( cs ); + } + // + // Flaming Zombie? Shoot flames while running + if ( ( cs->aiCharacter == AICHAR_ZOMBIE ) && + ( IS_FLAMING_ZOMBIE( ent->s ) ) && + ( fabs( cs->ideal_viewangles[YAW] - cs->viewangles[YAW] ) < 5 ) ) { + if ( fabs( sin( ( level.time + cs->entityNum * 314 ) / 1000 ) * cos( ( level.time + cs->entityNum * 267 ) / 979 ) ) < 0.5 ) { + ent->s.time = level.time + 800; + } + } + // reload? + AICast_IdleReload( cs ); + + if ( dist < chaseDist ) { + return NULL; + } + + // + // go to them + // + // ........................................................... + // Do the movement.. + // + // move straight to them if we can + if ( !moved && cs->leaderNum < 0 && + ( cs->bs->cur_ps.groundEntityNum != ENTITYNUM_NONE || g_entities[cs->entityNum].waterlevel > 1 ) && + AICast_EntityVisible( cs, cs->enemyNum, qtrue ) ) { + aicast_predictmove_t move; + vec3_t dir; + bot_input_t bi; + usercmd_t ucmd; + trace_t tr; + + // trace will eliminate most unsuccessful paths + trap_Trace( &tr, cs->bs->origin, NULL, NULL, followent->r.currentOrigin, cs->entityNum, g_entities[cs->entityNum].clipmask ); + if ( tr.entityNum == followent->s.number ) { + // try walking straight to them + VectorSubtract( followent->r.currentOrigin, cs->bs->origin, dir ); + VectorNormalize( dir ); + if ( !ent->waterlevel ) { + dir[2] = 0; + } + //trap_EA_Move(cs->entityNum, dir, 400); + trap_EA_GetInput( cs->entityNum, (float) level.time / 1000, &bi ); + VectorCopy( dir, bi.dir ); + bi.speed = 400; + bi.actionflags = 0; + AICast_InputToUserCommand( cs, &bi, &ucmd, bs->cur_ps.delta_angles ); + AICast_PredictMovement( cs, 5, 2.0, &move, &ucmd, cs->enemyNum ); + + if ( move.stopevent == PREDICTSTOP_HITENT ) { // success! + trap_EA_Move( cs->entityNum, dir, 400 ); + // RF, if we are really close, we might be stuck on a corner, so randomly move sideways + if ( ( VectorLength( followent->client->ps.velocity ) < 50 ) && ( dist < 10 + ( sqrt( cs->bs->cur_ps.maxs[0] * cs->bs->cur_ps.maxs[0] * 8.0 ) / 2.0 + sqrt( followent->client->ps.maxs[0] * followent->client->ps.maxs[0] * 8.0 ) / 2.0 ) ) ) { + // if the box trace is unsuccessful + trap_Trace( &tr, cs->bs->origin, cs->bs->cur_ps.mins, cs->bs->cur_ps.maxs, followent->r.currentOrigin, cs->entityNum, g_entities[cs->entityNum].clipmask ); + if ( tr.entityNum != followent->s.number ) { + if ( level.time % 6000 < 2000 ) { + trap_EA_MoveRight( cs->entityNum ); + } else { + trap_EA_MoveLeft( cs->entityNum ); + } + } + } + vectoangles( dir, cs->ideal_viewangles ); + cs->ideal_viewangles[2] *= 0.5; + moved = qtrue; + } else { // clear movement + //trap_EA_Move(cs->entityNum, dir, 0); + } + } + } + // + // if they are visible, but not attackable, look for a spot where we can attack them, and head + // for there. This should prevent AI's getting stuck in a bunch. + if ( !moved && cs->weaponNum >= WP_LUGER && cs->weaponNum <= WP_AKIMBO && cs->attributes[TACTICAL] >= 0.1 ) { + // + // check for another movement we should be making + if ( cs->obstructingTime > level.time ) { + AICast_MoveToPos( cs, cs->obstructingPos, -1 ); + moved = qtrue; + } + // + if ( cs->leaderNum >= 0 ) { + if ( cs->combatGoalTime < level.time ) { + if ( cs->attackSpotTime < level.time ) { + cs->attackSpotTime = level.time + 500 + rand() % 500; + if ( trap_AAS_FindAttackSpotWithinRange( cs->entityNum, cs->leaderNum, cs->enemyNum, MAX_LEADER_DIST, AICAST_TFL_DEFAULT, cs->combatGoalOrigin ) ) { + cs->combatGoalTime = level.time + 2000; + } + } + } + if ( cs->combatGoalTime > level.time ) { + if ( Distance( cs->combatGoalOrigin, g_entities[cs->leaderNum].r.currentOrigin ) > MAX_LEADER_DIST ) { + // go find a new combatSpot + cs->combatGoalTime = 0; + } else { + // go to the combat spot + moveresult = AICast_MoveToPos( cs, cs->combatGoalOrigin, -1 ); + if ( moveresult && moveresult->failure ) { // no path, so go back to idle behaviour + cs->combatGoalTime = 0; + } else { + moved = qtrue; + if ( Distance( cs->bs->origin, cs->combatGoalOrigin ) < 32 ) { + cs->combatGoalTime = 0; + } + } + } + } else { + // we can't find a way to get to our enemy, so go back to our leader if outside range + // do we need to go to our leader? + if ( Distance( cs->bs->origin, g_entities[cs->leaderNum].r.currentOrigin ) > MAX_LEADER_DIST ) { + return AIFunc_ChaseGoalStart( cs, cs->leaderNum, AICAST_LEADERDIST_MAX, qtrue ); + } + } + } else { + if ( cs->combatGoalTime < level.time ) { + if ( cs->attackSpotTime < level.time ) { + cs->attackSpotTime = level.time + 500 + rand() % 500; + if ( trap_AAS_FindAttackSpotWithinRange( cs->entityNum, cs->entityNum, cs->enemyNum, 512, AICAST_TFL_DEFAULT, cs->combatGoalOrigin ) ) { + cs->combatGoalTime = level.time + 2000; + } + } + } + if ( cs->combatGoalTime > level.time ) { + // go to the combat spot + moveresult = AICast_MoveToPos( cs, cs->combatGoalOrigin, -1 ); + if ( moveresult && moveresult->failure ) { // no path, so go back to idle behaviour + cs->combatGoalTime = 0; + } else { + moved = qtrue; + if ( Distance( cs->bs->origin, cs->combatGoalOrigin ) < 32 ) { + cs->combatGoalTime = 0; + cs->attackSpotTime = level.time + 12000; // dont go to another combatspot for some time, prevent repetitive behaviour + } + } + } + } + } + // just go to them + if ( !moved && cs->leaderNum < 0 ) { + moveresult = AICast_MoveToPos( cs, destorg, cs->enemyNum ); + if ( moveresult && moveresult->failure ) { // no path, so try and hude from them + // pausetime has expired, so go into ambush mode + if ( AICast_GetTakeCoverPos( cs, cs->enemyNum, cs->vislist[cs->enemyNum].real_visible_pos, cs->takeCoverPos ) ) { + // wait in ambush, for them to return + VectorCopy( cs->bs->origin, cs->combatGoalOrigin ); + return AIFunc_BattleAmbushStart( cs ); + } + // HACK, help lopers get out of bad spots + if ( cs->aiCharacter == AICHAR_LOPER ) { + cs->weaponFireTimes[WP_MONSTER_ATTACK2] = 0; + } + // couldn't find a spot, so just stay here? + if ( cs->bs->areanum ) { // if our area is valid + VectorCopy( cs->bs->origin, cs->combatGoalOrigin ); + VectorCopy( cs->bs->origin, cs->takeCoverPos ); + return AIFunc_BattleAmbushStart( cs ); + } + } else { + moved = qtrue; + } + } + // + // slow down real close to the goal, so we don't go passed it + cs->speedScale = AICast_SpeedScaleForDistance( cs, dist, chaseDist ); + // + // ........................................................... + // speed up over some time + #define BATTLE_CHASE_ACCEL_TIME 300 + if ( ( cs->attributes[RUNNING_SPEED] > 170 ) && ( cs->weaponNum != WP_GAUNTLET ) && ( level.time < ( cs->startBattleChaseTime + BATTLE_CHASE_ACCEL_TIME ) ) ) { + float ideal; + + ideal = 0.5 + 0.5 * ( 1.0 - ( (float)( ( cs->startBattleChaseTime + BATTLE_CHASE_ACCEL_TIME ) - level.time ) / BATTLE_CHASE_ACCEL_TIME ) ); + if ( ideal < cs->speedScale ) { + cs->speedScale = ideal; + } + } + // + // if we are going to reach them soon, predict the attack + { + float simTime = 1.5; + aicast_predictmove_t move; + float moveDist; + vec3_t vec; + // + if ( cs->weaponNum == WP_GAUNTLET ) { + simTime = 0.5; + } + // + AICast_PredictMovement( cs, 1, simTime, &move, &cs->lastucmd, cs->enemyNum ); + VectorSubtract( move.endpos, cs->bs->origin, vec ); + moveDist = VectorNormalize( vec ); + // + if ( cs->weaponNum == WP_GAUNTLET ) { + if ( move.stopevent == PREDICTSTOP_HITENT ) { + AICast_AimAtEnemy( cs ); + trap_EA_Attack( bs->client ); + cs->bFlags |= BFL_ATTACKED; + } + } + // + // do we went to play a diving animation into a cover position? + else if ( ( ( cs->attributes[TACTICAL] > 0.85 ) && ( cs->aiFlags & AIFL_ROLL_ANIM ) && !client->ps.torsoTimer && !client->ps.legsTimer && ( cs->lastRollMove < level.time - 800 ) && ( move.numtouch == 0 ) && ( moveDist > simTime * cs->attributes[RUNNING_SPEED] * 0.98 ) && move.groundEntityNum == ENTITYNUM_WORLD ) && + ( AICast_CheckAttackAtPos( cs->entityNum, cs->enemyNum, move.endpos, cs->attackcrouch_time > level.time, qfalse ) ) ) { + cs->takeCoverTime = 0; + return AIFunc_BattleRollStart( cs, vec ); + } + // + else if ( cs->aiFlags & AIFL_FLIP_ANIM && cs->lastRollMove < level.time - 800 && !client->ps.torsoTimer && cs->castScriptStatus.castScriptEventIndex < 0 && move.numtouch == 0 && moveDist > simTime * cs->attributes[RUNNING_SPEED] * 0.9 && move.groundEntityNum == ENTITYNUM_WORLD && cs->attackcrouch_time < level.time ) { + int destarea, simarea, starttravel, simtravel; + // if we'll be closer after the move, proceed + destarea = BotPointAreaNum( destorg ); + simarea = BotPointAreaNum( move.endpos ); + starttravel = trap_AAS_AreaTravelTimeToGoalArea( cs->bs->areanum, cs->bs->origin, destarea, cs->travelflags ); + simtravel = trap_AAS_AreaTravelTimeToGoalArea( simarea, move.endpos, destarea, cs->travelflags ); + if ( simtravel < starttravel ) { + return AIFunc_FlipMoveStart( cs, vec ); + } + } + // slow down? so we don't go too far from behind the obstruction which is protecting us + else if ( !( cs->aiFlags & AIFL_WALKFORWARD ) && ( VectorDistance( cs->bs->origin, g_entities[cs->enemyNum].s.pos.trBase ) < AICast_WeaponRange( cs, cs->weaponNum ) ) && + ( cs->obstructingTime < level.time ) && ( cs->attributes[TACTICAL] > 0.1 ) && + ( AICast_VisibleFromPos( cs->vislist[cs->enemyNum].visible_pos, cs->enemyNum, move.endpos, cs->entityNum, qfalse ) ) ) { + // start a crouch attack? + //if (cs->attributes[ATTACK_CROUCH] > 0.1) { + // cs->attackcrouch_time = level.time + 3000; + //else + cs->attackcrouch_time = 0; + if ( cs->bs->cur_ps.viewheight > cs->bs->cur_ps.crouchViewHeight && cs->attributes[RUNNING_SPEED] * cs->speedScale > 120 ) { + cs->speedScale = 120.0 * cs->attributes[RUNNING_SPEED]; + } + // also face them, ready for the attack + if ( cs->attributes[RUNNING_SPEED] > 140 ) { + AICast_AimAtEnemy( cs ); + } + /* disabled, causes them to use up ammo in the clip before they get visible + if ((cs->castScriptStatus.scriptNoAttackTime < level.time) && (cs->noAttackTime < level.time)) { + // if we are using a bullet weapon, start firing now + switch (cs->weaponNum) { + case WP_MP40: + case WP_VENOM: + case WP_THOMPSON: + case WP_STEN: //----(SA) added + trap_EA_Attack(cs->entityNum); + } + } + */ + } + } + + // reload? + AICast_IdleReload( cs ); + + return NULL; +} + +/* +============ +AIFunc_BattleChaseStart() +============ +*/ +char *AIFunc_BattleChaseStart( cast_state_t *cs ) { + cs->startBattleChaseTime = level.time; + cs->combatGoalTime = 0; + cs->battleChaseMarker = -99; + cs->battleChaseMarkerDir = 1; + // don't wait too long before taking cover, if we just aborted one + if ( cs->takeCoverTime > level.time ) { + cs->takeCoverTime = level.time + 1500 + rand() % 500; + } + // + // start a crouch attack? + if ( cs->attributes[ATTACK_CROUCH] > 0.1 ) { + cs->aiFlags |= AIFL_ATTACK_CROUCH; + } else { + cs->aiFlags &= ~AIFL_ATTACK_CROUCH; + } + // + cs->aifunc = AIFunc_BattleChase; + return "AIFunc_BattleChase"; +} + +/* +============ +AIFunc_AvoidDanger() +============ +*/ +char *AIFunc_AvoidDanger( cast_state_t *cs ) { + bot_state_t *bs; + vec3_t destorg, vec; + float dist; + int enemies[MAX_CLIENTS], numEnemies, i; + qboolean shouldAttack; + gentity_t *ent; + trace_t tr; + vec3_t end; + gentity_t *danger; + + // we need to move towards it + bs = cs->bs; + ent = g_entities + cs->entityNum; + // + // TODO: if we are on fire, play the correct torso animation + if ( ent->s.onFireEnd > level.time ) { + // set the animation, and a short timer, but long enough to last until the next frame + //if (g_cheats.integer) G_Printf( "TODO: torso onfire animation\n" ); + } + // + // is the danger gone? + if ( cs->dangerEntityValidTime < level.time ) { + return AIFunc_DefaultStart( cs ); + } + // + // special case: if it's a grenade, and it's going to land near us with some time left before it + // explodes, try and kick it back + // + danger = &g_entities[cs->dangerEntity]; + if ( ent->s.onFireEnd < level.time ) { + if ( ( danger->s.weapon == WP_GRENADE_LAUNCHER || danger->s.weapon == WP_GRENADE_PINEAPPLE ) && + ( danger->nextthink - level.time > 1500 ) && + ( level.lastGrenadeKick < level.time - 3000 ) && + ( cs->aiFlags & AIFL_CATCH_GRENADE ) && + !( danger->flags & FL_AI_GRENADE_KICK ) ) { + // if it was thrown by a friend of ours, leave it alone + if ( !AICast_SameTeam( cs, danger->r.ownerNum ) ) { + if ( G_PredictMissile( danger, danger->nextthink - level.time, cs->takeCoverPos, qfalse ) ) { + // make sure it's a valid position, and drop it down to the ground + cs->takeCoverPos[2] += -ent->r.mins[2] + 12; + VectorCopy( cs->takeCoverPos, end ); + end[2] -= 90; + trap_Trace( &tr, cs->takeCoverPos, ent->r.mins, ent->r.maxs, end, cs->entityNum, MASK_SOLID ); + VectorCopy( tr.endpos, cs->takeCoverPos ); + if ( !tr.startsolid && ( tr.fraction < 1.0 ) && + VectorDistance( cs->bs->origin, cs->takeCoverPos ) < cs->attributes[RUNNING_SPEED] * 0.0004 * ( danger->nextthink - level.time - 2000 ) ) { + + // check for a clear path to the grenade + trap_Trace( &tr, cs->bs->origin, ent->r.mins, ent->r.maxs, cs->takeCoverPos, cs->entityNum, MASK_SOLID ); + + if ( VectorDistance( tr.endpos, cs->takeCoverPos ) < 8 ) { + danger->flags |= FL_AI_GRENADE_KICK; + ent->flags |= FL_AI_GRENADE_KICK; + level.lastGrenadeKick = level.time; + return AIFunc_GrenadeKickStart( cs ); // we should decide our course of action within this start function (dive or return grenade) + } + } + } + } + // if it's really close to us, and we're heading for it, may as well pick it up + if ( VectorLength( danger->s.pos.trDelta ) < 10 && VectorDistance( danger->r.currentOrigin, cs->bs->origin ) < 128 && + ( level.lastGrenadeKick < level.time - 3000 ) && + ( cs->aiFlags & AIFL_CATCH_GRENADE ) ) { + vec3_t vec; + VectorSubtract( danger->r.currentOrigin, cs->bs->origin, vec ); + if ( DotProduct( vec, cs->bs->velocity ) > 0 ) { + danger->flags |= FL_AI_GRENADE_KICK; + ent->flags |= FL_AI_GRENADE_KICK; + level.lastGrenadeKick = level.time; + return AIFunc_GrenadeKickStart( cs ); // we should decide our course of action within this start function (dive or return grenade) + } + } + } + } + // + if ( g_entities[cs->dangerEntity].inuse ) { + // is our current destination still safe? + if ( Distance( cs->dangerEntityPos, cs->takeCoverPos ) < cs->dangerDist && + AICast_VisibleFromPos( cs->dangerEntityPos, cs->dangerEntity, cs->takeCoverPos, cs->entityNum, qfalse ) ) { + //G_Printf("current coverPos is dangerous, looking for a better place..\n" ); + if ( !AICast_GetTakeCoverPos( cs, cs->dangerEntity, cs->dangerEntityPos, cs->takeCoverPos ) ) { + // just run away from it ??? + } + } + } else { + // the entity isn't here anymore, so stop hiding + cs->dangerEntityValidTime = -1; + return AIFunc_DefaultStart( cs ); + } + // + VectorCopy( cs->takeCoverPos, destorg ); + VectorSubtract( destorg, cs->bs->origin, vec ); + vec[2] *= 0.2; + dist = VectorLength( vec ); + // + shouldAttack = qfalse; + if ( ent->s.onFireEnd < level.time ) { + // look for things we should attack + numEnemies = AICast_ScanForEnemies( cs, enemies ); + if ( numEnemies > 0 ) { + // default to the first known enemy, overwrite if we find a clearer shot + cs->enemyNum = enemies[0]; + // + for ( i = 0; i < numEnemies; i++ ) { + if ( AICast_CheckAttack( cs, enemies[i], qfalse ) || AICast_CheckAttack( AICast_GetCastState( enemies[i] ), cs->entityNum, qfalse ) ) { + cs->enemyNum = enemies[i]; + shouldAttack = qtrue; + break; + } else if ( cs->enemyNum < 0 ) { + cs->lastEnemy = enemies[i]; + } + } + } + } + // + // if we are now safe from the danger, stop running away + if ( cs->dangerEntity >= MAX_CLIENTS && Distance( cs->dangerEntityPos, cs->bs->origin ) > cs->dangerDist * 1.5 ) { + // don't move, wait for danger to pass + } else + // are we close enough to the goal? + if ( dist > 8 ) { + moveresult = AICast_MoveToPos( cs, destorg, -1 ); + if ( moveresult ) { + //if the movement failed + if ( moveresult->failure || moveresult->blocked ) { + //reset the avoid reach, otherwise bot is stuck in current area + trap_BotResetAvoidReach( bs->ms ); + if ( g_entities[cs->dangerEntity].inuse ) { + // find a better spot? + AICast_GetTakeCoverPos( cs, cs->dangerEntity, cs->dangerEntityPos, cs->takeCoverPos ); + } else { + VectorCopy( cs->bs->origin, cs->takeCoverPos ); + } + } + } + if ( ent->s.onFireEnd < level.time ) { + // slow down real close to the goal, so we don't go passed it + cs->speedScale = AICast_SpeedScaleForDistance( cs, dist, 0 ); + } + // + // pretend we can still see them while we run to our hide pos, this way they are less likely + // to forget about their enemy once they get there + if ( ent->s.onFireEnd < level.time && cs->enemyNum >= 0 && cs->vislist[cs->enemyNum].real_visible_timestamp && ( cs->vislist[cs->enemyNum].real_visible_timestamp > level.time - 10000 ) ) { + AICast_UpdateVisibility( &g_entities[cs->entityNum], &g_entities[cs->enemyNum], qfalse, cs->vislist[cs->enemyNum].real_visible_timestamp == cs->vislist[cs->enemyNum].lastcheck_timestamp ); + } + + } else { + // set our origin as the hidepos, that way if we are still in danger, we should find a better spot + VectorCopy( cs->bs->origin, cs->takeCoverPos ); + // check for a movement we should be making + if ( cs->obstructingTime > level.time ) { + AICast_MoveToPos( cs, cs->obstructingPos, -1 ); + } + + // if we are on fire, never stop + if ( ent->s.onFireEnd > level.time ) { + VectorCopy( cs->bs->origin, cs->dangerEntityPos ); + cs->dangerEntityValidTime = level.time + 10000; + } + + } + // + // if we should be attacking something on our way + if ( shouldAttack ) { + //attack the enemy if possible + AICast_ProcessAttack( cs ); + } else { //if (dist < 48) { + // if we've recently been in a fight, look towards the enemy + if ( cs->lastEnemy >= 0 ) { + // if we only just recently saw them, face that direction + if ( cs->vislist[cs->lastEnemy].visible_timestamp > ( level.time - 20000 ) ) { + vec3_t dir; + // + VectorSubtract( cs->vislist[cs->lastEnemy].visible_pos, cs->bs->origin, dir ); + VectorNormalize( dir ); + vectoangles( dir, cs->ideal_viewangles ); + } + } + } + + // reload? + AICast_IdleReload( cs ); + + return NULL; +} + +/* +============ +AIFunc_AvoidDangerStart() +============ +*/ +char *AIFunc_AvoidDangerStart( cast_state_t *cs ) { + // + //if (!AICast_CanMoveWhileFiringWeapon( cs->weaponNum )) { + // always run to the cover point + cs->attackcrouch_time = 0; + //} + // make sure we move if we are allowed (scripting will overwrite this if necessary) + cs->castScriptStatus.scriptNoMoveTime = 0; + // resume following once danger has gone + cs->castScriptStatus.scriptGotoId = -1; + // + cs->aifunc = AIFunc_AvoidDanger; + return "AIFunc_AvoidDanger"; +} + +/* +============ +AIFunc_BattleTakeCover() +============ +*/ +char *AIFunc_BattleTakeCover( cast_state_t *cs ) { + bot_state_t *bs; + vec3_t destorg, vec; + float dist, moveDist; + int enemies[MAX_CLIENTS], numEnemies, i; + qboolean shouldAttack; + aicast_predictmove_t move; + int *ammo; + gclient_t *client = &level.clients[cs->entityNum]; + // + // do we need to avoid a danger? + if ( cs->dangerEntityValidTime >= level.time ) { + if ( !AICast_GetTakeCoverPos( cs, cs->dangerEntity, cs->dangerEntityPos, cs->takeCoverPos ) ) { + // shit?? + } + // go to a position that cannot be seen from the dangerPos + cs->takeCoverTime = cs->dangerEntityValidTime + 1000; + cs->attackcrouch_time = 0; + return AIFunc_AvoidDangerStart( cs ); + } + // + // are we waiting for a door? + if ( cs->doorMarkerTime > level.time - 100 ) { + return AIFunc_DoorMarkerStart( cs, cs->doorMarkerDoor, cs->doorMarkerNum ); + } + + // we need to move towards it + bs = cs->bs; + // + // note: removing this will cause problems down below! + if ( cs->enemyNum < 0 ) { + return AIFunc_IdleStart( cs ); + } + // + if ( VectorLength( cs->takeCoverPos ) < 1 ) { + dist = 0; + } else { + VectorCopy( cs->takeCoverPos, destorg ); + VectorSubtract( destorg, cs->bs->origin, vec ); + vec[2] *= 0.2; + dist = VectorLength( vec ); + } + // + // look for things we should attack + // if we are out of ammo, we shouldn't bother trying to attack (and we should keep hiding) + ammo = cs->bs->cur_ps.ammo; + shouldAttack = qfalse; + numEnemies = AICast_ScanForEnemies( cs, enemies ); + if ( numEnemies == -1 ) { // query mode + return NULL; + } else if ( numEnemies == -2 ) { // inspection may be required + char *retval; + // TTimo: gcc: suggest () around assignment used as truth value + if ( ( retval = AIFunc_InspectFriendlyStart( cs, enemies[0] ) ) ) { + return retval; + } + } else if ( numEnemies == -3 ) { // bullet impact + if ( cs->aiState < AISTATE_COMBAT ) { + return AIFunc_InspectBulletImpactStart( cs ); + } + } else if ( numEnemies == -4 ) { // audible event + if ( cs->aiState < AISTATE_COMBAT ) { + return AIFunc_InspectAudibleEventStart( cs, cs->audibleEventEnt ); + } + } else if ( numEnemies > 0 ) { + + if ( AICast_GotEnoughAmmoForWeapon( cs, cs->weaponNum ) ) { + // default to the first known enemy, overwrite if we find a clearer shot + cs->enemyNum = enemies[0]; + // + for ( i = 0; i < numEnemies; i++ ) { + if ( AICast_CheckAttack( cs, enemies[i], qfalse ) || AICast_CheckAttack( AICast_GetCastState( enemies[i] ), cs->entityNum, qfalse ) || + AICast_EntityVisible( AICast_GetCastState( enemies[i] ), cs->entityNum, qtrue ) ) { + if ( ( cs->aiFlags & AIFL_WALKFORWARD ) || ( dist <= 12 ) ) { + // we are at our hidepos, abort! + cs->enemyNum = enemies[i]; + return AIFunc_BattleStart( cs ); + } else { + shouldAttack = qtrue; // fire at them as we go + } + } else if ( cs->enemyNum < 0 ) { + cs->lastEnemy = enemies[i]; + } + } + + } else { + AICast_ChooseWeapon( cs, qfalse ); + // + if ( dist <= 12 ) { + if ( !AICast_GotEnoughAmmoForWeapon( cs, cs->weaponNum ) ) { + // NO AMMO LEFT!! + // hide? + if ( AICast_GetTakeCoverPos( cs, cs->enemyNum, cs->vislist[cs->enemyNum].visible_pos, cs->takeCoverPos ) ) { + // go to a position that cannot be seen from the last place we saw the enemy, and wait there for some time + cs->takeCoverTime = level.time + 2000 + rand() % 3000; + //return AIFunc_BattleTakeCoverStart( cs ); + } + } + } + } + + } + // + //if (!shouldAttack) + // always do this check, if our destination sucks, abort it + { + // if the enemy can see our hide position, find a better spot + if ( AICast_VisibleFromPos( cs->vislist[cs->enemyNum].visible_pos, cs->enemyNum, cs->takeCoverPos, bs->entitynum, qfalse ) ) { + if ( !AICast_GetTakeCoverPos( cs, cs->enemyNum, cs->vislist[cs->enemyNum].visible_pos, cs->takeCoverPos ) ) { + // shit!! umm.. try and fire? + return AIFunc_BattleStart( cs ); + } else { // recalc distance + VectorCopy( cs->takeCoverPos, destorg ); + VectorSubtract( destorg, cs->bs->origin, vec ); + vec[2] *= 0.2; + dist = VectorLength( vec ); + } + } else if ( dist < 8 ) { + // if they can see us, find a better spot + if ( AICast_EntityVisible( AICast_GetCastState( cs->enemyNum ), cs->entityNum, qtrue ) || AICast_CheckAttack( AICast_GetCastState( cs->enemyNum ), cs->entityNum, qfalse ) ) { + if ( !AICast_GetTakeCoverPos( cs, cs->enemyNum, cs->vislist[cs->enemyNum].visible_pos, cs->takeCoverPos ) ) { + // shit!! umm.. try and fire? + return AIFunc_BattleStart( cs ); + } else { // recalc distance + VectorCopy( cs->takeCoverPos, destorg ); + VectorSubtract( destorg, cs->bs->origin, vec ); + vec[2] *= 0.2; + dist = VectorLength( vec ); + } + } + } + //cs->takeCoverTime = level.time + 1000; + } + // + // pretend we can still see them while we run to our hide pos, this way they are less likely + // to forget about their enemy once they get there +// DISABLED: doesn't work well with new AI system + //if (cs->enemyNum >= 0 && cs->vislist[cs->enemyNum].real_visible_timestamp && (cs->vislist[cs->enemyNum].real_visible_timestamp > level.time - 2000)) { + // AICast_UpdateVisibility( &g_entities[cs->entityNum], &g_entities[cs->enemyNum], qfalse, cs->vislist[cs->enemyNum].real_visible_timestamp == cs->vislist[cs->enemyNum].lastcheck_timestamp ); + //} + // + memset( &move, 0, sizeof( move ) ); + // + // are we close enough to the goal? + if ( VectorLength( cs->takeCoverPos ) > 1 && dist > 8 ) { + const float simTime = 1.5; + float enemyDist; + // + // we haven't reached it yet, make sure we at least wait there for a few seconds after arriving + cs->takeCoverTime = level.time + 2000 + rand() % 2000; + // + moveresult = AICast_MoveToPos( cs, destorg, -1 ); + if ( moveresult ) { + //if the movement failed + if ( moveresult->failure ) { + //reset the avoid reach, otherwise bot is stuck in current area + trap_BotResetAvoidReach( bs->ms ); + // couldn't get there, so stop trying to get there + VectorClear( cs->takeCoverPos ); + dist = 0; + } + // + if ( moveresult->blocked ) { + // abort the TakeCover + VectorClear( cs->takeCoverPos ); + dist = 0; + } + } + // + // if we are going to bump into something soon, abort it + AICast_PredictMovement( cs, 1, simTime, &move, &cs->lastucmd, -1 ); + enemyDist = Distance( cs->bs->origin, g_entities[cs->enemyNum].s.pos.trBase ); + VectorSubtract( move.endpos, cs->bs->origin, vec ); + moveDist = VectorNormalize( vec ); + // + if ( ( move.numtouch && move.touchents[0] < aicast_maxclients ) // hit something + // or moved closer to the enemy + || ( ( enemyDist < 128 ) + && ( ( enemyDist - 1 ) > ( Distance( move.endpos, g_entities[cs->enemyNum].s.pos.trBase ) ) ) ) ) { + // abort the manouver + VectorClear( cs->takeCoverPos ); + dist = 0; + } + // + // do we want to play a rolling animation into a cover position? + else if ( ( cs->aiFlags & AIFL_DIVE_ANIM && !client->ps.torsoTimer && cs->castScriptStatus.castScriptEventIndex < 0 && cs->lastRollMove < level.time - 800 && move.numtouch == 0 && ( moveDist > simTime * cs->attributes[RUNNING_SPEED] * 0.98 ) && move.groundEntityNum == ENTITYNUM_WORLD ) && + ( shouldAttack && !AICast_VisibleFromPos( g_entities[cs->enemyNum].s.pos.trBase, cs->enemyNum, move.endpos, cs->entityNum, qfalse ) ) ) { + VectorClear( cs->takeCoverPos ); // stay there when done rolling + return AIFunc_BattleDiveStart( cs, vec ); + } + // + // we should slow down on approaching the destination point + else if ( dist < 64 ) { + cs->speedScale = AICast_SpeedScaleForDistance( cs, dist, 0 ); + } + // + // if they cant see us, then stay here + if ( !( cs->aiFlags & AIFL_MISCFLAG1 ) && !AICast_VisibleFromPos( cs->vislist[cs->enemyNum].real_visible_pos, cs->enemyNum, move.endpos, cs->entityNum, qfalse ) + && !AICast_VisibleFromPos( cs->vislist[cs->enemyNum].real_visible_pos, cs->enemyNum, cs->bs->origin, cs->entityNum, qfalse ) + && trap_AAS_PointAreaNum( move.endpos ) ) { // make sure the endpos is in a valid area + VectorCopy( move.endpos, cs->takeCoverPos ); + dist = 0; + cs->aiFlags |= AIFL_MISCFLAG1; // dont do this again + } + // + if ( cs->aiFlags & AIFL_FLIP_ANIM && cs->lastRollMove < level.time - 800 && !client->ps.torsoTimer && cs->castScriptStatus.castScriptEventIndex < 0 && move.numtouch == 0 && moveDist > simTime * cs->attributes[RUNNING_SPEED] * 0.9 && move.groundEntityNum == ENTITYNUM_WORLD && cs->attackcrouch_time < level.time ) { + int destarea, simarea, starttravel, simtravel; + // if we'll be closer after the move, proceed + destarea = BotPointAreaNum( destorg ); + simarea = BotPointAreaNum( move.endpos ); + starttravel = trap_AAS_AreaTravelTimeToGoalArea( cs->bs->areanum, cs->bs->origin, destarea, cs->travelflags ); + simtravel = trap_AAS_AreaTravelTimeToGoalArea( simarea, move.endpos, destarea, cs->travelflags ); + if ( simtravel < starttravel ) { + return AIFunc_FlipMoveStart( cs, vec ); + } + } + // set crouching status + //if (dist && (cs->thinkFuncChangeTime < level.time - 2000) && (cs->crouchHideFlag || cs->aiFlags & AIFL_ATTACK_CROUCH)) { + if ( cs->crouchHideFlag || ( ( cs->thinkFuncChangeTime < level.time - 2000 ) && ( cs->aiFlags & AIFL_ATTACK_CROUCH ) ) ) { + cs->attackcrouch_time = level.time + 1000; + } + + } else { + // + // have we been Taking Cover for enough time? + if ( level.time > cs->takeCoverTime ) { + return AIFunc_DefaultStart( cs ); + } + // + // check for a movement we should be making + if ( cs->obstructingTime > level.time ) { + VectorClear( cs->takeCoverPos ); + AICast_MoveToPos( cs, cs->obstructingPos, -1 ); + } + // if we have some enemies that we can attack immediately (without going anywhere to chase them) + if ( shouldAttack ) { + return AIFunc_BattleStart( cs ); + } + // if we have some enemies in sight, but they can't attack us, flee if possible, otherwise if we are not afraid, go attack them + else if ( numEnemies ) { + + // are they reloading? if so we should attack! + if ( g_entities[cs->entityNum].client->ps.weaponDelay < 100 + && g_entities[cs->enemyNum].client->ps.weaponDelay > 1100 ) { + if ( AICast_GotEnoughAmmoForWeapon( cs, cs->weaponNum ) && AICast_WeaponUsable( cs, cs->weaponNum ) ) { + return AIFunc_BattleStart( cs ); + } + } + + // we can't hit them and they cant hit us, so dont bother doing anything + + //if (!AICast_GetTakeCoverPos( cs, cs->enemyNum, cs->vislist[cs->enemyNum].visible_pos, cs->takeCoverPos )) { + //if (!AICast_WantsToTakeCover(cs, qfalse)) + //return AIFunc_BattleStart( cs ); + //} + } + // do we need to go to our leader? + else if ( cs->leaderNum >= 0 && Distance( cs->bs->origin, g_entities[cs->leaderNum].r.currentOrigin ) > MAX_LEADER_DIST ) { + // wait until we've been hiding for long enough + if ( level.time > cs->takeCoverTime ) { + return AIFunc_ChaseGoalStart( cs, cs->leaderNum, AICAST_LEADERDIST_MAX, qtrue ); + } + } + + // else, crouch while we hide + if ( cs->attributes[ATTACK_CROUCH] > 0.1 || cs->crouchHideFlag ) { + cs->attackcrouch_time = level.time + 1000; + } + } + // + // if we should be attacking something on our way + if ( shouldAttack ) { + vec3_t vec, dir; + float dist; + // + // if they are close, and we're heading for them, we should abort this manouver + VectorSubtract( g_entities[cs->enemyNum].client->ps.origin, bs->origin, vec ); + if ( ( dist = VectorNormalize( vec ) ) < 256 ) { + VectorCopy( bs->velocity, vec ); + vec[2] = 0; + if ( VectorNormalize2( vec, dir ) > 20 ) { // we are moving + if ( DotProduct( dir, vec ) > 0.4 ) { + // abort + return AIFunc_BattleStart( cs ); + } + } + } + // + // if the enemy can see our hide position, abort the manouver + if ( ( cs->thinkFuncChangeTime < level.time - 1000 ) && ( AICast_VisibleFromPos( g_entities[cs->enemyNum].client->ps.origin, cs->enemyNum, cs->takeCoverPos, bs->entitynum, qfalse ) ) ) { + // abort + return AIFunc_BattleStart( cs ); + } + // + // if we are tactical and can crouch, do so + if ( !move.numtouch && ( cs->thinkFuncChangeTime < level.time - 2000 ) && ( dist > 128 ) && cs->attributes[TACTICAL] > 0.4 && cs->attributes[ATTACK_CROUCH] > 0.1 && + ( cs->attackcrouch_time >= level.time ) ) { + cs->attackcrouch_time = level.time + 1000; + } + // + //attack the enemy if possible + AICast_ProcessAttack( cs ); + // + } else /*if (dist < 48)*/ { + // if we've recently been in a fight, look towards the enemy + if ( cs->enemyNum >= 0 ) { + AICast_AimAtEnemy( cs ); + } else if ( cs->lastEnemy >= 0 ) { + // if we are not moving, face them + if ( VectorLength( cs->bs->cur_ps.velocity ) < 50 ) { + vec3_t dir; + // + VectorSubtract( cs->vislist[cs->lastEnemy].visible_pos, cs->bs->origin, dir ); + VectorNormalize( dir ); + vectoangles( dir, cs->ideal_viewangles ); + } + } else if ( !cs->crouchHideFlag ) { // no enemy, and no need to crouch, so stop crouching + //if (cs->attackcrouch_time > level.time + 1000) { + // cs->attackcrouch_time = level.time + 1000; + //} + } + // reload? + AICast_IdleReload( cs ); + } + + return NULL; +} + +/* +============ +AIFunc_BattleTakeCoverStart() +============ +*/ +char *AIFunc_BattleTakeCoverStart( cast_state_t *cs ) { +// debugging +#ifdef DEBUG +// if (cs->attributes[AGGRESSION] >= 1.0) +// AICast_Printf( 0, "AI taking cover with full aggression!\n" ); +#endif + + if ( !AICast_CanMoveWhileFiringWeapon( cs->weaponNum ) ) { + // always run to the cover point + cs->attackcrouch_time = 0; + cs->aiFlags &= ~AIFL_ATTACK_CROUCH; + } else { + // if we arent crouching, start crouching soon after we start retreating + if ( cs->attributes[ATTACK_CROUCH] > 0.1 ) { + cs->aiFlags |= AIFL_ATTACK_CROUCH; + } else { + cs->aiFlags &= ~AIFL_ATTACK_CROUCH; + } + cs->attackcrouch_time = 0; + } + + // miscflag1 used to set predicted point as our goal, so we dont keep setting this over and over + cs->aiFlags &= ~AIFL_MISCFLAG1; + + cs->aifunc = AIFunc_BattleTakeCover; + return "AIFunc_BattleTakeCover"; +} + +/* +============ +AIFunc_GrenadeFlush() +============ +*/ +char *AIFunc_GrenadeFlush( cast_state_t *cs ) { + vec3_t dir; + gentity_t *followent, *grenade, *ent; + bot_state_t *bs; + vec3_t destorg, endPos; + qboolean moved = qfalse; + int hitclient; + //qboolean attacked = qfalse; // TTimo: unused + float dist, oldyaw; + int grenadeType; + int *ammo; + + bs = cs->bs; + ent = &g_entities[cs->entityNum]; + // + // if we are throwing the grenade, keep holding down fire + + ammo = cs->bs->cur_ps.ammo; + if ( AICast_GotEnoughAmmoForWeapon( cs, WP_GRENADE_LAUNCHER ) ) { + grenadeType = WP_GRENADE_LAUNCHER; + } else if ( AICast_GotEnoughAmmoForWeapon( cs, WP_GRENADE_PINEAPPLE ) ) { + grenadeType = WP_GRENADE_PINEAPPLE; + } else { // not enough ammo, abort + return AIFunc_DefaultStart( cs ); + } + + // (SA) probably read the fweapon from t + if ( cs->grenadeFlushFiring ) { + // are we still moving? + if ( VectorLength( cs->bs->cur_ps.velocity ) ) { + // keep waiting + // pause for a bit, so the grenade comes out correctly + cs->lockViewAnglesTime = level.time + 1200; + if ( cs->castScriptStatus.scriptNoMoveTime < level.time + 1200 ) { + cs->castScriptStatus.scriptNoMoveTime = level.time + 1200; + } + return NULL; + } + if ( cs->weaponFireTimes[cs->grenadeFlushFiring] < cs->thinkFuncChangeTime ) { + // have we switched weapons? + if ( cs->weaponNum != cs->grenadeFlushFiring ) { + // damn + hitclient = -1; + } else { + // keep checking it's ok + CalcMuzzlePoints( ent, grenadeType ); + // fire a dummy grenade + grenade = weapon_grenadelauncher_fire( ent, WP_GRENADE_LAUNCHER ); + // check to see what will happen + hitclient = AICast_SafeMissileFire( grenade, grenade->nextthink - level.time, cs->enemyNum, destorg, cs->entityNum, endPos ); + // kill the grenade + G_FreeEntity( grenade ); + if ( hitclient != 1 ) { // it wont hit them, abort + hitclient = -1; // a miss is as bad as a friendly kill + } + } + if ( hitclient == -1 ) { // doh + //G_Printf("aborted grenade\n"); + cs->castScriptStatus.scriptNoMoveTime = 0; + cs->lockViewAnglesTime = 0; + AICast_ChooseWeapon( cs, qfalse ); + return AIFunc_DefaultStart( cs ); + } + if ( !cs->bs->cur_ps.grenadeTimeLeft ) { + // hold fire button down + trap_EA_Attack( bs->client ); + cs->bFlags |= BFL_ATTACKED; + } + cs->lockViewAnglesTime = level.time + 500; + return NULL; + } + // the grenade/pineapple has been released! + cs->lockViewAnglesTime = -1; + cs->startGrenadeFlushTime = level.time + 2000 + rand() % 2000; // dont throw one again for a bit + return AIFunc_DefaultStart( cs ); + } + // + // do we need to avoid a danger? + if ( cs->dangerEntityValidTime >= level.time ) { + if ( !AICast_GetTakeCoverPos( cs, cs->dangerEntity, cs->dangerEntityPos, cs->takeCoverPos ) ) { + // shit?? + } + // go to a position that cannot be seen from the dangerPos + cs->takeCoverTime = cs->dangerEntityValidTime + 1000; + cs->attackcrouch_time = 0; + return AIFunc_AvoidDangerStart( cs ); + } + // + // are we waiting for a door? + if ( cs->doorMarkerTime > level.time - 100 ) { + return AIFunc_DoorMarkerStart( cs, cs->doorMarkerDoor, cs->doorMarkerNum ); + } + // + if ( cs->weaponNum && ( cs->castScriptStatus.scriptFlags & SFL_NOCHANGEWEAPON ) ) { + return AIFunc_IdleStart( cs ); + } + // + if ( cs->enemyNum < 0 ) { + return AIFunc_IdleStart( cs ); + } + // + // if we have started a script, abort the grenade flush + if ( cs->castScriptStatus.castScriptEventIndex >= 0 ) { + return AIFunc_IdleStart( cs ); + } + // trying for too long? + if ( cs->startGrenadeFlushTime < level.time - 4000 ) { + cs->startGrenadeFlushTime = level.time; + return AIFunc_IdleStart( cs ); + } + // + followent = &g_entities[cs->enemyNum]; + // + // if the entity is not ready yet + if ( !followent->inuse ) { + // if it's a connecting client, wait + if ( !( ( cs->enemyNum < MAX_CLIENTS ) + && ( ( followent->client && followent->client->pers.connected == CON_CONNECTING ) + || ( level.time < 3000 ) ) ) ) { // they don't exist anymore, stop attacking + cs->enemyNum = -1; + } + return AIFunc_IdleStart( cs ); + } + // + // if we can see them, go back to an attack state after some time + if ( AICast_CheckAttack( cs, cs->enemyNum, qfalse ) + && cs->obstructingTime < level.time ) { // give us some time to throw the grenade, otherwise go back to attack state + //if ((cs->grenadeFlushEndTime > 0 && cs->grenadeFlushEndTime < level.time)) { + //G_Printf("aborting, enemy is attackable\n"); + return AIFunc_BattleStart( cs ); + //} else if (cs->grenadeFlushEndTime < 0) { + // cs->grenadeFlushEndTime = level.time + 1500; + //} + //attack the enemy if possible + //AICast_ProcessAttack( cs ); + //attacked = qtrue; + } else { + // not visible, go to their previously visible position + if ( !cs->vislist[cs->enemyNum].visible_timestamp || Distance( bs->origin, cs->vislist[cs->enemyNum].real_visible_pos ) < 16 ) { + // we're done attacking, go back to default state, which in turn will recall previous state + // + // face the direction they currently are from this position (bit of a hack, but it looks best) + VectorSubtract( g_entities[cs->enemyNum].client->ps.origin, cs->vislist[cs->enemyNum].visible_pos, dir ); + vectoangles( dir, cs->ideal_viewangles ); + // + //G_Printf("aborting, reached visible pos\n"); + return AIFunc_DefaultStart( cs ); + } + } + + // is there someone else we can go for instead? + numEnemies = AICast_ScanForEnemies( cs, enemies ); + if ( numEnemies == -1 ) { // query mode + return NULL; + } else if ( numEnemies == -2 ) { // inspection may be required + char *retval; + // TTimo: gcc: suggest () around assignment used as truth value + if ( ( retval = AIFunc_InspectFriendlyStart( cs, enemies[0] ) ) ) { + return retval; + } + } else if ( !( cs->bFlags & BFL_ATTACKED ) && numEnemies > 0 ) { + int i; + for ( i = 0; i < numEnemies; i++ ) { + if ( enemies[i] != cs->enemyNum && AICast_CheckAttack( cs, enemies[i], qfalse ) ) { + cs->enemyNum = enemies[i]; + //G_Printf("aborting, other enemy\n"); + return AIFunc_BattleStart( cs ); + } + } + } + + if ( followent->client ) { // go to the last visible position + VectorCopy( cs->vislist[cs->enemyNum].visible_pos, destorg ); + } else // assume we know where other entities are + { + VectorCopy( followent->s.pos.trBase, destorg ); + } + // + dist = VectorDistance( destorg, cs->bs->origin ); + // + if ( cs->vislist[cs->enemyNum].lastcheck_timestamp > cs->vislist[cs->enemyNum].real_visible_timestamp || + dist > 128 ) { + // + // go to them + // + if ( followent->client && followent->health <= 0 ) { + cs->enemyNum = -1; + //G_Printf("aborting, enemy dead\n"); + return AIFunc_DefaultStart( cs ); + } + // + // ........................................................... + // Do the movement.. + // + // move straight to them if we can + if ( ( cs->leaderNum < 0 ) && + ( cs->bs->cur_ps.groundEntityNum != ENTITYNUM_NONE || g_entities[cs->entityNum].waterlevel > 1 ) ) { + aicast_predictmove_t move; + vec3_t dir; + bot_input_t bi; + usercmd_t ucmd; + trace_t tr; + + // trace will eliminate most unsuccessful paths + trap_Trace( &tr, cs->bs->origin, g_entities[cs->entityNum].r.mins, g_entities[cs->entityNum].r.maxs, followent->r.currentOrigin, cs->entityNum, g_entities[cs->entityNum].clipmask ); + if ( tr.entityNum == followent->s.number ) { + // try walking straight to them + VectorSubtract( followent->r.currentOrigin, cs->bs->origin, dir ); + VectorNormalize( dir ); + if ( !ent->waterlevel ) { + dir[2] = 0; + } + //trap_EA_Move(cs->entityNum, dir, 400); + trap_EA_GetInput( cs->entityNum, (float) level.time / 1000, &bi ); + VectorCopy( dir, bi.dir ); + bi.speed = 400; + bi.actionflags = 0; + AICast_InputToUserCommand( cs, &bi, &ucmd, bs->cur_ps.delta_angles ); + AICast_PredictMovement( cs, 5, 2.0, &move, &ucmd, cs->enemyNum ); + + if ( move.stopevent == PREDICTSTOP_HITENT ) { // success! + trap_EA_Move( cs->entityNum, dir, 400 ); + vectoangles( dir, cs->ideal_viewangles ); + cs->ideal_viewangles[2] *= 0.5; + moved = qtrue; + } else { // clear movement + //trap_EA_Move(cs->entityNum, dir, 0); + } + } + } + // just go to them + if ( !moved ) { + moveresult = AICast_MoveToPos( cs, destorg, cs->enemyNum ); + if ( moveresult && moveresult->failure ) { // no path, so go back to idle behaviour + cs->enemyNum = -1; + //G_Printf("aborting, movement failure\n"); + return AIFunc_DefaultStart( cs ); + } else { + moved = qtrue; + } + } + } + // + // ........................................................... + // if we throw a grenade from here, will it get their last visible position? + // + CalcMuzzlePoints( ent, grenadeType ); + // fire a dummy grenade + grenade = weapon_grenadelauncher_fire( ent, WP_GRENADE_LAUNCHER ); + // check to see what will happen + hitclient = AICast_SafeMissileFire( grenade, grenade->nextthink - level.time, cs->enemyNum, destorg, cs->entityNum, endPos ); + // kill the grenade + G_FreeEntity( grenade ); + //if (!attacked) + // cs->weaponNum = grenadeType; // select grenade launcher + // set our angles for the next frame + oldyaw = cs->ideal_viewangles[YAW]; + AICast_AimAtEnemy( cs ); + // if we can't see them, keep facing our movement dir, but use the pitch information + if ( !AICast_EntityVisible( cs, cs->enemyNum, qtrue ) ) { + cs->ideal_viewangles[YAW] = oldyaw; + } + + if ( hitclient == 1 ) { + // it will hit their last visible position + // give us some time to aim and adjust + if ( cs->thinkFuncChangeTime < level.time - 200 ) { + cs->bFlags |= BFL_ATTACKED; + cs->weaponNum = grenadeType; // select grenade launcher + cs->grenadeFlushFiring = cs->weaponNum; + // pause for a bit, so the grenade comes out correctly + cs->lockViewAnglesTime = level.time + 1200; + if ( cs->castScriptStatus.scriptNoMoveTime < level.time + 1200 ) { + cs->castScriptStatus.scriptNoMoveTime = level.time + 1200; + } + return NULL; + } + } else if ( hitclient == -1 ) { + // hit a friendly + cs->startGrenadeFlushTime = level.time + 3000; // don't try again for a while + //G_Printf("aborting, too dangerous\n"); + return AIFunc_DefaultStart( cs ); + } else if ( hitclient == -2 ) { + // went too far, so angle down a bit + cs->ideal_viewangles[PITCH] += 15 * random(); + } else { + if ( cs->thinkFuncChangeTime < level.time - 200 ) { + // if it went reasonably close to them, but safe from us, then fire away + if ( Distance( endPos, cs->bs->origin ) > 100 + Distance( endPos, g_entities[cs->enemyNum].r.currentOrigin ) ) { + trap_EA_Attack( bs->client ); + cs->bFlags |= BFL_ATTACKED; + cs->weaponNum = grenadeType; // select grenade launcher + cs->grenadeFlushFiring = cs->weaponNum; + // pause for a bit, so the grenade comes out correctly + cs->lockViewAnglesTime = level.time + 1200; + if ( cs->castScriptStatus.scriptNoMoveTime < level.time + 1200 ) { + cs->castScriptStatus.scriptNoMoveTime = level.time + 1200; + } + return NULL; + } + } + cs->ideal_viewangles[PITCH] += -10 * random(); + } + // + return NULL; +} + +/* +============ +AIFunc_GrenadeFlushStart() +============ +*/ +char *AIFunc_GrenadeFlushStart( cast_state_t *cs ) { + lastGrenadeFlush = level.time; // + rand()%2000; + cs->startGrenadeFlushTime = level.time; + cs->grenadeFlushEndTime = -1; + cs->lockViewAnglesTime = 0; + cs->combatGoalTime = 0; + cs->grenadeFlushFiring = qfalse; + // don't wait too long before taking cover, if we just aborted one + if ( cs->takeCoverTime > level.time + 1000 ) { + cs->takeCoverTime = level.time + 500 + rand() % 500; + } + // + cs->aifunc = AIFunc_GrenadeFlush; + return "AIFunc_GrenadeFlush"; +} + +/* +============ +AIFunc_BattleMG42() +============ +*/ +char *AIFunc_BattleMG42( cast_state_t *cs ) { + bot_state_t *bs; + gentity_t *mg42, *ent; + vec3_t angles, vec, bestangles; + qboolean unmount = qfalse; + + mg42 = &g_entities[cs->mountedEntity]; + ent = &g_entities[cs->entityNum]; + bs = cs->bs; + + // have we dismounted the MG42? + if ( !ent->active ) { + return AIFunc_DefaultStart( cs ); + } + + // are we waiting to dismount + if ( cs->aiFlags & AIFL_DISMOUNTING ) { + // face straight forward + VectorCopy( mg42->s.angles, cs->ideal_viewangles ); + // only dismount when facing forwards + if ( fabs( AngleDifference( mg42->s.angles[YAW], cs->viewangles[YAW] ) ) < 10 ) { + // try and unmount + Cmd_Activate_f( ent ); + } + return NULL; + } + +/* RF, disabled this since the gun will unmount them when it is destroyed + // if the mg42 is dead, dismount + if (mg42->health <= 0) { + cs->aiFlags |= AIFL_DISMOUNTING; + AICast_ScriptEvent( cs, "forced_mg42_unmount", "destroyed" ); + return NULL; + } +*/ + // if enemy is dead, stop attacking them + if ( g_entities[cs->enemyNum].health <= 0 ) { + cs->enemyNum = -1; + } + + //if no enemy, or our current enemy isn't attackable, look for a better enemy + if ( cs->enemyNum >= 0 ) { + if ( cs->vislist[cs->enemyNum].real_visible_timestamp && cs->vislist[cs->enemyNum].real_visible_timestamp > ( level.time - 5000 ) ) { + VectorSubtract( cs->vislist[cs->enemyNum].real_visible_pos, mg42->r.currentOrigin, vec ); + } else if ( cs->vislist[cs->enemyNum].visible_timestamp && cs->vislist[cs->enemyNum].visible_timestamp > ( level.time - 5000 ) ) { + VectorSubtract( cs->vislist[cs->enemyNum].visible_pos, mg42->r.currentOrigin, vec ); + } else { // just aim straight forward + AngleVectors( mg42->s.angles, vec, NULL, NULL ); + } + + VectorNormalize( vec ); + vectoangles( vec, angles ); + angles[PITCH] = AngleNormalize180( angles[PITCH] ); + VectorCopy( angles, bestangles ); + } + + // check for enemy outside harc + if ( cs->enemyNum < 0 || + !AICast_CheckAttack( cs, cs->enemyNum, qfalse ) || + ( fabs( AngleDifference( angles[YAW], mg42->s.angles[YAW] ) ) > mg42->harc ) || + ( angles[PITCH] < 0 && angles[PITCH] + 5 < -mg42->varc ) || + ( angles[PITCH] > 0 && angles[PITCH] - 5 > 5.0 ) ) { + qboolean shouldAttack; + + // look for a better enemy + numEnemies = AICast_ScanForEnemies( cs, enemies ); + shouldAttack = qfalse; + if ( numEnemies > 0 ) { + int i; + // default to the first known enemy, overwrite if we find a clearer shot + cs->enemyNum = enemies[0]; + // + // unmount unless we find an enemy within harc + unmount = qtrue; + // + for ( i = 0; i < numEnemies; i++ ) { + /* + if (!cs->vislist[enemies[i]].real_visible_timestamp || + (cs->vislist[enemies[i]].real_visible_timestamp < level.time - 2000)) { + // we can't see them, ignore them + continue; + } + */ + + // if they are in the range + if ( cs->vislist[enemies[i]].real_visible_timestamp > ( level.time - 5000 ) ) { + VectorSubtract( cs->vislist[enemies[i]].real_visible_pos, mg42->r.currentOrigin, vec ); + } else { + VectorSubtract( cs->vislist[enemies[i]].visible_pos, mg42->r.currentOrigin, vec ); + } + VectorNormalize( vec ); + vectoangles( vec, angles ); + angles[PITCH] = AngleNormalize180( angles[PITCH] ); + if ( !( ( fabs( AngleDifference( angles[YAW], mg42->s.angles[YAW] ) ) > mg42->harc ) || + ( angles[YAW] < 0 && angles[YAW] + 2 < -mg42->varc ) || + ( angles[YAW] > 0 && angles[YAW] - 2 > 5.0 ) ) ) { + // + // found someone inside harc, so dont unmount + unmount = qfalse; + // + if ( AICast_CheckAttack( cs, enemies[i], qfalse ) ) { + VectorCopy( angles, bestangles ); + cs->enemyNum = enemies[i]; + shouldAttack = qtrue; + break; + } else if ( AICast_CheckAttack( cs, enemies[i], qtrue ) ) { + // keep firing at anything behind solids, in case they find a position where they can shoot us, but our checkattack() doesn't find a clear shot + VectorCopy( angles, bestangles ); + cs->enemyNum = enemies[i]; + shouldAttack = qtrue; + } + } + } + } + + if ( !shouldAttack ) { + // keep firing at anything behind solids, in case they find a position where they can shoot us, but our checkattack() doesn't find a clear shot + if ( cs->enemyNum < 0 || !AICast_CheckAttack( cs, cs->enemyNum, qtrue ) || + ( !cs->vislist[cs->enemyNum].real_visible_timestamp || + ( cs->vislist[cs->enemyNum].real_visible_timestamp < level.time - 2000 ) ) ) { + // face straight forward + cs->ideal_viewangles[PITCH] = 0; + return NULL; + } + } + + // if we had possible enemies, but couldnt find one to attack, then dismount now + if ( unmount ) { + AICast_ScriptEvent( cs, "forced_mg42_unmount", NULL ); + if ( !( cs->aiFlags & AIFL_DENYACTION ) ) { + cs->aiFlags |= AIFL_DISMOUNTING; + return NULL; + } + } + } + // + // hold down fire, and track them + // + // TODO: play a special "holding mg42" torso animation + // + VectorCopy( angles, cs->ideal_viewangles ); + if ( cs->triggerReleaseTime < level.time ) { + trap_EA_Attack( bs->client ); + cs->bFlags |= BFL_ATTACKED; + + if ( cs->triggerReleaseTime < level.time - 3000 ) { + cs->triggerReleaseTime = level.time + 700 + rand() % 700; + } + } + // + return NULL; +} + +/* +============ +AIFunc_BattleMG42Start() +============ +*/ +char *AIFunc_BattleMG42Start( cast_state_t *cs ) { + cs->aiFlags &= ~AIFL_DISMOUNTING; + // + cs->aifunc = AIFunc_BattleMG42; + return "AIFunc_BattleMG42"; +} + +/* +============ +AIFunc_InspectBody() + + go up to the enemy, and have a good look at them, randomly taunt them +============ +*/ +char *AIFunc_InspectBody( cast_state_t *cs ) { + bot_state_t *bs; + vec3_t destorg, enemyOrg; + // + // stop crouching + cs->attackcrouch_time = 0; + // + // do we need to avoid a danger? + if ( cs->dangerEntityValidTime >= level.time ) { + if ( !AICast_GetTakeCoverPos( cs, cs->dangerEntity, cs->dangerEntityPos, cs->takeCoverPos ) ) { + // shit?? + } + // go to a position that cannot be seen from the dangerPos + cs->takeCoverTime = cs->dangerEntityValidTime + 1000; + cs->attackcrouch_time = 0; + return AIFunc_AvoidDangerStart( cs ); + } + // + // are we waiting for a door? + if ( cs->doorMarkerTime > level.time - 100 ) { + return AIFunc_DoorMarkerStart( cs, cs->doorMarkerDoor, cs->doorMarkerNum ); + } + // + // if running a script + if ( cs->castScriptStatus.castScriptEventIndex >= 0 ) { + cs->enemyNum = -1; + return AIFunc_IdleStart( cs ); + } + // + bs = cs->bs; + // + if ( cs->enemyNum < 0 ) { + return AIFunc_IdleStart( cs ); + } + // + // look for things we should attack + numEnemies = AICast_ScanForEnemies( cs, enemies ); + if ( numEnemies == -1 ) { // query mode + return NULL; + } else if ( numEnemies == -2 ) { // inspection may be required + char *retval; + // TTimo: gcc: suggest () around assignment used as truth value + if ( ( retval = AIFunc_InspectFriendlyStart( cs, enemies[0] ) ) ) { + return retval; + } + } else if ( numEnemies == -3 ) { // bullet impact + if ( cs->aiState < AISTATE_COMBAT ) { + return AIFunc_InspectBulletImpactStart( cs ); + } + } else if ( numEnemies == -4 ) { // audible event + if ( cs->aiState < AISTATE_COMBAT ) { + return AIFunc_InspectAudibleEventStart( cs, cs->audibleEventEnt ); + } + } else if ( numEnemies > 0 ) { + cs->enemyNum = enemies[0]; // just attack the first one + return AIFunc_BattleStart( cs ); + } + // + VectorCopy( cs->vislist[cs->enemyNum].visible_pos, enemyOrg ); + if ( ( cs->inspectBodyTime < 0 ) && ( Distance( cs->bs->origin, enemyOrg ) > 64 ) ) { + // if they were gibbed, don't go all the way + if ( g_entities[cs->enemyNum].health < GIB_HEALTH && ( Distance( cs->bs->origin, enemyOrg ) < 180 ) ) { + cs->inspectBodyTime = level.time + 1000 + rand() % 1000; + trap_EA_Gesture( cs->entityNum ); + G_AddEvent( &g_entities[cs->entityNum], EV_GENERAL_SOUND, G_SoundIndex( aiDefaults[cs->aiCharacter].soundScripts[ORDERSSOUNDSCRIPT] ) ); + } + // walk to them + if ( cs->movestate != MS_CROUCH ) { + cs->movestate = MS_WALK; + } + cs->movestateType = MSTYPE_TEMPORARY; + // + moveresult = AICast_MoveToPos( cs, enemyOrg, -1 ); + //if the movement failed + if ( moveresult && ( moveresult->failure || moveresult->blocked ) ) { + //reset the avoid reach, otherwise bot is stuck in current area + trap_BotResetAvoidReach( bs->ms ); + // couldn't get there, so stop trying to get there + cs->enemyNum = -1; + return AIFunc_IdleStart( cs ); + } + if ( Distance( cs->bs->origin, enemyOrg ) < 180 ) { + // look down at them + VectorSubtract( enemyOrg, cs->bs->origin, destorg ); + destorg[2] -= 20; + VectorNormalize( destorg ); + vectoangles( destorg, cs->ideal_viewangles ); + } + } else if ( cs->inspectBodyTime < 0 ) { + // just reached them + cs->inspectBodyTime = level.time + 1000 + rand() % 1000; + trap_EA_Gesture( cs->entityNum ); + G_AddEvent( &g_entities[cs->entityNum], EV_GENERAL_SOUND, G_SoundIndex( aiDefaults[cs->aiCharacter].soundScripts[ORDERSSOUNDSCRIPT] ) ); + } else if ( cs->inspectBodyTime < level.time ) { + vec3_t vec; + VectorSubtract( cs->startOrigin, cs->bs->origin, vec ); + vec[2] = 0; + // ready to go back to start position + if ( VectorLength( vec ) > 64 ) { + if ( cs->movestate != MS_CROUCH ) { + cs->movestate = MS_WALK; + } + cs->movestateType = MSTYPE_TEMPORARY; + moveresult = AICast_MoveToPos( cs, cs->startOrigin, -1 ); + //if the movement failed + if ( moveresult && ( moveresult->failure || moveresult->blocked ) ) { + //reset the avoid reach, otherwise bot is stuck in current area + trap_BotResetAvoidReach( bs->ms ); + // couldn't get there, so stop trying to get there + cs->enemyNum = -1; + return AIFunc_IdleStart( cs ); + } + // stay looking at them for a bit after starting to walk back + if ( cs->inspectBodyTime + 750 > level.time ) { + // look down at them + VectorSubtract( enemyOrg, cs->bs->origin, destorg ); + destorg[2] -= 20; + VectorNormalize( destorg ); + vectoangles( destorg, cs->ideal_viewangles ); + } + } else { + cs->attackSNDtime = level.time; + cs->enemyNum = -1; + return AIFunc_IdleStart( cs ); + } + } + // + return NULL; +} + +/* +============ +AIFunc_InspectBodyStart() +============ +*/ +char *AIFunc_InspectBodyStart( cast_state_t *cs ) { + static int lastInspect; + // + // if an inspection was already started not long ago, forget it + if ( lastInspect <= level.time && lastInspect > level.time - 1000 ) { + cs->inspectBodyTime = 1; // go back to start position + } else { + lastInspect = level.time; + cs->inspectBodyTime = -1; + } + cs->aifunc = AIFunc_InspectBody; + return "AIFunc_InspectBody"; +} + +/* +============ +AIFunc_GrenadeKick() +============ +*/ +char *AIFunc_GrenadeKick( cast_state_t *cs ) { + bot_state_t *bs; + vec3_t destorg, vec; + float dist, speed; + int enemies[MAX_CLIENTS], numEnemies, i; + qboolean shouldAttack; + int *ammo; + gentity_t *danger; + gentity_t *ent; + vec3_t end; + trace_t tr; + vec3_t dir; + int weapon; + + // !!! NOTE: the only way control should pass out of here, is by calling AIFunc_DefaultStart() + + ent = &g_entities[cs->entityNum]; + danger = &g_entities[cs->dangerEntity]; + + weapon = cs->grenadeKickWeapon; + + // just to be sure, give us the grenade launcher + //ent->client->ps.weapons |= (1 << weapon); + + // + // NOTE: ignore all danger, since we are trying to solve the situation anyway + // + // we need to move towards it + bs = cs->bs; + // + // are we throwing it back? + if ( cs->grenadeFlushFiring ) { + // wait until the animation is done + if ( !ent->client->ps.legsTimer ) { + return AIFunc_DefaultStart( cs ); + } + // wait till its finished + return NULL; + /* + cs->weaponNum = weapon; // select grenade launcher + // + if (cs->weaponFireTimes[weapon] < cs->thinkFuncChangeTime) { + if (!cs->bs->cur_ps.grenadeTimeLeft) { + // hold fire button down + AICast_AimAtEnemy( cs ); + trap_EA_Attack(bs->client); + cs->bFlags |= BFL_ATTACKED; + } + // + return NULL; + } + // the grenade has been released! + // + // modify the explode time + g_entities[ent->grenadeFired].nextthink = ent->grenadeExplodeTime; + if (g_entities[ent->grenadeFired].nextthink < level.time + 200) { // cut them some slack + g_entities[ent->grenadeFired].nextthink = level.time + 200 + rand()%500; + } + // make sure no-one tries to throw this back again (hot potatoe syndrome) + g_entities[ent->grenadeFired].flags |= FL_AI_GRENADE_KICK; + // + cs->grenadeFlushFiring = qfalse; + cs->lockViewAnglesTime = -1; + cs->startGrenadeFlushTime = level.time + 2000 + rand()%2000; // dont throw one again for a bit + level.lastGrenadeKick = level.time; + return AIFunc_DefaultStart( cs ); + */ + } + // +/* + // have we caught the grenade? + if (!(ent->flags & FL_AI_GRENADE_KICK)) { + // select grenades + cs->weaponNum = weapon; // select grenade launcher + AICast_AimAtEnemy( cs ); + // hold fire + trap_EA_Attack(bs->client); + cs->bFlags |= BFL_ATTACKED; + cs->grenadeFlushFiring = qtrue; + // + return NULL; + } +*/ + // + // is it about to explode in our face? + if ( level.time > danger->nextthink - (int)( 2.0 * VectorDistance( cs->bs->origin, danger->r.currentOrigin ) ) ) { + // abort!! + if ( !AICast_GetTakeCoverPos( cs, cs->dangerEntity, cs->dangerEntityPos, cs->takeCoverPos ) ) { + // shit?? + } + // go to a position that cannot be seen from the dangerPos + cs->takeCoverTime = danger->nextthink + 1000; + cs->attackcrouch_time = 0; + level.lastGrenadeKick = level.time; + return AIFunc_AvoidDangerStart( cs ); + } + // + /* + // are we close enough to start crouching? + if (danger->s.pos.trDelta[2] < 40 && VectorDistance( danger->r.currentOrigin, cs->bs->origin ) < 48 && (danger->r.currentOrigin[2] < cs->bs->origin[2]) && + VectorLength(danger->s.pos.trDelta) < 40) { + // crouch to pick it up + cs->attackcrouch_time = level.time + 300; + } + */ + cs->attackcrouch_time = 0; // animation is played from standing start + // + // are we close enough to pick it up? + if ( /*cs->grenadeGrabFlag <= 0 || */ + ( danger->s.pos.trDelta[2] < 20 && VectorDistance( danger->r.currentOrigin, cs->bs->origin ) < 48 && ( danger->r.currentOrigin[2] < cs->bs->origin[2] ) && + VectorLength( danger->s.pos.trDelta ) < 50 ) ) { + // + // we have a choice here, either pick up and return, or just kick it +// if ((cs->grenadeGrabFlag == -1) || (cs->grenadeGrabFlag == qtrue && level.time > danger->nextthink - 2000)) { // kick + + // play the kick anim + if ( cs->grenadeGrabFlag == qtrue ) { + AICast_AimAtEnemy( cs ); + // play the kick anim + BG_AnimScriptEvent( &ent->client->ps, ANIM_ET_KICKGRENADE, qfalse, qtrue ); + cs->grenadeGrabFlag = -1; + // stop the grenade from moving away + danger->s.pos.trDelta[0] = 0; + danger->s.pos.trDelta[1] = 0; + if ( danger->s.pos.trDelta[2] > 0 ) { + danger->s.pos.trDelta[2] = 0; + } + } else if ( ent->client->ps.legsTimer < 800 ) { + // send the grenade on its way + cs->grenadeFlushFiring = qtrue; + AngleVectors( cs->viewangles, dir, NULL, NULL ); + dir[2] = 0.4; + VectorNormalize( dir ); + speed = 400; + if ( cs->enemyNum >= 0 ) { + speed = 1.5 * VectorDistance( danger->r.currentOrigin, g_entities[cs->enemyNum].r.currentOrigin ); + if ( speed > 650 ) { + speed = 650; + } + } + VectorScale( dir, speed, danger->s.pos.trDelta ); + danger->r.ownerNum = ent->s.number; // we are now the owner, let it pass through us + danger->s.pos.trTime = level.time - 50; // move a bit on the very first frame + VectorCopy( danger->r.currentOrigin, danger->s.pos.trBase ); + danger->s.pos.trType = TR_GRAVITY; + SnapVector( danger->s.pos.trDelta ); // save net bandwidth + } +/* + } else { // throw + + if (cs->grenadeGrabFlag == qtrue) { + AICast_AimAtEnemy( cs ); + // play the pickup anim + BG_AnimScriptEvent( &ent->client->ps, ANIM_ET_PICKUPGRENADE, qfalse, qtrue ); + cs->grenadeGrabFlag = qfalse; + // stop the grenade from moving away + danger->s.pos.trDelta[0] = 0; + danger->s.pos.trDelta[1] = 0; + if (danger->s.pos.trDelta[2] > 0) { + danger->s.pos.trDelta[2] = 0; + } + } else if (ent->client->ps.legsTimer < 400) { + // send the grenade on its way + cs->grenadeFlushFiring = qtrue; + AngleVectors( cs->viewangles, dir, NULL, NULL ); + dir[2] = 0.4; + VectorNormalize( dir ); + speed = 500; + if (cs->enemyNum >= 0) { + speed = 2*VectorDistance(danger->r.currentOrigin, g_entities[cs->enemyNum].r.currentOrigin); + if (speed > 650) + speed = 650; + } + VectorScale( dir, speed, danger->s.pos.trDelta ); + trap_LinkEntity( danger ); + } else if (ent->client->ps.legsTimer < 800) { + // stop showing the grenade + trap_UnlinkEntity( danger ); + } + } +*/ + // + return NULL; + } + // + cs->grenadeGrabFlag = qtrue; // we must play the anim before we can grab it + // + // is the danger gone? + if ( level.time > cs->dangerEntityValidTime || !danger->inuse ) { + return AIFunc_DefaultStart( cs ); + } + // + // update the predicted position of the grenade + if ( G_PredictMissile( danger, danger->nextthink - level.time, cs->takeCoverPos, qfalse ) ) { + // make sure it's a valid position, and drop it down to the ground + cs->takeCoverPos[2] += -ent->r.mins[2] + 8; + VectorCopy( cs->takeCoverPos, end ); + end[2] -= 80; + trap_Trace( &tr, cs->takeCoverPos, ent->r.mins, ent->r.maxs, end, cs->entityNum, MASK_SOLID ); + if ( tr.startsolid ) { // not a valid position, abort + level.lastGrenadeKick = level.time; + return AIFunc_DefaultStart( cs ); + } + VectorCopy( tr.endpos, cs->takeCoverPos ); + } else { // prediction failed, so use current position + VectorCopy( danger->r.currentOrigin, cs->takeCoverPos ); + cs->takeCoverPos[2] += 16; // lift it off the floor + } + + VectorCopy( cs->takeCoverPos, destorg ); + VectorSubtract( destorg, cs->bs->origin, vec ); + //vec[2] *= 0.2; + dist = VectorLength( vec ); + // + // look for things we should attack + // if we are out of ammo, we shouldn't bother trying to attack + ammo = cs->bs->cur_ps.ammo; + shouldAttack = qfalse; + numEnemies = 0; + if ( AICast_GotEnoughAmmoForWeapon( cs, cs->weaponNum ) ) { + numEnemies = AICast_ScanForEnemies( cs, enemies ); + if ( numEnemies == -1 ) { // query mode + return NULL; + } + if ( numEnemies == -2 ) { // inspection may be required + char *retval; + // TTimo: gcc: suggest () around assignment used as truth value + if ( ( retval = AIFunc_InspectFriendlyStart( cs, enemies[0] ) ) ) { + return retval; + } + } + if ( numEnemies > 0 ) { + // default to the first known enemy, overwrite if we find a clearer shot + cs->enemyNum = enemies[0]; + // + for ( i = 0; i < numEnemies; i++ ) { + if ( AICast_CheckAttack( cs, enemies[i], qfalse ) || AICast_CheckAttack( AICast_GetCastState( enemies[i] ), cs->entityNum, qfalse ) ) { + cs->enemyNum = enemies[i]; + shouldAttack = qtrue; + break; + } else if ( cs->enemyNum < 0 ) { + cs->lastEnemy = enemies[i]; + } + } + } + } + // + // are we close enough to the goal? + if ( dist > 12 ) { // not close enough + // + moveresult = AICast_MoveToPos( cs, destorg, -1 ); + if ( moveresult ) { + //if the movement failed + if ( moveresult->failure ) { + //reset the avoid reach, otherwise bot is stuck in current area + trap_BotResetAvoidReach( bs->ms ); + // couldn't get there, so stop trying to get there + level.lastGrenadeKick = level.time; + return AIFunc_DefaultStart( cs ); + } + // + if ( moveresult->blocked ) { // abort if we get blocked at any point + level.lastGrenadeKick = level.time; + return AIFunc_DefaultStart( cs ); + } + } + // we should slow down on approaching it + cs->speedScale = AICast_SpeedScaleForDistance( cs, dist, 0 ); + } +/* // + // if we are close, put our weapon away and get ready to catch it + if (VectorDistance( danger->r.currentOrigin, cs->bs->origin ) < 128) { + // put weapon away, select grenades + // FIXME: does this fail if we don't have any grenades? + cs->weaponNum = weapon; // select grenade launcher + shouldAttack = qfalse; // don't attack until we've caught it + } +*/ + // if we should be attacking something on our way + if ( shouldAttack ) { + vec3_t vec, dir; + + //attack the enemy if possible + AICast_ProcessAttack( cs ); + // + // if they are close, and we're heading for them, we should abort this manouver + VectorSubtract( g_entities[cs->enemyNum].client->ps.origin, bs->origin, vec ); + if ( VectorNormalize( vec ) < 64 ) { + if ( VectorNormalize2( bs->velocity, dir ) > 20 ) { // we are moving + if ( DotProduct( dir, vec ) > 0 ) { + // abort + level.lastGrenadeKick = level.time; + return AIFunc_DefaultStart( cs ); + } + } + } + } else { + // face the direction that the grenade is coming + VectorSubtract( danger->r.currentOrigin, cs->bs->origin, dir ); + dir[2] = 0; + VectorNormalize( dir ); + vectoangles( dir, cs->ideal_viewangles ); + } + + return NULL; +} + +/* +============= +AIFunc_GrenadeKickStart() +============= +*/ +char *AIFunc_GrenadeKickStart( cast_state_t *cs ) { + gentity_t *danger; + gentity_t *ent; + //gentity_t *trav; + //int numFriends, i; + + //G_Printf( "Excuse me, you dropped something\n" ); + + ent = &g_entities[cs->entityNum]; + danger = &g_entities[cs->dangerEntity]; + // should we dive onto the grenade? + /* + if (danger->s.pos.trDelta[2] < 30) { + // count the number of friends near us + numFriends = 0; + for (i=0, trav=g_entities; iinuse) + continue; + if (trav->aiInactive) + continue; + if (trav->health <= 0) + continue; + if (!AICast_SameTeam( cs, i )) + continue; + if (VectorDistance( cs->takeCoverPos, trav->r.currentOrigin ) > 200) + continue; + numFriends++; + } + // if there are enough friends around, and we have a clear path to the position, sacrifice ourself! + if (numFriends > 2) { + trace_t tr; + trap_Trace( &tr, cs->bs->origin, ent->r.mins, ent->r.maxs, cs->takeCoverPos, cs->entityNum, MASK_SOLID ); + if (tr.fraction == 1.0 && !tr.startsolid) { + return AIFunc_GrenadeDiveStart( cs ); + } + } + } + */ + // + // we have decided to kick or throw the grenade away + cs->grenadeKickWeapon = danger->s.weapon; + cs->grenadeFlushFiring = qfalse; + cs->aifunc = AIFunc_GrenadeKick; + return "AIFunc_GrenadeKick"; +} + +/* +============ +AIFunc_Battle() +============ +*/ +char *AIFunc_Battle( cast_state_t *cs ) { + bot_moveresult_t moveresult; + int tfl; + bot_state_t *bs; + gentity_t *ent, *enemy; + + ent = &g_entities[cs->entityNum]; + enemy = &g_entities[cs->enemyNum]; + + // if we are not in combat mode, then go there now! + if ( cs->aiState < AISTATE_COMBAT ) { + AICast_StateChange( cs, AISTATE_COMBAT ); // just go straight to combat mode + } + // + // do we need to avoid a danger? + if ( cs->dangerEntityValidTime >= level.time ) { + if ( !AICast_GetTakeCoverPos( cs, cs->dangerEntity, cs->dangerEntityPos, cs->takeCoverPos ) ) { + // shit?? + } + // go to a position that cannot be seen from the dangerPos + cs->takeCoverTime = cs->dangerEntityValidTime + 1000; + cs->attackcrouch_time = 0; + return AIFunc_AvoidDangerStart( cs ); + } + // + // are we waiting for a door? + if ( cs->doorMarkerTime > level.time - 100 ) { + return AIFunc_DoorMarkerStart( cs, cs->doorMarkerDoor, cs->doorMarkerNum ); + } + // + // do we need to go to our leader? + if ( cs->leaderNum >= 0 && Distance( cs->bs->origin, g_entities[cs->leaderNum].r.currentOrigin ) > MAX_LEADER_DIST ) { + return AIFunc_ChaseGoalStart( cs, cs->leaderNum, AICAST_LEADERDIST_MAX, qtrue ); + } + bs = cs->bs; + //if no enemy + if ( cs->enemyNum < 0 ) { + // go back to whatever our default action is + return AIFunc_DefaultStart( cs ); + } + // + if ( enemy->health <= 0 ) { + // go back to whatever our default action is + if ( g_entities[cs->entityNum].aiTeam == AITEAM_NAZI ) { + return AIFunc_InspectBodyStart( cs ); + } else { + return AIFunc_DefaultStart( cs ); + } + } + // + // if we are not in a good attacking position, we should chase + if ( !AICast_StopAndAttack( cs ) ) { + return AIFunc_BattleChaseStart( cs ); + } + // + // if the enemy is no longer visible + if ( ( cs->bs->cur_ps.weaponTime < 100 ) // if reloading, don't chase until ready + && ( cs->castScriptStatus.scriptNoMoveTime < level.time ) + && ( /*!AICast_EntityVisible( cs, cs->enemyNum, qtrue ) ||*/ !AICast_CheckAttack( cs, cs->enemyNum, qfalse ) ) ) { + + // if we are in a void, then try to avoid so we get out of it + if ( !cs->bs->areanum ) { + if ( cs->obstructingTime >= level.time ) { + // move there + trap_EA_Move( cs->entityNum, cs->takeCoverPos, 200 ); + } else if ( AICast_GetAvoid( cs, NULL, cs->takeCoverPos, qtrue, cs->enemyNum ) ) { + VectorSubtract( cs->takeCoverPos, cs->bs->origin, cs->takeCoverPos ); + if ( VectorNormalize( cs->takeCoverPos ) > 60 ) { + cs->obstructingTime = level.time + 1000 + rand() % 600; + } + return NULL; + } + } else + // if we are heading for a combatGoal, give us some time to get there + if ( cs->combatGoalTime > level.time ) { + if ( cs->combatGoalTime > level.time + 3000 ) { + cs->combatGoalTime = level.time + 2000 + rand() % 1000; + cs->combatSpotDelayTime = level.time + 4000 + rand() % 3000; + } + } else + if ( cs->leaderNum >= 0 ) { + // chase them, nothing else to do + return AIFunc_BattleChaseStart( cs ); + } else + // if we weren't moving, it is likely they have dodged back behind something, ready to duck out and take another + // shot. so, we could fool them by hiding from the position we last saw them from, in the hope that when they + // return to fire at us, we won't be in their sight. + if ( cs->attributes[TACTICAL] > 0.3 + && cs->attributes[AGGRESSION] < 1.0 + && cs->attributes[AGGRESSION] < ( random() + 0.5 * cs->attributes[TACTICAL] ) + && ( cs->takeCoverTime < level.time ) + && AICast_GetTakeCoverPos( cs, cs->enemyNum, cs->vislist[cs->enemyNum].real_visible_pos, cs->takeCoverPos ) ) { + // start taking cover + cs->takeCoverTime = level.time + 2000 + rand() % 4000; // only move a little bit + //cs->attackcrouch_time = 0; // get out of here real quick + return AIFunc_BattleTakeCoverStart( cs ); + } else + // if we haven't thrown a grenade in a bit, go into "grenade flush mode" + if ( ( lastGrenadeFlush > level.time || lastGrenadeFlush < level.time - 7000 ) && + ( cs->aiState >= AISTATE_COMBAT ) && + ( cs->castScriptStatus.castScriptEventIndex < 0 ) && + ( ( ( COM_BitCheck( cs->bs->cur_ps.weapons, WP_GRENADE_LAUNCHER ) ) && + ( AICast_GotEnoughAmmoForWeapon( cs, WP_GRENADE_LAUNCHER ) ) && + ( cs->weaponFireTimes[WP_GRENADE_LAUNCHER] < level.time - (int)( aicast_skillscale * 3000 ) ) ) || + ( ( COM_BitCheck( cs->bs->cur_ps.weapons, WP_GRENADE_PINEAPPLE ) ) && + ( AICast_GotEnoughAmmoForWeapon( cs, WP_GRENADE_PINEAPPLE ) ) && + ( cs->weaponFireTimes[WP_GRENADE_PINEAPPLE] < level.time - (int)( aicast_skillscale * 3000 ) ) ) ) && + !( cs->weaponNum && ( cs->castScriptStatus.scriptFlags & SFL_NOCHANGEWEAPON ) ) && + ( Distance( cs->bs->origin, cs->vislist[cs->enemyNum].real_visible_pos ) > 100 ) && + ( Distance( cs->bs->origin, cs->vislist[cs->enemyNum].real_visible_pos ) < 1200 ) && + ( AICast_WantsToChase( cs ) ) ) { + // try and flush them out with a grenade + //G_Printf("get outta there..\n"); + return AIFunc_GrenadeFlushStart( cs ); + } else + // not visible, should we chase them? + if ( AICast_WantsToChase( cs ) ) { + // chase them + return AIFunc_BattleChaseStart( cs ); + } else + // Take Cover? + if ( AICast_WantsToTakeCover( cs, qfalse ) + && ( cs->takeCoverTime < level.time ) + && AICast_GetTakeCoverPos( cs, cs->enemyNum, cs->vislist[cs->enemyNum].real_visible_pos, cs->takeCoverPos ) ) { + // go to a position that cannot be seen from the last place we saw the enemy, and wait there for some time + cs->takeCoverTime = level.time + 4000 + rand() % 2000; + //cs->attackcrouch_time = 0; + return AIFunc_BattleTakeCoverStart( cs ); + } else + { + // chase them, nothing else to do + return AIFunc_BattleChaseStart( cs ); + } + } + // if we are obstructing someone else, move out the way + if ( cs->obstructingTime > level.time ) { + // setup a combatgoal in the obstructionYaw direction + //cs->combatGoalTime = level.time + 10; + //VectorCopy( cs->obstructingPos, cs->combatGoalOrigin ); + AICast_MoveToPos( cs, cs->obstructingPos, -1 ); + // if not crouching, walk instead of running + cs->speedScale = cs->attributes[WALKING_SPEED] / cs->attributes[RUNNING_SPEED]; + } + // if the enemy is really close, avoid them + else if ( ( cs->obstructingTime < ( level.time - 500 + rand() % 300 ) ) && + ( Distance( cs->bs->origin, cs->vislist[cs->enemyNum].real_visible_pos ) < 100 ) ) { + if ( AICast_GetAvoid( cs, NULL, cs->obstructingPos, qtrue, cs->enemyNum ) ) { + cs->obstructingTime = level.time + 500; + } else { + cs->obstructingTime = level.time - 1; // wait a bit before trying again + } + } + // + // setup for the fight + // + tfl = cs->travelflags; + //if in lava or slime the bot should be able to get out + if ( BotInLava( bs ) ) { + tfl |= TFL_LAVA; + } + if ( BotInSlime( bs ) ) { + tfl |= TFL_SLIME; + } + // + /* + moveresult = AICast_CombatMove(cs, tfl); + //if the movement failed + if (moveresult.failure) { + //reset the avoid reach, otherwise bot is stuck in current area + trap_BotResetAvoidReach(bs->ms); + // reset the combatgoal + cs->combatGoalTime = 0; + } else if (cs->combatGoalTime > level.time && VectorLength(cs->bs->cur_ps.velocity)) { // crouch if moving? + if (cs->attributes[ATTACK_CROUCH] > 0.1) { + AICast_RequestCrouchAttack( cs, cs->bs->origin, 0.5 ); + } + } + */ + // if we are crouching, don't stay down for too long after we finish fighting + if ( cs->aiFlags & AIFL_ATTACK_CROUCH ) { + if ( cs->attackcrouch_time > level.time || ( cs->thinkFuncChangeTime < level.time - 1000 ) ) { + cs->attackcrouch_time = level.time + 1000; + } + } else { + cs->attackcrouch_time = 0; // only set it if we need it + } + // + AICast_Blocked( cs, &moveresult, qfalse, NULL ); + // + // Retreat? + if ( cs->castScriptStatus.scriptNoMoveTime < level.time && AICast_WantToRetreat( cs ) ) { + if ( AICast_GetTakeCoverPos( cs, cs->enemyNum, cs->vislist[cs->enemyNum].visible_pos, cs->takeCoverPos ) ) { + // go to a position that cannot be seen from the last place we saw the enemy, and wait there for some time + cs->takeCoverTime = level.time + 2000 + rand() % 3000; + return AIFunc_BattleTakeCoverStart( cs ); + } + } + // + // Lob a Grenade? + // if we haven't thrown a grenade in a bit, go into "grenade flush mode" + if ( ( lastGrenadeFlush > level.time || lastGrenadeFlush < level.time - 7000 ) && + ( cs->aiState >= AISTATE_COMBAT ) && + ( cs->castScriptStatus.castScriptEventIndex < 0 ) && + ( cs->startGrenadeFlushTime < level.time - 3000 ) && + ( COM_BitCheck( cs->bs->cur_ps.weapons, WP_GRENADE_LAUNCHER ) ) && + ( AICast_GotEnoughAmmoForWeapon( cs, WP_GRENADE_LAUNCHER ) ) && + ( cs->weaponFireTimes[WP_GRENADE_LAUNCHER] < level.time - (int)( aicast_skillscale * 3000 ) ) && + ( ( cs->weaponNum == WP_GRENADE_LAUNCHER ) || !( cs->castScriptStatus.scriptFlags & SFL_NOCHANGEWEAPON ) ) && + ( Distance( cs->bs->origin, cs->vislist[cs->enemyNum].real_visible_pos ) > 100 ) && + ( Distance( cs->bs->origin, cs->vislist[cs->enemyNum].real_visible_pos ) < 2000 ) ) { + // try and flush them out with a grenade + //G_Printf("pineapple?\n"); + return AIFunc_GrenadeFlushStart( cs ); + } + if ( ( lastGrenadeFlush > level.time || lastGrenadeFlush < level.time - 7000 ) && + ( cs->aiState >= AISTATE_COMBAT ) && + ( cs->castScriptStatus.castScriptEventIndex < 0 ) && + ( cs->startGrenadeFlushTime < level.time - 3000 ) && + ( COM_BitCheck( cs->bs->cur_ps.weapons, WP_GRENADE_PINEAPPLE ) ) && + ( AICast_GotEnoughAmmoForWeapon( cs, WP_GRENADE_PINEAPPLE ) ) && + ( cs->weaponFireTimes[WP_GRENADE_PINEAPPLE] < level.time - (int)( aicast_skillscale * 3000 ) ) && + ( ( cs->weaponNum == WP_GRENADE_PINEAPPLE ) || !( cs->castScriptStatus.scriptFlags & SFL_NOCHANGEWEAPON ) ) && + ( Distance( cs->bs->origin, cs->vislist[cs->enemyNum].real_visible_pos ) > 100 ) && + ( Distance( cs->bs->origin, cs->vislist[cs->enemyNum].real_visible_pos ) < 2000 ) ) { + // try and flush them out with a grenade + //G_Printf("pineapple?\n"); + return AIFunc_GrenadeFlushStart( cs ); + } + // + // Dodge enemy aim? + if ( ( cs->attributes[AGGRESSION] < 1.0 ) && + ( ent->client->ps.weapon ) && + ( ent->client->ps.groundEntityNum == ENTITYNUM_WORLD ) && + ( !cs->lastRollMove || cs->lastRollMove < level.time - 4000 ) && + ( cs->attributes[TACTICAL] > 0.5 ) && ( cs->aiFlags & AIFL_ROLL_ANIM ) && + ( VectorLength( cs->bs->cur_ps.velocity ) < 1 ) ) { + vec3_t aim, enemyVec, right; + // are they aiming at us? + AngleVectors( enemy->client->ps.viewangles, aim, right, NULL ); + VectorSubtract( cs->bs->origin, enemy->r.currentOrigin, enemyVec ); + VectorNormalize( enemyVec ); + // if they are looking at us, we should avoid them + if ( DotProduct( aim, enemyVec ) > 0.97 ) { + aicast_predictmove_t move; + vec3_t dir; + bot_input_t bi, bi_back; + usercmd_t ucmd; + float simTime = 0.8; + + cs->lastRollMove = level.time; + + trap_EA_GetInput( cs->entityNum, (float) level.time / 1000, &bi_back ); + trap_EA_ResetInput( cs->entityNum, NULL ); + if ( level.time % 200 < 100 ) { + VectorNegate( right, dir ); + } else { VectorCopy( right, dir );} + trap_EA_Move( cs->entityNum, dir, 400 ); + trap_EA_GetInput( cs->entityNum, (float) level.time / 1000, &bi ); + VectorCopy( dir, bi.dir ); + AICast_InputToUserCommand( cs, &bi, &ucmd, bs->cur_ps.delta_angles ); + AICast_PredictMovement( cs, 4, simTime / 4, &move, &ucmd, cs->enemyNum ); + + trap_EA_ResetInput( cs->entityNum, &bi_back ); + + if ( move.groundEntityNum == ENTITYNUM_WORLD && + VectorDistance( move.endpos, cs->bs->origin ) > simTime * cs->attributes[RUNNING_SPEED] * 0.8 ) { + // good enough + if ( AICast_CheckAttackAtPos( cs->entityNum, cs->enemyNum, move.endpos, cs->bs->cur_ps.viewheight == cs->bs->cur_ps.crouchViewHeight, qfalse ) ) { + cs->takeCoverTime = 0; + return AIFunc_BattleRollStart( cs, dir ); + } + } + } + } + // + // reload? + if ( ( cs->bs->cur_ps.weaponstate != WEAPON_RELOADING ) && ( cs->bs->cur_ps.ammoclip[BG_FindClipForWeapon( cs->bs->cur_ps.weapon )] < (int)( ammoTable[cs->bs->cur_ps.weapon].uses ) ) ) { + if ( AICast_GotEnoughAmmoForWeapon( cs, cs->weaponNum ) ) { + trap_EA_Reload( cs->entityNum ); + } else { // no ammo, switch? + AICast_ChooseWeapon( cs, qfalse ); + if ( cs->weaponNum == WP_NONE ) { + // no ammo, get out of here + return AIFunc_DefaultStart( cs ); + } + if ( !AICast_GotEnoughAmmoForWeapon( cs, cs->weaponNum ) ) { + // no ammo, get out of here + return AIFunc_DefaultStart( cs ); + } + } + } else { + //attack the enemy if possible + AICast_ProcessAttack( cs ); + } + // + return NULL; +} + +/* +============ +AIFunc_BattleStart() +============ +*/ +char *AIFunc_BattleStart( cast_state_t *cs ) { + char *rval; + int lastweap; + // make sure we don't avoid any areas when we start again + trap_BotInitAvoidReach( cs->bs->ms ); + // wait some time before taking cover again + cs->takeCoverTime = level.time + 300 + rand() % ( 2000 + (int)( 2000.0 * cs->attributes[AGGRESSION] ) ); + // wait some time before going to a combat spot + cs->combatSpotDelayTime = level.time + 1500 + rand() % 2500; + // + // start a crouch attack? + if ( ( random() * 3.0 + 1.0 < cs->attributes[ATTACK_CROUCH] ) + && AICast_RequestCrouchAttack( cs, cs->bs->origin, 0.0 ) ) { + cs->aiFlags |= AIFL_ATTACK_CROUCH; + } else { + cs->attackcrouch_time = 0; + cs->aiFlags &= ~AIFL_ATTACK_CROUCH; + } + // + cs->lastEnemy = cs->enemyNum; + cs->startAttackCount++; + cs->crouchHideFlag = qfalse; + // + // get out of talking state + cs->aiFlags &= ~AIFL_TALKING; + // + //update the attack inventory values + AICast_UpdateBattleInventory( cs, cs->enemyNum ); + // + // if we have a special attack, call the correct AI routine +recheck: + rval = NULL; + // ignore special attacks until we are facing our enemy + if ( fabs( AngleDifference( cs->ideal_viewangles[YAW], cs->viewangles[YAW] ) ) < 10 ) { + // select a weapon + AICast_ChooseWeapon( cs, qtrue ); + // + if ( ( cs->weaponNum == WP_MONSTER_ATTACK1 ) && cs->aifuncAttack1 ) { + if ( AICast_CheckAttack( cs, cs->enemyNum, qfalse ) ) { + rval = cs->aifuncAttack1( cs ); + } else { + rval = AIFunc_BattleChaseStart( cs ); + } + } else if ( ( cs->weaponNum == WP_MONSTER_ATTACK2 ) && cs->aifuncAttack2 ) { + if ( AICast_CheckAttack( cs, cs->enemyNum, qfalse ) ) { + rval = cs->aifuncAttack2( cs ); + } else { + rval = AIFunc_BattleChaseStart( cs ); + } + } else if ( ( cs->weaponNum == WP_MONSTER_ATTACK3 ) && cs->aifuncAttack3 ) { + if ( AICast_CheckAttack( cs, cs->enemyNum, qfalse ) ) { + rval = cs->aifuncAttack3( cs ); + } else { + rval = AIFunc_BattleChaseStart( cs ); + } + } + // + if ( !rval && cs->weaponNum >= WP_MONSTER_ATTACK1 && cs->weaponNum <= WP_MONSTER_ATTACK3 ) { + // don't use this weapon again for a while + cs->weaponFireTimes[cs->weaponNum] = level.time; + // select a different weapon + lastweap = cs->weaponNum; + AICast_ChooseWeapon( cs, qfalse ); // qfalse so we don't choose a special weapon + if ( cs->weaponNum == lastweap ) { + return NULL; + } + // try again + goto recheck; + } + } else { // normal weapons + // select a weapon + AICast_ChooseWeapon( cs, qfalse ); + rval = NULL; + } + // + if ( !rval ) { // use the generic battle routine for all "normal" weapons + if ( cs->weaponNum >= WP_MONSTER_ATTACK1 && cs->weaponNum <= WP_MONSTER_ATTACK3 ) { + // monster attacks are not allowed to go into the normal battle mode + return NULL; + } else { + cs->aifunc = AIFunc_Battle; + return "AIFunc_Battle"; + } + } + // + // we decided to start a special monster attack + return rval; +} + +/* +============ +AIFunc_DefaultStart() +============ +*/ +char *AIFunc_DefaultStart( cast_state_t *cs ) { + qboolean first = qfalse; + char *rval = NULL; + // + if ( cs->aiFlags & AIFL_JUST_SPAWNED ) { + first = qtrue; + cs->aiFlags &= ~AIFL_JUST_SPAWNED; + } + // + switch ( cs->aiCharacter ) { + case AICHAR_ZOMBIE: + // portal zombie, requires spawning effect + if ( first && ( g_entities[cs->entityNum].spawnflags & 4 ) ) { + return AIFunc_FlameZombie_PortalStart( cs ); + } + break; + } + // + // if they have an enemy, then pursue + if ( cs->enemyNum >= 0 && ( cs->aifunc != AIFunc_Battle ) ) { // make sure we haven't just come from there + rval = AIFunc_BattleStart( cs ); + } + // + if ( !rval ) { + return AIFunc_IdleStart( cs ); + } + // + return rval; +} diff --git a/Projects/Android/jni/rtcw/src/game/ai_cast_global.h b/Projects/Android/jni/rtcw/src/game/ai_cast_global.h new file mode 100644 index 0000000..9485f94 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/game/ai_cast_global.h @@ -0,0 +1,85 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +//=========================================================================== +// +// Name: ai_cast_global.h +// Function: Global AI Cast defines +// Programmer: Ridah +// Tab Size: 4 (real tabs) +//=========================================================================== + +// TTimo no typedef, "warning: useless keyword or type name in empty declaration" +struct cast_state_s; + +#define AICAST_AIM_SPREAD 2048.0 // a really bad shooter will offset a maximum of this per shot, from the end point of the 8192 trace length + +#define DANGER_MISSILE ( 1 << 0 ) +#define DANGER_CLIENTAIM ( 1 << 1 ) +#define DANGER_FLAMES ( 1 << 2 ) + +extern qboolean saveGamePending; + +qboolean AICast_SameTeam( struct cast_state_s *cs, int enemynum ); +struct cast_state_s *AICast_GetCastState( int entitynum ); +void AICast_ScriptLoad( void ); +void AICast_ScriptEvent( struct cast_state_s *cs, char *eventStr, char *params ); +void AICast_ForceScriptEvent( struct cast_state_s *cs, char *eventStr, char *params ); +qboolean AICast_AIDamageOK( struct cast_state_s *cs, struct cast_state_s *ocs ); +gentity_t *AICast_FindEntityForName( char *name ); +gentity_t *AICast_TravEntityForName( gentity_t *startent, char *name ); +void AICast_ScriptParse( struct cast_state_s *cs ); +void AICast_StartFrame( int time ); +void AICast_StartServerFrame( int time ); +void AICast_RecordWeaponFire( gentity_t *ent ); +void AICast_AIDoor_Touch( gentity_t *ent, gentity_t *aidoor_trigger, gentity_t *door ); +float AICast_GetAccuracy( int entnum ); +void AICast_Activate( int activatorNum, int entNum ); +void AICast_CheckDangerousEntity( gentity_t *ent, int dangerFlags, float dangerDist, float tacticalLevel, float aggressionLevel, qboolean hurtFriendly ); +qboolean AICast_NoFlameDamage( int entNum ); +void AICast_SetFlameDamage( int entNum, qboolean status ); +qboolean AICast_HasFiredWeapon( int entNum, int weapon ); +void G_SetAASBlockingEntity( gentity_t *ent, qboolean blocking ); +qboolean AICast_InFieldOfVision( vec3_t viewangles, float fov, vec3_t angles ); +qboolean AICast_VisibleFromPos( vec3_t srcpos, int srcnum, + vec3_t destpos, int destnum, qboolean updateVisPos ); +qboolean AICast_AllowFlameDamage( int entNum ); +void AICast_AdjustIdealYawForMover( int entnum, float yaw ); +void AICast_AgePlayTime( int entnum ); +int AICast_NoReload( int entnum ); +void AICast_RecordScriptSound( int client ); +void AICast_UpdateVisibility( gentity_t *srcent, gentity_t *destent, qboolean shareVis, qboolean directview ); +void AICast_ProcessBullet( gentity_t *attacker, vec3_t start, vec3_t end ); +void AICast_AudibleEvent( int srcnum, vec3_t pos, float range ); + +//----(SA) added +int AICast_PlayTime( int entnum ); +int AICast_NumAttempts( int entnum ); +//----(SA) end + +void AICast_RegisterPain( int entnum ); diff --git a/Projects/Android/jni/rtcw/src/game/ai_cast_script.c b/Projects/Android/jni/rtcw/src/game/ai_cast_script.c new file mode 100644 index 0000000..c580937 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/game/ai_cast_script.c @@ -0,0 +1,807 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +//=========================================================================== +// +// Name: ai_cast_script.c +// Function: Wolfenstein AI Character Scripting +// Programmer: Ridah +// Tab Size: 4 (real tabs) +//=========================================================================== + +#include "../game/g_local.h" +#include "../game/q_shared.h" +#include "../game/botlib.h" //bot lib interface +#include "../game/be_aas.h" +#include "../game/be_ea.h" +#include "../game/be_ai_gen.h" +#include "../game/be_ai_goal.h" +#include "../game/be_ai_move.h" +#include "../botai/botai.h" //bot ai interface + +#include "ai_cast.h" + +/* +Scripting that allows the designers to control the behaviour of AI characters +according to each different scenario. +*/ + +// action functions need to be declared here so they can be accessed in the scriptAction table +qboolean AICast_ScriptAction_GotoMarker( cast_state_t *cs, char *params ); +qboolean AICast_ScriptAction_WalkToMarker( cast_state_t *cs, char *params ); +qboolean AICast_ScriptAction_CrouchToMarker( cast_state_t *cs, char *params ); +qboolean AICast_ScriptAction_GotoCast( cast_state_t *cs, char *params ); +qboolean AICast_ScriptAction_WalkToCast( cast_state_t *cs, char *params ); +qboolean AICast_ScriptAction_CrouchToCast( cast_state_t *cs, char *params ); +qboolean AICast_ScriptAction_Wait( cast_state_t *cs, char *params ); +qboolean AICast_ScriptAction_AbortIfLoadgame( cast_state_t *cs, char *params ); //----(SA) added +qboolean AICast_ScriptAction_Trigger( cast_state_t *cs, char *params ); +qboolean AICast_ScriptAction_FollowCast( cast_state_t *cs, char *params ); +qboolean AICast_ScriptAction_PlaySound( cast_state_t *cs, char *params ); +qboolean AICast_ScriptAction_NoAttack( cast_state_t *cs, char *params ); +qboolean AICast_ScriptAction_Attack( cast_state_t *cs, char *params ); +qboolean AICast_ScriptAction_PlayAnim( cast_state_t *cs, char *params ); +qboolean AICast_ScriptAction_ClearAnim( cast_state_t *cs, char *params ); +qboolean AICast_ScriptAction_SetAmmo( cast_state_t *cs, char *params ); +qboolean AICast_ScriptAction_SetClip( cast_state_t *cs, char *params ); //----(SA) added +qboolean AICast_ScriptAction_SelectWeapon( cast_state_t *cs, char *params ); +qboolean AICast_ScriptAction_GiveArmor( cast_state_t *cs, char *params ); //----(SA) added +qboolean AICast_ScriptAction_SetArmor( cast_state_t *cs, char *params ); //----(SA) added +qboolean AICast_ScriptAction_SuggestWeapon( cast_state_t *cs, char *params ); //----(SA) added +qboolean AICast_ScriptAction_GiveWeapon( cast_state_t *cs, char *params ); +qboolean AICast_ScriptAction_GiveInventory( cast_state_t *cs, char *params ); +qboolean AICast_ScriptAction_TakeWeapon( cast_state_t *cs, char *params ); +qboolean AICast_ScriptAction_Movetype( cast_state_t *cs, char *params ); +qboolean AICast_ScriptAction_AlertEntity( cast_state_t *cs, char *params ); +qboolean AICast_ScriptAction_SaveGame( cast_state_t *cs, char *params ); +qboolean AICast_ScriptAction_FireAtTarget( cast_state_t *cs, char *params ); +qboolean AICast_ScriptAction_GodMode( cast_state_t *cs, char *params ); +qboolean AICast_ScriptAction_Accum( cast_state_t *cs, char *params ); +qboolean AICast_ScriptAction_SpawnCast( cast_state_t *cs, char *params ); +qboolean AICast_ScriptAction_MissionFailed( cast_state_t *cs, char *params ); +qboolean AICast_ScriptAction_ObjectiveMet( cast_state_t *cs, char *params ); +qboolean AICast_ScriptAction_ObjectivesNeeded( cast_state_t *cs, char *params ); +qboolean AICast_ScriptAction_NoAIDamage( cast_state_t *cs, char *params ); +qboolean AICast_ScriptAction_Print( cast_state_t *cs, char *params ); +qboolean AICast_ScriptAction_FaceTargetAngles( cast_state_t *cs, char *params ); +qboolean AICast_ScriptAction_ResetScript( cast_state_t *cs, char *params ); +qboolean AICast_ScriptAction_Mount( cast_state_t *cs, char *params ); +qboolean AICast_ScriptAction_Unmount( cast_state_t *cs, char *params ); +qboolean AICast_ScriptAction_SavePersistant( cast_state_t *cs, char *params ); +qboolean AICast_ScriptAction_ChangeLevel( cast_state_t *cs, char *params ); +qboolean AICast_ScriptAction_EndGame( cast_state_t *cs, char *params ); //----(SA) added +qboolean AICast_ScriptAction_Teleport( cast_state_t *cs, char *params ); //----(SA) added +qboolean AICast_ScriptAction_FoundSecret( cast_state_t *cs, char *params ); +qboolean AICast_ScriptAction_NoSight( cast_state_t *cs, char *params ); +qboolean AICast_ScriptAction_Sight( cast_state_t *cs, char *params ); +qboolean AICast_ScriptAction_NoAvoid( cast_state_t *cs, char *params ); +qboolean AICast_ScriptAction_Avoid( cast_state_t *cs, char *params ); +qboolean AICast_ScriptAction_Attrib( cast_state_t *cs, char *params ); +qboolean AICast_ScriptAction_DenyAction( cast_state_t *cs, char *params ); +qboolean AICast_ScriptAction_LightningDamage( cast_state_t *cs, char *params ); +qboolean AICast_ScriptAction_Headlook( cast_state_t *cs, char *params ); +qboolean AICast_ScriptAction_BackupScript( cast_state_t *cs, char *params ); +qboolean AICast_ScriptAction_RestoreScript( cast_state_t *cs, char *params ); +qboolean AICast_ScriptAction_StateType( cast_state_t *cs, char *params ); +qboolean AICast_ScriptAction_KnockBack( cast_state_t *cs, char *params ); +qboolean AICast_ScriptAction_Zoom( cast_state_t *cs, char *params ); +qboolean AICast_ScriptAction_Parachute( cast_state_t *cs, char *params ); +qboolean AICast_ScriptAction_Cigarette( cast_state_t *cs, char *params ); //----(SA) added +qboolean AICast_ScriptAction_StartCam( cast_state_t *cs, char *params ); +qboolean AICast_ScriptAction_StopCam( cast_state_t *cs, char *params ); //----(SA) added +qboolean AICast_ScriptAction_StartCamBlack( cast_state_t *cs, char *params ); +qboolean AICast_ScriptAction_EntityScriptName( cast_state_t *cs, char *params ); +qboolean AICast_ScriptAction_AIScriptName( cast_state_t *cs, char *params ); +qboolean AICast_ScriptAction_SetHealth( cast_state_t *cs, char *params ); +qboolean AICast_ScriptAction_NoTarget( cast_state_t *cs, char *params ); +qboolean AICast_ScriptAction_Cvar( cast_state_t *cs, char *params ); + +qboolean AICast_ScriptAction_MusicStart( cast_state_t *cs, char *params ); //----(SA) +qboolean AICast_ScriptAction_MusicPlay( cast_state_t *cs, char *params ); //----(SA) +qboolean AICast_ScriptAction_MusicStop( cast_state_t *cs, char *params ); //----(SA) +qboolean AICast_ScriptAction_MusicFade( cast_state_t *cs, char *params ); //----(SA) +qboolean AICast_ScriptAction_MusicQueue( cast_state_t *cs, char *params ); //----(SA) + +qboolean AICast_ScriptAction_ExplicitRouting( cast_state_t *cs, char *params ); +qboolean AICast_ScriptAction_LockPlayer( cast_state_t *cs, char *params ); +qboolean AICast_ScriptAction_AnimCondition( cast_state_t *cs, char *params ); +qboolean AICast_ScriptAction_PushAway( cast_state_t *cs, char *params ); +qboolean AICast_ScriptAction_CatchFire( cast_state_t *cs, char *params ); + +// these are the actions that each event can call +cast_script_stack_action_t scriptActions[] = +{ + {"gotomarker", AICast_ScriptAction_GotoMarker}, + {"runtomarker", AICast_ScriptAction_GotoMarker}, + {"walktomarker", AICast_ScriptAction_WalkToMarker}, + {"crouchtomarker", AICast_ScriptAction_CrouchToMarker}, + {"gotocast", AICast_ScriptAction_GotoCast}, + {"runtocast", AICast_ScriptAction_GotoCast}, + {"walktocast", AICast_ScriptAction_WalkToCast}, + {"crouchtocast", AICast_ScriptAction_CrouchToCast}, + {"followcast", AICast_ScriptAction_FollowCast}, + {"playsound", AICast_ScriptAction_PlaySound}, + {"playanim", AICast_ScriptAction_PlayAnim}, + {"clearanim", AICast_ScriptAction_ClearAnim}, + {"wait", AICast_ScriptAction_Wait}, + {"abort_if_loadgame",AICast_ScriptAction_AbortIfLoadgame}, //----(SA) added + {"trigger", AICast_ScriptAction_Trigger}, + {"setammo", AICast_ScriptAction_SetAmmo}, + {"setclip", AICast_ScriptAction_SetClip}, //----(SA) added + {"selectweapon", AICast_ScriptAction_SelectWeapon}, + {"noattack", AICast_ScriptAction_NoAttack}, + {"suggestweapon", AICast_ScriptAction_SuggestWeapon}, //----(SA) added + {"attack", AICast_ScriptAction_Attack}, + {"givearmor", AICast_ScriptAction_GiveArmor}, //----(SA) added + {"setarmor", AICast_ScriptAction_SetArmor}, //----(SA) added + {"giveinventory", AICast_ScriptAction_GiveInventory}, + {"giveweapon", AICast_ScriptAction_GiveWeapon}, + {"takeweapon", AICast_ScriptAction_TakeWeapon}, + {"movetype", AICast_ScriptAction_Movetype}, + {"alertentity", AICast_ScriptAction_AlertEntity}, + {"savegame", AICast_ScriptAction_SaveGame}, + {"fireattarget", AICast_ScriptAction_FireAtTarget}, + {"godmode", AICast_ScriptAction_GodMode}, + {"accum", AICast_ScriptAction_Accum}, + {"spawncast", AICast_ScriptAction_SpawnCast}, + {"missionfailed", AICast_ScriptAction_MissionFailed}, + {"missionsuccess", AICast_ScriptAction_ObjectiveMet}, + {"objectivemet", AICast_ScriptAction_ObjectiveMet}, // dupe of missionsuccess so scripts can changeover to a more logical name + {"objectivesneeded",AICast_ScriptAction_ObjectivesNeeded}, + {"noaidamage", AICast_ScriptAction_NoAIDamage}, + {"print", AICast_ScriptAction_Print}, + {"facetargetangles",AICast_ScriptAction_FaceTargetAngles}, + {"resetscript", AICast_ScriptAction_ResetScript}, + {"mount", AICast_ScriptAction_Mount}, + {"unmount", AICast_ScriptAction_Unmount}, + {"savepersistant", AICast_ScriptAction_SavePersistant}, + {"changelevel", AICast_ScriptAction_ChangeLevel}, + {"endgame", AICast_ScriptAction_EndGame}, //----(SA) added + {"teleport", AICast_ScriptAction_Teleport}, //----(SA) added + {"foundsecret", AICast_ScriptAction_FoundSecret}, + {"nosight", AICast_ScriptAction_NoSight}, + {"sight", AICast_ScriptAction_Sight}, + {"noavoid", AICast_ScriptAction_NoAvoid}, + {"avoid", AICast_ScriptAction_Avoid}, + {"attrib", AICast_ScriptAction_Attrib}, + {"denyactivate", AICast_ScriptAction_DenyAction}, + {"lightningdamage", AICast_ScriptAction_LightningDamage}, + {"deny", AICast_ScriptAction_DenyAction}, + {"headlook", AICast_ScriptAction_Headlook}, + {"backupscript", AICast_ScriptAction_BackupScript}, + {"restorescript", AICast_ScriptAction_RestoreScript}, + {"statetype", AICast_ScriptAction_StateType}, + {"knockback", AICast_ScriptAction_KnockBack}, + {"zoom", AICast_ScriptAction_Zoom}, + {"parachute", AICast_ScriptAction_Parachute}, + {"cigarette", AICast_ScriptAction_Cigarette}, //----(SA) added + {"startcam", AICast_ScriptAction_StartCam}, + {"startcamblack", AICast_ScriptAction_StartCamBlack}, + {"stopcam", AICast_ScriptAction_StopCam}, //----(SA) added + {"entityscriptname",AICast_ScriptAction_EntityScriptName}, + {"aiscriptname", AICast_ScriptAction_AIScriptName}, + {"sethealth", AICast_ScriptAction_SetHealth}, + {"notarget", AICast_ScriptAction_NoTarget}, + {"cvar", AICast_ScriptAction_Cvar}, + +//----(SA) added some music interface + {"mu_start", AICast_ScriptAction_MusicStart}, // (char *new_music, int time) // time to fade in + {"mu_play", AICast_ScriptAction_MusicPlay}, // (char *new_music) + {"mu_stop", AICast_ScriptAction_MusicStop}, // (int time) // time to fadeout + {"mu_fade", AICast_ScriptAction_MusicFade}, // (float target_volume, int time) // time to fade to target + {"mu_queue", AICast_ScriptAction_MusicQueue}, // (char *new_music) // music that will start when previous fades to 0 +//----(SA) end + + {"explicit_routing", AICast_ScriptAction_ExplicitRouting}, + {"lockplayer", AICast_ScriptAction_LockPlayer}, + {"anim_condition", AICast_ScriptAction_AnimCondition}, + {"pushaway", AICast_ScriptAction_PushAway}, + {"catchfire", AICast_ScriptAction_CatchFire}, + + {NULL, NULL} +}; + +qboolean AICast_EventMatch_StringEqual( cast_script_event_t *event, char *eventParm ); +qboolean AICast_EventMatch_IntInRange( cast_script_event_t *event, char *eventParm ); + +// the list of events that can start an action sequence +// NOTE!!: only append to this list, DO NOT INSERT!! +cast_script_event_define_t scriptEvents[] = +{ + {"spawn", NULL}, // called as each character is spawned into the game + {"playerstart", NULL}, // called when player hits 'start' button + {"enemysight", AICast_EventMatch_StringEqual}, // enemy has been sighted for the first time (once only) + {"sight", AICast_EventMatch_StringEqual}, // non-enemy has been sighted for the first time (once only) + {"enemydead", AICast_EventMatch_StringEqual}, // our enemy is now dead + {"trigger", AICast_EventMatch_StringEqual}, // something has triggered us (always followed by an identifier) + {"pain", AICast_EventMatch_IntInRange}, // we've been hurt + {"death", AICast_EventMatch_StringEqual}, // RIP + {"activate", AICast_EventMatch_StringEqual}, // "param" has just activated us + {"enemysightcorpse",AICast_EventMatch_StringEqual}, // sighted the given enemy as a corpse, for the first time + {"friendlysightcorpse", NULL}, // sighted a friendly as a corpse for the first time + {"avoiddanger", AICast_EventMatch_StringEqual}, // we are avoiding something dangerous + {"blocked", AICast_EventMatch_StringEqual}, // blocked by someone else + {"statechange", AICast_EventMatch_StringEqual}, // changing aistates + {"bulletimpact", NULL}, + {"inspectbodystart", AICast_EventMatch_StringEqual}, // starting to travel to body for inspection + {"inspectbodyend", AICast_EventMatch_StringEqual}, // reached body for inspection + {"inspectsoundstart", AICast_EventMatch_StringEqual}, // reached sound for inspection + {"inspectsoundend", AICast_EventMatch_StringEqual}, // reached sound for inspection + {"attacksound", AICast_EventMatch_StringEqual}, // play a custom attack sound, and/or deny playing the default sound + {"fakedeath", NULL}, + {"bulletimpactsound", NULL}, + {"inspectfriendlycombatstart", NULL}, + {"painenemy", AICast_EventMatch_StringEqual}, + {"forced_mg42_unmount", NULL}, + + {NULL, NULL} +}; + + +/* +=============== +AICast_EventMatch_StringEqual +=============== +*/ +qboolean AICast_EventMatch_StringEqual( cast_script_event_t *event, char *eventParm ) { + if ( !event->params || !event->params[0] || ( eventParm && !Q_strcasecmp( event->params, eventParm ) ) ) { + return qtrue; + } else { + return qfalse; + } +} + +/* +=============== +AICast_EventMatch_IntInRange +=============== +*/ +qboolean AICast_EventMatch_IntInRange( cast_script_event_t *event, char *eventParm ) { + char *pString, *token; + int int1, int2, eInt; + + // get the cast name + pString = eventParm; + token = COM_ParseExt( &pString, qfalse ); + int1 = atoi( token ); + token = COM_ParseExt( &pString, qfalse ); + int2 = atoi( token ); + + eInt = atoi( event->params ); + + if ( eventParm && eInt > int1 && eInt <= int2 ) { + return qtrue; + } else { + return qfalse; + } +} + +/* +=============== +AICast_EventForString +=============== +*/ +int AICast_EventForString( char *string ) { + int i; + + for ( i = 0; scriptEvents[i].eventStr; i++ ) + { + if ( !Q_strcasecmp( string, scriptEvents[i].eventStr ) ) { + return i; + } + } + + return -1; +} + +//----(SA) added + +/* +=============== +AICast_ActionForString +=============== +*/ +cast_script_stack_action_t *AICast_ActionForString( cast_state_t *cs, char *string ) { + int i; + + for ( i = 0; scriptActions[i].actionString; i++ ) + { + if ( !Q_strcasecmp( string, scriptActions[i].actionString ) ) { + if ( !Q_strcasecmp( string, "foundsecret" ) ) { + level.numSecrets++; + G_SendMissionStats(); + } + return &scriptActions[i]; + } + } + + return NULL; +} + +/* +============= +AICast_ScriptLoad + + Loads the script for the current level into the buffer +============= +*/ +void AICast_ScriptLoad( void ) { + char filename[MAX_QPATH]; + vmCvar_t mapname; + fileHandle_t f; + int len; + + level.scriptAI = NULL; + + trap_Cvar_VariableStringBuffer( "ai_scriptName", filename, sizeof( filename ) ); + if ( strlen( filename ) > 0 ) { + trap_Cvar_Register( &mapname, "ai_scriptName", "", CVAR_ROM ); + } else { + trap_Cvar_Register( &mapname, "mapname", "", CVAR_SERVERINFO | CVAR_ROM ); + } + Q_strncpyz( filename, "maps/", sizeof( filename ) ); + Q_strcat( filename, sizeof( filename ), mapname.string ); + Q_strcat( filename, sizeof( filename ), ".ai" ); + + len = trap_FS_FOpenFile( filename, &f, FS_READ ); + + // make sure we clear out the temporary scriptname + trap_Cvar_Set( "ai_scriptName", "" ); + + if ( len < 0 ) { + return; + } + + level.scriptAI = G_Alloc( len ); + trap_FS_Read( level.scriptAI, len, f ); + + trap_FS_FCloseFile( f ); + + return; +} + +/* +============== +AICast_ScriptParse + + Parses the script for the given character +============== +*/ + +void AICast_ScriptParse( cast_state_t *cs ) { + #define MAX_SCRIPT_EVENTS 64 + gentity_t *ent; + char *pScript; + char *token; + qboolean wantName; + qboolean inScript; + int eventNum; + cast_script_event_t events[MAX_SCRIPT_EVENTS]; + int numEventItems; + cast_script_event_t *curEvent; + char params[MAX_QPATH]; + cast_script_stack_action_t *action; + int i; + int bracketLevel; + qboolean buildScript; //----(SA) added + + if ( !level.scriptAI ) { + return; + } + + ent = &g_entities[cs->entityNum]; + if ( !ent->aiName ) { + return; + } + + buildScript = trap_Cvar_VariableIntegerValue( "com_buildScript" ); + buildScript = qtrue; + + pScript = level.scriptAI; + wantName = qtrue; + inScript = qfalse; + COM_BeginParseSession( "AICast_ScriptParse" ); + bracketLevel = 0; + numEventItems = 0; + + memset( events, 0, sizeof( events ) ); + + while ( 1 ) + { + token = COM_Parse( &pScript ); + + if ( !token[0] ) { + if ( !wantName ) { + G_Error( "AICast_ScriptParse(), Error (line %d): '}' expected, end of script found.\n", COM_GetCurrentParseLine() ); + } + break; + } + + // end of script + if ( token[0] == '}' ) { + if ( inScript ) { + break; + } + if ( wantName ) { + G_Error( "AICast_ScriptParse(), Error (line %d): '}' found, but not expected.\n", COM_GetCurrentParseLine() ); + } + wantName = qtrue; + } else if ( token[0] == '{' ) { + if ( wantName ) { + G_Error( "AICast_ScriptParse(), Error (line %d): '{' found, NAME expected.\n", COM_GetCurrentParseLine() ); + } + } else if ( wantName ) { + if ( !Q_strcasecmp( ent->aiName, token ) ) { + inScript = qtrue; + numEventItems = 0; + } + wantName = qfalse; + } else if ( inScript ) { + if ( !Q_strcasecmp( token, "attributes" ) ) { + // read in all the attributes + AICast_CheckLevelAttributes( cs, ent, &pScript ); + continue; + } + eventNum = AICast_EventForString( token ); + if ( eventNum < 0 ) { + G_Error( "AICast_ScriptParse(), Error (line %d): unknown event: %s.\n", COM_GetCurrentParseLine(), token ); + } + if ( numEventItems >= MAX_SCRIPT_EVENTS ) { + G_Error( "AICast_ScriptParse(), Error (line %d): MAX_SCRIPT_EVENTS reached (%d)\n", COM_GetCurrentParseLine(), MAX_SCRIPT_EVENTS ); + } + + // if this is a "friendlysightcorpse" event, then disable corpse vis sharing + if ( !Q_stricmp( token, "friendlysightcorpse" ) ) { + cs->aiFlags &= ~AIFL_CORPSESIGHTING; + } + + curEvent = &events[numEventItems]; + curEvent->eventNum = eventNum; + memset( params, 0, sizeof( params ) ); + + // parse any event params before the start of this event's actions + while ( ( token = COM_Parse( &pScript ) ) && ( token[0] != '{' ) ) + { + if ( !token[0] ) { + G_Error( "AICast_ScriptParse(), Error (line %d): '}' expected, end of script found.\n", COM_GetCurrentParseLine() ); + } + + if ( eventNum == 13 ) { // statechange event, check params + if ( strlen( token ) > 1 ) { + if ( BG_IndexForString( token, animStateStr, qtrue ) < 0 ) { + G_Error( "AICast_ScriptParse(), Error (line %d): unknown state type '%s'.\n", COM_GetCurrentParseLine(), token ); + } + } + } + + if ( strlen( params ) ) { // add a space between each param + Q_strcat( params, sizeof( params ), " " ); + } + Q_strcat( params, sizeof( params ), token ); + } + + if ( strlen( params ) ) { // copy the params into the event + curEvent->params = G_Alloc( strlen( params ) + 1 ); + Q_strncpyz( curEvent->params, params, strlen( params ) + 1 ); + } + + // parse the actions for this event + while ( ( token = COM_Parse( &pScript ) ) && ( token[0] != '}' ) ) + { + if ( !token[0] ) { + G_Error( "AICast_ScriptParse(), Error (line %d): '}' expected, end of script found.\n", COM_GetCurrentParseLine() ); + } + + action = AICast_ActionForString( cs, token ); + if ( !action ) { + G_Error( "AICast_ScriptParse(), Error (line %d): unknown action: %s.\n", COM_GetCurrentParseLine(), token ); + } + + curEvent->stack.items[curEvent->stack.numItems].action = action; + + memset( params, 0, sizeof( params ) ); + token = COM_ParseExt( &pScript, qfalse ); + for ( i = 0; token[0]; i++ ) + { + if ( strlen( params ) ) { // add a space between each param + Q_strcat( params, sizeof( params ), " " ); + } + + if ( i == 0 ) { + // Special case: playsound's need to be cached on startup to prevent in-game pauses + if ( !Q_stricmp( action->actionString, "playsound" ) ) { + G_SoundIndex( token ); + } + +//----(SA) added a bit more + if ( buildScript && ( + !Q_stricmp( action->actionString, "mu_start" ) || + !Q_stricmp( action->actionString, "mu_play" ) || + !Q_stricmp( action->actionString, "mu_queue" ) || + !Q_stricmp( action->actionString, "startcam" ) || + !Q_stricmp( action->actionString, "startcamblack" ) ) + ) { + if ( strlen( token ) ) { // we know there's a [0], but don't know if it's '0' + trap_SendServerCommand( cs->entityNum, va( "addToBuild %s\n", token ) ); + } + } + + if ( !Q_stricmp( action->actionString, "giveweapon" ) ) { // register weapon for client pre-loading + gitem_t *weap = BG_FindItem2( token ); // (SA) FIXME: rats, need to fix this for weapon names with spaces: 'mauser rifle' +// if(weap) + RegisterItem( weap ); // don't be nice, just do it. if it can't find it, you'll bomb out to the error menu + } +//----(SA) end + } + + if ( strrchr( token,' ' ) ) { // need to wrap this param in quotes since it has more than one word + Q_strcat( params, sizeof( params ), "\"" ); + } + + Q_strcat( params, sizeof( params ), token ); + + if ( strrchr( token,' ' ) ) { // need to wrap this param in quotes since it has more than one word + Q_strcat( params, sizeof( params ), "\"" ); + } + + token = COM_ParseExt( &pScript, qfalse ); + } + + if ( strlen( params ) ) { // copy the params into the event + curEvent->stack.items[curEvent->stack.numItems].params = G_Alloc( strlen( params ) + 1 ); + Q_strncpyz( curEvent->stack.items[curEvent->stack.numItems].params, params, strlen( params ) + 1 ); + } + + curEvent->stack.numItems++; + + if ( curEvent->stack.numItems >= AICAST_MAX_SCRIPT_STACK_ITEMS ) { + G_Error( "AICast_ScriptParse(): script exceeded MAX_SCRIPT_ITEMS (%d), line %d\n", AICAST_MAX_SCRIPT_STACK_ITEMS, COM_GetCurrentParseLine() ); + } + } + + numEventItems++; + } else // skip this character completely + { + // TTimo: gcc: suggest () around assignment used as truth value + while ( ( token = COM_Parse( &pScript ) ) ) + { + if ( !token[0] ) { + G_Error( "AICast_ScriptParse(), Error (line %d): '}' expected, end of script found.\n", COM_GetCurrentParseLine() ); + } else if ( token[0] == '{' ) { + bracketLevel++; + } else if ( token[0] == '}' ) { + if ( !--bracketLevel ) { + break; + } + } + } + } + } + + // alloc and copy the events into the cast_state_t for this cast + if ( numEventItems > 0 ) { + cs->castScriptEvents = G_Alloc( sizeof( cast_script_event_t ) * numEventItems ); + memcpy( cs->castScriptEvents, events, sizeof( cast_script_event_t ) * numEventItems ); + cs->numCastScriptEvents = numEventItems; + + cs->castScriptStatus.castScriptEventIndex = -1; + } +} + +/* +================ +AICast_ScriptChange +================ +*/ +void AICast_ScriptChange( cast_state_t *cs, int newScriptNum ) { + cast_script_status_t scriptStatusBackup; + + cs->scriptCallIndex++; + + // backup the current scripting + scriptStatusBackup = cs->castScriptStatus; + + // set the new script to this cast, and reset script status + cs->castScriptStatus.castScriptStackHead = 0; + cs->castScriptStatus.castScriptStackChangeTime = level.time; + cs->castScriptStatus.castScriptEventIndex = newScriptNum; + cs->castScriptStatus.scriptId = scriptStatusBackup.scriptId + 1; + cs->castScriptStatus.scriptGotoId = -1; + cs->castScriptStatus.scriptGotoEnt = -1; + cs->castScriptStatus.scriptFlags |= SFL_FIRST_CALL; + + // try and run the script, if it doesn't finish, then abort the current script (discard backup) + if ( AICast_ScriptRun( cs, qtrue ) ) { + // completed successfully + cs->castScriptStatus.castScriptStackHead = scriptStatusBackup.castScriptStackHead; + cs->castScriptStatus.castScriptStackChangeTime = scriptStatusBackup.castScriptStackChangeTime; + cs->castScriptStatus.castScriptEventIndex = scriptStatusBackup.castScriptEventIndex; + cs->castScriptStatus.scriptId = scriptStatusBackup.scriptId; + cs->castScriptStatus.scriptFlags = scriptStatusBackup.scriptFlags; + } +} + +/* +================ +AICast_ScriptEvent + + An event has occured, for which a script may exist +================ +*/ +void AICast_ScriptEvent( struct cast_state_s *cs, char *eventStr, char *params ) { + int i, eventNum; + + eventNum = -1; + + // find out which event this is + for ( i = 0; scriptEvents[i].eventStr; i++ ) + { + if ( !Q_strcasecmp( eventStr, scriptEvents[i].eventStr ) ) { // match found + eventNum = i; + break; + } + } + + if ( eventNum < 0 ) { + if ( g_cheats.integer ) { // dev mode + G_Printf( "devmode-> AICast_ScriptEvent(), unknown event: %s\n", eventStr ); + } + } + + // show debugging info + if ( ( ( aicast_debug.integer == 1 ) || + ( ( aicast_debug.integer == 2 ) && + ( ( strlen( aicast_debugname.string ) < 1 ) || ( g_entities[cs->entityNum].aiName && !strcmp( aicast_debugname.string, g_entities[cs->entityNum].aiName ) ) ) ) ) ) { + G_Printf( "(%s) AIScript event: %s %s ", g_entities[cs->entityNum].aiName, eventStr, params ); + } + + cs->aiFlags &= ~AIFL_DENYACTION; + + // see if this cast has this event + for ( i = 0; i < cs->numCastScriptEvents; i++ ) + { + if ( cs->castScriptEvents[i].eventNum == eventNum ) { + if ( ( !cs->castScriptEvents[i].params ) + || ( !scriptEvents[eventNum].eventMatch || scriptEvents[eventNum].eventMatch( &cs->castScriptEvents[i], params ) ) ) { + + // show debugging info + if ( ( ( aicast_debug.integer == 1 ) || + ( ( aicast_debug.integer == 2 ) && + ( ( strlen( aicast_debugname.string ) < 1 ) || ( g_entities[cs->entityNum].aiName && !strcmp( aicast_debugname.string, g_entities[cs->entityNum].aiName ) ) ) ) ) ) { + G_Printf( "found, calling script\n", g_entities[cs->entityNum].aiName, eventStr, params ); + } + + AICast_ScriptChange( cs, i ); + break; + } + } + } + + // show debugging info + if ( ( ( aicast_debug.integer == 1 ) || + ( ( aicast_debug.integer == 2 ) && + ( ( strlen( aicast_debugname.string ) < 1 ) || ( g_entities[cs->entityNum].aiName && !strcmp( aicast_debugname.string, g_entities[cs->entityNum].aiName ) ) ) ) ) ) { + if ( i == cs->numCastScriptEvents ) { + G_Printf( "not found\n" ); + } + } + +} + +/* +================ +AICast_ForceScriptEvent + + Definately run this event now, overriding any paised state +================ +*/ +void AICast_ForceScriptEvent( struct cast_state_s *cs, char *eventStr, char *params ) { + int oldPauseTime; + + oldPauseTime = cs->scriptPauseTime; + cs->scriptPauseTime = 0; + + AICast_ScriptEvent( cs, eventStr, params ); + + cs->scriptPauseTime = oldPauseTime; +} + +/* +============= +AICast_ScriptRun + + returns qtrue if the script completed +============= +*/ +qboolean AICast_ScriptRun( cast_state_t *cs, qboolean force ) { + cast_script_stack_t *stack; + + if ( !aicast_scripts.integer ) { + return qtrue; + } + + if ( cs->castScriptStatus.castScriptEventIndex < 0 ) { + return qtrue; + } + + if ( !cs->castScriptEvents ) { + cs->castScriptStatus.castScriptEventIndex = -1; + return qtrue; + } + + // only allow the PLAYER'S spawn function through if we're NOT still waiting on everything to finish loading in + if ( !cs->entityNum && saveGamePending && Q_stricmp( "spawn", scriptEvents[cs->castScriptEvents[cs->castScriptStatus.castScriptEventIndex].eventNum].eventStr ) ) { + //char loading[4]; + //trap_Cvar_VariableStringBuffer( "savegame_loading", loading, sizeof(loading) ); + //if (strlen( loading ) > 0 && atoi(loading) != 0) // we're loading a savegame + return qfalse; + } + + if ( !force && ( cs->scriptPauseTime >= level.time ) ) { + return qtrue; + } + + stack = &cs->castScriptEvents[cs->castScriptStatus.castScriptEventIndex].stack; + + if ( !stack->numItems ) { + cs->castScriptStatus.castScriptEventIndex = -1; + return qtrue; + } + + while ( cs->castScriptStatus.castScriptStackHead < stack->numItems ) + { + // + // show debugging info + if ( ( cs->castScriptStatus.castScriptStackChangeTime == level.time ) && + ( ( aicast_debug.integer == 1 ) || + ( ( aicast_debug.integer == 2 ) && + ( ( strlen( aicast_debugname.string ) < 1 ) || ( g_entities[cs->entityNum].aiName && !strcmp( aicast_debugname.string, g_entities[cs->entityNum].aiName ) ) ) ) ) ) { + G_Printf( "(%s) AIScript command: %s %s\n", g_entities[cs->entityNum].aiName, stack->items[cs->castScriptStatus.castScriptStackHead].action->actionString, ( stack->items[cs->castScriptStatus.castScriptStackHead].params ? stack->items[cs->castScriptStatus.castScriptStackHead].params : "" ) ); + } + // + if ( !stack->items[cs->castScriptStatus.castScriptStackHead].action->actionFunc( cs, stack->items[cs->castScriptStatus.castScriptStackHead].params ) ) { + // check that we are still running the same script that we were when we call the action + if ( cs->castScriptStatus.castScriptEventIndex >= 0 && stack == &cs->castScriptEvents[cs->castScriptStatus.castScriptEventIndex].stack ) { + cs->castScriptStatus.scriptFlags &= ~SFL_FIRST_CALL; + } + return qfalse; + } + // move to the next action in the script + cs->castScriptStatus.castScriptStackHead++; + // record the time that this new item became active + cs->castScriptStatus.castScriptStackChangeTime = level.time; + // reset misc stuff + cs->castScriptStatus.scriptGotoId = -1; + cs->castScriptStatus.scriptGotoEnt = -1; + cs->castScriptStatus.scriptFlags |= SFL_FIRST_CALL; + } + + cs->castScriptStatus.castScriptEventIndex = -1; + + return qtrue; +} diff --git a/Projects/Android/jni/rtcw/src/game/ai_cast_script_actions.c b/Projects/Android/jni/rtcw/src/game/ai_cast_script_actions.c new file mode 100644 index 0000000..746e6e5 --- /dev/null +++ b/Projects/Android/jni/rtcw/src/game/ai_cast_script_actions.c @@ -0,0 +1,3108 @@ +/* +=========================================================================== + +Return to Castle Wolfenstein single player GPL Source Code +Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company. + +This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”). + +RTCW SP Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RTCW SP Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RTCW SP Source Code. If not, see . + +In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below. + +If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. + +=========================================================================== +*/ + +//=========================================================================== +// +// Name: ai_cast_script_actions.c +// Function: Wolfenstein AI Character Scripting +// Programmer: Ridah +// Tab Size: 4 (real tabs) +//=========================================================================== + +#include "../game/g_local.h" +#include "../game/q_shared.h" +#include "../game/botlib.h" //bot lib interface +#include "../game/be_aas.h" +#include "../game/be_ea.h" +#include "../game/be_ai_gen.h" +#include "../game/be_ai_goal.h" +#include "../game/be_ai_move.h" +#include "../botai/botai.h" //bot ai interface + +#include "ai_cast.h" + +/* +Contains the code to handle the various commands available with an event script. + +These functions will return true if the action has been performed, and the script +should proceed to the next item on the list. +*/ + +/* +=============== +AICast_NoAttackIfNotHurtSinceLastScriptAction + + Not an actual command, this is just used by the script code +=============== +*/ +void AICast_NoAttackIfNotHurtSinceLastScriptAction( cast_state_t *cs ) { + if ( cs->castScriptStatus.scriptNoAttackTime > level.time ) { + return; + } + + // if not moving, we should attack + if ( VectorLength( cs->bs->velocity ) < 10 ) { + return; + } + + // if our enemy is in the direction we are moving, don't hold back + if ( cs->enemyNum >= 0 && cs->castScriptStatus.scriptGotoEnt >= 0 ) { + vec3_t v; + + VectorSubtract( g_entities[cs->enemyNum].r.currentOrigin, cs->bs->origin, v ); + if ( DotProduct( cs->bs->velocity, v ) > 0 ) { + return; + } + } + + if ( cs->lastPain < cs->castScriptStatus.castScriptStackChangeTime ) { + cs->castScriptStatus.scriptNoAttackTime = level.time + FRAMETIME; + } +} + +/* +=============== +AICast_ScriptAction_GotoMarker + + syntax: gotomarker [firetarget [noattack]] [nostop] OR runtomarker [firetarget [noattack]] [nostop] +=============== +*/ +qboolean AICast_ScriptAction_GotoMarker( cast_state_t *cs, char *params ) { +#define SCRIPT_REACHGOAL_DIST 8 + char *pString, *token; + gentity_t *ent; + vec3_t vec, org; + int i, diff; + qboolean slowApproach; + + ent = NULL; + + // if we are avoiding danger, then wait for the danger to pass + if ( cs->castScriptStatus.scriptGotoId < 0 && cs->dangerEntityValidTime > level.time ) { + return qfalse; + } + // if we are in a special func, then wait + if ( cs->aiFlags & AIFL_SPECIAL_FUNC ) { + return qfalse; + } + + pString = params; + token = COM_ParseExt( &pString, qfalse ); + if ( !token[0] ) { + G_Error( "AI scripting: gotomarker must have an targetname\n" ); + } + + // if we already are going to the marker, just use that, and check if we're in range + if ( cs->castScriptStatus.scriptGotoEnt >= 0 && cs->castScriptStatus.scriptGotoId == cs->thinkFuncChangeTime ) { + ent = &g_entities[cs->castScriptStatus.scriptGotoEnt]; + if ( ent->targetname && !Q_strcasecmp( ent->targetname, token ) ) { + // if we're not slowing down, then check for passing the marker, otherwise check distance only + VectorSubtract( ent->r.currentOrigin, cs->bs->origin, vec ); + // + if ( cs->followSlowApproach && VectorLength( vec ) < cs->followDist ) { + cs->followTime = 0; + AIFunc_IdleStart( cs ); // resume normal AI + return qtrue; + } else if ( !cs->followSlowApproach && VectorLength( vec ) < 64 /*&& DotProduct(cs->bs->cur_ps.velocity, vec) < 0*/ ) { + cs->followTime = 0; + AIFunc_IdleStart( cs ); // resume normal AI + return qtrue; + } else + { + // do we have a firetarget ? + token = COM_ParseExt( &pString, qfalse ); + if ( !token[0] || !Q_stricmp( token,"nostop" ) ) { + AICast_NoAttackIfNotHurtSinceLastScriptAction( cs ); + } else { // yes we do + // find this targetname + ent = G_Find( NULL, FOFS( targetname ), token ); + if ( !ent ) { + ent = AICast_FindEntityForName( token ); + if ( !ent ) { + G_Error( "AI Scripting: gotomarker cannot find targetname \"%s\"\n", token ); + } + } + // set the view angle manually + BG_EvaluateTrajectory( &ent->s.pos, level.time, org ); + VectorSubtract( org, cs->bs->origin, vec ); + VectorNormalize( vec ); + vectoangles( vec, cs->ideal_viewangles ); + // noattack? + token = COM_ParseExt( &pString, qfalse ); + if ( !token[0] || Q_stricmp( token,"noattack" ) ) { + qboolean fire = qtrue; + // if it's an AI, and they aren't visible, dont shoot + if ( ent->r.svFlags & SVF_CASTAI ) { + if ( cs->vislist[ent->s.number].real_visible_timestamp != cs->vislist[ent->s.number].lastcheck_timestamp ) { + fire = qfalse; + } + } + if ( fire ) { + for ( i = 0; i < 2; i++ ) { + diff = abs( AngleDifference( cs->viewangles[i], cs->ideal_viewangles[i] ) ); + if ( diff < 20 ) { + // dont reload prematurely + cs->noReloadTime = level.time + 1000; + // force fire + trap_EA_Attack( cs->bs->client ); + // + cs->bFlags |= BFL_ATTACKED; + // dont reload prematurely + cs->noReloadTime = level.time + 200; + } + } + } + } + } + cs->followTime = level.time + 500; + return qfalse; + } + } else + { + ent = NULL; + } + } + + // find the ai_marker with the given "targetname" + // TTimo: gcc: suggest () around assignment used as truth value + while ( ( ent = G_Find( ent, FOFS( classname ), "ai_marker" ) ) ) + { + if ( ent->targetname && !Q_strcasecmp( ent->targetname, token ) ) { + break; + } + } + + if ( !ent ) { + G_Error( "AI Scripting: can't find ai_marker with \"targetname\" = \"%s\"\n", token ); + } + + if ( Distance( cs->bs->origin, ent->r.currentOrigin ) < SCRIPT_REACHGOAL_DIST ) { // we made it + return qtrue; + } + + cs->castScriptStatus.scriptNoMoveTime = 0; + cs->castScriptStatus.scriptGotoEnt = ent->s.number; + // + // slow approach to the goal? + if ( !params || !strstr( params," nostop" ) ) { + slowApproach = qtrue; + } else { + slowApproach = qfalse; + } + // + AIFunc_ChaseGoalStart( cs, ent->s.number, ( slowApproach ? SCRIPT_REACHGOAL_DIST : 32 ), slowApproach ); + cs->followIsGoto = qtrue; + cs->followTime = 0x7fffffff; // make sure it gets through for the first frame + cs->castScriptStatus.scriptGotoId = cs->thinkFuncChangeTime; + + AICast_NoAttackIfNotHurtSinceLastScriptAction( cs ); + return qfalse; +} + +/* +=============== +AICast_ScriptAction_WalkToMarker + + syntax: walktomarker [firetarget [noattack]] [nostop] +=============== +*/ +qboolean AICast_ScriptAction_WalkToMarker( cast_state_t *cs, char *params ) { + // if we are avoiding danger, then wait for the danger to pass + if ( cs->castScriptStatus.scriptGotoId < 0 && cs->dangerEntityValidTime > level.time ) { + return qfalse; + } + // if we are in a special func, then wait + if ( cs->aiFlags & AIFL_SPECIAL_FUNC ) { + return qfalse; + } + if ( !AICast_ScriptAction_GotoMarker( cs, params ) || ( !strstr( params, " nostop" ) && VectorLength( cs->bs->cur_ps.velocity ) ) ) { + cs->movestate = MS_WALK; + cs->movestateType = MSTYPE_TEMPORARY; + AICast_NoAttackIfNotHurtSinceLastScriptAction( cs ); + return qfalse; + } + + return qtrue; +} + + +/* +=============== +AICast_ScriptAction_CrouchToMarker + + syntax: crouchtomarker [firetarget [noattack]] [nostop] +=============== +*/ +qboolean AICast_ScriptAction_CrouchToMarker( cast_state_t *cs, char *params ) { + // if we are avoiding danger, then wait for the danger to pass + if ( cs->castScriptStatus.scriptGotoId < 0 && cs->dangerEntityValidTime > level.time ) { + return qfalse; + } + // if we are in a special func, then wait + if ( cs->aiFlags & AIFL_SPECIAL_FUNC ) { + return qfalse; + } + if ( !AICast_ScriptAction_GotoMarker( cs, params ) || ( !strstr( params, " nostop" ) && VectorLength( cs->bs->cur_ps.velocity ) ) ) { + cs->movestate = MS_CROUCH; + cs->movestateType = MSTYPE_TEMPORARY; + AICast_NoAttackIfNotHurtSinceLastScriptAction( cs ); + return qfalse; + } + + return qtrue; +} + +/* +=============== +AICast_ScriptAction_GotoCast + + syntax: gotocast [firetarget [noattack]] OR runtocast [firetarget [noattack]] +=============== +*/ +qboolean AICast_ScriptAction_GotoCast( cast_state_t *cs, char *params ) { +#define SCRIPT_REACHCAST_DIST 64 + char *pString, *token; + gentity_t *ent; + vec3_t vec, org; + int i, diff; + + ent = NULL; + + // if we are avoiding danger, then wait for the danger to pass + if ( cs->castScriptStatus.scriptGotoId < 0 && cs->dangerEntityValidTime > level.time ) { + return qfalse; + } + // if we are in a special func, then wait + if ( cs->aiFlags & AIFL_SPECIAL_FUNC ) { + return qfalse; + } + + pString = params; + token = COM_ParseExt( &pString, qfalse ); + if ( !token[0] ) { + G_Error( "AI scripting: gotocast must have an ainame\n" ); + } + + // if we already are going to the marker, just use that, and check if we're in range + if ( cs->castScriptStatus.scriptGotoEnt >= 0 && cs->castScriptStatus.scriptGotoId == cs->thinkFuncChangeTime ) { + ent = &g_entities[cs->castScriptStatus.scriptGotoEnt]; + if ( ent->targetname && !Q_strcasecmp( ent->targetname, token ) ) { + if ( Distance( cs->bs->origin, ent->r.currentOrigin ) < cs->followDist ) { + cs->followTime = 0; + AIFunc_IdleStart( cs ); // resume normal AI + return qtrue; + } else + { + // do we have a firetarget ? + token = COM_ParseExt( &pString, qfalse ); + if ( !token[0] ) { + AICast_NoAttackIfNotHurtSinceLastScriptAction( cs ); + } else { // yes we do + // find this targetname + ent = G_Find( NULL, FOFS( targetname ), token ); + if ( !ent ) { + ent = AICast_FindEntityForName( token ); + if ( !ent ) { + G_Error( "AI Scripting: gotomarker cannot find targetname \"%s\"\n", token ); + } + } + + // set the view angle manually + BG_EvaluateTrajectory( &ent->s.pos, level.time, org ); + VectorSubtract( org, cs->bs->origin, vec ); + VectorNormalize( vec ); + vectoangles( vec, cs->ideal_viewangles ); + // noattack? + token = COM_ParseExt( &pString, qfalse ); + if ( !token[0] || Q_stricmp( token,"noattack" ) ) { + qboolean fire = qtrue; + // if it's an AI, and they aren't visible, dont shoot + if ( ent->r.svFlags & SVF_CASTAI ) { + if ( cs->vislist[ent->s.number].real_visible_timestamp != cs->vislist[ent->s.number].lastcheck_timestamp ) { + fire = qfalse; + } + } + if ( fire ) { + for ( i = 0; i < 2; i++ ) { + diff = abs( AngleDifference( cs->viewangles[i], cs->ideal_viewangles[i] ) ); + if ( diff < 20 ) { + // dont reload prematurely + cs->noReloadTime = level.time + 1000; + // force fire + trap_EA_Attack( cs->bs->client ); + // + cs->bFlags |= BFL_ATTACKED; + // dont reload prematurely + cs->noReloadTime = level.time + 200; + } + } + } + } + } + cs->followTime = level.time + 500; + return qfalse; + } + } else + { + ent = NULL; + } + } + + // find the cast/player with the given "name" + ent = AICast_FindEntityForName( token ); + if ( !ent ) { + G_Error( "AI Scripting: can't find AI cast with \"ainame\" = \"%s\"\n", token ); + } + + if ( Distance( cs->bs->origin, ent->r.currentOrigin ) < SCRIPT_REACHCAST_DIST ) { // we made it + return qtrue; + } + + if ( !ent ) { + G_Error( "AI Scripting: can't find ai_marker with \"targetname\" = \"%s\"\n", token ); + } + + cs->castScriptStatus.scriptNoMoveTime = 0; + cs->castScriptStatus.scriptGotoEnt = ent->s.number; + // + AIFunc_ChaseGoalStart( cs, ent->s.number, SCRIPT_REACHCAST_DIST, qtrue ); + cs->followTime = 0x7fffffff; + AICast_NoAttackIfNotHurtSinceLastScriptAction( cs ); + cs->castScriptStatus.scriptGotoId = cs->thinkFuncChangeTime; + + return qfalse; +} + +/* +=============== +AICast_ScriptAction_WalkToCast + + syntax: walktocast [firetarget [noattack]] +=============== +*/ +qboolean AICast_ScriptAction_WalkToCast( cast_state_t *cs, char *params ) { + // if we are avoiding danger, then wait for the danger to pass + if ( cs->castScriptStatus.scriptGotoId < 0 && cs->dangerEntityValidTime > level.time ) { + return qfalse; + } + // if we are in a special func, then wait + if ( cs->aiFlags & AIFL_SPECIAL_FUNC ) { + return qfalse; + } + if ( !AICast_ScriptAction_GotoCast( cs, params ) ) { + cs->movestate = MS_WALK; + cs->movestateType = MSTYPE_TEMPORARY; + AICast_NoAttackIfNotHurtSinceLastScriptAction( cs ); + return qfalse; + } + + return qtrue; +} + + +/* +=============== +AICast_ScriptAction_CrouchToCast + + syntax: crouchtocast [firetarget [noattack]] +=============== +*/ +qboolean AICast_ScriptAction_CrouchToCast( cast_state_t *cs, char *params ) { + // if we are avoiding danger, then wait for the danger to pass + if ( cs->castScriptStatus.scriptGotoId < 0 && cs->dangerEntityValidTime > level.time ) { + return qfalse; + } + // if we are in a special func, then wait + if ( cs->aiFlags & AIFL_SPECIAL_FUNC ) { + return qfalse; + } + if ( !AICast_ScriptAction_GotoCast( cs, params ) ) { + cs->movestate = MS_CROUCH; + cs->movestateType = MSTYPE_TEMPORARY; + AICast_NoAttackIfNotHurtSinceLastScriptAction( cs ); + return qfalse; + } + + return qtrue; +} + + +/* +============== +AICast_ScriptAction_AbortIfLoadgame +============== +*/ +qboolean AICast_ScriptAction_AbortIfLoadgame( cast_state_t *cs, char *params ) { + char loading[4]; + + trap_Cvar_VariableStringBuffer( "savegame_loading", loading, sizeof( loading ) ); + + if ( strlen( loading ) > 0 && atoi( loading ) != 0 ) { + // abort the current script + cs->castScriptStatus.castScriptStackHead = cs->castScriptEvents[cs->castScriptStatus.castScriptEventIndex].stack.numItems; + } + + return qtrue; +} + + +/* +================= +AICast_ScriptAction_Wait + + syntax: wait [moverange] [facetarget] + + moverange defaults to 200, allows some monouverability to avoid fire or attack +================= +*/ +qboolean AICast_ScriptAction_Wait( cast_state_t *cs, char *params ) { + char *pString, *token, *facetarget; + int duration; + float moverange; + float dist; + gentity_t *ent; + vec3_t org, vec; + + // if we are in a special func, then wait + if ( cs->aiFlags & AIFL_SPECIAL_FUNC ) { + return qfalse; + } + // EXPERIMENTAL: if they are on fire, or avoiding danger, let them loose until it passes (or they die) + if ( cs->dangerEntityValidTime > level.time ) { + cs->castScriptStatus.scriptNoMoveTime = -1; + return qfalse; + } + + if ( ( cs->castScriptStatus.scriptFlags & SFL_FIRST_CALL ) && cs->bs ) { + // first call, init the waitPos + VectorCopy( cs->bs->origin, cs->castScriptStatus.scriptWaitPos ); + } + + // get the duration + pString = params; + token = COM_ParseExt( &pString, qfalse ); + if ( !token[0] ) { + G_Error( "AI scripting: wait must have a duration\n" ); + } + if ( !Q_stricmp( token, "forever" ) ) { + duration = level.time + 10000; + } else { + duration = atoi( token ); + } + + // if this is for the player, don't worry about enforcing the moverange + if ( !cs->bs ) { + return ( cs->castScriptStatus.castScriptStackChangeTime + duration < level.time ); + } + + token = COM_ParseExt( &pString, qfalse ); + // if this token is a number, then assume it is the moverange, otherwise we have a default moverange with a facetarget + moverange = -999; + facetarget = NULL; + if ( token[0] ) { + if ( toupper( token[0] ) >= 'A' && toupper( token[0] ) <= 'Z' ) { + facetarget = token; + } else { // we found a moverange + moverange = atof( token ); + token = COM_ParseExt( &pString, qfalse ); + if ( token[0] ) { + facetarget = token; + } + } + } + + // default to no moverange + //if (moverange == -999) { + // moverange = 200; + //} + + if ( moverange != 0 ) { // default to 200 if no range given + if ( moverange > 0 ) { + dist = Distance( cs->bs->origin, cs->castScriptStatus.scriptWaitPos ); + // if we are able to move, and have an enemy + if ( ( cs->castScriptStatus.scriptWaitMovetime < level.time ) + && ( cs->enemyNum >= 0 ) ) { + + // if we can attack them, or they can't attack us, stay here + // TTimo: gcc: warning: suggest parentheses around && within || + if ( AICast_CheckAttack( cs, cs->enemyNum, qfalse ) + || ( !AICast_EntityVisible( AICast_GetCastState( cs->enemyNum ), cs->entityNum, qfalse ) + && !AICast_CheckAttack( AICast_GetCastState( cs->enemyNum ), cs->entityNum, qfalse ) ) ) { + cs->castScriptStatus.scriptNoMoveTime = level.time + 200; + } + + } + // if outside range, move towards waitPos + if ( ( !cs->bs || !cs->bs->cur_ps.legsTimer ) && ( ( ( cs->castScriptStatus.scriptWaitMovetime > level.time ) && ( dist > 32 ) ) || ( dist > moverange ) ) ) { + cs->castScriptStatus.scriptNoMoveTime = 0; + AICast_MoveToPos( cs, cs->castScriptStatus.scriptWaitPos, 0 ); + if ( dist > 64 ) { + cs->castScriptStatus.scriptWaitMovetime = level.time + 600; + } + } else + // if we are reloading, look for somewhere to hide + if ( cs->castScriptStatus.scriptWaitHideTime > level.time || cs->bs->cur_ps.weaponTime > 500 ) { + if ( cs->castScriptStatus.scriptWaitHideTime < level.time ) { + // look for a hide pos within the wait range + + } + cs->castScriptStatus.scriptWaitHideTime = level.time + 500; + } + } + } else { + cs->castScriptStatus.scriptNoMoveTime = cs->castScriptStatus.castScriptStackChangeTime + duration; + } + + // do we have a facetarget ? + if ( facetarget ) { // yes we do + // find this targetname + ent = G_Find( NULL, FOFS( targetname ), facetarget ); + if ( !ent ) { + ent = AICast_FindEntityForName( facetarget ); + if ( !ent ) { + G_Error( "AI Scripting: wait cannot find targetname \"%s\"\n", token ); + } + } + // set the view angle manually + BG_EvaluateTrajectory( &ent->s.pos, level.time, org ); + VectorSubtract( org, cs->bs->origin, vec ); + VectorNormalize( vec ); + vectoangles( vec, cs->ideal_viewangles ); + } + + return ( cs->castScriptStatus.castScriptStackChangeTime + duration < level.time ); +} + +/* +================= +AICast_ScriptAction_Trigger + + syntax: trigger + + Calls the specified trigger for the given ai character +================= +*/ +qboolean AICast_ScriptAction_Trigger( cast_state_t *cs, char *params ) { + gentity_t *ent; + char *pString, *token; + int oldId; + + // get the cast name + pString = params; + token = COM_ParseExt( &pString, qfalse ); + if ( !token[0] ) { + G_Error( "AI scripting: trigger must have a name and an identifier\n" ); + } + + ent = AICast_FindEntityForName( token ); + if ( !ent ) { + ent = G_Find( &g_entities[MAX_CLIENTS], FOFS( scriptName ), token ); + if ( !ent ) { + if ( trap_Cvar_VariableIntegerValue( "developer" ) ) { + G_Printf( "AI Scripting: can't find AI cast with \"ainame\" = \"%s\"\n", params ); + } + return qtrue; + } + } + + token = COM_ParseExt( &pString, qfalse ); + if ( !token[0] ) { + G_Error( "AI scripting: trigger must have a name and an identifier\n" ); + } + + oldId = cs->castScriptStatus.scriptId; + if ( ent->client ) { + AICast_ScriptEvent( AICast_GetCastState( ent->s.number ), "trigger", token ); + } else { + G_Script_ScriptEvent( ent, "trigger", token ); + } + + // if the script changed, return false so we don't muck with it's variables + return ( oldId == cs->castScriptStatus.scriptId ); +} + +/* +=================== +AICast_ScriptAction_FollowCast + + syntax: followcast +=================== +*/ +qboolean AICast_ScriptAction_FollowCast( cast_state_t *cs, char *params ) { + gentity_t *ent; + + // find the cast/player with the given "name" + ent = AICast_FindEntityForName( params ); + if ( !ent ) { + G_Error( "AI Scripting: can't find AI cast with \"ainame\" = \"%s\"\n", params ); + } + + AIFunc_ChaseGoalStart( cs, ent->s.number, 64, qtrue ); + + return qtrue; +}; + +/* +================ +AICast_ScriptAction_PlaySound + + syntax: playsound + + Currently only allows playing on the VOICE channel, unless you use a sound script (yay) +================ +*/ +qboolean AICast_ScriptAction_PlaySound( cast_state_t *cs, char *params ) { + if ( !params ) { + G_Error( "AI Scripting: syntax error\n\nplaysound \n" ); + } + + G_AddEvent( &g_entities[cs->bs->entitynum], EV_GENERAL_SOUND, G_SoundIndex( params ) ); + + // assume we are talking + cs->aiFlags |= AIFL_TALKING; + + // randomly choose idle animation + if ( cs->aiFlags & AIFL_STAND_IDLE2 ) { + if ( cs->lastEnemy < 0 && cs->aiFlags & AIFL_TALKING ) { + g_entities[cs->entityNum].client->ps.eFlags |= EF_STAND_IDLE2; + } else { + g_entities[cs->entityNum].client->ps.eFlags &= ~EF_STAND_IDLE2; + } + } + + return qtrue; +} + +/* +================= +AICast_ScriptAction_NoAttack + + syntax: noattack +================= +*/ +qboolean AICast_ScriptAction_NoAttack( cast_state_t *cs, char *params ) { + if ( !params ) { + G_Error( "AI Scripting: syntax error\n\nnoattack \n" ); + } + + cs->castScriptStatus.scriptNoAttackTime = level.time + atoi( params ); + + return qtrue; +} + +/* +================= +AICast_ScriptAction_Attack + + syntax: attack [ainame] + + Resumes attacking after a noattack was issued + + if ainame is given, we will attack only that entity as long as they are alive +================= +*/ +qboolean AICast_ScriptAction_Attack( cast_state_t *cs, char *params ) { + gentity_t *ent; + + cs->castScriptStatus.scriptNoAttackTime = 0; + + // if we have specified an aiName, then we should attack only this person + if ( params ) { + ent = AICast_FindEntityForName( params ); + if ( !ent ) { + G_Error( "AI Scripting: \"attack\" command unable to find aiName \"%s\"", params ); + } + cs->castScriptStatus.scriptAttackEnt = ent->s.number; + cs->enemyNum = ent->s.number; + } else { + cs->castScriptStatus.scriptAttackEnt = -1; + } + + return qtrue; +} + +/* +================= +AICast_ScriptAction_PlayAnim + + syntax: playanim [legs/torso/both] [HOLDFRAME] [numLoops/FOREVER] [target] + + NOTE: any new animations that are needed by the scripting system, will need to be added here +================= +*/ +qboolean AICast_ScriptAction_PlayAnim( cast_state_t *cs, char *params ) { + char *pString, *token, tokens[3][MAX_QPATH]; + int i, endtime, duration, numLoops; + gclient_t *client; + gentity_t *ent; + vec3_t org, vec; + qboolean forever = qfalse, setAngles = qfalse; + qboolean holdframe = qfalse; + + pString = params; + + client = &level.clients[cs->entityNum]; + + if ( level.animScriptData.modelInfo[level.animScriptData.clientModels[cs->entityNum] - 1]->version > 1 ) { // new (scripted) model + + // read the name + token = COM_ParseExt( &pString, qfalse ); + if ( !token || !token[0] ) { + G_Error( "AI Scripting: syntax error\n\nplayanim \n" ); + } + Q_strncpyz( tokens[0], token, sizeof( tokens[0] ) ); + Q_strlwr( tokens[0] ); + + // read the body part + token = COM_ParseExt( &pString, qfalse ); + if ( !token || !token[0] ) { + G_Error( "AI Scripting: syntax error\n\nplayanim \n" ); + } + Q_strncpyz( tokens[1], token, sizeof( tokens[1] ) ); + Q_strlwr( tokens[1] ); + + // read the HOLDFRAME (optional) + token = COM_ParseExt( &pString, qfalse ); + if ( token && token[0] && !Q_strcasecmp( token, "holdframe" ) ) { + holdframe = qtrue; + // read the numLoops (optional) + token = COM_ParseExt( &pString, qfalse ); + } + // token is parsed above + if ( token && token[0] ) { + if ( !Q_strcasecmp( token, "forever" ) ) { + forever = qtrue; + numLoops = -1; + // read the target (optional) + token = COM_ParseExt( &pString, qfalse ); + } else { + numLoops = atoi( token ); + if ( !numLoops ) { // must be the target, so set loops to 1 + numLoops = 1; + } else { + // read the target (optional) + token = COM_ParseExt( &pString, qfalse ); + } + } + + if ( token && token[0] ) { + // find this targetname + ent = G_Find( NULL, FOFS( targetname ), token ); + if ( !ent ) { + ent = AICast_FindEntityForName( token ); + if ( !ent ) { + G_Error( "AI Scripting: playanim cannot find targetname \"%s\"\n", token ); + } + } + // set the view angle manually + BG_EvaluateTrajectory( &ent->s.pos, level.time, org ); + VectorSubtract( org, cs->bs->origin, vec ); + VectorNormalize( vec ); + vectoangles( vec, cs->ideal_viewangles ); + VectorCopy( cs->ideal_viewangles, cs->castScriptStatus.playanim_viewangles ); + setAngles = qtrue; + } + + } else { + numLoops = 1; + } + + if ( cs->castScriptStatus.scriptFlags & SFL_FIRST_CALL ) { + // first time in here, play the anim + duration = BG_PlayAnimName( &( client->ps ), tokens[0], BG_IndexForString( tokens[1], animBodyPartsStr, qfalse ), qtrue, qfalse, qtrue ); + if ( numLoops == -1 ) { + cs->scriptAnimTime = 0x7fffffff; // maximum time allowed + } else { + cs->scriptAnimTime = level.time + ( numLoops * duration ); + } + if ( !strcmp( tokens[1], "torso" ) ) { + cs->scriptAnimNum = client->ps.torsoAnim & ~ANIM_TOGGLEBIT; + // adjust the duration according to numLoops + if ( numLoops > 1 ) { + client->ps.torsoTimer += duration * numLoops; + } else if ( numLoops == -1 ) { + client->ps.torsoTimer = 9999; + } + } else { // dont move + cs->scriptAnimNum = client->ps.legsAnim & ~ANIM_TOGGLEBIT; + cs->castScriptStatus.scriptNoMoveTime = cs->scriptAnimTime; + // lock the viewangles + if ( !cs->castScriptStatus.playAnimViewlockTime || cs->castScriptStatus.playAnimViewlockTime < level.time ) { + VectorCopy( cs->ideal_viewangles, cs->castScriptStatus.playanim_viewangles ); + } + cs->castScriptStatus.playAnimViewlockTime = cs->scriptAnimTime; + // adjust the duration according to numLoops + if ( numLoops > 1 ) { + client->ps.legsTimer += duration * ( numLoops - 1 ); + if ( !strcmp( tokens[1], "both" ) ) { + client->ps.torsoTimer += duration * ( numLoops - 1 ); + } + } else if ( numLoops == -1 ) { + client->ps.legsTimer = 9999; + if ( !strcmp( tokens[1], "both" ) ) { + client->ps.torsoTimer = 9999; + } + } + } + } else { + if ( holdframe ) { + // make sure it doesn't stop before the next command can be processed + if ( !strcmp( tokens[1], "torso" ) ) { + if ( client->ps.torsoTimer < 400 ) { + client->ps.torsoTimer = 400; + } + } else if ( !strcmp( tokens[1], "legs" ) ) { + if ( client->ps.legsTimer < 400 ) { + client->ps.legsTimer = 400; + } + } else if ( !strcmp( tokens[1], "both" ) ) { + if ( client->ps.torsoTimer < 400 ) { + client->ps.torsoTimer = 400; + } + if ( client->ps.legsTimer < 400 ) { + client->ps.legsTimer = 400; + } + } + } + // keep it looping if forever + if ( forever ) { + if ( !strcmp( tokens[1], "torso" ) ) { + client->ps.torsoTimer = 9999; + } else { + client->ps.legsTimer = 9999; + if ( !strcmp( tokens[1], "both" ) ) { + client->ps.torsoTimer = 9999; + } + } + return qfalse; + } + // wait for the anim to stop playing + if ( cs->scriptAnimTime <= level.time ) { + return qtrue; + } + } + + return qfalse; + + } else { // old model + + for ( i = 0; i < 3; i++ ) { + token = COM_ParseExt( &pString, qfalse ); + if ( !token || !token[0] ) { + //G_Error("AI Scripting: syntax error\n\nplayanim [legs/torso/both]\n"); + G_Printf( "AI Scripting: syntax error\n\nplayanim \n" ); + return qtrue; + } else { + Q_strncpyz( tokens[i], token, sizeof( tokens[i] ) ); + } + } + + Q_strlwr( tokens[2] ); + + endtime = cs->castScriptStatus.castScriptStackChangeTime + atoi( tokens[1] ); + duration = endtime - level.time + 200; // so animations don't run out before starting a next animation + if ( duration > 2000 ) { + duration = 2000; + } + + cs->scriptAnimTime = level.time; + + if ( duration < 200 ) { + return qtrue; // done playing animation + + } + // call the anims directly based on the animation token + + //if (cs->castScriptStatus.castScriptStackChangeTime == level.time) { + for ( i = 0; i < MAX_ANIMATIONS; i++ ) { + if ( !Q_strcasecmp( tokens[0], animStrings[i] ) ) { + if ( !Q_strcasecmp( tokens[2],"torso" ) ) { + if ( ( client->ps.torsoAnim & ~ANIM_TOGGLEBIT ) != i ) { + client->ps.torsoAnim = ( ( client->ps.torsoAnim & ANIM_TOGGLEBIT ) ^ ANIM_TOGGLEBIT ) | i; + } + client->ps.torsoTimer = duration; + } else if ( !Q_strcasecmp( tokens[2],"legs" ) ) { + if ( ( client->ps.legsAnim & ~ANIM_TOGGLEBIT ) != i ) { + client->ps.legsAnim = ( ( client->ps.legsAnim & ANIM_TOGGLEBIT ) ^ ANIM_TOGGLEBIT ) | i; + } + client->ps.legsTimer = duration; + } else if ( !Q_strcasecmp( tokens[2],"both" ) ) { + if ( ( client->ps.torsoAnim & ~ANIM_TOGGLEBIT ) != i ) { + client->ps.torsoAnim = ( ( client->ps.torsoAnim & ANIM_TOGGLEBIT ) ^ ANIM_TOGGLEBIT ) | i; + } + client->ps.torsoTimer = duration; + if ( ( client->ps.legsAnim & ~ANIM_TOGGLEBIT ) != i ) { + client->ps.legsAnim = ( ( client->ps.legsAnim & ANIM_TOGGLEBIT ) ^ ANIM_TOGGLEBIT ) | i; + } + client->ps.legsTimer = duration; + } else { + G_Printf( "AI Scripting: syntax error\n\nplayanim \n" ); + } + break; + } + } + if ( i == MAX_ANIMATIONS ) { + G_Printf( "AI Scripting: playanim has unknown or invalid animation \"%s\"\n", tokens[0] ); + } + //} + + if ( !strcmp( tokens[2], "torso" ) ) { + cs->scriptAnimNum = client->ps.torsoAnim & ~ANIM_TOGGLEBIT; + } else { + cs->scriptAnimNum = client->ps.legsAnim & ~ANIM_TOGGLEBIT; + } + + if ( cs->castScriptStatus.scriptNoMoveTime < level.time + 300 ) { + cs->castScriptStatus.scriptNoMoveTime = level.time + 300; + } + if ( cs->castScriptStatus.scriptNoAttackTime < level.time + 300 ) { + cs->castScriptStatus.scriptNoAttackTime = level.time + 300; + } + return qfalse; + } +}; + +/* +================= +AICast_ScriptAction_ClearAnim + + stops any animation that is currently playing +================= +*/ +qboolean AICast_ScriptAction_ClearAnim( cast_state_t *cs, char *params ) { + gclient_t *client; + + client = &level.clients[cs->entityNum]; + + client->ps.torsoTimer = 0; + client->ps.legsTimer = 0; + + // let us move again + cs->castScriptStatus.scriptNoMoveTime = 0; + + return qtrue; +} + +/* +================= +AICast_ScriptAction_SetAmmo + + syntax: setammo +================= +*/ +qboolean AICast_ScriptAction_SetAmmo( cast_state_t *cs, char *params ) { + char *pString, *token; + int weapon; + int i; + + pString = params; + + token = COM_ParseExt( &pString, qfalse ); + if ( !token[0] ) { + G_Error( "AI Scripting: setammo without ammo identifier\n" ); + } + + weapon = WP_NONE; + + for ( i = 1; bg_itemlist[i].classname; i++ ) + { + //----(SA) first try the name they see in the editor, then the pickup name + if ( !Q_strcasecmp( token, bg_itemlist[i].classname ) ) { + weapon = bg_itemlist[i].giTag; + break; + } + + if ( !Q_strcasecmp( token, bg_itemlist[i].pickup_name ) ) { + weapon = bg_itemlist[i].giTag; + break; + } + } + + token = COM_ParseExt( &pString, qfalse ); + if ( !token[0] ) { + G_Error( "AI Scripting: setammo without ammo count\n" ); + } + + if ( weapon != WP_NONE ) { + // give them the ammo + + if ( atoi( token ) ) { + int amt; + amt = atoi( token ); + if ( amt > 50 + ammoTable[BG_FindAmmoForWeapon( weapon )].maxammo ) { + amt = 999; // unlimited + } + Add_Ammo( &g_entities[cs->entityNum], weapon, amt, qtrue ); + } else { + // remove ammo for this weapon + g_entities[cs->entityNum].client->ps.ammo[BG_FindAmmoForWeapon( weapon )] = 0; + g_entities[cs->entityNum].client->ps.ammoclip[BG_FindClipForWeapon( weapon )] = 0; + } + + } else { + + if ( g_cheats.integer ) { + G_Printf( "--SCRIPTER WARNING-- AI Scripting: setammo: unknown ammo \"%s\"", params ); + } + return qfalse; // (SA) temp as scripts transition to new names + + } + + return qtrue; +}; + +/* +================= +AICast_ScriptAction_SetClip + + syntax: setclip + +================= +*/ +qboolean AICast_ScriptAction_SetClip( cast_state_t *cs, char *params ) { + char *pString, *token; + int weapon; + int i; + + pString = params; + + token = COM_ParseExt( &pString, qfalse ); + if ( !token[0] ) { + G_Error( "AI Scripting: setclip without weapon identifier\n" ); + } + + weapon = WP_NONE; + + for ( i = 1; bg_itemlist[i].classname; i++ ) + { + //----(SA) first try the name they see in the editor, then the pickup name + if ( !Q_strcasecmp( token, bg_itemlist[i].classname ) ) { + weapon = bg_itemlist[i].giTag; + break; + } + + if ( !Q_strcasecmp( token, bg_itemlist[i].pickup_name ) ) { + weapon = bg_itemlist[i].giTag; + break; + } + } + + token = COM_ParseExt( &pString, qfalse ); + if ( !token[0] ) { + G_Error( "AI Scripting: setclip without ammo count\n" ); + } + + if ( weapon != WP_NONE ) { + + int spillover = atoi( token ) - ammoTable[weapon].maxclip; + + if ( spillover > 0 ) { + // there was excess, put it in storage and fill the clip + g_entities[cs->entityNum].client->ps.ammo[BG_FindAmmoForWeapon( weapon )] += spillover; + g_entities[cs->entityNum].client->ps.ammoclip[BG_FindClipForWeapon( weapon )] = ammoTable[weapon].maxclip; + } else { + // set the clip amount to the exact specified value + g_entities[cs->entityNum].client->ps.ammoclip[weapon] = atoi( token ); + } + + } else { +// G_Printf( "--SCRIPTER WARNING-- AI Scripting: setclip: unknown weapon \"%s\"", params ); + return qfalse; // (SA) temp as scripts transition to new names +// G_Error( "AI Scripting: setclip: unknown weapon \"%s\"", params ); + } + + return qtrue; +}; + + + +/* +============== +AICast_ScriptAction_SuggestWeapon +============== +*/ +qboolean AICast_ScriptAction_SuggestWeapon( cast_state_t *cs, char *params ) { + int weapon; + int i; + //int suggestedweaps = 0; // TTimo: unused + + weapon = WP_NONE; + + for ( i = 1; bg_itemlist[i].classname; i++ ) + { + //----(SA) first try the name they see in the editor, then the pickup name + if ( !Q_strcasecmp( params, bg_itemlist[i].classname ) ) { + weapon = bg_itemlist[i].giTag; + break; + } + + if ( !Q_strcasecmp( params, bg_itemlist[i].pickup_name ) ) { + weapon = bg_itemlist[i].giTag; + break; + } + } + + if ( weapon != WP_NONE ) { + G_AddEvent( &g_entities[cs->entityNum], EV_SUGGESTWEAP, weapon ); + } else { + G_Error( "AI Scripting: suggestweapon: unknown weapon \"%s\"", params ); + } + + return qtrue; + +} + + +/* +================= +AICast_ScriptAction_SelectWeapon + + syntax: selectweapon +================= +*/ +qboolean AICast_ScriptAction_SelectWeapon( cast_state_t *cs, char *params ) { + int weapon; + int i; + + weapon = WP_NONE; + + for ( i = 1; bg_itemlist[i].classname; i++ ) + { + //----(SA) first try the name they see in the editor, then the pickup name + if ( !Q_strcasecmp( params, bg_itemlist[i].classname ) ) { + weapon = bg_itemlist[i].giTag; + break; + } + + if ( !Q_strcasecmp( params, bg_itemlist[i].pickup_name ) ) { + weapon = bg_itemlist[i].giTag; + break; + } + } + + if ( weapon != WP_NONE ) { + if ( cs->bs ) { + cs->weaponNum = weapon; + } + cs->castScriptStatus.scriptFlags |= SFL_NOCHANGEWEAPON; + + g_entities[cs->entityNum].client->ps.weapon = weapon; + g_entities[cs->entityNum].client->ps.weaponstate = WEAPON_READY; + + if ( !cs->aiCharacter ) { // only do this for player + //vmCvar_t cvar; + // + g_entities[cs->entityNum].client->ps.weaponTime = 750; // (SA) HACK: FIXME: TODO: delay to catch initial weapon reload + // tell it which weapon to use after spawning in + //trap_Cvar_Register( &cvar, "cg_loadWeaponSelect", "0", CVAR_ROM ); + //trap_Cvar_Set( "cg_loadWeaponSelect", va("%i", g_entities[cs->entityNum].client->ps.weapon ) ); + } + + } else { +// G_Printf( "--SCRIPTER WARNING-- AI Scripting: selectweapon: unknown weapon \"%s\"", params ); +// return qfalse; // (SA) temp as scripts transition to new names + G_Error( "AI Scripting: selectweapon: unknown weapon \"%s\"", params ); + } + + return qtrue; +}; + + + +//----(SA) added +/* +============== +AICast_ScriptAction_GiveArmor + syntax: setarmor + +============== +*/ +qboolean AICast_ScriptAction_SetArmor( cast_state_t *cs, char *params ) { + if ( !params || !params[0] ) { + G_Error( "AI Scripting: setarmor requires an armor value" ); + } + + g_entities[cs->entityNum].client->ps.stats[STAT_ARMOR] += atoi( params ); + + return qtrue; +} + +/* +============== +AICast_ScriptAction_GiveArmor + + syntax: givearmor + + will probably be more like: + syntax: givearmor +============== +*/ +qboolean AICast_ScriptAction_GiveArmor( cast_state_t *cs, char *params ) { + int i; + gitem_t *item = 0; + + for ( i = 1; bg_itemlist[i].classname; i++ ) { + //----(SA) first try the name they see in the editor, then the pickup name + if ( !Q_strcasecmp( params, bg_itemlist[i].classname ) ) { + item = &bg_itemlist[i]; + } + + if ( !Q_strcasecmp( params, bg_itemlist[i].pickup_name ) ) { + item = &bg_itemlist[i]; + } + } + + if ( !item ) { // item not found + G_Error( "AI Scripting: givearmor%s, unknown item", params ); + } + + if ( item->giType == IT_ARMOR ) { + g_entities[cs->entityNum].client->ps.stats[STAT_ARMOR] += item->quantity; + if ( g_entities[cs->entityNum].client->ps.stats[STAT_ARMOR] > 100 ) { + g_entities[cs->entityNum].client->ps.stats[STAT_ARMOR] = 100; + } + } + + return qtrue; +} +//----(SA) end + + + +/* +================= +AICast_ScriptAction_GiveWeapon + + syntax: giveweapon +================= +*/ +qboolean AICast_ScriptAction_GiveWeapon( cast_state_t *cs, char *params ) { + int weapon; + int i; + gentity_t *ent = &g_entities[cs->entityNum]; + + weapon = WP_NONE; + + for ( i = 1; bg_itemlist[i].classname; i++ ) + { + //----(SA) first try the name they see in the editor, then the pickup name + if ( !Q_strcasecmp( params, bg_itemlist[i].classname ) ) { + weapon = bg_itemlist[i].giTag; + break; + } + + if ( !Q_strcasecmp( params, bg_itemlist[i].pickup_name ) ) { + weapon = bg_itemlist[i].giTag; + } + } + + if ( weapon == WP_COLT ) { + // if you had the colt already, now you've got two! + if ( COM_BitCheck( g_entities[cs->entityNum].client->ps.weapons, WP_COLT ) ) { + weapon = WP_AKIMBO; + } + } + + if ( weapon != WP_NONE ) { + COM_BitSet( g_entities[cs->entityNum].client->ps.weapons, weapon ); + +//----(SA) some weapons always go together (and they share a clip, so this is okay) + if ( weapon == WP_GARAND ) { + COM_BitSet( g_entities[cs->entityNum].client->ps.weapons, WP_SNOOPERSCOPE ); + } + if ( weapon == WP_SNOOPERSCOPE ) { + COM_BitSet( g_entities[cs->entityNum].client->ps.weapons, WP_GARAND ); + } + if ( weapon == WP_FG42 ) { + COM_BitSet( g_entities[cs->entityNum].client->ps.weapons, WP_FG42SCOPE ); + } + if ( weapon == WP_SNIPERRIFLE ) { + COM_BitSet( g_entities[cs->entityNum].client->ps.weapons, WP_MAUSER ); + } +//----(SA) end + + // monsters have full ammo for their attacks + // knife gets infinite ammo too + if ( !Q_strncasecmp( params, "monsterattack", 13 ) || weapon == WP_KNIFE ) { + g_entities[cs->entityNum].client->ps.ammo[BG_FindAmmoForWeapon( weapon )] = 999; + Fill_Clip( &g_entities[cs->entityNum].client->ps, weapon ); //----(SA) added + } + // conditional flags + if ( ent->aiCharacter == AICHAR_ZOMBIE ) { + if ( COM_BitCheck( ent->client->ps.weapons, WP_MONSTER_ATTACK1 ) ) { + cs->aiFlags |= AIFL_NO_FLAME_DAMAGE; + SET_FLAMING_ZOMBIE( ent->s, 1 ); + } + } + } else { + G_Error( "AI Scripting: giveweapon %s, unknown weapon", params ); + } + + return qtrue; +}; + +/* +================= +AICast_ScriptAction_TakeWeapon + + syntax: takeweapon +================= +*/ +qboolean AICast_ScriptAction_TakeWeapon( cast_state_t *cs, char *params ) { + int weapon; + int i; + + weapon = WP_NONE; + + if ( !Q_stricmp( params, "all" ) ) { + + // clear out all weapons + memset( g_entities[cs->entityNum].client->ps.weapons, 0, sizeof( g_entities[cs->entityNum].client->ps.weapons ) ); + memset( g_entities[cs->entityNum].client->ps.ammo, 0, sizeof( g_entities[cs->entityNum].client->ps.ammo ) ); + memset( g_entities[cs->entityNum].client->ps.ammoclip, 0, sizeof( g_entities[cs->entityNum].client->ps.ammoclip ) ); + cs->weaponNum = WP_NONE; + + } else { + + + for ( i = 1; bg_itemlist[i].classname; i++ ) + { + //----(SA) first try the name they see in the editor, then the pickup name + if ( !Q_strcasecmp( params, bg_itemlist[i].classname ) ) { + weapon = bg_itemlist[i].giTag; + break; + } + + if ( !Q_strcasecmp( params, bg_itemlist[i].pickup_name ) ) { + weapon = bg_itemlist[i].giTag; + break; + } + } + + if ( weapon != WP_NONE ) { + qboolean clear; + + if ( weapon == WP_AKIMBO ) { + // take both the colt /and/ the akimbo weapons when 'akimbo' is specified + COM_BitClear( g_entities[cs->entityNum].client->ps.weapons, WP_COLT ); + } else if ( weapon == WP_COLT ) { + // take 'akimbo' first if it's there, then take 'colt' + if ( COM_BitCheck( g_entities[cs->entityNum].client->ps.weapons, WP_AKIMBO ) ) { + weapon = WP_AKIMBO; + } + } + + // + COM_BitClear( g_entities[cs->entityNum].client->ps.weapons, weapon ); + // also remove the ammo for this weapon + // but first make sure we dont have any other weapons that use the same ammo + clear = qtrue; + for ( i = 0; i < WP_NUM_WEAPONS; i++ ) { + if ( BG_FindAmmoForWeapon( weapon ) != BG_FindAmmoForWeapon( i ) ) { + continue; + } + if ( COM_BitCheck( g_entities[cs->entityNum].client->ps.weapons, i ) ) { + clear = qfalse; + } + } + if ( clear ) { +// (SA) temp only. commented out for pistol guys in escape1 +// g_entities[cs->entityNum].client->ps.ammo[BG_FindAmmoForWeapon(weapon)] = 0; + } + } else { + G_Error( "AI Scripting: takeweapon %s, unknown weapon", params ); + } + + } + + if ( !g_entities[cs->entityNum].client->ps.weapons ) { + if ( cs->bs ) { + cs->weaponNum = WP_NONE; + } else { + g_entities[cs->entityNum].client->ps.weapon = WP_NONE; + } + } + + return qtrue; +}; + + + +//----(SA) added + +/* +============== +AICast_ScriptAction_GiveInventory +============== +*/ +qboolean AICast_ScriptAction_GiveInventory( cast_state_t *cs, char *params ) { + int i; + gitem_t *item = 0; + + for ( i = 1; bg_itemlist[i].classname; i++ ) { + //----(SA) first try the name they see in the editor, then the pickup name + if ( !Q_strcasecmp( params, bg_itemlist[i].classname ) ) { + item = &bg_itemlist[i]; + } + + if ( !Q_strcasecmp( params, bg_itemlist[i].pickup_name ) ) { + item = &bg_itemlist[i]; + } + } + + if ( !item ) { // item not found + G_Error( "AI Scripting: giveinventory %s, unknown item", params ); + } + + if ( item->giType == IT_KEY ) { + g_entities[cs->entityNum].client->ps.stats[STAT_KEYS] |= ( 1 << item->giTag ); + } else if ( item->giType == IT_HOLDABLE ) { + // (SA) TODO + } + + return qtrue; +}; + + +//----(SA) end + + + +/* +================= +AICast_ScriptAction_Movetype + + syntax: movetype + + Sets this character's movement type, will exist until another movetype command is called +================= +*/ +qboolean AICast_ScriptAction_Movetype( cast_state_t *cs, char *params ) { + if ( !Q_strcasecmp( params, "walk" ) ) { + cs->movestate = MS_WALK; + cs->movestateType = MSTYPE_PERMANENT; + return qtrue; + } + if ( !Q_strcasecmp( params, "run" ) ) { + cs->movestate = MS_RUN; + cs->movestateType = MSTYPE_PERMANENT; + return qtrue; + } + if ( !Q_strcasecmp( params, "crouch" ) ) { + cs->movestate = MS_CROUCH; + cs->movestateType = MSTYPE_PERMANENT; + return qtrue; + } + if ( !Q_strcasecmp( params, "default" ) ) { + cs->movestate = MS_DEFAULT; + cs->movestateType = MSTYPE_NONE; + return qtrue; + } + + return qtrue; +} +/* +================= +AICast_ScriptAction_AlertEntity + + syntax: alertentity +================= +*/ +qboolean AICast_ScriptAction_AlertEntity( cast_state_t *cs, char *params ) { + gentity_t *ent; + + if ( !params || !params[0] ) { + G_Error( "AI Scripting: alertentity without targetname\n" ); + } + + // find this targetname + ent = G_Find( NULL, FOFS( targetname ), params ); + if ( !ent ) { + ent = G_Find( NULL, FOFS( aiName ), params ); // look for an AI + if ( !ent || !ent->client ) { // accept only AI for aiName check + G_Error( "AI Scripting: alertentity cannot find targetname \"%s\"\n", params ); + } + } + + // call this entity's AlertEntity function + if ( !ent->AIScript_AlertEntity ) { + if ( !ent->client && ent->use && !Q_stricmp( ent->classname, "ai_trigger" ) ) { + ent->use( ent, NULL, NULL ); + return qtrue; + } + + if ( aicast_debug.integer ) { + G_Printf( "AI Scripting: alertentity \"%s\" (classname = %s) doesn't have an \"AIScript_AlertEntity\" function\n", params, ent->classname ); + } + //G_Error( "AI Scripting: alertentity \"%s\" (classname = %s) doesn't have an \"AIScript_AlertEntity\" function\n", params, ent->classname ); + return qtrue; + } + + ent->AIScript_AlertEntity( ent ); + + return qtrue; +} + +/* +================= +AICast_ScriptAction_SaveGame + + NOTE: only use this command in "player" scripts, not for AI + + syntax: savegame +================= +*/ +qboolean AICast_ScriptAction_SaveGame( cast_state_t *cs, char *params ) { + char *pString, *saveName; + pString = params; + + if ( cs->bs ) { + G_Error( "AI Scripting: savegame attempted on a non-player" ); + } + +//----(SA) check for parameter + saveName = COM_ParseExt( &pString, qfalse ); + if ( !saveName[0] ) { + G_SaveGame( NULL ); // save the default "current" savegame + } else { + G_SaveGame( saveName ); + } +//----(SA) end + + return qtrue; +} + +/* +================= +AICast_ScriptAction_FireAtTarget + + syntax: fireattarget [duration] +================= +*/ +qboolean AICast_ScriptAction_FireAtTarget( cast_state_t *cs, char *params ) { + gentity_t *ent; + vec3_t vec, org, src; + char *pString, *token; + float diff; + int i; + + pString = params; + + token = COM_ParseExt( &pString, qfalse ); + if ( !token[0] ) { + G_Error( "AI Scripting: fireattarget without a targetname\n" ); + } + + if ( !cs->bs ) { + G_Error( "AI Scripting: fireattarget called for non-AI character\n" ); + } + + // find this targetname + ent = G_Find( NULL, FOFS( targetname ), token ); + if ( !ent ) { + ent = AICast_FindEntityForName( token ); + if ( !ent ) { + G_Error( "AI Scripting: fireattarget cannot find targetname/aiName \"%s\"\n", token ); + } + } + + // if this is our first call for this fireattarget, record the ammo count + if ( cs->castScriptStatus.scriptFlags & SFL_FIRST_CALL ) { + cs->lastWeaponFired = 0; + } + // make sure we don't move or shoot while turning to our target + if ( cs->castScriptStatus.scriptNoAttackTime < level.time ) { + cs->castScriptStatus.scriptNoAttackTime = level.time + 500; + } + // dont reload prematurely + cs->noReloadTime = level.time + 1000; + // don't move while firing at all + //if (cs->castScriptStatus.scriptNoMoveTime < level.time) { + cs->castScriptStatus.scriptNoMoveTime = level.time + 500; + //} + // let us move our view, whether it looks bad or not + cs->castScriptStatus.playAnimViewlockTime = 0; + // set the view angle manually + BG_EvaluateTrajectory( &ent->s.pos, level.time, org ); + VectorCopy( cs->bs->origin, src ); + src[2] += cs->bs->cur_ps.viewheight; + VectorSubtract( org, src, vec ); + VectorNormalize( vec ); + vectoangles( vec, cs->ideal_viewangles ); + for ( i = 0; i < 2; i++ ) { + diff = abs( AngleDifference( cs->bs->cur_ps.viewangles[i], cs->ideal_viewangles[i] ) ); + if ( VectorCompare( vec3_origin, ent->s.pos.trDelta ) ) { + if ( diff ) { + return qfalse; // not facing yet + } + } else { + if ( diff > 25 ) { // allow some slack when target is moving + return qfalse; + } + } + } + + // force fire + trap_EA_Attack( cs->bs->client ); + // + cs->bFlags |= BFL_ATTACKED; + // + // if we haven't fired yet + if ( !cs->lastWeaponFired ) { + return qfalse; + } + // + // do we need to stay and fire for a duration? + token = COM_ParseExt( &pString, qfalse ); + if ( !token[0] ) { + return qtrue; // no need to wait around + } + // only return true if we've been firing for long enough + return ( ( cs->castScriptStatus.castScriptStackChangeTime + atoi( token ) ) < level.time ); +} + +/* +================= +AICast_ScriptAction_GodMode + + syntax: godmode +================= +*/ +qboolean AICast_ScriptAction_GodMode( cast_state_t *cs, char *params ) { + if ( !params || !params[0] ) { + G_Error( "AI Scripting: godmode requires an on/off specifier\n" ); + } + + if ( !Q_stricmp( params, "on" ) ) { + g_entities[cs->bs->entitynum].flags |= FL_GODMODE; + } else if ( !Q_stricmp( params, "off" ) ) { + g_entities[cs->bs->entitynum].flags &= ~FL_GODMODE; + } else { + G_Error( "AI Scripting: godmode requires an on/off specifier\n" ); + } + + return qtrue; +} + +/* +================= +AICast_ScriptAction_Accum + + syntax: accum + + Commands: + + accum inc + accum abort_if_less_than + accum abort_if_greater_than + accum abort_if_not_equal + accum abort_if_equal + accum set + accum random + accum bitset + accum bitreset + accum abort_if_bitset + accum abort_if_not_bitset +================= +*/ +qboolean AICast_ScriptAction_Accum( cast_state_t *cs, char *params ) { + char *pString, *token, lastToken[MAX_QPATH]; + int bufferIndex; + + pString = params; + + token = COM_ParseExt( &pString, qfalse ); + if ( !token[0] ) { + G_Error( "AI Scripting: accum without a buffer index\n" ); + } + + bufferIndex = atoi( token ); + if ( bufferIndex >= MAX_SCRIPT_ACCUM_BUFFERS ) { + G_Error( "AI Scripting: accum buffer is outside range (0 - %i)\n", MAX_SCRIPT_ACCUM_BUFFERS ); + } + + token = COM_ParseExt( &pString, qfalse ); + if ( !token[0] ) { + G_Error( "AI Scripting: accum without a command\n" ); + } + + Q_strncpyz( lastToken, token, sizeof( lastToken ) ); + token = COM_ParseExt( &pString, qfalse ); + + if ( !Q_stricmp( lastToken, "inc" ) ) { + if ( !token[0] ) { + G_Error( "AI Scripting: accum %s requires a parameter\n", lastToken ); + } + cs->scriptAccumBuffer[bufferIndex] += atoi( token ); + } else if ( !Q_stricmp( lastToken, "abort_if_less_than" ) ) { + if ( !token[0] ) { + G_Error( "AI Scripting: accum %s requires a parameter\n", lastToken ); + } + if ( cs->scriptAccumBuffer[bufferIndex] < atoi( token ) ) { + // abort the current script + cs->castScriptStatus.castScriptStackHead = cs->castScriptEvents[cs->castScriptStatus.castScriptEventIndex].stack.numItems; + } + } else if ( !Q_stricmp( lastToken, "abort_if_greater_than" ) ) { + if ( !token[0] ) { + G_Error( "AI Scripting: accum %s requires a parameter\n", lastToken ); + } + if ( cs->scriptAccumBuffer[bufferIndex] > atoi( token ) ) { + // abort the current script + cs->castScriptStatus.castScriptStackHead = cs->castScriptEvents[cs->castScriptStatus.castScriptEventIndex].stack.numItems; + } + } else if ( !Q_stricmp( lastToken, "abort_if_not_equal" ) ) { + if ( !token[0] ) { + G_Error( "AI Scripting: accum %s requires a parameter\n", lastToken ); + } + if ( cs->scriptAccumBuffer[bufferIndex] != atoi( token ) ) { + // abort the current script + cs->castScriptStatus.castScriptStackHead = cs->castScriptEvents[cs->castScriptStatus.castScriptEventIndex].stack.numItems; + } + } else if ( !Q_stricmp( lastToken, "abort_if_equal" ) ) { + if ( !token[0] ) { + G_Error( "AI Scripting: accum %s requires a parameter\n", lastToken ); + } + if ( cs->scriptAccumBuffer[bufferIndex] == atoi( token ) ) { + // abort the current script + cs->castScriptStatus.castScriptStackHead = cs->castScriptEvents[cs->castScriptStatus.castScriptEventIndex].stack.numItems; + } + } else if ( !Q_stricmp( lastToken, "bitset" ) ) { + if ( !token[0] ) { + G_Error( "AI Scripting: accum %s requires a parameter\n", lastToken ); + } + cs->scriptAccumBuffer[bufferIndex] |= ( 1 << atoi( token ) ); + } else if ( !Q_stricmp( lastToken, "bitreset" ) ) { + if ( !token[0] ) { + G_Error( "AI Scripting: accum %s requires a parameter\n", lastToken ); + } + cs->scriptAccumBuffer[bufferIndex] &= ~( 1 << atoi( token ) ); + } else if ( !Q_stricmp( lastToken, "abort_if_bitset" ) ) { + if ( !token[0] ) { + G_Error( "AI Scripting: accum %s requires a parameter\n", lastToken ); + } + if ( cs->scriptAccumBuffer[bufferIndex] & ( 1 << atoi( token ) ) ) { + // abort the current script + cs->castScriptStatus.castScriptStackHead = cs->castScriptEvents[cs->castScriptStatus.castScriptEventIndex].stack.numItems; + } + } else if ( !Q_stricmp( lastToken, "abort_if_not_bitset" ) ) { + if ( !token[0] ) { + G_Error( "AI Scripting: accum %s requires a parameter\n", lastToken ); + } + if ( !( cs->scriptAccumBuffer[bufferIndex] & ( 1 << atoi( token ) ) ) ) { + // abort the current script + cs->castScriptStatus.castScriptStackHead = cs->castScriptEvents[cs->castScriptStatus.castScriptEventIndex].stack.numItems; + } + } else if ( !Q_stricmp( lastToken, "set" ) ) { + if ( !token[0] ) { + G_Error( "AI Scripting: accum %s requires a parameter\n", lastToken ); + } + cs->scriptAccumBuffer[bufferIndex] = atoi( token ); + } else if ( !Q_stricmp( lastToken, "random" ) ) { + if ( !token[0] ) { + G_Error( "AI Scripting: accum %s requires a parameter\n", lastToken ); + } + cs->scriptAccumBuffer[bufferIndex] = rand() % atoi( token ); + } else { + G_Error( "AI Scripting: accum %s: unknown command\n", params ); + } + + return qtrue; +} + +/* +================= +AICast_ScriptAction_SpawnCast + + syntax: spawncast + + is the entity marker which has the position and angles of where we want the new + cast AI to spawn +================= +*/ +qboolean AICast_ScriptAction_SpawnCast( cast_state_t *cs, char *params ) { +// char *pString, *token; +// char *classname; +// gentity_t *targetEnt, *newCast; + + G_Error( "AI Scripting: spawncast is no longer functional. Use trigger_spawn instead.\n" ); + return qfalse; +/* + if (!params[0]) { + G_Error( "AI Scripting: spawncast without a classname\n" ); + } + + pString = params; + + token = COM_ParseExt( &pString, qfalse ); + if (!token[0]) { + G_Error( "AI Scripting: spawncast without a classname\n" ); + } + + classname = G_Alloc( strlen(token)+1 ); + Q_strncpyz( classname, token, strlen(token)+1 ); + + token = COM_ParseExt( &pString, qfalse ); + if (!token[0]) { + G_Error( "AI Scripting: spawncast without a targetname\n" ); + } + + targetEnt = G_Find( NULL, FOFS(targetname), token ); + if (!targetEnt) { + G_Error( "AI Scripting: cannot find targetname \"%s\"\n", token ); + } + + token = COM_ParseExt( &pString, qfalse ); + if (!token[0]) { + G_Error( "AI Scripting: spawncast without an ainame\n" ); + } + + newCast = G_Spawn(); + newCast->classname = classname; + VectorCopy( targetEnt->s.origin, newCast->s.origin ); + VectorCopy( targetEnt->s.angles, newCast->s.angles ); + newCast->aiName = G_Alloc( strlen(token)+1 ); + Q_strncpyz( newCast->aiName, token, strlen(token)+1 ); + + if (!G_CallSpawn( newCast )) { + G_Error( "AI Scripting: spawncast for unknown entity \"%s\"\n", newCast->classname ); + } + + return qtrue; +*/ +} + +/* +================= +AICast_ScriptAction_MissionFailed + + syntax: missionfailed